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 <string.h>
     29 #include <fcntl.h>
     30 #include <termios.h>
     31 #include "bt_vendor_qcom.h"
     32 #include "userial_vendor.h"
     33 
     34 /******************************************************************************
     35 **  Externs
     36 ******************************************************************************/
     37 extern int hw_config(int nState);
     38 
     39 extern int is_hw_ready();
     40 
     41 /******************************************************************************
     42 **  Variables
     43 ******************************************************************************/
     44 int pFd[2] = {0,};
     45 bt_hci_transport_device_type bt_hci_transport_device;
     46 
     47 bt_vendor_callbacks_t *bt_vendor_cbacks = NULL;
     48 uint8_t vnd_local_bd_addr[6]={0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
     49 
     50 #if (HW_NEED_END_WITH_HCI_RESET == TRUE)
     51 void hw_epilog_process(void);
     52 #endif
     53 
     54 
     55 /******************************************************************************
     56 **  Local type definitions
     57 ******************************************************************************/
     58 
     59 
     60 /******************************************************************************
     61 **  Functions
     62 ******************************************************************************/
     63 
     64 /*****************************************************************************
     65 **
     66 **   BLUETOOTH VENDOR INTERFACE LIBRARY FUNCTIONS
     67 **
     68 *****************************************************************************/
     69 
     70 static int init(const bt_vendor_callbacks_t* p_cb, unsigned char *local_bdaddr)
     71 {
     72     ALOGI("bt-vendor : init");
     73 
     74     if (p_cb == NULL)
     75     {
     76         ALOGE("init failed with no user callbacks!");
     77         return -1;
     78     }
     79 
     80     //userial_vendor_init();
     81     //upio_init();
     82 
     83     //vnd_load_conf(VENDOR_LIB_CONF_FILE);
     84 
     85     /* store reference to user callbacks */
     86     bt_vendor_cbacks = (bt_vendor_callbacks_t *) p_cb;
     87 
     88     /* This is handed over from the stack */
     89     memcpy(vnd_local_bd_addr, local_bdaddr, 6);
     90 
     91     return 0;
     92 }
     93 
     94 
     95 /** Requested operations */
     96 static int op(bt_vendor_opcode_t opcode, void *param)
     97 {
     98     int retval = 0;
     99     int nCnt = 0;
    100     int nState = -1;
    101 
    102     ALOGV("bt-vendor : op for %d", opcode);
    103 
    104     switch(opcode)
    105     {
    106         case BT_VND_OP_POWER_CTRL:
    107             {
    108                 nState = *(int *) param;
    109                 retval = hw_config(nState);
    110                 if(nState == BT_VND_PWR_ON
    111                    && retval == 0
    112                    && is_hw_ready() == TRUE){
    113                     retval = 0;
    114                 }
    115                 else {
    116                     retval = -1;
    117                 }
    118             }
    119             break;
    120 
    121         case BT_VND_OP_FW_CFG:
    122             {
    123                 // call hciattach to initalize the stack
    124                 if(bt_vendor_cbacks){
    125                    ALOGI("Bluetooth Firmware and smd is initialized");
    126                    bt_vendor_cbacks->fwcfg_cb(BT_VND_OP_RESULT_SUCCESS);
    127                 }
    128                 else{
    129                    ALOGE("Error : hci, smd initialization Error");
    130                    bt_vendor_cbacks->fwcfg_cb(BT_VND_OP_RESULT_FAIL);
    131                 }
    132             }
    133             break;
    134 
    135         case BT_VND_OP_SCO_CFG:
    136             {
    137                 bt_vendor_cbacks->scocfg_cb(BT_VND_OP_RESULT_SUCCESS); //dummy
    138             }
    139             break;
    140 
    141         case BT_VND_OP_USERIAL_OPEN:
    142             {
    143                 if(bt_hci_init_transport(pFd) != -1){
    144                     int (*fd_array)[] = (int (*) []) param;
    145 
    146                         (*fd_array)[CH_CMD] = pFd[0];
    147                         (*fd_array)[CH_EVT] = pFd[0];
    148                         (*fd_array)[CH_ACL_OUT] = pFd[1];
    149                         (*fd_array)[CH_ACL_IN] = pFd[1];
    150                 }
    151                 else {
    152                     retval = -1;
    153                     break;
    154                 }
    155                 retval = 2;
    156             }
    157             break;
    158 
    159         case BT_VND_OP_USERIAL_CLOSE:
    160             {
    161                  bt_hci_deinit_transport(pFd);
    162             }
    163             break;
    164 
    165         case BT_VND_OP_GET_LPM_IDLE_TIMEOUT:
    166             break;
    167 
    168         case BT_VND_OP_LPM_SET_MODE:
    169             {
    170                 bt_vendor_cbacks->lpm_cb(BT_VND_OP_RESULT_SUCCESS); //dummy
    171             }
    172             break;
    173 
    174         case BT_VND_OP_LPM_WAKE_SET_STATE:
    175             break;
    176         case BT_VND_OP_EPILOG:
    177             {
    178 #if (HW_NEED_END_WITH_HCI_RESET == FALSE)
    179                 if (bt_vendor_cbacks)
    180                 {
    181                     bt_vendor_cbacks->epilog_cb(BT_VND_OP_RESULT_SUCCESS);
    182                 }
    183 #else
    184                 hw_epilog_process();
    185 #endif
    186             }
    187             break;
    188     }
    189 
    190     return retval;
    191 }
    192 
    193 /** Closes the interface */
    194 static void cleanup( void )
    195 {
    196     ALOGI("cleanup");
    197 
    198     //upio_cleanup();
    199 
    200     bt_vendor_cbacks = NULL;
    201 }
    202 
    203 // Entry point of DLib
    204 const bt_vendor_interface_t BLUETOOTH_VENDOR_LIB_INTERFACE = {
    205     sizeof(bt_vendor_interface_t),
    206     init,
    207     op,
    208     cleanup
    209 };
    210