mirror of
https://github.com/ndeadly/MissionControl
synced 2024-11-23 04:43:10 +00:00
applet: remove btm calls and reintroduce some logging calls
This commit is contained in:
parent
9cec1d752e
commit
b93465db41
2 changed files with 28 additions and 84 deletions
|
@ -8,53 +8,9 @@ namespace mc::bluetooth::core {
|
|||
|
||||
namespace {
|
||||
|
||||
union BluetoothEventData {
|
||||
struct {
|
||||
BluetoothName name;
|
||||
BluetoothAddress address;
|
||||
uint8_t _unk0[0x10];
|
||||
BluetoothDeviceClass cod;
|
||||
/* + more items we don't care about */
|
||||
} deviceFound;
|
||||
|
||||
struct {
|
||||
BluetoothDiscoveryState state;
|
||||
} discoveryState;
|
||||
|
||||
struct {
|
||||
BluetoothAddress address;
|
||||
BluetoothName name;
|
||||
BluetoothDeviceClass cod;
|
||||
} pinReply;
|
||||
|
||||
struct {
|
||||
BluetoothAddress address;
|
||||
BluetoothName name;
|
||||
BluetoothDeviceClass cod;
|
||||
BluetoothSspVariant variant;
|
||||
uint32_t passkey;
|
||||
} sspReply;
|
||||
|
||||
union {
|
||||
struct {
|
||||
BluetoothAddress address;
|
||||
BluetoothStatus status;
|
||||
BluetoothBondState state;
|
||||
};
|
||||
struct {
|
||||
BluetoothStatus status;
|
||||
BluetoothAddress address;
|
||||
BluetoothBondState state;
|
||||
} v2;
|
||||
} bondState;
|
||||
};
|
||||
|
||||
const constexpr size_t BLUETOOTH_EVENT_BUFFER_SIZE = 0x400;
|
||||
const constexpr size_t BLUETOOTH_THREAD_STACK_SIZE = 0x4000;
|
||||
|
||||
static Event btmDiscoveryEvent;
|
||||
static Thread btmDiscoveryEventThread;
|
||||
|
||||
static Event btEvent;
|
||||
static Thread btEventThread;
|
||||
static uint8_t btEventBuffer[BLUETOOTH_EVENT_BUFFER_SIZE];
|
||||
|
@ -68,7 +24,7 @@ namespace mc::bluetooth::core {
|
|||
static bool discoverEnabled = false;
|
||||
static bool pauseDiscovery = false;
|
||||
|
||||
Result registerDevice(const BluetoothDevice *device) {
|
||||
Result registerDevice(const BluetoothDevicesSettings *device) {
|
||||
BtmDeviceInfo dst = {0};
|
||||
memset(&dst, 0, sizeof(BtmDeviceInfo));
|
||||
memcpy(&dst.address, &device->address, sizeof(BluetoothAddress));
|
||||
|
@ -83,7 +39,7 @@ namespace mc::bluetooth::core {
|
|||
}
|
||||
|
||||
void handleDeviceFoundEvent(const BluetoothEventData *eventData) {
|
||||
//mc::app::log->write("bluetooth::core: device found");
|
||||
mc::app::log->write("bluetooth::core: device found");
|
||||
|
||||
if (isController(&eventData->deviceFound.cod)) {
|
||||
|
||||
|
@ -105,7 +61,7 @@ namespace mc::bluetooth::core {
|
|||
|
||||
void handleDiscoveryStateChangedEvent(const BluetoothEventData *eventData) {
|
||||
|
||||
//mc::app::log->write("bluetooth::core: discovery state changed: %d", eventData->discoveryState.state);
|
||||
mc::app::log->write("bluetooth::core: discovery state changed: %d", eventData->discoveryState.state);
|
||||
|
||||
//mutexLock(&btDiscoveryStateMutex);
|
||||
btDiscoveryState = eventData->discoveryState.state;
|
||||
|
@ -136,14 +92,14 @@ namespace mc::bluetooth::core {
|
|||
/* We will apply IPS patches to enable wii(U) controllers */
|
||||
BluetoothPinCode pincode = {};
|
||||
|
||||
//mc::app::log->write("bluetooth::core: sending pin reply...");
|
||||
mc::app::log->write("bluetooth::core: sending pin reply...");
|
||||
Result rc = btdrvRespondToPinRequest(&eventData->pinReply.address, false, &pincode, sizeof(BluetoothAddress));
|
||||
if R_FAILED(rc)
|
||||
fatalThrow(rc);
|
||||
}
|
||||
|
||||
void handleSspRequestEvent(const BluetoothEventData *eventData) {
|
||||
//mc::app::log->write("bluetooth::core: sending ssp reply...");
|
||||
mc::app::log->write("bluetooth::core: sending ssp reply...");
|
||||
Result rc = btdrvRespondToSspRequest(&eventData->sspReply.address, eventData->sspReply.variant, true, eventData->sspReply.passkey);
|
||||
if R_FAILED(rc)
|
||||
fatalThrow(rc);
|
||||
|
@ -151,7 +107,7 @@ namespace mc::bluetooth::core {
|
|||
|
||||
void handleBondStateChangedEvent(const BluetoothEventData *eventData) {
|
||||
|
||||
//mc::app::log->write("bluetooth::core: bond state changed: %d", eventData->bondState.state);
|
||||
mc::app::log->write("bluetooth::core: bond state changed: %d", eventData->bondState.state);
|
||||
|
||||
//mutexLock(&btBondStateMutex);
|
||||
btBondState = hosversionBefore(9, 0, 0) ? eventData->bondState.state : eventData->bondState.v2.state;
|
||||
|
@ -160,19 +116,21 @@ namespace mc::bluetooth::core {
|
|||
switch (btBondState) {
|
||||
case BluetoothBondState_Bonded:
|
||||
{
|
||||
//mc::app::log->write("bluetooth::core: device bonded");
|
||||
mc::app::log->write("bluetooth::core: device bonded");
|
||||
const BluetoothAddress *address = hosversionBefore(9, 0, 0) ? &eventData->bondState.address : &eventData->bondState.v2.address;
|
||||
|
||||
/* Retrieve bonded device details */
|
||||
BluetoothDevice device = {};
|
||||
BluetoothDevicesSettings device = {};
|
||||
Result rc = btdrvGetPairedDeviceInfo(address, &device);
|
||||
if R_FAILED(rc)
|
||||
fatalThrow(rc);
|
||||
|
||||
/* Add device to the controller database */
|
||||
// Add device to the controller database
|
||||
//rc = controllerDatabase->addDevice(&device);
|
||||
|
||||
/* Disconnect controller */
|
||||
|
||||
/*
|
||||
// Disconnect controller
|
||||
rc = btdrvCloseHidConnection(address);
|
||||
if R_FAILED(rc)
|
||||
fatalThrow(rc);
|
||||
|
@ -185,7 +143,7 @@ namespace mc::bluetooth::core {
|
|||
|
||||
svcSleepThread(2e8);
|
||||
|
||||
/* Register device with btm module */
|
||||
// Register device with btm module
|
||||
rc = registerDevice(&device);
|
||||
if R_FAILED(rc)
|
||||
fatalThrow(rc);
|
||||
|
@ -196,18 +154,19 @@ namespace mc::bluetooth::core {
|
|||
rc = btmdbgHidConnect(address);
|
||||
if R_FAILED(rc)
|
||||
fatalThrow(rc);
|
||||
*/
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case BluetoothBondState_Bonding:
|
||||
//mc::app::log->write("bluetooth::core: device bonding...");
|
||||
mc::app::log->write("bluetooth::core: device bonding...");
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
case BluetoothBondState_None:
|
||||
//mc::app::log->write("bluetooth::core: bond state none");
|
||||
mc::app::log->write("bluetooth::core: bond state none");
|
||||
{
|
||||
/* Restart device discovery if enabled */
|
||||
pauseDiscovery = false;
|
||||
|
@ -228,18 +187,14 @@ namespace mc::bluetooth::core {
|
|||
|
||||
while (!mc::app::exitFlag) {
|
||||
if (R_SUCCEEDED(eventWait(&btEvent, 1e9))) {
|
||||
|
||||
/* Crashes console on 10.0.0 */
|
||||
|
||||
/*
|
||||
|
||||
rc = btdrvGetEventInfo(&eventType, btEventBuffer, sizeof(btEventBuffer));
|
||||
if R_FAILED(rc)
|
||||
fatalThrow(rc);
|
||||
*/
|
||||
|
||||
|
||||
//eventClear(&btEvent);
|
||||
|
||||
/*
|
||||
switch (eventType) {
|
||||
case BluetoothEvent_DeviceFound:
|
||||
handleDeviceFoundEvent(eventData);
|
||||
|
@ -264,7 +219,6 @@ namespace mc::bluetooth::core {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -297,38 +251,25 @@ namespace mc::bluetooth::core {
|
|||
}
|
||||
|
||||
/* Initialise bluetooth events */
|
||||
/* Crashes console on 10.0.0 */
|
||||
rc = btdrvInitializeBluetooth(&btEvent);
|
||||
if (R_FAILED(rc) )
|
||||
fatalThrow(rc);
|
||||
|
||||
u8 flags;
|
||||
rc = btmdbgAcquireDiscoveryEvent(&btmDiscoveryEvent, &flags);
|
||||
if (R_FAILED(rc))
|
||||
fatalThrow(rc);
|
||||
|
||||
rc = threadCreate(&btEventThread, bluetoothEventThreadFunc, nullptr, nullptr, BLUETOOTH_THREAD_STACK_SIZE, 0x2C, -2);
|
||||
if (R_FAILED(rc))
|
||||
fatalThrow(rc);
|
||||
|
||||
/*
|
||||
rc = threadStart(&btEventThread);
|
||||
if (R_FAILED(rc))
|
||||
fatalThrow(rc);
|
||||
*/
|
||||
}
|
||||
|
||||
void Finalise(void) {
|
||||
threadWaitForExit(&btEventThread);
|
||||
threadClose(&btEventThread);
|
||||
|
||||
//threadWaitForExit(&btmDiscoveryEventThread);
|
||||
//threadClose(&btmDiscoveryEventThread);
|
||||
|
||||
eventClose(&btEvent);
|
||||
eventClose(&btmDiscoveryEvent);
|
||||
|
||||
/* Crashes console on 10.0.0 */
|
||||
btdrvFinalizeBluetooth();
|
||||
}
|
||||
|
||||
|
@ -347,25 +288,26 @@ namespace mc::bluetooth::core {
|
|||
}
|
||||
|
||||
Result StartDiscovery(void) {
|
||||
//mc::app::log->write("bluetooth::core: starting discovery");
|
||||
mc::app::log->write("bluetooth::core: starting discovery");
|
||||
discoverEnabled = true;
|
||||
return btdrvStartInquiry();
|
||||
}
|
||||
|
||||
Result StopDiscovery(void) {
|
||||
//mc::app::log->write("bluetooth::core: stopping discovery");
|
||||
mc::app::log->write("bluetooth::core: stopping discovery");
|
||||
discoverEnabled = false;
|
||||
return btdrvStopInquiry();
|
||||
}
|
||||
|
||||
Result PairDevice(const BluetoothAddress *address) {
|
||||
//mc::app::log->write("bluetooth::core: pausing discovery");
|
||||
//mc::app::log->write("bluetooth::core: pairing device...");
|
||||
mc::app::log->write("bluetooth::core: pausing discovery");
|
||||
pauseDiscovery = true;
|
||||
Result rc = btdrvStopInquiry();
|
||||
if (R_FAILED(rc))
|
||||
fatalThrow(rc);
|
||||
|
||||
mc::app::log->write("bluetooth::core: pairing device...");
|
||||
mc::app::log->writeData((void *)address, sizeof(BluetoothAddress));
|
||||
return btdrvCreateBond(address, BluetoothTransport_Auto);
|
||||
}
|
||||
|
||||
|
@ -374,7 +316,7 @@ namespace mc::bluetooth::core {
|
|||
}
|
||||
|
||||
Result CancelPairing(const BluetoothAddress *address) {
|
||||
//mc::app::log->write("bluetooth::core: cancelling pairing");
|
||||
mc::app::log->write("bluetooth::core: cancelling pairing");
|
||||
return btdrvCancelBond(address);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ void userAppInit(void) {
|
|||
if R_FAILED(rc)
|
||||
fatalThrow(rc);
|
||||
|
||||
/*
|
||||
rc = btmInitialize();
|
||||
if R_FAILED(rc)
|
||||
fatalThrow(rc);
|
||||
|
@ -22,6 +23,7 @@ void userAppInit(void) {
|
|||
rc = btmdbgInitialize();
|
||||
if R_FAILED(rc)
|
||||
fatalThrow(rc);
|
||||
*/
|
||||
|
||||
rc = splInitialize();
|
||||
if R_FAILED(rc)
|
||||
|
@ -45,8 +47,8 @@ void userAppExit(void) {
|
|||
plExit();
|
||||
romfsExit();
|
||||
splExit();
|
||||
btmdbgExit();
|
||||
btmExit();
|
||||
//btmdbgExit();
|
||||
//btmExit();
|
||||
btdrvExit();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue