summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Narr the Reg2023-04-13 20:55:47 -0600
committerGravatar Narr the Reg2023-04-14 17:03:57 -0600
commit00800d5289f580ffebd38f18d1c3d7e024fc3b16 (patch)
treed0e0741f6d4db96784fa36f2b3c222c72ae15574
parentservice: nfp: Use an unique interface (diff)
downloadyuzu-00800d5289f580ffebd38f18d1c3d7e024fc3b16.tar.gz
yuzu-00800d5289f580ffebd38f18d1c3d7e024fc3b16.tar.xz
yuzu-00800d5289f580ffebd38f18d1c3d7e024fc3b16.zip
service: nfp: Implement system interface
Diffstat (limited to '')
-rw-r--r--src/core/hle/service/nfp/nfp.cpp32
-rw-r--r--src/core/hle/service/nfp/nfp_device.cpp52
-rw-r--r--src/core/hle/service/nfp/nfp_device.h2
-rw-r--r--src/core/hle/service/nfp/nfp_interface.cpp202
-rw-r--r--src/core/hle/service/nfp/nfp_interface.h9
-rw-r--r--src/core/hle/service/nfp/nfp_types.h9
6 files changed, 289 insertions, 17 deletions
diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp
index e57e932c8..8a7365f17 100644
--- a/src/core/hle/service/nfp/nfp.cpp
+++ b/src/core/hle/service/nfp/nfp.cpp
@@ -51,8 +51,8 @@ public:
51 explicit ISystem(Core::System& system_) : Interface(system_, "NFP:ISystem") { 51 explicit ISystem(Core::System& system_) : Interface(system_, "NFP:ISystem") {
52 // clang-format off 52 // clang-format off
53 static const FunctionInfo functions[] = { 53 static const FunctionInfo functions[] = {
54 {0, nullptr, "InitializeSystem"}, 54 {0, &ISystem::InitializeSystem, "InitializeSystem"},
55 {1, nullptr, "FinalizeSystem"}, 55 {1, &ISystem::FinalizeSystem, "FinalizeSystem"},
56 {2, &ISystem::ListDevices, "ListDevices"}, 56 {2, &ISystem::ListDevices, "ListDevices"},
57 {3, &ISystem::StartDetection, "StartDetection"}, 57 {3, &ISystem::StartDetection, "StartDetection"},
58 {4, &ISystem::StopDetection, "StopDetection"}, 58 {4, &ISystem::StopDetection, "StopDetection"},
@@ -71,13 +71,13 @@ public:
71 {20, &ISystem::GetDeviceState, "GetDeviceState"}, 71 {20, &ISystem::GetDeviceState, "GetDeviceState"},
72 {21, &ISystem::GetNpadId, "GetNpadId"}, 72 {21, &ISystem::GetNpadId, "GetNpadId"},
73 {23, &ISystem::AttachAvailabilityChangeEvent, "AttachAvailabilityChangeEvent"}, 73 {23, &ISystem::AttachAvailabilityChangeEvent, "AttachAvailabilityChangeEvent"},
74 {100, nullptr, "Format"}, 74 {100, &ISystem::Format, "Format"},
75 {101, nullptr, "GetAdminInfo"}, 75 {101, &ISystem::GetAdminInfo, "GetAdminInfo"},
76 {102, nullptr, "GetRegisterInfoPrivate"}, 76 {102, &ISystem::GetRegisterInfoPrivate, "GetRegisterInfoPrivate"},
77 {103, nullptr, "SetRegisterInfoPrivate"}, 77 {103, &ISystem::SetRegisterInfoPrivate, "SetRegisterInfoPrivate"},
78 {104, nullptr, "DeleteRegisterInfo"}, 78 {104, &ISystem::DeleteRegisterInfo, "DeleteRegisterInfo"},
79 {105, nullptr, "DeleteApplicationArea"}, 79 {105, &ISystem::DeleteApplicationArea, "DeleteApplicationArea"},
80 {106, nullptr, "ExistsApplicationArea"}, 80 {106, &ISystem::ExistsApplicationArea, "ExistsApplicationArea"},
81 }; 81 };
82 // clang-format on 82 // clang-format on
83 83
@@ -115,13 +115,13 @@ public:
115 {22, &IDebug::GetApplicationAreaSize, "GetApplicationAreaSize"}, 115 {22, &IDebug::GetApplicationAreaSize, "GetApplicationAreaSize"},
116 {23, &IDebug::AttachAvailabilityChangeEvent, "AttachAvailabilityChangeEvent"}, 116 {23, &IDebug::AttachAvailabilityChangeEvent, "AttachAvailabilityChangeEvent"},
117 {24, &IDebug::RecreateApplicationArea, "RecreateApplicationArea"}, 117 {24, &IDebug::RecreateApplicationArea, "RecreateApplicationArea"},
118 {100, nullptr, "Format"}, 118 {100, &IDebug::Format, "Format"},
119 {101, nullptr, "GetAdminInfo"}, 119 {101, &IDebug::GetAdminInfo, "GetAdminInfo"},
120 {102, nullptr, "GetRegisterInfoPrivate"}, 120 {102, &IDebug::GetRegisterInfoPrivate, "GetRegisterInfoPrivate"},
121 {103, nullptr, "SetRegisterInfoPrivate"}, 121 {103, &IDebug::SetRegisterInfoPrivate, "SetRegisterInfoPrivate"},
122 {104, nullptr, "DeleteRegisterInfo"}, 122 {104, &IDebug::DeleteRegisterInfo, "DeleteRegisterInfo"},
123 {105, nullptr, "DeleteApplicationArea"}, 123 {105, &IDebug::DeleteApplicationArea, "DeleteApplicationArea"},
124 {106, nullptr, "ExistsApplicationArea"}, 124 {106, &IDebug::ExistsApplicationArea, "ExistsApplicationArea"},
125 {200, nullptr, "GetAll"}, 125 {200, nullptr, "GetAll"},
126 {201, nullptr, "SetAll"}, 126 {201, nullptr, "SetAll"},
127 {202, nullptr, "FlushDebug"}, 127 {202, nullptr, "FlushDebug"},
diff --git a/src/core/hle/service/nfp/nfp_device.cpp b/src/core/hle/service/nfp/nfp_device.cpp
index 607e70968..5ed6d4181 100644
--- a/src/core/hle/service/nfp/nfp_device.cpp
+++ b/src/core/hle/service/nfp/nfp_device.cpp
@@ -29,7 +29,6 @@
29#include "core/hle/service/nfp/amiibo_crypto.h" 29#include "core/hle/service/nfp/amiibo_crypto.h"
30#include "core/hle/service/nfp/nfp_device.h" 30#include "core/hle/service/nfp/nfp_device.h"
31#include "core/hle/service/nfp/nfp_result.h" 31#include "core/hle/service/nfp/nfp_result.h"
32#include "core/hle/service/nfp/nfp_user.h"
33#include "core/hle/service/time/time_manager.h" 32#include "core/hle/service/time/time_manager.h"
34#include "core/hle/service/time/time_zone_content_manager.h" 33#include "core/hle/service/time/time_zone_content_manager.h"
35#include "core/hle/service/time/time_zone_types.h" 34#include "core/hle/service/time/time_zone_types.h"
@@ -417,6 +416,38 @@ Result NfpDevice::GetRegisterInfo(RegisterInfo& register_info) const {
417 return ResultSuccess; 416 return ResultSuccess;
418} 417}
419 418
419Result NfpDevice::GetRegisterInfoPrivate(RegisterInfoPrivate& register_info) const {
420 if (device_state != DeviceState::TagMounted) {
421 LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
422 if (device_state == DeviceState::TagRemoved) {
423 return TagRemoved;
424 }
425 return WrongDeviceState;
426 }
427
428 if (mount_target == MountTarget::None || mount_target == MountTarget::Rom) {
429 LOG_ERROR(Service_NFP, "Amiibo is read only", device_state);
430 return WrongDeviceState;
431 }
432
433 if (tag_data.settings.settings.amiibo_initialized == 0) {
434 return RegistrationIsNotInitialized;
435 }
436
437 Service::Mii::MiiManager manager;
438 const auto& settings = tag_data.settings;
439
440 // TODO: Validate and complete this data
441 register_info = {
442 .mii_store_data = {},
443 .creation_date = settings.init_date.GetWriteDate(),
444 .amiibo_name = GetAmiiboName(settings),
445 .font_region = settings.settings.font_region,
446 };
447
448 return ResultSuccess;
449}
450
420Result NfpDevice::GetAdminInfo(AdminInfo& admin_info) const { 451Result NfpDevice::GetAdminInfo(AdminInfo& admin_info) const {
421 if (device_state != DeviceState::TagMounted) { 452 if (device_state != DeviceState::TagMounted) {
422 LOG_ERROR(Service_NFC, "Wrong device state {}", device_state); 453 LOG_ERROR(Service_NFC, "Wrong device state {}", device_state);
@@ -807,6 +838,25 @@ Result NfpDevice::DeleteApplicationArea() {
807 return Flush(); 838 return Flush();
808} 839}
809 840
841Result NfpDevice::ExistApplicationArea(bool& has_application_area) {
842 if (device_state != DeviceState::TagMounted) {
843 LOG_ERROR(Service_NFC, "Wrong device state {}", device_state);
844 if (device_state == DeviceState::TagRemoved) {
845 return TagRemoved;
846 }
847 return WrongDeviceState;
848 }
849
850 if (mount_target == MountTarget::None || mount_target == MountTarget::Rom) {
851 LOG_ERROR(Service_NFC, "Amiibo is read only", device_state);
852 return WrongDeviceState;
853 }
854
855 has_application_area = tag_data.settings.settings.appdata_initialized.Value() != 0;
856
857 return ResultSuccess;
858}
859
810u64 NfpDevice::GetHandle() const { 860u64 NfpDevice::GetHandle() const {
811 // Generate a handle based of the npad id 861 // Generate a handle based of the npad id
812 return static_cast<u64>(npad_id); 862 return static_cast<u64>(npad_id);
diff --git a/src/core/hle/service/nfp/nfp_device.h b/src/core/hle/service/nfp/nfp_device.h
index 7f963730d..0d778c1d7 100644
--- a/src/core/hle/service/nfp/nfp_device.h
+++ b/src/core/hle/service/nfp/nfp_device.h
@@ -47,6 +47,7 @@ public:
47 Result GetCommonInfo(CommonInfo& common_info) const; 47 Result GetCommonInfo(CommonInfo& common_info) const;
48 Result GetModelInfo(ModelInfo& model_info) const; 48 Result GetModelInfo(ModelInfo& model_info) const;
49 Result GetRegisterInfo(RegisterInfo& register_info) const; 49 Result GetRegisterInfo(RegisterInfo& register_info) const;
50 Result GetRegisterInfoPrivate(RegisterInfoPrivate& register_info) const;
50 Result GetAdminInfo(AdminInfo& admin_info) const; 51 Result GetAdminInfo(AdminInfo& admin_info) const;
51 52
52 Result DeleteRegisterInfo(); 53 Result DeleteRegisterInfo();
@@ -61,6 +62,7 @@ public:
61 Result CreateApplicationArea(u32 access_id, std::span<const u8> data); 62 Result CreateApplicationArea(u32 access_id, std::span<const u8> data);
62 Result RecreateApplicationArea(u32 access_id, std::span<const u8> data); 63 Result RecreateApplicationArea(u32 access_id, std::span<const u8> data);
63 Result DeleteApplicationArea(); 64 Result DeleteApplicationArea();
65 Result ExistApplicationArea(bool& has_application_area);
64 66
65 u64 GetHandle() const; 67 u64 GetHandle() const;
66 u32 GetApplicationAreaSize() const; 68 u32 GetApplicationAreaSize() const;
diff --git a/src/core/hle/service/nfp/nfp_interface.cpp b/src/core/hle/service/nfp/nfp_interface.cpp
index e131703cb..d60f3cb97 100644
--- a/src/core/hle/service/nfp/nfp_interface.cpp
+++ b/src/core/hle/service/nfp/nfp_interface.cpp
@@ -40,6 +40,19 @@ void Interface::Initialize(HLERequestContext& ctx) {
40 rb.Push(ResultSuccess); 40 rb.Push(ResultSuccess);
41} 41}
42 42
43void Interface::InitializeSystem(HLERequestContext& ctx) {
44 LOG_INFO(Service_NFP, "called");
45
46 state = State::Initialized;
47
48 for (auto& device : devices) {
49 device->Initialize();
50 }
51
52 IPC::ResponseBuilder rb{ctx, 2};
53 rb.Push(ResultSuccess);
54}
55
43void Interface::Finalize(HLERequestContext& ctx) { 56void Interface::Finalize(HLERequestContext& ctx) {
44 LOG_INFO(Service_NFP, "called"); 57 LOG_INFO(Service_NFP, "called");
45 58
@@ -53,6 +66,19 @@ void Interface::Finalize(HLERequestContext& ctx) {
53 rb.Push(ResultSuccess); 66 rb.Push(ResultSuccess);
54} 67}
55 68
69void Interface::FinalizeSystem(HLERequestContext& ctx) {
70 LOG_INFO(Service_NFP, "called");
71
72 state = State::NonInitialized;
73
74 for (auto& device : devices) {
75 device->Finalize();
76 }
77
78 IPC::ResponseBuilder rb{ctx, 2};
79 rb.Push(ResultSuccess);
80}
81
56void Interface::ListDevices(HLERequestContext& ctx) { 82void Interface::ListDevices(HLERequestContext& ctx) {
57 LOG_DEBUG(Service_NFP, "called"); 83 LOG_DEBUG(Service_NFP, "called");
58 84
@@ -631,6 +657,182 @@ void Interface::RecreateApplicationArea(HLERequestContext& ctx) {
631 rb.Push(result); 657 rb.Push(result);
632} 658}
633 659
660void Interface::Format(HLERequestContext& ctx) {
661 IPC::RequestParser rp{ctx};
662 const auto device_handle{rp.Pop<u64>()};
663 LOG_DEBUG(Service_NFP, "called, device_handle={}", device_handle);
664
665 if (state == State::NonInitialized) {
666 IPC::ResponseBuilder rb{ctx, 2};
667 rb.Push(NfcDisabled);
668 return;
669 }
670
671 auto device = GetNfpDevice(device_handle);
672
673 if (!device.has_value()) {
674 IPC::ResponseBuilder rb{ctx, 2};
675 rb.Push(DeviceNotFound);
676 return;
677 }
678
679 const auto result = device.value()->Format();
680 IPC::ResponseBuilder rb{ctx, 2};
681 rb.Push(result);
682}
683
684void Interface::GetAdminInfo(HLERequestContext& ctx) {
685 IPC::RequestParser rp{ctx};
686 const auto device_handle{rp.Pop<u64>()};
687 LOG_INFO(Service_NFP, "called, device_handle={}", device_handle);
688
689 if (state == State::NonInitialized) {
690 IPC::ResponseBuilder rb{ctx, 2};
691 rb.Push(NfcDisabled);
692 return;
693 }
694
695 auto device = GetNfpDevice(device_handle);
696
697 if (!device.has_value()) {
698 IPC::ResponseBuilder rb{ctx, 2};
699 rb.Push(DeviceNotFound);
700 return;
701 }
702
703 AdminInfo admin_info{};
704 const auto result = device.value()->GetAdminInfo(admin_info);
705 ctx.WriteBuffer(admin_info);
706 IPC::ResponseBuilder rb{ctx, 2};
707 rb.Push(result);
708}
709
710void Interface::GetRegisterInfoPrivate(HLERequestContext& ctx) {
711 IPC::RequestParser rp{ctx};
712 const auto device_handle{rp.Pop<u64>()};
713 LOG_INFO(Service_NFP, "called, device_handle={}", device_handle);
714
715 if (state == State::NonInitialized) {
716 IPC::ResponseBuilder rb{ctx, 2};
717 rb.Push(NfcDisabled);
718 return;
719 }
720
721 auto device = GetNfpDevice(device_handle);
722
723 if (!device.has_value()) {
724 IPC::ResponseBuilder rb{ctx, 2};
725 rb.Push(DeviceNotFound);
726 return;
727 }
728
729 RegisterInfoPrivate register_info{};
730 const auto result = device.value()->GetRegisterInfoPrivate(register_info);
731 ctx.WriteBuffer(register_info);
732 IPC::ResponseBuilder rb{ctx, 2};
733 rb.Push(result);
734}
735
736void Interface::SetRegisterInfoPrivate(HLERequestContext& ctx) {
737 IPC::RequestParser rp{ctx};
738 const auto device_handle{rp.Pop<u64>()};
739 const auto buffer{ctx.ReadBuffer()};
740 LOG_DEBUG(Service_NFP, "called, device_handle={}, buffer_size={}", device_handle,
741 buffer.size());
742
743 if (state == State::NonInitialized) {
744 IPC::ResponseBuilder rb{ctx, 2};
745 rb.Push(NfcDisabled);
746 return;
747 }
748
749 auto device = GetNfpDevice(device_handle);
750
751 if (!device.has_value()) {
752 IPC::ResponseBuilder rb{ctx, 2};
753 rb.Push(DeviceNotFound);
754 return;
755 }
756
757 const auto result = device.value()->SetRegisterInfoPrivate({});
758 IPC::ResponseBuilder rb{ctx, 2};
759 rb.Push(result);
760}
761
762void Interface::DeleteRegisterInfo(HLERequestContext& ctx) {
763 IPC::RequestParser rp{ctx};
764 const auto device_handle{rp.Pop<u64>()};
765 LOG_DEBUG(Service_NFP, "called, device_handle={}", device_handle);
766
767 if (state == State::NonInitialized) {
768 IPC::ResponseBuilder rb{ctx, 2};
769 rb.Push(NfcDisabled);
770 return;
771 }
772
773 auto device = GetNfpDevice(device_handle);
774
775 if (!device.has_value()) {
776 IPC::ResponseBuilder rb{ctx, 2};
777 rb.Push(DeviceNotFound);
778 return;
779 }
780
781 const auto result = device.value()->DeleteRegisterInfo();
782 IPC::ResponseBuilder rb{ctx, 2};
783 rb.Push(result);
784}
785
786void Interface::DeleteApplicationArea(HLERequestContext& ctx) {
787 IPC::RequestParser rp{ctx};
788 const auto device_handle{rp.Pop<u64>()};
789 LOG_DEBUG(Service_NFP, "called, device_handle={}", device_handle);
790
791 if (state == State::NonInitialized) {
792 IPC::ResponseBuilder rb{ctx, 2};
793 rb.Push(NfcDisabled);
794 return;
795 }
796
797 auto device = GetNfpDevice(device_handle);
798
799 if (!device.has_value()) {
800 IPC::ResponseBuilder rb{ctx, 2};
801 rb.Push(DeviceNotFound);
802 return;
803 }
804
805 const auto result = device.value()->DeleteApplicationArea();
806 IPC::ResponseBuilder rb{ctx, 2};
807 rb.Push(result);
808}
809
810void Interface::ExistsApplicationArea(HLERequestContext& ctx) {
811 IPC::RequestParser rp{ctx};
812 const auto device_handle{rp.Pop<u64>()};
813 LOG_DEBUG(Service_NFP, "called, device_handle={}", device_handle);
814
815 if (state == State::NonInitialized) {
816 IPC::ResponseBuilder rb{ctx, 2};
817 rb.Push(NfcDisabled);
818 return;
819 }
820
821 auto device = GetNfpDevice(device_handle);
822
823 if (!device.has_value()) {
824 IPC::ResponseBuilder rb{ctx, 2};
825 rb.Push(DeviceNotFound);
826 return;
827 }
828
829 bool has_application_area = false;
830 const auto result = device.value()->ExistApplicationArea(has_application_area);
831 IPC::ResponseBuilder rb{ctx, 3};
832 rb.Push(result);
833 rb.Push(has_application_area);
834}
835
634std::optional<std::shared_ptr<NfpDevice>> Interface::GetNfpDevice(u64 handle) { 836std::optional<std::shared_ptr<NfpDevice>> Interface::GetNfpDevice(u64 handle) {
635 for (auto& device : devices) { 837 for (auto& device : devices) {
636 if (device->GetHandle() == handle) { 838 if (device->GetHandle() == handle) {
diff --git a/src/core/hle/service/nfp/nfp_interface.h b/src/core/hle/service/nfp/nfp_interface.h
index 11f29c2ba..4affdbc0c 100644
--- a/src/core/hle/service/nfp/nfp_interface.h
+++ b/src/core/hle/service/nfp/nfp_interface.h
@@ -19,7 +19,9 @@ public:
19 ~Interface() override; 19 ~Interface() override;
20 20
21 void Initialize(HLERequestContext& ctx); 21 void Initialize(HLERequestContext& ctx);
22 void InitializeSystem(HLERequestContext& ctx);
22 void Finalize(HLERequestContext& ctx); 23 void Finalize(HLERequestContext& ctx);
24 void FinalizeSystem(HLERequestContext& ctx);
23 void ListDevices(HLERequestContext& ctx); 25 void ListDevices(HLERequestContext& ctx);
24 void StartDetection(HLERequestContext& ctx); 26 void StartDetection(HLERequestContext& ctx);
25 void StopDetection(HLERequestContext& ctx); 27 void StopDetection(HLERequestContext& ctx);
@@ -43,6 +45,13 @@ public:
43 void GetApplicationAreaSize(HLERequestContext& ctx); 45 void GetApplicationAreaSize(HLERequestContext& ctx);
44 void AttachAvailabilityChangeEvent(HLERequestContext& ctx); 46 void AttachAvailabilityChangeEvent(HLERequestContext& ctx);
45 void RecreateApplicationArea(HLERequestContext& ctx); 47 void RecreateApplicationArea(HLERequestContext& ctx);
48 void Format(HLERequestContext& ctx);
49 void GetAdminInfo(HLERequestContext& ctx);
50 void GetRegisterInfoPrivate(HLERequestContext& ctx);
51 void SetRegisterInfoPrivate(HLERequestContext& ctx);
52 void DeleteRegisterInfo(HLERequestContext& ctx);
53 void DeleteApplicationArea(HLERequestContext& ctx);
54 void ExistsApplicationArea(HLERequestContext& ctx);
46 55
47private: 56private:
48 enum class State : u32 { 57 enum class State : u32 {
diff --git a/src/core/hle/service/nfp/nfp_types.h b/src/core/hle/service/nfp/nfp_types.h
index 70c878552..90429baa2 100644
--- a/src/core/hle/service/nfp/nfp_types.h
+++ b/src/core/hle/service/nfp/nfp_types.h
@@ -354,6 +354,15 @@ struct RegisterInfo {
354}; 354};
355static_assert(sizeof(RegisterInfo) == 0x100, "RegisterInfo is an invalid size"); 355static_assert(sizeof(RegisterInfo) == 0x100, "RegisterInfo is an invalid size");
356 356
357struct RegisterInfoPrivate {
358 Service::Mii::MiiStoreData mii_store_data;
359 WriteDate creation_date;
360 AmiiboName amiibo_name;
361 u8 font_region;
362 INSERT_PADDING_BYTES(0x8E);
363};
364static_assert(sizeof(RegisterInfoPrivate) == 0x100, "RegisterInfoPrivate is an invalid size");
365
357struct AdminInfo { 366struct AdminInfo {
358 u64 application_id; 367 u64 application_id;
359 u32 application_area_id; 368 u32 application_area_id;