Changes in uspace/drv/bus/usb/usbhid/generic/hiddev.c [15f3c3f:a0c05e7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/generic/hiddev.c
r15f3c3f ra0c05e7 48 48 /*----------------------------------------------------------------------------*/ 49 49 50 usb_endpoint_description_t usb_hid_generic_poll_endpoint_description = {50 const usb_endpoint_description_t usb_hid_generic_poll_endpoint_description = { 51 51 .transfer_type = USB_TRANSFER_INTERRUPT, 52 52 .direction = USB_DIRECTION_IN, 53 53 .interface_class = USB_CLASS_HID, 54 .interface_subclass = -1, 55 .interface_protocol = -1, 54 56 .flags = 0 55 57 }; … … 59 61 60 62 /*----------------------------------------------------------------------------*/ 61 62 63 static size_t usb_generic_hid_get_event_length(ddf_fun_t *fun); 63 64 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, 65 65 size_t size, size_t *act_size, int *event_nr, unsigned int flags); 66 67 66 static int usb_generic_hid_client_connected(ddf_fun_t *fun); 68 69 67 static size_t usb_generic_get_report_descriptor_length(ddf_fun_t *fun); 70 71 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, 72 69 size_t size, size_t *actual_size); 73 74 /*----------------------------------------------------------------------------*/ 75 70 /*----------------------------------------------------------------------------*/ 76 71 static usbhid_iface_t usb_generic_iface = { 77 72 .get_event = usb_generic_hid_get_event, … … 80 75 .get_report_descriptor = usb_generic_get_report_descriptor 81 76 }; 82 77 /*----------------------------------------------------------------------------*/ 83 78 static ddf_dev_ops_t usb_generic_hid_ops = { 84 79 .interfaces[USBHID_DEV_IFACE] = &usb_generic_iface, 85 80 .open = usb_generic_hid_client_connected 86 81 }; 87 88 /*----------------------------------------------------------------------------*/ 89 82 /*----------------------------------------------------------------------------*/ 90 83 static size_t usb_generic_hid_get_event_length(ddf_fun_t *fun) 91 84 { 92 85 usb_log_debug2("Generic HID: Get event length (fun: %p, " 93 86 "fun->driver_data: %p.\n", fun, fun->driver_data); 94 87 95 88 if (fun == NULL || fun->driver_data == NULL) { 96 89 return 0; 97 90 } 98 91 99 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;100 92 const usb_hid_dev_t *hid_dev = fun->driver_data; 93 101 94 usb_log_debug2("hid_dev: %p, Max input report size (%zu).\n", 102 95 hid_dev, hid_dev->max_input_report_size); 103 96 104 97 return hid_dev->max_input_report_size; 105 98 } 106 107 /*----------------------------------------------------------------------------*/ 108 109 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, 110 101 size_t size, size_t *act_size, int *event_nr, unsigned int flags) 111 102 { 112 103 usb_log_debug2("Generic HID: Get event.\n"); 113 104 114 105 if (fun == NULL || fun->driver_data == NULL || buffer == NULL 115 106 || act_size == NULL || event_nr == NULL) { … … 118 109 } 119 110 120 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;121 111 const usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data; 112 122 113 if (hid_dev->input_report_size > size) { 123 usb_log_debug("input_report_size > size (%zu, %zu)\n", 114 usb_log_debug("input_report_size > size (%zu, %zu)\n", 124 115 hid_dev->input_report_size, size); 125 116 return EINVAL; // TODO: other error code 126 117 } 127 118 128 119 /*! @todo This should probably be somehow atomic. */ 129 memcpy(buffer, hid_dev->input_report, 120 memcpy(buffer, hid_dev->input_report, 130 121 hid_dev->input_report_size); 131 122 *act_size = hid_dev->input_report_size; 132 123 *event_nr = usb_hid_report_number(hid_dev); 133 124 134 125 usb_log_debug2("OK\n"); 135 136 return EOK; 137 } 138 139 /*----------------------------------------------------------------------------*/ 140 126 127 return EOK; 128 } 129 /*----------------------------------------------------------------------------*/ 141 130 static size_t usb_generic_get_report_descriptor_length(ddf_fun_t *fun) 142 131 { 143 132 usb_log_debug("Generic HID: Get report descriptor length.\n"); 144 133 145 134 if (fun == NULL || fun->driver_data == NULL) { 146 135 usb_log_debug("No function"); 147 136 return EINVAL; 148 137 } 149 150 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;151 152 usb_log_debug2("hid_dev->report_desc_size = %zu\n", 138 139 const usb_hid_dev_t *hid_dev = fun->driver_data; 140 141 usb_log_debug2("hid_dev->report_desc_size = %zu\n", 153 142 hid_dev->report_desc_size); 154 143 155 144 return hid_dev->report_desc_size; 156 145 } 157 158 /*----------------------------------------------------------------------------*/ 159 160 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, 161 148 size_t size, size_t *actual_size) 162 149 { 163 150 usb_log_debug2("Generic HID: Get report descriptor.\n"); 164 151 165 152 if (fun == NULL || fun->driver_data == NULL) { 166 153 usb_log_debug("No function"); 167 154 return EINVAL; 168 155 } 169 170 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;171 156 157 const usb_hid_dev_t *hid_dev = fun->driver_data; 158 172 159 if (hid_dev->report_desc_size > size) { 173 160 return EINVAL; 174 161 } 175 162 176 163 memcpy(desc, hid_dev->report_desc, hid_dev->report_desc_size); 177 164 *actual_size = hid_dev->report_desc_size; 178 179 return EOK; 180 } 181 182 /*----------------------------------------------------------------------------*/ 183 165 166 return EOK; 167 } 168 /*----------------------------------------------------------------------------*/ 184 169 static int usb_generic_hid_client_connected(ddf_fun_t *fun) 185 170 { … … 187 172 return EOK; 188 173 } 189 190 /*----------------------------------------------------------------------------*/ 191 192 static int usb_generic_hid_create_function(usb_hid_dev_t *hid_dev) 193 { 174 /*----------------------------------------------------------------------------*/ 175 void usb_generic_hid_deinit(usb_hid_dev_t *hid_dev, void *data) 176 { 177 ddf_fun_t *fun = data; 178 if (fun == NULL) 179 return; 180 181 if (ddf_fun_unbind(fun) != EOK) { 182 usb_log_error("Failed to unbind generic hid fun.\n"); 183 return; 184 } 185 usb_log_debug2("%s unbound.\n", fun->name); 186 /* We did not allocate this, so leave this alone 187 * the device would take care of it */ 188 fun->driver_data = NULL; 189 ddf_fun_destroy(fun); 190 } 191 /*----------------------------------------------------------------------------*/ 192 int usb_generic_hid_init(usb_hid_dev_t *hid_dev, void **data) 193 { 194 if (hid_dev == NULL) { 195 return EINVAL; 196 } 197 194 198 /* Create the exposed function. */ 195 /** @todo Generate numbers for the devices? */196 199 usb_log_debug("Creating DDF function %s...\n", HID_GENERIC_FUN_NAME); 197 200 ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed, … … 201 204 return ENOMEM; 202 205 } 203 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; 204 210 fun->ops = &usb_generic_hid_ops; 205 fun->driver_data = hid_dev;206 211 207 212 int rc = ddf_fun_bind(fun); … … 209 214 usb_log_error("Could not bind DDF function: %s.\n", 210 215 str_error(rc)); 216 fun->driver_data = NULL; 211 217 ddf_fun_destroy(fun); 212 218 return rc; 213 219 } 214 220 215 221 usb_log_debug("HID function created. Handle: %" PRIun "\n", fun->handle); 216 217 return EOK; 218 } 219 220 /*----------------------------------------------------------------------------*/ 221 222 int 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); 229 } 230 231 /*----------------------------------------------------------------------------*/ 232 222 *data = fun; 223 224 return EOK; 225 } 226 /*----------------------------------------------------------------------------*/ 233 227 bool usb_generic_hid_polling_callback(usb_hid_dev_t *hid_dev, void *data) 234 228 { 235 229 return true; 236 230 } 237 238 231 /** 239 232 * @}
Note:
See TracChangeset
for help on using the changeset viewer.