ldn.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. class INetworkService final : public ServiceFramework<INetworkService> {
  188. public:
  189. explicit INetworkService(Core::System& system_) : ServiceFramework{system_, "INetworkService"} {
  190. // clang-format off
  191. static const FunctionInfo functions[] = {
  192. {0, nullptr, "Initialize"},
  193. {256, nullptr, "AttachNetworkInterfaceStateChangeEvent"},
  194. {264, nullptr, "GetNetworkInterfaceLastError"},
  195. {272, nullptr, "GetRole"},
  196. {280, nullptr, "GetAdvertiseData"},
  197. {288, nullptr, "GetGroupInfo"},
  198. {296, nullptr, "GetGroupInfo2"},
  199. {304, nullptr, "GetGroupOwner"},
  200. {312, nullptr, "GetIpConfig"},
  201. {320, nullptr, "GetLinkLevel"},
  202. {512, nullptr, "Scan"},
  203. {768, nullptr, "CreateGroup"},
  204. {776, nullptr, "DestroyGroup"},
  205. {784, nullptr, "SetAdvertiseData"},
  206. {1536, nullptr, "SendToOtherGroup"},
  207. {1544, nullptr, "RecvFromOtherGroup"},
  208. {1552, nullptr, "AddAcceptableGroupId"},
  209. {1560, nullptr, "ClearAcceptableGroupId"},
  210. };
  211. // clang-format on
  212. RegisterHandlers(functions);
  213. }
  214. };
  215. class INetworkServiceMonitor final : public ServiceFramework<INetworkServiceMonitor> {
  216. public:
  217. explicit INetworkServiceMonitor(Core::System& system_)
  218. : ServiceFramework{system_, "INetworkServiceMonitor"} {
  219. // clang-format off
  220. static const FunctionInfo functions[] = {
  221. {0, &INetworkServiceMonitor::Initialize, "Initialize"},
  222. {256, nullptr, "AttachNetworkInterfaceStateChangeEvent"},
  223. {264, nullptr, "GetNetworkInterfaceLastError"},
  224. {272, nullptr, "GetRole"},
  225. {280, nullptr, "GetAdvertiseData"},
  226. {281, nullptr, "GetAdvertiseData2"},
  227. {288, nullptr, "GetGroupInfo"},
  228. {296, nullptr, "GetGroupInfo2"},
  229. {304, nullptr, "GetGroupOwner"},
  230. {312, nullptr, "GetIpConfig"},
  231. {320, nullptr, "GetLinkLevel"},
  232. {328, nullptr, "AttachJoinEvent"},
  233. {336, nullptr, "GetMembers"},
  234. };
  235. // clang-format on
  236. RegisterHandlers(functions);
  237. }
  238. void Initialize(Kernel::HLERequestContext& ctx) {
  239. LOG_WARNING(Service_LDN, "(STUBBED) called");
  240. IPC::ResponseBuilder rb{ctx, 2};
  241. rb.Push(ERROR_DISABLED);
  242. }
  243. };
  244. class LP2PAPP final : public ServiceFramework<LP2PAPP> {
  245. public:
  246. explicit LP2PAPP(Core::System& system_) : ServiceFramework{system_, "lp2p:app"} {
  247. // clang-format off
  248. static const FunctionInfo functions[] = {
  249. {0, &LP2PAPP::CreateMonitorService, "CreateNetworkService"},
  250. {8, &LP2PAPP::CreateMonitorService, "CreateNetworkServiceMonitor"},
  251. };
  252. // clang-format on
  253. RegisterHandlers(functions);
  254. }
  255. void CreateNetworkervice(Kernel::HLERequestContext& ctx) {
  256. IPC::RequestParser rp{ctx};
  257. const u64 reserved_input = rp.Pop<u64>();
  258. const u32 input = rp.Pop<u32>();
  259. LOG_WARNING(Service_LDN, "(STUBBED) called reserved_input={} input={}", reserved_input,
  260. input);
  261. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  262. rb.Push(RESULT_SUCCESS);
  263. rb.PushIpcInterface<INetworkService>(system);
  264. }
  265. void CreateMonitorService(Kernel::HLERequestContext& ctx) {
  266. IPC::RequestParser rp{ctx};
  267. const u64 reserved_input = rp.Pop<u64>();
  268. LOG_WARNING(Service_LDN, "(STUBBED) called reserved_input={}", reserved_input);
  269. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  270. rb.Push(RESULT_SUCCESS);
  271. rb.PushIpcInterface<INetworkServiceMonitor>(system);
  272. }
  273. };
  274. class LP2PSYS final : public ServiceFramework<LP2PSYS> {
  275. public:
  276. explicit LP2PSYS(Core::System& system_) : ServiceFramework{system_, "lp2p:sys"} {
  277. // clang-format off
  278. static const FunctionInfo functions[] = {
  279. {0, &LP2PSYS::CreateMonitorService, "CreateNetworkService"},
  280. {8, &LP2PSYS::CreateMonitorService, "CreateNetworkServiceMonitor"},
  281. };
  282. // clang-format on
  283. RegisterHandlers(functions);
  284. }
  285. void CreateNetworkervice(Kernel::HLERequestContext& ctx) {
  286. IPC::RequestParser rp{ctx};
  287. const u64 reserved_input = rp.Pop<u64>();
  288. const u32 input = rp.Pop<u32>();
  289. LOG_WARNING(Service_LDN, "(STUBBED) called reserved_input={} input={}", reserved_input,
  290. input);
  291. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  292. rb.Push(RESULT_SUCCESS);
  293. rb.PushIpcInterface<INetworkService>(system);
  294. }
  295. void CreateMonitorService(Kernel::HLERequestContext& ctx) {
  296. IPC::RequestParser rp{ctx};
  297. const u64 reserved_input = rp.Pop<u64>();
  298. LOG_WARNING(Service_LDN, "(STUBBED) called reserved_input={}", reserved_input);
  299. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  300. rb.Push(RESULT_SUCCESS);
  301. rb.PushIpcInterface<INetworkServiceMonitor>(system);
  302. }
  303. };
  304. void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) {
  305. std::make_shared<LDNM>(system)->InstallAsService(sm);
  306. std::make_shared<LDNS>(system)->InstallAsService(sm);
  307. std::make_shared<LDNU>(system)->InstallAsService(sm);
  308. std::make_shared<LP2PAPP>(system)->InstallAsService(sm);
  309. std::make_shared<LP2PSYS>(system)->InstallAsService(sm);
  310. }
  311. } // namespace Service::LDN