Skip to content

Commit

Permalink
sync: Merge remote-tracking branch 'travis/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
roelandjansen committed Feb 13, 2020
2 parents 5be66a3 + 993dc1a commit 2d1bfe1
Show file tree
Hide file tree
Showing 6 changed files with 723 additions and 637 deletions.
93 changes: 49 additions & 44 deletions applet/src/etsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@

#include "etsi.h"
#include "debug.h"
#include "syslog.h"
#include <string.h>

struct TAContext taContext;
struct TAContext talkerAlias;
struct TAContext talkerAlias = {
.src = 0,
.length = 0
};


inline const char* get_flco_str( lc_t *lc )
Expand Down Expand Up @@ -62,8 +66,6 @@ inline const char* get_ta_type_str(uint8_t taFormat)
}
}



// Full Link Control PDU
void dump_full_lc( lc_t *lc )
{
Expand All @@ -72,17 +74,28 @@ void dump_full_lc( lc_t *lc )
uint8_t opts = lc->svc_opts ;

PRINT("flco=%02x %s fid=%d svc=%d src=%d dst=%d\n",flco,get_flco_str(lc), fid,opts,get_adr(lc->src),get_adr(lc->dst));
return;
}

if (flco == 0 && fid == 0x00 && taContext.src != get_adr(lc->src))
{
memset(&taContext, 0, sizeof(taContext)); //Clear TA context
memset(&talkerAlias, 0, sizeof(talkerAlias)); //Clear TA context
taContext.src = (uint32_t)get_adr(lc->src);
}
// TA Decode
void decode_ta( lc_t *lc )
{
uint8_t flco = get_flco(lc);

if (!(flco >=4 && flco <= 7))
return;

// decode ta once, ta length will be reset to 0 when call is started (or after the later-entry header is received).
if (talkerAlias.length > 0)
return;

//Read TA Header from full LC
if (flco == 4 && fid == 0x00)
if (flco == 4)
{
// LOGR("decode ta head %d\n", talkerAlias.src);
memset(&taContext, 0, sizeof(taContext)); //Clear TA context
taContext.src = get_adr( lc->src );

struct TAHeader* header = (struct TAHeader*)lc; //Copy LC over TA struct
taContext.format = (header->options >> 6) & 0x03;
taContext.length = (header->options >> 1) & 0x1f;
Expand All @@ -106,53 +119,45 @@ void dump_full_lc( lc_t *lc )
((length > row[1]) << 2) |
((length > row[2]) << 3);
taContext.marked |= 0b0001;

//Print TA if no more blocks
if (taContext.blocks == taContext.marked)
{
if (taContext.format == 1 || taContext.format == 2)
{
PRINT("TA %d (%d): %s\n", taContext.src, taContext.length, taContext.text);
if (talkerAlias.src != taContext.src)
{
talkerAlias = taContext;
}
}
else
{
PRINT("TA Unsupported format: %s", get_ta_type_str(taContext.format));
talkerAlias.length = 0;
}
}
}

//Read TA Block from the full LC header
if (flco > 4 && flco < 8 && fid == 0x00)
else
{
// LOGR("decode ta block%d, %d\n", flco - 4, talkerAlias.src);
struct TABlock* block = (struct TABlock*)lc;

//Copy TA block to context
char* destination = taContext.text;
destination += 6 + 7 * (flco - 5);
memcpy(destination, block->text, 7);
taContext.marked |= 1 << (flco - 4);
}

//Print TA if no more blocks
if (taContext.blocks == taContext.marked)
// decode if all blocks received
if (taContext.blocks == taContext.marked) {
if (taContext.format == 1 || taContext.format == 2)
{
if (taContext.format == 1 || taContext.format == 2)
{
PRINT("TA %d (%d): %s\n", taContext.src, taContext.length, taContext.text);
if (talkerAlias.src != taContext.src)
{
talkerAlias = taContext;
}
}
else
PRINT("TA %d (%d): %s\n", taContext.src, taContext.length, taContext.text);
talkerAlias = taContext;
LOGR("TA: %s, %d\n", talkerAlias.text, talkerAlias.length);
}
else if (taContext.format == 3)
{
// poor man's iconv.
int i = 0;
for (i = 0;i < taContext.length; i++)
{
PRINT("TA Unsupported format: %s", get_ta_type_str(taContext.format));
talkerAlias.length = 0;
if (taContext.text[i * 2] == 0)
talkerAlias.text[i] = taContext.text[i * 2 + 1];
else
talkerAlias.text[i] = '?';
}
talkerAlias.text[i] = 0;
talkerAlias.length = taContext.length;
LOGR("TA: %s, %d\n", talkerAlias.text, talkerAlias.length);
}
else
{
PRINT("TA Unsupported format: %s", get_ta_type_str(taContext.format));
}
}
}
2 changes: 2 additions & 0 deletions applet/src/etsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ typedef struct lc {

void dump_full_lc( lc_t *lc );

void decode_ta( lc_t *lc );

inline uint8_t get_flco( lc_t *lc )
{
return lc->pf_flco & 0x3f ;
Expand Down
92 changes: 63 additions & 29 deletions applet/src/radiostate.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,35 +65,65 @@ void updateSrcDst(int src, int dst)

void rst_voice_lc_header(lc_t *lc)
{
int src = get_adr( lc->src );
int dst = get_adr( lc->dst );
//
// DMR FULL_LC DATA CALLBCK
//
// This callback method will be called when a FULL_LC data is decoded,
// it LC data will be a DT_VOICE_HEADER_LC DMRData frame,
// or reassembled FULL_LC data from DMR Voice EmbeddedData.
//
// Please see ETSI doc for the all above concepts/details.
//
// - BG5HHP
//
int flco = get_flco( lc );

int groupcall = flco == 0;
if(groupcall)
g_src = src;

if(( !rst_voice_active || rst_src != src || rst_dst != dst)) {
updateSrcDst(src, dst);
rst_flco = flco ;

PRINT("\n* Call from %d to %s%d started.\n", src, groupcall ? "group ":"", dst);

PRINT("cs " );
dump_full_lc(lc);

char grp_c = 'U' ;
if( flco == 0 ) {
grp_c = 'G' ;
rst_grp = 1 ;
} else {
rst_grp = 0 ;
if (flco == 0 || flco == 3) { // FULL_LC for LC Header - BG5HHP
int src = get_adr( lc->src );
int dst = get_adr( lc->dst );

int groupcall = flco == 0;
if(groupcall)
g_src = src;

if(( !rst_voice_active || rst_src != src || rst_dst != dst)) {
updateSrcDst(src, dst);
rst_flco = flco ;

PRINT("\n* Call from %d to %s%d started.\n", src, groupcall ? "group ":"", dst);

PRINT("cs " );

if (talkerAlias.src == 0) {
// mark call start.
// we'd better store the call state in a global LCHeader structure
// and remove the redundant variables.
// - BG5HHP
talkerAlias.src = src;
talkerAlias.length = 0;
}

char grp_c = 'U' ;
if( flco == 0 ) {
grp_c = 'G' ;
rst_grp = 1 ;
} else {
rst_grp = 0 ;
}

LOGR("cs %c %d->%d\n", grp_c, src, dst );
rst_voice_active = 1 ;
rx_voice = 1 ; // flag for new voice call received
}

LOGR("cs %c %d->%d\n", grp_c, src, dst );

rst_voice_active = 1 ;
rx_voice = 1 ; // flag for new voice call received
} else if (flco >=4 && flco <=7 ) { // FULL_LC for TalkerAlias - BG5HHP
LOGR("ta %d %d->%d\n", flco - 4, rst_src, rst_dst);
decode_ta(lc);
} else if (flco == 8) { // FULL_LC for GPS - BG5HHP
LOGR("gps %c %d->%d\n", rst_grp?'G':'U', rst_src, rst_dst);
} else {
// Unknown type,
LOGR("unknown %c %d->%d\n", rst_grp?'G':'U', rst_src, rst_dst);
}
}

Expand All @@ -102,14 +132,18 @@ void rst_term_with_lc(lc_t *lc)
int src = get_adr( lc->src );
int dst = get_adr( lc->dst );
int flco = get_flco( lc );
int groupcall = flco == 0;

int groupcall = (flco == 0);
if(groupcall)
g_src = src;

if( rst_voice_active) {
updateSrcDst(src, dst);
PRINT("\n* Call from %d to %s%d ended.\n", src, groupcall ? "group ":"", dst);


// mark call terminate - BG5HHP
talkerAlias.src = 0;

PRINT("ce " );
dump_full_lc(lc);

Expand All @@ -118,7 +152,7 @@ void rst_term_with_lc(lc_t *lc)
grp_c = 'G' ;
}

LOGR("ce %c %d->%d\n", grp_c, src, dst );
LOGR("ce %c %d->%d\n", grp_c, src, dst);

rst_voice_active = 0 ;
rx_voice = 0 ; // flag for voice call ended
Expand Down
Loading

0 comments on commit 2d1bfe1

Please sign in to comment.