Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS: send report id conditionally for hid_get_feature_report #70

Merged
merged 2 commits into from
Sep 24, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 46 additions & 38 deletions mac/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -763,38 +763,61 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)

static int set_report(hid_device *dev, IOHIDReportType type, const unsigned char *data, size_t length)
{
const unsigned char *data_to_send;
size_t length_to_send;
const unsigned char *data_to_send = data;
CFIndex length_to_send = length;
IOReturn res;
const unsigned char report_id = data[0];

/* Return if the device has been disconnected. */
if (dev->disconnected)
return -1;

if (data[0] == 0x0) {
if (report_id == 0x0) {
/* Not using numbered Reports.
Don't send the report number. */
data_to_send = data+1;
length_to_send = length-1;
}
else {
/* Using numbered Reports.
Send the Report Number */
data_to_send = data;
length_to_send = length;

/* Avoid crash if the device has been unplugged. */
if (dev->disconnected) {
return -1;
}

if (!dev->disconnected) {
res = IOHIDDeviceSetReport(dev->device_handle,
type,
data[0], /* Report ID*/
data_to_send, length_to_send);
res = IOHIDDeviceSetReport(dev->device_handle,
type,
report_id,
data_to_send, length_to_send);

if (res == kIOReturnSuccess) {
return length;
}
else
return -1;
if (res == kIOReturnSuccess) {
return length;
}

return -1;
}

static int get_report(hid_device *dev, IOHIDReportType type, unsigned char *data, size_t length)
{
unsigned char *report = data;
CFIndex report_length = length;
IOReturn res = kIOReturnSuccess;
const unsigned char report_id = data[0];

if (report_id == 0x0) {
/* Not using numbered Reports.
Don't send the report number. */
report = data+1;
report_length = length-1;
}

/* Avoid crash if the device has been unplugged. */
if (dev->disconnected) {
return -1;
}

res = IOHIDDeviceGetReport(dev->device_handle,
type,
report_id,
report, &report_length);

if (res == kIOReturnSuccess) {
return length;
}

return -1;
Expand Down Expand Up @@ -954,24 +977,9 @@ int HID_API_EXPORT hid_send_feature_report(hid_device *dev, const unsigned char

int HID_API_EXPORT hid_get_feature_report(hid_device *dev, unsigned char *data, size_t length)
{
CFIndex len = length - 1;
IOReturn res;

/* Return if the device has been unplugged. */
if (dev->disconnected)
return -1;

res = IOHIDDeviceGetReport(dev->device_handle,
kIOHIDReportTypeFeature,
data[0], /* Report ID */
data + 1, &len);
if (res == kIOReturnSuccess)
return len + 1;
else
return -1;
return get_report(dev, kIOHIDReportTypeFeature, data, length);
}


void HID_API_EXPORT hid_close(hid_device *dev)
{
if (!dev)
Expand Down