Changeset 9445aad in mainline for uspace/drv/usbmid/explore.c
- Timestamp:
- 2011-03-03T23:25:34Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3c775adb, 9a422574
- Parents:
- bdc8ab1 (diff), 8f74140c (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbmid/explore.c
rbdc8ab1 r9445aad 42 42 #include "usbmid.h" 43 43 44 /** Allocate and retrieve full configuration descriptor.45 *46 * @param[in] dev USB device.47 * @param[in] config_index Configuration index.48 * @param[out] size Pointer where to store size of the allocated buffer.49 * @return Allocated full configuration descriptor.50 * @retval NULL Error occured.51 */52 static void *get_configuration_descriptor(usbmid_device_t *dev,53 size_t config_index, size_t *size)54 {55 usb_standard_configuration_descriptor_t config_descriptor;56 int rc = usb_request_get_bare_configuration_descriptor(&dev->ctrl_pipe,57 config_index, &config_descriptor);58 if (rc != EOK) {59 usb_log_error("Failed getting configuration descriptor: %s.\n",60 str_error(rc));61 return NULL;62 }63 64 void *full_config_descriptor = malloc(config_descriptor.total_length);65 if (full_config_descriptor == NULL) {66 usb_log_fatal("Out of memory (wanted: %zuB).\n",67 (size_t) config_descriptor.total_length);68 return NULL;69 }70 71 size_t full_config_descriptor_size;72 rc = usb_request_get_full_configuration_descriptor(&dev->ctrl_pipe,73 config_index,74 full_config_descriptor, config_descriptor.total_length,75 &full_config_descriptor_size);76 if (rc != EOK) {77 usb_log_error("Failed getting configuration descriptor: %s.\n",78 str_error(rc));79 free(full_config_descriptor);80 return NULL;81 }82 83 if (full_config_descriptor_size != config_descriptor.total_length) {84 usb_log_error("Failed getting full configuration descriptor.\n");85 free(full_config_descriptor);86 return NULL;87 }88 89 if (size != NULL) {90 *size = full_config_descriptor_size;91 }92 93 return full_config_descriptor;94 }95 96 44 /** Find starting indexes of all interface descriptors in a configuration. 97 45 * … … 178 126 179 127 size_t config_descriptor_size; 180 uint8_t *config_descriptor_raw = get_configuration_descriptor(dev, 0, 181 &config_descriptor_size); 182 if (config_descriptor_raw == NULL) { 128 uint8_t *config_descriptor_raw = NULL; 129 rc = usb_request_get_full_configuration_descriptor_alloc( 130 &dev->ctrl_pipe, 0, 131 (void **) &config_descriptor_raw, &config_descriptor_size); 132 if (rc != EOK) { 133 usb_log_error("Failed getting full config descriptor: %s.\n", 134 str_error(rc)); 183 135 return false; 184 136 } … … 207 159 } 208 160 161 /* Select the first configuration */ 162 rc = usb_request_set_configuration(&dev->ctrl_pipe, 163 config_descriptor->configuration_number); 164 if (rc != EOK) { 165 usb_log_error("Failed to set device configuration: %s.\n", 166 str_error(rc)); 167 free(config_descriptor_raw); 168 free(interface_descriptors); 169 return false; 170 } 171 172 173 /* Create control function */ 209 174 ddf_fun_t *ctl_fun = ddf_fun_create(dev->dev, fun_exposed, "ctl"); 210 175 if (ctl_fun == NULL) { … … 223 188 } 224 189 190 /* Spawn interface children */ 225 191 size_t i; 226 192 for (i = 0; i < interface_descriptors_count; i++) {
Note:
See TracChangeset
for help on using the changeset viewer.