Changeset f8e8738 in mainline for uspace/lib


Ignore:
Timestamp:
2011-04-07T20:22:40Z (15 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fee6381
Parents:
61257f4 (diff), a82889e (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:

Changes from development

Location:
uspace/lib
Files:
6 added
35 edited
2 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/Makefile

    r61257f4 rf8e8738  
    7777        generic/io/io.c \
    7878        generic/io/printf.c \
     79        generic/io/log.c \
    7980        generic/io/klog.c \
    8081        generic/io/snprintf.c \
  • uspace/lib/c/arch/abs32le/_link.ld.in

    r61257f4 rf8e8738  
    1111       
    1212        .text : {
    13                 *(.text);
    14                 *(.rodata*);
     13                *(.text .text.*);
     14                *(.rodata .rodata.*);
    1515        } :text
    1616       
  • uspace/lib/c/arch/amd64/_link.ld.in

    r61257f4 rf8e8738  
    1616       
    1717        .text : {
    18                 *(.text);
    19                 *(.rodata*);
     18                *(.text .text.*);
     19                *(.rodata .rodata.*);
    2020        } :text
    2121       
  • uspace/lib/c/arch/arm32/_link.ld.in

    r61257f4 rf8e8738  
    1515       
    1616        .text : {
    17                 *(.text);
    18                 *(.rodata*);
     17                *(.text .text.*);
     18                *(.rodata .rodata.*);
    1919        } :text
    2020       
  • uspace/lib/c/arch/ia32/_link.ld.in

    r61257f4 rf8e8738  
    1616       
    1717        .text : {
    18                 *(.text);
    19                 *(.rodata*);
     18                *(.text .text.*);
     19                *(.rodata .rodata.*);
    2020        } :text
    2121       
  • uspace/lib/c/arch/ia64/_link.ld.in

    r61257f4 rf8e8738  
    1515       
    1616        .text : {
    17                 *(.text);
    18                 *(.rodata*);
     17                *(.text .text.*);
     18                *(.rodata .rodata.*);
    1919        } :text
    2020       
     
    2323        .got : {
    2424                _gp = .;
    25                 *(.got*);
     25                *(.got .got.*);
    2626        } :data
    2727       
  • uspace/lib/c/arch/mips32/_link.ld.in

    r61257f4 rf8e8738  
    1515       
    1616        .text : {
    17                 *(.text);
    18                 *(.rodata*);
     17                *(.text .text.*);
     18                *(.rodata .rodata.*);
    1919        } :text
    2020       
  • uspace/lib/c/arch/ppc32/_link.ld.in

    r61257f4 rf8e8738  
    1515       
    1616        .text : {
    17                 *(.text);
    18                 *(.rodata*);
     17                *(.text .text.*);
     18                *(.rodata .rodata.*);
    1919        } :text
    2020       
  • uspace/lib/c/arch/sparc64/_link.ld.in

    r61257f4 rf8e8738  
    1515       
    1616        .text : {
    17                 *(.text);
    18                 *(.rodata*);
     17                *(.text .text.*);
     18                *(.rodata .rodata.*);
    1919        } :text
    2020       
  • uspace/lib/c/generic/adt/hash_table.c

    r61257f4 rf8e8738  
    5454 *
    5555 */
    56 int hash_table_create(hash_table_t *h, hash_count_t m, hash_count_t max_keys,
     56bool hash_table_create(hash_table_t *h, hash_count_t m, hash_count_t max_keys,
    5757    hash_table_operations_t *op)
    5858{
  • uspace/lib/c/generic/devman.c

    r61257f4 rf8e8738  
    147147                ret = devman_send_match_id(phone, match_id);
    148148                if (ret != EOK) {
    149                         printf("Driver failed to send match id, error %d\n",
    150                             ret);
    151149                        return ret;
    152150                }
     
    195193        }
    196194       
    197         devman_send_match_ids(phone, match_ids);
    198        
    199         async_wait_for(req, &retval);
    200        
    201         async_serialize_end();
    202        
     195        int match_ids_rc = devman_send_match_ids(phone, match_ids);
     196       
     197        async_wait_for(req, &retval);
     198       
     199        async_serialize_end();
     200       
     201        /* Prefer the answer to DEVMAN_ADD_FUNCTION in case of errors. */
     202        if ((match_ids_rc != EOK) && (retval == EOK)) {
     203                retval = match_ids_rc;
     204        }
     205
    203206        if (retval == EOK)
    204207                fun_handle = (int) IPC_GET_ARG1(answer);
     
    326329}
    327330
     331int devman_device_get_handle_by_class(const char *classname,
     332    const char *devname, devman_handle_t *handle, unsigned int flags)
     333{
     334        int phone = devman_get_phone(DEVMAN_CLIENT, flags);
     335
     336        if (phone < 0)
     337                return phone;
     338
     339        async_serialize_start();
     340
     341        ipc_call_t answer;
     342        aid_t req = async_send_1(phone, DEVMAN_DEVICE_GET_HANDLE_BY_CLASS,
     343            flags, &answer);
     344
     345        sysarg_t retval = async_data_write_start(phone, classname,
     346            str_size(classname));
     347        if (retval != EOK) {
     348                async_wait_for(req, NULL);
     349                async_serialize_end();
     350                return retval;
     351        }
     352        retval = async_data_write_start(phone, devname,
     353            str_size(devname));
     354        if (retval != EOK) {
     355                async_wait_for(req, NULL);
     356                async_serialize_end();
     357                return retval;
     358        }
     359
     360        async_wait_for(req, &retval);
     361
     362        async_serialize_end();
     363
     364        if (retval != EOK) {
     365                if (handle != NULL)
     366                        *handle = (devman_handle_t) -1;
     367                return retval;
     368        }
     369
     370        if (handle != NULL)
     371                *handle = (devman_handle_t) IPC_GET_ARG1(answer);
     372
     373        return retval;
     374}
     375
    328376
    329377/** @}
  • uspace/lib/c/generic/net/packet.c

    r61257f4 rf8e8738  
    190190                }
    191191        }
    192         gpm_destroy(&pm_globals.packet_map);
     192        gpm_destroy(&pm_globals.packet_map, free);
    193193        /* leave locked */
    194194}
  • uspace/lib/c/generic/net/socket_client.c

    r61257f4 rf8e8738  
    749749        dyn_fifo_destroy(&socket->received);
    750750        dyn_fifo_destroy(&socket->accepted);
    751         sockets_exclude(socket_get_sockets(), socket->socket_id);
     751        sockets_exclude(socket_get_sockets(), socket->socket_id, free);
    752752}
    753753
  • uspace/lib/c/generic/vfs/vfs.c

    r61257f4 rf8e8738  
    756756{
    757757        struct stat stat;
    758         int rc;
    759 
    760         rc = fstat(fildes, &stat);
    761 
     758       
     759        int rc = fstat(fildes, &stat);
     760        if (rc != 0)
     761                return rc;
     762       
    762763        if (!stat.device)
    763764                return -1;
  • uspace/lib/c/include/adt/generic_char_map.h

    r61257f4 rf8e8738  
    4747#define GENERIC_CHAR_MAP_MAGIC_VALUE    0x12345622
    4848
     49/** Generic destructor function pointer. */
     50#define DTOR_T(identifier) \
     51        void (*identifier)(const void *)
     52
    4953/** Character string to generic type map declaration.
    5054 *  @param[in] name     Name of the map.
     
    6468        int name##_add(name##_t *, const uint8_t *, const size_t, type *); \
    6569        int name##_count(name##_t *); \
    66         void name##_destroy(name##_t *); \
    67         void name##_exclude(name##_t *, const uint8_t *, const size_t); \
     70        void name##_destroy(name##_t *, DTOR_T()); \
     71        void name##_exclude(name##_t *, const uint8_t *, const size_t, DTOR_T()); \
    6872        type *name##_find(name##_t *, const uint8_t *, const size_t); \
    6973        int name##_initialize(name##_t *); \
     
    8488             type *value) \
    8589        { \
    86                 int rc; \
    8790                int index; \
    8891                if (!name##_is_valid(map)) \
     
    9194                if (index < 0) \
    9295                        return index; \
    93                 rc = char_map_add(&map->names, name, length, index); \
    94                 if (rc != EOK) { \
    95                         name##_items_exclude_index(&map->values, index); \
    96                         return rc; \
    97                 } \
    98                 return EOK; \
     96                return char_map_add(&map->names, name, length, index); \
    9997        } \
    10098        \
     
    105103        } \
    106104        \
    107         void name##_destroy(name##_t *map) \
     105        void name##_destroy(name##_t *map, DTOR_T(dtor)) \
    108106        { \
    109107                if (name##_is_valid(map)) { \
    110108                        char_map_destroy(&map->names); \
    111                         name##_items_destroy(&map->values); \
     109                        name##_items_destroy(&map->values, dtor); \
    112110                } \
    113111        } \
    114112        \
    115113        void name##_exclude(name##_t *map, const uint8_t *name, \
    116             const size_t length) \
     114            const size_t length, DTOR_T(dtor)) \
    117115        { \
    118116                if (name##_is_valid(map)) { \
     
    121119                        if (index != CHAR_MAP_NULL) \
    122120                                name##_items_exclude_index(&map->values, \
    123                                      index); \
     121                                     index, dtor); \
    124122                } \
    125123        } \
  • uspace/lib/c/include/adt/generic_field.h

    r61257f4 rf8e8738  
    4646#define GENERIC_FIELD_MAGIC_VALUE               0x55667788
    4747
     48/** Generic destructor function pointer. */
     49#define DTOR_T(identifier) \
     50        void (*identifier)(const void *)
     51
    4852/** Generic type field declaration.
    4953 *
     
    6367        int name##_add(name##_t *, type *); \
    6468        int name##_count(name##_t *); \
    65         void name##_destroy(name##_t *); \
    66         void name##_exclude_index(name##_t *, int); \
     69        void name##_destroy(name##_t *, DTOR_T()); \
     70        void name##_exclude_index(name##_t *, int, DTOR_T()); \
    6771        type **name##_get_field(name##_t *); \
    6872        type *name##_get_index(name##_t *, int); \
     
    103107        } \
    104108        \
    105         void name##_destroy(name##_t *field) \
     109        void name##_destroy(name##_t *field, DTOR_T(dtor)) \
    106110        { \
    107111                if (name##_is_valid(field)) { \
    108112                        int index; \
    109113                        field->magic = 0; \
    110                         for (index = 0; index < field->next; index++) { \
    111                                 if (field->items[index]) \
    112                                         free(field->items[index]); \
     114                        if (dtor) { \
     115                                for (index = 0; index < field->next; index++) { \
     116                                        if (field->items[index]) \
     117                                                dtor(field->items[index]); \
     118                                } \
    113119                        } \
    114120                        free(field->items); \
     
    116122        } \
    117123         \
    118         void name##_exclude_index(name##_t *field, int index) \
     124        void name##_exclude_index(name##_t *field, int index, DTOR_T(dtor)) \
    119125        { \
    120126                if (name##_is_valid(field) && (index >= 0) && \
    121127                    (index < field->next) && (field->items[index])) { \
    122                         free(field->items[index]); \
     128                        if (dtor) \
     129                                dtor(field->items[index]); \
    123130                        field->items[index] = NULL; \
    124131                } \
  • uspace/lib/c/include/adt/hash_table.h

    r61257f4 rf8e8738  
    3838#include <adt/list.h>
    3939#include <unistd.h>
     40#include <bool.h>
    4041
    4142typedef unsigned long hash_count_t;
     
    8384    list_get_instance((item), type, member)
    8485
    85 extern int hash_table_create(hash_table_t *, hash_count_t, hash_count_t,
     86extern bool hash_table_create(hash_table_t *, hash_count_t, hash_count_t,
    8687    hash_table_operations_t *);
    8788extern void hash_table_insert(hash_table_t *, unsigned long [], link_t *);
  • uspace/lib/c/include/adt/int_map.h

    r61257f4 rf8e8738  
    4949#define INT_MAP_ITEM_MAGIC_VALUE        0x55667788
    5050
     51/** Generic destructor function pointer. */
     52#define DTOR_T(identifier) \
     53        void (*identifier)(const void *)
     54
    5155/** Integer to generic type map declaration.
    5256 *
     
    7276        \
    7377        int name##_add(name##_t *, int, type *); \
    74         void name##_clear(name##_t *); \
     78        void name##_clear(name##_t *, DTOR_T()); \
    7579        int name##_count(name##_t *); \
    76         void name##_destroy(name##_t *); \
    77         void name##_exclude(name##_t *, int); \
    78         void name##_exclude_index(name##_t *, int); \
     80        void name##_destroy(name##_t *, DTOR_T()); \
     81        void name##_exclude(name##_t *, int, DTOR_T()); \
     82        void name##_exclude_index(name##_t *, int, DTOR_T()); \
    7983        type *name##_find(name##_t *, int); \
    8084        int name##_update(name##_t *, int, int); \
     
    8286        int name##_initialize(name##_t *); \
    8387        int name##_is_valid(name##_t *); \
    84         void name##_item_destroy(name##_item_t *); \
     88        void name##_item_destroy(name##_item_t *, DTOR_T()); \
    8589        int name##_item_is_valid(name##_item_t *);
    8690
     
    115119        } \
    116120        \
    117         void name##_clear(name##_t *map) \
     121        void name##_clear(name##_t *map, DTOR_T(dtor)) \
    118122        { \
    119123                if (name##_is_valid(map)) { \
     
    122126                                if (name##_item_is_valid(&map->items[index])) { \
    123127                                        name##_item_destroy( \
    124                                             &map->items[index]); \
     128                                            &map->items[index], dtor); \
    125129                                } \
    126130                        } \
     
    135139        } \
    136140        \
    137         void name##_destroy(name##_t *map) \
     141        void name##_destroy(name##_t *map, DTOR_T(dtor)) \
    138142        { \
    139143                if (name##_is_valid(map)) { \
     
    143147                                if (name##_item_is_valid(&map->items[index])) { \
    144148                                        name##_item_destroy( \
    145                                             &map->items[index]); \
     149                                            &map->items[index], dtor); \
    146150                                } \
    147151                        } \
     
    150154        } \
    151155        \
    152         void name##_exclude(name##_t *map, int key) \
     156        void name##_exclude(name##_t *map, int key, DTOR_T(dtor)) \
    153157        { \
    154158                if (name##_is_valid(map)) { \
     
    158162                                    (map->items[index].key == key)) { \
    159163                                        name##_item_destroy( \
    160                                             &map->items[index]); \
    161                                 } \
    162                         } \
    163                 } \
    164         } \
    165         \
    166         void name##_exclude_index(name##_t *map, int index) \
     164                                            &map->items[index], dtor); \
     165                                } \
     166                        } \
     167                } \
     168        } \
     169        \
     170        void name##_exclude_index(name##_t *map, int index, DTOR_T(dtor)) \
    167171        { \
    168172                if (name##_is_valid(map) && (index >= 0) && \
    169173                    (index < map->next) && \
    170174                    name##_item_is_valid(&map->items[index])) { \
    171                         name##_item_destroy(&map->items[index]); \
     175                        name##_item_destroy(&map->items[index], dtor); \
    172176                } \
    173177        } \
     
    236240        } \
    237241        \
    238         void name##_item_destroy(name##_item_t *item) \
     242        void name##_item_destroy(name##_item_t *item, DTOR_T(dtor)) \
    239243        { \
    240244                if (name##_item_is_valid(item)) { \
    241245                        item->magic = 0; \
    242246                        if (item->value) { \
    243                                 free(item->value); \
     247                                if (dtor) \
     248                                        dtor(item->value); \
    244249                                item->value = NULL; \
    245250                        } \
  • uspace/lib/c/include/devman.h

    r61257f4 rf8e8738  
    5353extern int devman_device_get_handle(const char *, devman_handle_t *,
    5454    unsigned int);
     55extern int devman_device_get_handle_by_class(const char *, const char *,
     56    devman_handle_t *, unsigned int);
    5557
    5658extern int devman_add_device_to_class(devman_handle_t, const char *);
  • uspace/lib/c/include/io/log.h

    r61257f4 rf8e8738  
    11/*
    2  * Copyright (c) 2005 Sergey Bondari
     2 * Copyright (c) 2011 Vojtech Horky
     3 * Copyright (c) 2011 Jiri Svoboda
    34 * All rights reserved.
    45 *
     
    2728 */
    2829
    29 /** @addtogroup amd64
     30/** @addtogroup libc
    3031 * @{
    3132 */
    32 /** @file
    33  */
    3433
    35 #ifndef KERN_amd64_MEMSTR_H_
    36 #define KERN_amd64_MEMSTR_H_
     34#ifndef LIBC_IO_LOG_H_
     35#define LIBC_IO_LOG_H_
    3736
    38 #define memcpy(dst, src, cnt)  __builtin_memcpy((dst), (src), (cnt))
     37#include <stdarg.h>
    3938
    40 extern void memsetw(void *, size_t, uint16_t);
    41 extern void memsetb(void *, size_t, uint8_t);
     39typedef enum {
     40        LVL_FATAL,
     41        LVL_ERROR,
     42        LVL_WARN,
     43        LVL_NOTE,
     44        LVL_DEBUG,
     45        LVL_DEBUG2,
     46
     47        /** For checking range of values */
     48        LVL_LIMIT
     49} log_level_t;
     50
     51extern int log_init(const char *, log_level_t);
     52extern void log_msg(log_level_t, const char *, ...);
     53extern void log_msgv(log_level_t, const char *, va_list);
    4254
    4355#endif
  • uspace/lib/c/include/ipc/devman.h

    r61257f4 rf8e8738  
    148148
    149149typedef enum {
    150         DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD
     150        DEVMAN_DEVICE_GET_HANDLE = IPC_FIRST_USER_METHOD,
     151        DEVMAN_DEVICE_GET_HANDLE_BY_CLASS
    151152} client_to_devman_t;
    152153
  • uspace/lib/drv/Makefile

    r61257f4 rf8e8738  
    3636        generic/dev_iface.c \
    3737        generic/remote_char_dev.c \
     38        generic/log.c \
    3839        generic/remote_hw_res.c \
    3940        generic/remote_usb.c \
  • uspace/lib/drv/generic/driver.c

    r61257f4 rf8e8738  
    273273       
    274274        res = driver->driver_ops->add_device(dev);
    275         if (res == EOK) {
    276                 printf("%s: new device with handle=%" PRIun " was added.\n",
    277                     driver->name, dev_handle);
    278         } else {
    279                 printf("%s: failed to add a new device with handle = %" PRIun ".\n",
    280                     driver->name, dev_handle);
     275        if (res != EOK)
    281276                delete_device(dev);
    282         }
    283277       
    284278        async_answer_0(iid, res);
  • uspace/lib/drv/include/ddf/log.h

    r61257f4 rf8e8738  
    11/*
    2  * Copyright (c) 2005 Sergey Bondari
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup ia32
     29/** @addtogroup libdrv
    3030 * @{
    3131 */
    32 /** @file
    33  */
    3432
    35 #ifndef KERN_ia32_MEMSTR_H_
    36 #define KERN_ia32_MEMSTR_H_
     33#ifndef DDF_LOG_H_
     34#define DDF_LOG_H_
    3735
    38 #define memcpy(dst, src, cnt)  __builtin_memcpy((dst), (src), (cnt))
     36#include <io/log.h>
    3937
    40 extern void memsetw(void *, size_t, uint16_t);
    41 extern void memsetb(void *, size_t, uint8_t);
     38extern int ddf_log_init(const char *, log_level_t);
     39extern void ddf_msg(log_level_t, const char *, ...);
    4240
    4341#endif
  • uspace/lib/net/tl/socket_core.c

    r61257f4 rf8e8738  
    107107                socket_release(socket);
    108108
    109         socket_cores_exclude(local_sockets, socket->socket_id);
     109        socket_cores_exclude(local_sockets, socket->socket_id, free);
    110110}
    111111
     
    230230
    231231fail:
    232         socket_port_map_destroy(&socket_port->map);
     232        socket_port_map_destroy(&socket_port->map, free);
    233233        free(socket_port);
    234234        return rc;
     
    649649                        if (socket_port->count <= 0) {
    650650                                // destroy the map
    651                                 socket_port_map_destroy(&socket_port->map);
     651                                socket_port_map_destroy(&socket_port->map, free);
    652652                                // release the port
    653653                                socket_ports_exclude(global_sockets,
    654                                     socket->port);
     654                                    socket->port, free);
    655655                        } else {
    656656                                // remove
    657657                                socket_port_map_exclude(&socket_port->map,
    658                                     socket->key, socket->key_length);
     658                                    socket->key, socket->key_length, free);
    659659                        }
    660660                }
  • uspace/lib/net/tl/tl_common.c

    r61257f4 rf8e8738  
    182182                        else
    183183                                packet_dimensions_exclude(packet_dimensions,
    184                                     DEVICE_INVALID_ID);
     184                                    DEVICE_INVALID_ID, free);
    185185                }
    186186        }
  • uspace/lib/usb/Makefile

    r61257f4 rf8e8738  
    5353        src/hidreport.c \
    5454        src/host/device_keeper.c \
    55         src/host/batch.c
     55        src/host/batch.c \
     56        src/host/endpoint.c \
     57        src/host/usb_endpoint_manager.c
    5658
    5759include $(USPACE_PREFIX)/Makefile.common
  • uspace/lib/usb/include/usb/devdrv.h

    r61257f4 rf8e8738  
    4747} usb_device_descriptors_t;
    4848
     49/** Wrapper for data related to alternate interface setting.
     50 * The pointers will typically point inside configuration descriptor and
     51 * thus you shall not deallocate them.
     52 */
     53typedef struct {
     54        /** Interface descriptor. */
     55        usb_standard_interface_descriptor_t *interface;
     56        /** Pointer to start of descriptor tree bound with this interface. */
     57        uint8_t *nested_descriptors;
     58        /** Size of data pointed by nested_descriptors in bytes. */
     59        size_t nested_descriptors_size;
     60} usb_alternate_interface_descriptors_t;
     61
     62/** Alternate interface settings. */
     63typedef struct {
     64        /** Array of alternate interfaces descriptions. */
     65        usb_alternate_interface_descriptors_t *alternatives;
     66        /** Size of @c alternatives array. */
     67        size_t alternative_count;
     68        /** Index of currently selected one. */
     69        size_t current;
     70} usb_alternate_interfaces_t;
     71
    4972/** USB device structure. */
    5073typedef struct {
     
    5679         */
    5780        usb_endpoint_mapping_t *pipes;
     81        /** Number of other endpoint pipes. */
     82        size_t pipes_count;
    5883        /** Current interface.
    5984         * Usually, drivers operate on single interface only.
     
    6186         */
    6287        int interface_no;
     88
     89        /** Alternative interfaces.
     90         * Set to NULL when the driver controls whole device
     91         * (i.e. more (or any) interfaces).
     92         */
     93        usb_alternate_interfaces_t *alternate_interfaces;
    6394
    6495        /** Some useful descriptors. */
     
    92123         */
    93124        const char *name;
    94         /** Expected endpoints description, excluding default control endpoint.
     125        /** Expected endpoints description.
     126         * This description shall exclude default control endpoint (pipe zero)
     127         * and must be NULL terminated.
     128         * When only control endpoint is expected, you may set NULL directly
     129         * without creating one item array containing NULL.
    95130         *
    96          * It MUST be of size expected_enpoints_count(excluding default ctrl) + 1
    97          * where the last record MUST BE NULL, otherwise catastrophic things may
    98          * happen.
     131         * When the driver expect single interrupt in endpoint,
     132         * the initialization may look like this:
     133\code
     134static usb_endpoint_description_t poll_endpoint_description = {
     135        .transfer_type = USB_TRANSFER_INTERRUPT,
     136        .direction = USB_DIRECTION_IN,
     137        .interface_class = USB_CLASS_HUB,
     138        .interface_subclass = 0,
     139        .interface_protocol = 0,
     140        .flags = 0
     141};
     142
     143static usb_endpoint_description_t *hub_endpoints[] = {
     144        &poll_endpoint_description,
     145        NULL
     146};
     147
     148static usb_driver_t hub_driver = {
     149        .endpoints = hub_endpoints,
     150        ...
     151};
     152\endcode
    99153         */
    100154        usb_endpoint_description_t **endpoints;
     
    105159int usb_driver_main(usb_driver_t *);
    106160
     161int usb_device_select_interface(usb_device_t *, uint8_t,
     162    usb_endpoint_description_t **);
     163
    107164typedef bool (*usb_polling_callback_t)(usb_device_t *,
    108165    uint8_t *, size_t, void *);
    109166typedef void (*usb_polling_terminted_callback_t)(usb_device_t *, bool, void *);
    110 
    111167
    112168int usb_device_auto_poll(usb_device_t *, size_t,
  • uspace/lib/usb/include/usb/host/batch.h

    r61257f4 rf8e8738  
    3939#include <usbhc_iface.h>
    4040#include <usb/usb.h>
     41#include <usb/host/endpoint.h>
    4142
    4243typedef struct usb_transfer_batch usb_transfer_batch_t;
     
    6061        ddf_fun_t *fun;
    6162        void *arg;
     63        endpoint_t *ep;
    6264        void *private_data;
    6365};
     
    7880    void *arg,
    7981    ddf_fun_t *fun,
     82                endpoint_t *ep,
    8083    void *private_data
    8184);
  • uspace/lib/usb/include/usb/host/device_keeper.h

    r61257f4 rf8e8738  
    4040#ifndef LIBUSB_HOST_DEVICE_KEEPER_H
    4141#define LIBUSB_HOST_DEVICE_KEEPER_H
     42
     43#include <adt/list.h>
    4244#include <devman.h>
    4345#include <fibril_synch.h>
    4446#include <usb/usb.h>
     47#include <usb/host/endpoint.h>
    4548
    4649/** Number of USB address for array dimensions. */
     
    5154        usb_speed_t speed;
    5255        bool occupied;
    53         bool control_used;
    54         uint16_t toggle_status[2];
     56        link_t endpoints;
     57        uint16_t control_used;
    5558        devman_handle_t handle;
    5659};
     
    6871void usb_device_keeper_init(usb_device_keeper_t *instance);
    6972
    70 void usb_device_keeper_reserve_default_address(usb_device_keeper_t *instance,
    71     usb_speed_t speed);
     73void usb_device_keeper_add_ep(
     74    usb_device_keeper_t *instance, usb_address_t address, endpoint_t *ep);
     75
     76void usb_device_keeper_reserve_default_address(
     77    usb_device_keeper_t *instance, usb_speed_t speed);
    7278
    7379void usb_device_keeper_release_default_address(usb_device_keeper_t *instance);
    7480
    7581void usb_device_keeper_reset_if_need(usb_device_keeper_t *instance,
    76     usb_target_t target,
    77     const uint8_t *setup_data);
    78 
    79 int usb_device_keeper_get_toggle(usb_device_keeper_t *instance,
    80     usb_target_t target, usb_direction_t direction);
    81 
    82 int usb_device_keeper_set_toggle(usb_device_keeper_t *instance,
    83     usb_target_t target, usb_direction_t direction, bool toggle);
     82    usb_target_t target, const uint8_t *setup_data);
    8483
    8584usb_address_t device_keeper_get_free_address(usb_device_keeper_t *instance,
     
    9998
    10099void usb_device_keeper_use_control(usb_device_keeper_t *instance,
    101     usb_address_t address);
     100    usb_target_t target);
    102101
    103102void usb_device_keeper_release_control(usb_device_keeper_t *instance,
    104     usb_address_t address);
     103    usb_target_t target);
    105104
    106105#endif
  • uspace/lib/usb/include/usb/pipes.h

    r61257f4 rf8e8738  
    107107        /** Interface number the endpoint must belong to (-1 for any). */
    108108        int interface_no;
     109        /** Alternate interface setting to choose. */
     110        int interface_setting;
    109111        /** Found descriptor fitting the description. */
    110112        usb_standard_endpoint_descriptor_t *descriptor;
  • uspace/lib/usb/src/devdrv.c

    r61257f4 rf8e8738  
    3636#include <usb/request.h>
    3737#include <usb/debug.h>
     38#include <usb/dp.h>
    3839#include <errno.h>
    3940#include <str_error.h>
     
    8687 * @return Number of pipes (excluding default control pipe).
    8788 */
    88 static size_t count_other_pipes(usb_driver_t *drv)
     89static size_t count_other_pipes(usb_endpoint_description_t **endpoints)
    8990{
    9091        size_t count = 0;
    91         if (drv->endpoints == NULL) {
     92        if (endpoints == NULL) {
    9293                return 0;
    9394        }
    9495
    95         while (drv->endpoints[count] != NULL) {
     96        while (endpoints[count] != NULL) {
    9697                count++;
    9798        }
     
    106107 * @return Error code.
    107108 */
    108 static int initialize_other_pipes(usb_driver_t *drv, usb_device_t *dev)
     109static int initialize_other_pipes(usb_endpoint_description_t **endpoints,
     110    usb_device_t *dev)
    109111{
    110112        int rc;
    111         dev->interface_no = usb_device_get_assigned_interface(dev->ddf_dev);
    112 
    113         size_t pipe_count = count_other_pipes(drv);
     113
     114        size_t pipe_count = count_other_pipes(endpoints);
     115        if (pipe_count == 0) {
     116                return EOK;
     117        }
     118
    114119        dev->pipes = malloc(sizeof(usb_endpoint_mapping_t) * pipe_count);
    115120        if (dev->pipes == NULL) {
     
    133138                }
    134139
    135                 dev->pipes[i].description = drv->endpoints[i];
     140                dev->pipes[i].description = endpoints[i];
    136141                dev->pipes[i].interface_no = dev->interface_no;
     142                dev->pipes[i].interface_setting = 0;
    137143        }
    138144
     
    178184        usb_hc_connection_close(&hc_conn);
    179185
     186        dev->pipes_count = pipe_count;
     187
    180188        return EOK;
    181189
     
    227235        }
    228236
     237        /* Get our interface. */
     238        dev->interface_no = usb_device_get_assigned_interface(dev->ddf_dev);
     239
    229240        /*
    230241         * For further actions, we need open session on default control pipe.
     
    251262            &dev->descriptors.configuration_size);
    252263        if (rc != EOK) {
    253                 usb_log_error("Failed retrieving configuration descriptor: %s.\n",
     264                usb_log_error("Failed retrieving configuration descriptor: %s. %s\n",
    254265                    dev->ddf_dev->name, str_error(rc));
    255266                return rc;
     
    257268
    258269        if (driver->endpoints != NULL) {
    259                 rc = initialize_other_pipes(driver, dev);
     270                rc = initialize_other_pipes(driver->endpoints, dev);
    260271        }
    261272
     
    271282
    272283        return rc;
     284}
     285
     286/** Count number of alternate settings of a interface.
     287 *
     288 * @param config_descr Full configuration descriptor.
     289 * @param config_descr_size Size of @p config_descr in bytes.
     290 * @param interface_no Interface number.
     291 * @return Number of alternate interfaces for @p interface_no interface.
     292 */
     293static size_t count_alternate_interfaces(uint8_t *config_descr,
     294    size_t config_descr_size, int interface_no)
     295{
     296        assert(config_descr != NULL);
     297        usb_dp_parser_t dp_parser = {
     298                .nesting = usb_dp_standard_descriptor_nesting
     299        };
     300        usb_dp_parser_data_t dp_data = {
     301                .data = config_descr,
     302                .size = config_descr_size,
     303                .arg = NULL
     304        };
     305
     306        size_t alternate_count = 0;
     307
     308        uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,
     309            &dp_data, config_descr);
     310        while (iface_ptr != NULL) {
     311                usb_standard_interface_descriptor_t *iface
     312                    = (usb_standard_interface_descriptor_t *) iface_ptr;
     313                if (iface->descriptor_type == USB_DESCTYPE_INTERFACE) {
     314                        if (iface->interface_number == interface_no) {
     315                                alternate_count++;
     316                        }
     317                }
     318                iface_ptr = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data,
     319                    config_descr, iface_ptr);
     320        }
     321
     322        return alternate_count;
     323}
     324
     325/** Initialize structures related to alternate interfaces.
     326 *
     327 * @param dev Device where alternate settings shall be initialized.
     328 * @return Error code.
     329 */
     330static int initialize_alternate_interfaces(usb_device_t *dev)
     331{
     332        if (dev->interface_no < 0) {
     333                dev->alternate_interfaces = NULL;
     334                return EOK;
     335        }
     336
     337        usb_alternate_interfaces_t *alternates
     338            = malloc(sizeof(usb_alternate_interfaces_t));
     339
     340        if (alternates == NULL) {
     341                return ENOMEM;
     342        }
     343
     344        alternates->alternative_count
     345            = count_alternate_interfaces(dev->descriptors.configuration,
     346            dev->descriptors.configuration_size, dev->interface_no);
     347
     348        if (alternates->alternative_count == 0) {
     349                free(alternates);
     350                return ENOENT;
     351        }
     352
     353        alternates->alternatives = malloc(alternates->alternative_count
     354            * sizeof(usb_alternate_interface_descriptors_t));
     355        if (alternates->alternatives == NULL) {
     356                free(alternates);
     357                return ENOMEM;
     358        }
     359
     360        alternates->current = 0;
     361
     362        usb_dp_parser_t dp_parser = {
     363                .nesting = usb_dp_standard_descriptor_nesting
     364        };
     365        usb_dp_parser_data_t dp_data = {
     366                .data = dev->descriptors.configuration,
     367                .size = dev->descriptors.configuration_size,
     368                .arg = NULL
     369        };
     370
     371        usb_alternate_interface_descriptors_t *cur_alt_iface
     372            = &alternates->alternatives[0];
     373
     374        uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,
     375            &dp_data, dp_data.data);
     376        while (iface_ptr != NULL) {
     377                usb_standard_interface_descriptor_t *iface
     378                    = (usb_standard_interface_descriptor_t *) iface_ptr;
     379                if ((iface->descriptor_type != USB_DESCTYPE_INTERFACE)
     380                    || (iface->interface_number != dev->interface_no)) {
     381                        iface_ptr = usb_dp_get_sibling_descriptor(&dp_parser,
     382                            &dp_data,
     383                            dp_data.data, iface_ptr);
     384                        continue;
     385                }
     386
     387                cur_alt_iface->interface = iface;
     388                cur_alt_iface->nested_descriptors = iface_ptr + sizeof(*iface);
     389
     390                /* Find next interface to count size of nested descriptors. */
     391                iface_ptr = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data,
     392                    dp_data.data, iface_ptr);
     393                if (iface_ptr == NULL) {
     394                        uint8_t *next = dp_data.data + dp_data.size;
     395                        cur_alt_iface->nested_descriptors_size
     396                            = next - cur_alt_iface->nested_descriptors;
     397                } else {
     398                        cur_alt_iface->nested_descriptors_size
     399                            = iface_ptr - cur_alt_iface->nested_descriptors;
     400                }
     401
     402                cur_alt_iface++;
     403        }
     404
     405        dev->alternate_interfaces = alternates;
     406
     407        return EOK;
    273408}
    274409
     
    301436        dev->descriptors.configuration = NULL;
    302437
     438        dev->pipes_count = 0;
     439        dev->pipes = NULL;
     440
    303441        rc = initialize_pipes(dev);
    304442        if (rc != EOK) {
     
    307445        }
    308446
     447        (void) initialize_alternate_interfaces(dev);
     448
    309449        return driver->ops->add_device(dev);
     450}
     451
     452/** Destroy existing pipes of a USB device.
     453 *
     454 * @param dev Device where to destroy the pipes.
     455 * @return Error code.
     456 */
     457static int destroy_current_pipes(usb_device_t *dev)
     458{
     459        size_t i;
     460        int rc;
     461
     462        /* TODO: this shall be done under some device mutex. */
     463
     464        /* First check that no session is opened. */
     465        for (i = 0; i < dev->pipes_count; i++) {
     466                if (usb_pipe_is_session_started(dev->pipes[i].pipe)) {
     467                        return EBUSY;
     468                }
     469        }
     470
     471        /* Prepare connection to HC. */
     472        usb_hc_connection_t hc_conn;
     473        rc = usb_hc_connection_initialize_from_device(&hc_conn, dev->ddf_dev);
     474        if (rc != EOK) {
     475                return rc;
     476        }
     477        rc = usb_hc_connection_open(&hc_conn);
     478        if (rc != EOK) {
     479                return rc;
     480        }
     481
     482        /* Destroy the pipes. */
     483        for (i = 0; i < dev->pipes_count; i++) {
     484                usb_pipe_unregister(dev->pipes[i].pipe, &hc_conn);
     485                free(dev->pipes[i].pipe);
     486        }
     487
     488        usb_hc_connection_close(&hc_conn);
     489
     490        free(dev->pipes);
     491        dev->pipes = NULL;
     492        dev->pipes_count = 0;
     493
     494        return EOK;
     495}
     496
     497/** Change interface setting of a device.
     498 * This function selects new alternate setting of an interface by issuing
     499 * proper USB command to the device and also creates new USB pipes
     500 * under @c dev->pipes.
     501 *
     502 * @warning This function is intended for drivers working at interface level.
     503 * For drivers controlling the whole device, you need to change interface
     504 * manually using usb_request_set_interface() and creating new pipes
     505 * with usb_pipe_initialize_from_configuration().
     506 *
     507 * @param dev USB device.
     508 * @param alternate_setting Alternate setting to choose.
     509 * @param endpoints New endpoint descriptions.
     510 * @return Error code.
     511 */
     512int usb_device_select_interface(usb_device_t *dev, uint8_t alternate_setting,
     513    usb_endpoint_description_t **endpoints)
     514{
     515        if (dev->interface_no < 0) {
     516                return EINVAL;
     517        }
     518
     519        int rc;
     520
     521        /* TODO: more transactional behavior. */
     522
     523        /* Destroy existing pipes. */
     524        rc = destroy_current_pipes(dev);
     525        if (rc != EOK) {
     526                return rc;
     527        }
     528
     529        /* Change the interface itself. */
     530        rc = usb_request_set_interface(&dev->ctrl_pipe, dev->interface_no,
     531            alternate_setting);
     532        if (rc != EOK) {
     533                return rc;
     534        }
     535
     536        /* Create new pipes. */
     537        rc = initialize_other_pipes(endpoints, dev);
     538
     539        return rc;
    310540}
    311541
  • uspace/lib/usb/src/host/batch.c

    r61257f4 rf8e8738  
    5454    void *arg,
    5555    ddf_fun_t *fun,
     56                endpoint_t *ep,
    5657    void *private_data
    5758    )
     
    7778        instance->next_step = NULL;
    7879        instance->error = EOK;
    79 
     80        instance->ep = ep;
    8081}
    8182/*----------------------------------------------------------------------------*/
  • uspace/lib/usb/src/host/device_keeper.c

    r61257f4 rf8e8738  
    5454        for (; i < USB_ADDRESS_COUNT; ++i) {
    5555                instance->devices[i].occupied = false;
    56                 instance->devices[i].control_used = false;
     56                instance->devices[i].control_used = 0;
    5757                instance->devices[i].handle = 0;
    58                 instance->devices[i].toggle_status[0] = 0;
    59                 instance->devices[i].toggle_status[1] = 0;
    60         }
     58                list_initialize(&instance->devices[i].endpoints);
     59        }
     60}
     61/*----------------------------------------------------------------------------*/
     62void usb_device_keeper_add_ep(
     63    usb_device_keeper_t *instance, usb_address_t address, endpoint_t *ep)
     64{
     65        assert(instance);
     66        fibril_mutex_lock(&instance->guard);
     67        assert(instance->devices[address].occupied);
     68        list_append(&ep->same_device_eps, &instance->devices[address].endpoints);
     69        fibril_mutex_unlock(&instance->guard);
    6170}
    6271/*----------------------------------------------------------------------------*/
     
    6675 * @param[in] speed Speed of the device requesting default address.
    6776 */
    68 void usb_device_keeper_reserve_default_address(usb_device_keeper_t *instance,
    69     usb_speed_t speed)
     77void usb_device_keeper_reserve_default_address(
     78    usb_device_keeper_t *instance, usb_speed_t speed)
    7079{
    7180        assert(instance);
     
    101110 * Really ugly one.
    102111 */
    103 void usb_device_keeper_reset_if_need(usb_device_keeper_t *instance,
    104     usb_target_t target, const uint8_t *data)
     112void usb_device_keeper_reset_if_need(
     113    usb_device_keeper_t *instance, usb_target_t target, const uint8_t *data)
    105114{
    106115        assert(instance);
     
    119128                /* recipient is endpoint, value is zero (ENDPOINT_STALL) */
    120129                if (((data[0] & 0xf) == 1) && ((data[2] | data[3]) == 0)) {
     130                        link_t *current =
     131                            instance->devices[target.address].endpoints.next;
     132                        while (current !=
     133                           &instance->devices[target.address].endpoints)
     134                        {
    121135                        /* endpoint number is < 16, thus first byte is enough */
    122                         instance->devices[target.address].toggle_status[0] &=
    123                             ~(1 << data[4]);
    124                         instance->devices[target.address].toggle_status[1] &=
    125                             ~(1 << data[4]);
     136                                endpoint_toggle_reset_filtered(
     137                                    current, data[4]);
     138                                current = current->next;
     139                        }
    126140                }
    127141        break;
     
    131145                /* target must be device */
    132146                if ((data[0] & 0xf) == 0) {
    133                         instance->devices[target.address].toggle_status[0] = 0;
    134                         instance->devices[target.address].toggle_status[1] = 0;
     147                        link_t *current =
     148                            instance->devices[target.address].endpoints.next;
     149                        while (current !=
     150                           &instance->devices[target.address].endpoints)
     151                        {
     152                                endpoint_toggle_reset(current);
     153                                current = current->next;
     154                        }
    135155                }
    136156        break;
    137157        }
    138158        fibril_mutex_unlock(&instance->guard);
    139 }
    140 /*----------------------------------------------------------------------------*/
    141 /** Get current value of endpoint toggle.
    142  *
    143  * @param[in] instance Device keeper structure to use.
    144  * @param[in] target Device and endpoint used.
    145  * @return Error code
    146  */
    147 int usb_device_keeper_get_toggle(usb_device_keeper_t *instance,
    148     usb_target_t target, usb_direction_t direction)
    149 {
    150         assert(instance);
    151         /* only control pipes are bi-directional and those do not need toggle */
    152         if (direction == USB_DIRECTION_BOTH)
    153                 return ENOENT;
    154         int ret;
    155         fibril_mutex_lock(&instance->guard);
    156         if (target.endpoint > 15 || target.endpoint < 0
    157             || target.address >= USB_ADDRESS_COUNT || target.address < 0
    158             || !instance->devices[target.address].occupied) {
    159                 usb_log_error("Invalid data when asking for toggle value.\n");
    160                 ret = EINVAL;
    161         } else {
    162                 ret = (instance->devices[target.address].toggle_status[direction]
    163                         >> target.endpoint) & 1;
    164         }
    165         fibril_mutex_unlock(&instance->guard);
    166         return ret;
    167 }
    168 /*----------------------------------------------------------------------------*/
    169 /** Set current value of endpoint toggle.
    170  *
    171  * @param[in] instance Device keeper structure to use.
    172  * @param[in] target Device and endpoint used.
    173  * @param[in] toggle Toggle value.
    174  * @return Error code.
    175  */
    176 int usb_device_keeper_set_toggle(usb_device_keeper_t *instance,
    177     usb_target_t target, usb_direction_t direction, bool toggle)
    178 {
    179         assert(instance);
    180         /* only control pipes are bi-directional and those do not need toggle */
    181         if (direction == USB_DIRECTION_BOTH)
    182                 return ENOENT;
    183         int ret;
    184         fibril_mutex_lock(&instance->guard);
    185         if (target.endpoint > 15 || target.endpoint < 0
    186             || target.address >= USB_ADDRESS_COUNT || target.address < 0
    187             || !instance->devices[target.address].occupied) {
    188                 usb_log_error("Invalid data when setting toggle value.\n");
    189                 ret = EINVAL;
    190         } else {
    191                 if (toggle) {
    192                         instance->devices[target.address].toggle_status[direction]
    193                             |= (1 << target.endpoint);
    194                 } else {
    195                         instance->devices[target.address].toggle_status[direction]
    196                             &= ~(1 << target.endpoint);
    197                 }
    198                 ret = EOK;
    199         }
    200         fibril_mutex_unlock(&instance->guard);
    201         return ret;
    202159}
    203160/*----------------------------------------------------------------------------*/
     
    208165 * @return Free address, or error code.
    209166 */
    210 usb_address_t device_keeper_get_free_address(usb_device_keeper_t *instance,
    211     usb_speed_t speed)
     167usb_address_t device_keeper_get_free_address(
     168    usb_device_keeper_t *instance, usb_speed_t speed)
    212169{
    213170        assert(instance);
     
    229186        instance->devices[new_address].occupied = true;
    230187        instance->devices[new_address].speed = speed;
    231         instance->devices[new_address].toggle_status[0] = 0;
    232         instance->devices[new_address].toggle_status[1] = 0;
    233188        instance->last_address = new_address;
    234189        fibril_mutex_unlock(&instance->guard);
     
    259214 * @param[in] address Device address
    260215 */
    261 void usb_device_keeper_release(usb_device_keeper_t *instance,
    262     usb_address_t address)
     216void usb_device_keeper_release(
     217    usb_device_keeper_t *instance, usb_address_t address)
    263218{
    264219        assert(instance);
     
    278233 * @return USB Address, or error code.
    279234 */
    280 usb_address_t usb_device_keeper_find(usb_device_keeper_t *instance,
    281     devman_handle_t handle)
     235usb_address_t usb_device_keeper_find(
     236    usb_device_keeper_t *instance, devman_handle_t handle)
    282237{
    283238        assert(instance);
     
    301256 * @return USB speed.
    302257 */
    303 usb_speed_t usb_device_keeper_get_speed(usb_device_keeper_t *instance,
    304     usb_address_t address)
     258usb_speed_t usb_device_keeper_get_speed(
     259    usb_device_keeper_t *instance, usb_address_t address)
    305260{
    306261        assert(instance);
     
    310265}
    311266/*----------------------------------------------------------------------------*/
    312 void usb_device_keeper_use_control(usb_device_keeper_t *instance,
    313     usb_address_t address)
    314 {
    315         assert(instance);
    316         fibril_mutex_lock(&instance->guard);
    317         while (instance->devices[address].control_used) {
     267void usb_device_keeper_use_control(
     268    usb_device_keeper_t *instance, usb_target_t target)
     269{
     270        assert(instance);
     271        const uint16_t ep = 1 << target.endpoint;
     272        fibril_mutex_lock(&instance->guard);
     273        while (instance->devices[target.address].control_used & ep) {
    318274                fibril_condvar_wait(&instance->change, &instance->guard);
    319275        }
    320         instance->devices[address].control_used = true;
    321         fibril_mutex_unlock(&instance->guard);
    322 }
    323 /*----------------------------------------------------------------------------*/
    324 void usb_device_keeper_release_control(usb_device_keeper_t *instance,
    325     usb_address_t address)
    326 {
    327         assert(instance);
    328         fibril_mutex_lock(&instance->guard);
    329         instance->devices[address].control_used = false;
     276        instance->devices[target.address].control_used |= ep;
     277        fibril_mutex_unlock(&instance->guard);
     278}
     279/*----------------------------------------------------------------------------*/
     280void usb_device_keeper_release_control(
     281    usb_device_keeper_t *instance, usb_target_t target)
     282{
     283        assert(instance);
     284        const uint16_t ep = 1 << target.endpoint;
     285        fibril_mutex_lock(&instance->guard);
     286        assert((instance->devices[target.address].control_used & ep) != 0);
     287        instance->devices[target.address].control_used &= ~ep;
    330288        fibril_mutex_unlock(&instance->guard);
    331289        fibril_condvar_signal(&instance->change);
  • uspace/lib/usb/src/hub.c

    r61257f4 rf8e8738  
    142142            DEV_IFACE_ID(USBHC_DEV_IFACE),
    143143            IPC_M_USBHC_RELEASE_ADDRESS, address);
     144}
     145
     146static void unregister_control_endpoint_on_default_address(
     147    usb_hc_connection_t *connection)
     148{
     149        usb_device_connection_t dev_conn;
     150        int rc = usb_device_connection_initialize_on_default_address(&dev_conn,
     151            connection);
     152        if (rc != EOK) {
     153                return;
     154        }
     155
     156        usb_pipe_t ctrl_pipe;
     157        rc = usb_pipe_initialize_default_control(&ctrl_pipe, &dev_conn);
     158        if (rc != EOK) {
     159                return;
     160        }
     161
     162        usb_pipe_unregister(&ctrl_pipe, connection);
    144163}
    145164
     
    235254                goto leave_release_default_address;
    236255        }
     256
     257        /* Before sending any traffic, we need to register this
     258         * endpoint.
     259         */
     260        rc = usb_pipe_register(&ctrl_pipe, 0, connection);
     261        if (rc != EOK) {
     262                rc = EREFUSED;
     263                goto leave_release_default_address;
     264        }
    237265        rc = usb_pipe_probe_default_control(&ctrl_pipe);
    238266        if (rc != EOK) {
     
    244272        if (rc != EOK) {
    245273                rc = ENOTCONN;
    246                 goto leave_release_default_address;
     274                goto leave_unregister_endpoint;
    247275        }
    248276
     
    256284
    257285        /*
     286         * Register the control endpoint for the new device.
     287         */
     288        rc = usb_pipe_register(&ctrl_pipe, 0, connection);
     289        if (rc != EOK) {
     290                rc = EREFUSED;
     291                goto leave_unregister_endpoint;
     292        }
     293
     294        /*
     295         * Release the original endpoint.
     296         */
     297        unregister_control_endpoint_on_default_address(connection);
     298
     299        /*
    258300         * Once the address is changed, we can return the default address.
    259301         */
    260302        usb_hc_release_default_address(connection);
     303
    261304
    262305        /*
     
    273316        }
    274317
     318
     319
    275320        /*
    276321         * And now inform the host controller about the handle.
     
    308353        usb_pipe_end_session(&ctrl_pipe);
    309354
     355leave_unregister_endpoint:
     356        usb_pipe_unregister(&ctrl_pipe, connection);
     357
    310358leave_release_default_address:
    311359        usb_hc_release_default_address(connection);
  • uspace/lib/usb/src/pipesinit.c

    r61257f4 rf8e8738  
    121121    usb_endpoint_mapping_t *mapping, size_t mapping_count,
    122122    usb_endpoint_description_t *found_endpoint,
    123     int interface_number)
     123    int interface_number, int interface_setting)
    124124{
    125125        while (mapping_count > 0) {
     
    127127                    || (mapping->interface_no == interface_number);
    128128
     129                bool interface_setting_fits = (mapping->interface_setting < 0)
     130                    || (mapping->interface_setting == interface_setting);
     131
    129132                bool endpoint_descriptions_fits = endpoint_fits_description(
    130133                    mapping->description, found_endpoint);
    131134
    132                 if (interface_number_fits && endpoint_descriptions_fits) {
     135                if (interface_number_fits
     136                    && interface_setting_fits
     137                    && endpoint_descriptions_fits) {
    133138                        return mapping;
    134139                }
     
    181186         */
    182187        usb_endpoint_mapping_t *ep_mapping = find_endpoint_mapping(mapping,
    183             mapping_count, &description, interface->interface_number);
     188            mapping_count, &description,
     189            interface->interface_number, interface->alternate_setting);
    184190        if (ep_mapping == NULL) {
    185191                return ENOENT;
  • uspace/lib/usb/src/request.c

    r61257f4 rf8e8738  
    529529                return rc;
    530530        }
    531 
    532531        if (bare_config.descriptor_type != USB_DESCTYPE_CONFIGURATION) {
    533532                return ENOENT;
Note: See TracChangeset for help on using the changeset viewer.