diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/nfp/nfp_device.cpp | 33 | ||||
| -rw-r--r-- | src/core/hle/service/nfp/nfp_device.h | 6 | ||||
| -rw-r--r-- | src/core/hle/service/nfp/nfp_types.h | 10 | ||||
| -rw-r--r-- | src/core/hle/service/nfp/nfp_user.cpp | 2 |
4 files changed, 43 insertions, 8 deletions
diff --git a/src/core/hle/service/nfp/nfp_device.cpp b/src/core/hle/service/nfp/nfp_device.cpp index b19672560..2f9dfa9c2 100644 --- a/src/core/hle/service/nfp/nfp_device.cpp +++ b/src/core/hle/service/nfp/nfp_device.cpp | |||
| @@ -77,6 +77,9 @@ void NfpDevice::NpadUpdate(Core::HID::ControllerTriggerType type) { | |||
| 77 | LoadAmiibo(nfc_status.data); | 77 | LoadAmiibo(nfc_status.data); |
| 78 | break; | 78 | break; |
| 79 | case Common::Input::NfcState::AmiiboRemoved: | 79 | case Common::Input::NfcState::AmiiboRemoved: |
| 80 | if (device_state == DeviceState::Initialized || device_state == DeviceState::TagRemoved) { | ||
| 81 | break; | ||
| 82 | } | ||
| 80 | if (device_state != DeviceState::SearchingForTag) { | 83 | if (device_state != DeviceState::SearchingForTag) { |
| 81 | CloseAmiibo(); | 84 | CloseAmiibo(); |
| 82 | } | 85 | } |
| @@ -97,6 +100,8 @@ bool NfpDevice::LoadAmiibo(std::span<const u8> data) { | |||
| 97 | return false; | 100 | return false; |
| 98 | } | 101 | } |
| 99 | 102 | ||
| 103 | // TODO: Filter by allowed_protocols here | ||
| 104 | |||
| 100 | memcpy(&encrypted_tag_data, data.data(), sizeof(EncryptedNTAG215File)); | 105 | memcpy(&encrypted_tag_data, data.data(), sizeof(EncryptedNTAG215File)); |
| 101 | 106 | ||
| 102 | device_state = DeviceState::TagFound; | 107 | device_state = DeviceState::TagFound; |
| @@ -143,7 +148,7 @@ void NfpDevice::Finalize() { | |||
| 143 | device_state = DeviceState::Unavailable; | 148 | device_state = DeviceState::Unavailable; |
| 144 | } | 149 | } |
| 145 | 150 | ||
| 146 | Result NfpDevice::StartDetection(s32 protocol_) { | 151 | Result NfpDevice::StartDetection([[maybe_unused]] TagProtocol allowed_protocol) { |
| 147 | if (device_state != DeviceState::Initialized && device_state != DeviceState::TagRemoved) { | 152 | if (device_state != DeviceState::Initialized && device_state != DeviceState::TagRemoved) { |
| 148 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); | 153 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); |
| 149 | return WrongDeviceState; | 154 | return WrongDeviceState; |
| @@ -155,7 +160,7 @@ Result NfpDevice::StartDetection(s32 protocol_) { | |||
| 155 | } | 160 | } |
| 156 | 161 | ||
| 157 | device_state = DeviceState::SearchingForTag; | 162 | device_state = DeviceState::SearchingForTag; |
| 158 | protocol = protocol_; | 163 | allowed_protocols = allowed_protocol; |
| 159 | return ResultSuccess; | 164 | return ResultSuccess; |
| 160 | } | 165 | } |
| 161 | 166 | ||
| @@ -469,6 +474,30 @@ Result NfpDevice::OpenApplicationArea(u32 access_id) { | |||
| 469 | return ResultSuccess; | 474 | return ResultSuccess; |
| 470 | } | 475 | } |
| 471 | 476 | ||
| 477 | Result NfpDevice::GetApplicationAreaId(u32& application_area_id) const { | ||
| 478 | if (device_state != DeviceState::TagMounted) { | ||
| 479 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); | ||
| 480 | if (device_state == DeviceState::TagRemoved) { | ||
| 481 | return TagRemoved; | ||
| 482 | } | ||
| 483 | return WrongDeviceState; | ||
| 484 | } | ||
| 485 | |||
| 486 | if (mount_target == MountTarget::None || mount_target == MountTarget::Rom) { | ||
| 487 | LOG_ERROR(Service_NFP, "Amiibo is read only", device_state); | ||
| 488 | return WrongDeviceState; | ||
| 489 | } | ||
| 490 | |||
| 491 | if (tag_data.settings.settings.appdata_initialized.Value() == 0) { | ||
| 492 | LOG_WARNING(Service_NFP, "Application area is not initialized"); | ||
| 493 | return ApplicationAreaIsNotInitialized; | ||
| 494 | } | ||
| 495 | |||
| 496 | application_area_id = tag_data.application_area_id; | ||
| 497 | |||
| 498 | return ResultSuccess; | ||
| 499 | } | ||
| 500 | |||
| 472 | Result NfpDevice::GetApplicationArea(std::vector<u8>& data) const { | 501 | Result NfpDevice::GetApplicationArea(std::vector<u8>& data) const { |
| 473 | if (device_state != DeviceState::TagMounted) { | 502 | if (device_state != DeviceState::TagMounted) { |
| 474 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); | 503 | LOG_ERROR(Service_NFP, "Wrong device state {}", device_state); |
diff --git a/src/core/hle/service/nfp/nfp_device.h b/src/core/hle/service/nfp/nfp_device.h index 76d0e9ae4..3d1cb4609 100644 --- a/src/core/hle/service/nfp/nfp_device.h +++ b/src/core/hle/service/nfp/nfp_device.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include <array> | 6 | #include <array> |
| 7 | #include <span> | ||
| 7 | #include <vector> | 8 | #include <vector> |
| 8 | 9 | ||
| 9 | #include "common/common_funcs.h" | 10 | #include "common/common_funcs.h" |
| @@ -37,7 +38,7 @@ public: | |||
| 37 | void Initialize(); | 38 | void Initialize(); |
| 38 | void Finalize(); | 39 | void Finalize(); |
| 39 | 40 | ||
| 40 | Result StartDetection(s32 protocol_); | 41 | Result StartDetection(TagProtocol allowed_protocol); |
| 41 | Result StopDetection(); | 42 | Result StopDetection(); |
| 42 | Result Mount(MountTarget mount_target); | 43 | Result Mount(MountTarget mount_target); |
| 43 | Result Unmount(); | 44 | Result Unmount(); |
| @@ -53,6 +54,7 @@ public: | |||
| 53 | Result DeleteAllData(); | 54 | Result DeleteAllData(); |
| 54 | 55 | ||
| 55 | Result OpenApplicationArea(u32 access_id); | 56 | Result OpenApplicationArea(u32 access_id); |
| 57 | Result GetApplicationAreaId(u32& application_area_id) const; | ||
| 56 | Result GetApplicationArea(std::vector<u8>& data) const; | 58 | Result GetApplicationArea(std::vector<u8>& data) const; |
| 57 | Result SetApplicationArea(std::span<const u8> data); | 59 | Result SetApplicationArea(std::span<const u8> data); |
| 58 | Result CreateApplicationArea(u32 access_id, std::span<const u8> data); | 60 | Result CreateApplicationArea(u32 access_id, std::span<const u8> data); |
| @@ -88,7 +90,7 @@ private: | |||
| 88 | 90 | ||
| 89 | bool is_data_moddified{}; | 91 | bool is_data_moddified{}; |
| 90 | bool is_app_area_open{}; | 92 | bool is_app_area_open{}; |
| 91 | s32 protocol{}; | 93 | TagProtocol allowed_protocols{}; |
| 92 | s64 current_posix_time{}; | 94 | s64 current_posix_time{}; |
| 93 | MountTarget mount_target{MountTarget::None}; | 95 | MountTarget mount_target{MountTarget::None}; |
| 94 | DeviceState device_state{DeviceState::Unavailable}; | 96 | DeviceState device_state{DeviceState::Unavailable}; |
diff --git a/src/core/hle/service/nfp/nfp_types.h b/src/core/hle/service/nfp/nfp_types.h index 63d5917cb..866aefe20 100644 --- a/src/core/hle/service/nfp/nfp_types.h +++ b/src/core/hle/service/nfp/nfp_types.h | |||
| @@ -88,11 +88,15 @@ enum class PackedTagType : u8 { | |||
| 88 | Type5, // ISO15693 RW/RO 540 bytes 106kbit/s | 88 | Type5, // ISO15693 RW/RO 540 bytes 106kbit/s |
| 89 | }; | 89 | }; |
| 90 | 90 | ||
| 91 | // Verify this enum. It might be completely wrong default protocol is 0x48 | ||
| 91 | enum class TagProtocol : u32 { | 92 | enum class TagProtocol : u32 { |
| 92 | None, | 93 | None, |
| 93 | TypeA, // ISO14443A | 94 | TypeA = 1U << 0, // ISO14443A |
| 94 | TypeB, // ISO14443B | 95 | TypeB = 1U << 1, // ISO14443B |
| 95 | TypeF, // Sony Felica | 96 | TypeF = 1U << 2, // Sony Felica |
| 97 | Unknown1 = 1U << 3, | ||
| 98 | Unknown2 = 1U << 5, | ||
| 99 | All = 0xFFFFFFFFU, | ||
| 96 | }; | 100 | }; |
| 97 | 101 | ||
| 98 | using UniqueSerialNumber = std::array<u8, 7>; | 102 | using UniqueSerialNumber = std::array<u8, 7>; |
diff --git a/src/core/hle/service/nfp/nfp_user.cpp b/src/core/hle/service/nfp/nfp_user.cpp index 33e2ef518..ac492cc27 100644 --- a/src/core/hle/service/nfp/nfp_user.cpp +++ b/src/core/hle/service/nfp/nfp_user.cpp | |||
| @@ -130,7 +130,7 @@ void IUser::ListDevices(Kernel::HLERequestContext& ctx) { | |||
| 130 | void IUser::StartDetection(Kernel::HLERequestContext& ctx) { | 130 | void IUser::StartDetection(Kernel::HLERequestContext& ctx) { |
| 131 | IPC::RequestParser rp{ctx}; | 131 | IPC::RequestParser rp{ctx}; |
| 132 | const auto device_handle{rp.Pop<u64>()}; | 132 | const auto device_handle{rp.Pop<u64>()}; |
| 133 | const auto nfp_protocol{rp.Pop<s32>()}; | 133 | const auto nfp_protocol{rp.PopEnum<TagProtocol>()}; |
| 134 | LOG_INFO(Service_NFP, "called, device_handle={}, nfp_protocol={}", device_handle, nfp_protocol); | 134 | LOG_INFO(Service_NFP, "called, device_handle={}, nfp_protocol={}", device_handle, nfp_protocol); |
| 135 | 135 | ||
| 136 | if (state == State::NonInitialized) { | 136 | if (state == State::NonInitialized) { |