1 /* 2 * Copyright (C) 2021 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 POWER_SPEC_H 17 #define POWER_SPEC_H 18 19 #include <map> 20 #include <string> 21 #include <vector> 22 23 #include "interface_profile.h" 24 #include "power_manager.h" 25 26 namespace OHOS { 27 namespace bluetooth { 28 #define SNIFF_LEVEL_LOW_MAX_INTERVAL 800 29 #define SNIFF_LEVEL_LOW_MIN_INTERVAL 400 30 #define SNIFF_LEVEL_LOW_ATTEMPT 4 31 #define SNIFF_LEVEL_LOW_TIMEOUT 1 32 33 #define SNIFF_LEVEL_MID_MAX_INTERVAL 150 34 #define SNIFF_LEVEL_MID_MIN_INTERVAL 50 35 #define SNIFF_LEVEL_MID_ATTEMPT 4 36 #define SNIFF_LEVEL_MID_TIMEOUT 1 37 38 #define SNIFF_LEVEL_HIG_MAX_INTERVAL 18 39 #define SNIFF_LEVEL_HIG_MIN_INTERVAL 14 40 #define SNIFF_LEVEL_HIG_ATTEMPT 1 41 #define SNIFF_LEVEL_HIG_TIMEOUT 0 42 43 #define SSR0_MAX_LATENCY 0 44 #define SSR0_MIN_REMOTE_TIMEOUT 0 45 #define SSR0_MIN_LOCAL_TIMEOUT 0 46 47 #define SSR1_MAX_LATENCY 0 48 #define SSR1_MIN_REMOTE_TIMEOUT 0 49 #define SSR1_MIN_LOCAL_TIMEOUT 2 50 51 #define SSR2_MAX_LATENCY 1200 52 #define SSR2_MIN_REMOTE_TIMEOUT 2 53 #define SSR2_MIN_LOCAL_TIMEOUT 2 54 55 #define SSR3_MAX_LATENCY 360 56 #define SSR3_MIN_REMOTE_TIMEOUT 160 57 #define SSR3_MIN_LOCAL_TIMEOUT 1600 58 59 #define SNIFF_DELAYSET_TIMEOUT_1000_MS 1000 60 #define SNIFF_DELAYSET_TIMEOUT_3000_MS 3000 61 #define SNIFF_DELAYSET_TIMEOUT_5000_MS 5000 62 #define SNIFF_DELAYSET_TIMEOUT_7000_MS 7000 63 #define SNIFF_DELAYSET_TIMEOUT_10000_MS 10000 64 65 enum { 66 POWER_MODE_PARK, 67 POWER_MODE_HOLD, 68 POWER_MODE_SNIFF, 69 POWER_MODE_ACTIVE, 70 }; 71 72 enum class PowerModeLevel : int { 73 NO_ACTION = 0, 74 LEVEL_LOW = 1, 75 LEVEL_MID = 2, 76 LEVEL_HIG = 3, 77 LEVEL_ACTIVE = 4, 78 }; 79 80 enum class PowerSsrLevel : int { 81 SSR0 = 0, 82 SSR1 = 1, 83 SSR2 = 2, 84 SSR3 = 3, 85 NO_ACTION = 4, 86 }; 87 88 /** 89 * @brief Represents set btm power param information. 90 * 91 * @since 6 92 */ 93 struct PowerParam { 94 public: 95 /** 96 * @brief A constructor used to create an <b>PowerParam</b> instance. 97 * 98 * @since 6 99 */ 100 PowerParam() = delete; 101 /** 102 * @brief A destructor used to delete the <b>PowerParam</b> instance. 103 * 104 * @since 6 105 */ ~PowerParamPowerParam106 ~PowerParam(){}; 107 /** 108 * @brief A constructor used to create an <b>PowerInfo</b> instance. 109 * 110 * @param max Max interval. 111 * @param min Min interval. 112 * @param attempt Attempt time. 113 * @param timeout Timeout period. 114 * @since 6 115 */ PowerParamPowerParam116 PowerParam(int max, int min, int attempt, int timeout) 117 : maxInterval_(max), minInterval_(min), attempt_(attempt), timeout_(timeout){}; 118 119 int maxInterval_ {0}; 120 int minInterval_ {0}; 121 int attempt_ {0}; 122 int timeout_ {0}; 123 }; 124 125 struct PowerSsrParam { 126 /** 127 * @brief A constructor used to create an <b>PowerSsrParam</b> instance. 128 * 129 * @since 6 130 */ 131 PowerSsrParam() = delete; 132 /** 133 * @brief A destructor used to delete the <b>PowerSsrParam</b> instance. 134 * 135 * @since 6 136 */ ~PowerSsrParamPowerSsrParam137 ~PowerSsrParam(){}; 138 /** 139 * @brief A constructor used to create an <b>PowerSsrParam</b> instance. 140 * 141 * @param maxLat Max latency. 142 * @param minRmtTo Min remote timeout. 143 * @param minLocTo Min local timeout. 144 * @since 6 145 */ PowerSsrParamPowerSsrParam146 PowerSsrParam(int maxLat, int minRmtTo, int minLocTo) 147 : maxLat_(maxLat), minRmtTo_(minRmtTo), minLocTo_(minLocTo) {}; 148 149 int maxLat_ {0}; 150 int minRmtTo_ {0}; 151 int minLocTo_ {0}; 152 }; 153 154 /** 155 * @brief Represents power mode information. 156 * 157 * @since 6 158 */ 159 struct PowerInfo { 160 public: 161 /** 162 * @brief A constructor used to create an <b>PowerInfo</b> instance. 163 * 164 * @since 6 165 */ 166 PowerInfo() = delete; 167 /** 168 * @brief A destructor used to delete the <b>PowerInfo</b> instance. 169 * 170 * @since 6 171 */ ~PowerInfoPowerInfo172 ~PowerInfo(){}; 173 /** 174 * @brief A constructor used to create an <b>PowerInfo</b> instance. 175 * 176 * @param mode power mode. 177 * @param timer timer out. 178 * @since 6 179 */ PowerInfoPowerInfo180 PowerInfo(PowerModeLevel mode, int timer) : powerMode_(mode), timeout_(timer){}; 181 182 PowerModeLevel powerMode_ {PowerModeLevel::NO_ACTION}; 183 int timeout_ {}; 184 }; 185 186 class PowerSpec { 187 public: 188 /** 189 * @brief A constructor used to create an <b>PowerSpec</b> instance. 190 * 191 * @since 6 192 */ PowerSpec()193 PowerSpec(){}; 194 /** 195 * @brief A destructor used to delete the <b>PowerSpec</b> instance. 196 * 197 * @since 6 198 */ ~PowerSpec()199 ~PowerSpec(){}; 200 201 /** 202 * @brief Get PowerInfo. 203 * 204 * @param profileName Profile name. 205 * @param status Request status. 206 * @return Returns PowerInfo. 207 * @since 6 208 */ 209 static PowerInfo GetPowerSpec(const std::string &profileName, RequestStatus status); 210 211 /** 212 * @brief Get PowerParam, base on PowerModeLevel. 213 * 214 * @param level PowerModeLevel. 215 * @return Returns PowerParam. 216 * @since 6 217 */ 218 static PowerParam GetPowerParam(PowerModeLevel level); 219 220 /** 221 * @brief Get PowerSsrLevel. 222 * 223 * @param profileName Profile name. 224 * @param status Request status. 225 * @return Returns PowerSsrLevel. 226 * @since 6 227 */ 228 static PowerSsrLevel GetPowerSsrLevel(const std::string &profileName, RequestStatus status); 229 230 /** 231 * @brief Get PowerSsrParam, base on PowerSsrLevel. 232 * 233 * @param level PowerSsrLevel. 234 * @return Returns PowerSsrParam. 235 * @since 6 236 */ 237 static PowerSsrParam GetPowerSsrParam(PowerSsrLevel level); 238 239 private: 240 static const std::map<RequestStatus, PowerInfo> MODE_SPEC_AG; 241 static const std::map<RequestStatus, PowerInfo> MODE_SPEC_HF; 242 static const std::map<RequestStatus, PowerInfo> MODE_SPEC_A2DP_SRC; 243 static const std::map<RequestStatus, PowerInfo> MODE_SPEC_A2DP_SINK; 244 static const std::map<RequestStatus, PowerInfo> MODE_SPEC_AVRCP_CT; 245 static const std::map<RequestStatus, PowerInfo> MODE_SPEC_MAP_MSE; 246 static const std::map<RequestStatus, PowerInfo> MODE_SPEC_PBAP_PCE; 247 static const std::map<RequestStatus, PowerInfo> MODE_SPEC_PBAP_PSE; 248 static const std::map<RequestStatus, PowerInfo> MODE_SPEC_SPP; 249 static const std::map<RequestStatus, PowerInfo> MODE_SPEC_GATT_CLIENT; 250 static const std::map<RequestStatus, PowerInfo> MODE_SPEC_GATT_SERVER; 251 static const std::map<std::string, std::map<RequestStatus, PowerInfo>> POWER_MODE_SPEC; 252 static const std::map<PowerModeLevel, PowerParam> POWER_PARAM; 253 254 static const std::map<RequestStatus, PowerSsrLevel> SSR_SPEC_AG; 255 static const std::map<RequestStatus, PowerSsrLevel> SSR_SPEC_HF; 256 static const std::map<RequestStatus, PowerSsrLevel> SSR_SPEC_A2DP_SRC; 257 static const std::map<RequestStatus, PowerSsrLevel> SSR_SPEC_A2DP_SINK; 258 static const std::map<RequestStatus, PowerSsrLevel> SSR_SPEC_AVRCP_CT; 259 static const std::map<RequestStatus, PowerSsrLevel> SSR_SPEC_MAP_MSE; 260 static const std::map<RequestStatus, PowerSsrLevel> SSR_SPEC_PBAP_PCE; 261 static const std::map<RequestStatus, PowerSsrLevel> SSR_SPEC_PBAP_PSE; 262 static const std::map<RequestStatus, PowerSsrLevel> SSR_SPEC_SPP; 263 static const std::map<RequestStatus, PowerSsrLevel> SSR_SPEC_GATT_CLIENT; 264 static const std::map<RequestStatus, PowerSsrLevel> SSR_SPEC_GATT_SERVER; 265 static const std::map<std::string, std::map<RequestStatus, PowerSsrLevel>> SSR_SPEC; 266 static const std::map<PowerSsrLevel, PowerSsrParam> POWER_SSR_PARAMS; 267 }; 268 } // namespace bluetooth 269 } // namespace OHOS 270 271 #endif // POWER_SPEC_H