From 703160f5ac3a7b14cfec2e7fb629c7896e7f8f31 Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Thu, 1 Sep 2022 21:59:57 +0200 Subject: [PATCH 1/8] added android support --- host/libhackrf/src/hackrf.c | 22 ++++++++++++++++++++++ host/libhackrf/src/hackrf.h | 4 ++++ 2 files changed, 26 insertions(+) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index c9e7e5d08..61c84f033 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -754,6 +754,28 @@ int ADDCALL hackrf_open_by_serial( return hackrf_open_setup(usb_device, device); } +int ADDCALL hackrf_open_by_fd( + int fd, + hackrf_device** device) +{ + libusb_device_handle* usb_device; + + if (fd < 0) { + 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); +} + 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..5ed32e759 100644 --- a/host/libhackrf/src/hackrf.h +++ b/host/libhackrf/src/hackrf.h @@ -223,6 +223,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( From e523c92fabe06bbaa88d13dd15b664d0bc55f740 Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Thu, 1 Sep 2022 23:08:55 +0200 Subject: [PATCH 2/8] cmake bugfix --- host/hackrf-tools/src/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/host/hackrf-tools/src/CMakeLists.txt b/host/hackrf-tools/src/CMakeLists.txt index 7115151c4..16a7c76cd 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 ${FFTW_LIBRARIES}) else() LIST(APPEND TOOLS_LINK_LIBS m fftw3f) endif() From 00e9589e60c6b5ac964403f474dd094a0979b1f4 Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Thu, 1 Sep 2022 23:25:16 +0200 Subject: [PATCH 3/8] more bugfix --- host/hackrf-tools/src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host/hackrf-tools/src/CMakeLists.txt b/host/hackrf-tools/src/CMakeLists.txt index 16a7c76cd..955956919 100644 --- a/host/hackrf-tools/src/CMakeLists.txt +++ b/host/hackrf-tools/src/CMakeLists.txt @@ -45,7 +45,7 @@ if(MSVC) ) LIST(APPEND TOOLS_LINK_LIBS ${FFTW_LIBRARIES}) elseif(ANDROID) - LIST(APPEND TOOLS_LINK_LIBS ${FFTW_LIBRARIES}) + LIST(APPEND TOOLS_LINK_LIBS m ${FFTW_LIBRARIES}) else() LIST(APPEND TOOLS_LINK_LIBS m fftw3f) endif() From 42d039b87244372de141adf54229ee99d077b6ca Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Fri, 2 Sep 2022 01:46:41 +0200 Subject: [PATCH 4/8] bugfix --- host/libhackrf/src/hackrf.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index 61c84f033..3e17f082a 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 __ANDROID__ + // 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; From c07b6795451396add53131a68d9f86ca0a1ee0e7 Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Fri, 2 Sep 2022 20:45:52 +0200 Subject: [PATCH 5/8] added missing chedk --- host/libhackrf/src/hackrf.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index 3e17f082a..4b0027bf9 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -769,6 +769,10 @@ int ADDCALL hackrf_open_by_fd( 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; From 2c836065a5b7952913e8d25a912d904ddd3ab435 Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Sat, 3 Sep 2022 15:24:45 +0200 Subject: [PATCH 6/8] modifications --- host/libhackrf/CMakeLists.txt | 5 +++++ host/libhackrf/src/hackrf.c | 6 +++++- host/libhackrf/src/hackrf.h | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/host/libhackrf/CMakeLists.txt b/host/libhackrf/CMakeLists.txt index ea3601840..b15248167 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_ENUMERATION "Prevent libusb from trying to enumerate devices. Useful on non-root android" OFF) +if (DISABLE_USB_ENUMERATION) + add_definitions(-DDISABLE_USB_ENUMERATION) +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 4b0027bf9..7fedb54b7 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -415,7 +415,7 @@ int ADDCALL hackrf_init(void) return HACKRF_SUCCESS; } -#ifdef __ANDROID__ +#ifdef DISABLE_USB_ENUMERATION // LibUSB does not support device discovery on android libusb_set_option(NULL, LIBUSB_OPTION_NO_DEVICE_DISCOVERY, NULL); #endif @@ -763,6 +763,7 @@ int ADDCALL hackrf_open_by_fd( int fd, hackrf_device** device) { +#ifndef _WIN32 libusb_device_handle* usb_device; if (fd < 0) { @@ -783,6 +784,9 @@ int ADDCALL hackrf_open_by_fd( } return hackrf_open_setup(usb_device, device); +#else + return HACKRF_ERROR_UNSUPPORTED; +#endif } int ADDCALL hackrf_device_list_open( diff --git a/host/libhackrf/src/hackrf.h b/host/libhackrf/src/hackrf.h index 5ed32e759..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, From a5534372b8cb5aa4bec6a0a9beb9e995cbc71096 Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Tue, 31 Jan 2023 02:07:08 +0100 Subject: [PATCH 7/8] Rename option in cmake file --- host/libhackrf/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/host/libhackrf/CMakeLists.txt b/host/libhackrf/CMakeLists.txt index b15248167..e1d2a00dd 100644 --- a/host/libhackrf/CMakeLists.txt +++ b/host/libhackrf/CMakeLists.txt @@ -33,9 +33,9 @@ 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_ENUMERATION "Prevent libusb from trying to enumerate devices. Useful on non-root android" OFF) -if (DISABLE_USB_ENUMERATION) - add_definitions(-DDISABLE_USB_ENUMERATION) +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) From b1275e9c240b64cd7a8fd9bac70d77a8dd957616 Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Tue, 31 Jan 2023 02:08:12 +0100 Subject: [PATCH 8/8] Renamed option in library code --- host/libhackrf/src/hackrf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index 7fedb54b7..1f3200f76 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -415,7 +415,7 @@ int ADDCALL hackrf_init(void) return HACKRF_SUCCESS; } -#ifdef DISABLE_USB_ENUMERATION +#ifdef DISABLE_USB_DEVICE_DISCOVERY // LibUSB does not support device discovery on android libusb_set_option(NULL, LIBUSB_OPTION_NO_DEVICE_DISCOVERY, NULL); #endif