From b0fef13efe84d8601a9496098429b4a080e20c9e Mon Sep 17 00:00:00 2001 From: laforge Date: Sun, 29 May 2005 18:05:31 +0000 Subject: move librfid to new location in repository git-svn-id: https://svn.gnumonks.org/trunk/librfid@1181 e0336214-984f-0b4b-a45f-81c69e1f0ede --- include/rfid/rfid.h | 12 +++ include/rfid/rfid_asic.h | 43 +++++++++++ include/rfid/rfid_asic_rc632.h | 141 +++++++++++++++++++++++++++++++++++ include/rfid/rfid_layer2.h | 56 ++++++++++++++ include/rfid/rfid_layer2_iso14443a.h | 93 +++++++++++++++++++++++ include/rfid/rfid_layer2_iso14443b.h | 83 +++++++++++++++++++++ include/rfid/rfid_protocol.h | 53 +++++++++++++ include/rfid/rfid_protocol_tcl.h | 65 ++++++++++++++++ include/rfid/rfid_reader.h | 50 +++++++++++++ include/rfid/rfid_reader_cm5121.h | 21 ++++++ 10 files changed, 617 insertions(+) create mode 100644 include/rfid/rfid.h create mode 100644 include/rfid/rfid_asic.h create mode 100644 include/rfid/rfid_asic_rc632.h create mode 100644 include/rfid/rfid_layer2.h create mode 100644 include/rfid/rfid_layer2_iso14443a.h create mode 100644 include/rfid/rfid_layer2_iso14443b.h create mode 100644 include/rfid/rfid_protocol.h create mode 100644 include/rfid/rfid_protocol_tcl.h create mode 100644 include/rfid/rfid_reader.h create mode 100644 include/rfid/rfid_reader_cm5121.h (limited to 'include/rfid') diff --git a/include/rfid/rfid.h b/include/rfid/rfid.h new file mode 100644 index 0000000..bf8d799 --- /dev/null +++ b/include/rfid/rfid.h @@ -0,0 +1,12 @@ +#ifndef _RFID_H +#define _RFID_H + +#include + + +#define DEBUGP(x, args ...) fprintf(stderr, "%s(%d):%s: " x, __FILE__, __LINE__, __FUNCTION__, ## args) +extern const char *rfid_hexdump(const void *data, unsigned int len); + +int rfid_init(); + +#endif /* _RFID_H */ diff --git a/include/rfid/rfid_asic.h b/include/rfid/rfid_asic.h new file mode 100644 index 0000000..e336d01 --- /dev/null +++ b/include/rfid/rfid_asic.h @@ -0,0 +1,43 @@ +#ifndef _RFID_ASIC_H +#define _RFID_ASIC_H + +#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 new file mode 100644 index 0000000..f4c9fa1 --- /dev/null +++ b/include/rfid/rfid_asic_rc632.h @@ -0,0 +1,141 @@ +#ifndef _RFID_ASIC_RC632_H +#define _RFID_ASIC_RC632_H + +struct rfid_asic_transport_handle; + +struct rfid_asic_rc632_transport { + struct { + int (*reg_write)(struct rfid_asic_transport_handle *rath, + unsigned char reg, + unsigned char value); + int (*reg_read)(struct rfid_asic_transport_handle *rath, + unsigned char reg, + unsigned char *value); + int (*fifo_write)(struct rfid_asic_transport_handle *rath, + unsigned char len, + const unsigned char *buf, + unsigned char flags); + int (*fifo_read)(struct rfid_asic_transport_handle *rath, + unsigned char len, + unsigned char *buf); + } fn; +}; + +struct rfid_asic_handle; + +struct iso14443a_atqua; +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, + const unsigned char *tx_buf, + unsigned int tx_len, + unsigned char *rx_buf, + unsigned int *rx_len, + unsigned int timeout, + unsigned int flags); + struct { + int (*init)(struct rfid_asic_handle *h); + int (*transcieve_sf)(struct rfid_asic_handle *h, + unsigned char cmd, + struct iso14443a_atqa *atqa); + int (*transcieve_acf)(struct rfid_asic_handle *h, + struct iso14443a_anticol_cmd *cmd, + unsigned int *bit_of_col); + } iso14443a; + struct { + int (*init)(struct rfid_asic_handle *h); + } iso14443b; + } fn; +}; + +struct rc632_transport_handle { +}; + +/* A handle to a specific RC632 chip */ +struct rfid_asic_rc632_handle { + struct rc632_transport_handle th; +}; + +int +rc632_reg_write(struct rfid_asic_handle *handle, + unsigned char reg, + unsigned char val); + +int +rc632_reg_read(struct rfid_asic_handle *handle, + unsigned char reg, + unsigned char *val); +int +rc632_fifo_write(struct rfid_asic_handle *handle, + unsigned char len, + const unsigned char *buf, + unsigned char flags); + +int +rc632_fifo_read(struct rfid_asic_handle *handle, + unsigned char len, + unsigned char *buf); + +int +rc632_set_bits(struct rfid_asic_handle *handle, unsigned char reg, + unsigned char val); + +int +rc632_clear_bits(struct rfid_asic_handle *handle, unsigned char reg, + unsigned char 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, unsigned int time); + +int +rc632_transmit(struct rfid_asic_handle *handle, + const unsigned char *buf, + unsigned char len, + unsigned int timeout); + +int +rc632_transcieve(struct rfid_asic_handle *handle, + const unsigned char *tx_buf, + unsigned char tx_len, + unsigned char *rx_buf, + unsigned char *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, unsigned char *buf); + + +//struct rfid_asic_handle * rc632_open(struct rc632_transport *transport, void *data); + + +extern struct rfid_asic rc632; +#endif diff --git a/include/rfid/rfid_layer2.h b/include/rfid/rfid_layer2.h new file mode 100644 index 0000000..40b9bff --- /dev/null +++ b/include/rfid/rfid_layer2.h @@ -0,0 +1,56 @@ +#ifndef _RFID_LAYER2_H +#define _RFID_LAYER2_H + +struct rfid_layer2_handle; +struct rfid_reader_handle; + +#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, + const unsigned char *tx_buf, + unsigned int tx_len, unsigned char *rx_buf, + unsigned int *rx_len, unsigned int timeout, + unsigned int flags); + int (*close)(struct rfid_layer2_handle *h); + int (*fini)(struct rfid_layer2_handle *h); + } fn; + struct rfid_layer2 *next; +}; + +struct rfid_layer2_handle { + struct rfid_reader_handle *rh; + union { + struct iso14443a_handle iso14443a; + struct iso14443b_handle iso14443b; + //struct iso15693_handle iso15693; + } priv; + 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, + 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_layer2_close(struct rfid_layer2_handle *l2h); +int rfid_layer2_fini(struct rfid_layer2_handle *l2h); + +#endif diff --git a/include/rfid/rfid_layer2_iso14443a.h b/include/rfid/rfid_layer2_iso14443a.h new file mode 100644 index 0000000..400f951 --- /dev/null +++ b/include/rfid/rfid_layer2_iso14443a.h @@ -0,0 +1,93 @@ +#ifndef _RFID_ISO14443A_H +#define _RFID_ISO14443A_H + +#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; + +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; + 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 /* _ISO14443A_H */ diff --git a/include/rfid/rfid_layer2_iso14443b.h b/include/rfid/rfid_layer2_iso14443b.h new file mode 100644 index 0000000..72e6155 --- /dev/null +++ b/include/rfid/rfid_layer2_iso14443b.h @@ -0,0 +1,83 @@ +#ifndef _RFID_LAYER2_ISO14443B_H +#define _RFID_LAYER2_ISO14443B_H + +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 char pupi[4]; /* Pseudo-Unique PICC Identifier */ + 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 */ + + 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 diff --git a/include/rfid/rfid_protocol.h b/include/rfid/rfid_protocol.h new file mode 100644 index 0000000..93b89c3 --- /dev/null +++ b/include/rfid/rfid_protocol.h @@ -0,0 +1,53 @@ +#ifndef _RFID_PROTOCOL_H +#define _RFID_PROTOCOL_H + +#include + +#include + +struct rfid_protocol_handle; + +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); + 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); + } fn; +}; + +struct rfid_protocol_handle { + struct rfid_layer2_handle *l2h; + union { + struct tcl_handle tcl; + } priv; + struct rfid_protocol *proto; +}; + +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_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, +}; +#endif diff --git a/include/rfid/rfid_protocol_tcl.h b/include/rfid/rfid_protocol_tcl.h new file mode 100644 index 0000000..b913e80 --- /dev/null +++ b/include/rfid/rfid_protocol_tcl.h @@ -0,0 +1,65 @@ +#ifndef _RFID_PROTOCOL_TCL_H +#define _RFID_PROTOCOL_TCL_H + +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 */ + unsigned char ta; /* divisor information */ + unsigned char sfgt; /* start-up frame guard time */ + + /* otherwise determined */ + unsigned int cid; /* Card ID */ + unsigned int nad; /* Node Address */ + + unsigned int flags; + unsigned int state; /* protocol state */ + + 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 diff --git a/include/rfid/rfid_reader.h b/include/rfid/rfid_reader.h new file mode 100644 index 0000000..d6ad3a1 --- /dev/null +++ b/include/rfid/rfid_reader.h @@ -0,0 +1,50 @@ +#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, + const unsigned char *tx_buf, unsigned int tx_len, + unsigned char *rx_buf, unsigned int *rx_len, + unsigned int timeout, unsigned int flags); + struct rfid_reader_handle * (*open)(void *data); + int (*close)(void *data); + + 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); + } iso14443a; + struct rfid_14443b_reader { + int (*init)(struct rfid_reader_handle *rh); + } iso14443b; + struct rfid_15693_reader { + + } iso15693; + 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; +}; +#endif diff --git a/include/rfid/rfid_reader_cm5121.h b/include/rfid/rfid_reader_cm5121.h new file mode 100644 index 0000000..8d9a312 --- /dev/null +++ b/include/rfid/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 -- cgit v1.2.3