Skip to content

Commit d0cdd9b

Browse files
sean-madiganrlubos
authored andcommitted
bluetooth: services: ras: Add RREQ implementation to RAS
Add implementation for Ranging Requestor, a Ranging Service client which can be used to obtain channel sounding ranging data from a Ranging Responder which operates as a Ranging Service server. This current implementation can perform most mandatory features from the Ranging Profile/Ranging Service specifications to alert an application of available ranging data and receive the data from the server. Further work can be done to add support for reading the features from the server, receiving real time ranging data, aborting receive operation, adding filters for ranging data Signed-off-by: Sean Madigan <[email protected]>
1 parent 593b19c commit d0cdd9b

File tree

5 files changed

+1045
-0
lines changed

5 files changed

+1045
-0
lines changed

include/bluetooth/services/ras.h

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <zephyr/bluetooth/conn.h>
1313
#include <zephyr/bluetooth/uuid.h>
1414
#include <zephyr/bluetooth/hci_types.h>
15+
#include <bluetooth/gatt_dm.h>
1516

1617
/** @file
1718
* @defgroup bt_ras Ranging Service API
@@ -312,6 +313,170 @@ int bt_ras_rd_buffer_release(struct ras_rd_buffer *buf);
312313
int bt_ras_rd_buffer_bytes_pull(struct ras_rd_buffer *buf, uint8_t *out_buf, uint16_t max_data_len,
313314
uint16_t *read_cursor, bool *empty);
314315

316+
/** @brief Ranging data ready callback. Called when peer has ranging data available.
317+
*
318+
* @param[in] conn Connection Object.
319+
* @param[in] ranging_counter Ranging counter ready to be requested.
320+
*/
321+
typedef void (*bt_ras_rreq_rd_ready_cb_t)(struct bt_conn *conn, uint16_t ranging_counter);
322+
323+
/** @brief Ranging data overwritten callback. Called when peer has overwritten previously available
324+
* ranging data.
325+
*
326+
* @param[in] conn Connection Object.
327+
* @param[in] ranging_counter Ranging counter which has been overwritten.
328+
*/
329+
typedef void (*bt_ras_rreq_rd_overwritten_cb_t)(struct bt_conn *conn, uint16_t ranging_counter);
330+
331+
/** @brief Ranging data get complete callback. Called when ranging data get procedure has completed.
332+
*
333+
* @param[in] conn Connection Object.
334+
* @param[in] ranging_counter Ranging counter which has been completed.
335+
* @param[in] err Error code, 0 if the ranging data get was successful. Otherwise a
336+
* negative error code.
337+
*/
338+
typedef void (*bt_ras_rreq_ranging_data_get_complete_t)(struct bt_conn *conn,
339+
uint16_t ranging_counter, int err);
340+
341+
/** @brief Allocate a RREQ context and assign GATT handles. Takes a reference to the connection.
342+
*
343+
* @note RREQ context will be freed automatically on disconnect.
344+
*
345+
* @param[in] dm Discovery Object.
346+
* @param[in] conn Connection Object.
347+
*
348+
* @retval 0 If the operation was successful.
349+
* Otherwise, a negative error code is returned. No RREQ context will be allocated if
350+
* there is an error.
351+
*/
352+
int bt_ras_rreq_alloc_and_assign_handles(struct bt_gatt_dm *dm, struct bt_conn *conn);
353+
354+
/** @brief Get ranging data for given ranging counter.
355+
*
356+
* @note This should only be called after receiving a ranging data ready callback and
357+
* when subscribed to ondemand ranging data and RAS-CP.
358+
*
359+
* @param[in] conn Connection Object.
360+
* @param[in] ranging_data_out Simple buffer to store received ranging data.
361+
* @param[in] ranging_counter Ranging counter to get.
362+
* @param[in] data_get_complete_cb Callback called when get ranging data completes.
363+
*
364+
* @retval 0 If the operation was successful.
365+
* Otherwise, a negative error code is returned.
366+
*/
367+
int bt_ras_rreq_cp_get_ranging_data(struct bt_conn *conn, struct net_buf_simple *ranging_data_out,
368+
uint16_t ranging_counter,
369+
bt_ras_rreq_ranging_data_get_complete_t data_get_complete_cb);
370+
371+
/** @brief Free RREQ context for connection. This will unsubscribe from any remaining subscriptions.
372+
*
373+
* @note RREQ context will be freed automatically on disconnect.
374+
*
375+
* @param[in] conn Connection Object.
376+
*/
377+
void bt_ras_rreq_free(struct bt_conn *conn);
378+
379+
/** @brief Subscribe to RAS-CP. Required to be called before @ref bt_ras_rreq_cp_get_ranging_data.
380+
*
381+
* @note Calling from BT RX thread may return an error as bt_gatt_subscribe will not block if
382+
* there are no available TX buffers.
383+
*
384+
* @param[in] conn Connection Object, which already has associated RREQ context.
385+
*
386+
* @retval 0 If the operation was successful.
387+
* Otherwise, a negative error code is returned.
388+
*/
389+
int bt_ras_rreq_cp_subscribe(struct bt_conn *conn);
390+
391+
/** @brief Unsubscribe from RAS-CP.
392+
*
393+
* @note Calling from BT RX thread may return an error as bt_gatt_unsubscribe will not block if
394+
* there are no available TX buffers.
395+
*
396+
* @param[in] conn Connection Object, which already has associated RREQ context.
397+
*
398+
* @retval 0 If the operation was successful.
399+
* Otherwise, a negative error code is returned.
400+
*/
401+
int bt_ras_rreq_cp_unsubscribe(struct bt_conn *conn);
402+
403+
/** @brief Subscribe to on-demand ranging data notifications. Required to be called before @ref
404+
* bt_ras_rreq_cp_get_ranging_data.
405+
*
406+
* @note Calling from BT RX thread may return an error as bt_gatt_subscribe will not block if
407+
* there are no available TX buffers.
408+
*
409+
* @param[in] conn Connection Object, which already has associated RREQ context.
410+
*
411+
* @retval 0 If the operation was successful.
412+
* Otherwise, a negative error code is returned.
413+
*/
414+
int bt_ras_rreq_on_demand_rd_subscribe(struct bt_conn *conn);
415+
416+
/** @brief Unsubscribe from on-demand ranging data notifications.
417+
*
418+
* @note Calling from BT RX thread may return an error as bt_gatt_unsubscribe will not block if
419+
* there are no available TX buffers.
420+
*
421+
* @param[in] conn Connection Object, which already has associated RREQ context.
422+
*
423+
* @retval 0 If the operation was successful.
424+
* Otherwise, a negative error code is returned.
425+
*/
426+
int bt_ras_rreq_on_demand_rd_unsubscribe(struct bt_conn *conn);
427+
428+
/** @brief Subscribe to ranging data ready notifications. These notify when on-demand ranging data
429+
* is available for a given CS procedure counter.
430+
*
431+
* @note Calling from BT RX thread may return an error as bt_gatt_subscribe will not block if
432+
* there are no available TX buffers.
433+
*
434+
* @param[in] conn Connection Object, which already has associated RREQ context.
435+
* @param[in] cb Ranging data ready callback.
436+
*
437+
* @retval 0 If the operation was successful.
438+
* Otherwise, a negative error code is returned.
439+
*/
440+
int bt_ras_rreq_rd_ready_subscribe(struct bt_conn *conn, bt_ras_rreq_rd_ready_cb_t cb);
441+
442+
/** @brief Unsubscribe from ranging data ready notifications.
443+
*
444+
* @note Calling from BT RX thread may return an error as bt_gatt_unsubscribe will not block if
445+
* there are no available TX buffers.
446+
*
447+
* @param[in] conn Connection Object, which already has associated RREQ context.
448+
*
449+
* @retval 0 If the operation was successful.
450+
* Otherwise, a negative error code is returned.
451+
*/
452+
int bt_ras_rreq_rd_ready_unsubscribe(struct bt_conn *conn);
453+
454+
/** @brief Subscribe to ranging data overwritten notifications. These notify when on-demand ranging
455+
* data is no longer available for a given CS procedure counter.
456+
*
457+
* @note Calling from BT RX thread may return an error as bt_gatt_subscribe will not block if
458+
* there are no available TX buffers.
459+
*
460+
* @param[in] conn Connection Object, which already has associated RREQ context.
461+
* @param[in] cb Ranging data overwritten callback.
462+
*
463+
* @retval 0 If the operation was successful.
464+
* Otherwise, a negative error code is returned.
465+
*/
466+
int bt_ras_rreq_rd_overwritten_subscribe(struct bt_conn *conn, bt_ras_rreq_rd_overwritten_cb_t cb);
467+
468+
/** @brief Unsubscribe from ranging data overwritten notifications.
469+
*
470+
* @note Calling from BT RX thread may return an error as bt_gatt_unsubscribe will not block if
471+
* there are no available TX buffers.
472+
*
473+
* @param[in] conn Connection Object, which already has associated RREQ context.
474+
*
475+
* @retval 0 If the operation was successful.
476+
* Otherwise, a negative error code is returned.
477+
*/
478+
int bt_ras_rreq_rd_overwritten_unsubscribe(struct bt_conn *conn);
479+
315480
#ifdef __cplusplus
316481
}
317482
#endif

subsys/bluetooth/services/ras/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
#
66

77
add_subdirectory_ifdef(CONFIG_BT_RAS_RRSP rrsp)
8+
add_subdirectory_ifdef(CONFIG_BT_RAS_RREQ rreq)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
zephyr_library_sources_ifdef(
8+
CONFIG_BT_RAS_RREQ
9+
ras_rreq.c)

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@
77
menuconfig BT_RAS_RREQ
88
bool "GATT Ranging Requester Client [EXPERIMENTAL]"
99
select EXPERIMENTAL
10+
select BT_GATT_DM
11+
select BT_GATT_CLIENT
1012

1113
if BT_RAS_RREQ
1214

1315
module = BT_RAS_RREQ
1416
module-str = RAS_RREQ
1517
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
1618

19+
config BT_RAS_RREQ_MAX_ACTIVE_CONN
20+
int "Number of simultaneously supported RREQ instances"
21+
default BT_MAX_CONN
22+
range 1 BT_MAX_CONN
23+
help
24+
The number of simultaneous connections with an instance of RAS RREQ
25+
1726
endif # BT_RAS_RREQ

0 commit comments

Comments
 (0)