NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
ble_ll_ctrl.h
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_LL_CTRL_
21#define H_BLE_LL_CTRL_
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27/*
28 * LL control procedures. This "enumeration" is not in the specification;
29 * It is used to determine which LL control procedure is currently running
30 * in a connection and which ones may be pending.
31 */
32#define BLE_LL_CTRL_PROC_CONN_UPDATE (0)
33#define BLE_LL_CTRL_PROC_CHAN_MAP_UPD (1)
34#define BLE_LL_CTRL_PROC_ENCRYPT (2)
35#define BLE_LL_CTRL_PROC_FEATURE_XCHG (3)
36#define BLE_LL_CTRL_PROC_VERSION_XCHG (4)
37#define BLE_LL_CTRL_PROC_TERMINATE (5)
38#define BLE_LL_CTRL_PROC_CONN_PARAM_REQ (6)
39#define BLE_LL_CTRL_PROC_LE_PING (7)
40#define BLE_LL_CTRL_PROC_DATA_LEN_UPD (8)
41#define BLE_LL_CTRL_PROC_PHY_UPDATE (9)
42#define BLE_LL_CTRL_PROC_SCA_UPDATE (10)
43#define BLE_LL_CTRL_PROC_CIS_CREATE (11)
44#define BLE_LL_CTRL_PROC_SUBRATE_REQ (12)
45#define BLE_LL_CTRL_PROC_SUBRATE_UPDATE (13)
46#define BLE_LL_CTRL_PROC_NUM (14)
47#define BLE_LL_CTRL_PROC_IDLE (255)
48
49/* Checks if a particular control procedure is running */
50#define IS_PENDING_CTRL_PROC(sm, proc) (sm->pending_ctrl_procs & (1 << proc))
51#define CLR_PENDING_CTRL_PROC(sm, proc) (sm->pending_ctrl_procs &= ~(1 << proc))
52
53/* LL control procedure timeout */
54#define BLE_LL_CTRL_PROC_TIMEOUT_MS (40000) /* ms */
55
56/*
57 * LL CTRL PDU format
58 * -> Opcode (1 byte)
59 * -> Data (0 - 26 bytes)
60 */
61#define BLE_LL_CTRL_CONN_UPDATE_IND (0x00)
62#define BLE_LL_CTRL_CHANNEL_MAP_REQ (0x01)
63#define BLE_LL_CTRL_TERMINATE_IND (0x02)
64#define BLE_LL_CTRL_ENC_REQ (0x03)
65#define BLE_LL_CTRL_ENC_RSP (0x04)
66#define BLE_LL_CTRL_START_ENC_REQ (0x05)
67#define BLE_LL_CTRL_START_ENC_RSP (0x06)
68#define BLE_LL_CTRL_UNKNOWN_RSP (0x07)
69#define BLE_LL_CTRL_FEATURE_REQ (0x08)
70#define BLE_LL_CTRL_FEATURE_RSP (0x09)
71#define BLE_LL_CTRL_PAUSE_ENC_REQ (0x0A)
72#define BLE_LL_CTRL_PAUSE_ENC_RSP (0x0B)
73#define BLE_LL_CTRL_VERSION_IND (0x0C)
74#define BLE_LL_CTRL_REJECT_IND (0x0D)
75#define BLE_LL_CTRL_PERIPH_FEATURE_REQ (0x0E)
76#define BLE_LL_CTRL_CONN_PARM_REQ (0x0F)
77#define BLE_LL_CTRL_CONN_PARM_RSP (0x10)
78#define BLE_LL_CTRL_REJECT_IND_EXT (0x11)
79#define BLE_LL_CTRL_PING_REQ (0x12)
80#define BLE_LL_CTRL_PING_RSP (0x13)
81#define BLE_LL_CTRL_LENGTH_REQ (0x14)
82#define BLE_LL_CTRL_LENGTH_RSP (0x15)
83#define BLE_LL_CTRL_PHY_REQ (0x16)
84#define BLE_LL_CTRL_PHY_RSP (0x17)
85#define BLE_LL_CTRL_PHY_UPDATE_IND (0x18)
86#define BLE_LL_CTRL_MIN_USED_CHAN_IND (0x19)
87#define BLE_LL_CTRL_CTE_REQ (0x1A)
88#define BLE_LL_CTRL_CTE_RSP (0x1B)
89#define BLE_LL_CTRL_PERIODIC_SYNC_IND (0x1C)
90#define BLE_LL_CTRL_CLOCK_ACCURACY_REQ (0x1D)
91#define BLE_LL_CTRL_CLOCK_ACCURACY_RSP (0x1E)
92#define BLE_LL_CTRL_CIS_REQ (0x1F)
93#define BLE_LL_CTRL_CIS_RSP (0x20)
94#define BLE_LL_CTRL_CIS_IND (0x21)
95#define BLE_LL_CTRL_CIS_TERMINATE_IND (0x22)
96#define BLE_LL_CTRL_POWER_CONTROL_REQ (0x23)
97#define BLE_LL_CTRL_POWER_CONTROL_RSP (0x24)
98#define BLE_LL_CTRL_POWER_CHANGE_IND (0x25)
99#define BLE_LL_CTRL_SUBRATE_REQ (0x26)
100#define BLE_LL_CTRL_SUBRATE_IND (0x27)
101#define BLE_LL_CTRL_CHAN_REPORTING_IND (0x28)
102#define BLE_LL_CTRL_CHAN_STATUS_IND (0x29)
103
104/* Maximum opcode value */
105#define BLE_LL_CTRL_OPCODES (BLE_LL_CTRL_CHAN_STATUS_IND + 1)
106
107extern const uint8_t g_ble_ll_ctrl_pkt_lengths[BLE_LL_CTRL_OPCODES];
108
109/* Maximum LL control PDU size */
110#if MYNEWT_VAL(BLE_ISO)
111#define BLE_LL_CTRL_MAX_PDU_LEN (42)
112#elif MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_SYNC_TRANSFER)
113#define BLE_LL_CTRL_MAX_PDU_LEN (35)
114#else
115#define BLE_LL_CTRL_MAX_PDU_LEN (27)
116#endif
117
118/* LL control connection update request */
119struct ble_ll_conn_upd_req
120{
121 uint8_t winsize;
122 uint16_t winoffset;
123 uint16_t interval;
124 uint16_t latency;
125 uint16_t timeout;
126 uint16_t instant;
127};
128#define BLE_LL_CTRL_CONN_UPD_REQ_LEN (11)
129
130/* LL control channel map request */
131struct ble_ll_chan_map_req
132{
133 uint8_t chmap[5];
134 uint16_t instant;
135};
136#define BLE_LL_CTRL_CHAN_MAP_LEN (7)
137
138/*
139 * LL control terminate ind
140 * -> error code (1 byte)
141 */
142#define BLE_LL_CTRL_TERMINATE_IND_LEN (1)
143
144/* LL control enc req */
145struct ble_ll_enc_req
146{
147 uint8_t rand[8];
148 uint16_t ediv;
149 uint8_t skdm[8];
150 uint32_t ivm;
151};
152
153#define BLE_LL_CTRL_ENC_REQ_LEN (22)
154
155/* LL control enc rsp */
156struct ble_ll_enc_rsp
157{
158 uint8_t skds[8];
159 uint32_t ivs;
160};
161
162#define BLE_LL_CTRL_ENC_RSP_LEN (12)
163
164/* LL control start/pause enc request and response */
165#define BLE_LL_CTRL_START_ENC_REQ_LEN (0)
166#define BLE_LL_CTRL_START_ENC_RSP_LEN (0)
167#define BLE_LL_CTRL_PAUSE_ENC_REQ_LEN (0)
168#define BLE_LL_CTRL_PAUSE_ENC_RSP_LEN (0)
169
170/*
171 * LL control unknown response
172 * -> 1 byte which contains the unknown or un-supported opcode.
173 */
174#define BLE_LL_CTRL_UNK_RSP_LEN (1)
175
176/*
177 * LL control feature req and LL control feature rsp
178 * -> 8 bytes of data containing features supported by device.
179 */
180#define BLE_LL_CTRL_FEATURE_LEN (8)
181
182/*
183 * LL control version ind
184 * -> version (1 byte):
185 * Contains the version number of the bluetooth controller specification.
186 * -> comp_id (2 bytes)
187 * Contains the company identifier of the manufacturer of the controller.
188 * -> sub_ver_num: Contains a unique value for implementation or revision of
189 * the bluetooth controller.
190 */
191struct ble_ll_version_ind
192{
193 uint8_t ble_ctrlr_ver;
194 uint16_t company_id;
195 uint16_t sub_ver_num;
196};
197
198#define BLE_LL_CTRL_VERSION_IND_LEN (5)
199
200/*
201 * LL control reject ind
202 * -> error code (1 byte): contains reason why request was rejected.
203 */
204#define BLE_LL_CTRL_REJ_IND_LEN (1)
205
206/*
207 * LL control slave feature req
208 * -> 8 bytes of data containing features supported by device.
209 */
210#define BLE_LL_CTRL_PERIPH_FEATURE_REQ_LEN (8)
211
212/* LL control connection param req and connection param rsp */
213struct ble_ll_conn_params
214{
215 uint16_t interval_min;
216 uint16_t interval_max;
217 uint16_t latency;
218 uint16_t timeout;
219 uint8_t pref_periodicity;
220 uint16_t ref_conn_event_cnt;
221 uint16_t offset0;
222 uint16_t offset1;
223 uint16_t offset2;
224 uint16_t offset3;
225 uint16_t offset4;
226 uint16_t offset5;
227};
228
229#define BLE_LL_CTRL_CONN_PARAMS_LEN (23)
230
231/* LL control reject ind ext */
232struct ble_ll_reject_ind_ext
233{
234 uint8_t reject_opcode;
235 uint8_t err_code;
236};
237
238#define BLE_LL_CTRL_REJECT_IND_EXT_LEN (2)
239
240/* LL control ping req and ping rsp (contain no data) */
241#define BLE_LL_CTRL_PING_LEN (0)
242
243/*
244 * LL control length req and length rsp
245 * -> max_rx_bytes (2 bytes): defines connMaxRxOctets. Range 27 to 251
246 * -> max_rx_time (2 bytes): defines connMaxRxTime. Range 328 to 2120 usecs.
247 * -> max_tx_bytes (2 bytes): defines connMaxTxOctets. Range 27 to 251
248 * -> max_tx_time (2 bytes): defines connMaxTxTime. Range 328 to 2120 usecs.
249 */
250struct ble_ll_len_req
251{
252 uint16_t max_rx_bytes;
253 uint16_t max_rx_time;
254 uint16_t max_tx_bytes;
255 uint16_t max_tx_time;
256};
257
258#define BLE_LL_CTRL_LENGTH_REQ_LEN (8)
259
260/* PHY request/response */
261#define BLE_LL_CTRL_PHY_REQ_LEN (2)
262#define BLE_LL_CTRL_PHY_RSP_LEN (2)
263#define BLE_LL_CTRL_PHY_UPD_IND_LEN (4)
264
265/* Min used channels */
266#define BLE_LL_CTRL_MIN_USED_CHAN_LEN (2)
267
268/* CTE REQ */
269#define BLE_LL_CTRL_CTE_REQ_LEN (1)
270
271/* CTE RSP (contains no data) */
272#define BLE_LL_CTRL_CTE_RSP_LEN (0)
273
274/* Periodic Sync Transfer IND */
275#define BLE_LL_CTRL_PERIODIC_SYNC_IND_LEN (34)
276
277/* Clock accuracy request/response */
278#define BLE_LL_CTRL_CLOCK_ACCURACY_REQ_LEN (1)
279#define BLE_LL_CTRL_CLOCK_ACCURACY_RSP_LEN (1)
280
281/* BLE ISO */
282#define BLE_LL_CTRL_CIS_REQ_LEN (42)
283#define BLE_LL_CTRL_CIS_RSP_LEN (8)
284#define BLE_LL_CTRL_CIS_IND_LEN (15)
285#define BLE_LL_CTRL_CIS_TERMINATE_LEN (3)
286
287#define BLE_LL_CTRL_POWER_CONTROL_REQ_LEN (3)
288#define BLE_LL_CTRL_POWER_CONTROL_RSP_LEN (4)
289#define BLE_LL_CTRL_POWER_CHANGE_IND_LEN (4)
290#define BLE_LL_CTRL_SUBRATE_REQ_LEN (10)
291#define BLE_LL_CTRL_SUBRATE_IND_LEN (10)
292#define BLE_LL_CTRL_CHAN_REPORTING_IND_LEN (3)
293#define BLE_LL_CTRL_CHAN_STATUS_IND_LEN (10)
294
295/* API */
296struct ble_ll_conn_sm;
297void ble_ll_ctrl_proc_start(struct ble_ll_conn_sm *connsm, int ctrl_proc,
298 void *data);
299void ble_ll_ctrl_proc_stop(struct ble_ll_conn_sm *connsm, int ctrl_proc);
300int ble_ll_ctrl_rx_pdu(struct ble_ll_conn_sm *connsm, struct os_mbuf *om);
301void ble_ll_ctrl_chk_proc_start(struct ble_ll_conn_sm *connsm);
302void ble_ll_ctrl_terminate_start(struct ble_ll_conn_sm *connsm);
303int ble_ll_ctrl_is_terminate_ind(uint8_t hdr, uint8_t opcode);
304uint8_t ble_ll_ctrl_conn_param_reply(struct ble_ll_conn_sm *connsm,
305 uint8_t *rsp,
306 struct ble_ll_conn_params *req);
307int ble_ll_ctrl_reject_ind_send(struct ble_ll_conn_sm *connsm,
308 uint8_t rej_opcode, uint8_t err);
309int ble_ll_ctrl_start_enc_send(struct ble_ll_conn_sm *connsm);
310int ble_ll_ctrl_enc_allowed_pdu_rx(struct os_mbuf *rxpdu);
311int ble_ll_ctrl_enc_allowed_pdu_tx(struct os_mbuf_pkthdr *pkthdr);
312int ble_ll_ctrl_tx_start(struct ble_ll_conn_sm *connsm, struct os_mbuf *txpdu);
313int ble_ll_ctrl_tx_done(struct os_mbuf *txpdu, struct ble_ll_conn_sm *connsm);
314int ble_ll_ctrl_is_start_enc_rsp(struct os_mbuf *txpdu);
315
316void ble_ll_hci_ev_datalen_chg(struct ble_ll_conn_sm *connsm);
317void ble_ll_hci_ev_rem_conn_parm_req(struct ble_ll_conn_sm *connsm,
318 struct ble_ll_conn_params *cp);
319void ble_ll_hci_ev_conn_update(struct ble_ll_conn_sm *connsm, uint8_t status);
320void ble_ll_hci_ev_rd_rem_used_feat(struct ble_ll_conn_sm *connsm,
321 uint8_t status);
322void ble_ll_hci_ev_rd_rem_ver(struct ble_ll_conn_sm *connsm, uint8_t status);
323void ble_ll_hci_ev_encrypt_chg(struct ble_ll_conn_sm *connsm, uint8_t status);
324int ble_ll_hci_ev_ltk_req(struct ble_ll_conn_sm *connsm);
325int ble_ll_hci_ev_hw_err(uint8_t hw_err);
326void ble_ll_hci_ev_databuf_overflow(void);
327void ble_ll_hci_ev_le_csa(struct ble_ll_conn_sm *connsm);
328void ble_ll_hci_ev_send_scan_req_recv(uint8_t adv_handle, const uint8_t *peer,
329 uint8_t peer_addr_type);
330void ble_ll_hci_ev_send_scan_timeout(void);
331void ble_ll_hci_ev_send_adv_set_terminated(uint8_t status, uint8_t adv_handle,
332 uint16_t conn_handle, uint8_t events);
333int ble_ll_hci_ev_phy_update(struct ble_ll_conn_sm *connsm, uint8_t status);
334void ble_ll_calc_session_key(struct ble_ll_conn_sm *connsm);
335void ble_ll_ctrl_phy_update_proc_complete(struct ble_ll_conn_sm *connsm);
336void ble_ll_ctrl_initiate_dle(struct ble_ll_conn_sm *connsm);
337void ble_ll_hci_ev_send_vs_assert(const char *file, uint32_t line);
338void ble_ll_hci_ev_send_vs_llcp_trace(uint8_t type, uint16_t handle, uint16_t count,
339 void *pdu, size_t length);
340
341uint8_t ble_ll_ctrl_phy_tx_transition_get(uint8_t phy_mask);
342uint8_t ble_ll_ctrl_phy_from_phy_mask(uint8_t phy_mask);
343
344#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_SCA_UPDATE)
345void ble_ll_hci_ev_sca_update(struct ble_ll_conn_sm *connsm,
346 uint8_t status, uint8_t peer_sca);
347#endif
348
349#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_ENHANCED_CONN_UPDATE)
350void ble_ll_hci_ev_subrate_change(struct ble_ll_conn_sm *connsm, uint8_t status);
351#endif
352
353#ifdef __cplusplus
354}
355#endif
356
357#endif /* H_BLE_LL_CTRL_ */
Definition os_mbuf.h:70
Definition os_mbuf.h:86