2022-04-23 04:59:50 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-07-28 20:59:09 -04:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2018-07-28 21:08:08 -04:00
|
|
|
#include "common/logging/log.h"
|
2020-11-08 15:49:45 -05:00
|
|
|
#include "core/core.h"
|
2018-07-28 21:08:08 -04:00
|
|
|
#include "core/hle/ipc_helpers.h"
|
2021-01-31 04:38:57 -05:00
|
|
|
#include "core/hle/kernel/k_event.h"
|
2018-07-28 20:59:09 -04:00
|
|
|
#include "core/hle/service/btm/btm.h"
|
2021-09-28 23:42:50 -04:00
|
|
|
#include "core/hle/service/kernel_helpers.h"
|
2018-07-28 20:59:09 -04:00
|
|
|
#include "core/hle/service/service.h"
|
|
|
|
|
|
|
|
namespace Service::BTM {
|
|
|
|
|
2018-11-16 09:42:17 -05:00
|
|
|
class IBtmUserCore final : public ServiceFramework<IBtmUserCore> {
|
|
|
|
public:
|
2021-04-04 03:56:09 -04:00
|
|
|
explicit IBtmUserCore(Core::System& system_)
|
2021-09-28 23:42:50 -04:00
|
|
|
: ServiceFramework{system_, "IBtmUserCore"}, service_context{system_, "IBtmUserCore"} {
|
2018-11-16 09:42:17 -05:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2019-01-29 21:47:25 -05:00
|
|
|
{0, &IBtmUserCore::AcquireBleScanEvent, "AcquireBleScanEvent"},
|
|
|
|
{1, nullptr, "GetBleScanFilterParameter"},
|
|
|
|
{2, nullptr, "GetBleScanFilterParameter2"},
|
|
|
|
{3, nullptr, "StartBleScanForGeneral"},
|
|
|
|
{4, nullptr, "StopBleScanForGeneral"},
|
|
|
|
{5, nullptr, "GetBleScanResultsForGeneral"},
|
|
|
|
{6, nullptr, "StartBleScanForPaired"},
|
|
|
|
{7, nullptr, "StopBleScanForPaired"},
|
|
|
|
{8, nullptr, "StartBleScanForSmartDevice"},
|
|
|
|
{9, nullptr, "StopBleScanForSmartDevice"},
|
|
|
|
{10, nullptr, "GetBleScanResultsForSmartDevice"},
|
|
|
|
{17, &IBtmUserCore::AcquireBleConnectionEvent, "AcquireBleConnectionEvent"},
|
|
|
|
{18, nullptr, "BleConnect"},
|
|
|
|
{19, nullptr, "BleDisconnect"},
|
|
|
|
{20, nullptr, "BleGetConnectionState"},
|
|
|
|
{21, nullptr, "AcquireBlePairingEvent"},
|
|
|
|
{22, nullptr, "BlePairDevice"},
|
|
|
|
{23, nullptr, "BleUnPairDevice"},
|
|
|
|
{24, nullptr, "BleUnPairDevice2"},
|
|
|
|
{25, nullptr, "BleGetPairedDevices"},
|
|
|
|
{26, &IBtmUserCore::AcquireBleServiceDiscoveryEvent, "AcquireBleServiceDiscoveryEvent"},
|
|
|
|
{27, nullptr, "GetGattServices"},
|
|
|
|
{28, nullptr, "GetGattService"},
|
|
|
|
{29, nullptr, "GetGattIncludedServices"},
|
|
|
|
{30, nullptr, "GetBelongingGattService"},
|
|
|
|
{31, nullptr, "GetGattCharacteristics"},
|
|
|
|
{32, nullptr, "GetGattDescriptors"},
|
|
|
|
{33, &IBtmUserCore::AcquireBleMtuConfigEvent, "AcquireBleMtuConfigEvent"},
|
|
|
|
{34, nullptr, "ConfigureBleMtu"},
|
|
|
|
{35, nullptr, "GetBleMtu"},
|
|
|
|
{36, nullptr, "RegisterBleGattDataPath"},
|
|
|
|
{37, nullptr, "UnregisterBleGattDataPath"},
|
2018-11-16 09:42:17 -05:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
RegisterHandlers(functions);
|
2018-11-26 18:34:07 -05:00
|
|
|
|
2021-09-28 23:42:50 -04:00
|
|
|
scan_event = service_context.CreateEvent("IBtmUserCore:ScanEvent");
|
|
|
|
connection_event = service_context.CreateEvent("IBtmUserCore:ConnectionEvent");
|
|
|
|
service_discovery_event = service_context.CreateEvent("IBtmUserCore:DiscoveryEvent");
|
|
|
|
config_event = service_context.CreateEvent("IBtmUserCore:ConfigEvent");
|
|
|
|
}
|
2021-04-09 19:56:11 -04:00
|
|
|
|
2021-09-28 23:42:50 -04:00
|
|
|
~IBtmUserCore() override {
|
|
|
|
service_context.CloseEvent(scan_event);
|
|
|
|
service_context.CloseEvent(connection_event);
|
|
|
|
service_context.CloseEvent(service_discovery_event);
|
|
|
|
service_context.CloseEvent(config_event);
|
2018-11-16 09:42:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-01-29 21:47:25 -05:00
|
|
|
void AcquireBleScanEvent(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_WARNING(Service_BTM, "(STUBBED) called");
|
|
|
|
|
2018-11-16 09:42:17 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-09-28 23:42:50 -04:00
|
|
|
rb.PushCopyObjects(scan_event->GetReadableEvent());
|
2018-11-16 09:42:17 -05:00
|
|
|
}
|
2018-11-27 09:18:29 -05:00
|
|
|
|
2019-01-29 21:47:25 -05:00
|
|
|
void AcquireBleConnectionEvent(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_WARNING(Service_BTM, "(STUBBED) called");
|
|
|
|
|
2018-11-16 09:42:17 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-09-28 23:42:50 -04:00
|
|
|
rb.PushCopyObjects(connection_event->GetReadableEvent());
|
2018-11-16 09:42:17 -05:00
|
|
|
}
|
2018-11-27 09:18:29 -05:00
|
|
|
|
2019-01-29 21:47:25 -05:00
|
|
|
void AcquireBleServiceDiscoveryEvent(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_WARNING(Service_BTM, "(STUBBED) called");
|
|
|
|
|
2018-11-16 09:42:17 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-09-28 23:42:50 -04:00
|
|
|
rb.PushCopyObjects(service_discovery_event->GetReadableEvent());
|
2018-11-16 09:42:17 -05:00
|
|
|
}
|
2018-11-27 09:18:29 -05:00
|
|
|
|
2019-01-29 21:47:25 -05:00
|
|
|
void AcquireBleMtuConfigEvent(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_WARNING(Service_BTM, "(STUBBED) called");
|
|
|
|
|
2018-11-16 09:42:17 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 1};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2021-09-28 23:42:50 -04:00
|
|
|
rb.PushCopyObjects(config_event->GetReadableEvent());
|
2018-11-16 09:42:17 -05:00
|
|
|
}
|
2018-11-26 18:34:07 -05:00
|
|
|
|
2021-09-28 23:42:50 -04:00
|
|
|
KernelHelpers::ServiceContext service_context;
|
|
|
|
|
|
|
|
Kernel::KEvent* scan_event;
|
|
|
|
Kernel::KEvent* connection_event;
|
|
|
|
Kernel::KEvent* service_discovery_event;
|
|
|
|
Kernel::KEvent* config_event;
|
2018-11-16 09:42:17 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
class BTM_USR final : public ServiceFramework<BTM_USR> {
|
|
|
|
public:
|
2020-11-26 15:19:08 -05:00
|
|
|
explicit BTM_USR(Core::System& system_) : ServiceFramework{system_, "btm:u"} {
|
2018-11-16 09:42:17 -05:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2019-01-29 21:47:25 -05:00
|
|
|
{0, &BTM_USR::GetCore, "GetCore"},
|
2018-11-16 09:42:17 -05:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-01-29 21:47:25 -05:00
|
|
|
void GetCore(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_BTM, "called");
|
|
|
|
|
2018-11-16 09:42:17 -05:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2019-09-21 04:42:50 -04:00
|
|
|
rb.PushIpcInterface<IBtmUserCore>(system);
|
2018-11-16 09:42:17 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-07-28 20:59:09 -04:00
|
|
|
class BTM final : public ServiceFramework<BTM> {
|
|
|
|
public:
|
2020-11-26 15:19:08 -05:00
|
|
|
explicit BTM(Core::System& system_) : ServiceFramework{system_, "btm"} {
|
2018-07-28 20:59:09 -04:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2020-06-26 19:57:48 -04:00
|
|
|
{0, nullptr, "GetState"},
|
|
|
|
{1, nullptr, "GetHostDeviceProperty"},
|
|
|
|
{2, nullptr, "AcquireDeviceConditionEvent"},
|
|
|
|
{3, nullptr, "GetDeviceCondition"},
|
|
|
|
{4, nullptr, "SetBurstMode"},
|
|
|
|
{5, nullptr, "SetSlotMode"},
|
|
|
|
{6, nullptr, "SetBluetoothMode"},
|
|
|
|
{7, nullptr, "SetWlanMode"},
|
|
|
|
{8, nullptr, "AcquireDeviceInfoEvent"},
|
|
|
|
{9, nullptr, "GetDeviceInfo"},
|
|
|
|
{10, nullptr, "AddDeviceInfo"},
|
|
|
|
{11, nullptr, "RemoveDeviceInfo"},
|
|
|
|
{12, nullptr, "IncreaseDeviceInfoOrder"},
|
|
|
|
{13, nullptr, "LlrNotify"},
|
2019-01-29 21:47:25 -05:00
|
|
|
{14, nullptr, "EnableRadio"},
|
|
|
|
{15, nullptr, "DisableRadio"},
|
2020-06-26 19:57:48 -04:00
|
|
|
{16, nullptr, "HidDisconnect"},
|
|
|
|
{17, nullptr, "HidSetRetransmissionMode"},
|
|
|
|
{18, nullptr, "AcquireAwakeReqEvent"},
|
|
|
|
{19, nullptr, "AcquireLlrStateEvent"},
|
|
|
|
{20, nullptr, "IsLlrStarted"},
|
|
|
|
{21, nullptr, "EnableSlotSaving"},
|
|
|
|
{22, nullptr, "ProtectDeviceInfo"},
|
|
|
|
{23, nullptr, "AcquireBleScanEvent"},
|
|
|
|
{24, nullptr, "GetBleScanParameterGeneral"},
|
|
|
|
{25, nullptr, "GetBleScanParameterSmartDevice"},
|
|
|
|
{26, nullptr, "StartBleScanForGeneral"},
|
|
|
|
{27, nullptr, "StopBleScanForGeneral"},
|
|
|
|
{28, nullptr, "GetBleScanResultsForGeneral"},
|
|
|
|
{29, nullptr, "StartBleScanForPairedDevice"},
|
|
|
|
{30, nullptr, "StopBleScanForPairedDevice"},
|
|
|
|
{31, nullptr, "StartBleScanForSmartDevice"},
|
|
|
|
{32, nullptr, "StopBleScanForSmartDevice"},
|
|
|
|
{33, nullptr, "GetBleScanResultsForSmartDevice"},
|
|
|
|
{34, nullptr, "AcquireBleConnectionEvent"},
|
|
|
|
{35, nullptr, "BleConnect"},
|
|
|
|
{36, nullptr, "BleOverrideConnection"},
|
|
|
|
{37, nullptr, "BleDisconnect"},
|
|
|
|
{38, nullptr, "BleGetConnectionState"},
|
|
|
|
{39, nullptr, "BleGetGattClientConditionList"},
|
|
|
|
{40, nullptr, "AcquireBlePairingEvent"},
|
|
|
|
{41, nullptr, "BlePairDevice"},
|
|
|
|
{42, nullptr, "BleUnpairDeviceOnBoth"},
|
|
|
|
{43, nullptr, "BleUnpairDevice"},
|
|
|
|
{44, nullptr, "BleGetPairedAddresses"},
|
|
|
|
{45, nullptr, "AcquireBleServiceDiscoveryEvent"},
|
|
|
|
{46, nullptr, "GetGattServices"},
|
|
|
|
{47, nullptr, "GetGattService"},
|
|
|
|
{48, nullptr, "GetGattIncludedServices"},
|
|
|
|
{49, nullptr, "GetBelongingService"},
|
|
|
|
{50, nullptr, "GetGattCharacteristics"},
|
|
|
|
{51, nullptr, "GetGattDescriptors"},
|
|
|
|
{52, nullptr, "AcquireBleMtuConfigEvent"},
|
|
|
|
{53, nullptr, "ConfigureBleMtu"},
|
|
|
|
{54, nullptr, "GetBleMtu"},
|
|
|
|
{55, nullptr, "RegisterBleGattDataPath"},
|
|
|
|
{56, nullptr, "UnregisterBleGattDataPath"},
|
|
|
|
{57, nullptr, "RegisterAppletResourceUserId"},
|
|
|
|
{58, nullptr, "UnregisterAppletResourceUserId"},
|
|
|
|
{59, nullptr, "SetAppletResourceUserId"},
|
2020-06-26 20:42:46 -04:00
|
|
|
{60, nullptr, "Unknown60"},
|
|
|
|
{61, nullptr, "Unknown61"},
|
|
|
|
{62, nullptr, "Unknown62"},
|
|
|
|
{63, nullptr, "Unknown63"},
|
|
|
|
{64, nullptr, "Unknown64"},
|
2022-01-21 15:59:41 -05:00
|
|
|
{65, nullptr, "Unknown65"},
|
|
|
|
{66, nullptr, "Unknown66"},
|
|
|
|
{67, nullptr, "Unknown67"},
|
|
|
|
{68, nullptr, "Unknown68"},
|
|
|
|
{69, nullptr, "Unknown69"},
|
|
|
|
{70, nullptr, "Unknown70"},
|
|
|
|
{71, nullptr, "Unknown71"},
|
|
|
|
{72, nullptr, "Unknown72"},
|
|
|
|
{73, nullptr, "Unknown73"},
|
|
|
|
{74, nullptr, "Unknown74"},
|
|
|
|
{75, nullptr, "Unknown75"},
|
|
|
|
{76, nullptr, "Unknown76"},
|
|
|
|
{100, nullptr, "Unknown100"},
|
|
|
|
{101, nullptr, "Unknown101"},
|
|
|
|
{110, nullptr, "Unknown102"},
|
|
|
|
{111, nullptr, "Unknown103"},
|
2018-07-28 20:59:09 -04:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class BTM_DBG final : public ServiceFramework<BTM_DBG> {
|
|
|
|
public:
|
2020-11-26 15:19:08 -05:00
|
|
|
explicit BTM_DBG(Core::System& system_) : ServiceFramework{system_, "btm:dbg"} {
|
2018-07-28 20:59:09 -04:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2020-06-26 19:57:48 -04:00
|
|
|
{0, nullptr, "AcquireDiscoveryEvent"},
|
|
|
|
{1, nullptr, "StartDiscovery"},
|
|
|
|
{2, nullptr, "CancelDiscovery"},
|
|
|
|
{3, nullptr, "GetDeviceProperty"},
|
|
|
|
{4, nullptr, "CreateBond"},
|
|
|
|
{5, nullptr, "CancelBond"},
|
|
|
|
{6, nullptr, "SetTsiMode"},
|
|
|
|
{7, nullptr, "GeneralTest"},
|
|
|
|
{8, nullptr, "HidConnect"},
|
|
|
|
{9, nullptr, "GeneralGet"},
|
|
|
|
{10, nullptr, "GetGattClientDisconnectionReason"},
|
|
|
|
{11, nullptr, "GetBleConnectionParameter"},
|
|
|
|
{12, nullptr, "GetBleConnectionParameterRequest"},
|
2021-04-07 10:30:59 -04:00
|
|
|
{13, nullptr, "Unknown13"},
|
2018-07-28 20:59:09 -04:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-07-28 21:08:08 -04:00
|
|
|
class IBtmSystemCore final : public ServiceFramework<IBtmSystemCore> {
|
|
|
|
public:
|
2020-11-26 15:19:08 -05:00
|
|
|
explicit IBtmSystemCore(Core::System& system_) : ServiceFramework{system_, "IBtmSystemCore"} {
|
2018-07-28 21:08:08 -04:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2019-01-29 21:47:25 -05:00
|
|
|
{0, nullptr, "StartGamepadPairing"},
|
|
|
|
{1, nullptr, "CancelGamepadPairing"},
|
|
|
|
{2, nullptr, "ClearGamepadPairingDatabase"},
|
|
|
|
{3, nullptr, "GetPairedGamepadCount"},
|
|
|
|
{4, nullptr, "EnableRadio"},
|
|
|
|
{5, nullptr, "DisableRadio"},
|
|
|
|
{6, nullptr, "GetRadioOnOff"},
|
|
|
|
{7, nullptr, "AcquireRadioEvent"},
|
|
|
|
{8, nullptr, "AcquireGamepadPairingEvent"},
|
|
|
|
{9, nullptr, "IsGamepadPairingStarted"},
|
2022-01-21 15:59:41 -05:00
|
|
|
{10, nullptr, "StartAudioDeviceDiscovery"},
|
|
|
|
{11, nullptr, "StopAudioDeviceDiscovery"},
|
|
|
|
{12, nullptr, "IsDiscoveryingAudioDevice"},
|
|
|
|
{13, nullptr, "GetDiscoveredAudioDevice"},
|
|
|
|
{14, nullptr, "AcquireAudioDeviceConnectionEvent"},
|
|
|
|
{15, nullptr, "ConnectAudioDevice"},
|
|
|
|
{16, nullptr, "IsConnectingAudioDevice"},
|
|
|
|
{17, nullptr, "GetConnectedAudioDevices"},
|
|
|
|
{18, nullptr, "DisconnectAudioDevice"},
|
|
|
|
{19, nullptr, "AcquirePairedAudioDeviceInfoChangedEvent"},
|
|
|
|
{20, nullptr, "GetPairedAudioDevices"},
|
|
|
|
{21, nullptr, "RemoveAudioDevicePairing"},
|
|
|
|
{22, nullptr, "RequestAudioDeviceConnectionRejection"},
|
|
|
|
{23, nullptr, "CancelAudioDeviceConnectionRejection"}
|
2018-07-28 21:08:08 -04:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-07-28 20:59:09 -04:00
|
|
|
class BTM_SYS final : public ServiceFramework<BTM_SYS> {
|
|
|
|
public:
|
2020-11-26 15:19:08 -05:00
|
|
|
explicit BTM_SYS(Core::System& system_) : ServiceFramework{system_, "btm:sys"} {
|
2018-07-28 20:59:09 -04:00
|
|
|
// clang-format off
|
|
|
|
static const FunctionInfo functions[] = {
|
2019-01-29 21:47:25 -05:00
|
|
|
{0, &BTM_SYS::GetCore, "GetCore"},
|
2018-07-28 20:59:09 -04:00
|
|
|
};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
RegisterHandlers(functions);
|
|
|
|
}
|
2018-07-28 21:08:08 -04:00
|
|
|
|
|
|
|
private:
|
2019-01-29 21:47:25 -05:00
|
|
|
void GetCore(Kernel::HLERequestContext& ctx) {
|
2018-11-26 01:06:13 -05:00
|
|
|
LOG_DEBUG(Service_BTM, "called");
|
|
|
|
|
2018-07-28 21:08:08 -04:00
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1};
|
2021-05-21 01:05:04 -04:00
|
|
|
rb.Push(ResultSuccess);
|
2020-11-26 15:19:08 -05:00
|
|
|
rb.PushIpcInterface<IBtmSystemCore>(system);
|
2018-07-28 21:08:08 -04:00
|
|
|
}
|
2018-07-28 20:59:09 -04:00
|
|
|
};
|
|
|
|
|
2019-09-21 04:42:50 -04:00
|
|
|
void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) {
|
2020-11-26 15:19:08 -05:00
|
|
|
std::make_shared<BTM>(system)->InstallAsService(sm);
|
|
|
|
std::make_shared<BTM_DBG>(system)->InstallAsService(sm);
|
|
|
|
std::make_shared<BTM_SYS>(system)->InstallAsService(sm);
|
2019-09-21 04:42:50 -04:00
|
|
|
std::make_shared<BTM_USR>(system)->InstallAsService(sm);
|
2018-07-28 20:59:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Service::BTM
|