blob: c53c8e5768ad697ce070aa4679d31c091e174c2f [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
Hemant Gupta10256872013-08-19 18:33:01 +05303 * Copyright (c) 2014 The Android Open Source Project
The Android Open Source Project5738f832012-12-12 16:00:35 -08004 * Copyright (C) 2009-2012 Broadcom Corporation
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 ******************************************************************************/
19
20#ifndef BTIF_COMMON_H
21#define BTIF_COMMON_H
22
Vinit Deshpandef54df6b2015-04-15 13:02:58 -070023#include <stdlib.h>
Marie Janssendb554582015-06-26 14:53:46 -070024
Chris Manton0eefef02014-09-08 15:01:39 -070025#include <hardware/bluetooth.h>
26
Pavlin Radoslavovc196f212015-09-23 20:39:53 -070027#include "osi/include/osi.h"
28#include "osi/include/log.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080029#include "bt_types.h"
30#include "bta_api.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080031
32/*******************************************************************************
33** Constants & Macros
34********************************************************************************/
35
Marie Janssendb554582015-06-26 14:53:46 -070036#define ASSERTC(cond, msg, val) if (!(cond)) { LOG_ERROR(LOG_TAG, \
Balraj Selvaraj234af832016-01-06 11:18:32 +053037 "### ASSERT : %s %s line %d %s (%d) ###", __FILE__, __func__, __LINE__, msg, val);}
The Android Open Source Project5738f832012-12-12 16:00:35 -080038
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
Pavlin Radoslavov3f06e142015-11-09 18:39:03 -080046/*
47 * A memcpy(3) wrapper when copying memory that might not be aligned.
48 *
49 * On certain architectures, if the memcpy(3) arguments appear to be
50 * pointing to aligned memory (e.g., struct pointers), the compiler might
51 * generate optimized memcpy(3) code. However, if the original memory was not
52 * aligned (e.g., because of incorrect "char *" to struct pointer casting),
53 * the result code might trigger SIGBUS crash.
54 *
55 * As a short-term solution, we use the help of the maybe_non_aligned_memcpy()
56 * macro to identify and fix such cases. In the future, we should fix the
57 * problematic "char *" to struct pointer casting, and this macro itself should
58 * be removed.
59 */
60#define maybe_non_aligned_memcpy(_a, _b, _c) memcpy((void *)(_a), (_b), (_c))
61
The Android Open Source Project5738f832012-12-12 16:00:35 -080062/* BTIF sub-systems */
63#define BTIF_CORE 0
64#define BTIF_DM 1
65#define BTIF_HFP 2
66#define BTIF_AV 3
67#define BTIF_PAN 4
Hemant Gupta10256872013-08-19 18:33:01 +053068#define BTIF_HF_CLIENT 5
The Android Open Source Project5738f832012-12-12 16:00:35 -080069
70extern bt_callbacks_t *bt_hal_cbacks;
71
72#define HAL_CBACK(P_CB, P_CBACK, ...)\
Chih-Hung Hsieh63b05192016-05-20 10:29:31 -070073 if ((P_CB) && (P_CB)->P_CBACK) { \
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -070074 BTIF_TRACE_API("HAL %s->%s", #P_CB, #P_CBACK); \
Chih-Hung Hsieh63b05192016-05-20 10:29:31 -070075 (P_CB)->P_CBACK(__VA_ARGS__); \
The Android Open Source Project5738f832012-12-12 16:00:35 -080076 } \
77 else { \
78 ASSERTC(0, "Callback is NULL", 0); \
79 }
80
81/**
82 * BTIF events for requests that require context switch to btif task
83 * on downstreams path
84 */
85enum
86{
87 BTIF_CORE_API_START = BTIF_SIG_START(BTIF_CORE),
88 BTIF_CORE_STORAGE_NO_ACTION,
89 BTIF_CORE_STORAGE_ADAPTER_WRITE,
90 BTIF_CORE_STORAGE_ADAPTER_READ,
91 BTIF_CORE_STORAGE_ADAPTER_READ_ALL,
92 BTIF_CORE_STORAGE_REMOTE_WRITE,
93 BTIF_CORE_STORAGE_REMOTE_READ,
94 BTIF_CORE_STORAGE_REMOTE_READ_ALL,
95 BTIF_CORE_STORAGE_READ_ALL,
96 BTIF_CORE_STORAGE_NOTIFY_STATUS,
97 /* add here */
98
99 BTIF_DM_API_START = BTIF_SIG_START(BTIF_DM),
100 BTIF_DM_ENABLE_SERVICE,
101 BTIF_DM_DISABLE_SERVICE,
102 /* add here */
103
104 BTIF_HFP_API_START = BTIF_SIG_START(BTIF_HFP),
105 /* add here */
106
107 BTIF_AV_API_START = BTIF_SIG_START(BTIF_AV),
108 /* add here */
109};
110
111/**
112 * BTIF events for callbacks that require context switch to btif task
113 * on upstream path - Typically these would be non-BTA events
114 * that are generated by the BTIF layer.
115 */
116enum
117{
118 BTIF_CORE_CB_START = BTIF_SIG_CB_START(BTIF_CORE),
119 /* add here */
120
121 BTIF_DM_CB_START = BTIF_SIG_CB_START(BTIF_DM),
122 BTIF_DM_CB_DISCOVERY_STARTED, /* Discovery has started */
123 BTIF_DM_CB_CREATE_BOND, /* Create bond */
124 BTIF_DM_CB_REMOVE_BOND, /*Remove bond */
125 BTIF_DM_CB_HID_REMOTE_NAME, /* Remote name callback for HID device */
126 BTIF_DM_CB_BOND_STATE_BONDING,
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800127 BTIF_DM_CB_LE_TX_TEST, /* BLE Tx Test command complete callback */
128 BTIF_DM_CB_LE_RX_TEST, /* BLE Rx Test command complete callback */
129 BTIF_DM_CB_LE_TEST_END, /* BLE Test mode end callback */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800130
131 BTIF_HFP_CB_START = BTIF_SIG_CB_START(BTIF_HFP),
132 BTIF_HFP_CB_AUDIO_CONNECTING, /* HF AUDIO connect has been sent to BTA successfully */
133
134 BTIF_PAN_CB_START = BTIF_SIG_CB_START(BTIF_PAN),
135 BTIF_PAN_CB_DISCONNECTING, /* PAN Disconnect has been sent to BTA successfully */
Hemant Gupta10256872013-08-19 18:33:01 +0530136
137 BTIF_HF_CLIENT_CLIENT_CB_START = BTIF_SIG_CB_START(BTIF_HF_CLIENT),
138 BTIF_HF_CLIENT_CB_AUDIO_CONNECTING, /* AUDIO connect has been sent to BTA successfully */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800139};
140
141/* Macro definitions for BD ADDR persistence */
142
143/**
144 * PROPERTY_BT_BDADDR_PATH
145 * The property key stores the storage location of Bluetooth Device Address
146 */
147#ifndef PROPERTY_BT_BDADDR_PATH
148#define PROPERTY_BT_BDADDR_PATH "ro.bt.bdaddr_path"
149#endif
150
151/**
152 * PERSIST_BDADDR_PROPERTY
153 * If there is no valid bdaddr available from PROPERTY_BT_BDADDR_PATH,
154 * generating a random BDADDR and keeping it in the PERSIST_BDADDR_DROP.
155 */
156#ifndef PERSIST_BDADDR_PROPERTY
157#define PERSIST_BDADDR_PROPERTY "persist.service.bdroid.bdaddr"
158#endif
159
Ajay Panicker28f294b2015-08-03 16:29:31 -0700160/**
161 * FACTORY_BT_BDADDR_PROPERTY
162 * If there is no valid bdaddr available from PROPERTY_BT_BDADDR_PATH
163 * and there is no available persistent bdaddr available from
164 * PERSIST_BDADDR_PROPERTY use a factory set address
165 */
166#ifndef FACTORY_BT_ADDR_PROPERTY
167#define FACTORY_BT_ADDR_PROPERTY "ro.boot.btmacaddr"
168#endif
169
The Android Open Source Project5738f832012-12-12 16:00:35 -0800170#define FACTORY_BT_BDADDR_STORAGE_LEN 17
171
172
173/*******************************************************************************
174** Type definitions for callback functions
175********************************************************************************/
176
Marie Janssenb7f64bc2016-06-22 12:52:19 -0700177typedef void (tBTIF_CBACK) (uint16_t event, char *p_param);
178typedef void (tBTIF_COPY_CBACK) (uint16_t event, char *p_dest, char *p_src);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800179
180
181/*******************************************************************************
182** Type definitions and return values
183********************************************************************************/
184
185/* this type handles all btif context switches between BTU and HAL */
186typedef struct
187{
188 BT_HDR hdr;
189 tBTIF_CBACK* p_cb; /* context switch callback */
190
191 /* parameters passed to callback */
Marie Janssenb7f64bc2016-06-22 12:52:19 -0700192 uint16_t event; /* message event id */
Pavlin Radoslavov3f06e142015-11-09 18:39:03 -0800193 char __attribute__ ((aligned)) p_param[]; /* parameter area needs to be last */
The Android Open Source Project5738f832012-12-12 16:00:35 -0800194} tBTIF_CONTEXT_SWITCH_CBACK;
195
196
197/*******************************************************************************
198** Functions
199********************************************************************************/
200
The Android Open Source Project5738f832012-12-12 16:00:35 -0800201tBTA_SERVICE_MASK btif_get_enabled_services_mask(void);
202bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id);
203bt_status_t btif_disable_service(tBTA_SERVICE_ID service_id);
204int btif_is_enabled(void);
205
206/**
207 * BTIF_Events
208 */
Zach Johnson39110ec2014-10-06 13:15:00 -0700209void btif_enable_bluetooth_evt(tBTA_STATUS status);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800210void btif_disable_bluetooth_evt(void);
211void btif_adapter_properties_evt(bt_status_t status, uint32_t num_props, bt_property_t *p_props);
212void btif_remote_properties_evt(bt_status_t status, bt_bdaddr_t *remote_addr,
213 uint32_t num_props, bt_property_t *p_props);
Chris Manton0eefef02014-09-08 15:01:39 -0700214
Jakub Pawlowski22c590f2016-06-15 17:15:42 -0700215
216#ifdef __cplusplus
217extern "C" {
218#endif
219
220void bte_load_did_conf(const char *p_path);
221void bte_main_boot_entry(void);
Pavlin Radoslavovb2a292b2016-10-14 19:34:48 -0700222void bte_main_enable(void);
Jakub Pawlowski22c590f2016-06-15 17:15:42 -0700223void bte_main_disable(void);
224void bte_main_cleanup(void);
Marie Janssenb7f64bc2016-06-22 12:52:19 -0700225#if (HCILP_INCLUDED == TRUE)
226void bte_main_enable_lpm(bool enable);
Jakub Pawlowski22c590f2016-06-15 17:15:42 -0700227#endif
228void bte_main_postload_cfg(void);
229
Marie Janssenb7f64bc2016-06-22 12:52:19 -0700230bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, uint16_t event, char* p_params,
Jakub Pawlowski22c590f2016-06-15 17:15:42 -0700231 int param_len, tBTIF_COPY_CBACK *p_copy_cback);
232
Chris Manton0eefef02014-09-08 15:01:39 -0700233void btif_init_ok(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param);
Chris Manton0eefef02014-09-08 15:01:39 -0700234
Jakub Pawlowski713993d2016-04-21 13:16:45 -0700235#ifdef __cplusplus
236}
237#endif
238
The Android Open Source Project5738f832012-12-12 16:00:35 -0800239#endif /* BTIF_COMMON_H */