• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
41 extern tHCI_IF *p_hci_if;
42 void lpm_vnd_cback(uint8_t vnd_result);
43 
44 /******************************************************************************
45 **  Variables
46 ******************************************************************************/
47 
48 bt_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 ******************************************************************************/
fwcfg_cb(bt_vendor_op_result_t result)65 static 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 ******************************************************************************/
scocfg_cb(bt_vendor_op_result_t result)85 static 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 ******************************************************************************/
lpm_vnd_cb(bt_vendor_op_result_t result)102 static 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 ******************************************************************************/
alloc(int size)120 static 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 ******************************************************************************/
dealloc(void * p_buf)141 static 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 ******************************************************************************/
xmit_cb(uint16_t opcode,void * p_buf,tINT_CMD_CBACK p_cback)160 static 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 **   The libbt-vendor Callback Functions Table
167 *****************************************************************************/
168 static const bt_vendor_callbacks_t vnd_callbacks = {
169     sizeof(bt_vendor_callbacks_t),
170     fwcfg_cb,
171     scocfg_cb,
172     lpm_vnd_cb,
173     alloc,
174     dealloc,
175     xmit_cb
176 };
177 
178 /******************************************************************************
179 **
180 ** Function         init_vnd_if
181 **
182 ** Description      Initialize vendor lib interface
183 **
184 ** Returns          None
185 **
186 ******************************************************************************/
init_vnd_if(unsigned char * local_bdaddr)187 void init_vnd_if(unsigned char *local_bdaddr)
188 {
189     void *dlhandle;
190 
191     dlhandle = dlopen("libbt-vendor.so", RTLD_NOW);
192     if (!dlhandle)
193     {
194         ALOGE("!!! Failed to load libbt-vendor.so !!!");
195         return;
196     }
197 
198     bt_vnd_if = (bt_vendor_interface_t *) dlsym(dlhandle, "BLUETOOTH_VENDOR_LIB_INTERFACE");
199     if (!bt_vnd_if)
200     {
201         ALOGE("!!! Failed to get bt vendor interface !!!");
202         return;
203     }
204 
205     bt_vnd_if->init(&vnd_callbacks, local_bdaddr);
206 }
207 
208