blob: 46705bd4b4a268c9e187353be5f196e913ff0437 [file] [log] [blame]
John Stultz5c69c8c2015-11-23 17:13:51 -08001/*
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
31bt_vendor_callbacks_t *bt_vendor_cbacks = NULL;
32unsigned int hci_tty_fd = -1;
33void 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 * *******************************************************************************/
Dmitry Shmidt395b0442016-11-08 08:56:57 -080044void hw_config_cback(HC_BT_HDR * __unused p_evt_buf)
John Stultz5c69c8c2015-11-23 17:13:51 -080045{
46 ALOGV("hw_config_cback");
47}
48
Dmitry Shmidt395b0442016-11-08 08:56:57 -080049int ti_init(const bt_vendor_callbacks_t* p_cb, unsigned char * __unused local_bdaddr)
50{
John Stultz5c69c8c2015-11-23 17:13:51 -080051 ALOGV("vendor Init");
52
53 if (p_cb == NULL)
54 {
55 ALOGE("init failed with no user callbacks!");
56 return BT_STATUS_FAIL;
57 }
58
59 bt_vendor_cbacks = (bt_vendor_callbacks_t *) p_cb;
60
61 return 0;
62}
Dmitry Shmidt395b0442016-11-08 08:56:57 -080063
64void ti_cleanup(void)
65{
John Stultz5c69c8c2015-11-23 17:13:51 -080066 ALOGV("vendor cleanup");
67
68 bt_vendor_cbacks = NULL;
69}
Dmitry Shmidt395b0442016-11-08 08:56:57 -080070
71int ti_op(bt_vendor_opcode_t opcode, void *param)
72{
John Stultz5c69c8c2015-11-23 17:13:51 -080073 int fd;
Dmitry Shmidt395b0442016-11-08 08:56:57 -080074 int *fd_array = (int *)param;
John Stultz5c69c8c2015-11-23 17:13:51 -080075
76 ALOGV("vendor op - %d", opcode);
77 switch(opcode)
78 {
79 case BT_VND_OP_USERIAL_OPEN:
80 fd = open("/dev/hci_tty", O_RDWR);
81 if (fd < 0) {
82 ALOGE(" Can't open hci_tty");
83 return -1;
84 }
85 fd_array[CH_CMD] = fd;
86 hci_tty_fd = fd; /* for userial_close op */
87 return 1; /* CMD/EVT/ACL on same fd */
88 case BT_VND_OP_USERIAL_CLOSE:
89 close(hci_tty_fd);
90 return 0;
91 /* Since new stack expects fwcfg_cb we are returning SUCCESS here
92 * in actual, firmware download is already happened when /dev/hci_tty
93 * opened.
94 */
95 case BT_VND_OP_FW_CFG:
96 bt_vendor_cbacks->fwcfg_cb(BT_VND_OP_RESULT_SUCCESS);
97 return 0;
98 case BT_VND_OP_EPILOG:
99 bt_vendor_cbacks->epilog_cb(BT_VND_OP_RESULT_SUCCESS);
100 break;
101 default:
102 break;
103 }
104
105 return 0;
106}
Dmitry Shmidt395b0442016-11-08 08:56:57 -0800107
John Stultz5c69c8c2015-11-23 17:13:51 -0800108const bt_vendor_interface_t BLUETOOTH_VENDOR_LIB_INTERFACE = {
109 .init = ti_init,
110 .op = ti_op,
111 .cleanup = ti_cleanup,
112};
113
114int main()
115{
116 return 0;
117}