Module_RFID.h 3.3 KB

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