From acd2b0b134eb56b5bfd8abdfcbdb712c4343f552 Mon Sep 17 00:00:00 2001 From: lwvmobile Date: Tue, 25 Apr 2023 15:37:44 -0400 Subject: [PATCH] More NXDN/IDAS Tweaks and Fixes; #115 and #118 --- src/dsd_ncurses.c | 84 +++++++++++++++++++++++++++++++++++----------- src/nxdn_deperm.c | 4 +++ src/nxdn_element.c | 28 +++++++++++++--- src/nxdn_frame.c | 10 +++--- 4 files changed, 97 insertions(+), 29 deletions(-) diff --git a/src/dsd_ncurses.c b/src/dsd_ncurses.c index fa0f44e..f67f663 100644 --- a/src/dsd_ncurses.c +++ b/src/dsd_ncurses.c @@ -97,9 +97,9 @@ char * SyncTypes[44] = { "NXDN", "YSF", //30 "YSF", - "DMR MS VOICE", - "DMR MS DATA", - "DMR RC DATA", + "DMR", //DMR MS VOICE + "DMR", //DMR MS DATA + "DMR", //DMR RC DATA "P25P2", "P25P2", "EDACS/PV", //37 @@ -1686,6 +1686,7 @@ void ncursesMenu (dsd_opts * opts, dsd_state * state) void ncursesPrinter (dsd_opts * opts, dsd_state * state) { + uint8_t idas = 0; int level = 0; int c = 0; @@ -2245,39 +2246,44 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) //NXDN if (lls == 28 || lls == 29) { - + if (strcmp (state->nxdn_location_category, "Type-D") == 0) idas = 1; + if (opts->p25_trunk == 1) { printw ("| "); if (opts->p25_is_tuned == 0) { - printw ("Monitoring Control Channel"); + if (idas == 0) printw ("Monitoring RCCH Channel"); //Control Channel + if (idas == 1) printw ("Monitoring RTCH2 Channel"); //Idas RTCH2 Channel if (state->p25_cc_freq != 0) { - printw (" - CC Freq: [%.06lf] Mhz ", (double)state->p25_cc_freq/1000000); + printw (" - Frequency: [%.06lf] Mhz ", (double)state->p25_cc_freq/1000000); } } else if (opts->p25_is_tuned == 1) { - printw ("Monitoring Voice Channel"); + if (idas == 0) printw ("Monitoring RTCH Channel"); //Traffic Channel + if (idas == 1) printw ("Monitoring RTCH2 Channel"); //Idas RTCH2 if (state->p25_vc_freq[0] != 0) { - printw (" - VC Freq: [%.06lf] Mhz ", (double)state->p25_vc_freq[0]/1000000); + printw (" - Frequency: [%.06lf] Mhz ", (double)state->p25_vc_freq[0]/1000000); } - } - - printw ("\n"); + } + printw ("\n"); } + + printw ("| "); - printw ("NXDN - RAN: [%02d] ", rn); + if (idas == 0) printw ("NXDN - RAN: [%02d] ", rn); + if (idas == 1) printw ("IDAS - Area: [%02d] ", rn); if (state->nxdn_location_site_code != 0) { - printw ("Cat [%s] ", state->nxdn_location_category); - printw ("Sys Code [%d] ", state->nxdn_location_sys_code); - printw ("Site Code [%d] ", state->nxdn_location_site_code); + printw ("Cat: [%s] ", state->nxdn_location_category); + printw ("Sys Code: [%d] ", state->nxdn_location_sys_code); + printw ("Site Code: [%d] ", state->nxdn_location_site_code); } //if system supports Direct Frequency Assignment @@ -2310,9 +2316,9 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) } if (state->nxdn_cipher_type == 0x1 && state->carrier == 1) { - attron(COLOR_PAIR(2)); + if (state->R == 0) attron(COLOR_PAIR(2)); printw ("Scrambler "); - attroff(COLOR_PAIR(2)); + if (state->R == 0) attroff(COLOR_PAIR(2)); attron(COLOR_PAIR(3)); if (state->R != 0) { @@ -2489,6 +2495,12 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) printw("DES-OFB"); attron(COLOR_PAIR(3)); } + if (state->payload_algid == 0x82) + { + attron(COLOR_PAIR(1)); + printw("Double DES"); + attron(COLOR_PAIR(3)); + } if (state->payload_algid == 0x83 || state->payload_algid == 0x23) { attron(COLOR_PAIR(1)); @@ -2931,7 +2943,8 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) printw ("| %s ", SyncTypes[call_matrix[9-j][0]]); if (lls == 28 || lls == 29) { - printw ("RAN [%02lld] ", call_matrix[9-j][1]); + if (idas == 0) printw ("RAN [%02lld] ", call_matrix[9-j][1]); + if (idas == 1) printw ("Area [%02lld] ", call_matrix[9-j][1]); printw ("TG [%5lld] ", call_matrix[9-j][4]); printw ("RID [%5lld] ", call_matrix[9-j][2]); } @@ -2960,7 +2973,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) //DMR MS Types if (call_matrix[9-j][0] == 32 || call_matrix[9-j][0] == 33 || call_matrix[9-j][0] == 34 ) { - //printw ("S[%d] ", call_matrix[9-j][3]); + printw ("S[%lld] ", call_matrix[9-j][3]); printw ("TGT [%8lld] ", call_matrix[9-j][1]); printw ("SRC [%8lld] ", call_matrix[9-j][2]); printw ("DCC [%02lld] ", call_matrix[9-j][4]); @@ -3210,6 +3223,16 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) sprintf (state->group_array[state->group_tally].groupName, "%s", "LOCKOUT"); state->group_tally++; + //if we have an opened group file, let's write a group lock out into it to make it permanent + if (opts->group_in_file[0] != 0) //file is available + { + FILE * pFile; //file pointer + //open file by name that is supplied in the ncurses terminal, or cli + pFile = fopen (opts->group_in_file, "a"); + fprintf (pFile, "%d,B,LOCKOUT,%02X\n", state->lasttg, state->payload_algid); + fclose (pFile); + } + //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)); @@ -3249,6 +3272,16 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) sprintf (state->group_array[state->group_tally].groupName, "%s", "LOCKOUT"); state->group_tally++; + //if we have an opened group file, let's write a group lock out into it to make it permanent + if (opts->group_in_file[0] != 0) //file is available + { + FILE * pFile; //file pointer + //open file by name that is supplied in the ncurses terminal, or cli + pFile = fopen (opts->group_in_file, "a"); + fprintf (pFile, "%d,B,LOCKOUT,%02X\n", state->lasttgR, state->payload_algidR); + fclose (pFile); + } + //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)); @@ -3332,6 +3365,19 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) opts->dmr_dmrla_is_set = 0; opts->dmr_dmrla_n = 0; + //reset NXDN info + state->nxdn_location_site_code = 0; + state->nxdn_location_sys_code = 0; + sprintf (state->nxdn_location_category, "%s", " "); + + state->nxdn_last_ran = 0; + state->nxdn_ran = 0; + + state->nxdn_rcn = 0; + state->nxdn_base_freq = 0; + state->nxdn_step = 0; + state->nxdn_bw = 0; + } //Debug/Troubleshooting Option diff --git a/src/nxdn_deperm.c b/src/nxdn_deperm.c index 1e451c3..bb7255e 100644 --- a/src/nxdn_deperm.c +++ b/src/nxdn_deperm.c @@ -271,6 +271,10 @@ void nxdn_deperm_sacch(dsd_opts * opts, dsd_state * state, uint8_t bits[60]) } // if (crc != check) fprintf (stderr, " CRC ERR - %02X %02X", check, crc); } + + //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)); } diff --git a/src/nxdn_element.c b/src/nxdn_element.c index be7507d..9036ab7 100644 --- a/src/nxdn_element.c +++ b/src/nxdn_element.c @@ -37,6 +37,11 @@ void NXDN_SACCH_Full_decode(dsd_opts * opts, dsd_state * state) if (CrcCorrect == 1) NXDN_Elements_Content_decode(opts, state, CrcCorrect, SACCH); else if (opts->aggressive_framesync == 0) NXDN_Elements_Content_decode(opts, state, 0, SACCH); + //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)); + + } /* End NXDN_SACCH_Full_decode() */ @@ -428,7 +433,8 @@ void NXDN_decode_VCALL_ASSGN(dsd_opts * opts, dsd_state * state, uint8_t * Messa /* Print Source ID and Destination ID (Talk Group or Unit ID) */ fprintf(stderr, "Src=%u - Dst/TG=%u ", SourceUnitID & 0xFFFF, DestinationID & 0xFFFF); - // if (idas) fprintf (stderr, "- Ch: %d ", rep1); + //Channel here appears to be the prefix or home channel of the caller, not necessarily the channel the call is occuring on + // if (idas) fprintf (stderr, "- Prefix Ch: %d ", rep1); /* Print Channel */ if (state->nxdn_rcn == 0) @@ -1089,7 +1095,8 @@ void NXDN_decode_VCALL(dsd_opts * opts, dsd_state * state, uint8_t * Message) /* Print Source ID and Destination ID (Talk Group or Unit ID) */ fprintf(stderr, "Src=%u - Dst/TG=%u ", SourceUnitID & 0xFFFF, DestinationID & 0xFFFF); - if (idas) fprintf (stderr, "- Ch: %d ", rep1); + //Channel here appears to be the prefix or home channel of the caller, not necessarily the channel the call is occuring on + if (idas) fprintf (stderr, "- Prefix Ch: %d ", rep1); fprintf (stderr, "%s", KNRM); @@ -1102,6 +1109,15 @@ void NXDN_decode_VCALL(dsd_opts * opts, dsd_state * state, uint8_t * Message) //Don't zero key if no keyloader if (CipherType != 0x1 && state->keyloader == 1) state->R = 0; + //NOTE: Broadcast Call appears to have values that aren't typical for VCALL, + //so not applying any settings below if CallType == 0 (BC Call) + + //NOTE: Above note may be in error; its possible that the issues I was having + //was from not resetting the entire SACCH superframe after reading it, and + //the samples in question having interwoven ALIAS and VCALL, and bad settings + //coming from a missed SF Part of Frame, if not reset, we could skip a SF POF + //and still believe we have a good decode -- will need further testing #118 + /* Print the "Cipher Type" */ if(CipherType != 0 && MessageType == 0x1) { @@ -1218,9 +1234,11 @@ void NXDN_decode_scch(dsd_opts * opts, dsd_state * state, uint8_t * Message, uin 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_sys_code == 0) state->nxdn_location_sys_code = 99; - if (state->nxdn_last_ran == -1) state->nxdn_last_ran = 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; + + state->nxdn_last_ran = area; state->last_cc_sync_time = time(NULL); diff --git a/src/nxdn_frame.c b/src/nxdn_frame.c index 14e543a..3bc8f86 100644 --- a/src/nxdn_frame.c +++ b/src/nxdn_frame.c @@ -66,8 +66,8 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) uint8_t facch2_bits[348]; //facch2 or udch, same amount of bits uint8_t facch3_bits[288]; //facch3 or udch2, same amoount of bits - //nxdn bit buffer, for easy assignment handling - int nxdn_bit_buffer[364]; + //nxdn bit buffer, for easy assignment handling + int nxdn_bit_buffer[364]; int nxdn_dibit_buffer[182]; //init all arrays @@ -85,7 +85,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) memset (nxdn_dibit_buffer, 0, sizeof(nxdn_dibit_buffer)); //collect lich bits first, if they are good, then we can collect the rest of them - for (int i = 0; i < 8; i++) lich_dibits[i] = dbuf[i] = getDibit(opts, state); + for (int i = 0; i < 8; i++) lich_dibits[i] = dbuf[i] = getDibit(opts, state); nxdn_descramble (lich_dibits, 8); @@ -96,7 +96,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) lich_parity_computed = ((lich >> 7) + (lich >> 6) + (lich >> 5) + (lich >> 4)) & 1; lich = lich >> 1; if (lich_parity_received != lich_parity_computed) - { + { state->lastsynctype = -1; //set to -1 so we don't jump back here too quickly goto END; } @@ -318,7 +318,7 @@ void nxdn_frame (dsd_opts * opts, dsd_state * state) // RF Channel Type if (lich_rf == 0) fprintf (stderr, "RCCH "); else if (lich_rf == 1) fprintf (stderr, "RTCH "); - else if (lich_rf == 1) fprintf (stderr, "RDCH "); + else if (lich_rf == 2) fprintf (stderr, "RDCH "); else { if (lich < 0x60) fprintf (stderr, "RTCH_C ");