Ignore:
File:
1 edited

Legend:

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

    rbc1c6fb rad4562c2  
    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 endianness).
     112  *     (they will come in USB endianess).
    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 *
    163169 * @param pipe Control endpoint pipe (session must be already started).
    164170 * @param new_address New USB address to be set (in native endianness).
     
    195201 * @param[in] pipe Control endpoint pipe (session must be already started).
    196202 * @param[in] request_type Request type (standard/class/vendor).
    197  * @param[in] recipient Request recipient (device/interface/endpoint).
    198203 * @param[in] descriptor_type Descriptor type (device/configuration/HID/...).
    199204 * @param[in] descriptor_index Descriptor index.
     
    230235 * @param[in] pipe Control endpoint pipe (session must be already started).
    231236 * @param[in] request_type Request type (standard/class/vendor).
    232  * @param[in] recipient Request recipient (device/interface/endpoint).
    233237 * @param[in] descriptor_type Descriptor type (device/configuration/HID/...).
    234238 * @param[in] descriptor_index Descriptor index.
     
    408412}
    409413
    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  */
    422 int 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 
    475414/** Set configuration of USB device.
    476415 *
     
    524463                return EEMPTY;
    525464        }
    526         /* Subtract first 2 bytes (length and descriptor type). */
     465        /* Substract first 2 bytes (length and descriptor type). */
    527466        string_descriptor_size -= 2;
    528467
     
    544483        size_t i;
    545484        for (i = 0; i < langs_count; i++) {
    546                 /* Language code from the descriptor is in USB endianness. */
     485                /* Language code from the descriptor is in USB endianess. */
    547486                /* FIXME: is this really correct? */
    548487                uint16_t lang_code = (string_descriptor[2 + 2 * i + 1] << 8)
     
    565504 *
    566505 * @param[in] pipe Control endpoint pipe (session must be already started).
    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).
     506 * @param[in] index String index (in native endianess).
     507 * @param[in] lang String language (in native endianess).
    570508 * @param[out] string_ptr Where to store allocated string in native encoding.
    571509 * @return Error code.
     
    577515                return EBADMEM;
    578516        }
    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)) {
     517        /* Index is actually one byte value. */
     518        if (index > 0xFF) {
    584519                return ERANGE;
    585520        }
     
    609544                goto leave;
    610545        }
    611         /* Subtract first 2 bytes (length and descriptor type). */
     546        /* Substract first 2 bytes (length and descriptor type). */
    612547        string_size -= 2;
    613548
Note: See TracChangeset for help on using the changeset viewer.