From 7daa8bd9ceef01499997be8942315b69e7b95059 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Sun, 29 Jul 2018 11:06:23 +0200 Subject: [PATCH] posix: use TLV with btstack_tlv_posix --- port/posix-h4-atwilc3000/Makefile | 2 ++ port/posix-h4-atwilc3000/main.c | 17 ++++++++++++++++- port/posix-h4-da14581/main.c | 17 ++++++++++++++++- port/posix-h4-da14585/main.c | 18 +++++++++++++++++- port/posix-h4-zephyr/main.c | 13 +++++++++++++ port/posix-h4/main.c | 13 +++++++++++++ port/posix-h5-bcm/main.c | 12 ++++++++++++ port/posix-h5/main.c | 12 ++++++++++++ 8 files changed, 101 insertions(+), 3 deletions(-) diff --git a/port/posix-h4-atwilc3000/Makefile b/port/posix-h4-atwilc3000/Makefile index c0dfdfb78..15a30adcf 100644 --- a/port/posix-h4-atwilc3000/Makefile +++ b/port/posix-h4-atwilc3000/Makefile @@ -19,6 +19,8 @@ include ${BTSTACK_ROOT}/example/Makefile.inc # firmware include ${BTSTACK_ROOT}/chipset/atwilc3000/Makefile.inc +all: wilc3000_ble_firmware.h + CFLAGS += -g -Wall -Werror \ -I$(BTSTACK_ROOT)/platform/posix \ -I$(BTSTACK_ROOT)/chipset/atwilc3000 \ diff --git a/port/posix-h4-atwilc3000/main.c b/port/posix-h4-atwilc3000/main.c index fb6613e71..1dbe6989b 100644 --- a/port/posix-h4-atwilc3000/main.c +++ b/port/posix-h4-atwilc3000/main.c @@ -60,6 +60,7 @@ #include "hci.h" #include "hci_dump.h" #include "btstack_stdin.h" +#include "btstack_tlv_posix.h" #include "btstack_chipset_atwilc3000.h" // #include "wilc3000_bt_firmware.h" @@ -70,6 +71,12 @@ static const char ** main_argv; static const btstack_uart_block_t * uart_driver; static btstack_uart_config_t uart_config; +#define TLV_DB_PATH_PREFIX "/tmp/btstack_" +#define TLV_DB_PATH_POSTFIX ".tlv" +static char tlv_db_path[100]; +static const btstack_tlv_t * tlv_impl; +static btstack_tlv_posix_t tlv_context; + int btstack_main(int argc, const char * argv[]); static hci_transport_config_uart_t transport_config = { @@ -83,11 +90,19 @@ static hci_transport_config_uart_t transport_config = { static btstack_packet_callback_registration_t hci_event_callback_registration; static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ + bd_addr_t addr; if (packet_type != HCI_EVENT_PACKET) return; switch (hci_event_packet_get_type(packet)){ case BTSTACK_EVENT_STATE: if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) break; - printf("BTstack up and running.\n"); + gap_local_bd_addr(addr); + printf("BTstack up and running at %s\n", bd_addr_to_str(addr)); + // setup TLV + strcpy(tlv_db_path, TLV_DB_PATH_PREFIX); + strcat(tlv_db_path, bd_addr_to_str(addr)); + strcat(tlv_db_path, TLV_DB_PATH_POSTFIX); + tlv_impl = btstack_tlv_posix_init_instance(&tlv_context, tlv_db_path); + btstack_tlv_set_instance(tlv_impl, &tlv_context); break; default: break; diff --git a/port/posix-h4-da14581/main.c b/port/posix-h4-da14581/main.c index 8ae116473..88edc57b2 100644 --- a/port/posix-h4-da14581/main.c +++ b/port/posix-h4-da14581/main.c @@ -60,6 +60,7 @@ #include "hci.h" #include "hci_dump.h" #include "btstack_stdin.h" +#include "btstack_tlv_posix.h" #include "btstack_chipset_da14581.h" #include "hci_581_active_uart.h" @@ -69,6 +70,12 @@ static const char ** main_argv; static const btstack_uart_block_t * uart_driver; static btstack_uart_config_t uart_config; +#define TLV_DB_PATH_PREFIX "/tmp/btstack_" +#define TLV_DB_PATH_POSTFIX ".tlv" +static char tlv_db_path[100]; +static const btstack_tlv_t * tlv_impl; +static btstack_tlv_posix_t tlv_context; + int btstack_main(int argc, const char * argv[]); static hci_transport_config_uart_t transport_config = { @@ -82,11 +89,19 @@ static hci_transport_config_uart_t transport_config = { static btstack_packet_callback_registration_t hci_event_callback_registration; static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ + bd_addr_t addr; if (packet_type != HCI_EVENT_PACKET) return; switch (hci_event_packet_get_type(packet)){ case BTSTACK_EVENT_STATE: if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) break; - printf("BTstack up and running.\n"); + gap_local_bd_addr(addr); + printf("BTstack up and running at %s\n", bd_addr_to_str(addr)); + // setup TLV + strcpy(tlv_db_path, TLV_DB_PATH_PREFIX); + strcat(tlv_db_path, bd_addr_to_str(addr)); + strcat(tlv_db_path, TLV_DB_PATH_POSTFIX); + tlv_impl = btstack_tlv_posix_init_instance(&tlv_context, tlv_db_path); + btstack_tlv_set_instance(tlv_impl, &tlv_context); break; default: break; diff --git a/port/posix-h4-da14585/main.c b/port/posix-h4-da14585/main.c index c8299c51d..cc39dc554 100644 --- a/port/posix-h4-da14585/main.c +++ b/port/posix-h4-da14585/main.c @@ -60,6 +60,7 @@ #include "hci.h" #include "hci_dump.h" #include "btstack_stdin.h" +#include "btstack_tlv_posix.h" #include "btstack_chipset_da14581.h" #include "hci_581_active_uart.h" @@ -69,6 +70,12 @@ static const char ** main_argv; static const btstack_uart_block_t * uart_driver; static btstack_uart_config_t uart_config; +#define TLV_DB_PATH_PREFIX "/tmp/btstack_" +#define TLV_DB_PATH_POSTFIX ".tlv" +static char tlv_db_path[100]; +static const btstack_tlv_t * tlv_impl; +static btstack_tlv_posix_t tlv_context; + int btstack_main(int argc, const char * argv[]); static hci_transport_config_uart_t transport_config = { @@ -82,17 +89,26 @@ static hci_transport_config_uart_t transport_config = { static btstack_packet_callback_registration_t hci_event_callback_registration; static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ + bd_addr_t addr; if (packet_type != HCI_EVENT_PACKET) return; switch (hci_event_packet_get_type(packet)){ case BTSTACK_EVENT_STATE: if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) break; - printf("BTstack up and running.\n"); + gap_local_bd_addr(addr); + printf("BTstack up and running at %s\n", bd_addr_to_str(addr)); + // setup TLV + strcpy(tlv_db_path, TLV_DB_PATH_PREFIX); + strcat(tlv_db_path, bd_addr_to_str(addr)); + strcat(tlv_db_path, TLV_DB_PATH_POSTFIX); + tlv_impl = btstack_tlv_posix_init_instance(&tlv_context, tlv_db_path); + btstack_tlv_set_instance(tlv_impl, &tlv_context); break; default: break; } } + static void sigint_handler(int param){ UNUSED(param); diff --git a/port/posix-h4-zephyr/main.c b/port/posix-h4-zephyr/main.c index c85121652..86b6649b1 100644 --- a/port/posix-h4-zephyr/main.c +++ b/port/posix-h4-zephyr/main.c @@ -62,9 +62,16 @@ #include "hci_dump.h" #include "btstack_stdin.h" #include "btstack_chipset_zephyr.h" +#include "btstack_tlv_posix.h" int btstack_main(int argc, const char * argv[]); +#define TLV_DB_PATH_PREFIX "/tmp/btstack_" +#define TLV_DB_PATH_POSTFIX ".tlv" +static char tlv_db_path[100]; +static const btstack_tlv_t * tlv_impl; +static btstack_tlv_posix_t tlv_context; + static hci_transport_config_uart_t config = { HCI_TRANSPORT_CONFIG_UART, 1000000, @@ -85,6 +92,12 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack case BTSTACK_EVENT_STATE: if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) break; printf("BTstack up and running as %s\n", bd_addr_to_str(static_address)); + // setup TLV + strcpy(tlv_db_path, TLV_DB_PATH_PREFIX); + strcat(tlv_db_path, bd_addr_to_str(addr)); + strcat(tlv_db_path, TLV_DB_PATH_POSTFIX); + tlv_impl = btstack_tlv_posix_init_instance(&tlv_context, tlv_db_path); + btstack_tlv_set_instance(tlv_impl, &tlv_context); break; case HCI_EVENT_COMMAND_COMPLETE: if (memcmp(packet, read_static_address_command_complete_prefix, sizeof(read_static_address_command_complete_prefix)) == 0){ diff --git a/port/posix-h4/main.c b/port/posix-h4/main.c index 7163bfc22..671f43634 100644 --- a/port/posix-h4/main.c +++ b/port/posix-h4/main.c @@ -61,6 +61,7 @@ #include "hci.h" #include "hci_dump.h" #include "btstack_stdin.h" +#include "btstack_tlv_posix.h" #include "btstack_chipset_bcm.h" #include "btstack_chipset_csr.h" @@ -71,6 +72,12 @@ int is_bcm; +#define TLV_DB_PATH_PREFIX "/tmp/btstack_" +#define TLV_DB_PATH_POSTFIX ".tlv" +static char tlv_db_path[100]; +static const btstack_tlv_t * tlv_impl; +static btstack_tlv_posix_t tlv_context; + int btstack_main(int argc, const char * argv[]); static void local_version_information_handler(uint8_t * packet); @@ -92,6 +99,12 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) break; gap_local_bd_addr(addr); printf("BTstack up and running at %s\n", bd_addr_to_str(addr)); + // setup TLV + strcpy(tlv_db_path, TLV_DB_PATH_PREFIX); + strcat(tlv_db_path, bd_addr_to_str(addr)); + strcat(tlv_db_path, TLV_DB_PATH_POSTFIX); + tlv_impl = btstack_tlv_posix_init_instance(&tlv_context, tlv_db_path); + btstack_tlv_set_instance(tlv_impl, &tlv_context); break; case HCI_EVENT_COMMAND_COMPLETE: if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_local_name)){ diff --git a/port/posix-h5-bcm/main.c b/port/posix-h5-bcm/main.c index 6b3e9acd0..b394ef31d 100644 --- a/port/posix-h5-bcm/main.c +++ b/port/posix-h5-bcm/main.c @@ -61,12 +61,18 @@ #include "hci.h" #include "hci_dump.h" #include "btstack_stdin.h" +#include "btstack_tlv_posix.h" #include "btstack_chipset_bcm.h" #include "btstack_chipset_bcm_download_firmware.h" int btstack_main(int argc, const char * argv[]); +#define TLV_DB_PATH_PREFIX "/tmp/btstack_" +#define TLV_DB_PATH_POSTFIX ".tlv" +static char tlv_db_path[100]; +static const btstack_tlv_t * tlv_impl; +static btstack_tlv_posix_t tlv_context; static hci_transport_config_uart_t transport_config = { HCI_TRANSPORT_CONFIG_UART, @@ -112,6 +118,12 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) break; gap_local_bd_addr(addr); printf("BTstack up and running at %s\n", bd_addr_to_str(addr)); + // setup TLV + strcpy(tlv_db_path, TLV_DB_PATH_PREFIX); + strcat(tlv_db_path, bd_addr_to_str(addr)); + strcat(tlv_db_path, TLV_DB_PATH_POSTFIX); + tlv_impl = btstack_tlv_posix_init_instance(&tlv_context, tlv_db_path); + btstack_tlv_set_instance(tlv_impl, &tlv_context); break; default: break; diff --git a/port/posix-h5/main.c b/port/posix-h5/main.c index 527846fde..398c9845a 100644 --- a/port/posix-h5/main.c +++ b/port/posix-h5/main.c @@ -61,6 +61,7 @@ #include "hci.h" #include "hci_dump.h" #include "btstack_stdin.h" +#include "btstack_tlv_posix.h" #include "btstack_chipset_csr.h" #include "btstack_chipset_cc256x.h" @@ -70,6 +71,11 @@ int btstack_main(int argc, const char * argv[]); +#define TLV_DB_PATH_PREFIX "/tmp/btstack_" +#define TLV_DB_PATH_POSTFIX ".tlv" +static char tlv_db_path[100]; +static const btstack_tlv_t * tlv_impl; +static btstack_tlv_posix_t tlv_context; static hci_transport_config_uart_t config = { HCI_TRANSPORT_CONFIG_UART, @@ -158,6 +164,12 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) break; gap_local_bd_addr(addr); printf("BTstack up and running at %s\n", bd_addr_to_str(addr)); + // setup TLV + strcpy(tlv_db_path, TLV_DB_PATH_PREFIX); + strcat(tlv_db_path, bd_addr_to_str(addr)); + strcat(tlv_db_path, TLV_DB_PATH_POSTFIX); + tlv_impl = btstack_tlv_posix_init_instance(&tlv_context, tlv_db_path); + btstack_tlv_set_instance(tlv_impl, &tlv_context); break; case HCI_EVENT_COMMAND_COMPLETE: if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_local_name)){