- add accessor functions for protocol and layer2 names
- print l2 and proto name + uid after successful scan
git-svn-id: https://svn.gnumonks.org/trunk/librfid@1899
e0336214-984f-0b4b-a45f-
81c69e1f0ede
void *optval, unsigned int *optlen);
int rfid_layer2_setopt(struct rfid_layer2_handle *ph, int optname,
const void *optval, unsigned int optlen);
-
+char *rfid_layer2_name(struct rfid_layer2_handle *l2h);
#ifdef __LIBRFID__
#include <librfid/rfid_layer2_iso14443a.h>
int rfid_protocol_fini(struct rfid_protocol_handle *ph);
int rfid_protocol_close(struct rfid_protocol_handle *ph);
+char *rfid_protocol_name(struct rfid_protocol_handle *ph);
+
enum rfid_protocol_id {
RFID_PROTOCOL_UNKNOWN,
RFID_PROTOCOL_TCL,
}
return 0;
}
+
+char *rfid_layer2_name(struct rfid_layer2_handle *l2h)
+{
+ return l2h->l2->name;
+}
return 0;
}
+
+char *rfid_protocol_name(struct rfid_protocol_handle *ph)
+{
+ return ph->proto->name;
+}
#define RFID_LAYER2_MAX 16
for (i = 0; i < RFID_LAYER2_MAX; i++) {
+ DEBUGP("testing l2 %u\n", i);
l2h = rfid_layer2_scan1(rh, i);
if (l2h)
return l2h;
#define RFID_PROTOCOL_MAX 16
for (i = 0; i < RFID_PROTOCOL_MAX; i++) {
+ DEBUGP("testing proto %u\n", i);
ph = rfid_protocol_scan1(l2h, i);
if (ph)
return ph;
if (!*l2h)
return 0;
- *ph = rfid_protocol_scan(l2h);
+ *ph = rfid_protocol_scan(*l2h);
if (!*ph)
return 2;
-
+
return 3;
}
return -1;
}
+static void do_scan(void)
+{
+ int rc;
+ printf("scanning for RFID token...\n");
+ rc = rfid_scan(rh, &l2h, &ph);
+ if (rc >= 2) {
+ unsigned char uid_buf[16];
+ unsigned int uid_len = sizeof(uid_buf);
+ rfid_layer2_getopt(l2h, RFID_OPT_LAYER2_UID, &uid_buf,
+ &uid_len);
+ printf("Layer 2 success (%s): %s\n", rfid_layer2_name(l2h),
+ hexdump(uid_buf, uid_len));
+ }
+ if (rc >= 3) {
+ printf("Protocol success (%s)\n", rfid_protocol_name(ph));
+ }
+}
+
static void help(void)
{
printf( " -s --scan\n"
case 's':
if (reader() < 0)
exit(1);
- printf("scanning for RFID token...\n");
- i = rfid_scan(rh, &l2h, &ph);
+ do_scan();
exit(0);
break;
case 'p':