Unix packet read/write

pull/14/head
Tom Early 6 years ago
parent 2a447d89f6
commit f4b88b21f0

@ -49,25 +49,25 @@ dvrptr : qndvrptr
itap : qnitap itap : qnitap
modem : qnmodem modem : qnmodem
qngateway : QnetGateway.o aprs.o UnixDgramSocket.o TCPReaderWriterClient.o QnetConfigure.o QnetDB.o CacheManager.o DStarDecode.o $(IRCOBJS) qngateway : QnetGateway.o aprs.o UnixDgramSocket.o UnixPacketSock.o TCPReaderWriterClient.o QnetConfigure.o QnetDB.o CacheManager.o DStarDecode.o $(IRCOBJS)
g++ $(CPPFLAGS) -o $@ $^ $(LDFLAGS) -l sqlite3 -pthread g++ $(CPPFLAGS) -o $@ $^ $(LDFLAGS) -l sqlite3 -pthread
qnlink : QnetLink.o DPlusAuthenticator.o TCPReaderWriterClient.o UnixDgramSocket.o QnetConfigure.o QnetDB.o qnlink : QnetLink.o DPlusAuthenticator.o TCPReaderWriterClient.o UnixPacketSock.o QnetConfigure.o QnetDB.o
g++ $(CPPFLAGS) -o $@ $^ $(LDFLAGS) -l sqlite3 -pthread g++ $(CPPFLAGS) -o $@ $^ $(LDFLAGS) -l sqlite3 -pthread
qnrelay : QnetRelay.o UnixDgramSocket.o QnetConfigure.o qnrelay : QnetRelay.o UnixPacketSock.o QnetConfigure.o
g++ $(CPPFLAGS) -o $@ $^ $(LDFLAGS) g++ $(CPPFLAGS) -o $@ $^ $(LDFLAGS)
qnitap : QnetITAP.o UnixDgramSocket.o QnetConfigure.o qnitap : QnetITAP.o UnixPacketSock.o QnetConfigure.o
g++ $(CPPFLAGS) -o $@ $^ $(LDFLAGS) g++ $(CPPFLAGS) -o $@ $^ $(LDFLAGS)
qnmodem : QnetModem.o UnixDgramSocket.o QnetConfigure.o qnmodem : QnetModem.o UnixPacketSock.o QnetConfigure.o
g++ $(CPPFLAGS) -o $@ $^ $(LDFLAGS) g++ $(CPPFLAGS) -o $@ $^ $(LDFLAGS)
qndvap : QnetDVAP.o DVAPDongle.o UnixDgramSocket.o QnetConfigure.o DStarDecode.o qndvap : QnetDVAP.o DVAPDongle.o UnixPacketSock.o QnetConfigure.o DStarDecode.o
g++ $(CPPFLAGS) -o $@ $^ $(LDFLAGS) -pthread g++ $(CPPFLAGS) -o $@ $^ $(LDFLAGS) -pthread
qndvrptr : QnetDVRPTR.o UnixDgramSocket.o QnetConfigure.o DStarDecode.o qndvrptr : QnetDVRPTR.o UnixPacketSock.o QnetConfigure.o DStarDecode.o
g++ $(CPPFLAGS) -o $@ $^ $(LDFLAGS) g++ $(CPPFLAGS) -o $@ $^ $(LDFLAGS)
qnremote : QnetRemote.o UnixDgramSocket.o QnetConfigure.o qnremote : QnetRemote.o UnixDgramSocket.o QnetConfigure.o

@ -47,11 +47,11 @@
#include "DVAPDongle.h" #include "DVAPDongle.h"
#include "QnetTypeDefs.h" #include "QnetTypeDefs.h"
#include "Random.h" #include "Random.h"
#include "UnixDgramSocket.h" #include "UnixPacketSock.h"
#include "QnetConfigure.h" #include "QnetConfigure.h"
#include "Timer.h" #include "Timer.h"
#include "DStarDecode.h" #include "DStarDecode.h"
#define DVAP_VERSION "QnetDVAP-6.1.2" #define DVAP_VERSION "QnetDVAP-523"
#define CALL_SIZE 8 #define CALL_SIZE 8
#define IP_SIZE 15 #define IP_SIZE 15
@ -65,9 +65,8 @@ typedef struct dvap_ack_arg_tag {
static int assigned_module; static int assigned_module;
// unix sockets // unix sockets
static std::string modem2gate, gate2modem; static std::string togate;
static CUnixDgramReader Gate2Modem; static CUnixPacketClient ToGate;
static CUnixDgramWriter Modem2Gate;
/* Default configuration data */ /* Default configuration data */
static std::string RPTR; static std::string RPTR;
static std::string OWNER; static std::string OWNER;
@ -199,8 +198,7 @@ static bool ReadConfig(const char *cfgFile)
} }
} }
RPTR_MOD = 'A' + assigned_module; RPTR_MOD = 'A' + assigned_module;
cfg.GetValue("gateway_gate2modem"+std::string(1, 'a'+assigned_module), estr, gate2modem, 1, FILENAME_MAX); cfg.GetValue("gateway_tomodem"+std::string(1, 'a'+assigned_module), estr, togate, 1, FILENAME_MAX);
cfg.GetValue("gateway_modem2gate", estr, modem2gate, 1, FILENAME_MAX);
if (cfg.KeyExists(dvap_path+"_callsign")) { if (cfg.KeyExists(dvap_path+"_callsign")) {
if (cfg.GetValue(dvap_path+"_callsign", type, RPTR, 3, 6)) if (cfg.GetValue(dvap_path+"_callsign", type, RPTR, 3, 6))
return true; return true;
@ -254,8 +252,7 @@ static bool ReadConfig(const char *cfgFile)
static int open_sock() static int open_sock()
{ {
Modem2Gate.SetUp(modem2gate.c_str()); if (ToGate.Open(togate.c_str()))
if (Gate2Modem.Open(gate2modem.c_str()))
return 1; return 1;
return 0; return 0;
} }
@ -283,12 +280,12 @@ static void ReadFromGateway()
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = MODULE_PACKET_WAIT; tv.tv_usec = MODULE_PACKET_WAIT;
FD_ZERO (&readfd); FD_ZERO (&readfd);
int fd = Gate2Modem.GetFD(); int fd = ToGate.GetFD();
FD_SET (fd, &readfd); FD_SET (fd, &readfd);
select(fd + 1, &readfd, NULL, NULL, &tv); select(fd + 1, &readfd, NULL, NULL, &tv);
if (FD_ISSET(fd, &readfd)) { if (FD_ISSET(fd, &readfd)) {
len = Gate2Modem.Read(dsvt.title, 56); len = ToGate.Read(dsvt.title, 56);
if (len == 56) { if (len == 56) {
if (busy20000) { if (busy20000) {
FD_CLR (fd, &readfd); FD_CLR (fd, &readfd);
@ -790,7 +787,7 @@ static void ReadDVAPThread()
dsvt.ctrl = 0x80; dsvt.ctrl = 0x80;
sequence = 0; sequence = 0;
calcPFCS((unsigned char *)&(dsvt.hdr), dsvt.hdr.pfcs); calcPFCS((unsigned char *)&(dsvt.hdr), dsvt.hdr.pfcs);
Modem2Gate.Write(dsvt.title, 56); ToGate.Write(dsvt.title, 56);
// local RF user keying up, start timer // local RF user keying up, start timer
dvap_busy = true; dvap_busy = true;
@ -810,7 +807,7 @@ static void ReadDVAPThread()
if (the_end) if (the_end)
dsvt.ctrl = sequence | 0x40; dsvt.ctrl = sequence | 0x40;
memcpy(&dsvt.vasd, &dr.frame.vad.voice, 12); memcpy(&dsvt.vasd, &dr.frame.vad.voice, 12);
Modem2Gate.Write(dsvt.title, 27); ToGate.Write(dsvt.title, 27);
int ber_data[3]; int ber_data[3];
int ber_errs = decode.Decode(dsvt.vasd.voice, ber_data); int ber_errs = decode.Decode(dsvt.vasd.voice, ber_data);
@ -975,7 +972,7 @@ int main(int argc, const char **argv)
} }
readthread.get(); readthread.get();
Gate2Modem.Close(); ToGate.Close();
printf("QnetDVAP exiting\n"); printf("QnetDVAP exiting\n");
return 0; return 0;
} }

@ -24,12 +24,12 @@
#include <string> #include <string>
#include "Random.h" #include "Random.h"
#include "UnixDgramSocket.h" #include "UnixPacketSock.h"
#include "QnetConfigure.h" #include "QnetConfigure.h"
#include "QnetTypeDefs.h" #include "QnetTypeDefs.h"
#include "DStarDecode.h" #include "DStarDecode.h"
#define DVRPTR_VERSION "QnetDVRPTR-6.0.6" #define DVRPTR_VERSION "QnetDVRPTR-523"
#define BAUD B115200 #define BAUD B115200
#define CALL_SIZE 8 #define CALL_SIZE 8
@ -77,9 +77,8 @@ static unsigned char Modem_STATUS[6]= {0xD0,0x01,0x00,0x10,0x00,0x00}; // Status
static unsigned char Modem_SERIAL[6]= {0xD0,0x01,0x00,0x12,0x00,0x00}; static unsigned char Modem_SERIAL[6]= {0xD0,0x01,0x00,0x12,0x00,0x00};
static int assigned_module; static int assigned_module;
static std::string gate2modem, modem2gate; static std::string togate;
CUnixDgramWriter Modem2Gate; CUnixPacketClient ToGate;
CUnixDgramReader Gate2Modem;
static std::string DVRPTR_SERIAL; static std::string DVRPTR_SERIAL;
static char DVCALL[CALL_SIZE + 1]; static char DVCALL[CALL_SIZE + 1];
@ -1387,8 +1386,7 @@ static bool ReadConfig(const char *cfgFile)
} }
} }
DVRPTR_MOD = 'A' + assigned_module; DVRPTR_MOD = 'A' + assigned_module;
cfg.GetValue(std::string("gateway_gate2modem")+std::string(1, 'a'+assigned_module), estr, gate2modem, 1, FILENAME_MAX); cfg.GetValue(std::string("gateway_tomodem")+std::string(1, 'a'+assigned_module), estr, togate, 1, FILENAME_MAX);
cfg.GetValue("gateway_modem2gate", estr, modem2gate, 1, FILENAME_MAX);
std::string call; std::string call;
if (cfg.GetValue("ircddb_login", type, call, 3, 6)) if (cfg.GetValue("ircddb_login", type, call, 3, 6))
@ -1691,7 +1689,7 @@ static void readFrom20000()
unsigned char ctrl_in = 0x80; unsigned char ctrl_in = 0x80;
bool written_to_q = false; bool written_to_q = false;
int fd = Gate2Modem.GetFD(); int fd = ToGate.GetFD();
while (true) { while (true) {
written_to_q = false; written_to_q = false;
@ -1701,7 +1699,7 @@ static void readFrom20000()
FD_SET (fd, &readfd); FD_SET (fd, &readfd);
select(fd + 1, &readfd, NULL, NULL, &tv); select(fd + 1, &readfd, NULL, NULL, &tv);
if (FD_ISSET(fd, &readfd)) { if (FD_ISSET(fd, &readfd)) {
len = Gate2Modem.Read(recv_buf.title, 56); len = ToGate.Read(recv_buf.title, 56);
if (len == 56) { if (len == 56) {
if (busy20000) { if (busy20000) {
FD_CLR (fd, &readfd); FD_CLR (fd, &readfd);
@ -2086,8 +2084,7 @@ int main(int argc, const char **argv)
strcpy(DVCALL_and_MOD, DVCALL); strcpy(DVCALL_and_MOD, DVCALL);
DVCALL_and_MOD[7] = DVRPTR_MOD; DVCALL_and_MOD[7] = DVRPTR_MOD;
Modem2Gate.SetUp(modem2gate.c_str()); if (ToGate.Open(togate.c_str()))
if (Gate2Modem.Open(gate2modem.c_str()))
return 1; return 1;
if (RX_Inverse == true) { if (RX_Inverse == true) {
@ -2353,7 +2350,7 @@ int main(int argc, const char **argv)
if (ok) { if (ok) {
if (IS_ENABLED) { if (IS_ENABLED) {
Modem2Gate.Write(Send_Network_Header.title, 56); ToGate.Write(Send_Network_Header.title, 56);
} }
} }
@ -2413,7 +2410,7 @@ int main(int argc, const char **argv)
memcpy(Send_Network_Audio.vasd.voice , puffer + 8, 12); memcpy(Send_Network_Audio.vasd.voice , puffer + 8, 12);
if (IS_ENABLED) { if (IS_ENABLED) {
Modem2Gate.Write(Send_Network_Audio.title, 27); ToGate.Write(Send_Network_Audio.title, 27);
ber_errs = decode.Decode(Send_Network_Audio.vasd.voice, ber_data); ber_errs = decode.Decode(Send_Network_Audio.vasd.voice, ber_data);
num_bit_errors += ber_errs; num_bit_errors += ber_errs;
num_dv_frames++; num_dv_frames++;
@ -2537,7 +2534,7 @@ int main(int argc, const char **argv)
if (ok) { if (ok) {
if (IS_ENABLED) { if (IS_ENABLED) {
Modem2Gate.Write(Send_Network_Audio.title, 27); ToGate.Write(Send_Network_Audio.title, 27);
} }
} }
@ -2554,7 +2551,7 @@ int main(int argc, const char **argv)
} }
} }
Gate2Modem.Close(); ToGate.Close();
printf("dvrptr exiting...\n"); printf("dvrptr exiting...\n");
return 0; return 0;

@ -54,7 +54,7 @@
#define CFG_DIR "/usr/local/etc" #define CFG_DIR "/usr/local/etc"
#endif #endif
const std::string GW_VERSION("QnetGateway-518"); const std::string GW_VERSION("QnetGateway-523");
static std::atomic<bool> keep_running(true); static std::atomic<bool> keep_running(true);
@ -269,12 +269,11 @@ bool CQnetGateway::ReadConfig(char *cfgFile)
cfg.GetValue(path+"ipv6_port", estr, g2_ipv6_external.port, 1024, 65535); cfg.GetValue(path+"ipv6_port", estr, g2_ipv6_external.port, 1024, 65535);
cfg.GetValue(path+"header_regen", estr, GATEWAY_HEADER_REGEN); cfg.GetValue(path+"header_regen", estr, GATEWAY_HEADER_REGEN);
cfg.GetValue(path+"send_qrgs_maps", estr, GATEWAY_SEND_QRGS_MAP); cfg.GetValue(path+"send_qrgs_maps", estr, GATEWAY_SEND_QRGS_MAP);
cfg.GetValue(path+"gate2link", estr, gate2link, 1, FILENAME_MAX); cfg.GetValue(path+"tolink", estr, tolink, 1, FILENAME_MAX);
cfg.GetValue(path+"link2gate", estr, link2gate, 1, FILENAME_MAX); cfg.GetValue(path+"fromremote", estr, fromremote, 1, FILENAME_MAX);
cfg.GetValue(path+"modem2gate", estr, modem2gate, 1, FILENAME_MAX);
for (int m=0; m<3; m++) { for (int m=0; m<3; m++) {
if (Rptr.mod[m].defined) { if (Rptr.mod[m].defined) {
cfg.GetValue(path+"gate2modem"+std::string(1, 'a'+m), estr, gate2modem[m], 1, FILENAME_MAX); cfg.GetValue(path+"tomodem"+std::string(1, 'a'+m), estr, tomodem[m], 1, FILENAME_MAX);
cfg.GetValue(path+"latitude", estr, Rptr.mod[m].latitude, -90.0, 90.0); cfg.GetValue(path+"latitude", estr, Rptr.mod[m].latitude, -90.0, 90.0);
cfg.GetValue(path+"longitude", estr, Rptr.mod[m].longitude, -180.0, 180.0); cfg.GetValue(path+"longitude", estr, Rptr.mod[m].longitude, -180.0, 180.0);
cfg.GetValue(path+"desc1", estr, Rptr.mod[m].desc1, 0, 20); cfg.GetValue(path+"desc1", estr, Rptr.mod[m].desc1, 0, 20);
@ -584,7 +583,7 @@ void CQnetGateway::ProcessTimeouts()
end_of_audio.ctrl = toRptr[i].sequence | 0x40; end_of_audio.ctrl = toRptr[i].sequence | 0x40;
for (int j=0; j<2; j++) for (int j=0; j<2; j++)
Gate2Modem[i].Write(end_of_audio.title, 27); ToModem[i].Write(end_of_audio.title, 27);
toRptr[i].streamid = 0; toRptr[i].streamid = 0;
@ -998,7 +997,7 @@ void CQnetGateway::ProcessG2(const ssize_t g2buflen, SDSVT &g2buf, const int sou
if (source_sock >= 0) if (source_sock >= 0)
printf("IP=[%s]:%u\n", fromDstar.GetAddress(), fromDstar.GetPort()); printf("IP=[%s]:%u\n", fromDstar.GetAddress(), fromDstar.GetPort());
else else
printf("UnixSock=%s\n", link2gate.c_str()); printf("UnixSock=%s\n", tolink.c_str());
} }
lhcallsign[i].assign((const char *)g2buf.hdr.mycall, 8); lhcallsign[i].assign((const char *)g2buf.hdr.mycall, 8);
if (showLastHeard && memcmp(g2buf.hdr.sfx, "RPTR", 4) && std::regex_match(lhcallsign[i].c_str(), preg)) { if (showLastHeard && memcmp(g2buf.hdr.sfx, "RPTR", 4) && std::regex_match(lhcallsign[i].c_str(), preg)) {
@ -1011,7 +1010,7 @@ void CQnetGateway::ProcessG2(const ssize_t g2buflen, SDSVT &g2buf, const int sou
qnDB.UpdateLH(lhcallsign[i].c_str(), lhsfx[i].c_str(), 'A'+i, reflector.c_str()); qnDB.UpdateLH(lhcallsign[i].c_str(), lhsfx[i].c_str(), 'A'+i, reflector.c_str());
} }
Gate2Modem[i].Write(g2buf.title, 56); ToModem[i].Write(g2buf.title, 56);
nextctrl[i] = 0U; nextctrl[i] = 0U;
/* save the header */ /* save the header */
@ -1085,7 +1084,7 @@ void CQnetGateway::ProcessG2(const ssize_t g2buflen, SDSVT &g2buf, const int sou
const unsigned char sync[3] = { 0x55U, 0x2DU, 0x16U }; const unsigned char sync[3] = { 0x55U, 0x2DU, 0x16U };
memcpy(dsvt.vasd.voice, sync, 3U); memcpy(dsvt.vasd.voice, sync, 3U);
} }
Gate2Modem[i].Write(dsvt.title, 27); ToModem[i].Write(dsvt.title, 27);
} }
} else { } else {
if (LOG_DEBUG) if (LOG_DEBUG)
@ -1102,7 +1101,7 @@ void CQnetGateway::ProcessG2(const ssize_t g2buflen, SDSVT &g2buf, const int sou
g2buf.ctrl = nextctrl[i]; g2buf.ctrl = nextctrl[i];
nextctrl[i] = (nextctrl[i] + 1U) % 21U; nextctrl[i] = (nextctrl[i] + 1U) % 21U;
} }
Gate2Modem[i].Write(g2buf.title, 27); ToModem[i].Write(g2buf.title, 27);
if (source_sock >= 0 && showLastHeard) { if (source_sock >= 0 && showLastHeard) {
std::string smartgroup; std::string smartgroup;
if(ProcessG2Msg(g2buf.vasd.text, i, smartgroup)) { if(ProcessG2Msg(g2buf.vasd.text, i, smartgroup)) {
@ -1161,10 +1160,10 @@ void CQnetGateway::ProcessG2(const ssize_t g2buflen, SDSVT &g2buf, const int sou
printf("Re-generating header for streamID=%04x\n", ntohs(g2buf.streamid)); printf("Re-generating header for streamID=%04x\n", ntohs(g2buf.streamid));
/* re-generate/send the header */ /* re-generate/send the header */
Gate2Modem[i].Write(toRptr[i].saved_hdr.title, 56); ToModem[i].Write(toRptr[i].saved_hdr.title, 56);
/* send this audio packet to repeater */ /* send this audio packet to repeater */
Gate2Modem[i].Write(g2buf.title, 27); ToModem[i].Write(g2buf.title, 27);
/* make sure that any more audio arriving will be accepted */ /* make sure that any more audio arriving will be accepted */
toRptr[i].streamid = g2buf.streamid; toRptr[i].streamid = g2buf.streamid;
@ -1185,14 +1184,10 @@ void CQnetGateway::ProcessG2(const ssize_t g2buflen, SDSVT &g2buf, const int sou
} }
} }
void CQnetGateway::ProcessModem() void CQnetGateway::ProcessModem(const ssize_t recvlen, SDSVT &dsvt)
{ {
char tempfile[FILENAME_MAX]; char tempfile[FILENAME_MAX];
SDSVT dsvt;
int recvlen = Modem2Gate.Read(dsvt.title, 56);
if (0 == memcmp(dsvt.title, "DSVT", 4)) { if (0 == memcmp(dsvt.title, "DSVT", 4)) {
if ( (recvlen==56 || recvlen==27) && dsvt.id==0x20U && (dsvt.config==0x10U || dsvt.config==0x20U) ) { if ( (recvlen==56 || recvlen==27) && dsvt.id==0x20U && (dsvt.config==0x10U || dsvt.config==0x20U) ) {
if (recvlen == 56) { if (recvlen == 56) {
@ -1290,7 +1285,7 @@ void CQnetGateway::ProcessModem()
bool mycall_valid = std::regex_match(call.c_str(), preg); bool mycall_valid = std::regex_match(call.c_str(), preg);
if (mycall_valid) if (mycall_valid)
Gate2Link.Write(dsvt.title, recvlen); ToLink.Write(dsvt.title, recvlen);
else else
printf("MYCALL [%s] failed IRC expression validation\n", call.c_str()); printf("MYCALL [%s] failed IRC expression validation\n", call.c_str());
@ -1441,7 +1436,7 @@ void CQnetGateway::ProcessModem()
dsvt.hdr.rpt1[7] = 'G'; dsvt.hdr.rpt1[7] = 'G';
calcPFCS(dsvt.title, 56); calcPFCS(dsvt.title, 56);
Gate2Modem[i].Write(dsvt.title, 56); ToModem[i].Write(dsvt.title, 56);
/* This is the active streamid */ /* This is the active streamid */
toRptr[i].streamid = dsvt.streamid; toRptr[i].streamid = dsvt.streamid;
@ -1597,7 +1592,7 @@ void CQnetGateway::ProcessModem()
dsvt.hdr.rpt1[7] = 'G'; dsvt.hdr.rpt1[7] = 'G';
calcPFCS(dsvt.title, 56); calcPFCS(dsvt.title, 56);
Gate2Modem[i].Write(dsvt.title, 56); ToModem[i].Write(dsvt.title, 56);
/* This is the active streamid */ /* This is the active streamid */
toRptr[i].streamid = dsvt.streamid; toRptr[i].streamid = dsvt.streamid;
@ -1727,7 +1722,7 @@ void CQnetGateway::ProcessModem()
ProcessSlowData(dsvt.vasd.text, dsvt.streamid); ProcessSlowData(dsvt.vasd.text, dsvt.streamid);
/* send data to qnlink */ /* send data to qnlink */
Gate2Link.Write(dsvt.title, 27); ToLink.Write(dsvt.title, 27);
/* aprs processing */ /* aprs processing */
if (APRS_ENABLE) if (APRS_ENABLE)
@ -1787,7 +1782,7 @@ void CQnetGateway::ProcessModem()
break; break;
} }
else if (toRptr[i].streamid == dsvt.streamid) { // or maybe this is cross-banding data else if (toRptr[i].streamid == dsvt.streamid) { // or maybe this is cross-banding data
Gate2Modem[i].Write(dsvt.title, 27); ToModem[i].Write(dsvt.title, 27);
/* timeit */ /* timeit */
time(&toRptr[i].last_time); time(&toRptr[i].last_time);
@ -1866,8 +1861,12 @@ void CQnetGateway::Process()
AddFDSet(max_nfds, g2_sock[0], &fdset); AddFDSet(max_nfds, g2_sock[0], &fdset);
if (g2_sock[1] >= 0) if (g2_sock[1] >= 0)
AddFDSet(max_nfds, g2_sock[1], &fdset); AddFDSet(max_nfds, g2_sock[1], &fdset);
AddFDSet(max_nfds, Link2Gate.GetFD(), &fdset); AddFDSet(max_nfds, ToLink.GetFD(), &fdset);
AddFDSet(max_nfds, Modem2Gate.GetFD(), &fdset); for (int i=0; i<3; i++) {
if (Rptr.mod[i].defined)
AddFDSet(max_nfds, ToModem[i].GetFD(), &fdset);
}
AddFDSet(max_nfds, FromRemote.GetFD(), &fdset);
struct timeval tv; struct timeval tv;
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 20000; // 20 ms tv.tv_usec = 20000; // 20 ms
@ -1889,10 +1888,18 @@ void CQnetGateway::Process()
} }
} }
// process packets from qnremote
if (keep_running && FD_ISSET(FromRemote.GetFD(), &fdset)) {
SDSVT dsvt;
const ssize_t len = FromRemote.Read(dsvt.title, 56);
ProcessModem(len, dsvt);
FD_CLR(FromRemote.GetFD(), &fdset);
}
// process packets from qnlink // process packets from qnlink
if (keep_running && FD_ISSET(Link2Gate.GetFD(), &fdset)) { if (keep_running && FD_ISSET(ToLink.GetFD(), &fdset)) {
SDSVT dsvt; SDSVT dsvt;
ssize_t g2buflen = Link2Gate.Read(dsvt.title, 56); ssize_t g2buflen = ToLink.Read(dsvt.title, 56);
if (16==g2buflen && 0==memcmp(dsvt.title, "LINK", 4)) { if (16==g2buflen && 0==memcmp(dsvt.title, "LINK", 4)) {
SLINKFAMILY fam; SLINKFAMILY fam;
memcpy(fam.title, dsvt.title, 16); memcpy(fam.title, dsvt.title, 16);
@ -1907,13 +1914,18 @@ void CQnetGateway::Process()
} else { } else {
ProcessG2(g2buflen, dsvt, -1); ProcessG2(g2buflen, dsvt, -1);
} }
FD_CLR(Link2Gate.GetFD(), &fdset); FD_CLR(ToLink.GetFD(), &fdset);
} }
// process packets coming from local repeater module(s) // process packets coming from local repeater module(s)
if (keep_running && FD_ISSET(Modem2Gate.GetFD(), &fdset)) { for (int i=0; i<3; i++) {
ProcessModem(); if (keep_running && FD_ISSET(ToModem[i].GetFD(), &fdset)) {
FD_CLR(Modem2Gate.GetFD(), &fdset); SDSVT dsvt;
const ssize_t len = ToModem[i].Read(dsvt.title, 56);
if (Rptr.mod[i].defined)
ProcessModem(len, dsvt);
FD_CLR(ToModem[i].GetFD(), &fdset);
}
} }
} }
@ -2174,7 +2186,7 @@ void CQnetGateway::PlayFileThread(SECHO &edata)
memcpy(dsvt.hdr.urcall, "CQCQCQ ", 8); memcpy(dsvt.hdr.urcall, "CQCQCQ ", 8);
calcPFCS(dsvt.title, 56); calcPFCS(dsvt.title, 56);
Gate2Modem[mod].Write(dsvt.title, 56); ToModem[mod].Write(dsvt.title, 56);
dsvt.config = 0x20U; dsvt.config = 0x20U;
@ -2235,7 +2247,7 @@ void CQnetGateway::PlayFileThread(SECHO &edata)
if (i+1 == ambeblocks) if (i+1 == ambeblocks)
dsvt.ctrl |= 0x40U; dsvt.ctrl |= 0x40U;
Gate2Modem[mod].Write(dsvt.title, 27); ToModem[mod].Write(dsvt.title, 27);
std::this_thread::sleep_for(std::chrono::milliseconds(TIMING_PLAY_DELAY)); std::this_thread::sleep_for(std::chrono::milliseconds(TIMING_PLAY_DELAY));
} }
@ -2429,16 +2441,15 @@ bool CQnetGateway::Init(char *cfgfile)
} }
} }
// Open unix sockets between qngateway and qnlink // Open unix sockets between qngateway and qnremote
Gate2Link.SetUp(gate2link.c_str()); if (ToLink.Open(tolink.c_str()))
if (Link2Gate.Open(link2gate.c_str()))
return true; return true;
if (Modem2Gate.Open(modem2gate.c_str())) if (FromRemote.Open(fromremote.c_str()))
return true; return true;
for (i=0; i<3; i++) { for (i=0; i<3; i++) {
if (Rptr.mod[i].defined) { // open unix sockets between qngateway and each defined modem if (Rptr.mod[i].defined) { // open unix sockets between qngateway and each defined modem
Gate2Modem[i].SetUp(gate2modem[i].c_str()); ToModem[i].Open(tomodem[i].c_str());
} }
// recording for echotest on local repeater modules // recording for echotest on local repeater modules
recd[i].last_time = 0; recd[i].last_time = 0;
@ -2500,8 +2511,12 @@ CQnetGateway::CQnetGateway()
CQnetGateway::~CQnetGateway() CQnetGateway::~CQnetGateway()
{ {
Link2Gate.Close(); ToLink.Close();
Modem2Gate.Close(); FromRemote.Close();
for (int i=0; i<3; i++) {
if (Rptr.mod[i].defined)
ToModem[i].Close();
}
if (APRS_ENABLE) { if (APRS_ENABLE) {
if (aprs->aprs_sock.GetFD() != -1) { if (aprs->aprs_sock.GetFD() != -1) {

@ -17,10 +17,13 @@
*/ */
#include <set> #include <set>
#include <regex>
#include "IRCDDB.h"
#include "QnetTypeDefs.h" #include "QnetTypeDefs.h"
#include "SEcho.h" #include "SEcho.h"
#include "UnixDgramSocket.h" #include "UnixDgramSocket.h"
#include "UnixPacketSock.h"
#include "aprs.h" #include "aprs.h"
#include "SockAddress.h" #include "SockAddress.h"
#include "QnetDB.h" #include "QnetDB.h"
@ -97,10 +100,10 @@ private:
SPORTIP g2_external, g2_ipv6_external, ircddb[2]; SPORTIP g2_external, g2_ipv6_external, ircddb[2];
CUnixDgramReader Link2Gate, Modem2Gate; CUnixDgramReader FromRemote;
CUnixDgramWriter Gate2Link, Gate2Modem[3]; CUnixPacketServer ToLink, ToModem[3];
std::string gate2link, link2gate, gate2modem[3], modem2gate; std::string tolink, fromremote, tomodem[3];
std::string OWNER, owner, FILE_DTMF, FILE_ECHOTEST, IRCDDB_PASSWORD[2], FILE_QNVOICE_FILE, DASH_SHOW_ORDER; std::string OWNER, owner, FILE_DTMF, FILE_ECHOTEST, IRCDDB_PASSWORD[2], FILE_QNVOICE_FILE, DASH_SHOW_ORDER;
@ -175,7 +178,7 @@ private:
void ProcessSlowData(unsigned char *data, const unsigned short sid); void ProcessSlowData(unsigned char *data, const unsigned short sid);
bool ProcessG2Msg(const unsigned char *data, const int mod, std::string &smrtgrp); bool ProcessG2Msg(const unsigned char *data, const int mod, std::string &smrtgrp);
void ProcessG2(const ssize_t g2buflen, SDSVT &g2buf, const int sock_source); void ProcessG2(const ssize_t g2buflen, SDSVT &g2buf, const int sock_source);
void ProcessModem(); void ProcessModem(const ssize_t len, SDSVT &dsvt);
bool Flag_is_ok(unsigned char flag); bool Flag_is_ok(unsigned char flag);
void UnpackCallsigns(const std::string &str, std::set<std::string> &set, const std::string &delimiters = ","); void UnpackCallsigns(const std::string &str, std::set<std::string> &set, const std::string &delimiters = ",");
void PrintCallsigns(const std::string &key, const std::set<std::string> &set); void PrintCallsigns(const std::string &key, const std::set<std::string> &set);

@ -45,7 +45,7 @@
#include "QnetConfigure.h" #include "QnetConfigure.h"
#include "Timer.h" #include "Timer.h"
#define ITAP_VERSION "QnetITAP-518" #define ITAP_VERSION "QnetITAP-523"
std::atomic<bool> CQnetITAP::keep_running(true); std::atomic<bool> CQnetITAP::keep_running(true);
@ -67,8 +67,7 @@ bool CQnetITAP::Initialize(const char *cfgfile)
std::signal(SIGHUP, CQnetITAP::SignalCatch); std::signal(SIGHUP, CQnetITAP::SignalCatch);
std::signal(SIGINT, CQnetITAP::SignalCatch); std::signal(SIGINT, CQnetITAP::SignalCatch);
Modem2Gate.SetUp(modem2gate.c_str()); if (ToGate.Open(togate.c_str()))
if (Gate2Modem.Open(gate2modem.c_str()))
return true; return true;
return false; return false;
@ -214,7 +213,7 @@ void CQnetITAP::Run(const char *cfgfile)
if (serfd < 0) if (serfd < 0)
return; return;
int ug2m = Gate2Modem.GetFD(); int ug2m = ToGate.GetFD();
printf("gate2modem=%d, serial=%d\n", ug2m, serfd); printf("gate2modem=%d, serial=%d\n", ug2m, serfd);
keep_running = true; keep_running = true;
@ -334,7 +333,7 @@ void CQnetITAP::Run(const char *cfgfile)
} }
if (keep_running && FD_ISSET(ug2m, &readfds)) { if (keep_running && FD_ISSET(ug2m, &readfds)) {
ssize_t len = Gate2Modem.Read(buf, 100); ssize_t len = ToGate.Read(buf, 100);
if (len < 0) { if (len < 0) {
printf("ERROR: Run: recvfrom(gsock) returned error %d, %s\n", errno, strerror(errno)); printf("ERROR: Run: recvfrom(gsock) returned error %d, %s\n", errno, strerror(errno));
@ -384,7 +383,7 @@ void CQnetITAP::Run(const char *cfgfile)
} }
close(serfd); close(serfd);
Gate2Modem.Close(); ToGate.Close();
} }
int CQnetITAP::SendTo(const unsigned char *buf) int CQnetITAP::SendTo(const unsigned char *buf)
@ -517,7 +516,7 @@ bool CQnetITAP::ProcessITAP(const unsigned char *buf)
memcpy(dsvt.hdr.mycall, itap.header.my, 8); memcpy(dsvt.hdr.mycall, itap.header.my, 8);
memcpy(dsvt.hdr.sfx, itap.header.nm, 4); memcpy(dsvt.hdr.sfx, itap.header.nm, 4);
calcPFCS(dsvt.hdr.flag, dsvt.hdr.pfcs); calcPFCS(dsvt.hdr.flag, dsvt.hdr.pfcs);
if (56 != Modem2Gate.Write(dsvt.title, 56)) { if (ToGate.Write(dsvt.title, 56)) {
printf("ERROR: ProcessITAP: Could not write gateway header packet\n"); printf("ERROR: ProcessITAP: Could not write gateway header packet\n");
return true; return true;
} }
@ -526,7 +525,7 @@ bool CQnetITAP::ProcessITAP(const unsigned char *buf)
} else if (16 == len) { // ambe } else if (16 == len) { // ambe
dsvt.ctrl = itap.voice.sequence; dsvt.ctrl = itap.voice.sequence;
memcpy(dsvt.vasd.voice, itap.voice.ambe, 12); memcpy(dsvt.vasd.voice, itap.voice.ambe, 12);
if (27 != Modem2Gate.Write(dsvt.title, 27)) { if (ToGate.Write(dsvt.title, 27)) {
printf("ERROR: ProcessMMDVM: Could not write gateway voice packet\n"); printf("ERROR: ProcessMMDVM: Could not write gateway voice packet\n");
return true; return true;
} }
@ -609,8 +608,7 @@ bool CQnetITAP::ReadConfig(const char *cfgFile)
RPTR.resize(CALL_SIZE, ' '); RPTR.resize(CALL_SIZE, ' ');
} }
cfg.GetValue(std::string("gateway_gate2modem")+std::string(1, 'a'+assigned_module), estr, gate2modem, 1, FILENAME_MAX); cfg.GetValue(std::string("gateway_tomodem")+std::string(1, 'a'+assigned_module), estr, togate, 1, FILENAME_MAX);
cfg.GetValue("gateway_modem2gate", estr, modem2gate, 1, FILENAME_MAX);
cfg.GetValue("log_qso", estr, LOG_QSO); cfg.GetValue("log_qso", estr, LOG_QSO);
cfg.GetValue("log_debug", estr, LOG_DEBUG); cfg.GetValue("log_debug", estr, LOG_DEBUG);
return false; return false;

@ -25,7 +25,7 @@
#include <netinet/in.h> #include <netinet/in.h>
#include "Random.h" // for streamid generation #include "Random.h" // for streamid generation
#include "UnixDgramSocket.h" #include "UnixPacketSock.h"
#define CALL_SIZE 8 #define CALL_SIZE 8
#define IP_SIZE 15 #define IP_SIZE 15
@ -137,9 +137,8 @@ private:
CRandom random; CRandom random;
// unix sockets // unix sockets
std::string modem2gate, gate2modem; std::string togate;
CUnixDgramWriter Modem2Gate; CUnixPacketClient ToGate;
CUnixDgramReader Gate2Modem;
// Queue // Queue
std::queue<CFrame> queue; std::queue<CFrame> queue;

@ -54,7 +54,7 @@
#include "QnetLink.h" #include "QnetLink.h"
#include "Utilities.h" #include "Utilities.h"
#define LINK_VERSION "QnetLink-515" #define LINK_VERSION "QnetLink-523"
#ifndef BIN_DIR #ifndef BIN_DIR
#define BIN_DIR "/usr/local/bin" #define BIN_DIR "/usr/local/bin"
#endif #endif
@ -220,7 +220,7 @@ void CQnetLink::RptrAckThread(char *arg)
memcpy(dsvt.hdr.sfx, "RPTR", 4); memcpy(dsvt.hdr.sfx, "RPTR", 4);
calcPFCS(dsvt.title,56); calcPFCS(dsvt.title,56);
Link2Gate.Write(dsvt.title, 56); ToGate.Write(dsvt.title, 56);
//std::this_thread::sleep_for(std::chrono::milliseconds(delay_between)) //std::this_thread::sleep_for(std::chrono::milliseconds(delay_between))
dsvt.config = 0x20; dsvt.config = 0x20;
@ -283,7 +283,7 @@ void CQnetLink::RptrAckThread(char *arg)
dsvt.vasd.text[2] = 0xf5; dsvt.vasd.text[2] = 0xf5;
break; break;
} }
Link2Gate.Write(dsvt.title, 27); ToGate.Write(dsvt.title, 27);
if (i < 9) if (i < 9)
std::this_thread::sleep_for(std::chrono::milliseconds(delay_between)); std::this_thread::sleep_for(std::chrono::milliseconds(delay_between));
} }
@ -511,8 +511,7 @@ bool CQnetLink::ReadConfig(const char *cfgFile)
saved_max_dongles = max_dongles = (unsigned int)maxdongle; saved_max_dongles = max_dongles = (unsigned int)maxdongle;
key.assign("gateway_"); key.assign("gateway_");
cfg.GetValue(key+"gate2link", estr, gate2link, 1, FILENAME_MAX); cfg.GetValue(key+"tolink", estr, togate, 1, FILENAME_MAX);
cfg.GetValue(key+"link2gate", estr, link2gate, 1, FILENAME_MAX);
cfg.GetValue("log_qso", estr, qso_details); cfg.GetValue("log_qso", estr, qso_details);
cfg.GetValue("log_debug", estr, log_debug); cfg.GetValue("log_debug", estr, log_debug);
@ -605,15 +604,13 @@ bool CQnetLink::srv_open()
} }
/* create our gateway unix sockets */ /* create our gateway unix sockets */
Link2Gate.SetUp(link2gate.c_str()); if (ToGate.Open(togate.c_str())) {
if (Gate2Link.Open(gate2link.c_str())) {
close(dcs_g2_sock); close(dcs_g2_sock);
dcs_g2_sock = -1; dcs_g2_sock = -1;
close(xrf_g2_sock); close(xrf_g2_sock);
xrf_g2_sock = -1; xrf_g2_sock = -1;
close(ref_g2_sock); close(ref_g2_sock);
ref_g2_sock = -1; ref_g2_sock = -1;
Gate2Link.Close();
return false; return false;
} }
@ -644,7 +641,7 @@ void CQnetLink::srv_close()
printf("Closed rmt_dcs_port\n"); printf("Closed rmt_dcs_port\n");
} }
Gate2Link.Close(); ToGate.Close();
if (ref_g2_sock != -1) { if (ref_g2_sock != -1) {
close(ref_g2_sock); close(ref_g2_sock);
@ -867,10 +864,10 @@ void CQnetLink::Process()
max_nfds = ref_g2_sock; max_nfds = ref_g2_sock;
if (dcs_g2_sock > max_nfds) if (dcs_g2_sock > max_nfds)
max_nfds = dcs_g2_sock; max_nfds = dcs_g2_sock;
if (Gate2Link.GetFD() > max_nfds) if (ToGate.GetFD() > max_nfds)
max_nfds = Gate2Link.GetFD(); max_nfds = ToGate.GetFD();
printf("xrf=%d, dcs=%d, ref=%d, gateway=%d, MAX+1=%d\n", xrf_g2_sock, dcs_g2_sock, ref_g2_sock, Gate2Link.GetFD(), max_nfds + 1); printf("xrf=%d, dcs=%d, ref=%d, gateway=%d, MAX+1=%d\n", xrf_g2_sock, dcs_g2_sock, ref_g2_sock, ToGate.GetFD(), max_nfds + 1);
// initialize all request links // initialize all request links
bool first = true; bool first = true;
@ -1053,7 +1050,7 @@ void CQnetLink::Process()
FD_SET(xrf_g2_sock, &fdset); FD_SET(xrf_g2_sock, &fdset);
FD_SET(dcs_g2_sock, &fdset); FD_SET(dcs_g2_sock, &fdset);
FD_SET(ref_g2_sock, &fdset); FD_SET(ref_g2_sock, &fdset);
FD_SET(Gate2Link.GetFD(), &fdset); FD_SET(ToGate.GetFD(), &fdset);
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 20000; tv.tv_usec = 20000;
(void)select(max_nfds + 1, &fdset, 0, 0, &tv); (void)select(max_nfds + 1, &fdset, 0, 0, &tv);
@ -1355,7 +1352,7 @@ void CQnetLink::Process()
} }
/* relay data to our local G2 */ /* relay data to our local G2 */
Link2Gate.Write(dsvt.title, 56); ToGate.Write(dsvt.title, 56);
/* send data to donglers */ /* send data to donglers */
/* no changes here */ /* no changes here */
@ -1411,7 +1408,7 @@ void CQnetLink::Process()
calcPFCS(from_xrf_torptr_brd.title, 56); calcPFCS(from_xrf_torptr_brd.title, 56);
/* send the data to the local gateway/repeater */ /* send the data to the local gateway/repeater */
Link2Gate.Write(from_xrf_torptr_brd.title, 56); ToGate.Write(from_xrf_torptr_brd.title, 56);
/* save streamid for use with the audio packets that will arrive after this header */ /* save streamid for use with the audio packets that will arrive after this header */
@ -1507,7 +1504,7 @@ void CQnetLink::Process()
} }
/* relay data to our local G2 */ /* relay data to our local G2 */
Link2Gate.Write(dsvt.title, 27); ToGate.Write(dsvt.title, 27);
/* send data to donglers */ /* send data to donglers */
/* no changes here */ /* no changes here */
@ -1531,12 +1528,12 @@ void CQnetLink::Process()
if (brd_from_xrf.rptr_streamid[0] != 0x0) { if (brd_from_xrf.rptr_streamid[0] != 0x0) {
from_xrf_torptr_brd.streamid = brd_from_xrf.rptr_streamid[0]; from_xrf_torptr_brd.streamid = brd_from_xrf.rptr_streamid[0];
Link2Gate.Write(from_xrf_torptr_brd.title, 27); ToGate.Write(from_xrf_torptr_brd.title, 27);
} }
if (brd_from_xrf.rptr_streamid[1] != 0x0) { if (brd_from_xrf.rptr_streamid[1] != 0x0) {
from_xrf_torptr_brd.streamid = brd_from_xrf.rptr_streamid[1]; from_xrf_torptr_brd.streamid = brd_from_xrf.rptr_streamid[1];
Link2Gate.Write(from_xrf_torptr_brd.title, 27); ToGate.Write(from_xrf_torptr_brd.title, 27);
} }
if (dsvt.ctrl & 0x40) { if (dsvt.ctrl & 0x40) {
@ -2229,7 +2226,7 @@ void CQnetLink::Process()
} }
/* send the data to the local gateway/repeater */ /* send the data to the local gateway/repeater */
Link2Gate.Write(rdsvt.dsvt.title, 56); ToGate.Write(rdsvt.dsvt.title, 56);
/* send the data to the donglers */ /* send the data to the donglers */
for (auto pos = inbound_list.begin(); pos != inbound_list.end(); pos++) { for (auto pos = inbound_list.begin(); pos != inbound_list.end(); pos++) {
@ -2287,7 +2284,7 @@ void CQnetLink::Process()
} }
/* send the data to the local gateway/repeater */ /* send the data to the local gateway/repeater */
Link2Gate.Write(rdsvt.dsvt.title, 27); ToGate.Write(rdsvt.dsvt.title, 27);
/* send the data to the donglers */ /* send the data to the donglers */
for (pos = inbound_list.begin(); pos != inbound_list.end(); pos++) { for (pos = inbound_list.begin(); pos != inbound_list.end(); pos++) {
@ -2436,7 +2433,7 @@ void CQnetLink::Process()
/* send the header to the local gateway/repeater */ /* send the header to the local gateway/repeater */
for (int j=0; j<5; j++) for (int j=0; j<5; j++)
Link2Gate.Write(rdsvt.dsvt.title, 56); ToGate.Write(rdsvt.dsvt.title, 56);
/* send the data to the donglers */ /* send the data to the donglers */
for (auto pos = inbound_list.begin(); pos != inbound_list.end(); pos++) { for (auto pos = inbound_list.begin(); pos != inbound_list.end(); pos++) {
@ -2469,7 +2466,7 @@ void CQnetLink::Process()
memcpy(rdsvt.dsvt.vasd.voice, dcs_buf+46, 12); memcpy(rdsvt.dsvt.vasd.voice, dcs_buf+46, 12);
/* send the data to the local gateway/repeater */ /* send the data to the local gateway/repeater */
Link2Gate.Write(rdsvt.dsvt.title, 27); ToGate.Write(rdsvt.dsvt.title, 27);
/* send the data to the donglers */ /* send the data to the donglers */
for (auto pos = inbound_list.begin(); pos != inbound_list.end(); pos++) { for (auto pos = inbound_list.begin(); pos != inbound_list.end(); pos++) {
@ -2570,15 +2567,15 @@ void CQnetLink::Process()
FD_CLR (dcs_g2_sock,&fdset); FD_CLR (dcs_g2_sock,&fdset);
} }
if (keep_running && FD_ISSET(Gate2Link.GetFD(), &fdset)) { if (keep_running && FD_ISSET(ToGate.GetFD(), &fdset)) {
SDSVT dsvt; SDSVT dsvt;
int length = Gate2Link.Read(dsvt.title, 56); int length = ToGate.Read(dsvt.title, 56);
if ((length==56 || length==27) && 0==memcmp(dsvt.title,"DSVT", 4U) && dsvt.id==0x20U && (dsvt.config==0x10U || dsvt.config==0x20U)) { if ((length==56 || length==27) && 0==memcmp(dsvt.title,"DSVT", 4U) && dsvt.id==0x20U && (dsvt.config==0x10U || dsvt.config==0x20U)) {
if (length == 56) { if (length == 56) {
if (qso_details) if (qso_details)
printf("START from local g2: streamID=%04x, flags=%02x:%02x:%02x, my=%.8s/%.4s, ur=%.8s, rpt1=%.8s, rpt2=%.8s, %d bytes on %s\n", ntohs(dsvt.streamid), dsvt.hdr.flag[0], dsvt.hdr.flag[1], dsvt.hdr.flag[2], dsvt.hdr.mycall, dsvt.hdr.sfx, dsvt.hdr.urcall, dsvt.hdr.rpt1, dsvt.hdr.rpt2, length, gate2link.c_str()); printf("START from local g2: streamID=%04x, flags=%02x:%02x:%02x, my=%.8s/%.4s, ur=%.8s, rpt1=%.8s, rpt2=%.8s, %d bytes on %s\n", ntohs(dsvt.streamid), dsvt.hdr.flag[0], dsvt.hdr.flag[1], dsvt.hdr.flag[2], dsvt.hdr.mycall, dsvt.hdr.sfx, dsvt.hdr.urcall, dsvt.hdr.rpt1, dsvt.hdr.rpt2, length, togate.c_str());
// save mycall // save mycall
memcpy(call, dsvt.hdr.mycall, 8); memcpy(call, dsvt.hdr.mycall, 8);
@ -2813,7 +2810,7 @@ void CQnetLink::Process()
calcPFCS(fromrptr_torptr_brd.title, 56); calcPFCS(fromrptr_torptr_brd.title, 56);
Link2Gate.Write(fromrptr_torptr_brd.title, 56); ToGate.Write(fromrptr_torptr_brd.title, 56);
brd_from_rptr.from_rptr_streamid = dsvt.streamid; brd_from_rptr.from_rptr_streamid = dsvt.streamid;
brd_from_rptr.to_rptr_streamid[brd_from_rptr_idx] = fromrptr_torptr_brd.streamid; brd_from_rptr.to_rptr_streamid[brd_from_rptr_idx] = fromrptr_torptr_brd.streamid;
@ -2883,12 +2880,12 @@ void CQnetLink::Process()
memcpy(fromrptr_torptr_brd.title, dsvt.title, 27); memcpy(fromrptr_torptr_brd.title, dsvt.title, 27);
if (brd_from_rptr.to_rptr_streamid[0]) { if (brd_from_rptr.to_rptr_streamid[0]) {
fromrptr_torptr_brd.streamid = brd_from_rptr.to_rptr_streamid[0]; fromrptr_torptr_brd.streamid = brd_from_rptr.to_rptr_streamid[0];
Link2Gate.Write(fromrptr_torptr_brd.title, 27); ToGate.Write(fromrptr_torptr_brd.title, 27);
} }
if (brd_from_rptr.to_rptr_streamid[1]) { if (brd_from_rptr.to_rptr_streamid[1]) {
fromrptr_torptr_brd.streamid = brd_from_rptr.to_rptr_streamid[1]; fromrptr_torptr_brd.streamid = brd_from_rptr.to_rptr_streamid[1];
Link2Gate.Write(fromrptr_torptr_brd.title, 27); ToGate.Write(fromrptr_torptr_brd.title, 27);
} }
if (dsvt.ctrl & 0x40U) { if (dsvt.ctrl & 0x40U) {
@ -3016,7 +3013,7 @@ void CQnetLink::Process()
} }
} }
} }
FD_CLR (Gate2Link.GetFD(), &fdset); FD_CLR (ToGate.GetFD(), &fdset);
} }
for (int i=0; i<3 && keep_running; i++) { for (int i=0; i<3 && keep_running; i++) {
if (notify_msg[i][0] && 0x0U == tracing[i].streamid) { if (notify_msg[i][0] && 0x0U == tracing[i].streamid) {
@ -3123,7 +3120,7 @@ void CQnetLink::AudioNotifyThread(SECHO &edata)
return; return;
} }
Link2Gate.Write(edata.header.title, 56); ToGate.Write(edata.header.title, 56);
edata.header.config = 0x20U; edata.header.config = 0x20U;
@ -3185,7 +3182,7 @@ void CQnetLink::AudioNotifyThread(SECHO &edata)
} }
if (count+1 == ambeblocks && ! edata.is_linked) if (count+1 == ambeblocks && ! edata.is_linked)
edata.header.ctrl |= 0x40U; edata.header.ctrl |= 0x40U;
Link2Gate.Write(edata.header.title, 27); ToGate.Write(edata.header.title, 27);
std::this_thread::sleep_for(std::chrono::milliseconds(delay_between)); std::this_thread::sleep_for(std::chrono::milliseconds(delay_between));
} }
} }
@ -3238,7 +3235,7 @@ void CQnetLink::AudioNotifyThread(SECHO &edata)
memcpy(edata.header.vasd.text, edata.header.ctrl ? sdsilence : sdsync, 3); memcpy(edata.header.vasd.text, edata.header.ctrl ? sdsilence : sdsync, 3);
if (i+1==size && lastch) if (i+1==size && lastch)
edata.header.ctrl |= 0x40U; // signal the last voiceframe (of the last character) edata.header.ctrl |= 0x40U; // signal the last voiceframe (of the last character)
Link2Gate.Write(edata.header.title, 27); ToGate.Write(edata.header.title, 27);
std::this_thread::sleep_for(std::chrono::milliseconds(delay_between)); std::this_thread::sleep_for(std::chrono::milliseconds(delay_between));
} }
} }

@ -29,7 +29,7 @@
#include "QnetTypeDefs.h" #include "QnetTypeDefs.h"
#include "SEcho.h" #include "SEcho.h"
#include "Random.h" #include "Random.h"
#include "UnixDgramSocket.h" #include "UnixPacketSock.h"
#include "SockAddress.h" #include "SockAddress.h"
#include "Timer.h" #include "Timer.h"
#include "QnetDB.h" #include "QnetDB.h"
@ -145,9 +145,8 @@ private:
CSockAddress fromDst4; CSockAddress fromDst4;
// unix sockets to gateway // unix sockets to gateway
std::string link2gate, gate2link; std::string togate;
CUnixDgramReader Gate2Link; CUnixPacketClient ToGate;
CUnixDgramWriter Link2Gate;
// input from our own local repeater // input from our own local repeater
struct sockaddr_in fromRptr; struct sockaddr_in fromRptr;

@ -44,7 +44,7 @@
#include "QnetModem.h" #include "QnetModem.h"
#include "QnetConfigure.h" #include "QnetConfigure.h"
#define MODEM_VERSION "QnetModem-1.0.0" #define MODEM_VERSION "QnetModem-523"
#define MAX_RESPONSES 30 #define MAX_RESPONSES 30
std::atomic<bool> CQnetModem::keep_running(true); std::atomic<bool> CQnetModem::keep_running(true);
@ -222,8 +222,7 @@ bool CQnetModem::Initialize(const char *cfgfile)
std::signal(SIGINT, SignalCatch); std::signal(SIGINT, SignalCatch);
std::signal(SIGHUP, SignalCatch); std::signal(SIGHUP, SignalCatch);
Modem2Gate.SetUp(modem2gate.c_str()); if (ToGate.Open(togate.c_str()))
if (Gate2Modem.Open(gate2modem.c_str()))
return true; return true;
serfd = OpenModem(); serfd = OpenModem();
@ -437,7 +436,7 @@ void CQnetModem::Run(const char *cfgfile)
if (Initialize(cfgfile)) if (Initialize(cfgfile))
return; return;
int ug2m = Gate2Modem.GetFD(); int ug2m = ToGate.GetFD();
printf("gate2modem=%d, serial=%d\n", ug2m, serfd); printf("gate2modem=%d, serial=%d\n", ug2m, serfd);
keep_running = true; keep_running = true;
@ -501,7 +500,7 @@ void CQnetModem::Run(const char *cfgfile)
if (keep_running && FD_ISSET(ug2m, &readfds)) { if (keep_running && FD_ISSET(ug2m, &readfds)) {
SDSVT dsvt; SDSVT dsvt;
ssize_t len = Gate2Modem.Read(dsvt.title, sizeof(SDSVT)); ssize_t len = ToGate.Read(dsvt.title, sizeof(SDSVT));
if (len <= 0) { if (len <= 0) {
break; break;
@ -548,7 +547,7 @@ void CQnetModem::Run(const char *cfgfile)
} }
} }
close(serfd); close(serfd);
Gate2Modem.Close(); ToGate.Close();
} }
int CQnetModem::SendToModem(const unsigned char *buf) int CQnetModem::SendToModem(const unsigned char *buf)
@ -664,7 +663,7 @@ bool CQnetModem::ProcessModem(const SMODEM &frame)
memcpy(dsvt.hdr.mycall, frame.header.my, 8); memcpy(dsvt.hdr.mycall, frame.header.my, 8);
memcpy(dsvt.hdr.sfx, frame.header.nm, 4); memcpy(dsvt.hdr.sfx, frame.header.nm, 4);
memcpy(dsvt.hdr.pfcs, frame.header.pfcs, 2); memcpy(dsvt.hdr.pfcs, frame.header.pfcs, 2);
if (56 != Modem2Gate.Write(dsvt.title, 56)) { if (ToGate.Write(dsvt.title, 56)) {
printf("ERROR: ProcessModem: Could not write gateway header packet\n"); printf("ERROR: ProcessModem: Could not write gateway header packet\n");
return true; return true;
} }
@ -682,7 +681,7 @@ bool CQnetModem::ProcessModem(const SMODEM &frame)
printf("Warning: Inserting missing frame sync after header\n"); printf("Warning: Inserting missing frame sync after header\n");
dsvt.ctrl = 0U; dsvt.ctrl = 0U;
memcpy(dsvt.vasd.voice, sync, 12U); memcpy(dsvt.vasd.voice, sync, 12U);
Modem2Gate.Write(dsvt.title, 27); ToGate.Write(dsvt.title, 27);
nextctrl = 0x1U; nextctrl = 0x1U;
} }
first_voice_packet = false; first_voice_packet = false;
@ -694,7 +693,7 @@ bool CQnetModem::ProcessModem(const SMODEM &frame)
memcpy(dsvt.vasd.voice, silence, 12U); memcpy(dsvt.vasd.voice, silence, 12U);
while (nextctrl < 21U) { while (nextctrl < 21U) {
dsvt.ctrl = nextctrl++; dsvt.ctrl = nextctrl++;
Modem2Gate.Write(dsvt.title, 27); ToGate.Write(dsvt.title, 27);
} }
nextctrl = 0x0U; nextctrl = 0x0U;
} }
@ -703,7 +702,7 @@ bool CQnetModem::ProcessModem(const SMODEM &frame)
fprintf(stderr, "Warning: nextctrl=%u, inserting missing sync frame\n", nextctrl); fprintf(stderr, "Warning: nextctrl=%u, inserting missing sync frame\n", nextctrl);
dsvt.ctrl = 0U; dsvt.ctrl = 0U;
memcpy(dsvt.vasd.voice, sync, 12U); memcpy(dsvt.vasd.voice, sync, 12U);
Modem2Gate.Write(dsvt.title, 27); ToGate.Write(dsvt.title, 27);
nextctrl = 0x1U; nextctrl = 0x1U;
} }
@ -726,7 +725,7 @@ bool CQnetModem::ProcessModem(const SMODEM &frame)
in_stream = false; in_stream = false;
} }
dsvt.ctrl = nextctrl++; dsvt.ctrl = nextctrl++;
if (27 != Modem2Gate.Write(dsvt.title, 27)) { if (ToGate.Write(dsvt.title, 27)) {
printf("ERROR: ProcessModem: Could not write gateway voice packet\n"); printf("ERROR: ProcessModem: Could not write gateway voice packet\n");
return true; return true;
} }
@ -789,8 +788,7 @@ bool CQnetModem::ReadConfig(const char *cfgFile)
RPTR_MOD = 'A' + assigned_module; RPTR_MOD = 'A' + assigned_module;
cfg.GetValue(modem_path+"_device", type, MODEM_DEVICE, 7, FILENAME_MAX); cfg.GetValue(modem_path+"_device", type, MODEM_DEVICE, 7, FILENAME_MAX);
cfg.GetValue("gateway_gate2modem"+std::string(1, 'a'+assigned_module), estr, gate2modem, 1, FILENAME_MAX); cfg.GetValue("gateway_tomodem"+std::string(1, 'a'+assigned_module), estr, togate, 1, FILENAME_MAX);
cfg.GetValue("gateway_modem2gate", estr, modem2gate, 1, FILENAME_MAX);
if (cfg.GetValue(modem_path+"_tx_frequency", type, TX_FREQUENCY, 1.0, 6000.0)) if (cfg.GetValue(modem_path+"_tx_frequency", type, TX_FREQUENCY, 1.0, 6000.0))
return true; // we have to have a valid frequency return true; // we have to have a valid frequency

@ -25,7 +25,7 @@
#include <netinet/in.h> #include <netinet/in.h>
#include "Random.h" // for streamid generation #include "Random.h" // for streamid generation
#include "UnixDgramSocket.h" #include "UnixPacketSock.h"
#include "QnetTypeDefs.h" #include "QnetTypeDefs.h"
#include "Timer.h" #include "Timer.h"
@ -229,9 +229,8 @@ private:
CTimer PacketWait; CTimer PacketWait;
// unix sockets // unix sockets
std::string modem2gate, gate2modem; std::string togate;
CUnixDgramWriter Modem2Gate; CUnixPacketClient ToGate;
CUnixDgramReader Gate2Modem;
// Queue // Queue
std::queue<CFrame> queue; std::queue<CFrame> queue;

@ -36,7 +36,7 @@
#include "QnetTypeDefs.h" #include "QnetTypeDefs.h"
#include "QnetConfigure.h" #include "QnetConfigure.h"
#define RELAY_VERSION "QnetRelay-1.1.1" #define RELAY_VERSION "QnetRelay-523"
std::atomic<bool> CQnetRelay::keep_running(true); std::atomic<bool> CQnetRelay::keep_running(true);
@ -116,11 +116,10 @@ bool CQnetRelay::Run(const char *cfgfile)
if (msock < 0) if (msock < 0)
return true; return true;
Modem2Gate.SetUp(modem2gate.c_str()); if (ToGate.Open(togate.c_str()))
if (Gate2Modem.Open(gate2modem.c_str()))
return true; return true;
int fd = Gate2Modem.GetFD(); int fd = ToGate.GetFD();
printf("msock=%d, gateway=%d\n", msock, fd); printf("msock=%d, gateway=%d\n", msock, fd);
@ -164,10 +163,10 @@ bool CQnetRelay::Run(const char *cfgfile)
} }
if (FD_ISSET(fd, &readfds)) { if (FD_ISSET(fd, &readfds)) {
len = Gate2Modem.Read(buf, 100); len = ToGate.Read(buf, 100);
if (len < 0) { if (len < 0) {
fprintf(stderr, "ERROR: Run: Gate2Modem.Read() returned error %d: %s\n", errno, strerror(errno)); fprintf(stderr, "ERROR: Run: ToGate.Read() returned error %d: %s\n", errno, strerror(errno));
break; break;
} }
} }
@ -195,7 +194,7 @@ bool CQnetRelay::Run(const char *cfgfile)
} }
::close(msock); ::close(msock);
Gate2Modem.Close(); ToGate.Close();
return false; return false;
} }
@ -306,7 +305,7 @@ bool CQnetRelay::ProcessMMDVM(const int len, const unsigned char *raw)
memcpy(dsvt.hdr.mycall, dsrp.header.my, 8); memcpy(dsvt.hdr.mycall, dsrp.header.my, 8);
memcpy(dsvt.hdr.sfx, dsrp.header.nm, 4); memcpy(dsvt.hdr.sfx, dsrp.header.nm, 4);
memcpy(dsvt.hdr.pfcs, dsrp.header.pfcs, 2); memcpy(dsvt.hdr.pfcs, dsrp.header.pfcs, 2);
if (56 != Modem2Gate.Write(dsvt.title, 56)) { if (ToGate.Write(dsvt.title, 56)) {
printf("ERROR: ProcessMMDVM: Could not write gateway header packet\n"); printf("ERROR: ProcessMMDVM: Could not write gateway header packet\n");
return true; return true;
} }
@ -316,7 +315,7 @@ bool CQnetRelay::ProcessMMDVM(const int len, const unsigned char *raw)
dsvt.ctrl = dsrp.header.seq; dsvt.ctrl = dsrp.header.seq;
memcpy(dsvt.vasd.voice, dsrp.voice.ambe, 12); memcpy(dsvt.vasd.voice, dsrp.voice.ambe, 12);
if (27 != Modem2Gate.Write(dsvt.title, 27)) { if (ToGate.Write(dsvt.title, 27)) {
printf("ERROR: ProcessMMDVM: Could not write gateway voice packet\n"); printf("ERROR: ProcessMMDVM: Could not write gateway voice packet\n");
return true; return true;
} }
@ -377,8 +376,7 @@ bool CQnetRelay::ReadConfig(const char *cfgFile)
} }
RPTR_MOD = 'A' + assigned_module; RPTR_MOD = 'A' + assigned_module;
cfg.GetValue("gateway_gate2modem"+std::string(1, 'a'+assigned_module), estr, gate2modem, 1, FILENAME_MAX); cfg.GetValue("gateway_tomodem"+std::string(1, 'a'+assigned_module), estr, togate, 1, FILENAME_MAX);
cfg.GetValue("gateway_modem2gate", estr, modem2gate, 1, FILENAME_MAX);
cfg.GetValue(mmdvm_path+"_internal_ip", type, MMDVM_IP, 7, IP_SIZE); cfg.GetValue(mmdvm_path+"_internal_ip", type, MMDVM_IP, 7, IP_SIZE);
int i; int i;
cfg.GetValue(mmdvm_path+"_local_port", type, i, 10000, 65535); cfg.GetValue(mmdvm_path+"_local_port", type, i, 10000, 65535);

@ -22,7 +22,7 @@
#include <string> #include <string>
#include <netinet/in.h> #include <netinet/in.h>
#include "UnixDgramSocket.h" #include "UnixPacketSock.h"
#define CALL_SIZE 8 #define CALL_SIZE 8
#define IP_SIZE 15 #define IP_SIZE 15
@ -52,9 +52,8 @@ private:
// Unix sockets // Unix sockets
int assigned_module; int assigned_module;
std::string gate2modem, modem2gate; std::string togate;
CUnixDgramWriter Modem2Gate; CUnixPacketClient ToGate;
CUnixDgramReader Gate2Modem;
// config data // config data
char RPTR_MOD; char RPTR_MOD;

@ -39,22 +39,22 @@
#include "QnetConfigure.h" #include "QnetConfigure.h"
#include "UnixDgramSocket.h" #include "UnixDgramSocket.h"
#define VERSION "v2.3" #define VERSION "v523"
#ifndef CFG_DIR #ifndef CFG_DIR
#define CFG_DIR "/usr/local/etc" #define CFG_DIR "/usr/local/etc"
#endif #endif
int module; static int module;
time_t tNow = 0; static time_t tNow = 0;
short streamid_raw = 0; static short streamid_raw = 0;
std::string REPEATER, togateway; static std::string REPEATER, togateway;
int PLAY_WAIT, PLAY_DELAY; static int PLAY_WAIT, PLAY_DELAY;
unsigned char silence[9] = { 0x9E, 0x8D, 0x32, 0x88, 0x26, 0x1A, 0x3F, 0x61, 0xE8 }; static unsigned char silence[9] = { 0x9E, 0x8D, 0x32, 0x88, 0x26, 0x1A, 0x3F, 0x61, 0xE8 };
unsigned short crc_tabccitt[256] = { static unsigned short crc_tabccitt[256] = {
0x0000,0x1189,0x2312,0x329b,0x4624,0x57ad,0x6536,0x74bf,0x8c48,0x9dc1,0xaf5a,0xbed3,0xca6c,0xdbe5,0xe97e,0xf8f7, 0x0000,0x1189,0x2312,0x329b,0x4624,0x57ad,0x6536,0x74bf,0x8c48,0x9dc1,0xaf5a,0xbed3,0xca6c,0xdbe5,0xe97e,0xf8f7,
0x1081,0x0108,0x3393,0x221a,0x56a5,0x472c,0x75b7,0x643e,0x9cc9,0x8d40,0xbfdb,0xae52,0xdaed,0xcb64,0xf9ff,0xe876, 0x1081,0x0108,0x3393,0x221a,0x56a5,0x472c,0x75b7,0x643e,0x9cc9,0x8d40,0xbfdb,0xae52,0xdaed,0xcb64,0xf9ff,0xe876,
0x2102,0x308b,0x0210,0x1399,0x6726,0x76af,0x4434,0x55bd,0xad4a,0xbcc3,0x8e58,0x9fd1,0xeb6e,0xfae7,0xc87c,0xd9f5, 0x2102,0x308b,0x0210,0x1399,0x6726,0x76af,0x4434,0x55bd,0xad4a,0xbcc3,0x8e58,0x9fd1,0xeb6e,0xfae7,0xc87c,0xd9f5,
@ -73,9 +73,9 @@ unsigned short crc_tabccitt[256] = {
0xf78f,0xe606,0xd49d,0xc514,0xb1ab,0xa022,0x92b9,0x8330,0x7bc7,0x6a4e,0x58d5,0x495c,0x3de3,0x2c6a,0x1ef1,0x0f78 0xf78f,0xe606,0xd49d,0xc514,0xb1ab,0xa022,0x92b9,0x8330,0x7bc7,0x6a4e,0x58d5,0x495c,0x3de3,0x2c6a,0x1ef1,0x0f78
}; };
CQnetConfigure cfg; static CQnetConfigure cfg;
bool ReadCfgFile() static bool ReadCfgFile()
{ {
const std::string estr; const std::string estr;
std::string type; std::string type;
@ -95,14 +95,14 @@ bool ReadCfgFile()
return true; return true;
} }
} }
cfg.GetValue("gateway_modem2gate", estr, togateway, 1, FILENAME_MAX); cfg.GetValue("gateway_fromremote", estr, togateway, 1, FILENAME_MAX);
cfg.GetValue("timing_play_wait", estr, PLAY_WAIT, 1, 10); cfg.GetValue("timing_play_wait", estr, PLAY_WAIT, 1, 10);
cfg.GetValue("timing_play_delay", estr, PLAY_DELAY, 15, 25); cfg.GetValue("timing_play_delay", estr, PLAY_DELAY, 15, 25);
return false; return false;
} }
void calcPFCS(unsigned char rawbytes[56]) static void calcPFCS(unsigned char rawbytes[56])
{ {
unsigned short crc_dstar_ffff = 0xffff; unsigned short crc_dstar_ffff = 0xffff;
unsigned short tmp, short_c; unsigned short tmp, short_c;
@ -121,7 +121,7 @@ void calcPFCS(unsigned char rawbytes[56])
return; return;
} }
void ToUpper(std::string &str) static void ToUpper(std::string &str)
{ {
for (unsigned int i=0; i<str.size(); i++) for (unsigned int i=0; i<str.size(); i++)
if (islower(str[i])) if (islower(str[i]))

@ -0,0 +1,132 @@
/*
* Copyright (C) 2020 by Thomas Early N7TAE
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <iostream>
#include <unistd.h>
#include <sys/un.h>
#include <sys/socket.h>
#include "UnixPacketSock.h"
CUnixPacket::CUnixPacket() : m_fd(-1) {}
ssize_t CUnixPacket::Read(void *data, const ssize_t size)
{
return read(m_fd, data, size);
}
bool CUnixPacket::Write(const void *data, const ssize_t size) const
{
ssize_t written = write(m_fd, data, size);
if (written != size) {
std::cout << "CUnixPacketServer::Write ERROR: only wrote " << written << " of " << size << " bytes" << std::endl;
return true;
}
return false;
}
int CUnixPacket::GetFD()
{
return m_fd;
}
CUnixPacketServer::CUnixPacketServer() : m_server(-1) {}
CUnixPacketServer::~CUnixPacketServer()
{
Close();
}
bool CUnixPacketServer::Open(const char *name)
{
m_server = socket(AF_UNIX, SOCK_SEQPACKET, 0);
if (m_server < 0) {
std::cerr << "Cannot open " << name << " Unix server socket!" << std::endl;
return true;
}
struct sockaddr_un addr;
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
memcpy(addr.sun_path+1, name, strlen(name));
if (-1 == bind(m_server, (struct sockaddr *)&addr, sizeof(addr))) {
std::cerr << "Cannot bind " << name << "Unix server socket!" << std::endl;
Close();
return true;
}
if (-1 == listen(m_server, 1)) {
std::cerr << "Cannot listen on " << name << "Unix server socket!" << std::endl;
Close();
return true;
}
m_fd = accept(m_server, nullptr, 0);
if (m_fd < 0) {
std::cerr << "Cannot accept on " << name << "Unix server socket!" << std::endl;
Close();
return true;
}
return false;
}
void CUnixPacketServer::Close()
{
if (m_server >= 0) {
close(m_server);
m_server = -1;
}
if (m_fd >= 0) {
close(m_fd);
m_fd = -1;
}
}
CUnixPacketClient::~CUnixPacketClient()
{
Close();
}
bool CUnixPacketClient::Open(const char *name)
{
m_fd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
if (m_fd < 0) {
std::cerr << "Cannot open " << name << " Unix client socket!" << std::endl;
return true;
}
struct sockaddr_un addr;
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
memcpy(addr.sun_path+1, name, strlen(name));
if (-1 == connect(m_fd, (struct sockaddr *)&addr, sizeof(addr))) {
std::cerr << "Cannot connect " << name << "Unix client socket!" << std::endl;
Close();
return true;
}
return false;
}
void CUnixPacketClient::Close()
{
if (m_fd >= 0) {
close(m_fd);
m_fd = -1;
}
}

@ -0,0 +1,50 @@
#pragma once
/*
* Copyright (C) 2020 by Thomas Early N7TAE
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <sys/types.h>
class CUnixPacket {
public:
CUnixPacket();
virtual bool Open(const char *name) = 0;
virtual void Close() = 0;
bool Write(const void *buffer, const ssize_t size) const;
ssize_t Read(void *buffer, const ssize_t size);
int GetFD();
protected:
int m_fd;
};
class CUnixPacketServer : public CUnixPacket {
public:
CUnixPacketServer();
~CUnixPacketServer();
bool Open(const char *name);
void Close();
protected:
int m_server;
};
class CUnixPacketClient : public CUnixPacket {
public:
~CUnixPacketClient();
bool Open(const char *name);
void Close();
};

@ -53,12 +53,11 @@ gateway_ip_d='ANY_PORT' # the g2 port
gateway_port_d=40000 # don't change gateway_port_d=40000 # don't change
gateway_ipv6_ip_d='ANY_PORT' gateway_ipv6_ip_d='ANY_PORT'
gateway_ipv6_port_d=9011 # IANA-approved DStar rouing port gateway_ipv6_port_d=9011 # IANA-approved DStar rouing port
gateway_gate2link_d='gate2link' # Unix sockets between qngateway and QnetLink gateway_tolink_d='tolink' # Unix SOCK_SEQPACKET to qnlink
gateway_link2gate_d='link2gate' # all Unix sockets are on the file system, but hidden from view gateway_tomodema_d='tomodema' # Unix SOCK_SEQPACKET to modem on module A
gateway_modem2gate_d='modem2gate' # Unix Sockets between the modem(s) and the gateway (1 in, 3 out) gateway_tomodemb_d='tomodemb' # Unix SOCK_SEQPACKET to modem on module B
gateway_gate2modema_d='gate2modema' gateway_tomodemc_d='tomodemc' # Unix SOCK_SEQPACKET to modem on module C
gateway_gate2modemb_d='gate2modemb' gateway_fromremote_d='fromremote' # Unix SOCK_DRAM from remote to gateway
gateway_gate2modemc_d='gate2modemc'
gateway_latitude_d=0 # you can leave this unspecified for a mobile rig gateway_latitude_d=0 # you can leave this unspecified for a mobile rig
gateway_longitude_d=0 # like the latitude gateway_longitude_d=0 # like the latitude
gateway_desc1_d='' # maximum of 20 characters, most special symbols are not allowed gateway_desc1_d='' # maximum of 20 characters, most special symbols are not allowed

@ -300,12 +300,6 @@ GateMenu () {
echo -n "i : IRC TCP local network address = "; EvaluateVar gateway_local_irc_ip{,_d} echo -n "i : IRC TCP local network address = "; EvaluateVar gateway_local_irc_ip{,_d}
echo -n "a : G2 port address = "; EvaluateVar gateway_ip{,_d} echo -n "a : G2 port address = "; EvaluateVar gateway_ip{,_d}
echo -n "p : G2 port number = "; EvaluateVar gateway_port{,_d} echo -n "p : G2 port number = "; EvaluateVar gateway_port{,_d}
echo -n "tl : UNIX socket to QnetLink = "; EvaluateVar gateway_gate2link{,_d}
echo -n "fl : UNIX socket from QnetLink = "; EvaluateVar gateway_link2gate{,_d}
echo -n "ta : UNIX socket to Modem A = "; EvaluateVar gateway_gate2modema{,_d}
echo -n "tb : UNIX socket to Modem B = "; EvaluateVar gateway_gate2modemb{,_d}
echo -n "tc : UNIX socket to Modem C = "; EvaluateVar gateway_gate2modemc{,_d}
echo -n "fm : UNIX socket from Modem(s) = "; EvaluateVar gateway_modem2gate{,_d}
fi fi
echo -n "la : Latitude (-90.0 to 90.0) = "; EvaluateVar gateway_latitude{,_d} echo -n "la : Latitude (-90.0 to 90.0) = "; EvaluateVar gateway_latitude{,_d}
echo -n "lo : Longitude (-180.0 to 180.0) = "; EvaluateVar gateway_longitude{,_d} echo -n "lo : Longitude (-180.0 to 180.0) = "; EvaluateVar gateway_longitude{,_d}
@ -331,12 +325,6 @@ GateMenu () {
elif [[ "$key" == i* ]]; then gateway_local_irc_ip="$value" elif [[ "$key" == i* ]]; then gateway_local_irc_ip="$value"
elif [[ "$key" == a* ]]; then gateway_ip="$value" elif [[ "$key" == a* ]]; then gateway_ip="$value"
elif [[ "$key" == p* ]]; then gateway_port="$value" elif [[ "$key" == p* ]]; then gateway_port="$value"
elif [[ "$key" == tl* ]]; then gateway_gate2link="$value"
elif [[ "$key" == fl* ]]; then gateway_link2gate="$value"
elif [[ "$key" == ta* ]]; then gateway_gate2modema="$value"
elif [[ "$key" == tb* ]]; then gateway_gate2modemb="$value"
elif [[ "$key" == tc* ]]; then gateway_gate2modemc="$value"
elif [[ "$key" == fm* ]]; then gateway_modem2gate="$value"
elif [[ "$key" == la* ]]; then gateway_latitude="$value" elif [[ "$key" == la* ]]; then gateway_latitude="$value"
elif [[ "$key" == lo* ]]; then gateway_longitude="$value" elif [[ "$key" == lo* ]]; then gateway_longitude="$value"
elif [[ "$key" == d1* ]]; then gateway_desc1="${value:0:20}" elif [[ "$key" == d1* ]]; then gateway_desc1="${value:0:20}"
@ -354,11 +342,6 @@ GateMenu () {
elif [[ "$value" == i* ]]; then unset gateway_local_irc_ip elif [[ "$value" == i* ]]; then unset gateway_local_irc_ip
elif [[ "$value" == a* ]]; then unset gateway_ip elif [[ "$value" == a* ]]; then unset gateway_ip
elif [[ "$value" == p* ]]; then unset gateway_port elif [[ "$value" == p* ]]; then unset gateway_port
elif [[ "$value" == tl* ]]; then unset gateway_gate2link
elif [[ "$value" == ta* ]]; then unset gateway_gate2modema
elif [[ "$value" == tb* ]]; then unset gateway_gate2modemb
elif [[ "$value" == tc* ]]; then unset gateway_gate2modemc
elif [[ "$value" == fm* ]]; then unset gateway_modem2gate
elif [[ "$value" == la* ]]; then unset gateway_latitude elif [[ "$value" == la* ]]; then unset gateway_latitude
elif [[ "$value" == lo* ]]; then unset gateway_longitude elif [[ "$value" == lo* ]]; then unset gateway_longitude
elif [[ "$value" == d1* ]]; then unset gateway_desc1 elif [[ "$value" == d1* ]]; then unset gateway_desc1
@ -640,12 +623,6 @@ WriteCFGFile () {
[ -z "${gateway_local_irc_ip+x}" ] || echo "gateway_local_irc_ip='${gateway_local_irc_ip}'" >> $outFile [ -z "${gateway_local_irc_ip+x}" ] || echo "gateway_local_irc_ip='${gateway_local_irc_ip}'" >> $outFile
[ -z "${gateway_port+x}" ] || echo "gateway_port=${gateway_port}" >> $outFile [ -z "${gateway_port+x}" ] || echo "gateway_port=${gateway_port}" >> $outFile
[ -z "${gateway_ip+x}" ] || echo "gateway_ip=${gateway_ip}" >> $outFile [ -z "${gateway_ip+x}" ] || echo "gateway_ip=${gateway_ip}" >> $outFile
[ -z "${gateway_tolink+x}" ] || echo "gateway_tolink=${gateway_tolink}" >> $outFile
[ -z "${gateway_fromlink+x}" ] || echo "gateway_fromlink=${gateway_fromlink}" >> $outFile
[ -z "${gateway_gate2modema+x}" ] || echo "gateway_gate2modema=${gateway_gate2modema}" >> $outFile
[ -z "${gateway_gate2modemb+x}" ] || echo "gateway_gate2modemb=${gateway_gate2modemb}" >> $outFile
[ -z "${gateway_gate2modemc+x}" ] || echo "gateway_gate2modemc=${gateway_gate2modemc}" >> $outFile
[ -z "${gateway_modem2gate+x}" ] || echo "gateway_modem2gate=${gateway_modem2gate}" >> $outFile
[ -z "${gateway_latitude+x}" ] || echo "gateway_latitude=${gateway_latitude}" >> $outFile [ -z "${gateway_latitude+x}" ] || echo "gateway_latitude=${gateway_latitude}" >> $outFile
[ -z "${gateway_longitude+x}" ] || echo "gateway_longitude=${gateway_longitude}" >> $outFile [ -z "${gateway_longitude+x}" ] || echo "gateway_longitude=${gateway_longitude}" >> $outFile
[ -z "${gateway_desc1+x}" ] || echo "gateway_desc1='${gateway_desc1}'" >> $outFile [ -z "${gateway_desc1+x}" ] || echo "gateway_desc1='${gateway_desc1}'" >> $outFile

Loading…
Cancel
Save

Powered by TurnKey Linux.