|
| 1 | +/* |
| 2 | + * Copyright (c) 2024 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +#ifndef BT_RAS_H_ |
| 8 | +#define BT_RAS_H_ |
| 9 | + |
| 10 | +#include <stdint.h> |
| 11 | +#include <zephyr/kernel.h> |
| 12 | +#include <zephyr/bluetooth/conn.h> |
| 13 | +#include <zephyr/bluetooth/uuid.h> |
| 14 | + |
| 15 | +/** @file |
| 16 | + * @defgroup bt_ras Ranging Service API |
| 17 | + * @{ |
| 18 | + * @brief API for the Ranging Service (RAS). |
| 19 | + */ |
| 20 | + |
| 21 | +#ifdef __cplusplus |
| 22 | +extern "C" { |
| 23 | +#endif |
| 24 | + |
| 25 | +/** @brief UUID of the Ranging Service. **/ |
| 26 | +#define BT_UUID_RANGING_SERVICE_VAL (0x185B) |
| 27 | + |
| 28 | +/** @brief UUID of the RAS Features Characteristic. **/ |
| 29 | +#define BT_UUID_RAS_FEATURES_VAL (0x2C14) |
| 30 | + |
| 31 | +/** @brief UUID of the Real-time Ranging Data Characteristic. **/ |
| 32 | +#define BT_UUID_RAS_REALTIME_RD_VAL (0x2C15) |
| 33 | + |
| 34 | +/** @brief UUID of the On-demand Ranging Data Characteristic. **/ |
| 35 | +#define BT_UUID_RAS_ONDEMAND_RD_VAL (0x2C16) |
| 36 | + |
| 37 | +/** @brief UUID of the RAS Control Point Characteristic. **/ |
| 38 | +#define BT_UUID_RAS_CP_VAL (0x2C17) |
| 39 | + |
| 40 | +/** @brief UUID of the Ranging Data Ready Characteristic. **/ |
| 41 | +#define BT_UUID_RAS_RD_READY_VAL (0x2C18) |
| 42 | + |
| 43 | +/** @brief UUID of the Ranging Data Overwritten Characteristic. **/ |
| 44 | +#define BT_UUID_RAS_RD_OVERWRITTEN_VAL (0x2C19) |
| 45 | + |
| 46 | +#define BT_UUID_RANGING_SERVICE BT_UUID_DECLARE_16(BT_UUID_RANGING_SERVICE_VAL) |
| 47 | +#define BT_UUID_RAS_FEATURES BT_UUID_DECLARE_16(BT_UUID_RAS_FEATURES_VAL) |
| 48 | +#define BT_UUID_RAS_REALTIME_RD BT_UUID_DECLARE_16(BT_UUID_RAS_REALTIME_RD_VAL) |
| 49 | +#define BT_UUID_RAS_ONDEMAND_RD BT_UUID_DECLARE_16(BT_UUID_RAS_ONDEMAND_RD_VAL) |
| 50 | +#define BT_UUID_RAS_CP BT_UUID_DECLARE_16(BT_UUID_RAS_CP_VAL) |
| 51 | +#define BT_UUID_RAS_RD_READY BT_UUID_DECLARE_16(BT_UUID_RAS_RD_READY_VAL) |
| 52 | +#define BT_UUID_RAS_RD_OVERWRITTEN BT_UUID_DECLARE_16(BT_UUID_RAS_RD_OVERWRITTEN_VAL) |
| 53 | + |
| 54 | +#define BT_RAS_RANGING_HEADER_LEN 4 |
| 55 | +#define BT_RAS_SUBEVENT_HEADER_LEN 8 |
| 56 | +#define BT_RAS_STEP_MODE_LEN 1 |
| 57 | +#define BT_RAS_MAX_STEP_DATA_LEN 35 |
| 58 | + |
| 59 | +/** @brief Ranging Header structure as defined in RAS Specification, Table 3.7. */ |
| 60 | +struct ras_ranging_header { |
| 61 | + /** Ranging Counter is lower 12-bits of CS Procedure_Counter provided by the Core Controller |
| 62 | + * (Core Specification, Volume 4, Part E, Section 7.7.65.44). |
| 63 | + */ |
| 64 | + uint16_t ranging_counter : 12; |
| 65 | + /** CS configuration identifier. Range: 0 to 3. */ |
| 66 | + uint8_t config_id : 4; |
| 67 | + /** Transmit power level used for the CS Procedure. Range: -127 to 20. Units: dBm. */ |
| 68 | + int8_t selected_tx_power; |
| 69 | + /** Antenna paths that are reported: |
| 70 | + * Bit0: 1 if Antenna Path_1 included; 0 if not. |
| 71 | + * Bit1: 1 if Antenna Path_2 included; 0 if not. |
| 72 | + * Bit2: 1 if Antenna Path_3 included; 0 if not. |
| 73 | + * Bit3: 1 if Antenna Path_4 included; 0 if not. |
| 74 | + * Bits 4-7: RFU |
| 75 | + */ |
| 76 | + uint8_t antenna_paths_mask; |
| 77 | +} __packed; |
| 78 | +BUILD_ASSERT(sizeof(struct ras_ranging_header) == BT_RAS_RANGING_HEADER_LEN); |
| 79 | + |
| 80 | +/** @brief Subevent Header structure as defined in RAS Specification, Table 3.8. */ |
| 81 | +struct ras_subevent_header { |
| 82 | + /** Starting ACL connection event count for the results reported in the event */ |
| 83 | + uint16_t start_acl_conn_event; |
| 84 | + /** Frequency compensation value in units of 0.01 ppm (15-bit signed integer). |
| 85 | + * Note this value can be BT_HCI_LE_CS_SUBEVENT_RESULT_FREQ_COMPENSATION_NOT_AVAILABLE |
| 86 | + * if the role is not the initiator, or the frequency compensation value is unavailable. |
| 87 | + */ |
| 88 | + uint16_t freq_compensation; |
| 89 | + /** Ranging Done Status: |
| 90 | + * 0x0: All results complete for the CS Procedure |
| 91 | + * 0x1: Partial results with more to follow for the CS procedure |
| 92 | + * 0xF: All subsequent CS Procedures aborted |
| 93 | + * All other values: RFU |
| 94 | + */ |
| 95 | + uint8_t ranging_done_status : 4; |
| 96 | + /** Subevent Done Status: |
| 97 | + * 0x0: All results complete for the CS Subevent |
| 98 | + * 0xF: Current CS Subevent aborted. |
| 99 | + * All other values: RFU |
| 100 | + */ |
| 101 | + uint8_t subevent_done_status : 4; |
| 102 | + /** Indicates the abort reason when Procedure_Done Status received from the Core Controller |
| 103 | + * (Core Specification, Volume 4, Part 4, Section 7.7.65.44) is set to 0xF, |
| 104 | + * otherwise the value is set to zero. |
| 105 | + * 0x0: Report with no abort |
| 106 | + * 0x1: Abort because of local Host or remote request |
| 107 | + * 0x2: Abort because filtered channel map has less than 15 channels |
| 108 | + * 0x3: Abort because the channel map update instant has passed |
| 109 | + * 0xF: Abort because of unspecified reasons |
| 110 | + * All other values: RFU |
| 111 | + */ |
| 112 | + uint8_t ranging_abort_reason : 4; |
| 113 | + /** Indicates the abort reason when Subevent_Done_Status received from the Core Controller |
| 114 | + * (Core Specification, Volume 4, Part 4, Section 7.7.65.44) is set to 0xF, |
| 115 | + * otherwise the default value is set to zero. |
| 116 | + * 0x0: Report with no abort |
| 117 | + * 0x1: Abort because of local Host or remote request |
| 118 | + * 0x2: Abort because no CS_SYNC (mode 0) received |
| 119 | + * 0x3: Abort because of scheduling conflicts or limited resources |
| 120 | + * 0xF: Abort because of unspecified reasons |
| 121 | + * All other values: RFU |
| 122 | + */ |
| 123 | + uint8_t subevent_abort_reason : 4; |
| 124 | + /** Reference power level. Range: -127 to 20. Units: dBm */ |
| 125 | + int8_t ref_power_level; |
| 126 | + /** Number of steps in the CS Subevent for which results are reported. |
| 127 | + * If the Subevent is aborted, then the Number Of Steps Reported can be set to zero |
| 128 | + */ |
| 129 | + uint8_t num_steps_reported; |
| 130 | +} __packed; |
| 131 | +BUILD_ASSERT(sizeof(struct ras_subevent_header) == BT_RAS_SUBEVENT_HEADER_LEN); |
| 132 | + |
| 133 | +#ifdef __cplusplus |
| 134 | +} |
| 135 | +#endif |
| 136 | + |
| 137 | +/** |
| 138 | + * @} |
| 139 | + */ |
| 140 | + |
| 141 | +#endif /* BT_RAS_H_ */ |
0 commit comments