btm.cpp 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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, "Unknown1"},
  117. {1, nullptr, "Unknown2"},
  118. {2, nullptr, "RegisterSystemEventForConnectedDeviceCondition"},
  119. {3, nullptr, "Unknown3"},
  120. {4, nullptr, "Unknown4"},
  121. {5, nullptr, "Unknown5"},
  122. {6, nullptr, "Unknown6"},
  123. {7, nullptr, "Unknown7"},
  124. {8, nullptr, "RegisterSystemEventForRegisteredDeviceInfo"},
  125. {9, nullptr, "Unknown8"},
  126. {10, nullptr, "Unknown9"},
  127. {11, nullptr, "Unknown10"},
  128. {12, nullptr, "Unknown11"},
  129. {13, nullptr, "Unknown12"},
  130. {14, nullptr, "EnableRadio"},
  131. {15, nullptr, "DisableRadio"},
  132. {16, nullptr, "Unknown13"},
  133. {17, nullptr, "Unknown14"},
  134. {18, nullptr, "Unknown15"},
  135. {19, nullptr, "Unknown16"},
  136. {20, nullptr, "Unknown17"},
  137. {21, nullptr, "Unknown18"},
  138. {22, nullptr, "Unknown19"},
  139. {23, nullptr, "Unknown20"},
  140. {24, nullptr, "Unknown21"},
  141. {25, nullptr, "Unknown22"},
  142. {26, nullptr, "Unknown23"},
  143. {27, nullptr, "Unknown24"},
  144. {28, nullptr, "Unknown25"},
  145. {29, nullptr, "Unknown26"},
  146. {30, nullptr, "Unknown27"},
  147. {31, nullptr, "Unknown28"},
  148. {32, nullptr, "Unknown29"},
  149. {33, nullptr, "Unknown30"},
  150. {34, nullptr, "Unknown31"},
  151. {35, nullptr, "Unknown32"},
  152. {36, nullptr, "Unknown33"},
  153. {37, nullptr, "Unknown34"},
  154. {38, nullptr, "Unknown35"},
  155. {39, nullptr, "Unknown36"},
  156. {40, nullptr, "Unknown37"},
  157. {41, nullptr, "Unknown38"},
  158. {42, nullptr, "Unknown39"},
  159. {43, nullptr, "Unknown40"},
  160. {44, nullptr, "Unknown41"},
  161. {45, nullptr, "Unknown42"},
  162. {46, nullptr, "Unknown43"},
  163. {47, nullptr, "Unknown44"},
  164. {48, nullptr, "Unknown45"},
  165. {49, nullptr, "Unknown46"},
  166. {50, nullptr, "Unknown47"},
  167. {51, nullptr, "Unknown48"},
  168. {52, nullptr, "Unknown49"},
  169. {53, nullptr, "Unknown50"},
  170. {54, nullptr, "Unknown51"},
  171. {55, nullptr, "Unknown52"},
  172. {56, nullptr, "Unknown53"},
  173. {57, nullptr, "Unknown54"},
  174. {58, nullptr, "Unknown55"},
  175. {59, nullptr, "Unknown56"},
  176. };
  177. // clang-format on
  178. RegisterHandlers(functions);
  179. }
  180. };
  181. class BTM_DBG final : public ServiceFramework<BTM_DBG> {
  182. public:
  183. explicit BTM_DBG() : ServiceFramework{"btm:dbg"} {
  184. // clang-format off
  185. static const FunctionInfo functions[] = {
  186. {0, nullptr, "RegisterSystemEventForDiscovery"},
  187. {1, nullptr, "Unknown1"},
  188. {2, nullptr, "Unknown2"},
  189. {3, nullptr, "Unknown3"},
  190. {4, nullptr, "Unknown4"},
  191. {5, nullptr, "Unknown5"},
  192. {6, nullptr, "Unknown6"},
  193. {7, nullptr, "Unknown7"},
  194. {8, nullptr, "Unknown8"},
  195. {9, nullptr, "Unknown9"},
  196. {10, nullptr, "Unknown10"},
  197. {11, nullptr, "Unknown11"},
  198. {12, nullptr, "Unknown11"},
  199. };
  200. // clang-format on
  201. RegisterHandlers(functions);
  202. }
  203. };
  204. class IBtmSystemCore final : public ServiceFramework<IBtmSystemCore> {
  205. public:
  206. explicit IBtmSystemCore() : ServiceFramework{"IBtmSystemCore"} {
  207. // clang-format off
  208. static const FunctionInfo functions[] = {
  209. {0, nullptr, "StartGamepadPairing"},
  210. {1, nullptr, "CancelGamepadPairing"},
  211. {2, nullptr, "ClearGamepadPairingDatabase"},
  212. {3, nullptr, "GetPairedGamepadCount"},
  213. {4, nullptr, "EnableRadio"},
  214. {5, nullptr, "DisableRadio"},
  215. {6, nullptr, "GetRadioOnOff"},
  216. {7, nullptr, "AcquireRadioEvent"},
  217. {8, nullptr, "AcquireGamepadPairingEvent"},
  218. {9, nullptr, "IsGamepadPairingStarted"},
  219. };
  220. // clang-format on
  221. RegisterHandlers(functions);
  222. }
  223. };
  224. class BTM_SYS final : public ServiceFramework<BTM_SYS> {
  225. public:
  226. explicit BTM_SYS() : ServiceFramework{"btm:sys"} {
  227. // clang-format off
  228. static const FunctionInfo functions[] = {
  229. {0, &BTM_SYS::GetCore, "GetCore"},
  230. };
  231. // clang-format on
  232. RegisterHandlers(functions);
  233. }
  234. private:
  235. void GetCore(Kernel::HLERequestContext& ctx) {
  236. LOG_DEBUG(Service_BTM, "called");
  237. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  238. rb.Push(RESULT_SUCCESS);
  239. rb.PushIpcInterface<IBtmSystemCore>();
  240. }
  241. };
  242. void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) {
  243. std::make_shared<BTM>()->InstallAsService(sm);
  244. std::make_shared<BTM_DBG>()->InstallAsService(sm);
  245. std::make_shared<BTM_SYS>()->InstallAsService(sm);
  246. std::make_shared<BTM_USR>(system)->InstallAsService(sm);
  247. }
  248. } // namespace Service::BTM