Changeset a523af4 in mainline
- Timestamp:
- 2011-01-07T16:37:50Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 56184b2, 93fb170c, a97ea0f
- Parents:
- 72fea5a (diff), 9b95dbcf (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- uspace/lib/usb
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/include/usb/devreq.h
r72fea5a ra523af4 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 *); 94 96 95 97 -
uspace/lib/usb/include/usb/usb.h
r72fea5a ra523af4 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 = 2 62 } usb_request_type_t; 56 63 57 64 /** USB transaction outcome. */ -
uspace/lib/usb/include/usb/usbdrv.h
r72fea5a ra523af4 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 98 103 int usb_drv_create_device_match_ids(int, match_id_list_t *, usb_address_t); 99 104 int usb_drv_register_child_in_devman(int, device_t *, usb_address_t, -
uspace/lib/usb/src/recognise.c
r72fea5a ra523af4 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-idProduct 145 * 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 adding 169 * 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 interface 197 * descriptors. 198 */ 199 size_t position = sizeof(usb_standard_configuration_descriptor_t); 200 while (position + 1 < total_size) { 201 uint8_t *current_descriptor 202 = ((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 *interface 216 = (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 131 230 /** Add match ids based on configuration descriptor. 132 231 * … … 169 268 continue; 170 269 } 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 } 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 203 279 } 204 280 … … 220 296 { 221 297 int rc; 298 299 /* 300 * Retrieve device descriptor and add matches from it. 301 */ 222 302 usb_standard_device_descriptor_t device_descriptor; 223 303 … … 227 307 return rc; 228 308 } 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 } 309 310 rc = usb_drv_create_match_ids_from_device_descriptor(matches, 311 &device_descriptor); 312 if (rc != EOK) { 313 return rc; 314 } 315 266 316 /* 267 317 * Go through all configurations and add matches -
uspace/lib/usb/src/usbdrvreq.c
r72fea5a ra523af4 73 73 } 74 74 75 /** Retrieve device descriptor of connected USB device. 76 * 77 * @param[in] phone Open phone to HC driver. 78 * @param[in] address Device USB address. 79 * @param[out] descriptor Storage for the device descriptor. 80 * @return Error code. 81 * @retval EBADMEM @p descriptor is NULL. 82 */ 83 int usb_drv_req_get_device_descriptor(int phone, usb_address_t address, 84 usb_standard_device_descriptor_t *descriptor) 85 { 86 if (descriptor == NULL) { 87 return EBADMEM; 88 } 89 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 { 90 94 /* Prepare the target. */ 91 95 usb_target_t target = { … … 96 100 /* Prepare the setup packet. */ 97 101 usb_device_request_setup_packet_t setup_packet = { 98 .request_type = 128 ,102 .request_type = 128 | (request_type << 5), 99 103 .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. */ 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 /** Retrieve device descriptor of connected USB device. 119 * 120 * @param[in] phone Open phone to HC driver. 121 * @param[in] address Device USB address. 122 * @param[out] descriptor Storage for the device descriptor. 123 * @return Error code. 124 * @retval EBADMEM @p descriptor is NULL. 125 */ 126 int usb_drv_req_get_device_descriptor(int phone, usb_address_t address, 127 usb_standard_device_descriptor_t *descriptor) 128 { 129 if (descriptor == NULL) { 130 return EBADMEM; 131 } 132 107 133 size_t actually_transferred = 0; 108 134 usb_standard_device_descriptor_t descriptor_tmp; 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); 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); 114 141 115 142 if (rc != EOK) { … … 150 177 return EBADMEM; 151 178 } 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. */ 179 170 180 size_t actually_transferred = 0; 171 181 usb_standard_configuration_descriptor_t descriptor_tmp; 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); 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); 177 188 178 189 if (rc != EOK) { … … 214 225 } 215 226 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); 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); 236 233 237 234 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.