DnDpinentry: cancellation

This commit is contained in:
NIIBE Yutaka
2011-12-20 10:39:47 +09:00
parent a08669dfcd
commit c0ab2ae830
5 changed files with 54 additions and 6 deletions

View File

@@ -362,6 +362,7 @@ extern void msc_init (void);
extern void msc_media_insert_change (int available);
extern int msc_scsi_write (uint32_t lba, const uint8_t *buf, size_t size);
extern int msc_scsi_read (uint32_t lba, const uint8_t **sector_p);
extern void msc_scsi_stop (uint8_t code);
# endif
#define PIN_INPUT_CURRENT 1
#define PIN_INPUT_NEW 2

View File

@@ -72,13 +72,16 @@ pinpad_getline (int msg_code, systime_t timeout)
chSysUnlock ();
led_blink (0);
if (msg == 1)
if (msg != 0)
break;
}
msc_media_insert_change (0);
return pin_input_len;
if (msg == 1)
return pin_input_len;
else
return -1; /* cancel */
}
static void pinpad_input (void)
@@ -89,10 +92,13 @@ static void pinpad_input (void)
chSysUnlock ();
}
static void pinpad_finish_entry (void)
static void pinpad_finish_entry (int cancel)
{
chSysLock ();
pin_thread->p_u.rdymsg = 1;
if (cancel)
pin_thread->p_u.rdymsg = 2;
else
pin_thread->p_u.rdymsg = 1;
chSchReadyI (pin_thread);
chSysUnlock ();
}
@@ -328,7 +334,7 @@ static void parse_directory_sector (const uint8_t *p, uint8_t index)
}
if (index == 0 && num_children == 1)
pinpad_finish_entry ();
pinpad_finish_entry (0);
else if (input)
pinpad_input ();
}
@@ -357,3 +363,10 @@ msc_scsi_write (uint32_t lba, const uint8_t *buf, size_t size)
return 0;
}
}
void
msc_scsi_stop (uint8_t code)
{
(void)code;
pinpad_finish_entry (1);
}

View File

@@ -388,6 +388,17 @@ void msc_handle_command (void)
buf[11] = (uint8_t)(secsize >> 0);
msc_send_result (buf, 12);
return;
case SCSI_START_STOP_UNIT:
if (CBW.CBWCB[4] == 0x00 /* stop */
|| CBW.CBWCB[4] == 0x02 /* eject */ || CBW.CBWCB[4] == 0x03 /* close */)
{
msc_scsi_stop (CBW.CBWCB[4]);
set_scsi_sense_data (0x05, 0x24); /* ILLEGAL_REQUEST */
contingent_allegiance = 1;
keep_contingent_allegiance = 1;
}
/* CBW.CBWCB[4] == 0x01 *//* start */
goto success;
case SCSI_TEST_UNIT_READY:
if (contingent_allegiance)
{
@@ -397,9 +408,9 @@ void msc_handle_command (void)
return;
}
/* fall through */
success:
case SCSI_SYNCHRONIZE_CACHE:
case SCSI_VERIFY10:
case SCSI_START_STOP_UNIT:
case SCSI_ALLOW_MEDIUM_REMOVAL:
CSW.bCSWStatus = MSC_CSW_STATUS_PASSED;
CSW.dCSWDataResidue = CBW.dCBWDataTransferLength;