1 /* 2 * Copyright (C) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef A2DP_DEF_H 17 #define A2DP_DEF_H 18 19 #include <cstddef> 20 #include <cstdint> 21 22 #include "a2dp_codec/include/a2dp_codec_constant.h" 23 #include "avdtp.h" 24 #include "bt_def.h" 25 #include "btstack.h" 26 27 namespace OHOS { 28 namespace bluetooth { 29 /** 30 * SBC Codec Specific Information Element 31 */ 32 #define A2DP_ROLE_SOURCE 0 33 #define A2DP_ROLE_SINK 1 34 #define A2DP_ROLE_INT 2 35 #define A2DP_ROLE_ACP 3 36 37 /* the timeout to wait for open req after setconfig for incoming connections */ 38 #ifndef A2DP_SIGNALLING_TIMEOUT_MS 39 #define A2DP_SIGNALLING_TIMEOUT_MS (8 * 1000) /* 8 seconds */ 40 #endif 41 42 /// Service class uuid for A2DP. 43 #define A2DP_SERVICE_CLASS_UUID (0x110A) 44 45 /// Number of items when add service class id list. 46 #define A2DP_SERVICE_CLASS_ID_LIST_NUMBER (0x0001) 47 48 /// Service class uuid for A2DP Sink. 49 #define A2DP_SINK_SERVICE_CLASS_UUID (0x110B) 50 /// Service class uuid for A2DP Source. 51 #define A2DP_SERVICE_CLASS_UUID (0x110A) 52 /// Service class uuid for AVDTP. 53 #define A2DP_PROTOCOL_UUID_AVDTP (0x0019) 54 /// Service class uuid for L2CAP. 55 #define A2DP_PROTOCOL_UUID_L2CAP (0x0100) 56 /// Number of items when add protocol descriptor. 57 #define A2DP_PROTOCOL_DESCRIPTOR_LIST_NUMBER (0x0002) 58 /// Number of items when add bluetooth profile descriptor list. 59 #define A2DP_BLUETOOTH_PROFILE_DESCRIPTOR_LIST_NUMBER (0x0001) 60 /// Profile uuid for A2DP. 61 #define A2DP_PROFILE_UUID (0x110D) 62 /// The Version of A2DP Profile is 1.3. 63 #define A2DP_PROFILE_REV_1_3 (0x0103) 64 65 /* Time to wait for signalling from ACP */ 66 #ifndef A2DP_ACCEPT_SIGNALLING_TIMEOUT_MS 67 #define A2DP_ACCEPT_SIGNALLING_TIMEOUT_MS (2 * 1000) /* 2 seconds */ 68 #endif 69 70 /* Time to wait for close transport channel from INT */ 71 #ifndef A2DP_ACCEPT_CLOSING_SIGNALLING_TIMEOUT_MS 72 #define A2DP_ACCEPT_CLOSING_SIGNALLING_TIMEOUT_MS (3 * 1000) /* 3 seconds */ 73 #endif 74 75 #define A2DP_MAX_AVDTP_MTU_SIZE 1024 // MTU=1005, AVDTP Header:12, L2CAP:4 76 77 #define A2DP_STREAM_HANDLES_NUMBER 1 // number of start stream 78 79 struct CallbackParameter { 80 uint8_t role; 81 bool srcRole; 82 uint16_t handle; 83 }; 84 85 struct CodecInfo { 86 A2dpCodecIndex codecIndex; 87 uint8_t codecInfo[A2DP_CODEC_SIZE]; // Codec codecInfo 88 }; 89 90 enum ServiceStatus { 91 STREAM_CONNECTING, 92 STREAM_CONNECT, 93 STREAM_DISCONNECTING, 94 STREAM_DISCONNECT, 95 STREAM_CONNECT_FAILED, 96 STREAM_DISCONNECT_FAILED, 97 STREAM_TIMEOUT 98 }; 99 100 enum EventStream { 101 EVT_SDP_DISC, 102 EVT_SDP_CFM, 103 EVT_CONNECT_REQ, 104 EVT_CONNECT_IND, 105 EVT_CONNECT_CFM, 106 EVT_DISCOVER_REQ, 107 EVT_DISCOVER_CFM, 108 EVT_SETCONFIG_REQ, 109 EVT_SETCONFIG_IND, 110 EVT_SETCONFIG_CFM, 111 EVT_GET_ALLCAP_REQ, 112 EVT_GET_ALLCAP_IND, 113 EVT_GET_ALLCAP_CFM, 114 EVT_GET_CAP_REQ, 115 EVT_GET_CAP_IND, 116 EVT_GET_CAP_CFM, 117 EVT_OPEN_REQ, 118 EVT_OPEN_IND, 119 EVT_OPEN_CFM, 120 EVT_START_REQ, 121 EVT_START_IND, 122 EVT_START_CFM, 123 EVT_GETCONFIG_REQ, 124 EVT_GETCONFIG_IND, 125 EVT_GETCONFIG_CFM, 126 EVT_RECONFIG_REQ, 127 EVT_RECONFIG_IND, 128 EVT_RECONFIG_CFM, 129 EVT_SUSPEND_REQ, 130 EVT_SUSPEND_IND, 131 EVT_SUSPEND_CFM, 132 EVT_DISCONNECT_REQ, 133 EVT_DISCONNECT_IND, 134 EVT_DISCONNECT_CFM, 135 EVT_CLOSE_REQ, 136 EVT_CLOSE_IND, 137 EVT_CLOSE_CFM, 138 EVT_DELAY_REQ, 139 EVT_DELAY_IND, 140 EVT_DELAY_CFM, 141 EVT_ABORT_REQ, 142 EVT_ABORT_IND, 143 EVT_ABORT_CFM, 144 EVT_WRITE_CFM, 145 EVT_TIME_OUT, 146 EVT_CLOSE_TRANS_IND 147 }; 148 149 struct StreamInfo { 150 BtAddr addr; 151 uint16_t handle; 152 uint8_t acpSeid; 153 uint8_t label; 154 uint8_t errCode; 155 }; 156 157 struct ConfigureStream { 158 BtAddr addr; 159 uint8_t intSeid; 160 uint8_t acpSeid; 161 AvdtSepConfig cfg; 162 }; 163 164 struct ConfigrueRsp { 165 AvdtCatetory category; 166 uint16_t handle; 167 uint16_t scbIndex; 168 uint8_t label; 169 BtAddr addr; 170 uint8_t codecInfo[AVDT_CODEC_SIZE]; 171 uint8_t role; 172 }; 173 174 struct GetConfigrueRsp { 175 AvdtCatetory category; 176 uint16_t handle; 177 uint16_t scbIndex; 178 uint8_t label; 179 BtAddr addr; 180 AvdtSepConfig cfg; 181 }; 182 183 struct SepDetail { 184 BtAddr addr; 185 AvdtStreamConfig cfg; 186 }; 187 188 struct ConnectReq { 189 BtAddr addr; 190 uint8_t errCode; 191 }; 192 193 struct DelayReportInfo { 194 BtAddr addr; 195 uint16_t handle; 196 uint16_t delayValue; 197 }; 198 199 union A2dpAvdtMsgData { 200 StreamInfo stream; 201 ConnectReq connectInfo; 202 ConfigureStream configStream; 203 ConfigrueRsp configRsp; 204 GetConfigrueRsp getConfigureRsp; 205 DelayReportInfo delayReportInfo; 206 AvdtSepInfo discoverData[AVDT_NUM_SEPS]; 207 SepDetail sepDetail; 208 AvdtCtrlData msg; 209 }; 210 211 struct A2dpAvdtMsg { 212 uint16_t handle; 213 uint8_t role; 214 uint8_t event; 215 A2dpAvdtMsgData a2dpMsg; 216 }; 217 218 enum A2dpEvent { 219 A2DP_INVALID_EVT = 0, 220 A2DP_CONNECT_EVT, 221 A2DP_DISCONNECT_EVT, 222 A2DP_AVDTP_EVT, 223 A2DP_SDP_EVT, 224 A2DP_TIMEOUT_EVT, 225 }; 226 227 enum A2dpConnectNum { 228 A2DP_CONNECT_NUM_MAX = 6, 229 A2DP_CONNECT_NUM_UN_MAX, 230 }; 231 232 enum A2dpMessage { 233 A2DP_MSG_CONNECT, 234 A2DP_MSG_DISCONNECT, 235 A2DP_MSG_CONNECT_TIMEOUT, 236 A2DP_MSG_CONNECT_FORBIDDEN, 237 A2DP_MSG_PROFILE_CONNECTED, 238 A2DP_MSG_PROFILE_CONNECTING, 239 A2DP_MSG_PROFILE_DISCONNECTED, 240 A2DP_MSG_PROFILE_DISCONNECTING, 241 A2DP_MSG_PROFILE_AUDIO_PLAY_START, 242 A2DP_MSG_PROFILE_AUDIO_PLAY_SUSPEND, 243 A2DP_MSG_PROFILE_AUDIO_PLAY_STOP, 244 A2DP_MSG_PROFILE_CODEC_CHANGE, 245 }; 246 } // namespace bluetooth 247 } // namespace OHOS 248 #endif // A2DP_DEF_H