Changes in uspace/drv/usbhid/hiddev.c [77ab674:1c6c4092] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/hiddev.c
r77ab674 r1c6c4092 53 53 /* Non-API functions */ 54 54 /*----------------------------------------------------------------------------*/ 55 /** 56 * Retreives HID Report descriptor from the device. 57 * 58 * This function first parses the HID descriptor from the Interface descriptor 59 * to get the size of the Report descriptor and then requests the Report 60 * descriptor from the device. 61 * 62 * @param hid_dev HID device structure. 63 * @param config_desc Full configuration descriptor (including all nested 64 * descriptors). 65 * @param config_desc_size Size of the full configuration descriptor (in bytes). 66 * @param iface_desc Pointer to the interface descriptor inside the full 67 * configuration descriptor (@a config_desc) for the interface 68 * assigned with this device (@a hid_dev). 69 * 70 * @retval EOK if successful. 71 * @retval ENOENT if no HID descriptor could be found. 72 * @retval EINVAL if the HID descriptor or HID report descriptor have different 73 * size than expected. 74 * @retval ENOMEM if some allocation failed. 75 * @return Other value inherited from function usb_request_get_descriptor(). 76 * 77 * @sa usb_request_get_descriptor() 78 */ 55 79 56 static int usbhid_dev_get_report_descriptor(usbhid_dev_t *hid_dev, 80 57 uint8_t *config_desc, size_t config_desc_size, uint8_t *iface_desc) … … 164 141 165 142 /*----------------------------------------------------------------------------*/ 166 /** 167 * Retreives descriptors from the device, initializes pipes and stores 168 * important information from descriptors. 169 * 170 * Initializes the polling pipe described by the given endpoint description 171 * (@a poll_ep_desc). 172 * 173 * Information retreived from descriptors and stored in the HID device structure: 174 * - Assigned interface number (the interface controlled by this instance of 175 * the driver) 176 * - Polling interval (from the interface descriptor) 177 * - Report descriptor 178 * 179 * @param hid_dev HID device structure to be initialized. 180 * @param poll_ep_desc Description of the polling (Interrupt In) endpoint 181 * that has to be present in the device in order to 182 * successfuly initialize the structure. 183 * 184 * @sa usb_endpoint_pipe_initialize_from_configuration(), 185 * usbhid_dev_get_report_descriptor() 186 */ 143 187 144 static int usbhid_dev_process_descriptors(usbhid_dev_t *hid_dev, 188 145 usb_endpoint_description_t *poll_ep_desc) … … 192 149 usb_log_info("Processing descriptors...\n"); 193 150 151 // get the first configuration descriptor 152 usb_standard_configuration_descriptor_t config_desc; 153 194 154 int rc; 195 196 uint8_t *descriptors = NULL; 197 size_t descriptors_size; 198 rc = usb_request_get_full_configuration_descriptor_alloc( 199 &hid_dev->ctrl_pipe, 0, (void **) &descriptors, &descriptors_size); 200 if (rc != EOK) { 201 usb_log_error("Failed to retrieve config descriptor: %s.\n", 202 str_error(rc)); 203 return rc; 155 rc = usb_request_get_bare_configuration_descriptor(&hid_dev->ctrl_pipe, 156 0, &config_desc); 157 158 if (rc != EOK) { 159 usb_log_error("Failed to get bare config descriptor: %s.\n", 160 str_error(rc)); 161 return rc; 162 } 163 164 // prepare space for all underlying descriptors 165 uint8_t *descriptors = (uint8_t *)malloc(config_desc.total_length); 166 if (descriptors == NULL) { 167 usb_log_error("No memory!.\n"); 168 return ENOMEM; 169 } 170 171 size_t transferred = 0; 172 // get full configuration descriptor 173 rc = usb_request_get_full_configuration_descriptor(&hid_dev->ctrl_pipe, 174 0, descriptors, config_desc.total_length, &transferred); 175 176 if (rc != EOK) { 177 usb_log_error("Failed to get full config descriptor: %s.\n", 178 str_error(rc)); 179 free(descriptors); 180 return rc; 181 } 182 183 if (transferred != config_desc.total_length) { 184 usb_log_error("Configuration descriptor has wrong size (%u, " 185 "expected %u).\n", transferred, config_desc.total_length); 186 free(descriptors); 187 return ELIMIT; 204 188 } 205 189 … … 217 201 218 202 rc = usb_endpoint_pipe_initialize_from_configuration( 219 endpoint_mapping, 1, descriptors, descriptors_size,203 endpoint_mapping, 1, descriptors, config_desc.total_length, 220 204 &hid_dev->wire); 221 205 … … 249 233 assert(endpoint_mapping[0].interface != NULL); 250 234 251 /* 252 * Save polling interval 253 */ 254 hid_dev->poll_interval = endpoint_mapping[0].descriptor->poll_interval; 255 assert(hid_dev->poll_interval > 0); 256 257 rc = usbhid_dev_get_report_descriptor(hid_dev, 258 descriptors, descriptors_size, 235 rc = usbhid_dev_get_report_descriptor(hid_dev, descriptors, transferred, 259 236 (uint8_t *)endpoint_mapping[0].interface); 260 237 … … 273 250 /* API functions */ 274 251 /*----------------------------------------------------------------------------*/ 275 /** 276 * Creates new uninitialized HID device structure. 277 * 278 * @return Pointer to the new HID device structure, or NULL if an error occured. 279 */ 252 280 253 usbhid_dev_t *usbhid_dev_new(void) 281 254 { … … 296 269 297 270 /*----------------------------------------------------------------------------*/ 298 /** 299 * Properly destroys the HID device structure. 300 * 301 * @note Currently does not clean-up the used pipes, as there are no functions 302 * offering such functionality. 303 * 304 * @param hid_dev Pointer to the structure to be destroyed. 305 */ 271 306 272 void usbhid_dev_free(usbhid_dev_t **hid_dev) 307 273 { … … 326 292 327 293 /*----------------------------------------------------------------------------*/ 328 /** 329 * Initializes HID device structure. 330 * 331 * @param hid_dev HID device structure to be initialized. 332 * @param dev DDF device representing the HID device. 333 * @param poll_ep_desc Description of the polling (Interrupt In) endpoint 334 * that has to be present in the device in order to 335 * successfuly initialize the structure. 336 * 337 * @retval EOK if successful. 338 * @retval EINVAL if some argument is missing. 339 * @return Other value inherited from one of functions 340 * usb_device_connection_initialize_from_device(), 341 * usb_endpoint_pipe_initialize_default_control(), 342 * usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(), 343 * usbhid_dev_process_descriptors(). 344 * 345 * @sa usbhid_dev_process_descriptors() 346 */ 294 347 295 int usbhid_dev_init(usbhid_dev_t *hid_dev, ddf_dev_t *dev, 348 296 usb_endpoint_description_t *poll_ep_desc) … … 395 343 * Get descriptors, parse descriptors and save endpoints. 396 344 */ 397 rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe); 398 if (rc != EOK) { 399 usb_log_error("Failed to start session on the control pipe: %s" 400 ".\n", str_error(rc)); 401 return rc; 402 } 345 usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe); 403 346 404 347 rc = usbhid_dev_process_descriptors(hid_dev, poll_ep_desc); 405 if (rc != EOK) { 406 /* TODO: end session?? */ 348 349 usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe); 350 if (rc != EOK) { 407 351 usb_log_error("Failed to process descriptors: %s.\n", 408 352 str_error(rc)); 409 return rc;410 }411 412 rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);413 if (rc != EOK) {414 usb_log_warning("Failed to start session on the control pipe: "415 "%s.\n", str_error(rc));416 353 return rc; 417 354 }
Note:
See TracChangeset
for help on using the changeset viewer.