[FL-1039] Emv emulation (#491)

* nfc: add emulate emv to submenu
* api-hal-nfc: add emv emulation
This commit is contained in:
gornekich
2021-05-26 02:54:44 +03:00
committed by GitHub
parent d92bb18cca
commit e620b310b7
12 changed files with 282 additions and 48 deletions

View File

@@ -37,6 +37,25 @@ const PDOLValue* pdol_values[] = {
&pdol_unpredict_number,
};
static const uint8_t select_ppse_ans[] = {
0x6F, 0x29, 0x84, 0x0E, 0x32, 0x50, 0x41, 0x59, 0x2E,
0x53, 0x59, 0x53, 0x2E, 0x44, 0x44, 0x46, 0x30, 0x31,
0xA5, 0x17, 0xBF, 0x0C, 0x14, 0x61, 0x12, 0x4F, 0x07,
0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10, 0x50, 0x04,
0x56, 0x49, 0x53, 0x41, 0x87, 0x01, 0x01, 0x90, 0x00};
static const uint8_t select_app_ans[] = {
0x6F, 0x20, 0x84, 0x07, 0xA0, 0x00, 0x00, 0x00, 0x03,
0x10, 0x10, 0xA5, 0x15, 0x50, 0x04, 0x56, 0x49, 0x53,
0x41, 0x9F, 0x38, 0x0C, 0x9F, 0x66, 0x04, 0x9F, 0x02,
0x06, 0x9F, 0x37, 0x04, 0x5F, 0x2A, 0x02, 0x90, 0x00};
static const uint8_t pdol_ans[] = {
0x77, 0x40, 0x82, 0x02, 0x20, 0x00, 0x57, 0x13, 0x55, 0x70, 0x73, 0x83,
0x85, 0x87, 0x73, 0x31, 0xD1, 0x80, 0x22, 0x01, 0x38, 0x84, 0x77, 0x94,
0x00, 0x00, 0x1F, 0x5F, 0x34, 0x01, 0x00, 0x9F, 0x10, 0x07, 0x06, 0x01,
0x11, 0x03, 0x80, 0x00, 0x00, 0x9F, 0x26, 0x08, 0x7A, 0x65, 0x7F, 0xD3,
0x52, 0x96, 0xC9, 0x85, 0x9F, 0x27, 0x01, 0x00, 0x9F, 0x36, 0x02, 0x06,
0x0C, 0x9F, 0x6C, 0x02, 0x10, 0x00, 0x90, 0x00};
static uint16_t emv_parse_TLV(uint8_t* dest, uint8_t* src, uint16_t* idx) {
uint8_t len = src[*idx + 1];
memcpy(dest, &src[*idx + 2], len);
@@ -203,3 +222,18 @@ bool emv_decode_read_sfi_record(uint8_t* buff, uint16_t len, EmvApplication* app
}
return false;
}
uint16_t emv_select_ppse_ans(uint8_t* buff) {
memcpy(buff, select_ppse_ans, sizeof(select_ppse_ans));
return sizeof(select_ppse_ans);
}
uint16_t emv_select_app_ans(uint8_t* buff) {
memcpy(buff, select_app_ans, sizeof(select_app_ans));
return sizeof(select_app_ans);
}
uint16_t emv_get_proc_opt_ans(uint8_t* buff) {
memcpy(buff, pdol_ans, sizeof(pdol_ans));
return sizeof(pdol_ans);
}

View File

@@ -37,6 +37,7 @@ typedef struct {
APDU afl;
} EmvApplication;
/* Terminal emulation */
uint16_t emv_prepare_select_ppse(uint8_t* dest);
bool emv_decode_ppse_response(uint8_t* buff, uint16_t len, EmvApplication* app);
@@ -48,3 +49,8 @@ bool emv_decode_get_proc_opt(uint8_t* buff, uint16_t len, EmvApplication* app);
uint16_t emv_prepare_read_sfi_record(uint8_t* dest, uint8_t sfi, uint8_t record_num);
bool emv_decode_read_sfi_record(uint8_t* buff, uint16_t len, EmvApplication* app);
/* Card emulation */
uint16_t emv_select_ppse_ans(uint8_t* buff);
uint16_t emv_select_app_ans(uint8_t* buff);
uint16_t emv_get_proc_opt_ans(uint8_t* buff);