nfca.c 814 B

1234567891011121314151617181920212223242526272829303132
  1. #include "nfca.h"
  2. #include <string.h>
  3. #include <stdio.h>
  4. #define NFCA_CMD_RATS (0xE0U)
  5. typedef struct {
  6. uint8_t cmd;
  7. uint8_t param;
  8. } nfca_cmd_rats;
  9. static uint8_t nfca_default_ats[] = {0x05, 0x78, 0x80, 0x80, 0x00};
  10. static uint8_t nfca_sleep_req[] = {0x50, 0x00};
  11. bool nfca_emulation_handler(
  12. uint8_t* buff_rx,
  13. uint16_t buff_rx_len,
  14. uint8_t* buff_tx,
  15. uint16_t* buff_tx_len) {
  16. bool sleep = false;
  17. uint8_t rx_bytes = buff_rx_len / 8;
  18. if(rx_bytes == sizeof(nfca_sleep_req) && !memcmp(buff_rx, nfca_sleep_req, rx_bytes)) {
  19. sleep = true;
  20. } else if(rx_bytes == sizeof(nfca_cmd_rats) && buff_rx[0] == NFCA_CMD_RATS) {
  21. memcpy(buff_tx, nfca_default_ats, sizeof(nfca_default_ats));
  22. *buff_tx_len = sizeof(nfca_default_ats) * 8;
  23. }
  24. return sleep;
  25. }