Rev 4975 | Rev 4980 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4975 | gtament | 1 | ; standard driver stuff |
2 | format MS COFF |
||
3 | |||
4 | DEBUG = 1 |
||
5 | |||
6 | ; this is for DEBUGF macro from 'fdo.inc' |
||
7 | __DEBUG__ = 1 |
||
8 | __DEBUG_LEVEL__ = 1 |
||
9 | |||
10 | include '../proc32.inc' |
||
11 | include '../imports.inc' |
||
12 | include '../fdo.inc' |
||
4979 | gtament | 13 | include '../struct.inc' |
4975 | gtament | 14 | |
15 | public START |
||
16 | public version |
||
17 | |||
18 | ; USB constants |
||
19 | DEVICE_DESCR_TYPE = 1 |
||
20 | CONFIG_DESCR_TYPE = 2 |
||
21 | STRING_DESCR_TYPE = 3 |
||
22 | INTERFACE_DESCR_TYPE = 4 |
||
23 | ENDPOINT_DESCR_TYPE = 5 |
||
24 | DEVICE_QUALIFIER_DESCR_TYPE = 6 |
||
25 | |||
26 | CONTROL_PIPE = 0 |
||
27 | ISOCHRONOUS_PIPE = 1 |
||
28 | BULK_PIPE = 2 |
||
29 | INTERRUPT_PIPE = 3 |
||
30 | |||
31 | ; USB HID constants |
||
32 | HID_DESCR_TYPE = 21h |
||
33 | REPORT_DESCR_TYPE = 22h |
||
34 | PHYSICAL_DESCR_TYPE = 23h |
||
35 | |||
36 | |||
37 | ; LibUSB constatnts |
||
38 | LIBUSB_REQUEST_TYPE_STANDARD = (0x00 shl 5) |
||
39 | LIBUSB_REQUEST_TYPE_CLASS = (0x01 shl 5) |
||
40 | LIBUSB_REQUEST_TYPE_VENDOR = (0x02 shl 5) |
||
41 | LIBUSB_REQUEST_TYPE_RESERVED = (0x03 shl 5) |
||
42 | |||
43 | LIBUSB_RECIPIENT_DEVICE = 0x00 |
||
44 | LIBUSB_RECIPIENT_INTERFACE = 0x01 |
||
45 | LIBUSB_RECIPIENT_ENDPOINT = 0x02 |
||
46 | LIBUSB_RECIPIENT_OTHER = 0x03 |
||
47 | |||
48 | LIBUSB_ENDPOINT_IN = 0x80 |
||
49 | LIBUSB_ENDPOINT_OUT = 0x00 |
||
50 | |||
51 | ; FTDI Constants |
||
52 | FTDI_DEVICE_OUT_REQTYPE = (LIBUSB_REQUEST_TYPE_VENDOR or LIBUSB_RECIPIENT_DEVICE or LIBUSB_ENDPOINT_OUT) |
||
53 | FTDI_DEVICE_IN_REQTYPE = (LIBUSB_REQUEST_TYPE_VENDOR or LIBUSB_RECIPIENT_DEVICE or LIBUSB_ENDPOINT_IN) |
||
54 | |||
55 | ; Requests |
||
56 | ;Definitions for flow control |
||
57 | SIO_RESET =0 ;Reset the port |
||
58 | SIO_MODEM_CTRL =1 ;Set the modem control register |
||
59 | SIO_SET_FLOW_CTRL =2 ;Set flow control register |
||
60 | SIO_SET_BAUD_RATE =3 ;Set baud rate |
||
61 | SIO_SET_DATA =4 ;Set the data characteristics of the port |
||
62 | |||
63 | SIO_RESET_REQUEST =SIO_RESET |
||
64 | SIO_SET_BAUDRATE_REQUEST =SIO_SET_BAUD_RATE |
||
65 | SIO_SET_DATA_REQUEST =SIO_SET_DATA |
||
66 | SIO_SET_FLOW_CTRL_REQUEST =SIO_SET_FLOW_CTRL |
||
67 | SIO_SET_MODEM_CTRL_REQUEST =SIO_MODEM_CTRL |
||
68 | SIO_POLL_MODEM_STATUS_REQUEST=0x05 |
||
69 | SIO_SET_EVENT_CHAR_REQUEST =0x06 |
||
70 | SIO_SET_ERROR_CHAR_REQUEST =0x07 |
||
71 | SIO_SET_LATENCY_TIMER_REQUEST=0x09 |
||
72 | SIO_GET_LATENCY_TIMER_REQUEST=0x0A |
||
73 | SIO_SET_BITMODE_REQUEST =0x0B |
||
74 | SIO_READ_PINS_REQUEST =0x0C |
||
75 | SIO_READ_EEPROM_REQUEST =0x90 |
||
76 | SIO_WRITE_EEPROM_REQUEST =0x91 |
||
77 | SIO_ERASE_EEPROM_REQUEST =0x92 |
||
78 | |||
79 | |||
80 | SIO_RESET_SIO=0 |
||
81 | SIO_RESET_PURGE_RX=1 |
||
82 | SIO_RESET_PURGE_TX=2 |
||
83 | |||
84 | SIO_DISABLE_FLOW_CTRL=0x0 |
||
85 | SIO_RTS_CTS_HS =(0x1 shl 8) |
||
86 | SIO_DTR_DSR_HS =(0x2 shl 8) |
||
87 | SIO_XON_XOFF_HS=(0x4 shl 8) |
||
88 | |||
89 | SIO_SET_DTR_MASK=0x1 |
||
90 | SIO_SET_DTR_HIGH=( 1 or ( SIO_SET_DTR_MASK shl 8)) |
||
91 | SIO_SET_DTR_LOW =( 0 or ( SIO_SET_DTR_MASK shl 8)) |
||
92 | SIO_SET_RTS_MASK=0x2 |
||
93 | SIO_SET_RTS_HIGH=( 2 or ( SIO_SET_RTS_MASK shl 8 )) |
||
94 | SIO_SET_RTS_LOW =( 0 or ( SIO_SET_RTS_MASK shl 8 )) |
||
95 | |||
96 | SIO_RTS_CTS_HS =(0x1 shl 8) |
||
97 | |||
98 | ;strings |
||
99 | my_driver db 'usbother',0 |
||
100 | nomemory_msg db 'K : no memory',13,10,0 |
||
101 | |||
102 | ; Structures |
||
103 | struct ftdi_context |
||
104 | chipType db ? |
||
105 | baudrate dd ? |
||
106 | bitbangEnabled db ? |
||
107 | readBufPtr dd ? |
||
108 | readBufOffs dd ? |
||
109 | readBufChunkSize dd ? |
||
110 | writeBufChunkSize dd ? |
||
111 | interface dd ? |
||
112 | index dd ? |
||
113 | inEP dd ? |
||
114 | outEP dd ? |
||
115 | nullP dd ? |
||
116 | next_context dd ? |
||
117 | ends |
||
118 | |||
119 | struct IOCTL |
||
120 | handle dd ? |
||
121 | io_code dd ? |
||
122 | input dd ? |
||
123 | inp_size dd ? |
||
124 | output dd ? |
||
125 | out_size dd ? |
||
126 | ends |
||
127 | |||
128 | struct usb_descr |
||
4979 | gtament | 129 | bLength db ? |
130 | bDescriptorType db ? |
||
4975 | gtament | 131 | bcdUSB dw ? |
132 | bDeviceClass db ? |
||
133 | bDeviceSubClass db ? |
||
134 | bDeviceProtocol db ? |
||
135 | bMaxPacketSize0 db ? |
||
136 | idVendor dw ? |
||
137 | idProduct dw ? |
||
138 | bcdDevice dw ? |
||
139 | iManufacturer db ? |
||
140 | iProduct db ? |
||
141 | iSerialNumber db ? |
||
142 | bNumConfigurations db ? |
||
143 | ends |
||
144 | |||
4979 | gtament | 145 | struct conf_packet |
146 | bmRequestType db ? |
||
147 | bRequest db ? |
||
148 | wValue dw ? |
||
149 | wIndex dw ? |
||
150 | wLength dw ? |
||
151 | ends |
||
152 | |||
4975 | gtament | 153 | section '.flat' code readable align 16 |
154 | ; The start procedure. |
||
155 | proc START stdcall, .reason:DWORD |
||
156 | |||
157 | xor eax, eax ; initialize return value |
||
158 | cmp [.reason], 1 ; compare the argument |
||
159 | jnz .nothing |
||
160 | stdcall RegUSBDriver, my_driver, service_proc, usb_functions |
||
161 | |||
162 | .nothing: |
||
4979 | gtament | 163 | ret |
4975 | gtament | 164 | endp |
165 | |||
166 | |||
167 | proc AddDevice stdcall uses ebx, .config_pipe:DWORD, .config_descr:DWORD, .interface:DWORD |
||
168 | |||
169 | stdcall USBGetParam, [.config_pipe], 0 |
||
4979 | gtament | 170 | DEBUGF 1,'K : Device detected Vendor: %x\n', [eax+usb_descr.idVendor] |
171 | cmp word[eax+usb_descr.idVendor], 0x0403 |
||
4975 | gtament | 172 | jnz .notftdi |
173 | DEBUGF 1,'K : FTDI USB device detected\n' |
||
174 | movi eax, sizeof.ftdi_context |
||
175 | call Kmalloc |
||
176 | test eax, eax |
||
177 | jnz @f |
||
178 | mov esi, nomemory_msg |
||
179 | call SysMsgBoardStr |
||
180 | xor eax, eax |
||
181 | jmp .nothing |
||
182 | @@: |
||
183 | DEBUGF 1,'K : Adding struct to list %x\n', eax |
||
184 | call linkedlist.add |
||
185 | |||
186 | mov ebx, [.config_pipe] |
||
187 | mov [eax + ftdi_context.nullP], ebx |
||
188 | |||
189 | DEBUGF 1,'K : Open first pipe\n' |
||
190 | mov ebx, eax |
||
191 | stdcall USBOpenPipe, [.config_pipe], 0x81, 0x40, BULK_PIPE, 0 |
||
192 | mov [ebx + ftdi_context.inEP], eax |
||
193 | DEBUGF 1,'K : Open second pipe\n' |
||
194 | stdcall USBOpenPipe, [.config_pipe], 0x02, 0x40, BULK_PIPE, 0 |
||
195 | mov [ebx + ftdi_context.outEP], eax |
||
196 | |||
197 | .nothing: |
||
198 | ret |
||
199 | .notftdi: |
||
200 | DEBUGF 1,'K : Skipping not FTDI device\n' |
||
201 | xor eax, eax |
||
202 | ret |
||
203 | endp |
||
204 | |||
205 | |||
206 | handle equ IOCTL.handle |
||
207 | io_code equ IOCTL.io_code |
||
208 | input equ IOCTL.input |
||
209 | inp_size equ IOCTL.inp_size |
||
210 | output equ IOCTL.output |
||
211 | out_size equ IOCTL.out_size |
||
212 | |||
213 | align 4 |
||
214 | proc service_proc stdcall uses ebx esi edi, ioctl:DWORD |
||
215 | locals |
||
216 | ConfPacket rb 8 |
||
217 | EventData rd 2 |
||
218 | endl |
||
4979 | gtament | 219 | mov edi, [ioctl] |
220 | mov eax, [edi + io_code] |
||
4975 | gtament | 221 | DEBUGF 1,'K : FTDI got the request: %d\n', eax |
4979 | gtament | 222 | test eax, eax ;0 |
223 | jz .version |
||
224 | dec eax ;1 |
||
225 | jz .ftdi_get_list |
||
226 | dec eax ;2 |
||
227 | jz .ftdi_set_bitmode |
||
4975 | gtament | 228 | |
229 | .version: |
||
230 | .endswitch: |
||
4979 | gtament | 231 | xor eax, eax |
4975 | gtament | 232 | ret |
233 | |||
234 | .ftdi_set_bitmode: |
||
235 | DEBUGF 1,'K : FTDI Seting bitmode\n' |
||
4979 | gtament | 236 | xor ecx, ecx |
237 | xor esi, esi |
||
4975 | gtament | 238 | call CreateEvent |
4979 | gtament | 239 | mov edi, [ioctl] |
4975 | gtament | 240 | DEBUGF 1,'K : Event created %x %x\n' , eax, edx |
241 | mov [EventData], eax |
||
4979 | gtament | 242 | mov [EventData+4], edx |
243 | mov dword[ConfPacket], (FTDI_DEVICE_IN_REQTYPE) + (SIO_SET_BITMODE_REQUEST shl 8) + (0x0000 shl 16) |
||
4975 | gtament | 244 | mov edi, [edi+input] |
4979 | gtament | 245 | mov dx, word[edi+4] |
246 | mov word[ConfPacket+4], dx |
||
247 | DEBUGF 1,'K : ConfPacket %x %x\n', [ConfPacket], [ConfPacket+4] |
||
248 | mov ebx, [edi] |
||
4975 | gtament | 249 | lea esi, [ConfPacket] |
4979 | gtament | 250 | lea edi, [EventData] |
4975 | gtament | 251 | stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP], esi, 0, 0, control_callback, edi, 0 |
252 | DEBUGF 1, 'K : Returned value is %d\n', eax |
||
4979 | gtament | 253 | mov eax, [EventData] |
254 | mov ebx, [EventData+4] |
||
4975 | gtament | 255 | call WaitEvent |
256 | jmp .endswitch |
||
4979 | gtament | 257 | |
4975 | gtament | 258 | .ftdi_read_pins: |
259 | DEBUGF 1,'K : FTDI Reading pins\n' |
||
260 | call CreateEvent |
||
261 | mov [EventData], eax |
||
4979 | gtament | 262 | mov [EventData+4], edx |
4975 | gtament | 263 | mov eax, FTDI_DEVICE_IN_REQTYPE + (SIO_READ_PINS_REQUEST shl 8) |
264 | mov dword[ConfPacket], eax |
||
265 | jmp .endswitch |
||
4979 | gtament | 266 | |
4975 | gtament | 267 | .ftdi_get_list: |
4979 | gtament | 268 | call linkedlist.gethead |
4975 | gtament | 269 | mov edi, [edi+output] |
4979 | gtament | 270 | mov [edi], eax |
271 | DEBUGF 1, 'K : FTDI Device pointer %x\n', [edi] |
||
272 | mov eax, 4 |
||
4975 | gtament | 273 | mov [edi+out_size], eax |
274 | jmp .endswitch |
||
275 | endp |
||
276 | restore handle |
||
277 | restore io_code |
||
278 | restore input |
||
279 | restore inp_size |
||
280 | restore output |
||
281 | restore out_size |
||
282 | |||
283 | |||
284 | align 4 |
||
285 | proc control_callback stdcall uses ebx, .pipe:DWORD, .status:DWORD, .buffer:DWORD, .length:DWORD, .calldata:DWORD |
||
286 | |||
287 | mov eax, [.calldata] |
||
4979 | gtament | 288 | mov ebx, [.calldata+4] |
289 | DEBUGF 1,'K : EventData %x %x', [.calldata], [.calldata+4] |
||
290 | xor edx, edx |
||
4975 | gtament | 291 | call RaiseEvent |
292 | DEBUGF 1, 'K : status is %d\n', [.status+24h] |
||
293 | ret |
||
294 | endp |
||
295 | |||
296 | |||
297 | proc DeviceDisconnected stdcall uses ebx esi edi, .device_data:DWORD |
||
298 | |||
299 | DEBUGF 1, 'K : FTDI deleting device data\n' |
||
300 | mov eax, [.device_data] |
||
4979 | gtament | 301 | call linkedlist.delete |
302 | ret |
||
4975 | gtament | 303 | endp |
304 | |||
305 | include 'linkedlist.inc' |
||
306 | |||
307 | ; Exported variable: kernel API version. |
||
308 | align 4 |
||
309 | version dd 50005h |
||
310 | ; Structure with callback functions. |
||
311 | usb_functions: |
||
312 | dd 12 |
||
313 | dd AddDevice |
||
314 | dd DeviceDisconnected |
||
315 | |||
316 | ;for DEBUGF macro |
||
317 | include_debug_strings |
||
318 | |||
319 | |||
320 | |||
321 | |||
322 | ; for uninitialized data |
||
323 | ;section '.data' data readable writable align 16 |