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


Ignore:
Timestamp:
2011-03-22T10:07:53Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f8e4cb6
Parents:
18b3cfd (diff), b01995b (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:

Merged changes from development

File:
1 edited

Legend:

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

    r18b3cfd r62f4212  
    4242/** Generic wrapper for SET requests using standard control request format.
    4343 *
    44  * @see usb_endpoint_pipe_control_write
     44 * @see usb_pipe_control_write
    4545 *
    4646 * @param pipe Pipe used for the communication.
     
    6060 * @retval ERANGE Data buffer too large.
    6161 */
    62 int usb_control_request_set(usb_endpoint_pipe_t *pipe,
     62int usb_control_request_set(usb_pipe_t *pipe,
    6363    usb_request_type_t request_type, usb_request_recipient_t recipient,
    6464    uint8_t request,
     
    9090        setup_packet.length = (uint16_t) data_size;
    9191
    92         int rc = usb_endpoint_pipe_control_write(pipe,
     92        int rc = usb_pipe_control_write(pipe,
    9393            &setup_packet, sizeof(setup_packet),
    9494            data, data_size);
     
    9999 /** Generic wrapper for GET requests using standard control request format.
    100100  *
    101   * @see usb_endpoint_pipe_control_read
     101  * @see usb_pipe_control_read
    102102  *
    103103  * @param pipe Pipe used for the communication.
     
    120120  * @retval ERANGE Data buffer too large.
    121121  */
    122 int usb_control_request_get(usb_endpoint_pipe_t *pipe,
     122int usb_control_request_get(usb_pipe_t *pipe,
    123123    usb_request_type_t request_type, usb_request_recipient_t recipient,
    124124    uint8_t request,
     
    150150        setup_packet.length = (uint16_t) data_size;
    151151
    152         int rc = usb_endpoint_pipe_control_read(pipe,
     152        int rc = usb_pipe_control_read(pipe,
    153153            &setup_packet, sizeof(setup_packet),
    154154            data, data_size, actual_data_size);
     155
     156        return rc;
     157}
     158
     159/** Retrieve status of a USB device.
     160 *
     161 * @param[in] pipe Control endpoint pipe (session must be already started).
     162 * @param[in] index Recipient index (in native endianness).
     163 * @param[in] recipient Recipient of the GET_STATUS request.
     164 * @param[out] status Recipient status (in native endianness).
     165 * @return Error code.
     166 */
     167int usb_request_get_status(usb_pipe_t *pipe,
     168    usb_request_recipient_t recipient, uint16_t index,
     169    uint16_t *status)
     170{
     171        if ((recipient == USB_REQUEST_RECIPIENT_DEVICE) && (index != 0)) {
     172                return EINVAL;
     173        }
     174
     175        if (status == NULL) {
     176                return EBADMEM;
     177        }
     178
     179        uint16_t status_usb_endianess;
     180        size_t data_transfered_size;
     181        int rc = usb_control_request_get(pipe, USB_REQUEST_TYPE_STANDARD,
     182            recipient, USB_DEVREQ_GET_STATUS, 0, uint16_host2usb(index),
     183            &status_usb_endianess, 2, &data_transfered_size);
     184        if (rc != EOK) {
     185                return rc;
     186        }
     187        if (data_transfered_size != 2) {
     188                return ELIMIT;
     189        }
     190
     191        *status = uint16_usb2host(status_usb_endianess);
     192
     193        return EOK;
     194}
     195
     196/** Clear or disable specific device feature.
     197 *
     198 * @param[in] pipe Control endpoint pipe (session must be already started).
     199 * @param[in] request_type Request type (standard/class/vendor).
     200 * @param[in] recipient Recipient of the CLEAR_FEATURE request.
     201 * @param[in] feature_selector Feature selector (in native endianness).
     202 * @param[in] index Recipient index (in native endianness).
     203 * @return Error code.
     204 */
     205int usb_request_clear_feature(usb_pipe_t *pipe,
     206    usb_request_type_t request_type, usb_request_recipient_t recipient,
     207    uint16_t feature_selector, uint16_t index)
     208{
     209        if (request_type == USB_REQUEST_TYPE_STANDARD) {
     210                if ((recipient == USB_REQUEST_RECIPIENT_DEVICE)
     211                    && (index != 0)) {
     212                        return EINVAL;
     213                }
     214        }
     215
     216        int rc = usb_control_request_set(pipe, request_type, recipient,
     217            USB_DEVREQ_CLEAR_FEATURE,
     218            uint16_host2usb(feature_selector), uint16_host2usb(index),
     219            NULL, 0);
     220
     221        return rc;
     222}
     223
     224/** Set or enable specific device feature.
     225 *
     226 * @param[in] pipe Control endpoint pipe (session must be already started).
     227 * @param[in] request_type Request type (standard/class/vendor).
     228 * @param[in] recipient Recipient of the SET_FEATURE request.
     229 * @param[in] feature_selector Feature selector (in native endianness).
     230 * @param[in] index Recipient index (in native endianness).
     231 * @return Error code.
     232 */
     233int usb_request_set_feature(usb_pipe_t *pipe,
     234    usb_request_type_t request_type, usb_request_recipient_t recipient,
     235    uint16_t feature_selector, uint16_t index)
     236{
     237        if (request_type == USB_REQUEST_TYPE_STANDARD) {
     238                if ((recipient == USB_REQUEST_RECIPIENT_DEVICE)
     239                    && (index != 0)) {
     240                        return EINVAL;
     241                }
     242        }
     243
     244        int rc = usb_control_request_set(pipe, request_type, recipient,
     245            USB_DEVREQ_SET_FEATURE,
     246            uint16_host2usb(feature_selector), uint16_host2usb(index),
     247            NULL, 0);
    155248
    156249        return rc;
     
    165258 * @return Error code.
    166259 */
    167 int usb_request_set_address(usb_endpoint_pipe_t *pipe,
     260int usb_request_set_address(usb_pipe_t *pipe,
    168261    usb_address_t new_address)
    169262{
     
    204297 * @return Error code.
    205298 */
    206 int usb_request_get_descriptor(usb_endpoint_pipe_t *pipe,
     299int usb_request_get_descriptor(usb_pipe_t *pipe,
    207300    usb_request_type_t request_type, usb_request_recipient_t recipient,
    208301    uint8_t descriptor_type, uint8_t descriptor_index,
     
    238331 * @return
    239332 */
    240 int usb_request_get_descriptor_alloc(usb_endpoint_pipe_t * pipe,
     333int usb_request_get_descriptor_alloc(usb_pipe_t * pipe,
    241334    usb_request_type_t request_type, usb_request_recipient_t recipient,
    242335    uint8_t descriptor_type, uint8_t descriptor_index,
     
    307400 * @return Error code.
    308401 */
    309 int usb_request_get_device_descriptor(usb_endpoint_pipe_t *pipe,
     402int usb_request_get_device_descriptor(usb_pipe_t *pipe,
    310403    usb_standard_device_descriptor_t *descriptor)
    311404{
     
    349442 * @return Error code.
    350443 */
    351 int usb_request_get_bare_configuration_descriptor(usb_endpoint_pipe_t *pipe,
     444int usb_request_get_bare_configuration_descriptor(usb_pipe_t *pipe,
    352445    int index, usb_standard_configuration_descriptor_t *descriptor)
    353446{
     
    395488 * @return Error code.
    396489 */
    397 int usb_request_get_full_configuration_descriptor(usb_endpoint_pipe_t *pipe,
     490int usb_request_get_full_configuration_descriptor(usb_pipe_t *pipe,
    398491    int index, void *descriptor, size_t descriptor_size, size_t *actual_size)
    399492{
     
    421514 */
    422515int usb_request_get_full_configuration_descriptor_alloc(
    423     usb_endpoint_pipe_t *pipe, int index,
     516    usb_pipe_t *pipe, int index,
    424517    void **descriptor_ptr, size_t *descriptor_size)
    425518{
     
    473566}
    474567
     568/** Update existing or add new USB descriptor to a USB device.
     569 *
     570 * @param[in] pipe Control endpoint pipe (session must be already started).
     571 * @param[in] request_type Request type (standard/class/vendor).
     572 * @param[in] recipient Request recipient (device/interface/endpoint).
     573 * @param[in] descriptor_type Descriptor type (device/configuration/HID/...).
     574 * @param[in] descriptor_index Descriptor index.
     575 * @param[in] language Language index (in native endianness).
     576 * @param[in] buffer Buffer with the new descriptor (in USB endianness).
     577 * @param[in] size Size of the @p buffer in bytes (in native endianness).
     578 * @return Error code.
     579 */
     580int usb_request_set_descriptor(usb_pipe_t *pipe,
     581    usb_request_type_t request_type, usb_request_recipient_t recipient,
     582    uint8_t descriptor_type, uint8_t descriptor_index,
     583    uint16_t language,
     584    void *buffer, size_t size)
     585{
     586        if (buffer == NULL) {
     587                return EBADMEM;
     588        }
     589        if (size == 0) {
     590                return EINVAL;
     591        }
     592
     593        /* FIXME: proper endianness. */
     594        uint16_t wValue = descriptor_index | (descriptor_type << 8);
     595
     596        return usb_control_request_set(pipe,
     597            request_type, recipient,
     598            USB_DEVREQ_SET_DESCRIPTOR,
     599            wValue, language,
     600            buffer, size);
     601}
     602
     603/** Get current configuration value of USB device.
     604 *
     605 * @param[in] pipe Control endpoint pipe (session must be already started).
     606 * @param[out] configuration_value Current configuration value.
     607 * @return Error code.
     608 */
     609int usb_request_get_configuration(usb_pipe_t *pipe,
     610    uint8_t *configuration_value)
     611{
     612        uint8_t value;
     613        size_t actual_size;
     614
     615        int rc = usb_control_request_get(pipe,
     616            USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
     617            USB_DEVREQ_GET_CONFIGURATION,
     618            0, 0,
     619            &value, 1, &actual_size);
     620
     621        if (rc != EOK) {
     622                return rc;
     623        }
     624        if (actual_size != 1) {
     625                return ELIMIT;
     626        }
     627
     628        if (configuration_value != NULL) {
     629                *configuration_value = value;
     630        }
     631
     632        return EOK;
     633}
     634
    475635/** Set configuration of USB device.
    476636 *
     
    479639 * @return Error code.
    480640 */
    481 int usb_request_set_configuration(usb_endpoint_pipe_t *pipe,
     641int usb_request_set_configuration(usb_pipe_t *pipe,
    482642    uint8_t configuration_value)
    483643{
     
    491651}
    492652
     653/** Get selected alternate setting for USB interface.
     654 *
     655 * @param[in] pipe Control endpoint pipe (session must be already started).
     656 * @param[in] interface_index Interface index.
     657 * @param[out] alternate_setting Alternate setting for the interface.
     658 * @return Error code.
     659 */
     660int usb_request_get_interface(usb_pipe_t *pipe,
     661    uint8_t interface_index, uint8_t *alternate_setting)
     662{
     663        uint8_t value;
     664        size_t actual_size;
     665
     666        int rc = usb_control_request_get(pipe,
     667            USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE,
     668            USB_DEVREQ_GET_INTERFACE,
     669            0, uint16_host2usb((uint16_t) interface_index),
     670            &value, 1, &actual_size);
     671
     672        if (rc != EOK) {
     673                return rc;
     674        }
     675        if (actual_size != 1) {
     676                return ELIMIT;
     677        }
     678
     679        if (alternate_setting != NULL) {
     680                *alternate_setting = value;
     681        }
     682
     683        return EOK;
     684}
     685
     686/** Select alternate setting for USB interface.
     687 *
     688 * @param[in] pipe Control endpoint pipe (session must be already started).
     689 * @param[in] interface_index Interface index.
     690 * @param[in] alternate_setting Alternate setting to select.
     691 * @return Error code.
     692 */
     693int usb_request_set_interface(usb_pipe_t *pipe,
     694    uint8_t interface_index, uint8_t alternate_setting)
     695{
     696        return usb_control_request_set(pipe,
     697            USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_INTERFACE,
     698            USB_DEVREQ_SET_INTERFACE,
     699            uint16_host2usb((uint16_t) alternate_setting),
     700            uint16_host2usb((uint16_t) interface_index),
     701            NULL, 0);
     702}
     703
    493704/** Get list of supported languages by USB device.
    494705 *
     
    499710 * @return Error code.
    500711 */
    501 int usb_request_get_supported_languages(usb_endpoint_pipe_t *pipe,
     712int usb_request_get_supported_languages(usb_pipe_t *pipe,
    502713    l18_win_locales_t **languages_ptr, size_t *languages_count)
    503714{
     
    571782 * @return Error code.
    572783 */
    573 int usb_request_get_string(usb_endpoint_pipe_t *pipe,
     784int usb_request_get_string(usb_pipe_t *pipe,
    574785    size_t index, l18_win_locales_t lang, char **string_ptr)
    575786{
Note: See TracChangeset for help on using the changeset viewer.