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


Ignore:
Timestamp:
2011-03-11T15:42:43Z (14 years ago)
Author:
Matej Klonfar <maklf@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0bd4810c
Parents:
60a228f (diff), a8def7d (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 hidd

File:
1 edited

Legend:

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

    r60a228f r9d9ffdd  
    110110  *     (must be in USB endianness).
    111111  * @param data Buffer where to store data accepted during the DATA stage.
    112   *     (they will come in USB endianess).
     112  *     (they will come in USB endianness).
    113113  * @param data_size Size of the @p data buffer
    114114  *     (in native endianness).
     
    161161 * the new address.
    162162 *
    163  * @see usb_drv_reserve_default_address
    164  * @see usb_drv_release_default_address
    165  * @see usb_drv_request_address
    166  * @see usb_drv_release_address
    167  * @see usb_drv_bind_address
    168  *
    169163 * @param pipe Control endpoint pipe (session must be already started).
    170164 * @param new_address New USB address to be set (in native endianness).
     
    201195 * @param[in] pipe Control endpoint pipe (session must be already started).
    202196 * @param[in] request_type Request type (standard/class/vendor).
     197 * @param[in] recipient Request recipient (device/interface/endpoint).
    203198 * @param[in] descriptor_type Descriptor type (device/configuration/HID/...).
    204199 * @param[in] descriptor_index Descriptor index.
     
    235230 * @param[in] pipe Control endpoint pipe (session must be already started).
    236231 * @param[in] request_type Request type (standard/class/vendor).
     232 * @param[in] recipient Request recipient (device/interface/endpoint).
    237233 * @param[in] descriptor_type Descriptor type (device/configuration/HID/...).
    238234 * @param[in] descriptor_index Descriptor index.
     
    412408}
    413409
     410/** Retrieve full configuration descriptor, allocate space for it.
     411 *
     412 * The function takes care that full configuration descriptor is returned
     413 * (i.e. the function will fail when less data then descriptor.totalLength
     414 * is returned).
     415 *
     416 * @param[in] pipe Control endpoint pipe (session must be already started).
     417 * @param[in] index Configuration index.
     418 * @param[out] descriptor_ptr Where to store pointer to allocated buffer.
     419 * @param[out] descriptor_size Where to store the size of the descriptor.
     420 * @return Error code.
     421 */
     422int usb_request_get_full_configuration_descriptor_alloc(
     423    usb_endpoint_pipe_t *pipe, int index,
     424    void **descriptor_ptr, size_t *descriptor_size)
     425{
     426        int rc;
     427
     428        if (descriptor_ptr == NULL) {
     429                return EBADMEM;
     430        }
     431
     432        usb_standard_configuration_descriptor_t bare_config;
     433        rc = usb_request_get_bare_configuration_descriptor(pipe, index,
     434            &bare_config);
     435        if (rc != EOK) {
     436                return rc;
     437        }
     438
     439        if (bare_config.descriptor_type != USB_DESCTYPE_CONFIGURATION) {
     440                return ENOENT;
     441        }
     442        if (bare_config.total_length < sizeof(bare_config)) {
     443                return ELIMIT;
     444        }
     445
     446        void *buffer = malloc(bare_config.total_length);
     447        if (buffer == NULL) {
     448                return ENOMEM;
     449        }
     450
     451        size_t transferred = 0;
     452        rc = usb_request_get_full_configuration_descriptor(pipe, index,
     453            buffer, bare_config.total_length, &transferred);
     454        if (rc != EOK) {
     455                free(buffer);
     456                return rc;
     457        }
     458
     459        if (transferred != bare_config.total_length) {
     460                free(buffer);
     461                return ELIMIT;
     462        }
     463
     464        /* Everything looks okay, copy the pointers. */
     465
     466        *descriptor_ptr = buffer;
     467
     468        if (descriptor_size != NULL) {
     469                *descriptor_size = bare_config.total_length;
     470        }
     471
     472        return EOK;
     473}
     474
    414475/** Set configuration of USB device.
    415476 *
     
    463524                return EEMPTY;
    464525        }
    465         /* Substract first 2 bytes (length and descriptor type). */
     526        /* Subtract first 2 bytes (length and descriptor type). */
    466527        string_descriptor_size -= 2;
    467528
     
    483544        size_t i;
    484545        for (i = 0; i < langs_count; i++) {
    485                 /* Language code from the descriptor is in USB endianess. */
     546                /* Language code from the descriptor is in USB endianness. */
    486547                /* FIXME: is this really correct? */
    487548                uint16_t lang_code = (string_descriptor[2 + 2 * i + 1] << 8)
     
    504565 *
    505566 * @param[in] pipe Control endpoint pipe (session must be already started).
    506  * @param[in] index String index (in native endianess).
    507  * @param[in] lang String language (in native endianess).
     567 * @param[in] index String index (in native endianness),
     568 *      first index has number 1 (index from descriptors can be used directly).
     569 * @param[in] lang String language (in native endianness).
    508570 * @param[out] string_ptr Where to store allocated string in native encoding.
    509571 * @return Error code.
     
    515577                return EBADMEM;
    516578        }
    517         /* Index is actually one byte value. */
    518         if (index > 0xFF) {
     579        /*
     580         * Index is actually one byte value and zero index is used
     581         * to retrieve list of supported languages.
     582         */
     583        if ((index < 1) || (index > 0xFF)) {
    519584                return ERANGE;
    520585        }
     
    544609                goto leave;
    545610        }
    546         /* Substract first 2 bytes (length and descriptor type). */
     611        /* Subtract first 2 bytes (length and descriptor type). */
    547612        string_size -= 2;
    548613
Note: See TracChangeset for help on using the changeset viewer.