Lars Knudsen / USBDevice_WebUSB

Fork of USBDevice_STM32F103 by Devan Lai

Files at this revision

API Documentation at this revision

Comitter:
devanlai
Date:
Sun Sep 04 09:54:47 2016 +0000
Parent:
67:39396cc073f2
Child:
70:e410de636542
Commit message:
Add Microsoft OS Descriptors 1.0 Compatible ID support

Changed in this revision

USBDFU/WebUSBDFU.cpp Show annotated file Show diff for this revision Revisions of this file
USBDFU/WinUSB.h Show annotated file Show diff for this revision Revisions of this file
--- a/USBDFU/WebUSBDFU.cpp	Sun Sep 04 03:13:09 2016 +0000
+++ b/USBDFU/WebUSBDFU.cpp	Sun Sep 04 09:54:47 2016 +0000
@@ -20,6 +20,7 @@
 #include "WebUSBDFU.h"
 #include "WebUSB.h"
 #include "DFU.h"
+#include "WinUSB.h"
 
 #include "USBDescriptor.h"
 
@@ -56,9 +57,54 @@
 bool WebUSBDFU::USBCallback_request() {
     bool success = false;
     CONTROL_TRANSFER * transfer = getTransferPtr();
-
+    
+    // Handle the Microsoft OS Descriptors 1.0 special string descriptor request
+    if ((transfer->setup.bmRequestType.Type == STANDARD_TYPE) &&
+        (transfer->setup.bRequest == GET_DESCRIPTOR) &&
+        (DESCRIPTOR_TYPE(transfer->setup.wValue) == STRING_DESCRIPTOR) &&
+        (DESCRIPTOR_INDEX(transfer->setup.wValue) == 0xEE))
+    {
+        static uint8_t msftStringDescriptor[] = {
+            0x12,                                      /* bLength */
+            STRING_DESCRIPTOR,                         /* bDescriptorType */
+            'M',0,'S',0,'F',0,'T',0,'1',0,'0',0,'0',0, /* qWSignature - MSFT100 */
+            WINUSB_VENDOR_CODE,                        /* bMS_VendorCode */
+            0x00,                                      /* bPad */
+        };
+        
+        transfer->remaining = msftStringDescriptor[0];
+        transfer->ptr = msftStringDescriptor;
+        transfer->direction = DEVICE_TO_HOST;
+        success = true;
+    }
+    // Process Microsoft OS Descriptors 1.0 Compatible ID requests
+    else if ((transfer->setup.bmRequestType.Type == VENDOR_TYPE) &&
+             (transfer->setup.bmRequestType.Recipient == DEVICE_RECIPIENT) &&
+             (transfer->setup.bRequest == WINUSB_VENDOR_CODE) &&
+             (transfer->setup.wIndex == WINUSB_GET_COMPATIBLE_ID_FEATURE_DESCRIPTOR))
+    {
+        static uint8_t msftCompatibleIdDescriptor[] = {
+            0x28, 0x00, 0x00, 0x00,         /* dwLength */
+            LSB(COMPATIBLE_ID_VERSION_1_0), /* bcdVersion (LSB) */
+            MSB(COMPATIBLE_ID_VERSION_1_0), /* bcdVersion (MSB) */
+            LSB(WINUSB_GET_COMPATIBLE_ID_FEATURE_DESCRIPTOR), /* wIndex (LSB) */
+            MSB(WINUSB_GET_COMPATIBLE_ID_FEATURE_DESCRIPTOR), /* wIndex (MSB) */
+            0x01,                           /* bCount */
+            0, 0, 0, 0, 0, 0, 0,            /* reserved */
+            DFU_INTERFACE_NUMBER,           /* bFirstInterfaceNumber */
+            0x00,                           /* reserved */
+            'W','I','N','U','S','B',0,0,    /* compatible ID - WINUSB */
+            0, 0, 0, 0, 0, 0, 0, 0,         /* subCompatibleID */
+            0, 0, 0, 0, 0, 0,               /* reserved */
+        };
+        
+        transfer->remaining = sizeof(msftCompatibleIdDescriptor);
+        transfer->ptr = msftCompatibleIdDescriptor;
+        transfer->direction = DEVICE_TO_HOST;
+        success = true;
+    }
     // Process DFU class-specific requests
-    if (transfer->setup.bmRequestType.Type == CLASS_TYPE)
+    else if (transfer->setup.bmRequestType.Type == CLASS_TYPE)
     {
         switch (transfer->setup.bRequest)
         {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDFU/WinUSB.h	Sun Sep 04 09:54:47 2016 +0000
@@ -0,0 +1,29 @@
+/*
+* Copyright 2016 Devan Lai
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*    http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef WIN_USB_H
+#define WIN_USB_H
+/* Microsoft OS 1.0 descriptors */
+
+/* Extended Compat ID OS Feature Descriptor Specification */
+#define WINUSB_GET_COMPATIBLE_ID_FEATURE_DESCRIPTOR 0x04
+#define WINUSB_GET_EXTENDED_PROPERTIES_OS_FEATURE_DESCRIPTOR 0x05
+
+#define WINUSB_VENDOR_CODE 0x21
+
+#define COMPATIBLE_ID_VERSION_1_0 (0x0100)
+
+#endif
\ No newline at end of file