Changeset d70e0a3c in mainline
- Timestamp:
- 2011-03-02T18:17:27Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a6567ed
- Parents:
- 4723444
- Location:
- uspace/drv
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/hiddev.c
r4723444 rd70e0a3c 149 149 usb_log_info("Processing descriptors...\n"); 150 150 151 // get the first configuration descriptor152 usb_standard_configuration_descriptor_t config_desc;153 154 151 int rc; 155 rc = usb_request_get_bare_configuration_descriptor(&hid_dev->ctrl_pipe, 156 0, &config_desc); 157 158 if (rc != EOK) { 159 usb_log_error("Failed to get bare config descriptor: %s.\n", 152 153 uint8_t *descriptors = NULL; 154 size_t descriptors_size; 155 rc = usb_request_get_full_configuration_descriptor_alloc( 156 &hid_dev->ctrl_pipe, 0, (void **) &descriptors, &descriptors_size); 157 if (rc != EOK) { 158 usb_log_error("Failed to retrieve config descriptor: %s.\n", 160 159 str_error(rc)); 161 160 return rc; 162 }163 164 // prepare space for all underlying descriptors165 uint8_t *descriptors = (uint8_t *)malloc(config_desc.total_length);166 if (descriptors == NULL) {167 usb_log_error("No memory!.\n");168 return ENOMEM;169 }170 171 size_t transferred = 0;172 // get full configuration descriptor173 rc = usb_request_get_full_configuration_descriptor(&hid_dev->ctrl_pipe,174 0, descriptors, config_desc.total_length, &transferred);175 176 if (rc != EOK) {177 usb_log_error("Failed to get full config descriptor: %s.\n",178 str_error(rc));179 free(descriptors);180 return rc;181 }182 183 if (transferred != config_desc.total_length) {184 usb_log_error("Configuration descriptor has wrong size (%u, "185 "expected %u).\n", transferred, config_desc.total_length);186 free(descriptors);187 return ELIMIT;188 161 } 189 162 … … 201 174 202 175 rc = usb_endpoint_pipe_initialize_from_configuration( 203 endpoint_mapping, 1, descriptors, config_desc.total_length,176 endpoint_mapping, 1, descriptors, descriptors_size, 204 177 &hid_dev->wire); 205 178 … … 233 206 assert(endpoint_mapping[0].interface != NULL); 234 207 235 rc = usbhid_dev_get_report_descriptor(hid_dev, descriptors, transferred, 208 rc = usbhid_dev_get_report_descriptor(hid_dev, 209 descriptors, descriptors_size, 236 210 (uint8_t *)endpoint_mapping[0].interface); 237 211 -
uspace/drv/usbhub/usbhub.c
r4723444 rd70e0a3c 149 149 } 150 150 151 / /configuration descriptor152 /// \TODO check other configurations?153 usb_standard_configuration_descriptor_t config_descriptor;154 opResult = usb_request_get_ bare_configuration_descriptor(151 /* Retrieve full configuration descriptor. */ 152 uint8_t *descriptors = NULL; 153 size_t descriptors_size = 0; 154 opResult = usb_request_get_full_configuration_descriptor_alloc( 155 155 &hub->endpoints.control, 0, 156 &config_descriptor); 157 if(opResult!=EOK){ 158 dprintf(USB_LOG_LEVEL_ERROR, "could not get configuration descriptor, %d",opResult); 156 (void **) &descriptors, &descriptors_size); 157 if (opResult != EOK) { 158 usb_log_error("Could not get configuration descriptor: %s.\n", 159 str_error(opResult)); 159 160 return opResult; 160 161 } 161 //set configuration 162 usb_standard_configuration_descriptor_t *config_descriptor 163 = (usb_standard_configuration_descriptor_t *) descriptors; 164 165 /* Set configuration. */ 162 166 opResult = usb_request_set_configuration(&hub->endpoints.control, 163 config_descriptor.configuration_number); 164 165 if (opResult != EOK) { 166 dprintf(USB_LOG_LEVEL_ERROR, 167 "something went wrong when setting hub`s configuration, %d", 168 opResult); 167 config_descriptor->configuration_number); 168 169 if (opResult != EOK) { 170 usb_log_error("Failed to set hub configuration: %s.\n", 171 str_error(opResult)); 169 172 return opResult; 170 173 } 171 174 dprintf(USB_LOG_LEVEL_DEBUG, "\tused configuration %d", 172 config_descriptor.configuration_number); 173 174 //full configuration descriptor 175 size_t transferred = 0; 176 uint8_t * descriptors = (uint8_t *)malloc(config_descriptor.total_length); 177 if (descriptors == NULL) { 178 dprintf(USB_LOG_LEVEL_ERROR, "insufficient memory"); 179 return ENOMEM; 180 } 181 opResult = usb_request_get_full_configuration_descriptor(&hub->endpoints.control, 182 0, descriptors, 183 config_descriptor.total_length, &transferred); 184 if(opResult!=EOK){ 185 free(descriptors); 186 dprintf(USB_LOG_LEVEL_ERROR, 187 "could not get full configuration descriptor, %d",opResult); 188 return opResult; 189 } 190 if (transferred != config_descriptor.total_length) { 191 dprintf(USB_LOG_LEVEL_ERROR, 192 "received incorrect full configuration descriptor"); 193 return ELIMIT; 194 } 175 config_descriptor->configuration_number); 195 176 196 177 usb_endpoint_mapping_t endpoint_mapping[1] = { … … 204 185 opResult = usb_endpoint_pipe_initialize_from_configuration( 205 186 endpoint_mapping, 1, 206 descriptors, config_descriptor.total_length,187 descriptors, descriptors_size, 207 188 &hub->device_connection); 208 189 if (opResult != EOK) { -
uspace/drv/usbmid/explore.c
r4723444 rd70e0a3c 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 }
Note:
See TracChangeset
for help on using the changeset viewer.