Skip to content

Commit d5e1da7

Browse files
alexstanoev-nordicnordicjm
authored andcommitted
bluetooth: services: ras: Add initial folder structure for ranging service
This adds the base folder structure and headers to be used in the implementation of the Ranging Service draft specification. Create RAS primary service and support reading RRSP features. Signed-off-by: Aleksandar Stanoev <[email protected]>
1 parent fdf865b commit d5e1da7

File tree

10 files changed

+331
-0
lines changed

10 files changed

+331
-0
lines changed

include/bluetooth/services/ras.h

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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_ */

subsys/bluetooth/services/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ zephyr_sources_ifdef(CONFIG_BT_DDFS ddfs.c)
2828
zephyr_sources_ifdef(CONFIG_BT_MDS mds.c)
2929
add_subdirectory_ifdef(CONFIG_BT_CGMS cgms)
3030
add_subdirectory_ifdef(CONFIG_BT_FAST_PAIR fast_pair)
31+
add_subdirectory_ifdef(CONFIG_BT_RAS ras)
3132
add_subdirectory_ifdef(CONFIG_BT_WIFI_PROV wifi_prov)

subsys/bluetooth/services/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ rsource "Kconfig.ddfs"
3434
rsource "Kconfig.mds"
3535
rsource "cgms/Kconfig.cgms"
3636
rsource "fast_pair/Kconfig.fast_pair"
37+
rsource "ras/Kconfig.ras"
3738
rsource "wifi_prov/Kconfig.wifi_prov"
3839

3940
endmenu
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
add_subdirectory_ifdef(CONFIG_BT_RAS_RRSP rrsp)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
config BT_RAS
8+
bool
9+
help
10+
Common Bluetooth GATT Ranging Service modules.
11+
12+
rsource "rreq/Kconfig.ras_rreq"
13+
rsource "rrsp/Kconfig.ras_rrsp"
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#ifndef BT_RAS_INTERNAL_H_
8+
#define BT_RAS_INTERNAL_H_
9+
10+
#include <zephyr/kernel.h>
11+
#include <zephyr/bluetooth/conn.h>
12+
#include <zephyr/bluetooth/gatt.h>
13+
#include <bluetooth/services/ras.h>
14+
#include <stdint.h>
15+
16+
#ifdef __cplusplus
17+
extern "C" {
18+
#endif
19+
20+
#define RASCP_CMD_OPCODE_LEN 1
21+
#define RASCP_CMD_OPCODE_OFFSET 0
22+
#define RASCP_CMD_PARAMS_OFFSET RASCP_CMD_OPCODE_LEN
23+
#define RASCP_CMD_PARAMS_MAX_LEN 4
24+
#define RASCP_WRITE_MAX_LEN (RASCP_CMD_OPCODE_LEN + RASCP_CMD_PARAMS_MAX_LEN)
25+
26+
/** @brief RAS Control Point opcodes as defined in RAS Specification, Table 3.10. */
27+
enum rascp_opcode {
28+
RASCP_OPCODE_GET_RD = 0x00,
29+
RASCP_OPCODE_ACK_RD = 0x01,
30+
RASCP_OPCODE_RETRIEVE_LOST_RD_SEGMENTS = 0x02,
31+
RASCP_OPCODE_ABORT_OP = 0x03,
32+
RASCP_OPCODE_SET_FILTER = 0x04,
33+
};
34+
35+
/** @brief RAS Control Point Response opcodes as defined in RAS Specification, Table 3.11. */
36+
enum rascp_rsp_opcode {
37+
RASCP_RSP_OPCODE_COMPLETE_RD_RSP = 0x00,
38+
RASCP_RSP_OPCODE_COMPLETE_LOST_RD_SEG_RSP = 0x01,
39+
RASCP_RSP_OPCODE_RSP_CODE = 0x02,
40+
};
41+
42+
#define RASCP_RSP_OPCODE_COMPLETE_RD_RSP_LEN 2
43+
#define RASCP_RSP_OPCODE_COMPLETE_LOST_RD_SEG_RSP_LEN 4
44+
#define RASCP_RSP_OPCODE_RSP_CODE_LEN 1
45+
46+
/** @brief RAS Control Point Response Code Values as defined in RAS Specification, Table 3.12. */
47+
enum rascp_rsp_code {
48+
RASCP_RESPONSE_RESERVED = 0x00,
49+
RASCP_RESPONSE_SUCCESS = 0x01,
50+
RASCP_RESPONSE_OPCODE_NOT_SUPPORTED = 0x02,
51+
RASCP_RESPONSE_INVALID_PARAMETER = 0x03,
52+
RASCP_RESPONSE_SUCCESS_PERSISTED = 0x04,
53+
RASCP_RESPONSE_ABORT_UNSUCCESSFUL = 0x05,
54+
RASCP_RESPONSE_PROCEDURE_NOT_COMPLETED = 0x06,
55+
RASCP_RESPONSE_SERVER_BUSY = 0x07,
56+
RASCP_RESPONSE_NO_RECORDS_FOUND = 0x08,
57+
};
58+
59+
/** @brief RAS Features as defined in RAS Specification, Table 3.3. */
60+
enum ras_feat {
61+
RAS_FEAT_REALTIME_RD = BIT(0),
62+
RAS_FEAT_RETRIEVE_LOST_RD_SEG = BIT(1),
63+
RAS_FEAT_ABORT_OP = BIT(2),
64+
RAS_FEAT_FILTER_RD = BIT(3),
65+
};
66+
67+
/** @brief RAS ATT Application error codes as defined in RAS Specification, Table 2.1. */
68+
enum ras_att_error {
69+
RAS_ATT_ERROR_CCC_CONFIG = 0xFD,
70+
RAS_ATT_ERROR_WRITE_REQ_REJECTED = 0xFC,
71+
};
72+
73+
/** @brief RAS Segmentation Header as defined in RAS Specification, Table 3.5. */
74+
struct ras_seg_header {
75+
bool first_seg : 1;
76+
bool last_seg : 1;
77+
uint8_t seg_counter : 6;
78+
} __packed;
79+
BUILD_ASSERT(sizeof(struct ras_seg_header) == 1);
80+
81+
/** @brief RAS Ranging Data segment format as defined in RAS Specification, Table 3.4. */
82+
struct ras_segment {
83+
struct ras_seg_header header;
84+
uint8_t data[];
85+
} __packed;
86+
87+
#ifdef __cplusplus
88+
}
89+
#endif
90+
91+
#endif /* BT_RAS_INTERNAL_H_ */
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
menuconfig BT_RAS_RREQ
8+
bool "Enable GATT Ranging Requester Client [EXPERIMENTAL]"
9+
depends on BT_CHANNEL_SOUNDING
10+
select EXPERIMENTAL
11+
select BT_NRF_SERVICES
12+
select BT_RAS
13+
14+
if BT_RAS_RREQ
15+
16+
module = BT_RAS_RREQ
17+
module-str = RAS_RREQ
18+
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
19+
20+
endif # BT_RAS_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_RRSP
9+
ras_rrsp.c)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
menuconfig BT_RAS_RRSP
8+
bool "Enable GATT Ranging Responder Server [EXPERIMENTAL]"
9+
depends on BT_CHANNEL_SOUNDING
10+
select EXPERIMENTAL
11+
select BT_NRF_SERVICES
12+
select BT_RAS
13+
14+
if BT_RAS_RRSP
15+
16+
module = BT_RAS_RRSP
17+
module-str = RAS_RRSP
18+
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
19+
20+
endif # BT_RAS_RRSP
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/bluetooth/conn.h>
8+
#include <zephyr/bluetooth/uuid.h>
9+
#include <zephyr/bluetooth/gatt.h>
10+
#include <zephyr/logging/log.h>
11+
#include <bluetooth/services/ras.h>
12+
13+
LOG_MODULE_REGISTER(ras_rrsp, CONFIG_BT_RAS_RRSP_LOG_LEVEL);
14+
15+
static uint32_t ras_features; /* No optional features supported. */
16+
17+
static ssize_t ras_features_read(struct bt_conn *conn, const struct bt_gatt_attr *attr,
18+
void *buf, uint16_t len, uint16_t offset)
19+
{
20+
return bt_gatt_attr_read(conn, attr, buf, len, offset, &ras_features, sizeof(ras_features));
21+
}
22+
23+
BT_GATT_SERVICE_DEFINE(rrsp_svc,
24+
BT_GATT_PRIMARY_SERVICE(BT_UUID_RANGING_SERVICE),
25+
/* RAS Features */
26+
BT_GATT_CHARACTERISTIC(BT_UUID_RAS_FEATURES, BT_GATT_CHRC_READ,
27+
BT_GATT_PERM_READ_ENCRYPT, ras_features_read, NULL, NULL),
28+
);

0 commit comments

Comments
 (0)