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