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