diff options
| author | 2023-04-14 17:55:13 -0600 | |
|---|---|---|
| committer | 2023-04-23 23:28:09 -0600 | |
| commit | 00d76fc5f5276b74f4c14edda579981831808d35 (patch) | |
| tree | 601c74976ca479af844e33c58cbb2be376c0830d /src | |
| parent | service: nfc: Create interface (diff) | |
| download | yuzu-00d76fc5f5276b74f4c14edda579981831808d35.tar.gz yuzu-00d76fc5f5276b74f4c14edda579981831808d35.tar.xz yuzu-00d76fc5f5276b74f4c14edda579981831808d35.zip | |
service: nfc: Create mifare interface
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/service/nfc/mifare_interface.cpp (renamed from src/core/hle/service/nfc/mifare_user.cpp) | 58 | ||||
| -rw-r--r-- | src/core/hle/service/nfc/mifare_interface.h (renamed from src/core/hle/service/nfc/mifare_user.h) | 18 | ||||
| -rw-r--r-- | src/core/hle/service/nfc/nfc.cpp | 32 |
3 files changed, 58 insertions, 50 deletions
diff --git a/src/core/hle/service/nfc/mifare_user.cpp b/src/core/hle/service/nfc/mifare_interface.cpp index e0bbd46e1..7e6635ba2 100644 --- a/src/core/hle/service/nfc/mifare_user.cpp +++ b/src/core/hle/service/nfc/mifare_interface.cpp | |||
| @@ -6,33 +6,15 @@ | |||
| 6 | #include "core/hid/hid_types.h" | 6 | #include "core/hid/hid_types.h" |
| 7 | #include "core/hle/kernel/k_event.h" | 7 | #include "core/hle/kernel/k_event.h" |
| 8 | #include "core/hle/service/ipc_helpers.h" | 8 | #include "core/hle/service/ipc_helpers.h" |
| 9 | #include "core/hle/service/nfc/mifare_user.h" | 9 | #include "core/hle/service/nfc/mifare_interface.h" |
| 10 | #include "core/hle/service/nfc/nfc_device.h" | 10 | #include "core/hle/service/nfc/nfc_device.h" |
| 11 | #include "core/hle/service/nfc/nfc_result.h" | 11 | #include "core/hle/service/nfc/nfc_result.h" |
| 12 | 12 | ||
| 13 | namespace Service::NFC { | 13 | namespace Service::NFC { |
| 14 | 14 | ||
| 15 | MFIUser::MFIUser(Core::System& system_) | 15 | MFInterface::MFInterface(Core::System& system_, const char* name) |
| 16 | : ServiceFramework{system_, "NFC::MFIUser"}, service_context{system_, service_name} { | 16 | : ServiceFramework{system_, name}, service_context{system_, service_name} { |
| 17 | static const FunctionInfo functions[] = { | 17 | availability_change_event = service_context.CreateEvent("MFInterface:AvailabilityChangeEvent"); |
| 18 | {0, &MFIUser::Initialize, "Initialize"}, | ||
| 19 | {1, &MFIUser::Finalize, "Finalize"}, | ||
| 20 | {2, &MFIUser::ListDevices, "ListDevices"}, | ||
| 21 | {3, &MFIUser::StartDetection, "StartDetection"}, | ||
| 22 | {4, &MFIUser::StopDetection, "StopDetection"}, | ||
| 23 | {5, &MFIUser::Read, "Read"}, | ||
| 24 | {6, &MFIUser::Write, "Write"}, | ||
| 25 | {7, &MFIUser::GetTagInfo, "GetTagInfo"}, | ||
| 26 | {8, &MFIUser::GetActivateEventHandle, "GetActivateEventHandle"}, | ||
| 27 | {9, &MFIUser::GetDeactivateEventHandle, "GetDeactivateEventHandle"}, | ||
| 28 | {10, &MFIUser::GetState, "GetState"}, | ||
| 29 | {11, &MFIUser::GetDeviceState, "GetDeviceState"}, | ||
| 30 | {12, &MFIUser::GetNpadId, "GetNpadId"}, | ||
| 31 | {13, &MFIUser::GetAvailabilityChangeEventHandle, "GetAvailabilityChangeEventHandle"}, | ||
| 32 | }; | ||
| 33 | RegisterHandlers(functions); | ||
| 34 | |||
| 35 | availability_change_event = service_context.CreateEvent("MFIUser:AvailabilityChangeEvent"); | ||
| 36 | 18 | ||
| 37 | for (u32 device_index = 0; device_index < 10; device_index++) { | 19 | for (u32 device_index = 0; device_index < 10; device_index++) { |
| 38 | devices[device_index] = | 20 | devices[device_index] = |
| @@ -41,11 +23,11 @@ MFIUser::MFIUser(Core::System& system_) | |||
| 41 | } | 23 | } |
| 42 | } | 24 | } |
| 43 | 25 | ||
| 44 | MFIUser ::~MFIUser() { | 26 | MFInterface ::~MFInterface() { |
| 45 | availability_change_event->Close(); | 27 | availability_change_event->Close(); |
| 46 | } | 28 | } |
| 47 | 29 | ||
| 48 | void MFIUser::Initialize(HLERequestContext& ctx) { | 30 | void MFInterface::Initialize(HLERequestContext& ctx) { |
| 49 | LOG_INFO(Service_NFC, "called"); | 31 | LOG_INFO(Service_NFC, "called"); |
| 50 | 32 | ||
| 51 | state = State::Initialized; | 33 | state = State::Initialized; |
| @@ -58,7 +40,7 @@ void MFIUser::Initialize(HLERequestContext& ctx) { | |||
| 58 | rb.Push(ResultSuccess); | 40 | rb.Push(ResultSuccess); |
| 59 | } | 41 | } |
| 60 | 42 | ||
| 61 | void MFIUser::Finalize(HLERequestContext& ctx) { | 43 | void MFInterface::Finalize(HLERequestContext& ctx) { |
| 62 | LOG_INFO(Service_NFC, "called"); | 44 | LOG_INFO(Service_NFC, "called"); |
| 63 | 45 | ||
| 64 | state = State::NonInitialized; | 46 | state = State::NonInitialized; |
| @@ -71,7 +53,7 @@ void MFIUser::Finalize(HLERequestContext& ctx) { | |||
| 71 | rb.Push(ResultSuccess); | 53 | rb.Push(ResultSuccess); |
| 72 | } | 54 | } |
| 73 | 55 | ||
| 74 | void MFIUser::ListDevices(HLERequestContext& ctx) { | 56 | void MFInterface::ListDevices(HLERequestContext& ctx) { |
| 75 | LOG_DEBUG(Service_NFC, "called"); | 57 | LOG_DEBUG(Service_NFC, "called"); |
| 76 | 58 | ||
| 77 | if (state == State::NonInitialized) { | 59 | if (state == State::NonInitialized) { |
| @@ -117,7 +99,7 @@ void MFIUser::ListDevices(HLERequestContext& ctx) { | |||
| 117 | rb.Push(static_cast<s32>(nfp_devices.size())); | 99 | rb.Push(static_cast<s32>(nfp_devices.size())); |
| 118 | } | 100 | } |
| 119 | 101 | ||
| 120 | void MFIUser::StartDetection(HLERequestContext& ctx) { | 102 | void MFInterface::StartDetection(HLERequestContext& ctx) { |
| 121 | IPC::RequestParser rp{ctx}; | 103 | IPC::RequestParser rp{ctx}; |
| 122 | const auto device_handle{rp.Pop<u64>()}; | 104 | const auto device_handle{rp.Pop<u64>()}; |
| 123 | LOG_INFO(Service_NFC, "called, device_handle={}", device_handle); | 105 | LOG_INFO(Service_NFC, "called, device_handle={}", device_handle); |
| @@ -141,7 +123,7 @@ void MFIUser::StartDetection(HLERequestContext& ctx) { | |||
| 141 | rb.Push(result); | 123 | rb.Push(result); |
| 142 | } | 124 | } |
| 143 | 125 | ||
| 144 | void MFIUser::StopDetection(HLERequestContext& ctx) { | 126 | void MFInterface::StopDetection(HLERequestContext& ctx) { |
| 145 | IPC::RequestParser rp{ctx}; | 127 | IPC::RequestParser rp{ctx}; |
| 146 | const auto device_handle{rp.Pop<u64>()}; | 128 | const auto device_handle{rp.Pop<u64>()}; |
| 147 | LOG_INFO(Service_NFC, "called, device_handle={}", device_handle); | 129 | LOG_INFO(Service_NFC, "called, device_handle={}", device_handle); |
| @@ -165,7 +147,7 @@ void MFIUser::StopDetection(HLERequestContext& ctx) { | |||
| 165 | rb.Push(result); | 147 | rb.Push(result); |
| 166 | } | 148 | } |
| 167 | 149 | ||
| 168 | void MFIUser::Read(HLERequestContext& ctx) { | 150 | void MFInterface::Read(HLERequestContext& ctx) { |
| 169 | IPC::RequestParser rp{ctx}; | 151 | IPC::RequestParser rp{ctx}; |
| 170 | const auto device_handle{rp.Pop<u64>()}; | 152 | const auto device_handle{rp.Pop<u64>()}; |
| 171 | const auto buffer{ctx.ReadBuffer()}; | 153 | const auto buffer{ctx.ReadBuffer()}; |
| @@ -206,7 +188,7 @@ void MFIUser::Read(HLERequestContext& ctx) { | |||
| 206 | rb.Push(result); | 188 | rb.Push(result); |
| 207 | } | 189 | } |
| 208 | 190 | ||
| 209 | void MFIUser::Write(HLERequestContext& ctx) { | 191 | void MFInterface::Write(HLERequestContext& ctx) { |
| 210 | IPC::RequestParser rp{ctx}; | 192 | IPC::RequestParser rp{ctx}; |
| 211 | const auto device_handle{rp.Pop<u64>()}; | 193 | const auto device_handle{rp.Pop<u64>()}; |
| 212 | const auto buffer{ctx.ReadBuffer()}; | 194 | const auto buffer{ctx.ReadBuffer()}; |
| @@ -250,7 +232,7 @@ void MFIUser::Write(HLERequestContext& ctx) { | |||
| 250 | rb.Push(result); | 232 | rb.Push(result); |
| 251 | } | 233 | } |
| 252 | 234 | ||
| 253 | void MFIUser::GetTagInfo(HLERequestContext& ctx) { | 235 | void MFInterface::GetTagInfo(HLERequestContext& ctx) { |
| 254 | IPC::RequestParser rp{ctx}; | 236 | IPC::RequestParser rp{ctx}; |
| 255 | const auto device_handle{rp.Pop<u64>()}; | 237 | const auto device_handle{rp.Pop<u64>()}; |
| 256 | LOG_INFO(Service_NFC, "called, device_handle={}", device_handle); | 238 | LOG_INFO(Service_NFC, "called, device_handle={}", device_handle); |
| @@ -276,7 +258,7 @@ void MFIUser::GetTagInfo(HLERequestContext& ctx) { | |||
| 276 | rb.Push(result); | 258 | rb.Push(result); |
| 277 | } | 259 | } |
| 278 | 260 | ||
| 279 | void MFIUser::GetActivateEventHandle(HLERequestContext& ctx) { | 261 | void MFInterface::GetActivateEventHandle(HLERequestContext& ctx) { |
| 280 | IPC::RequestParser rp{ctx}; | 262 | IPC::RequestParser rp{ctx}; |
| 281 | const auto device_handle{rp.Pop<u64>()}; | 263 | const auto device_handle{rp.Pop<u64>()}; |
| 282 | LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); | 264 | LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); |
| @@ -300,7 +282,7 @@ void MFIUser::GetActivateEventHandle(HLERequestContext& ctx) { | |||
| 300 | rb.PushCopyObjects(device.value()->GetActivateEvent()); | 282 | rb.PushCopyObjects(device.value()->GetActivateEvent()); |
| 301 | } | 283 | } |
| 302 | 284 | ||
| 303 | void MFIUser::GetDeactivateEventHandle(HLERequestContext& ctx) { | 285 | void MFInterface::GetDeactivateEventHandle(HLERequestContext& ctx) { |
| 304 | IPC::RequestParser rp{ctx}; | 286 | IPC::RequestParser rp{ctx}; |
| 305 | const auto device_handle{rp.Pop<u64>()}; | 287 | const auto device_handle{rp.Pop<u64>()}; |
| 306 | LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); | 288 | LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); |
| @@ -324,7 +306,7 @@ void MFIUser::GetDeactivateEventHandle(HLERequestContext& ctx) { | |||
| 324 | rb.PushCopyObjects(device.value()->GetDeactivateEvent()); | 306 | rb.PushCopyObjects(device.value()->GetDeactivateEvent()); |
| 325 | } | 307 | } |
| 326 | 308 | ||
| 327 | void MFIUser::GetState(HLERequestContext& ctx) { | 309 | void MFInterface::GetState(HLERequestContext& ctx) { |
| 328 | LOG_DEBUG(Service_NFC, "called"); | 310 | LOG_DEBUG(Service_NFC, "called"); |
| 329 | 311 | ||
| 330 | IPC::ResponseBuilder rb{ctx, 3}; | 312 | IPC::ResponseBuilder rb{ctx, 3}; |
| @@ -332,7 +314,7 @@ void MFIUser::GetState(HLERequestContext& ctx) { | |||
| 332 | rb.PushEnum(state); | 314 | rb.PushEnum(state); |
| 333 | } | 315 | } |
| 334 | 316 | ||
| 335 | void MFIUser::GetDeviceState(HLERequestContext& ctx) { | 317 | void MFInterface::GetDeviceState(HLERequestContext& ctx) { |
| 336 | IPC::RequestParser rp{ctx}; | 318 | IPC::RequestParser rp{ctx}; |
| 337 | const auto device_handle{rp.Pop<u64>()}; | 319 | const auto device_handle{rp.Pop<u64>()}; |
| 338 | LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); | 320 | LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); |
| @@ -350,7 +332,7 @@ void MFIUser::GetDeviceState(HLERequestContext& ctx) { | |||
| 350 | rb.PushEnum(device.value()->GetCurrentState()); | 332 | rb.PushEnum(device.value()->GetCurrentState()); |
| 351 | } | 333 | } |
| 352 | 334 | ||
| 353 | void MFIUser::GetNpadId(HLERequestContext& ctx) { | 335 | void MFInterface::GetNpadId(HLERequestContext& ctx) { |
| 354 | IPC::RequestParser rp{ctx}; | 336 | IPC::RequestParser rp{ctx}; |
| 355 | const auto device_handle{rp.Pop<u64>()}; | 337 | const auto device_handle{rp.Pop<u64>()}; |
| 356 | LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); | 338 | LOG_DEBUG(Service_NFC, "called, device_handle={}", device_handle); |
| @@ -374,7 +356,7 @@ void MFIUser::GetNpadId(HLERequestContext& ctx) { | |||
| 374 | rb.PushEnum(device.value()->GetNpadId()); | 356 | rb.PushEnum(device.value()->GetNpadId()); |
| 375 | } | 357 | } |
| 376 | 358 | ||
| 377 | void MFIUser::GetAvailabilityChangeEventHandle(HLERequestContext& ctx) { | 359 | void MFInterface::GetAvailabilityChangeEventHandle(HLERequestContext& ctx) { |
| 378 | LOG_INFO(Service_NFC, "called"); | 360 | LOG_INFO(Service_NFC, "called"); |
| 379 | 361 | ||
| 380 | if (state == State::NonInitialized) { | 362 | if (state == State::NonInitialized) { |
| @@ -388,7 +370,7 @@ void MFIUser::GetAvailabilityChangeEventHandle(HLERequestContext& ctx) { | |||
| 388 | rb.PushCopyObjects(availability_change_event->GetReadableEvent()); | 370 | rb.PushCopyObjects(availability_change_event->GetReadableEvent()); |
| 389 | } | 371 | } |
| 390 | 372 | ||
| 391 | std::optional<std::shared_ptr<NfcDevice>> MFIUser::GetNfcDevice(u64 handle) { | 373 | std::optional<std::shared_ptr<NfcDevice>> MFInterface::GetNfcDevice(u64 handle) { |
| 392 | for (auto& device : devices) { | 374 | for (auto& device : devices) { |
| 393 | if (device->GetHandle() == handle) { | 375 | if (device->GetHandle() == handle) { |
| 394 | return device; | 376 | return device; |
diff --git a/src/core/hle/service/nfc/mifare_user.h b/src/core/hle/service/nfc/mifare_interface.h index 9701f1d7f..698c8a6b6 100644 --- a/src/core/hle/service/nfc/mifare_user.h +++ b/src/core/hle/service/nfc/mifare_interface.h | |||
| @@ -13,16 +13,10 @@ | |||
| 13 | namespace Service::NFC { | 13 | namespace Service::NFC { |
| 14 | class NfcDevice; | 14 | class NfcDevice; |
| 15 | 15 | ||
| 16 | class MFIUser final : public ServiceFramework<MFIUser> { | 16 | class MFInterface : public ServiceFramework<MFInterface> { |
| 17 | public: | 17 | public: |
| 18 | explicit MFIUser(Core::System& system_); | 18 | explicit MFInterface(Core::System& system_, const char* name); |
| 19 | ~MFIUser(); | 19 | ~MFInterface(); |
| 20 | |||
| 21 | private: | ||
| 22 | enum class State : u32 { | ||
| 23 | NonInitialized, | ||
| 24 | Initialized, | ||
| 25 | }; | ||
| 26 | 20 | ||
| 27 | void Initialize(HLERequestContext& ctx); | 21 | void Initialize(HLERequestContext& ctx); |
| 28 | void Finalize(HLERequestContext& ctx); | 22 | void Finalize(HLERequestContext& ctx); |
| @@ -39,6 +33,12 @@ private: | |||
| 39 | void GetNpadId(HLERequestContext& ctx); | 33 | void GetNpadId(HLERequestContext& ctx); |
| 40 | void GetAvailabilityChangeEventHandle(HLERequestContext& ctx); | 34 | void GetAvailabilityChangeEventHandle(HLERequestContext& ctx); |
| 41 | 35 | ||
| 36 | private: | ||
| 37 | enum class State : u32 { | ||
| 38 | NonInitialized, | ||
| 39 | Initialized, | ||
| 40 | }; | ||
| 41 | |||
| 42 | std::optional<std::shared_ptr<NfcDevice>> GetNfcDevice(u64 handle); | 42 | std::optional<std::shared_ptr<NfcDevice>> GetNfcDevice(u64 handle); |
| 43 | 43 | ||
| 44 | KernelHelpers::ServiceContext service_context; | 44 | KernelHelpers::ServiceContext service_context; |
diff --git a/src/core/hle/service/nfc/nfc.cpp b/src/core/hle/service/nfc/nfc.cpp index 7a8f59725..444d65f07 100644 --- a/src/core/hle/service/nfc/nfc.cpp +++ b/src/core/hle/service/nfc/nfc.cpp | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | #include "common/logging/log.h" | 6 | #include "common/logging/log.h" |
| 7 | #include "common/settings.h" | 7 | #include "common/settings.h" |
| 8 | #include "core/hle/service/ipc_helpers.h" | 8 | #include "core/hle/service/ipc_helpers.h" |
| 9 | #include "core/hle/service/nfc/mifare_user.h" | 9 | #include "core/hle/service/nfc/mifare_interface.h" |
| 10 | #include "core/hle/service/nfc/nfc.h" | 10 | #include "core/hle/service/nfc/nfc.h" |
| 11 | #include "core/hle/service/nfc/nfc_interface.h" | 11 | #include "core/hle/service/nfc/nfc_interface.h" |
| 12 | #include "core/hle/service/server_manager.h" | 12 | #include "core/hle/service/server_manager.h" |
| @@ -16,7 +16,7 @@ namespace Service::NFC { | |||
| 16 | 16 | ||
| 17 | class IUser final : public Interface { | 17 | class IUser final : public Interface { |
| 18 | public: | 18 | public: |
| 19 | explicit IUser(Core::System& system_) : Interface(system_, "IUser") { | 19 | explicit IUser(Core::System& system_) : Interface(system_, "NFC::IUser") { |
| 20 | // clang-format off | 20 | // clang-format off |
| 21 | static const FunctionInfo functions[] = { | 21 | static const FunctionInfo functions[] = { |
| 22 | {0, &Interface::Initialize, "InitializeOld"}, | 22 | {0, &Interface::Initialize, "InitializeOld"}, |
| @@ -50,7 +50,7 @@ public: | |||
| 50 | 50 | ||
| 51 | class ISystem final : public Interface { | 51 | class ISystem final : public Interface { |
| 52 | public: | 52 | public: |
| 53 | explicit ISystem(Core::System& system_) : Interface{system_, "ISystem"} { | 53 | explicit ISystem(Core::System& system_) : Interface{system_, "NFC::ISystem"} { |
| 54 | // clang-format off | 54 | // clang-format off |
| 55 | static const FunctionInfo functions[] = { | 55 | static const FunctionInfo functions[] = { |
| 56 | {0, &Interface::Initialize, "InitializeOld"}, | 56 | {0, &Interface::Initialize, "InitializeOld"}, |
| @@ -85,6 +85,32 @@ public: | |||
| 85 | } | 85 | } |
| 86 | }; | 86 | }; |
| 87 | 87 | ||
| 88 | class MFIUser final : public MFInterface { | ||
| 89 | public: | ||
| 90 | explicit MFIUser(Core::System& system_) : MFInterface{system_, "NFC::MFInterface"} { | ||
| 91 | // clang-format off | ||
| 92 | static const FunctionInfo functions[] = { | ||
| 93 | {0, &MFIUser::Initialize, "Initialize"}, | ||
| 94 | {1, &MFIUser::Finalize, "Finalize"}, | ||
| 95 | {2, &MFIUser::ListDevices, "ListDevices"}, | ||
| 96 | {3, &MFIUser::StartDetection, "StartDetection"}, | ||
| 97 | {4, &MFIUser::StopDetection, "StopDetection"}, | ||
| 98 | {5, &MFIUser::Read, "Read"}, | ||
| 99 | {6, &MFIUser::Write, "Write"}, | ||
| 100 | {7, &MFIUser::GetTagInfo, "GetTagInfo"}, | ||
| 101 | {8, &MFIUser::GetActivateEventHandle, "GetActivateEventHandle"}, | ||
| 102 | {9, &MFIUser::GetDeactivateEventHandle, "GetDeactivateEventHandle"}, | ||
| 103 | {10, &MFIUser::GetState, "GetState"}, | ||
| 104 | {11, &MFIUser::GetDeviceState, "GetDeviceState"}, | ||
| 105 | {12, &MFIUser::GetNpadId, "GetNpadId"}, | ||
| 106 | {13, &MFIUser::GetAvailabilityChangeEventHandle, "GetAvailabilityChangeEventHandle"}, | ||
| 107 | }; | ||
| 108 | // clang-format on | ||
| 109 | |||
| 110 | RegisterHandlers(functions); | ||
| 111 | } | ||
| 112 | }; | ||
| 113 | |||
| 88 | class IAm final : public ServiceFramework<IAm> { | 114 | class IAm final : public ServiceFramework<IAm> { |
| 89 | public: | 115 | public: |
| 90 | explicit IAm(Core::System& system_) : ServiceFramework{system_, "NFC::IAm"} { | 116 | explicit IAm(Core::System& system_) : ServiceFramework{system_, "NFC::IAm"} { |