From 2d49080cb8ec072c6ae1f1bc6463d558c77f06d0 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Mon, 20 May 2024 09:46:28 +0200 Subject: [PATCH] Bluetooth: Controller: Fix BT_CTLR_LE_ENC conditional compilation Fix BT_CTLR_LE_ENC conditional compilation when feature is disabled. Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/controller/CMakeLists.txt | 4 -- subsys/bluetooth/controller/Kconfig | 7 ++- .../ll_sw/nordic/hal/nrf5/radio/radio.c | 27 ++++++++++-- .../ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h | 15 +++++-- .../nordic/hal/nrf5/radio/radio_nrf5_dppi.h | 44 ++++++++++--------- .../controller/ll_sw/nordic/lll/lll_adv_iso.c | 6 ++- .../ll_sw/nordic/lll/lll_sync_iso.c | 9 ++-- .../bluetooth/controller/ll_sw/ull_adv_iso.c | 8 +++- .../bluetooth/controller/ll_sw/ull_sync_iso.c | 9 +++- 9 files changed, 89 insertions(+), 40 deletions(-) diff --git a/subsys/bluetooth/controller/CMakeLists.txt b/subsys/bluetooth/controller/CMakeLists.txt index a9761dc217d..6906ed1061a 100644 --- a/subsys/bluetooth/controller/CMakeLists.txt +++ b/subsys/bluetooth/controller/CMakeLists.txt @@ -173,10 +173,6 @@ zephyr_library_sources_ifdef( zephyr_library_include_directories( . include - ) - -zephyr_library_include_directories_ifdef( - CONFIG_BT_CTLR_CRYPTO ../crypto ) diff --git a/subsys/bluetooth/controller/Kconfig b/subsys/bluetooth/controller/Kconfig index 46d027b4e2f..a401502dbfe 100644 --- a/subsys/bluetooth/controller/Kconfig +++ b/subsys/bluetooth/controller/Kconfig @@ -813,9 +813,14 @@ config BT_CTLR_SYNC_ISO config BT_CTLR_BROADCAST_ISO bool - select BT_CRYPTO if BT_LL_SW_SPLIT default BT_CTLR_ADV_ISO || BT_CTLR_SYNC_ISO +config BT_CTLR_BROADCAST_ISO_ENC + bool + depends on BT_CTLR_CRYPTO_SUPPORT && BT_CTLR_BROADCAST_ISO + select BT_CRYPTO if BT_LL_SW_SPLIT + default y + config BT_CTLR_ADV_ISO_SET int "LE Isochronous Channel advertising sets" depends on BT_CTLR_ADV_ISO diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c index 4988276ffc9..14dc1e40763 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio.c @@ -1136,7 +1136,9 @@ void radio_tmr_status_reset(void) { nrf_rtc_event_disable(NRF_RTC0, RTC_EVTENCLR_COMPARE2_Msk); +#if defined(CONFIG_BT_CTLR_LE_ENC) || defined(CONFIG_BT_CTLR_BROADCAST_ISO_ENC) hal_trigger_crypt_ppi_disable(); +#endif /* CONFIG_BT_CTLR_LE_ENC || CONFIG_BT_CTLR_BROADCAST_ISO_ENC */ hal_radio_nrf_ppi_channels_disable( BIT(HAL_RADIO_ENABLE_TX_ON_TICK_PPI) | @@ -1163,14 +1165,19 @@ void radio_tmr_status_reset(void) #if defined(CONFIG_BT_CTLR_DF_CONN_CTE_RX) BIT(HAL_TRIGGER_CRYPT_DELAY_PPI) | #endif /* CONFIG_BT_CTLR_DF_CONN_CTE_RX */ - BIT(HAL_TRIGGER_CRYPT_PPI)); +#if defined(CONFIG_BT_CTLR_LE_ENC) || defined(CONFIG_BT_CTLR_BROADCAST_ISO_ENC) + BIT(HAL_TRIGGER_CRYPT_PPI) | +#endif /* CONFIG_BT_CTLR_LE_ENC || CONFIG_BT_CTLR_BROADCAST_ISO_ENC */ + 0); } void radio_tmr_tx_status_reset(void) { nrf_rtc_event_disable(NRF_RTC0, RTC_EVTENCLR_COMPARE2_Msk); +#if defined(CONFIG_BT_CTLR_LE_ENC) || defined(CONFIG_BT_CTLR_BROADCAST_ISO_ENC) hal_trigger_crypt_ppi_disable(); +#endif /* CONFIG_BT_CTLR_LE_ENC || CONFIG_BT_CTLR_BROADCAST_ISO_ENC */ hal_radio_nrf_ppi_channels_disable( #if (HAL_RADIO_ENABLE_TX_ON_TICK_PPI != HAL_RADIO_ENABLE_RX_ON_TICK_PPI) && \ @@ -1201,14 +1208,19 @@ void radio_tmr_tx_status_reset(void) #if defined(CONFIG_BT_CTLR_DF_CONN_CTE_RX) BIT(HAL_TRIGGER_CRYPT_DELAY_PPI) | #endif /* CONFIG_BT_CTLR_DF_CONN_CTE_RX */ - BIT(HAL_TRIGGER_CRYPT_PPI)); +#if defined(CONFIG_BT_CTLR_LE_ENC) || defined(CONFIG_BT_CTLR_BROADCAST_ISO_ENC) + BIT(HAL_TRIGGER_CRYPT_PPI) | +#endif /* CONFIG_BT_CTLR_LE_ENC || CONFIG_BT_CTLR_BROADCAST_ISO_ENC */ + 0); } void radio_tmr_rx_status_reset(void) { nrf_rtc_event_disable(NRF_RTC0, RTC_EVTENCLR_COMPARE2_Msk); +#if defined(CONFIG_BT_CTLR_LE_ENC) || defined(CONFIG_BT_CTLR_BROADCAST_ISO_ENC) hal_trigger_crypt_ppi_disable(); +#endif /* CONFIG_BT_CTLR_LE_ENC || CONFIG_BT_CTLR_BROADCAST_ISO_ENC */ hal_radio_nrf_ppi_channels_disable( #if (HAL_RADIO_ENABLE_TX_ON_TICK_PPI != HAL_RADIO_ENABLE_RX_ON_TICK_PPI) && \ @@ -1239,7 +1251,10 @@ void radio_tmr_rx_status_reset(void) #if defined(CONFIG_BT_CTLR_DF_CONN_CTE_RX) BIT(HAL_TRIGGER_CRYPT_DELAY_PPI) | #endif /* CONFIG_BT_CTLR_DF_CONN_CTE_RX */ - BIT(HAL_TRIGGER_CRYPT_PPI)); +#if defined(CONFIG_BT_CTLR_LE_ENC) || defined(CONFIG_BT_CTLR_BROADCAST_ISO_ENC) + BIT(HAL_TRIGGER_CRYPT_PPI) | +#endif /* CONFIG_BT_CTLR_LE_ENC || CONFIG_BT_CTLR_BROADCAST_ISO_ENC */ + 0); } void radio_tmr_tx_enable(void) @@ -1739,8 +1754,10 @@ void radio_gpio_pa_lna_disable(void) } #endif /* HAL_RADIO_GPIO_HAVE_PA_PIN || HAL_RADIO_GPIO_HAVE_LNA_PIN */ +#if defined(CONFIG_BT_CTLR_LE_ENC) || defined(CONFIG_BT_CTLR_BROADCAST_ISO_ENC) static uint8_t MALIGN(4) _ccm_scratch[(HAL_RADIO_PDU_LEN_MAX - 4) + 16]; +#if defined(CONFIG_BT_CTLR_LE_ENC) || defined(CONFIG_BT_CTLR_SYNC_ISO) static void *radio_ccm_ext_rx_pkt_set(struct ccm *cnf, uint8_t phy, uint8_t pdu_type, void *pkt) { uint32_t mode; @@ -1868,7 +1885,9 @@ void *radio_ccm_iso_rx_pkt_set(struct ccm *cnf, uint8_t phy, uint8_t pdu_type, v { return radio_ccm_ext_rx_pkt_set(cnf, phy, pdu_type, pkt); } +#endif /* CONFIG_BT_CTLR_LE_ENC || CONFIG_BT_CTLR_SYNC_ISO */ +#if defined(CONFIG_BT_CTLR_LE_ENC) || defined(CONFIG_BT_CTLR_ADV_ISO) static void *radio_ccm_ext_tx_pkt_set(struct ccm *cnf, uint8_t pdu_type, void *pkt) { uint32_t mode; @@ -1939,6 +1958,7 @@ void *radio_ccm_iso_tx_pkt_set(struct ccm *cnf, uint8_t pdu_type, void *pkt) { return radio_ccm_ext_tx_pkt_set(cnf, pdu_type, pkt); } +#endif /* CONFIG_BT_CTLR_LE_ENC || CONFIG_BT_CTLR_ADV_ISO */ uint32_t radio_ccm_is_done(void) { @@ -2086,6 +2106,7 @@ uint8_t radio_ar_resolve(const uint8_t *addr) } #endif /* CONFIG_BT_CTLR_PRIVACY */ +#endif /* CONFIG_BT_CTLR_LE_ENC || CONFIG_BT_CTLR_BROADCAST_ISO_ENC */ #if defined(CONFIG_BT_CTLR_DF_SUPPORT) && !defined(CONFIG_ZTEST) /* @brief Function configures CTE inline register to start sampling of CTE diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h index b9401a54292..bdfb3c89238 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5.h @@ -5,6 +5,9 @@ * SPDX-License-Identifier: Apache-2.0 */ +/* HAL header files for nRF5x SoCs. + * These has to come before the radio_*.h include below. + */ #include /* Common radio resources */ @@ -44,6 +47,14 @@ #error "Unsupported SoC." #endif +#include +#include + +#if defined(CONFIG_BT_CTLR_LE_ENC) || defined(CONFIG_BT_CTLR_BROADCAST_ISO_ENC) +#include +#include +#endif /* CONFIG_BT_CTLR_LE_ENC || CONFIG_BT_CTLR_BROADCAST_ISO_ENC */ + /* Define to reset PPI registration. * This has to come before the ppi/dppi includes below. */ @@ -57,10 +68,6 @@ #include "radio_nrf5_ppi_resources.h" #include "radio_nrf5_ppi.h" #elif defined(DPPI_PRESENT) -#include -#include -#include -#include #include #include "radio_nrf5_dppi_resources.h" #include "radio_nrf5_dppi.h" diff --git a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h index a09056ae2d3..6c975bccbc9 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h +++ b/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/radio/radio_nrf5_dppi.h @@ -113,6 +113,7 @@ static inline void hal_radio_ready_time_capture_ppi_config(void) NRF_TIMER_TASK_CAPTURE0, HAL_RADIO_READY_TIME_CAPTURE_PPI); } +#if defined(CONFIG_BT_CTLR_LE_ENC) || defined(CONFIG_BT_CTLR_BROADCAST_ISO_ENC) /******************************************************************************* * Trigger encryption task upon address reception: * wire the RADIO EVENTS_ADDRESS event to the CCM TASKS_CRYPT task. @@ -135,6 +136,28 @@ static inline void hal_trigger_crypt_ppi_disable(void) nrf_ccm_subscribe_clear(NRF_CCM, NRF_CCM_TASK_CRYPT); } +/******************************************************************************* + * Trigger automatic address resolution on Bit counter match: + * wire the RADIO EVENTS_BCMATCH event to the AAR TASKS_START task. + */ +static inline void hal_trigger_aar_ppi_config(void) +{ + nrf_radio_publish_set(NRF_RADIO, NRF_RADIO_EVENT_BCMATCH, HAL_TRIGGER_AAR_PPI); + nrf_aar_subscribe_set(NRF_AAR, NRF_AAR_TASK_START, HAL_TRIGGER_AAR_PPI); +} + +#if defined(CONFIG_BT_CTLR_PHY_CODED) && defined(CONFIG_HAS_HW_NRF_RADIO_BLE_CODED) +/******************************************************************************* + * Trigger Radio Rate override upon Rateboost event. + */ +static inline void hal_trigger_rateoverride_ppi_config(void) +{ + nrf_radio_publish_set(NRF_RADIO, NRF_RADIO_EVENT_RATEBOOST, HAL_TRIGGER_RATEOVERRIDE_PPI); + nrf_ccm_subscribe_set(NRF_CCM, NRF_CCM_TASK_RATEOVERRIDE, HAL_TRIGGER_RATEOVERRIDE_PPI); +} +#endif /* CONFIG_BT_CTLR_PHY_CODED && CONFIG_HAS_HW_NRF_RADIO_BLE_CODED */ +#endif /* CONFIG_BT_CTLR_LE_ENC || CONFIG_BT_CTLR_BROADCAST_ISO_ENC */ + #if defined(CONFIG_BT_CTLR_DF_CONN_CTE_RX) /******************************************************************************* * Trigger encryption task on Bit counter match: @@ -161,27 +184,6 @@ static inline void hal_trigger_crypt_by_bcmatch_ppi_config(void) } #endif /* CONFIG_BT_CTLR_DF_CONN_CTE_RX */ -/******************************************************************************* - * Trigger automatic address resolution on Bit counter match: - * wire the RADIO EVENTS_BCMATCH event to the AAR TASKS_START task. - */ -static inline void hal_trigger_aar_ppi_config(void) -{ - nrf_radio_publish_set(NRF_RADIO, NRF_RADIO_EVENT_BCMATCH, HAL_TRIGGER_AAR_PPI); - nrf_aar_subscribe_set(NRF_AAR, NRF_AAR_TASK_START, HAL_TRIGGER_AAR_PPI); -} - -#if defined(CONFIG_BT_CTLR_PHY_CODED) && defined(CONFIG_HAS_HW_NRF_RADIO_BLE_CODED) -/******************************************************************************* - * Trigger Radio Rate override upon Rateboost event. - */ -static inline void hal_trigger_rateoverride_ppi_config(void) -{ - nrf_radio_publish_set(NRF_RADIO, NRF_RADIO_EVENT_RATEBOOST, HAL_TRIGGER_RATEOVERRIDE_PPI); - nrf_ccm_subscribe_set(NRF_CCM, NRF_CCM_TASK_RATEOVERRIDE, HAL_TRIGGER_RATEOVERRIDE_PPI); -} -#endif /* CONFIG_BT_CTLR_PHY_CODED && CONFIG_HAS_HW_NRF_RADIO_BLE_CODED */ - /******************************************************************************/ #if !defined(CONFIG_BT_CTLR_TIFS_HW) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_iso.c index b3a86b7acb1..f11cd49c733 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv_iso.c @@ -351,7 +351,8 @@ static int prepare_cb_common(struct lll_prepare_param *p) /* Radio packet configuration */ pkt_flags = RADIO_PKT_CONF_FLAGS(RADIO_PKT_CONF_PDU_TYPE_BIS, phy, RADIO_PKT_CONF_CTE_DISABLED); - if (pdu->len && lll->enc) { + if (IS_ENABLED(CONFIG_BT_CTLR_BROADCAST_ISO_ENC) && + pdu->len && lll->enc) { /* Encryption */ lll->ccm_tx.counter = payload_count; @@ -698,7 +699,8 @@ static void isr_tx_common(void *param, lll_chan_set(data_chan_use); /* Encryption */ - if (pdu->len && lll->enc) { + if (IS_ENABLED(CONFIG_BT_CTLR_BROADCAST_ISO_ENC) && + pdu->len && lll->enc) { lll->ccm_tx.counter = payload_count; (void)memcpy(lll->ccm_tx.iv, lll->giv, 4U); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c index 96b932403aa..ebd7ccbb595 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_sync_iso.c @@ -305,7 +305,8 @@ static int prepare_cb_common(struct lll_prepare_param *p) LL_ASSERT(node_rx); /* Encryption */ - if (lll->enc) { + if (IS_ENABLED(CONFIG_BT_CTLR_BROADCAST_ISO_ENC) && + lll->enc) { uint64_t payload_count; uint8_t pkt_flags; @@ -619,7 +620,8 @@ static void isr_rx(void *param) !lll->payload[bis_idx][payload_index]) { uint16_t handle; - if (lll->enc) { + if (IS_ENABLED(CONFIG_BT_CTLR_BROADCAST_ISO_ENC) && + lll->enc) { uint32_t mic_failure; uint32_t done; @@ -922,7 +924,8 @@ isr_rx_next_subevent: lll_chan_set(data_chan_use); /* Encryption */ - if (lll->enc) { + if (IS_ENABLED(CONFIG_BT_CTLR_BROADCAST_ISO_ENC) && + lll->enc) { uint64_t payload_count; struct pdu_bis *pdu; diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c index 4c5265b799c..54e77951589 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c @@ -144,6 +144,12 @@ static uint8_t big_create(uint8_t big_handle, uint8_t adv_handle, uint8_t num_bi return BT_HCI_ERR_UNKNOWN_ADV_IDENTIFIER; } + /* Check if encryption supported */ + if (!IS_ENABLED(CONFIG_BT_CTLR_BROADCAST_ISO_ENC) && + encryption) { + return BT_HCI_ERR_CMD_DISALLOWED; + }; + if (IS_ENABLED(CONFIG_BT_CTLR_PARAM_CHECK)) { if (num_bis == 0U || num_bis > 0x1F) { return BT_HCI_ERR_INVALID_PARAM; @@ -566,7 +572,7 @@ static uint8_t big_create(uint8_t big_handle, uint8_t adv_handle, uint8_t num_bi big_info->payload_count_framing[4] &= ~BIT(7); big_info->payload_count_framing[4] |= ((framing & 0x01) << 7); - if (encryption) { + if (IS_ENABLED(CONFIG_BT_CTLR_BROADCAST_ISO_ENC) && encryption) { const uint8_t BIG1[16] = {0x31, 0x47, 0x49, 0x42, }; const uint8_t BIG2[4] = {0x32, 0x47, 0x49, 0x42}; const uint8_t BIG3[4] = {0x33, 0x47, 0x49, 0x42}; diff --git a/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c b/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c index 41a6d0a3037..9ad0a9cc3f8 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c @@ -125,6 +125,12 @@ uint8_t ll_big_sync_create(uint8_t big_handle, uint16_t sync_handle, last_index = bis[i]; } + /* Check if encryption supported */ + if (!IS_ENABLED(CONFIG_BT_CTLR_BROADCAST_ISO_ENC) && + encryption) { + return BT_HCI_ERR_CMD_DISALLOWED; + }; + /* Check if requested encryption matches */ if (encryption != sync->enc) { return BT_HCI_ERR_ENC_MODE_NOT_ACCEPTABLE; @@ -470,7 +476,8 @@ void ull_sync_iso_setup(struct ll_sync_iso_set *sync_iso, /* Set establishment event countdown */ lll->establish_events = CONN_ESTAB_COUNTDOWN; - if (lll->enc && (bi_size == PDU_BIG_INFO_ENCRYPTED_SIZE)) { + if (IS_ENABLED(CONFIG_BT_CTLR_BROADCAST_ISO_ENC) && + lll->enc && (bi_size == PDU_BIG_INFO_ENCRYPTED_SIZE)) { const uint8_t BIG3[4] = {0x33, 0x47, 0x49, 0x42}; struct ccm *ccm_rx; uint8_t gsk[16];