Ignore:
File:
1 edited

Legend:

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

    ra0c05e7 rb803845  
    6161
    6262/*----------------------------------------------------------------------------*/
     63
    6364static size_t usb_generic_hid_get_event_length(ddf_fun_t *fun);
    64 static int usb_generic_hid_get_event(ddf_fun_t *fun, uint8_t *buffer,
     65
     66static int usb_generic_hid_get_event(ddf_fun_t *fun, uint8_t *buffer,
    6567    size_t size, size_t *act_size, int *event_nr, unsigned int flags);
     68
    6669static int usb_generic_hid_client_connected(ddf_fun_t *fun);
     70
    6771static size_t usb_generic_get_report_descriptor_length(ddf_fun_t *fun);
    68 static int usb_generic_get_report_descriptor(ddf_fun_t *fun, uint8_t *desc,
     72
     73static int usb_generic_get_report_descriptor(ddf_fun_t *fun, uint8_t *desc,
    6974    size_t size, size_t *actual_size);
    70 /*----------------------------------------------------------------------------*/
     75
     76/*----------------------------------------------------------------------------*/
     77
    7178static usbhid_iface_t usb_generic_iface = {
    7279        .get_event = usb_generic_hid_get_event,
     
    7582        .get_report_descriptor = usb_generic_get_report_descriptor
    7683};
    77 /*----------------------------------------------------------------------------*/
     84
    7885static ddf_dev_ops_t usb_generic_hid_ops = {
    7986        .interfaces[USBHID_DEV_IFACE] = &usb_generic_iface,
    8087        .open = usb_generic_hid_client_connected
    8188};
    82 /*----------------------------------------------------------------------------*/
     89
     90/*----------------------------------------------------------------------------*/
     91
    8392static size_t usb_generic_hid_get_event_length(ddf_fun_t *fun)
    8493{
     
    9099        }
    91100
    92         const usb_hid_dev_t *hid_dev = fun->driver_data;
     101        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
    93102
    94103        usb_log_debug2("hid_dev: %p, Max input report size (%zu).\n",
     
    97106        return hid_dev->max_input_report_size;
    98107}
    99 /*----------------------------------------------------------------------------*/
    100 static int usb_generic_hid_get_event(ddf_fun_t *fun, uint8_t *buffer,
     108
     109/*----------------------------------------------------------------------------*/
     110
     111static int usb_generic_hid_get_event(ddf_fun_t *fun, uint8_t *buffer,
    101112    size_t size, size_t *act_size, int *event_nr, unsigned int flags)
    102113{
     
    109120        }
    110121
    111         const usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
     122        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
    112123
    113124        if (hid_dev->input_report_size > size) {
    114                 usb_log_debug("input_report_size > size (%zu, %zu)\n",
     125                usb_log_debug("input_report_size > size (%zu, %zu)\n", 
    115126                    hid_dev->input_report_size, size);
    116127                return EINVAL;  // TODO: other error code
     
    118129
    119130        /*! @todo This should probably be somehow atomic. */
    120         memcpy(buffer, hid_dev->input_report,
     131        memcpy(buffer, hid_dev->input_report, 
    121132            hid_dev->input_report_size);
    122133        *act_size = hid_dev->input_report_size;
     
    127138        return EOK;
    128139}
    129 /*----------------------------------------------------------------------------*/
     140
     141/*----------------------------------------------------------------------------*/
     142
    130143static size_t usb_generic_get_report_descriptor_length(ddf_fun_t *fun)
    131144{
     
    137150        }
    138151
    139         const usb_hid_dev_t *hid_dev = fun->driver_data;
    140 
    141         usb_log_debug2("hid_dev->report_desc_size = %zu\n",
     152        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
     153
     154        usb_log_debug2("hid_dev->report_desc_size = %zu\n", 
    142155            hid_dev->report_desc_size);
    143156
    144157        return hid_dev->report_desc_size;
    145158}
    146 /*----------------------------------------------------------------------------*/
    147 static int usb_generic_get_report_descriptor(ddf_fun_t *fun, uint8_t *desc,
     159
     160/*----------------------------------------------------------------------------*/
     161
     162static int usb_generic_get_report_descriptor(ddf_fun_t *fun, uint8_t *desc,
    148163    size_t size, size_t *actual_size)
    149164{
     
    155170        }
    156171
    157         const usb_hid_dev_t *hid_dev = fun->driver_data;
     172        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
    158173
    159174        if (hid_dev->report_desc_size > size) {
     
    166181        return EOK;
    167182}
    168 /*----------------------------------------------------------------------------*/
     183
     184/*----------------------------------------------------------------------------*/
     185
    169186static int usb_generic_hid_client_connected(ddf_fun_t *fun)
    170187{
     
    172189        return EOK;
    173190}
    174 /*----------------------------------------------------------------------------*/
     191
     192/*----------------------------------------------------------------------------*/
     193
    175194void usb_generic_hid_deinit(usb_hid_dev_t *hid_dev, void *data)
    176195{
    177196        ddf_fun_t *fun = data;
    178         if (fun == NULL)
    179                 return;
    180 
    181         if (ddf_fun_unbind(fun) != EOK) {
     197        const int ret = ddf_fun_unbind(fun);
     198        if (ret != EOK) {
    182199                usb_log_error("Failed to unbind generic hid fun.\n");
    183200                return;
     
    189206        ddf_fun_destroy(fun);
    190207}
    191 /*----------------------------------------------------------------------------*/
     208
     209/*----------------------------------------------------------------------------*/
     210
    192211int usb_generic_hid_init(usb_hid_dev_t *hid_dev, void **data)
    193212{
     
    197216
    198217        /* Create the exposed function. */
     218        /** @todo Generate numbers for the devices? */
    199219        usb_log_debug("Creating DDF function %s...\n", HID_GENERIC_FUN_NAME);
    200220        ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
     
    205225        }
    206226
    207         /* This is nasty, both device and this function have the same
    208          * driver data, thus destruction causes to double free */
    209         fun->driver_data = hid_dev;
    210227        fun->ops = &usb_generic_hid_ops;
    211228
     
    214231                usb_log_error("Could not bind DDF function: %s.\n",
    215232                    str_error(rc));
    216                 fun->driver_data = NULL;
    217233                ddf_fun_destroy(fun);
    218234                return rc;
    219235        }
     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;
    220239
    221240        usb_log_debug("HID function created. Handle: %" PRIun "\n", fun->handle);
     
    224243        return EOK;
    225244}
    226 /*----------------------------------------------------------------------------*/
     245
     246/*----------------------------------------------------------------------------*/
     247
    227248bool usb_generic_hid_polling_callback(usb_hid_dev_t *hid_dev, void *data)
    228249{
    229250        return true;
    230251}
     252
    231253/**
    232254 * @}
Note: See TracChangeset for help on using the changeset viewer.