149be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang/****************************************************************************** 249be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang * 349be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang * Copyright (c) 2014 The Android Open Source Project 449be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang * Copyright (C) 2009-2012 Broadcom Corporation 549be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang * 649be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang * Licensed under the Apache License, Version 2.0 (the "License"); 749be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang * you may not use this file except in compliance with the License. 849be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang * You may obtain a copy of the License at: 949be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang * 1049be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang * http://www.apache.org/licenses/LICENSE-2.0 1149be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang * 1249be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang * Unless required by applicable law or agreed to in writing, software 1349be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang * distributed under the License is distributed on an "AS IS" BASIS, 1449be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1549be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang * See the License for the specific language governing permissions and 1649be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang * limitations under the License. 1749be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang * 1849be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang ******************************************************************************/ 1949be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang 2049be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang#ifndef BTIF_COMMON_H 2149be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang#define BTIF_COMMON_H 2249be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang 2349be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang#include "data_types.h" 2449be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang#include "bt_types.h" 2549be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang#include "bta_api.h" 2649be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang 2749be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang#ifndef LOG_TAG 2849be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang#error "LOG_TAG not defined, please add in .c file prior to including bt_common.h" 2949be2ad9f863f5b238997e740aa35adc40ba66e3Geoff Lang#endif 30 31#include <utils/Log.h> 32 33/******************************************************************************* 34** Constants & Macros 35********************************************************************************/ 36 37#define ASSERTC(cond, msg, val) if (!(cond)) { ALOGE( \ 38 "### ASSERT : %s line %d %s (%d) ###", __FILE__, __LINE__, msg, val);} 39 40/* Calculate start of event enumeration; id is top 8 bits of event */ 41#define BTIF_SIG_START(id) ((id) << 8) 42 43/* For upstream the MSB bit is always SET */ 44#define BTIF_SIG_CB_BIT (0x8000) 45#define BTIF_SIG_CB_START(id) (((id) << 8) | BTIF_SIG_CB_BIT) 46 47/* BTIF sub-systems */ 48#define BTIF_CORE 0 49#define BTIF_DM 1 50#define BTIF_HFP 2 51#define BTIF_AV 3 52#define BTIF_PAN 4 53#define BTIF_HF_CLIENT 5 54 55extern bt_callbacks_t *bt_hal_cbacks; 56 57#define HAL_CBACK(P_CB, P_CBACK, ...)\ 58 if (P_CB && P_CB->P_CBACK) { \ 59 BTIF_TRACE_API("HAL %s->%s", #P_CB, #P_CBACK); \ 60 P_CB->P_CBACK(__VA_ARGS__); \ 61 } \ 62 else { \ 63 ASSERTC(0, "Callback is NULL", 0); \ 64 } 65 66/** 67 * BTIF events for requests that require context switch to btif task 68 * on downstreams path 69 */ 70enum 71{ 72 BTIF_CORE_API_START = BTIF_SIG_START(BTIF_CORE), 73 BTIF_CORE_STORAGE_NO_ACTION, 74 BTIF_CORE_STORAGE_ADAPTER_WRITE, 75 BTIF_CORE_STORAGE_ADAPTER_READ, 76 BTIF_CORE_STORAGE_ADAPTER_READ_ALL, 77 BTIF_CORE_STORAGE_REMOTE_WRITE, 78 BTIF_CORE_STORAGE_REMOTE_READ, 79 BTIF_CORE_STORAGE_REMOTE_READ_ALL, 80 BTIF_CORE_STORAGE_READ_ALL, 81 BTIF_CORE_STORAGE_NOTIFY_STATUS, 82 /* add here */ 83 84 BTIF_DM_API_START = BTIF_SIG_START(BTIF_DM), 85 BTIF_DM_ENABLE_SERVICE, 86 BTIF_DM_DISABLE_SERVICE, 87 /* add here */ 88 89 BTIF_HFP_API_START = BTIF_SIG_START(BTIF_HFP), 90 /* add here */ 91 92 BTIF_AV_API_START = BTIF_SIG_START(BTIF_AV), 93 /* add here */ 94}; 95 96/** 97 * BTIF events for callbacks that require context switch to btif task 98 * on upstream path - Typically these would be non-BTA events 99 * that are generated by the BTIF layer. 100 */ 101enum 102{ 103 BTIF_CORE_CB_START = BTIF_SIG_CB_START(BTIF_CORE), 104 /* add here */ 105 106 BTIF_DM_CB_START = BTIF_SIG_CB_START(BTIF_DM), 107 BTIF_DM_CB_DISCOVERY_STARTED, /* Discovery has started */ 108 BTIF_DM_CB_CREATE_BOND, /* Create bond */ 109 BTIF_DM_CB_REMOVE_BOND, /*Remove bond */ 110 BTIF_DM_CB_HID_REMOTE_NAME, /* Remote name callback for HID device */ 111 BTIF_DM_CB_BOND_STATE_BONDING, 112 BTIF_DM_CB_LE_TX_TEST, /* BLE Tx Test command complete callback */ 113 BTIF_DM_CB_LE_RX_TEST, /* BLE Rx Test command complete callback */ 114 BTIF_DM_CB_LE_TEST_END, /* BLE Test mode end callback */ 115 116 BTIF_HFP_CB_START = BTIF_SIG_CB_START(BTIF_HFP), 117 BTIF_HFP_CB_AUDIO_CONNECTING, /* HF AUDIO connect has been sent to BTA successfully */ 118 119 BTIF_PAN_CB_START = BTIF_SIG_CB_START(BTIF_PAN), 120 BTIF_PAN_CB_DISCONNECTING, /* PAN Disconnect has been sent to BTA successfully */ 121 122 BTIF_HF_CLIENT_CLIENT_CB_START = BTIF_SIG_CB_START(BTIF_HF_CLIENT), 123 BTIF_HF_CLIENT_CB_AUDIO_CONNECTING, /* AUDIO connect has been sent to BTA successfully */ 124}; 125 126/* Macro definitions for BD ADDR persistence */ 127 128/** 129 * PROPERTY_BT_BDADDR_PATH 130 * The property key stores the storage location of Bluetooth Device Address 131 */ 132#ifndef PROPERTY_BT_BDADDR_PATH 133#define PROPERTY_BT_BDADDR_PATH "ro.bt.bdaddr_path" 134#endif 135 136/** 137 * PERSIST_BDADDR_PROPERTY 138 * If there is no valid bdaddr available from PROPERTY_BT_BDADDR_PATH, 139 * generating a random BDADDR and keeping it in the PERSIST_BDADDR_DROP. 140 */ 141#ifndef PERSIST_BDADDR_PROPERTY 142#define PERSIST_BDADDR_PROPERTY "persist.service.bdroid.bdaddr" 143#endif 144 145#define FACTORY_BT_BDADDR_STORAGE_LEN 17 146 147 148/******************************************************************************* 149** Type definitions for callback functions 150********************************************************************************/ 151 152typedef void (tBTIF_CBACK) (UINT16 event, char *p_param); 153typedef void (tBTIF_COPY_CBACK) (UINT16 event, char *p_dest, char *p_src); 154 155 156/******************************************************************************* 157** Type definitions and return values 158********************************************************************************/ 159 160/* this type handles all btif context switches between BTU and HAL */ 161typedef struct 162{ 163 BT_HDR hdr; 164 tBTIF_CBACK* p_cb; /* context switch callback */ 165 166 /* parameters passed to callback */ 167 UINT16 event; /* message event id */ 168 char p_param[0]; /* parameter area needs to be last */ 169} tBTIF_CONTEXT_SWITCH_CBACK; 170 171 172/******************************************************************************* 173** Functions 174********************************************************************************/ 175 176bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char* p_params, 177 int param_len, tBTIF_COPY_CBACK *p_copy_cback); 178tBTA_SERVICE_MASK btif_get_enabled_services_mask(void); 179bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id); 180bt_status_t btif_disable_service(tBTA_SERVICE_ID service_id); 181int btif_is_enabled(void); 182 183/** 184 * BTIF_Events 185 */ 186void btif_enable_bluetooth_evt(tBTA_STATUS status, BD_ADDR local_bd); 187void btif_disable_bluetooth_evt(void); 188void btif_adapter_properties_evt(bt_status_t status, uint32_t num_props, bt_property_t *p_props); 189void btif_remote_properties_evt(bt_status_t status, bt_bdaddr_t *remote_addr, 190 uint32_t num_props, bt_property_t *p_props); 191#endif /* BTIF_COMMON_H */ 192