uhf_tag.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #include <stddef.h>
  5. #define MAX_BANK_SIZE 200
  6. // storage enum
  7. typedef enum {
  8. ReservedBank,
  9. EPCBank,
  10. TIDBank,
  11. UserBank
  12. } BankType;
  13. // Reserved Memory Bank
  14. typedef struct {
  15. uint8_t kill_password[2]; // 2 bytes (16 bits) for kill password
  16. uint8_t access_password[2]; // 2 bytes (16 bits) for access password
  17. } ReservedMemoryBank;
  18. // EPC Memory Bank
  19. typedef struct {
  20. size_t size; // Size of EPC memory data
  21. uint8_t data[MAX_BANK_SIZE]; // 2 bytes for CRC16, 2 bytes for PC, and max 14 bytes for EPC
  22. uint16_t pc;
  23. uint16_t crc;
  24. } EPCMemoryBank;
  25. // TID Memory Bank
  26. typedef struct {
  27. size_t size; // Size of TID memory data
  28. uint8_t data[MAX_BANK_SIZE]; // 4 bytes for Class ID
  29. } TIDMemoryBank;
  30. // User Memory Bank
  31. typedef struct {
  32. size_t size; // Size of user memory data
  33. uint8_t data[MAX_BANK_SIZE]; // Assuming max 512 bits (64 bytes) for User Memory
  34. } UserMemoryBank;
  35. // EPC Gen 2 Tag containing all memory banks
  36. typedef struct {
  37. ReservedMemoryBank* reserved;
  38. EPCMemoryBank* epc;
  39. TIDMemoryBank* tid;
  40. UserMemoryBank* user;
  41. } UHFTag;
  42. typedef struct UHFTagWrapper {
  43. UHFTag* uhf_tag;
  44. } UHFTagWrapper;
  45. UHFTagWrapper* uhf_tag_wrapper_alloc();
  46. void uhf_tag_wrapper_set_tag(UHFTagWrapper* uhf_tag_wrapper, UHFTag* uhf_tag);
  47. void uhf_tag_wrapper_free(UHFTagWrapper* uhf_tag_wrapper);
  48. UHFTag* uhf_tag_alloc();
  49. void uhf_tag_reset(UHFTag* uhf_tag);
  50. void uhf_tag_free(UHFTag* uhf_tag);
  51. void uhf_tag_set_kill_pwd(UHFTag* uhf_tag, uint8_t* data_in);
  52. void uhf_tag_set_access_pwd(UHFTag* uhf_tag, uint8_t* data_in);
  53. void uhf_tag_set_epc_pc(UHFTag* uhf_tag, uint16_t pc);
  54. void uhf_tag_set_epc_crc(UHFTag* uhf_tag, uint16_t crc);
  55. void uhf_tag_set_epc(UHFTag* uhf_tag, uint8_t* data_in, size_t size);
  56. void uhf_tag_set_epc_size(UHFTag* uhf_tag, size_t size);
  57. void uhf_tag_set_tid(UHFTag* uhf_tag, uint8_t* data_in, size_t size);
  58. void uhf_tag_set_tid_size(UHFTag* uhf_tag, size_t size);
  59. void uhf_tag_set_user(UHFTag* uhf_tag, uint8_t* data_in, size_t size);
  60. void uhf_tag_set_user_size(UHFTag* uhf_tag, size_t size);
  61. uint8_t* uhf_tag_get_kill_pwd(UHFTag* uhf_tag);
  62. uint8_t* uhf_tag_get_access_pwd(UHFTag* uhf_tag);
  63. uint8_t* uhf_tag_get_epc(UHFTag* uhf_tag);
  64. uint16_t uhf_tag_get_epc_pc(UHFTag* uhf_tag);
  65. uint16_t uhf_tag_get_epc_crc(UHFTag* uhf_tag);
  66. size_t uhf_tag_get_epc_size(UHFTag* uhf_tag);
  67. uint8_t* uhf_tag_get_tid(UHFTag* uhf_tag);
  68. size_t uhf_tag_get_tid_size(UHFTag* uhf_tag);
  69. uint8_t* uhf_tag_get_user(UHFTag* uhf_tag);
  70. size_t uhf_tag_get_user_size(UHFTag* uhf_tag);
  71. // debug
  72. char* uhf_tag_get_cstr(UHFTag* uhf_tag);