diff --git a/dvmconsole/FneSystemBase.P25.cs b/dvmconsole/FneSystemBase.P25.cs index e0d0c45..e757377 100644 --- a/dvmconsole/FneSystemBase.P25.cs +++ b/dvmconsole/FneSystemBase.P25.cs @@ -7,7 +7,7 @@ * @package DVM / Audio Bridge * @license AGPLv3 License (https://opensource.org/licenses/AGPL-3.0) * -* Copyright (C) 2022-2024 Bryan Biedenkapp, N2PLL +* Copyright (C) 2022-2025 Bryan Biedenkapp, N2PLL * Copyright (C) 2025 Caleb, K4PHP * */ @@ -19,29 +19,6 @@ using fnecore.P25.LC.TSBK; namespace dvmconsole { - /// - /// - /// - public class CryptoParams - { - /* - ** Properties - */ - - /// - /// Message Indicator - /// - public byte[] MI { get; set; } = new byte[P25Defines.P25_MI_LENGTH]; - /// - /// Algorithm ID. - /// - public byte AlgId { get; set; } = P25Defines.P25_ALGO_UNENCRYPT; - /// - /// Key ID. - /// - public ushort KeyId { get; set; } - } // public class CryptoParams - /// /// Implements a FNE system base. /// @@ -80,30 +57,6 @@ namespace dvmconsole return; } - /// - /// - /// - /// - /// - /// - /// - /// - /// - public void CreateNewP25MessageHdr(byte duid, RemoteCallData callData, ref byte[] data, byte algId = 0, ushort kId = 0, byte[] mi = null) - { - CreateP25MessageHdr(duid, callData, ref data); - - // if an MI is present, this is an encrypted header - if (mi != null) - { - data[14U] |= 0x08; // Control bit - - data[181U] = algId; // Algorithm ID - FneUtils.WriteBytes(kId, ref data, 182); // Key ID - Array.Copy(mi, 0, data, 184, P25Defines.P25_MI_LENGTH); // Message Indicator - } - } - /// /// Helper to send a P25 TDU message. /// @@ -387,7 +340,7 @@ namespace dvmconsole break; case P25DFSI.P25_DFSI_LDU2_VOICE15: { - dfsiFrame[1U] = cryptoParams.AlgId; // Algorithm ID + dfsiFrame[1U] = cryptoParams.AlgoId; // Algorithm ID FneUtils.WriteBytes(cryptoParams.KeyId, ref dfsiFrame, 2); // Key ID Buffer.BlockCopy(imbe, 0, dfsiFrame, 5, IMBE_BUF_LEN); // IMBE } diff --git a/dvmconsole/MainWindow.DMR.cs b/dvmconsole/MainWindow.DMR.cs index dd1d877..c839f5d 100644 --- a/dvmconsole/MainWindow.DMR.cs +++ b/dvmconsole/MainWindow.DMR.cs @@ -124,7 +124,7 @@ namespace dvmconsole } int smpIdx = 0; - short[] samples = new short[MBE_SAMPLES_LENGTH]; + short[] samples = new short[FneSystemBase.MBE_SAMPLES_LENGTH]; for (int pcmIdx = 0; pcmIdx < pcm.Length; pcmIdx += 2) { samples[smpIdx] = (short)((pcm[pcmIdx + 1] << 8) + pcm[pcmIdx + 0]); diff --git a/dvmconsole/MainWindow.P25.cs b/dvmconsole/MainWindow.P25.cs index b2dc1b1..80af30f 100644 --- a/dvmconsole/MainWindow.P25.cs +++ b/dvmconsole/MainWindow.P25.cs @@ -239,6 +239,14 @@ namespace dvmconsole if (channel.TxStreamId == 0) Log.WriteWarning($"({channel.SystemName}) P25D: Traffic *VOICE FRAME * Stream ID not set for traffic? Shouldn't happen."); + CryptoParams cryptoParams = new CryptoParams(); + if (cpgChannel.GetAlgoId() != P25Defines.P25_ALGO_UNENCRYPT && cpgChannel.GetKeyId() > 0) + { + cryptoParams.AlgoId = cpgChannel.GetAlgoId(); + cryptoParams.KeyId = cpgChannel.GetKeyId(); + Array.Copy(channel.mi, cryptoParams.MI, P25Defines.P25_MI_LENGTH); + } + // send P25 LDU1 if (channel.p25N == 8U) { @@ -257,7 +265,7 @@ namespace dvmconsole Log.WriteLine($"({channel.SystemName}) P25D: Traffic *VOICE FRAME LDU1* PEER {fne.PeerId} SRC_ID {srcId} TGID {dstId} [STREAM ID {channel.TxStreamId} SEQ {channel.p25SeqNo}]"); byte[] payload = new byte[200]; - fne.CreateNewP25MessageHdr((byte)P25DUID.LDU1, callData, ref payload, cpgChannel.GetAlgoId(), cpgChannel.GetKeyId(), channel.mi); + fne.CreateP25MessageHdr((byte)P25DUID.LDU1, callData, ref payload, cryptoParams); fne.CreateP25LDU1Message(channel.netLDU1, ref payload, srcId, dstId); peer.SendMaster(new Tuple(Constants.NET_FUNC_PROTOCOL, Constants.NET_PROTOCOL_SUBFUNC_P25), payload, channel.pktSeq, channel.TxStreamId); @@ -281,8 +289,10 @@ namespace dvmconsole Log.WriteLine($"({channel.SystemName}) P25D: Traffic *VOICE FRAME LDU2* PEER {fne.PeerId} SRC_ID {srcId} TGID {dstId} [STREAM ID {channel.TxStreamId} SEQ {channel.p25SeqNo}]"); byte[] payload = new byte[200]; - fne.CreateNewP25MessageHdr((byte)P25DUID.LDU2, callData, ref payload, cpgChannel.GetAlgoId(), cpgChannel.GetKeyId(), channel.mi); - fne.CreateP25LDU2Message(channel.netLDU2, ref payload, new CryptoParams { AlgId = cpgChannel.GetAlgoId(), KeyId = cpgChannel.GetKeyId(), MI = channel.mi }); + + + fne.CreateP25MessageHdr((byte)P25DUID.LDU2, callData, ref payload, cryptoParams); + fne.CreateP25LDU2Message(channel.netLDU2, ref payload, new CryptoParams { AlgoId = cpgChannel.GetAlgoId(), KeyId = cpgChannel.GetKeyId(), MI = channel.mi }); peer.SendMaster(new Tuple(Constants.NET_FUNC_PROTOCOL, Constants.NET_PROTOCOL_SUBFUNC_P25), payload, channel.pktSeq, channel.TxStreamId); } @@ -522,7 +532,11 @@ namespace dvmconsole } if ((channel.algId != cpgChannel.GetAlgoId() || channel.kId != cpgChannel.GetKeyId()) && channel.algId != P25Defines.P25_ALGO_UNENCRYPT) + { + channel.Background = ChannelBox.RED_GRADIENT; + Log.WriteLine($"({system.Name}) P25D: Traffic *CALL DROPPED * PEER {e.PeerId} SRC_ID {e.SrcId} TGID {e.DstId} [STREAM ID {e.StreamId}]"); continue; + } byte[] newMI = new byte[P25Defines.P25_MI_LENGTH]; diff --git a/dvmconsole/MainWindow.xaml.cs b/dvmconsole/MainWindow.xaml.cs index 27abfce..7ef4e16 100644 --- a/dvmconsole/MainWindow.xaml.cs +++ b/dvmconsole/MainWindow.xaml.cs @@ -66,7 +66,7 @@ namespace dvmconsole { public const double MIN_WIDTH = 875; public const double MIN_HEIGHT = 700; - public const int MBE_SAMPLES_LENGTH = 160; + public const int PCM_SAMPLES_LENGTH = 320; // MBE_SAMPLES_LENGTH * 2 public const int MAX_SYSTEM_NAME_LEN = 10; @@ -612,6 +612,7 @@ namespace dvmconsole KeysetItems[keyEntry.AlgId].AddKey(keyItem); } + foreach (var eventData in KeysetItems.Select(keyValuePair => keyValuePair.Value).Select(keysetItem => new KeyResponseEvent(0, new KmmModifyKey { AlgId = 0, diff --git a/fnecore b/fnecore index 741953c..13a82b3 160000 --- a/fnecore +++ b/fnecore @@ -1 +1 @@ -Subproject commit 741953ca206ed961af0b0a1cf8e3f7a8d9d169bc +Subproject commit 13a82b3a82054e4fe8299368c7258c51176cee87