CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
orangepi-xunlong

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: orangepi-xunlong/orangepi-build
Path: blob/next/external/cache/sources/hcitools/lib/mgmt.h
Views: 3959
1
/*
2
* BlueZ - Bluetooth protocol stack for Linux
3
*
4
* Copyright (C) 2010 Nokia Corporation
5
* Copyright (C) 2010 Marcel Holtmann <[email protected]>
6
*
7
*
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
12
*
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
17
*
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
*
22
*/
23
24
#ifndef __packed
25
#define __packed __attribute__((packed))
26
#endif
27
28
#define MGMT_INDEX_NONE 0xFFFF
29
30
#define MGMT_STATUS_SUCCESS 0x00
31
#define MGMT_STATUS_UNKNOWN_COMMAND 0x01
32
#define MGMT_STATUS_NOT_CONNECTED 0x02
33
#define MGMT_STATUS_FAILED 0x03
34
#define MGMT_STATUS_CONNECT_FAILED 0x04
35
#define MGMT_STATUS_AUTH_FAILED 0x05
36
#define MGMT_STATUS_NOT_PAIRED 0x06
37
#define MGMT_STATUS_NO_RESOURCES 0x07
38
#define MGMT_STATUS_TIMEOUT 0x08
39
#define MGMT_STATUS_ALREADY_CONNECTED 0x09
40
#define MGMT_STATUS_BUSY 0x0a
41
#define MGMT_STATUS_REJECTED 0x0b
42
#define MGMT_STATUS_NOT_SUPPORTED 0x0c
43
#define MGMT_STATUS_INVALID_PARAMS 0x0d
44
#define MGMT_STATUS_DISCONNECTED 0x0e
45
#define MGMT_STATUS_NOT_POWERED 0x0f
46
#define MGMT_STATUS_CANCELLED 0x10
47
#define MGMT_STATUS_INVALID_INDEX 0x11
48
#define MGMT_STATUS_RFKILLED 0x12
49
50
struct mgmt_hdr {
51
uint16_t opcode;
52
uint16_t index;
53
uint16_t len;
54
} __packed;
55
#define MGMT_HDR_SIZE 6
56
57
struct mgmt_addr_info {
58
bdaddr_t bdaddr;
59
uint8_t type;
60
} __packed;
61
62
#define MGMT_OP_READ_VERSION 0x0001
63
struct mgmt_rp_read_version {
64
uint8_t version;
65
uint16_t revision;
66
} __packed;
67
68
#define MGMT_OP_READ_COMMANDS 0x0002
69
struct mgmt_rp_read_commands {
70
uint16_t num_commands;
71
uint16_t num_events;
72
uint16_t opcodes[0];
73
} __packed;
74
75
#define MGMT_OP_READ_INDEX_LIST 0x0003
76
struct mgmt_rp_read_index_list {
77
uint16_t num_controllers;
78
uint16_t index[0];
79
} __packed;
80
81
/* Reserve one extra byte for names in management messages so that they
82
* are always guaranteed to be nul-terminated */
83
#define MGMT_MAX_NAME_LENGTH (248 + 1)
84
#define MGMT_MAX_SHORT_NAME_LENGTH (10 + 1)
85
86
#define MGMT_SETTING_POWERED 0x00000001
87
#define MGMT_SETTING_CONNECTABLE 0x00000002
88
#define MGMT_SETTING_FAST_CONNECTABLE 0x00000004
89
#define MGMT_SETTING_DISCOVERABLE 0x00000008
90
#define MGMT_SETTING_PAIRABLE 0x00000010
91
#define MGMT_SETTING_LINK_SECURITY 0x00000020
92
#define MGMT_SETTING_SSP 0x00000040
93
#define MGMT_SETTING_BREDR 0x00000080
94
#define MGMT_SETTING_HS 0x00000100
95
#define MGMT_SETTING_LE 0x00000200
96
#define MGMT_SETTING_ADVERTISING 0x00000400
97
98
#define MGMT_OP_READ_INFO 0x0004
99
struct mgmt_rp_read_info {
100
bdaddr_t bdaddr;
101
uint8_t version;
102
uint16_t manufacturer;
103
uint32_t supported_settings;
104
uint32_t current_settings;
105
uint8_t dev_class[3];
106
uint8_t name[MGMT_MAX_NAME_LENGTH];
107
uint8_t short_name[MGMT_MAX_SHORT_NAME_LENGTH];
108
} __packed;
109
110
struct mgmt_mode {
111
uint8_t val;
112
} __packed;
113
114
struct mgmt_cod {
115
uint8_t val[3];
116
} __packed;
117
118
#define MGMT_OP_SET_POWERED 0x0005
119
120
#define MGMT_OP_SET_DISCOVERABLE 0x0006
121
struct mgmt_cp_set_discoverable {
122
uint8_t val;
123
uint16_t timeout;
124
} __packed;
125
126
#define MGMT_OP_SET_CONNECTABLE 0x0007
127
128
#define MGMT_OP_SET_FAST_CONNECTABLE 0x0008
129
130
#define MGMT_OP_SET_PAIRABLE 0x0009
131
132
#define MGMT_OP_SET_LINK_SECURITY 0x000A
133
134
#define MGMT_OP_SET_SSP 0x000B
135
136
#define MGMT_OP_SET_HS 0x000C
137
138
#define MGMT_OP_SET_LE 0x000D
139
140
#define MGMT_OP_SET_DEV_CLASS 0x000E
141
struct mgmt_cp_set_dev_class {
142
uint8_t major;
143
uint8_t minor;
144
} __packed;
145
146
#define MGMT_OP_SET_LOCAL_NAME 0x000F
147
struct mgmt_cp_set_local_name {
148
uint8_t name[MGMT_MAX_NAME_LENGTH];
149
uint8_t short_name[MGMT_MAX_SHORT_NAME_LENGTH];
150
} __packed;
151
152
#define MGMT_OP_ADD_UUID 0x0010
153
struct mgmt_cp_add_uuid {
154
uint8_t uuid[16];
155
uint8_t svc_hint;
156
} __packed;
157
158
#define MGMT_OP_REMOVE_UUID 0x0011
159
struct mgmt_cp_remove_uuid {
160
uint8_t uuid[16];
161
} __packed;
162
163
struct mgmt_link_key_info {
164
struct mgmt_addr_info addr;
165
uint8_t type;
166
uint8_t val[16];
167
uint8_t pin_len;
168
} __packed;
169
170
#define MGMT_OP_LOAD_LINK_KEYS 0x0012
171
struct mgmt_cp_load_link_keys {
172
uint8_t debug_keys;
173
uint16_t key_count;
174
struct mgmt_link_key_info keys[0];
175
} __packed;
176
177
struct mgmt_ltk_info {
178
struct mgmt_addr_info addr;
179
uint8_t authenticated;
180
uint8_t master;
181
uint8_t enc_size;
182
uint16_t ediv;
183
uint8_t rand[8];
184
uint8_t val[16];
185
} __packed;
186
187
#define MGMT_OP_LOAD_LONG_TERM_KEYS 0x0013
188
struct mgmt_cp_load_long_term_keys {
189
uint16_t key_count;
190
struct mgmt_ltk_info keys[0];
191
} __packed;
192
193
#define MGMT_OP_DISCONNECT 0x0014
194
struct mgmt_cp_disconnect {
195
struct mgmt_addr_info addr;
196
} __packed;
197
struct mgmt_rp_disconnect {
198
struct mgmt_addr_info addr;
199
} __packed;
200
201
#define MGMT_OP_GET_CONNECTIONS 0x0015
202
struct mgmt_rp_get_connections {
203
uint16_t conn_count;
204
struct mgmt_addr_info addr[0];
205
} __packed;
206
207
#define MGMT_OP_PIN_CODE_REPLY 0x0016
208
struct mgmt_cp_pin_code_reply {
209
struct mgmt_addr_info addr;
210
uint8_t pin_len;
211
uint8_t pin_code[16];
212
} __packed;
213
214
#define MGMT_OP_PIN_CODE_NEG_REPLY 0x0017
215
struct mgmt_cp_pin_code_neg_reply {
216
struct mgmt_addr_info addr;
217
} __packed;
218
219
#define MGMT_OP_SET_IO_CAPABILITY 0x0018
220
struct mgmt_cp_set_io_capability {
221
uint8_t io_capability;
222
} __packed;
223
224
#define MGMT_OP_PAIR_DEVICE 0x0019
225
struct mgmt_cp_pair_device {
226
struct mgmt_addr_info addr;
227
uint8_t io_cap;
228
} __packed;
229
struct mgmt_rp_pair_device {
230
struct mgmt_addr_info addr;
231
} __packed;
232
233
#define MGMT_OP_CANCEL_PAIR_DEVICE 0x001A
234
235
#define MGMT_OP_UNPAIR_DEVICE 0x001B
236
struct mgmt_cp_unpair_device {
237
struct mgmt_addr_info addr;
238
uint8_t disconnect;
239
} __packed;
240
struct mgmt_rp_unpair_device {
241
struct mgmt_addr_info addr;
242
} __packed;
243
244
#define MGMT_OP_USER_CONFIRM_REPLY 0x001C
245
struct mgmt_cp_user_confirm_reply {
246
struct mgmt_addr_info addr;
247
} __packed;
248
struct mgmt_rp_user_confirm_reply {
249
struct mgmt_addr_info addr;
250
} __packed;
251
252
#define MGMT_OP_USER_CONFIRM_NEG_REPLY 0x001D
253
254
#define MGMT_OP_USER_PASSKEY_REPLY 0x001E
255
struct mgmt_cp_user_passkey_reply {
256
struct mgmt_addr_info addr;
257
uint32_t passkey;
258
} __packed;
259
struct mgmt_rp_user_passkey_reply {
260
struct mgmt_addr_info addr;
261
} __packed;
262
263
#define MGMT_OP_USER_PASSKEY_NEG_REPLY 0x001F
264
struct mgmt_cp_user_passkey_neg_reply {
265
struct mgmt_addr_info addr;
266
} __packed;
267
268
#define MGMT_OP_READ_LOCAL_OOB_DATA 0x0020
269
struct mgmt_rp_read_local_oob_data {
270
uint8_t hash[16];
271
uint8_t randomizer[16];
272
} __packed;
273
274
#define MGMT_OP_ADD_REMOTE_OOB_DATA 0x0021
275
struct mgmt_cp_add_remote_oob_data {
276
struct mgmt_addr_info addr;
277
uint8_t hash[16];
278
uint8_t randomizer[16];
279
} __packed;
280
281
#define MGMT_OP_REMOVE_REMOTE_OOB_DATA 0x0022
282
struct mgmt_cp_remove_remote_oob_data {
283
struct mgmt_addr_info addr;
284
} __packed;
285
286
#define MGMT_OP_START_DISCOVERY 0x0023
287
struct mgmt_cp_start_discovery {
288
uint8_t type;
289
} __packed;
290
291
#define MGMT_OP_STOP_DISCOVERY 0x0024
292
struct mgmt_cp_stop_discovery {
293
uint8_t type;
294
} __packed;
295
296
#define MGMT_OP_CONFIRM_NAME 0x0025
297
struct mgmt_cp_confirm_name {
298
struct mgmt_addr_info addr;
299
uint8_t name_known;
300
} __packed;
301
struct mgmt_rp_confirm_name {
302
struct mgmt_addr_info addr;
303
} __packed;
304
305
#define MGMT_OP_BLOCK_DEVICE 0x0026
306
struct mgmt_cp_block_device {
307
struct mgmt_addr_info addr;
308
} __packed;
309
310
#define MGMT_OP_UNBLOCK_DEVICE 0x0027
311
struct mgmt_cp_unblock_device {
312
struct mgmt_addr_info addr;
313
} __packed;
314
315
#define MGMT_OP_SET_DEVICE_ID 0x0028
316
struct mgmt_cp_set_device_id {
317
uint16_t source;
318
uint16_t vendor;
319
uint16_t product;
320
uint16_t version;
321
} __packed;
322
323
#define MGMT_OP_SET_ADVERTISING 0x0029
324
325
#define MGMT_OP_SET_BREDR 0x002A
326
327
#define MGMT_OP_SET_STATIC_ADDRESS 0x002B
328
struct mgmt_cp_set_static_address {
329
bdaddr_t bdaddr;
330
} __packed;
331
332
#define MGMT_OP_SET_SCAN_PARAMS 0x002C
333
struct mgmt_cp_set_scan_params {
334
uint16_t interval;
335
uint16_t window;
336
} __packed;
337
338
#define MGMT_EV_CMD_COMPLETE 0x0001
339
struct mgmt_ev_cmd_complete {
340
uint16_t opcode;
341
uint8_t status;
342
uint8_t data[0];
343
} __packed;
344
345
#define MGMT_EV_CMD_STATUS 0x0002
346
struct mgmt_ev_cmd_status {
347
uint16_t opcode;
348
uint8_t status;
349
} __packed;
350
351
#define MGMT_EV_CONTROLLER_ERROR 0x0003
352
struct mgmt_ev_controller_error {
353
uint8_t error_code;
354
} __packed;
355
356
#define MGMT_EV_INDEX_ADDED 0x0004
357
358
#define MGMT_EV_INDEX_REMOVED 0x0005
359
360
#define MGMT_EV_NEW_SETTINGS 0x0006
361
362
#define MGMT_EV_CLASS_OF_DEV_CHANGED 0x0007
363
struct mgmt_ev_class_of_dev_changed {
364
uint8_t class_of_dev[3];
365
} __packed;
366
367
#define MGMT_EV_LOCAL_NAME_CHANGED 0x0008
368
struct mgmt_ev_local_name_changed {
369
uint8_t name[MGMT_MAX_NAME_LENGTH];
370
uint8_t short_name[MGMT_MAX_SHORT_NAME_LENGTH];
371
} __packed;
372
373
#define MGMT_EV_NEW_LINK_KEY 0x0009
374
struct mgmt_ev_new_link_key {
375
uint8_t store_hint;
376
struct mgmt_link_key_info key;
377
} __packed;
378
379
#define MGMT_EV_NEW_LONG_TERM_KEY 0x000A
380
struct mgmt_ev_new_long_term_key {
381
uint8_t store_hint;
382
struct mgmt_ltk_info key;
383
} __packed;
384
385
#define MGMT_EV_DEVICE_CONNECTED 0x000B
386
struct mgmt_ev_device_connected {
387
struct mgmt_addr_info addr;
388
uint32_t flags;
389
uint16_t eir_len;
390
uint8_t eir[0];
391
} __packed;
392
393
#define MGMT_DEV_DISCONN_UNKNOWN 0x00
394
#define MGMT_DEV_DISCONN_TIMEOUT 0x01
395
#define MGMT_DEV_DISCONN_LOCAL_HOST 0x02
396
#define MGMT_DEV_DISCONN_REMOTE 0x03
397
398
#define MGMT_EV_DEVICE_DISCONNECTED 0x000C
399
struct mgmt_ev_device_disconnected {
400
struct mgmt_addr_info addr;
401
uint8_t reason;
402
} __packed;
403
404
#define MGMT_EV_CONNECT_FAILED 0x000D
405
struct mgmt_ev_connect_failed {
406
struct mgmt_addr_info addr;
407
uint8_t status;
408
} __packed;
409
410
#define MGMT_EV_PIN_CODE_REQUEST 0x000E
411
struct mgmt_ev_pin_code_request {
412
struct mgmt_addr_info addr;
413
uint8_t secure;
414
} __packed;
415
416
#define MGMT_EV_USER_CONFIRM_REQUEST 0x000F
417
struct mgmt_ev_user_confirm_request {
418
struct mgmt_addr_info addr;
419
uint8_t confirm_hint;
420
uint32_t value;
421
} __packed;
422
423
#define MGMT_EV_USER_PASSKEY_REQUEST 0x0010
424
struct mgmt_ev_user_passkey_request {
425
struct mgmt_addr_info addr;
426
} __packed;
427
428
#define MGMT_EV_AUTH_FAILED 0x0011
429
struct mgmt_ev_auth_failed {
430
struct mgmt_addr_info addr;
431
uint8_t status;
432
} __packed;
433
434
#define MGMT_DEV_FOUND_CONFIRM_NAME 0x01
435
#define MGMT_DEV_FOUND_LEGACY_PAIRING 0x02
436
437
#define MGMT_EV_DEVICE_FOUND 0x0012
438
struct mgmt_ev_device_found {
439
struct mgmt_addr_info addr;
440
int8_t rssi;
441
uint32_t flags;
442
uint16_t eir_len;
443
uint8_t eir[0];
444
} __packed;
445
446
#define MGMT_EV_DISCOVERING 0x0013
447
struct mgmt_ev_discovering {
448
uint8_t type;
449
uint8_t discovering;
450
} __packed;
451
452
#define MGMT_EV_DEVICE_BLOCKED 0x0014
453
struct mgmt_ev_device_blocked {
454
struct mgmt_addr_info addr;
455
} __packed;
456
457
#define MGMT_EV_DEVICE_UNBLOCKED 0x0015
458
struct mgmt_ev_device_unblocked {
459
struct mgmt_addr_info addr;
460
} __packed;
461
462
#define MGMT_EV_DEVICE_UNPAIRED 0x0016
463
struct mgmt_ev_device_unpaired {
464
struct mgmt_addr_info addr;
465
} __packed;
466
467
#define MGMT_EV_PASSKEY_NOTIFY 0x0017
468
struct mgmt_ev_passkey_notify {
469
struct mgmt_addr_info addr;
470
uint32_t passkey;
471
uint8_t entered;
472
} __packed;
473
474
static const char *mgmt_op[] = {
475
"<0x0000>",
476
"Read Version",
477
"Read Commands",
478
"Read Index List",
479
"Read Controller Info",
480
"Set Powered",
481
"Set Discoverable",
482
"Set Connectable",
483
"Set Fast Connectable", /* 0x0008 */
484
"Set Pairable",
485
"Set Link Security",
486
"Set Secure Simple Pairing",
487
"Set High Speed",
488
"Set Low Energy",
489
"Set Dev Class",
490
"Set Local Name",
491
"Add UUID", /* 0x0010 */
492
"Remove UUID",
493
"Load Link Keys",
494
"Load Long Term Keys",
495
"Disconnect",
496
"Get Connections",
497
"PIN Code Reply",
498
"PIN Code Neg Reply",
499
"Set IO Capability", /* 0x0018 */
500
"Pair Device",
501
"Cancel Pair Device",
502
"Unpair Device",
503
"User Confirm Reply",
504
"User Confirm Neg Reply",
505
"User Passkey Reply",
506
"User Passkey Neg Reply",
507
"Read Local OOB Data", /* 0x0020 */
508
"Add Remote OOB Data",
509
"Remove Remove OOB Data",
510
"Start Discovery",
511
"Stop Discovery",
512
"Confirm Name",
513
"Block Device",
514
"Unblock Device",
515
"Set Device ID",
516
"Set Advertising",
517
"Set BR/EDR",
518
"Set Static Address",
519
"Set Scan Parameters",
520
};
521
522
static const char *mgmt_ev[] = {
523
"<0x0000>",
524
"Command Complete",
525
"Command Status",
526
"Controller Error",
527
"Index Added",
528
"Index Removed",
529
"New Settings",
530
"Class of Device Changed",
531
"Local Name Changed", /* 0x0008 */
532
"New Link Key",
533
"New Long Term Key",
534
"Device Connected",
535
"Device Disconnected",
536
"Connect Failed",
537
"PIN Code Request",
538
"User Confirm Request",
539
"User Passkey Request", /* 0x0010 */
540
"Authentication Failed",
541
"Device Found",
542
"Discovering",
543
"Device Blocked",
544
"Device Unblocked",
545
"Device Unpaired",
546
"Passkey Notify",
547
};
548
549
static const char *mgmt_status[] = {
550
"Success",
551
"Unknown Command",
552
"Not Connected",
553
"Failed",
554
"Connect Failed",
555
"Authentication Failed",
556
"Not Paired",
557
"No Resources",
558
"Timeout",
559
"Already Connected",
560
"Busy",
561
"Rejected",
562
"Not Supported",
563
"Invalid Parameters",
564
"Disconnected",
565
"Not Powered",
566
"Cancelled",
567
"Invalid Index",
568
"Blocked through rfkill",
569
};
570
571
#ifndef NELEM
572
#define NELEM(x) (sizeof(x) / sizeof((x)[0]))
573
#endif
574
575
static inline const char *mgmt_opstr(uint16_t op)
576
{
577
if (op >= NELEM(mgmt_op))
578
return "<unknown opcode>";
579
return mgmt_op[op];
580
}
581
582
static inline const char *mgmt_evstr(uint16_t ev)
583
{
584
if (ev >= NELEM(mgmt_ev))
585
return "<unknown event>";
586
return mgmt_ev[ev];
587
}
588
589
static inline const char *mgmt_errstr(uint8_t status)
590
{
591
if (status >= NELEM(mgmt_status))
592
return "<unknown status>";
593
return mgmt_status[status];
594
}
595
596