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