From 169aa8795fb494e8711bb6e918319bf2b13fa72f Mon Sep 17 00:00:00 2001 From: Dirk Helbig Date: Thu, 2 Jun 2022 21:24:59 +0200 Subject: [PATCH] security_manager_sc: updated command line handling / support for clearing tlv storage --- test/security_manager_sc/main.c | 165 ++++++++++++++++++++++++++-- test/security_manager_sc/sm_test.c | 26 ++--- test/security_manager_sc/sm_test.py | 2 +- 3 files changed, 167 insertions(+), 26 deletions(-) diff --git a/test/security_manager_sc/main.c b/test/security_manager_sc/main.c index b7778421e..51f17da59 100644 --- a/test/security_manager_sc/main.c +++ b/test/security_manager_sc/main.c @@ -42,7 +42,8 @@ // minimal setup for HCI code // // ***************************************************************************** - +#include +#include #include #include #include @@ -73,6 +74,7 @@ #define TLV_DB_PATH_PREFIX "/tmp/btstack_" #define TLV_DB_PATH_POSTFIX ".tlv" static char tlv_db_path[100]; +static bool tlv_clear = false; static const btstack_tlv_t * tlv_impl; static btstack_tlv_posix_t tlv_context; static bd_addr_t local_addr; @@ -124,6 +126,16 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack btstack_strcpy(tlv_db_path, sizeof(tlv_db_path), TLV_DB_PATH_PREFIX); btstack_strcat(tlv_db_path, sizeof(tlv_db_path), bd_addr_to_str(local_addr)); btstack_strcat(tlv_db_path, sizeof(tlv_db_path), TLV_DB_PATH_POSTFIX); + printf("TLV path: %s", tlv_db_path); + if (tlv_clear){ + int rc = unlink(tlv_db_path); + if((rc == 0) || ( errno == ENOENT )){ + printf(", clear ok\n"); + } else { + printf(", clear failed because %s\n", strerror(errno)); + } + } + tlv_impl = btstack_tlv_posix_init_instance(&tlv_context, tlv_db_path); btstack_tlv_set_instance(tlv_impl, &tlv_context); #ifdef ENABLE_CLASSIC @@ -178,15 +190,137 @@ void hal_led_toggle(void){ printf("LED State %u\n", led_state); } +#include +static void btstack_log_cmd_line( int argc, const char *args[] ) +{ + char buf[2048] = "command line:"; + char *ptr = buf+strlen(buf); + size_t len = sizeof(buf); + for( int i=0; i= len )) + { + log_error("command line truncated!"); + break; + } + // terminate string + ptr[ret] = 0; + len -= ret; + ptr += ret; + } + log_info("%s", buf); + +} + +static const char short_options[] = "-hu:l:c"; + +static const struct option long_options[] = { + {"help", no_argument, NULL, 'h'}, + {"logfile", required_argument, NULL, 'l'}, + {"clear-tlv", no_argument, NULL, 'c'}, + {"usbpath", required_argument, NULL, 'u'}, + {0, 0, 0, 0} +}; + +static const char *help_options[] = { + "print (this) help.", + "set file to store debug output and HCI trace.", + "clear bonding information stored in TLV.", + "set USB path to Bluetooth Controller.", +}; + +static const char *option_arg_name[] = { + "", + "LOGFILE", + "", + "USBPATH", +}; + +static void usage(const char *name){ + unsigned int i; + printf( "usage:\n\t%s [options]\n", name ); + printf("valid options:\n"); + for( i=0; long_options[i].name != 0; i++) { + printf("--%-10s| -%c %-10s\t\t%s\n", long_options[i].name, long_options[i].val, option_arg_name[i], help_options[i] ); + } +} + +static int app_argc = 0; +static const char *app_argv[100] = { NULL }; + +static void clear_argv(int idx) +{ + app_argv[idx] = NULL; +} +static void shift_argv(int idx) +{ + for( int i=idx; i= 3 && strcmp(argv[1], "-u") == 0){ + const char * log_file_path = NULL; + + app_argc = argc; + for( int i=0; i