Skip to content

Commit 22bbbf7

Browse files
thomas-m-johansennordicjm
authored andcommitted
bluetooth: services: ras: fix ranging buffer value bug
When allocating ranging buffers the procedure counter was used. However, the ranging counter in ras is 12 bit instead of the 16 bits allocated to the procedure counter. This caused issues with the ranging counter after running 4096 procedures, as it was larger than the valid range. Signed-off-by: Thomas Johansen <[email protected]>
1 parent 44ce45a commit 22bbbf7

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,9 @@ static void subevent_data_available(struct bt_conn *conn,
194194
struct bt_conn_le_cs_subevent_result *result)
195195
{
196196
LOG_DBG("Procedure %u", result->header.procedure_counter);
197-
struct ras_rd_buffer *buf =
198-
rd_buffer_get(conn, result->header.procedure_counter, false, true);
197+
uint16_t ranging_counter =
198+
bt_ras_rreq_get_ranging_counter(result->header.procedure_counter);
199+
struct ras_rd_buffer *buf = rd_buffer_get(conn, ranging_counter, false, true);
199200

200201
uint8_t conn_index = bt_conn_index(conn);
201202

@@ -223,7 +224,7 @@ static void subevent_data_available(struct bt_conn *conn,
223224

224225
if (!buf) {
225226
/* First subevent - allocate a buffer */
226-
buf = rd_buffer_alloc(conn, result->header.procedure_counter);
227+
buf = rd_buffer_alloc(conn, ranging_counter);
227228

228229
if (!buf) {
229230
LOG_INF("Failed to allocate buffer for procedure %u",
@@ -233,7 +234,7 @@ static void subevent_data_available(struct bt_conn *conn,
233234
return;
234235
}
235236

236-
buf->procedure.ranging_header.ranging_counter = result->header.procedure_counter;
237+
buf->procedure.ranging_header.ranging_counter = ranging_counter;
237238
buf->procedure.ranging_header.config_id = result->header.config_id;
238239
buf->procedure.ranging_header.selected_tx_power = tx_power_cache[conn_index];
239240
buf->procedure.ranging_header.antenna_paths_mask =
@@ -292,7 +293,7 @@ static void subevent_data_available(struct bt_conn *conn,
292293
hdr->ranging_done_status == BT_CONN_LE_CS_PROCEDURE_ABORTED) {
293294
buf->ready = true;
294295
buf->busy = false;
295-
notify_new_rd_stored(conn, result->header.procedure_counter);
296+
notify_new_rd_stored(conn, ranging_counter);
296297
}
297298
}
298299

0 commit comments

Comments
 (0)