nfc.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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 "common/settings.h"
  7. #include "core/hle/ipc_helpers.h"
  8. #include "core/hle/kernel/hle_ipc.h"
  9. #include "core/hle/service/nfc/nfc.h"
  10. #include "core/hle/service/service.h"
  11. #include "core/hle/service/sm/sm.h"
  12. namespace Service::NFC {
  13. class IAm final : public ServiceFramework<IAm> {
  14. public:
  15. explicit IAm(Core::System& system_) : ServiceFramework{system_, "NFC::IAm"} {
  16. // clang-format off
  17. static const FunctionInfo functions[] = {
  18. {0, nullptr, "Initialize"},
  19. {1, nullptr, "Finalize"},
  20. {2, nullptr, "NotifyForegroundApplet"},
  21. };
  22. // clang-format on
  23. RegisterHandlers(functions);
  24. }
  25. };
  26. class NFC_AM final : public ServiceFramework<NFC_AM> {
  27. public:
  28. explicit NFC_AM(Core::System& system_) : ServiceFramework{system_, "nfc:am"} {
  29. // clang-format off
  30. static const FunctionInfo functions[] = {
  31. {0, &NFC_AM::CreateAmInterface, "CreateAmInterface"},
  32. };
  33. // clang-format on
  34. RegisterHandlers(functions);
  35. }
  36. private:
  37. void CreateAmInterface(Kernel::HLERequestContext& ctx) {
  38. LOG_DEBUG(Service_NFC, "called");
  39. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  40. rb.Push(RESULT_SUCCESS);
  41. rb.PushIpcInterface<IAm>(system);
  42. }
  43. };
  44. class MFIUser final : public ServiceFramework<MFIUser> {
  45. public:
  46. explicit MFIUser(Core::System& system_) : ServiceFramework{system_, "NFC::MFIUser"} {
  47. // clang-format off
  48. static const FunctionInfo functions[] = {
  49. {0, nullptr, "Initialize"},
  50. {1, nullptr, "Finalize"},
  51. {2, nullptr, "ListDevices"},
  52. {3, nullptr, "StartDetection"},
  53. {4, nullptr, "StopDetection"},
  54. {5, nullptr, "Read"},
  55. {6, nullptr, "Write"},
  56. {7, nullptr, "GetTagInfo"},
  57. {8, nullptr, "GetActivateEventHandle"},
  58. {9, nullptr, "GetDeactivateEventHandle"},
  59. {10, nullptr, "GetState"},
  60. {11, nullptr, "GetDeviceState"},
  61. {12, nullptr, "GetNpadId"},
  62. {13, nullptr, "GetAvailabilityChangeEventHandle"},
  63. };
  64. // clang-format on
  65. RegisterHandlers(functions);
  66. }
  67. };
  68. class NFC_MF_U final : public ServiceFramework<NFC_MF_U> {
  69. public:
  70. explicit NFC_MF_U(Core::System& system_) : ServiceFramework{system_, "nfc:mf:u"} {
  71. // clang-format off
  72. static const FunctionInfo functions[] = {
  73. {0, &NFC_MF_U::CreateUserInterface, "CreateUserInterface"},
  74. };
  75. // clang-format on
  76. RegisterHandlers(functions);
  77. }
  78. private:
  79. void CreateUserInterface(Kernel::HLERequestContext& ctx) {
  80. LOG_DEBUG(Service_NFC, "called");
  81. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  82. rb.Push(RESULT_SUCCESS);
  83. rb.PushIpcInterface<MFIUser>(system);
  84. }
  85. };
  86. class IUser final : public ServiceFramework<IUser> {
  87. public:
  88. explicit IUser(Core::System& system_) : ServiceFramework{system_, "NFC::IUser"} {
  89. // clang-format off
  90. static const FunctionInfo functions[] = {
  91. {0, &IUser::InitializeOld, "InitializeOld"},
  92. {1, &IUser::FinalizeOld, "FinalizeOld"},
  93. {2, &IUser::GetStateOld, "GetStateOld"},
  94. {3, &IUser::IsNfcEnabledOld, "IsNfcEnabledOld"},
  95. {400, nullptr, "Initialize"},
  96. {401, nullptr, "Finalize"},
  97. {402, nullptr, "GetState"},
  98. {403, nullptr, "IsNfcEnabled"},
  99. {404, nullptr, "ListDevices"},
  100. {405, nullptr, "GetDeviceState"},
  101. {406, nullptr, "GetNpadId"},
  102. {407, nullptr, "AttachAvailabilityChangeEvent"},
  103. {408, nullptr, "StartDetection"},
  104. {409, nullptr, "StopDetection"},
  105. {410, nullptr, "GetTagInfo"},
  106. {411, nullptr, "AttachActivateEvent"},
  107. {412, nullptr, "AttachDeactivateEvent"},
  108. {1000, nullptr, "ReadMifare"},
  109. {1001, nullptr, "WriteMifare"},
  110. {1300, nullptr, "SendCommandByPassThrough"},
  111. {1301, nullptr, "KeepPassThroughSession"},
  112. {1302, nullptr, "ReleasePassThroughSession"},
  113. };
  114. // clang-format on
  115. RegisterHandlers(functions);
  116. }
  117. private:
  118. enum class NfcStates : u32 {
  119. Finalized = 6,
  120. };
  121. void InitializeOld(Kernel::HLERequestContext& ctx) {
  122. LOG_DEBUG(Service_NFC, "called");
  123. IPC::ResponseBuilder rb{ctx, 2, 0};
  124. rb.Push(RESULT_SUCCESS);
  125. // We don't deal with hardware initialization so we can just stub this.
  126. }
  127. void IsNfcEnabledOld(Kernel::HLERequestContext& ctx) {
  128. LOG_DEBUG(Service_NFC, "IsNfcEnabledOld");
  129. IPC::ResponseBuilder rb{ctx, 3};
  130. rb.Push(RESULT_SUCCESS);
  131. rb.PushRaw<u8>(true);
  132. }
  133. void GetStateOld(Kernel::HLERequestContext& ctx) {
  134. LOG_WARNING(Service_NFC, "(STUBBED) called");
  135. IPC::ResponseBuilder rb{ctx, 3};
  136. rb.Push(RESULT_SUCCESS);
  137. rb.PushEnum(NfcStates::Finalized); // TODO(ogniK): Figure out if this matches nfp
  138. }
  139. void FinalizeOld(Kernel::HLERequestContext& ctx) {
  140. LOG_WARNING(Service_NFC, "(STUBBED) called");
  141. IPC::ResponseBuilder rb{ctx, 2};
  142. rb.Push(RESULT_SUCCESS);
  143. }
  144. };
  145. class NFC_U final : public ServiceFramework<NFC_U> {
  146. public:
  147. explicit NFC_U(Core::System& system_) : ServiceFramework{system_, "nfc:user"} {
  148. // clang-format off
  149. static const FunctionInfo functions[] = {
  150. {0, &NFC_U::CreateUserInterface, "CreateUserInterface"},
  151. };
  152. // clang-format on
  153. RegisterHandlers(functions);
  154. }
  155. private:
  156. void CreateUserInterface(Kernel::HLERequestContext& ctx) {
  157. LOG_DEBUG(Service_NFC, "called");
  158. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  159. rb.Push(RESULT_SUCCESS);
  160. rb.PushIpcInterface<IUser>(system);
  161. }
  162. };
  163. class ISystem final : public ServiceFramework<ISystem> {
  164. public:
  165. explicit ISystem(Core::System& system_) : ServiceFramework{system_, "ISystem"} {
  166. // clang-format off
  167. static const FunctionInfo functions[] = {
  168. {0, nullptr, "Initialize"},
  169. {1, nullptr, "Finalize"},
  170. {2, nullptr, "GetStateOld"},
  171. {3, nullptr, "IsNfcEnabledOld"},
  172. {100, nullptr, "SetNfcEnabledOld"},
  173. {400, nullptr, "InitializeSystem"},
  174. {401, nullptr, "FinalizeSystem"},
  175. {402, nullptr, "GetState"},
  176. {403, nullptr, "IsNfcEnabled"},
  177. {404, nullptr, "ListDevices"},
  178. {405, nullptr, "GetDeviceState"},
  179. {406, nullptr, "GetNpadId"},
  180. {407, nullptr, "AttachAvailabilityChangeEvent"},
  181. {408, nullptr, "StartDetection"},
  182. {409, nullptr, "StopDetection"},
  183. {410, nullptr, "GetTagInfo"},
  184. {411, nullptr, "AttachActivateEvent"},
  185. {412, nullptr, "AttachDeactivateEvent"},
  186. {500, nullptr, "SetNfcEnabled"},
  187. {510, nullptr, "OutputTestWave"},
  188. {1000, nullptr, "ReadMifare"},
  189. {1001, nullptr, "WriteMifare"},
  190. {1300, nullptr, "SendCommandByPassThrough"},
  191. {1301, nullptr, "KeepPassThroughSession"},
  192. {1302, nullptr, "ReleasePassThroughSession"},
  193. };
  194. // clang-format on
  195. RegisterHandlers(functions);
  196. }
  197. };
  198. class NFC_SYS final : public ServiceFramework<NFC_SYS> {
  199. public:
  200. explicit NFC_SYS(Core::System& system_) : ServiceFramework{system_, "nfc:sys"} {
  201. // clang-format off
  202. static const FunctionInfo functions[] = {
  203. {0, &NFC_SYS::CreateSystemInterface, "CreateSystemInterface"},
  204. };
  205. // clang-format on
  206. RegisterHandlers(functions);
  207. }
  208. private:
  209. void CreateSystemInterface(Kernel::HLERequestContext& ctx) {
  210. LOG_DEBUG(Service_NFC, "called");
  211. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  212. rb.Push(RESULT_SUCCESS);
  213. rb.PushIpcInterface<ISystem>(system);
  214. }
  215. };
  216. void InstallInterfaces(SM::ServiceManager& sm, Core::System& system) {
  217. std::make_shared<NFC_AM>(system)->InstallAsService(sm);
  218. std::make_shared<NFC_MF_U>(system)->InstallAsService(sm);
  219. std::make_shared<NFC_U>(system)->InstallAsService(sm);
  220. std::make_shared<NFC_SYS>(system)->InstallAsService(sm);
  221. }
  222. } // namespace Service::NFC