2 * (C) 2006 by Frank Zirkelbach <hackbard@hackdaworld.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define USB_VENDOR_GEMTAG 0x1394
22 #define USB_DEVICE_X501 0x0501
24 struct gemtag_handle {
25 struct usb_dev_handle *handle;
28 unsigned char serial[4];
31 #define GEMTAG_CAP_CRC 0x01
32 #define GEMTAG_CAP_VERB_TRANSMIT 0x02
34 struct gemtag_cmd_hdr {
39 } __attribute__ ((packed));
42 #define SEQ_MISMATCH 0x02
43 #define SHORT_ANSWER 0x03
44 #define CMD_FAILED 0x04
45 #define AUTH_FAILED 0x05
46 #define READ_FAILED 0x06
47 #define WRITE_FAILED 0x07
49 #define PICC_SELECT_ERROR 0x09
53 #define GEMTAG_CMD_PCD_CONFIG 0x10
54 #define GEMTAG_CMD_PICC_ANTICOLL 0x12
55 #define GEMTAG_CMD_PICC_SELECT 0x13
57 #define GEMTAG_CMD_PICC_AUTH 0x14
58 #define GEMTAG_CMD_PICC_AUTH_E2 0x15
59 #define GEMTAG_CMD_HOST_CODE_KEY 0x16
60 #define GEMTAG_CMD_PCD_LOAD_KEY_E2 0x17
61 #define GEMTAG_CMD_PICC_AUTH_KEY 0x18
62 #define GEMTAG_PICC_AUTHENT1A 0x60
63 #define GEMTAG_PICC_AUTHENT1B 0x61
65 #define GEMTAG_CMD_PICC_READ 0x19
66 #define GEMTAG_CMD_PICC_WRITE 0x1a
67 #define GEMTAG_CMD_PICC_VALUE 0x1b
68 #define GEMTAG_CMD_PICC_VALUE_DEBIT 0x1c
69 #define GEMTAG_CMD_PICC_HALT 0x1d
70 #define GEMTAG_CMD_PICC_WRITE4 0x1e
71 #define GEMTAG_CMD_COMMON_WRITE 0x1f
72 #define GEMTAG_CMD_PCD_RF_RESET 0x20
73 #define GEMTAG_CMD_GET_SERIAL_NUMBER 0x22
74 #define GEMTAG_CMD_PCD_READ_E2 0x23
75 #define GEMTAG_CMD_PCD_WRITE_E2 0x24
76 #define GEMTAG_CMD_PICC_COMMON_READ 0x28
77 #define GEMTAG_PICC_DECREMENT 0xc0
78 #define GEMTAG_PICC_INCREMENT 0xc1
79 #define GEMTAG_PICC_RESTORE 0xc2
80 #define GEMTAG_PICC_READ16 0x30
81 #define GEMTAG_PICC_WRITE16 0xa0
82 #define GEMTAG_PICC_WRITE4 0xa2
84 #define GEMTAG_CMD_PCD_SET_TMO 0x27
86 #define GEMTAG_CMD_PICC_REQUEST 0x40
87 #define GEMTAG_CMD_PICC_CASC_ANTICOLL 0x41
88 #define GEMTAG_CMD_PICC_CASC_SELECT 0x42
89 #define GEMTAG_PICC_STD_SELECT_CODE 0x93
90 #define GEMTAG_PICC_CASC_LEVEL1 0x95
91 #define GEMTAG_PICC_CASC_LEVEL2 0x97
92 /* from another source (mac gemtag tool) ... */
93 #define GEMTAG_PICC_CASC_L1 0x93
94 #define GEMTAG_PICC_CASC_L2 0x92
95 #define GEMTAG_PICC_CASC_L3 0x94
96 #define GEMTAG_PICC_CASC_L4 0x98
97 #define GEMTAG_PICC_CASC_L5 0x95
98 #define GEMTAG_PICC_CASC_L6 0x97
100 #define GEMTAG_CMD_PICC_ACTIVATE_IDLE 0x43
101 #define GEMTAG_CMD_PICC_ACTIVATE_WAKEUP 0x44
102 #define GEMTAG_CMD_SET_DFLT_ATTRIBUTES 0x45
103 #define GEMTAG_CMD_SET_ATTRIBUTES 0x46
104 #define GEMTAG_CMD_PICC_EXCHANGE_BLOCK 0x48
105 #define GEMTAG_PICC_REQIDL 0x26
106 #define GEMTAG_PICC_REQALL 0x52
108 #define GEMTAG_CMD_SWITCH_LED 0x60
109 #define GEMTAG_LED_OFF 0x00
110 #define GEMTAG_LED_ON 0x01
112 #define GEMTAG_CMD_GET_FW_VERSION 0x63
113 #define GEMTAG_CMD_GET_RIC_VERSION 0x64
114 #define GEMTAG_CMD_SET_DEFAULT_BAUDRATE 0x81
115 #define GEMTAG_CMD_SET_ONLINE_BAUDRATE 0x82
116 #define GEMTAG_CMD_SET_CPU_TIMEOUT 0x88
118 #define GEMTAG_CMD_DETECT_CARD 0x92
119 #define GEMTAG_CMD_DETECT_ISO15693_CARD 0x93
120 #define GEMTAG_CMD_PPS_REQUEST 0xa0
121 #define GEMTAG_CMD_DESELECT 0xa1
124 /* function prototypes */
125 int asciidump(unsigned char *data,int len);
126 int hexdump(unsigned char *data,int len);
127 struct usb_device *find_device(unsigned short vendor,unsigned short device);
128 u_int16_t gemtag_calc_crc(unsigned char *data,u_int16_t len);
129 int gemtag_transceive(struct gemtag_handle *gh,unsigned char cmd,
130 unsigned char *tx,unsigned int tx_len,
131 unsigned char *rx,unsigned int *rx_len);
132 struct gemtag_handle *gemtag_open(void);
133 int gemtag_close(struct gemtag_handle *gh);
134 int gemtag_transform_mifare_key(struct gemtag_handle *gh,
135 unsigned char *key6,unsigned char *key12);
136 int gemtag_auth_mifare_key(struct gemtag_handle *gh,
137 unsigned char *key6,int sector);
138 int gemtag_read16(struct gemtag_handle *gh,int sector,unsigned char *data);
139 int gemtag_write16(struct gemtag_handle *gh,int sector,unsigned char *data);
140 int gemtag_select_picc(struct gemtag_handle *gh);