diff --git a/include/dsd.h b/include/dsd.h index 03f0eda..31ca97c 100644 --- a/include/dsd.h +++ b/include/dsd.h @@ -440,6 +440,8 @@ typedef struct int payload_algid; int payload_keyid; int payload_mfid; + int payload_mi; + unsigned long long int K; unsigned int debug_audio_errors; unsigned int debug_header_errors; @@ -774,7 +776,7 @@ uint32_t ComputeAndCorrectFullLinkControlCrc(uint8_t * FullLinkControlDataBytes, uint8_t ComputeCrc5Bit(uint8_t * DMRData); uint8_t * DmrAlgIdToStr(uint8_t AlgID); uint8_t * DmrAlgPrivacyModeToStr(uint32_t PrivacyMode); - +void ProcessDmrPIHeader(dsd_opts * opts, dsd_state * state, uint8_t info[196], uint8_t syncdata[48], uint8_t SlotType[20]); void Hamming_7_4_init(); void Hamming_7_4_encode(unsigned char *origBits, unsigned char *encodedBits); diff --git a/src/dmr_data.c b/src/dmr_data.c index 1eddd5f..f2301f9 100644 --- a/src/dmr_data.c +++ b/src/dmr_data.c @@ -330,9 +330,10 @@ processDMRdata (dsd_opts * opts, dsd_state * state) /* Print the color code */ fprintf(stderr, "| Color Code=%02d ", (int)state->color_code); - if(state->color_code_ok) fprintf(stderr, "(OK) |"); - else fprintf(stderr, "(CRC ERR) |"); - + //if(state->color_code_ok) fprintf(stderr, "(OK) |"); + if(state->color_code_ok) fprintf(stderr, "(CRC OK ) |"); //add line break + else fprintf(stderr, "(CRC ERR) |"); //add line break + //fprintf (stderr, "\n"); //print line break if (strcmp (state->fsubtype, " ") == 0) { fprintf(stderr, " Unknown burst type: %s", bursttype); @@ -348,6 +349,7 @@ processDMRdata (dsd_opts * opts, dsd_state * state) /* Burst = PI header */ case 0b0000: { + ProcessDmrPIHeader(opts, state, (uint8_t *)info, (uint8_t *)syncdata, (uint8_t *)SlotType); break; } diff --git a/src/dmr_encryption.c b/src/dmr_encryption.c index 21122df..5355286 100644 --- a/src/dmr_encryption.c +++ b/src/dmr_encryption.c @@ -27,16 +27,14 @@ void ProcessDMREncryption (dsd_opts * opts, dsd_state * state) TimeSlotVoiceSuperFrame_t * TSVoiceSupFrame = NULL; TimeSlotVoiceSuperFrame_t * TSVoiceSupFrameL = NULL; TimeSlotVoiceSuperFrame_t * TSVoiceSupFrameR = NULL; + int *errs; int *errs2; int *errsR; int *errs2R; + unsigned long long int k; + k = 0; - /* - * Currently encryption is not supported in this public version... - */ - - /* Check the current time slot */ if(state->currentslot == 0) { TSVoiceSupFrame = &state->TS1SuperFrame; @@ -48,37 +46,9 @@ void ProcessDMREncryption (dsd_opts * opts, dsd_state * state) TSVoiceSupFrameL = &state->TS1SuperFrame; TSVoiceSupFrameR = &state->TS2SuperFrame; - - - - /* Apply encryption here - * - * A DMR superframe = 6 frames x 3 AMBE voice sample of 49 bits each - * uint8_t KeyStream[6][3][49]; - * - * 1�) Initialize the "KeyStream" buffer (total 882 bits) with correct bits (depending of - * encryption mode used, MotoTRBO BP, Hytera BP, MotoTRBO EP, MotoTRBO AES... - * - * 2�) Apply a XOR between "KeyStream" and "TSVoiceSupFrame->TimeSlotAmbeVoiceFrame[Frame].AmbeBit[i][j]" - * like code : - * for(Frame = 0; Frame < 6; Frame++) - * { - * for(i = 0; i < 3; i++) - * { - * for(j = 0; j < 49; j++) - * { - * TSVoiceSupFrame->TimeSlotAmbeVoiceFrame[Frame].AmbeBit[i] ^= KeyStream[Frame][i][j]; - * } - * } - * } - * - * 3�) Play all AMBE decoded sample (see the "for" loop below) - * - * */ - - /* - * Play all AMBE voice samples - * 1 DMR voice superframe = 6 DMR frames */ +// +// +// for(Frame = 0; Frame < 6; Frame++) { /* 1 DMR frame contains 3 AMBE voice samples */ diff --git a/src/dmr_sync.c b/src/dmr_sync.c index 007b5ef..1f7b338 100644 --- a/src/dmr_sync.c +++ b/src/dmr_sync.c @@ -21,7 +21,108 @@ //#define PRINT_VOICE_LC_HEADER_BYTES //#define PRINT_TERMINAISON_LC_BYTES //#define PRINT_VOICE_BURST_BYTES +void ProcessDmrPIHeader(dsd_opts * opts, dsd_state * state, uint8_t info[196], uint8_t syncdata[48], uint8_t SlotType[20]) +{ + //Placeholder + uint32_t i, j, k; + uint32_t CRCExtracted = 0; + uint32_t CRCComputed = 0; + uint32_t CRCCorrect = 0; + uint32_t IrrecoverableErrors = 0; + uint8_t DeInteleavedData[196]; + uint8_t DmrDataBit[96]; + uint8_t DmrDataByte[12]; + TimeSlotVoiceSuperFrame_t * TSVoiceSupFrame = NULL; + uint8_t R[3]; + uint8_t BPTCReservedBits = 0; + /* Remove warning compiler */ + //UNUSED_VARIABLE(syncdata[0]); + //UNUSED_VARIABLE(SlotType[0]); + //UNUSED_VARIABLE(BPTCReservedBits); + + /* Check the current time slot */ + if(state->currentslot == 0) + { + TSVoiceSupFrame = &state->TS1SuperFrame; + } + else + { + TSVoiceSupFrame = &state->TS2SuperFrame; + } + + CRCExtracted = 0; + CRCComputed = 0; + IrrecoverableErrors = 0; + + /* Deinterleave DMR data */ + BPTCDeInterleaveDMRData(info, DeInteleavedData); + + /* Extract the BPTC 196,96 DMR data */ + IrrecoverableErrors = BPTC_196x96_Extract_Data(DeInteleavedData, DmrDataBit, R); + + /* Fill the reserved bit (R(0)-R(2) of the BPTC(196,96) block) */ + BPTCReservedBits = (R[0] & 0x01) | ((R[1] << 1) & 0x02) | ((R[2] << 2) & 0x08); + + /* Convert the 96 bit of voice LC Header data into 12 bytes */ + k = 0; + for(i = 0; i < 12; i++) + { + DmrDataByte[i] = 0; + for(j = 0; j < 8; j++) + { + DmrDataByte[i] = DmrDataByte[i] << 1; + DmrDataByte[i] = DmrDataByte[i] | (DmrDataBit[k] & 0x01); + k++; + } + } + + /* Fill the CRC extracted (before Reed-Solomon (12,9) FEC correction) */ + CRCExtracted = 0; + //for(i = 0; i < 24; i++) + for(i = 0; i < 16; i++) + { + CRCExtracted = CRCExtracted << 1; + //CRCExtracted = CRCExtracted | (uint32_t)(DmrDataBit[i + 72] & 1); + CRCExtracted = CRCExtracted | (uint32_t)(DmrDataBit[i + 80] & 1); //80-96 for PI header + } + + /* Apply the CRC mask (see DMR standard B.3.12 Data Type CRC Mask) */ + //CRCExtracted = CRCExtracted ^ 0x969696; //does this mask get applied here though for PI? + //CRCExtracted = CRCExtracted ^ 0x6969; + + /* Check/correct the full link control data and compute the Reed-Solomon (12,9) CRC */ + //CRCCorrect = ComputeAndCorrectFullLinkControlCrc(DmrDataByte, &CRCComputed, 0x969696); + //CRCCorrect = ComputeAndCorrectFullLinkControlCrc(DmrDataByte, &CRCComputed, 0x6969); + + /* Convert corrected 12 bytes into 96 bits */ + for(i = 0, j = 0; i < 12; i++, j+=8) + { + DmrDataBit[j + 0] = (DmrDataByte[i] >> 7) & 0x01; + DmrDataBit[j + 1] = (DmrDataByte[i] >> 6) & 0x01; + DmrDataBit[j + 2] = (DmrDataByte[i] >> 5) & 0x01; + DmrDataBit[j + 3] = (DmrDataByte[i] >> 4) & 0x01; + DmrDataBit[j + 4] = (DmrDataByte[i] >> 3) & 0x01; + DmrDataBit[j + 5] = (DmrDataByte[i] >> 2) & 0x01; + DmrDataBit[j + 6] = (DmrDataByte[i] >> 1) & 0x01; + DmrDataBit[j + 7] = (DmrDataByte[i] >> 0) & 0x01; + } + //Placeholder, figure out which areas to grab + //state->payload_algid = DmrDataBit[1]; + state->payload_algid = DmrDataByte[0]; //not really sure, just guessing on observation? + //state->payload_keyid = DmrDataBit[2]; + state->payload_keyid = DmrDataByte[2]; + //state->payload_mi = ( (DmrDataBit[3] << 3) + (DmrDataBit[4] << 2) + (DmrDataBit[5] << 1) + DmrDataBit[6] ); + state->payload_mi = ( ((DmrDataByte[3]) << 24) + ((DmrDataByte[4]) << 16) + ((DmrDataByte[5]) << 8) + (DmrDataByte[6]) ); + //fprintf(stderr, "%s Slot(%d), CC(%x), PI HEADER: ALGID(%02x), KEYID(%02x), MI(%08x), DSTADDR(%06x)\n", + fprintf (stderr, "\n DMR PI Header ALG ID: 0x%02X KEY ID: 0x%02X MI: 0x%08X \n", state->payload_algid, state->payload_keyid, state->payload_mi); + fprintf (stderr, " Full PI Header Payload in Hex\n"); + for(i = 0, j = 0; i < 12; i++) + { + //fprintf (stderr, " Byte [%02d] [%02X] [%02X]\n", i+1, DmrDataByte[i], DmrDataByte[i] ^ 0x69); //0x6969 PI header mask? + } + //end Placeholder +} void ProcessDmrVoiceLcHeader(dsd_opts * opts, dsd_state * state, uint8_t info[196], uint8_t syncdata[48], uint8_t SlotType[20]) { @@ -140,7 +241,7 @@ void ProcessDmrVoiceLcHeader(dsd_opts * opts, dsd_state * state, uint8_t info[19 } /* Print the destination ID (TG) and the source ID */ - fprintf(stderr, "| TG=%u Src=%u ", TSVoiceSupFrame->FullLC.GroupAddress, TSVoiceSupFrame->FullLC.SourceAddress); + fprintf(stderr, "\n TG=%u Src=%u ", TSVoiceSupFrame->FullLC.GroupAddress, TSVoiceSupFrame->FullLC.SourceAddress); fprintf(stderr, "FID=0x%02X ", TSVoiceSupFrame->FullLC.FeatureSetID); //state->lasttg = TSVoiceSupFrame->FullLC.GroupAddress; //state->lastsrc = TSVoiceSupFrame->FullLC.SourceAddress; @@ -184,7 +285,7 @@ void ProcessDmrVoiceLcHeader(dsd_opts * opts, dsd_state * state, uint8_t info[19 } fprintf(stderr, "Call "); - if(TSVoiceSupFrame->FullLC.DataValidity) fprintf(stderr, "(OK) "); + if(TSVoiceSupFrame->FullLC.DataValidity) fprintf(stderr, "(CRC OK ) "); else if(IrrecoverableErrors == 0) fprintf(stderr, "RAS (FEC OK/CRC ERR)"); else fprintf(stderr, "(FEC FAIL/CRC ERR)"); @@ -340,7 +441,7 @@ void ProcessDmrTerminaisonLC(dsd_opts * opts, dsd_state * state, uint8_t info[19 } /* Print the destination ID (TG) and the source ID */ - fprintf(stderr, "| TG=%u Src=%u ", TSVoiceSupFrame->FullLC.GroupAddress, TSVoiceSupFrame->FullLC.SourceAddress); + fprintf(stderr, "\n TG=%u Src=%u ", TSVoiceSupFrame->FullLC.GroupAddress, TSVoiceSupFrame->FullLC.SourceAddress); fprintf(stderr, "FID=0x%02X ", TSVoiceSupFrame->FullLC.FeatureSetID); //state->lasttg = TSVoiceSupFrame->FullLC.GroupAddress; //state->lastsrc = TSVoiceSupFrame->FullLC.SourceAddress; @@ -349,7 +450,7 @@ void ProcessDmrTerminaisonLC(dsd_opts * opts, dsd_state * state, uint8_t info[19 if((IrrecoverableErrors == 0) && CRCCorrect) { - fprintf(stderr, "(OK) "); + fprintf(stderr, "(CRC OK ) "); //only set on good CRC value or corrected values state->lasttg = TSVoiceSupFrame->FullLC.GroupAddress; state->lastsrc = TSVoiceSupFrame->FullLC.SourceAddress; @@ -520,7 +621,7 @@ void ProcessVoiceBurstSync(dsd_opts * opts, dsd_state * state) } /* Print the destination ID (TG) and the source ID */ - fprintf(stderr, "| TG=%u Src=%u ", TSVoiceSupFrame->FullLC.GroupAddress, TSVoiceSupFrame->FullLC.SourceAddress); + fprintf(stderr, " TG=%u Src=%u ", TSVoiceSupFrame->FullLC.GroupAddress, TSVoiceSupFrame->FullLC.SourceAddress); fprintf(stderr, "FID=0x%02X ", TSVoiceSupFrame->FullLC.FeatureSetID); //state->lasttg = TSVoiceSupFrame->FullLC.GroupAddress; //state->lastsrc = TSVoiceSupFrame->FullLC.SourceAddress; @@ -528,7 +629,7 @@ void ProcessVoiceBurstSync(dsd_opts * opts, dsd_state * state) if((IrrecoverableErrors == 0) && CRCCorrect) { - fprintf(stderr, "(OK)"); + fprintf(stderr, "(CRC OK ) "); //only set on good CRC? state->lasttg = TSVoiceSupFrame->FullLC.GroupAddress; state->lastsrc = TSVoiceSupFrame->FullLC.SourceAddress; diff --git a/src/dmr_voice.c b/src/dmr_voice.c index 5522a76..fb0cf5c 100644 --- a/src/dmr_voice.c +++ b/src/dmr_voice.c @@ -593,15 +593,14 @@ void processDMRvoice (dsd_opts * opts, dsd_state * state) for(i = 0; i < 3; i++) { state->TS1SuperFrame.TimeSlotAmbeVoiceFrame[j].errs1[i] = mbe_eccAmbe3600x2450C0(state->TS1SuperFrame.TimeSlotDeinterleavedVoiceFrame[j].DeInterleavedVoiceSample[i]); - //state->errs = state->TS1SuperFrame.TimeSlotAmbeVoiceFrame[j].errs1[i]; //correct placement + state->TS1SuperFrame.TimeSlotAmbeVoiceFrame[j].errs2[i] = state->TS1SuperFrame.TimeSlotAmbeVoiceFrame[j].errs1[i]; - //state->errs2 = state->TS1SuperFrame.TimeSlotAmbeVoiceFrame[j].errs2[i]; //correct placement + mbe_demodulateAmbe3600x2450Data(state->TS1SuperFrame.TimeSlotDeinterleavedVoiceFrame[j].DeInterleavedVoiceSample[i]); state->TS1SuperFrame.TimeSlotAmbeVoiceFrame[j].errs2[i] += mbe_eccAmbe3600x2450Data(state->TS1SuperFrame.TimeSlotDeinterleavedVoiceFrame[j].DeInterleavedVoiceSample[i], &(state->TS1SuperFrame.TimeSlotAmbeVoiceFrame[j].AmbeBit[i][0])); } - //state->errs = state->TS1SuperFrame.TimeSlotAmbeVoiceFrame[j].errs1[i]; //correct placement - //state->errs2 = (int)state->TS1SuperFrame.TimeSlotAmbeVoiceFrame[j].errs2[i]; //correct placement + } else { @@ -609,15 +608,14 @@ void processDMRvoice (dsd_opts * opts, dsd_state * state) for(i = 0; i < 3; i++) { state->TS2SuperFrame.TimeSlotAmbeVoiceFrame[j].errs1[i] = mbe_eccAmbe3600x2450C0(state->TS2SuperFrame.TimeSlotDeinterleavedVoiceFrame[j].DeInterleavedVoiceSample[i]); - //state->errs = state->TS1SuperFrame.TimeSlotAmbeVoiceFrame[j].errs1[i]; //correct placement + state->TS2SuperFrame.TimeSlotAmbeVoiceFrame[j].errs2[i] = state->TS2SuperFrame.TimeSlotAmbeVoiceFrame[j].errs1[i]; - //state->errs2 = state->TS1SuperFrame.TimeSlotAmbeVoiceFrame[j].errs2[i]; //correct placement + mbe_demodulateAmbe3600x2450Data(state->TS2SuperFrame.TimeSlotDeinterleavedVoiceFrame[j].DeInterleavedVoiceSample[i]); state->TS2SuperFrame.TimeSlotAmbeVoiceFrame[j].errs2[i] += mbe_eccAmbe3600x2450Data(state->TS2SuperFrame.TimeSlotDeinterleavedVoiceFrame[j].DeInterleavedVoiceSample[i], &(state->TS2SuperFrame.TimeSlotAmbeVoiceFrame[j].AmbeBit[i][0])); } - //state->errs = state->TS2SuperFrame.TimeSlotAmbeVoiceFrame[j].errs1[i]; //correct placement - //state->errs2 = (int)state->TS2SuperFrame.TimeSlotAmbeVoiceFrame[j].errs2[i]; //correct placement + } } /* End for(j = 0; j < 6; j++) */ @@ -628,10 +626,12 @@ void processDMRvoice (dsd_opts * opts, dsd_state * state) /* Print the color code */ fprintf(stderr, "| Color Code=%02d ", (int)state->color_code); - if(state->color_code_ok) fprintf(stderr, "(OK) |"); - else fprintf(stderr, "(CRC ERR) |"); + //if(state->color_code_ok) fprintf(stderr, "(OK) |"); + if(state->color_code_ok) fprintf(stderr, "(CRC OK ) |"); //add line break + else fprintf(stderr, "(CRC ERR) |"); //add line break - fprintf(stderr, " VOICE e:"); + //fprintf(stderr, " VOICE e: \n"); + fprintf(stderr, " VOICE \n"); } /* Perform the SYNC DMR data embedded decoding */ diff --git a/src/dsd_audio.c b/src/dsd_audio.c index 10b0e9b..3a28e9e 100644 --- a/src/dsd_audio.c +++ b/src/dsd_audio.c @@ -27,9 +27,9 @@ pa_sample_spec cc; void openPulseOutput(dsd_opts * opts) { - //ss.format = PA_SAMPLE_S16NE; - //ss.channels = opts->pulse_raw_out_channels; //doing tests with 2 channels at 22050 for 44100 audio default in pulse - //ss.rate = opts->pulse_raw_rate_out; //48000 + ss.format = PA_SAMPLE_S16NE; + ss.channels = opts->pulse_raw_out_channels; //doing tests with 2 channels at 22050 for 44100 audio default in pulse + ss.rate = opts->pulse_raw_rate_out; //48000 tt.format = PA_SAMPLE_S16NE; tt.channels = opts->pulse_digi_out_channels; //doing tests with 2 channels at 22050 for 44100 audio default in pulse @@ -39,7 +39,7 @@ void openPulseOutput(dsd_opts * opts) //ss if (opts->monitor_input_audio == 1) { - //opts->pulse_raw_dev_out = pa_simple_new(NULL, "DSD FME", PA_STREAM_PLAYBACK, NULL, "Raw Audio Out", &ss, NULL, NULL, NULL); + opts->pulse_raw_dev_out = pa_simple_new(NULL, "DSD FME", PA_STREAM_PLAYBACK, NULL, "Raw Audio Out", &ss, NULL, NULL, NULL); } //tt @@ -64,7 +64,7 @@ void openPulseInput(dsd_opts * opts) cc.rate = opts->pulse_digi_rate_in; //48000 //zz - if (opts->monitor_input_audio == 2) + if (opts->monitor_input_audio == 1) { //opts->pulse_raw_dev_in = pa_simple_new(NULL, "DSD FME", PA_STREAM_RECORD, NULL, "Raw Audio In", &zz, NULL, NULL, NULL); } diff --git a/src/dsd_dibit.c b/src/dsd_dibit.c index 7502861..872c030 100644 --- a/src/dsd_dibit.c +++ b/src/dsd_dibit.c @@ -444,6 +444,9 @@ get_dibit_and_analog_signal (dsd_opts* opts, dsd_state* state, int* out_analog_s // state->sbuf[state->sidx] = symbol; + // + //state->pulse_raw_out_buffer = symbol; + // if (out_analog_signal != NULL) { *out_analog_signal = symbol; diff --git a/src/dsd_frame.c b/src/dsd_frame.c index 5b1c47a..f33eb97 100644 --- a/src/dsd_frame.c +++ b/src/dsd_frame.c @@ -31,7 +31,7 @@ printFrameInfo (dsd_opts * opts, dsd_state * state) level = (int) state->max / 164; if (opts->verbose > 0) { - fprintf (stderr,"inlvl: %2i%% ", level); + //fprintf (stderr,"inlvl: %2i%% ", level); } if (state->nac != 0) { @@ -89,7 +89,7 @@ processFrame (dsd_opts * opts, dsd_state * state) if (opts->verbose > 0) { level = (int) state->max / 164; - fprintf (stderr, "inlvl: %2i%% ", level); + //fprintf (stderr, "inlvl: %2i%% ", level); } } state->nac = 0; @@ -112,7 +112,7 @@ processFrame (dsd_opts * opts, dsd_state * state) if (opts->verbose > 0) { level = (int) state->max / 164; - fprintf (stderr, "inlvl: %2i%% ", level); + //fprintf (stderr, "inlvl: %2i%% ", level); } } state->nac = 0; @@ -134,7 +134,7 @@ processFrame (dsd_opts * opts, dsd_state * state) if (opts->verbose > 0) { level = (int) state->max / 164; - fprintf (stderr,"inlvl: %2i%% ", level); + //fprintf (stderr,"inlvl: %2i%% ", level); } } state->nac = 0; @@ -156,7 +156,7 @@ processFrame (dsd_opts * opts, dsd_state * state) if (opts->verbose > 0) { level = (int) state->max / 164; - fprintf (stderr,"inlvl: %2i%% ", level); + //fprintf (stderr,"inlvl: %2i%% ", level); } } state->nac = 0; @@ -179,7 +179,7 @@ processFrame (dsd_opts * opts, dsd_state * state) if (opts->verbose > 0) { level = (int) state->max / 164; - fprintf (stderr,"inlvl: %2i%% ", level); + //fprintf (stderr,"inlvl: %2i%% ", level); } } if ((state->synctype == 11) || (state->synctype == 12)) @@ -233,7 +233,7 @@ processFrame (dsd_opts * opts, dsd_state * state) if (opts->verbose > 0) { level = (int) state->max / 164; - fprintf (stderr,"inlvl: %2i%% ", level); + //fprintf (stderr,"inlvl: %2i%% ", level); } } if ((opts->mbe_out_dir[0] != 0) && (opts->mbe_out_f == NULL)) @@ -264,7 +264,7 @@ processFrame (dsd_opts * opts, dsd_state * state) if (opts->verbose > 0) { level = (int) state->max / 164; - fprintf(stderr, "inlvl: %2i%% ", level); + //fprintf(stderr, "inlvl: %2i%% ", level); } } state->nac = 0; diff --git a/src/dsd_frame_sync.c b/src/dsd_frame_sync.c index 7bfba83..6a88c55 100644 --- a/src/dsd_frame_sync.c +++ b/src/dsd_frame_sync.c @@ -108,7 +108,7 @@ printFrameSync (dsd_opts * opts, dsd_state * state, char *frametype, int offset, } if (opts->verbose > 1) { - fprintf (stderr,"mod: %s ", modulation); + //fprintf (stderr,"mod: %s ", modulation); //disabled, don't like looking at incorrect mod types anyways, and it eats up space on the console //printw("mod: %s ", modulation); } if (opts->verbose > 2) @@ -200,12 +200,6 @@ getFrameSync (dsd_opts * opts, dsd_state * state) { ncursesPrinter(opts, state); } - /* - if ( opts->monitor_input_audio == 1 && (time(NULL) - now) > 1 ) //okay, still something going on, still doing the read part for some reason - { - playRawAudio(opts, state); //this is on line 21 in dsd_audio.c - } - */ /* if (opts->reset_state == 1 && state->carrier == 0) @@ -1126,10 +1120,10 @@ getFrameSync (dsd_opts * opts, dsd_state * state) if (opts->inverted_dmr == 0) { // data frame - sprintf(state->ftype, " DMR "); + sprintf(state->ftype, "DMR "); if (opts->errorbars == 1) { - printFrameSync (opts, state, " +DMR ", synctest_pos + 1, modulation); + printFrameSync (opts, state, "+DMR ", synctest_pos + 1, modulation); } state->lastsynctype = 10; return (10); @@ -1137,10 +1131,10 @@ getFrameSync (dsd_opts * opts, dsd_state * state) else { // inverted voice frame - sprintf(state->ftype, " DMR "); + sprintf(state->ftype, "DMR "); if (opts->errorbars == 1) { - printFrameSync (opts, state, " -DMR ", synctest_pos + 1, modulation); + printFrameSync (opts, state, "-DMR ", synctest_pos + 1, modulation); } if (state->lastsynctype != 11) { @@ -1161,10 +1155,10 @@ getFrameSync (dsd_opts * opts, dsd_state * state) if (opts->inverted_dmr == 0) { // data frame - sprintf(state->ftype, " DMR "); + sprintf(state->ftype, "DMR "); if (opts->errorbars == 1) { - printFrameSync (opts, state, " +DMR ", synctest_pos + 1, modulation); + printFrameSync (opts, state, "+DMR ", synctest_pos + 1, modulation); } state->lastsynctype = 10; return (10); @@ -1172,10 +1166,10 @@ getFrameSync (dsd_opts * opts, dsd_state * state) else { // inverted voice frame - sprintf(state->ftype, " DMR "); + sprintf(state->ftype, "DMR "); if (opts->errorbars == 1) { - printFrameSync (opts, state, " -DMR ", synctest_pos + 1, modulation); + printFrameSync (opts, state, "-DMR ", synctest_pos + 1, modulation); } if (state->lastsynctype != 11) { @@ -1196,10 +1190,10 @@ getFrameSync (dsd_opts * opts, dsd_state * state) if (opts->inverted_dmr == 0) { // data frame - sprintf(state->ftype, " DMR "); + sprintf(state->ftype, "DMR "); if (opts->errorbars == 1) { - printFrameSync (opts, state, " +DMR ", synctest_pos + 1, modulation); + printFrameSync (opts, state, "+DMR ", synctest_pos + 1, modulation); } state->lastsynctype = 10; return (10); @@ -1207,10 +1201,10 @@ getFrameSync (dsd_opts * opts, dsd_state * state) else { // inverted voice frame - sprintf(state->ftype, " DMR "); + sprintf(state->ftype, "DMR "); if (opts->errorbars == 1) { - printFrameSync (opts, state, " -DMR ", synctest_pos + 1, modulation); + printFrameSync (opts, state, "-DMR ", synctest_pos + 1, modulation); } if (state->lastsynctype != 11) { @@ -1230,10 +1224,10 @@ getFrameSync (dsd_opts * opts, dsd_state * state) if (opts->inverted_dmr == 0) { // voice frame - sprintf(state->ftype, " DMR "); + sprintf(state->ftype, "DMR "); if (opts->errorbars == 1) { - printFrameSync (opts, state, " +DMR ", synctest_pos + 1, modulation); + printFrameSync (opts, state, "+DMR ", synctest_pos + 1, modulation); } if (state->lastsynctype != 12) { @@ -1245,10 +1239,10 @@ getFrameSync (dsd_opts * opts, dsd_state * state) else { // inverted data frame - sprintf(state->ftype, " DMR "); + sprintf(state->ftype, "DMR "); if (opts->errorbars == 1) { - printFrameSync (opts, state, " -DMR ", synctest_pos + 1, modulation); + printFrameSync (opts, state, "-DMR ", synctest_pos + 1, modulation); } state->lastsynctype = 13; return (13); @@ -1265,10 +1259,10 @@ getFrameSync (dsd_opts * opts, dsd_state * state) if (opts->inverted_dmr == 0) { // voice frame - sprintf(state->ftype, " DMR "); + sprintf(state->ftype, "DMR "); if (opts->errorbars == 1) { - printFrameSync (opts, state, " +DMR ", synctest_pos + 1, modulation); + printFrameSync (opts, state, "+DMR ", synctest_pos + 1, modulation); } if (state->lastsynctype != 12) { @@ -1280,10 +1274,10 @@ getFrameSync (dsd_opts * opts, dsd_state * state) else { // inverted data frame - sprintf(state->ftype, " DMR "); + sprintf(state->ftype, "DMR "); if (opts->errorbars == 1) { - printFrameSync (opts, state, " -DMR ", synctest_pos + 1, modulation); + printFrameSync (opts, state, "-DMR ", synctest_pos + 1, modulation); } state->lastsynctype = 13; return (13); @@ -1300,10 +1294,10 @@ getFrameSync (dsd_opts * opts, dsd_state * state) if (opts->inverted_dmr == 0) { // voice frame - sprintf(state->ftype, " DMR "); + sprintf(state->ftype, "DMR "); if (opts->errorbars == 1) { - printFrameSync (opts, state, " +DMR ", synctest_pos + 1, modulation); + printFrameSync (opts, state, "+DMR ", synctest_pos + 1, modulation); } if (state->lastsynctype != 12) { @@ -1315,10 +1309,10 @@ getFrameSync (dsd_opts * opts, dsd_state * state) else { // inverted data frame - sprintf(state->ftype, " DMR "); + sprintf(state->ftype, "DMR "); if (opts->errorbars == 1) { - printFrameSync (opts, state, " -DMR ", synctest_pos + 1, modulation); + printFrameSync (opts, state, "-DMR ", synctest_pos + 1, modulation); } state->lastsynctype = 13; return (13); @@ -1711,7 +1705,7 @@ getFrameSync (dsd_opts * opts, dsd_state * state) sprintf (state->ftype, "(DMR)"); if (opts->errorbars == 1) { - printFrameSync (opts, state, "(-DMR) ", synctest_pos + 1, modulation); + printFrameSync (opts, state, "(-DMR)", synctest_pos + 1, modulation); } state->lastsynctype = -1; if (opts->use_ncurses_terminal == 1) @@ -1726,10 +1720,10 @@ getFrameSync (dsd_opts * opts, dsd_state * state) state->offset = synctest_pos; state->max = ((state->max) + lmax) / 2; state->min = ((state->min) + lmin) / 2; - sprintf (state->ftype, "(DMR) "); + sprintf (state->ftype, "(DMR) "); if (opts->errorbars == 1) { - printFrameSync (opts, state, "(+DMR) ", synctest_pos + 1, modulation); + printFrameSync (opts, state, "(+DMR)", synctest_pos + 1, modulation); } state->lastsynctype = -1; if (opts->use_ncurses_terminal == 1) @@ -1778,7 +1772,11 @@ getFrameSync (dsd_opts * opts, dsd_state * state) return (-1); } } - + if ( opts->monitor_input_audio == 1 && (time(NULL) - now) > 1 ) //okay, still something going on, still doing the read part for some reason + //if ( opts->monitor_input_audio == 1) + { + playRawAudio(opts, state); //this is on line 21 in dsd_audio.c + } } return (-1); diff --git a/src/dsd_main.c b/src/dsd_main.c index 45a4090..f11fc00 100644 --- a/src/dsd_main.c +++ b/src/dsd_main.c @@ -191,11 +191,11 @@ initOpts (dsd_opts * opts) opts->rtl_udp_port = 6020; //set UDP port for RTL remote opts->rtl_bandwidth = 12; //changed recommended default to 12, 24 for ProVoice opts->pulse_raw_rate_in = 48000; - opts->pulse_raw_rate_out = 24000; //doing tests with 2 channels at 24000 for 48000 audio default in pulse + opts->pulse_raw_rate_out = 48000; //doing tests with 2 channels at 24000 for 48000 audio default in pulse opts->pulse_digi_rate_in = 48000; opts->pulse_digi_rate_out = 24000; //need to copy this to rtl type in and change rate out to 8000 opts->pulse_raw_in_channels = 1; - opts->pulse_raw_out_channels = 2; + opts->pulse_raw_out_channels = 1; opts->pulse_digi_in_channels = 1; //2 opts->pulse_digi_out_channels = 2; //2 //opts->output_name = "DSD-FME"; @@ -321,6 +321,13 @@ initState (dsd_state * state) state->dpmr_caller_id = 0; state->dpmr_target_id = 0; + state->payload_mi = 0; + state->payload_mfid = 0; + state->payload_algid = 0; + state->payload_keyid = 0; + + state->K = 0; + #ifdef TRACE_DSD state->debug_sample_index = 0; state->debug_label_file = NULL; @@ -650,7 +657,7 @@ main (int argc, char **argv) exitflag = 0; signal (SIGINT, sigfun); - while ((c = getopt (argc, argv, "haep:P:qstv:z:i:o:d:c:g:nw:B:C:R:f:m:u:x:A:S:M:G:D:L:V:U:Y:NWrlZ")) != -1) + while ((c = getopt (argc, argv, "haep:P:qstv:z:i:o:d:c:g:nw:B:C:R:f:m:u:x:A:S:M:G:D:L:V:U:Y:K:NWrlZ")) != -1) { opterr = 0; switch (c) @@ -713,6 +720,11 @@ main (int argc, char **argv) sscanf (optarg, "%d", &opts.verbose); break; + case 'K': + sscanf (optarg, "%d", &state.K); + state.K = ( ((state.K & 0xFF0F) << 32 ) + (state.K << 16) + state.K ); + break; + case 'G': //Set rtl device gain sscanf (optarg, "%d", &opts.rtl_gain_value); //multiple value by ten to make it consitent with the way rtl_fm really works break; @@ -738,10 +750,19 @@ main (int argc, char **argv) break; case 'W': //monitor_input_audio if no sync - opts.monitor_input_audio = 0; - //fprintf (stderr,"Monitor Source Audio Enabled (WIP!) Sounds bad.\n"); - //fprintf (stderr,"Monitor Source Audio may cause decoding issues.\n"); - fprintf (stderr,"Monitor Source Audio currently disabled in Pulse Audio Builds.\n"); + opts.monitor_input_audio = 1; + fprintf (stderr,"Monitor Source Audio Enabled.\n"); + //opts.pulse_raw_rate_in = 48000; + //opts.pulse_raw_rate_out = 48000; //doing tests with 2 channels at 24000 for 48000 audio default in pulse + //opts.pulse_digi_rate_in = 48000; + //opts.pulse_digi_rate_out = 48000; //need to copy this to rtl type in and change rate out to 8000 + //opts.pulse_raw_in_channels = 1; + //opts.pulse_raw_out_channels = 1; + //opts.pulse_digi_in_channels = 1; //2 + //opts.pulse_digi_out_channels = 1; //2 + fprintf (stderr," Monitor Source Audio may cause decoding issues.\n"); + fprintf (stderr," Don't Run Monitor Source Audio with Ncurses Terminal.\n"); + opts.use_ncurses_terminal = 0; //may not set depends on when -N and -W are first and second break; case 'N': diff --git a/src/dsd_ncurses.c b/src/dsd_ncurses.c index cd59917..f860a3f 100644 --- a/src/dsd_ncurses.c +++ b/src/dsd_ncurses.c @@ -31,6 +31,7 @@ int reset = 0; char c; //getch key int tg; //last tg +int tgn; int rd; //last rid int rn; //last ran int nc; //nac @@ -188,7 +189,7 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) call_matrix[9][1] = rn; call_matrix[9][2] = src; call_matrix[9][3] = 0; - call_matrix[9][4] = tg; + call_matrix[9][4] = tgn; call_matrix[9][5] = time(NULL); } @@ -278,12 +279,12 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) if (state->carrier == 1){ //figure out method that will tell me when is active and when not active, maybe carrier but this doesn't print anyways unless activity attron(COLOR_PAIR(3)); level = (int) state->max / 164; //only update on carrier present - reset = 1; + //reset = 1; } if (state->carrier == 0 && opts->reset_state == 1 && reset == 1) { - resetState (state); - reset = 0; + //resetState (state); + //reset = 0; } @@ -317,9 +318,9 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) { rn = state->nxdn_last_ran; } - if (state->nxdn_last_tg > 0 && state->nxdn_last_tg != tg); + if (state->nxdn_last_tg > 0 && state->nxdn_last_tg != tgn); { - tg = state->nxdn_last_tg; + tgn = state->nxdn_last_tg; } //if (state->dmr_color_code > 0 && (lls == 10 || lls == 11 || lls == 12 || lls == 13) ) //DMR, DCC only carried on Data? @@ -334,22 +335,22 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) if (state->lastsrc > 0 && (lls == 12 || lls == 13 || lls == 0 || lls == 1)) //DMR Voice and P25P1 { rd = state->lastsrc; - opts->p25enc = 0; + //opts->p25enc = 0; } if (state->lasttg > 0 && (lls == 12 || lls == 13 || lls == 0 || lls == 1)) //DMR Voice and P25P1 { tg = state->lasttg; - opts->p25enc = 0; + //opts->p25enc = 0; } //if (state->lastsynctype == 8 || state->lastsynctype == 9 || state->lastsynctype == 16 || state->lastsynctype == 17) //change this to NXDN syncs later on if (lls == 8 || lls == 9 || lls == 16 || lls == 17) { printw ("| RAN: [%02d] ", rn); - printw ("TID: [%d] ", tg); + printw ("TID: [%04d] ", tgn); //printw ("| RID: [%d] \n", src); - printw ("RID: [%d] \n| ALG: [0x%02X] KEY [0x%02X] ", src, state->nxdn_cipher_type, state->nxdn_key); + printw ("RID: [%04d] \n| ALG: 0x[%02X] KEY 0x[%02X] ", src, state->nxdn_cipher_type, state->nxdn_key); if (state->carrier == 1) { printw("%s ", state->nxdn_call_type); @@ -408,8 +409,8 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) { //printw("| TID:[%i] | RID:[%i] \n", tg, rd); //printw("| NAC: [0x%X] \n", nc); - printw("| TID:[%i] RID:[%i] ", tg, rd); - printw("NAC: [0x%X] \n", nc); + printw("| TID:[%08i] RID:[%08i] ", tg, rd); + printw("NAC: [0x%03X] \n", nc); printw("| ALG: [0x%02X] ", state->payload_algid); printw("KEY: [0x%04X] ", state->payload_keyid); //printw("MFG: [0x%X] ", state->payload_mfid); //no way of knowing if this is accurate info yet @@ -427,8 +428,34 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) if (lls == 12 || lls == 13) //DMR Voice Types { //printw ("| DCC: [%i] FID: [%02X]\n", dcc, state->dmr_fid); - printw ("| DCC: [%i] FID: [%02X] SOP: [%X] \n", dcc, state->dmr_fid, state->dmr_so); - printw ("| TID: [%i] RID: [%i]", tg, rd); + //attron(COLOR_PAIR(3)); + printw ("| DCC: [%02i] FID: [%02X] SOP: [%02X] ", dcc, state->dmr_fid, state->dmr_so); + if(state->payload_mi == 0 && state->dmr_so & 0x40) + { + attron(COLOR_PAIR(5)); + printw ("**BP** "); + //printw ("0x%X", state->payload_algid); + attroff(COLOR_PAIR(5)); + attron(COLOR_PAIR(3)); + } + if(state->payload_keyid > 0 && state->dmr_so & 0x40) + { + attron(COLOR_PAIR(5)); + printw (" ALG: [0x%02X] KEY [0x%02X] MI 0x[%08X]", state->payload_algid, state->payload_keyid, state->payload_mi); + //printw ("0x%X", state->payload_algid); + attroff(COLOR_PAIR(5)); + attron(COLOR_PAIR(3)); + } + if(state->K > 0 && state->dmr_so & 0x40) + { + attron(COLOR_PAIR(5)); + //printw ("K 0x[%12llX]", state->K); //seems to get reset in ncurses for some reason? some bigger issue perhaps? other strange issues occur too with provoice + attroff(COLOR_PAIR(5)); + attron(COLOR_PAIR(3)); + } + + printw("\n"); + printw ("| TID: [%08i] RID: [%08i]", tg, rd); if(state->dmr_so & 0x80) //1000 0000 { attron(COLOR_PAIR(2)); @@ -444,7 +471,11 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) //printw ("0x%X", state->payload_algid); attroff(COLOR_PAIR(2)); attron(COLOR_PAIR(3)); - opts->p25enc = 1; //just testing for now + //if (state->K = 0) + //{ + //opts->p25enc = 1; //just testing for now + //} + } if(state->dmr_so & 0x30) //0010 0000 @@ -479,8 +510,8 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) if (lls == 10 || lls == 11 ) //DMR Data Types { //printw ("| DCC: [%i]\n", dcc); - printw ("| DCC: [%i] FID: [%02X] SOP: [%X] \n", dcc, state->dmr_fid, state->dmr_so); - printw ("| TID: [%i] RID: [%i]", tg, rd); + printw ("| DCC: [%02i] FID: [%02X] SOP: [%02X] \n", dcc, state->dmr_fid, state->dmr_so); + printw ("| TID: [%08i] RID: [%08i]", tg, rd); //does this need to be in DATA type? /* if(state->dmr_so & 0x80) @@ -567,23 +598,23 @@ ncursesPrinter (dsd_opts * opts, dsd_state * state) printw ("| #%d %s ", j, SyncTypes[call_matrix[9-j][0]]); if (lls == 8 || lls == 9 || lls == 16 || lls == 17) { - printw ("RAN [%2d] ", call_matrix[9-j][1]); - printw ("TG [%d] ", call_matrix[9-j][4]); + printw ("RAN [%02d] ", call_matrix[9-j][1]); + printw ("TG [%04d] ", call_matrix[9-j][4]); } if (lls == 0 || lls == 1 || lls == 12 || lls == 13 || lls == 10 || lls == 11 ) //P25 P1 and DMR { - printw ("TID [%2d] ", call_matrix[9-j][1]); + printw ("TID [%08d] ", call_matrix[9-j][1]); } - printw ("RID [%4d] ", call_matrix[9-j][2]); + printw ("RID [%08d] ", call_matrix[9-j][2]); //printw ("S %d - ", call_matrix[j][3]); if (call_matrix[9-j][0] == 0 || call_matrix[9-j][0] == 1) //P25P1 Voice { - printw ("NAC [0x%X] ", call_matrix[9-j][4]); + printw ("NAC [0x%03X] ", call_matrix[9-j][4]); } if (call_matrix[9-j][0] == 12 || call_matrix[9-j][0] == 13 || call_matrix[9-j][0] == 10 || call_matrix[9-j][0] == 11 ) //DMR Voice Types { - printw ("DCC [%d] ", call_matrix[9-j][4]); + printw ("DCC [%02d] ", call_matrix[9-j][4]); } printw ("%d secs ago\n", time(NULL) - call_matrix[9-j][5]); } diff --git a/src/dsd_symbol.c b/src/dsd_symbol.c index 131cf2f..e132ce5 100644 --- a/src/dsd_symbol.c +++ b/src/dsd_symbol.c @@ -111,6 +111,7 @@ getSymbol (dsd_opts * opts, dsd_state * state, int have_sync) #ifdef USE_RTLSDR // TODO: need to read demodulated stream here get_rtlsdr_sample(&sample); + //state->pulse_raw_out_buffer = sample; #endif } diff --git a/src/nxdn_lib.c b/src/nxdn_lib.c index 6ed5f45..f3a1e1c 100644 --- a/src/nxdn_lib.c +++ b/src/nxdn_lib.c @@ -736,15 +736,17 @@ 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, "\n\t %s - ", NXDN_Call_Type_To_Str(CallType)); //line break 1 tab, 2 spaces start this string - sprintf (state->nxdn_call_type, NXDN_Call_Type_To_Str(CallType)); + sprintf (state->nxdn_call_type, NXDN_Call_Type_To_Str(CallType)); //fix warning below + //warning: format not a string literal and no format arguments [-Wformat-security] + //state->nxdn_call_type = NXDN_Call_Type_To_Str(CallType); /* Print the "Voice Call Option" */ NXDN_Voice_Call_Option_To_Str(VoiceCallOption, DuplexMode, TransmissionMode); fprintf(stderr, "%s %s - ", DuplexMode, TransmissionMode); - state->nxdn_key = (KeyID & 0xFF); - state->nxdn_cipher_type = CipherType; + //state->nxdn_key = (KeyID & 0xFF); + //state->nxdn_cipher_type = CipherType; /* Print the "Cipher Type" */ if(CipherType != 0) { @@ -761,13 +763,16 @@ 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); - state->nxdn_last_tg = (DestinationID & 0xFFFF); + if(state->NxdnElementsContent.VCallCrcIsGood) { if ( (SourceUnitID & 0xFFFF) > 0 ) { - state->nxdn_last_rid = SourceUnitID & 0xFFFF; //only grab if CRC is okay + state->nxdn_last_rid = SourceUnitID & 0xFFFF; //only grab if CRC is okay + state->nxdn_last_tg = (DestinationID & 0xFFFF); + state->nxdn_key = (KeyID & 0xFF); + state->nxdn_cipher_type = CipherType; } fprintf(stderr, " (OK) - "); }