Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6 | f9daq | 1 | /************************************************************************\ |
2 | ## ## |
||
3 | ## Creation Date: 18 Mar 2007 ## |
||
4 | ## Last Update: 18 Mar 2007 ## |
||
5 | ## Author: EviLove ## |
||
6 | ## ## |
||
7 | \************************************************************************/ |
||
8 | |||
9 | |||
10 | #include "usmcpkt.h" |
||
11 | #include <linux/usb.h> |
||
12 | #include <linux/usbdevice_fs.h> |
||
13 | #include <linux/usb/ch9.h> |
||
14 | #include <linux/module.h> // kzalloc (), kfree () |
||
15 | #include <asm/uaccess.h> |
||
16 | |||
17 | #include <linux/slab.h> |
||
18 | |||
19 | #define BYTE_I(i) (*(((__u8 * )pPacketData)+i)) |
||
20 | #define FIRST_BYTE(pPacketData) (*((__u8 * )pPacketData)) |
||
21 | #define SECOND_BYTE(pPacketData) (*(((__u8 * )pPacketData)+1)) |
||
22 | #define THIRD_BYTE(pPacketData) (*(((__u8 * )pPacketData)+2)) |
||
23 | #define FOURTH_BYTE(pPacketData) (*(((__u8 * )pPacketData)+3)) |
||
24 | #define FIRST_WORD(pPacketData) (*((__u16 * )pPacketData)) |
||
25 | #define SECOND_WORD(pPacketData) (*(((__u16 * )pPacketData)+1)) |
||
26 | #define FIRST_WORD_SWAPPED(pPacketData) ((FIRST_BYTE(pPacketData)<<8)|SECOND_BYTE(pPacketData)) |
||
27 | #define SECOND_WORD_SWAPPED(pPacketData) ((THIRD_BYTE(pPacketData)<<8)|FOURTH_BYTE(pPacketData)) |
||
28 | #define PACK_WORD(w) (HIBYTE(w)|(LOBYTE(w)<<8)) |
||
29 | #define REST_DATA(pPacketData) ((void *)(((__u16 * )pPacketData)+2)) |
||
30 | |||
31 | |||
32 | char * user_to_kernel ( const char * user_buf, int len ) |
||
33 | { |
||
34 | char * kern_buf; |
||
35 | int i; |
||
36 | |||
37 | kern_buf = ( char * ) kzalloc ( ( ssize_t ) len, GFP_KERNEL ); |
||
38 | |||
39 | for ( i = 0 ; i < len ; i++ ) |
||
40 | get_user ( kern_buf [i], user_buf + i ); |
||
41 | |||
42 | return kern_buf; |
||
43 | } |
||
44 | |||
45 | |||
46 | |||
47 | |||
48 | void bsp_GetDescriptor ( int descriptorType, |
||
49 | __u8 * bRequestType, |
||
50 | __u8 * bRequest, |
||
51 | __u16 * wValue, |
||
52 | __u16 * wIndex, |
||
53 | __u16 * wLength ) |
||
54 | { |
||
55 | *bRequestType = USB_DIR_IN | |
||
56 | USB_RECIP_DEVICE | |
||
57 | USB_TYPE_STANDARD; |
||
58 | *bRequest = 0x06; |
||
59 | |||
60 | switch ( descriptorType ) |
||
61 | { |
||
62 | case GET_DESCRIPTOR_CONFIGURATION: |
||
63 | *wValue = 0x0200; |
||
64 | *wIndex = 0x0000; |
||
65 | *wLength = 0x0009; |
||
66 | |||
67 | break; |
||
68 | case GET_DESCRIPTOR_DEVICE: |
||
69 | *wValue = 0x0100; |
||
70 | *wIndex = 0x0000; |
||
71 | *wLength = 0x0012; |
||
72 | |||
73 | break; |
||
74 | case GET_DESCRIPTOR_STRING: |
||
75 | *wValue = 0x0300; |
||
76 | *wIndex = 0x0409; |
||
77 | *wLength = 0x0002; |
||
78 | |||
79 | break; |
||
80 | } |
||
81 | } |
||
82 | |||
83 | |||
84 | |||
85 | |||
86 | void bsp_GetStatus ( int statusType, |
||
87 | __u8 * bRequestType, |
||
88 | __u8 * bRequest, |
||
89 | __u16 * wValue, |
||
90 | __u16 * wIndex, |
||
91 | __u16 * wLength ) |
||
92 | { |
||
93 | *bRequest = 0x00; |
||
94 | *wValue = 0x0000; |
||
95 | *wIndex = 0x0000; |
||
96 | *wLength = 0x0002; |
||
97 | |||
98 | switch ( statusType ) |
||
99 | { |
||
100 | case GET_STATUS_DEVICE: |
||
101 | |||
102 | *bRequestType = USB_DIR_IN | |
||
103 | USB_RECIP_DEVICE | |
||
104 | USB_TYPE_STANDARD; |
||
105 | |||
106 | break; |
||
107 | case GET_STATUS_ENDPOINT: |
||
108 | *bRequestType = USB_DIR_IN | |
||
109 | USB_RECIP_ENDPOINT | |
||
110 | USB_TYPE_STANDARD; |
||
111 | |||
112 | break; |
||
113 | case GET_STATUS_INTERFACE: |
||
114 | *bRequestType = USB_DIR_IN | |
||
115 | USB_RECIP_INTERFACE | |
||
116 | USB_TYPE_STANDARD; |
||
117 | |||
118 | break; |
||
119 | } |
||
120 | } |
||
121 | |||
122 | |||
123 | |||
124 | |||
125 | void bsp_GetVersion ( __u8 * bRequestType, |
||
126 | __u8 * bRequest, |
||
127 | __u16 * wValue, |
||
128 | __u16 * wIndex, |
||
129 | __u16 * wLength ) |
||
130 | { |
||
131 | *bRequestType = USB_DIR_IN | |
||
132 | USB_RECIP_DEVICE | |
||
133 | USB_TYPE_STANDARD; |
||
134 | *bRequest = 0x06; |
||
135 | *wValue = 0x0304; |
||
136 | *wIndex = 0x0409; |
||
137 | *wLength = 0x0006; |
||
138 | } |
||
139 | |||
140 | |||
141 | |||
142 | |||
143 | void bsp_GetSerial ( __u8 * bRequestType, |
||
144 | __u8 * bRequest, |
||
145 | __u16 * wValue, |
||
146 | __u16 * wIndex, |
||
147 | __u16 * wLength ) |
||
148 | { |
||
149 | *bRequestType = USB_DIR_IN | |
||
150 | USB_RECIP_DEVICE | |
||
151 | USB_TYPE_VENDOR; |
||
152 | *bRequest = 0xC9; // Dec: 201 |
||
153 | *wValue = 0x0000; |
||
154 | *wIndex = 0x0000; |
||
155 | *wLength = 0x0010; // Dec: 16 |
||
156 | } |
||
157 | |||
158 | |||
159 | |||
160 | |||
161 | void bsp_GetEncoderState ( __u8 * bRequestType, |
||
162 | __u8 * bRequest, |
||
163 | __u16 * wValue, |
||
164 | __u16 * wIndex, |
||
165 | __u16 * wLength ) |
||
166 | { |
||
167 | *bRequestType = USB_DIR_IN | |
||
168 | USB_RECIP_DEVICE | |
||
169 | USB_TYPE_VENDOR; |
||
170 | *bRequest = 0x85; // Dec: 133 |
||
171 | *wValue = 0x0000; |
||
172 | *wIndex = 0x0000; |
||
173 | *wLength = 0x0008; |
||
174 | } |
||
175 | |||
176 | |||
177 | |||
178 | |||
179 | void bsp_GetState ( __u8 * bRequestType, |
||
180 | __u8 * bRequest, |
||
181 | __u16 * wValue, |
||
182 | __u16 * wIndex, |
||
183 | __u16 * wLength ) |
||
184 | { |
||
185 | *bRequestType = USB_DIR_IN | |
||
186 | USB_RECIP_DEVICE | |
||
187 | USB_TYPE_VENDOR; |
||
188 | *bRequest = 0x82; // Dec: 130 |
||
189 | *wValue = 0x0000; |
||
190 | *wIndex = 0x0000; |
||
191 | *wLength = 0x000B; // Dec: 11 |
||
192 | } |
||
193 | |||
194 | |||
195 | |||
196 | |||
197 | char * bsp_GoTo ( const char * user_buf, |
||
198 | __u8 * bRequestType, |
||
199 | __u8 * bRequest, |
||
200 | __u16 * wValue, |
||
201 | __u16 * wIndex, |
||
202 | __u16 * wLength ) |
||
203 | { |
||
204 | char * kern_buf; |
||
205 | *bRequestType = USB_DIR_OUT | |
||
206 | USB_RECIP_DEVICE | |
||
207 | USB_TYPE_VENDOR; |
||
208 | *bRequest = 0x80; // Dec: 128 |
||
209 | *wLength = 0x0003; |
||
210 | kern_buf = user_to_kernel ( user_buf, *wLength + 4 ); |
||
211 | *wIndex = FIRST_WORD ( kern_buf ); |
||
212 | *wValue = SECOND_WORD ( kern_buf ); |
||
213 | |||
214 | return kern_buf; |
||
215 | } |
||
216 | |||
217 | |||
218 | |||
219 | |||
220 | char * bsp_SetMode ( const char * user_buf, |
||
221 | __u8 * bRequestType, |
||
222 | __u8 * bRequest, |
||
223 | __u16 * wValue, |
||
224 | __u16 * wIndex, |
||
225 | __u16 * wLength ) |
||
226 | { |
||
227 | char * kern_buf; |
||
228 | *bRequestType = USB_DIR_OUT | |
||
229 | USB_RECIP_DEVICE | |
||
230 | USB_TYPE_VENDOR; |
||
231 | *bRequest = 0x81; // Dec: 129 |
||
232 | *wLength = 0x0003; |
||
233 | kern_buf = user_to_kernel ( user_buf, *wLength + 4 ); |
||
234 | *wValue = FIRST_WORD_SWAPPED ( kern_buf ); |
||
235 | *wIndex = SECOND_WORD_SWAPPED ( kern_buf ); |
||
236 | |||
237 | |||
238 | return kern_buf; |
||
239 | } |
||
240 | |||
241 | |||
242 | |||
243 | |||
244 | char * bsp_SetParameters ( const char * user_buf, |
||
245 | __u8 * bRequestType, |
||
246 | __u8 * bRequest, |
||
247 | __u16 * wValue, |
||
248 | __u16 * wIndex, |
||
249 | __u16 * wLength ) |
||
250 | { |
||
251 | char * kern_buf; |
||
252 | *bRequestType = USB_DIR_OUT | |
||
253 | USB_RECIP_DEVICE | |
||
254 | USB_TYPE_VENDOR; |
||
255 | *bRequest = 0x83; // Dec: 131 |
||
256 | *wLength = 0x0035; // Dec: 53 |
||
257 | kern_buf = user_to_kernel ( user_buf, *wLength + 4 ); |
||
258 | *wValue = FIRST_WORD_SWAPPED ( kern_buf ); |
||
259 | *wIndex = SECOND_WORD ( kern_buf ); |
||
260 | |||
261 | return kern_buf; |
||
262 | } |
||
263 | |||
264 | |||
265 | |||
266 | |||
267 | char * bsp_Download ( const char * user_buf, |
||
268 | __u8 * bRequestType, |
||
269 | __u8 * bRequest, |
||
270 | __u16 * wValue, |
||
271 | __u16 * wIndex, |
||
272 | __u16 * wLength ) |
||
273 | { |
||
274 | char * kern_buf; |
||
275 | *bRequestType = USB_DIR_OUT | |
||
276 | USB_RECIP_DEVICE | |
||
277 | USB_TYPE_VENDOR; |
||
278 | *bRequest = 0xC8; // Dec: 200 |
||
279 | *wLength = 0x003D; // Dec: 61 |
||
280 | kern_buf = user_to_kernel ( user_buf, *wLength + 4 ); |
||
281 | *wValue = FIRST_WORD_SWAPPED ( kern_buf ); |
||
282 | *wIndex = SECOND_WORD_SWAPPED ( kern_buf ); |
||
283 | |||
284 | return kern_buf; |
||
285 | } |
||
286 | |||
287 | |||
288 | |||
289 | |||
290 | char * bsp_SetSerial ( const char * user_buf, |
||
291 | __u8 * bRequestType, |
||
292 | __u8 * bRequest, |
||
293 | __u16 * wValue, |
||
294 | __u16 * wIndex, |
||
295 | __u16 * wLength ) |
||
296 | { |
||
297 | char * kern_buf; |
||
298 | *bRequestType = USB_DIR_OUT | |
||
299 | USB_RECIP_DEVICE | |
||
300 | USB_TYPE_VENDOR; |
||
301 | *bRequest = 0xCA; // Dec: 202 |
||
302 | *wLength = 0x001C; // Dec: 28 |
||
303 | kern_buf = user_to_kernel ( user_buf, *wLength + 4 ); |
||
304 | *wValue = FIRST_WORD_SWAPPED ( kern_buf ); |
||
305 | *wIndex = SECOND_WORD_SWAPPED ( kern_buf ); |
||
306 | |||
307 | return kern_buf; |
||
308 | } |
||
309 | |||
310 | |||
311 | |||
312 | |||
313 | void bsp_SetCurrentPosition ( const char * user_buf, |
||
314 | __u8 * bRequestType, |
||
315 | __u8 * bRequest, |
||
316 | __u16 * wValue, |
||
317 | __u16 * wIndex, |
||
318 | __u16 * wLength ) |
||
319 | { |
||
320 | char * kern_buf; |
||
321 | *bRequestType = USB_DIR_OUT | |
||
322 | USB_RECIP_DEVICE | |
||
323 | USB_TYPE_VENDOR; |
||
324 | *bRequest = 0x01; |
||
325 | *wLength = 0x0000; |
||
326 | kern_buf = user_to_kernel ( user_buf, *wLength + 4 ); |
||
327 | *wValue = SECOND_WORD ( kern_buf ); |
||
328 | *wIndex = FIRST_WORD ( kern_buf ); |
||
329 | } |
||
330 | |||
331 | |||
332 | |||
333 | |||
334 | void bsp_StopStepMotor ( __u8 * bRequestType, |
||
335 | __u8 * bRequest, |
||
336 | __u16 * wValue, |
||
337 | __u16 * wIndex, |
||
338 | __u16 * wLength ) |
||
339 | { |
||
340 | *bRequestType = USB_DIR_OUT | |
||
341 | USB_RECIP_DEVICE | |
||
342 | USB_TYPE_VENDOR; |
||
343 | *bRequest = 0x07; |
||
344 | *wLength = 0x0000; |
||
345 | *wValue = 0x0000; |
||
346 | *wIndex = 0x0000; |
||
347 | } |
||
348 | |||
349 | |||
350 | |||
351 | |||
352 | void bsp_EmulateButtons ( const char * user_buf, |
||
353 | __u8 * bRequestType, |
||
354 | __u8 * bRequest, |
||
355 | __u16 * wValue, |
||
356 | __u16 * wIndex, |
||
357 | __u16 * wLength ) |
||
358 | { |
||
359 | char * kern_buf; |
||
360 | *bRequestType = USB_DIR_OUT | |
||
361 | USB_RECIP_DEVICE | |
||
362 | USB_TYPE_VENDOR; |
||
363 | *bRequest = 0x0D; // Dec: 13 |
||
364 | *wLength = 0x0000; |
||
365 | kern_buf = user_to_kernel ( user_buf, *wLength + 1 ); |
||
366 | *wValue = FIRST_BYTE ( kern_buf ); |
||
367 | *wIndex = 0x0000; |
||
368 | } |
||
369 | |||
370 | |||
371 | |||
372 | |||
373 | void bsp_SaveParameters ( __u8 * bRequestType, |
||
374 | __u8 * bRequest, |
||
375 | __u16 * wValue, |
||
376 | __u16 * wIndex, |
||
377 | __u16 * wLength ) |
||
378 | { |
||
379 | *bRequestType = USB_DIR_OUT | |
||
380 | USB_RECIP_DEVICE | |
||
381 | USB_TYPE_VENDOR; |
||
382 | *bRequest = 0x84; // Dec: 132 |
||
383 | *wLength = 0x0000; |
||
384 | *wValue = 0x0000; |
||
385 | *wIndex = 0x0000; |
||
386 | } |