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 "mca_api.h"
19
20namespace SYSTEM_BT_TOOLS_MCAP_TOOL {
21
22const tMCA_CHNL_CFG* get_test_channel_config();
23
24class McapMdl {
25 public:
26  /**
27   * An abstraction for the MCAP Data Link (MDL)
28   * @param mcap_test_interface Underlining MCAP interface to Bluetooth stack
29   * @param mcl_handle Parent MCL handle
30   * @param mdep_handle Associated MDEP handle
31   * @param mdl_id Desired MDL ID, application supported
32   * @param dep_id Peer or self MDEP ID
33   * @param cfg Configuration flags
34   */
35  McapMdl(btmcap_test_interface_t* mcap_test_interface, tMCA_CL mcl_handle,
36          tMCA_DEP mdep_handle, uint16_t mdl_id, uint8_t dep_id, uint8_t cfg);
37  /**
38   * Update this MDL's context so that it can be reused for a new connection
39   * This will close this MDL connection at the same time
40   * @param mdep_handle Associated MDEP handle
41   * @param dep_id Peer or self MDEP ID
42   * @param cfg Configuration flags
43   * @return True on success
44   */
45  bool UpdateContext(tMCA_DEP mdep_handle, uint8_t dep_id, uint8_t cfg);
46  /**
47   * Request to create this MDL to remote device through MCL
48   * The create command won't initiate an L2CAP connection unless a non-null
49   * config is given
50   * @param data_psm Data channel L2CAP PSM
51   * @return True on success
52   */
53  bool Create(uint16_t data_psm, bool should_connect);
54  /**
55   * Connect this MDL to remote by configuring the data channel
56   * @return True on success
57   */
58  bool Connect();
59  /**
60   * Close this MDL connection
61   * @return True on success
62   */
63  bool Close();
64  /**
65   * Request to reconnect connect this MDL to remote device through MCL
66   * @param data_psm Data channel L2CAP PSM
67   * @return True on success
68   */
69  bool Reconnect(uint16_t data_psm);
70  /**
71   * Respond to a reconnect request from peer
72   * @return True on success
73   */
74  bool ReconnectResponse();
75  /**
76   * Respond to a connect request from peer
77   * @return True on success
78   */
79  bool CreateResponse();
80  bool IsConnected();
81  int32_t GetResponseCode();
82  void SetResponseCode(int32_t rsp_code);
83  uint16_t GetId();
84  void SetHandle(tMCA_DL mdl_handle);
85  tMCA_DL GetHandle();
86  void SetMtu(uint16_t mtu);
87  uint16_t GetMtu();
88
89 private:
90  // Initialized at start up
91  btmcap_test_interface_t* _mcap_test_interface;
92  tMCA_CL _mcl_handle;
93  tMCA_DEP _mdep_handle;
94  uint16_t _mdl_id;
95  uint8_t _dep_id;
96  uint8_t _cfg;
97
98  // Initialized later
99  tMCA_DL _mdl_handle = 0;
100  uint16_t _data_mtu = 0;
101  int32_t _mdl_rsp_code = -1;
102};
103
104}  // namespace SYSTEM_BT_TOOLS_MCAP_TOOL
105