windows ports: configure for btstack_tlv_posix

This commit is contained in:
Matthias Ringwald 2020-06-22 16:27:42 +02:00
parent 7b884c89af
commit 6486d27807
9 changed files with 131 additions and 62 deletions

View File

@ -1,14 +1,14 @@
# Makefile for windows-h4 examples
BTSTACK_ROOT ?= ../..
CORE += main.c btstack_stdin_windows.c
CORE += main.c btstack_stdin_windows.c btstack_tlv_posix.c
COMMON += \
btstack_chipset_zephyr.c \
btstack_run_loop_windows.c \
btstack_uart_block_windows.c \
hci_transport_h4.c \
le_device_db_fs.c \
le_device_db_tlv.c \
# examples
include ${BTSTACK_ROOT}/example/Makefile.inc

View File

@ -62,15 +62,17 @@
#include "btstack_stdin.h"
#include "btstack_chipset_zephyr.h"
#include "hal_led.h"
#include "btstack_tlv_posix.h"
#include "ble/le_device_db_tlv.h"
int btstack_main(int argc, const char * argv[]);
static hci_transport_config_uart_t config = {
HCI_TRANSPORT_CONFIG_UART,
1000000,
0, // main baudrate
1, // flow control
NULL,
HCI_TRANSPORT_CONFIG_UART,
1000000,
0, // main baudrate
1, // flow control
NULL,
};
static btstack_packet_callback_registration_t hci_event_callback_registration;
@ -78,6 +80,12 @@ static btstack_packet_callback_registration_t hci_event_callback_registration;
static const uint8_t read_static_address_command_complete_prefix[] = { 0x0e, 0x1b, 0x01, 0x09, 0xfc };
static bd_addr_t static_address;
#define TLV_DB_PATH_PREFIX "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 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;
@ -85,6 +93,14 @@ 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));
strcpy(tlv_db_path, TLV_DB_PATH_PREFIX);
strcat(tlv_db_path, bd_addr_to_str(static_address));
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);
#ifdef ENABLE_BLE
le_device_db_tlv_configure(tlv_impl, &tlv_context);
#endif
break;
case HCI_EVENT_COMMAND_COMPLETE:
if (memcmp(packet, read_static_address_command_complete_prefix, sizeof(read_static_address_command_complete_prefix)) == 0){
@ -100,7 +116,7 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
static void sigint_handler(int param){
UNUSED(param);
printf("CTRL-C - SIGINT received, shutting down..\n");
printf("CTRL-C - SIGINT received, shutting down..\n");
log_info("sigint_handler: shutting down");
// reset anyway
@ -109,7 +125,7 @@ static void sigint_handler(int param){
// power down
hci_power_control(HCI_POWER_OFF);
hci_close();
log_info("Good bye, see you.\n");
log_info("Good bye, see you.\n");
exit(0);
}
@ -121,10 +137,10 @@ void hal_led_toggle(void){
int main(int argc, const char * argv[]){
/// GET STARTED with BTstack ///
btstack_memory_init();
/// GET STARTED with BTstack ///
btstack_memory_init();
btstack_run_loop_init(btstack_run_loop_windows_get_instance());
// use logger: format HCI_DUMP_PACKETLOGGER, HCI_DUMP_BLUEZ or HCI_DUMP_STDOUT
const char * pklg_path = "hci_dump.pklg";
hci_dump_open(pklg_path, HCI_DUMP_PACKETLOGGER);
@ -143,10 +159,10 @@ int main(int argc, const char * argv[]){
// init HCI
const btstack_uart_block_t * uart_driver = btstack_uart_block_windows_instance();
const hci_transport_t * transport = hci_transport_h4_instance(uart_driver);
hci_init(transport, (void*) &config);
const hci_transport_t * transport = hci_transport_h4_instance(uart_driver);
hci_init(transport, (void*) &config);
hci_set_chipset(btstack_chipset_zephyr_instance());
// inform about BTstack state
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
@ -158,7 +174,7 @@ int main(int argc, const char * argv[]){
btstack_main(argc, argv);
// go
btstack_run_loop_execute();
btstack_run_loop_execute();
return 0;
}

View File

@ -1,14 +1,14 @@
# Makefile for windows-h4 examples
BTSTACK_ROOT ?= ../..
CORE += main.c btstack_stdin_windows.c
CORE += main.c btstack_stdin_windows.c btstack_tlv_posix.c
COMMON += \
btstack_run_loop_windows.c \
hci_transport_h4.c \
btstack_uart_block_windows.c \
le_device_db_fs.c \
btstack_link_key_db_fs.c \
le_device_db_tlv.c \
btstack_link_key_db_tlv.c \
bluetooth_init_cc2564B_1.6_BT_Spec_4.1.c \
btstack_chipset_cc256x.c \
btstack_chipset_csr.c \

View File

@ -54,7 +54,9 @@
#include "hci.h"
#include "hci_dump.h"
#include "hal_led.h"
#include "btstack_link_key_db_fs.h"
#include "btstack_tlv_posix.h"
#include "ble/le_device_db_tlv.h"
#include "classic/btstack_link_key_db_tlv.h"
#include "btstack_stdin.h"
@ -80,6 +82,13 @@ int is_bcm;
static int led_state = 0;
#define TLV_DB_PATH_PREFIX "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 bd_addr_t local_addr;
void hal_led_toggle(void){
led_state = 1 - led_state;
printf("LED State %u\n", led_state);
@ -88,7 +97,7 @@ void hal_led_toggle(void){
static void sigint_handler(int param){
UNUSED(param);
printf("CTRL-C = SIGINT received, shutting down..\n");
printf("CTRL-C = SIGINT received, shutting down..\n");
log_info("sigint_handler: shutting down");
// reset anyway
@ -97,7 +106,7 @@ static void sigint_handler(int param){
// power down
hci_power_control(HCI_POWER_OFF);
hci_close();
log_info("Good bye, see you.\n");
log_info("Good bye, see you.\n");
exit(0);
}
@ -110,6 +119,18 @@ 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;
gap_local_bd_addr(addr);
printf("BTstack up and running on %s.\n", bd_addr_to_str(local_addr));
strcpy(tlv_db_path, TLV_DB_PATH_PREFIX);
strcat(tlv_db_path, bd_addr_to_str(local_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);
#ifdef ENABLE_CLASSIC
hci_set_link_key_db(btstack_link_key_db_tlv_get_instance(tlv_impl, &tlv_context));
#endif
#ifdef ENABLE_BLE
le_device_db_tlv_configure(tlv_impl, &tlv_context);
#endif
printf("BTstack up and running at %s\n", bd_addr_to_str(addr));
break;
case HCI_EVENT_COMMAND_COMPLETE:
@ -121,7 +142,7 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
if (is_bcm){
btstack_chipset_bcm_set_device_name((const char *)&packet[6]);
}
}
}
if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_local_version_information)){
local_version_information_handler(packet);
}
@ -153,7 +174,7 @@ static void local_version_information_handler(uint8_t * packet){
use_fast_uart();
hci_set_chipset(btstack_chipset_csr_instance());
break;
case BLUETOOTH_COMPANY_ID_TEXAS_INSTRUMENTS_INC:
case BLUETOOTH_COMPANY_ID_TEXAS_INSTRUMENTS_INC:
printf("Texas Instruments - CC256x compatible chipset.\n");
if (lmp_subversion != btstack_chipset_cc256x_lmp_subversion()){
printf("Error: LMP Subversion does not match initscript!");
@ -169,13 +190,13 @@ static void local_version_information_handler(uint8_t * packet){
printf("eHCILL disable.\n");
#endif
break;
case BLUETOOTH_COMPANY_ID_BROADCOM_CORPORATION:
case BLUETOOTH_COMPANY_ID_BROADCOM_CORPORATION:
printf("Broadcom - using BCM driver.\n");
hci_set_chipset(btstack_chipset_bcm_instance());
use_fast_uart();
is_bcm = 1;
break;
case BLUETOOTH_COMPANY_ID_ST_MICROELECTRONICS:
case BLUETOOTH_COMPANY_ID_ST_MICROELECTRONICS:
printf("ST Microelectronics - using STLC2500d driver.\n");
use_fast_uart();
hci_set_chipset(btstack_chipset_stlc2500d_instance());
@ -186,7 +207,7 @@ static void local_version_information_handler(uint8_t * packet){
break;
case BLUETOOTH_COMPANY_ID_NORDIC_SEMICONDUCTOR_ASA:
printf("Nordic Semiconductor nRF5 chipset.\n");
break;
break;
case BLUETOOTH_COMPANY_ID_TOSHIBA_CORP:
printf("Toshiba - using TC3566x driver.\n");
hci_set_chipset(btstack_chipset_tc3566x_instance());
@ -199,10 +220,10 @@ static void local_version_information_handler(uint8_t * packet){
}
int main(int argc, const char * argv[]){
printf("BTstack on windows booting up\n");
printf("BTstack on windows booting up\n");
/// GET STARTED with BTstack ///
btstack_memory_init();
/// GET STARTED with BTstack ///
btstack_memory_init();
btstack_run_loop_init(btstack_run_loop_windows_get_instance());
hci_dump_open("hci_dump.pklg", HCI_DUMP_PACKETLOGGER);
@ -220,10 +241,8 @@ int main(int argc, const char * argv[]){
// init HCI
const btstack_uart_block_t * uart_driver = btstack_uart_block_windows_instance();
const hci_transport_t * transport = hci_transport_h4_instance(uart_driver);
const btstack_link_key_db_t * link_key_db = btstack_link_key_db_fs_instance();
hci_init(transport, (void*) &config);
hci_set_link_key_db(link_key_db);
const hci_transport_t * transport = hci_transport_h4_instance(uart_driver);
hci_init(transport, (void*) &config);
// inform about BTstack state
hci_event_callback_registration.callback = &packet_handler;
@ -236,7 +255,7 @@ int main(int argc, const char * argv[]){
btstack_main(argc, argv);
// go
btstack_run_loop_execute();
btstack_run_loop_execute();
return 0;
return 0;
}

View File

@ -1,9 +1,9 @@
# Makefile for windows WinUSB based examples
BTSTACK_ROOT ?= ../..
CORE += main.c btstack_stdin_windows.c
CORE += main.c btstack_stdin_windows.c btstack_tlv_posix.c
COMMON += hci_transport_h2_winusb.c btstack_run_loop_windows.c le_device_db_fs.c btstack_link_key_db_fs.c wav_util.c
COMMON += hci_transport_h2_winusb.c btstack_run_loop_windows.c le_device_db_tlv.c btstack_link_key_db_tlv.c wav_util.c
COMMON += btstack_chipset_intel_firmware.c rijndael.c
include ${BTSTACK_ROOT}/example/Makefile.inc
@ -20,6 +20,7 @@ CFLAGS += -I${BTSTACK_ROOT}/platform/windows \
-I${BTSTACK_ROOT}/3rd-party/rijndael \
-I${BTSTACK_ROOT}/3rd-party/tinydir
VPATH += ${BTSTACK_ROOT}/3rd-party/rijndael
VPATH += ${BTSTACK_ROOT}/platform/embedded
VPATH += ${BTSTACK_ROOT}/platform/posix
VPATH += ${BTSTACK_ROOT}/platform/windows

View File

@ -15,6 +15,7 @@
#define ENABLE_BLE
#define ENABLE_CLASSIC
#define ENABLE_HFP_WIDE_BAND_SPEECH
#define ENABLE_L2CAP_ENHANCED_RETRANSMISSION_MODE
#define ENABLE_LE_CENTRAL
#define ENABLE_LE_PERIPHERAL
#define ENABLE_LE_SECURE_CONNECTIONS
@ -25,6 +26,7 @@
#define ENABLE_LOG_INFO
#define ENABLE_SCO_OVER_HCI
#define ENABLE_SDP_DES_DUMP
#define ENABLE_SOFTWARE_AES128
// BTstack configuration. buffers, sizes, ...
#define HCI_ACL_PAYLOAD_SIZE (1691 + 4)

View File

@ -53,10 +53,12 @@
#include "btstack_debug.h"
#include "btstack_event.h"
#include "btstack_link_key_db_fs.h"
#include "btstack_memory.h"
#include "btstack_run_loop.h"
#include "btstack_run_loop_windows.h"
#include "btstack_tlv_posix.h"
#include "ble/le_device_db_tlv.h"
#include "classic/btstack_link_key_db_tlv.h"
#include "hal_led.h"
#include "hci.h"
#include "hci_dump.h"
@ -65,6 +67,14 @@
int btstack_main(int argc, const char * argv[]);
#define TLV_DB_PATH_PREFIX "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 bd_addr_t local_addr;
static btstack_packet_callback_registration_t hci_event_callback_registration;
static int main_argc;
static const char ** main_argv;
@ -75,9 +85,19 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
if (packet_type != HCI_EVENT_PACKET) return;
if (hci_event_packet_get_type(packet) != BTSTACK_EVENT_STATE) return;
if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) return;
bd_addr_t addr;
gap_local_bd_addr(addr);
printf("BTstack up and running at %s\n", bd_addr_to_str(addr));
gap_local_bd_addr(local_addr);
printf("BTstack up and running on %s.\n", bd_addr_to_str(local_addr));
strcpy(tlv_db_path, TLV_DB_PATH_PREFIX);
strcat(tlv_db_path, bd_addr_to_str(local_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);
#ifdef ENABLE_CLASSIC
hci_set_link_key_db(btstack_link_key_db_tlv_get_instance(tlv_impl, &tlv_context));
#endif
#ifdef ENABLE_BLE
le_device_db_tlv_configure(tlv_impl, &tlv_context);
#endif
}
static void sigint_handler(int param){
@ -113,10 +133,6 @@ static void intel_firmware_done(int result){
// init HCI
hci_init(transport, NULL);
#ifdef ENABLE_CLASSIC
hci_set_link_key_db(btstack_link_key_db_fs_instance());
#endif
// inform about BTstack state
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);

View File

@ -1,9 +1,9 @@
# Makefile for windows WinUSB based examples
BTSTACK_ROOT ?= ../..
CORE += main.c btstack_stdin_windows.c
CORE += main.c btstack_stdin_windows.c btstack_tlv_posix.c
COMMON += hci_transport_h2_winusb.c btstack_run_loop_windows.c le_device_db_fs.c btstack_link_key_db_fs.c wav_util.c
COMMON += hci_transport_h2_winusb.c btstack_run_loop_windows.c le_device_db_tlv.c btstack_link_key_db_tlv.c wav_util.c
COMMON += rijndael.c
include ${BTSTACK_ROOT}/example/Makefile.inc

View File

@ -53,10 +53,12 @@
#include "btstack_debug.h"
#include "btstack_event.h"
#include "btstack_link_key_db_fs.h"
#include "btstack_memory.h"
#include "btstack_run_loop.h"
#include "btstack_run_loop_windows.h"
#include "btstack_tlv_posix.h"
#include "ble/le_device_db_tlv.h"
#include "classic/btstack_link_key_db_tlv.h"
#include "hal_led.h"
#include "hci.h"
#include "hci_dump.h"
@ -66,19 +68,36 @@ int btstack_main(int argc, const char * argv[]);
static btstack_packet_callback_registration_t hci_event_callback_registration;
#define TLV_DB_PATH_PREFIX "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 bd_addr_t local_addr;
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
if (packet_type != HCI_EVENT_PACKET) return;
if (hci_event_packet_get_type(packet) != BTSTACK_EVENT_STATE) return;
if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) return;
bd_addr_t addr;
gap_local_bd_addr(addr);
printf("BTstack up and running at %s\n", bd_addr_to_str(addr));
gap_local_bd_addr(local_addr);
printf("BTstack up and running on %s.\n", bd_addr_to_str(local_addr));
strcpy(tlv_db_path, TLV_DB_PATH_PREFIX);
strcat(tlv_db_path, bd_addr_to_str(local_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);
#ifdef ENABLE_CLASSIC
hci_set_link_key_db(btstack_link_key_db_tlv_get_instance(tlv_impl, &tlv_context));
#endif
#ifdef ENABLE_BLE
le_device_db_tlv_configure(tlv_impl, &tlv_context);
#endif
}
static void sigint_handler(int param){
UNUSED(param);
printf("CTRL-C - SIGINT received, shutting down..\n");
printf("CTRL-C - SIGINT received, shutting down..\n");
log_info("sigint_handler: shutting down");
// reset anyway
@ -87,7 +106,7 @@ static void sigint_handler(int param){
// power down
hci_power_control(HCI_POWER_OFF);
hci_close();
log_info("Good bye, see you.\n");
log_info("Good bye, see you.\n");
exit(0);
}
@ -126,10 +145,10 @@ int main(int argc, const char * argv[]){
}
#endif
/// GET STARTED with BTstack ///
btstack_memory_init();
/// GET STARTED with BTstack ///
btstack_memory_init();
btstack_run_loop_init(btstack_run_loop_windows_get_instance());
// if (usb_path_len){
// hci_transport_usb_set_path(usb_path_len, usb_path);
// }
@ -155,10 +174,6 @@ int main(int argc, const char * argv[]){
// init HCI
hci_init(hci_transport_usb_instance(), NULL);
#ifdef ENABLE_CLASSIC
hci_set_link_key_db(btstack_link_key_db_fs_instance());
#endif
// inform about BTstack state
hci_event_callback_registration.callback = &packet_handler;
hci_add_event_handler(&hci_event_callback_registration);
@ -170,7 +185,7 @@ int main(int argc, const char * argv[]){
btstack_main(argc, argv);
// go
btstack_run_loop_execute();
btstack_run_loop_execute();
return 0;
}