Merge pull request #9905 from german77/usbssl
Service: USB, SSL, PSC: Update
This commit is contained in:
		@@ -11,9 +11,9 @@
 | 
			
		||||
 | 
			
		||||
namespace Service::PSC {
 | 
			
		||||
 | 
			
		||||
class PSC_C final : public ServiceFramework<PSC_C> {
 | 
			
		||||
class IPmControl final : public ServiceFramework<IPmControl> {
 | 
			
		||||
public:
 | 
			
		||||
    explicit PSC_C(Core::System& system_) : ServiceFramework{system_, "psc:c"} {
 | 
			
		||||
    explicit IPmControl(Core::System& system_) : ServiceFramework{system_, "psc:c"} {
 | 
			
		||||
        // clang-format off
 | 
			
		||||
        static const FunctionInfo functions[] = {
 | 
			
		||||
            {0, nullptr, "Initialize"},
 | 
			
		||||
@@ -23,8 +23,8 @@ public:
 | 
			
		||||
            {4, nullptr, "Cancel"},
 | 
			
		||||
            {5, nullptr, "PrintModuleInformation"},
 | 
			
		||||
            {6, nullptr, "GetModuleInformation"},
 | 
			
		||||
            {10, nullptr, "Unknown10"},
 | 
			
		||||
            {11, nullptr, "Unknown11"},
 | 
			
		||||
            {10, nullptr, "AcquireStateLock"},
 | 
			
		||||
            {11, nullptr, "HasStateLock"},
 | 
			
		||||
        };
 | 
			
		||||
        // clang-format on
 | 
			
		||||
 | 
			
		||||
@@ -49,12 +49,12 @@ public:
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class PSC_M final : public ServiceFramework<PSC_M> {
 | 
			
		||||
class IPmService final : public ServiceFramework<IPmService> {
 | 
			
		||||
public:
 | 
			
		||||
    explicit PSC_M(Core::System& system_) : ServiceFramework{system_, "psc:m"} {
 | 
			
		||||
    explicit IPmService(Core::System& system_) : ServiceFramework{system_, "psc:m"} {
 | 
			
		||||
        // clang-format off
 | 
			
		||||
        static const FunctionInfo functions[] = {
 | 
			
		||||
            {0, &PSC_M::GetPmModule, "GetPmModule"},
 | 
			
		||||
            {0, &IPmService::GetPmModule, "GetPmModule"},
 | 
			
		||||
        };
 | 
			
		||||
        // clang-format on
 | 
			
		||||
 | 
			
		||||
@@ -74,8 +74,8 @@ private:
 | 
			
		||||
void LoopProcess(Core::System& system) {
 | 
			
		||||
    auto server_manager = std::make_unique<ServerManager>(system);
 | 
			
		||||
 | 
			
		||||
    server_manager->RegisterNamedService("psc:c", std::make_shared<PSC_C>(system));
 | 
			
		||||
    server_manager->RegisterNamedService("psc:m", std::make_shared<PSC_M>(system));
 | 
			
		||||
    server_manager->RegisterNamedService("psc:c", std::make_shared<IPmControl>(system));
 | 
			
		||||
    server_manager->RegisterNamedService("psc:m", std::make_shared<IPmService>(system));
 | 
			
		||||
    ServerManager::RunServer(std::move(server_manager));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -8,14 +8,36 @@
 | 
			
		||||
 | 
			
		||||
namespace Service::SSL {
 | 
			
		||||
 | 
			
		||||
// This is nn::ssl::sf::CertificateFormat
 | 
			
		||||
enum class CertificateFormat : u32 {
 | 
			
		||||
    Pem = 1,
 | 
			
		||||
    Der = 2,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// This is nn::ssl::sf::ContextOption
 | 
			
		||||
enum class ContextOption : u32 {
 | 
			
		||||
    None = 0,
 | 
			
		||||
    CrlImportDateCheckEnable = 1,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// This is nn::ssl::sf::SslVersion
 | 
			
		||||
struct SslVersion {
 | 
			
		||||
    union {
 | 
			
		||||
        u32 raw{};
 | 
			
		||||
 | 
			
		||||
        BitField<0, 1, u32> tls_auto;
 | 
			
		||||
        BitField<3, 1, u32> tls_v10;
 | 
			
		||||
        BitField<4, 1, u32> tls_v11;
 | 
			
		||||
        BitField<5, 1, u32> tls_v12;
 | 
			
		||||
        BitField<6, 1, u32> tls_v13;
 | 
			
		||||
        BitField<24, 7, u32> api_version;
 | 
			
		||||
    };
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class ISslConnection final : public ServiceFramework<ISslConnection> {
 | 
			
		||||
public:
 | 
			
		||||
    explicit ISslConnection(Core::System& system_) : ServiceFramework{system_, "ISslConnection"} {
 | 
			
		||||
    explicit ISslConnection(Core::System& system_, SslVersion version)
 | 
			
		||||
        : ServiceFramework{system_, "ISslConnection"}, ssl_version{version} {
 | 
			
		||||
        // clang-format off
 | 
			
		||||
        static const FunctionInfo functions[] = {
 | 
			
		||||
            {0, nullptr, "SetSocketDescriptor"},
 | 
			
		||||
@@ -59,11 +81,15 @@ public:
 | 
			
		||||
 | 
			
		||||
        RegisterHandlers(functions);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    SslVersion ssl_version;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class ISslContext final : public ServiceFramework<ISslContext> {
 | 
			
		||||
public:
 | 
			
		||||
    explicit ISslContext(Core::System& system_) : ServiceFramework{system_, "ISslContext"} {
 | 
			
		||||
    explicit ISslContext(Core::System& system_, SslVersion version)
 | 
			
		||||
        : ServiceFramework{system_, "ISslContext"}, ssl_version{version} {
 | 
			
		||||
        static const FunctionInfo functions[] = {
 | 
			
		||||
            {0, &ISslContext::SetOption, "SetOption"},
 | 
			
		||||
            {1, nullptr, "GetOption"},
 | 
			
		||||
@@ -84,17 +110,20 @@ public:
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    SslVersion ssl_version;
 | 
			
		||||
 | 
			
		||||
    void SetOption(HLERequestContext& ctx) {
 | 
			
		||||
        struct Parameters {
 | 
			
		||||
            u8 enable;
 | 
			
		||||
            u32 option;
 | 
			
		||||
            ContextOption option;
 | 
			
		||||
            s32 value;
 | 
			
		||||
        };
 | 
			
		||||
        static_assert(sizeof(Parameters) == 0x8, "Parameters is an invalid size");
 | 
			
		||||
 | 
			
		||||
        IPC::RequestParser rp{ctx};
 | 
			
		||||
        const auto parameters = rp.PopRaw<Parameters>();
 | 
			
		||||
 | 
			
		||||
        LOG_WARNING(Service_SSL, "(STUBBED) called. enable={}, option={}", parameters.enable,
 | 
			
		||||
                    parameters.option);
 | 
			
		||||
        LOG_WARNING(Service_SSL, "(STUBBED) called. option={}, value={}", parameters.option,
 | 
			
		||||
                    parameters.value);
 | 
			
		||||
 | 
			
		||||
        IPC::ResponseBuilder rb{ctx, 2};
 | 
			
		||||
        rb.Push(ResultSuccess);
 | 
			
		||||
@@ -105,7 +134,7 @@ private:
 | 
			
		||||
 | 
			
		||||
        IPC::ResponseBuilder rb{ctx, 2, 0, 1};
 | 
			
		||||
        rb.Push(ResultSuccess);
 | 
			
		||||
        rb.PushIpcInterface<ISslConnection>(system);
 | 
			
		||||
        rb.PushIpcInterface<ISslConnection>(system, ssl_version);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void ImportServerPki(HLERequestContext& ctx) {
 | 
			
		||||
@@ -142,20 +171,21 @@ private:
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class SSL final : public ServiceFramework<SSL> {
 | 
			
		||||
class ISslService final : public ServiceFramework<ISslService> {
 | 
			
		||||
public:
 | 
			
		||||
    explicit SSL(Core::System& system_) : ServiceFramework{system_, "ssl"} {
 | 
			
		||||
    explicit ISslService(Core::System& system_) : ServiceFramework{system_, "ssl"} {
 | 
			
		||||
        // clang-format off
 | 
			
		||||
        static const FunctionInfo functions[] = {
 | 
			
		||||
            {0, &SSL::CreateContext, "CreateContext"},
 | 
			
		||||
            {0, &ISslService::CreateContext, "CreateContext"},
 | 
			
		||||
            {1, nullptr, "GetContextCount"},
 | 
			
		||||
            {2, nullptr, "GetCertificates"},
 | 
			
		||||
            {3, nullptr, "GetCertificateBufSize"},
 | 
			
		||||
            {4, nullptr, "DebugIoctl"},
 | 
			
		||||
            {5, &SSL::SetInterfaceVersion, "SetInterfaceVersion"},
 | 
			
		||||
            {5, &ISslService::SetInterfaceVersion, "SetInterfaceVersion"},
 | 
			
		||||
            {6, nullptr, "FlushSessionCache"},
 | 
			
		||||
            {7, nullptr, "SetDebugOption"},
 | 
			
		||||
            {8, nullptr, "GetDebugOption"},
 | 
			
		||||
            {8, nullptr, "ClearTls12FallbackFlag"},
 | 
			
		||||
        };
 | 
			
		||||
        // clang-format on
 | 
			
		||||
 | 
			
		||||
@@ -163,20 +193,30 @@ public:
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    u32 ssl_version{};
 | 
			
		||||
    void CreateContext(HLERequestContext& ctx) {
 | 
			
		||||
        LOG_WARNING(Service_SSL, "(STUBBED) called");
 | 
			
		||||
        struct Parameters {
 | 
			
		||||
            SslVersion ssl_version;
 | 
			
		||||
            INSERT_PADDING_BYTES(0x4);
 | 
			
		||||
            u64 pid_placeholder;
 | 
			
		||||
        };
 | 
			
		||||
        static_assert(sizeof(Parameters) == 0x10, "Parameters is an invalid size");
 | 
			
		||||
 | 
			
		||||
        IPC::RequestParser rp{ctx};
 | 
			
		||||
        const auto parameters = rp.PopRaw<Parameters>();
 | 
			
		||||
 | 
			
		||||
        LOG_WARNING(Service_SSL, "(STUBBED) called, api_version={}, pid_placeholder={}",
 | 
			
		||||
                    parameters.ssl_version.api_version, parameters.pid_placeholder);
 | 
			
		||||
 | 
			
		||||
        IPC::ResponseBuilder rb{ctx, 2, 0, 1};
 | 
			
		||||
        rb.Push(ResultSuccess);
 | 
			
		||||
        rb.PushIpcInterface<ISslContext>(system);
 | 
			
		||||
        rb.PushIpcInterface<ISslContext>(system, parameters.ssl_version);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void SetInterfaceVersion(HLERequestContext& ctx) {
 | 
			
		||||
        LOG_DEBUG(Service_SSL, "called");
 | 
			
		||||
 | 
			
		||||
        IPC::RequestParser rp{ctx};
 | 
			
		||||
        ssl_version = rp.Pop<u32>();
 | 
			
		||||
        u32 ssl_version = rp.Pop<u32>();
 | 
			
		||||
 | 
			
		||||
        LOG_DEBUG(Service_SSL, "called, ssl_version={}", ssl_version);
 | 
			
		||||
 | 
			
		||||
        IPC::ResponseBuilder rb{ctx, 2};
 | 
			
		||||
        rb.Push(ResultSuccess);
 | 
			
		||||
@@ -186,7 +226,7 @@ private:
 | 
			
		||||
void LoopProcess(Core::System& system) {
 | 
			
		||||
    auto server_manager = std::make_unique<ServerManager>(system);
 | 
			
		||||
 | 
			
		||||
    server_manager->RegisterNamedService("ssl", std::make_shared<SSL>(system));
 | 
			
		||||
    server_manager->RegisterNamedService("ssl", std::make_shared<ISslService>(system));
 | 
			
		||||
    ServerManager::RunServer(std::move(server_manager));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -16,19 +16,19 @@ public:
 | 
			
		||||
    explicit IDsInterface(Core::System& system_) : ServiceFramework{system_, "IDsInterface"} {
 | 
			
		||||
        // clang-format off
 | 
			
		||||
        static const FunctionInfo functions[] = {
 | 
			
		||||
            {0, nullptr, "BindDevice"},
 | 
			
		||||
            {1, nullptr, "BindClientProcess"},
 | 
			
		||||
            {2, nullptr, "AddInterface"},
 | 
			
		||||
            {3, nullptr, "GetStateChangeEvent"},
 | 
			
		||||
            {4, nullptr, "GetState"},
 | 
			
		||||
            {5, nullptr, "ClearDeviceData"},
 | 
			
		||||
            {6, nullptr, "AddUsbStringDescriptor"},
 | 
			
		||||
            {7, nullptr, "DeleteUsbStringDescriptor"},
 | 
			
		||||
            {8, nullptr, "SetUsbDeviceDescriptor"},
 | 
			
		||||
            {9, nullptr, "SetBinaryObjectStore"},
 | 
			
		||||
            {10, nullptr, "Enable"},
 | 
			
		||||
            {11, nullptr, "Disable"},
 | 
			
		||||
            {12, nullptr, "Unknown12"},
 | 
			
		||||
            {0, nullptr, "AddEndpoint"},
 | 
			
		||||
            {1, nullptr, "GetSetupEvent"},
 | 
			
		||||
            {2, nullptr, "GetSetupPacket"},
 | 
			
		||||
            {3, nullptr, "Enable"},
 | 
			
		||||
            {4, nullptr, "Disable"},
 | 
			
		||||
            {5, nullptr, "CtrlIn"},
 | 
			
		||||
            {6, nullptr, "CtrlOut"},
 | 
			
		||||
            {7, nullptr, "GetCtrlInCompletionEvent"},
 | 
			
		||||
            {8, nullptr, "GetCtrlInUrbReport"},
 | 
			
		||||
            {9, nullptr, "GetCtrlOutCompletionEvent"},
 | 
			
		||||
            {10, nullptr, "GetCtrlOutUrbReport"},
 | 
			
		||||
            {11, nullptr, "CtrlStall"},
 | 
			
		||||
            {12, nullptr, "AppendConfigurationData"},
 | 
			
		||||
        };
 | 
			
		||||
        // clang-format on
 | 
			
		||||
 | 
			
		||||
@@ -36,9 +36,9 @@ public:
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class USB_DS final : public ServiceFramework<USB_DS> {
 | 
			
		||||
class IDsRootSession final : public ServiceFramework<IDsRootSession> {
 | 
			
		||||
public:
 | 
			
		||||
    explicit USB_DS(Core::System& system_) : ServiceFramework{system_, "usb:ds"} {
 | 
			
		||||
    explicit IDsRootSession(Core::System& system_) : ServiceFramework{system_, "usb:ds"} {
 | 
			
		||||
        // clang-format off
 | 
			
		||||
        static const FunctionInfo functions[] = {
 | 
			
		||||
            {0, nullptr, "OpenDsService"},
 | 
			
		||||
@@ -94,9 +94,9 @@ public:
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class USB_HS final : public ServiceFramework<USB_HS> {
 | 
			
		||||
class IClientRootSession final : public ServiceFramework<IClientRootSession> {
 | 
			
		||||
public:
 | 
			
		||||
    explicit USB_HS(Core::System& system_) : ServiceFramework{system_, "usb:hs"} {
 | 
			
		||||
    explicit IClientRootSession(Core::System& system_) : ServiceFramework{system_, "usb:hs"} {
 | 
			
		||||
        // clang-format off
 | 
			
		||||
        static const FunctionInfo functions[] = {
 | 
			
		||||
            {0, nullptr, "BindClientProcess"},
 | 
			
		||||
@@ -107,7 +107,7 @@ public:
 | 
			
		||||
            {5, nullptr, "DestroyInterfaceAvailableEvent"},
 | 
			
		||||
            {6, nullptr, "GetInterfaceStateChangeEvent"},
 | 
			
		||||
            {7, nullptr, "AcquireUsbIf"},
 | 
			
		||||
            {8, nullptr, "ResetDevice"},
 | 
			
		||||
            {8, nullptr, "SetTestMode"},
 | 
			
		||||
        };
 | 
			
		||||
        // clang-format on
 | 
			
		||||
 | 
			
		||||
@@ -134,12 +134,12 @@ public:
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class USB_PD final : public ServiceFramework<USB_PD> {
 | 
			
		||||
class IPdManager final : public ServiceFramework<IPdManager> {
 | 
			
		||||
public:
 | 
			
		||||
    explicit USB_PD(Core::System& system_) : ServiceFramework{system_, "usb:pd"} {
 | 
			
		||||
    explicit IPdManager(Core::System& system_) : ServiceFramework{system_, "usb:pd"} {
 | 
			
		||||
        // clang-format off
 | 
			
		||||
        static const FunctionInfo functions[] = {
 | 
			
		||||
            {0, &USB_PD::GetPdSession, "GetPdSession"},
 | 
			
		||||
            {0, &IPdManager::OpenSession, "OpenSession"},
 | 
			
		||||
        };
 | 
			
		||||
        // clang-format on
 | 
			
		||||
 | 
			
		||||
@@ -147,7 +147,7 @@ public:
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    void GetPdSession(HLERequestContext& ctx) {
 | 
			
		||||
    void OpenSession(HLERequestContext& ctx) {
 | 
			
		||||
        LOG_DEBUG(Service_USB, "called");
 | 
			
		||||
 | 
			
		||||
        IPC::ResponseBuilder rb{ctx, 2, 0, 1};
 | 
			
		||||
@@ -178,12 +178,12 @@ public:
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class USB_PD_C final : public ServiceFramework<USB_PD_C> {
 | 
			
		||||
class IPdCradleManager final : public ServiceFramework<IPdCradleManager> {
 | 
			
		||||
public:
 | 
			
		||||
    explicit USB_PD_C(Core::System& system_) : ServiceFramework{system_, "usb:pd:c"} {
 | 
			
		||||
    explicit IPdCradleManager(Core::System& system_) : ServiceFramework{system_, "usb:pd:c"} {
 | 
			
		||||
        // clang-format off
 | 
			
		||||
        static const FunctionInfo functions[] = {
 | 
			
		||||
            {0, &USB_PD_C::GetPdCradleSession, "GetPdCradleSession"},
 | 
			
		||||
            {0, &IPdCradleManager::OpenCradleSession, "OpenCradleSession"},
 | 
			
		||||
        };
 | 
			
		||||
        // clang-format on
 | 
			
		||||
 | 
			
		||||
@@ -191,18 +191,18 @@ public:
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    void GetPdCradleSession(HLERequestContext& ctx) {
 | 
			
		||||
    void OpenCradleSession(HLERequestContext& ctx) {
 | 
			
		||||
        LOG_DEBUG(Service_USB, "called");
 | 
			
		||||
 | 
			
		||||
        IPC::ResponseBuilder rb{ctx, 2, 0, 1};
 | 
			
		||||
        rb.Push(ResultSuccess);
 | 
			
		||||
        rb.PushIpcInterface<IPdCradleSession>(system);
 | 
			
		||||
 | 
			
		||||
        LOG_DEBUG(Service_USB, "called");
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class USB_PM final : public ServiceFramework<USB_PM> {
 | 
			
		||||
class IPmMainService final : public ServiceFramework<IPmMainService> {
 | 
			
		||||
public:
 | 
			
		||||
    explicit USB_PM(Core::System& system_) : ServiceFramework{system_, "usb:pm"} {
 | 
			
		||||
    explicit IPmMainService(Core::System& system_) : ServiceFramework{system_, "usb:pm"} {
 | 
			
		||||
        // clang-format off
 | 
			
		||||
        static const FunctionInfo functions[] = {
 | 
			
		||||
            {0, nullptr, "GetPowerEvent"},
 | 
			
		||||
@@ -221,11 +221,11 @@ public:
 | 
			
		||||
void LoopProcess(Core::System& system) {
 | 
			
		||||
    auto server_manager = std::make_unique<ServerManager>(system);
 | 
			
		||||
 | 
			
		||||
    server_manager->RegisterNamedService("usb:ds", std::make_shared<USB_DS>(system));
 | 
			
		||||
    server_manager->RegisterNamedService("usb:hs", std::make_shared<USB_HS>(system));
 | 
			
		||||
    server_manager->RegisterNamedService("usb:pd", std::make_shared<USB_PD>(system));
 | 
			
		||||
    server_manager->RegisterNamedService("usb:pd:c", std::make_shared<USB_PD_C>(system));
 | 
			
		||||
    server_manager->RegisterNamedService("usb:pm", std::make_shared<USB_PM>(system));
 | 
			
		||||
    server_manager->RegisterNamedService("usb:ds", std::make_shared<IDsRootSession>(system));
 | 
			
		||||
    server_manager->RegisterNamedService("usb:hs", std::make_shared<IClientRootSession>(system));
 | 
			
		||||
    server_manager->RegisterNamedService("usb:pd", std::make_shared<IPdManager>(system));
 | 
			
		||||
    server_manager->RegisterNamedService("usb:pd:c", std::make_shared<IPdCradleManager>(system));
 | 
			
		||||
    server_manager->RegisterNamedService("usb:pm", std::make_shared<IPmMainService>(system));
 | 
			
		||||
    ServerManager::RunServer(std::move(server_manager));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user