Ignore:
Timestamp:
2011-10-15T13:06:28Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a044f71
Parents:
3958e315 (diff), 065064e6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

USB improvements.

USB unplug part2; Unplug support in all drivers (except for unused usbmouse driver).
Make descriptor paring work on const pointers.
Fixes several crashes and memory leaks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhid/multimedia/multimedia.c

    r3958e315 re3f7418  
    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;
    6971} usb_multimedia_t;
    7072
     
    8688{
    8789        usb_log_debug(NAME " default_connection_handler()\n");
    88        
     90
    8991        usb_multimedia_t *multim_dev = (usb_multimedia_t *)fun->driver_data;
    90        
     92
    9193        if (multim_dev == NULL) {
    9294                async_answer_0(icallid, EINVAL);
    9395                return;
    9496        }
    95        
     97
    9698        async_sess_t *sess =
    9799            async_callback_receive_start(EXCHANGE_SERIALIZE, icall);
     
    137139        assert(hid_dev != NULL);
    138140        assert(multim_dev != NULL);
    139        
     141
    140142        kbd_event_t ev;
    141        
     143
    142144        ev.type = type;
    143145        ev.key = key;
     
    151153                return;
    152154        }
    153        
     155
    154156        async_exch_t *exch = async_exchange_begin(multim_dev->console_sess);
    155157        async_msg_4(exch, KBDEV_EVENT, ev.type, ev.key, ev.mods, ev.c);
     
    169171                return ENOMEM;
    170172        }
    171        
     173
    172174        fun->ops = &multimedia_ops;
    173175        fun->driver_data = multim_dev;   // TODO: maybe change to hid_dev->data
    174        
     176
    175177        int rc = ddf_fun_bind(fun);
    176178        if (rc != EOK) {
    177179                usb_log_error("Could not bind DDF function: %s.\n",
    178180                    str_error(rc));
    179                 // TODO: Can / should I destroy the DDF function?
    180181                ddf_fun_destroy(fun);
    181182                return rc;
    182183        }
    183        
     184
    184185        usb_log_debug("%s function created (handle: %" PRIun ").\n",
    185186            NAME, fun->handle);
    186        
     187
    187188        rc = ddf_fun_add_to_category(fun, "keyboard");
    188189        if (rc != EOK) {
     
    190191                    "Could not add DDF function to category 'keyboard': %s.\n",
    191192                    str_error(rc));
    192                 // TODO: Can / should I destroy the DDF function?
    193193                ddf_fun_destroy(fun);
    194194                return rc;
    195195        }
    196        
     196        multim_dev->fun = fun;
     197
    197198        return EOK;
    198199}
     
    205206                return EINVAL; /*! @todo Other return code? */
    206207        }
    207        
     208
    208209        usb_log_debug(NAME " Initializing HID/multimedia structure...\n");
    209        
     210
    210211        usb_multimedia_t *multim_dev = (usb_multimedia_t *)malloc(
    211212            sizeof(usb_multimedia_t));
     
    213214                return ENOMEM;
    214215        }
    215        
     216
    216217        multim_dev->console_sess = NULL;
    217        
     218
    218219        /*! @todo Autorepeat */
    219        
     220
    220221        // save the KBD device structure into the HID device structure
    221222        *data = multim_dev;
    222        
     223
    223224        usb_log_debug(NAME " HID/multimedia device structure initialized.\n");
    224        
     225
    225226        int rc = usb_multimedia_create_function(hid_dev, multim_dev);
    226227        if (rc != EOK)
    227228                return rc;
    228        
     229
    229230        usb_log_debug(NAME " HID/multimedia structure initialized.\n");
    230        
     231
    231232        return EOK;
    232233}
     
    239240                return;
    240241        }
    241        
     242
    242243        if (data != NULL) {
    243244                usb_multimedia_t *multim_dev = (usb_multimedia_t *)data;
    244245                // hangup session to the console
    245246                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                }
    246254        }
    247255}
     
    257265
    258266        usb_multimedia_t *multim_dev = (usb_multimedia_t *)data;
    259        
     267
    260268        usb_hid_report_path_t *path = usb_hid_report_path();
    261269        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0);
     
    283291                                               key);
    284292                }
    285                
     293
    286294                field = usb_hid_report_get_sibling(
    287295                    hid_dev->report, field, path, USB_HID_PATH_COMPARE_END
    288296                    | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
    289297                    USB_HID_REPORT_TYPE_INPUT);
    290         }       
     298        }
    291299
    292300        usb_hid_report_path_free(path);
    293        
     301
    294302        return true;
    295303}
Note: See TracChangeset for help on using the changeset viewer.