btm.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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/hle/ipc_helpers.h"
  7. #include "core/hle/kernel/hle_ipc.h"
  8. #include "core/hle/kernel/kernel.h"
  9. #include "core/hle/kernel/readable_event.h"
  10. #include "core/hle/kernel/writable_event.h"
  11. #include "core/hle/service/btm/btm.h"
  12. #include "core/hle/service/service.h"
  13. namespace Service::BTM {
  14. class IBtmUserCore final : public ServiceFramework<IBtmUserCore> {
  15. public:
  16. explicit IBtmUserCore(Core::System& system) : ServiceFramework{"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. auto& kernel = system.Kernel();
  55. scan_event = Kernel::WritableEvent::CreateEventPair(kernel, "IBtmUserCore:ScanEvent");
  56. connection_event =
  57. Kernel::WritableEvent::CreateEventPair(kernel, "IBtmUserCore:ConnectionEvent");
  58. service_discovery =
  59. Kernel::WritableEvent::CreateEventPair(kernel, "IBtmUserCore:Discovery");
  60. config_event = Kernel::WritableEvent::CreateEventPair(kernel, "IBtmUserCore:ConfigEvent");
  61. }
  62. private:
  63. void AcquireBleScanEvent(Kernel::HLERequestContext& ctx) {
  64. LOG_WARNING(Service_BTM, "(STUBBED) called");
  65. IPC::ResponseBuilder rb{ctx, 2, 1};
  66. rb.Push(RESULT_SUCCESS);
  67. rb.PushCopyObjects(scan_event.readable);
  68. }
  69. void AcquireBleConnectionEvent(Kernel::HLERequestContext& ctx) {
  70. LOG_WARNING(Service_BTM, "(STUBBED) called");
  71. IPC::ResponseBuilder rb{ctx, 2, 1};
  72. rb.Push(RESULT_SUCCESS);
  73. rb.PushCopyObjects(connection_event.readable);
  74. }
  75. void AcquireBleServiceDiscoveryEvent(Kernel::HLERequestContext& ctx) {
  76. LOG_WARNING(Service_BTM, "(STUBBED) called");
  77. IPC::ResponseBuilder rb{ctx, 2, 1};
  78. rb.Push(RESULT_SUCCESS);
  79. rb.PushCopyObjects(service_discovery.readable);
  80. }
  81. void AcquireBleMtuConfigEvent(Kernel::HLERequestContext& ctx) {
  82. LOG_WARNING(Service_BTM, "(STUBBED) called");
  83. IPC::ResponseBuilder rb{ctx, 2, 1};
  84. rb.Push(RESULT_SUCCESS);
  85. rb.PushCopyObjects(config_event.readable);
  86. }
  87. Kernel::EventPair scan_event;
  88. Kernel::EventPair connection_event;
  89. Kernel::EventPair service_discovery;
  90. Kernel::EventPair config_event;
  91. };
  92. class BTM_USR final : public ServiceFramework<BTM_USR> {
  93. public:
  94. explicit BTM_USR(Core::System& system) : ServiceFramework{"btm:u"}, system(system) {
  95. // clang-format off
  96. static const FunctionInfo functions[] = {
  97. {0, &BTM_USR::GetCore, "GetCore"},
  98. };
  99. // clang-format on
  100. RegisterHandlers(functions);
  101. }
  102. private:
  103. void GetCore(Kernel::HLERequestContext& ctx) {
  104. LOG_DEBUG(Service_BTM, "called");
  105. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  106. rb.Push(RESULT_SUCCESS);
  107. rb.PushIpcInterface<IBtmUserCore>(system);
  108. }
  109. Core::System& system;
  110. };
  111. class BTM final : public ServiceFramework<BTM> {
  112. public:
  113. explicit BTM() : ServiceFramework{"btm"} {
  114. // clang-format off
  115. static const FunctionInfo functions[] = {
  116. {0, nullptr, "GetState"},
  117. {1, nullptr, "GetHostDeviceProperty"},
  118. {2, nullptr, "AcquireDeviceConditionEvent"},
  119. {3, nullptr, "GetDeviceCondition"},
  120. {4, nullptr, "SetBurstMode"},
  121. {5, nullptr, "SetSlotMode"},
  122. {6, nullptr, "SetBluetoothMode"},
  123. {7, nullptr, "SetWlanMode"},
  124. {8, nullptr, "AcquireDeviceInfoEvent"},
  125. {9, nullptr, "GetDeviceInfo"},
  126. {10, nullptr, "AddDeviceInfo"},
  127. {11, nullptr, "RemoveDeviceInfo"},
  128. {12, nullptr, "IncreaseDeviceInfoOrder"},
  129. {13, nullptr, "LlrNotify"},
  130. {14, nullptr, "EnableRadio"},
  131. {15, nullptr, "DisableRadio"},
  132. {16, nullptr, "HidDisconnect"},
  133. {17, nullptr, "HidSetRetransmissionMode"},
  134. {18, nullptr, "AcquireAwakeReqEvent"},
  135. {19, nullptr, "AcquireLlrStateEvent"},
  136. {20, nullptr, "IsLlrStarted"},
  137. {21, nullptr, "EnableSlotSaving"},
  138. {22, nullptr, "ProtectDeviceInfo"},
  139. {23, nullptr, "AcquireBleScanEvent"},
  140. {24, nullptr, "GetBleScanParameterGeneral"},
  141. {25, nullptr, "GetBleScanParameterSmartDevice"},
  142. {26, nullptr, "StartBleScanForGeneral"},
  143. {27, nullptr, "StopBleScanForGeneral"},
  144. {28, nullptr, "GetBleScanResultsForGeneral"},
  145. {29, nullptr, "StartBleScanForPairedDevice"},
  146. {30, nullptr, "StopBleScanForPairedDevice"},
  147. {31, nullptr, "StartBleScanForSmartDevice"},
  148. {32, nullptr, "StopBleScanForSmartDevice"},
  149. {33, nullptr, "GetBleScanResultsForSmartDevice"},
  150. {34, nullptr, "AcquireBleConnectionEvent"},
  151. {35, nullptr, "BleConnect"},
  152. {36, nullptr, "BleOverrideConnection"},
  153. {37, nullptr, "BleDisconnect"},
  154. {38, nullptr, "BleGetConnectionState"},
  155. {39, nullptr, "BleGetGattClientConditionList"},
  156. {40, nullptr, "AcquireBlePairingEvent"},
  157. {41, nullptr, "BlePairDevice"},
  158. {42, nullptr, "BleUnpairDeviceOnBoth"},
  159. {43, nullptr, "BleUnpairDevice"},
  160. {44, nullptr, "BleGetPairedAddresses"},
  161. {45, nullptr, "AcquireBleServiceDiscoveryEvent"},
  162. {46, nullptr, "GetGattServices"},
  163. {47, nullptr, "GetGattService"},
  164. {48, nullptr, "GetGattIncludedServices"},
  165. {49, nullptr, "GetBelongingService"},
  166. {50, nullptr, "GetGattCharacteristics"},
  167. {51, nullptr, "GetGattDescriptors"},
  168. {52, nullptr, "AcquireBleMtuConfigEvent"},
  169. {53, nullptr, "ConfigureBleMtu"},
  170. {54, nullptr, "GetBleMtu"},
  171. {55, nullptr, "RegisterBleGattDataPath"},
  172. {56, nullptr, "UnregisterBleGattDataPath"},
  173. {57, nullptr, "RegisterAppletResourceUserId"},
  174. {58, nullptr, "UnregisterAppletResourceUserId"},
  175. {59, nullptr, "SetAppletResourceUserId"},
  176. {60, nullptr, "Unknown"},
  177. {61, nullptr, "Unknown2"},
  178. {62, nullptr, "Unknown3"},
  179. {63, nullptr, "Unknown4"},
  180. {64, nullptr, "Unknown5"},
  181. };
  182. // clang-format on
  183. RegisterHandlers(functions);
  184. }
  185. };
  186. class BTM_DBG final : public ServiceFramework<BTM_DBG> {
  187. public:
  188. explicit BTM_DBG() : ServiceFramework{"btm:dbg"} {
  189. // clang-format off
  190. static const FunctionInfo functions[] = {
  191. {0, nullptr, "AcquireDiscoveryEvent"},
  192. {1, nullptr, "StartDiscovery"},
  193. {2, nullptr, "CancelDiscovery"},
  194. {3, nullptr, "GetDeviceProperty"},
  195. {4, nullptr, "CreateBond"},
  196. {5, nullptr, "CancelBond"},
  197. {6, nullptr, "SetTsiMode"},
  198. {7, nullptr, "GeneralTest"},
  199. {8, nullptr, "HidConnect"},
  200. {9, nullptr, "GeneralGet"},
  201. {10, nullptr, "GetGattClientDisconnectionReason"},
  202. {11, nullptr, "GetBleConnectionParameter"},
  203. {12, nullptr, "GetBleConnectionParameterRequest"},
  204. };
  205. // clang-format on
  206. RegisterHandlers(functions);
  207. }
  208. };
  209. class IBtmSystemCore final : public ServiceFramework<IBtmSystemCore> {
  210. public:
  211. explicit IBtmSystemCore() : ServiceFramework{"IBtmSystemCore"} {
  212. // clang-format off
  213. static const FunctionInfo functions[] = {
  214. {0, nullptr, "StartGamepadPairing"},
  215. {1, nullptr, "CancelGamepadPairing"},
  216. {2, nullptr, "ClearGamepadPairingDatabase"},
  217. {3, nullptr, "GetPairedGamepadCount"},
  218. {4, nullptr, "EnableRadio"},
  219. {5, nullptr, "DisableRadio"},
  220. {6, nullptr, "GetRadioOnOff"},
  221. {7, nullptr, "AcquireRadioEvent"},
  222. {8, nullptr, "AcquireGamepadPairingEvent"},
  223. {9, nullptr, "IsGamepadPairingStarted"},
  224. };
  225. // clang-format on
  226. RegisterHandlers(functions);
  227. }
  228. };
  229. class BTM_SYS final : public ServiceFramework<BTM_SYS> {
  230. public:
  231. explicit BTM_SYS() : ServiceFramework{"btm:sys"} {
  232. // clang-format off
  233. static const FunctionInfo functions[] = {
  234. {0, &BTM_SYS::GetCore, "GetCore"},
  235. };
  236. // clang-format on
  237. RegisterHandlers(functions);
  238. }
  239. private:
  240. void GetCore(Kernel::HLERequestContext& ctx) {
  241. LOG_DEBUG(Service_BTM, "called");
  242. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  243. rb.Push(RESULT_SUCCESS);
  244. rb.PushIpcInterface<IBtmSystemCore>();
  245. }
  246. };
  247. void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) {
  248. std::make_shared<BTM>()->InstallAsService(sm);
  249. std::make_shared<BTM_DBG>()->InstallAsService(sm);
  250. std::make_shared<BTM_SYS>()->InstallAsService(sm);
  251. std::make_shared<BTM_USR>(system)->InstallAsService(sm);
  252. }
  253. } // namespace Service::BTM