diff --git a/firmware/common/usb_standard_request.c b/firmware/common/usb_standard_request.c index 43b11151..bf82ab4a 100644 --- a/firmware/common/usb_standard_request.c +++ b/firmware/common/usb_standard_request.c @@ -130,13 +130,17 @@ static usb_request_status_t usb_send_descriptor( static usb_request_status_t usb_send_descriptor_string( usb_endpoint_t* const endpoint ) { - uint_fast8_t index = endpoint->setup.value_l; - for( uint_fast8_t i=0; endpoint->device->descriptor_strings[i] != 0; i++ ) { - if( i == index ) { - return usb_send_descriptor(endpoint, endpoint->device->descriptor_strings[i]); + if ((endpoint->setup.value_l == 0xee) && + (endpoint->device->wcid_string_descriptor != NULL)) { /* MS WCID string */ + return usb_send_descriptor(endpoint, endpoint->device->wcid_string_descriptor); + } else { + uint_fast8_t index = endpoint->setup.value_l; + for( uint_fast8_t i=0; endpoint->device->descriptor_strings[i] != 0; i++ ) { + if( i == index ) { + return usb_send_descriptor(endpoint, endpoint->device->descriptor_strings[i]); + } } } - return USB_REQUEST_STATUS_STALL; } @@ -212,6 +216,26 @@ static usb_request_status_t usb_standard_request_get_descriptor( } } +usb_request_status_t usb_vendor_request_read_wcid( + usb_endpoint_t* const endpoint, + const usb_transfer_stage_t stage +) { + if( stage == USB_TRANSFER_STAGE_SETUP ) { + if ((endpoint->setup.index == 0x04) && + (endpoint->device->wcid_feature_descriptor != NULL)) { + usb_send_descriptor(endpoint, endpoint->device->wcid_feature_descriptor); + return USB_REQUEST_STATUS_OK; + } + if ((endpoint->setup.index == 0x05) && + (endpoint->device->wcid_extended_properties_descriptor != NULL)) { + usb_send_descriptor(endpoint, endpoint->device->wcid_extended_properties_descriptor); + return USB_REQUEST_STATUS_OK; + } + return USB_REQUEST_STATUS_STALL; + } + return USB_REQUEST_STATUS_OK; +} + /*********************************************************************/ static usb_request_status_t usb_standard_request_set_address_setup( diff --git a/firmware/common/usb_standard_request.h b/firmware/common/usb_standard_request.h index 77fd1b10..50b92c0d 100644 --- a/firmware/common/usb_standard_request.h +++ b/firmware/common/usb_standard_request.h @@ -29,6 +29,11 @@ void usb_set_configuration_changed_cb( void (*callback)(usb_device_t* const) ); +usb_request_status_t usb_vendor_request_read_wcid( + usb_endpoint_t* const endpoint, + const usb_transfer_stage_t stage +); + usb_request_status_t usb_standard_request( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage diff --git a/firmware/common/usb_type.h b/firmware/common/usb_type.h index 8f683fc6..2a1b7cd1 100644 --- a/firmware/common/usb_type.h +++ b/firmware/common/usb_type.h @@ -127,6 +127,9 @@ typedef struct { const uint8_t* const qualifier_descriptor; usb_configuration_t* (*configurations)[]; const usb_configuration_t* configuration; + uint8_t* wcid_string_descriptor; + uint8_t* wcid_feature_descriptor; + uint8_t* wcid_extended_properties_descriptor; } usb_device_t; typedef struct usb_endpoint_t usb_endpoint_t; diff --git a/firmware/hackrf_usb/hackrf_usb.c b/firmware/hackrf_usb/hackrf_usb.c index eb424be3..8a4357a5 100644 --- a/firmware/hackrf_usb/hackrf_usb.c +++ b/firmware/hackrf_usb/hackrf_usb.c @@ -139,6 +139,7 @@ static const usb_request_handler_fn vendor_request_handler[] = { NULL, #endif usb_vendor_request_set_freq_explicit, + usb_vendor_request_read_wcid, // USB_WCID_VENDOR_REQ }; static const uint32_t vendor_request_handler_count = diff --git a/firmware/hackrf_usb/usb_descriptor.c b/firmware/hackrf_usb/usb_descriptor.c index ff770b24..bacf7dd7 100644 --- a/firmware/hackrf_usb/usb_descriptor.c +++ b/firmware/hackrf_usb/usb_descriptor.c @@ -55,10 +55,10 @@ uint8_t usb_descriptor_device[] = { USB_MAX_PACKET0, // bMaxPacketSize0 USB_WORD(USB_VENDOR_ID), // idVendor USB_WORD(USB_PRODUCT_ID), // idProduct - USB_WORD(0x0100), // bcdDevice + USB_WORD(0x0101), // bcdDevice 0x01, // iManufacturer 0x02, // iProduct - 0x05, // iSerialNumber + 0x04, // iSerialNumber 0x02 // bNumConfigurations }; @@ -70,7 +70,7 @@ uint8_t usb_descriptor_device_qualifier[] = { 0x00, // bDeviceSubClass 0x00, // bDeviceProtocol 64, // bMaxPacketSize0 - 0x02, // bNumOtherSpeedConfigurations + 0x01, // bNumOtherSpeedConfigurations 0x00 // bReserved }; @@ -148,79 +148,6 @@ uint8_t usb_descriptor_configuration_high_speed[] = { 0, // TERMINATOR }; -uint8_t usb_descriptor_configuration_cpld_update_full_speed[] = { - 9, // bLength - USB_DESCRIPTOR_TYPE_CONFIGURATION, // bDescriptorType - USB_WORD(32), // wTotalLength - 0x01, // bNumInterfaces - 0x02, // bConfigurationValue - 0x04, // iConfiguration - 0x80, // bmAttributes: USB-powered - 250, // bMaxPower: 500mA - - 9, // bLength - USB_DESCRIPTOR_TYPE_INTERFACE, // bDescriptorType - 0x00, // bInterfaceNumber - 0x00, // bAlternateSetting - 0x02, // bNumEndpoints - 0xFF, // bInterfaceClass: vendor-specific - 0xFF, // bInterfaceSubClass - 0xFF, // bInterfaceProtocol: vendor-specific - 0x00, // iInterface - - 7, // bLength - USB_DESCRIPTOR_TYPE_ENDPOINT, // bDescriptorType - USB_BULK_IN_EP_ADDR, // bEndpointAddress - 0x02, // bmAttributes: BULK - USB_WORD(USB_MAX_PACKET_BULK_FS), // wMaxPacketSize - 0x00, // bInterval: no NAK - - 7, // bLength - USB_DESCRIPTOR_TYPE_ENDPOINT, // bDescriptorType - USB_BULK_OUT_EP_ADDR, // bEndpointAddress - 0x02, // bmAttributes: BULK - USB_WORD(USB_MAX_PACKET_BULK_FS), // wMaxPacketSize - 0x00, // bInterval: no NAK - - 0, // TERMINATOR -}; - -uint8_t usb_descriptor_configuration_cpld_update_high_speed[] = { - 9, // bLength - USB_DESCRIPTOR_TYPE_CONFIGURATION, // bDescriptorType - USB_WORD(32), // wTotalLength - 0x01, // bNumInterfaces - 0x02, // bConfigurationValue - 0x04, // iConfiguration - 0x80, // bmAttributes: USB-powered - 250, // bMaxPower: 500mA - - 9, // bLength - USB_DESCRIPTOR_TYPE_INTERFACE, // bDescriptorType - 0x00, // bInterfaceNumber - 0x00, // bAlternateSetting - 0x02, // bNumEndpoints - 0xFF, // bInterfaceClass: vendor-specific - 0xFF, // bInterfaceSubClass - 0xFF, // bInterfaceProtocol: vendor-specific - 0x00, // iInterface - - 7, // bLength - USB_DESCRIPTOR_TYPE_ENDPOINT, // bDescriptorType - USB_BULK_IN_EP_ADDR, // bEndpointAddress - 0x02, // bmAttributes: BULK - USB_WORD(USB_MAX_PACKET_BULK_HS), // wMaxPacketSize - 0x00, // bInterval: no NAK - - 7, // bLength - USB_DESCRIPTOR_TYPE_ENDPOINT, // bDescriptorType - USB_BULK_OUT_EP_ADDR, // bEndpointAddress - 0x02, // bmAttributes: BULK - USB_WORD(USB_MAX_PACKET_BULK_HS), // wMaxPacketSize - 0x00, // bInterval: no NAK - - 0, // TERMINATOR -}; uint8_t usb_descriptor_string_languages[] = { 0x04, // bLength @@ -298,7 +225,7 @@ uint8_t usb_descriptor_string_product[] = { #endif }; -uint8_t usb_descriptor_string_config1_description[] = { +uint8_t usb_descriptor_string_config_description[] = { 24, // bLength USB_DESCRIPTOR_TYPE_STRING, // bDescriptorType 'T', 0x00, @@ -314,21 +241,6 @@ uint8_t usb_descriptor_string_config1_description[] = { 'r', 0x00, }; -uint8_t usb_descriptor_string_config2_description[] = { - 24, // bLength - USB_DESCRIPTOR_TYPE_STRING, // bDescriptorType - 'C', 0x00, - 'P', 0x00, - 'L', 0x00, - 'D', 0x00, - ' ', 0x00, - 'u', 0x00, - 'p', 0x00, - 'd', 0x00, - 'a', 0x00, - 't', 0x00, - 'e', 0x00, -}; uint8_t usb_descriptor_string_serial_number[USB_DESCRIPTOR_STRING_SERIAL_BUF_LEN]; @@ -336,8 +248,34 @@ uint8_t* usb_descriptor_strings[] = { usb_descriptor_string_languages, usb_descriptor_string_manufacturer, usb_descriptor_string_product, - usb_descriptor_string_config1_description, - usb_descriptor_string_config2_description, + usb_descriptor_string_config_description, usb_descriptor_string_serial_number, 0, // TERMINATOR }; + +uint8_t wcid_string_descriptor[] = { + 18, // bLength + USB_DESCRIPTOR_TYPE_STRING, // bDescriptorType + 'M', 0x00, + 'S', 0x00, + 'F', 0x00, + 'T', 0x00, + '1', 0x00, + '0', 0x00, + '0', 0x00, + USB_WCID_VENDOR_REQ, // vendor request code for further descriptor + 0x00 +}; + +uint8_t wcid_feature_descriptor[] = { + 0x28, 0x00, 0x00, 0x00, // bLength + USB_WORD(0x0100), // WCID version + USB_WORD(0x0004), // WICD descriptor index + 0x01, //bNumSections + 0x00,0x00,0x00,0x00,0x00,0x00,0x00, //Reserved + 0x00, //bInterfaceNumber + 0x01, //Reserved + 'W', 'I', 'N', 'U', 'S', 'B', 0x00,0x00, //Compatible ID, padded with zeros + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //Sub-compatible ID + 0x00,0x00,0x00,0x00,0x00,0x00 //Reserved +}; diff --git a/firmware/hackrf_usb/usb_descriptor.h b/firmware/hackrf_usb/usb_descriptor.h index bffa9bf7..e8c9d507 100644 --- a/firmware/hackrf_usb/usb_descriptor.h +++ b/firmware/hackrf_usb/usb_descriptor.h @@ -25,8 +25,6 @@ extern uint8_t usb_descriptor_device[]; extern uint8_t usb_descriptor_device_qualifier[]; extern uint8_t usb_descriptor_configuration_full_speed[]; extern uint8_t usb_descriptor_configuration_high_speed[]; -extern uint8_t usb_descriptor_configuration_cpld_update_full_speed[]; -extern uint8_t usb_descriptor_configuration_cpld_update_high_speed[]; extern uint8_t usb_descriptor_string_languages[]; extern uint8_t usb_descriptor_string_manufacturer[]; extern uint8_t usb_descriptor_string_product[]; @@ -36,3 +34,7 @@ extern uint8_t usb_descriptor_string_product[]; extern uint8_t usb_descriptor_string_serial_number[]; extern uint8_t* usb_descriptor_strings[]; + +#define USB_WCID_VENDOR_REQ 0x19 +extern uint8_t wcid_string_descriptor[]; +extern uint8_t wcid_feature_descriptor[]; diff --git a/firmware/hackrf_usb/usb_device.c b/firmware/hackrf_usb/usb_device.c index 6df358ed..4803e024 100644 --- a/firmware/hackrf_usb/usb_device.c +++ b/firmware/hackrf_usb/usb_device.c @@ -38,23 +38,10 @@ usb_configuration_t usb_configuration_full_speed = { .descriptor = usb_descriptor_configuration_full_speed, }; -usb_configuration_t usb_configuration_cpld_update_full_speed = { - .number = 2, - .speed = USB_SPEED_FULL, - .descriptor = usb_descriptor_configuration_cpld_update_full_speed, -}; - -usb_configuration_t usb_configuration_cpld_update_high_speed = { - .number = 2, - .speed = USB_SPEED_HIGH, - .descriptor = usb_descriptor_configuration_cpld_update_high_speed, -}; usb_configuration_t* usb_configurations[] = { &usb_configuration_high_speed, &usb_configuration_full_speed, - &usb_configuration_cpld_update_full_speed, - &usb_configuration_cpld_update_high_speed, 0, }; @@ -64,4 +51,6 @@ usb_device_t usb_device = { .qualifier_descriptor = usb_descriptor_device_qualifier, .configurations = &usb_configurations, .configuration = 0, + .wcid_string_descriptor = wcid_string_descriptor, + .wcid_feature_descriptor = wcid_feature_descriptor, };