From 8c95f4852582d4587bf8c52442164b4714c910b8 Mon Sep 17 00:00:00 2001 From: Martin Lang Date: Fri, 18 Apr 2025 16:33:54 +0200 Subject: [PATCH 01/22] Update SysInit Message to announce 9.2 --- RfpProxy.AaMiDe/AaMiDe/Sys/SysInitMessage.cs | 6 +++--- rpmbuild/SPECS/rfpproxy.spec | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) 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/rpmbuild/SPECS/rfpproxy.spec b/rpmbuild/SPECS/rfpproxy.spec index c794827..22ce44d 100644 --- a/rpmbuild/SPECS/rfpproxy.spec +++ b/rpmbuild/SPECS/rfpproxy.spec @@ -1,7 +1,7 @@ Summary: rfpproxy Name: rfpproxy Version: 0.0.2 -Release: 1 +Release: 2 License: MIT URL: https://github.com/eventphone/rfpproxy Requires: dotnet-runtime-6.0 From ed71a8e06dc4172452495d6be7ef6420432b9a5b Mon Sep 17 00:00:00 2001 From: zivillian Date: Fri, 18 Apr 2025 21:26:07 +0200 Subject: [PATCH 02/22] upgrade --- AVM.Test/AVM.Test.csproj | 8 ++++---- AVM/AVM.csproj | 2 +- BusyLed/BusyLed.csproj | 2 +- CompressIPUI/CompressIPUI.csproj | 2 +- DoS/DoS.csproj | 2 +- MediaTone.Test/MediaTone.Test.csproj | 8 ++++---- MediaTone/MediaTone.csproj | 4 ++-- MorseLed/MorseLed.csproj | 2 +- RfpProxy.ChangeLed/RfpProxy.ChangeLed.csproj | 4 ++-- RfpProxy.Inject/RfpProxy.Inject.csproj | 2 +- RfpProxy.Log/RfpProxy.Log.csproj | 4 ++-- RfpProxy.Pcap/RfpProxy.Pcap.csproj | 2 +- RfpProxy.Test/RfpProxy.Test.csproj | 8 ++++---- RfpProxy.Traffic/RfpProxy.Traffic.csproj | 2 +- RfpProxy/RfpProxy.csproj | 6 +++--- RfpProxyLib/RfpProxyLib.csproj | 2 +- SoftRfp/SoftRfp.csproj | 4 ++-- 17 files changed, 32 insertions(+), 32 deletions(-) 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.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/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/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 - + From 52867302b8ac4ec9ac74cdb2dd12dc05769638e5 Mon Sep 17 00:00:00 2001 From: zivillian Date: Sat, 19 Apr 2025 14:40:19 +0200 Subject: [PATCH 03/22] update deps --- .github/workflows/dotnet-publish.yml | 2 +- rpmbuild/SPECS/rfpproxy.spec | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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/rpmbuild/SPECS/rfpproxy.spec b/rpmbuild/SPECS/rfpproxy.spec index 22ce44d..44afede 100644 --- a/rpmbuild/SPECS/rfpproxy.spec +++ b/rpmbuild/SPECS/rfpproxy.spec @@ -1,10 +1,10 @@ Summary: rfpproxy Name: rfpproxy Version: 0.0.2 -Release: 2 +Release: 3 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 ^.*$ From 7efcd648e524f53b9e6eb27f0b52b2dc1fe88ef6 Mon Sep 17 00:00:00 2001 From: zivillian Date: Sat, 19 Apr 2025 15:46:44 +0200 Subject: [PATCH 04/22] always send ACK --- RfpProxy/AbstractRfpProxy.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/RfpProxy/AbstractRfpProxy.cs b/RfpProxy/AbstractRfpProxy.cs index 8289aa6..a2b7d22 100644 --- a/RfpProxy/AbstractRfpProxy.cs +++ b/RfpProxy/AbstractRfpProxy.cs @@ -95,7 +95,12 @@ protected override async Task ReadFromServerAsync(CryptedRfpConnection connectio packet = await ReadPacketAsync(0x01, 0x08, server, cancellationToken).ConfigureAwait(false); } var ack = packet; - await OnServerMessageAsync(connection, ack, cancellationToken).ConfigureAwait(false); + /* + * if the omm closed the connection due to version mismatch, we still need to send the + * ack packet. That's why we can't use the cancellationtoken + */ + + await OnServerMessageAsync(connection, ack, CancellationToken.None).ConfigureAwait(false); connection.InitOmmToRfpIv(sysAuthenticate.Slice(27, 8).Span); From 09aa20fbb42ebc712512d146d962f228ba4fae7a Mon Sep 17 00:00:00 2001 From: zivillian Date: Sat, 19 Apr 2025 17:04:57 +0200 Subject: [PATCH 05/22] await all reads & writes before disposing the sockets --- RfpProxy/TcpProxy.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/RfpProxy/TcpProxy.cs b/RfpProxy/TcpProxy.cs index cd39568..1496b45 100644 --- a/RfpProxy/TcpProxy.cs +++ b/RfpProxy/TcpProxy.cs @@ -95,17 +95,21 @@ 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) @@ -117,6 +121,7 @@ private async Task HandleClientAsync(TcpClient client, CancellationToken cancell { cts.Cancel(); OnClientDisconnected(clientData); + await Task.WhenAll(tasks); } } } From 0ee236f67f7738e006d71cc8f65553f72bd786c6 Mon Sep 17 00:00:00 2001 From: zivillian Date: Sat, 19 Apr 2025 17:25:06 +0200 Subject: [PATCH 06/22] bump version --- rpmbuild/SPECS/rfpproxy.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpmbuild/SPECS/rfpproxy.spec b/rpmbuild/SPECS/rfpproxy.spec index 44afede..19e2211 100644 --- a/rpmbuild/SPECS/rfpproxy.spec +++ b/rpmbuild/SPECS/rfpproxy.spec @@ -1,7 +1,7 @@ Summary: rfpproxy Name: rfpproxy Version: 0.0.2 -Release: 3 +Release: 4 License: MIT URL: https://github.com/eventphone/rfpproxy Requires: dotnet-runtime-8.0 From 542b827fcfa023eedc2f8bc5a315e5a77e047c45 Mon Sep 17 00:00:00 2001 From: zivillian Date: Sat, 19 Apr 2025 18:24:25 +0200 Subject: [PATCH 07/22] moar logging --- RfpProxy/AbstractRfpProxy.cs | 2 +- RfpProxy/RfpConnection.cs | 6 ++++++ RfpProxy/TcpProxy.cs | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/RfpProxy/AbstractRfpProxy.cs b/RfpProxy/AbstractRfpProxy.cs index a2b7d22..3cc5368 100644 --- a/RfpProxy/AbstractRfpProxy.cs +++ b/RfpProxy/AbstractRfpProxy.cs @@ -151,7 +151,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/TcpProxy.cs b/RfpProxy/TcpProxy.cs index 1496b45..ba23655 100644 --- a/RfpProxy/TcpProxy.cs +++ b/RfpProxy/TcpProxy.cs @@ -114,7 +114,7 @@ private async Task HandleClientAsync(TcpClient client, CancellationToken cancell } catch (Exception ex) { - Console.WriteLine("HandleClient failed"); + Console.WriteLine($"[{clientData}] HandleClient failed"); Console.WriteLine(ex); } finally From 5bf9fafd4e49867c84b8409f38cfc36836af57ff Mon Sep 17 00:00:00 2001 From: zivillian Date: Sat, 19 Apr 2025 18:24:44 +0200 Subject: [PATCH 08/22] bump version --- rpmbuild/SPECS/rfpproxy.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpmbuild/SPECS/rfpproxy.spec b/rpmbuild/SPECS/rfpproxy.spec index 19e2211..79ba978 100644 --- a/rpmbuild/SPECS/rfpproxy.spec +++ b/rpmbuild/SPECS/rfpproxy.spec @@ -1,7 +1,7 @@ Summary: rfpproxy Name: rfpproxy Version: 0.0.2 -Release: 4 +Release: 5 License: MIT URL: https://github.com/eventphone/rfpproxy Requires: dotnet-runtime-8.0 From ccc8a6c5af1adfe00f014cdbc2ad54c648388e4f Mon Sep 17 00:00:00 2001 From: zivillian Date: Sat, 19 Apr 2025 18:35:46 +0200 Subject: [PATCH 09/22] moar logging --- RfpProxy/AbstractRfpProxy.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/RfpProxy/AbstractRfpProxy.cs b/RfpProxy/AbstractRfpProxy.cs index 3cc5368..4cdc5da 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,6 +97,10 @@ 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; /* * if the omm closed the connection due to version mismatch, we still need to send the From 72bbc8a493ac5c7bb0ab14f547060e460fc38387 Mon Sep 17 00:00:00 2001 From: zivillian Date: Sat, 19 Apr 2025 18:41:17 +0200 Subject: [PATCH 10/22] combine log --- RfpProxy/TcpProxy.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/RfpProxy/TcpProxy.cs b/RfpProxy/TcpProxy.cs index ba23655..4449dcc 100644 --- a/RfpProxy/TcpProxy.cs +++ b/RfpProxy/TcpProxy.cs @@ -114,8 +114,7 @@ private async Task HandleClientAsync(TcpClient client, CancellationToken cancell } catch (Exception ex) { - Console.WriteLine($"[{clientData}] HandleClient failed"); - Console.WriteLine(ex); + Console.WriteLine($"[{clientData}] HandleClient failed\n{ex}"); } finally { From d5717fe6ea32b35dc5d3ec64e087ec3ae0ff9d34 Mon Sep 17 00:00:00 2001 From: zivillian Date: Sat, 19 Apr 2025 19:40:05 +0200 Subject: [PATCH 11/22] wait before cancelling disconnected clients --- RfpProxy/TcpProxy.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/RfpProxy/TcpProxy.cs b/RfpProxy/TcpProxy.cs index 4449dcc..71c5bd3 100644 --- a/RfpProxy/TcpProxy.cs +++ b/RfpProxy/TcpProxy.cs @@ -118,9 +118,20 @@ private async Task HandleClientAsync(TcpClient client, CancellationToken cancell } finally { - cts.Cancel(); - OnClientDisconnected(clientData); - await Task.WhenAll(tasks); + //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); + } } } } From 87dc87f00390c2283b3162c7e6e6a2e1be67a4b8 Mon Sep 17 00:00:00 2001 From: zivillian Date: Sat, 19 Apr 2025 19:40:52 +0200 Subject: [PATCH 12/22] bump version --- rpmbuild/SPECS/rfpproxy.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpmbuild/SPECS/rfpproxy.spec b/rpmbuild/SPECS/rfpproxy.spec index 79ba978..a397b8c 100644 --- a/rpmbuild/SPECS/rfpproxy.spec +++ b/rpmbuild/SPECS/rfpproxy.spec @@ -1,7 +1,7 @@ Summary: rfpproxy Name: rfpproxy Version: 0.0.2 -Release: 5 +Release: 6 License: MIT URL: https://github.com/eventphone/rfpproxy Requires: dotnet-runtime-8.0 From dbf8efa82f5a49c710b92b4239b8ff429a36e6a7 Mon Sep 17 00:00:00 2001 From: zivillian Date: Sat, 19 Apr 2025 20:20:09 +0200 Subject: [PATCH 13/22] rly? --- RfpProxy/AbstractRfpProxy.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/RfpProxy/AbstractRfpProxy.cs b/RfpProxy/AbstractRfpProxy.cs index 4cdc5da..75f1705 100644 --- a/RfpProxy/AbstractRfpProxy.cs +++ b/RfpProxy/AbstractRfpProxy.cs @@ -102,12 +102,19 @@ protected override async Task ReadFromServerAsync(CryptedRfpConnection connectio Console.WriteLine($"[{connection.TraceId}] PACKET 0x{type.Span[0]:X2}{type.Span[1]:X2}"); } var ack = packet; - /* - * if the omm closed the connection due to version mismatch, we still need to send the - * ack packet. That's why we can't use the cancellationtoken - */ - - await OnServerMessageAsync(connection, ack, CancellationToken.None).ConfigureAwait(false); + 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 + if (server.TryRead(out var available)){ + var buffer = available.Buffer; + if (buffer.Length > 2 && buffer.FirstSpan[0] == 0x01 && buffer.Slice(1).FirstSpan[0] == 0x0c) + { + Console.WriteLine($"[{connection.TraceId}] found SYS_OMM_CONTROL"); + packet = await ReadPacketAsync(0x010c, 0x08, server, cancellationToken).ConfigureAwait(false); + Console.WriteLine($"[{connection.TraceId}] SYS_OMM_CONTROL"); + await OnServerMessageAsync(connection, packet, cancellationToken).ConfigureAwait(false); + } + } connection.InitOmmToRfpIv(sysAuthenticate.Slice(27, 8).Span); From b882312e7bad6f2f93f8326f5c644a4895adcf60 Mon Sep 17 00:00:00 2001 From: zivillian Date: Sat, 19 Apr 2025 20:20:47 +0200 Subject: [PATCH 14/22] bump version --- rpmbuild/SPECS/rfpproxy.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpmbuild/SPECS/rfpproxy.spec b/rpmbuild/SPECS/rfpproxy.spec index a397b8c..a6263a9 100644 --- a/rpmbuild/SPECS/rfpproxy.spec +++ b/rpmbuild/SPECS/rfpproxy.spec @@ -1,7 +1,7 @@ Summary: rfpproxy Name: rfpproxy Version: 0.0.2 -Release: 6 +Release: 7 License: MIT URL: https://github.com/eventphone/rfpproxy Requires: dotnet-runtime-8.0 From c6b1c6a0832a77bf6785aa8f77a76c9be81de47f Mon Sep 17 00:00:00 2001 From: zivillian Date: Sat, 19 Apr 2025 20:44:36 +0200 Subject: [PATCH 15/22] cancel TryRead --- RfpProxy/AbstractRfpProxy.cs | 1 + rpmbuild/SPECS/rfpproxy.spec | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/RfpProxy/AbstractRfpProxy.cs b/RfpProxy/AbstractRfpProxy.cs index 75f1705..ea6444b 100644 --- a/RfpProxy/AbstractRfpProxy.cs +++ b/RfpProxy/AbstractRfpProxy.cs @@ -106,6 +106,7 @@ protected override async Task ReadFromServerAsync(CryptedRfpConnection connectio //check if we have another unencrypted SYS_OMM_CONTROL //this may happen if the RFP requires a firmware update if (server.TryRead(out var available)){ + server.CancelPendingRead(); var buffer = available.Buffer; if (buffer.Length > 2 && buffer.FirstSpan[0] == 0x01 && buffer.Slice(1).FirstSpan[0] == 0x0c) { diff --git a/rpmbuild/SPECS/rfpproxy.spec b/rpmbuild/SPECS/rfpproxy.spec index a6263a9..419c4f2 100644 --- a/rpmbuild/SPECS/rfpproxy.spec +++ b/rpmbuild/SPECS/rfpproxy.spec @@ -1,7 +1,7 @@ Summary: rfpproxy Name: rfpproxy Version: 0.0.2 -Release: 7 +Release: 8 License: MIT URL: https://github.com/eventphone/rfpproxy Requires: dotnet-runtime-8.0 From e784cce4d48cf29fb5da08f242f9b819beb0db77 Mon Sep 17 00:00:00 2001 From: zivillian Date: Sat, 19 Apr 2025 23:10:12 +0200 Subject: [PATCH 16/22] always read next packet to check for SYS_OMM_CONTROL --- RfpProxy/AbstractRfpProxy.cs | 20 +++++++++----------- rpmbuild/SPECS/rfpproxy.spec | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/RfpProxy/AbstractRfpProxy.cs b/RfpProxy/AbstractRfpProxy.cs index ea6444b..0cbf427 100644 --- a/RfpProxy/AbstractRfpProxy.cs +++ b/RfpProxy/AbstractRfpProxy.cs @@ -103,19 +103,17 @@ protected override async Task ReadFromServerAsync(CryptedRfpConnection connectio } 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 - if (server.TryRead(out var available)){ - server.CancelPendingRead(); - var buffer = available.Buffer; - if (buffer.Length > 2 && buffer.FirstSpan[0] == 0x01 && buffer.Slice(1).FirstSpan[0] == 0x0c) - { - Console.WriteLine($"[{connection.TraceId}] found SYS_OMM_CONTROL"); - packet = await ReadPacketAsync(0x010c, 0x08, server, cancellationToken).ConfigureAwait(false); - Console.WriteLine($"[{connection.TraceId}] SYS_OMM_CONTROL"); - await OnServerMessageAsync(connection, packet, cancellationToken).ConfigureAwait(false); - } - } + var next = await server.ReadAsync(cancellationToken); + if (next.Buffer.Length > 2 && next.Buffer.FirstSpan[0] == 0x01 && next.Buffer.Slice(1).FirstSpan[0] == 0x0c) + { + Console.WriteLine($"[{connection.TraceId}] found SYS_OMM_CONTROL"); + packet = await ReadPacketAsync(0x010c, 0x08, server, cancellationToken).ConfigureAwait(false); + Console.WriteLine($"[{connection.TraceId}] SYS_OMM_CONTROL"); + await OnServerMessageAsync(connection, packet, cancellationToken).ConfigureAwait(false); + } connection.InitOmmToRfpIv(sysAuthenticate.Slice(27, 8).Span); diff --git a/rpmbuild/SPECS/rfpproxy.spec b/rpmbuild/SPECS/rfpproxy.spec index 419c4f2..40001ee 100644 --- a/rpmbuild/SPECS/rfpproxy.spec +++ b/rpmbuild/SPECS/rfpproxy.spec @@ -1,7 +1,7 @@ Summary: rfpproxy Name: rfpproxy Version: 0.0.2 -Release: 8 +Release: 9 License: MIT URL: https://github.com/eventphone/rfpproxy Requires: dotnet-runtime-8.0 From 7d41b6b8afacd119b9c94204572872a204b3b0bd Mon Sep 17 00:00:00 2001 From: zivillian Date: Sun, 20 Apr 2025 00:01:37 +0200 Subject: [PATCH 17/22] Bernie --- RfpProxy/AbstractRfpProxy.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/RfpProxy/AbstractRfpProxy.cs b/RfpProxy/AbstractRfpProxy.cs index 0cbf427..8935541 100644 --- a/RfpProxy/AbstractRfpProxy.cs +++ b/RfpProxy/AbstractRfpProxy.cs @@ -106,14 +106,15 @@ protected override async Task ReadFromServerAsync(CryptedRfpConnection connectio //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); + var next = await server.ReadAsync(cancellationToken).ConfigureAwait(false); if (next.Buffer.Length > 2 && next.Buffer.FirstSpan[0] == 0x01 && next.Buffer.Slice(1).FirstSpan[0] == 0x0c) { Console.WriteLine($"[{connection.TraceId}] found SYS_OMM_CONTROL"); packet = await ReadPacketAsync(0x010c, 0x08, server, cancellationToken).ConfigureAwait(false); Console.WriteLine($"[{connection.TraceId}] SYS_OMM_CONTROL"); await OnServerMessageAsync(connection, packet, cancellationToken).ConfigureAwait(false); - } + } + server.AdvanceTo(next.Buffer.Start, next.Buffer.End); connection.InitOmmToRfpIv(sysAuthenticate.Slice(27, 8).Span); From fd5adcaf0f87241cdad992f4415bad2fc83e8df7 Mon Sep 17 00:00:00 2001 From: zivillian Date: Sun, 20 Apr 2025 00:02:04 +0200 Subject: [PATCH 18/22] bump version --- rpmbuild/SPECS/rfpproxy.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpmbuild/SPECS/rfpproxy.spec b/rpmbuild/SPECS/rfpproxy.spec index 40001ee..aa34dca 100644 --- a/rpmbuild/SPECS/rfpproxy.spec +++ b/rpmbuild/SPECS/rfpproxy.spec @@ -1,7 +1,7 @@ Summary: rfpproxy Name: rfpproxy Version: 0.0.2 -Release: 9 +Release: 10 License: MIT URL: https://github.com/eventphone/rfpproxy Requires: dotnet-runtime-8.0 From 1b2b454ae4a7a42bce73f366d98e39f4b4935a7d Mon Sep 17 00:00:00 2001 From: zivillian Date: Sun, 20 Apr 2025 00:08:51 +0200 Subject: [PATCH 19/22] advance to correct position --- RfpProxy/AbstractRfpProxy.cs | 4 ++-- rpmbuild/SPECS/rfpproxy.spec | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/RfpProxy/AbstractRfpProxy.cs b/RfpProxy/AbstractRfpProxy.cs index 8935541..869df95 100644 --- a/RfpProxy/AbstractRfpProxy.cs +++ b/RfpProxy/AbstractRfpProxy.cs @@ -107,14 +107,14 @@ protected override async Task ReadFromServerAsync(CryptedRfpConnection connectio //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.End); if (next.Buffer.Length > 2 && next.Buffer.FirstSpan[0] == 0x01 && next.Buffer.Slice(1).FirstSpan[0] == 0x0c) { Console.WriteLine($"[{connection.TraceId}] found SYS_OMM_CONTROL"); packet = await ReadPacketAsync(0x010c, 0x08, server, cancellationToken).ConfigureAwait(false); Console.WriteLine($"[{connection.TraceId}] SYS_OMM_CONTROL"); await OnServerMessageAsync(connection, packet, cancellationToken).ConfigureAwait(false); - } - server.AdvanceTo(next.Buffer.Start, next.Buffer.End); + } connection.InitOmmToRfpIv(sysAuthenticate.Slice(27, 8).Span); diff --git a/rpmbuild/SPECS/rfpproxy.spec b/rpmbuild/SPECS/rfpproxy.spec index aa34dca..0c85c29 100644 --- a/rpmbuild/SPECS/rfpproxy.spec +++ b/rpmbuild/SPECS/rfpproxy.spec @@ -1,7 +1,7 @@ Summary: rfpproxy Name: rfpproxy Version: 0.0.2 -Release: 10 +Release: 11 License: MIT URL: https://github.com/eventphone/rfpproxy Requires: dotnet-runtime-8.0 From f06ac69d65824d97f689df828d56a51375277d85 Mon Sep 17 00:00:00 2001 From: zivillian Date: Sun, 20 Apr 2025 00:21:26 +0200 Subject: [PATCH 20/22] read additional SYS_RESET --- RfpProxy/AbstractRfpProxy.cs | 6 +++++- rpmbuild/SPECS/rfpproxy.spec | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/RfpProxy/AbstractRfpProxy.cs b/RfpProxy/AbstractRfpProxy.cs index 869df95..e72114d 100644 --- a/RfpProxy/AbstractRfpProxy.cs +++ b/RfpProxy/AbstractRfpProxy.cs @@ -111,9 +111,13 @@ protected override async Task ReadFromServerAsync(CryptedRfpConnection connectio if (next.Buffer.Length > 2 && next.Buffer.FirstSpan[0] == 0x01 && next.Buffer.Slice(1).FirstSpan[0] == 0x0c) { Console.WriteLine($"[{connection.TraceId}] found SYS_OMM_CONTROL"); - packet = await ReadPacketAsync(0x010c, 0x08, server, cancellationToken).ConfigureAwait(false); + 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); diff --git a/rpmbuild/SPECS/rfpproxy.spec b/rpmbuild/SPECS/rfpproxy.spec index 0c85c29..a7a48c5 100644 --- a/rpmbuild/SPECS/rfpproxy.spec +++ b/rpmbuild/SPECS/rfpproxy.spec @@ -1,7 +1,7 @@ Summary: rfpproxy Name: rfpproxy Version: 0.0.2 -Release: 11 +Release: 12 License: MIT URL: https://github.com/eventphone/rfpproxy Requires: dotnet-runtime-8.0 From 8c075eef64c82a0b2b43302bb326210e3df150c1 Mon Sep 17 00:00:00 2001 From: zivillian Date: Sun, 20 Apr 2025 00:34:26 +0200 Subject: [PATCH 21/22] fix AdvanceTo --- RfpProxy/AbstractRfpProxy.cs | 4 ++-- rpmbuild/SPECS/rfpproxy.spec | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/RfpProxy/AbstractRfpProxy.cs b/RfpProxy/AbstractRfpProxy.cs index e72114d..73c91c7 100644 --- a/RfpProxy/AbstractRfpProxy.cs +++ b/RfpProxy/AbstractRfpProxy.cs @@ -107,14 +107,14 @@ protected override async Task ReadFromServerAsync(CryptedRfpConnection connectio //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.End); + 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) { Console.WriteLine($"[{connection.TraceId}] found SYS_OMM_CONTROL"); 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); diff --git a/rpmbuild/SPECS/rfpproxy.spec b/rpmbuild/SPECS/rfpproxy.spec index a7a48c5..68a29a0 100644 --- a/rpmbuild/SPECS/rfpproxy.spec +++ b/rpmbuild/SPECS/rfpproxy.spec @@ -1,7 +1,7 @@ Summary: rfpproxy Name: rfpproxy Version: 0.0.2 -Release: 12 +Release: 13 License: MIT URL: https://github.com/eventphone/rfpproxy Requires: dotnet-runtime-8.0 From dd60e97660f765c902160dce903ad1f29499103a Mon Sep 17 00:00:00 2001 From: zivillian Date: Sun, 20 Apr 2025 14:34:32 +0200 Subject: [PATCH 22/22] cleanup --- RfpProxy/AbstractRfpProxy.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/RfpProxy/AbstractRfpProxy.cs b/RfpProxy/AbstractRfpProxy.cs index 73c91c7..5417a5d 100644 --- a/RfpProxy/AbstractRfpProxy.cs +++ b/RfpProxy/AbstractRfpProxy.cs @@ -110,7 +110,6 @@ protected override async Task ReadFromServerAsync(CryptedRfpConnection connectio 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) { - Console.WriteLine($"[{connection.TraceId}] found SYS_OMM_CONTROL"); packet = await ReadPacketAsync(0x010c, 0, server, cancellationToken).ConfigureAwait(false); Console.WriteLine($"[{connection.TraceId}] SYS_OMM_CONTROL"); await OnServerMessageAsync(connection, packet, cancellationToken).ConfigureAwait(false);