android: Add HCI snooping tool
PATCH 1/7 android: Add HCI snooping tool
This tool is intended to be run as Android service. It supports writing HCI snoop data in old btsnoop format only. By default traffic is stored in /sdcard/btsnoop_hci.log file (can be overridded with option - mainly for testing on Linux host). Only index 0 is sniffed.
--- .gitignore | 1 + android/Android.mk | 23 +++++ android/Makefile.am | 6 ++ android/bluetoothd-snoop.c | 219 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 249 insertions(+) create mode 100644 android/bluetoothd-snoop.c
.gitignore +1 -0
@@ -109,3 +109,4 @@ android/system-emulator android/bluetoothd android/haltest android/android-tester +android/bluetoothd-snoop
android/Android.mk +23 -0
@@ -253,3 +253,26 @@ LOCAL_MODULE_TAGS := debug LOCAL_MODULE := l2test include $(BUILD_EXECUTABLE) + +# +# bluetoothd-snoop +# + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := \ + bluetoothd-snoop.c \ + ../monitor/mainloop.c \ + ../src/shared/btsnoop.c \ + +LOCAL_C_INCLUDES := \ + $(LOCAL_PATH)/.. \ + $(LOCAL_PATH)/../lib \ + +LOCAL_CFLAGS := $(BLUEZ_COMMON_CFLAGS) + +LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES) +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE := bluetoothd-snoop + +include $(BUILD_EXECUTABLE)
android/Makefile.am +6 -0
@@ -4,6 +4,12 @@ noinst_PROGRAMS += android/system-emulator android_system_emulator_SOURCES = android/system-emulator.c \ monitor/mainloop.h monitor/mainloop.c +noinst_PROGRAMS += android/bluetoothd-snoop + +android_bluetoothd_snoop_SOURCES = android/bluetoothd-snoop.c \ + monitor/mainloop.h monitor/mainloop.c \ + src/shared/btsnoop.h src/shared/btsnoop.c + noinst_PROGRAMS += android/bluetoothd android_bluetoothd_SOURCES = android/main.c \
android/bluetoothd-snoop.c new file +219 -0
219 lines not on this page · raw message
Signature · 1 line
1.8.5.2
PATCH 2/7 android/hal-bluetooth: Update snoop service name
Match service name with android snoop binary name. It is more common to use '-' instead of '_' in the code for binaries name.
--- android/hal-bluetooth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
android/hal-bluetooth.c +1 -1
@@ -28,7 +28,7 @@#include "hal-ipc.h" #include "hal-utils.h" -#define SNOOP_SERVICE_NAME "bluetoothd_snoop" +#define SNOOP_SERVICE_NAME "bluetoothd-snoop"static const bt_callbacks_t *bt_hal_cbacks =NULL ;
Signature · 1 line
1.8.5.2
PATCH 3/7 android: Add support for bluetoothd-snoop service in system-emulator
In reply to Szymon JancThis allows to test bluetoothd-snoop service on Linux host.
--- android/system-emulator.c | 61 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 5 deletions(-)
android/system-emulator.c +56 -5
@@ -45,6 +45,7 @@static char exec_dir[PATH_MAX +1 ];static pid_t daemon_pid =-1 ; +static pid_t snoop_pid =-1 ;static void ctl_start (void ) {
@@ -81,6 +82,47 @@ static void ctl_start(void) daemon_pid = pid; } +static void snoop_start (void ) +{ +char prg_name[PATH_MAX +1 ]; +char *prg_argv[3 ]; +char *prg_envp[1 ]; +pid_t pid; + +snprintf (prg_name,sizeof (prg_name),"%s/%s" , exec_dir, +"bluetoothd-snoop" ); + + prg_argv[0 ] = prg_name; + prg_argv[1 ] ="/tmp/btsnoop_hci.log" ; + prg_argv[2 ] =NULL ; + + prg_envp[0 ] =NULL ; + +printf ("Starting %s\n" , prg_name); + + pid =fork (); +if (pid <0 ) { +perror ("Failed to fork new process" ); +return ; + } + +if (pid ==0 ) { +execve (prg_argv[0 ], prg_argv, prg_envp); +exit (0 ); + } + +printf ("New process %d created\n" , pid); + + snoop_pid = pid; +} + +static void snoop_stop (void ) +{ +printf ("Stoping %s/%s\n" , exec_dir,"bluetoothd-snoop" ); + +kill (snoop_pid,SIGTERM ); +} +static void system_socket_callback (int fd,uint32_t events,void *user_data) {char buf[4096 ];
@@ -97,13 +139,20 @@ static void system_socket_callback(int fd, uint32_t events, void *user_data)printf ("Received %s\n" , buf); -if (strcmp (buf,"ctl.start=bluetoothd" )) -return ; +if (!strcmp (buf,"ctl.start=bluetoothd" )) { +if (daemon_pid >0 ) +return ; -if (daemon_pid >0 ) -return ; +ctl_start (); + }else if (!strcmp (buf,"ctl.start=bluetoothd-snoop" )) { +if (snoop_pid >0 ) +return ; -ctl_start (); +snoop_start (); + }else if (!strcmp (buf,"ctl.stop=bluetoothd-snoop" )) { +if (snoop_pid >0 ) +snoop_stop (); + } }static void signal_callback (int signum,void *user_data)
@@ -127,6 +176,8 @@ static void signal_callback(int signum, void *user_data)if (pid == daemon_pid) daemon_pid =-1 ; +else if (pid == snoop_pid) + snoop_pid =-1 ; }break ; }
Signature · 1 line
1.8.5.2
PATCH 4/7 android/hal-bluetooth: Add debug print to config_hci_snoop_log
In reply to Szymon JancImproves debugs and make it consistent with other methods.
--- android/hal-bluetooth.c | 2 ++ 1 file changed, 2 insertions(+)
android/hal-bluetooth.c +2 -0
@@ -829,6 +829,8 @@ static int le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t len)#if PLATFORM_SDK_VERSION >18 static int config_hci_snoop_log (uint8_t enable) { +DBG ("enable %u" , enable); +if (enable &&property_set ("ctl.start" ,SNOOP_SERVICE_NAME ) <0 ) {error ("Failed to start service %s" ,SNOOP_SERVICE_NAME );return BT_STATUS_FAIL ;
Signature · 1 line
1.8.5.2
PATCH 5/7 android/haltest: Improve EXEC macro robustness
In reply to Szymon JancPrint info about method being NULL instead of crashing.
--- android/client/if-main.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
android/client/if-main.h +6 -2
@@ -147,8 +147,12 @@ const struct method *get_interface_method(const char *iname,/* Helper macro for executing function on interface and printing BT_STATUS */ #define EXEC (f, ...) \ { \ - int err = f(__VA_ARGS__); \ - haltest_info("%s: %s\n", #f, bt_status_t2str(err)); \ + if (f) { \ + int err = f(__VA_ARGS__); \ + haltest_info("%s: %s\n", #f, bt_status_t2str(err)); \ + } else { \ + haltest_info("%s is NULL\n", #f); \ + } \ }/* Helper macro for executing void function on interface */
Signature · 1 line
1.8.5.2
PATCH 6/7 android/haltest: Implement missing functions from bluetooth HAL
In reply to Szymon JancImplement functions added in Android 4.3+ to Bluetooth HAL.
--- android/client/if-bt.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
android/client/if-bt.c +37 -0
@@ -797,6 +797,36 @@ static void dut_mode_configure_p(int argc, const char **argv)EXEC (if_bluetooth->dut_mode_configure, mode); } +static void dut_mode_send_p (int argc,const char **argv) +{ +haltest_error ("not implemented\n" ); +} + +#if PLATFORM_SDK_VERSION >17 +static void le_test_mode_p (int argc,const char **argv) +{ +haltest_error ("not implemented\n" ); +} +#endif + +#if PLATFORM_SDK_VERSION >18 +static void config_hci_snoop_log_p (int argc,const char **argv) +{ +uint8_t mode; + +RETURN_IF_NULL (if_bluetooth); + +if (argc <=2 ) { +haltest_error ("No mode specified\n" ); +return ; + } + + mode =strtol (argv[2 ],NULL ,0 ); + +EXEC (if_bluetooth->config_hci_snoop_log, mode); +} +#endif +static struct method methods[] = {STD_METHOD (init),STD_METHOD (cleanup),
@@ -820,6 +850,13 @@ static struct method methods[] = {STD_METHODCH (ssp_reply,"<address> <ssp_veriant> 1|0 [<passkey>]" ),STD_METHODCH (get_profile_interface,"<profile id>" ),STD_METHODH (dut_mode_configure,"<dut mode>" ), +STD_METHOD (dut_mode_send), +#if PLATFORM_SDK_VERSION > 17 +STD_METHOD (le_test_mode), +#endif +#if PLATFORM_SDK_VERSION > 18 +STD_METHODH (config_hci_snoop_log,"<mode>" ), +#endif END_METHOD };
Signature · 1 line
1.8.5.2
PATCH 7/7 android/build: Fix building HAL library on Linux
In reply to Szymon JancPLATFORM_SDK_VERSION was not passed while building HAL library on Linux host resulting in 4.3+ features not being build.
--- android/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
android/Makefile.am +2 -1
@@ -59,7 +59,8 @@ android_libhal_internal_la_SOURCES = android/hal.h android/hal-bluetooth.c \ android/hal-log.h \ android/hal-ipc.h android/hal-ipc.c -android_libhal_internal_la_CPPFLAGS = -I$(srcdir)/android +android_libhal_internal_la_CPPFLAGS = -I$(srcdir)/android \ + -DPLATFORM_SDK_VERSION=19 noinst_PROGRAMS += android/haltest
Signature · 1 line
1.8.5.2
Hi Szymon,
Quoted 11 lines · Szymon Janc
This tool is intended to be run as Android service. It supports writing HCI snoop data in old btsnoop format only. By default traffic is stored in /sdcard/btsnoop_hci.log file (can be overridded with option - mainly for testing on Linux host). Only index 0 is sniffed.
--- .gitignore | 1 + android/Android.mk | 23 +++++ android/Makefile.am | 6 ++ android/bluetoothd-snoop.c | 219 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 249 insertions(+) create mode 100644 android/bluetoothd-snoop.c
All patches in this set have been applied. Thanks.
Johan