uhf_tag.h 2.6 KB

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