btm.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <memory>
  5. #include "common/logging/log.h"
  6. #include "core/core.h"
  7. #include "core/hle/ipc_helpers.h"
  8. #include "core/hle/kernel/k_event.h"
  9. #include "core/hle/service/btm/btm.h"
  10. #include "core/hle/service/kernel_helpers.h"
  11. #include "core/hle/service/service.h"
  12. namespace Service::BTM {
  13. class IBtmUserCore final : public ServiceFramework<IBtmUserCore> {
  14. public:
  15. explicit IBtmUserCore(Core::System& system_)
  16. : ServiceFramework{system_, "IBtmUserCore"}, service_context{system_, "IBtmUserCore"} {
  17. // clang-format off
  18. static const FunctionInfo functions[] = {
  19. {0, &IBtmUserCore::AcquireBleScanEvent, "AcquireBleScanEvent"},
  20. {1, nullptr, "GetBleScanFilterParameter"},
  21. {2, nullptr, "GetBleScanFilterParameter2"},
  22. {3, nullptr, "StartBleScanForGeneral"},
  23. {4, nullptr, "StopBleScanForGeneral"},
  24. {5, nullptr, "GetBleScanResultsForGeneral"},
  25. {6, nullptr, "StartBleScanForPaired"},
  26. {7, nullptr, "StopBleScanForPaired"},
  27. {8, nullptr, "StartBleScanForSmartDevice"},
  28. {9, nullptr, "StopBleScanForSmartDevice"},
  29. {10, nullptr, "GetBleScanResultsForSmartDevice"},
  30. {17, &IBtmUserCore::AcquireBleConnectionEvent, "AcquireBleConnectionEvent"},
  31. {18, nullptr, "BleConnect"},
  32. {19, nullptr, "BleDisconnect"},
  33. {20, nullptr, "BleGetConnectionState"},
  34. {21, nullptr, "AcquireBlePairingEvent"},
  35. {22, nullptr, "BlePairDevice"},
  36. {23, nullptr, "BleUnPairDevice"},
  37. {24, nullptr, "BleUnPairDevice2"},
  38. {25, nullptr, "BleGetPairedDevices"},
  39. {26, &IBtmUserCore::AcquireBleServiceDiscoveryEvent, "AcquireBleServiceDiscoveryEvent"},
  40. {27, nullptr, "GetGattServices"},
  41. {28, nullptr, "GetGattService"},
  42. {29, nullptr, "GetGattIncludedServices"},
  43. {30, nullptr, "GetBelongingGattService"},
  44. {31, nullptr, "GetGattCharacteristics"},
  45. {32, nullptr, "GetGattDescriptors"},
  46. {33, &IBtmUserCore::AcquireBleMtuConfigEvent, "AcquireBleMtuConfigEvent"},
  47. {34, nullptr, "ConfigureBleMtu"},
  48. {35, nullptr, "GetBleMtu"},
  49. {36, nullptr, "RegisterBleGattDataPath"},
  50. {37, nullptr, "UnregisterBleGattDataPath"},
  51. };
  52. // clang-format on
  53. RegisterHandlers(functions);
  54. scan_event = service_context.CreateEvent("IBtmUserCore:ScanEvent");
  55. connection_event = service_context.CreateEvent("IBtmUserCore:ConnectionEvent");
  56. service_discovery_event = service_context.CreateEvent("IBtmUserCore:DiscoveryEvent");
  57. config_event = service_context.CreateEvent("IBtmUserCore:ConfigEvent");
  58. }
  59. ~IBtmUserCore() override {
  60. service_context.CloseEvent(scan_event);
  61. service_context.CloseEvent(connection_event);
  62. service_context.CloseEvent(service_discovery_event);
  63. service_context.CloseEvent(config_event);
  64. }
  65. private:
  66. void AcquireBleScanEvent(Kernel::HLERequestContext& ctx) {
  67. LOG_WARNING(Service_BTM, "(STUBBED) called");
  68. IPC::ResponseBuilder rb{ctx, 2, 1};
  69. rb.Push(ResultSuccess);
  70. rb.PushCopyObjects(scan_event->GetReadableEvent());
  71. }
  72. void AcquireBleConnectionEvent(Kernel::HLERequestContext& ctx) {
  73. LOG_WARNING(Service_BTM, "(STUBBED) called");
  74. IPC::ResponseBuilder rb{ctx, 2, 1};
  75. rb.Push(ResultSuccess);
  76. rb.PushCopyObjects(connection_event->GetReadableEvent());
  77. }
  78. void AcquireBleServiceDiscoveryEvent(Kernel::HLERequestContext& ctx) {
  79. LOG_WARNING(Service_BTM, "(STUBBED) called");
  80. IPC::ResponseBuilder rb{ctx, 2, 1};
  81. rb.Push(ResultSuccess);
  82. rb.PushCopyObjects(service_discovery_event->GetReadableEvent());
  83. }
  84. void AcquireBleMtuConfigEvent(Kernel::HLERequestContext& ctx) {
  85. LOG_WARNING(Service_BTM, "(STUBBED) called");
  86. IPC::ResponseBuilder rb{ctx, 2, 1};
  87. rb.Push(ResultSuccess);
  88. rb.PushCopyObjects(config_event->GetReadableEvent());
  89. }
  90. KernelHelpers::ServiceContext service_context;
  91. Kernel::KEvent* scan_event;
  92. Kernel::KEvent* connection_event;
  93. Kernel::KEvent* service_discovery_event;
  94. Kernel::KEvent* config_event;
  95. };
  96. class BTM_USR final : public ServiceFramework<BTM_USR> {
  97. public:
  98. explicit BTM_USR(Core::System& system_) : ServiceFramework{system_, "btm:u"} {
  99. // clang-format off
  100. static const FunctionInfo functions[] = {
  101. {0, &BTM_USR::GetCore, "GetCore"},
  102. };
  103. // clang-format on
  104. RegisterHandlers(functions);
  105. }
  106. private:
  107. void GetCore(Kernel::HLERequestContext& ctx) {
  108. LOG_DEBUG(Service_BTM, "called");
  109. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  110. rb.Push(ResultSuccess);
  111. rb.PushIpcInterface<IBtmUserCore>(system);
  112. }
  113. };
  114. class BTM final : public ServiceFramework<BTM> {
  115. public:
  116. explicit BTM(Core::System& system_) : ServiceFramework{system_, "btm"} {
  117. // clang-format off
  118. static const FunctionInfo functions[] = {
  119. {0, nullptr, "GetState"},
  120. {1, nullptr, "GetHostDeviceProperty"},
  121. {2, nullptr, "AcquireDeviceConditionEvent"},
  122. {3, nullptr, "GetDeviceCondition"},
  123. {4, nullptr, "SetBurstMode"},
  124. {5, nullptr, "SetSlotMode"},
  125. {6, nullptr, "SetBluetoothMode"},
  126. {7, nullptr, "SetWlanMode"},
  127. {8, nullptr, "AcquireDeviceInfoEvent"},
  128. {9, nullptr, "GetDeviceInfo"},
  129. {10, nullptr, "AddDeviceInfo"},
  130. {11, nullptr, "RemoveDeviceInfo"},
  131. {12, nullptr, "IncreaseDeviceInfoOrder"},
  132. {13, nullptr, "LlrNotify"},
  133. {14, nullptr, "EnableRadio"},
  134. {15, nullptr, "DisableRadio"},
  135. {16, nullptr, "HidDisconnect"},
  136. {17, nullptr, "HidSetRetransmissionMode"},
  137. {18, nullptr, "AcquireAwakeReqEvent"},
  138. {19, nullptr, "AcquireLlrStateEvent"},
  139. {20, nullptr, "IsLlrStarted"},
  140. {21, nullptr, "EnableSlotSaving"},
  141. {22, nullptr, "ProtectDeviceInfo"},
  142. {23, nullptr, "AcquireBleScanEvent"},
  143. {24, nullptr, "GetBleScanParameterGeneral"},
  144. {25, nullptr, "GetBleScanParameterSmartDevice"},
  145. {26, nullptr, "StartBleScanForGeneral"},
  146. {27, nullptr, "StopBleScanForGeneral"},
  147. {28, nullptr, "GetBleScanResultsForGeneral"},
  148. {29, nullptr, "StartBleScanForPairedDevice"},
  149. {30, nullptr, "StopBleScanForPairedDevice"},
  150. {31, nullptr, "StartBleScanForSmartDevice"},
  151. {32, nullptr, "StopBleScanForSmartDevice"},
  152. {33, nullptr, "GetBleScanResultsForSmartDevice"},
  153. {34, nullptr, "AcquireBleConnectionEvent"},
  154. {35, nullptr, "BleConnect"},
  155. {36, nullptr, "BleOverrideConnection"},
  156. {37, nullptr, "BleDisconnect"},
  157. {38, nullptr, "BleGetConnectionState"},
  158. {39, nullptr, "BleGetGattClientConditionList"},
  159. {40, nullptr, "AcquireBlePairingEvent"},
  160. {41, nullptr, "BlePairDevice"},
  161. {42, nullptr, "BleUnpairDeviceOnBoth"},
  162. {43, nullptr, "BleUnpairDevice"},
  163. {44, nullptr, "BleGetPairedAddresses"},
  164. {45, nullptr, "AcquireBleServiceDiscoveryEvent"},
  165. {46, nullptr, "GetGattServices"},
  166. {47, nullptr, "GetGattService"},
  167. {48, nullptr, "GetGattIncludedServices"},
  168. {49, nullptr, "GetBelongingService"},
  169. {50, nullptr, "GetGattCharacteristics"},
  170. {51, nullptr, "GetGattDescriptors"},
  171. {52, nullptr, "AcquireBleMtuConfigEvent"},
  172. {53, nullptr, "ConfigureBleMtu"},
  173. {54, nullptr, "GetBleMtu"},
  174. {55, nullptr, "RegisterBleGattDataPath"},
  175. {56, nullptr, "UnregisterBleGattDataPath"},
  176. {57, nullptr, "RegisterAppletResourceUserId"},
  177. {58, nullptr, "UnregisterAppletResourceUserId"},
  178. {59, nullptr, "SetAppletResourceUserId"},
  179. {60, nullptr, "Unknown60"},
  180. {61, nullptr, "Unknown61"},
  181. {62, nullptr, "Unknown62"},
  182. {63, nullptr, "Unknown63"},
  183. {64, nullptr, "Unknown64"},
  184. {65, nullptr, "Unknown65"},
  185. {66, nullptr, "Unknown66"},
  186. {67, nullptr, "Unknown67"},
  187. {68, nullptr, "Unknown68"},
  188. {69, nullptr, "Unknown69"},
  189. {70, nullptr, "Unknown70"},
  190. {71, nullptr, "Unknown71"},
  191. {72, nullptr, "Unknown72"},
  192. {73, nullptr, "Unknown73"},
  193. {74, nullptr, "Unknown74"},
  194. {75, nullptr, "Unknown75"},
  195. {76, nullptr, "Unknown76"},
  196. {100, nullptr, "Unknown100"},
  197. {101, nullptr, "Unknown101"},
  198. {110, nullptr, "Unknown102"},
  199. {111, nullptr, "Unknown103"},
  200. };
  201. // clang-format on
  202. RegisterHandlers(functions);
  203. }
  204. };
  205. class BTM_DBG final : public ServiceFramework<BTM_DBG> {
  206. public:
  207. explicit BTM_DBG(Core::System& system_) : ServiceFramework{system_, "btm:dbg"} {
  208. // clang-format off
  209. static const FunctionInfo functions[] = {
  210. {0, nullptr, "AcquireDiscoveryEvent"},
  211. {1, nullptr, "StartDiscovery"},
  212. {2, nullptr, "CancelDiscovery"},
  213. {3, nullptr, "GetDeviceProperty"},
  214. {4, nullptr, "CreateBond"},
  215. {5, nullptr, "CancelBond"},
  216. {6, nullptr, "SetTsiMode"},
  217. {7, nullptr, "GeneralTest"},
  218. {8, nullptr, "HidConnect"},
  219. {9, nullptr, "GeneralGet"},
  220. {10, nullptr, "GetGattClientDisconnectionReason"},
  221. {11, nullptr, "GetBleConnectionParameter"},
  222. {12, nullptr, "GetBleConnectionParameterRequest"},
  223. {13, nullptr, "Unknown13"},
  224. };
  225. // clang-format on
  226. RegisterHandlers(functions);
  227. }
  228. };
  229. class IBtmSystemCore final : public ServiceFramework<IBtmSystemCore> {
  230. public:
  231. explicit IBtmSystemCore(Core::System& system_) : ServiceFramework{system_, "IBtmSystemCore"} {
  232. // clang-format off
  233. static const FunctionInfo functions[] = {
  234. {0, nullptr, "StartGamepadPairing"},
  235. {1, nullptr, "CancelGamepadPairing"},
  236. {2, nullptr, "ClearGamepadPairingDatabase"},
  237. {3, nullptr, "GetPairedGamepadCount"},
  238. {4, nullptr, "EnableRadio"},
  239. {5, nullptr, "DisableRadio"},
  240. {6, nullptr, "GetRadioOnOff"},
  241. {7, nullptr, "AcquireRadioEvent"},
  242. {8, nullptr, "AcquireGamepadPairingEvent"},
  243. {9, nullptr, "IsGamepadPairingStarted"},
  244. {10, nullptr, "StartAudioDeviceDiscovery"},
  245. {11, nullptr, "StopAudioDeviceDiscovery"},
  246. {12, nullptr, "IsDiscoveryingAudioDevice"},
  247. {13, nullptr, "GetDiscoveredAudioDevice"},
  248. {14, nullptr, "AcquireAudioDeviceConnectionEvent"},
  249. {15, nullptr, "ConnectAudioDevice"},
  250. {16, nullptr, "IsConnectingAudioDevice"},
  251. {17, nullptr, "GetConnectedAudioDevices"},
  252. {18, nullptr, "DisconnectAudioDevice"},
  253. {19, nullptr, "AcquirePairedAudioDeviceInfoChangedEvent"},
  254. {20, nullptr, "GetPairedAudioDevices"},
  255. {21, nullptr, "RemoveAudioDevicePairing"},
  256. {22, nullptr, "RequestAudioDeviceConnectionRejection"},
  257. {23, nullptr, "CancelAudioDeviceConnectionRejection"}
  258. };
  259. // clang-format on
  260. RegisterHandlers(functions);
  261. }
  262. };
  263. class BTM_SYS final : public ServiceFramework<BTM_SYS> {
  264. public:
  265. explicit BTM_SYS(Core::System& system_) : ServiceFramework{system_, "btm:sys"} {
  266. // clang-format off
  267. static const FunctionInfo functions[] = {
  268. {0, &BTM_SYS::GetCore, "GetCore"},
  269. };
  270. // clang-format on
  271. RegisterHandlers(functions);
  272. }
  273. private:
  274. void GetCore(Kernel::HLERequestContext& ctx) {
  275. LOG_DEBUG(Service_BTM, "called");
  276. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  277. rb.Push(ResultSuccess);
  278. rb.PushIpcInterface<IBtmSystemCore>(system);
  279. }
  280. };
  281. void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) {
  282. std::make_shared<BTM>(system)->InstallAsService(sm);
  283. std::make_shared<BTM_DBG>(system)->InstallAsService(sm);
  284. std::make_shared<BTM_SYS>(system)->InstallAsService(sm);
  285. std::make_shared<BTM_USR>(system)->InstallAsService(sm);
  286. }
  287. } // namespace Service::BTM