Compare commits

..

4 Commits

Author SHA1 Message Date
lwvmobile 8cfaced4b4 P25 Moto Talker Alias LCW WIP; 2025-02-05 09:52:30 -05:00
lwvmobile 61673222db Merge branch 'p25_moto_alias_setup' into aw_dev 2025-02-05 07:13:18 -05:00
lwvmobile f59f0cbb7f P25 Moto Talker Alias LCW Setup and Test; 2025-02-05 07:12:41 -05:00
lwvmobile 20af28597d Fix Variable Print Format; 2025-02-04 17:26:00 -05:00
5 changed files with 250 additions and 6 deletions

View File

@ -1256,6 +1256,9 @@ void dmr_gateway_identifier (uint32_t source, uint32_t target); //translate spec
//Embedded Alias and GPS reports
void dmr_embedded_alias_header (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[]);
void dmr_embedded_alias_blocks (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[]);
void apx_embedded_alias_test (dsd_opts * opts, dsd_state * state);
void apx_embedded_alias_header (dsd_opts * opts, dsd_state * state, uint8_t slot, uint8_t lc_bits[]);
void apx_embedded_alias_blocks (dsd_opts * opts, dsd_state * state, uint8_t slot, uint8_t lc_bits[]);
void dmr_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[]);
void apx_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[]);
void lip_protocol_decoder (dsd_opts * opts, dsd_state * state, uint8_t * input);

View File

@ -763,4 +763,234 @@ void apx_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[])
}
fprintf (stderr, "%s", KNRM);
}
//relocate all below later on
uint8_t alias_lut[256] = {
0xD2, 0xF6, 0xD4, 0x2B, 0x63, 0x49, 0x94, 0x5E, 0xA7, 0x5C, 0x70, 0x69, 0xF7, 0x08, 0xB1, 0x7D,
0x38, 0xCF, 0xCC, 0xD8, 0x51, 0x8F, 0xD5, 0x93, 0x6A, 0xF3, 0xEF, 0x7E, 0xFB, 0x64, 0xF4, 0x35,
0x27, 0x07, 0x31, 0x14, 0x87, 0x98, 0x76, 0x34, 0xCA, 0x92, 0x33,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5D, 0xDE, 0xE0, 0x1D, 0x19, 0x4B, 0xC6, 0x0C, 0x3F, 0x5A, 0xC7, 0xE1, 0x59, 0x55, 0x54,
0x4A, 0x43, 0x42, 0xE2, 0xE3, 0xFA, 0x00, 0xE4, 0xE5, 0x18, 0x41, 0x0B, 0x0A, 0xE6, 0xFC, 0xFD
};
void apx_embedded_alias_test (dsd_opts * opts, dsd_state * state)
{
uint64_t temp_a = 0x15900FE9060100B0; uint64_t temp_b = 0x5A; //72 bits, so break into segments
uint8_t lcw[72]; memset (lcw, 0, sizeof(lcw));
for (uint64_t i = 0; i < 64; i++)
lcw[i] = (temp_a >> (63-i)) & 1;
for (uint64_t i = 0; i < 8; i++)
lcw[i+64] = (temp_b >> (7-i)) & 1;
p25_lcw(opts, state, lcw, 0);
temp_a = 0x179001BBEE001C70; temp_b = 0x13;
memset (lcw, 0, sizeof(lcw));
for (uint64_t i = 0; i < 64; i++)
lcw[i] = (temp_a >> (63-i)) & 1;
for (uint64_t i = 0; i < 8; i++)
lcw[i+64] = (temp_b >> (7-i)) & 1;
p25_lcw(opts, state, lcw, 0);
temp_a = 0x179002B9CB7D5F2D; temp_b = 0x48;
memset (lcw, 0, sizeof(lcw));
for (uint64_t i = 0; i < 64; i++)
lcw[i] = (temp_a >> (63-i)) & 1;
for (uint64_t i = 0; i < 8; i++)
lcw[i+64] = (temp_b >> (7-i)) & 1;
p25_lcw(opts, state, lcw, 0);
temp_a = 0x179003B23695F7ED; temp_b = 0x49;
memset (lcw, 0, sizeof(lcw));
for (uint64_t i = 0; i < 64; i++)
lcw[i] = (temp_a >> (63-i)) & 1;
for (uint64_t i = 0; i < 8; i++)
lcw[i+64] = (temp_b >> (7-i)) & 1;
p25_lcw(opts, state, lcw, 0);
temp_a = 0x179004B9EA998F87; temp_b = 0x48;
memset (lcw, 0, sizeof(lcw));
for (uint64_t i = 0; i < 64; i++)
lcw[i] = (temp_a >> (63-i)) & 1;
for (uint64_t i = 0; i < 8; i++)
lcw[i+64] = (temp_b >> (7-i)) & 1;
p25_lcw(opts, state, lcw, 0);
temp_a = 0x179005BE6DAB167F; temp_b = 0xAC;
memset (lcw, 0, sizeof(lcw));
for (uint64_t i = 0; i < 64; i++)
lcw[i] = (temp_a >> (63-i)) & 1;
for (uint64_t i = 0; i < 8; i++)
lcw[i+64] = (temp_b >> (7-i)) & 1;
p25_lcw(opts, state, lcw, 0);
temp_a = 0x179006B15EC2C622; temp_b = 0x2E;
memset (lcw, 0, sizeof(lcw));
for (uint64_t i = 0; i < 64; i++)
lcw[i] = (temp_a >> (63-i)) & 1;
for (uint64_t i = 0; i < 8; i++)
lcw[i+64] = (temp_b >> (7-i)) & 1;
p25_lcw(opts, state, lcw, 0);
}
void apx_embedded_alias_header (dsd_opts * opts, dsd_state * state, uint8_t slot, uint8_t lc_bits[])
{
UNUSED(opts);
uint8_t ta_len = (uint8_t)ConvertBitIntoBytes(&lc_bits[32], 8); //len in blocks of associated talker alias
fprintf (stderr, " Block Len: %d;", ta_len);
//use dmr_pdu_sf for storage, store entire header (will be used to verify complete reception of full alias)
memset (state->dmr_pdu_sf[slot], 0, sizeof (state->dmr_pdu_sf[slot])); //reset storage for header and blocks
memcpy(state->dmr_pdu_sf[slot], lc_bits, 72*sizeof(uint8_t));
}
void apx_embedded_alias_blocks (dsd_opts * opts, dsd_state * state, uint8_t slot, uint8_t lc_bits[])
{
UNUSED(opts);
uint8_t bn = (uint8_t)ConvertBitIntoBytes(&lc_bits[16], 8); //current block number
uint8_t sn = (uint8_t)ConvertBitIntoBytes(&lc_bits[24], 4); //is a static value on all block sequences
uint8_t ta_len = (uint8_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][32], 8); //len in blocks pulled from stored header
uint16_t header = (uint16_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][0], 16); //header check, should be 0x1590
if (ta_len == 0 || header != 0x1590) //checkdown, make sure we have an up to date header for this with a good len value
{
fprintf (stderr, " Missing Header");
fprintf (stderr, " BN: %d/??;", bn);
fprintf (stderr, " SN: %X;", sn);
fprintf (stderr, " Partial: ");
for (uint8_t i = 7; i < 18; i++)
fprintf (stderr, "%0X", (uint8_t)ConvertBitIntoBytes(&lc_bits[0+(i*4)], 4));
//clear out now stale storage
memset (state->dmr_pdu_sf[slot], 0, sizeof (state->dmr_pdu_sf[slot]));
}
else //good len and header stored
{
//sanity check, bn cannot equal zero (this shouldn't happen, but bad decode could occur)
if (bn == 0) bn = 1;
fprintf (stderr, " SN: %X;", sn);
fprintf (stderr, " BN: %d/%d;", bn, ta_len);
//use dmr_pdu_sf for storage, store data relevant portion at ptr of (bn-1) * 44 + 72 offset for header
memcpy(state->dmr_pdu_sf[slot]+(((bn-1)*44)+72), lc_bits+28, 44*sizeof(uint8_t));
if (ta_len == bn) //this is the last block, proceed to decoding
{
//debug, let's look at byte, bit counts and see if we can find this in the completed dump
// fprintf (stderr, " Bits: %X; Bytes: %X; Mod: %d; ", bn*44, (bn*44)/8, (bn*44)%8); //the portion with 0100 is 8 off from 0108 (hex) bits
//debug, dump completed data set
// fprintf (stderr, "\n Full: ");
// for (uint8_t i = 0; i < ((bn*11)+18); i++) //double check on other bn values
// fprintf (stderr, "%X", (uint8_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][0+(i*4)], 4));
// fprintf (stderr, "\n");
//extract fully qualified SUID
uint32_t wacn = (uint32_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][72], 20);
uint32_t sys = (uint32_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][92], 12);
uint32_t rid = (uint32_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][104], 24);
//print fully qualified SUID
fprintf (stderr, "\n WACN: %05X; SYS: %03X; RID: %d;", wacn, sys, rid);
//extract CRC
uint16_t crc_ext = (uint16_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][(72+(bn*44)-16)], 16);
//compute CRC
uint16_t crc_cmp = ComputeCrcCCITT16d(&state->dmr_pdu_sf[slot][72], (bn*44)-16);
//print comparison
// fprintf (stderr, " CRC EXT: %04X CMP: %04X;", crc_ext, crc_cmp);
if (crc_ext != crc_cmp)
fprintf (stderr, " CRC Error;");
// else fprintf (stderr, " Okay;");
//start decoding the alias
if (crc_ext == crc_cmp)
{
//WIP: Working, needs more samples to verify various len values
uint16_t ptr = 128; //starting point of encoded data from test vectors
uint8_t encoded[200]; memset(encoded, 0, sizeof(encoded));
uint8_t decoded[200]; memset(decoded, 0, sizeof(decoded));
uint16_t num_bytes = ((44*bn) / 8) - 9; //substract 2 CRC and 7 FQSUID
for (int16_t i = 0; i < num_bytes; i++)
{
encoded[i] = (uint8_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][ptr], 8);
ptr += 8;
}
uint16_t accumulator = num_bytes;
//Ilya's Voodoo Code
for (int16_t i = 0; i < num_bytes; i++)
{
// Multiplication step 1
uint16_t accum_mult = accumulator * 293 + 0x72E9;
// Lookup table step
uint8_t lut = alias_lut[encoded[i]];
uint8_t mult1 = lut - (accum_mult >> 8);
// Incrementing step
uint8_t mult2 = 1;
uint8_t shortstop = accum_mult | 0x1;
uint8_t increment = shortstop << 1;
while(mult2 != -1 && shortstop != 1)
{
shortstop += increment;
mult2 += 2;
}
// Multiplication step 2
decoded[i] = mult1 * mult2;
// Update the accumulator
accumulator += encoded[i] + 1;
}
// //debug, dump just the encoded alias portion
// fprintf (stderr, "\n Encoded: ");
// for (int16_t i = 0; i < bytes; i++)
// fprintf (stderr, "%02X", encoded[i]);
// //debug, dump the decoded payload as hex octets
// fprintf (stderr, "\n Decoded: ");
// for (int16_t i = 0; i < bytes; i++)
// fprintf (stderr, "%02X", decoded[i]);
//dump the decoded payload as long chars
// fprintf (stderr, "\n");
fprintf (stderr, " Alias: ");
for (int16_t i = 0; i < num_bytes/2; i++)
fprintf (stderr, "%lc", ((decoded[(i*2)+0])<<8) | ((decoded[(i*2)+1])<<0) );
//For Ncurses Display (needs to be testing on real samples first to make sure this is setup right)
// memcpy(state->dmr_embedded_gps[slot], decoded, bytes*sizeof(uint8_t));
// state->dmr_embedded_gps[slot][199] = '\0'; //terminate string
}
//clear out now stale storage
memset (state->dmr_pdu_sf[slot], 0, sizeof (state->dmr_pdu_sf[slot]));
}
}
}

View File

@ -1534,11 +1534,8 @@ if (opts->audio_out_type == 0)
openPulseOutput(opts);
}
// #ifdef AERO_BUILD //NOTE: Blame seems to be synctest8 not being initialized (will continue to test)
// //TODO: More Random Cygwin Related M17 Bugs to sort out
// if(opts->frame_m17 == 1)
// for (int i = 0; i < 960; i++) getSymbol(opts, state, 1); //I think this is actually just framesync being a pain
// #endif
//test P25 moto alias by loading in test vectors captured from a system and dumped on forum (see dsd_gps.c)
// apx_embedded_alias_test(opts, state); //enable this to run test
while (!exitflag)
{

View File

@ -297,6 +297,7 @@ void p25_lcw (dsd_opts * opts, dsd_state * state, uint8_t LCW_bits[], uint8_t ir
{
uint32_t tgt = (uint32_t)ConvertBitIntoBytes(&LCW_bits[48], 24); //can be individual, or all units (0xFFFFFF)
fprintf (stderr, " Call Termination; TGT: %d;", tgt);
memset (state->dmr_pdu_sf[0], 0, sizeof (state->dmr_pdu_sf[0])); //reset storage for any talker alias (or other items)
if (opts->p25_trunk == 1 && state->p25_cc_freq != 0 && opts->p25_is_tuned == 1)
{
@ -455,6 +456,19 @@ void p25_lcw (dsd_opts * opts, dsd_state * state, uint8_t LCW_bits[], uint8_t ir
fprintf (stderr, " MFID90 (Moto) Talker EOT; SRC: %d;", src);
}
//look for these in logs
else if (lc_mfid == 0x90 && lc_opcode == 0x15)
{
fprintf (stderr, " MFID90 (Moto) Talker Alias Header");
apx_embedded_alias_header (opts, state, 0, LCW_bits);
}
else if (lc_mfid == 0x90 && lc_opcode == 0x17)
{
fprintf (stderr, " MFID90 (Moto) Talker Alias Block");
apx_embedded_alias_blocks (opts, state, 0, LCW_bits);
}
//observed format value on Harris SNDCP data channel (Phase 2 CC to Phase 1 MPDU channel)
else if (lc_mfid == 0xA4 && lc_format == 0x0A)
{

View File

@ -1861,7 +1861,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon
{
uint8_t mfid = MAC[len_a+2];
uint8_t len = MAC[len_a+3] & 0x3F;
fprintf (stderr, "\n MFID %02X (Tait); Len: %d; Opcode: %02X;", mfid, len, MAC[len_a+1]);
fprintf (stderr, "\n MFID %02X (Tait); Len: %d; Opcode: %02llX;", mfid, len, MAC[len_a+1]);
//sanity check
if (len > 24)