Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00024 #include <err.h>
00025 #include <stdlib.h>
00026 #include <string.h>
00027
00028 #include <nfc/nfc.h>
00029 #include <nfc/nfc-messages.h>
00030
00031 #include "nfc-utils.h"
00032
00033 #include "chips/pn53x.h"
00034
00035 #define MAX_DEVICE_COUNT 16
00036
00037
00038 int
00039 main (int argc, const char *argv[])
00040 {
00041 size_t szFound;
00042 size_t i;
00043 nfc_device_t *pnd;
00044 nfc_device_desc_t *pnddDevices;
00045 const char *acLibnfcVersion;
00046 bool result;
00047
00048 byte_t abtRx[MAX_FRAME_LEN];
00049 size_t szRxLen;
00050 const byte_t pncmd_diagnose_communication_line_test[] = { 0xD4, 0x00, 0x00, 0x06, 'l', 'i', 'b', 'n', 'f', 'c' };
00051 const byte_t pncmd_diagnose_rom_test[] = { 0xD4, 0x00, 0x01 };
00052 const byte_t pncmd_diagnose_ram_test[] = { 0xD4, 0x00, 0x02 };
00053
00054 if (argc > 1) {
00055 errx (1, "usage: %s", argv[0]);
00056 }
00057
00058 acLibnfcVersion = nfc_version ();
00059 printf ("%s use libnfc %s\n", argv[0], acLibnfcVersion);
00060
00061 if (!(pnddDevices = malloc (MAX_DEVICE_COUNT * sizeof (*pnddDevices)))) {
00062 fprintf (stderr, "malloc() failed\n");
00063 return EXIT_FAILURE;
00064 }
00065
00066 nfc_list_devices (pnddDevices, MAX_DEVICE_COUNT, &szFound);
00067
00068 if (szFound == 0) {
00069 INFO ("%s", "No device found.");
00070 }
00071
00072 for (i = 0; i < szFound; i++) {
00073 pnd = nfc_connect (&(pnddDevices[i]));
00074
00075 if (pnd == NULL) {
00076 ERR ("%s", "Unable to connect to NFC device.");
00077 return EXIT_FAILURE;
00078 }
00079
00080 printf ("NFC device [%s] connected.\n", pnd->acName);
00081
00082
00083 result =
00084 pn53x_transceive (pnd, pncmd_diagnose_communication_line_test, sizeof (pncmd_diagnose_communication_line_test),
00085 abtRx, &szRxLen);
00086 if (result) {
00087 result =
00088 (memcmp (pncmd_diagnose_communication_line_test + 2, abtRx, sizeof (pncmd_diagnose_communication_line_test) - 2)
00089 == 0);
00090 }
00091 printf (" Communication line test: %s\n", result ? "OK" : "Failed");
00092
00093
00094 result = pn53x_transceive (pnd, pncmd_diagnose_rom_test, sizeof (pncmd_diagnose_rom_test), abtRx, &szRxLen);
00095 if (result) {
00096 result = ((szRxLen == 1) && (abtRx[0] == 0x00));
00097 }
00098 printf (" ROM test: %s\n", result ? "OK" : "Failed");
00099
00100
00101 result = pn53x_transceive (pnd, pncmd_diagnose_ram_test, sizeof (pncmd_diagnose_ram_test), abtRx, &szRxLen);
00102 if (result) {
00103 result = ((szRxLen == 1) && (abtRx[0] == 0x00));
00104 }
00105 printf (" RAM test: %s\n", result ? "OK" : "Failed");
00106 }
00107 }