Skip to content

Commit 66312b0

Browse files
ppryga-nordiccarlescufi
authored andcommitted
Bluetooth: Host: df: Fix uninit per adv sync and IQ report passed to app
In case of error in hci_df_prepare_connectionless_iq_report function e.g. due to wrong periodic advertising sync handle, uninitilized per_adv_sync and IQ report object were passed by cte_report_cb callback to an application. Correct behavior in such situation is to not to cal cte_report_cb callback. Signed-off-by: Piotr Pryga <[email protected]>
1 parent a5fb434 commit 66312b0

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

subsys/bluetooth/host/direction.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,16 +368,16 @@ static int hci_df_set_cl_cte_rx_enable(struct bt_le_per_adv_sync *sync, bool ena
368368
return err;
369369
}
370370

371-
void hci_df_prepare_connectionless_iq_report(struct net_buf *buf,
372-
struct bt_df_per_adv_sync_iq_samples_report *report,
373-
struct bt_le_per_adv_sync **per_adv_sync_to_report)
371+
int hci_df_prepare_connectionless_iq_report(struct net_buf *buf,
372+
struct bt_df_per_adv_sync_iq_samples_report *report,
373+
struct bt_le_per_adv_sync **per_adv_sync_to_report)
374374
{
375375
struct bt_hci_evt_le_connectionless_iq_report *evt;
376376
struct bt_le_per_adv_sync *per_adv_sync;
377377

378378
if (buf->len < sizeof(*evt)) {
379379
BT_ERR("Unexpected end of buffer");
380-
return;
380+
return -EINVAL;
381381
}
382382

383383
evt = net_buf_pull_mem(buf, sizeof(*evt));
@@ -387,17 +387,17 @@ void hci_df_prepare_connectionless_iq_report(struct net_buf *buf,
387387
if (!per_adv_sync) {
388388
BT_ERR("Unknown handle 0x%04X for iq samples report",
389389
sys_le16_to_cpu(evt->sync_handle));
390-
return;
390+
return -EINVAL;
391391
}
392392

393393
if (!atomic_test_bit(per_adv_sync->flags, BT_PER_ADV_SYNC_CTE_ENABLED)) {
394394
BT_ERR("Received PA CTE report when CTE receive disabled");
395-
return;
395+
return -EINVAL;
396396
}
397397

398398
if (!(per_adv_sync->cte_types & BIT(evt->cte_type))) {
399399
BT_DBG("CTE filtered out by cte_type: %u", evt->cte_type);
400-
return;
400+
return -EINVAL;
401401
}
402402

403403
report->chan_idx = evt->chan_idx;
@@ -411,6 +411,8 @@ void hci_df_prepare_connectionless_iq_report(struct net_buf *buf,
411411
report->sample = &evt->sample[0];
412412

413413
*per_adv_sync_to_report = per_adv_sync;
414+
415+
return 0;
414416
}
415417
#endif /* CONFIG_BT_DF_CONNECTIONLESS_CTE_RX */
416418

subsys/bluetooth/host/direction_internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
/* Performs initialization of Direction Finding in Host */
88
int le_df_init(void);
99

10-
void hci_df_prepare_connectionless_iq_report(struct net_buf *buf,
11-
struct bt_df_per_adv_sync_iq_samples_report *report,
12-
struct bt_le_per_adv_sync **per_adv_sync_to_report);
10+
int hci_df_prepare_connectionless_iq_report(struct net_buf *buf,
11+
struct bt_df_per_adv_sync_iq_samples_report *report,
12+
struct bt_le_per_adv_sync **per_adv_sync_to_report);
1313
int hci_df_prepare_connection_iq_report(struct net_buf *buf,
1414
struct bt_df_conn_iq_samples_report *report,
1515
struct bt_conn **conn_to_report);

subsys/bluetooth/host/scan.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,11 +1088,17 @@ void bt_hci_le_biginfo_adv_report(struct net_buf *buf)
10881088
#if defined(CONFIG_BT_DF_CONNECTIONLESS_CTE_RX)
10891089
void bt_hci_le_df_connectionless_iq_report(struct net_buf *buf)
10901090
{
1091+
int err;
1092+
10911093
struct bt_df_per_adv_sync_iq_samples_report cte_report;
10921094
struct bt_le_per_adv_sync *per_adv_sync;
10931095
struct bt_le_per_adv_sync_cb *listener;
10941096

1095-
hci_df_prepare_connectionless_iq_report(buf, &cte_report, &per_adv_sync);
1097+
err = hci_df_prepare_connectionless_iq_report(buf, &cte_report, &per_adv_sync);
1098+
if (err) {
1099+
BT_ERR("Prepare CTE conn IQ report failed %d", err);
1100+
return;
1101+
}
10961102

10971103
SYS_SLIST_FOR_EACH_CONTAINER(&pa_sync_cbs, listener, node) {
10981104
if (listener->cte_report_cb) {

0 commit comments

Comments
 (0)