mirror of
https://github.com/ndeadly/MissionControl
synced 2025-02-17 05:38:27 +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 {
|
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_EVENT_BUFFER_SIZE = 0x400;
|
||||||
const constexpr size_t BLUETOOTH_THREAD_STACK_SIZE = 0x4000;
|
const constexpr size_t BLUETOOTH_THREAD_STACK_SIZE = 0x4000;
|
||||||
|
|
||||||
static Event btmDiscoveryEvent;
|
|
||||||
static Thread btmDiscoveryEventThread;
|
|
||||||
|
|
||||||
static Event btEvent;
|
static Event btEvent;
|
||||||
static Thread btEventThread;
|
static Thread btEventThread;
|
||||||
static uint8_t btEventBuffer[BLUETOOTH_EVENT_BUFFER_SIZE];
|
static uint8_t btEventBuffer[BLUETOOTH_EVENT_BUFFER_SIZE];
|
||||||
|
@ -68,7 +24,7 @@ namespace mc::bluetooth::core {
|
||||||
static bool discoverEnabled = false;
|
static bool discoverEnabled = false;
|
||||||
static bool pauseDiscovery = false;
|
static bool pauseDiscovery = false;
|
||||||
|
|
||||||
Result registerDevice(const BluetoothDevice *device) {
|
Result registerDevice(const BluetoothDevicesSettings *device) {
|
||||||
BtmDeviceInfo dst = {0};
|
BtmDeviceInfo dst = {0};
|
||||||
memset(&dst, 0, sizeof(BtmDeviceInfo));
|
memset(&dst, 0, sizeof(BtmDeviceInfo));
|
||||||
memcpy(&dst.address, &device->address, sizeof(BluetoothAddress));
|
memcpy(&dst.address, &device->address, sizeof(BluetoothAddress));
|
||||||
|
@ -83,7 +39,7 @@ namespace mc::bluetooth::core {
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleDeviceFoundEvent(const BluetoothEventData *eventData) {
|
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)) {
|
if (isController(&eventData->deviceFound.cod)) {
|
||||||
|
|
||||||
|
@ -105,7 +61,7 @@ namespace mc::bluetooth::core {
|
||||||
|
|
||||||
void handleDiscoveryStateChangedEvent(const BluetoothEventData *eventData) {
|
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);
|
//mutexLock(&btDiscoveryStateMutex);
|
||||||
btDiscoveryState = eventData->discoveryState.state;
|
btDiscoveryState = eventData->discoveryState.state;
|
||||||
|
@ -136,14 +92,14 @@ namespace mc::bluetooth::core {
|
||||||
/* We will apply IPS patches to enable wii(U) controllers */
|
/* We will apply IPS patches to enable wii(U) controllers */
|
||||||
BluetoothPinCode pincode = {};
|
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));
|
Result rc = btdrvRespondToPinRequest(&eventData->pinReply.address, false, &pincode, sizeof(BluetoothAddress));
|
||||||
if R_FAILED(rc)
|
if R_FAILED(rc)
|
||||||
fatalThrow(rc);
|
fatalThrow(rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleSspRequestEvent(const BluetoothEventData *eventData) {
|
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);
|
Result rc = btdrvRespondToSspRequest(&eventData->sspReply.address, eventData->sspReply.variant, true, eventData->sspReply.passkey);
|
||||||
if R_FAILED(rc)
|
if R_FAILED(rc)
|
||||||
fatalThrow(rc);
|
fatalThrow(rc);
|
||||||
|
@ -151,7 +107,7 @@ namespace mc::bluetooth::core {
|
||||||
|
|
||||||
void handleBondStateChangedEvent(const BluetoothEventData *eventData) {
|
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);
|
//mutexLock(&btBondStateMutex);
|
||||||
btBondState = hosversionBefore(9, 0, 0) ? eventData->bondState.state : eventData->bondState.v2.state;
|
btBondState = hosversionBefore(9, 0, 0) ? eventData->bondState.state : eventData->bondState.v2.state;
|
||||||
|
@ -160,19 +116,21 @@ namespace mc::bluetooth::core {
|
||||||
switch (btBondState) {
|
switch (btBondState) {
|
||||||
case BluetoothBondState_Bonded:
|
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;
|
const BluetoothAddress *address = hosversionBefore(9, 0, 0) ? &eventData->bondState.address : &eventData->bondState.v2.address;
|
||||||
|
|
||||||
/* Retrieve bonded device details */
|
/* Retrieve bonded device details */
|
||||||
BluetoothDevice device = {};
|
BluetoothDevicesSettings device = {};
|
||||||
Result rc = btdrvGetPairedDeviceInfo(address, &device);
|
Result rc = btdrvGetPairedDeviceInfo(address, &device);
|
||||||
if R_FAILED(rc)
|
if R_FAILED(rc)
|
||||||
fatalThrow(rc);
|
fatalThrow(rc);
|
||||||
|
|
||||||
/* Add device to the controller database */
|
// Add device to the controller database
|
||||||
//rc = controllerDatabase->addDevice(&device);
|
//rc = controllerDatabase->addDevice(&device);
|
||||||
|
|
||||||
/* Disconnect controller */
|
|
||||||
|
/*
|
||||||
|
// Disconnect controller
|
||||||
rc = btdrvCloseHidConnection(address);
|
rc = btdrvCloseHidConnection(address);
|
||||||
if R_FAILED(rc)
|
if R_FAILED(rc)
|
||||||
fatalThrow(rc);
|
fatalThrow(rc);
|
||||||
|
@ -185,7 +143,7 @@ namespace mc::bluetooth::core {
|
||||||
|
|
||||||
svcSleepThread(2e8);
|
svcSleepThread(2e8);
|
||||||
|
|
||||||
/* Register device with btm module */
|
// Register device with btm module
|
||||||
rc = registerDevice(&device);
|
rc = registerDevice(&device);
|
||||||
if R_FAILED(rc)
|
if R_FAILED(rc)
|
||||||
fatalThrow(rc);
|
fatalThrow(rc);
|
||||||
|
@ -196,18 +154,19 @@ namespace mc::bluetooth::core {
|
||||||
rc = btmdbgHidConnect(address);
|
rc = btmdbgHidConnect(address);
|
||||||
if R_FAILED(rc)
|
if R_FAILED(rc)
|
||||||
fatalThrow(rc);
|
fatalThrow(rc);
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BluetoothBondState_Bonding:
|
case BluetoothBondState_Bonding:
|
||||||
//mc::app::log->write("bluetooth::core: device bonding...");
|
mc::app::log->write("bluetooth::core: device bonding...");
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case BluetoothBondState_None:
|
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 */
|
/* Restart device discovery if enabled */
|
||||||
pauseDiscovery = false;
|
pauseDiscovery = false;
|
||||||
|
@ -228,18 +187,14 @@ namespace mc::bluetooth::core {
|
||||||
|
|
||||||
while (!mc::app::exitFlag) {
|
while (!mc::app::exitFlag) {
|
||||||
if (R_SUCCEEDED(eventWait(&btEvent, 1e9))) {
|
if (R_SUCCEEDED(eventWait(&btEvent, 1e9))) {
|
||||||
|
|
||||||
/* Crashes console on 10.0.0 */
|
|
||||||
|
|
||||||
/*
|
|
||||||
rc = btdrvGetEventInfo(&eventType, btEventBuffer, sizeof(btEventBuffer));
|
rc = btdrvGetEventInfo(&eventType, btEventBuffer, sizeof(btEventBuffer));
|
||||||
if R_FAILED(rc)
|
if R_FAILED(rc)
|
||||||
fatalThrow(rc);
|
fatalThrow(rc);
|
||||||
*/
|
|
||||||
|
|
||||||
//eventClear(&btEvent);
|
//eventClear(&btEvent);
|
||||||
|
|
||||||
/*
|
|
||||||
switch (eventType) {
|
switch (eventType) {
|
||||||
case BluetoothEvent_DeviceFound:
|
case BluetoothEvent_DeviceFound:
|
||||||
handleDeviceFoundEvent(eventData);
|
handleDeviceFoundEvent(eventData);
|
||||||
|
@ -264,7 +219,6 @@ namespace mc::bluetooth::core {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -297,38 +251,25 @@ namespace mc::bluetooth::core {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialise bluetooth events */
|
/* Initialise bluetooth events */
|
||||||
/* Crashes console on 10.0.0 */
|
|
||||||
rc = btdrvInitializeBluetooth(&btEvent);
|
rc = btdrvInitializeBluetooth(&btEvent);
|
||||||
if (R_FAILED(rc) )
|
if (R_FAILED(rc) )
|
||||||
fatalThrow(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);
|
rc = threadCreate(&btEventThread, bluetoothEventThreadFunc, nullptr, nullptr, BLUETOOTH_THREAD_STACK_SIZE, 0x2C, -2);
|
||||||
if (R_FAILED(rc))
|
if (R_FAILED(rc))
|
||||||
fatalThrow(rc);
|
fatalThrow(rc);
|
||||||
|
|
||||||
/*
|
|
||||||
rc = threadStart(&btEventThread);
|
rc = threadStart(&btEventThread);
|
||||||
if (R_FAILED(rc))
|
if (R_FAILED(rc))
|
||||||
fatalThrow(rc);
|
fatalThrow(rc);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Finalise(void) {
|
void Finalise(void) {
|
||||||
threadWaitForExit(&btEventThread);
|
threadWaitForExit(&btEventThread);
|
||||||
threadClose(&btEventThread);
|
threadClose(&btEventThread);
|
||||||
|
|
||||||
//threadWaitForExit(&btmDiscoveryEventThread);
|
|
||||||
//threadClose(&btmDiscoveryEventThread);
|
|
||||||
|
|
||||||
eventClose(&btEvent);
|
eventClose(&btEvent);
|
||||||
eventClose(&btmDiscoveryEvent);
|
|
||||||
|
|
||||||
/* Crashes console on 10.0.0 */
|
|
||||||
btdrvFinalizeBluetooth();
|
btdrvFinalizeBluetooth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,25 +288,26 @@ namespace mc::bluetooth::core {
|
||||||
}
|
}
|
||||||
|
|
||||||
Result StartDiscovery(void) {
|
Result StartDiscovery(void) {
|
||||||
//mc::app::log->write("bluetooth::core: starting discovery");
|
mc::app::log->write("bluetooth::core: starting discovery");
|
||||||
discoverEnabled = true;
|
discoverEnabled = true;
|
||||||
return btdrvStartInquiry();
|
return btdrvStartInquiry();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result StopDiscovery(void) {
|
Result StopDiscovery(void) {
|
||||||
//mc::app::log->write("bluetooth::core: stopping discovery");
|
mc::app::log->write("bluetooth::core: stopping discovery");
|
||||||
discoverEnabled = false;
|
discoverEnabled = false;
|
||||||
return btdrvStopInquiry();
|
return btdrvStopInquiry();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result PairDevice(const BluetoothAddress *address) {
|
Result PairDevice(const BluetoothAddress *address) {
|
||||||
//mc::app::log->write("bluetooth::core: pausing discovery");
|
mc::app::log->write("bluetooth::core: pausing discovery");
|
||||||
//mc::app::log->write("bluetooth::core: pairing device...");
|
|
||||||
pauseDiscovery = true;
|
pauseDiscovery = true;
|
||||||
Result rc = btdrvStopInquiry();
|
Result rc = btdrvStopInquiry();
|
||||||
if (R_FAILED(rc))
|
if (R_FAILED(rc))
|
||||||
fatalThrow(rc);
|
fatalThrow(rc);
|
||||||
|
|
||||||
|
mc::app::log->write("bluetooth::core: pairing device...");
|
||||||
|
mc::app::log->writeData((void *)address, sizeof(BluetoothAddress));
|
||||||
return btdrvCreateBond(address, BluetoothTransport_Auto);
|
return btdrvCreateBond(address, BluetoothTransport_Auto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,7 +316,7 @@ namespace mc::bluetooth::core {
|
||||||
}
|
}
|
||||||
|
|
||||||
Result CancelPairing(const BluetoothAddress *address) {
|
Result CancelPairing(const BluetoothAddress *address) {
|
||||||
//mc::app::log->write("bluetooth::core: cancelling pairing");
|
mc::app::log->write("bluetooth::core: cancelling pairing");
|
||||||
return btdrvCancelBond(address);
|
return btdrvCancelBond(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ void userAppInit(void) {
|
||||||
if R_FAILED(rc)
|
if R_FAILED(rc)
|
||||||
fatalThrow(rc);
|
fatalThrow(rc);
|
||||||
|
|
||||||
|
/*
|
||||||
rc = btmInitialize();
|
rc = btmInitialize();
|
||||||
if R_FAILED(rc)
|
if R_FAILED(rc)
|
||||||
fatalThrow(rc);
|
fatalThrow(rc);
|
||||||
|
@ -22,6 +23,7 @@ void userAppInit(void) {
|
||||||
rc = btmdbgInitialize();
|
rc = btmdbgInitialize();
|
||||||
if R_FAILED(rc)
|
if R_FAILED(rc)
|
||||||
fatalThrow(rc);
|
fatalThrow(rc);
|
||||||
|
*/
|
||||||
|
|
||||||
rc = splInitialize();
|
rc = splInitialize();
|
||||||
if R_FAILED(rc)
|
if R_FAILED(rc)
|
||||||
|
@ -45,8 +47,8 @@ void userAppExit(void) {
|
||||||
plExit();
|
plExit();
|
||||||
romfsExit();
|
romfsExit();
|
||||||
splExit();
|
splExit();
|
||||||
btmdbgExit();
|
//btmdbgExit();
|
||||||
btmExit();
|
//btmExit();
|
||||||
btdrvExit();
|
btdrvExit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue