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