1 /****************************************************************************** 2 * Copyright (c) 2022 Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK") 3 * All rights reserved. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 *****************************************************************************/ 18 #ifndef HCI_EVENT_H_ 19 #define HCI_EVENT_H_ 20 21 #include "stack/ble/ble_common.h" 22 23 /** 24 * @brief Definition for general HCI event packet 25 */ 26 typedef struct { 27 u8 type; 28 u8 eventCode; 29 u8 paraLen; 30 u8 parameters[1]; 31 } hci_event_t; 32 33 typedef struct { 34 u8 numHciCmds; 35 u8 opCode_OCF; 36 u8 opCode_OGF; 37 u8 returnParas[1]; 38 } hci_cmdCompleteEvt_evtParam_t; 39 40 typedef struct { 41 u8 status; 42 u8 numHciCmds; 43 u8 opCode_OCF; 44 u8 opCode_OGF; 45 } hci_cmdStatusEvt_evtParam_t; 46 47 typedef struct { 48 u16 connHandle; 49 u16 numOfCmpPkts; 50 } numCmpPktParamRet_t; 51 52 typedef struct { 53 u8 numHandles; 54 numCmpPktParamRet_t retParams[1]; 55 } hci_numOfCmpPktEvt_t; 56 57 typedef struct { 58 u8 status; 59 u16 connHandle; 60 u8 verNr; 61 u16 compId; 62 u16 subVerNr; 63 } hci_readRemVerInfoCmplEvt_t; 64 65 typedef struct { 66 u8 type; 67 u8 eventCode; 68 u8 paraLen; 69 u8 subEventCode; 70 u8 parameters[1]; 71 } hci_le_metaEvt_t; 72 73 /** 74 * @brief Event Parameters for "7.7.5 Disconnection Complete event" 75 */ 76 typedef struct { 77 u8 status; 78 u16 connHandle; 79 u8 reason; 80 } event_disconnection_t; 81 82 typedef struct { 83 u8 status; 84 u16 connHandle; 85 u8 reason; 86 } hci_disconnectionCompleteEvt_t; 87 88 /** 89 * @brief Event Parameters for "7.7.8 Encryption Change event" 90 */ 91 typedef struct { 92 u8 status; 93 u16 handle; 94 u8 enc_enable; 95 } event_enc_change_t; 96 97 typedef struct { 98 u8 status; 99 u16 connHandle; 100 u8 encryption_enable; 101 } hci_le_encryptEnableEvt_t; 102 103 /** 104 * @brief Event Parameters for "7.7.39 Encryption Key Refresh Complete event" 105 */ 106 typedef struct { 107 u8 status; 108 u16 handle; 109 } event_enc_refresh_t; 110 111 typedef struct { 112 u8 status; 113 u16 connHandle; 114 } hci_le_encryptKeyRefreshEvt_t; 115 116 /** 117 * @brief Event Parameters for "7.7.65.1 LE Connection Complete event" 118 */ 119 typedef struct { 120 u8 subEventCode; 121 u8 status; 122 u16 connHandle; 123 u8 role; 124 u8 peerAddrType; 125 u8 peerAddr[6]; 126 u16 connInterval; 127 u16 slaveLatency; 128 u16 supervisionTimeout; 129 u8 masterClkAccuracy; 130 } hci_le_connectionCompleteEvt_t; 131 132 /* ACL Connection Role */ 133 typedef enum { 134 LL_ROLE_MASTER = 0, 135 LL_ROLE_SLAVE = 1, 136 } acl_conection_role_t; 137 138 /** 139 * @brief Event Parameters for "7.7.65.2 LE Advertising Report event" 140 */ 141 typedef struct { 142 u8 subcode; 143 u8 nreport; 144 u8 event_type; 145 u8 adr_type; 146 u8 mac[6]; 147 u8 len; 148 u8 data[1]; 149 } event_adv_report_t; 150 151 /* Advertise report event type */ 152 typedef enum { 153 ADV_REPORT_EVENT_TYPE_ADV_IND = 0x00, 154 ADV_REPORT_EVENT_TYPE_DIRECT_IND = 0x01, 155 ADV_REPORT_EVENT_TYPE_SCAN_IND = 0x02, 156 ADV_REPORT_EVENT_TYPE_NONCONN_IND = 0x03, 157 ADV_REPORT_EVENT_TYPE_SCAN_RSP = 0x04, 158 } advReportEventType_t; 159 160 /** 161 * @brief Event Parameters for "7.7.65.3 LE Connection Update Complete event" 162 */ 163 typedef struct { 164 u8 subEventCode; 165 u8 status; 166 u16 connHandle; 167 u16 connInterval; 168 u16 connLatency; 169 u16 supervisionTimeout; 170 } hci_le_connectionUpdateCompleteEvt_t; 171 172 /** 173 * @brief Event Parameters for "7.7.65.4 LE Read Remote Features Complete event" 174 */ 175 #define LL_FEATURE_SIZE 8 176 typedef struct { 177 u8 subEventCode; 178 u8 status; 179 u16 connHandle; 180 u8 feature[LL_FEATURE_SIZE]; 181 } hci_le_readRemoteFeaturesCompleteEvt_t; 182 183 /** 184 * @brief Event Parameters for "7.7.65.5 LE Long Term Key Request event" 185 */ 186 typedef struct { 187 u8 subEventCode; 188 u16 connHandle; 189 u8 random[8]; 190 u16 ediv; 191 } hci_le_longTermKeyRequestEvt_t; 192 193 /** 194 * @brief Event Parameters for "7.7.65.6 LE Remote Connection Parameter Request event" 195 */ 196 typedef struct { 197 u8 subEventCode; 198 u16 connHandle; 199 u16 IntervalMin; 200 u16 IntervalMax; 201 u16 latency; 202 u16 timeout; 203 } hci_le_remoteConnParamReqEvt_t; 204 205 /** 206 * @brief Event Parameters for "7.7.65.7 LE Data Length Change event" 207 */ 208 typedef struct { 209 u8 subEventCode; 210 u16 connHandle; // no aligned, can not be used as pointer 211 u16 maxTxOct; 212 u16 maxTxtime; 213 u16 maxRxOct; 214 u16 maxRxtime; 215 } hci_le_dataLengthChangeEvt_t; 216 217 /** 218 * @brief Event Parameters for "7.7.65.8 LE Read Local P-256 Public Key Complete event" 219 */ 220 typedef struct { 221 u8 subEventCode; 222 u8 status; 223 u8 localP256Key[64]; 224 } hci_le_readLocalP256KeyCompleteEvt_t; 225 226 /** 227 * @brief Event Parameters for "7.7.65.9 LE Generate DHKey Complete event" 228 */ 229 typedef struct { 230 u8 subEventCode; 231 u8 status; 232 u8 DHKey[32]; 233 } hci_le_generateDHKeyCompleteEvt_t; 234 235 /** 236 * @brief Event Parameters for "7.7.65.10 LE Enhanced Connection Complete event" 237 */ 238 typedef struct { 239 u8 subEventCode; 240 u8 status; 241 u16 connHandle; 242 u8 role; 243 u8 PeerAddrType; 244 u8 PeerAddr[6]; 245 u8 localRslvPrivAddr[6]; 246 u8 Peer_RslvPrivAddr[6]; 247 u16 connInterval; 248 u16 connLatency; 249 u16 superTimeout; 250 u8 masterClkAccuracy; 251 } hci_le_enhancedConnCompleteEvt_t; 252 253 /** 254 * @brief Event Parameters for "7.7.65.12 LE PHY Update Complete event" 255 */ 256 typedef struct { 257 u8 subEventCode; 258 u8 status; 259 u16 connHandle; 260 u8 tx_phy; 261 u8 rx_phy; 262 } hci_le_phyUpdateCompleteEvt_t; 263 264 /** 265 * @brief Event Parameters for "7.7.65.13 LE Extended Advertising Report event" 266 */ 267 typedef struct { 268 u16 event_type; // 2 269 u8 address_type; // 1 270 u8 address[6]; // 6 271 u8 primary_phy; // 1 272 u8 secondary_phy; // 1 273 u8 advertising_sid; // 1 274 u8 tx_power; // 1 275 u8 rssi; // 1 276 u16 perd_adv_inter; // 2 Periodic_Advertising_Interval 277 u8 direct_address_type; // 1 278 u8 direct_address[6]; // 6 279 u8 data_length; // 1 280 u8 data[1]; 281 } extAdvEvt_info_t; 282 283 typedef struct { 284 u8 sub_code; 285 u16 sync_handle; 286 u8 tx_power; 287 288 u8 rssi; 289 u8 unused; 290 u8 data_status; 291 u8 data_len; 292 293 u8 data[1]; 294 } le_periodAdvReportEvt_t; 295 296 #define EXTADV_INFO_LENGTH 24 // byte number from "event_type" to "data_length" 297 #define EXTADV_RPT_DATA_LEN_MAX 229 // 253 - 24 = 229 298 299 typedef struct { 300 u8 subEventCode; 301 u8 num_reports; 302 u8 advEvtInfo[1]; 303 } hci_le_extAdvReportEvt_t; 304 305 /* Extended Advertising Report Event Event_Type mask */ 306 typedef enum { 307 EXTADV_RPT_EVT_MASK_CONNECTABLE = BIT(0), 308 EXTADV_RPT_EVT_MASK_SCANNABLE = BIT(1), 309 EXTADV_RPT_EVT_MASK_DIRECTED = BIT(2), 310 EXTADV_RPT_EVT_MASK_SCAN_RESPONSE = BIT(3), 311 EXTADV_RPT_EVT_MASK_LEGACY = BIT(4), 312 313 EXTADV_RPT_DATA_COMPLETE = 0x00, 314 EXTADV_RPT_DATA_INCOMPLETE_MORE_TO_COME = 0x20, 315 EXTADV_RPT_DATA_INCOMPLETE_TRUNCATED = 0x40, 316 EXTADV_RPT_DATA_RFU = 0x60, 317 318 EXTADV_RPT_EVTTYPE_MASK = 0x1F, 319 EXTADV_RPT_DATA_STATUS_MASK = 0x60, 320 } extAdvRptEvtMask_t; 321 322 /* Extended Advertising Report Event_Type */ 323 typedef enum { 324 // Legacy 325 EXTADV_RPT_EVTTYPE_LEGACY_ADV_IND = 0x0013, // 0001 0011'b 326 EXTADV_RPT_EVTTYPE_LEGACY_ADV_DIRECT_IND = 0x0015, // 0001 0101'b 327 EXTADV_RPT_EVTTYPE_LEGACY_ADV_SCAN_IND = 0x0012, // 0001 0010'b 328 EXTADV_RPT_EVTTYPE_LEGACY_ADV_NONCONN_IND = 0x0010, // 0001 0000'b 329 EXTADV_RPT_EVTTYPE_LEGACY_SCAN_RSP_2_ADV_IND = 0x001B, // 0001 1011'b 330 EXTADV_RPT_EVTTYPE_LEGACY_SCAN_RSP_2_ADV_SCAN_IND = 0x001A, // 0001 1010'b 331 332 // Extended 333 EXTADV_RPT_EVTTYPE_EXT_NON_CONN_NON_SCAN_UNDIRECTED = 334 0x0000, // Extended, Non_Connectable Non_Scannable Undirected 335 EXTADV_RPT_EVTTYPE_EXT_CONNECTABLE_UNDIRECTED = 0x0001, // Extended, Connectable Undirected 336 EXTADV_RPT_EVTTYPE_EXT_SCANNABLE_UNDIRECTED = 0x0002, // Extended, Scannable Undirected 337 EXTADV_RPT_EVTTYPE_EXT_NON_CONN_NON_SCAN_DIRECTED = 0x0004, // Extended, Non_Connectable Non_Scannable Directed 338 EXTADV_RPT_EVTTYPE_EXT_CONNECTABLE_DIRECTED = 0x0005, // Extended, Connectable Directed 339 EXTADV_RPT_EVTTYPE_EXT_SCANNABLE_DIRECTED = 0x0006, // Extended, Scannable Directed 340 EXTADV_RPT_EVTTYPE_EXT_SCAN_RESPONSE = 0x0008, // Extended, AUX_SCAN_RESPONSE 341 } extAdvRptEvtType_t; // extended advertising report event type 342 343 /* Address type */ 344 typedef enum { 345 EXTADV_RPT_PUBLIC_DEVICE_ADDRESS = 0x00, 346 EXTADV_RPT_RANDOM_DEVICE_ADDRESS = 0x01, 347 EXTADV_RPT_PUBLIC_IDENTITY_ADDRESS = 0x02, 348 EXTADV_RPT_RANDOM_IDENTITY_ADDRESS = 0x03, 349 EXTADV_RPT_ANONYMOUS_ADV = 0xFF, 350 } ext_adv_adr_type_t; 351 352 #define PERIODIC_ADV_INTER_NO_PERIODIC_ADV 0 353 #define SECONDARY_PHY_NO_PACKET_ON_SECONDARY_ADV_CHN 0 354 #define ADVERTISING_SID_NO_ADI_FIELD 0xFF 355 #define TX_POWER_INFO_NOT_AVAILABLE 127 356 357 /** 358 * @brief Event Parameters for "7.7.65.14 LE Periodic Advertising Sync Established event" 359 */ 360 typedef struct { 361 u8 subEventCode; 362 u8 status; 363 u16 syncHandle; 364 u8 advSID; 365 u8 advAddrType; 366 u8 advAddr[6]; 367 u8 advPHY; 368 u16 perdAdvItvl; 369 u8 advClkAccuracy; 370 } hci_le_periodicAdvSyncEstablishedEvt_t; 371 372 /** 373 * @brief Event Parameters for "7.7.65.15 LE Periodic Advertising Report event" 374 */ 375 typedef struct { 376 u8 subEventCode; 377 u16 syncHandle; 378 u8 txPower; 379 u8 RSSI; 380 u8 cteType; 381 u8 dataStatus; 382 u8 dataLength; // 0 to 247 Length of the Data field 383 u8 data[1]; 384 } hci_le_periodicAdvReportEvt_t; 385 386 /** 387 * @brief Event Parameters for "7.7.65.16 LE Periodic Advertising Sync Lost event" 388 */ 389 typedef struct { 390 u8 subEventCode; 391 u16 syncHandle; 392 } hci_le_periodicAdvSyncLostEvt_t; 393 394 typedef struct { 395 } hci_le_scanTimeoutEvt_t; 396 397 /** 398 * @brief Event Parameters for "7.7.65.18 LE Advertising Set Terminated event" 399 */ 400 typedef struct { 401 u8 subEventCode; 402 u8 status; 403 u8 advHandle; 404 u16 connHandle; 405 u8 num_compExtAdvEvt; 406 } hci_le_advSetTerminatedEvt_t; 407 408 /** 409 * @brief Event Parameters for "7.7.65.19 LE Scan Request Received event" 410 */ 411 typedef struct { 412 } hci_le_scanReqRcvdEvt_t; 413 414 /** 415 * @brief Event Parameters for "7.7.65.20 LE Channel Selection Algorithm event" 416 */ 417 typedef struct { 418 u8 subEventCode; 419 u16 connHandle; 420 u8 channel_selection_algotihm; 421 } hci_le_chnSelectAlgorithmEvt_t; 422 423 /** 424 * @brief Event Parameters for "7.7.65.25 LE CIS Established event" 425 */ 426 typedef struct { 427 u8 subEventCode; 428 u8 status; 429 u16 cisHandle; 430 u8 cigSyncDly[3]; 431 u8 cisSyncDly[3]; 432 u8 transLaty_m2s[3]; 433 u8 transLaty_s2m[3]; 434 u8 phy_m2s; 435 u8 phy_s2m; 436 u8 nse; 437 u8 bn_m2s; 438 u8 bn_s2m; 439 u8 ft_m2s; 440 u8 ft_s2m; 441 u16 maxPDU_m2s; 442 u16 maxPDU_s2m; 443 u16 isoIntvl; 444 } hci_le_cisEstablishedEvt_t; 445 446 /** 447 * @brief Event Parameters for "7.7.65.26 LE CIS Request event" 448 */ 449 typedef struct { 450 u8 subEventCode; 451 u16 aclHandle; 452 u16 cisHandle; 453 u8 cigId; 454 u8 cisId; 455 } hci_le_cisReqEvt_t; 456 457 /** 458 * @brief Event Parameters for "7.7.65.27 LE Create BIG Complete event" 459 */ 460 typedef struct { 461 u8 subEventCode; 462 u8 status; 463 u8 bigHandle; 464 u8 bigSyncDly[3]; 465 u8 transLatyBig[3]; 466 u8 phy; 467 u8 nse; 468 u8 bn; 469 u8 pto; 470 u8 irc; 471 u16 maxPDU; 472 u16 isoIntvl; 473 u8 numBis; 474 u16 bisHandles[1]; // LL_BIS_IN_PER_BIG_BCST_NUM_MAX]; 475 } hci_le_createBigCompleteEvt_t; 476 477 /** 478 * @brief Event Parameters for "7.7.65.28 LE Terminate BIG Complete event" 479 */ 480 typedef struct { 481 u8 subEventCode; 482 u8 bigHandle; 483 u8 reason; 484 } hci_le_terminateBigCompleteEvt_t; 485 486 /** 487 * @brief Event Parameters for "7.7.65.20 LE Channel Selection Algorithm event" 488 */ 489 typedef struct { 490 u8 subEventCode; 491 u8 status; 492 u8 bigHandle; 493 u8 transLatyBig[3]; 494 u8 nse; 495 u8 bn; 496 u8 pto; 497 u8 irc; 498 u16 maxPDU; 499 u16 isoIntvl; 500 u8 numBis; 501 u16 bisHandles[1]; // BIS_IN_PER_BIG_SYNC_NUM_MAX]; 502 } hci_le_bigSyncEstablishedEvt_t; 503 504 /** 505 * @brief Event Parameters for "7.7.65.29 LE BIG Sync Established event" 506 */ 507 typedef struct { 508 u8 subEventCode; 509 u8 bigHandle; 510 u8 reason; 511 } hci_le_bigSyncLostEvt_t; 512 513 /** 514 * @brief Event Parameters for "7.7.65.30 LE BIG Sync Lost event" 515 */ 516 517 /** 518 * @brief Event Parameters for "7.7.65.34 LE BIGInfo Advertising Report event" 519 */ 520 typedef struct { 521 u8 subEventCode; 522 u16 syncHandle; 523 u8 numBis; 524 u8 nse; 525 u16 IsoItvl; // in units of 1.25 ms. 526 u8 bn; 527 u8 pto; 528 u8 irc; 529 u16 maxPdu; 530 u8 sduItvl[3]; 531 u16 maxSdu; 532 u8 phy; 533 u8 framing; 534 u8 enc; 535 } hci_le_bigInfoAdvReportEvt_t; 536 537 int hci_le_periodicAdvSyncEstablished_evt(u8 status, u16 syncHandle, u8 advSID, u8 advAddrType, u8 advAddress[6], 538 u8 advPHY, u16 perdAdvItvl, u8 advClkAccuracy); 539 int hci_le_periodicAdvReport_evt(u8 subEventCode, u16 syncHandle, u8 txPower, u8 RSSI, u8 cteType, u8 dataStatus, 540 u8 dataLength, u8 *data); 541 int hci_le_periodicAdvSyncLost_evt(u16 syncHandle); 542 int hci_le_cisEstablished_evt(u8 status, u16 cisHandle, u8 cigSyncDly[3], u8 cisSyncDly[3], u8 transLaty_m2s[3], 543 u8 transLaty_s2m[3], u8 phy_m2s, u8 phy_s2m, u8 nse, u8 bn_m2s, u8 bn_s2m, u8 ft_m2s, 544 u8 ft_s2m, u16 maxPDU_m2s, u16 maxPDU_s2m, u16 isoIntvl); 545 int hci_le_cisReq_evt(u16 aclHandle, u16 cisHandle, u8 cigId, u8 cisId); 546 int hci_le_createBigComplete_evt(u8 status, u8 bigHandle, u8 bigSyncDly[3], u8 transLatyBig[3], u8 phy, u8 nse, u8 bn, 547 u8 pto, u8 irc, u16 maxPDU, u16 isoIntvl, u8 numBis, u16 *bisHandles); 548 int hci_le_terminateBigComplete_evt(u8 bigHandle, u8 reason); 549 int hci_le_bigSyncEstablished_evt(u8 staus, u8 bigHandle, u8 transLatyBig[3], u8 nse, u8 bn, u8 pto, u8 irc, 550 u16 maxPDU, u16 isoIntvl, u8 numBis, u16 *bisHandles); 551 int hci_le_bigSyncLost_evt(u8 bigHandle, u8 reason); 552 int hci_le_BigInfoAdvReport_evt(u16 syncHandle, u8 numBis, u8 nse, u16 IsoItvl, u8 bn, u8 pto, u8 irc, u16 maxPdu, 553 u8 sduItvl[3], u16 maxSdu, u8 phy, u8 framing, u8 enc); 554 int hci_disconnectionComplete_evt(u8 status, u16 connHandle, u8 reason); 555 int hci_cmdComplete_evt(u8 numHciCmds, u8 opCode_ocf, u8 opCode_ogf, u8 paraLen, u8 *para, u8 *result); 556 void hci_cmdStatus_evt(u8 numHciCmds, u8 opCode_ocf, u8 opCode_ogf, u8 status, u8 *result); 557 int hci_le_connectionComplete_evt(u8 status, u16 connHandle, u8 role, u8 peerAddrType, u8 *peerAddr, u16 connInterval, 558 u16 slaveLatency, u16 supervisionTimeout, u8 masterClkAccuracy); 559 int hci_le_enhancedConnectionComplete_evt(u8 status, u16 connHandle, u8 role, u8 peerAddrType, u8 *peerAddr, 560 u8 *loaclRpa, u8 *peerRpa, u16 connInterval, u16 connLatency, 561 u16 supervisionTimeout, u8 masterClkAccuracy); 562 int hci_le_connectionUpdateComplete_evt(u8 status, u16 connHandle, u16 connInterval, u16 connLatency, 563 u16 supervisionTimeout); 564 int hci_le_readRemoteFeaturesComplete_evt(u8 status, u16 connHandle, u8 *feature); 565 int hci_le_chennel_selection_algorithm_evt(u16 connhandle, u8 channel_selection_alg); 566 int hci_le_phyUpdateComplete_evt(u16 connhandle, u8 status, u8 new_phy); 567 int hci_le_data_len_update_evt(u16 connhandle, u16 effTxOctets, u16 effRxOctets, u16 maxtxtime, u16 maxrxtime); 568 int hci_le_longTermKeyRequest_evt(u16 connHandle, u8 *random, u16 ediv, u8 *result); 569 int hci_le_readLocalP256KeyComplete_evt(u8 *localP256Key, u8 status); 570 int hci_le_generateDHKeyComplete_evt(u8 *DHkey, u8 status); 571 int hci_le_encryptChange_evt(u16 connhandle, u8 encrypt_en); 572 int hci_le_encryptKeyRefresh_evt(u16 connhandle); 573 int hci_remoteNateReqComplete_evt(u8 *bd_addr); 574 575 #endif /* HCI_EVENT_H_ */ 576