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