1 /*
2 * Copyright 2001-2012 Texas Instruments, Inc. - http://www.ti.com/
3 *
4 * Bluetooth Vendor Library for TI's WiLink Chipsets
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 #define LOG_TAG "bt_vendor"
20
21 #include <stdio.h>
22 #include <dlfcn.h>
23 #include <utils/Log.h>
24 #include <pthread.h>
25 #include <fcntl.h>
26 #include <errno.h>
27 #include <bt_vendor_lib.h>
28 #include <bt_hci_bdroid.h>
29 #include <hardware/bluetooth.h>
30
31 bt_vendor_callbacks_t *bt_vendor_cbacks = NULL;
32 unsigned int hci_tty_fd = -1;
33 void hw_config_cback(HC_BT_HDR *p_evt_buf);
34
35 /*******************************************************************************
36 *
37 * Function hw_config_cback
38 *
39 * Description Callback function for controller configuration
40 *
41 * Returns None
42 *
43 * *******************************************************************************/
hw_config_cback(HC_BT_HDR * p_evt_buf)44 void hw_config_cback(HC_BT_HDR *p_evt_buf)
45 {
46 ALOGV("hw_config_cback");
47 }
48
ti_init(const bt_vendor_callbacks_t * p_cb,unsigned char * local_bdaddr)49 int ti_init(const bt_vendor_callbacks_t* p_cb, unsigned char *local_bdaddr) {
50 ALOGV("vendor Init");
51
52 if (p_cb == NULL)
53 {
54 ALOGE("init failed with no user callbacks!");
55 return BT_STATUS_FAIL;
56 }
57
58 bt_vendor_cbacks = (bt_vendor_callbacks_t *) p_cb;
59
60 return 0;
61 }
ti_cleanup(void)62 void ti_cleanup(void) {
63 ALOGV("vendor cleanup");
64
65 bt_vendor_cbacks = NULL;
66 }
ti_op(bt_vendor_opcode_t opcode,void ** param)67 int ti_op(bt_vendor_opcode_t opcode, void **param) {
68 int fd;
69 int *fd_array = (int (*)[]) param;
70
71 ALOGV("vendor op - %d", opcode);
72 switch(opcode)
73 {
74 case BT_VND_OP_USERIAL_OPEN:
75 fd = open("/dev/hci_tty", O_RDWR);
76 if (fd < 0) {
77 ALOGE(" Can't open hci_tty");
78 return -1;
79 }
80 fd_array[CH_CMD] = fd;
81 hci_tty_fd = fd; /* for userial_close op */
82 return 1; /* CMD/EVT/ACL on same fd */
83 case BT_VND_OP_USERIAL_CLOSE:
84 close(hci_tty_fd);
85 return 0;
86 /* Since new stack expects fwcfg_cb we are returning SUCCESS here
87 * in actual, firmware download is already happened when /dev/hci_tty
88 * opened.
89 */
90 case BT_VND_OP_FW_CFG:
91 bt_vendor_cbacks->fwcfg_cb(BT_VND_OP_RESULT_SUCCESS);
92 return 0;
93 case BT_VND_OP_EPILOG:
94 bt_vendor_cbacks->epilog_cb(BT_VND_OP_RESULT_SUCCESS);
95 break;
96 default:
97 break;
98 }
99
100 return 0;
101 }
102 const bt_vendor_interface_t BLUETOOTH_VENDOR_LIB_INTERFACE = {
103 .init = ti_init,
104 .op = ti_op,
105 .cleanup = ti_cleanup,
106 };
107
main()108 int main()
109 {
110 return 0;
111 }
112