// SPDX-License-Identifier: AGPL-3.0-only
/**
* Digital Voice Modem - Fixed Network Equipment Core Library
* AGPLv3 Open Source. Use is subject to license terms.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* @package DVM / Fixed Network Equipment Core Library
* @license AGPLv3 License (https://opensource.org/licenses/AGPL-3.0)
*
* Copyright (C) 2022 Bryan Biedenkapp, N2PLL
*
*/
using System;
namespace fnecore.DMR
{
///
/// Represents DMR privacy indicator link control data.
///
public class PrivacyLC
{
private byte[] mi;
///
/// Feature ID.
///
public byte FID;
///
/// Destination ID.
///
public uint DstId;
/** Service Options */
///
/// Flag indicating a group/talkgroup operation.
///
public bool Group;
/** Encryption Data */
///
/// Encryption algorithm ID.
///
public byte AlgId;
///
/// Encryption key ID.
///
public uint KId;
/*
** Methods
*/
///
/// Initializes a new instance of the class.
///
public PrivacyLC()
{
mi = new byte[4];
FID = 0;
DstId = 0;
Group = false;
AlgId = 0;
KId = 0;
}
///
/// Initializes a new instance of the class.
///
///
public PrivacyLC(byte[] bytes)
{
mi = new byte[4];
Group = (bytes[0U] & 0x20U) == 0x20U;
AlgId = (byte)(bytes[0U] & 7); // Algorithm ID
FID = bytes[1U];
KId = bytes[2U];
mi[0U] = bytes[3U];
mi[1U] = bytes[4U];
mi[2U] = bytes[5U];
mi[3U] = bytes[6U];
DstId = (uint)(bytes[7U] << 16 | bytes[8U] << 8 | bytes[9U]); // Destination Address
}
///
/// Gets LC data as bytes.
///
///
public byte[] GetBytes()
{
byte[] lcData = new byte[12];
GetData(ref lcData);
return lcData;
}
///
/// Gets LC data as bytes.
///
///
public void GetData(ref byte[] bytes)
{
if (bytes == null)
throw new NullReferenceException("bytes");
bytes[0U] = (byte)((Group ? 0x20U : 0x00U) +
(AlgId & 0x07U)); // Algorithm ID
bytes[1U] = FID;
bytes[2U] = (byte)KId;
bytes[3U] = mi[0U];
bytes[4U] = mi[1U];
bytes[5U] = mi[2U];
bytes[6U] = mi[3U];
bytes[7U] = (byte)(DstId >> 16); // Destination Address
bytes[8U] = (byte)(DstId >> 8); // ..
bytes[9U] = (byte)(DstId >> 0); // ..
}
} // public class PrivacyLC
} // namespace fnecore.DMR