HID: report delivery failures are discarded, so the connection gate only works on Bluetooth
Split out of the review of #1112, which added a "wait for the link" gate to the two Mouse Jiggler views. That gate is correct as far as it goes, but it sits a layer lower than the problem.
What is wrong
hid_hal_mouse_move() and its siblings are declared void and throw away a bool the HAL already returns:
applications/system/hid_app/transport_usb.c:37callsfuri_hal_hid_mouse_move(), declaredboolattargets/f7/furi_hal/furi_hal_usb_hid.c:319applications/system/hid_app/transport_ble.c:37callsble_profile_hid_mouse_move(), declaredboolatlib/ble_profile/extra_profiles/hid_profile.c:300
Same for the keyboard, consumer and scroll shims.
Because the result is discarded, every view has to reconstruct "am I connected?" from a connected field in its own view model, fed by bt_hid_connection_status_changed_callback(). That callback is only registered in hid_ble_app() (hid.c:341), so:
- The USB build gets no gate at all. In #1112 the gate is behind
#ifdef HID_TRANSPORT_BLE; on USB the local is hardcodedtrueand reports always go out. hid_send_report()fails five distinct ways that nobody can see (targets/f7/furi_hal/furi_hal_usb_hid.c:451-475): interface not configured, host not enumerated, endpoint busy (4 ms semaphore timeout), connection lost mid-send, and boot protocol.- The boot-protocol case is a total blackout. A host that issues
SET_PROTOCOL(boot)— BIOS/UEFI setup, many KVMs, some lock screens — makeshid_send_report()drop every non-keyboard report atfuri_hal_usb_hid.c:453. The USB jiggler then transmits nothing at all, for as long as that lasts, while the screen shows a highlighted "Stop". The screen the user was trying to keep awake locks anyway, and there is no log line. - The gate is inherently TOCTOU even on BLE.
connectedis copied out of the model, the link can drop before the transmit, and only the discarded return value could observe that.BtStatusConnectedalso does not imply the host has subscribed to HID input report notifications.
This affects all ~13 views with a *_set_connected_status() setter, not just the two jigglers.
Suggested fix
The shape already exists in this repo, in applications/main/bad_usb/helpers/bad_usb_hid.h:28-38, implemented for both transports:
bool (*is_connected)(void* inst);
bool (*mouse_move)(void* inst, int8_t dx, int8_t dy);So:
- Make the
hid_hal_*report senders inapplications/system/hid_app/hid.h:80-84returnbool;transport_usb.c/transport_ble.cjust stop discarding what they already get. - Add
bool hid_hal_is_connected(Hid*)— USB returnsfuri_hal_hid_is_connected()(already in the API table); BLE returns aboolstored once instruct Hidbybt_hid_connection_status_changed_callback().bad_usb_hid.c:32-35,208-212is the working precedent. - Views then gate on
hid_hal_is_connected()with no preprocessor, or react to a failed send directly. The per-viewconnectedfield stays only for drawing the BLE icon, which genuinely needs it.
That fixes all thirteen views at once, works on USB, and lets the two #ifdef HID_TRANSPORT_BLE blocks come out of the jiggler draw callbacks.
Notes
- Not a regression: #1112 narrowed the window, it did not open it. The author and I agreed to defer this rather than grow that PR.
- Worth a
FURI_LOG_Won a dropped report while in there. Neither jiggler view has a singleFURI_LOG_*today despite both definingTAG, which is why states like this turn into unreproducible reports.
Review thread this came from: https://github.com/DarkFlippers/unleashed-firmware/pull/1112#discussion_r3940652170
Source: DarkFlippers/unleashed-firmware