00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00036 #include <stdint.h>
00037 #include <errno.h>
00038 #include <str_error.h>
00039
00040 #include <usb/hid/hid.h>
00041 #include <usb/debug.h>
00042 #include <usb/dev/request.h>
00043 #include <usb/dev/pipes.h>
00044
00045 #include <usb/hid/request.h>
00046
00047
00060 int usbhid_req_set_report(usb_pipe_t *ctrl_pipe, int iface_no,
00061 usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size)
00062 {
00063 if (ctrl_pipe == NULL) {
00064 usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
00065 return EINVAL;
00066 }
00067
00068 if (iface_no < 0) {
00069 usb_log_warning("usbhid_req_set_report(): no interface given."
00070 "\n");
00071 return EINVAL;
00072 }
00073
00074
00075
00076
00077
00078
00079 int rc;
00080
00081 uint16_t value = 0;
00082 value |= (type << 8);
00083
00084 usb_log_debug("Sending Set Report request to the device.\n");
00085
00086 rc = usb_control_request_set(ctrl_pipe,
00087 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
00088 USB_HIDREQ_SET_REPORT, value, iface_no, buffer, buf_size);
00089
00090 if (rc != EOK) {
00091 usb_log_warning("Error sending Set Report request to the "
00092 "device: %s.\n", str_error(rc));
00093 return rc;
00094 }
00095
00096 return EOK;
00097 }
00098
00099
00110 int usbhid_req_set_protocol(usb_pipe_t *ctrl_pipe, int iface_no,
00111 usb_hid_protocol_t protocol)
00112 {
00113 if (ctrl_pipe == NULL) {
00114 usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
00115 return EINVAL;
00116 }
00117
00118 if (iface_no < 0) {
00119 usb_log_warning("usbhid_req_set_report(): no interface given."
00120 "\n");
00121 return EINVAL;
00122 }
00123
00124
00125
00126
00127
00128
00129 int rc;
00130
00131 usb_log_debug("Sending Set Protocol request to the device ("
00132 "protocol: %d, iface: %d).\n", protocol, iface_no);
00133
00134 rc = usb_control_request_set(ctrl_pipe,
00135 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
00136 USB_HIDREQ_SET_PROTOCOL, protocol, iface_no, NULL, 0);
00137
00138 if (rc != EOK) {
00139 usb_log_warning("Error sending Set Protocol request to the "
00140 "device: %s.\n", str_error(rc));
00141 return rc;
00142 }
00143
00144 return EOK;
00145 }
00146
00147
00159 int usbhid_req_set_idle(usb_pipe_t *ctrl_pipe, int iface_no, uint8_t duration)
00160 {
00161 if (ctrl_pipe == NULL) {
00162 usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
00163 return EINVAL;
00164 }
00165
00166 if (iface_no < 0) {
00167 usb_log_warning("usbhid_req_set_report(): no interface given."
00168 "\n");
00169 return EINVAL;
00170 }
00171
00172
00173
00174
00175
00176
00177 int rc;
00178
00179 usb_log_debug("Sending Set Idle request to the device ("
00180 "duration: %u, iface: %d).\n", duration, iface_no);
00181
00182 uint16_t value = duration << 8;
00183
00184 rc = usb_control_request_set(ctrl_pipe,
00185 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
00186 USB_HIDREQ_SET_IDLE, value, iface_no, NULL, 0);
00187
00188 if (rc != EOK) {
00189 usb_log_warning("Error sending Set Idle request to the device: "
00190 "%s.\n", str_error(rc));
00191 return rc;
00192 }
00193
00194 return EOK;
00195 }
00196
00197
00212 int usbhid_req_get_report(usb_pipe_t *ctrl_pipe, int iface_no,
00213 usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size,
00214 size_t *actual_size)
00215 {
00216 if (ctrl_pipe == NULL) {
00217 usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
00218 return EINVAL;
00219 }
00220
00221 if (iface_no < 0) {
00222 usb_log_warning("usbhid_req_set_report(): no interface given."
00223 "\n");
00224 return EINVAL;
00225 }
00226
00227
00228
00229
00230
00231
00232 int rc;
00233
00234 uint16_t value = 0;
00235 value |= (type << 8);
00236
00237 usb_log_debug("Sending Get Report request to the device.\n");
00238
00239 rc = usb_control_request_get(ctrl_pipe,
00240 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
00241 USB_HIDREQ_GET_REPORT, value, iface_no, buffer, buf_size,
00242 actual_size);
00243
00244 if (rc != EOK) {
00245 usb_log_warning("Error sending Get Report request to the device: "
00246 "%s.\n", str_error(rc));
00247 return rc;
00248 }
00249
00250 return EOK;
00251 }
00252
00253
00264 int usbhid_req_get_protocol(usb_pipe_t *ctrl_pipe, int iface_no,
00265 usb_hid_protocol_t *protocol)
00266 {
00267 if (ctrl_pipe == NULL) {
00268 usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
00269 return EINVAL;
00270 }
00271
00272 if (iface_no < 0) {
00273 usb_log_warning("usbhid_req_set_report(): no interface given."
00274 "\n");
00275 return EINVAL;
00276 }
00277
00278
00279
00280
00281
00282
00283 int rc;
00284
00285 usb_log_debug("Sending Get Protocol request to the device ("
00286 "iface: %d).\n", iface_no);
00287
00288 uint8_t buffer[1];
00289 size_t actual_size = 0;
00290
00291 rc = usb_control_request_get(ctrl_pipe,
00292 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
00293 USB_HIDREQ_GET_PROTOCOL, 0, iface_no, buffer, 1, &actual_size);
00294
00295 if (rc != EOK) {
00296 usb_log_warning("Error sending Get Protocol request to the "
00297 "device: %s.\n", str_error(rc));
00298 return rc;
00299 }
00300
00301 if (actual_size != 1) {
00302 usb_log_warning("Wrong data size: %zu, expected: 1.\n",
00303 actual_size);
00304 return ELIMIT;
00305 }
00306
00307 *protocol = buffer[0];
00308
00309 return EOK;
00310 }
00311
00312
00326 int usbhid_req_get_idle(usb_pipe_t *ctrl_pipe, int iface_no, uint8_t *duration)
00327 {
00328 if (ctrl_pipe == NULL) {
00329 usb_log_warning("usbhid_req_set_report(): no pipe given.\n");
00330 return EINVAL;
00331 }
00332
00333 if (iface_no < 0) {
00334 usb_log_warning("usbhid_req_set_report(): no interface given."
00335 "\n");
00336 return EINVAL;
00337 }
00338
00339
00340
00341
00342
00343
00344 int rc;
00345
00346 usb_log_debug("Sending Get Idle request to the device ("
00347 "iface: %d).\n", iface_no);
00348
00349 uint16_t value = 0;
00350 uint8_t buffer[1];
00351 size_t actual_size = 0;
00352
00353 rc = usb_control_request_get(ctrl_pipe,
00354 USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
00355 USB_HIDREQ_GET_IDLE, value, iface_no, buffer, 1,
00356 &actual_size);
00357
00358 if (rc != EOK) {
00359 usb_log_warning("Error sending Get Idle request to the device: "
00360 "%s.\n", str_error(rc));
00361 return rc;
00362 }
00363
00364 if (actual_size != 1) {
00365 usb_log_warning("Wrong data size: %zu, expected: 1.\n",
00366 actual_size);
00367 return ELIMIT;
00368 }
00369
00370 *duration = buffer[0];
00371
00372 return EOK;
00373 }
00374
00375
00376