libusb: use static random address stored in nRF52840 running Zephyr hci_usb

This commit is contained in:
Matthias Ringwald 2019-03-29 17:50:06 +01:00
parent fedcc363f3
commit f9563b8923
4 changed files with 54 additions and 4 deletions

View File

@ -18,6 +18,7 @@ include_directories(../../3rd-party/hxcmod-player/mod)
include_directories(../../3rd-party/yxml)
include_directories(../../3rd-party/tinydir)
include_directories(../../src)
include_directories(../../chipset/zephyr)
include_directories(../../platform/posix)
include_directories(../../platform/embedded)
include_directories(.)
@ -33,6 +34,7 @@ file(GLOB SOURCES_YXML "../../3rd-party/yxml/yxml.c")
file(GLOB SOURCES_HXCMOD "../../3rd-party/hxcmod-player/*.c" "../../3rd-party/hxcmod-player/mods/*.c")
file(GLOB SOURCES_POSIX "../../platform/posix/*.c")
file(GLOB SOURCES_LIBUSB "../../port/libusb/*.c" "../../platform/libusb/*.c")
file(GLOB SOURCES_ZEPHYR "../../chipset/zephyr/*.c")
file(GLOB SOURCES_OFF "../../src/ble/le_device_db_memory.c" "../../src/ble/le_device_db_tlv.c")
list(REMOVE_ITEM SOURCES_BLE ${SOURCES_OFF})
@ -49,6 +51,7 @@ set(SOURCES
${SOURCES_CLASSIC}
${SOURCES_UECC}
${SOURCES_HXCMOD}
${SOURCES_ZEPHYR}
)
list(SORT SOURCES)

View File

@ -3,8 +3,8 @@ BTSTACK_ROOT = ../..
CORE += main.c btstack_stdin_posix.c btstack_tlv_posix.c
COMMON += hci_transport_h2_libusb.c btstack_run_loop_posix.c le_device_db_fs.c btstack_link_key_db_fs.c wav_util.c btstack_network_posix.c
COMMON += btstack_audio_portaudio.c
COMMON += hci_transport_h2_libusb.c btstack_run_loop_posix.c le_device_db_fs.c btstack_link_key_db_fs.c wav_util.c btstack_network_posix.c
COMMON += btstack_audio_portaudio.c btstack_chipset_zephyr.c
include ${BTSTACK_ROOT}/example/Makefile.inc
@ -17,14 +17,16 @@ CFLAGS += -g -std=c99 -Wall -Wmissing-prototypes -Wstrict-prototypes -Wshadow -
# CFLAGS += -Wc11-extensions
# CFLAGS += -Wgnu-empty-initializer
CFLAGS += -I${BTSTACK_ROOT}/platform/posix \
CFLAGS += -I${BTSTACK_ROOT}/platform/posix \
-I${BTSTACK_ROOT}/platform/embedded \
-I${BTSTACK_ROOT}/3rd-party/tinydir
-I${BTSTACK_ROOT}/3rd-party/tinydir \
-I${BTSTACK_ROOT}/chipset/zephyr
VPATH += ${BTSTACK_ROOT}/platform/embedded
VPATH += ${BTSTACK_ROOT}/platform/posix
VPATH += ${BTSTACK_ROOT}/platform/libusb
VPATH += ${BTSTACK_ROOT}/chipset/csr
VPATH += ${BTSTACK_ROOT}/chipset/zephyr
# use pkg-config
CFLAGS += $(shell pkg-config libusb-1.0 --cflags)

View File

@ -51,6 +51,7 @@
#include "btstack_config.h"
#include "bluetooth_company_id.h"
#include "btstack_debug.h"
#include "btstack_event.h"
#include "btstack_link_key_db_fs.h"
@ -63,6 +64,7 @@
#include "btstack_stdin.h"
#include "btstack_audio.h"
#include "btstack_tlv_posix.h"
#include "btstack_chipset_zephyr.h"
#define TLV_DB_PATH_PREFIX "/tmp/btstack_"
#define TLV_DB_PATH_POSTFIX ".tlv"
@ -73,8 +75,35 @@ static bd_addr_t local_addr;
int btstack_main(int argc, const char * argv[]);
static const uint8_t read_static_address_command_complete_prefix[] = { 0x0e, 0x1b, 0x01, 0x09, 0xfc };
static bd_addr_t static_address;
static int using_static_address;
static btstack_packet_callback_registration_t hci_event_callback_registration;
static void local_version_information_handler(uint8_t * packet){
printf("Local version information:\n");
uint16_t hci_version = packet[6];
uint16_t hci_revision = little_endian_read_16(packet, 7);
uint16_t lmp_version = packet[9];
uint16_t manufacturer = little_endian_read_16(packet, 10);
uint16_t lmp_subversion = little_endian_read_16(packet, 12);
printf("- HCI Version 0x%04x\n", hci_version);
printf("- HCI Revision 0x%04x\n", hci_revision);
printf("- LMP Version 0x%04x\n", lmp_version);
printf("- LMP Subversion 0x%04x\n", lmp_subversion);
printf("- Manufacturer 0x%04x\n", manufacturer);
switch (manufacturer){
case BLUETOOTH_COMPANY_ID_THE_LINUX_FOUNDATION:
printf("Linux Foundation - assume Zephyr hci_usb example running on nRF52xx\n");
hci_set_chipset(btstack_chipset_zephyr_instance());
break;
default:
break;
}
}
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
UNUSED(channel);
UNUSED(size);
@ -83,6 +112,9 @@ 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) return;
gap_local_bd_addr(local_addr);
if (using_static_address){
memcpy(local_addr, static_address, 6);
}
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));
@ -90,6 +122,16 @@ static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *pack
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_version_information)){
local_version_information_handler(packet);
}
if (memcmp(packet, read_static_address_command_complete_prefix, sizeof(read_static_address_command_complete_prefix)) == 0){
reverse_48(&packet[7], static_address);
gap_random_address_set(static_address);
using_static_address = 1;
}
break;
default:
break;
}

View File

@ -1187,4 +1187,7 @@
#define BLUETOOTH_COMPANY_ID_COCHLEAR_LIMITED 0x0497
#define BLUETOOTH_COMPANY_ID_METER_GROUP_INC_USA 0x0498
// manually added
#define BLUETOOTH_COMPANY_ID_THE_LINUX_FOUNDATION 0x05F1
#endif