1 /*
2  * Copyright (c) 2018-2019 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
feature_unmask_features(struct ll_conn * conn,uint64_t ll_feat_mask)7 static inline void feature_unmask_features(struct ll_conn *conn, uint64_t ll_feat_mask)
8 {
9 	conn->llcp.fex.features_used &= ~ll_feat_mask;
10 }
11 
feature_unmask_peer_features(struct ll_conn * conn,uint64_t ll_feat_mask)12 static inline void feature_unmask_peer_features(struct ll_conn *conn, uint64_t ll_feat_mask)
13 {
14 	conn->llcp.fex.features_peer &= ~ll_feat_mask;
15 }
16 
feature_le_encryption(struct ll_conn * conn)17 static inline bool feature_le_encryption(struct ll_conn *conn)
18 {
19 #if defined(CONFIG_BT_CTLR_LE_ENC)
20 	return (conn->llcp.fex.features_used & LL_FEAT_BIT_ENC) != 0;
21 #else
22 	return 0;
23 #endif
24 }
25 
feature_conn_param_req(struct ll_conn * conn)26 static inline bool feature_conn_param_req(struct ll_conn *conn)
27 {
28 #if defined(CONFIG_BT_CTLR_CONN_PARAM_REQ)
29 	return (conn->llcp.fex.features_used & LL_FEAT_BIT_CONN_PARAM_REQ) != 0;
30 #else
31 	return 0;
32 #endif
33 }
34 
feature_ext_rej_ind(struct ll_conn * conn)35 static inline bool feature_ext_rej_ind(struct ll_conn *conn)
36 {
37 #if defined(CONFIG_BT_CTLR_EXT_REJ_IND)
38 	return (conn->llcp.fex.features_used & LL_FEAT_BIT_EXT_REJ_IND) != 0;
39 #else
40 	return 0;
41 #endif
42 }
43 
feature_periph_feat_req(struct ll_conn * conn)44 static inline bool feature_periph_feat_req(struct ll_conn *conn)
45 {
46 #if defined(CONFIG_BT_CTLR_PER_INIT_FEAT_XCHG)
47 	return (conn->llcp.fex.features_used & LL_FEAT_BIT_PER_INIT_FEAT_XCHG) != 0;
48 #else
49 	return 0;
50 #endif
51 }
52 
feature_le_ping(struct ll_conn * conn)53 static inline bool feature_le_ping(struct ll_conn *conn)
54 {
55 #if defined(CONFIG_BT_CTLR_LE_PING)
56 	return (conn->llcp.fex.features_used & LL_FEAT_BIT_PING) != 0;
57 #else
58 	return 0;
59 #endif
60 }
61 
feature_dle(struct ll_conn * conn)62 static inline bool feature_dle(struct ll_conn *conn)
63 {
64 #if defined(CONFIG_BT_CTLR_DATA_LENGTH)
65 	return (conn->llcp.fex.features_used & LL_FEAT_BIT_DLE) != 0;
66 #else
67 	return 0;
68 #endif
69 }
70 
feature_privacy(struct ll_conn * conn)71 static inline bool feature_privacy(struct ll_conn *conn)
72 {
73 #if defined(CONFIG_BT_CTLR_PRIVACY)
74 	return (conn->llcp.fex.features_used & LL_FEAT_BIT_PRIVACY) != 0;
75 #else
76 	return 0;
77 #endif
78 }
79 
feature_ext_scan(struct ll_conn * conn)80 static inline bool feature_ext_scan(struct ll_conn *conn)
81 {
82 #if defined(CONFIG_BT_CTLR_EXT_SCAN_FP)
83 	return (conn->llcp.fex.features_used & LL_FEAT_BIT_EXT_SCAN) != 0;
84 #else
85 	return 0;
86 #endif
87 }
88 
feature_chan_sel_2(struct ll_conn * conn)89 static inline bool feature_chan_sel_2(struct ll_conn *conn)
90 {
91 #if defined(CONFIG_BT_CTLR_CHAN_SEL_2)
92 	return (conn->llcp.fex.features_used & LL_FEAT_BIT_CHAN_SEL_2) != 0;
93 #else
94 	return 0;
95 #endif
96 }
97 
feature_min_used_chan(struct ll_conn * conn)98 static inline bool feature_min_used_chan(struct ll_conn *conn)
99 {
100 #if defined(CONFIG_BT_CTLR_MIN_USED_CHAN)
101 	return (conn->llcp.fex.features_used & LL_FEAT_BIT_MIN_USED_CHAN) != 0;
102 #else
103 	return 0;
104 #endif
105 }
106 
feature_phy_2m(struct ll_conn * conn)107 static inline bool feature_phy_2m(struct ll_conn *conn)
108 {
109 #if defined(CONFIG_BT_CTLR_PHY_2M)
110 	return (conn->llcp.fex.features_used & LL_FEAT_BIT_PHY_2M) != 0;
111 #else
112 	return 0;
113 #endif
114 }
115 
feature_phy_coded(struct ll_conn * conn)116 static inline bool feature_phy_coded(struct ll_conn *conn)
117 {
118 #if defined(CONFIG_BT_CTLR_PHY_CODED)
119 	return (conn->llcp.fex.features_used & LL_FEAT_BIT_PHY_CODED) != 0;
120 #else
121 	return 0;
122 #endif
123 }
124 
feature_cte_req(struct ll_conn * conn)125 static inline bool feature_cte_req(struct ll_conn *conn)
126 {
127 #if defined(CONFIG_BT_CTLR_DF) && defined(CONFIG_BT_CTLR_DF_CONN_CTE_REQ)
128 	return (conn->llcp.fex.features_used & LL_FEAT_BIT_CONNECTION_CTE_REQ) != 0;
129 #else
130 	return 0;
131 #endif
132 }
133 
feature_sca(struct ll_conn * conn)134 static inline bool feature_sca(struct ll_conn *conn)
135 {
136 #if defined(CONFIG_BT_CTLR_SCA_UPDATE)
137 	return (conn->llcp.fex.features_used & LL_FEAT_BIT_SCA_UPDATE) != 0;
138 #else
139 	return 0;
140 #endif
141 }
142 
143 /*
144  * for asymmetric features we can check either if we support it
145  * or if the peer supports it
146  */
feature_smi_rx(void)147 static inline bool feature_smi_rx(void)
148 {
149 	return LL_FEAT_BIT_SMI_RX != 0;
150 }
151 
feature_peer_smi_rx(struct ll_conn * conn)152 static inline bool feature_peer_smi_rx(struct ll_conn *conn)
153 {
154 	return (conn->llcp.fex.features_peer & BIT64(BT_LE_FEAT_BIT_SMI_RX)) != 0;
155 }
156 
feature_smi_tx(void)157 static inline bool feature_smi_tx(void)
158 {
159 	return LL_FEAT_BIT_SMI_TX != 0;
160 }
161 
feature_peer_smi_tx(struct ll_conn * conn)162 static inline bool feature_peer_smi_tx(struct ll_conn *conn)
163 {
164 	return (conn->llcp.fex.features_peer & BIT64(BT_LE_FEAT_BIT_SMI_TX)) != 0;
165 }
166 
feature_peer_iso_central(struct ll_conn * conn)167 static inline bool feature_peer_iso_central(struct ll_conn *conn)
168 {
169 	return (conn->llcp.fex.features_peer & BIT64(BT_LE_FEAT_BIT_CIS_CENTRAL)) != 0;
170 }
171 
feature_iso_central(struct ll_conn * conn)172 static inline bool feature_iso_central(struct ll_conn *conn)
173 {
174 	return LL_FEAT_BIT_CIS_CENTRAL != 0;
175 }
176 
feature_peer_iso_peripheral(struct ll_conn * conn)177 static inline bool feature_peer_iso_peripheral(struct ll_conn *conn)
178 {
179 	return (conn->llcp.fex.features_peer & BIT64(BT_LE_FEAT_BIT_CIS_PERIPHERAL)) != 0;
180 }
181 
feature_iso_peripheral(struct ll_conn * conn)182 static inline bool feature_iso_peripheral(struct ll_conn *conn)
183 {
184 	return LL_FEAT_BIT_CIS_PERIPHERAL != 0;
185 }
186 
187 /*
188  * The following features are not yet defined in KConfig and do
189  * not have a bitfield defined in ll_feat.h
190  * ext_adv
191  * per_adv
192  * pwr_class1
193  * min_chann
194  * ant_sw_CTE_tx
195  * ant_sw_CTE_rx
196  * tone_ext
197  * per_adv_sync_tx
198  * per_adv_sync_rx
199  * rpk_valid
200  * iso_central
201  * iso_periph
202  * iso_broadcast
203  * iso_receiver
204  * iso_channels
205  * le_pwr_req
206  * le_pwr_ind
207  * le_path_loss
208  */
209