btm.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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, Kernel::ResetType::Automatic,
  56. "IBtmUserCore:ScanEvent");
  57. connection_event = Kernel::WritableEvent::CreateEventPair(
  58. kernel, Kernel::ResetType::Automatic, "IBtmUserCore:ConnectionEvent");
  59. service_discovery = Kernel::WritableEvent::CreateEventPair(
  60. kernel, Kernel::ResetType::Automatic, "IBtmUserCore:Discovery");
  61. config_event = Kernel::WritableEvent::CreateEventPair(kernel, Kernel::ResetType::Automatic,
  62. "IBtmUserCore:ConfigEvent");
  63. }
  64. private:
  65. void AcquireBleScanEvent(Kernel::HLERequestContext& ctx) {
  66. LOG_WARNING(Service_BTM, "(STUBBED) called");
  67. IPC::ResponseBuilder rb{ctx, 2, 1};
  68. rb.Push(RESULT_SUCCESS);
  69. rb.PushCopyObjects(scan_event.readable);
  70. }
  71. void AcquireBleConnectionEvent(Kernel::HLERequestContext& ctx) {
  72. LOG_WARNING(Service_BTM, "(STUBBED) called");
  73. IPC::ResponseBuilder rb{ctx, 2, 1};
  74. rb.Push(RESULT_SUCCESS);
  75. rb.PushCopyObjects(connection_event.readable);
  76. }
  77. void AcquireBleServiceDiscoveryEvent(Kernel::HLERequestContext& ctx) {
  78. LOG_WARNING(Service_BTM, "(STUBBED) called");
  79. IPC::ResponseBuilder rb{ctx, 2, 1};
  80. rb.Push(RESULT_SUCCESS);
  81. rb.PushCopyObjects(service_discovery.readable);
  82. }
  83. void AcquireBleMtuConfigEvent(Kernel::HLERequestContext& ctx) {
  84. LOG_WARNING(Service_BTM, "(STUBBED) called");
  85. IPC::ResponseBuilder rb{ctx, 2, 1};
  86. rb.Push(RESULT_SUCCESS);
  87. rb.PushCopyObjects(config_event.readable);
  88. }
  89. Kernel::EventPair scan_event;
  90. Kernel::EventPair connection_event;
  91. Kernel::EventPair service_discovery;
  92. Kernel::EventPair config_event;
  93. };
  94. class BTM_USR final : public ServiceFramework<BTM_USR> {
  95. public:
  96. explicit BTM_USR(Core::System& system) : ServiceFramework{"btm:u"}, system(system) {
  97. // clang-format off
  98. static const FunctionInfo functions[] = {
  99. {0, &BTM_USR::GetCore, "GetCore"},
  100. };
  101. // clang-format on
  102. RegisterHandlers(functions);
  103. }
  104. private:
  105. void GetCore(Kernel::HLERequestContext& ctx) {
  106. LOG_DEBUG(Service_BTM, "called");
  107. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  108. rb.Push(RESULT_SUCCESS);
  109. rb.PushIpcInterface<IBtmUserCore>(system);
  110. }
  111. Core::System& system;
  112. };
  113. class BTM final : public ServiceFramework<BTM> {
  114. public:
  115. explicit BTM() : ServiceFramework{"btm"} {
  116. // clang-format off
  117. static const FunctionInfo functions[] = {
  118. {0, nullptr, "Unknown1"},
  119. {1, nullptr, "Unknown2"},
  120. {2, nullptr, "RegisterSystemEventForConnectedDeviceCondition"},
  121. {3, nullptr, "Unknown3"},
  122. {4, nullptr, "Unknown4"},
  123. {5, nullptr, "Unknown5"},
  124. {6, nullptr, "Unknown6"},
  125. {7, nullptr, "Unknown7"},
  126. {8, nullptr, "RegisterSystemEventForRegisteredDeviceInfo"},
  127. {9, nullptr, "Unknown8"},
  128. {10, nullptr, "Unknown9"},
  129. {11, nullptr, "Unknown10"},
  130. {12, nullptr, "Unknown11"},
  131. {13, nullptr, "Unknown12"},
  132. {14, nullptr, "EnableRadio"},
  133. {15, nullptr, "DisableRadio"},
  134. {16, nullptr, "Unknown13"},
  135. {17, nullptr, "Unknown14"},
  136. {18, nullptr, "Unknown15"},
  137. {19, nullptr, "Unknown16"},
  138. {20, nullptr, "Unknown17"},
  139. {21, nullptr, "Unknown18"},
  140. {22, nullptr, "Unknown19"},
  141. {23, nullptr, "Unknown20"},
  142. {24, nullptr, "Unknown21"},
  143. {25, nullptr, "Unknown22"},
  144. {26, nullptr, "Unknown23"},
  145. {27, nullptr, "Unknown24"},
  146. {28, nullptr, "Unknown25"},
  147. {29, nullptr, "Unknown26"},
  148. {30, nullptr, "Unknown27"},
  149. {31, nullptr, "Unknown28"},
  150. {32, nullptr, "Unknown29"},
  151. {33, nullptr, "Unknown30"},
  152. {34, nullptr, "Unknown31"},
  153. {35, nullptr, "Unknown32"},
  154. {36, nullptr, "Unknown33"},
  155. {37, nullptr, "Unknown34"},
  156. {38, nullptr, "Unknown35"},
  157. {39, nullptr, "Unknown36"},
  158. {40, nullptr, "Unknown37"},
  159. {41, nullptr, "Unknown38"},
  160. {42, nullptr, "Unknown39"},
  161. {43, nullptr, "Unknown40"},
  162. {44, nullptr, "Unknown41"},
  163. {45, nullptr, "Unknown42"},
  164. {46, nullptr, "Unknown43"},
  165. {47, nullptr, "Unknown44"},
  166. {48, nullptr, "Unknown45"},
  167. {49, nullptr, "Unknown46"},
  168. {50, nullptr, "Unknown47"},
  169. {51, nullptr, "Unknown48"},
  170. {52, nullptr, "Unknown49"},
  171. {53, nullptr, "Unknown50"},
  172. {54, nullptr, "Unknown51"},
  173. {55, nullptr, "Unknown52"},
  174. {56, nullptr, "Unknown53"},
  175. {57, nullptr, "Unknown54"},
  176. {58, nullptr, "Unknown55"},
  177. {59, nullptr, "Unknown56"},
  178. };
  179. // clang-format on
  180. RegisterHandlers(functions);
  181. }
  182. };
  183. class BTM_DBG final : public ServiceFramework<BTM_DBG> {
  184. public:
  185. explicit BTM_DBG() : ServiceFramework{"btm:dbg"} {
  186. // clang-format off
  187. static const FunctionInfo functions[] = {
  188. {0, nullptr, "RegisterSystemEventForDiscovery"},
  189. {1, nullptr, "Unknown1"},
  190. {2, nullptr, "Unknown2"},
  191. {3, nullptr, "Unknown3"},
  192. {4, nullptr, "Unknown4"},
  193. {5, nullptr, "Unknown5"},
  194. {6, nullptr, "Unknown6"},
  195. {7, nullptr, "Unknown7"},
  196. {8, nullptr, "Unknown8"},
  197. {9, nullptr, "Unknown9"},
  198. {10, nullptr, "Unknown10"},
  199. {11, nullptr, "Unknown11"},
  200. {12, nullptr, "Unknown11"},
  201. };
  202. // clang-format on
  203. RegisterHandlers(functions);
  204. }
  205. };
  206. class IBtmSystemCore final : public ServiceFramework<IBtmSystemCore> {
  207. public:
  208. explicit IBtmSystemCore() : ServiceFramework{"IBtmSystemCore"} {
  209. // clang-format off
  210. static const FunctionInfo functions[] = {
  211. {0, nullptr, "StartGamepadPairing"},
  212. {1, nullptr, "CancelGamepadPairing"},
  213. {2, nullptr, "ClearGamepadPairingDatabase"},
  214. {3, nullptr, "GetPairedGamepadCount"},
  215. {4, nullptr, "EnableRadio"},
  216. {5, nullptr, "DisableRadio"},
  217. {6, nullptr, "GetRadioOnOff"},
  218. {7, nullptr, "AcquireRadioEvent"},
  219. {8, nullptr, "AcquireGamepadPairingEvent"},
  220. {9, nullptr, "IsGamepadPairingStarted"},
  221. };
  222. // clang-format on
  223. RegisterHandlers(functions);
  224. }
  225. };
  226. class BTM_SYS final : public ServiceFramework<BTM_SYS> {
  227. public:
  228. explicit BTM_SYS() : ServiceFramework{"btm:sys"} {
  229. // clang-format off
  230. static const FunctionInfo functions[] = {
  231. {0, &BTM_SYS::GetCore, "GetCore"},
  232. };
  233. // clang-format on
  234. RegisterHandlers(functions);
  235. }
  236. private:
  237. void GetCore(Kernel::HLERequestContext& ctx) {
  238. LOG_DEBUG(Service_BTM, "called");
  239. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  240. rb.Push(RESULT_SUCCESS);
  241. rb.PushIpcInterface<IBtmSystemCore>();
  242. }
  243. };
  244. void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) {
  245. std::make_shared<BTM>()->InstallAsService(sm);
  246. std::make_shared<BTM_DBG>()->InstallAsService(sm);
  247. std::make_shared<BTM_SYS>()->InstallAsService(sm);
  248. std::make_shared<BTM_USR>(system)->InstallAsService(sm);
  249. }
  250. } // namespace Service::BTM