diff --git a/CMakeLists.txt b/CMakeLists.txt index 49146e9..4e8311c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,21 +14,21 @@ set(CURSES_NEED_WIDE TRUE) option(COLORS "Build with Colors Enabled" ON) if (COLORS) - add_definitions(-DPRETTY_COLORS) + add_definitions(-DPRETTY_COLORS) endif () #use cmake option -DCOLORSLOGS=OFF to disable color output (terminal/logs) option(COLORSLOGS "Build with Colors Enabled" ON) if (COLORSLOGS) - add_definitions(-DPRETTY_COLORS_LOGS) + add_definitions(-DPRETTY_COLORS_LOGS) endif () #use cmake option -DPVC=ON to enable Provoice Conventional Frame Sync option(PVC "Build with Provoice Conventional Frame Sync Enabled" OFF) if (PVC) - add_definitions(-DPVCONVENTIONAL) + add_definitions(-DPVCONVENTIONAL) endif () @@ -36,14 +36,14 @@ endif () option(LZ "Build with new LimaZulu Requested NXDN Tweaks Enabled" OFF) if (LZ) - add_definitions(-DLIMAZULUTWEAKS) + add_definitions(-DLIMAZULUTWEAKS) endif () #use cmake option -DSID=ON to enable P25p1 Soft ID decoding -- Experimental option(SID "Build with P25p1 LSD/Soft ID Enabled" OFF) if (SID) - add_definitions(-DSOFTID) + add_definitions(-DSOFTID) endif () @@ -54,7 +54,7 @@ find_package(LibSndFile REQUIRED) find_package(MBE REQUIRED) find_package(ITPP REQUIRED) find_package(RTLSDR) -find_package(Curses REQUIRED) +find_package(Curses REQUIRED) find_package(PulseAudio REQUIRED) find_package(CODEC2) diff --git a/cmake/git_revision.cmake.in b/cmake/git_revision.cmake.in index 888ce13..6faa374 100644 --- a/cmake/git_revision.cmake.in +++ b/cmake/git_revision.cmake.in @@ -1,4 +1,4 @@ -# +# # Internal file for GetGitRevisionDescription.cmake # # Requires CMake 2.6 or newer (uses the 'function' command) diff --git a/include/descramble.h b/include/descramble.h index 62a8e8e..d277019 100644 --- a/include/descramble.h +++ b/include/descramble.h @@ -17,7 +17,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ - + // This code was originally written by JOnathan Naylor, G4KLX, as part // of the "pcrepeatercontroller" project // More info: @@ -55,7 +55,7 @@ int traceBack (int * out, int * m_pathMemory0, int * m_pathMemory1, int * m_path } // end else - if out[loop]=0; break; - + case S1: // if state S1 if (m_pathMemory1[loop]) { state = S2; // lower path @@ -64,7 +64,7 @@ int traceBack (int * out, int * m_pathMemory0, int * m_pathMemory1, int * m_path } // end else - if out[loop]=1; break; - + case S2: // if state S2 if (m_pathMemory2[loop]) { state = S3; // lower path @@ -73,7 +73,7 @@ int traceBack (int * out, int * m_pathMemory0, int * m_pathMemory1, int * m_path } // end else - if out[loop]=0; break; - + case S3: // if state S3 if (m_pathMemory3[loop]) { state = S3; // lower path @@ -82,7 +82,7 @@ int traceBack (int * out, int * m_pathMemory0, int * m_pathMemory1, int * m_path } // end else - if out[loop]=1; break; - + } // end switch } // end for @@ -161,7 +161,7 @@ void viterbiDecode (int n, int *data, int *m_pathMemory0, int *m_pathMemory1, in }; // end function ViterbiDecode -// function FECdecoder +// function FECdecoder // returns outlen int FECdecoder (int * in, int * out) { int outLen; diff --git a/include/dsd.h b/include/dsd.h index 8f43733..81a531c 100644 --- a/include/dsd.h +++ b/include/dsd.h @@ -596,7 +596,7 @@ typedef struct unsigned long long int K4; int M; int menuopen; - + //AES Key Segments unsigned long long int A1[2]; unsigned long long int A2[2]; @@ -744,7 +744,7 @@ typedef struct //NXDN DES and AES, signal new VCALL_IV and new IV uint8_t nxdn_new_iv; //1 when a new IV comes in, else 0 - + short int dmr_encL; short int dmr_encR; diff --git a/include/dstar_const.h b/include/dstar_const.h index 23df459..103a23b 100644 --- a/include/dstar_const.h +++ b/include/dstar_const.h @@ -16,7 +16,7 @@ */ /* - * dstar interleave experiments + * dstar interleave experiments */ #ifndef _MAIN diff --git a/include/fcs.h b/include/fcs.h index 6f533f6..16602ea 100644 --- a/include/fcs.h +++ b/include/fcs.h @@ -1,6 +1,6 @@ /* fcs.h */ -// Viterbi decoder using Traceback method. +// Viterbi decoder using Traceback method. // Original Source was written by Sho Tamaoki and Tom Wada // See http://www.lsi.ie.u-ryukyu.ac.jp/~sho/midterm/ @@ -86,4 +86,4 @@ m_crc = (m_crc << 8) | (tmp >> 8 & 0xFF); // done return(m_crc); -}; // end function +}; // end function diff --git a/include/nxdn_const.h b/include/nxdn_const.h index d2d4cdc..3fb3c2f 100644 --- a/include/nxdn_const.h +++ b/include/nxdn_const.h @@ -5,12 +5,12 @@ // under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 3, or (at your option) // any later version. -// +// // OP25 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 OP25; see the file COPYING. If not, write to the Free // Software Foundation, Inc., 51 Franklin Street, Boston, MA diff --git a/src/crypt-aes.c b/src/crypt-aes.c index c724f0a..f261e2c 100644 --- a/src/crypt-aes.c +++ b/src/crypt-aes.c @@ -109,7 +109,7 @@ static void KeyExpansion(uint8_t* RoundKey, const uint8_t* Key) { unsigned i, j, k; uint8_t tempa[4]; // Used for the column/row operations - + // The first round key is the key itself. for (i = 0; i < Nk; ++i) { @@ -145,7 +145,7 @@ static void KeyExpansion(uint8_t* RoundKey, const uint8_t* Key) tempa[3] = u8tmp; } - // SubWord() is a function that takes a four-byte input word and + // SubWord() is a function that takes a four-byte input word and // applies the S-box to each of the four bytes to produce an output word. // Function Subword() @@ -261,14 +261,14 @@ static void ShiftRows(state_t* state) { uint8_t temp; - // Rotate first row 1 columns to left + // Rotate first row 1 columns to left temp = (*state)[0][1]; (*state)[0][1] = (*state)[1][1]; (*state)[1][1] = (*state)[2][1]; (*state)[2][1] = (*state)[3][1]; (*state)[3][1] = temp; - // Rotate second row 2 columns to left + // Rotate second row 2 columns to left temp = (*state)[0][2]; (*state)[0][2] = (*state)[2][2]; (*state)[2][2] = temp; @@ -295,7 +295,7 @@ static void MixColumns(state_t* state) uint8_t i; uint8_t Tmp, Tm, t; for (i = 0; i < 4; ++i) - { + { t = (*state)[i][0]; Tmp = (*state)[i][0] ^ (*state)[i][1] ^ (*state)[i][2] ^ (*state)[i][3] ; Tm = (*state)[i][0] ^ (*state)[i][1] ; Tm = xtime(Tm); (*state)[i][0] ^= Tm ^ Tmp ; @@ -320,7 +320,7 @@ static void InvMixColumns(state_t* state) int i; uint8_t a, b, c, d; for (i = 0; i < 4; ++i) - { + { a = (*state)[i][0]; b = (*state)[i][1]; c = (*state)[i][2]; @@ -349,14 +349,14 @@ static void InvShiftRows(state_t* state) { uint8_t temp; - // Rotate first row 1 columns to right + // Rotate first row 1 columns to right temp = (*state)[3][1]; (*state)[3][1] = (*state)[2][1]; (*state)[2][1] = (*state)[1][1]; (*state)[1][1] = (*state)[0][1]; (*state)[0][1] = temp; - // Rotate second row 2 columns to right + // Rotate second row 2 columns to right temp = (*state)[0][2]; (*state)[0][2] = (*state)[2][2]; (*state)[2][2] = temp; @@ -373,7 +373,7 @@ static void InvShiftRows(state_t* state) (*state)[3][3] = temp; } -// Cipher is the main function that encrypts the PlainText, +// Cipher is the main function that encrypts the PlainText, // or produces a keystream, depending on application. static void Cipher(state_t* state, const uint8_t* RoundKey) { @@ -479,14 +479,14 @@ void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length) void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length) { uint8_t buffer[AES_BLOCKLEN]; - + size_t i; int bi; for (i = 0, bi = AES_BLOCKLEN; i < length; ++i, ++bi) { if (bi == AES_BLOCKLEN) /* we need to regen xor compliment in buffer */ { - + memcpy(buffer, ctx->Iv, AES_BLOCKLEN); Cipher((state_t*)buffer,ctx->RoundKey); @@ -498,9 +498,9 @@ void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length) { ctx->Iv[bi] = 0; continue; - } + } ctx->Iv[bi] += 1; - break; + break; } bi = 0; } @@ -558,7 +558,7 @@ void aes_ofb_keystream_output (uint8_t * iv, uint8_t * key, uint8_t * output, in Cipher((state_t*)input_register, ctx.RoundKey); //input_register is returned as output, and is put back in as object feedback memcpy (output+(i*16), input_register, 16*sizeof(uint8_t) ); //copy ciphered input_register to output } - + } //byte-wise AES CFB (Cipher Feedback) Payload operating in 128-bit block mode @@ -624,7 +624,7 @@ void aes_cfb_bytewise_payload_crypt (uint8_t * iv, uint8_t * key, uint8_t * in, memcpy(input_register, in+(i*16), 16*sizeof(uint8_t)); } - + } //byte-wise AES CBC (Cipher Block Chaining) //Yeah, I know this already exists, but wanted a custom convenience wrapper version @@ -691,7 +691,7 @@ void aes_cbc_bytewise_payload_crypt (uint8_t * iv, uint8_t * key, uint8_t * in, memcpy (out+(i*16), input_register, 16*sizeof(uint8_t) ); } - + else //decrypt { @@ -719,12 +719,12 @@ void aes_cbc_bytewise_payload_crypt (uint8_t * iv, uint8_t * key, uint8_t * in, } } - + } -//byte-wise AES CBC_MAC (Cipher Block Chaining Message Authentication) //This is slightly different than above, no IV is present, +//byte-wise AES CBC_MAC (Cipher Block Chaining Message Authentication) //This is slightly different than above, no IV is present, //but if iv is desireable, it will need to be pre-XOR'd with the first plaintext input block by the calling function -//input in is a uint8_t bytewise array, is the input to be ciphered. +//input in is a uint8_t bytewise array, is the input to be ciphered. //input key is up to 32-byte uint8_t array of key value //input type is the type/key len of AES required (0-128, 1-192, 2-256) //input nblocks is the number of rounds of 16-byte payload blocks requried (last block will need padding if not flush) @@ -781,7 +781,7 @@ void aes_cbc_mac_generator (uint8_t * key, uint8_t * in, uint8_t * out, int type //copy final ciphered input_register to output 'out', user will determine how many bytes of output they want for MAC memcpy (out, input_register, 16*sizeof(uint8_t) ); - + } //byte-wise output of AES ECB Ciphering/Deciphering @@ -789,7 +789,7 @@ void aes_cbc_mac_generator (uint8_t * key, uint8_t * in, uint8_t * out, int type //input key is up to 32-byte uint8_t array of key value //input type is the type/len of AES required (0-128, 1-192, 2-256) //output is a uint8_t bytewise array of ciphered or deciphered input -//de is a bit-flag signalling to run Cipher (encrypt) on 1, or InvCipher (decrypt) on 0 +//de is a bit-flag signalling to run Cipher (encrypt) on 1, or InvCipher (decrypt) on 0 void aes_ecb_bytewise_payload_crypt (uint8_t * input, uint8_t * key, uint8_t * output, int type, int de) { @@ -833,7 +833,7 @@ void aes_ecb_bytewise_payload_crypt (uint8_t * input, uint8_t * key, uint8_t * o //copy ciphered/deciphered input_register to output memcpy (output, input_register, 16*sizeof(uint8_t) ); - + } //symmetrical ctr mode payload encryption and decryption @@ -859,7 +859,7 @@ void aes_ctr_bitwise_payload_crypt (uint8_t * iv, uint8_t * key, uint8_t * paylo Nk = 8; Nr = 14; } - + struct AES_ctx ctx; //init and set the iv and key variables @@ -905,7 +905,7 @@ void aes_ctr_bytewise_payload_crypt (uint8_t * iv, uint8_t * key, uint8_t * payl Nk = 8; Nr = 14; } - + struct AES_ctx ctx; //init and set the iv and key variables @@ -938,7 +938,7 @@ uint8_t aes_key_unwrap_execute (uint8_t * key, uint8_t * payload, uint8_t * outp memset(C, 0, sizeof(C)); //copy input_bytes to cipher code words - for (i = 0; i < 6; i++) + for (i = 0; i < 6; i++) memcpy(C[i], payload+(i*8), sizeof(C[0])); //A = C0 first 8 octets only @@ -1028,7 +1028,7 @@ uint8_t aes_key_unwrap_execute (uint8_t * key, uint8_t * payload, uint8_t * outp fprintf (stderr, "\n Unwrap Failure! ICV1 != 0xA6A6A6A6A6A6A6A6!"); return 0; } - else + else { fprintf (stderr, "\n Unwrap Success!"); return 1; diff --git a/src/crypt-des.c b/src/crypt-des.c index 001f972..09b4ada 100644 --- a/src/crypt-des.c +++ b/src/crypt-des.c @@ -173,16 +173,16 @@ uint8_t pc2_key_permutation[48] = { uint8_t key_shift_sizes[17] = { 1, -1, 1, 2, 2, -2, 2, 2, 2, -1, 2, 2, 2, +1, 1, 2, 2, +2, 2, 2, 2, +1, 2, 2, 2, 2, 2, 2, 1}; uint8_t key_shift_bytes[17] = { 0x80, -0x80, 0x80, 0xC0, 0xC0, -0xC0, 0xC0, 0xC0, 0xC0, -0x80, 0xC0, 0xC0, 0xC0, +0x80, 0x80, 0xC0, 0xC0, +0xC0, 0xC0, 0xC0, 0xC0, +0x80, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0x80}; uint8_t key_shift_x[4] = {8,8,8,4}; @@ -230,7 +230,7 @@ void rotate_sub_keys(uint8_t * Kc, uint8_t * Kd, uint8_t shift_size, uint8_t shi Kc[i] |= (sb1[y] >> (x - shift_size)); Kd[i] |= (sb2[y] >> (x - shift_size)); - + } } @@ -320,7 +320,7 @@ void des_cipher (uint8_t * main_key, uint8_t * input_register, uint8_t * output_ uint8_t e6 = ((exp[3] & 0x3) << 4) | (exp[4] >> 4); uint8_t e7 = ((exp[4] & 0xF) << 2) | (exp[5] >> 6); uint8_t e8 = exp[5] & 0x3F; - + //select 32-bits of each 48-bit expansion via modified S Box Look Up Tables //swap the 6 bits for 4 bits via SLUT tables and OR them together into a selection array sel[0] = SLUT1[e1] | SLUT2[e2]; @@ -396,7 +396,7 @@ void tdea_ecb_payload_crypt (uint8_t * K1, uint8_t * K2, uint8_t * K3, uint8_t * //NOTE: If running ECB mode in decryption, make sure to send the keys in reverse order //so that its K3, K2, and K1 for decryption, and K1, K2, K3 for encryption - + //K1 des_cipher(K1, input_register, output_register, de); memcpy(input_register, output_register, sizeof(output_register)); //recycle output_register back into input_register @@ -433,7 +433,7 @@ void tdea_cbc_payload_crypt (uint8_t * K1, uint8_t * K2, uint8_t * K3, uint8_t * if (de) memcpy (input_register, iv, sizeof(input_register)); //load the IV as first input_register if encrypting else memcpy (input_register, in, sizeof(input_register)); //load first cipher text as input_register is decrypting - + //run payload for number of payload nblocks required for (i = 0; i < nblocks; i++) { @@ -468,7 +468,7 @@ void tdea_cbc_payload_crypt (uint8_t * K1, uint8_t * K2, uint8_t * K3, uint8_t * } else { - + //K3 des_cipher(K3, input_register, output_register, de); memcpy(input_register, output_register, sizeof(output_register)); //recycle output_register back into input_register @@ -523,7 +523,7 @@ void tdea_cbc_mac_generator (uint8_t * K1, uint8_t * K2, uint8_t * K3, uint8_t * //cipher input and output uint8_t input_register[8]; memset(input_register, 0, sizeof(input_register)); uint8_t output_register[8]; memset(output_register, 0, sizeof(output_register)); - + //run payload for number of payload nblocks required for (i = 0; i < nblocks; i++) { @@ -576,7 +576,7 @@ void tdea_cfb_payload_crypt (uint8_t * K1, uint8_t * K2, uint8_t * K3, uint8_t * //execute the des_cipher in output feedback mode 3 times using each key and transferring output to input each time for (i = 0; i < nblocks; i++) { - + //the cipher is always run in the foward, or encryption mode (1,0,1) //K1 @@ -664,7 +664,7 @@ void tdea_ctr_payload_crypt (uint8_t * K1, uint8_t * K2, uint8_t * K3, uint8_t * //feed the new IV into the input register memcpy (input_register, iv, sizeof(input_register)); - + } } @@ -713,7 +713,7 @@ uint64_t lfsr_64_to_len_ca(uint8_t * iv, int16_t len) uint64_t lfsr = 0, bit = 0; - lfsr = ((uint64_t)iv[0] << 56ULL) + ((uint64_t)iv[1] << 48ULL) + ((uint64_t)iv[2] << 40ULL) + ((uint64_t)iv[3] << 32ULL) + + lfsr = ((uint64_t)iv[0] << 56ULL) + ((uint64_t)iv[1] << 48ULL) + ((uint64_t)iv[2] << 40ULL) + ((uint64_t)iv[3] << 32ULL) + ((uint64_t)iv[4] << 24ULL) + ((uint64_t)iv[5] << 16ULL) + ((uint64_t)iv[6] << 8ULL) + ((uint64_t)iv[7] << 0ULL); memset (iv, 0, 8*sizeof(uint8_t)); @@ -757,7 +757,7 @@ void des56_ca_keystream_output (uint8_t * main_key, uint8_t * iv, uint8_t * ks_b //de should be 1 here for encryption mode des_cipher(main_key, input_register, output_register, de); - //keystream accumulation, shift current byte and append + //keystream accumulation, shift current byte and append //single bit from current output register's most significant bit ks_bytes[i/8] <<= 1; ks_bytes[i/8] |= ((output_register[0] >> 7) & 1); diff --git a/src/dmr_34.c b/src/dmr_34.c index d1f3601..4d8d510 100644 --- a/src/dmr_34.c +++ b/src/dmr_34.c @@ -20,8 +20,8 @@ uint8_t constellation_map[16] = { }; //digitized dibit to OTA symbol conversion for reference -//0 = +1; 1 = +3; -//2 = -1; 3 = -3; +//0 = +1; 1 = +3; +//2 = -1; 3 = -3; //finite state machine values uint8_t fsm[64] = { @@ -81,7 +81,7 @@ uint8_t fix_34(uint8_t * p, uint8_t state, int position) counter++; break; } - + } if (counter > best_p) @@ -139,12 +139,12 @@ uint32_t dmr_34(uint8_t * input, uint8_t treturn[18]) uint8_t point[49]; memset (point, 0xFF, sizeof(point)); - for (i = 0; i < 49; i++) + for (i = 0; i < 49; i++) point[i] = constellation_map[nibs[i]]; //debug view points // fprintf (stderr, "\n P ="); - // for (i = 0; i < 49; i++) + // for (i = 0; i < 49; i++) // fprintf (stderr, " %02d", point[i]); //convert constellation points into tribit values using the FSM @@ -181,14 +181,14 @@ uint32_t dmr_34(uint8_t * input, uint8_t treturn[18]) //decrement one and resume decoding i--; - + } } //debug view tribits/states // fprintf (stderr, "\n T ="); - // for (i = 0; i < 49; i++) + // for (i = 0; i < 49; i++) // fprintf (stderr, " %02d", tribits[i]); //convert tribits into a return payload @@ -197,7 +197,7 @@ uint32_t dmr_34(uint8_t * input, uint8_t treturn[18]) //break into chunks of 24 bit values and shuffle into 8-bit (byte) treturn values for (i = 0; i < 6; i++) { - temp = (tribits[(i*8)+0] << 21) + (tribits[(i*8)+1] << 18) + (tribits[(i*8)+2] << 15) + (tribits[(i*8)+3] << 12) + + temp = (tribits[(i*8)+0] << 21) + (tribits[(i*8)+1] << 18) + (tribits[(i*8)+2] << 15) + (tribits[(i*8)+3] << 12) + (tribits[(i*8)+4] << 9) + (tribits[(i*8)+5] << 6) + (tribits[(i*8)+6] << 3) + (tribits[(i*8)+7] << 0); treturn[(i*3)+0] = (temp >> 16) & 0xFF; diff --git a/src/dmr_block.c b/src/dmr_block.c index ff64379..c8990e1 100644 --- a/src/dmr_block.c +++ b/src/dmr_block.c @@ -71,11 +71,11 @@ void dmr_dheader (dsd_opts * opts, dsd_state * state, uint8_t dheader[], uint8_t uint8_t poc = (uint8_t)ConvertBitIntoBytes(&dheader_bits[12], 4) + (mpoc << 4); //padding octets UNUSED(ab); - uint32_t target = (uint32_t)ConvertBitIntoBytes(&dheader_bits[16], 24); //destination llid + uint32_t target = (uint32_t)ConvertBitIntoBytes(&dheader_bits[16], 24); //destination llid uint32_t source = (uint32_t)ConvertBitIntoBytes(&dheader_bits[40], 24); //source llid - //extra tgt/src handling for XPT - uint8_t target_hash[24]; + //extra tgt/src handling for XPT + uint8_t target_hash[24]; uint8_t tg_hash = 0; uint8_t is_xpt = 0; //set flag if XPT @@ -84,9 +84,9 @@ void dmr_dheader (dsd_opts * opts, dsd_state * state, uint8_t dheader[], uint8_t //truncate tgt/src to 16-bit values if XPT if (is_xpt == 1) { - target = (uint32_t)ConvertBitIntoBytes(&dheader_bits[24], 16); //destination llid + target = (uint32_t)ConvertBitIntoBytes(&dheader_bits[24], 16); //destination llid source = (uint32_t)ConvertBitIntoBytes(&dheader_bits[48], 16); //source llid - if (gi == 0) + if (gi == 0) { for (int i = 0; i < 16; i++) target_hash[i] = dheader_bits[24+i]; tg_hash = crc8 (target_hash, 16); @@ -114,7 +114,7 @@ void dmr_dheader (dsd_opts * opts, dsd_state * state, uint8_t dheader[], uint8_t if (dpf != 15) state->data_block_poc[slot] = poc; //set dpf to storage for later use (UDT, SD, etc) - state->data_header_format[slot] = dpf; + state->data_header_format[slot] = dpf; //Type Strings char sap_string[20]; @@ -164,14 +164,14 @@ void dmr_dheader (dsd_opts * opts, dsd_state * state, uint8_t dheader[], uint8_t uint8_t udt_pf = dheader_bits[73]; uint8_t udt_op = (uint8_t)ConvertBitIntoBytes(&dheader_bits[74], 6); - //ETSI TS 102 361-4 V1.12.1 (2023-07) p281 + //ETSI TS 102 361-4 V1.12.1 (2023-07) p281 udt_uab += 1; //add 1 internally, up to 4 appended blocks are carried, min is 1 //NMEA Specific Fix for unspecified MFID format w/ 2 appended blocks (UAB 2) p291 if (udt_uab == 0x5 && udt_uab == 3) udt_uab = 2; //set to two if long unspecified format - //Note: NMEA Reserved value UAB 3 is not referenced in ETSI, so unknown number of + //Note: NMEA Reserved value UAB 3 is not referenced in ETSI, so unknown number of //appended blocks but we will assume it is supposed to be 4 appended blocks //p_head @@ -184,7 +184,7 @@ void dmr_dheader (dsd_opts * opts, dsd_state * state, uint8_t dheader[], uint8_t if (gi == 1 && dpf != 15) fprintf(stderr, "Group - "); if (gi == 0 && dpf != 15) fprintf(stderr, "Indiv - "); - + if (dpf == 0) fprintf (stderr, "Unified Data Transport (UDT) "); else if (dpf == 1) fprintf (stderr, "Response Packet "); else if (dpf == 2) fprintf (stderr, "Unconfirmed Delivery "); @@ -222,8 +222,8 @@ void dmr_dheader (dsd_opts * opts, dsd_state * state, uint8_t dheader[], uint8_t else if (p_mfid == 0x58) sprintf (mfid_string, "%s", "Tait"); else if (p_mfid == 0x68) sprintf (mfid_string, "%s", "Hytera"); else if (p_mfid == 0x08) sprintf (mfid_string, "%s", "Hytera"); - else if (p_mfid == 0x06) sprintf (mfid_string, "%s", "Trid/Mot"); - else if (p_mfid == 0x00) sprintf (mfid_string, "%s", "Standard"); + else if (p_mfid == 0x06) sprintf (mfid_string, "%s", "Trid/Mot"); + else if (p_mfid == 0x00) sprintf (mfid_string, "%s", "Standard"); else sprintf (mfid_string, "%s", "Other"); } @@ -234,8 +234,8 @@ void dmr_dheader (dsd_opts * opts, dsd_state * state, uint8_t dheader[], uint8_t else if (udt_format == 0x01) sprintf (udtf_string, "%s", "MS/TG Adr"); else if (udt_format == 0x02) sprintf (udtf_string, "%s", "4-bit BCD"); else if (udt_format == 0x03) sprintf (udtf_string, "%s", "ISO7 Char"); - else if (udt_format == 0x04) sprintf (udtf_string, "%s", "ISO8 Char"); - else if (udt_format == 0x05) sprintf (udtf_string, "%s", "NMEA LOCN"); + else if (udt_format == 0x04) sprintf (udtf_string, "%s", "ISO8 Char"); + else if (udt_format == 0x05) sprintf (udtf_string, "%s", "NMEA LOCN"); else if (udt_format == 0x06) sprintf (udtf_string, "%s", "IP Addr"); else if (udt_format == 0x07) sprintf (udtf_string, "%s", "UTF-16"); //16-bit Unicode Chars else if (udt_format == 0x08) sprintf (udtf_string, "%s", "Manu Spec"); //Manufacturer Specific @@ -261,7 +261,7 @@ void dmr_dheader (dsd_opts * opts, dsd_state * state, uint8_t dheader[], uint8_t else if (dd_format == 0x0A) sprintf (sddd_string, "%s", "IEC 8859-8"); else if (dd_format == 0x0B) sprintf (sddd_string, "%s", "IEC 8859-9"); else if (dd_format == 0x0C) sprintf (sddd_string, "%s", "IEC 8859-10"); - else if (dd_format == 0x0D) sprintf (sddd_string, "%s", "IEC 8859-11"); + else if (dd_format == 0x0D) sprintf (sddd_string, "%s", "IEC 8859-11"); else if (dd_format == 0x0E) sprintf (sddd_string, "%s", "IEC 8859-13"); //there is no 8059-12 else if (dd_format == 0x0F) sprintf (sddd_string, "%s", "IEC 8859-14"); else if (dd_format == 0x10) sprintf (sddd_string, "%s", "IEC 8859-15"); @@ -319,7 +319,7 @@ void dmr_dheader (dsd_opts * opts, dsd_state * state, uint8_t dheader[], uint8_t } //Confirmed or Unconfirmed Data Packets Header - if (dpf == 2 || dpf == 3) + if (dpf == 2 || dpf == 3) { if (dpf == 2) fprintf (stderr, "\n SAP %02d [%s] - FMF %d - BLOCKS %02d - PAD %02d - FSN %d", sap, sap_string, f, bf, poc, fsn); if (dpf == 3) fprintf (stderr, "\n SAP %02d [%s] - FMF %d - BLOCKS %02d - PAD %02d - S %d - NS %d - FSN %d", sap, sap_string, f, bf, poc, s, ns, fsn); @@ -329,7 +329,7 @@ void dmr_dheader (dsd_opts * opts, dsd_state * state, uint8_t dheader[], uint8_t } //Short Data DD_Head (13), and R_Head or SP_Head (14) - if (dpf == 13 || dpf == 14) + if (dpf == 13 || dpf == 14) { //only set if not all zeroes if (s_ab_fin) state->data_header_blocks[slot] = s_ab_fin; @@ -346,18 +346,18 @@ void dmr_dheader (dsd_opts * opts, dsd_state * state, uint8_t dheader[], uint8_t else fprintf (stderr, "\n SD:RAW [R_HEAD] - SAP %02d [%s] - BLOCKS %02d - SP %02d - DP %02d - SARQ %d - FMF %d - PDb %d", sap, sap_string, s_ab_fin, s_source_port, s_dest_port, sd_sarq, sd_f, sd_bp); } - //6.2.2 The Response Requested (A) information element of the header shall be set to 0 + //6.2.2 The Response Requested (A) information element of the header shall be set to 0 //for unconfirmed data and shall be set to 1 for confirmed data. DD_HEAD, R_HEAD, or SP_HEAD (double check) if (a == 1) { state->data_conf_data[slot] = 1; fprintf (stderr, " - Confirmed Data"); - } + } } - + //Proprietary Data Header - if (dpf == 15) + if (dpf == 15) { //The SAP found here is the actual SAP of the message (like a P25 ndary SAP, and can chain together according to ETSI) @@ -478,7 +478,7 @@ void dmr_dheader (dsd_opts * opts, dsd_state * state, uint8_t dheader[], uint8_t } //reset the ctr - state->data_byte_ctr[slot] = 0; + state->data_byte_ctr[slot] = 0; } //block storage sanity @@ -506,8 +506,8 @@ void dmr_dheader (dsd_opts * opts, dsd_state * state, uint8_t dheader[], uint8_t sprintf (state->dmr_lrrp_gps[slot], "%s", ""); state->data_p_head[slot] = 0; state->data_conf_data[slot] = 0; - state->data_block_counter[slot] = 1; - state->data_header_blocks[slot] = 1; + state->data_block_counter[slot] = 1; + state->data_header_blocks[slot] = 1; state->data_header_format[slot] = 7; } @@ -596,7 +596,7 @@ void dmr_udt_decoder (dsd_opts * opts, dsd_state * state, uint8_t * block_bytes, if (udt_format2 == 0x00) { - fprintf (stderr, "Binary Data;"); + fprintf (stderr, "Binary Data;"); } else if (udt_format2 == 0x01) //appended addresses { @@ -606,7 +606,7 @@ void dmr_udt_decoder (dsd_opts * opts, dsd_state * state, uint8_t * block_bytes, if (udt_uab == 3) end = 11; if (udt_uab == 4) end = 15; if (add_res) fprintf (stderr, "RES: %d; ", add_res); - fprintf (stderr, "OK: %d; ", add_ok); + fprintf (stderr, "OK: %d; ", add_ok); fprintf (stderr, "ADDR:"); for (i = 0; i < end; i++) { @@ -731,7 +731,7 @@ void dmr_udt_decoder (dsd_opts * opts, dsd_state * state, uint8_t * block_bytes, fprintf (stderr, " Encrypted Format :(" ); //sad face else if (udt_uab == 1) nmea_iec_61162_1 (opts, state, cs_bits+96, udt_source, 1); //short format w/ 1 appended block - else if (udt_uab == 2) + else if (udt_uab == 2) nmea_iec_61162_1 (opts, state, cs_bits+96, udt_source, 2); //standard long format w/ 2 appended blocks //check the 'spare' bits from 184 to 192 to see if this is a manufacturer specific nmea format else if (udt_uab == 3) //mfid format w/ 2 appended blocks -- format unspecified @@ -770,15 +770,15 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte uint8_t lb = 0; //mbc last block uint8_t pf = 0; //mbc protect flag - uint8_t slot = state->currentslot; - int blocks; + uint8_t slot = state->currentslot; + int blocks; uint8_t blockcounter = state->data_block_counter[slot]; int block_num = state->data_header_blocks[slot]; uint32_t CRCCorrect = 0; uint32_t CRCComputed = 0; uint32_t CRCExtracted = 0; - uint32_t IrrecoverableErrors = 0; + uint32_t IrrecoverableErrors = 0; uint8_t dmr_pdu_sf_bits[8*24*129]; //give plenty of space so we don't go oob @@ -786,7 +786,7 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte uint8_t mbc_crc_good[2]; //header and blocks crc pass/fail local storage memset (mbc_crc_good, 0, sizeof (mbc_crc_good)); //init on 0 - bad crc - if (type == 1) blocks = state->data_header_blocks[slot] - 1; + if (type == 1) blocks = state->data_header_blocks[slot] - 1; if (type == 2) blocks = state->data_block_counter[slot]; //UDT Header and Block Check @@ -815,7 +815,7 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte //debug // fprintf (stderr, " CTR: %02d; ", ctr); - //add block_len to current byte counter + //add block_len to current byte counter state->data_byte_ctr[slot] += block_len; //time to send the completed 'superframe' to the DMR PDU message handler @@ -838,7 +838,7 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte //sanity check to prevent a negative or zero block_num or sending a negative value into the bit array if (block_num < 1 || block_num == 0) block_num = 1; - CRCExtracted = (state->dmr_pdu_sf[slot][ctr-4] << 24) | (state->dmr_pdu_sf[slot][ctr-3] << 16) | + CRCExtracted = (state->dmr_pdu_sf[slot][ctr-4] << 24) | (state->dmr_pdu_sf[slot][ctr-3] << 16) | (state->dmr_pdu_sf[slot][ctr-2] << 8) | (state->dmr_pdu_sf[slot][ctr-1] << 0); int offset = 0; @@ -846,7 +846,7 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte offset = 12; //rearrage for ridiculously stupid CRC32 LSO/MSO ordering - for(i = 0, j = 0; i < ctr; i+=2, j+=16) + for(i = 0, j = 0; i < ctr; i+=2, j+=16) { dmr_pdu_sf_bits[j + 0] = (state->dmr_pdu_sf[slot][i+1] >> 7) & 0x01; dmr_pdu_sf_bits[j + 1] = (state->dmr_pdu_sf[slot][i+1] >> 6) & 0x01; @@ -869,7 +869,7 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte //increment extra 2 bytes on each nth byte (depends on data type 1/2, 3/4, 1) if conf data if ( i == (block_len - 1 + offset) ) { - + if (state->data_conf_data[slot] == 1) i+=2; //should this be 0, or 1? } @@ -878,7 +878,7 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte //confirmed working now! CRCComputed = (uint32_t)ComputeCrc32Bit(dmr_pdu_sf_bits, (ctr * 8) - 32); - //if the CRC32 is correct, I think its fair to assume we don't need to worry about if the + //if the CRC32 is correct, I think its fair to assume we don't need to worry about if the //individual CRC9s are correct on confirmed data blocks (but we can confirm now that they are all good) if (CRCComputed == CRCExtracted) CRCCorrect = 1; @@ -905,7 +905,7 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte #ifdef DMR_PDU_DECRYPTION if (enc_check) { - + int poc = (int)state->data_block_poc[slot]; int start = (int)state->data_ks_start[slot]; int end = ((blocks+1)*block_len)-4-poc-start; @@ -933,7 +933,7 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte //key loader if (state->currentslot == 0) - R = state->rkey_array[state->payload_keyid]; + R = state->rkey_array[state->payload_keyid]; else R = state->rkey_array[state->payload_keyidR]; @@ -1023,7 +1023,7 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte for (i = 0; i < end; i++) state->dmr_pdu_sf[slot][i+start] ^= ob[i%3096]; } - + else if (alg == 2 && R != 0) { for (i = 0; i < end; i++) @@ -1044,7 +1044,7 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte else if (alg == 0) { uint16_t bp_key = 0; - if (state->K != 0) //state->M == 1 && + if (state->K != 0) //state->M == 1 && { //load the BP key into the output blocks (only need two) bp_key = BPK[state->K]; @@ -1055,7 +1055,7 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte if (bp_key != 0) { - for (i = 0; i < end; i++) + for (i = 0; i < end; i++) state->dmr_pdu_sf[slot][i+start] ^= ob[i%2]; decrypted_pdu = 1; @@ -1138,12 +1138,12 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte fprintf (stderr, " ???: %04X", mnis_unk); sprintf (state->dmr_lrrp_gps[slot], "MNIS SRC: %d; DST: %d; ", msrc, mdst); - + if (mnis_type == 0x11) //+7 offset dmr_lrrp (opts, state, len, msrc, mdst, state->dmr_pdu_sf[slot]+7); else if (mnis_type == 0x33) //check any potential texts in this message utf8_to_text(state, 0, 15, state->dmr_pdu_sf[slot]+7); //seen some ARS radio IDs in ASCII/ISO7/UTF8 format here - + } } @@ -1165,9 +1165,9 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte { fprintf (stderr, "%s", KGRN); fprintf (stderr, "\n Slot %d - Multi Block PDU Message\n ", slot+1); - for (i = 0; i < ((blocks+1)*block_len); i++) + for (i = 0; i < ((blocks+1)*block_len); i++) { - if ( (i != 0) && (i % 12 == 0) ) fprintf (stderr, "\n "); + if ( (i != 0) && (i % 12 == 0) ) fprintf (stderr, "\n "); fprintf (stderr, "%02X", state->dmr_pdu_sf[slot][i]); } @@ -1178,8 +1178,8 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte state->data_header_format[slot] = 7; //reset data header sap storage state->data_header_sap[slot] = 0; - //flag off data header validity - state->data_header_valid[slot] = 0; + //flag off data header validity + state->data_header_valid[slot] = 0; //flag off conf data flag state->data_conf_data[slot] = 0; //reset padding @@ -1192,10 +1192,10 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte } //end completed sf } //end type 1 blocks - + //type 2 - MBC and UDT header, MBC and UDT continuation blocks - if (type == 2) + if (type == 2) { //sanity check (marginal signal, bad decodes, etc) -- may go a little lower (find out max number of MBC blocks supported) if (state->data_block_counter[slot] > 4) state->data_block_counter[slot] = 4; @@ -1203,9 +1203,9 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte //Type 2 data block, additive method for (i = 0; i < block_len; i++) { - state->dmr_pdu_sf[slot][i+(blockcounter*block_len)] = block_bytes[i]; + state->dmr_pdu_sf[slot][i+(blockcounter*block_len)] = block_bytes[i]; } - + memset (dmr_pdu_sf_bits, 0, sizeof(dmr_pdu_sf_bits)); lb = block_bytes[0] >> 7; //last block flag @@ -1216,13 +1216,13 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte lb = 0; //set to zero, data header may erroneously the lb flag check above (IG) pf = 0; //set to zero, data header may erroneously the pf flag check above (A) if (blocks == blockcounter) lb = 1; //seems to work now with the +1 on udt_uab - + //debug -- evaluate current block count vs the number of expected blocks // fprintf (stderr, " BL: %d; BC: %d; ", blocks, blockcounter); } //last block arrived and we have a valid data header, time to send to cspdu decoder - if (lb == 1 && state->data_header_valid[slot] == 1) + if (lb == 1 && state->data_header_valid[slot] == 1) { for(i = 0, j = 0; i < 12*6; i++, j+=8) //4 blocks max? { @@ -1240,18 +1240,18 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte if (is_udt) pf = dmr_pdu_sf_bits[73]; //CRC check on Header and full frames as appropriate (header crc already stored) - //The 16 bit CRC in the header shall include the data carried by the header. - //The 16 bit CRC in the last block shall be performed on + //The 16 bit CRC in the header shall include the data carried by the header. + //The 16 bit CRC in the last block shall be performed on //all MBC blocks (conmbined) except the header block. - + mbc_crc_good[0] = state->data_block_crc_valid[slot][0]; - + CRCExtracted = 0; //extract crc from last block, apply to completed 'superframe' minus header - for(i = 0; i < 16; i++) + for(i = 0; i < 16; i++) { CRCExtracted = CRCExtracted << 1; - CRCExtracted = CRCExtracted | (uint32_t)(dmr_pdu_sf_bits[i + 96*(1+blocks) - 16] & 1); + CRCExtracted = CRCExtracted | (uint32_t)(dmr_pdu_sf_bits[i + 96*(1+blocks) - 16] & 1); } uint8_t mbc_block_bits[12*8*6]; //needed more room @@ -1306,12 +1306,12 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte { fprintf (stderr, "%s", KGRN); fprintf (stderr, "\n Slot %d - Multi Block Control Message\n ", slot+1); - for (i = 0; i < ((blocks+1)*block_len); i++) + for (i = 0; i < ((blocks+1)*block_len); i++) { fprintf (stderr, "%02X", state->dmr_pdu_sf[slot][i]); - if (i == 11 || i == 23 || i == 35 || i == 47 || i == 59 || i == 71 || i == 83 || i == 95) + if (i == 11 || i == 23 || i == 35 || i == 47 || i == 59 || i == 71 || i == 83 || i == 95) { - fprintf (stderr, "\n "); + fprintf (stderr, "\n "); } } fprintf (stderr, "%s", KRED); @@ -1339,15 +1339,15 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte } //Zero Out MBC Header Block CRC Valid - state->data_block_crc_valid[slot][0] = 0; + state->data_block_crc_valid[slot][0] = 0; //reset the block counter (data blocks) - state->data_block_counter[slot] = 1; + state->data_block_counter[slot] = 1; //reset data header format storage state->data_header_format[slot] = 7; //reset data header sap storage state->data_header_sap[slot] = 0; - //flag off data header validity - state->data_header_valid[slot] = 0; + //flag off data header validity + state->data_header_valid[slot] = 0; //flag off conf data flag state->data_conf_data[slot] = 0; //flag off p_head @@ -1371,15 +1371,15 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte } //Zero Out MBC Header Block CRC Valid - state->data_block_crc_valid[slot][0] = 0; + state->data_block_crc_valid[slot][0] = 0; //reset the block counter (data blocks) - state->data_block_counter[slot] = 1; + state->data_block_counter[slot] = 1; //reset data header format storage state->data_header_format[slot] = 7; //reset data header sap storage state->data_header_sap[slot] = 0; - //flag off data header validity - state->data_header_valid[slot] = 0; + //flag off data header validity + state->data_header_valid[slot] = 0; //flag off conf data flag state->data_conf_data[slot] = 0; //flag off p_head @@ -1392,7 +1392,7 @@ void dmr_block_assembler (dsd_opts * opts, dsd_state * state, uint8_t block_byte } -//failsafe to clear old data header, block info, cach, in case of tact/emb/slottype failures +//failsafe to clear old data header, block info, cach, in case of tact/emb/slottype failures //or tuning away and we can no longer verify accurate data block reporting void dmr_reset_blocks (dsd_opts * opts, dsd_state * state) { diff --git a/src/dmr_bs.c b/src/dmr_bs.c index 6dea8ee..2f2f46e 100644 --- a/src/dmr_bs.c +++ b/src/dmr_bs.c @@ -14,7 +14,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state) { char * timestr = NULL; - + int i, dibit; char ambe_fr[4][24]; char ambe_fr2[4][24]; @@ -28,7 +28,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state) uint8_t m1[4][24]; uint8_t m2[4][24]; uint8_t m3[4][24]; - + const int *w, *x, *y, *z; char sync[25]; uint8_t syncdata[48]; @@ -51,11 +51,11 @@ void dmrBS (dsd_opts * opts, dsd_state * state) uint8_t power = 9; //power and pre-emption indicator uint8_t lcss = 9; UNUSED2(cc, lcss); - + //would be ideal to grab all dibits and break them into bits to pass to new data handler? - uint8_t dummy_bits[196]; + uint8_t dummy_bits[196]; memset (dummy_bits, 0, sizeof(dummy_bits)); - + //Init slot lights sprintf (state->slot1light, " slot1 "); sprintf (state->slot2light, " slot2 "); @@ -86,7 +86,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state) 11, 12, 2, 13, 14, 15, 3, 16, 4, 17, 18, 19, 5, 20, 21, 22, 6, 23 - }; + }; //cach tact bits uint8_t tact_bits[7]; @@ -265,7 +265,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state) //check for sync pattern here after collected the rest of the payload, decide what to do with it if ( strcmp (sync, DMR_BS_DATA_SYNC) == 0 ) { - + fprintf (stderr,"%s ", timestr); if (internalslot == 0) { @@ -274,11 +274,11 @@ void dmrBS (dsd_opts * opts, dsd_state * state) fprintf (stderr,"Sync: +DMR "); } else fprintf (stderr,"Sync: -DMR "); - + vc1 = 7; //set to 7 so we can see that we should not be on a VC unless a framesync comes in for it first //close MBEout file - slot 1 - if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state); + if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state); } if (internalslot == 1) { @@ -303,7 +303,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state) //check for a rc burst with bptc or 34 rate data in it (testing only) // #define RC_TESTING //disable if not in use #ifdef RC_TESTING - if ( (strcmp (sync, DMR_BS_DATA_SYNC) != 0) && (strcmp (sync, DMR_BS_VOICE_SYNC) != 0) && + if ( (strcmp (sync, DMR_BS_DATA_SYNC) != 0) && (strcmp (sync, DMR_BS_VOICE_SYNC) != 0) && ( (internalslot == 0 && vc1 == 6) || (internalslot == 1 && vc2 == 6) ) ) { @@ -376,10 +376,10 @@ void dmrBS (dsd_opts * opts, dsd_state * state) } //only play voice on no data sync, and VC values are within expected values 1-6 - if (strcmp (sync, DMR_BS_DATA_SYNC) != 0) //we already have a tact ecc check, so we won't get here without that, see if there is any other eccs we can run just to make sure + if (strcmp (sync, DMR_BS_DATA_SYNC) != 0) //we already have a tact ecc check, so we won't get here without that, see if there is any other eccs we can run just to make sure { - //check the embedded signalling, if bad at this point, we probably aren't quite in sync + //check the embedded signalling, if bad at this point, we probably aren't quite in sync if(QR_16_7_6_decode(emb_pdu)) emb_ok = 1; else emb_ok = 0; @@ -408,7 +408,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state) sprintf (light, "%s", " [SLOT1] slot2 "); //open MBEout file - slot 1 if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL)) openMbeOutFile (opts, state); - } + } else { state->dmrburstR = 16; @@ -416,14 +416,14 @@ void dmrBS (dsd_opts * opts, dsd_state * state) sprintf (light, "%s", " slot1 [SLOT2] "); //open MBEout file - slot 2 if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_fR == NULL)) openMbeOutFileR (opts, state); - } + } if (opts->inverted_dmr == 0) sprintf (polarity, "%s", "+"); else sprintf (polarity, "%s", "-"); if (state->dmr_color_code != 16) fprintf (stderr,"Sync: %sDMR %s| Color Code=%02d | VC%d ", polarity, light, state->dmr_color_code, vc); else fprintf (stderr,"Sync: %sDMR %s| Color Code=XX | VC%d ", polarity, light, vc); - - if (internalslot == 0 && vc1 == 6) + + if (internalslot == 0 && vc1 == 6) { //process embedded link control fprintf (stderr, "\n"); @@ -433,7 +433,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state) } - if (internalslot == 1 && vc2 == 6) + if (internalslot == 1 && vc2 == 6) { //process embedded link control fprintf (stderr, "\n"); @@ -445,8 +445,8 @@ void dmrBS (dsd_opts * opts, dsd_state * state) if (opts->payload == 1) fprintf (stderr, "\n"); //extra line break necessary here - //copy ambe_fr frames first, running process mbe will correct them, - //but this also leads to issues extracting good le mi values when + //copy ambe_fr frames first, running process mbe will correct them, + //but this also leads to issues extracting good le mi values when //we go to do correction on them there too memcpy (m1, ambe_fr, sizeof(m1)); memcpy (m2, ambe_fr2, sizeof(m2)); @@ -459,15 +459,15 @@ void dmrBS (dsd_opts * opts, dsd_state * state) memcpy(state->s_l4[0], state->s_l, sizeof(state->s_l)); memcpy(state->s_l4u[0], state->s_lu, sizeof(state->s_lu)); } - + else { memcpy(state->f_r4[0], state->audio_out_temp_bufR, sizeof(state->audio_out_temp_bufR)); memcpy(state->s_r4[0], state->s_r, sizeof(state->s_r)); memcpy(state->s_r4u[0], state->s_ru, sizeof(state->s_ru)); } - - + + processMbeFrame (opts, state, NULL, ambe_fr2, NULL); if(internalslot == 0) { @@ -475,7 +475,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state) memcpy(state->s_l4[1], state->s_l, sizeof(state->s_l)); memcpy(state->s_l4u[1], state->s_lu, sizeof(state->s_lu)); } - + else { memcpy(state->f_r4[1], state->audio_out_temp_bufR, sizeof(state->audio_out_temp_bufR)); @@ -490,7 +490,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state) memcpy(state->s_l4[2], state->s_l, sizeof(state->s_l)); memcpy(state->s_l4u[2], state->s_lu, sizeof(state->s_lu)); } - + else { memcpy(state->f_r4[2], state->audio_out_temp_bufR, sizeof(state->audio_out_temp_bufR)); @@ -523,7 +523,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state) if (internalslot == 0 && vc1 == 6) dmr_sbrc (opts, state, power); if (internalslot == 1 && vc2 == 6) dmr_sbrc (opts, state, power); - cach_err = dmr_cach (opts, state, cachdata); + cach_err = dmr_cach (opts, state, cachdata); if (opts->payload == 0) fprintf (stderr, "\n"); // run alg refresh after vc6 ambe processing @@ -547,7 +547,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state) cach_err = 1; tact_okay = 0; emb_ok = 0; - + //reset emb components cc = 25; power = 9; @@ -570,7 +570,7 @@ void dmrBS (dsd_opts * opts, dsd_state * state) if (skipcount > 3) //after 3 onsecutive data frames, drop back to getFrameSync and process with dmr_data_sync (need one more in order to push last voice on slot 2 only voice) { - //set tests to all good so we don't get a bogus/redundant voice error + //set tests to all good so we don't get a bogus/redundant voice error cach_err = 0; tact_okay = 1; emb_ok = 1; @@ -625,15 +625,15 @@ void dmrBS (dsd_opts * opts, dsd_state * state) state->currentslot = 0; dmr_alg_refresh (opts, state); } - if (state->payload_algidR >= 0x21) + if (state->payload_algidR >= 0x21) { state->currentslot = 1; dmr_alg_refresh (opts, state); } - + //failsafe to reset all data header and blocks when bad tact or emb - dmr_reset_blocks (opts, state); - + dmr_reset_blocks (opts, state); + } // @@ -838,13 +838,13 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state) sprintf (light, "%s", " [SLOT1] slot2 "); //open MBEout file - slot 1 if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL)) openMbeOutFile (opts, state); - } + } else { sprintf (light, "%s", " slot1 [SLOT2] "); //open MBEout file - slot 2 if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_fR == NULL)) openMbeOutFileR (opts, state); - } + } if (opts->inverted_dmr == 0) sprintf (polarity, "%s", "+"); else sprintf (polarity, "%s", "-"); if (state->dmr_color_code != 16) @@ -853,8 +853,8 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state) dmr_alg_reset (opts, state); - //copy ambe_fr frames first, running process mbe will correct them, - //but this also leads to issues extracting good le mi values when + //copy ambe_fr frames first, running process mbe will correct them, + //but this also leads to issues extracting good le mi values when //we go to do correction on them there too memcpy (m1, ambe_fr, sizeof(m1)); memcpy (m2, ambe_fr2, sizeof(m2)); @@ -872,14 +872,14 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state) memcpy(state->s_l4[0], state->s_l, sizeof(state->s_l)); memcpy(state->s_l4u[0], state->s_lu, sizeof(state->s_lu)); } - + else { memcpy(state->f_r4[0], state->audio_out_temp_bufR, sizeof(state->audio_out_temp_bufR)); memcpy(state->s_r4[0], state->s_r, sizeof(state->s_r)); memcpy(state->s_r4u[0], state->s_ru, sizeof(state->s_ru)); } - + processMbeFrame (opts, state, NULL, ambe_fr2, NULL); if(internalslot == 0) @@ -888,7 +888,7 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state) memcpy(state->s_l4[1], state->s_l, sizeof(state->s_l)); memcpy(state->s_l4u[1], state->s_lu, sizeof(state->s_lu)); } - + else { memcpy(state->f_r4[1], state->audio_out_temp_bufR, sizeof(state->audio_out_temp_bufR)); @@ -903,7 +903,7 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state) memcpy(state->s_l4[2], state->s_l, sizeof(state->s_l)); memcpy(state->s_l4u[2], state->s_lu, sizeof(state->s_lu)); } - + else { memcpy(state->f_r4[2], state->audio_out_temp_bufR, sizeof(state->audio_out_temp_bufR)); @@ -943,14 +943,14 @@ void dmrBSBootstrap (dsd_opts * opts, dsd_state * state) state->currentslot = 0; dmr_alg_refresh (opts, state); } - if (state->payload_algidR >= 0x21) + if (state->payload_algidR >= 0x21) { state->currentslot = 1; dmr_alg_refresh (opts, state); } - + //failsafe to reset all data header and blocks when bad tact or emb - dmr_reset_blocks (opts, state); + dmr_reset_blocks (opts, state); } if (timestr != NULL) diff --git a/src/dmr_csbk.c b/src/dmr_csbk.c index 0ccaead..20d4cd1 100644 --- a/src/dmr_csbk.c +++ b/src/dmr_csbk.c @@ -17,7 +17,7 @@ //function for handling Control Signalling PDUs (CSBK, MBC) messages void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8_t cs_pdu[], uint32_t CRCCorrect, uint32_t IrrecoverableErrors) { - + int csbk_lb = 0; int csbk_pf = 0; int csbk_o = 0; @@ -27,7 +27,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 csbk_lb = ( (cs_pdu[0] & 0x80) >> 7 ); csbk_pf = ( (cs_pdu[0] & 0x40) >> 6 ); - csbk_o = cs_pdu[0] & 0x3F; + csbk_o = cs_pdu[0] & 0x3F; csbk_fid = cs_pdu[1]; //feature set id UNUSED(csbk_lb); @@ -35,16 +35,16 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 if (IrrecoverableErrors == 0) { //Hytera XPT CSBK Check -- if bits 0 and 1 are used as lcss, gi, ts, then the pf bit may be set on - if ( csbk_fid == 0x68 && (csbk_o == 0x0A || csbk_o == 0x0B) ) csbk_pf = 0; + if ( csbk_fid == 0x68 && (csbk_o == 0x0A || csbk_o == 0x0B) ) csbk_pf = 0; if (csbk_pf == 1) //check the protect flag, don't run if set { - fprintf (stderr, "%s", KRED); + fprintf (stderr, "%s", KRED); fprintf (stderr, "\n Protected Control Signalling Block(s)"); fprintf (stderr, "%s", KNRM); } } - - if(IrrecoverableErrors == 0 && CRCCorrect == 1) + + if(IrrecoverableErrors == 0 && CRCCorrect == 1) { //clear stale Active Channel messages here if ( ((time(NULL) - state->last_active_time) > 3) && ((time(NULL) - state->last_vc_sync_time) > 3)) @@ -54,23 +54,23 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 //update time to prevent random 'Control Channel Signal Lost' hopping //in the middle of voice call on current Control Channel (con+ and t3) - state->last_cc_sync_time = time(NULL); + state->last_cc_sync_time = time(NULL); if (csbk_pf == 0) //okay to run { //set overarching manufacturer in use when non-standard feature id set is up - if (csbk_fid != 0) state->dmr_mfid = csbk_fid; + if (csbk_fid != 0) state->dmr_mfid = csbk_fid; + + fprintf (stderr, "%s", KYEL); - fprintf (stderr, "%s", KYEL); - //7.1.1.1.1 Channel Grant CSBK/MBC PDU if (csbk_o >= 48 && csbk_o <= 56 ) { //maintain this to allow users to hardset the cc freq as map[0]; otherwise, set from rigctl or rtl freq at c_aloha_sys_parms // if (state->p25_cc_freq == 0 && state->trunk_chan_map[0] != 0) state->p25_cc_freq = state->trunk_chan_map[0]; - + //initial line break fprintf (stderr, "\n"); @@ -89,7 +89,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 fprintf (stderr, " Talkgroup Data Channel Grant: Multi Item (TD_GRANT)"); //Logical Physical Channel Number - uint16_t lpchannum = (uint16_t)ConvertBitIntoBytes(&cs_pdu_bits[16], 12); + uint16_t lpchannum = (uint16_t)ConvertBitIntoBytes(&cs_pdu_bits[16], 12); if (lpchannum == 0) fprintf (stderr, " - Invalid Channel"); //invalid channel, not sure why this would even be transmitted else if (lpchannum == 0xFFF) fprintf (stderr, " - Absolute"); //This is from an MBC, signalling an absolute and not a logical else fprintf (stderr, " - Logical"); @@ -170,7 +170,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 fprintf (stderr, "\n"); fprintf (stderr, " RX APCN: %04d; RX INT: %d; RX STEP: %d;", mbc_lpchannum, mbc_abs_rx_int, mbc_abs_rx_step ); //The Frequency we want to tune is the RX Frequency - freq = (mbc_abs_rx_int * 1000000 ) + (mbc_abs_rx_step * 125); + freq = (mbc_abs_rx_int * 1000000 ) + (mbc_abs_rx_step * 125); } else fprintf (stderr, "\n MBC Channel Grant - Unknown Parms: %015llX", mbc_cdefparms); //for any reserved values } @@ -194,7 +194,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 if (csbk_o == 49 || csbk_o == 50) sprintf (state->active_channel[lcn], "Active Group Ch: %d TG: %d; ", lpchannum, target); else if (csbk_o == 51 || csbk_o == 52 || csbk_o == 54 || csbk_o == 55 || csbk_o == 56) sprintf (state->active_channel[lcn], "Active Data Ch: %d TG: %d; ", lpchannum, target); else sprintf (state->active_channel[lcn], "Active Private Ch: %d TG: %d; ", lpchannum, target); - } + } else if (lpchannum == 0xFFF) { if (csbk_o == 49 || csbk_o == 50) sprintf (state->active_channel[lcn], "Active Group Ch: %d TG: %d; ", mbc_lpchannum, target); @@ -219,24 +219,24 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 //Skip tuning private calls if private calls are disabled if (opts->trunk_tune_private_calls == 0 && csbk_o != 49) goto SKIPCALL; - + //if not a data channel grant (only tuning to voice channel grants) if (csbk_o == 48 || csbk_o == 49 || csbk_o == 50 || csbk_o == 53) //48, 49, 50 are voice grants, 51 and 52 are data grants, 53 Duplex Private Voice, 54 Duplex Private Data { - + //if tg hold is specified and matches target, allow for a call pre-emption by nullifying the last vc sync time if (state->tg_hold != 0 && state->tg_hold == target) state->last_vc_sync_time = 0; //TIII tuner fix if voice assignment occurs to the control channel itself, //then it may not want to resume tuning due to no framesync loss after call ends - if ( (time(NULL) - state->last_vc_sync_time > 2) ) + if ( (time(NULL) - state->last_vc_sync_time > 2) ) { opts->p25_is_tuned = 0; //zero out vc frequencies state->p25_vc_freq[0] = 0; state->p25_vc_freq[1] = 0; - } + } //shim in here for ncurses freq display when not trunking (playback, not live) if (opts->p25_trunk == 0 && freq != 0) @@ -247,7 +247,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 } //don't tune if currently a vc on the control channel - if ( (time(NULL) - state->last_vc_sync_time > 2) ) + if ( (time(NULL) - state->last_vc_sync_time > 2) ) { char mode[8]; //allow, block, digital, enc, etc sprintf (mode, "%s", ""); @@ -270,7 +270,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 if (state->tg_hold != 0 && state->tg_hold != target) sprintf (mode, "%s", "B"); if (state->tg_hold != 0 && state->tg_hold == target) sprintf (mode, "%s", "A"); - if (state->p25_cc_freq != 0 && opts->p25_trunk == 1 && (strcmp(mode, "B") != 0) && (strcmp(mode, "DE") != 0)) + if (state->p25_cc_freq != 0 && opts->p25_trunk == 1 && (strcmp(mode, "B") != 0) && (strcmp(mode, "DE") != 0)) { if (freq != 0) //if we have a valid frequency { @@ -325,10 +325,10 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 if (GetCurrentFreq(opts->rigctl_sockfd) != freq) SetFreq(opts->rigctl_sockfd, freq); state->p25_vc_freq[0] = state->p25_vc_freq[1] = freq; - opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop + opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop state->last_vc_sync_time = time(NULL); state->last_t3_tune_time = time(NULL); //set here so a random p_clear on the opposite slot doesn't send us back to the CC - + } //rtl @@ -396,7 +396,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 } SKIPCALL: ; //do nothing - + } //Move @@ -405,9 +405,9 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 //initial line break fprintf (stderr, "\n"); fprintf (stderr, " Move (C_MOVE) "); - } + } - //Aloha + //Aloha if (csbk_o == 25) { //initial line break @@ -415,7 +415,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 dmr_decode_syscode(opts, state, cs_pdu_bits, csbk_fid, 0); - //if using rigctl we can set an unknown or updated cc frequency + //if using rigctl we can set an unknown or updated cc frequency //by polling rigctl for the current frequency if (opts->use_rigctl == 1 && opts->p25_is_tuned == 0) //&& state->p25_cc_freq == 0 { @@ -429,8 +429,8 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 ccfreq = (long int)opts->rtlsdr_center_freq; if (ccfreq != 0) state->p25_cc_freq = ccfreq; } - - } + + } //P_CLEAR if (csbk_o == 46) @@ -504,7 +504,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 //display/le/buzzer bug fix when p_clear activated (unsure why this was disabled) //clear only the current slot initially, then clear both if tuning to a different freq - if (state->currentslot == 0 && csbk_fid != 253) //don't reset on Cap+ since we aren't testing based on the current TS + if (state->currentslot == 0 && csbk_fid != 253) //don't reset on Cap+ since we aren't testing based on the current TS { state->payload_mi = 0; state->payload_algid = 0; @@ -518,7 +518,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 state->payload_keyidR = 0; state->dmr_soR = 0; } - + //rigctl if (opts->use_rigctl == 1) { @@ -549,7 +549,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 state->p25_vc_freq[0] = state->p25_vc_freq[1] = 0; if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); if (GetCurrentFreq(opts->rigctl_sockfd) != state->p25_cc_freq) - SetFreq(opts->rigctl_sockfd, state->p25_cc_freq); + SetFreq(opts->rigctl_sockfd, state->p25_cc_freq); } //rtl @@ -592,8 +592,8 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 } //end if trunking is enabled #else UNUSED (clear); UNUSED(pslot); UNUSED(oslot); - #endif //end if PCLEAR_TUNE_AWAY is enabled in code - } + #endif //end if PCLEAR_TUNE_AWAY is enabled in code + } //(P_PROTECT) if (csbk_o == 47) @@ -622,7 +622,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 //check the source and/or target for special gateway identifiers dmr_gateway_identifier (source, target); - //change this slot burst type to VLC so the revamped p_clear doesn't tune away + //change this slot burst type to VLC so the revamped p_clear doesn't tune away if (opts->p25_trunk == 1) { if (gi && opts->trunk_tune_group_calls == 1) @@ -669,7 +669,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 //syscode start 40, len 16 uint16_t syscode = (uint32_t)ConvertBitIntoBytes(&cs_pdu_bits[40], 14); - + //parms2 start 56, len 24 uint32_t bparms2 = (uint32_t)ConvertBitIntoBytes(&cs_pdu_bits[56], 24); uint8_t bpbits2[24]; for (i = 0; i < 24; i++) bpbits2[i] = cs_pdu_bits[56+i]; @@ -739,7 +739,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 uint8_t lt_mon = (uint8_t)ConvertBitIntoBytes(&bpbits1[5], 4); //1-12, or 0 if not broadcast uint8_t lt_off = (uint8_t)ConvertBitIntoBytes(&bpbits1[9], 4); //0-14 hours, or 15 if not broadcast uint8_t lt_off_sign = bpbits1[13]; //0 is positive offset, 1 is negative offset - + uint8_t lt_hour = (uint8_t)ConvertBitIntoBytes(&bpbits2[0], 5); //0-23 uint8_t lt_mins = (uint8_t)ConvertBitIntoBytes(&bpbits2[5], 6); //0-59 uint8_t lt_secs = (uint8_t)ConvertBitIntoBytes(&bpbits2[11], 6); //0-59 @@ -755,13 +755,13 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 //I wonder if local offset will require rollover or rollunder if (lt_off_sign == 1) localhour = lt_hour - lt_off; if (lt_off_sign == 0) localhour = lt_hour + lt_off; - + if (lt_off_fr == 1) localmin += 15; if (lt_off_fr == 2) localmin += 30; if (lt_off_fr == 3) localmin += 45; fprintf (stderr, "\n"); - if (lt_mon != 0 && lt_day != 0) + if (lt_mon != 0 && lt_day != 0) fprintf (stderr, " Date: %d.%d;", lt_mon, lt_day); //day of the week, 1 is Sunday, 7 is Saturday, 0 not broadcasted if (lt_dofw == 1) fprintf (stderr, " Sunday;"); @@ -825,9 +825,9 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 // if (state->lcn_freq_count > 25) state->lcn_freq_count = 25; // } // } - + } - else + else { fprintf (stderr, "\n Unknown CDEFType: %X; CDEFParms: %015llX", mbc_cdeftype, mbc_cdefparms); fprintf (stderr, " MBC Op: %02X;", mbc_csbko); @@ -838,7 +838,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 } } - //Vote Now, Adjacent Site, + //Vote Now, Adjacent Site, if (a_type == 2 || a_type == 6) { uint8_t active_ava = bpbits2[0]; @@ -883,9 +883,9 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 fprintf (stderr, " RX Base: %d; RX Step: %d; RX Freq: %ld;", mbc_abs_rx_int * 1000000, mbc_abs_rx_step * 125, freqr); fprintf (stderr, "\n "); //12 spaces fprintf (stderr, " TX Base: %d; TX Step: %d; TX Freq: %ld;", mbc_abs_tx_int * 1000000, mbc_abs_tx_step * 125, freqt); - + } - else + else { fprintf (stderr, "\n Unknown CDEFType: %X; CDEFParms: %015llX", mbc_cdeftype, mbc_cdefparms); fprintf (stderr, " MBC Op: %02X;", mbc_csbko); @@ -956,7 +956,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 } - if (csbk_o == 28) + if (csbk_o == 28) { //initial line break fprintf (stderr, "\n"); @@ -1002,7 +1002,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 } - if (csbk_o == 42) + if (csbk_o == 42) { //initial line break fprintf (stderr, "\n"); @@ -1027,7 +1027,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 dmr_gateway_identifier (pm_source, pm_target); } - if (csbk_o == 30) + if (csbk_o == 30) { //initial line break fprintf (stderr, "\n"); @@ -1037,7 +1037,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 if (csbk_fid != 0x10) //if Not Motorola { //These opcodes to exist on CapMax as well, but don't function the same - if (csbk_o == 32 || csbk_o == 33 || csbk_o == 34 || csbk_o == 35) + if (csbk_o == 32 || csbk_o == 33 || csbk_o == 34 || csbk_o == 35) { //initial line break fprintf (stderr, "\n"); //(Acknowledgement) @@ -1054,7 +1054,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 uint32_t ack_source = (uint32_t)ConvertBitIntoBytes(&cs_pdu_bits[56], 24); //response_info and reason_code start to get really convoluted on decoding them - //for each opcode, so I am just going to put the values out to the console, + //for each opcode, so I am just going to put the values out to the console, //look at ETSI TS 102 361-4 V1.12.1 7.2.7 for more info fprintf (stderr, "Response: %02X; Reason: %02X; ", response_info, reason_code); @@ -1067,7 +1067,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 } } - if (csbk_o == 31) + if (csbk_o == 31) { //initial line break fprintf (stderr, "\n"); @@ -1135,12 +1135,12 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 uint32_t source = (uint32_t)ConvertBitIntoBytes(&cs_pdu_bits[56], 24); UNUSED2(res, blocks); - uint8_t target_hash[24]; - uint8_t tg_hash = 0; + uint8_t target_hash[24]; + uint8_t tg_hash = 0; if (gi == 0) fprintf (stderr, "Individual "); else fprintf (stderr, "Group "); - + if (content == 0) fprintf (stderr, "CSBK - "); else fprintf (stderr, "Data - "); @@ -1201,8 +1201,8 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 // 01:15:08 Sync: +DMR slot1 [slot2] | Color Code=03 | CSBK // Capacity Plus Channel Status - FL: 3 TS: 1 RS: 0 - Rest Channel 1 - Single Block - // Ch1: Rest Ch2: Idle Ch3: Idle Ch4: Idle - // Ch5: Idle Ch6: Idle Ch7: Idle Ch8: Idle + // Ch1: Rest Ch2: Idle Ch3: Idle Ch4: Idle + // Ch5: Idle Ch6: Idle Ch7: Idle Ch8: Idle // DMR PDU Payload [BE][10][E1][00][00][00][00][00][00][00][4E][15] // 01:15:08 Sync: +DMR [slot1] slot2 | Color Code=03 | CSBK @@ -1246,10 +1246,10 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 fprintf (stderr, "\n"); fprintf (stderr, "%s", KYEL); - uint8_t fl = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[16], 2); + uint8_t fl = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[16], 2); uint8_t ts = cs_pdu_bits[18]; //timeslot this PDU occurs in uint8_t res = cs_pdu_bits[19]; //unknown or unused bit value - uint8_t rest_channel = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[20], 4); + uint8_t rest_channel = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[20], 4); uint8_t group_tally = 0; //set this to the number of active channels tallied uint8_t bank_one = 0; uint8_t bank_two = 0; @@ -1263,7 +1263,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 uint8_t end = 8; uint8_t fl_bytes = 0; uint8_t ch[24]; //one bit per channel - uint8_t pch[24]; //private or data call channel bits + uint8_t pch[24]; //private or data call channel bits uint16_t tg = 0; int i, j, k, x; //tg and channel info for trunking purposes @@ -1285,7 +1285,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 memset (empty, 0, sizeof(empty)); //treating FL as a form of LCSS - if (fl == 2 || fl == 3) //initial or single block (fl2 or fl3) + if (fl == 2 || fl == 3) //initial or single block (fl2 or fl3) { //NOTE: this has been changed to store per slot memset (state->cap_plus_csbk_bits[ts], 0, sizeof(state->cap_plus_csbk_bits[ts])); @@ -1298,11 +1298,11 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 block_num++; state->cap_plus_block_num[ts]++; } - + //move assignment until later when evaluating for a p_clear condition if (rest_channel != state->dmr_rest_channel) { - state->dmr_rest_channel = rest_channel; + state->dmr_rest_channel = rest_channel; } //assign to cc freq to follow during no sync @@ -1315,7 +1315,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 fprintf (stderr, " Capacity Plus Channel Status - FL: %d TS: %d RS: %d - Rest LSN: %d", fl, ts, res, rest_channel); if (fl == 0) fprintf (stderr, " - Appended Block"); //have not yet observed a system use this fl value - if (fl == 1) fprintf (stderr, " - Final Block"); + if (fl == 1) fprintf (stderr, " - Final Block"); if (fl == 2) fprintf (stderr, " - Initial Block"); if (fl == 3) fprintf (stderr, " - Single Block"); @@ -1337,7 +1337,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 for (int i = 0; i < 8; i++) { ch[i+8] = state->cap_plus_csbk_bits[ts][i+32+(b2_start*8)]; - if (ch[i+8] == 1) group_tally++; + if (ch[i+8] == 1) group_tally++; } } @@ -1345,7 +1345,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 pdflag = (uint8_t)ConvertBitIntoBytes(&state->cap_plus_csbk_bits[ts][40+(group_tally*8)], 8); //check for private activity on LSNs 1-8 - if (fl == 1 || fl == 3) + if (fl == 1 || fl == 3) { if (pdflag) //== 0x80 //testing denny's 0x80 or 0x90 flag discovery { @@ -1361,8 +1361,8 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 private_target = (uint16_t)ConvertBitIntoBytes(&state->cap_plus_csbk_bits[ts][56+(k*16)+(group_tally*8)], 16); fprintf (stderr, " TGT %d;", private_target); k++; - if (bank_one == 0) bank_one = 0xFF; //set all bits on so we can atleast parse all of them below in listing/display - } + if (bank_one == 0) bank_one = 0xFF; //set all bits on so we can atleast parse all of them below in listing/display + } } //save for starting point of the next private call bank pd_b2 = k; @@ -1374,7 +1374,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 pdflag2 = (uint8_t)ConvertBitIntoBytes(&state->cap_plus_csbk_bits[ts][56+(group_tally*8)+(pd_b2*16)], 8); //48 -- had wrong value here (atleast in the one sample with the false positive) //check for private activity on LSNs 9-16 - if (fl == 1 || fl == 3) + if (fl == 1 || fl == 3) { //then check to see if this byte has a value, should be 0x80, could be other? //this bytes location shifts depending on level of activity -- see banks above @@ -1392,8 +1392,8 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 private_target = (uint16_t)ConvertBitIntoBytes(&state->cap_plus_csbk_bits[ts][64+(k*16)+(group_tally*8)+(pd_b2*16)], 16); //56 -- had wrong value here (atleast in the one sample with the false positive) fprintf (stderr, " TGT %d;", private_target); k++; - if (bank_two == 0) bank_two = 0xFF; //set all bits on so we can atleast parse all of them below in listing/display - } + if (bank_two == 0) bank_two = 0xFF; //set all bits on so we can atleast parse all of them below in listing/display + } } } } @@ -1407,7 +1407,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 memset (state->active_channel, 0, sizeof(state->active_channel)); sprintf (state->active_channel[0], "Cap+ "); state->last_active_time = time(NULL); - + k = 0; x = 0; @@ -1416,7 +1416,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 //being a four liner CSBK when there is little or no activity //start position; - start = 0; + start = 0; if (bank_one & 0xF0) start = 0; else if (rest_channel < 5) start = 0; @@ -1461,38 +1461,38 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 fprintf (stderr, "LSN %02d: ", i+1); if (ch[i] == 1) //group voice channels { - + tg = (uint16_t)ConvertBitIntoBytes(&state->cap_plus_csbk_bits[ts][(k*8)+32], 8); if (tg != 0) fprintf (stderr, "%5d; ", tg); - else fprintf (stderr, "Group; "); - //flag as available for tuning if group calls enabled + else fprintf (stderr, "Group; "); + //flag as available for tuning if group calls enabled if (opts->trunk_tune_group_calls == 1) t_tg[i] = tg; if (tg != 0) k++; //add active channel to display string sprintf (cap_active, "LSN:%d TG:%d; ", i+1, tg); - strcat (state->active_channel[i+1], cap_active); + strcat (state->active_channel[i+1], cap_active); } else if (pch[i] == 1) //private or data channels { tg = (uint16_t)ConvertBitIntoBytes(&state->cap_plus_csbk_bits[ts][(group_tally*8)+(x*16)+56], 16); //don't change this AGAIN!, this is correct! if (tg != 0) fprintf (stderr, "%5d; ", tg); else fprintf (stderr, " P||D; "); - //flag as available for tuning if private calls enabled + //flag as available for tuning if private calls enabled if (opts->trunk_tune_private_calls == 1) t_tg[i] = tg; //ch[i] = 1; if (tg != 0) x++; //add active channel to display string - - //NOTE: Consider only adding this if user toggled or else + + //NOTE: Consider only adding this if user toggled or else //lots of short data bursts blink in and out if (1 == 1) //opts->trunk_tune_private_calls { sprintf (cap_active, "LSN:%d PC:%d; ", i+1, tg); strcat (state->active_channel[i+1], cap_active); } - - } + + } else if (i+1 == rest_channel) fprintf (stderr, " Rest; "); else fprintf (stderr, " Idle; "); @@ -1521,8 +1521,8 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 //when a TG hold is specified but nether slot carries the TG on Hold; //CODED: using slow link control for that - //don't tune if vc on the current channel - if ( (time(NULL) - state->last_vc_sync_time > 2) ) + //don't tune if vc on the current channel + if ( (time(NULL) - state->last_vc_sync_time > 2) ) { for (j = start; j < end; j++) //go through the channels stored looking for active ones to tune to { @@ -1548,11 +1548,11 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 if (state->tg_hold != 0 && state->tg_hold == t_tg[j]) sprintf (mode, "%s", "A"); //without priority, this will tune the first one it finds (if group isn't blocked) - if (t_tg[j] != 0 && state->p25_cc_freq != 0 && opts->p25_trunk == 1 && (strcmp(mode, "B") != 0) && (strcmp(mode, "DE") != 0)) + if (t_tg[j] != 0 && state->p25_cc_freq != 0 && opts->p25_trunk == 1 && (strcmp(mode, "B") != 0) && (strcmp(mode, "DE") != 0)) { //debug print for tuning verification // fprintf (stderr, "\n LSN/TG to tune to: %d - %d", j+1, t_tg[j]); - + if (state->trunk_chan_map[j+1] != 0) //if we have a valid frequency { //RIGCTL @@ -1577,10 +1577,10 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 } if (GetCurrentFreq(opts->rigctl_sockfd) != state->trunk_chan_map[j+1]) dmr_reset_blocks (opts, state); //reset all block gathering since we are tuning away from current frequency - if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); - SetFreq(opts->rigctl_sockfd, state->trunk_chan_map[j+1]); + if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); + SetFreq(opts->rigctl_sockfd, state->trunk_chan_map[j+1]); state->p25_vc_freq[0] = state->p25_vc_freq[1] = state->trunk_chan_map[j+1]; - opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop + opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop state->last_vc_sync_time = time(NULL); j = 11; //break loop } @@ -1632,10 +1632,10 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 //debug print if (fl == 1 && opts->payload == 1) { - fprintf (stderr, "%s\n", KYEL); + fprintf (stderr, "%s\n", KYEL); fprintf (stderr, " CAP+ Multi Block PDU \n "); fl_bytes = 0; - for (i = 0; i < (10+(block_num*7)); i++) + for (i = 0; i < (10+(block_num*7)); i++) { fl_bytes = (uint8_t)ConvertBitIntoBytes(&state->cap_plus_csbk_bits[ts][i*8], 8); fprintf (stderr, "[%02X]", fl_bytes); @@ -1664,7 +1664,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 uint8_t dummy[12]; uint8_t* dbits; memset (dummy, 0, sizeof(dummy)); dummy[0] = 46; dummy[1] = 253; dmr_cspdu (opts, state, dbits, dummy, 1, 0); } - + } //if (fl == 1 || fl == 3) } //opcode == 0x3E @@ -1673,17 +1673,17 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 //Connect+ Section if (csbk_fid == 0x06) { - //Con+ Adjacent Site + //Con+ Adjacent Site if (csbk_o == 0x01) { - uint8_t nb1 = cs_pdu[2] & 0x3F; - uint8_t nb2 = cs_pdu[3] & 0x3F; - uint8_t nb3 = cs_pdu[4] & 0x3F; - uint8_t nb4 = cs_pdu[5] & 0x3F; + uint8_t nb1 = cs_pdu[2] & 0x3F; + uint8_t nb2 = cs_pdu[3] & 0x3F; + uint8_t nb3 = cs_pdu[4] & 0x3F; + uint8_t nb4 = cs_pdu[5] & 0x3F; uint8_t nb5 = cs_pdu[6] & 0x3F; //initial line break - fprintf (stderr, "\n"); + fprintf (stderr, "\n"); fprintf (stderr, "%s", KYEL); fprintf (stderr, " Connect Plus Adjacent Sites:"); if (nb1 != 0) fprintf (stderr, " %d;", nb1); @@ -1692,7 +1692,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 if (nb4 != 0) fprintf (stderr, " %d;", nb4); if (nb5 != 0) fprintf (stderr, " %d;", nb5); if (nb1 == 0) fprintf (stderr, " None Listed;"); - state->dmr_mfid = 0x06; + state->dmr_mfid = 0x06; sprintf (state->dmr_branding, "%s", "Motorola"); sprintf(state->dmr_branding_sub, "Con+ "); @@ -1715,13 +1715,13 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 //the 02/03 holds up on a few samples from different systems, also seems //that encrypted calls are not bit flipped here */ - + //initial line break fprintf (stderr, "\n"); - uint32_t srcAddr = ( (cs_pdu[2] << 16) + (cs_pdu[3] << 8) + cs_pdu[4] ); - uint32_t grpAddr = ( (cs_pdu[5] << 16) + (cs_pdu[6] << 8) + cs_pdu[7] ); - uint8_t lcn = ( (cs_pdu[8] & 0xF0 ) >> 4 ); - uint8_t tslot = ( (cs_pdu[8] & 0x08 ) >> 3 ) & 1; + uint32_t srcAddr = ( (cs_pdu[2] << 16) + (cs_pdu[3] << 8) + cs_pdu[4] ); + uint32_t grpAddr = ( (cs_pdu[5] << 16) + (cs_pdu[6] << 8) + cs_pdu[7] ); + uint8_t lcn = ( (cs_pdu[8] & 0xF0 ) >> 4 ); + uint8_t tslot = ( (cs_pdu[8] & 0x08 ) >> 3 ) & 1; uint8_t opt = cs_pdu[9]; //call options? May only be a few of the LSB honestly fprintf (stderr, "%s", KYEL); if (opt == 2) @@ -1731,7 +1731,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 else fprintf (stderr, " Connect Plus Unknown %02X Channel Grant;", opt); fprintf (stderr, " Target: %d; Source: %d; LCN: %d; TS: %d;", grpAddr, srcAddr, lcn, tslot+1); // fprintf (stderr, " OPT: %02X;", opt); //debug - state->dmr_mfid = 0x06; + state->dmr_mfid = 0x06; sprintf (state->dmr_branding, "%s", "Motorola"); sprintf(state->dmr_branding_sub, "Con+ "); @@ -1801,10 +1801,10 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 waitsec = 4; //increase time for a data call before hopping //don't tune if currently a vc on the control channel, but allow hopping form one VC to another VC if the former is in long TLC/Idle mode - if ( (opts->trunk_tune_group_calls == 1) && (time(NULL) - state->last_vc_sync_time > waitsec) ) + if ( (opts->trunk_tune_group_calls == 1) && (time(NULL) - state->last_vc_sync_time > waitsec) ) { - - if (state->p25_cc_freq != 0 && opts->p25_trunk == 1 && (strcmp(mode, "B") != 0) && (strcmp(mode, "DE") != 0) ) + + if (state->p25_cc_freq != 0 && opts->p25_trunk == 1 && (strcmp(mode, "B") != 0) && (strcmp(mode, "DE") != 0) ) { if (state->trunk_chan_map[lcn] != 0) //if we have a valid frequency { @@ -1812,7 +1812,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 if (opts->use_rigctl == 1) { if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); - SetFreq(opts->rigctl_sockfd, state->trunk_chan_map[lcn]); + SetFreq(opts->rigctl_sockfd, state->trunk_chan_map[lcn]); state->p25_vc_freq[0] = state->p25_vc_freq[1] = state->trunk_chan_map[lcn]; opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop state->is_con_plus = 1; //flag on @@ -1835,7 +1835,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 } } - } + } SKIPCON: ; //do nothing @@ -1844,16 +1844,16 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 //Con+ Data Channel Grant if (csbk_o == 0x06) { - + //initial line break fprintf (stderr, "\n"); - uint32_t dtarget = ( (cs_pdu[2] << 16) + (cs_pdu[3] << 8) + cs_pdu[4] ); - uint8_t lcn = ( (cs_pdu[5] & 0xF0 ) >> 4 ); - uint8_t tslot = ( (cs_pdu[5] & 0x08 ) >> 3 ) & 1; + uint32_t dtarget = ( (cs_pdu[2] << 16) + (cs_pdu[3] << 8) + cs_pdu[4] ); + uint8_t lcn = ( (cs_pdu[5] & 0xF0 ) >> 4 ); + uint8_t tslot = ( (cs_pdu[5] & 0x08 ) >> 3 ) & 1; fprintf (stderr, "%s", KYEL); fprintf (stderr, " Connect Plus Data Channel Grant;"); fprintf (stderr, " Target: %d; LCN: %d; TS: %d;", dtarget, lcn, tslot+1); - state->dmr_mfid = 0x06; + state->dmr_mfid = 0x06; sprintf (state->dmr_branding, "%s", "Motorola"); sprintf(state->dmr_branding_sub, "Con+ "); @@ -1903,10 +1903,10 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 // if (state->tg_hold != 0 && state->tg_hold == dtarget) sprintf (mode, "%s", "A"); //don't tune if currently a vc on the control channel - if ( (opts->trunk_tune_data_calls == 1) && (time(NULL) - state->last_vc_sync_time > 2) ) + if ( (opts->trunk_tune_data_calls == 1) && (time(NULL) - state->last_vc_sync_time > 2) ) { - - if (state->p25_cc_freq != 0 && opts->p25_trunk == 1 && (strcmp(mode, "B") != 0) && (strcmp(mode, "DE") != 0) ) + + if (state->p25_cc_freq != 0 && opts->p25_trunk == 1 && (strcmp(mode, "B") != 0) && (strcmp(mode, "DE") != 0) ) { if (state->trunk_chan_map[lcn] != 0) //if we have a valid frequency { @@ -1914,7 +1914,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 if (opts->use_rigctl == 1) { if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); - SetFreq(opts->rigctl_sockfd, state->trunk_chan_map[lcn]); + SetFreq(opts->rigctl_sockfd, state->trunk_chan_map[lcn]); state->p25_vc_freq[0] = state->p25_vc_freq[1] = state->trunk_chan_map[lcn]; opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop state->is_con_plus = 1; //flag on @@ -1937,7 +1937,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 } } - } + } SKIPCOND: ; //do nothing @@ -1949,7 +1949,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 //initial line break fprintf (stderr, "\n"); - uint32_t ttarget = ( (cs_pdu[2] << 16) + (cs_pdu[3] << 8) + cs_pdu[4] ); + uint32_t ttarget = ( (cs_pdu[2] << 16) + (cs_pdu[3] << 8) + cs_pdu[4] ); fprintf (stderr, "%s", KYEL); fprintf (stderr, " Connect Plus Slot Termination;"); fprintf (stderr, " Target: %d;", ttarget); @@ -1958,7 +1958,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 uint8_t dummy[12]; uint8_t* dbits; memset (dummy, 0, sizeof(dummy)); dummy[0] = 46; dummy[1] = 12; dmr_cspdu (opts, state, dbits, dummy, 1, 0); - state->dmr_mfid = 0x06; + state->dmr_mfid = 0x06; sprintf (state->dmr_branding, "%s", "Motorola"); sprintf(state->dmr_branding_sub, "Con+ "); @@ -1971,11 +1971,11 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 //Hytera XPT -- Experimental, but values now seem very consistent and trunking is working on systems tested with if (csbk_fid == 0x68) { - //XPT Site Status + //XPT Site Status if (csbk_o == 0x0A) { //initial line break - fprintf (stderr, "\n"); + fprintf (stderr, "\n"); fprintf (stderr, "%s", KYEL); uint8_t xpt_ch[6]; //one tg/call per LSN @@ -1993,10 +1993,10 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 //determine starting position of LCN value if (xpt_seq == 1) xpt_lcn = 4; - if (xpt_seq == 2) xpt_lcn = 7; + if (xpt_seq == 2) xpt_lcn = 7; //determine xpt_bank value for LSN value/tuning - if (xpt_seq) xpt_bank = xpt_seq*6; + if (xpt_seq) xpt_bank = xpt_seq*6; //get 2-bit status values for each 6 LSNs for (i = 0; i < 6; i++) xpt_ch[i] = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[20+(i*2)], 2); @@ -2009,21 +2009,21 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 else sprintf (state->active_channel[xpt_seq], "%s", ""); //blank current sequence to re-write to state->last_active_time = time(NULL); - //Print List of LCN with LSN Activity - for (i = 0; i < 6; i++) + //Print List of LCN with LSN Activity + for (i = 0; i < 6; i++) { //add LCN value for each LSN pair to help users differentiate between the two when seeing LCN on FLC if (i == 0 || i == 2 || i == 4) { fprintf (stderr, "\n LCN %d - ", xpt_lcn); xpt_lcn++; - } - + } + //LSN value here is logical slot, in flco, we get the logical channel (which is the repeater, does not include the slot value) fprintf (stderr, "LSN %02d: ", i+xpt_bank+1); //swapped out xpt_bank for all (xpt_seq*6) to simplify things tg = (uint16_t)ConvertBitIntoBytes(&cs_pdu_bits[i*8+32], 8); fprintf (stderr, "ST-%X", xpt_ch[i]); //status bits value 0,1,2, or 3 - if (tg != 0) fprintf (stderr, " %03d; ", tg); + if (tg != 0) fprintf (stderr, " %03d; ", tg); else { if (xpt_ch[i] == 3) fprintf (stderr, " Null; "); //NULL on ST-3 indicates repeater is not active for the LSNs that would be covered by these bits @@ -2067,17 +2067,17 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 sprintf (state->dmr_site_parms, "Free LCN - %d ", xpt_free); //assign to cc freq to follow during no sync - long int ccfreq = 0; + long int ccfreq = 0; - //if using rigctl we can set an unknown or updated cc frequency - if (opts->use_rigctl == 1 ) + //if using rigctl we can set an unknown or updated cc frequency + if (opts->use_rigctl == 1 ) { ccfreq = GetCurrentFreq (opts->rigctl_sockfd); if (ccfreq != 0) { state->p25_cc_freq = ccfreq; opts->p25_is_tuned = 1; - } + } } //if using rtl input, we can ask for the current frequency tuned @@ -2088,7 +2088,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 { state->p25_cc_freq = ccfreq; opts->p25_is_tuned = 1; - } + } } @@ -2105,7 +2105,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 //when a TG hold is specified but nether slot carries the TG on Hold; //CODED: using Free repeater in SLC to change over if required - //don't tune if vc on the current channel + //don't tune if vc on the current channel if ( (time(NULL) - state->last_vc_sync_time) > 2 ) //parenthesis error fixed { for (j = 0; j < 6; j++) //go through the channels stored looking for active ones to tune to @@ -2135,7 +2135,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 if (state->tg_hold != 0 && state->tg_hold == t_tg[j+xpt_bank]) sprintf (mode, "%s", "A"); //without priority, this will tune the first one it finds (if group isn't blocked) - if (t_tg[j+xpt_bank] != 0 && state->p25_cc_freq != 0 && opts->p25_trunk == 1 && (strcmp(mode, "B") != 0) && (strcmp(mode, "DE") != 0)) + if (t_tg[j+xpt_bank] != 0 && state->p25_cc_freq != 0 && opts->p25_trunk == 1 && (strcmp(mode, "B") != 0) && (strcmp(mode, "DE") != 0)) { //debug print for tuning verification fprintf (stderr, "\n LSN/TG to tune to: %d - %d", j+xpt_bank+1, t_tg[j+xpt_bank]); @@ -2163,15 +2163,15 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 //end TG set on tune } - //debug + //debug // fprintf (stderr, " - Freq: %ld", state->trunk_chan_map[j+xpt_bank+1]); if (GetCurrentFreq(opts->rigctl_sockfd) != state->trunk_chan_map[j+xpt_bank+1]) dmr_reset_blocks (opts, state); //reset all block gathering since we are tuning away from current frequency - if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); - SetFreq(opts->rigctl_sockfd, state->trunk_chan_map[j+xpt_bank+1]); + if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); + SetFreq(opts->rigctl_sockfd, state->trunk_chan_map[j+xpt_bank+1]); state->p25_vc_freq[0] = state->p25_vc_freq[1] = state->trunk_chan_map[j+xpt_bank+1]; - opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop + opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop j = 11; //break loop } @@ -2205,7 +2205,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 //debug print for tuning verification fprintf (stderr, " - Tune to Freq: %ld", state->trunk_chan_map[j+xpt_bank+1]); } - else fprintf (stderr, " - Dont Tune Freq: %ld", state->trunk_chan_map[j+xpt_bank+1]); + else fprintf (stderr, " - Dont Tune Freq: %ld", state->trunk_chan_map[j+xpt_bank+1]); state->p25_vc_freq[0] = state->p25_vc_freq[1] = state->trunk_chan_map[j+xpt_bank+1]; opts->p25_is_tuned = 1; j = 11; //break loop @@ -2237,7 +2237,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 { //initial line break - fprintf (stderr, "\n"); + fprintf (stderr, "\n"); fprintf (stderr, "%s", KYEL); int i; @@ -2247,7 +2247,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 uint8_t xpt_site_u2[4]; UNUSED2(xpt_site_u1, xpt_site_u2); - uint8_t xpt_sn = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[0], 2); + uint8_t xpt_sn = (uint8_t)ConvertBitIntoBytes(&cs_pdu_bits[0], 2); for (i = 0; i < 4; i++) { @@ -2262,7 +2262,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 fprintf (stderr, " XPT Adjacent "); for (i = 0; i < 4; i++) { - if (xpt_site_id[i] != 0) + if (xpt_site_id[i] != 0) { fprintf (stderr, "Site:%d Free:%d; ", xpt_site_id[i], xpt_site_rp[i]); // fprintf (stderr, "RS1: %d RS2: %d - ", xpt_site_u1[i], xpt_site_u2[i]); //debug @@ -2278,7 +2278,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 if (csbk_o == 41 && csbk_fid == 0x10) { //initial line break - fprintf (stderr, "\n"); + fprintf (stderr, "\n"); fprintf (stderr, "%s", KYEL); fprintf (stderr, " Moto Data Channel: %02X; ", csbk_o); for (int i = 2; i < 10; i++) @@ -2291,7 +2291,7 @@ void dmr_cspdu (dsd_opts * opts, dsd_state * state, uint8_t cs_pdu_bits[], uint8 } - fprintf (stderr, "%s", KNRM); + fprintf (stderr, "%s", KNRM); } @@ -2361,7 +2361,7 @@ void dmr_decode_syscode(dsd_opts * opts, dsd_state * state, uint8_t * cs_pdu_bit //bparms1 uint8_t bpbits1[14]; for (i = 0; i < 14; i++) bpbits1[i] = cs_pdu_bits[21+i]; - //if not C_ALOHA_SYS_PARMS, overwrite syscode with bparms1 (too lazy method) + //if not C_ALOHA_SYS_PARMS, overwrite syscode with bparms1 (too lazy method) if (type != 0) { for (i = 0; i < 14; i++) @@ -2426,7 +2426,7 @@ void dmr_decode_syscode(dsd_opts * opts, dsd_state * state, uint8_t * cs_pdu_bit opts->dmr_dmrla_n = 0; sprintf (state->dmr_branding, "%s", "Motorola"); // sprintf (state->dmr_branding_sub, "%s", "CapMax "); - } + } if (opts->dmr_dmrla_is_set == 1) n = opts->dmr_dmrla_n; @@ -2447,7 +2447,7 @@ void dmr_decode_syscode(dsd_opts * opts, dsd_state * state, uint8_t * cs_pdu_bit if (par == 2) sprintf (par_str, "%s", "B"); if (par == 3) sprintf (par_str, "%s", "AB"); - uint32_t target = (uint32_t)ConvertBitIntoBytes(&cs_pdu_bits[56], 24); + uint32_t target = (uint32_t)ConvertBitIntoBytes(&cs_pdu_bits[56], 24); if (type == 0) { @@ -2457,7 +2457,7 @@ void dmr_decode_syscode(dsd_opts * opts, dsd_state * state, uint8_t * cs_pdu_bit else fprintf (stderr, " C_ALOHA_SYS_PARMS: %s; Net ID: %d; Site ID: %d;", model_str, net, site); fprintf (stderr, " SYS: %04X;", syscode); //#192 if (is_capmax) fprintf (stderr, " Capacity Max"); - + if (opts->payload == 1) { fprintf (stderr, "\n"); diff --git a/src/dmr_data.c b/src/dmr_data.c index 8b43f48..c66c57e 100644 --- a/src/dmr_data.c +++ b/src/dmr_data.c @@ -30,12 +30,12 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state) uint8_t burst; char info[196]; - unsigned char SlotType[20]; + unsigned char SlotType[20]; unsigned int SlotTypeOk; uint8_t cach_err = 0; UNUSED(cach_err); - int cachInterleave[24] = + int cachInterleave[24] = {0, 7, 8, 9, 1, 10, 11, 12, 2, 13, 14, 15, 3, 16, 4, 17, 18, @@ -43,7 +43,7 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state) }; dibit_p = state->dmr_payload_p - 90; - + //collect cach and de-interleave for (i = 0; i < 12; i++) { @@ -116,7 +116,7 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state) } if (state->dmr_stereo == 1) { - dibit = (int)state->dmr_stereo_payload[61]; + dibit = (int)state->dmr_stereo_payload[61]; } else state->dmr_stereo_payload[61] = dibit; @@ -146,7 +146,7 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state) } if (state->dmr_stereo == 1) //state { - dibit = (int)state->dmr_stereo_payload[63]; + dibit = (int)state->dmr_stereo_payload[63]; } else state->dmr_stereo_payload[63] = dibit; @@ -161,7 +161,7 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state) } if (state->dmr_stereo == 1) //state { - dibit = (int)state->dmr_stereo_payload[64]; + dibit = (int)state->dmr_stereo_payload[64]; } else state->dmr_stereo_payload[64] = dibit; @@ -194,7 +194,7 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state) } if (state->dmr_stereo == 1) { - dibit = (int)state->dmr_stereo_payload[i+66]; + dibit = (int)state->dmr_stereo_payload[i+66]; } else state->dmr_stereo_payload[i+66] = dibit; @@ -202,7 +202,7 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state) syncdata[(2*i)+1] = (1 & dibit); // bit 0 sync[i] = (dibit | 1) + 48; } - sync[24] = 0; + sync[24] = 0; if((strcmp (sync, DMR_BS_DATA_SYNC) == 0) ) { @@ -240,21 +240,21 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state) // Slot type - Second part - Parity bit for (i = 0; i < 5; i++) { - if (state->dmr_stereo == 0) + if (state->dmr_stereo == 0) { dibit = getDibit(opts, state); state->dmr_stereo_payload[i+90] = dibit; } if (state->dmr_stereo == 1) { - dibit = (int)state->dmr_stereo_payload[i+90]; + dibit = (int)state->dmr_stereo_payload[i+90]; } SlotType[(i*2) + 10] = (1 & (dibit >> 1)); // bit 1 SlotType[(i*2) + 11] = (1 & dibit); // bit 0 } /* Check and correct the SlotType (apply Golay(20,8) FEC check) */ - + // golay (20,8) hamming-weight of 6 reliably corrects at most 2 bit-errors if( Golay_20_8_decode(SlotType) ) SlotTypeOk = 1; else @@ -278,7 +278,7 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state) // Current slot - Second Half - Data Payload - 2nd part for (i = 0; i < 49; i++) { - if (state->dmr_stereo == 0) + if (state->dmr_stereo == 0) { dibit = getDibit(opts, state); state->dmr_stereo_payload[i+95] = dibit; @@ -286,13 +286,13 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state) if (state->dmr_stereo == 1) { - dibit = (int)state->dmr_stereo_payload[i+95]; + dibit = (int)state->dmr_stereo_payload[i+95]; } info[(2*i) + 98] = (1 & (dibit >> 1)); // bit 1 info[(2*i) + 99] = (1 & dibit); // bit 0 } - + // dmr_data_burst_handler(opts, state, (uint8_t *)info, burst); @@ -300,7 +300,7 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state) if (state->dmr_ms_mode == 0 && opts->dmr_mono == 0) { cach_err = dmr_cach (opts, state, cachdata); - } + } //ending line break fprintf(stderr, "\n"); @@ -316,7 +316,7 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state) } // Skip cach (24 bit = 12 dibit) and next slot 1st half (98 + 10 bit = 49 + 5 dibit) - if (state->dmr_stereo == 0) + if (state->dmr_stereo == 0) { skipDibit (opts, state, 12 + 49 + 5); } @@ -325,7 +325,7 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state) #ifdef CON_TUNEAWAY //simplified, if IDLE condition, drop cc and vc sync time so when RF channel tears down, we go back much quicker - //NOTE: This was adopted, because going back to the CC early and then to be sent back to the channel grant, + //NOTE: This was adopted, because going back to the CC early and then to be sent back to the channel grant, //only for it to tear down and being sent back to the CC again isn't very efficient for trunk tracking //NOTE: This will still leave the tuner in the 'locked' state when tuning a voice channel grant on the CC, //and will remain locked until a new voice channel grant is received, but its just asthetic, trying to fix it @@ -342,4 +342,4 @@ dmr_data_sync (dsd_opts * opts, dsd_state * state) } } #endif -} +} diff --git a/src/dmr_dburst.c b/src/dmr_dburst.c index eee3a2d..61eee21 100644 --- a/src/dmr_dburst.c +++ b/src/dmr_dburst.c @@ -11,13 +11,13 @@ //TODO: Test USBD LIP Decoder with Real World Samples (if/when available) //TODO: Test UDT NMEA and LIP Decoders with Real World Samples (if/when available) -//WIP: Move all extra decoders for location, etc, to a new file and add prototypes to dsd.h +//WIP: Move all extra decoders for location, etc, to a new file and add prototypes to dsd.h //DONE: Test CRC9/CRC32 on Rate 1 Data with Real World Samples (if/when available) //TODO: Address areas that require reading of ISO7, ISO8, and UTF-16 string formats #include "dsd.h" -void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196], uint8_t databurst) +void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196], uint8_t databurst) { uint32_t i, j, k; @@ -27,7 +27,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 uint32_t IrrecoverableErrors = 0; uint8_t slot = state->currentslot; - //confirmed data + //confirmed data uint8_t dbsn = 0; //data block serial number for confirmed data blocks uint8_t blockcounter = 0; //local block count uint8_t confdatabits[250]; //array to reshuffle conf data block bits into sequence for crc9 check @@ -53,8 +53,8 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 memset (LC_DataBytes, 0, sizeof(LC_DataBytes)); //PDU Bytes and Bits - uint8_t DMR_PDU[25]; - uint8_t DMR_PDU_bits[196]; + uint8_t DMR_PDU[25]; + uint8_t DMR_PDU_bits[196]; memset (DMR_PDU, 0, sizeof (DMR_PDU)); memset (DMR_PDU_bits, 0, sizeof (DMR_PDU_bits)); @@ -63,19 +63,19 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 uint8_t is_ras = 0; uint8_t crc_original_validity = 0; - uint32_t crcmask = 0; + uint32_t crcmask = 0; uint8_t crclen = 0; uint8_t is_bptc = 0; - uint8_t is_trellis = 0; + uint8_t is_trellis = 0; uint8_t is_emb = 0; - uint8_t is_lc = 0; + uint8_t is_lc = 0; uint8_t is_full = 0; - uint8_t is_udt = 0; + uint8_t is_udt = 0; uint8_t pdu_len = 0; uint8_t pdu_start = 0; //starting value of pdu (0 normal, 2 for confirmed) - uint8_t usbd_st = 0; //usbd service type + uint8_t usbd_st = 0; //usbd service type switch(databurst){ case 0x00: //PI @@ -89,14 +89,14 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 is_bptc = 1; is_lc = 1; crclen = 24; - crcmask = 0x969696; + crcmask = 0x969696; pdu_len = 12; //12 bytes sprintf(state->fsubtype, " VLC "); break; case 0x02: //TLC is_bptc = 1; is_lc = 1; - crcmask = 0x999999; + crcmask = 0x999999; crclen = 24; pdu_len = 12; //12 bytes sprintf(state->fsubtype, " TLC "); @@ -104,7 +104,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 case 0x03: //CSBK is_bptc = 1; crclen = 16; - crcmask = 0xA5A5; + crcmask = 0xA5A5; pdu_len = 12; //12 bytes sprintf(state->fsubtype, " CSBK"); break; @@ -131,18 +131,18 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 case 0x07: //1/2 Rate Data is_bptc = 1; crclen = 9; //confirmed data only - crcmask = 0x0F0; + crcmask = 0x0F0; pdu_len = 12; //12 bytes unconfirmed sprintf(state->fsubtype, " R12U "); if (state->data_conf_data[slot] == 1) { - pdu_len = 10; + pdu_len = 10; pdu_start = 2; //start at plus two when assembling sprintf(state->fsubtype, " R12C "); } if (state->data_header_format[slot] == 0) //UDT 1/2 Encoded Blocks { - is_udt = 1; + is_udt = 1; sprintf(state->fsubtype, " UDTC "); } break; @@ -154,10 +154,10 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 sprintf(state->fsubtype, " R34U "); if (state->data_conf_data[slot] == 1) { - pdu_len = 16; + pdu_len = 16; pdu_start = 2; //start at plus two when assembling sprintf(state->fsubtype, " R34C "); - } + } break; case 0x09: //Idle //pseudo-random data fill, no need to do anything with this @@ -165,7 +165,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 break; case 0x0A: //1 Rate Data crclen = 9; //confirmed data only - crcmask = 0x10F; + crcmask = 0x10F; is_full = 1; pdu_len = 24; //192 bits 24 bytes + 4 pad bits sprintf(state->fsubtype, " R_1U "); @@ -183,7 +183,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 pdu_len = 12; //12 bytes sprintf(state->fsubtype, " USBD "); break; - + //special types (not real data 'sync' bursts) case 0xEB: //Embedded Signalling crclen = 5; @@ -194,12 +194,12 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 default: //Slot Type FEC should catch this so we never see it, //but if it doesn't, then we can still dump the entire 'packet' - //treat like rate 1 unconfirmed data + //treat like rate 1 unconfirmed data is_full = 1; - pdu_len = 25; //196 bits - 24.5 bytes - sprintf(state->fsubtype, " _UNK "); + pdu_len = 25; //196 bits - 24.5 bytes + sprintf(state->fsubtype, " _UNK "); break; - + } //flag off prop head when not looking at data blocks @@ -208,7 +208,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 if (databurst != 0xEB) { if (state->dmr_ms_mode == 0) - { + { if (state->dmr_color_code != 16) fprintf(stderr, "| Color Code=%02d ", state->dmr_color_code); else fprintf(stderr, "| Color Code=XX "); @@ -235,7 +235,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 fclose (pFile); } } - + //Most Data Sync Burst types will use the bptc 196x96 if (is_bptc) { @@ -253,7 +253,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 BPTCReservedBits = (R[0] & 0x01) | ((R[1] << 1) & 0x02) | ((R[2] << 2) & 0x04); //debug print - //fprintf (stderr, " RAS? %X - %d %d %d", BPTCReservedBits, R[0], R[1], R[2]); + //fprintf (stderr, " RAS? %X - %d %d %d", BPTCReservedBits, R[0], R[1], R[2]); /* Convert the 96 bits BPTC data into 12 bytes */ k = 0; @@ -270,16 +270,16 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 /* Fill the CRC extracted (before Reed-Solomon (12,9) FEC correction) */ CRCExtracted = 0; - for(i = 0; i < crclen; i++) + for(i = 0; i < crclen; i++) { CRCExtracted = CRCExtracted << 1; - CRCExtracted = CRCExtracted | (uint32_t)(BPTCDmrDataBit[i + 96 - crclen] & 1); + CRCExtracted = CRCExtracted | (uint32_t)(BPTCDmrDataBit[i + 96 - crclen] & 1); } /* Apply the CRC mask (see DMR standard B.3.12 Data Type CRC Mask) */ CRCExtracted = CRCExtracted ^ crcmask; - /* Check/correct the BPTC data and compute the Reed-Solomon (12,9) CRC */ + /* Check/correct the BPTC data and compute the Reed-Solomon (12,9) CRC */ if (is_lc) CRCCorrect = ComputeAndCorrectFullLinkControlCrc(BPTCDmrDataByte, &CRCComputed, crcmask); //set CRC to correct on unconfirmed 1/2 data blocks (for reporting due to no CRC available on these) @@ -288,7 +288,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 CRCComputed = 0; CRCExtracted = 0; CRCCorrect = 1; - } + } //run CRC9 on intermediate and last 1/2 confirmed data blocks else if (state->data_conf_data[slot] == 1 && databurst == 0x7) @@ -308,32 +308,32 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 { CRCCorrect = 1; state->data_block_crc_valid[slot][blockcounter] = 1; - } + } else state->data_block_crc_valid[slot][blockcounter] = 0; } //run CCITT on other data forms - else + else { - CRCComputed = ComputeCrcCCITT(BPTCDmrDataBit); + CRCComputed = ComputeCrcCCITT(BPTCDmrDataBit); if (CRCComputed == CRCExtracted) CRCCorrect = 1; else CRCCorrect = 0; } //set the 'RAS Flag', if no irrecoverable errors but bad crc, only when enabled by user (to prevent a lot of bad data CSBKs) - if (opts->aggressive_framesync == 0 && CRCCorrect == 0 && IrrecoverableErrors == 0 && BPTCReservedBits == 4) is_ras = 1; + if (opts->aggressive_framesync == 0 && CRCCorrect == 0 && IrrecoverableErrors == 0 && BPTCReservedBits == 4) is_ras = 1; //make sure the system type isn't Hytera, but could just be bad decodes on bad sample if (BPTCDmrDataByte[1] == 0x68) is_ras = 0; //if this is a RAS system, set the CRC to okay if irrecoverable errors are okay - //if we don't do this, then we can't view some data (CSBKs on RAS enabled systems) + //if we don't do this, then we can't view some data (CSBKs on RAS enabled systems) if (is_ras == 1) { crc_original_validity = CRCCorrect; CRCCorrect = 1; - } + } if (databurst == 0x04 || databurst == 0x06) //MBC Header, Data Header { @@ -343,7 +343,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 } else state->data_block_crc_valid[slot][0] = 0; } - + /* Convert corrected x bytes into x*8 bits */ for(i = 0, j = 0; i < pdu_len; i++, j+=8) { @@ -373,7 +373,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 //Embedded Signalling will use BPTC 128x77 if (is_emb) { - + CRCExtracted = 0; CRCComputed = 0; IrrecoverableErrors = 0; @@ -410,7 +410,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 if(CRCExtracted == CRCComputed) CRCCorrect = 1; else CRCCorrect = 0; - + for (i = 0; i < 72; i++) { DMR_PDU_bits[i] = LC_DataBit[i]; @@ -428,14 +428,14 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 { CRCExtracted = 0; CRCComputed = 0; - IrrecoverableErrors = 1; + IrrecoverableErrors = 1; uint8_t tdibits[98]; memset (tdibits, 0, sizeof(tdibits)); //reconstitute info bits into dibits for the trellis decoder for (i = 0; i < 98; i++) - tdibits[i] = (info[i*2] << 1) | info[i*2+1]; + tdibits[i] = (info[i*2] << 1) | info[i*2+1]; uint8_t TrellisReturn[18]; memset (TrellisReturn, 0, sizeof(TrellisReturn)); @@ -445,7 +445,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 //they may have been successfully corrected, the CRC will reveal as much for (i = 0; i < pdu_len; i++) - DMR_PDU[i] = TrellisReturn[i+pdu_start]; + DMR_PDU[i] = TrellisReturn[i+pdu_start]; for(i = 0, j = 0; i < 18; i++, j+=8) { @@ -461,7 +461,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 //set CRC to correct on unconfirmed 3/4 data blocks (for reporting due to no CRC available on these) if (state->data_conf_data[slot] == 0) CRCCorrect = 1; - + //run CRC9 on intermediate and last 3/4 data blocks else if (state->data_conf_data[slot] == 1) { @@ -474,12 +474,12 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 for(i = 0; i < 128; i++) confdatabits[i] = DMR_PDU_bits[i + 16]; for(i = 0; i < 7; i++) confdatabits[i + 128] = DMR_PDU_bits[i]; - CRCComputed = ComputeCrc9Bit(confdatabits, 135); + CRCComputed = ComputeCrc9Bit(confdatabits, 135); if (CRCExtracted == CRCComputed) { CRCCorrect = 1; state->data_block_crc_valid[slot][blockcounter] = 1; - } + } else state->data_block_crc_valid[slot][blockcounter] = 0; @@ -521,7 +521,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 //set CRC to correct on unconfirmed 1 rate data blocks (for reporting due to no CRC available on these) if (state->data_conf_data[slot] == 0) CRCCorrect = 1; - + //run CRC9 on intermediate and last 1 rate data blocks else if (state->data_conf_data[slot] == 1) { @@ -541,7 +541,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 { CRCCorrect = 1; state->data_block_crc_valid[slot][blockcounter] = 1; - } + } else state->data_block_crc_valid[slot][blockcounter] = 0; //debug confirmed data values (working now) @@ -554,7 +554,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 } - + //time for some pi if (databurst == 0x00) dmr_pi (opts, state, DMR_PDU, CRCCorrect, IrrecoverableErrors); @@ -572,14 +572,14 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 //control signalling types (CSBK, MBC) if (databurst == 0x03) dmr_cspdu (opts, state, DMR_PDU_bits, DMR_PDU, CRCCorrect, IrrecoverableErrors); - - //both MBC header and MBC continuation will go to the block_assembler - type 2, and then to dmr_cspdu - if (databurst == 0x04) + + //both MBC header and MBC continuation will go to the block_assembler - type 2, and then to dmr_cspdu + if (databurst == 0x04) { state->data_block_counter[slot] = 0; //zero block counter before running header state->data_header_valid[slot] = 1; //set valid header since we received one dmr_block_assembler (opts, state, DMR_PDU, pdu_len, databurst, 2); - } + } if (databurst == 0x05) dmr_block_assembler (opts, state, DMR_PDU, pdu_len, databurst, 2); //Unified Single Data Block (USBD) -- Not to be confused with Unified Data Transport (UDT) @@ -606,14 +606,14 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 // fprintf(stderr, " (FEC OK)"); // fprintf (stderr, "%s", KNRM); - // } + // } if (IrrecoverableErrors != 0 && databurst != 0x08 && databurst != 0x09) //&& databurst != 0x05 { fprintf (stderr, "%s", KRED); fprintf(stderr, " (FEC ERR)"); fprintf (stderr, "%s", KNRM); - } + } //print whether or not the 'RAS Field' bits are set to indicate RAS enabled (to be verified) if (is_ras == 1) @@ -624,7 +624,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 if (opts->payload == 1) fprintf (stderr, "%X ", BPTCReservedBits); fprintf (stderr, "%s", KNRM); } - + if (IrrecoverableErrors == 0 && CRCCorrect == 0 && is_ras == 0 && databurst != 0x09 && databurst != 0x05) { fprintf (stderr, "%s", KRED); @@ -648,7 +648,7 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 // fprintf (stderr, " CRC - EXT %X CMP %X", CRCExtracted, CRCComputed); fprintf (stderr, "%s", KNRM); - + } } diff --git a/src/dmr_flco.c b/src/dmr_flco.c index 2bff90e..4a98ae2 100644 --- a/src/dmr_flco.c +++ b/src/dmr_flco.c @@ -26,7 +26,7 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C uint8_t so = 0; uint32_t target = 0; uint32_t source = 0; - uint8_t capsite = 0; + uint8_t capsite = 0; int restchannel = -1; int is_cap_plus = 0; int is_alias = 0; @@ -59,7 +59,7 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C //read ahead a little to get this for the xpt flag if (IrrecoverableErrors == 0 && flco == 0x09 && fid == 0x68) { - sprintf (state->dmr_branding, "%s", " Hytera"); + sprintf (state->dmr_branding, "%s", " Hytera"); sprintf (state->dmr_branding_sub, "XPT "); } @@ -78,12 +78,12 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C if (type == 3) fprintf (stderr, "%s", KRED); fprintf (stderr, " SLOT %d", state->currentslot+1); fprintf (stderr, " Protected LC "); - goto END_FLCO; - } + goto END_FLCO; + } if (IrrecoverableErrors == 0) { - + if (slot == 0) state->dmr_flco = flco; else state->dmr_flcoR = flco; @@ -96,13 +96,13 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C } //Embedded Talker Alias Header Only (format and len storage) - if ( (fid == 0 || fid == 0x68) && type == 3 && flco == 0x04) + if ( (fid == 0 || fid == 0x68) && type == 3 && flco == 0x04) { dmr_embedded_alias_header(opts, state, lc_bits); } //Embedded Talker Alias Header (continuation) and Blocks - if ( (fid == 0 || fid == 0x68) && type == 3 && flco > 0x03 && flco < 0x08) + if ( (fid == 0 || fid == 0x68) && type == 3 && flco > 0x03 && flco < 0x08) { is_alias = 1; dmr_embedded_alias_blocks(opts, state, lc_bits); @@ -125,7 +125,7 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C } //Unknown CapMax/Moto Things - if (fid == 0x10 && (flco == 0x08 || flco == 0x28)) + if (fid == 0x10 && (flco == 0x08 || flco == 0x28)) { //NOTE: fid 0x10 and flco 0x08 (emb) produces a lot of 'zero' bytes //this has been observed to happen often on CapMax systems, so I believe it could be some CapMax 'thing' @@ -153,8 +153,8 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C state->data_header_format[slot] = 7; //reset data header sap storage state->data_header_sap[slot] = 0; - //flag off data header validity - state->data_header_valid[slot] = 0; + //flag off data header validity + state->data_header_valid[slot] = 0; //flag off conf data flag state->data_conf_data[slot] = 0; //reset padding @@ -163,7 +163,7 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C state->data_byte_ctr[slot] = 0; //reset ks start value state->data_ks_start[slot] = 0; - + goto END_FLCO; } @@ -181,7 +181,7 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C goto END_FLCO; } - //look for any Hytera XPT system, adjust TG to 16-bit allocation + //look for any Hytera XPT system, adjust TG to 16-bit allocation //Groups use only 8 out of 16, but 16 always seems to be allocated //private calls use 16-bit target values hashed to 8-bit in the site status csbk //the TLC preceeds the VLC for a 'handshake' call setup in XPT @@ -194,17 +194,17 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C //the crc8 hash is the value represented in the CSBK when dealing with private calls for (int i = 0; i < 16; i++) target_hash[i] = lc_bits[32+i]; - tg_hash = crc8 (target_hash, 16); - } + tg_hash = crc8 (target_hash, 16); + } - //XPT Call 'Grant/Alert' Setup Occurs in TLC with a flco 0x09 + //XPT Call 'Grant/Alert' Setup Occurs in TLC with a flco 0x09 if (fid == 0x68 && flco == 0x09) { //The CSBK always uses an 8-bit TG/TGT; The White Papers (user manuals) say 8-bit TG and 16-bit SRC addressing //private calls and indiv data calls use a hash of their 8 bit tgt values in the CSBK xpt_int = (uint8_t)ConvertBitIntoBytes(&lc_bits[16], 4); //This is consistent with an LCN value, not an LSN value xpt_free = (uint8_t)ConvertBitIntoBytes(&lc_bits[24], 4); //24 and 4 on 0x09 - xpt_hand = (uint8_t)ConvertBitIntoBytes(&lc_bits[28], 4); //handshake kind: 0 - ordinary; 1-2 Interrupts; 3-15 reserved; + xpt_hand = (uint8_t)ConvertBitIntoBytes(&lc_bits[28], 4); //handshake kind: 0 - ordinary; 1-2 Interrupts; 3-15 reserved; target = (uint32_t)ConvertBitIntoBytes(&lc_bits[32], 16); //16-bit allocation source = (uint32_t)ConvertBitIntoBytes(&lc_bits[56], 16); //16-bit allocation @@ -215,13 +215,13 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C //the crc8 hash is the value represented in the CSBK when dealing with private calls for (int i = 0; i < 16; i++) target_hash[i] = lc_bits[32+i]; - tg_hash = crc8 (target_hash, 16); + tg_hash = crc8 (target_hash, 16); fprintf (stderr, "%s \n", KGRN); fprintf (stderr, " SLOT %d ", state->currentslot+1); - if (opts->payload == 1) fprintf(stderr, "FLCO=0x%02X FID=0x%02X ", flco, fid); + if (opts->payload == 1) fprintf(stderr, "FLCO=0x%02X FID=0x%02X ", flco, fid); fprintf (stderr, "TGT=%u SRC=%u ", target, source); - + fprintf (stderr, "Hytera XPT "); //Group ID ranges from 1 to 240; emergency group call ID ranges from 250 to 254; all call ID is 255. @@ -230,7 +230,7 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C fprintf (stderr, "Group "); //according to observation if (target > 248 && target < 255) fprintf (stderr, "Emergency "); if (target == 255) fprintf (stderr, "All "); - } + } else fprintf (stderr, "Private "); //according to observation fprintf (stderr, "Call Alert "); //Alert or Grant @@ -241,7 +241,7 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C if (reserved == 0 && opts->payload == 1) fprintf(stderr, "TGT Hash=%d; ", tg_hash); if (opts->payload == 1) fprintf(stderr, "HSK=%X; ", xpt_hand); //extra verbosity on handshake types found in the patent - if (opts->payload == 1) + if (opts->payload == 1) { fprintf (stderr, "Handshake - "); if (xpt_hand == 0) fprintf (stderr, "Ordinary; "); @@ -285,7 +285,7 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C //unknown other manufacturer or OTA ENC, etc. //removed tait from the list, added hytera 0x08 - if (fid != 0 && fid != 0x68 && fid != 0x10 && fid != 0x08) + if (fid != 0 && fid != 0x68 && fid != 0x10 && fid != 0x08) { if (type == 1) fprintf (stderr, "%s \n", KYEL); if (type == 2) fprintf (stderr, "%s \n", KYEL); @@ -296,10 +296,10 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C goto END_FLCO; } - } + } //will want to continue to observe for different flco and fid combinations to find out their meaning - if(IrrecoverableErrors == 0 && is_alias == 0 && is_gps == 0) + if(IrrecoverableErrors == 0 && is_alias == 0 && is_gps == 0) { //set overarching manufacturer in use when non-standard feature id set is up if (fid != 0) state->dmr_mfid = fid; @@ -326,8 +326,8 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C { state->last_vc_sync_time = time(NULL); state->last_cc_sync_time = time(NULL); - } - + } + } if (type == 2) //TLC, zero out target, source, so, and fid per channel, and other odd and ends @@ -357,11 +357,11 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C state->payload_keyidR = 0; //reset gain if (opts->floating_point == 1) - state->aout_gainR = opts->audio_gain; + state->aout_gainR = opts->audio_gain; } - + } - + //only assign this value here if not trunking // if (opts->p25_trunk == 0) //may be safe to always do this now with code changes, will want to test at some point (tg hold w/ dual voice / slco may optimally need this set) { @@ -372,14 +372,14 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C // if (state->trunk_chan_map[restchannel] != 0) // { // state->p25_cc_freq = state->trunk_chan_map[restchannel]; - // } + // } } } if (type == 1) fprintf (stderr, "%s \n", KGRN); if (type == 2) fprintf (stderr, "%s \n", KRED); if (type == 3) fprintf (stderr, "%s", KGRN); - + fprintf (stderr, " SLOT %d ", state->currentslot+1); fprintf(stderr, "TGT=%u SRC=%u ", target, source); if (opts->payload == 1 && is_xpt == 1 && flco == 0x3) fprintf(stderr, "HASH=%d ", tg_hash); @@ -391,7 +391,7 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C //0x20 on the Embedded Voice Burst Sync seems to indicate a Moto (non-specific) Group Call in progress //its possible that both EMB FID 0x10 FLCO 0x20 and 0x23 are just Moto but non-specific (observed 0x20 on Tier 2) - if (fid == 0x68) sprintf (state->call_string[slot], " Hytera "); + if (fid == 0x68) sprintf (state->call_string[slot], " Hytera "); else if (flco == 0x4 || flco == 0x5 || flco == 0x7 || flco == 0x23) //Cap+ Things { @@ -409,18 +409,18 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C // strcat (state->call_string[slot], " Pri"); sprintf (state->call_string[slot], " Private "); fprintf (stderr, "Private "); - } + } } else if (flco == 0x3) //UU_V_Ch_Usr { sprintf (state->call_string[slot], " Private "); - fprintf (stderr, "Private "); + fprintf (stderr, "Private "); } else //Grp_V_Ch_Usr -- still valid on hytera VLC { sprintf (state->call_string[slot], " Group "); - fprintf (stderr, "Group "); - } + fprintf (stderr, "Group "); + } if(so & 0x80) { @@ -474,15 +474,15 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C dmr_cspdu (opts, state, dbits, dummy, 1, 0); } - + } //REMUS! Uncomment Line Below if desired // else strcat (state->call_string[slot], " "); - + if (1 == 1) //fid == 0x10 { - /* Check the "Service Option" bits */ + /* Check the "Service Option" bits */ if( (fid == 0x10) && (so & 0x20) ) //Motorola FID 0x10 Only { //REMUS! Uncomment Line Below if desired @@ -500,13 +500,13 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C //REMUS! Uncomment Line Below if desired // strcat (state->call_string[slot], "-BC "); fprintf(stderr, "Broadcast "); - } + } if(so & 0x04) { //REMUS! Uncomment Line Below if desired // strcat (state->call_string[slot], "-OVCM "); fprintf(stderr, "OVCM "); - } + } if(so & 0x03) { if((so & 0x03) == 0x01) @@ -514,28 +514,28 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C //REMUS! Uncomment Line Below if desired // strcat (state->call_string[slot], "-P1"); fprintf(stderr, "Priority 1 "); - } + } else if((so & 0x03) == 0x02) { //REMUS! Uncomment Line Below if desired // strcat (state->call_string[slot], "-P2"); fprintf(stderr, "Priority 2 "); - } + } else if((so & 0x03) == 0x03) { //REMUS! Uncomment Line Below if desired // strcat (state->call_string[slot], "-P3"); fprintf(stderr, "Priority 3 "); - } + } else /* We should never go here */ { //REMUS! Uncomment Line Below if desired // strcat (state->call_string[slot], " "); - fprintf(stderr, "No Priority "); - } + fprintf(stderr, "No Priority "); + } } } - + //should rework this back into the upper portion if (fid == 0x68) fprintf (stderr, "Hytera "); if (is_xpt) fprintf (stderr, "XPT "); @@ -543,7 +543,7 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C if (fid == 0x68 && flco == 0x03) fprintf (stderr, "Private "); fprintf(stderr, "Call "); - + //check Cap+ rest channel info if available and good fec if (is_cap_plus == 1) @@ -554,7 +554,7 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C fprintf (stderr, "Rest LSN: %d", restchannel); } } - + fprintf (stderr, "%s ", KNRM); //group labels @@ -585,7 +585,7 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C fprintf (stderr, "%s", KYEL); fprintf (stderr, "Key %lld ", state->K); fprintf (stderr, "%s ", KNRM); - } + } if (state->K1 != 0 && fid == 0x68 && so & 0x40 && slot == 0 && state->payload_algid == 0) { @@ -640,11 +640,11 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C fprintf (stderr, "%016llX %016llX", state->A3[1], state->A4[1]); fprintf (stderr, "%s ", KNRM); } - + } END_FLCO: - + //blank the call string here if its a TLC if (type == 2) sprintf (state->call_string[slot], "%s", " "); //21 spaces @@ -667,14 +667,14 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C } //externalized dmr cach - tact and slco fragment handling -uint8_t dmr_cach (dsd_opts * opts, dsd_state * state, uint8_t cach_bits[25]) +uint8_t dmr_cach (dsd_opts * opts, dsd_state * state, uint8_t cach_bits[25]) { int i, j; uint8_t err = 0; - uint8_t tact_valid = 0; + uint8_t tact_valid = 0; UNUSED(tact_valid); - bool h1, h2, h3, crc; + bool h1, h2, h3, crc; //dump payload - testing uint8_t slco_raw_bits[68]; //raw @@ -682,7 +682,7 @@ uint8_t dmr_cach (dsd_opts * opts, dsd_state * state, uint8_t cach_bits[25]) //tact pdu uint8_t tact_bits[7]; - uint8_t at = 0; //access type, set to 1 during continuous transmission mode + uint8_t at = 0; //access type, set to 1 during continuous transmission mode uint8_t slot = 2; //tdma time slot uint8_t lcss = 0; //link control start stop (9.3.3) NOTE: There is no Single fragment LC defined for CACH signalling UNUSED2(at, slot); @@ -721,13 +721,13 @@ uint8_t dmr_cach (dsd_opts * opts, dsd_state * state, uint8_t cach_bits[25]) { slco_raw_bits[i] = cach_bits[i+7]; } - + //De-interleave int src = 0; for (i = 0; i < 17; i++) { src = (i * 4) % 67; - slco_bits[i] = slco_raw_bits[src]; + slco_bits[i] = slco_raw_bits[src]; } //slco_bits[i] = slco_raw_bits[i]; @@ -747,14 +747,14 @@ uint8_t dmr_cach (dsd_opts * opts, dsd_state * state, uint8_t cach_bits[25]) if (lcss == 1) //first block, reset counters and memset { //reset the full cach and counter - state->dmr_cach_counter = 0; + state->dmr_cach_counter = 0; memset (state->dmr_cach_fragment, 1, sizeof (state->dmr_cach_fragment)); - } + } if (lcss == 3) state->dmr_cach_counter++; //continuation, so increment counter by one. if (lcss == 2) //final segment - assemble, de-interleave, hamming, crc, and execute { - state->dmr_cach_counter = 3; - } + state->dmr_cach_counter = 3; + } //sanity check if (state->dmr_cach_counter > 3) //marginal/shaky/bad signal or tuned away @@ -763,7 +763,7 @@ uint8_t dmr_cach (dsd_opts * opts, dsd_state * state, uint8_t cach_bits[25]) lcss = 5; //toss away value state->dmr_cach_counter = 0; memset (state->dmr_cach_fragment, 1, sizeof (state->dmr_cach_fragment)); - err = 1; + err = 1; return (err); } @@ -791,7 +791,7 @@ uint8_t dmr_cach (dsd_opts * opts, dsd_state * state, uint8_t cach_bits[25]) for (i = 0; i < 67; i++) { src = (i * 4) % 67; - slco_bits[i] = slco_raw_bits[src]; + slco_bits[i] = slco_raw_bits[src]; } slco_bits[i] = slco_raw_bits[i]; @@ -832,8 +832,8 @@ uint8_t dmr_cach (dsd_opts * opts, dsd_state * state, uint8_t cach_bits[25]) fprintf (stderr, "\n"); else if (opts->payload == 1 && state->dmrburstR == 16 && state->currentslot == 1) //if current slot is voice with payload enabled fprintf (stderr, "\n"); - } - + } + } return (err); //return err value based on success or failure, even if we aren't checking it } @@ -846,7 +846,7 @@ void dmr_slco (dsd_opts * opts, dsd_state * state, uint8_t slco_bits[]) uint8_t slco_bytes[6]; //completed byte blocks for payload print for (i = 0; i < 5; i++) slco_bytes[i] = (uint8_t)ConvertBitIntoBytes(&slco_bits[i*8], 8); slco_bytes[5] = (uint8_t)ConvertBitIntoBytes(&slco_bits[32], 4); - + //just going to decode the Short LC with all potential parameters known uint8_t slco = (uint8_t)ConvertBitIntoBytes(&slco_bits[0], 4); @@ -900,7 +900,7 @@ void dmr_slco (dsd_opts * opts, dsd_state * state, uint8_t slco_bits[]) //assigning n as largest possible value for model type //Sys_Parms - if (slco == 0x2 || slco == 0x3) + if (slco == 0x2 || slco == 0x3) { if (model == 0) //Tiny { @@ -953,7 +953,7 @@ void dmr_slco (dsd_opts * opts, dsd_state * state, uint8_t slco_bits[]) //Cap+ uint8_t capsite = (uint8_t)ConvertBitIntoBytes(&slco_bits[22], 3); //Seems more consistent - uint8_t restchannel = (uint8_t)ConvertBitIntoBytes(&slco_bits[16], 4); + uint8_t restchannel = (uint8_t)ConvertBitIntoBytes(&slco_bits[16], 4); uint8_t cap_reserved = (uint8_t)ConvertBitIntoBytes(&slco_bits[20], 2); //significant value? //Hytera XPT @@ -990,7 +990,7 @@ void dmr_slco (dsd_opts * opts, dsd_state * state, uint8_t slco_bits[]) else if (slco == 0x3) //P_SYS_Parms { uint16_t syscode = (uint16_t)ConvertBitIntoBytes(&slco_bits[4], 14); - if (n != 0) fprintf (stderr, " SLC_P_SYS_PARMS: %s; Net ID: %d; Site ID: %d.%d; Comp CC: %d;", model_str, net+1, (site>>n)+1, (site & sub_mask)+1, reg); + if (n != 0) fprintf (stderr, " SLC_P_SYS_PARMS: %s; Net ID: %d; Site ID: %d.%d; Comp CC: %d;", model_str, net+1, (site>>n)+1, (site & sub_mask)+1, reg); else fprintf (stderr, " SLC_P_SYS_PARMS: %s; Net ID: %d; Site ID: %d;", model_str, net, site); fprintf (stderr, " SYS: %04X;", syscode); //#192 @@ -1007,13 +1007,13 @@ void dmr_slco (dsd_opts * opts, dsd_state * state, uint8_t slco_bits[]) fprintf (stderr, " Activity Update"); //102 361-2 7.1.3.2 fprintf (stderr, " TS1: %s; Hash: %d;", ts1_str, ts1_hash); fprintf (stderr, " TS2: %s; Hash: %d;", ts2_str, ts2_hash); - } + } else if (slco == 0x9) { fprintf (stderr, " SLCO Connect Plus Traffic Channel - Net ID: %d Site ID: %d", con_netid, con_siteid); sprintf (state->dmr_site_parms, "%d-%d ", con_netid, con_siteid); } - + else if (slco == 0xA) { fprintf (stderr, " SLCO Connect Plus Control Channel - Net ID: %d Site ID: %d", con_netid, con_siteid); @@ -1032,9 +1032,9 @@ void dmr_slco (dsd_opts * opts, dsd_state * state, uint8_t slco_bits[]) ccfreq = (long int)opts->rtlsdr_center_freq; if (ccfreq != 0) state->p25_cc_freq = ccfreq; } - + } - + else if (slco == 0xF) { fprintf (stderr, " SLCO Capacity Plus Site: %d - Rest LSN: %d - RS: %02X", capsite, restchannel, cap_reserved); @@ -1047,7 +1047,7 @@ void dmr_slco (dsd_opts * opts, dsd_state * state, uint8_t slco_bits[]) //if both slots have some cobination of vlc, pi, voice, or tlc int busy = 0; - if ( (state->dmrburstL == 16 || state->dmrburstL == 0 || state->dmrburstL == 1 || state->dmrburstL == 2) && + if ( (state->dmrburstL == 16 || state->dmrburstL == 0 || state->dmrburstL == 1 || state->dmrburstL == 2) && (state->dmrburstR == 16 || state->dmrburstR == 0 || state->dmrburstR == 1 || state->dmrburstR == 2)) busy = 1; if (busy) { @@ -1073,7 +1073,7 @@ void dmr_slco (dsd_opts * opts, dsd_state * state, uint8_t slco_bits[]) //RIGCTL if (opts->use_rigctl == 1) { - if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); + if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); SetFreq(opts->rigctl_sockfd, state->p25_cc_freq); state->p25_vc_freq[0] = state->p25_vc_freq[1] = 0; opts->p25_is_tuned = 0; @@ -1103,7 +1103,7 @@ void dmr_slco (dsd_opts * opts, dsd_state * state, uint8_t slco_bits[]) //The Priority Repeater and Priority Hash values stem from SDRTrunk, but I've never seen these values not be zeroes fprintf (stderr, " SLCO Hytera XPT - Free LCN %d - PRI LCN %d - PRI HASH: %02X", xpt_free, xpt_pri, xpt_hash); //NOTE: on really busy systems, this free repeater assignment can lag due to the 4 TS requirment to get SLC - // fprintf (stderr, " SLCO Hytera XPT - Free LCN %d ", xpt_free); + // fprintf (stderr, " SLCO Hytera XPT - Free LCN %d ", xpt_free); sprintf (state->dmr_branding_sub, "XPT "); //add string for ncurses terminal display @@ -1139,7 +1139,7 @@ void dmr_slco (dsd_opts * opts, dsd_state * state, uint8_t slco_bits[]) //RIGCTL if (opts->use_rigctl == 1) { - if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); + if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); SetFreq(opts->rigctl_sockfd, state->p25_cc_freq); state->p25_vc_freq[0] = state->p25_vc_freq[1] = 0; opts->p25_is_tuned = 0; @@ -1163,7 +1163,7 @@ void dmr_slco (dsd_opts * opts, dsd_state * state, uint8_t slco_bits[]) } } } - + else fprintf (stderr, " SLCO Unknown - %d ", slco); if (opts->payload == 1 && slco != 0) //if not SLCO NULL @@ -1173,24 +1173,24 @@ void dmr_slco (dsd_opts * opts, dsd_state * state, uint8_t slco_bits[]) { fprintf (stderr, "[%02X]", slco_bytes[i]); } - fprintf (stderr, "\n"); //if its a voice frame, we need the line break + fprintf (stderr, "\n"); //if its a voice frame, we need the line break } fprintf (stderr, "%s", KNRM); - + } //externalize embedded alias to keep the flco function relatively clean void dmr_embedded_alias_header (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[]) { UNUSED(opts); - + uint8_t slot = state->currentslot; - uint8_t format = (uint8_t)ConvertBitIntoBytes(&lc_bits[16], 2); + uint8_t format = (uint8_t)ConvertBitIntoBytes(&lc_bits[16], 2); uint8_t len; //this len seems to pertain to number of blocks? not bit len. - //len = (uint8_t)ConvertBitIntoBytes(&lc_bits[18], 5); + //len = (uint8_t)ConvertBitIntoBytes(&lc_bits[18], 5); if (format == 0) len = 7; else if (format == 1 || format == 2) len = 8; @@ -1200,7 +1200,7 @@ void dmr_embedded_alias_header (dsd_opts * opts, dsd_state * state, uint8_t lc_b state->dmr_alias_len[slot] = len; //fprintf (stderr, "F: %d L: %d - ", format, len); - + } void dmr_embedded_alias_blocks (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[]) @@ -1226,13 +1226,13 @@ void dmr_embedded_alias_blocks (dsd_opts * opts, dsd_state * state, uint8_t lc_b //else start = 24; //forcing start to 16 make it work on 8-bit alias, len seems okay when set off of format - start = 16; + start = 16; len = 8; // fprintf (stderr, "block: %d start: %d len: %d ", block, start, len); //all may not be used depending on format, len, start. - uint16_t A0, A1, A2, A3, A4, A5, A6; + uint16_t A0, A1, A2, A3, A4, A5, A6; //sanity check if (block > 7) block = 4; //prevent oob array (although we should never get here) @@ -1261,13 +1261,13 @@ void dmr_embedded_alias_blocks (dsd_opts * opts, dsd_state * state, uint8_t lc_b { for (int j = 0; j < 7; j++) { - fprintf (stderr, "%s", state->dmr_alias_block_segment[slot][i][j]); + fprintf (stderr, "%s", state->dmr_alias_block_segment[slot][i][j]); } } - + } else fprintf (stderr, "Missing Header Block Format and Len Data"); fprintf (stderr, "%s", KNRM); - + } diff --git a/src/dmr_le.c b/src/dmr_le.c index 68fcefd..93b81bc 100644 --- a/src/dmr_le.c +++ b/src/dmr_le.c @@ -11,7 +11,7 @@ //gather ambe_fr mi fragments for processing void dmr_late_entry_mi_fragment (dsd_opts * opts, dsd_state * state, uint8_t vc, uint8_t ambe_fr[4][24], uint8_t ambe_fr2[4][24], uint8_t ambe_fr3[4][24]) { - + uint8_t slot = state->currentslot; //enforce RC4 due to missing PI header, but with valid SVC Opts @@ -30,7 +30,7 @@ void dmr_late_entry_mi_fragment (dsd_opts * opts, dsd_state * state, uint8_t vc, state->payload_keyidR = 0xFF; } } - + //collect our fragments and place them into storage state->late_entry_mi_fragment[slot][vc][0] = (uint64_t)ConvertBitIntoBytes(&ambe_fr[3][0], 4); state->late_entry_mi_fragment[slot][vc][1] = (uint64_t)ConvertBitIntoBytes(&ambe_fr2[3][0], 4); @@ -46,8 +46,8 @@ void dmr_late_entry_mi (dsd_opts * opts, dsd_state * state) uint8_t slot = state->currentslot; int i, j; - int g[3]; - unsigned char mi_go_bits[24]; + int g[3]; + unsigned char mi_go_bits[24]; uint64_t mi_test = 0; uint64_t go_test = 0; @@ -59,7 +59,7 @@ void dmr_late_entry_mi (dsd_opts * opts, dsd_state * state) uint8_t mi_crc_cmp = 0; uint8_t mi_crc_ext = 1; uint8_t mi_crc_ok = 0; - + mi_test = (state->late_entry_mi_fragment[slot][1][0] << 32L) | (state->late_entry_mi_fragment[slot][2][0] << 28) | (state->late_entry_mi_fragment[slot][3][0] << 24) | (state->late_entry_mi_fragment[slot][1][1] << 20) | (state->late_entry_mi_fragment[slot][2][1] << 16) | (state->late_entry_mi_fragment[slot][3][1] << 12) | (state->late_entry_mi_fragment[slot][1][2] << 8) | (state->late_entry_mi_fragment[slot][2][2] << 4) | (state->late_entry_mi_fragment[slot][3][2] << 0); @@ -72,8 +72,8 @@ void dmr_late_entry_mi (dsd_opts * opts, dsd_state * state) { for (i = 0; i < 12; i++) { - mi_go_bits[i] = (( mi_test << (i+j*12) ) & 0x800000000) >> 35; - mi_go_bits[i+12] = (( go_test << (i+j*12) ) & 0x800000000) >> 35; + mi_go_bits[i] = (( mi_test << (i+j*12) ) & 0x800000000) >> 35; + mi_go_bits[i+12] = (( go_test << (i+j*12) ) & 0x800000000) >> 35; } //execute golay decode and assign pass or fail to g if ( Golay_24_12_decode(mi_go_bits) ) g[j] = 1; @@ -90,7 +90,7 @@ void dmr_late_entry_mi (dsd_opts * opts, dsd_state * state) } } - int mi_final = 0; + int mi_final = 0; mi_final = (mi_corrected >> 4) & 0xFFFFFFFF; mi_crc_ext = (uint8_t)ConvertBitIntoBytes(&mi_bits[32], 4); @@ -105,7 +105,7 @@ void dmr_late_entry_mi (dsd_opts * opts, dsd_state * state) { if (slot == 0 && state->payload_algid != 0) { - if (state->payload_mi != mi_final) + if (state->payload_mi != mi_final) { fprintf (stderr, "%s", KCYN); fprintf (stderr, " Slot 1 PI/LFSR and Late Entry MI Mismatch - %08X : %08X ", state->payload_mi, mi_final); @@ -199,7 +199,7 @@ void dmr_late_entry_mi (dsd_opts * opts, dsd_state * state) fprintf (stderr, "\n"); } } - + } @@ -211,7 +211,7 @@ void dmr_alg_refresh (dsd_opts * opts, dsd_state * state) { state->dropL = 256; - if (state->K1 != 0) + if (state->K1 != 0) { state->DMRvcL = 0; } @@ -228,7 +228,7 @@ void dmr_alg_refresh (dsd_opts * opts, dsd_state * state) { state->dropR = 256; - if (state->K1 != 0) + if (state->K1 != 0) { state->DMRvcR = 0; } @@ -251,12 +251,12 @@ void dmr_alg_reset (dsd_opts * opts, dsd_state * state) state->dropL = 256; state->dropR = 256; state->DMRvcL = 0; - state->DMRvcR = 0; + state->DMRvcR = 0; // state->payload_miP = 0; //running these clears out before we can create a new keystream // state->payload_miN = 0; //running these clears out before we can create a new keystream } -//handle Single Burst (Voice Burst F) or Reverse Channel Signalling +//handle Single Burst (Voice Burst F) or Reverse Channel Signalling void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power) { int i; @@ -275,7 +275,7 @@ void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power) uint8_t crc3_okay = 0; //TXI uint8_t txi = 0; //SEE: https://patents.google.com/patent/US8271009B2 UNUSED(txi); - + //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 @@ -298,7 +298,7 @@ void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power) //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 + //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 -- See TXI patent if (power == 1) //RC { @@ -320,7 +320,7 @@ void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power) 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 + 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); } @@ -341,7 +341,7 @@ void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power) fprintf (stderr, "%d", sbrc_return[i]); fprintf (stderr, " - %03X; ", sbrc_hex); fprintf (stderr, "%s", KNRM); - + // if (crc_okay == 0) //forego this since the crc can vary or not be used at all // { // fprintf (stderr, "%s", KRED); @@ -352,7 +352,7 @@ void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power) 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; //SEE: https://patents.google.com/patent/EP2347540B1/en uint8_t key = (sbrc_hex >> 3) & 0xFF; @@ -412,7 +412,7 @@ void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power) fprintf (stderr, "%s", KCYN); fprintf (stderr, " TXI Op: %X -", sbrc_opcode); if (sbrc_opcode == 0) fprintf (stderr, " Null; "); - else if (sbrc_opcode == 3) + 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 @@ -506,7 +506,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)) { @@ -530,7 +530,7 @@ uint8_t crc4(uint8_t bits[], unsigned int len) { uint8_t crc=0; unsigned int K = 4; - //x^4+x+1 + //x^4+x+1 uint8_t poly[5] = {1,0,0,1,1}; uint8_t buf[256]; if (len+K > sizeof(buf)) { diff --git a/src/dmr_ms.c b/src/dmr_ms.c index 59cfcaa..e17fe25 100644 --- a/src/dmr_ms.c +++ b/src/dmr_ms.c @@ -35,7 +35,7 @@ void dmrMS (dsd_opts * opts, dsd_state * state) memset (emb_pdu, 0, sizeof(emb_pdu)); //cach - char cachdata[25]; + char cachdata[25]; //cach tact bits uint8_t tact_bits[7]; @@ -65,7 +65,7 @@ void dmrMS (dsd_opts * opts, dsd_state * state) //Note: Manual dibit inversion required here since I didn't seperate inverted return from normal return in framesync, //so getDibit doesn't know to invert it before it gets here - for (j = 0; j < 6; j++) { + for (j = 0; j < 6; j++) { state->dmrburstL = 16; memset (ambe_fr, 0, sizeof(ambe_fr)); @@ -167,7 +167,7 @@ void dmrMS (dsd_opts * opts, dsd_state * state) for(i = 0; i < 8; i++) emb_pdu[i + 0] = syncdata[i]; for(i = 0; i < 8; i++) emb_pdu[i + 8] = syncdata[i + 40]; - + emb_ok = -1; if(QR_16_7_6_decode(emb_pdu)) { @@ -237,8 +237,8 @@ void dmrMS (dsd_opts * opts, dsd_state * state) memcpy (ambe_fr4, ambe_fr2, sizeof(ambe_fr2)); - //copy ambe_fr frames first, running process mbe will correct them, - //but this also leads to issues extracting good le mi values when + //copy ambe_fr frames first, running process mbe will correct them, + //but this also leads to issues extracting good le mi values when //we go to do correction on them there too memcpy (m1, ambe_fr, sizeof(m1)); memcpy (m2, ambe_fr2, sizeof(m2)); @@ -265,7 +265,7 @@ void dmrMS (dsd_opts * opts, dsd_state * state) playSynthesizedVoiceSS3(opts, state); } - if (opts->floating_point == 1) + if (opts->floating_point == 1) { // memcpy (state->f_r4, state->f_l4, sizeof(state->f_l4)); if(opts->pulse_digi_out_channels == 2) @@ -277,7 +277,7 @@ void dmrMS (dsd_opts * opts, dsd_state * state) dmr_data_burst_handler(opts, state, (uint8_t *)dummy_bits, 0xEB); //check the single burst/reverse channel opportunity dmr_sbrc (opts, state, power); - + fprintf (stderr, "\n"); dmr_alg_refresh (opts, state); } @@ -292,14 +292,14 @@ void dmrMS (dsd_opts * opts, dsd_state * state) state->last_vc_sync_time = time(NULL); vc++; - + //reset emb components cc = 25; power = 9; //power and pre-emption indicator lcss = 9; //this is necessary because we need to skip and collect dibits, not just skip them - if (vc > 6) goto END; + if (vc > 6) goto END; skipDibit (opts, state, 144); //skip to next tdma channel @@ -365,10 +365,10 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state) const int *w, *x, *y, *z; //cach - char cachdata[25]; + char cachdata[25]; UNUSED(cachdata); - state->dmrburstL = 16; + state->dmrburstL = 16; state->currentslot = 0; //force to slot 0 dibit_p = state->dmr_payload_p - 90; @@ -520,8 +520,8 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state) memcpy (ambe_fr4, ambe_fr2, sizeof(ambe_fr2)); - //copy ambe_fr frames first, running process mbe will correct them, - //but this also leads to issues extracting good le mi values when + //copy ambe_fr frames first, running process mbe will correct them, + //but this also leads to issues extracting good le mi values when //we go to do correction on them there too memcpy (m1, ambe_fr, sizeof(m1)); memcpy (m2, ambe_fr2, sizeof(m2)); @@ -548,7 +548,7 @@ void dmrMSBootstrap (dsd_opts * opts, dsd_state * state) playSynthesizedVoiceSS3(opts, state); } - if (opts->floating_point == 1) + if (opts->floating_point == 1) { // memcpy (state->f_r4, state->f_l4, sizeof(state->f_l4)); if(opts->pulse_digi_out_channels == 2) diff --git a/src/dmr_pdu.c b/src/dmr_pdu.c index 27b03af..338efdb 100644 --- a/src/dmr_pdu.c +++ b/src/dmr_pdu.c @@ -40,7 +40,7 @@ void utf16_to_text (dsd_state * state, uint8_t wr, uint16_t len, uint8_t * input else fprintf (stderr, "-"); //TODO: Add TMS String to ncurses string w/ wide char support? - //for now, just rip the first 40 or so chars lower byte value + //for now, just rip the first 40 or so chars lower byte value //in the ASCII Range (should be alright for a quick visual) char c[2]; c[0] = (char)input[i+1]; c[2] = 0; if (wr == 1&& i < 76 && input[i+1] < 0x7F && input[i+1] >= 0x20) @@ -71,7 +71,7 @@ void utf8_to_text (dsd_state * state, uint8_t wr, uint16_t len, uint8_t * input) // break; else fprintf (stderr, "-"); - //for now, just rip the first 40 or so chars lower byte value + //for now, just rip the first 40 or so chars lower byte value //in the ASCII Range (should be alright for a quick visual) char c = input[i]; if (wr == 1 && i < 38 && c < 0x7F && c >= 0x20) @@ -102,8 +102,8 @@ void dmr_sd_pdu (dsd_opts * opts, dsd_state * state, uint16_t len, uint8_t * DMR if (len >= (127*18)) len = 127*18; //sanity check of sorts, prevent extra long line print outs in the console utf8_to_text(state, 0, len, DMR_PDU); //generic catch-all to see if anything relevant is there // utf16_to_text(state, 0, len, DMR_PDU); //generic catch-all to see if anything relevant is there - } - + } + } //reading ETSI, seems like these aren't compressed, just that they are preset indexed values on the radio @@ -148,7 +148,7 @@ void dmr_udp_comp_pdu (dsd_opts * opts, dsd_state * state, uint16_t len, uint8_t sprintf (addrstring[1], "%s", "Manufacturer Specific"); //according to ETSI, if spid and/or dpid is zero, their respective port is defined in this header, otherwise, they are preset indexed values - + //look for and set optional port values and the ptr value to start of data uint16_t ptr = 5; @@ -242,7 +242,7 @@ void decode_ip_pdu (dsd_opts * opts, dsd_state * state, uint16_t len, uint8_t * { uint8_t slot = state->currentslot; - + //the IPv4 Header uint8_t version = input[0] >> 4; //may need to read ahead and get this value before coming here uint8_t ihl = input[0] & 0xF; //decompressed value is 0x05 (may need to check this before preceeding) @@ -295,7 +295,7 @@ void decode_ip_pdu (dsd_opts * opts, dsd_state * state, uint16_t len, uint8_t * fprintf (stderr, "\n ------------Attached Message-------------"); decode_ip_pdu(opts, state, len-28, input+28); } - + } else if (prot == 0x11) //UDP @@ -348,11 +348,11 @@ void decode_ip_pdu (dsd_opts * opts, dsd_state * state, uint16_t len, uint8_t * uint8_t tms_ack = (tms_hdr >> 0) & 0xF; if (opts->payload == 1) fprintf (stderr, "HDR: %02X; ", tms_hdr); - + //optional address len and address value uint8_t tms_adl = input[tms_ptr++]; if (tms_adl != 0) - { + { //the encoding seems to start at the adl (len) byte, but does not include it //so, to get the decoder to work, we well go back one byte and zero it out tms_ptr--; //back up one position @@ -452,7 +452,7 @@ void decode_ip_pdu (dsd_opts * opts, dsd_state * state, uint16_t len, uint8_t * //known P25 Ports else if (port1 == 49198 && port2 == 49198) { - sprintf (state->dmr_lrrp_gps[slot], "P25 Tier 2 LOCN SRC(IP): %d.%d.%d.%d; DST(IP): %d.%d.%d.%d; ", + sprintf (state->dmr_lrrp_gps[slot], "P25 Tier 2 LOCN SRC(IP): %d.%d.%d.%d; DST(IP): %d.%d.%d.%d; ", input[12], input[13], input[14], input[15], input[16], input[17], input[18], input[19]); fprintf (stderr, "P25 Tier 2 Location Service;"); //LRRP dmr_lrrp (opts, state, len, src24, dst24, input+28); //same offsets as DMR variety (unknown) @@ -468,7 +468,7 @@ void decode_ip_pdu (dsd_opts * opts, dsd_state * state, uint16_t len, uint8_t * } - else + else { sprintf (state->dmr_lrrp_gps[slot], " IP Call SRC: %d; DST: %d; Protocol: %d;", src24, dst24, prot); fprintf(stderr, "Unknown IP Protocol: %02X;", prot); @@ -476,7 +476,7 @@ void decode_ip_pdu (dsd_opts * opts, dsd_state * state, uint16_t len, uint8_t * // utf8_to_text(state, 0, len-28, input+28); // else utf8_to_text(state, 0, len, input+28); } - + } //The contents of this function are mostly trial and error @@ -536,7 +536,7 @@ void dmr_lrrp (dsd_opts * opts, dsd_state * state, uint16_t len, uint32_t source case 0x0D: //message len indicator if (i == 0) //see if this is the first octet, otherwise, can't verify this is going to work { - message_len = DMR_PDU[i+1]; + message_len = DMR_PDU[i+1]; i += 3; //next byte is len, then next two are usually 0x22 0xXX or 0x23 0xXX lrrp_confidence++; } @@ -545,7 +545,7 @@ void dmr_lrrp (dsd_opts * opts, dsd_state * state, uint16_t len, uint32_t source //tokens case 0x51: //circle-2d case 0x54: //circle-3d - case 0x55: //circle-3d + case 0x55: //circle-3d if (message_len > 0 && lat == 0) { //debug @@ -554,12 +554,12 @@ void dmr_lrrp (dsd_opts * opts, dsd_state * state, uint16_t len, uint32_t source lat = ( ( (DMR_PDU[i+1] << 24 ) + (DMR_PDU[i+2] << 16) + (DMR_PDU[i+3] << 8) + DMR_PDU[i+4]) * 1 ); lon = ( ( (DMR_PDU[i+5] << 24 ) + (DMR_PDU[i+6] << 16) + (DMR_PDU[i+7] << 8) + DMR_PDU[i+8]) * 1 ); rad = (DMR_PDU[i+9] << 8) + DMR_PDU[i+10]; - i += 10; + i += 10; if (lat > 0 && lon > 0) lrrp_confidence++; else lat = 0; } break; - + case 0x34: //Time case 0x35: //Time if (message_len > 0 && year == 0) @@ -570,14 +570,14 @@ void dmr_lrrp (dsd_opts * opts, dsd_state * state, uint16_t len, uint32_t source hour = ((DMR_PDU[i+3] & 0x01) << 4) + ((DMR_PDU[i+4] & 0xF0) >> 4); minute = ((DMR_PDU[i+4] & 0x0F) << 2) + ((DMR_PDU[i+5] & 0xC0) >> 6); second = (DMR_PDU[i+5] & 0x3F); - i += 5; + i += 5; //sanity check if (year > 2000 && year <= 2026) lrrp_confidence++; if (year > 2025 || year < 2000) year = 0; //needs future proofing } break; - - case 0x66: //point-2d + + case 0x66: //point-2d if (message_len > 0 && lat == 0) { lat = ( ( (DMR_PDU[i+1] << 24 ) + (DMR_PDU[i+2] << 16) + (DMR_PDU[i+3] << 8) + DMR_PDU[i+4]) * 1 ); @@ -593,8 +593,8 @@ void dmr_lrrp (dsd_opts * opts, dsd_state * state, uint16_t len, uint32_t source lat = ( ( (DMR_PDU[i+1] << 24 ) + (DMR_PDU[i+2] << 16) + (DMR_PDU[i+3] << 8) + DMR_PDU[i+4]) * 1 ); lon = ( ( (DMR_PDU[i+5] << 24 ) + (DMR_PDU[i+6] << 16) + (DMR_PDU[i+7] << 8) + DMR_PDU[i+8]) * 1 ); alt = DMR_PDU[i+9]; - i += 9; - if (lat > 0 && lon > 0) lrrp_confidence++; + i += 9; + if (lat > 0 && lon > 0) lrrp_confidence++; else lat = 0; } break; @@ -623,8 +623,8 @@ void dmr_lrrp (dsd_opts * opts, dsd_state * state, uint16_t len, uint32_t source lrrp_confidence++; } break; - - //unknown tokens + + //unknown tokens default: //do nothing break; @@ -634,7 +634,7 @@ void dmr_lrrp (dsd_opts * opts, dsd_state * state, uint16_t len, uint32_t source if (message_len > 0) { fprintf (stderr, "%s", KYEL); - + if (lrrp_confidence >= 3) //minimal of src, dst, and message len indicator { @@ -656,14 +656,14 @@ void dmr_lrrp (dsd_opts * opts, dsd_state * state, uint16_t len, uint32_t source { lat = lat & 0x7FFFFFFF; lat_sign = -1; - // lat = 0x80000000 - lat; //not sure why this doesn't work here like it does on lon, extra bit? - } + // lat = 0x80000000 - lat; //not sure why this doesn't work here like it does on lon, extra bit? + } if (lon & 0x80000000) { lon = lon & 0x7FFFFFFF; lon_sign = -1; lon = 0x80000000 - lon; - } + } lat_fin = (double)lat * lat_unit * lat_sign; lon_fin = (double)lon * lon_unit * lon_sign; @@ -714,7 +714,7 @@ void dmr_lrrp (dsd_opts * opts, dsd_state * state, uint16_t len, uint32_t source //write data header source if not available in lrrp data if (!source) fprintf (pFile, "%08lld\t", state->dmr_lrrp_source[state->currentslot]); //source address from data header if (source) fprintf (pFile, "%08d\t", source); //add source form decoded audio if available, else its from the header - + if (timestr != NULL) { free (timestr); @@ -748,13 +748,13 @@ void dmr_lrrp (dsd_opts * opts, dsd_state * state, uint16_t len, uint32_t source if (vel_set) sprintf (velstr, " %.4lf km/h", velocity * 3.6); if (deg_set) sprintf (degstr, " %d%s ", degrees, deg_glyph); sprintf (state->dmr_lrrp_gps[slot], "%s%s%s", lrrpstr, velstr, degstr); - + } - + } fprintf (stderr, "%s", KNRM); - + } void dmr_locn (dsd_opts * opts, dsd_state * state, uint16_t len, uint8_t * DMR_PDU) @@ -812,9 +812,9 @@ void dmr_locn (dsd_opts * opts, dsd_state * state, uint16_t len, uint8_t * DMR_P day = ((DMR_PDU[i+7] - 0x30) << 4) | (DMR_PDU[i+8] - 0x30); month = ((DMR_PDU[i+9] - 0x30) << 4) | (DMR_PDU[i+10] - 0x30); year = ((DMR_PDU[i+11] - 0x30) << 4) | (DMR_PDU[i+12] - 0x30); - i += 12; + i += 12; break; - + case 0x53: //S -- South lat_sign = -1; case 0x4E: //N -- North @@ -824,11 +824,11 @@ void dmr_locn (dsd_opts * opts, dsd_state * state, uint16_t len, uint8_t * DMR_P lat_sec = ((DMR_PDU[i+6] - 0x30) << 12) | ((DMR_PDU[i+7] - 0x30) << 8) | ((DMR_PDU[i+8] - 0x30) << 4) | ((DMR_PDU[i+9] - 0x30) << 0); i += 8; break; - + case 0x57: //W -- West lon_sign = -1; case 0x45: //E -- East - lon = 1; + lon = 1; lon_deg = ((DMR_PDU[i+1] - 0x30) << 8) | ((DMR_PDU[i+2] - 0x30) << 4) | ((DMR_PDU[i+3] - 0x30) << 0); lon_min = ((DMR_PDU[i+4] - 0x30) << 4) | (DMR_PDU[i+5] - 0x30); lon_sec = ((DMR_PDU[i+7] - 0x30) << 12) | ((DMR_PDU[i+8] - 0x30) << 8) | ((DMR_PDU[i+9] - 0x30) << 4) | ((DMR_PDU[i+10] - 0x30) << 0); @@ -841,7 +841,7 @@ void dmr_locn (dsd_opts * opts, dsd_state * state, uint16_t len, uint8_t * DMR_P } //end switch - } //for i + } //for i if (lat && lon) { @@ -889,10 +889,10 @@ void dmr_locn (dsd_opts * opts, dsd_state * state, uint16_t len, uint8_t * DMR_P if (!time) fprintf (pFile, "%s\t", datestr ); if (!time) fprintf (pFile, "%s\t", timestr ); if (time) fprintf (pFile, "20%02X/%02X/%02X\t%02X:%02X:%02X\t", year, month, day, hour, minute, second); - + //write data header source from data header fprintf (pFile, "%08lld\t", state->dmr_lrrp_source[state->currentslot]); - + if (timestr != NULL) { free (timestr); @@ -914,6 +914,6 @@ void dmr_locn (dsd_opts * opts, dsd_state * state, uint16_t len, uint8_t * DMR_P fclose (pFile); } - } + } } \ No newline at end of file diff --git a/src/dmr_pi.c b/src/dmr_pi.c index bf3dd08..44ddfd0 100644 --- a/src/dmr_pi.c +++ b/src/dmr_pi.c @@ -7,14 +7,14 @@ * LWVMOBILE * 2022-12 DSD-FME Florida Man Edition *-----------------------------------------------------------------------------*/ - + #include "dsd.h" void dmr_pi (dsd_opts * opts, dsd_state * state, uint8_t PI_BYTE[], uint32_t CRCCorrect, uint32_t IrrecoverableErrors) { UNUSED2(opts, CRCCorrect); - if((IrrecoverableErrors == 0)) + if((IrrecoverableErrors == 0)) { //update cc amd vc sync time for trunking purposes (particularly Con+) @@ -22,14 +22,14 @@ void dmr_pi (dsd_opts * opts, dsd_state * state, uint8_t PI_BYTE[], uint32_t CRC { state->last_vc_sync_time = time(NULL); state->last_cc_sync_time = time(NULL); - } + } if (state->currentslot == 0) { state->payload_algid = PI_BYTE[0]; state->payload_keyid = PI_BYTE[2]; state->payload_mi = ( ((PI_BYTE[3]) << 24) + ((PI_BYTE[4]) << 16) + ((PI_BYTE[5]) << 8) + (PI_BYTE[6]) ); - if (state->payload_algid < 0x26) + if (state->payload_algid < 0x26) { fprintf (stderr, "%s ", KYEL); fprintf (stderr, "\n Slot 1"); @@ -70,7 +70,7 @@ void dmr_pi (dsd_opts * opts, dsd_state * state, uint8_t PI_BYTE[], uint32_t CRC { fprintf (stderr, "\n"); LFSR128d (state); - } + } } if (state->payload_algid >= 0x26) @@ -87,7 +87,7 @@ void dmr_pi (dsd_opts * opts, dsd_state * state, uint8_t PI_BYTE[], uint32_t CRC state->payload_algidR = PI_BYTE[0]; state->payload_keyidR = PI_BYTE[2]; state->payload_miR = ( ((PI_BYTE[3]) << 24) + ((PI_BYTE[4]) << 16) + ((PI_BYTE[5]) << 8) + (PI_BYTE[6]) ); - if (state->payload_algidR < 0x26) + if (state->payload_algidR < 0x26) { fprintf (stderr, "%s ", KYEL); fprintf (stderr, "\n Slot 2"); @@ -128,7 +128,7 @@ void dmr_pi (dsd_opts * opts, dsd_state * state, uint8_t PI_BYTE[], uint32_t CRC { fprintf (stderr, "\n"); LFSR128d (state); - } + } } if (state->payload_algidR >= 0x26) @@ -171,7 +171,7 @@ void LFSR(dsd_state * state) state->payload_mi = lfsr; } - if (state->currentslot == 1) + if (state->currentslot == 1) { fprintf (stderr, "%s", KYEL); @@ -191,13 +191,13 @@ void LFSR64(dsd_state * state) if (state->currentslot == 0) { - lfsr = (uint64_t) state->payload_mi; + lfsr = (uint64_t) state->payload_mi; } - else lfsr = (uint64_t) state->payload_miR; + else lfsr = (uint64_t) state->payload_miR; uint8_t cnt = 0; - for(cnt=0;cnt<32;cnt++) + for(cnt=0;cnt<32;cnt++) { unsigned long long int bit = ( (lfsr >> 31) ^ (lfsr >> 21) ^ (lfsr >> 1) ^ (lfsr >> 0) ) & 0x1; lfsr = (lfsr << 1) | bit; @@ -237,7 +237,7 @@ void LFSR128d(dsd_state * state) unsigned long long int lfsr = 0; if (state->currentslot == 0) - lfsr = state->payload_mi; + lfsr = state->payload_mi; else lfsr = state->payload_miR; unsigned long long int next_mi; @@ -260,7 +260,7 @@ void LFSR128d(dsd_state * state) int cnt = 0; int x = 32; unsigned long long int bit; - for(cnt=0;cnt<96;cnt++) + for(cnt=0;cnt<96;cnt++) { //32,22,2,1 bit = ( (lfsr >> 31) ^ (lfsr >> 21) ^ (lfsr >> 1) ^ (lfsr >> 0) ) & 0x1; diff --git a/src/dpmr_voice.c b/src/dpmr_voice.c index 9573bee..e9c2604 100644 --- a/src/dpmr_voice.c +++ b/src/dpmr_voice.c @@ -412,7 +412,7 @@ void processdPMRvoice (dsd_opts * opts, dsd_state * state) { fprintf (stderr, "%s", KRED); fprintf(stderr, " Src=(CRC ERR) Channel Code =(CRC ERR)"); - fprintf (stderr, "%s", KNRM); + fprintf (stderr, "%s", KNRM); } if (state->dPMRVoiceFS2Frame.Version[0] == 3) @@ -439,7 +439,7 @@ void processdPMRvoice (dsd_opts * opts, dsd_state * state) //reset scrambler key seed on frame 0 if (state->dPMRVoiceFS2Frame.FrameNumbering[o] == 0) state->payload_miN = 0; - + //depending on first or second TCH, set start and end variables appropriately if (o == 1) { @@ -448,14 +448,14 @@ void processdPMRvoice (dsd_opts * opts, dsd_state * state) } - //this is used so we can simply pass the voice here to the + //this is used so we can simply pass the voice here to the //nxdn scrambler by telling mbe these are nxdn frames and to //apply the same descramble method to them if necessary - int realsynctype = state->synctype; + int realsynctype = state->synctype; // fprintf (stderr, "\nCommunication Mode: %d\n", state->dPMRVoiceFS2Frame.CommunicationMode[o]); // fprintf (stderr, "Encryption Mode: %d\n", state->dPMRVoiceFS2Frame.Version[o]); //shows as 3 (manufacturer specific, 5.16) on the dPMR scrambler values received - // fprintf (stderr, "Superframe Number: %d", state->dPMRVoiceFS2Frame.FrameNumbering[o]); + // fprintf (stderr, "Superframe Number: %d", state->dPMRVoiceFS2Frame.FrameNumbering[o]); if((state->dPMRVoiceFS2Frame.CommunicationMode[o] == 0) || (state->dPMRVoiceFS2Frame.CommunicationMode[o] == 1) || @@ -469,14 +469,14 @@ void processdPMRvoice (dsd_opts * opts, dsd_state * state) state->nxdn_cipher_type = 0x01; //turn on nxdn scrambler cipher state->dmr_encL = 1; //flag on enc bit here so we can mute if no key provided } - + //flag back off if key is provided if (state->R != 0) state->dmr_encL = 0; //print Current Frame Number if payload verbosity enabled if (opts->payload == 1) fprintf (stderr, "\n FN %d/4", state->dPMRVoiceFS2Frame.FrameNumbering[o]+1); - + //There are 4 AMBE voice frames per TCH for(i = start; i < end; i++) { @@ -485,14 +485,14 @@ void processdPMRvoice (dsd_opts * opts, dsd_state * state) playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 1) playSynthesizedVoiceFM(opts, state); - } + } //set the correct sync type again and flag off the cipher state->synctype = realsynctype; state->nxdn_cipher_type = 0; - } - } + } + } fprintf(stderr, "\n"); diff --git a/src/dsd_alias.c b/src/dsd_alias.c index 1ead694..6138b17 100644 --- a/src/dsd_alias.c +++ b/src/dsd_alias.c @@ -9,7 +9,7 @@ #include "dsd.h" //Motorola P25 OTA Alias Decoding ripped/demystified from Ilya Smirnov's SDRTrunk Voodoo Code -uint8_t moto_alias_lut[256] = { +uint8_t moto_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, 0x1B, 0x4F, 0x8C, 0x09, 0x40, @@ -185,7 +185,7 @@ void apx_embedded_alias_blocks_phase1 (dsd_opts * opts, dsd_state * state, uint8 //pass to alias decoder apx_embedded_alias_decode (opts, state, slot, num_bits, state->dmr_pdu_sf[slot]); - + //clear out now stale storage memset (state->dmr_pdu_sf[slot], 0, sizeof(state->dmr_pdu_sf[slot])); @@ -195,7 +195,7 @@ void apx_embedded_alias_blocks_phase1 (dsd_opts * opts, dsd_state * state, uint8 void apx_embedded_alias_header_phase2 (dsd_opts * opts, dsd_state * state, uint8_t slot, uint8_t * lc_bits) { - + UNUSED(opts); uint8_t ta_len = (uint8_t)ConvertBitIntoBytes(&lc_bits[40], 8); uint8_t sn = (uint8_t)ConvertBitIntoBytes(&lc_bits[64], 4); @@ -224,7 +224,7 @@ void apx_embedded_alias_header_phase2 (dsd_opts * opts, dsd_state * state, uint8 void apx_embedded_alias_blocks_phase2 (dsd_opts * opts, dsd_state * state, uint8_t slot, uint8_t * lc_bits) { - + UNUSED(opts); int16_t rel_bits = 100; //number of relevant bits in each block int16_t rel_st = 36; //start of relevant bits in this block @@ -292,7 +292,7 @@ void apx_embedded_alias_blocks_phase2 (dsd_opts * opts, dsd_state * state, uint8 //pass to alias decoder apx_embedded_alias_decode (opts, state, slot, num_bits, state->dmr_pdu_sf[slot]); - + //clear out now stale storage memset (state->dmr_pdu_sf[slot], 0, sizeof (state->dmr_pdu_sf[slot])); @@ -367,7 +367,7 @@ void apx_embedded_alias_decode (dsd_opts * opts, dsd_state * state, uint8_t slot uint8_t mult2 = 1; uint8_t shortstop = accum_mult | 0x1; uint8_t increment = shortstop << 1; - + while(mult2 != -1 && shortstop != 1) { shortstop += increment; @@ -560,7 +560,7 @@ void l3h_embedded_alias_decode (dsd_opts * opts, dsd_state * state, uint8_t slot void tait_iso7_embedded_alias_decode (dsd_opts * opts, dsd_state * state, uint8_t slot, int16_t len, uint8_t * input) { - + UNUSED(slot); uint8_t alias[24]; memset(alias, 0, sizeof(alias)); for (uint8_t i = 0; i < len; i++) diff --git a/src/dsd_audio.c b/src/dsd_audio.c index 3eae07b..a62bd3f 100644 --- a/src/dsd_audio.c +++ b/src/dsd_audio.c @@ -189,7 +189,7 @@ void parse_pulse_output_string (dsd_opts * opts, char * input) void openOSSOutput (dsd_opts * opts) { - int fmt; + int fmt; int speed = 48000; if (opts->audio_in_type == 5) //if((strncmp(opts->audio_in_dev, "/dev/dsp", 8) == 0)) or 'split' == 0 { @@ -229,7 +229,7 @@ void openOSSOutput (dsd_opts * opts) fprintf (stderr, "ioctl setfmt error \n"); } - opts->audio_out_type = 5; //5 for 1 channel - 48k OSS 16-bit short output (matching with input) + opts->audio_out_type = 5; //5 for 1 channel - 48k OSS 16-bit short output (matching with input) opts->pulse_digi_rate_out = 48000; //this is used to force to upsample and also allow source audio monitor conditional check opts->pulse_digi_out_channels = 1; //this is used to allow source audio monitor conditional check opts->audio_gain = 0; @@ -250,7 +250,7 @@ void openOSSOutput (dsd_opts * opts) exit(1); } - //Setup the device. Note that it's important to set the sample format, number of channels and sample rate exactly in this order. Some devices depend on the order. + //Setup the device. Note that it's important to set the sample format, number of channels and sample rate exactly in this order. Some devices depend on the order. fmt = 0; if (ioctl (opts->audio_out_fd, SNDCTL_DSP_RESET) < 0) @@ -282,7 +282,7 @@ void openOSSOutput (dsd_opts * opts) } if (opts->pulse_digi_out_channels == 2) fmt = 1; - else fmt = 0; + else fmt = 0; if (ioctl (opts->audio_out_fd, SNDCTL_DSP_STEREO, &fmt) < 0) { @@ -296,7 +296,7 @@ void openOSSOutput (dsd_opts * opts) opts->audio_out_type = 2; else opts->audio_out_type = 5; - //debug + //debug fprintf (stderr, "Using OSS Output with %dk/%d channel configuration.\n", opts->pulse_digi_rate_out, opts->pulse_digi_out_channels); } } @@ -682,7 +682,7 @@ playSynthesizedVoice (dsd_opts * opts, dsd_state * state) state->audio_out_idx2 = 0; state->audio_out_idx = 0; goto end_psv; - } + } if (state->audio_out_idx > opts->delay) { @@ -694,7 +694,7 @@ playSynthesizedVoice (dsd_opts * opts, dsd_state * state) } else if (opts->audio_out_type == 0) { - pa_simple_write(opts->pulse_digi_dev_out, (state->audio_out_buf_p - state->audio_out_idx), (state->audio_out_idx * 2), NULL); + pa_simple_write(opts->pulse_digi_dev_out, (state->audio_out_buf_p - state->audio_out_idx), (state->audio_out_idx * 2), NULL); state->audio_out_idx = 0; } else if (opts->audio_out_type == 8) //UDP Audio Out -- Forgot some things still use this for now @@ -737,7 +737,7 @@ playSynthesizedVoiceR (dsd_opts * opts, dsd_state * state) } else if (opts->audio_out_type == 0) { - pa_simple_write(opts->pulse_digi_dev_outR, (state->audio_out_buf_pR - state->audio_out_idxR), (state->audio_out_idxR * 2), NULL); + pa_simple_write(opts->pulse_digi_dev_outR, (state->audio_out_buf_pR - state->audio_out_idxR), (state->audio_out_idxR * 2), NULL); state->audio_out_idxR = 0; } else if (opts->audio_out_type == 8) //UDP Audio Out -- Not sure how this would handle, but R never gets called anymore, so just here for symmetry @@ -905,7 +905,7 @@ openAudioInDevice (dsd_opts * opts) { //debug fprintf (stderr, "Opening M17 .rrc headless wav file\n"); - + opts->audio_in_type = 2; opts->audio_in_file_info = calloc(1, sizeof(SF_INFO)); opts->audio_in_file_info->samplerate = 48000; @@ -992,8 +992,8 @@ openAudioInDevice (dsd_opts * opts) { opts->audio_in_type = 2; //two now, seperating STDIN and wav files opts->audio_in_file_info = calloc(1, sizeof(SF_INFO)); - opts->audio_in_file_info->samplerate=opts->wav_sample_rate; - opts->audio_in_file_info->channels=1; + opts->audio_in_file_info->samplerate=opts->wav_sample_rate; + opts->audio_in_file_info->channels=1; opts->audio_in_file_info->channels = 1; opts->audio_in_file_info->seekable=0; opts->audio_in_file_info->format=SF_FORMAT_RAW|SF_FORMAT_PCM_16|SF_ENDIAN_LITTLE; diff --git a/src/dsd_audio2.c b/src/dsd_audio2.c index bab8028..a642ed4 100644 --- a/src/dsd_audio2.c +++ b/src/dsd_audio2.c @@ -1,9 +1,9 @@ /*------------------------------------------------------------------------------- - * - * + * + * * * TODO: Fill me in' - * + * * * LWVMOBILE * 2023-10 DSD-FME Florida Man Edition @@ -15,7 +15,7 @@ //NOTE: Tones produce ringing sound when put through the hpf_d, may want to look into tweaking it, //or looking for a way to store is_tone by glancing at ambe_d values and not running hpf_d on them -//TODO: WAV File saving (works fine on shorts, but on float, writing short to wav is not auto-gained, +//TODO: WAV File saving (works fine on shorts, but on float, writing short to wav is not auto-gained, //so super quiet, either convert to float wav files, or run processAudio AFTER memcpy of the temp_buf) //simple method -- produces cleaner results, but can be muted (or very loud) at times @@ -36,7 +36,7 @@ // if (opts->audio_gain != 0 && slot == 1) // gain = state->aout_gainR / 25.0f; - + // //mono output handles slightly different, need to further decimate // if (opts->pulse_digi_out_channels == 1) // df *= 4.0f; @@ -55,7 +55,7 @@ // //user gain factor // samp[i] *= gain; - + // } // } @@ -564,7 +564,7 @@ void playSynthesizedVoiceFS (dsd_opts * opts, dsd_state * state) encL = 1; } } - + //checkdown to see if we can lift the 'mute' if a key is available if (encL) { @@ -682,7 +682,7 @@ void playSynthesizedVoiceFS (dsd_opts * opts, dsd_state * state) void playSynthesizedVoiceFM (dsd_opts * opts, dsd_state * state) { - + agf(opts, state, state->f_l,0); //mono may need an additional decimation @@ -780,7 +780,7 @@ void playSynthesizedVoiceFM (dsd_opts * opts, dsd_state * state) memset (state->audio_out_buf, 0, 100 * sizeof (short)); state->audio_out_idx2 = 0; } - + memset (state->f_l, 0.0f, sizeof(state->f_l)); memset (state->audio_out_temp_buf, 0.0f, sizeof(state->audio_out_temp_buf)); @@ -1200,7 +1200,7 @@ void playSynthesizedVoiceSS3 (dsd_opts * opts, dsd_state * state) // } //if TG Hold in place, mute anything but that TG #132 - if (state->tg_hold != 0 && state->tg_hold != TGL) + if (state->tg_hold != 0 && state->tg_hold != TGL) encL = 1; if (state->tg_hold != 0 && state->tg_hold != TGR) encR = 1; @@ -1598,7 +1598,7 @@ void playSynthesizedVoiceSS4 (dsd_opts * opts, dsd_state * state) if (memcmp(empty, stereo_samp4, sizeof(empty)) != 0) udp_socket_blaster (opts, state, 320*2, stereo_samp4); } - + if (opts->audio_out_type == 1 || opts->audio_out_type == 2) //STDOUT or OSS 8k/2channel { @@ -1789,7 +1789,7 @@ void playSynthesizedVoiceSS18 (dsd_opts * opts, dsd_state * state) // } //if TG Hold in place, mute anything but that TG #132 - if (state->tg_hold != 0 && state->tg_hold != TGL) + if (state->tg_hold != 0 && state->tg_hold != TGL) encL = 1; if (state->tg_hold != 0 && state->tg_hold != TGR) encR = 1; @@ -1904,7 +1904,7 @@ void playSynthesizedVoiceSS18 (dsd_opts * opts, dsd_state * state) udp_socket_blaster (opts, state, 320*2, stereo_sf[j]); } } - + if (opts->audio_out_type == 1 || opts->audio_out_type == 2) //STDOUT or OSS 8k/2channel { @@ -2033,7 +2033,7 @@ void agf (dsd_opts * opts, dsd_state * state, float samp[160], int slot) aavg /= 20.0f; //average of the 20 samples - //debug + //debug // fprintf (stderr, "\nS%d - DF = %f AAVG = %f", slot, df, aavg); if (slot == 0) @@ -2051,7 +2051,7 @@ void agf (dsd_opts * opts, dsd_state * state, float samp[160], int slot) aavg = 0.0f; //reset } //j loop - + AGF_END: ; //do nothing } @@ -2088,7 +2088,7 @@ void agsm (dsd_opts * opts, dsd_state * state, short * input, int len) avg += (float)samp[i]; avg /= (float)len; - + coeff = fabsf (nom / max); //keep coefficient with tolerable range when silence to prevent crackle/buzz @@ -2097,7 +2097,7 @@ void agsm (dsd_opts * opts, dsd_state * state, short * input, int len) //apply the coefficient to bring the max value to our desired maximum value for (i = 0; i < 20; i++) samp[i] *= coeff; - + //debug // fprintf (stderr, "\n M: %f; C: %f; A: %f; ", max, coeff, avg); @@ -2107,7 +2107,7 @@ void agsm (dsd_opts * opts, dsd_state * state, short * input, int len) // fprintf (stderr, " in: %d", input[i]); // fprintf (stderr, " out: %f", samp[i]); // } - + //return new smaple values post agc for (i = 0; i < len; i++) input[i] = (short)samp[i]; diff --git a/src/dsd_dibit.c b/src/dsd_dibit.c index 5424f7a..6c2e758 100644 --- a/src/dsd_dibit.c +++ b/src/dsd_dibit.c @@ -267,7 +267,7 @@ int digitize (dsd_opts* opts, dsd_state* state, int symbol) else if ((state->synctype == 1) || (state->synctype == 3) || (state->synctype == 5) || (state->synctype == 9) || (state->synctype == 11) || (state->synctype == 13) || (state->synctype == 17) || (state->synctype == 29) || (state->synctype == 31) || - (state->synctype == 77) || (state->synctype == 87) ||(state->synctype == 36) || + (state->synctype == 77) || (state->synctype == 87) ||(state->synctype == 36) || (state->synctype == 99) ) { @@ -279,8 +279,8 @@ int digitize (dsd_opts* opts, dsd_state* state, int symbol) // 13 -DMR (inverted signal data frame) // 17 -M17 STR // 29 -NXDN (inverted FSW) - // 31 -YSF - // 36 -P25p2 + // 31 -YSF + // 36 -P25p2 // 77 -M17 BRT // 87 -M17 PKT // 99 -M17 Preamble @@ -334,7 +334,7 @@ int digitize (dsd_opts* opts, dsd_state* state, int symbol) state->dibit_buf_p++; //dmr buffer - *state->dmr_payload_p = invert_dibit(dibit); + *state->dmr_payload_p = invert_dibit(dibit); state->dmr_payload_p++; //dmr buffer end @@ -449,13 +449,13 @@ get_dibit_and_analog_signal (dsd_opts* opts, dsd_state* state, int* out_analog_s dibit = digitize (opts, state, symbol); - if (opts->audio_in_type == 4) + if (opts->audio_in_type == 4) { //assign dibit from last symbol/dibit read from capture bin dibit = state->symbolc; if (state->use_throttle == 1) { - usleep(0); + usleep(0); } } diff --git a/src/dsd_file.c b/src/dsd_file.c index 72dd332..43bc13f 100644 --- a/src/dsd_file.c +++ b/src/dsd_file.c @@ -52,7 +52,7 @@ void saveAmbe2450Data (dsd_opts * opts, dsd_state * state, char *ambe_d) fputc (err, opts->mbe_out_f); k = 0; - for (i = 0; i < 6; i++) + for (i = 0; i < 6; i++) { b = 0; for (j = 0; j < 8; j++) @@ -78,7 +78,7 @@ void saveAmbe2450DataR (dsd_opts * opts, dsd_state * state, char *ambe_d) fputc (err, opts->mbe_out_fR); k = 0; - for (i = 0; i < 6; i++) + for (i = 0; i < 6; i++) { b = 0; for (j = 0; j < 8; j++) @@ -103,16 +103,16 @@ void PrintIMBEData (dsd_opts * opts, dsd_state * state, char *imbe_d) //for P25P imbe[i] = convert_bits_into_output((uint8_t *)imbe_d+(i*8), 8); fprintf(stderr, "%02X", imbe[i]); } - + fprintf(stderr, " err = [%X] [%X] ", state->errs, state->errs2); UNUSED(opts); } -void PrintAMBEData (dsd_opts * opts, dsd_state * state, char *ambe_d) +void PrintAMBEData (dsd_opts * opts, dsd_state * state, char *ambe_d) { - //cast as unsigned long long int and not uint64_t + //cast as unsigned long long int and not uint64_t //to avoid the %lx vs %llx warning on 32 or 64 bit unsigned long long int ambe = 0; @@ -147,7 +147,7 @@ readImbe4400Data (dsd_opts * opts, dsd_state * state, char *imbe_d) k = 0; - if (opts->payload == 1) + if (opts->payload == 1) { fprintf(stderr, "\n"); } @@ -169,12 +169,12 @@ readImbe4400Data (dsd_opts * opts, dsd_state * state, char *imbe_d) b = b & 255; k++; } - - if (opts->payload == 1) + + if (opts->payload == 1) { fprintf (stderr, "%02X", x); } - + } if (opts->payload == 1) { @@ -194,7 +194,7 @@ readAmbe2450Data (dsd_opts * opts, dsd_state * state, char *ambe_d) state->errs = state->errs2; k = 0; - if (opts->payload == 1) + if (opts->payload == 1) { fprintf(stderr, "\n"); } @@ -217,13 +217,13 @@ readAmbe2450Data (dsd_opts * opts, dsd_state * state, char *ambe_d) b = b & 255; k++; } - if (opts->payload == 1 && i < 6) + if (opts->payload == 1 && i < 6) { fprintf (stderr, "%02X", x); } - if (opts->payload == 1 && i == 6) + if (opts->payload == 1 && i == 6) { - fprintf (stderr, "%02X", x & 0x80); + fprintf (stderr, "%02X", x & 0x80); } } if (opts->payload == 1) @@ -337,7 +337,7 @@ void openMbeOutFile (dsd_opts * opts, dsd_state * state) sprintf (ext, ".dmb"); //new dstar file extension to make it read in and process properly } //dmr, nxdn, phase 2, x2-tdma - else sprintf (ext, ".amb"); + else sprintf (ext, ".amb"); //reset talkgroup id buffer for (i = 0; i < 12; i++) @@ -399,7 +399,7 @@ void openMbeOutFileR (dsd_opts * opts, dsd_state * state) sprintf (ext, ".dmb"); //new dstar file extension to make it read in and process properly } //dmr, nxdn, phase 2, x2-tdma - else sprintf (ext, ".amb"); + else sprintf (ext, ".amb"); //reset talkgroup id buffer for (i = 0; i < 12; i++) @@ -461,7 +461,7 @@ void openWavOutFileL (dsd_opts * opts, dsd_state * state) UNUSED(state); SF_INFO info; - info.samplerate = 8000; + info.samplerate = 8000; info.channels = 1; info.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16 | SF_ENDIAN_LITTLE; opts->wav_out_f = sf_open (opts->wav_out_file, SFM_RDWR, &info); //RDWR will append to file instead of overwrite file @@ -641,7 +641,7 @@ uint16_t parse_raw_user_string (char * input, uint8_t * output) uint16_t len = strlen((const char*)input); uint8_t shift = 0; - + //if zero is returned, just do two // if (len == 0) len = 2; @@ -654,7 +654,7 @@ uint16_t parse_raw_user_string (char * input, uint8_t * output) { shift = 1; len++; - } + } //divide by two to get octet len len /= 2; diff --git a/src/dsd_filters.c b/src/dsd_filters.c index 8a267bd..395210b 100644 --- a/src/dsd_filters.c +++ b/src/dsd_filters.c @@ -1,7 +1,7 @@ #include "dsd.h" //M17 Filter -- RRC Alpha = 0.5 S/s 48000 with 81 taps -#define M17ZEROS 80 +#define M17ZEROS 80 float m17gain = 3.16227766f; //sqrt of 10.0f static float m17xv[81]; @@ -64,7 +64,7 @@ float xcoeffs[61] = //reverted to original NXDN filters, do better with LICH/Data handling // NXDN48 filter - Original Version #define NXZEROS 134 -float nxgain = 15.95930463f; +float nxgain = 15.95930463f; static float nxv[NXZEROS+1]; float nxcoeffs[135] = @@ -115,17 +115,17 @@ static float dxv[DMRNZEROS+1]; // DMR filter F4EXB - root raised cosine alpha=0.7 Ts = 6650 S/s Fc = 48kHz const float dmrcoeffs[61] = -{0.0301506278, 0.0269200615, 0.0159662432, -0.0013114705, -0.0216605133, --0.0404938748, -0.0528141756, -0.0543747957, -0.0428325003, -0.0186176083, -0.0147202645, 0.0508418571, 0.0816392577, 0.0988113688, 0.0957187780, -0.0691512084, 0.0206194642, -0.0431564563, -0.1107569268, -0.1675773224, --0.1981519842, -0.1889130786, -0.1308939560, -0.0218608492, 0.1325685970, -0.3190962499, 0.5182530574, 0.7070497652, 0.8623526878, 0.9644213921, -1.0000000000, 0.9644213921, 0.8623526878, 0.7070497652, 0.5182530574, -0.3190962499, 0.1325685970, -0.0218608492, -0.1308939560, -0.1889130786, --0.1981519842, -0.1675773224, -0.1107569268, -0.0431564563, 0.0206194642, -0.0691512084, 0.0957187780, 0.0988113688, 0.0816392577, 0.0508418571, -0.0147202645, -0.0186176083, -0.0428325003, -0.0543747957, -0.0528141756, +{0.0301506278, 0.0269200615, 0.0159662432, -0.0013114705, -0.0216605133, +-0.0404938748, -0.0528141756, -0.0543747957, -0.0428325003, -0.0186176083, +0.0147202645, 0.0508418571, 0.0816392577, 0.0988113688, 0.0957187780, +0.0691512084, 0.0206194642, -0.0431564563, -0.1107569268, -0.1675773224, +-0.1981519842, -0.1889130786, -0.1308939560, -0.0218608492, 0.1325685970, +0.3190962499, 0.5182530574, 0.7070497652, 0.8623526878, 0.9644213921, +1.0000000000, 0.9644213921, 0.8623526878, 0.7070497652, 0.5182530574, +0.3190962499, 0.1325685970, -0.0218608492, -0.1308939560, -0.1889130786, +-0.1981519842, -0.1675773224, -0.1107569268, -0.0431564563, 0.0206194642, +0.0691512084, 0.0957187780, 0.0988113688, 0.0816392577, 0.0508418571, +0.0147202645, -0.0186176083, -0.0428325003, -0.0543747957, -0.0528141756, -0.0404938748, -0.0216605133, -0.0013114705, 0.0159662432, 0.0269200615, 0.0301506278}; // dPMR filter, version of F4EXB @@ -193,7 +193,7 @@ nxdn_filter(short sample) short dpmr_filter(short sample) { - return dsd_input_filter(sample, 4); + return dsd_input_filter(sample, 4); } short m17_filter (short sample) @@ -245,7 +245,7 @@ dsd_input_filter(short sample, int mode) default: return sample; } - + for (i = 0; i < zeros; i++) v[i] = v[i+1]; diff --git a/src/dsd_frame.c b/src/dsd_frame.c index 18f352a..5c876f0 100644 --- a/src/dsd_frame.c +++ b/src/dsd_frame.c @@ -91,7 +91,7 @@ processFrame (dsd_opts * opts, dsd_state * state) if ((state->synctype == 28) || (state->synctype == 29)) { //MBEout restored, is not handled internally by nxdn_frame.c - nxdn_frame (opts, state); + nxdn_frame (opts, state); return; } @@ -121,7 +121,7 @@ processFrame (dsd_opts * opts, dsd_state * state) if (state->dmr_mfid == 0x10) ; //sprintf (state->dmr_branding, "%s", "Motorola"); else if (state->dmr_mfid == 0x68) sprintf (state->dmr_branding, "%s", " Hytera"); else if (state->dmr_mfid == 0x58) sprintf (state->dmr_branding, "%s", " Tait"); - + //disabling these due to random data decodes setting an odd mfid, could be legit, but only for that one packet? //or, its just a decode error somewhere // else if (state->dmr_mfid == 0x20) sprintf (state->dmr_branding, "%s", "JVC Kenwood"); @@ -159,14 +159,14 @@ processFrame (dsd_opts * opts, dsd_state * state) sprintf (state->slot1light, " slot1 "); sprintf (state->slot2light, " slot2 "); //we can safely open MBE on any MS or mono handling - if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL)) openMbeOutFile (opts, state); - if (opts->p25_trunk == 0) dmrMSBootstrap (opts, state); + if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL)) openMbeOutFile (opts, state); + if (opts->p25_trunk == 0) dmrMSBootstrap (opts, state); } if (opts->dmr_mono == 1 && state->synctype == 32) { //we can safely open MBE on any MS or mono handling if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL)) openMbeOutFile (opts, state); - if (opts->p25_trunk == 0) dmrMSBootstrap (opts, state); + if (opts->p25_trunk == 0) dmrMSBootstrap (opts, state); } if (opts->dmr_stereo == 1) //opts->dmr_stereo == 1 { @@ -258,7 +258,7 @@ processFrame (dsd_opts * opts, dsd_state * state) //edacs else if ((state->synctype == 37) || (state->synctype == 38)) { - if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state); + if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state); edacs (opts, state); return; } @@ -270,7 +270,7 @@ processFrame (dsd_opts * opts, dsd_state * state) return; } //M17 - else if ((state->synctype == 16) || (state->synctype == 9) || (state->synctype == 17) || (state->synctype == 8) || + else if ((state->synctype == 16) || (state->synctype == 9) || (state->synctype == 17) || (state->synctype == 8) || (state->synctype == 76) || (state->synctype == 77) || (state->synctype == 86) || (state->synctype == 87) || (state->synctype == 99) || (state->synctype == 98) ) { @@ -282,7 +282,7 @@ processFrame (dsd_opts * opts, dsd_state * state) // processM17BRT(opts, state); //Not available yet else if (state->synctype == 86 || state->synctype == 87) processM17PKT(opts, state); - else + else processM17LSF(opts, state); return; } @@ -443,7 +443,7 @@ processFrame (dsd_opts * opts, dsd_state * state) } if (opts->mbe_out_dir[0] != 0) { - if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state); + if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state); if (opts->mbe_out_f == NULL) openMbeOutFile (opts, state); } mbe_initMbeParms (state->cur_mp, state->prev_mp, state->prev_mp_enhanced); diff --git a/src/dsd_frame_sync.c b/src/dsd_frame_sync.c index ecb4156..e6b7af4 100644 --- a/src/dsd_frame_sync.c +++ b/src/dsd_frame_sync.c @@ -32,11 +32,11 @@ printFrameSync (dsd_opts * opts, dsd_state * state, char *frametype, int offset, //oops, that made a nested if-if-if-if statement, //causing a memory leak - + // if (opts->verbose > 2) //fprintf (stderr,"o: %4i ", offset); // if (opts->verbose > 1) - //fprintf (stderr,"mod: %s ", modulation); + //fprintf (stderr,"mod: %s ", modulation); // if (opts->verbose > 2) //fprintf (stderr,"g: %f ", state->aout_gain); @@ -123,14 +123,14 @@ getFrameSync (dsd_opts * opts, dsd_state * state) { state->lcn_freq_roll++; //check roll again if greater than expected, then go back to zero - if (state->lcn_freq_roll >= state->lcn_freq_count) + if (state->lcn_freq_roll >= state->lcn_freq_count) { state->lcn_freq_roll = 0; //reset to zero - } + } } } //check that we have a non zero value first, then tune next frequency - if (state->trunk_lcn_freq[state->lcn_freq_roll] != 0) + if (state->trunk_lcn_freq[state->lcn_freq_roll] != 0) { //rigctl if (opts->use_rigctl == 1) @@ -145,8 +145,8 @@ getFrameSync (dsd_opts * opts, dsd_state * state) rtl_dev_tune (opts, state->trunk_lcn_freq[state->lcn_freq_roll]); #endif } - - fprintf (stderr, "Tuning to Frequency: %.06lf MHz\n", + + fprintf (stderr, "Tuning to Frequency: %.06lf MHz\n", (double)state->trunk_lcn_freq[state->lcn_freq_roll]/1000000); } @@ -206,7 +206,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state) // detect frame sync t = 0; - synctest10[10] = 0; + synctest10[10] = 0; synctest[24] = 0; synctest8[8] = 0; //M17, wasn't initialized or terminated (source of much pain and frustration in Cygwin) synctest12[12] = 0; @@ -358,20 +358,20 @@ getFrameSync (dsd_opts * opts, dsd_state * state) } } } - + state->dmr_payload_p++; // end digitize and dmr buffer testing - *synctest_p = dibit; + *synctest_p = dibit; if (t >= t_max) //works excelent now with short sync patterns, and no issues with large ones! { for (i = 0; i < t_max; i++) //24 { lbuf2[i] = lbuf[i]; } - qsort (lbuf2, t_max, sizeof (int), comp); + qsort (lbuf2, t_max, sizeof (int), comp); lmin = (lbuf2[1] + lbuf2[2] + lbuf2[3]) / 3; - lmax = (lbuf2[t_max - 3] + lbuf2[t_max - 2] + lbuf2[t_max - 1]) / 3; + lmax = (lbuf2[t_max - 3] + lbuf2[t_max - 2] + lbuf2[t_max - 1]) / 3; if (state->rf_mod == 1) { @@ -528,7 +528,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state) } //YSF sync strncpy(synctest20, (synctest_p - 19), 20); - if(opts->frame_ysf == 1) + if(opts->frame_ysf == 1) { if (strcmp(synctest20, FUSION_SYNC) == 0) { @@ -558,9 +558,9 @@ getFrameSync (dsd_opts * opts, dsd_state * state) //M17 Sync -- Just STR and LSF for now strncpy(synctest16, (synctest_p - 15), 16); strncpy(synctest8, (synctest_p - 7), 8); - if(opts->frame_m17 == 1) + if(opts->frame_m17 == 1) { - //preambles will skip dibits in an attempt to prime the + //preambles will skip dibits in an attempt to prime the //demodulator but not attempt any decoding if (strcmp(synctest8, M17_PRE) == 0) { @@ -690,7 +690,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state) } } } - //end M17 + //end M17 //P25 P2 sync S-ISCH VCH strncpy(synctest20, (synctest_p - 19), 20); @@ -917,7 +917,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state) printFrameSync (opts, state, "+DMR ", synctest_pos + 1, modulation); } state->lastsynctype = 10; - state->last_cc_sync_time = time(NULL); + state->last_cc_sync_time = time(NULL); return (10); } else @@ -933,7 +933,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state) state->firstframe = 1; } state->lastsynctype = 11; - state->last_cc_sync_time = time(NULL); + state->last_cc_sync_time = time(NULL); return (11); //11 } } @@ -1032,7 +1032,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state) state->firstframe = 1; } state->lastsynctype = 12; - state->last_cc_sync_time = time(NULL); + state->last_cc_sync_time = time(NULL); return (12); } @@ -1045,7 +1045,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state) printFrameSync (opts, state, "-DMR ", synctest_pos + 1, modulation); } state->lastsynctype = 13; - state->last_cc_sync_time = time(NULL); + state->last_cc_sync_time = time(NULL); return (13); } } @@ -1164,7 +1164,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state) state->max = ((state->max) + lmax) / 2; state->min = ((state->min) + lmin) / 2; printFrameSync (opts, state, "-EDACS", synctest_pos + 1, modulation); - state->lastsynctype = 38; + state->lastsynctype = 38; return (38); } else if ( strcmp (synctest48, INV_EDACS_SYNC) == 0) @@ -1175,7 +1175,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state) state->max = ((state->max) + lmax) / 2; state->min = ((state->min) + lmin) / 2; printFrameSync (opts, state, "+EDACS", synctest_pos + 1, modulation); - state->lastsynctype = 37; + state->lastsynctype = 37; return (37); } else if ((strcmp (synctest48, DOTTING_SEQUENCE_A) == 0) || (strcmp (synctest48, DOTTING_SEQUENCE_B) == 0)) @@ -1189,7 +1189,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state) } } - + else if (opts->frame_dstar == 1) { if (strcmp (synctest, DSTAR_SYNC) == 0) @@ -1261,14 +1261,14 @@ getFrameSync (dsd_opts * opts, dsd_state * state) || (strcmp (synctest10, "3131331111") == 0 ) || (strcmp (synctest10, "3331331111") == 0 ) || (strcmp (synctest10, "3131311131") == 0 ) //First few FSW on NXDN48 Type-C seems to hit this for some reason - + ) { state->offset = synctest_pos; state->max = ((state->max) + lmax) / 2; state->min = ((state->min) + lmin) / 2; - if (state->lastsynctype == 28) + if (state->lastsynctype == 28) { state->last_cc_sync_time = time(NULL); return (28); @@ -1276,21 +1276,21 @@ getFrameSync (dsd_opts * opts, dsd_state * state) state->lastsynctype = 28; } - else if ( - + else if ( + (strcmp (synctest10, "1313113313") == 0 ) || (strcmp (synctest10, "1113113313") == 0 ) || (strcmp (synctest10, "1313113333") == 0 ) || (strcmp (synctest10, "1113113333") == 0 ) || (strcmp (synctest10, "1313133313") == 0 ) - + ) { state->offset = synctest_pos; state->max = ((state->max) + lmax) / 2; state->min = ((state->min) + lmin) / 2; - if (state->lastsynctype == 29) + if (state->lastsynctype == 29) { state->last_cc_sync_time = time(NULL); return (29); @@ -1303,7 +1303,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state) #ifdef PVCONVENTIONAL if (opts->frame_provoice == 1) { - memset (synctest32, 0, sizeof(synctest32)); + memset (synctest32, 0, sizeof(synctest32)); strncpy (synctest32, (synctest_p - 31), 16); //short sync grab here on 32 char pvc_txs[9]; //string (symbol) value of TX Address char pvc_rxs[9]; //string (symbol) value of RX Address @@ -1418,18 +1418,18 @@ 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); return (-1); } - } + } } return (-1); - + } diff --git a/src/dsd_gps.c b/src/dsd_gps.c index bc832b1..8b28ca5 100644 --- a/src/dsd_gps.c +++ b/src/dsd_gps.c @@ -54,7 +54,7 @@ void lip_protocol_decoder (dsd_opts * opts, dsd_state * state, uint8_t * input) lat = 0x800001 - lat; sprintf (latstr, "%s", "S"); lat_sf = -1.0f; - } + } latitude = ((double)lat * lat_unit); if (lon_sign) @@ -62,13 +62,13 @@ void lip_protocol_decoder (dsd_opts * opts, dsd_state * state, uint8_t * input) lon = 0x1000001 - lon; sprintf (lonstr, "%s", "W"); lon_sf = -1.0f; - } + } longitude = ((double)lon * lon_unit); //6.3.63 Position Error //6.3.17 Horizontal velocity /* - Horizontal velocity shall be encoded for speeds 0 km/h to 28 km/h in 1 km/h steps and + Horizontal velocity shall be encoded for speeds 0 km/h to 28 km/h in 1 km/h steps and from 28 km/h onwards using equation: v = C × (1 + x)^(K-A) + B where: */ float v = 0.0f; @@ -94,7 +94,7 @@ void lip_protocol_decoder (dsd_opts * opts, dsd_state * state, uint8_t * input) fprintf (stderr, "Src(Hash); %03d; Lat: %.5lf%s%s Lon: %.5lf%s%s (%.5lf, %.5lf); Spd: %d km/h; Dir: %d%s",add_hash, latitude, deg_glyph, latstr, longitude, deg_glyph, lonstr, lat_sf * latitude, lon_sf * longitude, vt, dt, deg_glyph); //6.3.63 Position Error - uint16_t position_error = 2 * pow(10, pos_err); //2 * 10^pos_err + uint16_t position_error = 2 * pow(10, pos_err); //2 * 10^pos_err if (pos_err == 0x7 ) fprintf (stderr, "\n Position Error: Unknown or Invalid;"); else fprintf (stderr, "\n Position Error: Less than %dm;", position_error); @@ -157,7 +157,7 @@ void nmea_iec_61162_1 (dsd_opts * opts, dsd_state * state, uint8_t * input, uint { int slot = state->currentslot; - //NOTE: The Only difference between Short (type == 1) and Long Format (type == 2) + //NOTE: The Only difference between Short (type == 1) and Long Format (type == 2) //is the utc_ss3 on short vs utc_ss6 and inclusion of COG value on long //NOTE: MFID Specific Formats are not handled here, unknown, could be added if worked out @@ -339,7 +339,7 @@ void nmea_harris (dsd_opts * opts, dsd_state * state, uint8_t * input, uint32_t fprintf (stderr, "\n"); if (header == 0x2AA4) fprintf (stderr, " SRC: %08d;", src); - else + else fprintf (stderr, " VCH: %d - SRC: %08d;", slot, src); fprintf (stderr, " GPS: %f%s, %f%s;", latitude, deg_glyph, longitude, deg_glyph); @@ -412,7 +412,7 @@ void nmea_harris (dsd_opts * opts, dsd_state * state, uint8_t * input, uint32_t //not including the CRC obviously, unsure of their meaning, could relate //to other GPS functions like precision, etc, unknown. - //NOTE2: All these values are just best effort based on observation and + //NOTE2: All these values are just best effort based on observation and //making map points match using logic and distance over time for speed and course //without any documentation, any of these values may still be wrong @@ -427,7 +427,7 @@ void harris_gps(dsd_opts * opts, dsd_state * state, int slot, uint8_t * input) uint16_t lat_mmin = 0; uint16_t lon_mmin = 0; - //potentially in this PDU, but unverifiable without documentation or reasonable + //potentially in this PDU, but unverifiable without documentation or reasonable //mathematical proof vs map points and direction of travel / distance over time (assuming the radio is facing that direction) uint16_t rspeed = (uint16_t)ConvertBitIntoBytes(&input[136], 8); //MSB //136 rspeed = (rspeed << 8) + (uint16_t)ConvertBitIntoBytes(&input[128], 8); //LSB //128 @@ -463,7 +463,7 @@ void harris_gps(dsd_opts * opts, dsd_state * state, int slot, uint8_t * input) char deg_glyph[4]; sprintf (deg_glyph, "%s", "°"); - //This appears to be similar to the NMEA GPGGA format (DDmm.mm) but + //This appears to be similar to the NMEA GPGGA format (DDmm.mm) but //octets are ordered in least significant to most significant value lat_mmin = (uint16_t)ConvertBitIntoBytes(&input[40], 16); //? bits required, but grabbing two octets lat_min = (uint8_t)ConvertBitIntoBytes(&input[58], 6); //6 bits required to get 60 @@ -472,7 +472,7 @@ void harris_gps(dsd_opts * opts, dsd_state * state, int slot, uint8_t * input) lon_mmin = (uint16_t)ConvertBitIntoBytes(&input[72], 16); //? bits required, but grabbing two octets lon_min = (uint8_t)ConvertBitIntoBytes(&input[90], 6); //6 bits required to get 60 - lon_deg = (uint8_t)ConvertBitIntoBytes(&input[96], 8); //8 bits required to get 180 + lon_deg = (uint8_t)ConvertBitIntoBytes(&input[96], 8); //8 bits required to get 180 lon_sign = input[88]; //88, unsure of a correct location, but on the sample with 0 minutes, this lonely bit was flagged on int src = 0; @@ -486,7 +486,7 @@ void harris_gps(dsd_opts * opts, dsd_state * state, int slot, uint8_t * input) if (lat_sign) lat_dec *= -1.0f; - if (lon_sign) + if (lon_sign) lon_dec *= -1.0f; //line break @@ -568,10 +568,10 @@ void dmr_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[]) char deg_glyph[4]; sprintf (deg_glyph, "%s", "°"); - uint32_t lon_sign = lc_bits[23]; - uint32_t lon = (uint32_t)ConvertBitIntoBytes(&lc_bits[24], 24); - uint32_t lat_sign = lc_bits[48]; - uint32_t lat = (uint32_t)ConvertBitIntoBytes(&lc_bits[49], 23); + uint32_t lon_sign = lc_bits[23]; + uint32_t lon = (uint32_t)ConvertBitIntoBytes(&lc_bits[24], 24); + uint32_t lat_sign = lc_bits[48]; + uint32_t lat = (uint32_t)ConvertBitIntoBytes(&lc_bits[49], 23); double lon_sf = 1.0f; //float value we can multiple longitude with double lat_sf = 1.0f; //float value we can multiple latitude with @@ -586,8 +586,8 @@ void dmr_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[]) //run calculations and print //7.2.16 and 7.2.17 (two's compliment) - double latitude = 0; - double longitude = 0; + double latitude = 0; + double longitude = 0; if (pf) fprintf (stderr, " Protected"); else @@ -597,7 +597,7 @@ void dmr_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[]) lat = 0x800001 - lat; sprintf (latstr, "%s", "S"); lat_sf = -1.0f; - } + } latitude = ((double)lat * lat_unit); if (lon_sign) @@ -605,7 +605,7 @@ void dmr_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[]) lon = 0x1000001 - lon; sprintf (lonstr, "%s", "W"); lon_sf = -1.0f; - } + } longitude = ((double)lon * lon_unit); //sanity check @@ -614,7 +614,7 @@ void dmr_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[]) fprintf (stderr, " Lat: %.5lf%s%s Lon: %.5lf%s%s (%.5lf, %.5lf)", latitude, deg_glyph, latstr, longitude, deg_glyph, lonstr, lat_sf * latitude, lon_sf * longitude); //7.2.15 Position Error - uint16_t position_error = 2 * pow(10, pos_err); //2 * 10^pos_err + uint16_t position_error = 2 * pow(10, pos_err); //2 * 10^pos_err if (pos_err == 0x7 ) fprintf (stderr, "\n Position Error: Unknown or Invalid"); else fprintf (stderr, "\n Position Error: Less than %dm", position_error); @@ -656,7 +656,7 @@ void dmr_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[]) fprintf (stderr, "%s", KNRM); } -//This Function needs testing, is tested working for NW and NE lat and +//This Function needs testing, is tested working for NW and NE lat and //long coordinates, but not for SE and SW coordinates void apx_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[]) { @@ -672,11 +672,11 @@ void apx_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[]) char deg_glyph[4]; sprintf (deg_glyph, "%s", "°"); - uint32_t lon_sign = lc_bits[48]; - uint32_t lon = (uint32_t)ConvertBitIntoBytes(&lc_bits[49], 23); + uint32_t lon_sign = lc_bits[48]; + uint32_t lon = (uint32_t)ConvertBitIntoBytes(&lc_bits[49], 23); uint32_t lat_sign = lc_bits[24]; - uint32_t lat = (uint32_t)ConvertBitIntoBytes(&lc_bits[25], 23); - + uint32_t lat = (uint32_t)ConvertBitIntoBytes(&lc_bits[25], 23); + double lat_unit = 90.0f / 0x7FFFFF; double lon_unit = 180.0f / 0x7FFFFF; @@ -687,8 +687,8 @@ void apx_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[]) sprintf (lonstr, "%s", "E"); sprintf (valid, "%s", "Current Fix"); - double latitude = 0; - double longitude = 0; + double latitude = 0; + double longitude = 0; if (pf) fprintf (stderr, " Protected"); else @@ -700,7 +700,7 @@ void apx_embedded_gps (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[]) latitude -= 90.0f; sprintf (latstr, "%s", "S"); } - + longitude = ((double)lon * lon_unit); if (lon_sign) { @@ -780,7 +780,7 @@ void decode_cellocator(dsd_opts * opts, dsd_state * state, uint8_t * input, int UNUSED(input); UNUSED(len); - //UTF8 Text: MCGP (0x4D434750) followed by data values + //UTF8 Text: MCGP (0x4D434750) followed by data values //(0417D1050000F45FD1DD00010000000097BDD56C81000009AAAABF12864C) utf8_to_text(state, 0, 4, input); diff --git a/src/dsd_import.c b/src/dsd_import.c index 907ae43..47a619f 100644 --- a/src/dsd_import.c +++ b/src/dsd_import.c @@ -5,8 +5,8 @@ int csvGroupImport(dsd_opts * opts, dsd_state * state) { - char filename[1024] = "filename.csv"; - sprintf (filename, "%s", opts->group_in_file); + char filename[1024] = "filename.csv"; + sprintf (filename, "%s", opts->group_in_file); //filename[1023] = '\0'; //necessary? char buffer[BSIZE]; FILE * fp; @@ -27,7 +27,7 @@ int csvGroupImport(dsd_opts * opts, dsd_state * state) continue; //don't want labels char * field = strtok(buffer, ","); //seperate by comma while (field) { - + if (field_count == 0) { //group_number = atol(field); @@ -44,23 +44,23 @@ int csvGroupImport(dsd_opts * opts, dsd_state * state) strcpy(state->group_array[i].groupName, field); fprintf (stderr, "%s ", state->group_array[i].groupName); } - + field = strtok(NULL, ","); field_count++; } fprintf (stderr, "\n"); i++; - state->group_tally++; + state->group_tally++; } fclose(fp); return 0; } //LCN import for EDACS, migrated to channel map (channel map does both) -int csvLCNImport(dsd_opts * opts, dsd_state * state) +int csvLCNImport(dsd_opts * opts, dsd_state * state) { - char filename[1024] = "filename.csv"; - sprintf (filename, "%s", opts->lcn_in_file); + char filename[1024] = "filename.csv"; + sprintf (filename, "%s", opts->lcn_in_file); //filename[1023] = '\0'; //necessary? char buffer[BSIZE]; FILE * fp; @@ -86,12 +86,12 @@ int csvLCNImport(dsd_opts * opts, dsd_state * state) fprintf (stderr, "LCN [%d] [%ld]", field_count+1, state->trunk_lcn_freq[field_count]); fprintf (stderr, "\n"); - + field = strtok(NULL, ","); field_count++; } fprintf (stderr, "LCN Count %d\n", state->lcn_freq_count); - + } fclose(fp); return 0; @@ -99,7 +99,7 @@ int csvLCNImport(dsd_opts * opts, dsd_state * state) int csvChanImport(dsd_opts * opts, dsd_state * state) //channel map import { - char filename[1024] = "filename.csv"; + char filename[1024] = "filename.csv"; sprintf (filename, "%s", opts->chan_in_file); char buffer[BSIZE]; @@ -135,13 +135,13 @@ int csvChanImport(dsd_opts * opts, dsd_state * state) //channel map import sscanf (field, "%ld", &state->trunk_lcn_freq[state->lcn_freq_count]); state->lcn_freq_count++; //keep tally of number of Frequencies imported } - + field = strtok(NULL, ","); field_count++; } fprintf (stderr, "Channel [%05ld] [%09ld]", chan_number, state->trunk_chan_map[chan_number]); fprintf (stderr, "\n"); - + } fclose(fp); return 0; @@ -150,7 +150,7 @@ int csvChanImport(dsd_opts * opts, dsd_state * state) //channel map import //Decimal Variant of Key Import int csvKeyImportDec(dsd_opts * opts, dsd_state * state) //multi-key support { - char filename[1024] = "filename.csv"; + char filename[1024] = "filename.csv"; sprintf (filename, "%s", opts->key_in_file); char buffer[BSIZE]; @@ -162,7 +162,7 @@ int csvKeyImportDec(dsd_opts * opts, dsd_state * state) //multi-key support } int row_count = 0; int field_count = 0; - + unsigned long long int keynumber = 0; unsigned long long int keyvalue = 0; @@ -186,13 +186,13 @@ int csvKeyImportDec(dsd_opts * opts, dsd_state * state) //multi-key support keynumber = keynumber & 0xFFFFFF; //truncate to 24-bits (max allowed) for (int i = 0; i < 24; i++) { - hash_bits[i] = ((keynumber << i) & 0x800000) >> 23; //load into array for CRC16 + hash_bits[i] = ((keynumber << i) & 0x800000) >> 23; //load into array for CRC16 } hash = ComputeCrcCCITT16d (hash_bits, 24); keynumber = hash & 0xFFFF; //make sure its no larger than 16-bits fprintf (stderr, "Hashed "); } - + } if (field_count == 1) @@ -200,14 +200,14 @@ int csvKeyImportDec(dsd_opts * opts, dsd_state * state) //multi-key support sscanf (field, "%lld", &keyvalue); state->rkey_array[keynumber] = keyvalue & 0xFFFFFFFFFF; //doesn't exceed 40-bit value } - + field = strtok(NULL, ","); field_count++; } fprintf (stderr, "Key [%03lld] [%05lld]", keynumber, state->rkey_array[keynumber]); fprintf (stderr, "\n"); hash = 0; - + } fclose(fp); return 0; @@ -246,7 +246,7 @@ int csvKeyImportHex(dsd_opts * opts, dsd_state * state) //key import for hex key { sscanf (field, "%llX", &state->rkey_array[keynumber]); } - + //this could also theoretically nuke other keys that are at the same offset if (field_count == 2) { @@ -262,18 +262,18 @@ int csvKeyImportHex(dsd_opts * opts, dsd_state * state) //key import for hex key { sscanf (field, "%llX", &state->rkey_array[keynumber+0x301]); } - + field = strtok(NULL, ","); field_count++; } fprintf (stderr, "Key [%04llX] [%016llX]", keynumber, state->rkey_array[keynumber]); - + //if longer key is loaded (or clash with the 0x101, 0x201, 0x301 offset, then print the full key listing) if ( (state->rkey_array[keynumber+0x101] != 0) || (state->rkey_array[keynumber+0x201] != 0) || (state->rkey_array[keynumber+0x301] != 0) ) fprintf (stderr, " [%016llX] [%016llX] [%016llX]", state->rkey_array[keynumber+0x101], state->rkey_array[keynumber+0x201], state->rkey_array[keynumber+0x301]); fprintf (stderr, "\n"); - + } fclose(fp); return 0; diff --git a/src/dsd_ks.c b/src/dsd_ks.c index 33a75f8..bfa6bb4 100644 --- a/src/dsd_ks.c +++ b/src/dsd_ks.c @@ -2,6 +2,6 @@ * dsd_ks.c * Placeholder File 6 -- This file is for temporary code storage * - * - * + * + * *-----------------------------------------------------------------------------*/ \ No newline at end of file diff --git a/src/dsd_main.c b/src/dsd_main.c index 81d0cab..9b961ab 100644 --- a/src/dsd_main.c +++ b/src/dsd_main.c @@ -141,7 +141,7 @@ noCarrier (dsd_opts * opts, dsd_state * state) state->lcn_freq_roll = 0; //reset to zero } //check that we have a non zero value first, then tune next frequency - if (state->trunk_lcn_freq[state->lcn_freq_roll] != 0) + if (state->trunk_lcn_freq[state->lcn_freq_roll] != 0) { //rigctl if (opts->use_rigctl == 1) @@ -163,10 +163,10 @@ noCarrier (dsd_opts * opts, dsd_state * state) } //end experimental conventional frequency scanner mode - //tune back to last known CC when using trunking after x second hangtime - if (opts->p25_trunk == 1 && opts->p25_is_tuned == 1 && ( (time(NULL) - state->last_cc_sync_time) > opts->trunk_hangtime) ) + //tune back to last known CC when using trunking after x second hangtime + if (opts->p25_trunk == 1 && opts->p25_is_tuned == 1 && ( (time(NULL) - state->last_cc_sync_time) > opts->trunk_hangtime) ) { - if (state->p25_cc_freq != 0) + if (state->p25_cc_freq != 0) { //cap+ rest channel - redundant? @@ -176,11 +176,11 @@ noCarrier (dsd_opts * opts, dsd_state * state) { state->p25_cc_freq = state->trunk_chan_map[state->dmr_rest_channel]; } - } + } if (opts->use_rigctl == 1) //rigctl tuning { - if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); + if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); SetFreq(opts->rigctl_sockfd, state->p25_cc_freq); state->dmr_rest_channel = -1; //maybe? } @@ -193,7 +193,7 @@ noCarrier (dsd_opts * opts, dsd_state * state) #endif } - opts->p25_is_tuned = 0; + opts->p25_is_tuned = 0; state->edacs_tuned_lcn = -1; //only for EDACS/PV @@ -240,7 +240,7 @@ noCarrier (dsd_opts * opts, dsd_state * state) memset (state->dmr_payload_buf, 0, sizeof (int) * 200); memset (state->dmr_stereo_payload, 1, sizeof(int) * 144); //dmr buffer end - + //close MBE out files if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state); if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state); @@ -250,7 +250,7 @@ noCarrier (dsd_opts * opts, dsd_state * state) state->carrier = 0; state->max = 15000; state->min = -15000; - state->center = 0; + state->center = 0; state->err_str[0] = 0; state->err_strR[0] = 0; sprintf (state->fsubtype, " "); @@ -290,12 +290,12 @@ noCarrier (dsd_opts * opts, dsd_state * state) //dmr mfid branding and site parms sprintf(state->dmr_branding_sub, "%s", ""); sprintf(state->dmr_branding, "%s", ""); - sprintf (state->dmr_site_parms, "%s", ""); + sprintf (state->dmr_site_parms, "%s", ""); } //zero out after x second hangtime when trunking to prevent premature zeroing on these variables //mainly bugfix for ncurses and per call wavs (edacs) and also signal fade, etc - if (opts->p25_trunk == 1 && opts->p25_is_tuned == 1 && time(NULL) - state->last_cc_sync_time > opts->trunk_hangtime) + if (opts->p25_trunk == 1 && opts->p25_is_tuned == 1 && time(NULL) - state->last_cc_sync_time > opts->trunk_hangtime) { state->lasttg = 0; state->lastsrc = 0; @@ -303,7 +303,7 @@ noCarrier (dsd_opts * opts, dsd_state * state) state->lastsrcR = 0; } - + state->lastp25type = 0; state->repeat = 0; state->nac = 0; @@ -340,8 +340,8 @@ noCarrier (dsd_opts * opts, dsd_state * state) state->HYTR = 0; state->DMRvcL = 0; state->DMRvcR = 0; - state->dropL = 256; - state->dropR = 256; + state->dropL = 256; + state->dropR = 256; state->payload_miN = 0; state->p25vc = 0; @@ -415,7 +415,7 @@ noCarrier (dsd_opts * opts, dsd_state * state) state->nxdn_ran = 0; state->nxdn_sf = 0; memset (state->nxdn_sacch_frame_segcrc, 1, sizeof(state->nxdn_sacch_frame_segcrc)); //init on 1, bad CRC all - state->nxdn_sacch_non_superframe = TRUE; + state->nxdn_sacch_non_superframe = TRUE; memset (state->nxdn_sacch_frame_segment, 1, sizeof(state->nxdn_sacch_frame_segment)); state->nxdn_alias_block_number = 0; memset (state->nxdn_alias_block_segment, 0, sizeof(state->nxdn_alias_block_segment)); @@ -442,7 +442,7 @@ noCarrier (dsd_opts * opts, dsd_state * state) //forcing key application will re-enable this at the time of voice tx state->nxdn_cipher_type = 0; - //dmr overaching manufacturer in use for a particular system or radio + //dmr overaching manufacturer in use for a particular system or radio // state->dmr_mfid = -1; //dmr slco stuff @@ -454,7 +454,7 @@ noCarrier (dsd_opts * opts, dsd_state * state) memset (state->data_header_valid, 0, sizeof(state->data_header_valid)); //initialize cap+ bits and block num storage - memset (state->cap_plus_csbk_bits, 0, sizeof(state->cap_plus_csbk_bits)); + memset (state->cap_plus_csbk_bits, 0, sizeof(state->cap_plus_csbk_bits)); memset (state->cap_plus_block_num, 0, sizeof(state->cap_plus_block_num)); //init confirmed data individual block crc as invalid @@ -487,10 +487,10 @@ noCarrier (dsd_opts * opts, dsd_state * state) state->dmr_rest_channel = -1; state->p25_vc_freq[0] = 0; state->p25_vc_freq[1] = 0; - state->dmr_mfid = -1; + state->dmr_mfid = -1; sprintf(state->dmr_branding_sub, "%s", ""); sprintf(state->dmr_branding, "%s", ""); - sprintf (state->dmr_site_parms, "%s", ""); + sprintf (state->dmr_site_parms, "%s", ""); opts->p25_is_tuned = 0; memset(state->active_channel, 0, sizeof(state->active_channel)); } @@ -711,7 +711,7 @@ initOpts (dsd_opts * opts) opts->inverted_dpmr = 0; opts->dmr_mono = 0; opts->dmr_stereo = 1; - opts->aggressive_framesync = 1; + opts->aggressive_framesync = 1; //this may not matter so much, since its already checked later on //but better safe than sorry I guess @@ -719,7 +719,7 @@ initOpts (dsd_opts * opts) opts->audio_in_type = 9; //only assign when configured opts->audio_out_type = 9; //only assign when configured #else - opts->audio_in_type = 0; + opts->audio_in_type = 0; opts->audio_out_type = 0; #endif @@ -765,7 +765,7 @@ initOpts (dsd_opts * opts) opts->scanner_mode = 0; //0 disabled, 1 is enabled - //reverse mute + //reverse mute opts->reverse_mute = 0; //setmod bandwidth @@ -1040,7 +1040,7 @@ initState (dsd_state * state) state->HYTR = 0; state->DMRvcL = 0; state->DMRvcR = 0; - state->dropL = 256; + state->dropL = 256; state->dropR = 256; //ks array storage and counters @@ -1166,7 +1166,7 @@ initState (dsd_state * state) state->last_t3_tune_time = time(NULL); state->is_con_plus = 0; - //dmr trunking/ncurses stuff + //dmr trunking/ncurses stuff state->dmr_rest_channel = -1; //init on -1 state->dmr_mfid = -1; // state->dmr_cc_lpcn = 0; @@ -1177,7 +1177,7 @@ initState (dsd_state * state) state->nxdn_ran = 0; state->nxdn_sf = 0; memset (state->nxdn_sacch_frame_segcrc, 1, sizeof(state->nxdn_sacch_frame_segcrc)); //init on 1, bad CRC all - state->nxdn_sacch_non_superframe = TRUE; + state->nxdn_sacch_non_superframe = TRUE; memset (state->nxdn_sacch_frame_segment, 1, sizeof(state->nxdn_sacch_frame_segment)); state->nxdn_alias_block_number = 0; memset (state->nxdn_alias_block_segment, 0, sizeof(state->nxdn_alias_block_segment)); @@ -1195,7 +1195,7 @@ initState (dsd_state * state) //multi-key array memset (state->rkey_array, 0, sizeof(state->rkey_array)); - state->keyloader = 0; //keyloader off + state->keyloader = 0; //keyloader off //Remus DMR End Call Alert Beep state->dmr_end_alert[0] = 0; @@ -1208,9 +1208,9 @@ initState (dsd_state * state) //initialize unified dmr pdu 'superframe' memset (state->dmr_pdu_sf, 0, sizeof (state->dmr_pdu_sf)); memset (state->data_header_valid, 0, sizeof(state->data_header_valid)); - + //initialize cap+ bits and block num storage - memset (state->cap_plus_csbk_bits, 0, sizeof(state->cap_plus_csbk_bits)); + memset (state->cap_plus_csbk_bits, 0, sizeof(state->cap_plus_csbk_bits)); memset (state->cap_plus_block_num, 0, sizeof(state->cap_plus_block_num)); //init confirmed data individual block crc as invalid @@ -1240,7 +1240,7 @@ initState (dsd_state * state) //late entry mi fragments memset (state->late_entry_mi_fragment, 0, sizeof (state->late_entry_mi_fragment)); - + initialize_p25_heuristics(&state->p25_heuristics); initialize_p25_heuristics(&state->inv_p25_heuristics); @@ -1305,7 +1305,7 @@ initState (dsd_state * state) state->m17encoder_eot = 0; memset(state->m17_meta, 0, sizeof(state->m17_meta)); - + #ifdef USE_CODEC2 state->codec2_3200 = codec2_create(CODEC2_MODE_3200); state->codec2_1600 = codec2_create(CODEC2_MODE_1600); @@ -1567,7 +1567,7 @@ liveScanner (dsd_opts * opts, dsd_state * state) if (opts->floating_point == 1) { - + if (opts->audio_gain > 50.0f) opts->audio_gain = 50.0f; if (opts->audio_gain < 0.0f) opts->audio_gain = 0.0f; } @@ -1659,7 +1659,7 @@ cleanupAndExit (dsd_opts * opts, dsd_state * state) { // Signal that everything should shutdown. exitflag = 1; - + #ifdef USE_CODEC2 codec2_destroy(state->codec2_1600); codec2_destroy(state->codec2_3200); @@ -1781,14 +1781,14 @@ main (int argc, char **argv) while ((c = getopt (argc, argv, "yhaepPqs:t:v:z:i:o:d:c:g:n:w:B:C:R:f:m:u:x:A:S:M:G:D:L:V:U:YK:b:H:X:NQ:WrlZTF01:2:345:6:7:89Ek:I:JO")) != -1) { - + switch (c) { case 'h': usage (); exit (0); break; //probably isn't required, but just making sure it doesn't do anything bizarre - + case 'a': opts.call_alert = 1; break; @@ -1827,14 +1827,14 @@ main (int argc, char **argv) state.m17sms[772] = '\0'; state.m17_str_dt = 3; //flip this so that STR encoder knows to use 1600 voice + data break; - + //specify TG Hold value case 'I': sscanf (optarg, "%d", &state.tg_hold); fprintf (stderr, "TG Hold set to %d \n", state.tg_hold); break; - case '9': //Leaving Enabled to maintain backwards compatability + case '9': //Leaving Enabled to maintain backwards compatability state.ea_mode = 0; state.esk_mask = 0; fprintf (stderr,"Force Enabling EDACS Standard/Networked Mode Mode without ESK.\n"); @@ -1857,7 +1857,7 @@ main (int argc, char **argv) sscanf (optarg, "%llX", &state.R); state.RR = state.R; //put key on both sides fprintf (stderr, "RC4/DES Encryption Key Value set to 0x%llX \n", state.R); - opts.unmute_encrypted_p25 = 0; + opts.unmute_encrypted_p25 = 0; state.keyloader = 0; //turn off keyloader break; @@ -1907,7 +1907,7 @@ main (int argc, char **argv) break; case 'Q': //'DSP' Structured Output file for OKDMRlib - sprintf (wav_file_directory, "./DSP"); + sprintf (wav_file_directory, "./DSP"); wav_file_directory[1023] = '\0'; if (stat(wav_file_directory, &st) == -1) { @@ -1929,8 +1929,8 @@ main (int argc, char **argv) if (opts.slot_preference > 1) opts.slot_preference = 1; fprintf (stderr, "TDMA (DMR and P2) Slot Voice Preference is Slot %d. \n", opts.slot_preference+1); break; - - case 'n': //manually set analog audio output gain + + case 'n': //manually set analog audio output gain sscanf (optarg, "%f", &opts.audio_gainA); if (opts.audio_gainA > 100.0f) opts.audio_gainA = 100.0f; else if (opts.audio_gainA < 0.0f) opts.audio_gainA = 0.0f; @@ -2004,7 +2004,7 @@ main (int argc, char **argv) case 'U': //New letter assignment for RIGCTL TCP port, flow down to allow temp numbers sscanf (optarg, "%d", &opts.rigctlportno); - if (opts.rigctlportno != 0) opts.use_rigctl = 1; + if (opts.rigctlportno != 0) opts.use_rigctl = 1; break; //NOTE: I changed trunk_hangtime to a float, BUT! time(NULL) returns in second whole numbers @@ -2015,12 +2015,12 @@ main (int argc, char **argv) sscanf (optarg, "%f", &opts.trunk_hangtime); //updated for float/decimal values fprintf (stderr, "Trunking or Scanner Speed/Hang Time set to: %.02f sec\n", opts.trunk_hangtime); break; - + case 'q': //New letter assignment for Reverse Mute, flow down to allow temp numbers opts.reverse_mute = 1; fprintf (stderr, "Reverse Mute\n"); break; - + case 'B': //New letter assignment for RIGCTL SetMod BW, flow down to allow temp numbers sscanf (optarg, "%d", &opts.setmod_bw); if (opts.setmod_bw > 25000) opts.setmod_bw = 25000; //not too high @@ -2078,13 +2078,13 @@ main (int argc, char **argv) case 'H': //new handling for 10/32/64 Char Key - + strncpy(opts.szNumbers, optarg, 1023); opts.szNumbers[1023] = '\0'; state.K1 = strtoull (opts.szNumbers, &pEnd, 16); state.K2 = strtoull (pEnd, &pEnd, 16); state.K3 = strtoull (pEnd, &pEnd, 16); - state.K4 = strtoull (pEnd, &pEnd, 16); + state.K4 = strtoull (pEnd, &pEnd, 16); fprintf (stderr, "Hytera40/128/256 BP or AES128/256 Key = %016llX %016llX %016llX %016llX\n", state.K1, state.K2, state.K3, state.K4); opts.dmr_mute_encL = 0; opts.dmr_mute_encR = 0; @@ -2155,7 +2155,7 @@ main (int argc, char **argv) break; case 'P': //TDMA/NXDN Per Call - was T, now is P - sprintf (wav_file_directory, "%s", opts.wav_out_dir); + sprintf (wav_file_directory, "%s", opts.wav_out_dir); wav_file_directory[1023] = '\0'; if (stat(wav_file_directory, &st) == -1) { @@ -2164,11 +2164,11 @@ main (int argc, char **argv) mkdir(wav_file_directory, 0700); //user read write execute, needs execute for some reason or segfault } fprintf (stderr,"AUTO and NXDN Per Call Wav File Saving Enabled. (NCurses Terminal Only)\n"); - sprintf (opts.wav_out_file, "%s/DSD-FME-X1.wav", opts.wav_out_dir); + sprintf (opts.wav_out_file, "%s/DSD-FME-X1.wav", opts.wav_out_dir); sprintf (opts.wav_out_fileR, "%s/DSD-FME-X2.wav", opts.wav_out_dir); opts.dmr_stereo_wav = 1; - openWavOutFileL (&opts, &state); - openWavOutFileR (&opts, &state); + openWavOutFileL (&opts, &state); + openWavOutFileR (&opts, &state); break; case 'F': @@ -2204,7 +2204,7 @@ main (int argc, char **argv) else fprintf (stderr,"Writing mbe data files to directory %s\n", opts.mbe_out_dir); break; - case 'c': + case 'c': strncpy(opts.symbol_out_file, optarg, 1023); opts.symbol_out_file[1023] = '\0'; fprintf (stderr,"Writing symbol capture to file %s\n", opts.symbol_out_file); @@ -2213,7 +2213,7 @@ main (int argc, char **argv) case 'g': sscanf (optarg, "%f", &opts.audio_gain); - + if (opts.audio_gain < (float) 0 ) { fprintf (stderr,"Disabling audio out gain setting\n"); @@ -2656,7 +2656,7 @@ main (int argc, char **argv) opts.frame_provoice = 0; opts.frame_ysf = 0; opts.frame_m17 = 0; - state.samplesPerSymbol = 8; + state.samplesPerSymbol = 8; state.symbolCenter = 3; opts.mod_c4fm = 1; opts.mod_qpsk = 0; @@ -2675,7 +2675,7 @@ main (int argc, char **argv) opts.frame_x2tdma = 0; opts.frame_p25p1 = 0; opts.frame_p25p2 = 0; - opts.inverted_p2 = 0; + opts.inverted_p2 = 0; opts.frame_nxdn48 = 0; opts.frame_nxdn96 = 0; opts.frame_dmr = 1; @@ -2693,7 +2693,7 @@ main (int argc, char **argv) opts.pulse_digi_rate_out = 8000; opts.pulse_digi_out_channels = 2; sprintf (opts.output_name, "DMR"); - + fprintf (stderr,"Decoding DMR BS/MS Simplex\n"); } //change ft to only do P25 and DMR (TDMA trunking modes) @@ -2722,7 +2722,7 @@ main (int argc, char **argv) // opts.setmod_bw = 12000; //safe default on both DMR and P25 opts.pulse_digi_rate_out = 8000; opts.pulse_digi_out_channels = 2; - // opts.use_heuristics = 1; //Causes issues with Voice Wide + // opts.use_heuristics = 1; //Causes issues with Voice Wide sprintf (opts.output_name, "TDMA"); fprintf (stderr,"Decoding P25 and DMR\n"); } @@ -2913,8 +2913,8 @@ main (int argc, char **argv) opts.mod_qpsk = 1; opts.mod_gfsk = 0; state.rf_mod = 1; - state.samplesPerSymbol = 8; - state.symbolCenter = 3; + state.samplesPerSymbol = 8; + state.symbolCenter = 3; // opts.setmod_bw = 12000; fprintf (stderr,"Enabling 6000 sps P25p2 QPSK.\n"); } @@ -2925,8 +2925,8 @@ main (int argc, char **argv) opts.mod_qpsk = 0; opts.mod_gfsk = 0; state.rf_mod = 0; - state.samplesPerSymbol = 10; - state.symbolCenter = 4; + state.samplesPerSymbol = 10; + state.symbolCenter = 4; // opts.setmod_bw = 12000; fprintf (stderr,"Enabling 6000 sps P25p2 C4FM.\n"); } @@ -2936,8 +2936,8 @@ main (int argc, char **argv) opts.mod_qpsk = 1; opts.mod_gfsk = 1; state.rf_mod = 0; - state.samplesPerSymbol = 8; - state.symbolCenter = 3; + state.samplesPerSymbol = 8; + state.symbolCenter = 3; // opts.setmod_bw = 12000; fprintf (stderr,"Enabling 6000 sps P25p2 all optimizations.\n"); } @@ -2980,7 +2980,7 @@ main (int argc, char **argv) sscanf (optarg, "%i", &opts.mod_threshold); fprintf (stderr,"Setting C4FM/QPSK auto detection threshold to %i\n", opts.mod_threshold); break; //this was missing a break - + //Disabled and switches reassigned to M17 User Data Argumeents // case 'S': //disabled, using for M17 encoder user SMS message // sscanf (optarg, "%i", &opts.ssize); @@ -3035,7 +3035,7 @@ main (int argc, char **argv) if((strncmp(opts.audio_in_dev, "m17udp", 6) == 0)) //M17 UDP Socket Input { fprintf (stderr, "M17 UDP IP Frame Input: "); - char * curr; + char * curr; curr = strtok(opts.audio_in_dev, ":"); //should be 'm17' if (curr != NULL) ; //continue @@ -3055,7 +3055,7 @@ main (int argc, char **argv) if((strncmp(opts.audio_out_dev, "m17udp", 6) == 0)) //M17 UDP Socket Output { fprintf (stderr, "M17 UDP IP Frame Output: "); - char * curr; + char * curr; curr = strtok(opts.audio_out_dev, ":"); //should be 'm17' if (curr != NULL) ; //continue @@ -3077,7 +3077,7 @@ main (int argc, char **argv) if((strncmp(opts.audio_in_dev, "tcp", 3) == 0)) //tcp socket input from SDR++ and others { fprintf (stderr, "TCP Direct Link: "); - char * curr; + char * curr; curr = strtok(opts.audio_in_dev, ":"); //should be 'tcp' if (curr != NULL) ; //continue @@ -3090,7 +3090,7 @@ main (int argc, char **argv) //shim to tie the hostname of the tcp input to the rigctl hostname (probably covers a vast majority of use cases) //in the future, I will rework part of this so that users can enter a hostname and port similar to how tcp and rtl strings work memcpy (opts.rigctlhostname, opts.tcp_hostname, sizeof (opts.rigctlhostname) ); - } + } curr = strtok(NULL, ":"); //host port if (curr != NULL) opts.tcp_portno = atoi (curr); @@ -3103,11 +3103,11 @@ main (int argc, char **argv) if (opts.tcp_sockfd != 0) { opts.audio_in_type = 8; - + fprintf (stderr, "TCP Connection Success!\n"); // openAudioInDevice(&opts); //do this to see if it makes it work correctly } - else + else { #ifdef __CYGWIN__ sprintf (opts.audio_in_dev, "%s", "/dev/dsp"); @@ -3123,7 +3123,7 @@ main (int argc, char **argv) opts.audio_in_type = 0; #endif } - + } if (opts.use_rigctl == 1) @@ -3134,7 +3134,7 @@ main (int argc, char **argv) { fprintf (stderr, "RIGCTL Connection Failure - RIGCTL Features Disabled\n"); opts.use_rigctl = 0; - } + } } if((strncmp(opts.audio_in_dev, "rtl", 3) == 0)) //rtl dongle input @@ -3143,10 +3143,10 @@ main (int argc, char **argv) //use to list out all detected RTL dongles char vendor[256], product[256], serial[256], userdev[256]; int device_count = 0; - + #ifdef USE_RTLSDR fprintf (stderr, "RTL Input: "); - char * curr; + char * curr; curr = strtok(opts.audio_in_dev, ":"); //should be 'rtl' if (curr != NULL) ; //continue @@ -3178,10 +3178,10 @@ main (int argc, char **argv) { opts.rtl_bandwidth = bw; } - else + else opts.rtl_bandwidth = 12; //safe default -- provides best performance on most systems } - else goto RTLEND; + else goto RTLEND; curr = strtok(NULL, ":"); //rtl squelch level "-L" if (curr != NULL) opts.rtl_squelch_level = atoi (curr); @@ -3221,7 +3221,7 @@ main (int argc, char **argv) fprintf (stderr, "Selected Device #%d with Serial Number: %s \n", i, serial); opts.rtl_dev_index = i; } - + } if (opts.rtl_volume_multiplier > 3 || opts.rtl_volume_multiplier < 0) @@ -3236,7 +3236,7 @@ main (int argc, char **argv) // fprintf (stderr, "UDP %d \n", opts.rtl_udp_port); fprintf (stderr, "VOL %d \n", opts.rtl_volume_multiplier); opts.audio_in_type = 3; - + rtl_ok = 1; #endif @@ -3270,7 +3270,7 @@ main (int argc, char **argv) //UDP Socket Blaster Audio Output Setup if((strncmp(opts.audio_out_dev, "udp", 3) == 0)) { - + //read in values fprintf (stderr, "UDP Blaster Output: "); char * curr; @@ -3282,7 +3282,7 @@ main (int argc, char **argv) curr = strtok(NULL, ":"); //udp blaster hostname if (curr != NULL) strncpy (opts.udp_hostname, curr, 1023); //set address to blast to - + curr = strtok(NULL, ":"); //udp blaster port if (curr != NULL) opts.udp_portno = atoi (curr); @@ -3353,7 +3353,7 @@ main (int argc, char **argv) fprintf(stderr, "Audio Out Device: -\n"); } - int fmt; + int fmt; int speed; //The long of the short is that PADSP can open multiple virtual /dev/dsp devices each with different sampling rates and channel configurations @@ -3383,7 +3383,7 @@ main (int argc, char **argv) { fprintf (stderr, "Error, couldn't open %s\n", opts.audio_in_dev); } - + fmt = 0; if (ioctl (opts.audio_in_fd, SNDCTL_DSP_RESET) < 0) { @@ -3482,10 +3482,10 @@ main (int argc, char **argv) fprintf (stderr, "M17 User Data: "); char * curr; - + // if((strncmp(state.m17dat, "M17", 3) == 0)) // goto M17END; - + curr = strtok(state.m17dat, ":"); //should be 'M17' if (curr != NULL) ; //continue else goto M17END; //end early with preset values @@ -3500,7 +3500,7 @@ main (int argc, char **argv) strncpy (state.str50c, curr, 9); //only read first 9 state.str50c[9] = '\0'; } - + curr = strtok(NULL, ":"); //m17 dst address if (curr != NULL) { @@ -3550,7 +3550,7 @@ main (int argc, char **argv) opts.use_cosine_filter = 0; opts.pulse_digi_rate_out = 8000; - + //open any inputs, if not alread opened, OSS input and output already handled if (opts.audio_in_type == 0) openPulseInput(&opts); @@ -3573,7 +3573,7 @@ main (int argc, char **argv) opts.pulse_digi_rate_out = 8000; //open any outputs, if not already opened if (opts.audio_out_type == 0) openPulseOutput(&opts); - encodeM17BRT(&opts, &state); + encodeM17BRT(&opts, &state); } else if (opts.m17encoderpkt == 1) diff --git a/src/dsd_mbe.c b/src/dsd_mbe.c index 0d8b8e3..00b5319 100644 --- a/src/dsd_mbe.c +++ b/src/dsd_mbe.c @@ -149,7 +149,7 @@ void playMbeFiles (dsd_opts * opts, dsd_state * state, int argc, char **argv) ambe_d[j] ^= x; } } - + //ambe+2 if (state->mbe_file_type == 1) 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); //dstar ambe @@ -244,7 +244,7 @@ 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)) + if ((state->synctype == 0) || (state->synctype == 1)) { // 0 +P25p1 // 1 -P25p1 @@ -283,7 +283,7 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a state->octet_counter = 11+8; //start on 19 for DES-OFB (8 discard + 8 LC + 3 reserved) else if (state->payload_algid == 0x9F) state->octet_counter = 11; //11 with info from LFSR run values (no discard) - else + else state->octet_counter = 11+16; //start on 27 for AES (16 discard + 8 LC + 3 reserved) memset (state->ks_octetL, 0, sizeof(state->ks_octetL)); @@ -294,7 +294,7 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a des_multi_keystream_output (state->payload_miP, state->R, state->ks_octetL, 1, 28); if (state->payload_algid == 0x83) //3DES, or TDEA tdea_multi_keystream_output (state->payload_miP, aes_key, state->ks_octetL, 1, 28); - if (state->payload_algid == 0x9F) //DES-XL + if (state->payload_algid == 0x9F) //DES-XL des_multi_keystream_output (state->payload_miP, state->R, state->ks_octetL, 2, state->xl_is_hdu); //hard coded bit count value, xl_is_hdu determines lfsr run values if (state->payload_algid == 0x84) //AES256 aes_ofb_keystream_output (state->aes_iv, aes_key, state->ks_octetL, 2, 14); //14 + 1 discard round @@ -334,7 +334,7 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a } } - + } //P25p1 RC4 Handling @@ -485,7 +485,7 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a } //NXDN Generic Cipher 2 and Cipher 3 Keystream Application (to be tested) - else if ( (state->nxdn_cipher_type == 0x02 && state->R != 0) || + else if ( (state->nxdn_cipher_type == 0x02 && state->R != 0) || (state->nxdn_cipher_type == 0x03 && state->aes_key_loaded[0] == 1) ) { @@ -508,7 +508,7 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a //reset flag to 0 state->nxdn_new_iv = 0; - + } //untested, but same setup as DES, so it 'SHOULD' work...maybe @@ -531,7 +531,7 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a //reset flag to 0 state->nxdn_new_iv = 0; - + } //sanity check, don't exceed bit application counter @@ -595,7 +595,7 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a //debug -- print 48-bit expanded key value // fprintf (stderr, "K: %012llX", k); - for (int j = 0; j < 48; j++) + for (int j = 0; j < 48; j++) { x = ( ((k << j) & 0x800000000000) >> 47 ) & 1; ambe_d[j] ^= x; @@ -625,12 +625,12 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a { //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); + // 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_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 @@ -916,7 +916,7 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a } - mbe_processAmbe2450Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, + 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); @@ -967,7 +967,7 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a //debug -- print 48-bit expanded key value fprintf (stderr, "K: %012llX", k); - for (int j = 0; j < 48; j++) + for (int j = 0; j < 48; j++) { x = ( ((k << j) & 0x800000000000) >> 47 ) & 1; ambe_d[j] ^= x; @@ -995,13 +995,13 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a if (state->M == 0 && state->payload_algidR == 0) { //see if we need to hash a value larger than 16-bits - hash = state->lasttgR & 0xFFFFFF; + 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_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 @@ -1286,7 +1286,7 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a } - mbe_processAmbe2450Dataf (state->audio_out_temp_bufR, &state->errsR, &state->errs2R, state->err_strR, + 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 @@ -1360,25 +1360,25 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a state->dmr_encL = 1; opts->unmute_encrypted_p25 = 0; opts->dmr_mute_encL = 1; - } + } else { state->dmr_encL = 0; opts->unmute_encrypted_p25 = 1; opts->dmr_mute_encL = 0; - } + } } //end reverse mute test //OSS 48k/1 Specific Voice Preemption if dual voices on TDMA and one slot has preference over the other - if (opts->slot_preference == 1 && opts->audio_out_type == 5 && opts->audio_out == 1 && (state->dmrburstR == 16 || state->dmrburstR == 21) ) + if (opts->slot_preference == 1 && opts->audio_out_type == 5 && opts->audio_out == 1 && (state->dmrburstR == 16 || state->dmrburstR == 21) ) { opts->audio_out = 0; preempt = 1; - if (opts->payload == 0 && opts->slot1_on == 1) - fprintf (stderr, " *MUTED*"); - else if (opts->payload == 0 && opts->slot1_on == 0) - fprintf (stderr, " *OFF*"); + if (opts->payload == 0 && opts->slot1_on == 1) + fprintf (stderr, " *MUTED*"); + else if (opts->payload == 0 && opts->slot1_on == 0) + fprintf (stderr, " *OFF*"); } state->debug_audio_errors += state->errs2; @@ -1394,15 +1394,15 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a } if (opts->audio_out == 1 && opts->floating_point == 0 && opts->audio_out_type == 5 && opts->slot1_on == 1) //for OSS 48k 1 channel configs -- relocate later if possible { - playSynthesizedVoiceMS (opts, state); //it may be more beneficial to move this to each individual decoding type to handle, but ultimately, let's just simpifly mbe handling instead + playSynthesizedVoiceMS (opts, state); //it may be more beneficial to move this to each individual decoding type to handle, but ultimately, let's just simpifly mbe handling instead } } - memcpy (state->f_l, state->audio_out_temp_buf, sizeof(state->f_l)); //these are for mono or FDMA where we don't need to buffer and wait for a stereo mix + memcpy (state->f_l, state->audio_out_temp_buf, sizeof(state->f_l)); //these are for mono or FDMA where we don't need to buffer and wait for a stereo mix } - if (opts->dmr_stereo == 1 && state->currentslot == 1) + if (opts->dmr_stereo == 1 && state->currentslot == 1) { enc_bit = (state->dmr_soR >> 6) & 0x1; if (enc_bit == 0x1) @@ -1437,24 +1437,24 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a state->dmr_encR = 1; opts->unmute_encrypted_p25 = 0; opts->dmr_mute_encR = 1; - } + } else { state->dmr_encR = 0; opts->unmute_encrypted_p25 = 1; opts->dmr_mute_encR = 0; - } + } } //end reverse mute test //OSS 48k/1 Specific Voice Preemption if dual voices on TDMA and one slot has preference over the other - if (opts->slot_preference == 0 && opts->audio_out_type == 5 && opts->audio_out == 1 && (state->dmrburstL == 16 || state->dmrburstL == 21) ) + if (opts->slot_preference == 0 && opts->audio_out_type == 5 && opts->audio_out == 1 && (state->dmrburstL == 16 || state->dmrburstL == 21) ) { opts->audio_out = 0; preempt = 1; - if (opts->payload == 0 && opts->slot2_on == 1) - fprintf (stderr, " *MUTED*"); - else if (opts->payload == 0 && opts->slot2_on == 0) + if (opts->payload == 0 && opts->slot2_on == 1) + fprintf (stderr, " *MUTED*"); + else if (opts->payload == 0 && opts->slot2_on == 0) fprintf (stderr, " *OFF*"); } @@ -1524,7 +1524,7 @@ processMbeFrame (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char a if (preempt == 1) { opts->audio_out = 1; - preempt = 0; + preempt = 0; } //reset audio out flag for next repitition --disabled for now diff --git a/src/dsd_mbe2.c b/src/dsd_mbe2.c index 55dcebb..35542a3 100644 --- a/src/dsd_mbe2.c +++ b/src/dsd_mbe2.c @@ -1,14 +1,14 @@ /*------------------------------------------------------------------------------- - * - * + * + * * * TODO: Fill me in' - * + * * * LWVMOBILE * 2023-07 DSD-FME Florida Man Edition *-----------------------------------------------------------------------------*/ - + //new and simplified/organized ambe and imbe handling //moving all audio handling and decryption to seperate files for simplicity (eventually) @@ -54,7 +54,7 @@ void soft_demod_ambe2_ehr(dsd_state * state, char ambe2_ehr[4][24], char ambe_d[ //AMBE One Shot (DSTAR) void soft_demod_ambe_dstar(dsd_opts * opts, dsd_state * state, char ambe_fr[4][24], char ambe_d[49]) { - mbe_processAmbe3600x2400Framef (state->audio_out_temp_buf, &state->errs, &state->errs2, + 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->floating_point == 1) memcpy (state->f_l, state->audio_out_temp_buf, sizeof(state->f_l)); @@ -64,7 +64,7 @@ void soft_demod_ambe_dstar(dsd_opts * opts, dsd_state * state, char ambe_fr[4][2 //AMBE+2 One Shot (X2-TDMA) void soft_demod_ambe_x2(dsd_opts * opts, dsd_state * state, char ambe_fr[4][24], char ambe_d[49]) { - mbe_processAmbe3600x2450Framef (state->audio_out_temp_buf, &state->errs, &state->errs2, + 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->floating_point == 1) memcpy (state->f_l, state->audio_out_temp_buf, sizeof(state->f_l)); @@ -73,7 +73,7 @@ void soft_demod_ambe_x2(dsd_opts * opts, dsd_state * state, char ambe_fr[4][24], void soft_mbe (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 ambe_d[49]; char imbe_d[88]; int slot = state->currentslot; @@ -92,7 +92,7 @@ void soft_mbe (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char amb imbe_d, state->cur_mp, state->prev_mp, state->prev_mp_enhanced, opts->uvquality); //send to playback here } - + //ProVoice else if (state->synctype == 14 || state->synctype == 15) { @@ -106,7 +106,7 @@ void soft_mbe (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char amb //send to playback here } - + //D-STAR AMBE else if (state->synctype == 6 || state->synctype == 7) { @@ -163,15 +163,15 @@ void soft_mbe (dsd_opts * opts, dsd_state * state, char imbe_fr[8][23], char amb //make left or right channel decision if (slot == 0) { - mbe_processAmbe2450Dataf (state->audio_out_temp_buf, &state->errs, &state->errs2, state->err_str, + 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 (slot == 1) { - mbe_processAmbe2450Dataf (state->audio_out_temp_bufR, &state->errsR, &state->errs2R, state->err_strR, + 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); } - + } } diff --git a/src/dsd_misc.c b/src/dsd_misc.c index ae5e34a..cafba49 100644 --- a/src/dsd_misc.c +++ b/src/dsd_misc.c @@ -2,8 +2,8 @@ * dsd_misc.c * Misc Code that needs to be reorganized and sorted out * - * - * + * + * *-----------------------------------------------------------------------------*/ #include "dsd.h" @@ -57,7 +57,7 @@ void trellis_decode(uint8_t result[], const uint8_t source[], int result_len) reg = (reg << 1) | min_bt; dstats[(min_d > 3) ? 3 : min_d] += 1; } - + //debug output // fprintf (stderr, "\n stats\t%d %d %d %d\n", dstats[0], dstats[1], dstats[2], dstats[3]); } @@ -65,21 +65,21 @@ void trellis_decode(uint8_t result[], const uint8_t source[], int result_len) //Original Copyright/License /* -*- c++ -*- */ -/* +/* * NXDN Encoder/Decoder (C) Copyright 2019 Max H. Parke KA1RBI - * + * * This file is part of OP25 - * + * * This 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, or (at your option) * any later version. - * + * * This software 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 software; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -385,7 +385,7 @@ void HPFilter_Init(HPFilter *filter, float cutoffFreqHz, float sampleTimeS) float HPFilter_Update(HPFilter *filter, float v_in) { - + filter->v_in[1]=filter->v_in[0]; filter->v_in[0]=v_in; @@ -493,7 +493,7 @@ void init_audio_filters (dsd_state * state) //passband filter working (seems to be), notch filter unsure which values to use, doesn't have any appreciable affect when used as is PBFilter_Init(&state->PBF, 8000, 12000, (float)1/(float)1536000); //RTL Sampling at 1536000 S/s. NOTCHFilter_Init(&state->NF, 1000, 4000, (float)1/(float)1536000); - + } //FUNCTIONS for handing use of above filters @@ -572,7 +572,7 @@ void pbf(dsd_state * state, short * input, int len) //Generic RMS function derived from RTL_FM (RTL_SDR) RMS code (doesnt' really work correctly outside of RTL) long int raw_rms(int16_t *samples, int len, int step) //use samplespersymbol as len { - + int i; long int rms; long p, t, s; diff --git a/src/dsd_ncurses.c b/src/dsd_ncurses.c index a95e6c4..231a5b0 100644 --- a/src/dsd_ncurses.c +++ b/src/dsd_ncurses.c @@ -3282,7 +3282,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) break; } } - + } else if (lls == 35 || lls == 36) //P2 { @@ -5058,7 +5058,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) //so probably just write a function to handle c input, and when c = certain values //needing an entry box, then stop all of those - + //allocated memory pointer needs to be free'd diff --git a/src/dsd_reset.c b/src/dsd_reset.c index 8144aae..7b5d080 100644 --- a/src/dsd_reset.c +++ b/src/dsd_reset.c @@ -13,7 +13,7 @@ void resetState (dsd_state * state) //Dibit Buffer -- Memset/Init/Allocate Memory // state->dibit_buf = malloc (sizeof (int) * 1000000); - + state->dibit_buf_p = state->dibit_buf + 200; memset (state->dibit_buf, 0, sizeof (int) * 200); state->repeat = 0; //repeat frame? @@ -32,7 +32,7 @@ void resetState (dsd_state * state) memset (state->audio_out_buf, 0, 100 * sizeof (short)); state->audio_out_buf_p = state->audio_out_buf + 100; - + memset (state->audio_out_float_buf, 0, 100 * sizeof (float)); state->audio_out_float_buf_p = state->audio_out_float_buf + 100; @@ -46,7 +46,7 @@ void resetState (dsd_state * state) memset (state->audio_out_bufR, 0, 100 * sizeof (short)); state->audio_out_buf_pR = state->audio_out_bufR + 100; - + memset (state->audio_out_float_bufR, 0, 100 * sizeof (float)); state->audio_out_float_buf_pR = state->audio_out_float_bufR + 100; @@ -100,12 +100,12 @@ void resetState (dsd_state * state) state->numtdulc = 0; state->firstframe = 0; - //unsure if these are still used or ever were used, + //unsure if these are still used or ever were used, // memset (state->aout_max_buf, 0, sizeof (float) * 200); // state->aout_max_buf_p = state->aout_max_buf; // state->aout_max_buf_idx = 0; - // //MBE Specific + // //MBE Specific // //free the memory before allocating it again -- may not use this // free (state->cur_mp); // free (state->prev_mp); diff --git a/src/dsd_rigctl.c b/src/dsd_rigctl.c index 4b75fd5..810a440 100644 --- a/src/dsd_rigctl.c +++ b/src/dsd_rigctl.c @@ -51,14 +51,14 @@ int Connect (char *hostname, int portno) fprintf(stderr,"ERROR opening socket\n"); error("ERROR opening socket"); } - + /* gethostbyname: get the server's DNS entry */ server = gethostbyname(hostname); if (server == NULL) { fprintf(stderr,"ERROR, no such host as %s\n", hostname); //exit(0); - return (0); //return 0, check on other end and configure pulse input + return (0); //return 0, check on other end and configure pulse input } /* build the server's Internet address */ @@ -73,7 +73,7 @@ int Connect (char *hostname, int portno) { fprintf(stderr,"ERROR opening socket\n"); return (0); - } + } return sockfd; } @@ -108,7 +108,7 @@ bool Recv(int sockfd, char *buf) // // GQRX Protocol // -long int GetCurrentFreq(int sockfd) +long int GetCurrentFreq(int sockfd) { long int freq = 0; char buf[BUFSIZE]; @@ -116,13 +116,13 @@ long int GetCurrentFreq(int sockfd) char * token; Send(sockfd, "f\n"); - Recv(sockfd, buf); + Recv(sockfd, buf); - if (strcmp(buf, "RPRT 1") == 0 ) + if (strcmp(buf, "RPRT 1") == 0 ) return freq; - token = strtok (buf, "\n"); - freq = strtol (token, &ptr, 10); + token = strtok (buf, "\n"); + freq = strtol (token, &ptr, 10); // fprintf (stderr, "\nRIGCTL VFO Freq: [%ld]\n", freq); return freq; } @@ -131,7 +131,7 @@ bool SetFreq(int sockfd, long int freq) { char buf[BUFSIZE]; - sprintf (buf, "F %ld\n", freq); + sprintf (buf, "F %ld\n", freq); Send(sockfd, buf); Recv(sockfd, buf); @@ -141,7 +141,7 @@ bool SetFreq(int sockfd, long int freq) return true; } -bool SetModulation(int sockfd, int bandwidth) +bool SetModulation(int sockfd, int bandwidth) { char buf[BUFSIZE]; //the bandwidth is now a user/system based configurable variable @@ -256,7 +256,7 @@ int UDPBind (char *hostname, int portno) serveraddr.sin_port = htons(portno); //Bind socket to listening - if (bind(sockfd, (struct sockaddr *) &serveraddr, sizeof(serveraddr)) < 0) { + if (bind(sockfd, (struct sockaddr *) &serveraddr, sizeof(serveraddr)) < 0) { perror("ERROR on binding UDP Port"); } @@ -270,12 +270,12 @@ int UDPBind (char *hostname, int portno) } //going to leave this function available, even if completely switched over to rtl_dev_tune now, may be useful in the future -void rtl_udp_tune(dsd_opts * opts, dsd_state * state, long int frequency) +void rtl_udp_tune(dsd_opts * opts, dsd_state * state, long int frequency) { UNUSED(state); - int handle; - unsigned short udp_port = opts->rtl_udp_port; + int handle; + unsigned short udp_port = opts->rtl_udp_port; char data[5] = {0}; //data buffer size is 5 for UDP frequency tuning struct sockaddr_in address; @@ -327,8 +327,8 @@ void udp_socket_blaster(dsd_opts * opts, dsd_state * state, size_t nsam, void * int m17_socket_receiver(dsd_opts * opts, void * data) { size_t err = 0; - struct sockaddr_in cliaddr; - socklen_t len = sizeof(cliaddr); + struct sockaddr_in cliaddr; + socklen_t len = sizeof(cliaddr); //receive data from socket err = recvfrom(opts->udp_sockfd, data, 1000, 0, (struct sockaddr * ) & address, &len); //was MSG_WAITALL, but that seems to be = 256 diff --git a/src/dsd_symbol.c b/src/dsd_symbol.c index b4b9e07..9d1b8b9 100644 --- a/src/dsd_symbol.c +++ b/src/dsd_symbol.c @@ -117,12 +117,12 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) { opts->audio_in_type = 0; //set input type openPulseInput(opts); //open pulse input - } + } //else cleanup and exit else { - cleanupAndExit(opts, state); - } + cleanupAndExit(opts, state); + } } } else if (opts->audio_in_type == 3) @@ -150,7 +150,7 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) sleep (3); //halt all processing and wait 3 seconds //attempt to reconnect to socket - opts->tcp_sockfd = 0; + opts->tcp_sockfd = 0; opts->tcp_sockfd = Connect(opts->tcp_hostname, opts->tcp_portno); if (opts->tcp_sockfd != 0) { @@ -168,7 +168,7 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) } else fprintf (stderr, "TCP Socket Reconnected Successfully.\n"); } - else fprintf (stderr, "TCP Socket Connection Error.\n"); + else fprintf (stderr, "TCP Socket Connection Error.\n"); //now retry reading sample result = sf_read_short(opts->tcp_file_in, &sample, 1); @@ -185,17 +185,17 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) fprintf (stderr, "Opening Pulse Audio Input.\n"); opts->audio_in_type = 0; //set input type openPulseInput(opts); //open pulse input - } + } //else cleanup and exit - else + else { fprintf (stderr, "Connection to TCP Server Disconnected.\n"); fprintf (stderr, "Closing DSD-FME.\n"); cleanupAndExit(opts, state); } - + } - + } #else result = sf_read_short(opts->tcp_file_in, &sample, 1); @@ -208,7 +208,7 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) sleep (3); //halt all processing and wait 3 seconds //attempt to reconnect to socket - opts->tcp_sockfd = 0; + opts->tcp_sockfd = 0; opts->tcp_sockfd = Connect(opts->tcp_hostname, opts->tcp_portno); if (opts->tcp_sockfd != 0) { @@ -242,14 +242,14 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) sample = 0; //zero sample on bad result, keep the ball rolling fprintf (stderr, "Connection to TCP Server Disconnected.\n"); } - + } #endif - + } //BUG REPORT: 1. DMR Simplex doesn't work with raw wav files. 2. Using the monitor w/ wav file saving may produce undecodable wav files. - //reworked a bit to allow raw audio wav file saving without the monitoring poriton active + //reworked a bit to allow raw audio wav file saving without the monitoring poriton active if (have_sync == 0) { @@ -264,7 +264,7 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) if (state->analog_sample_counter > 959) state->analog_sample_counter = 959; - state->analog_out[state->analog_sample_counter++] = sample; + state->analog_out[state->analog_sample_counter++] = sample; if (state->analog_sample_counter == 960) { @@ -351,7 +351,7 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) if (state->analog_sample_counter > 959) state->analog_sample_counter = 959; - state->analog_out[state->analog_sample_counter++] = sample; + state->analog_out[state->analog_sample_counter++] = sample; if (state->analog_sample_counter == 960) { @@ -371,19 +371,19 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) if (opts->use_cosine_filter) { - if ( (state->lastsynctype >= 10 && state->lastsynctype <= 13) || state->lastsynctype == 32 || state->lastsynctype == 33 + if ( (state->lastsynctype >= 10 && state->lastsynctype <= 13) || state->lastsynctype == 32 || state->lastsynctype == 33 || state->lastsynctype == 34 || state->lastsynctype == 30 || state->lastsynctype == 31) { sample = dmr_filter(sample); } - else if (state->lastsynctype == 8 || state->lastsynctype == 9 || state->lastsynctype == 16 || state->lastsynctype == 17 || + else if (state->lastsynctype == 8 || state->lastsynctype == 9 || state->lastsynctype == 16 || state->lastsynctype == 17 || state->lastsynctype == 86 || state->lastsynctype == 87 || state->lastsynctype == 98 || state->lastsynctype == 99) { sample = m17_filter(sample); } - else if ( + else if ( state->lastsynctype == 20 || state->lastsynctype == 21 || state->lastsynctype == 22 || state->lastsynctype == 23 || state->lastsynctype == 24 || state->lastsynctype == 25 || @@ -510,7 +510,7 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) if (state->rf_mod == 0) { // 0: C4FM modulation - + //EXPERIMENTAL: manipulate the left edge depending on sync type //TODO: See if we can manipulate this a bit more based on AFC or similar type function int l_edge = 2; @@ -572,7 +572,7 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) //is my original consclusion back when I was working on it last, unsure //or the best course on that, could just be a rtl_fm flaw //P25 may also work better at 16 as well now, hard to tell the difference since both are good - //DMR may not be any different on 12 or 16 + //DMR may not be any different on 12 or 16 //most likely though, this all will just depend on signal stregth more than anything //as to how much BW you should set @@ -664,7 +664,7 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) { opts->audio_in_type = 0; //set input type openPulseInput(opts); //open pulse input - } + } //else cleanup and exit else { @@ -676,11 +676,11 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) if (state->rf_mod == 2) //GFSK { symbol = state->symbolc; - if (state->symbolc == 0 ) + if (state->symbolc == 0 ) { symbol = -3; //-1 } - if (state->symbolc == 1 ) + if (state->symbolc == 1 ) { symbol = -1; //-3 } diff --git a/src/dsd_upsample.c b/src/dsd_upsample.c index 25fb3ee..dc22e80 100644 --- a/src/dsd_upsample.c +++ b/src/dsd_upsample.c @@ -2,8 +2,8 @@ * dsd_upsample.c * Simplified 8k to 48k Upsample Functions * Goodbye terrible ringing sound - * - * + * + * * * LWVMOBILE * 2024-03 DSD-FME Florida Man Edition diff --git a/src/dstar.c b/src/dstar.c index c41c1fd..1d4fdf2 100644 --- a/src/dstar.c +++ b/src/dstar.c @@ -70,7 +70,7 @@ void processDSTAR_HD(dsd_opts * opts, dsd_state * state) } //first 24-bits of the larger scramble table -uint8_t sd_d[48] = +uint8_t sd_d[48] = {0,0,0,0, //0 1,1,1,0, //E 1,1,1,1, //F @@ -275,7 +275,7 @@ void processDSTAR_SD(dsd_opts * opts, dsd_state * state, uint8_t * sd) if (start == -1) goto SKIP; - //debug + //debug // fprintf (stderr, "S: %d; ", start); //38, or 39 //LAT @@ -377,7 +377,7 @@ void processDSTAR_SD(dsd_opts * opts, dsd_state * state, uint8_t * sd) fprintf (stderr, " _UNK:"); fprintf (stderr, " %s", strf); // memcpy (state->dstar_txt, strf, sizeof(strf)); //don't copy the unknown garbo strings - } + } } diff --git a/src/edacs-bch3.c b/src/edacs-bch3.c index 79e009d..5d9398c 100644 --- a/src/edacs-bch3.c +++ b/src/edacs-bch3.c @@ -6,7 +6,7 @@ * Mod: December 14, 2021, for EDACS-FM BCH Polynomial Error Generation and Detection * Mod2: October 2022, for DSD-FME port of EDACS-FM * Source: www.eccpage.com - * + * * =============== Encoder/Decoder for binary BCH codes in C ================= * * Version 1: Original program. The user provides the generator polynomial @@ -30,7 +30,7 @@ * previous version of the BCH encoder/decoder in C, 'bch2.c', was written by * Robert Morelos-Zaragoza (robert@spectra.eng.hawaii.edu) on 5/19/92. * - * NOTE: + * NOTE: * The author is not responsible for any malfunctioning of * this program, nor for any damage caused by it. Please include the * original program along with these comments in any redistribution. @@ -45,14 +45,14 @@ * email: r.morelos-zaragoza@ieee.org * * COPYRIGHT NOTICE: This computer program is free for non-commercial purposes. - * You may implement this program for any non-commercial application. You may + * You may implement this program for any non-commercial application. You may * also implement this program for commercial purposes, provided that you * obtain my written permission. Any modification of this program is covered * by this copyright. * * == Copyright (c) 1994-7, Robert Morelos-Zaragoza. All rights reserved. == * - * m = order of the Galois field GF(2**m) + * m = order of the Galois field GF(2**m) * n = 2**m - 1 = size of the multiplicative group of GF(2**m) * length = length of the BCH code * t = error correcting capability (max. no. of errors the code corrects) @@ -60,14 +60,14 @@ * k = n - deg(g(x)) = dimension (no. of information bits/codeword) of the code * p[] = coefficients of a primitive polynomial used to generate GF(2**m) * g[] = coefficients of the generator polynomial, g(x) - * alpha_to [] = log table of GF(2**m) + * alpha_to [] = log table of GF(2**m) * index_of[] = antilog table of GF(2**m) * ddata[] = information bits = coefficients of data polynomial, i(x) * bb[] = coefficients of redundancy polynomial x^(length-k) i(x) modulo g(x) - * numerr = number of errors - * errpos[] = error positions - * recd[] = coefficients of the received polynomial - * decerror = number of decoding errors (in _message_ positions) + * numerr = number of errors + * errpos[] = error positions + * recd[] = coefficients of the received polynomial + * decerror = number of decoding errors (in _message_ positions) * */ @@ -83,7 +83,7 @@ int seed; int numerr, errpos[1024], decerror = 0; -void +void read_p() /* * Read m, the degree of a primitive polynomial p(x) used to compute the @@ -126,7 +126,7 @@ read_p() } n = n / 2 - 1; ninf = (n + 1) / 2 - 1; - + do { length = 40; @@ -134,7 +134,7 @@ read_p() } -void +void generate_gf() /* * Generate field GF(2**m) from the irreducible polynomial p(X) with @@ -144,7 +144,7 @@ generate_gf() * index->polynomial form: alpha_to[] contains j=alpha^i; * polynomial form -> index form: index_of[j=alpha^i] = i * - * alpha=2 is the primitive element of GF(2**m) + * alpha=2 is the primitive element of GF(2**m) */ { register int i, mask; @@ -171,7 +171,7 @@ generate_gf() } -void +void gen_poly() /* * Compute the generator polynomial of a binary BCH code. Fist generate the @@ -209,7 +209,7 @@ gen_poly() do { ll++; test = 0; - for (ii = 1; ((ii <= jj) && (!test)); ii++) + for (ii = 1; ((ii <= jj) && (!test)); ii++) /* Examine previous cycle sets */ for (kaux = 0; ((kaux < size[ii]) && (!test)); kaux++) if (ll == cycle[ii][kaux]) @@ -274,7 +274,7 @@ gen_poly() } -void +void encode_bch() /* * Compute redundacy bb[], the coefficients of b(x). The redundancy @@ -305,7 +305,7 @@ encode_bch() } -void +void decode_bch() /* * Simon Rockliff's implementation of Berlekamp's algorithm. @@ -361,7 +361,7 @@ decode_bch() * u='mu'+1 and 'mu' (the Greek letter!) is the step number * ranging from -1 to 2*t (see L&C), l[u] is the degree of * the elp at that step, and u_l[u] is the difference between - * the step number and the degree of the elp. + * the step number and the degree of the elp. */ /* initialise table entries */ d[0] = 0; /* index form */ @@ -377,7 +377,7 @@ decode_bch() u_lu[0] = -1; u_lu[1] = 0; u = 0; - + do { u++; if (d[u] == -1) { @@ -389,7 +389,7 @@ decode_bch() } else /* * search for words with greatest u_lu[q] for - * which d[q]!=0 + * which d[q]!=0 */ { q = u - 1; @@ -404,23 +404,23 @@ decode_bch() q = j; } while (j > 0); } - + /* * have now found q such that d[u]!=0 and - * u_lu[q] is maximum + * u_lu[q] is maximum */ /* store degree of new elp polynomial */ if (l[u] > l[q] + u - q) l[u + 1] = l[u]; else l[u + 1] = l[q] + u - q; - + /* form new elp(x) */ for (i = 0; i < t2; i++) elp[u + 1][i] = 0; for (i = 0; i <= l[q]; i++) if (elp[q][i] != -1) - elp[u + 1][i + u - q] = + elp[u + 1][i + u - q] = alpha_to[(d[u] + n - d[q] + elp[q][i]) % n]; for (i = 0; i <= l[u]; i++) { elp[u + 1][i] ^= elp[u][i]; @@ -428,9 +428,9 @@ decode_bch() } } u_lu[u + 1] = u - l[u + 1]; - + /* form (u+1)th discrepancy */ - if (u < t2) { + if (u < t2) { /* no discrepancy computed on last iteration */ if (s[u + 1] != -1) d[u + 1] = alpha_to[s[u + 1]]; @@ -441,10 +441,10 @@ decode_bch() d[u + 1] ^= alpha_to[(s[u + 1 - i] + index_of[elp[u + 1][i]]) % n]; /* put d[u+1] into index form */ - d[u + 1] = index_of[d[u + 1]]; + d[u + 1] = index_of[d[u + 1]]; } } while ((u < t2) && (l[u + 1] <= t)); - + u++; if (l[u] <= t) {/* Can correct errors */ /* put elp into index form */ @@ -472,7 +472,7 @@ decode_bch() } } - if (count == l[u]) + if (count == l[u]) /* no. roots = degree of elp hence <= t errors */ for (i = 0; i < l[u]; i++) recd[loc[i]] ^= 1; @@ -496,8 +496,8 @@ unsigned long long int edacs_bch (unsigned long long int message) for (i = 0; i < k; i++){ ddata[i] = ( (message >> i) & 0x1 ); //loaded up backwards? or just outputs backwards? } - - + + encode_bch(); /* encode data */ /* diff --git a/src/edacs-fme.c b/src/edacs-fme.c index 36cc417..bb6c007 100644 --- a/src/edacs-fme.c +++ b/src/edacs-fme.c @@ -812,7 +812,7 @@ void edacs(dsd_opts * opts, dsd_state * state) //Ilya, please don't nit fix my logging format for these, it breaks grep when parsing a bunch of these all at once fprintf (stderr, "%s", KWHT); fprintf (stderr, " System Dynamic Regroup :: SP-WGID: %03d; Target: %07d;", sgid, target); - + if (sgid != target) { //decode potential TGA values (assumming same as Harris P25) @@ -833,7 +833,7 @@ void edacs(dsd_opts * opts, dsd_state * state) fprintf (stderr, " UNK2: %02X;", unk2); fprintf (stderr, " SSN: %02X;", ssn); //this may or may not be a unique value to each SGID, is 1F for termination of a patch } - + //07:25:17 Sync: +EDACS MSG_1 [FE00045] MSG_2 [FE00045] (MT1: 1F; MT2: C) System Dynamic Regroup :: SP-WGID: 069; Target: 0000069; One-Way Group Patch Delete TGA: 6; //Upon Reflection, thinking the same MT1 and MT2 values are in both messages, so appears to just be the SP-WGID here and a bunch of zeroes leading into it, and not a TGA value @@ -2146,7 +2146,7 @@ void edacs(dsd_opts * opts, dsd_state * state) free (datestr); datestr = NULL; } - + fprintf (stderr, "\n"); } diff --git a/src/ez.cpp b/src/ez.cpp index 8e8f6af..f2ef04c 100644 --- a/src/ez.cpp +++ b/src/ez.cpp @@ -84,7 +84,7 @@ int ez_rs28_facch (int payload[156], int parity[114]) int ec = -2; int i, j, k, b; - //init HB + //init HB for (i = 0; i < 64; i++) { HB[i] = 0; @@ -338,7 +338,7 @@ int isch_lookup (uint64_t isch) } else // No errors, so simply return the matching value decoded = isch_map[isch]; - + return decoded; } \ No newline at end of file diff --git a/src/fec.c b/src/fec.c index 1497ed0..d257fb8 100644 --- a/src/fec.c +++ b/src/fec.c @@ -965,7 +965,7 @@ bool Golay_20_8_decode(unsigned char *rxBits) int is = 0; int i = 0; //tally corrections made, exceeding 2 will return false - int correction = 0; + int correction = 0; for (is = 0; is < 12; is++) { @@ -1014,11 +1014,11 @@ bool Golay_20_8_decode(unsigned char *rxBits) } //return false due to exceeding the number of allowed corrected bits - //being stingy and only allowing 1 error, may wreck some good data decodes, + //being stingy and only allowing 1 error, may wreck some good data decodes, //decided to play it safe with 2 if (correction > 2) { - return false; + return false; } } diff --git a/src/m17.c b/src/m17.c index d7f7217..544eec2 100644 --- a/src/m17.c +++ b/src/m17.c @@ -11,7 +11,7 @@ #include "dsd.h" //try to find a fancy lfsr or calculation for this and not an array if possible -uint8_t m17_scramble[369] = { +uint8_t m17_scramble[369] = { 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, @@ -34,7 +34,7 @@ uint8_t m17_scramble[369] = { 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, -0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1 +0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1 }; char b40[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-/."; @@ -74,7 +74,7 @@ void M17decodeCSD(dsd_state * state, unsigned long long int dst, unsigned long l int i; char c; - if (dst == 0xFFFFFFFFFFFF) + if (dst == 0xFFFFFFFFFFFF) fprintf (stderr, " DST: BROADCAST"); else if (dst == 0) fprintf (stderr, " DST: RESERVED %012llx", dst); @@ -91,15 +91,15 @@ void M17decodeCSD(dsd_state * state, unsigned long long int dst, unsigned long l dst = dst / 40; } //assign completed CSD to a more useful string instead - sprintf (state->m17_dst_str, "%c%c%c%c%c%c%c%c%c", - state->m17_dst_csd[0], state->m17_dst_csd[1], state->m17_dst_csd[2], state->m17_dst_csd[3], + sprintf (state->m17_dst_str, "%c%c%c%c%c%c%c%c%c", + state->m17_dst_csd[0], state->m17_dst_csd[1], state->m17_dst_csd[2], state->m17_dst_csd[3], state->m17_dst_csd[4], state->m17_dst_csd[5], state->m17_dst_csd[6], state->m17_dst_csd[7], state->m17_dst_csd[8]); //debug // fprintf (stderr, "DT: %s", state->m17_dst_str); } - if (src == 0xFFFFFFFFFFFF) + if (src == 0xFFFFFFFFFFFF) fprintf (stderr, " SRC: UNKNOWN FFFFFFFFFFFF"); else if (src == 0) fprintf (stderr, " SRC: RESERVED %012llx", src); @@ -116,8 +116,8 @@ void M17decodeCSD(dsd_state * state, unsigned long long int dst, unsigned long l src = src / 40; } //assign completed CSD to a more useful string instead - sprintf (state->m17_src_str, "%c%c%c%c%c%c%c%c%c", - state->m17_src_csd[0], state->m17_src_csd[1], state->m17_src_csd[2], state->m17_src_csd[3], + sprintf (state->m17_src_str, "%c%c%c%c%c%c%c%c%c", + state->m17_src_csd[0], state->m17_src_csd[1], state->m17_src_csd[2], state->m17_src_csd[3], state->m17_src_csd[4], state->m17_src_csd[5], state->m17_src_csd[6], state->m17_src_csd[7], state->m17_src_csd[8]); //debug @@ -132,7 +132,7 @@ void M17decodeCSD(dsd_state * state, unsigned long long int dst, unsigned long l void M17decodeLSF(dsd_state * state) { int i; - + unsigned long long int lsf_dst = (unsigned long long int)ConvertBitIntoBytes(&state->m17_lsf[0], 48); unsigned long long int lsf_src = (unsigned long long int)ConvertBitIntoBytes(&state->m17_lsf[48], 48); uint16_t lsf_type = (uint16_t)ConvertBitIntoBytes(&state->m17_lsf[96], 16); @@ -159,7 +159,7 @@ void M17decodeLSF(dsd_state * state) fprintf (stderr, " CAN: %d", lsf_cn); M17decodeCSD(state, lsf_dst, lsf_src); - + if (lsf_dt == 0) fprintf (stderr, " Reserved"); if (lsf_dt == 1) fprintf (stderr, " Data"); if (lsf_dt == 2) fprintf (stderr, " Voice (3200bps)"); @@ -175,7 +175,7 @@ void M17decodeLSF(dsd_state * state) state->m17_enc_st = lsf_es; if (lsf_rs != 0) - { + { if (lsf_rs == 0x10) fprintf (stderr, " OTAKD Data Packet;"); else if (lsf_rs == 0x11) @@ -217,7 +217,7 @@ void M17decodeLSF(dsd_state * state) //if no Meta (debug) // if (lsf_et == 0 && meta_sum == 0) // fprintf (stderr, " Meta Null; "); - + if (lsf_et == 2) { fprintf (stderr, " IV: "); @@ -226,7 +226,7 @@ void M17decodeLSF(dsd_state * state) } LSF_END: ; //do nothing - + } int M17processLICH(dsd_state * state, dsd_opts * opts, uint8_t * lich_bits) @@ -293,7 +293,7 @@ int M17processLICH(dsd_state * state, dsd_opts * opts, uint8_t * lich_bits) { fprintf (stderr, " LICH: "); for (i = 0; i < 6; i++) - fprintf (stderr, "[%02X]", (uint8_t)ConvertBitIntoBytes(&lich_decoded[i*8], 8)); + fprintf (stderr, "[%02X]", (uint8_t)ConvertBitIntoBytes(&lich_decoded[i*8], 8)); } uint8_t lsf_packed[30]; @@ -351,7 +351,7 @@ void M17processCodec2_1600(dsd_opts * opts, dsd_state * state, uint8_t * payload //TODO: Add some decryption methods if (state->m17_enc != 0) { - //process scrambler or AES-CTR decryption + //process scrambler or AES-CTR decryption //(no AES-CTR right now, Scrambler should be easy enough) } @@ -366,7 +366,7 @@ void M17processCodec2_1600(dsd_opts * opts, dsd_state * state, uint8_t * payload for (i = 0; i < 8; i++) fprintf (stderr, "%02X", voice2[i]); } - + #ifdef USE_CODEC2 size_t nsam; nsam = 320; @@ -386,7 +386,7 @@ void M17processCodec2_1600(dsd_opts * opts, dsd_state * state, uint8_t * payload if (opts->slot1_on == 1) //playback if enabled { - + if (opts->audio_out_type == 0 && state->m17_enc == 0) //Pulse Audio { pa_simple_write(opts->pulse_digi_dev_out, samp1, nsam*2, NULL); @@ -396,7 +396,7 @@ void M17processCodec2_1600(dsd_opts * opts, dsd_state * state, uint8_t * payload { udp_socket_blaster (opts, state, nsam*2, samp1); } - + if (opts->audio_out_type == 5 && state->m17_enc == 0) //OSS 48k/1 { //upsample to 48k and then play @@ -444,7 +444,7 @@ void M17processCodec2_1600(dsd_opts * opts, dsd_state * state, uint8_t * payload uint8_t adata[9]; adata[0] = 0x89; //set so pkt decoder will rip these out as just utf-8 chars for (i = 0; i < 8; i++) adata[i+1] = (unsigned char)ConvertBitIntoBytes(&payload[i*8+64], 8); - + //look and see if the payload has stuff in it first, if not, then run this if (adata[1] != 0 || adata[2] != 0 || adata[3] != 0 || adata[4] != 0 || adata[5] != 0 || adata[6] != 0 || adata[7] != 0 || adata[8] != 0) { @@ -469,7 +469,7 @@ void M17processCodec2_3200(dsd_opts * opts, dsd_state * state, uint8_t * payload //TODO: Add some decryption methods if (state->m17_enc != 0) { - //process scrambler or AES-CTR decryption + //process scrambler or AES-CTR decryption //(no AES-CTR right now, Scrambler should be easy enough) } @@ -485,7 +485,7 @@ void M17processCodec2_3200(dsd_opts * opts, dsd_state * state, uint8_t * payload fprintf (stderr, "%02X", voice2[i]); fprintf (stderr, " (3200)"); } - + #ifdef USE_CODEC2 size_t nsam; nsam = 160; @@ -522,7 +522,7 @@ void M17processCodec2_3200(dsd_opts * opts, dsd_state * state, uint8_t * payload udp_socket_blaster (opts, state, nsam*2, samp1); udp_socket_blaster (opts, state, nsam*2, samp2); } - + if (opts->audio_out_type == 5 && state->m17_enc == 0) //OSS 48k/1 { //upsample to 48k and then play @@ -548,7 +548,7 @@ void M17processCodec2_3200(dsd_opts * opts, dsd_state * state, uint8_t * payload write (opts->audio_out_fd, samp2, nsam*2); } - if (opts->audio_out_type == 2 && state->m17_enc == 0) //OSS 8k/1 + if (opts->audio_out_type == 2 && state->m17_enc == 0) //OSS 8k/1 { write (opts->audio_out_fd, samp1, nsam*2); write (opts->audio_out_fd, samp2, nsam*2); @@ -581,7 +581,7 @@ void M17processCodec2_3200(dsd_opts * opts, dsd_state * state, uint8_t * payload void M17prepareStream(dsd_opts * opts, dsd_state * state, uint8_t * m17_bits) { - int i, k, x; + int i, k, x; uint8_t m17_punc[275]; //25 * 11 = 275 memset (m17_punc, 0, sizeof(m17_punc)); for (i = 0; i < 272; i++) @@ -604,7 +604,7 @@ void M17prepareStream(dsd_opts * opts, dsd_state * state, uint8_t * m17_bits) m17_depunc[k++] = m17_punc[x++]; m17_depunc[k++] = m17_punc[x++]; m17_depunc[k++] = m17_punc[x++]; - m17_depunc[k++] = 0; + m17_depunc[k++] = 0; } //setup the convolutional decoder @@ -618,7 +618,7 @@ void M17prepareStream(dsd_opts * opts, dsd_state * state, uint8_t * m17_bits) memset (m_data, 0, sizeof (m_data)); for (i = 0; i < 296; i++) - temp[i] = m17_depunc[i] << 1; + temp[i] = m17_depunc[i] << 1; CNXDNConvolution_start(); for (i = 0; i < 148; i++) @@ -677,7 +677,7 @@ void M17prepareStream(dsd_opts * opts, dsd_state * state, uint8_t * m17_bits) if (opts->payload == 1 && state->m17_str_dt < 2) { fprintf (stderr, "\n STREAM: "); - for (i = 0; i < 18; i++) + for (i = 0; i < 18; i++) fprintf (stderr, "[%02X]", (uint8_t)ConvertBitIntoBytes(&trellis_buf[i*8], 8)); } @@ -746,7 +746,7 @@ void processM17LSF(dsd_opts * opts, dsd_state * state) //NOTE: Works now with decisions based on previous bit, but still //not quite as good as it needs to be, need better decision making on the punctured bit - + int i, j, k, x; uint8_t dbuf[184]; //384-bit frame - 16-bit (8 symbol) sync pattern (184 dibits) uint8_t m17_rnd_bits[368]; //368 bits that are still scrambled (randomized) @@ -809,7 +809,7 @@ void processM17LSF(dsd_opts * opts, dsd_state * state) else m17_depunc[x++] = 0; } - + if (k == 61) k = 0; //61 -- should reset 8 times againt the array @@ -839,7 +839,7 @@ void processM17LSF(dsd_opts * opts, dsd_state * state) memset (m_data, 0, sizeof (m_data)); for (i = 0; i < 488; i++) - temp[i] = m17_depunc[i] << 1; + temp[i] = m17_depunc[i] << 1; CNXDNConvolution_start(); for (i = 0; i < 244; i++) @@ -896,7 +896,7 @@ void processM17LSF(dsd_opts * opts, dsd_state * state) } fprintf (stderr, " (CRC CHK) E: %04X; C: %04X;", crc_ext, crc_cmp); } - + if (crc_err == 1) fprintf (stderr, " CRC ERR"); //ending linebreak @@ -958,7 +958,7 @@ void processM17LSF_debug(dsd_opts * opts, dsd_state * state, uint8_t * m17_rnd_b else m17_depunc[x++] = 0; } - + if (k == 61) k = 0; //61 -- should reset 8 times againt the array @@ -975,7 +975,7 @@ void processM17LSF_debug(dsd_opts * opts, dsd_state * state, uint8_t * m17_rnd_b memset (m_data, 0, sizeof (m_data)); for (i = 0; i < 488; i++) - temp[i] = m17_depunc[i] << 1; + temp[i] = m17_depunc[i] << 1; CNXDNConvolution_start(); for (i = 0; i < 244; i++) @@ -1361,11 +1361,11 @@ void encodeM17RF (dsd_opts * opts, dsd_state * state, uint8_t * input, int type) for (i = 0; i < 1920; i++) baseband[i] = output_up[i] * 7168.0f; } - + //version w/ filtering lifted from M17_Implementations / libM17 else if (opts->use_cosine_filter == 1) { - + float mac = 0.0f; x = 0; for (i = 0; i < 192; i++) @@ -1429,7 +1429,7 @@ void encodeM17RF (dsd_opts * opts, dsd_state * state, uint8_t * input, int type) //Pulse Audio if (opts->audio_out_type == 0) pa_simple_write(opts->pulse_raw_dev_out, baseband, 1920*2, NULL); - + //UDP if (opts->audio_out_type == 8) udp_socket_blasterA (opts, state, 1920*2, baseband); @@ -1439,7 +1439,7 @@ void encodeM17RF (dsd_opts * opts, dsd_state * state, uint8_t * input, int type) write (opts->audio_out_fd, baseband, 1920*2); } - + //if we have a raw signal wav file, write to it now if (opts->wav_out_raw != NULL) { @@ -1471,7 +1471,7 @@ void encodeM17STR(dsd_opts * opts, dsd_state * state) //Enable frame, TX and Ncurses Printer opts->frame_m17 = 1; state->m17encoder_tx = 1; - + if (opts->use_ncurses_terminal == 1) ncursesOpen(opts, state); @@ -1509,7 +1509,7 @@ void encodeM17STR(dsd_opts * opts, dsd_state * state) if (strcmp (d40, "ALL") == 0) dst = 0xFFFFFFFFFFFF; //end - + int i, j, k, x; //basic utility counters short sample = 0; //individual audio sample from source size_t nsam = 160; //number of samples to be read in (default is 160 samples for codec2 3200 bps) @@ -1594,7 +1594,7 @@ void encodeM17STR(dsd_opts * opts, dsd_state * state) short voice1[nsam]; //read in xxx ms of audio from input source short voice2[nsam]; //read in xxx ms of audio from input source - + //frame sequence number and eot bit uint16_t fsn = 0; uint8_t eot = 0; @@ -1675,7 +1675,7 @@ void encodeM17STR(dsd_opts * opts, dsd_state * state) udp_return = m17_socket_blaster (opts, state, 11, conn); //TODO: Read UDP ACKN/NACK value, disable use_ip if NULL or nack return - + //load dst and src values into the LSF for (i = 0; i < 48; i++) m17_lsf[i] = (dst >> (47ULL-(unsigned long long int)i)) & 1; for (i = 0; i < 48; i++) m17_lsf[i+48] = (src >> (47ULL-(unsigned long long int)i)) & 1; @@ -1943,7 +1943,7 @@ void encodeM17STR(dsd_opts * opts, dsd_state * state) if (st == 2) hpf (state, voice2, 160); } - + //passband filter if (opts->use_pbf == 1) { @@ -1991,7 +1991,7 @@ void encodeM17STR(dsd_opts * opts, dsd_state * state) //Fill vc2_bytes with arbitrary data, UTF-8 chars (up to 48) if (st == 3) memcpy (vc2_bytes, state->m17sms+(lich_cnt*8), 8); - + //initialize and start assembling the completed frame //Data/Voice Portion of Stream Data Link Layer w/ FSN @@ -2040,7 +2040,7 @@ void encodeM17STR(dsd_opts * opts, dsd_state * state) //tally consecutive squelch hits based on RMS value, or reset if (opts->rtl_rms > opts->rtl_squelch_level) sql_hit = 0; - else sql_hit++; //may eventually roll over to 0 again + else sql_hit++; //may eventually roll over to 0 again //if vox enabled, toggle tx/eot with sql_hit comparison if (state->m17_vox == 1) @@ -2081,7 +2081,7 @@ void encodeM17STR(dsd_opts * opts, dsd_state * state) m17_v1p[k++] = m17_v1c[x++]; m17_v1p[k++] = m17_v1c[x++]; m17_v1p[k++] = m17_v1c[x++]; - //quit early on last set of i when 272 k bits reached + //quit early on last set of i when 272 k bits reached //index from 0 to 271,so 272 is breakpoint with k++ if (k == 272) break; m17_v1p[k++] = m17_v1c[x++]; @@ -2189,7 +2189,7 @@ void encodeM17STR(dsd_opts * opts, dsd_state * state) //convert bit array into symbols and RF/Audio encodeM17RF (opts, state, m17_t4s, 2); - + //Contruct an IP frame using previously created arrays memset (m17_ip_frame, 0, sizeof(m17_ip_frame)); memset (m17_ip_packed, 0, sizeof(m17_ip_packed)); @@ -2236,7 +2236,7 @@ void encodeM17STR(dsd_opts * opts, dsd_state * state) //add CRC value to the ip frame for (i = 0; i < 16; i++) m17_ip_frame[k++] = (ip_crc >> (15-i))&1; - + //pack CRC into the byte array as well for (i = 52; i < 54; i++) m17_ip_packed[i] = (uint8_t)ConvertBitIntoBytes(&m17_ip_frame[i*8], 8); @@ -2319,7 +2319,7 @@ void encodeM17STR(dsd_opts * opts, dsd_state * state) for (i = 52; i < 54; i++) m17_ip_packed[i] = (uint8_t)ConvertBitIntoBytes(&m17_ip_frame[i*8], 8); - //reset + //reset lich_cnt = 0; fsn = 0; state->carrier = 0; @@ -2465,7 +2465,7 @@ void encodeM17STR(dsd_opts * opts, dsd_state * state) //refresh ncurses printer, if enabled if (opts->use_ncurses_terminal == 1) ncursesPrinter(opts, state); - + } //SEND EOTX to reflector @@ -2475,7 +2475,7 @@ void encodeM17STR(dsd_opts * opts, dsd_state * state) //SEND DISC to reflector if (use_ip == 1) udp_return = m17_socket_blaster (opts, state, 10, disc); - + //free allocated memory free(samp1); free(samp2); @@ -2491,7 +2491,7 @@ void encodeM17BRT(dsd_opts * opts, dsd_state * state) //NOTE: BERT will not use the nucrses terminal, //just strictly for making a BERT test signal - + uint8_t nil[368]; //empty array memset (nil, 0, sizeof(nil)); @@ -2548,7 +2548,7 @@ void encodeM17BRT(dsd_opts * opts, dsd_state * state) m17_b2p[k++] = m17_b1c[x++]; m17_b2p[k++] = m17_b1c[x++]; m17_b2p[k++] = m17_b1c[x++]; - //quit early on last set of i when 368 k bits reached + //quit early on last set of i when 368 k bits reached //index from 0 to 367,so 368 is breakpoint with k++ if (k == 368) break; m17_b2p[k++] = m17_b1c[x++]; @@ -2590,7 +2590,7 @@ void encodeM17BRT(dsd_opts * opts, dsd_state * state) //reverse the sequence and shift so it appears correct on display for (i = 0; i < 197; i++) m17_b1r[i+3] = m17_b1[196-i]; - + //Dump Output of the BERT array (reversed and shifted sequence) for (i = 0; i < 25; i++) fprintf (stderr, "%02X", (uint8_t)ConvertBitIntoBytes(&m17_b1r[i*8], 8)); @@ -2802,7 +2802,7 @@ void encodeM17PKT(dsd_opts * opts, dsd_state * state) //load protocol value into first 8 bits k = 0; for (i = 0; i < 8; i++) - m17_p1_full[k++] = (protocol >> (7-i)) & 1; + m17_p1_full[k++] = (protocol >> (7-i)) & 1; //byte representation of a single string char uint8_t cbyte; @@ -2846,7 +2846,7 @@ void encodeM17PKT(dsd_opts * opts, dsd_state * state) if (cbyte == 0) break; //if terminator reached ptr++; //increment pointer - + //add line break to keep it under 80 columns if ( (i%71) == 0 && i != 0) @@ -2870,7 +2870,7 @@ void encodeM17PKT(dsd_opts * opts, dsd_state * state) //sanity check block value // if (block > 31) block = 31; - + //debug position values // fprintf (stderr, "\nBLOCK: %02d; PAD: %02d; LST: %d; K: %04d; PTR: %04d;\n", block, pad, lst, k, ptr); @@ -3264,7 +3264,7 @@ void decodeM17PKT(dsd_opts * opts, dsd_state * state, uint8_t * input, int len) fprintf (stderr, " "); if (protocol == 0x80) //Meta - { + { //show Control Byte Len and Segment Values on Meta Text fprintf (stderr, "%d/%d; ", (input[1] >> 4), input[1] & 0xF); for (i = 2; i < len; i++) @@ -3292,7 +3292,7 @@ void decodeM17PKT(dsd_opts * opts, dsd_state * state, uint8_t * input, int len) //WIP PKT decoder void processM17PKT(dsd_opts * opts, dsd_state * state) { - + int i, x; uint8_t dbuf[184]; //384-bit (192 symbol) frame - 16-bit (8 symbol) sync pattern (184 dibits) uint8_t m17_int_bits[368]; //368 bits that are still interleaved @@ -3384,12 +3384,12 @@ void processM17PKT(dsd_opts * opts, dsd_state * state) //sanity check on total if (total < 0 && eot == 1) total = 0; //this is from a bad decode, and caused a core dump on total being a negative value - + int end = ptr + 25; //TODO: Fix this /* - 00:23:28 Sync: +M17 PREAMBLE + 00:23:28 Sync: +M17 PREAMBLE 00:23:28 Sync: +M17 PKT 00:23:28 Sync: +M17 PKT CNT: 00; LST: 01; EOT: 1;Segmentation fault (core dumped) <--negative total value calculated on this */ @@ -3441,7 +3441,7 @@ void processM17PKT(dsd_opts * opts, dsd_state * state) } fprintf (stderr, "\n CRC - C: %04X; E: %04X", crc_cmp, crc_ext); } - + //reset after processing memset (state->m17_pkt, 0, sizeof(state->m17_pkt)); state->m17_pbc_ct = 0; @@ -3503,7 +3503,7 @@ void processM17IPF(dsd_opts * opts, dsd_state * state) { //NOTE: blocking issue resolved with setsockopt in UDPBind - //NOTE: Using recvfrom seems to load MSB of array first, + //NOTE: Using recvfrom seems to load MSB of array first, //compared to having to push samples through it like with STDIN. err = m17_socket_receiver(opts, &ip_frame); @@ -3610,7 +3610,7 @@ void processM17IPF(dsd_opts * opts, dsd_state * state) { fprintf (stderr, "\n M17 IP CONN: "); - if (src == 0xFFFFFFFFFFFF) + if (src == 0xFFFFFFFFFFFF) fprintf (stderr, "UNKNOWN FFFFFFFFFFFF"); else if (src == 0) fprintf (stderr, "RESERVED %012llx", src); @@ -3643,7 +3643,7 @@ void processM17IPF(dsd_opts * opts, dsd_state * state) { fprintf (stderr, "\n M17 IP DISC: "); - if (src == 0xFFFFFFFFFFFF) + if (src == 0xFFFFFFFFFFFF) fprintf (stderr, "UNKNOWN FFFFFFFFFFFF"); else if (src == 0) fprintf (stderr, "RESERVED %012llx", src); @@ -3676,7 +3676,7 @@ void processM17IPF(dsd_opts * opts, dsd_state * state) { fprintf (stderr, "\n M17 IP EOTX: "); - if (src == 0xFFFFFFFFFFFF) + if (src == 0xFFFFFFFFFFFF) fprintf (stderr, "UNKNOWN FFFFFFFFFFFF"); else if (src == 0) fprintf (stderr, "RESERVED %012llx", src); @@ -3710,7 +3710,7 @@ void processM17IPF(dsd_opts * opts, dsd_state * state) { fprintf (stderr, "\n M17 IP PING: "); - if (src == 0xFFFFFFFFFFFF) + if (src == 0xFFFFFFFFFFFF) fprintf (stderr, "UNKNOWN FFFFFFFFFFFF"); else if (src == 0) fprintf (stderr, "RESERVED %012llx", src); @@ -3738,7 +3738,7 @@ void processM17IPF(dsd_opts * opts, dsd_state * state) { fprintf (stderr, "\n M17 IP PONG: "); - if (src == 0xFFFFFFFFFFFF) + if (src == 0xFFFFFFFFFFFF) fprintf (stderr, "UNKNOWN FFFFFFFFFFFF"); else if (src == 0) fprintf (stderr, "RESERVED %012llx", src); diff --git a/src/nxdn_deperm.c b/src/nxdn_deperm.c index 11d397a..06622dd 100644 --- a/src/nxdn_deperm.c +++ b/src/nxdn_deperm.c @@ -2,20 +2,20 @@ //Reworked portions from Osmocom OP25 /* -*- c++ -*- */ -/* +/* * NXDN Encoder/Decoder (C) Copyright 2019 Max H. Parke KA1RBI - * - * + * + * * This 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, or (at your option) * any later version. - * + * * This software 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 software; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -59,12 +59,12 @@ void nxdn_deperm_facch(dsd_opts * opts, dsd_state * state, uint8_t bits[144]) memset (deperm, 0, sizeof(deperm)); memset (depunc, 0, sizeof(depunc)); - for (int i=0; i<144; i++) - deperm[PERM_16_9[i]] = bits[i]; + for (int i=0; i<144; i++) + deperm[PERM_16_9[i]] = bits[i]; out = 0; for (int i=0; i<144; i+=3) { depunc[out++] = deperm[i+0]; - depunc[out++] = 0; + depunc[out++] = 0; depunc[out++] = deperm[i+1]; depunc[out++] = deperm[i+2]; } @@ -79,10 +79,10 @@ void nxdn_deperm_facch(dsd_opts * opts, dsd_state * state, uint8_t bits[144]) memset (trellis_buf, 0, sizeof(trellis_buf)); for (int i = 0; i < 192; i++) - temp[i] = depunc[i] << 1; + temp[i] = depunc[i] << 1; CNXDNConvolution_start(); - for (int i = 0; i < 96; i++) + for (int i = 0; i < 96; i++) { s0 = temp[(2*i)]; s1 = temp[(2*i)+1]; @@ -119,7 +119,7 @@ void nxdn_deperm_facch(dsd_opts * opts, dsd_state * state, uint8_t bits[144]) if (crc != check) { //debug - // fprintf (stderr, " Pass 2 "); + // fprintf (stderr, " Pass 2 "); crc = 1; check = 0; memset (trellis_buf, 0, sizeof(trellis_buf)); memset (m_data, 0, sizeof(m_data)); @@ -135,7 +135,7 @@ void nxdn_deperm_facch(dsd_opts * opts, dsd_state * state, uint8_t bits[144]) } } - if (crc == check) NXDN_Elements_Content_decode(opts, state, 1, trellis_buf); + if (crc == check) NXDN_Elements_Content_decode(opts, state, 1, trellis_buf); // else if (opts->aggressive_framesync == 0) NXDN_Elements_Content_decode(opts, state, 0, trellis_buf); if (opts->payload == 1) @@ -144,7 +144,7 @@ void nxdn_deperm_facch(dsd_opts * opts, dsd_state * state, uint8_t bits[144]) fprintf (stderr, " FACCH1 Payload "); for (int i = 0; i < 12; i++) { - fprintf (stderr, "[%02X]", m_data[i]); + fprintf (stderr, "[%02X]", m_data[i]); } if (crc != check && opts->payload == 1) { @@ -160,7 +160,7 @@ void nxdn_deperm_facch(dsd_opts * opts, dsd_state * state, uint8_t bits[144]) void nxdn_deperm_sacch(dsd_opts * opts, dsd_state * state, uint8_t bits[60]) { //see about initializing these variables - uint8_t deperm[60]; //60 + uint8_t deperm[60]; //60 uint8_t depunc[72]; //72 uint8_t trellis_buf[32]; //32 @@ -175,7 +175,7 @@ void nxdn_deperm_sacch(dsd_opts * opts, dsd_state * state, uint8_t bits[60]) int ran = 0; int part_of_frame = 0; - for (int i=0; i<60; i++) + for (int i=0; i<60; i++) deperm[PERM_12_5[i]] = bits[i]; for (int p=0; p<60; p+= 10) { depunc[o++] = deperm[p+0]; @@ -203,7 +203,7 @@ void nxdn_deperm_sacch(dsd_opts * opts, dsd_state * state, uint8_t bits[60]) memset (trellis_buf, 0, sizeof(trellis_buf)); for (int i = 0; i < 72; i++) - temp[i] = depunc[i] << 1; + temp[i] = depunc[i] << 1; CNXDNConvolution_start(); for (int i = 0; i < 36; i++) @@ -244,7 +244,7 @@ void nxdn_deperm_sacch(dsd_opts * opts, dsd_state * state, uint8_t bits[60]) if (crc != check) { //debug - // fprintf (stderr, " Pass 2 "); + // fprintf (stderr, " Pass 2 "); crc = 1; check = 0; memset (trellis_buf, 0, sizeof(trellis_buf)); memset (m_data, 0, sizeof(m_data)); @@ -280,21 +280,21 @@ void nxdn_deperm_sacch(dsd_opts * opts, dsd_state * state, uint8_t bits[60]) { ran = (trellis_buf[2] << 5) | (trellis_buf[3] << 4) | (trellis_buf[4] << 3) | (trellis_buf[5] << 2) | (trellis_buf[6] << 1) | trellis_buf[7]; state->nxdn_last_ran = ran; - } + } fprintf (stderr, "PF 1/1"); if (state->nxdn_cipher_type == 1 && state->R != 0) state->payload_miN = state->R; //reset scrambler seed else if (state->M == 1 && state->R != 0) state->payload_miN = state->R; //force reset scrambler seed - if (crc == check) NXDN_Elements_Content_decode(opts, state, 1, nsf_sacch); + if (crc == check) NXDN_Elements_Content_decode(opts, state, 1, nsf_sacch); // else if (opts->aggressive_framesync == 0) NXDN_Elements_Content_decode(opts, state, 0, nsf_sacch); - //I'm placing this here, my observation is that SACCH NSF + //I'm placing this here, my observation is that SACCH NSF //is almost always, if not always, just IDLE else fprintf (stderr, " IDLE"); if (opts->payload == 1) - { + { fprintf (stderr, "\n SACCH NSF "); for (int i = 0; i < 4; i++) { @@ -310,13 +310,13 @@ void nxdn_deperm_sacch(dsd_opts * opts, dsd_state * state, uint8_t bits[60]) } } - + //reset the sacch field -- Github Issue #118 memset (state->nxdn_sacch_frame_segment, 1, sizeof(state->nxdn_sacch_frame_segment)); memset (state->nxdn_sacch_frame_segcrc, 1, sizeof(state->nxdn_sacch_frame_segcrc)); } - + //If part of superframe, collect the fragments and send to NXDN_SACCH_Full_decode instead else if (state->nxdn_sacch_non_superframe == FALSE) { @@ -328,7 +328,7 @@ void nxdn_deperm_sacch(dsd_opts * opts, dsd_state * state, uint8_t bits[60]) else if (sf == 2) part_of_frame = 1; else if (sf == 1) part_of_frame = 2; else if (sf == 0) part_of_frame = 3; - else part_of_frame = 0; + else part_of_frame = 0; //needed for DES and AES state->nxdn_part_of_frame = part_of_frame; @@ -351,7 +351,7 @@ void nxdn_deperm_sacch(dsd_opts * opts, dsd_state * state, uint8_t bits[60]) // fprintf (stderr, " (CRC ERR)"); // fprintf (stderr, "%s", KNRM); // } - + //reset scrambler seed to key value on new superframe // if (part_of_frame == 0 && state->nxdn_cipher_type == 0x1) state->payload_miN = 0; @@ -396,7 +396,7 @@ void nxdn_deperm_sacch(dsd_opts * opts, dsd_state * state, uint8_t bits[60]) for (int i = 0; i < 18; i++) { sacch_segment = sacch_segment << 1; - sacch_segment = sacch_segment + trellis_buf[i+8]; + sacch_segment = sacch_segment + trellis_buf[i+8]; state->nxdn_sacch_frame_segment[part_of_frame][i] = trellis_buf[i+8]; } @@ -404,11 +404,11 @@ void nxdn_deperm_sacch(dsd_opts * opts, dsd_state * state, uint8_t bits[60]) if (part_of_frame == 3) { NXDN_SACCH_Full_decode (opts, state); - } + } if (opts->payload == 1) - { - fprintf (stderr, "\n"); + { + fprintf (stderr, "\n"); fprintf (stderr, " SACCH SF Segment #%d ", part_of_frame+1); for (int i = 0; i < 4; i++) { @@ -417,8 +417,8 @@ void nxdn_deperm_sacch(dsd_opts * opts, dsd_state * state, uint8_t bits[60]) if (crc != check) fprintf (stderr, " CRC ERR - %02X %02X", crc, check); } - } - + } + } void nxdn_deperm_facch2_udch(dsd_opts * opts, dsd_state * state, uint8_t bits[348], uint8_t type) @@ -452,7 +452,7 @@ void nxdn_deperm_facch2_udch(dsd_opts * opts, dsd_state * state, uint8_t bits[34 depunc[id++] = deperm[i*12+10]; depunc[id++] = deperm[i*12+11]; } - + //switch to the convolutional decoder uint8_t temp[406]; uint8_t s0; @@ -463,10 +463,10 @@ void nxdn_deperm_facch2_udch(dsd_opts * opts, dsd_state * state, uint8_t bits[34 memset (m_data, 0, sizeof (m_data)); for (int i = 0; i < 406; i++) - temp[i] = depunc[i] << 1; + temp[i] = depunc[i] << 1; CNXDNConvolution_start(); - for (int i = 0; i < 203; i++) + for (int i = 0; i < 203; i++) { s0 = temp[(2*i)]; s1 = temp[(2*i)+1]; @@ -475,7 +475,7 @@ void nxdn_deperm_facch2_udch(dsd_opts * opts, dsd_state * state, uint8_t bits[34 } //numerals seem okay now - CNXDNConvolution_chainback(m_data, 199); + CNXDNConvolution_chainback(m_data, 199); for(int i = 0; i < 26; i++) { @@ -504,7 +504,7 @@ void nxdn_deperm_facch2_udch(dsd_opts * opts, dsd_state * state, uint8_t bits[34 if (crc != check) { //debug - // fprintf (stderr, " Pass 2 "); + // fprintf (stderr, " Pass 2 "); crc = 1; check = 0; memset (trellis_buf, 0, sizeof(trellis_buf)); memset (m_data, 0, sizeof(m_data)); @@ -530,21 +530,21 @@ void nxdn_deperm_facch2_udch(dsd_opts * opts, dsd_state * state, uint8_t bits[34 //just going to leave this all here in case its needed, like in cac, //don't have any samples with f2 or udch data in it - for (int i = 0; i < 199-8-15; i++) + for (int i = 0; i < 199-8-15; i++) { - f2u_message_buffer[i] = trellis_buf[i+8]; + f2u_message_buffer[i] = trellis_buf[i+8]; } - + if (crc == check) - { + { if (type == 1) NXDN_Elements_Content_decode(opts, state, 1, f2u_message_buffer); if (type == 0) {} //need handling for user data (text messages and AVL) - } + } // else if (opts->aggressive_framesync == 0) // { // if (type == 1) NXDN_Elements_Content_decode(opts, state, 0, f2u_message_buffer); // if (type == 0) {} //need handling for user data (text messages and AVL) - // } + // } if (type == 0 && crc == check) { @@ -580,9 +580,9 @@ void nxdn_deperm_facch2_udch(dsd_opts * opts, dsd_state * state, uint8_t bits[34 for (int i = 0; i < 26; i++) { if (i == 13) fprintf (stderr, "\n "); - fprintf (stderr, "[%02X]", m_data[i]); + fprintf (stderr, "[%02X]", m_data[i]); } - + if (crc != check) { fprintf (stderr, "%s", KRED); @@ -604,7 +604,7 @@ void nxdn_deperm_facch2_udch(dsd_opts * opts, dsd_state * state, uint8_t bits[34 // else fprintf (stderr, " "); // } // } - } + } } static int cac_fail = 0; @@ -650,7 +650,7 @@ void nxdn_deperm_cac(dsd_opts * opts, dsd_state * state, uint8_t bits[300]) memset (m_data, 0, sizeof (m_data)); for (int i = 0; i < 350; i++) - temp[i] = depunc[i] << 1; + temp[i] = depunc[i] << 1; CNXDNConvolution_start(); for (int i = 0; i < 175; i++) //179 @@ -675,7 +675,7 @@ void nxdn_deperm_cac(dsd_opts * opts, dsd_state * state, uint8_t bits[300]) trellis_buf[(i*8)+7] = (m_data[i] >> 0) & 1; } - crc = crc16cac(trellis_buf, 171); + crc = crc16cac(trellis_buf, 171); //debug // if (crc == 0) @@ -684,7 +684,7 @@ void nxdn_deperm_cac(dsd_opts * opts, dsd_state * state, uint8_t bits[300]) if (crc != 0) { //debug - // fprintf (stderr, " Pass 2 "); + // fprintf (stderr, " Pass 2 "); memset (trellis_buf, 0, sizeof(trellis_buf)); memset (m_data, 0, sizeof(m_data)); trellis_decode(trellis_buf, depunc, 171); @@ -710,7 +710,7 @@ void nxdn_deperm_cac(dsd_opts * opts, dsd_state * state, uint8_t bits[300]) { ran = (trellis_buf[2] << 5) | (trellis_buf[3] << 4) | (trellis_buf[4] << 3) | (trellis_buf[5] << 2) | (trellis_buf[6] << 1) | trellis_buf[7]; state->nxdn_last_ran = ran; - } + } fprintf (stderr, "%s", KYEL); fprintf (stderr, " CAC"); @@ -723,7 +723,7 @@ void nxdn_deperm_cac(dsd_opts * opts, dsd_state * state, uint8_t bits[300]) fprintf (stderr, "%s", KNRM); } - //check for accumulative cac failures and reset if multiple errors pile up + //check for accumulative cac failures and reset if multiple errors pile up //(LZ issue and also issue very occasssionally noticed on remote) if (crc != 0) cac_fail++; else cac_fail = 0; @@ -767,7 +767,7 @@ void nxdn_deperm_cac(dsd_opts * opts, dsd_state * state, uint8_t bits[300]) } if (crc == 0) NXDN_Elements_Content_decode(opts, state, 1, cac_message_buffer); - // else if (opts->aggressive_framesync == 0) NXDN_Elements_Content_decode(opts, state, 0, cac_message_buffer); + // else if (opts->aggressive_framesync == 0) NXDN_Elements_Content_decode(opts, state, 0, cac_message_buffer); if (opts->payload == 1) { @@ -775,23 +775,23 @@ void nxdn_deperm_cac(dsd_opts * opts, dsd_state * state, uint8_t bits[300]) fprintf (stderr, " CAC Payload\n "); for (int i = 0; i < 22; i++) { - fprintf (stderr, "[%02X]", m_data[i]); + fprintf (stderr, "[%02X]", m_data[i]); if (i == 10) fprintf (stderr, "\n "); } // if (crc != 0) fprintf (stderr, " CRC ERR "); - } + } } -//Type-D "IDAS" +//Type-D "IDAS" void nxdn_deperm_scch(dsd_opts * opts, dsd_state * state, uint8_t bits[60], uint8_t direction) { fprintf (stderr, "%s", KYEL); fprintf (stderr, " SCCH"); //see about initializing these variables - uint8_t deperm[60]; //60 + uint8_t deperm[60]; //60 uint8_t depunc[72]; //72 uint8_t trellis_buf[32]; //32 @@ -805,7 +805,7 @@ void nxdn_deperm_scch(dsd_opts * opts, dsd_state * state, uint8_t bits[60], uint int sf = 0; int part_of_frame = 0; - for (int i=0; i<60; i++) + for (int i=0; i<60; i++) deperm[PERM_12_5[i]] = bits[i]; for (int p=0; p<60; p+= 10) { depunc[o++] = deperm[p+0]; @@ -833,10 +833,10 @@ void nxdn_deperm_scch(dsd_opts * opts, dsd_state * state, uint8_t bits[60], uint memset (trellis_buf, 0, sizeof(trellis_buf)); for (int i = 0; i < 72; i++) - temp[i] = depunc[i] << 1; + temp[i] = depunc[i] << 1; CNXDNConvolution_start(); - for (int i = 0; i < 36; i++) + for (int i = 0; i < 36; i++) { s0 = temp[(2*i)]; s1 = temp[(2*i)+1]; @@ -873,7 +873,7 @@ void nxdn_deperm_scch(dsd_opts * opts, dsd_state * state, uint8_t bits[60], uint if (crc != check) { //debug - // fprintf (stderr, " Pass 2 "); + // fprintf (stderr, " Pass 2 "); crc = 1; check = 0; memset (trellis_buf, 0, sizeof(trellis_buf)); memset (m_data, 0, sizeof(m_data)); @@ -895,7 +895,7 @@ void nxdn_deperm_scch(dsd_opts * opts, dsd_state * state, uint8_t bits[60], uint else if (sf == 2) part_of_frame = 1; else if (sf == 1) part_of_frame = 2; else if (sf == 0) part_of_frame = 3; - else part_of_frame = 0; + else part_of_frame = 0; //reset scrambler seed to key value on new superframe // if (part_of_frame == 0 && state->nxdn_cipher_type == 0x1) state->payload_miN = 0; @@ -920,8 +920,8 @@ void nxdn_deperm_scch(dsd_opts * opts, dsd_state * state, uint8_t bits[60], uint //English Translation: Superframe when voice, Non Superframe when not voice //What I've found is that by not using the superframe structure, and decoding each 'unit' - //individually instead, we can get more expedient decoding on elements without having to - //sacrifice an entire superframe for one bad CRC, also each element cleanly divides into a + //individually instead, we can get more expedient decoding on elements without having to + //sacrifice an entire superframe for one bad CRC, also each element cleanly divides into a //single 'unit' except for enc parms IV, which can be stored seperately if needed //NOTE: scch has its own message format, and thus, doesn't go to content element decoding @@ -933,7 +933,7 @@ void nxdn_deperm_scch(dsd_opts * opts, dsd_state * state, uint8_t bits[60], uint fprintf (stderr, "%s", KNRM); if (opts->payload == 1) - { + { fprintf (stderr, "\n SCCH Payload "); for (int i = 0; i < 4; i++) { @@ -945,11 +945,11 @@ void nxdn_deperm_scch(dsd_opts * opts, dsd_state * state, uint8_t bits[60], uint fprintf (stderr, "%s", KRED); fprintf (stderr, " (CRC ERR)"); fprintf (stderr, "%s", KNRM); - } + } } fprintf (stderr, "%s", KNRM); - + } void nxdn_deperm_facch3_udch2(dsd_opts * opts, dsd_state * state, uint8_t bits[288], uint8_t type) @@ -980,21 +980,21 @@ void nxdn_deperm_facch3_udch2(dsd_opts * opts, dsd_state * state, uint8_t bits[2 for (int j=0; j<2; j++) { - for (int i=0; i<144; i++) - deperm[PERM_16_9[i]] = bits[i+(j*144)]; + for (int i=0; i<144; i++) + deperm[PERM_16_9[i]] = bits[i+(j*144)]; out = 0; for (int i=0; i<144; i+=3) { depunc[out++] = deperm[i+0]; - depunc[out++] = 0; + depunc[out++] = 0; depunc[out++] = deperm[i+1]; depunc[out++] = deperm[i+2]; } for (int i = 0; i < 192; i++) - temp[i] = depunc[i] << 1; + temp[i] = depunc[i] << 1; CNXDNConvolution_start(); - for (int i = 0; i < 96; i++) + for (int i = 0; i < 96; i++) { s0 = temp[(2*i)]; s1 = temp[(2*i)+1]; @@ -1021,7 +1021,7 @@ void nxdn_deperm_facch3_udch2(dsd_opts * opts, dsd_state * state, uint8_t bits[2 { check[j] = check[j] << 1; check[j] = check[j] | trellis_buf[84+i]; //84 - + } //debug @@ -1032,7 +1032,7 @@ void nxdn_deperm_facch3_udch2(dsd_opts * opts, dsd_state * state, uint8_t bits[2 if (crc[j] != check[j]) { //debug - // fprintf (stderr, "P:%d Pass 2 ", j); + // fprintf (stderr, "P:%d Pass 2 ", j); crc[j] = 1; check[j] = 0; memset (trellis_buf, 0, sizeof(trellis_buf)); memset (m_data, 0, sizeof(m_data)); @@ -1063,8 +1063,8 @@ void nxdn_deperm_facch3_udch2(dsd_opts * opts, dsd_state * state, uint8_t bits[2 { if (type == 1) NXDN_Elements_Content_decode(opts, state, 1, trellis_buf); if (type == 0) {} //need handling for user data (text messages and AVL) - } - // else if (opts->aggressive_framesync == 0) + } + // else if (opts->aggressive_framesync == 0) // { // if (type == 1) NXDN_Elements_Content_decode(opts, state, 0, trellis_buf); // if (type == 0) {} //need handling for user data (text messages and AVL) @@ -1111,7 +1111,7 @@ void nxdn_deperm_facch3_udch2(dsd_opts * opts, dsd_state * state, uint8_t bits[2 for (int i = 0; i < 24; i++) { if (i == 12) fprintf (stderr, "\n "); - fprintf (stderr, "[%02X]", f3_udch2_bytes[i]); + fprintf (stderr, "[%02X]", f3_udch2_bytes[i]); } if ( (crc[0] != check[0] || crc[1] != check[1]) && opts->payload == 1) @@ -1138,7 +1138,7 @@ void nxdn_deperm_facch3_udch2(dsd_opts * opts, dsd_state * state, uint8_t bits[2 // else fprintf (stderr, " "); // } // } - + } } @@ -1181,7 +1181,7 @@ void nxdn_message_type (dsd_opts * opts, dsd_state * state, uint8_t MessageType) else if (MessageType == 0x38) fprintf(stderr, " SDCALL_REQ_HEADER"); else if (MessageType == 0x39) fprintf(stderr, " SDCALL_REQ_USERDATA"); else if (MessageType == 0x3B) fprintf(stderr, " SDCALL_RESP"); - else if (MessageType == 0x3F) fprintf(stderr, " ALIAS"); + else if (MessageType == 0x3F) fprintf(stderr, " ALIAS"); else fprintf(stderr, " Unknown M-%02X", MessageType); fprintf (stderr, "%s", KNRM); @@ -1204,7 +1204,7 @@ void nxdn_message_type (dsd_opts * opts, dsd_state * state, uint8_t MessageType) if (opts->floating_point == 1) state->aout_gain = opts->audio_gain; } - + } //voice descrambler @@ -1309,7 +1309,7 @@ uint16_t crc16cac(const uint8_t buf[], int len) { uint32_t crc = 0xc3ee; //not sure why this though uint32_t poly = (1<<12) + (1<<5) + 1; //poly is fine - for (int i=0;inxdn_sacch_frame_segment[i], 18); - /* Check CRC */ + /* Check CRC */ if (state->nxdn_sacch_frame_segcrc[i] != 0) CrcCorrect = 0; } @@ -90,9 +90,9 @@ void NXDN_Elements_Content_decode(dsd_opts * opts, dsd_state * state, /* //Note: CAC Message with same Message Type -- This is a private call request and rejection (TODO: Seperate handling depending on CAC, FACCH< Sacch, etc) 20:56:15 Sync: NXDN96 RCCH Data RAN 01 CAC VCALL (VCALL_REQ) - Private Call - Half Duplex 9600bps/EHR (02) - Src=211 - Dst/TG=1603 + Private Call - Half Duplex 9600bps/EHR (02) - Src=211 - Dst/TG=1603 20:56:15 Sync: NXDN96 RCCH Data RAN 01 CAC DISC (VCALL_REJECTION) - Private Call - Disconnect - Src=1603 - Dst/TG=211 + Private Call - Disconnect - Src=1603 - Dst/TG=211 */ //Debug: Disable DUP messages if they cause random issues with Type-C trunking (i.e. changing SRC ang TGT IDs, hopping in the middle of calls, etc) @@ -107,7 +107,7 @@ void NXDN_Elements_Content_decode(dsd_opts * opts, dsd_state * state, case 0x04: //DCALL_ASSGN - case 0x0E: + case 0x0E: NXDN_decode_VCALL_ASSGN(opts, state, ElementsContent); break; @@ -166,14 +166,14 @@ void NXDN_Elements_Content_decode(dsd_opts * opts, dsd_state * state, memset(state->active_channel, 0, sizeof(state->active_channel)); opts->p25_is_tuned = 0; if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); - SetFreq(opts->rigctl_sockfd, state->p25_cc_freq); + SetFreq(opts->rigctl_sockfd, state->p25_cc_freq); state->nxdn_last_rid = 0; state->nxdn_last_tg = 0; if (state->M == 0) state->nxdn_cipher_type = 0; sprintf (state->nxdn_call_type, "%s", ""); - + } //rtl else if (opts->audio_in_type == 3) @@ -205,7 +205,7 @@ void NXDN_Elements_Content_decode(dsd_opts * opts, dsd_state * state, break; //VCALL_IV - case 0x03: + case 0x03: NXDN_decode_VCALL_IV(opts, state, ElementsContent); break; @@ -222,28 +222,28 @@ void NXDN_Elements_Content_decode(dsd_opts * opts, dsd_state * state, void nxdn_location_id_handler (dsd_state * state, uint32_t location_id, uint8_t type) { //6.5.2 Location ID - uint8_t category_bit = location_id >> 22; + uint8_t category_bit = location_id >> 22; uint32_t sys_code = 0; uint16_t site_code = 0; - char category[14]; //G, R, or L + char category[14]; //G, R, or L if (category_bit == 0) { sys_code = ( (location_id & 0x3FFFFF) >> 12); //10 bits - site_code = location_id & 0x3FF; //12 bits + site_code = location_id & 0x3FF; //12 bits sprintf (category, "%s", "Global"); - } + } else if (category_bit == 2) { sys_code = ( (location_id & 0x3FFFFF) >> 8); //14 bits - site_code = location_id & 0xFF; //8 bits + site_code = location_id & 0xFF; //8 bits sprintf (category, "%s", "Regional"); - } + } else if (category_bit == 1) { sys_code = ( (location_id & 0x3FFFFF) >> 5); //17 bits - site_code = location_id & 0x1F; //5 bits + site_code = location_id & 0x1F; //5 bits sprintf (category, "%s", "Local"); } else @@ -256,11 +256,11 @@ void nxdn_location_id_handler (dsd_state * state, uint32_t location_id, uint8_t if (type == 0) { state->nxdn_last_ran = site_code % 64; //Table 6.3-4 RAN for Trunked Radio Systems - if (site_code != 0) state->nxdn_location_site_code = site_code; + if (site_code != 0) state->nxdn_location_site_code = site_code; if (sys_code != 0) state->nxdn_location_sys_code = sys_code; - sprintf (state->nxdn_location_category, "%s", category); - } - + sprintf (state->nxdn_location_category, "%s", category); + } + if (type == 0) fprintf (stderr, "\n Location Information - Cat: %s - Sys Code: %d - Site Code %d ", category, sys_code, site_code); else fprintf (stderr, "\n Adjacent Information - Cat: %s - Sys Code: %d - Site Code %d ", category, sys_code, site_code); @@ -310,7 +310,7 @@ void nxdn_rst_info_handler (dsd_state * state, uint32_t rst_info) //Access cycle interval (Octet 0, Bits 3 to 0) fprintf (stderr, " ACI:"); - uint8_t frames = (rst_info >> 16) & 0xF; + uint8_t frames = (rst_info >> 16) & 0xF; if (frames) fprintf (stderr, " %d Frame Restriction;", frames * 20); // else fprintf (stderr, " No Restriction;"); @@ -328,7 +328,7 @@ void nxdn_rst_info_handler (dsd_state * state, uint32_t rst_info) //Restriction group ratio specification (Octet 2, Bits 7 to 6) fprintf (stderr, " RT:"); - uint8_t ratio = (rst_info >> 22) & 0x3; + uint8_t ratio = (rst_info >> 22) & 0x3; if (ratio == 1) fprintf (stderr, " 50 Restriction;"); else if (ratio == 2) fprintf (stderr, " 75 Restriction;"); else if (ratio == 3) fprintf (stderr, " 87.5 Restriction;"); @@ -336,7 +336,7 @@ void nxdn_rst_info_handler (dsd_state * state, uint32_t rst_info) //Delay time extension specification (Octet 2, Bits 5 to 4) fprintf (stderr, " DT:"); - uint8_t dt = (rst_info >> 20) & 0x3; + uint8_t dt = (rst_info >> 20) & 0x3; if (dt == 0) fprintf (stderr, " Timer T2 max x 1;"); else if (dt == 1) fprintf (stderr, " Timer T2 max x 2;"); else if (dt == 2) fprintf (stderr, " Timer T2 max x 3;"); @@ -363,10 +363,10 @@ void nxdn_ca_info_handler (dsd_state * state, uint32_t ca_info) //set state variable here to tell us to use DFA or Channel Versions if (RCN == 1) { - state->nxdn_rcn = RCN; + state->nxdn_rcn = RCN; state->nxdn_step = step; state->nxdn_base_freq = base; - } + } } @@ -428,7 +428,7 @@ void NXDN_decode_VCALL_ASSGN(dsd_opts * opts, dsd_state * state, uint8_t * Messa state->NxdnElementsContent.DestinationID = DestinationID; /* Decode "Call Timer" */ //unsure of format of call timer, not required info for trunking - CallTimer = (uint8_t)ConvertBitIntoBytes(&Message[56], 6); + CallTimer = (uint8_t)ConvertBitIntoBytes(&Message[56], 6); /* Decode "Channel" */ Channel = (uint16_t)ConvertBitIntoBytes(&Message[62], 10); @@ -436,7 +436,7 @@ void NXDN_decode_VCALL_ASSGN(dsd_opts * opts, dsd_state * state, uint8_t * Messa /* Decode DFA-only variables*/ if (state->nxdn_rcn == 1) { - bw = (uint8_t)ConvertBitIntoBytes(&Message[62], 2); + bw = (uint8_t)ConvertBitIntoBytes(&Message[62], 2); OFN = (uint16_t)ConvertBitIntoBytes(&Message[64], 16); IFN = (uint16_t)ConvertBitIntoBytes(&Message[80], 16); } @@ -445,7 +445,7 @@ void NXDN_decode_VCALL_ASSGN(dsd_opts * opts, dsd_state * state, uint8_t * Messa //While I've only seen Busy Repeater Message on the SCCH message (different format) //The manual suggests this message exists on Type-D systems with this configuration - //On Type-D systems, need to truncate to an 11-bit value + //On Type-D systems, need to truncate to an 11-bit value //other 5-bits are repeater or prefix value // uint8_t idas = 0; // uint8_t rep1 = 0; @@ -457,12 +457,12 @@ void NXDN_decode_VCALL_ASSGN(dsd_opts * opts, dsd_state * state, uint8_t * Messa // rep2 = (DestinationID >> 11) & 0x1F; // SourceUnitID = SourceUnitID & 0x7FF; // DestinationID = DestinationID & 0x7FF; - // //assign source prefix/rep1 as the tune to channel? + // //assign source prefix/rep1 as the tune to channel? // //In normal VCALL, both prefix/rep values are the same on the Type-D samples I have - // Channel = rep1; + // Channel = rep1; // } - - if (MessageType == 0x4 || MessageType == 0x5) + + if (MessageType == 0x4 || MessageType == 0x5) fprintf (stderr, "%s", KGRN); //VCALL_ASSGN else fprintf (stderr, "%s", KCYN); //DCALL_ASSGN @@ -474,7 +474,7 @@ void NXDN_decode_VCALL_ASSGN(dsd_opts * opts, dsd_state * state, uint8_t * Messa if(CCOption & 0x20) fprintf(stderr, "Priority Paging "); /* Print the "Call Type" */ - fprintf(stderr, "%s - ", NXDN_Call_Type_To_Str(CallType)); + fprintf(stderr, "%s - ", NXDN_Call_Type_To_Str(CallType)); /* Print the "Voice Call Option" */ if (MessageType == 0x4 || MessageType == 0x5) NXDN_Voice_Call_Option_To_Str(VoiceCallOption, DuplexMode, TransmissionMode); @@ -490,14 +490,14 @@ void NXDN_decode_VCALL_ASSGN(dsd_opts * opts, dsd_state * state, uint8_t * Messa /* Print Channel */ if (state->nxdn_rcn == 0) fprintf(stderr, "- Channel [%03X][%04d] ", Channel & 0x3FF, Channel & 0x3FF); - if (state->nxdn_rcn == 1) + if (state->nxdn_rcn == 1) fprintf(stderr, "- DFA Channel [%04X][%05d] ", OFN, OFN); //test VCALL_ASSGN_DUP, if no voice sync activity (by trunk_hangtime), then convert to assgn and allow tuning //VCALL_ASSGN_DUP has been seen in the middle of calls, but also on the tail end instead of a TX_REL or DISC if (MessageType == 0x5 && opts->p25_is_tuned == 1 && opts->p25_trunk == 1) { - if ( (time(NULL) - state->last_vc_sync_time) > opts->trunk_hangtime ) + if ( (time(NULL) - state->last_vc_sync_time) > opts->trunk_hangtime ) { MessageType = 0x04; //convert to VCALL opts->p25_is_tuned = 0; //open tuning back up to tune @@ -507,7 +507,7 @@ void NXDN_decode_VCALL_ASSGN(dsd_opts * opts, dsd_state * state, uint8_t * Messa //TG Hold during VCALL_ASSGN_DUP, allow tuning to TG hold channel assignment if (MessageType == 0x5 && opts->p25_is_tuned == 1 && opts->p25_trunk == 1) { - if ( state->tg_hold != 0 && state->tg_hold == DestinationID ) + if ( state->tg_hold != 0 && state->tg_hold == DestinationID ) { MessageType = 0x04; //convert to VCALL // opts->p25_is_tuned = 0; //open tuning back up to tune @@ -544,10 +544,10 @@ void NXDN_decode_VCALL_ASSGN(dsd_opts * opts, dsd_state * state, uint8_t * Messa } if (tune == 0) goto END_ASSGN; - + //run process to figure out frequency value from the channel import or from DFA long int freq = 0; - if (state->nxdn_rcn == 0) + if (state->nxdn_rcn == 0) freq = nxdn_channel_to_frequency(opts, state, Channel); if (state->nxdn_rcn == 1) freq = nxdn_channel_to_frequency(opts, state, OFN); @@ -556,7 +556,7 @@ void NXDN_decode_VCALL_ASSGN(dsd_opts * opts, dsd_state * state, uint8_t * Messa if (opts->p25_trunk == 1 && state->p25_cc_freq == 0) { long int ccfreq = 0; - + //if not available, then poll rigctl if its available if (opts->use_rigctl == 1) { @@ -613,7 +613,7 @@ void NXDN_decode_VCALL_ASSGN(dsd_opts * opts, dsd_state * state, uint8_t * Messa //TG hold on NXDN -- block non-matching target, allow matching DestinationID if (state->tg_hold != 0 && state->tg_hold != DestinationID) sprintf (mode, "%s", "B"); - if (state->tg_hold != 0 && state->tg_hold == DestinationID) + if (state->tg_hold != 0 && state->tg_hold == DestinationID) { sprintf (mode, "%s", "A"); opts->p25_is_tuned = 0; //unlock tuner at this stage and not above check @@ -630,11 +630,11 @@ void NXDN_decode_VCALL_ASSGN(dsd_opts * opts, dsd_state * state, uint8_t * Messa //extra safeguards due to sync issues with NXDN memset (state->nxdn_sacch_frame_segment, 1, sizeof(state->nxdn_sacch_frame_segment)); memset (state->nxdn_sacch_frame_segcrc, 1, sizeof(state->nxdn_sacch_frame_segcrc)); - state->lastsynctype = -1; + state->lastsynctype = -1; state->last_cc_sync_time = time(NULL); state->last_vc_sync_time = time(NULL); // - + if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); SetFreq(opts->rigctl_sockfd, freq); state->p25_vc_freq[0] = state->p25_vc_freq[1] = freq; @@ -659,7 +659,7 @@ void NXDN_decode_VCALL_ASSGN(dsd_opts * opts, dsd_state * state, uint8_t * Messa fprintf (stderr, " %s", KYEL); fprintf (stderr, " Key Loaded: %lld", state->rkey_array[DestinationID]); state->payload_miN = state->R; //should be okay to load here, will test - } + } if (state->M == 1) state->nxdn_cipher_type = 0x1; } //rtl @@ -669,19 +669,19 @@ void NXDN_decode_VCALL_ASSGN(dsd_opts * opts, dsd_state * state, uint8_t * Messa //extra safeguards due to sync issues with NXDN memset (state->nxdn_sacch_frame_segment, 1, sizeof(state->nxdn_sacch_frame_segment)); memset (state->nxdn_sacch_frame_segcrc, 1, sizeof(state->nxdn_sacch_frame_segcrc)); - state->lastsynctype = -1; + state->lastsynctype = -1; state->last_cc_sync_time = time(NULL); state->last_vc_sync_time = time(NULL); // - rtl_dev_tune (opts, freq); + rtl_dev_tune (opts, freq); state->p25_vc_freq[0] = state->p25_vc_freq[1] = freq; opts->p25_is_tuned = 1; //set rid and tg when we actually tune to it //only assign rid if not spare and not reserved (happens on private calls, unsure of its significance) if ( (VoiceCallOption & 0xF) < 4) //ideally, only want 0, 2, or 3 - state->nxdn_last_rid = SourceUnitID; + state->nxdn_last_rid = SourceUnitID; state->nxdn_last_tg = DestinationID; sprintf (state->nxdn_call_type, "%s", NXDN_Call_Type_To_Str(CallType)); @@ -701,8 +701,8 @@ void NXDN_decode_VCALL_ASSGN(dsd_opts * opts, dsd_state * state, uint8_t * Messa if (state->M == 1) state->nxdn_cipher_type = 0x1; #endif } - - } + + } } END_ASSGN: ; //do nothing @@ -718,19 +718,19 @@ void NXDN_decode_Alias(dsd_opts * opts, dsd_state * state, uint8_t * Message) uint8_t Alias2 = 0x20; uint8_t Alias3 = 0x20; uint8_t Alias4 = 0x20; - uint8_t blocknumber = 0; + uint8_t blocknumber = 0; uint8_t total = 0; uint8_t unk1 = 0; uint8_t unk2 = 0; uint8_t CrcCorrect = 0; - + //alias can also hit on a facch1 -- do we still need this checkdown? if (state->nxdn_sacch_non_superframe == FALSE) { CrcCorrect = state->NxdnElementsContent.VCallCrcIsGood; } else CrcCorrect = 1; //FACCH1 with bad CRC won't make it this far anyways, so set as 1 - + //FACCH Payload [3F][68][82][04][2 <- block number4] "[69][6F][6E][20]" <- 4 alias octets [00][7F][1C] blocknumber = (uint8_t)ConvertBitIntoBytes(&Message[32], 4) & 0x7; // & 0x7, might just be three bits, unsure @@ -790,14 +790,14 @@ void NXDN_decode_Alias(dsd_opts * opts, dsd_state * state, uint8_t * Message) //crc errs in one repitition may occlude an otherwise good alias, so test and change if needed //completed alias should still appear in ncurses terminal regardless, so this may be okay - if (CrcCorrect) - { + if (CrcCorrect) + { fprintf (stderr, " "); //spacer for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { - fprintf (stderr, "%s", state->nxdn_alias_block_segment[i][j]); + fprintf (stderr, "%s", state->nxdn_alias_block_segment[i][j]); } } fprintf (stderr, " "); @@ -816,7 +816,7 @@ void NXDN_decode_cch_info(dsd_opts * opts, dsd_state * state, uint8_t * Message) long int freq1 = 0; long int freq2 = 0; UNUSED2(channel2sts, freq2); - + //DFA uint8_t bw1 = 0; uint16_t OFN1 = 0; @@ -849,7 +849,7 @@ void NXDN_decode_cch_info(dsd_opts * opts, dsd_state * state, uint8_t * Message) freq1 = nxdn_channel_to_frequency (opts, state, channel1); freq2 = nxdn_channel_to_frequency (opts, state, channel2); } - + //DFA version if (state->nxdn_rcn == 1) { @@ -898,7 +898,7 @@ void NXDN_decode_cch_info(dsd_opts * opts, dsd_state * state, uint8_t * Message) } } - + fprintf (stderr, "%s", KNRM); } @@ -982,7 +982,7 @@ void NXDN_decode_site_info(dsd_opts * opts, dsd_state * state, uint8_t * Message nxdn_ca_info_handler (state, ca_info); fprintf (stderr, "%s", KYEL); - fprintf (stderr, "\n Location ID [%06X] CSC [%04X] SVC [%04X] RST [%06X] \n CA [%06X] V[%X] ADJ [%01X] ", + fprintf (stderr, "\n Location ID [%06X] CSC [%04X] SVC [%04X] RST [%06X] \n CA [%06X] V[%X] ADJ [%01X] ", location_id, cs_info, svc_info, rst_info, ca_info, version_num, adj_alloc); nxdn_location_id_handler(state, location_id, 0); @@ -1022,7 +1022,7 @@ void NXDN_decode_adj_site(dsd_opts * opts, dsd_state * state, uint8_t * Message) //will want to monitor this PDU for potential overflow related issues with the Message or ElementContent size //up to four adj_site_location_ids can be conveyed -- see 6.4.3.4 for more information - uint32_t adj1_site = 0; + uint32_t adj1_site = 0; uint32_t adj2_site = 0; uint32_t adj3_site = 0; //options -- 6.5.38. Adjacent Site Option -- 4 LSB are Site Number, 2 MSB are spares @@ -1193,7 +1193,7 @@ void NXDN_decode_VCALL(dsd_opts * opts, dsd_state * state, uint8_t * Message) DestinationID = (uint16_t)ConvertBitIntoBytes(&Message[40], 16); state->NxdnElementsContent.DestinationID = DestinationID; - //On Type-D systems, need to truncate to an 11-bit value + //On Type-D systems, need to truncate to an 11-bit value //other 5-bits are repeater or prefix value uint8_t idas = 0; uint8_t rep1 = 0; @@ -1240,7 +1240,7 @@ void NXDN_decode_VCALL(dsd_opts * opts, dsd_state * state, uint8_t * Message) } /* Print the "Call Type" */ - fprintf (stderr, "%s - ", NXDN_Call_Type_To_Str(CallType)); + fprintf (stderr, "%s - ", NXDN_Call_Type_To_Str(CallType)); sprintf (state->nxdn_call_type, "%s", NXDN_Call_Type_To_Str(CallType)); /* Print the "Voice Call Option" */ @@ -1311,7 +1311,7 @@ void NXDN_decode_VCALL(dsd_opts * opts, dsd_state * state, uint8_t * Message) { //only assign rid if not spare and not reserved (happens on private calls, unsure of its significance) if ( (VoiceCallOption & 0xF) < 4) //ideally, only want 0, 2, or 3 - state->nxdn_last_rid = SourceUnitID; + state->nxdn_last_rid = SourceUnitID; state->nxdn_last_tg = DestinationID; state->nxdn_key = KeyID; state->nxdn_cipher_type = CipherType; @@ -1366,7 +1366,7 @@ void NXDN_decode_VCALL(dsd_opts * opts, dsd_state * state, uint8_t * Message) } //Craft a fake DISC Message send it to return to CC - uint8_t dbits[96]; memset (dbits, 0, sizeof(dbits)); dbits[3] = 1; dbits[7] = 1; //DISC = 0x11; + uint8_t dbits[96]; memset (dbits, 0, sizeof(dbits)); dbits[3] = 1; dbits[7] = 1; //DISC = 0x11; if ( (strcmp(gm, "DE") == 0) && (strcmp(gn, "ENC LO") == 0) ) NXDN_Elements_Content_decode (opts, state, 1, dbits); @@ -1379,7 +1379,7 @@ void NXDN_decode_VCALL_IV(dsd_opts * opts, dsd_state * state, uint8_t * Message) UNUSED(opts); state->payload_miN = 0; //zero out - unsigned long long int IV = 0; + unsigned long long int IV = 0; //NOTE: On Type-D systems, the FACCH1 version of message only carries a 4-octet payload and also only carries a 22-bit IV //which makes no sense since you still have the full 80-bits of FACCH1 to use @@ -1441,12 +1441,12 @@ void NXDN_decode_VCALL_IV(dsd_opts * opts, dsd_state * state, uint8_t * Message) } /* End NXDN_decode_VCALL_IV() */ -//SCCH messages have a unique format that can be used in a super frame, but each 'unit' +//SCCH messages have a unique format that can be used in a super frame, but each 'unit' //can also (mostly) be decoded seperately, except an enc IV void NXDN_decode_scch(dsd_opts * opts, dsd_state * state, uint8_t * Message, uint8_t direction) { uint8_t sf = (uint8_t)ConvertBitIntoBytes(&Message[0], 2); - uint8_t opcode = (direction << 2 | sf); + uint8_t opcode = (direction << 2 | sf); fprintf (stderr, "\n " ); //initial line break @@ -1466,7 +1466,7 @@ void NXDN_decode_scch(dsd_opts * opts, dsd_state * state, uint8_t * Message, uin //elements used will be determined by other elements in the ISM/OSM messages //OSM 4 elements - uint8_t area = Message[2]; + uint8_t area = Message[2]; uint8_t rep1 = (uint8_t)ConvertBitIntoBytes(&Message[3], 5); //repeater 1 value uint8_t rep2 = (uint8_t)ConvertBitIntoBytes(&Message[8], 5); //repeater 2 value uint16_t id = (uint16_t)ConvertBitIntoBytes(&Message[13], 11); //id is context dependent @@ -1486,14 +1486,14 @@ void NXDN_decode_scch(dsd_opts * opts, dsd_state * state, uint8_t * Message, uin uint8_t DuplexMode[32] = {0}; uint8_t TransmissionMode[32] = {0}; - //ISM messages are seemingly exactly the same info as OSM, so just going to use OSM versions + //ISM messages are seemingly exactly the same info as OSM, so just going to use OSM versions //(manual doesn't specify other than that ISM 4 is the same as ISM2, but probably doesn't have IDLE/HALT/SITE ID messages) //set category to "Type-D" to alert users this is an a Distributed Trunking System sprintf (state->nxdn_location_category, "Type-D"); //placeholder numbers, using 99 if these aren't set by the Site ID Message (single sites) - // if (state->nxdn_location_site_code == 0) state->nxdn_location_site_code = 99; + // if (state->nxdn_location_site_code == 0) state->nxdn_location_site_code = 99; // if (state->nxdn_location_sys_code == 0) state->nxdn_location_sys_code = 99; // if (state->nxdn_last_ran == -1) state->nxdn_last_ran = 99; @@ -1520,7 +1520,7 @@ void NXDN_decode_scch(dsd_opts * opts, dsd_state * state, uint8_t * Message, uin sprintf (state->active_channel[rep1], "%s", ""); sprintf (state->active_channel[rep2], "%s", ""); - } + } else if (id == 2045) { fprintf (stderr, "Halt Repeater Message - "); @@ -1528,7 +1528,7 @@ void NXDN_decode_scch(dsd_opts * opts, dsd_state * state, uint8_t * Message, uin fprintf (stderr, "Repeater 1: %d; ", rep1); fprintf (stderr, "Repeater 2: %d; ", rep2); - } + } else if (id == 2044) { fprintf (stderr, "Free Repeater Message - "); @@ -1536,7 +1536,7 @@ void NXDN_decode_scch(dsd_opts * opts, dsd_state * state, uint8_t * Message, uin fprintf (stderr, "Free Repeater 1: %d; ", rep1); fprintf (stderr, "Free Repeater 2: %d; ", rep2); - } + } else if (id == 2041) { fprintf (stderr, "Site ID Message - "); @@ -1550,15 +1550,15 @@ void NXDN_decode_scch(dsd_opts * opts, dsd_state * state, uint8_t * Message, uin if (rep2 == 0) fprintf (stderr, "Reserved; "); else if (rep2 < 251) fprintf (stderr, "Open Access; "); //Usable voluntary every TRS...? else fprintf (stderr, "Reserved; "); - state->nxdn_location_site_code = sitet; - state->nxdn_location_sys_code = sitet; + state->nxdn_location_site_code = sitet; + state->nxdn_location_sys_code = sitet; state->nxdn_last_ran = sitet; - } + } else //Busy Repeater Message is essentially our 'call in progess' message for a repeater { if (gu && rep1 == 0) fprintf (stderr, "REG_COMM; "); - else fprintf (stderr, "Busy Repeater Message - "); + else fprintf (stderr, "Busy Repeater Message - "); fprintf (stderr, "Area: %d; ", area); fprintf (stderr, "Go to Repeater: %d; ", rep1); fprintf (stderr, "Home Repeater: %d; ", rep2); @@ -1568,8 +1568,8 @@ void NXDN_decode_scch(dsd_opts * opts, dsd_state * state, uint8_t * Message, uin fprintf (stderr, "\n%s ", KRED); state->nxdn_last_tg = 0; state->nxdn_last_rid = 0; - } - else + } + else { fprintf (stderr, "\n%s ", KGRN); //only set this is during a voice tx, and not a data tx @@ -1577,14 +1577,14 @@ void NXDN_decode_scch(dsd_opts * opts, dsd_state * state, uint8_t * Message, uin state->nxdn_last_tg = id; } - fprintf (stderr, " Channel Update - CH: %d - TGT: %d ", rep1, id); + fprintf (stderr, " Channel Update - CH: %d - TGT: %d ", rep1, id); if (gu == 0) fprintf (stderr, "Group Call "); else fprintf (stderr, "Private Call "); if (rep1 == 31) fprintf (stderr, "Termination "); //add current active to display string -- may need tweaking on if to use rep1 (active ch), or rep2 (home prefix) - if (rep1 != 0 && rep1 != 31) + if (rep1 != 0 && rep1 != 31) { if (gu == 0) sprintf (state->active_channel[rep1], "Active Group Ch: %d TG: %d-%d; ", rep1, rep2, id); //Group TG else sprintf (state->active_channel[rep1], "Active Private Ch: %d TGT: %d-%d; ", rep1, rep2, id); //Private TGT @@ -1604,7 +1604,7 @@ void NXDN_decode_scch(dsd_opts * opts, dsd_state * state, uint8_t * Message, uin if (rep1 == 31) tune = 1; //begin tuning - if (tune == 1 && rep1 != 0) + if (tune == 1 && rep1 != 0) { //check for control channel frequency in the channel map if not available if (state->trunk_chan_map[31] != 0) state->p25_cc_freq = state->trunk_chan_map[31]; //user provided channel to go to for '31' -- may change to 0 later? @@ -1631,7 +1631,7 @@ void NXDN_decode_scch(dsd_opts * opts, dsd_state * state, uint8_t * Message, uin //TG hold on IDAS -- block non-matching target, allow matching DestinationID if (state->tg_hold != 0 && state->tg_hold != id) sprintf (mode, "%s", "B"); - if (state->tg_hold != 0 && state->tg_hold == id) + if (state->tg_hold != 0 && state->tg_hold == id) { sprintf (mode, "%s", "A"); opts->p25_is_tuned = 0; //unlock tuner at this stage and not above check @@ -1644,7 +1644,7 @@ void NXDN_decode_scch(dsd_opts * opts, dsd_state * state, uint8_t * Message, uin if (opts->p25_trunk == 1 && (strcmp(mode, "DE") != 0) && (strcmp(mode, "B") != 0)) //DE is digital encrypted, B is block { //will need to monitor, 1 second may be too long on idas, may need to try 0 or manipulate another way - if (state->p25_cc_freq != 0 && ((time(NULL) - state->last_vc_sync_time) > 1) && freq != 0) + if (state->p25_cc_freq != 0 && ((time(NULL) - state->last_vc_sync_time) > 1) && freq != 0) { //rigctl if (opts->use_rigctl == 1) @@ -1652,7 +1652,7 @@ void NXDN_decode_scch(dsd_opts * opts, dsd_state * state, uint8_t * Message, uin //extra safeguards due to sync issues with NXDN memset (state->nxdn_sacch_frame_segment, 1, sizeof(state->nxdn_sacch_frame_segment)); memset (state->nxdn_sacch_frame_segcrc, 1, sizeof(state->nxdn_sacch_frame_segcrc)); - state->lastsynctype = -1; + state->lastsynctype = -1; state->last_cc_sync_time = time(NULL); state->last_vc_sync_time = time(NULL); //should we use this here, or not? // @@ -1672,11 +1672,11 @@ void NXDN_decode_scch(dsd_opts * opts, dsd_state * state, uint8_t * Message, uin //extra safeguards due to sync issues with NXDN memset (state->nxdn_sacch_frame_segment, 1, sizeof(state->nxdn_sacch_frame_segment)); memset (state->nxdn_sacch_frame_segcrc, 1, sizeof(state->nxdn_sacch_frame_segcrc)); - state->lastsynctype = -1; + state->lastsynctype = -1; state->last_cc_sync_time = time(NULL); state->last_vc_sync_time = time(NULL); //should we use this here, or not? // - rtl_dev_tune (opts, freq); + rtl_dev_tune (opts, freq); state->p25_vc_freq[0] = state->p25_vc_freq[1] = freq; opts->p25_is_tuned = 1; //check the rkey array for a scrambler key value @@ -1685,8 +1685,8 @@ void NXDN_decode_scch(dsd_opts * opts, dsd_state * state, uint8_t * Message, uin if (state->M == 1) state->nxdn_cipher_type = 0x1; #endif } - - } + + } } } //end tuning -- NOTE: since we are only going by last time voice sync detected, tuning here is always 'unlocked' @@ -1698,7 +1698,7 @@ void NXDN_decode_scch(dsd_opts * opts, dsd_state * state, uint8_t * Message, uin { fprintf (stderr, "Source Message - "); fprintf (stderr, "Area: %d; ", area); - fprintf (stderr, "Free Repeater 1: %d; ", rep1); + fprintf (stderr, "Free Repeater 1: %d; ", rep1); if (id == 31) { @@ -1719,7 +1719,7 @@ void NXDN_decode_scch(dsd_opts * opts, dsd_state * state, uint8_t * Message, uin if (opcode == 0x6 || opcode == 0x2) //OSM INFO 2 -- same as 4 { - fprintf (stderr, "Target Message - "); + fprintf (stderr, "Target Message - "); fprintf (stderr, "Area: %d; ", area); fprintf (stderr, "Go to Repeater: %d; ", rep1); if (id == 31) @@ -1727,14 +1727,14 @@ void NXDN_decode_scch(dsd_opts * opts, dsd_state * state, uint8_t * Message, uin fprintf (stderr, "\n%s ", KYEL); fprintf (stderr, " Call IV A: %04llX; ", iv_a); //MSB 0-11 //zero out IV storage and append this chunk to MSB position - state->payload_miN = 0; + state->payload_miN = 0; state->payload_miN = state->payload_miN | (iv_a << 11); //MSB 11, so shift 11 (22 total bits). } else { //rep2 is the home repeater/source prefix in this instance fprintf (stderr, "\n%s ", KGRN); - fprintf (stderr, " Target Update - Prefix CH: %d SRC: %d - (%d-%d) ", rep2, id, rep2, id); //rep2 + fprintf (stderr, " Target Update - Prefix CH: %d SRC: %d - (%d-%d) ", rep2, id, rep2, id); //rep2 //only set this is during a voice tx, and not a data tx if ( time(NULL) - state->last_vc_sync_time < 1 ) state->nxdn_last_tg = id; diff --git a/src/nxdn_frame.c b/src/nxdn_frame.c index 968a76f..735a7c3 100644 --- a/src/nxdn_frame.c +++ b/src/nxdn_frame.c @@ -2,20 +2,20 @@ //Reworked portions from Osmocom OP25 rx_sync.cc /* -*- c++ -*- */ -/* +/* * NXDN Encoder/Decoder (C) Copyright 2019 Max H. Parke KA1RBI - * - * + * + * * This 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, or (at your option) * any later version. - * + * * This software 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 software; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, @@ -30,7 +30,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) { // length is implicitly 192, with frame sync in first 10 dibits - uint8_t dbuf[182]; + uint8_t dbuf[182]; uint8_t lich; uint8_t answer[32]; uint8_t sacch_answer[32]; @@ -56,7 +56,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) uint8_t direction; //inbound or outbound direction UNUSED2(lich_fc, lich_op); - uint8_t lich_dibits[8]; + uint8_t lich_dibits[8]; uint8_t sacch_bits[60]; uint8_t facch_bits_a[144]; uint8_t facch_bits_b[144]; @@ -65,7 +65,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) uint8_t facch3_bits[288]; //facch3 or udch2, same amount of bits //nxdn bit buffer, for easy assignment handling - int nxdn_bit_buffer[364]; + int nxdn_bit_buffer[364]; int nxdn_dibit_buffer[182]; //init all arrays @@ -86,20 +86,20 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) for (int i = 0; i < 8; i++) lich_dibits[i] = dbuf[i] = getDibit(opts, state); nxdn_descramble (lich_dibits, 8); - + lich = 0; for (int i=0; i<8; i++) lich |= (lich_dibits[i] >> 1) << (7-i); - + lich_parity_received = lich & 1; lich_parity_computed = ((lich >> 7) + (lich >> 6) + (lich >> 5) + (lich >> 4)) & 1; lich = lich >> 1; if (lich_parity_received != lich_parity_computed) { if (opts->payload == 1) fprintf(stderr, " Lich Parity Error %02X\n", lich); - state->lastsynctype = -1; //set to -1 so we don't jump back here too quickly + state->lastsynctype = -1; //set to -1 so we don't jump back here too quickly goto END; } - + voice = 0; facch = 0; facch2 = 0; @@ -111,7 +111,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) if (lich % 2 == 0 && opts->p25_trunk == 1) { if (opts->payload == 1) fprintf(stderr, " Simplex/Inbound NXDN lich on trunking system - type 0x%02X\n", lich); - state->lastsynctype = -1; //set to -1 so we don't jump back here too quickly + state->lastsynctype = -1; //set to -1 so we don't jump back here too quickly goto END; } @@ -136,7 +136,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) case 0x33: case 0x52: case 0x53: - voice = 2; + voice = 2; facch = 1; sacch = 1; break; @@ -144,19 +144,19 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) case 0x35: case 0x54: case 0x55: //disabled for testing, IDAS system randomly triggers this one, probably due to poor signal - voice = 1; + voice = 1; facch = 2; sacch = 1; break; case 0x36: //vch in both case 0x37: - case 0x56: - case 0x57: - voice = 3; + case 0x56: + case 0x57: + voice = 3; facch = 0; sacch = 1; break; - case 0x20: //facch in both + case 0x20: //facch in both case 0x21: case 0x30: case 0x31: @@ -165,7 +165,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) case 0x50: case 0x51: voice = 0; - facch = 3; + facch = 3; sacch = 1; break; case 0x38: //sacch only (NULL?) @@ -175,7 +175,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) //NXDN "Type-D" or "IDAS" Specific Lich Codes case 0x76: //normal vch voice (in one and two) - case 0x77: + case 0x77: idas = 1; scch = 1; voice = 3; @@ -230,7 +230,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) //reset the sacch field, we probably got a false sync and need to wipe or give a bad crc memset (state->nxdn_sacch_frame_segment, 1, sizeof(state->nxdn_sacch_frame_segment)); memset (state->nxdn_sacch_frame_segcrc, 1, sizeof(state->nxdn_sacch_frame_segcrc)); - state->lastsynctype = -1; //set to -1 so we don't jump back here too quickly + state->lastsynctype = -1; //set to -1 so we don't jump back here too quickly voice = 0; goto END; break; @@ -247,7 +247,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) { printFrameSync (opts, state, "IDAS D ", 0, "-"); } - if (opts->payload == 1) + if (opts->payload == 1) fprintf (stderr, "L%02X - ", lich); } else if (voice || facch || sacch || facch2 || udch || cac) @@ -282,12 +282,12 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) { sacch_bits[i] = nxdn_bit_buffer[i+16]; } - + //facch for (int i = 0; i < 144; i++) { facch_bits_a[i] = nxdn_bit_buffer[i+16+60]; - facch_bits_b[i] = nxdn_bit_buffer[i+16+60+144]; + facch_bits_b[i] = nxdn_bit_buffer[i+16+60+144]; } //cac @@ -357,7 +357,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) uint8_t hash_bits[24]; memset (hash_bits, 0, sizeof(hash_bits)); uint16_t limazulu = 0; - + //if not available, then poll rigctl if its available if (opts->use_rigctl == 1) freq = GetCurrentFreq (opts->rigctl_sockfd); @@ -372,7 +372,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) //the hash has to be run the same way as the import, so at a 24-bit depth, which hopefully //will not lead to any duplicate key loads due to multiple CRC16 collisions on a larger value? for (int i = 0; i < 24; i++) - hash_bits[i] = ((freq << i) & 0x800000) >> 23; //load into array for CRC16 + hash_bits[i] = ((freq << i) & 0x800000) >> 23; //load into array for CRC16 if (freq) limazulu = ComputeCrcCCITT16d (hash_bits, 24); limazulu = limazulu & 0xFFFF; //make sure no larger than 16-bits @@ -382,7 +382,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) if (state->rkey_array[limazulu] != 0) fprintf (stderr, " - Key Loaded: %lld", state->rkey_array[limazulu]); fprintf (stderr, "%s", KNRM); - if (state->rkey_array[limazulu] != 0) + if (state->rkey_array[limazulu] != 0) state->R = state->rkey_array[limazulu]; if (state->R != 0 && state->M == 1) state->nxdn_cipher_type = 0x1; @@ -397,7 +397,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) if (opts->scanner_mode == 1) state->last_cc_sync_time = time(NULL) + 2; //add a little extra hangtime between resuming scan - //Option/Steal Flags echoed in Voice, V+F, or Data + //Option/Steal Flags echoed in Voice, V+F, or Data if (voice && !facch) //voice only, no facch steal { fprintf (stderr, "%s", KGRN); @@ -417,7 +417,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) fprintf (stderr, "%s", KNRM); //roll the voice scrambler LFSR here if key available to advance seed (usually just needed on NXDN96) - if (state->nxdn_cipher_type == 0x1 && state->R != 0) + if (state->nxdn_cipher_type == 0x1 && state->R != 0) { if (state->payload_miN == 0) { @@ -441,7 +441,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) if (voice && facch == 1) //facch steal 1 -- before voice { //force scrambler here, but with unspecified key (just use what's loaded) - if (state->M == 1 && state->R != 0) state->nxdn_cipher_type = 0x1; + if (state->M == 1 && state->R != 0) state->nxdn_cipher_type = 0x1; //roll the voice scrambler LFSR here if key available to advance seed -- half rotation on a facch steal if (state->nxdn_cipher_type == 0x1 && state->R != 0) { @@ -456,11 +456,11 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) { LFSRN(ambe_temp, ambe_d, state); } - } + } //correct the bit counter if FACCH1 steal) if (state->nxdn_cipher_type == 0x2 || state->nxdn_cipher_type == 0x3) - state->bit_counterL += 49*2; + state->bit_counterL += 49*2; } if (lich == 0x20 || lich == 0x21 || lich == 0x61 || lich == 0x40 || lich == 0x41) state->nxdn_sacch_non_superframe = TRUE; @@ -475,7 +475,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) if (sacch) nxdn_deperm_sacch(opts, state, sacch_bits); if (cac) nxdn_deperm_cac(opts, state, cac_bits); - //Seperated UDCH user data from facch2 data + //Seperated UDCH user data from facch2 data if (udch) nxdn_deperm_facch2_udch(opts, state, facch2_bits, 0); if (facch2) nxdn_deperm_facch2_udch(opts, state, facch2_bits, 1); @@ -501,7 +501,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) //turn on scrambler if forced by user option if (state->M == 1 && state->R != 0) state->nxdn_cipher_type = 0x1; //process voice frame - nxdn_voice (opts, state, voice, dbuf); + nxdn_voice (opts, state, voice, dbuf); } //close MBE file if no voice and its open @@ -514,11 +514,11 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) if ( (time(NULL) - state->last_vc_sync_time) > 1) //test for optimal time, 1 sec should be okay { closeMbeOutFile (opts, state); - } + } } //may need to reconsider this, due to double FACCH1 steals on some Type-C (ASSGN_DUP, etc) and Conventional Systems (random IDLE FACCH1 steal for no reason) if (opts->frame_nxdn48 == 1) closeMbeOutFile (opts, state); //okay to close right away if nxdn48, no data/voice frames mixing - } + } } if (voice && facch == 2) //facch steal 2 -- after voice 1 @@ -532,13 +532,13 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) { LFSRN(ambe_temp, ambe_d, state); } - } + } //correct the bit counter if FACCH1 steal) if (state->nxdn_cipher_type == 0x2 || state->nxdn_cipher_type == 0x3) - state->bit_counterL += 49*2; + state->bit_counterL += 49*2; } - + if (opts->payload == 1 && !voice) fprintf (stderr, "\n"); else if (opts->payload == 0) fprintf (stderr, "\n"); diff --git a/src/nxdn_voice.c b/src/nxdn_voice.c index 7443302..e01e775 100644 --- a/src/nxdn_voice.c +++ b/src/nxdn_voice.c @@ -79,9 +79,9 @@ void nxdn_voice (dsd_opts * opts, dsd_state * state, int voice, uint8_t dbuf[182 { //skip 8 lich and 30 sacch dibits already in buffer plus 36 times start position - ambe_fr[*w][*x] = dbuf[i+38+start*36] >> 1; - ambe_fr[*y][*z] = dbuf[i+38+start*36] & 1; - + ambe_fr[*w][*x] = dbuf[i+38+start*36] >> 1; + ambe_fr[*y][*z] = dbuf[i+38+start*36] & 1; + w++; x++; y++; @@ -91,17 +91,17 @@ void nxdn_voice (dsd_opts * opts, dsd_state * state, int voice, uint8_t dbuf[182 processMbeFrame (opts, state, NULL, ambe_fr, NULL); memcpy (state->f_l, state->audio_out_temp_buf, sizeof(state->f_l)); - + if (opts->floating_point == 0 ) playSynthesizedVoiceMS(opts, state); if (opts->floating_point == 1) playSynthesizedVoiceFM(opts, state); } - + if (opts->payload == 1) { fprintf(stderr, "\n"); } - + } \ No newline at end of file diff --git a/src/p25_12.c b/src/p25_12.c index fa2b058..2b38781 100644 --- a/src/p25_12.c +++ b/src/p25_12.c @@ -20,8 +20,8 @@ uint8_t p25_constellation_map[16] = { }; //digitized dibit to OTA symbol conversion for reference -//0 = +1; 1 = +3; -//2 = -1; 3 = -3; +//0 = +1; 1 = +3; +//2 = -1; 3 = -3; //finite state machine values uint8_t p25_fsm[16] = { @@ -97,12 +97,12 @@ int p25_12(uint8_t * input, uint8_t treturn[12]) uint8_t point[49]; memset (point, 0xFF, sizeof(point)); - for (i = 0; i < 49; i++) + for (i = 0; i < 49; i++) point[i] = p25_constellation_map[nibs[i]]; //debug view points // fprintf (stderr, "\n P ="); - // for (i = 0; i < 49; i++) + // for (i = 0; i < 49; i++) // fprintf (stderr, " %02d", point[i]); //convert constellation points into tdibit values using the FSM @@ -149,7 +149,7 @@ int p25_12(uint8_t * input, uint8_t treturn[12]) //debug view tdibits/states // fprintf (stderr, "\n T ="); - // for (i = 0; i < 49; i++) + // for (i = 0; i < 49; i++) // fprintf (stderr, " %02d", tdibits[i]); //pack tdibits into return payload bytes diff --git a/src/p25_crc.c b/src/p25_crc.c index adc206c..924a13f 100644 --- a/src/p25_crc.c +++ b/src/p25_crc.c @@ -157,7 +157,7 @@ int p25p1_lsd_fec(uint8_t * input) uint8_t lsd = (uint8_t)ConvertBitIntoBytes(&input[0], 8); uint8_t par = (uint8_t)ConvertBitIntoBytes(&input[8], 8); uint8_t chk = lsd_parity[lsd]; - //NOTE: Simply checking the parity doesn't account for the parity bits being bad, but the + //NOTE: Simply checking the parity doesn't account for the parity bits being bad, but the //low speed data bits being correct, but is better than nothing if (chk == par) return 1; else diff --git a/src/p25_frequency.c b/src/p25_frequency.c index 6b239ff..22e9228 100644 --- a/src/p25_frequency.c +++ b/src/p25_frequency.c @@ -3,7 +3,7 @@ * P25 Channel to Frequency Calculator * * NXDN Channel to Frequency Calculator - * + * * LWVMOBILE * 2022-11 DSD-FME Florida Man Edition *-----------------------------------------------------------------------------*/ @@ -32,7 +32,7 @@ long int process_channel_to_freq (dsd_opts * opts, dsd_state * state, int channe //Note: Base Frequency is calculated as (Base Frequency) x (0.000005 MHz) from the IDEN_UP message. long int freq = -1; - int iden = channel >> 12; + int iden = channel >> 12; int type = state->p25_chan_type[iden]; int slots_per_carrier[16] = {1,1,1,2,4,2,2,2,2,2,2,2,2,2,2,2}; //from OP25 int step = (channel & 0xFFF) / slots_per_carrier[type]; @@ -45,7 +45,7 @@ long int process_channel_to_freq (dsd_opts * opts, dsd_state * state, int channe return (freq); } - //if not found, attempt to find it via calculation + //if not found, attempt to find it via calculation else { if (state->p25_base_freq[iden] != 0) @@ -54,13 +54,13 @@ long int process_channel_to_freq (dsd_opts * opts, dsd_state * state, int channe fprintf (stderr, "\n Frequency [%.6lf] MHz", (double)freq/1000000); return (freq); } - else + else { fprintf (stderr, "\n Base Frequency Not Found - Iden [%d]", iden); fprintf(stderr, "\n or Channel not found in import file"); return (0); } - } + } } @@ -106,18 +106,18 @@ long int nxdn_channel_to_frequency(dsd_opts * opts, dsd_state * state, uint16_t fprintf (stderr, "\n DFA Frequency [%.6lf] MHz", (double)freq/1000000); return (freq); } - else + else { fprintf(stderr, "\n Custom DFA Settings -- Unknown Freq;"); return (0); } - + } else { fprintf(stderr, "\n Channel not found in import file"); return (0); - } + } } \ No newline at end of file diff --git a/src/p25_lcw.c b/src/p25_lcw.c index 371adc2..dc41319 100644 --- a/src/p25_lcw.c +++ b/src/p25_lcw.c @@ -31,14 +31,14 @@ void p25_lcw (dsd_opts * opts, dsd_state * state, uint8_t LCW_bits[], uint8_t ir if (lc_pf == 0) //not protected/encrypted lcw { - if (opts->payload == 1) fprintf (stderr, " LCW"); + if (opts->payload == 1) fprintf (stderr, " LCW"); //check to see if we need to run these as MFID 0 or 1 only (standard) if (lc_mfid == 0 || lc_mfid == 1) //lc_mfid == 0 { //check the service options on applicable formats - if (lc_format == 0x4A || lc_format == 0x46 || lc_format == 0x45 + if (lc_format == 0x4A || lc_format == 0x46 || lc_format == 0x45 || lc_format == 0x44 || lc_format == 0x03 || lc_format == 0x00) { @@ -154,7 +154,7 @@ void p25_lcw (dsd_opts * opts, dsd_state * state, uint8_t LCW_bits[], uint8_t ir } - else if (lc_format == 0x4A) + else if (lc_format == 0x4A) { fprintf (stderr, " Unit to Unit Voice Channel User – Extended"); uint32_t target = (uint32_t)ConvertBitIntoBytes(&LCW_bits[16], 24); @@ -177,71 +177,71 @@ void p25_lcw (dsd_opts * opts, dsd_state * state, uint8_t LCW_bits[], uint8_t ir fprintf (stderr, " Unit Authentication Command - OBSOLETE"); } - else if (lc_format == 0x53) + else if (lc_format == 0x53) { fprintf (stderr, " Status Query"); } - else if (lc_format == 0x54) + else if (lc_format == 0x54) { fprintf (stderr, " Status Update"); } - else if (lc_format == 0x55) + else if (lc_format == 0x55) { fprintf (stderr, " Status Update"); } - else if (lc_format == 0x56) + else if (lc_format == 0x56) { fprintf (stderr, " Call Alert"); } - else if (lc_format == 0x5A) + else if (lc_format == 0x5A) { fprintf (stderr, " Status Update – Source ID Extension Required"); } - else if (lc_format == 0x5C) + else if (lc_format == 0x5C) { fprintf (stderr, " Extended Function Command – Source ID Extension Required"); } - else if (lc_format == 0x60) + else if (lc_format == 0x60) { fprintf (stderr, " System Service Broadcast"); } //this PDU does not have an associated MFID, often seen on kiwi and matches its TSBK counterpart //its possible some of the other ones here don't as well, need to re-check all of them - else if (lc_format == 0x61) + else if (lc_format == 0x61) { fprintf (stderr, " Secondary Control Channel Broadcast"); } - else if (lc_format == 0x62) + else if (lc_format == 0x62) { fprintf (stderr, " Adjacent Site Status Broadcast"); } - else if (lc_format == 0x63) + else if (lc_format == 0x63) { fprintf (stderr, " RFSS Status Broadcast"); } - else if (lc_format == 0x64) + else if (lc_format == 0x64) { fprintf (stderr, " Network Status Broadcast"); } - else if (lc_format == 0x65) + else if (lc_format == 0x65) { fprintf (stderr, " Protection Parameter Broadcast - OBSOLETE"); } - else if (lc_format == 0x66) + else if (lc_format == 0x66) { fprintf (stderr, " Secondary Control Channel Broadcast – Explicit (LCSCBX)"); } @@ -267,40 +267,40 @@ void p25_lcw (dsd_opts * opts, dsd_state * state, uint8_t LCW_bits[], uint8_t ir // else fprintf (stderr, " Last Known"); if (cfva & 0x1) fprintf (stderr, " - Connection Active"); // process_channel_to_freq (opts, state, channelt); - //end debug, way too much for a simple link control line + //end debug, way too much for a simple link control line } - else if (lc_format == 0x68) + else if (lc_format == 0x68) { fprintf (stderr, " RFSS Status Broadcast – Explicit (LCRSBX)"); } - else if (lc_format == 0x69) + else if (lc_format == 0x69) { fprintf (stderr, " Network Status Broadcast – Explicit (LCNSBX)"); } - else if (lc_format == 0x6A) + else if (lc_format == 0x6A) { fprintf (stderr, " Conventional Fallback"); } - else if (lc_format == 0x6B) + else if (lc_format == 0x6B) { fprintf (stderr, " Message Update – Source ID Extension Required"); } //tune back to CC here - save about 1-2 seconds - else if (lc_format == 0x4F) //# Call Termination/Cancellation + else if (lc_format == 0x4F) //# Call Termination/Cancellation { 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) { - + //Will we need to check for a symbolrate change here, can a P25p2 TDMA-CC system //revert back to a phase 1 traffic channel or carry a phase 1 traffic channel? if (state->p25_cc_is_tdma == 1) @@ -326,7 +326,7 @@ void p25_lcw (dsd_opts * opts, dsd_state * state, uint8_t LCW_bits[], uint8_t ir { state->lasttg = 0; state->lastsrc = 0; - state->payload_algid = 0; + state->payload_algid = 0; state->payload_keyid = 0; // state->payload_miP = 0; //reset some strings @@ -337,7 +337,7 @@ void p25_lcw (dsd_opts * opts, dsd_state * state, uint8_t LCW_bits[], uint8_t ir opts->p25_is_tuned = 0; state->p25_vc_freq[0] = state->p25_vc_freq[1] = 0; if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); - SetFreq(opts->rigctl_sockfd, state->p25_cc_freq); + SetFreq(opts->rigctl_sockfd, state->p25_cc_freq); } //rtl else if (opts->audio_in_type == 3) @@ -378,7 +378,7 @@ void p25_lcw (dsd_opts * opts, dsd_state * state, uint8_t LCW_bits[], uint8_t ir //0xFFFFFF - All Units //This lc_format doesn't use the MFID field - else if (lc_format == 0x42) + else if (lc_format == 0x42) fprintf (stderr, " Conventional Fallback Indication"); //This lc_format doesn't use the MFID field @@ -402,15 +402,15 @@ void p25_lcw (dsd_opts * opts, dsd_state * state, uint8_t LCW_bits[], uint8_t ir } //This lc_format doesn't use the MFID field - else if (lc_format == 0x61) + else if (lc_format == 0x61) fprintf (stderr, " Secondary Control Channel Broadcast"); //This lc_format doesn't use the MFID field - else if (lc_format == 0x62) + else if (lc_format == 0x62) fprintf (stderr, " Adjacent Site Status Broadcast"); - + //This lc_format doesn't use the MFID field - else if (lc_format == 0x63) + else if (lc_format == 0x63) fprintf (stderr, " RFSS Status Broadcast"); //MFID 90 Embedded GPS @@ -486,7 +486,7 @@ void p25_lcw (dsd_opts * opts, dsd_state * state, uint8_t LCW_bits[], uint8_t ir else if (lc_mfid == 0xA4 && lc_opcode == 0x2B) { - fprintf (stderr, " MFIDA4 (Harris) GPS Block 2"); + fprintf (stderr, " MFIDA4 (Harris) GPS Block 2"); memcpy(state->dmr_pdu_sf[0]+40+56, LCW_bits+16, 56*sizeof(uint8_t)); //+40 +56 to offset first block uint16_t check = (uint16_t)ConvertBitIntoBytes(&state->dmr_pdu_sf[0][0], 16); if (check == 0x2AA4) diff --git a/src/p25p1_check_hdu.cpp b/src/p25p1_check_hdu.cpp index 5d643c4..083444a 100644 --- a/src/p25p1_check_hdu.cpp +++ b/src/p25p1_check_hdu.cpp @@ -2,7 +2,7 @@ #if __cplusplus > 199711L #define register // Deprecated in C++11. #endif // #if __cplusplus > 199711L -//end ifdef to fix compiler warnings +//end ifdef to fix compiler warnings #include "p25p1_check_hdu.h" #include "ReedSolomon.hpp" diff --git a/src/p25p1_hdu.c b/src/p25p1_hdu.c index 5a4aee8..a2d68e5 100644 --- a/src/p25p1_hdu.c +++ b/src/p25p1_hdu.c @@ -461,7 +461,7 @@ processHDU(dsd_opts* opts, dsd_state* state) mihex3 = (unsigned long long int)ConvertBitIntoBytes(&mi[64], 8); //reset dropbytes - skip first 11 for LCW - state->dropL = 267; + state->dropL = 267; //set vc counter to 0 state->p25vc = 0; @@ -538,5 +538,5 @@ processHDU(dsd_opts* opts, dsd_state* state) //reset gain if (opts->floating_point == 1) state->aout_gain = opts->audio_gain; - + } diff --git a/src/p25p1_ldu.c b/src/p25p1_ldu.c index 7f3db81..3dd8167 100644 --- a/src/p25p1_ldu.c +++ b/src/p25p1_ldu.c @@ -146,13 +146,13 @@ process_IMBE (dsd_opts* opts, dsd_state* state, int* status_count) } /* //this is what is observed on the sigid wiki example (matches above pattern) - IMBE 000F920291AD6F06540980 err = [3] [A] - IMBE 000F920294816F06540980 err = [3] [A] + IMBE 000F920291AD6F06540980 err = [3] [A] + IMBE 000F920294816F06540980 err = [3] [A] IMBE 000E1C0294816F06540980 err = [3] [B] //this is what is observed on the 'hole' examples (not a match, TODO: Examine imbe_fr add this?) - IMBE FC00000000000000000300 err = [2] [B] - IMBE FC00000000000000000300 err = [2] [B] + IMBE FC00000000000000000300 err = [2] [B] + IMBE FC00000000000000000300 err = [2] [B] IMBE FC00000000000000000300 err = [2] [B] */ diff --git a/src/p25p1_ldu1.c b/src/p25p1_ldu1.c index a9b7a61..a950478 100644 --- a/src/p25p1_ldu1.c +++ b/src/p25p1_ldu1.c @@ -443,7 +443,7 @@ processLDU1 (dsd_opts* opts, dsd_state* state) LCW_bits[j + 6] = (LCW_bytes[i] >> 1) & 0x01; LCW_bits[j + 7] = (LCW_bytes[i] >> 0) & 0x01; } - + //send to new P25 LCW function if (irrecoverable_errors == 0) { @@ -573,7 +573,7 @@ processLDU1 (dsd_opts* opts, dsd_state* state) sprintf (state->group_array[state->group_tally].groupMode, "%s", "D"); sprintf (state->group_array[z].groupName, "%s", str); } - + } fprintf (stderr, "%s",KNRM); diff --git a/src/p25p1_ldu2.c b/src/p25p1_ldu2.c index a1e5e69..c879571 100644 --- a/src/p25p1_ldu2.c +++ b/src/p25p1_ldu2.c @@ -281,7 +281,7 @@ processLDU2 (dsd_opts * opts, dsd_state * state) //reset dropbytes -- skip first 11 for next LCW state->dropL = 267; //reset octet counter - state->octet_counter = 0; + state->octet_counter = 0; if (opts->errorbars == 1) { @@ -538,7 +538,7 @@ processLDU2 (dsd_opts * opts, dsd_state * state) #ifdef SOFTID if (opts->payload == 1) - { + { //view Low Speed Data fprintf (stderr, "%s",KCYN); fprintf (stderr, " LSD: %02X %02X ", lsd_hex1, lsd_hex2); @@ -634,7 +634,7 @@ processLDU2 (dsd_opts * opts, dsd_state * state) sprintf (state->group_array[state->group_tally].groupMode, "%s", "D"); sprintf (state->group_array[z].groupName, "%s", str); } - + } fprintf (stderr, "%s",KNRM); @@ -653,7 +653,7 @@ processLDU2 (dsd_opts * opts, dsd_state * state) #endif //SOFTID //run LFSR on the MI if we have irrecoverable errors here - if (irrecoverable_errors && state->payload_algid != 0x80 && state->payload_keyid != 0 && state->payload_miP != 0) + if (irrecoverable_errors && state->payload_algid != 0x80 && state->payload_keyid != 0 && state->payload_miP != 0) { LFSRP(state); fprintf (stderr, "\n"); @@ -753,7 +753,7 @@ void LFSR128(dsd_state * state) int slot = state->currentslot; if (state->currentslot == 0) - lfsr = state->payload_miP; + lfsr = state->payload_miP; else lfsr = state->payload_miN; //start packing aes_iv @@ -783,7 +783,7 @@ void LFSR128(dsd_state * state) int cnt = 0; int x = 64; unsigned long long int bit; //polynomial P(x) = 1 + X15 + X27 + X38 + X46 + X62 + X64 - for(cnt=0;cnt<64;cnt++) + for(cnt=0;cnt<64;cnt++) { //63,61,45,37,27,14 // Polynomial is C(x) = x^64 + x^62 + x^46 + x^38 + x^27 + x^15 + 1 diff --git a/src/p25p1_mdpu.c b/src/p25p1_mdpu.c index 69f87c2..29080c8 100644 --- a/src/p25p1_mdpu.c +++ b/src/p25p1_mdpu.c @@ -9,7 +9,7 @@ #include "dsd.h" uint32_t crc32mbf(uint8_t * buf, int len) -{ +{ uint32_t g = 0x04c11db7; uint64_t crc = 0; for (int i = 0; i < len; i++) @@ -67,10 +67,10 @@ void processMPDU(dsd_opts * opts, dsd_state * state) uint8_t mpdu_decoded_bits[18*129*8]; memset (mpdu_decoded_bits, 0, sizeof(mpdu_decoded_bits)); - uint8_t mpdu_crc_bits[18*129*8]; + uint8_t mpdu_crc_bits[18*129*8]; memset (mpdu_crc_bits, 0, sizeof(mpdu_crc_bits)); - uint8_t mpdu_crc9_bits[18*129*8]; + uint8_t mpdu_crc9_bits[18*129*8]; memset (mpdu_crc9_bits, 0, sizeof(mpdu_crc9_bits)); uint8_t mpdu_crc_bytes[18*129]; @@ -86,10 +86,10 @@ void processMPDU(dsd_opts * opts, dsd_state * state) memset (mpdu_byte, 0, sizeof(mpdu_byte)); uint8_t an = 0; - uint8_t io = 0; - uint8_t fmt = 0; - uint8_t sap = 0; - uint8_t blks = 0; + uint8_t io = 0; + uint8_t fmt = 0; + uint8_t sap = 0; + uint8_t blks = 0; int end = 3; //ending value for data gathering repetitions (default at 3) //CRC32 @@ -123,7 +123,7 @@ void processMPDU(dsd_opts * opts, dsd_state * state) skipdibit = 0; status_count++; } - + skipdibit++; //increment //this is used to skip gathering one dibit as well since we only will end up skipping 2 status dibits (getting 99 instead of 98, throwing alignment off) @@ -216,7 +216,7 @@ void processMPDU(dsd_opts * opts, dsd_state * state) if (end > 128) end = 128; //Storage for up to 127 blocks plus 1 header } - + } if (err[0] == 0) @@ -236,8 +236,8 @@ void processMPDU(dsd_opts * opts, dsd_state * state) //trunking blocks if ((sap == 0x3D) && ((fmt == 0x17) || (fmt == 0x15))) { - - //CRC32 is now working! + + //CRC32 is now working! CRCExtracted = (mpdu_byte[(12*(blks+1))-4] << 24) | (mpdu_byte[(12*(blks+1))-3] << 16) | (mpdu_byte[(12*(blks+1))-2] << 8) | (mpdu_byte[(12*(blks+1))-1] << 0); CRCComputed = crc32mbf(mpdu_byte+12, (96*blks)-32); if (CRCComputed == CRCExtracted) err[1] = 0; @@ -260,20 +260,20 @@ void processMPDU(dsd_opts * opts, dsd_state * state) } - fprintf (stderr, "\n "); + fprintf (stderr, "\n "); fprintf (stderr, " CRC EXT %08X CMP %08X", CRCExtracted, CRCComputed); fprintf (stderr, "%s ", KNRM); - //Header - if (err[0] != 0) + //Header + if (err[0] != 0) { fprintf (stderr, "%s",KRED); fprintf (stderr, " (HDR CRC16 ERR)"); fprintf (stderr, "%s",KCYN); } - //Completed MBF - if (err[1] != 0) + //Completed MBF + if (err[1] != 0) { fprintf (stderr, "%s",KRED); fprintf (stderr, " (MBT CRC32 ERR)"); @@ -323,7 +323,7 @@ void processMPDU(dsd_opts * opts, dsd_state * state) if (i != 18*blks) i += 2; //skip the next DBSN/CRC9 } mpdu_byte[mpdu_idx++] = r34bytes[i]; - } + } //minus 1 to offset the last rounds mpdu_idx++ if (err[1] == 0 && blks != 0) @@ -361,7 +361,7 @@ void processMPDU(dsd_opts * opts, dsd_state * state) fprintf (stderr, "%02X", mpdu_byte[i]); } - if (err[1] != 0) + if (err[1] != 0) { fprintf (stderr, "%s",KRED); fprintf (stderr, "\n (MPDU CRC32 ERR)"); @@ -405,7 +405,7 @@ void processMPDU(dsd_opts * opts, dsd_state * state) } } - if (err[1] != 0) + if (err[1] != 0) { fprintf (stderr, "%s",KRED); fprintf (stderr, "\n (MPDU CRC32 ERR)"); @@ -422,5 +422,5 @@ void processMPDU(dsd_opts * opts, dsd_state * state) fprintf (stderr, "%s",KNRM); fprintf (stderr, "\n"); } - + } diff --git a/src/p25p1_pdu_data.c b/src/p25p1_pdu_data.c index 47af54c..ff50cd5 100644 --- a/src/p25p1_pdu_data.c +++ b/src/p25p1_pdu_data.c @@ -23,7 +23,7 @@ void p25_decode_rsp(uint8_t C, uint8_t T, uint8_t S, char * rsp_string) else if (T == 5) sprintf (rsp_string, " NACK (NS/VR Sequence Error);"); //depreciated else if (T == 6) sprintf (rsp_string, " NACK (Invalid User on System);"); } - + fprintf (stderr, " Response Packet:%s C: %X; T: %X; S: %X; ", rsp_string, C, T, S); } @@ -54,7 +54,7 @@ void p25_decode_sap(uint8_t SAP, char * sap_string) else if (SAP == 48) sprintf (sap_string, " Location Service;"); else if (SAP == 61) sprintf (sap_string, " Trunking Control;"); else if (SAP == 63) sprintf (sap_string, " Encrypted Trunking Control;"); - + //catch all for everything else else sprintf (sap_string, " Unknown SAP;"); @@ -66,12 +66,12 @@ void lfsr_64_to_128(uint8_t * iv) { uint64_t lfsr = 0, bit = 0; - lfsr = ((uint64_t)iv[0] << 56ULL) + ((uint64_t)iv[1] << 48ULL) + ((uint64_t)iv[2] << 40ULL) + ((uint64_t)iv[3] << 32ULL) + + lfsr = ((uint64_t)iv[0] << 56ULL) + ((uint64_t)iv[1] << 48ULL) + ((uint64_t)iv[2] << 40ULL) + ((uint64_t)iv[3] << 32ULL) + ((uint64_t)iv[4] << 24ULL) + ((uint64_t)iv[5] << 16ULL) + ((uint64_t)iv[6] << 8ULL) + ((uint64_t)iv[7] << 0ULL); uint8_t cnt = 0, x = 64; - for(cnt = 0;cnt < 64; cnt++) + for(cnt = 0;cnt < 64; cnt++) { //63,61,45,37,27,14 // Polynomial is C(x) = x^64 + x^62 + x^46 + x^38 + x^27 + x^15 + 1 @@ -142,7 +142,7 @@ uint8_t p25_decrypt_pdu(dsd_opts * opts, dsd_state * state, uint8_t * input, uin aes_iv[4] = ((mi & 0xFF000000) >> 24); aes_iv[5] = ((mi & 0xFF0000) >> 16); aes_iv[6] = ((mi & 0xFF00) >> 8); - aes_iv[7] = ((mi & 0xFF) >> 0); + aes_iv[7] = ((mi & 0xFF) >> 0); lfsr_64_to_128(aes_iv); @@ -182,7 +182,7 @@ uint8_t p25_decrypt_pdu(dsd_opts * opts, dsd_state * state, uint8_t * input, uin //if no key loaded from loader, check state->R for key if (des_key == 0) des_key = state->R; - + ks_idx = 8; //offset for OFB discard round if (des_key) @@ -204,7 +204,7 @@ uint8_t p25_decrypt_pdu(dsd_opts * opts, dsd_state * state, uint8_t * input, uin //if no key loaded from loader, check state->R for key if (rc4_key == 0) rc4_key = state->R; - + ks_idx = 0; //offset uint8_t rc4_kiv[13]; memset (rc4_kiv, 0, sizeof(rc4_key)); @@ -214,7 +214,7 @@ uint8_t p25_decrypt_pdu(dsd_opts * opts, dsd_state * state, uint8_t * input, uin rc4_kiv[2] = ((rc4_key & 0xFF0000) >> 16); rc4_kiv[3] = ((rc4_key & 0xFF00) >> 8); rc4_kiv[4] = ((rc4_key & 0xFF) >> 0); - + rc4_kiv[5] = ((mi & 0xFF00000000000000) >> 56); rc4_kiv[6] = ((mi & 0xFF000000000000) >> 48); rc4_kiv[7] = ((mi & 0xFF0000000000) >> 40); @@ -418,7 +418,7 @@ void p25_decode_pdu_data(dsd_opts * opts, dsd_state * state, uint8_t * input, in //test if an offset value set, then take the difference between it and the ptr and and add that to the ptr //or perhaps, just assign the ptr to that value + 12? if (offset) ptr = 12 + offset; - + //now start checking for the actual message if (sap == 0 || sap == 4) //User Data or Packet Data (both are UDP typically, same format dmr UDP/IP data) decode_ip_pdu (opts, state, len, input+ptr); @@ -427,7 +427,7 @@ void p25_decode_pdu_data(dsd_opts * opts, dsd_state * state, uint8_t * input, in utf8_to_text(state, 0, len-ptr, input+ptr); //TODO, read initial string, i.e., $GPRMC and properly decode // else //default catch all (debug only) - // { + // { // if (len > ptr) // utf8_to_text(state, 0, len-ptr, input+ptr); // else utf8_to_text(state, 0, len, input+ptr); diff --git a/src/p25p1_pdu_trunking.c b/src/p25p1_pdu_trunking.c index 5889cc5..0402f72 100644 --- a/src/p25p1_pdu_trunking.c +++ b/src/p25p1_pdu_trunking.c @@ -50,26 +50,26 @@ void p25_decode_pdu_trunking(dsd_opts * opts, dsd_state * state, uint8_t * mpdu_ long int ct_freq = process_channel_to_freq(opts, state, channelt); long int cr_freq = process_channel_to_freq(opts, state, channelr); UNUSED(cr_freq); - + state->p25_cc_freq = ct_freq; state->p25_cc_is_tdma = 0; //flag off for CC tuning purposes when system is qpsk - //place the cc freq into the list at index 0 if 0 is empty, or not the same, + //place the cc freq into the list at index 0 if 0 is empty, or not the same, //so we can hunt for rotating CCs without user LCN list if (state->trunk_lcn_freq[0] == 0 || state->trunk_lcn_freq[0] != state->p25_cc_freq) { - state->trunk_lcn_freq[0] = state->p25_cc_freq; - } + state->trunk_lcn_freq[0] = state->p25_cc_freq; + } //only set IF these values aren't already hard set by the user if (state->p2_hardset == 0) { state->p2_wacn = wacn; state->p2_sysid = sysid; - } + } } //RFSS Status Broadcast - Extended 6.2.15.2 - else if (opcode == 0x3A) + else if (opcode == 0x3A) { int lra = mpdu_byte[3]; int lsysid = ((mpdu_byte[4] & 0xF) << 8) | mpdu_byte[5]; @@ -89,7 +89,7 @@ void p25_decode_pdu_trunking(dsd_opts * opts, dsd_state * state, uint8_t * mpdu_ } //Adjacent Status Broadcast (ADJ_STS_BCST) Extended 6.2.2.2 - else if (opcode == 0x3C) + else if (opcode == 0x3C) { int lra = mpdu_byte[3]; int cfva = mpdu_byte[4] >> 4; @@ -98,7 +98,7 @@ void p25_decode_pdu_trunking(dsd_opts * opts, dsd_state * state, uint8_t * mpdu_ int siteid = mpdu_byte[9]; int channelt = (mpdu_byte[12] << 8) | mpdu_byte[13]; int channelr = (mpdu_byte[14] << 8) | mpdu_byte[15]; - int sysclass = mpdu_byte[16]; + int sysclass = mpdu_byte[16]; long int wacn = (mpdu_byte[17] << 12) | (mpdu_byte[18] << 4) | (mpdu_byte[19] >> 4); fprintf (stderr, "%s",KYEL); fprintf (stderr, "\n Adjacent Status Broadcast - Extended\n"); @@ -113,8 +113,8 @@ void p25_decode_pdu_trunking(dsd_opts * opts, dsd_state * state, uint8_t * mpdu_ } - //Group Voice Channel Grant - Extended - else if (opcode == 0x0) + //Group Voice Channel Grant - Extended + else if (opcode == 0x0) { int svc = mpdu_byte[8]; int channelt = (mpdu_byte[14] << 8) | mpdu_byte[15]; @@ -158,7 +158,7 @@ void p25_decode_pdu_trunking(dsd_opts * opts, dsd_state * state, uint8_t * mpdu_ //TG hold on P25p1 Ext -- block non-matching target, allow matching group if (state->tg_hold != 0 && state->tg_hold != group) sprintf (mode, "%s", "B"); if (state->tg_hold != 0 && state->tg_hold == group) sprintf (mode, "%s", "A"); - + //Skip tuning group calls if group calls are disabled if (opts->trunk_tune_group_calls == 0) goto SKIPCALL; @@ -201,7 +201,7 @@ void p25_decode_pdu_trunking(dsd_opts * opts, dsd_state * state, uint8_t * mpdu_ if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); SetFreq(opts->rigctl_sockfd, freq1); state->p25_vc_freq[0] = state->p25_vc_freq[1] = freq1; - opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop + opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop state->last_vc_sync_time = time(NULL); } //rtl @@ -214,12 +214,12 @@ void p25_decode_pdu_trunking(dsd_opts * opts, dsd_state * state, uint8_t * mpdu_ state->last_vc_sync_time = time(NULL); #endif } - } + } } } //Unit to Unit Voice Channel Grant - Extended - else if (opcode == 0x6) + else if (opcode == 0x6) { //I'm not doing EVERY element of this, just enough for tuning! int svc = mpdu_byte[8]; @@ -269,7 +269,7 @@ void p25_decode_pdu_trunking(dsd_opts * opts, dsd_state * state, uint8_t * mpdu_ //TG hold on P25p1 Ext UU -- will want to disable UU_V grants while TG Hold enabled if (state->tg_hold != 0 && state->tg_hold != target) sprintf (mode, "%s", "B"); // if (state->tg_hold != 0 && state->tg_hold == target) sprintf (mode, "%s", "A"); - + //Skip tuning private calls if group calls are disabled if (opts->trunk_tune_private_calls == 0) goto SKIPCALL; @@ -325,7 +325,7 @@ void p25_decode_pdu_trunking(dsd_opts * opts, dsd_state * state, uint8_t * mpdu_ state->last_vc_sync_time = time(NULL); #endif } - } + } } } @@ -362,7 +362,7 @@ void p25_decode_pdu_trunking(dsd_opts * opts, dsd_state * state, uint8_t * mpdu_ state->last_active_time = time(NULL); //Skip tuning private calls if private calls is disabled (are telephone int calls private, or talkgroup?) - if (opts->trunk_tune_private_calls == 0) goto SKIPCALL; + if (opts->trunk_tune_private_calls == 0) goto SKIPCALL; //Skip tuning encrypted calls if enc calls are disabled if ( (svc & 0x40) && opts->trunk_tune_enc_calls == 0) goto SKIPCALL; @@ -418,7 +418,7 @@ void p25_decode_pdu_trunking(dsd_opts * opts, dsd_state * state, uint8_t * mpdu_ SetFreq(opts->rigctl_sockfd, freq); if (state->synctype == 0 || state->synctype == 1) state->p25_vc_freq[0] = freq; opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop - state->last_vc_sync_time = time(NULL); + state->last_vc_sync_time = time(NULL); } //rtl else if (opts->audio_in_type == 3) @@ -430,7 +430,7 @@ void p25_decode_pdu_trunking(dsd_opts * opts, dsd_state * state, uint8_t * mpdu_ state->last_vc_sync_time = time(NULL); #endif } - } + } } if (opts->p25_trunk == 0) { @@ -446,7 +446,7 @@ void p25_decode_pdu_trunking(dsd_opts * opts, dsd_state * state, uint8_t * mpdu_ } //look at Harris Opcodes and payload portion of MPDU - else if (MFID == 0xA4) + else if (MFID == 0xA4) { //TODO: Add Known Opcodes from Manual (all one of them) fprintf (stderr, "%s",KCYN); @@ -496,7 +496,7 @@ void p25_decode_pdu_trunking(dsd_opts * opts, dsd_state * state, uint8_t * mpdu_ //TG hold on MFID90 GRG -- block non-matching target, allow matching group if (state->tg_hold != 0 && state->tg_hold != group) sprintf (mode, "%s", "B"); if (state->tg_hold != 0 && state->tg_hold == group) sprintf (mode, "%s", "A"); - + //Skip tuning group calls if group calls are disabled if (opts->trunk_tune_group_calls == 0) goto SKIPCALL; @@ -539,7 +539,7 @@ void p25_decode_pdu_trunking(dsd_opts * opts, dsd_state * state, uint8_t * mpdu_ if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); SetFreq(opts->rigctl_sockfd, freq1); state->p25_vc_freq[0] = state->p25_vc_freq[1] = freq1; - opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop + opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop state->last_vc_sync_time = time(NULL); } //rtl @@ -552,7 +552,7 @@ void p25_decode_pdu_trunking(dsd_opts * opts, dsd_state * state, uint8_t * mpdu_ state->last_vc_sync_time = time(NULL); #endif } - } + } } } diff --git a/src/p25p1_tdu.c b/src/p25p1_tdu.c index 2af0c91..fbc4825 100644 --- a/src/p25p1_tdu.c +++ b/src/p25p1_tdu.c @@ -34,7 +34,7 @@ processTDU (dsd_opts* opts, dsd_state* state) // TODO: do something useful with the status bits... UNUSED(status); } - + //reset some strings -- since its a tdu, blank out any call strings, only want during actual call sprintf (state->call_string[0], "%s", " "); //21 spaces sprintf (state->call_string[1], "%s", " "); //21 spaces @@ -47,5 +47,5 @@ processTDU (dsd_opts* opts, dsd_state* state) state->payload_miP = 0; state->payload_algid = 0; state->payload_keyid = 0; - + } diff --git a/src/p25p1_tdulc.c b/src/p25p1_tdulc.c index cec6df2..63b566d 100644 --- a/src/p25p1_tdulc.c +++ b/src/p25p1_tdulc.c @@ -415,7 +415,7 @@ processTDULC (dsd_opts* opts, dsd_state* state) LCW_bits[j + 6] = (LCW_bytes[i] >> 1) & 0x01; LCW_bits[j + 7] = (LCW_bytes[i] >> 0) & 0x01; } - + //send to new P25 LCW function if (irrecoverable_errors == 0) { @@ -438,8 +438,8 @@ processTDULC (dsd_opts* opts, dsd_state* state) { fprintf (stderr, "[%02X]", LCW_bytes[i]); } - - + + fprintf (stderr, "%s\n", KNRM); } diff --git a/src/p25p1_tsbk.c b/src/p25p1_tsbk.c index 234e7db..7877537 100644 --- a/src/p25p1_tsbk.c +++ b/src/p25p1_tsbk.c @@ -17,7 +17,7 @@ void processTSBK(dsd_opts * opts, dsd_state * state) memset (state->s_l4, 0, sizeof(state->s_l4)); memset (state->s_r4, 0, sizeof(state->s_r4)); opts->slot_preference = 2; - + //reset some strings when returning from a call in case they didn't get zipped already sprintf (state->call_string[0], "%s", " "); //21 spaces @@ -135,7 +135,7 @@ void processTSBK(dsd_opts * opts, dsd_state * state) PDU[8] = tsbk_byte[8]; PDU[9] = tsbk_byte[9]; //remove CRC to prevent false positive when vPDU goes to look for additional message in block - PDU[10] = 0; //tsbk_byte[10]; + PDU[10] = 0; //tsbk_byte[10]; PDU[11] = 0; //tsbk_byte[11]; PDU[1] = PDU[1] ^ 0x40; //flip bit to make it compatible with MAC_PDUs, i.e. 3D to 7D @@ -205,13 +205,13 @@ void processTSBK(dsd_opts * opts, dsd_state * state) fprintf (stderr, "[%02X]", tsbk_byte[i]); } fprintf (stderr, "\n MFID %02X Protected: %d Last Block: %d", MFID, protectbit, lb); - - if (ec != 0) + + if (ec != 0) { fprintf (stderr, "%s",KRED); fprintf (stderr, " ERR = %d", ec); } - if (err != 0) + if (err != 0) { fprintf (stderr, "%s",KRED); fprintf (stderr, " (CRC ERR)"); @@ -239,8 +239,8 @@ void processTSBK(dsd_opts * opts, dsd_state * state) fprintf (stderr, "%s\n ",KYEL); //unsure if this follows for GRG - // if (svc & 0x80) fprintf (stderr, " Emergency"); - + // if (svc & 0x80) fprintf (stderr, " Emergency"); + if (svc & 0x40) fprintf (stderr, " Encrypted"); //P-bit //unsure if this follows for GRG @@ -319,7 +319,7 @@ void processTSBK(dsd_opts * opts, dsd_state * state) if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); SetFreq(opts->rigctl_sockfd, freq1); state->p25_vc_freq[0] = state->p25_vc_freq[1] = freq1; - opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop + opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop state->last_vc_sync_time = time(NULL); } //rtl @@ -332,7 +332,7 @@ void processTSBK(dsd_opts * opts, dsd_state * state) state->last_vc_sync_time = time(NULL); #endif } - } + } } } @@ -418,7 +418,7 @@ void processTSBK(dsd_opts * opts, dsd_state * state) if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); SetFreq(opts->rigctl_sockfd, tempf); state->p25_vc_freq[0] = state->p25_vc_freq[1] = tempf; - opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop + opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop state->last_vc_sync_time = time(NULL); } //rtl @@ -431,7 +431,7 @@ void processTSBK(dsd_opts * opts, dsd_state * state) state->last_vc_sync_time = time(NULL); #endif } - } + } } } @@ -492,7 +492,7 @@ void processTSBK(dsd_opts * opts, dsd_state * state) } - //Some of these Opcodes that aren't found in any TIA manual come from SDRTrunk (or other sources), + //Some of these Opcodes that aren't found in any TIA manual come from SDRTrunk (or other sources), //but can't verify the accuracy of their meaning/context // else if ( (tsbk_byte[0] & 0x3F) == 0x05 ) // { @@ -568,13 +568,13 @@ void processTSBK(dsd_opts * opts, dsd_state * state) fprintf (stderr, "[%02X]", tsbk_byte[i]); } fprintf (stderr, "\n MFID %02X Protected: %d Last Block: %d", MFID, protectbit, lb); - - if (ec != 0) + + if (ec != 0) { fprintf (stderr, "%s",KRED); fprintf (stderr, " ERR = %d", ec); } - if (err != 0) + if (err != 0) { fprintf (stderr, "%s",KRED); fprintf (stderr, " (CRC ERR)"); @@ -587,7 +587,7 @@ void processTSBK(dsd_opts * opts, dsd_state * state) } //set our WACN and SYSID here now that we have valid ec and crc/checksum - else if (protectbit == 0 && err == 0 && (tsbk_byte[0] & 0x3F) == 0x3B) + else if (protectbit == 0 && err == 0 && (tsbk_byte[0] & 0x3F) == 0x3B) { long int wacn = (tsbk_byte[3] << 12) | (tsbk_byte[4] << 4) | (tsbk_byte[5] >> 4); int sysid = ((tsbk_byte[5] & 0xF) << 8) | tsbk_byte[6]; @@ -598,20 +598,20 @@ void processTSBK(dsd_opts * opts, dsd_state * state) state->p25_cc_freq = process_channel_to_freq(opts, state, channel); state->p25_cc_is_tdma = 0; //flag off for CC tuning purposes when system is qpsk - //place the cc freq into the list at index 0 if 0 is empty, or not the same, + //place the cc freq into the list at index 0 if 0 is empty, or not the same, //so we can hunt for rotating CCs without user LCN list if (state->trunk_lcn_freq[0] == 0 || state->trunk_lcn_freq[0] != state->p25_cc_freq) { - state->trunk_lcn_freq[0] = state->p25_cc_freq; - } + state->trunk_lcn_freq[0] = state->p25_cc_freq; + } //only set IF these values aren't already hard set by the user if (state->p2_hardset == 0) { state->p2_wacn = wacn; state->p2_sysid = sysid; - } - + } + if (opts->payload == 1) { fprintf (stderr, "%s",KCYN); @@ -637,20 +637,20 @@ void processTSBK(dsd_opts * opts, dsd_state * state) fprintf (stderr, "[%02X]", tsbk_byte[i]); } fprintf (stderr, "\n MFID %02X Protected: %d Last Block: %d", MFID, protectbit, lb); - - if (ec != 0) + + if (ec != 0) { fprintf (stderr, "%s",KRED); fprintf (stderr, " ERR = %d", ec); } - if (err != 0) + if (err != 0) { fprintf (stderr, "%s",KRED); fprintf (stderr, " (CRC ERR)"); } fprintf (stderr, "%s ", KNRM); } - } + } //reset for next rep ec = -2; @@ -663,5 +663,5 @@ void processTSBK(dsd_opts * opts, dsd_state * state) } fprintf (stderr, "%s ", KNRM); - fprintf (stderr, "\n"); + fprintf (stderr, "\n"); } diff --git a/src/p25p2_frame.c b/src/p25p2_frame.c index dce904e..ad5ba34 100644 --- a/src/p25p2_frame.c +++ b/src/p25p2_frame.c @@ -36,20 +36,20 @@ const int c0[25] = { 17,16,15,14,13,12,11,10,9,8,7,6 }; -const int c1[24] = { +const int c1[24] = { 10,9,8,7,6,5,22,4,21,3,20,2, 19,1,18,0,17,16,15,14,13,12,11 }; -const int c2[12] = { +const int c2[12] = { 3,2,1,0,10,9,8,7,6,5,4 }; -const int c3[15] = { +const int c3[15] = { 13,12,11,10,9,8,7,6,5,4,3,2,1,0 }; -const int csubset[73] = { +const int csubset[73] = { 0,0,1,2,0,0,1,2,0,0,1,2,0,0,1,2, 0,0,1,3,0,0,1,3,0,1,1,3,0,1,1,3, 0,1,1,3,0,1,1,3,0,1,1,3,0,1,2,3, @@ -392,21 +392,21 @@ void process_ISCH (dsd_opts * opts, dsd_state * state) // //find TS1 if TS0 isn't found // else if (chan_num == 1 && isch_loc == 0) // { - // state->p2_scramble_offset = 12 - framing_counter; + // state->p2_scramble_offset = 12 - framing_counter; // } //new rules for relative position to the only chan 1 we should see if (chan_num == 1 && isch_loc == 0) { - state->p2_scramble_offset = 12 - framing_counter; + state->p2_scramble_offset = 12 - framing_counter; } else if (chan_num == 1 && isch_loc == 1) { - state->p2_scramble_offset = 4 - framing_counter; + state->p2_scramble_offset = 4 - framing_counter; } else if (chan_num == 1 && isch_loc == 2) { - state->p2_scramble_offset = 8 - framing_counter; + state->p2_scramble_offset = 8 - framing_counter; } } @@ -416,7 +416,7 @@ void process_ISCH (dsd_opts * opts, dsd_state * state) } } - + isch_decoded = -1; //reset to bad value after running } @@ -487,7 +487,7 @@ void process_4V (dsd_opts * opts, dsd_state * state) if (state->voice_counter[1] >= 18) state->voice_counter[1] = 0; - + processMbeFrame (opts, state, NULL, ambe_fr1, NULL); if(state->currentslot == 0) { @@ -571,8 +571,8 @@ void process_ESS (dsd_opts * opts, dsd_state * state) parity[i] = ess_a[state->currentslot][i]; } - int ec = 69; - ec = ez_rs28_ess(payload, parity); + int ec = 69; + ec = ez_rs28_ess(payload, parity); int algid = 0; for (short i = 0; i < 8; i++) @@ -764,7 +764,7 @@ void process_ESS (dsd_opts * opts, dsd_state * state) } fprintf (stderr, "%s", KNRM); - state->fourv_counter[state->currentslot] = 0; + state->fourv_counter[state->currentslot] = 0; } @@ -928,7 +928,7 @@ void process_P2_DUID (dsd_opts * opts, dsd_state * state) fprintf (stderr, "\n"); fprintf (stderr,"%s ", timestr); fprintf (stderr, " P25p2 "); - + if (timestr != NULL) { free (timestr); @@ -1149,7 +1149,7 @@ void process_P2_DUID (dsd_opts * opts, dsd_state * state) void processP2 (dsd_opts * opts, dsd_state * state) { - state->dmr_stereo = 1; + state->dmr_stereo = 1; p2_dibit_buffer (opts, state); voice = 0; @@ -1157,15 +1157,15 @@ void processP2 (dsd_opts * opts, dsd_state * state) for (framing_counter = 0; framing_counter < 4; framing_counter++) { //run ISCH in here so we know when to start descramble offset - process_ISCH (opts, state); + process_ISCH (opts, state); } //set initial current slot depending on offset value if (state->p2_scramble_offset % 2) { - state->currentslot = 1; + state->currentslot = 1; } - else state->currentslot = 0; + else state->currentslot = 0; //frame_scramble runs lfsr and creates an array of unscrambled bits to pull from process_Frame_Scramble (opts, state); @@ -1173,8 +1173,8 @@ void processP2 (dsd_opts * opts, dsd_state * state) //process DUID will run through all collected frames and handle them appropriately process_P2_DUID (opts, state); - state->dmr_stereo = 0; + state->dmr_stereo = 0; state->p2_is_lcch = 0; - fprintf (stderr, "\n"); + fprintf (stderr, "\n"); } diff --git a/src/p25p2_vpdu.c b/src/p25p2_vpdu.c index 936ee88..fd2fef5 100644 --- a/src/p25p2_vpdu.c +++ b/src/p25p2_vpdu.c @@ -13,7 +13,7 @@ static const uint8_t mac_msg_len[256] = { 0, 7, 8, 7, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //0F 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //1F 0, 14, 15, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //2F - 5, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //3F + 5, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //3F 9, 7, 9, 0, 9, 8, 9, 0, 10, 10, 9, 0, 10, 0, 0, 0, //4F 0, 0, 0, 0, 9, 7, 0, 0, 10, 0, 7, 0, 10, 8, 14, 7, //5F //reverted previous changes here 9, 9, 0, 0, 9, 0, 0, 9, 10, 0, 7, 10, 10, 7, 0, 9, //6F @@ -23,7 +23,7 @@ static const uint8_t mac_msg_len[256] = { 16, 0, 0, 11, 13, 11, 11, 11, 10, 0, 0, 0, 0, 0, 0, 0, //AF 17, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //BF, B0 was 0, set to 17 (Harris again), B5 Tait 0, set to 5 11, 0, 0, 8, 15, 12, 15, 32, 12, 12, 0, 27, 14, 29, 29, 32, //CF - 0, 0, 0, 0, 0, 0, 9, 0, 14, 29, 11, 27, 14, 0, 40, 11, //DF + 0, 0, 0, 0, 0, 0, 9, 0, 14, 29, 11, 27, 14, 0, 40, 11, //DF 28, 0, 0, 14, 17, 14, 0, 0, 16, 8, 11, 0, 13, 19, 0, 0, //EF 0, 0, 16, 14, 0, 0, 12, 0, 22, 0, 11, 13, 11, 0, 15, 0 }; //FF @@ -42,8 +42,8 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon //b values - 0 = Unique TDMA Message, 1 Phase 1 OSP/ISP abbreviated // 2 = Manufacturer Message, 3 Phase 1 OSP/ISP extended/explicit - int len_a = 0; - int len_b = mac_msg_len[MAC[1]]; + int len_a = 0; + int len_b = mac_msg_len[MAC[1]]; int len_c = 0; //sanity check @@ -70,7 +70,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon //TEMP: assume LCH 0 is the SIGNAL slot, fix for blinking SIGNAL on Slot 2 during inverted slot if (type == 0 && slot == 0) state->dmrburstL = 30; if (type == 1 && slot == 0) state->dmrburstL = 30; - // if (type == 0 && slot == 1) state->dmrburstR = 30; + // if (type == 0 && slot == 1) state->dmrburstR = 30; // if (type == 1 && slot == 1) state->dmrburstR = 30; //Temp Fix: Disable Slot Playback when MAC_SIGNAL present (good CRC), @@ -84,7 +84,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon } - if (len_b == 0 || len_b > 18) + if (len_b == 0 || len_b > 18) { goto END_PDU; } @@ -97,7 +97,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon //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"); - for (int i = 0; i < 2; i++) + for (int i = 0; i < 2; i++) { //MFID90 Voice Grants, A3, A4, and A5 <--I bet A4 here was triggering a phantom call when TSBK sent PDUs here @@ -167,7 +167,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon } } - + //rigctl if (opts->use_rigctl == 1) { @@ -187,7 +187,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon state->last_vc_sync_time = time(NULL); #endif } - } + } } //if playing back files, and we still want to see what freqs are in use in the ncurses terminal //might only want to do these on a grant update, and not a grant by itself? @@ -197,7 +197,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon if (state->synctype == 0 || state->synctype == 1) state->p25_vc_freq[0] = freq; //P2 TDMA else state->p25_vc_freq[0] = state->p25_vc_freq[1] = freq; - } + } } //MFID90 Group Regroup Channel Grant - Explicit @@ -267,7 +267,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon } } - + if (opts->use_rigctl == 1) { if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); @@ -286,7 +286,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon state->last_vc_sync_time = time(NULL); #endif } - } + } } //if playing back files, and we still want to see what freqs are in use in the ncurses terminal //might only want to do these on a grant update, and not a grant by itself? @@ -337,7 +337,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon else loop = 2; //assigned inside loop long int tunable_freq = 0; - int tunable_chan = 0; + int tunable_chan = 0; int tunable_group = 0; for (int j = 0; j < loop; j++) @@ -349,7 +349,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon tunable_chan = channel1; tunable_group = group1; } - else + else { tunable_freq = freq2; tunable_chan = channel2; @@ -414,7 +414,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop state->last_vc_sync_time = time(NULL); j = 8; //break loop - + } //rtl else if (opts->audio_in_type == 3) @@ -427,7 +427,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon j = 8; //break loop #endif } - } + } } //if playing back files, and we still want to see what freqs are in use in the ncurses terminal //might only want to do these on a grant update, and not a grant by itself? @@ -535,7 +535,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); SetFreq(opts->rigctl_sockfd, freq); state->p25_vc_freq[0] = state->p25_vc_freq[1] = freq; - opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop + opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop state->last_vc_sync_time = time(NULL); } //rtl @@ -548,7 +548,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon state->last_vc_sync_time = time(NULL); #endif } - } + } } //if playing back files, and we still want to see what freqs are in use in the ncurses terminal //might only want to do these on a grant update, and not a grant by itself? @@ -606,7 +606,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon state->last_active_time = time(NULL); //Skip tuning private calls if private calls is disabled (are telephone int calls private, or talkgroup?) - if (opts->trunk_tune_private_calls == 0) goto SKIPCALL; + if (opts->trunk_tune_private_calls == 0) goto SKIPCALL; //Skip tuning encrypted calls if enc calls are disabled if ( (svc & 0x40) && opts->trunk_tune_enc_calls == 0) goto SKIPCALL; @@ -667,7 +667,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon SetFreq(opts->rigctl_sockfd, freq); if (state->synctype == 0 || state->synctype == 1) state->p25_vc_freq[0] = freq; opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop - state->last_vc_sync_time = time(NULL); + state->last_vc_sync_time = time(NULL); } //rtl else if (opts->audio_in_type == 3) @@ -679,7 +679,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon state->last_vc_sync_time = time(NULL); #endif } - } + } } if (opts->p25_trunk == 0) { @@ -727,7 +727,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon state->last_active_time = time(NULL); //Skip tuning private calls if private calls is disabled - if (opts->trunk_tune_private_calls == 0) goto SKIPCALL; + if (opts->trunk_tune_private_calls == 0) goto SKIPCALL; //Skip tuning encrypted calls if enc calls are disabled -- abb formats do not carry svc bits :( // if (opts->trunk_tune_enc_calls == 0) goto SKIPCALL; //enable, or disable? @@ -788,7 +788,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon SetFreq(opts->rigctl_sockfd, freq); if (state->synctype == 0 || state->synctype == 1) state->p25_vc_freq[0] = freq; opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop - state->last_vc_sync_time = time(NULL); + state->last_vc_sync_time = time(NULL); } //rtl else if (opts->audio_in_type == 3) @@ -800,7 +800,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon state->last_vc_sync_time = time(NULL); #endif } - } + } } if (opts->p25_trunk == 0) { @@ -875,7 +875,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon else loop = 2; //assigned inside loop long int tunable_freq = 0; - int tunable_chan = 0; + int tunable_chan = 0; int tunable_group = 0; for (int j = 0; j < loop; j++) @@ -897,7 +897,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon tunable_chan = channelt1; tunable_group = group1; } - else + else { tunable_freq = freq2t; tunable_chan = channelt2; @@ -950,7 +950,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon } } - + if (opts->use_rigctl == 1) { if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); @@ -971,7 +971,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon j = 8; //break loop #endif } - } + } } if (opts->p25_trunk == 0) { @@ -1066,7 +1066,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon int loop = 3; long int tunable_freq = 0; - int tunable_chan = 0; + int tunable_chan = 0; int tunable_group = 0; for (int j = 0; j < loop; j++) @@ -1098,7 +1098,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon tunable_chan = channel2; tunable_group = group2; } - else + else { tunable_freq = freq3; tunable_chan = channel3; @@ -1176,7 +1176,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon j = 8; //break loop #endif } - } + } } if (opts->p25_trunk == 0) { @@ -1187,7 +1187,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon //P2 TDMA else state->p25_vc_freq[0] = state->p25_vc_freq[1] = tunable_freq; } - } + } } } @@ -1227,7 +1227,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon else loop = 2; //assigned inside loop long int tunable_freq = 0; - int tunable_chan = 0; + int tunable_chan = 0; int tunable_group = 0; for (int j = 0; j < loop; j++) @@ -1239,7 +1239,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon tunable_chan = channel1; tunable_group = group1; } - else + else { tunable_freq = freq2; tunable_chan = channel2; @@ -1301,7 +1301,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon SetFreq(opts->rigctl_sockfd, tunable_freq); //probably best to only set these when really tuning state->p25_vc_freq[0] = state->p25_vc_freq[1] = tunable_freq; - opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop + opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop state->last_vc_sync_time = time(NULL); j = 8; //break loop } @@ -1317,7 +1317,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon j = 8; //break loop #endif } - } + } } if (opts->p25_trunk == 0) { @@ -1419,7 +1419,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon // opts->slot1_on = 1; // opts->slot2_on = 0; // } - + } } @@ -1443,7 +1443,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon state->last_vc_sync_time = time(NULL); #endif } - } + } } if (opts->p25_trunk == 0) { @@ -1555,7 +1555,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon //enable voice on slot 1 (just in case they start talking too, but probably won't) opts->slot1_on = 1; - } + } } @@ -1566,7 +1566,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon SetFreq(opts->rigctl_sockfd, freq); if (state->synctype == 0 || state->synctype == 1) state->p25_vc_freq[0] = freq; opts->p25_is_tuned = 1; //set to 1 to set as currently tuned so we don't keep tuning nonstop - state->last_vc_sync_time = time(NULL); + state->last_vc_sync_time = time(NULL); } //rtl else if (opts->audio_in_type == 3) @@ -1578,7 +1578,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon state->last_vc_sync_time = time(NULL); #endif } - } + } } if (opts->p25_trunk == 0) { @@ -1631,7 +1631,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon //MFID90 Group Regroup Add Command if (MAC[1+len_a] == 0x81 && MAC[2+len_a] == 0x90) //needs MAC message len update, may work same as explicit enc regroup? { - fprintf (stderr, "\n MFID90 Group Regroup Add Command "); + fprintf (stderr, "\n MFID90 Group Regroup Add Command "); } //the len on these indicate they are always a single messages, foregoing the +len_a index pointer @@ -1658,7 +1658,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon } //System Service Broadcast - if (MAC[1+len_a] == 0x78) + if (MAC[1+len_a] == 0x78) { int TWV = MAC[2+len_a]; //TWUID Validity int SSA = (MAC[3+len_a] << 16) | (MAC[4+len_a] << 8) | MAC[5+len_a]; @@ -1669,7 +1669,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon } //RFSS Status Broadcast - Implicit - if (MAC[1+len_a] == 0x7A) + if (MAC[1+len_a] == 0x7A) { int lra = MAC[2+len_a]; int lsysid = ((MAC[3+len_a] & 0xF) << 8) | MAC[4+len_a]; @@ -1680,13 +1680,13 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon fprintf (stderr, "\n RFSS Status Broadcast - Implicit \n"); fprintf (stderr, " LRA [%02X] SYSID [%03X] RFSS ID [%03d] SITE ID [%03d] CHAN [%04X] SSC [%02X] ", lra, lsysid, rfssid, siteid, channel, sysclass); process_channel_to_freq (opts, state, channel); - + state->p2_siteid = siteid; state->p2_rfssid = rfssid; } //RFSS Status Broadcast - Explicit - if (MAC[1+len_a] == 0xFA) + if (MAC[1+len_a] == 0xFA) { int lra = MAC[2+len_a]; int lsysid = ((MAC[3+len_a] & 0xF) << 8) | MAC[4+len_a]; @@ -1719,7 +1719,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon // else if (ans == 0x21) fprintf (stderr, " - Deny;"); // else if (ans == 0x22) fprintf (stderr, " - Wait;"); // else fprintf (stderr, " - Other;"); //unspecified - + // } //TODO: Restructure this function to group standard Opcodes away from MFID 90 and MFID A4, and Unknown MFID @@ -1730,7 +1730,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon // 6.2.36 Manufacturer Specific regarding octet 3 as len int len = MAC[3+len_a] & 0x3F; int res = MAC[3+len_a] >> 6; - + //sanity check that we don't exceed the max MAC array size if (len > 24) len = 24; //should never exceed this len, but just in case it does @@ -1755,14 +1755,14 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon else { - fprintf (stderr, "\n MFID A4 (Harris); Res: %d; Len: %d; Opcode: %02llX; ", res, len, MAC[1+len_a] & 0x3F); //first two bits are the b0 and b1 + fprintf (stderr, "\n MFID A4 (Harris); Res: %d; Len: %d; Opcode: %02llX; ", res, len, MAC[1+len_a] & 0x3F); //first two bits are the b0 and b1 for (i = 4; i <= len; i++) fprintf (stderr, "%02llX", MAC[i+len_a]); } - + } - //This is now confirmed to have the Harris Talker GPS, but the structure is unusual compared to other MFID messages, + //This is now confirmed to have the Harris Talker GPS, but the structure is unusual compared to other MFID messages, //the A4 indicator is one octet more to the 'right' than is normative, so I cannot verify the len value (0x11, or 17). //Its possible the 0x80 is the 'Manufacturer Message' Opcode, which in the manual shows the rest of the //octets are not normative, and as such, can't say there is a len value (but should assume entire the SACCH/FACCH field) @@ -1830,7 +1830,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon fprintf (stderr, " Payload: "); for (i = 4; i < len; i++) fprintf (stderr, "%02llX", MAC[i+len_a]); - + len_b = len; } @@ -1880,13 +1880,13 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon offhour = -( (ltoff & 0b11111 ) / 2); } else offhour = ( (ltoff & 0b11111 ) / 2); - + int seconds = slots / 135; //very rough estimation, but may be close enough for grins if (seconds > 59) seconds = 59; //sanity check for rounding error if (year != 0) //if time is synced in this PDU { - fprintf (stderr, "\n Date: 20%02d.%02d.%02d Time: %02d:%02d:%02d UTC", + fprintf (stderr, "\n Date: 20%02d.%02d.%02d Time: %02d:%02d:%02d UTC", year, month, day, hour, min, seconds); if (offhour != 0) //&& vl == 1 fprintf (stderr, "\n Local Time Offset: %.01f Hours;", offhour); @@ -1895,8 +1895,8 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon fprintf (stderr, "\n US: %d; IST: %d; MM: %d; MC: %d; VL: %d; Sync Slots: %d; ", us, ist, mm, mc, vl, slots); } - //identifier update VHF/UHF - if (MAC[1+len_a] == 0x74) + //identifier update VHF/UHF + if (MAC[1+len_a] == 0x74) { state->p25_chan_iden = MAC[2+len_a] >> 4; int iden = state->p25_chan_iden; @@ -1969,7 +1969,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon state->p25_trans_off[iden] = (MAC[4+len_a] << 6) | (MAC[5+len_a] >> 2); state->p25_chan_spac[iden] = ((MAC[5+len_a] & 0x3) << 8) | MAC[6+len_a]; state->p25_base_freq[iden] = (MAC[7+len_a] << 24) | (MAC[8+len_a] << 16) | (MAC[9+len_a] << 8) | (MAC[10+len_a] << 0); - int lwacn = (MAC[11+len_a] << 12) | (MAC[12+len_a] << 4) | ((MAC[13+len_a] & 0xF0) >> 4); + int lwacn = (MAC[11+len_a] << 12) | (MAC[12+len_a] << 4) | ((MAC[13+len_a] & 0xF0) >> 4); int lsysid = ((MAC[13+len_a] & 0xF) << 8) | MAC[14+len_a]; fprintf (stderr, "\n Identifier Update for TDMA - Extended\n"); @@ -2026,13 +2026,13 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon //place the cc freq into the list at index 0 if 0 is empty so we can hunt for rotating CCs without user LCN list if (state->trunk_lcn_freq[1] == 0) { - state->trunk_lcn_freq[1] = freq1; + state->trunk_lcn_freq[1] = freq1; state->trunk_lcn_freq[2] = freq2; state->lcn_freq_count = 3; //increment to three } state->p2_siteid = siteid; - state->p2_rfssid = rfssid; + state->p2_rfssid = rfssid; } @@ -2097,7 +2097,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon fprintf (stderr, " SSN: %02d;", ssn); if ( (tga & 0x2) == 2) //group WGID to supergroup - { + { int sg = (MAC[5+len_a] << 8) | MAC[6+len_a]; int key = (MAC[7+len_a] << 8) | MAC[8+len_a]; int alg = MAC[9+len_a]; @@ -2147,7 +2147,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon int res = (MAC[3+len_a] >> 2) & 0x3F; int RV = (MAC[2+len_a] >> 0) & 0x3; int src = (MAC[8+len_a] << 16) | (MAC[9+len_a] << 8) | MAC[10+len_a]; - int uwacn = (MAC[4+len_a] << 12) | (MAC[5+len_a] << 4) | ((MAC[6+len_a] & 0xF0) >> 4); + int uwacn = (MAC[4+len_a] << 12) | (MAC[5+len_a] << 4) | ((MAC[6+len_a] & 0xF0) >> 4); int usys = ((MAC[6+len_a] & 0xF) << 8) | MAC[7+len_a]; fprintf (stderr, "\n Unit Registration Response - WACN: %05X; SYS: %03X; SRC: %d", uwacn, usys, src); if (res) fprintf (stderr, " RES: %d;", res); @@ -2197,7 +2197,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon if (MAC[1+len_a] == 0x6F) { int src = (MAC[7+len_a] << 16) | (MAC[8+len_a] << 8) | MAC[9+len_a]; - int uwacn = (MAC[3+len_a] << 12) | (MAC[4+len_a] << 4) | ((MAC[5+len_a] & 0xF0) >> 4); + int uwacn = (MAC[3+len_a] << 12) | (MAC[4+len_a] << 4) | ((MAC[5+len_a] & 0xF0) >> 4); int usys = ((MAC[5+len_a] & 0xF) << 8) | MAC[6+len_a]; fprintf (stderr, "\n Unit Deregistration Acknowlegement - WACN: %05X; SYS: %03X; SRC: %d", uwacn, usys, src); if (MAC[1+len_a] == 0xEF) fprintf (stderr, " - Extended;"); @@ -2346,10 +2346,10 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon } } - + //network status broadcast, abbreviated - if (MAC[1+len_a] == 0x7B) + if (MAC[1+len_a] == 0x7B) { int lra = MAC[2+len_a]; int lwacn = (MAC[3+len_a] << 12) | (MAC[4+len_a] << 4) | ((MAC[5+len_a] & 0xF0) >> 4); @@ -2369,12 +2369,12 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon state->p2_cc = lcolorcode; } - //place the cc freq into the list at index 0 if 0 is empty, or not the same, + //place the cc freq into the list at index 0 if 0 is empty, or not the same, //so we can hunt for rotating CCs without user LCN list if (state->trunk_lcn_freq[0] == 0 || state->trunk_lcn_freq[0] != state->p25_cc_freq) { - state->trunk_lcn_freq[0] = state->p25_cc_freq; - } + state->trunk_lcn_freq[0] = state->p25_cc_freq; + } } //network status broadcast, extended @@ -2403,7 +2403,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon } //Adjacent Status Broadcast, abbreviated - if (MAC[1+len_a] == 0x7C) + if (MAC[1+len_a] == 0x7C) { int lra = MAC[2+len_a]; int cfva = MAC[3+len_a] >> 4; @@ -2425,16 +2425,16 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon } //Adjacent Status Broadcast, extended - if (MAC[1+len_a] == 0xFC) + if (MAC[1+len_a] == 0xFC) { int lra = MAC[2+len_a]; - int cfva = MAC[3+len_a] >> 4; + int cfva = MAC[3+len_a] >> 4; int lsysid = ((MAC[3+len_a] & 0xF) << 8) | MAC[4+len_a]; int rfssid = MAC[5+len_a]; int siteid = MAC[6+len_a]; int channelt = (MAC[7+len_a] << 8) | MAC[8+len_a]; int channelr = (MAC[9+len_a] << 8) | MAC[10+len_a]; - int sysclass = MAC[11+len_a]; //need to re-check this + int sysclass = MAC[11+len_a]; //need to re-check this fprintf (stderr, "\n Adjacent Status Broadcast - Extended\n"); fprintf (stderr, " LRA [%02X] RFSS[%03d] SITE [%03d] SYSID [%03X] CHAN-T [%04X] CHAN-R [%04X] SSC [%02X]\n ", lra, rfssid, siteid, lsysid, channelt, channelr, sysclass); if (cfva & 0x8) fprintf (stderr, " Conventional"); @@ -2450,7 +2450,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon SKIPCALL: ; //do nothing - if ( (len_b + len_c) < 24 && len_c != 0) + if ( (len_b + len_c) < 24 && len_c != 0) { len_a = len_b; } @@ -2462,7 +2462,7 @@ void process_MAC_VPDU(dsd_opts * opts, dsd_state * state, int type, unsigned lon } END_PDU: - state->p2_is_lcch = 0; + state->p2_is_lcch = 0; //debug printing if (opts->payload == 1 && MAC[1] != 0) //print only if not a null type //&& MAC[1] != 0 //&& MAC[2] != 0 { diff --git a/src/p25p2_xcch.c b/src/p25p2_xcch.c index fc0b94b..06a052d 100644 --- a/src/p25p2_xcch.c +++ b/src/p25p2_xcch.c @@ -92,7 +92,7 @@ void process_SACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[180] //if (state->currentslot == 0) state->dmrburstL = 14; //else state->dmrburstR = 14; goto END_SMAC; - } + } } } } @@ -140,7 +140,7 @@ void process_SACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[180] The outbound SACCH for the talker radio containing the talker ID information is required at the talker radio site and optional at other sites. (So, if its from an external site, then it can be zero?) - + */ // if (state->lastsrc == 0) fprintf (stderr, "External "); @@ -285,13 +285,13 @@ void process_SACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[180] //remember, slots are inverted here, so set the opposite ones if (state->currentslot == 1) { - + state->fourv_counter[0] = 0; state->voice_counter[0] = 0; state->dropL = 256; state->dmrburstL = 23; - state->payload_algid = 0; - state->payload_keyid = 0; + state->payload_algid = 0; + state->payload_keyid = 0; fprintf (stderr, "\n VCH 0 - "); fprintf (stderr, "TG %d ", state->lasttg); @@ -314,7 +314,7 @@ void process_SACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[180] } if (state->currentslot == 0) { - + state->fourv_counter[1] = 0; state->voice_counter[1] = 0; state->dropR = 256; @@ -377,9 +377,9 @@ void process_SACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[180] state->lastsrc = 0; state->lasttgR = 0; state->lastsrcR = 0; - state->payload_algid = 0; + state->payload_algid = 0; state->payload_keyid = 0; - state->payload_algidR = 0; + state->payload_algidR = 0; state->payload_keyidR = 0; // state->payload_miP = 0; //reset some strings @@ -390,7 +390,7 @@ void process_SACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[180] opts->p25_is_tuned = 0; state->p25_vc_freq[0] = state->p25_vc_freq[1] = 0; if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); - SetFreq(opts->rigctl_sockfd, state->p25_cc_freq); + SetFreq(opts->rigctl_sockfd, state->p25_cc_freq); } //rtl else if (opts->audio_in_type == 3) @@ -400,9 +400,9 @@ void process_SACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[180] state->lastsrc = 0; state->lasttgR = 0; state->lastsrcR = 0; - state->payload_algid = 0; + state->payload_algid = 0; state->payload_keyid = 0; - state->payload_algidR = 0; + state->payload_algidR = 0; state->payload_keyidR = 0; // state->payload_miP = 0; //reset some strings @@ -460,7 +460,7 @@ void process_SACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[180] if (state->currentslot == 1) state->dmrburstL = 21; else state->dmrburstR = 21; #endif - + fprintf (stderr, " MAC_ACTIVE "); fprintf (stderr, "%s", KYEL); process_MAC_VPDU(opts, state, 1, SMAC); @@ -473,7 +473,7 @@ void process_SACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[180] state->dmrburstL = 22; //close any open MBEout files if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state); - } + } else { state->dmrburstR = 22; @@ -722,7 +722,7 @@ void process_FACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[156] fprintf (stderr, "%s", KRED); if (state->currentslot == 0) { - + state->fourv_counter[0] = 0; state->voice_counter[0] = 0; state->dropL = 256; @@ -741,17 +741,17 @@ void process_FACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[156] //close any open MBEout files if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state); - //blank the call string here + //blank the call string here sprintf (state->call_string[slot], "%s", " "); //21 spaces //reset gain if (opts->floating_point == 1) state->aout_gain = opts->audio_gain; //reset - + } if (state->currentslot == 1) { - + state->fourv_counter[1] = 0; state->voice_counter[1] = 0; state->dropR = 256; @@ -784,7 +784,7 @@ void process_FACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[156] { if (opts->p25_trunk == 1 && opts->p25_is_tuned == 1) { - + //if P25p2 VCH and going back to P25p1 CC, flip symbolrate if (state->p25_cc_is_tdma == 0) { @@ -802,9 +802,9 @@ void process_FACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[156] state->lastsrc = 0; state->lasttgR = 0; state->lastsrcR = 0; - state->payload_algid = 0; + state->payload_algid = 0; state->payload_keyid = 0; - state->payload_algidR = 0; + state->payload_algidR = 0; state->payload_keyidR = 0; // state->payload_miP = 0; //reset some strings @@ -815,7 +815,7 @@ void process_FACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[156] opts->p25_is_tuned = 0; state->p25_vc_freq[0] = state->p25_vc_freq[1] = 0; if (opts->setmod_bw != 0 ) SetModulation(opts->rigctl_sockfd, opts->setmod_bw); - SetFreq(opts->rigctl_sockfd, state->p25_cc_freq); + SetFreq(opts->rigctl_sockfd, state->p25_cc_freq); } //rtl else if (opts->audio_in_type == 3) @@ -825,9 +825,9 @@ void process_FACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[156] state->lastsrc = 0; state->lasttgR = 0; state->lastsrcR = 0; - state->payload_algid = 0; + state->payload_algid = 0; state->payload_keyid = 0; - state->payload_algidR = 0; + state->payload_algidR = 0; state->payload_keyidR = 0; // state->payload_miP = 0; //reset some strings @@ -890,9 +890,9 @@ void process_FACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[156] // } // } - //blank the call string here + //blank the call string here sprintf (state->call_string[slot], "%s", " "); //21 spaces - + } if (opcode == 0x4 && err == 0) { @@ -907,7 +907,7 @@ void process_FACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[156] if (state->currentslot == 0) state->dmrburstL = 21; else state->dmrburstR = 21; #endif - + fprintf (stderr, " MAC_ACTIVE "); fprintf (stderr, "%s", KYEL); process_MAC_VPDU(opts, state, 0, FMAC); @@ -920,13 +920,13 @@ void process_FACCH_MAC_PDU (dsd_opts * opts, dsd_state * state, int payload[156] state->dmrburstL = 22; //close any open MBEout files if (opts->mbe_out_f != NULL) closeMbeOutFile (opts, state); - } + } else { state->dmrburstR = 22; //close any open MBEout files if (opts->mbe_out_fR != NULL) closeMbeOutFileR (opts, state); - } + } fprintf (stderr, " MAC_HANGTIME "); fprintf (stderr, "%s", KYEL); process_MAC_VPDU(opts, state, 0, FMAC); diff --git a/src/provoice.c b/src/provoice.c index 08d2c5c..780deef 100644 --- a/src/provoice.c +++ b/src/provoice.c @@ -13,7 +13,7 @@ void processProVoice (dsd_opts * opts, dsd_state * state) //raw bits storage for analysis uint8_t raw_bits[800]; - memset (raw_bits, 0, sizeof(raw_bits)); + memset (raw_bits, 0, sizeof(raw_bits)); //raw bytes storage for analysis uint8_t raw_bytes[100]; memset (raw_bytes, 0, sizeof(raw_bytes)); @@ -32,11 +32,11 @@ void processProVoice (dsd_opts * opts, dsd_state * state) fprintf (stderr, "%s", KGRN); if (state->lasttg > 100000) { // I-Call - fprintf (stderr, " Site: %lld Target: %d Source: %d LCN: %d ", + fprintf (stderr, " Site: %lld Target: %d Source: %d LCN: %d ", state->edacs_site_id, state->lasttg - 100000, state->lastsrc, state->edacs_tuned_lcn); } else { // Group call - fprintf (stderr, " Site: %lld Group: %d Source: %d LCN: %d ", + fprintf (stderr, " Site: %lld Group: %d Source: %d LCN: %d ", state->edacs_site_id, state->lasttg, state->lastsrc, state->edacs_tuned_lcn); } fprintf (stderr, "%s", KNRM); @@ -45,7 +45,7 @@ void processProVoice (dsd_opts * opts, dsd_state * state) else if (opts->p25_trunk == 1 && opts->p25_is_tuned == 1 && state->ea_mode == 0) { fprintf (stderr, "%s", KGRN); - fprintf (stderr, " Site: %lld AFS: %d-%d LCN: %d ", + fprintf (stderr, " Site: %lld AFS: %d-%d LCN: %d ", state->edacs_site_id, (state->lastsrc >> 7) & 0xF, state->lastsrc & 0x7F, state->edacs_tuned_lcn); fprintf (stderr, "%s", KNRM); } @@ -235,7 +235,7 @@ void processProVoice (dsd_opts * opts, dsd_state * state) raw_bits[k++] = dibit; for (i = 0; i < 16; i++) - raw_bits[k++] = getDibit (opts, state); + raw_bits[k++] = getDibit (opts, state); bf = (uint16_t)ConvertBitIntoBytes(&raw_bits[54*8], 16); @@ -285,7 +285,7 @@ void processProVoice (dsd_opts * opts, dsd_state * state) imbe7100_fr2[*w][*x] = dibit; w++; x++; - raw_bits[k++] = dibit; + raw_bits[k++] = dibit; } // spacer bits @@ -415,7 +415,7 @@ void processProVoice (dsd_opts * opts, dsd_state * state) fprintf (stderr, "\n pV Payload Dump: \n "); for (i = 0; i < k/8; i++) { - + // if ( (i != 0) && ((i%26) == 0) ) // fprintf (stderr, "\n "); diff --git a/src/pulse_devices.c b/src/pulse_devices.c index 8963ae8..448e649 100644 --- a/src/pulse_devices.c +++ b/src/pulse_devices.c @@ -166,7 +166,7 @@ int pa_get_devicelist(pa_devicelist_t *input, pa_devicelist_t *output) // Now we wait for our operation to complete. When it's // complete our pa_output_devicelist is filled out, and we move // along to the next state - if (pa_operation_get_state(pa_op) == PA_OPERATION_DONE) + if (pa_operation_get_state(pa_op) == PA_OPERATION_DONE) { pa_operation_unref(pa_op); @@ -199,7 +199,7 @@ int pa_get_devicelist(pa_devicelist_t *input, pa_devicelist_t *output) // or not the iteration should block until something is ready to be // done. Set it to zero for non-blocking. pa_mainloop_iterate(pa_ml, 1, NULL); - + } } diff --git a/src/rtl_sdr_fm.cpp b/src/rtl_sdr_fm.cpp index ad04667..787aa5a 100644 --- a/src/rtl_sdr_fm.cpp +++ b/src/rtl_sdr_fm.cpp @@ -1058,7 +1058,7 @@ void open_rtlsdr_stream(dsd_opts *opts) if (opts->rtl_udp_port != 0) port = opts->rtl_udp_port; //set this here, only open socket thread if set if (opts->rtl_gain_value > 0) { dongle.gain = opts->rtl_gain_value * 10; //multiple by ten to make it consitent with the way rtl_fm works - } + } /* quadruple sample_rate to limit to Δθ to ±π/2 */ demod.rate_in *= demod.post_downsample; @@ -1182,7 +1182,7 @@ void rtl_dev_tune(dsd_opts * opts, long int frequency) pthread_rwlock_wrlock(&output.rw); //prevent possible segfault when cleaning the queue rtl_clean_queue(); - pthread_rwlock_unlock(&output.rw); //resume + pthread_rwlock_unlock(&output.rw); //resume } diff --git a/src/ysf.c b/src/ysf.c index eeca048..023eae6 100644 --- a/src/ysf.c +++ b/src/ysf.c @@ -32,41 +32,41 @@ uint8_t fr_interleave[144] = { uint8_t pn95[512] = { 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, - 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, - 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, - 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, - 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, - 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, - 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, - 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, - 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, - 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, - 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, - 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, - 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, - 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, - 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, - 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, - 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, - 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, - 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, - 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, - 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, - 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, - 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, - 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, - 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, - 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, - 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, - 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, + 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, + 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, + 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, + 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, + 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, + 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, + 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, + 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, + 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, + 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, + 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, + 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, + 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, + 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, + 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, + 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, + 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, + 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, + 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, + 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, + 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, + 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, + 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, + 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, + 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, + 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, + 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1 }; //half-rate (from NXDN) -const int YnW[36] = +const int YnW[36] = { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, @@ -75,7 +75,7 @@ const int YnW[36] = 0, 2, 0, 2, 0, 2 }; -const int YnX[36] = +const int YnX[36] = { 23, 10, 22, 9, 21, 8, 20, 7, 19, 6, 18, 5, 17, 4, 16, 3, 15, 2, @@ -84,7 +84,7 @@ const int YnX[36] = 8, 6, 7, 5, 6, 4 }; -const int YnY[36] = +const int YnY[36] = { 0, 2, 0, 2, 0, 2, 0, 2, 0, 3, 0, 3, 1, 3, 1, 3, 1, 3, @@ -93,7 +93,7 @@ const int YnY[36] = 1, 3, 1, 3, 1, 3 }; -const int YnZ[36] = +const int YnZ[36] = { 5, 3, 4, 2, 3, 1, 2, 0, 1, 13, 0, 12, 22, 11, 21, 10, 20, 9, @@ -199,7 +199,7 @@ void ysf_dch_decode (dsd_state * state, uint8_t bn, uint8_t bt, uint8_t fn, uint string2[10] = '\0'; fprintf (stderr, "D/L: "); fprintf (stderr, "%s ", string2); - + //Copy both to Ncurses Call String memcpy (state->ysf_upl, dch_bytes, 10); state->ysf_upl[10] = '\0'; @@ -221,8 +221,8 @@ void ysf_dch_decode (dsd_state * state, uint8_t bn, uint8_t bt, uint8_t fn, uint //copy text to txt storage -- works now (had to expand storage space), but is cumbersome in ncurses (too long) // if (fn < 20) // { - // //switch to checking each byte for a 'nice' ASCII character and - // //not a 'naughty' del/rem/break/garbled non ASCII/ALPHANUMERIC type character + // //switch to checking each byte for a 'nice' ASCII character and + // //not a 'naughty' del/rem/break/garbled non ASCII/ALPHANUMERIC type character // for (i = 0; i < 20; i++) // { // C = dch_bytes[i]; //skipping 0x20 space key @@ -230,9 +230,9 @@ void ysf_dch_decode (dsd_state * state, uint8_t bn, uint8_t bt, uint8_t fn, uint // else state->ysf_txt[fn][i] = 0; //NULL // } // } - + break; - + default: break; @@ -280,7 +280,7 @@ void ysf_dch_decode2 (dsd_state * state, uint8_t bn, uint8_t bt, uint8_t fn, uin memcpy (state->ysf_tgt, dch_bytes, 10); state->ysf_tgt[10] = '\0'; - + break; case 1: @@ -322,7 +322,7 @@ void ysf_dch_decode2 (dsd_state * state, uint8_t bn, uint8_t bt, uint8_t fn, uin rem1[5] = '\0'; fprintf (stderr, "RM1: "); fprintf (stderr, "%s ", rem1); - + memcpy (rem2, dch_bytes+5, 5); rem2[5] = '\0'; fprintf (stderr, "RM2: "); @@ -341,7 +341,7 @@ void ysf_dch_decode2 (dsd_state * state, uint8_t bn, uint8_t bt, uint8_t fn, uin rem1[5] = '\0'; fprintf (stderr, "RM3: "); fprintf (stderr, "%s ", rem1); - + memcpy (rem2, dch_bytes+5, 5); rem2[5] = '\0'; fprintf (stderr, "RM4: "); @@ -364,7 +364,7 @@ static inline uint16_t crc16ysf(const uint8_t buf[], int len) { uint32_t poly = (1<<12) + (1<<5) + (1<<0); uint32_t crc = 0; - for(int i=0; i> 7) & 1; trellis_buf[(i*8)+1] = (m_data[i] >> 6) & 1; @@ -461,7 +461,7 @@ int ysf_conv_dch2 (dsd_opts * opts, dsd_state * state, uint8_t bn, uint8_t bt, u fprintf (stderr, "\n "); fprintf (stderr, "DCH2: "); for (i = 0; i < 12; i++) - fprintf (stderr, "[%02X]", m_data[i]); + fprintf (stderr, "[%02X]", m_data[i]); } @@ -487,7 +487,7 @@ int ysf_conv_dch (dsd_opts * opts, dsd_state * state, uint8_t bn, uint8_t bt, ui uint8_t buf[180]; memset (buf, 0, sizeof(buf)); for (i=0; i<20; i++) { //20*9 = 180 - for (j=0; j<9; j++) { + for (j=0; j<9; j++) { buf[j+(i*9)] = input[i+(j*20)]; } } @@ -516,7 +516,7 @@ int ysf_conv_dch (dsd_opts * opts, dsd_state * state, uint8_t bn, uint8_t bt, ui CNXDNConvolution_chainback(m_data, 176); //176/8 = 22, last 4 (176-180) are trailing zeroes - for(i = 0; i < 22; i++) + for(i = 0; i < 22; i++) { trellis_buf[(i*8)+0] = (m_data[i] >> 7) & 1; trellis_buf[(i*8)+1] = (m_data[i] >> 6) & 1; @@ -554,7 +554,7 @@ int ysf_conv_dch (dsd_opts * opts, dsd_state * state, uint8_t bn, uint8_t bt, ui fprintf (stderr, "\n "); fprintf (stderr, "DCH1: "); for (i = 0; i < 22; i++) - fprintf (stderr, "[%02X]", m_data[i]); + fprintf (stderr, "[%02X]", m_data[i]); } @@ -609,7 +609,7 @@ int ysf_conv_fich (uint8_t input[], uint8_t dest[32]) CNXDNConvolution_chainback(m_data, 96); //96/8 = 12, last 4 (96-100) are trailing zeroes - for(i = 0; i < 12; i++) + for(i = 0; i < 12; i++) { trellis_buf[(i*8)+0] = (m_data[i] >> 7) & 1; trellis_buf[(i*8)+1] = (m_data[i] >> 6) & 1; @@ -661,7 +661,7 @@ int ysf_conv_fich (uint8_t input[], uint8_t dest[32]) return err; } -//YSF pn95 scrambler/whitening bit generator with seed 111001001 +//YSF pn95 scrambler/whitening bit generator with seed 111001001 void pn95_lfsr() //test to see if this generates the correct bits now { int i; @@ -719,7 +719,7 @@ void ysf_ehr (dsd_opts * opts, dsd_state * state, uint8_t dbuf[180], int start, //should all be loaded back to back ambe_fr[*w][*x] = (char)b1; ambe_fr[*y][*z] = (char)b2; - + w++; x++; y++; @@ -747,7 +747,7 @@ void ysf_ehr (dsd_opts * opts, dsd_state * state, uint8_t dbuf[180], int start, { memcpy (state->f_l, state->audio_out_temp_buf, sizeof(state->f_l)); - + if (opts->pulse_digi_out_channels == 1) playSynthesizedVoiceFM(opts, state); @@ -756,12 +756,12 @@ void ysf_ehr (dsd_opts * opts, dsd_state * state, uint8_t dbuf[180], int start, } } - + if (opts->payload == 1) { fprintf(stderr, "\n"); } - + state->synctype = st; } @@ -857,7 +857,7 @@ void processYSF(dsd_opts * opts, dsd_state * state) if (vp == 0) fprintf (stderr, "-Simplex "); if (vp == 1) fprintf (stderr, "Repeater "); - //disabling below lines, seems mostly redundant, + //disabling below lines, seems mostly redundant, //any Simplex is Direct Wave, and if its VoIP, then the Uplink is always busy (I think) // if (mr == 0) fprintf (stderr, "(Direct Wave) "); @@ -892,7 +892,7 @@ void processYSF(dsd_opts * opts, dsd_state * state) { fprintf (stderr, " FICH: "); for (int i = 0; i < 4; i++) - fprintf (stderr, "[%02X]", (uint8_t)ConvertBitIntoBytes(&fich_decode[i*8], 8)); + fprintf (stderr, "[%02X]", (uint8_t)ConvertBitIntoBytes(&fich_decode[i*8], 8)); } // if (fi == 0) fprintf (stderr, "%s", KGRN); //HC Channel @@ -948,7 +948,7 @@ void processYSF(dsd_opts * opts, dsd_state * state) ysf_conv_dch (opts, state, bn, bt, fn, ft, cm, dbuf); } - + /* In the case of V/D mode type 2, error correction for the purpose of improving the connectivity @@ -963,7 +963,7 @@ void processYSF(dsd_opts * opts, dsd_state * state) for (i = 0; i < 5; i++) { //DCH - for (j = 0; j < 20; j++) + for (j = 0; j < 20; j++) dbuf[d++] = getDibit(opts, state); //VeCH @@ -1006,9 +1006,9 @@ void processYSF(dsd_opts * opts, dsd_state * state) for (j = 0; j < 22; j++) temp[j+27] = vech_bits[j+81]; - + for (j = 0; j < 49; j++) - ambe_d[j] = temp[j]; //(char) + ambe_d[j] = temp[j]; //(char) state->errs2 = vech_bits[103]; //should be zero, but if it isn't, then its an error @@ -1032,7 +1032,7 @@ void processYSF(dsd_opts * opts, dsd_state * state) if(opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); } - + if (opts->floating_point == 1) { memcpy (state->f_l, state->audio_out_temp_buf, sizeof(state->f_l)); @@ -1050,7 +1050,7 @@ void processYSF(dsd_opts * opts, dsd_state * state) ysf_conv_dch2 (opts, state, bn, bt, fn, ft, cm, dbuf); } - + //Full-Rate AMBE+2 EFR (Works with IMBE decoder) uint8_t imbe_vch[144]; memset (imbe_vch, 0, sizeof(imbe_vch)); @@ -1091,12 +1091,12 @@ void processYSF(dsd_opts * opts, dsd_state * state) if (dstart != 5) //only want the first 5 dbuf[(dstart*36)+j] = getDibit(opts, state); else skipDibit(opts, state, 1); //skip the reserved bank - } + } } for (; vstart < vstop; vstart++) { - + //init a bunch of stuff memset (imbe_raw, 0, sizeof(imbe_raw)); memset (imbe_fr, 0, sizeof(imbe_fr)); @@ -1152,7 +1152,7 @@ void processYSF(dsd_opts * opts, dsd_state * state) if(opts->pulse_digi_out_channels == 2) playSynthesizedVoiceSS(opts, state); } - + if (opts->floating_point == 1) //float audio is really quiet now (look into it) { @@ -1197,7 +1197,7 @@ void processYSF(dsd_opts * opts, dsd_state * state) else ysf_conv_dch (opts, state, 2, bt, fn*2+i, ft, cm, dbufFR[i]); } - + } //ending line break