libbt-vendor: implementation for Qualcomm chipsets

Open-source project was migrated from vendor/qcom/proprietary at the following
commit:

    commit 48f9521fd9863bb06977f5dfac3d30370a292645
    Author: Sungmin Choi <sungmin.choi@lge.com>
    Date:   Wed Oct 10 18:05:45 2012 -0700

	bluetooth: add license

	Bug: 7041466
	Change-Id: Ie410374ec5dff371eda374ed26e081bff8ef5755

Bug: 7041466
Change-Id: Iff9e01b682b00bd09cc58330cb97867bcf828499
Signed-off-by: Iliyan Malchev <malchev@google.com>
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..a5f4e20
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,3 @@
+ifneq ($(filter msm8960,$(TARGET_BOARD_PLATFORM)),)
+include $(call all-named-subdir-makefiles,libbt-vendor)
+endif
diff --git a/CleanSpec.mk b/CleanSpec.mk
new file mode 100755
index 0000000..8ab6f23
--- /dev/null
+++ b/CleanSpec.mk
@@ -0,0 +1,54 @@
+# Copyright (C) 2007 The Android Open Source Project
+#
+# 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.
+#
+
+# If you don't need to do a full clean build but would like to touch
+# a file or delete some intermediate files, add a clean step to the end
+# of the list.  These steps will only be run once, if they haven't been
+# run before.
+#
+# E.g.:
+#     $(call add-clean-step, touch -c external/sqlite/sqlite3.h)
+#     $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates)
+#
+# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with
+# files that are missing or have been moved.
+#
+# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory.
+# Use $(OUT_DIR) to refer to the "out" directory.
+#
+# If you need to re-do something that's already mentioned, just copy
+# the command and add it to the bottom of the list.  E.g., if a change
+# that you made last week required touching a file and a change you
+# made today requires touching the same file, just copy the old
+# touch step and add it to the end of the list.
+#
+# ************************************************
+# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
+# ************************************************
+
+# For example:
+#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates)
+#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates)
+#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
+#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
+
+# ************************************************
+# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
+# ************************************************
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/SHARED_LIBRARIES/libbt-vendor_intermediates)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/NOTICE_FILES/src/system/vendor/lib/libbt-vendor.so.txt)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/lib/libbt-vendor.so)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/symbols/system/vendor/lib/libbt-vendor.so)
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/vendor/lib/libbt-vendor.so)
diff --git a/libbt-vendor/Android.mk b/libbt-vendor/Android.mk
new file mode 100644
index 0000000..2752006
--- /dev/null
+++ b/libbt-vendor/Android.mk
@@ -0,0 +1,47 @@
+#
+# Copyright 2012 The Android Open Source Project
+#
+# 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.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+ifneq ($(BOARD_HAVE_BLUETOOTH_QCOM),)
+
+include $(CLEAR_VARS)
+
+BDROID_DIR:= external/bluetooth/bluedroid
+
+LOCAL_SRC_FILES := \
+        src/bt_vendor_qcom.c \
+        src/hardware.c \
+        src/userial_vendor.c
+
+LOCAL_C_INCLUDES += \
+        $(LOCAL_PATH)/include \
+        $(BDROID_DIR)/hci/include
+
+LOCAL_SHARED_LIBRARIES := \
+        libcutils
+
+LOCAL_MODULE := libbt-vendor
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+LOCAL_MODULE_OWNER := qcom
+LOCAL_MODULE_PATH := $(TARGET_OUT_VENDOR_SHARED_LIBRARIES)
+
+include $(LOCAL_PATH)/vnd_buildcfg.mk
+
+include $(BUILD_SHARED_LIBRARY)
+
+endif # BOARD_HAVE_BLUETOOTH_QCOM
diff --git a/libbt-vendor/NOTICE b/libbt-vendor/NOTICE
new file mode 100644
index 0000000..33ff961
--- /dev/null
+++ b/libbt-vendor/NOTICE
@@ -0,0 +1,190 @@
+
+   Copyright (c) 2005-2012, The Android Open Source Project
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+
+   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.
+
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
diff --git a/libbt-vendor/include/bt_vendor_qcom.h b/libbt-vendor/include/bt_vendor_qcom.h
new file mode 100644
index 0000000..31a18d3
--- /dev/null
+++ b/libbt-vendor/include/bt_vendor_qcom.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2012 The Android Open Source Project
+ *
+ * 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_QCOM_H
+#define BT_VENDOR_QCOM_H
+
+#include "bt_vendor_lib.h"
+#include "vnd_buildcfg.h"
+#include "userial_vendor.h"
+
+#ifndef FALSE
+#define FALSE  0
+#endif
+
+#ifndef TRUE
+#define TRUE   (!FALSE)
+#endif
+
+// File discriptor using Transport
+extern int fd;
+
+extern bt_hci_transport_device_type bt_hci_transport_device;
+
+extern bt_vendor_callbacks_t *bt_vendor_cbacks;
+
+#endif /* BT_VENDOR_BRCM_H */
+
diff --git a/libbt-vendor/include/userial_vendor.h b/libbt-vendor/include/userial_vendor.h
new file mode 100644
index 0000000..31049b7
--- /dev/null
+++ b/libbt-vendor/include/userial_vendor.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2012 The Android Open Source Project
+ *
+ * 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:      userial_vendor.h
+ *
+ *  Description:   Contains vendor-specific definitions used in serial port
+ *                 controls
+ *
+ ******************************************************************************/
+
+#ifndef USERIAL_VENDOR_H
+#define USERIAL_VENDOR_H
+
+/* Variables to identify the platform */
+/*BT HS UART TTY DEVICE */
+#define BT_HS_UART_DEVICE "/dev/ttyHS0"
+/*BT RIVA-SMD CHANNELS */
+#define APPS_RIVA_BT_ACL_CH  "/dev/smd2"
+#define APPS_RIVA_BT_CMD_CH  "/dev/smd3"
+
+typedef enum
+{
+  BT_HCI_UART,
+  BT_HCI_SMD,
+  BT_HCI_NONE = 0xFF
+} bt_hci_transport_enum_type;
+
+typedef struct
+{
+  /*transport type can be SMD/UART*/
+  bt_hci_transport_enum_type type;
+
+  /*hci cmd/event packet is required to carry the Packet indicator for UART interfaces only
+    and not required for smd */
+  int pkt_ind;
+
+  /*transport device can be UART/SMD*/
+  char *name;
+
+} bt_hci_transport_device_type;
+
+bt_hci_transport_device_type bt_hci_set_transport();
+
+int bt_hci_init_transport ( int *pFd );
+
+int bt_hci_deinit_transport(int *pFd);
+
+#endif /* USERIAL_VENDOR_H */
+
diff --git a/libbt-vendor/include/vnd_generic.txt b/libbt-vendor/include/vnd_generic.txt
new file mode 100644
index 0000000..43e790c
--- /dev/null
+++ b/libbt-vendor/include/vnd_generic.txt
@@ -0,0 +1,9 @@
+BLUETOOTH_UART_DEVICE_PORT = "/dev/ttyO1"
+FW_PATCHFILE_LOCATION = "/vendor/firmware/"
+BT_WAKE_VIA_USERIAL_IOCTL = TRUE
+LPM_IDLE_TIMEOUT_MULTIPLE = 5
+SCO_USE_I2S_INTERFACE = TRUE
+BTVND_DBG = FALSE
+BTHW_DBG = TRUE
+VNDUSERIAL_DBG = FALSE
+UPIO_DBG = FALSE
diff --git a/libbt-vendor/include/vnd_mako.txt b/libbt-vendor/include/vnd_mako.txt
new file mode 100644
index 0000000..5408c92
--- /dev/null
+++ b/libbt-vendor/include/vnd_mako.txt
@@ -0,0 +1,9 @@
+BLUETOOTH_UART_DEVICE_PORT = "/dev/smd3"
+FW_PATCHFILE_LOCATION = "/vendor/firmware/"
+BT_WAKE_VIA_USERIAL_IOCTL = TRUE
+LPM_IDLE_TIMEOUT_MULTIPLE = 5
+SCO_USE_I2S_INTERFACE = TRUE
+BTVND_DBG = FALSE
+BTHW_DBG = TRUE
+VNDUSERIAL_DBG = FALSE
+UPIO_DBG = FALSE
diff --git a/libbt-vendor/src/bt_vendor_qcom.c b/libbt-vendor/src/bt_vendor_qcom.c
new file mode 100644
index 0000000..53d3e13
--- /dev/null
+++ b/libbt-vendor/src/bt_vendor_qcom.c
@@ -0,0 +1,191 @@
+/*
+ * Copyright 2012 The Android Open Source Project
+ *
+ * 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_vendor_brcm.c
+ *
+ *  Description:   Broadcom vendor specific library implementation
+ *
+ ******************************************************************************/
+
+#define LOG_TAG "bt_vendor"
+
+#include <utils/Log.h>
+#include <fcntl.h>
+#include <termios.h>
+#include "bt_vendor_qcom.h"
+#include "userial_vendor.h"
+
+/******************************************************************************
+**  Externs
+******************************************************************************/
+extern int hw_config(int nState);
+
+extern int is_hw_ready();
+
+/******************************************************************************
+**  Variables
+******************************************************************************/
+int pFd[2] = {0,};
+bt_hci_transport_device_type bt_hci_transport_device;
+
+bt_vendor_callbacks_t *bt_vendor_cbacks = NULL;
+uint8_t vnd_local_bd_addr[6]={0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+/******************************************************************************
+**  Local type definitions
+******************************************************************************/
+
+
+/******************************************************************************
+**  Functions
+******************************************************************************/
+
+/*****************************************************************************
+**
+**   BLUETOOTH VENDOR INTERFACE LIBRARY FUNCTIONS
+**
+*****************************************************************************/
+
+static int init(const bt_vendor_callbacks_t* p_cb, unsigned char *local_bdaddr)
+{
+    ALOGI("bt-vendor : init");
+
+    if (p_cb == NULL)
+    {
+        ALOGE("init failed with no user callbacks!");
+        return -1;
+    }
+
+    //userial_vendor_init();
+    //upio_init();
+
+    //vnd_load_conf(VENDOR_LIB_CONF_FILE);
+
+    /* store reference to user callbacks */
+    bt_vendor_cbacks = (bt_vendor_callbacks_t *) p_cb;
+
+    /* This is handed over from the stack */
+    memcpy(vnd_local_bd_addr, local_bdaddr, 6);
+
+    return 0;
+}
+
+
+/** Requested operations */
+static int op(bt_vendor_opcode_t opcode, void *param)
+{
+    int retval = 0;
+    int nCnt = 0;
+    int nState = -1;
+
+    ALOGV("bt-vendor : op for %d", opcode);
+
+    switch(opcode)
+    {
+        case BT_VND_OP_POWER_CTRL:
+            {
+                nState = *(int *) param;
+                retval = hw_config(nState);
+                if(nState == BT_VND_PWR_ON
+                   && retval == 0
+                   && is_hw_ready() == TRUE){
+                    retval = 0;
+                }
+                else {
+                    retval = -1;
+                }
+            }
+            break;
+
+        case BT_VND_OP_FW_CFG:
+            {
+                // call hciattach to initalize the stack
+                if(bt_vendor_cbacks){
+                   ALOGI("Bluetooth Firmware and smd is initialized");
+                   bt_vendor_cbacks->fwcfg_cb(BT_VND_OP_RESULT_SUCCESS);
+                }
+                else{
+                   ALOGE("Error : hci, smd initialization Error");
+                   bt_vendor_cbacks->fwcfg_cb(BT_VND_OP_RESULT_FAIL);
+                }
+            }
+            break;
+
+        case BT_VND_OP_SCO_CFG:
+            {
+                bt_vendor_cbacks->scocfg_cb(BT_VND_OP_RESULT_SUCCESS); //dummy
+            }
+            break;
+
+        case BT_VND_OP_USERIAL_OPEN:
+            {
+                if(bt_hci_init_transport(pFd) != -1){
+                    int (*fd_array)[] = (int (*) []) param;
+
+                        (*fd_array)[CH_CMD] = pFd[0];
+                        (*fd_array)[CH_EVT] = pFd[0];
+                        (*fd_array)[CH_ACL_OUT] = pFd[1];
+                        (*fd_array)[CH_ACL_IN] = pFd[1];
+                }
+                else {
+                    retval = -1;
+                    break;
+                }
+                retval = 2;
+            }
+            break;
+
+        case BT_VND_OP_USERIAL_CLOSE:
+            {
+                 bt_hci_deinit_transport(pFd);
+            }
+            break;
+
+        case BT_VND_OP_GET_LPM_IDLE_TIMEOUT:
+            break;
+
+        case BT_VND_OP_LPM_SET_MODE:
+            {
+                bt_vendor_cbacks->lpm_cb(BT_VND_OP_RESULT_SUCCESS); //dummy
+            }
+            break;
+
+        case BT_VND_OP_LPM_WAKE_SET_STATE:
+            break;
+    }
+
+    return retval;
+}
+
+/** Closes the interface */
+static void cleanup( void )
+{
+    ALOGI("cleanup");
+
+    //upio_cleanup();
+
+    bt_vendor_cbacks = NULL;
+}
+
+// Entry point of DLib
+const bt_vendor_interface_t BLUETOOTH_VENDOR_LIB_INTERFACE = {
+    sizeof(bt_vendor_interface_t),
+    init,
+    op,
+    cleanup
+};
diff --git a/libbt-vendor/src/hardware.c b/libbt-vendor/src/hardware.c
new file mode 100644
index 0000000..e1299c4
--- /dev/null
+++ b/libbt-vendor/src/hardware.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2012 The Android Open Source Project
+ *
+ * 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:      hardware.c
+ *
+ *  Description:   Contains controller-specific functions, like
+ *                      firmware patch download
+ *                      low power mode operations
+ *
+ ******************************************************************************/
+
+#define LOG_TAG "bt_hwcfg"
+
+#include <utils/Log.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <signal.h>
+#include <time.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <ctype.h>
+#include <cutils/properties.h>
+#include <stdlib.h>
+#include "bt_hci_bdroid.h"
+#include "bt_vendor_qcom.h"
+
+#define MAX_CNT_RETRY 100
+
+int hw_config(int nState)
+{
+    ALOGI("Starting hciattach daemon");
+    char *szState[] = {"true", "false"};
+    char *szReqSt = NULL;
+
+    if(nState == BT_VND_PWR_OFF)
+        szReqSt = szState[1];
+    else
+        szReqSt = szState[0];
+
+    ALOGI("try to set %s", szReqSt);
+
+    if (property_set("bluetooth.hciattach", szReqSt) < 0){
+        ALOGE("Property Setting fail");
+	return -1;
+    }
+
+    return 0;
+}
+
+int readTrpState()
+{
+    char szBtStatus[20] = {0, };
+    if(property_get("bluetooth.status", szBtStatus, "") < 0){
+        ALOGE("Fail to get bluetooth satus");
+        return FALSE;
+    }
+
+    if(!strncmp(szBtStatus, "on", strlen("on"))){
+        ALOGI("bluetooth satus is on");
+        return TRUE;
+    }
+    return FALSE;
+}
+
+int is_hw_ready()
+{
+    int i=0;
+    char szStatus[10] = {0,};
+
+    for(i=MAX_CNT_RETRY; i>0; i--){
+       usleep(50*1000);
+       //TODO :: checking routine
+       if(readTrpState()==TRUE){
+           break;
+       }
+    }
+
+    return (i==0)? FALSE:TRUE;
+}
diff --git a/libbt-vendor/src/userial_vendor.c b/libbt-vendor/src/userial_vendor.c
new file mode 100644
index 0000000..1e9b39d
--- /dev/null
+++ b/libbt-vendor/src/userial_vendor.c
@@ -0,0 +1,153 @@
+/*
+ * Copyright 2012 The Android Open Source Project
+ *
+ * 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:      userial_vendor.c
+ *
+ *  Description:   Contains vendor-specific userial functions
+ *
+ ******************************************************************************/
+
+#define LOG_TAG "bt_userial_vendor"
+
+#include <utils/Log.h>
+#include <termios.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdio.h>
+#include "bt_vendor_qcom.h"
+#include "userial_vendor.h"
+
+bt_hci_transport_device_type bt_hci_set_transport()
+{
+    int ret;
+    char transport_type[10] = {0,};
+    bt_hci_transport_device_type bt_hci_transport_device;
+
+    ret = property_get("ro.qualcomm.bt.hci_transport", transport_type, NULL);
+    if(ret == 0)
+        printf("ro.qualcomm.bt.hci_transport not set\n");
+    else
+        printf("ro.qualcomm.bt.hci_transport: %s \n", transport_type);
+
+    if (!strcasecmp(transport_type, "smd"))
+    {
+        bt_hci_transport_device.type = BT_HCI_SMD;
+        bt_hci_transport_device.name = APPS_RIVA_BT_CMD_CH;
+        bt_hci_transport_device.pkt_ind = 1;
+    }
+    else{
+        bt_hci_transport_device.type = BT_HCI_UART;
+        bt_hci_transport_device.name = BT_HS_UART_DEVICE;
+        bt_hci_transport_device.pkt_ind = 0;
+    }
+
+    return bt_hci_transport_device;
+}
+
+#define NUM_OF_DEVS 2
+static char *s_pszDevSmd[] = {
+    "/dev/smd3",
+    "/dev/smd2"
+};
+
+int bt_hci_init_transport(int *pFd)
+{
+    int i = 0;
+    int fd;
+    for(i=0; i < NUM_OF_DEVS; i++){
+       fd = bt_hci_init_transport_id(i);
+       if(fd < 0 ){
+          return -1;
+       }
+       pFd[i] = fd;
+    }
+    return 0;
+}
+
+int bt_hci_init_transport_id (int chId )
+{
+  struct termios   term;
+  int fd = -1;
+  int retry = 0;
+
+  if(chId > 2 || chId <0)
+     return -1;
+
+  fd = open(s_pszDevSmd[chId], (O_RDWR | O_NOCTTY));
+
+  while ((-1 == fd) && (retry < 7)) {
+    ALOGE("init_transport: Cannot open %s: %s\n. Retry after 2 seconds",
+        bt_hci_transport_device.name, strerror(errno));
+    usleep(2000000);
+    fd = open(bt_hci_transport_device.name, (O_RDWR | O_NOCTTY));
+    retry++;
+  }
+
+  if (-1 == fd)
+  {
+    ALOGE("init_transport: Cannot open %s: %s\n",
+        bt_hci_transport_device.name, strerror(errno));
+    return -1;
+  }
+
+  /* Sleep (0.5sec) added giving time for the smd port to be successfully
+     opened internally. Currently successful return from open doesn't
+     ensure the smd port is successfully opened.
+     TODO: Following sleep to be removed once SMD port is successfully
+     opened immediately on return from the aforementioned open call */
+  if(BT_HCI_SMD == bt_hci_transport_device.type)
+     usleep(500000);
+
+  if (tcflush(fd, TCIOFLUSH) < 0)
+  {
+    ALOGE("init_uart: Cannot flush %s\n", bt_hci_transport_device.name);
+    close(fd);
+    return -1;
+  }
+
+  if (tcgetattr(fd, &term) < 0)
+  {
+    ALOGE("init_uart: Error while getting attributes\n");
+    close(fd);
+    return -1;
+  }
+
+  cfmakeraw(&term);
+
+  /* JN: Do I need to make flow control configurable, since 4020 cannot
+   * disable it?
+   */
+  term.c_cflag |= (CRTSCTS | CLOCAL);
+
+  if (tcsetattr(fd, TCSANOW, &term) < 0)
+  {
+    ALOGE("init_uart: Error while getting attributes\n");
+    close(fd);
+    return -1;
+  }
+
+  ALOGI("Done intiailizing UART\n");
+  return fd;
+}
+
+int bt_hci_deinit_transport(int *pFd)
+{
+    close(pFd[0]);
+    close(pFd[1]);
+    return TRUE;
+}
diff --git a/libbt-vendor/vnd_buildcfg.mk b/libbt-vendor/vnd_buildcfg.mk
new file mode 100644
index 0000000..d18e121
--- /dev/null
+++ b/libbt-vendor/vnd_buildcfg.mk
@@ -0,0 +1,32 @@
+#
+# Copyright 2012 The Android Open Source Project
+#
+# 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.
+#
+
+intermediates := $(local-intermediates-dir)
+
+SRC := $(call my-dir)/include/$(addprefix vnd_, $(addsuffix .txt,$(basename $(TARGET_DEVICE))))
+ifeq (,$(wildcard $(SRC)))
+# configuration file does not exist. Use default one
+SRC := $(call my-dir)/include/vnd_generic.txt
+endif
+GEN := $(intermediates)/vnd_buildcfg.h
+TOOL := $(TOP_DIR)external/bluetooth/bluedroid/tools/gen-buildcfg.sh
+
+$(GEN): PRIVATE_PATH := $(call my-dir)
+$(GEN): PRIVATE_CUSTOM_TOOL = $(TOOL) $< $@
+$(GEN): $(SRC)  $(TOOL)
+	$(transform-generated-source)
+
+LOCAL_GENERATED_SOURCES += $(GEN)