nfp.cpp 5.9 KB

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