diff --git a/QnetGateway.cpp b/QnetGateway.cpp index 884a831..634295f 100644 --- a/QnetGateway.cpp +++ b/QnetGateway.cpp @@ -918,13 +918,9 @@ void CQnetGateway::process() (g2buf.hdr.flag[0] == 0x28) || (g2buf.hdr.flag[0] == 0x40))) { if (bool_qso_details) - printf("START from g2: streamID=%04x, flags=%02x:%02x:%02x, my=%.8s, sfx=%.4s, ur=%.8s, rpt1=%.8s, rpt2=%.8s, %d bytes fromIP=%s and port %u\n", - g2buf.streamid, - g2buf.hdr.flag[0], g2buf.hdr.flag[1], g2buf.hdr.flag[2], - g2buf.hdr.mycall, - g2buf.hdr.sfx, g2buf.hdr.urcall, - g2buf.hdr.rpt1, g2buf.hdr.rpt2, - g2buflen, inet_ntoa(fromDst4.sin_addr), ntohs(fromDst4.sin_port)); + printf("START DVST G2, id=%04x ur=%.8s r1=%.8s r2=%.8s my=%.8s/%.4s IP=%s:%u\n", + ntohs(g2buf.streamid), g2buf.hdr.mycall, g2buf.hdr.rpt1, g2buf.hdr.rpt2, + g2buf.hdr.urcall, g2buf.hdr.sfx, inet_ntoa(fromDst4.sin_addr), ntohs(fromDst4.sin_port)); memcpy(rptrbuf.pkt_id, "DSTR", 4); rptrbuf.counter = htons(is_icom ? G2_COUNTER_OUT++ : toRptr[i].G2_COUNTER++); // bump the counter @@ -951,10 +947,8 @@ void CQnetGateway::process() } } } else { // g2buflen == 27 - if (g2buf.counter & 0x40) { - if (bool_qso_details) - printf("END from g2: streamID=%04x, %d bytes from IP=%s\n", g2buf.streamid, g2buflen,inet_ntoa(fromDst4.sin_addr)); - } + if (bool_qso_details && g2buf.counter & 0x40) + printf("Send G2 end of stream: id=%04x\n", ntohs(g2buf.streamid)); /* find out which repeater module to send the data to */ int i; @@ -1084,12 +1078,10 @@ void CQnetGateway::process() if (recvlen == 58) { if (bool_qso_details) - printf("START from rptr: cntr=%04x, streamID=%04x, flags=%02x:%02x:%02x, my=%.8s, sfx=%.4s, ur=%.8s, rpt1=%.8s, rpt2=%.8s, %d bytes fromIP=%s\n", - ntohs(rptrbuf.counter), - ntohs(rptrbuf.vpkt.streamid), - rptrbuf.vpkt.hdr.flag[0], rptrbuf.vpkt.hdr.flag[1], rptrbuf.vpkt.hdr.flag[2], - rptrbuf.vpkt.hdr.my, rptrbuf.vpkt.hdr.nm, rptrbuf.vpkt.hdr.ur, - rptrbuf.vpkt.hdr.r1, rptrbuf.vpkt.hdr.r2, recvlen, inet_ntoa(fromRptr.sin_addr)); + printf("START DSTR RPTR: cntr=%04x id=%04x ur=%.8s r1=%.8s r2=%.8s my=%.8s/%.4s ip=%s\n", + ntohs(rptrbuf.counter), ntohs(rptrbuf.vpkt.streamid), + rptrbuf.vpkt.hdr.ur, rptrbuf.vpkt.hdr.r1, rptrbuf.vpkt.hdr.r2, + rptrbuf.vpkt.hdr.my, rptrbuf.vpkt.hdr.nm, inet_ntoa(fromRptr.sin_addr)); if ((memcmp(rptrbuf.vpkt.hdr.r1, OWNER.c_str(), 7) == 0) && /* rpt1 is this repeater */ /*** (memcmp(rptrbuf + 44, OWNER, 7) != 0) && ***/ /* MYCALL is NOT this repeater */ @@ -2136,10 +2128,8 @@ void CQnetGateway::process() } } - if (rptrbuf.vpkt.ctrl & 0x40) { - if (bool_qso_details) - printf("END from rptr: cntr=%04x, streamID=%04x, %d bytes\n", ntohs(rptrbuf.counter), ntohs(rptrbuf.vpkt.streamid), recvlen); - } + if (bool_qso_details && rptrbuf.vpkt.ctrl&0x40) + printf("END DSTR RPTR: cntr=%04x, id=%04x\n", ntohs(rptrbuf.counter), ntohs(rptrbuf.vpkt.streamid)); } } } diff --git a/QnetRelay.cpp b/QnetRelay.cpp index bf5656b..7b3d771 100644 --- a/QnetRelay.cpp +++ b/QnetRelay.cpp @@ -230,42 +230,42 @@ int CQnetRelay::SendTo(const int fd, const unsigned char *buf, const int size, c bool CQnetRelay::ProcessGateway(const int len, const unsigned char *raw) { if (29==len || 58==len) { //here is dstar data - SDSTR buf; - ::memcpy(buf.pkt_id, raw, len); // transfer raw data to SDSTR struct + SDSTR dstr; + ::memcpy(dstr.pkt_id, raw, len); // transfer raw data to SDSTR struct - SDSRP pkt; // destination + SDSRP dsrp; // destination // fill in some inital stuff - ::memcpy(pkt.title, "DSRP", 4); - pkt.voice.id = buf.vpkt.streamid; - pkt.voice.seq = buf.vpkt.ctrl; + ::memcpy(dsrp.title, "DSRP", 4); + dsrp.voice.id = dstr.vpkt.streamid; // voice or header is the same position + dsrp.voice.seq = dstr.vpkt.ctrl; // ditto if (29 == len) { // write an AMBE packet - pkt.tag = 0x21U; - if (pkt.voice.seq & 0x40) -// printf("INFO: ProcessGateway: sending voice end-of-stream\n"); - ; - else if (pkt.voice.seq > 20) - printf("DEBUG: ProcessGateway: unexpected voice sequence number %d\n", pkt.voice.seq); - pkt.voice.err = 0; // NOT SURE WHERE TO GET THIS FROM THE INPUT buf - memcpy(pkt.voice.ambe, buf.vpkt.vasd.voice, 12); - int ret = SendTo(msock, pkt.title, 21, MMDVM_IP, MMDVM_IN_PORT); + dsrp.tag = 0x21U; + if (log_qso && dsrp.voice.seq&0x40) + printf("Sent DSRP end of streamid=%04x\n", ntohs(dsrp.voice.id)); + else if (dsrp.voice.seq > 20) + printf("DEBUG: ProcessGateway: unexpected voice sequence number %d\n", dsrp.voice.seq); + dsrp.voice.err = 0; // NOT SURE WHERE TO GET THIS FROM THE INPUT buf + memcpy(dsrp.voice.ambe, dstr.vpkt.vasd.voice, 12); + int ret = SendTo(msock, dsrp.title, 21, MMDVM_IP, MMDVM_IN_PORT); if (ret != 21) { printf("ERROR: ProcessGateway: Could not write AMBE mmdvm packet\n"); return true; } } else { // write a Header packet - pkt.tag = 0x20U; - pkt.header.id = buf.vpkt.streamid; - if (pkt.header.seq) { + dsrp.tag = 0x20U; + if (dsrp.header.seq) { // printf("DEBUG: ProcessGateway: unexpected pkt.header.seq %d, resetting to 0\n", pkt.header.seq); - pkt.header.seq = 0; + dsrp.header.seq = 0; } - memcpy(pkt.header.flag, buf.vpkt.hdr.flag, 41); - int ret = SendTo(msock, pkt.title, 49, MMDVM_IP, MMDVM_IN_PORT); + memcpy(dsrp.header.flag, dstr.vpkt.hdr.flag, 41); + int ret = SendTo(msock, dsrp.title, 49, MMDVM_IP, MMDVM_IN_PORT); if (ret != 49) { printf("ERROR: ProcessGateway: Could not write Header mmdvm packet\n"); return true; } - printf("INFO: ProcessGateway: sent header to port %u pkt = '%s'\n", MMDVM_IN_PORT, std::string((char *)pkt.header.r2, 36).c_str()); + if (log_qso) + printf("Sent DSRP to %u, streamid=%04x ur=%.8s r1=%.8s r2=%.8s my=%.8s/%.4s\n", MMDVM_IN_PORT, ntohs(dsrp.header.id), + dsrp.header.ur, dsrp.header.r1, dsrp.header.r2, dsrp.header.my, dsrp.header.nm); } } else @@ -277,53 +277,58 @@ bool CQnetRelay::ProcessMMDVM(const int len, const unsigned char *raw) { static short old_id = 0U; static short stream_id = 0U; - SDSRP mpkt; + SDSRP dsrp; if (len < 65) - ::memcpy(mpkt.title, raw, len); // transfer raw data to SDSRP struct + ::memcpy(dsrp.title, raw, len); // transfer raw data to SDSRP struct if (49==len || 21==len) { // grab the stream id if this is a header if (49 == len) { - stream_id = mpkt.header.id; + stream_id = dsrp.header.id; if (old_id == stream_id) return false; old_id = stream_id; } - SDSTR gpkt; // destination + SDSTR dstr; // destination // sets most of the params - ::memcpy(gpkt.pkt_id, "DSTR", 4); - gpkt.counter = COUNTER++; - gpkt.flag[0] = 0x73; - gpkt.flag[1] = 0x12; - gpkt.flag[2] = 0x0; - gpkt.vpkt.icm_id = 0x20; - gpkt.vpkt.dst_rptr_id = 0x0; - gpkt.vpkt.snd_rptr_id = 0x1; - gpkt.vpkt.snd_term_id = ('B'==RPTR_MOD) ? 0x1 : (('C'==RPTR_MOD) ? 0x2 : 0x3); - gpkt.vpkt.streamid = stream_id; + ::memcpy(dstr.pkt_id, "DSTR", 4); + dstr.counter = htons(COUNTER++); + dstr.flag[0] = 0x73; + dstr.flag[1] = 0x12; + dstr.flag[2] = 0x0; + dstr.vpkt.icm_id = 0x20; + dstr.vpkt.dst_rptr_id = 0x0; + dstr.vpkt.snd_rptr_id = 0x1; + dstr.vpkt.snd_term_id = ('B'==RPTR_MOD) ? 0x1 : (('C'==RPTR_MOD) ? 0x2 : 0x3); + dstr.vpkt.streamid = stream_id; if (49 == len) { // header - gpkt.remaining = 0x30; - gpkt.vpkt.ctrl = 0x80; - ::memcpy(gpkt.vpkt.hdr.flag, mpkt.header.flag, 41); - int ret = SendTo(msock, gpkt.pkt_id, 58, G2_INTERNAL_IP, G2_IN_PORT); + dstr.remaining = 0x30; + dstr.vpkt.ctrl = 0x80; + memcpy(dstr.vpkt.hdr.flag, dsrp.header.flag, 41); + int ret = SendTo(msock, dstr.pkt_id, 58, G2_INTERNAL_IP, G2_IN_PORT); if (ret != 58) { printf("ERROR: ProcessMMDVM: Could not write gateway header packet\n"); return true; } - printf("INFO: ProcessMMDVM: sent header to port %u pkt = '%s'\n", G2_IN_PORT, std::string((char *)gpkt.vpkt.hdr.r2, 36).c_str()); + if (log_qso) + printf("Sent DSTR to %u, streamid=%04x ur=%.8s r1=%.8s r2=%.8s my=%.8s/%.4s\n", G2_IN_PORT, ntohs(dstr.vpkt.streamid), + dstr.vpkt.hdr.ur, dstr.vpkt.hdr.r1, dstr.vpkt.hdr.r2, dstr.vpkt.hdr.my, dstr.vpkt.hdr.nm); } else if (21 == len) { // ambe - gpkt.remaining = 0x16; - gpkt.vpkt.ctrl = mpkt.header.seq; - ::memcpy(gpkt.vpkt.vasd.voice, mpkt.voice.ambe, 12); - int ret = SendTo(msock, gpkt.pkt_id, 29, G2_INTERNAL_IP, G2_IN_PORT); + dstr.remaining = 0x16; + dstr.vpkt.ctrl = dsrp.header.seq; + memcpy(dstr.vpkt.vasd.voice, dsrp.voice.ambe, 12); + int ret = SendTo(msock, dstr.pkt_id, 29, G2_INTERNAL_IP, G2_IN_PORT); + if (log_qso && dstr.vpkt.ctrl&0x40) + printf("Sent dstr end of streamid=%04x\n", ntohs(dstr.vpkt.streamid)); + if (ret != 29) { printf("ERROR: ProcessMMDVM: Could not write gateway voice packet\n"); return true; } } - } else if (len < 65 && mpkt.tag == 0xAU) { + } else if (len < 65 && dsrp.tag == 0xAU) { // printf("MMDVM Poll: '%s'\n", (char *)mpkt.poll_msg); } else printf("DEBUG: ProcessMMDVM: unusual packet len=%d\n", len); @@ -469,11 +474,7 @@ bool CQnetRelay::ReadConfig(const char *cfgFile) } else return true; - GetValue(cfg, "timing.play.delay", DELAY_BETWEEN, 9, 25, 19); - - GetValue(cfg, "timing.play.wait", DELAY_BEFORE, 1, 10, 2); - - GetValue(cfg, std::string(mmdvm_path+".packet_wait").c_str(), WAIT_FOR_PACKETS, 6, 100, 25); + GetValue(cfg, "log.qso", log_qso, false); return false; } @@ -495,8 +496,8 @@ int main(int argc, const char **argv) } if ('-' == argv[1][0]) { - printf("\nMMDVM Modem Version #%s Copyright (C) 2018 by Thomas A. Early N7TAE\n", MMDVM_VERSION); - printf("MMDVM Modem comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n"); + printf("\nQnetRelay Version #%s Copyright (C) 2018 by Thomas A. Early N7TAE\n", RELAY_VERSION); + printf("QnetRelay comes with ABSOLUTELY NO WARRANTY; see the LICENSE for details.\n"); printf("This is free software, and you are welcome to distribute it\nunder certain conditions that are discussed in the LICENSE file.\n\n"); return 0; } diff --git a/QnetRelay.h b/QnetRelay.h index e890dac..ea3e614 100644 --- a/QnetRelay.h +++ b/QnetRelay.h @@ -62,7 +62,7 @@ private: char OWNER[CALL_SIZE + 1]; std::string MMDVM_IP, G2_INTERNAL_IP; unsigned short MMDVM_IN_PORT, MMDVM_OUT_PORT, G2_IN_PORT, G2_OUT_PORT; - int WAIT_FOR_PACKETS, DELAY_BEFORE, DELAY_BETWEEN; + bool log_qso; // parameters int msock, gsock; diff --git a/QnetTypeDefs.h b/QnetTypeDefs.h index 0e9b392..b6714fc 100644 --- a/QnetTypeDefs.h +++ b/QnetTypeDefs.h @@ -108,7 +108,7 @@ typedef struct dsrp_tag { // offset size // 0x01 Dstar Relay Unavailable unsigned char r2[8]; // Repeater 2 11 unsigned char r1[8]; // Repeater 1 19 - unsigned char yr[8]; // Your Call 27 + unsigned char ur[8]; // Your Call 27 unsigned char my[8]; // My Call 35 unsigned char nm[4]; // Name 43 unsigned short pfcs; // checksum 47 49 diff --git a/versions.h b/versions.h index 1eee3ce..2c7bcf5 100644 --- a/versions.h +++ b/versions.h @@ -2,6 +2,7 @@ #define IRCDDB_VERSION "QnetGateway-7.0.0" #define LINK_VERSION "QnetLink-6.0.0" #define DVAP_VERSION "QnetDVAP-5.1.1" +#define RELAY_VERSION "QnetRelay-0.2.0" #define DVRPTR_VERSION "QnetDVRPTR-5.1.0" #define MMDVM_VERSION "QnetGateway-MMDVM-0.1.0" #define ICOM_VERSION IRCDDB_VERSION