LibDriver NTAG21X
Loading...
Searching...
No Matches
driver_ntag21x_card_test.c
Go to the documentation of this file.
1
36
38#include <stdlib.h>
39
40static ntag21x_handle_t gs_handle;
41
49uint8_t ntag21x_card_test(void)
50{
51 uint8_t res;
52 uint8_t p;
53 uint8_t limit_check;
54 uint32_t i;
55 uint32_t cnt;
56 uint8_t id[4];
57 uint8_t number[7];
58 uint8_t signature[32];
59 uint8_t data[16];
60 uint8_t data_check[16];
61 uint8_t page[32];
62 uint8_t pack[2];
63 uint8_t pwd[4];
64 uint8_t lock[3];
65 uint8_t lock_check[3];
66 uint16_t len;
67 ntag21x_info_t info;
68 ntag21x_type_t type;
70 ntag21x_version_t version;
71 ntag21x_mirror_t mirror;
74 ntag21x_bool_t enable;
75
76 /* link functions */
83
84 /* get information */
85 res = ntag21x_info(&info);
86 if (res != 0)
87 {
88 ntag21x_interface_debug_print("ntag21x: get info failed.\n");
89
90 return 1;
91 }
92 else
93 {
94 /* print chip info */
95 ntag21x_interface_debug_print("ntag21x: chip is %s.\n", info.chip_name);
96 ntag21x_interface_debug_print("ntag21x: manufacturer is %s.\n", info.manufacturer_name);
97 ntag21x_interface_debug_print("ntag21x: interface is %s.\n", info.interface);
98 ntag21x_interface_debug_print("ntag21x: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
99 ntag21x_interface_debug_print("ntag21x: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
100 ntag21x_interface_debug_print("ntag21x: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
101 ntag21x_interface_debug_print("ntag21x: max current is %0.2fmA.\n", info.max_current_ma);
102 ntag21x_interface_debug_print("ntag21x: max temperature is %0.1fC.\n", info.temperature_max);
103 ntag21x_interface_debug_print("ntag21x: min temperature is %0.1fC.\n", info.temperature_min);
104 }
105
106 /* start register test */
107 ntag21x_interface_debug_print("ntag21x: start card test.\n");
108
109 /* init */
110 res = ntag21x_init(&gs_handle);
111 if (res != 0)
112 {
113 ntag21x_interface_debug_print("ntag21x: init failed.\n");
114
115 return 1;
116 }
117
118 /* wake up */
119 res = ntag21x_wake_up(&gs_handle, &type);
120 if (res != 0)
121 {
122 ntag21x_interface_debug_print("ntag21x: wake up failed.\n");
123 (void)ntag21x_deinit(&gs_handle);
124
125 return 1;
126 }
127 if (type == NTAG21X_TYPE_213_5_6)
128 {
129 ntag21x_interface_debug_print("ntag21x: find ntag213/5/6 card.\n");
130 }
131 else
132 {
133 ntag21x_interface_debug_print("ntag21x: invalid type.\n");
134 (void)ntag21x_deinit(&gs_handle);
135
136 return 1;
137 }
138
139 /* anti collision cl1 */
140 res = ntag21x_anticollision_cl1(&gs_handle, id);
141 if (res != 0)
142 {
143 ntag21x_interface_debug_print("ntag21x: anti collision cl1 failed.\n");
144 (void)ntag21x_deinit(&gs_handle);
145
146 return 1;
147 }
148
149 /* select cl1 */
150 res = ntag21x_select_cl1(&gs_handle, id);
151 if (res != 0)
152 {
153 ntag21x_interface_debug_print("ntag21x: select cl1 failed.\n");
154 (void)ntag21x_deinit(&gs_handle);
155
156 return 1;
157 }
158 ntag21x_interface_debug_print("ntag21x: id1 is 0x%02X 0x%02X 0x%02X 0x%02X.\n", id[0], id[1], id[2], id[3]);
159
160 /* anti collision cl2 */
161 res = ntag21x_anticollision_cl2(&gs_handle, id);
162 if (res != 0)
163 {
164 ntag21x_interface_debug_print("ntag21x: anti collision cl2 failed.\n");
165 (void)ntag21x_deinit(&gs_handle);
166
167 return 1;
168 }
169
170 /* anti collision cl2 */
171 res = ntag21x_anticollision_cl2(&gs_handle, id);
172 if (res != 0)
173 {
174 ntag21x_interface_debug_print("ntag21x: anti collision cl2 failed.\n");
175 (void)ntag21x_deinit(&gs_handle);
176
177 return 1;
178 }
179 ntag21x_interface_debug_print("ntag21x: id2 is 0x%02X 0x%02X 0x%02X 0x%02X.\n", id[0], id[1], id[2], id[3]);
180
181 /* get capability container */
182 res = ntag21x_get_capability_container(&gs_handle, &container);
183 if (res != 0)
184 {
185 ntag21x_interface_debug_print("ntag21x: get capability container failed.\n");
186 (void)ntag21x_deinit(&gs_handle);
187
188 return 1;
189 }
191 {
192 ntag21x_interface_debug_print("ntag21x: get capability container ntag213.\n");
193 }
195 {
196 ntag21x_interface_debug_print("ntag21x: get capability container ntag215.\n");
197 }
199 {
200 ntag21x_interface_debug_print("ntag21x: get capability container ntag216.\n");
201 }
202 else
203 {
204 ntag21x_interface_debug_print("ntag21x: unknown type.\n");
205 (void)ntag21x_deinit(&gs_handle);
206
207 return 1;
208 }
209
210 /* get serial number */
211 res = ntag21x_get_serial_number(&gs_handle, number);
212 if (res != 0)
213 {
214 ntag21x_interface_debug_print("ntag21x: get serial number failed.\n");
215 (void)ntag21x_deinit(&gs_handle);
216
217 return 1;
218 }
219 ntag21x_interface_debug_print("ntag21x: serial number is ");
220 for (i = 0; i < 7; i++)
221 {
222 ntag21x_interface_debug_print("0x%02X ", number[i]);
223 }
225
226 /* read signature */
227 res = ntag21x_read_signature(&gs_handle, signature);
228 if (res != 0)
229 {
230 ntag21x_interface_debug_print("ntag21x: read signature failed.\n");
231 (void)ntag21x_deinit(&gs_handle);
232
233 return 1;
234 }
235 ntag21x_interface_debug_print("ntag21x: signature is ");
236 for (i = 0; i < 32; i++)
237 {
238 ntag21x_interface_debug_print("0x%02X ", signature[i]);
239 }
241
242 ntag21x_interface_debug_print("ntag21x: read four pages from page 0.\n");
243
244 /* read four pages */
245 res = ntag21x_read_four_pages(&gs_handle, 0x00, data_check);
246 if (res != 0)
247 {
248 ntag21x_interface_debug_print("ntag21x: read four pages failed.\n");
249 (void)ntag21x_deinit(&gs_handle);
250
251 return 1;
252 }
253 for (i = 0; i < 16; i++)
254 {
255 ntag21x_interface_debug_print("0x%02X ", data_check[i]);
256 }
258
259 ntag21x_interface_debug_print("ntag21x: read page 3.\n");
260
261 /* read page */
262 res = ntag21x_read_page(&gs_handle, 0x3, data_check);
263 if (res != 0)
264 {
265 ntag21x_interface_debug_print("ntag21x: read page failed.\n");
266 (void)ntag21x_deinit(&gs_handle);
267
268 return 1;
269 }
270 for (i = 0; i < 4; i++)
271 {
272 ntag21x_interface_debug_print("0x%02X ", data_check[i]);
273 }
275
276 ntag21x_interface_debug_print("ntag21x: fast read page from page 0 - page 5.\n");
277
278 /* fast read page */
279 len = 32;
280 res = ntag21x_fast_read_page(&gs_handle, 0x00, 0x5, page, &len);
281 if (res != 0)
282 {
283 ntag21x_interface_debug_print("ntag21x: fast read page failed.\n");
284 (void)ntag21x_deinit(&gs_handle);
285
286 return 1;
287 }
288 for (i = 0; i < 32; i++)
289 {
290 ntag21x_interface_debug_print("0x%02X ", page[i]);
291 }
293
294 ntag21x_interface_debug_print("ntag21x: compatibility write page 16.\n");
295 for (i = 0; i < 4; i++)
296 {
297 data[i] = rand() % 256;
298 }
299 res = ntag21x_compatibility_write_page(&gs_handle, 16, data);
300 if (res != 0)
301 {
302 ntag21x_interface_debug_print("ntag21x: compatibility write page failed.\n");
303 (void)ntag21x_deinit(&gs_handle);
304
305 return 1;
306 }
307 res = ntag21x_read_page(&gs_handle, 16, data_check);
308 if (res != 0)
309 {
310 ntag21x_interface_debug_print("ntag21x: read page failed.\n");
311 (void)ntag21x_deinit(&gs_handle);
312
313 return 1;
314 }
315 ntag21x_interface_debug_print("ntag21x: check page %s.\n", memcmp(data, data_check, 4) == 0 ? "ok" : "error");
316
317 ntag21x_interface_debug_print("ntag21x: write page 17.\n");
318 for (i = 0; i < 4; i++)
319 {
320 data[i] = rand() % 256;
321 }
322 res = ntag21x_write_page(&gs_handle, 17, data);
323 if (res != 0)
324 {
325 ntag21x_interface_debug_print("ntag21x: write page failed.\n");
326 (void)ntag21x_deinit(&gs_handle);
327
328 return 1;
329 }
330 res = ntag21x_read_page(&gs_handle, 17, data_check);
331 if (res != 0)
332 {
333 ntag21x_interface_debug_print("ntag21x: read page failed.\n");
334 (void)ntag21x_deinit(&gs_handle);
335
336 return 1;
337 }
338 ntag21x_interface_debug_print("ntag21x: check page %s.\n", memcmp(data, data_check, 4) == 0 ? "ok" : "error");
339
340 /* check the password */
341 pwd[0] = 0xFF;
342 pwd[1] = 0xFF;
343 pwd[2] = 0xFF;
344 pwd[3] = 0xFF;
345 pack[0] = 0x00;
346 pack[1] = 0x00;
347 res = ntag21x_set_password(&gs_handle, pwd);
348 if (res != 0)
349 {
350 ntag21x_interface_debug_print("ntag21x: set password failed.\n");
351 (void)ntag21x_deinit(&gs_handle);
352
353 return 1;
354 }
355 res = ntag21x_set_pack(&gs_handle, pack);
356 if (res != 0)
357 {
358 ntag21x_interface_debug_print("ntag21x: set pack failed.\n");
359 (void)ntag21x_deinit(&gs_handle);
360
361 return 1;
362 }
363 ntag21x_interface_debug_print("ntag21x: authenticate.\n");
364 res = ntag21x_authenticate(&gs_handle, pwd, pack);
365 if (res != 0)
366 {
367 ntag21x_interface_debug_print("ntag21x: authenticate failed.\n");
368 (void)ntag21x_deinit(&gs_handle);
369
370 return 1;
371 }
372
373 /* get version */
374 res = ntag21x_get_version(&gs_handle, &version);
375 if (res != 0)
376 {
377 ntag21x_interface_debug_print("ntag21x: get version failed.\n");
378 (void)ntag21x_deinit(&gs_handle);
379
380 return 1;
381 }
382 ntag21x_interface_debug_print("ntag21x: fixed_header is 0x%02X\n", version.fixed_header);
383 ntag21x_interface_debug_print("ntag21x: vendor_id is 0x%02X\n", version.vendor_id);
384 ntag21x_interface_debug_print("ntag21x: product_type is 0x%02X\n", version.product_type);
385 ntag21x_interface_debug_print("ntag21x: product_subtype is 0x%02X\n", version.product_subtype);
386 ntag21x_interface_debug_print("ntag21x: major_product_version is 0x%02X\n", version.major_product_version);
387 ntag21x_interface_debug_print("ntag21x: minor_product_version is 0x%02X\n", version.minor_product_version);
388 ntag21x_interface_debug_print("ntag21x: storage_size is 0x%02X\n", version.storage_size);
389 ntag21x_interface_debug_print("ntag21x: protocol_type is 0x%02X\n", version.protocol_type);
390
391 /* set dynamic lock */
392 lock[0] = 0x00;
393 lock[1] = 0x00;
394 lock[2] = 0x00;
395 res = ntag21x_set_dynamic_lock(&gs_handle, lock);
396 if (res != 0)
397 {
398 ntag21x_interface_debug_print("ntag21x: set dynamic lock failed.\n");
399 (void)ntag21x_deinit(&gs_handle);
400
401 return 1;
402 }
403 ntag21x_interface_debug_print("ntag21x: set dynamic lock 0x%02X 0x%02X 0x%02X\n", lock[0], lock[1], lock[2]);
404 res = ntag21x_get_dynamic_lock(&gs_handle, lock_check);
405 if (res != 0)
406 {
407 ntag21x_interface_debug_print("ntag21x: get dynamic lock failed.\n");
408 (void)ntag21x_deinit(&gs_handle);
409
410 return 1;
411 }
412 ntag21x_interface_debug_print("ntag21x: get dynamic lock 0x%02X 0x%02X 0x%02X\n", lock_check[0], lock_check[1], lock_check[2]);
413
414 /* set static lock */
415 lock[0] = 0x00;
416 lock[1] = 0x00;
417 res = ntag21x_set_static_lock(&gs_handle, lock);
418 if (res != 0)
419 {
420 ntag21x_interface_debug_print("ntag21x: set static lock failed.\n");
421 (void)ntag21x_deinit(&gs_handle);
422
423 return 1;
424 }
425 ntag21x_interface_debug_print("ntag21x: set static lock 0x%02X 0x%02X\n", lock[0], lock[1]);
426 res = ntag21x_get_static_lock(&gs_handle, lock_check);
427 if (res != 0)
428 {
429 ntag21x_interface_debug_print("ntag21x: get static lock failed.\n");
430 (void)ntag21x_deinit(&gs_handle);
431
432 return 1;
433 }
434 ntag21x_interface_debug_print("ntag21x: get static lock 0x%02X 0x%02X\n", lock_check[0], lock_check[1]);
435
436 /* set uid and nfc counter mirror */
438 if (res != 0)
439 {
440 ntag21x_interface_debug_print("ntag21x: set mirror failed.\n");
441 (void)ntag21x_deinit(&gs_handle);
442
443 return 1;
444 }
445 ntag21x_interface_debug_print("ntag21x: set uid and nfc counter mirror.\n");
446 res = ntag21x_get_mirror(&gs_handle, &mirror);
447 if (res != 0)
448 {
449 ntag21x_interface_debug_print("ntag21x: get mirror failed.\n");
450 (void)ntag21x_deinit(&gs_handle);
451
452 return 1;
453 }
454 ntag21x_interface_debug_print("ntag21x: check mirror %s.\n", mirror == NTAG21X_MIRROR_UID_NFC_COUNTER_ASCII ? "ok" : "error");
455
456 /* set nfc counter mirror */
458 if (res != 0)
459 {
460 ntag21x_interface_debug_print("ntag21x: set mirror failed.\n");
461 (void)ntag21x_deinit(&gs_handle);
462
463 return 1;
464 }
465 ntag21x_interface_debug_print("ntag21x: set nfc counter mirror.\n");
466 res = ntag21x_get_mirror(&gs_handle, &mirror);
467 if (res != 0)
468 {
469 ntag21x_interface_debug_print("ntag21x: get mirror failed.\n");
470 (void)ntag21x_deinit(&gs_handle);
471
472 return 1;
473 }
474 ntag21x_interface_debug_print("ntag21x: check mirror %s.\n", mirror == NTAG21X_MIRROR_NFC_COUNTER_ASCII ? "ok" : "error");
475
476 /* set uid ascii mirror */
478 if (res != 0)
479 {
480 ntag21x_interface_debug_print("ntag21x: set mirror failed.\n");
481 (void)ntag21x_deinit(&gs_handle);
482
483 return 1;
484 }
485 ntag21x_interface_debug_print("ntag21x: set uid ascii mirror.\n");
486 res = ntag21x_get_mirror(&gs_handle, &mirror);
487 if (res != 0)
488 {
489 ntag21x_interface_debug_print("ntag21x: get mirror failed.\n");
490 (void)ntag21x_deinit(&gs_handle);
491
492 return 1;
493 }
494 ntag21x_interface_debug_print("ntag21x: check mirror %s.\n", mirror == NTAG21X_MIRROR_UID_ASCII ? "ok" : "error");
495
496 /* set no ascii mirror */
498 if (res != 0)
499 {
500 ntag21x_interface_debug_print("ntag21x: set mirror failed.\n");
501 (void)ntag21x_deinit(&gs_handle);
502
503 return 1;
504 }
505 ntag21x_interface_debug_print("ntag21x: set no ascii mirror.\n");
506 res = ntag21x_get_mirror(&gs_handle, &mirror);
507 if (res != 0)
508 {
509 ntag21x_interface_debug_print("ntag21x: get mirror failed.\n");
510 (void)ntag21x_deinit(&gs_handle);
511
512 return 1;
513 }
514 ntag21x_interface_debug_print("ntag21x: check mirror %s.\n", mirror == NTAG21X_MIRROR_NO_ASCII ? "ok" : "error");
515
516 /* set mirror byte 3 */
518 if (res != 0)
519 {
520 ntag21x_interface_debug_print("ntag21x: set mirror byte failed.\n");
521 (void)ntag21x_deinit(&gs_handle);
522
523 return 1;
524 }
525 ntag21x_interface_debug_print("ntag21x: set mirror byte 3.\n");
526 res = ntag21x_get_mirror_byte(&gs_handle, &byte);
527 if (res != 0)
528 {
529 ntag21x_interface_debug_print("ntag21x: get mirror byte failed.\n");
530 (void)ntag21x_deinit(&gs_handle);
531
532 return 1;
533 }
534 ntag21x_interface_debug_print("ntag21x: check mirror byte %s.\n", byte == NTAG21X_MIRROR_BYTE_3 ? "ok" : "error");
535
536 /* set mirror byte 2 */
538 if (res != 0)
539 {
540 ntag21x_interface_debug_print("ntag21x: set mirror byte failed.\n");
541 (void)ntag21x_deinit(&gs_handle);
542
543 return 1;
544 }
545 ntag21x_interface_debug_print("ntag21x: set mirror byte 2.\n");
546 res = ntag21x_get_mirror_byte(&gs_handle, &byte);
547 if (res != 0)
548 {
549 ntag21x_interface_debug_print("ntag21x: get mirror byte failed.\n");
550 (void)ntag21x_deinit(&gs_handle);
551
552 return 1;
553 }
554 ntag21x_interface_debug_print("ntag21x: check mirror byte %s.\n", byte == NTAG21X_MIRROR_BYTE_2 ? "ok" : "error");
555
556 /* set mirror byte 1 */
558 if (res != 0)
559 {
560 ntag21x_interface_debug_print("ntag21x: set mirror byte failed.\n");
561 (void)ntag21x_deinit(&gs_handle);
562
563 return 1;
564 }
565 ntag21x_interface_debug_print("ntag21x: set mirror byte 1.\n");
566 res = ntag21x_get_mirror_byte(&gs_handle, &byte);
567 if (res != 0)
568 {
569 ntag21x_interface_debug_print("ntag21x: get mirror byte failed.\n");
570 (void)ntag21x_deinit(&gs_handle);
571
572 return 1;
573 }
574 ntag21x_interface_debug_print("ntag21x: check mirror byte %s.\n", byte == NTAG21X_MIRROR_BYTE_1 ? "ok" : "error");
575
576 /* set mirror byte 0 */
578 if (res != 0)
579 {
580 ntag21x_interface_debug_print("ntag21x: set mirror byte failed.\n");
581 (void)ntag21x_deinit(&gs_handle);
582
583 return 1;
584 }
585 ntag21x_interface_debug_print("ntag21x: set mirror byte 0.\n");
586 res = ntag21x_get_mirror_byte(&gs_handle, &byte);
587 if (res != 0)
588 {
589 ntag21x_interface_debug_print("ntag21x: get mirror byte failed.\n");
590 (void)ntag21x_deinit(&gs_handle);
591
592 return 1;
593 }
594 ntag21x_interface_debug_print("ntag21x: check mirror byte %s.\n", byte == NTAG21X_MIRROR_BYTE_0 ? "ok" : "error");
595
596 /* set normal mode */
598 if (res != 0)
599 {
600 ntag21x_interface_debug_print("ntag21x: set modulation mode failed.\n");
601 (void)ntag21x_deinit(&gs_handle);
602
603 return 1;
604 }
605 ntag21x_interface_debug_print("ntag21x: set normal mode.\n");
606 res = ntag21x_get_modulation_mode(&gs_handle, &mode);
607 if (res != 0)
608 {
609 ntag21x_interface_debug_print("ntag21x: get modulation mode failed.\n");
610 (void)ntag21x_deinit(&gs_handle);
611
612 return 1;
613 }
614 ntag21x_interface_debug_print("ntag21x: check modulation mode %s.\n", mode == NTAG21X_MODULATION_MODE_NORMAL ? "ok" : "error");
615
616 /* set strong mode */
618 if (res != 0)
619 {
620 ntag21x_interface_debug_print("ntag21x: set modulation mode failed.\n");
621 (void)ntag21x_deinit(&gs_handle);
622
623 return 1;
624 }
625 ntag21x_interface_debug_print("ntag21x: set strong mode.\n");
626 res = ntag21x_get_modulation_mode(&gs_handle, &mode);
627 if (res != 0)
628 {
629 ntag21x_interface_debug_print("ntag21x: get modulation mode failed.\n");
630 (void)ntag21x_deinit(&gs_handle);
631
632 return 1;
633 }
634 ntag21x_interface_debug_print("ntag21x: check modulation mode %s.\n", mode == NTAG21X_MODULATION_MODE_STRONG ? "ok" : "error");
635
636 /* set mirror page */
637 res = ntag21x_set_mirror_page(&gs_handle, 0x00);
638 if (res != 0)
639 {
640 ntag21x_interface_debug_print("ntag21x: set mirror page failed.\n");
641 (void)ntag21x_deinit(&gs_handle);
642
643 return 1;
644 }
645 ntag21x_interface_debug_print("ntag21x: set mirror page 0x00.\n");
646 res = ntag21x_get_mirror_page(&gs_handle, &p);
647 if (res != 0)
648 {
649 ntag21x_interface_debug_print("ntag21x: get mirror page failed.\n");
650 (void)ntag21x_deinit(&gs_handle);
651
652 return 1;
653 }
654 ntag21x_interface_debug_print("ntag21x: check mirror page %s.\n", p == 0 ? "ok" : "error");
655
656 /* set protect start page */
657 res = ntag21x_set_protect_start_page(&gs_handle, 0xFF);
658 if (res != 0)
659 {
660 ntag21x_interface_debug_print("ntag21x: set protect start page failed.\n");
661 (void)ntag21x_deinit(&gs_handle);
662
663 return 1;
664 }
665 ntag21x_interface_debug_print("ntag21x: set protect start page 0xFF.\n");
666 res = ntag21x_get_protect_start_page(&gs_handle, &p);
667 if (res != 0)
668 {
669 ntag21x_interface_debug_print("ntag21x: get protect start page failed.\n");
670 (void)ntag21x_deinit(&gs_handle);
671
672 return 1;
673 }
674 ntag21x_interface_debug_print("ntag21x: check protect start page %s.\n", p == 0xFF ? "ok" : "error");
675
676 /* read access protection */
678 if (res != 0)
679 {
680 ntag21x_interface_debug_print("ntag21x: set access failed.\n");
681 (void)ntag21x_deinit(&gs_handle);
682
683 return 1;
684 }
685 ntag21x_interface_debug_print("ntag21x: read access protection disable.\n");
686 res = ntag21x_get_access(&gs_handle, NTAG21X_ACCESS_READ_PROTECTION, &enable);
687 if (res != 0)
688 {
689 ntag21x_interface_debug_print("ntag21x: get access failed.\n");
690 (void)ntag21x_deinit(&gs_handle);
691
692 return 1;
693 }
694 ntag21x_interface_debug_print("ntag21x: check read access protection %s.\n", enable == NTAG21X_BOOL_FALSE ? "ok" : "error");
695
696 /* user configuration protection */
698 if (res != 0)
699 {
700 ntag21x_interface_debug_print("ntag21x: set access failed.\n");
701 (void)ntag21x_deinit(&gs_handle);
702
703 return 1;
704 }
705 ntag21x_interface_debug_print("ntag21x: user configuration protection disable.\n");
707 if (res != 0)
708 {
709 ntag21x_interface_debug_print("ntag21x: get access failed.\n");
710 (void)ntag21x_deinit(&gs_handle);
711
712 return 1;
713 }
714 ntag21x_interface_debug_print("ntag21x: check user configuration protection %s.\n", enable == NTAG21X_BOOL_FALSE ? "ok" : "error");
715
716 /* nfc counter protection */
718 if (res != 0)
719 {
720 ntag21x_interface_debug_print("ntag21x: set access failed.\n");
721 (void)ntag21x_deinit(&gs_handle);
722
723 return 1;
724 }
725 ntag21x_interface_debug_print("ntag21x: nfc counter protection enable.\n");
726 res = ntag21x_get_access(&gs_handle, NTAG21X_ACCESS_NFC_COUNTER, &enable);
727 if (res != 0)
728 {
729 ntag21x_interface_debug_print("ntag21x: get access failed.\n");
730 (void)ntag21x_deinit(&gs_handle);
731
732 return 1;
733 }
734 ntag21x_interface_debug_print("ntag21x: check nfc counter protection %s.\n", enable == NTAG21X_BOOL_TRUE ? "ok" : "error");
735
736 /* nfc counter password protection */
738 if (res != 0)
739 {
740 ntag21x_interface_debug_print("ntag21x: set access failed.\n");
741 (void)ntag21x_deinit(&gs_handle);
742
743 return 1;
744 }
745 ntag21x_interface_debug_print("ntag21x: nfc counter password protection enable.\n");
747 if (res != 0)
748 {
749 ntag21x_interface_debug_print("ntag21x: get access failed.\n");
750 (void)ntag21x_deinit(&gs_handle);
751
752 return 1;
753 }
754 ntag21x_interface_debug_print("ntag21x: check nfc counter password protection %s.\n", enable == NTAG21X_BOOL_FALSE ? "ok" : "error");
755
756 /* set authenticate limitation */
757 res = ntag21x_set_authenticate_limitation(&gs_handle, 7);
758 if (res != 0)
759 {
760 ntag21x_interface_debug_print("ntag21x: set authenticate limitation failed.\n");
761 (void)ntag21x_deinit(&gs_handle);
762
763 return 1;
764 }
765 ntag21x_interface_debug_print("ntag21x: set authenticate limitation 7.\n");
766 res = ntag21x_get_authenticate_limitation(&gs_handle, &limit_check);
767 if (res != 0)
768 {
769 ntag21x_interface_debug_print("ntag21x: get authenticate limitation failed.\n");
770 (void)ntag21x_deinit(&gs_handle);
771
772 return 1;
773 }
774 ntag21x_interface_debug_print("ntag21x: check authenticate limitation %s.\n", limit_check == 7 ? "ok" : "error");
775
776 /* read counter */
777 res = ntag21x_read_counter(&gs_handle, &cnt);
778 if (res != 0)
779 {
780 ntag21x_interface_debug_print("ntag21x: read counter failed.\n");
781 (void)ntag21x_deinit(&gs_handle);
782
783 return 1;
784 }
785 ntag21x_interface_debug_print("ntag21x: read counter %d.\n", cnt);
786
787 /* halt */
788 res = ntag21x_halt(&gs_handle);
789 if (res != 0)
790 {
791 ntag21x_interface_debug_print("ntag21x: halt failed.\n");
792 (void)ntag21x_deinit(&gs_handle);
793
794 return 1;
795 }
796
797 /* finish register */
798 ntag21x_interface_debug_print("ntag21x: finish card test.\n");
799 (void)ntag21x_deinit(&gs_handle);
800
801 return 0;
802}
driver ntag21x card test 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
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_compatibility_write_page(ntag21x_handle_t *handle, uint8_t page, uint8_t data[4])
ntag21x compatibility write page
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_213_5_6
@ NTAG21X_CAPABILITY_CONTAINER_144_BYTE_NTAG213
@ NTAG21X_CAPABILITY_CONTAINER_496_BYTE_NTAG215
@ NTAG21X_CAPABILITY_CONTAINER_872_BYTE_NTAG216
@ NTAG21X_ACCESS_NFC_COUNTER_PASSWORD_PROTECTION
@ NTAG21X_ACCESS_READ_PROTECTION
@ NTAG21X_ACCESS_USER_CONF_PROTECTION
@ NTAG21X_ACCESS_NFC_COUNTER
@ NTAG21X_MODULATION_MODE_STRONG
@ NTAG21X_MODULATION_MODE_NORMAL
@ NTAG21X_MIRROR_BYTE_1
@ NTAG21X_MIRROR_BYTE_0
@ NTAG21X_MIRROR_BYTE_3
@ NTAG21X_MIRROR_BYTE_2
@ NTAG21X_BOOL_TRUE
@ NTAG21X_BOOL_FALSE
@ NTAG21X_MIRROR_NFC_COUNTER_ASCII
@ NTAG21X_MIRROR_UID_ASCII
@ NTAG21X_MIRROR_NO_ASCII
@ NTAG21X_MIRROR_UID_NFC_COUNTER_ASCII
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
uint8_t ntag21x_card_test(void)
card test
uint32_t driver_version
char manufacturer_name[32]
uint8_t minor_product_version
uint8_t major_product_version