nfp.cpp 4.9 KB

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