X-Git-Url: https://git.cryptolib.org/?p=labortage2013badge.git;a=blobdiff_plain;f=firmware%2Fmain.c;h=5bcb9345f1a0bb06390884dde38c1f7d00d5f4f7;hp=f0fd1bf9b2d8f8e958d3326fb672a488eb9a14bc;hb=bef15b51e1f41aa3fc159ce2aa439182a393fd9c;hpb=dcc28b118d8136e462aaece312c2f757b956f7ff diff --git a/firmware/main.c b/firmware/main.c index f0fd1bf..5bcb934 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -1,10 +1,10 @@ /* Name: main.c - * Project: hid-custom-rq example - * Author: Christian Starkjohann - * Creation Date: 2008-04-07 + * Project: labortage-2013-badge + * Author: bg (bg@das-labor.org) + * Creation Date: 2013-10-16 * Tabsize: 4 - * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH - * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH, (c) Daniel Otte + * License: GNU GPL v3 * This Revision: $Id: main.c 692 2008-11-07 15:07:40Z cs $ */ @@ -13,12 +13,12 @@ This example should run on most AVRs with only little changes. No special hardware resources except INT0 are used. You may have to change usbconfig.h for different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or at least be connected to INT0 as well. -We assume that an LED is connected to port B bit 0. If you connect it to a -different port or bit, change the macros below: */ + #define BUTTON_PIN 4 #define SIMPLE_COUNTER 1 +#define NO_CHECK 1 #include #include @@ -32,7 +32,6 @@ different port or bit, change the macros below: #include /* required by usbdrv.h */ #include "usbdrv.h" -#include "oddebug.h" /* This is also an example for using debug macros */ #include "requests.h" /* The custom request numbers we use */ #include "hotp.h" #if !SIMPLE_COUNTER @@ -109,7 +108,7 @@ static union __attribute__((packed)) { static uint8_t current_command; -typedef struct { +typedef struct __attribute__((packed)) { uint8_t modifier; uint8_t reserved; uint8_t keycode[6]; @@ -127,8 +126,6 @@ void memory_clean(void) { secret_length_b = 0; } -#define NO_CHECK 1 - static uint8_t secret_set(void){ #if !NO_CHECK @@ -279,6 +276,7 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) } if ((rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_VENDOR) { current_command = rq->bRequest; + usbMsgPtr = uni_buffer.w8; switch(rq->bRequest) { case CUSTOM_RQ_SET_SECRET: @@ -298,7 +296,6 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) #else uni_buffer.w32[0] = percnt_get(0); #endif - usbMsgPtr = (usbMsgPtr_t)uni_buffer.w32; return 4; case CUSTOM_RQ_RESET_COUNTER: counter_reset(); @@ -306,9 +303,11 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) case CUSTOM_RQ_GET_RESET_COUNTER: eeprom_busy_wait(); uni_buffer.w8[0] = eeprom_read_byte(&reset_counter_ee); - usbMsgPtr = uni_buffer.w8; return 1; case CUSTOM_RQ_SET_DIGITS: + if (rq->wValue.bytes[0] < 6) { + rq->wValue.bytes[0] = 6; + } if (rq->wValue.bytes[0] > 9) { rq->wValue.bytes[0] = 9; } @@ -318,13 +317,11 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) case CUSTOM_RQ_GET_DIGITS: eeprom_busy_wait(); uni_buffer.w8[0] = eeprom_read_byte(&digits_ee); - usbMsgPtr = uni_buffer.w8; return 1; case CUSTOM_RQ_GET_TOKEN: token_generate(); usbMsgPtr = (usbMsgPtr_t)token; return strlen(token); - case CUSTOM_RQ_PRESS_BUTTON: key_state = STATE_SEND_KEY; return 0; @@ -346,7 +343,6 @@ usbMsgLen_t usbFunctionSetup(uchar data[8]) break; case CUSTOM_RQ_READ_BUTTON: uni_buffer.w8[0] = button_get_debounced(25); - usbMsgPtr = uni_buffer.w8; return 1; } }