Changeset ae3a941 in mainline for uspace/lib/usbhid/src/hidreq.c
- Timestamp:
- 2018-02-26T16:51:40Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e773f58
- Parents:
- 3692678
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhid/src/hidreq.c
r3692678 rae3a941 65 65 return EINVAL; 66 66 } 67 68 if (iface_no < 0) { 69 usb_log_warning("usbhid_req_set_report(): no interface given." 70 "\n"); 71 return EINVAL; 72 } 73 74 /* 75 * No need for checking other parameters, as they are checked in 76 * the called function (usb_control_request_set()). 77 */ 78 79 errno_t rc; 80 67 68 if (iface_no < 0) { 69 usb_log_warning("usbhid_req_set_report(): no interface given." 70 "\n"); 71 return EINVAL; 72 } 73 74 /* 75 * No need for checking other parameters, as they are checked in 76 * the called function (usb_control_request_set()). 77 */ 78 79 errno_t rc; 80 81 81 uint16_t value = 0; 82 82 value |= (type << 8); 83 83 84 84 usb_log_debug("Sending Set Report request to the device."); 85 85 86 86 rc = usb_control_request_set(ctrl_pipe, 87 87 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, … … 93 93 return rc; 94 94 } 95 95 96 96 return EOK; 97 97 } … … 115 115 return EINVAL; 116 116 } 117 118 if (iface_no < 0) { 119 usb_log_warning("usbhid_req_set_report(): no interface given." 120 "\n"); 121 return EINVAL; 122 } 123 124 /* 125 * No need for checking other parameters, as they are checked in 126 * the called function (usb_control_request_set()). 127 */ 128 117 118 if (iface_no < 0) { 119 usb_log_warning("usbhid_req_set_report(): no interface given." 120 "\n"); 121 return EINVAL; 122 } 123 124 /* 125 * No need for checking other parameters, as they are checked in 126 * the called function (usb_control_request_set()). 127 */ 128 129 129 errno_t rc; 130 130 131 131 usb_log_debug("Sending Set Protocol request to the device (" 132 132 "protocol: %d, iface: %d).\n", protocol, iface_no); 133 134 rc = usb_control_request_set(ctrl_pipe, 135 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 133 134 rc = usb_control_request_set(ctrl_pipe, 135 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 136 136 USB_HIDREQ_SET_PROTOCOL, protocol, iface_no, NULL, 0); 137 137 … … 141 141 return rc; 142 142 } 143 143 144 144 return EOK; 145 145 } … … 163 163 return EINVAL; 164 164 } 165 166 if (iface_no < 0) { 167 usb_log_warning("usbhid_req_set_report(): no interface given." 168 "\n"); 169 return EINVAL; 170 } 171 172 /* 173 * No need for checking other parameters, as they are checked in 174 * the called function (usb_control_request_set()). 175 */ 176 165 166 if (iface_no < 0) { 167 usb_log_warning("usbhid_req_set_report(): no interface given." 168 "\n"); 169 return EINVAL; 170 } 171 172 /* 173 * No need for checking other parameters, as they are checked in 174 * the called function (usb_control_request_set()). 175 */ 176 177 177 errno_t rc; 178 178 179 179 usb_log_debug("Sending Set Idle request to the device (" 180 180 "duration: %u, iface: %d).\n", duration, iface_no); 181 181 182 182 uint16_t value = duration << 8; 183 183 184 184 rc = usb_control_request_set(ctrl_pipe, 185 185 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, … … 191 191 return rc; 192 192 } 193 193 194 194 return EOK; 195 195 } … … 203 203 * @param[in][out] buffer Buffer for the report data. 204 204 * @param[in] buf_size Size of the buffer (in bytes). 205 * @param[out] actual_size Actual size of report received from the device 205 * @param[out] actual_size Actual size of report received from the device 206 206 * (in bytes). 207 207 * … … 210 210 * @return Other value inherited from function usb_control_request_set(). 211 211 */ 212 errno_t usbhid_req_get_report(usb_pipe_t *ctrl_pipe, int iface_no, 213 usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size, 212 errno_t usbhid_req_get_report(usb_pipe_t *ctrl_pipe, int iface_no, 213 usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size, 214 214 size_t *actual_size) 215 215 { … … 218 218 return EINVAL; 219 219 } 220 221 if (iface_no < 0) { 222 usb_log_warning("usbhid_req_set_report(): no interface given." 223 "\n"); 224 return EINVAL; 225 } 226 227 /* 228 * No need for checking other parameters, as they are checked in 229 * the called function (usb_control_request_set()). 230 */ 231 220 221 if (iface_no < 0) { 222 usb_log_warning("usbhid_req_set_report(): no interface given." 223 "\n"); 224 return EINVAL; 225 } 226 227 /* 228 * No need for checking other parameters, as they are checked in 229 * the called function (usb_control_request_set()). 230 */ 231 232 232 errno_t rc; 233 233 234 234 uint16_t value = 0; 235 235 value |= (type << 8); 236 236 237 237 usb_log_debug("Sending Get Report request to the device."); 238 239 rc = usb_control_request_get(ctrl_pipe, 240 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 238 239 rc = usb_control_request_get(ctrl_pipe, 240 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 241 241 USB_HIDREQ_GET_REPORT, value, iface_no, buffer, buf_size, 242 242 actual_size); … … 247 247 return rc; 248 248 } 249 249 250 250 return EOK; 251 251 } … … 262 262 * @return Other value inherited from function usb_control_request_set(). 263 263 */ 264 errno_t usbhid_req_get_protocol(usb_pipe_t *ctrl_pipe, int iface_no, 264 errno_t usbhid_req_get_protocol(usb_pipe_t *ctrl_pipe, int iface_no, 265 265 usb_hid_protocol_t *protocol) 266 266 { … … 269 269 return EINVAL; 270 270 } 271 272 if (iface_no < 0) { 273 usb_log_warning("usbhid_req_set_report(): no interface given." 274 "\n"); 275 return EINVAL; 276 } 277 278 /* 279 * No need for checking other parameters, as they are checked in 280 * the called function (usb_control_request_set()). 281 */ 282 283 errno_t rc; 271 272 if (iface_no < 0) { 273 usb_log_warning("usbhid_req_set_report(): no interface given." 274 "\n"); 275 return EINVAL; 276 } 277 278 /* 279 * No need for checking other parameters, as they are checked in 280 * the called function (usb_control_request_set()). 281 */ 282 283 errno_t rc; 284 284 285 285 usb_log_debug("Sending Get Protocol request to the device (" 286 286 "iface: %d).\n", iface_no); 287 287 288 288 uint8_t buffer[1]; 289 289 size_t actual_size = 0; 290 291 rc = usb_control_request_get(ctrl_pipe, 292 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 290 291 rc = usb_control_request_get(ctrl_pipe, 292 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 293 293 USB_HIDREQ_GET_PROTOCOL, 0, iface_no, buffer, 1, &actual_size); 294 294 … … 298 298 return rc; 299 299 } 300 300 301 301 if (actual_size != 1) { 302 302 usb_log_warning("Wrong data size: %zu, expected: 1.", 303 303 actual_size); 304 304 return ELIMIT; 305 305 } 306 306 307 307 *protocol = buffer[0]; 308 308 309 309 return EOK; 310 310 } … … 320 320 * @retval EOK if successful. 321 321 * @retval EINVAL if no HID device is given. 322 * @return Other value inherited from one of functions 322 * @return Other value inherited from one of functions 323 323 * usb_pipe_start_session(), usb_pipe_end_session(), 324 324 * usb_control_request_set(). 325 325 */ 326 errno_t usbhid_req_get_idle(usb_pipe_t *ctrl_pipe, int iface_no, uint8_t *duration) 327 { 328 if (ctrl_pipe == NULL) { 329 usb_log_warning("usbhid_req_set_report(): no pipe given."); 330 return EINVAL; 331 } 332 333 if (iface_no < 0) { 334 usb_log_warning("usbhid_req_set_report(): no interface given." 335 "\n"); 336 return EINVAL; 337 } 338 339 /* 340 * No need for checking other parameters, as they are checked in 341 * the called function (usb_control_request_set()). 342 */ 343 326 errno_t usbhid_req_get_idle(usb_pipe_t *ctrl_pipe, int iface_no, 327 uint8_t *duration) 328 { 329 if (ctrl_pipe == NULL) { 330 usb_log_warning("usbhid_req_set_report(): no pipe given."); 331 return EINVAL; 332 } 333 334 if (iface_no < 0) { 335 usb_log_warning("usbhid_req_set_report(): no interface given." 336 "\n"); 337 return EINVAL; 338 } 339 340 /* 341 * No need for checking other parameters, as they are checked in 342 * the called function (usb_control_request_set()). 343 */ 344 344 345 errno_t rc; 345 346 346 347 usb_log_debug("Sending Get Idle request to the device (" 347 348 "iface: %d).\n", iface_no); 348 349 349 350 uint16_t value = 0; 350 351 uint8_t buffer[1]; 351 352 size_t actual_size = 0; 352 353 rc = usb_control_request_get(ctrl_pipe, 354 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 355 USB_HIDREQ_GET_IDLE, value, iface_no, buffer, 1, 353 354 rc = usb_control_request_get(ctrl_pipe, 355 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE, 356 USB_HIDREQ_GET_IDLE, value, iface_no, buffer, 1, 356 357 &actual_size); 357 358 … … 361 362 return rc; 362 363 } 363 364 364 365 if (actual_size != 1) { 365 366 usb_log_warning("Wrong data size: %zu, expected: 1.", 366 367 actual_size); 367 368 return ELIMIT; 368 369 } 369 370 370 371 *duration = buffer[0]; 371 372 372 373 return EOK; 373 374 }
Note:
See TracChangeset
for help on using the changeset viewer.