@@ -156,6 +156,40 @@ static int hci_df_read_ant_info(uint8_t *switch_sample_rates,
156156 return 0 ;
157157}
158158
159+ /* @brief Function handles send of HCI commnad to enable or disables CTE
160+ * transmission for given advertising set.
161+ *
162+ * @param[in] adv Pointer to advertising set
163+ * @param[in] enable Enable or disable CTE TX
164+ *
165+ * @return Zero in case of success, other value in case of failure.
166+ */
167+ static int hci_df_set_adv_cte_tx_enable (struct bt_le_ext_adv * adv ,
168+ bool enable )
169+ {
170+ struct bt_hci_cp_le_set_cl_cte_tx_enable * cp ;
171+ struct bt_hci_cmd_state_set state ;
172+ struct net_buf * buf ;
173+
174+ buf = bt_hci_cmd_create (BT_HCI_OP_LE_SET_CL_CTE_TX_ENABLE , sizeof (* cp ));
175+ if (!buf ) {
176+ return - ENOBUFS ;
177+ }
178+
179+ cp = net_buf_add (buf , sizeof (* cp ));
180+ (void )memset (cp , 0 , sizeof (* cp ));
181+
182+ cp -> handle = adv -> handle ;
183+ cp -> cte_enable = enable ? 1 : 0 ;
184+
185+ bt_hci_cmd_state_set_init (& state , adv -> flags , BT_PER_ADV_CTE_ENABLED ,
186+ enable );
187+ bt_hci_cmd_data_state_set (buf , & state );
188+
189+ return bt_hci_cmd_send_sync (BT_HCI_OP_LE_SET_CL_CTE_TX_ENABLE ,
190+ buf , NULL );
191+ }
192+
159193/* @brief Function sets CTE parameters for connection object
160194 *
161195 * @param[in] cte_types Allowed response CTE types
@@ -271,10 +305,45 @@ int bt_df_set_adv_cte_tx_param(struct bt_le_ext_adv *adv,
271305 return - EINVAL ;
272306 }
273307
308+ if (atomic_test_bit (adv -> flags , BT_PER_ADV_CTE_ENABLED )) {
309+ return - EINVAL ;
310+ }
311+
274312 err = hci_df_set_cl_cte_tx_params (adv , params );
275313 if (err ) {
276314 return err ;
277315 }
278316
317+ atomic_set_bit (adv -> flags , BT_PER_ADV_CTE_PARAMS_SET );
318+
279319 return 0 ;
280320}
321+
322+ static int bt_df_set_adv_cte_tx_enabled (struct bt_le_ext_adv * adv , bool enable )
323+ {
324+ if (!atomic_test_bit (adv -> flags , BT_PER_ADV_PARAMS_SET )) {
325+ return - EINVAL ;
326+ }
327+
328+ if (!atomic_test_bit (adv -> flags , BT_PER_ADV_CTE_PARAMS_SET )) {
329+ return - EINVAL ;
330+ }
331+
332+ if (enable == atomic_test_bit (adv -> flags , BT_PER_ADV_CTE_ENABLED )) {
333+ return - EALREADY ;
334+ }
335+
336+ return hci_df_set_adv_cte_tx_enable (adv , enable );
337+ }
338+
339+ int bt_df_adv_cte_tx_enable (struct bt_le_ext_adv * adv )
340+ {
341+ __ASSERT_NO_MSG (adv );
342+ return bt_df_set_adv_cte_tx_enabled (adv , true);
343+ }
344+
345+ int bt_df_adv_cte_tx_disable (struct bt_le_ext_adv * adv )
346+ {
347+ __ASSERT_NO_MSG (adv );
348+ return bt_df_set_adv_cte_tx_enabled (adv , false);
349+ }
0 commit comments