blob: d17baa2712af58d258475381862404f98aa071c3
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_vendor_brcm.c |
22 | * |
23 | * Description: Broadcom vendor specific library implementation |
24 | * |
25 | ******************************************************************************/ |
26 | |
27 | #define LOG_TAG "bt_vendor" |
28 | |
29 | #include <utils/Log.h> |
30 | #include "bt_vendor_brcm.h" |
31 | #include "upio.h" |
32 | #include "userial_vendor.h" |
33 | |
34 | #ifndef BTVND_DBG |
35 | #define BTVND_DBG FALSE |
36 | #endif |
37 | |
38 | #if (BTVND_DBG == TRUE) |
39 | #define BTVNDDBG(param, ...) {ALOGD(param, ## __VA_ARGS__);} |
40 | #else |
41 | #define BTVNDDBG(param, ...) {} |
42 | #endif |
43 | |
44 | /****************************************************************************** |
45 | ** Externs |
46 | ******************************************************************************/ |
47 | |
48 | void hw_config_start(void); |
49 | uint8_t hw_lpm_enable(uint8_t turn_on); |
50 | uint32_t hw_lpm_get_idle_timeout(void); |
51 | void hw_lpm_set_wake_state(uint8_t wake_assert); |
52 | #if (SCO_CFG_INCLUDED == TRUE) |
53 | void hw_sco_config(void); |
54 | #endif |
55 | void vnd_load_conf(const char *p_path); |
56 | |
57 | /****************************************************************************** |
58 | ** Variables |
59 | ******************************************************************************/ |
60 | |
61 | bt_vendor_callbacks_t *bt_vendor_cbacks = NULL; |
62 | uint8_t vnd_local_bd_addr[6]={0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
63 | |
64 | /****************************************************************************** |
65 | ** Local type definitions |
66 | ******************************************************************************/ |
67 | |
68 | /****************************************************************************** |
69 | ** Static Variables |
70 | ******************************************************************************/ |
71 | |
72 | static const tUSERIAL_CFG userial_init_cfg = |
73 | { |
74 | (USERIAL_DATABITS_8 | USERIAL_PARITY_NONE | USERIAL_STOPBITS_1), |
75 | USERIAL_BAUD_115200 |
76 | }; |
77 | |
78 | /****************************************************************************** |
79 | ** Functions |
80 | ******************************************************************************/ |
81 | |
82 | /***************************************************************************** |
83 | ** |
84 | ** BLUETOOTH VENDOR INTERFACE LIBRARY FUNCTIONS |
85 | ** |
86 | *****************************************************************************/ |
87 | |
88 | static int init(const bt_vendor_callbacks_t* p_cb, unsigned char *local_bdaddr) |
89 | { |
90 | ALOGI("init"); |
91 | |
92 | if (p_cb == NULL) |
93 | { |
94 | ALOGE("init failed with no user callbacks!"); |
95 | return -1; |
96 | } |
97 | |
98 | #if (VENDOR_LIB_RUNTIME_TUNING_ENABLED == TRUE) |
99 | ALOGW("*****************************************************************"); |
100 | ALOGW("*****************************************************************"); |
101 | ALOGW("** Warning - BT Vendor Lib is loaded in debug tuning mode!"); |
102 | ALOGW("**"); |
103 | ALOGW("** If this is not intentional, rebuild libbt-vendor.so "); |
104 | ALOGW("** with VENDOR_LIB_RUNTIME_TUNING_ENABLED=FALSE and "); |
105 | ALOGW("** check if any run-time tuning parameters needed to be"); |
106 | ALOGW("** carried to the build-time configuration accordingly."); |
107 | ALOGW("*****************************************************************"); |
108 | ALOGW("*****************************************************************"); |
109 | #endif |
110 | |
111 | userial_vendor_init(); |
112 | upio_init(); |
113 | |
114 | vnd_load_conf(VENDOR_LIB_CONF_FILE); |
115 | |
116 | /* store reference to user callbacks */ |
117 | bt_vendor_cbacks = (bt_vendor_callbacks_t *) p_cb; |
118 | |
119 | /* This is handed over from the stack */ |
120 | memcpy(vnd_local_bd_addr, local_bdaddr, 6); |
121 | |
122 | return 0; |
123 | } |
124 | |
125 | |
126 | /** Requested operations */ |
127 | static int op(bt_vendor_opcode_t opcode, void *param) |
128 | { |
129 | int retval = 0; |
130 | |
131 | BTVNDDBG("op for %d", opcode); |
132 | |
133 | switch(opcode) |
134 | { |
135 | case BT_VND_OP_POWER_CTRL: |
136 | { |
137 | int *state = (int *) param; |
138 | if (*state == BT_VND_PWR_OFF) |
139 | upio_set_bluetooth_power(UPIO_BT_POWER_OFF); |
140 | else if (*state == BT_VND_PWR_ON) |
141 | upio_set_bluetooth_power(UPIO_BT_POWER_ON); |
142 | } |
143 | break; |
144 | |
145 | case BT_VND_OP_FW_CFG: |
146 | { |
147 | hw_config_start(); |
148 | } |
149 | break; |
150 | |
151 | case BT_VND_OP_SCO_CFG: |
152 | { |
153 | #if (SCO_CFG_INCLUDED == TRUE) |
154 | hw_sco_config(); |
155 | #else |
156 | retval = -1; |
157 | #endif |
158 | } |
159 | break; |
160 | |
161 | case BT_VND_OP_USERIAL_OPEN: |
162 | { |
163 | int (*fd_array)[] = (int (*)[]) param; |
164 | int fd, idx; |
165 | fd = userial_vendor_open((tUSERIAL_CFG *) &userial_init_cfg); |
166 | if (fd != -1) |
167 | { |
168 | for (idx=0; idx < CH_MAX; idx++) |
169 | (*fd_array)[idx] = fd; |
170 | |
171 | retval = 1; |
172 | } |
173 | /* retval contains numbers of open fd of HCI channels */ |
174 | } |
175 | break; |
176 | |
177 | case BT_VND_OP_USERIAL_CLOSE: |
178 | { |
179 | userial_vendor_close(); |
180 | } |
181 | break; |
182 | |
183 | case BT_VND_OP_GET_LPM_IDLE_TIMEOUT: |
184 | { |
185 | uint32_t *timeout_ms = (uint32_t *) param; |
186 | *timeout_ms = hw_lpm_get_idle_timeout(); |
187 | } |
188 | break; |
189 | |
190 | case BT_VND_OP_LPM_SET_MODE: |
191 | { |
192 | uint8_t *mode = (uint8_t *) param; |
193 | retval = hw_lpm_enable(*mode); |
194 | } |
195 | break; |
196 | |
197 | case BT_VND_OP_LPM_WAKE_SET_STATE: |
198 | { |
199 | uint8_t *state = (uint8_t *) param; |
200 | uint8_t wake_assert = (state == BT_VND_LPM_WAKE_ASSERT) ? \ |
201 | TRUE : FALSE; |
202 | |
203 | hw_lpm_set_wake_state(wake_assert); |
204 | } |
205 | break; |
206 | } |
207 | |
208 | return retval; |
209 | } |
210 | |
211 | /** Closes the interface */ |
212 | static void cleanup( void ) |
213 | { |
214 | BTVNDDBG("cleanup"); |
215 | |
216 | upio_cleanup(); |
217 | |
218 | bt_vendor_cbacks = NULL; |
219 | } |
220 | |
221 | // Entry point of DLib |
222 | const bt_vendor_interface_t BLUETOOTH_VENDOR_LIB_INTERFACE = { |
223 | sizeof(bt_vendor_interface_t), |
224 | init, |
225 | op, |
226 | cleanup |
227 | }; |
228 |