Skip to content

Commit

Permalink
Fix wrong reportID usage
Browse files Browse the repository at this point in the history
- Fix the usage of reportIDs, before one the reportID one was checked if reportIDs were used
- Show the reportID of the found device
  • Loading branch information
RockyZeroFour committed Apr 11, 2024
1 parent 4370c00 commit 097e212
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/gfx_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ void gfx_set_byte_offsets_text(void)
uint8_t interface = xlat_get_found_interface();

if (button->found && x->found && y->found && XLAT_MODE_KEY != xlat_get_mode()) {
sprintf(text, "Mouse Data (#%d): click@%d motion@%d,%d", interface, button->byte_offset, x->byte_offset, y->byte_offset);
sprintf(text, "Mouse Data (#%d): id@%d click@%d motion@%d,%d", interface, xlat_get_reportid(), button->byte_offset, x->byte_offset, y->byte_offset);
} else if (key->found && XLAT_MODE_KEY == xlat_get_mode()) {
sprintf(text, "Keyboard Data (#%d): pressed@%d", interface, key->byte_offset);
sprintf(text, "Keyboard Data (#%d): id@%d pressed@%d", interface, xlat_get_reportid(), key->byte_offset);
} else {
// offsets not found
sprintf(text, "Data: offsets not found");
Expand Down
37 changes: 22 additions & 15 deletions src/xlat.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static volatile uint_fast8_t gpio_irq_consumer = 0;
// SETTINGS
volatile bool xlat_initialized = false;
static xlat_mode_t xlat_mode = XLAT_MODE_CLICK;
static bool hid_using_reportid = false;
static uint8_t hid_reportid = 0;
static bool auto_trigger_level_high = false;
static xlat_interface_t xlat_interface = XLAT_INTERFACE_AUTO;
static uint8_t found_interface = 0xFF;
Expand Down Expand Up @@ -169,6 +169,8 @@ static void hidreport_check_item(HID_ReportItem_t *item)
x_location.found = true;
x_location.bit_index = item->BitOffset;
x_location.bit_size = item->Attributes.BitSize;

hid_reportid = item->ReportID;
}
break;

Expand All @@ -178,6 +180,8 @@ static void hidreport_check_item(HID_ReportItem_t *item)
y_location.found = true;
y_location.bit_index = item->BitOffset;
y_location.bit_size = item->Attributes.BitSize;

hid_reportid = item->ReportID;
}
break;
}
Expand All @@ -188,6 +192,8 @@ static void hidreport_check_item(HID_ReportItem_t *item)
if (!key_location.found) {
key_location.found = true;
key_location.bit_index = item->BitOffset;

hid_reportid = item->ReportID;
}
break;

Expand All @@ -196,6 +202,8 @@ static void hidreport_check_item(HID_ReportItem_t *item)
if (!button_location.found) {
button_location.found = true;
button_location.bit_index = item->BitOffset;

hid_reportid = item->ReportID;
}
break;

Expand Down Expand Up @@ -268,8 +276,8 @@ static void check_offsets(void)
{
printf("\n");

if (hid_using_reportid) {
printf("[*] Using reportId, so actual report data is starting at index [1]\n");
if (hid_reportid) {
printf("[*] Using reportId '%d', so actual report data is starting at index [1]\n", hid_reportid);
}

// Only print offsets relevant for a mouse
Expand All @@ -280,7 +288,7 @@ static void check_offsets(void)
printf("[!] Button found at bit index %d, which is not a multiple of 8. Currently not supported by XLAT.\n", button_location.bit_index);
button_location.found = false;
} else {
button_location.byte_offset = button_location.bit_index / 8 + (size_t)hid_using_reportid;
button_location.byte_offset = button_location.bit_index / 8 + (hid_reportid ? 1 : 0);
printf("[*] Button found at bit index %d, which is byte %d\n", button_location.bit_index, button_location.bit_index / 8);
printf(" Button byte offset: %d\n", button_location.byte_offset);
}
Expand All @@ -295,7 +303,7 @@ static void check_offsets(void)
printf("[!] X found at bit index %d, which is not a multiple of 8. Currently not supported by XLAT.\n", x_location.bit_index);
x_location.found = false;
} else {
x_location.byte_offset = x_location.bit_index / 8 + (size_t)hid_using_reportid;
x_location.byte_offset = x_location.bit_index / 8 + (hid_reportid ? 1 : 0);
printf("[*] X found at bit index %d, which is byte %d\n", x_location.bit_index, x_location.bit_index / 8);
printf(" X size: %d bits, %d bytes\n", x_location.bit_size, x_location.bit_size / 8);
printf(" X byte offset: %d\n", x_location.byte_offset);
Expand All @@ -315,7 +323,7 @@ static void check_offsets(void)
y_location.bit_index);
y_location.found = false;
} else {
y_location.byte_offset = y_location.bit_index / 8 + (size_t)hid_using_reportid;
y_location.byte_offset = y_location.bit_index / 8 + (hid_reportid ? 1 : 0);
printf("[*] Y found at bit index %d, which is byte %d\n", y_location.bit_index, y_location.bit_index / 8);
printf(" Y size: %d bits, %d bytes\n", y_location.bit_size, y_location.bit_size / 8);
printf(" Y byte offset: %d\n", y_location.byte_offset);
Expand All @@ -333,7 +341,7 @@ static void check_offsets(void)
printf("[!] Key found at bit index %d, which is not a multiple of 8. Currently not supported by XLAT.\n", key_location.bit_index);
key_location.found = false;
} else {
key_location.byte_offset = key_location.bit_index / 8 + (size_t)hid_using_reportid;
key_location.byte_offset = key_location.bit_index / 8 + (hid_reportid ? 1 : 0);
printf("[*] Key found at bit index %d, which is byte %d\n", key_location.bit_index, key_location.bit_index / 8);
printf(" Key byte offset: %d\n", key_location.byte_offset);
}
Expand Down Expand Up @@ -388,7 +396,7 @@ void xlat_usb_hid_event(void)

if (USBH_HID_GetRawData(phost, hid_raw_data) == USBH_OK) {
// check reportId for ULX
if (hid_using_reportid && (hid_raw_data[0] != 0x01)) {
if (hid_reportid && (hid_raw_data[0] != hid_reportid)) {
// ignore
goto out;
}
Expand Down Expand Up @@ -470,7 +478,7 @@ void xlat_usb_hid_event(void)

if (USBH_HID_GetRawData(phost, hid_raw_data) == USBH_OK) {
// check reportId for ULX
if (hid_using_reportid && (hid_raw_data[0] != 0x01)) {
if (hid_reportid && (hid_raw_data[0] != hid_reportid)) {
// ignore
goto out;
}
Expand Down Expand Up @@ -644,14 +652,14 @@ void xlat_reset_latency(void)
}
}

void xlat_set_using_reportid(bool use_reportid)
void xlat_set_reportid(uint8_t reportid)
{
hid_using_reportid = use_reportid;
hid_reportid = reportid;
}

bool xlat_get_using_reportid(void)
uint8_t xlat_get_reportid(void)
{
return hid_using_reportid;
return hid_reportid;
}

static void xlat_timer_callback(TimerHandle_t xTimer)
Expand Down Expand Up @@ -738,8 +746,7 @@ void xlat_parse_hid_descriptor(uint8_t *desc, size_t desc_size)
}

// Check if using reportIDs:
hid_using_reportid = report_info.UsingReportIDs;
printf("Using reportIDs: %d\n", hid_using_reportid);
printf("Using reportIDs: %d\n", report_info.UsingReportIDs);

// Find click and motion data offsets
check_offsets();
Expand Down
4 changes: 2 additions & 2 deletions src/xlat.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ uint32_t xlat_get_last_usb_timestamp_us(void);
uint32_t xlat_get_last_button_timestamp_us(void);


void xlat_set_using_reportid(bool use_reportid);
bool xlat_get_using_reportid(void);
void xlat_set_reportid(uint8_t reportid);
uint8_t xlat_get_reportid(void);

void xlat_parse_hid_descriptor(uint8_t *desc, size_t desc_size);

Expand Down

0 comments on commit 097e212

Please sign in to comment.