STM32: USB: properly catch device's GET_DESCRIPTOR requests
[bertos.git] / bertos / cpu / cortex-m3 / drv / usb_stm32.c
index 6b0b28e1d31751fa582330cfc33f9d5d922834c4..89782fca20454d8a03df0f7bd6628be08741f774 100644 (file)
@@ -1381,6 +1381,17 @@ static void UsbGetDescriptor(void)
        }
 }
 
+/* USB setup packet: class/vendor request handler */
+static void usb_event_handler(struct usb_device *dev)
+{
+       /*
+        * TODO: get the appropriate usb_dev in function of the endpoint
+        * address.
+        */
+       if (dev->event_cb)
+               dev->event_cb(&setup_packet);
+}
+
 /* USB setup packet: GET_DESCRIPTOR handler */
 static void UBS_GetDescriptorHandler(void)
 {
@@ -1390,6 +1401,9 @@ static void UBS_GetDescriptorHandler(void)
        if ((setup_packet.mRequestType & USB_RECIP_MASK) ==
                        USB_RECIP_DEVICE)
                UsbGetDescriptor();
+       /* Getting descriptor for a device is a standard request */
+       else if ((setup_packet.mRequestType & USB_DIR_MASK) == USB_DIR_IN)
+               usb_event_handler(usb_dev);
        else
                ep_cnfg[CTRL_ENP_OUT].status = STALLED;
 }
@@ -1555,17 +1569,6 @@ static void USB_StandardRequestHandler(void)
        }
 }
 
-/* USB setup packet: class/vendor request handler */
-static void USB_EventHandler(void)
-{
-       /*
-        * TODO: get the appropriate usb_dev in function of the endpoint
-        * address.
-        */
-       if (usb_dev->event_cb)
-               usb_dev->event_cb(&setup_packet);
-}
-
 /* USB setup packet handler */
 static void USB_SetupHandler(void)
 {
@@ -1581,13 +1584,13 @@ static void USB_SetupHandler(void)
        case USB_TYPE_CLASS:
                LOG_INFO("%s: bmRequestType=%02x (Class)\n",
                                __func__, setup_packet.mRequestType);
-               USB_EventHandler();
+               usb_event_handler(usb_dev);
                break;
        /* Vendor */
        case USB_TYPE_VENDOR:
                LOG_INFO("%s: bmRequestType=%02x (Vendor)\n",
                                __func__, setup_packet.mRequestType);
-               USB_EventHandler();
+               usb_event_handler(usb_dev);
                break;
        case USB_TYPE_RESERVED:
                LOG_INFO("%s: bmRequestType=%02x (Reserved)\n",