LibDriver NTAG21X
Loading...
Searching...
No Matches
driver_ntag21x_basic.c
Go to the documentation of this file.
1
36
38
39static ntag21x_handle_t gs_handle;
40
46static void s_debug_print(const char *const fmt, ...)
47{
48 (void)fmt;
49
50 return;
51}
52
60uint8_t ntag21x_basic_init(void)
61{
62 uint8_t res;
63
64 /* link function */
70#ifndef NO_DEBUG
72#else
73 DRIVER_NTAG21X_LINK_DEBUG_PRINT(&gs_handle, s_debug_print);
74#endif
75
76 /* init */
77 res = ntag21x_init(&gs_handle);
78 if (res != 0)
79 {
80 ntag21x_interface_debug_print("ntag21x: init failed.\n");
81
82 return 1;
83 }
84
85 return 0;
86}
87
96{
97 uint8_t res;
98
99 /* deinit */
100 res = ntag21x_deinit(&gs_handle);
101 if (res != 0)
102 {
103 return 1;
104 }
105
106 return 0;
107}
108
117{
118 uint8_t res;
119
120 /* halt */
121 res = ntag21x_halt(&gs_handle);
122 if (res != 0)
123 {
124 return 1;
125 }
126
127 return 0;
128}
129
138{
139 uint8_t res;
140 ntag21x_type_t type;
141
142 /* wake up */
143 res = ntag21x_wake_up(&gs_handle, &type);
144 if (res != 0)
145 {
146 return 1;
147 }
148
149 return 0;
150}
151
162uint8_t ntag21x_basic_search(ntag21x_capability_container_t *type, uint8_t id[8], int32_t timeout)
163{
164 uint8_t res;
166
167 /* loop */
168 while (1)
169 {
170 /* request */
171 res = ntag21x_request(&gs_handle, &t);
172 if (res == 0)
173 {
174 /* anti collision_cl1 */
175 res = ntag21x_anticollision_cl1(&gs_handle, id);
176 if (res == 0)
177 {
178 /* cl1 */
179 res = ntag21x_select_cl1(&gs_handle, id);
180 if (res == 0)
181 {
182 /* anti collision_cl2 */
183 res = ntag21x_anticollision_cl2(&gs_handle, id + 4);
184 if (res == 0)
185 {
186 /* cl2 */
187 res = ntag21x_select_cl2(&gs_handle, id + 4);
188 if (res == 0)
189 {
190 res = ntag21x_get_capability_container(&gs_handle, type);
191 if (res == 0)
192 {
193 return 0;
194 }
195 }
196 }
197 }
198 }
199 }
200
201 /* delay */
203
204 /* check the timeout */
205 if (timeout < 0)
206 {
207 /* never timeout */
208 continue;
209 }
210 else
211 {
212 /* timeout */
213 if (timeout == 0)
214 {
215 return 1;
216 }
217 else
218 {
219 /* timout-- */
220 timeout--;
221 }
222 }
223 }
224}
225
235uint8_t ntag21x_basic_read(uint8_t page, uint8_t data[4])
236{
237 uint8_t res;
238
239 /* read */
240 res = ntag21x_read_page(&gs_handle, page, data);
241 if (res != 0)
242 {
243 return 1;
244 }
245
246 return 0;
247}
248
258uint8_t ntag21x_basic_read_four_pages(uint8_t start_page, uint8_t data[16])
259{
260 uint8_t res;
261
262 /* read */
263 res = ntag21x_read_four_pages(&gs_handle, start_page, data);
264 if (res != 0)
265 {
266 return 1;
267 }
268
269 return 0;
270}
271
284uint8_t ntag21x_basic_read_pages(uint8_t start_page, uint8_t stop_page, uint8_t *data, uint16_t *len)
285{
286 uint8_t res;
287
288 /* fast read */
289 res = ntag21x_fast_read_page(&gs_handle, start_page, stop_page, data, len);
290 if (res != 0)
291 {
292 return 1;
293 }
294
295 return 0;
296}
297
307uint8_t ntag21x_basic_write(uint8_t page, uint8_t data[4])
308{
309 uint8_t res;
310
311 /* write */
312 res = ntag21x_write_page(&gs_handle, page, data);
313 if (res != 0)
314 {
315 return 1;
316 }
317
318 return 0;
319}
320
330{
331 uint8_t res;
332
333 /* get the version */
334 res = ntag21x_get_version(&gs_handle, version);
335 if (res != 0)
336 {
337 return 1;
338 }
339
340 return 0;
341}
342
351uint8_t ntag21x_basic_read_counter(uint32_t *cnt)
352{
353 uint8_t res;
354
355 /* read the counter */
356 res = ntag21x_read_counter(&gs_handle, cnt);
357 if (res != 0)
358 {
359 return 1;
360 }
361
362 return 0;
363}
364
373uint8_t ntag21x_basic_read_signature(uint8_t signature[32])
374{
375 uint8_t res;
376
377 /* read the signature */
378 res = ntag21x_read_signature(&gs_handle, signature);
379 if (res != 0)
380 {
381 return 1;
382 }
383
384 return 0;
385}
386
395uint8_t ntag21x_basic_get_serial_number(uint8_t number[7])
396{
397 uint8_t res;
398
399 /* get serial number */
400 res = ntag21x_get_serial_number(&gs_handle, number);
401 if (res != 0)
402 {
403 return 1;
404 }
405
406 return 0;
407}
408
418uint8_t ntag21x_basic_set_password_pack(uint8_t pwd[4], uint8_t pack[2])
419{
420 uint8_t res;
421
422 /* set password */
423 res = ntag21x_set_password(&gs_handle, pwd);
424 if (res != 0)
425 {
426 return 1;
427 }
428
429 /* set pack */
430 res = ntag21x_set_pack(&gs_handle, pack);
431 if (res != 0)
432 {
433 return 1;
434 }
435
436 return 0;
437}
438
448uint8_t ntag21x_basic_authenticate(uint8_t pwd[4], uint8_t pack[2])
449{
450 uint8_t res;
451
452 /* authenticate */
453 res = ntag21x_authenticate(&gs_handle, pwd, pack);
454 if (res != 0)
455 {
456 return 1;
457 }
458
459 return 0;
460}
461
470uint8_t ntag21x_basic_set_dynamic_lock(uint8_t lock[3])
471{
472 uint8_t res;
473
474 /* set dynamic lock */
475 res = ntag21x_set_dynamic_lock(&gs_handle, lock);
476 if (res != 0)
477 {
478 return 1;
479 }
480
481 return 0;
482}
483
492uint8_t ntag21x_basic_set_static_lock(uint8_t lock[2])
493{
494 uint8_t res;
495
496 /* set static lock */
497 res = ntag21x_set_static_lock(&gs_handle, lock);
498 if (res != 0)
499 {
500 return 1;
501 }
502
503 return 0;
504}
505
517{
518 uint8_t res;
519
520 /* set mirror */
521 res = ntag21x_set_mirror(&gs_handle, mirror);
522 if (res != 0)
523 {
524 return 1;
525 }
526
527 /* set mirror byte */
528 res = ntag21x_set_mirror_byte(&gs_handle, byte);
529 if (res != 0)
530 {
531 return 1;
532 }
533
534 /* set mirror page */
535 res = ntag21x_set_mirror_page(&gs_handle, page);
536 if (res != 0)
537 {
538 return 1;
539 }
540
541 return 0;
542}
543
553{
554 uint8_t res;
555
556 /* set modulation mode */
557 res = ntag21x_set_modulation_mode(&gs_handle, mode);
558 if (res != 0)
559 {
560 return 1;
561 }
562
563 return 0;
564}
565
575{
576 uint8_t res;
577
578 /* set protect start page */
579 res = ntag21x_set_protect_start_page(&gs_handle, page);
580 if (res != 0)
581 {
582 return 1;
583 }
584
585 return 0;
586}
587
597{
598 uint8_t res;
599
600 /* set authenticate limitation */
601 res = ntag21x_set_authenticate_limitation(&gs_handle, limit);
602 if (res != 0)
603 {
604 return 1;
605 }
606
607 return 0;
608}
609
620{
621 uint8_t res;
622
623 /* set access */
624 res = ntag21x_set_access(&gs_handle, access, enable);
625 if (res != 0)
626 {
627 return 1;
628 }
629
630 return 0;
631}
driver ntag21x basic header file
ntag21x_type_t
ntag21x type enumeration definition
ntag21x_capability_container_t
ntag21x capability container enumeration definition
uint8_t ntag21x_anticollision_cl1(ntag21x_handle_t *handle, uint8_t id[4])
ntag21x anti collision cl1
uint8_t ntag21x_set_dynamic_lock(ntag21x_handle_t *handle, uint8_t lock[3])
ntag21x set the dynamic lock
struct ntag21x_handle_s ntag21x_handle_t
ntag21x handle structure definition
uint8_t ntag21x_halt(ntag21x_handle_t *handle)
ntag21x halt
uint8_t ntag21x_set_pack(ntag21x_handle_t *handle, uint8_t pack[2])
ntag21x set the pack
ntag21x_access_t
ntag21x access enumeration definition
uint8_t ntag21x_wake_up(ntag21x_handle_t *handle, ntag21x_type_t *type)
ntag21x wake up
uint8_t ntag21x_read_signature(ntag21x_handle_t *handle, uint8_t signature[32])
ntag21x read the signature
uint8_t ntag21x_read_counter(ntag21x_handle_t *handle, uint32_t *cnt)
ntag21x read the counter
uint8_t ntag21x_authenticate(ntag21x_handle_t *handle, uint8_t pwd[4], uint8_t pack[2])
ntag21x authenticate
uint8_t ntag21x_fast_read_page(ntag21x_handle_t *handle, uint8_t start_page, uint8_t stop_page, uint8_t *data, uint16_t *len)
ntag21x fast read page
uint8_t ntag21x_select_cl2(ntag21x_handle_t *handle, uint8_t id[4])
ntag21x select cl2
uint8_t ntag21x_request(ntag21x_handle_t *handle, ntag21x_type_t *type)
ntag21x request
uint8_t ntag21x_get_version(ntag21x_handle_t *handle, ntag21x_version_t *version)
ntag21x get the version
uint8_t ntag21x_get_serial_number(ntag21x_handle_t *handle, uint8_t number[7])
ntag21x get the serial number
uint8_t ntag21x_set_mirror_byte(ntag21x_handle_t *handle, ntag21x_mirror_byte_t byte)
ntag21x set the mirror byte
uint8_t ntag21x_read_four_pages(ntag21x_handle_t *handle, uint8_t start_page, uint8_t data[16])
ntag21x read four pages
uint8_t ntag21x_deinit(ntag21x_handle_t *handle)
close the chip
uint8_t ntag21x_set_static_lock(ntag21x_handle_t *handle, uint8_t lock[2])
ntag21x set the static lock
ntag21x_modulation_mode_t
ntag21x modulation mode enumeration definition
uint8_t ntag21x_set_protect_start_page(ntag21x_handle_t *handle, uint8_t page)
ntag21x set the start page of protection
uint8_t ntag21x_write_page(ntag21x_handle_t *handle, uint8_t page, uint8_t data[4])
ntag21x write page
uint8_t ntag21x_init(ntag21x_handle_t *handle)
initialize the chip
uint8_t ntag21x_set_mirror(ntag21x_handle_t *handle, ntag21x_mirror_t mirror)
ntag21x set the mirror
ntag21x_mirror_byte_t
ntag21x mirror byte enumeration definition
uint8_t ntag21x_read_page(ntag21x_handle_t *handle, uint8_t page, uint8_t data[4])
ntag21x read page
uint8_t ntag21x_set_access(ntag21x_handle_t *handle, ntag21x_access_t access, ntag21x_bool_t enable)
ntag21x enable or disable access
uint8_t ntag21x_anticollision_cl2(ntag21x_handle_t *handle, uint8_t id[4])
ntag21x anti collision cl2
uint8_t ntag21x_get_capability_container(ntag21x_handle_t *handle, ntag21x_capability_container_t *container)
ntag21x get the capability container
uint8_t ntag21x_set_password(ntag21x_handle_t *handle, uint8_t pwd[4])
ntag21x set the password
uint8_t ntag21x_set_authenticate_limitation(ntag21x_handle_t *handle, uint8_t limit)
ntag21x set the authenticate limitation
uint8_t ntag21x_select_cl1(ntag21x_handle_t *handle, uint8_t id[4])
ntag21x select cl1
ntag21x_bool_t
ntag21x bool enumeration definition
struct ntag21x_version_s ntag21x_version_t
ntag21x version structure definition
ntag21x_mirror_t
ntag21x mirror enumeration definition
uint8_t ntag21x_set_mirror_page(ntag21x_handle_t *handle, uint8_t page)
ntag21x set the mirror page
uint8_t ntag21x_set_modulation_mode(ntag21x_handle_t *handle, ntag21x_modulation_mode_t mode)
ntag21x set the modulation mode
uint8_t ntag21x_basic_search(ntag21x_capability_container_t *type, uint8_t id[8], int32_t timeout)
basic example search
uint8_t ntag21x_basic_set_authenticate_limitation(uint8_t limit)
basic example set the authenticate limitation
uint8_t ntag21x_basic_halt(void)
basic example halt
uint8_t ntag21x_basic_get_serial_number(uint8_t number[7])
basic example get serial number
uint8_t ntag21x_basic_wake_up(void)
basic example wake up
uint8_t ntag21x_basic_set_password_pack(uint8_t pwd[4], uint8_t pack[2])
basic example set password and pack
uint8_t ntag21x_basic_init(void)
basic example init
uint8_t ntag21x_basic_set_modulation_mode(ntag21x_modulation_mode_t mode)
basic example set modulation mode
uint8_t ntag21x_basic_read_signature(uint8_t signature[32])
basic example read signature
uint8_t ntag21x_basic_set_access(ntag21x_access_t access, ntag21x_bool_t enable)
basic example set access
uint8_t ntag21x_basic_set_dynamic_lock(uint8_t lock[3])
basic example set dynamic lock
uint8_t ntag21x_basic_deinit(void)
basic example deinit
uint8_t ntag21x_basic_authenticate(uint8_t pwd[4], uint8_t pack[2])
basic example authenticate
uint8_t ntag21x_basic_set_mirror(ntag21x_mirror_t mirror, ntag21x_mirror_byte_t byte, uint8_t page)
basic example set mirror
uint8_t ntag21x_basic_write(uint8_t page, uint8_t data[4])
basic example write
uint8_t ntag21x_basic_read_pages(uint8_t start_page, uint8_t stop_page, uint8_t *data, uint16_t *len)
basic example read pages
uint8_t ntag21x_basic_read(uint8_t page, uint8_t data[4])
basic example read
uint8_t ntag21x_basic_set_protect_start_page(uint8_t page)
basic example set protect start page
uint8_t ntag21x_basic_read_counter(uint32_t *cnt)
basic example read counter
uint8_t ntag21x_basic_set_static_lock(uint8_t lock[2])
basic example set static lock
uint8_t ntag21x_basic_read_four_pages(uint8_t start_page, uint8_t data[16])
basic example read four pages
#define MIFARE_NTAG21X_DEFAULT_SEARCH_DELAY_MS
ntag21x basic example default definition
uint8_t ntag21x_basic_get_version(ntag21x_version_t *version)
basic example get version
void ntag21x_interface_delay_ms(uint32_t ms)
interface delay ms
void ntag21x_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t ntag21x_interface_contactless_transceiver(uint8_t *in_buf, uint8_t in_len, uint8_t *out_buf, uint8_t *out_len)
interface contactless transceiver
uint8_t ntag21x_interface_contactless_init(void)
interface contactless init
uint8_t ntag21x_interface_contactless_deinit(void)
interface contactless deinit