Changes in uspace/drv/usbmid/explore.c [8f74140c:d3880aa] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbmid/explore.c
r8f74140c rd3880aa 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 44 96 /** Find starting indexes of all interface descriptors in a configuration. 45 97 * … … 126 178 127 179 size_t config_descriptor_size; 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)); 180 uint8_t *config_descriptor_raw = get_configuration_descriptor(dev, 0, 181 &config_descriptor_size); 182 if (config_descriptor_raw == NULL) { 135 183 return false; 136 184 } … … 159 207 } 160 208 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 */174 209 ddf_fun_t *ctl_fun = ddf_fun_create(dev->dev, fun_exposed, "ctl"); 175 210 if (ctl_fun == NULL) { … … 188 223 } 189 224 190 /* Spawn interface children */191 225 size_t i; 192 226 for (i = 0; i < interface_descriptors_count; i++) {
Note:
See TracChangeset
for help on using the changeset viewer.