am 67020954: am a4611ac0: DO NOT MERGE: cherrypick from master to fix b/13289050

* commit '670209545cbf585165029d8866972ade111785c5':
  DO NOT MERGE: cherrypick from master to fix b/13289050
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..2fee588 100644
--- a/audio_a2dp_hw/audio_a2dp_hw.c
+++ b/audio_a2dp_hw/audio_a2dp_hw.c
@@ -195,7 +195,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);
 
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/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/jv/bta_jv_act.c b/bta/jv/bta_jv_act.c
index 77f636b..ab51071 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/btif/src/btif_sock_rfc.c b/btif/src/btif_sock_rfc.c
index d70e499..24bc546 100644
--- a/btif/src/btif_sock_rfc.c
+++ b/btif/src/btif_sock_rfc.c
@@ -334,7 +334,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 +364,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 +390,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 +473,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 +503,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 +688,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 +714,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 +723,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 +734,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 +746,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 +769,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 +801,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 +936,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);
@@ -972,7 +972,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 +996,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);
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 2b1b07e..b87c787 100644
--- a/hci/Android.mk
+++ b/hci/Android.mk
@@ -9,9 +9,11 @@
         src/btsnoop.c \
         src/utils.c
 
+LOCAL_CFLAGS := -Wno-unused-parameter
+
 ifeq ($(BLUETOOTH_HCI_USE_MCT),true)
 
-LOCAL_CFLAGS := -DHCI_USE_MCT
+LOCAL_CFLAGS += -DHCI_USE_MCT
 
 LOCAL_SRC_FILES += \
         src/hci_mct.c \
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/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 21222bd..a530d2a 100644
--- a/stack/hcic/hcicmds.c
+++ b/stack/hcic/hcicmds.c
@@ -1364,6 +1364,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/pan/pan_api.c b/stack/pan/pan_api.c
index f9742ed..e6275ea 100644
--- a/stack/pan/pan_api.c
+++ b/stack/pan/pan_api.c
@@ -466,7 +466,7 @@
     }
 
     result = BNEP_Disconnect (pcb->handle);
-    if (pcb->con_state == PAN_STATE_CONNECTED)
+    if (pcb->con_state != PAN_STATE_IDLE)
         pan_cb.num_conns--;
 
     if (pan_cb.pan_bridge_req_cb && pcb->src_uuid == UUID_SERVCLASS_NAP)
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..579edfe 100644
--- a/test/bluedroidtest/Android.mk
+++ b/test/bluedroidtest/Android.mk
@@ -22,6 +22,7 @@
     bluedroidtest.c
 
 LOCAL_C_INCLUDES :=
+LOCAL_CFLAGS := -Wno-unused-parameter
 
 LOCAL_MODULE_TAGS := eng
 
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;