nfp.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/logging/log.h"
  5. #include "core/hle/ipc_helpers.h"
  6. #include "core/hle/kernel/event.h"
  7. #include "core/hle/service/nfp/nfp.h"
  8. #include "core/hle/service/nfp/nfp_user.h"
  9. namespace Service::NFP {
  10. Module::Interface::Interface(std::shared_ptr<Module> module, const char* name)
  11. : ServiceFramework(name), module(std::move(module)) {}
  12. class IUser final : public ServiceFramework<IUser> {
  13. public:
  14. IUser() : ServiceFramework("IUser") {
  15. static const FunctionInfo functions[] = {
  16. {0, &IUser::Initialize, "Initialize"},
  17. {1, nullptr, "Finalize"},
  18. {2, &IUser::ListDevices, "ListDevices"},
  19. {3, nullptr, "StartDetection"},
  20. {4, nullptr, "StopDetection"},
  21. {5, nullptr, "Mount"},
  22. {6, nullptr, "Unmount"},
  23. {7, nullptr, "OpenApplicationArea"},
  24. {8, nullptr, "GetApplicationArea"},
  25. {9, nullptr, "SetApplicationArea"},
  26. {10, nullptr, "Flush"},
  27. {11, nullptr, "Restore"},
  28. {12, nullptr, "CreateApplicationArea"},
  29. {13, nullptr, "GetTagInfo"},
  30. {14, nullptr, "GetRegisterInfo"},
  31. {15, nullptr, "GetCommonInfo"},
  32. {16, nullptr, "GetModelInfo"},
  33. {17, &IUser::AttachActivateEvent, "AttachActivateEvent"},
  34. {18, &IUser::AttachDeactivateEvent, "AttachDeactivateEvent"},
  35. {19, &IUser::GetState, "GetState"},
  36. {20, &IUser::GetDeviceState, "GetDeviceState"},
  37. {21, &IUser::GetNpadId, "GetNpadId"},
  38. {22, nullptr, "GetApplicationArea2"},
  39. {23, nullptr, "AttachAvailabilityChangeEvent"},
  40. {24, nullptr, "RecreateApplicationArea"},
  41. };
  42. RegisterHandlers(functions);
  43. activate_event = Kernel::Event::Create(Kernel::ResetType::OneShot, "IUser:ActivateEvent");
  44. deactivate_event =
  45. Kernel::Event::Create(Kernel::ResetType::OneShot, "IUser:DeactivateEvent");
  46. }
  47. private:
  48. enum class State : u32 {
  49. NonInitialized = 0,
  50. Initialized = 1,
  51. };
  52. enum class DeviceState : u32 {
  53. Initialized = 0,
  54. };
  55. void Initialize(Kernel::HLERequestContext& ctx) {
  56. NGLOG_WARNING(Service_NFP, "(STUBBED) called");
  57. state = State::Initialized;
  58. IPC::ResponseBuilder rb{ctx, 2};
  59. rb.Push(RESULT_SUCCESS);
  60. }
  61. void ListDevices(Kernel::HLERequestContext& ctx) {
  62. NGLOG_WARNING(Service_NFP, "(STUBBED) called");
  63. IPC::ResponseBuilder rb{ctx, 3};
  64. rb.Push(RESULT_SUCCESS);
  65. rb.Push<u32>(0);
  66. }
  67. void AttachActivateEvent(Kernel::HLERequestContext& ctx) {
  68. NGLOG_WARNING(Service_NFP, "(STUBBED) called");
  69. IPC::ResponseBuilder rb{ctx, 2, 1};
  70. rb.Push(RESULT_SUCCESS);
  71. rb.PushCopyObjects(activate_event);
  72. }
  73. void AttachDeactivateEvent(Kernel::HLERequestContext& ctx) {
  74. NGLOG_WARNING(Service_NFP, "(STUBBED) called");
  75. IPC::ResponseBuilder rb{ctx, 2, 1};
  76. rb.Push(RESULT_SUCCESS);
  77. rb.PushCopyObjects(deactivate_event);
  78. }
  79. void GetState(Kernel::HLERequestContext& ctx) {
  80. NGLOG_WARNING(Service_NFP, "(STUBBED) called");
  81. IPC::ResponseBuilder rb{ctx, 3};
  82. rb.Push(RESULT_SUCCESS);
  83. rb.Push<u32>(static_cast<u32>(state));
  84. }
  85. void GetDeviceState(Kernel::HLERequestContext& ctx) {
  86. NGLOG_WARNING(Service_NFP, "(STUBBED) called");
  87. IPC::ResponseBuilder rb{ctx, 3};
  88. rb.Push(RESULT_SUCCESS);
  89. rb.Push<u32>(static_cast<u32>(device_state));
  90. }
  91. void GetNpadId(Kernel::HLERequestContext& ctx) {
  92. NGLOG_WARNING(Service_NFP, "(STUBBED) called");
  93. IPC::ResponseBuilder rb{ctx, 3};
  94. rb.Push(RESULT_SUCCESS);
  95. rb.Push<u32>(0);
  96. }
  97. State state{State::NonInitialized};
  98. DeviceState device_state{DeviceState::Initialized};
  99. Kernel::SharedPtr<Kernel::Event> activate_event;
  100. Kernel::SharedPtr<Kernel::Event> deactivate_event;
  101. };
  102. void Module::Interface::CreateUserInterface(Kernel::HLERequestContext& ctx) {
  103. NGLOG_DEBUG(Service_NFP, "called");
  104. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  105. rb.Push(RESULT_SUCCESS);
  106. rb.PushIpcInterface<IUser>();
  107. }
  108. void InstallInterfaces(SM::ServiceManager& service_manager) {
  109. auto module = std::make_shared<Module>();
  110. std::make_shared<NFP_User>(module)->InstallAsService(service_manager);
  111. }
  112. } // namespace Service::NFP