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 #pragma once 19 20 #include <bluetooth/log.h> 21 #include <stdbool.h> 22 23 #include <cstdint> 24 #include <vector> 25 26 #include "stack/include/bt_hdr.h" 27 #include "stack/include/l2cap_interface.h" 28 #include "types/bt_transport.h" 29 #include "types/hci_role.h" 30 #include "types/raw_address.h" 31 32 namespace bluetooth { 33 namespace stack { 34 namespace l2cap { 35 36 class Impl : public Interface { 37 public: 38 virtual ~Impl() = default; 39 40 // Lifecycle methods to register BR/EDR l2cap services 41 [[nodiscard]] uint16_t L2CA_Register(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, 42 bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info, 43 uint16_t my_mtu, uint16_t required_remote_mtu, 44 uint16_t sec_level) override; 45 [[nodiscard]] uint16_t L2CA_RegisterWithSecurity(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, 46 bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info, 47 uint16_t my_mtu, uint16_t required_remote_mtu, 48 uint16_t sec_level) override; 49 void L2CA_Deregister(uint16_t psm) override; 50 51 // Lifecycle methods to register BLE l2cap services 52 [[nodiscard]] uint16_t L2CA_AllocateLePSM(void) override; 53 void L2CA_FreeLePSM(uint16_t psm) override; 54 55 [[nodiscard]] uint16_t L2CA_RegisterLECoc(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info, 56 uint16_t sec_level, tL2CAP_LE_CFG_INFO cfg) override; 57 void L2CA_DeregisterLECoc(uint16_t psm) override; 58 59 // Methods used for both BR/EDR and BLE 60 [[nodiscard]] bool L2CA_IsLinkEstablished(const RawAddress& bd_addr, 61 tBT_TRANSPORT transport) override; 62 [[nodiscard]] bool L2CA_SetIdleTimeoutByBdAddr(const RawAddress& bd_addr, uint16_t timeout, 63 tBT_TRANSPORT transport) override; 64 [[nodiscard]] bool L2CA_GetRemoteChannelId(uint16_t lcid, uint16_t* rcid) override; 65 66 // Connection methods to configure and connect to peer over BR/EDR ACL 67 [[nodiscard]] uint16_t L2CA_ConnectReq(uint16_t psm, const RawAddress& bd_addr) override; 68 [[nodiscard]] uint16_t L2CA_ConnectReqWithSecurity(uint16_t psm, const RawAddress& bd_addr, 69 uint16_t sec_level) override; 70 [[nodiscard]] bool L2CA_SetAclLatency(const RawAddress& bd_addr, tL2CAP_LATENCY latency) override; 71 [[nodiscard]] bool L2CA_UseLatencyMode(const RawAddress& bd_addr, bool use_latency_mode) override; 72 [[nodiscard]] bool L2CA_GetPeerFeatures(const RawAddress& bd_addr, uint32_t* p_ext_feat, 73 uint8_t* p_chnl_mask) override; 74 [[nodiscard]] bool L2CA_SetAclPriority(const RawAddress& bd_addr, 75 tL2CAP_PRIORITY priority) override; 76 void L2CA_SetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency, 77 uint16_t cont_num, uint16_t timeout) override; 78 void L2CA_AdjustConnectionIntervals(uint16_t* min_interval, uint16_t* max_interval, 79 uint16_t floor_interval) override; 80 void L2CA_SetEcosystemBaseInterval(uint32_t base_interval) override; 81 82 [[nodiscard]] bool L2CA_SubrateRequest(const RawAddress& bd_addr, uint16_t subrate_min, 83 uint16_t subrate_max, uint16_t max_latency, 84 uint16_t cont_num, uint16_t timeout) override; 85 [[nodiscard]] uint16_t L2CA_FlushChannel(uint16_t lcid, uint16_t num_to_flush) override; 86 [[nodiscard]] bool L2CA_SetTxPriority(uint16_t cid, tL2CAP_CHNL_PRIORITY priority) override; 87 [[nodiscard]] bool L2CA_SetChnlFlushability(uint16_t cid, bool is_flushable) override; 88 89 // Connection methods to configure and connect to peer over BLE ACL 90 [[nodiscard]] uint16_t L2CA_ConnectLECocReq(uint16_t psm, const RawAddress& bd_addr, 91 tL2CAP_LE_CFG_INFO* p_cfg, 92 uint16_t sec_level) override; 93 [[nodiscard]] std::vector<uint16_t> L2CA_ConnectCreditBasedReq( 94 uint16_t psm, const RawAddress& bd_addr, tL2CAP_LE_CFG_INFO* p_cfg) override; 95 [[nodiscard]] bool L2CA_ConnectCreditBasedRsp(const RawAddress& bd_addr, uint8_t id, 96 std::vector<uint16_t>& accepted_lcids, 97 tL2CAP_LE_RESULT_CODE result, 98 tL2CAP_LE_CFG_INFO* p_cfg) override; 99 [[nodiscard]] uint16_t L2CA_GetPeerLECocCredit(const RawAddress& bd_addr, uint16_t lcid) override; 100 [[nodiscard]] bool L2CA_ReconfigCreditBasedConnsReq(const RawAddress& bd_addr, 101 std::vector<uint16_t>& lcids, 102 tL2CAP_LE_CFG_INFO* p_cfg) override; 103 [[nodiscard]] bool L2CA_UpdateBleConnParams(const RawAddress& bd_addr, uint16_t min_int, 104 uint16_t max_int, uint16_t latency, uint16_t timeout, 105 uint16_t min_ce_len, uint16_t max_ce_len) override; 106 void L2CA_LockBleConnParamsForServiceDiscovery(const RawAddress& bd_addr, bool lock) override; 107 void L2CA_LockBleConnParamsForProfileConnection(const RawAddress& bd_addr, bool lock) override; 108 [[nodiscard]] tHCI_ROLE L2CA_GetBleConnRole(const RawAddress& bd_addr) override; 109 [[nodiscard]] bool L2CA_SetLeGattTimeout(const RawAddress& bd_addr, uint16_t idle_tout) override; 110 [[nodiscard]] bool L2CA_MarkLeLinkAsActive(const RawAddress& bd_addr) override; 111 [[nodiscard]] bool L2CA_GetPeerLECocConfig(uint16_t lcid, tL2CAP_LE_CFG_INFO* peer_cfg) override; 112 // Method to consolidate two BLE addresses into a single device 113 void L2CA_Consolidate(const RawAddress& identity_addr, const RawAddress& rpa) override; 114 115 // Disconnect methods an active connection for both BR/EDR and BLE 116 [[nodiscard]] bool L2CA_DisconnectReq(uint16_t cid) override; 117 [[nodiscard]] bool L2CA_DisconnectLECocReq(uint16_t cid) override; 118 119 // Data write methods for both BR/EDR and BLE 120 [[nodiscard]] tL2CAP_DW_RESULT L2CA_DataWrite(uint16_t cid, BT_HDR* p_data) override; 121 [[nodiscard]] tL2CAP_DW_RESULT L2CA_LECocDataWrite(uint16_t cid, BT_HDR* p_data) override; 122 123 // Fixed channel methods 124 [[nodiscard]] bool L2CA_RegisterFixedChannel(uint16_t fixed_cid, 125 tL2CAP_FIXED_CHNL_REG* p_freg) override; 126 [[nodiscard]] bool L2CA_ConnectFixedChnl(uint16_t fixed_cid, const RawAddress& bd_addr) override; 127 [[nodiscard]] tL2CAP_DW_RESULT L2CA_SendFixedChnlData(uint16_t fixed_cid, 128 const RawAddress& bd_addr, 129 BT_HDR* p_buf) override; 130 [[nodiscard]] bool L2CA_RemoveFixedChnl(uint16_t fixed_cid, const RawAddress& bd_addr) override; 131 132 // Media methods 133 void L2CA_SetMediaStreamChannel(uint16_t local_media_cid, bool status) override; 134 [[nodiscard]] bool L2CA_isMediaChannel(uint16_t handle, uint16_t channel_id, 135 bool is_local_cid) override; 136 137 [[nodiscard]] bool L2CA_GetAclHandle(uint16_t lcid, uint16_t* acl_handle) override; 138 }; 139 140 } // namespace l2cap 141 } // namespace stack 142 } // namespace bluetooth 143