Skip to content

Commit a26ee7c

Browse files
ppryga-nordiccfriedt
authored andcommitted
Bluetooth: host: Add IQ reports handing in DF connecte mode
Add reception of IQ sample report from controller. Add applications notification about received reports. Signed-off-by: Piotr Pryga <[email protected]>
1 parent f18637f commit a26ee7c

File tree

7 files changed

+123
-0
lines changed

7 files changed

+123
-0
lines changed

include/bluetooth/conn.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <bluetooth/hci_err.h>
2424
#include <bluetooth/addr.h>
2525
#include <bluetooth/gap.h>
26+
#include <bluetooth/direction.h>
2627

2728
#ifdef __cplusplus
2829
extern "C" {
@@ -927,6 +928,17 @@ struct bt_conn_cb {
927928
struct bt_conn_le_data_len_info *info);
928929
#endif /* defined(CONFIG_BT_USER_DATA_LEN_UPDATE) */
929930

931+
#if defined(CONFIG_BT_DF_CONNECTION_CTE_RX)
932+
/** @brief Callback for IQ samples report collected when sampling
933+
* CTE received by data channel PDU.
934+
*
935+
* @param conn The connection object.
936+
* @param iq_report Report data for collected IQ samples.
937+
*/
938+
void (*cte_report_cb)(struct bt_conn *conn,
939+
const struct bt_df_conn_iq_samples_report *iq_report);
940+
#endif /* CONFIG_BT_DF_CONNECTION_CTE_RX */
941+
930942
struct bt_conn_cb *_next;
931943
};
932944

include/bluetooth/direction.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,28 @@ struct bt_df_conn_cte_rx_param {
120120
const uint8_t *ant_ids;
121121
};
122122

123+
struct bt_df_conn_iq_samples_report {
124+
/** PHY that was used to receive PDU with CTE that was sampled. */
125+
uint8_t rx_phy;
126+
/** Channel index used to receive PDU with CTE that was sampled. */
127+
uint8_t chan_idx;
128+
/** The RSSI of the PDU with CTE (excluding CTE). */
129+
int16_t rssi;
130+
/** Id of antenna used to measure the RSSI. */
131+
uint8_t rssi_ant_id;
132+
/** Type of CTE (@ref bt_df_cte_type). */
133+
uint8_t cte_type;
134+
/** Duration of slots when received CTE type is AoA (@ref bt_df_antenna_switching_slot). */
135+
uint8_t slot_durations;
136+
/** Status of received PDU with CTE (@ref bt_df_packet_status). */
137+
uint8_t packet_status;
138+
/** Value of connection event counter when the CTE was received and sampled. */
139+
uint16_t conn_evt_counter;
140+
/** Number of IQ samples in report. */
141+
uint8_t sample_count;
142+
/** Pinter to IQ samples data. */
143+
struct bt_hci_le_iq_sample const *sample;
144+
};
123145
/**
124146
* @brief Set or update the Constant Tone Extension parameters for periodic advertising set.
125147
*

subsys/bluetooth/host/conn.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <bluetooth/hci.h>
2121
#include <bluetooth/bluetooth.h>
22+
#include <bluetooth/direction.h>
2223
#include <bluetooth/conn.h>
2324
#include <drivers/bluetooth/hci_driver.h>
2425
#include <bluetooth/att.h>
@@ -38,6 +39,7 @@
3839
#include "att_internal.h"
3940
#include "gatt_internal.h"
4041
#include "iso_internal.h"
42+
#include "direction_internal.h"
4143

4244
struct tx_meta {
4345
struct bt_conn_tx *tx;
@@ -2921,4 +2923,33 @@ int bt_conn_init(void)
29212923
return 0;
29222924
}
29232925

2926+
#if defined(CONFIG_BT_DF_CONNECTION_CTE_RX)
2927+
void bt_hci_le_df_connection_iq_report(struct net_buf *buf)
2928+
{
2929+
struct bt_df_conn_iq_samples_report iq_report;
2930+
struct bt_conn *conn;
2931+
struct bt_conn_cb *cb;
2932+
int err;
2933+
2934+
err = hci_df_prepare_connection_iq_report(buf, &iq_report, &conn);
2935+
if (err) {
2936+
BT_ERR("Prepare CTE conn IQ report failed %d", err);
2937+
return;
2938+
}
2939+
2940+
for (cb = callback_list; cb; cb = cb->_next) {
2941+
if (cb->cte_report_cb) {
2942+
cb->cte_report_cb(conn, &iq_report);
2943+
}
2944+
}
2945+
2946+
STRUCT_SECTION_FOREACH(bt_conn_cb, cb)
2947+
{
2948+
if (cb->cte_report_cb) {
2949+
cb->cte_report_cb(conn, &iq_report);
2950+
}
2951+
}
2952+
}
2953+
#endif /* CONFIG_BT_DF_CONNECTION_CTE_RX */
2954+
29242955
#endif /* CONFIG_BT_CONN */

subsys/bluetooth/host/direction.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,55 @@ static int hci_df_set_conn_cte_rx_enable(struct bt_conn *conn, bool enable,
542542

543543
return err;
544544
}
545+
546+
int hci_df_prepare_connection_iq_report(struct net_buf *buf,
547+
struct bt_df_conn_iq_samples_report *report,
548+
struct bt_conn **conn_to_report)
549+
{
550+
struct bt_hci_evt_le_connection_iq_report *evt;
551+
struct bt_conn *conn;
552+
553+
if (buf->len < sizeof(*evt)) {
554+
BT_ERR("Unexpected end of buffer");
555+
return -EINVAL;
556+
}
557+
558+
evt = net_buf_pull_mem(buf, sizeof(*evt));
559+
560+
conn = bt_conn_lookup_handle(sys_le16_to_cpu(evt->conn_handle));
561+
562+
if (!conn) {
563+
BT_ERR("Unknown conn handle 0x%04X for iq samples report",
564+
sys_le16_to_cpu(evt->conn_handle));
565+
return -EINVAL;
566+
}
567+
568+
if (!atomic_test_bit(conn->flags, BT_CONN_CTE_RX_ENABLED)) {
569+
BT_ERR("Received conn CTE report when CTE receive disabled");
570+
return -EINVAL;
571+
}
572+
573+
if (!(conn->cte_type & BIT(evt->cte_type))) {
574+
BT_DBG("CTE filtered out by cte_type: %u", evt->cte_type);
575+
return -EINVAL;
576+
}
577+
578+
report->chan_idx = evt->data_chan_idx;
579+
report->rx_phy = evt->rx_phy;
580+
report->chan_idx = evt->data_chan_idx;
581+
report->rssi = evt->rssi;
582+
report->rssi_ant_id = evt->rssi_ant_id;
583+
report->cte_type = BIT(evt->cte_type);
584+
report->packet_status = evt->packet_status;
585+
report->slot_durations = evt->slot_durations;
586+
report->conn_evt_counter = sys_le16_to_cpu(evt->conn_evt_counter);
587+
report->sample_count = evt->sample_count;
588+
report->sample = evt->sample;
589+
590+
*conn_to_report = conn;
591+
592+
return 0;
593+
}
545594
#endif /* CONFIG_BT_DF_CONNECTION_CTE_RX */
546595

547596
/* @brief Function initializes Direction Finding in Host

subsys/bluetooth/host/direction_internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ int le_df_init(void);
1010
void hci_df_prepare_connectionless_iq_report(struct net_buf *buf,
1111
struct bt_df_per_adv_sync_iq_samples_report *report,
1212
struct bt_le_per_adv_sync **per_adv_sync_to_report);
13+
int hci_df_prepare_connection_iq_report(struct net_buf *buf,
14+
struct bt_df_conn_iq_samples_report *report,
15+
struct bt_conn **conn_to_report);

subsys/bluetooth/host/hci_core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,6 +2225,10 @@ static const struct event_handler meta_events[] = {
22252225
EVENT_HANDLER(BT_HCI_EVT_LE_CONNECTIONLESS_IQ_REPORT, bt_hci_le_df_connectionless_iq_report,
22262226
sizeof(struct bt_hci_evt_le_connectionless_iq_report)),
22272227
#endif /* CONFIG_BT_DF_CONNECTIONLESS_CTE_RX */
2228+
#if defined(CONFIG_BT_DF_CONNECTION_CTE_RX)
2229+
EVENT_HANDLER(BT_HCI_EVT_LE_CONNECTION_IQ_REPORT, bt_hci_le_df_connection_iq_report,
2230+
sizeof(struct bt_hci_evt_le_connection_iq_report)),
2231+
#endif /* CONFIG_BT_DF_CONNECTION_CTE_RX */
22282232
};
22292233

22302234
static void hci_le_meta_event(struct net_buf *buf)

subsys/bluetooth/host/hci_core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,3 +450,5 @@ void bt_hci_read_remote_features_complete(struct net_buf *buf);
450450
void bt_hci_read_remote_ext_features_complete(struct net_buf *buf);
451451
void bt_hci_role_change(struct net_buf *buf);
452452
void bt_hci_synchronous_conn_complete(struct net_buf *buf);
453+
454+
void bt_hci_le_df_connection_iq_report(struct net_buf *buf);

0 commit comments

Comments
 (0)