diff --git a/libcrypt/main.c b/libcrypt/main.c index 793f009..e8f10d2 100644 --- a/libcrypt/main.c +++ b/libcrypt/main.c @@ -19,6 +19,7 @@ uint8_t reportBuffer[2]; /* buffer for HID reports */ static uint8_t next_key=0, prev_key=0xFF; +static uint8_t sec[SECLEN]=SECRET; uint32_t get_cnt(){ void* p=(void*)eeprom_read_word(CNTPOS_PTR); @@ -65,14 +66,50 @@ void buildReport(uint8_t mod, uint8_t key){ reportBuffer[1] = key; } +void main_fsm(){ + static uint8_t device_state=0; + static uint8_t prev_btn=0; + switch(device_state){ + case DEV_STATE_RESET: + { + uint32_t cnt; + if( eeprom_read_word(CNTPOS_PTR)==ERROR ){ + writeToBuffer(USB_KEY_E); + writeToBuffer(USB_KEY_R); + writeToBuffer(USB_KEY_R); + writeToBuffer(USB_KEY_O); + writeToBuffer(USB_KEY_R); + }else{ + cnt = get_cnt(); + buffer_unum(get_otp_from_cnt(cnt,8,sec,SECLEN)); + } + device_state=DEV_STATE_SENT; + break; + } + case DEV_STATE_SENT: + if( prev_btn!=0 && ((PIN_BTN)&(1< #include -#define _PORT_BTN B -#define _NUM_BTN 3 -#define PORT_BTN PORT_PORT_BTN -#define DDR_BTN DDR_PORT_BTN -#define P_BTN P_PORT_BTN_NUM_BTN -#define BTN_VECT INT_NUM_BTN_vect +#define PORT_BTN PORTB +#define PIN_BTN PINB +#define DDR_BTN DDRB +#define PBTN PB3 #define CNTPOS_PTR ((void*)1) #define ERROR 32202 @@ -23,3 +21,7 @@ #define UINT32_MAX 4294967296 #endif +#define DEV_STATE_RESET 0 +#define DEV_STATE_SENT 1 +#define DEV_STATE_CONFIRMED 2 +