diff --git a/host/hackrf-tools/src/CMakeLists.txt b/host/hackrf-tools/src/CMakeLists.txt index 7115151c4..955956919 100644 --- a/host/hackrf-tools/src/CMakeLists.txt +++ b/host/hackrf-tools/src/CMakeLists.txt @@ -44,6 +44,8 @@ if(MSVC) ../getopt/getopt.c ) LIST(APPEND TOOLS_LINK_LIBS ${FFTW_LIBRARIES}) +elseif(ANDROID) + LIST(APPEND TOOLS_LINK_LIBS m ${FFTW_LIBRARIES}) else() LIST(APPEND TOOLS_LINK_LIBS m fftw3f) endif() diff --git a/host/libhackrf/CMakeLists.txt b/host/libhackrf/CMakeLists.txt index ea3601840..e1d2a00dd 100644 --- a/host/libhackrf/CMakeLists.txt +++ b/host/libhackrf/CMakeLists.txt @@ -33,6 +33,11 @@ include(${PROJECT_SOURCE_DIR}/../cmake/set_release.cmake) add_definitions(-DLIBRARY_RELEASE="${RELEASE}") set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../cmake/modules) +option(DISABLE_USB_DEVICE_DISCOVERY "Prevent libusb from trying to enumerate devices. Useful on non-root android" OFF) +if (DISABLE_USB_DEVICE_DISCOVERY) + add_definitions(-DDISABLE_USB_DEVICE_DISCOVERY) +endif() + if(MSVC) set(THREADS_USE_PTHREADS_WIN32 true) else() diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index c9e7e5d08..1f3200f76 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -415,6 +415,11 @@ int ADDCALL hackrf_init(void) return HACKRF_SUCCESS; } +#ifdef DISABLE_USB_DEVICE_DISCOVERY + // LibUSB does not support device discovery on android + libusb_set_option(NULL, LIBUSB_OPTION_NO_DEVICE_DISCOVERY, NULL); +#endif + libusb_error = libusb_init(&g_libusb_context); if (libusb_error != 0) { last_libusb_error = libusb_error; @@ -754,6 +759,36 @@ int ADDCALL hackrf_open_by_serial( return hackrf_open_setup(usb_device, device); } +int ADDCALL hackrf_open_by_fd( + int fd, + hackrf_device** device) +{ +#ifndef _WIN32 + libusb_device_handle* usb_device; + + if (fd < 0) { + return HACKRF_ERROR_INVALID_PARAM; + } + + if (device == NULL) { + return HACKRF_ERROR_INVALID_PARAM; + } + + int err = libusb_wrap_sys_device(g_libusb_context, (intptr_t)fd, &usb_device); + if (err) { + return HACKRF_ERROR_NOT_FOUND; + } + + if (usb_device == NULL) { + return HACKRF_ERROR_NOT_FOUND; + } + + return hackrf_open_setup(usb_device, device); +#else + return HACKRF_ERROR_UNSUPPORTED; +#endif +} + int ADDCALL hackrf_device_list_open( hackrf_device_list_t* list, int idx, diff --git a/host/libhackrf/src/hackrf.h b/host/libhackrf/src/hackrf.h index 0d3efc8f7..4d0c8aba2 100644 --- a/host/libhackrf/src/hackrf.h +++ b/host/libhackrf/src/hackrf.h @@ -63,6 +63,7 @@ enum hackrf_error { HACKRF_ERROR_NOT_FOUND = -5, HACKRF_ERROR_BUSY = -6, HACKRF_ERROR_NO_MEM = -11, + HACKRF_ERROR_UNSUPPORTED = -12, HACKRF_ERROR_LIBUSB = -1000, HACKRF_ERROR_THREAD = -1001, HACKRF_ERROR_STREAMING_THREAD_ERR = -1002, @@ -223,6 +224,10 @@ extern ADDAPI int ADDCALL hackrf_open_by_serial( const char* const desired_serial_number, hackrf_device** device); +extern ADDAPI int ADDCALL hackrf_open_by_fd( + int fd, + hackrf_device** device); + extern ADDAPI int ADDCALL hackrf_close(hackrf_device* device); extern ADDAPI int ADDCALL hackrf_start_rx(