Skip to content

Commit

Permalink
Regenerate the header structures and fix the data header.
Browse files Browse the repository at this point in the history
  • Loading branch information
g4klx committed Feb 22, 2016
1 parent ac82c4f commit 0881df6
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 91 deletions.
79 changes: 46 additions & 33 deletions DMRCSBK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,75 +24,88 @@
#include <cstdio>
#include <cassert>

CDMRCSBK::CDMRCSBK(const unsigned char* bytes) :
CDMRCSBK::CDMRCSBK() :
m_data(NULL),
m_CSBKO(CSBKO_NONE),
m_FID(0x00U),
m_bsId(0U),
m_srcId(0U),
m_dstId(0U),
m_valid(false)
m_dstId(0U)
{
m_data = new unsigned char[12U];
}

CDMRCSBK::~CDMRCSBK()
{
delete[] m_data;
}

bool CDMRCSBK::put(const unsigned char* bytes)
{
assert(bytes != NULL);

CBPTC19696 bptc;
bptc.decode(bytes, m_data);

unsigned char data[12U];
bptc.decode(bytes, data);
m_data[10U] ^= CSBK_CRC_MASK[0U];
m_data[11U] ^= CSBK_CRC_MASK[1U];

data[10U] ^= CSBK_CRC_MASK[0U];
data[11U] ^= CSBK_CRC_MASK[1U];
bool valid = CCRC::checkCCITT162(m_data, 12U);
if (!valid)
return false;

m_valid = CCRC::checkCCITT162(data, 12U);
if (!m_valid)
return;
// Restore the checksum
m_data[10U] ^= CSBK_CRC_MASK[0U];
m_data[11U] ^= CSBK_CRC_MASK[1U];

m_CSBKO = CSBKO(data[0U] & 0x3FU);
m_FID = data[1U];
m_CSBKO = CSBKO(m_data[0U] & 0x3FU);
m_FID = m_data[1U];

switch (m_CSBKO) {
case CSBKO_BSDWNACT:
m_bsId = data[4U] << 16 | data[5U] << 8 | data[6U];
m_srcId = data[7U] << 16 | data[8U] << 8 | data[9U];
CUtils::dump("Download Activate CSBK", data, 12U);
m_bsId = m_data[4U] << 16 | m_data[5U] << 8 | m_data[6U];
m_srcId = m_data[7U] << 16 | m_data[8U] << 8 | m_data[9U];
CUtils::dump("Download Activate CSBK", m_data, 12U);
break;

case CSBKO_UUVREQ:
m_dstId = data[4U] << 16 | data[5U] << 8 | data[6U];
m_srcId = data[7U] << 16 | data[8U] << 8 | data[9U];
CUtils::dump("Unit to Unit Service Request CSBK", data, 12U);
m_dstId = m_data[4U] << 16 | m_data[5U] << 8 | m_data[6U];
m_srcId = m_data[7U] << 16 | m_data[8U] << 8 | m_data[9U];
CUtils::dump("Unit to Unit Service Request CSBK", m_data, 12U);
break;

case CSBKO_UUANSRSP:
m_dstId = data[4U] << 16 | data[5U] << 8 | data[6U];
m_srcId = data[7U] << 16 | data[8U] << 8 | data[9U];
CUtils::dump("Unit to Unit Service Answer Response CSBK", data, 12U);
m_dstId = m_data[4U] << 16 | m_data[5U] << 8 | m_data[6U];
m_srcId = m_data[7U] << 16 | m_data[8U] << 8 | m_data[9U];
CUtils::dump("Unit to Unit Service Answer Response CSBK", m_data, 12U);
break;

case CSBKO_PRECCSBK:
m_dstId = data[4U] << 16 | data[5U] << 8 | data[6U];
m_srcId = data[7U] << 16 | data[8U] << 8 | data[9U];
CUtils::dump("Preamble CSBK", data, 12U);
m_dstId = m_data[4U] << 16 | m_data[5U] << 8 | m_data[6U];
m_srcId = m_data[7U] << 16 | m_data[8U] << 8 | m_data[9U];
CUtils::dump("Preamble CSBK", m_data, 12U);
break;

case CSBKO_NACKRSP:
m_srcId = data[4U] << 16 | data[5U] << 8 | data[6U];
m_dstId = data[7U] << 16 | data[8U] << 8 | data[9U];
CUtils::dump("Negative Acknowledge Response CSBK", data, 12U);
m_srcId = m_data[4U] << 16 | m_data[5U] << 8 | m_data[6U];
m_dstId = m_data[7U] << 16 | m_data[8U] << 8 | m_data[9U];
CUtils::dump("Negative Acknowledge Response CSBK", m_data, 12U);
break;

default:
CUtils::dump("Unhandled CSBK type", data, 12U);
CUtils::dump("Unhandled CSBK type", m_data, 12U);
break;
}
}

CDMRCSBK::~CDMRCSBK()
{
return true;
}

bool CDMRCSBK::isValid() const
void CDMRCSBK::get(unsigned char* bytes) const
{
return m_valid;
assert(bytes != NULL);

CBPTC19696 bptc;
bptc.encode(m_data, bytes);
}

CSBKO CDMRCSBK::getCSBKO() const
Expand Down
18 changes: 10 additions & 8 deletions DMRCSBK.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ enum CSBKO {
class CDMRCSBK
{
public:
CDMRCSBK(const unsigned char* bytes);
CDMRCSBK();
~CDMRCSBK();

bool isValid() const;
bool put(const unsigned char* bytes);

void get(unsigned char* bytes) const;

// Generic fields
CSBKO getCSBKO() const;
Expand All @@ -50,12 +52,12 @@ class CDMRCSBK
unsigned int getDstId() const;

private:
CSBKO m_CSBKO;
unsigned char m_FID;
unsigned int m_bsId;
unsigned int m_srcId;
unsigned int m_dstId;
bool m_valid;
unsigned char* m_data;
CSBKO m_CSBKO;
unsigned char m_FID;
unsigned int m_bsId;
unsigned int m_srcId;
unsigned int m_dstId;
};

#endif
6 changes: 3 additions & 3 deletions DMRControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ bool CDMRControl::processWakeup(const unsigned char* data)
if (data[0U] != TAG_DATA || data[1U] != (DMR_IDLE_RX | DMR_SYNC_DATA | DT_CSBK))
return false;

CDMRCSBK csbk(data + 2U);

if (!csbk.isValid())
CDMRCSBK csbk;
bool valid = csbk.put(data + 2U);
if (!valid)
return false;

CSBKO csbko = csbk.getCSBKO();
Expand Down
56 changes: 38 additions & 18 deletions DMRDataHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,65 @@

#include "DMRDataHeader.h"
#include "DMRDefines.h"
#include "BPTC19696.h"
#include "Utils.h"
#include "CRC.h"
#include "Log.h"

#include <cstdio>
#include <cassert>

CDMRDataHeader::CDMRDataHeader(const unsigned char* data) :
m_bptc(),
m_valid(false),
CDMRDataHeader::CDMRDataHeader() :
m_data(NULL),
m_gi(false),
m_srcId(0U),
m_dstId(0U),
m_blocks(0U)
{
assert(data != NULL);
m_data = new unsigned char[12U];
}

unsigned char header[12U];
m_bptc.decode(data, header);
CDMRDataHeader::~CDMRDataHeader()
{
delete[] m_data;
}

header[10U] ^= DATA_HEADER_CRC_MASK[0U];
header[11U] ^= DATA_HEADER_CRC_MASK[1U];
bool CDMRDataHeader::put(const unsigned char* bytes)
{
assert(bytes != NULL);

m_valid = CCRC::checkCCITT162(header, 12U);
CBPTC19696 bptc;
bptc.decode(bytes, m_data);

m_gi = (header[0U] & 0x80U) == 0x80U;
m_data[10U] ^= DATA_HEADER_CRC_MASK[0U];
m_data[11U] ^= DATA_HEADER_CRC_MASK[1U];

m_dstId = data[2U] << 16 | data[3U] << 8 | data[4U];
m_srcId = data[5U] << 16 | data[6U] << 8 | data[7U];
bool valid = CCRC::checkCCITT162(m_data, 12U);
if (!valid)
return false;

m_blocks = data[8U] & 0x7FU;
}
// Restore the checksum
m_data[10U] ^= DATA_HEADER_CRC_MASK[0U];
m_data[11U] ^= DATA_HEADER_CRC_MASK[1U];

CDMRDataHeader::~CDMRDataHeader()
{
m_gi = (m_data[0U] & 0x80U) == 0x80U;

m_dstId = m_data[2U] << 16 | m_data[3U] << 8 | m_data[4U];
m_srcId = m_data[5U] << 16 | m_data[6U] << 8 | m_data[7U];

m_blocks = m_data[8U] & 0x7FU;

CUtils::dump("Data Header", m_data, 12U);

return true;
}

bool CDMRDataHeader::isValid() const
void CDMRDataHeader::get(unsigned char* bytes) const
{
return m_valid;
assert(bytes != NULL);

CBPTC19696 bptc;
bptc.encode(m_data, bytes);
}

bool CDMRDataHeader::getGI() const
Expand Down
19 changes: 9 additions & 10 deletions DMRDataHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
#ifndef DMRDataHeader_H
#define DMRDataHeader_H

#include "BPTC19696.h"

class CDMRDataHeader
{
public:
CDMRDataHeader(const unsigned char* data);
CDMRDataHeader();
~CDMRDataHeader();

bool isValid() const;
bool put(const unsigned char* bytes);

void get(unsigned char* bytes) const;

bool getGI() const;

Expand All @@ -37,12 +37,11 @@ class CDMRDataHeader
unsigned int getBlocks() const;

private:
CBPTC19696 m_bptc;
bool m_valid;
bool m_gi;
unsigned int m_srcId;
unsigned int m_dstId;
unsigned int m_blocks;
unsigned char* m_data;
bool m_gi;
unsigned int m_srcId;
unsigned int m_dstId;
unsigned int m_blocks;
};

#endif
Expand Down
Loading

0 comments on commit 0881df6

Please sign in to comment.