1/******************************************************************************
2 *
3 *  Copyright (C) 2002-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 is the interface file for the bte application task
22 *
23 ******************************************************************************/
24
25#ifndef BTE_APPL_H
26#define BTE_APPL_H
27
28#include "btm_int.h"
29#include "bta_api.h"
30#include "bta_sys.h"
31#include "bte.h"
32
33/* Maximum length for serial port device name */
34#ifndef BTE_APPL_MAX_USERIAL_DEV_NAME
35#define BTE_APPL_MAX_USERIAL_DEV_NAME       (256)
36#endif
37#ifndef BTAPP_AHF_API_SUPPORT
38#define BTAPP_AHF_API_SUPPORT FALSE
39#endif
40
41/* BTA APP_IDs */
42#define UI_DM_ID    1
43#define UI_PRM_ID   20
44/* this defines the enabled BTA modules. client may not be defined as those are enabled at run time.
45 * they are defined for completeness. please check with bta_sys.h for new modules.
46 * BTA_ID_DM serves as flag for BTA_EnableBluetooth()
47 * BTA_ID_RES can be used to fs ID in bte_appl.
48 */
49
50#define BTAPP_NUM_ID_BLOCKS ((BTA_ID_MAX/32)+1)        /* number of 32 bit required to store one bit per
51                                                            btapp id */
52
53#define BTAPP_APPL_MAIL_EVENT(x)  (x<<8)    /* define bte_appl task mail box event. LSB contains
54                                                BTA_ID_xxx (see bta_sys.h) */
55#define BTAPP_APPL_MAIL_EVT       0xff00    /* high byte contains bitmap of application module event */
56
57/* helper macro to copy BTA callack data y into message buffer x, for event data structure z */
58#define MEMCPY_APPL_MSG(x, y, z)  memcpy( (void *)(((UINT8 *)x)+sizeof(BT_HDR)), (void *)y, sizeof(z) )
59
60/* Event masks for BTE_APPL_TASK */
61#define BTE_APPL_STARTUP_EVT    EVENT_MASK(APPL_EVT_0)      /* Bluetooth has started */
62#define BTE_APPL_SHUTDOWN_EVT   EVENT_MASK(APPL_EVT_1)      /* Bluetooth is shutting down */
63#define BTE_APPL_SOCKET_RX_EVT  EVENT_MASK(APPL_EVT_2)      /* Socket data ready to be read */
64#define BTE_APPL_DBUS_RX_EVT    EVENT_MASK(APPL_EVT_3)      /* DBUS message ready to be read */
65#define BTE_APPL_BTA_ENABLE_EVT EVENT_MASK(APPL_EVT_4)      /* BTA Enabled event */
66
67
68/* Application configuration */
69#define BTE_APPL_PATCHRAM_PATH_MAXLEN   128
70#define BTE_APPL_CONTACTS_DB_PATH       256
71
72typedef struct {
73#if ((BLE_INCLUDED == TRUE) && (SMP_INCLUDED == TRUE))
74    UINT8   ble_auth_req;
75    UINT8   ble_io_cap;
76    UINT8   ble_init_key;
77    UINT8   ble_resp_key;
78    UINT8   ble_max_key_size;
79#endif
80} tBTE_APPL_CFG;
81
82extern tBTE_APPL_CFG bte_appl_cfg;
83
84typedef struct {
85    pthread_mutex_t     mutex;  /* mutex to protect below signal condition */
86    pthread_cond_t      cond;   /* signal event */
87} tBTAPP_SEMAPHORE;
88
89/* helper functions to handle pthread conditions event from outside GKI */
90extern void bte_create_semaphore( tBTAPP_SEMAPHORE * p_sema );
91extern void bte_wait_semaphore( tBTAPP_SEMAPHORE * p_sema, unsigned msecs_to );
92extern void bte_signal_semaphore( tBTAPP_SEMAPHORE * p_sema );
93extern void bte_destroy_semaphore( tBTAPP_SEMAPHORE * p_sema );
94
95/* global application control block storing global application states and variables */
96typedef struct tBTE_APPL_CB_tag {
97    sigset_t            signal_handler_set;        /* signal handler set used by signal handler thread */
98#if ( TRUE == BTE_RESET_BAUD_ON_BT_DISABLE )
99    tBTAPP_SEMAPHORE    shutdown_semaphore;   /* used to sync with  terminate handler initated ops */
100#endif
101    BOOLEAN amp_enabled;                        /* TRUE if AMP is in use */
102} tBTE_APPL_CB;
103
104extern tBTE_APPL_CB bte_appl_cb;
105
106/* Exports the application task */
107extern void BTE_appl_task(UINT32 params);
108extern int BTAPP_enable_bta( const UINT32 bta_module_state[BTAPP_NUM_ID_BLOCKS], int includingFM );
109extern int BTAPP_disable_bta( const UINT32 bta_module_state[BTAPP_NUM_ID_BLOCKS], int includingFM );
110
111extern UINT8 appl_trace_level;
112#define BT_PCM_CLK_IDX 1
113#ifndef BT_PCM_DEF_CLK
114#define BT_PCM_DEF_CLK 4       /* defaults to 2048khz PCM clk */
115#endif
116#define BT_PCM_SYNC_MS_ROLE_IDX 3
117#define BT_PCM_CLK_MS_ROLE_IDX  4
118#ifndef BT_PCM_DEF_ROLE
119#define BT_PCM_DEF_ROLE    0x00     /* assume slave as default */
120#endif
121
122/* helper macros to set, clear and get current BTA module id in a 32bit ARRAY!! */
123/* set bit id to 1 in UINT32 a[] NO RANGE CHECK!*/
124#define BTAPP_SET_BTA_MOD(id, a)    { a[id/32] |= (UINT32)(1<<(id % 32)); }
125
126/* set bit id to 0 (cleared) in UINT32 a[] NO RANGE CHECK */
127#define BTAPP_CLEAR_BTA_MOD(id, a)  { a[id/32] &= (UINT32)!(1<<(id % 32)); }
128
129/* tests if bit id is 1 in UINT32 a[] NO RANGE CHECK */
130#define BTAPP_BTA_MOD_IS_SET(id, a) (a[id/32] & (UINT32)(1<<(id % 32)))
131
132/* update this list either via btld.txt or directly here by adding the new profiles as per bta_sys.h.
133 * each xxx_LISTx may only contain 32 bits */
134#ifndef BTAPP_BTA_MODULES_LIST0
135#define BTAPP_BTA_MODULES_LIST0 (\
136        ( 1<<BTA_ID_DM ) | \
137        ( 1<<BTA_ID_DG ) | \
138        ( 1<<BTA_ID_AG ) | \
139        ( 1<<BTA_ID_OPC )| \
140        ( 1<<BTA_ID_OPS )| \
141        ( 1<<BTA_ID_FTS )| \
142        ( 1<<BTA_ID_PAN )| \
143        ( 1<<BTA_ID_PR ) | \
144        ( 1<<BTA_ID_SC)  | \
145        ( 1<<BTA_ID_AV ) | \
146        ( 1<<BTA_ID_HH ) | \
147        ( 1<<BTA_ID_PBS) | \
148        ( 1<<BTA_ID_FMTX)| \
149        ( 1<<BTA_ID_JV) | \
150        ( 1<<BTA_ID_MSE) \
151        )
152#endif
153
154#define BTAPP_LIST1_BLOCK 32    /* next 32 bit block */
155#ifndef BTAPP_BTA_MODULES_LIST1
156#define BTAPP_BTA_MODULES_LIST1 (\
157        ( 1<<(BTA_ID_MAX-BTAPP_LIST1_BLOCK) ) | \
158        ( 1<<(BTA_ID_MSE-BTAPP_LIST1_BLOCK) ) | \
159        0 \
160        )
161#endif
162/* for future GPS etc support. goes int LIST1 above */
163#if 0
164    ( 1<<(BTA_ID_SSR-BTAPP_LIST1_BLOCK) ) \
165    ( 1<<(BTA_ID_MSE-BTAPP_LIST1_BLOCK) ) \
166    ( 1<<(BTA_ID_MCE-BTAPP_LIST1_BLOCK) )
167#endif
168
169/* used application init default in bte_main.c, bte_appl_cfg */
170#ifndef BTAPP_DEFAULT_MODULES
171#if (1==BTAPP_NUM_ID_BLOCKS)
172#define BTAPP_DEFAULT_MODULES {BTAPP_BTA_MODULES_LIST0} /* max 32 modules IDs */
173#elif (2==BTAPP_NUM_ID_BLOCKS)
174#define BTAPP_DEFAULT_MODULES {BTAPP_BTA_MODULES_LIST0, BTAPP_BTA_MODULES_LIST1} /* 64 module IDs max */
175#else
176#error "Define more BTAPP_BTA_MODULES_LISTx"
177#endif
178#endif
179
180#endif  /* BTE_APPL_H */
181