Module_RFID.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Module_RFID.h
  3. *
  4. * Created on: 2019-10-24
  5. * Update: 2022-08-09
  6. * Author: Eason Yang
  7. * Version: V0.04
  8. *
  9. * History
  10. * 1. Added : Reyax constant.
  11. *
  12. *
  13. *
  14. *
  15. *
  16. */
  17. #ifndef LIB_RFID_H_
  18. #define LIB_RFID_H_
  19. #include <sys/time.h>
  20. #include <sys/timeb.h>
  21. #include <sys/types.h>
  22. #include <sys/stat.h>
  23. #include <sys/types.h>
  24. #include <sys/ioctl.h>
  25. #include <sys/socket.h>
  26. #include <sys/ipc.h>
  27. #include <sys/shm.h>
  28. #include <sys/shm.h>
  29. #include <sys/mman.h>
  30. #include <linux/wireless.h>
  31. #include <arpa/inet.h>
  32. #include <netinet/in.h>
  33. #include <unistd.h>
  34. #include <stdarg.h>
  35. #include <stdio.h> /* Standard input/output definitions */
  36. #include <stdlib.h>
  37. #include <unistd.h> /* UNIX standard function definitions */
  38. #include <fcntl.h> /* File control definitions */
  39. #include <termios.h> /* POSIX terminal control definitions */
  40. #include <errno.h> /* Error number definitions */
  41. #include <string.h> /* String function definitions */
  42. #include <time.h>
  43. #include <ctype.h>
  44. #include <ifaddrs.h>
  45. #include <stdbool.h>
  46. typedef struct Rfid
  47. {
  48. uint8_t snType; // 4 bytes or 6 bytes or 7 bytes or 10 bytes
  49. uint8_t cardType; // 0: NONE 1: ISO14443A 2: ISO14443B 4: FELICA
  50. uint8_t currentCard[32]; // Current charging cycle start card number
  51. uint8_t targetBlock; // RFID read/write target block
  52. uint8_t keyType; // 0: Key-A 1: Key-B
  53. uint8_t data_Block[32]; // RFID operation block data
  54. }RFID;
  55. //==================================
  56. // Global Constant (Card Length)
  57. //==================================
  58. #define RFID_SN_TYPE_4BYTE 4
  59. #define RFID_SN_TYPE_6BYTE 6
  60. #define RFID_SN_TYPE_7BYTE 7
  61. #define RFID_SN_TYPE_8BYTE 8
  62. #define RFID_SN_TYPE_10BYTE 10
  63. //==================================
  64. // Global Constant (Card Type)
  65. //==================================
  66. #define NONE 0
  67. #define ISO14443A 1
  68. #define IS014443B 2
  69. #define FELICA 3
  70. //==================================
  71. // Global Constant (Module type)
  72. //==================================
  73. #define NO_MODULE -1
  74. #define MODULE_EWT 0
  75. #define MODULE_REYAX 1
  76. //==================================
  77. // Global Constant (RF Output level)
  78. //==================================
  79. #define SET_RF_STRONGEST 0x00
  80. #define SET_RF_STRONGER 0x01
  81. #define SET_RF_WEAK 0x02
  82. #define SET_RF_WEAKEST 0x03
  83. //==================================
  84. // Global Constant (Automatic Detecting)
  85. //==================================
  86. #define SET_DETECTING_OFF 0x00
  87. #define SET_DETECTING_ON 0x01
  88. #define SET_DETECTING_TEMPORARILY 0x11
  89. //==========================
  90. // Declare RFID module type
  91. //==========================
  92. #define RFID_MODULE_TYPE MODULE_EWT // EWT : MODULE_EWT REYAX : MODULE_REYAX
  93. char ClaCheckSum(unsigned char *buffer, int len);
  94. int system_command(int uart, unsigned char* cmd,int length, unsigned char* rx);
  95. int at_command(int uart, unsigned char* cmd,int length, unsigned char* rx);
  96. bool getRequestCardSN(int Fd, int moduleType,RFID *rfid);
  97. bool ISO14443A_REQUEST_SN(int Fd, int moduleType, unsigned char *serialNumber);
  98. bool ISO14443B_REQUEST_SN(int Fd, int moduleType, unsigned char *serialNumber);
  99. bool FELICA_REQUEST_SN(int Fd, int moduleType, unsigned char *serialNumber);
  100. bool getBlockRead(int Fd, int moduleType,int block, unsigned char keyid, unsigned char *data);
  101. bool setBlockWrite(int Fd, int moduleType,int block, unsigned char keyid, unsigned char *data);
  102. bool setDefaultOfAutomaticDetectingCard(int Fd, int moduleType, int Value);
  103. bool setRfOutputLevel(int Fd, int moduleType, int Value);
  104. void setBuzzer(int Fd, int moduleType, unsigned char time);
  105. void sethaltCard(int Fd, int moduleType);
  106. #endif