am ba2f6d99: Revert "anthias:17614185:Bluetooth: Getbuf returning invalid buffer pointer"

* commit 'ba2f6d995d058bc9e77d860d0d755e4ae6086deb':
  Revert "anthias:17614185:Bluetooth: Getbuf returning invalid buffer pointer"
diff --git a/Android.mk b/Android.mk
index 5f2d274..9e197f0 100644
--- a/Android.mk
+++ b/Android.mk
@@ -1,12 +1,14 @@
 LOCAL_PATH := $(call my-dir)
 
+bdroid_CFLAGS := -Wno-unused-parameter
+
 # Setup bdroid local make variables for handling configuration
 ifneq ($(BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR),)
   bdroid_C_INCLUDES := $(BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR)
-  bdroid_CFLAGS := -DHAS_BDROID_BUILDCFG
+  bdroid_CFLAGS += -DHAS_BDROID_BUILDCFG
 else
   bdroid_C_INCLUDES :=
-  bdroid_CFLAGS := -DHAS_NO_BDROID_BUILDCFG
+  bdroid_CFLAGS += -DHAS_NO_BDROID_BUILDCFG
 endif
 
 include $(call all-subdir-makefiles)
diff --git a/audio_a2dp_hw/Android.mk b/audio_a2dp_hw/Android.mk
index f9fd0a1..d2a8f0a 100644
--- a/audio_a2dp_hw/Android.mk
+++ b/audio_a2dp_hw/Android.mk
@@ -6,6 +6,7 @@
 	audio_a2dp_hw.c
 
 LOCAL_C_INCLUDES+= . $(LOCAL_PATH)/../utils/include
+LOCAL_CFLAGS := -Wno-unused-parameter
 
 LOCAL_SHARED_LIBRARIES := \
 	libcutils liblog
diff --git a/audio_a2dp_hw/audio_a2dp_hw.c b/audio_a2dp_hw/audio_a2dp_hw.c
index cde56c1..dacba66 100644
--- a/audio_a2dp_hw/audio_a2dp_hw.c
+++ b/audio_a2dp_hw/audio_a2dp_hw.c
@@ -25,6 +25,7 @@
  *****************************************************************************/
 
 #include <errno.h>
+#include <inttypes.h>
 #include <pthread.h>
 #include <stdint.h>
 #include <sys/time.h>
@@ -47,7 +48,7 @@
 
 #define LOG_TAG "audio_a2dp_hw"
 /* #define LOG_NDEBUG 0 */
-#include <cutils/log.h>
+#include <log/log.h>
 
 /*****************************************************************************
 **  Constants & Macros
@@ -195,7 +196,7 @@
     struct sockaddr_un remote;
     int len;
 
-    INFO("connect to %s (sz %d)", path, out->buffer_sz);
+    INFO("connect to %s (sz %zu)", path, out->buffer_sz);
 
     skt_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
 
@@ -443,7 +444,7 @@
     struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
     int sent;
 
-    DEBUG("write %d bytes (fd %d)", bytes, out->audio_fd);
+    DEBUG("write %zu bytes (fd %d)", bytes, out->audio_fd);
 
     if (out->state == AUDIO_A2DP_STATE_SUSPENDED)
     {
@@ -488,7 +489,7 @@
         out->state = AUDIO_A2DP_STATE_STOPPED;
     }
 
-    DEBUG("wrote %d bytes out of %d bytes", sent, bytes);
+    DEBUG("wrote %d bytes out of %zu bytes", sent, bytes);
     return sent;
 }
 
@@ -497,7 +498,7 @@
 {
     struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
 
-    DEBUG("rate %d", out->cfg.rate);
+    DEBUG("rate %" PRIu32, out->cfg.rate);
 
     return out->cfg.rate;
 }
@@ -506,7 +507,7 @@
 {
     struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
 
-    DEBUG("out_set_sample_rate : %d", rate);
+    DEBUG("out_set_sample_rate : %" PRIu32, rate);
 
     if (rate != AUDIO_STREAM_DEFAULT_RATE)
     {
@@ -523,7 +524,7 @@
 {
     struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
 
-    DEBUG("buffer_size : %d", out->buffer_sz);
+    DEBUG("buffer_size : %zu", out->buffer_sz);
 
     return out->buffer_sz;
 }
@@ -532,7 +533,7 @@
 {
     struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
 
-    DEBUG("channels 0x%x", out->cfg.channel_flags);
+    DEBUG("channels 0x%" PRIx32, out->cfg.channel_flags);
 
     return out->cfg.channel_flags;
 }
diff --git a/bta/Android.mk b/bta/Android.mk
index bca6c08..310080d 100644
--- a/bta/Android.mk
+++ b/bta/Android.mk
@@ -1,5 +1,3 @@
-ifneq ($(TARGET_SIMULATOR),true)
-
 LOCAL_PATH:= $(call my-dir)
 
 include $(CLEAR_VARS)
@@ -103,5 +101,3 @@
 
 
 include $(BUILD_STATIC_LIBRARY)
-
-endif  # TARGET_SIMULATOR != true
diff --git a/bta/av/bta_av_aact.c b/bta/av/bta_av_aact.c
index fed838a..6b1a352 100644
--- a/bta/av/bta_av_aact.c
+++ b/bta/av/bta_av_aact.c
@@ -2170,15 +2170,15 @@
         p_scb->q_tag = BTA_AV_Q_TAG_START;
     }
 
-    if (p_scb->wait & BTA_AV_WAIT_ACP_CAPS_ON)
-    {
-        p_scb->wait |= BTA_AV_WAIT_ACP_CAPS_STARTED;
-    }
-
     if (p_scb->wait)
     {
-        APPL_TRACE_DEBUG2("wait:x%x q_tag:%d- not started", p_scb->wait, p_scb->q_tag);
-        return;
+        APPL_TRACE_ERROR2("wait:x%x q_tag:%d- not started", p_scb->wait, p_scb->q_tag);
+        /* Clear first bit of p_scb->wait and not to return from this point else
+         * HAL layer gets blocked. And if there is delay in Get Capability response as
+         * first bit of p_scb->wait is cleared hence it ensures bt_av_start_ok is not called
+         * again from bta_av_save_caps.
+        */
+        p_scb->wait &= ~BTA_AV_WAIT_ACP_CAPS_ON;
     }
 
     /* tell role manager to check M/S role */
diff --git a/bta/dm/bta_dm_act.c b/bta/dm/bta_dm_act.c
index ee1ba03..6a72e97 100755
--- a/bta/dm/bta_dm_act.c
+++ b/bta/dm/bta_dm_act.c
@@ -38,6 +38,7 @@
 #include "l2c_api.h"
 #include "wbt_api.h"
 #include "utl.h"
+#include "gap_api.h"    /* For GAP_BleReadPeerPrefConnParams */
 #include <string.h>
 
 #if (GAP_INCLUDED == TRUE)
diff --git a/bta/dm/bta_dm_cfg.c b/bta/dm/bta_dm_cfg.c
index e4a1681..cdc623d 100644
--- a/bta/dm/bta_dm_cfg.c
+++ b/bta/dm/bta_dm_cfg.c
@@ -111,9 +111,9 @@
 tBTA_DM_RM *p_bta_dm_rm_cfg = (tBTA_DM_RM *)&bta_dm_rm_cfg;
 
 #if BLE_INCLUDED == TRUE
-#define BTA_DM_NUM_PM_ENTRY         (17+BTA_DM_NUM_JV_ID)  /* number of entries in bta_dm_pm_cfg except the first */
+#define BTA_DM_NUM_PM_ENTRY         (19+BTA_DM_NUM_JV_ID)  /* number of entries in bta_dm_pm_cfg except the first */
 #else
-#define BTA_DM_NUM_PM_ENTRY         (15+BTA_DM_NUM_JV_ID)  /* number of entries in bta_dm_pm_cfg except the first */
+#define BTA_DM_NUM_PM_ENTRY         (17+BTA_DM_NUM_JV_ID)  /* number of entries in bta_dm_pm_cfg except the first */
 #endif
 
 tBTA_DM_PM_TYPE_QUALIFIER tBTA_DM_PM_CFG bta_dm_pm_cfg[] =
@@ -135,24 +135,26 @@
   {BTA_ID_MSE, BTA_ALL_APP_ID,      7},  /* reuse fts spec table */
   {BTA_ID_JV,  BTA_JV_PM_ID_1,      6},  /* app BTA_JV_PM_ID_1, reuse ftc spec table */
   {BTA_ID_JV,  BTA_ALL_APP_ID,      7},  /* reuse fts spec table */
-  {BTA_ID_HL,  BTA_ALL_APP_ID,      8}   /* reuse fts spec table */
+  {BTA_ID_HL,  BTA_ALL_APP_ID,      8},  /* reuse fts spec table */
+  {BTA_ID_PAN, BTUI_PAN_ID_PANU,    9},  /*  PANU spec table */
+  {BTA_ID_PAN, BTUI_PAN_ID_NAP,    10}   /* NAP spec table */
 #if BLE_INCLUDED == TRUE
-  ,{BTA_ID_GATTC,  BTA_ALL_APP_ID,   9}   /* gattc spec table */
-  ,{BTA_ID_GATTS,  BTA_ALL_APP_ID,   10}  /* gatts spec table */
+  ,{BTA_ID_GATTC,  BTA_ALL_APP_ID,   11}   /* gattc spec table */
+  ,{BTA_ID_GATTS,  BTA_ALL_APP_ID,   12}  /* gatts spec table */
 #endif
 };
 
 #if BLE_INCLUDED == TRUE /* add GATT PM entry for GATT over BR/EDR  */
 #ifdef BTE_SIM_APP      /* For Insight builds only, see the detail below */
-#define BTA_DM_NUM_PM_SPEC      (11 + 2)  /* additional two */
+#define BTA_DM_NUM_PM_SPEC      (13 + 2)  /* additional two */
 #else
-#define BTA_DM_NUM_PM_SPEC      11 /* additional JV*/
+#define BTA_DM_NUM_PM_SPEC      13 /* additional JV*/
 #endif
 #else
 #ifdef BTE_SIM_APP      /* For Insight builds only, see the detail below */
-#define BTA_DM_NUM_PM_SPEC      (9 + 2)  /* additional two */
+#define BTA_DM_NUM_PM_SPEC      (11 + 2)  /* additional two */
 #else
-#define BTA_DM_NUM_PM_SPEC      9  /* additional JV*/
+#define BTA_DM_NUM_PM_SPEC      11  /* additional JV*/
 #endif
 #endif
 
@@ -328,6 +330,44 @@
       {{BTA_DM_PM_ACTIVE,    0},   {BTA_DM_PM_NO_ACTION, 0}},   /* busy */
       {{BTA_DM_PM_NO_ACTION, 0},   {BTA_DM_PM_NO_ACTION, 0}}    /* mode change retry */
   }
+ },
+
+  /* PANU */
+ {
+  (BTA_DM_PM_SNIFF),                                             /* allow sniff */
+#if (BTM_SSR_INCLUDED == TRUE)
+  (BTA_DM_PM_SSR2),                                              /* the SSR entry */
+#endif
+  {
+      {{BTA_DM_PM_ACTIVE,    0},   {BTA_DM_PM_NO_ACTION, 0}},    /* conn open  active */
+      {{BTA_DM_PM_NO_PREF,   0},   {BTA_DM_PM_NO_ACTION, 0}},    /* conn close  */
+      {{BTA_DM_PM_ACTIVE,    0},   {BTA_DM_PM_NO_ACTION, 0}},    /* app open */
+      {{BTA_DM_PM_NO_ACTION, 0},   {BTA_DM_PM_NO_ACTION, 0}},    /* app close */
+      {{BTA_DM_PM_NO_ACTION, 0},   {BTA_DM_PM_NO_ACTION, 0}},    /* sco open  */
+      {{BTA_DM_PM_NO_ACTION, 0},   {BTA_DM_PM_NO_ACTION, 0}},    /* sco close   */
+      {{BTA_DM_PM_SNIFF,  7000},   {BTA_DM_PM_NO_ACTION, 0}},    /* idle */
+      {{BTA_DM_PM_ACTIVE,    0},   {BTA_DM_PM_NO_ACTION, 0}},    /* busy */
+      {{BTA_DM_PM_NO_ACTION, 0},   {BTA_DM_PM_NO_ACTION, 0}}     /* mode change retry */
+  }
+ },
+
+  /* NAP */
+ {
+  (BTA_DM_PM_SNIFF),                                             /* allow sniff */
+#if (BTM_SSR_INCLUDED == TRUE)
+  (BTA_DM_PM_SSR2),                                              /* the SSR entry */
+#endif
+  {
+      {{BTA_DM_PM_ACTIVE,    0},   {BTA_DM_PM_NO_ACTION, 0}},    /* conn open  active */
+      {{BTA_DM_PM_NO_PREF,   0},   {BTA_DM_PM_NO_ACTION, 0}},    /* conn close  */
+      {{BTA_DM_PM_ACTIVE,    0},   {BTA_DM_PM_NO_ACTION, 0}},    /* app open */
+      {{BTA_DM_PM_NO_ACTION, 0},   {BTA_DM_PM_NO_ACTION, 0}},    /* app close */
+      {{BTA_DM_PM_NO_ACTION, 0},   {BTA_DM_PM_NO_ACTION, 0}},    /* sco open  */
+      {{BTA_DM_PM_NO_ACTION, 0},   {BTA_DM_PM_NO_ACTION, 0}},    /* sco close   */
+      {{BTA_DM_PM_SNIFF,  5000},   {BTA_DM_PM_NO_ACTION, 0}},    /* idle */
+      {{BTA_DM_PM_ACTIVE,    0},   {BTA_DM_PM_NO_ACTION, 0}},    /* busy */
+      {{BTA_DM_PM_NO_ACTION, 0},   {BTA_DM_PM_NO_ACTION, 0}}     /* mode change retry */
+  }
  }
 
 #if BLE_INCLUDED == TRUE
diff --git a/bta/jv/bta_jv_act.c b/bta/jv/bta_jv_act.c
index dd09ca7..65c20aa 100644
--- a/bta/jv/bta_jv_act.c
+++ b/bta/jv/bta_jv_act.c
@@ -285,8 +285,8 @@
         return BTA_JV_FAILURE;
     }
     APPL_TRACE_DEBUG6("bta_jv_free_sr_rfc_cb: max_sess:%d, curr_sess:%d, p_pcb:%p, user:"
-            "%d, state:%d, jv handle: 0x%x" ,p_cb->max_sess, p_cb->curr_sess, p_pcb,
-            (int)p_pcb->user_data, p_pcb->state, p_pcb->handle);
+            "%p, state:%d, jv handle: 0x%x" ,p_cb->max_sess, p_cb->curr_sess, p_pcb,
+            p_pcb->user_data, p_pcb->state, p_pcb->handle);
 
     if (p_cb->curr_sess <= 0)
         return BTA_JV_SUCCESS;
@@ -296,32 +296,32 @@
     case BTA_JV_ST_CL_CLOSING:
     case BTA_JV_ST_SR_CLOSING:
         APPL_TRACE_WARNING4("bta_jv_free_sr_rfc_cb: return on closing, port state:%d, "
-                "scn:%d, p_pcb:%p, user_data:%d", p_pcb->state, p_cb->scn, p_pcb,
-                (int)p_pcb->user_data);
+                "scn:%d, p_pcb:%p, user_data:%p", p_pcb->state, p_cb->scn, p_pcb,
+                p_pcb->user_data);
         status = BTA_JV_FAILURE;
         return status;
     case BTA_JV_ST_CL_OPEN:
     case BTA_JV_ST_CL_OPENING:
         APPL_TRACE_DEBUG3("bta_jv_free_sr_rfc_cb: state: %d, scn:%d,"
-                          " user_data:%d", p_pcb->state, p_cb->scn, (int)p_pcb->user_data);
+                          " user_data:%p", p_pcb->state, p_cb->scn, p_pcb->user_data);
         p_pcb->state = BTA_JV_ST_CL_CLOSING;
         break;
     case BTA_JV_ST_SR_LISTEN:
         p_pcb->state = BTA_JV_ST_SR_CLOSING;
         remove_server = TRUE;
         APPL_TRACE_DEBUG2("bta_jv_free_sr_rfc_cb: state: BTA_JV_ST_SR_LISTEN, scn:%d,"
-                " user_data:%d", p_cb->scn, (int)p_pcb->user_data);
+                " user_data:%p", p_cb->scn, p_pcb->user_data);
         break;
     case BTA_JV_ST_SR_OPEN:
         p_pcb->state = BTA_JV_ST_SR_CLOSING;
         APPL_TRACE_DEBUG2("bta_jv_free_sr_rfc_cb: state: BTA_JV_ST_SR_OPEN, scn:%d,"
-                " user_data:%d", p_cb->scn, (int)p_pcb->user_data);
+                " user_data:%p", p_cb->scn, p_pcb->user_data);
         break;
     default:
         APPL_TRACE_WARNING6("bta_jv_free_sr_rfc_cb():failed, ignore port state:%d, scn:"
-                "%d, p_pcb:%p, jv handle: 0x%x, port_handle: %d, user_data:%d",
+                "%d, p_pcb:%p, jv handle: 0x%x, port_handle: %d, user_data:%p",
                 p_pcb->state, p_cb->scn, p_pcb, p_pcb->handle, p_pcb->port_handle,
-                (int)p_pcb->user_data);
+                p_pcb->user_data);
         status = BTA_JV_FAILURE;
         break;
     }
@@ -449,7 +449,7 @@
 {
     tBTA_JV_STATUS status = BTA_JV_FAILURE;
     tBTA_JV_PM_CB  **p_cb;
-    int i;
+    int i, j, bd_counter = 0, appid_counter = 0;
 
     for (i = 0; i < BTA_JV_PM_MAX_NUM; i++)
     {
@@ -457,10 +457,31 @@
         if ((bta_jv_cb.pm_cb[i].state != BTA_JV_PM_FREE_ST) &&
                 (jv_handle == bta_jv_cb.pm_cb[i].handle))
         {
+            for (j = 0; j < BTA_JV_PM_MAX_NUM; j++)
+            {
+                if (bdcmp(bta_jv_cb.pm_cb[j].peer_bd_addr, bta_jv_cb.pm_cb[i].peer_bd_addr) == 0)
+                    bd_counter++;
+                if (bta_jv_cb.pm_cb[j].app_id == bta_jv_cb.pm_cb[i].app_id)
+                    appid_counter++;
+            }
+
             APPL_TRACE_API3("bta_jv_free_set_pm_profile_cb(jv_handle: 0x%2x), idx: %d, "
                     "app_id: 0x%x", jv_handle, i, bta_jv_cb.pm_cb[i].app_id);
+            APPL_TRACE_API2("bta_jv_free_set_pm_profile_cb, bd_counter = %d, "
+                    "appid_counter = %d", bd_counter, appid_counter);
+            if (bd_counter > 1)
+            {
+                bta_jv_pm_conn_idle(&bta_jv_cb.pm_cb[i]);
+            }
 
-            bta_jv_clear_pm_cb(&bta_jv_cb.pm_cb[i], TRUE);
+            if (bd_counter <= 1 || (appid_counter <= 1))
+            {
+                bta_jv_clear_pm_cb(&bta_jv_cb.pm_cb[i], TRUE);
+            }
+            else
+            {
+                bta_jv_clear_pm_cb(&bta_jv_cb.pm_cb[i], FALSE);
+            }
 
             if (BTA_JV_RFCOMM_MASK & jv_handle)
             {
diff --git a/bta/pan/bta_pan_act.c b/bta/pan/bta_pan_act.c
index d0939d6..fbb4147 100644
--- a/bta/pan/bta_pan_act.c
+++ b/bta/pan/bta_pan_act.c
@@ -43,6 +43,40 @@
 #define BTA_PAN_TX_MASK              0xF0
 
 /*******************************************************************************
+ **
+ ** Function    bta_pan_pm_conn_busy
+ **
+ ** Description set pan pm connection busy state
+ **
+ ** Params      p_scb: state machine control block of pan connection
+ **
+ ** Returns     void
+ **
+ *******************************************************************************/
+static void bta_pan_pm_conn_busy(tBTA_PAN_SCB *p_scb)
+{
+    if ((p_scb != NULL) && (p_scb->state != BTA_PAN_IDLE_ST))
+        bta_sys_busy(BTA_ID_PAN, p_scb->app_id, p_scb->bd_addr);
+}
+
+/*******************************************************************************
+ **
+ ** Function    bta_pan_pm_conn_idle
+ **
+ ** Description set pan pm connection idle state
+ **
+ ** Params      p_scb: state machine control block of pan connection
+ **
+ ** Returns     void
+ **
+ *******************************************************************************/
+static void bta_pan_pm_conn_idle(tBTA_PAN_SCB *p_scb)
+{
+    if ((p_scb != NULL) && (p_scb->state != BTA_PAN_IDLE_ST))
+        bta_sys_idle(BTA_ID_PAN, p_scb->app_id, p_scb->bd_addr);
+}
+
+/*******************************************************************************
 **
 ** Function         bta_pan_conn_state_cback
 **
@@ -627,12 +661,14 @@
     /* if data path configured for tx pull */
     if ((bta_pan_cb.flow_mask & BTA_PAN_TX_MASK) == BTA_PAN_TX_PULL)
     {
+        bta_pan_pm_conn_busy(p_scb);
         /* call application callout function for tx path */
         bta_pan_co_tx_path(p_scb->handle, p_scb->app_id);
 
         /* free data that exceeds queue level */
         while(p_scb->data_queue.count > bta_pan_cb.q_level)
             GKI_freebuf(GKI_dequeue(&p_scb->data_queue));
+        bta_pan_pm_conn_idle(p_scb);
     }
     /* if configured for zero copy push */
     else if ((bta_pan_cb.flow_mask & BTA_PAN_TX_MASK) == BTA_PAN_TX_PUSH_BUF)
@@ -704,6 +740,7 @@
 {
     if ((bta_pan_cb.flow_mask & BTA_PAN_RX_MASK) == BTA_PAN_RX_PUSH_BUF)
     {
+        bta_pan_pm_conn_busy(p_scb);
 
         PAN_WriteBuf (p_scb->handle,
                       ((tBTA_PAN_DATA_PARAMS *)p_data)->dst,
@@ -711,6 +748,7 @@
                       ((tBTA_PAN_DATA_PARAMS *)p_data)->protocol,
                       (BT_HDR *)p_data,
                       ((tBTA_PAN_DATA_PARAMS *)p_data)->ext);
+        bta_pan_pm_conn_idle(p_scb);
 
     }
 }
diff --git a/bta/pan/bta_pan_int.h b/bta/pan/bta_pan_int.h
index 1667e57..bd75311 100644
--- a/bta/pan/bta_pan_int.h
+++ b/bta/pan/bta_pan_int.h
@@ -56,6 +56,14 @@
     BTA_PAN_API_OPEN_EVT
 };
 
+/* state machine states */
+enum
+{
+    BTA_PAN_IDLE_ST,
+    BTA_PAN_OPEN_ST,
+    BTA_PAN_CLOSING_ST
+};
+
 
 
 
diff --git a/bta/pan/bta_pan_main.c b/bta/pan/bta_pan_main.c
index 5ed545f..7d42bfe 100644
--- a/bta/pan/bta_pan_main.c
+++ b/bta/pan/bta_pan_main.c
@@ -84,14 +84,6 @@
 #define BTA_PAN_NUM_COLS             2       /* number of columns in state tables */
 
 
-/* state machine states */
-enum
-{
-    BTA_PAN_IDLE_ST,
-    BTA_PAN_OPEN_ST,
-    BTA_PAN_CLOSING_ST
-};
-
 
 /* state table for listen state */
 const UINT8 bta_pan_st_idle[][BTA_PAN_NUM_COLS] =
diff --git a/btif/src/btif_gatt_util.c b/btif/src/btif_gatt_util.c
index 715dcd6..8a977d0 100644
--- a/btif/src/btif_gatt_util.c
+++ b/btif/src/btif_gatt_util.c
@@ -43,7 +43,7 @@
 #define GATTC_READ_VALUE_TYPE_VALUE          0x0000  /* Attribute value itself */
 #define GATTC_READ_VALUE_TYPE_AGG_FORMAT     0x2905  /* Characteristic Aggregate Format*/
 
-static char BASE_UUID[16] = {
+static unsigned char BASE_UUID[16] = {
     0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80,
     0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 };
diff --git a/btif/src/btif_pan.c b/btif/src/btif_pan.c
index 28c5156..f340f6f 100644
--- a/btif/src/btif_pan.c
+++ b/btif/src/btif_pan.c
@@ -197,7 +197,7 @@
 }
 static volatile int btpan_dev_local_role;
 static tBTA_PAN_ROLE_INFO bta_panu_info = {PANU_SERVICE_NAME, 0, PAN_SECURITY};
-static tBTA_PAN_ROLE_INFO bta_pan_nap_info = {PAN_NAP_SERVICE_NAME, 0, PAN_SECURITY};
+static tBTA_PAN_ROLE_INFO bta_pan_nap_info = {PAN_NAP_SERVICE_NAME, 1, PAN_SECURITY};
 
 static bt_status_t btpan_enable(int local_role)
 {
@@ -308,6 +308,16 @@
     /*         ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1], ifr.ifr_hwaddr.sa_data[2], */
     /*         ifr.ifr_hwaddr.sa_data[3], ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]); */
 
+    /* The IEEE has specified that the most significant bit of the most significant byte is used to
+     * determine a multicast address. If its a 1, that means multicast, 0 means unicast.
+     * Kernel returns an error if we try to set a multicast address for the tun-tap ethernet interface.
+     * Mask this bit to avoid any issue with auto generated address.
+     */
+    if (ifr.ifr_hwaddr.sa_data[0] & 0x01) {
+        BTIF_TRACE_WARNING0("Not a unicast MAC address, force multicast bit flipping");
+        ifr.ifr_hwaddr.sa_data[0] &= ~0x01;
+    }
+
     err = ioctl(sk, SIOCSIFHWADDR, (caddr_t)&ifr);
 
     if (err < 0) {
diff --git a/btif/src/btif_sock_rfc.c b/btif/src/btif_sock_rfc.c
index abb2a97..d2daa29 100644
--- a/btif/src/btif_sock_rfc.c
+++ b/btif/src/btif_sock_rfc.c
@@ -283,26 +283,35 @@
                                         int open_handle, int new_listen_handle)
 {
     rfc_slot_t *accept_rs = alloc_rfc_slot(addr, srv_rs->service_name, srv_rs->service_uuid, srv_rs->scn, 0, FALSE);
-    clear_slot_flag(&accept_rs->f);
-    accept_rs->f.server = FALSE;
-    accept_rs->f.connected = TRUE;
-    accept_rs->security = srv_rs->security;
-    accept_rs->mtu = srv_rs->mtu;
-    accept_rs->role = srv_rs->role;
-    accept_rs->rfc_handle = open_handle;
-    accept_rs->rfc_port_handle = BTA_JvRfcommGetPortHdl(open_handle);
-     //now update listen rfc_handle of server slot
-    srv_rs->rfc_handle = new_listen_handle;
-    srv_rs->rfc_port_handle = BTA_JvRfcommGetPortHdl(new_listen_handle);
-    BTIF_TRACE_DEBUG4("create_srv_accept__rfc_slot(open_handle: 0x%x, new_listen_handle:"
-            "0x%x) accept_rs->rfc_handle:0x%x, srv_rs_listen->rfc_handle:0x%x"
-      ,open_handle, new_listen_handle, accept_rs->rfc_port_handle, srv_rs->rfc_port_handle);
-    asrt(accept_rs->rfc_port_handle != srv_rs->rfc_port_handle);
-  //now swap the slot id
-    uint32_t new_listen_id = accept_rs->id;
-    accept_rs->id = srv_rs->id;
-    srv_rs->id = new_listen_id;
-    return accept_rs;
+    if( accept_rs)
+    {
+        clear_slot_flag(&accept_rs->f);
+        accept_rs->f.server = FALSE;
+        accept_rs->f.connected = TRUE;
+        accept_rs->security = srv_rs->security;
+        accept_rs->mtu = srv_rs->mtu;
+        accept_rs->role = srv_rs->role;
+        accept_rs->rfc_handle = open_handle;
+        accept_rs->rfc_port_handle = BTA_JvRfcommGetPortHdl(open_handle);
+        //now update listen rfc_handle of server slot
+        srv_rs->rfc_handle = new_listen_handle;
+        srv_rs->rfc_port_handle = BTA_JvRfcommGetPortHdl(new_listen_handle);
+        BTIF_TRACE_DEBUG4("create_srv_accept__rfc_slot(open_handle: 0x%x, new_listen_handle:"
+                "0x%x) accept_rs->rfc_handle:0x%x, srv_rs_listen->rfc_handle:0x%x"
+                ,open_handle, new_listen_handle, accept_rs->rfc_port_handle, srv_rs->rfc_port_handle);
+        asrt(accept_rs->rfc_port_handle != srv_rs->rfc_port_handle);
+        //now swap the slot id
+        uint32_t new_listen_id = accept_rs->id;
+        accept_rs->id = srv_rs->id;
+        srv_rs->id = new_listen_id;
+
+        return accept_rs;
+    }
+    else
+    {
+        APPL_TRACE_ERROR1(" accept_rs is NULL %s", __FUNCTION__);
+        return NULL;
+    }
 }
 bt_status_t btsock_rfc_listen(const char* service_name, const uint8_t* service_uuid, int channel,
                             int* sock_fd, int flags)
@@ -334,7 +343,7 @@
     if(rs)
     {
         APPL_TRACE_DEBUG1("BTA_JvCreateRecordByUser:%s", service_name);
-        BTA_JvCreateRecordByUser((void *)rs->id);
+        BTA_JvCreateRecordByUser((void *)(intptr_t)rs->id);
         *sock_fd = rs->app_fd;
         rs->app_fd = -1; //the fd ownership is transferred to app
         status = BT_STATUS_SUCCESS;
@@ -364,7 +373,7 @@
         {
             APPL_TRACE_DEBUG1("connecting to rfcomm channel:%d without service discovery", channel);
             if(BTA_JvRfcommConnect(rs->security, rs->role, rs->scn, rs->addr.address,
-                        rfcomm_cback, (void*)rs->id) == BTA_JV_SUCCESS)
+                        rfcomm_cback, (void*)(intptr_t)rs->id) == BTA_JV_SUCCESS)
             {
                 if(send_app_scn(rs))
                 {
@@ -390,7 +399,7 @@
             rfc_slot_t* rs_doing_sdp = find_rfc_slot_requesting_sdp();
             if(rs_doing_sdp == NULL)
             {
-                BTA_JvStartDiscovery((UINT8*)bd_addr->address, 1, &sdp_uuid, (void*)rs->id);
+                BTA_JvStartDiscovery((UINT8*)bd_addr->address, 1, &sdp_uuid, (void*)(intptr_t)rs->id);
                 rs->f.pending_sdp_request = FALSE;
                 rs->f.doing_sdp_request = TRUE;
             }
@@ -473,7 +482,7 @@
     {
         if(rs->f.server && !rs->f.closing && rs->rfc_handle)
         {
-            BTA_JvRfcommStopServer(rs->rfc_handle, (void*)rs->id);
+            BTA_JvRfcommStopServer(rs->rfc_handle, (void*)(uintptr_t)rs->id);
             rs->rfc_handle = 0;
         }
         if(rs->f.server)
@@ -503,7 +512,7 @@
     if(rs->rfc_handle && !rs->f.closing && !rs->f.server)
     {
         APPL_TRACE_DEBUG1("closing rfcomm connection, rfc_handle:0x%x", rs->rfc_handle);
-        BTA_JvRfcommClose(rs->rfc_handle, (void*)rs->id);
+        BTA_JvRfcommClose(rs->rfc_handle, (void*)(uintptr_t)rs->id);
         rs->rfc_handle = 0;
     }
     free_rfc_slot_scn(rs);
@@ -688,25 +697,25 @@
     switch (event)
     {
     case BTA_JV_RFCOMM_START_EVT:
-        on_srv_rfc_listen_started(&p_data->rfc_start, (uint32_t)user_data);
+        on_srv_rfc_listen_started(&p_data->rfc_start, (uintptr_t)user_data);
         break;
 
     case BTA_JV_RFCOMM_CL_INIT_EVT:
-        on_cl_rfc_init(&p_data->rfc_cl_init, (uint32_t)user_data);
+        on_cl_rfc_init(&p_data->rfc_cl_init, (uintptr_t)user_data);
         break;
 
     case BTA_JV_RFCOMM_OPEN_EVT:
         BTA_JvSetPmProfile(p_data->rfc_open.handle,BTA_JV_PM_ID_1,BTA_JV_CONN_OPEN);
-        on_cli_rfc_connect(&p_data->rfc_open, (uint32_t)user_data);
+        on_cli_rfc_connect(&p_data->rfc_open, (uintptr_t)user_data);
         break;
     case BTA_JV_RFCOMM_SRV_OPEN_EVT:
         BTA_JvSetPmProfile(p_data->rfc_srv_open.handle,BTA_JV_PM_ALL,BTA_JV_CONN_OPEN);
-        new_user_data = (void*)on_srv_rfc_connect(&p_data->rfc_srv_open, (uint32_t)user_data);
+        new_user_data = (void*)(intptr_t)on_srv_rfc_connect(&p_data->rfc_srv_open, (uintptr_t)user_data);
         break;
 
     case BTA_JV_RFCOMM_CLOSE_EVT:
-        APPL_TRACE_DEBUG1("BTA_JV_RFCOMM_CLOSE_EVT: user_data:%d", (uint32_t)user_data);
-        on_rfc_close(&p_data->rfc_close, (uint32_t)user_data);
+        APPL_TRACE_DEBUG1("BTA_JV_RFCOMM_CLOSE_EVT: user_data:%d", (uintptr_t)user_data);
+        on_rfc_close(&p_data->rfc_close, (uintptr_t)user_data);
         break;
 
     case BTA_JV_RFCOMM_READ_EVT:
@@ -714,7 +723,7 @@
         break;
 
     case BTA_JV_RFCOMM_WRITE_EVT:
-        on_rfc_write_done(&p_data->rfc_write, (uint32_t)user_data);
+        on_rfc_write_done(&p_data->rfc_write, (uintptr_t)user_data);
         break;
 
     case BTA_JV_RFCOMM_DATA_IND_EVT:
@@ -723,10 +732,10 @@
 
     case BTA_JV_RFCOMM_CONG_EVT:
         //on_rfc_cong(&p_data->rfc_cong);
-        on_rfc_outgoing_congest(&p_data->rfc_cong, (uint32_t)user_data);
+        on_rfc_outgoing_congest(&p_data->rfc_cong, (uintptr_t)user_data);
         break;
     default:
-        APPL_TRACE_ERROR2("unhandled event %d, slot id:%d", event, (uint32_t)user_data);
+        APPL_TRACE_ERROR2("unhandled event %d, slot id:%d", event, (uintptr_t)user_data);
         break;
     }
     return new_user_data;
@@ -734,7 +743,7 @@
 
 static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV *p_data, void *user_data)
 {
-    uint32_t id = (uint32_t)user_data;
+    uint32_t id = (uintptr_t)user_data;
     APPL_TRACE_DEBUG2("jv_dm_cback: event:%d, slot id:%d", event, id);
     switch(event)
     {
@@ -746,7 +755,7 @@
                 {
                     //now start the rfcomm server after sdp & channel # assigned
                     BTA_JvRfcommStartServer(rs->security, rs->role, rs->scn, MAX_RFC_SESSION, rfcomm_cback,
-                                            (void*)rs->id);
+                                            (void*)(uintptr_t)rs->id);
                 }
                 else if(rs)
                 {
@@ -769,7 +778,7 @@
                     if(rs && rs->f.doing_sdp_request)
                     {
                         if(BTA_JvRfcommConnect(rs->security, rs->role, p_data->disc_comp.scn, rs->addr.address,
-                                    rfcomm_cback, (void*)rs->id) == BTA_JV_SUCCESS)
+                                    rfcomm_cback, (void*)(uintptr_t)rs->id) == BTA_JV_SUCCESS)
                         {
                             rs->scn = p_data->disc_comp.scn;
                             rs->f.doing_sdp_request = FALSE;
@@ -801,7 +810,7 @@
                     tSDP_UUID sdp_uuid;
                     sdp_uuid.len = 16;
                     memcpy(sdp_uuid.uu.uuid128, rs->service_uuid, sizeof(sdp_uuid.uu.uuid128));
-                    BTA_JvStartDiscovery((UINT8*)rs->addr.address, 1, &sdp_uuid, (void*)rs->id);
+                    BTA_JvStartDiscovery((UINT8*)rs->addr.address, 1, &sdp_uuid, (void*)(uintptr_t)rs->id);
                     rs->f.pending_sdp_request = FALSE;
                     rs->f.doing_sdp_request = TRUE;
                 }
@@ -936,7 +945,7 @@
 
 int bta_co_rfc_data_incoming(void *user_data, BT_HDR *p_buf)
 {
-    uint32_t id = (uint32_t)user_data;
+    uint32_t id = (uintptr_t)user_data;
     int ret = 0;
     lock_slot(&slot_lock);
     rfc_slot_t* rs = find_rfc_slot_by_id(id, "bta_co_rfc_data_incoming");
@@ -972,7 +981,7 @@
 }
 int bta_co_rfc_data_outgoing_size(void *user_data, int *size)
 {
-    uint32_t id = (uint32_t)user_data;
+    uint32_t id = (uintptr_t)user_data;
     int ret = FALSE;
     *size = 0;
     lock_slot(&slot_lock);
@@ -996,7 +1005,7 @@
 }
 int bta_co_rfc_data_outgoing(void *user_data, UINT8* buf, UINT16 size)
 {
-    uint32_t id = (uint32_t)user_data;
+    uint32_t id = (uintptr_t)user_data;
     int ret = FALSE;
     lock_slot(&slot_lock);
     rfc_slot_t* rs = find_rfc_slot_by_id(id, "bta_co_rfc_data_outgoing");
diff --git a/btif/src/btif_sock_thread.c b/btif/src/btif_sock_thread.c
index 475b8de..18c961f 100644
--- a/btif/src/btif_sock_thread.c
+++ b/btif/src/btif_sock_thread.c
@@ -232,7 +232,7 @@
     if(h >= 0)
     {
         init_poll(h);
-        if((ts[h].thread_id = create_thread(sock_poll_thread, (void*)h)) != -1)
+        if((ts[h].thread_id = create_thread(sock_poll_thread, (void*)(uintptr_t)h)) != -1)
         {
             APPL_TRACE_DEBUG2("h:%d, thread id:%d", h, ts[h].thread_id);
             ts[h].callback = callback;
@@ -556,7 +556,7 @@
 {
     struct pollfd pfds[MAX_POLL];
     memset(pfds, 0, sizeof(pfds));
-    int h = (int)arg;
+    int h = (intptr_t)arg;
     for(;;)
     {
         prepare_poll_fds(h, pfds);
diff --git a/btif/src/btif_storage.c b/btif/src/btif_storage.c
index 8f41ce5..a12c5cc 100644
--- a/btif/src/btif_storage.c
+++ b/btif/src/btif_storage.c
@@ -783,7 +783,8 @@
     int ret = btif_config_set_int("Remote", bdstr, "LinkKeyType", (int)key_type);
     ret &= btif_config_set_int("Remote", bdstr, "PinLength", (int)pin_length);
     ret &= btif_config_set("Remote", bdstr, "LinkKey", (const char*)link_key, sizeof(LINK_KEY), BTIF_CFG_TYPE_BIN);
-    btif_config_save();
+    /* write bonded info immediately */
+    btif_config_flush();
     return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
 }
 
@@ -805,7 +806,8 @@
     int ret = btif_config_remove("Remote", bdstr, "LinkKeyType");
     ret &= btif_config_remove("Remote", bdstr, "PinLength");
     ret &= btif_config_remove("Remote", bdstr, "LinkKey");
-    btif_config_save();
+    /* write bonded info immediately */
+    btif_config_flush();
     return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
 
 }
diff --git a/gki/Android.mk b/gki/Android.mk
index ed9f904..e9ad13a 100644
--- a/gki/Android.mk
+++ b/gki/Android.mk
@@ -1,5 +1,3 @@
-ifneq ($(TARGET_SIMULATOR),true)
-
 LOCAL_PATH:= $(call my-dir)
 
 include $(CLEAR_VARS)
@@ -31,5 +29,3 @@
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
 
 include $(BUILD_STATIC_LIBRARY)
-
-endif  # TARGET_SIMULATOR != true
diff --git a/hci/Android.mk b/hci/Android.mk
index 24fec19..0d3d56d 100644
--- a/hci/Android.mk
+++ b/hci/Android.mk
@@ -11,6 +11,8 @@
         src/btsnoop.c \
         src/utils.c
 
+LOCAL_CFLAGS := -Wno-unused-parameter
+
 ifeq ($(BLUETOOTH_HCI_USE_MCT),true)
 
 LOCAL_CFLAGS += -DHCI_USE_MCT
diff --git a/hci/include/bt_hci_bdroid.h b/hci/include/bt_hci_bdroid.h
index 904c698..ac2f162 100644
--- a/hci/include/bt_hci_bdroid.h
+++ b/hci/include/bt_hci_bdroid.h
@@ -66,9 +66,8 @@
 #endif
 #endif  // (BTHC_LINUX_BASE_POLICY != SCHED_NORMAL)
 
-#ifndef BTHC_USERIAL_READ_MEM_SIZE
-#define BTHC_USERIAL_READ_MEM_SIZE (1024)
-#endif
+#define HCI_ACL_MAX_SIZE 1024
+#define HCI_MAX_FRAME_SIZE (HCI_ACL_MAX_SIZE + 4)
 
 #ifndef BTSNOOPDISP_INCLUDED
 #define BTSNOOPDISP_INCLUDED TRUE
diff --git a/hci/src/userial.c b/hci/src/userial.c
index 5dc4f84..bdd0be1 100644
--- a/hci/src/userial.c
+++ b/hci/src/userial.c
@@ -58,7 +58,6 @@
 #endif
 
 #define MAX_SERIAL_PORT (USERIAL_PORT_3 + 1)
-#define READ_LIMIT (BTHC_USERIAL_READ_MEM_SIZE - BT_HC_HDR_SIZE)
 
 enum {
     USERIAL_RX_EXIT,
@@ -255,8 +254,8 @@
     {
         if (bt_hc_cbacks)
         {
-            p_buf = (HC_BT_HDR *) bt_hc_cbacks->alloc( \
-                                                BTHC_USERIAL_READ_MEM_SIZE);
+            p_buf = (HC_BT_HDR *) bt_hc_cbacks->alloc(
+                        BT_HC_HDR_SIZE + HCI_MAX_FRAME_SIZE + 1); /* H4 HDR = 1 */
         }
         else
             p_buf = NULL;
@@ -267,7 +266,7 @@
             p_buf->layer_specific = 0;
 
             p = (uint8_t *) (p_buf + 1);
-            rx_length = select_read(userial_cb.fd, p, READ_LIMIT);
+            rx_length = select_read(userial_cb.fd, p, HCI_MAX_FRAME_SIZE + 1);
         }
         else
         {
diff --git a/stack/Android.mk b/stack/Android.mk
index 92ce253..f00daff 100755
--- a/stack/Android.mk
+++ b/stack/Android.mk
@@ -1,5 +1,3 @@
-ifneq ($(TARGET_SIMULATOR),true)
-
 LOCAL_PATH:= $(call my-dir)
 
 include $(CLEAR_VARS)
@@ -153,5 +151,3 @@
 LOCAL_SHARED_LIBRARIES := libcutils libc
 
 include $(BUILD_STATIC_LIBRARY)
-
-endif  # TARGET_SIMULATOR != true
diff --git a/stack/btm/btm_sec.c b/stack/btm/btm_sec.c
index 09f41b7..eb5714a 100644
--- a/stack/btm/btm_sec.c
+++ b/stack/btm/btm_sec.c
@@ -4785,6 +4785,10 @@
     tBTM_SEC_DEV_REC *p_dev_rec;
     tBTM_CB          *p_cb = &btm_cb;
 
+#ifdef PORCHE_PAIRING_CONFLICT
+    UINT8 default_pin_code_len = 4;
+    PIN_CODE default_pin_code = {0x30, 0x30, 0x30, 0x30};
+#endif
     BTM_TRACE_EVENT3 ("btm_sec_pin_code_request()  State: %s, BDA:%04x%08x",
                       btm_pair_state_descr(btm_cb.pairing_state),
                       (p_bda[0]<<8)+p_bda[1], (p_bda[2]<<24)+(p_bda[3]<<16)+(p_bda[4]<<8)+p_bda[5] );
@@ -4818,7 +4822,8 @@
             BTM_TRACE_EVENT0 ("btm_sec_pin_code_request from remote dev. for local initiated pairing");
             if(! btm_cb.pin_code_len_saved)
             {
-                btsnd_hcic_pin_code_neg_reply (p_bda);
+                btm_sec_change_pairing_state (BTM_PAIR_STATE_WAIT_AUTH_COMPLETE);
+                btsnd_hcic_pin_code_req_reply (p_bda, default_pin_code_len, default_pin_code);
             }
             else
             {
diff --git a/stack/btu/btu_hcif.c b/stack/btu/btu_hcif.c
index 0081850..cef5096 100644
--- a/stack/btu/btu_hcif.c
+++ b/stack/btu/btu_hcif.c
@@ -37,6 +37,9 @@
 #include "btm_api.h"
 #include "btm_int.h"
 
+extern void btm_process_cancel_complete(UINT8 status, UINT8 mode);
+extern void btm_ble_test_command_complete(UINT8 *p);
+
 // btla-specific ++
 #define LOG_TAG "BTLD"
 #if (defined(ANDROID_APP_INCLUDED) && (ANDROID_APP_INCLUDED == TRUE) && (!defined(LINUX_NATIVE)) )
diff --git a/stack/hcic/hcicmds.c b/stack/hcic/hcicmds.c
index 778ebfb..09e98fe 100644
--- a/stack/hcic/hcicmds.c
+++ b/stack/hcic/hcicmds.c
@@ -1371,6 +1371,7 @@
         return (FALSE);
 
     pp = (UINT8 *)(p + 1);
+    memset(pp, 0, HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CHANGE_NAME);
 
     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CHANGE_NAME;
     p->offset = 0;
diff --git a/stack/hid/hidh_conn.c b/stack/hid/hidh_conn.c
index 86b41d3..b1b778e 100644
--- a/stack/hid/hidh_conn.c
+++ b/stack/hid/hidh_conn.c
@@ -502,6 +502,8 @@
      && (p_hcon->conn_state == HID_CONN_STATE_CONFIG))
     {
         p_hcon->conn_state = HID_CONN_STATE_CONNECTED;
+        /* Reset disconnect reason to success, as connection successful */
+        p_hcon->disc_reason = HID_SUCCESS;
 
         hh_cb.devices[dhandle].state = HID_DEV_CONNECTED;
         hh_cb.callback( dhandle,  hh_cb.devices[dhandle].addr, HID_HDEV_EVT_OPEN, 0, NULL ) ;
@@ -556,6 +558,8 @@
      && (p_hcon->conn_state == HID_CONN_STATE_CONFIG))
     {
         p_hcon->conn_state = HID_CONN_STATE_CONNECTED;
+        /* Reset disconnect reason to success, as connection successful */
+        p_hcon->disc_reason = HID_SUCCESS;
 
         hh_cb.devices[dhandle].state = HID_DEV_CONNECTED;
         hh_cb.callback( dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_OPEN, 0, NULL ) ;
diff --git a/test/Android.mk b/test/Android.mk
index 3c3cb61..5053e7d 100644
--- a/test/Android.mk
+++ b/test/Android.mk
@@ -1,3 +1 @@
-ifneq ($(TARGET_SIMULATOR),true)
-  include $(call all-subdir-makefiles)
-endif
+include $(call all-subdir-makefiles)
diff --git a/test/bluedroidtest/Android.mk b/test/bluedroidtest/Android.mk
index 0c6693a..6bf8da5 100644
--- a/test/bluedroidtest/Android.mk
+++ b/test/bluedroidtest/Android.mk
@@ -22,18 +22,15 @@
     bluedroidtest.c
 
 LOCAL_C_INCLUDES :=
+LOCAL_CFLAGS := -Wno-unused-parameter
 
 LOCAL_MODULE_TAGS := eng
 
 LOCAL_MODULE:= bdt
 
-LOCAL_LDLIBS += -lpthread -ldl -llog -lreadline
-LIBS_c += -lreadline
-
 LOCAL_SHARED_LIBRARIES += libcutils   \
                           libutils    \
                           libhardware \
                           libhardware_legacy
 
 include $(BUILD_EXECUTABLE)
-
diff --git a/test/bluedroidtest/bluedroidtest.c b/test/bluedroidtest/bluedroidtest.c
index 2b517df..1e39b98 100644
--- a/test/bluedroidtest/bluedroidtest.c
+++ b/test/bluedroidtest/bluedroidtest.c
@@ -199,7 +199,7 @@
         if (n%16 == 1) {
             /* store address for this line */
             snprintf(addrstr, sizeof(addrstr), "%.4x",
-               ((unsigned int)p-(unsigned int)data) );
+               (unsigned int)((uintptr_t)p-(uintptr_t)data) );
         }
 
         c = *p;
diff --git a/udrv/ulinux/uipc.c b/udrv/ulinux/uipc.c
index 795f615..186e58c 100644
--- a/udrv/ulinux/uipc.c
+++ b/udrv/ulinux/uipc.c
@@ -215,7 +215,7 @@
     struct sockaddr_un remote;
     struct pollfd pfd;
     int fd;
-    int len = sizeof(struct sockaddr_un);
+    socklen_t len = sizeof(struct sockaddr_un);
 
     BTIF_TRACE_EVENT1("accept fd %d", sfd);
 
@@ -891,7 +891,7 @@
             break;
 
         case UIPC_SET_READ_POLL_TMO:
-            uipc_main.ch[ch_id].read_poll_tmo_ms = (int)param;
+            uipc_main.ch[ch_id].read_poll_tmo_ms = (intptr_t)param;
             BTIF_TRACE_EVENT2("UIPC_SET_READ_POLL_TMO : CH %d, TMO %d ms", ch_id, uipc_main.ch[ch_id].read_poll_tmo_ms );
             break;