aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/IUserLocalCommunicationService.cs
diff options
context:
space:
mode:
authorAc_K <Acoustik666@gmail.com>2019-11-21 13:24:06 +0100
committerThog <me@thog.eu>2019-11-21 13:24:06 +0100
commitcfcc360d0610c66e9b9986f7aab96f79df0da79e (patch)
tree178fb92d9dcbd7f52be430319f44a01149c4bd23 /Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/IUserLocalCommunicationService.cs
parentee81ab547ee35c4f5f3342a6f1e0d6bbc60500e8 (diff)
ldn: Implement calls of UserLocalCommunicationService (#829)
* ldn: Implement calls of UserLocalCommunicationService - Implement `IUserServiceCreator: CreateUserLocalCommunicationService` according to RE. - Implement `IUserLocalCommunicationService` calls: - Every calls in this interface are layered to `NetworkInterface`. - `GetState` according to RE. - `InitializeOld`, `Initialize` and `Finalize` stubbed with the appropriate result code and some TODO according to RE. - `AttachStateChangeEvent` according to RE. * Fix var name and TODO comments * Fix review
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/IUserLocalCommunicationService.cs')
-rw-r--r--Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/IUserLocalCommunicationService.cs88
1 files changed, 88 insertions, 0 deletions
diff --git a/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/IUserLocalCommunicationService.cs b/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/IUserLocalCommunicationService.cs
new file mode 100644
index 00000000..b1ae2d6e
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/IUserLocalCommunicationService.cs
@@ -0,0 +1,88 @@
+using Ryujinx.HLE.HOS.Ipc;
+using Ryujinx.HLE.HOS.Kernel.Common;
+using Ryujinx.HLE.HOS.Services.Ldn.Types;
+using System;
+using System.Net;
+
+namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator
+{
+ class IUserLocalCommunicationService : IpcService
+ {
+ // TODO(Ac_K): Determine what the hardcoded unknown value is.
+ private const int UnknownValue = 90;
+
+ private NetworkInterface _networkInterface;
+
+ private int _stateChangeEventHandle = 0;
+
+ public IUserLocalCommunicationService(ServiceCtx context)
+ {
+ _networkInterface = new NetworkInterface(context.Device.System);
+ }
+
+ [Command(0)]
+ // GetState() -> s32 state
+ public ResultCode GetState(ServiceCtx context)
+ {
+ if (_networkInterface.NifmState != ResultCode.Success)
+ {
+ context.ResponseData.Write((int)NetworkState.Error);
+
+ return ResultCode.Success;
+ }
+
+ ResultCode result = _networkInterface.GetState(out NetworkState state);
+
+ if (result == ResultCode.Success)
+ {
+ context.ResponseData.Write((int)state);
+ }
+
+ return result;
+ }
+
+ [Command(100)]
+ // AttachStateChangeEvent() -> handle<copy>
+ public ResultCode AttachStateChangeEvent(ServiceCtx context)
+ {
+ if (_stateChangeEventHandle == 0)
+ {
+ if (context.Process.HandleTable.GenerateHandle(_networkInterface.StateChangeEvent.ReadableEvent, out _stateChangeEventHandle) != KernelResult.Success)
+ {
+ throw new InvalidOperationException("Out of handles!");
+ }
+ }
+
+ context.Response.HandleDesc = IpcHandleDesc.MakeCopy(_stateChangeEventHandle);
+
+ // Return ResultCode.InvalidArgument if handle is null, doesn't occur in our case since we already throw an Exception.
+
+ return ResultCode.Success;
+ }
+
+ [Command(400)]
+ // InitializeOld(u64, pid)
+ public ResultCode InitializeOld(ServiceCtx context)
+ {
+ return _networkInterface.Initialize(UnknownValue, 0, null, null);
+ }
+
+ [Command(401)]
+ // Finalize()
+ public ResultCode Finalize(ServiceCtx context)
+ {
+ return _networkInterface.Finalize();
+ }
+
+ [Command(402)] // 7.0.0+
+ // Initialize(u64 ip_addresses, u64, pid)
+ public ResultCode Initialize(ServiceCtx context)
+ {
+ // TODO(Ac_K): Determine what addresses are.
+ IPAddress unknownAddress1 = new IPAddress(context.RequestData.ReadUInt32());
+ IPAddress unknownAddress2 = new IPAddress(context.RequestData.ReadUInt32());
+
+ return _networkInterface.Initialize(UnknownValue, version: 1, unknownAddress1, unknownAddress2);
+ }
+ }
+} \ No newline at end of file