Skip to content

Commit 8db30da

Browse files
olivier-le-sagerlubos
authored andcommitted
bluetooth: services: Support aborted procedures/subevents in RAS
1. When a subevent in a procedure is aborted: - Encode ranging data in RRSP such that num_steps_reported is 0 if a subevent was aborted -> if some steps in the subevent were successful, these will still be discarded. -> subsequent subevents in the procedure will no longer be dropped. - Update parser API in RREQ to continue parsing subevent headers if a subevent header with num_steps_reported=0 is seen - Update sample to make use of these extra steps. Note that this doesn't impact the behavior of the sample because the subevent length is currently large enough to fit the entire procedure. 2. When procedure_done_status is 0xF: - Notify RREQ subscribers with RD Ready. -> this is important because some subevents in the procedure may have successfully performed some steps Signed-off-by: Olivier Lesage <[email protected]>
1 parent 00a6650 commit 8db30da

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

samples/bluetooth/channel_sounding_ras_initiator/src/main.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,13 @@ static void subevent_result_cb(struct bt_conn *conn, struct bt_conn_le_cs_subeve
5656
{
5757
LOG_INF("Subevent result callback %d", result->header.procedure_counter);
5858

59-
if (result->header.subevent_done_status == BT_CONN_LE_CS_SUBEVENT_ABORTED) {
60-
/* If this subevent was aborted, drop the entire procedure for now. */
61-
LOG_WRN("Subevent aborted");
62-
dropped_ranging_counter = result->header.procedure_counter;
63-
net_buf_simple_reset(&latest_local_steps);
64-
return;
65-
}
66-
6759
if (dropped_ranging_counter == result->header.procedure_counter) {
6860
return;
6961
}
7062

71-
if (result->step_data_buf) {
63+
if (result->header.subevent_done_status == BT_CONN_LE_CS_SUBEVENT_ABORTED) {
64+
/* The steps from this subevent will not be used. */
65+
} else if (result->step_data_buf) {
7266
if (result->step_data_buf->len <= net_buf_simple_tailroom(&latest_local_steps)) {
7367
uint16_t len = result->step_data_buf->len;
7468
uint8_t *step_data = net_buf_simple_pull_mem(result->step_data_buf, len);
@@ -91,7 +85,7 @@ static void subevent_result_cb(struct bt_conn *conn, struct bt_conn_le_cs_subeve
9185
most_recent_local_ranging_counter = result->header.procedure_counter;
9286
k_sem_give(&sem_procedure_done);
9387
} else if (result->header.procedure_done_status == BT_CONN_LE_CS_PROCEDURE_ABORTED) {
94-
LOG_WRN("Procedure aborted");
88+
LOG_WRN("Procedure %u aborted", result->header.procedure_counter);
9589
net_buf_simple_reset(&latest_local_steps);
9690
}
9791
}

subsys/bluetooth/services/ras/rreq/ras_rreq.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,10 @@ void bt_ras_rreq_rd_subevent_data_parse(struct net_buf_simple *peer_ranging_data
977977
bt_ras_rreq_subevent_header_cb_t subevent_header_cb,
978978
bt_ras_rreq_step_data_cb_t step_data_cb, void *user_data)
979979
{
980-
if (!peer_ranging_data_buf || !local_step_data_buf) {
980+
if (!peer_ranging_data_buf
981+
|| !local_step_data_buf
982+
|| peer_ranging_data_buf->len == 0
983+
|| local_step_data_buf->len == 0) {
981984
LOG_ERR("Tried to parse empty step data.");
982985
return;
983986
}
@@ -994,8 +997,13 @@ void bt_ras_rreq_rd_subevent_data_parse(struct net_buf_simple *peer_ranging_data
994997
return;
995998
}
996999

997-
if (peer_subevent_header_data->num_steps_reported == 0 ||
998-
peer_ranging_data_buf->len == 0) {
1000+
if (peer_subevent_header_data->num_steps_reported == 0) {
1001+
LOG_DBG("Skipping subevent with no steps.");
1002+
continue;
1003+
}
1004+
1005+
if (peer_ranging_data_buf->len == 0) {
1006+
LOG_WRN("Empty peer step data buf where steps were expected.");
9991007
return;
10001008
}
10011009

subsys/bluetooth/services/ras/rrsp/ras_rd_buffer.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,14 @@ static void subevent_data_available(struct bt_conn *conn,
200200
__ASSERT_NO_MSG(conn_index < ARRAY_SIZE(tx_power_cache));
201201
__ASSERT_NO_MSG(conn_index < ARRAY_SIZE(drop_procedure_counter));
202202

203-
if (result->header.subevent_done_status == BT_CONN_LE_CS_SUBEVENT_ABORTED) {
204-
/* If this subevent was aborted, drop the entire procedure for now. */
203+
if (result->header.procedure_done_status == BT_CONN_LE_CS_PROCEDURE_ABORTED) {
204+
LOG_DBG("Procedure was aborted.");
205205
drop_procedure_counter[conn_index] = result->header.procedure_counter;
206206
}
207207

208208
if (drop_procedure_counter[conn_index] == result->header.procedure_counter) {
209209
/* This procedure will not be sent to the peer, so ignore all data. */
210-
LOG_WRN("Dropping subevent data for procedure %u",
210+
LOG_DBG("Dropping subevent data for procedure %u",
211211
result->header.procedure_counter);
212212

213213
if (buf) {
@@ -261,10 +261,17 @@ static void subevent_data_available(struct bt_conn *conn,
261261
hdr->ranging_abort_reason = result->header.procedure_abort_reason;
262262
hdr->subevent_abort_reason = result->header.subevent_abort_reason;
263263
hdr->ref_power_level = result->header.reference_power_level;
264-
hdr->num_steps_reported = result->header.num_steps_reported;
265264

266-
if (result->step_data_buf) {
267-
bt_le_cs_step_data_parse(result->step_data_buf, process_step_data, buf);
265+
if (result->header.subevent_done_status == BT_CONN_LE_CS_SUBEVENT_ABORTED) {
266+
hdr->num_steps_reported = 0;
267+
LOG_DBG("Discarding %u steps in aborted subevent",
268+
result->header.num_steps_reported);
269+
} else {
270+
hdr->num_steps_reported = result->header.num_steps_reported;
271+
272+
if (result->step_data_buf) {
273+
bt_le_cs_step_data_parse(result->step_data_buf, process_step_data, buf);
274+
}
268275
}
269276

270277
/* process_step_data might have requested dropping this procedure. */
@@ -275,7 +282,8 @@ static void subevent_data_available(struct bt_conn *conn,
275282
return;
276283
}
277284

278-
if (hdr->ranging_done_status == BT_CONN_LE_CS_PROCEDURE_COMPLETE) {
285+
if (hdr->ranging_done_status == BT_CONN_LE_CS_PROCEDURE_COMPLETE ||
286+
hdr->ranging_done_status == BT_CONN_LE_CS_PROCEDURE_ABORTED) {
279287
buf->ready = true;
280288
buf->busy = false;
281289
notify_new_rd_stored(conn, result->header.procedure_counter);

0 commit comments

Comments
 (0)