Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4049

General • Re: Adding MS OS descriptors to USB dev_lowlevel example

$
0
0
Thank you so much for the explanation. I added BOS descriptor, MS OS 2.0 descriptor and modified the device descriptor and usb_handle_setup_packet to send BOS and OS 2.0 descriptors to host as follows. But so far, I have had no luck getting it work. I mean installing and loading WINUSB driver upon plugin in. I would greatly appreciate, if you could point me where my code (descriptors and the usb_handle_setup_packet function) has the problem or share your code that you made it work.

static const struct usb_device_descriptor device_descriptor = {
.bLength = sizeof(struct usb_device_descriptor),
.bDescriptorType = USB_DT_DEVICE,
.bcdUSB = 0x0201, // USB 1.1 device 0x0110
.bDeviceClass = 0, // Specified in interface descriptor
.bDeviceSubClass = 0, // No subclass
.bDeviceProtocol = 0, // No protocol
.bMaxPacketSize0 = 64, // Max packet size for ep0
.idVendor = 0x1234, // Your vendor id
.idProduct = 0x0006, // Your product ID
.bcdDevice = 0, // No device revision number
.iManufacturer = 1, // Manufacturer string index
.iProduct = 2, // Product string index
.iSerialNumber = 0, // No serial number
.bNumConfigurations = 1 // One configuration
};



static const uint8_t bosDescriptor[0x21] = {
0x05, // bLength of this descriptor
0x0F,
0x21, 0x00, // wLength
0x01, // bNumDeviceCaps

0x1C, // bLength of this first device capability descriptor
0x10,
0x05,
0x00, // bReserved
// Microsoft OS 2.0 descriptor platform capability UUID
// from Microsoft OS 2.0 Descriptors, Table 3.
0xDF, 0x60, 0xDD, 0xD8, 0x89, 0x45, 0xC7, 0x4C,
0x9C, 0xD2, 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F,

0x00, 0x00, 0x03, 0x06, // dwWindowsVersion: Windows 8.1 (NTDDI_WINBLUE)
0xA2, 0x00, // wMSOSDescriptorSetTotalLength
0x20,
0, // bAltEnumCode
};


static const uint8_t msOs20DescriptorSet[0xA2] =
{
// Microsoft OS 2.0 Descriptor Set header (Table 10)
0x0A, 0x00, // wLength
0x00, 0x00,
0x00, 0x00, 0x03, 0x06, // dwWindowsVersion: Windows 8.1 (NTDDI_WINBLUE)
0xA2, 0x00, // wTotalLength

// Microsoft OS 2.0 compatible ID descriptor (Table 13)
0x14, 0x00, // wLength
0x03, 0x00, // 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
0x04, 0x00,
0x07, 0x00, // wPropertyDataType: REG_MULTI_SZ
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,
0x50, 0x00, // wPropertyDataLength
'{',0,'1',0,'6',0,'F',0,'6',0,'2',0,'C',0,'9',0,'7',0,'-',0,
'2',0,'F',0,'9',0,'E',0,'-',0,'4',0,'1',0,'0',0,'3',0,'-',0,
'B',0,'5',0,'4',0,'A',0,'-',0,'A',0,'9',0,'9',0,'D',0,'B',0,
'B',0,'D',0,'8',0,'C',0,'F',0,'2',0,'4',0,'}',0,0,0,0,0,
};


void usb_handle_setup_packet(void) {
volatile struct usb_setup_packet *pkt = (volatile struct usb_setup_packet *) &usb_dpram->setup_packet;
uint8_t req_direction = pkt->bmRequestType;
uint8_t req = pkt->bRequest;

// Reset PID to 1 for EP0 IN
usb_get_endpoint_configuration(EP0_IN_ADDR)->next_pid = 1u;
usb_get_endpoint_configuration(EP0_OUT_ADDR)->next_pid =1u;
if (req_direction == USB_DIR_OUT) {
if (req == USB_REQUEST_SET_ADDRESS) {
usb_set_device_address(pkt);
} else if (req == USB_REQUEST_SET_CONFIGURATION) {
usb_set_device_configuration(pkt);
} else if (req == 0xC2) {
last_write_index = pkt->wIndex;
controlWriteMode = ModeWrite;
receiving_data = true;
usb_start_transfer(usb_get_endpoint_configuration(EP0_OUT_ADDR),NULL,64);
usb_get_endpoint_configuration(EP0_OUT_ADDR)->next_pid =1u;
} else if(req == 0xC8) {
last_write_index = pkt->wIndex;
controlWriteMode = ModeSet;
receiving_data = true;
usb_start_transfer(usb_get_endpoint_configuration(EP0_OUT_ADDR),NULL,64);
usb_get_endpoint_configuration(EP0_OUT_ADDR)->next_pid =1u;
} else if(req == 0xC9) {
last_write_index = pkt->wIndex;
controlWriteMode = ModeReset;
receiving_data = true;
usb_start_transfer(usb_get_endpoint_configuration(EP0_OUT_ADDR),NULL,64);
usb_get_endpoint_configuration(EP0_OUT_ADDR)->next_pid =1u;
} else {
usb_acknowledge_out_request();
//printf("Other OUT request (0x%x)\r\n", pkt->bRequest);
}
} else if (req_direction == USB_DIR_IN) {
if (req == USB_REQUEST_GET_DESCRIPTOR) {
uint16_t descriptor_type = pkt->wValue >> 8;

switch (descriptor_type) {
case USB_DT_DEVICE:
usb_handle_device_descriptor(pkt);
printf("GET DEVICE DESCRIPTOR\r\n");
break;

case USB_DT_CONFIG:
usb_handle_config_descriptor(pkt);
printf("GET CONFIG DESCRIPTOR\r\n");
break;

case USB_DT_STRING:
usb_handle_string_descriptor(pkt);
printf("GET STRING DESCRIPTOR\r\n");
break;
case 0x0F:
printf("GET BOS DESCRIPTOR\r\n");
memcpy(ep0_wcid_buf,(uint8_t*)(&bosDescriptor[0]),33);
reading_data = true;
usb_start_transfer(usb_get_endpoint_configuration(EP0_IN_ADDR), ep0_wcid_buf, 33);
usb_get_endpoint_configuration(EP0_OUT_ADDR)->next_pid =1u;
break;
default:
break;
//printf("Unhandled GET_DESCRIPTOR type 0x%x\r\n", descriptor_type);
}
}
else if(req == 0xC3)
{
memcpy(ep0_buf_rw,(uint8_t*)(&ioRegisters[pkt->wIndex]),4);
reading_data = true;
usb_start_transfer(usb_get_endpoint_configuration(EP0_IN_ADDR), ep0_buf_rw, 4);
usb_get_endpoint_configuration(EP0_OUT_ADDR)->next_pid =1u;
}
else {
printf("Other IN request (0x%x)\r\n", pkt->bRequest);
}
}
else if (req_direction == 0xC0)
{
printf("GET OS 2.0 DESCRIPTOR \r\n");
reading_data = true;
memcpy(ep0_wcid_buf,(uint8_t*)(&msOs20DescriptorSet[0]),64);
usb_start_transfer(usb_get_endpoint_configuration(EP0_IN_ADDR), ep0_wcid_buf, 64);

memcpy(ep0_wcid_buf,(uint8_t*)(&msOs20DescriptorSet[64]),64);
usb_start_transfer(usb_get_endpoint_configuration(EP0_IN_ADDR), ep0_wcid_buf, 64);

memcpy(ep0_wcid_buf,(uint8_t*)(&msOs20DescriptorSet[128]),34);
usb_start_transfer(usb_get_endpoint_configuration(EP0_IN_ADDR), ep0_wcid_buf, 34);
usb_get_endpoint_configuration(EP0_OUT_ADDR)->next_pid =1u;
}
}

Statistics: Posted by kapico — Thu Aug 08, 2024 8:25 pm



Viewing all articles
Browse latest Browse all 4049

Trending Articles