Skip to content

[nrf fromtree] Cherry pick cs complete events with status #2698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 39 additions & 17 deletions include/zephyr/bluetooth/conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -1847,35 +1847,50 @@ struct bt_conn_cb {
#if defined(CONFIG_BT_CHANNEL_SOUNDING)
/** @brief LE CS Read Remote Supported Capabilities Complete event.
*
* This callback notifies the application that the remote channel
* This callback notifies the application that a Channel Sounding
* Capabilities Exchange procedure has completed.
*
* If status is BT_HCI_ERR_SUCCESS, the remote channel
* sounding capabilities have been received from the peer.
*
* @param conn Connection object.
* @param remote_cs_capabilities Remote Channel Sounding Capabilities.
* @param status HCI status of complete event.
* @param remote_cs_capabilities Pointer to CS Capabilities on success or NULL otherwise.
*/
void (*le_cs_remote_capabilities_available)(struct bt_conn *conn,
struct bt_conn_le_cs_capabilities *params);
void (*le_cs_read_remote_capabilities_complete)(struct bt_conn *conn,
uint8_t status,
struct bt_conn_le_cs_capabilities *params);

/** @brief LE CS Read Remote FAE Table Complete event.
*
* This callback notifies the application that the remote mode-0
* This callback notifies the application that a Channel Sounding
* Mode-0 FAE Table Request procedure has completed.
*
* If status is BT_HCI_ERR_SUCCESS, the remote mode-0
* FAE Table has been received from the peer.
*
* @param conn Connection object.
* @param params FAE Table.
* @param status HCI status of complete event.
* @param params Pointer to FAE Table on success or NULL otherwise.
*/
void (*le_cs_remote_fae_table_available)(struct bt_conn *conn,
struct bt_conn_le_cs_fae_table *params);
void (*le_cs_read_remote_fae_table_complete)(struct bt_conn *conn,
uint8_t status,
struct bt_conn_le_cs_fae_table *params);

/** @brief LE CS Config created.
*
* This callback notifies the application that a Channel Sounding
* Configuration procedure has completed and a new CS config is created
* Configuration procedure has completed.
*
* If status is BT_HCI_ERR_SUCCESS, a new CS config is created.
*
* @param conn Connection object.
* @param config CS configuration.
* @param status HCI status of complete event.
* @param config Pointer to CS configuration on success or NULL otherwise.
*/
void (*le_cs_config_created)(struct bt_conn *conn, struct bt_conn_le_cs_config *config);
void (*le_cs_config_complete)(struct bt_conn *conn,
uint8_t status,
struct bt_conn_le_cs_config *config);

/** @brief LE CS Config removed.
*
Expand All @@ -1901,22 +1916,29 @@ struct bt_conn_cb {
/** @brief LE CS Security Enabled.
*
* This callback notifies the application that a Channel Sounding
* Security Enable procedure has completed
* Security Enable procedure has completed.
*
* If status is BT_HCI_ERR_SUCCESS, CS Security is enabled.
*
* @param conn Connection object.
* @param status HCI status of complete event.
*/
void (*le_cs_security_enabled)(struct bt_conn *conn);
void (*le_cs_security_enable_complete)(struct bt_conn *conn, uint8_t status);

/** @brief LE CS Procedure Enabled.
*
* This callback notifies the application that a Channel Sounding
* Procedure Enable procedure has completed
* Procedure Enable procedure has completed.
*
* If status is BT_HCI_ERR_SUCCESS, CS procedure is enabled.
*
* @param conn Connection object.
* @param params CS Procedure Enable parameters
* @param status HCI status.
* @param params Pointer to CS Procedure Enable parameters on success or NULL otherwise.
*/
void (*le_cs_procedure_enabled)(
struct bt_conn *conn, struct bt_conn_le_cs_procedure_enable_complete *params);
void (*le_cs_procedure_enable_complete)(
struct bt_conn *conn, uint8_t status,
struct bt_conn_le_cs_procedure_enable_complete *params);

#endif

Expand Down
56 changes: 39 additions & 17 deletions samples/bluetooth/channel_sounding/src/connected_cs_initiator.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,32 +138,54 @@ static void security_changed_cb(struct bt_conn *conn, bt_security_t level, enum
k_sem_give(&sem_acl_encryption_enabled);
}

static void remote_capabilities_cb(struct bt_conn *conn, struct bt_conn_le_cs_capabilities *params)
static void remote_capabilities_cb(struct bt_conn *conn,
uint8_t status,
struct bt_conn_le_cs_capabilities *params)
{
ARG_UNUSED(params);
printk("CS capability exchange completed.\n");
k_sem_give(&sem_remote_capabilities_obtained);

if (status == BT_HCI_ERR_SUCCESS) {
printk("CS capability exchange completed.\n");
k_sem_give(&sem_remote_capabilities_obtained);
} else {
printk("CS capability exchange failed. (HCI status 0x%02x)\n", status);
}
}

static void config_created_cb(struct bt_conn *conn, struct bt_conn_le_cs_config *config)
static void config_create_cb(struct bt_conn *conn,
uint8_t status,
struct bt_conn_le_cs_config *config)
{
printk("CS config creation complete. ID: %d\n", config->id);
k_sem_give(&sem_config_created);
if (status == BT_HCI_ERR_SUCCESS) {
printk("CS config creation complete. ID: %d\n", config->id);
k_sem_give(&sem_config_created);
} else {
printk("CS config creation failed. (HCI status 0x%02x)\n", status);
}
}

static void security_enabled_cb(struct bt_conn *conn)
static void security_enable_cb(struct bt_conn *conn, uint8_t status)
{
printk("CS security enabled.\n");
k_sem_give(&sem_cs_security_enabled);
if (status == BT_HCI_ERR_SUCCESS) {
printk("CS security enabled.\n");
k_sem_give(&sem_cs_security_enabled);
} else {
printk("CS security enable failed. (HCI status 0x%02x)\n", status);
}
}

static void procedure_enabled_cb(struct bt_conn *conn,
static void procedure_enable_cb(struct bt_conn *conn,
uint8_t status,
struct bt_conn_le_cs_procedure_enable_complete *params)
{
if (params->state == 1) {
printk("CS procedures enabled.\n");
if (status == BT_HCI_ERR_SUCCESS) {
if (params->state == 1) {
printk("CS procedures enabled.\n");
} else {
printk("CS procedures disabled.\n");
}
} else {
printk("CS procedures disabled.\n");
printk("CS procedures enable failed. (HCI status 0x%02x)\n", status);
}
}

Expand Down Expand Up @@ -223,10 +245,10 @@ BT_CONN_CB_DEFINE(conn_cb) = {
.connected = connected_cb,
.disconnected = disconnected_cb,
.security_changed = security_changed_cb,
.le_cs_remote_capabilities_available = remote_capabilities_cb,
.le_cs_config_created = config_created_cb,
.le_cs_security_enabled = security_enabled_cb,
.le_cs_procedure_enabled = procedure_enabled_cb,
.le_cs_read_remote_capabilities_complete = remote_capabilities_cb,
.le_cs_config_complete = config_create_cb,
.le_cs_security_enable_complete = security_enable_cb,
.le_cs_procedure_enable_complete = procedure_enable_cb,
.le_cs_subevent_data_available = subevent_result_cb,
};

Expand Down
58 changes: 40 additions & 18 deletions samples/bluetooth/channel_sounding/src/connected_cs_reflector.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,54 @@ static void disconnected_cb(struct bt_conn *conn, uint8_t reason)
connection = NULL;
}

static void remote_capabilities_cb(struct bt_conn *conn, struct bt_conn_le_cs_capabilities *params)
static void remote_capabilities_cb(struct bt_conn *conn,
uint8_t status,
struct bt_conn_le_cs_capabilities *params)
{
ARG_UNUSED(params);
printk("CS capability exchange completed.\n");
k_sem_give(&sem_remote_capabilities_obtained);

if (status == BT_HCI_ERR_SUCCESS) {
printk("CS capability exchange completed.\n");
k_sem_give(&sem_remote_capabilities_obtained);
} else {
printk("CS capability exchange failed. (HCI status 0x%02x)\n", status);
}
}

static void config_created_cb(struct bt_conn *conn, struct bt_conn_le_cs_config *config)
static void config_create_cb(struct bt_conn *conn,
uint8_t status,
struct bt_conn_le_cs_config *config)
{
printk("CS config creation complete. ID: %d\n", config->id);
k_sem_give(&sem_config_created);
if (status == BT_HCI_ERR_SUCCESS) {
printk("CS config creation complete. ID: %d\n", config->id);
k_sem_give(&sem_config_created);
} else {
printk("CS config creation failed. (HCI status 0x%02x)\n", status);
}
}

static void security_enabled_cb(struct bt_conn *conn)
static void security_enable_cb(struct bt_conn *conn, uint8_t status)
{
printk("CS security enabled.\n");
k_sem_give(&sem_cs_security_enabled);
if (status == BT_HCI_ERR_SUCCESS) {
printk("CS security enabled.\n");
k_sem_give(&sem_cs_security_enabled);
} else {
printk("CS security enable failed. (HCI status 0x%02x)\n", status);
}
}

static void procedure_enabled_cb(struct bt_conn *conn,
struct bt_conn_le_cs_procedure_enable_complete *params)
static void procedure_enable_cb(struct bt_conn *conn,
uint8_t status,
struct bt_conn_le_cs_procedure_enable_complete *params)
{
if (params->state == 1) {
printk("CS procedures enabled.\n");
if (status == BT_HCI_ERR_SUCCESS) {
if (params->state == 1) {
printk("CS procedures enabled.\n");
} else {
printk("CS procedures disabled.\n");
}
} else {
printk("CS procedures disabled.\n");
printk("CS procedures enable failed. (HCI status 0x%02x)\n", status);
}
}

Expand Down Expand Up @@ -160,10 +182,10 @@ static void write_func(struct bt_conn *conn, uint8_t err, struct bt_gatt_write_p
BT_CONN_CB_DEFINE(conn_cb) = {
.connected = connected_cb,
.disconnected = disconnected_cb,
.le_cs_remote_capabilities_available = remote_capabilities_cb,
.le_cs_config_created = config_created_cb,
.le_cs_security_enabled = security_enabled_cb,
.le_cs_procedure_enabled = procedure_enabled_cb,
.le_cs_read_remote_capabilities_complete = remote_capabilities_cb,
.le_cs_config_complete = config_create_cb,
.le_cs_security_enable_complete = security_enable_cb,
.le_cs_procedure_enable_complete = procedure_enable_cb,
.le_cs_subevent_data_available = subevent_result_cb,
};

Expand Down
53 changes: 28 additions & 25 deletions subsys/bluetooth/host/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -3340,53 +3340,56 @@ int bt_conn_le_subrate_request(struct bt_conn *conn,
#endif /* CONFIG_BT_SUBRATING */

#if defined(CONFIG_BT_CHANNEL_SOUNDING)
void notify_remote_cs_capabilities(struct bt_conn *conn, struct bt_conn_le_cs_capabilities params)
void notify_remote_cs_capabilities(struct bt_conn *conn, uint8_t status,
struct bt_conn_le_cs_capabilities *params)
{
struct bt_conn_cb *callback;

SYS_SLIST_FOR_EACH_CONTAINER(&conn_cbs, callback, _node) {
if (callback->le_cs_remote_capabilities_available) {
callback->le_cs_remote_capabilities_available(conn, &params);
if (callback->le_cs_read_remote_capabilities_complete) {
callback->le_cs_read_remote_capabilities_complete(conn, status, params);
}
}

STRUCT_SECTION_FOREACH(bt_conn_cb, cb) {
if (cb->le_cs_remote_capabilities_available) {
cb->le_cs_remote_capabilities_available(conn, &params);
if (cb->le_cs_read_remote_capabilities_complete) {
cb->le_cs_read_remote_capabilities_complete(conn, status, params);
}
}
}

void notify_remote_cs_fae_table(struct bt_conn *conn, struct bt_conn_le_cs_fae_table params)
void notify_remote_cs_fae_table(struct bt_conn *conn, uint8_t status,
struct bt_conn_le_cs_fae_table *params)
{
struct bt_conn_cb *callback;

SYS_SLIST_FOR_EACH_CONTAINER(&conn_cbs, callback, _node) {
if (callback->le_cs_remote_fae_table_available) {
callback->le_cs_remote_fae_table_available(conn, &params);
if (callback->le_cs_read_remote_fae_table_complete) {
callback->le_cs_read_remote_fae_table_complete(conn, status, params);
}
}

STRUCT_SECTION_FOREACH(bt_conn_cb, cb) {
if (cb->le_cs_remote_fae_table_available) {
cb->le_cs_remote_fae_table_available(conn, &params);
if (cb->le_cs_read_remote_fae_table_complete) {
cb->le_cs_read_remote_fae_table_complete(conn, status, params);
}
}
}

void notify_cs_config_created(struct bt_conn *conn, struct bt_conn_le_cs_config *params)
void notify_cs_config_created(struct bt_conn *conn, uint8_t status,
struct bt_conn_le_cs_config *params)
{
struct bt_conn_cb *callback;

SYS_SLIST_FOR_EACH_CONTAINER(&conn_cbs, callback, _node) {
if (callback->le_cs_config_created) {
callback->le_cs_config_created(conn, params);
if (callback->le_cs_config_complete) {
callback->le_cs_config_complete(conn, status, params);
}
}

STRUCT_SECTION_FOREACH(bt_conn_cb, cb) {
if (cb->le_cs_config_created) {
cb->le_cs_config_created(conn, params);
if (cb->le_cs_config_complete) {
cb->le_cs_config_complete(conn, status, params);
}
}
}
Expand All @@ -3408,37 +3411,37 @@ void notify_cs_config_removed(struct bt_conn *conn, uint8_t config_id)
}
}

void notify_cs_security_enable_available(struct bt_conn *conn)
void notify_cs_security_enable_available(struct bt_conn *conn, uint8_t status)
{
struct bt_conn_cb *callback;

SYS_SLIST_FOR_EACH_CONTAINER(&conn_cbs, callback, _node) {
if (callback->le_cs_security_enabled) {
callback->le_cs_security_enabled(conn);
if (callback->le_cs_security_enable_complete) {
callback->le_cs_security_enable_complete(conn, status);
}
}

STRUCT_SECTION_FOREACH(bt_conn_cb, cb) {
if (cb->le_cs_security_enabled) {
cb->le_cs_security_enabled(conn);
if (cb->le_cs_security_enable_complete) {
cb->le_cs_security_enable_complete(conn, status);
}
}
}

void notify_cs_procedure_enable_available(struct bt_conn *conn,
void notify_cs_procedure_enable_available(struct bt_conn *conn, uint8_t status,
struct bt_conn_le_cs_procedure_enable_complete *params)
{
struct bt_conn_cb *callback;

SYS_SLIST_FOR_EACH_CONTAINER(&conn_cbs, callback, _node) {
if (callback->le_cs_procedure_enabled) {
callback->le_cs_procedure_enabled(conn, params);
if (callback->le_cs_procedure_enable_complete) {
callback->le_cs_procedure_enable_complete(conn, status, params);
}
}

STRUCT_SECTION_FOREACH(bt_conn_cb, cb) {
if (cb->le_cs_procedure_enabled) {
cb->le_cs_procedure_enabled(conn, params);
if (cb->le_cs_procedure_enable_complete) {
cb->le_cs_procedure_enable_complete(conn, status, params);
}
}
}
Expand Down
Loading