| 870 | |
| 871 | |
| 872 | int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length) |
| 873 | { |
| 874 | int res; |
| 875 | int report_number = data[0]; |
| 876 | int skipped_report_id = 0; |
| 877 | |
| 878 | if (report_number == 0x0) { |
| 879 | data++; |
| 880 | length--; |
| 881 | skipped_report_id = 1; |
| 882 | } |
| 883 | |
| 884 | |
| 885 | if (dev->output_endpoint <= 0) { |
| 886 | /* No interrupt out endpoint. Use the Control Endpoint */ |
| 887 | res = libusb_control_transfer(dev->device_handle, |
| 888 | LIBUSB_REQUEST_TYPE_CLASS|LIBUSB_RECIPIENT_INTERFACE|LIBUSB_ENDPOINT_OUT, |
| 889 | 0x09/*HID Set_Report*/, |
| 890 | (2/*HID output*/ << 8) | report_number, |
| 891 | dev->interface, |
| 892 | (unsigned char *)data, length, |
| 893 | 1000/*timeout millis*/); |
| 894 | |
| 895 | if (res < 0) |
| 896 | return -1; |
| 897 | |
| 898 | if (skipped_report_id) |
| 899 | length++; |
| 900 | |
| 901 | return length; |
| 902 | } |
| 903 | else { |
| 904 | /* Use the interrupt out endpoint */ |
| 905 | int actual_length; |
| 906 | res = libusb_interrupt_transfer(dev->device_handle, |
| 907 | dev->output_endpoint, |
| 908 | (unsigned char*)data, |
| 909 | length, |
| 910 | &actual_length, 1000); |
| 911 | |
| 912 | if (res < 0) |
| 913 | return -1; |
| 914 | |
| 915 | if (skipped_report_id) |
| 916 | actual_length++; |
| 917 | |
| 918 | return actual_length; |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | /* Helper function, to simplify hid_read(). |
| 923 | This should be called with dev->mutex locked. */ |
no outgoing calls
no test coverage detected