USB Libraries Help > USB Device Libraries > USB Device Layer Library > Using the Library > How the Library Works > Microsoft OS Descriptor Support
MPLAB Harmony USB Stack
Microsoft OS Descriptor Support

Microsoft provides a set of proprietary device classes and USB descriptors, which are called Microsoft OS Descriptors (MODs). 

The MPLAB Harmony USB Device Library allows the application to support the Microsoft OS Descriptors requests. To enable Microsoft OS Descriptors, follow below procedure.

  1. Navigate to the USB Device Layer Configuration options through the MHC Project graph and enable following check boxes.
    1. Enable Advanced String Descriptor Table
    2. Enable Microsoft OS Descriptor Support
  2. Type in a Vendor code in the "Vendor Code" check box and generate the code.

 

  1. Add Extended Compat ID Feature Descriptor in the application. The following is a sample Extended Compat ID Feature Descriptor.
/* Extended Compat ID Feature Descriptor */
const uint8_t microsoftExtendedCompatIdDescriptor[] =
{
0x28, 0x00, 0x00, 0x00, /* dwLength Length of this descriptor */
0x00, 0x01, /* bcdVersion = Version 1.0 */
0x04, 0x00, /* wIndex = 0x0004 */
0x01, /* bCount = 1 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Reserved */
0x00, /* Interface number = 0 */
0x01, /* Reserved */
0x57, 0x49, 0x4E, 0x55, 0x53, 0x42, 0x00, 0x00, /* compatibleID */ //WINUSB
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* subCompatibleID */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* Reserved */
};

 

  1. The following code example shows how to respond to Extended Compat ID Feature Descriptor request from the Host. This code can be added to USB Device Event Handler.
case USB_DEVICE_EVENT_CONTROL_TRANSFER_SETUP_REQUEST:
{
    uint16_t length = 0;
    USB_SETUP_PACKET *setupPacket = (USB_SETUP_PACKET *)pData;
    if(setupPacket->bRequest == USB_DEVICE_MICROSOFT_OS_DESCRIPTOR_VENDOR_CODE)
    {
        if ((setupPacket->bmRequestType == 0xC0) && (setupPacket->W_Index.Val == 0x0004))
        {
           length = setupPacket->wLength;
           if (length > sizeof(microsoftExtendedCompatIdDescriptor))
           {
               length = sizeof(microsoftExtendedCompatIdDescriptor);
           }
           USB_DEVICE_ControlSend(appData.usbDevHandle, (uint8_t*)&microsoftExtendedCompatIdDescriptor, length);
        }
        else
        {
           USB_DEVICE_ControlStatus(appData.usbDevHandle, USB_DEVICE_CONTROL_STATUS_ERROR);
        }
    }
    else
    {
        USB_DEVICE_ControlStatus(appData.usbDevHandle, USB_DEVICE_CONTROL_STATUS_ERROR);
    }
    break;
}