Change Bluetooth device discovery on Linux to use LIAC

This changes Bluetooth device discovery on Linux to use LIAC (Limited
Dedicated Inquiry Access Code) since third-party Wiimotes (such as Rock
Candy Wiimotes) are not discovered without it.

Also added accessor function in IONix class to help with checking if
the discovered Wiimote has already been found.

[leoetlino: code review suggested changes, remove unused variable,
commit message formatting fixes, and build fix]
This commit is contained in:
Bryan Grim 2015-12-09 01:04:24 -08:00 committed by Léo Lam
parent 8a1bbaa563
commit 92c572a83d
1 changed files with 19 additions and 9 deletions

View File

@ -12,7 +12,6 @@
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Core/HW/WiimoteEmu/WiimoteHid.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h"
namespace WiimoteReal
@ -22,6 +21,7 @@ class WiimoteLinux final : public Wiimote
public:
WiimoteLinux(bdaddr_t bdaddr);
~WiimoteLinux() override;
const bdaddr_t& Address() const;
protected:
bool ConnectInternal() override;
@ -82,10 +82,13 @@ void WiimoteScanner::FindWiimotes(std::vector<Wiimote*>& found_wiimotes, Wiimote
inquiry_info scan_infos[max_infos] = {};
auto* scan_infos_ptr = scan_infos;
found_board = nullptr;
// Use Limited Dedicated Inquiry Access Code (LIAC) to query, since third-party Wiimotes
// cannot be discovered without it.
const u8 lap[3] = {0x00, 0x8b, 0x9e};
// Scan for Bluetooth devices
int const found_devices =
hci_inquiry(device_id, wait_len, max_infos, nullptr, &scan_infos_ptr, IREQ_CACHE_FLUSH);
hci_inquiry(device_id, wait_len, max_infos, lap, &scan_infos_ptr, IREQ_CACHE_FLUSH);
if (found_devices < 0)
{
ERROR_LOG(WIIMOTE, "Error searching for Bluetooth devices.");
@ -112,14 +115,16 @@ void WiimoteScanner::FindWiimotes(std::vector<Wiimote*>& found_wiimotes, Wiimote
{
bool new_wiimote = true;
// TODO: do this
// Determine if this Wiimote has already been found.
// for (int j = 0; j < MAX_WIIMOTES && new_wiimote; ++j)
//{
// if (wm[j] && bacmp(&scan_infos[i].bdaddr,&wm[j]->bdaddr) == 0)
// new_wiimote = false;
//}
for (int j = 0; j < MAX_BBMOTES && new_wiimote; ++j)
{
// compare this address with the stored addresses in our global array
// static_cast is OK here, since we're only ever going to have this subclass in g_wiimotes
// on Linux (and likewise, only WiimoteWindows on Windows, etc)
auto connected_wiimote = static_cast<WiimoteLinux*>(g_wiimotes[j]);
if (connected_wiimote && bacmp(&scan_infos[i].bdaddr, &connected_wiimote->Address()) == 0)
new_wiimote = false;
}
if (new_wiimote)
{
@ -165,6 +170,11 @@ WiimoteLinux::~WiimoteLinux()
close(m_wakeup_pipe_r);
}
const bdaddr_t& WiimoteLinux::Address() const
{
return m_bdaddr;
}
// Connect to a Wiimote with a known address.
bool WiimoteLinux::ConnectInternal()
{