Changeset 4723444 in mainline for uspace/lib/usb/src/request.c


Ignore:
Timestamp:
2011-03-02T18:06:42Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d70e0a3c
Parents:
c081780
Message:

Add allocating "get full config descriptor"

This function encapsulates two phase retrieval of full configuration
descriptor.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/request.c

    rc081780 r4723444  
    412412}
    413413
     414/** Retrieve full configuration descriptor, allocate space for it.
     415 *
     416 * The function takes care that full configuration descriptor is returned
     417 * (i.e. the function will fail when less data then descriptor.totalLength
     418 * is returned).
     419 *
     420 * @param[in] pipe Control endpoint pipe (session must be already started).
     421 * @param[in] index Configuration index.
     422 * @param[out] descriptor_ptr Where to store pointer to allocated buffer.
     423 * @param[out] descriptor_size Where to store the size of the descriptor.
     424 * @return Error code.
     425 */
     426int usb_request_get_full_configuration_descriptor_alloc(
     427    usb_endpoint_pipe_t *pipe, int index,
     428    void **descriptor_ptr, size_t *descriptor_size)
     429{
     430        int rc;
     431
     432        if (descriptor_ptr == NULL) {
     433                return EBADMEM;
     434        }
     435
     436        usb_standard_configuration_descriptor_t bare_config;
     437        rc = usb_request_get_bare_configuration_descriptor(pipe, index,
     438            &bare_config);
     439        if (rc != EOK) {
     440                return rc;
     441        }
     442
     443        if (bare_config.descriptor_type != USB_DESCTYPE_CONFIGURATION) {
     444                return ENOENT;
     445        }
     446        if (bare_config.total_length < sizeof(bare_config)) {
     447                return ELIMIT;
     448        }
     449
     450        void *buffer = malloc(bare_config.total_length);
     451        if (buffer == NULL) {
     452                return ENOMEM;
     453        }
     454
     455        size_t transferred = 0;
     456        rc = usb_request_get_full_configuration_descriptor(pipe, index,
     457            buffer, bare_config.total_length, &transferred);
     458        if (rc != EOK) {
     459                free(buffer);
     460                return rc;
     461        }
     462
     463        if (transferred != bare_config.total_length) {
     464                free(buffer);
     465                return ELIMIT;
     466        }
     467
     468        /* Everything looks okay, copy the pointers. */
     469
     470        *descriptor_ptr = buffer;
     471
     472        if (descriptor_size != NULL) {
     473                *descriptor_size = bare_config.total_length;
     474        }
     475
     476        return EOK;
     477}
     478
    414479/** Set configuration of USB device.
    415480 *
Note: See TracChangeset for help on using the changeset viewer.