Commit Graph
26 Commits
Author SHA1 Message Date
LibretroAdmin 2ec3607c97 Bluetooth (Windows): show a pairing's progress on screen
Selecting a device showed nothing: whether it paired went only to the
log. A pairing now says on screen when it starts and whether it worked,
and a Wii controller that could not be paired gets a reminder to press
its sync button and select it again while its lights blink.
2026-10-24 04:08:45 +02:00
LibretroAdmin f448ad267d Bluetooth: a scan holds the driver, so quitting during one cannot crash
The scan task calls the driver from the task thread while the frontend
can stop the driver from its own, so quitting during a scan freed the
driver under the task, which then ended the scan on freed memory and
corrupted the heap.

The driver started is now held by a count: the frontend's hold, and one
taken for each scan, on the frontend's thread, when the scan task is
pushed. Stopping the driver lets go of the frontend's; whichever lets go
last frees it, so a scan running finishes on a live driver. No lock and
nothing waited for.
2026-10-24 04:08:42 +02:00
LibretroAdmin fc62101469 Bluetooth (Windows): answer a Wii controller's PIN, and never hang on quit
Windows asked the user for a Wii controller's PIN, which is the radio's
own address in binary and cannot be typed. The driver now registers for
the device's authentication and answers its PIN request itself, falling
back to the older call without Vista's functions. A device whose name
the search had not heard yet is looked up again before pairing, so a
Wii controller is not taken for another device.

Quitting while a pairing waited on Windows hung, as the driver joined
its thread. A thread still running is now let go, and the last of it
and the driver to finish frees the driver.
2026-10-24 02:42:28 +02:00
LibretroAdmin 0ab9c5a6c6 Bluetooth: say when the adapter is on Windows' generic driver
Windows can run a Bluetooth adapter on its own generic driver, which
often finds no classic device at all - no phone, no Wii controller -
and says nothing of it: its own pairing screen is as empty. When a
scan finds nothing, the Windows driver looks whether the adapter's
driver is bth.inf, Windows' own, and the list's "No Bluetooth Devices
Found" then says so and what to install; the log says it too. A
driver can tell this through a new, optional call.
2026-10-22 09:26:36 +02:00
LibretroAdmin f78d9b9850 Bluetooth: Scan for Devices in the list, and a scan ends when it is done
The Bluetooth list had no way to look again short of leaving it and
coming back. It now ends with Scan for Devices, below the devices so
their places stay the driver's numbers for them.

A scan waited out its whole ten-second window whatever the driver was
doing. A driver can now say it has found all it will, and the scan
task, parked meanwhile and looking every 100 ms, ends then. The
Windows driver says so when its search returns, and searches for
about five seconds instead of eight: a controller in pairing mode
answers within the first. It also lists a device that has not said
its name yet, by its address, and logs a search that found nothing.
2026-10-22 07:34:56 +02:00
LibretroAdmin 2fb661c361 menu: the Bluetooth list is never left empty
A scan that found nothing cleared the list and put nothing back, and
a list with nothing in it cannot be left with Back. It now says no
devices were found, as the list does before a scan; the Windows
driver also logs how many a scan found.
2026-10-22 07:17:26 +02:00
LibretroAdmin ba03395b8a Bluetooth: a Windows driver, which pairs Wii controllers too
Windows' settings often cannot pair a Wii remote or a Wii U Pro
Controller. A Bluetooth driver on Windows' own stack, through
bthprops.cpl loaded when it starts, gives the menu's Bluetooth list:
a scan finds the devices in pairing mode, and picking one pairs it.
A Wii controller is paired as Dolphin pairs one whose sync button was
pressed - the radio's address its PIN, after a pairing Windows
remembers but cannot reach is forgotten - and its HID service is
turned on, so Windows makes it a HID device the hid joypad driver
finds. Searching and pairing block for seconds, so each runs on a
thread of the driver's.

Windows builds have Bluetooth by default. The list now scans again
each time it is opened, showing the last scan's devices meanwhile, so
a pad put in pairing mode since is found; and the scan task is
declared without networking.
2026-10-22 07:08:00 +02:00
Acts1631 f20adf39f8 bluetoothctl: validate addresses from device listings (#19651)
A nearby Bluetooth name can contain a newline that forges a line in
bluetoothctl devices output. The next status check or a connect action
used the forged line's second token in a popen() command, allowing
shell commands to run as the RetroArch user.

Accept only lines with a valid Bluetooth address, use that address
for status, connect, and remove commands, and cap the list to the
fixed status arrays.
2026-10-01 05:19:08 +02:00
LibretroAdmin 50cf4c28ed bluetooth: scan in two steps instead of holding the task thread for ten seconds
A Bluetooth scan ran inside one task handler call, and both drivers
waited out the ten-second discovery window in it: bluez in a
retro_sleep(10000) between StartDiscovery and StopDiscovery,
bluetoothctl in a pclose() of "bluetoothctl --timeout 10 scan on".
That is the task queue's one worker thread, so for the whole window
every other task - downloads, thumbnails, cloud sync - sat queued
behind the scan.

The driver interface's scan() becomes scan_begin() and scan_end(),
BLUETOOTH_SCAN_WINDOW_US apart. The scan task calls begin, sets its own
'when' to the end of the window and returns unfinished; the task queue
keeps scheduled tasks behind ready ones, so everything else runs in the
meantime, and the task comes back at the end of the window to call end
and finish. A cancel ends the window early.

- bluez: begin powers the adapter and starts discovery on a connection
  it keeps open - BlueZ ends a client's discovery when its connection
  goes - and end stops discovery, reads the devices and disconnects.
  A begin that failed part way leaves end only disconnecting. The
  driver's free() now releases a connection a scan still holds, and
  the device list, which it leaked.
- bluetoothctl: begin starts "scan on" with popen() and returns; end
  pcloses it, which by the end of the window has already exited, then
  lists the devices as before. free() closes a scan still running.

samples/tasks/bluetooth_scan runs the scan task on the real threaded
task queue against stand-in driver calls, with the window shortened to
300 ms. It pins that begin and end run once each a window apart, that
another task pushed during the window runs within 100 ms, and that the
scan's callback fires. Clean under ASan, UBSan and TSan; added to the
samples/tasks job.
2026-09-18 16:32:26 +02:00
Tomáš Kelemen cd85a4dbf2 bluetoothctl: use two calls to disconnect/remove device (#17593)
the previous method does not remove the pairing of the selected device,
user must remove the pairing manually by modifying filesystem.

change tested on real system (Lakka-RPi4.aarch64).
2025-02-18 17:11:36 +01:00
LibretroAdmin 047e04ed3e Standardize local len variable naming conventions 2025-01-15 15:00:12 +01:00
LibretroAdmin 18c85b5ccd Cleanups -
* Less string copies
* Some general cleanups
* Add extra param to runloop_message_queue_push so we can pass size_t
of the message
* Consistent conventions for local variable usage for certain things
2024-12-27 15:13:45 +01:00
libretroadmin 82e4504968 Revert "(pt. 2) static variables are initialized to '0' automatically as per C rules"
This reverts commit 47410df7a3.
2024-11-19 03:03:05 +01:00
libretroadmin 47410df7a3 (pt. 2) static variables are initialized to '0' automatically as per C rules 2024-11-18 15:59:46 +01:00
Tomáš Kelemen b2b2425203 bluetoothctl: add / modify pairing steps (#13818)
due to some changes in bluez / bluetoothctl, `pairable on` is required
in order to create a `[LinkKey]` section in the configuration file for
the connected device. if this section is missing, the device / gamepad
will not pair after being disconnect and has to be repaired again.
2022-04-03 19:29:03 +02:00
Autechre 5f49899343 Bluetooth refactor (#13266)
* Use HAVE_BLUETOOTH ifdef to strip out this code when not defined

* Split up bluetooth code into its own file
2021-11-21 20:44:08 +01:00
Tomáš Kelemen (vudiq) a2f9273979 Bluetooth: add option to remove pairing
Pressing the START button removes the device pairing. Useful in case
the device (e.g. gamepad) was paired with a different adapter/computer
and needs to be paired again with current adapter/computer.

To pair again, RetroArch needs to be restarted, so the device list is
populated again.

Upstream of patch used by Lakka at build time
https://github.com/libretro/Lakka-LibreELEC/blob/1943ad296eaf7c01040f02aa8f5dff3d2f37309f/packages/libretro/retroarch/patches/retroarch-98-remove_bluetooth_pairing.patch
2021-11-17 22:15:35 +01:00
twinaphex 2d5e090eb3 Move driver code to driver.c file - move code outside of retroarch.c 2021-11-12 04:45:09 +01:00
twinaphex b4be553ccc (bluetooth) Cleanups 2020-06-29 00:25:37 +02:00
parport0 f668ed063e (bluetooth drivers) Move driver info to userdata, clean up API 2020-06-28 23:08:58 +03:00
Autechre b57e6e76c2 Revert "Bluetooth fixes" 2020-06-28 19:40:37 +02:00
parport0 9e3dd965eb (bluetooth) Move driver info to userdata, clean up API 2020-06-28 15:58:01 +03:00
twinaphex 724a9a393e (bluetooth drivers) Cleanups and add TODO/FIXME notes 2020-06-27 19:46:27 +02:00
parport0 a24d2b50a5 bluetooth: split into labels and sublabels 2020-06-24 12:53:27 +03:00
parport0 4f8ccb8642 Add bluez bluetooth driver 2020-06-24 12:53:27 +03:00
parport0 23c08ad9b0 Add bluetoothctl bluetooth driver 2020-06-24 12:53:27 +03:00