Minor quickscreen and pitchscreen fixes
[kugel-rb.git] / firmware / usbstack / usb_core.c
blob5fac5d3815893ebacfdca0fddd4fc85c9fac75ff
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 by Bj�rn Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "system.h"
22 #include "thread.h"
23 #include "kernel.h"
24 #include "string.h"
25 //#define LOGF_ENABLE
26 #include "logf.h"
28 #include "usb.h"
29 #include "usb_ch9.h"
30 #include "usb_drv.h"
31 #include "usb_core.h"
32 #include "usb_class_driver.h"
34 #if defined(USB_STORAGE)
35 #include "usb_storage.h"
36 #endif
38 #if defined(USB_SERIAL)
39 #include "usb_serial.h"
40 #endif
42 #if defined(USB_CHARGING_ONLY)
43 #include "usb_charging_only.h"
44 #endif
46 /* TODO: Move target-specific stuff somewhere else (serial number reading) */
48 #ifdef HAVE_AS3514
49 #include "ascodec.h"
50 #include "as3514.h"
51 #endif
53 #if !defined(HAVE_AS3514) && !defined(IPOD_ARCH) && (CONFIG_STORAGE & STORAGE_ATA)
54 #include "ata.h"
55 #endif
57 #ifndef USB_MAX_CURRENT
58 #define USB_MAX_CURRENT 500
59 #endif
61 /*-------------------------------------------------------------------------*/
62 /* USB protocol descriptors: */
64 #define USB_SC_SCSI 0x06 /* Transparent */
65 #define USB_PROT_BULK 0x50 /* bulk only */
67 static const struct usb_device_descriptor __attribute__((aligned(2)))
68 device_descriptor=
70 .bLength = sizeof(struct usb_device_descriptor),
71 .bDescriptorType = USB_DT_DEVICE,
72 #ifndef USB_NO_HIGH_SPEED
73 .bcdUSB = 0x0200,
74 #else
75 .bcdUSB = 0x0110,
76 #endif
77 .bDeviceClass = USB_CLASS_PER_INTERFACE,
78 .bDeviceSubClass = 0,
79 .bDeviceProtocol = 0,
80 .bMaxPacketSize0 = 64,
81 .idVendor = USB_VENDOR_ID,
82 .idProduct = USB_PRODUCT_ID,
83 .bcdDevice = 0x0100,
84 .iManufacturer = 1,
85 .iProduct = 2,
86 .iSerialNumber = 3,
87 .bNumConfigurations = 1
88 } ;
90 static struct usb_config_descriptor __attribute__((aligned(2)))
91 config_descriptor =
93 .bLength = sizeof(struct usb_config_descriptor),
94 .bDescriptorType = USB_DT_CONFIG,
95 .wTotalLength = 0, /* will be filled in later */
96 .bNumInterfaces = 1,
97 .bConfigurationValue = 1,
98 .iConfiguration = 0,
99 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
100 .bMaxPower = (USB_MAX_CURRENT+1) / 2, /* In 2mA units */
104 static const struct usb_qualifier_descriptor __attribute__((aligned(2)))
105 qualifier_descriptor =
107 .bLength = sizeof(struct usb_qualifier_descriptor),
108 .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
109 .bcdUSB = 0x0200,
110 .bDeviceClass = 0,
111 .bDeviceSubClass = 0,
112 .bDeviceProtocol = 0,
113 .bMaxPacketSize0 = 64,
114 .bNumConfigurations = 1
117 static const struct usb_string_descriptor __attribute__((aligned(2)))
118 usb_string_iManufacturer =
121 USB_DT_STRING,
122 {'R','o','c','k','b','o','x','.','o','r','g'}
125 static const struct usb_string_descriptor __attribute__((aligned(2)))
126 usb_string_iProduct =
129 USB_DT_STRING,
130 {'R','o','c','k','b','o','x',' ',
131 'm','e','d','i','a',' ',
132 'p','l','a','y','e','r'}
135 static struct usb_string_descriptor __attribute__((aligned(2)))
136 usb_string_iSerial =
139 USB_DT_STRING,
140 {'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0',
141 '0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0',
142 '0','0','0','0','0','0','0','0','0'}
145 /* Generic for all targets */
147 /* this is stringid #0: languages supported */
148 static const struct usb_string_descriptor __attribute__((aligned(2)))
149 lang_descriptor =
152 USB_DT_STRING,
153 {0x0409} /* LANGID US English */
156 static const struct usb_string_descriptor* const usb_strings[] =
158 &lang_descriptor,
159 &usb_string_iManufacturer,
160 &usb_string_iProduct,
161 &usb_string_iSerial
164 static int usb_address = 0;
165 static bool initialized = false;
166 static enum { DEFAULT, ADDRESS, CONFIGURED } usb_state;
168 static int usb_core_num_interfaces;
170 typedef void (*completion_handler_t)(int ep,int dir, int status, int length);
171 typedef bool (*control_handler_t)(struct usb_ctrlrequest* req);
173 static struct
175 completion_handler_t completion_handler[2];
176 control_handler_t control_handler[2];
177 struct usb_transfer_completion_event_data completion_event;
178 } ep_data[USB_NUM_ENDPOINTS];
180 static struct usb_class_driver drivers[USB_NUM_DRIVERS] =
182 #ifdef USB_STORAGE
183 [USB_DRIVER_MASS_STORAGE] = {
184 .enabled = false,
185 .needs_exclusive_storage = true,
186 .first_interface = 0,
187 .last_interface = 0,
188 .request_endpoints = usb_storage_request_endpoints,
189 .set_first_interface = usb_storage_set_first_interface,
190 .get_config_descriptor = usb_storage_get_config_descriptor,
191 .init_connection = usb_storage_init_connection,
192 .init = usb_storage_init,
193 .disconnect = usb_storage_disconnect,
194 .transfer_complete = usb_storage_transfer_complete,
195 .control_request = usb_storage_control_request,
196 #ifdef HAVE_HOTSWAP
197 .notify_hotswap = usb_storage_notify_hotswap,
198 #endif
200 #endif
201 #ifdef USB_SERIAL
202 [USB_DRIVER_SERIAL] = {
203 .enabled = false,
204 .needs_exclusive_storage = false,
205 .first_interface = 0,
206 .last_interface = 0,
207 .request_endpoints = usb_serial_request_endpoints,
208 .set_first_interface = usb_serial_set_first_interface,
209 .get_config_descriptor = usb_serial_get_config_descriptor,
210 .init_connection = usb_serial_init_connection,
211 .init = usb_serial_init,
212 .disconnect = usb_serial_disconnect,
213 .transfer_complete = usb_serial_transfer_complete,
214 .control_request = usb_serial_control_request,
215 #ifdef HAVE_HOTSWAP
216 .notify_hotswap = NULL,
217 #endif
219 #endif
220 #ifdef USB_CHARGING_ONLY
221 [USB_DRIVER_CHARGING_ONLY] = {
222 .enabled = false,
223 .needs_exclusive_storage = false,
224 .first_interface = 0,
225 .last_interface = 0,
226 .request_endpoints = usb_charging_only_request_endpoints,
227 .set_first_interface = usb_charging_only_set_first_interface,
228 .get_config_descriptor = usb_charging_only_get_config_descriptor,
229 .init_connection = NULL,
230 .init = NULL,
231 .disconnect = NULL,
232 .transfer_complete = NULL,
233 .control_request = NULL,
234 #ifdef HAVE_HOTSWAP
235 .notify_hotswap = NULL,
236 #endif
238 #endif
241 static void usb_core_control_request_handler(struct usb_ctrlrequest* req);
243 static unsigned char response_data[256] USB_DEVBSS_ATTR;
246 static short hex[16] = {'0','1','2','3','4','5','6','7',
247 '8','9','A','B','C','D','E','F'};
248 #ifdef IPOD_ARCH
249 static void set_serial_descriptor(void)
251 #ifdef IPOD_VIDEO
252 uint32_t* serial = (uint32_t*)(0x20004034);
253 #else
254 uint32_t* serial = (uint32_t*)(0x20002034);
255 #endif
257 /* We need to convert from a little-endian 64-bit int
258 into a utf-16 string of hex characters */
259 short* p = &usb_string_iSerial.wString[24];
260 uint32_t x;
261 int i,j;
263 for (i = 0; i < 2; i++) {
264 x = serial[i];
265 for (j=0;j<8;j++) {
266 *p-- = hex[x & 0xf];
267 x >>= 4;
270 usb_string_iSerial.bLength=52;
272 #elif defined(HAVE_AS3514)
273 static void set_serial_descriptor(void)
275 unsigned char serial[16];
276 /* Align 32 digits right in the 40-digit serial number */
277 short* p = &usb_string_iSerial.wString[1];
278 int i;
280 ascodec_readbytes(AS3514_UID_0, 0x10, serial);
281 for (i = 0; i < 16; i++) {
282 *p++ = hex[(serial[i] >> 4) & 0xF];
283 *p++ = hex[(serial[i] >> 0) & 0xF];
285 usb_string_iSerial.bLength=68;
287 #elif (CONFIG_STORAGE & STORAGE_ATA)
288 /* If we don't know the device serial number, use the one
289 * from the disk */
290 static void set_serial_descriptor(void)
292 short* p = &usb_string_iSerial.wString[1];
293 unsigned short* identify = ata_get_identify();
294 unsigned short x;
295 int i;
297 for (i = 10; i < 20; i++) {
298 x = identify[i];
299 *p++ = hex[(x >> 12) & 0xF];
300 *p++ = hex[(x >> 8) & 0xF];
301 *p++ = hex[(x >> 4) & 0xF];
302 *p++ = hex[(x >> 0) & 0xF];
304 usb_string_iSerial.bLength=84;
306 #elif (CONFIG_STORAGE & STORAGE_RAMDISK)
307 /* This "serial number" isn't unique, but it should never actually
308 appear in non-testing use */
309 static void set_serial_descriptor(void)
311 short* p = &usb_string_iSerial.wString[1];
312 int i;
313 for (i = 0; i < 16; i++) {
314 *p++ = hex[(2*i)&0xF];
315 *p++ = hex[(2*i+1)&0xF];
317 usb_string_iSerial.bLength=68;
319 #else
320 #warning No proper set_serial_descriptor() implementation for this target
321 static void set_serial_descriptor(void)
323 short* p = &usb_string_iSerial.wString[1];
324 int i;
325 for (i = 0; i < 16; i++) {
326 *p++ = hex[(2*i)&0xF];
327 *p++ = hex[(2*i+1)&0xF];
329 usb_string_iSerial.bLength=68;
331 #endif
333 void usb_core_init(void)
335 int i;
336 if (initialized)
337 return;
339 usb_drv_init();
341 /* class driver init functions should be safe to call even if the driver
342 * won't be used. This simplifies other logic (i.e. we don't need to know
343 * yet which drivers will be enabled */
344 for(i=0;i<USB_NUM_DRIVERS;i++) {
345 if(drivers[i].enabled && drivers[i].init != NULL)
346 drivers[i].init();
349 initialized = true;
350 usb_state = DEFAULT;
351 logf("usb_core_init() finished");
354 void usb_core_exit(void)
356 int i;
357 for(i=0;i<USB_NUM_DRIVERS;i++) {
358 if(drivers[i].enabled && drivers[i].disconnect != NULL)
360 drivers[i].disconnect ();
361 drivers[i].enabled = false;
365 if (initialized) {
366 usb_drv_exit();
368 initialized = false;
369 usb_state = DEFAULT;
370 logf("usb_core_exit() finished");
373 void usb_core_handle_transfer_completion(
374 struct usb_transfer_completion_event_data* event)
376 int ep = event->endpoint;
378 switch(ep) {
379 case EP_CONTROL:
380 logf("ctrl handled %ld",current_tick);
381 usb_core_control_request_handler(
382 (struct usb_ctrlrequest*)event->data);
383 break;
384 default:
385 if(ep_data[ep].completion_handler[event->dir>>7] != NULL)
386 ep_data[ep].completion_handler[event->dir>>7](ep,event->dir,
387 event->status,event->length);
388 break;
392 void usb_core_enable_driver(int driver,bool enabled)
394 drivers[driver].enabled = enabled;
397 bool usb_core_driver_enabled(int driver)
399 return drivers[driver].enabled;
402 bool usb_core_any_exclusive_storage(void)
404 int i;
405 for(i=0;i<USB_NUM_DRIVERS;i++) {
406 if(drivers[i].enabled &&
407 drivers[i].needs_exclusive_storage)
409 return true;
413 return false;
416 #ifdef HAVE_HOTSWAP
417 void usb_core_hotswap_event(int volume,bool inserted)
419 int i;
420 for(i=0;i<USB_NUM_DRIVERS;i++) {
421 if(drivers[i].enabled &&
422 drivers[i].notify_hotswap!=NULL)
424 drivers[i].notify_hotswap(volume,inserted);
428 #endif
430 static void usb_core_set_serial_function_id(void)
432 int id = 0;
433 int i;
434 for(i=0;i<USB_NUM_DRIVERS;i++) {
435 if(drivers[i].enabled)
436 id |= 1<<i;
438 usb_string_iSerial.wString[0] = hex[id];
441 int usb_core_request_endpoint(int dir, struct usb_class_driver *drv)
443 int ret, ep;
445 ret = usb_drv_request_endpoint(dir);
447 if (ret == -1)
448 return -1;
450 ep = ret & 0x7f;
451 dir = ret >> 7;
453 ep_data[ep].completion_handler[dir] = drv->transfer_complete;
454 ep_data[ep].control_handler[dir] = drv->control_request;
456 return ret;
459 void usb_core_release_endpoint(int ep)
461 int dir;
463 usb_drv_release_endpoint(ep);
465 dir = ep >> 7;
466 ep &= 0x7f;
468 ep_data[ep].completion_handler[dir] = NULL;
469 ep_data[ep].control_handler[dir] = NULL;
472 static void allocate_interfaces_and_endpoints(void)
474 int i;
475 int interface=0;
477 memset(ep_data,0,sizeof(ep_data));
479 for (i = 0; i < USB_NUM_ENDPOINTS; i++) {
480 usb_drv_release_endpoint(i | USB_DIR_OUT);
481 usb_drv_release_endpoint(i | USB_DIR_IN);
484 for(i=0; i < USB_NUM_DRIVERS; i++) {
485 if(drivers[i].enabled) {
486 drivers[i].first_interface = interface;
488 if (drivers[i].request_endpoints(&drivers[i])) {
489 drivers[i].enabled = false;
490 continue;
493 interface = drivers[i].set_first_interface(interface);
494 drivers[i].last_interface = interface;
497 usb_core_num_interfaces = interface;
500 static void usb_core_control_request_handler(struct usb_ctrlrequest* req)
502 int i;
503 if(usb_state == DEFAULT) {
504 set_serial_descriptor();
505 usb_core_set_serial_function_id();
507 allocate_interfaces_and_endpoints();
510 switch(req->bRequestType & 0x1f) {
511 case 0: /* Device */
512 switch (req->bRequest) {
513 case USB_REQ_GET_CONFIGURATION: {
514 logf("usb_core: GET_CONFIG");
515 if (usb_state == ADDRESS)
516 response_data[0] = 0;
517 else
518 response_data[0] = 1;
519 if(usb_drv_send(EP_CONTROL, response_data, 1)!= 0)
520 break;
521 usb_core_ack_control(req);
522 break;
523 case USB_REQ_SET_CONFIGURATION:
524 logf("usb_core: SET_CONFIG");
525 usb_drv_cancel_all_transfers();
526 if (req->wValue) {
527 usb_state = CONFIGURED;
528 for(i=0;i<USB_NUM_DRIVERS;i++) {
529 if(drivers[i].enabled &&
530 drivers[i].init_connection!=NULL)
532 drivers[i].init_connection();
536 else {
537 usb_state = ADDRESS;
539 usb_core_ack_control(req);
540 break;
542 case USB_REQ_SET_ADDRESS: {
543 unsigned char address = req->wValue;
544 logf("usb_core: SET_ADR %d", address);
545 if(usb_core_ack_control(req)!=0)
546 break;
547 usb_drv_cancel_all_transfers();
548 usb_address = address;
549 usb_drv_set_address(usb_address);
550 usb_state = ADDRESS;
551 break;
553 case USB_REQ_GET_DESCRIPTOR: {
554 int index = req->wValue & 0xff;
555 int length = req->wLength;
556 int size;
557 const void* ptr = NULL;
558 logf("usb_core: GET_DESC %d", req->wValue >> 8);
560 switch (req->wValue >> 8) { /* type */
561 case USB_DT_DEVICE:
562 ptr = &device_descriptor;
563 size = sizeof(struct usb_device_descriptor);
564 break;
566 case USB_DT_OTHER_SPEED_CONFIG:
567 case USB_DT_CONFIG: {
568 int max_packet_size;
570 if(req->wValue >> 8 == USB_DT_CONFIG) {
571 if(usb_drv_port_speed())
572 max_packet_size=512;
573 else
574 max_packet_size=64;
575 config_descriptor.bDescriptorType=USB_DT_CONFIG;
577 else {
578 if(usb_drv_port_speed())
579 max_packet_size=64;
580 else
581 max_packet_size=512;
582 config_descriptor.bDescriptorType =
583 USB_DT_OTHER_SPEED_CONFIG;
585 size = sizeof(struct usb_config_descriptor);
587 for(i=0;i<USB_NUM_DRIVERS;i++) {
588 if(drivers[i].enabled &&
589 drivers[i].get_config_descriptor)
591 size+=drivers[i].get_config_descriptor(
592 &response_data[size],
593 max_packet_size);
596 config_descriptor.bNumInterfaces =
597 usb_core_num_interfaces;
598 config_descriptor.wTotalLength = size;
599 memcpy(&response_data[0],&config_descriptor,
600 sizeof(struct usb_config_descriptor));
602 ptr = response_data;
603 break;
606 case USB_DT_STRING:
607 logf("STRING %d",index);
608 if ((unsigned)index < (sizeof(usb_strings)/
609 sizeof(struct usb_string_descriptor*)))
611 size = usb_strings[index]->bLength;
612 ptr = usb_strings[index];
614 else {
615 logf("bad string id %d", index);
616 usb_drv_stall(EP_CONTROL, true,true);
618 break;
620 case USB_DT_DEVICE_QUALIFIER:
621 ptr = &qualifier_descriptor;
622 size = sizeof (struct usb_qualifier_descriptor);
623 break;
625 default:
626 logf("bad desc %d", req->wValue >> 8);
627 usb_drv_stall(EP_CONTROL, true,true);
628 break;
631 if (ptr) {
632 length = MIN(size, length);
634 if (ptr != response_data) {
635 memcpy(response_data, ptr, length);
638 if(usb_drv_send(EP_CONTROL, response_data, length)!=0)
639 break;
641 usb_core_ack_control(req);
642 break;
643 } /* USB_REQ_GET_DESCRIPTOR */
644 case USB_REQ_CLEAR_FEATURE:
645 break;
646 case USB_REQ_SET_FEATURE:
647 if(req->wValue == 2) { /* TEST_MODE */
648 int mode=req->wIndex>>8;
649 usb_core_ack_control(req);
650 usb_drv_set_test_mode(mode);
652 break;
653 case USB_REQ_GET_STATUS:
654 response_data[0]= 0;
655 response_data[1]= 0;
656 if(usb_drv_send(EP_CONTROL, response_data, 2)!=0)
657 break;
658 usb_core_ack_control(req);
659 break;
660 default:
661 break;
663 break;
664 case 1: /* Interface */
665 switch (req->bRequest) {
666 case USB_REQ_SET_INTERFACE:
667 logf("usb_core: SET_INTERFACE");
668 usb_core_ack_control(req);
669 break;
671 case USB_REQ_GET_INTERFACE:
672 logf("usb_core: GET_INTERFACE");
673 response_data[0] = 0;
674 if(usb_drv_send(EP_CONTROL, response_data, 1)!=0)
675 break;
676 usb_core_ack_control(req);
677 break;
678 case USB_REQ_CLEAR_FEATURE:
679 break;
680 case USB_REQ_SET_FEATURE:
681 break;
682 case USB_REQ_GET_STATUS:
683 response_data[0]= 0;
684 response_data[1]= 0;
685 if(usb_drv_send(EP_CONTROL, response_data, 2)!=0)
686 break;
687 usb_core_ack_control(req);
688 break;
689 default: {
690 bool handled=false;
691 for(i=0;i<USB_NUM_DRIVERS;i++) {
692 if(drivers[i].enabled &&
693 drivers[i].control_request &&
694 drivers[i].first_interface <= (req->wIndex) &&
695 drivers[i].last_interface > (req->wIndex))
697 handled = drivers[i].control_request(req);
700 if(!handled) {
701 /* nope. flag error */
702 logf("usb bad req %d", req->bRequest);
703 usb_drv_stall(EP_CONTROL, true,true);
704 usb_core_ack_control(req);
706 break;
709 break;
710 case 2: /* Endpoint */
711 switch (req->bRequest) {
712 case USB_REQ_CLEAR_FEATURE:
713 if (req->wValue == 0 ) /* ENDPOINT_HALT */
714 usb_drv_stall(req->wIndex & 0xf, false,
715 (req->wIndex & 0x80) !=0);
716 usb_core_ack_control(req);
717 break;
718 case USB_REQ_SET_FEATURE:
719 if (req->wValue == 0 ) /* ENDPOINT_HALT */
720 usb_drv_stall(req->wIndex & 0xf, true,
721 (req->wIndex & 0x80) !=0);
722 usb_core_ack_control(req);
723 break;
724 case USB_REQ_GET_STATUS:
725 response_data[0]= 0;
726 response_data[1]= 0;
727 logf("usb_core: GET_STATUS");
728 if(req->wIndex>0)
729 response_data[0] = usb_drv_stalled(req->wIndex&0xf,
730 (req->wIndex&0x80)!=0);
731 if(usb_drv_send(EP_CONTROL, response_data, 2)!=0)
732 break;
733 usb_core_ack_control(req);
734 break;
735 default: {
736 bool handled=false;
737 if(ep_data[req->wIndex & 0xf].control_handler[0] != NULL)
738 handled = ep_data[req->wIndex & 0xf].control_handler[0](req);
739 if(!handled) {
740 /* nope. flag error */
741 logf("usb bad req %d", req->bRequest);
742 usb_drv_stall(EP_CONTROL, true,true);
743 usb_core_ack_control(req);
745 break;
749 logf("control handled");
752 /* called by usb_drv_int() */
753 void usb_core_bus_reset(void)
755 usb_address = 0;
756 usb_state = DEFAULT;
759 /* called by usb_drv_transfer_completed() */
760 void usb_core_transfer_complete(int endpoint, int dir, int status,int length)
762 switch (endpoint) {
763 case EP_CONTROL:
764 /* already handled */
765 break;
767 default:
768 ep_data[endpoint].completion_event.endpoint=endpoint;
769 ep_data[endpoint].completion_event.dir=dir;
770 ep_data[endpoint].completion_event.data=0;
771 ep_data[endpoint].completion_event.status=status;
772 ep_data[endpoint].completion_event.length=length;
773 /* All other endoints. Let the thread deal with it */
774 usb_signal_transfer_completion(&ep_data[endpoint].completion_event);
775 break;
779 /* called by usb_drv_int() */
780 void usb_core_control_request(struct usb_ctrlrequest* req)
782 ep_data[0].completion_event.endpoint=0;
783 ep_data[0].completion_event.dir=0;
784 ep_data[0].completion_event.data=(void *)req;
785 ep_data[0].completion_event.status=0;
786 ep_data[0].completion_event.length=0;
787 logf("ctrl received %ld",current_tick);
788 usb_signal_transfer_completion(&ep_data[0].completion_event);
791 int usb_core_ack_control(struct usb_ctrlrequest* req)
793 if (req->bRequestType & 0x80)
794 return usb_drv_recv(EP_CONTROL, NULL, 0);
795 else
796 return usb_drv_send(EP_CONTROL, NULL, 0);
799 #ifdef HAVE_USB_POWER
800 unsigned short usb_allowed_current()
802 if (usb_state == CONFIGURED)
804 return MAX(USB_MAX_CURRENT, 100);
806 else
808 return 100;
811 #endif