• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 <functional>
19 #include <iterator>
20 #include <memory>
21 #include <string>
22 #include <unordered_map>
23 #include <vector>
24 
25 #include <base/logging.h>
26 
27 #include "mca_api.h"
28 
29 #include "mcap_test_mcl.h"
30 #include "mcap_test_mdep.h"
31 
32 namespace SYSTEM_BT_TOOLS_MCAP_TOOL {
33 
34 extern const tMCA_CHNL_CFG MCAP_TEST_CHANNEL_CONFIG;
35 
36 class McapTestApp {
37  public:
38   /**
39    * McapTestApp is the root node for an MCAP application
40    *
41    * @param mcap_test_interface interface to MCAP APIs on Bluetooth stack
42    *                            from get_test_interface()
43    */
44   McapTestApp(btmcap_test_interface_t* mcap_test_interface);
45   btmcap_test_interface_t* GetInterface();
46   /**
47    * Register an application with the Bluetooth stack
48    * @param ctrl_psm Control channel L2CAP PSM
49    * @param data_psm Data channel L2CAP PSM
50    * @param sec_mask Security Mask
51    * @param callback Control channel callback
52    * @return
53    */
54   bool Register(uint16_t ctrl_psm, uint16_t data_psm, uint16_t sec_mask,
55                 tMCA_CTRL_CBACK* callback);
56   /**
57    * De-register the current application
58    */
59   void Deregister();
60   /**
61    * Check if current application is registered
62    * @return True if registered
63    */
64   bool Registered();
65   /**
66    * Create MCAP Communication Link
67    * @param bd_addr Peer Bluetooth Address
68    * @param ctrl_psm Control channel L2CAP PSM, should be the same as registered
69    *                 value for most cases
70    * @param sec_mask Security mask
71    * @return True on success
72    */
73   bool ConnectMcl(const RawAddress& bd_addr, uint16_t ctrl_psm,
74                   uint16_t sec_mask);
75   /**
76    * Create MCAP Data End Point
77    * @param type 0 - MCA_TDEP_ECHO, 1 - MCA_TDEP_DATA
78    * @param max_mdl Maximum number of data channels for this end point
79    * @param data_callback Data callback
80    * @return True on success
81    */
82   bool CreateMdep(uint8_t type, uint8_t max_mdl,
83                   tMCA_DATA_CBACK* data_callback);
84   // Simple methods that are self-explanatory
85   uint8_t GetHandle();
86   McapMcl* FindMclByPeerAddress(const RawAddress& bd_addr);
87   McapMcl* FindMclByHandle(tMCA_CL mcl_handle);
88   McapMdep* FindMdepByHandle(tMCA_DEP mdep_handle);
89   void RemoveMclByHandle(tMCA_CL mcl_handle);
90   bool IsRegistered();
91   /**
92    * Callback function for control channel, need to be called by an external
93    * function registered during McapTestApp::Register()
94    * @param handle MCAP application handle, should be the same as GetHandle()
95    * @param mcl MCL handle, FindMclByHandle(mcl) should return non-null value
96    * @param event Control event
97    * @param p_data Control data
98    */
99   void ControlCallback(tMCA_HANDLE handle, tMCA_CL mcl, uint8_t event,
100                        tMCA_CTRL* p_data);
101 
102  private:
103   // Initialized during start up
104   tMCA_REG _mca_reg;
105   btmcap_test_interface_t* _mcap_test_interface = nullptr;
106   std::vector<McapMcl> _mcl_list;
107   std::vector<McapMdep> _mdep_list;
108 
109   // Initialized later
110   tMCA_HANDLE _mcap_handle = 0;
111 };
112 
113 }  // namespace SYSTEM_BT_TOOLS_MCAP_TOOL
114