1 /******************************************************************************
2  *
3  *  Copyright 2003-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /******************************************************************************
20  *
21  *  This file contains compile-time configurable constants for the device
22  *  manager.
23  *
24  ******************************************************************************/
25 
26 #include <cstdint>
27 
28 #include "bta/dm/bta_dm_int.h"
29 #include "bta/include/bta_api.h"
30 #include "bta/include/bta_hh_api.h"
31 #include "bta/include/bta_jv_api.h"
32 #include "bta/sys/bta_sys.h"
33 #include "internal_include/bt_target.h"
34 #include "osi/include/properties.h"
35 
36 /* page timeout in 625uS */
37 #ifndef BTA_DM_PAGE_TIMEOUT
38 #define BTA_DM_PAGE_TIMEOUT 8192
39 #endif
40 
41 /* TRUE to avoid scatternet when av is streaming (be the central) */
42 #ifndef BTA_DM_AVOID_SCATTER_A2DP
43 #define BTA_DM_AVOID_SCATTER_A2DP TRUE
44 #endif
45 
46 const tBTA_DM_CFG bta_dm_cfg = {
47     /* page timeout in 625uS */
48     BTA_DM_PAGE_TIMEOUT,
49     /* true to avoid scatternet when av is streaming (be the central) */
50     BTA_DM_AVOID_SCATTER_A2DP};
51 
52 #ifndef BTA_DM_SCATTERNET
53 /* By default, allow partial scatternet */
54 #define BTA_DM_SCATTERNET BTA_DM_PARTIAL_SCATTERNET
55 #endif
56 
57 #ifndef BTA_HH_ROLE
58 /* By default, do not specify HH role (backward compatibility) */
59 #define BTA_HH_ROLE BTA_ANY_ROLE
60 #endif
61 
62 #ifndef BTA_PANU_ROLE
63 /* By default, AV role (backward BTA_CENTRAL_ROLE_PREF) */
64 #define BTA_PANU_ROLE BTA_PERIPHERAL_ROLE_ONLY
65 #endif
66 #define BTA_DM_NUM_RM_ENTRY 6
67 
68 /* appids for PAN used by insight sample application
69    these have to be same as defined in btui_int.h */
70 #define BTUI_PAN_ID_PANU 0
71 #define BTUI_PAN_ID_NAP 1
72 #define BTUI_PAN_ID_GN 2
73 
74 /* First element is always for SYS:
75    app_id = # of entries table, cfg is
76    device scatternet support */
77 const tBTA_DM_RM bta_dm_rm_cfg[] = {
78     {BTA_ID_SYS, BTA_DM_NUM_RM_ENTRY, BTA_DM_SCATTERNET},
79     {BTA_ID_PAN, BTUI_PAN_ID_NAP, BTA_ANY_ROLE},
80     {BTA_ID_PAN, BTUI_PAN_ID_GN, BTA_ANY_ROLE},
81     {BTA_ID_PAN, BTA_APP_ID_PAN_MULTI, BTA_CENTRAL_ROLE_ONLY},
82     {BTA_ID_PAN, BTUI_PAN_ID_PANU, BTA_PANU_ROLE},
83     {BTA_ID_HH, BTA_ALL_APP_ID, BTA_HH_ROLE},
84     {BTA_ID_AV, BTA_ALL_APP_ID, BTA_CENTRAL_ROLE_PREF}};
85 
86 const tBTA_DM_CFG* p_bta_dm_cfg = &bta_dm_cfg;
87 
88 const tBTA_DM_RM* p_bta_dm_rm_cfg = &bta_dm_rm_cfg[0];
89 
90 #define BTA_DM_NUM_PM_ENTRY \
91   25 /* number of entries in bta_dm_pm_cfg except the first */
92 #define BTA_DM_NUM_PM_SPEC 16 /* number of entries in bta_dm_pm_spec */
93 
94 tBTA_DM_PM_TYPE_QUALIFIER tBTA_DM_PM_CFG
95     bta_dm_pm_cfg[BTA_DM_NUM_PM_ENTRY + 1] = {
96         {BTA_ID_SYS, BTA_DM_NUM_PM_ENTRY,
97          0}, /* reserved: specifies length of this table. */
98         {BTA_ID_AG, BTA_ALL_APP_ID,
99          0},               /* ag uses first spec table for app id 0 */
100         {BTA_ID_CT, 1, 1}, /* ct (BTA_ID_CT,APP ID=1) spec table */
101         {BTA_ID_CG, BTA_ALL_APP_ID, 1},     /* cg resue ct spec table */
102         {BTA_ID_DG, BTA_ALL_APP_ID, 2},     /* dg spec table */
103         {BTA_ID_AV, BTA_ALL_APP_ID, 4},     /* av spec table */
104         {BTA_ID_FTC, BTA_ALL_APP_ID, 7},    /* ftc spec table */
105         {BTA_ID_FTS, BTA_ALL_APP_ID, 8},    /* fts spec table */
106         {BTA_ID_HD, BTA_ALL_APP_ID, 3},     /* hd spec table */
107         {BTA_ID_HH, BTA_HH_APP_ID_JOY, 5},  /* app BTA_HH_APP_ID_JOY,
108                                                similar to hh spec table */
109         {BTA_ID_HH, BTA_HH_APP_ID_GPAD, 5}, /* app BTA_HH_APP_ID_GPAD,
110                                                similar to hh spec table */
111         {BTA_ID_HH, BTA_ALL_APP_ID, 6},     /* hh spec table */
112         {BTA_ID_PBC, BTA_ALL_APP_ID, 2},    /* reuse dg spec table */
113         {BTA_ID_PBS, BTA_ALL_APP_ID, 8},    /* reuse fts spec table */
114         {BTA_ID_OPC, BTA_ALL_APP_ID, 7},    /* reuse ftc spec table */
115         {BTA_ID_OPS, BTA_ALL_APP_ID, 8},    /* reuse fts spec table */
116         {BTA_ID_MSE, BTA_ALL_APP_ID, 8},    /* reuse fts spec table */
117         {BTA_ID_JV, BTA_JV_PM_ID_1,
118          7}, /* app BTA_JV_PM_ID_1, reuse ftc spec table */
119         {BTA_ID_JV, BTA_ALL_APP_ID, 8},     /* reuse fts spec table */
120         {BTA_ID_HL, BTA_ALL_APP_ID, 9},     /* reuse fts spec table */
121         {BTA_ID_PAN, BTUI_PAN_ID_PANU, 10}, /* PANU spec table */
122         {BTA_ID_PAN, BTUI_PAN_ID_NAP, 11},  /* NAP spec table */
123         {BTA_ID_HS, BTA_ALL_APP_ID, 12},    /* HS spec table */
124         {BTA_ID_GATTC, BTA_ALL_APP_ID, 14}, /* gattc spec table */
125         {BTA_ID_GATTS, BTA_ALL_APP_ID, 15}  /* gatts spec table */
126 };
127 
get_bta_dm_pm_spec()128 tBTA_DM_PM_TYPE_QUALIFIER tBTA_DM_PM_SPEC* get_bta_dm_pm_spec() {
129   static uint16_t hs_sniff_delay = uint16_t(
130       osi_property_get_int32("bluetooth.bta_hs_sniff_delay_ms.config", 7000));
131   static uint16_t fts_ops_idle_to_sniff_delay_ms =
132       uint16_t(osi_property_get_int32(
133           "bluetooth.bta_fts_ops_idle_to_sniff_delay_ms.config",
134           BTA_FTS_OPS_IDLE_TO_SNIFF_DELAY_MS));
135   static uint16_t ftc_idle_to_sniff_delay_ms = uint16_t(
136       osi_property_get_int32("bluetooth.bta_ftc_idle_to_sniff_delay_ms.config",
137                              BTA_FTC_IDLE_TO_SNIFF_DELAY_MS));
138 
139   static tBTA_DM_PM_TYPE_QUALIFIER tBTA_DM_PM_SPEC
140       bta_dm_pm_spec[BTA_DM_NUM_PM_SPEC] = {
141           /* AG : 0 */
142           {(BTA_DM_PM_SNIFF | BTA_DM_PM_PARK), /* allow park & sniff */
143            (BTA_DM_PM_SSR2),                   /* the SSR entry */
144            {
145                {{BTA_DM_PM_SNIFF_A2DP_IDX, 7000},
146                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn open sniff  */
147                {{BTA_DM_PM_NO_PREF, 0},
148                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn close  */
149                {{BTA_DM_PM_NO_ACTION, 0},
150                 {BTA_DM_PM_NO_ACTION, 0}}, /* app open */
151                {{BTA_DM_PM_NO_ACTION, 0},
152                 {BTA_DM_PM_NO_ACTION, 0}}, /* app close */
153                {{BTA_DM_PM_SNIFF_SCO_OPEN_IDX, 7000},
154                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco open, active */
155                {{BTA_DM_PM_SNIFF_A2DP_IDX, 7000},
156                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco close sniff  */
157                {{BTA_DM_PM_SNIFF_A2DP_IDX, 7000},
158                 {BTA_DM_PM_NO_ACTION, 0}},                        /* idle */
159                {{BTA_DM_PM_ACTIVE, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* busy */
160                {{BTA_DM_PM_RETRY, 7000},
161                 {BTA_DM_PM_NO_ACTION, 0}} /* mode change retry */
162            }},
163 
164           /* CT, CG : 1 */
165           {(BTA_DM_PM_SNIFF | BTA_DM_PM_PARK), /* allow park & sniff */
166            (BTA_DM_PM_SSR2),                   /* the SSR entry */
167            {
168                {{BTA_DM_PM_PARK, 5000},
169                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn open  park */
170                {{BTA_DM_PM_NO_PREF, 0},
171                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn close  */
172                {{BTA_DM_PM_NO_ACTION, 0},
173                 {BTA_DM_PM_NO_ACTION, 0}}, /* app open */
174                {{BTA_DM_PM_NO_ACTION, 0},
175                 {BTA_DM_PM_NO_ACTION, 0}}, /* app close */
176                {{BTA_DM_PM_SNIFF_A2DP_IDX, 5000},
177                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco open sniff */
178                {{BTA_DM_PM_PARK, 5000},
179                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco close  park */
180                {{BTA_DM_PM_NO_ACTION, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* idle */
181                {{BTA_DM_PM_NO_ACTION, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* busy */
182                {{BTA_DM_PM_RETRY, 5000},
183                 {BTA_DM_PM_NO_ACTION, 0}} /* mode change retry */
184            }},
185 
186           /* DG, PBC : 2 */
187           {(BTA_DM_PM_ACTIVE), /* no power saving mode allowed */
188            (BTA_DM_PM_SSR2),   /* the SSR entry */
189            {
190                {{BTA_DM_PM_SNIFF, 5000},
191                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn open active */
192                {{BTA_DM_PM_NO_PREF, 0},
193                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn close  */
194                {{BTA_DM_PM_ACTIVE, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* app open */
195                {{BTA_DM_PM_NO_ACTION, 0},
196                 {BTA_DM_PM_NO_ACTION, 0}}, /* app close */
197                {{BTA_DM_PM_NO_ACTION, 0},
198                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco open  */
199                {{BTA_DM_PM_NO_ACTION, 0},
200                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco close   */
201                {{BTA_DM_PM_SNIFF, 1000}, {BTA_DM_PM_NO_ACTION, 0}}, /* idle */
202                {{BTA_DM_PM_ACTIVE, 0}, {BTA_DM_PM_NO_ACTION, 0}},   /* busy */
203                {{BTA_DM_PM_NO_ACTION, 0},
204                 {BTA_DM_PM_NO_ACTION, 0}} /* mode change retry */
205            }},
206 
207           /* HD : 3 */
208           {(BTA_DM_PM_SNIFF | BTA_DM_PM_PARK), /* allow park & sniff */
209            (BTA_DM_PM_SSR3),                   /* the SSR entry */
210            {
211                {{BTA_DM_PM_SNIFF_HD_ACTIVE_IDX, 5000},
212                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn open sniff */
213                {{BTA_DM_PM_NO_PREF, 0},
214                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn close */
215                {{BTA_DM_PM_NO_ACTION, 0},
216                 {BTA_DM_PM_NO_ACTION, 0}}, /* app open */
217                {{BTA_DM_PM_NO_ACTION, 0},
218                 {BTA_DM_PM_NO_ACTION, 0}}, /* app close */
219                {{BTA_DM_PM_NO_ACTION, 0},
220                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco open  */
221                {{BTA_DM_PM_NO_ACTION, 0},
222                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco close */
223                {{BTA_DM_PM_SNIFF_HD_IDLE_IDX, 5000},
224                 {BTA_DM_PM_NO_ACTION, 0}}, /* idle */
225                {{BTA_DM_PM_SNIFF_HD_ACTIVE_IDX, 0},
226                 {BTA_DM_PM_NO_ACTION, 0}}, /* busy */
227                {{BTA_DM_PM_NO_ACTION, 0},
228                 {BTA_DM_PM_NO_ACTION, 0}} /* mode change retry */
229            }},
230 
231           /* AV : 4 */
232           {(BTA_DM_PM_SNIFF), /* allow sniff */
233            (BTA_DM_PM_SSR2),  /* the SSR entry */
234            {
235                {{BTA_DM_PM_SNIFF_A2DP_IDX, 7000},
236                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn open  sniff */
237                {{BTA_DM_PM_NO_PREF, 0},
238                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn close  */
239                {{BTA_DM_PM_NO_ACTION, 0},
240                 {BTA_DM_PM_NO_ACTION, 0}}, /* app open */
241                {{BTA_DM_PM_NO_ACTION, 0},
242                 {BTA_DM_PM_NO_ACTION, 0}}, /* app close */
243                {{BTA_DM_PM_NO_ACTION, 0},
244                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco open  */
245                {{BTA_DM_PM_NO_ACTION, 0},
246                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco close   */
247                {{BTA_DM_PM_SNIFF_A2DP_IDX, 7000},
248                 {BTA_DM_PM_NO_ACTION, 0}},                        /* idle */
249                {{BTA_DM_PM_ACTIVE, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* busy */
250                {{BTA_DM_PM_NO_ACTION, 0},
251                 {BTA_DM_PM_NO_ACTION, 0}} /* mode change retry */
252            }},
253 
254           /* HH for joysticks and gamepad : 5 */
255           {(BTA_DM_PM_SNIFF | BTA_DM_PM_PARK), /* allow park & sniff */
256            (BTA_DM_PM_SSR1),                   /* the SSR entry */
257            {
258                {{BTA_DM_PM_SNIFF6, BTA_DM_PM_HH_OPEN_DELAY},
259                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn open  sniff */
260                {{BTA_DM_PM_NO_PREF, 0},
261                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn close  */
262                {{BTA_DM_PM_NO_ACTION, 0},
263                 {BTA_DM_PM_NO_ACTION, 0}}, /* app open */
264                {{BTA_DM_PM_NO_ACTION, 0},
265                 {BTA_DM_PM_NO_ACTION, 0}}, /* app close */
266                {{BTA_DM_PM_NO_ACTION, 0},
267                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco open  */
268                {{BTA_DM_PM_NO_ACTION, 0},
269                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco close, used for HH suspend */
270                {{BTA_DM_PM_SNIFF6, BTA_DM_PM_HH_IDLE_DELAY},
271                 {BTA_DM_PM_NO_ACTION, 0}}, /* idle */
272                {{BTA_DM_PM_SNIFF6, BTA_DM_PM_HH_ACTIVE_DELAY},
273                 {BTA_DM_PM_NO_ACTION, 0}}, /* busy */
274                {{BTA_DM_PM_NO_ACTION, 0},
275                 {BTA_DM_PM_NO_ACTION, 0}} /* mode change retry */
276            }},
277 
278           /* HH : 6 */
279           {(BTA_DM_PM_SNIFF | BTA_DM_PM_PARK), /* allow park & sniff */
280            (BTA_DM_PM_SSR1),                   /* the SSR entry */
281            {
282                {{BTA_DM_PM_SNIFF_HH_OPEN_IDX, BTA_DM_PM_HH_OPEN_DELAY},
283                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn open  sniff */
284                {{BTA_DM_PM_NO_PREF, 0},
285                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn close  */
286                {{BTA_DM_PM_NO_ACTION, 0},
287                 {BTA_DM_PM_NO_ACTION, 0}}, /* app open */
288                {{BTA_DM_PM_NO_ACTION, 0},
289                 {BTA_DM_PM_NO_ACTION, 0}}, /* app close */
290                {{BTA_DM_PM_NO_ACTION, 0},
291                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco open  */
292                {{BTA_DM_PM_NO_ACTION, 0},
293                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco close, used for HH suspend */
294                {{BTA_DM_PM_SNIFF_HH_IDLE_IDX, BTA_DM_PM_HH_IDLE_DELAY},
295                 {BTA_DM_PM_NO_ACTION, 0}}, /* idle */
296                {{BTA_DM_PM_SNIFF_HH_ACTIVE_IDX, BTA_DM_PM_HH_ACTIVE_DELAY},
297                 {BTA_DM_PM_NO_ACTION, 0}}, /* busy */
298                {{BTA_DM_PM_NO_ACTION, 0},
299                 {BTA_DM_PM_NO_ACTION, 0}} /* mode change retry */
300            }},
301 
302           /* FTC, OPC, JV : 7 */
303           {(BTA_DM_PM_SNIFF), /* allow sniff */
304            (BTA_DM_PM_SSR2),  /* the SSR entry */
305            {
306                {{BTA_DM_PM_ACTIVE, 0},
307                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn open  active */
308                {{BTA_DM_PM_NO_PREF, 0},
309                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn close  */
310                {{BTA_DM_PM_ACTIVE, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* app open */
311                {{BTA_DM_PM_NO_ACTION, 0},
312                 {BTA_DM_PM_NO_ACTION, 0}}, /* app close */
313                {{BTA_DM_PM_NO_ACTION, 0},
314                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco open  */
315                {{BTA_DM_PM_NO_ACTION, 0},
316                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco close   */
317                {{BTA_DM_PM_SNIFF_A2DP_IDX, ftc_idle_to_sniff_delay_ms},
318                 {BTA_DM_PM_NO_ACTION, 0}},                        /* idle */
319                {{BTA_DM_PM_ACTIVE, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* busy */
320                {{BTA_DM_PM_NO_ACTION, 0},
321                 {BTA_DM_PM_NO_ACTION, 0}} /* mode change retry */
322            }},
323 
324           /* FTS, PBS, OPS, MSE, BTA_JV_PM_ID_1 : 8 */
325           {(BTA_DM_PM_SNIFF), /* allow sniff */
326            (BTA_DM_PM_SSR2),  /* the SSR entry */
327            {
328                {{BTA_DM_PM_ACTIVE, 0},
329                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn open  active */
330                {{BTA_DM_PM_NO_PREF, 0},
331                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn close  */
332                {{BTA_DM_PM_ACTIVE, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* app open */
333                {{BTA_DM_PM_NO_ACTION, 0},
334                 {BTA_DM_PM_NO_ACTION, 0}}, /* app close */
335                {{BTA_DM_PM_NO_ACTION, 0},
336                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco open  */
337                {{BTA_DM_PM_NO_ACTION, 0},
338                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco close   */
339                {{BTA_DM_PM_SNIFF_A2DP_IDX, fts_ops_idle_to_sniff_delay_ms},
340                 {BTA_DM_PM_NO_ACTION, 0}},                        /* idle */
341                {{BTA_DM_PM_ACTIVE, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* busy */
342                {{BTA_DM_PM_NO_ACTION, 0},
343                 {BTA_DM_PM_NO_ACTION, 0}} /* mode change retry */
344            }},
345 
346           /* HL : 9 */
347           {(BTA_DM_PM_SNIFF), /* allow sniff */
348            (BTA_DM_PM_SSR2),  /* the SSR entry */
349            {
350                {{BTA_DM_PM_SNIFF_A2DP_IDX, 5000},
351                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn open sniff  */
352                {{BTA_DM_PM_NO_PREF, 0},
353                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn close  */
354                {{BTA_DM_PM_NO_ACTION, 0},
355                 {BTA_DM_PM_NO_ACTION, 0}}, /* app open */
356                {{BTA_DM_PM_NO_ACTION, 0},
357                 {BTA_DM_PM_NO_ACTION, 0}}, /* app close */
358                {{BTA_DM_PM_NO_ACTION, 0},
359                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco open, active */
360                {{BTA_DM_PM_NO_ACTION, 0},
361                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco close sniff  */
362                {{BTA_DM_PM_NO_ACTION, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* idle */
363                {{BTA_DM_PM_ACTIVE, 0}, {BTA_DM_PM_NO_ACTION, 0}},    /* busy */
364                {{BTA_DM_PM_NO_ACTION, 0},
365                 {BTA_DM_PM_NO_ACTION, 0}} /* mode change retry */
366            }},
367 
368           /* PANU : 10 */
369           {(BTA_DM_PM_SNIFF), /* allow sniff */
370            (BTA_DM_PM_SSR2),  /* the SSR entry */
371            {
372                {{BTA_DM_PM_ACTIVE, 0},
373                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn open  active */
374                {{BTA_DM_PM_NO_PREF, 0},
375                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn close  */
376                {{BTA_DM_PM_ACTIVE, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* app open */
377                {{BTA_DM_PM_NO_ACTION, 0},
378                 {BTA_DM_PM_NO_ACTION, 0}}, /* app close */
379                {{BTA_DM_PM_NO_ACTION, 0},
380                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco open  */
381                {{BTA_DM_PM_NO_ACTION, 0},
382                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco close   */
383                {{BTA_DM_PM_SNIFF_A2DP_IDX, 5000},
384                 {BTA_DM_PM_NO_ACTION, 0}},                        /* idle */
385                {{BTA_DM_PM_ACTIVE, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* busy */
386                {{BTA_DM_PM_NO_ACTION, 0},
387                 {BTA_DM_PM_NO_ACTION, 0}} /* mode change retry */
388            }},
389 
390           /* NAP : 11 */
391           {(BTA_DM_PM_SNIFF), /* allow sniff */
392            (BTA_DM_PM_SSR2),  /* the SSR entry */
393            {
394                {{BTA_DM_PM_ACTIVE, 0},
395                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn open  active */
396                {{BTA_DM_PM_NO_PREF, 0},
397                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn close  */
398                {{BTA_DM_PM_ACTIVE, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* app open */
399                {{BTA_DM_PM_NO_ACTION, 0},
400                 {BTA_DM_PM_NO_ACTION, 0}}, /* app close */
401                {{BTA_DM_PM_NO_ACTION, 0},
402                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco open  */
403                {{BTA_DM_PM_NO_ACTION, 0},
404                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco close   */
405                {{BTA_DM_PM_SNIFF_A2DP_IDX, 5000},
406                 {BTA_DM_PM_NO_ACTION, 0}},                        /* idle */
407                {{BTA_DM_PM_ACTIVE, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* busy */
408 
409                {{BTA_DM_PM_NO_ACTION, 0},
410                 {BTA_DM_PM_NO_ACTION, 0}} /* mode change retry */
411            }},
412 
413           /* HS : 12 */
414           {(BTA_DM_PM_SNIFF | BTA_DM_PM_PARK), /* allow park & sniff */
415            (BTA_DM_PM_SSR2),                   /* the SSR entry */
416            {
417                {{BTA_DM_PM_SNIFF, hs_sniff_delay},
418                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn open sniff  */
419                {{BTA_DM_PM_NO_PREF, 0},
420                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn close  */
421                {{BTA_DM_PM_NO_ACTION, 0},
422                 {BTA_DM_PM_NO_ACTION, 0}}, /* app open */
423                {{BTA_DM_PM_NO_ACTION, 0},
424                 {BTA_DM_PM_NO_ACTION, 0}}, /* app close */
425                {{BTA_DM_PM_SNIFF3, 7000},
426                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco open, active */
427                {{BTA_DM_PM_SNIFF, 7000},
428                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco close sniff  */
429                {{BTA_DM_PM_SNIFF, hs_sniff_delay},
430                 {BTA_DM_PM_NO_ACTION, 0}},                        /* idle */
431                {{BTA_DM_PM_ACTIVE, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* busy */
432                {{BTA_DM_PM_RETRY, 7000},
433                 {BTA_DM_PM_NO_ACTION, 0}} /* mode change retry */
434            }},
435 
436           /* AVK : 13 */
437           {(BTA_DM_PM_SNIFF), /* allow sniff */
438            (BTA_DM_PM_SSR2),  /* the SSR entry */
439            {
440                {{BTA_DM_PM_SNIFF, 3000},
441                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn open  sniff */
442                {{BTA_DM_PM_NO_PREF, 0},
443                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn close  */
444                {{BTA_DM_PM_NO_ACTION, 0},
445                 {BTA_DM_PM_NO_ACTION, 0}}, /* app open */
446                {{BTA_DM_PM_NO_ACTION, 0},
447                 {BTA_DM_PM_NO_ACTION, 0}}, /* app close */
448                {{BTA_DM_PM_NO_ACTION, 0},
449                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco open  */
450                {{BTA_DM_PM_NO_ACTION, 0},
451                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco close   */
452                {{BTA_DM_PM_SNIFF4, 3000}, {BTA_DM_PM_NO_ACTION, 0}}, /* idle */
453                {{BTA_DM_PM_ACTIVE, 0}, {BTA_DM_PM_NO_ACTION, 0}},    /* busy */
454                {{BTA_DM_PM_NO_ACTION, 0},
455                 {BTA_DM_PM_NO_ACTION, 0}} /* mode change retry */
456            }},
457 
458           /* GATTC : 14 */
459           {(BTA_DM_PM_SNIFF | BTA_DM_PM_PARK), /* allow park & sniff */
460            (BTA_DM_PM_SSR2),                   /* the SSR entry */
461            {
462                {{BTA_DM_PM_SNIFF_A2DP_IDX, 10000},
463                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn open  active */
464                {{BTA_DM_PM_NO_PREF, 0},
465                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn close  */
466                {{BTA_DM_PM_ACTIVE, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* app open */
467                {{BTA_DM_PM_NO_ACTION, 0},
468                 {BTA_DM_PM_NO_ACTION, 0}}, /* app close */
469                {{BTA_DM_PM_NO_ACTION, 0},
470                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco open  */
471                {{BTA_DM_PM_NO_ACTION, 0},
472                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco close   */
473                {{BTA_DM_PM_SNIFF_A2DP_IDX, 10000},
474                 {BTA_DM_PM_NO_ACTION, 0}},                        /* idle */
475                {{BTA_DM_PM_ACTIVE, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* busy */
476                {{BTA_DM_PM_RETRY, 5000},
477                 {BTA_DM_PM_NO_ACTION, 0}} /* mode change retry */
478            }},
479 
480           /* GATTS : 15 */
481           {(BTA_DM_PM_SNIFF | BTA_DM_PM_PARK), /* allow park & sniff */
482            (BTA_DM_PM_SSR2),                   /* the SSR entry */
483            {
484                {{BTA_DM_PM_NO_PREF, 0},
485                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn open  active */
486                {{BTA_DM_PM_NO_PREF, 0},
487                 {BTA_DM_PM_NO_ACTION, 0}}, /* conn close  */
488                {{BTA_DM_PM_NO_PREF, 0},
489                 {BTA_DM_PM_NO_ACTION, 0}}, /* app open */
490                {{BTA_DM_PM_NO_PREF, 0},
491                 {BTA_DM_PM_NO_ACTION, 0}}, /* app close */
492                {{BTA_DM_PM_NO_PREF, 0},
493                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco open  */
494                {{BTA_DM_PM_NO_PREF, 0},
495                 {BTA_DM_PM_NO_ACTION, 0}}, /* sco close */
496                {{BTA_DM_PM_NO_PREF, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* idle */
497                {{BTA_DM_PM_NO_PREF, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* busy */
498                {{BTA_DM_PM_RETRY, 5000},
499                 {BTA_DM_PM_NO_ACTION, 0}} /* mode change retry */
500            }}
501 
502 #ifdef BTE_SIM_APP /* For Insight builds only */
503           /* Entries at the end of the pm_spec table are user-defined (runtime
504              configurable),
505              for power consumption experiments.
506              Insight finds the first user-defined entry by looking for the first
507              BTA_DM_PM_NO_PREF.
508              The number of user_defined specs is defined by
509              BTA_SWRAP_UD_PM_SPEC_COUNT */
510           ,
511           {BTA_DM_PM_NO_PREF}, /* pm_spec USER_DEFINED_0 */
512           {BTA_DM_PM_NO_PREF}  /* pm_spec USER_DEFINED_1 */
513 #endif                   /* BTE_SIM_APP */
514       };
515   return bta_dm_pm_spec;
516 }
517 
518 /* Please refer to the SNIFF table definitions in bta_api.h.
519  *
520  * Adding to or Modifying the Table
521  * Additional sniff parameter entries can be added for BTA_DM_PM_SNIFF6 -
522  * BTA_DM_PM_SNIFF7.
523  * Overrides of additional table entries can be specified in bdroid_buildcfg.h.
524  * If additional
525  * sniff parameter entries are added or an override of an existing entry is
526  * specified in
527  * bdroid_buildcfg.h then the BTA_DM_PM_*_IDX defines in bta_api.h will need to
528  * be match the new
529  * ordering.
530  *
531  * Table Ordering
532  * Sniff Table entries must be ordered from highest latency (biggest interval)
533  * to lowest latency.
534  * If there is a conflict among the connected services the setting with the
535  * lowest latency will
536  * be selected.
537  */
538 tBTA_DM_PM_TYPE_QUALIFIER tBTM_PM_PWR_MD bta_dm_pm_md[] = {
539     /*
540      * More sniff parameter entries can be added for
541      * BTA_DM_PM_SNIFF3 - BTA_DM_PM_SNIFF7, if needed. When entries are added or
542      * removed, BTA_DM_PM_PARK_IDX needs to be updated to reflect the actual
543      * index
544      * BTA_DM_PM_PARK_IDX is defined in bta_api.h and can be override by the
545      * bdroid_buildcfg.h settings.
546      * The SNIFF table entries must be in the order from highest latency
547      * (biggest
548      * interval) to lowest latency. If there's a conflict among the connected
549      * services, the setting with lowest latency wins.
550      */
551     /* sniff modes: max interval, min interval, attempt, timeout */
552     {BTA_DM_PM_SNIFF_MAX, BTA_DM_PM_SNIFF_MIN, BTA_DM_PM_SNIFF_ATTEMPT,
553      BTA_DM_PM_SNIFF_TIMEOUT, BTM_PM_MD_SNIFF}, /* for BTA_DM_PM_SNIFF - A2DP */
554     {BTA_DM_PM_SNIFF1_MAX, BTA_DM_PM_SNIFF1_MIN, BTA_DM_PM_SNIFF1_ATTEMPT,
555      BTA_DM_PM_SNIFF1_TIMEOUT, BTM_PM_MD_SNIFF}, /* for BTA_DM_PM_SNIFF1 */
556     {BTA_DM_PM_SNIFF2_MAX, BTA_DM_PM_SNIFF2_MIN, BTA_DM_PM_SNIFF2_ATTEMPT,
557      BTA_DM_PM_SNIFF2_TIMEOUT,
558      BTM_PM_MD_SNIFF}, /* for BTA_DM_PM_SNIFF2- HD idle */
559     {BTA_DM_PM_SNIFF3_MAX, BTA_DM_PM_SNIFF3_MIN, BTA_DM_PM_SNIFF3_ATTEMPT,
560      BTA_DM_PM_SNIFF3_TIMEOUT,
561      BTM_PM_MD_SNIFF}, /* for BTA_DM_PM_SNIFF3- SCO open */
562     {BTA_DM_PM_SNIFF4_MAX, BTA_DM_PM_SNIFF4_MIN, BTA_DM_PM_SNIFF4_ATTEMPT,
563      BTA_DM_PM_SNIFF4_TIMEOUT,
564      BTM_PM_MD_SNIFF}, /* for BTA_DM_PM_SNIFF4- HD active */
565     {BTA_DM_PM_SNIFF5_MAX, BTA_DM_PM_SNIFF5_MIN, BTA_DM_PM_SNIFF5_ATTEMPT,
566      BTA_DM_PM_SNIFF5_TIMEOUT,
567      BTM_PM_MD_SNIFF}, /* for BTA_DM_PM_SNIFF5- HD active */
568     {BTA_DM_PM_SNIFF6_MAX, BTA_DM_PM_SNIFF6_MIN, BTA_DM_PM_SNIFF6_ATTEMPT,
569      BTA_DM_PM_SNIFF6_TIMEOUT,
570      BTM_PM_MD_SNIFF}, /* for BTA_DM_PM_SNIFF6- HD active */
571     {BTA_DM_PM_PARK_MAX, BTA_DM_PM_PARK_MIN, BTA_DM_PM_PARK_ATTEMPT,
572      BTA_DM_PM_PARK_TIMEOUT, BTM_PM_MD_PARK}
573 
574 #ifdef BTE_SIM_APP /* For Insight builds only */
575     /* Entries at the end of the bta_dm_pm_md table are user-defined (runtime
576        configurable),
577        for power consumption experiments.
578        Insight finds the first user-defined entry by looking for the first
579        'max=0'.
580        The number of user_defined specs is defined by BTA_SWRAP_UD_PM_DM_COUNT
581        */
582     ,
583     {0}, /* CONN_OPEN/SCO_CLOSE power mode settings for pm_spec USER_DEFINED_0
584             */
585     {0}, /* SCO_OPEN power mode settings for pm_spec USER_DEFINED_0 */
586 
587     {0}, /* CONN_OPEN/SCO_CLOSE power mode settings for pm_spec USER_DEFINED_1
588             */
589     {0}  /* SCO_OPEN power mode settings for pm_spec USER_DEFINED_1 */
590 #endif   /* BTE_SIM_APP */
591 };
592 
593 /* 0=max_lat -> no SSR */
594 /* the smaller of the SSR max latency wins.
595  * the entries in this table must be from highest latency (biggest interval) to
596  * lowest latency */
597 tBTA_DM_SSR_SPEC bta_dm_ssr_spec[] = {
598     /*max_lat, min_rmt_to, min_loc_to*/
599     {0, 0, 0, "no_ssr"}, /* BTA_DM_PM_SSR0 - do not use SSR */
600     /* BTA_DM_PM_SSR1 - HH, can NOT share entry with any other profile, seting
601        default max latency and min remote timeout as 0, and always read
602        individual device preference from HH module */
603     {0, 0, 2, "hid_host"},
604     {1200, 2, 2, "sniff_capable"},  /* BTA_DM_PM_SSR2 - others (as long as sniff
605                                        is allowed)*/
606     {360, 160, 1600, "hid_device"}, /* BTA_DM_PM_SSR3 - HD */
607     {1200, 65534, 65534, "a2dp"}    /* BTA_DM_PM_SSR4 - A2DP streaming */
608 };
609 
610 tBTA_DM_SSR_SPEC* p_bta_dm_ssr_spec = &bta_dm_ssr_spec[0];
611 
612 const tBTA_DM_PM_CFG* p_bta_dm_pm_cfg = &bta_dm_pm_cfg[0];
613 const tBTM_PM_PWR_MD* p_bta_dm_pm_md = &bta_dm_pm_md[0];
614 
615 /* The performance impact of EIR packet size
616  *
617  * 1 to 17 bytes,    DM1 is used and most robust.
618  * 18 to 121 bytes,  DM3 is used but impacts inquiry scan time with large number
619  *                    of devices.(almost double with 150 users)
620  * 122 to 224 bytes, DM5 is used but cause quite big performance loss even with
621  *                    small number of users. so it is not recommended.
622  * 225 to 240 bytes, DH5 is used without FEC but it not recommended.
623  *                    (same reason of DM5)
624  */
625 
626 /* Extended Inquiry Response */
627 const tBTA_DM_EIR_CONF bta_dm_eir_cfg = {
628     50, /* minimum length of local name when it is shortened */
629         /* if length of local name is longer than this and EIR has not enough */
630         /* room for all UUID list then local name is shortened to this length */
631     {
632         /* mask of UUID list in EIR */
633         0xFFFFFFFF, /* LSB is the first UUID of the first 32 UUIDs in
634                        BTM_EIR_UUID_LKUP_TBL */
635         0xFFFFFFFF  /* LSB is the first UUID of the next 32 UUIDs in
636                        BTM_EIR_UUID_LKUP_TBL */
637                     /* BTM_EIR_UUID_LKUP_TBL can be overrided */
638     },
639     NULL, /* Inquiry TX power         */
640     0,    /* length of flags in bytes */
641     NULL, /* flags for EIR */
642     0,    /* length of manufacturer specific in bytes */
643     NULL, /* manufacturer specific */
644     0,    /* length of additional data in bytes */
645     NULL  /* additional data */
646 };
647 const tBTA_DM_EIR_CONF* p_bta_dm_eir_cfg = &bta_dm_eir_cfg;
648