From da4aa962e17978a70bf1cf4fc3d1b46b620bc3bf Mon Sep 17 00:00:00 2001 From: laforge Date: Tue, 29 Jan 2008 16:29:21 +0000 Subject: * implement rfid_reader_{get,set}opt() * move get/set environment and get firmware api version to reader_{get,set}opt() * merge rc632 power_up and power_down functions in new power function * merge rc632 layer 2 protocol init functions into one * rename parameters of rfid_layer2_{get,set}opt() * move rf_power() function of reader to new setopt() interface * merge reader layer 2 protocol init functiosn into one * move most of the iso15693 anticol implementation from asic into layer2 code * make most iso15693 parameters configurable via layer2_{get,set}opt() * implement AFI for iso15693 inventory request * introduce new generic 'rc632 asic based reader' functions * use those functions from openpcd, cm5121 and spidev readers * use new register initialization script data structure for rc632 init functions * TODO update git-svn-id: https://svn.gnumonks.org/trunk/librfid@2064 e0336214-984f-0b4b-a45f-81c69e1f0ede --- include/librfid/rfid_asic_rc632.h | 17 ++++---- include/librfid/rfid_layer2.h | 4 +- include/librfid/rfid_layer2_iso15693.h | 76 ++++++++++++++++++---------------- include/librfid/rfid_reader.h | 54 ++++++++++++++---------- include/librfid/rfid_reader_openpcd.h | 5 +++ 5 files changed, 88 insertions(+), 68 deletions(-) (limited to 'include') diff --git a/include/librfid/rfid_asic_rc632.h b/include/librfid/rfid_asic_rc632.h index 0602cd9..529b48c 100644 --- a/include/librfid/rfid_asic_rc632.h +++ b/include/librfid/rfid_asic_rc632.h @@ -5,6 +5,7 @@ struct rfid_asic_transport_handle; #include #include +#include struct rfid_asic_rc632_transport { struct { @@ -32,9 +33,9 @@ struct iso15693_anticol_cmd; struct rfid_asic_rc632 { struct { - int (*power_up)(struct rfid_asic_handle *h); - int (*power_down)(struct rfid_asic_handle *h); + int (*power)(struct rfid_asic_handle *h, int on); int (*rf_power)(struct rfid_asic_handle *h, int on); + int (*init)(struct rfid_asic_handle *h, enum rfid_layer2_id); int (*transceive)(struct rfid_asic_handle *h, enum rfid_frametype, const u_int8_t *tx_buf, @@ -44,7 +45,6 @@ struct rfid_asic_rc632 { u_int64_t timeout, unsigned int flags); struct { - int (*init)(struct rfid_asic_handle *h); int (*transceive_sf)(struct rfid_asic_handle *h, u_int8_t cmd, struct iso14443a_atqa *atqa); @@ -56,14 +56,11 @@ struct rfid_asic_rc632 { unsigned int speed); } iso14443a; struct { - int (*init)(struct rfid_asic_handle *h); - } iso14443b; - struct { - int (*init)(struct rfid_asic_handle *h); int (*transceive_ac)(struct rfid_asic_handle *h, - struct iso15693_anticol_cmd *acf, - unsigned char *uuid, - char *bit_of_col); + const struct iso15693_anticol_cmd *acf, + unsigned int acf_len, + struct iso15693_anticol_resp *resp, + unsigned int *rx_len, char *bit_of_col); } iso15693; struct { int (*setkey)(struct rfid_asic_handle *h, diff --git a/include/librfid/rfid_layer2.h b/include/librfid/rfid_layer2.h index 023b171..7fbf81c 100644 --- a/include/librfid/rfid_layer2.h +++ b/include/librfid/rfid_layer2.h @@ -32,9 +32,9 @@ int rfid_layer2_transceive(struct rfid_layer2_handle *l2h, 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, +int rfid_layer2_getopt(struct rfid_layer2_handle *l2h, int optname, void *optval, unsigned int *optlen); -int rfid_layer2_setopt(struct rfid_layer2_handle *ph, int optname, +int rfid_layer2_setopt(struct rfid_layer2_handle *l2h, int optname, const void *optval, unsigned int optlen); char *rfid_layer2_name(struct rfid_layer2_handle *l2h); #ifdef __LIBRFID__ diff --git a/include/librfid/rfid_layer2_iso15693.h b/include/librfid/rfid_layer2_iso15693.h index 5719a39..495eebb 100644 --- a/include/librfid/rfid_layer2_iso15693.h +++ b/include/librfid/rfid_layer2_iso15693.h @@ -29,40 +29,16 @@ /* protocol definitions */ -#if 0 -struct rfid_15693_handle; - -struct rfid_layer2_15693t { - unsigned char *name; - - struct { - int (*init)(struct iso15693_handle *handle); - int (*fini)(struct iso15693_handle *handle); - -#if 0 - int (*transceive_sf)(struct iso14443a_handle *handle, - unsigned char cmd, - struct iso14443a_atqa *atqa); - int (*transceive_acf)(struct iso14443a_handle *handle, - struct iso14443a_anticol_cmd *acf, - unsigned int *bit_of_col); -#endif - int (*transceive)(struct iso15693_handle *handle, - const unsigned char *tx_buf, - unsigned int tx_len, - unsigned char *rx_buf, - unsigned int *rx_len); - } fn; - - union { - } priv; -}; -#endif - struct iso15693_handle { unsigned int state; - unsigned int ask100:1, - out256:1; + unsigned int vcd_ask100:1, + vicc_two_subc:1, + vicc_fast:1, + single_slot:1, + use_afi:1, + vcd_out256:1; + u_int8_t afi; /* appplication family identifier */ + u_int8_t dsfid; /* data storage format identifier */ }; enum rfid_15693_state { @@ -76,6 +52,10 @@ enum rfid_15693_opt { RFID_OPT_15693_VCD_CODING = 0x00010002, RFID_OPT_15693_VICC_SUBC = 0x00010003, RFID_OPT_15693_VICC_SPEED = 0x00010004, + RFID_OPT_15693_VCD_SLOTS = 0x00010005, + RFID_OPT_15693_USE_AFI = 0x00010006, + RFID_OPT_15693_AFI = 0x00010007, + RFID_OPT_15693_DSFID = 0x00010008, }; enum rfid_15693_opt_mod_depth { @@ -195,14 +175,40 @@ enum iso15693_commands { }; struct iso15693_anticol_cmd { - /* iso15693-3 table5 flags*/ - unsigned char flags; // SLOTS16 | SLOT1, AFI_PRESENT, OPTION_FLAG - unsigned char afi; // AFI 0 for any + struct iso15693_request req; unsigned char mask_len; unsigned char mask_bits[ISO15693_UID_LEN]; unsigned char current_slot; } __attribute__((packed)); +struct iso15693_anticol_cmd_afi { + struct iso15693_request req; + unsigned char afi; + unsigned char mask_len; + unsigned char mask_bits[ISO15693_UID_LEN]; +} __attribute__((packed)); + +/* Figure 11, Chapter 9.2.1 */ +struct iso15693_anticol_resp { + struct iso15693_response resp; + u_int8_t dsfid; + u_int8_t uuid[ISO15693_UID_LEN]; +} __attribute__((packed)); + + +#define ISO15693_T_SLOW 0 +#define ISO15693_T_FAST 1 +enum iso15693_t { + ISO15693_T1, + ISO15693_T2, + ISO15693_T3, + ISO15693_T4, + ISO15693_T4_WRITE, +}; + +/* in microseconds as per Chapter 8.4 table 8 */ +extern const unsigned int iso15693_timing[2][5]; + #include extern const struct rfid_layer2 rfid_layer2_iso15693; diff --git a/include/librfid/rfid_reader.h b/include/librfid/rfid_reader.h index 8dc7860..1c53677 100644 --- a/include/librfid/rfid_reader.h +++ b/include/librfid/rfid_reader.h @@ -7,39 +7,46 @@ struct rfid_reader_handle; +/* 0...0xffff = global options, 0x10000...0x1ffff = private options */ +#define RFID_OPT_RDR_PRIV 0x00010000 +enum rfid_reader_opt { + RFID_OPT_RDR_FW_VERSION = 0x0001, + RFID_OPT_RDR_RF_KILL = 0x0002, +}; + + struct rfid_reader { char *name; unsigned int id; unsigned int l2_supported; unsigned int proto_supported; - int (*get_api_version)( - struct rfid_reader_handle *h, - u_int8_t *version); + int (*reset)(struct rfid_reader_handle *h); - int (*get_environment)( - struct rfid_reader_handle *rh, - unsigned char num_bytes, - unsigned char *buf); + /* open the reader */ + struct rfid_reader_handle * (*open)(void *data); - int (*set_environment)( - struct rfid_reader_handle *rh, - unsigned char num_bytes, - const unsigned char *buf); + /* Initialize the reader for a given layer 2 */ + int (*init)(struct rfid_reader_handle *h, enum rfid_layer2_id); - int (*reset)(struct rfid_reader_handle *h); + /* completely close the reader */ + void (*close)(struct rfid_reader_handle *h); + + int (*getopt)(struct rfid_reader_handle *rh, int optname, + void *optval, unsigned int *optlen); + + int (*setopt)(struct rfid_reader_handle *rh, int optname, + const void *optval, unsigned int optlen); + + /* transceive one frame */ int (*transceive)(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); - int (*rf_power)(struct rfid_reader_handle *h, int on); struct rfid_14443a_reader { - int (*init)(struct rfid_reader_handle *h); int (*transceive_sf)(struct rfid_reader_handle *h, unsigned char cmd, struct iso14443a_atqa *atqa); @@ -52,15 +59,14 @@ struct rfid_reader { 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); int (*transceive_ac)(struct rfid_reader_handle *h, - struct iso15693_anticol_cmd *acf, - unsigned char *uuid, - char *bit_of_col); + const struct iso15693_anticol_cmd *acf, + unsigned int acf_len, + struct iso15693_anticol_resp *resp, + unsigned int *rx_len, char *bit_of_col); } iso15693; struct rfid_mifare_classic_reader { int (*setkey)(struct rfid_reader_handle *h, const unsigned char *key); @@ -89,4 +95,10 @@ extern struct rfid_reader_handle * rfid_reader_open(void *data, unsigned int id); extern void rfid_reader_close(struct rfid_reader_handle *rh); + +extern int rfid_reader_getopt(struct rfid_reader_handle *rh, int optname, + void *optval, unsigned int *optlen); +extern int rfid_reader_setopt(struct rfid_reader_handle *rh, int optname, + const void *optval, unsigned int optlen); + #endif diff --git a/include/librfid/rfid_reader_openpcd.h b/include/librfid/rfid_reader_openpcd.h index 14b1f63..05ea45e 100644 --- a/include/librfid/rfid_reader_openpcd.h +++ b/include/librfid/rfid_reader_openpcd.h @@ -99,4 +99,9 @@ enum openpcd_cmd_class { extern const struct rfid_reader rfid_reader_openpcd; +/* 0...0xffff = global options, 0x10000...0x1ffff = private options */ +enum rfid_reader_openpcd_opt { + RFID_OPT_RDR_ENVIRONMENT = 0x10001, +}; + #endif -- cgit v1.2.3