| 1 | #ifndef _CARDMAN_H_ |
|---|
| 2 | #define _CARDMAN_H_ |
|---|
| 3 | |
|---|
| 4 | #define MAX_ATR 33 |
|---|
| 5 | |
|---|
| 6 | #define CM2020_MAX_DEV 16 |
|---|
| 7 | #define CM4000_MAX_DEV 4 |
|---|
| 8 | |
|---|
| 9 | typedef struct atreq { |
|---|
| 10 | int atr_len; |
|---|
| 11 | unsigned char atr[64]; |
|---|
| 12 | int power_act; |
|---|
| 13 | unsigned char bIFSD; |
|---|
| 14 | unsigned char bIFSC; |
|---|
| 15 | } atreq_t; |
|---|
| 16 | |
|---|
| 17 | typedef struct ptsreq { |
|---|
| 18 | unsigned long protocol; /*T=0: 2^0, T=1: 2^1 */ |
|---|
| 19 | unsigned char flags; |
|---|
| 20 | unsigned char pts1; |
|---|
| 21 | unsigned char pts2; |
|---|
| 22 | unsigned char pts3; |
|---|
| 23 | } ptsreq_t; |
|---|
| 24 | |
|---|
| 25 | #define CM_IOC_MAGIC 'c' |
|---|
| 26 | #define CM_IOC_MAXNR 255 |
|---|
| 27 | |
|---|
| 28 | #define CM_IOCGSTATUS _IOR (CM_IOC_MAGIC, 0, unsigned char *) |
|---|
| 29 | #define CM_IOCGATR _IOWR(CM_IOC_MAGIC, 1, atreq_t *) |
|---|
| 30 | #define CM_IOCSPTS _IOW (CM_IOC_MAGIC, 2, ptsreq_t *) |
|---|
| 31 | #define CM_IOCSRDR _IO (CM_IOC_MAGIC, 3) |
|---|
| 32 | #define CM_IOCARDOFF _IO (CM_IOC_MAGIC, 4) |
|---|
| 33 | |
|---|
| 34 | #define CM_IOSDBGLVL _IOW(CM_IOC_MAGIC, 250, int*) |
|---|
| 35 | |
|---|
| 36 | /* card and device states */ |
|---|
| 37 | #define CM_CARD_INSERTED 0x01 |
|---|
| 38 | #define CM_CARD_POWERED 0x02 |
|---|
| 39 | #define CM_ATR_PRESENT 0x04 |
|---|
| 40 | #define CM_ATR_VALID 0x08 |
|---|
| 41 | #define CM_STATE_VALID 0x0f |
|---|
| 42 | /* extra info only from CM4000 */ |
|---|
| 43 | #define CM_NO_READER 0x10 |
|---|
| 44 | #define CM_BAD_CARD 0x20 |
|---|
| 45 | |
|---|
| 46 | #ifdef __KERNEL__ |
|---|
| 47 | |
|---|
| 48 | /* USB can have 16 readers, while PCMCIA is allowed 4 slots */ |
|---|
| 49 | |
|---|
| 50 | #define CM4000_MAX_DEV 4 |
|---|
| 51 | |
|---|
| 52 | #ifdef __CM2020__ |
|---|
| 53 | |
|---|
| 54 | #define MODULE_NAME "cardman_usb" |
|---|
| 55 | |
|---|
| 56 | #define CM2020_MAX_DEV 16 |
|---|
| 57 | #define CM2020_MINOR 224 |
|---|
| 58 | |
|---|
| 59 | #define CM2020_REQT_WRITE 0x42 |
|---|
| 60 | #define CM2020_REQT_READ 0xc2 |
|---|
| 61 | |
|---|
| 62 | #define CM2020_MODE_1 0x01 |
|---|
| 63 | #define CM2020_MODE_2 0x02 |
|---|
| 64 | #define CM2020_MODE_3 0x03 |
|---|
| 65 | #define CM2020_MODE_4 0x08 |
|---|
| 66 | #define CM2020_CARD_ON 0x10 |
|---|
| 67 | #define CM2020_CARD_OFF 0x11 |
|---|
| 68 | #define CM2020_GET_STATUS 0x20 |
|---|
| 69 | #define CM2020_STATUS_MASK 0xc0 |
|---|
| 70 | #define CM2020_STATUS_NO_CARD 0x00 |
|---|
| 71 | #define CM2020_STATUS_NOT_POWERD 0x40 |
|---|
| 72 | #define CM2020_STATUS_POWERD 0xc0 |
|---|
| 73 | #define CM2020_SET_PARAMETER 0x30 |
|---|
| 74 | |
|---|
| 75 | #define CM2020_CARDON_COLD 0x00 |
|---|
| 76 | #define CM2020_CARDON_WARM 0x01 |
|---|
| 77 | |
|---|
| 78 | #define CM2020_FREQUENCY_3_72MHZ 0x00 |
|---|
| 79 | #define CM2020_FREQUENCY_5_12MHZ 0x10 |
|---|
| 80 | |
|---|
| 81 | #define CM2020_BAUDRATE_115200 0x0C |
|---|
| 82 | #define CM2020_BAUDRATE_76800 0x08 |
|---|
| 83 | #define CM2020_BAUDRATE_57600 0x06 |
|---|
| 84 | #define CM2020_BAUDRATE_38400 0x04 |
|---|
| 85 | #define CM2020_BAUDRATE_28800 0x03 |
|---|
| 86 | #define CM2020_BAUDRATE_19200 0x02 |
|---|
| 87 | #define CM2020_BAUDRATE_9600 0x01 |
|---|
| 88 | |
|---|
| 89 | #define CM2020_ODD_PARITY 0x80 |
|---|
| 90 | |
|---|
| 91 | #define CM2020_CARD_ASYNC 0x00 |
|---|
| 92 | |
|---|
| 93 | enum { |
|---|
| 94 | CB_NOP, |
|---|
| 95 | CB_SET_PARAMETER, |
|---|
| 96 | CB_READ_STATUS, |
|---|
| 97 | CB_READ_ATR, |
|---|
| 98 | CB_WRITE_PTS, |
|---|
| 99 | CB_READ_PTS, |
|---|
| 100 | CB_WRITE_T1, |
|---|
| 101 | CB_PROG_T1, |
|---|
| 102 | CB_READ_T1, |
|---|
| 103 | CB_WRITE_T0, |
|---|
| 104 | CB_WRITE_T0_SW1SW2, |
|---|
| 105 | CB_READ_T0, |
|---|
| 106 | CB_READ_T0_DATA, |
|---|
| 107 | CB_CARD_OFF, |
|---|
| 108 | CB_T1MODE2 |
|---|
| 109 | }; |
|---|
| 110 | |
|---|
| 111 | #define TIMEOUT_LEN 60000 |
|---|
| 112 | #define MAX_RBUF 512 |
|---|
| 113 | |
|---|
| 114 | typedef struct usb_cardman { |
|---|
| 115 | |
|---|
| 116 | struct usb_device *dev; |
|---|
| 117 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
|---|
| 118 | struct usb_interface *interface; /* the interface for this device */ |
|---|
| 119 | #endif |
|---|
| 120 | struct task_struct *owner; |
|---|
| 121 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) |
|---|
| 122 | struct usb_ctrlrequest *dr; |
|---|
| 123 | #else |
|---|
| 124 | devrequest *dr; |
|---|
| 125 | #endif |
|---|
| 126 | struct urb *irq, *ctrl, *rctl; |
|---|
| 127 | unsigned char *ibuf, *cbuf, *rcbuf; |
|---|
| 128 | wait_queue_head_t waitq; |
|---|
| 129 | |
|---|
| 130 | unsigned char atr[MAX_ATR]; |
|---|
| 131 | unsigned char atr_csum; |
|---|
| 132 | unsigned char atr_len; |
|---|
| 133 | unsigned char bIFSD, bIFSC; |
|---|
| 134 | unsigned char ta1; /* TA(1) specifies Fi over b8 to b5, Di over b4 to b1 */ |
|---|
| 135 | unsigned char pts[4]; |
|---|
| 136 | |
|---|
| 137 | unsigned char rbuf[MAX_RBUF]; |
|---|
| 138 | short rlen; |
|---|
| 139 | |
|---|
| 140 | int t1_reply_len; |
|---|
| 141 | |
|---|
| 142 | /* length of a T=0 packet, excl. the header length */ |
|---|
| 143 | unsigned char t0_data_len; |
|---|
| 144 | |
|---|
| 145 | /* relative data offset as we proceed through the packet */ |
|---|
| 146 | unsigned char t0_data_off; |
|---|
| 147 | |
|---|
| 148 | /* byte 2 of the T=0 header (INS from CLA INS ADR...) */ |
|---|
| 149 | unsigned char t0_ins; |
|---|
| 150 | |
|---|
| 151 | /* length of T=0 reply we expcet. 2 for a WriteT0, else |
|---|
| 152 | * ReadT0 length + 2 (Sw1 Sw2) |
|---|
| 153 | */ |
|---|
| 154 | unsigned short t0_expected_reply_len; |
|---|
| 155 | |
|---|
| 156 | int bInterval; |
|---|
| 157 | unsigned char ctrlendp; |
|---|
| 158 | unsigned char intendp; |
|---|
| 159 | unsigned char card_state; |
|---|
| 160 | int flags; |
|---|
| 161 | int op; |
|---|
| 162 | unsigned char proto; |
|---|
| 163 | int ttl, ttl_hi, /* CWT */ |
|---|
| 164 | bwt, /* BWT */ |
|---|
| 165 | ptsttl; /* PTS retry */ |
|---|
| 166 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) |
|---|
| 167 | int open; |
|---|
| 168 | int present; |
|---|
| 169 | struct semaphore sem; |
|---|
| 170 | int minor; |
|---|
| 171 | #endif |
|---|
| 172 | } usb_cardman_t; |
|---|
| 173 | #endif /* __CM2020__ */ |
|---|
| 174 | |
|---|
| 175 | #ifdef __CM4000__ |
|---|
| 176 | |
|---|
| 177 | #define DEVICE_NAME "cmm" |
|---|
| 178 | #define MODULE_NAME "cardman_cs" |
|---|
| 179 | |
|---|
| 180 | /* unofficial CM4000 ioctl */ |
|---|
| 181 | #define CM4000_IOCMONITOR _IO (CM_IOC_MAGIC, 251) |
|---|
| 182 | #define CM4000_IOCDUMPATR _IO (CM_IOC_MAGIC, 252) |
|---|
| 183 | #define CM4000_IOCDECUSECOUNT _IO (CM_IOC_MAGIC, 253) |
|---|
| 184 | #define CM4000_IOCPOWERON _IO (CM_IOC_MAGIC, 254) |
|---|
| 185 | #define CM4000_IOCGIOADDR _IOW(CM_IOC_MAGIC, 255, int*) |
|---|
| 186 | |
|---|
| 187 | #endif /* __CM4000__ */ |
|---|
| 188 | |
|---|
| 189 | #endif /* __KERNEL__ */ |
|---|
| 190 | #endif /* _CARDMAN_H_ */ |
|---|