diff options
| author | Mister Oyster <oysterized@gmail.com> | 2017-01-22 17:45:18 +0100 |
|---|---|---|
| committer | Mister Oyster <oysterized@gmail.com> | 2017-01-22 17:45:18 +0100 |
| commit | 70124fec5b40eb0876cf143f3ba9235df4f2b3d5 (patch) | |
| tree | 2bed9b94918190002d0b300dd7f80ec4080de288 | |
| parent | f4c227f49eee3cd7185864ffca32ae5e69d0e000 (diff) | |
bluetooth: revert to 'LP' blobs and build libbt-vendor-mtk
| -rw-r--r-- | mtk/libbt-vendor-mtk/Android.mk | 27 | ||||
| -rw-r--r-- | mtk/libbt-vendor-mtk/bt_hci_bdroid.h | 135 | ||||
| -rw-r--r-- | mtk/libbt-vendor-mtk/bt_hci_lib.h | 208 | ||||
| -rw-r--r-- | mtk/libbt-vendor-mtk/bt_vendor_lib.h | 362 | ||||
| -rw-r--r-- | mtk/libbt-vendor-mtk/libbt-vendor-mtk.c | 151 | ||||
| -rw-r--r-- | product/packages.mk | 3 |
6 files changed, 886 insertions, 0 deletions
diff --git a/mtk/libbt-vendor-mtk/Android.mk b/mtk/libbt-vendor-mtk/Android.mk new file mode 100644 index 0000000..64a5ab3 --- /dev/null +++ b/mtk/libbt-vendor-mtk/Android.mk @@ -0,0 +1,27 @@ +LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_C_INCLUDES := \ + system/bt/hci/include \ + $(LOCAL_PATH) + +LOCAL_CFLAGS := -g -c -W -Wall -O2 -D_POSIX_SOURCE + +LOCAL_SRC_FILES := libbt-vendor-mtk.c + +LOCAL_SHARED_LIBRARIES := \ + libnativehelper \ + libcutils \ + libutils \ + liblog \ + libdl + +LOCAL_PRELINK_MODULE := false +LOCAL_MODULE := libbt-vendor +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := SHARED_LIBRARIES +LOCAL_MODULE_PATH_64 := $(TARGET_OUT_VENDOR_SHARED_LIBRARIES) +LOCAL_MODULE_PATH_32 := $(2ND_TARGET_OUT_VENDOR_SHARED_LIBRARIES) +LOCAL_MULTILIB := both + +include $(BUILD_SHARED_LIBRARY)
\ No newline at end of file diff --git a/mtk/libbt-vendor-mtk/bt_hci_bdroid.h b/mtk/libbt-vendor-mtk/bt_hci_bdroid.h new file mode 100644 index 0000000..220946b --- /dev/null +++ b/mtk/libbt-vendor-mtk/bt_hci_bdroid.h @@ -0,0 +1,135 @@ +/****************************************************************************** + * + * Copyright (C) 2009-2012 Broadcom Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +/****************************************************************************** + * + * Filename: bt_hci_bdroid.h + * + * Description: A wrapper header file of bt_hci_lib.h + * + * Contains definitions specific for interfacing with Bluedroid + * Bluetooth stack + * + ******************************************************************************/ + +#pragma once + +#include "bt_hci_lib.h" + +#ifdef HAS_BDROID_BUILDCFG +#include "bdroid_buildcfg.h" +#endif + +/****************************************************************************** +** Constants & Macros +******************************************************************************/ + +#if __STDC_VERSION__ < 199901L +# ifndef FALSE +# define FALSE 0 +# endif +# ifndef TRUE +# define TRUE (!FALSE) +# endif +#else +# include <stdbool.h> +# ifndef FALSE +# define FALSE false +# endif +# ifndef TRUE +# define TRUE true +# endif +#endif + +#define HCI_ACL_MAX_SIZE 1024 +#define HCI_MAX_FRAME_SIZE (HCI_ACL_MAX_SIZE + 4) + +/* Host/Controller lib internal event ID */ +typedef enum { + HC_EVENT_LPM_IDLE_TIMEOUT, +} bthc_event_t; + +#define MSG_CTRL_TO_HC_CMD 0x0100 /* evt mask used by HC_EVENT_TX_CMD */ + +/* Message event mask across Host/Controller lib and stack */ +#define MSG_EVT_MASK 0xFF00 /* eq. BT_EVT_MASK */ +#define MSG_SUB_EVT_MASK 0x00FF /* eq. BT_SUB_EVT_MASK */ + +/* Message event ID passed from Host/Controller lib to stack */ +#define MSG_HC_TO_STACK_HCI_ERR 0x1300 /* eq. BT_EVT_TO_BTU_HCIT_ERR */ +#define MSG_HC_TO_STACK_HCI_ACL 0x1100 /* eq. BT_EVT_TO_BTU_HCI_ACL */ +#define MSG_HC_TO_STACK_HCI_SCO 0x1200 /* eq. BT_EVT_TO_BTU_HCI_SCO */ +#define MSG_HC_TO_STACK_HCI_EVT 0x1000 /* eq. BT_EVT_TO_BTU_HCI_EVT */ +#define MSG_HC_TO_STACK_L2C_SEG_XMIT 0x1900 /* eq. BT_EVT_TO_BTU_L2C_SEG_XMIT */ + +/* Message event ID passed from stack to vendor lib */ +#define MSG_STACK_TO_HC_HCI_ACL 0x2100 /* eq. BT_EVT_TO_LM_HCI_ACL */ +#define MSG_STACK_TO_HC_HCI_SCO 0x2200 /* eq. BT_EVT_TO_LM_HCI_SCO */ +#define MSG_STACK_TO_HC_HCI_CMD 0x2000 /* eq. BT_EVT_TO_LM_HCI_CMD */ + +/* Local Bluetooth Controller ID for BR/EDR */ +#define LOCAL_BR_EDR_CONTROLLER_ID 0 + +/* Definitions of audio codec type + * inherited from AG callout function "codec" parameter + */ +#define SCO_CODEC_NONE 0x0000 /* BTA_AG_CODEC_NONE/BTM_SCO_CODEC_NONE */ +#define SCO_CODEC_CVSD 0x0001 /* BTA_AG_CODEC_CVSD/BTM_SCO_CODEC_CVSD */ +#define SCO_CODEC_MSBC 0x0002 /* BTA_AG_CODEC_MSBC/BTM_SCO_CODEC_MSBC */ + +/****************************************************************************** +** Type definitions and return values +******************************************************************************/ + +typedef struct +{ + uint16_t event; + uint16_t len; + uint16_t offset; + uint16_t layer_specific; + uint8_t data[]; +} HC_BT_HDR; + +#define BT_HC_HDR_SIZE (sizeof(HC_BT_HDR)) + +typedef struct _hc_buffer_hdr +{ + struct _hc_buffer_hdr *p_next; /* next buffer in the queue */ + uint8_t reserved1; + uint8_t reserved2; + uint8_t reserved3; + uint8_t reserved4; +} HC_BUFFER_HDR_T; + +#define BT_HC_BUFFER_HDR_SIZE (sizeof(HC_BUFFER_HDR_T)) + +/****************************************************************************** +** Extern variables and functions +******************************************************************************/ + +extern bt_hc_callbacks_t *bt_hc_cbacks; + +/****************************************************************************** +** Functions +******************************************************************************/ + +// Called when a buffer has been produced by the serial layer and should be +// processed by the HCI layer. +void bthc_rx_ready(void); +void bthc_tx(HC_BT_HDR *buf); +void bthc_idle_timeout(void); diff --git a/mtk/libbt-vendor-mtk/bt_hci_lib.h b/mtk/libbt-vendor-mtk/bt_hci_lib.h new file mode 100644 index 0000000..c9f8cd7 --- /dev/null +++ b/mtk/libbt-vendor-mtk/bt_hci_lib.h @@ -0,0 +1,208 @@ +/****************************************************************************** + * + * Copyright (C) 2009-2012 Broadcom Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef BT_HCI_LIB_H +#define BT_HCI_LIB_H + +#include <stdint.h> +#include <stdbool.h> +#include <sys/cdefs.h> +#include <sys/types.h> + +/** Struct types */ + + +/** Typedefs and defines */ + +/* Generic purpose transac returned upon request complete */ +typedef void* TRANSAC; + +/** Bluetooth Power Control States */ +typedef enum { + BT_HC_CHIP_PWR_OFF, + BT_HC_CHIP_PWR_ON, +} bt_hc_chip_power_state_t; + +/** Bluetooth Low Power Mode */ +typedef enum { + BT_HC_LPM_DISABLE, + BT_HC_LPM_ENABLE, + BT_HC_LPM_WAKE_ASSERT, + BT_HC_LPM_WAKE_DEASSERT, +} bt_hc_low_power_event_t; + +/** Receive flow control */ +typedef enum { + BT_RXFLOW_OFF, /* add transport device fd to select set */ + BT_RXFLOW_ON, /* remove transport device to from select set */ +} bt_rx_flow_state_t; + +/** HCI logging control */ +typedef enum { + BT_HC_LOGGING_OFF, + BT_HC_LOGGING_ON, +} bt_hc_logging_state_t; + +/* commands to be used in LSB with MSG_CTRL_TO_HC_CMD */ +typedef enum { + BT_HC_AUDIO_STATE = 0, + BT_HC_CMD_MAX +} bt_hc_tx_cmd_t; +/** Result of write request */ +typedef enum { + BT_HC_TX_SUCCESS, /* a buffer is fully processed and can be released */ + BT_HC_TX_FAIL, /* transmit fail */ + BT_HC_TX_FRAGMENT, /* send split ACL pkt back to stack to reprocess */ +} bt_hc_transmit_result_t; + +/** Result of preload initialization */ +typedef enum { + BT_HC_PRELOAD_SUCCESS, + BT_HC_PRELOAD_FAIL, +} bt_hc_preload_result_t; + +/** Result of postload initialization */ +typedef enum { + BT_HC_POSTLOAD_SUCCESS, + BT_HC_POSTLOAD_FAIL, +} bt_hc_postload_result_t; + +/** Result of low power enable/disable request */ +typedef enum { + BT_HC_LPM_DISABLED, + BT_HC_LPM_ENABLED, +} bt_hc_lpm_request_result_t; + +/** Host/Controller Library Return Status */ +typedef enum { + BT_HC_STATUS_SUCCESS, + BT_HC_STATUS_FAIL, + BT_HC_STATUS_NOT_READY, + BT_HC_STATUS_NOMEM, + BT_HC_STATUS_BUSY, + BT_HC_STATUS_CORRUPTED_BUFFER +} bt_hc_status_t; + + +/* Section comment */ + +/* + * Bluetooth Host/Controller callback structure. + */ + +/* called upon bt host wake signal */ +typedef void (*hostwake_ind_cb)(bt_hc_low_power_event_t event); + +/* preload initialization callback */ +typedef void (*preload_result_cb)(TRANSAC transac, bt_hc_preload_result_t result); + +/* postload initialization callback */ +typedef void (*postload_result_cb)(TRANSAC transac, bt_hc_postload_result_t result); + +/* lpm enable/disable callback */ +typedef void (*lpm_result_cb)(bt_hc_lpm_request_result_t result); + +/* datapath buffer allocation callback (callout) */ +typedef char* (*alloc_mem_cb)(int size); + +/* datapath buffer deallocation callback (callout) */ +typedef void (*dealloc_mem_cb)(TRANSAC transac); + +/* transmit result callback */ +typedef int (*tx_result_cb)(TRANSAC transac, char *p_buf, bt_hc_transmit_result_t result); + +/* a previously setup buffer is read and available for processing + buffer is deallocated in stack when processed */ +typedef int (*data_ind_cb)(TRANSAC transac, char *p_buf, int len); + +typedef struct { + /** set to sizeof(bt_hc_callbacks_t) */ + size_t size; + + /* notifies caller result of preload request */ + preload_result_cb preload_cb; + + /* notifies caller result of postload request */ + postload_result_cb postload_cb; + + /* notifies caller result of lpm enable/disable */ + lpm_result_cb lpm_cb; + + /* notifies hardware on host wake state */ + hostwake_ind_cb hostwake_ind; + + /* buffer allocation request */ + alloc_mem_cb alloc; + + /* buffer deallocation request */ + dealloc_mem_cb dealloc; + + /* notifies stack data is available */ + data_ind_cb data_ind; + + /* notifies caller when a buffer is transmitted (or failed) */ + tx_result_cb tx_result; +} bt_hc_callbacks_t; + +/* + * Bluetooth Host/Controller Interface + */ +typedef struct { + /** Set to sizeof(bt_hc_interface_t) */ + size_t size; + + /** + * Opens the interface and provides the callback routines + * to the implemenation of this interface. + */ + int (*init)(const bt_hc_callbacks_t* p_cb, unsigned char *local_bdaddr); + + /** Chip power control */ + void (*set_power)(bt_hc_chip_power_state_t state); + + /** Set low power mode wake */ + int (*lpm)(bt_hc_low_power_event_t event); + + /** Called prior to stack initialization */ + void (*preload)(TRANSAC transac); + + /** Called post stack initialization */ + void (*postload)(TRANSAC transac); + + /** Transmit buffer */ + int (*transmit_buf)(TRANSAC transac, char *p_buf, int len); + + /** Controls HCI logging on/off */ + int (*logging)(bt_hc_logging_state_t state, char *p_path, bool save_existing); + + /** Closes the interface */ + void (*cleanup)( void ); + + /** sends commands to hc layer (e.g. SCO state) */ + int (*tx_cmd)(TRANSAC transac, char *p_buf, int len); +} bt_hc_interface_t; + + +/* + * External shared lib functions + */ + +extern const bt_hc_interface_t* bt_hc_get_interface(void); + +#endif /* BT_HCI_LIB_H */ + diff --git a/mtk/libbt-vendor-mtk/bt_vendor_lib.h b/mtk/libbt-vendor-mtk/bt_vendor_lib.h new file mode 100644 index 0000000..65d448b --- /dev/null +++ b/mtk/libbt-vendor-mtk/bt_vendor_lib.h @@ -0,0 +1,362 @@ +/****************************************************************************** + * + * Copyright (C) 2009-2012 Broadcom Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +#ifndef BT_VENDOR_LIB_H +#define BT_VENDOR_LIB_H + +#include <stdint.h> +#include <sys/cdefs.h> +#include <sys/types.h> + +/** Struct types */ + + +/** Typedefs and defines */ + +/** Vendor specific operations OPCODE */ +typedef enum { +/* [operation] + * Power on or off the BT Controller. + * [input param] + * A pointer to int type with content of bt_vendor_power_state_t. + * Typecasting conversion: (int *) param. + * [return] + * 0 - default, don't care. + * [callback] + * None. + */ + BT_VND_OP_POWER_CTRL, + +/* [operation] + * Perform any vendor specific initialization or configuration + * on the BT Controller. This is called before stack initialization. + * [input param] + * None. + * [return] + * 0 - default, don't care. + * [callback] + * Must call fwcfg_cb to notify the stack of the completion of vendor + * specific initialization once it has been done. + */ + BT_VND_OP_FW_CFG, + +/* [operation] + * Perform any vendor specific SCO/PCM configuration on the BT Controller. + * This is called after stack initialization. + * [input param] + * None. + * [return] + * 0 - default, don't care. + * [callback] + * Must call scocfg_cb to notify the stack of the completion of vendor + * specific SCO configuration once it has been done. + */ + BT_VND_OP_SCO_CFG, + +/* [operation] + * Open UART port on where the BT Controller is attached. + * This is called before stack initialization. + * [input param] + * A pointer to int array type for open file descriptors. + * The mapping of HCI channel to fd slot in the int array is given in + * bt_vendor_hci_channels_t. + * And, it requires the vendor lib to fill up the content before returning + * the call. + * Typecasting conversion: (int (*)[]) param. + * [return] + * Numbers of opened file descriptors. + * Valid number: + * 1 - CMD/EVT/ACL-In/ACL-Out via the same fd (e.g. UART) + * 2 - CMD/EVT on one fd, and ACL-In/ACL-Out on the other fd + * 4 - CMD, EVT, ACL-In, ACL-Out are on their individual fd + * [callback] + * None. + */ + BT_VND_OP_USERIAL_OPEN, + +/* [operation] + * Close the previously opened UART port. + * [input param] + * None. + * [return] + * 0 - default, don't care. + * [callback] + * None. + */ + BT_VND_OP_USERIAL_CLOSE, + +/* [operation] + * Get the LPM idle timeout in milliseconds. + * The stack uses this information to launch a timer delay before it + * attempts to de-assert LPM WAKE signal once downstream HCI packet + * has been delivered. + * [input param] + * A pointer to uint32_t type which is passed in by the stack. And, it + * requires the vendor lib to fill up the content before returning + * the call. + * Typecasting conversion: (uint32_t *) param. + * [return] + * 0 - default, don't care. + * [callback] + * None. + */ + BT_VND_OP_GET_LPM_IDLE_TIMEOUT, + +/* [operation] + * Enable or disable LPM mode on BT Controller. + * [input param] + * A pointer to uint8_t type with content of bt_vendor_lpm_mode_t. + * Typecasting conversion: (uint8_t *) param. + * [return] + * 0 - default, don't care. + * [callback] + * Must call lpm_cb to notify the stack of the completion of LPM + * disable/enable process once it has been done. + */ + BT_VND_OP_LPM_SET_MODE, + +/* [operation] + * Assert or Deassert LPM WAKE on BT Controller. + * [input param] + * A pointer to uint8_t type with content of bt_vendor_lpm_wake_state_t. + * Typecasting conversion: (uint8_t *) param. + * [return] + * 0 - default, don't care. + * [callback] + * None. + */ + BT_VND_OP_LPM_WAKE_SET_STATE, + +/* [operation] + * Perform any vendor specific commands related to audio state changes. + * [input param] + * a pointer to bt_vendor_op_audio_state_t indicating what audio state is + * set. + * [return] + * 0 - default, don't care. + * [callback] + * None. + */ + BT_VND_OP_SET_AUDIO_STATE, + +/* [operation] + * The epilog call to the vendor module so that it can perform any + * vendor-specific processes (e.g. send a HCI_RESET to BT Controller) + * before the caller calls for cleanup(). + * [input param] + * None. + * [return] + * 0 - default, don't care. + * [callback] + * Must call epilog_cb to notify the stack of the completion of vendor + * specific epilog process once it has been done. + */ + BT_VND_OP_EPILOG, +} bt_vendor_opcode_t; + +/** Power on/off control states */ +typedef enum { + BT_VND_PWR_OFF, + BT_VND_PWR_ON, +} bt_vendor_power_state_t; + +/** Define HCI channel identifier in the file descriptors array + used in BT_VND_OP_USERIAL_OPEN operation. + */ +typedef enum { + CH_CMD, // HCI Command channel + CH_EVT, // HCI Event channel + CH_ACL_OUT, // HCI ACL downstream channel + CH_ACL_IN, // HCI ACL upstream channel + + CH_MAX // Total channels +} bt_vendor_hci_channels_t; + +/** LPM disable/enable request */ +typedef enum { + BT_VND_LPM_DISABLE, + BT_VND_LPM_ENABLE, +} bt_vendor_lpm_mode_t; + +/** LPM WAKE set state request */ +typedef enum { + BT_VND_LPM_WAKE_ASSERT, + BT_VND_LPM_WAKE_DEASSERT, +} bt_vendor_lpm_wake_state_t; + +/** Callback result values */ +typedef enum { + BT_VND_OP_RESULT_SUCCESS, + BT_VND_OP_RESULT_FAIL, +} bt_vendor_op_result_t; + +/** audio (SCO) state changes triggering VS commands for configuration */ +typedef struct { + uint16_t handle; + uint16_t peer_codec; + uint16_t state; +} bt_vendor_op_audio_state_t; + +/* + * Bluetooth Host/Controller Vendor callback structure. + */ + +/* vendor initialization/configuration callback */ +typedef void (*cfg_result_cb)(bt_vendor_op_result_t result); + +/* datapath buffer allocation callback (callout) + * + * Vendor lib needs to request a buffer through the alloc callout function + * from HCI lib if the buffer is for constructing a HCI Command packet which + * will be sent through xmit_cb to BT Controller. + * + * For each buffer allocation, the requested size needs to be big enough to + * accommodate the below header plus a complete HCI packet -- + * typedef struct + * { + * uint16_t event; + * uint16_t len; + * uint16_t offset; + * uint16_t layer_specific; + * } HC_BT_HDR; + * + * HCI lib returns a pointer to the buffer where Vendor lib should use to + * construct a HCI command packet as below format: + * + * -------------------------------------------- + * | HC_BT_HDR | HCI command | + * -------------------------------------------- + * where + * HC_BT_HDR.event = 0x2000; + * HC_BT_HDR.len = Length of HCI command; + * HC_BT_HDR.offset = 0; + * HC_BT_HDR.layer_specific = 0; + * + * For example, a HCI_RESET Command will be formed as + * ------------------------ + * | HC_BT_HDR |03|0c|00| + * ------------------------ + * with + * HC_BT_HDR.event = 0x2000; + * HC_BT_HDR.len = 3; + * HC_BT_HDR.offset = 0; + * HC_BT_HDR.layer_specific = 0; + */ +typedef void* (*malloc_cb)(int size); + +/* datapath buffer deallocation callback (callout) */ +typedef void (*mdealloc_cb)(void *p_buf); + +/* define callback of the cmd_xmit_cb + * + * The callback function which HCI lib will call with the return of command + * complete packet. Vendor lib is responsible for releasing the buffer passed + * in at the p_mem parameter by calling dealloc callout function. + */ +typedef void (*tINT_CMD_CBACK)(void *p_mem); + +/* hci command packet transmit callback (callout) + * + * Vendor lib calls xmit_cb callout function in order to send a HCI Command + * packet to BT Controller. The buffer carrying HCI Command packet content + * needs to be first allocated through the alloc callout function. + * HCI lib will release the buffer for Vendor lib once it has delivered the + * packet content to BT Controller. + * + * Vendor lib needs also provide a callback function (p_cback) which HCI lib + * will call with the return of command complete packet. + * + * The opcode parameter gives the HCI OpCode (combination of OGF and OCF) of + * HCI Command packet. For example, opcode = 0x0c03 for the HCI_RESET command + * packet. + */ +typedef uint8_t (*cmd_xmit_cb)(uint16_t opcode, void *p_buf, tINT_CMD_CBACK p_cback); + +typedef struct { + /** set to sizeof(bt_vendor_callbacks_t) */ + size_t size; + + /* + * Callback and callout functions have implemented in HCI libray + * (libbt-hci.so). + */ + + /* notifies caller result of firmware configuration request */ + cfg_result_cb fwcfg_cb; + + /* notifies caller result of sco configuration request */ + cfg_result_cb scocfg_cb; + + /* notifies caller result of lpm enable/disable */ + cfg_result_cb lpm_cb; + + /* notifies the result of codec setting */ + cfg_result_cb audio_state_cb; + + /* buffer allocation request */ + malloc_cb alloc; + + /* buffer deallocation request */ + mdealloc_cb dealloc; + + /* hci command packet transmit request */ + cmd_xmit_cb xmit_cb; + + /* notifies caller completion of epilog process */ + cfg_result_cb epilog_cb; +} bt_vendor_callbacks_t; + +/* + * Bluetooth Host/Controller VENDOR Interface + */ +typedef struct { + /** Set to sizeof(bt_vndor_interface_t) */ + size_t size; + + /* + * Functions need to be implemented in Vendor libray (libbt-vendor.so). + */ + + /** + * Caller will open the interface and pass in the callback routines + * to the implemenation of this interface. + */ + int (*init)(const bt_vendor_callbacks_t* p_cb, unsigned char *local_bdaddr); + + /** Vendor specific operations */ + int (*op)(bt_vendor_opcode_t opcode, void *param); + + /** Closes the interface */ + void (*cleanup)(void); +} bt_vendor_interface_t; + + +/* + * External shared lib functions/data + */ + +/* Entry point of DLib -- + * Vendor library needs to implement the body of bt_vendor_interface_t + * structure and uses the below name as the variable name. HCI library + * will use this symbol name to get address of the object through the + * dlsym call. + */ +extern const bt_vendor_interface_t BLUETOOTH_VENDOR_LIB_INTERFACE; + +#endif /* BT_VENDOR_LIB_H */ + diff --git a/mtk/libbt-vendor-mtk/libbt-vendor-mtk.c b/mtk/libbt-vendor-mtk/libbt-vendor-mtk.c new file mode 100644 index 0000000..87f4c08 --- /dev/null +++ b/mtk/libbt-vendor-mtk/libbt-vendor-mtk.c @@ -0,0 +1,151 @@ +#define LOG_TAG "libbt_vendor_mtk" + +#include <stdlib.h> +#include <stdio.h> +#include <dlfcn.h> +#include <utils/Log.h> +#include <pthread.h> +#include <fcntl.h> +#include <errno.h> +#include <bt_vendor_lib.h> +#include <bt_hci_lib.h> +#include <bt_hci_bdroid.h> + +/** + * TODO: check/fix this value. does this make sense for MTK? It is taken from TI + * Low power mode: default transport idle timer + */ +#define WL_DEFAULT_LPM_IDLE_TIMEOUT 200 + +static void *mtklib_handle = NULL; +typedef int (*ENABLE)(int flag, void *func_cb); +typedef int (*DISABLE)(int bt_fd); + +unsigned int hci_tty_fd = -1; + +ENABLE mtk_bt_enable = NULL; +DISABLE mtk_bt_disable = NULL; + +bt_vendor_callbacks_t *bt_vendor_cbacks = NULL; +void hw_config_cback(HC_BT_HDR *p_evt_buf); + +/******************************************************************************* + * + * Function hw_config_cback + * + * Description Callback function for controller configuration + * + * Returns None + * + * *******************************************************************************/ +void hw_config_cback(HC_BT_HDR *p_evt_buf) +{ + ALOGI("hw_config_cback"); +} + +int mtk_init(const bt_vendor_callbacks_t* p_cb, unsigned char *local_bdaddr) { + const char *dlerrors; + + ALOGI("libbt-vendor init for MTK blob"); + + if (p_cb == NULL) + { + ALOGE("init failed with no user callbacks!"); + return BT_HC_STATUS_FAIL; + } + + bt_vendor_cbacks = (bt_vendor_callbacks_t *) p_cb; + + dlerror(); + + mtklib_handle = dlopen("libbluetoothdrv.so", RTLD_LAZY); + + mtk_bt_enable = dlsym(mtklib_handle, "mtk_bt_enable"); + mtk_bt_disable = dlsym(mtklib_handle, "mtk_bt_disable"); + + if ((dlerrors = dlerror()) != NULL){ + ALOGE("Errors while opening symbols from mtk blob"); + dlclose(mtklib_handle); + } + return 0; +} + +void mtk_cleanup(void) { + ALOGI("vendor cleanup"); + bt_vendor_cbacks = NULL; + + if (mtklib_handle) { + dlclose(mtklib_handle); + } +} + +int mtk_open(void **param) { + int (*fd_array)[] = (int (*)[]) param; + int fd, idx; + fd = mtk_bt_enable(0, NULL); + if (fd < 0) { + ALOGE("Can't open mtk fd"); + return -1; + } + for (idx = 0; idx < CH_MAX; idx++) + (*fd_array)[idx] = fd; + + hci_tty_fd = fd; /* for userial_close op */ + return 1; /* CMD/EVT/ACL on same fd */ +} + +int mtk_close() { + if (hci_tty_fd == (unsigned int) -1) + return -1; + return mtk_bt_disable(hci_tty_fd); +} + +int mtk_op(bt_vendor_opcode_t opcode, void **param) { + int ret = 0; + + switch(opcode) + { + case BT_VND_OP_POWER_CTRL: + break; + case BT_VND_OP_SCO_CFG: + break; + case BT_VND_OP_GET_LPM_IDLE_TIMEOUT: + *((uint32_t *) param) = WL_DEFAULT_LPM_IDLE_TIMEOUT; + break; + case BT_VND_OP_LPM_SET_MODE: + break; + case BT_VND_OP_LPM_WAKE_SET_STATE: + break; + case BT_VND_OP_USERIAL_OPEN: + ret = mtk_open(param); + break; + case BT_VND_OP_USERIAL_CLOSE: + ret = mtk_close(); + break; + /* Since new stack expects fwcfg_cb we are returning SUCCESS here + * in actual, firmware download is already happened when /dev/hci_tty + * opened. + */ + case BT_VND_OP_FW_CFG: + bt_vendor_cbacks->fwcfg_cb(BT_VND_OP_RESULT_SUCCESS); + break; + case BT_VND_OP_EPILOG: + bt_vendor_cbacks->epilog_cb(BT_VND_OP_RESULT_SUCCESS); + break; + default: + ALOGW("Unknown opcode: %d", opcode); + break; + } + + return ret; +} +const bt_vendor_interface_t BLUETOOTH_VENDOR_LIB_INTERFACE = { + .init = mtk_init, + .op = mtk_op, + .cleanup = mtk_cleanup, +}; + +int main() +{ + return 0; +} diff --git a/product/packages.mk b/product/packages.mk index b419430..5e48cba 100644 --- a/product/packages.mk +++ b/product/packages.mk @@ -52,6 +52,9 @@ PRODUCT_PACKAGES += \ gps.mt6753 \
libcurl
+# BT
+PRODUCT_PACKAGES += libbt-vendor
+
# Audio
PRODUCT_PACKAGES += \
audio.a2dp.default \
|
