Skip to content

Commit 5bb0759

Browse files
olivier-le-sagerlubos
authored andcommitted
bluetooth: services: Implement real-time ranging data service
The RRSP now always supports the two operation modes: on-demand and real-time data. When using real-time data, the CS procedure results are notified immediately as soon as they are available. The RREQ doesn't need to fetch or ACK the notifications, or wait for the data complete indication. In the case where new procedure results are received from the controller before the previous procedure results have been completely sent, the new results are dropped. A callback has been exposed for the CCCD write request responses as it's now possible for the RRSP to reject these if they would lead to both on-demand and real-time modes to be enabled at the same time. The alternative would be to block on a semaphore before returning from bt_ras_rreq_realtime_rd_subscribe() or bt_ras_rreq_on_demand_rd_subscribe(). Signed-off-by: Olivier Lesage <[email protected]>
1 parent 4327dff commit 5bb0759

File tree

6 files changed

+555
-161
lines changed

6 files changed

+555
-161
lines changed

doc/nrf/libraries/bluetooth/services/rreq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Overview
1212

1313
This library implements the Ranging Requestor for Channel Sounding with the corresponding set of characteristics defined in the `Ranging Service Specification`_ and the `Ranging Profile Specification`_.
1414

15-
This library supports On Demand Ranging Data.
15+
This library supports On Demand Ranging Data and Real-time Ranging Data.
1616

1717
Configuration
1818
*************

doc/nrf/libraries/bluetooth/services/rrsp.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Overview
1212

1313
This library implements the Ranging Responder for Channel Sounding with the corresponding set of characteristics defined in the `Ranging Service Specification`_ and the `Ranging Profile Specification`_.
1414

15-
This library supports On Demand Ranging Data.
15+
This library supports On Demand Ranging Data and Real-time Ranging Data.
1616

1717
Configuration
1818
*************

include/bluetooth/services/ras.h

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,15 +329,15 @@ typedef void (*bt_ras_rreq_rd_ready_cb_t)(struct bt_conn *conn, uint16_t ranging
329329
*/
330330
typedef void (*bt_ras_rreq_rd_overwritten_cb_t)(struct bt_conn *conn, uint16_t ranging_counter);
331331

332-
/** @brief Ranging data get complete callback. Called when ranging data get procedure has completed.
332+
/** @brief Ranging data complete callback. Called when complete ranging data has been received from
333+
* the peer.
333334
*
334335
* @param[in] conn Connection Object.
335-
* @param[in] ranging_counter Ranging counter which has been completed.
336-
* @param[in] err Error code, 0 if the ranging data get was successful. Otherwise a
337-
* negative error code.
336+
* @param[in] ranging_counter Ranging counter which has been received.
337+
* @param[in] err Error code, 0 if successful. Otherwise a negative error code.
338338
*/
339-
typedef void (*bt_ras_rreq_ranging_data_get_complete_t)(struct bt_conn *conn,
340-
uint16_t ranging_counter, int err);
339+
typedef void (*bt_ras_rreq_ranging_data_received_t)(struct bt_conn *conn, uint16_t ranging_counter,
340+
int err);
341341

342342
/** @brief RAS features read callback.
343343
*
@@ -366,11 +366,27 @@ typedef void (*bt_ras_rreq_features_read_cb_t)(struct bt_conn *conn, uint32_t fe
366366
*/
367367
int bt_ras_rreq_alloc_and_assign_handles(struct bt_gatt_dm *dm, struct bt_conn *conn);
368368

369+
/** @brief Register a callback for GATT subscriptions and unsubscriptions attempted by the RREQ.
370+
*
371+
* @note This callback will not be called when attempting to subscribe or unsubscribe to a
372+
* characteristic to which the device is already subscribed or unsubscribed (respectively).
373+
*
374+
* @param[in] conn Connection object.
375+
* @param[in] subscription_change_cb CCC write request response callback
376+
*
377+
* @retval 0 If the operation was successful.
378+
* Otherwise, a negative error code is returned.
379+
*/
380+
int bt_ras_rreq_subscription_change_cb_register(struct bt_conn *conn,
381+
bt_gatt_subscribe_func_t subscription_change_cb);
382+
369383
/** @brief Get ranging data for given ranging counter.
370384
*
371385
* @note This should only be called after receiving a ranging data ready callback and
372386
* when subscribed to ondemand ranging data and RAS-CP.
373387
*
388+
* @note Using this API is not allowed when the RAS server uses real-time ranging data.
389+
*
374390
* @param[in] conn Connection Object.
375391
* @param[in] ranging_data_out Simple buffer to store received ranging data.
376392
* @param[in] ranging_counter Ranging counter to get.
@@ -381,7 +397,7 @@ int bt_ras_rreq_alloc_and_assign_handles(struct bt_gatt_dm *dm, struct bt_conn *
381397
*/
382398
int bt_ras_rreq_cp_get_ranging_data(struct bt_conn *conn, struct net_buf_simple *ranging_data_out,
383399
uint16_t ranging_counter,
384-
bt_ras_rreq_ranging_data_get_complete_t data_get_complete_cb);
400+
bt_ras_rreq_ranging_data_received_t data_get_complete_cb);
385401

386402
/** @brief Free RREQ context for connection. This will unsubscribe from any remaining subscriptions.
387403
*
@@ -421,6 +437,9 @@ int bt_ras_rreq_cp_unsubscribe(struct bt_conn *conn);
421437
* @note Calling from BT RX thread may return an error as bt_gatt_subscribe will not block if
422438
* there are no available TX buffers.
423439
*
440+
* @note On-Demand and Real-time ranging data are not compatible and attempting to
441+
* subscribe to both at the same time will be rejected by the RAS server.
442+
*
424443
* @param[in] conn Connection Object, which already has associated RREQ context.
425444
*
426445
* @retval 0 If the operation was successful.
@@ -492,6 +511,42 @@ int bt_ras_rreq_rd_overwritten_subscribe(struct bt_conn *conn, bt_ras_rreq_rd_ov
492511
*/
493512
int bt_ras_rreq_rd_overwritten_unsubscribe(struct bt_conn *conn);
494513

514+
/** @brief Subscribe to real-time ranging data notifications.
515+
*
516+
* @note Calling from BT RX thread may return an error as bt_gatt_subscribe will not block if
517+
* there are no available TX buffers.
518+
*
519+
* @note The ranging_data_out buffer is automatically reset after the data_received_cb
520+
* callback.
521+
*
522+
* @note On-Demand and Real-time ranging data are not compatible and attempting to
523+
* subscribe to both at the same time will be rejected by the RAS server.
524+
*
525+
* @note The data callback will be called many times (for as long as the RRSP continues
526+
* to send notifications).
527+
*
528+
* @param[in] conn Connection Object, which already has associated RREQ context.
529+
* @param[in] ranging_data_out Simple buffer to store received ranging data.
530+
* @param[in] data_received_cb Callback called when complete ranging data is received.
531+
*
532+
* @retval 0 If the operation was successful.
533+
* Otherwise, a negative error code is returned.
534+
*/
535+
int bt_ras_rreq_realtime_rd_subscribe(struct bt_conn *conn, struct net_buf_simple *ranging_data_out,
536+
bt_ras_rreq_ranging_data_received_t data_received_cb);
537+
538+
/** @brief Unsubscribe from real-time ranging data notifications.
539+
*
540+
* @note Calling from BT RX thread may return an error as bt_gatt_unsubscribe will not block if
541+
* there are no available TX buffers.
542+
*
543+
* @param[in] conn Connection Object, which already has associated RREQ context.
544+
*
545+
* @retval 0 If the operation was successful.
546+
* Otherwise, a negative error code is returned.
547+
*/
548+
int bt_ras_rreq_realtime_rd_unsubscribe(struct bt_conn *conn);
549+
495550
/** @brief Read supported RAS features from peer.
496551
*
497552
* @note Calling from BT RX thread may return an error as bt_gatt_read will not block if

0 commit comments

Comments
 (0)