emv_decoder.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #include <string.h>
  5. #define MAX_APDU_LEN 255
  6. #define EMV_TAG_APP_TEMPLATE 0x61
  7. #define EMV_TAG_AID 0x4F
  8. #define EMV_TAG_PRIORITY 0x87
  9. #define EMV_TAG_PDOL 0x9F38
  10. #define EMV_TAG_CARD_NAME 0x50
  11. #define EMV_TAG_FCI 0xBF0C
  12. #define EMV_TAG_LOG_CTRL 0x9F4D
  13. #define EMV_TAG_CARD_NUM 0x57
  14. #define EMV_TAG_PAN 0x5A
  15. #define EMV_TAG_AFL 0x94
  16. #define EMV_TAG_EXP_DATE 0x5F24
  17. #define EMV_TAG_COUNTRY_CODE 0x5F28
  18. #define EMV_TAG_CURRENCY_CODE 0x9F42
  19. #define EMV_TAG_CARDHOLDER_NAME 0x5F20
  20. typedef struct {
  21. uint16_t tag;
  22. uint8_t data[];
  23. } PDOLValue;
  24. extern const PDOLValue* pdol_values[];
  25. typedef struct {
  26. uint8_t size;
  27. uint8_t data[MAX_APDU_LEN];
  28. } APDU;
  29. typedef struct {
  30. uint8_t priority;
  31. uint8_t aid[16];
  32. uint8_t aid_len;
  33. char name[32];
  34. uint8_t card_number[8];
  35. uint8_t exp_month;
  36. uint8_t exp_year;
  37. uint16_t country_code;
  38. uint16_t currency_code;
  39. APDU pdol;
  40. APDU afl;
  41. } EmvApplication;
  42. /* Terminal emulation */
  43. uint16_t emv_prepare_select_ppse(uint8_t* dest);
  44. bool emv_decode_ppse_response(uint8_t* buff, uint16_t len, EmvApplication* app);
  45. uint16_t emv_prepare_select_app(uint8_t* dest, EmvApplication* app);
  46. bool emv_decode_select_app_response(uint8_t* buff, uint16_t len, EmvApplication* app);
  47. uint16_t emv_prepare_get_proc_opt(uint8_t* dest, EmvApplication* app);
  48. bool emv_decode_get_proc_opt(uint8_t* buff, uint16_t len, EmvApplication* app);
  49. uint16_t emv_prepare_read_sfi_record(uint8_t* dest, uint8_t sfi, uint8_t record_num);
  50. bool emv_decode_read_sfi_record(uint8_t* buff, uint16_t len, EmvApplication* app);
  51. /* Card emulation */
  52. uint16_t emv_select_ppse_ans(uint8_t* buff);
  53. uint16_t emv_select_app_ans(uint8_t* buff);
  54. uint16_t emv_get_proc_opt_ans(uint8_t* buff);