mirror of
https://github.com/yuzu-mirror/yuzu.git
synced 2024-09-07 04:19:08 +01:00
service: nfc: fix tagprotocol and implement GetApplicationAreaId
This commit is contained in:
parent
08091ff3e3
commit
6c045c9beb
4 changed files with 43 additions and 8 deletions
|
@ -77,6 +77,9 @@ void NfpDevice::NpadUpdate(Core::HID::ControllerTriggerType type) {
|
||||||
LoadAmiibo(nfc_status.data);
|
LoadAmiibo(nfc_status.data);
|
||||||
break;
|
break;
|
||||||
case Common::Input::NfcState::AmiiboRemoved:
|
case Common::Input::NfcState::AmiiboRemoved:
|
||||||
|
if (device_state == DeviceState::Initialized || device_state == DeviceState::TagRemoved) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (device_state != DeviceState::SearchingForTag) {
|
if (device_state != DeviceState::SearchingForTag) {
|
||||||
CloseAmiibo();
|
CloseAmiibo();
|
||||||
}
|
}
|
||||||
|
@ -97,6 +100,8 @@ bool NfpDevice::LoadAmiibo(std::span<const u8> data) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Filter by allowed_protocols here
|
||||||
|
|
||||||
memcpy(&encrypted_tag_data, data.data(), sizeof(EncryptedNTAG215File));
|
memcpy(&encrypted_tag_data, data.data(), sizeof(EncryptedNTAG215File));
|
||||||
|
|
||||||
device_state = DeviceState::TagFound;
|
device_state = DeviceState::TagFound;
|
||||||
|
@ -143,7 +148,7 @@ void NfpDevice::Finalize() {
|
||||||
device_state = DeviceState::Unavailable;
|
device_state = DeviceState::Unavailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result NfpDevice::StartDetection(s32 protocol_) {
|
Result NfpDevice::StartDetection([[maybe_unused]] TagProtocol allowed_protocol) {
|
||||||
if (device_state != DeviceState::Initialized && device_state != DeviceState::TagRemoved) {
|
if (device_state != DeviceState::Initialized && device_state != DeviceState::TagRemoved) {
|
||||||
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
||||||
return WrongDeviceState;
|
return WrongDeviceState;
|
||||||
|
@ -155,7 +160,7 @@ Result NfpDevice::StartDetection(s32 protocol_) {
|
||||||
}
|
}
|
||||||
|
|
||||||
device_state = DeviceState::SearchingForTag;
|
device_state = DeviceState::SearchingForTag;
|
||||||
protocol = protocol_;
|
allowed_protocols = allowed_protocol;
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,6 +474,30 @@ Result NfpDevice::OpenApplicationArea(u32 access_id) {
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result NfpDevice::GetApplicationAreaId(u32& application_area_id) const {
|
||||||
|
if (device_state != DeviceState::TagMounted) {
|
||||||
|
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
||||||
|
if (device_state == DeviceState::TagRemoved) {
|
||||||
|
return TagRemoved;
|
||||||
|
}
|
||||||
|
return WrongDeviceState;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mount_target == MountTarget::None || mount_target == MountTarget::Rom) {
|
||||||
|
LOG_ERROR(Service_NFP, "Amiibo is read only", device_state);
|
||||||
|
return WrongDeviceState;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tag_data.settings.settings.appdata_initialized.Value() == 0) {
|
||||||
|
LOG_WARNING(Service_NFP, "Application area is not initialized");
|
||||||
|
return ApplicationAreaIsNotInitialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
application_area_id = tag_data.application_area_id;
|
||||||
|
|
||||||
|
return ResultSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
Result NfpDevice::GetApplicationArea(std::vector<u8>& data) const {
|
Result NfpDevice::GetApplicationArea(std::vector<u8>& data) const {
|
||||||
if (device_state != DeviceState::TagMounted) {
|
if (device_state != DeviceState::TagMounted) {
|
||||||
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
LOG_ERROR(Service_NFP, "Wrong device state {}", device_state);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <span>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "common/common_funcs.h"
|
#include "common/common_funcs.h"
|
||||||
|
@ -37,7 +38,7 @@ public:
|
||||||
void Initialize();
|
void Initialize();
|
||||||
void Finalize();
|
void Finalize();
|
||||||
|
|
||||||
Result StartDetection(s32 protocol_);
|
Result StartDetection(TagProtocol allowed_protocol);
|
||||||
Result StopDetection();
|
Result StopDetection();
|
||||||
Result Mount(MountTarget mount_target);
|
Result Mount(MountTarget mount_target);
|
||||||
Result Unmount();
|
Result Unmount();
|
||||||
|
@ -53,6 +54,7 @@ public:
|
||||||
Result DeleteAllData();
|
Result DeleteAllData();
|
||||||
|
|
||||||
Result OpenApplicationArea(u32 access_id);
|
Result OpenApplicationArea(u32 access_id);
|
||||||
|
Result GetApplicationAreaId(u32& application_area_id) const;
|
||||||
Result GetApplicationArea(std::vector<u8>& data) const;
|
Result GetApplicationArea(std::vector<u8>& data) const;
|
||||||
Result SetApplicationArea(std::span<const u8> data);
|
Result SetApplicationArea(std::span<const u8> data);
|
||||||
Result CreateApplicationArea(u32 access_id, std::span<const u8> data);
|
Result CreateApplicationArea(u32 access_id, std::span<const u8> data);
|
||||||
|
@ -88,7 +90,7 @@ private:
|
||||||
|
|
||||||
bool is_data_moddified{};
|
bool is_data_moddified{};
|
||||||
bool is_app_area_open{};
|
bool is_app_area_open{};
|
||||||
s32 protocol{};
|
TagProtocol allowed_protocols{};
|
||||||
s64 current_posix_time{};
|
s64 current_posix_time{};
|
||||||
MountTarget mount_target{MountTarget::None};
|
MountTarget mount_target{MountTarget::None};
|
||||||
DeviceState device_state{DeviceState::Unavailable};
|
DeviceState device_state{DeviceState::Unavailable};
|
||||||
|
|
|
@ -88,11 +88,15 @@ enum class PackedTagType : u8 {
|
||||||
Type5, // ISO15693 RW/RO 540 bytes 106kbit/s
|
Type5, // ISO15693 RW/RO 540 bytes 106kbit/s
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Verify this enum. It might be completely wrong default protocol is 0x48
|
||||||
enum class TagProtocol : u32 {
|
enum class TagProtocol : u32 {
|
||||||
None,
|
None,
|
||||||
TypeA, // ISO14443A
|
TypeA = 1U << 0, // ISO14443A
|
||||||
TypeB, // ISO14443B
|
TypeB = 1U << 1, // ISO14443B
|
||||||
TypeF, // Sony Felica
|
TypeF = 1U << 2, // Sony Felica
|
||||||
|
Unknown1 = 1U << 3,
|
||||||
|
Unknown2 = 1U << 5,
|
||||||
|
All = 0xFFFFFFFFU,
|
||||||
};
|
};
|
||||||
|
|
||||||
using UniqueSerialNumber = std::array<u8, 7>;
|
using UniqueSerialNumber = std::array<u8, 7>;
|
||||||
|
|
|
@ -130,7 +130,7 @@ void IUser::ListDevices(Kernel::HLERequestContext& ctx) {
|
||||||
void IUser::StartDetection(Kernel::HLERequestContext& ctx) {
|
void IUser::StartDetection(Kernel::HLERequestContext& ctx) {
|
||||||
IPC::RequestParser rp{ctx};
|
IPC::RequestParser rp{ctx};
|
||||||
const auto device_handle{rp.Pop<u64>()};
|
const auto device_handle{rp.Pop<u64>()};
|
||||||
const auto nfp_protocol{rp.Pop<s32>()};
|
const auto nfp_protocol{rp.PopEnum<TagProtocol>()};
|
||||||
LOG_INFO(Service_NFP, "called, device_handle={}, nfp_protocol={}", device_handle, nfp_protocol);
|
LOG_INFO(Service_NFP, "called, device_handle={}, nfp_protocol={}", device_handle, nfp_protocol);
|
||||||
|
|
||||||
if (state == State::NonInitialized) {
|
if (state == State::NonInitialized) {
|
||||||
|
|
Loading…
Reference in a new issue