From 1fcc35aad699f3d40ca786b99c7255cf8aa55892 Mon Sep 17 00:00:00 2001 From: laforge Date: Tue, 8 Nov 2005 13:04:32 +0000 Subject: move include directory for pkginclude compliance git-svn-id: https://svn.gnumonks.org/trunk/librfid@1664 e0336214-984f-0b4b-a45f-81c69e1f0ede --- include/Makefile.am | 2 +- include/librfid/Makefile.am | 10 + include/librfid/rfid.h | 26 ++ include/librfid/rfid_asic.h | 45 +++ include/librfid/rfid_asic_rc632.h | 160 ++++++++++ include/librfid/rfid_layer2.h | 76 +++++ include/librfid/rfid_layer2_iso14443a.h | 84 ++++++ include/librfid/rfid_layer2_iso14443b.h | 85 ++++++ include/librfid/rfid_layer2_iso15693.h | 55 ++++ include/librfid/rfid_protocol.h | 88 ++++++ include/librfid/rfid_protocol_mifare_classic.h | 28 ++ include/librfid/rfid_protocol_mifare_ul.h | 24 ++ include/librfid/rfid_protocol_tcl.h | 70 +++++ include/librfid/rfid_reader.h | 67 +++++ include/librfid/rfid_reader_cm5121.h | 21 ++ include/rfid/Makefile.am | 10 - include/rfid/rfid.h | 26 -- include/rfid/rfid_asic.h | 45 --- include/rfid/rfid_asic_rc632.h | 160 ---------- include/rfid/rfid_layer2.h | 76 ----- include/rfid/rfid_layer2_iso14443a.h | 84 ------ include/rfid/rfid_layer2_iso14443b.h | 85 ------ include/rfid/rfid_layer2_iso15693.h | 55 ---- include/rfid/rfid_protocol.h | 88 ------ include/rfid/rfid_protocol_mifare_classic.h | 28 -- include/rfid/rfid_protocol_mifare_ul.h | 24 -- include/rfid/rfid_protocol_tcl.h | 70 ----- include/rfid/rfid_reader.h | 67 ----- include/rfid/rfid_reader_cm5121.h | 21 -- src/rfid.c | 10 +- src/rfid_asic_rc632.c | 12 +- src/rfid_asic_rc632_14443a.c | 394 ------------------------- src/rfid_asic_rc632_14443b.c | 69 ----- src/rfid_asic_rc632_mifare.c | 25 -- src/rfid_layer2.c | 4 +- src/rfid_layer2_iso14443a.c | 8 +- src/rfid_layer2_iso14443b.c | 8 +- src/rfid_layer2_iso15693.c | 8 +- src/rfid_proto_mifare_classic.c | 10 +- src/rfid_proto_mifare_ul.c | 8 +- src/rfid_proto_tcl.c | 16 +- src/rfid_protocol.c | 4 +- src/rfid_reader.c | 4 +- src/rfid_reader_cm5121.c | 10 +- src/rfid_reader_cm5121_ccid_direct.c | 2 +- src/rfid_reader_cm5121_openct.c | 2 +- utils/openct-escape.c | 20 +- 47 files changed, 903 insertions(+), 1391 deletions(-) create mode 100644 include/librfid/Makefile.am create mode 100644 include/librfid/rfid.h create mode 100644 include/librfid/rfid_asic.h create mode 100644 include/librfid/rfid_asic_rc632.h create mode 100644 include/librfid/rfid_layer2.h create mode 100644 include/librfid/rfid_layer2_iso14443a.h create mode 100644 include/librfid/rfid_layer2_iso14443b.h create mode 100644 include/librfid/rfid_layer2_iso15693.h create mode 100644 include/librfid/rfid_protocol.h create mode 100644 include/librfid/rfid_protocol_mifare_classic.h create mode 100644 include/librfid/rfid_protocol_mifare_ul.h create mode 100644 include/librfid/rfid_protocol_tcl.h create mode 100644 include/librfid/rfid_reader.h create mode 100644 include/librfid/rfid_reader_cm5121.h delete mode 100644 include/rfid/Makefile.am delete mode 100644 include/rfid/rfid.h delete mode 100644 include/rfid/rfid_asic.h delete mode 100644 include/rfid/rfid_asic_rc632.h delete mode 100644 include/rfid/rfid_layer2.h delete mode 100644 include/rfid/rfid_layer2_iso14443a.h delete mode 100644 include/rfid/rfid_layer2_iso14443b.h delete mode 100644 include/rfid/rfid_layer2_iso15693.h delete mode 100644 include/rfid/rfid_protocol.h delete mode 100644 include/rfid/rfid_protocol_mifare_classic.h delete mode 100644 include/rfid/rfid_protocol_mifare_ul.h delete mode 100644 include/rfid/rfid_protocol_tcl.h delete mode 100644 include/rfid/rfid_reader.h delete mode 100644 include/rfid/rfid_reader_cm5121.h delete mode 100644 src/rfid_asic_rc632_14443a.c delete mode 100644 src/rfid_asic_rc632_14443b.c delete mode 100644 src/rfid_asic_rc632_mifare.c diff --git a/include/Makefile.am b/include/Makefile.am index df5706a..dfaa277 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,2 +1,2 @@ -SUBDIRS = rfid +SUBDIRS = librfid diff --git a/include/librfid/Makefile.am b/include/librfid/Makefile.am new file mode 100644 index 0000000..59ce8cb --- /dev/null +++ b/include/librfid/Makefile.am @@ -0,0 +1,10 @@ + +pkginclude_HEADERS = rfid.h rfid_asic.h rfid_asic_rc632.h \ + rfid_layer2.h rfid_layer2_iso14443a.h \ + rfid_layer2_iso14443b.h rfid_layer2_iso15693.h \ + rfid_protocol.h rfid_protocol_tcl.h \ + rfid_protocol_mifare_ul.h \ + rfid_protocol_mifare_classic.h \ + rfid_reader.h \ + rfid_reader_cm5121.h + diff --git a/include/librfid/rfid.h b/include/librfid/rfid.h new file mode 100644 index 0000000..6717ef8 --- /dev/null +++ b/include/librfid/rfid.h @@ -0,0 +1,26 @@ +#ifndef _RFID_H +#define _RFID_H + +#include + +#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); + +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#endif + +#endif /* __LIBRFID__ */ + +int rfid_init(); + +#endif /* _RFID_H */ diff --git a/include/librfid/rfid_asic.h b/include/librfid/rfid_asic.h new file mode 100644 index 0000000..3686a7c --- /dev/null +++ b/include/librfid/rfid_asic.h @@ -0,0 +1,45 @@ +#ifndef _RFID_ASIC_H +#define _RFID_ASIC_H + +enum rfid_frametype; + +#include + +struct rfid_asic_transport { + char *name; + union { + struct rfid_asic_rc632_transport rc632; + } priv; +}; + +struct rfid_asic_transport_handle { + void *data; /* handle to stuff like even lower layers */ + + struct rfid_asic_transport *rat; +}; + + +struct rfid_asic_handle { + struct rfid_asic_transport_handle *rath; + unsigned int fc; + unsigned int mtu; + unsigned int mru; + + union { + struct rfid_asic_rc632_handle rc632; + //struct rfid_asic_rc531_handle rc531; + } priv; + struct rfid_asic *asic; +}; + + +struct rfid_asic { + char *name; + unsigned int fc; /* carrier frequency */ + union { + struct rfid_asic_rc632 rc632; + //struct rfid_asic_rc531 rc531; + } priv; +}; + +#endif /* _RFID_ASIC_H */ diff --git a/include/librfid/rfid_asic_rc632.h b/include/librfid/rfid_asic_rc632.h new file mode 100644 index 0000000..893e73b --- /dev/null +++ b/include/librfid/rfid_asic_rc632.h @@ -0,0 +1,160 @@ +#ifndef _RFID_ASIC_RC632_H +#define _RFID_ASIC_RC632_H + +struct rfid_asic_transport_handle; + +#include +#include + +struct rfid_asic_rc632_transport { + struct { + int (*reg_write)(struct rfid_asic_transport_handle *rath, + u_int8_t reg, + u_int8_t value); + int (*reg_read)(struct rfid_asic_transport_handle *rath, + u_int8_t reg, + u_int8_t *value); + int (*fifo_write)(struct rfid_asic_transport_handle *rath, + u_int8_t len, + const u_int8_t *buf, + u_int8_t flags); + int (*fifo_read)(struct rfid_asic_transport_handle *rath, + u_int8_t len, + u_int8_t *buf); + } fn; +}; + +struct rfid_asic_handle; + +struct iso14443a_atqa; +struct iso14443a_anticol_cmd; + +struct rfid_asic_rc632 { + struct { + int (*power_up)(struct rfid_asic_handle *h); + int (*power_down)(struct rfid_asic_handle *h); + int (*turn_on_rf)(struct rfid_asic_handle *h); + int (*turn_off_rf)(struct rfid_asic_handle *h); + int (*transcieve)(struct rfid_asic_handle *h, + enum rfid_frametype, + const u_int32_t *tx_buf, + unsigned int tx_len, + u_int32_t *rx_buf, + unsigned int *rx_len, + u_int64_t timeout, + unsigned int flags); + struct { + int (*init)(struct rfid_asic_handle *h); + int (*transcieve_sf)(struct rfid_asic_handle *h, + u_int32_t cmd, + struct iso14443a_atqa *atqa); + 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 tx, + unsigned int speed); + } iso14443a; + struct { + int (*init)(struct rfid_asic_handle *h); + } iso14443b; + struct { + int (*init)(struct rfid_asic_handle *h); + } iso15693; + struct { + int (*setkey)(struct rfid_asic_handle *h, + const unsigned char *key); + int (*auth)(struct rfid_asic_handle *h, u_int8_t cmd, + u_int32_t serno, u_int8_t block); + } mifare_classic; + } fn; +}; + +struct rc632_transport_handle { +}; + +/* A handle to a specific RC632 chip */ +struct rfid_asic_rc632_handle { + struct rc632_transport_handle th; +}; + +#if 0 +int +rc632_reg_write(struct rfid_asic_handle *handle, + u_int8_t reg, + u_int8_t val); + +int +rc632_reg_read(struct rfid_asic_handle *handle, + u_int8_t reg, + u_int8_t *val); +int +rc632_fifo_write(struct rfid_asic_handle *handle, + u_int8_t len, + const u_int32_t *buf, + u_int8_t flags); + +int +rc632_fifo_read(struct rfid_asic_handle *handle, + u_int8_t len, + u_int8_t *buf); + +int +rc632_set_bits(struct rfid_asic_handle *handle, u_int8_t reg, + u_int82_t val); + +int +rc632_clear_bits(struct rfid_asic_handle *handle, u_int32_t reg, + u_int32_t val); + + +int +rc632_turn_on_rf(struct rfid_asic_handle *handle); + + +int +rc632_turn_off_rf(struct rfid_asic_handle *handle); + +int +rc632_power_up(struct rfid_asic_handle *handle); + +int +rc632_power_down(struct rfid_asic_handle *handle); + + +int +rc632_wait_idle(struct rfid_asic_handle *handle, u_int64_t time); + +int +rc632_transmit(struct rfid_asic_handle *handle, + const u_int32_t *buf, + u_int32_t len, + u_int64_t timeout); + +int +rc632_transcieve(struct rfid_asic_handle *handle, + const u_int32_t *tx_buf, + u_int32_t tx_len, + u_int32_t *rx_buf, + u_int32_t *rx_len, + unsigned int timer, + unsigned int toggle); + +int +rc632_read_eeprom(struct rfid_asic_handle *handle); + + +int +rc632_calc_crc16_from(struct rfid_asic_handle *handle); + +int +rc632_register_dump(struct rfid_asic_handle *handle, u_int32_t *buf); + + +struct rfid_asic_handle * rc632_open(struct rfid_asic_transport_handle *th); + + +extern struct rfid_asic rc632; +#endif + +#endif diff --git a/include/librfid/rfid_layer2.h b/include/librfid/rfid_layer2.h new file mode 100644 index 0000000..4622a02 --- /dev/null +++ b/include/librfid/rfid_layer2.h @@ -0,0 +1,76 @@ +#ifndef _RFID_LAYER2_H +#define _RFID_LAYER2_H + +#include +#include + +struct rfid_layer2_handle; +struct rfid_reader_handle; + +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 +#include +#include + +struct rfid_layer2 { + unsigned int id; + char *name; + + struct { + struct rfid_layer2_handle *(*init)(struct rfid_reader_handle *h); + int (*open)(struct rfid_layer2_handle *h); + int (*transcieve)(struct rfid_layer2_handle *h, + 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 (*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; +}; + +struct rfid_layer2_handle { + struct rfid_reader_handle *rh; + unsigned char uid[10]; /* triple size 14443a id is 10 bytes */ + unsigned int uid_len; + union { + struct iso14443a_handle iso14443a; + struct iso14443b_handle iso14443b; + struct iso15693_handle iso15693; + } priv; + struct rfid_layer2 *l2; +}; + +#endif /* __LIBRFID__ */ + +#endif diff --git a/include/librfid/rfid_layer2_iso14443a.h b/include/librfid/rfid_layer2_iso14443a.h new file mode 100644 index 0000000..50a6f43 --- /dev/null +++ b/include/librfid/rfid_layer2_iso14443a.h @@ -0,0 +1,84 @@ +#ifndef _RFID_ISO14443A_H +#define _RFID_ISO14443A_H + +enum rfid_14443a_opt { + RFID_OPT_14443A_SPEED_RX = 0x00000001, + RFID_OPT_14443A_SPEED_TX = 0x00000002, +}; + +enum rfid_14443_opt_speed { + RFID_14443A_SPEED_106K = 0x01, + RFID_14443A_SPEED_212K = 0x02, + RFID_14443A_SPEED_424K = 0x04, + RFID_14443A_SPEED_848K = 0x08, +}; + +#ifdef __LIBRFID__ + +#include + +/* protocol definitions */ + +/* ISO 14443-3, Chapter 6.3.1 */ +enum iso14443a_sf_cmd { + ISO14443A_SF_CMD_REQA = 0x26, + ISO14443A_SF_CMD_WUPA = 0x52, + ISO14443A_SF_CMD_OPT_TIMESLOT = 0x35, /* Annex C */ + /* 40 to 4f and 78 to 7f: proprietary */ +}; + +struct iso14443a_atqa { + u_int8_t bf_anticol:5, + rfu1:1, + uid_size:2; + u_int8_t proprietary:4, + rfu2:4; +}; + +#define ISO14443A_HLTA 0x5000 + +/* ISO 14443-3, Chapter 6.3.2 */ +struct iso14443a_anticol_cmd { + unsigned char sel_code; + unsigned char nvb; + unsigned char uid_bits[5]; +}; + +enum iso14443a_anticol_sel_code { + ISO14443A_AC_SEL_CODE_CL1 = 0x93, + ISO14443A_AC_SEL_CODE_CL2 = 0x95, + ISO14443A_AC_SEL_CODE_CL3 = 0x97, +}; + +#define ISO14443A_BITOFCOL_NONE 0xffffffff + +struct iso14443a_handle { + unsigned int state; + unsigned int level; + unsigned int tcl_capable; +}; + +enum iso14443a_level { + ISO14443A_LEVEL_NONE, + ISO14443A_LEVEL_CL1, + ISO14443A_LEVEL_CL2, + ISO14443A_LEVEL_CL3, +}; + +enum iso14443a_state { + ISO14443A_STATE_ERROR, + ISO14443A_STATE_NONE, + ISO14443A_STATE_REQA_SENT, + ISO14443A_STATE_ATQA_RCVD, + ISO14443A_STATE_NO_BITFRAME_ANTICOL, + ISO14443A_STATE_ANTICOL_RUNNING, + ISO14443A_STATE_SELECTED, +}; + +#include +struct rfid_layer2 rfid_layer2_iso14443a; + +#endif /* __LIBRFID__ */ + + +#endif /* _ISO14443A_H */ diff --git a/include/librfid/rfid_layer2_iso14443b.h b/include/librfid/rfid_layer2_iso14443b.h new file mode 100644 index 0000000..5d6d979 --- /dev/null +++ b/include/librfid/rfid_layer2_iso14443b.h @@ -0,0 +1,85 @@ +#ifndef _RFID_LAYER2_ISO14443B_H +#define _RFID_LAYER2_ISO14443B_H + +#ifdef __LIBRFID__ + +struct iso14443b_atqb { + unsigned char fifty; + unsigned char pupi[4]; + unsigned char app_data[4]; + struct { + unsigned char bit_rate_capability; + unsigned char protocol_type:4, + max_frame_size:4; + unsigned char fo:2, + adc:2, + fwi:4; + } protocol_info; +}; + +struct iso14443b_attrib_hdr { + unsigned char one_d; + unsigned char identifier[4]; + struct { + unsigned char rfu:2, + sof:1, + eof:1, + min_tr1:2, + min_tr0:2; + } param1; + struct { + unsigned char fsdi:4, + spd_out:2, + spd_in:2; + } param2; + struct { + unsigned char protocol_type:4, + rfu:4; + } param3; + struct { + unsigned char cid:4, + rfu:4; + } param4; +}; + +struct iso14443b_handle { + unsigned int tcl_capable; /* do we support T=CL */ + + unsigned int cid; /* Card ID */ + + unsigned int fsc; /* max. frame size card */ + unsigned int fsd; /* max. frame size reader */ + + unsigned int fwt; /* frame waiting time (in usec) */ + + unsigned int mbl; /* maximum buffer length */ + + unsigned int tr0; /* pcd-eof to picc-subcarrier-on */ + unsigned int tr1; /* picc-subcarrier-on to picc-sof */ + + unsigned int flags; + unsigned int state; +}; + +enum { + ISO14443B_CID_SUPPORTED = 0x01, + ISO14443B_NAD_SUPPORTED = 0x02, +}; + +enum { + ISO14443B_STATE_ERROR, + ISO14443B_STATE_NONE, + ISO14443B_STATE_REQB_SENT, + ISO14443B_STATE_ATQB_RCVD, + ISO14443B_STATE_ATTRIB_SENT, + ISO14443B_STATE_SELECTED, + ISO14443B_STATE_HLTB_SENT, + ISO14443B_STATE_HALTED, +}; + +#include +struct rfid_layer2 rfid_layer2_iso14443b; + +#endif /* __LIBRFID__ */ + +#endif diff --git a/include/librfid/rfid_layer2_iso15693.h b/include/librfid/rfid_layer2_iso15693.h new file mode 100644 index 0000000..ea7f87a --- /dev/null +++ b/include/librfid/rfid_layer2_iso15693.h @@ -0,0 +1,55 @@ +#ifndef _RFID_ISO15693_H +#define _RFID_ISO15693_H + +#include + +/* +07h = TagIt +04h = I.CODE +05h = Infineon +02h = ST +*/ + +/* protocol definitions */ + +struct iso15693_handle; + +struct iso15693_transport { + unsigned char *name; + + struct { + int (*init)(struct iso15693_handle *handle); + int (*fini)(struct iso15693_handle *handle); + +#if 0 + 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); +#endif + int (*transcieve)(struct iso15693_handle *handle, + const unsigned char *tx_buf, + unsigned int tx_len, + unsigned char *rx_buf, + unsigned int *rx_len); + } fn; + + union { + } priv; +}; + +struct iso15693_handle { + unsigned int state; +}; + +enum iso15693_state { + ISO15693_STATE_ERROR, + ISO15693_STATE_NONE, +}; + +#include +extern struct rfid_layer2 rfid_layer2_iso15693; + +#endif /* _ISO15693_H */ diff --git a/include/librfid/rfid_protocol.h b/include/librfid/rfid_protocol.h new file mode 100644 index 0000000..65bda4c --- /dev/null +++ b/include/librfid/rfid_protocol.h @@ -0,0 +1,88 @@ +#ifndef _RFID_PROTOCOL_H +#define _RFID_PROTOCOL_H + +#include + +struct rfid_protocol_handle; + +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; + unsigned int id; + char *name; + struct { + struct rfid_protocol_handle *(*init)(struct rfid_layer2_handle *l2h); + int (*open)(struct rfid_protocol_handle *ph); + int (*close)(struct rfid_protocol_handle *ph); + int (*fini)(struct rfid_protocol_handle *ph); + /* transcieve for session based transport protocols */ + int (*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); + /* read/write for synchronous memory cards */ + int (*read)(struct rfid_protocol_handle *ph, + unsigned int page, + unsigned char *rx_data, + unsigned int *rx_len); + int (*write)(struct rfid_protocol_handle *ph, + unsigned int page, + unsigned char *tx_data, + unsigned int tx_len); + } fn; +}; + +int rfid_protocol_register(struct rfid_protocol *p); + +#include +#include +#include + +struct rfid_protocol_handle { + struct rfid_layer2_handle *l2h; + struct rfid_protocol *proto; + union { + struct tcl_handle tcl; + } priv; /* priv has to be last, since + * it could contain additional + * private data over the end of + * sizeof(priv). */ +}; + +#endif /* __LIBRFID__ */ + +#endif /* _RFID_PROTOCOL_H */ diff --git a/include/librfid/rfid_protocol_mifare_classic.h b/include/librfid/rfid_protocol_mifare_classic.h new file mode 100644 index 0000000..e6b2400 --- /dev/null +++ b/include/librfid/rfid_protocol_mifare_classic.h @@ -0,0 +1,28 @@ +#ifndef _MIFARE_CLASSIC_H + +#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 + + +#endif /* __LIBRFID__ */ + +#endif /* _MIFARE_CLASSIC_H */ diff --git a/include/librfid/rfid_protocol_mifare_ul.h b/include/librfid/rfid_protocol_mifare_ul.h new file mode 100644 index 0000000..cc93b6b --- /dev/null +++ b/include/librfid/rfid_protocol_mifare_ul.h @@ -0,0 +1,24 @@ +#ifndef _RFID_PROTOCOL_MFUL_H +#define _RFID_PROTOCOL_MFUL_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 + +#define MIFARE_UL_RESP_ACK 0x0a +#define MIFARE_UL_RESP_NAK 0x00 + +#define MIFARE_UL_PAGE_LOCK 2 +#define MIFARE_UL_PAGE_OTP 3 + +extern struct rfid_protocol rfid_protocol_mful; + +#endif /* __LIBRFID__ */ + +#endif diff --git a/include/librfid/rfid_protocol_tcl.h b/include/librfid/rfid_protocol_tcl.h new file mode 100644 index 0000000..f754ad9 --- /dev/null +++ b/include/librfid/rfid_protocol_tcl.h @@ -0,0 +1,70 @@ +#ifndef _RFID_PROTOCOL_TCL_H +#define _RFID_PROTOCOL_TCL_H + +#ifdef __LIBRFID__ + +enum tcl_transport_rate { + TCL_RATE_106 = 0x01, + TCL_RATE_212 = 0x02, + TCL_RATE_424 = 0x04, + TCL_RATE_848 = 0x08, +}; + +enum tcl_transport_transcieve_flags { + TCL_TRANSP_F_TX_CRC = 0x01, /* transport adds TX CRC */ + TCL_TRANSP_F_RX_CRC = 0x02, +}; + +struct tcl_handle { + /* derived from ats */ + unsigned char *historical_bytes; /* points into ats */ + unsigned int historical_len; + + unsigned int fsc; /* max frame size accepted by card */ + unsigned int fsd; /* max frame size accepted by reader */ + unsigned int fwt; /* frame waiting time (in usec)*/ + unsigned char ta; /* divisor information */ + unsigned char sfgt; /* start-up frame guard time (in usec) */ + + /* otherwise determined */ + unsigned int cid; /* Card ID */ + unsigned int nad; /* Node Address */ + + unsigned int flags; + unsigned int state; /* protocol state */ + + unsigned int toggle; /* send toggle with next frame */ + + unsigned int ats_len; + unsigned char ats[0]; +}; + +enum tcl_handle_flags { + TCL_HANDLE_F_NAD_SUPPORTED = 0x0001, + TCL_HANDLE_F_CID_SUPPORTED = 0x0002, + TCL_HANDLE_F_NAD_USED = 0x0010, + TCL_HANDLE_F_CID_USED = 0x0020, +}; + + +enum tcl_pcb_bits { + TCL_PCB_CID_FOLLOWING = 0x08, + TCL_PCB_NAD_FOLLOWING = 0x04, +}; + +enum tcl_pcd_state { + TCL_STATE_NONE = 0x00, + TCL_STATE_INITIAL, + TCL_STATE_RATS_SENT, /* waiting for ATS */ + TCL_STATE_ATS_RCVD, /* ATS received */ + TCL_STATE_PPS_SENT, /* waiting for PPS response */ + TCL_STATE_ESTABLISHED, /* xchg transparent data */ + TCL_STATE_DESELECT_SENT, /* waiting for DESELECT response */ + TCL_STATE_DESELECTED, /* card deselected or HLTA'd */ +}; + +struct rfid_protocol rfid_protocol_tcl; + +#endif /* __LIBRFID__ */ + +#endif diff --git a/include/librfid/rfid_reader.h b/include/librfid/rfid_reader.h new file mode 100644 index 0000000..3581cc1 --- /dev/null +++ b/include/librfid/rfid_reader.h @@ -0,0 +1,67 @@ +#ifndef _RFID_READER_H +#define _RFID_READER_H + +#include +#include + +struct rfid_reader_handle; + +struct rfid_reader { + char *name; + unsigned int id; + int (*transcieve)(struct rfid_reader_handle *h, + 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); + struct rfid_reader_handle * (*open)(void *data); + void (*close)(struct rfid_reader_handle *h); + + struct rfid_14443a_reader { + int (*init)(struct rfid_reader_handle *h); + int (*transcieve_sf)(struct rfid_reader_handle *h, + unsigned char cmd, + struct iso14443a_atqa *atqa); + 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 tx, + unsigned int speed); + unsigned int speed; + } iso14443a; + struct rfid_14443b_reader { + int (*init)(struct rfid_reader_handle *rh); + unsigned int speed; + } iso14443b; + struct rfid_15693_reader { + int (*init)(struct rfid_reader_handle *rh); + } iso15693; + struct rfid_mifare_classic_reader { + int (*setkey)(struct rfid_reader_handle *h, unsigned char *key); + int (*auth)(struct rfid_reader_handle *h, u_int8_t cmd, + u_int32_t serno, u_int8_t block); + } mifare_classic; + struct rfid_reader *next; +}; + +enum rfid_reader_id { + RFID_READER_CM5121, + RFID_READER_PEGODA, +}; + +struct rfid_reader_handle { + struct rfid_asic_handle *ah; + + union { + + } priv; + struct rfid_reader *reader; +}; + + +extern struct rfid_reader_handle * +rfid_reader_open(void *data, unsigned int id); + +extern void rfid_reader_close(struct rfid_reader_handle *rh); +#endif diff --git a/include/librfid/rfid_reader_cm5121.h b/include/librfid/rfid_reader_cm5121.h new file mode 100644 index 0000000..8d9a312 --- /dev/null +++ b/include/librfid/rfid_reader_cm5121.h @@ -0,0 +1,21 @@ +#ifndef _RFID_READER_CM5121_H +#define _RFID_READER_CM5121_H + +#define CM5121_CW_CONDUCTANCE 0x3f +#define CM5121_MOD_CONDUCTANCE 0x3f +#define CM5121_14443A_BITPHASE 0xa9 +#define CM5121_14443A_THRESHOLD 0xff + +#define CM5121_14443B_BITPHASE 0xad +#define CM5121_14443B_THRESHOLD 0xff + + +extern int +PC_to_RDR_Escape(void *handle, + const unsigned char *tx_buf, unsigned int tx_len, + unsigned char *rx_buf, unsigned int *rx_len); + +extern struct rfid_reader rfid_reader_cm5121; +// extern struct rfid_asic_transport cm5121_ccid; + +#endif diff --git a/include/rfid/Makefile.am b/include/rfid/Makefile.am deleted file mode 100644 index 59ce8cb..0000000 --- a/include/rfid/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ - -pkginclude_HEADERS = rfid.h rfid_asic.h rfid_asic_rc632.h \ - rfid_layer2.h rfid_layer2_iso14443a.h \ - rfid_layer2_iso14443b.h rfid_layer2_iso15693.h \ - rfid_protocol.h rfid_protocol_tcl.h \ - rfid_protocol_mifare_ul.h \ - rfid_protocol_mifare_classic.h \ - rfid_reader.h \ - rfid_reader_cm5121.h - diff --git a/include/rfid/rfid.h b/include/rfid/rfid.h deleted file mode 100644 index 6717ef8..0000000 --- a/include/rfid/rfid.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef _RFID_H -#define _RFID_H - -#include - -#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); - -#ifndef ARRAY_SIZE -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) -#endif - -#endif /* __LIBRFID__ */ - -int rfid_init(); - -#endif /* _RFID_H */ diff --git a/include/rfid/rfid_asic.h b/include/rfid/rfid_asic.h deleted file mode 100644 index 6511615..0000000 --- a/include/rfid/rfid_asic.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef _RFID_ASIC_H -#define _RFID_ASIC_H - -enum rfid_frametype; - -#include - -struct rfid_asic_transport { - char *name; - union { - struct rfid_asic_rc632_transport rc632; - } priv; -}; - -struct rfid_asic_transport_handle { - void *data; /* handle to stuff like even lower layers */ - - struct rfid_asic_transport *rat; -}; - - -struct rfid_asic_handle { - struct rfid_asic_transport_handle *rath; - unsigned int fc; - unsigned int mtu; - unsigned int mru; - - union { - struct rfid_asic_rc632_handle rc632; - //struct rfid_asic_rc531_handle rc531; - } priv; - struct rfid_asic *asic; -}; - - -struct rfid_asic { - char *name; - unsigned int fc; /* carrier frequency */ - union { - struct rfid_asic_rc632 rc632; - //struct rfid_asic_rc531 rc531; - } priv; -}; - -#endif /* _RFID_ASIC_H */ diff --git a/include/rfid/rfid_asic_rc632.h b/include/rfid/rfid_asic_rc632.h deleted file mode 100644 index e156814..0000000 --- a/include/rfid/rfid_asic_rc632.h +++ /dev/null @@ -1,160 +0,0 @@ -#ifndef _RFID_ASIC_RC632_H -#define _RFID_ASIC_RC632_H - -struct rfid_asic_transport_handle; - -#include -#include - -struct rfid_asic_rc632_transport { - struct { - int (*reg_write)(struct rfid_asic_transport_handle *rath, - u_int8_t reg, - u_int8_t value); - int (*reg_read)(struct rfid_asic_transport_handle *rath, - u_int8_t reg, - u_int8_t *value); - int (*fifo_write)(struct rfid_asic_transport_handle *rath, - u_int8_t len, - const u_int8_t *buf, - u_int8_t flags); - int (*fifo_read)(struct rfid_asic_transport_handle *rath, - u_int8_t len, - u_int8_t *buf); - } fn; -}; - -struct rfid_asic_handle; - -struct iso14443a_atqa; -struct iso14443a_anticol_cmd; - -struct rfid_asic_rc632 { - struct { - int (*power_up)(struct rfid_asic_handle *h); - int (*power_down)(struct rfid_asic_handle *h); - int (*turn_on_rf)(struct rfid_asic_handle *h); - int (*turn_off_rf)(struct rfid_asic_handle *h); - int (*transcieve)(struct rfid_asic_handle *h, - enum rfid_frametype, - const u_int32_t *tx_buf, - unsigned int tx_len, - u_int32_t *rx_buf, - unsigned int *rx_len, - u_int64_t timeout, - unsigned int flags); - struct { - int (*init)(struct rfid_asic_handle *h); - int (*transcieve_sf)(struct rfid_asic_handle *h, - u_int32_t cmd, - struct iso14443a_atqa *atqa); - 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 tx, - unsigned int speed); - } iso14443a; - struct { - int (*init)(struct rfid_asic_handle *h); - } iso14443b; - struct { - int (*init)(struct rfid_asic_handle *h); - } iso15693; - struct { - int (*setkey)(struct rfid_asic_handle *h, - const unsigned char *key); - int (*auth)(struct rfid_asic_handle *h, u_int8_t cmd, - u_int32_t serno, u_int8_t block); - } mifare_classic; - } fn; -}; - -struct rc632_transport_handle { -}; - -/* A handle to a specific RC632 chip */ -struct rfid_asic_rc632_handle { - struct rc632_transport_handle th; -}; - -#if 0 -int -rc632_reg_write(struct rfid_asic_handle *handle, - u_int8_t reg, - u_int8_t val); - -int -rc632_reg_read(struct rfid_asic_handle *handle, - u_int8_t reg, - u_int8_t *val); -int -rc632_fifo_write(struct rfid_asic_handle *handle, - u_int8_t len, - const u_int32_t *buf, - u_int8_t flags); - -int -rc632_fifo_read(struct rfid_asic_handle *handle, - u_int8_t len, - u_int8_t *buf); - -int -rc632_set_bits(struct rfid_asic_handle *handle, u_int8_t reg, - u_int82_t val); - -int -rc632_clear_bits(struct rfid_asic_handle *handle, u_int32_t reg, - u_int32_t val); - - -int -rc632_turn_on_rf(struct rfid_asic_handle *handle); - - -int -rc632_turn_off_rf(struct rfid_asic_handle *handle); - -int -rc632_power_up(struct rfid_asic_handle *handle); - -int -rc632_power_down(struct rfid_asic_handle *handle); - - -int -rc632_wait_idle(struct rfid_asic_handle *handle, u_int64_t time); - -int -rc632_transmit(struct rfid_asic_handle *handle, - const u_int32_t *buf, - u_int32_t len, - u_int64_t timeout); - -int -rc632_transcieve(struct rfid_asic_handle *handle, - const u_int32_t *tx_buf, - u_int32_t tx_len, - u_int32_t *rx_buf, - u_int32_t *rx_len, - unsigned int timer, - unsigned int toggle); - -int -rc632_read_eeprom(struct rfid_asic_handle *handle); - - -int -rc632_calc_crc16_from(struct rfid_asic_handle *handle); - -int -rc632_register_dump(struct rfid_asic_handle *handle, u_int32_t *buf); - - -struct rfid_asic_handle * rc632_open(struct rfid_asic_transport_handle *th); - - -extern struct rfid_asic rc632; -#endif - -#endif diff --git a/include/rfid/rfid_layer2.h b/include/rfid/rfid_layer2.h deleted file mode 100644 index 54c3c46..0000000 --- a/include/rfid/rfid_layer2.h +++ /dev/null @@ -1,76 +0,0 @@ -#ifndef _RFID_LAYER2_H -#define _RFID_LAYER2_H - -#include -#include - -struct rfid_layer2_handle; -struct rfid_reader_handle; - -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 -#include -#include - -struct rfid_layer2 { - unsigned int id; - char *name; - - struct { - struct rfid_layer2_handle *(*init)(struct rfid_reader_handle *h); - int (*open)(struct rfid_layer2_handle *h); - int (*transcieve)(struct rfid_layer2_handle *h, - 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 (*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; -}; - -struct rfid_layer2_handle { - struct rfid_reader_handle *rh; - unsigned char uid[10]; /* triple size 14443a id is 10 bytes */ - unsigned int uid_len; - union { - struct iso14443a_handle iso14443a; - struct iso14443b_handle iso14443b; - struct iso15693_handle iso15693; - } priv; - struct rfid_layer2 *l2; -}; - -#endif /* __LIBRFID__ */ - -#endif diff --git a/include/rfid/rfid_layer2_iso14443a.h b/include/rfid/rfid_layer2_iso14443a.h deleted file mode 100644 index fc79bca..0000000 --- a/include/rfid/rfid_layer2_iso14443a.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef _RFID_ISO14443A_H -#define _RFID_ISO14443A_H - -enum rfid_14443a_opt { - RFID_OPT_14443A_SPEED_RX = 0x00000001, - RFID_OPT_14443A_SPEED_TX = 0x00000002, -}; - -enum rfid_14443_opt_speed { - RFID_14443A_SPEED_106K = 0x01, - RFID_14443A_SPEED_212K = 0x02, - RFID_14443A_SPEED_424K = 0x04, - RFID_14443A_SPEED_848K = 0x08, -}; - -#ifdef __LIBRFID__ - -#include - -/* protocol definitions */ - -/* ISO 14443-3, Chapter 6.3.1 */ -enum iso14443a_sf_cmd { - ISO14443A_SF_CMD_REQA = 0x26, - ISO14443A_SF_CMD_WUPA = 0x52, - ISO14443A_SF_CMD_OPT_TIMESLOT = 0x35, /* Annex C */ - /* 40 to 4f and 78 to 7f: proprietary */ -}; - -struct iso14443a_atqa { - u_int8_t bf_anticol:5, - rfu1:1, - uid_size:2; - u_int8_t proprietary:4, - rfu2:4; -}; - -#define ISO14443A_HLTA 0x5000 - -/* ISO 14443-3, Chapter 6.3.2 */ -struct iso14443a_anticol_cmd { - unsigned char sel_code; - unsigned char nvb; - unsigned char uid_bits[5]; -}; - -enum iso14443a_anticol_sel_code { - ISO14443A_AC_SEL_CODE_CL1 = 0x93, - ISO14443A_AC_SEL_CODE_CL2 = 0x95, - ISO14443A_AC_SEL_CODE_CL3 = 0x97, -}; - -#define ISO14443A_BITOFCOL_NONE 0xffffffff - -struct iso14443a_handle { - unsigned int state; - unsigned int level; - unsigned int tcl_capable; -}; - -enum iso14443a_level { - ISO14443A_LEVEL_NONE, - ISO14443A_LEVEL_CL1, - ISO14443A_LEVEL_CL2, - ISO14443A_LEVEL_CL3, -}; - -enum iso14443a_state { - ISO14443A_STATE_ERROR, - ISO14443A_STATE_NONE, - ISO14443A_STATE_REQA_SENT, - ISO14443A_STATE_ATQA_RCVD, - ISO14443A_STATE_NO_BITFRAME_ANTICOL, - ISO14443A_STATE_ANTICOL_RUNNING, - ISO14443A_STATE_SELECTED, -}; - -#include -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 deleted file mode 100644 index 2bf8255..0000000 --- a/include/rfid/rfid_layer2_iso14443b.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef _RFID_LAYER2_ISO14443B_H -#define _RFID_LAYER2_ISO14443B_H - -#ifdef __LIBRFID__ - -struct iso14443b_atqb { - unsigned char fifty; - unsigned char pupi[4]; - unsigned char app_data[4]; - struct { - unsigned char bit_rate_capability; - unsigned char protocol_type:4, - max_frame_size:4; - unsigned char fo:2, - adc:2, - fwi:4; - } protocol_info; -}; - -struct iso14443b_attrib_hdr { - unsigned char one_d; - unsigned char identifier[4]; - struct { - unsigned char rfu:2, - sof:1, - eof:1, - min_tr1:2, - min_tr0:2; - } param1; - struct { - unsigned char fsdi:4, - spd_out:2, - spd_in:2; - } param2; - struct { - unsigned char protocol_type:4, - rfu:4; - } param3; - struct { - unsigned char cid:4, - rfu:4; - } param4; -}; - -struct iso14443b_handle { - unsigned int tcl_capable; /* do we support T=CL */ - - unsigned int cid; /* Card ID */ - - unsigned int fsc; /* max. frame size card */ - unsigned int fsd; /* max. frame size reader */ - - unsigned int fwt; /* frame waiting time (in usec) */ - - unsigned int mbl; /* maximum buffer length */ - - unsigned int tr0; /* pcd-eof to picc-subcarrier-on */ - unsigned int tr1; /* picc-subcarrier-on to picc-sof */ - - unsigned int flags; - unsigned int state; -}; - -enum { - ISO14443B_CID_SUPPORTED = 0x01, - ISO14443B_NAD_SUPPORTED = 0x02, -}; - -enum { - ISO14443B_STATE_ERROR, - ISO14443B_STATE_NONE, - ISO14443B_STATE_REQB_SENT, - ISO14443B_STATE_ATQB_RCVD, - ISO14443B_STATE_ATTRIB_SENT, - ISO14443B_STATE_SELECTED, - ISO14443B_STATE_HLTB_SENT, - ISO14443B_STATE_HALTED, -}; - -#include -struct rfid_layer2 rfid_layer2_iso14443b; - -#endif /* __LIBRFID__ */ - -#endif diff --git a/include/rfid/rfid_layer2_iso15693.h b/include/rfid/rfid_layer2_iso15693.h deleted file mode 100644 index 6ca1a7b..0000000 --- a/include/rfid/rfid_layer2_iso15693.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef _RFID_ISO15693_H -#define _RFID_ISO15693_H - -#include - -/* -07h = TagIt -04h = I.CODE -05h = Infineon -02h = ST -*/ - -/* protocol definitions */ - -struct iso15693_handle; - -struct iso15693_transport { - unsigned char *name; - - struct { - int (*init)(struct iso15693_handle *handle); - int (*fini)(struct iso15693_handle *handle); - -#if 0 - 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); -#endif - int (*transcieve)(struct iso15693_handle *handle, - const unsigned char *tx_buf, - unsigned int tx_len, - unsigned char *rx_buf, - unsigned int *rx_len); - } fn; - - union { - } priv; -}; - -struct iso15693_handle { - unsigned int state; -}; - -enum iso15693_state { - ISO15693_STATE_ERROR, - ISO15693_STATE_NONE, -}; - -#include -extern struct rfid_layer2 rfid_layer2_iso15693; - -#endif /* _ISO15693_H */ diff --git a/include/rfid/rfid_protocol.h b/include/rfid/rfid_protocol.h deleted file mode 100644 index bd9570f..0000000 --- a/include/rfid/rfid_protocol.h +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef _RFID_PROTOCOL_H -#define _RFID_PROTOCOL_H - -#include - -struct rfid_protocol_handle; - -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; - unsigned int id; - char *name; - struct { - struct rfid_protocol_handle *(*init)(struct rfid_layer2_handle *l2h); - int (*open)(struct rfid_protocol_handle *ph); - int (*close)(struct rfid_protocol_handle *ph); - int (*fini)(struct rfid_protocol_handle *ph); - /* transcieve for session based transport protocols */ - int (*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); - /* read/write for synchronous memory cards */ - int (*read)(struct rfid_protocol_handle *ph, - unsigned int page, - unsigned char *rx_data, - unsigned int *rx_len); - int (*write)(struct rfid_protocol_handle *ph, - unsigned int page, - unsigned char *tx_data, - unsigned int tx_len); - } fn; -}; - -int rfid_protocol_register(struct rfid_protocol *p); - -#include -#include -#include - -struct rfid_protocol_handle { - struct rfid_layer2_handle *l2h; - struct rfid_protocol *proto; - union { - struct tcl_handle tcl; - } priv; /* priv has to be last, since - * it could contain additional - * private data over the end of - * sizeof(priv). */ -}; - -#endif /* __LIBRFID__ */ - -#endif /* _RFID_PROTOCOL_H */ diff --git a/include/rfid/rfid_protocol_mifare_classic.h b/include/rfid/rfid_protocol_mifare_classic.h deleted file mode 100644 index e6b2400..0000000 --- a/include/rfid/rfid_protocol_mifare_classic.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _MIFARE_CLASSIC_H - -#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 - - -#endif /* __LIBRFID__ */ - -#endif /* _MIFARE_CLASSIC_H */ diff --git a/include/rfid/rfid_protocol_mifare_ul.h b/include/rfid/rfid_protocol_mifare_ul.h deleted file mode 100644 index cc93b6b..0000000 --- a/include/rfid/rfid_protocol_mifare_ul.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _RFID_PROTOCOL_MFUL_H -#define _RFID_PROTOCOL_MFUL_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 - -#define MIFARE_UL_RESP_ACK 0x0a -#define MIFARE_UL_RESP_NAK 0x00 - -#define MIFARE_UL_PAGE_LOCK 2 -#define MIFARE_UL_PAGE_OTP 3 - -extern struct rfid_protocol rfid_protocol_mful; - -#endif /* __LIBRFID__ */ - -#endif diff --git a/include/rfid/rfid_protocol_tcl.h b/include/rfid/rfid_protocol_tcl.h deleted file mode 100644 index f754ad9..0000000 --- a/include/rfid/rfid_protocol_tcl.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef _RFID_PROTOCOL_TCL_H -#define _RFID_PROTOCOL_TCL_H - -#ifdef __LIBRFID__ - -enum tcl_transport_rate { - TCL_RATE_106 = 0x01, - TCL_RATE_212 = 0x02, - TCL_RATE_424 = 0x04, - TCL_RATE_848 = 0x08, -}; - -enum tcl_transport_transcieve_flags { - TCL_TRANSP_F_TX_CRC = 0x01, /* transport adds TX CRC */ - TCL_TRANSP_F_RX_CRC = 0x02, -}; - -struct tcl_handle { - /* derived from ats */ - unsigned char *historical_bytes; /* points into ats */ - unsigned int historical_len; - - unsigned int fsc; /* max frame size accepted by card */ - unsigned int fsd; /* max frame size accepted by reader */ - unsigned int fwt; /* frame waiting time (in usec)*/ - unsigned char ta; /* divisor information */ - unsigned char sfgt; /* start-up frame guard time (in usec) */ - - /* otherwise determined */ - unsigned int cid; /* Card ID */ - unsigned int nad; /* Node Address */ - - unsigned int flags; - unsigned int state; /* protocol state */ - - unsigned int toggle; /* send toggle with next frame */ - - unsigned int ats_len; - unsigned char ats[0]; -}; - -enum tcl_handle_flags { - TCL_HANDLE_F_NAD_SUPPORTED = 0x0001, - TCL_HANDLE_F_CID_SUPPORTED = 0x0002, - TCL_HANDLE_F_NAD_USED = 0x0010, - TCL_HANDLE_F_CID_USED = 0x0020, -}; - - -enum tcl_pcb_bits { - TCL_PCB_CID_FOLLOWING = 0x08, - TCL_PCB_NAD_FOLLOWING = 0x04, -}; - -enum tcl_pcd_state { - TCL_STATE_NONE = 0x00, - TCL_STATE_INITIAL, - TCL_STATE_RATS_SENT, /* waiting for ATS */ - TCL_STATE_ATS_RCVD, /* ATS received */ - TCL_STATE_PPS_SENT, /* waiting for PPS response */ - TCL_STATE_ESTABLISHED, /* xchg transparent data */ - TCL_STATE_DESELECT_SENT, /* waiting for DESELECT response */ - TCL_STATE_DESELECTED, /* card deselected or HLTA'd */ -}; - -struct rfid_protocol rfid_protocol_tcl; - -#endif /* __LIBRFID__ */ - -#endif diff --git a/include/rfid/rfid_reader.h b/include/rfid/rfid_reader.h deleted file mode 100644 index 78d07e4..0000000 --- a/include/rfid/rfid_reader.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef _RFID_READER_H -#define _RFID_READER_H - -#include -#include - -struct rfid_reader_handle; - -struct rfid_reader { - char *name; - unsigned int id; - int (*transcieve)(struct rfid_reader_handle *h, - 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); - struct rfid_reader_handle * (*open)(void *data); - void (*close)(struct rfid_reader_handle *h); - - struct rfid_14443a_reader { - int (*init)(struct rfid_reader_handle *h); - int (*transcieve_sf)(struct rfid_reader_handle *h, - unsigned char cmd, - struct iso14443a_atqa *atqa); - 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 tx, - unsigned int speed); - unsigned int speed; - } iso14443a; - struct rfid_14443b_reader { - int (*init)(struct rfid_reader_handle *rh); - unsigned int speed; - } iso14443b; - struct rfid_15693_reader { - int (*init)(struct rfid_reader_handle *rh); - } iso15693; - struct rfid_mifare_classic_reader { - int (*setkey)(struct rfid_reader_handle *h, unsigned char *key); - int (*auth)(struct rfid_reader_handle *h, u_int8_t cmd, - u_int32_t serno, u_int8_t block); - } mifare_classic; - struct rfid_reader *next; -}; - -enum rfid_reader_id { - RFID_READER_CM5121, - RFID_READER_PEGODA, -}; - -struct rfid_reader_handle { - struct rfid_asic_handle *ah; - - union { - - } priv; - struct rfid_reader *reader; -}; - - -extern struct rfid_reader_handle * -rfid_reader_open(void *data, unsigned int id); - -extern void rfid_reader_close(struct rfid_reader_handle *rh); -#endif diff --git a/include/rfid/rfid_reader_cm5121.h b/include/rfid/rfid_reader_cm5121.h deleted file mode 100644 index 8d9a312..0000000 --- a/include/rfid/rfid_reader_cm5121.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _RFID_READER_CM5121_H -#define _RFID_READER_CM5121_H - -#define CM5121_CW_CONDUCTANCE 0x3f -#define CM5121_MOD_CONDUCTANCE 0x3f -#define CM5121_14443A_BITPHASE 0xa9 -#define CM5121_14443A_THRESHOLD 0xff - -#define CM5121_14443B_BITPHASE 0xad -#define CM5121_14443B_THRESHOLD 0xff - - -extern int -PC_to_RDR_Escape(void *handle, - const unsigned char *tx_buf, unsigned int tx_len, - unsigned char *rx_buf, unsigned int *rx_len); - -extern struct rfid_reader rfid_reader_cm5121; -// extern struct rfid_asic_transport cm5121_ccid; - -#endif diff --git a/src/rfid.c b/src/rfid.c index be72f12..6fba46a 100644 --- a/src/rfid.c +++ b/src/rfid.c @@ -15,11 +15,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include const char * rfid_hexdump(const void *data, unsigned int len) diff --git a/src/rfid_asic_rc632.c b/src/rfid_asic_rc632.c index 6de9c11..0c38052 100644 --- a/src/rfid_asic_rc632.c +++ b/src/rfid_asic_rc632.c @@ -25,12 +25,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include "rfid_iso14443_common.h" #include "rc632.h" diff --git a/src/rfid_asic_rc632_14443a.c b/src/rfid_asic_rc632_14443a.c deleted file mode 100644 index 4c8a37b..0000000 --- a/src/rfid_asic_rc632_14443a.c +++ /dev/null @@ -1,394 +0,0 @@ -/* - * Philips CL RC632 primitives for ISO 14443-A compliant PICC's - * - * (C) 2005 by Harald Welte - * - */ - -#include -#include -#include - -#include -#include -#include - -#include "rc632.h" - -#include "cm5121_rfid.h" /* FIXME: this needs to be modular */ - -static int -rc632_iso14443a_init(struct rfid_asic_handle *handle) -{ - int ret; - -#if 0 - ret = rc632_power_up(handle); - if (ret < 0) - return ret; - - ret = rc632_turn_on_rf(handle); - if (ret < 0) - return ret; -#endif - - // FIXME: some fifo work (drain fifo?) - - /* flush fifo (our way) */ - ret = rc632_reg_write(handle, RC632_REG_CONTROL, 0x01); - - ret = rc632_reg_write(handle, RC632_REG_TX_CONTROL, - (RC632_TXCTRL_TX1_RF_EN | - RC632_TXCTRL_TX2_RF_EN | - RC632_TXCTRL_TX2_INV | - RC632_TXCTRL_FORCE_100_ASK | - RC632_TXCTRL_MOD_SRC_INT)); - if (ret < 0) - return ret; - - ret = rc632_reg_write(handle, RC632_REG_CW_CONDUCTANCE, - CM5121_CW_CONDUCTANCE); - if (ret < 0) - return ret; - - /* Since FORCE_100_ASK is set (cf mc073930.pdf), this line may be left out? */ - ret = rc632_reg_write(handle, RC632_REG_MOD_CONDUCTANCE, - CM5121_MOD_CONDUCTANCE); - if (ret < 0) - return ret; - - ret = rc632_reg_write(handle, RC632_REG_CODER_CONTROL, - (RC632_CDRCTRL_TXCD_14443A | - RC632_CDRCTRL_RATE_106K)); - if (ret < 0) - return ret; - - ret = rc632_reg_write(handle, RC632_REG_MOD_WIDTH, 0x13); - if (ret < 0) - return ret; - - ret = rc632_reg_write(handle, RC632_REG_MOD_WIDTH_SOF, 0x3f); - if (ret < 0) - return ret; - - ret = rc632_reg_write(handle, RC632_REG_TYPE_B_FRAMING, 0x00); - if (ret < 0) - return ret; - - ret = rc632_reg_write(handle, RC632_REG_RX_CONTROL1, - (RC632_RXCTRL1_GAIN_35DB | - RC632_RXCTRL1_ISO14443 | - RC632_RXCTRL1_SUBCP_8)); - if (ret < 0) - return ret; - - ret = rc632_reg_write(handle, RC632_REG_DECODER_CONTROL, - (RC632_DECCTRL_MANCHESTER | - RC632_DECCTRL_RXFR_14443A)); - if (ret < 0) - return ret; - - ret = rc632_reg_write(handle, RC632_REG_BIT_PHASE, - CM5121_14443A_BITPHASE); - if (ret < 0) - return ret; - - ret = rc632_reg_write(handle, RC632_REG_RX_THRESHOLD, - CM5121_14443A_THRESHOLD); - if (ret < 0) - return ret; - - ret = rc632_reg_write(handle, RC632_REG_BPSK_DEM_CONTROL, 0x00); - if (ret < 0) - return ret; - - ret = rc632_reg_write(handle, RC632_REG_RX_CONTROL2, - (RC632_RXCTRL2_DECSRC_INT | - RC632_RXCTRL2_CLK_Q)); - if (ret < 0) - return ret; - - ret = rc632_reg_write(handle, RC632_REG_RX_WAIT, 0x03); - if (ret < 0) - return ret; - - ret = rc632_reg_write(handle, RC632_REG_CHANNEL_REDUNDANCY, - (RC632_CR_PARITY_ENABLE | - RC632_CR_PARITY_ODD)); - if (ret < 0) - return ret; - - ret = rc632_reg_write(handle, RC632_REG_CRC_PRESET_LSB, 0x63); - if (ret < 0) - return ret; - - ret = rc632_reg_write(handle, RC632_REG_CRC_PRESET_MSB, 0x63); - if (ret < 0) - return ret; - - return 0; -} - -static int -rc632_iso14443a_fini(struct iso14443a_handle *handle_14443) -{ - -#if 0 - ret = rc632_turn_off_rf(handle); - if (ret < 0) - return ret; -#endif - - - return 0; -} - -#if 0 -int -rc632_iso14443a_select(struct rc632_handle *handle, - unsigned char *retptr, - ) -{ - int ret; - unsigned char tx_buf[7]; - unsigned char rx_buf[64]; - unsigned char rx_len = 1; - - memset(rx_buf, 0, sizeof(rx_buf)); - - tx_buf[0] = arg_8; - tx_buf[1] = 0x70; - (u_int32_t *)tx_buf[2] = arg_4; - tx_buf[6] = arg4+4; - - /* disable mifare cryto */ - ret = rc632_clear_bit(handle, RC632_REG_CONTROL, - RC632_CONTROL_CRYPTO1_ON); - if (ret < 0) - return ret; - - ret = rc632_reg_write(handle, RC632_REG_CHANNEL_REDUNDANCY, - (RC632_CR_PARITY_ENABLE | - RC632_CR_PARITY_ODD | - RC632_CR_TX_CRC_ENABLE | - RC632_CR_RX_CRC_ENABLE)); - if (ret < 0) - return ret; - - ret = rc632_transcieve(handle, tx_buf, sizeof(tx_buf), - rx_buf, &rx_len, 0x32, 0); - - if (ret < 0 || rx_len != 1) - return ret; - - *retptr = rx_buf[0]; - - return 0; -} - -/* issue a 14443-3 A PCD -> PICC command, such as REQA, WUPA */ -int -rc632_iso14443a_req(sutruct rc632_handle *handle, unsigned char req, - unsigned char *resp) -{ - int ret; - unsigned char tx_buf[1]; - unsigned char rx_buf[0x40]; - unsigned char rx_len = 2; - - memset(rx_buf, 0, sizeof(rx_buf)); - - tx_buf[0] = req; - - /* transfer only 7 bits of last byte in frame */ - ret = rc632_reg_write(handle, RC632_REG_BIT_FRAMING, 0x07); - if (ret < 0) - return ret; - - - ret = rc632_clear_bits(handle, RC632_REG_CONTROL, - RC632_CONTROL_CRYPTO1_ON); - if (ret < 0) - return ret; - - ret = rc632_reg_write(handle, RC632_REG_CHANNEL_REDUNDANCY, - (RC632_CR_PARITY_ENABLE | - RC632_CR_PARITY_ODD)); - if (ret < 0) - return ret; - - ret = rc632_transcieve(handle, tx_buf, sizeof(tx_buf), rx_buf, - &rx_len, 0x32, 0); - if (ret < 0) - return ret; - - /* switch back to normal 8bit last byte */ - ret = rc632_reg_write(handle, RC632_REG_BIT_FRAMING, 0x00); - if (ret < 0) - return ret; - - if ((rx_len != 2) || (rx_buf[1] != 0xf0)) - return -1; - - resp[0] = rx_buf[0]; - resp[1] = rx_buf[1]; - - return 0; -} -#endif - -/* issue a 14443-3 A PCD -> PICC command in a short frame, such as REQA, WUPA */ -static int -rc632_iso14443a_transcieve_sf(struct rfid_asic_handle *handle, - unsigned char cmd, - struct iso14443a_atqa *atqa) -{ - int ret; - unsigned char tx_buf[1]; - unsigned char rx_len = 2; - - memset(atqa, 0, sizeof(atqa)); - - tx_buf[0] = cmd; - - /* transfer only 7 bits of last byte in frame */ - ret = rc632_reg_write(handle, RC632_REG_BIT_FRAMING, 0x07); - if (ret < 0) - return ret; - - - ret = rc632_clear_bits(handle, RC632_REG_CONTROL, - RC632_CONTROL_CRYPTO1_ON); - if (ret < 0) - return ret; - - ret = rc632_reg_write(handle, RC632_REG_CHANNEL_REDUNDANCY, - (RC632_CR_PARITY_ENABLE | - RC632_CR_PARITY_ODD)); - if (ret < 0) - return ret; - - ret = rc632_transcieve(handle, tx_buf, sizeof(tx_buf), - (unsigned char *)atqa, &rx_len, 0x32, 0); - if (ret < 0) { - DEBUGP("error during rc632_transcieve()\n"); - return ret; - } - - /* switch back to normal 8bit last byte */ - ret = rc632_reg_write(handle, RC632_REG_BIT_FRAMING, 0x00); - if (ret < 0) - return ret; - - if (rx_len != 2) { - DEBUGP("rx_len(%d) != 2\n", rx_len); - return -1; - } - - return 0; -} - -/* transcieve regular frame */ -static int -rc632_iso14443a_transcieve(struct rfid_asic_handle *handle, - const unsigned char *tx_buf, unsigned int tx_len, - unsigned char *rx_buf, unsigned int *rx_len, - unsigned int timeout, unsigned int flags) -{ - int ret; - unsigned char rxl = *rx_len & 0xff; - - memset(rx_buf, 0, *rx_len); - - ret = rc632_reg_write(handle, RC632_REG_CHANNEL_REDUNDANCY, - (RC632_CR_PARITY_ENABLE | - RC632_CR_PARITY_ODD | - RC632_CR_TX_CRC_ENABLE | - RC632_CR_RX_CRC_ENABLE)); - if (ret < 0) - return ret; - - ret = rc632_transcieve(handle, tx_buf, tx_len, rx_buf, &rxl, 0x32, 0); - *rx_len = rxl; - if (ret < 0) - return ret; - - - return 0; -} - -/* transcieve anti collission bitframe */ -static int -rc632_iso14443a_transcieve_acf(struct rfid_asic_handle *handle, - struct iso14443a_anticol_cmd *acf, - unsigned int *bit_of_col) -{ - int ret; - unsigned char rx_buf[64]; - unsigned char rx_len = sizeof(rx_buf); - unsigned char rx_align = 0, tx_last_bits, tx_bytes; - unsigned char boc; - unsigned char error_flag; - *bit_of_col = ISO14443A_BITOFCOL_NONE; - memset(rx_buf, 0, sizeof(rx_buf)); - - /* disable mifare cryto */ - ret = rc632_clear_bits(handle, RC632_REG_CONTROL, - RC632_CONTROL_CRYPTO1_ON); - if (ret < 0) - return ret; - - /* disalbe CRC summing */ - ret = rc632_reg_write(handle, RC632_REG_CHANNEL_REDUNDANCY, - (RC632_CR_PARITY_ENABLE | - RC632_CR_PARITY_ODD)); - if (ret < 0) - return ret; - - tx_last_bits = acf->nvb & 0x0f; /* lower nibble indicates bits */ - tx_bytes = acf->nvb >> 4; - if (tx_last_bits) { - tx_bytes++; - rx_align = (tx_last_bits+1) % 8;/* rx frame complements tx */ - } - - //rx_align = 8 - tx_last_bits;/* rx frame complements tx */ - - /* set RxAlign and TxLastBits*/ - ret = rc632_reg_write(handle, RC632_REG_BIT_FRAMING, - (rx_align << 4) | (tx_last_bits)); - if (ret < 0) - return ret; - - ret = rc632_transcieve(handle, (unsigned char *)acf, tx_bytes, - rx_buf, &rx_len, 0x32, 0); - if (ret < 0) - return ret; - - /* bitwise-OR the two halves of the split byte */ - acf->uid_bits[tx_bytes-2] = ( - (acf->uid_bits[tx_bytes-2] & (0xff >> (8-tx_last_bits))) - | rx_buf[0]); - /* copy the rest */ - memcpy(&acf->uid_bits[tx_bytes+1-2], &rx_buf[1], rx_len-1); - - /* determine whether there was a collission */ - ret = rc632_reg_read(handle, RC632_REG_ERROR_FLAG, &error_flag); - if (ret < 0) - return ret; - - if (error_flag & RC632_ERR_FLAG_COL_ERR) { - /* retrieve bit of collission */ - ret = rc632_reg_read(handle, RC632_REG_COLL_POS, &boc); - if (ret < 0) - return ret; - - /* bit of collission relative to start of part 1 of - * anticollision frame (!) */ - *bit_of_col = 2*8 + boc; - } - - return 0; -} - - diff --git a/src/rfid_asic_rc632_14443b.c b/src/rfid_asic_rc632_14443b.c deleted file mode 100644 index 62aa224..0000000 --- a/src/rfid_asic_rc632_14443b.c +++ /dev/null @@ -1,69 +0,0 @@ - -#include "rc632.h" - -int rc632_iso14443b_init(struct rc632_handle *handle) -{ - // FIXME: some FIFO work - // - ret = rc632_reg_write(handle, RC632_REG_TX_CONTROL, - (RC632_TXCTRL_TX1_RF_EN | - RC632_TXCTRL_TX2_RF_EN | - RC632_TXCTRL_TX2_INV | - RC632_TXCTRL_MOD_SRC_INT)); - - ret = rc632_reg_write(handle, RC632_REG_CW_CONDUCTANCE, 0x3f); - - ret = rc632_reg_write(handle, RC632_REG_MOD_CONDUCTANCE, 0x04); - - ret = rc632_reg_write(handle, RC632_REG_CODE_CONTROL, - (RC632_CDRCTRL_TXCD_NRZ | - RC632_CDRCTRL_RATE_14443B)); - - ret = rc632_reg_write(handle, RC632_REG_MOD_WIDTH, 0x13); - - ret = rc632_reg_write(handle, RC632_REG_SOF_WIDTH, 0x3f); - - ret = rc632_reg_write(handle, RC632_REG_TYPE_B_FRAMING, - (RC632_TBFRAMING_SOF_11L_3H | - (6 << RC632_TBFRAMING_SPACE_SHIFT) | - RC632_TBFRAMING_EOF_11)); - - ret = rc632_reg_write(handle, RC632_REG_RX_CONTROL1, - (RC632_RXCTRL1_GAIN_35DB | - RC632_RXCTRL1_ISO14443 | - RC632_RXCTRL1_SUBCP_8)); - - ret = rc632_reg_write(handle, RC632_REG_DECODE_CONTROL, - (RC632_DECCTRL_BPSK | - RC632_DECCTRL_RXFR_14443B)); - - ret = rc632_reg_write(handle, RC632_REG_BIT_PHASE, - CM5121_14443B_BITPHASE); - - ret = rc632_reg_write(handle, RC632_REG_RX_THRESHOLD, - CM5121_14443B_THRESHOLD); - - ret = rc632_reg_write(handle, RC632_REG_BPSK_DEM_CONTROL, - ((0x10 & RC632_BPSKD_TAUB_MASK)< #include -#include -#include +#include +#include static struct rfid_layer2 *rfid_layer2_list; diff --git a/src/rfid_layer2_iso14443a.c b/src/rfid_layer2_iso14443a.c index 64a860f..da2628f 100644 --- a/src/rfid_layer2_iso14443a.c +++ b/src/rfid_layer2_iso14443a.c @@ -24,10 +24,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #define TIMEOUT 1236 diff --git a/src/rfid_layer2_iso14443b.c b/src/rfid_layer2_iso14443b.c index f874071..7c92562 100644 --- a/src/rfid_layer2_iso14443b.c +++ b/src/rfid_layer2_iso14443b.c @@ -23,10 +23,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "rfid_iso14443_common.h" diff --git a/src/rfid_layer2_iso15693.c b/src/rfid_layer2_iso15693.c index 15ff18a..1a93a19 100644 --- a/src/rfid_layer2_iso15693.c +++ b/src/rfid_layer2_iso15693.c @@ -23,10 +23,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #if 0 /* Transcieve a 7-bit short frame */ diff --git a/src/rfid_proto_mifare_classic.c b/src/rfid_proto_mifare_classic.c index d6de606..e2ee80c 100644 --- a/src/rfid_proto_mifare_classic.c +++ b/src/rfid_proto_mifare_classic.c @@ -25,12 +25,12 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -#include +#include #include "rfid_iso14443_common.h" diff --git a/src/rfid_proto_mifare_ul.c b/src/rfid_proto_mifare_ul.c index 7649b99..747f38c 100644 --- a/src/rfid_proto_mifare_ul.c +++ b/src/rfid_proto_mifare_ul.c @@ -25,10 +25,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "rfid_iso14443_common.h" diff --git a/src/rfid_proto_tcl.c b/src/rfid_proto_tcl.c index 0587611..8f8eae9 100644 --- a/src/rfid_proto_tcl.c +++ b/src/rfid_proto_tcl.c @@ -25,14 +25,14 @@ #include #include -#include -#include -#include -#include -#include - -#include -#include +#include +#include +#include +#include +#include + +#include +#include #include "rfid_iso14443_common.h" diff --git a/src/rfid_protocol.c b/src/rfid_protocol.c index abbd04d..c401a2c 100644 --- a/src/rfid_protocol.c +++ b/src/rfid_protocol.c @@ -21,8 +21,8 @@ #include #include -#include -#include +#include +#include static struct rfid_protocol *rfid_protocol_list; diff --git a/src/rfid_reader.c b/src/rfid_reader.c index 9e46a29..9486cae 100644 --- a/src/rfid_reader.c +++ b/src/rfid_reader.c @@ -20,8 +20,8 @@ #include #include -#include -#include +#include +#include static struct rfid_reader *rfid_reader_list; diff --git a/src/rfid_reader_cm5121.c b/src/rfid_reader_cm5121.c index 8baf013..5ccce98 100644 --- a/src/rfid_reader_cm5121.c +++ b/src/rfid_reader_cm5121.c @@ -32,11 +32,11 @@ #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include /* FIXME */ #include "rc632.h" diff --git a/src/rfid_reader_cm5121_ccid_direct.c b/src/rfid_reader_cm5121_ccid_direct.c index 7f53bb7..3161059 100644 --- a/src/rfid_reader_cm5121_ccid_direct.c +++ b/src/rfid_reader_cm5121_ccid_direct.c @@ -3,7 +3,7 @@ #include #include -#include +#include #include "ccid/ccid-driver.h" diff --git a/src/rfid_reader_cm5121_openct.c b/src/rfid_reader_cm5121_openct.c index 9d96638..4bc879c 100644 --- a/src/rfid_reader_cm5121_openct.c +++ b/src/rfid_reader_cm5121_openct.c @@ -2,7 +2,7 @@ #include -#include +#include #include /* FIXME: get rid of this global crap. In fact this needs to become part of diff --git a/utils/openct-escape.c b/utils/openct-escape.c index 0f9a68a..bc7883e 100644 --- a/utils/openct-escape.c +++ b/utils/openct-escape.c @@ -18,13 +18,13 @@ #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include + +#include +#include static struct rfid_reader_handle *rh; static struct rfid_layer2_handle *l2h; @@ -125,9 +125,9 @@ static int iso7816_get_challenge(unsigned char len) int iso7816_select_application(void) { - char cmd[] = { 0x00, 0xa4, 0x04, 0x0c, 0x07, + unsigned char cmd[] = { 0x00, 0xa4, 0x04, 0x0c, 0x07, 0xa0, 0x00, 0x00, 0x02, 0x47, 0x10, 0x01 }; - char resp[7]; + unsigned char resp[7]; unsigned int rlen = sizeof(resp); int rv; @@ -308,7 +308,7 @@ int main(int argc, char **argv) iso7816_select_ef(0x0101); #if 1 for (i = 0; i < 4; i++) - iso7816_get_challenge(0x60); + iso7816_get_challenge(0x06); #endif break; case RFID_PROTOCOL_MIFARE_UL: -- cgit v1.2.3