bt_hw.c revision 67e4077c23bb9cc045885ae01cc83b38faecb71b
1/****************************************************************************** 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/****************************************************************************** 20 * 21 * Filename: bt_hw.c 22 * 23 * Description: Bluedroid libbt-vendor callback functions 24 * 25 ******************************************************************************/ 26 27#define LOG_TAG "bt_hw" 28 29#include <dlfcn.h> 30#include <utils/Log.h> 31#include <pthread.h> 32#include "bt_vendor_lib.h" 33#include "bt_hci_bdroid.h" 34#include "hci.h" 35#include "userial.h" 36 37/****************************************************************************** 38** Externs 39******************************************************************************/ 40 41extern tHCI_IF *p_hci_if; 42void lpm_vnd_cback(uint8_t vnd_result); 43 44/****************************************************************************** 45** Variables 46******************************************************************************/ 47 48bt_vendor_interface_t *bt_vnd_if=NULL; 49 50/****************************************************************************** 51** Functions 52******************************************************************************/ 53 54/****************************************************************************** 55** 56** Function fwcfg_cb 57** 58** Description HOST/CONTROLLER VENDOR LIB CALLBACK API - This function is 59** called when the libbt-vendor completed firmware 60** configuration process 61** 62** Returns None 63** 64******************************************************************************/ 65static void fwcfg_cb(bt_vendor_op_result_t result) 66{ 67 bt_hc_postload_result_t status = (result == BT_VND_OP_RESULT_SUCCESS) ? \ 68 BT_HC_PRELOAD_SUCCESS : BT_HC_PRELOAD_FAIL; 69 70 if (bt_hc_cbacks) 71 bt_hc_cbacks->preload_cb(NULL, status); 72} 73 74/****************************************************************************** 75** 76** Function scocfg_cb 77** 78** Description HOST/CONTROLLER VENDOR LIB CALLBACK API - This function is 79** called when the libbt-vendor completed vendor specific SCO 80** configuration process 81** 82** Returns None 83** 84******************************************************************************/ 85static void scocfg_cb(bt_vendor_op_result_t result) 86{ 87 /* Continue rest of postload process*/ 88 p_hci_if->get_acl_max_len(); 89} 90 91/****************************************************************************** 92** 93** Function lpm_vnd_cb 94** 95** Description HOST/CONTROLLER VENDOR LIB CALLBACK API - This function is 96** called back from the libbt-vendor to indicate the result of 97** previous LPM enable/disable request 98** 99** Returns None 100** 101******************************************************************************/ 102static void lpm_vnd_cb(bt_vendor_op_result_t result) 103{ 104 uint8_t status = (result == BT_VND_OP_RESULT_SUCCESS) ? 0 : 1; 105 106 lpm_vnd_cback(status); 107} 108 109/****************************************************************************** 110** 111** Function alloc 112** 113** Description HOST/CONTROLLER VENDOR LIB CALLOUT API - This function is 114** called from the libbt-vendor to request for data buffer 115** allocation 116** 117** Returns NULL / pointer to allocated buffer 118** 119******************************************************************************/ 120static void *alloc(int size) 121{ 122 HC_BT_HDR *p_hdr = NULL; 123 124 if (bt_hc_cbacks) 125 p_hdr = (HC_BT_HDR *) bt_hc_cbacks->alloc(size); 126 127 return (p_hdr); 128} 129 130/****************************************************************************** 131** 132** Function dealloc 133** 134** Description HOST/CONTROLLER VENDOR LIB CALLOUT API - This function is 135** called from the libbt-vendor to release the data buffer 136** allocated through the alloc call earlier 137** 138** Returns None 139** 140******************************************************************************/ 141static void dealloc(void *p_buf) 142{ 143 HC_BT_HDR *p_hdr = (HC_BT_HDR *) p_buf; 144 145 if (bt_hc_cbacks) 146 bt_hc_cbacks->dealloc((TRANSAC) p_buf, (char *) (p_hdr+1)); 147} 148 149/****************************************************************************** 150** 151** Function xmit_cb 152** 153** Description HOST/CONTROLLER VEDNOR LIB CALLOUT API - This function is 154** called from the libbt-vendor in order to send a prepared 155** HCI command packet through HCI transport TX function. 156** 157** Returns TRUE/FALSE 158** 159******************************************************************************/ 160static uint8_t xmit_cb(uint16_t opcode, void *p_buf, tINT_CMD_CBACK p_cback) 161{ 162 return p_hci_if->send_int_cmd(opcode, (HC_BT_HDR *)p_buf, p_cback); 163} 164 165/****************************************************************************** 166** 167** Function epilog_cb 168** 169** Description HOST/CONTROLLER VENDOR LIB CALLBACK API - This function is 170** called back from the libbt-vendor to indicate the result of 171** previous epilog call. 172** 173** Returns None 174** 175******************************************************************************/ 176static void epilog_cb(bt_vendor_op_result_t result) 177{ 178 bthc_signal_event(HC_EVENT_EXIT); 179} 180 181/***************************************************************************** 182** The libbt-vendor Callback Functions Table 183*****************************************************************************/ 184static const bt_vendor_callbacks_t vnd_callbacks = { 185 sizeof(bt_vendor_callbacks_t), 186 fwcfg_cb, 187 scocfg_cb, 188 lpm_vnd_cb, 189 alloc, 190 dealloc, 191 xmit_cb, 192 epilog_cb 193}; 194 195/****************************************************************************** 196** 197** Function init_vnd_if 198** 199** Description Initialize vendor lib interface 200** 201** Returns None 202** 203******************************************************************************/ 204void init_vnd_if(unsigned char *local_bdaddr) 205{ 206 void *dlhandle; 207 208 dlhandle = dlopen("libbt-vendor.so", RTLD_NOW); 209 if (!dlhandle) 210 { 211 ALOGE("!!! Failed to load libbt-vendor.so !!!"); 212 return; 213 } 214 215 bt_vnd_if = (bt_vendor_interface_t *) dlsym(dlhandle, "BLUETOOTH_VENDOR_LIB_INTERFACE"); 216 if (!bt_vnd_if) 217 { 218 ALOGE("!!! Failed to get bt vendor interface !!!"); 219 return; 220 } 221 222 bt_vnd_if->init(&vnd_callbacks, local_bdaddr); 223} 224 225