Changeset 8a121b1 in mainline


Ignore:
Timestamp:
2011-10-15T11:58:16Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7c95d6f5
Parents:
2a5b62b
Message:

usb: Make descriptors readonly.

Location:
uspace
Files:
13 edited

Legend:

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

    r2a5b62b r8a121b1  
    5050
    5151static void browse_descriptor_tree_internal(usb_dp_parser_t *parser,
    52     usb_dp_parser_data_t *data, uint8_t *root, size_t depth,
     52    usb_dp_parser_data_t *data, const uint8_t *root, size_t depth,
    5353    dump_descriptor_in_tree_t callback, void *arg)
    5454{
     
    5757        }
    5858        callback(root, depth, arg);
    59         uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
     59        const uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
    6060        do {
    6161                browse_descriptor_tree_internal(parser, data, child, depth + 1,
  • uspace/app/usbinfo/dump.c

    r2a5b62b r8a121b1  
    110110}
    111111
    112 static void dump_tree_descriptor(uint8_t *descriptor, size_t depth)
     112static void dump_tree_descriptor(const uint8_t *descriptor, size_t depth)
    113113{
    114114        if (descriptor == NULL) {
    115115                return;
    116116        }
    117         int type = (int) *(descriptor + 1);
     117        int type = descriptor[1];
    118118        const char *name = "unknown";
    119119        switch (type) {
     
    136136}
    137137
    138 static void dump_tree_internal(usb_dp_parser_t *parser, usb_dp_parser_data_t *data,
    139     uint8_t *root, size_t depth)
     138static void dump_tree_internal(
     139    usb_dp_parser_t *parser, usb_dp_parser_data_t *data,
     140    const uint8_t *root, size_t depth)
    140141{
    141142        if (root == NULL) {
     
    143144        }
    144145        dump_tree_descriptor(root, depth);
    145         uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
     146        const uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
    146147        do {
    147148                dump_tree_internal(parser, data, child, depth + 1);
  • uspace/app/usbinfo/hid.c

    r2a5b62b r8a121b1  
    5555} descriptor_walk_context_t;
    5656
    57 static bool is_descriptor_kind(uint8_t *d, usb_descriptor_type_t t)
     57static bool is_descriptor_kind(const uint8_t *d, usb_descriptor_type_t t)
    5858{
    5959        if (d == NULL) {
     
    180180 * @param arg Custom argument, passed as descriptor_walk_context_t.
    181181 */
    182 static void descriptor_walk_callback(uint8_t *raw_descriptor,
     182static void descriptor_walk_callback(const uint8_t *raw_descriptor,
    183183    size_t depth, void *arg)
    184184{
  • uspace/app/usbinfo/info.c

    r2a5b62b r8a121b1  
    5151}
    5252
    53 static void dump_match_ids_from_interface(uint8_t *descriptor, size_t depth,
    54     void *arg)
     53static void dump_match_ids_from_interface(
     54    const uint8_t *descriptor, size_t depth, void *arg)
    5555{
    5656        if (depth != 1) {
     
    165165
    166166
    167 static void dump_descriptor_tree_callback(uint8_t *descriptor,
    168     size_t depth, void *arg)
     167static void dump_descriptor_tree_callback(
     168    const uint8_t *descriptor, size_t depth, void *arg)
    169169{
    170170        const char *indent = get_indent(depth + 1);
     
    246246}
    247247
    248 static void find_string_indexes_callback(uint8_t *descriptor,
    249     size_t depth, void *arg)
     248static void find_string_indexes_callback(
     249    const uint8_t *descriptor, size_t depth, void *arg)
    250250{
    251251        size_t descriptor_length = descriptor[0];
  • uspace/app/usbinfo/usbinfo.h

    r2a5b62b r8a121b1  
    7474void destroy_device(usbinfo_device_t *);
    7575
    76 typedef void (*dump_descriptor_in_tree_t)(uint8_t *, size_t, void *);
     76typedef void (*dump_descriptor_in_tree_t)(const uint8_t *, size_t, void *);
    7777void browse_descriptor_tree(uint8_t *, size_t, usb_dp_descriptor_nesting_t *,
    7878    dump_descriptor_in_tree_t, size_t, void *);
  • uspace/drv/bus/usb/usbmid/dump.c

    r2a5b62b r8a121b1  
    4747 * @param depth Nesting depth.
    4848 */
    49 static void dump_tree_descriptor(uint8_t *data, size_t depth)
     49static void dump_tree_descriptor(const uint8_t *data, size_t depth)
    5050{
    5151        if (data == NULL) {
    5252                return;
    5353        }
    54         int type = (int) *(data + 1);
     54        const int type = data[1];
    5555        if (type == USB_DESCTYPE_INTERFACE) {
    5656                usb_standard_interface_descriptor_t *descriptor
     
    7171 * @param depth Nesting depth.
    7272 */
    73 static void dump_tree_internal(usb_dp_parser_t *parser, usb_dp_parser_data_t *data,
    74     uint8_t *root, size_t depth)
     73static void dump_tree_internal(
     74    usb_dp_parser_t *parser, usb_dp_parser_data_t *data,
     75    const uint8_t *root, size_t depth)
    7576{
    7677        if (root == NULL) {
     
    7879        }
    7980        dump_tree_descriptor(root, depth);
    80         uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
     81        const uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
    8182        do {
    8283                dump_tree_internal(parser, data, child, depth + 1);
  • uspace/drv/bus/usb/usbmid/explore.c

    r2a5b62b r8a121b1  
    8686        };
    8787
    88         uint8_t *interface_ptr = usb_dp_get_nested_descriptor(&parser, &data,
    89             data.data);
     88        const uint8_t *interface_ptr =
     89            usb_dp_get_nested_descriptor(&parser, &data, data.data);
    9090        if (interface_ptr == NULL) {
    9191                return;
  • uspace/lib/usbdev/include/usb/dev/dp.h

    r2a5b62b r8a121b1  
    5959typedef struct {
    6060        /** Used descriptor nesting. */
    61         usb_dp_descriptor_nesting_t *nesting;
     61        const usb_dp_descriptor_nesting_t *nesting;
    6262} usb_dp_parser_t;
    6363
     
    7272} usb_dp_parser_data_t;
    7373
    74 uint8_t *usb_dp_get_nested_descriptor(usb_dp_parser_t *,
    75     usb_dp_parser_data_t *, uint8_t *);
    76 uint8_t *usb_dp_get_sibling_descriptor(usb_dp_parser_t *,
    77     usb_dp_parser_data_t *, uint8_t *, uint8_t *);
     74typedef void (*walk_callback_t)(const uint8_t *, size_t, void *);
    7875
    79 void usb_dp_walk_simple(uint8_t *, size_t, usb_dp_descriptor_nesting_t *,
    80     void (*)(uint8_t *, size_t, void *), void *);
     76const uint8_t *usb_dp_get_nested_descriptor(const usb_dp_parser_t *,
     77    const usb_dp_parser_data_t *, const uint8_t *);
     78const uint8_t *usb_dp_get_sibling_descriptor(const usb_dp_parser_t *,
     79    const usb_dp_parser_data_t *, const uint8_t *, const uint8_t *);
     80
     81void usb_dp_walk_simple(uint8_t *, size_t, const usb_dp_descriptor_nesting_t *,
     82    walk_callback_t, void *);
    8183
    8284#endif
  • uspace/lib/usbdev/include/usb/dev/driver.h

    r2a5b62b r8a121b1  
    5353typedef struct {
    5454        /** Interface descriptor. */
    55         usb_standard_interface_descriptor_t *interface;
     55        const usb_standard_interface_descriptor_t *interface;
    5656        /** Pointer to start of descriptor tree bound with this interface. */
    57         uint8_t *nested_descriptors;
     57        const uint8_t *nested_descriptors;
    5858        /** Size of data pointed by nested_descriptors in bytes. */
    5959        size_t nested_descriptors_size;
  • uspace/lib/usbdev/src/altiface.c

    r2a5b62b r8a121b1  
    5454        assert(config_descr_size > 0);
    5555
    56         usb_dp_parser_t dp_parser = {
     56        const usb_dp_parser_t dp_parser = {
    5757                .nesting = usb_dp_standard_descriptor_nesting
    5858        };
    59         usb_dp_parser_data_t dp_data = {
     59        const usb_dp_parser_data_t dp_data = {
    6060                .data = config_descr,
    6161                .size = config_descr_size,
     
    6565        size_t alternate_count = 0;
    6666
    67         uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,
     67        const uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,
    6868            &dp_data, config_descr);
    6969        while (iface_ptr != NULL) {
     
    140140            = &alternates->alternatives[0];
    141141
    142         uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,
     142        const uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,
    143143            &dp_data, dp_data.data);
    144144        while (iface_ptr != NULL) {
  • uspace/lib/usbdev/src/dp.c

    r2a5b62b r8a121b1  
    7575 * @return Whether @p ptr points inside <code>data->data</code> field.
    7676 */
    77 static bool is_valid_descriptor_pointer(usb_dp_parser_data_t *data,
    78     uint8_t *ptr)
     77static bool is_valid_descriptor_pointer(const usb_dp_parser_data_t *data,
     78    const uint8_t *ptr)
    7979{
    8080        if (ptr == NULL) {
     
    100100 * @retval NULL Invalid input or no next descriptor.
    101101 */
    102 static uint8_t *get_next_descriptor(usb_dp_parser_data_t *data,
    103     uint8_t *current)
     102static const uint8_t *get_next_descriptor(const usb_dp_parser_data_t *data,
     103    const uint8_t *current)
    104104{
    105105        assert(is_valid_descriptor_pointer(data, current));
    106106
    107         uint8_t current_length = *current;
    108         uint8_t *next = current + current_length;
     107        const uint8_t current_length = *current;
     108        const uint8_t *next = current + current_length;
    109109
    110110        if (!is_valid_descriptor_pointer(data, next)) {
     
    124124 * @retval -1 Invalid input.
    125125 */
    126 static int get_descriptor_type(usb_dp_parser_data_t *data, uint8_t *start)
     126static int get_descriptor_type(const usb_dp_parser_data_t *data, const uint8_t *start)
    127127{
    128128        if (start == NULL) {
     
    145145 * @return Whether @p child could be child of @p parent.
    146146 */
    147 static bool is_nested_descriptor_type(usb_dp_parser_t *parser,
     147static bool is_nested_descriptor_type(const usb_dp_parser_t *parser,
    148148    int child, int parent)
    149149{
    150         usb_dp_descriptor_nesting_t *nesting = parser->nesting;
     150        const usb_dp_descriptor_nesting_t *nesting = parser->nesting;
    151151        while ((nesting->child > 0) && (nesting->parent > 0)) {
    152152                if ((nesting->child == child) && (nesting->parent == parent)) {
     
    166166 * @return Whether @p child could be child of @p parent.
    167167 */
    168 static bool is_nested_descriptor(usb_dp_parser_t *parser,
    169     usb_dp_parser_data_t *data, uint8_t *child, uint8_t *parent)
     168static bool is_nested_descriptor(const usb_dp_parser_t *parser,
     169    const usb_dp_parser_data_t *data, const uint8_t *child, const uint8_t *parent)
    170170{
    171171        return is_nested_descriptor_type(parser,
     
    183183 * @retval NULL Invalid input.
    184184 */
    185 uint8_t *usb_dp_get_nested_descriptor(usb_dp_parser_t *parser,
    186     usb_dp_parser_data_t *data, uint8_t *parent)
     185const uint8_t *usb_dp_get_nested_descriptor(const usb_dp_parser_t *parser,
     186    const usb_dp_parser_data_t *data, const uint8_t *parent)
    187187{
    188188        if (!is_valid_descriptor_pointer(data, parent)) {
     
    190190        }
    191191
    192         uint8_t *next = get_next_descriptor(data, parent);
     192        const uint8_t *next = get_next_descriptor(data, parent);
    193193        if (next == NULL) {
    194194                return NULL;
     
    211211 * @retval NULL Invalid input.
    212212 */
    213 static uint8_t *skip_nested_descriptors(usb_dp_parser_t *parser,
    214     usb_dp_parser_data_t *data, uint8_t *parent)
    215 {
    216         uint8_t *child = usb_dp_get_nested_descriptor(parser, data, parent);
     213static const uint8_t *skip_nested_descriptors(const usb_dp_parser_t *parser,
     214    const usb_dp_parser_data_t *data, const uint8_t *parent)
     215{
     216        const uint8_t *child =
     217            usb_dp_get_nested_descriptor(parser, data, parent);
    217218        if (child == NULL) {
    218219                return get_next_descriptor(data, parent);
    219220        }
    220         uint8_t *next_child = skip_nested_descriptors(parser, data, child);
     221        const uint8_t *next_child =
     222            skip_nested_descriptors(parser, data, child);
    221223        while (is_nested_descriptor(parser, data, next_child, parent)) {
    222224                next_child = skip_nested_descriptors(parser, data, next_child);
     
    236238 * @retval NULL Invalid input.
    237239 */
    238 uint8_t *usb_dp_get_sibling_descriptor(usb_dp_parser_t *parser,
    239     usb_dp_parser_data_t *data, uint8_t *parent, uint8_t *sibling)
     240const uint8_t *usb_dp_get_sibling_descriptor(
     241    const usb_dp_parser_t *parser, const usb_dp_parser_data_t *data,
     242    const uint8_t *parent, const uint8_t *sibling)
    240243{
    241244        if (!is_valid_descriptor_pointer(data, parent)
     
    244247        }
    245248
    246         uint8_t *possible_sibling = skip_nested_descriptors(parser, data, sibling);
     249        const uint8_t *possible_sibling =
     250            skip_nested_descriptors(parser, data, sibling);
    247251        if (possible_sibling == NULL) {
    248252                return NULL;
     
    269273 * @param arg Custom (user) argument.
    270274 */
    271 static void usb_dp_browse_simple_internal(usb_dp_parser_t *parser,
    272     usb_dp_parser_data_t *data, uint8_t *root, size_t depth,
    273     void (*callback)(uint8_t *, size_t, void *), void *arg)
     275static void usb_dp_browse_simple_internal(const usb_dp_parser_t *parser,
     276    const usb_dp_parser_data_t *data, const uint8_t *root, size_t depth,
     277    void (*callback)(const uint8_t *, size_t, void *), void *arg)
    274278{
    275279        if (root == NULL) {
     
    277281        }
    278282        callback(root, depth, arg);
    279         uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
     283        const uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
    280284        do {
    281285                usb_dp_browse_simple_internal(parser, data, child, depth + 1,
     
    301305 */
    302306void usb_dp_walk_simple(uint8_t *descriptors, size_t descriptors_size,
    303     usb_dp_descriptor_nesting_t *descriptor_nesting,
    304     void (*callback)(uint8_t *, size_t, void *), void *arg)
     307    const usb_dp_descriptor_nesting_t *descriptor_nesting,
     308    walk_callback_t callback, void *arg)
    305309{
    306310        if ((descriptors == NULL) || (descriptors_size == 0)
     
    309313        }
    310314
    311         usb_dp_parser_data_t data = {
     315        const usb_dp_parser_data_t data = {
    312316                .data = descriptors,
    313317                .size = descriptors_size,
     
    315319        };
    316320
    317         usb_dp_parser_t parser = {
     321        const usb_dp_parser_t parser = {
    318322                .nesting = descriptor_nesting
    319323        };
  • uspace/lib/usbdev/src/pipesinit.c

    r2a5b62b r8a121b1  
    6868 * @return Whether the given descriptor is endpoint descriptor.
    6969 */
    70 static inline bool is_endpoint_descriptor(uint8_t *descriptor)
     70static inline bool is_endpoint_descriptor(const uint8_t *descriptor)
    7171{
    7272        return descriptor[1] == USB_DESCTYPE_ENDPOINT;
     
    8080 */
    8181static bool endpoint_fits_description(const usb_endpoint_description_t *wanted,
    82     usb_endpoint_description_t *found)
     82    const usb_endpoint_description_t *found)
    8383{
    8484#define _SAME(fieldname) ((wanted->fieldname) == (found->fieldname))
     
    120120static usb_endpoint_mapping_t *find_endpoint_mapping(
    121121    usb_endpoint_mapping_t *mapping, size_t mapping_count,
    122     usb_endpoint_description_t *found_endpoint,
     122    const usb_endpoint_description_t *found_endpoint,
    123123    int interface_number, int interface_setting)
    124124{
     
    160160    usb_device_connection_t *wire)
    161161{
    162         usb_endpoint_description_t description;
    163162
    164163        /*
     
    167166
    168167        /* Actual endpoint number is in bits 0..3 */
    169         usb_endpoint_t ep_no = endpoint->endpoint_address & 0x0F;
    170 
    171         /* Endpoint direction is set by bit 7 */
    172         description.direction = (endpoint->endpoint_address & 128)
    173             ? USB_DIRECTION_IN : USB_DIRECTION_OUT;
    174         /* Transfer type is in bits 0..2 and the enum values corresponds 1:1 */
    175         description.transfer_type = endpoint->attributes & 3;
    176 
    177         /*
    178          * Get interface characteristics.
    179          */
    180         description.interface_class = interface->interface_class;
    181         description.interface_subclass = interface->interface_subclass;
    182         description.interface_protocol = interface->interface_protocol;
     168        const usb_endpoint_t ep_no = endpoint->endpoint_address & 0x0F;
     169
     170        const usb_endpoint_description_t description = {
     171                /* Endpoint direction is set by bit 7 */
     172                .direction = (endpoint->endpoint_address & 128)
     173                    ? USB_DIRECTION_IN : USB_DIRECTION_OUT,
     174                /* Transfer type is in bits 0..2 and
     175                 * the enum values corresponds 1:1 */
     176                .transfer_type = endpoint->attributes & 3,
     177
     178                /* Get interface characteristics. */
     179                .interface_class = interface->interface_class,
     180                .interface_subclass = interface->interface_subclass,
     181                .interface_protocol = interface->interface_protocol,
     182        };
    183183
    184184        /*
     
    225225    usb_endpoint_mapping_t *mapping, size_t mapping_count,
    226226    usb_dp_parser_t *parser, usb_dp_parser_data_t *parser_data,
    227     uint8_t *interface_descriptor)
    228 {
    229         uint8_t *descriptor = usb_dp_get_nested_descriptor(parser,
     227    const uint8_t *interface_descriptor)
     228{
     229        const uint8_t *descriptor = usb_dp_get_nested_descriptor(parser,
    230230            parser_data, interface_descriptor);
    231231
     
    322322         * Iterate through all interfaces.
    323323         */
    324         uint8_t *interface = usb_dp_get_nested_descriptor(&dp_parser,
     324        const uint8_t *interface = usb_dp_get_nested_descriptor(&dp_parser,
    325325            &dp_data, configuration_descriptor);
    326326        if (interface == NULL) {
     
    329329        do {
    330330                (void) process_interface(mapping, mapping_count,
    331                     &dp_parser, &dp_data,
    332                     interface);
     331                    &dp_parser, &dp_data, interface);
    333332                interface = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data,
    334333                    configuration_descriptor, interface);
  • uspace/lib/usbhid/src/hidreport.c

    r2a5b62b r8a121b1  
    6969         * First nested descriptor of the configuration descriptor.
    7070         */
    71         uint8_t *d =
     71        const uint8_t *d =
    7272            usb_dp_get_nested_descriptor(&parser, &parser_data,
    7373            dev->descriptors.configuration);
     
    9292         * First nested descriptor of the interface descriptor.
    9393         */
    94         uint8_t *iface_desc = d;
     94        const uint8_t *iface_desc = d;
    9595        d = usb_dp_get_nested_descriptor(&parser, &parser_data, iface_desc);
    9696       
Note: See TracChangeset for help on using the changeset viewer.