From 15a12acfd3a473302de1c7c25345676c7de69dc4 Mon Sep 17 00:00:00 2001 From: lwvmobile Date: Thu, 15 Jun 2023 17:47:58 -0400 Subject: [PATCH 1/7] Update Cmake for zDEV; --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a3bddb8..7026c38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,7 @@ endif () #use cmake option -DZDEV to change designation of this build from MAIN to zDEV option(ZDEV - "change designation of this build from MAIN to zDEV" OFF) + "change designation of this build from MAIN to zDEV" ON) if (ZDEV) add_definitions(-DZDEV_BUILD) endif () From b6a12b6cebb22ae5d31ce5fc34877db348f43e0a Mon Sep 17 00:00:00 2001 From: lwvmobile Date: Sat, 17 Jun 2023 17:29:03 -0400 Subject: [PATCH 2/7] Fix RC4 'Pop' on DMR when VC6 is Null; Fix Align; --- src/dsd_frame_sync.c | 2 +- src/dsd_mbe.c | 1554 +++++++++++++++++++++--------------------- 2 files changed, 784 insertions(+), 772 deletions(-) diff --git a/src/dsd_frame_sync.c b/src/dsd_frame_sync.c index cd682e2..d99c507 100644 --- a/src/dsd_frame_sync.c +++ b/src/dsd_frame_sync.c @@ -1606,7 +1606,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state) if ((opts->errorbars == 1) && (opts->verbose > 1) && (state->carrier == 1)) { fprintf (stderr,"Sync: no sync\n"); - fprintf (stderr,"Press CTRL + C to close.\n"); + // fprintf (stderr,"Press CTRL + C to close.\n"); } noCarrier (opts, state); diff --git a/src/dsd_mbe.c b/src/dsd_mbe.c index a491d10..6738370 100644 --- a/src/dsd_mbe.c +++ b/src/dsd_mbe.c @@ -17,53 +17,54 @@ #include "dsd.h" -//test for potential clashing with other key loading mechanisms (bp key loading on tgid, nxdn key loading, etc) +//NOTE: I attempted to fix the atrocious tab/space alignnment issues that happened in this file, +//it looks fine in VSCodium, but no telling how it will translate when pushed to Github or another editor + void keyring(dsd_opts * opts, dsd_state * state) { - //keys now loaded from csv files with the -K key.csv file (capital K) - if (state->currentslot == 0) - state->R = state->rkey_array[state->payload_keyid]; - if (state->currentslot == 1) - state->RR = state->rkey_array[state->payload_keyidR]; + if (state->currentslot == 0) + state->R = state->rkey_array[state->payload_keyid]; + if (state->currentslot == 1) + state->RR = state->rkey_array[state->payload_keyidR]; } void RC4(int drop, uint8_t keylength, uint8_t messagelength, uint8_t key[], uint8_t cipher[], uint8_t plain[]) { - int i, j, count; + int i, j, count; uint8_t t, b; - //init Sbox - uint8_t S[256]; + //init Sbox + uint8_t S[256]; for(int i = 0; i < 256; i++) S[i] = i; - //Key Scheduling - j = 0; - for(i = 0; i < 256; i++) - { - j = (j + S[i] + key[i % keylength]) % 256; - t = S[i]; - S[i] = S[j]; - S[j] = t; - } + //Key Scheduling + j = 0; + for(i = 0; i < 256; i++) + { + j = (j + S[i] + key[i % keylength]) % 256; + t = S[i]; + S[i] = S[j]; + S[j] = t; + } - //Drop Bytes and Cipher Byte XOR - i = j = 0; - for(count = 0; count < (messagelength + drop); count++) - { - i = (i + 1) % 256; - j = (j + S[i]) % 256; - t = S[i]; - S[i] = S[j]; - S[j] = t; - b = S[(S[i] + S[j]) % 256]; + //Drop Bytes and Cipher Byte XOR + i = j = 0; + for(count = 0; count < (messagelength + drop); count++) + { + i = (i + 1) % 256; + j = (j + S[i]) % 256; + t = S[i]; + S[i] = S[j]; + S[j] = t; + b = S[(S[i] + S[j]) % 256]; //return mbe payload byte here - if (count >= drop) + if (count >= drop) plain[count - drop] = b^cipher[count - drop]; - } + } } @@ -126,16 +127,14 @@ void playMbeFiles (dsd_opts * opts, dsd_state * state, int argc, char **argv) processAudio(opts, state); } if (opts->wav_out_f != NULL) - { - writeSynthesizedVoice (opts, state); - } + { + writeSynthesizedVoice (opts, state); + } if (opts->audio_out == 1) - { - - playSynthesizedVoice (opts, state); - - } + { + playSynthesizedVoice (opts, state); + } } else if (state->mbe_file_type > 0) //ambe files { @@ -183,7 +182,7 @@ void processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char ambe_fr[4][24], char imbe7100_fr[7][24]) { - int i; + int i; char imbe_d[88]; char ambe_d[49]; char ambe_d_str[50]; @@ -221,7 +220,7 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a //if we are using allow/whitelist mode, then write 'B' to mode for block //comparison below will look for an 'A' to write to mode if it is allowed if (opts->trunk_use_allow_list == 1) sprintf (mode, "%s", "B"); - + int groupNumber = 0; if (state->currentslot == 0) groupNumber = state->lasttg; @@ -240,21 +239,373 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a //end set playback mode for this frame - if ((state->synctype == 0) || (state->synctype == 1)) - { - // 0 +P25p1 - // 1 -P25p1 - state->errs = mbe_eccImbe7200x4400C0 (imbe_fr); - //state->errs2 = state->errs; - mbe_demodulateImbe7200x4400Data (imbe_fr); - state->errs2 = mbe_eccImbe7200x4400Data (imbe_fr, imbe_d); + if ((state->synctype == 0) || (state->synctype == 1)) + { + // 0 +P25p1 + // 1 -P25p1 + state->errs = mbe_eccImbe7200x4400C0 (imbe_fr); + //state->errs2 = state->errs; + mbe_demodulateImbe7200x4400Data (imbe_fr); + state->errs2 = mbe_eccImbe7200x4400Data (imbe_fr, imbe_d); - //P25p1 RC4 Handling - if (state->payload_algid == 0xAA && state->R != 0) + //P25p1 RC4 Handling + if (state->payload_algid == 0xAA && state->R != 0) + { + uint8_t cipher[11] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t plain[11] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t rckey[13] = {0x00, 0x00, 0x00, 0x00, 0x00, // <- RC4 Key + 0x00, 0x00, 0x00, 0x00, 0x00, // <- MI + 0x00, 0x00, 0x00}; // <- MI cont. + + //easier to manually load up rather than make a loop + rckey[0] = ((state->R & 0xFF00000000) >> 32); + rckey[1] = ((state->R & 0xFF000000) >> 24); + rckey[2] = ((state->R & 0xFF0000) >> 16); + rckey[3] = ((state->R & 0xFF00) >> 8); + rckey[4] = ((state->R & 0xFF) >> 0); + + // load valid MI from state->payload_miP + rckey[5] = ((state->payload_miP & 0xFF00000000000000) >> 56); + rckey[6] = ((state->payload_miP & 0xFF000000000000) >> 48); + rckey[7] = ((state->payload_miP & 0xFF0000000000) >> 40); + rckey[8] = ((state->payload_miP & 0xFF00000000) >> 32); + rckey[9] = ((state->payload_miP & 0xFF000000) >> 24); + rckey[10] = ((state->payload_miP & 0xFF0000) >> 16); + rckey[11] = ((state->payload_miP & 0xFF00) >> 8); + rckey[12] = ((state->payload_miP & 0xFF) >> 0); + + // if (state->p25vc == 0) + // { + // fprintf (stderr, "%s", KYEL); + // fprintf (stderr, "\n RC4K "); + // for (short o = 0; o < 13; o++) + // { + // fprintf (stderr, "%02X", rckey[o]); + // } + // fprintf (stderr, "%s", KNRM); + // } + + //load imbe_d into imbe_cipher octets + int z = 0; + for (i = 0; i < 11; i++) { - uint8_t cipher[11] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t plain[11] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t rckey[13] = {0x00, 0x00, 0x00, 0x00, 0x00, // <- RC4 Key + cipher[i] = 0; + plain[i] = 0; + for (short int j = 0; j < 8; j++) + { + cipher[i] = cipher[i] << 1; + cipher[i] = cipher[i] + imbe_d[z]; + imbe_d[z] = 0; + z++; + } + } + + RC4(state->dropL, 13, 11, rckey, cipher, plain); + state->dropL += 11; + + z = 0; + for (short p = 0; p < 11; p++) + { + for (short o = 0; o < 8; o++) + { + imbe_d[z] = (plain[p] & 0x80) >> 7; + plain[p] = plain[p] << 1; + z++; + } + } + + } + + mbe_processImbe4400Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, + imbe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); + + //mbe_processImbe7200x4400Framef (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, imbe_fr, imbe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); + if (opts->payload == 1) + { + PrintIMBEData (opts, state, imbe_d); + } + + //increment vc counter by one. + state->p25vc++; + + if (opts->mbe_out_f != NULL && state->dmr_encL == 0) //only save if this bit not set + { + saveImbe4400Data (opts, state, imbe_d); + } + } + else if ((state->synctype == 14) || (state->synctype == 15)) //pV Sync + { + + state->errs = mbe_eccImbe7100x4400C0 (imbe7100_fr); + //state->errs2 = state->errs; + mbe_demodulateImbe7100x4400Data (imbe7100_fr); + state->errs2 = mbe_eccImbe7100x4400Data (imbe7100_fr, imbe_d); + + if (opts->payload == 1) + { + PrintIMBEData (opts, state, imbe_d); + } + + mbe_convertImbe7100to7200(imbe_d); + mbe_processImbe4400Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, + imbe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); + + if (opts->mbe_out_f != NULL) + { + saveImbe4400Data (opts, state, imbe_d); + } + } + else if ((state->synctype == 6) || (state->synctype == 7)) + { + mbe_processAmbe3600x2400Framef (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, ambe_fr, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); + if (opts->payload == 1) + { + PrintAMBEData (opts, state, ambe_d); + } + if (opts->mbe_out_f != NULL) + { + saveAmbe2450Data (opts, state, ambe_d); + } + } + else if ((state->synctype == 28) || (state->synctype == 29)) //was 8 and 9 + { + + state->errs = mbe_eccAmbe3600x2450C0 (ambe_fr); + //state->errs2 = state->errs; + mbe_demodulateAmbe3600x2450Data (ambe_fr); + state->errs2 = mbe_eccAmbe3600x2450Data (ambe_fr, ambe_d); + + if ( (state->nxdn_cipher_type == 0x01 && state->R > 0) || + (state->M == 1 && state->R > 0) ) + { + + if (state->payload_miN == 0) + { + state->payload_miN = state->R; + } + + char ambe_temp[49]; + for (short int i = 0; i < 49; i++) + { + ambe_temp[i] = ambe_d[i]; + ambe_d[i] = 0; + } + LFSRN(ambe_temp, ambe_d, state); + + } + + mbe_processAmbe2450Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, + ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); + + if (opts->payload == 1) + { + PrintAMBEData (opts, state, ambe_d); + } + + if (opts->mbe_out_f != NULL && (state->dmr_encL == 0 || opts->dmr_mute_encL == 0) ) + { + saveAmbe2450Data (opts, state, ambe_d); + } + + } + else + { + //stereo slots and slot 0 (left slot) + if (state->currentslot == 0) //&& opts->dmr_stereo == 1 + { + + state->errs = mbe_eccAmbe3600x2450C0 (ambe_fr); + //state->errs2 = state->errs; + mbe_demodulateAmbe3600x2450Data (ambe_fr); + state->errs2 = mbe_eccAmbe3600x2450Data (ambe_fr, ambe_d); + + //EXPERIMENTAL!! + //load basic privacy key number from array by the tg value (if not forced) + //currently only Moto BP and Hytera 10 Char BP + if (state->M == 0 && state->payload_algid == 0) + { + //see if we need to hash a value larger than 16-bits + hash = state->lasttg & 0xFFFFFF; + // fprintf (stderr, "TG: %lld Hash: %ld ", state->lasttg, hash); + if (hash > 0xFFFF) //if greater than 16-bits + { + for (int i = 0; i < 24; i++) + { + hash_bits[i] = ((hash << i) & 0x800000) >> 23; //load into array for CRC16 + } + hash = ComputeCrcCCITT16d (hash_bits, 24); + hash = hash & 0xFFFF; //make sure its no larger than 16-bits + // fprintf (stderr, "Hash: %d ", hash); + } + if (state->rkey_array[hash] != 0) + { + state->K = state->rkey_array[hash] & 0xFF; //doesn't exceed 255 + state->K1 = state->H = state->rkey_array[hash] & 0xFFFFFFFFFF; //doesn't exceed 40-bit limit + opts->dmr_mute_encL = 0; + // fprintf (stderr, "Key: %X ", state->rkey_array[hash]); + } + // else opts->dmr_mute_encL = 1; //may cause issues for manual key entry (non-csv) + } + + if ( (state->K > 0 && state->dmr_so & 0x40 && state->payload_keyid == 0 && state->dmr_fid == 0x10) || + (state->K > 0 && state->M == 1) ) + { + k = Pr[state->K]; + k = ( ((k & 0xFF0F) << 32 ) + (k << 16) + k ); + for (short int j = 0; j < 48; j++) //49 + { + x = ( ((k << j) & 0x800000000000) >> 47 ); + ambe_d[j] ^= x; + } + } + + if ( (state->K1 > 0 && state->dmr_so & 0x40 && state->payload_keyid == 0 && state->dmr_fid == 0x68) || + (state->K1 > 0 && state->M == 1) ) + { + + int pos = 0; + + unsigned long long int k1 = state->K1; + unsigned long long int k2 = state->K2; + unsigned long long int k3 = state->K3; + unsigned long long int k4 = state->K4; + + int T_Key[256] = {0}; + int pN[882] = {0}; + + int len = 0; + + if (k2 == 0) + { + len = 39; + k1 = k1 << 24; + } + if (k2 != 0) + { + len = 127; + } + if (k4 != 0) + { + len = 255; + } + + for (i = 0; i < 64; i++) + { + T_Key[i] = ( ((k1 << i) & 0x8000000000000000) >> 63 ); + T_Key[i+64] = ( ((k2 << i) & 0x8000000000000000) >> 63 ); + T_Key[i+128] = ( ((k3 << i) & 0x8000000000000000) >> 63 ); + T_Key[i+192] = ( ((k4 << i) & 0x8000000000000000) >> 63 ); + } + + for (i = 0; i < 882; i++) + { + pN[i] = T_Key[pos]; + pos++; + if (pos > len) + { + pos = 0; + } + } + + //sanity check + if (state->DMRvcL > 17) //18 + { + state->DMRvcL = 17; //18 + } + + pos = state->DMRvcL * 49; + for(i = 0; i < 49; i++) + { + ambe_d[i] ^= pN[pos]; + pos++; + } + state->DMRvcL++; + } + + //DMR RC4, Slot 1 + if (state->currentslot == 0 && state->payload_algid == 0x21 && state->R != 0) + { + uint8_t cipher[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t plain[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t rckey[9] = {0x00, 0x00, 0x00, 0x00, 0x00, // <- RC4 Key + 0x00, 0x00, 0x00, 0x00}; // <- MI + + //easier to manually load up rather than make a loop + rckey[0] = ((state->R & 0xFF00000000) >> 32); + rckey[1] = ((state->R & 0xFF000000) >> 24); + rckey[2] = ((state->R & 0xFF0000) >> 16); + rckey[3] = ((state->R & 0xFF00) >> 8); + rckey[4] = ((state->R & 0xFF) >> 0); + rckey[5] = ((state->payload_mi & 0xFF000000) >> 24); + rckey[6] = ((state->payload_mi & 0xFF0000) >> 16); + rckey[7] = ((state->payload_mi & 0xFF00) >> 8); + rckey[8] = ((state->payload_mi & 0xFF) >> 0); + + // if (opts->payload == 1) + // { + // fprintf (stderr, "%s", KYEL); + // fprintf (stderr, " RC4K "); + // for (short o = 0; o < 9; o++) + // { + // fprintf (stderr, "%02X", rckey[o]); + // } + // fprintf (stderr, "%s", KNRM); + // fprintf (stderr, "\n"); + // } + + short k = 0; + for (short o = 0; o < 7; o++) + { + short b = 0; + for (short p = 0; p < 8; p++) + { + b = b << 1; + b = b + ambe_d[k]; + k++; + if (k == 49) + { + cipher[6] = ((b << 3) & 0x80); //set 7th octet/bit 49 accordingly + break; + } + } + cipher[o] = b; + } + + //only run keystream application if errs < 3 -- this is a fix to the pop sound + //that may occur on some systems that preempt VC6 voice for a RC opportuninity (TXI) + //this occurs because we are supposed to either have a a 'repeat' frame, or 'silent' frame play + //due to the error, but the keystream application makes it random 'pfft pop' sound instead + if (state->errs < 3) + RC4(state->dropL, 9, 7, rckey, cipher, plain); + else memcpy (plain, cipher, sizeof(plain)); + + state->dropL += 7; + + short z = 0; + for (short p = 0; p < 6; p++) + { + //convert bytes back to bits and load into ambe_d array. + short b = 0; //reset b to use again + for (short o = 0; o < 8; o++) + { + b = (( (plain[p] << o) & 0x80) >> 7); + ambe_d[z] = b; + z++; + if (z == 49) + { + ambe_d[48] = ( (plain[p] << o) & 0x80); + break; + } + } + } + } + + //P25p2 RC4 Handling, VCH 0 + if (state->currentslot == 0 && state->payload_algid == 0xAA && state->R != 0 && ((state->synctype == 35) || (state->synctype == 36))) + { + uint8_t cipher[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t plain[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t rckey[13] = {0x00, 0x00, 0x00, 0x00, 0x00, // <- RC4 Key 0x00, 0x00, 0x00, 0x00, 0x00, // <- MI 0x00, 0x00, 0x00}; // <- MI cont. @@ -275,716 +626,377 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a rckey[11] = ((state->payload_miP & 0xFF00) >> 8); rckey[12] = ((state->payload_miP & 0xFF) >> 0); - // if (state->p25vc == 0) - // { - // fprintf (stderr, "%s", KYEL); - // fprintf (stderr, "\n RC4K "); - // for (short o = 0; o < 13; o++) - // { - // fprintf (stderr, "%02X", rckey[o]); - // } - // fprintf (stderr, "%s", KNRM); - // } + // if (opts->payload == 1) + // { + // fprintf (stderr, "%s", KYEL); + // fprintf (stderr, " RC4K "); + // for (short o = 0; o < 13; o++) + // { + // fprintf (stderr, "%02X", rckey[o]); + // } + // fprintf (stderr, "%s", KNRM); + // fprintf (stderr, "\n"); + // } - //load imbe_d into imbe_cipher octets - int z = 0; - for (i = 0; i < 11; i++) - { - cipher[i] = 0; - plain[i] = 0; - for (short int j = 0; j < 8; j++) - { - cipher[i] = cipher[i] << 1; - cipher[i] = cipher[i] + imbe_d[z]; - imbe_d[z] = 0; - z++; - } - } - - RC4(state->dropL, 13, 11, rckey, cipher, plain); - state->dropL += 11; - - z = 0; - for (short p = 0; p < 11; p++) - { - for (short o = 0; o < 8; o++) - { - imbe_d[z] = (plain[p] & 0x80) >> 7; - plain[p] = plain[p] << 1; - z++; - } + short k = 0; + for (short o = 0; o < 7; o++) + { + short b = 0; + for (short p = 0; p < 8; p++) + { + b = b << 1; + b = b + ambe_d[k]; + k++; + if (k == 49) + { + cipher[6] = ((b << 3) & 0x80); //set 7th octet/bit 49 accordingly + break; + } + } + cipher[o] = b; } + RC4(state->dropL, 13, 7, rckey, cipher, plain); + state->dropL += 7; + + short z = 0; + for (short p = 0; p < 6; p++) + { + //convert bytes back to bits and load into ambe_d array. + short b = 0; //reset b to use again + for (short o = 0; o < 8; o++) + { + b = (( (plain[p] << o) & 0x80) >> 7); + ambe_d[z] = b; + z++; + if (z == 49) + { + ambe_d[48] = ( (plain[p] << o) & 0x80); + break; + } + } + } } - mbe_processImbe4400Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, - imbe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); + mbe_processAmbe2450Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, + ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); - //mbe_processImbe7200x4400Framef (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, imbe_fr, imbe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); - if (opts->payload == 1) + + //old method for this step below + //mbe_processAmbe3600x2450Framef (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, ambe_fr, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); + if (opts->payload == 1) // && state->R == 0 this is why slot 1 didn't primt abme, probably had it set during testing { - PrintIMBEData (opts, state, imbe_d); + PrintAMBEData (opts, state, ambe_d); } - //increment vc counter by one. - state->p25vc++; - - if (opts->mbe_out_f != NULL && state->dmr_encL == 0) //only save if this bit not set + //restore MBE file save, slot 1 -- consider saving even if enc + if (opts->mbe_out_f != NULL && (state->dmr_encL == 0 || opts->dmr_mute_encL == 0) ) { - saveImbe4400Data (opts, state, imbe_d); + saveAmbe2450Data (opts, state, ambe_d); } + } - else if ((state->synctype == 14) || (state->synctype == 15)) //pV Sync + //stereo slots and slot 1 (right slot) + if (state->currentslot == 1) //&& opts->dmr_stereo == 1 { - state->errs = mbe_eccImbe7100x4400C0 (imbe7100_fr); - //state->errs2 = state->errs; - mbe_demodulateImbe7100x4400Data (imbe7100_fr); - state->errs2 = mbe_eccImbe7100x4400Data (imbe7100_fr, imbe_d); + state->errsR = mbe_eccAmbe3600x2450C0 (ambe_fr); + //state->errs2R = state->errsR; + mbe_demodulateAmbe3600x2450Data (ambe_fr); + state->errs2R = mbe_eccAmbe3600x2450Data (ambe_fr, ambe_d); - if (opts->payload == 1) - { - PrintIMBEData (opts, state, imbe_d); - } - - mbe_convertImbe7100to7200(imbe_d); - mbe_processImbe4400Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, - imbe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); - - if (opts->mbe_out_f != NULL) + //EXPERIMENTAL!! + //load basic privacy key number from array by the tg value (if not forced) + //currently only Moto BP and Hytera 10 Char BP + if (state->M == 0 && state->payload_algidR == 0) { - saveImbe4400Data (opts, state, imbe_d); + //see if we need to hash a value larger than 16-bits + hash = state->lasttgR & 0xFFFFFF; + // fprintf (stderr, "TG: %lld Hash: %ld ", state->lasttgR, hash); + if (hash > 0xFFFF) //if greater than 16-bits + { + for (int i = 0; i < 24; i++) + { + hash_bits[i] = ((hash << i) & 0x800000) >> 23; //load into array for CRC16 + } + hash = ComputeCrcCCITT16d (hash_bits, 24); + hash = hash & 0xFFFF; //make sure its no larger than 16-bits + // fprintf (stderr, "Hash: %d ", hash); + } + if (state->rkey_array[hash] != 0) + { + state->K = state->rkey_array[hash] & 0xFF; //doesn't exceed 255 + state->K1 = state->H = state->rkey_array[hash] & 0xFFFFFFFFFF; //doesn't exceed 40-bit limit + opts->dmr_mute_encR = 0; + // fprintf (stderr, "Key: %X ", state->rkey_array[hash]); + } + // else opts->dmr_mute_encR = 1; //may cause issues for manual key entry (non-csv) } - } - else if ((state->synctype == 6) || (state->synctype == 7)) - { - mbe_processAmbe3600x2400Framef (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, ambe_fr, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); + + if ( (state->K > 0 && state->dmr_soR & 0x40 && state->payload_keyidR == 0 && state->dmr_fidR == 0x10) || + (state->K > 0 && state->M == 1) ) + { + k = Pr[state->K]; + k = ( ((k & 0xFF0F) << 32 ) + (k << 16) + k ); + for (short int j = 0; j < 48; j++) + { + x = ( ((k << j) & 0x800000000000) >> 47 ); + ambe_d[j] ^= x; + } + } + + if ( (state->K1 > 0 && state->dmr_soR & 0x40 && state->payload_keyidR == 0 && state->dmr_fidR == 0x68) || + (state->K1 > 0 && state->M == 1)) + { + + int pos = 0; + + unsigned long long int k1 = state->K1; + unsigned long long int k2 = state->K2; + unsigned long long int k3 = state->K3; + unsigned long long int k4 = state->K4; + + int T_Key[256] = {0}; + int pN[882] = {0}; + + int len = 0; + + if (k2 == 0) + { + len = 39; + k1 = k1 << 24; + } + if (k2 != 0) + { + len = 127; + } + if (k4 != 0) + { + len = 255; + } + + for (i = 0; i < 64; i++) + { + T_Key[i] = ( ((k1 << i) & 0x8000000000000000) >> 63 ); + T_Key[i+64] = ( ((k2 << i) & 0x8000000000000000) >> 63 ); + T_Key[i+128] = ( ((k3 << i) & 0x8000000000000000) >> 63 ); + T_Key[i+192] = ( ((k4 << i) & 0x8000000000000000) >> 63 ); + } + + for (i = 0; i < 882; i++) + { + pN[i] = T_Key[pos]; + pos++; + if (pos > len) + { + pos = 0; + } + } + + //sanity check + if (state->DMRvcR > 17) //18 + { + state->DMRvcR = 17; //18 + } + + pos = state->DMRvcR * 49; + for(i = 0; i < 49; i++) + { + ambe_d[i] ^= pN[pos]; + pos++; + } + state->DMRvcR++; + } + + //DMR RC4, Slot 2 + if (state->currentslot == 1 && state->payload_algidR == 0x21 && state->RR != 0) + { + uint8_t cipher[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t plain[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t rckey[9] = {0x00, 0x00, 0x00, 0x00, 0x00, // <- RC4 Key + 0x00, 0x00, 0x00, 0x00}; // <- MI + + //easier to manually load up rather than make a loop + rckey[0] = ((state->RR & 0xFF00000000) >> 32); + rckey[1] = ((state->RR & 0xFF000000) >> 24); + rckey[2] = ((state->RR & 0xFF0000) >> 16); + rckey[3] = ((state->RR & 0xFF00) >> 8); + rckey[4] = ((state->RR & 0xFF) >> 0); + rckey[5] = ((state->payload_miR & 0xFF000000) >> 24); + rckey[6] = ((state->payload_miR & 0xFF0000) >> 16); + rckey[7] = ((state->payload_miR & 0xFF00) >> 8); + rckey[8] = ((state->payload_miR & 0xFF) >> 0); + + // if (opts->payload == 1) + // { + // fprintf (stderr, "%s", KYEL); + // fprintf (stderr, " RC4K "); + // for (short o = 0; o < 9; o++) + // { + // fprintf (stderr, "%02X", rckey[o]); + // } + // fprintf (stderr, "%s", KNRM); + // fprintf (stderr, "\n"); + // } + + short k = 0; + for (short o = 0; o < 7; o++) + { + short b = 0; + for (short p = 0; p < 8; p++) + { + b = b << 1; + b = b + ambe_d[k]; + k++; + if (k == 49) + { + cipher[6] = ((b << 3) & 0x80); //set 7th octet/bit 49 accordingly + break; + } + } + cipher[o] = b; + } + + //only run keystream application if errs < 3 -- this is a fix to the pop sound + //that may occur on some systems that preempt VC6 voice for a RC opportuninity (TXI) + //this occurs because we are supposed to either have a a 'repeat' frame, or 'silent' frame play + //due to the error, but the keystream application makes it random 'pfft pop' sound instead + if (state->errsR < 3) + RC4(state->dropR, 9, 7, rckey, cipher, plain); + else memcpy (plain, cipher, sizeof(plain)); + state->dropR += 7; + + short z = 0; + for (short p = 0; p < 6; p++) + { + //convert bytes back to bits and load into ambe_d array. + short b = 0; //reset b to use again + for (short o = 0; o < 8; o++) + { + b = (( (plain[p] << o) & 0x80) >> 7); + ambe_d[z] = b; + z++; + if (z == 49) + { + ambe_d[48] = ( (plain[p] << o) & 0x80); + break; + } + } + } + } + + //P25p2 RC4 Handling, VCH 1 + if (state->currentslot == 1 && state->payload_algidR == 0xAA && state->RR != 0 && ((state->synctype == 35) || (state->synctype == 36))) + { + uint8_t cipher[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t plain[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t rckey[13] = {0x00, 0x00, 0x00, 0x00, 0x00, // <- RC4 Key + 0x00, 0x00, 0x00, 0x00, 0x00, // <- MI + 0x00, 0x00, 0x00}; // <- MI cont. + + //easier to manually load up rather than make a loop + rckey[0] = ((state->RR & 0xFF00000000) >> 32); + rckey[1] = ((state->RR & 0xFF000000) >> 24); + rckey[2] = ((state->RR & 0xFF0000) >> 16); + rckey[3] = ((state->RR & 0xFF00) >> 8); + rckey[4] = ((state->RR & 0xFF) >> 0); + + //state->payload_miN for VCH1/slot 2 + rckey[5] = ((state->payload_miN & 0xFF00000000000000) >> 56); + rckey[6] = ((state->payload_miN & 0xFF000000000000) >> 48); + rckey[7] = ((state->payload_miN & 0xFF0000000000) >> 40); + rckey[8] = ((state->payload_miN & 0xFF00000000) >> 32); + rckey[9] = ((state->payload_miN & 0xFF000000) >> 24); + rckey[10] = ((state->payload_miN & 0xFF0000) >> 16); + rckey[11] = ((state->payload_miN & 0xFF00) >> 8); + rckey[12] = ((state->payload_miN & 0xFF) >> 0); + + // if (opts->payload == 1) + // { + // fprintf (stderr, "%s", KYEL); + // fprintf (stderr, " RC4K "); + // for (short o = 0; o < 13; o++) + // { + // fprintf (stderr, "%02X", rckey[o]); + // } + // fprintf (stderr, "%s", KNRM); + // fprintf (stderr, "\n"); + // } + + short k = 0; + for (short o = 0; o < 7; o++) + { + short b = 0; + for (short p = 0; p < 8; p++) + { + b = b << 1; + b = b + ambe_d[k]; + k++; + if (k == 49) + { + cipher[6] = ((b << 3) & 0x80); //set 7th octet/bit 49 accordingly + break; + } + } + cipher[o] = b; + } + + RC4(state->dropR, 13, 7, rckey, cipher, plain); + state->dropR += 7; + + short z = 0; + for (short p = 0; p < 6; p++) + { + //convert bytes back to bits and load into ambe_d array. + short b = 0; //reset b to use again + for (short o = 0; o < 8; o++) + { + b = (( (plain[p] << o) & 0x80) >> 7); + ambe_d[z] = b; + z++; + if (z == 49) + { + ambe_d[48] = ( (plain[p] << o) & 0x80); + break; + } + } + } + } + + mbe_processAmbe2450Dataf (state->audio_out_temp_bufR, &state->errsR, &state->errs2R, state->err_strR, + ambe_d, state->cur_mp2, state->prev_mp2, state->prev_mp_enhanced2, opts->uvquality); + + //old method for this step below + //mbe_processAmbe3600x2450Framef (state->audio_out_temp_bufR, &state->errsR, &state->errs2R, state->err_strR, ambe_fr, ambe_d, state->cur_mp2, state->prev_mp2, state->prev_mp_enhanced2, opts->uvquality); if (opts->payload == 1) { PrintAMBEData (opts, state, ambe_d); } - if (opts->mbe_out_f != NULL) + + //restore MBE file save, slot 2 -- consider saving even if enc + if (opts->mbe_out_fR != NULL && (state->dmr_encR == 0 || opts->dmr_mute_encR == 0) ) { - saveAmbe2450Data (opts, state, ambe_d); + saveAmbe2450DataR (opts, state, ambe_d); } } - else if ((state->synctype == 28) || (state->synctype == 29)) //was 8 and 9 - { - state->errs = mbe_eccAmbe3600x2450C0 (ambe_fr); - //state->errs2 = state->errs; - mbe_demodulateAmbe3600x2450Data (ambe_fr); - state->errs2 = mbe_eccAmbe3600x2450Data (ambe_fr, ambe_d); - - if ( (state->nxdn_cipher_type == 0x01 && state->R > 0) || - (state->M == 1 && state->R > 0) ) - { - - if (state->payload_miN == 0) - { - state->payload_miN = state->R; - } - - char ambe_temp[49]; - for (short int i = 0; i < 49; i++) - { - ambe_temp[i] = ambe_d[i]; - ambe_d[i] = 0; - } - LFSRN(ambe_temp, ambe_d, state); - - } - - mbe_processAmbe2450Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, - ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); - - if (opts->payload == 1) - { - PrintAMBEData (opts, state, ambe_d); - } - - if (opts->mbe_out_f != NULL && (state->dmr_encL == 0 || opts->dmr_mute_encL == 0) ) - { - saveAmbe2450Data (opts, state, ambe_d); - } - - } - else - { - //stereo slots and slot 0 (left slot) - if (state->currentslot == 0) //&& opts->dmr_stereo == 1 - { - - state->errs = mbe_eccAmbe3600x2450C0 (ambe_fr); - //state->errs2 = state->errs; - mbe_demodulateAmbe3600x2450Data (ambe_fr); - state->errs2 = mbe_eccAmbe3600x2450Data (ambe_fr, ambe_d); - - //EXPERIMENTAL!! - //load basic privacy key number from array by the tg value (if not forced) - //currently only Moto BP and Hytera 10 Char BP - if (state->M == 0 && state->payload_algid == 0) - { - //see if we need to hash a value larger than 16-bits - hash = state->lasttg & 0xFFFFFF; - // fprintf (stderr, "TG: %lld Hash: %ld ", state->lasttg, hash); - if (hash > 0xFFFF) //if greater than 16-bits - { - for (int i = 0; i < 24; i++) - { - hash_bits[i] = ((hash << i) & 0x800000) >> 23; //load into array for CRC16 - } - hash = ComputeCrcCCITT16d (hash_bits, 24); - hash = hash & 0xFFFF; //make sure its no larger than 16-bits - // fprintf (stderr, "Hash: %d ", hash); - } - if (state->rkey_array[hash] != 0) - { - state->K = state->rkey_array[hash] & 0xFF; //doesn't exceed 255 - state->K1 = state->H = state->rkey_array[hash] & 0xFFFFFFFFFF; //doesn't exceed 40-bit limit - opts->dmr_mute_encL = 0; - // fprintf (stderr, "Key: %X ", state->rkey_array[hash]); - } - // else opts->dmr_mute_encL = 1; //may cause issues for manual key entry (non-csv) - } - - if ( (state->K > 0 && state->dmr_so & 0x40 && state->payload_keyid == 0 && state->dmr_fid == 0x10) || - (state->K > 0 && state->M == 1) ) - { - k = Pr[state->K]; - k = ( ((k & 0xFF0F) << 32 ) + (k << 16) + k ); - for (short int j = 0; j < 48; j++) //49 - { - x = ( ((k << j) & 0x800000000000) >> 47 ); - ambe_d[j] ^= x; - } - } - - if ( (state->K1 > 0 && state->dmr_so & 0x40 && state->payload_keyid == 0 && state->dmr_fid == 0x68) || - (state->K1 > 0 && state->M == 1) ) - { - - int pos = 0; - - unsigned long long int k1 = state->K1; - unsigned long long int k2 = state->K2; - unsigned long long int k3 = state->K3; - unsigned long long int k4 = state->K4; - - int T_Key[256] = {0}; - int pN[882] = {0}; - - int len = 0; - - if (k2 == 0) - { - len = 39; - k1 = k1 << 24; - } - if (k2 != 0) - { - len = 127; - } - if (k4 != 0) - { - len = 255; - } - - for (i = 0; i < 64; i++) - { - T_Key[i] = ( ((k1 << i) & 0x8000000000000000) >> 63 ); - T_Key[i+64] = ( ((k2 << i) & 0x8000000000000000) >> 63 ); - T_Key[i+128] = ( ((k3 << i) & 0x8000000000000000) >> 63 ); - T_Key[i+192] = ( ((k4 << i) & 0x8000000000000000) >> 63 ); - } - - for (i = 0; i < 882; i++) - { - pN[i] = T_Key[pos]; - pos++; - if (pos > len) - { - pos = 0; - } - } - - //sanity check - if (state->DMRvcL > 17) //18 - { - state->DMRvcL = 17; //18 - } - - pos = state->DMRvcL * 49; - for(i = 0; i < 49; i++) - { - ambe_d[i] ^= pN[pos]; - pos++; - } - state->DMRvcL++; - } - - //DMR RC4, Slot 1 - if (state->currentslot == 0 && state->payload_algid == 0x21 && state->R != 0) - { - uint8_t cipher[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t plain[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t rckey[9] = {0x00, 0x00, 0x00, 0x00, 0x00, // <- RC4 Key - 0x00, 0x00, 0x00, 0x00}; // <- MI - - //easier to manually load up rather than make a loop - rckey[0] = ((state->R & 0xFF00000000) >> 32); - rckey[1] = ((state->R & 0xFF000000) >> 24); - rckey[2] = ((state->R & 0xFF0000) >> 16); - rckey[3] = ((state->R & 0xFF00) >> 8); - rckey[4] = ((state->R & 0xFF) >> 0); - rckey[5] = ((state->payload_mi & 0xFF000000) >> 24); - rckey[6] = ((state->payload_mi & 0xFF0000) >> 16); - rckey[7] = ((state->payload_mi & 0xFF00) >> 8); - rckey[8] = ((state->payload_mi & 0xFF) >> 0); - - // if (opts->payload == 1) - // { - // fprintf (stderr, "%s", KYEL); - // fprintf (stderr, " RC4K "); - // for (short o = 0; o < 9; o++) - // { - // fprintf (stderr, "%02X", rckey[o]); - // } - // fprintf (stderr, "%s", KNRM); - // fprintf (stderr, "\n"); - // } - - short k = 0; - for (short o = 0; o < 7; o++) - { - short b = 0; - for (short p = 0; p < 8; p++) - { - b = b << 1; - b = b + ambe_d[k]; - k++; - if (k == 49) - { - cipher[6] = ((b << 3) & 0x80); //set 7th octet/bit 49 accordingly - break; - } - } - cipher[o] = b; - } - - RC4(state->dropL, 9, 7, rckey, cipher, plain); - state->dropL += 7; - - short z = 0; - for (short p = 0; p < 6; p++) - { - //convert bytes back to bits and load into ambe_d array. - short b = 0; //reset b to use again - for (short o = 0; o < 8; o++) - { - b = (( (plain[p] << o) & 0x80) >> 7); - ambe_d[z] = b; - z++; - if (z == 49) - { - ambe_d[48] = ( (plain[p] << o) & 0x80); - break; - } - } - } - } - - //P25p2 RC4 Handling, VCH 0 - if (state->currentslot == 0 && state->payload_algid == 0xAA && state->R != 0 && ((state->synctype == 35) || (state->synctype == 36))) - { - uint8_t cipher[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t plain[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t rckey[13] = {0x00, 0x00, 0x00, 0x00, 0x00, // <- RC4 Key - 0x00, 0x00, 0x00, 0x00, 0x00, // <- MI - 0x00, 0x00, 0x00}; // <- MI cont. - - //easier to manually load up rather than make a loop - rckey[0] = ((state->R & 0xFF00000000) >> 32); - rckey[1] = ((state->R & 0xFF000000) >> 24); - rckey[2] = ((state->R & 0xFF0000) >> 16); - rckey[3] = ((state->R & 0xFF00) >> 8); - rckey[4] = ((state->R & 0xFF) >> 0); - - // load valid MI from state->payload_miP - rckey[5] = ((state->payload_miP & 0xFF00000000000000) >> 56); - rckey[6] = ((state->payload_miP & 0xFF000000000000) >> 48); - rckey[7] = ((state->payload_miP & 0xFF0000000000) >> 40); - rckey[8] = ((state->payload_miP & 0xFF00000000) >> 32); - rckey[9] = ((state->payload_miP & 0xFF000000) >> 24); - rckey[10] = ((state->payload_miP & 0xFF0000) >> 16); - rckey[11] = ((state->payload_miP & 0xFF00) >> 8); - rckey[12] = ((state->payload_miP & 0xFF) >> 0); - - // if (opts->payload == 1) - // { - // fprintf (stderr, "%s", KYEL); - // fprintf (stderr, " RC4K "); - // for (short o = 0; o < 13; o++) - // { - // fprintf (stderr, "%02X", rckey[o]); - // } - // fprintf (stderr, "%s", KNRM); - // fprintf (stderr, "\n"); - // } - - short k = 0; - for (short o = 0; o < 7; o++) - { - short b = 0; - for (short p = 0; p < 8; p++) - { - b = b << 1; - b = b + ambe_d[k]; - k++; - if (k == 49) - { - cipher[6] = ((b << 3) & 0x80); //set 7th octet/bit 49 accordingly - break; - } - } - cipher[o] = b; - } - - RC4(state->dropL, 13, 7, rckey, cipher, plain); - state->dropL += 7; - - short z = 0; - for (short p = 0; p < 6; p++) - { - //convert bytes back to bits and load into ambe_d array. - short b = 0; //reset b to use again - for (short o = 0; o < 8; o++) - { - b = (( (plain[p] << o) & 0x80) >> 7); - ambe_d[z] = b; - z++; - if (z == 49) - { - ambe_d[48] = ( (plain[p] << o) & 0x80); - break; - } - } - } - } - - mbe_processAmbe2450Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, - ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); - - - //old method for this step below - //mbe_processAmbe3600x2450Framef (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, ambe_fr, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); - if (opts->payload == 1) // && state->R == 0 this is why slot 1 didn't primt abme, probably had it set during testing - { - PrintAMBEData (opts, state, ambe_d); - } - - //restore MBE file save, slot 1 -- consider saving even if enc - if (opts->mbe_out_f != NULL && (state->dmr_encL == 0 || opts->dmr_mute_encL == 0) ) - { - saveAmbe2450Data (opts, state, ambe_d); - } - - } - //stereo slots and slot 1 (right slot) - if (state->currentslot == 1) //&& opts->dmr_stereo == 1 - { - - state->errsR = mbe_eccAmbe3600x2450C0 (ambe_fr); - //state->errs2R = state->errsR; - mbe_demodulateAmbe3600x2450Data (ambe_fr); - state->errs2R = mbe_eccAmbe3600x2450Data (ambe_fr, ambe_d); - - //EXPERIMENTAL!! - //load basic privacy key number from array by the tg value (if not forced) - //currently only Moto BP and Hytera 10 Char BP - if (state->M == 0 && state->payload_algidR == 0) - { - //see if we need to hash a value larger than 16-bits - hash = state->lasttgR & 0xFFFFFF; - // fprintf (stderr, "TG: %lld Hash: %ld ", state->lasttgR, hash); - if (hash > 0xFFFF) //if greater than 16-bits - { - for (int i = 0; i < 24; i++) - { - hash_bits[i] = ((hash << i) & 0x800000) >> 23; //load into array for CRC16 - } - hash = ComputeCrcCCITT16d (hash_bits, 24); - hash = hash & 0xFFFF; //make sure its no larger than 16-bits - // fprintf (stderr, "Hash: %d ", hash); - } - if (state->rkey_array[hash] != 0) - { - state->K = state->rkey_array[hash] & 0xFF; //doesn't exceed 255 - state->K1 = state->H = state->rkey_array[hash] & 0xFFFFFFFFFF; //doesn't exceed 40-bit limit - opts->dmr_mute_encR = 0; - // fprintf (stderr, "Key: %X ", state->rkey_array[hash]); - } - // else opts->dmr_mute_encR = 1; //may cause issues for manual key entry (non-csv) - } - - if ( (state->K > 0 && state->dmr_soR & 0x40 && state->payload_keyidR == 0 && state->dmr_fidR == 0x10) || - (state->K > 0 && state->M == 1) ) - { - k = Pr[state->K]; - k = ( ((k & 0xFF0F) << 32 ) + (k << 16) + k ); - for (short int j = 0; j < 48; j++) - { - x = ( ((k << j) & 0x800000000000) >> 47 ); - ambe_d[j] ^= x; - } - } - - if ( (state->K1 > 0 && state->dmr_soR & 0x40 && state->payload_keyidR == 0 && state->dmr_fidR == 0x68) || - (state->K1 > 0 && state->M == 1)) - { - - int pos = 0; - - unsigned long long int k1 = state->K1; - unsigned long long int k2 = state->K2; - unsigned long long int k3 = state->K3; - unsigned long long int k4 = state->K4; - - int T_Key[256] = {0}; - int pN[882] = {0}; - - int len = 0; - - if (k2 == 0) - { - len = 39; - k1 = k1 << 24; - } - if (k2 != 0) - { - len = 127; - } - if (k4 != 0) - { - len = 255; - } - - for (i = 0; i < 64; i++) - { - T_Key[i] = ( ((k1 << i) & 0x8000000000000000) >> 63 ); - T_Key[i+64] = ( ((k2 << i) & 0x8000000000000000) >> 63 ); - T_Key[i+128] = ( ((k3 << i) & 0x8000000000000000) >> 63 ); - T_Key[i+192] = ( ((k4 << i) & 0x8000000000000000) >> 63 ); - } - - for (i = 0; i < 882; i++) - { - pN[i] = T_Key[pos]; - pos++; - if (pos > len) - { - pos = 0; - } - } - - //sanity check - if (state->DMRvcR > 17) //18 - { - state->DMRvcR = 17; //18 - } - - pos = state->DMRvcR * 49; - for(i = 0; i < 49; i++) - { - ambe_d[i] ^= pN[pos]; - pos++; - } - state->DMRvcR++; - } - - //DMR RC4, Slot 2 - if (state->currentslot == 1 && state->payload_algidR == 0x21 && state->RR != 0) - { - uint8_t cipher[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t plain[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t rckey[9] = {0x00, 0x00, 0x00, 0x00, 0x00, // <- RC4 Key - 0x00, 0x00, 0x00, 0x00}; // <- MI - - //easier to manually load up rather than make a loop - rckey[0] = ((state->RR & 0xFF00000000) >> 32); - rckey[1] = ((state->RR & 0xFF000000) >> 24); - rckey[2] = ((state->RR & 0xFF0000) >> 16); - rckey[3] = ((state->RR & 0xFF00) >> 8); - rckey[4] = ((state->RR & 0xFF) >> 0); - rckey[5] = ((state->payload_miR & 0xFF000000) >> 24); - rckey[6] = ((state->payload_miR & 0xFF0000) >> 16); - rckey[7] = ((state->payload_miR & 0xFF00) >> 8); - rckey[8] = ((state->payload_miR & 0xFF) >> 0); - - // if (opts->payload == 1) - // { - // fprintf (stderr, "%s", KYEL); - // fprintf (stderr, " RC4K "); - // for (short o = 0; o < 9; o++) - // { - // fprintf (stderr, "%02X", rckey[o]); - // } - // fprintf (stderr, "%s", KNRM); - // fprintf (stderr, "\n"); - // } - - short k = 0; - for (short o = 0; o < 7; o++) - { - short b = 0; - for (short p = 0; p < 8; p++) - { - b = b << 1; - b = b + ambe_d[k]; - k++; - if (k == 49) - { - cipher[6] = ((b << 3) & 0x80); //set 7th octet/bit 49 accordingly - break; - } - } - cipher[o] = b; - } - - RC4(state->dropR, 9, 7, rckey, cipher, plain); - state->dropR += 7; - - short z = 0; - for (short p = 0; p < 6; p++) - { - //convert bytes back to bits and load into ambe_d array. - short b = 0; //reset b to use again - for (short o = 0; o < 8; o++) - { - b = (( (plain[p] << o) & 0x80) >> 7); - ambe_d[z] = b; - z++; - if (z == 49) - { - ambe_d[48] = ( (plain[p] << o) & 0x80); - break; - } - } - } - } - - //P25p2 RC4 Handling, VCH 1 - if (state->currentslot == 1 && state->payload_algidR == 0xAA && state->RR != 0 && ((state->synctype == 35) || (state->synctype == 36))) - { - uint8_t cipher[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t plain[7] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - uint8_t rckey[13] = {0x00, 0x00, 0x00, 0x00, 0x00, // <- RC4 Key - 0x00, 0x00, 0x00, 0x00, 0x00, // <- MI - 0x00, 0x00, 0x00}; // <- MI cont. - - //easier to manually load up rather than make a loop - rckey[0] = ((state->RR & 0xFF00000000) >> 32); - rckey[1] = ((state->RR & 0xFF000000) >> 24); - rckey[2] = ((state->RR & 0xFF0000) >> 16); - rckey[3] = ((state->RR & 0xFF00) >> 8); - rckey[4] = ((state->RR & 0xFF) >> 0); - - //state->payload_miN for VCH1/slot 2 - rckey[5] = ((state->payload_miN & 0xFF00000000000000) >> 56); - rckey[6] = ((state->payload_miN & 0xFF000000000000) >> 48); - rckey[7] = ((state->payload_miN & 0xFF0000000000) >> 40); - rckey[8] = ((state->payload_miN & 0xFF00000000) >> 32); - rckey[9] = ((state->payload_miN & 0xFF000000) >> 24); - rckey[10] = ((state->payload_miN & 0xFF0000) >> 16); - rckey[11] = ((state->payload_miN & 0xFF00) >> 8); - rckey[12] = ((state->payload_miN & 0xFF) >> 0); - - // if (opts->payload == 1) - // { - // fprintf (stderr, "%s", KYEL); - // fprintf (stderr, " RC4K "); - // for (short o = 0; o < 13; o++) - // { - // fprintf (stderr, "%02X", rckey[o]); - // } - // fprintf (stderr, "%s", KNRM); - // fprintf (stderr, "\n"); - // } - - short k = 0; - for (short o = 0; o < 7; o++) - { - short b = 0; - for (short p = 0; p < 8; p++) - { - b = b << 1; - b = b + ambe_d[k]; - k++; - if (k == 49) - { - cipher[6] = ((b << 3) & 0x80); //set 7th octet/bit 49 accordingly - break; - } - } - cipher[o] = b; - } - - RC4(state->dropR, 13, 7, rckey, cipher, plain); - state->dropR += 7; - - short z = 0; - for (short p = 0; p < 6; p++) - { - //convert bytes back to bits and load into ambe_d array. - short b = 0; //reset b to use again - for (short o = 0; o < 8; o++) - { - b = (( (plain[p] << o) & 0x80) >> 7); - ambe_d[z] = b; - z++; - if (z == 49) - { - ambe_d[48] = ( (plain[p] << o) & 0x80); - break; - } - } - } - } - - mbe_processAmbe2450Dataf (state->audio_out_temp_bufR, &state->errsR, &state->errs2R, state->err_strR, - ambe_d, state->cur_mp2, state->prev_mp2, state->prev_mp_enhanced2, opts->uvquality); - - //old method for this step below - //mbe_processAmbe3600x2450Framef (state->audio_out_temp_bufR, &state->errsR, &state->errs2R, state->err_strR, ambe_fr, ambe_d, state->cur_mp2, state->prev_mp2, state->prev_mp_enhanced2, opts->uvquality); - if (opts->payload == 1) - { - PrintAMBEData (opts, state, ambe_d); - } - - //restore MBE file save, slot 2 -- consider saving even if enc - if (opts->mbe_out_fR != NULL && (state->dmr_encR == 0 || opts->dmr_mute_encR == 0) ) - { - saveAmbe2450DataR (opts, state, ambe_d); - } - } - - //X2-TDMA? Not sure what still makes it this far to run under Framef - // if (opts->dmr_stereo == 0) - // { - // mbe_processAmbe3600x2450Framef (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, ambe_fr, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); - // if (opts->payload == 1) - // { - // PrintAMBEData (opts, state, ambe_d); - // } - // //only save MBE files if not enc or unmuted, THIS does not seem to work for some reason - // if (opts->mbe_out_f != NULL && (opts->unmute_encrypted_p25 == 1 || state->dmr_encL == 0) ) - // { - // saveAmbe2450Data (opts, state, ambe_d); - // } - // } - - - } + //X2-TDMA? Not sure what still makes it this far to run under Framef + // if (opts->dmr_stereo == 0) + // { + // mbe_processAmbe3600x2450Framef (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, ambe_fr, ambe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); + // if (opts->payload == 1) + // { + // PrintAMBEData (opts, state, ambe_d); + // } + // //only save MBE files if not enc or unmuted, THIS does not seem to work for some reason + // if (opts->mbe_out_f != NULL && (opts->unmute_encrypted_p25 == 1 || state->dmr_encL == 0) ) + // { + // saveAmbe2450Data (opts, state, ambe_d); + // } + // } + + + } //quick enc check to determine whether or not to play enc traffic int enc_bit = 0; @@ -999,23 +1011,23 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a } //checkdown for P25 1 and 2 - else if (state->payload_algid != 0 && state->payload_algid != 0x80) - { - state->dmr_encL = 1; - } + else if (state->payload_algid != 0 && state->payload_algid != 0x80) + { + state->dmr_encL = 1; + } else state->dmr_encL = 0; //check for available R key if (state->R != 0) state->dmr_encL = 0; //second checkdown for P25p2 WACN, SYSID, and CC set - if (state->synctype == 35 || state->synctype == 36) - { - if (state->p2_wacn == 0 || state->p2_sysid == 0 || state->p2_cc == 0) - { - state->dmr_encL = 1; - } - } + if (state->synctype == 35 || state->synctype == 36) + { + if (state->p2_wacn == 0 || state->p2_sysid == 0 || state->p2_cc == 0) + { + state->dmr_encL = 1; + } + } //reverse mute testing, only mute unencrypted traffic (slave piggyback dsd+ method) if (opts->reverse_mute == 1) @@ -1069,23 +1081,23 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a } //checkdown for P25 1 and 2 - else if (state->payload_algidR != 0 && state->payload_algidR != 0x80) - { - state->dmr_encR = 1; - } + else if (state->payload_algidR != 0 && state->payload_algidR != 0x80) + { + state->dmr_encR = 1; + } else state->dmr_encR = 0; //check for available RR key if (state->RR != 0) state->dmr_encR = 0; //second checkdown for P25p2 WACN, SYSID, and CC set - if (state->synctype == 35 || state->synctype == 36) - { - if (state->p2_wacn == 0 || state->p2_sysid == 0 || state->p2_cc == 0) - { - state->dmr_encR = 1; - } - } + if (state->synctype == 35 || state->synctype == 36) + { + if (state->p2_wacn == 0 || state->p2_sysid == 0 || state->p2_cc == 0) + { + state->dmr_encR = 1; + } + } //reverse mute testing, only mute unencrypted traffic (slave piggyback dsd+ method) if (opts->reverse_mute == 1) @@ -1150,25 +1162,25 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a writeSynthesizedVoice (opts, state); } - //per call can only be used when ncurses terminal is active since we use its call history matrix for when to record - if (opts->dmr_stereo_wav == 1 && opts->dmr_stereo == 1 && state->currentslot == 0) //opts->use_ncurses_terminal == 1 && - { + //per call can only be used when ncurses terminal is active since we use its call history matrix for when to record + if (opts->dmr_stereo_wav == 1 && opts->dmr_stereo == 1 && state->currentslot == 0) //opts->use_ncurses_terminal == 1 && + { if (state->dmr_encL == 0 || opts->dmr_mute_encL == 0) { - //write wav to per call on left channel Slot 1 - writeSynthesizedVoice (opts, state); + //write wav to per call on left channel Slot 1 + writeSynthesizedVoice (opts, state); } } - //per call can only be used when ncurses terminal is active since we use its call history matrix for when to record - if (opts->dmr_stereo_wav == 1 && opts->dmr_stereo == 1 && state->currentslot == 1) //opts->use_ncurses_terminal == 1 && - { + //per call can only be used when ncurses terminal is active since we use its call history matrix for when to record + if (opts->dmr_stereo_wav == 1 && opts->dmr_stereo == 1 && state->currentslot == 1) //opts->use_ncurses_terminal == 1 && + { if (state->dmr_encR == 0 || opts->dmr_mute_encR == 0) { - //write wav to per call on right channel Slot 2 - writeSynthesizedVoiceR (opts, state); + //write wav to per call on right channel Slot 2 + writeSynthesizedVoiceR (opts, state); } - } + } if (preempt == 1) { From 56b0e8440e480b649d7f737b80494d1ca354a3ab Mon Sep 17 00:00:00 2001 From: lwvmobile Date: Sat, 17 Jun 2023 17:32:59 -0400 Subject: [PATCH 3/7] Initialize/Zero Some Arrays; --- src/dmr_bs.c | 8 ++++++++ src/dmr_dburst.c | 7 +++++++ src/dmr_ms.c | 12 ++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/dmr_bs.c b/src/dmr_bs.c index 99045fb..04ace0c 100644 --- a/src/dmr_bs.c +++ b/src/dmr_bs.c @@ -96,6 +96,10 @@ void dmrBS (dsd_opts * opts, dsd_state * state) //Run Loop while the getting is good while (loop == 1) { + memset (ambe_fr, 0, sizeof(ambe_fr)); + memset (ambe_fr2, 0, sizeof(ambe_fr2)); + memset (ambe_fr3, 0, sizeof(ambe_fr3)); + internalslot = -1; //reset here so we know if this value is being set properly for(i = 0; i < 12; i++) { @@ -494,6 +498,10 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state) char ambe_fr2[4][24]; char ambe_fr3[4][24]; + memset (ambe_fr, 0, sizeof(ambe_fr)); + memset (ambe_fr2, 0, sizeof(ambe_fr2)); + memset (ambe_fr3, 0, sizeof(ambe_fr3)); + //memcpy of ambe_fr for late entry char m1[4][24]; char m2[4][24]; diff --git a/src/dmr_dburst.c b/src/dmr_dburst.c index 1488dc7..6248289 100644 --- a/src/dmr_dburst.c +++ b/src/dmr_dburst.c @@ -45,6 +45,13 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 uint8_t LC_DataBytes[10]; int Burst = -1; + memset (BPTCDeInteleavedData, 0, sizeof(BPTCDeInteleavedData)); + memset (BPTCDmrDataBit, 0, sizeof(BPTCDmrDataBit)); + memset (BPTCDmrDataByte, 0, sizeof(BPTCDmrDataByte)); + memset (BptcDataMatrix, 0, sizeof(BptcDataMatrix)); + memset (LC_DataBit, 0, sizeof(LC_DataBit)); + memset (LC_DataBytes, 0, sizeof(LC_DataBytes)); + //PDU Bytes and Bits uint8_t DMR_PDU[25]; uint8_t DMR_PDU_bits[196]; diff --git a/src/dmr_ms.c b/src/dmr_ms.c index 2fe6556..9a82b03 100644 --- a/src/dmr_ms.c +++ b/src/dmr_ms.c @@ -87,7 +87,11 @@ void dmrMS (dsd_opts * opts, dsd_state * state) //so getDibit doesn't know to invert it before it gets here for (j = 0; j < 6; j++) { - state->dmrburstL = 16; + state->dmrburstL = 16; + + memset (ambe_fr, 0, sizeof(ambe_fr)); + memset (ambe_fr2, 0, sizeof(ambe_fr2)); + memset (ambe_fr3, 0, sizeof(ambe_fr3)); for(i = 0; i < 12; i++) { @@ -370,7 +374,11 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state) char ambe_fr[4][24]; char ambe_fr2[4][24]; char ambe_fr3[4][24]; - char ambe_fr4[4][24]; //shim for crappy tdma direct, need more samples to see if this is really a necessary shim or not + char ambe_fr4[4][24]; + + memset (ambe_fr, 0, sizeof(ambe_fr)); + memset (ambe_fr2, 0, sizeof(ambe_fr2)); + memset (ambe_fr3, 0, sizeof(ambe_fr3)); //memcpy of ambe_fr for late entry char m1[4][24]; From a5d73f06d285108c9de59bd5419731e18f9bc6c6 Mon Sep 17 00:00:00 2001 From: lwvmobile Date: Sun, 18 Jun 2023 19:54:18 -0400 Subject: [PATCH 4/7] DMR - SB TXI Information and ENC Identifiers Fix; --- include/dsd.h | 2 + src/dmr_flco.c | 27 +++++++++- src/dmr_le.c | 138 ++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 135 insertions(+), 32 deletions(-) diff --git a/include/dsd.h b/include/dsd.h index f35a931..d71a8b7 100644 --- a/include/dsd.h +++ b/include/dsd.h @@ -1013,7 +1013,9 @@ void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power); bool Hamming17123(uint8_t* d); uint8_t crc8(uint8_t bits[], unsigned int len); bool crc8_ok(uint8_t bits[], unsigned int len); +//modified CRC functions for SB/RC uint8_t crc7(uint8_t bits[], unsigned int len); +uint8_t crc3(uint8_t bits[], unsigned int len); //LFSR and LFSRP code courtesy of https://github.com/mattames/LFSR/ void LFSR(dsd_state * state); diff --git a/src/dmr_flco.c b/src/dmr_flco.c index f684960..7e4cb6f 100644 --- a/src/dmr_flco.c +++ b/src/dmr_flco.c @@ -433,6 +433,8 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C } else { + //Observation: If RS3 is set, or just the bit at location 0001 0000, + //then the NEXT VC6 will be pre-empted for TXI //REMUS! Uncomment Line Below if desired // strcat (state->call_string[slot], " RES"); fprintf(stderr, "RS%d ", (so & 0x30) >> 4); @@ -512,14 +514,35 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C } } - if (state->K != 0 && fid == 0x10 && so & 0x40) + //BUGFIX: Include slot and algid so we don't accidentally print more than one loaded key + //this can happen on Missing PI header and LE when the keyloader has loaded a TG/Hash key and an RC4 key simultandeously + //subsequennt EMB would print two key values until call cleared out + + if (state->K != 0 && fid == 0x10 && so & 0x40 && slot == 0 && state->payload_algid == 0) + { + fprintf (stderr, "%s", KYEL); + fprintf (stderr, "Key %lld ", state->K); + fprintf (stderr, "%s ", KNRM); + } + + if (state->K != 0 && fid == 0x10 && so & 0x40 && slot == 1 && state->payload_algidR == 0) { fprintf (stderr, "%s", KYEL); fprintf (stderr, "Key %lld ", state->K); fprintf (stderr, "%s ", KNRM); } - if (state->K1 != 0 && fid == 0x68 && so & 0x40) + if (state->K1 != 0 && fid == 0x68 && so & 0x40 && slot == 0 && state->payload_algid == 0) + { + if (state->K2 != 0) fprintf (stderr, "\n "); + fprintf (stderr, "%s", KYEL); + fprintf (stderr, "Key %010llX ", state->K1); + if (state->K2 != 0) fprintf (stderr, "%016llX ", state->K2); + if (state->K4 != 0) fprintf (stderr, "%016llX %016llX", state->K3, state->K4); + fprintf (stderr, "%s ", KNRM); + } + + if (state->K1 != 0 && fid == 0x68 && so & 0x40 && slot == 1 && state->payload_algidR == 0) { if (state->K2 != 0) fprintf (stderr, "\n "); fprintf (stderr, "%s", KYEL); diff --git a/src/dmr_le.c b/src/dmr_le.c index 535fe27..401e1ee 100644 --- a/src/dmr_le.c +++ b/src/dmr_le.c @@ -178,13 +178,24 @@ void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power) uint8_t slot = state->currentslot; uint8_t sbrc_interleaved[32]; uint8_t sbrc_return[32]; + uint8_t sbrc_retcrc[32]; //crc significant bits of the return for SB memset (sbrc_interleaved, 0, sizeof(sbrc_interleaved)); memset (sbrc_return, 0, sizeof(sbrc_return)); + memset (sbrc_retcrc, 0, sizeof(sbrc_retcrc)); uint32_t irr_err = 0; uint32_t sbrc_hex = 0; uint16_t crc_extracted = 7777; uint16_t crc_computed = 9999; - uint8_t crc_okay = 0; + uint8_t crc7_okay = 0; //RC + uint8_t crc3_okay = 0; //TXI + uint8_t txi = 0; //SEE: https://patents.google.com/patent/US8271009B2 + + //NOTE: Any previous mentions to Cap+ in this area may have been in error, + //The signalling observed here was actually TXI information, not Cap+ Specifically + + //check to see if this a TXI system + if (slot == 0 && state->dmr_so & 0x20) txi = 1; + if (slot == 1 && state->dmr_soR & 0x20) txi = 1; // 9.3.2 Pre-emption and power control Indicator (PI) // 0 - The embedded signalling carries information associated to the same logical channel or the Null embedded message @@ -198,8 +209,11 @@ void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power) //bad emb burst, never set a valid power indicator value (probably 9) if (power > 1) goto SBRC_END; + //arrange the return for proper order for the crc3 check + for (i = 0; i < 8; i++) sbrc_retcrc[i] = sbrc_return[i+3]; + //RC Channel CRC 7 Mask = 0x7A; CRC bits are used as privacy indicators on - //Single Voice Burst F (see below), other moto values seem to exist there as well + //Single Voice Burst F (see below), other moto values seem to exist there as well -- See TXI patent if (power == 1) //RC { crc_extracted = 0; @@ -209,15 +223,27 @@ void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power) crc_extracted = crc_extracted | sbrc_return[i+4]; } crc_extracted = crc_extracted ^ 0x7A; - crc_computed = crc7((uint8_t *) sbrc_return, 11); - if (crc_extracted == crc_computed) crc_okay = 1; + crc_computed = crc7((uint8_t *) sbrc_return, 7); + if (crc_extracted == crc_computed) crc7_okay = 1; } - else crc_okay = 1; //SB + else //if (txi == 1) //if TXI -- but TXI systems also carry the non-crc protected ENC identifiers + { + crc_extracted = 0; + for (i = 0; i < 3; i++) + { + crc_extracted = crc_extracted << 1; + crc_extracted = crc_extracted | sbrc_return[i]; //first 3 most significant bits + } + crc_computed = crc3((uint8_t *) sbrc_retcrc, 8); //working now seems consistent as well + if (crc_extracted == crc_computed) crc3_okay = 1; + // fprintf (stderr, " CRC EXT %02X, CRC CMP %02X", crc_extracted, crc_computed); + } + // else //crc_okay = 0; //CRC invalid / not available when is ENC Identifiers (I really hate that) for(i = 0; i < 11; i++) { sbrc_hex = sbrc_hex << 1; - sbrc_hex |= sbrc_return[i] & 1; //sbrc_return + sbrc_hex |= sbrc_return[i] & 1; } if (opts->payload == 1) //hide the sb/rc behind the payload printer, won't be useful to most people @@ -227,48 +253,76 @@ void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power) if (power == 1) fprintf (stderr, " RC: "); for(i = 0; i < 11; i++) fprintf (stderr, "%d", sbrc_return[i]); - fprintf (stderr, " - %03X", sbrc_hex); - fprintf (stderr, "\n"); + fprintf (stderr, " - %03X; ", sbrc_hex); fprintf (stderr, "%s", KNRM); - - if (crc_okay == 0) - { - fprintf (stderr, "%s", KRED); - fprintf (stderr, " (CRC ERR)"); - fprintf (stderr, "%s", KNRM); - fprintf (stderr, " CRC EXT %02X, CRC CMP %02X", crc_extracted, crc_computed); - } - } - uint8_t sbrc_opcode = sbrc_hex; + // if (crc_okay == 0) //forego this since the crc can vary or not be used at all + // { + // fprintf (stderr, "%s", KRED); + // fprintf (stderr, " (CRC ERR)"); + // fprintf (stderr, "%s", KNRM); + // fprintf (stderr, " CRC EXT %02X, CRC CMP %02X", crc_extracted, crc_computed); + // } + + fprintf (stderr, "\n"); + } + + uint8_t sbrc_opcode = sbrc_hex & 0x7; //opcode and alg the same bits, but the alg is present when CRC is bad (I know they are limited on bits, but I hate that idea) uint8_t alg = sbrc_hex & 0x7; uint8_t key = (sbrc_hex >> 3) & 0xFF; - uint8_t cap_site = (sbrc_hex >> 4) & 0x7; //signalling on Cap+ when voice errors (non voice VC6 is present) + uint8_t txi_delay = (sbrc_hex >> 3) & 0x1F; //middle five are the 'delay' value on a TXI system if (opts->dmr_le == 1) //this will now require a user to switch it on or off until more testing/figuring can be done { - if (irr_err != 0) ; //fprintf (stderr, "\n %s SLOT %d SB/RC (FEC ERR) %d %s \n", KRED, slot, irr_err, KNRM); + if (irr_err != 0) fprintf (stderr, "\n %s SLOT %d SB/RC (FEC ERR) %d %s \n", KRED, slot, irr_err, KNRM); if (irr_err == 0) { - if (sbrc_hex == 0) ; //NULL + if (sbrc_hex == 0) ; //NULL, do nothing + //else if (placeholder for future conditions) // { // placeholder for future conditions // } - else //Finally have a consistent set-up for this -- spoke too soon, sadly + + else if (crc7_okay == 1) { - //the signalling here is always presents on good voice frames, if errs are [3][2] then its not a VC6 voice frame, but some other 'hidden' frame - if (slot == 0 && state->errs < 3) + //do something with the reverse channel information + } + + //if the call is interruptable (TXI) and the crc3 is okay + else if (crc3_okay == 1) + { + //opcodes -- 0 (NULL), BR Delay (3) + fprintf (stderr, "\n"); + fprintf (stderr, " TXI Op: %X - ", sbrc_opcode); + if (sbrc_opcode == 0) fprintf (stderr, " Null; "); + else if (sbrc_opcode == 3) + { + if (txi_delay != 0) + fprintf (stderr, " BR Delay: %d - %d ms; ", txi_delay, txi_delay * 30); //could also indicate number of superframes until next VC6 pre-emption + else fprintf (stderr, "BR Delay: Irrelevant / Send at any time;"); + } + else fprintf (stderr, " Unk; "); + + if (opts->payload == 1) fprintf (stderr, "\n"); //only during payload + + } + + else //all that should be left in this field is the potential ENC identifiers + { + + if (slot == 0) //may not need the state->errs anymore //&& state->errs < 3 { if (state->dmr_so & 0x40 && key != 0 && state->payload_keyid == 0) { //if we aren't forcing a particular alg or privacy key set if (state->M == 0) { + fprintf (stderr, "\n"); fprintf (stderr, "%s ", KYEL); fprintf (stderr, " Slot 1"); fprintf (stderr, " DMR LE SB ALG ID: %X KEY ID: %0X", alg + 0x20, key); - fprintf (stderr, "\n"); + // fprintf (stderr, "\n"); fprintf (stderr, "%s ", KNRM); state->payload_keyid = key; @@ -278,18 +332,18 @@ void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power) } } - //the signalling here is always presents on good voice frames, if errs are [3][2] then its not a VC6 voice frame, but some other 'hidden' frame - if (slot == 1 && state->errsR < 3) + if (slot == 1) //may not need the state->errs anymore //&& state->errsR < 3 { if (state->dmr_soR & 0x40 && key != 0 && state->payload_keyidR == 0) { //if we aren't forcing a particular alg or privacy key set if (state->M == 0) { - fprintf (stderr, "%s ", KYEL); - fprintf (stderr, " Slot 1"); - fprintf (stderr, " DMR LE SB ALG ID: %X KEY ID: %0X", alg + 0x20, key); fprintf (stderr, "\n"); + fprintf (stderr, "%s ", KYEL); + fprintf (stderr, " Slot 2"); + fprintf (stderr, " DMR LE SB ALG ID: %X KEY ID: %0X", alg + 0x20, key); + // fprintf (stderr, "\n"); fprintf (stderr, "%s ", KNRM); state->payload_keyidR = key; @@ -324,3 +378,27 @@ void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power) } +uint8_t crc3(uint8_t bits[], unsigned int len) +{ + uint8_t crc=0; + unsigned int K = 3; + //x^3+x+1 + uint8_t poly[4] = {1,1,0,1}; + uint8_t buf[256]; + if (len+K > sizeof(buf)) { + return 0; + } + memset (buf, 0, sizeof(buf)); + for (unsigned int i=0; i Date: Sun, 18 Jun 2023 20:12:37 -0400 Subject: [PATCH 5/7] Fix Alignment 2; --- src/dmr_le.c | 2 +- src/dsd_mbe.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dmr_le.c b/src/dmr_le.c index 401e1ee..1fb1427 100644 --- a/src/dmr_le.c +++ b/src/dmr_le.c @@ -382,7 +382,7 @@ uint8_t crc3(uint8_t bits[], unsigned int len) { uint8_t crc=0; unsigned int K = 3; - //x^3+x+1 + //x^3+x+1 uint8_t poly[4] = {1,1,0,1}; uint8_t buf[256]; if (len+K > sizeof(buf)) { diff --git a/src/dsd_mbe.c b/src/dsd_mbe.c index 6738370..54ccc00 100644 --- a/src/dsd_mbe.c +++ b/src/dsd_mbe.c @@ -367,8 +367,8 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a saveAmbe2450Data (opts, state, ambe_d); } } - else if ((state->synctype == 28) || (state->synctype == 29)) //was 8 and 9 - { + else if ((state->synctype == 28) || (state->synctype == 29)) //was 8 and 9 + { state->errs = mbe_eccAmbe3600x2450C0 (ambe_fr); //state->errs2 = state->errs; From 966fbf8c6a3ea52d7be2303a78f6c0c0c7b26554 Mon Sep 17 00:00:00 2001 From: lwvmobile Date: Sun, 18 Jun 2023 20:15:12 -0400 Subject: [PATCH 6/7] Fix Alignment 3; --- src/dmr_le.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/dmr_le.c b/src/dmr_le.c index 1fb1427..4eb7051 100644 --- a/src/dmr_le.c +++ b/src/dmr_le.c @@ -380,25 +380,25 @@ void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power) uint8_t crc3(uint8_t bits[], unsigned int len) { - uint8_t crc=0; - unsigned int K = 3; + uint8_t crc=0; + unsigned int K = 3; //x^3+x+1 - uint8_t poly[4] = {1,1,0,1}; - uint8_t buf[256]; - if (len+K > sizeof(buf)) { - return 0; - } - memset (buf, 0, sizeof(buf)); - for (unsigned int i=0; i sizeof(buf)) { + return 0; + } + memset (buf, 0, sizeof(buf)); + for (unsigned int i=0; i Date: Mon, 19 Jun 2023 06:40:21 -0400 Subject: [PATCH 7/7] Renable DMR Late Entry SB; Misc; --- CMakeLists.txt | 2 +- src/dsd_main.c | 14 ++++++++------ src/dsd_ncurses.c | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7026c38..a3bddb8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,7 @@ endif () #use cmake option -DZDEV to change designation of this build from MAIN to zDEV option(ZDEV - "change designation of this build from MAIN to zDEV" ON) + "change designation of this build from MAIN to zDEV" OFF) if (ZDEV) add_definitions(-DZDEV_BUILD) endif () diff --git a/src/dsd_main.c b/src/dsd_main.c index 510fc9b..bb107cf 100644 --- a/src/dsd_main.c +++ b/src/dsd_main.c @@ -628,7 +628,7 @@ initOpts (dsd_opts * opts) opts->dmr_dmrla_n = 0; //DMR Late Entry - opts->dmr_le = 0; //off by default until worked out some more + opts->dmr_le = 1; //re-enabled again //Trunking - Use Group List as Allow List opts->trunk_use_allow_list = 0; //disabled by default @@ -1157,9 +1157,11 @@ usage () printf (" \n"); printf (" -0 Force RC4 Key over Missing PI header/LE Encryption Identifiers (DMR) \n"); printf (" \n"); - printf (" -3 Enable DMR Late Entry Encryption Identifiers (VC6 Single Burst) \n"); - printf (" Note: This is experimental and may produce false positives depending on system type, notably Cap+. \n"); - printf (" Use -0 or -4 options above instead if needed. \n"); + printf (" -3 Disable DMR Late Entry Encryption Identifiers (VC6 Single Burst) \n"); + printf (" Note: Disable this if false positives on Voice ENC occur. \n"); + // printf (" -3 Enable DMR Late Entry Encryption Identifiers (VC6 Single Burst) \n"); + // printf (" Note: This is experimental and may produce false positives depending on system type, notably TXI. \n"); + // printf (" Use -0 or -4 options above instead if needed. \n"); printf ("\n"); printf (" Trunking Options:\n"); printf (" -C Import Channel to Frequency Map (channum, freq) from csv file. (Capital C) \n"); @@ -1372,7 +1374,7 @@ main (int argc, char **argv) } #ifdef AERO_BUILD - fprintf (stderr, "Build Version: v2.1 Beta 2\n"); + fprintf (stderr, "Build Version: v2.1 Beta 3\n"); #else fprintf (stderr, "Build Version: %s \n", GIT_TAG); #endif @@ -1424,7 +1426,7 @@ main (int argc, char **argv) case '3': opts.dmr_le = 1; - fprintf (stderr,"DMR Late Entry Encryption Identifiers Enabled (VC6 Single Burst)\n"); + fprintf (stderr,"DMR Late Entry Encryption Identifiers Disabled (VC6 Single Burst)\n"); break; case 'Y': //conventional scanner mode diff --git a/src/dsd_ncurses.c b/src/dsd_ncurses.c index bbd4b00..a0cbd89 100644 --- a/src/dsd_ncurses.c +++ b/src/dsd_ncurses.c @@ -2158,7 +2158,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) if (opts->ncurses_compact == 1) { printw ("------------------------------------------------------------------------------\n"); - printw ("| Digital Speech Decoder: Florida Man Edition - Aero %s \n", "v2.1 Beta 2"); + printw ("| Digital Speech Decoder: Florida Man Edition - Aero %s \n", "v2.1 Beta 3"); printw ("------------------------------------------------------------------------------\n"); } #elif LIMAZULUTWEAKS @@ -2194,7 +2194,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) if (i == 4) printw (" MBElib %s", versionstr); #ifdef AERO_BUILD if (i == 5) printw (" %s ", "Aero Build"); - if (i == 6) printw (" v2.1 Beta 2\n"); + if (i == 6) printw (" v2.1 Beta 3\n"); #elif ZDEV_BUILD if (i == 5) printw (" %s ", "zDEV Build"); if (i == 6) printw (" %s \n", GIT_TAG);