From 635f06bf5076ce849879ce1f684bb4771f7f763c Mon Sep 17 00:00:00 2001 From: Dima Date: Thu, 20 Apr 2023 16:27:49 +0300 Subject: [PATCH] Stub correctly some nifm calls --- .../cpp/skyline/services/nifm/IRequest.cpp | 11 +++++-- .../main/cpp/skyline/services/nifm/IRequest.h | 19 +++++++++++- .../services/socket/sfdnsres/IResolver.cpp | 30 +++++++++---------- .../services/socket/sfdnsres/IResolver.h | 2 -- 4 files changed, 42 insertions(+), 20 deletions(-) diff --git a/app/src/main/cpp/skyline/services/nifm/IRequest.cpp b/app/src/main/cpp/skyline/services/nifm/IRequest.cpp index c627be49..1f00a180 100644 --- a/app/src/main/cpp/skyline/services/nifm/IRequest.cpp +++ b/app/src/main/cpp/skyline/services/nifm/IRequest.cpp @@ -3,6 +3,7 @@ #include #include "IRequest.h" +#include namespace skyline::service::nifm { namespace result { @@ -15,8 +16,10 @@ namespace skyline::service::nifm { BaseService(state, manager) {} Result IRequest::GetRequestState(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { - constexpr u32 Unsubmitted{1}; //!< The request has not been submitted - response.Push(Unsubmitted); + if (*state.settings->isInternetEnabled) + response.Push(RequestState::Accepted); + else + response.Push(RequestState::Invalid); return {}; } @@ -36,6 +39,10 @@ namespace skyline::service::nifm { return {}; } + Result IRequest::Cancel(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { + return {}; + } + Result IRequest::Submit(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { return {}; } diff --git a/app/src/main/cpp/skyline/services/nifm/IRequest.h b/app/src/main/cpp/skyline/services/nifm/IRequest.h index 5c3c15b5..49f19643 100644 --- a/app/src/main/cpp/skyline/services/nifm/IRequest.h +++ b/app/src/main/cpp/skyline/services/nifm/IRequest.h @@ -7,6 +7,17 @@ #include namespace skyline::service::nifm { + /** + * @url https://switchbrew.org/wiki/Network_Interface_services#RequestState + */ + enum class RequestState : u32 { + Invalid = 0, + Free = 1, + OnHold = 2, + Accepted = 3, + Blocking = 4, + }; + /** * @brief IRequest is used by applications to bring up a network * @url https://switchbrew.org/wiki/Network_Interface_services#IRequest @@ -37,6 +48,11 @@ namespace skyline::service::nifm { */ Result GetSystemEventReadableHandles(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); + /** + * @url https://switchbrew.org/wiki/Network_Interface_services#Cancel + */ + Result Cancel(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); + /** * @brief Submits a request to bring up a network * @url https://switchbrew.org/wiki/Network_Interface_services#Submit @@ -57,9 +73,10 @@ namespace skyline::service::nifm { SFUNC(0x0, IRequest, GetRequestState), SFUNC(0x1, IRequest, GetResult), SFUNC(0x2, IRequest, GetSystemEventReadableHandles), + SFUNC(0x3, IRequest, Cancel), SFUNC(0x4, IRequest, Submit), SFUNC(0xB, IRequest, SetConnectionConfirmationOption), SFUNC(0x15, IRequest, GetAppletInfo) - ) + ) }; } diff --git a/app/src/main/cpp/skyline/services/socket/sfdnsres/IResolver.cpp b/app/src/main/cpp/skyline/services/socket/sfdnsres/IResolver.cpp index f90ca091..94af59da 100644 --- a/app/src/main/cpp/skyline/services/socket/sfdnsres/IResolver.cpp +++ b/app/src/main/cpp/skyline/services/socket/sfdnsres/IResolver.cpp @@ -6,6 +6,19 @@ #include namespace skyline::service::socket { + static NetDbError AddrInfoErrorToNetDbError(i32 result) { + switch (result) { + case 0: + return NetDbError::Success; + case EAI_AGAIN: + return NetDbError::TryAgain; + case EAI_NODATA: + return NetDbError::NoData; + default: + return NetDbError::HostNotFound; + } + } + IResolver::IResolver(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager) {} Result IResolver::GetAddrInfoRequest(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { @@ -42,12 +55,12 @@ namespace skyline::service::socket { return {0, -1}; } - addrinfo* result; + addrinfo *result; i32 resultCode = getaddrinfo(hostname.data(), service.data(), nullptr, &result); u32 dataSize{0}; if (resultCode == 0 && result != nullptr) { - const std::vector& data = SerializeAddrInfo(result, resultCode, hostname); + const std::vector data = SerializeAddrInfo(result, resultCode, hostname); dataSize = static_cast(data.size()); request.outputBuf.at(0).copy_from(data); freeaddrinfo(result); @@ -161,17 +174,4 @@ namespace skyline::service::socket { return data; } - - NetDbError IResolver::AddrInfoErrorToNetDbError(i32 result) { - switch (result) { - case 0: - return NetDbError::Success; - case EAI_AGAIN: - return NetDbError::TryAgain; - case EAI_NODATA: - return NetDbError::NoData; - default: - return NetDbError::HostNotFound; - } - } } diff --git a/app/src/main/cpp/skyline/services/socket/sfdnsres/IResolver.h b/app/src/main/cpp/skyline/services/socket/sfdnsres/IResolver.h index 992a48ed..1cddf6a9 100644 --- a/app/src/main/cpp/skyline/services/socket/sfdnsres/IResolver.h +++ b/app/src/main/cpp/skyline/services/socket/sfdnsres/IResolver.h @@ -38,8 +38,6 @@ namespace skyline::service::socket { std::vector SerializeAddrInfo(const addrinfo* addrinfo, i32 result_code, std::string_view host); - NetDbError AddrInfoErrorToNetDbError(i32 result); - SERVICE_DECL( SFUNC(0x6, IResolver, GetAddrInfoRequest), SFUNC(0xA, IResolver, GetHostByNameRequestWithOptions),