diff options
-rw-r--r-- | include/rfid/rfid.h | 6 | ||||
-rw-r--r-- | include/rfid/rfid_asic_rc632.h | 2 | ||||
-rw-r--r-- | include/rfid/rfid_layer2.h | 51 | ||||
-rw-r--r-- | include/rfid/rfid_layer2_iso14443a.h | 42 | ||||
-rw-r--r-- | include/rfid/rfid_layer2_iso14443b.h | 5 | ||||
-rw-r--r-- | include/rfid/rfid_protocol.h | 71 | ||||
-rw-r--r-- | include/rfid/rfid_protocol_mifare_classic.h | 22 | ||||
-rw-r--r-- | include/rfid/rfid_protocol_mifare_ul.h | 12 | ||||
-rw-r--r-- | include/rfid/rfid_protocol_tcl.h | 5 | ||||
-rw-r--r-- | include/rfid/rfid_reader.h | 9 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/rc632.h | 6 | ||||
-rw-r--r-- | src/rfid_asic_rc632.c | 17 | ||||
-rw-r--r-- | src/rfid_layer2.c | 33 | ||||
-rw-r--r-- | src/rfid_layer2_iso14443a.c | 21 | ||||
-rw-r--r-- | src/rfid_proto_mifare_classic.c | 12 | ||||
-rw-r--r-- | src/rfid_proto_mifare_ul.c | 12 | ||||
-rw-r--r-- | src/rfid_proto_tcl.c | 45 | ||||
-rw-r--r-- | src/rfid_reader_cm5121.c | 36 | ||||
-rw-r--r-- | utils/openct-escape.c | 7 |
20 files changed, 273 insertions, 143 deletions
diff --git a/include/rfid/rfid.h b/include/rfid/rfid.h index f9d36c9..6bb5b58 100644 --- a/include/rfid/rfid.h +++ b/include/rfid/rfid.h @@ -3,18 +3,20 @@ #include <stdio.h> +#ifdef __LIBRFID__ + enum rfid_frametype { RFID_14443A_FRAME_REGULAR, RFID_14443B_FRAME_REGULAR, RFID_MIFARE_FRAME, }; - - #define DEBUGP(x, args ...) fprintf(stderr, "%s(%d):%s: " x, __FILE__, __LINE__, __FUNCTION__, ## args) #define DEBUGPC(x, args ...) fprintf(stderr, x, ## args) extern const char *rfid_hexdump(const void *data, unsigned int len); +#endif + int rfid_init(); #endif /* _RFID_H */ diff --git a/include/rfid/rfid_asic_rc632.h b/include/rfid/rfid_asic_rc632.h index 494e044..315fee2 100644 --- a/include/rfid/rfid_asic_rc632.h +++ b/include/rfid/rfid_asic_rc632.h @@ -51,6 +51,8 @@ struct rfid_asic_rc632 { int (*transcieve_acf)(struct rfid_asic_handle *h, struct iso14443a_anticol_cmd *cmd, unsigned int *bit_of_col); + int (*set_speed)(struct rfid_asic_handle *h, + unsigned int speed); } iso14443a; struct { int (*init)(struct rfid_asic_handle *h); diff --git a/include/rfid/rfid_layer2.h b/include/rfid/rfid_layer2.h index f6d9117..54c3c46 100644 --- a/include/rfid/rfid_layer2.h +++ b/include/rfid/rfid_layer2.h @@ -1,16 +1,40 @@ #ifndef _RFID_LAYER2_H #define _RFID_LAYER2_H +#include <sys/types.h> +#include <rfid/rfid.h> + struct rfid_layer2_handle; struct rfid_reader_handle; -#include <rfid/rfid.h> +enum rfid_layer2_id { + RFID_LAYER2_NONE, + RFID_LAYER2_ISO14443A, + RFID_LAYER2_ISO14443B, + RFID_LAYER2_ISO15693, +}; + +struct rfid_layer2_handle *rfid_layer2_init(struct rfid_reader_handle *rh, + unsigned int id); +int rfid_layer2_open(struct rfid_layer2_handle *l2h); +int rfid_layer2_transcieve(struct rfid_layer2_handle *l2h, + enum rfid_frametype frametype, + const unsigned char *tx_buf, unsigned int tx_len, + unsigned char *rx_buf, unsigned int *rx_len, + u_int64_t timeout, unsigned int flags); +int rfid_layer2_close(struct rfid_layer2_handle *l2h); +int rfid_layer2_fini(struct rfid_layer2_handle *l2h); +int rfid_layer2_getopt(struct rfid_layer2_handle *ph, int optname, + void *optval, unsigned int *optlen); +int rfid_layer2_setopt(struct rfid_layer2_handle *ph, int optname, + const void *optval, unsigned int optlen); + +#ifdef __LIBRFID__ #include <rfid/rfid_layer2_iso14443a.h> #include <rfid/rfid_layer2_iso14443b.h> #include <rfid/rfid_layer2_iso15693.h> - struct rfid_layer2 { unsigned int id; char *name; @@ -26,6 +50,11 @@ struct rfid_layer2 { unsigned int flags); int (*close)(struct rfid_layer2_handle *h); int (*fini)(struct rfid_layer2_handle *h); + int (*getopt)(struct rfid_layer2_handle *h, + int optname, void *optval, unsigned int *optlen); + int (*setopt)(struct rfid_layer2_handle *h, + int optname, const void *optval, + unsigned int optlen); } fn; struct rfid_layer2 *next; }; @@ -42,22 +71,6 @@ struct rfid_layer2_handle { struct rfid_layer2 *l2; }; -enum rfid_layer2_id { - RFID_LAYER2_NONE, - RFID_LAYER2_ISO14443A, - RFID_LAYER2_ISO14443B, - RFID_LAYER2_ISO15693, -}; - -struct rfid_layer2_handle *rfid_layer2_init(struct rfid_reader_handle *rh, - unsigned int id); -int rfid_layer2_open(struct rfid_layer2_handle *l2h); -int rfid_layer2_transcieve(struct rfid_layer2_handle *l2h, - enum rfid_frametype frametype, - const unsigned char *tx_buf, unsigned int tx_len, - unsigned char *rx_buf, unsigned int *rx_len, - u_int64_t timeout, unsigned int flags); -int rfid_layer2_close(struct rfid_layer2_handle *l2h); -int rfid_layer2_fini(struct rfid_layer2_handle *l2h); +#endif /* __LIBRFID__ */ #endif diff --git a/include/rfid/rfid_layer2_iso14443a.h b/include/rfid/rfid_layer2_iso14443a.h index 400f951..bd078ad 100644 --- a/include/rfid/rfid_layer2_iso14443a.h +++ b/include/rfid/rfid_layer2_iso14443a.h @@ -1,6 +1,19 @@ #ifndef _RFID_ISO14443A_H #define _RFID_ISO14443A_H +enum rfid_14443a_opt { + RFID_OPT_14443A_SPEED = 0x00000001, +}; + +enum rfid_14443_opt_speed { + RFID_14443A_SPEED_106K, + RFID_14443A_SPEED_212K, + RFID_14443A_SPEED_424K, + RFID_14443A_SPEED_848K, +}; + +#ifdef __LIBRFID__ + #include <sys/types.h> /* protocol definitions */ @@ -38,32 +51,6 @@ enum iso14443a_anticol_sel_code { #define ISO14443A_BITOFCOL_NONE 0xffffffff -struct iso14443a_handle; - -struct iso14443a_transport { - unsigned char *name; - - struct { - int (*init)(struct iso14443a_handle *handle); - int (*fini)(struct iso14443a_handle *handle); - - int (*transcieve_sf)(struct iso14443a_handle *handle, - unsigned char cmd, - struct iso14443a_atqa *atqa); - int (*transcieve_acf)(struct iso14443a_handle *handle, - struct iso14443a_anticol_cmd *acf, - unsigned int *bit_of_col); - int (*transcieve)(struct iso14443a_handle *handle, - const unsigned char *tx_buf, - unsigned int tx_len, - unsigned char *rx_buf, - unsigned int *rx_len); - } fn; - - union { - } priv; -}; - struct iso14443a_handle { unsigned int state; unsigned int level; @@ -90,4 +77,7 @@ enum iso14443a_state { #include <rfid/rfid_layer2.h> struct rfid_layer2 rfid_layer2_iso14443a; +#endif /* __LIBRFID__ */ + + #endif /* _ISO14443A_H */ diff --git a/include/rfid/rfid_layer2_iso14443b.h b/include/rfid/rfid_layer2_iso14443b.h index 6c84c26..2bf8255 100644 --- a/include/rfid/rfid_layer2_iso14443b.h +++ b/include/rfid/rfid_layer2_iso14443b.h @@ -1,6 +1,8 @@ #ifndef _RFID_LAYER2_ISO14443B_H #define _RFID_LAYER2_ISO14443B_H +#ifdef __LIBRFID__ + struct iso14443b_atqb { unsigned char fifty; unsigned char pupi[4]; @@ -75,8 +77,9 @@ enum { ISO14443B_STATE_HALTED, }; - #include <rfid/rfid_layer2.h> struct rfid_layer2 rfid_layer2_iso14443b; +#endif /* __LIBRFID__ */ + #endif diff --git a/include/rfid/rfid_protocol.h b/include/rfid/rfid_protocol.h index 1403e83..bd9570f 100644 --- a/include/rfid/rfid_protocol.h +++ b/include/rfid/rfid_protocol.h @@ -5,8 +5,37 @@ struct rfid_protocol_handle; -#include <rfid/rfid_protocol_tcl.h> -#include <rfid/rfid_protocol_mifare_ul.h> +struct rfid_protocol_handle * +rfid_protocol_init(struct rfid_layer2_handle *l2h, unsigned int id); +int rfid_protocol_open(struct rfid_protocol_handle *ph); +int rfid_protocol_transcieve(struct rfid_protocol_handle *ph, + const unsigned char *tx_buf, unsigned int tx_len, + unsigned char *rx_buf, unsigned int *rx_len, + unsigned int timeout, unsigned int flags); +int +rfid_protocol_read(struct rfid_protocol_handle *ph, + unsigned int page, + unsigned char *rx_data, + unsigned int *rx_len); + +int +rfid_protocol_write(struct rfid_protocol_handle *ph, + unsigned int page, + unsigned char *tx_data, + unsigned int tx_len); + +int rfid_protocol_fini(struct rfid_protocol_handle *ph); +int rfid_protocol_close(struct rfid_protocol_handle *ph); + +enum rfid_protocol_id { + RFID_PROTOCOL_UNKNOWN, + RFID_PROTOCOL_TCL, + RFID_PROTOCOL_MIFARE_UL, + RFID_PROTOCOL_MIFARE_CLASSIC, +}; + + +#ifdef __LIBRFID__ struct rfid_protocol { struct rfid_protocol *next; @@ -37,6 +66,12 @@ struct rfid_protocol { } fn; }; +int rfid_protocol_register(struct rfid_protocol *p); + +#include <rfid/rfid_protocol_tcl.h> +#include <rfid/rfid_protocol_mifare_ul.h> +#include <rfid/rfid_protocol_mifare_classic.h> + struct rfid_protocol_handle { struct rfid_layer2_handle *l2h; struct rfid_protocol *proto; @@ -48,34 +83,6 @@ struct rfid_protocol_handle { * sizeof(priv). */ }; -struct rfid_protocol_handle * -rfid_protocol_init(struct rfid_layer2_handle *l2h, unsigned int id); -int rfid_protocol_open(struct rfid_protocol_handle *ph); -int rfid_protocol_transcieve(struct rfid_protocol_handle *ph, - const unsigned char *tx_buf, unsigned int tx_len, - unsigned char *rx_buf, unsigned int *rx_len, - unsigned int timeout, unsigned int flags); -int -rfid_protocol_read(struct rfid_protocol_handle *ph, - unsigned int page, - unsigned char *rx_data, - unsigned int *rx_len); +#endif /* __LIBRFID__ */ -int -rfid_protocol_write(struct rfid_protocol_handle *ph, - unsigned int page, - unsigned char *tx_data, - unsigned int tx_len); - -int rfid_protocol_fini(struct rfid_protocol_handle *ph); -int rfid_protocol_close(struct rfid_protocol_handle *ph); - -int rfid_protocol_register(struct rfid_protocol *p); - -enum rfid_protocol_id { - RFID_PROTOCOL_UNKNOWN, - RFID_PROTOCOL_TCL, - RFID_PROTOCOL_MIFARE_UL, - RFID_PROTOCOL_MIFARE_CLASSIC, -}; -#endif +#endif /* _RFID_PROTOCOL_H */ diff --git a/include/rfid/rfid_protocol_mifare_classic.h b/include/rfid/rfid_protocol_mifare_classic.h index b5c7daf..e6b2400 100644 --- a/include/rfid/rfid_protocol_mifare_classic.h +++ b/include/rfid/rfid_protocol_mifare_classic.h @@ -1,22 +1,28 @@ #ifndef _MIFARE_CLASSIC_H -extern struct rfid_protocol rfid_protocol_mfcl; +#define MIFARE_CL_KEYA_DEFAULT "\xa0\xa1\xa2\xa3\xa4\xa5" +#define MIFARE_CL_KEYB_DEFAULT "\xb0\xb1\xb2\xb3\xb4\xb5" + +#define MIFARE_CL_KEYA_DEFAULT_INFINEON "\xff\xff\xff\xff\xff\xff" +#define MIFARE_CL_KEYB_DEFAULT_INFINEON MIFARE_CL_KEYA_DEFAULT_INFINEON + +#define MIFARE_CL_PAGE_MAX 0xff #define RFID_CMD_MIFARE_AUTH1A 0x60 #define RFID_CMD_MIFARE_AUTH1B 0x61 +#ifdef __LIBRFID__ + +extern struct rfid_protocol rfid_protocol_mfcl; + + #define MIFARE_CL_CMD_WRITE16 0xA0 #define MIFARE_CL_CMD_READ 0x30 #define MIFARE_CL_RESP_ACK 0x0a #define MIFARE_CL_RESP_NAK 0x00 -#define MIFARE_CL_PAGE_MAX 0xff -#define MIFARE_CL_KEYA_DEFAULT "\xa0\xa1\xa2\xa3\xa4\xa5" -#define MIFARE_CL_KEYB_DEFAULT "\xb0\xb1\xb2\xb3\xb4\xb5" - -#define MIFARE_CL_KEYA_DEFAULT_INFINEON "\xff\xff\xff\xff\xff\xff" -#define MIFARE_CL_KEYB_DEFAULT_INFINEON MIFARE_CL_KEYA_DEFAULT_INFINEON +#endif /* __LIBRFID__ */ -#endif +#endif /* _MIFARE_CLASSIC_H */ diff --git a/include/rfid/rfid_protocol_mifare_ul.h b/include/rfid/rfid_protocol_mifare_ul.h index 06cf515..cc93b6b 100644 --- a/include/rfid/rfid_protocol_mifare_ul.h +++ b/include/rfid/rfid_protocol_mifare_ul.h @@ -1,7 +1,12 @@ #ifndef _RFID_PROTOCOL_MFUL_H #define _RFID_PROTOCOL_MFUL_H -#include <rfid/rfid_protocol.h> +int rfid_mful_lock_page(struct rfid_protocol_handle *ph, unsigned int page); +int rfid_mful_lock_otp(struct rfid_protocol_handle *ph); + +#define MIFARE_UL_PAGE_MAX 15 + +#ifdef __LIBRFID__ #define MIFARE_UL_CMD_WRITE 0xA2 #define MIFARE_UL_CMD_READ 0x30 @@ -9,14 +14,11 @@ #define MIFARE_UL_RESP_ACK 0x0a #define MIFARE_UL_RESP_NAK 0x00 -#define MIFARE_UL_PAGE_MAX 15 #define MIFARE_UL_PAGE_LOCK 2 #define MIFARE_UL_PAGE_OTP 3 extern struct rfid_protocol rfid_protocol_mful; - -int rfid_mful_lock_page(struct rfid_protocol_handle *ph, unsigned int page); -int rfid_mful_lock_otp(struct rfid_protocol_handle *ph); +#endif /* __LIBRFID__ */ #endif diff --git a/include/rfid/rfid_protocol_tcl.h b/include/rfid/rfid_protocol_tcl.h index f0dbcdc..f754ad9 100644 --- a/include/rfid/rfid_protocol_tcl.h +++ b/include/rfid/rfid_protocol_tcl.h @@ -1,6 +1,8 @@ #ifndef _RFID_PROTOCOL_TCL_H #define _RFID_PROTOCOL_TCL_H +#ifdef __LIBRFID__ + enum tcl_transport_rate { TCL_RATE_106 = 0x01, TCL_RATE_212 = 0x02, @@ -13,7 +15,6 @@ enum tcl_transport_transcieve_flags { TCL_TRANSP_F_RX_CRC = 0x02, }; - struct tcl_handle { /* derived from ats */ unsigned char *historical_bytes; /* points into ats */ @@ -64,4 +65,6 @@ enum tcl_pcd_state { struct rfid_protocol rfid_protocol_tcl; +#endif /* __LIBRFID__ */ + #endif diff --git a/include/rfid/rfid_reader.h b/include/rfid/rfid_reader.h index 501119b..364425c 100644 --- a/include/rfid/rfid_reader.h +++ b/include/rfid/rfid_reader.h @@ -25,6 +25,8 @@ struct rfid_reader { int (*transcieve_acf)(struct rfid_reader_handle *h, struct iso14443a_anticol_cmd *cmd, unsigned int *bit_of_col); + int (*set_speed)(struct rfid_reader_handle *h, + unsigned int speed); unsigned int speed; } iso14443a; struct rfid_14443b_reader { @@ -47,13 +49,6 @@ enum rfid_reader_id { RFID_READER_PEGODA, }; -enum rfid_reader_14443a_speed { - RFID_READER_SPEED_106K, - RFID_READER_SPEED_212K, - RFID_READER_SPEED_424K, - RFID_READER_SPEED_848K, -}; - struct rfid_reader_handle { struct rfid_asic_handle *ah; diff --git a/src/Makefile.am b/src/Makefile.am index fe219b7..dbc608f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ LIBVERSION= 0:0:0 -INCLUDES = $(all_includes) -I$(top_srcdir)/include +INCLUDES = $(all_includes) -I$(top_srcdir)/include -D__LIBRFID__ lib_LTLIBRARIES = librfid.la diff --git a/src/rc632.h b/src/rc632.h index 4ad0e99..0bd5b00 100644 --- a/src/rc632.h +++ b/src/rc632.h @@ -116,13 +116,9 @@ enum rc632_reg_coder_control { RC632_CDRCTRL_TXCD_14443A = 0x01, RC632_CDRCTRL_TXCD_ICODE_STD = 0x04, +#define RC632_CDRDTRL_RATE_MASK 0x38 RC632_CDRCTRL_RATE_848K = 0x00, -#if 0 - /* See mc073930.pdf, page 41 */ - RC632_CDRCTRL_RATE_424K = 0x80, -#else RC632_CDRCTRL_RATE_424K = 0x08, -#endif RC632_CDRCTRL_RATE_212K = 0x10, RC632_CDRCTRL_RATE_106K = 0x18, RC632_CDRCTRL_RATE_14443B = 0x20, diff --git a/src/rfid_asic_rc632.c b/src/rfid_asic_rc632.c index 4377d73..e794a38 100644 --- a/src/rfid_asic_rc632.c +++ b/src/rfid_asic_rc632.c @@ -739,6 +739,22 @@ rc632_iso14443a_transcieve_acf(struct rfid_asic_handle *handle, return 0; } +static int rc632_iso14443a_set_speed(struct rfid_asic_handle *handle, + u_int8_t rate) +{ + int rc; + u_int8_t reg; + + rc = rc632_reg_read(handle, RC632_REG_CODER_CONTROL, ®); + if (rc < 0) + return rc; + + reg &= ~RC632_CDRDTRL_RATE_MASK; + reg |= (rate & RC632_CDRDTRL_RATE_MASK); + + return rc632_reg_write(handle, RC632_REG_CODER_CONTROL, reg); +} + static int rc632_iso14443b_init(struct rfid_asic_handle *handle) { int ret; @@ -1279,6 +1295,7 @@ struct rfid_asic rc632 = { .init = &rc632_iso14443a_init, .transcieve_sf = &rc632_iso14443a_transcieve_sf, .transcieve_acf = &rc632_iso14443a_transcieve_acf, + .set_speed = &rc632_iso14443a_set_speed, }, .iso14443b = { .init = &rc632_iso14443b_init, diff --git a/src/rfid_layer2.c b/src/rfid_layer2.c index c1ab6a6..01443d8 100644 --- a/src/rfid_layer2.c +++ b/src/rfid_layer2.c @@ -19,6 +19,7 @@ #include <stdlib.h> #include <stdio.h> +#include <errno.h> #include <rfid/rfid.h> #include <rfid/rfid_layer2.h> @@ -41,6 +42,9 @@ rfid_layer2_init(struct rfid_reader_handle *rh, unsigned int id) int rfid_layer2_open(struct rfid_layer2_handle *ph) { + if (!ph->l2->fn.open) + return 0; + return ph->l2->fn.open(ph); } @@ -51,18 +55,27 @@ rfid_layer2_transcieve(struct rfid_layer2_handle *ph, unsigned char *rx_buf, unsigned int *rx_len, u_int64_t timeout, unsigned int flags) { + if (!ph->l2->fn.transcieve) + return -EIO; + return ph->l2->fn.transcieve(ph, frametype, tx_buf, len, rx_buf, rx_len, timeout, flags); } int rfid_layer2_fini(struct rfid_layer2_handle *ph) { + if (!ph->l2->fn.fini) + return 0; + return ph->l2->fn.fini(ph); } int rfid_layer2_close(struct rfid_layer2_handle *ph) { + if (!ph->l2->fn.close) + return 0; + return ph->l2->fn.close(ph); } @@ -74,3 +87,23 @@ rfid_layer2_register(struct rfid_layer2 *p) return 0; } + +int +rfid_layer2_getopt(struct rfid_layer2_handle *ph, int optname, + void *optval, unsigned int *optlen) +{ + if (!ph->l2->fn.getopt) + return -EINVAL; + + return ph->l2->fn.getopt(ph, optname, optval, optlen); +} + +int +rfid_layer2_setopt(struct rfid_layer2_handle *ph, int optname, + const void *optval, unsigned int optlen) +{ + if (!ph->l2->fn.setopt) + return -EINVAL; + + return ph->l2->fn.setopt(ph, optname, optval, optlen); +} diff --git a/src/rfid_layer2_iso14443a.c b/src/rfid_layer2_iso14443a.c index d93f917..d33b316 100644 --- a/src/rfid_layer2_iso14443a.c +++ b/src/rfid_layer2_iso14443a.c @@ -22,6 +22,7 @@ #include <stdlib.h> #include <unistd.h> #include <string.h> +#include <errno.h> #include <rfid/rfid.h> #include <rfid/rfid_layer2.h> @@ -250,6 +251,25 @@ iso14443a_hlta(struct rfid_layer2_handle *handle) return -1; } +static int +iso14443a_setopt(struct rfid_layer2_handle *handle, int optname, + const void *optval, unsigned int optlen) +{ + int ret = -EINVAL; + struct rfid_reader *rdr = handle->rh->reader; + unsigned int speed; + + switch (optname) { + case RFID_OPT_14443A_SPEED: + speed = *(unsigned int *)optval; + ret = rdr->iso14443a.set_speed(handle->rh, speed); + break; + }; + + return ret; +} + + static struct rfid_layer2_handle * iso14443a_init(struct rfid_reader_handle *rh) { @@ -289,6 +309,7 @@ struct rfid_layer2 rfid_layer2_iso14443a = { .transcieve = &iso14443a_transcieve, .close = &iso14443a_hlta, .fini = &iso14443a_fini, + .setopt = &iso14443a_setopt, }, }; diff --git a/src/rfid_proto_mifare_classic.c b/src/rfid_proto_mifare_classic.c index 99386a1..d6de606 100644 --- a/src/rfid_proto_mifare_classic.c +++ b/src/rfid_proto_mifare_classic.c @@ -57,9 +57,9 @@ mfcl_read(struct rfid_protocol_handle *ph, unsigned int page, tx[0] = MIFARE_CL_CMD_READ; tx[1] = page & 0xff; - ret = ph->l2h->l2->fn.transcieve(ph->l2h, RFID_MIFARE_FRAME, tx, - sizeof(tx), rx_buf, &real_rx_len, - MIFARE_CL_READ_FWT, 0); + ret = rfid_layer2_transcieve(ph->l2h, RFID_MIFARE_FRAME, tx, + sizeof(tx), rx_buf, &real_rx_len, + MIFARE_CL_READ_FWT, 0); if (ret < 0) return ret; @@ -93,9 +93,9 @@ mfcl_write(struct rfid_protocol_handle *ph, unsigned int page, memcpy(tx+2, tx_data, 16); - ret = ph->l2h->l2->fn.transcieve(ph->l2h, RFID_MIFARE_FRAME, tx, - sizeof(tx), rx, &rx_len, - MIFARE_CL_WRITE_FWT, 0); + ret = rfid_layer2_transcieve(ph->l2h, RFID_MIFARE_FRAME, tx, + sizeof(tx), rx, &rx_len, + MIFARE_CL_WRITE_FWT, 0); if (ret < 0) return ret; diff --git a/src/rfid_proto_mifare_ul.c b/src/rfid_proto_mifare_ul.c index 9e5363f..7649b99 100644 --- a/src/rfid_proto_mifare_ul.c +++ b/src/rfid_proto_mifare_ul.c @@ -52,9 +52,9 @@ mful_read(struct rfid_protocol_handle *ph, unsigned int page, tx[0] = MIFARE_UL_CMD_READ; tx[1] = page & 0xff; - ret = ph->l2h->l2->fn.transcieve(ph->l2h, RFID_14443A_FRAME_REGULAR, - tx, sizeof(tx), rx_buf, - &real_rx_len, MIFARE_UL_READ_FWT, 0); + ret = rfid_layer2_transcieve(ph->l2h, RFID_14443A_FRAME_REGULAR, + tx, sizeof(tx), rx_buf, + &real_rx_len, MIFARE_UL_READ_FWT, 0); if (ret < 0) return ret; @@ -86,9 +86,9 @@ mful_write(struct rfid_protocol_handle *ph, unsigned int page, for (i = 0; i < 4; i++) tx[2+i] = tx_data[i]; - ret = ph->l2h->l2->fn.transcieve(ph->l2h, RFID_14443A_FRAME_REGULAR, - tx, sizeof(tx), rx, &rx_len, - MIFARE_UL_WRITE_FWT, 0); + ret = rfid_layer2_transcieve(ph->l2h, RFID_14443A_FRAME_REGULAR, + tx, sizeof(tx), rx, &rx_len, + MIFARE_UL_WRITE_FWT, 0); if (ret < 0) return ret; diff --git a/src/rfid_proto_tcl.c b/src/rfid_proto_tcl.c index f070614..2be20d9 100644 --- a/src/rfid_proto_tcl.c +++ b/src/rfid_proto_tcl.c @@ -40,6 +40,9 @@ #ifdef DEBUGP #undef DEBUGP #define DEBUGP(x, ...) +#endif +#ifdef DEBUGPC +#undef DEBUGPC #define DEBUGPC(x, ...) #endif #endif @@ -185,10 +188,10 @@ tcl_request_ats(struct rfid_protocol_handle *h) rats[1] = (h->priv.tcl.cid & 0x0f) | ((fsdi << 4) & 0xf0); /* transcieve (with CRC) */ - ret = h->l2h->l2->fn.transcieve(h->l2h, RFID_14443A_FRAME_REGULAR, - rats, 2, h->priv.tcl.ats, - &h->priv.tcl.ats_len, activation_fwt(h), - TCL_TRANSP_F_TX_CRC); + ret = rfid_layer2_transcieve(h->l2h, RFID_14443A_FRAME_REGULAR, + rats, 2, h->priv.tcl.ats, + &h->priv.tcl.ats_len, activation_fwt(h), + TCL_TRANSP_F_TX_CRC); if (ret < 0) { DEBUGP("transcieve of rats failed\n"); h->priv.tcl.state = TCL_STATE_RATS_SENT; @@ -219,11 +222,11 @@ static unsigned char d_to_di(struct rfid_protocol_handle *h, unsigned char D) static char DI; unsigned int speed = h->l2h->rh->reader->iso14443a.speed; - if ((D & ATS_TA_DIV_8) && (speed & RFID_READER_SPEED_848K)) + if ((D & ATS_TA_DIV_8) && (speed & RFID_14443A_SPEED_848K)) DI = PPS_DIV_8; - else if ((D & ATS_TA_DIV_4) && (speed & RFID_READER_SPEED_424K)) + else if ((D & ATS_TA_DIV_4) && (speed & RFID_14443A_SPEED_424K)) DI = PPS_DIV_4; - else if ((D & ATS_TA_DIV_2) && (speed & RFID_READER_SPEED_212K)) + else if ((D & ATS_TA_DIV_2) && (speed & RFID_14443A_SPEED_212K)) DI = PPS_DIV_2; else DI = PPS_DIV_1; @@ -232,16 +235,17 @@ static unsigned char d_to_di(struct rfid_protocol_handle *h, unsigned char D) } -/* start a PSS run (autimatically configure highest possible speed */ +/* start a PPS run (autimatically configure highest possible speed */ static int tcl_do_pps(struct rfid_protocol_handle *h) { -#if 0 +#if 1 int ret; unsigned char ppss[3]; unsigned char pps_response[1]; unsigned int rx_len = 1; unsigned char Dr, Ds, DrI, DsI; + unsigned int optlen = 0; if (h->priv.tcl.state != TCL_STATE_ATS_RCVD) return -1; @@ -257,7 +261,7 @@ tcl_do_pps(struct rfid_protocol_handle *h) /* ISO 14443-4:2000(E) Section 5.3. */ - ppss[0] = 0xd0 & (h->priv.tcl.cid & 0x0f); + ppss[0] = 0xd0 | (h->priv.tcl.cid & 0x0f); ppss[1] = 0x11; /* FIXME: deal with different speed for each direction */ @@ -266,9 +270,9 @@ tcl_do_pps(struct rfid_protocol_handle *h) ppss[2] = (ppss[2] & 0xf0) | (DrI | DsI << 2); - ret = h->l2h->l2->fn.transcieve(h->l2h, ppss, 3, pps_response, - &rx_len, h->priv.tcl.fwt, - TCL_TRANSP_F_TX_CRC); + ret = rfid_layer2_transcieve(h->l2h, RFID_14443A_FRAME_REGULAR, + ppss, 3, pps_response, &rx_len, + h->priv.tcl.fwt, TCL_TRANSP_F_TX_CRC); if (ret < 0) return ret; @@ -276,6 +280,11 @@ tcl_do_pps(struct rfid_protocol_handle *h) DEBUGP("PPS Response != PPSS\n"); return -1; } + + ret = rfid_layer2_setopt(h->l2h, RFID_OPT_14443A_SPEED, + NULL, &optlen); + if (ret < 0) + return ret; h->priv.tcl.state = TCL_STATE_ESTABLISHED; #endif @@ -453,8 +462,8 @@ tcl_deselect(struct rfid_protocol_handle *h) if (ret < 0) return ret; - ret = h->l2h->l2->fn.transcieve(h->l2h, RFID_14443A_FRAME_REGULAR, - frame, prlg_len, rx, + ret = rfid_layer2_transcieve(h->l2h, RFID_14443A_FRAME_REGULAR, + frame, prlg_len, rx, &rx_len, deactivation_fwt(h), TCL_TRANSP_F_TX_CRC); if (ret < 0) { @@ -522,9 +531,9 @@ tcl_transcieve(struct rfid_protocol_handle *h, *rx_len = 0; do_tx: - ret = h->l2h->l2->fn.transcieve(h->l2h, l2_to_frame(h->l2h->l2->id), - _tx, _tx_len, - rx_buf, &_rx_len, _timeout, 0); + ret = rfid_layer2_transcieve(h->l2h, l2_to_frame(h->l2h->l2->id), + _tx, _tx_len, + rx_buf, &_rx_len, _timeout, 0); DEBUGP("l2 transcieve finished\n"); if (ret < 0) goto out_rxb; diff --git a/src/rfid_reader_cm5121.c b/src/rfid_reader_cm5121.c index 978e18f..f2a8b9a 100644 --- a/src/rfid_reader_cm5121.c +++ b/src/rfid_reader_cm5121.c @@ -30,6 +30,7 @@ #include <stdlib.h> #include <unistd.h> #include <string.h> +#include <errno.h> #include <rfid/rfid.h> #include <rfid/rfid_reader.h> @@ -37,11 +38,14 @@ #include <rfid/rfid_asic_rc632.h> #include <rfid/rfid_reader_cm5121.h> +/* FIXME */ +#include "rc632.h" + //#define SENDBUF_LEN 40 #define SENDBUF_LEN 100 #define RECVBUF_LEN 40 -#if 1 +#if 0 #ifdef DEBUGP #undef DEBUGP #define DEBUGP(x, ...) @@ -215,6 +219,31 @@ cm5121_14443a_init(struct rfid_reader_handle *rh) } static int +cm5121_14443a_set_speed(struct rfid_reader_handle *rh, unsigned int speed) +{ + u_int8_t rate; + + switch (speed) { + case RFID_14443A_SPEED_106K: + rate = RC632_CDRCTRL_RATE_106K; + break; + case RFID_14443A_SPEED_212K: + rate = RC632_CDRCTRL_RATE_212K; + break; + case RFID_14443A_SPEED_424K: + rate = RC632_CDRCTRL_RATE_424K; + break; + case RFID_14443A_SPEED_848K: + rate = RC632_CDRCTRL_RATE_848K; + break; + default: + return -EINVAL; + break; + } + return rh->ah->asic->priv.rc632.fn.iso14443a.set_speed(rh->ah, rate); +} + +static int cm5121_14443b_init(struct rfid_reader_handle *rh) { return rh->ah->asic->priv.rc632.fn.iso14443b.init(rh->ah); @@ -322,8 +351,9 @@ struct rfid_reader rfid_reader_cm5121 = { .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, + .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, diff --git a/utils/openct-escape.c b/utils/openct-escape.c index 6f19eb5..0f9a68a 100644 --- a/utils/openct-escape.c +++ b/utils/openct-escape.c @@ -24,6 +24,7 @@ #include <rfid/rfid_protocol.h> #include <rfid/rfid_reader_cm5121.h> #include <rfid/rfid_protocol_mifare_classic.h> +#include <rfid/rfid_protocol_mifare_ul.h> static struct rfid_reader_handle *rh; static struct rfid_layer2_handle *l2h; @@ -250,7 +251,7 @@ mifare_classic_read(struct rfid_protocol_handle *ph) if (ret < 0) return ret; - printf("Page 0x%x: %s\n", i, rfid_hexdump(buf, 4)); + printf("Page 0x%x: %s\n", i, rfid_hexdump(buf, len)); } return 0; } @@ -319,12 +320,12 @@ int main(int argc, char **argv) #endif break; case RFID_PROTOCOL_MIFARE_CLASSIC: - rc = mfcl_set_key(ph, MIFARE_CL_KEYB_DEFAULT); + rc = mfcl_set_key(ph, MIFARE_CL_KEYA_DEFAULT_INFINEON); if (rc < 0) { printf("key format error\n"); exit(1); } - rc = mfcl_auth(ph, RFID_CMD_MIFARE_AUTH1B, 10); + rc = mfcl_auth(ph, RFID_CMD_MIFARE_AUTH1A, 0); if (rc < 0) { printf("mifare auth error\n"); exit(1); |