Added custom INS (named EXTRAS) to support different extra commands. At this moment:
- 0xA: gets/sets the datetime. - 0x6: enables/disables press to confirm (BOOTSEL). It allows other dynamic device options. At this moment, only press to confirm option is available. Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
@@ -1740,9 +1740,10 @@ static int cmd_derive_asym() {
|
|||||||
return SW_OK();
|
return SW_OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmd_datetime() {
|
static int cmd_extras() {
|
||||||
if (P1(apdu) != 0x0 || P2(apdu) != 0x0)
|
if (P2(apdu) != 0x0)
|
||||||
return SW_INCORRECT_P1P2();
|
return SW_INCORRECT_P1P2();
|
||||||
|
if (P1(apdu) == 0xA) { //datetime operations
|
||||||
if (apdu.cmd_apdu_data_len == 0) {
|
if (apdu.cmd_apdu_data_len == 0) {
|
||||||
datetime_t dt;
|
datetime_t dt;
|
||||||
if (!rtc_get_datetime(&dt))
|
if (!rtc_get_datetime(&dt))
|
||||||
@@ -1770,9 +1771,28 @@ static int cmd_datetime() {
|
|||||||
if (!rtc_set_datetime(&dt))
|
if (!rtc_set_datetime(&dt))
|
||||||
return SW_WRONG_DATA();
|
return SW_WRONG_DATA();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if (P1(apdu) == 0x6) { //dynamic options
|
||||||
|
if (apdu.cmd_apdu_data_len > sizeof(uint8_t))
|
||||||
|
return SW_WRONG_LENGTH();
|
||||||
|
uint16_t opts = get_device_options();
|
||||||
|
if (apdu.cmd_apdu_data_len == 0) {
|
||||||
|
res_APDU[res_APDU_size++] = opts >> 8;
|
||||||
|
res_APDU[res_APDU_size++] = opts & 0xff;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
uint8_t newopts[] = { apdu.cmd_apdu_data[0], (opts & 0xff) };
|
||||||
|
file_t *tf = search_by_fid(EF_DEVOPS, NULL, SPECIFY_EF);
|
||||||
|
flash_write_data_to_file(tf, newopts, sizeof(newopts));
|
||||||
|
low_flash_available();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return SW_INCORRECT_P1P2();
|
||||||
return SW_OK();
|
return SW_OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef struct cmd
|
typedef struct cmd
|
||||||
{
|
{
|
||||||
uint8_t ins;
|
uint8_t ins;
|
||||||
@@ -1794,7 +1814,7 @@ typedef struct cmd
|
|||||||
#define INS_DERIVE_ASYM 0x76
|
#define INS_DERIVE_ASYM 0x76
|
||||||
#define INS_CIPHER_SYM 0x78
|
#define INS_CIPHER_SYM 0x78
|
||||||
#define INS_CHALLENGE 0x84
|
#define INS_CHALLENGE 0x84
|
||||||
#define INS_DATETIME 0x88
|
#define INS_EXTRAS 0x88
|
||||||
#define INS_SELECT_FILE 0xA4
|
#define INS_SELECT_FILE 0xA4
|
||||||
#define INS_READ_BINARY 0xB0
|
#define INS_READ_BINARY 0xB0
|
||||||
#define INS_READ_BINARY_ODD 0xB1
|
#define INS_READ_BINARY_ODD 0xB1
|
||||||
@@ -1822,7 +1842,7 @@ static const cmd_t cmds[] = {
|
|||||||
{ INS_DECRYPT_ASYM, cmd_decrypt_asym },
|
{ INS_DECRYPT_ASYM, cmd_decrypt_asym },
|
||||||
{ INS_CIPHER_SYM, cmd_cipher_sym },
|
{ INS_CIPHER_SYM, cmd_cipher_sym },
|
||||||
{ INS_DERIVE_ASYM, cmd_derive_asym },
|
{ INS_DERIVE_ASYM, cmd_derive_asym },
|
||||||
{ INS_DATETIME, cmd_datetime },
|
{ INS_EXTRAS, cmd_extras },
|
||||||
{ 0x00, 0x0}
|
{ 0x00, 0x0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user