From d2d750e920eaae47d0b08056bb4bdda4feb289d2 Mon Sep 17 00:00:00 2001 From: lwvmobile Date: Thu, 19 Jan 2023 09:39:05 -0500 Subject: [PATCH] Tweak RAS/CRC; Other Misc Tweaks; --- .gitignore | 3 +- src/dmr_dburst.c | 19 +++++--- src/dmr_flco.c | 4 +- src/dmr_le.c | 114 +++++++++++++++++++++++++---------------------- src/provoice.c | 22 ++++----- 5 files changed, 90 insertions(+), 72 deletions(-) diff --git a/.gitignore b/.gitignore index 83b9a67..57ad766 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ *.dylib build *.sh - +*.csv +examples diff --git a/src/dmr_dburst.c b/src/dmr_dburst.c index 374aac5..c1c583e 100644 --- a/src/dmr_dburst.c +++ b/src/dmr_dburst.c @@ -210,8 +210,6 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 //debug print //fprintf (stderr, " RAS? %X - %d %d %d", BPTCReservedBits, R[0], R[1], R[2]); - //set the 'RAS Flag' - if (BPTCReservedBits != 0) is_ras = 1; //!=0, or == 0x4 /* Convert the 96 bits BPTC data into 12 bytes */ k = 0; @@ -252,7 +250,17 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 CRCComputed = ComputeCrcCCITT(BPTCDmrDataBit); if (CRCComputed == CRCExtracted) CRCCorrect = 1; else CRCCorrect = 0; - } + } + + //set the 'RAS Flag', if no irrecoverable errors but bad crc + if (CRCCorrect == 0 && IrrecoverableErrors == 0 && BPTCReservedBits == 4) is_ras = 1; //!=0, or == 0x4, or just R[2] == 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 is okay + //if we don't do this, then we can't view some data (CSBKs on RAS enabled systems) + if (is_ras == 1) CRCCorrect = 1; if (databurst == 0x04 || databurst == 0x06) //MBC Header, Data Header { @@ -444,10 +452,11 @@ void dmr_data_burst_handler(dsd_opts * opts, dsd_state * state, uint8_t info[196 if (databurst == 0x05) dmr_block_assembler (opts, state, DMR_PDU, pdu_len, databurst, 2); //print whether or not the 'RAS Field' bits are set to indicate RAS enabled (to be verified) - if (IrrecoverableErrors == 0 && is_ras == 1) + if (is_ras == 1) { fprintf (stderr, "%s", KRED); - fprintf (stderr, " RAS "); + fprintf (stderr, " CRC/RAS "); + //the value of this field seems to always, or usually, be 4, or just R[2] bit is set if (opts->payload == 1) fprintf (stderr, "%X ", BPTCReservedBits); fprintf (stderr, "%s", KNRM); } diff --git a/src/dmr_flco.c b/src/dmr_flco.c index 22f7ba9..8a8689b 100644 --- a/src/dmr_flco.c +++ b/src/dmr_flco.c @@ -53,7 +53,7 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C } - if (IrrecoverableErrors == 0) + if (IrrecoverableErrors == 0 && CRCCorrect == 1) { //Embedded Talker Alias Header Only (format and len storage) if (type == 3 && flco == 0x04) @@ -90,7 +90,7 @@ void dmr_flco (dsd_opts * opts, dsd_state * state, uint8_t lc_bits[], uint32_t C //will want to continue to observe for different flco and fid combinations to find out their meaning //Standard Addressing/Cap+ Addressing (trying to avoid embedded alias and gps, etc) - if(IrrecoverableErrors == 0 && is_alias == 0 && is_gps == 0) + if(IrrecoverableErrors == 0 && is_alias == 0 && is_gps == 0 && CRCCorrect == 1) { //set overarching manufacturer in use when non-standard feature id set is up //may not want to set moto 0x10 here either, lots of radios use that set as well diff --git a/src/dmr_le.c b/src/dmr_le.c index f247d3f..2954730 100644 --- a/src/dmr_le.c +++ b/src/dmr_le.c @@ -183,26 +183,29 @@ void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power) if (opts->payload == 1) fprintf (stderr, " CRC EXT %02X, CRC CMP %02X", crc_extracted, crc_computed); } else crc_okay = 1; //SB - - fprintf (stderr, "\n %s", KCYN); - if (power == 0) fprintf (stderr, " SB: "); - if (power == 1) fprintf (stderr, " RC: "); - for(i = 0; i < 11; i++) - { - sbrc_hex = sbrc_hex << 1; - sbrc_hex |= sbrc_return[i] & 1; //sbrc_return - fprintf (stderr, "%d", sbrc_return[i]); - } - fprintf (stderr, " - %03X", sbrc_hex); - fprintf (stderr, "%s", KNRM); - if (crc_okay == 0) + if (opts->payload == 1) //hide the sb/rc behind the payload printer, won't be useful to most people right now { - fprintf (stderr, "%s", KRED); - fprintf (stderr, " (CRC ERR)"); + fprintf (stderr, "\n %s", KCYN); + if (power == 0) fprintf (stderr, " SB: "); + if (power == 1) fprintf (stderr, " RC: "); + for(i = 0; i < 11; i++) + { + sbrc_hex = sbrc_hex << 1; + sbrc_hex |= sbrc_return[i] & 1; //sbrc_return + fprintf (stderr, "%d", sbrc_return[i]); + } + fprintf (stderr, " - %03X", sbrc_hex); fprintf (stderr, "%s", KNRM); - } + if (crc_okay == 0) + { + fprintf (stderr, "%s", KRED); + fprintf (stderr, " (CRC ERR)"); + fprintf (stderr, "%s", KNRM); + } + } + //sbrc_hex value of 0x313 seems to be some Cap+ Thing, //also observed 0x643 on another cap+ system (site id, status? something?) //I've observed it in the Private Cap+ TXI calls as well @@ -211,58 +214,61 @@ void dmr_sbrc (dsd_opts * opts, dsd_state * state, uint8_t power) uint8_t alg = sbrc_hex & 3; uint16_t key = (sbrc_hex >> 3) & 0xFF; - if (irr_err != 0) fprintf (stderr, "%s (FEC ERR) %d %s", KRED, irr_err, KNRM); - if (irr_err == 0) + if (opts->payload == 1) { - if (sbrc_hex == 0) ; //NULL - else if (sbrc_hex == 0x313) - { - //Cap+ Thing? Observed On Cap+ Systems - // fprintf (stderr, " Cap+ Thing?"); - } - else + if (irr_err != 0) fprintf (stderr, "%s (FEC ERR) %d %s", KRED, irr_err, KNRM); + if (irr_err == 0) { + if (sbrc_hex == 0) ; //NULL + else if (sbrc_hex == 0x313) + { + //Cap+ Thing? Observed On Cap+ Systems + // fprintf (stderr, " Cap+ Thing?"); + } + else + { - if (slot == 0) - { - //key and alg only present SOME times, not all, - //also, intermixed with other signalling - //needs more study first! - if (state->dmr_so & 0x40 && key != 0 && state->payload_keyid == 0) + if (slot == 0) { - if (opts->payload == 1) + //key and alg only present SOME times, not all, + //also, intermixed with other signalling + //needs more study first! + if (state->dmr_so & 0x40 && key != 0 && state->payload_keyid == 0) { - fprintf (stderr, "%s ", KYEL); - fprintf (stderr, "\n Slot 1"); - fprintf (stderr, " DMR LE SB ALG ID: %X KEY ID: %0X", alg + 0x20, key); - fprintf (stderr, "%s ", KNRM); + if (opts->payload == 1) + { + fprintf (stderr, "%s ", KYEL); + fprintf (stderr, "\n Slot 1"); + fprintf (stderr, " DMR LE SB ALG ID: %X KEY ID: %0X", alg + 0x20, key); + fprintf (stderr, "%s ", KNRM); + } + + //needs more study before assignment + //state->payload_keyid = key; + //state->payload_algid = alg + 0x20; //assuming DMRA approved alg values (moto patent) } - - //needs more study before assignment - //state->payload_keyid = key; - //state->payload_algid = alg + 0x20; //assuming DMRA approved alg values (moto patent) } - } - if (slot == 1) - { - if (state->dmr_soR & 0x40 && key != 0 && state->payload_keyidR == 0) + if (slot == 1) { - if (opts->payload == 1) + if (state->dmr_soR & 0x40 && key != 0 && state->payload_keyidR == 0) { - fprintf (stderr, "%s ", KYEL); - fprintf (stderr, "\n Slot 2"); - fprintf (stderr, " DMR LE SB ALG ID: %X KEY ID: %0X", alg + 0x20, key); - fprintf (stderr, "%s ", KNRM); + if (opts->payload == 1) + { + fprintf (stderr, "%s ", KYEL); + fprintf (stderr, "\n Slot 2"); + fprintf (stderr, " DMR LE SB ALG ID: %X KEY ID: %0X", alg + 0x20, key); + fprintf (stderr, "%s ", KNRM); + } + + //needs more study before assignment + //state->payload_keyidR = key; + //state->payload_algidR = alg + 0x20; //assuming DMRA approved alg values (moto patent) } - - //needs more study before assignment - //state->payload_keyidR = key; - //state->payload_algidR = alg + 0x20; //assuming DMRA approved alg values (moto patent) } + } } - } SBRC_END: diff --git a/src/provoice.c b/src/provoice.c index 9678120..24fc26d 100644 --- a/src/provoice.c +++ b/src/provoice.c @@ -33,11 +33,11 @@ processProVoice (dsd_opts * opts, dsd_state * state) #ifdef PROVOICE_DUMP fprintf (stderr," "); #endif - //init Bits (64)...MI? + //iNitial 64 bits if (opts->payload == 1) { k = 0; - //fprintf (stderr, "\nInit 64 "); + fprintf (stderr, "\n N64: "); for(i = 0; i < 8; i++) { initbyte[i] = 0; @@ -47,9 +47,10 @@ processProVoice (dsd_opts * opts, dsd_state * state) initbyte[i] = initbyte[i] | init[k]; k++; } - //fprintf (stderr, "%02X", initbyte[i]); + fprintf (stderr, "%02X", initbyte[i]); + if (i == 3) fprintf (stderr, "-"); } - //fprintf (stderr, "\n"); + fprintf (stderr, "\n"); } // lid for (i = 0; i < 16; i++) @@ -79,7 +80,7 @@ processProVoice (dsd_opts * opts, dsd_state * state) if (opts->payload == 1) { k = 0; - //fprintf (stderr, "LID "); + fprintf (stderr, " LID: "); for(i = 0; i < 10; i++) { lidbyte[i] = 0; @@ -89,9 +90,10 @@ processProVoice (dsd_opts * opts, dsd_state * state) lidbyte[i] = lidbyte[i] | lid[k]; k++; } - //fprintf (stderr, "%02X", lidbyte[i]); + fprintf (stderr, "%02X", lidbyte[i]); + if (i == 3 || i == 7) fprintf (stderr, "-"); } - //fprintf (stderr, "\n"); + // fprintf (stderr, "\n"); } @@ -337,7 +339,7 @@ processProVoice (dsd_opts * opts, dsd_state * state) if (opts->payload == 1) { k = 0; - //fprintf (stderr, "16 bits? "); + fprintf (stderr, "\n 16B: "); for(i = 0; i < 2; i++) { initbyte[i] = 0; @@ -347,9 +349,9 @@ if (opts->payload == 1) initbyte[i] = initbyte[i] | init[k]; k++; } - //fprintf (stderr, "%02X", initbyte[i]); + fprintf (stderr, "%02X", initbyte[i]); } - //fprintf (stderr, "\n"); + // fprintf (stderr, "\n"); } // imbe frames 3,4 first half w = pW;