Skip to content

Commit 28b4964

Browse files
committed
nimble/host: Add RAS for Channel Sounding
Add GATT Randing Service used in Channel Sounding.
1 parent a178b47 commit 28b4964

File tree

10 files changed

+3317
-2
lines changed

10 files changed

+3317
-2
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#ifndef H_BLE_PEER_
21+
#define H_BLE_PEER_
22+
23+
#include "os/mynewt.h"
24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif
27+
28+
/** Peer. */
29+
struct ble_peer_dsc {
30+
SLIST_ENTRY(ble_peer_dsc) next;
31+
struct ble_gatt_dsc dsc;
32+
};
33+
SLIST_HEAD(ble_peer_dsc_list, ble_peer_dsc);
34+
35+
struct ble_peer_chr {
36+
SLIST_ENTRY(ble_peer_chr) next;
37+
struct ble_gatt_chr chr;
38+
39+
struct ble_peer_dsc_list dscs;
40+
};
41+
SLIST_HEAD(ble_peer_chr_list, ble_peer_chr);
42+
43+
struct ble_peer_svc {
44+
SLIST_ENTRY(ble_peer_svc) next;
45+
struct ble_gatt_svc svc;
46+
47+
struct ble_peer_chr_list chrs;
48+
};
49+
SLIST_HEAD(ble_peer_svc_list, ble_peer_svc);
50+
51+
struct ble_peer;
52+
typedef void ble_peer_disc_fn(const struct ble_peer *peer, int status, void *arg);
53+
54+
struct ble_peer {
55+
SLIST_ENTRY(ble_peer) next;
56+
57+
uint16_t conn_handle;
58+
59+
/** List of discovered GATT services. */
60+
struct ble_peer_svc_list svcs;
61+
62+
/** Keeps track of where we are in the service discovery process. */
63+
uint16_t disc_prev_chr_val;
64+
struct ble_peer_svc *cur_svc;
65+
66+
/** Callback that gets executed when service discovery completes. */
67+
ble_peer_disc_fn *disc_cb;
68+
void *disc_cb_arg;
69+
};
70+
71+
struct ble_peer *ble_peer_find(uint16_t conn_handle);
72+
int ble_peer_disc_all(uint16_t conn_handle, ble_peer_disc_fn *disc_cb, void *disc_cb_arg);
73+
const struct ble_peer_dsc *ble_peer_dsc_find_uuid(const struct ble_peer *peer,
74+
const ble_uuid_t *svc_uuid, const ble_uuid_t *chr_uuid, const ble_uuid_t *dsc_uuid);
75+
const struct ble_peer_chr *ble_peer_chr_find_uuid(const struct ble_peer *peer,
76+
const ble_uuid_t *svc_uuid, const ble_uuid_t *chr_uuid);
77+
const struct ble_peer_svc *ble_peer_svc_find_uuid(const struct ble_peer *peer, const ble_uuid_t *uuid);
78+
int ble_peer_delete(uint16_t conn_handle);
79+
int ble_peer_add(uint16_t conn_handle);
80+
81+
#ifdef __cplusplus
82+
}
83+
#endif
84+
85+
#endif

nimble/host/pkg.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,8 @@ pkg.req_apis:
5555
pkg.down.BLE_HS_STOP_ON_SHUTDOWN:
5656
ble_hs_shutdown: 200
5757

58+
pkg.init.'BLE_PEER':
59+
ble_peer_init: $after:ble_transport_hs_init
60+
5861
pkg.init.'BLE_CHANNEL_SOUNDING':
5962
ble_cs_init: $after:ble_transport_hs_init
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#ifndef H_BLE_SVC_RAS_
21+
#define H_BLE_SVC_RAS_
22+
23+
#include <inttypes.h>
24+
#include "host/ble_cs.h"
25+
26+
#ifdef __cplusplus
27+
extern "C" {
28+
#endif
29+
30+
#define BLE_CONN_HANDLE_INVALID 0xffff
31+
32+
#define BLE_SVC_RAS_SVC_RANGING_SERVICE_UUID 0x185B
33+
#define BLE_SVC_RAS_CHR_RAS_FEATURES_UUID 0x2C14
34+
#define BLE_SVC_RAS_CHR_REAL_TIME_RANGING_DATA_UUID 0x2C15
35+
#define BLE_SVC_RAS_CHR_ON_DEMAND_RANGING_DATA_UUID 0x2C16
36+
#define BLE_SVC_RAS_CHR_RAS_CONTROL_POINT_UUID 0x2C17
37+
#define BLE_SVC_RAS_CHR_RANGING_DATA_READY_UUID 0x2C18
38+
#define BLE_SVC_RAS_CHR_RANGING_DATA_OVERWRITTEN_UUID 0x2C19
39+
40+
#define BLE_SVC_RAS_FILTER_MODE0_POSITION (0)
41+
#define BLE_SVC_RAS_FILTER_MODE1_POSITION (BLE_SVC_RAS_FILTER_MODE0_POSITION << 14)
42+
#define BLE_SVC_RAS_FILTER_MODE2_POSITION (BLE_SVC_RAS_FILTER_MODE1_POSITION << 14)
43+
#define BLE_SVC_RAS_FILTER_MODE3_POSITION (BLE_SVC_RAS_FILTER_MODE3_POSITION << 14)
44+
45+
#define BLE_SVC_RAS_FILTER_MODE0_MASK (0xF)
46+
#define BLE_SVC_RAS_FILTER_MODE1_MASK (0x7F)
47+
#define BLE_SVC_RAS_FILTER_MODE2_MASK (0x7F)
48+
#define BLE_SVC_RAS_FILTER_MODE3_MASK (0x3FFF)
49+
50+
#define BLE_SVC_RAS_FILTER_MODE0_PACKET_QUALITY (0)
51+
#define BLE_SVC_RAS_FILTER_MODE0_PACKET_RSSI (1)
52+
#define BLE_SVC_RAS_FILTER_MODE0_PACKET_ANTENNA (2)
53+
#define BLE_SVC_RAS_FILTER_MODE0_MEASURED_FREQ_OFFSET (3)
54+
55+
#define BLE_SVC_RAS_FILTER_MODE1_PACKET_QUALITY (0)
56+
#define BLE_SVC_RAS_FILTER_MODE1_PACKET_NADM (1)
57+
#define BLE_SVC_RAS_FILTER_MODE1_PACKET_RSSI (2)
58+
#define BLE_SVC_RAS_FILTER_MODE1_TOD_TOA (3)
59+
#define BLE_SVC_RAS_FILTER_MODE1_PACKET_ANTENNA (4)
60+
#define BLE_SVC_RAS_FILTER_MODE1_PACKET_PCT1 (5)
61+
#define BLE_SVC_RAS_FILTER_MODE1_PACKET_PCT2 (6)
62+
63+
#define BLE_SVC_RAS_FILTER_MODE2_ANTENNA_PERMUTATION_ID (0)
64+
#define BLE_SVC_RAS_FILTER_MODE2_TONE_PCT (1)
65+
#define BLE_SVC_RAS_FILTER_MODE2_TONE_QUALITY (2)
66+
#define BLE_SVC_RAS_FILTER_MODE2_ANTENNA_PATH_1 (3)
67+
#define BLE_SVC_RAS_FILTER_MODE2_ANTENNA_PATH_2 (4)
68+
#define BLE_SVC_RAS_FILTER_MODE2_ANTENNA_PATH_3 (5)
69+
#define BLE_SVC_RAS_FILTER_MODE2_ANTENNA_PATH_4 (6)
70+
71+
#define BLE_SVC_RAS_FILTER_MODE3_PACKET_QUALITY (0)
72+
#define BLE_SVC_RAS_FILTER_MODE3_PACKET_NADM (1)
73+
#define BLE_SVC_RAS_FILTER_MODE3_PACKET_RSSI (2)
74+
#define BLE_SVC_RAS_FILTER_MODE3_TOD_TOA (3)
75+
#define BLE_SVC_RAS_FILTER_MODE3_PACKET_ANTENNA (4)
76+
#define BLE_SVC_RAS_FILTER_MODE3_PACKET_PCT1 (5)
77+
#define BLE_SVC_RAS_FILTER_MODE3_PACKET_PCT2 (6)
78+
#define BLE_SVC_RAS_FILTER_MODE3_ANTENNA_PERMUTATION_ID (7)
79+
#define BLE_SVC_RAS_FILTER_MODE3_TONE_PCT (8)
80+
#define BLE_SVC_RAS_FILTER_MODE3_TONE_QUALITY (9)
81+
#define BLE_SVC_RAS_FILTER_MODE3_ANTENNA_PATH_1 (10)
82+
#define BLE_SVC_RAS_FILTER_MODE3_ANTENNA_PATH_2 (11)
83+
#define BLE_SVC_RAS_FILTER_MODE3_ANTENNA_PATH_3 (12)
84+
#define BLE_SVC_RAS_FILTER_MODE3_ANTENNA_PATH_4 (13)
85+
86+
#define BLE_SVC_RAS_CP_CMD_GET_RANGING_DATA (0x00)
87+
#define BLE_SVC_RAS_CP_CMD_ACK_RANGING_DATA (0x01)
88+
#define BLE_SVC_RAS_CP_CMD_RETRIEVE_LOST_SEGMENT (0x02)
89+
#define BLE_SVC_RAS_CP_CMD_ABORT_OPERATION (0x03)
90+
#define BLE_SVC_RAS_CP_CMD_SET_FILTER (0x04)
91+
92+
#define BLE_SVC_RAS_CP_RSP_COMPLETE_RANGING_DATA (0x00)
93+
#define BLE_SVC_RAS_CP_RSP_COMPLETE_LOST_SEGMENT (0x01)
94+
#define BLE_SVC_RAS_CP_RSP_RESPONSE_CODE (0x02)
95+
96+
#define BLE_SVC_RAS_CP_RSPCODE_SUCCESS (0x01)
97+
#define BLE_SVC_RAS_CP_RSPCODE_OP_CODE_NOT_SUPPORTED (0x02)
98+
#define BLE_SVC_RAS_CP_RSPCODE_INVALID_PARAMETER (0x03)
99+
#define BLE_SVC_RAS_CP_RSPCODE_SUCCESS_PERSISTED (0x04)
100+
#define BLE_SVC_RAS_CP_RSPCODE_ABORT_UNSUCCESSFUL (0x05)
101+
#define BLE_SVC_RAS_CP_RSPCODE_PROCEDURE_NOT_COMPLETED (0x06)
102+
#define BLE_SVC_RAS_CP_RSPCODE_SERVER_BUSY (0x07)
103+
#define BLE_SVC_RAS_CP_RSPCODE_NO_RECORDS_FOUND (0x08)
104+
105+
#define BLE_SVC_RAS_MODE_REAL_TIME (0)
106+
#define BLE_SVC_RAS_MODE_ON_DEMAND (1)
107+
108+
#if MYNEWT_VAL(BLE_SVC_RAS_SERVER)
109+
void ble_svc_ras_init(void);
110+
int ble_svc_ras_ranging_data_body_init(uint16_t conn_handle, uint16_t procedure_counter, uint8_t config_id,
111+
uint8_t tx_power, uint8_t antenna_paths_mask);
112+
int ble_svc_ras_ranging_subevent_init(uint16_t conn_handle, uint16_t start_acl_conn_event, uint16_t frequency_compensation,
113+
uint8_t ranging_done_status, uint8_t subevent_done_status,
114+
uint8_t ranging_abort_reason, uint8_t subevent_abort_reason,
115+
uint8_t reference_power_level, uint8_t number_of_steps_reported);
116+
int ble_svc_ras_ranging_subevent_update_status(uint16_t conn_handle, uint8_t number_of_steps_reported,
117+
uint8_t ranging_done_status, uint8_t subevent_done_status,
118+
uint8_t ranging_abort_reason, uint8_t subevent_abort_reason);
119+
int ble_svc_ras_add_step_mode(uint16_t conn_handle, uint8_t mode, uint8_t status);
120+
int ble_svc_ras_add_mode0_result(struct ble_cs_mode0_result *result, uint16_t conn_handle, uint8_t local_role);
121+
int ble_svc_ras_add_mode1_result(struct ble_cs_mode1_result *result, uint16_t conn_handle, uint8_t rtt_pct_included);
122+
int ble_svc_ras_add_mode2_result(struct ble_cs_mode2_result *result, uint16_t conn_handle, uint8_t n_ap);
123+
int ble_svc_ras_add_mode3_result(struct ble_cs_mode3_result *result, uint16_t conn_handle, uint8_t n_ap, uint8_t rtt_pct_included);
124+
int ble_svc_ras_ranging_data_ready(uint16_t conn_handle);
125+
#endif
126+
127+
#if MYNEWT_VAL(BLE_SVC_RAS_CLIENT)
128+
struct ble_svc_ras_clt_ranging_header {
129+
uint16_t ranging_counter;
130+
uint8_t config_id;
131+
uint8_t tx_power;
132+
uint8_t antenna_paths_mask;
133+
};
134+
135+
struct ble_svc_ras_clt_subevent_header {
136+
uint16_t start_acl_conn_event;
137+
uint16_t frequency_compensation;
138+
uint8_t done_status;
139+
uint8_t abort_reason;
140+
uint8_t reference_power_level;
141+
uint8_t number_of_steps_reported;
142+
};
143+
144+
typedef void ble_svc_ras_clt_subscribe_cb(uint16_t conn_handle);
145+
typedef void ble_svc_ras_clt_step_data_received_cb(void *data, uint16_t conn_handle, uint8_t step_mode);
146+
int ble_svc_ras_clt_config_set(uint16_t conn_handle, uint8_t rtt_pct_included, uint8_t n_ap, uint8_t local_role);
147+
int ble_svc_ras_clt_subscribe(ble_svc_ras_clt_subscribe_cb *subscribe_cb,
148+
ble_svc_ras_clt_step_data_received_cb *step_data_cb,
149+
uint16_t conn_handle, uint8_t mode);
150+
#endif
151+
#ifdef __cplusplus
152+
}
153+
#endif
154+
155+
#endif

nimble/host/services/ras/pkg.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
pkg.name: nimble/host/services/ras
21+
pkg.description: Implements the RAS Service.
22+
pkg.author: "Apache Mynewt <[email protected]>"
23+
pkg.homepage: "http://mynewt.apache.org/"
24+
pkg.keywords:
25+
- ble
26+
- bluetooth
27+
- nimble
28+
- ras
29+
30+
pkg.deps:
31+
- nimble/host
32+
33+
pkg.init.'BLE_SVC_RAS_SERVER':
34+
ble_svc_ras_init: 'MYNEWT_VAL(BLE_SVC_RAS_SYSINIT_STAGE)'
35+
36+
pkg.init.'BLE_SVC_RAS_CLIENT':
37+
ble_svc_ras_clt_init: 'MYNEWT_VAL(BLE_SVC_RAS_SYSINIT_STAGE)'
38+
39+
pkg.source_files.'BLE_SVC_RAS_SERVER':
40+
- "src/ble_svc_ras.c"
41+
42+
pkg.source_files.'BLE_SVC_RAS_CLIENT':
43+
- "src/ble_svc_ras_clt.c"

0 commit comments

Comments
 (0)