-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhci_const.h
547 lines (460 loc) · 14.4 KB
/
hci_const.h
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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
/******************************************************************************
*
* File Description
* ---------------------
* This file defines constants and functions for HCI layer.
* See Bluetooth Core v 4.0, Vol. 2, Part E.
*
*******************************************************************************/
#ifndef __HCI_INTERNAL_H_
#define __HCI_INTERNAL_H_
#include "compiler.h"
#include "hal_types.h"
//#include "clock.h"
#include "link_layer.h"
#include <hci.h>
//#define DEFAULT_TIMEOUT (CLOCK_SECOND/10)
/**
* Maximum payload of HCI commands that can be sent. Change this value if needed.
* This value can be up to 255.
*/
#define HCI_MAX_PAYLOAD_SIZE 128
/* HCI Packet types */
#define HCI_COMMAND_PKT 0x01
#define HCI_ACLDATA_PKT 0x02
#define HCI_SCODATA_PKT 0x03
#define HCI_EVENT_PKT 0x04
#define HCI_VENDOR_PKT 0xff
typedef __packed struct _hci_uart_pckt{
uint8_t type;
uint8_t data[0];
} PACKED hci_uart_pckt;
#define HCI_HDR_SIZE 1
typedef __packed struct _hci_command_hdr{
uint16_t opcode; /* OCF & OGF */
uint8_t plen;
} PACKED hci_command_hdr;
#define HCI_COMMAND_HDR_SIZE 3
typedef __packed struct _hci_event_pckt{
uint8_t evt;
uint8_t plen;
uint8_t data[0];
} PACKED hci_event_pckt;
#define HCI_EVENT_HDR_SIZE 2
typedef __packed struct _hci_acl_hdr{
uint16_t handle; /* Handle & Flags(PB, BC) */
uint16_t dlen;
} PACKED hci_acl_hdr;
#define HCI_ACL_HDR_SIZE 4
/* Link Control */
#define OGF_LINK_CTL 0x01
#define OCF_DISCONNECT 0x0006
typedef __packed struct _disconnect_cp{
uint16_t handle;
uint8_t reason;
} PACKED disconnect_cp;
#define DISCONNECT_CP_SIZE 3
/* Host Controller and Baseband */
#define OGF_HOST_CTL 0x03
#define OCF_SET_EVENT_MASK 0x0001
#define OCF_RESET 0x0003
#define OCF_READ_TRANSMIT_POWER_LEVEL 0x002D
typedef __packed struct _read_transmit_power_level_cp{
uint16_t handle;
uint8_t type;
} PACKED read_transmit_power_level_cp;
#define READ_TRANSMIT_POWER_LEVEL_CP_SIZE 3
typedef __packed struct _read_transmit_power_level_rp{
uint8_t status;
uint16_t handle;
int8_t level;
} PACKED read_transmit_power_level_rp;
#define READ_TRANSMIT_POWER_LEVEL_RP_SIZE 4
#define OCF_SET_CONTROLLER_TO_HOST_FC 0x0031
#define OCF_HOST_BUFFER_SIZE 0x0033
#define OCF_HOST_NUM_COMP_PKTS 0x0035
/* Informational Parameters */
#define OGF_INFO_PARAM 0x04
#define OCF_READ_LOCAL_VERSION 0x0001
typedef __packed struct _read_local_version_rp{
uint8_t status;
uint8_t hci_version;
uint16_t hci_revision;
uint8_t lmp_pal_version;
uint16_t manufacturer_name;
uint16_t lmp_pal_subversion;
} PACKED read_local_version_rp;
#define READ_LOCAL_VERSION_RP_SIZE 9
#define OCF_READ_LOCAL_COMMANDS 0x0002
#define OCF_READ_LOCAL_FEATURES 0x0003
#define OCF_READ_BD_ADDR 0x0009
typedef __packed struct _read_bd_addr_rp{
uint8_t status;
tBDAddr bdaddr;
} PACKED read_bd_addr_rp;
#define READ_BD_ADDR_RP_SIZE 7
/* Status params */
#define OGF_STATUS_PARAM 0x05
#define OCF_READ_RSSI 0x0005
typedef __packed struct _read_rssi_cp{
uint16_t handle;
} PACKED read_rssi_cp;
#define READ_RSSI_CP_SIZE 2
typedef __packed struct _read_rssi_rp{
uint8_t status;
uint16_t handle;
int8_t rssi;
} PACKED read_rssi_rp;
#define READ_RSSI_RP_SIZE 4
/* LE commands */
#define OGF_LE_CTL 0x08
#define OCF_LE_SET_EVENT_MASK 0x0001
typedef __packed struct _le_set_event_mask_cp{
uint8_t mask[8];
} PACKED le_set_event_mask_cp;
#define LE_SET_EVENT_MASK_CP_SIZE 8
#define OCF_LE_READ_BUFFER_SIZE 0x0002
typedef __packed struct _le_read_buffer_size_rp{
uint8_t status;
uint16_t pkt_len;
uint8_t max_pkt;
} PACKED le_read_buffer_size_rp;
#define LE_READ_BUFFER_SIZE_RP_SIZE 4
#define OCF_LE_READ_LOCAL_SUPPORTED_FEATURES 0x0003
typedef __packed struct _le_read_local_supported_features_rp{
uint8_t status;
uint8_t features[8];
} PACKED le_read_local_supported_features_rp;
#define LE_READ_LOCAL_SUPPORTED_FEATURES_RP_SIZE 9
#define OCF_LE_SET_RANDOM_ADDRESS 0x0005
typedef __packed struct _le_set_random_address_cp{
tBDAddr bdaddr;
} PACKED le_set_random_address_cp;
#define LE_SET_RANDOM_ADDRESS_CP_SIZE 6
#define OCF_LE_SET_ADV_PARAMETERS 0x0006
typedef __packed struct _le_set_adv_parameters_cp{
uint16_t min_interval;
uint16_t max_interval;
uint8_t advtype;
uint8_t own_bdaddr_type;
uint8_t direct_bdaddr_type;
tBDAddr direct_bdaddr;
uint8_t chan_map;
uint8_t filter;
} PACKED le_set_adv_parameters_cp;
#define LE_SET_ADV_PARAMETERS_CP_SIZE 15
#define OCF_LE_READ_ADV_CHANNEL_TX_POWER 0x0007
typedef __packed struct _le_read_adv_channel_tx_power_rp{
uint8_t status;
int8_t level;
} PACKED le_read_adv_channel_tx_power_rp;
#define LE_READ_ADV_CHANNEL_TX_POWER_RP_SIZE 2
#define OCF_LE_SET_ADV_DATA 0x0008
typedef __packed struct _le_set_adv_data_cp{
uint8_t length;
uint8_t data[31];
} PACKED le_set_adv_data_cp;
#define LE_SET_ADV_DATA_CP_SIZE 32
#define OCF_LE_SET_SCAN_RESPONSE_DATA 0x0009
typedef __packed struct _le_set_scan_response_data_cp{
uint8_t length;
uint8_t data[31];
} PACKED le_set_scan_response_data_cp;
#define LE_SET_SCAN_RESPONSE_DATA_CP_SIZE 32
#define OCF_LE_SET_ADVERTISE_ENABLE 0x000A
typedef __packed struct _le_set_advertise_enable_cp{
uint8_t enable;
} PACKED le_set_advertise_enable_cp;
#define LE_SET_ADVERTISE_ENABLE_CP_SIZE 1
#define OCF_LE_SET_SCAN_PARAMETERS 0x000B
typedef __packed struct _le_set_scan_parameters_cp{
uint8_t type;
uint16_t interval;
uint16_t window;
uint8_t own_bdaddr_type;
uint8_t filter;
} PACKED le_set_scan_parameters_cp;
#define LE_SET_SCAN_PARAMETERS_CP_SIZE 7
#define OCF_LE_SET_SCAN_ENABLE 0x000C
typedef __packed struct _le_set_scan_enable_cp{
uint8_t enable;
uint8_t filter_dup;
} PACKED le_set_scan_enable_cp;
#define LE_SET_SCAN_ENABLE_CP_SIZE 2
#define OCF_LE_CREATE_CONN 0x000D
typedef __packed struct _le_create_connection_cp{
uint16_t interval;
uint16_t window;
uint8_t initiator_filter;
uint8_t peer_bdaddr_type;
tBDAddr peer_bdaddr;
uint8_t own_bdaddr_type;
uint16_t min_interval;
uint16_t max_interval;
uint16_t latency;
uint16_t supervision_timeout;
uint16_t min_ce_length;
uint16_t max_ce_length;
} PACKED le_create_connection_cp;
#define LE_CREATE_CONN_CP_SIZE 25
#define OCF_LE_CREATE_CONN_CANCEL 0x000E
#define OCF_LE_READ_WHITE_LIST_SIZE 0x000F
typedef __packed struct _le_read_white_list_size_rp{
uint8_t status;
uint8_t size;
} PACKED le_read_white_list_size_rp;
#define LE_READ_WHITE_LIST_SIZE_RP_SIZE 2
#define OCF_LE_CLEAR_WHITE_LIST 0x0010
#define OCF_LE_ADD_DEVICE_TO_WHITE_LIST 0x0011
typedef __packed struct _le_add_device_to_white_list_cp{
uint8_t bdaddr_type;
tBDAddr bdaddr;
} PACKED le_add_device_to_white_list_cp;
#define LE_ADD_DEVICE_TO_WHITE_LIST_CP_SIZE 7
#define OCF_LE_REMOVE_DEVICE_FROM_WHITE_LIST 0x0012
typedef __packed struct _le_remove_device_from_white_list_cp{
uint8_t bdaddr_type;
tBDAddr bdaddr;
} PACKED le_remove_device_from_white_list_cp;
#define LE_REMOVE_DEVICE_FROM_WHITE_LIST_CP_SIZE 7
#define OCF_LE_CONN_UPDATE 0x0013
typedef __packed struct _le_connection_update_cp{
uint16_t handle;
uint16_t min_interval;
uint16_t max_interval;
uint16_t latency;
uint16_t supervision_timeout;
uint16_t min_ce_length;
uint16_t max_ce_length;
} PACKED le_connection_update_cp;
#define LE_CONN_UPDATE_CP_SIZE 14
#define OCF_LE_SET_HOST_CHANNEL_CLASSIFICATION 0x0014
typedef __packed struct _le_set_host_channel_classification_cp{
uint8_t map[5];
} PACKED le_set_host_channel_classification_cp;
#define LE_SET_HOST_CHANNEL_CLASSIFICATION_CP_SIZE 5
#define OCF_LE_READ_CHANNEL_MAP 0x0015
typedef __packed struct _le_read_channel_map_cp{
uint16_t handle;
} PACKED le_read_channel_map_cp;
#define LE_READ_CHANNEL_MAP_CP_SIZE 2
typedef __packed struct _le_read_channel_map_rp{
uint8_t status;
uint16_t handle;
uint8_t map[5];
} le_read_channel_map_rp;
#define LE_READ_CHANNEL_MAP_RP_SIZE 8
#define OCF_LE_READ_REMOTE_USED_FEATURES 0x0016
typedef __packed struct _le_read_remote_used_features_cp{
uint16_t handle;
} PACKED le_read_remote_used_features_cp;
#define LE_READ_REMOTE_USED_FEATURES_CP_SIZE 2
#define OCF_LE_ENCRYPT 0x0017
typedef __packed struct _le_encrypt_cp{
uint8_t key[16];
uint8_t plaintext[16];
} PACKED le_encrypt_cp;
#define LE_ENCRYPT_CP_SIZE 32
typedef __packed struct _le_encrypt_rp{
uint8_t status;
uint8_t encdata[16];
} PACKED le_encrypt_rp;
#define LE_ENCRYPT_RP_SIZE 17
#define OCF_LE_RAND 0x0018
typedef __packed struct _le_rand_rp{
uint8_t status;
uint8_t random[8];
} PACKED le_rand_rp;
#define LE_RAND_RP_SIZE 9
#define OCF_LE_START_ENCRYPTION 0x0019
typedef __packed struct _le_start_encryption_cp{
uint16_t handle;
uint8_t random[8];
uint16_t diversifier;
uint8_t key[16];
} PACKED le_start_encryption_cp;
#define LE_START_ENCRYPTION_CP_SIZE 28
#define OCF_LE_LTK_REPLY 0x001A
typedef __packed struct _le_ltk_reply_cp{
uint16_t handle;
uint8_t key[16];
} PACKED le_ltk_reply_cp;
#define LE_LTK_REPLY_CP_SIZE 18
typedef __packed struct _le_ltk_reply_rp{
uint8_t status;
uint16_t handle;
} PACKED le_ltk_reply_rp;
#define LE_LTK_REPLY_RP_SIZE 3
#define OCF_LE_LTK_NEG_REPLY 0x001B
typedef __packed struct _le_ltk_neg_reply_cp{
uint16_t handle;
} PACKED le_ltk_neg_reply_cp;
#define LE_LTK_NEG_REPLY_CP_SIZE 2
typedef __packed struct _le_ltk_neg_reply_rp{
uint8_t status;
uint16_t handle;
} PACKED le_ltk_neg_reply_rp;
#define LE_LTK_NEG_REPLY_RP_SIZE 3
#define OCF_LE_READ_SUPPORTED_STATES 0x001C
typedef __packed struct _le_read_supported_states_rp{
uint8_t status;
uint8_t states[8];
} PACKED le_read_supported_states_rp;
#define LE_READ_SUPPORTED_STATES_RP_SIZE 9
#define OCF_LE_RECEIVER_TEST 0x001D
typedef __packed struct _le_receiver_test_cp{
uint8_t frequency;
} PACKED le_receiver_test_cp;
#define LE_RECEIVER_TEST_CP_SIZE 1
#define OCF_LE_TRANSMITTER_TEST 0x001E
typedef __packed struct _le_transmitter_test_cp{
uint8_t frequency;
uint8_t length;
uint8_t payload;
} PACKED le_transmitter_test_cp;
#define LE_TRANSMITTER_TEST_CP_SIZE 3
#define OCF_LE_TEST_END 0x001F
typedef __packed struct _le_test_end_rp{
uint8_t status;
uint16_t num_pkts;
} PACKED le_test_end_rp;
#define LE_TEST_END_RP_SIZE 3
/* Vendor specific commands */
#define OGF_VENDOR_CMD 0x3f
/*------------- Events -------------*/
#define EVT_CONN_COMPLETE 0x03
typedef __packed struct _evt_conn_complete{
uint8_t status;
uint16_t handle;
tBDAddr bdaddr;
uint8_t link_type;
uint8_t encr_mode;
} PACKED evt_conn_complete;
#define EVT_CONN_COMPLETE_SIZE 13
#define EVT_DISCONN_COMPLETE 0x05
typedef __packed struct _evt_disconn_complete{
uint8_t status;
uint16_t handle;
uint8_t reason;
} PACKED evt_disconn_complete;
#define EVT_DISCONN_COMPLETE_SIZE 4
#define EVT_ENCRYPT_CHANGE 0x08
typedef __packed struct _evt_encrypt_change{
uint8_t status;
uint16_t handle;
uint8_t encrypt;
} PACKED evt_encrypt_change;
#define EVT_ENCRYPT_CHANGE_SIZE 5
#define EVT_READ_REMOTE_VERSION_COMPLETE 0x0C
#define EVT_CMD_COMPLETE 0x0E
typedef __packed struct _evt_cmd_complete{
uint8_t ncmd;
uint16_t opcode;
} PACKED evt_cmd_complete;
#define EVT_CMD_COMPLETE_SIZE 3
#define EVT_CMD_STATUS 0x0F
typedef __packed struct _evt_cmd_status{
uint8_t status;
uint8_t ncmd;
uint16_t opcode;
} PACKED evt_cmd_status;
#define EVT_CMD_STATUS_SIZE 4
#define EVT_HARDWARE_ERROR 0x10
typedef __packed struct _evt_hardware_error{
uint8_t code;
} PACKED evt_hardware_error;
#define EVT_HARDWARE_ERROR_SIZE 1
#define EVT_NUM_COMP_PKTS 0x13
typedef __packed struct _evt_num_comp_pkts{
uint8_t num_hndl;
/* variable length part */
} PACKED evt_num_comp_pkts;
#define EVT_NUM_COMP_PKTS_SIZE 1
/* variable length part of evt_num_comp_pkts. */
typedef __packed struct _evt_num_comp_pkts_param{
uint16_t hndl;
uint16_t num_comp_pkts;
} PACKED evt_num_comp_pkts_param;
#define EVT_NUM_COMP_PKTS_PARAM_SIZE 1
#define EVT_DATA_BUFFER_OVERFLOW 0x1A
typedef __packed struct _evt_data_buffer_overflow{
uint8_t link_type;
} PACKED evt_data_buffer_overflow;
#define EVT_DATA_BUFFER_OVERFLOW_SIZE 1
#define EVT_ENCRYPTION_KEY_REFRESH_COMPLETE 0x30
typedef __packed struct _evt_encryption_key_refresh_complete{
uint8_t status;
uint16_t handle;
} PACKED evt_encryption_key_refresh_complete;
#define EVT_ENCRYPTION_KEY_REFRESH_COMPLETE_SIZE 3
#define EVT_LE_META_EVENT 0x3E
typedef __packed struct _evt_le_meta_event{
uint8_t subevent;
uint8_t data[0];
} PACKED evt_le_meta_event;
#define EVT_LE_META_EVENT_SIZE 1
#define EVT_LE_CONN_COMPLETE 0x01
typedef __packed struct _evt_le_connection_complete{
uint8_t status;
uint16_t handle;
uint8_t role;
uint8_t peer_bdaddr_type;
tBDAddr peer_bdaddr;
uint16_t interval;
uint16_t latency;
uint16_t supervision_timeout;
uint8_t master_clock_accuracy;
} PACKED evt_le_connection_complete;
#define EVT_LE_CONN_COMPLETE_SIZE 18
#define EVT_LE_ADVERTISING_REPORT 0x02
typedef __packed struct _le_advertising_info{
uint8_t evt_type;
uint8_t bdaddr_type;
tBDAddr bdaddr;
uint8_t data_length;
uint8_t data_RSSI[0]; // RSSI is last octect (signed integer).
} PACKED le_advertising_info;
#define LE_ADVERTISING_INFO_SIZE 9
#define EVT_LE_CONN_UPDATE_COMPLETE 0x03
typedef __packed struct _evt_le_connection_update_complete{
uint8_t status;
uint16_t handle;
uint16_t interval;
uint16_t latency;
uint16_t supervision_timeout;
} PACKED evt_le_connection_update_complete;
#define EVT_LE_CONN_UPDATE_COMPLETE_SIZE 9
#define EVT_LE_READ_REMOTE_USED_FEATURES_COMPLETE 0x04
typedef __packed struct _evt_le_read_remote_used_features_complete{
uint8_t status;
uint16_t handle;
uint8_t features[8];
} PACKED evt_le_read_remote_used_features_complete;
#define EVT_LE_READ_REMOTE_USED_FEATURES_COMPLETE_SIZE 11
#define EVT_LE_LTK_REQUEST 0x05
typedef __packed struct _evt_le_long_term_key_request{
uint16_t handle;
uint8_t random[8];
uint16_t ediv;
} PACKED evt_le_long_term_key_request;
#define EVT_LE_LTK_REQUEST_SIZE 12
/**
* The event code in the @ref hci_event_pckt structure. If event code is EVT_VENDOR,
* application can use @ref evt_blue_aci structure to parse the packet.
*/
#define EVT_VENDOR 0xFF
/* Command opcode pack/unpack */
#define cmd_opcode_pack(ogf, ocf) (uint16_t)((ocf & 0x03ff)|(ogf << 10))
#define cmd_opcode_ogf(op) (op >> 10)
#define cmd_opcode_ocf(op) (op & 0x03ff)
struct hci_request {
uint16_t ogf;
uint16_t ocf;
int event;
void *cparam;
int clen;
void *rparam;
int rlen;
};
int hci_send_req(struct hci_request *r, BOOL async);
#endif /* __HCI_INTERNAL_H_ */