/* Omnikey CardMan 5121 specific RC632 transport layer
*
- * (C) 2005 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2005-2006 by Harald Welte <laforge@gnumonks.org>
*
- * 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.
*
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
-
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
+#define DEBUG_LIBRFID
#include <librfid/rfid.h>
+
+#ifndef LIBRFID_FIRMWARE
+
+
#include <librfid/rfid_reader.h>
#include <librfid/rfid_asic.h>
#include <librfid/rfid_asic_rc632.h>
#include <librfid/rfid_reader_cm5121.h>
+#include <librfid/rfid_layer2.h>
+#include <librfid/rfid_protocol.h>
+
+#include "cm5121_source.h"
/* FIXME */
#include "rc632.h"
-//#define SENDBUF_LEN 40
-#define SENDBUF_LEN 100
-#define RECVBUF_LEN 40
+#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
int Write1ByteToReg(struct rfid_asic_transport_handle *rath,
{
unsigned char sndbuf[SENDBUF_LEN];
unsigned char rcvbuf[RECVBUF_LEN];
- unsigned int retlen = RECVBUF_LEN;
+ size_t retlen = RECVBUF_LEN;
sndbuf[0] = 0x20;
sndbuf[1] = 0x00;
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;
}
{
unsigned char sndbuf[SENDBUF_LEN];
unsigned char recvbuf[RECVBUF_LEN];
- unsigned int retlen = sizeof(recvbuf);
+ size_t retlen = sizeof(recvbuf);
sndbuf[0] = 0x20;
sndbuf[1] = 0x00;
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;
}
{
unsigned char sndbuf[SENDBUF_LEN];
unsigned char recvbuf[0x7f];
- unsigned int retlen = sizeof(recvbuf);
+ size_t retlen = sizeof(recvbuf);
sndbuf[0] = 0x20;
sndbuf[1] = 0x00;
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;
}
{
unsigned char sndbuf[SENDBUF_LEN];
unsigned char recvbuf[0x7f];
- unsigned int retlen = sizeof(recvbuf);
+ size_t retlen = sizeof(recvbuf);
sndbuf[0] = 0x20;
sndbuf[1] = 0x00;
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;
}
}
#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);
}
DEBUGPC("848K\n");
break;
default:
+ DEBUGPC("invalid\n");
return -EINVAL;
break;
}
{
unsigned char tx_buf[1] = { 0x01 };
unsigned char rx_buf[64];
- unsigned int rx_len = sizeof(rx_buf);
+ size_t rx_len = sizeof(rx_buf);
PC_to_RDR_Escape(rath->data, tx_buf, 1, rx_buf, &rx_len);
- printf("received %u bytes from 01 command\n", rx_len);
return 0;
}
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));
return rh;
out_rath:
- free(rath);
+ free_rat_handle(rath);
out_rh:
- free(rh);
+ free_reader_handle(rh);
return NULL;
}
{
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,
+ .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,
+ 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 */