Changeset 8a121b1 in mainline for uspace/lib/usbdev/src


Ignore:
Timestamp:
2011-10-15T11:58:16Z (14 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/lib/usbdev/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.