nfc.cpp 8.3 KB

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