btif_common.h revision 254588bfe6c3e70625b0f725b908598f30f476c8
1/************************************************************************************
2 *
3 *  Copyright (C) 2009-2012 Broadcom Corporation
4 *
5 *  This program is the proprietary software of Broadcom Corporation and/or its
6 *  licensors, and may only be used, duplicated, modified or distributed
7 *  pursuant to the terms and conditions of a separate, written license
8 *  agreement executed between you and Broadcom (an "Authorized License").
9 *  Except as set forth in an Authorized License, Broadcom grants no license
10 *  (express or implied), right to use, or waiver of any kind with respect to
11 *  the Software, and Broadcom expressly reserves all rights in and to the
12 *  Software and all intellectual property rights therein.
13 *  IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS
14 *  SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE
15 *  ALL USE OF THE SOFTWARE.
16 *
17 *  Except as expressly set forth in the Authorized License,
18 *
19 *  1.     This program, including its structure, sequence and organization,
20 *         constitutes the valuable trade secrets of Broadcom, and you shall
21 *         use all reasonable efforts to protect the confidentiality thereof,
22 *         and to use this information only in connection with your use of
23 *         Broadcom integrated circuit products.
24 *
25 *  2.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED
26 *         "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES,
27 *         REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY,
28 *         OR OTHERWISE, WITH RESPECT TO THE SOFTWARE.  BROADCOM SPECIFICALLY
29 *         DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY,
30 *         NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES,
31 *         ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
32 *         CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT
33 *         OF USE OR PERFORMANCE OF THE SOFTWARE.
34 *
35 *  3.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR
36 *         ITS LICENSORS BE LIABLE FOR
37 *         (i)   CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY
38 *               DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO
39 *               YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM
40 *               HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR
41 *         (ii)  ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE
42 *               SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE
43 *               LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF
44 *               ESSENTIAL PURPOSE OF ANY LIMITED REMEDY.
45 *
46 ************************************************************************************/
47
48/************************************************************************************
49 *
50 *  Filename:      btif_common.h
51 *
52 *  Description:
53 *
54 ***********************************************************************************/
55
56#ifndef BTIF_COMMON_H
57#define BTIF_COMMON_H
58
59#include "data_types.h"
60#include "bt_types.h"
61#include "bta_api.h"
62
63#ifndef LOG_TAG
64#error "LOG_TAG not defined, please add in .c file prior to including bt_common.h"
65#endif
66
67#include <utils/Log.h>
68
69/************************************************************************************
70**  Constants & Macros
71************************************************************************************/
72
73#define ASSERTC(cond, msg, val) if (!(cond)) {LOGE("### ASSERT : %s line %d %s (%d) ###", __FILE__, __LINE__, msg, val);}
74
75/* Calculate start of event enumeration; id is top 8 bits of event */
76#define BTIF_SIG_START(id)       ((id) << 8)
77
78/* for upstream the MSB bit is always SET */
79#define BTIF_SIG_CB_BIT   (0x8000)
80#define BTIF_SIG_CB_START(id)    (((id) << 8) | BTIF_SIG_CB_BIT)
81
82/* BTIF sub-systems */
83#define BTIF_CORE           0 /* core */
84#define BTIF_DM             1
85#define BTIF_HFP            2
86#define BTIF_AV             3
87
88extern bt_callbacks_t *bt_hal_cbacks;
89
90#define HAL_CBACK(P_CB, P_CBACK, ...)\
91    if (P_CB && P_CB->P_CBACK) {            \
92        LOGD("HAL %s->%s", #P_CB, #P_CBACK); \
93        P_CB->P_CBACK(__VA_ARGS__);         \
94    }                                       \
95    else {                                  \
96        ASSERTC(0, "Callback is NULL", 0);  \
97    }
98
99/* btif events for requests that require context switch to btif task
100   on downstreams path */
101enum
102{
103    BTIF_CORE_API_START = BTIF_SIG_START(BTIF_CORE),
104    BTIF_CORE_STORAGE_NO_ACTION,
105    BTIF_CORE_STORAGE_ADAPTER_WRITE,
106    BTIF_CORE_STORAGE_ADAPTER_READ,
107    BTIF_CORE_STORAGE_ADAPTER_READ_ALL,
108    BTIF_CORE_STORAGE_REMOTE_WRITE,
109    BTIF_CORE_STORAGE_REMOTE_READ,
110    BTIF_CORE_STORAGE_REMOTE_READ_ALL,
111    BTIF_CORE_STORAGE_READ_ALL,
112    BTIF_CORE_STORAGE_NOTIFY_STATUS,
113    /* add here */
114
115    BTIF_DM_API_START = BTIF_SIG_START(BTIF_DM),
116    BTIF_DM_ENABLE_SERVICE,
117    BTIF_DM_DISABLE_SERVICE,
118    /* add here */
119
120    BTIF_HFP_API_START = BTIF_SIG_START(BTIF_HFP),
121    /* add here */
122
123    BTIF_AV_API_START = BTIF_SIG_START(BTIF_AV),
124    /* add here */
125
126};
127
128/* btif events for callbacks that require context switch to btif task
129  on upstream path - Typically these would be non-BTA events
130  that are generated by the BTIF layer */
131enum
132{
133    BTIF_CORE_CB_START = BTIF_SIG_CB_START(BTIF_CORE),
134    /* add here */
135
136    BTIF_DM_CB_START = BTIF_SIG_CB_START(BTIF_DM),
137    BTIF_DM_CB_DISCOVERY_STARTED, /* Discovery has started */
138    BTIF_DM_CB_BONDING_STARTED,   /* Bonding process has started */
139};
140
141/************************************************************************************
142**  Type definitions for callback functions
143************************************************************************************/
144
145typedef void (tBTIF_CBACK) (UINT16 event, char *p_param);
146typedef void (tBTIF_COPY_CBACK) (UINT16 event, char *p_dest, char *p_src);
147
148/************************************************************************************
149**  Type definitions and return values
150************************************************************************************/
151
152/* this type handles all btif context switches between BTU and HAL */
153typedef struct
154{
155    BT_HDR               hdr;
156    tBTIF_CBACK*         p_cb;    /* context switch callback */
157
158    /* parameters passed to callback */
159    UINT16               event;   /* message event id */
160    char                 p_param[0]; /* parameter area needs to be last */
161} tBTIF_CONTEXT_SWITCH_CBACK;
162
163
164/************************************************************************************
165**  Functions
166************************************************************************************/
167bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char* p_params, int param_len, tBTIF_COPY_CBACK *p_copy_cback);
168tBTA_SERVICE_MASK btif_get_enabled_services_mask(void);
169bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id);
170bt_status_t btif_disable_service(tBTA_SERVICE_ID service_id);
171
172/*
173 * BTIF_Events
174 */
175
176void btif_enable_bluetooth_evt(tBTA_STATUS status, BD_ADDR local_bd);
177void btif_disable_bluetooth_evt(void);
178void btif_adapter_properties_evt(bt_status_t status, uint32_t num_props, bt_property_t *p_props);
179void btif_remote_properties_evt(bt_status_t status, bt_bdaddr_t *remote_addr,
180                                   uint32_t num_props, bt_property_t *p_props);
181#endif /* BTIF_COMMON_H */
182
183