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 "bt_target.h" 30 #include "hcidefs.h" 31 #include "l2cdefs.h" 32 33 /***************************************************************************** 34 * Constants 35 ****************************************************************************/ 36 37 /* Define the minimum offset that L2CAP needs in a buffer. This is made up of 38 * HCI type(1), len(2), handle(2), L2CAP len(2) and CID(2) => 9 39 */ 40 #define L2CAP_MIN_OFFSET 13 /* plus control(2), SDU length(2) */ 41 42 #define L2CAP_LCC_SDU_LENGTH 2 43 #define L2CAP_LCC_OFFSET \ 44 (L2CAP_MIN_OFFSET + L2CAP_LCC_SDU_LENGTH) /* plus SDU length(2) */ 45 46 #define L2CAP_FCS_LENGTH 2 47 48 /* ping result codes */ 49 #define L2CAP_PING_RESULT_OK 0 /* Ping reply received OK */ 50 #define L2CAP_PING_RESULT_NO_LINK 1 /* Link could not be setup */ 51 #define L2CAP_PING_RESULT_NO_RESP 2 /* Remote L2CAP did not reply */ 52 53 /* result code for L2CA_DataWrite() */ 54 #define L2CAP_DW_FAILED false 55 #define L2CAP_DW_SUCCESS true 56 #define L2CAP_DW_CONGESTED 2 57 58 /* Values for priority parameter to L2CA_SetAclPriority */ 59 #define L2CAP_PRIORITY_NORMAL 0 60 #define L2CAP_PRIORITY_HIGH 1 61 62 /* Values for priority parameter to L2CA_SetTxPriority */ 63 #define L2CAP_CHNL_PRIORITY_HIGH 0 64 #define L2CAP_CHNL_PRIORITY_MEDIUM 1 65 #define L2CAP_CHNL_PRIORITY_LOW 2 66 67 typedef uint8_t tL2CAP_CHNL_PRIORITY; 68 69 /* Values for Tx/Rx data rate parameter to L2CA_SetChnlDataRate */ 70 #define L2CAP_CHNL_DATA_RATE_HIGH 3 71 #define L2CAP_CHNL_DATA_RATE_MEDIUM 2 72 #define L2CAP_CHNL_DATA_RATE_LOW 1 73 #define L2CAP_CHNL_DATA_RATE_NO_TRAFFIC 0 74 75 typedef uint8_t tL2CAP_CHNL_DATA_RATE; 76 77 /* Data Packet Flags (bits 2-15 are reserved) */ 78 /* layer specific 14-15 bits are used for FCR SAR */ 79 #define L2CAP_FLUSHABLE_MASK 0x0003 80 #define L2CAP_FLUSHABLE_CH_BASED 0x0000 81 #define L2CAP_FLUSHABLE_PKT 0x0001 82 #define L2CAP_NON_FLUSHABLE_PKT 0x0002 83 84 /* L2CA_FlushChannel num_to_flush definitions */ 85 #define L2CAP_FLUSH_CHANS_ALL 0xffff 86 #define L2CAP_FLUSH_CHANS_GET 0x0000 87 88 /* set this bit to allow switch at create conn */ 89 #define L2CAP_ROLE_ALLOW_SWITCH 0x80 90 /* set this bit to disallow switch at create conn */ 91 #define L2CAP_ROLE_DISALLOW_SWITCH 0x40 92 #define L2CAP_ROLE_CHECK_SWITCH 0xC0 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 /***************************************************************************** 111 * Type Definitions 112 ****************************************************************************/ 113 114 typedef struct { 115 #define L2CAP_FCR_BASIC_MODE 0x00 116 #define L2CAP_FCR_ERTM_MODE 0x03 117 #define L2CAP_FCR_STREAM_MODE 0x04 118 #define L2CAP_FCR_LE_COC_MODE 0x05 119 120 uint8_t mode; 121 122 uint8_t tx_win_sz; 123 uint8_t max_transmit; 124 uint16_t rtrans_tout; 125 uint16_t mon_tout; 126 uint16_t mps; 127 } tL2CAP_FCR_OPTS; 128 129 /* Define a structure to hold the configuration parameters. Since the 130 * parameters are optional, for each parameter there is a boolean to 131 * use to signify its presence or absence. 132 */ 133 typedef struct { 134 uint16_t result; /* Only used in confirm messages */ 135 bool mtu_present; 136 uint16_t mtu; 137 bool qos_present; 138 FLOW_SPEC qos; 139 bool flush_to_present; 140 uint16_t flush_to; 141 bool fcr_present; 142 tL2CAP_FCR_OPTS fcr; 143 bool fcs_present; /* Optionally bypasses FCS checks */ 144 uint8_t fcs; /* '0' if desire is to bypass FCS, otherwise '1' */ 145 bool ext_flow_spec_present; 146 tHCI_EXT_FLOW_SPEC ext_flow_spec; 147 uint16_t flags; /* bit 0: 0-no continuation, 1-continuation */ 148 } tL2CAP_CFG_INFO; 149 150 /* Define a structure to hold the configuration parameter for LE L2CAP 151 * connection oriented channels. 152 */ 153 typedef struct { 154 uint16_t mtu; 155 uint16_t mps; 156 uint16_t credits; 157 } tL2CAP_LE_CFG_INFO; 158 159 /* L2CAP channel configured field bitmap */ 160 #define L2CAP_CH_CFG_MASK_MTU 0x0001 161 #define L2CAP_CH_CFG_MASK_QOS 0x0002 162 #define L2CAP_CH_CFG_MASK_FLUSH_TO 0x0004 163 #define L2CAP_CH_CFG_MASK_FCR 0x0008 164 #define L2CAP_CH_CFG_MASK_FCS 0x0010 165 #define L2CAP_CH_CFG_MASK_EXT_FLOW_SPEC 0x0020 166 167 typedef uint16_t tL2CAP_CH_CFG_BITS; 168 169 /********************************* 170 * Callback Functions Prototypes 171 *********************************/ 172 173 /* Connection indication callback prototype. Parameters are 174 * BD Address of remote 175 * Local CID assigned to the connection 176 * PSM that the remote wants to connect to 177 * Identifier that the remote sent 178 */ 179 typedef void(tL2CA_CONNECT_IND_CB)(const RawAddress&, uint16_t, uint16_t, 180 uint8_t); 181 182 /* Connection confirmation callback prototype. Parameters are 183 * Local CID 184 * Result - 0 = connected, non-zero means failure reason 185 */ 186 typedef void(tL2CA_CONNECT_CFM_CB)(uint16_t, uint16_t); 187 188 /* Connection pending callback prototype. Parameters are 189 * Local CID 190 */ 191 typedef void(tL2CA_CONNECT_PND_CB)(uint16_t); 192 193 /* Configuration indication callback prototype. Parameters are 194 * Local CID assigned to the connection 195 * Pointer to configuration info 196 */ 197 typedef void(tL2CA_CONFIG_IND_CB)(uint16_t, tL2CAP_CFG_INFO*); 198 199 /* Configuration confirm callback prototype. Parameters are 200 * Local CID assigned to the connection 201 * Pointer to configuration info 202 */ 203 typedef void(tL2CA_CONFIG_CFM_CB)(uint16_t, tL2CAP_CFG_INFO*); 204 205 /* Disconnect indication callback prototype. Parameters are 206 * Local CID 207 * Boolean whether upper layer should ack this 208 */ 209 typedef void(tL2CA_DISCONNECT_IND_CB)(uint16_t, bool); 210 211 /* Disconnect confirm callback prototype. Parameters are 212 * Local CID 213 * Result 214 */ 215 typedef void(tL2CA_DISCONNECT_CFM_CB)(uint16_t, uint16_t); 216 217 /* QOS Violation indication callback prototype. Parameters are 218 * BD Address of violating device 219 */ 220 typedef void(tL2CA_QOS_VIOLATION_IND_CB)(const RawAddress&); 221 222 /* Data received indication callback prototype. Parameters are 223 * Local CID 224 * Address of buffer 225 */ 226 typedef void(tL2CA_DATA_IND_CB)(uint16_t, BT_HDR*); 227 228 /* Echo response callback prototype. Note that this is not included in the 229 * registration information, but is passed to L2CAP as part of the API to 230 * actually send an echo request. Parameters are 231 * Result 232 */ 233 typedef void(tL2CA_ECHO_RSP_CB)(uint16_t); 234 235 /* Callback function prototype to pass broadcom specific echo response */ 236 /* to the upper layer */ 237 typedef void(tL2CA_ECHO_DATA_CB)(const RawAddress&, uint16_t, uint8_t*); 238 239 /* Congestion status callback protype. This callback is optional. If 240 * an application tries to send data when the transmit queue is full, 241 * the data will anyways be dropped. The parameter is: 242 * Local CID 243 * true if congested, false if uncongested 244 */ 245 typedef void(tL2CA_CONGESTION_STATUS_CB)(uint16_t, bool); 246 247 /* Callback prototype for number of packets completed events. 248 * This callback notifies the application when Number of Completed Packets 249 * event has been received. 250 * This callback is originally designed for 3DG devices. 251 * The parameter is: 252 * peer BD_ADDR 253 */ 254 typedef void(tL2CA_NOCP_CB)(const RawAddress&); 255 256 /* Transmit complete callback protype. This callback is optional. If 257 * set, L2CAP will call it when packets are sent or flushed. If the 258 * count is 0xFFFF, it means all packets are sent for that CID (eRTM 259 * mode only). The parameters are: 260 * Local CID 261 * Number of SDUs sent or dropped 262 */ 263 typedef void(tL2CA_TX_COMPLETE_CB)(uint16_t, uint16_t); 264 265 /* Callback for receiving credits from the remote device. 266 * |credit_received| parameter represents number of credits received in "LE Flow 267 * Control Credit" packet from the remote. |credit_count| parameter represents 268 * the total available credits, including |credit_received|. 269 */ 270 typedef void(tL2CA_CREDITS_RECEIVED_CB)(uint16_t local_cid, 271 uint16_t credits_received, 272 uint16_t credit_count); 273 274 /* Define the structure that applications use to register with 275 * L2CAP. This structure includes callback functions. All functions 276 * MUST be provided, with the exception of the "connect pending" 277 * callback and "congestion status" callback. 278 */ 279 typedef struct { 280 tL2CA_CONNECT_IND_CB* pL2CA_ConnectInd_Cb; 281 tL2CA_CONNECT_CFM_CB* pL2CA_ConnectCfm_Cb; 282 tL2CA_CONNECT_PND_CB* pL2CA_ConnectPnd_Cb; 283 tL2CA_CONFIG_IND_CB* pL2CA_ConfigInd_Cb; 284 tL2CA_CONFIG_CFM_CB* pL2CA_ConfigCfm_Cb; 285 tL2CA_DISCONNECT_IND_CB* pL2CA_DisconnectInd_Cb; 286 tL2CA_DISCONNECT_CFM_CB* pL2CA_DisconnectCfm_Cb; 287 tL2CA_QOS_VIOLATION_IND_CB* pL2CA_QoSViolationInd_Cb; 288 tL2CA_DATA_IND_CB* pL2CA_DataInd_Cb; 289 tL2CA_CONGESTION_STATUS_CB* pL2CA_CongestionStatus_Cb; 290 tL2CA_TX_COMPLETE_CB* pL2CA_TxComplete_Cb; 291 tL2CA_CREDITS_RECEIVED_CB* pL2CA_CreditsReceived_Cb; 292 } tL2CAP_APPL_INFO; 293 294 /* Define the structure that applications use to create or accept 295 * connections with enhanced retransmission mode. 296 */ 297 typedef struct { 298 uint8_t preferred_mode; 299 uint8_t allowed_modes; 300 uint16_t user_rx_buf_size; 301 uint16_t user_tx_buf_size; 302 uint16_t fcr_rx_buf_size; 303 uint16_t fcr_tx_buf_size; 304 305 } tL2CAP_ERTM_INFO; 306 307 /***************************************************************************** 308 * External Function Declarations 309 ****************************************************************************/ 310 311 /******************************************************************************* 312 * 313 * Function L2CA_Register 314 * 315 * Description Other layers call this function to register for L2CAP 316 * services. 317 * 318 * Returns PSM to use or zero if error. Typically, the PSM returned 319 * is the same as was passed in, but for an outgoing-only 320 * connection to a dynamic PSM, a "virtual" PSM is returned 321 * and should be used in the calls to L2CA_ConnectReq() and 322 * BTM_SetSecurityLevel(). 323 * 324 ******************************************************************************/ 325 extern uint16_t L2CA_Register(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info, 326 bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info, 327 uint16_t required_mtu); 328 329 /******************************************************************************* 330 * 331 * Function L2CA_Deregister 332 * 333 * Description Other layers call this function to deregister for L2CAP 334 * services. 335 * 336 * Returns void 337 * 338 ******************************************************************************/ 339 extern void L2CA_Deregister(uint16_t psm); 340 341 /******************************************************************************* 342 * 343 * Function L2CA_AllocatePSM 344 * 345 * Description Other layers call this function to find an unused PSM for 346 * L2CAP services. 347 * 348 * Returns PSM to use. 349 * 350 ******************************************************************************/ 351 extern uint16_t L2CA_AllocatePSM(void); 352 353 /******************************************************************************* 354 * 355 * Function L2CA_AllocateLePSM 356 * 357 * Description Other layers call this function to find an unused LE PSM for 358 * L2CAP services. 359 * 360 * Returns LE_PSM to use if success. Otherwise returns 0. 361 * 362 ******************************************************************************/ 363 extern uint16_t L2CA_AllocateLePSM(void); 364 365 /******************************************************************************* 366 * 367 * Function L2CA_FreeLePSM 368 * 369 * Description Free an assigned LE PSM. 370 * 371 * Returns void 372 * 373 ******************************************************************************/ 374 extern void L2CA_FreeLePSM(uint16_t psm); 375 376 /******************************************************************************* 377 * 378 * Function L2CA_ConnectReq 379 * 380 * Description Higher layers call this function to create an L2CAP 381 * connection. 382 * Note that the connection is not established at this time, 383 * but connection establishment gets started. The callback 384 * will be invoked when connection establishes or fails. 385 * 386 * Returns the CID of the connection, or 0 if it failed to start 387 * 388 ******************************************************************************/ 389 extern uint16_t L2CA_ConnectReq(uint16_t psm, const RawAddress& p_bd_addr); 390 391 /******************************************************************************* 392 * 393 * Function L2CA_ConnectRsp 394 * 395 * Description Higher layers call this function to accept an incoming 396 * L2CAP connection, for which they had gotten an connect 397 * indication callback. 398 * 399 * Returns true for success, false for failure 400 * 401 ******************************************************************************/ 402 extern bool L2CA_ConnectRsp(const RawAddress& p_bd_addr, uint8_t id, 403 uint16_t lcid, uint16_t result, uint16_t status); 404 405 /******************************************************************************* 406 * 407 * Function L2CA_ErtmConnectReq 408 * 409 * Description Higher layers call this function to create an L2CAP 410 * connection that needs to use Enhanced Retransmission Mode. 411 * Note that the connection is not established at this time, 412 * but connection establishment gets started. The callback 413 * will be invoked when connection establishes or fails. 414 * 415 * Returns the CID of the connection, or 0 if it failed to start 416 * 417 ******************************************************************************/ 418 extern uint16_t L2CA_ErtmConnectReq(uint16_t psm, const RawAddress& p_bd_addr, 419 tL2CAP_ERTM_INFO* p_ertm_info); 420 421 /******************************************************************************* 422 * 423 * Function L2CA_RegisterLECoc 424 * 425 * Description Other layers call this function to register for L2CAP 426 * Connection Oriented Channel. 427 * 428 * Returns PSM to use or zero if error. Typically, the PSM returned 429 * is the same as was passed in, but for an outgoing-only 430 * connection to a dynamic PSM, a "virtual" PSM is returned 431 * and should be used in the calls to L2CA_ConnectLECocReq() 432 * and BTM_SetSecurityLevel(). 433 * 434 ******************************************************************************/ 435 extern uint16_t L2CA_RegisterLECoc(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info); 436 437 /******************************************************************************* 438 * 439 * Function L2CA_DeregisterLECoc 440 * 441 * Description Other layers call this function to deregister for L2CAP 442 * Connection Oriented Channel. 443 * 444 * Returns void 445 * 446 ******************************************************************************/ 447 extern void L2CA_DeregisterLECoc(uint16_t psm); 448 449 /******************************************************************************* 450 * 451 * Function L2CA_ConnectLECocReq 452 * 453 * Description Higher layers call this function to create an L2CAP LE COC. 454 * Note that the connection is not established at this time, 455 * but connection establishment gets started. The callback 456 * will be invoked when connection establishes or fails. 457 * 458 * Returns the CID of the connection, or 0 if it failed to start 459 * 460 ******************************************************************************/ 461 extern uint16_t L2CA_ConnectLECocReq(uint16_t psm, const RawAddress& p_bd_addr, 462 tL2CAP_LE_CFG_INFO* p_cfg); 463 464 /******************************************************************************* 465 * 466 * Function L2CA_ConnectLECocRsp 467 * 468 * Description Higher layers call this function to accept an incoming 469 * L2CAP LE COC connection, for which they had gotten a connect 470 * indication callback. 471 * 472 * Returns true for success, false for failure 473 * 474 ******************************************************************************/ 475 extern bool L2CA_ConnectLECocRsp(const RawAddress& p_bd_addr, uint8_t id, 476 uint16_t lcid, uint16_t result, 477 uint16_t status, tL2CAP_LE_CFG_INFO* p_cfg); 478 479 /******************************************************************************* 480 * 481 * Function L2CA_GetPeerLECocConfig 482 * 483 * Description Get peers configuration for LE Connection Oriented Channel. 484 * 485 * Return value: true if peer is connected 486 * 487 ******************************************************************************/ 488 extern bool L2CA_GetPeerLECocConfig(uint16_t lcid, 489 tL2CAP_LE_CFG_INFO* peer_cfg); 490 491 /******************************************************************************* 492 * 493 * Function L2CA_ErtmConnectRsp 494 * 495 * Description Higher layers call this function to accept an incoming 496 * L2CAP connection, for which they had gotten an connect 497 * indication callback, and for which the higher layer wants 498 * to use Enhanced Retransmission Mode. 499 * 500 * Returns true for success, false for failure 501 * 502 ******************************************************************************/ 503 extern bool L2CA_ErtmConnectRsp(const RawAddress& p_bd_addr, uint8_t id, 504 uint16_t lcid, uint16_t result, uint16_t status, 505 tL2CAP_ERTM_INFO* p_ertm_info); 506 507 /******************************************************************************* 508 * 509 * Function L2CA_ConfigReq 510 * 511 * Description Higher layers call this function to send configuration. 512 * 513 * Returns true if configuration sent, else false 514 * 515 ******************************************************************************/ 516 extern bool L2CA_ConfigReq(uint16_t cid, tL2CAP_CFG_INFO* p_cfg); 517 518 /******************************************************************************* 519 * 520 * Function L2CA_ConfigRsp 521 * 522 * Description Higher layers call this function to send a configuration 523 * response. 524 * 525 * Returns true if configuration response sent, else false 526 * 527 ******************************************************************************/ 528 extern bool L2CA_ConfigRsp(uint16_t cid, tL2CAP_CFG_INFO* p_cfg); 529 530 /******************************************************************************* 531 * 532 * Function L2CA_DisconnectReq 533 * 534 * Description Higher layers call this function to disconnect a channel. 535 * 536 * Returns true if disconnect sent, else false 537 * 538 ******************************************************************************/ 539 extern bool L2CA_DisconnectReq(uint16_t cid); 540 541 /******************************************************************************* 542 * 543 * Function L2CA_DisconnectRsp 544 * 545 * Description Higher layers call this function to acknowledge the 546 * disconnection of a channel. 547 * 548 * Returns void 549 * 550 ******************************************************************************/ 551 extern bool L2CA_DisconnectRsp(uint16_t cid); 552 553 /******************************************************************************* 554 * 555 * Function L2CA_DataWrite 556 * 557 * Description Higher layers call this function to write data. 558 * 559 * Returns L2CAP_DW_SUCCESS, if data accepted, else false 560 * L2CAP_DW_CONGESTED, if data accepted and the channel is 561 * congested 562 * L2CAP_DW_FAILED, if error 563 * 564 ******************************************************************************/ 565 extern uint8_t L2CA_DataWrite(uint16_t cid, BT_HDR* p_data); 566 567 // Given a local channel identifier, |lcid|, this function returns the bound 568 // remote channel identifier, |rcid|. If 569 // |lcid| is not known or is invalid, this function returns false and does not 570 // modify the value pointed at by |rcid|. |rcid| may be NULL. 571 bool L2CA_GetRemoteCid(uint16_t lcid, uint16_t* rcid); 572 573 /******************************************************************************* 574 * 575 * Function L2CA_SetIdleTimeout 576 * 577 * Description Higher layers call this function to set the idle timeout for 578 * a connection, or for all future connections. The "idle 579 * timeout" is the amount of time that a connection can remain 580 * up with no L2CAP channels on it. A timeout of zero means 581 * that the connection will be torn down immediately when the 582 * last channel is removed. A timeout of 0xFFFF means no 583 * timeout. Values are in seconds. 584 * 585 * Returns true if command succeeded, false if failed 586 * 587 ******************************************************************************/ 588 extern bool L2CA_SetIdleTimeout(uint16_t cid, uint16_t timeout, bool is_global); 589 590 /******************************************************************************* 591 * 592 * Function L2CA_SetIdleTimeoutByBdAddr 593 * 594 * Description Higher layers call this function to set the idle timeout for 595 * a connection. The "idle timeout" is the amount of time that 596 * a connection can remain up with no L2CAP channels on it. 597 * A timeout of zero means that the connection will be torn 598 * down immediately when the last channel is removed. 599 * A timeout of 0xFFFF means no timeout. Values are in seconds. 600 * A bd_addr is the remote BD address. If bd_addr = 601 * RawAddress::kAny, then the idle timeouts for all active 602 * l2cap links will be changed. 603 * 604 * Returns true if command succeeded, false if failed 605 * 606 * NOTE This timeout applies to all logical channels active on the 607 * ACL link. 608 ******************************************************************************/ 609 extern bool L2CA_SetIdleTimeoutByBdAddr(const RawAddress& bd_addr, 610 uint16_t timeout, 611 tBT_TRANSPORT transport); 612 613 /******************************************************************************* 614 * 615 * Function L2CA_SetTraceLevel 616 * 617 * Description This function sets the trace level for L2CAP. If called with 618 * a value of 0xFF, it simply reads the current trace level. 619 * 620 * Returns the new (current) trace level 621 * 622 ******************************************************************************/ 623 extern uint8_t L2CA_SetTraceLevel(uint8_t trace_level); 624 625 /******************************************************************************* 626 * 627 * Function L2CA_SetDesireRole 628 * 629 * Description This function sets the desire role for L2CAP. 630 * If the new role is L2CAP_ROLE_ALLOW_SWITCH, allow switch on 631 * HciCreateConnection. 632 * If the new role is L2CAP_ROLE_DISALLOW_SWITCH, do not allow 633 * switch on HciCreateConnection. 634 * 635 * If the new role is a valid role (HCI_ROLE_MASTER or 636 * HCI_ROLE_SLAVE), the desire role is set to the new value. 637 * Otherwise, it is not changed. 638 * 639 * Returns the new (current) role 640 * 641 ******************************************************************************/ 642 extern uint8_t L2CA_SetDesireRole(uint8_t new_role); 643 644 /******************************************************************************* 645 * 646 * Function L2CA_FlushChannel 647 * 648 * Description This function flushes none, some or all buffers queued up 649 * for xmission for a particular CID. If called with 650 * L2CAP_FLUSH_CHANS_GET (0), it simply returns the number 651 * of buffers queued for that CID L2CAP_FLUSH_CHANS_ALL (0xffff) 652 * flushes all buffers. All other values specifies the maximum 653 * buffers to flush. 654 * 655 * Returns Number of buffers left queued for that CID 656 * 657 ******************************************************************************/ 658 extern uint16_t L2CA_FlushChannel(uint16_t lcid, uint16_t num_to_flush); 659 660 /******************************************************************************* 661 * 662 * Function L2CA_SetAclPriority 663 * 664 * Description Sets the transmission priority for an ACL channel. 665 * (For initial implementation only two values are valid. 666 * L2CAP_PRIORITY_NORMAL and L2CAP_PRIORITY_HIGH). 667 * 668 * Returns true if a valid channel, else false 669 * 670 ******************************************************************************/ 671 extern bool L2CA_SetAclPriority(const RawAddress& bd_addr, uint8_t priority); 672 673 /******************************************************************************* 674 * 675 * Function L2CA_SetTxPriority 676 * 677 * Description Sets the transmission priority for a channel. (FCR Mode) 678 * 679 * Returns true if a valid channel, else false 680 * 681 ******************************************************************************/ 682 extern bool L2CA_SetTxPriority(uint16_t cid, tL2CAP_CHNL_PRIORITY priority); 683 684 /******************************************************************************* 685 * 686 * Function L2CA_SetFlushTimeout 687 * 688 * Description This function set the automatic flush time out in Baseband 689 * for ACL-U packets. 690 * BdAddr : the remote BD address of ACL link. If it is 691 * BT_DB_ANY then the flush time out will be applied 692 * to all ACL link. 693 * FlushTimeout: flush time out in ms 694 * 0x0000 : No automatic flush 695 * L2CAP_NO_RETRANSMISSION : No retransmission 696 * 0x0002 - 0xFFFE : flush time out, if 697 * (flush_tout * 8) + 3 / 5) <= 698 * HCI_MAX_AUTOMATIC_FLUSH_TIMEOUT 699 * (in 625us slot). 700 * Otherwise, return false. 701 * L2CAP_NO_AUTOMATIC_FLUSH : No automatic flush 702 * 703 * Returns true if command succeeded, false if failed 704 * 705 * NOTE This flush timeout applies to all logical channels active on 706 * the ACL link. 707 ******************************************************************************/ 708 extern bool L2CA_SetFlushTimeout(const RawAddress& bd_addr, 709 uint16_t flush_tout); 710 711 /******************************************************************************* 712 * 713 * Function L2CA_SetChnlFlushability 714 * 715 * Description Higher layers call this function to set a channels 716 * flushability flags 717 * 718 * Returns true if CID found, else false 719 * 720 ******************************************************************************/ 721 extern bool L2CA_SetChnlFlushability(uint16_t cid, bool is_flushable); 722 723 /******************************************************************************* 724 * 725 * Function L2CA_GetPeerFeatures 726 * 727 * Description Get a peers features and fixed channel map 728 * 729 * Parameters: BD address of the peer 730 * Pointers to features and channel mask storage area 731 * 732 * Return value: true if peer is connected 733 * 734 ******************************************************************************/ 735 extern bool L2CA_GetPeerFeatures(const RawAddress& bd_addr, 736 uint32_t* p_ext_feat, uint8_t* p_chnl_mask); 737 738 /******************************************************************************* 739 * 740 * Fixed Channel callback prototypes 741 * 742 ******************************************************************************/ 743 744 /* Fixed channel connected and disconnected. Parameters are 745 * channel 746 * BD Address of remote 747 * true if channel is connected, false if disconnected 748 * Reason for connection failure 749 * transport : physical transport, BR/EDR or LE 750 */ 751 typedef void(tL2CA_FIXED_CHNL_CB)(uint16_t, const RawAddress&, bool, uint16_t, 752 tBT_TRANSPORT); 753 754 /* Signalling data received. Parameters are 755 * channel 756 * BD Address of remote 757 * Pointer to buffer with data 758 */ 759 typedef void(tL2CA_FIXED_DATA_CB)(uint16_t, const RawAddress&, BT_HDR*); 760 761 /* Congestion status callback protype. This callback is optional. If 762 * an application tries to send data when the transmit queue is full, 763 * the data will anyways be dropped. The parameter is: 764 * remote BD_ADDR 765 * true if congested, false if uncongested 766 */ 767 typedef void(tL2CA_FIXED_CONGESTION_STATUS_CB)(const RawAddress&, bool); 768 769 /* Fixed channel registration info (the callback addresses and channel config) 770 */ 771 typedef struct { 772 tL2CA_FIXED_CHNL_CB* pL2CA_FixedConn_Cb; 773 tL2CA_FIXED_DATA_CB* pL2CA_FixedData_Cb; 774 tL2CA_FIXED_CONGESTION_STATUS_CB* pL2CA_FixedCong_Cb; 775 776 uint16_t default_idle_tout; 777 tL2CA_TX_COMPLETE_CB* 778 pL2CA_FixedTxComplete_Cb; /* fixed channel tx complete callback */ 779 } tL2CAP_FIXED_CHNL_REG; 780 781 #if (L2CAP_NUM_FIXED_CHNLS > 0) 782 /******************************************************************************* 783 * 784 * Function L2CA_RegisterFixedChannel 785 * 786 * Description Register a fixed channel. 787 * 788 * Parameters: Fixed Channel # 789 * Channel Callbacks and config 790 * 791 * Return value: true if registered OK 792 * 793 ******************************************************************************/ 794 extern bool L2CA_RegisterFixedChannel(uint16_t fixed_cid, 795 tL2CAP_FIXED_CHNL_REG* p_freg); 796 797 /******************************************************************************* 798 * 799 * Function L2CA_ConnectFixedChnl 800 * 801 * Description Connect an fixed signalling channel to a remote device. 802 * 803 * Parameters: Fixed CID 804 * BD Address of remote 805 * 806 * Return value: true if connection started 807 * 808 ******************************************************************************/ 809 extern bool L2CA_ConnectFixedChnl(uint16_t fixed_cid, 810 const RawAddress& bd_addr); 811 extern bool L2CA_ConnectFixedChnl(uint16_t fixed_cid, const RawAddress& bd_addr, 812 uint8_t initiating_phys); 813 814 /******************************************************************************* 815 * 816 * Function L2CA_SendFixedChnlData 817 * 818 * Description Write data on a fixed signalling channel. 819 * 820 * Parameters: Fixed CID 821 * BD Address of remote 822 * Pointer to buffer of type BT_HDR 823 * 824 * Return value L2CAP_DW_SUCCESS, if data accepted 825 * L2CAP_DW_FAILED, if error 826 * 827 ******************************************************************************/ 828 extern uint16_t L2CA_SendFixedChnlData(uint16_t fixed_cid, 829 const RawAddress& rem_bda, 830 BT_HDR* p_buf); 831 832 /******************************************************************************* 833 * 834 * Function L2CA_RemoveFixedChnl 835 * 836 * Description Remove a fixed channel to a remote device. 837 * 838 * Parameters: Fixed CID 839 * BD Address of remote 840 * Idle timeout to use (or 0xFFFF if don't care) 841 * 842 * Return value: true if channel removed 843 * 844 ******************************************************************************/ 845 extern bool L2CA_RemoveFixedChnl(uint16_t fixed_cid, const RawAddress& rem_bda); 846 847 /******************************************************************************* 848 * 849 * Function L2CA_SetFixedChannelTout 850 * 851 * Description Higher layers call this function to set the idle timeout for 852 * a fixed channel. The "idle timeout" is the amount of time 853 * that a connection can remain up with no L2CAP channels on 854 * it. A timeout of zero means that the connection will be torn 855 * down immediately when the last channel is removed. 856 * A timeout of 0xFFFF means no timeout. Values are in seconds. 857 * A bd_addr is the remote BD address. If bd_addr = 858 * RawAddress::kAny, then the idle timeouts for all active 859 * l2cap links will be changed. 860 * 861 * Returns true if command succeeded, false if failed 862 * 863 ******************************************************************************/ 864 extern bool L2CA_SetFixedChannelTout(const RawAddress& rem_bda, 865 uint16_t fixed_cid, uint16_t idle_tout); 866 867 #endif /* (L2CAP_NUM_FIXED_CHNLS > 0) */ 868 869 /******************************************************************************* 870 * 871 * Function L2CA_CancelBleConnectReq 872 * 873 * Description Cancel a pending connection attempt to a BLE device. 874 * 875 * Parameters: BD Address of remote 876 * 877 * Return value: true if connection was cancelled 878 * 879 ******************************************************************************/ 880 extern bool L2CA_CancelBleConnectReq(const RawAddress& rem_bda); 881 882 /******************************************************************************* 883 * 884 * Function L2CA_UpdateBleConnParams 885 * 886 * Description Update BLE connection parameters. 887 * 888 * Parameters: BD Address of remote 889 * 890 * Return value: true if update started 891 * 892 ******************************************************************************/ 893 extern bool L2CA_UpdateBleConnParams(const RawAddress& rem_bdRa, 894 uint16_t min_int, uint16_t max_int, 895 uint16_t latency, uint16_t timeout); 896 extern bool L2CA_UpdateBleConnParams(const RawAddress& rem_bda, 897 uint16_t min_int, uint16_t max_int, 898 uint16_t latency, uint16_t timeout, 899 uint16_t min_ce_len, uint16_t max_ce_len); 900 901 /******************************************************************************* 902 * 903 * Function L2CA_EnableUpdateBleConnParams 904 * 905 * Description Update BLE connection parameters. 906 * 907 * Parameters: BD Address of remote 908 * enable flag 909 * 910 * Return value: true if update started 911 * 912 ******************************************************************************/ 913 extern bool L2CA_EnableUpdateBleConnParams(const RawAddress& rem_bda, 914 bool enable); 915 916 /******************************************************************************* 917 * 918 * Function L2CA_GetBleConnRole 919 * 920 * Description This function returns the connection role. 921 * 922 * Returns link role. 923 * 924 ******************************************************************************/ 925 extern uint8_t L2CA_GetBleConnRole(const RawAddress& bd_addr); 926 927 /******************************************************************************* 928 * 929 * Function L2CA_GetDisconnectReason 930 * 931 * Description This function returns the disconnect reason code. 932 * 933 * Parameters: BD Address of remote 934 * Physical transport for the L2CAP connection (BR/EDR or LE) 935 * 936 * Returns disconnect reason 937 * 938 ******************************************************************************/ 939 extern uint16_t L2CA_GetDisconnectReason(const RawAddress& remote_bda, 940 tBT_TRANSPORT transport); 941 942 extern void L2CA_AdjustConnectionIntervals(uint16_t* min_interval, 943 uint16_t* max_interval, 944 uint16_t floor_interval); 945 946 /** 947 * Update max fixed channel tx data length if applicable 948 */ 949 extern void L2CA_SetLeFixedChannelTxDataLength(const RawAddress& remote_bda, 950 uint16_t fix_cid, 951 uint16_t tx_mtu); 952 953 /** 954 * Check whether an ACL or LE link to the remote device is established 955 */ 956 extern bool L2CA_IsLinkEstablished(const RawAddress& bd_addr, 957 tBT_TRANSPORT transport); 958 959 #endif /* L2C_API_H */ 960