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:
Pol Henarejos
2022-04-06 14:41:09 +02:00
parent 532d79bcc5
commit 7060d2d2ca

View File

@@ -1740,39 +1740,59 @@ 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 (apdu.cmd_apdu_data_len == 0) { if (P1(apdu) == 0xA) { //datetime operations
datetime_t dt; if (apdu.cmd_apdu_data_len == 0) {
if (!rtc_get_datetime(&dt)) datetime_t dt;
return SW_EXEC_ERROR(); if (!rtc_get_datetime(&dt))
res_APDU[res_APDU_size++] = dt.year >> 8; return SW_EXEC_ERROR();
res_APDU[res_APDU_size++] = dt.year & 0xff; res_APDU[res_APDU_size++] = dt.year >> 8;
res_APDU[res_APDU_size++] = dt.month; res_APDU[res_APDU_size++] = dt.year & 0xff;
res_APDU[res_APDU_size++] = dt.day; res_APDU[res_APDU_size++] = dt.month;
res_APDU[res_APDU_size++] = dt.dotw; res_APDU[res_APDU_size++] = dt.day;
res_APDU[res_APDU_size++] = dt.hour; res_APDU[res_APDU_size++] = dt.dotw;
res_APDU[res_APDU_size++] = dt.min; res_APDU[res_APDU_size++] = dt.hour;
res_APDU[res_APDU_size++] = dt.sec; res_APDU[res_APDU_size++] = dt.min;
res_APDU[res_APDU_size++] = dt.sec;
}
else {
if (apdu.cmd_apdu_data_len != 8)
return SW_WRONG_LENGTH();
datetime_t dt;
dt.year = (apdu.cmd_apdu_data[0] << 8) | (apdu.cmd_apdu_data[1]);
dt.month = apdu.cmd_apdu_data[2];
dt.day = apdu.cmd_apdu_data[3];
dt.dotw = apdu.cmd_apdu_data[4];
dt.hour = apdu.cmd_apdu_data[5];
dt.min = apdu.cmd_apdu_data[6];
dt.sec = apdu.cmd_apdu_data[7];
if (!rtc_set_datetime(&dt))
return SW_WRONG_DATA();
}
} }
else { else if (P1(apdu) == 0x6) { //dynamic options
if (apdu.cmd_apdu_data_len != 8) if (apdu.cmd_apdu_data_len > sizeof(uint8_t))
return SW_WRONG_LENGTH(); return SW_WRONG_LENGTH();
datetime_t dt; uint16_t opts = get_device_options();
dt.year = (apdu.cmd_apdu_data[0] << 8) | (apdu.cmd_apdu_data[1]); if (apdu.cmd_apdu_data_len == 0) {
dt.month = apdu.cmd_apdu_data[2]; res_APDU[res_APDU_size++] = opts >> 8;
dt.day = apdu.cmd_apdu_data[3]; res_APDU[res_APDU_size++] = opts & 0xff;
dt.dotw = apdu.cmd_apdu_data[4]; }
dt.hour = apdu.cmd_apdu_data[5]; else {
dt.min = apdu.cmd_apdu_data[6]; uint8_t newopts[] = { apdu.cmd_apdu_data[0], (opts & 0xff) };
dt.sec = apdu.cmd_apdu_data[7]; file_t *tf = search_by_fid(EF_DEVOPS, NULL, SPECIFY_EF);
if (!rtc_set_datetime(&dt)) flash_write_data_to_file(tf, newopts, sizeof(newopts));
return SW_WRONG_DATA(); 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}
}; };