Emit LED light

This commit is contained in:
NIIBE Yutaka 2012-06-08 09:48:40 +09:00
parent 17fd82ffa1
commit 258552e544
6 changed files with 35 additions and 20 deletions

View File

@ -1,3 +1,14 @@
2012-06-08 Niibe Yutaka <gniibe@fsij.org>
Emit LED light while computation (or asking user input).
* src/usb-icc.c (icc_handle_timeout): Call led_blink.
* src/openpgp.c (cmd_pso, cmd_internal_authenticate): Call
LED_WAIT_MODE, LED_STATUS_MODE to show "it's under computation".
* src/openpgp-do.c (gpg_do_keygen): Ditto.
* src/gnuk.h (LED_WAIT_MODE): Rename (was: LED_INPUT_MODE).
* src/main.c (display_interaction): Change the behavior of LED,
now, it's mostly ON (was: mostly OFF).
2012-06-07 Niibe Yutaka <gniibe@fsij.org>
* src/openpgp.c (cmd_internal_authenticate): Add check for input

View File

@ -367,7 +367,7 @@ extern const uint8_t gnukStringSerial[];
#define LED_ONESHOT_LONG ((eventmask_t)2)
#define LED_TWOSHOT ((eventmask_t)4)
#define LED_STATUS_MODE ((eventmask_t)8)
#define LED_INPUT_MODE ((eventmask_t)16)
#define LED_WAIT_MODE ((eventmask_t)16)
#define LED_FATAL_MODE ((eventmask_t)32)
extern Thread *main_thread;
extern void led_blink (int spec);

View File

@ -210,14 +210,14 @@ static volatile uint8_t fatal_code;
Thread *main_thread;
#define GNUK_INIT 0
#define GNUK_RUNNING 1
#define GNUK_INPUT_WAIT 2
#define GNUK_FATAL 255
#define GNUK_INIT 0
#define GNUK_RUNNING 1
#define GNUK_WAIT 2
#define GNUK_FATAL 255
/*
* 0 for initializing
* 1 for normal mode
* 2 for input waiting
* 2 for input waiting / under calculation
* 255 for fatal
*/
static uint8_t main_mode;
@ -226,10 +226,11 @@ static void display_interaction (void)
{
eventmask_t m;
set_led (1);
while (1)
{
m = chEvtWaitOne (ALL_EVENTS);
set_led (1);
set_led (0);
switch (m)
{
case LED_ONESHOT_SHORT:
@ -239,24 +240,21 @@ static void display_interaction (void)
chThdSleep (MS2ST (400));
break;
case LED_TWOSHOT:
chThdSleep (MS2ST (50));
set_led (0);
chThdSleep (MS2ST (50));
set_led (1);
chThdSleep (MS2ST (50));
set_led (0);
chThdSleep (MS2ST (50));
break;
case LED_STATUS_MODE:
chThdSleep (MS2ST (400));
set_led (0);
return;
case LED_FATAL_MODE:
main_mode = GNUK_FATAL;
set_led (0);
return;
default:
break;
}
set_led (0);
set_led (1);
}
}
@ -434,11 +432,8 @@ main (int argc, char *argv[])
case LED_FATAL_MODE:
main_mode = GNUK_FATAL;
break;
case LED_INPUT_MODE:
main_mode = GNUK_INPUT_WAIT;
set_led (1);
chThdSleep (MS2ST (400));
set_led (0);
case LED_WAIT_MODE:
main_mode = GNUK_WAIT;
break;
default:
break;
@ -455,7 +450,7 @@ main (int argc, char *argv[])
set_led (0);
chThdSleep (LED_TIMEOUT_STOP * 3);
break;
case GNUK_INPUT_WAIT:
case GNUK_WAIT:
display_interaction ();
break;
case GNUK_RUNNING:

View File

@ -1506,7 +1506,9 @@ gpg_do_keygen (uint8_t kk_byte)
else
keystring_admin = NULL;
chEvtSignal (main_thread, LED_WAIT_MODE);
p_q_modulus = rsa_genkey ();
chEvtSignal (main_thread, LED_STATUS_MODE);
if (p_q_modulus == NULL)
{
GPG_MEMORY_FAILURE ();

View File

@ -118,7 +118,7 @@ get_pinpad_input (int msg_code)
{
int r;
chEvtSignal (main_thread, LED_INPUT_MODE);
chEvtSignal (main_thread, LED_WAIT_MODE);
r = pinpad_getline (msg_code, MS2ST (8000));
chEvtSignal (main_thread, LED_STATUS_MODE);
return r;
@ -701,8 +701,10 @@ cmd_pso (void)
DEBUG_SHORT (len);
DEBUG_BINARY (&kd[GPG_KEY_FOR_SIGNING], KEY_CONTENT_LEN);
chEvtSignal (main_thread, LED_WAIT_MODE);
r = rsa_sign (apdu.cmd_apdu_data, res_APDU, len,
&kd[GPG_KEY_FOR_SIGNING]);
chEvtSignal (main_thread, LED_STATUS_MODE);
if (r < 0)
{
ac_reset_pso_cds ();
@ -727,8 +729,10 @@ cmd_pso (void)
/* Skip padding 0x00 */
len--;
chEvtSignal (main_thread, LED_WAIT_MODE);
r = rsa_decrypt (apdu.cmd_apdu_data+1, res_APDU, len,
&kd[GPG_KEY_FOR_DECRYPTION]);
chEvtSignal (main_thread, LED_STATUS_MODE);
if (r < 0)
GPG_ERROR ();
}
@ -772,8 +776,10 @@ cmd_internal_authenticate (void)
return;
}
chEvtSignal (main_thread, LED_WAIT_MODE);
r = rsa_sign (apdu.cmd_apdu_data, res_APDU, len,
&kd[GPG_KEY_FOR_AUTHENTICATION]);
chEvtSignal (main_thread, LED_STATUS_MODE);
if (r < 0)
GPG_ERROR ();
}

View File

@ -1260,6 +1260,7 @@ icc_handle_timeout (struct ccid *c)
{
case ICC_STATE_EXECUTE:
icc_send_data_block (c, ICC_CMD_STATUS_TIMEEXT);
led_blink (2);
break;
default:
break;