1 /* 2 * Copyright (c) 2021 Nordic Semiconductor ASA 3 * Copyright (c) 2020 Demant 4 * 5 * SPDX-License-Identifier: Apache-2.0 6 */ 7 8 #include <zephyr.h> 9 10 #include "util/util.h" 11 #include "util/memq.h" 12 13 #include "hal/ccm.h" 14 15 #include "pdu.h" 16 17 #include "lll.h" 18 #include "lll/lll_df_types.h" 19 #include "lll_conn.h" 20 21 #include "ull_conn_internal.h" 22 23 #include "ll_feat.h" 24 25 #define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER) 26 #define LOG_MODULE_NAME bt_ctlr_ll_feat 27 #include "common/log.h" 28 #include "hal/debug.h" 29 30 #if defined(CONFIG_BT_CTLR_SET_HOST_FEATURE) 31 static uint64_t host_features; 32 ll_set_host_feature(uint8_t bit_number,uint8_t bit_value)33uint8_t ll_set_host_feature(uint8_t bit_number, uint8_t bit_value) 34 { 35 uint64_t feature; 36 37 /* Check if Bit_Number is not controlled by the Host */ 38 feature = BIT64(bit_number); 39 if (!(feature & LL_FEAT_HOST_BIT_MASK)) { 40 return BT_HCI_ERR_UNSUPP_FEATURE_PARAM_VAL; 41 } 42 43 #if defined(CONFIG_BT_CONN) 44 /* Check if the Controller has an established ACL */ 45 uint16_t conn_free_count = ll_conn_free_count_get(); 46 47 /* Check if any connection contexts where allocated */ 48 if (conn_free_count != CONFIG_BT_MAX_CONN) { 49 uint16_t handle; 50 51 /* Check if there are established connections */ 52 for (handle = 0U; handle < CONFIG_BT_MAX_CONN; handle++) { 53 if (ll_connected_get(handle)) { 54 return BT_HCI_ERR_CMD_DISALLOWED; 55 } 56 } 57 } 58 #endif /* CONFIG_BT_CONN */ 59 60 /* Set or Clear the Host feature bit */ 61 if (bit_value) { 62 host_features |= feature; 63 } else { 64 host_features &= ~feature; 65 } 66 67 return BT_HCI_ERR_SUCCESS; 68 } 69 ll_feat_get(void)70uint64_t ll_feat_get(void) 71 { 72 return LL_FEAT | (host_features & LL_FEAT_HOST_BIT_MASK); 73 } 74 75 #else /* !CONFIG_BT_CTLR_SET_HOST_FEATURE */ ll_feat_get(void)76uint64_t ll_feat_get(void) 77 { 78 return LL_FEAT; 79 } 80 81 #endif /* !CONFIG_BT_CTLR_SET_HOST_FEATURE */ 82