]> git.cryptolib.org Git - labortage2013badge.git/commitdiff
some minor fixes
authorbg <daniel.otte@rub.de>
Sun, 20 Oct 2013 11:11:51 +0000 (13:11 +0200)
committerbg <daniel.otte@rub.de>
Sun, 20 Oct 2013 11:11:51 +0000 (13:11 +0200)
firmware/main.c
hostware/commandline/main.c

index b1afcdced995686b1c2f6475d09aa023b1bd03dc..247fcedcc018921775c429881e827774a63136ae 100644 (file)
@@ -50,6 +50,8 @@ at least be connected to INT0 as well.
 #define STATE_RELEASE_KEY 2
 #define STATE_NEXT 3
 
+#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+
 PROGMEM const char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = {
     0x05, 0x01,                    /* USAGE_PAGE (Generic Desktop) */
     0x09, 0x06,                    /* USAGE (Keyboard) */
@@ -340,23 +342,23 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
             return 0;
                case CUSTOM_RQ_SET_DBG:
                        return USB_NO_MSG;
-               case CUSTOM_RQ_GET_DBG:{
-                       usbMsgLen_t len = 8;
-                       if(len > rq->wLength.word){
-                               len = rq->wLength.word;
-                       }
+               case CUSTOM_RQ_GET_DBG:
                        usbMsgPtr = dbg_buffer;
-                       return len;
-               }
+                       return MIN(8, rq->wLength.word);
                case CUSTOM_RQ_RESET:
                        soft_reset((uint8_t)(rq->wValue.word));
                        break;
                case CUSTOM_RQ_READ_BUTTON:
                        uni_buffer.w8[0] = button_get_debounced(DEBOUNCE_DELAY);
                        return 1;
+#if ALLOW_SECRET_READ
                case CUSTOM_RQ_GET_SECRET:
-                   uni_buffer.w8[0] = 0;
+            uni_buffer.w8[0] = 0;
                    return USB_NO_MSG;
+#else
+#endif
+        default:
+            return 0;
                }
     }
 
@@ -389,17 +391,12 @@ uchar usbFunctionWrite(uchar *data, uchar len)
                        len = sizeof(dbg_buffer);
                }
                memcpy(dbg_buffer, data, len);
-               return 1;
-       default:
-               return 1;
        }
-       return 0;
+       return 1;
 }
 
-#define MIN(a, b) (((a) < (b)) ? (a) : (b))
-
 uchar usbFunctionRead(uchar *data, uchar len){
-#if ALLOW_SECRET_READ
+#if ALLOW_SECRET_READ || 1
     uchar r;
     uint8_t s_length_B;
     switch(current_command){
index 202dbeea6e92390411421fade9c54251631a3281..18e9547e483611010ffb550d6298f7bd5bb19734 100644 (file)
@@ -78,7 +78,7 @@ void set_dbg(char *hex_string){
 }
 
 void get_dbg(char *param){
-       uint16_t buffer[256];
+       uint8_t buffer[256];
        int cnt;
        cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_GET_DBG, 0, 0, (char*)buffer, 256, 5000);
        printf("DBG-Buffer:\n");
@@ -191,11 +191,15 @@ void read_button(char* param){
 }
 
 void get_secret(char *param){
-    uint16_t buffer[256];
+    uint8_t buffer[64];
     int cnt;
-    cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_GET_SECRET, 0, 0, (char*)buffer, 256, 5000);
-    printf("Secret:\n");
-    hexdump_block(stdout, buffer, 0, cnt, 16);
+    cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_GET_SECRET, 0, 0, (char*)buffer, 32, 5000);
+    if (cnt > 0) {
+    printf("Secret (%d):\n", cnt);
+    hexdump_block(stdout, buffer, NULL, cnt, 16);
+    } else {
+        fprintf(stderr, "Error: usb_control_msg(...) returned %d\n", cnt);
+    }
 }