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