0
0
Fork 0

feat: Add Microsoft OS 2.0 Descriptors and WinUSB Support.

This commit is contained in:
windowsair 2020-01-26 15:54:57 +08:00
parent 529e0a375f
commit 8cfb843951
6 changed files with 196 additions and 6 deletions

View File

@ -0,0 +1,84 @@
/**
* @file MSOS20Descriptors.c
* @author windowsair
* @brief Store related data of Microsoft OS 2.0 descriptor
* @version 0.1
* @date 2019-11-21
*
* @copyright Copyright (c) 2019
*
*/
////TODO: refactoring into structure
#include <stdint.h>
#include "MSOS20Descriptors.h"
#define USBShort(ui16Value) ((ui16Value) & 0xff), ((ui16Value) >> 8) //((ui16Value) & 0xFF),(((ui16Value) >> 8) & 0xFF)
// Microsoft OS 2.0 descriptor set header
const uint8_t msOs20DescriptorSetHeader[kLengthOfMsOS20] =
{
// Microsoft OS 2.0 Descriptor Set header (Table 10)
0x0A, 0x00, // wLength (Shall be set to 0x0A)
MS_OS_20_SET_HEADER_DESCRIPTOR, 0x00,
0x00, 0x00, 0x03, 0x06, // dwWindowsVersion: Windows 8.1 (NTDDI_WINBLUE)
USBShort(kLengthOfMsOS20), // wTotalLength
// Support WinUSB
// See https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/automatic-installation-of-winusb
// Microsoft OS 2.0 compatible ID descriptor (Table 13)
0x14, 0x00, // wLength
USBShort(MS_OS_20_FEATURE_COMPATIBLE_ID), // wDescriptorType
'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, // compatibleID
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // subCompatibleID
// Microsoft OS 2.0 registry property descriptor (Table 14)
0x84, 0x00, // wLength
USBShort(MS_OS_20_FEATURE_REG_PROPERTY),
0x07, 0x00, // wPropertyDataType: REG_MULTI_SZ (Unicode Strings)
0x2A, 0x00, // wPropertyNameLength
'D',0,'e',0,'v',0,'i',0,'c',0,'e',0,'I',0,'n',0,'t',0,'e',0,'r',0,
'f',0,'a',0,'c',0,'e',0,'G',0,'U',0,'I',0,'D',0,'s',0,0,0,
// Set to "DeviceInterfaceGUID" to support WinUSB
0x50, 0x00, // wPropertyDataLength
// WinUSB GUID
'{',0,'C',0,'D',0,'B',0,'3',0,'B',0,'5',0,'A',0,'D',0,'-',0,
'2',0,'9',0,'3',0,'B',0,'-',0,'4',0,'6',0,'6',0,'3',0,'-',0,
'A',0,'A',0,'3',0,'6',0,'-',0,'1',0,'A',0,'A',0,'E',0,'4',0,
'6',0,'4',0,'6',0,'3',0,'7',0,'7',0,'6',0,'}',0,0,0,0,0,
// identify a CMSIS-DAP V2 configuration,
// must set to "{CDB3B5AD-293B-4663-AA36-1AAE46463776}"
};
const uint8_t bosDescriptor[kLengthOfBos] =
{
// Universal Serial Bus 3.0 Specification, Table 9-9.
0x05, // bLength of this descriptor
USB_DESCRIPTOR_TYPE_BOS, // BOS Descriptor type(Constant)
USBShort(kLengthOfBos), // wLength
0x01, // bNumDeviceCaps
// Microsoft OS 2.0 platform capability descriptor header (Table 4)
// See also:
// Universal Serial Bus 3.0 Specification : Format of a Device Capability Descriptor, Table 9-10.
0x1C, // bLength of this first device capability descriptor
// bLength -> The total length of the remaining arrays containing this field
USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY, // bDescriptorType
USB_DEVICE_CAPABILITY_TYPE_PLATFORM, // bDevCapabilityType
// Capability-Dependent (See USB3.0 Specification Table 9-10.)
0x00, // bReserved
USB_DEVICE_CAPABILITY_UUID, // MS_OS_20_Platform_Capability_ID
0x00, 0x00, 0x03, 0x06, // dwWindowsVersion: Windows 8.1 (NTDDI_WINBLUE)
USBShort(kLengthOfMsOS20), // wMSOSDescriptorSetTotalLength(length of descriptor set header)
kValueOfbMS_VendorCode, // bMS_VendorCode (0x01 will be ok)
////TODO:change this
0, // bAltEnumCode
};

View File

@ -0,0 +1,81 @@
/**
* @file MSOS20Descriptors.h
* @author windowsair
* @brief
* @version 0.1
* @date 2019-11-21
*
* @copyright Copyright (c) 2019
*
*/
#ifndef __MSOS20DESCRIPTORS_H__
#define __MSOS20DESCRIPTORS_H__
#define kLengthOfMsOS20 0xA2
#define kLengthOfBos 0x21
#define kValueOfbMS_VendorCode 0x01// Just set to 0x01
extern const uint8_t bosDescriptor[kLengthOfBos];
extern const uint8_t msOs20DescriptorSetHeader[kLengthOfMsOS20];
/* Microsoft OS 2.0 Descriptors BEGIN */
// Platform capability BOS descriptor, Table 1.
#define USB_DEVICE_CAPABILITY_TYPE_PLATFORM 5
// Platform capability UUID, Table 3.
// {D8DD60DF-4589-4CC7-9CD2-659D9E648A9F}
#define USB_DEVICE_CAPABILITY_UUID 0xDF, 0x60, 0xDD, 0xD8, 0x89, 0x45, 0xC7, 0x4C, 0x9C, 0xD2, 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F
// Microsoft OS 2.0 descriptor wIndex values enum, Table 8.
#define MS_OS_20_DESCRIPTOR_INDEX 7
#define MS_OS_20_SET_ALT_ENUMERATION 8
// Microsoft OS 2.0 descriptor types enum for wDescriptorType values, Table 9.
#define MS_OS_20_SET_HEADER_DESCRIPTOR 0x00
#define MS_OS_20_SUBSET_HEADER_CONFIGURATION 0x01
#define MS_OS_20_SUBSET_HEADER_FUNCTION 0x02
#define MS_OS_20_FEATURE_COMPATIBLE_ID 0x03
#define MS_OS_20_FEATURE_REG_PROPERTY 0x04
#define MS_OS_20_FEATURE_MIN_RESUME_TIME 0x05
#define MS_OS_20_FEATURE_MODEL_ID 0x06
#define MS_OS_20_FEATURE_CCGP_DEVICE 0x07
/* Microsoft OS 2.0 Descriptors END */
/* Wireless USB Standard Extension Descriptor Types BEGIN */
// Wireless USB Specification 1.1 revison 1.1, Table 7-21.
#define USB_DESCRIPTOR_TYPE_SECURITY 12
#define USB_DESCRIPTOR_TYPE_KEY 13
#define USB_DESCRIPTOR_TYPE_ENCRYPTION_TYPE 14
#define USB_DESCRIPTOR_TYPE_BOS 15
#define USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY 16
#define USB_DESCRIPTOR_TYPE_WIRELESS_ENDPOINT_COMPANION 17
/* Wireless USB Standard Extension Descriptor Types END */
/* Microsoft Extended Compat ID OS Feature Descriptor BEGIN */
#define USB_MS_EXTENDED_COMPAT_ID_VERSION 0x0100
#define USB_MS_EXTENDED_COMPAT_ID_TYPE 0x04
#define USB_COMPATID_NONE {0}
#define USB_SUBCOMPATID_NONE {0}
#define USB_COMPATID_WINUSB "WINUSB\0"
#define USB_COMPATID_RNDIS "RNDIS\0\0"
#define USB_COMPATID_PTP "PTP\0\0\0\0"
#define USB_COMPATID_MTP "MTP\0\0\0\0"
#define USB_COMPATID_BLUETOOTH "BLUTUTH"
#define USB_SUBCOMPATID_BT_V11 "11\0\0\0\0\0"
#define USB_SUBCOMPATID_BT_V12 "12\0\0\0\0\0"
#define USB_SUBCOMPATID_BT_V20EDR "EDR\0\0\0\0"
/* Microsoft Extended Compat ID OS Feature Descriptor END */
#endif

View File

@ -16,11 +16,12 @@
#include "USBd_config.h"
#include "usbip_server.h"
#include "usb_defs.h"
#include "MSOS20Descriptors.h"
// handle functions
static void handleGetDescriptor(usbip_stage2_header *header);
////TODO: fill this
////TODO: may be ok
int handleUSBControlRequest(usbip_stage2_header *header)
{
// Table 9-3. Standard Device Requests
@ -154,7 +155,26 @@ int handleUSBControlRequest(usbip_stage2_header *header)
break;
}
break;
case 0xC0: // Microsoft OS 2.0 vendor-specific descriptor
uint16_t *wIndex = (uint16_t *)(&(header->u.cmd_submit.request.wIndex));
switch (*wIndex)
{
case MS_OS_20_DESCRIPTOR_INDEX:
os_printf("* GET MSOS 2.0 vendor-specific descriptor\r\n");
send_stage2_submit_data(header, 0, msOs20DescriptorSetHeader, sizeof(msOs20DescriptorSetHeader));
break;
case MS_OS_20_SET_ALT_ENUMERATION:
// set alternate enumeration command
// bAltEnumCode set to 0
os_printf("Set alternate enumeration.This should not happen.\r\n");
break;
default:
os_printf("USB unknown request, bmRequestType:%d,bRequest:%d,wIndex:%d\r\n",
header->u.cmd_submit.request.bmRequestType, header->u.cmd_submit.request.bRequest, *wIndex);
break;
}
break;
default:
os_printf("USB unknown request, bmRequestType:%d,bRequest:%d\r\n",
header->u.cmd_submit.request.bmRequestType, header->u.cmd_submit.request.bRequest);
@ -162,7 +182,7 @@ int handleUSBControlRequest(usbip_stage2_header *header)
}
}
////TODO: BOS descriptor
static void handleGetDescriptor(usbip_stage2_header *header)
{
// 9.4.3 Get Descriptor
@ -241,6 +261,10 @@ static void handleGetDescriptor(usbip_stage2_header *header)
send_stage2_submit(header, 0, 0);
break;
case USB_DT_BOS:
os_printf("* GET 0x0F BOS DESCRIPTOR\r\n");
send_stage2_submit_data(header, 0, bosDescriptor, sizeof(bosDescriptor));
break;
default:
os_printf("USB unknown Get Descriptor requested:%d", header->u.cmd_submit.request.wValue.u8lo);
break;

View File

@ -110,6 +110,7 @@ typedef struct
#define USB_DT_DEVICE_QUALIFIER 6
#define USB_DT_OTHER_SPEED_CONFIGURATION 7
#define USB_DT_INTERFACE_POWER 8
#define USB_DT_BOS 15
/* From ECNs */
#define USB_DT_OTG 9
#define USB_DT_DEBUG 10

View File

@ -33,7 +33,7 @@ enum usbip_stage1_command
};
enum usbip_stager2_command
{ ////TODO: change to stage2
{
//Offset 0
USBIP_STAGE2_REQ_SUBMIT = 0x0001,
USBIP_STAGE2_REQ_UNLINK = 0x0002,

View File

@ -39,7 +39,7 @@ int attach(uint8_t *buffer, uint32_t length)
break;
case USBIP_STAGE1_CMD_DEVICE_ATTACH: // OP_REQ_IMPORT
handle_device_attach(buffer, length); ////TODO: fill this
handle_device_attach(buffer, length);
break;
default:
@ -171,7 +171,7 @@ static void send_interface_info()
int emulate(uint8_t *buffer, uint32_t length)
{
// usbip_stage2_header header;
int command = read_stage2_command((usbip_stage2_header *)buffer, length); ////TODO: fill this
int command = read_stage2_command((usbip_stage2_header *)buffer, length);
if (command < 0)
{
return -1;
@ -253,7 +253,7 @@ static void unpack(void *data, int size)
}
}
////TODO: fill this
/**
* @brief
*