From 98b2f4efdb5ac839baa0db88a75c0bf7fcd988d2 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Mon, 4 May 2009 04:20:41 +0000 Subject: [PATCH] cleaned up mifare-read --- mifare-read.c | 143 ++++++++++++--------------------------------------------- 1 file changed, 29 insertions(+), 114 deletions(-) diff --git a/mifare-read.c b/mifare-read.c index 7761697..05851c9 100644 --- a/mifare-read.c +++ b/mifare-read.c @@ -20,34 +20,22 @@ #include #include #include -#include #include #include #include #include #include -#include - -#include -#include - -//#include struct rfid_reader_handle *rh = NULL; struct rfid_layer2_handle *l2h = NULL; -struct rfid_protocol_handle *ph = NULL; - void sigHandler(int sig) { printf("sig handler called\n"); -/* rfid_protocol_close(ph); */ -/* rfid_protocol_fini(ph); */ - - rfid_layer2_close(l2h); - rfid_layer2_fini(l2h); +/* rfid_layer2_close(l2h); */ +/* rfid_layer2_fini(l2h); */ rfid_reader_close(rh); exit(0); @@ -55,123 +43,50 @@ void sigHandler(int sig) int l2_init(int layer2) { - int rc; - - l2h = rfid_layer2_init(rh, layer2); - if (!l2h) { - fprintf(stderr, "error during layer2(%d)_init (0=14a,1=14b,3=15)\n",layer2); - return -1; - } - - rc = rfid_layer2_open(l2h); - if (rc < 0) { - fprintf(stderr, "error during layer2_open\n"); - return rc; - } - - return 0; -} + int rc; -int l3_init(int protocol) -{ - ph = rfid_protocol_init(l2h, protocol); - if (!ph) { - fprintf(stderr, "error during protocol_init\n"); - return -1; - } - if (rfid_protocol_open(ph) < 0) { - fprintf(stderr, "error during protocol_open\n"); - return -1; - } - - return 0; -} - -static int mifare_cl_auth(unsigned char *key, int page) -{ - int rc; - - rc = mfcl_set_key(ph, key); - if (rc < 0) { - fprintf(stderr, "key format error\n"); - return rc; - } - rc = mfcl_auth(ph, RFID_CMD_MIFARE_AUTH1A, page); - if (rc < 0) { - fprintf(stderr, "mifare auth error\n"); - return rc; - } else -// printf("mifare auth succeeded!\n"); - - return 0; -} - -static void mifare_l3(void) -{ - while (l2_init(RFID_LAYER2_ISO14443A) < 0) ; + l2h = rfid_layer2_init(rh, layer2); + if (!l2h) { + fprintf(stderr, "error during layer2(%d)_init (0=14a,1=14b,3=15)\n",layer2); + return -1; + } -// printf("ISO14443-3A anticollision succeeded\n"); - -// while (l3_init(RFID_PROTOCOL_MIFARE_CLASSIC) < 0) ; + rc = rfid_layer2_open(l2h); + if (rc < 0) { + fprintf(stderr, "error during layer2_open\n"); + return rc; + } -// printf("Mifare card available\n"); + return 0; } -void print_hex(const unsigned char* buffer, int length) +int main(int argc, char **argv) { - int i; + unsigned int uid, uid_len; - if(length <= 0) return; - for(i=0; i=0) + uid_len = sizeof(uid); + uid = 0; + if(rfid_layer2_getopt(l2h, RFID_OPT_LAYER2_UID, &uid, &uid_len) >= 0) printf("UID=%08X\n",uid); fflush(stdout); -// rfid_layer2_close(l2h); -// rfid_layer2_fini(l2h); +/* rfid_layer2_close(l2h); */ +/* rfid_layer2_fini(l2h); */ - rfid_reader_close(rh); - exit(0); + rfid_reader_close(rh); + exit(0); } -- 1.7.10.4