From 5dd3355bd8bf29b5df6f66dd560e201ec1306581 Mon Sep 17 00:00:00 2001 From: Conor Patrick Date: Sat, 8 Dec 2018 20:37:30 -0500 Subject: [PATCH] add wink command --- fido2/ctaphid.c | 2 ++ fido2/device.h | 3 ++- pc/app.h | 1 + pc/device.c | 5 ++++- targets/stm32l442/src/device.c | 38 ++++++++++++++++++++++++++++++---- tools/programmer.py | 13 ++++++++++++ 6 files changed, 56 insertions(+), 6 deletions(-) diff --git a/fido2/ctaphid.c b/fido2/ctaphid.c index 676387d..7a448ac 100644 --- a/fido2/ctaphid.c +++ b/fido2/ctaphid.c @@ -609,6 +609,8 @@ uint8_t ctaphid_handle_packet(uint8_t * pkt_raw) ctaphid_write_buffer_init(&wb); + device_wink(); + wb.cid = cid; wb.cmd = CTAPHID_WINK; diff --git a/fido2/device.h b/fido2/device.h index c6b63f5..174920d 100644 --- a/fido2/device.h +++ b/fido2/device.h @@ -98,7 +98,8 @@ void ctap_overwrite_rk(int index,CTAP_residentKey * rk); void boot_solo_bootloader(); void boot_st_bootloader(); - +// HID wink command +void device_wink(); #endif diff --git a/pc/app.h b/pc/app.h index aee6bdf..321d61a 100644 --- a/pc/app.h +++ b/pc/app.h @@ -22,6 +22,7 @@ void printing_init(); // 0xRRGGBB #define LED_INIT_VALUE 0x000800 +#define LED_WINK_VALUE 0x000008 #define LED_MAX_SCALER 30 #define LED_MIN_SCALER 1 // # of ms between each change in LED diff --git a/pc/device.c b/pc/device.c index 94d47a0..4581176 100644 --- a/pc/device.c +++ b/pc/device.c @@ -447,4 +447,7 @@ void ctap_overwrite_rk(int index,CTAP_residentKey * rk) printf("Warning: rk not implemented\n"); } - +void device_wink() +{ + printf("*WINK*\n"); +} diff --git a/targets/stm32l442/src/device.c b/targets/stm32l442/src/device.c index 580bc9a..1b03025 100644 --- a/targets/stm32l442/src/device.c +++ b/targets/stm32l442/src/device.c @@ -22,8 +22,6 @@ #include "stm32l4xx_ll_iwdg.h" - - uint32_t __90_ms = 0; uint32_t __device_status = 0; uint32_t __last_update = 0; @@ -148,6 +146,15 @@ void main_loop_delay() } +static int wink_time = 0; +static uint32_t winkt1 = 0; +static uint32_t winkt2 = 0; +void device_wink() +{ + wink_time = 10; + winkt1 = 0; +} + void heartbeat() { static int state = 0; @@ -170,9 +177,30 @@ void heartbeat() { state = !state; } - if (but) led_rgb(((val * r)<<8) | ((val*b) << 16) | (val*g)); + if (wink_time) + { + if (millis() - winkt1 > 120) + { + winkt1 = millis(); + if (winkt2++ & 1) + { + led_rgb(LED_WINK_VALUE * (LED_MAX_SCALER - LED_MIN_SCALER)/2); + } + else + { + led_rgb(0); + } + wink_time--; + } + } else - led_rgb(((val * g)<<8) | ((val*r) << 16) | (val*b)); + { + if (but) + led_rgb(((val * r)<<8) | ((val*b) << 16) | (val*g)); + else + led_rgb(((val * g)<<8) | ((val*r) << 16) | (val*b)); + } + } void authenticator_read_state(AuthenticatorState * a) @@ -520,6 +548,8 @@ void boot_solo_bootloader() } + + void _Error_Handler(char *file, int line) { printf2(TAG_ERR,"Error: %s: %d\r\n", file, line); diff --git a/tools/programmer.py b/tools/programmer.py index 2ea278c..1b39e34 100644 --- a/tools/programmer.py +++ b/tools/programmer.py @@ -131,6 +131,14 @@ class Programmer(): """ self.exchange(SoloBootloader.done,0,sig) + def wink(self,): + """ + If solo is configured as solo hacker or something similar, + this command will tell the token to boot directly to the bootloader + so it can be reprogrammed + """ + self.send_data_hid(CTAPHID.WINK,b'') + def enter_solo_bootloader(self,): """ If solo is configured as solo hacker or something similar, @@ -271,6 +279,7 @@ if __name__ == '__main__': parser.add_argument("--st-dfu", action="store_true", help = 'Don\'t write anything, try to enter ST DFU. Warning, you could brick your Solo if you overwrite everything. You should reprogram the option bytes just to be safe (boot to Solo bootloader first, then run this command).') parser.add_argument("--disable", action="store_true", help = 'Disable the Solo bootloader. Cannot be undone. No future updates can be applied.') parser.add_argument("--rng", action="store_true", help = 'Continuously dump random numbers generated from Solo.') + parser.add_argument("--wink", action="store_true", help = 'HID Wink command.') args = parser.parse_args() print() @@ -297,6 +306,10 @@ if __name__ == '__main__': sys.stdout.buffer.write(r) sys.exit(0) + if args.wink: + p.wink() + sys.exit(0) + if args.st_dfu: print('Sending command to boot into ST DFU...') p.enter_st_dfu()