diff --git a/.github/workflows/dotnet-publish.yml b/.github/workflows/dotnet-publish.yml index 8706dc8..cc4a6c5 100644 --- a/.github/workflows/dotnet-publish.yml +++ b/.github/workflows/dotnet-publish.yml @@ -7,7 +7,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-dotnet@v1 with: - dotnet-version: '6.0' + dotnet-version: '8.0' - run: 'dotnet restore' - run: 'dotnet publish -o publish/rfpproxy -c Release RfpProxy/RfpProxy.csproj' - run: 'dotnet publish -o publish/rfpproxy.log -c Release RfpProxy.Log/RfpProxy.Log.csproj' diff --git a/AVM.Test/AVM.Test.csproj b/AVM.Test/AVM.Test.csproj index ad35bcc..c265cf6 100644 --- a/AVM.Test/AVM.Test.csproj +++ b/AVM.Test/AVM.Test.csproj @@ -1,15 +1,15 @@ - net6.0 + net8.0 false - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/AVM/AVM.csproj b/AVM/AVM.csproj index ac1a5cd..ebb1fc9 100644 --- a/AVM/AVM.csproj +++ b/AVM/AVM.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 avm RfpProxy.AVM diff --git a/BusyLed/BusyLed.csproj b/BusyLed/BusyLed.csproj index 402e3e4..09f83de 100644 --- a/BusyLed/BusyLed.csproj +++ b/BusyLed/BusyLed.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 busyled RfpProxy.BusyLed diff --git a/CompressIPUI/CompressIPUI.csproj b/CompressIPUI/CompressIPUI.csproj index 8e35d7d..51332f3 100644 --- a/CompressIPUI/CompressIPUI.csproj +++ b/CompressIPUI/CompressIPUI.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 compressipui RfpProxy.CompressIPUI diff --git a/DoS/DoS.csproj b/DoS/DoS.csproj index f030ab2..58dcbc8 100644 --- a/DoS/DoS.csproj +++ b/DoS/DoS.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 dos RfpProxy.Dos diff --git a/MediaTone.Test/MediaTone.Test.csproj b/MediaTone.Test/MediaTone.Test.csproj index 6efeef0..320336f 100644 --- a/MediaTone.Test/MediaTone.Test.csproj +++ b/MediaTone.Test/MediaTone.Test.csproj @@ -1,15 +1,15 @@  - net6.0 + net8.0 false - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/MediaTone/MediaTone.csproj b/MediaTone/MediaTone.csproj index 18ef510..2e1b80b 100644 --- a/MediaTone/MediaTone.csproj +++ b/MediaTone/MediaTone.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 mediatone RfpProxy.MediaTone @@ -16,7 +16,7 @@ - + diff --git a/MorseLed/MorseLed.csproj b/MorseLed/MorseLed.csproj index f29f9e5..684e68a 100644 --- a/MorseLed/MorseLed.csproj +++ b/MorseLed/MorseLed.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 morseled RfpProxy.MorseLed diff --git a/RfpProxy.AaMiDe/AaMiDe/Sys/SysInitMessage.cs b/RfpProxy.AaMiDe/AaMiDe/Sys/SysInitMessage.cs index be8149d..a33cad5 100644 --- a/RfpProxy.AaMiDe/AaMiDe/Sys/SysInitMessage.cs +++ b/RfpProxy.AaMiDe/AaMiDe/Sys/SysInitMessage.cs @@ -224,9 +224,9 @@ public SysInitMessage(PhysicalAddress mac, RfpCapabilities capabilities) : base( Hardware = RfpType.RFP35; Mac2 = mac; Magic = 0x00037a20000529d9; - Protocol = 0x080303u; + Protocol = 0x080500u; Capabilities = capabilities; - SwVersion = "SIP-DECT 8.3-eventphone"; + SwVersion = "SIP-DECT 9.2-eventphone"; } public SysInitMessage(ReadOnlyMemory data):base(MsgType.SYS_INIT, data) @@ -362,4 +362,4 @@ public override void Log(TextWriter writer) writer.Write($"SW Version({SwVersion}) Signature({Signature.ToHex()}) "); } } -} \ No newline at end of file +} diff --git a/RfpProxy.ChangeLed/RfpProxy.ChangeLed.csproj b/RfpProxy.ChangeLed/RfpProxy.ChangeLed.csproj index 74005b0..0e8b5db 100644 --- a/RfpProxy.ChangeLed/RfpProxy.ChangeLed.csproj +++ b/RfpProxy.ChangeLed/RfpProxy.ChangeLed.csproj @@ -2,14 +2,14 @@ Exe - net6.0 + net8.0 true - + diff --git a/RfpProxy.Inject/RfpProxy.Inject.csproj b/RfpProxy.Inject/RfpProxy.Inject.csproj index 33b1ddb..b0e39fd 100644 --- a/RfpProxy.Inject/RfpProxy.Inject.csproj +++ b/RfpProxy.Inject/RfpProxy.Inject.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 rfpproxyinject true diff --git a/RfpProxy.Log/RfpProxy.Log.csproj b/RfpProxy.Log/RfpProxy.Log.csproj index 28f5612..0983b82 100644 --- a/RfpProxy.Log/RfpProxy.Log.csproj +++ b/RfpProxy.Log/RfpProxy.Log.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 rfpproxylog true @@ -10,7 +10,7 @@ - + diff --git a/RfpProxy.Pcap/RfpProxy.Pcap.csproj b/RfpProxy.Pcap/RfpProxy.Pcap.csproj index 4afebbb..7027c6c 100644 --- a/RfpProxy.Pcap/RfpProxy.Pcap.csproj +++ b/RfpProxy.Pcap/RfpProxy.Pcap.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 rfpproxydump true diff --git a/RfpProxy.Test/RfpProxy.Test.csproj b/RfpProxy.Test/RfpProxy.Test.csproj index 42fa5a5..9fa0366 100644 --- a/RfpProxy.Test/RfpProxy.Test.csproj +++ b/RfpProxy.Test/RfpProxy.Test.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 false @@ -18,9 +18,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/RfpProxy.Traffic/RfpProxy.Traffic.csproj b/RfpProxy.Traffic/RfpProxy.Traffic.csproj index cd25439..b4bbf14 100644 --- a/RfpProxy.Traffic/RfpProxy.Traffic.csproj +++ b/RfpProxy.Traffic/RfpProxy.Traffic.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 rfpproxytraffic diff --git a/RfpProxy/AbstractRfpProxy.cs b/RfpProxy/AbstractRfpProxy.cs index 8289aa6..5417a5d 100644 --- a/RfpProxy/AbstractRfpProxy.cs +++ b/RfpProxy/AbstractRfpProxy.cs @@ -21,7 +21,7 @@ public AbstractRfpProxy(int listenPort, string ommHost, int ommPort) protected override async Task ReadFromClientAsync(CryptedRfpConnection connection, PipeReader client, CancellationToken cancellationToken) { var sysInit = await ReadPacketAsync(0x0120, 0, client, cancellationToken).ConfigureAwait(false); - + Console.WriteLine($"[{connection.TraceId}] SYS_INIT"); var iv = connection.RfpToOmmIv; connection.RfpToOmmIv = ReadOnlyMemory.Empty; @@ -37,6 +37,7 @@ protected override async Task ReadFromClientAsync(CryptedRfpConnection connectio protected override async Task ReadFromServerAsync(CryptedRfpConnection connection, PipeReader server, CancellationToken cancellationToken) { var sysAuthenticate = await ReadPacketAsync(0x012d, 0x20, server, cancellationToken).ConfigureAwait(false); + Console.WriteLine($"[{connection.TraceId}] SYS_AUTHENTICATE"); connection.InitRfpToOmmIv(sysAuthenticate.Slice(11, 8).Span); await OnServerMessageAsync(connection, sysAuthenticate, cancellationToken).ConfigureAwait(false); @@ -49,11 +50,13 @@ protected override async Task ReadFromServerAsync(CryptedRfpConnection connectio if (type.Span[1] == 0x24) { //SYS_RFP_AUTH_KEY + Console.WriteLine($"[{connection.TraceId}] SYS_RFP_AUTH_KEY"); key = packet.Slice(4); } else if (type.Span[1] == 0x25) { //SYS_RFP_RE_ENROLEMENT + Console.WriteLine($"[{connection.TraceId}] SYS_RFP_RE_ENROLEMENT"); var checksum = packet.Slice(0x44); var crypted = packet.Slice(4, 0x40); var pw = await GetRootPasswordHashAsync(cancellationToken).ConfigureAwait(false); @@ -94,9 +97,28 @@ protected override async Task ReadFromServerAsync(CryptedRfpConnection connectio await OnServerMessageAsync(connection, packet, cancellationToken).ConfigureAwait(false); packet = await ReadPacketAsync(0x01, 0x08, server, cancellationToken).ConfigureAwait(false); } + else + { + Console.WriteLine($"[{connection.TraceId}] PACKET 0x{type.Span[0]:X2}{type.Span[1]:X2}"); + } var ack = packet; await OnServerMessageAsync(connection, ack, cancellationToken).ConfigureAwait(false); + //check if we have another unencrypted SYS_OMM_CONTROL + //this may happen if the RFP requires a firmware update + var next = await server.ReadAsync(cancellationToken).ConfigureAwait(false); + server.AdvanceTo(next.Buffer.Start, next.Buffer.Start); + if (next.Buffer.Length > 2 && next.Buffer.FirstSpan[0] == 0x01 && next.Buffer.Slice(1).FirstSpan[0] == 0x0c) + { + packet = await ReadPacketAsync(0x010c, 0, server, cancellationToken).ConfigureAwait(false); + Console.WriteLine($"[{connection.TraceId}] SYS_OMM_CONTROL"); + await OnServerMessageAsync(connection, packet, cancellationToken).ConfigureAwait(false); + + packet = await ReadPacketAsync(0x0121, 0, server, cancellationToken).ConfigureAwait(false); + Console.WriteLine($"[{connection.TraceId}] SYS_RESET"); + await OnServerMessageAsync(connection, packet, cancellationToken).ConfigureAwait(false); + } + connection.InitOmmToRfpIv(sysAuthenticate.Slice(27, 8).Span); await ReadAsync(connection, server, OnServerMessageAsync, connection.OmmToRfpIv, connection.DecryptOmmToRfp, cancellationToken).ConfigureAwait(false); @@ -146,7 +168,7 @@ private static async Task ReadAsync(CryptedRfpConnection connection, PipeReader } catch (OperationCanceledException ex) { - Console.WriteLine("cancelled in AbstractRfpProxy.ReadAsync"); + Console.WriteLine($"[{connection.TraceId}] cancelled in AbstractRfpProxy.ReadAsync"); reader.Complete(ex); } } diff --git a/RfpProxy/RfpConnection.cs b/RfpProxy/RfpConnection.cs index 6b30e6f..0d794f3 100644 --- a/RfpProxy/RfpConnection.cs +++ b/RfpProxy/RfpConnection.cs @@ -18,6 +18,7 @@ public RfpConnection(TcpClient client, TcpClient server) } public RfpIdentifier Identifier { get; set; } + public Guid TraceId { get; } = Guid.NewGuid(); public virtual ValueTask SendToServerAsync(ReadOnlyMemory data, CancellationToken cancellationToken) { @@ -30,5 +31,10 @@ public virtual ValueTask SendToClientAsync(ReadOnlyMemory data, Cance if (data.IsEmpty) return new ValueTask(0); return Client.Client.SendAsync(data, SocketFlags.None, cancellationToken); } + + public override string ToString() + { + return TraceId.ToString(); + } } } \ No newline at end of file diff --git a/RfpProxy/RfpProxy.csproj b/RfpProxy/RfpProxy.csproj index 04c562d..17d5a3d 100644 --- a/RfpProxy/RfpProxy.csproj +++ b/RfpProxy/RfpProxy.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 rfpproxy true @@ -10,8 +10,8 @@ - - + + diff --git a/RfpProxy/TcpProxy.cs b/RfpProxy/TcpProxy.cs index cd39568..71c5bd3 100644 --- a/RfpProxy/TcpProxy.cs +++ b/RfpProxy/TcpProxy.cs @@ -95,28 +95,43 @@ private async Task HandleClientAsync(TcpClient client, CancellationToken cancell { await server.ConnectAsync(_server, _port, cts.Token).ConfigureAwait(false); var clientData = OnClientConnected(client, server); + var tasks = new List(); try { var clientPipe = new Pipe(); var fillClientPipe = PipeHelper.FillPipeAsync(client.Client, clientPipe.Writer, cts.Token); + tasks.Add(fillClientPipe); var readClientPipe = ReadFromClientAsync(clientData, clientPipe.Reader, cts.Token); + tasks.Add(readClientPipe); var serverPipe = new Pipe(); var fillServerPipe = PipeHelper.FillPipeAsync(server.Client, serverPipe.Writer, cts.Token); + tasks.Add(fillServerPipe); var readServerPipe = ReadFromServerAsync(clientData, serverPipe.Reader, cts.Token); - - var t = await Task.WhenAny(fillClientPipe, readClientPipe, fillServerPipe, readServerPipe).ConfigureAwait(false); + tasks.Add(readServerPipe); + var t = await Task.WhenAny(tasks).ConfigureAwait(false); await t; } catch (Exception ex) { - Console.WriteLine("HandleClient failed"); - Console.WriteLine(ex); + Console.WriteLine($"[{clientData}] HandleClient failed\n{ex}"); } finally { - cts.Cancel(); - OnClientDisconnected(clientData); + //delay cancellation to allow processing of pending packets + cts.CancelAfter(100); + try + { + await Task.WhenAll(tasks); + } + catch(Exception ex) + { + Console.WriteLine($"[{clientData}] Exception during teardown\n{ex}"); + } + finally + { + OnClientDisconnected(clientData); + } } } } diff --git a/RfpProxyLib/RfpProxyLib.csproj b/RfpProxyLib/RfpProxyLib.csproj index 27c6367..0c3d41a 100644 --- a/RfpProxyLib/RfpProxyLib.csproj +++ b/RfpProxyLib/RfpProxyLib.csproj @@ -10,7 +10,7 @@ - + diff --git a/SoftRfp/SoftRfp.csproj b/SoftRfp/SoftRfp.csproj index 0c124ad..c527d47 100644 --- a/SoftRfp/SoftRfp.csproj +++ b/SoftRfp/SoftRfp.csproj @@ -2,14 +2,14 @@ Exe - net6.0 + net8.0 virtualrfp RfpProxy.Virtual - + diff --git a/rpmbuild/SPECS/rfpproxy.spec b/rpmbuild/SPECS/rfpproxy.spec index c794827..68a29a0 100644 --- a/rpmbuild/SPECS/rfpproxy.spec +++ b/rpmbuild/SPECS/rfpproxy.spec @@ -1,10 +1,10 @@ Summary: rfpproxy Name: rfpproxy Version: 0.0.2 -Release: 1 +Release: 13 License: MIT URL: https://github.com/eventphone/rfpproxy -Requires: dotnet-runtime-6.0 +Requires: dotnet-runtime-8.0 %global __requires_exclude_from ^.*$ %global __provides_exclude_from ^.*$