Changes in uspace/drv/bus/usb/usbhid/generic/hiddev.c [b803845:a0c05e7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/generic/hiddev.c
rb803845 ra0c05e7 61 61 62 62 /*----------------------------------------------------------------------------*/ 63 64 63 static size_t usb_generic_hid_get_event_length(ddf_fun_t *fun); 65 66 static int usb_generic_hid_get_event(ddf_fun_t *fun, uint8_t *buffer, 64 static int usb_generic_hid_get_event(ddf_fun_t *fun, uint8_t *buffer, 67 65 size_t size, size_t *act_size, int *event_nr, unsigned int flags); 68 69 66 static int usb_generic_hid_client_connected(ddf_fun_t *fun); 70 71 67 static size_t usb_generic_get_report_descriptor_length(ddf_fun_t *fun); 72 73 static int usb_generic_get_report_descriptor(ddf_fun_t *fun, uint8_t *desc, 68 static int usb_generic_get_report_descriptor(ddf_fun_t *fun, uint8_t *desc, 74 69 size_t size, size_t *actual_size); 75 76 /*----------------------------------------------------------------------------*/ 77 70 /*----------------------------------------------------------------------------*/ 78 71 static usbhid_iface_t usb_generic_iface = { 79 72 .get_event = usb_generic_hid_get_event, … … 82 75 .get_report_descriptor = usb_generic_get_report_descriptor 83 76 }; 84 77 /*----------------------------------------------------------------------------*/ 85 78 static ddf_dev_ops_t usb_generic_hid_ops = { 86 79 .interfaces[USBHID_DEV_IFACE] = &usb_generic_iface, 87 80 .open = usb_generic_hid_client_connected 88 81 }; 89 90 /*----------------------------------------------------------------------------*/ 91 82 /*----------------------------------------------------------------------------*/ 92 83 static size_t usb_generic_hid_get_event_length(ddf_fun_t *fun) 93 84 { … … 99 90 } 100 91 101 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;92 const usb_hid_dev_t *hid_dev = fun->driver_data; 102 93 103 94 usb_log_debug2("hid_dev: %p, Max input report size (%zu).\n", … … 106 97 return hid_dev->max_input_report_size; 107 98 } 108 109 /*----------------------------------------------------------------------------*/ 110 111 static int usb_generic_hid_get_event(ddf_fun_t *fun, uint8_t *buffer, 99 /*----------------------------------------------------------------------------*/ 100 static int usb_generic_hid_get_event(ddf_fun_t *fun, uint8_t *buffer, 112 101 size_t size, size_t *act_size, int *event_nr, unsigned int flags) 113 102 { … … 120 109 } 121 110 122 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;111 const usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 123 112 124 113 if (hid_dev->input_report_size > size) { 125 usb_log_debug("input_report_size > size (%zu, %zu)\n", 114 usb_log_debug("input_report_size > size (%zu, %zu)\n", 126 115 hid_dev->input_report_size, size); 127 116 return EINVAL; // TODO: other error code … … 129 118 130 119 /*! @todo This should probably be somehow atomic. */ 131 memcpy(buffer, hid_dev->input_report, 120 memcpy(buffer, hid_dev->input_report, 132 121 hid_dev->input_report_size); 133 122 *act_size = hid_dev->input_report_size; … … 138 127 return EOK; 139 128 } 140 141 /*----------------------------------------------------------------------------*/ 142 129 /*----------------------------------------------------------------------------*/ 143 130 static size_t usb_generic_get_report_descriptor_length(ddf_fun_t *fun) 144 131 { … … 150 137 } 151 138 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", 139 const usb_hid_dev_t *hid_dev = fun->driver_data; 140 141 usb_log_debug2("hid_dev->report_desc_size = %zu\n", 155 142 hid_dev->report_desc_size); 156 143 157 144 return hid_dev->report_desc_size; 158 145 } 159 160 /*----------------------------------------------------------------------------*/ 161 162 static int usb_generic_get_report_descriptor(ddf_fun_t *fun, uint8_t *desc, 146 /*----------------------------------------------------------------------------*/ 147 static int usb_generic_get_report_descriptor(ddf_fun_t *fun, uint8_t *desc, 163 148 size_t size, size_t *actual_size) 164 149 { … … 170 155 } 171 156 172 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;157 const usb_hid_dev_t *hid_dev = fun->driver_data; 173 158 174 159 if (hid_dev->report_desc_size > size) { … … 181 166 return EOK; 182 167 } 183 184 /*----------------------------------------------------------------------------*/ 185 168 /*----------------------------------------------------------------------------*/ 186 169 static int usb_generic_hid_client_connected(ddf_fun_t *fun) 187 170 { … … 189 172 return EOK; 190 173 } 191 192 /*----------------------------------------------------------------------------*/ 193 174 /*----------------------------------------------------------------------------*/ 194 175 void usb_generic_hid_deinit(usb_hid_dev_t *hid_dev, void *data) 195 176 { 196 177 ddf_fun_t *fun = data; 197 const int ret = ddf_fun_unbind(fun); 198 if (ret != EOK) { 178 if (fun == NULL) 179 return; 180 181 if (ddf_fun_unbind(fun) != EOK) { 199 182 usb_log_error("Failed to unbind generic hid fun.\n"); 200 183 return; … … 206 189 ddf_fun_destroy(fun); 207 190 } 208 209 /*----------------------------------------------------------------------------*/ 210 191 /*----------------------------------------------------------------------------*/ 211 192 int usb_generic_hid_init(usb_hid_dev_t *hid_dev, void **data) 212 193 { … … 216 197 217 198 /* Create the exposed function. */ 218 /** @todo Generate numbers for the devices? */219 199 usb_log_debug("Creating DDF function %s...\n", HID_GENERIC_FUN_NAME); 220 200 ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed, … … 225 205 } 226 206 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; 227 210 fun->ops = &usb_generic_hid_ops; 228 211 … … 231 214 usb_log_error("Could not bind DDF function: %s.\n", 232 215 str_error(rc)); 216 fun->driver_data = NULL; 233 217 ddf_fun_destroy(fun); 234 218 return rc; 235 219 } 236 /* This is nasty both device and this function have the same237 * driver data, thus destruction would lead to double free */238 fun->driver_data = hid_dev;239 220 240 221 usb_log_debug("HID function created. Handle: %" PRIun "\n", fun->handle); … … 243 224 return EOK; 244 225 } 245 246 /*----------------------------------------------------------------------------*/ 247 226 /*----------------------------------------------------------------------------*/ 248 227 bool usb_generic_hid_polling_callback(usb_hid_dev_t *hid_dev, void *data) 249 228 { 250 229 return true; 251 230 } 252 253 231 /** 254 232 * @}
Note:
See TracChangeset
for help on using the changeset viewer.