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