Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 /******************************************************************************
     18  *
     19  *  Filename:      bt_vendor_brcm.c
     20  *
     21  *  Description:   Broadcom vendor specific library implementation
     22  *
     23  ******************************************************************************/
     24 
     25 #define LOG_TAG "bt_vendor"
     26 
     27 #include <utils/Log.h>
     28 #include <fcntl.h>
     29 #include <termios.h>
     30 #include "bt_vendor_qcom.h"
     31 #include "userial_vendor.h"
     32 
     33 /******************************************************************************
     34 **  Externs
     35 ******************************************************************************/
     36 extern int hw_config(int nState);
     37 
     38 extern int is_hw_ready();
     39 
     40 /******************************************************************************
     41 **  Variables
     42 ******************************************************************************/
     43 int pFd[2] = {0,};
     44 bt_hci_transport_device_type bt_hci_transport_device;
     45 
     46 bt_vendor_callbacks_t *bt_vendor_cbacks = NULL;
     47 uint8_t vnd_local_bd_addr[6]={0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
     48 
     49 #if (HW_NEED_END_WITH_HCI_RESET == TRUE)
     50 void hw_epilog_process(void);
     51 #endif
     52 
     53 
     54 /******************************************************************************
     55 **  Local type definitions
     56 ******************************************************************************/
     57 
     58 
     59 /******************************************************************************
     60 **  Functions
     61 ******************************************************************************/
     62 
     63 /*****************************************************************************
     64 **
     65 **   BLUETOOTH VENDOR INTERFACE LIBRARY FUNCTIONS
     66 **
     67 *****************************************************************************/
     68 
     69 static int init(const bt_vendor_callbacks_t* p_cb, unsigned char *local_bdaddr)
     70 {
     71     ALOGI("bt-vendor : init");
     72 
     73     if (p_cb == NULL)
     74     {
     75         ALOGE("init failed with no user callbacks!");
     76         return -1;
     77     }
     78 
     79     //userial_vendor_init();
     80     //upio_init();
     81 
     82     //vnd_load_conf(VENDOR_LIB_CONF_FILE);
     83 
     84     /* store reference to user callbacks */
     85     bt_vendor_cbacks = (bt_vendor_callbacks_t *) p_cb;
     86 
     87     /* This is handed over from the stack */
     88     memcpy(vnd_local_bd_addr, local_bdaddr, 6);
     89 
     90     return 0;
     91 }
     92 
     93 
     94 /** Requested operations */
     95 static int op(bt_vendor_opcode_t opcode, void *param)
     96 {
     97     int retval = 0;
     98     int nCnt = 0;
     99     int nState = -1;
    100 
    101     ALOGV("bt-vendor : op for %d", opcode);
    102 
    103     switch(opcode)
    104     {
    105         case BT_VND_OP_POWER_CTRL:
    106             {
    107                 nState = *(int *) param;
    108                 retval = hw_config(nState);
    109                 if(nState == BT_VND_PWR_ON
    110                    && retval == 0
    111                    && is_hw_ready() == TRUE){
    112                     retval = 0;
    113                 }
    114                 else {
    115                     retval = -1;
    116                 }
    117             }
    118             break;
    119 
    120         case BT_VND_OP_FW_CFG:
    121             {
    122                 // call hciattach to initalize the stack
    123                 if(bt_vendor_cbacks){
    124                    ALOGI("Bluetooth Firmware and smd is initialized");
    125                    bt_vendor_cbacks->fwcfg_cb(BT_VND_OP_RESULT_SUCCESS);
    126                 }
    127                 else{
    128                    ALOGE("Error : hci, smd initialization Error");
    129                    bt_vendor_cbacks->fwcfg_cb(BT_VND_OP_RESULT_FAIL);
    130                 }
    131             }
    132             break;
    133 
    134         case BT_VND_OP_SCO_CFG:
    135             {
    136                 bt_vendor_cbacks->scocfg_cb(BT_VND_OP_RESULT_SUCCESS); //dummy
    137             }
    138             break;
    139 
    140         case BT_VND_OP_USERIAL_OPEN:
    141             {
    142                 if(bt_hci_init_transport(pFd) != -1){
    143                     int (*fd_array)[] = (int (*) []) param;
    144 
    145                         (*fd_array)[CH_CMD] = pFd[0];
    146                         (*fd_array)[CH_EVT] = pFd[0];
    147                         (*fd_array)[CH_ACL_OUT] = pFd[1];
    148                         (*fd_array)[CH_ACL_IN] = pFd[1];
    149                 }
    150                 else {
    151                     retval = -1;
    152                     break;
    153                 }
    154                 retval = 2;
    155             }
    156             break;
    157 
    158         case BT_VND_OP_USERIAL_CLOSE:
    159             {
    160                  bt_hci_deinit_transport(pFd);
    161             }
    162             break;
    163 
    164         case BT_VND_OP_GET_LPM_IDLE_TIMEOUT:
    165             break;
    166 
    167         case BT_VND_OP_LPM_SET_MODE:
    168             {
    169                 bt_vendor_cbacks->lpm_cb(BT_VND_OP_RESULT_SUCCESS); //dummy
    170             }
    171             break;
    172 
    173         case BT_VND_OP_LPM_WAKE_SET_STATE:
    174             break;
    175         case BT_VND_OP_EPILOG:
    176             {
    177 #if (HW_NEED_END_WITH_HCI_RESET == FALSE)
    178                 if (bt_vendor_cbacks)
    179                 {
    180                     bt_vendor_cbacks->epilog_cb(BT_VND_OP_RESULT_SUCCESS);
    181                 }
    182 #else
    183                 hw_epilog_process();
    184 #endif
    185             }
    186             break;
    187     }
    188 
    189     return retval;
    190 }
    191 
    192 /** Closes the interface */
    193 static void cleanup( void )
    194 {
    195     ALOGI("cleanup");
    196 
    197     //upio_cleanup();
    198 
    199     bt_vendor_cbacks = NULL;
    200 }
    201 
    202 // Entry point of DLib
    203 const bt_vendor_interface_t BLUETOOTH_VENDOR_LIB_INTERFACE = {
    204     sizeof(bt_vendor_interface_t),
    205     init,
    206     op,
    207     cleanup
    208 };
    209