Chameleon-Mini
 All Classes Files Functions Variables Macros Pages
ISO15693-3.h
1 /*
2  * ISO15693-3.h
3  *
4  * Created on: 24.08.2013
5  * Author: skuser
6  */
7 
8 #ifndef ISO15693_3_H_
9 #define ISO15693_3_H_
10 
11 #include "../Common.h"
12 
13 #define ISO15693_CMD_INVENTORY 0x01
14 #define ISO15693_CMD_STAY_QUIET 0x02
15 #define ISO15693_CMD_READ_SINGLE 0x20
16 #define ISO15693_CMD_WRITE_SINGLE 0x21
17 #define ISO15693_CMD_LOCK_BLOCK 0x22
18 #define ISO15693_CMD_READ_MULTIPLE 0x23
19 #define ISO15693_CMD_WRITE_MULTIPLE 0x24
20 #define ISO15693_CMD_SELECT 0x25
21 #define ISO15693_CMD_RESET_TO_READY 0x26
22 #define ISO15693_CMD_WRITE_AFI 0x27
23 #define ISO15693_CMD_LOCK_AFI 0x28
24 #define ISO15693_CMD_WRITE_DSFID 0x29
25 #define ISO15693_CMD_LOCK_DSFID 0x2A
26 #define ISO15693_CMD_GET_SYS_INFO 0x2B
27 #define ISO15693_CMD_GET_BLOCK_SEC 0x2C
28 
29 #define ISO15693_REQ_FLAG_SUBCARRIER 0x01
30 #define ISO15693_REQ_FLAG_DATARATE 0x02
31 #define ISO15693_REQ_FLAG_INVENTORY 0x04
32 #define ISO15693_REQ_FLAG_PROT_EXT 0x08
33 #define ISO15693_REQ_FLAG_OPTION 0x40
34 #define ISO15693_REQ_FLAG_RFU 0x80
35 /* When INVENTORY flag is not set: */
36 #define ISO15693_REQ_FLAG_SELECT 0x10
37 #define ISO15693_REQ_FLAG_ADDRESS 0x20
38 /* When INVENTORY flag is set: */
39 #define ISO15693_REQ_FLAG_AFI 0x10
40 #define ISO15693_REQ_FLAG_NB_SLOTS 0x20
41 
42 #define ISO15693_RES_FLAG_ERROR 0x01
43 #define ISO15693_RES_FLAG_PROT_EXT 0x08
44 
45 #define ISO15693_CRC_SIZE 2 /* Byte */
46 
47 typedef uint8_t ISO15693UidType[8];
48 
49 void ISO15693AppendCRC(void* Buffer, uint16_t ByteCount);
50 bool ISO15693CheckCRC(void* Buffer, uint16_t ByteCount);
51 
52 INLINE
53 bool ISO15693CompareUid(uint8_t* Uid1, uint8_t* Uid2)
54 {
55  if ( (Uid1[0] == Uid2[0])
56  && (Uid1[1] == Uid2[1])
57  && (Uid1[2] == Uid2[2])
58  && (Uid1[3] == Uid2[3])
59  && (Uid1[4] == Uid2[4])
60  && (Uid1[5] == Uid2[5])
61  && (Uid1[6] == Uid2[6])
62  && (Uid1[7] == Uid2[7]) ) {
63  return true;
64  } else {
65  return false;
66  }
67 }
68 
69 INLINE
70 void ISO15693CopyUid(uint8_t* DstUid, uint8_t* SrcUid)
71 {
72  DstUid[0] = SrcUid[0];
73  DstUid[1] = SrcUid[1];
74  DstUid[2] = SrcUid[2];
75  DstUid[3] = SrcUid[3];
76  DstUid[4] = SrcUid[4];
77  DstUid[5] = SrcUid[5];
78  DstUid[6] = SrcUid[6];
79  DstUid[7] = SrcUid[7];
80 }
81 
82 INLINE
83 bool ISO15693Addressed(uint8_t* Buffer, uint8_t* MyUid) {
84  if (Buffer[0] & ISO15693_REQ_FLAG_ADDRESS) {
85  /* Addressed mode */
86  if ( ISO15693CompareUid(&Buffer[2], MyUid) ) {
87  /* Our UID addressed */
88  return true;
89  } else {
90  /* Our UID not addressed */
91  return false;
92  }
93  } else {
94  /* Non-Addressed mode */
95  return true;
96  }
97 }
98 
99 #endif /* ISO15693_3_H_ */