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


Ignore:
Timestamp:
2011-03-04T13:05:35Z (13 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d49728c
Parents:
dff940f8 (diff), 9a422574 (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.
Message:

merge with \usb\development

File:
1 edited

Legend:

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

    rdff940f8 r8c877b2  
    3636#include <errno.h>
    3737#include <assert.h>
     38#include <usb/debug.h>
    3839
    3940#define MAX_DATA_LENGTH ((size_t)(0xFFFF))
     
    209210 */
    210211int usb_request_get_descriptor(usb_endpoint_pipe_t *pipe,
    211     usb_request_type_t request_type,
     212    usb_request_type_t request_type, usb_request_recipient_t recipient,
    212213    uint8_t descriptor_type, uint8_t descriptor_index,
    213214    uint16_t language,
     
    224225
    225226        return usb_control_request_get(pipe,
    226             request_type, USB_REQUEST_RECIPIENT_DEVICE,
     227            request_type, recipient,
    227228            USB_DEVREQ_GET_DESCRIPTOR,
    228229            wValue, language,
     
    242243 */
    243244int usb_request_get_descriptor_alloc(usb_endpoint_pipe_t * pipe,
    244     usb_request_type_t request_type,
     245    usb_request_type_t request_type, usb_request_recipient_t recipient,
    245246    uint8_t descriptor_type, uint8_t descriptor_index,
    246247    uint16_t language,
     
    258259        uint8_t tmp_buffer[1];
    259260        size_t bytes_transfered;
    260         rc = usb_request_get_descriptor(pipe, request_type,
     261        rc = usb_request_get_descriptor(pipe, request_type, recipient,
    261262            descriptor_type, descriptor_index, language,
    262263            &tmp_buffer, 1, &bytes_transfered);
     
    283284        }
    284285
    285         rc = usb_request_get_descriptor(pipe, request_type,
     286        rc = usb_request_get_descriptor(pipe, request_type, recipient,
    286287            descriptor_type, descriptor_index, language,
    287288            buffer, size, &bytes_transfered);
     
    320321        usb_standard_device_descriptor_t descriptor_tmp;
    321322        int rc = usb_request_get_descriptor(pipe,
    322             USB_REQUEST_TYPE_STANDARD, USB_DESCTYPE_DEVICE,
    323             0, 0,
     323            USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
     324            USB_DESCTYPE_DEVICE, 0, 0,
    324325            &descriptor_tmp, sizeof(descriptor_tmp),
    325326            &actually_transferred);
     
    366367        usb_standard_configuration_descriptor_t descriptor_tmp;
    367368        int rc = usb_request_get_descriptor(pipe,
    368             USB_REQUEST_TYPE_STANDARD, USB_DESCTYPE_CONFIGURATION,
    369             index, 0,
     369            USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
     370            USB_DESCTYPE_CONFIGURATION, index, 0,
    370371            &descriptor_tmp, sizeof(descriptor_tmp),
    371372            &actually_transferred);
     
    406407
    407408        return usb_request_get_descriptor(pipe,
    408             USB_REQUEST_TYPE_STANDARD, USB_DESCTYPE_CONFIGURATION,
    409             index, 0,
     409            USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
     410            USB_DESCTYPE_CONFIGURATION, index, 0,
    410411            descriptor, descriptor_size, actual_size);
     412}
     413
     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;
    411477}
    412478
     
    452518        size_t string_descriptor_size = 0;
    453519        rc = usb_request_get_descriptor_alloc(pipe,
    454             USB_REQUEST_TYPE_STANDARD, USB_DESCTYPE_STRING, 0, 0,
     520            USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
     521            USB_DESCTYPE_STRING, 0, 0,
    455522            (void **) &string_descriptor, &string_descriptor_size);
    456523        if (rc != EOK) {
     
    502569 *
    503570 * @param[in] pipe Control endpoint pipe (session must be already started).
    504  * @param[in] index String index (in native endianess).
     571 * @param[in] index String index (in native endianess),
     572 *      first index has number 1 (index from descriptors can be used directly).
    505573 * @param[in] lang String language (in native endianess).
    506574 * @param[out] string_ptr Where to store allocated string in native encoding.
     
    513581                return EBADMEM;
    514582        }
    515         /* Index is actually one byte value. */
    516         if (index > 0xFF) {
     583        /*
     584         * Index is actually one byte value and zero index is used
     585         * to retrieve list of supported languages.
     586         */
     587        if ((index < 1) || (index > 0xFF)) {
    517588                return ERANGE;
    518589        }
     
    531602        size_t string_size;
    532603        rc = usb_request_get_descriptor_alloc(pipe,
    533             USB_REQUEST_TYPE_STANDARD, USB_DESCTYPE_STRING,
    534             index, uint16_host2usb(lang),
     604            USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
     605            USB_DESCTYPE_STRING, index, uint16_host2usb(lang),
    535606            (void **) &string, &string_size);
    536607        if (rc != EOK) {
Note: See TracChangeset for help on using the changeset viewer.