Martin Ling 837b5ee9c8 Use a lock to prevent transfers being restarted during cancellation.
Fixes bug #916.

Previously, there was a race which could lead to a transfer being left
active after cancel_transfers() completed. This would then cause the
next prepare_transfers() call to fail, because libusb_submit_transfer()
would return an error due to the transfer already being in use.

The sequence of events that could cause this was:

1. Main thread calls hackrf_stop_rx(), which calls cancel_transfers(),
   which iterates through the 4 transfers in use and cancels them one
   by one with libusb_cancel_transfer().

2. During this time, a transfer is completed. The transfer thread calls
   hackrf_libusb_transfer_callback(), which handles the data and then
   calls libusb_submit_transfer() to resubmit that transfer.

3. Now, cancel_transfers() and hackrf_stop_rx() are completed but one
   transfer is still active.

4. The next hackrf_start_rx() call fails, because prepare_transfers()
   tries to submit a transfer which is already in use.

To fix this, we add a lock which must be held to either cancel transfers
or restart them. This ensures that only one of these actions can happen
for a given transfer; it's no longer possible for a transfer to be
cancelled and then immediately restarted.
2022-02-03 06:44:19 +00:00
..

This repository contains host software (Linux/Windows) for HackRF, a project to produce a low cost, open source software radio platform.

How to build the host software on Linux:

Prerequisites for Linux (Debian/Ubuntu):

sudo apt-get install build-essential cmake libusb-1.0-0-dev pkg-config libfftw3-dev

Build host software on Linux:

mkdir host/build
cd host/build
cmake ..
make
sudo make install
sudo ldconfig

By default this will attempt to install an udev rule to /etc/udev/rules.d to provide the usb or plugdev group access to HackRF. If your setup requires the udev rule to be installed elsewhere you can modify the path with -DUDEV_RULES_PATH=/path/to/udev.

Note: The udev rule is not installed by default for PyBOMBS installs as they do not ususally get installed with root privileges.

Clean CMake temporary files/dirs:

cd host/build
rm -rf *

How to build host software on Windows:

Prerequisites for Cygwin, MinGW, or Visual Studio:

Note for Windows build: You shall always execute hackrf-tools from Windows command shell and not from Cygwin or MinGW shell because on Cygwin/MinGW Ctrl C is not managed correctly and especially for hackrf_transfer the Ctrl C(abort) will not stop correctly and will corrupt the file.

For Cygwin:

mkdir host/build
cd host/build
cmake ../ -G "Unix Makefiles" -DCMAKE_LEGACY_CYGWIN_WIN32=1 -DLIBUSB_INCLUDE_DIR=/usr/local/include/libusb-1.0/
make
make install

For MinGW:

mkdir host/build
cd host/build
cmake ../ -G "MSYS Makefiles" -DLIBUSB_INCLUDE_DIR=/usr/local/include/libusb-1.0/
make
make install

For Visual Studio 2015 x64

Create library definition for MSVC to link to C:\fftw-3.3.5-dll64> lib /machine:x64 /def:libfftw3f-3.def

c:\hackrf\host\build> cmake ../ -G "Visual Studio 14 2015 Win64" \
-DLIBUSB_INCLUDE_DIR=c:\libusb-1.0.21\libusb \
-DLIBUSB_LIBRARIES=c:\libusb-1.0.21\MS64\dll\lib\libusb-1.0.lib \
-DTHREADS_PTHREADS_INCLUDE_DIR=c:\pthreads-w32-2-9-1-release\Pre-built.2\include \
-DTHREADS_PTHREADS_WIN32_LIBRARY=c:\pthreads-w32-2-9-1-release\Pre-built.2\lib\x64\pthreadVC2.lib \
-DFFTW_INCLUDES=C:\fftw-3.3.5-dll64 \
-DFFTW_LIBRARIES=C:\fftw-3.3.5-dll64\libfftw3f-3.lib

CMake will produce a solution file named HackRF.sln and a series of project files which can be built with msbuild as follows: c:\hackrf\host\build> msbuild HackRF.sln

How to build host the software on FreeBSD

You can use the binary package: # pkg install hackrf

You can build and install from ports:

# cd /usr/ports/comms/hackrf
# make install

principal author: Michael Ossmann mike@ossmann.com

http://greatscottgadgets.com/hackrf/