summaryrefslogtreecommitdiff
path: root/firmware/usbstack/usb_core.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/usbstack/usb_core.c')
-rw-r--r--firmware/usbstack/usb_core.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/firmware/usbstack/usb_core.c b/firmware/usbstack/usb_core.c
index 4bc0443477..9ece4fc796 100644
--- a/firmware/usbstack/usb_core.c
+++ b/firmware/usbstack/usb_core.c
@@ -172,7 +172,7 @@ static int usb_no_host_callback(struct timeout *tmo)
172static int usb_core_num_interfaces; 172static int usb_core_num_interfaces;
173 173
174typedef void (*completion_handler_t)(int ep, int dir, int status, int length); 174typedef void (*completion_handler_t)(int ep, int dir, int status, int length);
175typedef bool (*control_handler_t)(struct usb_ctrlrequest* req, 175typedef bool (*control_handler_t)(struct usb_ctrlrequest* req, void* reqdata,
176 unsigned char* dest); 176 unsigned char* dest);
177 177
178static struct 178static struct
@@ -262,7 +262,7 @@ static struct usb_class_driver drivers[USB_NUM_DRIVERS] =
262#endif 262#endif
263}; 263};
264 264
265static void usb_core_control_request_handler(struct usb_ctrlrequest* req); 265static void usb_core_control_request_handler(struct usb_ctrlrequest* req, void* reqdata);
266 266
267static unsigned char response_data[256] USB_DEVBSS_ATTR; 267static unsigned char response_data[256] USB_DEVBSS_ATTR;
268 268
@@ -449,7 +449,7 @@ void usb_core_handle_transfer_completion(
449 ((struct usb_ctrlrequest*)event->data[0])->bRequest); 449 ((struct usb_ctrlrequest*)event->data[0])->bRequest);
450 450
451 usb_core_control_request_handler( 451 usb_core_control_request_handler(
452 (struct usb_ctrlrequest*)event->data[0]); 452 (struct usb_ctrlrequest*)event->data[0], event->data[1]);
453 break; 453 break;
454 default: 454 default:
455 handler = ep_data[ep].completion_handler[EP_DIR(event->dir)]; 455 handler = ep_data[ep].completion_handler[EP_DIR(event->dir)];
@@ -560,7 +560,7 @@ static void allocate_interfaces_and_endpoints(void)
560} 560}
561 561
562 562
563static void control_request_handler_drivers(struct usb_ctrlrequest* req) 563static void control_request_handler_drivers(struct usb_ctrlrequest* req, void* reqdata)
564{ 564{
565 int i, interface = req->wIndex & 0xff; 565 int i, interface = req->wIndex & 0xff;
566 bool handled = false; 566 bool handled = false;
@@ -571,7 +571,7 @@ static void control_request_handler_drivers(struct usb_ctrlrequest* req)
571 drivers[i].first_interface <= interface && 571 drivers[i].first_interface <= interface &&
572 drivers[i].last_interface > interface) 572 drivers[i].last_interface > interface)
573 { 573 {
574 handled = drivers[i].control_request(req, response_data); 574 handled = drivers[i].control_request(req, reqdata, response_data);
575 if(handled) 575 if(handled)
576 break; 576 break;
577 } 577 }
@@ -583,7 +583,7 @@ static void control_request_handler_drivers(struct usb_ctrlrequest* req)
583 } 583 }
584} 584}
585 585
586static void request_handler_device_get_descriptor(struct usb_ctrlrequest* req) 586static void request_handler_device_get_descriptor(struct usb_ctrlrequest* req, void* reqdata)
587{ 587{
588 int size; 588 int size;
589 const void* ptr = NULL; 589 const void* ptr = NULL;
@@ -662,7 +662,7 @@ static void request_handler_device_get_descriptor(struct usb_ctrlrequest* req)
662 662
663 default: 663 default:
664 logf("ctrl desc."); 664 logf("ctrl desc.");
665 control_request_handler_drivers(req); 665 control_request_handler_drivers(req, reqdata);
666 break; 666 break;
667 } 667 }
668 668
@@ -718,7 +718,7 @@ static void usb_core_do_clear_feature(int recip, int recip_nr, int feature)
718 } 718 }
719} 719}
720 720
721static void request_handler_device(struct usb_ctrlrequest* req) 721static void request_handler_device(struct usb_ctrlrequest* req, void* reqdata)
722{ 722{
723 switch(req->bRequest) { 723 switch(req->bRequest) {
724 case USB_REQ_GET_CONFIGURATION: { 724 case USB_REQ_GET_CONFIGURATION: {
@@ -744,7 +744,7 @@ static void request_handler_device(struct usb_ctrlrequest* req)
744 } 744 }
745 case USB_REQ_GET_DESCRIPTOR: 745 case USB_REQ_GET_DESCRIPTOR:
746 logf("usb_core: GET_DESC %d", req->wValue >> 8); 746 logf("usb_core: GET_DESC %d", req->wValue >> 8);
747 request_handler_device_get_descriptor(req); 747 request_handler_device_get_descriptor(req, reqdata);
748 break; 748 break;
749 case USB_REQ_CLEAR_FEATURE: 749 case USB_REQ_CLEAR_FEATURE:
750 break; 750 break;
@@ -768,7 +768,7 @@ static void request_handler_device(struct usb_ctrlrequest* req)
768 } 768 }
769} 769}
770 770
771static void request_handler_interface_standard(struct usb_ctrlrequest* req) 771static void request_handler_interface_standard(struct usb_ctrlrequest* req, void* reqdata)
772{ 772{
773 switch (req->bRequest) 773 switch (req->bRequest)
774 { 774 {
@@ -794,19 +794,19 @@ static void request_handler_interface_standard(struct usb_ctrlrequest* req)
794 usb_drv_send(EP_CONTROL, response_data, 2); 794 usb_drv_send(EP_CONTROL, response_data, 2);
795 break; 795 break;
796 default: 796 default:
797 control_request_handler_drivers(req); 797 control_request_handler_drivers(req, reqdata);
798 break; 798 break;
799 } 799 }
800} 800}
801 801
802static void request_handler_interface(struct usb_ctrlrequest* req) 802static void request_handler_interface(struct usb_ctrlrequest* req, void* reqdata)
803{ 803{
804 switch(req->bRequestType & USB_TYPE_MASK) { 804 switch(req->bRequestType & USB_TYPE_MASK) {
805 case USB_TYPE_STANDARD: 805 case USB_TYPE_STANDARD:
806 request_handler_interface_standard(req); 806 request_handler_interface_standard(req, reqdata);
807 break; 807 break;
808 case USB_TYPE_CLASS: 808 case USB_TYPE_CLASS:
809 control_request_handler_drivers(req); 809 control_request_handler_drivers(req, reqdata);
810 break; 810 break;
811 case USB_TYPE_VENDOR: 811 case USB_TYPE_VENDOR:
812 default: 812 default:
@@ -816,7 +816,7 @@ static void request_handler_interface(struct usb_ctrlrequest* req)
816 } 816 }
817} 817}
818 818
819static void request_handler_endoint_drivers(struct usb_ctrlrequest* req) 819static void request_handler_endoint_drivers(struct usb_ctrlrequest* req, void* reqdata)
820{ 820{
821 bool handled = false; 821 bool handled = false;
822 control_handler_t control_handler = NULL; 822 control_handler_t control_handler = NULL;
@@ -826,7 +826,7 @@ static void request_handler_endoint_drivers(struct usb_ctrlrequest* req)
826 ep_data[EP_NUM(req->wIndex)].control_handler[EP_DIR(req->wIndex)]; 826 ep_data[EP_NUM(req->wIndex)].control_handler[EP_DIR(req->wIndex)];
827 827
828 if(control_handler) 828 if(control_handler)
829 handled = control_handler(req, response_data); 829 handled = control_handler(req, reqdata, response_data);
830 830
831 if(!handled) { 831 if(!handled) {
832 /* nope. flag error */ 832 /* nope. flag error */
@@ -835,7 +835,7 @@ static void request_handler_endoint_drivers(struct usb_ctrlrequest* req)
835 } 835 }
836} 836}
837 837
838static void request_handler_endpoint_standard(struct usb_ctrlrequest* req) 838static void request_handler_endpoint_standard(struct usb_ctrlrequest* req, void* reqdata)
839{ 839{
840 switch (req->bRequest) { 840 switch (req->bRequest) {
841 case USB_REQ_CLEAR_FEATURE: 841 case USB_REQ_CLEAR_FEATURE:
@@ -863,19 +863,19 @@ static void request_handler_endpoint_standard(struct usb_ctrlrequest* req)
863 usb_drv_send(EP_CONTROL, response_data, 2); 863 usb_drv_send(EP_CONTROL, response_data, 2);
864 break; 864 break;
865 default: 865 default:
866 request_handler_endoint_drivers(req); 866 request_handler_endoint_drivers(req, reqdata);
867 break; 867 break;
868 } 868 }
869} 869}
870 870
871static void request_handler_endpoint(struct usb_ctrlrequest* req) 871static void request_handler_endpoint(struct usb_ctrlrequest* req, void* reqdata)
872{ 872{
873 switch(req->bRequestType & USB_TYPE_MASK) { 873 switch(req->bRequestType & USB_TYPE_MASK) {
874 case USB_TYPE_STANDARD: 874 case USB_TYPE_STANDARD:
875 request_handler_endpoint_standard(req); 875 request_handler_endpoint_standard(req, reqdata);
876 break; 876 break;
877 case USB_TYPE_CLASS: 877 case USB_TYPE_CLASS:
878 request_handler_endoint_drivers(req); 878 request_handler_endoint_drivers(req, reqdata);
879 break; 879 break;
880 case USB_TYPE_VENDOR: 880 case USB_TYPE_VENDOR:
881 default: 881 default:
@@ -886,7 +886,7 @@ static void request_handler_endpoint(struct usb_ctrlrequest* req)
886} 886}
887 887
888/* Handling USB requests starts here */ 888/* Handling USB requests starts here */
889static void usb_core_control_request_handler(struct usb_ctrlrequest* req) 889static void usb_core_control_request_handler(struct usb_ctrlrequest* req, void* reqdata)
890{ 890{
891#ifdef HAVE_USB_CHARGING_ENABLE 891#ifdef HAVE_USB_CHARGING_ENABLE
892 timeout_cancel(&usb_no_host_timeout); 892 timeout_cancel(&usb_no_host_timeout);
@@ -904,13 +904,13 @@ static void usb_core_control_request_handler(struct usb_ctrlrequest* req)
904 904
905 switch(req->bRequestType & USB_RECIP_MASK) { 905 switch(req->bRequestType & USB_RECIP_MASK) {
906 case USB_RECIP_DEVICE: 906 case USB_RECIP_DEVICE:
907 request_handler_device(req); 907 request_handler_device(req, reqdata);
908 break; 908 break;
909 case USB_RECIP_INTERFACE: 909 case USB_RECIP_INTERFACE:
910 request_handler_interface(req); 910 request_handler_interface(req, reqdata);
911 break; 911 break;
912 case USB_RECIP_ENDPOINT: 912 case USB_RECIP_ENDPOINT:
913 request_handler_endpoint(req); 913 request_handler_endpoint(req, reqdata);
914 break; 914 break;
915 case USB_RECIP_OTHER: 915 case USB_RECIP_OTHER:
916 logf("unsupported recipient"); 916 logf("unsupported recipient");