update fnecore submodule; move cryptoparams into fnecore proper; remove CreateNewP25MessageHdr;

pull/1/head
Bryan Biedenkapp 11 months ago
parent a706e15f50
commit f79d349b0f

@ -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
{
/// <summary>
///
/// </summary>
public class CryptoParams
{
/*
** Properties
*/
/// <summary>
/// Message Indicator
/// </summary>
public byte[] MI { get; set; } = new byte[P25Defines.P25_MI_LENGTH];
/// <summary>
/// Algorithm ID.
/// </summary>
public byte AlgId { get; set; } = P25Defines.P25_ALGO_UNENCRYPT;
/// <summary>
/// Key ID.
/// </summary>
public ushort KeyId { get; set; }
} // public class CryptoParams
/// <summary>
/// Implements a FNE system base.
/// </summary>
@ -80,30 +57,6 @@ namespace dvmconsole
return;
}
/// <summary>
///
/// </summary>
/// <param name="duid"></param>
/// <param name="callData"></param>
/// <param name="data"></param>
/// <param name="algId"></param>
/// <param name="kId"></param>
/// <param name="mi"></param>
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
}
}
/// <summary>
/// Helper to send a P25 TDU message.
/// </summary>
@ -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
}

@ -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]);

@ -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<byte, byte>(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<byte, byte>(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];

@ -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,

@ -1 +1 @@
Subproject commit 741953ca206ed961af0b0a1cf8e3f7a8d9d169bc
Subproject commit 13a82b3a82054e4fe8299368c7258c51176cee87
Loading…
Cancel
Save

Powered by TurnKey Linux.