libnfc  1.8.0
jewel.h
Go to the documentation of this file.
1 /*-
2  * Free/Libre Near Field Communication (NFC) library
3  *
4  * Libnfc historical contributors:
5  * Copyright (C) 2009 Roel Verdult
6  * Copyright (C) 2009-2013 Romuald Conty
7  * Copyright (C) 2010-2012 Romain Tartière
8  * Copyright (C) 2010-2013 Philippe Teuwen
9  * Copyright (C) 2012-2013 Ludovic Rousseau
10  * See AUTHORS file for a more comprehensive list of contributors.
11  * Additional contributors of this file:
12  * Copyright (C) 2014 Pim 't Hart
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are met:
16  * 1) Redistributions of source code must retain the above copyright notice,
17  * this list of conditions and the following disclaimer.
18  * 2 )Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * Note that this license only applies on the examples, NFC library itself is under LGPL
35  *
36  */
37 
43 #ifndef _LIBNFC_JEWEL_H_
44 # define _LIBNFC_JEWEL_H_
45 
46 # include <nfc/nfc-types.h>
47 
48 // Compiler directive, set struct alignment to 1 uint8_t for compatibility
49 # pragma pack(1)
50 
51 typedef enum {
52  TC_RID = 0x78, // Read ID
53  // List of commands (Static memory model)
54  TC_RALL = 0x00, // Real All
55  TC_READ = 0x01, // Read (single byte)
56  TC_WRITEE = 0x53, // Write-with-Erase (single byte)
57  TC_WRITENE = 0x1A, // Write-without-Erase (single byte)
58  // List of commands (Dynamic memory model)
59  TC_RSEG = 0x10, // Read segment
60  TC_READ8 = 0x02, // Read (8-bytes)
61  TC_WRITEE8 = 0x54, // Write-with-Erase (8 bytes)
62  TC_WRITENE8 = 0x1B // Write-without-Erase (8 byes)
63 } jewel_cmd;
64 
65 // Jewel request
66 typedef struct {
67  uint8_t btCmd;
68 } jewel_req_rid;
69 
70 typedef struct {
71  uint8_t btCmd;
72 } jewel_req_rall;
73 
74 typedef struct {
75  uint8_t btCmd;
76  uint8_t btAdd;
77 } jewel_req_read;
78 
79 typedef struct {
80  uint8_t btCmd;
81  uint8_t btAdd;
82  uint8_t btDat;
83 } jewel_req_writee;
84 
85 typedef struct {
86  uint8_t btCmd;
87  uint8_t btAdd;
88  uint8_t btDat;
89 } jewel_req_writene;
90 
91 typedef struct {
92  uint8_t btCmd;
93  uint8_t btAddS;
94 } jewel_req_rseg;
95 
96 typedef struct {
97  uint8_t btCmd;
98  uint8_t btAdd8;
99 } jewel_req_read8;
100 
101 typedef struct {
102  uint8_t btCmd;
103  uint8_t btAdd8;
104  uint8_t abtDat[8];
105 } jewel_req_writee8;
106 
107 typedef struct {
108  uint8_t btCmd;
109  uint8_t btAdd8;
110  uint8_t abtDat[8];
111 } jewel_req_writene8;
112 
113 typedef union {
114  jewel_req_rid rid;
115  jewel_req_rall rall;
116  jewel_req_read read;
117  jewel_req_writee writee;
118  jewel_req_writene writene;
119  jewel_req_rseg rseg;
120  jewel_req_read8 read8;
121  jewel_req_writee8 writee8;
122  jewel_req_writene8 writene8;
123 } jewel_req;
124 
125 // Jewel responses
126 typedef struct {
127  uint8_t abtHr[2];
128  uint8_t abtUid[4]; // 4-LSB from UID
129 } jewel_res_rid;
130 
131 typedef struct {
132  uint8_t abtHr[2];
133  uint8_t abtDat[104]; // Block 0 - E, but not block D (reserved)
134 } jewel_res_rall;
135 
136 typedef struct {
137  uint8_t btDat;
138 } jewel_res_read;
139 
140 typedef struct {
141  uint8_t btDat;
142 } jewel_res_writee;
143 
144 typedef struct {
145  uint8_t btDat;
146 } jewel_res_writene;
147 
148 typedef struct {
149  uint8_t abtDat[128];
150 } jewel_res_rseg;
151 
152 typedef struct {
153  uint8_t abtDat[8];
154 } jewel_res_read8;
155 
156 typedef struct {
157  uint8_t abtDat[8];
158 } jewel_res_writee8;
159 
160 typedef struct {
161  uint8_t abtDat[8];
162 } jewel_res_writene8;
163 
164 typedef union {
165  jewel_res_rid rid;
166  jewel_res_rall rall;
167  jewel_res_read read;
168  jewel_res_writee writee;
169  jewel_res_writene writene;
170  jewel_res_rseg rseg;
171  jewel_res_read8 read8;
172  jewel_res_writee8 writee8;
173  jewel_res_writene8 writene8;
174 } jewel_res;
175 
176 // Jewel tag
177 typedef struct {
178  uint8_t abtUid[7];
179  uint8_t btReserved;
180 } jewel_block_uid;
181 
182 typedef struct {
183  uint8_t abtData[8];
184 } jewel_block_data;
185 
186 typedef struct {
187  uint8_t abtReserved[8];
188 } jewel_block_reserved;
189 
190 typedef struct {
191  uint8_t abtLock[2];
192  uint8_t abtOtp[6];
193 } jewel_block_lockotp;
194 
195 typedef struct {
196  jewel_block_uid bu;
197  jewel_block_data abd[12];
198  jewel_block_reserved br;
199  jewel_block_lockotp bl;
200 } jewel_tag_blocks;
201 
202 typedef struct {
203  uint8_t abtData[120];
204 } jewel_tag_data;
205 
206 typedef union {
207  jewel_tag_blocks ttb;
208  jewel_tag_data ttd;
209 } jewel_tag;
210 
211 // Reset struct alignment to default
212 # pragma pack()
213 
214 bool nfc_initiator_jewel_cmd(nfc_device *pnd, const jewel_req req, jewel_res *pres);
215 
216 #endif // _LIBNFC_JEWEL_H_
bool nfc_initiator_jewel_cmd(nfc_device *pnd, const jewel_req req, jewel_res *pres)
Execute a Jewel Topaz Command.
Definition: jewel.c:56
Define NFC types.
NFC device information.
Definition: nfc-internal.h:190