Changes in / [e3f7418:3958e315] in mainline


Ignore:
Location:
uspace
Files:
38 edited

Legend:

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

    re3f7418 r3958e315  
    5050
    5151static void browse_descriptor_tree_internal(usb_dp_parser_t *parser,
    52     usb_dp_parser_data_t *data, const uint8_t *root, size_t depth,
     52    usb_dp_parser_data_t *data, uint8_t *root, size_t depth,
    5353    dump_descriptor_in_tree_t callback, void *arg)
    5454{
     
    5757        }
    5858        callback(root, depth, arg);
    59         const uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
     59        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

    re3f7418 r3958e315  
    110110}
    111111
    112 static void dump_tree_descriptor(const uint8_t *descriptor, size_t depth)
     112static void dump_tree_descriptor(uint8_t *descriptor, size_t depth)
    113113{
    114114        if (descriptor == NULL) {
    115115                return;
    116116        }
    117         int type = descriptor[1];
     117        int type = (int) *(descriptor + 1);
    118118        const char *name = "unknown";
    119119        switch (type) {
     
    136136}
    137137
    138 static void dump_tree_internal(
    139     usb_dp_parser_t *parser, usb_dp_parser_data_t *data,
    140     const uint8_t *root, size_t depth)
     138static void dump_tree_internal(usb_dp_parser_t *parser, usb_dp_parser_data_t *data,
     139    uint8_t *root, size_t depth)
    141140{
    142141        if (root == NULL) {
     
    144143        }
    145144        dump_tree_descriptor(root, depth);
    146         const uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
     145        uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
    147146        do {
    148147                dump_tree_internal(parser, data, child, depth + 1);
     
    153152static void dump_tree(usb_dp_parser_t *parser, usb_dp_parser_data_t *data)
    154153{
    155         const uint8_t *ptr = data->data;
     154        uint8_t *ptr = data->data;
    156155        printf("Descriptor tree:\n");
    157156        dump_tree_internal(parser, data, ptr, 0);
  • uspace/app/usbinfo/hid.c

    re3f7418 r3958e315  
    5555} descriptor_walk_context_t;
    5656
    57 static bool is_descriptor_kind(const uint8_t *d, usb_descriptor_type_t t)
     57static bool is_descriptor_kind(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(const uint8_t *raw_descriptor,
     182static void descriptor_walk_callback(uint8_t *raw_descriptor,
    183183    size_t depth, void *arg)
    184184{
  • uspace/app/usbinfo/info.c

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

    re3f7418 r3958e315  
    7474void destroy_device(usbinfo_device_t *);
    7575
    76 typedef void (*dump_descriptor_in_tree_t)(const uint8_t *, size_t, void *);
     76typedef void (*dump_descriptor_in_tree_t)(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/usbflbk/main.c

    re3f7418 r3958e315  
    6464        }
    6565
    66         dev->driver_data = ctl_fun;
    67 
    6866        usb_log_info("Pretending to control %s `%s'" \
    6967            " (node `%s', handle %" PRIun ").\n",
     
    7472}
    7573
    76 /** Callback when new device is removed and recognized as gone by DDF.
    77  *
    78  * @param dev Representation of a generic DDF device.
    79  * @return Error code.
    80  */
    81 static int usbfallback_device_gone(usb_device_t *dev)
    82 {
    83         assert(dev);
    84         ddf_fun_t *ctl_fun = dev->driver_data;
    85         const int ret = ddf_fun_unbind(ctl_fun);
    86         if (ret != EOK) {
    87                 usb_log_error("Failed to unbind %s.\n", ctl_fun->name);
    88                 return ret;
    89         }
    90         ddf_fun_destroy(ctl_fun);
    91         dev->driver_data = NULL;
    92 
    93         return EOK;
    94 }
    9574/** USB fallback driver ops. */
    9675static usb_driver_ops_t usbfallback_driver_ops = {
    9776        .device_add = usbfallback_device_add,
    98         .device_gone = usbfallback_device_gone,
    9977};
    10078
  • uspace/drv/bus/usb/usbhid/generic/hiddev.c

    re3f7418 r3958e315  
    5252        .direction = USB_DIRECTION_IN,
    5353        .interface_class = USB_CLASS_HID,
    54         .interface_subclass = -1,
    55         .interface_protocol = -1,
    5654        .flags = 0
    5755};
     
    9492        usb_log_debug2("Generic HID: Get event length (fun: %p, "
    9593            "fun->driver_data: %p.\n", fun, fun->driver_data);
    96 
     94       
    9795        if (fun == NULL || fun->driver_data == NULL) {
    9896                return 0;
     
    10098
    10199        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
    102 
     100       
    103101        usb_log_debug2("hid_dev: %p, Max input report size (%zu).\n",
    104102            hid_dev, hid_dev->max_input_report_size);
    105 
     103       
    106104        return hid_dev->max_input_report_size;
    107105}
     
    113111{
    114112        usb_log_debug2("Generic HID: Get event.\n");
    115 
     113       
    116114        if (fun == NULL || fun->driver_data == NULL || buffer == NULL
    117115            || act_size == NULL || event_nr == NULL) {
     
    121119
    122120        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
    123 
     121       
    124122        if (hid_dev->input_report_size > size) {
    125123                usb_log_debug("input_report_size > size (%zu, %zu)\n",
     
    127125                return EINVAL;  // TODO: other error code
    128126        }
    129 
     127       
    130128        /*! @todo This should probably be somehow atomic. */
    131129        memcpy(buffer, hid_dev->input_report,
     
    133131        *act_size = hid_dev->input_report_size;
    134132        *event_nr = usb_hid_report_number(hid_dev);
    135 
     133       
    136134        usb_log_debug2("OK\n");
    137 
     135       
    138136        return EOK;
    139137}
     
    144142{
    145143        usb_log_debug("Generic HID: Get report descriptor length.\n");
    146 
     144       
    147145        if (fun == NULL || fun->driver_data == NULL) {
    148146                usb_log_debug("No function");
    149147                return EINVAL;
    150148        }
    151 
    152         usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
    153 
     149       
     150        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
     151       
    154152        usb_log_debug2("hid_dev->report_desc_size = %zu\n",
    155153            hid_dev->report_desc_size);
    156 
     154       
    157155        return hid_dev->report_desc_size;
    158156}
     
    164162{
    165163        usb_log_debug2("Generic HID: Get report descriptor.\n");
    166 
     164       
    167165        if (fun == NULL || fun->driver_data == NULL) {
    168166                usb_log_debug("No function");
    169167                return EINVAL;
    170168        }
    171 
    172         usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
    173 
     169       
     170        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
     171       
    174172        if (hid_dev->report_desc_size > size) {
    175173                return EINVAL;
    176174        }
    177 
     175       
    178176        memcpy(desc, hid_dev->report_desc, hid_dev->report_desc_size);
    179177        *actual_size = hid_dev->report_desc_size;
    180 
     178       
    181179        return EOK;
    182180}
     
    192190/*----------------------------------------------------------------------------*/
    193191
    194 void usb_generic_hid_deinit(usb_hid_dev_t *hid_dev, void *data)
    195 {
    196         ddf_fun_t *fun = data;
    197         const int ret = ddf_fun_unbind(fun);
    198         if (ret != EOK) {
    199                 usb_log_error("Failed to unbind generic hid fun.\n");
    200                 return;
    201         }
    202         usb_log_debug2("%s unbound.\n", fun->name);
    203         /* We did not allocate this, so leave this alone
    204          * the device would take care of it */
    205         fun->driver_data = NULL;
    206         ddf_fun_destroy(fun);
    207 }
    208 
    209 /*----------------------------------------------------------------------------*/
    210 
    211 int usb_generic_hid_init(usb_hid_dev_t *hid_dev, void **data)
    212 {
    213         if (hid_dev == NULL) {
    214                 return EINVAL;
    215         }
    216 
     192static int usb_generic_hid_create_function(usb_hid_dev_t *hid_dev)
     193{       
    217194        /* Create the exposed function. */
    218195        /** @todo Generate numbers for the devices? */
     
    224201                return ENOMEM;
    225202        }
    226 
     203       
    227204        fun->ops = &usb_generic_hid_ops;
     205        fun->driver_data = hid_dev;
    228206
    229207        int rc = ddf_fun_bind(fun);
     
    234212                return rc;
    235213        }
    236         /* This is nasty both device and this function have the same
    237          * driver data, thus destruction would lead to double free */
    238         fun->driver_data = hid_dev;
    239 
     214       
    240215        usb_log_debug("HID function created. Handle: %" PRIun "\n", fun->handle);
    241         *data = fun;
    242 
    243         return EOK;
     216       
     217        return EOK;
     218}
     219
     220/*----------------------------------------------------------------------------*/
     221
     222int usb_generic_hid_init(usb_hid_dev_t *hid_dev, void **data)
     223{
     224        if (hid_dev == NULL) {
     225                return EINVAL;
     226        }
     227       
     228        return usb_generic_hid_create_function(hid_dev);
    244229}
    245230
  • uspace/drv/bus/usb/usbhid/generic/hiddev.h

    re3f7418 r3958e315  
    5050int usb_generic_hid_init(struct usb_hid_dev *hid_dev, void **data);
    5151
    52 void usb_generic_hid_deinit(struct usb_hid_dev *hid_dev, void *data);
    53 
    5452bool usb_generic_hid_polling_callback(struct usb_hid_dev *hid_dev, void *data);
    5553
  • uspace/drv/bus/usb/usbhid/kbd/conv.c

    re3f7418 r3958e315  
    8787        [0x26] = KC_9,
    8888        [0x27] = KC_0,
    89 
     89       
    9090        [0x28] = KC_ENTER,
    9191        [0x29] = KC_ESCAPE,
     
    109109
    110110        [0x39] = KC_CAPS_LOCK,
    111 
     111       
    112112        [0x3a] = KC_F1,
    113113        [0x3b] = KC_F2,
     
    122122        [0x44] = KC_F11,
    123123        [0x45] = KC_F12,
    124 
     124       
    125125        [0x46] = KC_PRTSCR,
    126126        [0x47] = KC_SCROLL_LOCK,
     
    136136        [0x51] = KC_DOWN,
    137137        [0x52] = KC_UP,
    138 
     138       
    139139        //[0x64] = // some funny key
    140 
     140       
    141141        [0xe0] = KC_LCTRL,
    142142        [0xe1] = KC_LSHIFT,
     
    147147        [0xe6] = KC_RALT,
    148148        //[0xe7] = KC_R // TODO: right GUI
    149 
     149       
    150150        [0x53] = KC_NUM_LOCK,
    151151        [0x54] = KC_NSLASH,
     
    165165        [0x62] = KC_N0,
    166166        [0x63] = KC_NPERIOD
    167 
     167       
    168168};
    169169
     
    186186
    187187        key = map[scancode];
    188 
     188       
    189189        return key;
    190190}
  • uspace/drv/bus/usb/usbhid/kbd/kbddev.c

    re3f7418 r3958e315  
    174174{
    175175        sysarg_t method = IPC_GET_IMETHOD(*icall);
    176 
     176       
    177177        usb_kbd_t *kbd_dev = (usb_kbd_t *) fun->driver_data;
    178178        if (kbd_dev == NULL) {
     
    182182                return;
    183183        }
    184 
     184       
    185185        async_sess_t *sess =
    186186            async_callback_receive_start(EXCHANGE_SERIALIZE, icall);
     
    240240            USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    241241            USB_HID_REPORT_TYPE_OUTPUT);
    242 
     242       
    243243        while (field != NULL) {
    244244               
     
    263263                        USB_HID_REPORT_TYPE_OUTPUT);
    264264        }
    265 
     265       
    266266        // TODO: what about the Report ID?
    267267        int rc = usb_hid_report_output_translate(hid_dev->report, 0,
    268268            kbd_dev->output_buffer, kbd_dev->output_size);
    269 
     269       
    270270        if (rc != EOK) {
    271271                usb_log_warning("Error translating LED output to output report"
     
    273273                return;
    274274        }
    275 
     275       
    276276        usb_log_debug("Output report buffer: %s\n",
    277277            usb_debug_str_buffer(kbd_dev->output_buffer, kbd_dev->output_size,
    278278                0));
    279 
     279       
    280280        usbhid_req_set_report(&hid_dev->usb_dev->ctrl_pipe,
    281281            hid_dev->usb_dev->interface_no, USB_HID_REPORT_TYPE_OUTPUT,
     
    300300                return;
    301301        }
    302 
     302       
    303303        async_exch_t *exch = async_exchange_begin(kbd_dev->console_sess);
    304304        async_msg_2(exch, KBDEV_EVENT, type, key);
     
    347347        unsigned int key;
    348348        size_t i;
    349 
     349       
    350350        /*
    351351         * First of all, check if the kbd have reported phantom state.
     
    362362                return;
    363363        }
    364 
     364       
    365365        /*
    366366         * Key releases
     
    382382                }
    383383        }
    384 
     384       
    385385        /*
    386386         * Key presses
     
    402402                }
    403403        }
    404 
     404       
    405405        memcpy(kbd_dev->keys_old, kbd_dev->keys, kbd_dev->key_count * 4);
    406 
     406       
    407407        char key_buffer[512];
    408408        ddf_dump_buffer(key_buffer, 512,
     
    435435        assert(hid_dev != NULL);
    436436        assert(kbd_dev != NULL);
    437 
     437       
    438438        usb_hid_report_path_t *path = usb_hid_report_path();
    439439        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
    440440
    441441        usb_hid_report_path_set_report_id (path, hid_dev->report_id);
    442 
     442       
    443443        // fill in the currently pressed keys
    444 
     444       
    445445        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    446446            hid_dev->report, NULL, path,
     
    448448            USB_HID_REPORT_TYPE_INPUT);
    449449        unsigned i = 0;
    450 
     450       
    451451        while (field != NULL) {
    452452                usb_log_debug2("FIELD (%p) - VALUE(%d) USAGE(%u)\n",
     
    470470                    USB_HID_REPORT_TYPE_INPUT);
    471471        }
    472 
     472       
    473473        usb_hid_report_path_free(path);
    474 
     474       
    475475        usb_kbd_check_key_changes(hid_dev, kbd_dev);
    476476}
     
    502502
    503503        if (kbd_dev == NULL) {
    504                 usb_log_error("No memory!\n");
     504                usb_log_fatal("No memory!\n");
    505505                return NULL;
    506506        }
    507 
     507       
    508508        kbd_dev->console_sess = NULL;
    509509        kbd_dev->initialized = USB_KBD_STATUS_UNINITIALIZED;
    510 
     510       
    511511        return kbd_dev;
    512512}
     
    514514/*----------------------------------------------------------------------------*/
    515515
    516 static int usb_kbd_create_function(usb_kbd_t *kbd_dev)
    517 {
     516static int usb_kbd_create_function(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev)
     517{
     518        assert(hid_dev != NULL);
     519        assert(hid_dev->usb_dev != NULL);
    518520        assert(kbd_dev != NULL);
    519         assert(kbd_dev->hid_dev != NULL);
    520         assert(kbd_dev->hid_dev->usb_dev != NULL);
    521 
     521       
    522522        /* Create the exposed function. */
    523523        usb_log_debug("Creating DDF function %s...\n", HID_KBD_FUN_NAME);
    524         ddf_fun_t *fun = ddf_fun_create(kbd_dev->hid_dev->usb_dev->ddf_dev,
    525             fun_exposed, HID_KBD_FUN_NAME);
     524        ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
     525            HID_KBD_FUN_NAME);
    526526        if (fun == NULL) {
    527527                usb_log_error("Could not create DDF function node.\n");
    528528                return ENOMEM;
    529529        }
    530 
     530       
    531531        /*
    532532         * Store the initialized HID device and HID ops
     
    540540                usb_log_error("Could not bind DDF function: %s.\n",
    541541                    str_error(rc));
    542                 fun->driver_data = NULL; /* We need this later */
    543542                ddf_fun_destroy(fun);
    544543                return rc;
    545544        }
    546 
     545       
    547546        usb_log_debug("%s function created. Handle: %" PRIun "\n",
    548547            HID_KBD_FUN_NAME, fun->handle);
    549 
     548       
    550549        usb_log_debug("Adding DDF function to category %s...\n",
    551550            HID_KBD_CLASS_NAME);
     
    555554                    "Could not add DDF function to category %s: %s.\n",
    556555                    HID_KBD_CLASS_NAME, str_error(rc));
    557                 fun->driver_data = NULL; /* We need this later */
    558556                ddf_fun_destroy(fun);
    559557                return rc;
    560558        }
    561         kbd_dev->fun = fun;
    562 
     559       
    563560        return EOK;
    564561}
     
    590587{
    591588        usb_log_debug("Initializing HID/KBD structure...\n");
    592 
     589       
    593590        if (hid_dev == NULL) {
    594591                usb_log_error("Failed to init keyboard structure: no structure"
     
    596593                return EINVAL;
    597594        }
    598 
     595       
    599596        usb_kbd_t *kbd_dev = usb_kbd_new();
    600597        if (kbd_dev == NULL) {
     
    606603        /* Store link to HID device */
    607604        kbd_dev->hid_dev = hid_dev;
    608 
     605       
    609606        /*
    610607         * TODO: make more general
     
    612609        usb_hid_report_path_t *path = usb_hid_report_path();
    613610        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_KEYBOARD, 0);
    614 
     611       
    615612        usb_hid_report_path_set_report_id(path, 0);
    616 
     613       
    617614        kbd_dev->key_count = usb_hid_report_size(
    618615            hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT);
    619616        usb_hid_report_path_free(path);
    620 
     617       
    621618        usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
    622 
     619       
    623620        kbd_dev->keys = (int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t));
    624 
     621       
    625622        if (kbd_dev->keys == NULL) {
    626                 usb_log_error("No memory!\n");
     623                usb_log_fatal("No memory!\n");
    627624                free(kbd_dev);
    628625                return ENOMEM;
    629626        }
    630 
     627       
    631628        kbd_dev->keys_old =
    632629                (int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t));
    633 
     630       
    634631        if (kbd_dev->keys_old == NULL) {
    635                 usb_log_error("No memory!\n");
     632                usb_log_fatal("No memory!\n");
    636633                free(kbd_dev->keys);
    637634                free(kbd_dev);
    638635                return ENOMEM;
    639636        }
    640 
     637       
    641638        /*
    642639         * Output report
     
    650647                return ENOMEM;
    651648        }
    652 
     649       
    653650        usb_log_debug("Output buffer size: %zu\n", kbd_dev->output_size);
    654 
     651       
    655652        kbd_dev->led_path = usb_hid_report_path();
    656653        usb_hid_report_path_append_item(
    657654            kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0);
    658 
     655       
    659656        kbd_dev->led_output_size = usb_hid_report_size(hid_dev->report,
    660657            0, USB_HID_REPORT_TYPE_OUTPUT);
    661 
     658       
    662659        usb_log_debug("Output report size (in items): %zu\n",
    663660            kbd_dev->led_output_size);
    664 
     661       
    665662        kbd_dev->led_data = (int32_t *)calloc(
    666663            kbd_dev->led_output_size, sizeof(int32_t));
    667 
     664       
    668665        if (kbd_dev->led_data == NULL) {
    669666                usb_log_warning("Error creating buffer for LED output report."
     
    674671                return ENOMEM;
    675672        }
    676 
     673       
    677674        /*
    678675         * Modifiers and locks
     
    681678        kbd_dev->mods = DEFAULT_ACTIVE_MODS;
    682679        kbd_dev->lock_keys = 0;
    683 
     680       
    684681        /*
    685682         * Autorepeat
     
    689686        kbd_dev->repeat.delay_before = DEFAULT_DELAY_BEFORE_FIRST_REPEAT;
    690687        kbd_dev->repeat.delay_between = DEFAULT_REPEAT_DELAY;
    691 
    692         fibril_mutex_initialize(&kbd_dev->repeat_mtx);
    693 
     688       
     689        kbd_dev->repeat_mtx = (fibril_mutex_t *)(
     690            malloc(sizeof(fibril_mutex_t)));
     691        if (kbd_dev->repeat_mtx == NULL) {
     692                usb_log_fatal("No memory!\n");
     693                free(kbd_dev->keys);
     694                usb_hid_report_output_free(kbd_dev->output_buffer);
     695                free(kbd_dev);
     696                return ENOMEM;
     697        }
     698       
     699        fibril_mutex_initialize(kbd_dev->repeat_mtx);
     700       
    694701        // save the KBD device structure into the HID device structure
    695702        *data = kbd_dev;
    696 
     703       
    697704        // set handler for incoming calls
    698705        kbd_dev->ops.default_handler = default_connection_handler;
    699 
     706       
    700707        /*
    701708         * Set LEDs according to initial setup.
     
    703710         */
    704711        usb_kbd_set_led(hid_dev, kbd_dev);
    705 
     712       
    706713        usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe,
    707714            hid_dev->usb_dev->interface_no, IDLE_RATE);
    708 
     715       
    709716        /*
    710717         * Create new fibril for auto-repeat
     
    716723        }
    717724        fibril_add_ready(fid);
    718 
     725       
    719726        kbd_dev->initialized = USB_KBD_STATUS_INITIALIZED;
    720727        usb_log_debug("HID/KBD device structure initialized.\n");
    721 
     728       
    722729        usb_log_debug("Creating KBD function...\n");
    723         int rc = usb_kbd_create_function(kbd_dev);
     730        int rc = usb_kbd_create_function(hid_dev, kbd_dev);
    724731        if (rc != EOK) {
    725732                usb_kbd_destroy(kbd_dev);
    726733                return rc;
    727734        }
    728 
     735       
    729736        return EOK;
    730737}
     
    738745                return false;
    739746        }
    740 
     747       
    741748        usb_kbd_t *kbd_dev = (usb_kbd_t *)data;
    742749        assert(kbd_dev != NULL);
    743 
     750       
    744751        // TODO: add return value from this function
    745752        usb_kbd_process_data(hid_dev, kbd_dev);
    746 
     753       
    747754        return true;
    748755}
     
    773780                return;
    774781        }
    775 
     782       
    776783        // hangup session to the console
    777784        async_hangup(kbd_dev->console_sess);
    778 
    779         //assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx));
    780         // FIXME - the fibril_mutex_is_locked may not cause
    781         // fibril scheduling
    782         while (fibril_mutex_is_locked(&kbd_dev->repeat_mtx)) {}
    783 
     785       
     786        if (kbd_dev->repeat_mtx != NULL) {
     787                //assert(!fibril_mutex_is_locked((*kbd_dev)->repeat_mtx));
     788                // FIXME - the fibril_mutex_is_locked may not cause
     789                // fibril scheduling
     790                while (fibril_mutex_is_locked(kbd_dev->repeat_mtx)) {}
     791                free(kbd_dev->repeat_mtx);
     792        }
     793       
    784794        // free all buffers
    785         free(kbd_dev->keys);
    786         free(kbd_dev->keys_old);
    787         free(kbd_dev->led_data);
    788 
     795        if (kbd_dev->keys != NULL) {
     796                free(kbd_dev->keys);
     797        }
     798        if (kbd_dev->keys_old != NULL) {
     799                free(kbd_dev->keys_old);
     800        }
     801        if (kbd_dev->led_data != NULL) {
     802                free(kbd_dev->led_data);
     803        }
    789804        if (kbd_dev->led_path != NULL) {
    790805                usb_hid_report_path_free(kbd_dev->led_path);
     
    793808                usb_hid_report_output_free(kbd_dev->output_buffer);
    794809        }
    795 
    796         if (ddf_fun_unbind(kbd_dev->fun) != EOK) {
    797                 usb_log_warning("Failed to unbind kbd function.\n");
    798         } else {
    799                 usb_log_debug2("%s unbound.\n", kbd_dev->fun->name);
    800                 kbd_dev->fun->driver_data = NULL;
    801                 ddf_fun_destroy(kbd_dev->fun);
    802         }
    803810}
    804811
     
    810817                return;
    811818        }
    812 
     819       
    813820        if (data != NULL) {
    814                 usb_kbd_t *kbd_dev = data;
     821                usb_kbd_t *kbd_dev = (usb_kbd_t *)data;
    815822                if (usb_kbd_is_initialized(kbd_dev)) {
    816823                        usb_kbd_mark_unusable(kbd_dev);
    817                         /* wait for autorepeat */
    818                         async_usleep(CHECK_DELAY);
     824                } else {
    819825                        usb_kbd_destroy(kbd_dev);
    820826                }
     
    829835            USB_KBD_BOOT_REPORT_DESCRIPTOR,
    830836            USB_KBD_BOOT_REPORT_DESCRIPTOR_SIZE);
    831 
     837       
    832838        if (rc != EOK) {
    833839                usb_log_error("Failed to parse boot report descriptor: %s\n",
     
    835841                return rc;
    836842        }
    837 
     843       
    838844        rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe,
    839845            hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT);
    840 
     846       
    841847        if (rc != EOK) {
    842848                usb_log_warning("Failed to set boot protocol to the device: "
     
    844850                return rc;
    845851        }
    846 
     852       
    847853        return EOK;
    848854}
  • uspace/drv/bus/usb/usbhid/kbd/kbddev.h

    re3f7418 r3958e315  
    7575        /** Currently pressed modifiers (bitmap). */
    7676        uint8_t modifiers;
    77 
     77       
    7878        /** Currently active modifiers including locks. Sent to the console. */
    7979        unsigned mods;
    80 
     80       
    8181        /** Currently active lock keys. */
    8282        unsigned lock_keys;
    83 
     83       
    8484        /** IPC session to the console device (for sending key events). */
    8585        async_sess_t *console_sess;
    86 
     86       
    8787        /** @todo What is this actually? */
    8888        ddf_dev_ops_t ops;
    89 
     89       
    9090        /** Information for auto-repeat of keys. */
    9191        usb_kbd_repeat_t repeat;
    92 
     92       
    9393        /** Mutex for accessing the information about auto-repeat. */
    94         fibril_mutex_t repeat_mtx;
    95 
     94        fibril_mutex_t *repeat_mtx;
     95       
    9696        uint8_t *output_buffer;
    97 
     97       
    9898        size_t output_size;
    99 
     99       
    100100        size_t led_output_size;
    101 
     101       
    102102        usb_hid_report_path_t *led_path;
    103 
     103       
    104104        int32_t *led_data;
    105 
     105       
    106106        /** State of the structure (for checking before use).
    107107         *
     
    111111         */
    112112        int initialized;
    113 
    114         /** DDF function */
    115         ddf_fun_t *fun;
    116113} usb_kbd_t;
    117114
  • uspace/drv/bus/usb/usbhid/kbd/kbdrepeat.c

    re3f7418 r3958e315  
    4646
    4747
     48/** Delay between auto-repeat state checks when no key is being repeated. */
     49static unsigned int CHECK_DELAY = 10000;
    4850
    4951/*----------------------------------------------------------------------------*/
     
    7173{
    7274        unsigned int delay = 0;
    73 
     75       
    7476        usb_log_debug("Starting autorepeat loop.\n");
    7577
     
    7779                // check if the kbd structure is usable
    7880                if (!usb_kbd_is_initialized(kbd)) {
    79                         usb_log_warning("kbd not ready, exiting autorepeat.\n");
     81                        if (usb_kbd_is_ready_to_destroy(kbd)) {
     82                                usb_kbd_destroy(kbd);
     83                        }
    8084                        return;
    8185                }
    8286               
    83                 fibril_mutex_lock(&kbd->repeat_mtx);
     87                fibril_mutex_lock(kbd->repeat_mtx);
    8488
    8589                if (kbd->repeat.key_new > 0) {
     
    105109                        delay = CHECK_DELAY;
    106110                }
    107                 fibril_mutex_unlock(&kbd->repeat_mtx);
     111                fibril_mutex_unlock(kbd->repeat_mtx);
    108112               
    109113                async_usleep(delay);
     
    126130{
    127131        usb_log_debug("Autorepeat fibril spawned.\n");
    128 
     132       
    129133        if (arg == NULL) {
    130134                usb_log_error("No device!\n");
    131135                return EINVAL;
    132136        }
    133 
     137       
    134138        usb_kbd_t *kbd = (usb_kbd_t *)arg;
    135 
     139       
    136140        usb_kbd_repeat_loop(kbd);
    137 
     141       
    138142        return EOK;
    139143}
     
    152156void usb_kbd_repeat_start(usb_kbd_t *kbd, unsigned int key)
    153157{
    154         fibril_mutex_lock(&kbd->repeat_mtx);
     158        fibril_mutex_lock(kbd->repeat_mtx);
    155159        kbd->repeat.key_new = key;
    156         fibril_mutex_unlock(&kbd->repeat_mtx);
     160        fibril_mutex_unlock(kbd->repeat_mtx);
    157161}
    158162
     
    170174void usb_kbd_repeat_stop(usb_kbd_t *kbd, unsigned int key)
    171175{
    172         fibril_mutex_lock(&kbd->repeat_mtx);
     176        fibril_mutex_lock(kbd->repeat_mtx);
    173177        if (key == kbd->repeat.key_new) {
    174178                kbd->repeat.key_new = 0;
    175179        }
    176         fibril_mutex_unlock(&kbd->repeat_mtx);
     180        fibril_mutex_unlock(kbd->repeat_mtx);
    177181}
    178182
  • uspace/drv/bus/usb/usbhid/kbd/kbdrepeat.h

    re3f7418 r3958e315  
    3737#define USB_HID_KBDREPEAT_H_
    3838
    39 /** Delay between auto-repeat state checks when no key is being repeated. */
    40 #define CHECK_DELAY 10000
    41 
    4239struct usb_kbd_t;
    4340
  • uspace/drv/bus/usb/usbhid/main.c

    re3f7418 r3958e315  
    7676{
    7777        assert(dev != NULL);
    78 
    79         /* Initialize device (get and process descriptors, get address, etc.) */
     78       
     79        /*
     80         * Initialize device (get and process descriptors, get address, etc.)
     81         */
    8082        usb_log_debug("Initializing USB/HID device...\n");
    81 
    82         usb_hid_dev_t *hid_dev =
    83             usb_device_data_alloc(dev, sizeof(usb_hid_dev_t));
     83       
     84        usb_hid_dev_t *hid_dev = usb_hid_new();
    8485        if (hid_dev == NULL) {
    8586                usb_log_error("Error while creating USB/HID device "
     
    8788                return ENOMEM;
    8889        }
    89 
     90       
    9091        int rc = usb_hid_init(hid_dev, dev);
    91 
     92       
    9293        if (rc != EOK) {
    9394                usb_log_error("Failed to initialize USB/HID device.\n");
    9495                usb_hid_destroy(hid_dev);
    9596                return rc;
    96         }
    97 
     97        }       
     98       
    9899        usb_log_debug("USB/HID device structure initialized.\n");
    99 
     100       
    100101        /*
    101102         * 1) subdriver vytvori vlastnu ddf_fun, vlastne ddf_dev_ops, ktore da
     
    108109         *    pouzit usb/classes/hid/iface.h - prvy int je telefon
    109110         */
    110 
     111       
    111112        /* Start automated polling function.
    112113         * This will create a separate fibril that will query the device
     
    124125           /* Custom argument. */
    125126           hid_dev);
    126 
     127       
     128       
    127129        if (rc != EOK) {
    128130                usb_log_error("Failed to start polling fibril for `%s'.\n",
    129131                    dev->ddf_dev->name);
    130                 usb_hid_destroy(hid_dev);
    131132                return rc;
    132133        }
    133         hid_dev->running = true;
    134         dev->driver_data = hid_dev;
    135134
    136135        /*
     
    154153{
    155154        usb_log_debug("usb_hid_device_add()\n");
    156 
     155       
    157156        if (dev == NULL) {
    158157                usb_log_warning("Wrong parameter given for add_device().\n");
    159158                return EINVAL;
    160159        }
    161 
     160       
    162161        if (dev->interface_no < 0) {
    163162                usb_log_warning("Device is not a supported HID device.\n");
     
    166165                return ENOTSUP;
    167166        }
    168 
     167       
    169168        int rc = usb_hid_try_add_device(dev);
    170 
     169       
    171170        if (rc != EOK) {
    172171                usb_log_warning("Device is not a supported HID device.\n");
     
    175174                return rc;
    176175        }
    177 
     176       
    178177        usb_log_info("HID device `%s' ready to use.\n", dev->ddf_dev->name);
    179178
     
    183182/*----------------------------------------------------------------------------*/
    184183
    185 /**
    186  * Callback for removing a device from the driver.
    187  *
    188  * @param dev Structure representing the device.
    189  *
    190  * @retval EOK if successful.
    191  * @retval EREFUSED if the device is not supported.
    192  */
    193 static int usb_hid_device_gone(usb_device_t *dev)
    194 {
    195         usb_hid_dev_t *hid_dev = dev->driver_data;
    196         unsigned tries = 10;
    197         while (hid_dev->running) {
    198                 async_usleep(100000);
    199                 if (!tries--) {
    200                         usb_log_error("Can't remove hub, still running.\n");
    201                         return EINPROGRESS;
    202                 }
    203         }
    204 
    205         assert(!hid_dev->running);
    206         usb_hid_destroy(hid_dev);
    207         usb_log_debug2("%s destruction complete.\n", dev->ddf_dev->name);
    208         return EOK;
    209 }
    210 
    211 /** USB generic driver callbacks */
     184/* Currently, the framework supports only device adding. Once the framework
     185 * supports unplug, more callbacks will be added. */
    212186static usb_driver_ops_t usb_hid_driver_ops = {
    213         .device_add = usb_hid_device_add,
    214         .device_gone = usb_hid_device_gone,
     187        .device_add = usb_hid_device_add,
    215188};
    216189
    217190
    218 /** The driver itself. */
     191/* The driver itself. */
    219192static usb_driver_t usb_hid_driver = {
    220193        .name = NAME,
  • uspace/drv/bus/usb/usbhid/mouse/mousedev.c

    re3f7418 r3958e315  
    124124{
    125125        usb_mouse_t *mouse_dev = (usb_mouse_t *) fun->driver_data;
    126 
     126       
    127127        if (mouse_dev == NULL) {
    128128                usb_log_debug("default_connection_handler: Missing "
     
    131131                return;
    132132        }
    133 
     133       
    134134        usb_log_debug("default_connection_handler: fun->name: %s\n",
    135135                      fun->name);
    136136        usb_log_debug("default_connection_handler: mouse_sess: %p, "
    137137            "wheel_sess: %p\n", mouse_dev->mouse_sess, mouse_dev->wheel_sess);
    138 
     138       
    139139        async_sess_t **sess_ptr =
    140140            (str_cmp(fun->name, HID_MOUSE_FUN_NAME) == 0) ?
    141141            &mouse_dev->mouse_sess : &mouse_dev->wheel_sess;
    142 
     142       
    143143        async_sess_t *sess =
    144144            async_callback_receive_start(EXCHANGE_SERIALIZE, icall);
     
    170170        mouse->mouse_sess = NULL;
    171171        mouse->wheel_sess = NULL;
    172 
     172       
    173173        return mouse;
    174174}
     
    179179{
    180180        assert(mouse_dev != NULL);
    181 
     181       
    182182        // hangup session to the console
    183183        if (mouse_dev->mouse_sess != NULL)
    184184                async_hangup(mouse_dev->mouse_sess);
    185 
     185       
    186186        if (mouse_dev->wheel_sess != NULL)
    187187                async_hangup(mouse_dev->wheel_sess);
    188         int ret = ddf_fun_unbind(mouse_dev->mouse_fun);
    189         if (ret != EOK) {
    190                 usb_log_error("Failed to unbind mouse function.\n");
    191         } else {
    192                 ddf_fun_destroy(mouse_dev->mouse_fun);
    193                 /* Prevent double free */
    194                 mouse_dev->wheel_fun->driver_data = NULL;
    195         }
    196 
    197         ret = ddf_fun_unbind(mouse_dev->wheel_fun);
    198         if (ret != EOK) {
    199                 usb_log_error("Failed to unbind wheel function.\n");
    200         } else {
    201                 ddf_fun_destroy(mouse_dev->wheel_fun);
    202         }
    203188}
    204189
     
    214199                return;
    215200        }
    216 
     201       
    217202        int count = ((wheel < 0) ? -wheel : wheel) * ARROWS_PER_SINGLE_WHEEL;
    218203        int i;
    219 
     204       
    220205        for (i = 0; i < count; i++) {
    221206                /* Send arrow press and release. */
     
    261246{
    262247        assert(mouse_dev != NULL);
    263 
     248       
    264249        if (mouse_dev->mouse_sess == NULL) {
    265250                usb_log_warning(NAME " No console session.\n");
     
    279264                async_exchange_end(exch);
    280265        }
    281 
     266       
    282267        if (wheel != 0)
    283268                usb_mouse_send_wheel(mouse_dev, wheel);
    284 
     269       
    285270        /*
    286271         * Buttons
     
    289274        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0);
    290275        usb_hid_report_path_set_report_id(path, hid_dev->report_id);
    291 
     276       
    292277        usb_hid_report_field_t *field = usb_hid_report_get_sibling(
    293278            hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END
     
    324309                    USB_HID_REPORT_TYPE_INPUT);
    325310        }
    326 
     311       
    327312        usb_hid_report_path_free(path);
    328313
     
    336321        assert(hid_dev != NULL);
    337322        assert(mouse != NULL);
    338 
     323       
    339324        /* Create the exposed function. */
    340325        usb_log_debug("Creating DDF function %s...\n", HID_MOUSE_FUN_NAME);
     
    345330                return ENOMEM;
    346331        }
    347 
     332       
    348333        fun->ops = &mouse->ops;
    349334        fun->driver_data = mouse;
     
    353338                usb_log_error("Could not bind DDF function: %s.\n",
    354339                    str_error(rc));
    355                 return rc;
    356         }
    357 
     340                ddf_fun_destroy(fun);
     341                return rc;
     342        }
     343       
    358344        usb_log_debug("Adding DDF function to category %s...\n",
    359345            HID_MOUSE_CATEGORY);
     
    363349                    "Could not add DDF function to category %s: %s.\n",
    364350                    HID_MOUSE_CATEGORY, str_error(rc));
    365                 return rc;
    366         }
    367         mouse->mouse_fun = fun;
    368 
     351                ddf_fun_destroy(fun);
     352                return rc;
     353        }
     354       
    369355        /*
    370356         * Special function for acting as keyboard (wheel)
     
    378364                return ENOMEM;
    379365        }
    380 
     366       
    381367        /*
    382368         * Store the initialized HID device and HID ops
     
    390376                usb_log_error("Could not bind DDF function: %s.\n",
    391377                    str_error(rc));
    392                 return rc;
    393         }
    394 
     378                ddf_fun_destroy(fun);
     379                return rc;
     380        }
     381       
    395382        usb_log_debug("Adding DDF function to category %s...\n",
    396383            HID_MOUSE_WHEEL_CATEGORY);
     
    400387                    "Could not add DDF function to category %s: %s.\n",
    401388                    HID_MOUSE_WHEEL_CATEGORY, str_error(rc));
    402                 return rc;
    403         }
    404         mouse->wheel_fun = fun;
    405 
     389                ddf_fun_destroy(fun);
     390                return rc;
     391        }
     392       
    406393        return EOK;
    407394}
     
    454441{
    455442        usb_log_debug("Initializing HID/Mouse structure...\n");
    456 
     443       
    457444        if (hid_dev == NULL) {
    458445                usb_log_error("Failed to init keyboard structure: no structure"
     
    460447                return EINVAL;
    461448        }
    462 
     449       
    463450        usb_mouse_t *mouse_dev = usb_mouse_new();
    464451        if (mouse_dev == NULL) {
     
    467454                return ENOMEM;
    468455        }
    469 
     456       
    470457        // FIXME: This may not be optimal since stupid hardware vendor may
    471458        // use buttons 1, 2, 3 and 6000 and we would allocate array of
     
    477464            hid_dev->report_id) + 1;
    478465        mouse_dev->buttons = calloc(mouse_dev->buttons_count, sizeof(int32_t));
    479 
     466       
    480467        if (mouse_dev->buttons == NULL) {
    481468                usb_log_error(NAME ": out of memory, giving up on device!\n");
     
    487474        // save the Mouse device structure into the HID device structure
    488475        *data = mouse_dev;
    489 
     476       
    490477        // set handler for incoming calls
    491478        mouse_dev->ops.default_handler = default_connection_handler;
    492 
     479       
    493480        // TODO: how to know if the device supports the request???
    494481        usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe,
    495482            hid_dev->usb_dev->interface_no, IDLE_RATE);
    496 
     483       
    497484        int rc = usb_mouse_create_function(hid_dev, mouse_dev);
    498485        if (rc != EOK) {
     
    500487                return rc;
    501488        }
    502 
     489       
    503490        return EOK;
    504491}
     
    513500                return false;
    514501        }
    515 
     502       
    516503        usb_mouse_t *mouse_dev = (usb_mouse_t *)data;
    517504               
     
    524511{
    525512        if (data != NULL) {
    526                 usb_mouse_destroy(data);
     513                usb_mouse_destroy((usb_mouse_t *)data);
    527514        }
    528515}
     
    535522            USB_MOUSE_BOOT_REPORT_DESCRIPTOR,
    536523            USB_MOUSE_BOOT_REPORT_DESCRIPTOR_SIZE);
    537 
     524       
    538525        if (rc != EOK) {
    539526                usb_log_error("Failed to parse boot report descriptor: %s\n",
     
    541528                return rc;
    542529        }
    543 
     530       
    544531        rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe,
    545532            hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT);
    546 
     533       
    547534        if (rc != EOK) {
    548535                usb_log_warning("Failed to set boot protocol to the device: "
     
    550537                return rc;
    551538        }
    552 
     539       
    553540        return EOK;
    554541}
  • uspace/drv/bus/usb/usbhid/mouse/mousedev.h

    re3f7418 r3958e315  
    4949        async_sess_t *mouse_sess;
    5050        async_sess_t *wheel_sess;
    51 
     51       
    5252        /* Mouse buttons statuses. */
    5353        int32_t *buttons;
    5454        size_t buttons_count;
    55 
     55       
    5656        ddf_dev_ops_t ops;
    57         /* DDF mouse function */
    58         ddf_fun_t *mouse_fun;
    59         /* DDF mouse function */
    60         ddf_fun_t *wheel_fun;
    6157} usb_mouse_t;
    6258
  • uspace/drv/bus/usb/usbhid/multimedia/multimedia.c

    re3f7418 r3958e315  
    6464        //int32_t *keys;
    6565        /** Count of stored keys (i.e. number of keys in the report). */
    66         //size_t key_count;
     66        //size_t key_count;     
    6767        /** IPC session to the console device (for sending key events). */
    6868        async_sess_t *console_sess;
    69         /** DDF function */
    70         ddf_fun_t *fun;
    7169} usb_multimedia_t;
    7270
     
    8886{
    8987        usb_log_debug(NAME " default_connection_handler()\n");
    90 
     88       
    9189        usb_multimedia_t *multim_dev = (usb_multimedia_t *)fun->driver_data;
    92 
     90       
    9391        if (multim_dev == NULL) {
    9492                async_answer_0(icallid, EINVAL);
    9593                return;
    9694        }
    97 
     95       
    9896        async_sess_t *sess =
    9997            async_callback_receive_start(EXCHANGE_SERIALIZE, icall);
     
    139137        assert(hid_dev != NULL);
    140138        assert(multim_dev != NULL);
    141 
     139       
    142140        kbd_event_t ev;
    143 
     141       
    144142        ev.type = type;
    145143        ev.key = key;
     
    153151                return;
    154152        }
    155 
     153       
    156154        async_exch_t *exch = async_exchange_begin(multim_dev->console_sess);
    157155        async_msg_4(exch, KBDEV_EVENT, ev.type, ev.key, ev.mods, ev.c);
     
    171169                return ENOMEM;
    172170        }
    173 
     171       
    174172        fun->ops = &multimedia_ops;
    175173        fun->driver_data = multim_dev;   // TODO: maybe change to hid_dev->data
    176 
     174       
    177175        int rc = ddf_fun_bind(fun);
    178176        if (rc != EOK) {
    179177                usb_log_error("Could not bind DDF function: %s.\n",
    180178                    str_error(rc));
     179                // TODO: Can / should I destroy the DDF function?
    181180                ddf_fun_destroy(fun);
    182181                return rc;
    183182        }
    184 
     183       
    185184        usb_log_debug("%s function created (handle: %" PRIun ").\n",
    186185            NAME, fun->handle);
    187 
     186       
    188187        rc = ddf_fun_add_to_category(fun, "keyboard");
    189188        if (rc != EOK) {
     
    191190                    "Could not add DDF function to category 'keyboard': %s.\n",
    192191                    str_error(rc));
     192                // TODO: Can / should I destroy the DDF function?
    193193                ddf_fun_destroy(fun);
    194194                return rc;
    195195        }
    196         multim_dev->fun = fun;
    197 
     196       
    198197        return EOK;
    199198}
     
    206205                return EINVAL; /*! @todo Other return code? */
    207206        }
    208 
     207       
    209208        usb_log_debug(NAME " Initializing HID/multimedia structure...\n");
    210 
     209       
    211210        usb_multimedia_t *multim_dev = (usb_multimedia_t *)malloc(
    212211            sizeof(usb_multimedia_t));
     
    214213                return ENOMEM;
    215214        }
    216 
     215       
    217216        multim_dev->console_sess = NULL;
    218 
     217       
    219218        /*! @todo Autorepeat */
    220 
     219       
    221220        // save the KBD device structure into the HID device structure
    222221        *data = multim_dev;
    223 
     222       
    224223        usb_log_debug(NAME " HID/multimedia device structure initialized.\n");
    225 
     224       
    226225        int rc = usb_multimedia_create_function(hid_dev, multim_dev);
    227226        if (rc != EOK)
    228227                return rc;
    229 
     228       
    230229        usb_log_debug(NAME " HID/multimedia structure initialized.\n");
    231 
     230       
    232231        return EOK;
    233232}
     
    240239                return;
    241240        }
    242 
     241       
    243242        if (data != NULL) {
    244243                usb_multimedia_t *multim_dev = (usb_multimedia_t *)data;
    245244                // hangup session to the console
    246245                async_hangup(multim_dev->console_sess);
    247                 const int ret = ddf_fun_unbind(multim_dev->fun);
    248                 if (ret != EOK) {
    249                         usb_log_error("Failed to unbind multim function.\n");
    250                 } else {
    251                         usb_log_debug2("%s unbound.\n", multim_dev->fun->name);
    252                         ddf_fun_destroy(multim_dev->fun);
    253                 }
    254246        }
    255247}
     
    265257
    266258        usb_multimedia_t *multim_dev = (usb_multimedia_t *)data;
    267 
     259       
    268260        usb_hid_report_path_t *path = usb_hid_report_path();
    269261        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0);
     
    291283                                               key);
    292284                }
    293 
     285               
    294286                field = usb_hid_report_get_sibling(
    295287                    hid_dev->report, field, path, USB_HID_PATH_COMPARE_END
    296288                    | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    297289                    USB_HID_REPORT_TYPE_INPUT);
    298         }
     290        }       
    299291
    300292        usb_hid_report_path_free(path);
    301 
     293       
    302294        return true;
    303295}
  • uspace/drv/bus/usb/usbhid/subdrivers.h

    re3f7418 r3958e315  
    6464         */
    6565        const usb_hid_subdriver_usage_t *usage_path;
    66 
     66       
    6767        /** Report ID for which the path should apply. */
    6868        int report_id;
    69 
     69       
    7070        /** Compare type for the Usage path. */
    7171        int compare;
    72 
     72       
    7373        /** Vendor ID (set to -1 if not specified). */
    7474        int vendor_id;
    75 
     75       
    7676        /** Product ID (set to -1 if not specified). */
    7777        int product_id;
    78 
     78       
    7979        /** Subdriver for controlling this device. */
    8080        usb_hid_subdriver_t subdriver;
  • uspace/drv/bus/usb/usbhid/usbhid.c

    re3f7418 r3958e315  
    5454
    5555/* Array of endpoints expected on the device, NULL terminated. */
    56 usb_endpoint_description_t *usb_hid_endpoints[] = {
     56usb_endpoint_description_t *usb_hid_endpoints[USB_HID_POLL_EP_COUNT + 1] = {
    5757        &usb_hid_kbd_poll_endpoint_description,
    5858        &usb_hid_mouse_poll_endpoint_description,
     
    6868{
    6969        assert(hid_dev != NULL && hid_dev->subdriver_count == 0);
    70 
     70       
    7171        hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(
    7272            sizeof(usb_hid_subdriver_t));
     
    7474                return ENOMEM;
    7575        }
    76 
     76       
    7777        assert(hid_dev->subdriver_count >= 0);
    78 
     78       
    7979        // set the init callback
    8080        hid_dev->subdrivers[hid_dev->subdriver_count].init = usb_kbd_init;
    81 
     81       
    8282        // set the polling callback
    8383        hid_dev->subdrivers[hid_dev->subdriver_count].poll =
    8484            usb_kbd_polling_callback;
    85 
     85       
    8686        // set the polling ended callback
    8787        hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL;
    88 
     88       
    8989        // set the deinit callback
    9090        hid_dev->subdrivers[hid_dev->subdriver_count].deinit = usb_kbd_deinit;
    91 
     91       
    9292        // set subdriver count
    9393        ++hid_dev->subdriver_count;
    94 
     94       
    9595        return EOK;
    9696}
     
    101101{
    102102        assert(hid_dev != NULL && hid_dev->subdriver_count == 0);
    103 
     103       
    104104        hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(
    105105            sizeof(usb_hid_subdriver_t));
     
    107107                return ENOMEM;
    108108        }
    109 
     109       
    110110        assert(hid_dev->subdriver_count >= 0);
    111 
     111       
    112112        // set the init callback
    113113        hid_dev->subdrivers[hid_dev->subdriver_count].init = usb_mouse_init;
    114 
     114       
    115115        // set the polling callback
    116116        hid_dev->subdrivers[hid_dev->subdriver_count].poll =
    117117            usb_mouse_polling_callback;
    118 
     118       
    119119        // set the polling ended callback
    120120        hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL;
    121 
     121       
    122122        // set the deinit callback
    123123        hid_dev->subdrivers[hid_dev->subdriver_count].deinit = usb_mouse_deinit;
    124 
     124       
    125125        // set subdriver count
    126126        ++hid_dev->subdriver_count;
    127 
     127       
    128128        return EOK;
    129129}
     
    134134{
    135135        assert(hid_dev != NULL && hid_dev->subdriver_count == 0);
    136 
     136       
    137137        hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(
    138138            sizeof(usb_hid_subdriver_t));
     
    140140                return ENOMEM;
    141141        }
    142 
     142       
    143143        assert(hid_dev->subdriver_count >= 0);
    144 
     144       
    145145        // set the init callback
    146146        hid_dev->subdrivers[hid_dev->subdriver_count].init =
    147147            usb_generic_hid_init;
    148 
     148       
    149149        // set the polling callback
    150150        hid_dev->subdrivers[hid_dev->subdriver_count].poll =
    151151            usb_generic_hid_polling_callback;
    152 
     152       
    153153        // set the polling ended callback
    154154        hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL;
    155 
     155       
    156156        // set the deinit callback
    157         hid_dev->subdrivers[hid_dev->subdriver_count].deinit =
    158             usb_generic_hid_deinit;
    159 
     157        hid_dev->subdrivers[hid_dev->subdriver_count].deinit = NULL;
     158       
    160159        // set subdriver count
    161160        ++hid_dev->subdriver_count;
    162 
     161       
    163162        return EOK;
    164163}
     
    171170        assert(hid_dev != NULL);
    172171        assert(hid_dev->usb_dev != NULL);
    173 
     172       
    174173        return (hid_dev->usb_dev->descriptors.device.vendor_id
    175174            == mapping->vendor_id
     
    185184        assert(hid_dev != NULL);
    186185        assert(mapping != NULL);
    187 
     186       
    188187        usb_hid_report_path_t *usage_path = usb_hid_report_path();
    189188        if (usage_path == NULL) {
     
    203202                ++i;
    204203        }
    205 
     204       
    206205        assert(hid_dev->report != NULL);
    207 
     206       
    208207        usb_log_debug("Compare flags: %d\n", mapping->compare);
    209 
     208       
    210209        bool matches = false;
    211210        uint8_t report_id = mapping->report_id;
     
    235234                    USB_HID_REPORT_TYPE_INPUT);
    236235        } while (!matches && report_id != 0);
    237 
     236       
    238237        usb_hid_report_path_free(usage_path);
    239 
     238       
    240239        return matches;
    241240}
     
    247246{
    248247        int i;
    249 
     248       
    250249        if (count <= 0) {
    251250                hid_dev->subdriver_count = 0;
     
    253252                return EOK;
    254253        }
    255 
     254       
    256255        // add one generic HID subdriver per device
    257 
     256       
    258257        hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc((count + 1) *
    259258            sizeof(usb_hid_subdriver_t));
     
    261260                return ENOMEM;
    262261        }
    263 
     262       
    264263        for (i = 0; i < count; ++i) {
    265264                hid_dev->subdrivers[i].init = subdrivers[i]->init;
     
    268267                hid_dev->subdrivers[i].poll_end = subdrivers[i]->poll_end;
    269268        }
    270 
     269       
    271270        hid_dev->subdrivers[count].init = usb_generic_hid_init;
    272271        hid_dev->subdrivers[count].poll = usb_generic_hid_polling_callback;
    273         hid_dev->subdrivers[count].deinit = usb_generic_hid_deinit;
     272        hid_dev->subdrivers[count].deinit = NULL;
    274273        hid_dev->subdrivers[count].poll_end = NULL;
    275 
     274       
    276275        hid_dev->subdriver_count = count + 1;
    277 
     276       
    278277        return EOK;
    279278}
     
    284283{
    285284        assert(hid_dev != NULL);
    286 
     285       
    287286        const usb_hid_subdriver_t *subdrivers[USB_HID_MAX_SUBDRIVERS];
    288 
     287       
    289288        int i = 0, count = 0;
    290289        const usb_hid_subdriver_mapping_t *mapping = &usb_hid_subdrivers[i];
     
    292291        bool ids_matched;
    293292        bool matched;
    294 
     293       
    295294        while (count < USB_HID_MAX_SUBDRIVERS &&
    296295            (mapping->usage_path != NULL
     
    340339                mapping = &usb_hid_subdrivers[++i];
    341340        }
    342 
     341       
    343342        // we have all subdrivers determined, save them into the hid device
    344343        return usb_hid_save_subdrivers(hid_dev, subdrivers, count);
     
    350349{
    351350        assert(hid_dev != NULL && dev != NULL);
    352 
     351       
    353352        int rc = EOK;
    354 
     353       
    355354        if (dev->pipes[USB_HID_KBD_POLL_EP_NO].present) {
    356355                usb_log_debug("Found keyboard endpoint.\n");
     
    370369                rc = ENOTSUP;
    371370        }
    372 
     371       
    373372        return rc;
    374373}
     
    379378{
    380379        assert(hid_dev != NULL && hid_dev->report != NULL);
    381 
     380       
    382381        uint8_t report_id = 0;
    383382        size_t size;
    384 
     383       
    385384        size_t max_size = 0;
    386 
     385       
    387386        do {
    388387                usb_log_debug("Getting size of the report.\n");
     
    395394                    report_id, USB_HID_REPORT_TYPE_INPUT);
    396395        } while (report_id != 0);
    397 
     396       
    398397        usb_log_debug("Max size of input report: %zu\n", max_size);
    399 
     398       
    400399        hid_dev->max_input_report_size = max_size;
    401400        assert(hid_dev->input_report == NULL);
    402 
     401       
    403402        hid_dev->input_report = malloc(max_size);
    404403        if (hid_dev->input_report == NULL) {
     
    406405        }
    407406        memset(hid_dev->input_report, 0, max_size);
    408 
     407       
    409408        return EOK;
    410409}
     
    412411/*----------------------------------------------------------------------------*/
    413412
     413usb_hid_dev_t *usb_hid_new(void)
     414{
     415        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)calloc(1,
     416            sizeof(usb_hid_dev_t));
     417       
     418        if (hid_dev == NULL) {
     419                usb_log_fatal("No memory!\n");
     420                return NULL;
     421        }
     422       
     423        hid_dev->report = (usb_hid_report_t *)(malloc(sizeof(
     424            usb_hid_report_t)));
     425        if (hid_dev->report == NULL) {
     426                usb_log_fatal("No memory!\n");
     427                free(hid_dev);
     428                return NULL;
     429        }
     430       
     431        hid_dev->poll_pipe_index = -1;
     432       
     433        return hid_dev;
     434}
     435
     436/*----------------------------------------------------------------------------*/
     437
    414438int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev)
    415439{
    416440        int rc, i;
    417 
     441       
    418442        usb_log_debug("Initializing HID structure...\n");
    419 
     443       
    420444        if (hid_dev == NULL) {
    421445                usb_log_error("Failed to init HID structure: no structure given"
     
    423447                return EINVAL;
    424448        }
    425 
     449       
    426450        if (dev == NULL) {
    427451                usb_log_error("Failed to init HID structure: no USB device"
     
    429453                return EINVAL;
    430454        }
    431 
    432         hid_dev->report = (usb_hid_report_t *)(malloc(sizeof(
    433             usb_hid_report_t)));
    434         if (hid_dev->report == NULL) {
    435                 usb_log_error("No memory!\n");
    436                 return ENOMEM;
    437         }
    438         usb_hid_report_init(hid_dev->report);
    439 
     455       
    440456        /* The USB device should already be initialized, save it in structure */
    441457        hid_dev->usb_dev = dev;
    442         hid_dev->poll_pipe_index = -1;
    443 
     458       
    444459        rc = usb_hid_check_pipes(hid_dev, dev);
    445460        if (rc != EOK) {
     
    450465        rc = usb_hid_process_report_descriptor(hid_dev->usb_dev,
    451466            hid_dev->report, &hid_dev->report_desc, &hid_dev->report_desc_size);
    452 
     467       
    453468        bool fallback = false;
    454 
     469       
    455470        if (rc == EOK) {
    456471                // try to find subdrivers that may want to handle this device
     
    469484                fallback = true;
    470485        }
    471 
     486       
    472487        if (fallback) {
    473488                // fall back to boot protocol
     
    495510                }
    496511        }
    497 
     512       
    498513        if (rc != EOK) {
    499514                usb_log_error("No subdriver for handling this device could be"
     
    527542                rc = (ok) ? EOK : -1;   // what error to report
    528543        }
    529 
    530 
     544       
     545       
    531546        if (rc == EOK) {
    532547                // save max input report size and allocate space for the report
     
    537552                }
    538553        }
    539 
    540 
     554       
     555       
    541556        return rc;
    542557}
     
    548563{
    549564        int i;
    550 
     565       
    551566        if (dev == NULL || arg == NULL || buffer == NULL) {
    552567                usb_log_error("Missing arguments to polling callback.\n");
    553568                return false;
    554569        }
    555 
     570       
    556571        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg;
    557 
     572       
    558573        assert(hid_dev->input_report != NULL);
    559574        usb_log_debug("New data [%zu/%zu]: %s\n", buffer_size,
     
    567582                usb_hid_new_report(hid_dev);
    568583        }
    569 
     584       
    570585        // parse the input report
    571 
     586       
    572587        int rc = usb_hid_parse_report(hid_dev->report, buffer, buffer_size,
    573588            &hid_dev->report_id);
    574 
     589       
    575590        if (rc != EOK) {
    576591                usb_log_warning("Error in usb_hid_parse_report():"
    577592                    "%s\n", str_error(rc));
    578593        }       
    579 
     594       
    580595        bool cont = false;
    581 
     596       
    582597        // continue if at least one of the subdrivers want to continue
    583598        for (i = 0; i < hid_dev->subdriver_count; ++i) {
     
    588603                }
    589604        }
    590 
     605       
    591606        return cont;
    592607}
     
    598613{
    599614        int i;
    600 
     615       
    601616        if (dev == NULL || arg == NULL) {
    602617                return;
    603618        }
    604 
     619       
    605620        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg;
    606 
     621       
    607622        for (i = 0; i < hid_dev->subdriver_count; ++i) {
    608623                if (hid_dev->subdrivers[i].poll_end != NULL) {
     
    611626                }
    612627        }
    613 
    614         hid_dev->running = false;
     628       
     629        usb_hid_destroy(hid_dev);
    615630}
    616631
     
    634649{
    635650        int i;
    636 
     651       
    637652        if (hid_dev == NULL) {
    638653                return;
    639654        }
    640 
     655       
    641656        usb_log_debug("Subdrivers: %p, subdriver count: %d\n",
    642657            hid_dev->subdrivers, hid_dev->subdriver_count);
    643 
     658       
    644659        assert(hid_dev->subdrivers != NULL
    645660            || hid_dev->subdriver_count == 0);
    646 
     661       
    647662        for (i = 0; i < hid_dev->subdriver_count; ++i) {
    648663                if (hid_dev->subdrivers[i].deinit != NULL) {
     
    651666                }
    652667        }
    653 
    654         /* Free allocated structures */
    655         free(hid_dev->subdrivers);
    656         free(hid_dev->report_desc);
    657 
    658         /* Destroy the parser */
     668       
     669        // free the subdrivers info
     670        if (hid_dev->subdrivers != NULL) {
     671                free(hid_dev->subdrivers);
     672        }
     673
     674        // destroy the parser
    659675        if (hid_dev->report != NULL) {
    660676                usb_hid_free_report(hid_dev->report);
    661677        }
    662678
     679        if (hid_dev->report_desc != NULL) {
     680                free(hid_dev->report_desc);
     681        }
    663682}
    664683
  • uspace/drv/bus/usb/usbhid/usbhid.h

    re3f7418 r3958e315  
    102102        /** Structure holding generic USB device information. */
    103103        usb_device_t *usb_dev;
    104 
     104       
    105105        /** Index of the polling pipe in usb_hid_endpoints array. */
    106106        int poll_pipe_index;
    107 
     107       
    108108        /** Subdrivers. */
    109109        usb_hid_subdriver_t *subdrivers;
    110 
     110       
    111111        /** Number of subdrivers. */
    112112        int subdriver_count;
    113 
     113       
    114114        /** Report descriptor. */
    115115        uint8_t *report_desc;
     
    117117        /** Report descriptor size. */
    118118        size_t report_desc_size;
    119 
     119       
    120120        /** HID Report parser. */
    121121        usb_hid_report_t *report;
    122 
     122       
    123123        uint8_t report_id;
    124 
     124       
    125125        uint8_t *input_report;
    126 
     126       
    127127        size_t input_report_size;
    128128        size_t max_input_report_size;
    129 
     129       
    130130        int report_nr;
    131         volatile bool running;
    132131};
    133132
     
    141140};
    142141
    143 extern usb_endpoint_description_t *usb_hid_endpoints[];
     142usb_endpoint_description_t *usb_hid_endpoints[USB_HID_POLL_EP_COUNT + 1];
    144143
    145144/*----------------------------------------------------------------------------*/
     145
     146usb_hid_dev_t *usb_hid_new(void);
    146147
    147148int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev);
  • uspace/drv/bus/usb/usbhub/port.c

    re3f7418 r3958e315  
    288288        port->attached_device.fun = NULL;
    289289
    290         ret = usb_hc_connection_open(&hub->connection);
    291         if (ret == EOK) {
    292                 ret = usb_hc_unregister_device(&hub->connection,
    293                     port->attached_device.address);
    294                 if (ret != EOK) {
    295                         usb_log_warning("Failed to unregister address of the "
    296                             "removed device: %s.\n", str_error(ret));
    297                 }
    298                 ret = usb_hc_connection_close(&hub->connection);
    299                 if (ret != EOK) {
    300                         usb_log_warning("Failed to close hc connection %s.\n",
    301                             str_error(ret));
    302                 }
    303 
    304         } else {
    305                 usb_log_warning("Failed to open hc connection %s.\n",
    306                     str_error(ret));
    307         }
    308 
     290        ret = usb_hc_unregister_device(&hub->connection,
     291            port->attached_device.address);
     292        if (ret != EOK) {
     293                usb_log_warning("Failed to unregister address of the removed "
     294                    "device: %s.\n", str_error(ret));
     295        }
    309296        port->attached_device.address = -1;
    310297        fibril_mutex_unlock(&port->mutex);
  • uspace/drv/bus/usb/usbhub/usbhub.c

    re3f7418 r3958e315  
    117117        ddf_fun_destroy(hub->hub_fun);
    118118
     119        free(hub);
     120        usb_dev->driver_data = NULL;
    119121        usb_log_info("USB hub driver, stopped and cleaned.\n");
    120122        return EOK;
     
    252254{
    253255        assert(usb_dev);
    254         usb_hub_dev_t *hub_dev =
    255             usb_device_data_alloc(usb_dev, sizeof(usb_hub_dev_t));
     256        usb_hub_dev_t *hub_dev = malloc(sizeof(usb_hub_dev_t));
    256257        if (!hub_dev)
    257258            return NULL;
    258259
    259260        hub_dev->usb_device = usb_dev;
     261
    260262        hub_dev->ports = NULL;
    261263        hub_dev->port_count = 0;
     
    264266        fibril_mutex_initialize(&hub_dev->pending_ops_mutex);
    265267        fibril_condvar_initialize(&hub_dev->pending_ops_cv);
     268        usb_dev->driver_data = hub_dev;
    266269
    267270        return hub_dev;
  • uspace/drv/bus/usb/usbmast/main.c

    re3f7418 r3958e315  
    8282    void *arg);
    8383
    84 /** Callback when a device is removed from the system.
    85  *
    86  * @param dev Representation of USB device.
    87  * @return Error code.
    88  */
    89 static int usbmast_device_gone(usb_device_t *dev)
    90 {
    91         usbmast_dev_t *mdev = dev->driver_data;
    92         assert(mdev);
    93 
    94         for (size_t i = 0; i < mdev->lun_count; ++i) {
    95                 const int rc = ddf_fun_unbind(mdev->luns[i]);
    96                 if (rc != EOK) {
    97                         usb_log_error("Failed to unbind LUN function %zu: "
    98                             "%s\n", i, str_error(rc));
    99                         return rc;
    100                 }
    101                 ddf_fun_destroy(mdev->luns[i]);
    102                 mdev->luns[i] = NULL;
    103         }
    104         free(mdev->luns);
    105         return EOK;
    106 }
    107 
    10884/** Callback when new device is attached and recognized as a mass storage.
    10985 *
     
    11894
    11995        /* Allocate softstate */
    120         mdev = usb_device_data_alloc(dev, sizeof(usbmast_dev_t));
     96        dev->driver_data = mdev = malloc(sizeof(usbmast_dev_t));
    12197        if (mdev == NULL) {
    12298                usb_log_error("Failed allocating softstate.\n");
     
    136112
    137113        usb_log_debug("Get LUN count...\n");
    138         mdev->lun_count = usb_masstor_get_lun_count(mdev);
    139         mdev->luns = calloc(mdev->lun_count, sizeof(ddf_fun_t*));
    140         if (mdev->luns == NULL) {
    141                 rc = ENOMEM;
    142                 usb_log_error("Failed allocating luns table.\n");
    143                 goto error;
    144         }
    145 
    146         for (i = 0; i < mdev->lun_count; i++) {
     114        mdev->luns = usb_masstor_get_lun_count(mdev);
     115
     116        for (i = 0; i < mdev->luns; i++) {
    147117                rc = usbmast_fun_create(mdev, i);
    148118                if (rc != EOK)
     
    152122        return EOK;
    153123error:
    154         /* Destroy functions */
    155         for (size_t i = 0; i < mdev->lun_count; ++i) {
    156                 if (mdev->luns[i] == NULL)
    157                         continue;
    158                 const int rc = ddf_fun_unbind(mdev->luns[i]);
    159                 if (rc != EOK) {
    160                         usb_log_warning("Failed to unbind LUN function %zu: "
    161                             "%s.\n", i, str_error(rc));
    162                 }
    163                 ddf_fun_destroy(mdev->luns[i]);
    164         }
    165         free(mdev->luns);
    166         free(mdev);
     124        /* XXX Destroy functions */
    167125        return rc;
    168126}
     
    204162        }
    205163
    206         mfun->ddf_fun = fun;
    207164        mfun->mdev = mdev;
    208165        mfun->lun = lun;
     
    255212
    256213        free(fun_name);
    257         mdev->luns[lun] = fun;
    258214
    259215        return EOK;
     
    339295static usb_driver_ops_t usbmast_driver_ops = {
    340296        .device_add = usbmast_device_add,
    341         .device_gone = usbmast_device_gone,
    342297};
    343298
  • uspace/drv/bus/usb/usbmast/usbmast.h

    re3f7418 r3958e315  
    4141
    4242/** Mass storage device. */
    43 typedef struct usbmast_dev {
     43typedef struct {
    4444        /** DDF device */
    4545        ddf_dev_t *ddf_dev;
     
    4747        usb_device_t *usb_dev;
    4848        /** Number of LUNs */
    49         unsigned lun_count;
    50         /** LUN functions */
    51         ddf_fun_t **luns;
     49        unsigned luns;
    5250} usbmast_dev_t;
    53 
    5451
    5552/** Mass storage function.
  • uspace/drv/bus/usb/usbmid/dump.c

    re3f7418 r3958e315  
    4747 * @param depth Nesting depth.
    4848 */
    49 static void dump_tree_descriptor(const uint8_t *data, size_t depth)
     49static void dump_tree_descriptor(uint8_t *data, size_t depth)
    5050{
    5151        if (data == NULL) {
    5252                return;
    5353        }
    54         const int type = data[1];
     54        int type = (int) *(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(
    74     usb_dp_parser_t *parser, usb_dp_parser_data_t *data,
    75     const uint8_t *root, size_t depth)
     73static void dump_tree_internal(usb_dp_parser_t *parser, usb_dp_parser_data_t *data,
     74    uint8_t *root, size_t depth)
    7675{
    7776        if (root == NULL) {
     
    7978        }
    8079        dump_tree_descriptor(root, depth);
    81         const uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
     80        uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
    8281        do {
    8382                dump_tree_internal(parser, data, child, depth + 1);
     
    9392static void dump_tree(usb_dp_parser_t *parser, usb_dp_parser_data_t *data)
    9493{
    95         const uint8_t *ptr = data->data;
     94        uint8_t *ptr = data->data;
    9695        dump_tree_internal(parser, data, ptr, 0);
    9796}
  • uspace/drv/bus/usb/usbmid/explore.c

    re3f7418 r3958e315  
    7373 * @param list List where to add the interfaces.
    7474 */
    75 static void create_interfaces(const uint8_t *config_descriptor,
     75static void create_interfaces(uint8_t *config_descriptor,
    7676    size_t config_descriptor_size, list_t *list)
    7777{
    78         const usb_dp_parser_data_t data = {
     78        usb_dp_parser_data_t data = {
    7979                .data = config_descriptor,
    8080                .size = config_descriptor_size,
     
    8686        };
    8787
    88         const uint8_t *interface_ptr =
    89             usb_dp_get_nested_descriptor(&parser, &data, data.data);
     88        uint8_t *interface_ptr = usb_dp_get_nested_descriptor(&parser, &data,
     89            data.data);
    9090        if (interface_ptr == NULL) {
    9191                return;
     
    149149
    150150        /* Short cuts to save on typing ;-). */
    151         const void *config_descriptor_raw = dev->descriptors.configuration;
     151        uint8_t *config_descriptor_raw = dev->descriptors.configuration;
    152152        size_t config_descriptor_size = dev->descriptors.configuration_size;
    153         const usb_standard_configuration_descriptor_t *config_descriptor =
    154             config_descriptor_raw;
     153        usb_standard_configuration_descriptor_t *config_descriptor =
     154            (usb_standard_configuration_descriptor_t *) config_descriptor_raw;
    155155
    156156        /* Select the first configuration */
     
    163163        }
    164164
    165         usb_mid_t *usb_mid = usb_device_data_alloc(dev, sizeof(usb_mid_t));
    166         if (!usb_mid) {
    167                 usb_log_error("Failed to create USB MID structure.\n");
    168                 return false;
    169         }
    170 
    171165        /* Create control function */
    172         usb_mid->ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "ctl");
    173         if (usb_mid->ctl_fun == NULL) {
     166        ddf_fun_t *ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, "ctl");
     167        if (ctl_fun == NULL) {
    174168                usb_log_error("Failed to create control function.\n");
    175169                return false;
    176170        }
    177171
    178         usb_mid->ctl_fun->ops = &mid_device_ops;
    179 
    180         rc = ddf_fun_bind(usb_mid->ctl_fun);
     172        ctl_fun->ops = &mid_device_ops;
     173
     174        rc = ddf_fun_bind(ctl_fun);
    181175        if (rc != EOK) {
    182176                usb_log_error("Failed to bind control function: %s.\n",
    183177                    str_error(rc));
    184                 ddf_fun_destroy(usb_mid->ctl_fun);
    185                 return false;
    186         }
    187 
     178                return false;
     179        }
    188180
    189181        /* Create interface children. */
    190         list_initialize(&usb_mid->interface_list);
     182        list_t interface_list;
     183        list_initialize(&interface_list);
    191184        create_interfaces(config_descriptor_raw, config_descriptor_size,
    192             &usb_mid->interface_list);
    193 
    194         list_foreach(usb_mid->interface_list, link) {
     185            &interface_list);
     186
     187        list_foreach(interface_list, link) {
    195188                usbmid_interface_t *iface = list_get_instance(link,
    196189                    usbmid_interface_t, link);
  • uspace/drv/bus/usb/usbmid/main.c

    re3f7418 r3958e315  
    6666}
    6767
    68 static int usbmid_device_gone(usb_device_t *dev)
    69 {
    70         assert(dev);
    71         usb_log_info("USB MID gone: `%s'.\n", dev->ddf_dev->name);
    72 
    73         /* Remove ctl function */
    74         usb_mid_t *usb_mid = dev->driver_data;
    75         int ret = ddf_fun_unbind(usb_mid->ctl_fun);
    76         if (ret != EOK) {
    77                 usb_log_error("Failed to unbind USB MID ctl function: %s.\n",
    78                     str_error(ret));
    79                 return ret;
    80         }
    81         ddf_fun_destroy(usb_mid->ctl_fun);
    82 
    83         /* Now remove all other functions */
    84         while (!list_empty(&usb_mid->interface_list)) {
    85                 link_t *item = list_first(&usb_mid->interface_list);
    86                 list_remove(item);
    87 
    88                 usbmid_interface_t *iface = list_get_instance(item,
    89                     usbmid_interface_t, link);
    90 
    91                 usb_log_info("Removing child for interface %d (%s).\n",
    92                     iface->interface_no,
    93                     usb_str_class(iface->interface->interface_class));
    94 
    95                 const int pret = usbmid_interface_destroy(iface);
    96                 if (pret != EOK) {
    97                         usb_log_error("Failed to remove child for interface "
    98                             "%d (%s): %s\n",
    99                             iface->interface_no,
    100                             usb_str_class(iface->interface->interface_class),
    101                             str_error(pret));
    102                         ret = pret;
    103                 }
    104         }
    105         return ret;
    106 }
    107 
    10868/** USB MID driver ops. */
    10969static usb_driver_ops_t mid_driver_ops = {
    11070        .device_add = usbmid_device_add,
    111         .device_gone = usbmid_device_gone,
    11271};
    11372
  • uspace/drv/bus/usb/usbmid/usbmid.c

    re3f7418 r3958e315  
    4545
    4646/** Callback for DDF USB interface. */
     47static int usb_iface_get_address_impl(ddf_fun_t *fun, devman_handle_t handle,
     48    usb_address_t *address)
     49{
     50        return usb_iface_get_address_hub_impl(fun, handle, address);
     51}
     52
     53/** Callback for DDF USB interface. */
    4754static int usb_iface_get_interface_impl(ddf_fun_t *fun, devman_handle_t handle,
    4855    int *iface_no)
     
    6370static usb_iface_t child_usb_iface = {
    6471        .get_hc_handle = usb_iface_get_hc_handle_hub_child_impl,
    65         .get_address = usb_iface_get_address_hub_impl,
     72        .get_address = usb_iface_get_address_impl,
    6673        .get_interface = usb_iface_get_interface_impl
    6774};
     
    7279};
    7380
    74 int usbmid_interface_destroy(usbmid_interface_t *mid_iface)
    75 {
    76         assert(mid_iface);
    77         assert_link_not_used(&mid_iface->link);
    78         const int ret = ddf_fun_unbind(mid_iface->fun);
    79         if (ret != EOK) {
    80                 return ret;
    81         }
    82         /* NOTE: usbmid->interface points somewhere, but we did not
    83          * allocate that space, so don't touch */
    84         ddf_fun_destroy(mid_iface->fun);
    85         /* NOTE: mid_iface is invalid at this point, it was assigned to
    86          * mid_iface->fun->driver_data and freed in ddf_fun_destroy */
    87         return EOK;
    88 }
    8981
    9082/** Spawn new child device from one interface.
     
    114106            (int) interface_descriptor->interface_number);
    115107        if (rc < 0) {
    116                 return ENOMEM;
     108                goto error_leave;
    117109        }
    118110
    119111        /* Create the device. */
    120112        child = ddf_fun_create(parent->ddf_dev, fun_inner, child_name);
    121         free(child_name);
    122113        if (child == NULL) {
    123                 return ENOMEM;
     114                rc = ENOMEM;
     115                goto error_leave;
    124116        }
    125117
     
    130122
    131123        rc = usb_device_create_match_ids_from_interface(device_descriptor,
    132             interface_descriptor, &child->match_ids);
     124            interface_descriptor,
     125            &child->match_ids);
    133126        if (rc != EOK) {
    134                 ddf_fun_destroy(child);
    135                 return rc;
     127                goto error_leave;
    136128        }
    137129
    138130        rc = ddf_fun_bind(child);
    139131        if (rc != EOK) {
    140                 /* This takes care of match_id deallocation as well. */
    141                 ddf_fun_destroy(child);
    142                 return rc;
     132                goto error_leave;
    143133        }
    144134
    145135        return EOK;
     136
     137error_leave:
     138        if (child != NULL) {
     139                child->name = NULL;
     140                /* This takes care of match_id deallocation as well. */
     141                ddf_fun_destroy(child);
     142        }
     143        if (child_name != NULL) {
     144                free(child_name);
     145        }
     146
     147        return rc;
    146148}
    147149
  • uspace/drv/bus/usb/usbmid/usbmid.h

    re3f7418 r3958e315  
    5858} usbmid_interface_t;
    5959
    60 /** Container to hold all the function pointers */
    61 typedef struct usb_mid {
    62         ddf_fun_t *ctl_fun;
    63         list_t interface_list;
    64 } usb_mid_t;
    65 
    6660bool usbmid_explore_device(usb_device_t *);
    6761int usbmid_spawn_interface_child(usb_device_t *, usbmid_interface_t *,
     
    6963    const usb_standard_interface_descriptor_t *);
    7064void usbmid_dump_descriptors(uint8_t *, size_t);
    71 int usbmid_interface_destroy(usbmid_interface_t *mid_iface);
    7265
    7366#endif
  • uspace/lib/usbdev/include/usb/dev/dp.h

    re3f7418 r3958e315  
    5959typedef struct {
    6060        /** Used descriptor nesting. */
    61         const usb_dp_descriptor_nesting_t *nesting;
     61        usb_dp_descriptor_nesting_t *nesting;
    6262} usb_dp_parser_t;
    6363
     
    6565typedef struct {
    6666        /** Data to be parsed. */
    67         const uint8_t *data;
     67        uint8_t *data;
    6868        /** Size of input data in bytes. */
    6969        size_t size;
     
    7272} usb_dp_parser_data_t;
    7373
    74 typedef void (*walk_callback_t)(const uint8_t *, size_t, void *);
     74uint8_t *usb_dp_get_nested_descriptor(usb_dp_parser_t *,
     75    usb_dp_parser_data_t *, uint8_t *);
     76uint8_t *usb_dp_get_sibling_descriptor(usb_dp_parser_t *,
     77    usb_dp_parser_data_t *, uint8_t *, uint8_t *);
    7578
    76 const uint8_t *usb_dp_get_nested_descriptor(const usb_dp_parser_t *,
    77     const usb_dp_parser_data_t *, const uint8_t *);
    78 const 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 
    81 void usb_dp_walk_simple(uint8_t *, size_t, const usb_dp_descriptor_nesting_t *,
    82     walk_callback_t, void *);
     79void usb_dp_walk_simple(uint8_t *, size_t, usb_dp_descriptor_nesting_t *,
     80    void (*)(uint8_t *, size_t, void *), void *);
    8381
    8482#endif
  • uspace/lib/usbdev/include/usb/dev/driver.h

    re3f7418 r3958e315  
    4343        usb_standard_device_descriptor_t device;
    4444        /** Full configuration descriptor of current configuration. */
    45         const uint8_t *configuration;
     45        uint8_t *configuration;
    4646        size_t configuration_size;
    4747} usb_device_descriptors_t;
     
    5353typedef struct {
    5454        /** Interface descriptor. */
    55         const usb_standard_interface_descriptor_t *interface;
     55        usb_standard_interface_descriptor_t *interface;
    5656        /** Pointer to start of descriptor tree bound with this interface. */
    57         const uint8_t *nested_descriptors;
     57        uint8_t *nested_descriptors;
    5858        /** Size of data pointed by nested_descriptors in bytes. */
    5959        size_t nested_descriptors_size;
     
    158158        usb_endpoint_description_t **endpoints;
    159159        /** Driver ops. */
    160         const usb_driver_ops_t *ops;
     160        usb_driver_ops_t *ops;
    161161} usb_driver_t;
    162162
     
    168168int usb_device_retrieve_descriptors(usb_pipe_t *, usb_device_descriptors_t *);
    169169int usb_device_create_pipes(const ddf_dev_t *, usb_device_connection_t *,
    170     usb_endpoint_description_t **, const uint8_t *, size_t, int, int,
     170    usb_endpoint_description_t **, uint8_t *, size_t, int, int,
    171171    usb_endpoint_mapping_t **, size_t *);
    172172int usb_device_destroy_pipes(const ddf_dev_t *, usb_endpoint_mapping_t *, size_t);
    173173int usb_device_create(ddf_dev_t *, usb_endpoint_description_t **, usb_device_t **, const char **);
    174174void usb_device_destroy(usb_device_t *);
    175 void * usb_device_data_alloc(usb_device_t *, size_t);
    176175
    177 size_t usb_interface_count_alternates(const uint8_t *, size_t, uint8_t);
    178 int usb_alternate_interfaces_create(const uint8_t *, size_t, int,
     176size_t usb_interface_count_alternates(uint8_t *, size_t, uint8_t);
     177int usb_alternate_interfaces_create(uint8_t *, size_t, int,
    179178    usb_alternate_interfaces_t **);
    180179
  • uspace/lib/usbdev/include/usb/dev/pipes.h

    re3f7418 r3958e315  
    171171int usb_pipe_probe_default_control(usb_pipe_t *);
    172172int usb_pipe_initialize_from_configuration(usb_endpoint_mapping_t *,
    173     size_t, const uint8_t *, size_t, usb_device_connection_t *);
     173    size_t, uint8_t *, size_t, usb_device_connection_t *);
    174174int usb_pipe_register_with_speed(usb_pipe_t *, usb_speed_t,
    175175    unsigned int, usb_hc_connection_t *);
  • uspace/lib/usbdev/src/altiface.c

    re3f7418 r3958e315  
    4848 * @return Number of alternate interfaces for @p interface_no interface.
    4949 */
    50 size_t usb_interface_count_alternates(const uint8_t *config_descr,
     50size_t usb_interface_count_alternates(uint8_t *config_descr,
    5151    size_t config_descr_size, uint8_t interface_no)
    5252{
     
    5454        assert(config_descr_size > 0);
    5555
    56         const usb_dp_parser_t dp_parser = {
     56        usb_dp_parser_t dp_parser = {
    5757                .nesting = usb_dp_standard_descriptor_nesting
    5858        };
    59         const usb_dp_parser_data_t dp_data = {
     59        usb_dp_parser_data_t dp_data = {
    6060                .data = config_descr,
    6161                .size = config_descr_size,
     
    6565        size_t alternate_count = 0;
    6666
    67         const uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,
     67        uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,
    6868            &dp_data, config_descr);
    6969        while (iface_ptr != NULL) {
     
    9090 * @return Error code.
    9191 */
    92 int usb_alternate_interfaces_create(const uint8_t *config_descr,
     92int usb_alternate_interfaces_create(uint8_t *config_descr,
    9393    size_t config_descr_size, int interface_number,
    9494    usb_alternate_interfaces_t **alternates_ptr)
     
    140140            = &alternates->alternatives[0];
    141141
    142         const uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,
     142        uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,
    143143            &dp_data, dp_data.data);
    144144        while (iface_ptr != NULL) {
     
    160160                    dp_data.data, iface_ptr);
    161161                if (iface_ptr == NULL) {
    162                         const uint8_t *next = dp_data.data + dp_data.size;
     162                        uint8_t *next = dp_data.data + dp_data.size;
    163163                        cur_alt_iface->nested_descriptors_size
    164164                            = next - cur_alt_iface->nested_descriptors;
  • uspace/lib/usbdev/src/devdrv.c

    re3f7418 r3958e315  
    5454};
    5555
    56 static const usb_driver_t *driver = NULL;
     56static usb_driver_t *driver = NULL;
    5757
    5858
     
    115115        int rc = usb_device_create_pipes(dev->ddf_dev, &dev->wire, endpoints,
    116116            dev->descriptors.configuration, dev->descriptors.configuration_size,
    117             dev->interface_no, alternate_setting, &pipes, &pipes_count);
     117            dev->interface_no, alternate_setting,
     118            &pipes, &pipes_count);
    118119
    119120        if (rc != EOK) {
     
    152153        gen_dev->driver_data = dev;
    153154
    154         rc = driver->ops->device_add(dev);
    155         if (rc != EOK)
    156                 usb_device_destroy(dev);
    157         return rc;
     155        return driver->ops->device_add(dev);
    158156}
    159157/*----------------------------------------------------------------------------*/
     
    188186        if (driver->ops->device_gone == NULL)
    189187                return ENOTSUP;
    190         usb_device_t *usb_dev = gen_dev->driver_data;
    191         const int ret = driver->ops->device_gone(usb_dev);
     188        const int ret = driver->ops->device_gone(gen_dev->driver_data);
    192189        if (ret == EOK)
    193                 usb_device_destroy(usb_dev);
     190                usb_device_destroy(gen_dev->driver_data);
    194191
    195192        return ret;
     
    322319int usb_device_create_pipes(const ddf_dev_t *dev, usb_device_connection_t *wire,
    323320    usb_endpoint_description_t **endpoints,
    324     const uint8_t *config_descr, size_t config_descr_size,
     321    uint8_t *config_descr, size_t config_descr_size,
    325322    int interface_no, int interface_setting,
    326323    usb_endpoint_mapping_t **pipes_ptr, size_t *pipes_count_ptr)
     
    336333        int rc;
    337334
    338         const size_t pipe_count = count_other_pipes(endpoints);
     335        size_t pipe_count = count_other_pipes(endpoints);
    339336        if (pipe_count == 0) {
    340                 *pipes_count_ptr = pipe_count;
    341337                *pipes_ptr = NULL;
    342338                return EOK;
     
    449445{
    450446        assert(dev != NULL);
     447        assert(((pipes != NULL) && (pipes_count > 0))
     448            || ((pipes == NULL) && (pipes_count == 0)));
    451449
    452450        if (pipes_count == 0) {
    453                 assert(pipes == NULL);
    454451                return EOK;
    455452        }
    456         assert(pipes != NULL);
    457453
    458454        int rc;
     
    472468        size_t i;
    473469        for (i = 0; i < pipes_count; i++) {
    474                 usb_log_debug2("Unregistering pipe %zu (%spresent).\n",
    475                     i, pipes[i].present ? "" : "not ");
    476                 if (pipes[i].present)
    477                         usb_pipe_unregister(pipes[i].pipe, &hc_conn);
     470                usb_pipe_unregister(pipes[i].pipe, &hc_conn);
    478471                free(pipes[i].pipe);
    479472        }
     
    599592
    600593        /* Ignore errors and hope for the best. */
    601         destroy_current_pipes(dev);
     594        usb_device_destroy_pipes(dev->ddf_dev, dev->pipes, dev->pipes_count);
     595        free(dev->descriptors.configuration);
    602596
    603597        if (dev->alternate_interfaces != NULL) {
     
    605599        }
    606600        free(dev->alternate_interfaces);
    607         free(dev->descriptors.configuration);
    608         free(dev->driver_data);
    609 }
    610 
    611 void * usb_device_data_alloc(usb_device_t *usb_dev, size_t size)
    612 {
    613         assert(usb_dev);
    614         assert(usb_dev->driver_data == NULL);
    615         return usb_dev->driver_data = calloc(1, size);
    616 
     601
     602        free(dev);
    617603}
    618604
  • uspace/lib/usbdev/src/dp.c

    re3f7418 r3958e315  
    7575 * @return Whether @p ptr points inside <code>data->data</code> field.
    7676 */
    77 static bool is_valid_descriptor_pointer(const usb_dp_parser_data_t *data,
    78     const uint8_t *ptr)
     77static bool is_valid_descriptor_pointer(usb_dp_parser_data_t *data,
     78    uint8_t *ptr)
    7979{
    8080        if (ptr == NULL) {
     
    100100 * @retval NULL Invalid input or no next descriptor.
    101101 */
    102 static const uint8_t *get_next_descriptor(const usb_dp_parser_data_t *data,
    103     const uint8_t *current)
     102static uint8_t *get_next_descriptor(usb_dp_parser_data_t *data,
     103    uint8_t *current)
    104104{
    105105        assert(is_valid_descriptor_pointer(data, current));
    106106
    107         const uint8_t current_length = *current;
    108         const uint8_t *next = current + current_length;
     107        uint8_t current_length = *current;
     108        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(const usb_dp_parser_data_t *data, const uint8_t *start)
     126static int get_descriptor_type(usb_dp_parser_data_t *data, 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(const usb_dp_parser_t *parser,
     147static bool is_nested_descriptor_type(usb_dp_parser_t *parser,
    148148    int child, int parent)
    149149{
    150         const usb_dp_descriptor_nesting_t *nesting = parser->nesting;
     150        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(const usb_dp_parser_t *parser,
    169     const usb_dp_parser_data_t *data, const uint8_t *child, const uint8_t *parent)
     168static bool is_nested_descriptor(usb_dp_parser_t *parser,
     169    usb_dp_parser_data_t *data, uint8_t *child, uint8_t *parent)
    170170{
    171171        return is_nested_descriptor_type(parser,
     
    183183 * @retval NULL Invalid input.
    184184 */
    185 const 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)
     185uint8_t *usb_dp_get_nested_descriptor(usb_dp_parser_t *parser,
     186    usb_dp_parser_data_t *data, uint8_t *parent)
    187187{
    188188        if (!is_valid_descriptor_pointer(data, parent)) {
     
    190190        }
    191191
    192         const uint8_t *next = get_next_descriptor(data, parent);
     192        uint8_t *next = get_next_descriptor(data, parent);
    193193        if (next == NULL) {
    194194                return NULL;
     
    211211 * @retval NULL Invalid input.
    212212 */
    213 static 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);
     213static 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);
    218217        if (child == NULL) {
    219218                return get_next_descriptor(data, parent);
    220219        }
    221         const uint8_t *next_child =
    222             skip_nested_descriptors(parser, data, child);
     220        uint8_t *next_child = skip_nested_descriptors(parser, data, child);
    223221        while (is_nested_descriptor(parser, data, next_child, parent)) {
    224222                next_child = skip_nested_descriptors(parser, data, next_child);
     
    238236 * @retval NULL Invalid input.
    239237 */
    240 const 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)
     238uint8_t *usb_dp_get_sibling_descriptor(usb_dp_parser_t *parser,
     239    usb_dp_parser_data_t *data, uint8_t *parent, uint8_t *sibling)
    243240{
    244241        if (!is_valid_descriptor_pointer(data, parent)
     
    247244        }
    248245
    249         const uint8_t *possible_sibling =
    250             skip_nested_descriptors(parser, data, sibling);
     246        uint8_t *possible_sibling = skip_nested_descriptors(parser, data, sibling);
    251247        if (possible_sibling == NULL) {
    252248                return NULL;
     
    273269 * @param arg Custom (user) argument.
    274270 */
    275 static 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)
     271static 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)
    278274{
    279275        if (root == NULL) {
     
    281277        }
    282278        callback(root, depth, arg);
    283         const uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
     279        uint8_t *child = usb_dp_get_nested_descriptor(parser, data, root);
    284280        do {
    285281                usb_dp_browse_simple_internal(parser, data, child, depth + 1,
     
    305301 */
    306302void usb_dp_walk_simple(uint8_t *descriptors, size_t descriptors_size,
    307     const usb_dp_descriptor_nesting_t *descriptor_nesting,
    308     walk_callback_t callback, void *arg)
     303    usb_dp_descriptor_nesting_t *descriptor_nesting,
     304    void (*callback)(uint8_t *, size_t, void *), void *arg)
    309305{
    310306        if ((descriptors == NULL) || (descriptors_size == 0)
     
    313309        }
    314310
    315         const usb_dp_parser_data_t data = {
     311        usb_dp_parser_data_t data = {
    316312                .data = descriptors,
    317313                .size = descriptors_size,
     
    319315        };
    320316
    321         const usb_dp_parser_t parser = {
     317        usb_dp_parser_t parser = {
    322318                .nesting = descriptor_nesting
    323319        };
  • uspace/lib/usbdev/src/pipesinit.c

    re3f7418 r3958e315  
    6868 * @return Whether the given descriptor is endpoint descriptor.
    6969 */
    70 static inline bool is_endpoint_descriptor(const uint8_t *descriptor)
     70static inline bool is_endpoint_descriptor(uint8_t *descriptor)
    7171{
    7272        return descriptor[1] == USB_DESCTYPE_ENDPOINT;
     
    8080 */
    8181static bool endpoint_fits_description(const usb_endpoint_description_t *wanted,
    82     const usb_endpoint_description_t *found)
     82    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     const usb_endpoint_description_t *found_endpoint,
     122    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;
    162163
    163164        /*
     
    166167
    167168        /* Actual endpoint number is in bits 0..3 */
    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         };
     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;
    183183
    184184        /*
     
    224224static int process_interface(
    225225    usb_endpoint_mapping_t *mapping, size_t mapping_count,
    226     const usb_dp_parser_t *parser, const usb_dp_parser_data_t *parser_data,
    227     const uint8_t *interface_descriptor)
    228 {
    229         const uint8_t *descriptor = usb_dp_get_nested_descriptor(parser,
     226    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,
    230230            parser_data, interface_descriptor);
    231231
     
    284284int usb_pipe_initialize_from_configuration(
    285285    usb_endpoint_mapping_t *mapping, size_t mapping_count,
    286     const uint8_t *config_descriptor, size_t config_descriptor_size,
     286    uint8_t *configuration_descriptor, size_t configuration_descriptor_size,
    287287    usb_device_connection_t *connection)
    288288{
    289289        assert(connection);
    290290
    291         if (config_descriptor == NULL) {
     291        if (configuration_descriptor == NULL) {
    292292                return EBADMEM;
    293293        }
    294         if (config_descriptor_size
     294        if (configuration_descriptor_size
    295295            < sizeof(usb_standard_configuration_descriptor_t)) {
    296296                return ERANGE;
     
    310310         * Prepare the descriptor parser.
    311311         */
    312         const usb_dp_parser_t dp_parser = {
     312        usb_dp_parser_t dp_parser = {
    313313                .nesting = descriptor_nesting
    314314        };
    315         const usb_dp_parser_data_t dp_data = {
    316                 .data = config_descriptor,
    317                 .size = config_descriptor_size,
     315        usb_dp_parser_data_t dp_data = {
     316                .data = configuration_descriptor,
     317                .size = configuration_descriptor_size,
    318318                .arg = connection
    319319        };
     
    322322         * Iterate through all interfaces.
    323323         */
    324         const uint8_t *interface = usb_dp_get_nested_descriptor(&dp_parser,
    325             &dp_data, config_descriptor);
     324        uint8_t *interface = usb_dp_get_nested_descriptor(&dp_parser,
     325            &dp_data, configuration_descriptor);
    326326        if (interface == NULL) {
    327327                return ENOENT;
     
    329329        do {
    330330                (void) process_interface(mapping, mapping_count,
    331                     &dp_parser, &dp_data, interface);
     331                    &dp_parser, &dp_data,
     332                    interface);
    332333                interface = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data,
    333                     config_descriptor, interface);
     334                    configuration_descriptor, interface);
    334335        } while (interface != NULL);
    335336
     
    513514{
    514515        assert(pipe);
    515         assert(pipe->wire);
    516516        assert(hc_connection);
    517517       
  • uspace/lib/usbdev/src/request.c

    re3f7418 r3958e315  
    425425
    426426        /* Everything is okay, copy the descriptor. */
    427         memcpy(descriptor, &descriptor_tmp, sizeof(descriptor_tmp));
     427        memcpy(descriptor, &descriptor_tmp,
     428            sizeof(descriptor_tmp));
    428429
    429430        return EOK;
     
    469470
    470471        /* Everything is okay, copy the descriptor. */
    471         memcpy(descriptor, &descriptor_tmp, sizeof(descriptor_tmp));
     472        memcpy(descriptor, &descriptor_tmp,
     473            sizeof(descriptor_tmp));
    472474
    473475        return EOK;
  • uspace/lib/usbhid/src/hidreport.c

    re3f7418 r3958e315  
    6969         * First nested descriptor of the configuration descriptor.
    7070         */
    71         const uint8_t *d =
     71        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         const uint8_t *iface_desc = d;
     94        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.