Skip to content

Commit bd679ca

Browse files
committed
[nrf fromtree] bluetooth: host: Apply callback changes of CS complete events
The CS complete callbacks provide both status and params. In the case of errors, NULL pointer is passed to the params of callbacks. Signed-off-by: Ryan Chu <[email protected]> (cherry picked from commit 9ba60d3)
1 parent f8430ef commit bd679ca

File tree

3 files changed

+106
-41
lines changed

3 files changed

+106
-41
lines changed

samples/bluetooth/channel_sounding/src/connected_cs_initiator.c

+39-17
Original file line numberDiff line numberDiff line change
@@ -138,32 +138,54 @@ static void security_changed_cb(struct bt_conn *conn, bt_security_t level, enum
138138
k_sem_give(&sem_acl_encryption_enabled);
139139
}
140140

141-
static void remote_capabilities_cb(struct bt_conn *conn, struct bt_conn_le_cs_capabilities *params)
141+
static void remote_capabilities_cb(struct bt_conn *conn,
142+
uint8_t status,
143+
struct bt_conn_le_cs_capabilities *params)
142144
{
143145
ARG_UNUSED(params);
144-
printk("CS capability exchange completed.\n");
145-
k_sem_give(&sem_remote_capabilities_obtained);
146+
147+
if (status == BT_HCI_ERR_SUCCESS) {
148+
printk("CS capability exchange completed.\n");
149+
k_sem_give(&sem_remote_capabilities_obtained);
150+
} else {
151+
printk("CS capability exchange failed. (HCI status 0x%02x)\n", status);
152+
}
146153
}
147154

148-
static void config_created_cb(struct bt_conn *conn, struct bt_conn_le_cs_config *config)
155+
static void config_create_cb(struct bt_conn *conn,
156+
uint8_t status,
157+
struct bt_conn_le_cs_config *config)
149158
{
150-
printk("CS config creation complete. ID: %d\n", config->id);
151-
k_sem_give(&sem_config_created);
159+
if (status == BT_HCI_ERR_SUCCESS) {
160+
printk("CS config creation complete. ID: %d\n", config->id);
161+
k_sem_give(&sem_config_created);
162+
} else {
163+
printk("CS config creation failed. (HCI status 0x%02x)\n", status);
164+
}
152165
}
153166

154-
static void security_enabled_cb(struct bt_conn *conn)
167+
static void security_enable_cb(struct bt_conn *conn, uint8_t status)
155168
{
156-
printk("CS security enabled.\n");
157-
k_sem_give(&sem_cs_security_enabled);
169+
if (status == BT_HCI_ERR_SUCCESS) {
170+
printk("CS security enabled.\n");
171+
k_sem_give(&sem_cs_security_enabled);
172+
} else {
173+
printk("CS security enable failed. (HCI status 0x%02x)\n", status);
174+
}
158175
}
159176

160-
static void procedure_enabled_cb(struct bt_conn *conn,
177+
static void procedure_enable_cb(struct bt_conn *conn,
178+
uint8_t status,
161179
struct bt_conn_le_cs_procedure_enable_complete *params)
162180
{
163-
if (params->state == 1) {
164-
printk("CS procedures enabled.\n");
181+
if (status == BT_HCI_ERR_SUCCESS) {
182+
if (params->state == 1) {
183+
printk("CS procedures enabled.\n");
184+
} else {
185+
printk("CS procedures disabled.\n");
186+
}
165187
} else {
166-
printk("CS procedures disabled.\n");
188+
printk("CS procedures enable failed. (HCI status 0x%02x)\n", status);
167189
}
168190
}
169191

@@ -223,10 +245,10 @@ BT_CONN_CB_DEFINE(conn_cb) = {
223245
.connected = connected_cb,
224246
.disconnected = disconnected_cb,
225247
.security_changed = security_changed_cb,
226-
.le_cs_remote_capabilities_available = remote_capabilities_cb,
227-
.le_cs_config_created = config_created_cb,
228-
.le_cs_security_enabled = security_enabled_cb,
229-
.le_cs_procedure_enabled = procedure_enabled_cb,
248+
.le_cs_read_remote_capabilities_complete = remote_capabilities_cb,
249+
.le_cs_config_complete = config_create_cb,
250+
.le_cs_security_enable_complete = security_enable_cb,
251+
.le_cs_procedure_enable_complete = procedure_enable_cb,
230252
.le_cs_subevent_data_available = subevent_result_cb,
231253
};
232254

samples/bluetooth/channel_sounding/src/connected_cs_reflector.c

+40-18
Original file line numberDiff line numberDiff line change
@@ -89,32 +89,54 @@ static void disconnected_cb(struct bt_conn *conn, uint8_t reason)
8989
connection = NULL;
9090
}
9191

92-
static void remote_capabilities_cb(struct bt_conn *conn, struct bt_conn_le_cs_capabilities *params)
92+
static void remote_capabilities_cb(struct bt_conn *conn,
93+
uint8_t status,
94+
struct bt_conn_le_cs_capabilities *params)
9395
{
9496
ARG_UNUSED(params);
95-
printk("CS capability exchange completed.\n");
96-
k_sem_give(&sem_remote_capabilities_obtained);
97+
98+
if (status == BT_HCI_ERR_SUCCESS) {
99+
printk("CS capability exchange completed.\n");
100+
k_sem_give(&sem_remote_capabilities_obtained);
101+
} else {
102+
printk("CS capability exchange failed. (HCI status 0x%02x)\n", status);
103+
}
97104
}
98105

99-
static void config_created_cb(struct bt_conn *conn, struct bt_conn_le_cs_config *config)
106+
static void config_create_cb(struct bt_conn *conn,
107+
uint8_t status,
108+
struct bt_conn_le_cs_config *config)
100109
{
101-
printk("CS config creation complete. ID: %d\n", config->id);
102-
k_sem_give(&sem_config_created);
110+
if (status == BT_HCI_ERR_SUCCESS) {
111+
printk("CS config creation complete. ID: %d\n", config->id);
112+
k_sem_give(&sem_config_created);
113+
} else {
114+
printk("CS config creation failed. (HCI status 0x%02x)\n", status);
115+
}
103116
}
104117

105-
static void security_enabled_cb(struct bt_conn *conn)
118+
static void security_enable_cb(struct bt_conn *conn, uint8_t status)
106119
{
107-
printk("CS security enabled.\n");
108-
k_sem_give(&sem_cs_security_enabled);
120+
if (status == BT_HCI_ERR_SUCCESS) {
121+
printk("CS security enabled.\n");
122+
k_sem_give(&sem_cs_security_enabled);
123+
} else {
124+
printk("CS security enable failed. (HCI status 0x%02x)\n", status);
125+
}
109126
}
110127

111-
static void procedure_enabled_cb(struct bt_conn *conn,
112-
struct bt_conn_le_cs_procedure_enable_complete *params)
128+
static void procedure_enable_cb(struct bt_conn *conn,
129+
uint8_t status,
130+
struct bt_conn_le_cs_procedure_enable_complete *params)
113131
{
114-
if (params->state == 1) {
115-
printk("CS procedures enabled.\n");
132+
if (status == BT_HCI_ERR_SUCCESS) {
133+
if (params->state == 1) {
134+
printk("CS procedures enabled.\n");
135+
} else {
136+
printk("CS procedures disabled.\n");
137+
}
116138
} else {
117-
printk("CS procedures disabled.\n");
139+
printk("CS procedures enable failed. (HCI status 0x%02x)\n", status);
118140
}
119141
}
120142

@@ -160,10 +182,10 @@ static void write_func(struct bt_conn *conn, uint8_t err, struct bt_gatt_write_p
160182
BT_CONN_CB_DEFINE(conn_cb) = {
161183
.connected = connected_cb,
162184
.disconnected = disconnected_cb,
163-
.le_cs_remote_capabilities_available = remote_capabilities_cb,
164-
.le_cs_config_created = config_created_cb,
165-
.le_cs_security_enabled = security_enabled_cb,
166-
.le_cs_procedure_enabled = procedure_enabled_cb,
185+
.le_cs_read_remote_capabilities_complete = remote_capabilities_cb,
186+
.le_cs_config_complete = config_create_cb,
187+
.le_cs_security_enable_complete = security_enable_cb,
188+
.le_cs_procedure_enable_complete = procedure_enable_cb,
167189
.le_cs_subevent_data_available = subevent_result_cb,
168190
};
169191

subsys/bluetooth/host/shell/bt.c

+27-6
Original file line numberDiff line numberDiff line change
@@ -988,8 +988,15 @@ void subrate_changed(struct bt_conn *conn,
988988
#endif
989989

990990
#if defined(CONFIG_BT_CHANNEL_SOUNDING)
991-
void print_remote_cs_capabilities(struct bt_conn *conn, struct bt_conn_le_cs_capabilities *params)
991+
void print_remote_cs_capabilities(struct bt_conn *conn,
992+
uint8_t status,
993+
struct bt_conn_le_cs_capabilities *params)
992994
{
995+
if (status != BT_HCI_ERR_SUCCESS) {
996+
bt_shell_print("Read Remote CS Capabilities failed (HCI status 0x%02x)", status);
997+
return;
998+
}
999+
9931000
bt_shell_print(
9941001
"Received remote channel sounding capabilities:\n"
9951002
"- Num CS configurations: %d\n"
@@ -1051,14 +1058,28 @@ void print_remote_cs_capabilities(struct bt_conn *conn, struct bt_conn_le_cs_cap
10511058
params->tx_snr_capability);
10521059
}
10531060

1054-
void print_remote_cs_fae_table(struct bt_conn *conn, struct bt_conn_le_cs_fae_table *params)
1061+
void print_remote_cs_fae_table(struct bt_conn *conn,
1062+
uint8_t status,
1063+
struct bt_conn_le_cs_fae_table *params)
10551064
{
1065+
if (status != BT_HCI_ERR_SUCCESS) {
1066+
bt_shell_print("Read Remote CS FAE Table failed (HCI status 0x%02x)", status);
1067+
return;
1068+
}
1069+
10561070
bt_shell_print("Received FAE Table: ");
10571071
bt_shell_hexdump(params->remote_fae_table, 72);
10581072
}
10591073

1060-
static void le_cs_config_created(struct bt_conn *conn, struct bt_conn_le_cs_config *config)
1074+
static void le_cs_config_created(struct bt_conn *conn,
1075+
uint8_t status,
1076+
struct bt_conn_le_cs_config *config)
10611077
{
1078+
if (status != BT_HCI_ERR_SUCCESS) {
1079+
bt_shell_print("Create CS Config failed (HCI status 0x%02x)", status);
1080+
return;
1081+
}
1082+
10621083
const char *mode_str[5] = {"Unused", "1 (RTT)", "2 (PBR)", "3 (RTT + PBR)", "Invalid"};
10631084
const char *role_str[3] = {"Initiator", "Reflector", "Invalid"};
10641085
const char *rtt_type_str[8] = {"AA only", "32-bit sounding", "96-bit sounding",
@@ -1146,9 +1167,9 @@ static struct bt_conn_cb conn_callbacks = {
11461167
.subrate_changed = subrate_changed,
11471168
#endif
11481169
#if defined(CONFIG_BT_CHANNEL_SOUNDING)
1149-
.le_cs_remote_capabilities_available = print_remote_cs_capabilities,
1150-
.le_cs_remote_fae_table_available = print_remote_cs_fae_table,
1151-
.le_cs_config_created = le_cs_config_created,
1170+
.le_cs_read_remote_capabilities_complete = print_remote_cs_capabilities,
1171+
.le_cs_read_remote_fae_table_complete = print_remote_cs_fae_table,
1172+
.le_cs_config_complete = le_cs_config_created,
11521173
.le_cs_config_removed = le_cs_config_removed,
11531174
#endif
11541175
};

0 commit comments

Comments
 (0)