HelenOS sources
This source file includes following definitions.
- usbhid_req_set_report
- usbhid_req_set_protocol
- usbhid_req_set_idle
- usbhid_req_get_report
- usbhid_req_get_protocol
- usbhid_req_get_idle
#include <stdint.h>
#include <errno.h>
#include <str_error.h>
#include <usb/hid/hid.h>
#include <usb/debug.h>
#include <usb/dev/request.h>
#include <usb/dev/pipes.h>
#include <usb/hid/request.h>
errno_t usbhid_req_set_report(usb_pipe_t *ctrl_pipe, int iface_no,
usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size)
{
if (ctrl_pipe == NULL) {
usb_log_warning("usbhid_req_set_report(): no pipe given.");
return EINVAL;
}
if (iface_no < 0) {
usb_log_warning("usbhid_req_set_report(): no interface given."
"\n");
return EINVAL;
}
errno_t rc;
uint16_t value = 0;
value |= (type << 8);
usb_log_debug("Sending Set Report request to the device.");
rc = usb_control_request_set(ctrl_pipe,
USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
USB_HIDREQ_SET_REPORT, value, iface_no, buffer, buf_size);
if (rc != EOK) {
usb_log_error("Error sending Set Report request to the "
"device: %s.\n", str_error(rc));
return rc;
}
return EOK;
}
errno_t usbhid_req_set_protocol(usb_pipe_t *ctrl_pipe, int iface_no,
usb_hid_protocol_t protocol)
{
if (ctrl_pipe == NULL) {
usb_log_warning("usbhid_req_set_report(): no pipe given.");
return EINVAL;
}
if (iface_no < 0) {
usb_log_warning("usbhid_req_set_report(): no interface given."
"\n");
return EINVAL;
}
errno_t rc;
usb_log_debug("Sending Set Protocol request to the device ("
"protocol: %d, iface: %d).\n", protocol, iface_no);
rc = usb_control_request_set(ctrl_pipe,
USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
USB_HIDREQ_SET_PROTOCOL, protocol, iface_no, NULL, 0);
if (rc != EOK) {
usb_log_warning("Error sending Set Protocol request to the "
"device: %s.\n", str_error(rc));
return rc;
}
return EOK;
}
errno_t usbhid_req_set_idle(usb_pipe_t *ctrl_pipe, int iface_no, uint8_t duration)
{
if (ctrl_pipe == NULL) {
usb_log_warning("usbhid_req_set_report(): no pipe given.");
return EINVAL;
}
if (iface_no < 0) {
usb_log_warning("usbhid_req_set_report(): no interface given."
"\n");
return EINVAL;
}
errno_t rc;
usb_log_debug("Sending Set Idle request to the device ("
"duration: %u, iface: %d).\n", duration, iface_no);
uint16_t value = duration << 8;
rc = usb_control_request_set(ctrl_pipe,
USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
USB_HIDREQ_SET_IDLE, value, iface_no, NULL, 0);
if (rc != EOK) {
usb_log_warning("Device did not accept Set Idle request: "
"%s.\n", str_error(rc));
return rc;
}
return EOK;
}
errno_t usbhid_req_get_report(usb_pipe_t *ctrl_pipe, int iface_no,
usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size,
size_t *actual_size)
{
if (ctrl_pipe == NULL) {
usb_log_warning("usbhid_req_set_report(): no pipe given.");
return EINVAL;
}
if (iface_no < 0) {
usb_log_warning("usbhid_req_set_report(): no interface given."
"\n");
return EINVAL;
}
errno_t rc;
uint16_t value = 0;
value |= (type << 8);
usb_log_debug("Sending Get Report request to the device.");
rc = usb_control_request_get(ctrl_pipe,
USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
USB_HIDREQ_GET_REPORT, value, iface_no, buffer, buf_size,
actual_size);
if (rc != EOK) {
usb_log_warning("Error sending Get Report request to the device: "
"%s.\n", str_error(rc));
return rc;
}
return EOK;
}
errno_t usbhid_req_get_protocol(usb_pipe_t *ctrl_pipe, int iface_no,
usb_hid_protocol_t *protocol)
{
if (ctrl_pipe == NULL) {
usb_log_warning("usbhid_req_set_report(): no pipe given.");
return EINVAL;
}
if (iface_no < 0) {
usb_log_warning("usbhid_req_set_report(): no interface given."
"\n");
return EINVAL;
}
errno_t rc;
usb_log_debug("Sending Get Protocol request to the device ("
"iface: %d).\n", iface_no);
uint8_t buffer[1];
size_t actual_size = 0;
rc = usb_control_request_get(ctrl_pipe,
USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
USB_HIDREQ_GET_PROTOCOL, 0, iface_no, buffer, 1, &actual_size);
if (rc != EOK) {
usb_log_warning("Error sending Get Protocol request to the "
"device: %s.\n", str_error(rc));
return rc;
}
if (actual_size != 1) {
usb_log_warning("Wrong data size: %zu, expected: 1.",
actual_size);
return ELIMIT;
}
*protocol = buffer[0];
return EOK;
}
errno_t usbhid_req_get_idle(usb_pipe_t *ctrl_pipe, int iface_no,
uint8_t *duration)
{
if (ctrl_pipe == NULL) {
usb_log_warning("usbhid_req_set_report(): no pipe given.");
return EINVAL;
}
if (iface_no < 0) {
usb_log_warning("usbhid_req_set_report(): no interface given."
"\n");
return EINVAL;
}
errno_t rc;
usb_log_debug("Sending Get Idle request to the device ("
"iface: %d).\n", iface_no);
uint16_t value = 0;
uint8_t buffer[1];
size_t actual_size = 0;
rc = usb_control_request_get(ctrl_pipe,
USB_REQUEST_TYPE_CLASS, USB_REQUEST_RECIPIENT_INTERFACE,
USB_HIDREQ_GET_IDLE, value, iface_no, buffer, 1,
&actual_size);
if (rc != EOK) {
usb_log_warning("Error sending Get Idle request to the device: "
"%s.\n", str_error(rc));
return rc;
}
if (actual_size != 1) {
usb_log_warning("Wrong data size: %zu, expected: 1.",
actual_size);
return ELIMIT;
}
*duration = buffer[0];
return EOK;
}
HelenOS homepage, sources at GitHub