[Hamlib-commits] Hamlib -- Ham radio control libraries branch master updated. 0806896e3be5f2465f52b
Library to control radio transceivers and receivers
Brought to you by:
n0nb
From: Michael B. <mdb...@us...> - 2021-09-22 04:34:00
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Hamlib -- Ham radio control libraries". The branch, master has been updated via 0806896e3be5f2465f52b5352d2ec5bf684616f9 (commit) via 9671a26858404400b05dd9f47511a2dea9dd28d3 (commit) via a94dcddcf44c5ee1942f5c04a037edfb806f2878 (commit) via 4c0633bf6256af2ce64d7f0aff9b8ea9bc674209 (commit) via 3fb38741aa0a87fa2fa9a19f4eec433941a8dd92 (commit) via 0ad5f4c3dbe07be92b7e76968f1ecd38315cd03a (commit) via 8024fba14d364d3ed5f0fb290fa6d801b1853677 (commit) via a3ab4a4312a76e2b8eca9b0e088988bfb0083bc6 (commit) from c0c941a9d0d942fe374b607ff48a827c0d15017e (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 0806896e3be5f2465f52b5352d2ec5bf684616f9 Author: Mike Black W9MDB <mdb...@ya...> Date: Tue Sep 21 23:32:12 2021 -0500 Fix compilation when OS does not have libusb installed https://github.com/Hamlib/Hamlib/issues/803 diff --git a/configure.ac b/configure.ac index 21d98847..03a99f95 100644 --- a/configure.ac +++ b/configure.ac @@ -321,10 +321,11 @@ LIBUSB="" AC_ARG_VAR([LIBUSB_CFLAGS], [C compiler flags for libusb, overriding configure defaults]) AC_ARG_VAR([LIBUSB_LIBS], [linker flags for libusb, overriding configure check (useful for specifying static libusb-1.0.a (see INSTALL))]) -AS_IF([test x"${cf_with_libusb}" = "xyes"], - [AS_IF([test -z $LIBUSB_LIBS], +AS_IF([test x"${cf_with_libusb}" = "xyes"], [ + AS_IF([test -z $LIBUSB_LIBS], [AC_CHECK_LIB([usb-1.0], [libusb_init], [LIBUSB_LIBS="-lusb-1.0"], [AC_MSG_WARN([libusb_init was not found in libusb-1.0--USB backends will be disabled])]) + [cf_with_libusb="no"] ], [cf_with_libusb="yes"]) AS_IF([test x"${cf_with_libusb}" = "xyes"], diff --git a/tests/rigtestlibusb.c b/tests/rigtestlibusb.c index 29156cc0..4689ff7e 100644 --- a/tests/rigtestlibusb.c +++ b/tests/rigtestlibusb.c @@ -24,12 +24,13 @@ #include <stdio.h> #include <string.h> -#if __has_include("libusb.h") +#if defined(HAVE_LIBUSB_H) #include "libusb.h" -#else +#elif defined(HAVE_LIBUSB_1_0_LIBUSB_H) #include <libusb-1.0/libusb.h> #endif +#if HAVE_LIBUSB int verbose = 0; static void print_endpoint_comp(const struct @@ -410,3 +411,10 @@ int main(int argc, char *argv[]) libusb_exit(NULL); return r; } +#else +int main() +{ + puts("libusb not installed"); + return 0; +} +#endif commit 9671a26858404400b05dd9f47511a2dea9dd28d3 Author: Mike Black W9MDB <mdb...@ya...> Date: Tue Sep 21 23:30:45 2021 -0500 Add mutex back to rigctld. Migrating to mutext locks on all rig functions https://github.com/Hamlib/Hamlib/issues/695 diff --git a/tests/rigctld.c b/tests/rigctld.c index 854227e0..39110629 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -148,9 +148,8 @@ const char *multicast_addr = "0.0.0.0"; #define MAXCONFLEN 1024 -extern void sync_callback(int lock); -#if 0 -void sync_callback(int lock) + +void mutex_rigctld(int lock) { #ifdef HAVE_PTHREAD static pthread_mutex_t client_lock = PTHREAD_MUTEX_INITIALIZER; @@ -168,7 +167,6 @@ void sync_callback(int lock) #endif } -#endif #ifdef WIN32 static BOOL WINAPI CtrlHandler(DWORD fdwCtrlType) @@ -999,7 +997,7 @@ int main(int argc, char *argv[]) #ifdef HAVE_PTHREAD /* allow threads to finish current action */ - sync_callback(1); + mutex_rigctld(1); if (client_count) { @@ -1007,7 +1005,7 @@ int main(int argc, char *argv[]) } rig_close(my_rig); - sync_callback(0); + mutex_rigctld(0); #else rig_close(my_rig); /* close port */ #endif @@ -1085,7 +1083,7 @@ void *handle_socket(void *arg) } #ifdef HAVE_PTHREAD - sync_callback(1); + mutex_rigctld(1); // ++client_count; #if 0 @@ -1104,7 +1102,7 @@ void *handle_socket(void *arg) #endif - sync_callback(0); + mutex_rigctld(0); #else retcode = rig_open(my_rig); @@ -1134,7 +1132,7 @@ void *handle_socket(void *arg) rig_debug(RIG_DEBUG_TRACE, "%s: doing rigctl_parse vfo_mode=%d\n", __func__, handle_data_arg->vfo_mode); retcode = rigctl_parse(handle_data_arg->rig, fsockin, fsockout, NULL, 0, - sync_callback, + mutex_rigctld, 1, 0, &handle_data_arg->vfo_mode, send_cmd_term, &ext_resp, &resp_sep); if (retcode != 0) { rig_debug(RIG_DEBUG_VERBOSE, "%s: rigctl_parse retcode=%d\n", __func__, retcode); } @@ -1168,7 +1166,7 @@ void *handle_socket(void *arg) #ifdef HAVE_PTHREAD #if 0 - sync_callback(1); + mutex_rigctld(1); /* Release rig if there are no clients */ if (!--client_count) @@ -1183,7 +1181,7 @@ void *handle_socket(void *arg) } } - sync_callback(0); + mutex_rigctld(0); #endif #else rig_close(my_rig); commit a94dcddcf44c5ee1942f5c04a037edfb806f2878 Author: Mike Black W9MDB <mdb...@ya...> Date: Tue Sep 21 12:17:17 2021 -0500 Fix ICOM request for VFOB info when VFOB is active vfo https://github.com/Hamlib/Hamlib/issues/806 diff --git a/rigs/icom/icom.c b/rigs/icom/icom.c index 60daccfa..2438fd4e 100644 --- a/rigs/icom/icom.c +++ b/rigs/icom/icom.c @@ -2193,8 +2193,10 @@ int icom_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) && rig->caps->rig_model != RIG_MODEL_IC7800) { int vfosel = 0x00; + vfo_t vfoask = vfo_fixup(rig, vfo, 0); + vfo_t vfocurr = vfo_fixup(rig, rig->state.current_vfo, 0); - if (vfo & (RIG_VFO_B | RIG_VFO_SUB | RIG_VFO_SUB_B | RIG_VFO_MAIN_B)) { vfosel = 0x01; } + if (vfoask != vfocurr) { vfosel = 0x01; } // use cache for the non-selected VFO -- can't get it by VFO // this avoids vfo swapping but accurate answers for these rigs @@ -6947,6 +6949,7 @@ int icom_set_parm(RIG *rig, setting_t parm, value_t val) rig_strparm(parm)); RETURNFUNC(-RIG_EINVAL); } + RETURNFUNC(-RIG_EINVAL); } diff --git a/rigs/icom/icom.h b/rigs/icom/icom.h index 9127b6e2..acdfeed1 100644 --- a/rigs/icom/icom.h +++ b/rigs/icom/icom.h @@ -30,7 +30,7 @@ #include <sys/time.h> #endif -#define BACKEND_VER "20210911" +#define BACKEND_VER "20210921" #define ICOM_IS_SECONDARY_VFO(vfo) ((vfo) & (RIG_VFO_B | RIG_VFO_SUB | RIG_VFO_SUB_B | RIG_VFO_MAIN_B)) #define ICOM_GET_VFO_NUMBER(vfo) (ICOM_IS_SECONDARY_VFO(vfo) ? 0x01 : 0x00) commit 4c0633bf6256af2ce64d7f0aff9b8ea9bc674209 Merge: 3fb38741 a3ab4a43 Author: Michael Black <mdb...@ya...> Date: Tue Sep 21 09:26:11 2021 -0500 Merge pull request #804 from wutje/improve_rig Fix rig_cookie: use lock for reads and write. commit 3fb38741aa0a87fa2fa9a19f4eec433941a8dd92 Merge: c0c941a9 0ad5f4c3 Author: Michael Black <mdb...@ya...> Date: Mon Sep 20 16:31:56 2021 -0500 Merge pull request #805 from wutje/fix_yaesu_detect Fix Yaesu and Adat detect commit 0ad5f4c3dbe07be92b7e76968f1ecd38315cd03a Author: Wouter van Gulik <pa...@gm...> Date: Mon Sep 20 23:19:59 2021 +0200 Drop debug printf diff --git a/rigs/yaesu/yaesu.c b/rigs/yaesu/yaesu.c index 9a7b8cb5..ff209154 100644 --- a/rigs/yaesu/yaesu.c +++ b/rigs/yaesu/yaesu.c @@ -159,7 +159,6 @@ DECLARE_PROBERIG_BACKEND(yaesu) port->parm.serial.rate = rates[rates_idx]; port->timeout = 2 * 1000 / rates[rates_idx] + 50; - printf("Yaesu trying rate = %d\n", rates[rates_idx]); retval = serial_open(port); if (retval != RIG_OK) commit 8024fba14d364d3ed5f0fb290fa6d801b1853677 Author: Wouter van Gulik <pa...@gm...> Date: Mon Sep 20 23:06:25 2021 +0200 Fix bug yaesu and adat probe: Yaesu probe code never left the loop, even if it did find something. Adat tried stop_bits 0, which serial_setup rightfully refused. THIS IS UNTESTED. diff --git a/rigs/adat/adat.c b/rigs/adat/adat.c index bab7a946..c1503a52 100644 --- a/rigs/adat/adat.c +++ b/rigs/adat/adat.c @@ -3706,7 +3706,7 @@ DECLARE_PROBERIG_BACKEND(adat) } port->write_delay = port->post_write_delay = 10; - port->parm.serial.stop_bits = 0; + port->parm.serial.stop_bits = 2; port->retry = 1; diff --git a/rigs/yaesu/yaesu.c b/rigs/yaesu/yaesu.c index 09296e00..9a7b8cb5 100644 --- a/rigs/yaesu/yaesu.c +++ b/rigs/yaesu/yaesu.c @@ -134,7 +134,7 @@ DECLARE_PROBERIG_BACKEND(yaesu) static const unsigned char cmd[YAESU_CMD_LENGTH] = { 0x00, 0x00, 0x00, 0x00, 0xfa}; int id_len = -1, i, id1, id2; int retval = -1; - int rates[] = { 4800, 57600, 9600, 38400, 0 }; /* possible baud rates */ + static const int rates[] = { 4800, 57600, 9600, 38400, 0 }; /* possible baud rates */ int rates_idx; if (!port) @@ -159,6 +159,7 @@ DECLARE_PROBERIG_BACKEND(yaesu) port->parm.serial.rate = rates[rates_idx]; port->timeout = 2 * 1000 / rates[rates_idx] + 50; + printf("Yaesu trying rate = %d\n", rates[rates_idx]); retval = serial_open(port); if (retval != RIG_OK) @@ -172,9 +173,9 @@ DECLARE_PROBERIG_BACKEND(yaesu) close(port->fd); - if (retval != RIG_OK || id_len < 0) + if (retval == RIG_OK && id_len > 0) { - continue; + break; } } commit a3ab4a4312a76e2b8eca9b0e088988bfb0083bc6 Author: Wouter van Gulik <pa...@gm...> Date: Mon Sep 20 22:10:55 2021 +0200 Fix rig_cookie: use lock for reads and write. Ensure we never print more then HAMLIB_COOKIE_SIZE otherwise we read out-of-bounds. Drop stray printf. Add tests for invalid input and overly large input. Fix test2 to release the cookie. diff --git a/src/rig.c b/src/rig.c index 3ef58153..5c4ab9aa 100644 --- a/src/rig.c +++ b/src/rig.c @@ -6791,16 +6791,16 @@ int HAMLIB_API rig_cookie(RIG *rig, enum cookie_e cookie_cmd, char *cookie, // only 1 client can have the cookie so these can be static // this should also prevent problems with DLLs & shared libraies // the debug_msg is another non-thread-safe which this will help fix - // 27 char cookie will last until the year 10000 static char - cookie_save[HAMLIB_COOKIE_SIZE]; // only one client can have the 26-char cookie + cookie_save[HAMLIB_COOKIE_SIZE]; // only one client can have the cookie static double time_last_used; - double time_curr; struct timespec tp; + int ret; #ifdef HAVE_PTHREAD static pthread_mutex_t cookie_lock = PTHREAD_MUTEX_INITIALIZER; #endif + /* This is not needed for RIG_COOKIE_RELEASE but keep it simple. */ if (cookie_len < HAMLIB_COOKIE_SIZE) { rig_debug(RIG_DEBUG_ERR, "%s(%d): cookie_len < %d\n", @@ -6815,6 +6815,12 @@ int HAMLIB_API rig_cookie(RIG *rig, enum cookie_e cookie_cmd, char *cookie, return -RIG_EINVAL; // nothing to do } + /* Accesing cookie_save and time_last_used must be done with lock held. + * So keep code simple and lock it during the whole operation. */ +#ifdef HAVE_PTHREAD + pthread_mutex_lock(&cookie_lock); +#endif + switch (cookie_cmd) { case RIG_COOKIE_RELEASE: @@ -6824,14 +6830,14 @@ int HAMLIB_API rig_cookie(RIG *rig, enum cookie_e cookie_cmd, char *cookie, rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): %s cookie released\n", __FILE__, __LINE__, cookie_save); memset(cookie_save, 0, sizeof(cookie_save)); - return RIG_OK; + ret = RIG_OK; } else // not the right cookie!! { rig_debug(RIG_DEBUG_ERR, "%s(%d): %s can't release cookie as cookie %s is active\n", __FILE__, __LINE__, cookie, cookie_save); - return -RIG_BUSBUSY; + ret = -RIG_BUSBUSY; } break; @@ -6847,13 +6853,15 @@ int HAMLIB_API rig_cookie(RIG *rig, enum cookie_e cookie_cmd, char *cookie, __LINE__, cookie); clock_gettime(CLOCK_REALTIME, &tp); time_last_used = tp.tv_sec + tp.tv_nsec / 1e9; - return RIG_OK; + ret = RIG_OK; + } + else + { + rig_debug(RIG_DEBUG_ERR, + "%s(%d): %s renew request refused %s is active\n", + __FILE__, __LINE__, cookie, cookie_save); + ret = -RIG_EINVAL; // wrong cookie } - - rig_debug(RIG_DEBUG_ERR, - "%s(%d): %s renew request refused %s is active\n", - __FILE__, __LINE__, cookie, cookie_save); - return -RIG_EINVAL; // wrong cookie break; @@ -6864,48 +6872,48 @@ int HAMLIB_API rig_cookie(RIG *rig, enum cookie_e cookie_cmd, char *cookie, // we are just allow for a crashed client that fails to release:q clock_gettime(CLOCK_REALTIME, &tp); - time_curr = tp.tv_sec + tp.tv_nsec / 1e9; - -#ifdef HAVE_PTHREAD - pthread_mutex_lock(&cookie_lock); -#endif + double time_curr = tp.tv_sec + tp.tv_nsec / 1e9; if (cookie_save[0] != 0 && (strcmp(cookie_save, cookie) == 0) && (time_curr - time_last_used < 1)) // then we will deny the request { - printf("Cookie %s in use\n", cookie_save); rig_debug(RIG_DEBUG_ERR, "%s(%d): %s cookie is in use\n", __FILE__, __LINE__, cookie_save); -#ifdef HAVE_PTHREAD - pthread_mutex_unlock(&cookie_lock); -#endif - return -RIG_BUSBUSY; + ret = -RIG_BUSBUSY; } - - - if (cookie_save[0] != 0) + else { - rig_debug(RIG_DEBUG_ERR, + if (cookie_save[0] != 0) + { + rig_debug(RIG_DEBUG_ERR, "%s(%d): %s cookie has expired after %.3f seconds....overriding with new cookie\n", __FILE__, __LINE__, cookie_save, time_curr - time_last_used); + } + + date_strget(cookie, cookie_len); + size_t len = strlen(cookie); + // add on our random number to ensure uniqueness + // The cookie should never be longer then HAMLIB_COOKIE_SIZE + snprintf(cookie + len, HAMLIB_COOKIE_SIZE - len, " %d\n", rand()); + strcpy(cookie_save, cookie); + time_last_used = time_curr; + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): %s new cookie request granted\n", + __FILE__, __LINE__, cookie_save); + ret = RIG_OK; } + break; - date_strget(cookie_save, sizeof(cookie_save)); - // add on our random number to ensure uniqueness - snprintf(cookie, cookie_len, "%s %d\n", cookie_save, rand()); - strcpy(cookie_save, cookie); - time_last_used = time_curr; - rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): %s new cookie request granted\n", - __FILE__, __LINE__, cookie_save); -#ifdef HAVE_PTHREAD - pthread_mutex_unlock(&cookie_lock); -#endif - return RIG_OK; + default: + rig_debug(RIG_DEBUG_ERR, "%s(%d): unknown cmd!!\n'", __FILE__, __LINE__); + ret = -RIG_EPROTO; break; } - rig_debug(RIG_DEBUG_ERR, "%s(%d): unknown cmd!!\n'", __FILE__, __LINE__); - return -RIG_EPROTO; +#ifdef HAVE_PTHREAD + pthread_mutex_unlock(&cookie_lock); +#endif + return ret; + } HAMLIB_EXPORT(void) sync_callback(int lock) diff --git a/tests/testcookie.c b/tests/testcookie.c index bdb22e7b..94c5fa65 100644 --- a/tests/testcookie.c +++ b/tests/testcookie.c @@ -1,7 +1,7 @@ #include <hamlib/rig.h> // GET tests -int test1() +static int test1() { int retcode; // Normal get @@ -45,7 +45,7 @@ int test1() } // RENEW tests -int test2() +static int test2() { int retcode; char cookie[HAMLIB_COOKIE_SIZE]; @@ -72,9 +72,61 @@ int test2() if (retcode != RIG_OK) { printf("Test#2d OK\n"); } else {printf("Test#2d Failed cookie=%s\n", cookie); return 1;} +// release cookie2 again to clean up test + retcode = rig_cookie(NULL, RIG_COOKIE_RELEASE, cookie2, sizeof(cookie2)); + + if (retcode == RIG_OK) { printf("Test#2e OK\n"); } + else {printf("Test#2e Failed\n"); return 1;} return 0; } +// Input sanity checks +static int test3_invalid_input() +{ + int retcode; + char cookie[HAMLIB_COOKIE_SIZE]; + /* Make sure any value smaller then HAMLIB_COOKIE_SIZE is rejected */ + for(unsigned int i = 0; i < HAMLIB_COOKIE_SIZE; i++) + { + retcode = rig_cookie(NULL, RIG_COOKIE_GET, cookie, i); + if (retcode == -RIG_EINVAL) { printf("Test#3a OK\n"); } + else {printf("Test#3a Failed\n"); return 1;} + } + + /* Make sure a NULL cookie is ignored */ + retcode = rig_cookie(NULL, RIG_COOKIE_GET, NULL, sizeof(cookie)); + if (retcode == -RIG_EINVAL) { printf("Test#3b OK\n"); } + else {printf("Test#3b Failed\n"); return 1;} + + /* Make sure an invalid command is dropped with proto error */ + retcode = rig_cookie(NULL, RIG_COOKIE_RENEW + 1, cookie, sizeof(cookie)); + if (retcode == -RIG_EPROTO) { printf("Test#3c OK\n"); } + else {printf("Test#3c Failed\n"); return 1;} + + return 0; +} + +static int test4_large_cookie_size() +{ + int retcode; + char cookie[HAMLIB_COOKIE_SIZE * 2]; + + /* Using a larger cookie should also work */ + retcode = rig_cookie(NULL, RIG_COOKIE_GET, cookie, sizeof(cookie)); + if (retcode == RIG_OK) { printf("Test#4a OK\n"); } + else {printf("Test#4a Failed\n"); return 1;} + + /* Cookie should be smaller the maximum specified by lib */ + if (strlen(cookie) < HAMLIB_COOKIE_SIZE) { printf("Test#4b OK\n"); } + else {printf("Test#4b Failed\n"); return 1;} + + /* Release the cookie again to clean up */ + retcode = rig_cookie(NULL, RIG_COOKIE_RELEASE, cookie, sizeof(cookie)); + if (retcode == RIG_OK) { printf("Test#4c OK\n"); } + else {printf("Test#4c Failed\n"); return 1;} + + return 0; +} int main() { @@ -84,5 +136,9 @@ int main() if (test2()) { return 1; } + if (test3_invalid_input()) { return 1; } + + if (test4_large_cookie_size()) { return 1; } + return 0; } ----------------------------------------------------------------------- Summary of changes: configure.ac | 5 +-- rigs/adat/adat.c | 2 +- rigs/icom/icom.c | 5 ++- rigs/icom/icom.h | 2 +- rigs/yaesu/yaesu.c | 6 ++-- src/rig.c | 84 ++++++++++++++++++++++++++++----------------------- tests/rigctld.c | 20 ++++++------ tests/rigtestlibusb.c | 12 ++++++-- tests/testcookie.c | 60 ++++++++++++++++++++++++++++++++++-- 9 files changed, 135 insertions(+), 61 deletions(-) hooks/post-receive -- Hamlib -- Ham radio control libraries |