Changeset 0e45e7f in mainline


Ignore:
Timestamp:
2011-03-21T13:28:31Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
48fe0c9, 925e099
Parents:
2e1d5d70 (diff), f8e1a2c (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:

USB request wrappers, usbinfo tunning (#53, #136)

The request wrappers are not tested because no driver uses them
(https://sourceforge.net/apps/trac/helenos-usb/ticket/53).

Added full descriptor dump back to usbinfo application
(https://sourceforge.net/apps/trac/helenos-usb/ticket/136).

Location:
uspace
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/usbinfo/info.c

    r2e1d5d70 r0e45e7f  
    4242#include <usb/classes/classes.h>
    4343#include <usb/classes/hid.h>
     44#include <usb/classes/hub.h>
    4445#include "usbinfo.h"
    4546
     
    119120    usb_standard_configuration_descriptor_t *descriptor)
    120121{
    121         printf("%sConfiguration #%d (%zu interfaces)\n", prefix,
     122        printf("%sConfiguration #%d (%zu interfaces, total %zuB)\n", prefix,
    122123            (int) descriptor->configuration_number,
    123             (size_t) descriptor->interface_count);
     124            (size_t) descriptor->interface_count,
     125            (size_t) descriptor->total_length);
    124126}
    125127
     
    156158}
    157159
    158 
    159 static void dump_descriptor_tree_brief_callback(uint8_t *descriptor,
     160static void dump_descriptor_tree_brief_hub(const char *prefix,
     161    usb_hub_descriptor_header_t *descriptor)
     162{
     163        printf("%shub (%d ports)\n", prefix,
     164            (int) descriptor->port_count);
     165}
     166
     167
     168static void dump_descriptor_tree_callback(uint8_t *descriptor,
    160169    size_t depth, void *arg)
    161170{
     
    174183                if (descr_size >= sizeof(descriptor_type)) { \
    175184                        callback(indent, (descriptor_type *) descriptor); \
     185                        if (arg != NULL) { \
     186                                usb_dump_standard_descriptor(stdout, \
     187                                    get_indent(depth +2), "\n", \
     188                                    descriptor, descr_size); \
     189                        } \
    176190                } else { \
    177191                        descr_type = -1; \
     
    194208                    usb_standard_hid_descriptor_t,
    195209                    dump_descriptor_tree_brief_hid);
     210                /*
     211                 * Probably useless, hub descriptor shall not be part of
     212                 * configuration descriptor.
     213                 */
     214                _BRANCH(USB_DESCTYPE_HUB,
     215                    usb_hub_descriptor_header_t,
     216                    dump_descriptor_tree_brief_hub);
    196217
    197218                default:
     
    206227void dump_descriptor_tree_brief(usbinfo_device_t *dev)
    207228{
    208         dump_descriptor_tree_brief_callback((uint8_t *)&dev->device_descriptor,
     229        dump_descriptor_tree_callback((uint8_t *)&dev->device_descriptor,
    209230            (size_t) -1, NULL);
    210231        usb_dp_walk_simple(dev->full_configuration_descriptor,
    211232            dev->full_configuration_descriptor_size,
    212233            usb_dp_standard_descriptor_nesting,
    213             dump_descriptor_tree_brief_callback,
     234            dump_descriptor_tree_callback,
    214235            NULL);
    215236}
     237
     238void dump_descriptor_tree_full(usbinfo_device_t *dev)
     239{
     240        dump_descriptor_tree_callback((uint8_t *)&dev->device_descriptor,
     241            (size_t) -1, dev);
     242        usb_dp_walk_simple(dev->full_configuration_descriptor,
     243            dev->full_configuration_descriptor_size,
     244            usb_dp_standard_descriptor_nesting,
     245            dump_descriptor_tree_callback,
     246            dev);
     247}
     248
    216249
    217250void dump_strings(usbinfo_device_t *dev)
  • uspace/app/usbinfo/main.c

    r2e1d5d70 r0e45e7f  
    134134        _OPTION("-m --match-ids", "Print match ids generated for the device.");
    135135        _OPTION("-t --descriptor-tree", "Print descriptor tree.");
     136        _OPTION("-T --descriptor-tree-full", "Print detailed descriptor tree");
    136137        _OPTION("-s --strings", "Try to print all string descriptors.");
    137138
     
    149150        {"match-ids", no_argument, NULL, 'm'},
    150151        {"descriptor-tree", no_argument, NULL, 't'},
     152        {"descriptor-tree-full", no_argument, NULL, 'T'},
    151153        {"strings", no_argument, NULL, 's'},
    152154        {0, 0, NULL, 0}
    153155};
    154 static const char *short_options = "himts";
     156static const char *short_options = "himtTs";
    155157
    156158static usbinfo_action_t actions[] = {
     
    168170                .opt = 't',
    169171                .action = dump_descriptor_tree_brief,
     172                .active = false
     173        },
     174        {
     175                .opt = 'T',
     176                .action = dump_descriptor_tree_full,
    170177                .active = false
    171178        },
  • uspace/app/usbinfo/usbinfo.h

    r2e1d5d70 r0e45e7f  
    8282void dump_device_match_ids(usbinfo_device_t *);
    8383void dump_descriptor_tree_brief(usbinfo_device_t *);
     84void dump_descriptor_tree_full(usbinfo_device_t *);
    8485void dump_strings(usbinfo_device_t *);
    8586
  • uspace/lib/usb/include/usb/classes/hub.h

    r2e1d5d70 r0e45e7f  
    6060} usb_hub_class_feature_t;
    6161
     62/** Header of standard hub descriptor without the "variadic" part. */
     63typedef struct {
     64        /** Descriptor length. */
     65        uint8_t length;
     66        /** Descriptor type (0x29). */
     67        uint8_t descriptor_type;
     68        /** Number of downstream ports. */
     69        uint8_t port_count;
     70        /** Characteristics bitmask. */
     71        uint16_t characteristics;
     72        /** Time from power-on to stabilization of current on the port. */
     73        uint8_t power_good_time;
     74        /** Maximum current requirements in mA. */
     75        uint8_t max_current;
     76} __attribute__ ((packed)) usb_hub_descriptor_header_t;
    6277
    6378/**
  • uspace/lib/usb/include/usb/request.h

    r2e1d5d70 r0e45e7f  
    9494    uint16_t, uint16_t, void *, size_t, size_t *);
    9595
     96int usb_request_get_status(usb_endpoint_pipe_t *, usb_request_recipient_t,
     97    uint16_t, uint16_t *);
     98int usb_request_clear_feature(usb_endpoint_pipe_t *, usb_request_type_t,
     99    usb_request_recipient_t, uint16_t, uint16_t);
     100int usb_request_set_feature(usb_endpoint_pipe_t *, usb_request_type_t,
     101    usb_request_recipient_t, uint16_t, uint16_t);
    96102int usb_request_set_address(usb_endpoint_pipe_t *, usb_address_t);
    97103int usb_request_get_descriptor(usb_endpoint_pipe_t *, usb_request_type_t,
     
    108114int usb_request_get_full_configuration_descriptor_alloc(usb_endpoint_pipe_t *,
    109115    int, void **, size_t *);
     116int usb_request_set_descriptor(usb_endpoint_pipe_t *, usb_request_type_t,
     117    usb_request_recipient_t, uint8_t, uint8_t, uint16_t, void *, size_t);
     118int usb_request_get_configuration(usb_endpoint_pipe_t *, uint8_t *);
    110119int usb_request_set_configuration(usb_endpoint_pipe_t *, uint8_t);
     120int usb_request_get_interface(usb_endpoint_pipe_t *, uint8_t, uint8_t *);
     121int usb_request_set_interface(usb_endpoint_pipe_t *, uint8_t, uint8_t);
    111122
    112123int usb_request_get_supported_languages(usb_endpoint_pipe_t *,
  • uspace/lib/usb/src/request.c

    r2e1d5d70 r0e45e7f  
    157157}
    158158
     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_endpoint_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_endpoint_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_endpoint_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);
     248
     249        return rc;
     250}
     251
    159252/** Change address of connected device.
    160253 * This function automatically updates the backing connection to point to
     
    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_endpoint_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_endpoint_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 *
     
    488648            USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
    489649            USB_DEVREQ_SET_CONFIGURATION, config_value, 0,
     650            NULL, 0);
     651}
     652
     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_endpoint_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_endpoint_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),
    490701            NULL, 0);
    491702}
Note: See TracChangeset for help on using the changeset viewer.