update to new (four-byte, explicit response_request flag) revision of openpcd usb protocol
git-svn-id: https://svn.gnumonks.org/trunk/librfid@1884 e0336214-984f-0b4b-a45f-81c69e1f0ede
This commit is contained in:
parent
19bdabf243
commit
341afde582
|
@ -6,30 +6,85 @@
|
|||
#include <sys/types.h>
|
||||
|
||||
struct openpcd_hdr {
|
||||
u_int8_t cmd; /* command */
|
||||
u_int8_t cmd; /* command. high nibble: class,
|
||||
* low nibble: cmd */
|
||||
u_int8_t flags;
|
||||
u_int8_t reg; /* register */
|
||||
u_int8_t val; /* value (in case of write *) */
|
||||
u_int16_t len;
|
||||
u_int16_t res;
|
||||
u_int8_t data[0];
|
||||
} __attribute__((packed));
|
||||
} __attribute__ ((packed));
|
||||
|
||||
#define OPENPCD_REG_MAX 0x3f
|
||||
#define OPCD_REV_LEN 16
|
||||
struct openpcd_compile_version {
|
||||
char svnrev[OPCD_REV_LEN];
|
||||
char by[OPCD_REV_LEN];
|
||||
char date[OPCD_REV_LEN];
|
||||
} __attribute__ ((packed));
|
||||
|
||||
#define OPENPCD_CMD_WRITE_REG 0x01
|
||||
#define OPENPCD_CMD_WRITE_FIFO 0x02
|
||||
#define OPENPCD_CMD_WRITE_VFIFO 0x03
|
||||
#define OPENPCD_CMD_REG_BITS_CLEAR 0x04
|
||||
#define OPENPCD_CMD_REG_BITS_SET 0x05
|
||||
#define OPENPCD_FLAG_RESPOND 0x01 /* Response requested */
|
||||
#define OPENPCD_FLAG_ERROR 0x80 /* An error occurred */
|
||||
|
||||
#define OPENPCD_CMD_READ_REG 0x11
|
||||
#define OPENPCD_CMD_READ_FIFO 0x12
|
||||
#define OPENPCD_CMD_READ_VFIFO 0x13
|
||||
enum openpcd_cmd_class {
|
||||
OPENPCD_CMD_CLS_GENERIC = 0x0,
|
||||
/* PCD (reader) side */
|
||||
OPENPCD_CMD_CLS_RC632 = 0x1,
|
||||
//OPENPCD_CMD_CLS_LED = 0x2,
|
||||
OPENPCD_CMD_CLS_SSC = 0x3,
|
||||
OPENPCD_CMD_CLS_PWM = 0x4,
|
||||
OPENPCD_CMD_CLS_ADC = 0x5,
|
||||
/* PICC (transponder) side */
|
||||
OPENPCD_CMD_CLS_PICC = 0xe,
|
||||
|
||||
#define OPENPCD_CMD_SET_LED 0x21
|
||||
OPENPCD_CMD_CLS_USBTEST = 0xf,
|
||||
};
|
||||
|
||||
#define OPENPCD_REG_MAX 0x3f
|
||||
|
||||
#define OPENPCD_CMD_CLS(x) (x >> 4)
|
||||
#define OPENPCD_CMD(x) (x & 0xf)
|
||||
|
||||
#define OPENPCD_CLS2CMD(x) (x << 4)
|
||||
|
||||
#define OPENPCD_CMD_GET_VERSION (0x1|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_GENERIC))
|
||||
#define OPENPCD_CMD_SET_LED (0x2|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_GENERIC))
|
||||
|
||||
/* CMD_CLS_RC632 */
|
||||
#define OPENPCD_CMD_WRITE_REG (0x1|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_RC632))
|
||||
#define OPENPCD_CMD_WRITE_FIFO (0x2|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_RC632))
|
||||
#define OPENPCD_CMD_WRITE_VFIFO (0x3|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_RC632))
|
||||
#define OPENPCD_CMD_REG_BITS_CLEAR (0x4|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_RC632))
|
||||
#define OPENPCD_CMD_REG_BITS_SET (0x5|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_RC632))
|
||||
#define OPENPCD_CMD_READ_REG (0x6|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_RC632))
|
||||
#define OPENPCD_CMD_READ_FIFO (0x7|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_RC632))
|
||||
#define OPENPCD_CMD_READ_VFIFO (0x8|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_RC632))
|
||||
#define OPENPCD_CMD_DUMP_REGS (0x9|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_RC632))
|
||||
#define OPENPCD_CMD_IRQ (0xa|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_RC632))
|
||||
|
||||
/* CMD_CLS_SSC */
|
||||
#define OPENPCD_CMD_SSC_READ (0x1|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_SSC))
|
||||
#define OPENPCD_CMD_SSC_WRITE (0x2|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_SSC))
|
||||
|
||||
/* CMD_CLS_PWM */
|
||||
#define OPENPCD_CMD_PWM_ENABLE (0x1|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_PWM))
|
||||
#define OPENPCD_CMD_PWM_DUTY_SET (0x2|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_PWM))
|
||||
#define OPENPCD_CMD_PWM_DUTY_GET (0x3|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_PWM))
|
||||
#define OPENPCD_CMD_PWM_FREQ_SET (0x4|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_PWM))
|
||||
#define OPENPCD_CMD_PWM_FREQ_GET (0x5|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_PWM))
|
||||
|
||||
/* CMD_CLS_PICC */
|
||||
#define OPENPCD_CMD_PICC_REG_WRITE (0x1|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_PICC))
|
||||
#define OPENPCD_CMD_PICC_REG_READ (0x2|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_PICC))
|
||||
|
||||
/* CMD_CLS_ADC */
|
||||
#define OPENPCD_CMD_ADC_READ (0x1|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_ADC))
|
||||
|
||||
/* CMD_CLS_USBTEST */
|
||||
#define OPENPCD_CMD_USBTEST_IN (0x1|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_USBTEST))
|
||||
#define OPENPCD_CMD_USBTEST_OUT (0x2|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_USBTEST))
|
||||
|
||||
/* FIXME */
|
||||
#define OPENPCD_CMD_PIO_IRQ (0x3|OPENPCD_CLS2CMD(OPENPCD_CMD_CLS_USBTEST))
|
||||
|
||||
#define OPENPCD_CMD_IRQ 0x40 /* IRQ reported by RC632 */
|
||||
|
||||
#define OPENPCD_VENDOR_ID 0x2342
|
||||
#define OPENPCD_PRODUCT_ID 0x0001
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* OpenPC specific RC632 transport layer
|
||||
/* OpenPCD specific RC632 transport layer
|
||||
*
|
||||
* (C) 2006 by Harald Welte <laforge@gnumonks.org>
|
||||
*
|
||||
|
@ -24,6 +24,8 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
//#define DEBUG
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
@ -41,7 +43,7 @@
|
|||
#include "rc632.h"
|
||||
|
||||
|
||||
#define SENDBUF_LEN (256+7+10) /* 256bytes max FSD/FSC, plus 7 bytes header,
|
||||
#define SENDBUF_LEN (256+4+10) /* 256bytes max FSD/FSC, plus 4 bytes header,
|
||||
plus 10 bytes reserve */
|
||||
#define RECVBUF_LEN SENDBUF_LEN
|
||||
|
||||
|
@ -63,7 +65,7 @@ static int openpcd_send_command(u_int8_t cmd, u_int8_t reg, u_int8_t val,
|
|||
snd_hdr->cmd = cmd;
|
||||
snd_hdr->reg = reg;
|
||||
snd_hdr->val = val;
|
||||
snd_hdr->len = len;
|
||||
snd_hdr->flags = OPENPCD_FLAG_RESPOND;
|
||||
if (data && len)
|
||||
memcpy(snd_hdr->data, data, len);
|
||||
|
||||
|
@ -80,6 +82,20 @@ static int openpcd_recv_reply(void)
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int openpcd_xcv(u_int8_t cmd, u_int8_t reg, u_int8_t val,
|
||||
u_int16_t len, const unsigned char *data)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = openpcd_send_command(cmd, reg, val, len, data);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
if (ret < sizeof(sizeof(struct openpcd_hdr)))
|
||||
return -EINVAL;
|
||||
|
||||
return openpcd_recv_reply();
|
||||
}
|
||||
|
||||
static struct usb_device *find_opcd_device(void)
|
||||
{
|
||||
|
@ -93,7 +109,6 @@ static struct usb_device *find_opcd_device(void)
|
|||
&& dev->descriptor.iManufacturer == 0
|
||||
&& dev->descriptor.iProduct == 0
|
||||
&& dev->descriptor.bNumConfigurations == 1
|
||||
&& dev->config->bNumInterfaces == 1
|
||||
&& dev->config->iConfiguration == 0)
|
||||
return dev;
|
||||
}
|
||||
|
@ -108,7 +123,7 @@ static int openpcd_reg_write(struct rfid_asic_transport_handle *rath,
|
|||
|
||||
DEBUGP("reg=0x%02x, val=%02x: ", reg, value);
|
||||
|
||||
ret = openpcd_send_command(OPENPCD_CMD_WRITE_REG, reg, value, 0, NULL);
|
||||
ret = openpcd_xcv(OPENPCD_CMD_WRITE_REG, reg, value, 0, NULL);
|
||||
if (ret < 0)
|
||||
DEBUGPC("ERROR sending command\n");
|
||||
else
|
||||
|
@ -125,15 +140,14 @@ static int openpcd_reg_read(struct rfid_asic_transport_handle *rath,
|
|||
|
||||
DEBUGP("reg=0x%02x, ", reg);
|
||||
|
||||
ret = openpcd_send_command(OPENPCD_CMD_READ_REG, reg, 0, 0, NULL);
|
||||
ret = openpcd_xcv(OPENPCD_CMD_READ_REG, reg, 0, 0, NULL);
|
||||
if (ret < 0) {
|
||||
DEBUGPC("ERROR sending command\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = openpcd_recv_reply();
|
||||
if (ret < 0) {
|
||||
DEBUGPC("ERROR receiving reply\n");
|
||||
if (ret < sizeof(struct openpcd_hdr)) {
|
||||
DEBUGPC("ERROR: short packet\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -151,21 +165,16 @@ static int openpcd_fifo_read(struct rfid_asic_transport_handle *rath,
|
|||
|
||||
DEBUGP(" ");
|
||||
|
||||
ret = openpcd_send_command(OPENPCD_CMD_READ_FIFO, 0x00, num_bytes, 0, NULL);
|
||||
ret = openpcd_xcv(OPENPCD_CMD_READ_FIFO, 0x00, num_bytes, 0, NULL);
|
||||
if (ret < 0) {
|
||||
DEBUGPC("ERROR sending command\n");
|
||||
return ret;
|
||||
}
|
||||
DEBUGPC("ret = %d\n", ret);
|
||||
|
||||
ret = openpcd_recv_reply();
|
||||
if (ret < 0) {
|
||||
DEBUGPC("ERROR receiving reply\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
memcpy(buf, rcv_hdr->data, rcv_hdr->len);
|
||||
DEBUGPC("len=%u val=%s: OK\n", rcv_hdr->len,
|
||||
rfid_hexdump(rcv_hdr->data, rcv_hdr->len));
|
||||
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;
|
||||
}
|
||||
|
@ -178,7 +187,7 @@ static int openpcd_fifo_write(struct rfid_asic_transport_handle *rath,
|
|||
int ret;
|
||||
|
||||
DEBUGP("len=%u, data=%s\n", len, rfid_hexdump(bytes, len));
|
||||
ret = openpcd_send_command(OPENPCD_CMD_WRITE_FIFO, 0, 0, len, bytes);
|
||||
ret = openpcd_xcv(OPENPCD_CMD_WRITE_FIFO, 0, 0, len, bytes);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -304,14 +313,19 @@ openpcd_open(void *data)
|
|||
return NULL;
|
||||
|
||||
dev = find_opcd_device();
|
||||
if (!dev)
|
||||
if (!dev) {
|
||||
DEBUGP("No matching USB device found\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hdl = usb_open(dev);
|
||||
if (!hdl)
|
||||
if (!hdl) {
|
||||
DEBUGP("Can't open USB device\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (usb_claim_interface(hdl, 0) < 0) {
|
||||
DEBUGP("Can't claim interface\n");
|
||||
usb_close(hdl);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -378,5 +392,3 @@ struct rfid_reader rfid_reader_openpcd = {
|
|||
.auth = &openpcd_mifare_auth,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue