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