diff options
-rw-r--r-- | firmware/export/usb_core.h | 1 | ||||
-rw-r--r-- | firmware/usbstack/usb_core.c | 56 | ||||
-rw-r--r-- | firmware/usbstack/usb_hid.c | 10 | ||||
-rw-r--r-- | firmware/usbstack/usb_storage.c | 2 |
4 files changed, 33 insertions, 36 deletions
diff --git a/firmware/export/usb_core.h b/firmware/export/usb_core.h index c65be5fa3c..5286dbcdfe 100644 --- a/firmware/export/usb_core.h +++ b/firmware/export/usb_core.h | |||
@@ -51,7 +51,6 @@ void usb_core_enable_driver(int driver,bool enabled); | |||
51 | bool usb_core_driver_enabled(int driver); | 51 | bool usb_core_driver_enabled(int driver); |
52 | void usb_core_handle_transfer_completion( | 52 | void usb_core_handle_transfer_completion( |
53 | struct usb_transfer_completion_event_data* event); | 53 | struct usb_transfer_completion_event_data* event); |
54 | int usb_core_ack_control(struct usb_ctrlrequest* req); | ||
55 | 54 | ||
56 | int usb_core_request_endpoint(int type, int dir,struct usb_class_driver* drv); | 55 | int usb_core_request_endpoint(int type, int dir,struct usb_class_driver* drv); |
57 | void usb_core_release_endpoint(int dir); | 56 | void usb_core_release_endpoint(int dir); |
diff --git a/firmware/usbstack/usb_core.c b/firmware/usbstack/usb_core.c index 5093b93301..7d3d14f331 100644 --- a/firmware/usbstack/usb_core.c +++ b/firmware/usbstack/usb_core.c | |||
@@ -507,6 +507,15 @@ static void allocate_interfaces_and_endpoints(void) | |||
507 | usb_core_num_interfaces = interface; | 507 | usb_core_num_interfaces = interface; |
508 | } | 508 | } |
509 | 509 | ||
510 | static int usb_core_ack_control(struct usb_ctrlrequest* req) | ||
511 | { | ||
512 | if (req->bRequestType & USB_DIR_IN) | ||
513 | return usb_drv_recv(EP_CONTROL,NULL,0); | ||
514 | else | ||
515 | return usb_drv_send(EP_CONTROL,NULL,0); | ||
516 | } | ||
517 | |||
518 | |||
510 | static void control_request_handler_drivers(struct usb_ctrlrequest* req) | 519 | static void control_request_handler_drivers(struct usb_ctrlrequest* req) |
511 | { | 520 | { |
512 | int i, interface = req->wIndex; | 521 | int i, interface = req->wIndex; |
@@ -608,11 +617,9 @@ static void request_handler_device_get_descriptor(struct usb_ctrlrequest* req) | |||
608 | memcpy(response_data,ptr,length); | 617 | memcpy(response_data,ptr,length); |
609 | } | 618 | } |
610 | 619 | ||
611 | if(usb_drv_send(EP_CONTROL,response_data,length)) | 620 | usb_drv_recv(EP_CONTROL,NULL,0); |
612 | return; | 621 | usb_drv_send(EP_CONTROL,response_data,length); |
613 | } | 622 | } |
614 | if (handled) | ||
615 | usb_core_ack_control(req); | ||
616 | } | 623 | } |
617 | 624 | ||
618 | static void request_handler_device(struct usb_ctrlrequest* req) | 625 | static void request_handler_device(struct usb_ctrlrequest* req) |
@@ -623,8 +630,8 @@ static void request_handler_device(struct usb_ctrlrequest* req) | |||
623 | case USB_REQ_GET_CONFIGURATION: { | 630 | case USB_REQ_GET_CONFIGURATION: { |
624 | logf("usb_core: GET_CONFIG"); | 631 | logf("usb_core: GET_CONFIG"); |
625 | response_data[0] = (usb_state == ADDRESS ? 0 : 1); | 632 | response_data[0] = (usb_state == ADDRESS ? 0 : 1); |
626 | if(!usb_drv_send(EP_CONTROL, response_data, 1)) | 633 | usb_drv_recv(EP_CONTROL,NULL,0); |
627 | usb_core_ack_control(req); | 634 | usb_drv_send(EP_CONTROL, response_data, 1); |
628 | break; | 635 | break; |
629 | } | 636 | } |
630 | case USB_REQ_SET_CONFIGURATION: { | 637 | case USB_REQ_SET_CONFIGURATION: { |
@@ -640,14 +647,13 @@ static void request_handler_device(struct usb_ctrlrequest* req) | |||
640 | else { | 647 | else { |
641 | usb_state = ADDRESS; | 648 | usb_state = ADDRESS; |
642 | } | 649 | } |
643 | usb_core_ack_control(req); | 650 | usb_drv_send(EP_CONTROL,NULL,0); |
644 | break; | 651 | break; |
645 | } | 652 | } |
646 | case USB_REQ_SET_ADDRESS: { | 653 | case USB_REQ_SET_ADDRESS: { |
647 | unsigned char address = req->wValue; | 654 | unsigned char address = req->wValue; |
648 | logf("usb_core: SET_ADR %d", address); | 655 | logf("usb_core: SET_ADR %d", address); |
649 | if(usb_core_ack_control(req)) | 656 | usb_drv_send(EP_CONTROL,NULL,0); |
650 | break; | ||
651 | usb_drv_cancel_all_transfers(); | 657 | usb_drv_cancel_all_transfers(); |
652 | usb_address = address; | 658 | usb_address = address; |
653 | usb_drv_set_address(usb_address); | 659 | usb_drv_set_address(usb_address); |
@@ -663,15 +669,15 @@ static void request_handler_device(struct usb_ctrlrequest* req) | |||
663 | case USB_REQ_SET_FEATURE: | 669 | case USB_REQ_SET_FEATURE: |
664 | if(req->wValue==USB_DEVICE_TEST_MODE) { | 670 | if(req->wValue==USB_DEVICE_TEST_MODE) { |
665 | int mode=req->wIndex>>8; | 671 | int mode=req->wIndex>>8; |
666 | usb_core_ack_control(req); | 672 | usb_drv_send(EP_CONTROL,NULL,0); |
667 | usb_drv_set_test_mode(mode); | 673 | usb_drv_set_test_mode(mode); |
668 | } | 674 | } |
669 | break; | 675 | break; |
670 | case USB_REQ_GET_STATUS: | 676 | case USB_REQ_GET_STATUS: |
671 | response_data[0]= 0; | 677 | response_data[0]= 0; |
672 | response_data[1]= 0; | 678 | response_data[1]= 0; |
673 | if(!usb_drv_send(EP_CONTROL, response_data, 2)) | 679 | usb_drv_recv(EP_CONTROL,NULL,0); |
674 | usb_core_ack_control(req); | 680 | usb_drv_send(EP_CONTROL, response_data, 2); |
675 | break; | 681 | break; |
676 | default: | 682 | default: |
677 | break; | 683 | break; |
@@ -684,14 +690,14 @@ static void request_handler_interface_standard(struct usb_ctrlrequest* req) | |||
684 | { | 690 | { |
685 | case USB_REQ_SET_INTERFACE: | 691 | case USB_REQ_SET_INTERFACE: |
686 | logf("usb_core: SET_INTERFACE"); | 692 | logf("usb_core: SET_INTERFACE"); |
687 | usb_core_ack_control(req); | 693 | usb_drv_send(EP_CONTROL,NULL,0); |
688 | break; | 694 | break; |
689 | 695 | ||
690 | case USB_REQ_GET_INTERFACE: | 696 | case USB_REQ_GET_INTERFACE: |
691 | logf("usb_core: GET_INTERFACE"); | 697 | logf("usb_core: GET_INTERFACE"); |
692 | response_data[0]=0; | 698 | response_data[0]=0; |
693 | if(!usb_drv_send(EP_CONTROL,response_data,1)) | 699 | usb_drv_recv(EP_CONTROL,NULL,0); |
694 | usb_core_ack_control(req); | 700 | usb_drv_send(EP_CONTROL,response_data,1); |
695 | break; | 701 | break; |
696 | case USB_REQ_CLEAR_FEATURE: | 702 | case USB_REQ_CLEAR_FEATURE: |
697 | break; | 703 | break; |
@@ -700,8 +706,8 @@ static void request_handler_interface_standard(struct usb_ctrlrequest* req) | |||
700 | case USB_REQ_GET_STATUS: | 706 | case USB_REQ_GET_STATUS: |
701 | response_data[0]=0; | 707 | response_data[0]=0; |
702 | response_data[1]=0; | 708 | response_data[1]=0; |
703 | if(!usb_drv_send(EP_CONTROL, response_data, 2)) | 709 | usb_drv_recv(EP_CONTROL,NULL,0); |
704 | usb_core_ack_control(req); | 710 | usb_drv_send(EP_CONTROL, response_data, 2); |
705 | break; | 711 | break; |
706 | default: | 712 | default: |
707 | control_request_handler_drivers(req); | 713 | control_request_handler_drivers(req); |
@@ -730,13 +736,13 @@ static void request_handler_endpoint(struct usb_ctrlrequest* req) | |||
730 | if (req->wValue==USB_ENDPOINT_HALT) { | 736 | if (req->wValue==USB_ENDPOINT_HALT) { |
731 | usb_drv_stall(EP_NUM(req->wIndex), false, EP_DIR(req->wIndex)); | 737 | usb_drv_stall(EP_NUM(req->wIndex), false, EP_DIR(req->wIndex)); |
732 | } | 738 | } |
733 | usb_core_ack_control(req); | 739 | usb_drv_send(EP_CONTROL,NULL,0); |
734 | break; | 740 | break; |
735 | case USB_REQ_SET_FEATURE: | 741 | case USB_REQ_SET_FEATURE: |
736 | if (req->wValue==USB_ENDPOINT_HALT) { | 742 | if (req->wValue==USB_ENDPOINT_HALT) { |
737 | usb_drv_stall(EP_NUM(req->wIndex), true, EP_DIR(req->wIndex)); | 743 | usb_drv_stall(EP_NUM(req->wIndex), true, EP_DIR(req->wIndex)); |
738 | } | 744 | } |
739 | usb_core_ack_control(req); | 745 | usb_drv_send(EP_CONTROL,NULL,0); |
740 | break; | 746 | break; |
741 | case USB_REQ_GET_STATUS: | 747 | case USB_REQ_GET_STATUS: |
742 | response_data[0]=0; | 748 | response_data[0]=0; |
@@ -746,8 +752,8 @@ static void request_handler_endpoint(struct usb_ctrlrequest* req) | |||
746 | response_data[0]=usb_drv_stalled(EP_NUM(req->wIndex), | 752 | response_data[0]=usb_drv_stalled(EP_NUM(req->wIndex), |
747 | EP_DIR(req->wIndex)); | 753 | EP_DIR(req->wIndex)); |
748 | } | 754 | } |
749 | if(!usb_drv_send(EP_CONTROL,response_data,2)) | 755 | usb_drv_recv(EP_CONTROL,NULL,0); |
750 | usb_core_ack_control(req); | 756 | usb_drv_send(EP_CONTROL,response_data,2); |
751 | break; | 757 | break; |
752 | default: { | 758 | default: { |
753 | bool handled; | 759 | bool handled; |
@@ -843,14 +849,6 @@ void usb_core_control_request(struct usb_ctrlrequest* req) | |||
843 | usb_signal_transfer_completion(completion_event); | 849 | usb_signal_transfer_completion(completion_event); |
844 | } | 850 | } |
845 | 851 | ||
846 | int usb_core_ack_control(struct usb_ctrlrequest* req) | ||
847 | { | ||
848 | if (req->bRequestType & USB_DIR_IN) | ||
849 | return usb_drv_recv(EP_CONTROL,NULL,0); | ||
850 | else | ||
851 | return usb_drv_send(EP_CONTROL,NULL,0); | ||
852 | } | ||
853 | |||
854 | #ifdef HAVE_USB_POWER | 852 | #ifdef HAVE_USB_POWER |
855 | unsigned short usb_allowed_current() | 853 | unsigned short usb_allowed_current() |
856 | { | 854 | { |
diff --git a/firmware/usbstack/usb_hid.c b/firmware/usbstack/usb_hid.c index 2f592fcacd..53dd767c59 100644 --- a/firmware/usbstack/usb_hid.c +++ b/firmware/usbstack/usb_hid.c | |||
@@ -739,10 +739,10 @@ bool usb_hid_control_request(struct usb_ctrlrequest *req, unsigned char *dest) | |||
739 | logf("hid: unsup. std. req"); | 739 | logf("hid: unsup. std. req"); |
740 | break; | 740 | break; |
741 | } | 741 | } |
742 | if (dest != orig_dest && | 742 | if (dest != orig_dest) |
743 | !usb_drv_send(EP_CONTROL, orig_dest, dest - orig_dest)) | ||
744 | { | 743 | { |
745 | usb_core_ack_control(req); | 744 | usb_drv_recv(EP_CONTROL, NULL, 0); /* ack */ |
745 | usb_drv_send(EP_CONTROL, orig_dest, dest - orig_dest); | ||
746 | handled = true; | 746 | handled = true; |
747 | } | 747 | } |
748 | break; | 748 | break; |
@@ -754,14 +754,14 @@ bool usb_hid_control_request(struct usb_ctrlrequest *req, unsigned char *dest) | |||
754 | { | 754 | { |
755 | case USB_HID_SET_IDLE: | 755 | case USB_HID_SET_IDLE: |
756 | logf("hid: set idle"); | 756 | logf("hid: set idle"); |
757 | usb_core_ack_control(req); | 757 | usb_drv_send(EP_CONTROL, NULL, 0); /* ack */ |
758 | handled = true; | 758 | handled = true; |
759 | break; | 759 | break; |
760 | case USB_HID_SET_REPORT: | 760 | case USB_HID_SET_REPORT: |
761 | logf("hid: set report"); | 761 | logf("hid: set report"); |
762 | if (!usb_hid_set_report(req)) | 762 | if (!usb_hid_set_report(req)) |
763 | { | 763 | { |
764 | usb_core_ack_control(req); | 764 | usb_drv_send(EP_CONTROL, NULL, 0); /* ack */ |
765 | handled = true; | 765 | handled = true; |
766 | } | 766 | } |
767 | break; | 767 | break; |
diff --git a/firmware/usbstack/usb_storage.c b/firmware/usbstack/usb_storage.c index 4ca4366e79..d16277a5f1 100644 --- a/firmware/usbstack/usb_storage.c +++ b/firmware/usbstack/usb_storage.c | |||
@@ -659,8 +659,8 @@ bool usb_storage_control_request(struct usb_ctrlrequest* req, unsigned char* des | |||
659 | *tb.max_lun --; | 659 | *tb.max_lun --; |
660 | #endif | 660 | #endif |
661 | logf("ums: getmaxlun"); | 661 | logf("ums: getmaxlun"); |
662 | usb_drv_send(EP_CONTROL, tb.max_lun, 1); | ||
663 | usb_drv_recv(EP_CONTROL, NULL, 0); /* ack */ | 662 | usb_drv_recv(EP_CONTROL, NULL, 0); /* ack */ |
663 | usb_drv_send(EP_CONTROL, tb.max_lun, 1); | ||
664 | handled = true; | 664 | handled = true; |
665 | break; | 665 | break; |
666 | } | 666 | } |