emv_decoder.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_CARDHOLDER_NAME 0x5F20
  18. typedef struct {
  19. uint16_t tag;
  20. uint8_t data[];
  21. } PDOLValue;
  22. extern const PDOLValue* pdol_values[];
  23. typedef struct {
  24. uint8_t size;
  25. uint8_t data[MAX_APDU_LEN];
  26. } APDU;
  27. typedef struct {
  28. uint8_t priority;
  29. uint8_t aid[16];
  30. uint8_t aid_len;
  31. char name[32];
  32. uint8_t card_number[8];
  33. uint8_t exp_month;
  34. uint8_t exp_year;
  35. char crdholder_name[32];
  36. APDU pdol;
  37. APDU afl;
  38. } EmvApplication;
  39. /* Terminal emulation */
  40. uint16_t emv_prepare_select_ppse(uint8_t* dest);
  41. bool emv_decode_ppse_response(uint8_t* buff, uint16_t len, EmvApplication* app);
  42. uint16_t emv_prepare_select_app(uint8_t* dest, EmvApplication* app);
  43. bool emv_decode_select_app_response(uint8_t* buff, uint16_t len, EmvApplication* app);
  44. uint16_t emv_prepare_get_proc_opt(uint8_t* dest, EmvApplication* app);
  45. bool emv_decode_get_proc_opt(uint8_t* buff, uint16_t len, EmvApplication* app);
  46. uint16_t emv_prepare_read_sfi_record(uint8_t* dest, uint8_t sfi, uint8_t record_num);
  47. bool emv_decode_read_sfi_record(uint8_t* buff, uint16_t len, EmvApplication* app);
  48. /* Card emulation */
  49. uint16_t emv_select_ppse_ans(uint8_t* buff);
  50. uint16_t emv_select_app_ans(uint8_t* buff);
  51. uint16_t emv_get_proc_opt_ans(uint8_t* buff);