service: nfc: Implement SetNfcEnabled

This commit is contained in:
Narr the Reg 2024-02-23 12:38:43 -06:00
parent 624c90a439
commit 015d666a4d
5 changed files with 39 additions and 8 deletions

View File

@ -13,6 +13,7 @@
#include "core/hle/service/nfc/nfc_result.h"
#include "core/hle/service/psc/time/steady_clock.h"
#include "core/hle/service/service.h"
#include "core/hle/service/set/system_settings_server.h"
#include "core/hle/service/sm/sm.h"
#include "hid_core/hid_types.h"
#include "hid_core/hid_util.h"
@ -32,6 +33,9 @@ DeviceManager::DeviceManager(Core::System& system_, KernelHelpers::ServiceContex
}
is_initialized = false;
m_set_sys =
system.ServiceManager().GetService<Service::Set::ISystemSettingsServer>("set:sys", true);
}
DeviceManager ::~DeviceManager() {
@ -774,8 +778,8 @@ Result DeviceManager::CheckDeviceState(std::shared_ptr<NfcDevice> device) const
}
Result DeviceManager::IsNfcEnabled() const {
// TODO: This calls nn::settings::detail::GetNfcEnableFlag
const bool is_enabled = true;
bool is_enabled{};
R_TRY(m_set_sys->GetNfcEnableFlag(&is_enabled));
if (!is_enabled) {
return ResultNfcDisabled;
}

View File

@ -15,6 +15,10 @@
#include "core/hle/service/service.h"
#include "hid_core/hid_types.h"
namespace Service::Set {
class ISystemSettingsServer;
}
namespace Service::NFC {
class NfcDevice;
@ -98,6 +102,7 @@ private:
Core::System& system;
KernelHelpers::ServiceContext service_context;
Kernel::KEvent* availability_change_event;
std::shared_ptr<Service::Set::ISystemSettingsServer> m_set_sys;
};
} // namespace Service::NFC

View File

@ -57,7 +57,7 @@ public:
{1, &NfcInterface::Finalize, "FinalizeOld"},
{2, &NfcInterface::GetState, "GetStateOld"},
{3, &NfcInterface::IsNfcEnabled, "IsNfcEnabledOld"},
{100, nullptr, "SetNfcEnabledOld"},
{100, &NfcInterface::SetNfcEnabled, "SetNfcEnabledOld"},
{400, &NfcInterface::Initialize, "Initialize"},
{401, &NfcInterface::Finalize, "Finalize"},
{402, &NfcInterface::GetState, "GetState"},
@ -71,7 +71,7 @@ public:
{410, &NfcInterface::GetTagInfo, "GetTagInfo"},
{411, &NfcInterface::AttachActivateEvent, "AttachActivateEvent"},
{412, &NfcInterface::AttachDeactivateEvent, "AttachDeactivateEvent"},
{500, nullptr, "SetNfcEnabled"},
{500, &NfcInterface::SetNfcEnabled, "SetNfcEnabled"},
{510, nullptr, "OutputTestWave"},
{1000, &NfcInterface::ReadMifare, "ReadMifare"},
{1001, &NfcInterface::WriteMifare, "WriteMifare"},

View File

@ -13,13 +13,18 @@
#include "core/hle/service/nfc/nfc_result.h"
#include "core/hle/service/nfc/nfc_types.h"
#include "core/hle/service/nfp/nfp_result.h"
#include "core/hle/service/set/system_settings_server.h"
#include "core/hle/service/sm/sm.h"
#include "hid_core/hid_types.h"
namespace Service::NFC {
NfcInterface::NfcInterface(Core::System& system_, const char* name, BackendType service_backend)
: ServiceFramework{system_, name}, service_context{system_, service_name},
backend_type{service_backend} {}
backend_type{service_backend} {
m_set_sys =
system.ServiceManager().GetService<Service::Set::ISystemSettingsServer>("set:sys", true);
}
NfcInterface ::~NfcInterface() = default;
@ -65,11 +70,11 @@ void NfcInterface::GetState(HLERequestContext& ctx) {
void NfcInterface::IsNfcEnabled(HLERequestContext& ctx) {
LOG_DEBUG(Service_NFC, "called");
// TODO: This calls nn::settings::detail::GetNfcEnableFlag
const bool is_enabled = true;
bool is_enabled{};
const auto result = m_set_sys->GetNfcEnableFlag(&is_enabled);
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(ResultSuccess);
rb.Push(result);
rb.Push(is_enabled);
}
@ -212,6 +217,17 @@ void NfcInterface::AttachDeactivateEvent(HLERequestContext& ctx) {
rb.PushCopyObjects(out_event);
}
void NfcInterface::SetNfcEnabled(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const auto is_enabled{rp.Pop<bool>()};
LOG_DEBUG(Service_NFC, "called, is_enabled={}", is_enabled);
const auto result = m_set_sys->SetNfcEnableFlag(is_enabled);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(result);
}
void NfcInterface::ReadMifare(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const auto device_handle{rp.Pop<u64>()};

View File

@ -7,6 +7,10 @@
#include "core/hle/service/nfc/nfc_types.h"
#include "core/hle/service/service.h"
namespace Service::Set {
class ISystemSettingsServer;
}
namespace Service::NFC {
class DeviceManager;
@ -29,6 +33,7 @@ public:
void AttachActivateEvent(HLERequestContext& ctx);
void AttachDeactivateEvent(HLERequestContext& ctx);
void ReadMifare(HLERequestContext& ctx);
void SetNfcEnabled(HLERequestContext& ctx);
void WriteMifare(HLERequestContext& ctx);
void SendCommandByPassThrough(HLERequestContext& ctx);
@ -44,6 +49,7 @@ protected:
BackendType backend_type;
State state{State::NonInitialized};
std::shared_ptr<DeviceManager> device_manager = nullptr;
std::shared_ptr<Service::Set::ISystemSettingsServer> m_set_sys;
};
} // namespace Service::NFC