diff options
| author | laforge <laforge@e0336214-984f-0b4b-a45f-81c69e1f0ede> | 2005-11-08 10:34:18 +0000 | 
|---|---|---|
| committer | laforge <laforge@e0336214-984f-0b4b-a45f-81c69e1f0ede> | 2005-11-08 10:34:18 +0000 | 
| commit | 7600eb5ebbb8ac0f7532e7e7ae6cb5d4dc29d30b (patch) | |
| tree | f38665192c50bdcbbda8e74d00f585ced5cea63b /include | |
| parent | 27e8fe5394184505e09318d3691761da59ecdff5 (diff) | |
- better layering abstraciton
- differentiate between library internal definitions and public ones
- implement getopt/setopt like get/setsockopt
- offer speed changing controls
git-svn-id: https://svn.gnumonks.org/trunk/librfid@1662 e0336214-984f-0b4b-a45f-81c69e1f0ede
Diffstat (limited to 'include')
| -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 | 
10 files changed, 124 insertions, 101 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;  | 
