LibDriver NTAG21X
Loading...
Searching...
No Matches
driver_ntag21x.c
Go to the documentation of this file.
1
36
37#include "driver_ntag21x.h"
38
42#define CHIP_NAME "NXP NTAG213/5/6"
43#define MANUFACTURER_NAME "NXP"
44#define SUPPLY_VOLTAGE_MIN 3.3f
45#define SUPPLY_VOLTAGE_MAX 4.0f
46#define MAX_CURRENT 30.0f
47#define TEMPERATURE_MIN -25.0f
48#define TEMPERATURE_MAX 70.0f
49#define DRIVER_VERSION 1000
50
54#define NTAG21X_COMMAND_REQUEST 0x26
55#define NTAG21X_COMMAND_WAKE_UP 0x52
56#define NTAG21X_COMMAND_ANTICOLLISION_CL1 0x9320U
57#define NTAG21X_COMMAND_SELECT_CL1 0x9370U
58#define NTAG21X_COMMAND_ANTICOLLISION_CL2 0x9520U
59#define NTAG21X_COMMAND_SELECT_CL2 0x9570U
60#define NTAG21X_COMMAND_HALT 0x5000U
61#define NTAG21X_COMMAND_GET_VERSION 0x60
62#define NTAG21X_COMMAND_READ 0x30
63#define NTAG21X_COMMAND_FAST_READ 0x3A
64#define NTAG21X_COMMAND_WRITE 0xA2
65#define NTAG21X_COMMAND_COMP_WRITE 0xA0
66#define NTAG21X_COMMAND_READ_CNT 0x39
67#define NTAG21X_COMMAND_PWD_AUTH 0x1B
68#define NTAG21X_COMMAND_READ_SIG 0x3C
69
76static void a_ntag21x_iso14443a_crc(uint8_t *p, uint8_t len, uint8_t output[2])
77{
78 uint32_t w_crc = 0x6363;
79
80 do
81 {
82 uint8_t bt;
83
84 bt = *p++; /* get one byte */
85 bt = (bt ^ (uint8_t)(w_crc & 0x00FF)); /* xor */
86 bt = (bt ^ (bt << 4)); /* xor */
87 w_crc = (w_crc >> 8) ^ ((uint32_t) bt << 8) ^ ((uint32_t) bt << 3) ^ ((uint32_t) bt >> 4); /* get the crc */
88 } while (--len); /* len-- */
89
90 output[0] = (uint8_t)(w_crc & 0xFF); /* lsb */
91 output[1] = (uint8_t)((w_crc >> 8) & 0xFF); /* msb */
92}
93
104static uint8_t a_ntag21x_conf_read(ntag21x_handle_t *handle, uint8_t page, uint8_t data[4])
105{
106 uint8_t res;
107 uint8_t input_len;
108 uint8_t input_buf[5];
109 uint8_t output_len;
110 uint8_t output_buf[6];
111 uint8_t crc_buf[2];
112
113 input_len = 5; /* set the input length */
114 input_buf[0] = NTAG21X_COMMAND_FAST_READ; /* set the command */
115 input_buf[1] = page; /* set the start page */
116 input_buf[2] = page; /* set the stop page */
117 a_ntag21x_iso14443a_crc(input_buf , 3, input_buf + 3); /* get the crc */
118 output_len = 6; /* set the output length */
119 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
120 if (res != 0) /* check the result */
121 {
122 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
123
124 return 1; /* return error */
125 }
126 if (output_len != 6) /* check the output_len */
127 {
128 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
129
130 return 1; /* return error */
131 }
132 a_ntag21x_iso14443a_crc(output_buf, 4, crc_buf); /* get the crc */
133 if ((output_buf[4] == crc_buf[0]) && (output_buf[5] == crc_buf[1])) /* check the crc */
134 {
135 memcpy(data, output_buf, 4); /* copy the data */
136
137 return 0; /* success return 0 */
138 }
139 else
140 {
141 handle->debug_print("ntag21x: crc error.\n"); /* crc error */
142
143 return 1; /* return error */
144 }
145}
146
157static uint8_t a_ntag21x_conf_write(ntag21x_handle_t *handle, uint8_t page, uint8_t data[4])
158{
159 uint8_t res;
160 uint8_t input_len;
161 uint8_t input_buf[8];
162 uint8_t output_len;
163 uint8_t output_buf[1];
164
165 input_len = 8; /* set the input length */
166 input_buf[0] = NTAG21X_COMMAND_WRITE; /* set the command */
167 input_buf[1] = page; /* set the setting page */
168 input_buf[2] = data[0]; /* set data0 */
169 input_buf[3] = data[1]; /* set data1 */
170 input_buf[4] = data[2]; /* set data2 */
171 input_buf[5] = data[3]; /* set data3 */
172 a_ntag21x_iso14443a_crc(input_buf, 6, input_buf + 6); /* get the crc */
173 output_len = 1; /* set the output length */
174 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
175 if (res != 0) /* check the result */
176 {
177 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
178
179 return 1; /* return error */
180 }
181 if (output_len != 1) /* check the output_len */
182 {
183 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
184
185 return 1; /* return error */
186 }
187 if (output_buf[0] != 0xA) /* check the result */
188 {
189 handle->debug_print("ntag21x: ack error.\n"); /* ack error */
190
191 return 1; /* return error */
192 }
193
194 return 0; /* success return 0 */
195}
196
208{
209 uint8_t res;
210
211 if (handle == NULL) /* check handle */
212 {
213 return 2; /* return error */
214 }
215 if (handle->debug_print == NULL) /* check debug_print */
216 {
217 return 3; /* return error */
218 }
219 if (handle->contactless_init == NULL) /* check contactless_init */
220 {
221 handle->debug_print("ntag21x: contactless_init is null.\n"); /* contactless_init is null */
222
223 return 3; /* return error */
224 }
225 if (handle->contactless_deinit == NULL) /* check contactless_deinit */
226 {
227 handle->debug_print("ntag21x: contactless_deinit is null.\n"); /* contactless_deinit is null */
228
229 return 3; /* return error */
230 }
231 if (handle->contactless_transceiver == NULL) /* check contactless_transceiver */
232 {
233 handle->debug_print("ntag21x: contactless_transceiver is null.\n"); /* contactless_transceiver is null */
234
235 return 3; /* return error */
236 }
237 if (handle->delay_ms == NULL) /* check delay_ms */
238 {
239 handle->debug_print("ntag21x: delay_ms is null.\n"); /* delay_ms is null */
240
241 return 3; /* return error */
242 }
243
244 res = handle->contactless_init(); /* contactless init */
245 if (res != 0) /* check the result */
246 {
247 handle->debug_print("ntag21x: contactless init failed.\n"); /* contactless init failed */
248
249 return 1; /* return error */
250 }
251 handle->type = NTAG21X_TYPE_INVALID; /* set the invalid type */
252 handle->end_page = 0xFF; /* set 0xFF */
253 handle->inited = 1; /* flag inited */
254
255 return 0; /* success return 0 */
256}
257
269{
270 uint8_t res;
271
272 if (handle == NULL) /* check handle */
273 {
274 return 2; /* return error */
275 }
276 if (handle->inited != 1) /* check handle initialization */
277 {
278 return 3; /* return error */
279 }
280
281 res = handle->contactless_deinit(); /* contactless deinit */
282 if (res != 0) /* check the result */
283 {
284 handle->debug_print("ntag21x: contactless deinit failed.\n"); /* contactless deinit failed */
285
286 return 1; /* return error */
287 }
288 handle->inited = 0; /* flag closed */
289
290 return 0; /* success return 0 */
291}
292
307{
308 uint8_t res;
309 uint8_t input_len;
310 uint8_t input_buf[1];
311 uint8_t output_len;
312 uint8_t output_buf[2];
313
314 if (handle == NULL) /* check handle */
315 {
316 return 2; /* return error */
317 }
318 if (handle->inited != 1) /* check handle initialization */
319 {
320 return 3; /* return error */
321 }
322
323 input_len = 1; /* set the input length */
324 input_buf[0] = NTAG21X_COMMAND_REQUEST; /* set the command */
325 output_len = 2; /* set the output length */
326 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
327 if (res != 0) /* check the result */
328 {
329 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
330
331 return 1; /* return error */
332 }
333 if (output_len != 2) /* check the output_len */
334 {
335 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
336
337 return 4; /* return error */
338 }
339 if ((output_buf[0] == 0x44) && (output_buf[1] == 0x00)) /* check classic type */
340 {
341 *type = NTAG21X_TYPE_213_5_6; /* ntag213/5/6 */
342 handle->type = *type; /* save the type */
343
344 return 0; /* success return 0 */
345 }
346 else
347 {
348 *type = NTAG21X_TYPE_INVALID; /* invalid */
349 handle->type = *type; /* save the type */
350 handle->debug_print("ntag21x: type is invalid.\n"); /* type is invalid */
351
352 return 5; /* return error */
353 }
354}
355
370{
371 uint8_t res;
372 uint8_t input_len;
373 uint8_t input_buf[1];
374 uint8_t output_len;
375 uint8_t output_buf[2];
376
377 if (handle == NULL) /* check handle */
378 {
379 return 2; /* return error */
380 }
381 if (handle->inited != 1) /* check handle initialization */
382 {
383 return 3; /* return error */
384 }
385
386 handle->delay_ms(1); /* delay 1ms */
387 input_len = 1; /* set the input length */
388 input_buf[0] = NTAG21X_COMMAND_WAKE_UP; /* set the command */
389 output_len = 2; /* set the output length */
390 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
391 if (res != 0) /* check the result */
392 {
393 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
394
395 return 1; /* return error */
396 }
397 if (output_len != 2) /* check the output_len */
398 {
399 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
400
401 return 4; /* return error */
402 }
403 if ((output_buf[0] == 0x44) && (output_buf[1] == 0x00)) /* check classic type */
404 {
405 *type = NTAG21X_TYPE_213_5_6; /* ntag213/5/6 */
406 handle->type = *type; /* save the type */
407
408 return 0; /* success return 0 */
409 }
410 else
411 {
412 *type = NTAG21X_TYPE_INVALID; /* invalid */
413 handle->type = *type; /* save the type */
414 handle->debug_print("ntag21x: type is invalid.\n"); /* type is invalid */
415
416 return 5; /* return error */
417 }
418}
419
431{
432 uint8_t input_len;
433 uint8_t input_buf[4];
434 uint8_t output_len;
435 uint8_t output_buf[1];
436
437 if (handle == NULL) /* check handle */
438 {
439 return 2; /* return error */
440 }
441 if (handle->inited != 1) /* check handle initialization */
442 {
443 return 3; /* return error */
444 }
445
446 input_len = 4; /* set the input length */
447 input_buf[0] = (NTAG21X_COMMAND_HALT >> 8) & 0xFF; /* set the command */
448 input_buf[1] = (NTAG21X_COMMAND_HALT >> 0) & 0xFF; /* set the command */
449 a_ntag21x_iso14443a_crc(input_buf, 2, input_buf + 2); /* get the crc */
450 output_len = 1; /* set the output length */
451 (void)handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
452
453 return 0; /* success return 0 */
454}
455
469uint8_t ntag21x_anticollision_cl1(ntag21x_handle_t *handle, uint8_t id[4])
470{
471 uint8_t res;
472 uint8_t i;
473 uint8_t check;
474 uint8_t input_len;
475 uint8_t input_buf[2];
476 uint8_t output_len;
477 uint8_t output_buf[5];
478
479 if (handle == NULL) /* check handle */
480 {
481 return 2; /* return error */
482 }
483 if (handle->inited != 1) /* check handle initialization */
484 {
485 return 3; /* return error */
486 }
487
488 input_len = 2; /* set the input length */
489 input_buf[0] = (NTAG21X_COMMAND_ANTICOLLISION_CL1 >> 8) & 0xFF; /* set the command */
490 input_buf[1] = (NTAG21X_COMMAND_ANTICOLLISION_CL1 >> 0) & 0xFF; /* set the command */
491 output_len = 5; /* set the output length */
492 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
493 if (res != 0) /* check the result */
494 {
495 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
496
497 return 1; /* return error */
498 }
499 if (output_len != 5) /* check the output_len */
500 {
501 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
502
503 return 4; /* return error */
504 }
505 check = 0; /* init 0 */
506 for (i = 0; i < 4; i++) /* run 4 times */
507 {
508 id[i] = output_buf[i]; /* get one id */
509 check ^= output_buf[i]; /* xor */
510 }
511 if (check != output_buf[4]) /* check the result */
512 {
513 handle->debug_print("ntag21x: check error.\n"); /* check error */
514
515 return 5; /* return error */
516 }
517
518 return 0; /* success return 0 */
519}
520
534uint8_t ntag21x_anticollision_cl2(ntag21x_handle_t *handle, uint8_t id[4])
535{
536 uint8_t res;
537 uint8_t i;
538 uint8_t check;
539 uint8_t input_len;
540 uint8_t input_buf[2];
541 uint8_t output_len;
542 uint8_t output_buf[5];
543
544 if (handle == NULL) /* check handle */
545 {
546 return 2; /* return error */
547 }
548 if (handle->inited != 1) /* check handle initialization */
549 {
550 return 3; /* return error */
551 }
552
553 input_len = 2; /* set the input length */
554 input_buf[0] = (NTAG21X_COMMAND_ANTICOLLISION_CL2 >> 8) & 0xFF; /* set the command */
555 input_buf[1] = (NTAG21X_COMMAND_ANTICOLLISION_CL2 >> 0) & 0xFF; /* set the command */
556 output_len = 5; /* set the output length */
557 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
558 if (res != 0) /* check the result */
559 {
560 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
561
562 return 1; /* return error */
563 }
564 if (output_len != 5) /* check the output_len */
565 {
566 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
567
568 return 4; /* return error */
569 }
570 check = 0; /* init 0 */
571 for (i = 0; i < 4; i++) /* run 4 times */
572 {
573 id[i] = output_buf[i]; /* get one id */
574 check ^= output_buf[i]; /* xor */
575 }
576 if (check != output_buf[4]) /* check the result */
577 {
578 handle->debug_print("ntag21x: check error.\n"); /* check error */
579
580 return 5; /* return error */
581 }
582
583 return 0; /* success return 0 */
584}
585
599uint8_t ntag21x_select_cl1(ntag21x_handle_t *handle, uint8_t id[4])
600{
601 uint8_t res;
602 uint8_t i;
603 uint8_t input_len;
604 uint8_t input_buf[9];
605 uint8_t output_len;
606 uint8_t output_buf[1];
607
608 if (handle == NULL) /* check handle */
609 {
610 return 2; /* return error */
611 }
612 if (handle->inited != 1) /* check handle initialization */
613 {
614 return 3; /* return error */
615 }
616
617 input_len = 9; /* set the input length */
618 input_buf[0] = (NTAG21X_COMMAND_SELECT_CL1 >> 8) & 0xFF; /* set the command */
619 input_buf[1] = (NTAG21X_COMMAND_SELECT_CL1 >> 0) & 0xFF; /* set the command */
620 input_buf[6] = 0; /* init 0 */
621 for (i = 0; i < 4; i++) /* run 4 times */
622 {
623 input_buf[2 + i] = id[i]; /* get one id */
624 input_buf[6] ^= id[i]; /* xor */
625 }
626 a_ntag21x_iso14443a_crc(input_buf, 7, input_buf + 7); /* get the crc */
627 output_len = 1; /* set the output length */
628 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
629 if (res != 0) /* check the result */
630 {
631 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
632
633 return 1; /* return error */
634 }
635 if (output_len != 1) /* check the output_len */
636 {
637 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
638
639 return 4; /* return error */
640 }
641 if (output_buf[0] == 0x04) /* check the sak */
642 {
643 return 0; /* success return 0 */
644 }
645 else
646 {
647 handle->debug_print("ntag21x: sak error.\n"); /* sak error */
648
649 return 5; /* return error */
650 }
651}
652
666uint8_t ntag21x_select_cl2(ntag21x_handle_t *handle, uint8_t id[4])
667{
668 uint8_t res;
669 uint8_t i;
670 uint8_t input_len;
671 uint8_t input_buf[9];
672 uint8_t output_len;
673 uint8_t output_buf[1];
674
675 if (handle == NULL) /* check handle */
676 {
677 return 2; /* return error */
678 }
679 if (handle->inited != 1) /* check handle initialization */
680 {
681 return 3; /* return error */
682 }
683
684 input_len = 9; /* set the input length */
685 input_buf[0] = (NTAG21X_COMMAND_SELECT_CL2 >> 8) & 0xFF; /* set the command */
686 input_buf[1] = (NTAG21X_COMMAND_SELECT_CL2 >> 0) & 0xFF; /* set the command */
687 input_buf[6] = 0; /* init 0 */
688 for (i = 0; i < 4; i++) /* run 4 times */
689 {
690 input_buf[2 + i] = id[i]; /* get one id */
691 input_buf[6] ^= id[i]; /* xor */
692 }
693 a_ntag21x_iso14443a_crc(input_buf, 7, input_buf + 7); /* get the crc */
694 output_len = 1; /* set the output length */
695 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
696 if (res != 0) /* check the result */
697 {
698 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
699
700 return 1; /* return error */
701 }
702 if (output_len != 1) /* check the output_len */
703 {
704 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
705
706 return 4; /* return error */
707 }
708 if (output_buf[0] == 0x00) /* check the sak */
709 {
710 return 0; /* success return 0 */
711 }
712 else
713 {
714 handle->debug_print("ntag21x: sak error.\n"); /* sak error */
715
716 return 5; /* return error */
717 }
718}
719
734{
735 uint8_t res;
736 uint8_t input_len;
737 uint8_t input_buf[3];
738 uint8_t output_len;
739 uint8_t output_buf[10];
740 uint8_t crc_buf[2];
741
742 if (handle == NULL) /* check handle */
743 {
744 return 2; /* return error */
745 }
746 if (handle->inited != 1) /* check handle initialization */
747 {
748 return 3; /* return error */
749 }
750
751 input_len = 3; /* set the input length */
752 input_buf[0] = NTAG21X_COMMAND_GET_VERSION; /* set the command */
753 a_ntag21x_iso14443a_crc(input_buf, 1, input_buf + 1); /* get the crc */
754 output_len = 10; /* set the output length */
755 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
756 if (res != 0) /* check the result */
757 {
758 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
759
760 return 1; /* return error */
761 }
762 if (output_len != 10) /* check the output_len */
763 {
764 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
765
766 return 4; /* return error */
767 }
768 a_ntag21x_iso14443a_crc(output_buf, 8, crc_buf); /* get the crc */
769 if ((output_buf[8] == crc_buf[0]) && (output_buf[9] == crc_buf[1])) /* check the crc */
770 {
771 version->fixed_header = output_buf[0]; /* fixed header */
772 version->vendor_id = output_buf[1]; /* vendor id */
773 version->product_type = output_buf[2]; /* product type */
774 version->product_subtype = output_buf[3]; /* product subtype */
775 version->major_product_version = output_buf[4]; /* major product version */
776 version->minor_product_version = output_buf[5]; /* minor product version */
777 version->storage_size = output_buf[6]; /* storage size */
778 if (version->storage_size == 0x0F) /* ntag213 */
779 {
780 handle->end_page = 0x2C; /* set the last page */
781 }
782 else if (version->storage_size == 0x11) /* ntag215 */
783 {
784 handle->end_page = 0x86; /* set the last page */
785 }
786 else if (version->storage_size == 0x13) /* ntag216 */
787 {
788 handle->end_page = 0xE6; /* set the last page */
789 }
790 else /* unknown */
791 {
792 handle->end_page = 0xFF; /* set 0xFF */
793 }
794 version->protocol_type = output_buf[7]; /* protocol type */
795
796 return 0; /* success return 0 */
797 }
798 else
799 {
800 handle->debug_print("ntag21x: crc error.\n"); /* crc error */
801
802 return 5; /* return error */
803 }
804}
805
819uint8_t ntag21x_read_counter(ntag21x_handle_t *handle, uint32_t *cnt)
820{
821 uint8_t res;
822 uint8_t input_len;
823 uint8_t input_buf[4];
824 uint8_t output_len;
825 uint8_t output_buf[5];
826 uint8_t crc_buf[2];
827
828 if (handle == NULL) /* check handle */
829 {
830 return 2; /* return error */
831 }
832 if (handle->inited != 1) /* check handle initialization */
833 {
834 return 3; /* return error */
835 }
836
837 input_len = 4; /* set the input length */
838 input_buf[0] = NTAG21X_COMMAND_READ_CNT; /* set the command */
839 input_buf[1] = 0x02; /* set the address */
840 a_ntag21x_iso14443a_crc(input_buf, 2, input_buf + 2); /* get the crc */
841 output_len = 5; /* set the output length */
842 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
843 if (res != 0) /* check the result */
844 {
845 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
846
847 return 1; /* return error */
848 }
849 if (output_len != 5) /* check the output_len */
850 {
851 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
852
853 return 4; /* return error */
854 }
855 a_ntag21x_iso14443a_crc(output_buf, 3, crc_buf); /* get the crc */
856 if ((output_buf[3] == crc_buf[0]) && (output_buf[4] == crc_buf[1])) /* check the result */
857 {
858 *cnt = ((uint32_t)output_buf[2] << 16) | ((uint32_t)output_buf[1] << 8) |
859 ((uint32_t)output_buf[0] << 0); /* set the counter */
860
861 return 0; /* success return 0 */
862 }
863 else
864 {
865 handle->debug_print("ntag21x: crc error.\n"); /* crc error */
866
867 return 5; /* return error */
868 }
869}
870
884uint8_t ntag21x_read_signature(ntag21x_handle_t *handle, uint8_t signature[32])
885{
886 uint8_t res;
887 uint8_t input_len;
888 uint8_t input_buf[4];
889 uint8_t output_len;
890 uint8_t output_buf[34];
891 uint8_t crc_buf[2];
892
893 if (handle == NULL) /* check handle */
894 {
895 return 2; /* return error */
896 }
897 if (handle->inited != 1) /* check handle initialization */
898 {
899 return 3; /* return error */
900 }
901
902 input_len = 4; /* set the input length */
903 input_buf[0] = NTAG21X_COMMAND_READ_SIG; /* set the command */
904 input_buf[1] = 0x00; /* set the address */
905 a_ntag21x_iso14443a_crc(input_buf, 2, input_buf + 2); /* get the crc */
906 output_len = 34; /* set the output length */
907 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
908 if (res != 0) /* check the result */
909 {
910 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
911
912 return 1; /* return error */
913 }
914 if (output_len != 34) /* check the output_len */
915 {
916 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
917
918 return 4; /* return error */
919 }
920 a_ntag21x_iso14443a_crc(output_buf, 32, crc_buf); /* get the crc */
921 if ((output_buf[32] == crc_buf[0]) && (output_buf[33] == crc_buf[1])) /* check the result */
922 {
923 memcpy(signature, output_buf, 32); /* copy the data */
924
925 return 0; /* success return 0 */
926 }
927 else
928 {
929 handle->debug_print("ntag21x: crc error.\n"); /* crc error */
930
931 return 5; /* return error */
932 }
933}
934
948uint8_t ntag21x_get_serial_number(ntag21x_handle_t *handle, uint8_t number[7])
949{
950 uint8_t res;
951 uint8_t input_len;
952 uint8_t input_buf[4];
953 uint8_t output_len;
954 uint8_t output_buf[18];
955 uint8_t crc_buf[2];
956
957 if (handle == NULL) /* check handle */
958 {
959 return 2; /* return error */
960 }
961 if (handle->inited != 1) /* check handle initialization */
962 {
963 return 3; /* return error */
964 }
965
966 input_len = 4; /* set the input length */
967 input_buf[0] = NTAG21X_COMMAND_READ; /* set the command */
968 input_buf[1] = 0x00; /* set the read page */
969 a_ntag21x_iso14443a_crc(input_buf , 2, input_buf + 2); /* get the crc */
970 output_len = 18; /* set the output length */
971 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
972 if (res != 0) /* check the result */
973 {
974 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
975
976 return 1; /* return error */
977 }
978 if (output_len != 18) /* check the output_len */
979 {
980 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
981
982 return 4; /* return error */
983 }
984 a_ntag21x_iso14443a_crc(output_buf, 16, crc_buf); /* get the crc */
985 if ((output_buf[16] == crc_buf[0]) && (output_buf[17] == crc_buf[1])) /* check the crc */
986 {
987 number[0] = output_buf[0]; /* set the number 0 */
988 number[1] = output_buf[1]; /* set the number 1 */
989 number[2] = output_buf[2]; /* set the number 2 */
990 number[3] = output_buf[4]; /* set the number 3 */
991 number[4] = output_buf[5]; /* set the number 4 */
992 number[5] = output_buf[6]; /* set the number 5 */
993 number[6] = output_buf[7]; /* set the number 6 */
994
995 return 0; /* success return 0 */
996 }
997 else
998 {
999 handle->debug_print("ntag21x: crc error.\n"); /* crc error */
1000
1001 return 5; /* return error */
1002 }
1003}
1004
1020{
1021 uint8_t res;
1022 uint8_t input_len;
1023 uint8_t input_buf[4];
1024 uint8_t output_len;
1025 uint8_t output_buf[18];
1026 uint8_t crc_buf[2];
1027
1028 if (handle == NULL) /* check handle */
1029 {
1030 return 2; /* return error */
1031 }
1032 if (handle->inited != 1) /* check handle initialization */
1033 {
1034 return 3; /* return error */
1035 }
1036
1037 input_len = 4; /* set the input length */
1038 input_buf[0] = NTAG21X_COMMAND_READ; /* set the command */
1039 input_buf[1] = 0x00; /* set the read page */
1040 a_ntag21x_iso14443a_crc(input_buf , 2, input_buf + 2); /* get the crc */
1041 output_len = 18; /* set the output length */
1042 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
1043 if (res != 0) /* check the result */
1044 {
1045 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
1046
1047 return 1; /* return error */
1048 }
1049 if (output_len != 18) /* check the output_len */
1050 {
1051 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
1052
1053 return 4; /* return error */
1054 }
1055 a_ntag21x_iso14443a_crc(output_buf, 16, crc_buf); /* get the crc */
1056 if ((output_buf[16] == crc_buf[0]) && (output_buf[17] == crc_buf[1])) /* check the crc */
1057 {
1058 if ((output_buf[12] == 0xE1) && (output_buf[13] == 0x10) &&
1059 (output_buf[15] == 0x00) /* check the data */
1060 )
1061 {
1062 if (output_buf[14] == 0x12) /* ntag213 */
1063 {
1064 *container = NTAG21X_CAPABILITY_CONTAINER_144_BYTE_NTAG213; /* set the ntag213 */
1065 handle->end_page = 0x2C; /* set the end page */
1066 }
1067 else if (output_buf[14] == 0x3E) /* ntag215 */
1068 {
1069 *container = NTAG21X_CAPABILITY_CONTAINER_496_BYTE_NTAG215; /* set the ntag215 */
1070 handle->end_page = 0x86; /* set the end page */
1071 }
1072 else if (output_buf[14] == 0x6D) /* ntag216 */
1073 {
1074 *container = NTAG21X_CAPABILITY_CONTAINER_872_BYTE_NTAG216; /* set the ntag216 */
1075 handle->end_page = 0xE6; /* set the end page */
1076 }
1077 else
1078 {
1079 handle->debug_print("ntag21x: data is invalid.\n"); /* data is invalid */
1080
1081 return 6; /* return error */
1082 }
1083
1084 return 0; /* success return 0 */
1085 }
1086 else
1087 {
1088 handle->debug_print("ntag21x: data is invalid.\n"); /* data is invalid */
1089
1090 return 6; /* return error */
1091 }
1092 }
1093 else
1094 {
1095 handle->debug_print("ntag21x: crc error.\n"); /* crc error */
1096
1097 return 5; /* return error */
1098 }
1099}
1100
1115uint8_t ntag21x_read_four_pages(ntag21x_handle_t *handle, uint8_t start_page, uint8_t data[16])
1116{
1117 uint8_t res;
1118 uint8_t input_len;
1119 uint8_t input_buf[4];
1120 uint8_t output_len;
1121 uint8_t output_buf[18];
1122 uint8_t crc_buf[2];
1123
1124 if (handle == NULL) /* check handle */
1125 {
1126 return 2; /* return error */
1127 }
1128 if (handle->inited != 1) /* check handle initialization */
1129 {
1130 return 3; /* return error */
1131 }
1132
1133 input_len = 4; /* set the input length */
1134 input_buf[0] = NTAG21X_COMMAND_READ; /* set the command */
1135 input_buf[1] = start_page; /* set the page */
1136 a_ntag21x_iso14443a_crc(input_buf , 2, input_buf + 2); /* get the crc */
1137 output_len = 18; /* set the output length */
1138 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
1139 if (res != 0) /* check the result */
1140 {
1141 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
1142
1143 return 1; /* return error */
1144 }
1145 if (output_len != 18) /* check the output_len */
1146 {
1147 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
1148
1149 return 4; /* return error */
1150 }
1151 a_ntag21x_iso14443a_crc(output_buf, 16, crc_buf); /* get the crc */
1152 if ((output_buf[16] == crc_buf[0]) && (output_buf[17] == crc_buf[1])) /* check the crc */
1153 {
1154 memcpy(data, output_buf, 16); /* copy the data */
1155
1156 return 0; /* success return 0 */
1157 }
1158 else
1159 {
1160 handle->debug_print("ntag21x: crc error.\n"); /* crc error */
1161
1162 return 5; /* return error */
1163 }
1164}
1165
1180uint8_t ntag21x_read_page(ntag21x_handle_t *handle, uint8_t page, uint8_t data[4])
1181{
1182 uint8_t res;
1183 uint8_t input_len;
1184 uint8_t input_buf[4];
1185 uint8_t output_len;
1186 uint8_t output_buf[18];
1187 uint8_t crc_buf[2];
1188
1189 if (handle == NULL) /* check handle */
1190 {
1191 return 2; /* return error */
1192 }
1193 if (handle->inited != 1) /* check handle initialization */
1194 {
1195 return 3; /* return error */
1196 }
1197
1198 input_len = 4; /* set the input length */
1199 input_buf[0] = NTAG21X_COMMAND_READ; /* set the command */
1200 input_buf[1] = page; /* set the page */
1201 a_ntag21x_iso14443a_crc(input_buf , 2, input_buf + 2); /* get the crc */
1202 output_len = 18; /* set the output length */
1203 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
1204 if (res != 0) /* check the result */
1205 {
1206 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
1207
1208 return 1; /* return error */
1209 }
1210 if (output_len != 18) /* check the output_len */
1211 {
1212 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
1213
1214 return 4; /* return error */
1215 }
1216 a_ntag21x_iso14443a_crc(output_buf, 16, crc_buf); /* get the crc */
1217 if ((output_buf[16] == crc_buf[0]) && (output_buf[17] == crc_buf[1])) /* check the crc */
1218 {
1219 memcpy(data, output_buf, 4); /* copy the data */
1220
1221 return 0; /* success return 0 */
1222 }
1223 else
1224 {
1225 handle->debug_print("ntag21x: crc error.\n"); /* crc error */
1226
1227 return 5; /* return error */
1228 }
1229}
1230
1251uint8_t ntag21x_fast_read_page(ntag21x_handle_t *handle, uint8_t start_page, uint8_t stop_page, uint8_t *data, uint16_t *len)
1252{
1253 uint8_t res;
1254 uint8_t input_len;
1255 uint8_t input_buf[5];
1256 uint8_t output_len;
1257 uint8_t cal_len;
1258 uint8_t output_buf[64];
1259 uint8_t crc_buf[2];
1260
1261 if (handle == NULL) /* check handle */
1262 {
1263 return 2; /* return error */
1264 }
1265 if (handle->inited != 1) /* check handle initialization */
1266 {
1267 return 3; /* return error */
1268 }
1269 if (stop_page < start_page) /* check start and stop page */
1270 {
1271 handle->debug_print("ntag21x: stop_page < start_page.\n"); /* stop_page < start_page */
1272
1273 return 4; /* return error */
1274 }
1275 if (stop_page - start_page + 1 > 15) /* check start and stop page */
1276 {
1277 handle->debug_print("ntag21x: stop_page - start_page + 1 is over 15.\n"); /* stop_page - start_page + 1 is over 15 */
1278
1279 return 5; /* return error */
1280 }
1281 if ((*len) < (4 * (stop_page - start_page + 1))) /* check the length */
1282 {
1283 handle->debug_print("ntag21x: len < %d.\n", 4 * (stop_page - start_page + 1)); /* len is invalid */
1284
1285 return 6; /* return error */
1286 }
1287
1288 input_len = 5; /* set the input length */
1289 input_buf[0] = NTAG21X_COMMAND_FAST_READ; /* set the command */
1290 input_buf[1] = start_page; /* set the start page */
1291 input_buf[2] = stop_page; /* set the stop page */
1292 a_ntag21x_iso14443a_crc(input_buf , 3, input_buf + 3); /* get the crc */
1293 cal_len = 4 * (stop_page - start_page + 1); /* set the cal length */
1294 output_len = (uint8_t)(cal_len + 2); /* set the output length */
1295 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
1296 if (res != 0) /* check the result */
1297 {
1298 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
1299
1300 return 1; /* return error */
1301 }
1302 if (output_len != (cal_len + 2)) /* check the output_len */
1303 {
1304 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
1305
1306 return 7; /* return error */
1307 }
1308 a_ntag21x_iso14443a_crc(output_buf, (uint8_t)cal_len, crc_buf); /* get the crc */
1309 if ((output_buf[cal_len] == crc_buf[0]) && (output_buf[cal_len + 1] == crc_buf[1])) /* check the crc */
1310 {
1311 memcpy(data, output_buf, cal_len); /* copy the data */
1312 *len = cal_len; /* set the length */
1313
1314 return 0; /* success return 0 */
1315 }
1316 else
1317 {
1318 handle->debug_print("ntag21x: crc error.\n"); /* crc error */
1319
1320 return 8; /* return error */
1321 }
1322}
1323
1338uint8_t ntag21x_compatibility_write_page(ntag21x_handle_t *handle, uint8_t page, uint8_t data[4])
1339{
1340 uint8_t res;
1341 uint8_t i;
1342 uint8_t input_len;
1343 uint8_t input_buf[18];
1344 uint8_t output_len;
1345 uint8_t output_buf[1];
1346
1347 if (handle == NULL) /* check handle */
1348 {
1349 return 2; /* return error */
1350 }
1351 if (handle->inited != 1) /* check handle initialization */
1352 {
1353 return 3; /* return error */
1354 }
1355
1356 input_len = 4; /* set the input length */
1357 input_buf[0] = NTAG21X_COMMAND_COMP_WRITE; /* set the command */
1358 input_buf[1] = page; /* set the page */
1359 a_ntag21x_iso14443a_crc(input_buf, 2, input_buf + 2); /* get the crc */
1360 output_len = 1; /* set the output length */
1361 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
1362 if (res != 0) /* check the result */
1363 {
1364 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
1365
1366 return 1; /* return error */
1367 }
1368 if (output_len != 1) /* check the output_len */
1369 {
1370 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
1371
1372 return 4; /* return error */
1373 }
1374 if (output_buf[0] != 0xA) /* check the result */
1375 {
1376 handle->debug_print("ntag21x: ack error.\n"); /* ack error */
1377
1378 return 5; /* return error */
1379 }
1380
1381 for (i = 0; i < 4; i ++) /* 4 times */
1382 {
1383 input_buf[i] = data[i]; /* copy data */
1384 }
1385 for (i = 0; i < 12; i ++) /* 12 times */
1386 {
1387 input_buf[4 + i] = 0x00; /* copy data */
1388 }
1389 a_ntag21x_iso14443a_crc(input_buf, 16, input_buf + 16); /* get the crc */
1390 input_len = 18; /* set the input length */
1391 output_len = 1; /* set the output length */
1392 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
1393 if (res != 0) /* check the result */
1394 {
1395 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
1396
1397 return 1; /* return error */
1398 }
1399 if (output_buf[0] != 0xA) /* check the result */
1400 {
1401 handle->debug_print("ntag21x: ack error.\n"); /* ack error */
1402
1403 return 5; /* return error */
1404 }
1405
1406 return 0; /* success return 0 */
1407}
1408
1423uint8_t ntag21x_write_page(ntag21x_handle_t *handle, uint8_t page, uint8_t data[4])
1424{
1425 uint8_t res;
1426 uint8_t input_len;
1427 uint8_t input_buf[8];
1428 uint8_t output_len;
1429 uint8_t output_buf[1];
1430
1431 if (handle == NULL) /* check handle */
1432 {
1433 return 2; /* return error */
1434 }
1435 if (handle->inited != 1) /* check handle initialization */
1436 {
1437 return 3; /* return error */
1438 }
1439
1440 input_len = 8; /* set the input length */
1441 input_buf[0] = NTAG21X_COMMAND_WRITE; /* set the command */
1442 input_buf[1] = page; /* set the page */
1443 input_buf[2] = data[0]; /* set data0 */
1444 input_buf[3] = data[1]; /* set data1 */
1445 input_buf[4] = data[2]; /* set data2 */
1446 input_buf[5] = data[3]; /* set data3 */
1447 a_ntag21x_iso14443a_crc(input_buf, 6, input_buf + 6); /* get the crc */
1448 output_len = 1; /* set the output length */
1449 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
1450 if (res != 0) /* check the result */
1451 {
1452 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
1453
1454 return 1; /* return error */
1455 }
1456 if (output_len != 1) /* check the output_len */
1457 {
1458 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
1459
1460 return 4; /* return error */
1461 }
1462 if (output_buf[0] != 0xA) /* check the result */
1463 {
1464 handle->debug_print("ntag21x: ack error.\n"); /* ack error */
1465
1466 return 5; /* return error */
1467 }
1468
1469 return 0; /* success return 0 */
1470}
1471
1487uint8_t ntag21x_authenticate(ntag21x_handle_t *handle, uint8_t pwd[4], uint8_t pack[2])
1488{
1489 uint8_t res;
1490 uint8_t input_len;
1491 uint8_t input_buf[7];
1492 uint8_t output_len;
1493 uint8_t output_buf[4];
1494 uint8_t crc_buf[2];
1495
1496 if (handle == NULL) /* check handle */
1497 {
1498 return 2; /* return error */
1499 }
1500 if (handle->inited != 1) /* check handle initialization */
1501 {
1502 return 3; /* return error */
1503 }
1504
1505 input_len = 7; /* set the input length */
1506 input_buf[0] = NTAG21X_COMMAND_PWD_AUTH; /* set the command */
1507 input_buf[1] = pwd[0]; /* set pwd0 */
1508 input_buf[2] = pwd[1]; /* set pwd1 */
1509 input_buf[3] = pwd[2]; /* set pwd2 */
1510 input_buf[4] = pwd[3]; /* set pwd3 */
1511 a_ntag21x_iso14443a_crc(input_buf, 5, input_buf + 5); /* get the crc */
1512 output_len = 4; /* set the output length */
1513 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
1514 if (res != 0) /* check the result */
1515 {
1516 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
1517
1518 return 1; /* return error */
1519 }
1520 if (output_len != 4) /* check the output_len */
1521 {
1522 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
1523
1524 return 4; /* return error */
1525 }
1526 a_ntag21x_iso14443a_crc(output_buf, 2, crc_buf); /* get the crc */
1527 if ((output_buf[2] == crc_buf[0]) && (output_buf[3] == crc_buf[1])) /* check the crc */
1528 {
1529 if ((output_buf[0] != pack[0]) || (output_buf[1] != pack[1])) /* check the pack */
1530 {
1531 handle->debug_print("ntag21x: pack check failed.\n"); /* pack check failed. */
1532
1533 return 6; /* return error */
1534 }
1535
1536 return 0; /* success return 0 */
1537 }
1538 else
1539 {
1540 handle->debug_print("ntag21x: crc error.\n"); /* crc error */
1541
1542 return 5; /* return error */
1543 }
1544}
1545
1559uint8_t ntag21x_set_password(ntag21x_handle_t *handle, uint8_t pwd[4])
1560{
1561 uint8_t res;
1562 uint8_t input_len;
1563 uint8_t input_buf[8];
1564 uint8_t output_len;
1565 uint8_t output_buf[1];
1566
1567 if (handle == NULL) /* check handle */
1568 {
1569 return 2; /* return error */
1570 }
1571 if (handle->inited != 1) /* check handle initialization */
1572 {
1573 return 3; /* return error */
1574 }
1575
1576 input_len = 8; /* set the input length */
1577 input_buf[0] = NTAG21X_COMMAND_WRITE; /* set the command */
1578 input_buf[1] = handle->end_page - 1; /* set the last page */
1579 input_buf[2] = pwd[0]; /* set pwd0 */
1580 input_buf[3] = pwd[1]; /* set pwd1 */
1581 input_buf[4] = pwd[2]; /* set pwd2 */
1582 input_buf[5] = pwd[3]; /* set pwd3 */
1583 a_ntag21x_iso14443a_crc(input_buf, 6, input_buf + 6); /* get the crc */
1584 output_len = 1; /* set the output length */
1585 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
1586 if (res != 0) /* check the result */
1587 {
1588 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
1589
1590 return 1; /* return error */
1591 }
1592 if (output_len != 1) /* check the output_len */
1593 {
1594 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
1595
1596 return 4; /* return error */
1597 }
1598 if (output_buf[0] != 0xA) /* check the result */
1599 {
1600 handle->debug_print("ntag21x: ack error.\n"); /* ack error */
1601
1602 return 5; /* return error */
1603 }
1604
1605 return 0; /* success return 0 */
1606}
1607
1621uint8_t ntag21x_set_pack(ntag21x_handle_t *handle, uint8_t pack[2])
1622{
1623 uint8_t res;
1624 uint8_t input_len;
1625 uint8_t input_buf[8];
1626 uint8_t output_len;
1627 uint8_t output_buf[1];
1628
1629 if (handle == NULL) /* check handle */
1630 {
1631 return 2; /* return error */
1632 }
1633 if (handle->inited != 1) /* check handle initialization */
1634 {
1635 return 3; /* return error */
1636 }
1637
1638 input_len = 8; /* set the input length */
1639 input_buf[0] = NTAG21X_COMMAND_WRITE; /* set the command */
1640 input_buf[1] = handle->end_page; /* set the last page */
1641 input_buf[2] = pack[0]; /* set pack0 */
1642 input_buf[3] = pack[1]; /* set pack1 */
1643 input_buf[4] = 0x00; /* set 0x00 */
1644 input_buf[5] = 0x00; /* set 0x00 */
1645 a_ntag21x_iso14443a_crc(input_buf, 6, input_buf + 6); /* get the crc */
1646 output_len = 1; /* set the output length */
1647 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
1648 if (res != 0) /* check the result */
1649 {
1650 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
1651
1652 return 1; /* return error */
1653 }
1654 if (output_len != 1) /* check the output_len */
1655 {
1656 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
1657
1658 return 4; /* return error */
1659 }
1660 if (output_buf[0] != 0xA) /* check the result */
1661 {
1662 handle->debug_print("ntag21x: ack error.\n"); /* ack error */
1663
1664 return 5; /* return error */
1665 }
1666
1667 return 0; /* success return 0 */
1668}
1669
1712uint8_t ntag21x_set_dynamic_lock(ntag21x_handle_t *handle, uint8_t lock[3])
1713{
1714 uint8_t res;
1715 uint8_t input_len;
1716 uint8_t input_buf[8];
1717 uint8_t output_len;
1718 uint8_t output_buf[1];
1719
1720 if (handle == NULL) /* check handle */
1721 {
1722 return 2; /* return error */
1723 }
1724 if (handle->inited != 1) /* check handle initialization */
1725 {
1726 return 3; /* return error */
1727 }
1728
1729 input_len = 8; /* set the input length */
1730 input_buf[0] = NTAG21X_COMMAND_WRITE; /* set the command */
1731 input_buf[1] = handle->end_page - 4; /* set the setting page */
1732 input_buf[2] = lock[0]; /* set lock0 */
1733 input_buf[3] = lock[1]; /* set lock1 */
1734 input_buf[4] = lock[2]; /* set lock2 */
1735 input_buf[5] = 0x00; /* set 0x00 */
1736 a_ntag21x_iso14443a_crc(input_buf, 6, input_buf + 6); /* get the crc */
1737 output_len = 1; /* set the output length */
1738 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
1739 if (res != 0) /* check the result */
1740 {
1741 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
1742
1743 return 1; /* return error */
1744 }
1745 if (output_len != 1) /* check the output_len */
1746 {
1747 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
1748
1749 return 4; /* return error */
1750 }
1751 if (output_buf[0] != 0xA) /* check the result */
1752 {
1753 handle->debug_print("ntag21x: ack error.\n"); /* ack error */
1754
1755 return 5; /* return error */
1756 }
1757
1758 return 0; /* success return 0 */
1759}
1760
1774uint8_t ntag21x_get_dynamic_lock(ntag21x_handle_t *handle, uint8_t lock[3])
1775{
1776 uint8_t res;
1777 uint8_t input_len;
1778 uint8_t input_buf[5];
1779 uint8_t output_len;
1780 uint8_t output_buf[6];
1781 uint8_t crc_buf[2];
1782
1783 if (handle == NULL) /* check handle */
1784 {
1785 return 2; /* return error */
1786 }
1787 if (handle->inited != 1) /* check handle initialization */
1788 {
1789 return 3; /* return error */
1790 }
1791
1792 input_len = 5; /* set the input length */
1793 input_buf[0] = NTAG21X_COMMAND_FAST_READ; /* set the command */
1794 input_buf[1] = handle->end_page - 4; /* set the start page */
1795 input_buf[2] = handle->end_page - 4; /* set the stop page */
1796 a_ntag21x_iso14443a_crc(input_buf , 3, input_buf + 3); /* get the crc */
1797 output_len = 6; /* set the output length */
1798 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
1799 if (res != 0) /* check the result */
1800 {
1801 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
1802
1803 return 1; /* return error */
1804 }
1805 if (output_len != 6) /* check the output_len */
1806 {
1807 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
1808
1809 return 4; /* return error */
1810 }
1811 a_ntag21x_iso14443a_crc(output_buf, 4, crc_buf); /* get the crc */
1812 if ((output_buf[4] == crc_buf[0]) && (output_buf[5] == crc_buf[1])) /* check the crc */
1813 {
1814 memcpy(lock, output_buf, 3); /* copy the data */
1815
1816 return 0; /* success return 0 */
1817 }
1818 else
1819 {
1820 handle->debug_print("ntag21x: crc error.\n"); /* crc error */
1821
1822 return 5; /* return error */
1823 }
1824}
1825
1844uint8_t ntag21x_set_static_lock(ntag21x_handle_t *handle, uint8_t lock[2])
1845{
1846 uint8_t res;
1847 uint8_t input_len;
1848 uint8_t input_buf[8];
1849 uint8_t output_len;
1850 uint8_t output_buf[1];
1851
1852 if (handle == NULL) /* check handle */
1853 {
1854 return 2; /* return error */
1855 }
1856 if (handle->inited != 1) /* check handle initialization */
1857 {
1858 return 3; /* return error */
1859 }
1860
1861 input_len = 8; /* set the input length */
1862 input_buf[0] = NTAG21X_COMMAND_WRITE; /* set the command */
1863 input_buf[1] = 0x02; /* set the setting page */
1864 input_buf[2] = 0x00; /* set 0x00 */
1865 input_buf[3] = 0x00; /* set 0x00 */
1866 input_buf[4] = lock[0]; /* set lock0 */
1867 input_buf[5] = lock[1]; /* set lock1 */
1868 a_ntag21x_iso14443a_crc(input_buf, 6, input_buf + 6); /* get the crc */
1869 output_len = 1; /* set the output length */
1870 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
1871 if (res != 0) /* check the result */
1872 {
1873 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
1874
1875 return 1; /* return error */
1876 }
1877 if (output_len != 1) /* check the output_len */
1878 {
1879 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
1880
1881 return 4; /* return error */
1882 }
1883 if (output_buf[0] != 0xA) /* check the result */
1884 {
1885 handle->debug_print("ntag21x: ack error.\n"); /* ack error */
1886
1887 return 5; /* return error */
1888 }
1889
1890 return 0; /* success return 0 */
1891}
1892
1906uint8_t ntag21x_get_static_lock(ntag21x_handle_t *handle, uint8_t lock[2])
1907{
1908 uint8_t res;
1909 uint8_t input_len;
1910 uint8_t input_buf[5];
1911 uint8_t output_len;
1912 uint8_t output_buf[6];
1913 uint8_t crc_buf[2];
1914
1915 if (handle == NULL) /* check handle */
1916 {
1917 return 2; /* return error */
1918 }
1919 if (handle->inited != 1) /* check handle initialization */
1920 {
1921 return 3; /* return error */
1922 }
1923
1924 input_len = 5; /* set the input length */
1925 input_buf[0] = NTAG21X_COMMAND_FAST_READ; /* set the command */
1926 input_buf[1] = 2; /* set the start page */
1927 input_buf[2] = 2; /* set the stop page */
1928 a_ntag21x_iso14443a_crc(input_buf , 3, input_buf + 3); /* get the crc */
1929 output_len = 6; /* set the output length */
1930 res = handle->contactless_transceiver(input_buf, input_len, output_buf, &output_len); /* transceiver */
1931 if (res != 0) /* check the result */
1932 {
1933 handle->debug_print("ntag21x: contactless transceiver failed.\n"); /* contactless transceiver failed */
1934
1935 return 1; /* return error */
1936 }
1937 if (output_len != 6) /* check the output_len */
1938 {
1939 handle->debug_print("ntag21x: output_len is invalid.\n"); /* output_len is invalid */
1940
1941 return 4; /* return error */
1942 }
1943 a_ntag21x_iso14443a_crc(output_buf, 4, crc_buf); /* get the crc */
1944 if ((output_buf[4] == crc_buf[0]) && (output_buf[5] == crc_buf[1])) /* check the crc */
1945 {
1946 memcpy(lock, output_buf + 2, 2); /* copy the data */
1947
1948 return 0; /* success return 0 */
1949 }
1950 else
1951 {
1952 handle->debug_print("ntag21x: crc error.\n"); /* crc error */
1953
1954 return 5; /* return error */
1955 }
1956}
1957
1970{
1971 uint8_t res;
1972 uint8_t conf[4];
1973
1974 if (handle == NULL) /* check handle */
1975 {
1976 return 2; /* return error */
1977 }
1978 if (handle->inited != 1) /* check handle initialization */
1979 {
1980 return 3; /* return error */
1981 }
1982
1983 memset(conf, 0, sizeof(uint8_t) * 4); /* clear the conf */
1984 res = a_ntag21x_conf_read(handle, handle->end_page - 3, conf); /* read conf */
1985 if (res != 0) /* check the result */
1986 {
1987 handle->debug_print("ntag21x: conf read failed.\n"); /* conf read failed */
1988
1989 return 1; /* return error */
1990 }
1991 conf[0] &= ~(3 << 6); /* clear the settings */
1992 conf[0] |= mirror << 6; /* set the mirror */
1993 res = a_ntag21x_conf_write(handle, handle->end_page - 3, conf); /* write conf */
1994 if (res != 0) /* check the result */
1995 {
1996 handle->debug_print("ntag21x: conf write failed.\n"); /* conf write failed */
1997
1998 return 1; /* return error */
1999 }
2000
2001 return 0; /* success return 0 */
2002}
2003
2016{
2017 uint8_t res;
2018 uint8_t conf[4];
2019
2020 if (handle == NULL) /* check handle */
2021 {
2022 return 2; /* return error */
2023 }
2024 if (handle->inited != 1) /* check handle initialization */
2025 {
2026 return 3; /* return error */
2027 }
2028
2029 memset(conf, 0, sizeof(uint8_t) * 4); /* clear the conf */
2030 res = a_ntag21x_conf_read(handle, handle->end_page - 3, conf); /* read conf */
2031 if (res != 0) /* check the result */
2032 {
2033 handle->debug_print("ntag21x: conf read failed.\n"); /* conf read failed */
2034
2035 return 1; /* return error */
2036 }
2037 *mirror = (ntag21x_mirror_t)((conf[0] >> 6) & 0x3); /* get the conf */
2038
2039 return 0; /* success return 0 */
2040}
2041
2054{
2055 uint8_t res;
2056 uint8_t conf[4];
2057
2058 if (handle == NULL) /* check handle */
2059 {
2060 return 2; /* return error */
2061 }
2062 if (handle->inited != 1) /* check handle initialization */
2063 {
2064 return 3; /* return error */
2065 }
2066
2067 memset(conf, 0, sizeof(uint8_t) * 4); /* clear the conf */
2068 res = a_ntag21x_conf_read(handle, handle->end_page - 3, conf); /* read conf */
2069 if (res != 0) /* check the result */
2070 {
2071 handle->debug_print("ntag21x: conf read failed.\n"); /* conf read failed */
2072
2073 return 1; /* return error */
2074 }
2075 conf[0] &= ~(3 << 4); /* clear the settings */
2076 conf[0] |= byte << 4; /* set the byte */
2077 res = a_ntag21x_conf_write(handle, handle->end_page - 3, conf); /* write conf */
2078 if (res != 0) /* check the result */
2079 {
2080 handle->debug_print("ntag21x: conf write failed.\n"); /* conf write failed */
2081
2082 return 1; /* return error */
2083 }
2084
2085 return 0; /* success return 0 */
2086}
2087
2100{
2101 uint8_t res;
2102 uint8_t conf[4];
2103
2104 if (handle == NULL) /* check handle */
2105 {
2106 return 2; /* return error */
2107 }
2108 if (handle->inited != 1) /* check handle initialization */
2109 {
2110 return 3; /* return error */
2111 }
2112
2113 memset(conf, 0, sizeof(uint8_t) * 4); /* clear the conf */
2114 res = a_ntag21x_conf_read(handle, handle->end_page - 3, conf); /* read conf */
2115 if (res != 0) /* check the result */
2116 {
2117 handle->debug_print("ntag21x: conf read failed.\n"); /* conf read failed */
2118
2119 return 1; /* return error */
2120 }
2121 *byte = (ntag21x_mirror_byte_t)((conf[0] >> 4) & 0x3); /* get the conf */
2122
2123 return 0; /* success return 0 */
2124}
2125
2138{
2139 uint8_t res;
2140 uint8_t conf[4];
2141
2142 if (handle == NULL) /* check handle */
2143 {
2144 return 2; /* return error */
2145 }
2146 if (handle->inited != 1) /* check handle initialization */
2147 {
2148 return 3; /* return error */
2149 }
2150
2151 memset(conf, 0, sizeof(uint8_t) * 4); /* clear the conf */
2152 res = a_ntag21x_conf_read(handle, handle->end_page - 3, conf); /* read conf */
2153 if (res != 0) /* check the result */
2154 {
2155 handle->debug_print("ntag21x: conf read failed.\n"); /* conf read failed */
2156
2157 return 1; /* return error */
2158 }
2159 conf[0] &= ~(1 << 2); /* clear the settings */
2160 conf[0] |= mode << 2; /* set the mode */
2161 res = a_ntag21x_conf_write(handle, handle->end_page - 3, conf); /* write conf */
2162 if (res != 0) /* check the result */
2163 {
2164 handle->debug_print("ntag21x: conf write failed.\n"); /* conf write failed */
2165
2166 return 1; /* return error */
2167 }
2168
2169 return 0; /* success return 0 */
2170}
2171
2184{
2185 uint8_t res;
2186 uint8_t conf[4];
2187
2188 if (handle == NULL) /* check handle */
2189 {
2190 return 2; /* return error */
2191 }
2192 if (handle->inited != 1) /* check handle initialization */
2193 {
2194 return 3; /* return error */
2195 }
2196
2197 memset(conf, 0, sizeof(uint8_t) * 4); /* clear the conf */
2198 res = a_ntag21x_conf_read(handle, handle->end_page - 3, conf); /* read conf */
2199 if (res != 0) /* check the result */
2200 {
2201 handle->debug_print("ntag21x: conf read failed.\n"); /* conf read failed */
2202
2203 return 1; /* return error */
2204 }
2205 *mode = (ntag21x_modulation_mode_t)((conf[0] >> 2) & 0x1); /* get the conf */
2206
2207 return 0; /* success return 0 */
2208}
2209
2221uint8_t ntag21x_set_mirror_page(ntag21x_handle_t *handle, uint8_t page)
2222{
2223 uint8_t res;
2224 uint8_t conf[4];
2225
2226 if (handle == NULL) /* check handle */
2227 {
2228 return 2; /* return error */
2229 }
2230 if (handle->inited != 1) /* check handle initialization */
2231 {
2232 return 3; /* return error */
2233 }
2234
2235 memset(conf, 0, sizeof(uint8_t) * 4); /* clear the conf */
2236 res = a_ntag21x_conf_read(handle, handle->end_page - 3, conf); /* read conf */
2237 if (res != 0) /* check the result */
2238 {
2239 handle->debug_print("ntag21x: conf read failed.\n"); /* conf read failed */
2240
2241 return 1; /* return error */
2242 }
2243 conf[2] = page; /* set the page */
2244 res = a_ntag21x_conf_write(handle, handle->end_page - 3, conf); /* write conf */
2245 if (res != 0) /* check the result */
2246 {
2247 handle->debug_print("ntag21x: conf write failed.\n"); /* conf write failed */
2248
2249 return 1; /* return error */
2250 }
2251
2252 return 0; /* success return 0 */
2253}
2254
2266uint8_t ntag21x_get_mirror_page(ntag21x_handle_t *handle, uint8_t *page)
2267{
2268 uint8_t res;
2269 uint8_t conf[4];
2270
2271 if (handle == NULL) /* check handle */
2272 {
2273 return 2; /* return error */
2274 }
2275 if (handle->inited != 1) /* check handle initialization */
2276 {
2277 return 3; /* return error */
2278 }
2279
2280 memset(conf, 0, sizeof(uint8_t) * 4); /* clear the conf */
2281 res = a_ntag21x_conf_read(handle, handle->end_page - 3, conf); /* read conf */
2282 if (res != 0) /* check the result */
2283 {
2284 handle->debug_print("ntag21x: conf read failed.\n"); /* conf read failed */
2285
2286 return 1; /* return error */
2287 }
2288 *page = conf[2]; /* get the page */
2289
2290 return 0; /* success return 0 */
2291}
2292
2305{
2306 uint8_t res;
2307 uint8_t conf[4];
2308
2309 if (handle == NULL) /* check handle */
2310 {
2311 return 2; /* return error */
2312 }
2313 if (handle->inited != 1) /* check handle initialization */
2314 {
2315 return 3; /* return error */
2316 }
2317
2318 memset(conf, 0, sizeof(uint8_t) * 4); /* clear the conf */
2319 res = a_ntag21x_conf_read(handle, handle->end_page - 3, conf); /* read conf */
2320 if (res != 0) /* check the result */
2321 {
2322 handle->debug_print("ntag21x: conf read failed.\n"); /* conf read failed */
2323
2324 return 1; /* return error */
2325 }
2326 conf[3] = page; /* set the page */
2327 res = a_ntag21x_conf_write(handle, handle->end_page - 3, conf); /* write conf */
2328 if (res != 0) /* check the result */
2329 {
2330 handle->debug_print("ntag21x: conf write failed.\n"); /* conf write failed */
2331
2332 return 1; /* return error */
2333 }
2334
2335 return 0; /* success return 0 */
2336}
2337
2350{
2351 uint8_t res;
2352 uint8_t conf[4];
2353
2354 if (handle == NULL) /* check handle */
2355 {
2356 return 2; /* return error */
2357 }
2358 if (handle->inited != 1) /* check handle initialization */
2359 {
2360 return 3; /* return error */
2361 }
2362
2363 memset(conf, 0, sizeof(uint8_t) * 4); /* clear the conf */
2364 res = a_ntag21x_conf_read(handle, handle->end_page - 3, conf); /* read conf */
2365 if (res != 0) /* check the result */
2366 {
2367 handle->debug_print("ntag21x: conf read failed.\n"); /* conf read failed */
2368
2369 return 1; /* return error */
2370 }
2371 *page = conf[3]; /* get the page */
2372
2373 return 0; /* success return 0 */
2374}
2375
2389{
2390 uint8_t res;
2391 uint8_t conf[4];
2392
2393 if (handle == NULL) /* check handle */
2394 {
2395 return 2; /* return error */
2396 }
2397 if (handle->inited != 1) /* check handle initialization */
2398 {
2399 return 3; /* return error */
2400 }
2401
2402 memset(conf, 0, sizeof(uint8_t) * 4); /* clear the conf */
2403 res = a_ntag21x_conf_read(handle, handle->end_page - 2, conf); /* read conf */
2404 if (res != 0) /* check the result */
2405 {
2406 handle->debug_print("ntag21x: conf read failed.\n"); /* conf read failed */
2407
2408 return 1; /* return error */
2409 }
2410 conf[0] &= ~(1 << access); /* clear the settings */
2411 conf[0] |= enable << access; /* set the access */
2412 res = a_ntag21x_conf_write(handle, handle->end_page - 2, conf); /* write conf */
2413 if (res != 0) /* check the result */
2414 {
2415 handle->debug_print("ntag21x: conf write failed.\n"); /* conf write failed */
2416
2417 return 1; /* return error */
2418 }
2419
2420 return 0; /* success return 0 */
2421}
2422
2436{
2437 uint8_t res;
2438 uint8_t conf[4];
2439
2440 if (handle == NULL) /* check handle */
2441 {
2442 return 2; /* return error */
2443 }
2444 if (handle->inited != 1) /* check handle initialization */
2445 {
2446 return 3; /* return error */
2447 }
2448
2449 memset(conf, 0, sizeof(uint8_t) * 4); /* clear the conf */
2450 res = a_ntag21x_conf_read(handle, handle->end_page - 2, conf); /* read conf */
2451 if (res != 0) /* check the result */
2452 {
2453 handle->debug_print("ntag21x: conf read failed.\n"); /* conf read failed */
2454
2455 return 1; /* return error */
2456 }
2457 *enable = (ntag21x_bool_t)((conf[0] >> access) & 0x1); /* get the bool */
2458
2459 return 0; /* success return 0 */
2460}
2461
2475{
2476 uint8_t res;
2477 uint8_t conf[4];
2478
2479 if (handle == NULL) /* check handle */
2480 {
2481 return 2; /* return error */
2482 }
2483 if (handle->inited != 1) /* check handle initialization */
2484 {
2485 return 3; /* return error */
2486 }
2487 if (limit > 7) /* check the limit */
2488 {
2489 handle->debug_print("ntag21x: limit > 7.\n"); /* limit > 7 */
2490
2491 return 4; /* return error */
2492 }
2493
2494 memset(conf, 0, sizeof(uint8_t) * 4); /* clear the conf */
2495 res = a_ntag21x_conf_read(handle, handle->end_page - 2, conf); /* read conf */
2496 if (res != 0) /* check the result */
2497 {
2498 handle->debug_print("ntag21x: conf read failed.\n"); /* conf read failed */
2499
2500 return 1; /* return error */
2501 }
2502 conf[0] &= ~(7 << 0); /* clear the settings */
2503 conf[0] |= limit << 0; /* set the limit */
2504 res = a_ntag21x_conf_write(handle, handle->end_page - 2, conf); /* write conf */
2505 if (res != 0) /* check the result */
2506 {
2507 handle->debug_print("ntag21x: conf write failed.\n"); /* conf write failed */
2508
2509 return 1; /* return error */
2510 }
2511
2512 return 0; /* success return 0 */
2513}
2514
2527{
2528 uint8_t res;
2529 uint8_t conf[4];
2530
2531 if (handle == NULL) /* check handle */
2532 {
2533 return 2; /* return error */
2534 }
2535 if (handle->inited != 1) /* check handle initialization */
2536 {
2537 return 3; /* return error */
2538 }
2539
2540 memset(conf, 0, sizeof(uint8_t) * 4); /* clear the conf */
2541 res = a_ntag21x_conf_read(handle, handle->end_page - 2, conf); /* read conf */
2542 if (res != 0) /* check the result */
2543 {
2544 handle->debug_print("ntag21x: conf read failed.\n"); /* conf read failed */
2545
2546 return 1; /* return error */
2547 }
2548 *limit = conf[0] & 0x7; /* set the limit */
2549
2550 return 0; /* success return 0 */
2551}
2552
2565uint8_t ntag21x_transceiver(ntag21x_handle_t *handle, uint8_t *in_buf, uint8_t in_len, uint8_t *out_buf, uint8_t *out_len)
2566{
2567 if (handle == NULL) /* check handle */
2568 {
2569 return 2; /* return error */
2570 }
2571 if (handle->inited != 1) /* check handle initialization */
2572 {
2573 return 3; /* return error */
2574 }
2575
2576 if (handle->contactless_transceiver(in_buf, in_len,
2577 out_buf, out_len) != 0) /* transceiver data */
2578 {
2579 return 1; /* return error */
2580 }
2581 else
2582 {
2583 return 0; /* success return 0 */
2584 }
2585}
2586
2596{
2597 if (info == NULL) /* check handle */
2598 {
2599 return 2; /* return error */
2600 }
2601
2602 memset(info, 0, sizeof(ntag21x_info_t)); /* initialize ntag21x info structure */
2603 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
2604 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
2605 strncpy(info->interface, "RF", 8); /* copy interface name */
2606 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
2607 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
2608 info->max_current_ma = MAX_CURRENT; /* set maximum current */
2609 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
2610 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
2611 info->driver_version = DRIVER_VERSION; /* set driver version */
2612
2613 return 0; /* success return 0 */
2614}
#define NTAG21X_COMMAND_FAST_READ
#define MAX_CURRENT
#define NTAG21X_COMMAND_ANTICOLLISION_CL1
#define NTAG21X_COMMAND_COMP_WRITE
#define NTAG21X_COMMAND_SELECT_CL1
#define NTAG21X_COMMAND_READ
#define SUPPLY_VOLTAGE_MAX
#define NTAG21X_COMMAND_READ_SIG
#define TEMPERATURE_MAX
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SUPPLY_VOLTAGE_MIN
#define NTAG21X_COMMAND_WAKE_UP
#define NTAG21X_COMMAND_PWD_AUTH
#define NTAG21X_COMMAND_READ_CNT
#define NTAG21X_COMMAND_GET_VERSION
#define NTAG21X_COMMAND_ANTICOLLISION_CL2
#define NTAG21X_COMMAND_WRITE
#define NTAG21X_COMMAND_HALT
#define NTAG21X_COMMAND_REQUEST
chip command definition
#define CHIP_NAME
chip information definition
#define NTAG21X_COMMAND_SELECT_CL2
#define DRIVER_VERSION
driver ntag21x 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_get_static_lock(ntag21x_handle_t *handle, uint8_t lock[2])
ntag21x get the static lock
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_get_dynamic_lock(ntag21x_handle_t *handle, uint8_t lock[3])
ntag21x get the dynamic lock
uint8_t ntag21x_get_mirror(ntag21x_handle_t *handle, ntag21x_mirror_t *mirror)
ntag21x get the mirror
uint8_t ntag21x_get_protect_start_page(ntag21x_handle_t *handle, uint8_t *page)
ntag21x get the start page of protection
uint8_t ntag21x_select_cl2(ntag21x_handle_t *handle, uint8_t id[4])
ntag21x select cl2
uint8_t ntag21x_compatibility_write_page(ntag21x_handle_t *handle, uint8_t page, uint8_t data[4])
ntag21x compatibility write page
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_get_mirror_byte(ntag21x_handle_t *handle, ntag21x_mirror_byte_t *byte)
ntag21x get the mirror byte
uint8_t ntag21x_set_protect_start_page(ntag21x_handle_t *handle, uint8_t page)
ntag21x set the start page of protection
uint8_t ntag21x_info(ntag21x_info_t *info)
get chip information
uint8_t ntag21x_write_page(ntag21x_handle_t *handle, uint8_t page, uint8_t data[4])
ntag21x write page
uint8_t ntag21x_get_authenticate_limitation(ntag21x_handle_t *handle, uint8_t *limit)
ntag21x get the authenticate limitation
uint8_t ntag21x_get_mirror_page(ntag21x_handle_t *handle, uint8_t *page)
ntag21x get the mirror page
struct ntag21x_info_s ntag21x_info_t
ntag21x information structure definition
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_get_access(ntag21x_handle_t *handle, ntag21x_access_t access, ntag21x_bool_t *enable)
ntag21x get the access status
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
uint8_t ntag21x_get_modulation_mode(ntag21x_handle_t *handle, ntag21x_modulation_mode_t *mode)
ntag21x get the modulation mode
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
@ NTAG21X_TYPE_INVALID
@ NTAG21X_TYPE_213_5_6
@ NTAG21X_CAPABILITY_CONTAINER_144_BYTE_NTAG213
@ NTAG21X_CAPABILITY_CONTAINER_496_BYTE_NTAG215
@ NTAG21X_CAPABILITY_CONTAINER_872_BYTE_NTAG216
uint8_t ntag21x_transceiver(ntag21x_handle_t *handle, uint8_t *in_buf, uint8_t in_len, uint8_t *out_buf, uint8_t *out_len)
transceiver data
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* contactless_deinit)(void)
uint8_t(* contactless_transceiver)(uint8_t *in_buf, uint8_t in_len, uint8_t *out_buf, uint8_t *out_len)
uint8_t(* contactless_init)(void)
uint32_t driver_version
char manufacturer_name[32]
uint8_t minor_product_version
uint8_t major_product_version