GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / include / usbstd.h
blob5e29836d27f0848c6b4991561267d4f49a95a8f0
1 /*
2 * Copyright (c) 1998 The NetBSD Foundation, Inc.
3 * All rights reserved.
5 * This code is derived from software contributed to The NetBSD Foundation
6 * by Lennart Augustsson (lennart@augustsson.net) at
7 * Carlstedt Research & Technology.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the NetBSD
20 * Foundation, Inc. and its contributors.
21 * 4. Neither the name of The NetBSD Foundation nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
37 /* FILE-CSTYLED */
39 #ifndef _USB_H_
40 #define _USB_H_
42 #include <typedefs.h>
43 typedef uint8 uByte;
44 typedef uint16 uWord;
46 #define USB_MAX_DEVICES 128
47 #define USB_START_ADDR 0
49 #define USB_CONTROL_ENDPOINT 0
50 #define USB_MAX_ENDPOINTS 16
52 #define USB_FRAMES_PER_SECOND 1000
54 #if defined(__GNUC__)
55 #define UPACKED __attribute__ ((packed))
56 #else
57 #pragma pack(1)
58 #define UPACKED
59 #endif
61 typedef struct {
62 uByte bmRequestType;
63 uByte bRequest;
64 uWord wValue;
65 uWord wIndex;
66 uWord wLength;
67 } UPACKED usb_device_request_t;
68 #define USB_DEVICE_REQUEST_SIZE 8
70 #define UT_WRITE 0x00
71 #define UT_READ 0x80
72 #define UT_STANDARD 0x00
73 #define UT_CLASS 0x20
74 #define UT_VENDOR 0x40
75 #define UT_DEVICE 0x00
76 #define UT_INTERFACE 0x01
77 #define UT_ENDPOINT 0x02
78 #define UT_OTHER 0x03
80 #define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_DEVICE)
81 #define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE)
82 #define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT)
83 #define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_DEVICE)
84 #define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE)
85 #define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT)
86 #define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_DEVICE)
87 #define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE)
88 #define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER)
89 #define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT)
90 #define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_DEVICE)
91 #define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
92 #define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER)
93 #define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT)
94 #define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_DEVICE)
95 #define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE)
96 #define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER)
97 #define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT)
98 #define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_DEVICE)
99 #define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
100 #define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER)
101 #define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
103 /* Requests */
104 #define UR_GET_STATUS 0x00
105 #define UR_CLEAR_FEATURE 0x01
106 #define UR_SET_FEATURE 0x03
107 #define UR_SET_ADDRESS 0x05
108 #define UR_GET_DESCRIPTOR 0x06
109 #define UDESC_DEVICE 0x01
110 #define UDESC_CONFIG 0x02
111 #define UDESC_STRING 0x03
112 #define UDESC_INTERFACE 0x04
113 #define UDESC_ENDPOINT 0x05
114 #define UDESC_DEVICE_QUALIFIER 0x06
115 #define UDESC_OTHER_SPEED_CONFIGURATION 0x07
116 #define UDESC_INTERFACE_POWER 0x08
117 #define UDESC_OTG 0x09
118 #define UDESC_CS_DEVICE 0x21 /* class specific */
119 #define UDESC_CS_CONFIG 0x22
120 #define UDESC_CS_STRING 0x23
121 #define UDESC_CS_INTERFACE 0x24
122 #define UDESC_CS_ENDPOINT 0x25
123 #define UDESC_HUB 0x29
124 #define UR_SET_DESCRIPTOR 0x07
125 #define UR_GET_CONFIG 0x08
126 #define UR_SET_CONFIG 0x09
127 #define UR_GET_INTERFACE 0x0a
128 #define UR_SET_INTERFACE 0x0b
129 #define UR_SYNCH_FRAME 0x0c
131 /* Feature numbers */
132 #define UF_ENDPOINT_HALT 0
133 #define UF_DEVICE_REMOTE_WAKEUP 1
134 #define UF_TEST_MODE 2
136 #define USB_MAX_IPACKET 8 /* maximum size of the initial packet */
138 #define USB_2_MAX_CTRL_PACKET 64
139 #define USB_2_MAX_BULK_PACKET 512
141 typedef struct {
142 uByte bLength;
143 uByte bDescriptorType;
144 uByte bDescriptorSubtype;
145 } UPACKED usb_descriptor_t;
147 typedef struct {
148 uByte bLength;
149 uByte bDescriptorType;
150 uWord bcdUSB;
151 #define UD_USB_2_0 0x0200
152 #define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
153 uByte bDeviceClass;
154 uByte bDeviceSubClass;
155 uByte bDeviceProtocol;
156 uByte bMaxPacketSize;
157 /* The fields below are not part of the initial descriptor. */
158 uWord idVendor;
159 uWord idProduct;
160 uWord bcdDevice;
161 uByte iManufacturer;
162 uByte iProduct;
163 uByte iSerialNumber;
164 uByte bNumConfigurations;
165 } UPACKED usb_device_descriptor_t;
166 #define USB_DEVICE_DESCRIPTOR_SIZE 18
168 typedef struct {
169 uByte bLength;
170 uByte bDescriptorType;
171 uWord wTotalLength;
172 uByte bNumInterface;
173 uByte bConfigurationValue;
174 uByte iConfiguration;
175 uByte bmAttributes;
176 #define UC_BUS_POWERED 0x80
177 #define UC_SELF_POWERED 0x40
178 #define UC_REMOTE_WAKEUP 0x20
179 uByte bMaxPower; /* max current in 2 mA units */
180 #define UC_POWER_FACTOR 2
181 } UPACKED usb_config_descriptor_t;
182 #define USB_CONFIG_DESCRIPTOR_SIZE 9
184 typedef struct {
185 uByte bLength;
186 uByte bDescriptorType;
187 uByte bInterfaceNumber;
188 uByte bAlternateSetting;
189 uByte bNumEndpoints;
190 uByte bInterfaceClass;
191 uByte bInterfaceSubClass;
192 uByte bInterfaceProtocol;
193 uByte iInterface;
194 } UPACKED usb_interface_descriptor_t;
195 #define USB_INTERFACE_DESCRIPTOR_SIZE 9
197 typedef struct {
198 uByte bLength;
199 uByte bDescriptorType;
200 uByte bEndpointAddress;
201 #define UE_GET_DIR(a) ((a) & 0x80)
202 #define UE_SET_DIR(a, d) ((a) | (((d)&1) << 7))
203 #define UE_DIR_IN 0x80
204 #define UE_DIR_OUT 0x00
205 #define UE_ADDR 0x0f
206 #define UE_GET_ADDR(a) ((a) & UE_ADDR)
207 uByte bmAttributes;
208 #define UE_XFERTYPE 0x03
209 #define UE_CONTROL 0x00
210 #define UE_ISOCHRONOUS 0x01
211 #define UE_BULK 0x02
212 #define UE_INTERRUPT 0x03
213 #define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE)
214 #define UE_ISO_TYPE 0x0c
215 #define UE_ISO_ASYNC 0x04
216 #define UE_ISO_ADAPT 0x08
217 #define UE_ISO_SYNC 0x0c
218 #define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
219 uWord wMaxPacketSize;
220 uByte bInterval;
221 } UPACKED usb_endpoint_descriptor_t;
222 #define USB_ENDPOINT_DESCRIPTOR_SIZE 7
224 typedef struct {
225 uByte bLength;
226 uByte bDescriptorType;
227 uWord bString[127];
228 } UPACKED usb_string_descriptor_t;
229 #define USB_MAX_STRING_LEN 127
230 #define USB_LANGUAGE_TABLE 0 /* # of the string language id table */
232 /* Hub specific request */
233 #define UR_GET_BUS_STATE 0x02
234 #define UR_CLEAR_TT_BUFFER 0x08
235 #define UR_RESET_TT 0x09
236 #define UR_GET_TT_STATE 0x0a
237 #define UR_STOP_TT 0x0b
239 /* Hub features */
240 #define UHF_C_HUB_LOCAL_POWER 0
241 #define UHF_C_HUB_OVER_CURRENT 1
242 #define UHF_PORT_CONNECTION 0
243 #define UHF_PORT_ENABLE 1
244 #define UHF_PORT_SUSPEND 2
245 #define UHF_PORT_OVER_CURRENT 3
246 #define UHF_PORT_RESET 4
247 #define UHF_PORT_POWER 8
248 #define UHF_PORT_LOW_SPEED 9
249 #define UHF_C_PORT_CONNECTION 16
250 #define UHF_C_PORT_ENABLE 17
251 #define UHF_C_PORT_SUSPEND 18
252 #define UHF_C_PORT_OVER_CURRENT 19
253 #define UHF_C_PORT_RESET 20
254 #define UHF_PORT_TEST 21
255 #define UHF_PORT_INDICATOR 22
257 typedef struct {
258 uByte bDescLength;
259 uByte bDescriptorType;
260 uByte bNbrPorts;
261 uWord wHubCharacteristics;
262 #define UHD_PWR 0x0003
263 #define UHD_PWR_GANGED 0x0000
264 #define UHD_PWR_INDIVIDUAL 0x0001
265 #define UHD_PWR_NO_SWITCH 0x0002
266 #define UHD_COMPOUND 0x0004
267 #define UHD_OC 0x0018
268 #define UHD_OC_GLOBAL 0x0000
269 #define UHD_OC_INDIVIDUAL 0x0008
270 #define UHD_OC_NONE 0x0010
271 #define UHD_TT_THINK 0x0060
272 #define UHD_TT_THINK_8 0x0000
273 #define UHD_TT_THINK_16 0x0020
274 #define UHD_TT_THINK_24 0x0040
275 #define UHD_TT_THINK_32 0x0060
276 #define UHD_PORT_IND 0x0080
277 uByte bPwrOn2PwrGood; /* delay in 2 ms units */
278 #define UHD_PWRON_FACTOR 2
279 uByte bHubContrCurrent;
280 uByte DeviceRemovable[32]; /* max 255 ports */
281 #define UHD_NOT_REMOV(desc, i) \
282 (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
283 /* deprecated */ uByte PortPowerCtrlMask[1];
284 } UPACKED usb_hub_descriptor_t;
285 #define USB_HUB_DESCRIPTOR_SIZE 8 /* includes deprecated PortPowerCtrlMask */
287 typedef struct {
288 uByte bLength;
289 uByte bDescriptorType;
290 uWord bcdUSB;
291 uByte bDeviceClass;
292 uByte bDeviceSubClass;
293 uByte bDeviceProtocol;
294 uByte bMaxPacketSize0;
295 uByte bNumConfigurations;
296 uByte bReserved;
297 } UPACKED usb_device_qualifier_t;
298 #define USB_DEVICE_QUALIFIER_SIZE 10
300 typedef struct {
301 uByte bLength;
302 uByte bDescriptorType;
303 uByte bmAttributes;
304 #define UOTG_SRP 0x01
305 #define UOTG_HNP 0x02
306 } UPACKED usb_otg_descriptor_t;
308 /* OTG feature selectors */
309 #define UOTG_B_HNP_ENABLE 3
310 #define UOTG_A_HNP_SUPPORT 4
311 #define UOTG_A_ALT_HNP_SUPPORT 5
313 typedef struct {
314 uWord wStatus;
315 /* Device status flags */
316 #define UDS_SELF_POWERED 0x0001
317 #define UDS_REMOTE_WAKEUP 0x0002
318 /* Endpoint status flags */
319 #define UES_HALT 0x0001
320 } UPACKED usb_status_t;
322 typedef struct {
323 uWord wHubStatus;
324 #define UHS_LOCAL_POWER 0x0001
325 #define UHS_OVER_CURRENT 0x0002
326 uWord wHubChange;
327 } UPACKED usb_hub_status_t;
329 typedef struct {
330 uWord wPortStatus;
331 #define UPS_CURRENT_CONNECT_STATUS 0x0001
332 #define UPS_PORT_ENABLED 0x0002
333 #define UPS_SUSPEND 0x0004
334 #define UPS_OVERCURRENT_INDICATOR 0x0008
335 #define UPS_RESET 0x0010
336 #define UPS_PORT_POWER 0x0100
337 #define UPS_LOW_SPEED 0x0200
338 #define UPS_HIGH_SPEED 0x0400
339 #define UPS_PORT_TEST 0x0800
340 #define UPS_PORT_INDICATOR 0x1000
341 uWord wPortChange;
342 #define UPS_C_CONNECT_STATUS 0x0001
343 #define UPS_C_PORT_ENABLED 0x0002
344 #define UPS_C_SUSPEND 0x0004
345 #define UPS_C_OVERCURRENT_INDICATOR 0x0008
346 #define UPS_C_PORT_RESET 0x0010
347 } UPACKED usb_port_status_t;
349 /* Device class codes */
350 #define UDCLASS_IN_INTERFACE 0x00
351 #define UDCLASS_COMM 0x02
352 #define UDCLASS_HUB 0x09
353 #define UDSUBCLASS_HUB 0x00
354 #define UDPROTO_FSHUB 0x00
355 #define UDPROTO_HSHUBSTT 0x01
356 #define UDPROTO_HSHUBMTT 0x02
357 #define UDCLASS_DIAGNOSTIC 0xdc
358 #define UDCLASS_WIRELESS 0xe0
359 #define UDSUBCLASS_RF 0x01
360 #define UDPROTO_BLUETOOTH 0x01
361 #define UDCLASS_VENDOR 0xff
363 /* Interface class codes */
364 #define UICLASS_UNSPEC 0x00
366 #define UICLASS_AUDIO 0x01
367 #define UISUBCLASS_AUDIOCONTROL 1
368 #define UISUBCLASS_AUDIOSTREAM 2
369 #define UISUBCLASS_MIDISTREAM 3
371 #define UICLASS_CDC 0x02 /* communication */
372 #define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1
373 #define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2
374 #define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3
375 #define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4
376 #define UISUBCLASS_CAPI_CONTROLMODEL 5
377 #define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
378 #define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
379 #define UIPROTO_CDC_AT 1
381 #define UICLASS_HID 0x03
382 #define UISUBCLASS_BOOT 1
383 #define UIPROTO_BOOT_KEYBOARD 1
385 #define UICLASS_PHYSICAL 0x05
387 #define UICLASS_IMAGE 0x06
389 #define UICLASS_PRINTER 0x07
390 #define UISUBCLASS_PRINTER 1
391 #define UIPROTO_PRINTER_UNI 1
392 #define UIPROTO_PRINTER_BI 2
393 #define UIPROTO_PRINTER_1284 3
395 #define UICLASS_MASS 0x08
396 #define UISUBCLASS_RBC 1
397 #define UISUBCLASS_SFF8020I 2
398 #define UISUBCLASS_QIC157 3
399 #define UISUBCLASS_UFI 4
400 #define UISUBCLASS_SFF8070I 5
401 #define UISUBCLASS_SCSI 6
402 #define UIPROTO_MASS_CBI_I 0
403 #define UIPROTO_MASS_CBI 1
404 #define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */
405 #define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */
407 #define UICLASS_HUB 0x09
408 #define UISUBCLASS_HUB 0
409 #define UIPROTO_FSHUB 0
410 #define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */
411 #define UIPROTO_HSHUBMTT 1
413 #define UICLASS_CDC_DATA 0x0a
414 #define UISUBCLASS_DATA 0
415 #define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */
416 #define UIPROTO_DATA_HDLC 0x31 /* HDLC */
417 #define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */
418 #define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */
419 #define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */
420 #define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */
421 #define UIPROTO_DATA_V42BIS 0x90 /* Data compression */
422 #define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */
423 #define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */
424 #define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */
425 #define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */
426 #define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc. */
427 #define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */
429 #define UICLASS_SMARTCARD 0x0b
431 /* #define UICLASS_FIRM_UPD 0x0c */
433 #define UICLASS_SECURITY 0x0d
435 #define UICLASS_DIAGNOSTIC 0xdc
437 #define UICLASS_WIRELESS 0xe0
438 #define UISUBCLASS_RF 0x01
439 #define UIPROTO_BLUETOOTH 0x01
441 #define UICLASS_APPL_SPEC 0xfe
442 #define UISUBCLASS_FIRMWARE_DOWNLOAD 1
443 #define UISUBCLASS_IRDA 2
444 #define UIPROTO_IRDA 0
446 #define UICLASS_VENDOR 0xff
449 #define USB_HUB_MAX_DEPTH 5
451 #define USB_POWER_DOWN_TIME 200 /* ms */
452 #define USB_PORT_POWER_DOWN_TIME 100 /* ms */
454 /* Allow for marginal (i.e. non-conforming) devices. */
455 #define USB_PORT_RESET_DELAY 50 /* ms */
456 #define USB_PORT_RESET_RECOVERY 50 /* ms */
457 #define USB_PORT_POWERUP_DELAY 200 /* ms */
458 #define USB_SET_ADDRESS_SETTLE 10 /* ms */
459 #define USB_RESUME_DELAY (50*5) /* ms */
460 #define USB_RESUME_WAIT 50 /* ms */
461 #define USB_RESUME_RECOVERY 50 /* ms */
462 #define USB_EXTRA_POWER_UP_TIME 20 /* ms */
464 #define USB_MIN_POWER 100 /* mA */
465 #define USB_MAX_POWER 500 /* mA */
467 #define USB_BUS_RESET_DELAY 100
470 #define USB_UNCONFIG_NO 0
471 #define USB_UNCONFIG_INDEX (-1)
474 * The USB records contain some unaligned little-endian word
475 * components. The htol/ltoh macros take care of the alignment,
476 * endian, and packing problems and should always be used to copy
477 * descriptors to and from raw byte buffers.
480 static inline int
481 htol_usb_device_request(const usb_device_request_t *d, uchar *buf)
483 *buf++ = d->bmRequestType;
484 *buf++ = d->bRequest;
485 *buf++ = d->wValue & 0xff;
486 *buf++ = d->wValue >> 8;
487 *buf++ = d->wIndex & 0xff;
488 *buf++ = d->wIndex >> 8;
489 *buf++ = d->wLength & 0xff;
490 *buf++ = d->wLength >> 8;
491 return USB_DEVICE_REQUEST_SIZE;
494 static inline int
495 ltoh_usb_device_request(const uchar *buf, usb_device_request_t *d)
497 d->bmRequestType = *buf++;
498 d->bRequest = *buf++;
499 d->wValue = (uWord)(*buf++) & 0x00ff;
500 d->wValue |= ((uWord)(*buf++) << 8) & 0xff00;
501 d->wIndex = (uWord)(*buf++) & 0x00ff;
502 d->wIndex |= ((uWord)(*buf++) << 8) & 0xff00;
503 d->wLength = (uWord)(*buf++) & 0x00ff;
504 d->wLength |= ((uWord)(*buf++) << 8) & 0xff00;
505 return USB_DEVICE_REQUEST_SIZE;
508 static inline int
509 htol_usb_device_descriptor(const usb_device_descriptor_t *d, uchar *buf)
511 *buf++ = d->bLength;
512 *buf++ = d->bDescriptorType;
513 *buf++ = d->bcdUSB & 0xff;
514 *buf++ = d->bcdUSB >> 8;
515 *buf++ = d->bDeviceClass;
516 *buf++ = d->bDeviceSubClass;
517 *buf++ = d->bDeviceProtocol;
518 *buf++ = d->bMaxPacketSize;
519 *buf++ = d->idVendor & 0xff;
520 *buf++ = d->idVendor >> 8;
521 *buf++ = d->idProduct & 0xff;
522 *buf++ = d->idProduct >> 8;
523 *buf++ = d->bcdDevice & 0xff;
524 *buf++ = d->bcdDevice >> 8;
525 *buf++ = d->iManufacturer;
526 *buf++ = d->iProduct;
527 *buf++ = d->iSerialNumber;
528 *buf++ = d->bNumConfigurations;
529 return USB_DEVICE_DESCRIPTOR_SIZE;
532 static inline int
533 ltoh_usb_device_descriptor(const char *buf, usb_device_descriptor_t *d)
535 d->bLength = *buf++;
536 d->bDescriptorType = *buf++;
537 d->bcdUSB = (uWord)(*buf++) & 0x00ff;
538 d->bcdUSB |= ((uWord)(*buf++) << 8) & 0xff00;
539 d->bDeviceClass = *buf++;
540 d->bDeviceSubClass = *buf++;
541 d->bDeviceProtocol = *buf++;
542 d->bMaxPacketSize = *buf++;
543 d->idVendor = (uWord)(*buf++) & 0x00ff;
544 d->idVendor |= ((uWord)(*buf++) << 8) & 0xff00;
545 d->idProduct = (uWord)(*buf++) & 0x00ff;
546 d->idProduct |= ((uWord)(*buf++) << 8) & 0xff00;
547 d->bcdDevice = (uWord)(*buf++) & 0x00ff;
548 d->bcdDevice |= ((uWord)(*buf++) << 8) & 0xff00;
549 d->iManufacturer = *buf++;
550 d->iProduct = *buf++;
551 d->iSerialNumber = *buf++;
552 d->bNumConfigurations = *buf++;
553 return USB_DEVICE_DESCRIPTOR_SIZE;
556 static inline int
557 htol_usb_config_descriptor(const usb_config_descriptor_t *d, uchar *buf)
559 *buf++ = d->bLength;
560 *buf++ = d->bDescriptorType;
561 *buf++ = d->wTotalLength & 0xff;
562 *buf++ = d->wTotalLength >> 8;
563 *buf++ = d->bNumInterface;
564 *buf++ = d->bConfigurationValue;
565 *buf++ = d->iConfiguration;
566 *buf++ = d->bmAttributes;
567 *buf++ = d->bMaxPower;
568 return USB_CONFIG_DESCRIPTOR_SIZE;
571 static inline int
572 ltoh_usb_config_descriptor(const char *buf, usb_config_descriptor_t *d)
574 d->bLength = *buf++;
575 d->bDescriptorType = *buf++;
576 d->wTotalLength = (uWord)(*buf++) & 0x00ff;
577 d->wTotalLength |= ((uWord)(*buf++) << 8) & 0xff00;
578 d->bNumInterface = *buf++;
579 d->bConfigurationValue = *buf++;
580 d->iConfiguration = *buf++;
581 d->bmAttributes = *buf++;
582 d->bMaxPower = *buf++;
583 return USB_CONFIG_DESCRIPTOR_SIZE;
586 static inline int
587 htol_usb_interface_descriptor(const usb_interface_descriptor_t *d, uchar *buf)
589 *buf++ = d->bLength;
590 *buf++ = d->bDescriptorType;
591 *buf++ = d->bInterfaceNumber;
592 *buf++ = d->bAlternateSetting;
593 *buf++ = d->bNumEndpoints;
594 *buf++ = d->bInterfaceClass;
595 *buf++ = d->bInterfaceSubClass;
596 *buf++ = d->bInterfaceProtocol;
597 *buf++ = d->iInterface;
598 return USB_INTERFACE_DESCRIPTOR_SIZE;
601 static inline int
602 ltoh_usb_interface_descriptor(const char *buf, usb_interface_descriptor_t *d)
604 d->bLength = *buf++;
605 d->bDescriptorType = *buf++;
606 d->bInterfaceNumber = *buf++;
607 d->bAlternateSetting = *buf++;
608 d->bNumEndpoints = *buf++;
609 d->bInterfaceClass = *buf++;
610 d->bInterfaceSubClass = *buf++;
611 d->bInterfaceProtocol = *buf++;
612 d->iInterface = *buf++;
613 return USB_INTERFACE_DESCRIPTOR_SIZE;
616 static inline int
617 htol_usb_endpoint_descriptor(const usb_endpoint_descriptor_t *d, uchar *buf)
619 *buf++ = d->bLength;
620 *buf++ = d->bDescriptorType;
621 *buf++ = d->bEndpointAddress;
622 *buf++ = d->bmAttributes;
623 *buf++ = d->wMaxPacketSize & 0xff;
624 *buf++ = d->wMaxPacketSize >> 8;
625 *buf++ = d->bInterval;
626 return USB_ENDPOINT_DESCRIPTOR_SIZE;
629 static inline int
630 ltoh_usb_endpoint_descriptor(const char *buf, usb_endpoint_descriptor_t *d)
632 d->bLength = *buf++;
633 d->bDescriptorType = *buf++;
634 d->bEndpointAddress = *buf++;
635 d->bmAttributes = *buf++;
636 d->wMaxPacketSize = (uWord)(*buf++) & 0x00ff;
637 d->wMaxPacketSize |= ((uWord)(*buf++) << 8) & 0xff00;
638 d->bInterval = *buf++;
639 return USB_ENDPOINT_DESCRIPTOR_SIZE;
642 static inline int
643 htol_usb_string_descriptor(const usb_string_descriptor_t *d, uchar *buf)
645 int i;
646 *buf++ = d->bLength;
647 *buf++ = d->bDescriptorType;
648 for (i = 0; i < ((d->bLength - 2) / 2); i++) {
649 *buf++ = d->bString[i] & 0xff;
650 *buf++ = d->bString[i] >> 8;
652 return d->bLength;
655 static inline int
656 ltoh_usb_string_descriptor(const char *buf, usb_string_descriptor_t *d)
658 int i;
659 d->bLength = *buf++;
660 d->bDescriptorType = *buf++;
661 for (i = 0; i < ((d->bLength - 2) / 2); i++) {
662 d->bString[i] = (uWord)(*buf++) & 0x00ff;
663 d->bString[i] |= ((uWord)(*buf++) << 8) & 0xff00;
665 return d->bLength;
668 static inline int
669 htol_usb_device_qualifier(const usb_device_qualifier_t *d, uchar *buf)
671 *buf++ = d->bLength;
672 *buf++ = d->bDescriptorType;
673 *buf++ = d->bcdUSB & 0xff;
674 *buf++ = d->bcdUSB >> 8;
675 *buf++ = d->bDeviceClass;
676 *buf++ = d->bDeviceSubClass;
677 *buf++ = d->bDeviceProtocol;
678 *buf++ = d->bMaxPacketSize0;
679 *buf++ = d->bNumConfigurations;
680 *buf++ = d->bReserved;
681 return USB_DEVICE_QUALIFIER_SIZE;
684 static inline int
685 ltoh_usb_device_qualifier(const char *buf, usb_device_qualifier_t *d)
687 d->bLength = *buf++;
688 d->bDescriptorType = *buf++;
689 d->bcdUSB = (uWord)(*buf++) & 0x00ff;
690 d->bcdUSB |= ((uWord)(*buf++) << 8) & 0xff00;
691 d->bDeviceClass = *buf++;
692 d->bDeviceSubClass = *buf++;
693 d->bDeviceProtocol = *buf++;
694 d->bMaxPacketSize0 = *buf++;
695 d->bNumConfigurations = *buf++;
696 d->bReserved = *buf++;
697 return USB_DEVICE_QUALIFIER_SIZE;
700 #endif /* _USB_H_ */