1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
From 5138486b1b739ec8ca84c69387597c3417e02a80 Mon Sep 17 00:00:00 2001
From: Dominic Spill <dominicgs@gmail.com>
Date: Sun, 17 Jul 2016 22:20:32 +0100
Subject: [PATCH 085/111] Add Windows Compatible ID descriptors
---
firmware/common/usb_standard_request.c | 34 +++++++++++++++++++++++++++++-----
firmware/common/usb_standard_request.h | 5 +++++
firmware/common/usb_type.h | 3 +++
firmware/hackrf_usb/hackrf_usb.c | 1 +
firmware/hackrf_usb/usb_descriptor.c | 29 ++++++++++++++++++++++++++++-
firmware/hackrf_usb/usb_descriptor.h | 4 ++++
firmware/hackrf_usb/usb_device.c | 2 ++
7 files changed, 72 insertions(+), 6 deletions(-)
diff --git a/firmware/common/usb_standard_request.c b/firmware/common/usb_standard_request.c
index 43b1115..bf82ab4 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 77fd1b1..50b92c0 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 8f683fc..2a1b7cd 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 eb424be..8a4357a 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 12d3fca..bacf7dd 100644
--- a/firmware/hackrf_usb/usb_descriptor.c
+++ b/firmware/hackrf_usb/usb_descriptor.c
@@ -55,7 +55,7 @@ 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
0x04, // iSerialNumber
@@ -252,3 +252,30 @@ uint8_t* usb_descriptor_strings[] = {
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 3d496ee..e8c9d50 100644
--- a/firmware/hackrf_usb/usb_descriptor.h
+++ b/firmware/hackrf_usb/usb_descriptor.h
@@ -34,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 e7204ad..4803e02 100644
--- a/firmware/hackrf_usb/usb_device.c
+++ b/firmware/hackrf_usb/usb_device.c
@@ -51,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,
};
--
2.1.4
|