P25 Moto Talker Alias LCW WIP;

This commit is contained in:
lwvmobile
2025-02-05 09:52:30 -05:00
parent 61673222db
commit 8cfaced4b4

View File

@@ -765,25 +765,26 @@ void apx_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[])
fprintf (stderr, "%s", KNRM); fprintf (stderr, "%s", KNRM);
} }
uint8_t alias_scramble[256] = { //relocate all below later on
0xA8, 0xDF, 0x9E, 0x04, 0xF5, 0xF9, 0xEE, 0x1B, 0xAC, 0x3E, 0xE2, 0xAD, 0x71, 0xFC, 0x38, 0x03, uint8_t alias_lut[256] = {
0x59, 0xCE, 0xED, 0x82, 0xE1, 0xBD, 0x28, 0x86, 0x39, 0x78, 0x1C, 0xB7, 0xBA, 0xA3, 0x41, 0xD0, 0xD2, 0xF6, 0xD4, 0x2B, 0x63, 0x49, 0x94, 0x5E, 0xA7, 0x5C, 0x70, 0x69, 0xF7, 0x08, 0xB1, 0x7D,
0x6D, 0x1F, 0x2F, 0xBB, 0x3D, 0x02, 0x3A, 0x20, 0x5F, 0x42, 0xC7, 0xA2, 0x70, 0x6E, 0x21, 0x7E, 0x38, 0xCF, 0xCC, 0xD8, 0x51, 0x8F, 0xD5, 0x93, 0x6A, 0xF3, 0xEF, 0x7E, 0xFB, 0x64, 0xF4, 0x35,
0x22, 0x90, 0xDB, 0xC8, 0xD7, 0x23, 0x85, 0xE0, 0xFB, 0x8D, 0x79, 0xEC, 0x33, 0xD6, 0xCC, 0x3C, 0x27, 0x07, 0x31, 0x14, 0x87, 0x98, 0x76, 0x34, 0xCA, 0x92, 0x33, 0x1B, 0x4F, 0x8C, 0x09, 0x40,
0xA9, 0x24, 0x8F, 0x6C, 0x36, 0x25, 0x26, 0xBC, 0xFF, 0xEB, 0x34, 0xA1, 0x2D, 0x2E, 0x44, 0x48, 0x32, 0x36, 0x77, 0x12, 0xD3, 0xC3, 0x01, 0xAB, 0x72, 0x81, 0x95, 0xC9, 0xC0, 0xE9, 0x65, 0x52,
0x45, 0xD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BE, 0x62, 0x2D, 0xF1, 0x7C, 0xB8, 0x83,
0xA4, 0xB0, 0x9C, 0x5B, 0x08, 0x68, 0x17, 0x1D, 0xD8, 0xA6, 0x84, 0xB9, 0x2C, 0xAA, 0x1E, 0x2A, 0xD9, 0x4E, 0x6D, 0x02, 0x61, 0x3D, 0xA8, 0x06, 0xB9, 0xF8, 0x9C, 0x37, 0x3A, 0x23, 0xC1, 0x50,
0xA5, 0x57, 0x4E, 0x6B, 0x16, 0x75, 0x8E, 0x0D, 0x5C, 0x29, 0xAF, 0x5D, 0x9F, 0x6A, 0x11, 0x37, 0xED, 0x9F, 0xAF, 0x3B, 0xBD, 0x82, 0xBA, 0xA0, 0xDF, 0xC2, 0x47, 0x22, 0xF0, 0xEE, 0xA1, 0xFE,
0x56, 0x09, 0x0B, 0x51, 0x30, 0x19, 0x93, 0xFA, 0x67, 0x1A, 0x35, 0x06, 0x7F, 0xC6, 0x05, 0x32, 0xA2, 0x10, 0x5B, 0x48, 0x57, 0xA3, 0x05, 0x60, 0x7B, 0x0D, 0xF9, 0x6C, 0xB3, 0x56, 0x4C, 0xBC,
0xF3, 0x5A, 0x3F, 0x50, 0xF1, 0x4B, 0xCD, 0x00, 0x95, 0xE7, 0x96, 0x9A, 0xA0, 0x0E, 0xC5, 0xBE 0x29, 0xA4, 0x0F, 0xEC, 0xB6, 0xA5, 0xA6, 0x3C, 0x7F, 0x6B, 0xB4, 0x21, 0xAD, 0xAE, 0xC4, 0xC8,
0xC5, 0x5D, 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
}; };
//relocate this later on
void apx_embedded_alias_test (dsd_opts * opts, dsd_state * state) 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 uint64_t temp_a = 0x15900FE9060100B0; uint64_t temp_b = 0x5A; //72 bits, so break into segments
@@ -914,25 +915,77 @@ void apx_embedded_alias_blocks (dsd_opts * opts, dsd_state * state, uint8_t slot
uint16_t crc_cmp = ComputeCrcCCITT16d(&state->dmr_pdu_sf[slot][72], (bn*44)-16); uint16_t crc_cmp = ComputeCrcCCITT16d(&state->dmr_pdu_sf[slot][72], (bn*44)-16);
//print comparison //print comparison
fprintf (stderr, " CRC EXT: %04X CMP: %04X;", crc_ext, crc_cmp); // fprintf (stderr, " CRC EXT: %04X CMP: %04X;", crc_ext, crc_cmp);
if (crc_ext != crc_cmp) if (crc_ext != crc_cmp)
fprintf (stderr, " Error;"); fprintf (stderr, " CRC Error;");
else fprintf (stderr, " Okay;"); // else fprintf (stderr, " Okay;");
//debug, dump just the encoded alias portion
fprintf (stderr, "\n Encoded: ");
for (int16_t i = 32; i < ((bn*11)+18-4); i++) //double check on other bn values
{
// if ((i != 32) && ((i % 2) == 0))
// fprintf (stderr, " ");
fprintf (stderr, "%X", (uint8_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[slot][0+(i*4)], 4));
}
//start decoding the alias //start decoding the alias
if (crc_ext == crc_cmp) if (crc_ext == crc_cmp)
{ {
//TODO: Figure this out //WIP: Working, needs more samples to verify various len values
// int16_t ptr = 128; //starting point of encoded data from test vectors 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 //clear out now stale storage