X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=src%2Frfid_reader_cm5121.c;h=a62cc4cc87823dd3aa81c897ccfb05a20058a480;hb=9ce76f09417c31a8fc904b67624c0f3b397c21c0;hp=978e18fa34d59cc8a22b2ec9a334d46936ccafac;hpb=05c7e304271bcf88901da3782fcd3f28a0c7c9cf;p=librfid diff --git a/src/rfid_reader_cm5121.c b/src/rfid_reader_cm5121.c index 978e18f..a62cc4c 100644 --- a/src/rfid_reader_cm5121.c +++ b/src/rfid_reader_cm5121.c @@ -1,8 +1,8 @@ /* Omnikey CardMan 5121 specific RC632 transport layer * - * (C) 2005 by Harald Welte + * (C) 2005-2006 by Harald Welte * - * The 5121 is an Atmel AT98C5122 based USB CCID reader (probably the same + * The 5121 is an Atmel AT89C5122 based USB CCID reader (probably the same * design like the 3121). It's CL RC632 is connected via address/data bus, * not via SPI. * @@ -26,27 +26,39 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - #include #include #include +#include -#include -#include -#include -#include -#include - -//#define SENDBUF_LEN 40 -#define SENDBUF_LEN 100 -#define RECVBUF_LEN 40 - -#if 1 -#ifdef DEBUGP -#undef DEBUGP -#define DEBUGP(x, ...) -#define DEBUGPC(x, ...) -#endif +#include + +#ifndef LIBRFID_FIRMWARE + +#include +#include +#include +#include +#include +#include + +#include "cm5121_source.h" + +/* FIXME */ +#include "rc632.h" + +#define SENDBUF_LEN 256+7+10 /* 256bytes max FSD/FSC, plus 7 bytes header, + plus 10 bytes reserve */ +#define RECVBUF_LEN SENDBUF_LEN + +//#define DEBUG_REGISTER + +#ifdef DEBUG_REGISTER +#define DEBUGRC DEBUGPC +#define DEBUGR DEBUGP +#else +#define DEBUGRC(x, args ...) do {} while(0) +#define DEBUGR(x, args ...) do {} while(0) #endif static @@ -66,15 +78,15 @@ int Write1ByteToReg(struct rfid_asic_transport_handle *rath, sndbuf[6] = reg; sndbuf[7] = value; - DEBUGP("reg=0x%02x, val=%02x: ", reg, value); + DEBUGR("reg=0x%02x, val=%02x: ", reg, value); if (PC_to_RDR_Escape(rath->data, sndbuf, 8, rcvbuf, &retlen) == 0) { - DEBUGPC("OK\n"); + DEBUGRC("OK\n"); return 0; } - DEBUGPC("ERROR\n"); + DEBUGRC("ERROR\n"); return -1; } @@ -97,12 +109,12 @@ static int Read1ByteFromReg(struct rfid_asic_transport_handle *rath, if (PC_to_RDR_Escape(rath->data, sndbuf, 7, recvbuf, &retlen) == 0) { *value = recvbuf[1]; - DEBUGP("reg=0x%02x, val=%02x: ", reg, *value); - DEBUGPC("OK\n"); + DEBUGR("reg=0x%02x, val=%02x: ", reg, *value); + DEBUGRC("OK\n"); return 0; } - DEBUGPC("ERROR\n"); + DEBUGRC("ERROR\n"); return -1; } @@ -122,15 +134,15 @@ static int ReadNBytesFromFIFO(struct rfid_asic_transport_handle *rath, sndbuf[5] = 0x00; sndbuf[6] = 0x02; - DEBUGP("num_bytes=%u: ", num_bytes); + DEBUGR("num_bytes=%u: ", num_bytes); if (PC_to_RDR_Escape(rath->data, sndbuf, 7, recvbuf, &retlen) == 0) { - DEBUGPC("%u [%s]\n", retlen, + DEBUGRC("%u [%s]\n", retlen, rfid_hexdump(recvbuf+1, num_bytes)); memcpy(buf, recvbuf+1, num_bytes); // len == 0x7f return 0; } - DEBUGPC("ERROR\n"); + DEBUGRC("ERROR\n"); return -1; } @@ -151,16 +163,16 @@ static int WriteNBytesToFIFO(struct rfid_asic_transport_handle *rath, sndbuf[5] = flags; sndbuf[6] = 0x02; - DEBUGP("%u [%s]: ", len, rfid_hexdump(bytes, len)); + DEBUGR("%u [%s]: ", len, rfid_hexdump(bytes, len)); memcpy(sndbuf+7, bytes, len); if (PC_to_RDR_Escape(rath->data, sndbuf, len+7, recvbuf, &retlen) == 0) { - DEBUGPC("OK (%u [%s])\n", retlen, rfid_hexdump(recvbuf, retlen)); + DEBUGRC("OK (%u [%s])\n", retlen, rfid_hexdump(recvbuf, retlen)); return 0; } - DEBUGPC("ERROR\n"); + DEBUGRC("ERROR\n"); return -1; } @@ -180,31 +192,31 @@ static int TestFIFO(struct rc632_handle *handle) } #endif -static int cm5121_transcieve(struct rfid_reader_handle *rh, +static int cm5121_transceive(struct rfid_reader_handle *rh, enum rfid_frametype frametype, const unsigned char *tx_data, unsigned int tx_len, unsigned char *rx_data, unsigned int *rx_len, u_int64_t timeout, unsigned int flags) { - return rh->ah->asic->priv.rc632.fn.transcieve(rh->ah, frametype, + return rh->ah->asic->priv.rc632.fn.transceive(rh->ah, frametype, tx_data, tx_len, rx_data, rx_len, timeout, flags); } -static int cm5121_transcieve_sf(struct rfid_reader_handle *rh, +static int cm5121_transceive_sf(struct rfid_reader_handle *rh, unsigned char cmd, struct iso14443a_atqa *atqa) { - return rh->ah->asic->priv.rc632.fn.iso14443a.transcieve_sf(rh->ah, + return rh->ah->asic->priv.rc632.fn.iso14443a.transceive_sf(rh->ah, cmd, atqa); } static int -cm5121_transcieve_acf(struct rfid_reader_handle *rh, +cm5121_transceive_acf(struct rfid_reader_handle *rh, struct iso14443a_anticol_cmd *cmd, unsigned int *bit_of_col) { - return rh->ah->asic->priv.rc632.fn.iso14443a.transcieve_acf(rh->ah, + return rh->ah->asic->priv.rc632.fn.iso14443a.transceive_acf(rh->ah, cmd, bit_of_col); } @@ -214,6 +226,40 @@ cm5121_14443a_init(struct rfid_reader_handle *rh) return rh->ah->asic->priv.rc632.fn.iso14443a.init(rh->ah); } +static int +cm5121_14443a_set_speed(struct rfid_reader_handle *rh, + unsigned int tx, + unsigned int speed) +{ + u_int8_t rate; + + DEBUGP("setting rate: "); + switch (speed) { + case RFID_14443A_SPEED_106K: + rate = 0x00; + DEBUGPC("106K\n"); + break; + case RFID_14443A_SPEED_212K: + rate = 0x01; + DEBUGPC("212K\n"); + break; + case RFID_14443A_SPEED_424K: + rate = 0x02; + DEBUGPC("424K\n"); + break; + case RFID_14443A_SPEED_848K: + rate = 0x03; + DEBUGPC("848K\n"); + break; + default: + DEBUGPC("invalid\n"); + return -EINVAL; + break; + } + return rh->ah->asic->priv.rc632.fn.iso14443a.set_speed(rh->ah, + tx, rate); +} + static int cm5121_14443b_init(struct rfid_reader_handle *rh) { @@ -270,12 +316,12 @@ cm5121_open(void *data) struct rfid_reader_handle *rh; struct rfid_asic_transport_handle *rath; - rh = malloc(sizeof(*rh)); + rh = malloc_reader_handle(sizeof(*rh)); if (!rh) return NULL; memset(rh, 0, sizeof(*rh)); - rath = malloc(sizeof(*rath)); + rath = malloc_rat_handle(sizeof(*rath)); if (!rath) goto out_rh; memset(rath, 0, sizeof(*rath)); @@ -297,9 +343,9 @@ cm5121_open(void *data) return rh; out_rath: - free(rath); + free_rat_handle(rath); out_rh: - free(rh); + free_reader_handle(rh); return NULL; } @@ -309,29 +355,39 @@ cm5121_close(struct rfid_reader_handle *rh) { struct rfid_asic_transport_handle *rath = rh->ah->rath; rc632_close(rh->ah); - free(rath); - free(rh); + free_rat_handle(rath); + free_reader_handle(rh); } -struct rfid_reader rfid_reader_cm5121 = { +const struct rfid_reader rfid_reader_cm5121 = { .name = "Omnikey CardMan 5121 RFID", .open = &cm5121_open, .close = &cm5121_close, - .transcieve = &cm5121_transcieve, + .transceive = &cm5121_transceive, + .l2_supported = (1 << RFID_LAYER2_ISO14443A) | + (1 << RFID_LAYER2_ISO14443B) | + (1 << RFID_LAYER2_ISO15693), + .proto_supported = (1 << RFID_PROTOCOL_TCL) | + (1 << RFID_PROTOCOL_MIFARE_UL) | + (1 << RFID_PROTOCOL_MIFARE_CLASSIC), .iso14443a = { .init = &cm5121_14443a_init, - .transcieve_sf = &cm5121_transcieve_sf, - .transcieve_acf = &cm5121_transcieve_acf, - .speed = RFID_READER_SPEED_106K | RFID_READER_SPEED_212K | - RFID_READER_SPEED_424K | RFID_READER_SPEED_848K, + .transceive_sf = &cm5121_transceive_sf, + .transceive_acf = &cm5121_transceive_acf, + .speed = RFID_14443A_SPEED_106K | RFID_14443A_SPEED_212K | + RFID_14443A_SPEED_424K, //| RFID_14443A_SPEED_848K, + .set_speed = &cm5121_14443a_set_speed, }, .iso14443b = { .init = &cm5121_14443b_init, }, + .iso15693 = { + .init = &cm5121_15693_init, + }, .mifare_classic = { .setkey = &cm5121_mifare_setkey, .auth = &cm5121_mifare_auth, }, }; - +#endif /* LIBRFID_FIRMWARE */