X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=src%2Frfid_reader_openpcd.c;h=b885d9f8864b02786b413779c9f7a366d2a3e39f;hb=237c7f9e9d0aad3a9830498a9bdb5fe5dd94df9e;hp=9f5517c56446a91a6f4290d8089898af1fe26c52;hpb=fee486a7c477f4360e99ff32f01ef6a8707e4cee;p=librfid diff --git a/src/rfid_reader_openpcd.c b/src/rfid_reader_openpcd.c index 9f5517c..b885d9f 100644 --- a/src/rfid_reader_openpcd.c +++ b/src/rfid_reader_openpcd.c @@ -25,14 +25,11 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -//#define DEBUG - #include #include #include #include - #include #include #include @@ -53,10 +50,14 @@ static char rcv_buf[RECVBUF_LEN]; static struct openpcd_hdr *snd_hdr; static struct openpcd_hdr *rcv_hdr; - #ifndef LIBRFID_FIRMWARE +#ifdef __MINGW32__ +#include "libusb_dyn.h" +#else /*__MINGW32__*/ #include +#endif/*__MINGW32__*/ + static struct usb_device *dev; static struct usb_dev_handle *hdl; @@ -75,7 +76,7 @@ static int openpcd_send_command(u_int8_t cmd, u_int8_t reg, u_int8_t val, cur = sizeof(*snd_hdr) + len; - return usb_bulk_write(hdl, OPENPCD_OUT_EP, (char *)snd_hdr, cur, 0); + return usb_bulk_write(hdl, OPENPCD_OUT_EP, (char *)snd_hdr, cur, 1000); } static int openpcd_recv_reply(void) @@ -95,7 +96,7 @@ static int openpcd_xcv(u_int8_t cmd, u_int8_t reg, u_int8_t val, ret = openpcd_send_command(cmd, reg, val, len, data); if (ret < 0) return ret; - if (ret < sizeof(sizeof(struct openpcd_hdr))) + if (ret < sizeof(struct openpcd_hdr)) return -EINVAL; return openpcd_recv_reply(); @@ -115,7 +116,7 @@ static struct usb_device *find_opcd_device(void) { struct usb_bus *bus; - for (bus = usb_busses; bus; bus = bus->next) { + for (bus = usb_get_busses(); bus; bus = bus->next) { struct usb_device *dev; for (dev = bus->devices; dev; dev = dev->next) { int i; @@ -220,6 +221,83 @@ const struct rfid_asic_transport openpcd_rat = { }, }; +static int openpcd_get_api_version(struct rfid_reader_handle *rh, u_int8_t *version) +{ + int ret; + + // preset version result to zero + rcv_hdr->val=0; + + ret = openpcd_xcv(OPENPCD_CMD_GET_API_VERSION, 0, 0, 0, NULL); + if (ret < 0) { + DEBUGPC("ERROR sending command [%i]\n", ret); + return ret; + } + + if (ret < sizeof(struct openpcd_hdr)) { + DEBUGPC("ERROR: short packet [%i]\n", ret); + return -EINVAL; + } + + *version = rcv_hdr->val; + + return ret; +} + +static int openpcd_get_environment( + struct rfid_reader_handle *rh, + unsigned char num_bytes, + unsigned char *buf) +{ + int ret; + + DEBUGP(" "); + + ret = openpcd_xcv(OPENPCD_CMD_GET_ENVIRONMENT, 0x00, num_bytes, 0, NULL); + if (ret < 0) { + DEBUGPC("ERROR sending command [%i]\n",ret); + return ret; + } + DEBUGPC("ret = %d\n", ret); + + memcpy(buf, rcv_hdr->data, ret - sizeof(struct openpcd_hdr)); + DEBUGPC("len=%d val=%s: OK\n", ret - sizeof(struct openpcd_hdr), + rfid_hexdump(rcv_hdr->data, ret - sizeof(struct openpcd_hdr))); + + return ret; +} + +static int openpcd_set_environment( + struct rfid_reader_handle *rh, + const unsigned char num_bytes, + unsigned char *buf) +{ + int ret; + + ret = openpcd_xcv(OPENPCD_CMD_SET_ENVIRONMENT, 0, 0, num_bytes, buf); + if (ret < 0) { + DEBUGPC("ERROR sending command [%i]\n",ret); + return ret; + } + + if (ret < sizeof(struct openpcd_hdr)) { + DEBUGPC("ERROR: short packet [%i]\n", ret); + return -EINVAL; + } + + return rcv_hdr->val; +} + +static int openpcd_reset(struct rfid_reader_handle *rh) +{ + int ret; + + DEBUGP("reset "); + ret = openpcd_xcv(OPENPCD_CMD_RESET, 0, 0, 0, 0); + + return ret; +} + #else /* RC632 access primitives for librfid inside reader firmware */ @@ -320,7 +398,7 @@ openpcd_14443a_set_speed(struct rfid_reader_handle *rh, break; case RFID_14443A_SPEED_424K: rate = 0x02; - DEBUGPC("424K\n"); + DEBUGPC("424K\n"); break; case RFID_14443A_SPEED_848K: rate = 0x03; @@ -388,6 +466,13 @@ openpcd_open(void *data) return NULL; } + if(usb_set_configuration(hdl, 1 ) < 0) + { + DEBUGP("setting config failed\n"); + usb_close( hdl ); + return NULL; + } + if (usb_claim_interface(hdl, 0) < 0) { DEBUGP("Can't claim interface\n"); usb_close(hdl); @@ -442,6 +527,14 @@ const struct rfid_reader rfid_reader_openpcd = { .id = RFID_READER_OPENPCD, .open = &openpcd_open, .close = &openpcd_close, + +#ifndef LIBRFID_FIRMWARE + .get_api_version = &openpcd_get_api_version, + .get_environment = &openpcd_get_environment, + .set_environment = &openpcd_set_environment, + .reset = &openpcd_reset, +#endif + .transceive = &openpcd_transceive, .l2_supported = (1 << RFID_LAYER2_ISO14443A) | (1 << RFID_LAYER2_ISO14443B) |