nifm/ssl: Implement GetCurrentNetworkProfile and stub Ssl Service (#2186)

* nifm/ssl: Implement GetCurrentNetworkProfile and stub Ssl Service

* remove InterfaceVersion
This commit is contained in:
Ac_K 2021-04-13 03:04:18 +02:00 committed by GitHub
parent 73881fad19
commit b662a26c7e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 375 additions and 56 deletions

View file

@ -2,8 +2,11 @@ using Ryujinx.Common;
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Services.Nifm.StaticService.GeneralService;
using Ryujinx.HLE.HOS.Services.Nifm.StaticService.Types;
using Ryujinx.HLE.Utilities;
using System;
using System.Net.NetworkInformation;
using System.Runtime.CompilerServices;
using System.Text;
namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
{
@ -51,6 +54,38 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
return ResultCode.Success;
}
[Command(5)]
// GetCurrentNetworkProfile() -> buffer<nn::nifm::detail::sf::NetworkProfileData, 0x1a, 0x17c>
public ResultCode GetCurrentNetworkProfile(ServiceCtx context)
{
long networkProfileDataPosition = context.Request.RecvListBuff[0].Position;
(IPInterfaceProperties interfaceProperties, UnicastIPAddressInformation unicastAddress) = GetLocalInterface();
if (interfaceProperties == null || unicastAddress == null)
{
return ResultCode.NoInternetConnection;
}
Logger.Info?.Print(LogClass.ServiceNifm, $"Console's local IP is \"{unicastAddress.Address}\".");
context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(Unsafe.SizeOf<NetworkProfileData>());
NetworkProfileData networkProfile = new NetworkProfileData
{
Uuid = new UInt128(Guid.NewGuid().ToByteArray())
};
networkProfile.IpSettingData.IpAddressSetting = new IpAddressSetting(interfaceProperties, unicastAddress);
networkProfile.IpSettingData.DnsSetting = new DnsSetting(interfaceProperties);
Encoding.ASCII.GetBytes("RyujinxNetwork").CopyTo(networkProfile.Name.ToSpan());
context.Memory.Write((ulong)networkProfileDataPosition, networkProfile);
return ResultCode.Success;
}
[Command(12)]
// GetCurrentIpAddress() -> nn::nifm::IpV4Address
public ResultCode GetCurrentIpAddress(ServiceCtx context)
@ -75,7 +110,7 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
{
(IPInterfaceProperties interfaceProperties, UnicastIPAddressInformation unicastAddress) = GetLocalInterface();
if (interfaceProperties == null)
if (interfaceProperties == null || unicastAddress == null)
{
return ResultCode.NoInternetConnection;
}
@ -138,11 +173,11 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
foreach (NetworkInterface adapter in interfaces)
{
// Ignore loopback and non IPv4 capable interface.
if (adapter.NetworkInterfaceType != NetworkInterfaceType.Loopback && adapter.Supports(NetworkInterfaceComponent.IPv4))
if (targetProperties == null && adapter.NetworkInterfaceType != NetworkInterfaceType.Loopback && adapter.Supports(NetworkInterfaceComponent.IPv4))
{
IPInterfaceProperties properties = adapter.GetIPProperties();
if (properties.GatewayAddresses.Count > 0 && properties.DnsAddresses.Count > 1)
if (properties.GatewayAddresses.Count > 0 && properties.DnsAddresses.Count > 0)
{
foreach (UnicastIPAddressInformation info in properties.UnicastAddresses)
{
@ -156,12 +191,6 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService
}
}
}
// Found the target interface, stop here.
if (targetProperties != null)
{
break;
}
}
}

View file

@ -14,8 +14,17 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService.Types
public DnsSetting(IPInterfaceProperties interfaceProperties)
{
IsDynamicDnsEnabled = interfaceProperties.IsDynamicDnsEnabled;
PrimaryDns = new IpV4Address(interfaceProperties.DnsAddresses[0]);
SecondaryDns = new IpV4Address(interfaceProperties.DnsAddresses[1]);
if (interfaceProperties.DnsAddresses.Count == 0)
{
PrimaryDns = new IpV4Address();
SecondaryDns = new IpV4Address();
}
else
{
PrimaryDns = new IpV4Address(interfaceProperties.DnsAddresses[0]);
SecondaryDns = new IpV4Address(interfaceProperties.DnsAddresses[interfaceProperties.DnsAddresses.Count > 1 ? 1 : 0]);
}
}
}
}
}

View file

@ -0,0 +1,13 @@
using System.Runtime.InteropServices;
namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService.Types
{
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0xc2)]
struct IpSettingData
{
public IpAddressSetting IpAddressSetting;
public DnsSetting DnsSetting;
public ProxySetting ProxySetting;
public short Mtu;
}
}

View file

@ -0,0 +1,17 @@
using Ryujinx.Common.Memory;
using Ryujinx.HLE.Utilities;
using System.Runtime.InteropServices;
namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService.Types
{
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x17C)]
struct NetworkProfileData
{
public IpSettingData IpSettingData;
public UInt128 Uuid;
public Array64<byte> Name;
public Array4<byte> Unknown;
public WirelessSettingData WirelessSettingData;
public byte Padding;
}
}

View file

@ -0,0 +1,27 @@
using LibHac.Common;
using Ryujinx.Common.Memory;
using System;
using System.Runtime.InteropServices;
namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService.Types
{
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0xaa)]
public struct ProxySetting
{
[MarshalAs(UnmanagedType.I1)]
public bool Enabled;
private byte _padding;
public short Port;
private NameStruct _name;
[MarshalAs(UnmanagedType.I1)]
public bool AutoAuthEnabled;
public Array32<byte> User;
public Array32<byte> Pass;
private byte _padding2;
[StructLayout(LayoutKind.Sequential, Size = 0x64)]
private struct NameStruct { }
public Span<byte> Name => SpanHelpers.AsSpan<NameStruct, byte>(ref _name);
}
}

View file

@ -0,0 +1,15 @@
using Ryujinx.Common.Memory;
using System.Runtime.InteropServices;
namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService.Types
{
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x65)]
struct WirelessSettingData
{
public byte SsidLength;
public Array32<byte> Ssid;
public Array3<byte> Unknown;
public Array64<byte> Passphrase1;
public byte Passphrase2;
}
}