2021-06-15 14:54:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-05-18 18:12:01 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define MAX_APDU_LEN 255
|
|
|
|
|
|
|
|
#define EMV_TAG_APP_TEMPLATE 0x61
|
|
|
|
#define EMV_TAG_AID 0x4F
|
|
|
|
#define EMV_TAG_PRIORITY 0x87
|
|
|
|
#define EMV_TAG_PDOL 0x9F38
|
|
|
|
#define EMV_TAG_CARD_NAME 0x50
|
|
|
|
#define EMV_TAG_FCI 0xBF0C
|
|
|
|
#define EMV_TAG_LOG_CTRL 0x9F4D
|
|
|
|
#define EMV_TAG_CARD_NUM 0x57
|
|
|
|
#define EMV_TAG_PAN 0x5A
|
|
|
|
#define EMV_TAG_AFL 0x94
|
2021-08-04 18:58:11 +00:00
|
|
|
#define EMV_TAG_EXP_DATE 0x5F24
|
2021-08-20 19:56:43 +00:00
|
|
|
#define EMV_TAG_COUNTRY_CODE 0x5F28
|
|
|
|
#define EMV_TAG_CURRENCY_CODE 0x9F42
|
2021-08-04 18:58:11 +00:00
|
|
|
#define EMV_TAG_CARDHOLDER_NAME 0x5F20
|
2021-05-18 18:12:01 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint16_t tag;
|
|
|
|
uint8_t data[];
|
|
|
|
} PDOLValue;
|
|
|
|
|
2022-02-13 19:24:03 +00:00
|
|
|
extern const PDOLValue* const pdol_values[];
|
2021-05-18 18:12:01 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint8_t size;
|
|
|
|
uint8_t data[MAX_APDU_LEN];
|
|
|
|
} APDU;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint8_t priority;
|
|
|
|
uint8_t aid[16];
|
|
|
|
uint8_t aid_len;
|
|
|
|
char name[32];
|
2021-10-05 05:14:19 +00:00
|
|
|
uint8_t card_number[10];
|
|
|
|
uint8_t card_number_len;
|
2021-08-04 18:58:11 +00:00
|
|
|
uint8_t exp_month;
|
|
|
|
uint8_t exp_year;
|
2021-08-20 19:56:43 +00:00
|
|
|
uint16_t country_code;
|
|
|
|
uint16_t currency_code;
|
2021-05-18 18:12:01 +00:00
|
|
|
APDU pdol;
|
|
|
|
APDU afl;
|
|
|
|
} EmvApplication;
|
|
|
|
|
2021-05-25 23:54:44 +00:00
|
|
|
/* Terminal emulation */
|
2021-05-18 18:12:01 +00:00
|
|
|
uint16_t emv_prepare_select_ppse(uint8_t* dest);
|
|
|
|
bool emv_decode_ppse_response(uint8_t* buff, uint16_t len, EmvApplication* app);
|
|
|
|
|
|
|
|
uint16_t emv_prepare_select_app(uint8_t* dest, EmvApplication* app);
|
|
|
|
bool emv_decode_select_app_response(uint8_t* buff, uint16_t len, EmvApplication* app);
|
|
|
|
|
|
|
|
uint16_t emv_prepare_get_proc_opt(uint8_t* dest, EmvApplication* app);
|
|
|
|
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);
|
2021-05-25 23:54:44 +00:00
|
|
|
|
|
|
|
/* 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);
|