-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhci_extended_cmd.h
124 lines (113 loc) · 2.91 KB
/
hci_extended_cmd.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
#pragma once
// add missing definition from hci.h
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
#include <errno.h>
int set_random( int dd, int to) {
struct hci_request rq;
le_set_random_address_cp param_cp;
uint8_t status;
memset(¶m_cp, 0, sizeof(param_cp));
//param_cp.bdaddr = 0x1234;
memset(&rq, 0, sizeof(rq));
rq.ogf = OGF_LE_CTL;
rq.ocf = OCF_LE_SET_RANDOM_ADDRESS;
rq.cparam = ¶m_cp;
rq.clen = LE_SET_RANDOM_ADDRESS_CP_SIZE;
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(dd, &rq, to) < 0)
return -1;
if (status) {
errno = EIO;
return -1;
}
return 0;
}
#ifndef BT_HCI_CMD_LE_SET_EXT_SCAN_PARAMS
#define BT_HCI_CMD_LE_SET_EXT_SCAN_PARAMS 0x2041
int hci_le_set_ext_scan_parameters(int dd, uint8_t type, uint16_t interval, uint16_t window, uint8_t own_type, uint8_t filter, int to)
{
struct bt_hci_cmd_le_set_ext_scan_params {
uint8_t own_addr_type;
uint8_t filter_policy;
uint8_t num_phys;
uint8_t type;
uint16_t interval;
uint16_t window;
} __attribute__((packed)) param_cp;
memset(¶m_cp, 0, sizeof(param_cp));
param_cp.type = type;
param_cp.interval = interval;
param_cp.window = window;
param_cp.own_addr_type = own_type;
param_cp.filter_policy = filter;
param_cp.num_phys = 1;
uint8_t status;
struct hci_request rq;
memset(&rq, 0, sizeof(rq));
rq.ogf = OGF_LE_CTL;
rq.ocf = BT_HCI_CMD_LE_SET_EXT_SCAN_PARAMS;
rq.cparam = ¶m_cp;
rq.clen = sizeof(bt_hci_cmd_le_set_ext_scan_params);
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(dd, &rq, to) < 0)
return -1;
if (status) {
errno = EIO;
return -1;
}
return 0;
}
#endif // !BT_HCI_CMD_LE_SET_EXT_SCAN_PARAMS
#ifndef BT_HCI_CMD_LE_SET_EXT_SCAN_ENABLE
#define BT_HCI_CMD_LE_SET_EXT_SCAN_ENABLE 0x2042
int hci_le_set_ext_scan_enable(int dd, uint8_t enable, uint8_t filter_dup, int to)
{
struct bt_hci_cmd_le_set_ext_scan_enable {
uint8_t enable;
uint8_t filter_dup;
uint16_t duration;
uint16_t period;
} __attribute__((packed)) scan_cp;
memset(&scan_cp, 0, sizeof(scan_cp));
scan_cp.enable = enable;
scan_cp.filter_dup = filter_dup;
uint8_t status;
struct hci_request rq;
memset(&rq, 0, sizeof(rq));
rq.ogf = OGF_LE_CTL;
rq.ocf = BT_HCI_CMD_LE_SET_EXT_SCAN_ENABLE;
rq.cparam = &scan_cp;
rq.clen = sizeof(scan_cp);
rq.rparam = &status;
rq.rlen = 1;
if (hci_send_req(dd, &rq, to) < 0)
return -1;
if (status) {
errno = EIO;
return -1;
}
return 0;
}
#endif // !BT_HCI_CMD_LE_SET_EXT_SCAN_ENABLE
#ifndef BT_HCI_EVT_LE_META_EVENT
#define BT_HCI_EVT_LE_META_EVENT 0x3e
struct bt_hci_le_ext_adv_report {
uint16_t event_type;
uint8_t addr_type;
uint8_t addr[6];
uint8_t primary_phy;
uint8_t secondary_phy;
uint8_t sid;
uint8_t tx_power;
int8_t rssi;
uint16_t interval;
uint8_t direct_addr_type;
uint8_t direct_addr[6];
uint8_t data_len;
uint8_t data[0];
} __attribute__ ((packed));
#endif // !BT_HCI_EVT_LE_META_EVENT