diff --git a/port/nrf5-zephyr/hci_firmware.patch b/port/nrf5-zephyr/hci_firmware.patch deleted file mode 100644 index 373da5998..000000000 --- a/port/nrf5-zephyr/hci_firmware.patch +++ /dev/null @@ -1,35 +0,0 @@ -diff --git a/subsys/bluetooth/controller/ll_sw/ctrl.h b/subsys/bluetooth/controller/ll_sw/ctrl.h -index ecec3ccc3..88cdba5fc 100644 ---- a/subsys/bluetooth/controller/ll_sw/ctrl.h -+++ b/subsys/bluetooth/controller/ll_sw/ctrl.h -@@ -128,7 +128,7 @@ - #if defined(CONFIG_BT_CTLR_COMPANY_ID) - #define RADIO_BLE_COMPANY_ID CONFIG_BT_CTLR_COMPANY_ID - #else --#define RADIO_BLE_COMPANY_ID 0xFFFF -+#define RADIO_BLE_COMPANY_ID (0x0059) // Nordic Semiconductor ASA - #endif - #if defined(CONFIG_BT_CTLR_SUBVERSION_NUMBER) - #define RADIO_BLE_SUB_VERSION_NUMBER \ -diff --git a/subsys/Kconfig b/subsys/Kconfig -index 4966a0b81..546713963 100644 ---- a/subsys/Kconfig -+++ b/subsys/Kconfig -@@ -24,3 +24,5 @@ source "subsys/net/Kconfig" - source "subsys/shell/Kconfig" - - source "subsys/usb/Kconfig" -+ -+source "subsys/btstack/Kconfig" -diff --git a/subsys/Makefile b/subsys/Makefile -index a9a2aa153..94da28f17 100644 ---- a/subsys/Makefile -+++ b/subsys/Makefile -@@ -1,6 +1,7 @@ - obj-$(CONFIG_FILE_SYSTEM) += fs/ - obj-$(CONFIG_USB) += usb/ - obj-$(CONFIG_BT) += bluetooth/ -+obj-$(CONFIG_BTSTACK) += btstack/ - obj-$(CONFIG_NET_BUF) += net/ - obj-$(CONFIG_CONSOLE_SHELL) += shell/ - obj-$(CONFIG_CONSOLE_PULL) += console/ diff --git a/port/nrf5-zephyr/integrate_btstack.sh b/port/nrf5-zephyr/integrate_btstack.sh index 65ffb0505..c73ce9363 100755 --- a/port/nrf5-zephyr/integrate_btstack.sh +++ b/port/nrf5-zephyr/integrate_btstack.sh @@ -4,15 +4,6 @@ ZEPHYR_BASE=../../.. echo "Integrating BTstack into Zephyr" -if grep -q -F "NRF_FICR->DEVICEADDR" ${ZEPHYR_BASE}/samples/bluetooth/hci_uart/src/main.c; then - echo "HCI Firmware patch already installed" -else - # assert files don't exist since patch would get irritated - echo "Applying HCI Firmware patch" - rm -f ${ZEPHYR_BASE}/samples/bluetooth/hci_uart/flash* - cat hci_firmware.patch | patch -d ${ZEPHYR_BASE} -p1 -fi - echo "Adding subsys/btstack" # add btstack folder to subsys/Makefile @@ -48,7 +39,6 @@ rsync -a Kconfig ${ZEPHYR_BASE}/subsys/btstack # copy Makefiles rsync -a Makefile.src ${ZEPHYR_BASE}/subsys/btstack/Makefile -rsync -a Makefile.classic ${ZEPHYR_BASE}/subsys/btstack/classic/Makefile rsync -a Makefile.ble ${ZEPHYR_BASE}/subsys/btstack/ble/Makefile rsync -a Makefile.gatt-service ${ZEPHYR_BASE}/subsys/btstack/ble/gatt-service/Makefile rsync -a Makefile.bluedroid ${ZEPHYR_BASE}/subsys/btstack/bluedroid/Makefile diff --git a/port/nrf5-zephyr/main.c b/port/nrf5-zephyr/main.c index 7c1ce675a..0786e119a 100644 --- a/port/nrf5-zephyr/main.c +++ b/port/nrf5-zephyr/main.c @@ -285,11 +285,13 @@ const btstack_run_loop_t * btstack_run_loop_zephyr_get_instance(void){ static btstack_packet_callback_registration_t hci_event_callback_registration; +static bd_addr_t static_address; + 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; - printf("BTstack up and running.\n"); + printf("BTstack up and running as %s.\n", bd_addr_to_str(static_address)); } int btstack_main(void); @@ -303,7 +305,6 @@ void bt_ctlr_assert_handle(char *file, u32_t line) } #endif /* CONFIG_BT_CTLR_ASSERT_HANDLER */ - void main(void) { // configure console UART by replacing CONFIG_UART_NRF5_BAUD_RATE with 115200 in uart_console.c @@ -320,23 +321,12 @@ void main(void) // init HCI hci_init(transport_get_instance(), NULL); -#if 1 // nRF5 chipsets don't have an official public address - // Instead, they use a Static Random Address set in the factory - bd_addr_t addr; -#if 0 - // set random static address - big_endian_store_16(addr, 0, NRF_FICR->DEVICEADDR[1] | 0xc000); - big_endian_store_32(addr, 2, NRF_FICR->DEVICEADDR[0]); - gap_random_address_set(addr); - printf("Random Static Address: %s\n", bd_addr_to_str(addr)); -#else - // make Random Static Address available via HCI Read BD ADDR as fake public address - little_endian_store_32(addr, 0, NRF_FICR->DEVICEADDR[0]); - little_endian_store_16(addr, 4, NRF_FICR->DEVICEADDR[1] | 0xc000); - ll_addr_set(0, addr); -#endif -#endif + // Instead, a Static Random Address is assigned during manufacturing + // let's use it as well + big_endian_store_16(static_address, 0, NRF_FICR->DEVICEADDR[1] | 0xc000); + big_endian_store_32(static_address, 2, NRF_FICR->DEVICEADDR[0]); + gap_random_address_set(static_address); // inform about BTstack state hci_event_callback_registration.callback = &packet_handler; diff --git a/src/ble/sm.c b/src/ble/sm.c index fea337770..3a3b29961 100644 --- a/src/ble/sm.c +++ b/src/ble/sm.c @@ -3275,17 +3275,9 @@ static void sm_event_packet_handler (uint8_t packet_type, uint16_t channel, uint break; } if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_bd_addr)){ - // Hack for Nordic nRF5 series that doesn't have public address: - // - with patches from port/nrf5-zephyr, hci_read_bd_addr returns random static address - // - we use this as default for advertisements/connections + // set local addr for le device db bd_addr_t addr; reverse_bd_addr(&packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE + 1], addr); - if (hci_get_manufacturer() == BLUETOOTH_COMPANY_ID_NORDIC_SEMICONDUCTOR_ASA){ - log_info("nRF5: using (fake) public address as random static address"); - gap_random_address_set(addr); - } - - // set local addr for le device db le_device_db_set_local_bd_addr(addr); } if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_local_supported_commands)){