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