first beta - patch sent to librfid list
[rfid/librfid.git] / gemtag / gemtag.h
index d1bef96..e5c24bf 100644 (file)
@@ -1,5 +1,6 @@
 /*
- * (C) 2006 by Frank Zirkelbach <hackbard@hackdaworld.org>
+ * (C) 2006 by Harald Welte <laforge@gnumonks.org>
+ *             Frank Zirkelbach <hackbard@hackdaworld.org>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2 
@@ -44,8 +45,11 @@ struct gemtag_cmd_hdr {
 #define CMD_FAILED                     0x04
 #define AUTH_FAILED                    0x05
 #define READ_FAILED                    0x06
-#define NO_PICC                                0x07
-#define PICC_SELECT_ERROR              0x08
+#define WRITE_FAILED                   0x07
+#define NO_PICC                                0x08
+#define PICC_SELECT_ERROR              0x09
+#define LOAD_E2_FAILED                 0x0a
+#define AUTH_E2_FAILED                 0x0b
 
 /* gemtag commands */
 
@@ -58,8 +62,8 @@ struct gemtag_cmd_hdr {
 #define GEMTAG_CMD_HOST_CODE_KEY       0x16
 #define GEMTAG_CMD_PCD_LOAD_KEY_E2     0x17
 #define GEMTAG_CMD_PICC_AUTH_KEY       0x18
-#define GEMTAG_PICC_AUTHENT1A
-#define GEMTAG_PICC_AUTHENT1B
+#define GEMTAG_PICC_AUTHENT1A          0x60
+#define GEMTAG_PICC_AUTHENT1B          0x61
 
 #define GEMTAG_CMD_PICC_READ           0x19
 #define GEMTAG_CMD_PICC_WRITE          0x1a
@@ -73,28 +77,35 @@ struct gemtag_cmd_hdr {
 #define GEMTAG_CMD_PCD_READ_E2         0x23
 #define GEMTAG_CMD_PCD_WRITE_E2                0x24
 #define GEMTAG_CMD_PICC_COMMON_READ    0x28
-#define GEMTAG_PICC_DECREMENT          
-#define GEMTAG_PICC_INCREMENT          
-#define GEMTAG_PICC_READ16
-#define GEMTAG_PICC_RESTORE
-#define GEMTAG_PICC_WRITE16
-#define GEMTAG_PICC_WRITE4
+#define GEMTAG_PICC_DECREMENT          0xc0
+#define GEMTAG_PICC_INCREMENT          0xc1
+#define GEMTAG_PICC_RESTORE            0xc2
+#define GEMTAG_PICC_READ16             0x30
+#define GEMTAG_PICC_WRITE16            0xa0
+#define GEMTAG_PICC_WRITE4             0xa2
 
-#define GEMTAG_CMD_PICC_REQUEST                0x40
-#define GEMTAG_PICC_REQIDL             0x26
 #define GEMTAG_CMD_PCD_SET_TMO         0x27
 
+#define GEMTAG_CMD_PICC_REQUEST                0x40
 #define GEMTAG_CMD_PICC_CASC_ANTICOLL  0x41
 #define GEMTAG_CMD_PICC_CASC_SELECT    0x42
 #define GEMTAG_PICC_STD_SELECT_CODE    0x93
 #define GEMTAG_PICC_CASC_LEVEL1                0x95
 #define GEMTAG_PICC_CASC_LEVEL2                0x97
+/* from another source (mac gemtag tool) ... */
+#define GEMTAG_PICC_CASC_L1            0x93
+#define GEMTAG_PICC_CASC_L2            0x92
+#define GEMTAG_PICC_CASC_L3            0x94
+#define GEMTAG_PICC_CASC_L4            0x98
+#define GEMTAG_PICC_CASC_L5            0x95
+#define GEMTAG_PICC_CASC_L6            0x97
 
 #define GEMTAG_CMD_PICC_ACTIVATE_IDLE  0x43
 #define GEMTAG_CMD_PICC_ACTIVATE_WAKEUP        0x44
 #define GEMTAG_CMD_SET_DFLT_ATTRIBUTES 0x45
 #define GEMTAG_CMD_SET_ATTRIBUTES      0x46
 #define GEMTAG_CMD_PICC_EXCHANGE_BLOCK 0x48
+#define GEMTAG_PICC_REQIDL             0x26
 #define GEMTAG_PICC_REQALL             0x52
 
 #define GEMTAG_CMD_SWITCH_LED          0x60
@@ -112,4 +123,26 @@ struct gemtag_cmd_hdr {
 #define GEMTAG_CMD_PPS_REQUEST         0xa0
 #define GEMTAG_CMD_DESELECT            0xa1
 
+
+/* function prototypes */
+
+int asciidump(unsigned char *data,int len);
+int hexdump(unsigned char *data,int len);
+struct usb_device *find_device(unsigned short vendor,unsigned short device);
+u_int16_t gemtag_calc_crc(unsigned char *data,u_int16_t len);
+int gemtag_transceive(struct gemtag_handle *gh,unsigned char cmd,
+                      unsigned char *tx,unsigned int tx_len,
+                      unsigned char *rx,unsigned int *rx_len);
+struct gemtag_handle *gemtag_open(void);
+int gemtag_close(struct gemtag_handle *gh);
+int gemtag_transform_mifare_key(struct gemtag_handle *gh,
+                                unsigned char *key6,unsigned char *key12);
+int gemtag_auth_e2(struct gemtag_handle *gh,unsigned char authmode,
+                   int sector,unsigned char *key6);
+int gemtag_auth_mifare_key(struct gemtag_handle *gh,
+                           unsigned char *key6,int sector);
+int gemtag_read16(struct gemtag_handle *gh,int sector,unsigned char *data);
+int gemtag_write16(struct gemtag_handle *gh,int sector,unsigned char *data);
+int gemtag_select_picc(struct gemtag_handle *gh);
+
 #endif