nfc.cpp 8.0 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 "core/hle/ipc_helpers.h"
  7. #include "core/hle/kernel/hle_ipc.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. #include "core/settings.h"
  12. namespace Service::NFC {
  13. class IAm final : public ServiceFramework<IAm> {
  14. public:
  15. explicit IAm() : ServiceFramework{"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() : ServiceFramework{"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. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  39. rb.Push(RESULT_SUCCESS);
  40. rb.PushIpcInterface<IAm>();
  41. LOG_DEBUG(Service_NFC, "called");
  42. }
  43. };
  44. class MFIUser final : public ServiceFramework<MFIUser> {
  45. public:
  46. explicit MFIUser() : ServiceFramework{"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() : ServiceFramework{"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. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  81. rb.Push(RESULT_SUCCESS);
  82. rb.PushIpcInterface<MFIUser>();
  83. LOG_DEBUG(Service_NFC, "called");
  84. }
  85. };
  86. class IUser final : public ServiceFramework<IUser> {
  87. public:
  88. explicit IUser() : ServiceFramework{"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. IPC::ResponseBuilder rb{ctx, 2, 0};
  123. rb.Push(RESULT_SUCCESS);
  124. // We don't deal with hardware initialization so we can just stub this.
  125. LOG_DEBUG(Service_NFC, "called");
  126. }
  127. void IsNfcEnabledOld(Kernel::HLERequestContext& ctx) {
  128. IPC::ResponseBuilder rb{ctx, 3};
  129. rb.Push(RESULT_SUCCESS);
  130. rb.PushRaw<u8>(Settings::values.enable_nfc);
  131. LOG_DEBUG(Service_NFC, "IsNfcEnabledOld");
  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() : ServiceFramework{"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. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  158. rb.Push(RESULT_SUCCESS);
  159. rb.PushIpcInterface<IUser>();
  160. LOG_DEBUG(Service_NFC, "called");
  161. }
  162. };
  163. class ISystem final : public ServiceFramework<ISystem> {
  164. public:
  165. explicit ISystem() : ServiceFramework{"ISystem"} {
  166. // clang-format off
  167. static const FunctionInfo functions[] = {
  168. {0, nullptr, "Initialize"},
  169. {1, nullptr, "Finalize"},
  170. {2, nullptr, "GetState"},
  171. {3, nullptr, "IsNfcEnabled"},
  172. {100, nullptr, "SetNfcEnabled"},
  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. {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() : ServiceFramework{"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. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  210. rb.Push(RESULT_SUCCESS);
  211. rb.PushIpcInterface<ISystem>();
  212. LOG_DEBUG(Service_NFC, "called");
  213. }
  214. };
  215. void InstallInterfaces(SM::ServiceManager& sm) {
  216. std::make_shared<NFC_AM>()->InstallAsService(sm);
  217. std::make_shared<NFC_MF_U>()->InstallAsService(sm);
  218. std::make_shared<NFC_U>()->InstallAsService(sm);
  219. std::make_shared<NFC_SYS>()->InstallAsService(sm);
  220. }
  221. } // namespace Service::NFC