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