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