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