commit rtl-sdr for openSUSE:Factory
Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package rtl-sdr for openSUSE:Factory checked in at 2021-07-31 18:51:27 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rtl-sdr (Old) and /work/SRC/openSUSE:Factory/.rtl-sdr.new.1899 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "rtl-sdr" Sat Jul 31 18:51:27 2021 rev:8 rq:909511 version:0.6.0 Changes: -------- --- /work/SRC/openSUSE:Factory/rtl-sdr/rtl-sdr.changes 2018-08-31 10:45:00.135242690 +0200 +++ /work/SRC/openSUSE:Factory/.rtl-sdr.new.1899/rtl-sdr.changes 2021-07-31 18:52:29.758451151 +0200 @@ -1,0 +2,44 @@ +Thu Jul 22 09:07:26 UTC 2021 - Wojciech Kazubski <wk@ire.pw.edu.pl> + +- patches: + rtl-sdr-0003-disable-zerocopy-by-default.patch + rtl-sdr-0007-allow-build-rtlsdr-as-subroject.patch + rtl-sdr-0008-add-CMP0075-policy.patch + rtl-sdr-0016-add-missing-rtlsdrConfig.patch + rtl-sdr-0017-add-rtl_biast-as-install-target.patch + rtl-sdr-0018-fix-for-older-cmake.patch + merged into rtl-sdr-0015-modernize-cmake-usage.patch +- patch rtl-sdr-0005-add-rtlsdr_set_bias_tee_gpio.patch + merged into rtl-sdr-0006-add-rtl_biast.patch + +------------------------------------------------------------------- +Tue Jul 6 10:55:44 UTC 2021 - Wojciech Kazubski <wk@ire.pw.edu.pl> + +- Added patches to upgrade to latest git head (only significant + changes), including: + + rtl-sdr-0001-mmap-bug-arm.patch + + rtl-sdr-0002-fix-rtlsdr_open-memory-leak.patch + + rtl-sdr-0003-disable-zerocopy-by-default.patch + + rtl-sdr-0004-fix-rtl_eeprom-warnings.patch + + rtl-sdr-0005-add-rtlsdr_set_bias_tee_gpio.patch + + rtl-sdr-0006-add-rtl_biast.patch + + rtl-sdr-0007-allow-build-rtlsdr-as-subroject.patch + + rtl-sdr-0008-add-CMP0075-policy.patch + + rtl-sdr-0009-fix-FC0013-UHF-reception.patch + + rtl-sdr-0010-improve-librtlsdr_pc.patch + + rtl-sdr-0011-improve-rtl_power--scanning-range-parsing.patch + + rtl-sdr-0012-use-udev-uaccess_rules.patch (not used) + + rtl-sdr-0013-add-IPV6-for-rtl_tcp.patch + + rtl-sdr-0014-initialize-listensocket_in-rtl_tcp.patch + + rtl-sdr-0015-modernize-cmake-usage.patch + + rtl-sdr-0016-add-missing-rtlsdrConfig.patch + + rtl-sdr-0017-add-rtl_biast-as-install-target.patch + + rtl-sdr-0018-fix-for-older-cmake.patch + + rtl-sdr-0019-fix-short-write-in-r82xx_read.patch + + rtl-sdr-0020-populate-pkgconfig-with-prefix.patch + * Full bias tee support for RTL-SDR v3 dongle + * Command line utility rtl_biast for controlling bias tee + * IPV-6 support for rtl_tcp + * Fixed some bugs and compile time issues + +------------------------------------------------------------------- New: ---- rtl-sdr-0001-mmap-bug-arm.patch rtl-sdr-0002-fix-rtlsdr_open-memory-leak.patch rtl-sdr-0004-fix-rtl_eeprom-warnings.patch rtl-sdr-0006-add-rtl_biast.patch rtl-sdr-0009-fix-FC0013-UHF-reception.patch rtl-sdr-0010-improve-librtlsdr_pc.patch rtl-sdr-0011-improve-rtl_power--scanning-range-parsing.patch rtl-sdr-0013-add-IPV6-for-rtl_tcp.patch rtl-sdr-0014-initialize-listensocket_in-rtl_tcp.patch rtl-sdr-0015-modernize-cmake-usage.patch rtl-sdr-0019-fix-short-write-in-r82xx_read.patch ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rtl-sdr.spec ++++++ --- /var/tmp/diff_new_pack.j6Wp29/_old 2021-07-31 18:52:30.146450688 +0200 +++ /var/tmp/diff_new_pack.j6Wp29/_new 2021-07-31 18:52:30.146450688 +0200 @@ -1,6 +1,7 @@ # # spec file for package rtl-sdr # +# Copyright (c) 2021 SUSE LLC # Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties @@ -19,6 +20,7 @@ %define sover 0 %define libname librtlsdr%{sover} %define rtlsdr_group rtlsdr + Name: rtl-sdr Version: 0.6.0 Release: 0 @@ -29,7 +31,19 @@ #Git-Clone: https://git.osmocom.org/rtl-sdr Source: https://github.com/steve-m/librtlsdr/archive/%{version}.tar.gz#/%{name}-%{version}.tar.gz Patch0: 0001-Better-udev-handling.patch -BuildRequires: cmake +Patch1: rtl-sdr-0001-mmap-bug-arm.patch +Patch2: rtl-sdr-0002-fix-rtlsdr_open-memory-leak.patch +Patch4: rtl-sdr-0004-fix-rtl_eeprom-warnings.patch +Patch6: rtl-sdr-0006-add-rtl_biast.patch +Patch9: rtl-sdr-0009-fix-FC0013-UHF-reception.patch +Patch10: rtl-sdr-0010-improve-librtlsdr_pc.patch +Patch11: rtl-sdr-0011-improve-rtl_power--scanning-range-parsing.patch +Patch13: rtl-sdr-0013-add-IPV6-for-rtl_tcp.patch +Patch14: rtl-sdr-0014-initialize-listensocket_in-rtl_tcp.patch +Patch15: rtl-sdr-0015-modernize-cmake-usage.patch +Patch19: rtl-sdr-0019-fix-short-write-in-r82xx_read.patch +BuildRequires: cmake >= 3.7.2 +BuildRequires: gcc-c++ BuildRequires: pkgconfig BuildRequires: pkgconfig(libusb-1.0) BuildRequires: pkgconfig(udev) @@ -64,6 +78,17 @@ %prep %setup -q -n librtlsdr-%{version} +%patch1 -p1 +%patch2 -p1 +%patch4 -p1 +%patch6 -p1 +%patch9 -p1 +%patch10 -p1 +%patch11 -p1 +%patch13 -p1 +%patch14 -p1 +%patch15 -p1 +%patch19 -p1 %patch0 -p1 %build @@ -72,6 +97,7 @@ -DUDEV_RULES_PATH=%{_udevrulesdir} \ -DUDEV_RULES_GROUP=%{rtlsdr_group} \ -DDETACH_KERNEL_DRIVER=ON \ + -DENABLE_ZEROCOPY=ON \ -Wno-dev %make_jobs @@ -95,6 +121,7 @@ %license COPYING %doc AUTHORS README %{_bindir}/rtl_adsb +%{_bindir}/rtl_biast %{_bindir}/rtl_eeprom %{_bindir}/rtl_fm %{_bindir}/rtl_power @@ -113,5 +140,6 @@ %{_includedir}/rtl-sdr.h %{_includedir}/rtl-sdr_export.h %{_libdir}/pkgconfig/librtlsdr.pc +%{_libdir}/cmake/rtlsdr %changelog ++++++ rtl-sdr-0001-mmap-bug-arm.patch ++++++ From f68bb2fa772ad94f58c59babd78353667570630b Mon Sep 17 00:00:00 2001 From: Steve Markgraf <steve@steve-m.de> Date: Sun, 7 Oct 2018 01:16:07 +0200 Subject: [PATCH] lib: Add workaround for Linux usbfs mmap() bug The Linux Kernel has a bug on ARM/ARM64 systems where the USB CMA memory is incorrectly mapped to userspace, breaking zerocopy. When the Kernel allocates the memory, it clears it with memset(). If the mapping worked correctly, we should have zeroed out buffers, if it doesn't, we get random Kernel memory. We now check for this, and fall back to buffers in userspace if that's the case. Signed-off-by: Steve Markgraf <steve@steve-m.de> --- src/librtlsdr.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/librtlsdr.c b/src/librtlsdr.c index 433ed5b..89ec903 100644 --- a/src/librtlsdr.c +++ b/src/librtlsdr.c @@ -1755,11 +1755,26 @@ static int _rtlsdr_alloc_async_buffers(rtlsdr_dev_t *dev) for (i = 0; i < dev->xfer_buf_num; ++i) { dev->xfer_buf[i] = libusb_dev_mem_alloc(dev->devh, dev->xfer_buf_len); - if (!dev->xfer_buf[i]) { + if (dev->xfer_buf[i]) { + /* Check if Kernel usbfs mmap() bug is present: if the + * mapping is correct, the buffers point to memory that + * was memset to 0 by the Kernel, otherwise, they point + * to random memory. We check if the buffers are zeroed + * and otherwise fall back to buffers in userspace. + */ + if (dev->xfer_buf[i][0] || memcmp(dev->xfer_buf[i], + dev->xfer_buf[i] + 1, + dev->xfer_buf_len - 1)) { + fprintf(stderr, "Detected Kernel usbfs mmap() " + "bug, falling back to buffers " + "in userspace\n"); + dev->use_zerocopy = 0; + break; + } + } else { fprintf(stderr, "Failed to allocate zero-copy " "buffer for transfer %d\nFalling " "back to buffers in userspace\n", i); - dev->use_zerocopy = 0; break; } ++++++ rtl-sdr-0002-fix-rtlsdr_open-memory-leak.patch ++++++ From be1d1206bfb6e6c41f7d91b20b77e20f929fa6a7 Mon Sep 17 00:00:00 2001 From: Steve Markgraf <steve@steve-m.de> Date: Tue, 16 Jul 2019 23:31:31 +0200 Subject: [PATCH] lib: fix memory leak in rtlsdr_open() Thanks to Vincent Perrier for reporting the bug. --- src/librtlsdr.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/librtlsdr.c b/src/librtlsdr.c index 89ec903..d72a0f5 100644 --- a/src/librtlsdr.c +++ b/src/librtlsdr.c @@ -1628,6 +1628,9 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index) return 0; err: if (dev) { + if (dev->devh) + libusb_close(dev->devh); + if (dev->ctx) libusb_exit(dev->ctx); ++++++ rtl-sdr-0004-fix-rtl_eeprom-warnings.patch ++++++ From 3c263b745121d9f4df95fd06910a00eba98a2f11 Mon Sep 17 00:00:00 2001 From: Steve Markgraf <steve@steve-m.de> Date: Fri, 1 Nov 2019 02:18:54 +0100 Subject: [PATCH] rtl_eeprom: fix warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Account for \0 string terminator when calling strncpy(). Fixes the following GCC 9 warning: warning: ���__builtin_strncpy��� specified bound 256 equals destination size --- src/rtl_eeprom.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rtl_eeprom.c b/src/rtl_eeprom.c index f562d73..24be900 100644 --- a/src/rtl_eeprom.c +++ b/src/rtl_eeprom.c @@ -370,14 +370,14 @@ int main(int argc, char **argv) } if (manuf_str) - strncpy((char*)&conf.manufacturer, manuf_str, MAX_STR_SIZE); + strncpy((char*)&conf.manufacturer, manuf_str, MAX_STR_SIZE - 1); if (product_str) - strncpy((char*)&conf.product, product_str, MAX_STR_SIZE); + strncpy((char*)&conf.product, product_str, MAX_STR_SIZE - 1); if (serial_str) { conf.have_serial = 1; - strncpy((char*)&conf.serial, serial_str, MAX_STR_SIZE); + strncpy((char*)&conf.serial, serial_str, MAX_STR_SIZE - 1); } if (ir_endpoint != 0) ++++++ rtl-sdr-0006-add-rtl_biast.patch ++++++ diff --git a/include/rtl-sdr.h b/include/rtl-sdr.h index 3ed13ae..d64701e 100644 --- a/include/rtl-sdr.h +++ b/include/rtl-sdr.h @@ -389,6 +389,17 @@ RTLSDR_API int rtlsdr_cancel_async(rtlsdr_dev_t *dev); */ RTLSDR_API int rtlsdr_set_bias_tee(rtlsdr_dev_t *dev, int on); +/*! + * Enable or disable the bias tee on the given GPIO pin. + * + * \param dev the device handle given by rtlsdr_open() + * \param gpio the gpio pin to configure as a Bias T control. + * \param on 1 for Bias T on. 0 for Bias T off. + * \return -1 if device is not initialized. 0 otherwise. + */ +RTLSDR_API int rtlsdr_set_bias_tee_gpio(rtlsdr_dev_t *dev, int gpio, int on); + + #ifdef __cplusplus } #endif diff --git a/src/librtlsdr.c b/src/librtlsdr.c index 213e96c..0146298 100644 --- a/src/librtlsdr.c +++ b/src/librtlsdr.c @@ -2009,13 +2009,18 @@ int rtlsdr_i2c_read_fn(void *dev, uint8_t addr, uint8_t *buf, int len) return -1; } -int rtlsdr_set_bias_tee(rtlsdr_dev_t *dev, int on) +int rtlsdr_set_bias_tee_gpio(rtlsdr_dev_t *dev, int gpio, int on) { if (!dev) return -1; - rtlsdr_set_gpio_output(dev, 0); - rtlsdr_set_gpio_bit(dev, 0, on); + rtlsdr_set_gpio_output(dev, gpio); + rtlsdr_set_gpio_bit(dev, gpio, on); return 0; } + +int rtlsdr_set_bias_tee(rtlsdr_dev_t *dev, int on) +{ + return rtlsdr_set_bias_tee_gpio(dev, 0, on); +} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 015fd48..8713fba 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -91,7 +91,8 @@ add_executable(rtl_fm rtl_fm.c) add_executable(rtl_eeprom rtl_eeprom.c) add_executable(rtl_adsb rtl_adsb.c) add_executable(rtl_power rtl_power.c) -set(INSTALL_TARGETS rtlsdr_shared rtlsdr_static rtl_sdr rtl_tcp rtl_test rtl_fm rtl_eeprom rtl_adsb rtl_power) +add_executable(rtl_biast rtl_biast.c) +set(INSTALL_TARGETS rtlsdr_shared rtlsdr_static rtl_sdr rtl_tcp rtl_test rtl_fm rtl_eeprom rtl_adsb rtl_power rtl_biast) target_link_libraries(rtl_sdr rtlsdr_shared convenience_static ${LIBUSB_LIBRARIES} @@ -121,6 +122,11 @@ target_link_libraries(rtl_power rtlsdr_shared convenience_static ${LIBUSB_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ) +target_link_libraries(rtl_biast rtlsdr_shared convenience_static + ${LIBUSB_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT} +) + if(UNIX) target_link_libraries(rtl_fm m) target_link_libraries(rtl_adsb m) diff --git a/src/rtl_biast.c b/src/rtl_biast.c new file mode 100644 index 0000000..185e838 --- /dev/null +++ b/src/rtl_biast.c @@ -0,0 +1,101 @@ +/* + * rtl-sdr, turns your Realtek RTL2832 based DVB dongle into a SDR receiver + * rtl_biast, tool to set bias tee gpio output + * Copyright (C) 2012 by Steve Markgraf <steve@steve-m.de> + * + * 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, see <http://www.gnu.org/licenses/>. + */ + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> + +#ifndef _WIN32 +#include <unistd.h> +#else +#include <windows.h> +#include "getopt/getopt.h" +#endif + +#include "rtl-sdr.h" +#include "convenience/convenience.h" + +static rtlsdr_dev_t *dev = NULL; + +void usage(void) +{ + fprintf(stderr, + "rtl_biast, a tool for turning the RTL-SDR.com \n" + "bias tee or any GPIO ON and OFF. Example to turn on the \n" + "bias tee: rtl_biast -d 0 -b 1\n" + "Any GPIO: rtl_biast -d 0 -g 1 -b 1\n\n" + "Usage:\n" + "\t[-d device_index (default: 0)]\n" + "\t[-b bias_on (default: 0)]\n" + "\t[-g GPIO select (default: 0)]\n"); + exit(1); +} + +int main(int argc, char **argv) +{ + int i, r, opt; + int dev_index = 0; + int dev_given = 0; + uint32_t bias_on = 0; + uint32_t gpio_pin = 0; + int device_count; + + while ((opt = getopt(argc, argv, "d:b:g:h?")) != -1) { + switch (opt) { + case 'd': + dev_index = verbose_device_search(optarg); + dev_given = 1; + break; + case 'b': + bias_on = atoi(optarg); + break; + case 'g': + gpio_pin = atoi(optarg); + break; + default: + usage(); + break; + } + } + + if (!dev_given) { + dev_index = verbose_device_search("0"); + } + + if (dev_index < 0) { + exit(1); + } + + r = rtlsdr_open(&dev, dev_index); + rtlsdr_set_bias_tee_gpio(dev, gpio_pin, bias_on); + +exit: + /* + * Note - rtlsdr_close() in this tree does not clear the bias tee + * GPIO line, so it leaves the bias tee enabled if a client program + * doesn't explictly disable it. + * + * If that behaviour changes then another rtlsdr_close() will be + * needed that takes some extension flags, and one of them should + * be to either explicitly close the biast or leave it alone. + */ + rtlsdr_close(dev); + + return r >= 0 ? r : -r; +} ++++++ rtl-sdr-0009-fix-FC0013-UHF-reception.patch ++++++ From 1dff8e0b4c5681cf2cbc6d4ab0aa0bee30c5ed09 Mon Sep 17 00:00:00 2001 From: Benjamin Larsson <banan@ludd.ltu.se> Date: Mon, 17 Feb 2020 01:20:24 +0100 Subject: [PATCH] lib: enable better UHF reception (>862MHz) for FC0013 --- src/tuner_fc0013.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tuner_fc0013.c b/src/tuner_fc0013.c index 78b696e..5984dfb 100644 --- a/src/tuner_fc0013.c +++ b/src/tuner_fc0013.c @@ -248,11 +248,11 @@ int fc0013_set_params(void *dev, uint32_t freq, uint32_t bandwidth) if (ret) goto exit; - /* disable UHF & enable GPS */ + /* enable UHF & disable GPS */ ret = fc0013_readreg(dev, 0x14, &tmp); if (ret) goto exit; - ret = fc0013_writereg(dev, 0x14, (tmp & 0x1f) | 0x20); + ret = fc0013_writereg(dev, 0x14, (tmp & 0x1f) | 0x40); if (ret) goto exit; } ++++++ rtl-sdr-0010-improve-librtlsdr_pc.patch ++++++ From 222517b506278178ab93182d79ccf7eb04d107ce Mon Sep 17 00:00:00 2001 From: "A. Maitland Bottoms" <bottoms@debian.org> Date: Sun, 8 May 2016 18:57:29 -0400 Subject: [PATCH] Improve librtlsdr.pc file librtlsdr.pc should declare -lusb-1.0 in Libs.private section to exclude usb library from dynamic linking. References to libusb headers are not needed in Cflags, since these headers are not used by external rtlsdr API, but this is optional. https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=784912 --- librtlsdr.pc.in | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/librtlsdr.pc.in b/librtlsdr.pc.in index 5e55049..e46519a 100644 --- a/librtlsdr.pc.in +++ b/librtlsdr.pc.in @@ -6,6 +6,6 @@ includedir=@includedir@ Name: RTL-SDR Library Description: C Utility Library Version: @VERSION@ -Cflags: -I${includedir}/ @RTLSDR_PC_CFLAGS@ -Libs: -L${libdir} -lrtlsdr -lusb-1.0 -Libs.private: @RTLSDR_PC_LIBS@ +Cflags: -I${includedir}/ +Libs: -L${libdir} -lrtlsdr +Libs.private: -lusb-1.0 @RTLSDR_PC_LIBS@ ++++++ rtl-sdr-0011-improve-rtl_power--scanning-range-parsing.patch ++++++ From f2a9a81c4be95a6e9da97ec784f893d98a43f289 Mon Sep 17 00:00:00 2001 From: "A. Maitland Bottoms" <bottoms@debian.org> Date: Thu, 24 Aug 2017 05:27:57 -0400 Subject: [PATCH] rtl_fm/rtl_power: Improve scanning range parsing --- src/rtl_fm.c | 13 +++++++++++++ src/rtl_power.c | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/src/rtl_fm.c b/src/rtl_fm.c index b163979..283542d 100644 --- a/src/rtl_fm.c +++ b/src/rtl_fm.c @@ -926,8 +926,21 @@ void frequency_range(struct controller_state *s, char *arg) int i; start = arg; stop = strchr(start, ':') + 1; + if (stop == (char *)1) { // no stop or step given + s->freqs[s->freq_len] = (uint32_t) atofs(start); + s->freq_len++; + return; + } stop[-1] = '\0'; step = strchr(stop, ':') + 1; + if (step == (char *)1) { // no step given + s->freqs[s->freq_len] = (uint32_t) atofs(start); + s->freq_len++; + s->freqs[s->freq_len] = (uint32_t) atofs(stop); + s->freq_len++; + stop[-1] = ':'; + return; + } step[-1] = '\0'; for(i=(int)atofs(start); i<=(int)atofs(stop); i+=(int)atofs(step)) { diff --git a/src/rtl_power.c b/src/rtl_power.c index 625d818..6204de2 100644 --- a/src/rtl_power.c +++ b/src/rtl_power.c @@ -437,8 +437,16 @@ void frequency_range(char *arg, double crop) /* hacky string parsing */ start = arg; stop = strchr(start, ':') + 1; + if (stop == (char *)1) { + fprintf(stderr, "Bad frequency range specification: %s\n", arg); + exit(1); + } stop[-1] = '\0'; step = strchr(stop, ':') + 1; + if (step == (char *)1) { + fprintf(stderr, "Bad frequency range specification: %s\n", arg); + exit(1); + } step[-1] = '\0'; lower = (int)atofs(start); upper = (int)atofs(stop); ++++++ rtl-sdr-0013-add-IPV6-for-rtl_tcp.patch ++++++ From 8985b45e1fe1a5d50c5e1dc4c7c306705e602445 Mon Sep 17 00:00:00 2001 From: "A. Maitland Bottoms" <bottoms@debian.org> Date: Sun, 3 Sep 2017 16:22:55 -0400 Subject: [PATCH] rtl_tcp: Add IPv6 support I've prepared this patch in response to Debian bug #870804 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=870804 It passes the text from the -a and -p options through getaddrinfo() and uses the first result that has a valid socket with a successful bind. While not a complete bind to all possible valid names, it does appear to address the use case of the bug submitter without completely changing the program flow. --- src/rtl_tcp.c | 72 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 17 deletions(-) diff --git a/src/rtl_tcp.c b/src/rtl_tcp.c index da6057b..42b90cb 100644 --- a/src/rtl_tcp.c +++ b/src/rtl_tcp.c @@ -30,6 +30,7 @@ #include <sys/types.h> #include <sys/socket.h> #include <sys/time.h> +#include <netdb.h> #include <netinet/in.h> #include <fcntl.h> #else @@ -371,10 +372,18 @@ static void *command_worker(void *arg) int main(int argc, char **argv) { int r, opt, i; - char* addr = "127.0.0.1"; - int port = 1234; + char *addr = "127.0.0.1"; + char *port = "1234"; uint32_t frequency = 100000000, samp_rate = 2048000; - struct sockaddr_in local, remote; + struct sockaddr_storage local, remote; + struct addrinfo *ai; + struct addrinfo *aiHead; + struct addrinfo hints; + char hostinfo[NI_MAXHOST]; + char portinfo[NI_MAXSERV]; + char remhostinfo[NI_MAXHOST]; + char remportinfo[NI_MAXSERV]; + int aiErr; uint32_t buf_num = 0; int dev_index = 0; int dev_given = 0; @@ -413,10 +422,10 @@ int main(int argc, char **argv) samp_rate = (uint32_t)atofs(optarg); break; case 'a': - addr = optarg; + addr = strdup(optarg); break; case 'p': - port = atoi(optarg); + port = strdup(optarg); break; case 'b': buf_num = atoi(optarg); @@ -515,16 +524,42 @@ int main(int argc, char **argv) pthread_cond_init(&cond, NULL); pthread_cond_init(&exit_cond, NULL); - memset(&local,0,sizeof(local)); - local.sin_family = AF_INET; - local.sin_port = htons(port); - local.sin_addr.s_addr = inet_addr(addr); + hints.ai_flags = AI_PASSIVE; /* Server mode. */ + hints.ai_family = PF_UNSPEC; /* IPv4 or IPv6. */ + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + + if ((aiErr = getaddrinfo(addr, + port, + &hints, + &aiHead )) != 0) + { + fprintf(stderr, "local address %s ERROR - %s.\n", + addr, gai_strerror(aiErr)); + return(-1); + } + memcpy(&local, aiHead->ai_addr, aiHead->ai_addrlen); + + for (ai = aiHead; ai != NULL; ai = ai->ai_next) { + aiErr = getnameinfo((struct sockaddr *)ai->ai_addr, ai->ai_addrlen, + hostinfo, NI_MAXHOST, + portinfo, NI_MAXSERV, NI_NUMERICSERV | NI_NUMERICHOST); + if (aiErr) + fprintf( stderr, "getnameinfo ERROR - %s.\n",hostinfo); + + listensocket = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); + if (listensocket < 0) + continue; + + r = 1; + setsockopt(listensocket, SOL_SOCKET, SO_REUSEADDR, (char *)&r, sizeof(int)); + setsockopt(listensocket, SOL_SOCKET, SO_LINGER, (char *)&ling, sizeof(ling)); - listensocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - r = 1; - setsockopt(listensocket, SOL_SOCKET, SO_REUSEADDR, (char *)&r, sizeof(int)); - setsockopt(listensocket, SOL_SOCKET, SO_LINGER, (char *)&ling, sizeof(ling)); - bind(listensocket,(struct sockaddr *)&local,sizeof(local)); + if (bind(listensocket, (struct sockaddr *)&local, sizeof(local))) + fprintf(stderr, "rtl_tcp bind error: %s", strerror(errno)); + else + break; + } #ifdef _WIN32 ioctlsocket(listensocket, FIONBIO, &blockmode); @@ -535,11 +570,11 @@ int main(int argc, char **argv) while(1) { printf("listening...\n"); - printf("Use the device argument 'rtl_tcp=%s:%d' in OsmoSDR " + printf("Use the device argument 'rtl_tcp=%s:%s' in OsmoSDR " "(gr-osmosdr) source\n" "to receive samples in GRC and control " "rtl_tcp parameters (frequency, gain, ...).\n", - addr, port); + hostinfo, portinfo); listen(listensocket,1); while(1) { @@ -559,7 +594,10 @@ int main(int argc, char **argv) setsockopt(s, SOL_SOCKET, SO_LINGER, (char *)&ling, sizeof(ling)); - printf("client accepted!\n"); + getnameinfo((struct sockaddr *)&remote, rlen, + remhostinfo, NI_MAXHOST, + remportinfo, NI_MAXSERV, NI_NUMERICSERV); + printf("client accepted! %s %s\n", remhostinfo, remportinfo); memset(&dongle_info, 0, sizeof(dongle_info)); memcpy(&dongle_info.magic, "RTL0", 4); ++++++ rtl-sdr-0014-initialize-listensocket_in-rtl_tcp.patch ++++++ From f427883320cbb65e254644717f5d7963e37bbd1d Mon Sep 17 00:00:00 2001 From: Steve Markgraf <steve@steve-m.de> Date: Wed, 26 Feb 2020 23:52:02 +0100 Subject: [PATCH] rtl_tcp: Initialize listensocket Older versions of GCC will complain that it can be used uninitialized - which is not the case, but it breaks our Jenkins build as we build with -Werror. --- src/rtl_tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rtl_tcp.c b/src/rtl_tcp.c index 42b90cb..562198f 100644 --- a/src/rtl_tcp.c +++ b/src/rtl_tcp.c @@ -394,7 +394,7 @@ int main(int argc, char **argv) void *status; struct timeval tv = {1,0}; struct linger ling = {1,0}; - SOCKET listensocket; + SOCKET listensocket = 0; socklen_t rlen; fd_set readfds; u_long blockmode = 1; ++++++ rtl-sdr-0015-modernize-cmake-usage.patch ++++++ ++++ 714 lines (skipped) ++++++ rtl-sdr-0019-fix-short-write-in-r82xx_read.patch ++++++ From d794155ba65796a76cd0a436f9709f4601509320 Mon Sep 17 00:00:00 2001 From: Derrick Pallas <derrick@pallas.us> Date: Wed, 18 Mar 2020 14:54:48 -0700 Subject: [PATCH] tuner_r82xx: fix short-write in r82xx_read In r82xx_read, there is a 1-byte I2C write followed by the I2C read. If this I2C write fails, r82xx_read correctly bails out but may return 0. Callers that check whether (rc < 0) will assume that the buffer was written when it has not been, e.g. in r82xx_set_tv_standard where priv->fil_cal_code = data[4] & 0x0f; consumes a garbage value for data[4]. This change resolves that issue by copying the error path from r82xx_write. --- src/tuner_r82xx.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/tuner_r82xx.c b/src/tuner_r82xx.c index fe52bd9..997abd7 100644 --- a/src/tuner_r82xx.c +++ b/src/tuner_r82xx.c @@ -330,8 +330,14 @@ static int r82xx_read(struct r82xx_priv *priv, uint8_t reg, uint8_t *val, int le priv->buf[0] = reg; rc = rtlsdr_i2c_write_fn(priv->rtl_dev, priv->cfg->i2c_addr, priv->buf, 1); - if (rc < 1) - return rc; + + if (rc != 1) { + fprintf(stderr, "%s: i2c wr failed=%d reg=%02x len=%d\n", + __FUNCTION__, rc, reg, 1); + if (rc < 0) + return rc; + return -1; + } rc = rtlsdr_i2c_read_fn(priv->rtl_dev, priv->cfg->i2c_addr, p, len);
participants (1)
-
Source-Sync