btdrv.cpp 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/logging/log.h"
  5. #include "core/core.h"
  6. #include "core/hle/ipc_helpers.h"
  7. #include "core/hle/kernel/hle_ipc.h"
  8. #include "core/hle/kernel/k_event.h"
  9. #include "core/hle/kernel/kernel.h"
  10. #include "core/hle/service/btdrv/btdrv.h"
  11. #include "core/hle/service/kernel_helpers.h"
  12. #include "core/hle/service/service.h"
  13. #include "core/hle/service/sm/sm.h"
  14. namespace Service::BtDrv {
  15. class Bt final : public ServiceFramework<Bt> {
  16. public:
  17. explicit Bt(Core::System& system_)
  18. : ServiceFramework{system_, "bt"}, service_context{system_, "bt"} {
  19. // clang-format off
  20. static const FunctionInfo functions[] = {
  21. {0, nullptr, "LeClientReadCharacteristic"},
  22. {1, nullptr, "LeClientReadDescriptor"},
  23. {2, nullptr, "LeClientWriteCharacteristic"},
  24. {3, nullptr, "LeClientWriteDescriptor"},
  25. {4, nullptr, "LeClientRegisterNotification"},
  26. {5, nullptr, "LeClientDeregisterNotification"},
  27. {6, nullptr, "SetLeResponse"},
  28. {7, nullptr, "LeSendIndication"},
  29. {8, nullptr, "GetLeEventInfo"},
  30. {9, &Bt::RegisterBleEvent, "RegisterBleEvent"},
  31. };
  32. // clang-format on
  33. RegisterHandlers(functions);
  34. register_event = service_context.CreateEvent("BT:RegisterEvent");
  35. }
  36. ~Bt() override {
  37. service_context.CloseEvent(register_event);
  38. }
  39. private:
  40. void RegisterBleEvent(Kernel::HLERequestContext& ctx) {
  41. LOG_WARNING(Service_BTM, "(STUBBED) called");
  42. IPC::ResponseBuilder rb{ctx, 2, 1};
  43. rb.Push(ResultSuccess);
  44. rb.PushCopyObjects(register_event->GetReadableEvent());
  45. }
  46. KernelHelpers::ServiceContext service_context;
  47. Kernel::KEvent* register_event;
  48. };
  49. class BtDrv final : public ServiceFramework<BtDrv> {
  50. public:
  51. explicit BtDrv(Core::System& system_) : ServiceFramework{system_, "btdrv"} {
  52. // clang-format off
  53. static const FunctionInfo functions[] = {
  54. {0, nullptr, "InitializeBluetoothDriver"},
  55. {1, nullptr, "InitializeBluetooth"},
  56. {2, nullptr, "EnableBluetooth"},
  57. {3, nullptr, "DisableBluetooth"},
  58. {4, nullptr, "FinalizeBluetooth"},
  59. {5, nullptr, "GetAdapterProperties"},
  60. {6, nullptr, "GetAdapterProperty"},
  61. {7, nullptr, "SetAdapterProperty"},
  62. {8, nullptr, "StartInquiry"},
  63. {9, nullptr, "StopInquiry"},
  64. {10, nullptr, "CreateBond"},
  65. {11, nullptr, "RemoveBond"},
  66. {12, nullptr, "CancelBond"},
  67. {13, nullptr, "RespondToPinRequest"},
  68. {14, nullptr, "RespondToSspRequest"},
  69. {15, nullptr, "GetEventInfo"},
  70. {16, nullptr, "InitializeHid"},
  71. {17, nullptr, "OpenHidConnection"},
  72. {18, nullptr, "CloseHidConnection"},
  73. {19, nullptr, "WriteHidData"},
  74. {20, nullptr, "WriteHidData2"},
  75. {21, nullptr, "SetHidReport"},
  76. {22, nullptr, "GetHidReport"},
  77. {23, nullptr, "TriggerConnection"},
  78. {24, nullptr, "AddPairedDeviceInfo"},
  79. {25, nullptr, "GetPairedDeviceInfo"},
  80. {26, nullptr, "FinalizeHid"},
  81. {27, nullptr, "GetHidEventInfo"},
  82. {28, nullptr, "SetTsi"},
  83. {29, nullptr, "EnableBurstMode"},
  84. {30, nullptr, "SetZeroRetransmission"},
  85. {31, nullptr, "EnableMcMode"},
  86. {32, nullptr, "EnableLlrScan"},
  87. {33, nullptr, "DisableLlrScan"},
  88. {34, nullptr, "EnableRadio"},
  89. {35, nullptr, "SetVisibility"},
  90. {36, nullptr, "EnableTbfcScan"},
  91. {37, nullptr, "RegisterHidReportEvent"},
  92. {38, nullptr, "GetHidReportEventInfo"},
  93. {39, nullptr, "GetLatestPlr"},
  94. {40, nullptr, "GetPendingConnections"},
  95. {41, nullptr, "GetChannelMap"},
  96. {42, nullptr, "EnableTxPowerBoostSetting"},
  97. {43, nullptr, "IsTxPowerBoostSettingEnabled"},
  98. {44, nullptr, "EnableAfhSetting"},
  99. {45, nullptr, "IsAfhSettingEnabled"},
  100. {46, nullptr, "InitializeBle"},
  101. {47, nullptr, "EnableBle"},
  102. {48, nullptr, "DisableBle"},
  103. {49, nullptr, "FinalizeBle"},
  104. {50, nullptr, "SetBleVisibility"},
  105. {51, nullptr, "SetBleConnectionParameter"},
  106. {52, nullptr, "SetBleDefaultConnectionParameter"},
  107. {53, nullptr, "SetBleAdvertiseData"},
  108. {54, nullptr, "SetBleAdvertiseParameter"},
  109. {55, nullptr, "StartBleScan"},
  110. {56, nullptr, "StopBleScan"},
  111. {57, nullptr, "AddBleScanFilterCondition"},
  112. {58, nullptr, "DeleteBleScanFilterCondition"},
  113. {59, nullptr, "DeleteBleScanFilter"},
  114. {60, nullptr, "ClearBleScanFilters"},
  115. {61, nullptr, "EnableBleScanFilter"},
  116. {62, nullptr, "RegisterGattClient"},
  117. {63, nullptr, "UnregisterGattClient"},
  118. {64, nullptr, "UnregisterAllGattClients"},
  119. {65, nullptr, "ConnectGattServer"},
  120. {66, nullptr, "CancelConnectGattServer"},
  121. {67, nullptr, "DisconnectGattServer"},
  122. {68, nullptr, "GetGattAttribute"},
  123. {69, nullptr, "GetGattService"},
  124. {70, nullptr, "ConfigureAttMtu"},
  125. {71, nullptr, "RegisterGattServer"},
  126. {72, nullptr, "UnregisterGattServer"},
  127. {73, nullptr, "ConnectGattClient"},
  128. {74, nullptr, "DisconnectGattClient"},
  129. {75, nullptr, "AddGattService"},
  130. {76, nullptr, "EnableGattService"},
  131. {77, nullptr, "AddGattCharacteristic"},
  132. {78, nullptr, "AddGattDescriptor"},
  133. {79, nullptr, "GetBleManagedEventInfo"},
  134. {80, nullptr, "GetGattFirstCharacteristic"},
  135. {81, nullptr, "GetGattNextCharacteristic"},
  136. {82, nullptr, "GetGattFirstDescriptor"},
  137. {83, nullptr, "GetGattNextDescriptor"},
  138. {84, nullptr, "RegisterGattManagedDataPath"},
  139. {85, nullptr, "UnregisterGattManagedDataPath"},
  140. {86, nullptr, "RegisterGattHidDataPath"},
  141. {87, nullptr, "UnregisterGattHidDataPath"},
  142. {88, nullptr, "RegisterGattDataPath"},
  143. {89, nullptr, "UnregisterGattDataPath"},
  144. {90, nullptr, "ReadGattCharacteristic"},
  145. {91, nullptr, "ReadGattDescriptor"},
  146. {92, nullptr, "WriteGattCharacteristic"},
  147. {93, nullptr, "WriteGattDescriptor"},
  148. {94, nullptr, "RegisterGattNotification"},
  149. {95, nullptr, "UnregisterGattNotification"},
  150. {96, nullptr, "GetLeHidEventInfo"},
  151. {97, nullptr, "RegisterBleHidEvent"},
  152. {98, nullptr, "SetBleScanParameter"},
  153. {99, nullptr, "MoveToSecondaryPiconet"},
  154. {100, nullptr, "IsBluetoothEnabled"},
  155. {128, nullptr, "AcquireAudioEvent"},
  156. {129, nullptr, "GetAudioEventInfo"},
  157. {130, nullptr, "OpenAudioConnection"},
  158. {131, nullptr, "CloseAudioConnection"},
  159. {132, nullptr, "OpenAudioOut"},
  160. {133, nullptr, "CloseAudioOut"},
  161. {134, nullptr, "AcquireAudioOutStateChangedEvent"},
  162. {135, nullptr, "StartAudioOut"},
  163. {136, nullptr, "StopAudioOut"},
  164. {137, nullptr, "GetAudioOutState"},
  165. {138, nullptr, "GetAudioOutFeedingCodec"},
  166. {139, nullptr, "GetAudioOutFeedingParameter"},
  167. {140, nullptr, "AcquireAudioOutBufferAvailableEvent"},
  168. {141, nullptr, "SendAudioData"},
  169. {142, nullptr, "AcquireAudioControlInputStateChangedEvent"},
  170. {143, nullptr, "GetAudioControlInputState"},
  171. {144, nullptr, "AcquireAudioConnectionStateChangedEvent"},
  172. {145, nullptr, "GetConnectedAudioDevice"},
  173. {146, nullptr, "CloseAudioControlInput"},
  174. {147, nullptr, "RegisterAudioControlNotification"},
  175. {148, nullptr, "SendAudioControlPassthroughCommand"},
  176. {149, nullptr, "SendAudioControlSetAbsoluteVolumeCommand"},
  177. {256, nullptr, "IsManufacturingMode"},
  178. {257, nullptr, "EmulateBluetoothCrash"},
  179. {258, nullptr, "GetBleChannelMap"},
  180. };
  181. // clang-format on
  182. RegisterHandlers(functions);
  183. }
  184. };
  185. void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) {
  186. std::make_shared<BtDrv>(system)->InstallAsService(sm);
  187. std::make_shared<Bt>(system)->InstallAsService(sm);
  188. }
  189. } // namespace Service::BtDrv