btif_common.h revision 44802768c447ab480d4227b3a852a97d923b816d
1/****************************************************************************** 2 * 3 * Copyright (c) 2014 The Android Open Source Project 4 * 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 23#include <hardware/bluetooth.h> 24 25#include "bt_types.h" 26#include "bta_api.h" 27#include "osi.h" 28 29#ifndef LOG_TAG 30#error "LOG_TAG not defined, please add in .c file prior to including bt_common.h" 31#endif 32 33#include "osi/include/log.h" 34 35/******************************************************************************* 36** Constants & Macros 37********************************************************************************/ 38 39#define ASSERTC(cond, msg, val) if (!(cond)) { LOG_ERROR( \ 40 "### ASSERT : %s line %d %s (%d) ###", __FILE__, __LINE__, msg, val);} 41 42/* Calculate start of event enumeration; id is top 8 bits of event */ 43#define BTIF_SIG_START(id) ((id) << 8) 44 45/* For upstream the MSB bit is always SET */ 46#define BTIF_SIG_CB_BIT (0x8000) 47#define BTIF_SIG_CB_START(id) (((id) << 8) | BTIF_SIG_CB_BIT) 48 49/* BTIF sub-systems */ 50#define BTIF_CORE 0 51#define BTIF_DM 1 52#define BTIF_HFP 2 53#define BTIF_AV 3 54#define BTIF_PAN 4 55#define BTIF_HF_CLIENT 5 56 57extern bt_callbacks_t *bt_hal_cbacks; 58 59#define HAL_CBACK(P_CB, P_CBACK, ...)\ 60 if (P_CB && P_CB->P_CBACK) { \ 61 BTIF_TRACE_API("HAL %s->%s", #P_CB, #P_CBACK); \ 62 P_CB->P_CBACK(__VA_ARGS__); \ 63 } \ 64 else { \ 65 ASSERTC(0, "Callback is NULL", 0); \ 66 } 67 68/** 69 * BTIF events for requests that require context switch to btif task 70 * on downstreams path 71 */ 72enum 73{ 74 BTIF_CORE_API_START = BTIF_SIG_START(BTIF_CORE), 75 BTIF_CORE_STORAGE_NO_ACTION, 76 BTIF_CORE_STORAGE_ADAPTER_WRITE, 77 BTIF_CORE_STORAGE_ADAPTER_READ, 78 BTIF_CORE_STORAGE_ADAPTER_READ_ALL, 79 BTIF_CORE_STORAGE_REMOTE_WRITE, 80 BTIF_CORE_STORAGE_REMOTE_READ, 81 BTIF_CORE_STORAGE_REMOTE_READ_ALL, 82 BTIF_CORE_STORAGE_READ_ALL, 83 BTIF_CORE_STORAGE_NOTIFY_STATUS, 84 /* add here */ 85 86 BTIF_DM_API_START = BTIF_SIG_START(BTIF_DM), 87 BTIF_DM_ENABLE_SERVICE, 88 BTIF_DM_DISABLE_SERVICE, 89 /* add here */ 90 91 BTIF_HFP_API_START = BTIF_SIG_START(BTIF_HFP), 92 /* add here */ 93 94 BTIF_AV_API_START = BTIF_SIG_START(BTIF_AV), 95 /* add here */ 96}; 97 98/** 99 * BTIF events for callbacks that require context switch to btif task 100 * on upstream path - Typically these would be non-BTA events 101 * that are generated by the BTIF layer. 102 */ 103enum 104{ 105 BTIF_CORE_CB_START = BTIF_SIG_CB_START(BTIF_CORE), 106 /* add here */ 107 108 BTIF_DM_CB_START = BTIF_SIG_CB_START(BTIF_DM), 109 BTIF_DM_CB_DISCOVERY_STARTED, /* Discovery has started */ 110 BTIF_DM_CB_CREATE_BOND, /* Create bond */ 111 BTIF_DM_CB_REMOVE_BOND, /*Remove bond */ 112 BTIF_DM_CB_HID_REMOTE_NAME, /* Remote name callback for HID device */ 113 BTIF_DM_CB_BOND_STATE_BONDING, 114 BTIF_DM_CB_LE_TX_TEST, /* BLE Tx Test command complete callback */ 115 BTIF_DM_CB_LE_RX_TEST, /* BLE Rx Test command complete callback */ 116 BTIF_DM_CB_LE_TEST_END, /* BLE Test mode end callback */ 117 118 BTIF_HFP_CB_START = BTIF_SIG_CB_START(BTIF_HFP), 119 BTIF_HFP_CB_AUDIO_CONNECTING, /* HF AUDIO connect has been sent to BTA successfully */ 120 121 BTIF_PAN_CB_START = BTIF_SIG_CB_START(BTIF_PAN), 122 BTIF_PAN_CB_DISCONNECTING, /* PAN Disconnect has been sent to BTA successfully */ 123 124 BTIF_HF_CLIENT_CLIENT_CB_START = BTIF_SIG_CB_START(BTIF_HF_CLIENT), 125 BTIF_HF_CLIENT_CB_AUDIO_CONNECTING, /* AUDIO connect has been sent to BTA successfully */ 126}; 127 128/* Macro definitions for BD ADDR persistence */ 129 130/** 131 * PROPERTY_BT_BDADDR_PATH 132 * The property key stores the storage location of Bluetooth Device Address 133 */ 134#ifndef PROPERTY_BT_BDADDR_PATH 135#define PROPERTY_BT_BDADDR_PATH "ro.bt.bdaddr_path" 136#endif 137 138/** 139 * PERSIST_BDADDR_PROPERTY 140 * If there is no valid bdaddr available from PROPERTY_BT_BDADDR_PATH, 141 * generating a random BDADDR and keeping it in the PERSIST_BDADDR_DROP. 142 */ 143#ifndef PERSIST_BDADDR_PROPERTY 144#define PERSIST_BDADDR_PROPERTY "persist.service.bdroid.bdaddr" 145#endif 146 147#define FACTORY_BT_BDADDR_STORAGE_LEN 17 148 149 150/******************************************************************************* 151** Type definitions for callback functions 152********************************************************************************/ 153 154typedef void (tBTIF_CBACK) (UINT16 event, char *p_param); 155typedef void (tBTIF_COPY_CBACK) (UINT16 event, char *p_dest, char *p_src); 156 157 158/******************************************************************************* 159** Type definitions and return values 160********************************************************************************/ 161 162/* this type handles all btif context switches between BTU and HAL */ 163typedef struct 164{ 165 BT_HDR hdr; 166 tBTIF_CBACK* p_cb; /* context switch callback */ 167 168 /* parameters passed to callback */ 169 UINT16 event; /* message event id */ 170 char p_param[0]; /* parameter area needs to be last */ 171} tBTIF_CONTEXT_SWITCH_CBACK; 172 173 174/******************************************************************************* 175** Functions 176********************************************************************************/ 177 178bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char* p_params, 179 int param_len, tBTIF_COPY_CBACK *p_copy_cback); 180tBTA_SERVICE_MASK btif_get_enabled_services_mask(void); 181bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id); 182bt_status_t btif_disable_service(tBTA_SERVICE_ID service_id); 183int btif_is_enabled(void); 184 185/** 186 * BTIF_Events 187 */ 188void btif_enable_bluetooth_evt(tBTA_STATUS status); 189void btif_disable_bluetooth_evt(void); 190void btif_adapter_properties_evt(bt_status_t status, uint32_t num_props, bt_property_t *p_props); 191void btif_remote_properties_evt(bt_status_t status, bt_bdaddr_t *remote_addr, 192 uint32_t num_props, bt_property_t *p_props); 193 194void btif_init_ok(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param); 195void btif_init_fail(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param); 196 197#endif /* BTIF_COMMON_H */ 198