Boot Linux faster!

Check our new training course

Boot Linux faster!

Check our new training course
and Creative Commons CC-BY-SA
lecture and lab materials

Bootlin logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
/** @file
 *  @brief Internal API for Generic Access Profile.
 */

/*
 * Copyright (c) 2016 Intel Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* Maximum security key len (LTK, CSRK) */
#define BLE_GAP_SEC_MAX_KEY_LEN		16

#define BT_SMP_AUTH_NONE			0x00
#define BT_SMP_AUTH_BONDING			0x01
#define BT_SMP_AUTH_MITM			0x04
#define BT_SMP_AUTH_SC				0x08

enum NBLE_GAP_SM_PASSKEY_TYPE {
	NBLE_GAP_SM_REJECT = 0,
	NBLE_GAP_SM_PK_PASSKEY,
	NBLE_GAP_SM_PK_OOB,
};

enum NBLE_GAP_SM_EVT {
	NBLE_GAP_SM_EVT_START_PAIRING,
	NBLE_GAP_SM_EVT_BONDING_COMPLETE,
	NBLE_GAP_SM_EVT_LINK_ENCRYPTED,
	NBLE_GAP_SM_EVT_LINK_SECURITY_CHANGE,
};

struct nble_response {
	int status;
	void *user_data;
};

struct nble_gap_device_name {
	/* Security mode for writing device name */
	uint8_t sec_mode;
	/* 0: no authorization, 1: authorization required */
	uint8_t authorization;
	/* Device name length (0-248) */
	uint8_t len;
	uint8_t name_array[20];
};

struct nble_gap_connection_values {
	/* Connection interval (unit 1.25 ms) */
	uint16_t interval;
	/* Connection latency (unit interval) */
	uint16_t latency;
	/* Connection supervision timeout (unit 10ms)*/
	uint16_t supervision_to;
};

struct nble_gap_connection_params {
	/* minimal connection interval: range 0x0006 to 0x0c80 (unit 1.25ms) */
	uint16_t interval_min;
	/* maximum connection interval: range 0x0006 to 0x0c80 must be bigger then min! */
	uint16_t interval_max;
	/* maximum connection slave latency: 0x0000 to 0x01f3 */
	uint16_t slave_latency;
	/* link supervision timeout: 0x000a to 0x0c80 (unit 10ms) */
	uint16_t link_sup_to;
};

struct nble_gap_scan_parameters {
	/* If 1, perform active scanning (scan requests). */
	uint8_t active;
	/* If 1, ignore unknown devices (non whitelisted). */
	uint8_t selective;
	/* Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
	uint16_t interval;
	/* Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
	uint16_t window;
	/* Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */
	uint16_t timeout;
};

struct nble_gap_service_write_params {
	/* GAP Characteristics attribute type  @ref BLE_GAP_SVC_ATTR_TYPE */
	uint16_t attr_type;
	union {
		struct nble_gap_device_name name;
		/* Appearance UUID */
		uint16_t appearance;
		/* Preferred Peripheral Connection Parameters */
		struct nble_gap_connection_params conn_params;
		/* Central Address Resolution support 0: no, 1: yes */
		uint8_t car;
	};
};

struct nble_service_read_bda_response {
	int status;
	/* If @ref status ok */
	bt_addr_le_t bd;
	void *user_data;
};

struct nble_service_write_response {
	int status;
	/* GAP Characteristics attribute type  @ref BLE_GAP_SVC_ATTR_TYPE */
	uint16_t attr_type;
	void *user_data;
};

struct nble_debug_params {
	uint32_t u0;
	uint32_t u1;
};

struct nble_debug_resp {
	int status;
	uint32_t u0;
	uint32_t u1;
	void *user_data;
};

typedef void (*nble_set_bda_cb_t)(int status, void *user_data);

struct nble_set_bda_params {
	bt_addr_le_t bda;
	nble_set_bda_cb_t cb;
	void *user_data;
};

struct nble_set_bda_rsp {
	nble_set_bda_cb_t cb;
	void *user_data;
	int status;
};

struct bt_eir_data {
	uint8_t len;
	uint8_t data[31];
};

struct nble_gap_adv_params {
	uint16_t timeout;
	/* min interval 0xffff: use default 0x0800 */
	uint16_t interval_min;
	/* max interval 0xffff: use default 0x0800 */
	uint16_t interval_max;
	/* advertisement types @ref GAP_ADV_TYPES */
	uint8_t type;
	/* filter policy to apply with white list */
	uint8_t filter_policy;
	/* bd address of peer device in case of directed advertisement */
	bt_addr_le_t peer_bda;
};

struct nble_gap_ad_data_params {
	/* Advertisement data, maybe 0 (length) */
	struct bt_eir_data ad;
	/* Scan response data, maybe 0 (length) */
	struct bt_eir_data sd;
};

struct nble_log_s {
	uint8_t param0;
	uint8_t param1;
	uint8_t param2;
	uint8_t param3;
};

void nble_log(const struct nble_log_s *param, char *buf, uint8_t buflen);

void on_nble_up(void);

void nble_gap_service_write_req(const struct nble_gap_service_write_params *);

void on_nble_gap_read_bda_rsp(const struct nble_service_read_bda_response *par);

void nble_gap_dbg_req(const struct nble_debug_params *par, void *user_data);

void on_nble_gap_dbg_rsp(const struct nble_debug_resp *rsp);

void on_nble_set_bda_rsp(const struct nble_set_bda_rsp *par);

void nble_set_bda_req(const struct nble_set_bda_params *par);

void nble_gap_set_adv_data_req(struct nble_gap_ad_data_params *ad_data_params);

void nble_gap_set_adv_params_req(struct nble_gap_adv_params *adv_params);

void nble_gap_start_adv_req(void);

void on_nble_gap_start_advertise_rsp(const struct nble_response *params);

void nble_gap_stop_adv_req(void *user_data);

void nble_gap_read_bda_req(void *priv);

struct nble_gap_irk_info {
	uint8_t irk[BLE_GAP_SEC_MAX_KEY_LEN];
};

struct nble_gap_connect_update_params {
	uint16_t conn_handle;
	struct nble_gap_connection_params params;
};

void nble_gap_conn_update_req(const struct nble_gap_connect_update_params *par);

struct nble_gap_connect_req_params {
	bt_addr_le_t bda;
	struct nble_gap_connection_params conn_params;
	struct nble_gap_scan_parameters scan_params;
};

struct nble_gap_disconnect_req_params {
	uint16_t conn_handle;
	uint8_t reason;
};

void nble_gap_disconnect_req(const struct nble_gap_disconnect_req_params *);

struct nble_gap_sm_config_params {
	/* Security options (@ref BLE_GAP_SM_OPTIONS) */
	uint8_t options;
	/* I/O Capabilities to allow passkey exchange (@ref BLE_GAP_IO_CAPABILITIES) */
	uint8_t io_caps;
	/* Maximum encryption key size (7-16) */
	uint8_t key_size;
	uint8_t oob_present;
};

void nble_gap_sm_config_req(const struct nble_gap_sm_config_params *par);

struct nble_gap_sm_config_rsp {
	void *user_data;
	int status;
	bool sm_bond_dev_avail;
};

struct nble_gap_sm_pairing_params {
	/* authentication level see @ref BLE_GAP_SM_OPTIONS */
	uint8_t auth_level;
};

struct nble_gap_sm_security_params {
	struct bt_conn *conn;
	uint16_t conn_handle;
	/* Local authentication/bonding parameters */
	struct nble_gap_sm_pairing_params params;
};

void nble_gap_sm_security_req(const struct nble_gap_sm_security_params *par);

struct nble_gap_sm_passkey {
	uint8_t type;
	union {
		uint32_t passkey;
		uint8_t oob[16];
		uint8_t reason;
	};
};

struct nble_gap_sm_key_reply_req_params {
	struct bt_conn *conn;
	uint16_t conn_handle;
	struct nble_gap_sm_passkey params;
};

void nble_gap_sm_passkey_reply_req(const struct nble_gap_sm_key_reply_req_params *par);

struct nble_gap_sm_clear_bond_req_params {
	bt_addr_le_t addr;
};

void nble_gap_sm_clear_bonds_req(const struct nble_gap_sm_clear_bond_req_params *par);

struct nble_gap_sm_response {
	int status;
	struct bt_conn *conn;
};

struct nble_rssi_report_params {
	uint16_t conn_handle;
	/* RSSI operation @ref BLE_GAP_RSSI_OPS */
	uint8_t op;
	/* Channel for RSSI enabling */
	uint8_t channel;
	/* minimum RSSI dBm change to report a new RSSI value */
	uint8_t delta_dBm;
	/* number of delta_dBm changes before sending a new RSSI report */
	uint8_t min_count;
};

void nble_gap_set_rssi_report_req(const struct nble_rssi_report_params *par,
				  void *user_data);

void on_nble_gap_set_rssi_report_rsp(const struct nble_response *par);

struct nble_gap_scan_params {
	uint16_t interval;
	uint16_t window;
	uint8_t scan_type;
	uint8_t use_whitelist;
};

void nble_gap_start_scan_req(const struct nble_gap_scan_params *par);

void nble_gap_stop_scan_req(void);

void on_nble_gap_scan_start_stop_rsp(const struct nble_response *par);

void nble_gap_connect_req(const struct nble_gap_connect_req_params *req,
			  void *user_data);

void on_nble_gap_connect_rsp(const struct nble_response *rsp);

void nble_gap_cancel_connect_req(void *user_data);

void on_nble_gap_cancel_connect_rsp(const struct nble_response *par);

enum BLE_GAP_SET_OPTIONS {
	BLE_GAP_SET_CH_MAP = 0,
};

struct nble_gap_channel_map {
	/* connection on which to change channel map */
	uint16_t conn_handle;
	/* 37 bits are used of the 40 bits (LSB) */
	uint8_t map[5];
};

struct nble_uas_rssi_calibrate {
	float distance;
};
void nble_uas_rssi_calibrate_req(const struct nble_uas_rssi_calibrate *);

struct nble_uas_bucket_change {
	uint8_t distance;
};
void on_nble_uas_bucket_change(const struct nble_uas_bucket_change *);

struct nble_version {
	uint8_t version;
	uint8_t major;
	uint8_t minor;
	uint8_t patch;
	char version_string[20];
	uint8_t hash[4];
};

typedef void (*ble_get_version_cb_t)(const struct nble_version *ver);

struct nble_gap_get_version_param {
	ble_get_version_cb_t cb;
};

struct nble_version_response {
	struct nble_gap_get_version_param params;
	struct nble_version ver;
};

void nble_get_version_req(const struct nble_gap_get_version_param *params);

void on_nble_get_version_rsp(const struct nble_version_response *params);

void nble_gap_dtm_init_req(void *user_data);

struct nble_gap_tx_power_params {
	int8_t tx_power;
};

void nble_gap_tx_power_req(const struct nble_gap_tx_power_params *params);

struct nble_gap_connect_evt {
	uint16_t conn_handle;
	struct nble_gap_connection_values conn_values;
	/* 0 if connected as master, otherwise as slave */
	uint8_t role_slave;
	/* Address of peer device */
	bt_addr_le_t peer_bda;
};

void on_nble_gap_connect_evt(const struct nble_gap_connect_evt *ev);

struct nble_gap_disconnect_evt {
	uint16_t conn_handle;
	uint8_t hci_reason;
};

void on_nble_gap_disconnect_evt(const struct nble_gap_disconnect_evt *ev);

struct nble_gap_conn_update_evt {
	uint16_t conn_handle;
	struct nble_gap_connection_values conn_values;
};

void on_nble_gap_conn_update_evt(const struct nble_gap_conn_update_evt *ev);

struct nble_gap_adv_report_evt {
	bt_addr_le_t addr;
	int8_t rssi;
	uint8_t adv_type;
};

struct nble_gap_dir_adv_timeout_evt {
	uint16_t conn_handle;
	uint16_t error;
};

void on_nble_gap_dir_adv_timeout_evt(const struct nble_gap_dir_adv_timeout_evt *evt);

#define BLE_GAP_RSSI_EVT_SIZE	32
struct nble_gap_rssi_evt {
	uint16_t conn_handle;
	int8_t rssi_data[BLE_GAP_RSSI_EVT_SIZE];
};

void on_nble_gap_rssi_evt(const struct nble_gap_rssi_evt *ev);

struct nble_gap_sm_passkey_req_evt {
	uint16_t conn_handle;
	uint8_t key_type;
};

void on_nble_gap_sm_passkey_req_evt(const struct nble_gap_sm_passkey_req_evt *);

struct nble_gap_sm_passkey_disp_evt {
	uint16_t conn_handle;
	uint32_t passkey;
};

void on_nble_gap_sm_passkey_display_evt(const struct nble_gap_sm_passkey_disp_evt *evt);

struct nble_link_sec {
	bt_security_t sec_level;
	uint8_t enc_size;
};

struct nble_gap_sm_status_evt {
	uint16_t conn_handle;
	uint8_t evt_type;
	int status;
	struct nble_link_sec enc_link_sec;
};

void on_nble_gap_sm_status_evt(const struct nble_gap_sm_status_evt *ev);

struct nble_gap_sm_bond_info;

typedef void (*ble_bond_info_cb_t)(const struct nble_gap_sm_bond_info *info,
				   const bt_addr_le_t *addr, uint16_t len,
				   void *user_data);

struct nble_gap_sm_bond_info_param {
	ble_bond_info_cb_t cb;
	void *user_data;
	bool include_bonded_addrs;
};

void nble_gap_sm_bond_info_req(const struct nble_gap_sm_bond_info_param *params);

struct nble_gap_sm_bond_info {
	int err;
	uint8_t addr_count;
	uint8_t irk_count;
};

struct nble_gap_sm_bond_info_rsp {
	ble_bond_info_cb_t cb;
	void *user_data;
	struct nble_gap_sm_bond_info info;
};

struct nble {
	/* Local Bluetooth LE Device Address */
	bt_addr_le_t addr;
	const struct bt_conn_auth_cb *auth;
	bool keep_adv;
};

extern struct nble nble;