diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/hle/service/nfc/nfc.cpp | 53 | ||||
| -rw-r--r-- | src/core/hle/service/nfp/nfp.cpp | 268 | ||||
| -rw-r--r-- | src/core/hle/service/nfp/nfp.h | 23 | ||||
| -rw-r--r-- | src/core/settings.h | 1 |
4 files changed, 295 insertions, 50 deletions
diff --git a/src/core/hle/service/nfc/nfc.cpp b/src/core/hle/service/nfc/nfc.cpp index 8fec97db8..30e542542 100644 --- a/src/core/hle/service/nfc/nfc.cpp +++ b/src/core/hle/service/nfc/nfc.cpp | |||
| @@ -10,12 +10,13 @@ | |||
| 10 | #include "core/hle/service/nfc/nfc.h" | 10 | #include "core/hle/service/nfc/nfc.h" |
| 11 | #include "core/hle/service/service.h" | 11 | #include "core/hle/service/service.h" |
| 12 | #include "core/hle/service/sm/sm.h" | 12 | #include "core/hle/service/sm/sm.h" |
| 13 | #include "core/settings.h" | ||
| 13 | 14 | ||
| 14 | namespace Service::NFC { | 15 | namespace Service::NFC { |
| 15 | 16 | ||
| 16 | class IAm final : public ServiceFramework<IAm> { | 17 | class IAm final : public ServiceFramework<IAm> { |
| 17 | public: | 18 | public: |
| 18 | explicit IAm() : ServiceFramework{"IAm"} { | 19 | explicit IAm() : ServiceFramework{"NFC::IAm"} { |
| 19 | // clang-format off | 20 | // clang-format off |
| 20 | static const FunctionInfo functions[] = { | 21 | static const FunctionInfo functions[] = { |
| 21 | {0, nullptr, "Initialize"}, | 22 | {0, nullptr, "Initialize"}, |
| @@ -52,7 +53,7 @@ private: | |||
| 52 | 53 | ||
| 53 | class MFIUser final : public ServiceFramework<MFIUser> { | 54 | class MFIUser final : public ServiceFramework<MFIUser> { |
| 54 | public: | 55 | public: |
| 55 | explicit MFIUser() : ServiceFramework{"IUser"} { | 56 | explicit MFIUser() : ServiceFramework{"NFC::MFIUser"} { |
| 56 | // clang-format off | 57 | // clang-format off |
| 57 | static const FunctionInfo functions[] = { | 58 | static const FunctionInfo functions[] = { |
| 58 | {0, nullptr, "Initialize"}, | 59 | {0, nullptr, "Initialize"}, |
| @@ -100,13 +101,13 @@ private: | |||
| 100 | 101 | ||
| 101 | class IUser final : public ServiceFramework<IUser> { | 102 | class IUser final : public ServiceFramework<IUser> { |
| 102 | public: | 103 | public: |
| 103 | explicit IUser() : ServiceFramework{"IUser"} { | 104 | explicit IUser() : ServiceFramework{"NFC::IUser"} { |
| 104 | // clang-format off | 105 | // clang-format off |
| 105 | static const FunctionInfo functions[] = { | 106 | static const FunctionInfo functions[] = { |
| 106 | {0, nullptr, "Initialize"}, | 107 | {0, &IUser::InitializeOld, "InitializeOld"}, |
| 107 | {1, nullptr, "Finalize"}, | 108 | {1, &IUser::FinalizeOld, "FinalizeOld"}, |
| 108 | {2, nullptr, "GetState"}, | 109 | {2, &IUser::GetStateOld, "GetStateOld"}, |
| 109 | {3, nullptr, "IsNfcEnabled"}, | 110 | {3, &IUser::IsNfcEnabledOld, "IsNfcEnabledOld"}, |
| 110 | {400, nullptr, "Initialize"}, | 111 | {400, nullptr, "Initialize"}, |
| 111 | {401, nullptr, "Finalize"}, | 112 | {401, nullptr, "Finalize"}, |
| 112 | {402, nullptr, "GetState"}, | 113 | {402, nullptr, "GetState"}, |
| @@ -130,11 +131,47 @@ public: | |||
| 130 | 131 | ||
| 131 | RegisterHandlers(functions); | 132 | RegisterHandlers(functions); |
| 132 | } | 133 | } |
| 134 | |||
| 135 | private: | ||
| 136 | enum class NfcStates : u32 { | ||
| 137 | Finalized = 6, | ||
| 138 | }; | ||
| 139 | |||
| 140 | void InitializeOld(Kernel::HLERequestContext& ctx) { | ||
| 141 | IPC::ResponseBuilder rb{ctx, 2, 0}; | ||
| 142 | rb.Push(RESULT_SUCCESS); | ||
| 143 | |||
| 144 | // We don't deal with hardware initialization so we can just stub this. | ||
| 145 | LOG_DEBUG(Service_NFC, "called"); | ||
| 146 | } | ||
| 147 | |||
| 148 | void IsNfcEnabledOld(Kernel::HLERequestContext& ctx) { | ||
| 149 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 150 | rb.Push(RESULT_SUCCESS); | ||
| 151 | rb.PushRaw<u8>(Settings::values.enable_nfc); | ||
| 152 | |||
| 153 | LOG_DEBUG(Service_NFC, "IsNfcEnabledOld"); | ||
| 154 | } | ||
| 155 | |||
| 156 | void GetStateOld(Kernel::HLERequestContext& ctx) { | ||
| 157 | LOG_WARNING(Service_NFC, "(STUBBED) called"); | ||
| 158 | |||
| 159 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 160 | rb.Push(RESULT_SUCCESS); | ||
| 161 | rb.PushEnum(NfcStates::Finalized); // TODO(ogniK): Figure out if this matches nfp | ||
| 162 | } | ||
| 163 | |||
| 164 | void FinalizeOld(Kernel::HLERequestContext& ctx) { | ||
| 165 | LOG_WARNING(Service_NFC, "(STUBBED) called"); | ||
| 166 | |||
| 167 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 168 | rb.Push(RESULT_SUCCESS); | ||
| 169 | } | ||
| 133 | }; | 170 | }; |
| 134 | 171 | ||
| 135 | class NFC_U final : public ServiceFramework<NFC_U> { | 172 | class NFC_U final : public ServiceFramework<NFC_U> { |
| 136 | public: | 173 | public: |
| 137 | explicit NFC_U() : ServiceFramework{"nfc:u"} { | 174 | explicit NFC_U() : ServiceFramework{"nfc:user"} { |
| 138 | // clang-format off | 175 | // clang-format off |
| 139 | static const FunctionInfo functions[] = { | 176 | static const FunctionInfo functions[] = { |
| 140 | {0, &NFC_U::CreateUserInterface, "CreateUserInterface"}, | 177 | {0, &NFC_U::CreateUserInterface, "CreateUserInterface"}, |
diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp index 39c0c1e63..9a4eb9301 100644 --- a/src/core/hle/service/nfp/nfp.cpp +++ b/src/core/hle/service/nfp/nfp.cpp | |||
| @@ -2,56 +2,67 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <atomic> | ||
| 6 | |||
| 5 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 6 | #include "core/core.h" | 8 | #include "core/core.h" |
| 7 | #include "core/hle/ipc_helpers.h" | 9 | #include "core/hle/ipc_helpers.h" |
| 8 | #include "core/hle/kernel/event.h" | 10 | #include "core/hle/kernel/event.h" |
| 11 | #include "core/hle/lock.h" | ||
| 9 | #include "core/hle/service/hid/hid.h" | 12 | #include "core/hle/service/hid/hid.h" |
| 10 | #include "core/hle/service/nfp/nfp.h" | 13 | #include "core/hle/service/nfp/nfp.h" |
| 11 | #include "core/hle/service/nfp/nfp_user.h" | 14 | #include "core/hle/service/nfp/nfp_user.h" |
| 12 | 15 | ||
| 13 | namespace Service::NFP { | 16 | namespace Service::NFP { |
| 14 | 17 | ||
| 18 | namespace ErrCodes { | ||
| 19 | constexpr ResultCode ERR_TAG_FAILED(ErrorModule::NFP, | ||
| 20 | -1); // TODO(ogniK): Find the actual error code | ||
| 21 | } | ||
| 22 | |||
| 15 | Module::Interface::Interface(std::shared_ptr<Module> module, const char* name) | 23 | Module::Interface::Interface(std::shared_ptr<Module> module, const char* name) |
| 16 | : ServiceFramework(name), module(std::move(module)) {} | 24 | : ServiceFramework(name), module(std::move(module)) { |
| 25 | auto& kernel = Core::System::GetInstance().Kernel(); | ||
| 26 | nfc_tag_load = | ||
| 27 | Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, "IUser:NFCTagDetected"); | ||
| 28 | } | ||
| 17 | 29 | ||
| 18 | Module::Interface::~Interface() = default; | 30 | Module::Interface::~Interface() = default; |
| 19 | 31 | ||
| 20 | class IUser final : public ServiceFramework<IUser> { | 32 | class IUser final : public ServiceFramework<IUser> { |
| 21 | public: | 33 | public: |
| 22 | IUser() : ServiceFramework("IUser") { | 34 | IUser(Module::Interface& nfp_interface) |
| 35 | : ServiceFramework("NFP::IUser"), nfp_interface(nfp_interface) { | ||
| 23 | static const FunctionInfo functions[] = { | 36 | static const FunctionInfo functions[] = { |
| 24 | {0, &IUser::Initialize, "Initialize"}, | 37 | {0, &IUser::Initialize, "Initialize"}, |
| 25 | {1, nullptr, "Finalize"}, | 38 | {1, &IUser::Finalize, "Finalize"}, |
| 26 | {2, &IUser::ListDevices, "ListDevices"}, | 39 | {2, &IUser::ListDevices, "ListDevices"}, |
| 27 | {3, nullptr, "StartDetection"}, | 40 | {3, &IUser::StartDetection, "StartDetection"}, |
| 28 | {4, nullptr, "StopDetection"}, | 41 | {4, &IUser::StopDetection, "StopDetection"}, |
| 29 | {5, nullptr, "Mount"}, | 42 | {5, &IUser::Mount, "Mount"}, |
| 30 | {6, nullptr, "Unmount"}, | 43 | {6, &IUser::Unmount, "Unmount"}, |
| 31 | {7, nullptr, "OpenApplicationArea"}, | 44 | {7, &IUser::OpenApplicationArea, "OpenApplicationArea"}, |
| 32 | {8, nullptr, "GetApplicationArea"}, | 45 | {8, &IUser::GetApplicationArea, "GetApplicationArea"}, |
| 33 | {9, nullptr, "SetApplicationArea"}, | 46 | {9, nullptr, "SetApplicationArea"}, |
| 34 | {10, nullptr, "Flush"}, | 47 | {10, nullptr, "Flush"}, |
| 35 | {11, nullptr, "Restore"}, | 48 | {11, nullptr, "Restore"}, |
| 36 | {12, nullptr, "CreateApplicationArea"}, | 49 | {12, nullptr, "CreateApplicationArea"}, |
| 37 | {13, nullptr, "GetTagInfo"}, | 50 | {13, &IUser::GetTagInfo, "GetTagInfo"}, |
| 38 | {14, nullptr, "GetRegisterInfo"}, | 51 | {14, &IUser::GetRegisterInfo, "GetRegisterInfo"}, |
| 39 | {15, nullptr, "GetCommonInfo"}, | 52 | {15, &IUser::GetCommonInfo, "GetCommonInfo"}, |
| 40 | {16, nullptr, "GetModelInfo"}, | 53 | {16, &IUser::GetModelInfo, "GetModelInfo"}, |
| 41 | {17, &IUser::AttachActivateEvent, "AttachActivateEvent"}, | 54 | {17, &IUser::AttachActivateEvent, "AttachActivateEvent"}, |
| 42 | {18, &IUser::AttachDeactivateEvent, "AttachDeactivateEvent"}, | 55 | {18, &IUser::AttachDeactivateEvent, "AttachDeactivateEvent"}, |
| 43 | {19, &IUser::GetState, "GetState"}, | 56 | {19, &IUser::GetState, "GetState"}, |
| 44 | {20, &IUser::GetDeviceState, "GetDeviceState"}, | 57 | {20, &IUser::GetDeviceState, "GetDeviceState"}, |
| 45 | {21, &IUser::GetNpadId, "GetNpadId"}, | 58 | {21, &IUser::GetNpadId, "GetNpadId"}, |
| 46 | {22, nullptr, "GetApplicationArea2"}, | 59 | {22, &IUser::GetApplicationAreaSize, "GetApplicationAreaSize"}, |
| 47 | {23, &IUser::AttachAvailabilityChangeEvent, "AttachAvailabilityChangeEvent"}, | 60 | {23, &IUser::AttachAvailabilityChangeEvent, "AttachAvailabilityChangeEvent"}, |
| 48 | {24, nullptr, "RecreateApplicationArea"}, | 61 | {24, nullptr, "RecreateApplicationArea"}, |
| 49 | }; | 62 | }; |
| 50 | RegisterHandlers(functions); | 63 | RegisterHandlers(functions); |
| 51 | 64 | ||
| 52 | auto& kernel = Core::System::GetInstance().Kernel(); | 65 | auto& kernel = Core::System::GetInstance().Kernel(); |
| 53 | activate_event = | ||
| 54 | Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, "IUser:ActivateEvent"); | ||
| 55 | deactivate_event = | 66 | deactivate_event = |
| 56 | Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, "IUser:DeactivateEvent"); | 67 | Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, "IUser:DeactivateEvent"); |
| 57 | availability_change_event = Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, | 68 | availability_change_event = Kernel::Event::Create(kernel, Kernel::ResetType::OneShot, |
| @@ -59,6 +70,17 @@ public: | |||
| 59 | } | 70 | } |
| 60 | 71 | ||
| 61 | private: | 72 | private: |
| 73 | struct TagInfo { | ||
| 74 | std::array<u8, 10> uuid; | ||
| 75 | u8 uuid_length; // TODO(ogniK): Figure out if this is actual the uuid length or does it | ||
| 76 | // mean something else | ||
| 77 | INSERT_PADDING_BYTES(0x15); | ||
| 78 | u32_le protocol; | ||
| 79 | u32_le tag_type; | ||
| 80 | INSERT_PADDING_BYTES(0x2c); | ||
| 81 | }; | ||
| 82 | static_assert(sizeof(TagInfo) == 0x54, "TagInfo is an invalid size"); | ||
| 83 | |||
| 62 | enum class State : u32 { | 84 | enum class State : u32 { |
| 63 | NonInitialized = 0, | 85 | NonInitialized = 0, |
| 64 | Initialized = 1, | 86 | Initialized = 1, |
| @@ -66,15 +88,40 @@ private: | |||
| 66 | 88 | ||
| 67 | enum class DeviceState : u32 { | 89 | enum class DeviceState : u32 { |
| 68 | Initialized = 0, | 90 | Initialized = 0, |
| 91 | SearchingForTag = 1, | ||
| 92 | TagFound = 2, | ||
| 93 | TagRemoved = 3, | ||
| 94 | TagNearby = 4, | ||
| 95 | Unknown5 = 5, | ||
| 96 | Finalized = 6 | ||
| 69 | }; | 97 | }; |
| 70 | 98 | ||
| 99 | struct CommonInfo { | ||
| 100 | u16_be last_write_year; | ||
| 101 | u8 last_write_month; | ||
| 102 | u8 last_write_day; | ||
| 103 | u16_be write_counter; | ||
| 104 | u16_be version; | ||
| 105 | u32_be application_area_size; | ||
| 106 | INSERT_PADDING_BYTES(0x34); | ||
| 107 | }; | ||
| 108 | static_assert(sizeof(CommonInfo) == 0x40, "CommonInfo is an invalid size"); | ||
| 109 | |||
| 71 | void Initialize(Kernel::HLERequestContext& ctx) { | 110 | void Initialize(Kernel::HLERequestContext& ctx) { |
| 72 | LOG_WARNING(Service_NFP, "(STUBBED) called"); | 111 | IPC::ResponseBuilder rb{ctx, 2, 0}; |
| 112 | rb.Push(RESULT_SUCCESS); | ||
| 73 | 113 | ||
| 74 | state = State::Initialized; | 114 | state = State::Initialized; |
| 75 | 115 | ||
| 76 | IPC::ResponseBuilder rb{ctx, 2}; | 116 | LOG_DEBUG(Service_NFC, "called"); |
| 117 | } | ||
| 118 | |||
| 119 | void GetState(Kernel::HLERequestContext& ctx) { | ||
| 120 | IPC::ResponseBuilder rb{ctx, 3, 0}; | ||
| 77 | rb.Push(RESULT_SUCCESS); | 121 | rb.Push(RESULT_SUCCESS); |
| 122 | rb.PushRaw<u32>(static_cast<u32>(state)); | ||
| 123 | |||
| 124 | LOG_DEBUG(Service_NFC, "called"); | ||
| 78 | } | 125 | } |
| 79 | 126 | ||
| 80 | void ListDevices(Kernel::HLERequestContext& ctx) { | 127 | void ListDevices(Kernel::HLERequestContext& ctx) { |
| @@ -83,80 +130,217 @@ private: | |||
| 83 | 130 | ||
| 84 | ctx.WriteBuffer(&device_handle, sizeof(device_handle)); | 131 | ctx.WriteBuffer(&device_handle, sizeof(device_handle)); |
| 85 | 132 | ||
| 86 | LOG_WARNING(Service_NFP, "(STUBBED) called, array_size={}", array_size); | 133 | LOG_DEBUG(Service_NFP, "called, array_size={}", array_size); |
| 87 | 134 | ||
| 88 | IPC::ResponseBuilder rb{ctx, 3}; | 135 | IPC::ResponseBuilder rb{ctx, 3}; |
| 89 | rb.Push(RESULT_SUCCESS); | 136 | rb.Push(RESULT_SUCCESS); |
| 90 | rb.Push<u32>(0); | 137 | rb.Push<u32>(1); |
| 91 | } | 138 | } |
| 92 | 139 | ||
| 93 | void AttachActivateEvent(Kernel::HLERequestContext& ctx) { | 140 | void GetNpadId(Kernel::HLERequestContext& ctx) { |
| 94 | IPC::RequestParser rp{ctx}; | 141 | IPC::RequestParser rp{ctx}; |
| 95 | const u64 dev_handle = rp.Pop<u64>(); | 142 | const u64 dev_handle = rp.Pop<u64>(); |
| 96 | LOG_WARNING(Service_NFP, "(STUBBED) called, dev_handle=0x{:X}", dev_handle); | 143 | LOG_DEBUG(Service_NFP, "called, dev_handle=0x{:X}", dev_handle); |
| 144 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 145 | rb.Push(RESULT_SUCCESS); | ||
| 146 | rb.Push<u32>(npad_id); | ||
| 147 | } | ||
| 97 | 148 | ||
| 149 | void AttachActivateEvent(Kernel::HLERequestContext& ctx) { | ||
| 150 | IPC::RequestParser rp{ctx}; | ||
| 151 | const u64 dev_handle = rp.Pop<u64>(); | ||
| 152 | LOG_DEBUG(Service_NFP, "called, dev_handle=0x{:X}", dev_handle); | ||
| 98 | IPC::ResponseBuilder rb{ctx, 2, 1}; | 153 | IPC::ResponseBuilder rb{ctx, 2, 1}; |
| 99 | rb.Push(RESULT_SUCCESS); | 154 | rb.Push(RESULT_SUCCESS); |
| 100 | rb.PushCopyObjects(activate_event); | 155 | rb.PushCopyObjects(nfp_interface.GetNFCEvent()); |
| 156 | has_attached_handle = true; | ||
| 101 | } | 157 | } |
| 102 | 158 | ||
| 103 | void AttachDeactivateEvent(Kernel::HLERequestContext& ctx) { | 159 | void AttachDeactivateEvent(Kernel::HLERequestContext& ctx) { |
| 104 | IPC::RequestParser rp{ctx}; | 160 | IPC::RequestParser rp{ctx}; |
| 105 | const u64 dev_handle = rp.Pop<u64>(); | 161 | const u64 dev_handle = rp.Pop<u64>(); |
| 106 | LOG_WARNING(Service_NFP, "(STUBBED) called, dev_handle=0x{:X}", dev_handle); | 162 | LOG_DEBUG(Service_NFP, "called, dev_handle=0x{:X}", dev_handle); |
| 107 | 163 | ||
| 108 | IPC::ResponseBuilder rb{ctx, 2, 1}; | 164 | IPC::ResponseBuilder rb{ctx, 2, 1}; |
| 109 | rb.Push(RESULT_SUCCESS); | 165 | rb.Push(RESULT_SUCCESS); |
| 110 | rb.PushCopyObjects(deactivate_event); | 166 | rb.PushCopyObjects(deactivate_event); |
| 111 | } | 167 | } |
| 112 | 168 | ||
| 113 | void GetState(Kernel::HLERequestContext& ctx) { | 169 | void StopDetection(Kernel::HLERequestContext& ctx) { |
| 114 | LOG_WARNING(Service_NFP, "(STUBBED) called"); | 170 | LOG_DEBUG(Service_NFP, "called"); |
| 115 | IPC::ResponseBuilder rb{ctx, 3}; | 171 | switch (device_state) { |
| 172 | case DeviceState::TagFound: | ||
| 173 | case DeviceState::TagNearby: | ||
| 174 | deactivate_event->Signal(); | ||
| 175 | device_state = DeviceState::Initialized; | ||
| 176 | break; | ||
| 177 | case DeviceState::SearchingForTag: | ||
| 178 | case DeviceState::TagRemoved: | ||
| 179 | device_state = DeviceState::Initialized; | ||
| 180 | break; | ||
| 181 | } | ||
| 182 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 116 | rb.Push(RESULT_SUCCESS); | 183 | rb.Push(RESULT_SUCCESS); |
| 117 | rb.Push<u32>(static_cast<u32>(state)); | ||
| 118 | } | 184 | } |
| 119 | 185 | ||
| 120 | void GetDeviceState(Kernel::HLERequestContext& ctx) { | 186 | void GetDeviceState(Kernel::HLERequestContext& ctx) { |
| 121 | LOG_WARNING(Service_NFP, "(STUBBED) called"); | 187 | LOG_DEBUG(Service_NFP, "called"); |
| 188 | auto nfc_event = nfp_interface.GetNFCEvent(); | ||
| 189 | if (!nfc_event->ShouldWait(Kernel::GetCurrentThread()) && !has_attached_handle) { | ||
| 190 | device_state = DeviceState::TagFound; | ||
| 191 | nfc_event->Clear(); | ||
| 192 | } | ||
| 193 | |||
| 122 | IPC::ResponseBuilder rb{ctx, 3}; | 194 | IPC::ResponseBuilder rb{ctx, 3}; |
| 123 | rb.Push(RESULT_SUCCESS); | 195 | rb.Push(RESULT_SUCCESS); |
| 124 | rb.Push<u32>(static_cast<u32>(device_state)); | 196 | rb.Push<u32>(static_cast<u32>(device_state)); |
| 125 | } | 197 | } |
| 126 | 198 | ||
| 127 | void GetNpadId(Kernel::HLERequestContext& ctx) { | 199 | void StartDetection(Kernel::HLERequestContext& ctx) { |
| 128 | IPC::RequestParser rp{ctx}; | 200 | LOG_DEBUG(Service_NFP, "called"); |
| 129 | const u64 dev_handle = rp.Pop<u64>(); | 201 | |
| 130 | LOG_WARNING(Service_NFP, "(STUBBED) called, dev_handle=0x{:X}", dev_handle); | 202 | if (device_state == DeviceState::Initialized || device_state == DeviceState::TagRemoved) { |
| 131 | IPC::ResponseBuilder rb{ctx, 3}; | 203 | device_state = DeviceState::SearchingForTag; |
| 204 | } | ||
| 205 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 206 | rb.Push(RESULT_SUCCESS); | ||
| 207 | } | ||
| 208 | |||
| 209 | void GetTagInfo(Kernel::HLERequestContext& ctx) { | ||
| 210 | LOG_DEBUG(Service_NFP, "called"); | ||
| 211 | |||
| 212 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 213 | auto amiibo = nfp_interface.GetAmiiboBuffer(); | ||
| 214 | TagInfo tag_info{}; | ||
| 215 | std::memcpy(tag_info.uuid.data(), amiibo.uuid.data(), sizeof(tag_info.uuid.size())); | ||
| 216 | tag_info.uuid_length = static_cast<u8>(tag_info.uuid.size()); | ||
| 217 | |||
| 218 | tag_info.protocol = 1; // TODO(ogniK): Figure out actual values | ||
| 219 | tag_info.tag_type = 2; | ||
| 220 | ctx.WriteBuffer(&tag_info, sizeof(TagInfo)); | ||
| 221 | rb.Push(RESULT_SUCCESS); | ||
| 222 | } | ||
| 223 | |||
| 224 | void Mount(Kernel::HLERequestContext& ctx) { | ||
| 225 | LOG_DEBUG(Service_NFP, "called"); | ||
| 226 | |||
| 227 | device_state = DeviceState::TagNearby; | ||
| 228 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 229 | rb.Push(RESULT_SUCCESS); | ||
| 230 | } | ||
| 231 | |||
| 232 | void GetModelInfo(Kernel::HLERequestContext& ctx) { | ||
| 233 | LOG_DEBUG(Service_NFP, "called"); | ||
| 234 | |||
| 235 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 236 | auto amiibo = nfp_interface.GetAmiiboBuffer(); | ||
| 237 | ctx.WriteBuffer(&amiibo.model_info, sizeof(amiibo.model_info)); | ||
| 238 | rb.Push(RESULT_SUCCESS); | ||
| 239 | } | ||
| 240 | |||
| 241 | void Unmount(Kernel::HLERequestContext& ctx) { | ||
| 242 | LOG_DEBUG(Service_NFP, "called"); | ||
| 243 | |||
| 244 | device_state = DeviceState::TagFound; | ||
| 245 | |||
| 246 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 247 | rb.Push(RESULT_SUCCESS); | ||
| 248 | } | ||
| 249 | |||
| 250 | void Finalize(Kernel::HLERequestContext& ctx) { | ||
| 251 | LOG_DEBUG(Service_NFP, "called"); | ||
| 252 | |||
| 253 | device_state = DeviceState::Finalized; | ||
| 254 | |||
| 255 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 132 | rb.Push(RESULT_SUCCESS); | 256 | rb.Push(RESULT_SUCCESS); |
| 133 | rb.Push<u32>(npad_id); | ||
| 134 | } | 257 | } |
| 135 | 258 | ||
| 136 | void AttachAvailabilityChangeEvent(Kernel::HLERequestContext& ctx) { | 259 | void AttachAvailabilityChangeEvent(Kernel::HLERequestContext& ctx) { |
| 137 | IPC::RequestParser rp{ctx}; | 260 | LOG_WARNING(Service_NFP, "(STUBBED) called"); |
| 138 | const u64 dev_handle = rp.Pop<u64>(); | ||
| 139 | LOG_WARNING(Service_NFP, "(STUBBED) called, dev_handle=0x{:X}", dev_handle); | ||
| 140 | 261 | ||
| 141 | IPC::ResponseBuilder rb{ctx, 2, 1}; | 262 | IPC::ResponseBuilder rb{ctx, 2, 1}; |
| 142 | rb.Push(RESULT_SUCCESS); | 263 | rb.Push(RESULT_SUCCESS); |
| 143 | rb.PushCopyObjects(availability_change_event); | 264 | rb.PushCopyObjects(availability_change_event); |
| 144 | } | 265 | } |
| 145 | 266 | ||
| 146 | const u64 device_handle{0xDEAD}; | 267 | void GetRegisterInfo(Kernel::HLERequestContext& ctx) { |
| 147 | const u32 npad_id{0}; // This is the first player controller id | 268 | LOG_WARNING(Service_NFP, "(STUBBED) called"); |
| 269 | |||
| 270 | // TODO(ogniK): Pull Mii and owner data from amiibo | ||
| 271 | |||
| 272 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 273 | rb.Push(RESULT_SUCCESS); | ||
| 274 | } | ||
| 275 | |||
| 276 | void GetCommonInfo(Kernel::HLERequestContext& ctx) { | ||
| 277 | LOG_WARNING(Service_NFP, "(STUBBED) called"); | ||
| 278 | |||
| 279 | // TODO(ogniK): Pull common information from amiibo | ||
| 280 | |||
| 281 | CommonInfo common_info{}; | ||
| 282 | common_info.application_area_size = 0; | ||
| 283 | ctx.WriteBuffer(&common_info, sizeof(CommonInfo)); | ||
| 284 | |||
| 285 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 286 | rb.Push(RESULT_SUCCESS); | ||
| 287 | } | ||
| 288 | |||
| 289 | void OpenApplicationArea(Kernel::HLERequestContext& ctx) { | ||
| 290 | LOG_DEBUG(Service_NFP, "called"); | ||
| 291 | // We don't need to worry about this since we can just open the file | ||
| 292 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 293 | rb.Push(RESULT_SUCCESS); | ||
| 294 | } | ||
| 295 | |||
| 296 | void GetApplicationAreaSize(Kernel::HLERequestContext& ctx) { | ||
| 297 | LOG_WARNING(Service_NFP, "(STUBBED) called"); | ||
| 298 | // We don't need to worry about this since we can just open the file | ||
| 299 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 300 | rb.Push(RESULT_SUCCESS); | ||
| 301 | rb.PushRaw<u32>(0); // This is from the GetCommonInfo stub | ||
| 302 | } | ||
| 303 | |||
| 304 | void GetApplicationArea(Kernel::HLERequestContext& ctx) { | ||
| 305 | LOG_WARNING(Service_NFP, "(STUBBED) called"); | ||
| 306 | |||
| 307 | // TODO(ogniK): Pull application area from amiibo | ||
| 308 | |||
| 309 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 310 | rb.Push(RESULT_SUCCESS); | ||
| 311 | rb.PushRaw<u32>(0); // This is from the GetCommonInfo stub | ||
| 312 | } | ||
| 313 | |||
| 314 | bool has_attached_handle{}; | ||
| 315 | const u64 device_handle{Common::MakeMagic('Y', 'U', 'Z', 'U')}; | ||
| 316 | const u32 npad_id{0}; // Player 1 controller | ||
| 148 | State state{State::NonInitialized}; | 317 | State state{State::NonInitialized}; |
| 149 | DeviceState device_state{DeviceState::Initialized}; | 318 | DeviceState device_state{DeviceState::Initialized}; |
| 150 | Kernel::SharedPtr<Kernel::Event> activate_event; | ||
| 151 | Kernel::SharedPtr<Kernel::Event> deactivate_event; | 319 | Kernel::SharedPtr<Kernel::Event> deactivate_event; |
| 152 | Kernel::SharedPtr<Kernel::Event> availability_change_event; | 320 | Kernel::SharedPtr<Kernel::Event> availability_change_event; |
| 321 | const Module::Interface& nfp_interface; | ||
| 153 | }; | 322 | }; |
| 154 | 323 | ||
| 155 | void Module::Interface::CreateUserInterface(Kernel::HLERequestContext& ctx) { | 324 | void Module::Interface::CreateUserInterface(Kernel::HLERequestContext& ctx) { |
| 156 | LOG_DEBUG(Service_NFP, "called"); | 325 | LOG_DEBUG(Service_NFP, "called"); |
| 157 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 326 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 158 | rb.Push(RESULT_SUCCESS); | 327 | rb.Push(RESULT_SUCCESS); |
| 159 | rb.PushIpcInterface<IUser>(); | 328 | rb.PushIpcInterface<IUser>(*this); |
| 329 | } | ||
| 330 | |||
| 331 | void Module::Interface::LoadAmiibo(const std::vector<u8>& buffer) { | ||
| 332 | std::lock_guard<std::recursive_mutex> lock(HLE::g_hle_lock); | ||
| 333 | if (buffer.size() < sizeof(AmiiboFile)) { | ||
| 334 | return; // Failed to load file | ||
| 335 | } | ||
| 336 | std::memcpy(&amiibo, buffer.data(), sizeof(amiibo)); | ||
| 337 | nfc_tag_load->Signal(); | ||
| 338 | } | ||
| 339 | const Kernel::SharedPtr<Kernel::Event>& Module::Interface::GetNFCEvent() const { | ||
| 340 | return nfc_tag_load; | ||
| 341 | } | ||
| 342 | const Module::Interface::AmiiboFile& Module::Interface::GetAmiiboBuffer() const { | ||
| 343 | return amiibo; | ||
| 160 | } | 344 | } |
| 161 | 345 | ||
| 162 | void InstallInterfaces(SM::ServiceManager& service_manager) { | 346 | void InstallInterfaces(SM::ServiceManager& service_manager) { |
diff --git a/src/core/hle/service/nfp/nfp.h b/src/core/hle/service/nfp/nfp.h index 77df343c4..46370dedd 100644 --- a/src/core/hle/service/nfp/nfp.h +++ b/src/core/hle/service/nfp/nfp.h | |||
| @@ -4,6 +4,9 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | ||
| 8 | #include <vector> | ||
| 9 | #include "core/hle/kernel/event.h" | ||
| 7 | #include "core/hle/service/service.h" | 10 | #include "core/hle/service/service.h" |
| 8 | 11 | ||
| 9 | namespace Service::NFP { | 12 | namespace Service::NFP { |
| @@ -15,7 +18,27 @@ public: | |||
| 15 | explicit Interface(std::shared_ptr<Module> module, const char* name); | 18 | explicit Interface(std::shared_ptr<Module> module, const char* name); |
| 16 | ~Interface() override; | 19 | ~Interface() override; |
| 17 | 20 | ||
| 21 | struct ModelInfo { | ||
| 22 | std::array<u8, 0x8> amiibo_identification_block; | ||
| 23 | INSERT_PADDING_BYTES(0x38); | ||
| 24 | }; | ||
| 25 | static_assert(sizeof(ModelInfo) == 0x40, "ModelInfo is an invalid size"); | ||
| 26 | |||
| 27 | struct AmiiboFile { | ||
| 28 | std::array<u8, 10> uuid; | ||
| 29 | INSERT_PADDING_BYTES(0x4a); | ||
| 30 | ModelInfo model_info; | ||
| 31 | }; | ||
| 32 | static_assert(sizeof(AmiiboFile) == 0x94, "AmiiboFile is an invalid size"); | ||
| 33 | |||
| 18 | void CreateUserInterface(Kernel::HLERequestContext& ctx); | 34 | void CreateUserInterface(Kernel::HLERequestContext& ctx); |
| 35 | void LoadAmiibo(const std::vector<u8>& buffer); | ||
| 36 | const Kernel::SharedPtr<Kernel::Event>& GetNFCEvent() const; | ||
| 37 | const AmiiboFile& GetAmiiboBuffer() const; | ||
| 38 | |||
| 39 | private: | ||
| 40 | Kernel::SharedPtr<Kernel::Event> nfc_tag_load{}; | ||
| 41 | AmiiboFile amiibo{}; | ||
| 19 | 42 | ||
| 20 | protected: | 43 | protected: |
| 21 | std::shared_ptr<Module> module; | 44 | std::shared_ptr<Module> module; |
diff --git a/src/core/settings.h b/src/core/settings.h index 8f2da01c8..ca80718e2 100644 --- a/src/core/settings.h +++ b/src/core/settings.h | |||
| @@ -113,6 +113,7 @@ static const std::array<const char*, NumAnalogs> mapping = {{ | |||
| 113 | struct Values { | 113 | struct Values { |
| 114 | // System | 114 | // System |
| 115 | bool use_docked_mode; | 115 | bool use_docked_mode; |
| 116 | bool enable_nfc; | ||
| 116 | std::string username; | 117 | std::string username; |
| 117 | int language_index; | 118 | int language_index; |
| 118 | 119 | ||