hci_le.h revision 1.1 1 /* $NetBSD: hci_le.h,v 1.1 2024/03/13 07:22:16 nat Exp $ */
2
3 /*-
4 * Copyright (c) 2020 Nathanial Sloss <nathanialsloss (at) yahoo.com.au>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #define HCI_ADVERT_DATA_SIZE 31 /* advertising data size */
30 #define HCI_SCAN_DATA_SIZE 31 /* scan resp. data size */
31
32 /* LE Event masks */
33 #define HCI_LE_EVMSK_ALL 0x000000000000001f
34 #define HCI_LE_EVMSK_NONE 0x0000000000000000
35 #define HCI_LE_EVMSK_CON_COMPL 0x0000000000000001
36 #define HCI_LE_EVMSK_ADV_REPORT 0x0000000000000002
37 #define HCI_LE_EVMSK_CON_UPDATE_COMPL 0x0000000000000004
38 #define HCI_LE_EVMSK_READ_REMOTE_FEATURES_COMPL 0x0000000000000008
39 #define HCI_LE_EVMSK_LONG_TERM_KEY_REQ 0x0000000000000010
40 /* 0x0000000000000020 - 0x8000000000000000 - reserved for future use */
41
42 /**************************************************************************
43 **************************************************************************
44 ** OGF 0x08 Bluetooth Low Energy (LE) Link commands
45 **************************************************************************
46 **************************************************************************/
47
48 #define HCI_OGF_LE 0x08
49
50 #define HCI_OCF_LE_SET_EVENT_MASK 0x0001
51 #define HCI_CMD_LE_SET_EVENT_MASK 0x2001
52 typedef struct {
53 uint8_t event_mask[HCI_EVENT_MASK_SIZE]; /* event_mask */
54 } __packed hci_le_set_event_mask_cp;
55
56 typedef hci_status_rp hci_le_set_event_mask_rp;
57
58 #define HCI_OCF_LE_READ_BUFFER_SIZE 0x0002
59 #define HCI_CMD_LE_READ_BUFFER_SIZE 0x2002
60 /* No command parameter(s) */
61
62 typedef struct {
63 uint8_t status; /* status 0x00 = success */
64 uint16_t le_data_pktlen; /* buffer len*/
65 uint8_t le_num_pkts; /* no. acl data packets */
66 } __packed hci_le_read_buffer_size_rp;
67
68 #define HCI_OCF_LE_READ_LOCAL_FEATURES 0x0003
69 #define HCI_CMD_LE_READ_LOCAL_FEATURES 0x2003
70 /* No command parameter(s) */
71
72 typedef struct {
73 uint8_t status; /* status 0x00 = success */
74 uint8_t features[HCI_FEATURES_SIZE]; /* le features */
75 } __packed hci_le_read_local_features_rp;
76
77 #define HCI_OCF_LE_SET_RND_ADDR 0x0005
78 #define HCI_CMD_LE_SET_RND_ADDR 0x2005
79 typedef struct {
80 bdaddr_t bdaddr; /* random local address */
81 } __packed hci_le_set_rnd_addr_cp;
82
83 typedef hci_status_rp hci_le_set_rnd_addr_rp;
84 /* XXX NS Finish defines. */
85 #define HCI_OCF_LE_SET_ADVERT_PARAM 0x0006
86 #define HCI_CMD_LE_SET_ADVERT_PARAM 0x2006
87 typedef struct {
88 uint16_t min_interval; /* min interval * 0.625ms */
89 uint16_t max_interval; /* max_interval * 0.625ms */
90 uint8_t advert_type;
91 uint8_t own_address_type;
92 uint8_t direct_address_type;
93 bdaddr_t direct_address; /* remote address */
94 uint8_t advert_channel_map;
95 uint8_t advert_filter_policy;
96 } __packed hci_le_set_advert_param_cp;
97
98 typedef hci_status_rp hci_le_set_advert_param_rp;
99
100 #define HCF_OCF_LE_READ_ADVERT_CHAN_TX_PWR 0x0007
101 #define HCF_CMD_LE_READ_ADVERT_CHAN_TX_PWR 0x2007
102 /* No command parameter(s) */
103
104 typedef struct {
105 uint8_t status; /* status 0x00 = success */
106 int8_t tx_power_level; /* -20 - 10 dBm */
107 } __packed hci_le_read_advert_chan_tx_pwr_rp;
108
109 #define HCF_OCF_LE_SET_ADVERT_DATA 0x0008
110 #define HCF_CMD_LE_SET_ADVERT_DATA 0x2008
111 typedef struct {
112 uint8_t advert_data_len; /* 0x00 - 0x1f */
113 uint8_t advert_data[HCI_ADVERT_DATA_SIZE]; /* def all 0's */
114 } __packed hci_le_set_advert_data_cp;
115
116 typedef hci_status_rp hci_le_set_advert_data_rp;
117
118 #define HCF_OCF_LE_SET_SCAN_RESP_DATA 0x0009
119 #define HCF_CMD_LE_SET_SCAN_RESP_DATA 0x2009
120 typedef struct {
121 uint8_t scan_resp_data_len; /* 0x00 - 0x1f */
122 uint8_t scan_resp_data[HCI_SCAN_DATA_SIZE]; /* def all 0's */
123 } __packed hci_le_set_scan_resp_data_cp;
124
125 typedef hci_status_rp hci_le_set_scan_resp_data_rp;
126
127 #define HCF_OCF_LE_SET_ADVERT_ENABLE 0x000a
128 #define HCF_CMD_LE_SET_ADVERT_ENABLE 0x200A
129 typedef struct {
130 uint8_t advert_enable; /* 0x00 - disable 0x1 - enable */
131 /* 0x2 - 0xff reserved */
132 } __packed hci_le_set_advert_enable_cp;
133
134 typedef hci_status_rp hci_le_set_advert_enable_rp;
135
136 #define HCI_OCF_LE_SET_SCAN_PARAM 0x000b
137 #define HCI_CMD_LE_SET_SCAN_PARAM 0x200B
138 typedef struct {
139 uint8_t scan_type;
140 uint16_t scan_interval; /* min interval * 0.625ms */
141 uint16_t scan_window; /* max_interval * 0.625ms */
142 uint8_t own_address_type;
143 uint8_t scan_filter_policy;
144 } __packed hci_le_set_scan_param_cp;
145
146 typedef hci_status_rp hci_le_set_scan_param_rp;
147
148 #define HCF_OCF_LE_SET_SCAN_ENABLE 0x000c
149 #define HCF_CMD_LE_SET_SCAN_ENABLE 0x200C
150 typedef struct {
151 uint8_t scan_enable; /* 0x00 - disable 0x1 - enable */
152 /* 0x2 - 0xff reserved */
153 uint8_t filter_dup; /* 0x00 - no filtering 0x1 - filter */
154 /* 0x2 - 0xff reserved */
155 } __packed hci_le_set_scan_enable_cp;
156
157 typedef hci_status_rp hci_le_set_scan_enable_rp;
158
159 #define HCI_OCF_CREATE_CON_LE 0x000d
160 #define HCI_CMD_CREATE_CON_LE 0x200D
161 typedef struct {
162 uint16_t scan_interval; /* min interval * 0.625ms */
163 uint16_t scan_window; /* max_interval * 0.625ms */
164 uint8_t initiator_filter_policy;
165 uint8_t peer_address_type;
166 bdaddr_t peer_address; /* remote address */
167 uint8_t own_address_type;
168 uint16_t con_interval_min; /* min interval * 1.25ms */
169 uint16_t con_interval_max; /* max_interval * 1.25ms */
170 uint16_t con_latency; /* 0x0 - 0x1f4 */
171 uint16_t supervision_timo; /* timeout * 10ms */
172 uint16_t min_ce_length; /* min length * 0.625ms */
173 uint16_t max_ce_length; /* max length * 0.625ms */
174 } __packed hci_create_con_le_cp;
175 /* No return parameter(s) */
176
177 #define HCI_OCF_CREATE_CON_LE_CANCEL 0x000e
178 #define HCI_CMD_CREATE_CON_LE_CANCEL 0x200E
179 /* No command parameter(s) */
180
181 typedef hci_status_rp hci_create_con_le_cancel_rp;
182
183 #define HCI_OCF_LE_READ_WHITE_LIST_SIZE 0x000f
184 #define HCI_CMD_LE_READ_WHITE_LIST_SIZE 0x200F
185 /* No command parameter(s) */
186
187 typedef struct {
188 uint8_t status; /* status 0x00 = success */
189 uint8_t white_list_size; /* 0x1 - 0xff */
190 /* 0x0 reserved */
191 } __packed hci_le_read_white_list_size_rp;
192
193 #define HCI_OCF_LE_CLEAR_WHITE_LIST 0x0010
194 #define HCI_CMD_LE_CLEAR_WHITE_LIST 0x2010
195 /* No command parameter(s) */
196
197 typedef hci_status_rp hci_le_clear_white_list_rp;
198
199 #define HCI_OCF_LE_ADD_DEV_TO_WHITE_LIST 0x0011
200 #define HCI_CMD_LE_ADD_DEV_TO_WHITE_LIST 0x2011
201 typedef struct {
202 uint8_t address_type;
203 bdaddr_t address; /* remote address */
204 } __packed hci_le_add_dev_to_white_list_cp;
205
206 typedef hci_status_rp hci_le_add_dev_to_white_list_rp;
207
208 #define HCI_OCF_LE_REMOVE_DEV_FROM_WHITE_LIST 0x0012
209 #define HCI_CMD_LE_REMOVE_DEV_FROM_WHITE_LIST 0x2012
210 typedef struct {
211 uint8_t address_type;
212 bdaddr_t address; /* remote address */
213 } __packed hci_le_remove_dev_from_white_list_cp;
214
215 typedef hci_status_rp hci_le_remove_dev_from_white_list_rp;
216
217 #define HCI_OCF_UPDATE_CON_LE 0x0013
218 #define HCI_CMD_UPDATE_CON_LE 0x2013
219 typedef struct {
220 uint16_t con_handle; /* handle 12 bits */
221 uint16_t con_interval_min; /* min interval * 1.25ms */
222 uint16_t con_interval_max; /* max_interval * 1.25ms */
223 uint16_t con_latency; /* 0x0 - 0x1f4 */
224 uint16_t supervision_timo; /* timeout * 10ms */
225 uint16_t min_ce_length; /* min length * 0.625ms */
226 uint16_t max_ce_length; /* max length * 0.625ms */
227 } __packed hci_update_con_le_cp;
228 /* No return parameter(s) */
229
230 #define HCI_OCF_LE_SET_HOST_CHAN_CLASSIFICATION 0x0014
231 #define HCI_CMD_LE_SET_HOST_CHAN_CLASSIFICATION 0x2014
232 typedef struct {
233 uint8_t map[5];
234 } __packed hci_le_set_host_chan_classification_cp;
235
236 typedef hci_status_rp hci_le_set_host_chan_classification_rp;
237
238 #define HCI_OCF_LE_READ_CHANNEL_MAP 0x0015
239 #define HCI_CMD_LE_READ_CHANNEL_MAP 0x2015
240 typedef struct {
241 uint16_t con_handle; /* connection handle */
242 } __packed hci_le_read_channel_map_cp;
243
244 typedef struct {
245 uint8_t status; /* status 0x00 = success */
246 uint16_t con_handle; /* connection handle */
247 uint8_t map[5]; /* LE channel map */
248 } __packed hci_le_read_channel_map_rp;
249
250 #define HCI_OCF_LE_READ_REMOTE_FEATURES 0x0016
251 #define HCI_CMD_LE_READ_REMOTE_FEATURES 0x2016
252 typedef struct {
253 uint16_t con_handle; /* connection handle */
254 } __packed hci_le_read_remote_features_cp;
255 /* No return parameter(s) */
256
257 #define HCI_OCF_LE_ENCRYPT 0x0017
258 #define HCI_CMD_LE_ENCRYPT 0x2017
259 typedef struct {
260 uint8_t key[16];
261 uint8_t plaintext_data[16];
262 } __packed hci_le_encrypt_cp;
263
264 typedef struct {
265 uint8_t status; /* status 0x00 = success */
266 uint16_t enc_data[16];
267 } __packed hci_le_encrypt_rp;
268
269 #define HCI_OCF_LE_RAND 0x0018
270 #define HCI_CMD_LE_RAND 0x2018
271 /* No command parameter(s) */
272
273 typedef struct {
274 uint8_t status; /* status 0x00 = success */
275 uint8_t rand_num[8];
276 } __packed hci_le_rand_rp;
277
278 #define HCI_OCF_LE_START_ENCRYPT 0x0019
279 #define HCI_CMD_LE_START_ENCRYPT 0x2019
280 typedef struct {
281 uint16_t con_handle; /* connection handle */
282 uint8_t rand_num[8];
283 uint16_t enc_diversifier;
284 uint8_t key[HCI_KEY_SIZE]; /* key */
285 } __packed hci_le_start_encrypt_cp;
286 /* No return parameter(s) */
287
288 #define HCI_OCF_LE_LONG_TERM_KEY_REQ_REP 0x001a
289 #define HCI_CMD_LE_LONG_TERM_KEY_REQ_REP 0x201A
290 typedef struct {
291 uint16_t con_handle; /* connection handle */
292 uint8_t key[HCI_KEY_SIZE]; /* key */
293 } __packed hci_le_long_term_key_req_rep_cp;
294
295 typedef struct {
296 uint8_t status; /* status 0x00 = success */
297 uint16_t con_handle; /* connection handle */
298 } __packed hci_le_long_term_key_req_rep_rp;
299
300 #define HCI_OCF_LE_LONG_TERM_KEY_REQ_REP_NEG 0x001b
301 #define HCI_CMD_LE_LONG_TERM_KEY_REQ_REP_NEG 0x201B
302 typedef struct {
303 uint16_t con_handle; /* connection handle */
304 } __packed hci_le_long_term_key_req_rep_neg_cp;
305
306 typedef struct {
307 uint8_t status; /* status 0x00 = success */
308 uint16_t con_handle; /* connection handle */
309 } __packed hci_le_long_term_key_req_rep_neg_rp;
310
311 /* XXX NS Read supported states */
312
313 #define HCI_OCF_LE_RECEIVER_TEST 0x001d
314 #define HCI_CMD_LE_RECEIVER_TEST 0x201D
315 typedef struct {
316 uint8_t rx_freq; /* 0x00 - 0x27 (2402 - 2480MHz) */
317 } __packed hci_le_receiver_test_cp;
318
319 typedef struct {
320 uint8_t status; /* status 0x00 = success */
321 } __packed hci_le_receiver_test_rp;
322
323 #define HCI_OCF_LE_TRANSMITTER_TEST 0x001e
324 #define HCI_CMD_LE_TRANSMITTER_TEST 0x201E
325 typedef struct {
326 uint8_t tx_freq; /* 0x00 - 0x27 (2402 - 2480MHz) */
327 uint8_t test_len; /* 0x00 - 0x25 bytes */
328 /* 0x26 - 0xff reserved */
329 uint8_t payload; /* 0x00 - 0x02 mandatory */
330 /* 0x03 - 0x07 opt. test patterns */
331 /* 0x08 - 0xff reserved */
332 } __packed hci_le_transmitter_test_cp;
333
334 typedef struct {
335 uint8_t status; /* status 0x00 = success */
336 } __packed hci_le_transmitter_test_rp;
337
338 #define HCI_OCF_LE_TEST_END 0x001f
339 #define HCI_CMD_LE_TEST_END 0x201F
340 /* No command parameter(s) */
341
342 typedef struct {
343 uint8_t status; /* status 0x00 = success */
344 uint16_t num_pkts; /* num pkts received */
345 /* 0x0000 for tx test */
346 } __packed hci_le_test_end_rp;
347
348 /**************************************************************************
349 **************************************************************************
350 ** Events and event parameters
351 **************************************************************************
352 **************************************************************************/
353
354 #define HCI_LE_META_EVENT 0x3e
355 #define HCI_SUBEVT_CON_COMP 0x01
356 typedef struct {
357 uint8_t subevt_code;
358 uint8_t status; /* status 0x00 = success */
359 uint16_t con_handle; /* handle 12 bits */
360 uint8_t role;
361 uint8_t peer_address_type;
362 bdaddr_t peer_address; /* remote address */
363 uint8_t own_address_type;
364 uint16_t con_interval; /* min interval * 1.25ms */
365 uint16_t con_latency; /* 0x0 - 0x1f4 */
366 uint8_t master_clk_accuracy;
367 } __packed hci_le_con_comp_ep;
368
369