Changeset 071b5f8 in mainline for uspace/lib/usb/src/request.c
- Timestamp:
- 2011-02-23T18:12:05Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6dd929c
- Parents:
- 3f0ef89d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified uspace/lib/usb/src/request.c ¶
r3f0ef89d r071b5f8 230 230 } 231 231 232 /** Retrieve USB descriptor, allocate space for it. 233 * 234 * @param[in] pipe Control endpoint pipe (session must be already started). 235 * @param[in] request_type Request type (standard/class/vendor). 236 * @param[in] descriptor_type Descriptor type (device/configuration/HID/...). 237 * @param[in] descriptor_index Descriptor index. 238 * @param[in] language Language index. 239 * @param[out] buffer_ptr Where to store pointer to allocated buffer. 240 * @param[out] buffer_size Where to store the size of the descriptor. 241 * @return 242 */ 243 int usb_request_get_descriptor_alloc(usb_endpoint_pipe_t * pipe, 244 usb_request_type_t request_type, 245 uint8_t descriptor_type, uint8_t descriptor_index, 246 uint16_t language, 247 void **buffer_ptr, size_t *buffer_size) 248 { 249 if (buffer_ptr == NULL) { 250 return EBADMEM; 251 } 252 253 int rc; 254 255 /* 256 * Get only first byte to retrieve descriptor length. 257 */ 258 uint8_t tmp_buffer[1]; 259 size_t bytes_transfered; 260 rc = usb_request_get_descriptor(pipe, request_type, 261 descriptor_type, descriptor_index, language, 262 &tmp_buffer, 1, &bytes_transfered); 263 if (rc != EOK) { 264 return rc; 265 } 266 if (bytes_transfered != 1) { 267 /* FIXME: some better error code? */ 268 return ESTALL; 269 } 270 271 size_t size = tmp_buffer[0]; 272 if (size == 0) { 273 /* FIXME: some better error code? */ 274 return ESTALL; 275 } 276 277 /* 278 * Allocate buffer and get the descriptor again. 279 */ 280 void *buffer = malloc(size); 281 if (buffer == NULL) { 282 return ENOMEM; 283 } 284 285 rc = usb_request_get_descriptor(pipe, request_type, 286 descriptor_type, descriptor_index, language, 287 buffer, size, &bytes_transfered); 288 if (rc != EOK) { 289 free(buffer); 290 return rc; 291 } 292 if (bytes_transfered != size) { 293 free(buffer); 294 /* FIXME: some better error code? */ 295 return ESTALL; 296 } 297 298 *buffer_ptr = buffer; 299 if (buffer_size != NULL) { 300 *buffer_size = size; 301 } 302 303 return EOK; 304 } 305 232 306 /** Retrieve standard device descriptor of a USB device. 233 307 *
Note:
See TracChangeset
for help on using the changeset viewer.