diff --git a/CMakeLists.txt b/CMakeLists.txt index 56525117..9ae68801 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,8 @@ file(GLOB dvmhost_SRC "network/*.h" "network/*.cpp" "network/json/*.h" + "remote/RemoteCommand.cpp" + "remote/RemoteCommand.h" "yaml/*.h" "yaml/*.cpp" "*.h" diff --git a/dmr/Control.cpp b/dmr/Control.cpp index daf869c2..155e0a39 100644 --- a/dmr/Control.cpp +++ b/dmr/Control.cpp @@ -324,6 +324,15 @@ void Control::clock() m_slot2->clock(); } +/// +/// Permits a TGID on a non-authoritative host. +/// +/// +void Control::permittedTG(uint32_t dstId) +{ + // TODO TODO +} + /// /// Helper to return the slot carrying the TSCC. /// diff --git a/dmr/Control.h b/dmr/Control.h index 3e57ffea..369434fe 100644 --- a/dmr/Control.h +++ b/dmr/Control.h @@ -90,6 +90,9 @@ namespace dmr /// Updates the processor. void clock(); + /// Permits a TGID on a non-authoritative host. + void permittedTG(uint32_t dstId); + /// Helper to return the slot carrying the TSCC. Slot* getTSCCSlot() const; diff --git a/network/RemoteControl.cpp b/network/RemoteControl.cpp index fefc3ea8..7e447889 100644 --- a/network/RemoteControl.cpp +++ b/network/RemoteControl.cpp @@ -1221,7 +1221,7 @@ std::string RemoteControl::rcdMode(std::vector args, Host* host, dm std::string RemoteControl::rcdPermitTG(std::vector args, Host* host, dmr::Control* dmr, p25::Control* p25, nxdn::Control* nxdn) { std::string reply = ""; - if (host->m_authoritative) { + if (!host->m_authoritative) { DVM_STATE state = (DVM_STATE)getArgInt32(args, 0U); uint32_t dstId = getArgInt32(args, 1U); if (dstId == 0U) { @@ -1234,7 +1234,7 @@ std::string RemoteControl::rcdPermitTG(std::vector args, Host* host #if defined(ENABLE_DMR) { if (dmr != nullptr) { - // TODO TODO TODO -- handle permitting destination IDs + dmr->permittedTG(dstId); } else { reply = CMD_FAILED_STR "DMR mode is not enabled!"; @@ -1252,7 +1252,7 @@ std::string RemoteControl::rcdPermitTG(std::vector args, Host* host #if defined(ENABLE_P25) { if (p25 != nullptr) { - // TODO TODO TODO -- handle permitting destination IDs + p25->permittedTG(dstId); } else { reply = CMD_FAILED_STR "P25 mode is not enabled!"; @@ -1270,7 +1270,7 @@ std::string RemoteControl::rcdPermitTG(std::vector args, Host* host #if defined(ENABLE_NXDN) { if (nxdn != nullptr) { - // TODO TODO TODO -- handle permitting destination IDs + nxdn->permittedTG(dstId); } else { reply = CMD_FAILED_STR "NXDN mode is not enabled!"; diff --git a/nxdn/Control.cpp b/nxdn/Control.cpp index aaf75b5f..3b6d7058 100644 --- a/nxdn/Control.cpp +++ b/nxdn/Control.cpp @@ -585,6 +585,15 @@ void Control::clock(uint32_t ms) } } +/// +/// Permits a TGID on a non-authoritative host. +/// +/// +void Control::permittedTG(uint32_t dstId) +{ + // TODO TODO +} + /// /// Flag indicating whether the process or is busy or not. /// diff --git a/nxdn/Control.h b/nxdn/Control.h index fc616b66..214cb3aa 100644 --- a/nxdn/Control.h +++ b/nxdn/Control.h @@ -103,6 +103,9 @@ namespace nxdn /// Updates the processor by the passed number of milliseconds. void clock(uint32_t ms); + /// Permits a TGID on a non-authoritative host. + void permittedTG(uint32_t dstId); + /// Flag indicating whether the processor or is busy or not. bool isBusy() const; diff --git a/p25/Control.cpp b/p25/Control.cpp index d2c4a845..13e0775d 100644 --- a/p25/Control.cpp +++ b/p25/Control.cpp @@ -735,6 +735,15 @@ void Control::clock(uint32_t ms) } } +/// +/// Permits a TGID on a non-authoritative host. +/// +/// +void Control::permittedTG(uint32_t dstId) +{ + // TODO TODO +} + /// /// Flag indicating whether the processor or is busy or not. /// diff --git a/p25/Control.h b/p25/Control.h index bb0a955c..6ac2412c 100644 --- a/p25/Control.h +++ b/p25/Control.h @@ -110,6 +110,9 @@ namespace p25 /// Updates the processor by the passed number of milliseconds. void clock(uint32_t ms); + /// Permits a TGID on a non-authoritative host. + void permittedTG(uint32_t dstId); + /// Gets instance of the NID class. NID nid() { return m_nid; } /// Gets instance of the Trunk class. diff --git a/remote/RemoteCommand.cpp b/remote/RemoteCommand.cpp index 7b82fb88..4e486c7a 100644 --- a/remote/RemoteCommand.cpp +++ b/remote/RemoteCommand.cpp @@ -1,9 +1,9 @@ /** -* Digital Voice Modem - Remote Command Client +* Digital Voice Modem - Host Software * GPLv2 Open Source. Use is subject to license terms. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * -* @package DVM / Remote Command Client +* @package DVM / Host Software * */ // @@ -47,12 +47,6 @@ using namespace network; // Constants // --------------------------------------------------------------------------- -#undef __PROG_NAME__ -#define __PROG_NAME__ "Digital Voice Modem (DVM) RCON Tool" -#undef __EXE_NAME__ -#define __EXE_NAME__ "dvmcmd" - -#define ERRNO_REMOTE_CMD 99 #define ERRNO_SOCK_OPEN 98 #define ERRNO_ADDR_LOOKUP 97 #define ERRNO_FAILED_TO_SEND 96 @@ -66,180 +60,6 @@ const uint8_t REC_SEPARATOR = 0x1EU; const uint32_t RC_BUFFER_LENGTH = 250U; const uint32_t RESPONSE_BUFFER_LEN = 4095U; -// --------------------------------------------------------------------------- -// Macros -// --------------------------------------------------------------------------- - -#define IS(s) (::strcmp(argv[i], s) == 0) - -// --------------------------------------------------------------------------- -// Global Variables -// --------------------------------------------------------------------------- - -static std::string g_progExe = std::string(__EXE_NAME__); -static std::string g_remoteAddress = std::string("127.0.0.1"); -static uint32_t g_remotePort = RCON_DEFAULT_PORT; -static std::string g_remotePassword = std::string(); -static bool g_debug = false; - -// --------------------------------------------------------------------------- -// Global Functions -// --------------------------------------------------------------------------- - -void fatal(const char* message) -{ - ::fprintf(stderr, "%s: %s\n", g_progExe.c_str(), message); - exit(EXIT_FAILURE); -} - -void usage(const char* message, const char* arg) -{ - ::fprintf(stdout, __PROG_NAME__ " %s (built %s)\r\n", __VER__, __BUILD__); - ::fprintf(stdout, "Copyright (c) 2017-2022 Bryan Biedenkapp, N2PLL and DVMProject (https://github.com/dvmproject) Authors.\n"); - ::fprintf(stdout, "Portions Copyright (c) 2015-2021 by Jonathan Naylor, G4KLX and others\n\n"); - if (message != nullptr) { - ::fprintf(stderr, "%s: ", g_progExe.c_str()); - ::fprintf(stderr, message, arg); - ::fprintf(stderr, "\n\n"); - } - - ::fprintf(stdout, "usage: %s [-v] [-a
] [-p ] [-P ] \n\n" - " -a remote modem command address\n" - " -p remote modem command port\n" - " -P remote modem authentication password\n" - "\n" - " -d enable debug\n" - " -v show version information\n" - " -h show this screen\n" - " -- stop handling options\n", - g_progExe.c_str()); - exit(EXIT_FAILURE); -} - -int checkArgs(int argc, char* argv[]) -{ - int i, p = 0; - - // iterate through arguments - for (i = 1; i <= argc; i++) - { - if (argv[i] == nullptr) { - break; - } - - if (*argv[i] != '-') { - continue; - } - else if (IS("--")) { - ++p; - break; - } - else if (IS("-a")) { - if ((argc - 1) <= 0) - usage("error: %s", "must specify the address to connect to"); - g_remoteAddress = std::string(argv[++i]); - - if (g_remoteAddress == "") - usage("error: %s", "remote address cannot be blank!"); - - p += 2; - } - else if (IS("-p")) { - if ((argc - 1) <= 0) - usage("error: %s", "must specify the port to connect to"); - g_remotePort = (uint32_t)::atoi(argv[++i]); - - if (g_remotePort == 0) - usage("error: %s", "remote port number cannot be blank or 0!"); - - p += 2; - } - else if (IS("-P")) { - if ((argc - 1) <= 0) - usage("error: %s", "must specify the auth password"); - g_remotePassword = std::string(argv[++i]); - - if (g_remotePassword == "") - usage("error: %s", "remote auth password cannot be blank!"); - - p += 2; - } - else if (IS("-d")) { - ++p; - g_debug = true; - } - else if (IS("-v")) { - ::fprintf(stdout, __PROG_NAME__ " %s (built %s)\r\n", __VER__, __BUILD__); - ::fprintf(stdout, "Copyright (c) 2017-2022 Bryan Biedenkapp, N2PLL and DVMProject (https://github.com/dvmproject) Authors.\r\n"); - ::fprintf(stdout, "Portions Copyright (c) 2015-2021 by Jonathan Naylor, G4KLX and others\r\n"); - if (argc == 2) - exit(EXIT_SUCCESS); - } - else if (IS("-h")) { - usage(nullptr, nullptr); - if (argc == 2) - exit(EXIT_SUCCESS); - } - else { - usage("unrecognized option `%s'", argv[i]); - } - } - - if (p < 0 || p > argc) { - p = 0; - } - - return ++p; -} - -// --------------------------------------------------------------------------- -// Program Entry Point -// --------------------------------------------------------------------------- - -int main(int argc, char** argv) -{ - if (argv[0] != nullptr && *argv[0] != 0) - g_progExe = std::string(argv[0]); - - if (argc < 2) { - usage("error: %s", "must specify the remote command!"); - return ERRNO_REMOTE_CMD; - } - - if (argc > 1) { - // check arguments - int i = checkArgs(argc, argv); - if (i < argc) { - argc -= i; - argv += i; - } - else { - argc--; - argv++; - } - } - - // process command - std::string cmd = std::string(argv[0]); - for (int i = 1; i < argc; i++) { - cmd += " "; - cmd += std::string(argv[i]); - } - - // initialize system logging - bool ret = ::LogInitialise("", "", 0U, 1U, true); - if (!ret) { - ::fprintf(stderr, "unable to open the log file\n"); - return 1; - } - - RemoteCommand* command = new RemoteCommand(g_remoteAddress, g_remotePort, g_remotePassword); - int retCode = command->send(cmd); - - ::LogFinalise(); - return retCode; -} - // --------------------------------------------------------------------------- // Public Class Members // --------------------------------------------------------------------------- @@ -250,10 +70,12 @@ int main(int argc, char** argv) /// Network Hostname/IP address to connect to. /// Network port number. /// Authentication password. -RemoteCommand::RemoteCommand(const std::string& address, uint32_t port, const std::string& password) : +/// Flag indicating whether debug is enabled. +RemoteCommand::RemoteCommand(const std::string& address, uint32_t port, const std::string& password, bool debug) : m_address(address), m_port(port), - m_password(password) + m_password(password), + m_debug(debug) { assert(!address.empty()); assert(port > 0U); @@ -291,8 +113,7 @@ int RemoteCommand::send(const std::string& command) return ERRNO_ADDR_LOOKUP; } - ::LogInfoEx(LOG_HOST, "%s: sending command \"%s\" to %s:%u", g_progExe.c_str(), command.c_str(), - m_address.c_str(), m_port); + ::LogInfoEx(LOG_HOST, "sending RCON command \"%s\" to %s:%u", command.c_str(), m_address.c_str(), m_port); buffer[0U] = RCON_FRAME_START; buffer[1U] = START_OF_TEXT; @@ -318,7 +139,7 @@ int RemoteCommand::send(const std::string& command) buffer[35U + command.size()] = END_OF_TEXT; - if (g_debug) + if (m_debug) Utils::dump(1U, "RCON Sent", (uint8_t*)buffer, 36U + command.size()); ret = socket.write((uint8_t *)buffer, 36U + command.size(), addr, addrLen); @@ -345,12 +166,12 @@ int RemoteCommand::send(const std::string& command) if (offs + len > RESPONSE_BUFFER_LEN) break; - if (g_debug) + if (m_debug) ::LogDebug(LOG_RCON, "RemoteCommand::send() block len = %u, offs = %u", len - 3, offs); buffer[len] = '\0'; - if (g_debug) + if (m_debug) Utils::dump(1U, "RCON Received", (uint8_t*)buffer, len); // make sure this is an RCON response diff --git a/remote/RemoteCommand.h b/remote/RemoteCommand.h index 01bafe52..0cb81073 100644 --- a/remote/RemoteCommand.h +++ b/remote/RemoteCommand.h @@ -1,9 +1,9 @@ /** -* Digital Voice Modem - Remote Command Client +* Digital Voice Modem - Host Software * GPLv2 Open Source. Use is subject to license terms. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * -* @package DVM / Remote Command Client +* @package DVM / Host Software * */ // @@ -44,7 +44,7 @@ class HOST_SW_API RemoteCommand { public: /// Initializes a new instance of the RemoteCommand class. - RemoteCommand(const std::string& address, uint32_t port, const std::string& password); + RemoteCommand(const std::string& address, uint32_t port, const std::string& password, bool debug); /// Finalizes a instance of the RemoteCommand class. ~RemoteCommand(); @@ -55,6 +55,8 @@ private: std::string m_address; uint32_t m_port; std::string m_password; + + bool m_debug; }; #endif // __REMOTE_COMMAND_H__