fix things around write_binary

This commit is contained in:
NIIBE Yutaka
2011-02-09 14:06:57 +09:00
parent 677fc00489
commit 6f19c97afd
7 changed files with 42 additions and 41 deletions

View File

@@ -416,7 +416,7 @@ const uint8_t openpgpcard_aid[] = {
static int
do_openpgpcard_aid (uint16_t tag, int with_tag)
{
const uint16_t *vid_p = (const uint16_t *)&openpgpcard_aid[8];
uint16_t vid = *((const volatile uint16_t *)&openpgpcard_aid[8]);
if (with_tag)
{
@@ -424,7 +424,7 @@ do_openpgpcard_aid (uint16_t tag, int with_tag)
*res_p++ = 16;
}
if (*vid_p == 0xffff || *vid_p == 0x0000)
if (vid == 0xffff || vid == 0x0000)
{
const uint8_t *u = unique_device_id ();

View File

@@ -870,7 +870,7 @@ cmd_update_binary (void)
}
if ((cmd_APDU[2] & 0x80))
if ((cmd_APDU[2] & 0x7f) <= 0x01)
if ((cmd_APDU[2] & 0x7f) <= FILEID_RANDOM)
{
file_selection = FILE_EF_CH_CERTIFICATE + (cmd_APDU[2] & 0x7f);
r = flash_erase_binary (file_selection - FILE_EF_CH_CERTIFICATE);
@@ -941,7 +941,7 @@ cmd_write_binary (void)
}
if ((cmd_APDU[2] & 0x80))
if ((cmd_APDU[2] & 0x7f) == FILEID_SERIAL_NO)
if ((cmd_APDU[2] & 0x7f) <= FILEID_SERIAL_NO)
{
file_selection = FILE_EF_CH_CERTIFICATE + (cmd_APDU[2] & 0x7f);
offset = 0;
@@ -953,7 +953,9 @@ cmd_write_binary (void)
}
else
{
if (file_selection != FILEID_SERIAL_NO)
if (file_selection != FILE_EF_CH_CERTIFICATE
&& file_selection != FILE_EF_RANDOM
&& file_selection != FILEID_SERIAL_NO)
{
GPG_COMMAND_NOT_ALLOWED ();
return;

View File

@@ -37,19 +37,14 @@
#endif
static uint8_t gnukStringSerial[] = {
14*2+2, /* bLength */
13*2+2, /* bLength */
USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */
#if defined(SERIAL_NUMBER_IN_AID)
'F', 0, /* 'F' for Fixed */
#else
'C', 0, /* 'C' for Chip uniqure ID */
#endif
'-', 0,
'0', 0, '.', 0, '8', 0, /* Version number of Gnuk */
'0', 0, '.', 0, '1', 0, '0', 0, /* Version number of Gnuk */
'-', 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
#define ID_OFFSET 12
static void
gnuk_device_init (void)
@@ -59,10 +54,10 @@ gnuk_device_init (void)
for (i = 0; i < 4; i++)
{
gnukStringSerial[i*4+14] = (u[i*2] >> 4) + 'A';
gnukStringSerial[i*4+15] = 0;
gnukStringSerial[i*4+16] = (u[i*2+1] & 0x0f) + 'A';
gnukStringSerial[i*4+17] = 0;
gnukStringSerial[i*4+ID_OFFSET+0] = (u[i*2] >> 4) + 'A';
gnukStringSerial[i*4+ID_OFFSET+1] = 0;
gnukStringSerial[i*4+ID_OFFSET+2] = (u[i*2+1] & 0x0f) + 'A';
gnukStringSerial[i*4+ID_OFFSET+3] = 0;
}
pInformation->Current_Configuration = 0;