1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef HCI_DEF_LE_EVT_H
17 #define HCI_DEF_LE_EVT_H
18 
19 #include <stdint.h>
20 
21 #include "hci_def_common.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #pragma pack(1)
28 
29 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
30 // 7.7.65.1 LE Connection Complete Event
31 #define HCI_LE_CONNECTION_COMPLETE_EVENT 0x01
32 
33 #define HCI_PEER_ADDR_TYPE_PUBLIC 0x00
34 #define HCI_PEER_ADDR_TYPE_RANDOM 0x01
35 
36 typedef struct {
37     uint8_t status;
38     uint16_t connectionHandle;
39     uint8_t role;
40     uint8_t peerAddressType;
41     HciBdAddr peerAddress;
42     uint16_t connInterval;
43     uint16_t connLatency;
44     uint16_t supervisionTimeout;
45     uint8_t masterClockAccuracy;
46 } HciLeConnectionCompleteEventParam;
47 
48 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
49 // 7.7.65.2 LE Advertising Report Event
50 #define HCI_LE_ADVERTISING_REPORT_EVENT 0x02
51 
52 typedef struct {
53     uint8_t eventType;
54     uint8_t addressType;
55     HciBdAddr address;
56     uint8_t lengthData;
57     uint8_t *data;
58     uint8_t rssi;
59 } HciLeAdvertisingReport;
60 
61 typedef struct {
62     uint8_t numReports;
63     HciLeAdvertisingReport *reports;
64 } HciLeAdvertisingReportEventParam;
65 
66 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
67 // 7.7.65.3 LE Connection Update Complete Event
68 #define HCI_LE_CONNECTION_UPDATE_COMPLETE_EVENT 0x03
69 
70 typedef struct {
71     uint8_t status;
72     uint16_t connectionHandle;
73     uint16_t connInterval;
74     uint16_t connLatency;
75     uint16_t supervisionTimeout;
76 } HciLeConnectionUpdateCompleteEventParam;
77 
78 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
79 // 7.7.65.4 LE Read Remote Features Complete Event
80 #define HCI_LE_READ_REMOTE_FEATURES_COMPLETE_EVENT 0x04
81 
82 typedef struct {
83     uint8_t status;
84     uint16_t connectionHandle;
85     HciLeFeatures leFeatures;
86 } HciLeReadRemoteFeaturesCompleteEventParam;
87 
88 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
89 // 7.7.65.5 LE Long Term Key Request Event
90 #define HCI_LE_LONG_TERM_KEYREQUEST_EVENT 0x05
91 
92 typedef struct {
93     uint16_t connectionHandle;
94     uint8_t randomNumber[8];
95     uint16_t encryptedDiversifier;
96 } HciLeLongTermKeyRequestEventParam;
97 
98 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
99 // 7.7.65.6 LE Remote Connection Parameter Request Event
100 #define HCI_LE_REMOTE_CONNECTION_PARAMETER_REQUEST_EVENT 0x06
101 
102 typedef struct {
103     uint16_t connectionHandle;
104     uint16_t intervalMin;
105     uint16_t IntervalMax;
106     uint16_t latency;
107     uint16_t timeout;
108 } HciLeRemoteConnectionParameterRequestEventParam;
109 
110 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
111 // 7.7.65.7 LE Data Length Change Event
112 #define HCI_LE_DATA_LENGTH_CHANGE_EVENT 0x07
113 
114 typedef struct {
115     uint8_t subeventCode;
116     uint16_t connectionHandle;
117     uint16_t maxTxOctets;
118     uint16_t maxTxTime;
119     uint16_t maxRxOctets;
120     uint16_t maxRxTime;
121 } HciLeDataLengthChangeEventParam;
122 
123 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
124 // 7.7.65.8 LE Read Local P-256 Public Key Complete Event
125 #define HCI_LE_READ_LOCAL_P256_PUBLIC_KEY_COMPLETE_EVENT 0x08
126 
127 typedef struct {
128     uint8_t status;
129     uint8_t localP256PublicKey[64];
130 } HciLeReadLocalP256PublicKeyCompleteEventParam;
131 
132 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
133 // 7.7.65.9 LE Generate DHKey Complete Event
134 #define HCI_LE_GENERATE_DHKEY_COMPLETE_EVENT 0x09
135 
136 typedef struct {
137     uint8_t status;
138     uint8_t DHKey[32];
139 } HciLeGenerateDHKeyCompleteEventParam;
140 
141 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
142 // 7.7.65.10 LE Enhanced Connection Complete Event
143 #define HCI_LE_ENHANCED_CONNECTION_COMPLETE_EVENT 0x0A
144 
145 typedef struct {
146     uint8_t status;
147     uint16_t connectionHandle;
148     uint8_t role;
149     uint8_t peerAddressType;
150     HciBdAddr peerAddress;
151     HciBdAddr localResolvablePrivateAddress;
152     HciBdAddr peerResolvablePrivateAddress;
153     uint16_t connInterval;
154     uint16_t connLatency;
155     uint16_t supervisionTimeout;
156     uint8_t masterClockAccuracy;
157 } HciLeEnhancedConnectionCompleteEventParam;
158 
159 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
160 // 7.7.65.11 LE Directed Advertising Report Event
161 #define HCI_LE_DIRECTED_ADVERTISING_REPORT_EVENT 0x0B
162 
163 typedef struct {
164     uint8_t eventType;
165     uint8_t addressType;
166     HciBdAddr address;
167     uint8_t directAddressType;
168     HciBdAddr directAddress;
169     uint8_t rssi;
170 } HciLeDirectedAdvertisingReport;
171 
172 typedef struct {
173     uint8_t numReports;
174     HciLeDirectedAdvertisingReport *reports;
175 } HciLeDirectedAdvertisingReportEventParam;
176 
177 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
178 // 7.7.65.12 LE PHY Update Complete Event
179 #define HCI_LE_PHY_UPDATE_COMPLETE_EVENT 0x0C
180 
181 typedef struct {
182     uint8_t status;
183     uint16_t connectionHandle;
184     uint8_t txPhy;
185     uint8_t rxPhy;
186 } HciLePhyUpdateCompleteEventParam;
187 
188 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
189 // 7.7.65.13 LE Extended Advertising Report Event
190 #define HCI_LE_EXTENDED_ADVERTISING_REPORT_EVENT 0x0D
191 
192 #define HCI_PDU_TYPE_ADV_IND 4105
193 #define HCI_PDU_TYPE_ADV_DIRECT_IND 4161
194 #define HCI_PDU_TYPE_ADV_SCAN_IND 4104
195 #define HCI_PDU_TYPE_ADV_NONCONN_IND 4096
196 #define HCI_PDU_TYPE_SCAN_RSP_TO_AN_ADV_IND 4617
197 #define HCI_PDU_TYPE_SCAN_RSP_TO_AN_ADV_SCAN_IND 4616
198 
199 typedef struct {
200     uint16_t eventType;
201     uint8_t addressType;
202     HciBdAddr address;
203     uint8_t primaryPHY;
204     uint8_t secondaryPHY;
205     uint8_t advertisingSID;
206     uint8_t txPower;
207     uint8_t rssi;
208     uint16_t periodicAdvertisingInterval;
209     uint8_t directAddressType;
210     HciBdAddr directAddress;
211     uint8_t dataLength;
212     uint8_t *data;
213 } HciLeExtendedAdvertisingReport;
214 
215 typedef struct {
216     uint8_t numReports;
217     HciLeExtendedAdvertisingReport *reports;
218 } HciLeExtendedAdvertisingReportEventParam;
219 
220 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
221 // 7.7.65.14 LE Periodic Advertising Sync Established Event
222 #define HCI_LE_PERIODIC_ADVERTISING_SYNC_ESTABLISHED_EVENT 0x0E
223 
224 typedef struct {
225     uint8_t status;
226     uint8_t advertisingHandle;
227     uint16_t connectionHandle;
228     uint8_t numCompletedExtendedAdvertisingEvents;
229 } HciLePeriodicAdvertisingSyncEstablishedEventParam;
230 
231 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
232 // 7.7.65.15 LE Periodic Advertising Report Event
233 #define HCI_LE_PERIODIC_ADVERTISING_REPORT_EVENT 0x0F
234 
235 typedef struct {
236     uint8_t subeventCode;
237     uint16_t syncHandle;
238     uint8_t txPower;
239     uint8_t rssi;
240     uint8_t unused;
241     uint8_t dataStatus;
242     uint8_t dataLength;
243     uint8_t *data;
244 } HciLePeriodicAdvertisingReportEventParam;
245 
246 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
247 // 7.7.65.16 LE Periodic Advertising Sync Lost Event
248 #define HCI_LE_PERIODIC_ADVERTISING_SYNC_LOST_EVENT 0x10
249 
250 typedef struct {
251     uint8_t subeventCode;
252     uint16_t syncHandle;
253 } HciLePeriodicAdvertisingSyncLostEventParam;
254 
255 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
256 // 7.7.65.17 LE Scan Timeout Event
257 #define HCI_LE_SCAN_TIMEOUT_EVENT 0x11
258 
259 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
260 // 7.7.65.18 LE Advertising Set Terminated Event
261 #define HCI_LE_ADVERTISING_SET_TERMINATED_EVENT 0x12
262 
263 typedef struct {
264     uint8_t status;
265     uint8_t advertisingHandle;
266     uint16_t connectionHandle;
267     uint8_t numCompletedExtendedAdvertisingEvents;
268 } HciLeAdvertisingSetTerminatedEventParam;
269 
270 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
271 // 7.7.65.19 LE Scan Request Received Event
272 #define HCI_LE_SCAN_REQUEST_RECEIVED_EVENT 0x13
273 
274 typedef struct {
275     uint8_t advertisingHandle;
276     uint8_t scannerAddressType;
277     HciBdAddr scannerAddress;
278 } HciLeScanRequestReceivedEventParam;
279 
280 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
281 // 7.7.65.20 LE Channel Selection Algorithm Event
282 #define HCI_LE_CHANNEL_SELECTION_ALGORITHM_EVENT 0x14
283 
284 typedef struct {
285     uint16_t connectionHandle;
286     uint8_t ChannelSelectionAlgorithm;
287 } HciLeChannelSelectionAlgorithmEventParam;
288 
289 // BLUETOOTH SPECIFICATION Version 5.0 | Vol 2, Part E
290 // 7.7.75 Authenticated Payload Timeout Expired Event
291 #define HCI_AUTHENTICATED_PAYLOAD_TIMEOUT_EXPIRED_EVENT 0x57
292 
293 typedef struct {
294     uint16_t connectionHandle;
295 } HciAuthenticatedPayloadTimeoutExpiredEventParam;
296 
297 #pragma pack(0)
298 
299 #ifdef __cplusplus
300 }
301 #endif
302 
303 #endif