Changes in / [a523af4:72fea5a] in mainline
- Location:
- uspace/lib/usb
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/include/usb/devreq.h
ra523af4 r72fea5a 92 92 int usb_drv_req_get_full_configuration_descriptor(int, usb_address_t, int, 93 93 void *, size_t, size_t *); 94 int usb_drv_req_get_descriptor(int, usb_address_t, usb_request_type_t,95 uint8_t, uint8_t, uint16_t, void *, size_t, size_t *);96 94 97 95 -
uspace/lib/usb/include/usb/usb.h
ra523af4 r72fea5a 54 54 USB_DIRECTION_OUT 55 55 } usb_direction_t; 56 57 /** USB request type target. */58 typedef enum {59 USB_REQUEST_TYPE_STANDARD = 0,60 USB_REQUEST_TYPE_CLASS = 1,61 USB_REQUEST_TYPE_VENDOR = 262 } usb_request_type_t;63 56 64 57 /** USB transaction outcome. */ -
uspace/lib/usb/include/usb/usbdrv.h
ra523af4 r72fea5a 96 96 int usb_drv_async_wait_for(usb_handle_t); 97 97 98 int usb_drv_create_match_ids_from_device_descriptor(match_id_list_t *,99 const usb_standard_device_descriptor_t *);100 int usb_drv_create_match_ids_from_configuration_descriptor(match_id_list_t *,101 const void *, size_t);102 103 98 int usb_drv_create_device_match_ids(int, match_id_list_t *, usb_address_t); 104 99 int usb_drv_register_child_in_devman(int, device_t *, usb_address_t, -
uspace/lib/usb/src/recognise.c
ra523af4 r72fea5a 129 129 } 130 130 131 /** Create DDF match ids from USB device descriptor.132 *133 * @param matches List of match ids to extend.134 * @param device_descriptor Device descriptor returned by given device.135 * @return Error code.136 */137 int usb_drv_create_match_ids_from_device_descriptor(138 match_id_list_t *matches,139 const usb_standard_device_descriptor_t *device_descriptor)140 {141 int rc;142 143 /*144 * Unless the vendor id is 0, the pair idVendor-idProduct145 * quite uniquely describes the device.146 */147 if (device_descriptor->vendor_id != 0) {148 /* First, with release number. */149 rc = usb_add_match_id(matches, 100,150 "usb&vendor=%d&product=%d&release=" BCD_FMT,151 (int) device_descriptor->vendor_id,152 (int) device_descriptor->product_id,153 BCD_ARGS(device_descriptor->device_version));154 if (rc != EOK) {155 return rc;156 }157 158 /* Next, without release number. */159 rc = usb_add_match_id(matches, 90, "usb&vendor=%d&product=%d",160 (int) device_descriptor->vendor_id,161 (int) device_descriptor->product_id);162 if (rc != EOK) {163 return rc;164 }165 }166 167 /*168 * If the device class points to interface we skip adding169 * class directly.170 */171 if (device_descriptor->device_class != USB_CLASS_USE_INTERFACE) {172 rc = usb_add_match_id(matches, 50, "usb&class=%s",173 usb_str_class(device_descriptor->device_class));174 if (rc != EOK) {175 return rc;176 }177 }178 179 return EOK;180 }181 182 /** Create DDF match ids from USB configuration descriptor.183 * The configuration descriptor is expected to be in the complete form,184 * i.e. including interface, endpoint etc. descriptors.185 *186 * @param matches List of match ids to extend.187 * @param config_descriptor Configuration descriptor returned by given device.188 * @param total_size Size of the @p config_descriptor.189 * @return Error code.190 */191 int usb_drv_create_match_ids_from_configuration_descriptor(192 match_id_list_t *matches,193 const void *config_descriptor, size_t total_size)194 {195 /*196 * Iterate through config descriptor to find the interface197 * descriptors.198 */199 size_t position = sizeof(usb_standard_configuration_descriptor_t);200 while (position + 1 < total_size) {201 uint8_t *current_descriptor202 = ((uint8_t *) config_descriptor) + position;203 uint8_t cur_descr_len = current_descriptor[0];204 uint8_t cur_descr_type = current_descriptor[1];205 206 position += cur_descr_len;207 208 if (cur_descr_type != USB_DESCTYPE_INTERFACE) {209 continue;210 }211 212 /*213 * Finally, we found an interface descriptor.214 */215 usb_standard_interface_descriptor_t *interface216 = (usb_standard_interface_descriptor_t *)217 current_descriptor;218 219 int rc = usb_add_match_id(matches, 50,220 "usb&interface&class=%s",221 usb_str_class(interface->interface_class));222 if (rc != EOK) {223 return rc;224 }225 }226 227 return EOK;228 }229 230 131 /** Add match ids based on configuration descriptor. 231 132 * … … 268 169 continue; 269 170 } 270 271 rc = usb_drv_create_match_ids_from_configuration_descriptor( 272 matches, 273 full_config_descriptor, full_config_descriptor_size); 274 if (rc != EOK) { 275 final_rc = rc; 276 continue; 277 } 278 171 172 /* 173 * Iterate through config descriptor to find the interface 174 * descriptors. 175 */ 176 size_t position = sizeof(config_descriptor); 177 while (position + 1 < full_config_descriptor_size) { 178 uint8_t *current_descriptor 179 = ((uint8_t *) full_config_descriptor) + position; 180 uint8_t cur_descr_len = current_descriptor[0]; 181 uint8_t cur_descr_type = current_descriptor[1]; 182 183 position += cur_descr_len; 184 185 if (cur_descr_type != USB_DESCTYPE_INTERFACE) { 186 continue; 187 } 188 /* 189 * Finally, we found an interface descriptor. 190 */ 191 usb_standard_interface_descriptor_t *interface 192 = (usb_standard_interface_descriptor_t *) 193 current_descriptor; 194 195 rc = usb_add_match_id(matches, 50, 196 "usb&interface&class=%s", 197 usb_str_class(interface->interface_class)); 198 if (rc != EOK) { 199 final_rc = rc; 200 break; 201 } 202 } 279 203 } 280 204 … … 296 220 { 297 221 int rc; 298 299 /*300 * Retrieve device descriptor and add matches from it.301 */302 222 usb_standard_device_descriptor_t device_descriptor; 303 223 … … 307 227 return rc; 308 228 } 309 310 rc = usb_drv_create_match_ids_from_device_descriptor(matches, 311 &device_descriptor); 312 if (rc != EOK) { 313 return rc; 314 } 315 229 230 /* 231 * Unless the vendor id is 0, the pair idVendor-idProduct 232 * quite uniquely describes the device. 233 */ 234 if (device_descriptor.vendor_id != 0) { 235 /* First, with release number. */ 236 rc = usb_add_match_id(matches, 100, 237 "usb&vendor=%d&product=%d&release=" BCD_FMT, 238 (int) device_descriptor.vendor_id, 239 (int) device_descriptor.product_id, 240 BCD_ARGS(device_descriptor.device_version)); 241 if (rc != EOK) { 242 return rc; 243 } 244 245 /* Next, without release number. */ 246 rc = usb_add_match_id(matches, 90, "usb&vendor=%d&product=%d", 247 (int) device_descriptor.vendor_id, 248 (int) device_descriptor.product_id); 249 if (rc != EOK) { 250 return rc; 251 } 252 253 } 254 255 /* 256 * If the device class points to interface we skip adding 257 * class directly. 258 */ 259 if (device_descriptor.device_class != USB_CLASS_USE_INTERFACE) { 260 rc = usb_add_match_id(matches, 50, "usb&class=%s", 261 usb_str_class(device_descriptor.device_class)); 262 if (rc != EOK) { 263 return rc; 264 } 265 } 316 266 /* 317 267 * Go through all configurations and add matches -
uspace/lib/usb/src/usbdrvreq.c
ra523af4 r72fea5a 73 73 } 74 74 75 /** Retrieve USB descriptor of connected USB device.76 *77 * @param[in] hc_phone Open phone to HC driver.78 * @param[in] address Device USB address.79 * @param[in] request_type Request type (standard/class/vendor).80 * @param[in] descriptor_type Descriptor type (device/configuration/HID/...).81 * @param[in] descriptor_index Descriptor index.82 * @param[in] langauge Language index.83 * @param[out] buffer Buffer where to store the retrieved descriptor.84 * @param[in] size Size of the @p buffer.85 * @param[out] actual_size Number of bytes actually transferred.86 * @return Error code.87 */88 int usb_drv_req_get_descriptor(int hc_phone, usb_address_t address,89 usb_request_type_t request_type,90 uint8_t descriptor_type, uint8_t descriptor_index,91 uint16_t language,92 void *buffer, size_t size, size_t *actual_size)93 {94 /* Prepare the target. */95 usb_target_t target = {96 .address = address,97 .endpoint = 098 };99 100 /* Prepare the setup packet. */101 usb_device_request_setup_packet_t setup_packet = {102 .request_type = 128 | (request_type << 5),103 .request = USB_DEVREQ_GET_DESCRIPTOR,104 .index = language,105 .length = (uint16_t) size,106 };107 setup_packet.value_high = descriptor_type;108 setup_packet.value_low = descriptor_index;109 110 /* Perform CONTROL READ */111 int rc = usb_drv_psync_control_read(hc_phone, target,112 &setup_packet, sizeof(setup_packet),113 buffer, size, actual_size);114 115 return rc;116 }117 118 75 /** Retrieve device descriptor of connected USB device. 119 76 * … … 130 87 return EBADMEM; 131 88 } 132 89 90 /* Prepare the target. */ 91 usb_target_t target = { 92 .address = address, 93 .endpoint = 0 94 }; 95 96 /* Prepare the setup packet. */ 97 usb_device_request_setup_packet_t setup_packet = { 98 .request_type = 128, 99 .request = USB_DEVREQ_GET_DESCRIPTOR, 100 .index = 0, 101 .length = sizeof(usb_standard_device_descriptor_t) 102 }; 103 setup_packet.value_high = USB_DESCTYPE_DEVICE; 104 setup_packet.value_low = 0; 105 106 /* Prepare local descriptor. */ 133 107 size_t actually_transferred = 0; 134 108 usb_standard_device_descriptor_t descriptor_tmp; 135 int rc = usb_drv_req_get_descriptor(phone, address, 136 USB_REQUEST_TYPE_STANDARD, 137 USB_DESCTYPE_DEVICE, 0, 138 0, 139 &descriptor_tmp, sizeof(descriptor_tmp), 140 &actually_transferred); 109 110 /* Perform the control read transaction. */ 111 int rc = usb_drv_psync_control_read(phone, target, 112 &setup_packet, sizeof(setup_packet), 113 &descriptor_tmp, sizeof(descriptor_tmp), &actually_transferred); 141 114 142 115 if (rc != EOK) { … … 177 150 return EBADMEM; 178 151 } 179 152 153 /* Prepare the target. */ 154 usb_target_t target = { 155 .address = address, 156 .endpoint = 0 157 }; 158 159 /* Prepare the setup packet. */ 160 usb_device_request_setup_packet_t setup_packet = { 161 .request_type = 128, 162 .request = USB_DEVREQ_GET_DESCRIPTOR, 163 .index = 0, 164 .length = sizeof(usb_standard_configuration_descriptor_t) 165 }; 166 setup_packet.value_high = USB_DESCTYPE_CONFIGURATION; 167 setup_packet.value_low = index; 168 169 /* Prepare local descriptor. */ 180 170 size_t actually_transferred = 0; 181 171 usb_standard_configuration_descriptor_t descriptor_tmp; 182 int rc = usb_drv_req_get_descriptor(phone, address, 183 USB_REQUEST_TYPE_STANDARD, 184 USB_DESCTYPE_CONFIGURATION, 0, 185 0, 186 &descriptor_tmp, sizeof(descriptor_tmp), 187 &actually_transferred); 172 173 /* Perform the control read transaction. */ 174 int rc = usb_drv_psync_control_read(phone, target, 175 &setup_packet, sizeof(setup_packet), 176 &descriptor_tmp, sizeof(descriptor_tmp), &actually_transferred); 188 177 189 178 if (rc != EOK) { … … 225 214 } 226 215 227 int rc = usb_drv_req_get_descriptor(phone, address, 228 USB_REQUEST_TYPE_STANDARD, 229 USB_DESCTYPE_CONFIGURATION, 0, 230 0, 231 buffer, buffer_size, 232 actual_buffer_size); 216 /* Prepare the target. */ 217 usb_target_t target = { 218 .address = address, 219 .endpoint = 0 220 }; 221 222 /* Prepare the setup packet. */ 223 usb_device_request_setup_packet_t setup_packet = { 224 .request_type = 128, 225 .request = USB_DEVREQ_GET_DESCRIPTOR, 226 .index = 0, 227 .length = buffer_size 228 }; 229 setup_packet.value_high = USB_DESCTYPE_CONFIGURATION; 230 setup_packet.value_low = index; 231 232 /* Perform the control read transaction. */ 233 int rc = usb_drv_psync_control_read(phone, target, 234 &setup_packet, sizeof(setup_packet), 235 buffer, buffer_size, actual_buffer_size); 233 236 234 237 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.