blob: 6bf885fde044c90036692f260e4f2366595ccb9a [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
3 * Copyright (C) 2009-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#ifndef BTIF_COMMON_H
20#define BTIF_COMMON_H
21
22#include "data_types.h"
23#include "bt_types.h"
24#include "bta_api.h"
25
26#ifndef LOG_TAG
27#error "LOG_TAG not defined, please add in .c file prior to including bt_common.h"
28#endif
29
30#include <utils/Log.h>
31
32/*******************************************************************************
33** Constants & Macros
34********************************************************************************/
35
36#define ASSERTC(cond, msg, val) if (!(cond)) { ALOGE( \
37 "### ASSERT : %s line %d %s (%d) ###", __FILE__, __LINE__, msg, val);}
38
39/* Calculate start of event enumeration; id is top 8 bits of event */
40#define BTIF_SIG_START(id) ((id) << 8)
41
42/* For upstream the MSB bit is always SET */
43#define BTIF_SIG_CB_BIT (0x8000)
44#define BTIF_SIG_CB_START(id) (((id) << 8) | BTIF_SIG_CB_BIT)
45
46/* BTIF sub-systems */
47#define BTIF_CORE 0
48#define BTIF_DM 1
49#define BTIF_HFP 2
50#define BTIF_AV 3
51#define BTIF_PAN 4
52
53extern bt_callbacks_t *bt_hal_cbacks;
54
55#define HAL_CBACK(P_CB, P_CBACK, ...)\
56 if (P_CB && P_CB->P_CBACK) { \
The Android Open Source Project689d66b2012-12-12 17:18:15 -080057 BTIF_TRACE_API2("HAL %s->%s", #P_CB, #P_CBACK); \
The Android Open Source Project5738f832012-12-12 16:00:35 -080058 P_CB->P_CBACK(__VA_ARGS__); \
59 } \
60 else { \
61 ASSERTC(0, "Callback is NULL", 0); \
62 }
63
64/**
65 * BTIF events for requests that require context switch to btif task
66 * on downstreams path
67 */
68enum
69{
70 BTIF_CORE_API_START = BTIF_SIG_START(BTIF_CORE),
71 BTIF_CORE_STORAGE_NO_ACTION,
72 BTIF_CORE_STORAGE_ADAPTER_WRITE,
73 BTIF_CORE_STORAGE_ADAPTER_READ,
74 BTIF_CORE_STORAGE_ADAPTER_READ_ALL,
75 BTIF_CORE_STORAGE_REMOTE_WRITE,
76 BTIF_CORE_STORAGE_REMOTE_READ,
77 BTIF_CORE_STORAGE_REMOTE_READ_ALL,
78 BTIF_CORE_STORAGE_READ_ALL,
79 BTIF_CORE_STORAGE_NOTIFY_STATUS,
80 /* add here */
81
82 BTIF_DM_API_START = BTIF_SIG_START(BTIF_DM),
83 BTIF_DM_ENABLE_SERVICE,
84 BTIF_DM_DISABLE_SERVICE,
85 /* add here */
86
87 BTIF_HFP_API_START = BTIF_SIG_START(BTIF_HFP),
88 /* add here */
89
90 BTIF_AV_API_START = BTIF_SIG_START(BTIF_AV),
91 /* add here */
92};
93
94/**
95 * BTIF events for callbacks that require context switch to btif task
96 * on upstream path - Typically these would be non-BTA events
97 * that are generated by the BTIF layer.
98 */
99enum
100{
101 BTIF_CORE_CB_START = BTIF_SIG_CB_START(BTIF_CORE),
102 /* add here */
103
104 BTIF_DM_CB_START = BTIF_SIG_CB_START(BTIF_DM),
105 BTIF_DM_CB_DISCOVERY_STARTED, /* Discovery has started */
106 BTIF_DM_CB_CREATE_BOND, /* Create bond */
107 BTIF_DM_CB_REMOVE_BOND, /*Remove bond */
108 BTIF_DM_CB_HID_REMOTE_NAME, /* Remote name callback for HID device */
109 BTIF_DM_CB_BOND_STATE_BONDING,
110
111 BTIF_HFP_CB_START = BTIF_SIG_CB_START(BTIF_HFP),
112 BTIF_HFP_CB_AUDIO_CONNECTING, /* HF AUDIO connect has been sent to BTA successfully */
113
114 BTIF_PAN_CB_START = BTIF_SIG_CB_START(BTIF_PAN),
115 BTIF_PAN_CB_DISCONNECTING, /* PAN Disconnect has been sent to BTA successfully */
116};
117
118/* Macro definitions for BD ADDR persistence */
119
120/**
121 * PROPERTY_BT_BDADDR_PATH
122 * The property key stores the storage location of Bluetooth Device Address
123 */
124#ifndef PROPERTY_BT_BDADDR_PATH
125#define PROPERTY_BT_BDADDR_PATH "ro.bt.bdaddr_path"
126#endif
127
128/**
129 * PERSIST_BDADDR_PROPERTY
130 * If there is no valid bdaddr available from PROPERTY_BT_BDADDR_PATH,
131 * generating a random BDADDR and keeping it in the PERSIST_BDADDR_DROP.
132 */
133#ifndef PERSIST_BDADDR_PROPERTY
134#define PERSIST_BDADDR_PROPERTY "persist.service.bdroid.bdaddr"
135#endif
136
137#define FACTORY_BT_BDADDR_STORAGE_LEN 17
138
139
140/*******************************************************************************
141** Type definitions for callback functions
142********************************************************************************/
143
144typedef void (tBTIF_CBACK) (UINT16 event, char *p_param);
145typedef void (tBTIF_COPY_CBACK) (UINT16 event, char *p_dest, char *p_src);
146
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********************************************************************************/
167
168bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char* p_params,
169 int param_len, tBTIF_COPY_CBACK *p_copy_cback);
170tBTA_SERVICE_MASK btif_get_enabled_services_mask(void);
171bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id);
172bt_status_t btif_disable_service(tBTA_SERVICE_ID service_id);
173int btif_is_enabled(void);
174
175/**
176 * BTIF_Events
177 */
178void btif_enable_bluetooth_evt(tBTA_STATUS status, BD_ADDR local_bd);
179void btif_disable_bluetooth_evt(void);
180void btif_adapter_properties_evt(bt_status_t status, uint32_t num_props, bt_property_t *p_props);
181void btif_remote_properties_evt(bt_status_t status, bt_bdaddr_t *remote_addr,
182 uint32_t num_props, bt_property_t *p_props);
183#endif /* BTIF_COMMON_H */