Skip to content

Commit

Permalink
#1618 WIP extracting iv value from voice super frame.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Sheirer committed Aug 6, 2023
1 parent 2510e83 commit 84a93ce
Show file tree
Hide file tree
Showing 32 changed files with 848 additions and 222 deletions.
28 changes: 15 additions & 13 deletions src/main/java/io/github/dsheirer/edac/CRCUtil.java
@@ -1,6 +1,6 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2022 Dennis Sheirer
* Copyright (C) 2014-2023 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -226,17 +226,19 @@ public static void main(String[] args)
{
mLog.debug("Starting");

//DMR message
// String raw = "100110010001000000001001000000001111011011010000011001010000000000000000000000001100001000001011";
String raw = "101010000000000000110110100000101101011011010000011001111100000000000011100101001001111010001110";
mLog.debug(raw);
raw = "101010000000000000110110100000101101011011010000011001111100000000000011100101000000000000000000";
BinaryMessage message = BinaryMessage.load(raw);
mLog.debug(message.toString());

long polynomial = 0x11021l;
decode(message, 0, 80, polynomial, 16);
mLog.debug(message.toString());
mLog.debug("Finished");
long poly = 0x13l;
long[] checksums = generate(32, 4, poly, 0, true);

StringBuilder sb = new StringBuilder();
sb.append("private static int[] CHECKSUMS = new int[]{");
for(long checksum: checksums)
{
sb.append("0x").append(Long.toHexString(checksum).toUpperCase());
sb.append(",");
}

sb.append("};");

System.out.println("Checksums:\n" + sb);
}
}
53 changes: 32 additions & 21 deletions src/main/java/io/github/dsheirer/edac/Golay24.java
@@ -1,31 +1,29 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2023 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
* ****************************************************************************
*/

package io.github.dsheirer.edac;

import io.github.dsheirer.bits.BinaryMessage;
import io.github.dsheirer.bits.CorrectedBinaryMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*******************************************************************************
* SDR Trunk
* Copyright (C) 2014 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
* -----------------------------------------------------------------------
* Galois24 decoder based on Hank Wallace's tutorial/algorithm located at:
* http://www.aqdi.com/golay.htm
******************************************************************************/

/**
* Galois 24/12/7 decoder
*/
Expand Down Expand Up @@ -160,4 +158,17 @@ private static int getSyndrome(BinaryMessage message, int startIndex)

return (checksum ^ calculated);
}

public static void main(String[] args)
{
// CorrectedBinaryMessage bm = new CorrectedBinaryMessage(BinaryMessage.loadHex("F3BB20"));
// CorrectedBinaryMessage bm = new CorrectedBinaryMessage(BinaryMessage.loadHex("F0C5C0"));
CorrectedBinaryMessage bm = new CorrectedBinaryMessage(BinaryMessage.loadHex("AFAC00"));

System.out.println("M:" + bm.toHexString());
int a = Golay24.checkAndCorrect(bm, 0);
System.out.println("M:" + bm.toHexString());

System.out.println("A:" + a);
}
}
Expand Up @@ -34,6 +34,7 @@
import io.github.dsheirer.module.decode.dmr.message.data.header.PacketSequenceHeader;
import io.github.dsheirer.module.decode.dmr.message.data.header.ProprietaryDataHeader;
import io.github.dsheirer.module.decode.dmr.message.data.header.UDTHeader;
import io.github.dsheirer.module.decode.dmr.message.data.header.VoiceHeader;
import io.github.dsheirer.module.decode.dmr.message.data.lc.full.FLCAssembler;
import io.github.dsheirer.module.decode.dmr.message.data.lc.full.FullLCMessage;
import io.github.dsheirer.module.decode.dmr.message.data.lc.full.TalkerAliasAssembler;
Expand All @@ -43,7 +44,9 @@
import io.github.dsheirer.module.decode.dmr.message.data.mbc.MBCContinuationBlock;
import io.github.dsheirer.module.decode.dmr.message.data.packet.PacketSequenceAssembler;
import io.github.dsheirer.module.decode.dmr.message.data.terminator.Terminator;
import io.github.dsheirer.module.decode.dmr.message.voice.CallEncryptionParametersCollector;
import io.github.dsheirer.module.decode.dmr.message.voice.VoiceEMBMessage;
import io.github.dsheirer.module.decode.dmr.message.voice.VoiceMessage;
import io.github.dsheirer.sample.Listener;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -59,6 +62,8 @@ public class DMRMessageProcessor implements Listener<IMessage>
{
private final static Logger mLog = LoggerFactory.getLogger(DMRMessageProcessor.class);
private DecodeConfigDMR mConfigDMR;
private CallEncryptionParametersCollector mEncryptionCollector1 = new CallEncryptionParametersCollector();
private CallEncryptionParametersCollector mEncryptionCollector2 = new CallEncryptionParametersCollector();
private FLCAssembler mFLCAssemblerTimeslot1 = new FLCAssembler(1);
private FLCAssembler mFLCAssemblerTimeslot2 = new FLCAssembler(2);
private MBCAssembler mMBCAssembler = new MBCAssembler();
Expand Down Expand Up @@ -89,11 +94,47 @@ public DMRMessageProcessor(DecodeConfigDMR config)
@Override
public void receive(IMessage message)
{
//Process voice header and voice frame messages to extract encryption parameters when call is encrypted,
//otherwise reset the encryption collectors when the message is valid but not a voice header or
if(message instanceof VoiceHeader voiceHeader)
{
if(voiceHeader.getTimeslot() == 1)
{
mEncryptionCollector1.process(voiceHeader);
}
else
{
mEncryptionCollector2.process(voiceHeader);
}
}
else if(message instanceof VoiceMessage voiceMessage)
{
if(voiceMessage.getTimeslot() == 1)
{
mEncryptionCollector1.process(voiceMessage);
}
else
{
mEncryptionCollector2.process(voiceMessage);
}
}
else if(message instanceof DMRBurst dmrBurst && dmrBurst.isValid())
{
if(dmrBurst.getTimeslot() == 1)
{
// mEncryptionCollector1.reset();
}
else
{
// mEncryptionCollector2.reset();
}
}

//Enrich messages that carry DMR Logical Slot Number channels with LCN to frequency mappings
if(message instanceof ITimeslotFrequencyReceiver)
{
ITimeslotFrequencyReceiver receiver = (ITimeslotFrequencyReceiver)message;
int[] lsns = receiver.getLogicalTimeslotNumbers();
int[] lsns = receiver.getLogicalSlotNumbers();

List<TimeslotFrequency> timeslotFrequencies = new ArrayList<>();

Expand Down
@@ -1,23 +1,20 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2023 Dennis Sheirer
*
* * ******************************************************************************
* * Copyright (C) 2014-2019 Dennis Sheirer
* *
* * This program is free software: you can redistribute it and/or modify
* * it under the terms of the GNU General Public License as published by
* * the Free Software Foundation, either version 3 of the License, or
* * (at your option) any later version.
* *
* * This program is distributed in the hope that it will be useful,
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* * GNU General Public License for more details.
* *
* * You should have received a copy of the GNU General Public License
* * along with this program. If not, see <http://www.gnu.org/licenses/>
* * *****************************************************************************
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
* ****************************************************************************
*/

package io.github.dsheirer.module.decode.dmr.channel;
Expand All @@ -39,7 +36,7 @@ public class DMRAbsoluteChannel extends DMRChannel
*/
public DMRAbsoluteChannel(int lcn, int timeslot, long downlinkFrequency, long uplinkFrequency)
{
super(lcn * 2 + timeslot);
super(lcn, timeslot);
mDownlinkFrequency = downlinkFrequency;
mUplinkFrequency = uplinkFrequency;
}
Expand Down
@@ -1,6 +1,6 @@
/*
* *****************************************************************************
* Copyright (C) 2014-2020 Dennis Sheirer
* Copyright (C) 2014-2023 Dennis Sheirer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -26,21 +26,27 @@
import io.github.dsheirer.identifier.integer.IntegerIdentifier;
import io.github.dsheirer.module.decode.p25.phase1.message.IFrequencyBand;
import io.github.dsheirer.protocol.Protocol;
import org.apache.commons.lang3.Validate;

/**
* Base DMR Channel
*
* Note: timeslots are tracked as 1 and 2
*/
public abstract class DMRChannel extends IntegerIdentifier implements IChannelDescriptor
{
private int mTimeslot;

/**
* Constructs an instance
*
* @param lsn number that is a combination of the repeater number and timeslot where the channel number or repeater
* number is left shifted by two and the timeslot is added as either a zero or one value.
* @param channel number or repeater number, one-based repeater number.
* @param timeslot in range: 1 or 2
*/
public DMRChannel(int lsn)
public DMRChannel(int channel, int timeslot)
{
super(lsn, IdentifierClass.NETWORK, Form.CHANNEL, Role.BROADCAST);
super(channel, IdentifierClass.NETWORK, Form.CHANNEL, Role.BROADCAST);
Validate.inclusiveBetween(0, 2, timeslot, "Timeslot must be between 1 and 2");
mTimeslot = timeslot;
}

@Override
Expand All @@ -50,24 +56,20 @@ public Protocol getProtocol()
}

/**
* Timeslot for the channel. Note: timeslot values are normally zero or one, but for this application we use
* timeslot values of 1 and 2 so that we can reserve timeslot 0 as the slow link control (SLC) channel.
*
* @return timeslot as 1-based index with values in range: 1-2.
* Repeater number or channel number for the channel.
*/
public int getTimeslot()
public int getChannel()
{
return getValue() % 2 + 1;
return getValue();
}

/**
* Returns an array of length 1 containing this channel's logical slot number
* Timeslot for the channel.
* @return timeslot as zero-based index with values in range: 0 or 1.
*/
public int[] getLSNArray()
public int getTimeslot()
{
int[] logicalSlotNumbers = new int[1];
logicalSlotNumbers[0] = getValue();
return logicalSlotNumbers;
return mTimeslot;
}

/**
Expand All @@ -89,6 +91,13 @@ public boolean isTDMAChannel()
return true;
}


@Override
public String toString()
{
return "CHAN:" + getChannel() + ":" + getTimeslot();
}

/**
* Not implemented
*/
Expand Down

0 comments on commit 84a93ce

Please sign in to comment.