- fix segfault during rfid_scan()
- 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
This commit is contained in:
parent
1db4b3b435
commit
6e87a00752
|
@ -34,7 +34,7 @@ int rfid_layer2_getopt(struct rfid_layer2_handle *ph, int optname,
|
|||
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>
|
||||
|
|
|
@ -27,6 +27,8 @@ rfid_protocol_write(struct rfid_protocol_handle *ph,
|
|||
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,
|
||||
|
|
|
@ -132,3 +132,8 @@ rfid_layer2_setopt(struct rfid_layer2_handle *ph, int optname,
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *rfid_layer2_name(struct rfid_layer2_handle *l2h)
|
||||
{
|
||||
return l2h->l2->name;
|
||||
}
|
||||
|
|
|
@ -111,3 +111,8 @@ rfid_protocol_register(struct rfid_protocol *p)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *rfid_protocol_name(struct rfid_protocol_handle *ph)
|
||||
{
|
||||
return ph->proto->name;
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ rfid_layer2_scan(struct rfid_reader_handle *rh)
|
|||
|
||||
#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;
|
||||
|
@ -87,6 +88,7 @@ rfid_protocol_scan(struct rfid_layer2_handle *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;
|
||||
|
@ -105,9 +107,9 @@ int rfid_scan(struct rfid_reader_handle *rh,
|
|||
if (!*l2h)
|
||||
return 0;
|
||||
|
||||
*ph = rfid_protocol_scan(l2h);
|
||||
*ph = rfid_protocol_scan(*l2h);
|
||||
if (!*ph)
|
||||
return 2;
|
||||
|
||||
|
||||
return 3;
|
||||
}
|
||||
|
|
|
@ -330,6 +330,24 @@ static int l2_by_name(const char *name)
|
|||
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"
|
||||
|
@ -368,8 +386,7 @@ int main(int argc, char **argv)
|
|||
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':
|
||||
|
|
Loading…
Reference in New Issue