diff --git a/ChangeLog b/ChangeLog index 4878b58..4813d71 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2015-09-14 Niibe Yutaka + + * src/gnuk.h (LED_GNUK_EXEC): New. + * src/main.c, src/usb-icc.c, src/usb_ctrl.c: icc_state_p access + clean up. + 2015-09-11 Niibe Yutaka * tool/upgrade_by_passwd.py (main): Loop until finding reGNUal diff --git a/chopstx b/chopstx index 4705e2f..ae0e475 160000 --- a/chopstx +++ b/chopstx @@ -1 +1 @@ -Subproject commit 4705e2fb15ae58cc47a3df100949b07931d53526 +Subproject commit ae0e47537372ba86a39bb5cfe3313914b47db99d diff --git a/src/gnuk.h b/src/gnuk.h index 80ac338..9cf95e8 100644 --- a/src/gnuk.h +++ b/src/gnuk.h @@ -418,13 +418,14 @@ void flash_do_write_internal (const uint8_t *p, int nr, extern const uint8_t gnuk_string_serial[]; -#define LED_ONESHOT 1 -#define LED_TWOSHOTS 2 -#define LED_SHOW_STATUS 4 -#define LED_START_COMMAND 8 -#define LED_FINISH_COMMAND 16 -#define LED_FATAL 32 -#define LED_USB_RESET 64 +#define LED_ONESHOT 1 +#define LED_TWOSHOTS 2 +#define LED_SHOW_STATUS 4 +#define LED_START_COMMAND 8 +#define LED_FINISH_COMMAND 16 +#define LED_FATAL 32 +#define LED_USB_RESET 64 +#define LED_GNUK_EXEC 128 void led_blink (int spec); #if defined(PINPAD_SUPPORT) diff --git a/src/main.c b/src/main.c index b9d553a..ee40094 100644 --- a/src/main.c +++ b/src/main.c @@ -210,13 +210,8 @@ static eventmask_t emit_led (int on_time, int off_time) static eventmask_t display_status_code (void) { - enum icc_state icc_state; eventmask_t m; - - if (icc_state_p == NULL) - icc_state = ICC_STATE_START; - else - icc_state = *icc_state_p; + enum icc_state icc_state = *icc_state_p; if (icc_state == ICC_STATE_START) return emit_led (LED_TIMEOUT_ONE, LED_TIMEOUT_STOP); @@ -331,8 +326,8 @@ main (int argc, char *argv[]) stdout_init (); #endif - ccid_thd = chopstx_create (PRIO_CCID, __stackaddr_ccid, - __stacksize_ccid, USBthread, NULL); + ccid_thd = chopstx_create (PRIO_CCID, __stackaddr_ccid, __stacksize_ccid, + USBthread, NULL); #ifdef PINPAD_CIR_SUPPORT cir_init (); @@ -358,9 +353,6 @@ main (int argc, char *argv[]) { eventmask_t m; - if (icc_state_p != NULL && *icc_state_p == ICC_STATE_EXEC_REQUESTED) - break; - m = eventflag_wait_timeout (&led_event, MAIN_TIMEOUT_INTERVAL); got_it: count++; @@ -398,6 +390,8 @@ main (int argc, char *argv[]) ccid_thd = chopstx_create (PRIO_CCID, __stackaddr_ccid, __stacksize_ccid, USBthread, NULL); break; + case LED_GNUK_EXEC: + goto exec; default: if ((m = emit_led (LED_TIMEOUT_ZERO, LED_TIMEOUT_STOP))) goto got_it; @@ -415,6 +409,7 @@ main (int argc, char *argv[]) #endif } + exec: random_fini (); set_led (1); diff --git a/src/usb-icc.c b/src/usb-icc.c index 15e90a7..9244982 100644 --- a/src/usb-icc.c +++ b/src/usb-icc.c @@ -179,8 +179,6 @@ struct icc_header { } __attribute__((packed)); -enum icc_state *icc_state_p; - /* Data structure handled by CCID layer */ struct ccid { enum icc_state icc_state; @@ -1297,6 +1295,7 @@ icc_handle_timeout (struct ccid *c) } static struct ccid ccid; +enum icc_state *icc_state_p = &ccid.icc_state; /* * Another Tx done callback @@ -1458,6 +1457,5 @@ ccid_thread (chopstx_t thd) c->application = 0; } - icc_state_p = NULL; return NULL; } diff --git a/src/usb_ctrl.c b/src/usb_ctrl.c index b8d5122..0d69f05 100644 --- a/src/usb_ctrl.c +++ b/src/usb_ctrl.c @@ -280,7 +280,7 @@ usb_cb_setup (uint8_t req, uint8_t req_no, struct control_info *detail) if (req_no == USB_FSIJ_GNUK_DOWNLOAD) { - if (icc_state_p == NULL || *icc_state_p != ICC_STATE_EXITED) + if (*icc_state_p != ICC_STATE_EXITED) return USB_UNSUPPORT; if (addr < &_regnual_start || addr + detail->len > __heap_end__) @@ -294,7 +294,7 @@ usb_cb_setup (uint8_t req, uint8_t req_no, struct control_info *detail) } else if (req_no == USB_FSIJ_GNUK_EXEC && detail->len == 0) { - if (icc_state_p == NULL || *icc_state_p != ICC_STATE_EXITED) + if (*icc_state_p != ICC_STATE_EXITED) return USB_UNSUPPORT; if (((uint32_t)addr & 0x03)) @@ -398,12 +398,12 @@ usb_cb_ctrl_write_finish (uint8_t req, uint8_t req_no, uint16_t value) { if (USB_SETUP_SET (req) && req_no == USB_FSIJ_GNUK_EXEC) { - if (icc_state_p == NULL || *icc_state_p != ICC_STATE_EXITED) + if (*icc_state_p != ICC_STATE_EXITED) return; (void)value; (void)index; usb_lld_prepare_shutdown (); /* No further USB communication */ - *icc_state_p = ICC_STATE_EXEC_REQUESTED; + led_blink (LED_GNUK_EXEC); /* Notify the main. */ } } #ifdef HID_CARD_CHANGE_SUPPORT diff --git a/tool/upgrade_by_passwd.py b/tool/upgrade_by_passwd.py index 244c5d0..ba03234 100755 --- a/tool/upgrade_by_passwd.py +++ b/tool/upgrade_by_passwd.py @@ -78,8 +78,6 @@ def main(wait_e, keyno, passwd, data_regnual, data_upgrade): break except: pass - print("Wait 3 seconds...") - time.sleep(3) # Then, send upgrade program... mem_info = reg.mem_info() print("%08x:%08x" % mem_info) @@ -92,8 +90,8 @@ def main(wait_e, keyno, passwd, data_regnual, data_upgrade): from getpass import getpass -# This should be event driven, not guessing some period. -DEFAULT_WAIT_FOR_REENUMERATION=3 +# This should be event driven, not guessing some period, or polling. +DEFAULT_WAIT_FOR_REENUMERATION=1 if __name__ == '__main__': if os.getcwd() != os.path.dirname(os.path.abspath(__file__)):