1 /****************************************************************************** 2 * 3 * Copyright 1999-2012 Broadcom Corporation 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 19 /****************************************************************************** 20 * 21 * this file contains the L2CAP API definitions 22 * 23 ******************************************************************************/ 24 #pragma once 25 26 #include <bluetooth/log.h> 27 #include <stdbool.h> 28 29 #include <cstdint> 30 #include <vector> 31 32 #include "stack/include/bt_hdr.h" 33 #include "stack/include/l2cap_interface.h" 34 #include "stack/include/l2cap_types.h" 35 #include "types/bt_transport.h" 36 #include "types/hci_role.h" 37 #include "types/raw_address.h" 38 39 /***************************************************************************** 40 * Constants 41 ****************************************************************************/ 42 43 #define L2CAP_LCC_SDU_LENGTH 2 44 #define L2CAP_LCC_OFFSET (L2CAP_MIN_OFFSET + L2CAP_LCC_SDU_LENGTH) /* plus SDU length(2) */ 45 46 #define L2CAP_FCS_LENGTH 2 47 48 /* Values for priority parameter to L2CA_SetTxPriority */ 49 #define L2CAP_CHNL_PRIORITY_HIGH 0 50 #define L2CAP_CHNL_PRIORITY_LOW 2 51 52 typedef uint8_t tL2CAP_CHNL_PRIORITY; 53 54 /* Values for Tx/Rx data rate parameter to L2CA_SetChnlDataRate */ 55 #define L2CAP_CHNL_DATA_RATE_LOW 1 56 57 typedef uint8_t tL2CAP_CHNL_DATA_RATE; 58 59 /* Data Packet Flags (bits 2-15 are reserved) */ 60 /* layer specific 14-15 bits are used for FCR SAR */ 61 #define L2CAP_FLUSHABLE_MASK 0x0003 62 #define L2CAP_FLUSHABLE_CH_BASED 0x0000 63 #define L2CAP_FLUSHABLE_PKT 0x0001 64 #define L2CAP_NON_FLUSHABLE_PKT 0x0002 65 66 /* L2CA_FlushChannel num_to_flush definitions */ 67 #define L2CAP_FLUSH_CHANS_ALL 0xffff 68 #define L2CAP_FLUSH_CHANS_GET 0x0000 69 70 /* Values for 'allowed_modes' field passed in structure tL2CAP_ERTM_INFO 71 */ 72 #define L2CAP_FCR_CHAN_OPT_BASIC (1 << L2CAP_FCR_BASIC_MODE) 73 #define L2CAP_FCR_CHAN_OPT_ERTM (1 << L2CAP_FCR_ERTM_MODE) 74 75 #define L2CAP_FCR_CHAN_OPT_ALL_MASK (L2CAP_FCR_CHAN_OPT_BASIC | L2CAP_FCR_CHAN_OPT_ERTM) 76 77 /* Validity check for PSM. PSM values must be odd. Also, all PSM values must 78 * be assigned such that the least significant bit of the most significant 79 * octet equals zero. 80 */ 81 #define L2C_INVALID_PSM(psm) (((psm) & 0x0101) != 0x0001) 82 #define L2C_IS_VALID_PSM(psm) (((psm) & 0x0101) == 0x0001) 83 #define L2C_IS_VALID_LE_PSM(psm) (((psm) > 0x0000) && ((psm) < 0x0100)) 84 85 #define L2CAP_NO_IDLE_TIMEOUT 0xFFFF 86 87 /***************************************************************************** 88 * Type Definitions 89 ****************************************************************************/ 90 91 /* Values for service_type */ 92 #define SVC_TYPE_BEST_EFFORT 1 93 #define SVC_TYPE_GUARANTEED 2 94 95 // This is initial amount of credits we send, and amount to which we increase 96 // credits once they fall below threshold 97 uint16_t L2CA_LeCreditDefault(); 98 99 // If credit count on remote fall below this value, we send back credits to 100 // reach default value. 101 uint16_t L2CA_LeCreditThreshold(); 102 103 /********************************* 104 * Callback Functions Prototypes 105 *********************************/ 106 107 /* Connection indication callback prototype. Parameters are 108 * BD Address of remote 109 * Local CID assigned to the connection 110 * PSM that the remote wants to connect to 111 * Identifier that the remote sent 112 */ 113 typedef void(tL2CA_CONNECT_IND_CB)(const RawAddress&, uint16_t, uint16_t, uint8_t); 114 115 /* Connection confirmation callback prototype. Parameters are 116 * Local CID 117 * Result - 0 = connected 118 * If there is an error, tL2CA_ERROR_CB is invoked 119 */ 120 typedef void(tL2CA_CONNECT_CFM_CB)(uint16_t, tL2CAP_CONN); 121 122 /* Configuration indication callback prototype. Parameters are 123 * Local CID assigned to the connection 124 * Pointer to configuration info 125 */ 126 typedef void(tL2CA_CONFIG_IND_CB)(uint16_t, tL2CAP_CFG_INFO*); 127 128 constexpr uint16_t L2CAP_INITIATOR_LOCAL = 1; 129 constexpr uint16_t L2CAP_INITIATOR_REMOTE = 0; 130 /* Configuration confirm callback prototype. Parameters are 131 * Local CID assigned to the connection 132 * Initiator (1 for local, 0 for remote) 133 * Initial config from remote 134 * If there is an error, tL2CA_ERROR_CB is invoked 135 */ 136 typedef void(tL2CA_CONFIG_CFM_CB)(uint16_t, uint16_t, tL2CAP_CFG_INFO*); 137 138 /* Disconnect indication callback prototype. Parameters are 139 * Local CID 140 * Boolean whether upper layer should ack this 141 */ 142 typedef void(tL2CA_DISCONNECT_IND_CB)(uint16_t, bool); 143 144 /* Disconnect confirm callback prototype. Parameters are 145 * Local CID 146 * Result 147 */ 148 typedef void(tL2CA_DISCONNECT_CFM_CB)(uint16_t, uint16_t); 149 150 /* Disconnect confirm callback prototype. Parameters are 151 * Local CID 152 * Result 153 */ 154 typedef void(tL2CA_DATA_IND_CB)(uint16_t, BT_HDR*); 155 156 /* Congestion status callback protype. This callback is optional. If 157 * an application tries to send data when the transmit queue is full, 158 * the data will anyways be dropped. The parameter is: 159 * Local CID 160 * true if congested, false if uncongested 161 */ 162 typedef void(tL2CA_CONGESTION_STATUS_CB)(uint16_t, bool); 163 164 /* Transmit complete callback protype. This callback is optional. If 165 * set, L2CAP will call it when packets are sent or flushed. If the 166 * count is 0xFFFF, it means all packets are sent for that CID (eRTM 167 * mode only). The parameters are: 168 * Local CID 169 * Number of SDUs sent or dropped 170 */ 171 typedef void(tL2CA_TX_COMPLETE_CB)(uint16_t, uint16_t); 172 173 /* 174 * Notify the user when the remote send error result on ConnectRsp or ConfigRsp 175 * The parameters are: 176 * Local CID 177 * Error type (L2CAP_CONN_OTHER_ERROR for ConnectRsp, 178 * L2CAP_CFG_FAILED_NO_REASON for ConfigRsp) 179 */ 180 typedef void(tL2CA_ERROR_CB)(uint16_t, uint16_t); 181 182 /* Create credit based connection request callback prototype. Parameters are 183 * BD Address of remote 184 * Vector of allocated local cids to accept 185 * PSM 186 * Peer MTU 187 * Identifier that the remote sent 188 */ 189 typedef void(tL2CA_CREDIT_BASED_CONNECT_IND_CB)(const RawAddress& bdaddr, 190 std::vector<uint16_t>& lcids, uint16_t psm, 191 uint16_t peer_mtu, uint8_t identifier); 192 193 /* Collision Indication callback prototype. Used to notify upper layer that 194 * remote devices sent Credit Based Connection Request but it was rejected due 195 * to ongoing local request. Upper layer might want to sent another request when 196 * local request is completed. Parameters are: 197 * BD Address of remote 198 */ 199 typedef void(tL2CA_CREDIT_BASED_COLLISION_IND_CB)(const RawAddress& bdaddr); 200 201 /* Credit based connection confirmation callback prototype. Parameters are 202 * BD Address of remote 203 * Connected Local CIDs 204 * Peer MTU 205 * Result - 0 = connected, non-zero means CID is not connected 206 */ 207 typedef void(tL2CA_CREDIT_BASED_CONNECT_CFM_CB)(const RawAddress& bdaddr, uint16_t lcid, 208 uint16_t peer_mtu, tL2CAP_LE_RESULT_CODE result); 209 210 /* Credit based reconfiguration confirm callback prototype. Parameters are 211 * BD Address of remote 212 * Local CID assigned to the connection 213 * Flag indicating if this is local or peer configuration 214 * Pointer to configuration info 215 */ 216 typedef void(tL2CA_CREDIT_BASED_RECONFIG_COMPLETED_CB)(const RawAddress& bdaddr, uint16_t lcid, 217 bool is_local_cfg, 218 tL2CAP_LE_CFG_INFO* p_cfg); 219 220 /***************************************************************************** 221 * External Function Declarations 222 ****************************************************************************/ 223 224 // Also does security for you 225 [[nodiscard]] uint16_t L2CA_RegisterWithSecurity(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, 226 bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info, 227 uint16_t my_mtu, uint16_t required_remote_mtu, 228 uint16_t sec_level); 229 230 /******************************************************************************* 231 * 232 * Function L2CA_Register 233 * 234 * Description Other layers call this function to register for L2CAP 235 * services. 236 * 237 * Returns PSM to use or zero if error. Typically, the PSM returned 238 * is the same as was passed in, but for an outgoing-only 239 * connection to a dynamic PSM, a "virtual" PSM is returned 240 * and should be used in the calls to L2CA_ConnectReq() and 241 * BTM_SetSecurityLevel(). 242 * 243 ******************************************************************************/ 244 [[nodiscard]] uint16_t L2CA_Register(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, 245 bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info, 246 uint16_t my_mtu, uint16_t required_remote_mtu, 247 uint16_t sec_level); 248 249 /******************************************************************************* 250 * 251 * Function L2CA_Deregister 252 * 253 * Description Other layers call this function to deregister for L2CAP 254 * services. 255 * 256 * Returns void 257 * 258 ******************************************************************************/ 259 void L2CA_Deregister(uint16_t psm); 260 261 /******************************************************************************* 262 * 263 * Function L2CA_AllocateLePSM 264 * 265 * Description Other layers call this function to find an unused LE PSM for 266 * L2CAP services. 267 * 268 * Returns LE_PSM to use if success. Otherwise returns 0. 269 * 270 ******************************************************************************/ 271 [[nodiscard]] uint16_t L2CA_AllocateLePSM(void); 272 273 /******************************************************************************* 274 * 275 * Function L2CA_FreeLePSM 276 * 277 * Description Free an assigned LE PSM. 278 * 279 * Returns void 280 * 281 ******************************************************************************/ 282 void L2CA_FreeLePSM(uint16_t psm); 283 284 [[nodiscard]] uint16_t L2CA_ConnectReqWithSecurity(uint16_t psm, const RawAddress& p_bd_addr, 285 uint16_t sec_level); 286 /******************************************************************************* 287 * 288 * Function L2CA_ConnectReq 289 * 290 * Description Higher layers call this function to create an L2CAP 291 * connection. 292 * Note that the connection is not established at this time, 293 * but connection establishment gets started. The callback 294 * will be invoked when connection establishes or fails. 295 * 296 * Returns the CID of the connection, or 0 if it failed to start 297 * 298 ******************************************************************************/ 299 [[nodiscard]] uint16_t L2CA_ConnectReq(uint16_t psm, const RawAddress& p_bd_addr); 300 301 /******************************************************************************* 302 * 303 * Function L2CA_RegisterLECoc 304 * 305 * Description Other layers call this function to register for L2CAP 306 * Connection Oriented Channel. 307 * 308 * Returns PSM to use or zero if error. Typically, the PSM returned 309 * is the same as was passed in, but for an outgoing-only 310 * connection to a dynamic PSM, a "virtual" PSM is returned 311 * and should be used in the calls to L2CA_ConnectLECocReq() 312 * and BTM_SetSecurityLevel(). 313 * 314 ******************************************************************************/ 315 [[nodiscard]] uint16_t L2CA_RegisterLECoc(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, 316 uint16_t sec_level, tL2CAP_LE_CFG_INFO cfg); 317 318 /******************************************************************************* 319 * 320 * Function L2CA_DeregisterLECoc 321 * 322 * Description Other layers call this function to deregister for L2CAP 323 * Connection Oriented Channel. 324 * 325 * Returns void 326 * 327 ******************************************************************************/ 328 void L2CA_DeregisterLECoc(uint16_t psm); 329 330 /******************************************************************************* 331 * 332 * Function L2CA_ConnectLECocReq 333 * 334 * Description Higher layers call this function to create an L2CAP LE COC. 335 * Note that the connection is not established at this time, 336 * but connection establishment gets started. The callback 337 * will be invoked when connection establishes or fails. 338 * 339 * Returns the CID of the connection, or 0 if it failed to start 340 * 341 ******************************************************************************/ 342 [[nodiscard]] uint16_t L2CA_ConnectLECocReq(uint16_t psm, const RawAddress& p_bd_addr, 343 tL2CAP_LE_CFG_INFO* p_cfg, uint16_t sec_level); 344 345 /******************************************************************************* 346 * 347 * Function L2CA_GetPeerLECocConfig 348 * 349 * Description Get peers configuration for LE Connection Oriented Channel. 350 * 351 * Return value: true if peer is connected 352 * 353 ******************************************************************************/ 354 [[nodiscard]] bool L2CA_GetPeerLECocConfig(uint16_t lcid, tL2CAP_LE_CFG_INFO* peer_cfg); 355 356 /******************************************************************************* 357 * 358 * Function L2CA_GetPeerLECocCredit 359 * 360 * Description Get peers current credit for LE Connection Oriented 361 * Channel. 362 * 363 * Return value: Number of the peer current credit 364 * 365 ******************************************************************************/ 366 [[nodiscard]] uint16_t L2CA_GetPeerLECocCredit(const RawAddress& bd_addr, uint16_t lcid); 367 368 /******************************************************************************* 369 * 370 * Function L2CA_ReconfigCreditBasedConnsReq 371 * 372 * Description Start reconfigure procedure on Connection Oriented Channel. 373 * 374 * Return value: true if peer is connected 375 * 376 ******************************************************************************/ 377 [[nodiscard]] bool L2CA_ReconfigCreditBasedConnsReq(const RawAddress& bd_addr, 378 std::vector<uint16_t>& lcids, 379 tL2CAP_LE_CFG_INFO* p_cfg); 380 381 /******************************************************************************* 382 * 383 * Function L2CA_ConnectCreditBasedReq 384 * 385 * Description With this function L2CAP will initiate setup of up to 5 credit 386 * based connections for given psm using provided configuration. 387 * L2CAP will notify user on the connection result, by calling 388 * pL2CA_CreditBasedConnectCfm_Cb for each cid with a result. 389 * 390 * Return value: vector of allocated local cids for the connection 391 * 392 ******************************************************************************/ 393 394 [[nodiscard]] std::vector<uint16_t> L2CA_ConnectCreditBasedReq(uint16_t psm, 395 const RawAddress& p_bd_addr, 396 tL2CAP_LE_CFG_INFO* p_cfg); 397 398 /******************************************************************************* 399 * 400 * Function L2CA_ConnectCreditBasedRsp 401 * 402 * Description Response for the pL2CA_CreditBasedConnectInd_Cb which is the 403 * indication for peer requesting credit based connection. 404 * 405 * Return value: true if peer is connected 406 * 407 ******************************************************************************/ 408 [[nodiscard]] bool L2CA_ConnectCreditBasedRsp(const RawAddress& p_bd_addr, uint8_t id, 409 std::vector<uint16_t>& accepted_lcids, 410 tL2CAP_LE_RESULT_CODE result, 411 tL2CAP_LE_CFG_INFO* p_cfg); 412 413 /******************************************************************************* 414 * 415 * Function L2CA_DisconnectReq 416 * 417 * Description Higher layers call this function to disconnect a channel. 418 * 419 * Returns true if disconnect sent, else false 420 * 421 ******************************************************************************/ 422 [[nodiscard]] bool L2CA_DisconnectReq(uint16_t cid); 423 424 [[nodiscard]] bool L2CA_DisconnectLECocReq(uint16_t cid); 425 426 /******************************************************************************* 427 * 428 * Function L2CA_DataWrite 429 * 430 * Description Higher layers call this function to write data. 431 * 432 * Returns tL2CAP_DW_RESULT::L2CAP_DW_SUCCESS, if data accepted, else 433 * false 434 * tL2CAP_DW_RESULT::L2CAP_DW_CONGESTED, if data accepted and 435 * the channel is congested 436 * tL2CAP_DW_RESULT::L2CAP_DW_FAILED, if error 437 * 438 ******************************************************************************/ 439 [[nodiscard]] tL2CAP_DW_RESULT L2CA_DataWrite(uint16_t cid, BT_HDR* p_data); 440 441 [[nodiscard]] tL2CAP_DW_RESULT L2CA_LECocDataWrite(uint16_t cid, BT_HDR* p_data); 442 443 /******************************************************************************* 444 * 445 * Function L2CA_GetRemoteChannelId 446 * 447 * Description Given a local channel identifier, |lcid|, this function 448 * returns the bound remote channel identifier, |rcid|. If 449 * |lcid| is not known or is invalid, this function returns 450 * false and does not modify the value pointed at by |rcid|. 451 * 452 * Parameters: lcid: Local CID 453 * rcid: Pointer to remote CID must NOT be nullptr 454 * 455 * Return value: true if rcid lookup was successful 456 * 457 ******************************************************************************/ 458 [[nodiscard]] bool L2CA_GetRemoteChannelId(uint16_t lcid, uint16_t* rcid); 459 460 /******************************************************************************* 461 * 462 * Function L2CA_SetIdleTimeoutByBdAddr 463 * 464 * Description Higher layers call this function to set the idle timeout for 465 * a connection. The "idle timeout" is the amount of time that 466 * a connection can remain up with no L2CAP channels on it. 467 * A timeout of zero means that the connection will be torn 468 * down immediately when the last channel is removed. 469 * A timeout of 0xFFFF means no timeout. Values are in seconds. 470 * A bd_addr is the remote BD address. If bd_addr = 471 * RawAddress::kAny, then the idle timeouts for all active 472 * l2cap links will be changed. 473 * 474 * Returns true if command succeeded, false if failed 475 * 476 * NOTE This timeout applies to all logical channels active on the 477 * ACL link. 478 ******************************************************************************/ 479 [[nodiscard]] bool L2CA_SetIdleTimeoutByBdAddr(const RawAddress& bd_addr, uint16_t timeout, 480 tBT_TRANSPORT transport); 481 482 /******************************************************************************* 483 * 484 * Function L2CA_FlushChannel 485 * 486 * Description This function flushes none, some or all buffers queued up 487 * for xmission for a particular CID. If called with 488 * L2CAP_FLUSH_CHANS_GET (0), it simply returns the number 489 * of buffers queued for that CID L2CAP_FLUSH_CHANS_ALL (0xffff) 490 * flushes all buffers. All other values specifies the maximum 491 * buffers to flush. 492 * 493 * Returns Number of buffers left queued for that CID 494 * 495 ******************************************************************************/ 496 [[nodiscard]] uint16_t L2CA_FlushChannel(uint16_t lcid, uint16_t num_to_flush); 497 498 /******************************************************************************* 499 * 500 * Function L2CA_UseLatencyMode 501 * 502 * Description Sets use latency mode for an ACL channel. 503 * 504 * Returns true if a valid channel, else false 505 * 506 ******************************************************************************/ 507 [[nodiscard]] bool L2CA_UseLatencyMode(const RawAddress& bd_addr, bool use_latency_mode); 508 509 /******************************************************************************* 510 * 511 * Function L2CA_SetAclPriority 512 * 513 * Description Sets the transmission priority for an ACL channel. 514 * (For initial implementation only two values are valid. 515 * L2CAP_PRIORITY_NORMAL and L2CAP_PRIORITY_HIGH). 516 * 517 * Returns true if a valid channel, else false 518 * 519 ******************************************************************************/ 520 [[nodiscard]] bool L2CA_SetAclPriority(const RawAddress& bd_addr, tL2CAP_PRIORITY priority); 521 522 /******************************************************************************* 523 * 524 * Function L2CA_SetAclLatency 525 * 526 * Description Sets the transmission latency for a channel. 527 * 528 * Returns true if a valid channel, else false 529 * 530 ******************************************************************************/ 531 [[nodiscard]] bool L2CA_SetAclLatency(const RawAddress& bd_addr, tL2CAP_LATENCY latency); 532 533 /******************************************************************************* 534 * 535 * Function L2CA_SetTxPriority 536 * 537 * Description Sets the transmission priority for a channel. (FCR Mode) 538 * 539 * Returns true if a valid channel, else false 540 * 541 ******************************************************************************/ 542 [[nodiscard]] bool L2CA_SetTxPriority(uint16_t cid, tL2CAP_CHNL_PRIORITY priority); 543 544 /******************************************************************************* 545 * 546 * Function L2CA_SetChnlFlushability 547 * 548 * Description Higher layers call this function to set a channels 549 * flushability flags 550 * 551 * Returns true if CID found, else false 552 * 553 ******************************************************************************/ 554 [[nodiscard]] bool L2CA_SetChnlFlushability(uint16_t cid, bool is_flushable); 555 556 /******************************************************************************* 557 * 558 * Function L2CA_GetPeerFeatures 559 * 560 * Description Get a peers features and fixed channel map 561 * 562 * Parameters: BD address of the peer 563 * Pointers to features and channel mask storage area 564 * 565 * Return value: true if peer is connected 566 * 567 ******************************************************************************/ 568 [[nodiscard]] bool L2CA_GetPeerFeatures(const RawAddress& bd_addr, uint32_t* p_ext_feat, 569 uint8_t* p_chnl_mask); 570 571 /******************************************************************************* 572 * 573 * Fixed Channel callback prototypes 574 * 575 ******************************************************************************/ 576 577 /* Fixed channel connected and disconnected. Parameters are 578 * channel 579 * BD Address of remote 580 * true if channel is connected, false if disconnected 581 * Reason for connection failure 582 * transport : physical transport, BR/EDR or LE 583 */ 584 typedef void(tL2CA_FIXED_CHNL_CB)(uint16_t, const RawAddress&, bool, uint16_t, tBT_TRANSPORT); 585 586 /* Signalling data received. Parameters are 587 * channel 588 * BD Address of remote 589 * Pointer to buffer with data 590 */ 591 typedef void(tL2CA_FIXED_DATA_CB)(uint16_t, const RawAddress&, BT_HDR*); 592 593 /* Congestion status callback protype. This callback is optional. If 594 * an application tries to send data when the transmit queue is full, 595 * the data will anyways be dropped. The parameter is: 596 * remote BD_ADDR 597 * true if congested, false if uncongested 598 */ 599 typedef void(tL2CA_FIXED_CONGESTION_STATUS_CB)(const RawAddress&, bool); 600 601 /******************************************************************************* 602 * 603 * Function L2CA_RegisterFixedChannel 604 * 605 * Description Register a fixed channel. 606 * 607 * Parameters: Fixed Channel # 608 * Channel Callbacks and config 609 * 610 * Return value: true if registered OK 611 * 612 ******************************************************************************/ 613 [[nodiscard]] bool L2CA_RegisterFixedChannel(uint16_t fixed_cid, tL2CAP_FIXED_CHNL_REG* p_freg); 614 615 /******************************************************************************* 616 * 617 * Function L2CA_ConnectFixedChnl 618 * 619 * Description Connect an fixed signalling channel to a remote device. 620 * 621 * Parameters: Fixed CID 622 * BD Address of remote 623 * 624 * Return value: true if connection started 625 * 626 ******************************************************************************/ 627 [[nodiscard]] bool L2CA_ConnectFixedChnl(uint16_t fixed_cid, const RawAddress& bd_addr); 628 629 /******************************************************************************* 630 * 631 * Function L2CA_SendFixedChnlData 632 * 633 * Description Write data on a fixed signalling channel. 634 * 635 * Parameters: Fixed CID 636 * BD Address of remote 637 * Pointer to buffer of type BT_HDR 638 * 639 * Return value tL2CAP_DW_RESULT::L2CAP_DW_SUCCESS, if data accepted 640 * tL2CAP_DW_RESULT::L2CAP_DW_FAILED, if error 641 * 642 ******************************************************************************/ 643 [[nodiscard]] tL2CAP_DW_RESULT L2CA_SendFixedChnlData(uint16_t fixed_cid, const RawAddress& rem_bda, 644 BT_HDR* p_buf); 645 646 /******************************************************************************* 647 * 648 * Function L2CA_RemoveFixedChnl 649 * 650 * Description Remove a fixed channel to a remote device. 651 * 652 * Parameters: Fixed CID 653 * BD Address of remote 654 * 655 * Return value: true if channel removed or marked for removal 656 * 657 ******************************************************************************/ 658 [[nodiscard]] bool L2CA_RemoveFixedChnl(uint16_t fixed_cid, const RawAddress& rem_bda); 659 660 /******************************************************************************* 661 * 662 * Function L2CA_SetLeGattTimeout 663 * 664 * Description Higher layers call this function to set the idle timeout for 665 * a fixed channel. The "idle timeout" is the amount of time 666 * that a connection can remain up with no L2CAP channels on 667 * it. A timeout of zero means that the connection will be torn 668 * down immediately when the last channel is removed. 669 * A timeout of 0xFFFF means no timeout. Values are in seconds. 670 * A bd_addr is the remote BD address. If bd_addr = 671 * RawAddress::kAny, then the idle timeouts for all active 672 * l2cap links will be changed. 673 * 674 * Returns true if command succeeded, false if failed 675 * 676 ******************************************************************************/ 677 [[nodiscard]] bool L2CA_SetLeGattTimeout(const RawAddress& rem_bda, uint16_t idle_tout); 678 679 [[nodiscard]] bool L2CA_MarkLeLinkAsActive(const RawAddress& rem_bda); 680 681 [[nodiscard]] bool L2CA_UpdateBleConnParams(const RawAddress& rem_bda, uint16_t min_int, 682 uint16_t max_int, uint16_t latency, uint16_t timeout, 683 uint16_t min_ce_len, uint16_t max_ce_len); 684 685 /* When called with lock=true, LE connection parameters will be locked on 686 * fastest value, and we won't accept request to change it from remote. When 687 * called with lock=false, parameters are relaxed. 688 */ 689 void L2CA_LockBleConnParamsForServiceDiscovery(const RawAddress& rem_bda, bool lock); 690 691 /* When called with lock=true, LE connection parameters will be locked on 692 * fastest value, and we won't accept request to change it from remote. When 693 * called with lock=false, parameters are relaxed. 694 */ 695 void L2CA_LockBleConnParamsForProfileConnection(const RawAddress& rem_bda, bool lock); 696 697 /******************************************************************************* 698 * 699 * Function L2CA_GetBleConnRole 700 * 701 * Description This function returns the connection role. 702 * 703 * Returns link role. 704 * 705 ******************************************************************************/ 706 void L2CA_Consolidate(const RawAddress& identity_addr, const RawAddress& rpa); 707 [[nodiscard]] tHCI_ROLE L2CA_GetBleConnRole(const RawAddress& bd_addr); 708 709 void L2CA_AdjustConnectionIntervals(uint16_t* min_interval, uint16_t* max_interval, 710 uint16_t floor_interval); 711 712 void L2CA_SetEcosystemBaseInterval(uint32_t base_interval); 713 714 /** 715 * Check whether an ACL or LE link to the remote device is established 716 */ 717 [[nodiscard]] bool L2CA_IsLinkEstablished(const RawAddress& bd_addr, tBT_TRANSPORT transport); 718 719 /******************************************************************************* 720 * 721 * Function L2CA_SetDefaultSubrate 722 * 723 * Description BLE Set Default Subrate. 724 * 725 * Parameters: Subrate parameters 726 * 727 * Return value: void 728 * 729 ******************************************************************************/ 730 void L2CA_SetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency, 731 uint16_t cont_num, uint16_t timeout); 732 733 /******************************************************************************* 734 * 735 * Function L2CA_SubrateRequest 736 * 737 * Description BLE Subrate request. 738 * 739 * Parameters: Subrate parameters 740 * 741 * Return value: true if update started 742 * 743 ******************************************************************************/ 744 [[nodiscard]] bool L2CA_SubrateRequest(const RawAddress& rem_bda, uint16_t subrate_min, 745 uint16_t subrate_max, uint16_t max_latency, 746 uint16_t cont_num, uint16_t timeout); 747 748 /******************************************************************************* 749 ** 750 ** Function L2CA_SetMediaStreamChannel 751 ** 752 ** Description This function is called to set/reset the ccb of active media 753 ** streaming channel 754 ** 755 ** Parameters: local_media_cid: The local cid provided to A2DP to be used 756 ** for streaming 757 ** status: The status of media streaming on this channel 758 ** 759 ** Returns void 760 ** 761 *******************************************************************************/ 762 void L2CA_SetMediaStreamChannel(uint16_t local_media_cid, bool status); 763 764 /******************************************************************************* 765 ** 766 ** Function L2CA_isMediaChannel 767 ** 768 ** Description This function returns if the channel id passed as parameter 769 ** is an A2DP streaming channel 770 ** 771 ** Parameters: handle: Connection handle with the remote device 772 ** channel_id: Channel ID 773 ** is_local_cid: Signifies if the channel id passed is local 774 ** cid or remote cid (true if local, remote otherwise) 775 ** 776 ** Returns bool 777 ** 778 *******************************************************************************/ 779 [[nodiscard]] bool L2CA_isMediaChannel(uint16_t handle, uint16_t channel_id, bool is_local_cid); 780 781 /******************************************************************************* 782 ** 783 ** Function L2CA_GetAclHandle 784 ** 785 ** Description Given a local channel identifier, |lcid|, this function 786 ** returns the handle of the corresponding ACL connection, |acl_handle|. If 787 ** |lcid| is not known or is invalid, this function returns false and does not 788 ** modify the value pointed at by |acl_handle|. 789 ** 790 ** Parameters: lcid: Local CID 791 ** acl_handle: Pointer to ACL handle must NOT be nullptr 792 ** 793 ** Returns true if acl_handle lookup was successful 794 ** 795 ******************************************************************************/ 796 [[nodiscard]] bool L2CA_GetAclHandle(uint16_t lcid, uint16_t* acl_handle); 797