ldn.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 "core/hle/ipc_helpers.h"
  6. #include "core/hle/result.h"
  7. #include "core/hle/service/ldn/errors.h"
  8. #include "core/hle/service/ldn/ldn.h"
  9. #include "core/hle/service/sm/sm.h"
  10. namespace Service::LDN {
  11. class IMonitorService final : public ServiceFramework<IMonitorService> {
  12. public:
  13. explicit IMonitorService(Core::System& system_) : ServiceFramework{system_, "IMonitorService"} {
  14. // clang-format off
  15. static const FunctionInfo functions[] = {
  16. {0, nullptr, "GetStateForMonitor"},
  17. {1, nullptr, "GetNetworkInfoForMonitor"},
  18. {2, nullptr, "GetIpv4AddressForMonitor"},
  19. {3, nullptr, "GetDisconnectReasonForMonitor"},
  20. {4, nullptr, "GetSecurityParameterForMonitor"},
  21. {5, nullptr, "GetNetworkConfigForMonitor"},
  22. {100, nullptr, "InitializeMonitor"},
  23. {101, nullptr, "FinalizeMonitor"},
  24. };
  25. // clang-format on
  26. RegisterHandlers(functions);
  27. }
  28. };
  29. class LDNM final : public ServiceFramework<LDNM> {
  30. public:
  31. explicit LDNM(Core::System& system_) : ServiceFramework{system_, "ldn:m"} {
  32. // clang-format off
  33. static const FunctionInfo functions[] = {
  34. {0, &LDNM::CreateMonitorService, "CreateMonitorService"}
  35. };
  36. // clang-format on
  37. RegisterHandlers(functions);
  38. }
  39. void CreateMonitorService(Kernel::HLERequestContext& ctx) {
  40. LOG_DEBUG(Service_LDN, "called");
  41. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  42. rb.Push(RESULT_SUCCESS);
  43. rb.PushIpcInterface<IMonitorService>(system);
  44. }
  45. };
  46. class ISystemLocalCommunicationService final
  47. : public ServiceFramework<ISystemLocalCommunicationService> {
  48. public:
  49. explicit ISystemLocalCommunicationService(Core::System& system_)
  50. : ServiceFramework{system_, "ISystemLocalCommunicationService"} {
  51. // clang-format off
  52. static const FunctionInfo functions[] = {
  53. {0, nullptr, "GetState"},
  54. {1, nullptr, "GetNetworkInfo"},
  55. {2, nullptr, "GetIpv4Address"},
  56. {3, nullptr, "GetDisconnectReason"},
  57. {4, nullptr, "GetSecurityParameter"},
  58. {5, nullptr, "GetNetworkConfig"},
  59. {100, nullptr, "AttachStateChangeEvent"},
  60. {101, nullptr, "GetNetworkInfoLatestUpdate"},
  61. {102, nullptr, "Scan"},
  62. {103, nullptr, "ScanPrivate"},
  63. {104, nullptr, "SetWirelessControllerRestriction"},
  64. {200, nullptr, "OpenAccessPoint"},
  65. {201, nullptr, "CloseAccessPoint"},
  66. {202, nullptr, "CreateNetwork"},
  67. {203, nullptr, "CreateNetworkPrivate"},
  68. {204, nullptr, "DestroyNetwork"},
  69. {205, nullptr, "Reject"},
  70. {206, nullptr, "SetAdvertiseData"},
  71. {207, nullptr, "SetStationAcceptPolicy"},
  72. {208, nullptr, "AddAcceptFilterEntry"},
  73. {209, nullptr, "ClearAcceptFilter"},
  74. {300, nullptr, "OpenStation"},
  75. {301, nullptr, "CloseStation"},
  76. {302, nullptr, "Connect"},
  77. {303, nullptr, "ConnectPrivate"},
  78. {304, nullptr, "Disconnect"},
  79. {400, nullptr, "InitializeSystem"},
  80. {401, nullptr, "FinalizeSystem"},
  81. {402, nullptr, "SetOperationMode"},
  82. {403, nullptr, "InitializeSystem2"},
  83. };
  84. // clang-format on
  85. RegisterHandlers(functions);
  86. }
  87. };
  88. class IUserLocalCommunicationService final
  89. : public ServiceFramework<IUserLocalCommunicationService> {
  90. public:
  91. explicit IUserLocalCommunicationService(Core::System& system_)
  92. : ServiceFramework{system_, "IUserLocalCommunicationService"} {
  93. // clang-format off
  94. static const FunctionInfo functions[] = {
  95. {0, &IUserLocalCommunicationService::GetState, "GetState"},
  96. {1, nullptr, "GetNetworkInfo"},
  97. {2, nullptr, "GetIpv4Address"},
  98. {3, nullptr, "GetDisconnectReason"},
  99. {4, nullptr, "GetSecurityParameter"},
  100. {5, nullptr, "GetNetworkConfig"},
  101. {100, nullptr, "AttachStateChangeEvent"},
  102. {101, nullptr, "GetNetworkInfoLatestUpdate"},
  103. {102, nullptr, "Scan"},
  104. {103, nullptr, "ScanPrivate"},
  105. {104, nullptr, "SetWirelessControllerRestriction"},
  106. {200, nullptr, "OpenAccessPoint"},
  107. {201, nullptr, "CloseAccessPoint"},
  108. {202, nullptr, "CreateNetwork"},
  109. {203, nullptr, "CreateNetworkPrivate"},
  110. {204, nullptr, "DestroyNetwork"},
  111. {205, nullptr, "Reject"},
  112. {206, nullptr, "SetAdvertiseData"},
  113. {207, nullptr, "SetStationAcceptPolicy"},
  114. {208, nullptr, "AddAcceptFilterEntry"},
  115. {209, nullptr, "ClearAcceptFilter"},
  116. {300, nullptr, "OpenStation"},
  117. {301, nullptr, "CloseStation"},
  118. {302, nullptr, "Connect"},
  119. {303, nullptr, "ConnectPrivate"},
  120. {304, nullptr, "Disconnect"},
  121. {400, nullptr, "Initialize"},
  122. {401, nullptr, "Finalize"},
  123. {402, &IUserLocalCommunicationService::Initialize2, "Initialize2"}, // 7.0.0+
  124. };
  125. // clang-format on
  126. RegisterHandlers(functions);
  127. }
  128. void GetState(Kernel::HLERequestContext& ctx) {
  129. LOG_WARNING(Service_LDN, "(STUBBED) called");
  130. IPC::ResponseBuilder rb{ctx, 3};
  131. // Indicate a network error, as we do not actually emulate LDN
  132. rb.Push(static_cast<u32>(State::Error));
  133. rb.Push(RESULT_SUCCESS);
  134. }
  135. void Initialize2(Kernel::HLERequestContext& ctx) {
  136. LOG_DEBUG(Service_LDN, "called");
  137. is_initialized = true;
  138. IPC::ResponseBuilder rb{ctx, 2};
  139. rb.Push(ERROR_DISABLED);
  140. }
  141. private:
  142. enum class State {
  143. None,
  144. Initialized,
  145. AccessPointOpened,
  146. AccessPointCreated,
  147. StationOpened,
  148. StationConnected,
  149. Error,
  150. };
  151. bool is_initialized{};
  152. };
  153. class LDNS final : public ServiceFramework<LDNS> {
  154. public:
  155. explicit LDNS(Core::System& system_) : ServiceFramework{system_, "ldn:s"} {
  156. // clang-format off
  157. static const FunctionInfo functions[] = {
  158. {0, &LDNS::CreateSystemLocalCommunicationService, "CreateSystemLocalCommunicationService"},
  159. };
  160. // clang-format on
  161. RegisterHandlers(functions);
  162. }
  163. void CreateSystemLocalCommunicationService(Kernel::HLERequestContext& ctx) {
  164. LOG_DEBUG(Service_LDN, "called");
  165. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  166. rb.Push(RESULT_SUCCESS);
  167. rb.PushIpcInterface<ISystemLocalCommunicationService>(system);
  168. }
  169. };
  170. class LDNU final : public ServiceFramework<LDNU> {
  171. public:
  172. explicit LDNU(Core::System& system_) : ServiceFramework{system_, "ldn:u"} {
  173. // clang-format off
  174. static const FunctionInfo functions[] = {
  175. {0, &LDNU::CreateUserLocalCommunicationService, "CreateUserLocalCommunicationService"},
  176. };
  177. // clang-format on
  178. RegisterHandlers(functions);
  179. }
  180. void CreateUserLocalCommunicationService(Kernel::HLERequestContext& ctx) {
  181. LOG_DEBUG(Service_LDN, "called");
  182. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  183. rb.Push(RESULT_SUCCESS);
  184. rb.PushIpcInterface<IUserLocalCommunicationService>(system);
  185. }
  186. };
  187. void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) {
  188. std::make_shared<LDNM>(system)->InstallAsService(sm);
  189. std::make_shared<LDNS>(system)->InstallAsService(sm);
  190. std::make_shared<LDNU>(system)->InstallAsService(sm);
  191. }
  192. } // namespace Service::LDN