Changes in / [0e45e7f:2e1d5d70] in mainline


Ignore:
Location:
uspace
Files:
6 edited

Legend:

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

    r0e45e7f r2e1d5d70  
    4242#include <usb/classes/classes.h>
    4343#include <usb/classes/hid.h>
    44 #include <usb/classes/hub.h>
    4544#include "usbinfo.h"
    4645
     
    120119    usb_standard_configuration_descriptor_t *descriptor)
    121120{
    122         printf("%sConfiguration #%d (%zu interfaces, total %zuB)\n", prefix,
     121        printf("%sConfiguration #%d (%zu interfaces)\n", prefix,
    123122            (int) descriptor->configuration_number,
    124             (size_t) descriptor->interface_count,
    125             (size_t) descriptor->total_length);
     123            (size_t) descriptor->interface_count);
    126124}
    127125
     
    158156}
    159157
    160 static 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 
    168 static void dump_descriptor_tree_callback(uint8_t *descriptor,
     158
     159static void dump_descriptor_tree_brief_callback(uint8_t *descriptor,
    169160    size_t depth, void *arg)
    170161{
     
    183174                if (descr_size >= sizeof(descriptor_type)) { \
    184175                        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                         } \
    190176                } else { \
    191177                        descr_type = -1; \
     
    208194                    usb_standard_hid_descriptor_t,
    209195                    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);
    217196
    218197                default:
     
    227206void dump_descriptor_tree_brief(usbinfo_device_t *dev)
    228207{
    229         dump_descriptor_tree_callback((uint8_t *)&dev->device_descriptor,
     208        dump_descriptor_tree_brief_callback((uint8_t *)&dev->device_descriptor,
    230209            (size_t) -1, NULL);
    231210        usb_dp_walk_simple(dev->full_configuration_descriptor,
    232211            dev->full_configuration_descriptor_size,
    233212            usb_dp_standard_descriptor_nesting,
    234             dump_descriptor_tree_callback,
     213            dump_descriptor_tree_brief_callback,
    235214            NULL);
    236215}
    237 
    238 void 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 
    249216
    250217void dump_strings(usbinfo_device_t *dev)
  • uspace/app/usbinfo/main.c

    r0e45e7f r2e1d5d70  
    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");
    137136        _OPTION("-s --strings", "Try to print all string descriptors.");
    138137
     
    150149        {"match-ids", no_argument, NULL, 'm'},
    151150        {"descriptor-tree", no_argument, NULL, 't'},
    152         {"descriptor-tree-full", no_argument, NULL, 'T'},
    153151        {"strings", no_argument, NULL, 's'},
    154152        {0, 0, NULL, 0}
    155153};
    156 static const char *short_options = "himtTs";
     154static const char *short_options = "himts";
    157155
    158156static usbinfo_action_t actions[] = {
     
    170168                .opt = 't',
    171169                .action = dump_descriptor_tree_brief,
    172                 .active = false
    173         },
    174         {
    175                 .opt = 'T',
    176                 .action = dump_descriptor_tree_full,
    177170                .active = false
    178171        },
  • uspace/app/usbinfo/usbinfo.h

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

    r0e45e7f r2e1d5d70  
    6060} usb_hub_class_feature_t;
    6161
    62 /** Header of standard hub descriptor without the "variadic" part. */
    63 typedef 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;
    7762
    7863/**
  • uspace/lib/usb/include/usb/request.h

    r0e45e7f r2e1d5d70  
    9494    uint16_t, uint16_t, void *, size_t, size_t *);
    9595
    96 int usb_request_get_status(usb_endpoint_pipe_t *, usb_request_recipient_t,
    97     uint16_t, uint16_t *);
    98 int usb_request_clear_feature(usb_endpoint_pipe_t *, usb_request_type_t,
    99     usb_request_recipient_t, uint16_t, uint16_t);
    100 int usb_request_set_feature(usb_endpoint_pipe_t *, usb_request_type_t,
    101     usb_request_recipient_t, uint16_t, uint16_t);
    10296int usb_request_set_address(usb_endpoint_pipe_t *, usb_address_t);
    10397int usb_request_get_descriptor(usb_endpoint_pipe_t *, usb_request_type_t,
     
    114108int usb_request_get_full_configuration_descriptor_alloc(usb_endpoint_pipe_t *,
    115109    int, void **, size_t *);
    116 int 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);
    118 int usb_request_get_configuration(usb_endpoint_pipe_t *, uint8_t *);
    119110int usb_request_set_configuration(usb_endpoint_pipe_t *, uint8_t);
    120 int usb_request_get_interface(usb_endpoint_pipe_t *, uint8_t, uint8_t *);
    121 int usb_request_set_interface(usb_endpoint_pipe_t *, uint8_t, uint8_t);
    122111
    123112int usb_request_get_supported_languages(usb_endpoint_pipe_t *,
  • uspace/lib/usb/src/request.c

    r0e45e7f r2e1d5d70  
    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  */
    167 int 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  */
    205 int 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  */
    233 int 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 
    252159/** Change address of connected device.
    253160 * This function automatically updates the backing connection to point to
     
    566473}
    567474
    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  */
    580 int 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  */
    609 int 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 
    635475/** Set configuration of USB device.
    636476 *
     
    648488            USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
    649489            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  */
    660 int 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  */
    693 int 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),
    701490            NULL, 0);
    702491}
Note: See TracChangeset for help on using the changeset viewer.