nfc_emv_parser.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "nfc_emv_parser.h"
  2. #include <file-worker.h>
  3. static bool
  4. nfc_emv_parser_get_value(const char* file_path, string_t key, char delimiter, string_t value) {
  5. bool found = false;
  6. FileWorker* file_worker = file_worker_alloc(true);
  7. if(file_worker_open(file_worker, file_path, FSAM_READ, FSOM_OPEN_EXISTING)) {
  8. if(file_worker_get_value_from_key(file_worker, key, delimiter, value)) {
  9. found = true;
  10. }
  11. }
  12. file_worker_close(file_worker);
  13. file_worker_free(file_worker);
  14. return found;
  15. }
  16. bool nfc_emv_parser_get_aid_name(uint8_t* aid, uint8_t aid_len, string_t aid_name) {
  17. bool result = false;
  18. string_t key;
  19. string_init(key);
  20. for(uint8_t i = 0; i < aid_len; i++) {
  21. string_cat_printf(key, "%02X", aid[i]);
  22. }
  23. result = nfc_emv_parser_get_value("/ext/nfc/emv/aid.nfc", key, ' ', aid_name);
  24. string_clear(key);
  25. return result;
  26. }
  27. bool nfc_emv_parser_get_country_name(uint16_t country_code, string_t country_name) {
  28. bool result = false;
  29. string_t key;
  30. string_init_printf(key, "%04X", country_code);
  31. result = nfc_emv_parser_get_value("/ext/nfc/emv/country_code.nfc", key, ' ', country_name);
  32. string_clear(key);
  33. return result;
  34. }
  35. bool nfc_emv_parser_get_currency_name(uint16_t currency_code, string_t currency_name) {
  36. bool result = false;
  37. string_t key;
  38. string_init_printf(key, "%04X", currency_code);
  39. result = nfc_emv_parser_get_value("/ext/nfc/emv/currency_code.nfc", key, ' ', currency_name);
  40. string_clear(key);
  41. return result;
  42. }