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/kernel.h> 9 10 #include "util/util.h" 11 #include "util/memq.h" 12 #include "util/dbuf.h" 13 14 #include "hal/ccm.h" 15 16 #include "pdu_df.h" 17 #include "lll/pdu_vendor.h" 18 #include "pdu.h" 19 20 #include "lll.h" 21 #include "lll/lll_df_types.h" 22 #include "lll_conn.h" 23 24 #include "ull_conn_internal.h" 25 26 #include "ll_feat.h" 27 #include "ll_settings.h" 28 29 #include <zephyr/bluetooth/hci_types.h> 30 31 #include "hal/debug.h" 32 33 #if defined(CONFIG_BT_CTLR_SET_HOST_FEATURE) 34 static uint64_t host_features; 35 ll_set_host_feature(uint8_t bit_number,uint8_t bit_value)36uint8_t ll_set_host_feature(uint8_t bit_number, uint8_t bit_value) 37 { 38 uint64_t feature; 39 40 /* Check if Bit_Number is not controlled by the Host */ 41 feature = BIT64(bit_number); 42 if (!(feature & LL_FEAT_HOST_BIT_MASK)) { 43 return BT_HCI_ERR_UNSUPP_FEATURE_PARAM_VAL; 44 } 45 46 #if defined(CONFIG_BT_CONN) 47 /* Check if the Controller has an established ACL */ 48 uint16_t conn_free_count = ll_conn_free_count_get(); 49 50 /* Check if any connection contexts where allocated */ 51 if (conn_free_count != CONFIG_BT_MAX_CONN) { 52 uint16_t handle; 53 54 /* Check if there are established connections */ 55 for (handle = 0U; handle < CONFIG_BT_MAX_CONN; handle++) { 56 if (ll_connected_get(handle)) { 57 return BT_HCI_ERR_CMD_DISALLOWED; 58 } 59 } 60 } 61 #endif /* CONFIG_BT_CONN */ 62 63 /* Set or Clear the Host feature bit */ 64 if (bit_value) { 65 host_features |= feature; 66 } else { 67 host_features &= ~feature; 68 } 69 70 return BT_HCI_ERR_SUCCESS; 71 } 72 ll_feat_reset(void)73void ll_feat_reset(void) 74 { 75 host_features = 0U; 76 } 77 ll_feat_get(void)78uint64_t ll_feat_get(void) 79 { 80 return LL_FEAT | (host_features & LL_FEAT_HOST_BIT_MASK); 81 } 82 83 #else /* !CONFIG_BT_CTLR_SET_HOST_FEATURE */ ll_feat_get(void)84uint64_t ll_feat_get(void) 85 { 86 return LL_FEAT; 87 } 88 89 #endif /* !CONFIG_BT_CTLR_SET_HOST_FEATURE */ 90