1 /* 2 * Copyright 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 18 #include <vector> 19 20 #include "mca_api.h" 21 #include "mcap_test_mdl.h" 22 23 namespace SYSTEM_BT_TOOLS_MCAP_TOOL { 24 25 class McapMcl { 26 public: 27 /** 28 * A controller for a MCAP Communication Link (MCL) 29 * @param mcap_test_interface Underlining interface to Bluetooth stack 30 * @param mcap_handle Parent application handle 31 * @param peer_bd_addr Peer Bluetooth MAC address 32 */ 33 McapMcl(btmcap_test_interface_t* mcap_test_interface, tMCA_HANDLE mcap_handle, 34 const RawAddress& peer_bd_addr); 35 /** 36 * Connect this MCL's control channel 37 * @param ctrl_psm Control channel L2CAP PSM 38 * @param sec_mask Security mask 39 * @return True on success 40 */ 41 bool Connect(uint16_t ctrl_psm, uint16_t sec_mask); 42 /** 43 * Disconnect from control channel 44 * @return 45 */ 46 bool Disconnect(); 47 /** 48 * Close this MCL connection 49 * @return 50 */ 51 bool Close(); 52 /** 53 * Allocate an MCAP Data Link (MDL) object and save to this MCL object 54 * @param mdep_handle MDEP handle for data, MDEP must be prior created 55 * @param mdl_id Desired MDL ID, user supported 56 * @param dep_id Peer MDEP ID 57 * @param cfg Configuration flags 58 * @return True on success 59 */ 60 McapMdl* AllocateMdl(tMCA_DEP mdep_handle, uint16_t mdl_id, uint8_t dep_id, 61 uint8_t cfg); 62 /** 63 * Send CREATE_MDL message to peer device, will allocate an MDL if the MDL for 64 * corresponding MDL ID was not allocated before 65 * @param mdep_handle MDEP handle for data, MDEP must be prior created 66 * @param data_psm Data channel L2CAP PSM 67 * @param mdl_id Desired MDL ID, user supported 68 * @param peer_dep_id Peer MDEP ID 69 * @param cfg Configuration flags 70 * @param should_connect whether we should connect L2CAP immediately 71 * @return True on success 72 */ 73 bool CreateMdl(tMCA_DEP mdep_handle, uint16_t data_psm, uint16_t mdl_id, 74 uint8_t peer_dep_id, uint8_t cfg, bool should_connect); 75 /** 76 * Configure data channel, unblock any pending MDL L2CAP connection requests 77 * @return True on Success 78 */ 79 bool DataChannelConfig(); 80 /** 81 * Respond to CREATE_MDL message received from peer device, will allocate an 82 * MDL if the MDL for corresponding MDL ID was not allocated before 83 * @param mdep_handle MDEP handle for data, MDEP must be prior created 84 * @param mdl_id Desired MDL ID, peer supported 85 * @param my_dep_id My MDEP ID 86 * @param cfg Configuration flags 87 * @return True on success 88 */ 89 bool CreateMdlResponse(tMCA_DEP mdep_handle, uint16_t mdl_id, 90 uint8_t my_dep_id, uint8_t cfg); 91 /** 92 * Send ABORT_MDL request, aborting all pending CREATE_MDL requests 93 * @return 94 */ 95 bool AbortMdl(); 96 /** 97 * Send DELETE_MDL request to remote 98 * @param mdl_id None zero value mdl_id, 0xFFFF for all remote MDLs 99 * @return True on success 100 */ 101 bool DeleteMdl(uint16_t mdl_id); 102 // Simple methods that are self-explanatory 103 RawAddress& GetPeerAddress(); 104 void SetHandle(tMCA_CL handle); 105 tMCA_CL GetHandle() const; 106 void SetMtu(uint16_t mtu); 107 uint16_t GetMtu(); 108 McapMdl* FindMdlById(uint16_t mdl_id); 109 McapMdl* FindMdlByHandle(tMCA_DL mdl_handle); 110 void RemoveAllMdl(); 111 void RemoveMdl(uint16_t mdl_id); 112 void ResetAllMdl(); 113 void ResetMdl(uint16_t mdl_id); 114 bool IsConnected(); 115 int ConnectedMdlCount(); 116 bool HasAvailableMdl(); 117 118 private: 119 // Initialized during start up 120 btmcap_test_interface_t* _mcap_test_interface; 121 tMCA_HANDLE _mcap_handle; 122 RawAddress _peer_bd_addr; 123 std::vector<McapMdl> _mdl_list; 124 125 // Initialized later 126 tMCA_CL _mcl_handle = 0; 127 uint16_t _control_mtu = 0; 128 }; 129 130 } // namespace SYSTEM_BT_TOOLS_MCAP_TOOL 131