|
12 | 12 | #include <zephyr/bluetooth/conn.h> |
13 | 13 | #include <zephyr/bluetooth/uuid.h> |
14 | 14 | #include <zephyr/bluetooth/hci_types.h> |
| 15 | +#include <bluetooth/gatt_dm.h> |
15 | 16 |
|
16 | 17 | /** @file |
17 | 18 | * @defgroup bt_ras Ranging Service API |
@@ -312,6 +313,170 @@ int bt_ras_rd_buffer_release(struct ras_rd_buffer *buf); |
312 | 313 | int bt_ras_rd_buffer_bytes_pull(struct ras_rd_buffer *buf, uint8_t *out_buf, uint16_t max_data_len, |
313 | 314 | uint16_t *read_cursor, bool *empty); |
314 | 315 |
|
| 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 | + |
315 | 480 | #ifdef __cplusplus |
316 | 481 | } |
317 | 482 | #endif |
|
0 commit comments