am 65aec3a3: am 6d429d9d: (-s ours) am 3efb9e2e: DO NOT MERGE Change pairing_cb to assume temporary pairing by default

* commit '65aec3a3f62c004d7073470f18330007b7ecf230':
  DO NOT MERGE Change pairing_cb to assume temporary pairing by default
diff --git a/Android.mk b/Android.mk
index b5fe1d8..5f2d274 100644
--- a/Android.mk
+++ b/Android.mk
@@ -13,4 +13,4 @@
 
 # Cleanup our locals
 bdroid_C_INCLUDES :=
-bdroid_CFLaGS :=
+bdroid_CFLAGS :=
diff --git a/audio_a2dp_hw/Android.mk b/audio_a2dp_hw/Android.mk
index b5ca08a..f9fd0a1 100644
--- a/audio_a2dp_hw/Android.mk
+++ b/audio_a2dp_hw/Android.mk
@@ -5,7 +5,7 @@
 LOCAL_SRC_FILES:= \
 	audio_a2dp_hw.c
 
-LOCAL_C_INCLUDES+= .
+LOCAL_C_INCLUDES+= . $(LOCAL_PATH)/../utils/include
 
 LOCAL_SHARED_LIBRARIES := \
 	libcutils liblog
@@ -14,7 +14,7 @@
 	libpower
 
 LOCAL_MODULE := audio.a2dp.default
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
 
 LOCAL_MODULE_TAGS := optional
 
diff --git a/audio_a2dp_hw/audio_a2dp_hw.c b/audio_a2dp_hw/audio_a2dp_hw.c
index 42e416e..cde56c1 100644
--- a/audio_a2dp_hw/audio_a2dp_hw.c
+++ b/audio_a2dp_hw/audio_a2dp_hw.c
@@ -43,6 +43,7 @@
 
 #include <hardware/hardware.h>
 #include "audio_a2dp_hw.h"
+#include "bt_utils.h"
 
 #define LOG_TAG "audio_a2dp_hw"
 /* #define LOG_NDEBUG 0 */
@@ -150,6 +151,8 @@
     static struct timespec prev = {0,0};
     unsigned long long now_us;
     unsigned long long diff_us;
+    UNUSED(tag);
+    UNUSED(val);
 
     clock_gettime(CLOCK_MONOTONIC, &now);
 
@@ -543,6 +546,7 @@
 
 static int out_set_format(struct audio_stream *stream, audio_format_t format)
 {
+    UNUSED(format);
     struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
     DEBUG("setting format not yet supported (0x%x)", format);
     return -ENOSYS;
@@ -551,8 +555,6 @@
 static int out_standby(struct audio_stream *stream)
 {
     struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
-    int retval = 0;
-
     int retVal = 0;
 
     FNLOG();
@@ -570,6 +572,7 @@
 
 static int out_dump(const struct audio_stream *stream, int fd)
 {
+    UNUSED(fd);
     struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
     FNLOG();
     return 0;
@@ -631,6 +634,7 @@
 
 static char * out_get_parameters(const struct audio_stream *stream, const char *keys)
 {
+    UNUSED(keys);
     struct a2dp_stream_out *out = (struct a2dp_stream_out *)stream;
 
     FNLOG();
@@ -659,6 +663,10 @@
 static int out_set_volume(struct audio_stream_out *stream, float left,
                           float right)
 {
+    UNUSED(stream);
+    UNUSED(left);
+    UNUSED(right);
+
     FNLOG();
 
     /* volume controlled in audioflinger mixer (digital) */
@@ -671,18 +679,27 @@
 static int out_get_render_position(const struct audio_stream_out *stream,
                                    uint32_t *dsp_frames)
 {
+    UNUSED(stream);
+    UNUSED(dsp_frames);
+
     FNLOG();
     return -EINVAL;
 }
 
 static int out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
 {
+    UNUSED(stream);
+    UNUSED(effect);
+
     FNLOG();
     return 0;
 }
 
 static int out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
 {
+    UNUSED(stream);
+    UNUSED(effect);
+
     FNLOG();
     return 0;
 }
@@ -693,54 +710,76 @@
 
 static uint32_t in_get_sample_rate(const struct audio_stream *stream)
 {
+    UNUSED(stream);
+
     FNLOG();
     return 8000;
 }
 
 static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
 {
+    UNUSED(stream);
+    UNUSED(rate);
+
     FNLOG();
     return 0;
 }
 
 static size_t in_get_buffer_size(const struct audio_stream *stream)
 {
+    UNUSED(stream);
+
     FNLOG();
     return 320;
 }
 
 static uint32_t in_get_channels(const struct audio_stream *stream)
 {
+    UNUSED(stream);
+
     FNLOG();
     return AUDIO_CHANNEL_IN_MONO;
 }
 
 static audio_format_t in_get_format(const struct audio_stream *stream)
 {
+    UNUSED(stream);
+
     FNLOG();
     return AUDIO_FORMAT_PCM_16_BIT;
 }
 
 static int in_set_format(struct audio_stream *stream, audio_format_t format)
 {
+    UNUSED(stream);
+    UNUSED(format);
+
     FNLOG();
     return 0;
 }
 
 static int in_standby(struct audio_stream *stream)
 {
+    UNUSED(stream);
+
     FNLOG();
     return 0;
 }
 
 static int in_dump(const struct audio_stream *stream, int fd)
 {
+    UNUSED(stream);
+    UNUSED(fd);
+
     FNLOG();
     return 0;
 }
 
 static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
 {
+    UNUSED(stream);
+    UNUSED(kvpairs);
+
     FNLOG();
     return 0;
 }
@@ -748,12 +787,18 @@
 static char * in_get_parameters(const struct audio_stream *stream,
                                 const char *keys)
 {
+    UNUSED(stream);
+    UNUSED(keys);
+
     FNLOG();
     return strdup("");
 }
 
 static int in_set_gain(struct audio_stream_in *stream, float gain)
 {
+    UNUSED(stream);
+    UNUSED(gain);
+
     FNLOG();
     return 0;
 }
@@ -761,24 +806,36 @@
 static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
                        size_t bytes)
 {
+    UNUSED(stream);
+    UNUSED(buffer);
+    UNUSED(bytes);
+
     FNLOG();
     return bytes;
 }
 
 static uint32_t in_get_input_frames_lost(struct audio_stream_in *stream)
 {
+    UNUSED(stream);
+
     FNLOG();
     return 0;
 }
 
 static int in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
 {
+    UNUSED(stream);
+    UNUSED(effect);
+
     FNLOG();
     return 0;
 }
 
 static int in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
 {
+    UNUSED(stream);
+    UNUSED(effect);
+
     FNLOG();
 
     return 0;
@@ -796,6 +853,9 @@
     struct a2dp_stream_out *out;
     int ret = 0;
     int i;
+    UNUSED(handle);
+    UNUSED(devices);
+    UNUSED(flags);
 
     INFO("opening output");
 
@@ -908,6 +968,7 @@
                                   const char *keys)
 {
     struct str_parms *parms;
+    UNUSED(dev);
 
     FNLOG();
 
@@ -931,6 +992,9 @@
 
 static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
 {
+    UNUSED(dev);
+    UNUSED(volume);
+
     FNLOG();
 
     return -ENOSYS;
@@ -938,6 +1002,9 @@
 
 static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
 {
+    UNUSED(dev);
+    UNUSED(volume);
+
     FNLOG();
 
     return -ENOSYS;
@@ -945,6 +1012,9 @@
 
 static int adev_set_mode(struct audio_hw_device *dev, int mode)
 {
+    UNUSED(dev);
+    UNUSED(mode);
+
     FNLOG();
 
     return 0;
@@ -952,6 +1022,9 @@
 
 static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
 {
+    UNUSED(dev);
+    UNUSED(state);
+
     FNLOG();
 
     return -ENOSYS;
@@ -959,6 +1032,9 @@
 
 static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state)
 {
+    UNUSED(dev);
+    UNUSED(state);
+
     FNLOG();
 
     return -ENOSYS;
@@ -967,6 +1043,9 @@
 static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
                                          const struct audio_config *config)
 {
+    UNUSED(dev);
+    UNUSED(config);
+
     FNLOG();
 
     return 320;
@@ -981,6 +1060,9 @@
     struct a2dp_audio_device *ladev = (struct a2dp_audio_device *)dev;
     struct a2dp_stream_in *in;
     int ret;
+    UNUSED(handle);
+    UNUSED(devices);
+    UNUSED(config);
 
     FNLOG();
 
@@ -1017,6 +1099,9 @@
 static void adev_close_input_stream(struct audio_hw_device *dev,
                                    struct audio_stream_in *in)
 {
+    UNUSED(dev);
+    UNUSED(in);
+
     FNLOG();
 
     return;
@@ -1024,6 +1109,9 @@
 
 static int adev_dump(const audio_hw_device_t *device, int fd)
 {
+    UNUSED(device);
+    UNUSED(fd);
+
     FNLOG();
 
     return 0;
diff --git a/bta/Android.mk b/bta/Android.mk
index f4b8a7e..bca6c08 100644
--- a/bta/Android.mk
+++ b/bta/Android.mk
@@ -98,6 +98,7 @@
                    $(LOCAL_PATH)/../hcis/patchram \
                    $(LOCAL_PATH)/../udrv/include \
                    $(LOCAL_PATH)/../brcm/include \
+                   $(LOCAL_PATH)/../utils/include \
                    $(bdroid_C_INCLUDES) \
 
 
diff --git a/bta/ag/bta_ag_act.c b/bta/ag/bta_ag_act.c
index 5f72444..11fc85c 100644
--- a/bta/ag/bta_ag_act.c
+++ b/bta/ag/bta_ag_act.c
@@ -334,6 +334,8 @@
 *******************************************************************************/
 void bta_ag_disc_fail(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data)
 {
+    UNUSED(p_data);
+
     /* reopen registered servers */
     bta_ag_start_servers(p_scb, p_scb->reg_services);
 
@@ -371,6 +373,8 @@
 *******************************************************************************/
 void bta_ag_rfc_fail(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data)
 {
+    UNUSED(p_data);
+
     /* reinitialize stuff */
     p_scb->conn_handle = 0;
     p_scb->conn_service = 0;
@@ -405,6 +409,7 @@
     tBTA_AG_HDR    close;
     tBTA_SERVICE_MASK services;
     int i, num_active_conn = 0;
+    UNUSED(p_data);
 
 #ifdef  _WIN32_WCE
     /* The BTE RFCOMM automatically removes the connection when closed, but BTW does not */
@@ -637,6 +642,7 @@
 {
     UINT16  len;
     char    buf[BTA_AG_RFC_READ_MAX];
+    UNUSED(p_data);
 
     memset(buf, 0, BTA_AG_RFC_READ_MAX);
 
@@ -796,6 +802,7 @@
 void bta_ag_svc_conn_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data)
 {
     tBTA_AG_CONN evt;
+    UNUSED(p_data);
 
     if (!p_scb->svc_conn)
     {
@@ -856,6 +863,8 @@
 *******************************************************************************/
 void bta_ag_rcvd_slc_ready(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data)
 {
+    UNUSED(p_data);
+
     APPL_TRACE_DEBUG1("bta_ag_rcvd_slc_ready: handle = %d", bta_ag_scb_to_idx(p_scb));
 
     if (bta_ag_cb.parse_mode == BTA_AG_PASS_THROUGH)
diff --git a/bta/ag/bta_ag_cmd.c b/bta/ag/bta_ag_cmd.c
index c035cf3..54cd4d3 100644
--- a/bta/ag/bta_ag_cmd.c
+++ b/bta/ag/bta_ag_cmd.c
@@ -631,6 +631,7 @@
 {
     UINT8   retval = 0;
     INT16   idx = -1;
+    UNUSED(p_scb);
 
     if (p_s[1] != 0)
     {
@@ -1747,6 +1748,9 @@
     {
         APPL_TRACE_ERROR1("bta_ag_setcodec error: unsupported codec type %d", codec_type);
     }
+#else
+    UNUSED(p_scb);
+    UNUSED(p_data);
 #endif
 }
 
@@ -1801,6 +1805,8 @@
 *******************************************************************************/
 void bta_ag_send_ring(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data)
 {
+    UNUSED(p_data);
+
 #if defined(BTA_AG_MULTI_RESULT_INCLUDED) && (BTA_AG_MULTI_RESULT_INCLUDED == TRUE)
     tBTA_AG_MULTI_RESULT_CB m_res_cb;
 
diff --git a/bta/ag/bta_ag_main.c b/bta/ag/bta_ag_main.c
index 9b28067..bae992b 100644
--- a/bta/ag/bta_ag_main.c
+++ b/bta/ag/bta_ag_main.c
@@ -28,6 +28,7 @@
 #include "bta_ag_co.h"
 #include "bta_ag_int.h"
 #include "bd.h"
+#include "utl.h"
 
 /*****************************************************************************
 ** Constants and types
@@ -586,6 +587,8 @@
 {
     UINT16  handle;
     tBTA_AG_SCB *p_scb;
+    UNUSED(status);
+    UNUSED(app_id);
 
     /* Check if we have opening scb for the peer device. */
     handle = bta_ag_idx_by_bdaddr (peer_addr);
diff --git a/bta/ag/bta_ag_rfc.c b/bta/ag/bta_ag_rfc.c
index 3575020..d6b5329 100644
--- a/bta/ag/bta_ag_rfc.c
+++ b/bta/ag/bta_ag_rfc.c
@@ -34,6 +34,7 @@
 #include "rfcdefs.h"
 #include "gki.h"
 #include "bd.h"
+#include "utl.h"
 
 /* Event mask for RfCOMM port callback */
 #define BTA_AG_PORT_EV_MASK         PORT_EV_RXCHAR
@@ -89,6 +90,7 @@
 {
     BT_HDR      *p_buf;
     tBTA_AG_SCB *p_scb;
+    UNUSED(code);
 
     if ((p_scb = bta_ag_scb_by_idx(handle)) != NULL)
     {
@@ -195,6 +197,8 @@
 *******************************************************************************/
 static int bta_ag_data_cback(UINT16 port_handle, void *p_data, UINT16 len, UINT16 handle)
 {
+    UNUSED(port_handle);
+
     /* call data call-out directly */
     bta_ag_co_tx_write(handle, (UINT8 *) p_data, len);
     return 0;
@@ -400,6 +404,7 @@
 void bta_ag_rfc_do_close(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data)
 {
     tBTA_AG_RFC     *p_buf;
+    UNUSED(p_data);
 
     if (p_scb->conn_handle)
     {
diff --git a/bta/ag/bta_ag_sco.c b/bta/ag/bta_ag_sco.c
index 0c811b4..87d9188 100644
--- a/bta/ag/bta_ag_sco.c
+++ b/bta/ag/bta_ag_sco.c
@@ -31,6 +31,7 @@
 #include "bta_ag_int.h"
 #include "btm_api.h"
 #include "gki.h"
+#include "utl.h"
 
 #ifndef BTA_AG_SCO_DEBUG
 #define BTA_AG_SCO_DEBUG FALSE
@@ -1277,6 +1278,7 @@
 *******************************************************************************/
 void bta_ag_sco_listen(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data)
 {
+    UNUSED(p_data);
     bta_ag_sco_event(p_scb, BTA_AG_SCO_LISTEN_E);
 }
 
@@ -1293,6 +1295,7 @@
 void bta_ag_sco_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data)
 {
     UINT8 event;
+    UNUSED(p_data);
 
     /* if another scb using sco, this is a transfer */
     if (bta_ag_cb.sco.p_curr_scb != NULL && bta_ag_cb.sco.p_curr_scb != p_scb)
@@ -1320,6 +1323,8 @@
 *******************************************************************************/
 void bta_ag_sco_close(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data)
 {
+    UNUSED(p_data);
+
     /* if scb is in use */
 #if (BTM_WBS_INCLUDED == TRUE )
     /* sco_idx is not allocated in SCO_CODEC_ST, we still need to move to listening state. */
@@ -1371,6 +1376,8 @@
 *******************************************************************************/
 void bta_ag_sco_shutdown(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data)
 {
+    UNUSED(p_data);
+
     bta_ag_sco_event(p_scb, BTA_AG_SCO_SHUTDOWN_E);
 }
 
@@ -1386,6 +1393,8 @@
 *******************************************************************************/
 void bta_ag_sco_conn_open(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data)
 {
+    UNUSED(p_data);
+
     bta_ag_sco_event(p_scb, BTA_AG_SCO_CONN_OPEN_E);
 
     bta_sys_sco_open(BTA_ID_AG, p_scb->app_id, p_scb->peer_addr);
@@ -1416,6 +1425,7 @@
 void bta_ag_sco_conn_close(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data)
 {
     UINT16 handle = bta_ag_scb_to_idx(p_scb);
+    UNUSED(p_data);
 
     /* clear current scb */
     bta_ag_cb.sco.p_curr_scb = NULL;
@@ -1560,6 +1570,9 @@
 *******************************************************************************/
 void bta_ag_ci_sco_data(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data)
 {
+    UNUSED(p_scb);
+    UNUSED(p_data);
+
 #if (BTM_SCO_HCI_INCLUDED == TRUE )
     bta_ag_sco_event(p_scb, BTA_AG_SCO_CI_DATA_E);
 #endif
diff --git a/bta/ag/bta_ag_sdp.c b/bta/ag/bta_ag_sdp.c
index d708cf2..333cb1b 100644
--- a/bta/ag/bta_ag_sdp.c
+++ b/bta/ag/bta_ag_sdp.c
@@ -31,6 +31,7 @@
 #include "sdp_api.h"
 #include "btm_api.h"
 #include "gki.h"
+#include "utl.h"
 
 /* Number of protocol elements in protocol element list. */
 #define BTA_AG_NUM_PROTO_ELEMS      2
@@ -256,6 +257,7 @@
     tBTA_SERVICE_MASK   services;
     tBTA_SERVICE_MASK   others = 0;
     int                 i;
+    UNUSED(p_data);
 
     /* get services of all other registered servers */
     for (i = 0; i < BTA_AG_NUM_IDX; i++, p++)
@@ -492,6 +494,8 @@
 *******************************************************************************/
 void bta_ag_free_db(tBTA_AG_SCB *p_scb, tBTA_AG_DATA *p_data)
 {
+    UNUSED(p_data);
+
     if (p_scb->p_disc_db != NULL)
     {
         GKI_freebuf(p_scb->p_disc_db);
diff --git a/bta/av/bta_av_aact.c b/bta/av/bta_av_aact.c
index a50fb80..fed838a 100644
--- a/bta/av/bta_av_aact.c
+++ b/bta/av/bta_av_aact.c
@@ -288,6 +288,7 @@
 *******************************************************************************/
 void bta_av_st_rc_timer(tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
 {
+    UNUSED(p_data);
 
     APPL_TRACE_DEBUG2("bta_av_st_rc_timer rc_handle:%d, use_rc: %d",
         p_scb->rc_handle, p_scb->use_rc);
@@ -681,6 +682,7 @@
 {
     tBTA_AV_RS_RES      switch_res = BTA_AV_RS_NONE;
     tBTA_AV_API_OPEN  *p_buf = &p_scb->q_info.open;
+    UNUSED(p_data);
 
     APPL_TRACE_DEBUG1("bta_av_switch_role wait:x%x", p_scb->wait);
     if (p_scb->wait & BTA_AV_WAIT_ROLE_SW_RES_START)
@@ -947,6 +949,7 @@
     tBTA_AV_CONN_CHG msg;
     int             xx;
     UINT8           role = BTA_AV_ROLE_AD_INT;
+    UNUSED(p_data);
 
     APPL_TRACE_DEBUG0("bta_av_cleanup");
 
@@ -999,6 +1002,7 @@
 *******************************************************************************/
 void bta_av_free_sdb(tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
 {
+    UNUSED(p_data);
     utl_freebuf((void **) &p_scb->p_disc_db);
 }
 
@@ -1017,6 +1021,7 @@
     tAVDT_SEP_INFO       *p_info;
     tAVDT_CFG            *p_evt_cfg = &p_data->str_msg.cfg;
     UINT8   psc_mask = (p_evt_cfg->psc_mask | p_scb->cfg.psc_mask);
+    UNUSED(p_data);
 
     p_scb->avdt_label = p_data->str_msg.msg.hdr.label;
     memcpy(p_scb->cfg.codec_info, p_evt_cfg->codec_info, AVDT_CODEC_SIZE);
@@ -1076,6 +1081,8 @@
 void bta_av_disconnect_req (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
 {
     tBTA_AV_RCB *p_rcb;
+    UNUSED(p_data);
+
     APPL_TRACE_DEBUG1("bta_av_disconnect_req conn_lcb: 0x%x", bta_av_cb.conn_lcb);
 
     bta_sys_stop_timer(&bta_av_cb.sig_tmr);
@@ -1346,6 +1353,8 @@
 *******************************************************************************/
 void bta_av_do_close (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
 {
+    UNUSED(p_data);
+
     /* stop stream if started */
     if (p_scb->co_started)
     {
@@ -1381,6 +1390,8 @@
 *******************************************************************************/
 void bta_av_connect_req (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
 {
+    UNUSED(p_data);
+
     utl_freebuf((void **) &p_scb->p_disc_db);
 
     if (p_scb->coll_mask & BTA_AV_COLL_INC_TMR)
@@ -1570,6 +1581,8 @@
 *******************************************************************************/
 void bta_av_set_use_rc (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
 {
+    UNUSED(p_data);
+
     p_scb->use_rc = TRUE;
 }
 
@@ -1585,6 +1598,8 @@
 void bta_av_cco_close (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
 {
     UINT16 mtu;
+    UNUSED(p_data);
+
     mtu = bta_av_chk_mtu(p_scb, BTA_AV_MAX_A2DP_MTU);
 
     p_scb->p_cos->close(p_scb->hndl, p_scb->codec_type, mtu);
@@ -1742,6 +1757,8 @@
 *******************************************************************************/
 void bta_av_discover_req (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
 {
+    UNUSED(p_data);
+
     /* send avdtp discover request */
 
     AVDT_DiscoverReq(p_scb->peer_addr, p_scb->sep_info, BTA_AV_NUM_SEPS, bta_av_dt_cback[p_scb->hdi]);
@@ -1997,6 +2014,7 @@
     BOOLEAN new_buf = FALSE;
     UINT8   m_pt = 0x60 | p_scb->codec_type;
     tAVDT_DATA_OPT_MASK     opt;
+    UNUSED(p_data);
 
     if (!p_scb->cong)
     {
@@ -2260,6 +2278,8 @@
 *******************************************************************************/
 void bta_av_start_failed (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
 {
+    UNUSED(p_data);
+
     if(p_scb->started == FALSE && p_scb->co_started == FALSE)
     {
         bta_sys_idle(BTA_ID_AV, bta_av_cb.audio_open_cnt, p_scb->peer_addr);
@@ -2344,6 +2364,8 @@
 *******************************************************************************/
 void bta_av_clr_cong (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
 {
+    UNUSED(p_data);
+
     if(p_scb->co_started)
         p_scb->cong = FALSE;
 }
@@ -2440,6 +2462,7 @@
 void bta_av_rcfg_str_ok (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
 {
     tBTA_AV_RECONFIG    evt;
+    UNUSED(p_data);
 
     p_scb->l2c_cid      = AVDT_GetL2CapChannel(p_scb->avdt_handle);
     APPL_TRACE_DEBUG1("bta_av_rcfg_str_ok: l2c_cid: %d", p_scb->l2c_cid);
@@ -2514,6 +2537,8 @@
 *******************************************************************************/
 void bta_av_rcfg_connect (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
 {
+    UNUSED(p_data);
+
     p_scb->cong    = FALSE;
     p_scb->num_recfg++;
     APPL_TRACE_DEBUG1("bta_av_rcfg_connect num_recfg: %d", p_scb->num_recfg);
@@ -2538,6 +2563,7 @@
 void bta_av_rcfg_discntd (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
 {
     tBTA_AV_RECONFIG    evt;
+    UNUSED(p_data);
 
     APPL_TRACE_DEBUG1("bta_av_rcfg_discntd num_recfg: %d", p_scb->num_recfg);
     p_scb->num_recfg++;
@@ -2655,6 +2681,8 @@
 *******************************************************************************/
 void bta_av_rcfg_open (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
 {
+    UNUSED(p_data);
+
     APPL_TRACE_DEBUG1("bta_av_rcfg_open, num_disc_snks = %d", p_scb->num_disc_snks);
 
     if (p_scb->num_disc_snks == 0)
@@ -2692,6 +2720,8 @@
 *******************************************************************************/
 void bta_av_security_rej (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)
 {
+    UNUSED(p_data);
+
     AVDT_SecurityRsp(p_scb->avdt_handle, p_scb->avdt_label, AVDT_ERR_BAD_STATE,
                      NULL, 0);
 }
@@ -2711,7 +2741,7 @@
     tBTA_AV_SCB *p_scbi;
     int i;
     BOOLEAN new_started = FALSE;
-
+    UNUSED(p_data);
 
     if ((p_scb->chnl == BTA_AV_CHNL_AUDIO) && (bta_av_cb.audio_open_cnt >= 2))
     {
diff --git a/bta/av/bta_av_act.c b/bta/av/bta_av_act.c
index ada7592..4408874 100755
--- a/bta/av/bta_av_act.c
+++ b/bta/av/bta_av_act.c
@@ -181,6 +181,7 @@
 static void bta_av_avrc_sdp_cback(UINT16 status)
 {
     BT_HDR *p_msg;
+    UNUSED(status);
 
     if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
     {
@@ -202,6 +203,7 @@
 {
     tBTA_AV_RC_CONN_CHG *p_msg;
     UINT16 msg_event = 0;
+    UNUSED(result);
 
 #if (defined(BTA_AV_MIN_DEBUG_TRACES) && BTA_AV_MIN_DEBUG_TRACES == TRUE)
     APPL_TRACE_EVENT2("rc_ctrl handle: %d event=0x%x", handle, event);
@@ -688,6 +690,8 @@
 *******************************************************************************/
 void bta_av_rc_free_rsp (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
 {
+    UNUSED(p_cb);
+
     GKI_freebuf (p_data->api_meta_rsp.p_pkt);
 }
 
@@ -702,6 +706,8 @@
 *******************************************************************************/
 void bta_av_rc_free_msg (tBTA_AV_CB *p_cb, tBTA_AV_DATA *p_data)
 {
+    UNUSED(p_cb);
+    UNUSED(p_data);
 }
 
 
@@ -1362,6 +1368,7 @@
 {
     BT_HDR  hdr;
     UINT16  xx;
+    UNUSED(p_data);
 
     p_cb->disabling = TRUE;
 
@@ -1519,6 +1526,7 @@
     UINT8   mask;
     tBTA_AV_LCB *p_lcb = NULL;
     tBTA_AV_PEND pend;
+    UNUSED(p_data);
 
     APPL_TRACE_DEBUG0("bta_av_sig_timer");
     for(xx=0; xx<BTA_AV_NUM_LINKS; xx++)
@@ -1689,6 +1697,7 @@
     tBTA_AV_RC_FEAT rc_feat;
     UINT8               rc_handle;
     tBTA_AV_FEAT        peer_features;  /* peer features mask */
+    UNUSED(p_data);
 
     APPL_TRACE_DEBUG1("bta_av_rc_disc_done disc:x%x", p_cb->disc);
     if (!p_cb->disc)
diff --git a/bta/av/bta_av_cfg.c b/bta/av/bta_av_cfg.c
index c31f7a9..9eb8bd6 100755
--- a/bta/av/bta_av_cfg.c
+++ b/bta/av/bta_av_cfg.c
@@ -110,6 +110,10 @@
     BTA_AV_RC_PASS_RSP_CODE,/* the default response code for pass through commands */
     bta_av_meta_caps_co_ids,/* the metadata Get Capabilities response for company id */
     bta_av_meta_caps_evt_ids,/* the the metadata Get Capabilities response for event id */
+    NULL,                   /* the action function table for VDP stream */
+    NULL,                   /* action function to register VDP */
+    {0},                    /* Default AVRCP controller name */
+    {0},                    /* Default AVRCP target name */
 };
 
 tBTA_AV_CFG *p_bta_av_cfg = (tBTA_AV_CFG *) &bta_av_cfg;
diff --git a/bta/av/bta_av_main.c b/bta/av/bta_av_main.c
index 749756d..25c40a5 100644
--- a/bta/av/bta_av_main.c
+++ b/bta/av/bta_av_main.c
@@ -392,6 +392,7 @@
     tBTA_AV_STR_MSG     *p_msg;
     UINT16  evt = 0;
     tBTA_AV_SCB *p_scb = NULL;
+    UNUSED(handle);
 
 #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
     if (event == BTA_AR_AVDT_CONN_EVT ||
@@ -450,6 +451,9 @@
 static void bta_av_a2dp_report_cback(UINT8 handle, AVDT_REPORT_TYPE type,
                                     tAVDT_REPORT_DATA *p_data)
 {
+    UNUSED(handle);
+    UNUSED(type);
+    UNUSED(p_data);
     /* Do not need to handle report data for now.
      * This empty function is here for conformance reasons. */
 }
@@ -715,9 +719,9 @@
 **
 *******************************************************************************/
 #if (AVDT_REPORTING == TRUE)
-
 static void bta_av_rpc_conn(tBTA_AV_DATA *p_data)
 {
+    UNUSED(p_data);
 }
 #endif
 
@@ -832,6 +836,7 @@
     tBTA_AV_ROLE_RES  *p_buf;
     UINT8       cur_role;
     UINT8       peer_idx = 0;
+    UNUSED(status);
 
     APPL_TRACE_DEBUG1("bta_av_sys_rs_cback: %d", bta_av_cb.rs_idx);
     for(i=0; i<BTA_AV_NUM_STRS; i++)
@@ -907,6 +912,8 @@
     tBTA_AV_SCB *p_scb;
     int     i;
     tBTA_AV_API_STOP stop;
+    UNUSED(app_id);
+    UNUSED(peer_addr);
 
     APPL_TRACE_DEBUG2("bta_av_sco_chg_cback:%d status:%d", id, status);
     if(id)
@@ -1049,6 +1056,7 @@
     tBTA_AV_SCB *p_scbi;
     int i;
     UINT8   mask;
+    UNUSED(mtu);
 
     /* TODO_MV mess with the mtu according to the number of EDR/non-EDR headsets */
     if(p_scb->chnl == BTA_AV_CHNL_AUDIO)
diff --git a/bta/av/bta_av_sbc.c b/bta/av/bta_av_sbc.c
index 1517270..a570375 100644
--- a/bta/av/bta_av_sbc.c
+++ b/bta/av/bta_av_sbc.c
@@ -26,6 +26,7 @@
 #include "a2d_api.h"
 #include "a2d_sbc.h"
 #include "bta_av_sbc.h"
+#include "utl.h"
 
 typedef int (tBTA_AV_SBC_ACT)(void *p_src, void *p_dst,
                                UINT32 src_samples, UINT32 dst_samples,
@@ -425,6 +426,7 @@
 {
     UINT8           status = A2D_SUCCESS;
     tA2D_SBC_CIE    peer_cie;
+    UNUSED(p_cap);
 
     /* parse peer capabilities */
     if ((status = A2D_ParsSbcInfo(&peer_cie, p_peer, TRUE)) != 0)
diff --git a/bta/dm/bta_dm_act.c b/bta/dm/bta_dm_act.c
index 36d7082..ee1ba03 100755
--- a/bta/dm/bta_dm_act.c
+++ b/bta/dm/bta_dm_act.c
@@ -23,6 +23,7 @@
  *
  ******************************************************************************/
 
+#include "bt_target.h"
 #include "bt_types.h"
 #include "gki.h"
 #include "bd.h"
@@ -39,6 +40,10 @@
 #include "utl.h"
 #include <string.h>
 
+#if (GAP_INCLUDED == TRUE)
+#include "gap_api.h"
+#endif
+
 static void bta_dm_inq_results_cb (tBTM_INQ_RESULTS *p_inq, UINT8 *p_eir);
 static void bta_dm_inq_cmpl_cb (void * p_result);
 static void bta_dm_service_search_remname_cback (BD_ADDR bd_addr, DEV_CLASS dc, BD_NAME bd_name);
@@ -246,6 +251,7 @@
 #if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&(BTA_EIR_CANNED_UUID_LIST != TRUE)
 static void bta_dm_app_ready_timer_cback (TIMER_LIST_ENT *p_tle)
 {
+    UNUSED(p_tle);
     bta_dm_set_eir (NULL);
 }
 #else
@@ -380,8 +386,10 @@
         {
             BTM_BleLoadLocalKeys(BTA_BLE_LOCAL_KEY_TYPE_ID, (tBTM_BLE_LOCAL_KEYS *)&id_key);
         }
+#if ((defined BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE))
         bta_dm_search_cb.conn_id = BTA_GATT_INVALID_CONN_ID;
 #endif
+#endif
 
         BTM_SecRegister((tBTM_APPL_INFO*)&bta_security);
         BTM_SetDefaultLinkSuperTout(bta_dm_cfg.link_timeout);
@@ -453,6 +461,8 @@
 *******************************************************************************/
 void bta_dm_disable (tBTA_DM_MSG *p_data)
 {
+    UNUSED(p_data);
+
     /* Set l2cap idle timeout to 0 (so BTE immediately disconnects ACL link after last channel is closed) */
     L2CA_SetIdleTimeoutByBdAddr((UINT8 *)BT_BD_ANY, 0);
 
@@ -504,7 +514,7 @@
 *******************************************************************************/
 static void bta_dm_disable_timer_cback (TIMER_LIST_ENT *p_tle)
 {
-
+    UNUSED(p_tle);
     UINT8 i;
 
     APPL_TRACE_EVENT0(" bta_dm_disable_timer_cback  ");
@@ -839,14 +849,14 @@
     if (bta_dm_cb.p_sec_cback && (status != BTM_CMD_STARTED))
     {
 
-        p_name = BTM_SecReadDevName(p_data->bond.bd_addr);
-        if (!p_name)
-            p_name = "";
-
         memset(&sec_event, 0, sizeof(tBTA_DM_SEC));
         bdcpy(sec_event.auth_cmpl.bd_addr, p_data->bond.bd_addr);
-        memcpy(sec_event.auth_cmpl.bd_name, p_name, (BD_NAME_LEN-1));
-        sec_event.auth_cmpl.bd_name[BD_NAME_LEN-1] = 0;
+        p_name = BTM_SecReadDevName(p_data->bond.bd_addr);
+        if (p_name != NULL)
+        {
+            memcpy(sec_event.auth_cmpl.bd_name, p_name, (BD_NAME_LEN-1));
+            sec_event.auth_cmpl.bd_name[BD_NAME_LEN-1] = 0;
+        }
 
 /*      taken care of by memset [above]
         sec_event.auth_cmpl.key_present = FALSE;
@@ -1133,6 +1143,7 @@
 #if (BTM_OOB_INCLUDED == TRUE)
 void bta_dm_loc_oob(tBTA_DM_MSG *p_data)
 {
+    UNUSED(p_data);
     BTM_ReadLocalOobData();
 }
 
@@ -1250,7 +1261,7 @@
 *******************************************************************************/
 void bta_dm_search_cancel (tBTA_DM_MSG *p_data)
 {
-
+    UNUSED(p_data);
     tBTA_DM_MSG * p_msg;
 
     if(BTM_IsInquiryActive())
@@ -2007,6 +2018,7 @@
 *******************************************************************************/
 static void bta_dm_search_timer_cback (TIMER_LIST_ENT *p_tle)
 {
+    UNUSED(p_tle);
 
     APPL_TRACE_EVENT0(" bta_dm_search_timer_cback  ");
     bta_dm_search_cb.wait_disc = FALSE;
@@ -2028,6 +2040,7 @@
 *******************************************************************************/
 void bta_dm_free_sdp_db (tBTA_DM_MSG *p_data)
 {
+    UNUSED(p_data);
     if(bta_dm_search_cb.p_sdp_db)
     {
         GKI_freebuf(bta_dm_search_cb.p_sdp_db);
@@ -2089,7 +2102,7 @@
 *******************************************************************************/
 void bta_dm_search_clear_queue (tBTA_DM_MSG *p_data)
 {
-
+    UNUSED(p_data);
     if(bta_dm_search_cb.p_search_queue)
     {
         GKI_freebuf(bta_dm_search_cb.p_search_queue);
@@ -2110,7 +2123,7 @@
 *******************************************************************************/
 void bta_dm_search_cancel_cmpl (tBTA_DM_MSG *p_data)
 {
-
+    UNUSED(p_data);
     if(bta_dm_search_cb.p_search_queue)
     {
         bta_sys_sendmsg(bta_dm_search_cb.p_search_queue);
@@ -2131,7 +2144,7 @@
 *******************************************************************************/
 void bta_dm_search_cancel_transac_cmpl(tBTA_DM_MSG *p_data)
 {
-
+    UNUSED(p_data);
     if(bta_dm_search_cb.p_sdp_db)
     {
         GKI_freebuf(bta_dm_search_cb.p_sdp_db);
@@ -2153,6 +2166,7 @@
 *******************************************************************************/
 void bta_dm_search_cancel_notify (tBTA_DM_MSG *p_data)
 {
+    UNUSED(p_data);
     if (bta_dm_search_cb.p_search_cback)
     {
         bta_dm_search_cb.p_search_cback(BTA_DM_SEARCH_CANCEL_CMPL_EVT, NULL);
@@ -2613,6 +2627,7 @@
 {
     tBTM_REMOTE_DEV_NAME    rem_name;
     tBTM_STATUS             btm_status;
+    UNUSED(dc);
 
     APPL_TRACE_DEBUG1("bta_dm_service_search_remname_cback name=<%s>", bd_name);
 
@@ -2708,6 +2723,8 @@
 {
     tBTA_DM_SEC sec_event;
     UINT8       index = 1;
+    UNUSED(service_name);
+    UNUSED(is_originator);
 
     bdcpy(sec_event.authorize.bd_addr, bd_addr);
     memcpy(sec_event.authorize.dev_class, dev_class, DEV_CLASS_LEN);
@@ -2872,6 +2889,8 @@
     API. If BTM doesn't have the link key in it's
     data base, that's because application doesn't
     it */
+    UNUSED(bd_addr);
+    UNUSED(key);
 
     return BTM_NOT_AUTHORIZED;
 }
@@ -2895,6 +2914,7 @@
     tBTA_DM_SEC sec_event;
     tBTA_DM_AUTH_CMPL *p_auth_cmpl;
     UINT8             event;
+    UNUSED(dev_class);
 
     memset (&sec_event, 0, sizeof(tBTA_DM_SEC));
 
@@ -2941,8 +2961,8 @@
 *******************************************************************************/
 static UINT8 bta_dm_authentication_complete_cback(BD_ADDR bd_addr, DEV_CLASS dev_class,BD_NAME bd_name, int result)
 {
-
     tBTA_DM_SEC sec_event;
+    UNUSED(dev_class);
 
     if(result != BTM_SUCCESS)
     {
@@ -3107,6 +3127,7 @@
 static void bta_dm_local_name_cback(UINT8 *p_name)
 {
     tBTA_DM_SEC sec_event;
+    UNUSED(p_name);
 
     BTM_GetLocalDeviceAddr(sec_event.enable.bd_addr);
     sec_event.enable.status = BTA_SUCCESS;
@@ -3152,7 +3173,7 @@
 *******************************************************************************/
 static void bta_dm_signal_strength_timer_cback (TIMER_LIST_ENT *p_tle)
 {
-
+    UNUSED(p_tle);
     UINT8 i;
 
     if(bta_dm_cb.signal_strength_mask & BTA_SIG_STRENGTH_RSSI_MASK)
@@ -3278,6 +3299,7 @@
 *******************************************************************************/
 static void bta_dm_rs_cback (tBTM_ROLE_SWITCH_CMPL *p1)
 {
+    UNUSED(p1);
     APPL_TRACE_WARNING1("bta_dm_rs_cback:%d", bta_dm_cb.rs_event);
     if(bta_dm_cb.rs_event == BTA_DM_API_SEARCH_EVT)
     {
@@ -3546,6 +3568,7 @@
 *******************************************************************************/
 static void bta_dm_disable_conn_down_timer_cback (TIMER_LIST_ENT *p_tle)
 {
+    UNUSED(p_tle);
     tBTA_SYS_HW_MSG *sys_enable_event;
 
     /* disable the power managment module */
@@ -3743,6 +3766,7 @@
 *******************************************************************************/
 static void bta_dm_delay_role_switch_cback(TIMER_LIST_ENT *p_tle)
 {
+    UNUSED(p_tle);
     APPL_TRACE_EVENT0("bta_dm_delay_role_switch_cback: initiating Delayed RS");
     bta_dm_adjust_roles (FALSE);
 }
@@ -4435,6 +4459,7 @@
 *******************************************************************************/
 void bta_dm_enable_test_mode(tBTA_DM_MSG *p_data)
 {
+    UNUSED(p_data);
     BTM_EnableTestMode();
 }
 
@@ -4450,6 +4475,7 @@
 *******************************************************************************/
 void bta_dm_disable_test_mode(tBTA_DM_MSG *p_data)
 {
+    UNUSED(p_data);
     BTM_DeviceReset(NULL);
 }
 
@@ -4486,6 +4512,7 @@
 {
     tBTA_STATUS   bta_status = BTA_SUCCESS;
     tBTA_DM_ENCRYPT_CBACK *p_callback = bta_dm_cb.p_encrypt_cback;
+    UNUSED(p_ref_data);
 
     bta_dm_cb.p_encrypt_cback = NULL;
     switch (result)
@@ -5252,6 +5279,8 @@
 *******************************************************************************/
 void bta_dm_close_gatt_conn(tBTA_DM_MSG *p_data)
 {
+    UNUSED(p_data);
+
     if (bta_dm_search_cb.conn_id != BTA_GATT_INVALID_CONN_ID)
         BTA_GATTC_Close(bta_dm_search_cb.conn_id);
 
diff --git a/bta/dm/bta_dm_api.c b/bta/dm/bta_dm_api.c
index e37548e..7db7f7b 100644
--- a/bta/dm/bta_dm_api.c
+++ b/bta/dm/bta_dm_api.c
@@ -31,6 +31,7 @@
 #include "btm_api.h"
 #include "btm_int.h"
 #include <string.h>
+#include "utl.h"
 
 /*****************************************************************************
 **  Constants
@@ -207,7 +208,7 @@
     {
         p_msg->hdr.event = BTA_DM_API_SET_NAME_EVT;
         /* truncate the name if needed */
-        BCM_STRNCPY_S(p_msg->name, sizeof(p_msg->name), p_name, BD_NAME_LEN-1);
+        BCM_STRNCPY_S((char *)p_msg->name, sizeof(p_msg->name), p_name, BD_NAME_LEN-1);
         p_msg->name[BD_NAME_LEN-1]=0;
 
         bta_sys_sendmsg(p_msg);
@@ -1236,6 +1237,8 @@
     }
 }
 
+#if BLE_INCLUDED == TRUE
+
 /*******************************************************************************
 **
 ** Function         BTA_DmAddBleKey
@@ -1642,6 +1645,11 @@
 
         bta_sys_sendmsg(p_msg);
     }
+#else
+    UNUSED(bd_addr);
+    UNUSED(p_services);
+    UNUSED(p_cback);
+    UNUSED(sdp_search);
 #endif
 
 }
@@ -1698,6 +1706,10 @@
 
         bta_sys_sendmsg(p_msg);
     }
+#else
+    UNUSED(p_dm_inq);
+    UNUSED(p_services);
+    UNUSED(p_cback);
 #endif
 }
 
@@ -1715,8 +1727,8 @@
 *******************************************************************************/
 void BTA_DmBleEnableRemotePrivacy(BD_ADDR bd_addr, BOOLEAN privacy_enable)
 {
-#if BLE_INCLUDED == TRUE
-#endif
+    UNUSED(bd_addr);
+    UNUSED(privacy_enable);
 }
 
 
@@ -1733,10 +1745,9 @@
 *******************************************************************************/
 void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable)
 {
-#if BLE_INCLUDED == TRUE
-#endif
+    UNUSED(privacy_enable);
 }
-
+#endif
 
 /*******************************************************************************
 **
@@ -1811,6 +1822,7 @@
     }
 }
 
+#if BLE_INCLUDED == TRUE
 /*******************************************************************************
 **
 ** Function         BTA_DmBleObserve
@@ -1848,5 +1860,4 @@
     }
 #endif
 }
-
-
+#endif
diff --git a/bta/dm/bta_dm_cfg.c b/bta/dm/bta_dm_cfg.c
index 5caf04a..e4a1681 100644
--- a/bta/dm/bta_dm_cfg.c
+++ b/bta/dm/bta_dm_cfg.c
@@ -488,6 +488,8 @@
     NULL,   /* flags for EIR */
     0,      /* length of manufacturer specific in bytes */
     NULL,   /* manufacturer specific */
+    0,      /* length of additional data in bytes */
+    NULL    /* additional data */
 };
 tBTA_DM_EIR_CONF *p_bta_dm_eir_cfg = (tBTA_DM_EIR_CONF*)&bta_dm_eir_cfg;
 #endif
diff --git a/bta/dm/bta_dm_pm.c b/bta/dm/bta_dm_pm.c
index cb5da6f..7008498 100644
--- a/bta/dm/bta_dm_pm.c
+++ b/bta/dm/bta_dm_pm.c
@@ -31,6 +31,8 @@
 #include "btm_api.h"
 
 #include <string.h>
+#include <cutils/properties.h>
+#include <utils/Log.h>
 
 
 static void bta_dm_pm_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
@@ -334,6 +336,8 @@
     tBTA_DM_PM_SPEC     *p_pm_spec;
     tBTA_DM_PM_ACTN     *p_act0, *p_act1;
     tBTA_DM_SRVCS       *p_srvcs;
+    char buf[PROPERTY_VALUE_MAX];
+    int len = 0, temp = 0;
 
 
     if(!bta_dm_cb.device_list.count)
@@ -432,6 +436,12 @@
                 bta_dm_cb.pm_timer[i].in_use = TRUE;
                 bdcpy(bta_dm_cb.pm_timer[i].peer_bdaddr, peer_addr);
                 bta_dm_cb.pm_timer[i].timer.p_cback = bta_dm_pm_timer_cback;
+                len = property_get("bluetooth.force_pm_timer", buf, NULL);
+                if(len > 0)
+                {
+                    sscanf(buf, "%d", &temp);
+                    timeout = temp;
+                }
                 bta_sys_start_timer(&bta_dm_cb.pm_timer[i].timer, 0, timeout);
                 APPL_TRACE_DEBUG2("start dm_pm_timer:%d, %d", i, timeout);
                 return;
diff --git a/bta/gatt/bta_gattc_act.c b/bta/gatt/bta_gattc_act.c
index 7563ec3..44f88e4 100644
--- a/bta/gatt/bta_gattc_act.c
+++ b/bta/gatt/bta_gattc_act.c
@@ -69,7 +69,8 @@
 {
     BTA_GATTC_API_READ_EVT,
     BTA_GATTC_API_WRITE_EVT,
-    BTA_GATTC_API_EXEC_EVT
+    BTA_GATTC_API_EXEC_EVT,
+    BTA_GATTC_API_CFG_MTU_EVT
 };
 
 #if (BT_TRACE_VERBOSE == TRUE)
@@ -250,6 +251,8 @@
 *******************************************************************************/
 void bta_gattc_start_if(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg)
 {
+    UNUSED(p_cb);
+
     if (bta_gattc_cl_get_regcb(p_msg->int_start_if.client_if) !=NULL )
     {
         GATT_StartIf(p_msg->int_start_if.client_if);
@@ -329,6 +332,7 @@
     UINT16 event = ((BT_HDR *)p_msg)->event;
     tBTA_GATTC_CLCB *p_clcb = NULL;
     tBTA_GATTC_RCB *p_clreg = bta_gattc_cl_get_regcb(p_msg->api_conn.client_if);
+    UNUSED(p_cb);
 
     if (p_clreg != NULL)
     {
@@ -346,7 +350,8 @@
                 bta_gattc_send_open_cback(p_clreg,
                                           BTA_GATT_NO_RESOURCES,
                                           p_msg->api_conn.remote_bda,
-                                          BTA_GATT_INVALID_CONN_ID);
+                                          BTA_GATT_INVALID_CONN_ID,
+                                          0);
             }
         }
         else
@@ -375,6 +380,7 @@
     tBTA_GATTC_CLCB *p_clcb = NULL;
     tBTA_GATTC_RCB *p_clreg;
     tBTA_GATTC cb_data;
+    UNUSED(p_cb);
 
     if (p_msg->api_cancel_conn.is_direct)
     {
@@ -416,6 +422,7 @@
 {
     tBTA_GATTC_RCB *p_clreg;
     tBTA_GATTC cb_data;
+    UNUSED(p_cb);
 
     p_clreg = bta_gattc_cl_get_regcb(p_msg->enc_cmpl.client_if);
 
@@ -442,6 +449,8 @@
 void bta_gattc_cancel_open_error(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
 {
     tBTA_GATTC cb_data;
+    UNUSED(p_data);
+
     cb_data.status=BTA_GATT_ERROR;
 
     if ( p_clcb && p_clcb->p_rcb && p_clcb->p_rcb->p_cback )
@@ -459,12 +468,15 @@
 *******************************************************************************/
 void bta_gattc_open_error(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
 {
+    UNUSED(p_data);
+
     APPL_TRACE_ERROR0("Connection already opened. wrong state");
 
     bta_gattc_send_open_cback(p_clcb->p_rcb,
                               BTA_GATT_OK,
                               p_clcb->bda,
-                              p_clcb->bta_conn_id);
+                              p_clcb->bta_conn_id,
+                              0);
 }
 /*******************************************************************************
 **
@@ -477,10 +489,13 @@
 *******************************************************************************/
 void bta_gattc_open_fail(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
 {
+    UNUSED(p_data);
+
     bta_gattc_send_open_cback(p_clcb->p_rcb,
                               BTA_GATT_ERROR,
                               p_clcb->bda,
-                              p_clcb->bta_conn_id);
+                              p_clcb->bta_conn_id,
+                              0);
 
     /* open failure, remove clcb */
     bta_gattc_clcb_dealloc(p_clcb);
@@ -568,7 +583,7 @@
     /* open failure, report OPEN_EVT */
     if (status != BTA_GATT_OK)
     {
-        bta_gattc_send_open_cback(p_clreg, status, p_data->remote_bda, BTA_GATT_INVALID_CONN_ID);
+        bta_gattc_send_open_cback(p_clreg, status, p_data->remote_bda, BTA_GATT_INVALID_CONN_ID, 0);
     }
 }
 /*******************************************************************************
@@ -618,6 +633,7 @@
 void bta_gattc_cancel_open_ok(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
 {
     tBTA_GATTC          cb_data;
+    UNUSED(p_data);
 
     if ( p_clcb->p_rcb->p_cback )
     {
@@ -675,6 +691,10 @@
     }
 
         p_clcb->p_srcb->connected = TRUE;
+
+        if (p_clcb->p_srcb->mtu == 0)
+            p_clcb->p_srcb->mtu = GATT_DEF_BLE_MTU_SIZE;
+
         /* start database cache if needed */
         if (p_clcb->p_srcb->p_srvc_cache == NULL ||
             p_clcb->p_srcb->state != BTA_GATTC_SERV_IDLE)
@@ -707,7 +727,8 @@
             bta_gattc_send_open_cback(p_clcb->p_rcb,
                                       BTA_GATT_OK,
                                       p_clcb->bda,
-                                      p_clcb->bta_conn_id);
+                                      p_clcb->bta_conn_id,
+                                      p_clcb->p_srcb->mtu);
         }
     }
 /*******************************************************************************
@@ -854,9 +875,43 @@
 *******************************************************************************/
 void bta_gattc_restart_discover(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
 {
+    UNUSED(p_data);
+
     p_clcb->status      = BTA_GATT_CANCEL;
     p_clcb->auto_update = BTA_GATTC_DISC_WAITING;
 }
+
+/*******************************************************************************
+**
+** Function         bta_gattc_cfg_mtu
+**
+** Description      Configure MTU size on the GATT connection.
+**
+** Returns          None.
+**
+*******************************************************************************/
+void bta_gattc_cfg_mtu(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
+{
+    tBTA_GATTC_OP_CMPL  op_cmpl;
+    tBTA_GATT_STATUS    status;
+
+    if (bta_gattc_enqueue(p_clcb, p_data))
+    {
+        status = GATTC_ConfigureMTU (p_clcb->bta_conn_id, p_data->api_mtu.mtu);
+
+        /* if failed, return callback here */
+        if (status != GATT_SUCCESS && status != GATT_CMD_STARTED)
+        {
+            memset(&op_cmpl, 0, sizeof(tBTA_GATTC_OP_CMPL));
+
+            op_cmpl.status  = status;
+            op_cmpl.op_code = GATTC_OPTYPE_CONFIG;
+            op_cmpl.p_cmpl  = NULL;
+
+            bta_gattc_sm_execute(p_clcb, BTA_GATTC_OP_CMPL_EVT, (tBTA_GATTC_DATA *)&op_cmpl);
+        }
+    }
+}
 /*******************************************************************************
 **
 ** Function         bta_gattc_start_discover
@@ -868,6 +923,7 @@
 *******************************************************************************/
 void bta_gattc_start_discover(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
 {
+    UNUSED(p_data);
 
     APPL_TRACE_DEBUG2("bta_gattc_start_discover conn_id=%d p_clcb->p_srcb->state = %d ",
         p_clcb->bta_conn_id, p_clcb->p_srcb->state);
@@ -926,6 +982,8 @@
 void bta_gattc_disc_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
 {
     tBTA_GATTC_DATA *p_q_cmd = p_clcb->p_q_cmd;
+    UNUSED(p_data);
+
     APPL_TRACE_DEBUG1("bta_gattc_disc_cmpl conn_id=%d",p_clcb->bta_conn_id);
 
 #if BLE_INCLUDED == TRUE
@@ -1329,6 +1387,35 @@
     ( *p_clcb->p_rcb->p_cback)(BTA_GATTC_EXEC_EVT,  &cb_data);
 
 }
+
+/*******************************************************************************
+**
+** Function         bta_gattc_cfg_mtu_cmpl
+**
+** Description      configure MTU operation complete
+**
+** Returns          None.
+**
+*******************************************************************************/
+void bta_gattc_cfg_mtu_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_OP_CMPL *p_data)
+{
+    tBTA_GATTC          cb_data;
+
+    utl_freebuf((void **)&p_clcb->p_q_cmd);
+
+
+    if (p_data->p_cmpl  &&  p_data->status == BTA_GATT_OK)
+        p_clcb->p_srcb->mtu  = p_data->p_cmpl->mtu;
+
+    /* configure MTU complete, callback */
+    p_clcb->status          = p_data->status;
+    cb_data.cfg_mtu.conn_id = p_clcb->bta_conn_id;
+    cb_data.cfg_mtu.status  = p_data->status;
+    cb_data.cfg_mtu.mtu     = p_clcb->p_srcb->mtu;
+
+    (*p_clcb->p_rcb->p_cback) (BTA_GATTC_CFG_MTU_EVT,  &cb_data);
+
+}
 /*******************************************************************************
 **
 ** Function         bta_gattc_op_cmpl
@@ -1386,11 +1473,9 @@
 
         else if (op == GATTC_OPTYPE_EXE_WRITE)
             bta_gattc_exec_cmpl(p_clcb, &p_data->op_cmpl);
-        /*
-        else if (op == GATTC_OPTYPE_CONFIG) // API to be added
-        {
-        }
-       */
+
+        else if (op == GATTC_OPTYPE_CONFIG)
+            bta_gattc_cfg_mtu_cmpl(p_clcb, &p_data->op_cmpl);
     }
 }
 /*******************************************************************************
@@ -1404,6 +1489,8 @@
 *******************************************************************************/
 void  bta_gattc_ignore_op_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
 {
+    UNUSED(p_clcb);
+
     /* receive op complete when discovery is started, ignore the response,
         and wait for discovery finish and resent */
     APPL_TRACE_DEBUG1("bta_gattc_ignore_op_cmpl op = %d", p_data->hdr.layer_specific);
@@ -1460,6 +1547,8 @@
 *******************************************************************************/
 void bta_gattc_cache_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
 {
+    UNUSED(p_data);
+
     bta_gattc_set_discover_st(p_clcb->p_srcb);
 
     APPL_TRACE_DEBUG1("bta_gattc_cache_open conn_id=%d",p_clcb->bta_conn_id);
@@ -1571,6 +1660,8 @@
 *******************************************************************************/
 void bta_gattc_ci_save(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
 {
+    UNUSED(p_data);
+
     APPL_TRACE_DEBUG1("bta_gattc_ci_save conn_id=%d  " ,
                       p_clcb->bta_conn_id   );
 
@@ -1592,6 +1683,8 @@
 *******************************************************************************/
 void bta_gattc_fail(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
 {
+    UNUSED(p_data);
+
     if (p_clcb->status == BTA_GATT_OK)
     {
         APPL_TRACE_ERROR1("operation not supported at current state [%d]", p_clcb->state);
@@ -1724,6 +1817,7 @@
     tBTA_GATTC_CLCB      *p_clcb = &bta_gattc_cb.clcb[0];
     BOOLEAN         found = FALSE;
     UINT8           i;
+    UNUSED(p_cb);
 
     if (p_srvc_cb != NULL)
     {
@@ -2074,6 +2168,8 @@
 {
     tBTA_GATTC_RCB      *p_clreg = bta_gattc_cl_get_regcb(p_msg->api_listen.client_if);
     tBTA_GATTC          cb_data;
+    UNUSED(p_cb);
+
     cb_data.reg_oper.status = BTA_GATT_ERROR;
     cb_data.reg_oper.client_if = p_msg->api_listen.client_if;
 
diff --git a/bta/gatt/bta_gattc_api.c b/bta/gatt/bta_gattc_api.c
index d264458..0bc87ec 100644
--- a/bta/gatt/bta_gattc_api.c
+++ b/bta/gatt/bta_gattc_api.c
@@ -224,6 +224,34 @@
 }
 /*******************************************************************************
 **
+** Function         BTA_GATTC_ConfigureMTU
+**
+** Description      Configure the MTU size in the GATT channel. This can be done
+**                  only once per connection.
+**
+** Parameters       conn_id: connection ID.
+**                  mtu: desired MTU size to use.
+**
+** Returns          void
+**
+*******************************************************************************/
+void BTA_GATTC_ConfigureMTU (UINT16 conn_id, UINT16 mtu)
+{
+    tBTA_GATTC_API_CFG_MTU  *p_buf;
+
+    if ((p_buf = (tBTA_GATTC_API_CFG_MTU *) GKI_getbuf(sizeof(tBTA_GATTC_API_CFG_MTU))) != NULL)
+    {
+        p_buf->hdr.event = BTA_GATTC_API_CFG_MTU_EVT;
+        p_buf->hdr.layer_specific = conn_id;
+
+        p_buf->mtu = mtu;
+
+        bta_sys_sendmsg(p_buf);
+    }
+    return;
+}
+/*******************************************************************************
+**
 ** Function         BTA_GATTC_ServiceSearchRequest
 **
 ** Description      This function is called to request a GATT service discovery
diff --git a/bta/gatt/bta_gattc_cache.c b/bta/gatt/bta_gattc_cache.c
index bc784d7..3d603c3 100644
--- a/bta/gatt/bta_gattc_cache.c
+++ b/bta/gatt/bta_gattc_cache.c
@@ -35,6 +35,7 @@
 #include "sdpdefs.h"
 #include "bta_gattc_int.h"
 #include "btm_api.h"
+#include "btm_ble_api.h"
 
 static void bta_gattc_char_dscpt_disc_cmpl(UINT16 conn_id, tBTA_GATTC_SERV *p_srvc_cb);
 static tBTA_GATT_STATUS bta_gattc_sdp_service_disc(UINT16 conn_id, tBTA_GATTC_SERV *p_server_cb);
@@ -689,6 +690,7 @@
     tBTA_GATTC_ATTR_REC *p_rec = NULL;
     UINT8   i;
     BOOLEAN exist_srvc = FALSE;
+    UNUSED(uuid);
 
     if (!GATT_HANDLE_IS_VALID(s_handle) || !GATT_HANDLE_IS_VALID(e_handle))
     {
diff --git a/bta/gatt/bta_gattc_ci.c b/bta/gatt/bta_gattc_ci.c
index 212126f..533955a 100644
--- a/bta/gatt/bta_gattc_ci.c
+++ b/bta/gatt/bta_gattc_ci.c
@@ -33,6 +33,7 @@
 #include "bta_gattc_ci.h"
 #include "gki.h"
 #include "bd.h"
+#include "utl.h"
 
 /*******************************************************************************
 **
@@ -52,6 +53,7 @@
                              UINT16 conn_id)
 {
     tBTA_GATTC_CI_EVT  *p_evt;
+    UNUSED(server_bda);
 
     if ((p_evt = (tBTA_GATTC_CI_EVT *) GKI_getbuf(sizeof(tBTA_GATTC_CI_EVT))) != NULL)
     {
@@ -84,6 +86,7 @@
                              UINT16 conn_id)
 {
     tBTA_GATTC_CI_LOAD  *p_evt;
+    UNUSED(server_bda);
 
     if ((p_evt = (tBTA_GATTC_CI_LOAD *) GKI_getbuf(sizeof(tBTA_GATTC_CI_LOAD))) != NULL)
     {
@@ -124,6 +127,7 @@
                              UINT16 conn_id)
 {
     tBTA_GATTC_CI_EVT  *p_evt;
+    UNUSED(server_bda);
 
     if ((p_evt = (tBTA_GATTC_CI_EVT *) GKI_getbuf(sizeof(tBTA_GATTC_CI_EVT))) != NULL)
     {
diff --git a/bta/gatt/bta_gattc_int.h b/bta/gatt/bta_gattc_int.h
index 255090d..4f192cb 100644
--- a/bta/gatt/bta_gattc_int.h
+++ b/bta/gatt/bta_gattc_int.h
@@ -45,6 +45,7 @@
     BTA_GATTC_API_READ_EVT,
     BTA_GATTC_API_WRITE_EVT,
     BTA_GATTC_API_EXEC_EVT,
+    BTA_GATTC_API_CFG_MTU_EVT,
 
     BTA_GATTC_API_CLOSE_EVT,
 
@@ -188,6 +189,13 @@
     BOOLEAN                 start;
 } tBTA_GATTC_API_LISTEN;
 
+
+typedef struct
+{
+    BT_HDR              hdr;
+    UINT16              mtu;
+}tBTA_GATTC_API_CFG_MTU;
+
 typedef struct
 {
     BT_HDR                  hdr;
@@ -217,6 +225,7 @@
     tBTA_GATTC_API_CONFIRM      api_confirm;
     tBTA_GATTC_API_EXEC         api_exec;
     tBTA_GATTC_API_READ_MULTI   api_read_multi;
+    tBTA_GATTC_API_CFG_MTU      api_mtu;
     tBTA_GATTC_OP_CMPL          op_cmpl;
     tBTA_GATTC_CI_EVT           ci_open;
     tBTA_GATTC_CI_EVT           ci_save;
@@ -327,6 +336,7 @@
     UINT8               srvc_hdl_chg;   /* service handle change indication pending */
     UINT16              attr_index;     /* cahce NV saving/loading attribute index */
 
+    UINT16              mtu;
 } tBTA_GATTC_SERV;
 
 #ifndef BTA_GATTC_NOTIF_REG_MAX
@@ -481,8 +491,9 @@
 extern void bta_gattc_init_bk_conn(tBTA_GATTC_API_OPEN *p_data, tBTA_GATTC_RCB *p_clreg);
 extern void bta_gattc_cancel_bk_conn(tBTA_GATTC_API_CANCEL_OPEN *p_data);
 extern void bta_gattc_send_open_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status,
-                                       BD_ADDR remote_bda, UINT16 conn_id);
+                                       BD_ADDR remote_bda, UINT16 conn_id, UINT16 mtu);
 extern void bta_gattc_process_api_refresh(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg);
+extern void bta_gattc_cfg_mtu(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
 #if BLE_INCLUDED == TRUE
 extern void bta_gattc_listen(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg);
 extern void bta_gattc_broadcast(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg);
diff --git a/bta/gatt/bta_gattc_main.c b/bta/gatt/bta_gattc_main.c
index 638f2f9..932a1d7 100644
--- a/bta/gatt/bta_gattc_main.c
+++ b/bta/gatt/bta_gattc_main.c
@@ -69,6 +69,7 @@
     BTA_GATTC_IGNORE_OP_CMPL,
     BTA_GATTC_DISC_CLOSE,
     BTA_GATTC_RESTART_DISCOVER,
+    BTA_GATTC_CFG_MTU,
 
     BTA_GATTC_IGNORE
 };
@@ -106,7 +107,8 @@
     bta_gattc_cache_open,
     bta_gattc_ignore_op_cmpl,
     bta_gattc_disc_close,
-    bta_gattc_restart_discover
+    bta_gattc_restart_discover,
+    bta_gattc_cfg_mtu
 };
 
 
@@ -127,6 +129,7 @@
 /* BTA_GATTC_API_READ_EVT           */   {BTA_GATTC_FAIL,              BTA_GATTC_IDLE_ST},
 /* BTA_GATTC_API_WRITE_EVT          */   {BTA_GATTC_FAIL,              BTA_GATTC_IDLE_ST},
 /* BTA_GATTC_API_EXEC_EVT           */   {BTA_GATTC_FAIL,              BTA_GATTC_IDLE_ST},
+/* BTA_GATTC_API_CFG_MTU_EVT        */   {BTA_GATTC_IGNORE,            BTA_GATTC_IDLE_ST},
 
 /* BTA_GATTC_API_CLOSE_EVT          */   {BTA_GATTC_CLOSE_FAIL,        BTA_GATTC_IDLE_ST},
 
@@ -161,6 +164,7 @@
 /* BTA_GATTC_API_READ_EVT           */   {BTA_GATTC_FAIL,               BTA_GATTC_W4_CONN_ST},
 /* BTA_GATTC_API_WRITE_EVT          */   {BTA_GATTC_FAIL,               BTA_GATTC_W4_CONN_ST},
 /* BTA_GATTC_API_EXEC_EVT           */   {BTA_GATTC_FAIL,               BTA_GATTC_W4_CONN_ST},
+/* BTA_GATTC_API_CFG_MTU_EVT        */   {BTA_GATTC_IGNORE,             BTA_GATTC_W4_CONN_ST},
 
 /* BTA_GATTC_API_CLOSE_EVT          */   {BTA_GATTC_CANCEL_OPEN,         BTA_GATTC_W4_CONN_ST},
 
@@ -186,7 +190,7 @@
 static const UINT8 bta_gattc_st_connected[][BTA_GATTC_NUM_COLS] =
 {
 /* Event                            Action 1                            Next state */
-/* BTA_GATTC_API_OPEN_EVT           */   {BTA_GATTC_OPEN_ERROR,         BTA_GATTC_CONN_ST},
+/* BTA_GATTC_API_OPEN_EVT           */   {BTA_GATTC_OPEN,               BTA_GATTC_CONN_ST},
 /* BTA_GATTC_INT_OPEN_FAIL_EVT      */   {BTA_GATTC_IGNORE,             BTA_GATTC_CONN_ST},
 /* BTA_GATTC_API_CANCEL_OPEN_EVT    */   {BTA_GATTC_CANCEL_OPEN_ERROR, BTA_GATTC_CONN_ST},
 /* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */   {BTA_GATTC_IGNORE,            BTA_GATTC_CONN_ST},
@@ -194,6 +198,7 @@
 /* BTA_GATTC_API_READ_EVT           */   {BTA_GATTC_READ,               BTA_GATTC_CONN_ST},
 /* BTA_GATTC_API_WRITE_EVT          */   {BTA_GATTC_WRITE,              BTA_GATTC_CONN_ST},
 /* BTA_GATTC_API_EXEC_EVT           */   {BTA_GATTC_EXEC,               BTA_GATTC_CONN_ST},
+/* BTA_GATTC_API_CFG_MTU_EVT        */   {BTA_GATTC_CFG_MTU,            BTA_GATTC_CONN_ST},
 
 /* BTA_GATTC_API_CLOSE_EVT          */   {BTA_GATTC_CLOSE,              BTA_GATTC_IDLE_ST},
 
@@ -220,7 +225,7 @@
 static const UINT8 bta_gattc_st_discover[][BTA_GATTC_NUM_COLS] =
 {
 /* Event                            Action 1                            Next state */
-/* BTA_GATTC_API_OPEN_EVT           */   {BTA_GATTC_OPEN_ERROR,         BTA_GATTC_DISCOVER_ST},
+/* BTA_GATTC_API_OPEN_EVT           */   {BTA_GATTC_OPEN,               BTA_GATTC_DISCOVER_ST},
 /* BTA_GATTC_INT_OPEN_FAIL_EVT      */   {BTA_GATTC_IGNORE,             BTA_GATTC_DISCOVER_ST},
 /* BTA_GATTC_API_CANCEL_OPEN_EVT    */   {BTA_GATTC_CANCEL_OPEN_ERROR,  BTA_GATTC_DISCOVER_ST},
 /* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */   {BTA_GATTC_FAIL,               BTA_GATTC_DISCOVER_ST},
@@ -228,6 +233,7 @@
 /* BTA_GATTC_API_READ_EVT           */   {BTA_GATTC_Q_CMD,              BTA_GATTC_DISCOVER_ST},
 /* BTA_GATTC_API_WRITE_EVT          */   {BTA_GATTC_Q_CMD,              BTA_GATTC_DISCOVER_ST},
 /* BTA_GATTC_API_EXEC_EVT           */   {BTA_GATTC_Q_CMD,              BTA_GATTC_DISCOVER_ST},
+/* BTA_GATTC_API_CFG_MTU_EVT        */   {BTA_GATTC_Q_CMD,              BTA_GATTC_DISCOVER_ST},
 
 /* BTA_GATTC_API_CLOSE_EVT          */   {BTA_GATTC_DISC_CLOSE,         BTA_GATTC_DISCOVER_ST},
 
@@ -489,6 +495,8 @@
             return "BTA_GATTC_API_LISTEN_EVT";
         case BTA_GATTC_API_DISABLE_EVT:
             return "BTA_GATTC_API_DISABLE_EVT";
+        case BTA_GATTC_API_CFG_MTU_EVT:
+            return "BTA_GATTC_API_CFG_MTU_EVT";
         default:
             return "unknown GATTC event code";
     }
diff --git a/bta/gatt/bta_gattc_utils.c b/bta/gatt/bta_gattc_utils.c
index d81e121..b52e52c 100644
--- a/bta/gatt/bta_gattc_utils.c
+++ b/bta/gatt/bta_gattc_utils.c
@@ -294,6 +294,7 @@
         {
             p_srcb->connected = FALSE;
             p_srcb->state = BTA_GATTC_SERV_IDLE;
+            p_srcb->mtu = 0;
         }
 
         utl_freebuf((void **)&p_clcb->p_q_cmd);
@@ -557,6 +558,18 @@
                 }
                 break;
             }
+            case BTA_GATTC_API_CFG_MTU_EVT:
+            {
+                len = sizeof(tBTA_GATTC_API_CFG_MTU);
+                p_clcb->p_q_cmd = (tBTA_GATTC_DATA *)GKI_getbuf(len);
+                if (p_clcb->p_q_cmd == NULL)
+                {
+                    APPL_TRACE_ERROR0("allocate buffer failed for p_q_cmd");
+                    return FALSE;
+                }
+                memcpy(p_clcb->p_q_cmd, p_data, len);
+                break;
+            }
             default:
                 APPL_TRACE_ERROR1("queue unsupported command %d", p_data->hdr.event);
                 return FALSE;
@@ -906,7 +919,7 @@
 **
 *******************************************************************************/
 void bta_gattc_send_open_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status,
-                                BD_ADDR remote_bda, UINT16 conn_id)
+                                BD_ADDR remote_bda, UINT16 conn_id, UINT16 mtu)
 {
     tBTA_GATTC      cb_data;
 
@@ -917,6 +930,7 @@
         cb_data.open.status = status;
         cb_data.open.client_if = p_clreg->client_if;
         cb_data.open.conn_id = conn_id;
+        cb_data.open.mtu = mtu;
         bdcpy(cb_data.open.remote_bda, remote_bda);
 
         (*p_clreg->p_cback)(BTA_GATTC_OPEN_EVT, &cb_data);
diff --git a/bta/gatt/bta_gatts_act.c b/bta/gatt/bta_gatts_act.c
index f1bd88e..be03655 100644
--- a/bta/gatt/bta_gatts_act.c
+++ b/bta/gatt/bta_gatts_act.c
@@ -267,6 +267,8 @@
 *******************************************************************************/
 void bta_gatts_start_if(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
 {
+    UNUSED(p_cb);
+
     if (bta_gatts_find_app_rcb_by_app_if(p_msg->int_start_if.server_if))
     {
         GATT_StartIf(p_msg->int_start_if.server_if);
@@ -577,6 +579,7 @@
 {
     tBTA_GATTS_RCB *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx];
     tBTA_GATTS      cb_data;
+    UNUSED(p_msg);
 
     GATTS_StopService(p_srvc_cb->service_id);
     cb_data.srvc_oper.server_if = p_rcb->gatt_if;
@@ -599,6 +602,7 @@
 *******************************************************************************/
 void bta_gatts_send_rsp (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
 {
+    UNUSED(p_cb);
 
     if (GATTS_SendRsp (p_msg->api_rsp.hdr.layer_specific,
                         p_msg->api_rsp.trans_id,
@@ -688,7 +692,7 @@
 {
     tBTA_GATTS_RCB      *p_rcb=NULL;
     tBTA_GATT_STATUS    status= BTA_GATT_ERROR;
-
+    UNUSED(p_cb);
 
     if ((p_rcb = bta_gatts_find_app_rcb_by_app_if(p_msg->api_open.server_if)) != NULL)
     {
@@ -719,6 +723,7 @@
 {
     tBTA_GATTS_RCB      *p_rcb;
     tBTA_GATT_STATUS    status= BTA_GATT_ERROR;
+    UNUSED(p_cb);
 
     if ((p_rcb = bta_gatts_find_app_rcb_by_app_if(p_msg->api_cancel_open.server_if)) != NULL)
     {
@@ -754,6 +759,7 @@
     tBTA_GATT_STATUS    status= BTA_GATT_ERROR;
     tGATT_IF            gatt_if;
     BD_ADDR             remote_bda;
+    UNUSED(p_cb);
 
     if (GATT_GetConnectionInfor(p_msg->hdr.layer_specific, &gatt_if, remote_bda))
     {
@@ -795,6 +801,8 @@
 {
     tBTA_GATTS_RCB     *p_rcb = bta_gatts_find_app_rcb_by_app_if(p_msg->api_listen.server_if);
     tBTA_GATTS          cb_data;
+    UNUSED(p_cb);
+
     cb_data.reg_oper.status = BTA_GATT_OK;
     cb_data.reg_oper.server_if = p_msg->api_listen.server_if;
 
diff --git a/bta/hh/bta_hh_act.c b/bta/hh/bta_hh_act.c
index 1c83d07..8ec2698 100644
--- a/bta/hh/bta_hh_act.c
+++ b/bta/hh/bta_hh_act.c
@@ -33,6 +33,7 @@
 #include "l2c_api.h"
 #include "bta_hh_int.h"
 #include "bta_hh_co.h"
+#include "utl.h"
 
 /*****************************************************************************
 **  Constants
@@ -222,6 +223,10 @@
                     p_cb->app_id = 0;
                 }
             }
+            else
+            {
+                hdl = p_cb->hid_handle;
+            }
             /* else : incoming connection after SDP should update the SDP information as well */
 
             if (p_cb->app_id != 0)
@@ -940,6 +945,8 @@
 *******************************************************************************/
 void bta_hh_get_dscp_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
 {
+    UNUSED(p_data);
+
 #if (BTA_HH_LE_INCLUDED == TRUE)
     if (p_cb->is_le_device)
     {
diff --git a/bta/hh/bta_hh_api.c b/bta/hh/bta_hh_api.c
index 1e71d91..df41a52 100644
--- a/bta/hh/bta_hh_api.c
+++ b/bta/hh/bta_hh_api.c
@@ -33,6 +33,7 @@
 #include "bta_hh_api.h"
 #include "bta_hh_int.h"
 #include "l2c_api.h"
+#include "utl.h"
 
 /*****************************************************************************
 **  Constants
@@ -305,12 +306,13 @@
 *******************************************************************************/
 void BTA_HhSendData(UINT8 dev_handle, BD_ADDR dev_bda, BT_HDR  *p_data)
 {
+    UNUSED(dev_bda);
 #if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
-        if (p_data->layer_specific != BTA_HH_RPTT_OUTPUT)
-        {
-            APPL_TRACE_ERROR0("ERROR! Wrong report type! Write Command only valid for output report!");
-            return;
-        }
+    if (p_data->layer_specific != BTA_HH_RPTT_OUTPUT)
+    {
+        APPL_TRACE_ERROR0("ERROR! Wrong report type! Write Command only valid for output report!");
+        return;
+    }
 #endif
     bta_hh_snd_write_dev(dev_handle, HID_TRANS_DATA, (UINT8)p_data->layer_specific, 0, 0, p_data);
 }
diff --git a/bta/hh/bta_hh_le.c b/bta/hh/bta_hh_le.c
index dbbfb32..4f297ee 100644
--- a/bta/hh/bta_hh_le.c
+++ b/bta/hh/bta_hh_le.c
@@ -29,6 +29,7 @@
 #include "bta_gatt_api.h"
 #include "srvc_api.h"
 #include "btm_int.h"
+#include "utl.h"
 
 #ifndef BTA_HH_LE_RECONN
 #define BTA_HH_LE_RECONN    TRUE
@@ -1213,6 +1214,7 @@
 {
     UINT8   idx = bta_hh_find_cb(bd_addr);
     tBTA_HH_DEV_CB *p_dev_cb;
+    UNUSED(p_ref_data);
 
     APPL_TRACE_ERROR0("bta_hh_le_encrypt_cback");
 
@@ -1239,6 +1241,8 @@
 *******************************************************************************/
 void bta_hh_security_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_buf)
 {
+    UNUSED(p_buf);
+
     if (p_cb->status == BTA_HH_OK)
     {
         /*  discovery has been done for HID service */
@@ -1296,6 +1300,7 @@
 {
     UINT8           sec_flag=0;
     tBTM_SEC_DEV_REC  *p_dev_rec;
+    UNUSED(p_buf);
 
     p_dev_rec = btm_find_dev(p_cb->addr);
     if (p_dev_rec)
@@ -1640,6 +1645,9 @@
 *******************************************************************************/
 void bta_hh_read_battery_level_cmpl(UINT8 status, tBTA_HH_DEV_CB *p_dev_cb, tBTA_GATTC_READ *p_data)
 {
+    UNUSED(status);
+    UNUSED(p_data);
+
     p_dev_cb->hid_srvc[p_dev_cb->cur_srvc_index].expl_incl_srvc = TRUE;
     bta_hh_le_srvc_expl_srvc(p_dev_cb);
 }
diff --git a/bta/hh/bta_hh_utils.c b/bta/hh/bta_hh_utils.c
index 0c67513..6130a88 100644
--- a/bta/hh/bta_hh_utils.c
+++ b/bta/hh/bta_hh_utils.c
@@ -165,6 +165,8 @@
     p_cb->dscp_info.version       =   version;
 #if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
     p_cb->dscp_info.flag          =   flag;
+#else
+    UNUSED(flag);
 #endif
 }
 /*******************************************************************************
@@ -335,7 +337,7 @@
         APPL_TRACE_DEBUG1("found keycode %02x ",  this_report[xx]);
 #endif
         p_data->caps_lock   = p_kb->caps_lock;
-        p_kb->num_lock      = p_kb->num_lock;
+        p_data->num_lock      = p_kb->num_lock;
     }
 
     memset (p_kb->last_report, 0, BTA_HH_MAX_RPT_CHARS);
diff --git a/bta/hl/bta_hl_act.c b/bta/hl/bta_hl_act.c
index 8e16146..01528aa 100644
--- a/bta/hl/bta_hl_act.c
+++ b/bta/hl/bta_hl_act.c
@@ -121,6 +121,7 @@
     tBTA_HL_APP_CB      *p_acb  = BTA_HL_GET_APP_CB_PTR(app_idx);
     tBTA_HL_MCL_CB      *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
     tBTA_HL_MDL_CB      *p_dcb  = BTA_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
+    UNUSED(p_data);
 
 #if (BTA_HL_DEBUG == TRUE)
     APPL_TRACE_DEBUG0("bta_hl_dch_echo_test");
diff --git a/bta/hl/bta_hl_main.c b/bta/hl/bta_hl_main.c
index f229c10..7b15585 100644
--- a/bta/hl/bta_hl_main.c
+++ b/bta/hl/bta_hl_main.c
@@ -770,9 +770,9 @@
 *******************************************************************************/
 static void bta_hl_api_deregister(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data)
 {
-
     UINT8           app_idx;
     tBTA_HL_APP_CB  *p_acb;
+    UNUSED(p_cb);
 
     if (bta_hl_find_app_idx_using_handle(p_data->api_dereg.app_handle, &app_idx))
     {
@@ -802,6 +802,7 @@
     UINT8           app_idx, mcl_idx;
     tBTA_HL_APP_CB  *p_acb;
     tBTA_HL_MCL_CB  *p_mcb;
+    UNUSED(p_cb);
 
     if (bta_hl_find_app_idx_using_handle(p_data->api_cch_open.app_handle, &app_idx))
     {
@@ -900,6 +901,7 @@
     UINT8           app_idx, mcl_idx;
     tBTA_HL_APP_CB  *p_acb;
     tBTA_HL_MCL_CB  *p_mcb;
+    UNUSED(p_cb);
 
     if (bta_hl_find_mcl_idx_using_handle(p_data->api_cch_close.mcl_handle, &app_idx,  &mcl_idx))
     {
@@ -961,10 +963,11 @@
     tBTA_HL_STATUS              status = BTA_HL_STATUS_OK;
     UINT8                       app_idx, mcl_idx, mdl_idx;
     tBTA_HL_APP_CB              *p_acb;
-    tBTA_HL_MCL_CB              *p_mcb;
+    tBTA_HL_MCL_CB              *p_mcb = NULL;
     tBTA_HL_MDL_CB              *p_dcb;
     tBTA_HL_MDEP_CFG            *p_mdep_cfg;
     UINT8                       mdep_cfg_idx;
+    UNUSED(p_cb);
 
     if (bta_hl_find_mcl_idx_using_handle(p_data->api_dch_open.mcl_handle, &app_idx, &mcl_idx))
     {
@@ -1116,7 +1119,7 @@
     tBTA_HL_APP_CB  *p_acb;
     tBTA_HL_MCL_CB  *p_mcb;
     tBTA_HL_MDL_CB  *p_dcb;
-
+    UNUSED(p_cb);
 
     if (bta_hl_find_mdl_idx_using_handle(p_data->api_dch_close.mdl_handle, &app_idx, &mcl_idx, &mdl_idx ))
     {
@@ -1183,11 +1186,12 @@
     tBTA_HL_STATUS  status = BTA_HL_STATUS_OK;
     UINT8           app_idx, mcl_idx, mdl_idx;
     tBTA_HL_APP_CB  *p_acb;
-    tBTA_HL_MCL_CB  *p_mcb;
+    tBTA_HL_MCL_CB  *p_mcb = NULL;
     tBTA_HL_MDL_CB  *p_dcb;
     UINT8           mdep_cfg_idx;
     UINT8           mdl_cfg_idx;
     tBTA_HL_MDEP_CFG            *p_mdep_cfg;
+    UNUSED(p_cb);
 
     if (bta_hl_find_mcl_idx_using_handle(p_data->api_dch_reconnect.mcl_handle, &app_idx, &mcl_idx))
     {
@@ -1323,10 +1327,10 @@
     tBTA_HL_STATUS      status = BTA_HL_STATUS_OK;
     UINT8               app_idx, mcl_idx, mdl_idx;
     tBTA_HL_APP_CB      *p_acb;
-    tBTA_HL_MCL_CB      *p_mcb;
+    tBTA_HL_MCL_CB      *p_mcb = NULL;
     tBTA_HL_MDL_CB      *p_dcb;
     tBTA_HL_ECHO_CFG    *p_echo_cfg;
-
+    UNUSED(p_cb);
 
     if (bta_hl_find_mcl_idx_using_handle(p_data->api_dch_echo_test.mcl_handle, &app_idx,  &mcl_idx))
     {
@@ -1457,7 +1461,7 @@
     UINT8           app_idx, mcl_idx;
     tBTA_HL_APP_CB  *p_acb;
     tBTA_HL_MCL_CB  *p_mcb;
-
+    UNUSED(p_cb);
 
     if (bta_hl_find_app_idx_using_handle(p_data->api_sdp_query.app_handle, &app_idx))
     {
@@ -1564,6 +1568,7 @@
     tBTA_HL_SDP_OPER    sdp_oper;
     UINT16              event;
     BOOLEAN             release_sdp_buf=FALSE;
+    UNUSED(p_cb);
 
     event = p_data->hdr.event;
     sdp_oper = p_mcb->sdp_oper;
@@ -1638,6 +1643,7 @@
     UINT8           app_idx, mcl_idx;
     tBTA_HL_APP_CB  *p_acb;
     tBTA_HL_MCL_CB  *p_mcb;
+    UNUSED(p_cb);
 
     if (bta_hl_find_mcl_idx_using_handle(p_data->api_delete_mdl.mcl_handle, &app_idx, &mcl_idx ))
     {
@@ -1728,6 +1734,7 @@
     tBTA_HL_MCL_CB  *p_mcb;
     BOOLEAN         send_cfm_evt = TRUE;
     tBTA_HL_APP_CB  *p_acb;
+    UNUSED(p_cb);
 
     if (bta_hl_find_mcl_idx_using_handle(p_data->mca_evt.mcl_handle, &app_idx, &mcl_idx))
     {
@@ -1805,8 +1812,9 @@
     tMCA_EVT_HDR    *p_delete_ind = &p_data->mca_evt.mca_data.delete_ind;
     tBTA_HL_MCL_CB  *p_mcb;
     tBTA_HL_MDL_CB  *p_dcb;
-    BOOLEAN         send_ind_evt = TRUE;
+    BOOLEAN         send_ind_evt = FALSE;
     tBTA_HL_APP_CB  *p_acb;
+    UNUSED(p_cb);
 
     if (bta_hl_find_mcl_idx_using_handle(p_data->mca_evt.mcl_handle, &app_idx, &mcl_idx) )
     {
@@ -1862,14 +1870,13 @@
 *******************************************************************************/
 static void bta_hl_api_dch_abort(tBTA_HL_CB *p_cb, tBTA_HL_DATA *p_data)
 {
-
     tBTA_HL_STATUS  status = BTA_HL_STATUS_OK;
     UINT8           app_idx, mcl_idx, mdl_idx;
     tBTA_HL_APP_CB  *p_acb;
     tBTA_HL_MCL_CB  *p_mcb;
     tBTA_HL_MDL_CB  *p_dcb;
     tBTA_HL         evt_data;
-
+    UNUSED(p_cb);
 
     if (bta_hl_find_mcl_idx_using_handle(p_data->api_dch_abort.mcl_handle, &app_idx, &mcl_idx ))
     {
diff --git a/bta/hl/bta_hl_sdp.c b/bta/hl/bta_hl_sdp.c
index 22dd70a..43d22d2 100644
--- a/bta/hl/bta_hl_sdp.c
+++ b/bta/hl/bta_hl_sdp.c
@@ -23,7 +23,7 @@
 
 #include "sdp_api.h"
 #include "bta_hl_int.h"
-
+#include "utl.h"
 
 /*******************************************************************************
 **
@@ -164,11 +164,7 @@
 **
 **  Purpose:     Register an HDP application with SDP
 **
-**  Parameters:  p_cb           - Pointer to MA instance control block
-**               p_service_name - MA server name
-**               inst_id        - MAS instance ID
-**               msg_type       - Supported message type(s)
-**
+**  Parameters:
 **
 **  Returns:     void
 **
@@ -189,6 +185,7 @@
     tBTA_HL_APP_CB                  *p_cb = BTA_HL_GET_APP_CB_PTR(0);
     BOOLEAN                         result = TRUE;
     tBTA_HL_STATUS                  status = BTA_HL_STATUS_OK;
+    UNUSED(app_id);
 
     if ((p_cb->sup_feature.app_role_mask == BTA_HL_MDEP_ROLE_MASK_SOURCE) &&
         (!p_cb->sup_feature.advertize_source_sdp))
diff --git a/bta/hl/bta_hl_utils.c b/bta/hl/bta_hl_utils.c
index 2fc6a6f..6a08b74 100644
--- a/bta/hl/bta_hl_utils.c
+++ b/bta/hl/bta_hl_utils.c
@@ -53,6 +53,7 @@
 {
     tBTA_HL_MCL_CB *p_mcb  = BTA_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
     BOOLEAN success = TRUE, update_ctrl_psm = FALSE;
+    UNUSED(mdl_idx);
 
     if (p_mcb->sdp.num_recs)
     {
@@ -1353,7 +1354,7 @@
 **
 ** Function      bta_hl_find_mdl_cfg_idx
 **
-** Description  This function finds an available MDL configiration index
+** Description  This function finds an available MDL configuration index
 **
 ** Returns      BOOLEAN - TRUE found
 **                        FALSE not found
@@ -1367,7 +1368,7 @@
     BOOLEAN             found=FALSE;
     UINT8               first_mdl_cfg_idx, second_mdl_cfg_idx, older_mdl_cfg_idx;
     BOOLEAN             done;
-
+    UNUSED(mcl_idx);
 
     for (i=0; i< BTA_HL_NUM_MDL_CFGS; i++)
     {
diff --git a/bta/include/bta_gatt_api.h b/bta/include/bta_gatt_api.h
index 7c974c5..b53b180 100644
--- a/bta/include/bta_gatt_api.h
+++ b/bta/include/bta_gatt_api.h
@@ -29,10 +29,10 @@
 #include "gatt_api.h"
 
 #ifndef     BTA_GATT_INCLUDED
+#warning BTA_GATT_INCLUDED not defined
 #define     BTA_GATT_INCLUDED     FALSE
 #endif
 
-
 #if ((BLE_INCLUDED == FALSE) && (BTA_GATT_INCLUDED == TRUE))
 #undef BTA_GATT_INCLUDED
 #define BTA_GATT_INCLUDED        FALSE
@@ -116,6 +116,7 @@
 #define BTA_GATTC_SRVC_CHG_EVT      15  /* service change event */
 #define BTA_GATTC_LISTEN_EVT        16  /* listen event */
 #define BTA_GATTC_ENC_CMPL_CB_EVT   17  /* encryption complete callback event */
+#define BTA_GATTC_CFG_MTU_EVT       18  /* configure MTU complete event */
 
 typedef UINT8 tBTA_GATTC_EVT;
 
@@ -311,6 +312,12 @@
     tBTA_GATT_SRVC_ID   service_uuid;
 }tBTA_GATTC_SRVC_RES;
 
+typedef struct
+{
+    UINT16              conn_id;
+    tBTA_GATT_STATUS    status;
+    UINT16              mtu;
+}tBTA_GATTC_CFG_MTU;
 
 typedef struct
 {
@@ -318,6 +325,7 @@
     UINT16              conn_id;
     tBTA_GATTC_IF       client_if;
     BD_ADDR             remote_bda;
+    UINT16              mtu;
 }tBTA_GATTC_OPEN;
 
 typedef struct
@@ -371,6 +379,7 @@
     tBTA_GATTC_NOTIFY       notify;           /* notification/indication event data */
     tBTA_GATTC_ENC_CMPL_CB  enc_cmpl;
     BD_ADDR                 remote_bda;     /* service change event */
+    tBTA_GATTC_CFG_MTU      cfg_mtu;        /* configure MTU operation */
 } tBTA_GATTC;
 
 /* GATTC enable callback function */
@@ -1046,6 +1055,21 @@
 
 
 /*******************************************************************************
+**
+** Function         BTA_GATTC_ConfigureMTU
+**
+** Description      Configure the MTU size in the GATT channel. This can be done
+**                  only once per connection.
+**
+** Parameters       conn_id: connection ID.
+**                  mtu: desired MTU size to use.
+**
+** Returns          void
+**
+*******************************************************************************/
+BTA_API extern void BTA_GATTC_ConfigureMTU (UINT16 conn_id, UINT16 mtu);
+
+/*******************************************************************************
 **  BTA GATT Server API
 ********************************************************************************/
 
diff --git a/bta/include/utl.h b/bta/include/utl.h
index df08b5a..e26cded 100644
--- a/bta/include/utl.h
+++ b/bta/include/utl.h
@@ -25,6 +25,7 @@
 #define UTL_H
 
 #include "data_types.h"
+#include "bt_utils.h"
 
 /*****************************************************************************
 **  Constants
diff --git a/bta/jv/bta_jv_act.c b/bta/jv/bta_jv_act.c
index ea1c9d7..dd09ca7 100644
--- a/bta/jv/bta_jv_act.c
+++ b/bta/jv/bta_jv_act.c
@@ -379,6 +379,7 @@
 *******************************************************************************/
 tBTA_JV_STATUS bta_jv_free_l2c_cb(tBTA_JV_L2C_CB *p_cb)
 {
+    UNUSED(p_cb);
 #if 0
     tBTA_JV_STATUS status = BTA_JV_SUCCESS;
 
@@ -733,6 +734,8 @@
 *******************************************************************************/
 void bta_jv_disable (tBTA_JV_MSG *p_data)
 {
+    UNUSED(p_data);
+
     APPL_TRACE_ERROR0("bta_jv_disable not used");
 #if 0
     int i;
@@ -823,6 +826,8 @@
 *******************************************************************************/
 void bta_jv_get_local_device_addr(tBTA_JV_MSG *p_data)
 {
+    UNUSED(p_data);
+
     BTM_ReadLocalDeviceAddr((tBTM_CMPL_CB *)bta_jv_get_local_device_addr_cback);
 }
 
@@ -839,6 +844,7 @@
 {
     tBTA_JV evt_data;
     char *name;
+    UNUSED(p_data);
 
     BTM_ReadLocalDeviceName(&name);
     evt_data.p_name = (UINT8*)name;
@@ -896,6 +902,8 @@
 *******************************************************************************/
 static void bta_jv_sec_cback (BD_ADDR bd_addr, void *p_ref_data, tBTM_STATUS result)
 {
+    UNUSED(p_ref_data);
+
     tBTA_JV_SET_ENCRYPTION  set_enc;
     if(bta_jv_cb.p_dm_cback)
     {
@@ -932,6 +940,7 @@
 *******************************************************************************/
 void bta_jv_get_scn(tBTA_JV_MSG *p_data)
 {
+    UNUSED(p_data);
 #if 0
     UINT8   scn;
     scn = BTM_AllocateSCN();
@@ -967,7 +976,7 @@
     static uint8_t bt_base_uuid[] =
        {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB };
 
-    logu("in, uuid:", u);
+    logu("in, uuid:", u->uu.uuid128);
     APPL_TRACE_DEBUG1("uuid len:%d", u->len);
     if(u->len == 16)
     {
@@ -1144,6 +1153,7 @@
 *******************************************************************************/
 void bta_jv_get_services_length(tBTA_JV_MSG *p_data)
 {
+    UNUSED(p_data);
 #if 0
     tBTA_JV_SERVICES_LEN    evt_data;
     UINT8   *p, *np, *op, type;
@@ -1201,6 +1211,7 @@
 *******************************************************************************/
 void bta_jv_service_select(tBTA_JV_MSG *p_data)
 {
+    UNUSED(p_data);
 #if 0
     tBTA_JV_SERVICE_SEL     serv_sel;
     tSDP_DISC_REC *p_rec, *p_tmp;
@@ -1283,6 +1294,7 @@
 *******************************************************************************/
 void bta_jv_update_record(tBTA_JV_MSG *p_data)
 {
+    UNUSED(p_data);
 #if 0
     tBTA_JV_API_UPDATE_RECORD *ur = &(p_data->update_record);
     tBTA_JV_UPDATE_RECORD   evt_data;
@@ -1346,6 +1358,7 @@
 *******************************************************************************/
 void bta_jv_add_attribute(tBTA_JV_MSG *p_data)
 {
+    UNUSED(p_data);
 #if 0
     tBTA_JV_API_ADD_ATTRIBUTE *aa = &(p_data->add_attr);
     tBTA_JV_ADD_ATTR   evt_data;
@@ -1392,6 +1405,7 @@
 *******************************************************************************/
 void bta_jv_delete_attribute(tBTA_JV_MSG *p_data)
 {
+    UNUSED(p_data);
 #if 0
     tBTA_JV_API_ADD_ATTRIBUTE *da = &(p_data->add_attr);
     tBTA_JV_DELETE_ATTR   evt_data;
@@ -1444,6 +1458,8 @@
 *******************************************************************************/
 static void bta_jv_l2cap_client_cback(UINT16 gap_handle, UINT16 event)
 {
+    UNUSED(gap_handle);
+    UNUSED(event);
 #if 0
     tBTA_JV_L2C_CB  *p_cb = &bta_jv_cb.l2c_cb[gap_handle];
     tBTA_JV     evt_data;
@@ -1573,6 +1589,7 @@
 *******************************************************************************/
 void bta_jv_l2cap_connect(tBTA_JV_MSG *p_data)
 {
+    UNUSED(p_data);
 #if 0
     tBTA_JV_L2C_CB      *p_cb;
     tBTA_JV_L2CAP_CL_INIT  evt_data;
@@ -1648,6 +1665,7 @@
 *******************************************************************************/
 void bta_jv_l2cap_close(tBTA_JV_MSG *p_data)
 {
+    UNUSED(p_data);
 #if 0
     tBTA_JV_L2CAP_CLOSE  evt_data;
     tBTA_JV_API_L2CAP_CLOSE *cc = &(p_data->l2cap_close);
@@ -1675,6 +1693,8 @@
 *******************************************************************************/
 static void bta_jv_l2cap_server_cback(UINT16 gap_handle, UINT16 event)
 {
+    UNUSED(gap_handle);
+    UNUSED(event);
 #if 0
     tBTA_JV_L2C_CB  *p_cb = &bta_jv_cb.l2c_cb[gap_handle];
     tBTA_JV evt_data;
@@ -1734,6 +1754,7 @@
 *******************************************************************************/
 void bta_jv_l2cap_start_server(tBTA_JV_MSG *p_data)
 {
+    UNUSED(p_data);
 #if 0
     tBTA_JV_L2C_CB      *p_cb;
     UINT8   sec_id;
@@ -1800,6 +1821,7 @@
 *******************************************************************************/
 void bta_jv_l2cap_stop_server(tBTA_JV_MSG *p_data)
 {
+    UNUSED(p_data);
 #if 0
     tBTA_JV_L2C_CB      *p_cb;
     tBTA_JV_L2CAP_CLOSE  evt_data;
@@ -1834,6 +1856,7 @@
 *******************************************************************************/
 void bta_jv_l2cap_read(tBTA_JV_MSG *p_data)
 {
+    UNUSED(p_data);
 #if 0
     tBTA_JV_L2CAP_READ evt_data;
     tBTA_JV_API_L2CAP_READ *rc = &(p_data->l2cap_read);
@@ -1877,6 +1900,7 @@
 *******************************************************************************/
 void bta_jv_l2cap_write(tBTA_JV_MSG *p_data)
 {
+    UNUSED(p_data);
 #if 0
     tBTA_JV_L2CAP_WRITE evt_data;
     tBTA_JV_API_L2CAP_WRITE *ls = &(p_data->l2cap_write);
@@ -1939,14 +1963,18 @@
 {
     tBTA_JV_RFC_CB  *p_cb = bta_jv_rfc_port_to_cb(port_handle);
     tBTA_JV_PCB     *p_pcb = bta_jv_rfc_port_to_pcb(port_handle);
-    APPL_TRACE_DEBUG3("bta_jv_port_data_co_cback, p_cb:%p, p_pcb:%p, len:%d",
-                        p_cb, p_pcb, len);
+    int ret = 0;
+    APPL_TRACE_DEBUG4("bta_jv_port_data_co_cback, p_cb:%p, p_pcb:%p, len:%d, type:%d",
+                        p_cb, p_pcb, len, type);
     if (p_pcb != NULL)
     {
         switch(type)
         {
             case DATA_CO_CALLBACK_TYPE_INCOMING:
-                return bta_co_rfc_data_incoming(p_pcb->user_data, (BT_HDR*)buf);
+                bta_jv_pm_conn_busy(p_pcb->p_pm_cb);
+                ret = bta_co_rfc_data_incoming(p_pcb->user_data, (BT_HDR*)buf);
+                bta_jv_pm_conn_idle(p_pcb->p_pm_cb);
+                return ret;
             case DATA_CO_CALLBACK_TYPE_OUTGOING_SIZE:
                 return bta_co_rfc_data_outgoing_size(p_pcb->user_data, (int*)buf);
             case DATA_CO_CALLBACK_TYPE_OUTGOING:
diff --git a/bta/jv/bta_jv_api.c b/bta/jv/bta_jv_api.c
index 1ee9924..16ab2d5 100644
--- a/bta/jv/bta_jv_api.c
+++ b/bta/jv/bta_jv_api.c
@@ -31,6 +31,7 @@
 #include <string.h>
 #include "port_api.h"
 #include "sdp_api.h"
+#include "utl.h"
 
 /*****************************************************************************
 **  Constants
@@ -714,6 +715,8 @@
 *******************************************************************************/
 INT32 BTA_JvGetServicesResult(BOOLEAN inc_hdr, UINT8 **TLVs)
 {
+    UNUSED(inc_hdr);
+    UNUSED(TLVs);
 #if 0
     INT32 num_services = -1;
     UINT8   *p, *np, *op, type;
@@ -860,6 +863,11 @@
 tBTA_JV_STATUS BTA_JvUpdateRecord(UINT32 handle, UINT16 *p_ids,
     UINT8 **p_values, INT32 *p_value_sizes, INT32 array_len)
 {
+    UNUSED(handle);
+    UNUSED(p_ids);
+    UNUSED(p_values);
+    UNUSED(p_value_sizes);
+    UNUSED(array_len);
 #if 0
     tBTA_JV_STATUS status = BTA_JV_FAILURE;
     tBTA_JV_API_UPDATE_RECORD *p_msg;
@@ -1145,6 +1153,11 @@
 *******************************************************************************/
 tBTA_JV_STATUS BTA_JvL2capRead(UINT32 handle, UINT32 req_id, UINT8 *p_data, UINT16 len)
 {
+    UNUSED(handle);
+    UNUSED(req_id);
+    UNUSED(p_data);
+    UNUSED(len);
+
 #if 0
     tBTA_JV_STATUS status = BTA_JV_FAILURE;
 #if SDP_FOR_JV_INCLUDED == TRUE
@@ -1208,6 +1221,10 @@
 *******************************************************************************/
 tBTA_JV_STATUS BTA_JvL2capReceive(UINT32 handle, UINT32 req_id, UINT8 *p_data, UINT16 len)
 {
+    UNUSED(handle);
+    UNUSED(req_id);
+    UNUSED(p_data);
+    UNUSED(len);
 #if 0
     tBTA_JV_STATUS status = BTA_JV_FAILURE;
     tBTA_JV_L2CAP_RECEIVE evt_data;
@@ -1256,6 +1273,8 @@
 *******************************************************************************/
 tBTA_JV_STATUS BTA_JvL2capReady(UINT32 handle, UINT32 *p_data_size)
 {
+    UNUSED(handle);
+    UNUSED(p_data_size);
 #if 0
     tBTA_JV_STATUS status = BTA_JV_FAILURE;
 
diff --git a/bta/pan/bta_pan_act.c b/bta/pan/bta_pan_act.c
index b29920f..d0939d6 100644
--- a/bta/pan/bta_pan_act.c
+++ b/bta/pan/bta_pan_act.c
@@ -35,6 +35,7 @@
 #include "bta_pan_int.h"
 #include "bta_pan_co.h"
 #include <string.h>
+#include "utl.h"
 
 
 /* RX and TX data flow mask */
@@ -456,6 +457,8 @@
         bta_pan_scb_dealloc(p_scb);
         bdcpy(data.bd_addr, p_data->api_open.bd_addr);
         data.status = BTA_PAN_FAIL;
+        data.local_role = p_data->api_open.local_role;
+        data.peer_role = p_data->api_open.peer_role;
         bta_pan_cb.p_cback(BTA_PAN_OPEN_EVT, (tBTA_PAN *)&data);
     }
 
@@ -476,6 +479,7 @@
 void bta_pan_api_close (tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data)
 {
     tBTA_PAN_CONN * p_buf;
+    UNUSED(p_data);
 
     PAN_Disconnect (p_scb->handle);
 
@@ -586,6 +590,8 @@
 *******************************************************************************/
 void bta_pan_rx_path(tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data)
 {
+    UNUSED(p_data);
+
     /* if data path configured for rx pull */
     if ((bta_pan_cb.flow_mask & BTA_PAN_RX_MASK) == BTA_PAN_RX_PULL)
     {
@@ -615,8 +621,9 @@
 *******************************************************************************/
 void bta_pan_tx_path(tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data)
 {
-
     BT_HDR * p_buf;
+    UNUSED(p_data);
+
     /* if data path configured for tx pull */
     if ((bta_pan_cb.flow_mask & BTA_PAN_TX_MASK) == BTA_PAN_TX_PULL)
     {
@@ -720,6 +727,7 @@
 *******************************************************************************/
 void bta_pan_free_buf(tBTA_PAN_SCB *p_scb, tBTA_PAN_DATA *p_data)
 {
+    UNUSED(p_scb);
 
     GKI_freebuf(p_data);
 
diff --git a/bta/pan/bta_pan_api.c b/bta/pan/bta_pan_api.c
index 6588230..17ae6a7 100644
--- a/bta/pan/bta_pan_api.c
+++ b/bta/pan/bta_pan_api.c
@@ -25,8 +25,6 @@
 
 #include "bt_target.h"
 
-#if defined(BTA_PAN_INCLUDED) && (BTA_PAN_INCLUDED == TRUE)
-
 #include "bta_api.h"
 #include "bta_sys.h"
 #include "pan_api.h"
@@ -35,6 +33,9 @@
 #include "bta_pan_int.h"
 #include "bd.h"
 #include <string.h>
+#include "bt_utils.h"
+
+#if defined(BTA_PAN_INCLUDED) && (BTA_PAN_INCLUDED == TRUE)
 
 static const tBTA_SYS_REG bta_pan_reg =
 {
@@ -211,4 +212,36 @@
         bta_sys_sendmsg(p_buf);
     }
 }
+#else
+
+void BTA_PanEnable(tBTA_PAN_CBACK p_cback)
+{
+    UNUSED(p_cback);
+}
+
+void BTA_PanDisable(void)
+{
+}
+
+void BTA_PanSetRole(tBTA_PAN_ROLE role, tBTA_PAN_ROLE_INFO *p_user_info, tBTA_PAN_ROLE_INFO *p_gn_info,
+                    tBTA_PAN_ROLE_INFO *p_nap_info)
+{
+    UNUSED(role);
+    UNUSED(p_user_info);
+    UNUSED(p_gn_info);
+    UNUSED(p_nap_info);
+}
+
+void BTA_PanOpen(BD_ADDR bd_addr, tBTA_PAN_ROLE local_role, tBTA_PAN_ROLE peer_role)
+{
+    UNUSED(bd_addr);
+    UNUSED(local_role);
+    UNUSED(peer_role);
+}
+
+void BTA_PanClose(UINT16 handle)
+{
+    UNUSED(handle);
+}
+
 #endif /* BTA_PAN_INCLUDED */
diff --git a/bta/pan/bta_pan_ci.c b/bta/pan/bta_pan_ci.c
index f8e5832..7e67477 100644
--- a/bta/pan/bta_pan_ci.c
+++ b/bta/pan/bta_pan_ci.c
@@ -24,8 +24,6 @@
 
 #include "bt_target.h"
 
-#if defined(BTA_PAN_INCLUDED) && (BTA_PAN_INCLUDED == TRUE)
-
 #include <string.h>
 
 #include "gki.h"
@@ -35,7 +33,9 @@
 #include "bta_pan_api.h"
 #include "bta_pan_ci.h"
 #include "bta_pan_int.h"
+#include "bt_utils.h"
 
+#if defined(BTA_PAN_INCLUDED) && (BTA_PAN_INCLUDED == TRUE)
 
 /*******************************************************************************
 **
@@ -256,5 +256,61 @@
     PAN_SetProtocolFilters(handle, num_filters, p_start_array, p_end_array );
 
 }
+#else
+
+void bta_pan_ci_tx_ready(UINT16 handle)
+{
+    UNUSED(handle);
+}
+
+void bta_pan_ci_rx_ready(UINT16 handle)
+{
+    UNUSED(handle);
+}
+
+void bta_pan_ci_tx_flow(UINT16 handle, BOOLEAN enable)
+{
+    UNUSED(handle);
+    UNUSED(enable);
+}
+
+void bta_pan_ci_rx_writebuf(UINT16 handle, BD_ADDR src, BD_ADDR dst, UINT16 protocol, BT_HDR *p_buf, BOOLEAN ext)
+{
+    UNUSED(handle);
+    UNUSED(src);
+    UNUSED(dst);
+    UNUSED(protocol);
+    UNUSED(p_buf);
+    UNUSED(ext);
+}
+
+BT_HDR * bta_pan_ci_readbuf(UINT16 handle, BD_ADDR src, BD_ADDR dst, UINT16 *p_protocol,
+                            BOOLEAN* p_ext, BOOLEAN* p_forward)
+{
+    UNUSED(handle);
+    UNUSED(src);
+    UNUSED(dst);
+    UNUSED(p_protocol);
+    UNUSED(p_ext);
+    UNUSED(p_forward);
+    return NULL;
+}
+
+void bta_pan_ci_set_pfilters(UINT16 handle, UINT16 num_filters, UINT16 *p_start_array, UINT16 *p_end_array)
+{
+    UNUSED(handle);
+    UNUSED(num_filters);
+    UNUSED(p_start_array);
+    UNUSED(p_end_array);
+}
+
+void bta_pan_ci_set_mfilters(UINT16 handle, UINT16 num_mcast_filters, UINT8 *p_start_array,
+                             UINT8 *p_end_array)
+{
+    UNUSED(handle);
+    UNUSED(num_mcast_filters);
+    UNUSED(p_start_array);
+    UNUSED(p_end_array);
+}
 
 #endif /* BTA_PAN_API */
diff --git a/bta/pan/bta_pan_main.c b/bta/pan/bta_pan_main.c
index add1c7c..5ed545f 100644
--- a/bta/pan/bta_pan_main.c
+++ b/bta/pan/bta_pan_main.c
@@ -34,6 +34,7 @@
 #include "bta_pan_api.h"
 #include "bta_pan_int.h"
 #include "bd.h"
+#include "utl.h"
 
 /*****************************************************************************
 ** Constants and types
@@ -265,6 +266,8 @@
 *******************************************************************************/
 static void bta_pan_api_disable(tBTA_PAN_DATA *p_data)
 {
+    UNUSED(p_data);
+
     bta_pan_disable();
 }
 
diff --git a/bta/sys/bta_sys_conn.c b/bta/sys/bta_sys_conn.c
index b495085..a5d1017 100644
--- a/bta/sys/bta_sys_conn.c
+++ b/bta/sys/bta_sys_conn.c
@@ -26,7 +26,7 @@
 #include "bta_sys.h"
 #include "bta_sys_int.h"
 #include "gki.h"
-
+#include "utl.h"
 
 /*******************************************************************************
 **
@@ -349,6 +349,8 @@
 *******************************************************************************/
 void bta_sys_sco_use(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
 {
+    UNUSED(id);
+
     /* AV streaming need to be suspended before SCO is connected. */
     if(bta_sys_cb.p_sco_cb)
     {
@@ -370,6 +372,7 @@
 void bta_sys_sco_unuse(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
 {
     UINT8 num_sco_links;
+    UNUSED(id);
 
     if((bta_sys_cb.p_sco_cb))
     {
diff --git a/bta/sys/bta_sys_main.c b/bta/sys/bta_sys_main.c
index 59fbdd7..a440f52 100644
--- a/bta/sys/bta_sys_main.c
+++ b/bta/sys/bta_sys_main.c
@@ -44,6 +44,7 @@
 #if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
 #include "bta_ar_api.h"
 #endif
+#include "utl.h"
 
 /* protocol timer update period, in milliseconds */
 #ifndef BTA_SYS_TIMER_PERIOD
@@ -295,8 +296,8 @@
 *******************************************************************************/
 void bta_sys_hw_error(tBTA_SYS_HW_MSG *p_sys_hw_msg)
 {
-
     UINT8 module_index;
+    UNUSED(p_sys_hw_msg);
 
     APPL_TRACE_DEBUG1("%s", __FUNCTION__);
 
@@ -455,7 +456,7 @@
 **
 ** Function         bta_sys_hw_event_stack_enabled
 **
-** Description     we receive this event from once the SW side is ready ( stack, FW download,... ),
+** Description     we receive this event once the SW side is ready ( stack, FW download,... ),
 **                       i.e. we can really start using the device. So notify the app.
 **
 ** Returns          success or failure
@@ -464,6 +465,7 @@
 void bta_sys_hw_evt_stack_enabled(tBTA_SYS_HW_MSG *p_sys_hw_msg)
 {
     UINT8 hw_module_index;
+    UNUSED(p_sys_hw_msg);
 
     APPL_TRACE_DEBUG0(" bta_sys_hw_evt_stack_enabled!notify the callers");
 
diff --git a/btif/co/bta_ag_co.c b/btif/co/bta_ag_co.c
index cd969f8..9c6de7d 100644
--- a/btif/co/bta_ag_co.c
+++ b/btif/co/bta_ag_co.c
@@ -21,6 +21,7 @@
 #include "bta_ag_api.h"
 #include "bta_ag_co.h"
 #include "bte_appl.h"
+#include "bt_utils.h"
 
 #define LOG_TAG "BTA_AG_CO: "
 
@@ -74,6 +75,7 @@
 *******************************************************************************/
 void bta_ag_co_audio_state(UINT16 handle, UINT8 app_id, UINT8 state)
 {
+    UNUSED(app_id);
     BTIF_TRACE_DEBUG2("bta_ag_co_audio_state: handle %d, state %d", handle, state);
 }
 
@@ -127,6 +129,7 @@
  *******************************************************************************/
 void bta_ag_co_tx_write(UINT16 handle, UINT8 * p_data, UINT16 len)
 {
-   BTIF_TRACE_DEBUG2( "bta_ag_co_tx_write: handle: %d, len: %d", handle, len );
+    UNUSED(p_data);
+    BTIF_TRACE_DEBUG2( "bta_ag_co_tx_write: handle: %d, len: %d", handle, len );
 }
 
diff --git a/btif/co/bta_av_co.c b/btif/co/bta_av_co.c
index 6089532..fecf621 100644
--- a/btif/co/bta_av_co.c
+++ b/btif/co/bta_av_co.c
@@ -35,6 +35,7 @@
 #include "btif_media.h"
 #include "sbc_encoder.h"
 #include "btif_av_co.h"
+#include "btif_util.h"
 
 
 /*****************************************************************************
@@ -516,6 +517,8 @@
     UINT8 status = A2D_SUCCESS;
     UINT8 category = A2D_SUCCESS;
     BOOLEAN recfg_needed = FALSE;
+    UNUSED(seid);
+    UNUSED(addr);
 
     FUNC_TRACE();
 
@@ -645,6 +648,7 @@
         UINT16 mtu)
 {
     tBTA_AV_CO_PEER *p_peer;
+    UNUSED(p_codec_info);
 
     FUNC_TRACE();
 
@@ -678,6 +682,8 @@
 
 {
     tBTA_AV_CO_PEER *p_peer;
+    UNUSED(codec_type);
+    UNUSED(mtu);
 
     FUNC_TRACE();
 
@@ -713,6 +719,11 @@
 BTA_API void bta_av_co_audio_start(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
         UINT8 *p_codec_info, BOOLEAN *p_no_rtp_hdr)
 {
+    UNUSED(hndl);
+    UNUSED(codec_type);
+    UNUSED(p_codec_info);
+    UNUSED(p_no_rtp_hdr);
+
     FUNC_TRACE();
 
     APPL_TRACE_DEBUG0("bta_av_co_audio_start");
@@ -732,6 +743,9 @@
  *******************************************************************************/
 BTA_API extern void bta_av_co_audio_stop(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type)
 {
+    UNUSED(hndl);
+    UNUSED(codec_type);
+
     FUNC_TRACE();
 
     APPL_TRACE_DEBUG0("bta_av_co_audio_stop");
@@ -751,6 +765,8 @@
         UINT32 *p_timestamp)
 {
     BT_HDR *p_buf;
+    UNUSED(p_len);
+
     FUNC_TRACE();
 
     p_buf = btif_media_aa_readbuf();
diff --git a/btif/co/bta_dm_co.c b/btif/co/bta_dm_co.c
index fd91817..13a5c8f 100644
--- a/btif/co/bta_dm_co.c
+++ b/btif/co/bta_dm_co.c
@@ -22,6 +22,7 @@
 #include "bta_sys.h"
 #include "bta_dm_co.h"
 #include "bta_dm_ci.h"
+#include "bt_utils.h"
 #if (BTM_OOB_INCLUDED == TRUE)
 #include "btif_dm.h"
 #endif
@@ -46,6 +47,9 @@
 *******************************************************************************/
 BOOLEAN bta_dm_co_get_compress_memory(tBTA_SYS_ID id, UINT8 **memory_p, UINT32 *memory_size)
 {
+    UNUSED(id);
+    UNUSED(memory_p);
+    UNUSED(memory_size);
     return TRUE;
 }
 
@@ -67,6 +71,7 @@
 void bta_dm_co_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap, tBTA_OOB_DATA *p_oob_data,
                       tBTA_AUTH_REQ *p_auth_req, BOOLEAN is_orig)
 {
+    UNUSED(bd_addr);
 #if (BTM_OOB_INCLUDED == TRUE)
     btif_dm_set_oob_for_io_req(p_oob_data);
 #endif
@@ -94,6 +99,10 @@
 void bta_dm_co_io_rsp(BD_ADDR bd_addr, tBTA_IO_CAP io_cap,
                       tBTA_OOB_DATA oob_data, tBTA_AUTH_REQ auth_req)
 {
+    UNUSED(bd_addr);
+    UNUSED(io_cap);
+    UNUSED(oob_data);
+    UNUSED(auth_req);
 }
 
 /*******************************************************************************
@@ -111,6 +120,8 @@
 *******************************************************************************/
 void  bta_dm_co_lk_upgrade(BD_ADDR bd_addr, BOOLEAN *p_upgrade )
 {
+    UNUSED(bd_addr);
+    UNUSED(p_upgrade);
 }
 
 #if (BTM_OOB_INCLUDED == TRUE)
@@ -334,6 +345,7 @@
                              tBTA_LE_KEY_TYPE *p_init_key,
                              tBTA_LE_KEY_TYPE  *p_resp_key )
 {
+    UNUSED(bd_addr);
     BTIF_TRACE_ERROR0("##################################");
     BTIF_TRACE_ERROR0("bta_dm_co_le_io_key_req: only setting max size to 16");
     BTIF_TRACE_ERROR0("##################################");
@@ -389,6 +401,7 @@
                           tBTA_LE_KEY_TYPE *p_init_key,
                           tBTA_LE_KEY_TYPE  *p_resp_key )
 {
+    UNUSED(bd_addr);
     /* if OOB is not supported, this call-out function does not need to do anything
      * otherwise, look for the OOB data associated with the address and set *p_oob_data accordingly
      * If the answer can not be obtained right away,
diff --git a/btif/co/bta_fs_co.c b/btif/co/bta_fs_co.c
index ffc146b..958fef5 100644
--- a/btif/co/bta_fs_co.c
+++ b/btif/co/bta_fs_co.c
@@ -30,6 +30,7 @@
 #include "bta_fs_co.h"
 #include "bta_fs_ci.h"
 #include <inttypes.h>
+#include "bt_utils.h"
 
 #ifndef AID_SYSTEM
 #define AID_SYSTEM        1000
@@ -248,12 +249,12 @@
  *******************************************************************************/
 static int btapp_fs_check_space( const char *p_path, const UINT32 size, const UINT8 app_id )
 {
-
     unsigned long long max_space;
     struct statfs fs_buffer;
     int err = 0;
     char *p_dir;
     char *p_end;
+    UNUSED(app_id);
 
     if(size==BTA_FS_LEN_UNKNOWN)
         return 0;
@@ -455,6 +456,7 @@
     tBTA_FS_CO_STATUS  status = BTA_FS_CO_OK;
     INT32   num_read;
     int     err;
+    UNUSED(ssn);
 
     if ((num_read = read (fd, p_buf, nbytes)) < 0)
     {
@@ -500,6 +502,8 @@
     tBTA_FS_CO_STATUS  status = BTA_FS_CO_OK;
     INT32   num_written;
     int     err=0;
+    UNUSED(ssn);
+    UNUSED(app_id);
 
     if ((num_written = write (fd, p_buf, nbytes)) < 0)
     {
@@ -528,6 +532,7 @@
 *******************************************************************************/
 void bta_fs_co_seek (int fd, INT32 offset, INT16 origin, UINT8 app_id)
 {
+    UNUSED(app_id);
     lseek(fd, offset, origin);
 }
 
@@ -559,6 +564,7 @@
     int os_mode = 0;
     tBTA_FS_CO_STATUS status = BTA_FS_CO_OK;
     struct stat buffer;
+    UNUSED(app_id);
 
     #if (TRUE==BTA_FS_DEBUG)
     LOGI("***********CHECKING ACCESS TO = %s", p_path);
@@ -776,6 +782,7 @@
     tBTA_FS_CO_STATUS status = BTA_FS_CO_OK;
     char *dirName, *tmp=NULL;
     struct stat buffer;
+    UNUSED(app_id);
 
     if(! p_path)
         return BTA_FS_CO_FAIL;
@@ -856,6 +863,7 @@
     struct dirent *dirent;
     struct stat buf;
     char fullname[500];
+    UNUSED(app_id);
 
     BTIF_TRACE_DEBUG0("Entered bta_fs_co_getdirentry");
 
@@ -978,6 +986,9 @@
 *******************************************************************************/
 void bta_fs_co_setdir(const char *p_path, UINT8 app_id)
 {
+    UNUSED(p_path);
+    UNUSED(app_id);
+
     BTIF_TRACE_DEBUG2("Entered %s. New path: %s", __FUNCTION__, p_path);
 }
 
@@ -1006,6 +1017,9 @@
 *******************************************************************************/
 void bta_fs_co_resume(UINT16 evt, UINT8 app_id)
 {
+    UNUSED(evt);
+    UNUSED(app_id);
+
     BTIF_TRACE_WARNING0("[CO] bta_fs_co_resume - NOT implemented");
 }
 
@@ -1031,6 +1045,11 @@
 *******************************************************************************/
 void bta_fs_co_set_perms(const char *p_src_path,  UINT8 *p_perms, UINT16 evt, UINT8 app_id)
 {
+    UNUSED(p_src_path);
+    UNUSED(p_perms);
+    UNUSED(evt);
+    UNUSED(app_id);
+
     BTIF_TRACE_WARNING0("[CO] bta_fs_co_set_perms - NOT implemented");
 }
 
@@ -1057,6 +1076,12 @@
 *******************************************************************************/
 void bta_fs_co_rename(const char *p_src_path, const char *p_dest_path, UINT8 *p_perms, UINT16 evt, UINT8 app_id)
 {
+    UNUSED(p_src_path);
+    UNUSED(p_dest_path);
+    UNUSED(p_perms);
+    UNUSED(evt);
+    UNUSED(app_id);
+
     BTIF_TRACE_WARNING0("[CO] bta_fs_co_rename - NOT implemented");
 }
 
@@ -1085,6 +1110,12 @@
 *******************************************************************************/
 void bta_fs_co_copy(const char *p_src_path, const char *p_dest_path, UINT8 *p_perms, UINT16 evt, UINT8 app_id)
 {
+    UNUSED(p_src_path);
+    UNUSED(p_dest_path);
+    UNUSED(p_perms);
+    UNUSED(evt);
+    UNUSED(app_id);
+
     BTIF_TRACE_WARNING0("[CO] bta_fs_co_copy - NOT implemented");
 }
 
@@ -1106,6 +1137,10 @@
 *******************************************************************************/
 void bta_fs_co_resume_op(UINT32 offset, UINT16 evt, UINT8 app_id)
 {
+    UNUSED(offset);
+    UNUSED(evt);
+    UNUSED(app_id);
+
     BTIF_TRACE_WARNING0("[CO] bta_fs_co_resume_op - NOT implemented");
 }
 
@@ -1129,6 +1164,14 @@
 void bta_fs_co_session_info(BD_ADDR bd_addr, UINT8 *p_sess_info, UINT8 ssn,
                                            tBTA_FS_CO_SESS_ST new_st, char *p_path, UINT8 *p_info, UINT8 app_id)
 {
+    UNUSED(bd_addr);
+    UNUSED(p_sess_info);
+    UNUSED(ssn);
+    UNUSED(new_st);
+    UNUSED(p_path);
+    UNUSED(p_info);
+    UNUSED(app_id);
+
     BTIF_TRACE_WARNING0("[CO] bta_fs_co_session_info - NOT implemented");
 }
 
@@ -1154,6 +1197,14 @@
 void bta_fs_co_suspend(BD_ADDR bd_addr, UINT8 *p_sess_info, UINT8 ssn,
                                       UINT32 *p_timeout, UINT32 *p_offset, UINT8 info, UINT8 app_id)
 {
+    UNUSED(bd_addr);
+    UNUSED(p_sess_info);
+    UNUSED(ssn);
+    UNUSED(p_timeout);
+    UNUSED(p_offset);
+    UNUSED(info);
+    UNUSED(app_id);
+
     BTIF_TRACE_WARNING0("[CO] bta_fs_co_suspend - NOT implemented");
 }
 
@@ -1176,6 +1227,10 @@
 *******************************************************************************/
 void bta_fs_co_sess_ssn(int fd, UINT8 ssn, UINT8 app_id)
 {
+    UNUSED(fd);
+    UNUSED(ssn);
+    UNUSED(app_id);
+
     BTIF_TRACE_WARNING0("[CO] bta_fs_co_suspend - NOT implemented");
 }
 
diff --git a/btif/co/bta_gattc_co.c b/btif/co/bta_gattc_co.c
index 1a71d69..29fbb09 100644
--- a/btif/co/bta_gattc_co.c
+++ b/btif/co/bta_gattc_co.c
@@ -20,6 +20,7 @@
 #include "gki.h"
 #include "bta_gattc_co.h"
 #include "bta_gattc_ci.h"
+#include "btif_util.h"
 
 #if( defined BLE_INCLUDED ) && (BLE_INCLUDED == TRUE)
 #if( defined BTA_GATT_INCLUDED ) && (BTA_GATT_INCLUDED == TRUE)
@@ -47,6 +48,7 @@
 void bta_gattc_co_cache_open(BD_ADDR server_bda, UINT16 evt, UINT16 conn_id, BOOLEAN to_save)
 {
     tBTA_GATT_STATUS    status = BTA_GATT_OK;
+    UNUSED(to_save);
 
     /* open NV cache and send call in */
     bta_gattc_ci_cache_open(server_bda, evt, status, conn_id);
@@ -72,6 +74,7 @@
     UINT16              num_attr = 0;
     tBTA_GATTC_NV_ATTR  attr[BTA_GATTC_NV_LOAD_MAX];
     tBTA_GATT_STATUS    status = BTA_GATT_MORE;
+    UNUSED(start_index);
 
     bta_gattc_ci_cache_load(server_bda, evt, num_attr, attr, status, conn_id);
 }
@@ -95,6 +98,9 @@
                               tBTA_GATTC_NV_ATTR *p_attr_list, UINT16 attr_index, UINT16 conn_id)
 {
     tBTA_GATT_STATUS    status = BTA_GATT_OK;
+    UNUSED(num_attr);
+    UNUSED(p_attr_list);
+    UNUSED(attr_index);
 
     bta_gattc_ci_cache_save(server_bda, evt, status, conn_id);
 }
@@ -114,6 +120,8 @@
 *******************************************************************************/
 void bta_gattc_co_cache_close(BD_ADDR server_bda, UINT16 conn_id)
 {
+    UNUSED(server_bda);
+    UNUSED(conn_id);
     /* close NV when server cache is done saving or loading,
        does not need to do anything for now on Insight */
 }
@@ -132,6 +140,7 @@
 *******************************************************************************/
 void bta_gattc_co_cache_reset(BD_ADDR server_bda)
 {
+    UNUSED(server_bda);
 }
 
 #endif
diff --git a/btif/co/bta_gatts_co.c b/btif/co/bta_gatts_co.c
index 16b0450..d030075 100644
--- a/btif/co/bta_gatts_co.c
+++ b/btif/co/bta_gatts_co.c
@@ -25,6 +25,7 @@
 #include "gki.h"
 #include "bd.h"
 #include "bta_gatts_co.h"
+#include "btif_util.h"
 
 /*****************************************************************************
 **  Local type definitions
@@ -202,6 +203,8 @@
 *******************************************************************************/
 void bta_gatts_co_update_handle_range(BOOLEAN is_add, tBTA_GATTS_HNDL_RANGE *p_hndl_range)
 {
+    UNUSED(is_add);
+    UNUSED(p_hndl_range);
 }
 
 /*******************************************************************************
@@ -225,6 +228,10 @@
                              tBTA_GATTS_SRV_CHG_REQ *p_req,
                              tBTA_GATTS_SRV_CHG_RSP *p_rsp)
 {
+    UNUSED(cmd);
+    UNUSED(p_req);
+    UNUSED(p_rsp);
+
     return FALSE;
 }
 
@@ -243,7 +250,10 @@
 BOOLEAN bta_gatts_co_load_handle_range(UINT8 index,
                                        tBTA_GATTS_HNDL_RANGE *p_handle_range)
 {
-   return FALSE;
+    UNUSED(index);
+    UNUSED(p_handle_range);
+
+    return FALSE;
 }
 #endif
 #endif
diff --git a/btif/co/bta_hh_co.c b/btif/co/bta_hh_co.c
index 51edcd4..b393099 100644
--- a/btif/co/bta_hh_co.c
+++ b/btif/co/bta_hh_co.c
@@ -30,7 +30,7 @@
 #include "btif_hh.h"
 #include "bta_api.h"
 #include "bta_hh_api.h"
-
+#include "btif_util.h"
 
 
 const char *dev_path = "/dev/uhid";
@@ -365,6 +365,7 @@
                     UINT8 sub_class, UINT8 ctry_code, BD_ADDR peer_addr, UINT8 app_id)
 {
     btif_hh_device_t *p_dev;
+    UNUSED(peer_addr);
 
     APPL_TRACE_DEBUG6("%s: dev_handle = %d, subclass = 0x%02X, mode = %d, "
          "ctry_code = %d, app_id = %d",
@@ -419,6 +420,11 @@
     memset(&ev, 0, sizeof(ev));
     ev.type = UHID_CREATE;
     strncpy((char*)ev.u.create.name, dev_name, sizeof(ev.u.create.name) - 1);
+    snprintf((char*)ev.u.create.uniq, sizeof(ev.u.create.uniq),
+             "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
+             p_dev->bd_addr.address[5], p_dev->bd_addr.address[4],
+             p_dev->bd_addr.address[3], p_dev->bd_addr.address[2],
+             p_dev->bd_addr.address[1], p_dev->bd_addr.address[0]);
     ev.u.create.rd_size = dscp_len;
     ev.u.create.rd_data = p_dscp;
     ev.u.create.bus = BUS_BLUETOOTH;
diff --git a/btif/co/bta_hl_co.c b/btif/co/bta_hl_co.c
index 2713da1..1432974 100644
--- a/btif/co/bta_hl_co.c
+++ b/btif/co/bta_hl_co.c
@@ -42,7 +42,7 @@
 #include "bta_hl_co.h"
 #include "bta_hl_ci.h"
 #include "btif_hl.h"
-
+#include "btif_util.h"
 
 
 /*****************************************************************************
@@ -427,6 +427,9 @@
                               UINT16 buf_size, UINT8 *p_buf,  UINT16 evt)
 {
     tBTA_HL_STATUS status = BTA_HL_STATUS_FAIL;
+    UNUSED(app_id);
+    UNUSED(buf_size);
+    UNUSED(p_buf);
 
     BTIF_TRACE_ERROR1("%s not supported",__FUNCTION__);
     bta_hl_ci_get_echo_data(mcl_handle,  status, evt);
@@ -453,6 +456,9 @@
                               UINT16 data_size, UINT8 *p_data, UINT16 evt)
 {
     tBTA_HL_STATUS status = BTA_HL_STATUS_FAIL;
+    UNUSED(app_id);
+    UNUSED(data_size);
+    UNUSED(p_data);
 
     BTIF_TRACE_ERROR1("%s not supported",__FUNCTION__);
     bta_hl_ci_put_echo_data(mcl_handle,  status, evt);
diff --git a/btif/co/bta_pan_co.c b/btif/co/bta_pan_co.c
index c6310d4..1dcce8e 100644
--- a/btif/co/bta_pan_co.c
+++ b/btif/co/bta_pan_co.c
@@ -35,7 +35,7 @@
 #include "btif_pan_internal.h"
 #include "bd.h"
 #include <string.h>
-
+#include "btif_util.h"
 
 /*******************************************************************************
 **
@@ -218,6 +218,9 @@
 *******************************************************************************/
 void bta_pan_co_rx_path(UINT16 handle, UINT8 app_id)
 {
+    UNUSED(handle);
+    UNUSED(app_id);
+
     BTIF_TRACE_API0("bta_pan_co_rx_path not used");
 }
 
@@ -238,7 +241,17 @@
                                 UINT16 protocol, UINT8 *p_data,
                                 UINT16 len, BOOLEAN ext, BOOLEAN forward)
 {
-     BTIF_TRACE_API0("bta_pan_co_tx_write not used");
+    UNUSED(handle);
+    UNUSED(app_id);
+    UNUSED(src);
+    UNUSED(dst);
+    UNUSED(protocol);
+    UNUSED(p_data);
+    UNUSED(len);
+    UNUSED(ext);
+    UNUSED(forward);
+
+    BTIF_TRACE_API0("bta_pan_co_tx_write not used");
 }
 
 /*******************************************************************************
@@ -258,6 +271,15 @@
                                     BD_ADDR dst, UINT16 protocol, BT_HDR *p_buf,
                                     BOOLEAN ext, BOOLEAN forward)
 {
+    UNUSED(handle);
+    UNUSED(app_id);
+    UNUSED(src);
+    UNUSED(dst);
+    UNUSED(protocol);
+    UNUSED(p_buf);
+    UNUSED(ext);
+    UNUSED(forward);
+
     BTIF_TRACE_API0("bta_pan_co_tx_writebuf not used");
 }
 
@@ -277,6 +299,10 @@
 *******************************************************************************/
 void bta_pan_co_rx_flow(UINT16 handle, UINT8 app_id, BOOLEAN enable)
 {
+    UNUSED(handle);
+    UNUSED(app_id);
+    UNUSED(enable);
+
     BTIF_TRACE_API1("bta_pan_co_rx_flow, enabled:%d, not used", enable);
 }
 
@@ -292,6 +318,12 @@
 void bta_pan_co_pfilt_ind(UINT16 handle, BOOLEAN indication, tBTA_PAN_STATUS result,
                                     UINT16 len, UINT8 *p_filters)
 {
+    UNUSED(handle);
+    UNUSED(indication);
+    UNUSED(result);
+    UNUSED(len);
+    UNUSED(p_filters);
+
     BTIF_TRACE_API0("bta_pan_co_pfilt_ind");
 }
 
@@ -307,6 +339,12 @@
 void bta_pan_co_mfilt_ind(UINT16 handle, BOOLEAN indication, tBTA_PAN_STATUS result,
                                     UINT16 len, UINT8 *p_filters)
 {
+    UNUSED(handle);
+    UNUSED(indication);
+    UNUSED(result);
+    UNUSED(len);
+    UNUSED(p_filters);
+
     BTIF_TRACE_API0("bta_pan_co_mfilt_ind");
 }
 
diff --git a/btif/include/btif_hh.h b/btif/include/btif_hh.h
index d864ec4..7edba74 100644
--- a/btif/include/btif_hh.h
+++ b/btif/include/btif_hh.h
@@ -63,7 +63,6 @@
     UINT8                         sub_class;
     UINT8                         app_id;
     int                           fd;
-    BT_HDR                        *p_buf;
     UINT32                        hh_poll_thread_id;
     UINT8                         hh_keep_polling;
     BOOLEAN                       vup_timer_active;
diff --git a/btif/include/btif_storage.h b/btif/include/btif_storage.h
index 951b376..9a69b00 100644
--- a/btif/include/btif_storage.h
+++ b/btif/include/btif_storage.h
@@ -237,7 +237,8 @@
                                                     UINT16 attr_mask, UINT8 sub_class,
                                                     UINT8 app_id, UINT16 vendor_id,
                                                     UINT16 product_id, UINT16 version,
-                                                    UINT8 ctry_code, UINT16 dl_len, UINT8 *dsc_list);
+                                                    UINT8 ctry_code, UINT16 ssr_max_latency,
+                                                    UINT16 ssr_min_tout, UINT16 dl_len, UINT8 *dsc_list);
 
 /*******************************************************************************
 **
diff --git a/btif/include/btif_util.h b/btif/include/btif_util.h
index 30bff69..95969dd 100755
--- a/btif/include/btif_util.h
+++ b/btif/include/btif_util.h
@@ -26,6 +26,7 @@
 
 #include "data_types.h"
 #include "bt_types.h"
+#include "bt_utils.h"
 
 /*******************************************************************************
 **  Constants & Macros
diff --git a/btif/src/bluetooth.c b/btif/src/bluetooth.c
index aa42dbc..f6c2f48 100755
--- a/btif/src/bluetooth.c
+++ b/btif/src/bluetooth.c
@@ -68,6 +68,8 @@
 **  Externs
 ************************************************************************************/
 
+extern bt_wakelock_callback config_wakelock_callback;
+
 /* list all extended interfaces here */
 
 /* handsfree profile */
@@ -82,8 +84,10 @@
 extern bthl_interface_t *btif_hl_get_interface();
 /*pan*/
 extern btpan_interface_t *btif_pan_get_interface();
+#if BLE_INCLUDED == TRUE
 /* gatt */
 extern btgatt_interface_t *btif_gatt_get_interface();
+#endif
 /* avrc */
 extern btrc_interface_t *btif_rc_get_interface();
 
@@ -117,6 +121,7 @@
 
     /* store reference to user callbacks */
     bt_hal_cbacks = callbacks;
+    config_wakelock_callback = callbacks->bt_wakelock_cb;
 
     /* add checks for individual callbacks ? */
 
@@ -423,13 +428,16 @@
 
 static int close_bluetooth_stack(struct hw_device_t* device)
 {
+    UNUSED(device);
     cleanup();
     return 0;
 }
 
 static int open_bluetooth_stack (const struct hw_module_t* module, char const* name,
-struct hw_device_t** abstraction)
+                                 struct hw_device_t** abstraction)
 {
+    UNUSED(name);
+
     bluetooth_device_t *stack = malloc(sizeof(bluetooth_device_t) );
     memset(stack, 0, sizeof(bluetooth_device_t) );
     stack->common.tag = HARDWARE_DEVICE_TAG;
diff --git a/btif/src/btif_av.c b/btif/src/btif_av.c
index f173f6a..3c0c293 100755
--- a/btif/src/btif_av.c
+++ b/btif/src/btif_av.c
@@ -201,6 +201,7 @@
 static void btif_initiate_av_open_tmr_hdlr(TIMER_LIST_ENT *tle)
 {
     BD_ADDR peer_addr;
+    UNUSED(tle);
 
     /* is there at least one RC connection - There should be */
     if (btif_rc_get_connected_peer(peer_addr)) {
diff --git a/btif/src/btif_config.c b/btif/src/btif_config.c
index 8b36a11..e7809a7 100644
--- a/btif/src/btif_config.c
+++ b/btif/src/btif_config.c
@@ -49,6 +49,7 @@
 #include "btif_config_util.h"
 #include "btif_sock_thread.h"
 #include "btif_sock_util.h"
+#include "btif_util.h"
 
 //#define UNIT_TEST
 #define CFG_PATH "/data/misc/bluedroid/"
@@ -781,6 +782,10 @@
 }
 static void cfg_cmd_callback(int cmd_fd, int type, int size, uint32_t user_id)
 {
+    UNUSED(cmd_fd);
+    UNUSED(size);
+    UNUSED(user_id);
+
   //bdld("cmd type:%d, size:%d", type, size);
     switch(type)
     {
diff --git a/btif/src/btif_config_util.cpp b/btif/src/btif_config_util.cpp
index 885f5c2..0cc2b36 100644
--- a/btif/src/btif_config_util.cpp
+++ b/btif/src/btif_config_util.cpp
@@ -470,6 +470,8 @@
     {
         error("open_file_map fail, fd:%d, path:%s, size:%d", fd, path, size);
         //debug("out");
+        if (fd >= 0)
+            close(fd);
         return FALSE;
     }
     //get local bt device name from bluez config
@@ -539,6 +541,8 @@
     {
         error("open_file_map fail, fd:%d, path:%s, size:%d", fd, path, size);
         //debug("out");
+        if (fd >= 0)
+            close(fd);
         return FALSE;
     }
     int line_size = 0;
@@ -597,6 +601,8 @@
     {
         error("open_file_map fail, fd:%d, path:%s, size:%d", fd, path, size);
         //debug("out");
+        if (fd >= 0)
+            close(fd);
         return FALSE;
     }
     int pos = 0;
diff --git a/btif/src/btif_core.c b/btif/src/btif_core.c
index 9504c3c..5fcee4e 100644
--- a/btif/src/btif_core.c
+++ b/btif/src/btif_core.c
@@ -275,6 +275,7 @@
 {
     UINT16   event;
     BT_HDR   *p_msg;
+    UNUSED(params);
 
     BTIF_TRACE_DEBUG0("btif task starting");
 
@@ -606,9 +607,6 @@
     /* callback to HAL */
     if (status == BTA_SUCCESS)
     {
-        /* initialize a2dp service */
-        btif_av_init();
-
         /* init rfcomm & l2cap api */
         btif_sock_init();
 
@@ -821,6 +819,7 @@
 *******************************************************************************/
 static void btif_dut_mode_cback( tBTM_VSC_CMPL *p )
 {
+    UNUSED(p);
     /* For now nothing to be done. */
 }
 
diff --git a/btif/src/btif_dm.c b/btif/src/btif_dm.c
index ccf136f..f907b67 100644
--- a/btif/src/btif_dm.c
+++ b/btif/src/btif_dm.c
@@ -1947,6 +1947,25 @@
 
 /*******************************************************************************
 **
+** Function         btif_dm_hh_open_failed
+**
+** Description      informs the upper layers if the HH have failed during bonding
+**
+** Returns          none
+**
+*******************************************************************************/
+
+void btif_dm_hh_open_failed(bt_bdaddr_t *bdaddr)
+{
+    if (pairing_cb.state == BT_BOND_STATE_BONDING &&
+            bdcmp(bdaddr->address, pairing_cb.bd_addr) == 0)
+    {
+        bond_state_changed(BT_STATUS_FAIL, bdaddr, BT_BOND_STATE_NONE);
+    }
+}
+
+/*******************************************************************************
+**
 ** Function         btif_dm_remove_bond
 **
 ** Description      Removes bonding with the specified device
@@ -2021,11 +2040,12 @@
 ** Returns          bt_status_t
 **
 *******************************************************************************/
-
 bt_status_t btif_dm_ssp_reply(const bt_bdaddr_t *bd_addr,
                                  bt_ssp_variant_t variant, uint8_t accept,
                                  uint32_t passkey)
 {
+    UNUSED(passkey);
+
     if (variant == BT_SSP_VARIANT_PASSKEY_ENTRY)
     {
         /* This is not implemented in the stack.
diff --git a/btif/src/btif_gatt_client.c b/btif/src/btif_gatt_client.c
index 6aab986..c788bd8 100644
--- a/btif/src/btif_gatt_client.c
+++ b/btif/src/btif_gatt_client.c
@@ -90,7 +90,8 @@
     BTIF_GATTC_REFRESH,
     BTIF_GATTC_READ_RSSI,
     BTIF_GATTC_LISTEN,
-    BTIF_GATTC_SET_ADV_DATA
+    BTIF_GATTC_SET_ADV_DATA,
+    BTIF_GATTC_CONFIGURE_MTU,
 } btif_gattc_event_t;
 
 #define BTIF_GATT_MAX_OBSERVED_DEV 40
@@ -438,6 +439,12 @@
             HAL_CBACK(bt_gatt_callbacks, client->open_cb, p_data->open.conn_id
                 , p_data->open.status, p_data->open.client_if, &bda);
 
+            if (GATT_DEF_BLE_MTU_SIZE != p_data->open.mtu && p_data->open.mtu)
+            {
+                HAL_CBACK(bt_gatt_callbacks, client->configure_mtu_cb, p_data->open.conn_id
+                    , p_data->open.status , p_data->open.mtu);
+            }
+
             if (p_data->open.status == BTA_GATT_OK)
                 btif_gatt_check_encrypted_link(p_data->open.remote_bda);
             break;
@@ -510,6 +517,14 @@
             );
             break;
         }
+
+        case BTA_GATTC_CFG_MTU_EVT:
+        {
+            HAL_CBACK(bt_gatt_callbacks, client->configure_mtu_cb, p_data->cfg_mtu.conn_id
+                , p_data->cfg_mtu.status , p_data->cfg_mtu.mtu);
+            break;
+        }
+
         default:
             ALOGE("%s: Unhandled event (%d)!", __FUNCTION__, event);
             break;
@@ -840,7 +855,7 @@
             break;
 
         case BTIF_GATTC_LISTEN:
-#ifdef BLE_PERIPHERAL_MODE_SUPPORT
+#if (defined(BLE_PERIPHERAL_MODE_SUPPORT) && (BLE_PERIPHERAL_MODE_SUPPORT == TRUE))
             BTA_GATTC_Listen(p_cb->client_if, p_cb->start, NULL);
 #else
             BTA_GATTC_Broadcast(p_cb->client_if, p_cb->start);
@@ -882,6 +897,9 @@
 
             break;
         }
+        case BTIF_GATTC_CONFIGURE_MTU:
+            BTA_GATTC_ConfigureMTU(p_cb->conn_id, p_cb->len);
+            break;
 
         default:
             ALOGE("%s: Unknown event (%d)!", __FUNCTION__, event);
@@ -1108,6 +1126,10 @@
         }
     }
 
+#if (defined(BLE_PERIPHERAL_ADV_NAME) && (BLE_PERIPHERAL_ADV_NAME == TRUE))
+    btif_cb.adv_data.mask |= BTM_BLE_AD_BIT_DEV_NAME;
+#endif
+
     return btif_transfer_context(btgattc_handle_event, BTIF_GATTC_SET_ADV_DATA,
                                  (char*) &btif_cb, sizeof(btif_gattc_cb_t), NULL);
 }
@@ -1302,6 +1324,16 @@
                                  (char*) &btif_cb, sizeof(btif_gattc_cb_t), NULL);
 }
 
+static bt_status_t btif_gattc_configure_mtu(int conn_id, int mtu)
+{
+    CHECK_BTGATT_INIT();
+    btif_gattc_cb_t btif_cb;
+    btif_cb.conn_id = conn_id;
+    btif_cb.len = mtu; // Re-use len field
+    return btif_transfer_context(btgattc_handle_event, BTIF_GATTC_CONFIGURE_MTU,
+                                 (char*) &btif_cb, sizeof(btif_gattc_cb_t), NULL);
+}
+
 static int btif_gattc_get_device_type( const bt_bdaddr_t *bd_addr )
 {
     int device_type = 0;
@@ -1343,6 +1375,7 @@
     btif_gattc_read_remote_rssi,
     btif_gattc_get_device_type,
     btif_gattc_set_adv_data,
+    btif_gattc_configure_mtu,
     btif_gattc_test_command
 };
 
diff --git a/btif/src/btif_gatt_test.c b/btif/src/btif_gatt_test.c
index 2a316fe..a2cca6a 100644
--- a/btif/src/btif_gatt_test.c
+++ b/btif/src/btif_gatt_test.c
@@ -103,6 +103,10 @@
 static void btif_test_connect_cback(tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id,
                                     BOOLEAN connected, tGATT_DISCONN_REASON reason)
 {
+    UNUSED(gatt_if);
+    UNUSED(bda);
+    UNUSED(reason);
+
     ALOGD("%s: conn_id=%d, connected=%d", __FUNCTION__, conn_id, connected);
     test_cb.conn_id = connected ? conn_id : 0;
 }
@@ -137,6 +141,7 @@
                                            tGATT_DISC_RES *p_data)
 {
     char    str_buf[50];
+    UNUSED(conn_id);
 
     ALOGD("------ GATT Discovery result %-22s -------", disc_name[disc_type]);
     ALOGD("      Attribute handle: 0x%04x (%d)", p_data->handle, p_data->handle);
@@ -188,6 +193,8 @@
                                                tGATT_DISC_TYPE disc_type,
                                                tGATT_STATUS status)
 {
+    UNUSED(conn_id);
+    UNUSED(disc_type);
     ALOGD("%s: status=%d", __FUNCTION__, status);
 }
 
diff --git a/btif/src/btif_gatt_util.c b/btif/src/btif_gatt_util.c
index ab56f99..715dcd6 100644
--- a/btif/src/btif_gatt_util.c
+++ b/btif/src/btif_gatt_util.c
@@ -271,7 +271,7 @@
 
 static void btif_gatt_set_encryption_cb (BD_ADDR bd_addr, tBTA_STATUS result)
 {
-    if (result != BTA_SUCCESS)
+    if (result != BTA_SUCCESS && result != BTA_BUSY)
     {
         bt_bdaddr_t bda;
         bdcpy(bda.address, bd_addr);
@@ -291,8 +291,10 @@
                     buf, sizeof(btif_dm_ble_penc_keys_t)) == BT_STATUS_SUCCESS)
         && !btif_gatt_is_link_encrypted(bd_addr))
     {
+#if (!defined(BLE_DELAY_REQUEST_ENC) || (BLE_DELAY_REQUEST_ENC == FALSE))
         BTA_DmSetEncryption(bd_addr,
                             &btif_gatt_set_encryption_cb, BTM_BLE_SEC_ENCRYPT);
+#endif
     }
 }
 
diff --git a/btif/src/btif_hf.c b/btif/src/btif_hf.c
index 7688e68..b4ade0d 100644
--- a/btif/src/btif_hf.c
+++ b/btif/src/btif_hf.c
@@ -452,6 +452,8 @@
 *******************************************************************************/
 static void btif_in_hf_generic_evt(UINT16 event, char *p_param)
 {
+    UNUSED(p_param);
+
     BTIF_TRACE_EVENT2("%s: event=%d", __FUNCTION__, event);
     switch (event) {
         case BTIF_HFP_CB_AUDIO_CONNECTING:
diff --git a/btif/src/btif_hh.c b/btif/src/btif_hh.c
index 8eeddfc..34b119d 100644
--- a/btif/src/btif_hh.c
+++ b/btif/src/btif_hh.c
@@ -159,6 +159,7 @@
 extern void btif_dm_cb_remove_bond(bt_bdaddr_t *bd_addr);
 extern BOOLEAN check_cod_hid(const bt_bdaddr_t *remote_bdaddr, uint32_t cod);
 extern int  scru_ascii_2_hex(char *p_ascii, int len, UINT8 *p_hex);
+extern void btif_dm_hh_open_failed(bt_bdaddr_t *bdaddr);
 
 /*****************************************************************************
 **  Local Function prototypes
@@ -248,6 +249,29 @@
 
 /*******************************************************************************
 **
+** Function         create_pbuf
+**
+** Description      Helper function to create p_buf for send_data or set_report
+**
+*******************************************************************************/
+static BT_HDR *create_pbuf(UINT16 len, UINT8 *data)
+{
+    BT_HDR* p_buf = GKI_getbuf((UINT16) (len + BTA_HH_MIN_OFFSET + sizeof(BT_HDR)));
+
+    if (p_buf) {
+        UINT8* pbuf_data;
+
+        p_buf->len = len;
+        p_buf->offset = BTA_HH_MIN_OFFSET;
+
+        pbuf_data = (UINT8*) (p_buf + 1) + p_buf->offset;
+        memcpy(pbuf_data, data, len);
+    }
+    return p_buf;
+}
+
+/*******************************************************************************
+**
 ** Function         update_keyboard_lockstates
 **
 ** Description      Sends a report to the keyboard to set the lock states of keys
@@ -257,30 +281,20 @@
 {
     UINT8 len = 2;  /* reportid + 1 byte report*/
     BD_ADDR* bda;
+    BT_HDR* p_buf;
+    UINT8 data[] = {0x01, /* report id */
+                    btif_hh_keylockstates}; /* keystate */
 
     /* Set report for other keyboards */
     BTIF_TRACE_EVENT3("%s: setting report on dev_handle %d to 0x%x",
          __FUNCTION__, p_dev->dev_handle, btif_hh_keylockstates);
 
-    if (p_dev->p_buf != NULL) {
-        GKI_freebuf(p_dev->p_buf);
-    }
     /* Get SetReport buffer */
-    p_dev->p_buf = GKI_getbuf((UINT16) (len + BTA_HH_MIN_OFFSET +
-        sizeof(BT_HDR)));
-    if (p_dev->p_buf != NULL) {
-        p_dev->p_buf->len = len;
-        p_dev->p_buf->offset = BTA_HH_MIN_OFFSET;
-        p_dev->p_buf->layer_specific = BTA_HH_RPTT_OUTPUT;
-
-        /* LED status updated by data event */
-        UINT8 *pbuf_data  = (UINT8 *)(p_dev->p_buf + 1)
-            + p_dev->p_buf->offset;
-        pbuf_data[0]=0x01; /*report id */
-        pbuf_data[1]=btif_hh_keylockstates; /*keystate*/
+    p_buf = create_pbuf(len, data);
+    if (p_buf != NULL) {
+        p_buf->layer_specific = BTA_HH_RPTT_OUTPUT;
         bda = (BD_ADDR*) (&p_dev->bd_addr);
-        BTA_HhSendData(p_dev->dev_handle, *bda,
-            p_dev->p_buf);
+        BTA_HhSendData(p_dev->dev_handle, *bda, p_buf);
     }
 }
 
@@ -544,10 +558,6 @@
     else {
         BTIF_TRACE_WARNING1("%s: device_num = 0", __FUNCTION__);
     }
-    if (p_dev->p_buf != NULL) {
-        GKI_freebuf(p_dev->p_buf);
-        p_dev->p_buf = NULL;
-    }
 
     p_dev->hh_keep_polling = 0;
     p_dev->hh_poll_thread_id = -1;
@@ -719,35 +729,15 @@
 ** Returns          void
 **
 *******************************************************************************/
-
 void btif_hh_setreport(btif_hh_device_t *p_dev, bthh_report_type_t r_type, UINT16 size,
                             UINT8* report)
 {
-    UINT8  hexbuf[20];
-    UINT16 len = size;
-    int i = 0;
-    if (p_dev->p_buf != NULL) {
-        GKI_freebuf(p_dev->p_buf);
-    }
-    p_dev->p_buf = GKI_getbuf((UINT16) (len + BTA_HH_MIN_OFFSET + sizeof(BT_HDR)));
-    if (p_dev->p_buf == NULL) {
-        APPL_TRACE_ERROR2("%s: Error, failed to allocate RPT buffer, len = %d", __FUNCTION__, len);
+    BT_HDR* p_buf = create_pbuf(size, report);
+    if (p_buf == NULL) {
+        APPL_TRACE_ERROR2("%s: Error, failed to allocate RPT buffer, size = %d", __FUNCTION__, size);
         return;
     }
-
-    p_dev->p_buf->len = len;
-    p_dev->p_buf->offset = BTA_HH_MIN_OFFSET;
-
-    //Build a SetReport data buffer
-    memset(hexbuf, 0, 20);
-    for(i=0; i<len; i++)
-        hexbuf[i] = report[i];
-
-    UINT8* pbuf_data;
-    pbuf_data = (UINT8*) (p_dev->p_buf + 1) + p_dev->p_buf->offset;
-    memcpy(pbuf_data, hexbuf, len);
-    BTA_HhSetReport(p_dev->dev_handle, r_type, p_dev->p_buf);
-
+    BTA_HhSetReport(p_dev->dev_handle, r_type, p_buf);
 }
 
 /*****************************************************************************
@@ -845,6 +835,7 @@
             }
             else {
                 bt_bdaddr_t *bdaddr = (bt_bdaddr_t*)p_data->conn.bda;
+                btif_dm_hh_open_failed(bdaddr);
                 HAL_CBACK(bt_hh_callbacks, connection_state_cb, (bt_bdaddr_t*) &p_data->conn.bda,BTHH_CONN_STATE_DISCONNECTED);
                 btif_hh_cb.status = BTIF_HH_DEV_DISCONNECTED;
             }
@@ -855,12 +846,6 @@
             p_dev = btif_hh_find_connected_dev_by_handle(p_data->dev_status.handle);
             if (p_dev != NULL) {
                 BTIF_TRACE_DEBUG2("%s: uhid fd = %d", __FUNCTION__, p_dev->fd);
-                if (p_dev->fd >= 0){
-                    UINT8 hidreport[9];
-                    memset(hidreport,0,9);
-                    hidreport[0]=1;
-                    bta_hh_co_write(p_dev->fd , hidreport, sizeof(hidreport));
-                }
                 if(p_dev->vup_timer_active)
                 {
                     btif_hh_stop_vup_timer(&(p_dev->bd_addr));
@@ -876,22 +861,40 @@
                 BTIF_TRACE_WARNING1("Error: cannot find device with handle %d", p_data->dev_status.handle);
             }
             break;
-        case BTA_HH_GET_RPT_EVT:
+        case BTA_HH_GET_RPT_EVT: {
+            BT_HDR *hdr = p_data->hs_data.rsp_data.p_rpt_data;
+            UINT8 *data = NULL;
+            UINT16 len = 0;
+
             BTIF_TRACE_DEBUG2("BTA_HH_GET_RPT_EVT: status = %d, handle = %d",
                  p_data->hs_data.status, p_data->hs_data.handle);
-            p_dev = btif_hh_find_connected_dev_by_handle(p_data->conn.handle);
-            HAL_CBACK(bt_hh_callbacks, get_report_cb,(bt_bdaddr_t*) &(p_dev->bd_addr), (bthh_status_t) p_data->hs_data.status,
-                (uint8_t*) p_data->hs_data.rsp_data.p_rpt_data, BT_HDR_SIZE);
+            p_dev = btif_hh_find_connected_dev_by_handle(p_data->hs_data.handle);
+            if (p_dev) {
+                /* p_rpt_data is NULL in HANDSHAKE response case */
+                if (hdr) {
+                    data = (UINT8 *)(hdr + 1) + hdr->offset;
+                    len = hdr->len;
+                    HAL_CBACK(bt_hh_callbacks, get_report_cb,
+                              (bt_bdaddr_t*) &(p_dev->bd_addr),
+                              (bthh_status_t) p_data->hs_data.status, data, len);
+                } else {
+                    HAL_CBACK(bt_hh_callbacks, handshake_cb,
+                              (bt_bdaddr_t*) &(p_dev->bd_addr),
+                              (bthh_status_t) p_data->hs_data.status);
+                }
+            } else {
+                BTIF_TRACE_WARNING1("Error: cannot find device with handle %d", p_data->hs_data.handle);
+            }
             break;
-
+        }
         case BTA_HH_SET_RPT_EVT:
             BTIF_TRACE_DEBUG2("BTA_HH_SET_RPT_EVT: status = %d, handle = %d",
             p_data->dev_status.status, p_data->dev_status.handle);
             p_dev = btif_hh_find_connected_dev_by_handle(p_data->dev_status.handle);
-            if (p_dev != NULL && p_dev->p_buf != NULL) {
-                BTIF_TRACE_DEBUG0("Freeing buffer..." );
-                GKI_freebuf(p_dev->p_buf);
-                p_dev->p_buf = NULL;
+            if (p_dev != NULL) {
+                HAL_CBACK(bt_hh_callbacks, handshake_cb,
+                          (bt_bdaddr_t*) &(p_dev->bd_addr),
+                          (bthh_status_t) p_data->hs_data.status);
             }
             break;
 
@@ -902,13 +905,27 @@
                  p_data->hs_data.rsp_data.proto_mode,
                  (p_data->hs_data.rsp_data.proto_mode == BTA_HH_PROTO_RPT_MODE) ? "Report Mode" :
                  (p_data->hs_data.rsp_data.proto_mode == BTA_HH_PROTO_BOOT_MODE) ? "Boot Mode" : "Unsupported");
-            HAL_CBACK(bt_hh_callbacks, protocol_mode_cb,(bt_bdaddr_t*) &(p_dev->bd_addr), (bthh_status_t)p_data->hs_data.status,
-                             (bthh_protocol_mode_t) p_data->hs_data.rsp_data.proto_mode);
+            if (p_data->hs_data.rsp_data.proto_mode != BTA_HH_PROTO_UNKNOWN) {
+                HAL_CBACK(bt_hh_callbacks, protocol_mode_cb,
+                          (bt_bdaddr_t*) &(p_dev->bd_addr),
+                          (bthh_status_t)p_data->hs_data.status,
+                          (bthh_protocol_mode_t) p_data->hs_data.rsp_data.proto_mode);
+            } else {
+                HAL_CBACK(bt_hh_callbacks, handshake_cb,
+                          (bt_bdaddr_t*) &(p_dev->bd_addr),
+                          (bthh_status_t)p_data->hs_data.status);
+            }
             break;
 
         case BTA_HH_SET_PROTO_EVT:
             BTIF_TRACE_DEBUG2("BTA_HH_SET_PROTO_EVT: status = %d, handle = %d",
                  p_data->dev_status.status, p_data->dev_status.handle);
+            p_dev = btif_hh_find_connected_dev_by_handle(p_data->dev_status.handle);
+            if (p_dev) {
+                HAL_CBACK(bt_hh_callbacks, handshake_cb,
+                          (bt_bdaddr_t*)&(p_dev->bd_addr),
+                          (bthh_status_t)p_data->hs_data.status);
+            }
             break;
 
         case BTA_HH_GET_IDLE_EVT:
@@ -973,6 +990,7 @@
                     ret = btif_storage_add_hid_device_info(&(p_dev->bd_addr), p_dev->attr_mask,p_dev->sub_class,p_dev->app_id,
                                                         p_data->dscp_info.vendor_id, p_data->dscp_info.product_id,
                                                         p_data->dscp_info.version,   p_data->dscp_info.ctry_code,
+                                                        p_data->dscp_info.ssr_max_latency, p_data->dscp_info.ssr_min_tout,
                                                         len, p_data->dscp_info.descriptor.dsc_list);
 
                     ASSERTC(ret == BT_STATUS_SUCCESS, "storing hid info failed", ret);
@@ -1426,6 +1444,8 @@
 *******************************************************************************/
 static bt_status_t set_idle_time (bt_bdaddr_t *bd_addr, uint8_t idle_time)
 {
+    UNUSED(idle_time);
+
     CHECK_BTHH_INIT();
     btif_hh_device_t *p_dev;
     BD_ADDR* bda = (BD_ADDR*) bd_addr;
@@ -1464,6 +1484,7 @@
     CHECK_BTHH_INIT();
     btif_hh_device_t *p_dev;
     BD_ADDR* bda = (BD_ADDR*) bd_addr;
+    UNUSED(protocolMode);
 
     BTIF_TRACE_DEBUG6(" addr = %02X:%02X:%02X:%02X:%02X:%02X",
          (*bda)[0], (*bda)[1], (*bda)[2], (*bda)[3], (*bda)[4], (*bda)[5]);
@@ -1475,6 +1496,7 @@
 
     p_dev = btif_hh_find_connected_dev_by_bda(bd_addr);
     if (p_dev != NULL) {
+
         BTA_HhGetProtoMode(p_dev->dev_handle);
     }
     else {
@@ -1615,34 +1637,22 @@
         UINT8  hexbuf[200];
         UINT16 len = (strlen(report) + 1) / 2;
 
-        if (p_dev->p_buf != NULL) {
-            GKI_freebuf(p_dev->p_buf);
-        }
-        p_dev->p_buf = GKI_getbuf((UINT16) (len + BTA_HH_MIN_OFFSET + sizeof(BT_HDR)));
-        if (p_dev->p_buf == NULL) {
-            BTIF_TRACE_ERROR2("%s: Error, failed to allocate RPT buffer, len = %d", __FUNCTION__, len);
-            return BT_STATUS_FAIL;
-        }
-
-        p_dev->p_buf->len = len;
-        p_dev->p_buf->offset = BTA_HH_MIN_OFFSET;
-
         /* Build a SetReport data buffer */
         memset(hexbuf, 0, 200);
         //TODO
         hex_bytes_filled = ascii_2_hex(report, len, hexbuf);
-        ALOGI("Hex bytes filled, hex value: %d", hex_bytes_filled);
-
+        BTIF_TRACE_DEBUG1("Hex bytes filled, hex value: %d", hex_bytes_filled);
         if (hex_bytes_filled) {
-            UINT8* pbuf_data;
-            pbuf_data = (UINT8*) (p_dev->p_buf + 1) + p_dev->p_buf->offset;
-            memcpy(pbuf_data, hexbuf, hex_bytes_filled);
-            BTA_HhSetReport(p_dev->dev_handle, reportType, p_dev->p_buf);
+            BT_HDR* p_buf = create_pbuf(hex_bytes_filled, hexbuf);
+            if (p_buf == NULL) {
+                BTIF_TRACE_ERROR2("%s: Error, failed to allocate RPT buffer, len = %d",
+                                  __FUNCTION__, hex_bytes_filled);
+                return BT_STATUS_FAIL;
+            }
+            BTA_HhSetReport(p_dev->dev_handle, reportType, p_buf);
         }
         return BT_STATUS_SUCCESS;
     }
-
-
 }
 
 /*******************************************************************************
@@ -1682,29 +1692,20 @@
         UINT8  hexbuf[200];
         UINT16 len = (strlen(data) + 1) / 2;
 
-        if (p_dev->p_buf != NULL) {
-            GKI_freebuf(p_dev->p_buf);
-        }
-        p_dev->p_buf = GKI_getbuf((UINT16) (len + BTA_HH_MIN_OFFSET + sizeof(BT_HDR)));
-        if (p_dev->p_buf == NULL) {
-            BTIF_TRACE_ERROR2("%s: Error, failed to allocate RPT buffer, len = %d", __FUNCTION__, len);
-            return BT_STATUS_FAIL;
-        }
-
-        p_dev->p_buf->len = len;
-        p_dev->p_buf->offset = BTA_HH_MIN_OFFSET;
-
         /* Build a SetReport data buffer */
         memset(hexbuf, 0, 200);
         hex_bytes_filled = ascii_2_hex(data, len, hexbuf);
         BTIF_TRACE_ERROR2("Hex bytes filled, hex value: %d, %d", hex_bytes_filled, len);
 
         if (hex_bytes_filled) {
-            UINT8* pbuf_data;
-            pbuf_data = (UINT8*) (p_dev->p_buf + 1) + p_dev->p_buf->offset;
-            memcpy(pbuf_data, hexbuf, hex_bytes_filled);
-            p_dev->p_buf->layer_specific = BTA_HH_RPTT_OUTPUT;
-            BTA_HhSendData(p_dev->dev_handle, *bda, p_dev->p_buf);
+            BT_HDR* p_buf = create_pbuf(hex_bytes_filled, hexbuf);
+            if (p_buf == NULL) {
+                BTIF_TRACE_ERROR2("%s: Error, failed to allocate RPT buffer, len = %d",
+                                  __FUNCTION__, hex_bytes_filled);
+                return BT_STATUS_FAIL;
+            }
+            p_buf->layer_specific = BTA_HH_RPTT_OUTPUT;
+            BTA_HhSendData(p_dev->dev_handle, *bda, p_buf);
             return BT_STATUS_SUCCESS;
         }
 
diff --git a/btif/src/btif_hl.c b/btif/src/btif_hl.c
index 28a1461..e80a0b9 100644
--- a/btif/src/btif_hl.c
+++ b/btif/src/btif_hl.c
@@ -1857,21 +1857,22 @@
                                            UINT8 *p_app_idx){
     btif_hl_app_cb_t  *p_acb;
     BOOLEAN         found=FALSE;
-    UINT8 i,j;
+    UINT8 i;
 
     for (i=0; i<BTA_HL_NUM_APPS; i++)
     {
         p_acb =BTIF_HL_GET_APP_CB_PTR(i);
-        if (p_acb->delete_mdl.active)
-                BTIF_TRACE_DEBUG3("btif_hl_find_app_idx_using_deleted_mdl_id: app_idx=%d,"
-                    "mcl_idx =%d mcl_handle=%d",i,j,p_acb->mcb[j].mcl_handle);
-            if (p_acb->delete_mdl.active &&
-                (p_acb->delete_mdl.mdl_id == mdl_id))
-            {
-                found = TRUE;
-                *p_app_idx = i;
-                break;
-            }
+        if (p_acb->delete_mdl.active) {
+            BTIF_TRACE_DEBUG3("btif_hl_find_app_idx_using_deleted_mdl_id: app_idx=%d,"
+                              "mdl_id=%d mcl_handle=%d",i,mdl_id,p_acb->mcb[i].mcl_handle);
+        }
+        if (p_acb->delete_mdl.active &&
+            (p_acb->delete_mdl.mdl_id == mdl_id))
+        {
+            found = TRUE;
+            *p_app_idx = i;
+            break;
+        }
     }
     BTIF_TRACE_DEBUG3("%s found=%d app_idx=%d",__FUNCTION__,
                       found, i);
@@ -2823,7 +2824,7 @@
     btif_hl_app_cb_t         *p_acb;
     btif_hl_mcl_cb_t         *p_mcb;
     btif_hl_mdl_cb_t         *p_dcb;
-    UINT8                    app_idx,orig_app_idx, mcl_idx, mdl_idx, mdep_cfg_idx;
+    UINT8                    orig_app_idx, mcl_idx, mdl_idx, mdep_cfg_idx;
     UINT8                    dc_cfg;
     BOOLEAN close_dch = FALSE;
 
@@ -2856,7 +2857,7 @@
                 if(btif_hl_find_channel_id_using_mdl_id(orig_app_idx,p_dcb->mdl_id , &p_dcb->channel_id))
                 {
                     BTIF_TRACE_DEBUG4(" app_idx=%d mcl_idx=%d mdl_idx=%d channel_id=%d",
-                                        app_idx, mcl_idx, mdl_idx, p_dcb->channel_id  );
+                                        orig_app_idx, mcl_idx, mdl_idx, p_dcb->channel_id  );
                     if (!btif_hl_create_socket(orig_app_idx, mcl_idx, mdl_idx))
                     {
                         BTIF_TRACE_ERROR0("Unable to create socket");
@@ -3262,6 +3263,7 @@
                                        tBTA_HL_STATUS status){
     UINT8                   app_idx,mcl_idx, mdl_idx;
     btif_hl_mdl_cb_t         *p_dcb;
+    UNUSED(status);
 
     BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
     if (btif_hl_find_mdl_idx_using_handle(mdl_handle,
@@ -3301,7 +3303,7 @@
 
 /*******************************************************************************
 **
-** Function         btif_hl_proc_cb_evt
+** Function         btif_hl_proc_reg_request
 **
 ** Description      Process registration request
 **
@@ -3314,6 +3316,8 @@
     bt_status_t status= BT_STATUS_SUCCESS;
     UINT8 i;
     btif_hl_app_data_t *p_data;
+    UNUSED(p_cback);
+
     BTIF_TRACE_DEBUG3("%s app_idx=%d app_id=%d", __FUNCTION__, app_idx, app_id);
 
     if(reg_counter >1)
@@ -4929,6 +4933,7 @@
     btif_hl_soc_cb_t      *p_scb = NULL;
     btif_hl_mdl_cb_t      *p_dcb = NULL;
     int r;
+    UNUSED(p_org_set);
 
     BTIF_TRACE_DEBUG1("entering %s",__FUNCTION__);
 
@@ -5131,6 +5136,7 @@
 static void *btif_hl_select_thread(void *arg){
     fd_set org_set, curr_set;
     int r, max_curr_s, max_org_s;
+    UNUSED(arg);
 
     BTIF_TRACE_DEBUG0("entered btif_hl_select_thread");
     FD_ZERO(&org_set);
diff --git a/btif/src/btif_media_task.c b/btif/src/btif_media_task.c
index ff9f92c..0b9b613 100755
--- a/btif/src/btif_media_task.c
+++ b/btif/src/btif_media_task.c
@@ -66,7 +66,6 @@
 #include "btif_av.h"
 #include "btif_sm.h"
 #include "btif_util.h"
-#include "bt_utils.h"
 
 /*****************************************************************************
  **  Constants
@@ -88,6 +87,7 @@
 #define BTIF_MEDIA_TASK_CMD_MBOX        TASK_MBOX_0     /* cmd mailbox  */
 #define BTIF_MEDIA_TASK_DATA_MBOX       TASK_MBOX_1     /* data mailbox  */
 
+
 /* BTIF media cmd event definition : BTIF_MEDIA_TASK_CMD */
 enum
 {
@@ -120,6 +120,7 @@
    (1000/TICKS_PER_SEC) (10) */
 
 #define BTIF_MEDIA_TIME_TICK                     (20 * BTIF_MEDIA_NUM_TICK)
+#define A2DP_DATA_READ_POLL_MS    (BTIF_MEDIA_TIME_TICK / 2)
 
 /* buffer pool */
 #define BTIF_MEDIA_AA_POOL_ID GKI_POOL_ID_3
@@ -175,8 +176,11 @@
    but due to link flow control or thread preemption in lower
    layers we might need to temporarily buffer up data */
 
-/* 24 frames is equivalent to 6.89*24*2.9 ~= 480 ms @ 44.1 khz, 20 ms mediatick */
-#define MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ 24
+/* 18 frames is equivalent to 6.89*18*2.9 ~= 360 ms @ 44.1 khz, 20 ms mediatick */
+#define MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ 18
+#define A2DP_PACKET_COUNT_LOW_WATERMARK 5
+#define MAX_PCM_FRAME_NUM_PER_TICK     40
+#define RESET_RATE_COUNTER_THRESHOLD_MS    2000
 
 //#define BTIF_MEDIA_VERBOSE_ENABLED
 
@@ -199,6 +203,10 @@
     INT32  aa_feed_residue;
     UINT32 counter;
     UINT32 bytes_per_tick;  /* pcm bytes read each media task tick */
+    UINT32 max_counter_exit;
+    UINT32 max_counter_enter;
+    UINT32 overflow_count;
+    BOOLEAN overflow;
 } tBTIF_AV_MEDIA_FEEDINGS_PCM_STATE;
 
 
@@ -517,6 +525,8 @@
 
 static void btif_a2dp_ctrl_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event)
 {
+    UNUSED(ch_id);
+
     APPL_TRACE_DEBUG1("A2DP-CTRL-CHANNEL EVENT %s", dump_uipc_event(event));
 
     switch(event)
@@ -544,6 +554,8 @@
 
 static void btif_a2dp_data_cb(tUIPC_CH_ID ch_id, tUIPC_EVENT event)
 {
+    UNUSED(ch_id);
+
     APPL_TRACE_DEBUG1("BTIF MEDIA (A2DP-DATA) EVENT %s", dump_uipc_event(event));
 
     switch(event)
@@ -553,7 +565,8 @@
             /*  read directly from media task from here on (keep callback for
                 connection events */
             UIPC_Ioctl(UIPC_CH_ID_AV_AUDIO, UIPC_REG_REMOVE_ACTIVE_READSET, NULL);
-
+            UIPC_Ioctl(UIPC_CH_ID_AV_AUDIO, UIPC_SET_READ_POLL_TMO,
+                       (void *)A2DP_DATA_READ_POLL_MS);
             /* Start the media task to encode SBC */
             btif_media_task_start_aa_req();
 
@@ -1105,6 +1118,7 @@
 {
     UINT16 event;
     BT_HDR *p_msg;
+    UNUSED(p);
 
     VERBOSE("================ MEDIA TASK STARTING ================");
 
@@ -1428,6 +1442,8 @@
  *******************************************************************************/
 static void btif_media_task_aa_tx_flush(BT_HDR *p_msg)
 {
+    UNUSED(p_msg);
+
     /* Flush all enqueued GKI music buffers (encoded) */
     APPL_TRACE_DEBUG0("btif_media_task_aa_tx_flush");
 
@@ -1772,6 +1788,11 @@
  *******************************************************************************/
 static void btif_media_task_feeding_state_reset(void)
 {
+    APPL_TRACE_WARNING3("overflow %d, enter %d, exit %d",
+        btif_media_cb.media_feeding_state.pcm.overflow_count,
+        btif_media_cb.media_feeding_state.pcm.max_counter_enter,
+        btif_media_cb.media_feeding_state.pcm.max_counter_exit);
+
     /* By default, just clear the entire state */
     memset(&btif_media_cb.media_feeding_state, 0, sizeof(btif_media_cb.media_feeding_state));
 
@@ -1852,7 +1873,7 @@
  *******************************************************************************/
 static UINT8 btif_get_num_aa_frame(void)
 {
-    UINT8 result=0;
+    UINT32 result=0;
 
     switch (btif_media_cb.TxTranscoding)
     {
@@ -1865,11 +1886,24 @@
 
             btif_media_cb.media_feeding_state.pcm.counter +=
                                 btif_media_cb.media_feeding_state.pcm.bytes_per_tick;
+            if ((!btif_media_cb.media_feeding_state.pcm.overflow) ||
+                (btif_media_cb.TxAaQ.count < A2DP_PACKET_COUNT_LOW_WATERMARK)) {
+                if (btif_media_cb.media_feeding_state.pcm.overflow) {
+                    btif_media_cb.media_feeding_state.pcm.overflow = FALSE;
 
-            /* calculate nbr of frames pending for this media tick */
-            result = btif_media_cb.media_feeding_state.pcm.counter/pcm_bytes_per_frame;
-            btif_media_cb.media_feeding_state.pcm.counter -= result*pcm_bytes_per_frame;
-
+                    if (btif_media_cb.media_feeding_state.pcm.counter >
+                        btif_media_cb.media_feeding_state.pcm.max_counter_exit) {
+                        btif_media_cb.media_feeding_state.pcm.max_counter_exit =
+                            btif_media_cb.media_feeding_state.pcm.counter;
+                    }
+                }
+                /* calculate nbr of frames pending for this media tick */
+                result = btif_media_cb.media_feeding_state.pcm.counter/pcm_bytes_per_frame;
+                if (result > MAX_PCM_FRAME_NUM_PER_TICK) result = MAX_PCM_FRAME_NUM_PER_TICK;
+                btif_media_cb.media_feeding_state.pcm.counter -= result*pcm_bytes_per_frame;
+            } else {
+                result = 0;
+            }
             VERBOSE("WRITE %d FRAMES", result);
         }
         break;
@@ -1885,7 +1919,7 @@
     APPL_TRACE_DEBUG1("btif_get_num_aa_frame returns %d", result);
 #endif
 
-    return result;
+    return (UINT8)result;
 }
 
 /*******************************************************************************
@@ -2182,6 +2216,32 @@
         {
             GKI_freebuf(p_buf);
         }
+
+        if (btif_media_cb.TxAaQ.count >= MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ) {
+            UINT32 reset_rate_bytes = btif_media_cb.media_feeding_state.pcm.bytes_per_tick *
+                                (RESET_RATE_COUNTER_THRESHOLD_MS / BTIF_MEDIA_TIME_TICK);
+            btif_media_cb.media_feeding_state.pcm.overflow = TRUE;
+            btif_media_cb.media_feeding_state.pcm.counter += nb_frame *
+                     btif_media_cb.encoder.s16NumOfSubBands *
+                     btif_media_cb.encoder.s16NumOfBlocks *
+                     btif_media_cb.media_feeding.cfg.pcm.num_channel *
+                     btif_media_cb.media_feeding.cfg.pcm.bit_per_sample / 8;
+
+            btif_media_cb.media_feeding_state.pcm.overflow_count++;
+            if (btif_media_cb.media_feeding_state.pcm.counter >
+                btif_media_cb.media_feeding_state.pcm.max_counter_enter) {
+                btif_media_cb.media_feeding_state.pcm.max_counter_enter =
+                    btif_media_cb.media_feeding_state.pcm.counter;
+            }
+
+            if (btif_media_cb.media_feeding_state.pcm.counter > reset_rate_bytes) {
+                btif_media_cb.media_feeding_state.pcm.counter = 0;
+                APPL_TRACE_WARNING0("btif_media_aa_prep_sbc_2_send:reset rate counter");
+            }
+
+            /* no more pcm to read */
+            nb_frame = 0;
+        }
     }
 }
 
@@ -2201,13 +2261,6 @@
     VERBOSE("btif_media_aa_prep_2_send : %d frames (queue %d)", nb_frame,
                        btif_media_cb.TxAaQ.count);
 
-    while (btif_media_cb.TxAaQ.count >= MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ)
-    {
-        APPL_TRACE_WARNING1("btif_media_aa_prep_2_send congestion buf count %d",
-                             btif_media_cb.TxAaQ.count);
-        GKI_freebuf(GKI_dequeue(&(btif_media_cb.TxAaQ)));
-    }
-
     switch (btif_media_cb.TxTranscoding)
     {
     case BTIF_MEDIA_TRSCD_PCM_2_SBC:
@@ -2237,8 +2290,10 @@
     /* get the number of frame to send */
     nb_frame_2_send = btif_get_num_aa_frame();
 
-    /* format and Q buffer to send */
-    btif_media_aa_prep_2_send(nb_frame_2_send);
+    if (nb_frame_2_send != 0) {
+        /* format and Q buffer to send */
+        btif_media_aa_prep_2_send(nb_frame_2_send);
+    }
 
     /* send it */
     VERBOSE("btif_media_send_aa_frame : send %d frames", nb_frame_2_send);
diff --git a/btif/src/btif_pan.c b/btif/src/btif_pan.c
index 633f6ef..28c5156 100644
--- a/btif/src/btif_pan.c
+++ b/btif/src/btif_pan.c
@@ -204,9 +204,13 @@
     int bta_pan_role;
     BTIF_TRACE_DEBUG1("local_role:%d", local_role);
     bta_pan_role = btpan_role_to_bta(local_role);
+#if BTA_PAN_INCLUDED == TRUE
     BTA_PanSetRole(bta_pan_role, &bta_panu_info, NULL, &bta_pan_nap_info);
     btpan_dev_local_role = local_role;
     return BT_STATUS_SUCCESS;
+#else
+    return BT_STATUS_FAIL;
+#endif
 }
 static int btpan_get_local_role()
 {
@@ -389,6 +393,8 @@
 int btpan_tap_send(int tap_fd, const BD_ADDR src, const BD_ADDR dst, UINT16 proto, const char* buf,
                     UINT16 len, BOOLEAN ext, BOOLEAN forward)
 {
+    UNUSED(ext);
+    UNUSED(forward);
     if(tap_fd != -1)
     {
         tETH_HDR eth_hdr;
@@ -486,8 +492,22 @@
     BTIF_TRACE_DEBUG1("unknown proto:%x", ntohs(hdr->h_proto));
     return FALSE;
 }
+#if BTA_PAN_INCLUDED == TRUE
 extern void bta_pan_ci_rx_write(UINT16 handle, BD_ADDR dst, BD_ADDR src, UINT16 protocol,
         UINT8 *p_data, UINT16 len, BOOLEAN ext);
+#else
+static void bta_pan_ci_rx_write(UINT16 handle, BD_ADDR dst, BD_ADDR src, UINT16 protocol,
+        UINT8 *p_data, UINT16 len, BOOLEAN ext)
+{
+    UNUSED(handle);
+    UNUSED(dst);
+    UNUSED(src);
+    UNUSED(protocol);
+    UNUSED(p_data);
+    UNUSED(len);
+    UNUSED(ext);
+}
+#endif
 static void forward_bnep(tETH_HDR* eth_hdr, char * packet, int size)
 {
     int broadcast = eth_hdr->h_dest[0] & 1;
@@ -606,6 +626,9 @@
 {
     char packet[MAX_PACKET_SIZE];
     tETH_HDR eth_hdr;
+    UNUSED(type);
+    UNUSED(user_id);
+
     if(flags & SOCK_THREAD_FD_EXCEPTION)
     {
         BTIF_TRACE_ERROR1("pan tap fd:%d exception", fd);
@@ -631,4 +654,3 @@
     }
 }
 
-
diff --git a/btif/src/btif_rc.c b/btif/src/btif_rc.c
index d4ac0f1..068d096 100755
--- a/btif/src/btif_rc.c
+++ b/btif/src/btif_rc.c
@@ -764,6 +764,8 @@
 /* clear the queued PLAY command. if bSend is TRUE, forward to app */
 void btif_rc_check_handle_pending_play (BD_ADDR peer_addr, BOOLEAN bSendToApp)
 {
+    UNUSED(peer_addr);
+
     BTIF_TRACE_DEBUG2("%s: bSendToApp=%d", __FUNCTION__, bSendToApp);
     if (btif_rc_cb.rc_pending_play)
     {
@@ -1006,9 +1008,33 @@
             }
             else
             {
-                num_attr = pavrc_cmd->get_elem_attrs.num_attr;
-                memcpy(element_attrs, pavrc_cmd->get_elem_attrs.attrs, sizeof(UINT32)
-                    *pavrc_cmd->get_elem_attrs.num_attr);
+                int attr_cnt, filled_attr_count;
+
+                num_attr = 0;
+                /* Attribute IDs from 1 to AVRC_MAX_NUM_MEDIA_ATTR_ID are only valid,
+                 * hence HAL definition limits the attributes to AVRC_MAX_NUM_MEDIA_ATTR_ID.
+                 * Fill only valid entries.
+                 */
+                for (attr_cnt = 0; (attr_cnt < pavrc_cmd->get_elem_attrs.num_attr) &&
+                    (num_attr < AVRC_MAX_NUM_MEDIA_ATTR_ID); attr_cnt++)
+                {
+                    if ((pavrc_cmd->get_elem_attrs.attrs[attr_cnt] > 0) &&
+                        (pavrc_cmd->get_elem_attrs.attrs[attr_cnt] <= AVRC_MAX_NUM_MEDIA_ATTR_ID))
+                    {
+                        /* Skip the duplicate entries : PTS sends duplicate entries for Fragment cases
+                         */
+                        for (filled_attr_count = 0; filled_attr_count < num_attr; filled_attr_count++)
+                        {
+                            if (element_attrs[filled_attr_count] == pavrc_cmd->get_elem_attrs.attrs[attr_cnt])
+                                break;
+                        }
+                        if (filled_attr_count == num_attr)
+                        {
+                            element_attrs[num_attr] = pavrc_cmd->get_elem_attrs.attrs[attr_cnt];
+                            num_attr++;
+                        }
+                    }
+                }
             }
             FILL_PDU_QUEUE(IDX_GET_ELEMENT_ATTR_RSP, ctype, label, TRUE);
             HAL_CBACK(bt_rc_callbacks, get_element_attr_cb, num_attr, element_attrs);
diff --git a/btif/src/btif_sock_rfc.c b/btif/src/btif_sock_rfc.c
index cdc51a9..abb2a97 100644
--- a/btif/src/btif_sock_rfc.c
+++ b/btif/src/btif_sock_rfc.c
@@ -173,7 +173,7 @@
     }
     return NULL;
 }
-static inline rfc_slot_t* find_rfc_slot_by_id(uint32_t id)
+static inline rfc_slot_t* find_rfc_slot_by_id(uint32_t id, const char* label)
 {
     int i;
     if(id)
@@ -186,7 +186,7 @@
             }
         }
     }
-    APPL_TRACE_WARNING1("invalid rfc slot id: %d", id);
+    APPL_TRACE_WARNING2("invalid rfc slot id: %d, %s", id, label);
     return NULL;
 }
 static inline rfc_slot_t* find_rfc_slot_by_pending_sdp()
@@ -552,8 +552,8 @@
 }
 static void on_cl_rfc_init(tBTA_JV_RFCOMM_CL_INIT *p_init, uint32_t id)
 {
-   lock_slot(&slot_lock);
-    rfc_slot_t* rs = find_rfc_slot_by_id(id);
+    lock_slot(&slot_lock);
+    rfc_slot_t* rs = find_rfc_slot_by_id(id, "on_cl_rfc_init");
     if(rs)
     {
         if (p_init->status != BTA_JV_SUCCESS)
@@ -568,7 +568,7 @@
 static void  on_srv_rfc_listen_started(tBTA_JV_RFCOMM_START *p_start, uint32_t id)
 {
     lock_slot(&slot_lock);
-    rfc_slot_t* rs = find_rfc_slot_by_id(id);
+    rfc_slot_t* rs = find_rfc_slot_by_id(id, "on_srv_rfc_listen_started");
     if(rs)
     {
         if (p_start->status != BTA_JV_SUCCESS)
@@ -591,7 +591,7 @@
 {
     uint32_t new_listen_slot_id = 0;
     lock_slot(&slot_lock);
-    rfc_slot_t* srv_rs = find_rfc_slot_by_id(id);
+    rfc_slot_t* srv_rs = find_rfc_slot_by_id(id, "on_srv_rfc_connect");
     if(srv_rs)
     {
         rfc_slot_t* accept_rs = create_srv_accept_rfc_slot(srv_rs, (const bt_bdaddr_t*)p_open->rem_bda,
@@ -615,7 +615,7 @@
 static void on_cli_rfc_connect(tBTA_JV_RFCOMM_OPEN *p_open, uint32_t id)
 {
     lock_slot(&slot_lock);
-    rfc_slot_t* rs = find_rfc_slot_by_id(id);
+    rfc_slot_t* rs = find_rfc_slot_by_id(id, "on_cli_rfc_connect");
     if(rs && p_open->status == BTA_JV_SUCCESS)
     {
         rs->rfc_port_handle = BTA_JvRfcommGetPortHdl(p_open->handle);
@@ -638,8 +638,9 @@
 }
 static void on_rfc_close(tBTA_JV_RFCOMM_CLOSE * p_close, uint32_t id)
 {
+    UNUSED(p_close);
     lock_slot(&slot_lock);
-    rfc_slot_t* rs = find_rfc_slot_by_id(id);
+    rfc_slot_t* rs = find_rfc_slot_by_id(id, "on_rfc_close");
     if(rs)
     {
         APPL_TRACE_DEBUG4("on_rfc_close, slot id:%d, fd:%d, rfc scn:%d, server:%d",
@@ -653,8 +654,10 @@
 }
 static void on_rfc_write_done(tBTA_JV_RFCOMM_WRITE *p, uint32_t id)
 {
+    UNUSED(p);
+
     lock_slot(&slot_lock);
-    rfc_slot_t* rs = find_rfc_slot_by_id(id);
+    rfc_slot_t* rs = find_rfc_slot_by_id(id, "on_rfc_write_done");
     if(rs && !rs->f.outgoing_congest)
     {
         //mointer the fd for any outgoing data
@@ -665,7 +668,7 @@
 static void on_rfc_outgoing_congest(tBTA_JV_RFCOMM_CONG *p, uint32_t id)
 {
     lock_slot(&slot_lock);
-    rfc_slot_t* rs = find_rfc_slot_by_id(id);
+    rfc_slot_t* rs = find_rfc_slot_by_id(id, "on_rfc_outgoing_congest");
     if(rs)
     {
         rs->f.outgoing_congest = p->cong ? 1 : 0;
@@ -738,7 +741,7 @@
         case BTA_JV_CREATE_RECORD_EVT:
             {
                 lock_slot(&slot_lock);
-                rfc_slot_t* rs = find_rfc_slot_by_id(id);
+                rfc_slot_t* rs = find_rfc_slot_by_id(id, "jv_dm_cback: BTA_JV_CREATE_RECORD_EVT");
                 if(rs && create_server_sdp_record(rs))
                 {
                     //now start the rfcomm server after sdp & channel # assigned
@@ -762,7 +765,7 @@
                     APPL_TRACE_DEBUG3("BTA_JV_DISCOVERY_COMP_EVT, slot id:%d, status:%d, scn:%d",
                                       id, p_data->disc_comp.status, p_data->disc_comp.scn);
 
-                    rs = find_rfc_slot_by_id(id);
+                    rs = find_rfc_slot_by_id(id, "jv_dm_cback: BTA_JV_DISCOVERY_COMP_EVT");
                     if(rs && rs->f.doing_sdp_request)
                     {
                         if(BTA_JvRfcommConnect(rs->security, rs->role, p_data->disc_comp.scn, rs->addr.address,
@@ -784,10 +787,10 @@
                 }
                 else
                 {
-                    APPL_TRACE_ERROR3("DISCOVERY_COMP_EVT slot id:%d, failed to find channle, \
+                    APPL_TRACE_ERROR3("DISCOVERY_COMP_EVT slot id:%d, failed to find channel, \
                                       status:%d, scn:%d", id, p_data->disc_comp.status,
                                       p_data->disc_comp.scn);
-                    rs = find_rfc_slot_by_id(id);
+                    rs = find_rfc_slot_by_id(id, "jv_dm_cback: BTA_JV_DISCOVERY_COMP_EVT, no channel");
                     if(rs)
                         cleanup_rfc_slot(rs);
                 }
@@ -876,7 +879,7 @@
 void btsock_rfc_signaled(int fd, int flags, uint32_t user_id)
 {
     lock_slot(&slot_lock);
-    rfc_slot_t* rs = find_rfc_slot_by_id(user_id);
+    rfc_slot_t* rs = find_rfc_slot_by_id(user_id, "btsock_rfc_signaled");
     if(rs)
     {
         APPL_TRACE_DEBUG3("rfc slot id:%d, fd:%d, flags:%x", rs->id, fd, flags);
@@ -936,7 +939,7 @@
     uint32_t id = (uint32_t)user_data;
     int ret = 0;
     lock_slot(&slot_lock);
-    rfc_slot_t* rs = find_rfc_slot_by_id(id);
+    rfc_slot_t* rs = find_rfc_slot_by_id(id, "bta_co_rfc_data_incoming");
     if(rs)
     {
         if(!GKI_queue_is_empty(&rs->incoming_que))
@@ -973,7 +976,7 @@
     int ret = FALSE;
     *size = 0;
     lock_slot(&slot_lock);
-    rfc_slot_t* rs = find_rfc_slot_by_id(id);
+    rfc_slot_t* rs = find_rfc_slot_by_id(id, "bta_co_rfc_data_outgoing_size");
     if(rs)
     {
         if(ioctl(rs->fd, FIONREAD, size) == 0)
@@ -996,7 +999,7 @@
     uint32_t id = (uint32_t)user_data;
     int ret = FALSE;
     lock_slot(&slot_lock);
-    rfc_slot_t* rs = find_rfc_slot_by_id(id);
+    rfc_slot_t* rs = find_rfc_slot_by_id(id, "bta_co_rfc_data_outgoing");
     if(rs)
     {
         int received = recv(rs->fd, buf, size, 0);
@@ -1013,4 +1016,3 @@
     unlock_slot(&slot_lock);
     return ret;
 }
-
diff --git a/btif/src/btif_storage.c b/btif/src/btif_storage.c
index 284488d..8f41ce5 100644
--- a/btif/src/btif_storage.c
+++ b/btif/src/btif_storage.c
@@ -1358,7 +1358,8 @@
                                                     UINT16 attr_mask, UINT8 sub_class,
                                                     UINT8 app_id, UINT16 vendor_id,
                                                     UINT16 product_id, UINT16 version,
-                                                    UINT8 ctry_code, UINT16 dl_len, UINT8 *dsc_list)
+                                                    UINT8 ctry_code, UINT16 ssr_max_latency,
+                                                    UINT16 ssr_min_tout, UINT16 dl_len, UINT8 *dsc_list)
 {
     bdstr_t bdstr;
     BTIF_TRACE_DEBUG0("btif_storage_add_hid_device_info:");
@@ -1370,6 +1371,8 @@
     btif_config_set_int("Remote", bdstr, "HidProductId", product_id);
     btif_config_set_int("Remote", bdstr, "HidVersion", version);
     btif_config_set_int("Remote", bdstr, "HidCountryCode", ctry_code);
+    btif_config_set_int("Remote", bdstr, "HidSSRMaxLatency", ssr_max_latency);
+    btif_config_set_int("Remote", bdstr, "HidSSRMinTimeout", ssr_min_tout);
     if(dl_len > 0)
         btif_config_set("Remote", bdstr, "HidDescriptor", (const char*)dsc_list, dl_len,
                         BTIF_CFG_TYPE_BIN);
@@ -1430,6 +1433,14 @@
             btif_config_get_int("Remote", kname, "HidCountryCode", &value);
             dscp_info.ctry_code = (uint8_t) value;
 
+            value = 0;
+            btif_config_get_int("Remote", kname, "HidSSRMaxLatency", &value);
+            dscp_info.ssr_max_latency = (uint16_t) value;
+
+            value = 0;
+            btif_config_get_int("Remote", kname, "HidSSRMinTimeout", &value);
+            dscp_info.ssr_min_tout = (uint16_t) value;
+
             int len = 0;
             int type;
             btif_config_get("Remote", kname, "HidDescriptor", NULL, &len, &type);
@@ -1476,6 +1487,8 @@
     btif_config_remove("Remote", bdstr, "HidProductId");
     btif_config_remove("Remote", bdstr, "HidVersion");
     btif_config_remove("Remote", bdstr, "HidCountryCode");
+    btif_config_remove("Remote", bdstr, "HidSSRMaxLatency");
+    btif_config_remove("Remote", bdstr, "HidSSRMinTimeout");
     btif_config_remove("Remote", bdstr, "HidDescriptor");
     btif_config_save();
     return BT_STATUS_SUCCESS;
@@ -1498,7 +1511,7 @@
 
     if (!btif_config_exist("Local", BTIF_STORAGE_HL_APP, BTIF_STORAGE_HL_APP_CB))
     {
-        memset(value, value_size, 0);
+        memset(value, 0, value_size);
         if (!btif_config_set("Local", BTIF_STORAGE_HL_APP,BTIF_STORAGE_HL_APP_CB,
                              value, value_size, BTIF_CFG_TYPE_BIN))
         {
@@ -1683,8 +1696,9 @@
     char input_value [20];
 
     bd2str(remote_bd_addr, &bdstr);
-    strncpy(input_value, (char*)bdstr, 20);
-    strncat(input_value,BTIF_AUTO_PAIR_CONF_VALUE_SEPARATOR, 20);
+    strlcpy(input_value, (char*)bdstr, sizeof(input_value));
+    strlcat(input_value,BTIF_AUTO_PAIR_CONF_VALUE_SEPARATOR, sizeof(input_value));
+
     int line_size = sizeof(linebuf);
     if(btif_config_get_str("Local", BTIF_STORAGE_PATH_AUTOPAIR_BLACKLIST,
                             BTIF_STORAGE_KEY_AUTOPAIR_DYNAMIC_BLACKLIST_ADDR, linebuf, &line_size))
diff --git a/btif/src/btif_util.c b/btif/src/btif_util.c
index 6389ccb..96685f2 100755
--- a/btif/src/btif_util.c
+++ b/btif/src/btif_util.c
@@ -93,11 +93,11 @@
 
 char *bd2str(const bt_bdaddr_t *bdaddr, bdstr_t *bdstr)
 {
-    char *addr = (char *) bdaddr->address;
+    const uint8_t *addr = bdaddr->address;
 
-    sprintf((char*)bdstr, "%02x:%02x:%02x:%02x:%02x:%02x",
-                       (int)addr[0],(int)addr[1],(int)addr[2],
-                       (int)addr[3],(int)addr[4],(int)addr[5]);
+    snprintf((char*)bdstr, sizeof(*bdstr), "%02x:%02x:%02x:%02x:%02x:%02x",
+             addr[0], addr[1], addr[2],
+             addr[3], addr[4], addr[5]);
     return (char *)bdstr;
 }
 
diff --git a/gki/Android.mk b/gki/Android.mk
index 0ece25b..ed9f904 100644
--- a/gki/Android.mk
+++ b/gki/Android.mk
@@ -11,7 +11,7 @@
                    $(LOCAL_PATH)/../utils/include \
                    $(bdroid_C_INCLUDES) \
 
-LOCAL_CFLAGS += -Werror $(bdroid_CFLAGS)
+LOCAL_CFLAGS += -Werror -Wno-error=unused-parameter $(bdroid_CFLAGS)
 
 ifeq ($(BOARD_HAVE_BLUETOOTH_BCM),true)
 LOCAL_CFLAGS += \
diff --git a/gki/ulinux/gki_ulinux.c b/gki/ulinux/gki_ulinux.c
index 57ff7bb..a66a32f 100755
--- a/gki/ulinux/gki_ulinux.c
+++ b/gki/ulinux/gki_ulinux.c
@@ -29,6 +29,7 @@
 #include <stdarg.h>
 #include <errno.h>
 #include <sys/times.h>
+#include <hardware/bluetooth.h>
 
 #include <pthread.h>  /* must be 1st header defined  */
 #include <time.h>
@@ -74,8 +75,6 @@
 #define UNLOCK(m) pthread_mutex_unlock(&m)
 #define INIT(m) pthread_mutex_init(&m, NULL)
 
-#define WAKE_LOCK_ID "brcm_btld"
-#define PARTIAL_WAKE_LOCK 1
 
 #if GKI_DYNAMIC_MEMORY == FALSE
 tGKI_CB   gki_cb;
@@ -113,6 +112,7 @@
 
 int g_GkiTimerWakeLockOn = 0;
 gki_pthread_info_t gki_pthread_info[GKI_MAX_TASKS];
+bt_wakelock_callback config_wakelock_callback = NULL;
 
 /*****************************************************************************
 **  Static functions
@@ -122,13 +122,33 @@
 **  Externs
 ******************************************************************************/
 
-extern int acquire_wake_lock(int lock, const char* id);
-extern int release_wake_lock(const char* id);
+
 
 /*****************************************************************************
 **  Functions
 ******************************************************************************/
 
+/* send a given byte into the wakelock pipe */
+static void wakelock_op_gki(unsigned char op)
+{
+    if (!config_wakelock_callback)
+        GKI_ERROR_LOG("Cannot perform wakelock operation with no callback\n");
+    else
+        config_wakelock_callback(op);
+}
+
+/* release a wakelock by sending a zero down the pipe */
+static void release_wake_lock_gki(void)
+{
+    wakelock_op_gki(0);
+}
+
+/* acquire a wakelock by sending a one down the pipe */
+static void acquire_wake_lock_gki(void)
+{
+    wakelock_op_gki(1);
+}
+
 
 /*****************************************************************************
 **
@@ -247,6 +267,8 @@
     struct sched_param param;
     int policy, ret = 0;
     pthread_attr_t attr1;
+    UNUSED(stack);
+    UNUSED(stacksize);
 
     GKI_TRACE( "GKI_create_task %x %d %s %x %d", (int)task_entry, (int)task_id,
             (char*) taskname, (int) stack, (int)stacksize);
@@ -311,8 +333,10 @@
          {
              /* check if define in gki_int.h is correct for this compile environment! */
              policy = GKI_LINUX_BASE_POLICY;
-#if (GKI_LINUX_BASE_POLICY!=GKI_SCHED_NORMAL)
+#if (GKI_LINUX_BASE_POLICY != GKI_SCHED_NORMAL)
              param.sched_priority = GKI_LINUX_BASE_PRIORITY - task_id - 2;
+#else
+             param.sched_priority = 0;
 #endif
          }
          pthread_setschedparam(gki_cb.os.thread_id[task_id], policy, &param);
@@ -523,8 +547,8 @@
 #endif
     if (g_GkiTimerWakeLockOn)
     {
-        GKI_TRACE("GKI_shutdown :  release_wake_lock(brcm_btld)");
-        release_wake_lock(WAKE_LOCK_ID);
+        GKI_TRACE("GKI_shutdown :  release_wake_lock_gki()");
+        release_wake_lock_gki();
         g_GkiTimerWakeLockOn = 0;
     }
 }
@@ -565,14 +589,14 @@
 
             GKI_TIMER_TRACE(">>> STOP GKI_timer_update(), wake_lock_count:%d", --wake_lock_count);
 
-            release_wake_lock(WAKE_LOCK_ID);
+            release_wake_lock_gki();
             g_GkiTimerWakeLockOn = 0;
         }
     }
     else
     {
         /* restart GKI_timer_update() loop */
-        acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);
+        acquire_wake_lock_gki();
 
         g_GkiTimerWakeLockOn = 1;
         *p_run_cond = GKI_TIMER_TICK_RUN_COND;
@@ -615,6 +639,7 @@
     int restart;
     tGKI_OS         *p_os = &gki_cb.os;
     int  *p_run_cond = &p_os->no_timer_suspend;
+    (void)arg;
 
     /* Indicate that tick is just starting */
     restart = 1;
@@ -781,11 +806,12 @@
 **
 *******************************************************************************/
 
-void GKI_run (void *p_task_id)
+void GKI_run (void * p_task_id)
 {
     struct timespec delay;
     int err;
     volatile int * p_run_cond = &gki_cb.os.no_timer_suspend;
+    UNUSED(p_task_id);
 
 #ifndef GKI_NO_TICK_STOP
     /* adjust btld scheduling scheme now */
@@ -1402,9 +1428,9 @@
 *******************************************************************************/
 UINT8 GKI_suspend_task (UINT8 task_id)
 {
+    UNUSED(task_id);
     GKI_TRACE("GKI_suspend_task %d - NOT implemented", task_id);
 
-
     GKI_TRACE("GKI_suspend_task %d done", task_id);
 
     return (GKI_SUCCESS);
@@ -1428,9 +1454,9 @@
 *******************************************************************************/
 UINT8 GKI_resume_task (UINT8 task_id)
 {
+    UNUSED(task_id);
     GKI_TRACE("GKI_resume_task %d - NOT implemented", task_id);
 
-
     GKI_TRACE("GKI_resume_task %d done", task_id);
 
     return (GKI_SUCCESS);
diff --git a/hci/Android.mk b/hci/Android.mk
index 2b1b07e..24fec19 100644
--- a/hci/Android.mk
+++ b/hci/Android.mk
@@ -2,6 +2,8 @@
 
 include $(CLEAR_VARS)
 
+LOCAL_CFLAGS += $(bdroid_CFLAGS)
+
 LOCAL_SRC_FILES := \
         src/bt_hci_bdroid.c \
         src/lpm.c \
@@ -11,7 +13,7 @@
 
 ifeq ($(BLUETOOTH_HCI_USE_MCT),true)
 
-LOCAL_CFLAGS := -DHCI_USE_MCT
+LOCAL_CFLAGS += -DHCI_USE_MCT
 
 LOCAL_SRC_FILES += \
         src/hci_mct.c \
@@ -27,7 +29,8 @@
 
 LOCAL_C_INCLUDES += \
         $(LOCAL_PATH)/include \
-        $(LOCAL_PATH)/../utils/include
+        $(LOCAL_PATH)/../utils/include \
+        $(bdroid_C_INCLUDES)
 
 LOCAL_SHARED_LIBRARIES := \
         libcutils \
diff --git a/hci/include/bt_hci_bdroid.h b/hci/include/bt_hci_bdroid.h
index 7b23851..904c698 100644
--- a/hci/include/bt_hci_bdroid.h
+++ b/hci/include/bt_hci_bdroid.h
@@ -32,6 +32,10 @@
 
 #include "bt_hci_lib.h"
 
+#ifdef HAS_BDROID_BUILDCFG
+#include "bdroid_buildcfg.h"
+#endif
+
 /******************************************************************************
 **  Constants & Macros
 ******************************************************************************/
diff --git a/hci/src/bt_hci_bdroid.c b/hci/src/bt_hci_bdroid.c
index 8e4f8ff..ed98b37 100644
--- a/hci/src/bt_hci_bdroid.c
+++ b/hci/src/bt_hci_bdroid.c
@@ -125,6 +125,7 @@
 *******************************************************************************/
 static void epilog_wait_timeout(union sigval arg)
 {
+    UNUSED(arg);
     ALOGI("...epilog_wait_timeout...");
     bthc_signal_event(HC_EVENT_EXIT);
 }
@@ -237,8 +238,10 @@
     if(pthread_getschedparam(hc_cb.worker_thread, &policy, &param)==0)
     {
         policy = BTHC_LINUX_BASE_POLICY;
-#if (BTHC_LINUX_BASE_POLICY!=SCHED_NORMAL)
+#if (BTHC_LINUX_BASE_POLICY != SCHED_NORMAL)
         param.sched_priority = BTHC_MAIN_THREAD_PRIORITY;
+#else
+        param.sched_priority = 0;
 #endif
         result = pthread_setschedparam(hc_cb.worker_thread, policy, &param);
         if (result != 0)
@@ -297,9 +300,10 @@
 }
 
 
-/** Called prio to stack initialization */
+/** Called prior to stack initialization */
 static void preload(TRANSAC transac)
 {
+    UNUSED(transac);
     BTHCDBG("preload");
     bthc_signal_event(HC_EVENT_PRELOAD);
 }
@@ -308,14 +312,17 @@
 /** Called post stack initialization */
 static void postload(TRANSAC transac)
 {
+    UNUSED(transac);
     BTHCDBG("postload");
     bthc_signal_event(HC_EVENT_POSTLOAD);
 }
 
 
 /** Transmit frame */
-static int transmit_buf(TRANSAC transac, char *p_buf, int len)
+static int transmit_buf(TRANSAC transac, char * p_buf, int len)
 {
+    UNUSED(p_buf);
+    UNUSED(len);
     utils_enqueue(&tx_q, (void *) transac);
 
     bthc_signal_event(HC_EVENT_TX);
@@ -425,6 +432,7 @@
 {
     uint16_t events;
     HC_BT_HDR *p_msg, *p_next_msg;
+    UNUSED(arg);
 
     ALOGI("bt_hc_worker_thread started");
     prctl(PR_SET_NAME, (unsigned long)"bt_hc_worker", 0, 0, 0);
@@ -504,7 +512,7 @@
             utils_lock();
             p_next_msg = tx_q.p_first;
             while (p_next_msg && sending_msg_count <
-                            (int)sizeof(sending_msg_que)/sizeof(sending_msg_que[0]))
+		   (int)(sizeof(sending_msg_que)/sizeof(sending_msg_que[0])))
             {
                 if ((p_next_msg->event & MSG_EVT_MASK)==MSG_STACK_TO_HC_HCI_CMD)
                 {
diff --git a/hci/src/bt_hw.c b/hci/src/bt_hw.c
index 5265dce..898a6ed 100644
--- a/hci/src/bt_hw.c
+++ b/hci/src/bt_hw.c
@@ -33,6 +33,7 @@
 #include "bt_hci_bdroid.h"
 #include "hci.h"
 #include "userial.h"
+#include "bt_utils.h"
 
 /******************************************************************************
 **  Externs
@@ -87,6 +88,7 @@
 ******************************************************************************/
 static void scocfg_cb(bt_vendor_op_result_t result)
 {
+    UNUSED(result);
     /* Continue rest of postload process*/
     p_hci_if->get_acl_max_len();
 }
@@ -178,6 +180,7 @@
 ******************************************************************************/
 static void epilog_cb(bt_vendor_op_result_t result)
 {
+    UNUSED(result);
     bthc_signal_event(HC_EVENT_EXIT);
 }
 
diff --git a/hci/src/btsnoop.c b/hci/src/btsnoop.c
index 4807df8..c6556d6 100755
--- a/hci/src/btsnoop.c
+++ b/hci/src/btsnoop.c
@@ -55,6 +55,7 @@
 
 #include "bt_hci_bdroid.h"
 #include "utils.h"
+#include "bt_utils.h"
 
 #ifndef BTSNOOP_DBG
 #define BTSNOOP_DBG FALSE
@@ -66,6 +67,11 @@
 #define SNOOPDBG(param, ...) {}
 #endif
 
+#define HCIT_TYPE_COMMAND   1
+#define HCIT_TYPE_ACL_DATA  2
+#define HCIT_TYPE_SCO_DATA  3
+#define HCIT_TYPE_EVENT     4
+
 /* file descriptor of the BT snoop file (by default, -1 means disabled) */
 int hci_btsnoop_fd = -1;
 
@@ -117,6 +123,7 @@
 #define BTSNOOP_EPOCH_HI 0x00dcddb3U
 #define BTSNOOP_EPOCH_LO 0x0f2f8000U
 
+
 /*******************************************************************************
  **
  ** Function         tv_to_btsnoop_ts
@@ -252,6 +259,46 @@
 }
 
 /*******************************************************************************
+ ** Function          btsnoop_write
+ **
+ ** Description       Function used to write the actual data to the log
+ **
+ ** Returns           none
+*******************************************************************************/
+
+void btsnoop_write(uint8_t *p, uint32_t flags, const uint8_t *ptype, uint32_t len)
+{
+    uint32_t value, value_hi;
+    struct timeval tv;
+    struct iovec io[3];
+    uint32_t header[6];
+
+    /* store the length in both original and included fields */
+    header[0] = l_to_be(len + 1);
+    header[1] = header[0];
+    /* flags: data can be sent or received */
+    header[2] = l_to_be(flags);
+    /* drops: none */
+    header[3] = 0;
+    /* time */
+    gettimeofday(&tv, NULL);
+    tv_to_btsnoop_ts(&header[5], &header[4], &tv);
+    header[4] = l_to_be(header[4]);
+    header[5] = l_to_be(header[5]);
+
+    io[0].iov_base = header;
+    io[0].iov_len = sizeof(header);
+
+    io[1].iov_base = (void*)ptype;
+    io[1].iov_len = 1;
+
+    io[2].iov_base = p;
+    io[2].iov_len = len;
+
+    (void) writev(hci_btsnoop_fd, io, 3);
+}
+
+/*******************************************************************************
  **
  ** Function         btsnoop_hci_cmd
  **
@@ -261,42 +308,14 @@
 *******************************************************************************/
 void btsnoop_hci_cmd(uint8_t *p)
 {
+    const uint8_t cmd = HCIT_TYPE_COMMAND;
+    int plen;
     SNOOPDBG("btsnoop_hci_cmd: fd = %d", hci_btsnoop_fd);
-
-    if (hci_btsnoop_fd != -1)
-    {
-        uint32_t value, value_hi;
-        struct timeval tv;
-
-        /* since these display functions are called from different contexts */
-        utils_lock();
-
-        /* store the length in both original and included fields */
-        value = l_to_be(p[2] + 4);
-        write(hci_btsnoop_fd, &value, 4);
-        write(hci_btsnoop_fd, &value, 4);
-        /* flags: command sent from the host */
-        value = l_to_be(2);
-        write(hci_btsnoop_fd, &value, 4);
-        /* drops: none */
-        value = 0;
-        write(hci_btsnoop_fd, &value, 4);
-        /* time */
-        gettimeofday(&tv, NULL);
-        tv_to_btsnoop_ts(&value, &value_hi, &tv);
-        value_hi = l_to_be(value_hi);
-        value = l_to_be(value);
-        write(hci_btsnoop_fd, &value_hi, 4);
-        write(hci_btsnoop_fd, &value, 4);
-        /* data */
-        write(hci_btsnoop_fd, "\x1", 1);
-        write(hci_btsnoop_fd, p, p[2] + 3);
-
-        /* since these display functions are called from different contexts */
-        utils_unlock();
-    }
+    plen = (int) p[2] + 3;
+    btsnoop_write(p, 2, &cmd, plen);
 }
 
+
 /*******************************************************************************
  **
  ** Function         btsnoop_hci_evt
@@ -307,40 +326,12 @@
 *******************************************************************************/
 void btsnoop_hci_evt(uint8_t *p)
 {
+    const uint8_t evt = HCIT_TYPE_EVENT;
+    int plen;
     SNOOPDBG("btsnoop_hci_evt: fd = %d", hci_btsnoop_fd);
+    plen = (int) p[1] + 2;
 
-    if (hci_btsnoop_fd != -1)
-    {
-        uint32_t value, value_hi;
-        struct timeval tv;
-
-        /* since these display functions are called from different contexts */
-        utils_lock();
-
-        /* store the length in both original and included fields */
-        value = l_to_be(p[1] + 3);
-        write(hci_btsnoop_fd, &value, 4);
-        write(hci_btsnoop_fd, &value, 4);
-        /* flags: event received in the host */
-        value = l_to_be(3);
-        write(hci_btsnoop_fd, &value, 4);
-        /* drops: none */
-        value = 0;
-        write(hci_btsnoop_fd, &value, 4);
-        /* time */
-        gettimeofday(&tv, NULL);
-        tv_to_btsnoop_ts(&value, &value_hi, &tv);
-        value_hi = l_to_be(value_hi);
-        value = l_to_be(value);
-        write(hci_btsnoop_fd, &value_hi, 4);
-        write(hci_btsnoop_fd, &value, 4);
-        /* data */
-        write(hci_btsnoop_fd, "\x4", 1);
-        write(hci_btsnoop_fd, p, p[1] + 2);
-
-        /* since these display functions are called from different contexts */
-        utils_unlock();
-    }
+    btsnoop_write(p, 3, &evt, plen);
 }
 
 /*******************************************************************************
@@ -353,40 +344,12 @@
 *******************************************************************************/
 void btsnoop_sco_data(uint8_t *p, uint8_t is_rcvd)
 {
+    const uint8_t sco = HCIT_TYPE_SCO_DATA;
+    int plen;
     SNOOPDBG("btsnoop_sco_data: fd = %d", hci_btsnoop_fd);
+    plen = (int) p[2] + 3;
 
-    if (hci_btsnoop_fd != -1)
-    {
-        uint32_t value, value_hi;
-        struct timeval tv;
-
-        /* since these display functions are called from different contexts */
-        utils_lock();
-
-        /* store the length in both original and included fields */
-        value = l_to_be(p[2] + 4);
-        write(hci_btsnoop_fd, &value, 4);
-        write(hci_btsnoop_fd, &value, 4);
-        /* flags: data can be sent or received */
-        value = l_to_be(is_rcvd?1:0);
-        write(hci_btsnoop_fd, &value, 4);
-        /* drops: none */
-        value = 0;
-        write(hci_btsnoop_fd, &value, 4);
-        /* time */
-        gettimeofday(&tv, NULL);
-        tv_to_btsnoop_ts(&value, &value_hi, &tv);
-        value_hi = l_to_be(value_hi);
-        value = l_to_be(value);
-        write(hci_btsnoop_fd, &value_hi, 4);
-        write(hci_btsnoop_fd, &value, 4);
-        /* data */
-        write(hci_btsnoop_fd, "\x3", 1);
-        write(hci_btsnoop_fd, p, p[2] + 3);
-
-        /* since these display functions are called from different contexts */
-        utils_unlock();
-    }
+    btsnoop_write(p, is_rcvd, &sco, plen);
 }
 
 /*******************************************************************************
@@ -399,42 +362,16 @@
 *******************************************************************************/
 void btsnoop_acl_data(uint8_t *p, uint8_t is_rcvd)
 {
+    const uint8_t acl = HCIT_TYPE_ACL_DATA;
+    int plen;
+
     SNOOPDBG("btsnoop_acl_data: fd = %d", hci_btsnoop_fd);
-    if (hci_btsnoop_fd != -1)
-    {
-        uint32_t value, value_hi;
-        struct timeval tv;
 
-        /* since these display functions are called from different contexts */
-        utils_lock();
+    plen = (((int) p[3]) << 8) + ((int) p[2]) +4;
 
-        /* store the length in both original and included fields */
-        value = l_to_be((p[3]<<8) + p[2] + 5);
-        write(hci_btsnoop_fd, &value, 4);
-        write(hci_btsnoop_fd, &value, 4);
-        /* flags: data can be sent or received */
-        value = l_to_be(is_rcvd?1:0);
-        write(hci_btsnoop_fd, &value, 4);
-        /* drops: none */
-        value = 0;
-        write(hci_btsnoop_fd, &value, 4);
-        /* time */
-        gettimeofday(&tv, NULL);
-        tv_to_btsnoop_ts(&value, &value_hi, &tv);
-        value_hi = l_to_be(value_hi);
-        value = l_to_be(value);
-        write(hci_btsnoop_fd, &value_hi, 4);
-        write(hci_btsnoop_fd, &value, 4);
-        /* data */
-        write(hci_btsnoop_fd, "\x2", 1);
-        write(hci_btsnoop_fd, p, (p[3]<<8) + p[2] + 4);
-
-        /* since these display functions are called from different contexts */
-        utils_unlock();
-    }
+    btsnoop_write(p, is_rcvd, &acl, plen);
 }
 
-
 /********************************************************************************
  ** API allow external realtime parsing of output using e.g hcidump
  *********************************************************************************/
@@ -542,6 +479,7 @@
 
 static void interruptFn (int sig)
 {
+    UNUSED(sig);
     ALOGD("interruptFn");
     pthread_exit(0);
 }
@@ -553,6 +491,7 @@
     sigset_t sigSet;
     sigemptyset (&sigSet);
     sigaddset (&sigSet, sig);
+    UNUSED(param);
 
     ALOGD("ext_parser_thread");
 
@@ -619,11 +558,6 @@
 }
 
 
-#define HCIT_TYPE_COMMAND   1
-#define HCIT_TYPE_ACL_DATA  2
-#define HCIT_TYPE_SCO_DATA  3
-#define HCIT_TYPE_EVENT     4
-
 void btsnoop_capture(HC_BT_HDR *p_buf, uint8_t is_rcvd)
 {
     uint8_t *p = (uint8_t *)(p_buf + 1) + p_buf->offset;
diff --git a/hci/src/lpm.c b/hci/src/lpm.c
index fb6f837..946b193 100644
--- a/hci/src/lpm.c
+++ b/hci/src/lpm.c
@@ -31,6 +31,7 @@
 #include <time.h>
 #include "bt_hci_bdroid.h"
 #include "bt_vendor_lib.h"
+#include "bt_utils.h"
 
 /******************************************************************************
 **  Constants & Macros
@@ -109,6 +110,7 @@
 *******************************************************************************/
 static void lpm_idle_timeout(union sigval arg)
 {
+    UNUSED(arg);
     BTLPMDBG("..lpm_idle_timeout..");
 
     if ((bt_lpm_cb.state == LPM_ENABLED) && \
@@ -152,7 +154,7 @@
     if (bt_lpm_cb.timer_created == TRUE)
     {
         ts.it_value.tv_sec = bt_lpm_cb.timeout_ms/1000;
-        ts.it_value.tv_nsec = 1000*(bt_lpm_cb.timeout_ms%1000);
+        ts.it_value.tv_nsec = 1000000*(bt_lpm_cb.timeout_ms%1000);
         ts.it_interval.tv_sec = 0;
         ts.it_interval.tv_nsec = 0;
 
diff --git a/hci/src/userial.c b/hci/src/userial.c
index 8e5bf6c..5dc4f84 100644
--- a/hci/src/userial.c
+++ b/hci/src/userial.c
@@ -241,6 +241,7 @@
     int rx_length = 0;
     HC_BT_HDR *p_buf = NULL;
     uint8_t *p;
+    UNUSED(arg);
 
     USERIALDBG("Entering userial_read_thread()");
     prctl(PR_SET_NAME, (unsigned long)"userial_read", 0, 0, 0);
@@ -401,8 +402,10 @@
     if(pthread_getschedparam(userial_cb.read_thread, &policy, &param)==0)
     {
         policy = BTHC_LINUX_BASE_POLICY;
-#if (BTHC_LINUX_BASE_POLICY!=SCHED_NORMAL)
+#if (BTHC_LINUX_BASE_POLICY != SCHED_NORMAL)
         param.sched_priority = BTHC_USERIAL_READ_THREAD_PRIORITY;
+#else
+        param.sched_priority = 0;
 #endif
         result = pthread_setschedparam(userial_cb.read_thread, policy, &param);
         if (result != 0)
@@ -430,6 +433,7 @@
     uint16_t total_len = 0;
     uint16_t copy_len = 0;
     uint8_t *p_data = NULL;
+    UNUSED(msg_id);
 
     do
     {
@@ -482,6 +486,7 @@
 uint16_t userial_write(uint16_t msg_id, uint8_t *p_data, uint16_t len)
 {
     int ret, total = 0;
+    UNUSED(msg_id);
 
     while(len != 0)
     {
@@ -544,6 +549,8 @@
 *******************************************************************************/
 void userial_ioctl(userial_ioctl_op_t op, void *p_data)
 {
+    UNUSED(p_data);
+
     switch(op)
     {
         case USERIAL_OP_RXFLOW_ON:
diff --git a/hci/src/userial_mct.c b/hci/src/userial_mct.c
index 3c59384..d7554cc 100644
--- a/hci/src/userial_mct.c
+++ b/hci/src/userial_mct.c
@@ -321,10 +321,12 @@
     if(pthread_getschedparam(userial_cb.read_thread, &policy, &param)==0)
     {
         policy = BTHC_LINUX_BASE_POLICY;
-#if (BTHC_LINUX_BASE_POLICY!=SCHED_NORMAL)
+#if (BTHC_LINUX_BASE_POLICY != SCHED_NORMAL)
         param.sched_priority = BTHC_USERIAL_READ_THREAD_PRIORITY;
+#else
+        param.sched_priority = 0;
 #endif
-        result=pthread_setschedparam(userial_cb.read_thread,policy,&param);
+        result = pthread_setschedparam(userial_cb.read_thread, policy, &param);
         if (result != 0)
         {
             ALOGW("userial_open: pthread_setschedparam failed (%s)", \
diff --git a/include/bt_target.h b/include/bt_target.h
index a106773..7e77164 100644
--- a/include/bt_target.h
+++ b/include/bt_target.h
@@ -263,10 +263,6 @@
 #define BTA_JV_INCLUDED FALSE
 #endif
 
-#ifndef BTA_GATT_INCLUDED
-#define BTA_GATT_INCLUDED TRUE
-#endif
-
 #ifndef BTA_DISABLE_DELAY
 #define BTA_DISABLE_DELAY 200 /* in milliseconds */
 #endif
@@ -1411,11 +1407,27 @@
 #define LOCAL_BLE_CONTROLLER_ID         (1)
 #endif
 
+#ifndef BTM_BLE_PRIVACY_SPT
+#define BTM_BLE_PRIVACY_SPT      TRUE
+#endif
+
 /******************************************************************************
 **
 ** ATT/GATT Protocol/Profile Settings
 **
 ******************************************************************************/
+#ifndef BTA_GATT_INCLUDED
+#if BLE_INCLUDED == TRUE
+#define BTA_GATT_INCLUDED TRUE
+#else
+#define BTA_GATT_INCLUDED FALSE
+#endif
+#endif
+
+#if BTA_GATT_INCLUDED == TRUE && BLE_INCLUDED == FALSE
+#error "can't have GATT without BLE"
+#endif
+
 #ifndef ATT_INCLUDED
 #define ATT_INCLUDED         TRUE
 #endif
@@ -1432,6 +1444,32 @@
 #define GATT_CLIENT_ENABLED          TRUE
 #endif
 
+#ifndef BLE_PERIPHERAL_MODE_SUPPORT
+#define BLE_PERIPHERAL_MODE_SUPPORT  FALSE
+#endif
+
+#ifndef BLE_PERIPHERAL_DISPLAYONLY
+#define BLE_PERIPHERAL_DISPLAYONLY   FALSE
+#endif
+
+#ifndef BLE_PERIPHERAL_ADV_NAME
+#define BLE_PERIPHERAL_ADV_NAME      FALSE
+#endif
+
+#ifndef BLE_DELAY_REQUEST_ENC
+/* This flag is to work around IPHONE problem, We need to wait for iPhone ready
+   before send encryption request to iPhone */
+#define BLE_DELAY_REQUEST_ENC        FALSE
+#endif
+
+#ifndef GAP_TRANSPORT_SUPPORTED
+#define GAP_TRANSPORT_SUPPORTED      GATT_TRANSPORT_LE_BR_EDR
+#endif
+
+#ifndef GATTP_TRANSPORT_SUPPORTED
+#define GATTP_TRANSPORT_SUPPORTED    GATT_TRANSPORT_LE_BR_EDR
+#endif
+
 #ifndef GATT_MAX_SR_PROFILES
 #define GATT_MAX_SR_PROFILES        32 /* max is 32 */
 #endif
@@ -1465,7 +1503,15 @@
 **
 ******************************************************************************/
 #ifndef SMP_INCLUDED
+#if BLE_INCLUDED == TRUE
 #define SMP_INCLUDED         TRUE
+#else
+#define SMP_INCLUDED         FALSE
+#endif
+#endif
+
+#if SMP_INCLUDED == TRUE && BLE_INCLUDED == FALSE
+#error "can't have SMP without BLE"
 #endif
 
 #ifndef SMP_DEBUG
diff --git a/main/Android.mk b/main/Android.mk
index a2b868a..5230b32 100644
--- a/main/Android.mk
+++ b/main/Android.mk
@@ -99,7 +99,7 @@
 	$(bdroid_C_INCLUDES) \
 	external/tinyxml2
 
-LOCAL_CFLAGS += -DBUILDCFG $(bdroid_CFLAGS) -Werror -Wno-error=maybe-uninitialized -Wno-error=uninitialized
+LOCAL_CFLAGS += -DBUILDCFG $(bdroid_CFLAGS) -Werror -Wno-error=maybe-uninitialized -Wno-error=uninitialized -Wno-error=unused-parameter
 
 ifeq ($(TARGET_PRODUCT), full_crespo)
      LOCAL_CFLAGS += -DTARGET_CRESPO
@@ -129,7 +129,7 @@
 LOCAL_STATIC_LIBRARIES := libbt-brcm_gki libbt-brcm_bta libbt-brcm_stack libtinyxml2
 
 LOCAL_MODULE := bluetooth.default
-LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+LOCAL_MODULE_RELATIVE_PATH := hw
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := SHARED_LIBRARIES
 LOCAL_REQUIRED_MODULES := libbt-hci libbt-vendor bt_stack.conf bt_did.conf auto_pair_devlist.conf
diff --git a/main/bte_conf.c b/main/bte_conf.c
index e001d59..ddad0c7 100644
--- a/main/bte_conf.c
+++ b/main/bte_conf.c
@@ -35,6 +35,7 @@
 
 #include "bt_target.h"
 #include "bta_api.h"
+#include "bt_utils.h"
 
 /******************************************************************************
 **  Externs
@@ -130,6 +131,7 @@
 
 int device_name_cfg(char *p_conf_name, char *p_conf_value)
 {
+    UNUSED(p_conf_name);
     strcpy((char *)local_device_default_name, p_conf_value);
     return 0;
 }
@@ -138,6 +140,7 @@
 {
     char *p_token;
     unsigned int x;
+    UNUSED(p_conf_name);
 
     p_token = strtok(p_conf_value, CONF_COD_DELIMITERS);
     sscanf(p_token, "%x", &x);
@@ -154,6 +157,7 @@
 
 int logging_cfg_onoff(char *p_conf_name, char *p_conf_value)
 {
+    UNUSED(p_conf_name);
     if (strcmp(p_conf_value, "true") == 0)
         hci_logging_enabled = TRUE;
     else
@@ -163,12 +167,14 @@
 
 int logging_set_filepath(char *p_conf_name, char *p_conf_value)
 {
+    UNUSED(p_conf_name);
     strcpy(hci_logfile, p_conf_value);
     return 0;
 }
 
 int trace_cfg_onoff(char *p_conf_name, char *p_conf_value)
 {
+    UNUSED(p_conf_name);
     trace_conf_enabled = (strcmp(p_conf_value, "true") == 0) ? TRUE : FALSE;
     return 0;
 }
diff --git a/main/bte_main.c b/main/bte_main.c
index 62c6b6b..cf21456 100644
--- a/main/bte_main.c
+++ b/main/bte_main.c
@@ -36,6 +36,7 @@
 #include "bte.h"
 #include "bta_api.h"
 #include "bt_hci_lib.h"
+#include "bt_utils.h"
 
 /*******************************************************************************
 **  Constants & Macros
@@ -337,6 +338,8 @@
 *******************************************************************************/
 static void preload_wait_timeout(union sigval arg)
 {
+    UNUSED(arg);
+
     APPL_TRACE_ERROR2("...preload_wait_timeout (retried:%d/max-retry:%d)...",
                         preload_retry_cb.retry_counts,
                         PRELOAD_MAX_RETRY_ATTEMPTS);
@@ -559,8 +562,9 @@
 ******************************************************************************/
 static void preload_cb(TRANSAC transac, bt_hc_preload_result_t result)
 {
-    APPL_TRACE_EVENT1("HC preload_cb %d [0:SUCCESS 1:FAIL]", result);
+    UNUSED(transac);
 
+    APPL_TRACE_EVENT1("HC preload_cb %d [0:SUCCESS 1:FAIL]", result);
 
     if (result == BT_HC_PRELOAD_SUCCESS)
     {
@@ -583,6 +587,8 @@
 ******************************************************************************/
 static void postload_cb(TRANSAC transac, bt_hc_postload_result_t result)
 {
+    UNUSED(transac);
+
     APPL_TRACE_EVENT1("HC postload_cb %d", result);
 }
 
@@ -663,6 +669,8 @@
 ******************************************************************************/
 static int dealloc(TRANSAC transac, char *p_buf)
 {
+    UNUSED(p_buf);
+
     GKI_freebuf(transac);
     return BT_HC_STATUS_SUCCESS;
 }
@@ -690,6 +698,8 @@
 static int data_ind(TRANSAC transac, char *p_buf, int len)
 {
     BT_HDR *p_msg = (BT_HDR *) transac;
+    UNUSED(p_buf);
+    UNUSED(len);
 
     /*
     APPL_TRACE_DEBUG2("HC data_ind event=0x%04X (len=%d)", p_msg->event, len);
@@ -719,9 +729,9 @@
 ** Returns          bt_hc_status_t
 **
 ******************************************************************************/
-static int tx_result(TRANSAC transac, char *p_buf, \
-                      bt_hc_transmit_result_t result)
+static int tx_result(TRANSAC transac, char *p_buf, bt_hc_transmit_result_t result)
 {
+    UNUSED(p_buf);
     /*
     APPL_TRACE_DEBUG2("HC tx_result %d (event=%04X)", result, \
                       ((BT_HDR *)transac)->event);
diff --git a/stack/a2dp/a2d_sbc.c b/stack/a2dp/a2d_sbc.c
index a4e5255..3858b4a 100644
--- a/stack/a2dp/a2d_sbc.c
+++ b/stack/a2dp/a2d_sbc.c
@@ -24,12 +24,13 @@
  ******************************************************************************/
 
 #include "bt_target.h"
-
-#if (A2D_SBC_INCLUDED == TRUE)
 #include <string.h>
 #include "a2d_api.h"
 #include "a2d_int.h"
 #include "a2d_sbc.h"
+#include "bt_utils.h"
+
+#if (A2D_SBC_INCLUDED == TRUE)
 
 /*************************************************************************************************
  * SBC descramble code
@@ -398,4 +399,57 @@
     }
 }
 
+#else /* A2D_SBC_INCLUDED == TRUE */
+
+void A2D_SbcChkFrInit(UINT8 *p_pkt)
+{
+    UNUSED(p_pkt);
+}
+
+void A2D_SbcDescramble(UINT8 *p_pkt, UINT16 len)
+{
+    UNUSED(p_pkt);
+    UNUSED(len);
+}
+
+tA2D_STATUS A2D_BldSbcInfo(UINT8 media_type, tA2D_SBC_CIE *p_ie,
+                           UINT8 *p_result)
+{
+    UNUSED(media_type);
+    UNUSED(p_ie);
+    UNUSED(p_result);
+    return A2D_FAIL;
+}
+
+tA2D_STATUS A2D_ParsSbcInfo(tA2D_SBC_CIE *p_ie, UINT8 *p_info,
+                            BOOLEAN for_caps)
+{
+    UNUSED(p_ie);
+    UNUSED(p_info);
+    UNUSED(for_caps);
+    return A2D_FAIL;
+}
+
+void A2D_BldSbcMplHdr(UINT8 *p_dst, BOOLEAN frag, BOOLEAN start,
+                      BOOLEAN last, UINT8 num)
+{
+    UNUSED(p_dst);
+    UNUSED(frag);
+    UNUSED(start);
+    UNUSED(last);
+    UNUSED(num);
+}
+
+void A2D_ParsSbcMplHdr(UINT8 *p_src, BOOLEAN *p_frag,
+                       BOOLEAN *p_start, BOOLEAN *p_last,
+                       UINT8 *p_num)
+{
+    UNUSED(p_src);
+    UNUSED(p_frag);
+    UNUSED(p_start);
+    UNUSED(p_last);
+    UNUSED(p_num);
+}
+
+
 #endif /* A2D_SBC_INCLUDED == TRUE */
diff --git a/stack/avct/avct_api.c b/stack/avct/avct_api.c
index 7e37a90..d590cb5 100644
--- a/stack/avct/avct_api.c
+++ b/stack/avct/avct_api.c
@@ -25,6 +25,7 @@
 #include <string.h>
 #include "data_types.h"
 #include "bt_target.h"
+#include "bt_utils.h"
 #include "gki.h"
 #include "l2c_api.h"
 #include "l2cdefs.h"
@@ -53,6 +54,8 @@
 *******************************************************************************/
 void AVCT_Register(UINT16 mtu, UINT16 mtu_br, UINT8 sec_mask)
 {
+    UNUSED(mtu_br);
+
     AVCT_TRACE_API0("AVCT_Register");
 
     /* register PSM with L2CAP */
@@ -289,6 +292,8 @@
 
     return result;
 #else
+    UNUSED(handle);
+    UNUSED(role);
     return AVCT_NO_RESOURCES;
 #endif
 }
@@ -326,6 +331,7 @@
     }
     return result;
 #else
+    UNUSED(handle);
     return AVCT_NO_RESOURCES;
 #endif
 }
@@ -350,6 +356,8 @@
     {
         peer_mtu = p_ccb->p_bcb->peer_mtu;
     }
+#else
+    UNUSED(handle);
 #endif
     return peer_mtu;
 }
diff --git a/stack/avct/avct_l2c.c b/stack/avct/avct_l2c.c
index ef0f5fc..aabcd0e 100644
--- a/stack/avct/avct_l2c.c
+++ b/stack/avct/avct_l2c.c
@@ -25,6 +25,7 @@
 #include <string.h>
 #include "data_types.h"
 #include "bt_target.h"
+#include "bt_utils.h"
 #include "avct_api.h"
 #include "avct_int.h"
 #include "l2c_api.h"
@@ -105,6 +106,7 @@
     tAVCT_LCB       *p_lcb;
     UINT16          result = L2CAP_CONN_OK;
     tL2CAP_CFG_INFO cfg;
+    UNUSED(psm);
 
     /* do we already have a channel for this peer? */
     if ((p_lcb = avct_lcb_by_bd(bd_addr)) == NULL)
diff --git a/stack/avct/avct_lcb.c b/stack/avct/avct_lcb.c
index bb3f447..6bc7e51 100644
--- a/stack/avct/avct_lcb.c
+++ b/stack/avct/avct_lcb.c
@@ -26,6 +26,7 @@
 #include <string.h>
 #include "data_types.h"
 #include "bt_target.h"
+#include "bt_utils.h"
 #include "avct_api.h"
 #include "avct_int.h"
 #include "gki.h"
@@ -351,6 +352,7 @@
     tAVCT_CCB   *p_ccb = &avct_cb.ccb[0];
     BOOLEAN     found = FALSE;
     int         i;
+    UNUSED(p_data);
 
     AVCT_TRACE_DEBUG1("avct_lcb_dealloc %d", p_lcb->allocated);
 
diff --git a/stack/avct/avct_lcb_act.c b/stack/avct/avct_lcb_act.c
index b883517..23ad332 100644
--- a/stack/avct/avct_lcb_act.c
+++ b/stack/avct/avct_lcb_act.c
@@ -25,6 +25,7 @@
 #include <string.h>
 #include "data_types.h"
 #include "bt_target.h"
+#include "bt_utils.h"
 #include "avct_api.h"
 #include "avct_int.h"
 #include "gki.h"
@@ -88,17 +89,35 @@
             GKI_freebuf(p_lcb->p_rx_msg);
             AVCT_TRACE_WARNING0("Got start during reassembly");
         }
-        p_lcb->p_rx_msg = p_buf;
+        /* Allocate bigger buffer for reassembly. As lower layers are
+         * not aware of possible packet size after reassembly they
+         * would have allocated smaller buffer.
+         */
+        p_lcb->p_rx_msg = (BT_HDR*)GKI_getbuf(GKI_MAX_BUF_SIZE);
+        if (p_lcb->p_rx_msg == NULL)
+        {
+            AVCT_TRACE_ERROR0 ("Cannot alloc buffer for reassembly !!");
+            GKI_freebuf(p_buf);
+        }
+        else
+        {
+            memcpy (p_lcb->p_rx_msg, p_buf,
+                sizeof(BT_HDR) + p_buf->offset + p_buf->len);
+            /* Free original buffer */
+            GKI_freebuf(p_buf);
 
-        /* copy first header byte over nosp */
-        *(p + 1) = *p;
+            /* update p to point to new buffer */
+            p = (UINT8 *)(p_lcb->p_rx_msg + 1) + p_lcb->p_rx_msg->offset;
 
-        /* set offset to point to where to copy next */
-        p_lcb->p_rx_msg->offset += p_lcb->p_rx_msg->len;
+            /* copy first header byte over nosp */
+            *(p + 1) = *p;
 
-        /* adjust length for packet header */
-        p_lcb->p_rx_msg->len -= 1;
+            /* set offset to point to where to copy next */
+            p_lcb->p_rx_msg->offset += p_lcb->p_rx_msg->len;
 
+            /* adjust length for packet header */
+            p_lcb->p_rx_msg->len -= 1;
+        }
         p_ret = NULL;
     }
     /* continue or end */
@@ -170,6 +189,7 @@
 void avct_lcb_chnl_open(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data)
 {
     UINT16 result = AVCT_RESULT_FAIL;
+    UNUSED(p_data);
 
     BTM_SetOutService(p_lcb->peer_addr, BTM_SEC_SERVICE_AVCTP, 0);
     /* call l2cap connect req */
@@ -193,6 +213,8 @@
 *******************************************************************************/
 void avct_lcb_unbind_disc(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data)
 {
+    UNUSED(p_lcb);
+
     avct_ccb_dealloc(p_data->p_ccb, AVCT_DISCONNECT_CFM_EVT, 0, NULL);
 }
 
@@ -290,6 +312,7 @@
 {
     tAVCT_CCB           *p_ccb = &avct_cb.ccb[0];
     int                 i;
+    UNUSED(p_data);
 
     for (i = 0; i < AVCT_NUM_CONN; i++, p_ccb++)
     {
@@ -416,6 +439,8 @@
 *******************************************************************************/
 void avct_lcb_chnl_disc(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data)
 {
+    UNUSED(p_data);
+
     L2CA_DisconnectReq(p_lcb->ch_lcid);
 }
 
@@ -432,6 +457,8 @@
 *******************************************************************************/
 void avct_lcb_bind_fail(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data)
 {
+    UNUSED(p_lcb);
+
     avct_ccb_dealloc(p_data->p_ccb, AVCT_CONNECT_CFM_EVT, AVCT_RESULT_FAIL, NULL);
 }
 
@@ -488,6 +515,8 @@
 *******************************************************************************/
 void avct_lcb_discard_msg(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data)
 {
+    UNUSED(p_lcb);
+
     AVCT_TRACE_WARNING0("Dropping msg");
 
     GKI_freebuf(p_data->ul_msg.p_buf);
@@ -623,6 +652,8 @@
 *******************************************************************************/
 void avct_lcb_free_msg_ind(tAVCT_LCB *p_lcb, tAVCT_LCB_EVT *p_data)
 {
+    UNUSED(p_lcb);
+
     if (p_data)
         GKI_freebuf(p_data->p_buf);
     return;
diff --git a/stack/avdt/avdt_ad.c b/stack/avdt/avdt_ad.c
index 92f429a..7fe665c 100644
--- a/stack/avdt/avdt_ad.c
+++ b/stack/avdt/avdt_ad.c
@@ -25,6 +25,7 @@
 #include <string.h>
 #include "data_types.h"
 #include "bt_target.h"
+#include "bt_utils.h"
 #include "avdt_api.h"
 #include "avdtc_api.h"
 #include "avdt_int.h"
@@ -322,6 +323,7 @@
     tAVDT_CCB   *p_ccb;
     tAVDT_SCB   *p_scb;
     tAVDT_SCB_TC_CLOSE  close;
+    UNUSED(reason);
 
     close.old_tc_state = p_tbl->state;
     /* clear avdt_ad_tc_tbl entry */
diff --git a/stack/avdt/avdt_ccb.c b/stack/avdt/avdt_ccb.c
index 9cb40b2..c2ef2f4 100644
--- a/stack/avdt/avdt_ccb.c
+++ b/stack/avdt/avdt_ccb.c
@@ -26,6 +26,7 @@
 #include <string.h>
 #include "data_types.h"
 #include "bt_target.h"
+#include "bt_utils.h"
 #include "avdt_api.h"
 #include "avdtc_api.h"
 #include "avdt_int.h"
@@ -309,9 +310,10 @@
     state_table = avdt_ccb_st_tbl[p_ccb->state];
 
     /* set next state */
-    if (p_ccb->state != state_table[event][AVDT_CCB_NEXT_STATE])
+    if (p_ccb->state != state_table[event][AVDT_CCB_NEXT_STATE]) {
         BTTRC_AVDT_CCB_STATE(state_table[event][AVDT_CCB_NEXT_STATE]);
-    p_ccb->state = state_table[event][AVDT_CCB_NEXT_STATE];
+        p_ccb->state = state_table[event][AVDT_CCB_NEXT_STATE];
+    }
 
     /* execute action functions */
     for (i = 0; i < AVDT_CCB_ACTIONS; i++)
@@ -414,6 +416,8 @@
 *******************************************************************************/
 void avdt_ccb_dealloc(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
 {
+    UNUSED(p_data);
+
     AVDT_TRACE_DEBUG1("avdt_ccb_dealloc %d", avdt_ccb_to_idx(p_ccb));
     btu_stop_timer(&p_ccb->timer_entry);
     memset(p_ccb, 0, sizeof(tAVDT_CCB));
diff --git a/stack/avdt/avdt_ccb_act.c b/stack/avdt/avdt_ccb_act.c
index 12c11b4..1249c63 100644
--- a/stack/avdt/avdt_ccb_act.c
+++ b/stack/avdt/avdt_ccb_act.c
@@ -26,6 +26,7 @@
 #include <string.h>
 #include "data_types.h"
 #include "bt_target.h"
+#include "bt_utils.h"
 #include "avdt_api.h"
 #include "avdtc_api.h"
 #include "avdt_int.h"
@@ -86,6 +87,8 @@
 *******************************************************************************/
 void avdt_ccb_chan_open(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
 {
+    UNUSED(p_data);
+
     BTM_SetOutService(p_ccb->peer_addr, BTM_SEC_SERVICE_AVDTP, AVDT_CHAN_SIG);
     avdt_ad_open_req(AVDT_CHAN_SIG, p_ccb, NULL, AVDT_INT);
 }
@@ -103,6 +106,8 @@
 *******************************************************************************/
 void avdt_ccb_chan_close(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
 {
+    UNUSED(p_data);
+
     /* close the transport channel used by this CCB */
     avdt_ad_close_req(AVDT_CHAN_SIG, p_ccb, NULL);
 }
@@ -122,6 +127,7 @@
 {
     int         i;
     tAVDT_SCB   *p_scb = &avdt_cb.scb[0];
+    UNUSED(p_data);
 
     /* see if there are any active scbs associated with this ccb */
     for (i = 0; i < AVDT_NUM_SEPS; i++, p_scb++)
@@ -666,6 +672,7 @@
     int             i;
     tAVDT_SCB       *p_scb = &avdt_cb.scb[0];
     UINT8           err_code = AVDT_ERR_CONNECT;
+    UNUSED(p_data);
 
     /* clear the ccb */
     avdt_ccb_clear_ccb(p_ccb);
@@ -754,6 +761,8 @@
 *******************************************************************************/
 void avdt_ccb_free_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
 {
+    UNUSED(p_data);
+
     if (p_ccb->p_curr_cmd != NULL)
     {
         GKI_freebuf(p_ccb->p_curr_cmd);
@@ -838,6 +847,7 @@
 void avdt_ccb_snd_cmd(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
 {
     BT_HDR  *p_msg;
+    UNUSED(p_data);
 
     /* do we have commands to send?  send next command;  make sure we're clear;
     ** not congested, not sending fragment, not waiting for response
@@ -870,6 +880,7 @@
 void avdt_ccb_snd_msg(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
 {
     BT_HDR      *p_msg;
+    UNUSED(p_data);
 
     /* if not congested */
     if (!p_ccb->cong)
@@ -911,6 +922,8 @@
 *******************************************************************************/
 void avdt_ccb_set_reconn(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
 {
+    UNUSED(p_data);
+
     p_ccb->reconn = TRUE;
 }
 
@@ -926,6 +939,8 @@
 *******************************************************************************/
 void avdt_ccb_clr_reconn(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
 {
+    UNUSED(p_data);
+
     p_ccb->reconn = FALSE;
 }
 
@@ -944,6 +959,7 @@
 void avdt_ccb_chk_reconn(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
 {
     UINT8   err_code = AVDT_ERR_CONNECT;
+    UNUSED(p_data);
 
     if (p_ccb->reconn)
     {
@@ -977,6 +993,8 @@
 *******************************************************************************/
 void avdt_ccb_chk_timer(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
 {
+    UNUSED(p_data);
+
     if (p_ccb->timer_entry.event == BTU_TTYPE_AVDT_CCB_IDLE)
     {
         btu_stop_timer(&p_ccb->timer_entry);
@@ -1036,6 +1054,8 @@
 *******************************************************************************/
 void avdt_ccb_do_disconn(tAVDT_CCB *p_ccb, tAVDT_CCB_EVT *p_data)
 {
+    UNUSED(p_data);
+
     /* clear any pending commands */
     avdt_ccb_clear_cmds(p_ccb, NULL);
 
@@ -1058,6 +1078,7 @@
     tAVDT_CTRL_CBACK    *p_cback;
     BD_ADDR             bd_addr;
     tAVDT_CTRL          avdt_ctrl;
+    UNUSED(p_data);
 
     /* clear any pending commands */
     avdt_ccb_clear_cmds(p_ccb, NULL);
diff --git a/stack/avdt/avdt_l2c.c b/stack/avdt/avdt_l2c.c
index 20979b4..2256a90 100644
--- a/stack/avdt/avdt_l2c.c
+++ b/stack/avdt/avdt_l2c.c
@@ -25,6 +25,7 @@
 #include <string.h>
 #include "data_types.h"
 #include "bt_target.h"
+#include "bt_utils.h"
 #include "avdt_api.h"
 #include "avdtc_api.h"
 #include "avdt_int.h"
@@ -74,6 +75,7 @@
     tAVDT_CCB       *p_ccb = NULL;
     tL2CAP_CFG_INFO cfg;
     tAVDT_TC_TBL    *p_tbl;
+    UNUSED(p_ref_data);
 
     AVDT_TRACE_DEBUG1("avdt_sec_check_complete_term res: %d", res);
     if (!bd_addr)
@@ -130,6 +132,7 @@
     tAVDT_CCB       *p_ccb = NULL;
     tL2CAP_CFG_INFO cfg;
     tAVDT_TC_TBL    *p_tbl;
+    UNUSED(p_ref_data);
 
     AVDT_TRACE_DEBUG1("avdt_sec_check_complete_orig res: %d", res);
     if (bd_addr)
@@ -174,6 +177,7 @@
     UINT16          result;
     tL2CAP_CFG_INFO cfg;
     tBTM_STATUS rc;
+    UNUSED(psm);
 
     /* do we already have a control channel for this peer? */
     if ((p_ccb = avdt_ccb_by_bd(bd_addr)) == NULL)
diff --git a/stack/avdt/avdt_msg.c b/stack/avdt/avdt_msg.c
index 5d9c2fb..a1c57b3 100644
--- a/stack/avdt/avdt_msg.c
+++ b/stack/avdt/avdt_msg.c
@@ -29,6 +29,7 @@
 #include <string.h>
 #include "data_types.h"
 #include "bt_target.h"
+#include "bt_utils.h"
 #include "avdt_api.h"
 #include "avdtc_api.h"
 #include "avdt_int.h"
@@ -373,6 +374,8 @@
 *******************************************************************************/
 static void avdt_msg_bld_none(UINT8 **p, tAVDT_MSG *p_msg)
 {
+    UNUSED(p);
+    UNUSED(p_msg);
     return;
 }
 
@@ -688,8 +691,12 @@
                 /* verify length */
                 AVDT_TRACE_WARNING2("psc_mask=0x%x elem_len=%d", p_cfg->psc_mask, elem_len);
                 if( ((0 == (p_cfg->psc_mask & (AVDT_PSC_RECOV|AVDT_PSC_REPORT))) && (elem_len != 3))
-                    || ((p_cfg->psc_mask & AVDT_PSC_RECOV) && (elem_len != 7))
-                    || ((p_cfg->psc_mask & AVDT_PSC_REPORT) && (elem_len != 5)) )
+                    || (((p_cfg->psc_mask & AVDT_PSC_REPORT) && !(p_cfg->psc_mask & AVDT_PSC_RECOV))
+                    && (elem_len != 5))
+                    || ((!(p_cfg->psc_mask & AVDT_PSC_REPORT) && (p_cfg->psc_mask & AVDT_PSC_RECOV))
+                    && (elem_len != 5))
+                    || (((p_cfg->psc_mask & AVDT_PSC_REPORT) && (p_cfg->psc_mask & AVDT_PSC_RECOV))
+                    && (elem_len != 7)) )
                 {
                     err = AVDT_ERR_MUX_FMT;
                     break;
@@ -771,6 +778,9 @@
 *******************************************************************************/
 static UINT8 avdt_msg_prs_none(tAVDT_MSG *p_msg, UINT8 *p, UINT16 len)
 {
+    UNUSED(p_msg);
+    UNUSED(p);
+    UNUSED(len);
     return 0;
 }
 
@@ -1644,6 +1654,7 @@
     BT_HDR      *p_buf;
     UINT8       *p;
     UINT8       *p_start;
+    UNUSED(sig_id);
 
     /* get a buffer */
     p_buf = (BT_HDR *) GKI_getpoolbuf(AVDT_CMD_POOL_ID);
@@ -1656,11 +1667,9 @@
     /* calculate length */
     p_buf->len = (UINT16) (p - p_start);
 
-    /* stash sig, label, and message type in buf */
-    p_buf->event = sig_id;
+    /* stash label, and message type in buf */
     AVDT_BLD_LAYERSPEC(p_buf->layer_specific, AVDT_MSG_TYPE_GRJ, p_params->hdr.label);
-    //p_buf->event = 0;
-    //AVDT_BLD_LAYERSPEC(p_buf->layer_specific, 0, p_params->hdr.label);
+    p_buf->event = 0;
     AVDT_TRACE_DEBUG0("avdt_msg_send_grej");
 
     /* queue message and trigger ccb to send it */
diff --git a/stack/avdt/avdt_scb.c b/stack/avdt/avdt_scb.c
index 07c141f..d0c9e0f 100644
--- a/stack/avdt/avdt_scb.c
+++ b/stack/avdt/avdt_scb.c
@@ -26,6 +26,7 @@
 #include <string.h>
 #include "data_types.h"
 #include "bt_target.h"
+#include "bt_utils.h"
 #include "avdt_api.h"
 #include "avdtc_api.h"
 #include "avdt_int.h"
@@ -539,10 +540,10 @@
     state_table = avdt_scb_st_tbl[p_scb->state];
 
     /* set next state */
-    if (p_scb->state != state_table[event][AVDT_SCB_NEXT_STATE])
+    if (p_scb->state != state_table[event][AVDT_SCB_NEXT_STATE]) {
         BTTRC_AVDT_SCB_STATE(state_table[event][AVDT_SCB_NEXT_STATE]);
-    p_scb->state = state_table[event][AVDT_SCB_NEXT_STATE];
-
+        p_scb->state = state_table[event][AVDT_SCB_NEXT_STATE];
+    }
 
     /* execute action functions */
     for (i = 0; i < AVDT_SCB_ACTIONS; i++)
@@ -647,6 +648,7 @@
 #if AVDT_MULTIPLEXING == TRUE
     void *p_buf;
 #endif
+    UNUSED(p_data);
 
     AVDT_TRACE_DEBUG1("avdt_scb_dealloc hdl=%d", avdt_scb_to_hdl(p_scb));
     btu_stop_timer(&p_scb->timer_entry);
diff --git a/stack/avdt/avdt_scb_act.c b/stack/avdt/avdt_scb_act.c
index 66f9b7d..75242ac 100644
--- a/stack/avdt/avdt_scb_act.c
+++ b/stack/avdt/avdt_scb_act.c
@@ -26,6 +26,7 @@
 #include <string.h>
 #include "data_types.h"
 #include "bt_target.h"
+#include "bt_utils.h"
 #include "avdt_api.h"
 #include "avdtc_api.h"
 #include "avdt_int.h"
@@ -103,6 +104,8 @@
 *******************************************************************************/
 void avdt_scb_hdl_abort_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
+    UNUSED(p_scb);
+    UNUSED(p_data);
     return;
 }
 
@@ -167,6 +170,8 @@
 *******************************************************************************/
 void avdt_scb_hdl_getconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
+    UNUSED(p_scb);
+    UNUSED(p_data);
     return;
 }
 
@@ -215,6 +220,8 @@
 *******************************************************************************/
 void avdt_scb_hdl_open_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
+    UNUSED(p_data);
+
     /* initiate opening of trans channels for this SEID */
     p_scb->role = AVDT_OPEN_INT;
     avdt_ad_open_req(AVDT_CHAN_MEDIA, p_scb->p_ccb, p_scb, AVDT_INT);
@@ -668,6 +675,8 @@
 *******************************************************************************/
 void avdt_scb_drop_pkt(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
+    UNUSED(p_scb);
+
     GKI_freebuf(p_data->p_pkt);
     AVDT_TRACE_WARNING0("Dropped incoming media packet");
 }
@@ -874,6 +883,7 @@
 void avdt_scb_hdl_setconfig_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
     tAVDT_EVT_HDR   single;
+    UNUSED(p_data);
 
     if (p_scb->p_ccb != NULL)
     {
@@ -898,6 +908,8 @@
 *******************************************************************************/
 void avdt_scb_hdl_start_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
+    UNUSED(p_data);
+
     (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb),
                               p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL,
                               AVDT_START_IND_EVT,
@@ -934,6 +946,8 @@
 *******************************************************************************/
 void avdt_scb_hdl_suspend_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
+    UNUSED(p_data);
+
     (*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb),
                               p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL,
                               AVDT_SUSPEND_IND_EVT,
@@ -1220,7 +1234,7 @@
 
         p_data->apiwrite.p_buf->len += AVDT_MEDIA_HDR_SIZE;
         p_data->apiwrite.p_buf->offset -= AVDT_MEDIA_HDR_SIZE;
-
+        p_scb->media_seq++;
         p = (UINT8 *)(p_data->apiwrite.p_buf + 1) + p_data->apiwrite.p_buf->offset;
 
         UINT8_TO_BE_STREAM(p, AVDT_MEDIA_OCTET1);
@@ -1230,8 +1244,6 @@
         UINT32_TO_BE_STREAM(p, ssrc);
     }
 
-    p_scb->media_seq++;
-
     /* store it */
     p_scb->p_pkt = p_data->apiwrite.p_buf;
 }
@@ -1344,6 +1356,7 @@
 void avdt_scb_snd_abort_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
     tAVDT_EVT_HDR   hdr;
+    UNUSED(p_data);
 
     if (p_scb->p_ccb != NULL)
     {
@@ -1366,6 +1379,8 @@
 *******************************************************************************/
 void avdt_scb_snd_abort_rsp(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
+    UNUSED(p_scb);
+
     avdt_msg_send_rsp(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx), AVDT_SIG_ABORT,
                       &p_data->msg);
 }
@@ -1382,6 +1397,7 @@
 void avdt_scb_snd_close_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
     tAVDT_EVT_HDR   hdr;
+    UNUSED(p_data);
 
     p_scb->role = AVDT_CLOSE_INT;
 
@@ -1452,6 +1468,7 @@
 void avdt_scb_snd_getconfig_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
     tAVDT_EVT_HDR   hdr;
+    UNUSED(p_data);
 
     hdr.seid = p_scb->peer_seid;
 
@@ -1484,6 +1501,7 @@
 void avdt_scb_snd_open_req(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
     tAVDT_EVT_HDR   hdr;
+    UNUSED(p_data);
 
     hdr.seid = p_scb->peer_seid;
 
@@ -1696,6 +1714,8 @@
 *******************************************************************************/
 void avdt_scb_snd_tc_close(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
+    UNUSED(p_data);
+
 #if AVDT_REPORTING == TRUE
     if(p_scb->curr_cfg.psc_mask & AVDT_PSC_REPORT)
         avdt_ad_close_req(AVDT_CHAN_REPORT, p_scb->p_ccb, p_scb);
@@ -1716,6 +1736,7 @@
 void avdt_scb_cb_err(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
     tAVDT_CTRL          avdt_ctrl;
+    UNUSED(p_data);
 
     /* set error code and parameter */
     avdt_ctrl.hdr.err_code = AVDT_ERR_BAD_STATE;
@@ -1755,6 +1776,8 @@
 *******************************************************************************/
 void avdt_scb_rej_state(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
+    UNUSED(p_scb);
+
     p_data->msg.hdr.err_code = AVDT_ERR_BAD_STATE;
     p_data->msg.hdr.err_param = 0;
     avdt_msg_send_rej(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx),
@@ -1773,6 +1796,8 @@
 *******************************************************************************/
 void avdt_scb_rej_in_use(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
+    UNUSED(p_scb);
+
     p_data->msg.hdr.err_code = AVDT_ERR_IN_USE;
     p_data->msg.hdr.err_param = 0;
     avdt_msg_send_rej(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx),
@@ -1791,6 +1816,8 @@
 *******************************************************************************/
 void avdt_scb_rej_not_in_use(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
+    UNUSED(p_scb);
+
     p_data->msg.hdr.err_code = AVDT_ERR_NOT_IN_USE;
     p_data->msg.hdr.err_param = 0;
     avdt_msg_send_rej(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx),
@@ -1808,6 +1835,8 @@
 *******************************************************************************/
 void avdt_scb_set_remove(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
+    UNUSED(p_data);
+
     p_scb->remove = TRUE;
 }
 
@@ -1866,6 +1895,7 @@
 #if AVDT_MULTIPLEXING == TRUE
     BT_HDR          *p_frag;
 #endif
+    UNUSED(p_data);
 
     /* set error code and parameter */
     avdt_ctrl.hdr.err_code = AVDT_ERR_BAD_STATE;
@@ -1930,6 +1960,7 @@
     UINT8   res = AVDT_AD_SUCCESS;
     tAVDT_SCB_EVT data;
 #endif
+    UNUSED(p_data);
 
     avdt_ctrl.hdr.err_code = 0;
 
@@ -2003,6 +2034,8 @@
 *******************************************************************************/
 void avdt_scb_tc_timer(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
+    UNUSED(p_data);
+
     btu_start_timer(&p_scb->timer_entry, BTU_TTYPE_AVDT_SCB_TC, AVDT_SCB_TC_DISC_TOUT);
 }
 
@@ -2017,6 +2050,8 @@
 *******************************************************************************/
 void avdt_scb_clr_vars(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)
 {
+    UNUSED(p_data);
+
     p_scb->in_use = FALSE;
     p_scb->p_ccb = NULL;
     p_scb->peer_seid = 0;
diff --git a/stack/avrc/avrc_bld_tg.c b/stack/avrc/avrc_bld_tg.c
index d201b9d..6fe645a 100755
--- a/stack/avrc/avrc_bld_tg.c
+++ b/stack/avrc/avrc_bld_tg.c
@@ -21,6 +21,7 @@
 #include "avrc_api.h"
 #include "avrc_defs.h"
 #include "avrc_int.h"
+#include "bt_utils.h"
 
 /*****************************************************************************
 **  Global data
@@ -276,6 +277,9 @@
 *******************************************************************************/
 static tAVRC_STS avrc_bld_set_app_setting_value_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt)
 {
+    UNUSED(p_rsp);
+    UNUSED(p_pkt);
+
     /* nothing to be added. */
     AVRC_TRACE_API0("avrc_bld_set_app_setting_value_rsp");
     return AVRC_STS_NO_ERROR;
@@ -401,6 +405,9 @@
 *******************************************************************************/
 static tAVRC_STS avrc_bld_inform_charset_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt)
 {
+    UNUSED(p_rsp);
+    UNUSED(p_pkt);
+
     /* nothing to be added. */
     AVRC_TRACE_API0("avrc_bld_inform_charset_rsp");
     return AVRC_STS_NO_ERROR;
@@ -419,6 +426,9 @@
 *******************************************************************************/
 static tAVRC_STS avrc_bld_inform_battery_status_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt)
 {
+    UNUSED(p_rsp);
+    UNUSED(p_pkt);
+
     /* nothing to be added. */
     AVRC_TRACE_API0("avrc_bld_inform_battery_status_rsp");
     return AVRC_STS_NO_ERROR;
@@ -653,6 +663,9 @@
 *******************************************************************************/
 static tAVRC_STS avrc_bld_next_rsp (tAVRC_RSP *p_rsp, BT_HDR *p_pkt)
 {
+    UNUSED(p_rsp);
+    UNUSED(p_pkt);
+
     /* nothing to be added. */
     AVRC_TRACE_API0("avrc_bld_next_rsp");
     return AVRC_STS_NO_ERROR;
@@ -800,6 +813,7 @@
     tAVRC_STS status = AVRC_STS_BAD_PARAM;
     BT_HDR *p_pkt;
     BOOLEAN alloc = FALSE;
+    UNUSED(handle);
 
     if (!p_rsp || !pp_pkt)
     {
diff --git a/stack/avrc/avrc_pars_ct.c b/stack/avrc/avrc_pars_ct.c
index 85a9233..f3b4af5 100755
--- a/stack/avrc/avrc_pars_ct.c
+++ b/stack/avrc/avrc_pars_ct.c
@@ -21,6 +21,7 @@
 #include "avrc_api.h"
 #include "avrc_defs.h"
 #include "avrc_int.h"
+#include "bt_utils.h"
 
 /*****************************************************************************
 **  Global data
@@ -39,7 +40,7 @@
 **                  Otherwise, the error code defined by AVRCP 1.4
 **
 *******************************************************************************/
-static tAVRC_STS avrc_pars_vendor_rsp(tAVRC_MSG_VENDOR *p_msg, tAVRC_RESPONSE *p_result, UINT8 *p_buf, UINT16 buf_len)
+static tAVRC_STS avrc_pars_vendor_rsp(tAVRC_MSG_VENDOR *p_msg, tAVRC_RESPONSE *p_result)
 {
     tAVRC_STS  status = AVRC_STS_NO_ERROR;
     UINT8   *p = p_msg->p_vendor_data;
@@ -117,13 +118,15 @@
 {
     tAVRC_STS  status = AVRC_STS_INTERNAL_ERR;
     UINT16  id;
+    UNUSED(p_buf);
+    UNUSED(buf_len);
 
     if (p_msg && p_result)
     {
         switch (p_msg->hdr.opcode)
         {
         case AVRC_OP_VENDOR:     /*  0x00    Vendor-dependent commands */
-            status = avrc_pars_vendor_rsp(&p_msg->vendor, p_result, p_buf, buf_len);
+            status = avrc_pars_vendor_rsp(&p_msg->vendor, p_result);
             break;
 
         case AVRC_OP_PASS_THRU:  /*  0x7C    panel subunit opcode */
@@ -139,7 +142,7 @@
             break;
         }
         p_result->rsp.opcode = p_msg->hdr.opcode;
-    p_result->rsp.status = status;
+        p_result->rsp.status = status;
     }
     return status;
 }
diff --git a/stack/avrc/avrc_utils.c b/stack/avrc/avrc_utils.c
index 939a26f..01254fa 100755
--- a/stack/avrc/avrc_utils.c
+++ b/stack/avrc/avrc_utils.c
@@ -114,8 +114,7 @@
          break;
     }
 
-    if (attrib >= AVRC_PLAYER_SETTING_LOW_MENU_EXT &&
-       attrib <= AVRC_PLAYER_SETTING_HIGH_MENU_EXT)
+    if (attrib >= AVRC_PLAYER_SETTING_LOW_MENU_EXT)
        result = TRUE;
 
     if (!result)
@@ -140,7 +139,7 @@
     BOOLEAN result=FALSE;
 
     if ( (attr >= AVRC_PLAYER_SETTING_EQUALIZER && attr <= AVRC_PLAYER_SETTING_SCAN) ||
-         (attr >= AVRC_PLAYER_SETTING_LOW_MENU_EXT && attr <= AVRC_PLAYER_SETTING_HIGH_MENU_EXT) )
+         (attr >= AVRC_PLAYER_SETTING_LOW_MENU_EXT) )
     {
        result = TRUE;
     }
diff --git a/stack/bnep/bnep_main.c b/stack/bnep/bnep_main.c
index 12c9da0..45d3b14 100644
--- a/stack/bnep/bnep_main.c
+++ b/stack/bnep/bnep_main.c
@@ -41,6 +41,7 @@
 
 #include "bnep_api.h"
 #include "bnep_int.h"
+#include "bt_utils.h"
 
 
 /********************************************************************************/
@@ -120,6 +121,7 @@
 static void bnep_connect_ind (BD_ADDR  bd_addr, UINT16 l2cap_cid, UINT16 psm, UINT8 l2cap_id)
 {
     tBNEP_CONN    *p_bcb = bnepu_find_bcb_by_bd_addr (bd_addr);
+    UNUSED(psm);
 
     /* If we are not acting as server, or already have a connection, or have */
     /* no more resources to handle the connection, reject the connection.    */
diff --git a/stack/bnep/bnep_utils.c b/stack/bnep/bnep_utils.c
index 205eeeb..0a8fd6d 100644
--- a/stack/bnep/bnep_utils.c
+++ b/stack/bnep/bnep_utils.c
@@ -29,6 +29,7 @@
 #include "bnep_int.h"
 #include "btu.h"
 #include "btm_int.h"
+#include "bt_utils.h"
 
 
 /********************************************************************************/
@@ -1213,6 +1214,7 @@
     tBNEP_CONN      *p_bcb = (tBNEP_CONN *)p_ref_data;
     UINT16          resp_code = BNEP_SETUP_CONN_OK;
     BOOLEAN         is_role_change;
+    UNUSED(bd_addr);
 
     BNEP_TRACE_EVENT1 ("BNEP security callback returned result %d", result);
     if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED)
diff --git a/stack/btm/btm_acl.c b/stack/btm/btm_acl.c
index 629c8b4..49ace6e 100644
--- a/stack/btm/btm_acl.c
+++ b/stack/btm/btm_acl.c
@@ -37,6 +37,8 @@
 #include "btm_int.h"
 #include "l2c_int.h"
 #include "hcidefs.h"
+#include "bd.h"
+#include "bt_utils.h"
 
 static void btm_establish_continue (tACL_CONN *p_acl_cb);
 static void btm_read_remote_features (UINT16 handle);
@@ -178,6 +180,62 @@
     /* If here, no BD Addr found */
     return(xx);
 }
+
+#if BTM_BLE_PRIVACY_SPT == TRUE
+/*******************************************************************************
+**
+** Function         btm_ble_get_acl_remote_addr
+**
+** Description      This function reads the active remote address used for the
+**                  connection.
+**
+** Returns          success return TRUE, otherwise FALSE.
+**
+*******************************************************************************/
+BOOLEAN btm_ble_get_acl_remote_addr(tBTM_SEC_DEV_REC *p_dev_rec, BD_ADDR conn_addr,
+                                    tBLE_ADDR_TYPE *p_addr_type)
+{
+#if BLE_INCLUDED == TRUE
+    BOOLEAN         st = TRUE;
+
+    if (p_dev_rec == NULL)
+    {
+        BTM_TRACE_ERROR0("btm_ble_get_acl_remote_addr can not find device with matching address");
+        return FALSE;
+    }
+
+    switch (p_dev_rec->ble.active_addr_type)
+    {
+    case BTM_BLE_ADDR_PSEUDO:
+        memcpy(conn_addr, p_dev_rec->bd_addr, BD_ADDR_LEN);
+        * p_addr_type = p_dev_rec->ble.ble_addr_type;
+        break;
+
+    case BTM_BLE_ADDR_RRA:
+        memcpy(conn_addr, p_dev_rec->ble.cur_rand_addr, BD_ADDR_LEN);
+        * p_addr_type = BLE_ADDR_RANDOM;
+        break;
+
+    case BTM_BLE_ADDR_STATIC:
+        memcpy(conn_addr, p_dev_rec->ble.static_addr, BD_ADDR_LEN);
+        * p_addr_type = p_dev_rec->ble.static_addr_type;
+        break;
+
+    default:
+        BTM_TRACE_ERROR1("Unknown active address: %d", p_dev_rec->ble.active_addr_type);
+        st = FALSE;
+        break;
+    }
+
+    return st;
+#else
+    UNUSED(p_dev_rec);
+    UNUSED(conn_addr);
+    UNUSED(p_addr_type);
+    return FALSE;
+#endif
+}
+#endif
 /*******************************************************************************
 **
 ** Function         btm_acl_created
@@ -297,6 +355,10 @@
             /* If here, features are not known yet */
             if (p_dev_rec && is_le_link)
             {
+#if BTM_BLE_PRIVACY_SPT == TRUE
+                btm_ble_get_acl_remote_addr (p_dev_rec, p->active_remote_addr,
+                    &p->active_remote_addr_type);
+#endif
                 btm_establish_continue(p);
 
 #if (!defined(BTA_SKIP_BLE_READ_REMOTE_FEAT) || BTA_SKIP_BLE_READ_REMOTE_FEAT == FALSE)
diff --git a/stack/btm/btm_ble.c b/stack/btm/btm_ble.c
index f25bfd5..5b61b76 100644
--- a/stack/btm/btm_ble.c
+++ b/stack/btm/btm_ble.c
@@ -22,6 +22,9 @@
  *  security functions.
  *
  ******************************************************************************/
+#include "bt_target.h"
+
+#if BLE_INCLUDED == TRUE
 
 #include <string.h>
 
@@ -32,7 +35,11 @@
 #include "btm_ble_api.h"
 #include "smp_api.h"
 #include "l2c_int.h"
+#if (defined BLE_BRCM_INCLUDED && BLE_BRCM_INCLUDED == TRUE)
+#include "brcm_ble.h"
+#endif
 #include "gap_api.h"
+#include "bt_utils.h"
 
 #if SMP_INCLUDED == TRUE
 extern BOOLEAN AES_CMAC ( BT_OCTET16 key, UINT8 *input, UINT16 length, UINT16 tlen, UINT8 *p_signature);
@@ -63,7 +70,6 @@
 BOOLEAN BTM_SecAddBleDevice (BD_ADDR bd_addr, BD_NAME bd_name, tBT_DEVICE_TYPE dev_type,
                              tBLE_ADDR_TYPE addr_type)
 {
-#if BLE_INCLUDED == TRUE
     tBTM_SEC_DEV_REC  *p_dev_rec;
     UINT8               i = 0;
     tBTM_INQ_INFO      *p_info=NULL;
@@ -132,7 +138,6 @@
                           p_info->results.device_type, p_info->results.ble_addr_type);
     }
 
-#endif
     return(TRUE);
 }
 
@@ -153,7 +158,7 @@
 *******************************************************************************/
 BOOLEAN BTM_SecAddBleKey (BD_ADDR bd_addr, tBTM_LE_KEY_VALUE *p_le_key, tBTM_LE_KEY_TYPE key_type)
 {
-#if (BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE)
+#if SMP_INCLUDED == TRUE
     tBTM_SEC_DEV_REC  *p_dev_rec;
     BTM_TRACE_DEBUG0 ("BTM_SecAddBleKey");
     p_dev_rec = btm_find_dev (bd_addr);
@@ -200,7 +205,6 @@
 *******************************************************************************/
 void BTM_BleLoadLocalKeys(UINT8 key_type, tBTM_BLE_LOCAL_KEYS *p_key)
 {
-#if BLE_INCLUDED == TRUE
     tBTM_DEVCB *p_devcb = &btm_cb.devcb;
     BTM_TRACE_DEBUG0 ("BTM_BleLoadLocalKeys");
     if (p_key != NULL)
@@ -220,7 +224,6 @@
                 break;
         }
     }
-#endif
 }
 
 /*******************************************************************************
@@ -238,9 +241,7 @@
 {
     BTM_TRACE_DEBUG0 ("BTM_GetDeviceEncRoot");
 
-#if BLE_INCLUDED == TRUE
     memcpy (er, btm_cb.devcb.er, BT_OCTET16_LEN);
-#endif
 }
 
 /*******************************************************************************
@@ -258,9 +259,7 @@
 {
     BTM_TRACE_DEBUG0 ("BTM_GetDeviceIDRoot ");
 
-#if BLE_INCLUDED == TRUE
     memcpy (irk, btm_cb.devcb.id_keys.irk, BT_OCTET16_LEN);
-#endif
 }
 
 /*******************************************************************************
@@ -275,10 +274,8 @@
 *******************************************************************************/
 void BTM_GetDeviceDHK (BT_OCTET16 dhk)
 {
-#if BLE_INCLUDED == TRUE
     BTM_TRACE_DEBUG0 ("BTM_GetDeviceDHK");
     memcpy (dhk, btm_cb.devcb.id_keys.dhk, BT_OCTET16_LEN);
-#endif
 }
 
 /*******************************************************************************
@@ -293,7 +290,6 @@
 *******************************************************************************/
 void BTM_ReadConnectionAddr (BD_ADDR remote_bda, BD_ADDR local_conn_addr, tBLE_ADDR_TYPE *p_addr_type)
 {
-#if BLE_INCLUDED == TRUE
     tACL_CONN       *p_acl = btm_bda_to_acl(remote_bda);
 
     if (p_acl == NULL)
@@ -306,9 +302,8 @@
 
     BTM_TRACE_DEBUG2 ("BTM_ReadConnectionAddr address type: %d addr: 0x%02x",
                     p_acl->conn_addr_type, p_acl->conn_addr[0]);
-
-#endif
 }
+
 /*******************************************************************************
 **
 ** Function         BTM_IsBleConnection
@@ -321,7 +316,6 @@
 *******************************************************************************/
 BOOLEAN BTM_IsBleConnection (UINT16 conn_handle)
 {
-#if (BLE_INCLUDED == TRUE)
     UINT8                xx;
     tACL_CONN            *p;
 
@@ -334,9 +328,6 @@
     p = &btm_cb.acl_db[xx];
 
     return(p->is_le_link);
-#else
-    return FALSE;
-#endif
 }
 
 /*******************************************************************************
@@ -352,9 +343,19 @@
 BOOLEAN BTM_ReadRemoteConnectionAddr(BD_ADDR pseudo_addr, BD_ADDR conn_addr, tBLE_ADDR_TYPE *p_addr_type)
 {
     BOOLEAN         st = TRUE;
-#if BLE_INCLUDED == TRUE
     tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev(pseudo_addr);
+#if BTM_BLE_PRIVACY_SPT == TRUE
+    tACL_CONN       *p = btm_bda_to_acl (pseudo_addr);
 
+    if (p == NULL)
+    {
+        BTM_TRACE_ERROR0("BTM_ReadRemoteConnectionAddr can not find matching address");
+        return FALSE;
+    }
+
+    memcpy(conn_addr, p->active_remote_addr, BD_ADDR_LEN);
+    *p_addr_type = p->active_remote_addr_type;
+#else
     memcpy(conn_addr, pseudo_addr, BD_ADDR_LEN);
     if (p_dev_rec != NULL)
     {
@@ -378,7 +379,7 @@
 *******************************************************************************/
 void BTM_SecurityGrant(BD_ADDR bd_addr, UINT8 res)
 {
-#if (BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE)
+#if SMP_INCLUDED == TRUE
     tSMP_STATUS res_smp = (res == BTM_SUCCESS) ? SMP_SUCCESS : SMP_REPEATED_ATTEMPTS;
     BTM_TRACE_DEBUG0 ("BTM_SecurityGrant");
     SMP_SecurityGrant(bd_addr, res_smp);
@@ -401,7 +402,7 @@
 *******************************************************************************/
 void BTM_BlePasskeyReply (BD_ADDR bd_addr, UINT8 res, UINT32 passkey)
 {
-#if (BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE)
+#if SMP_INCLUDED == TRUE
     tBTM_SEC_DEV_REC  *p_dev_rec = btm_find_dev (bd_addr);
     tSMP_STATUS      res_smp = (res == BTM_SUCCESS) ? SMP_SUCCESS : SMP_PASSKEY_ENTRY_FAIL;
 
@@ -431,7 +432,7 @@
 *******************************************************************************/
 void BTM_BleOobDataReply(BD_ADDR bd_addr, UINT8 res, UINT8 len, UINT8 *p_data)
 {
-#if (BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE)
+#if SMP_INCLUDED == TRUE
     tSMP_STATUS res_smp = (res == BTM_SUCCESS) ? SMP_SUCCESS : SMP_OOB_FAIL;
     tBTM_SEC_DEV_REC  *p_dev_rec = btm_find_dev (bd_addr);
 
@@ -462,7 +463,7 @@
 *******************************************************************************/
 void BTM_BleSetConnScanParams (UINT16 scan_interval, UINT16 scan_window)
 {
-#if (BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE)
+#if SMP_INCLUDED == TRUE
     tBTM_BLE_CB *p_ble_cb = &btm_cb.ble_ctr_cb;
     BOOLEAN     new_param = FALSE;
 
@@ -516,7 +517,6 @@
                                UINT16 min_conn_int, UINT16 max_conn_int,
                                UINT16 slave_latency, UINT16 supervision_tout)
 {
-#if BLE_INCLUDED == TRUE
     tBTM_SEC_DEV_REC  *p_dev_rec = btm_find_dev (bd_addr);
 
     BTM_TRACE_API4 ("BTM_BleSetPrefConnParams min: %u  max: %u  latency: %u  \
@@ -565,7 +565,6 @@
     {
         BTM_TRACE_ERROR0("Illegal Connection Parameters");
     }
-#endif  /* BLE_INCLUDED */
 }
 
 /*******************************************************************************
@@ -582,7 +581,6 @@
 *******************************************************************************/
 void BTM_ReadDevInfo (BD_ADDR remote_bda, tBT_DEVICE_TYPE *p_dev_type, tBLE_ADDR_TYPE *p_addr_type)
 {
-#if BLE_INCLUDED == TRUE
     tBTM_SEC_DEV_REC  *p_dev_rec = btm_find_dev (remote_bda);
     tBTM_INQ_INFO     *p_inq_info = BTM_InqDbRead(remote_bda);
 
@@ -615,13 +613,8 @@
     }
 
     BTM_TRACE_DEBUG2 ("btm_find_dev_type - device_type = %d addr_type = %d", *p_dev_type , *p_addr_type);
-#endif
-
-    return;
 }
 
-#if BLE_INCLUDED == TRUE
-
 /*******************************************************************************
 **
 ** Function         BTM_BleReceiverTest
@@ -683,13 +676,9 @@
      }
 }
 
-#endif
-
 /*******************************************************************************
 ** Internal Functions
 *******************************************************************************/
-#if BLE_INCLUDED == TRUE
-
 void btm_ble_test_command_complete(UINT8 *p)
 {
     tBTM_CMPL_CB   *p_cb = btm_cb.devcb.p_le_test_cmd_cmpl_cb;
@@ -714,13 +703,11 @@
 *******************************************************************************/
 BOOLEAN BTM_IsBleLink (BD_ADDR bd_addr)
 {
-#if (BLE_INCLUDED == TRUE)
     tACL_CONN         *p;
     BTM_TRACE_DEBUG0 ("BTM_IsBleLink");
     if ((p = btm_bda_to_acl(bd_addr)) != NULL)
         return p->is_le_link;
     else
-#endif
         return FALSE;
 }
 /*******************************************************************************
@@ -741,9 +728,7 @@
 
     if ((p = btm_bda_to_acl(bd_addr)) != NULL)
     {
-#if (BLE_INCLUDED == TRUE)
         use_le = (p->is_le_link);
-#endif
     }
     else
     {
@@ -1492,6 +1477,61 @@
     return callback_rc;
 }
 
+#if (BTM_BLE_PRIVACY_SPT == TRUE )
+/*******************************************************************************
+**
+** Function         btm_ble_resolve_random_addr_on_conn_cmpl
+**
+** Description      resolve random address complete on connection complete event.
+**
+** Returns          void
+**
+*******************************************************************************/
+static void btm_ble_resolve_random_addr_on_conn_cmpl(void * p_rec, void *p_data)
+{
+    UINT8   *p = (UINT8 *)p_data;
+    tBTM_SEC_DEV_REC    *match_rec = (tBTM_SEC_DEV_REC *) p_rec;
+    UINT8       role, status, bda_type;
+    UINT16      handle;
+    BD_ADDR     bda;
+    UINT16      conn_interval, conn_latency, conn_timeout;
+    BOOLEAN     match = FALSE;
+
+    STREAM_TO_UINT8   (status, p);
+    STREAM_TO_UINT16   (handle, p);
+    STREAM_TO_UINT8    (role, p);
+    STREAM_TO_UINT8    (bda_type, p);
+    STREAM_TO_BDADDR   (bda, p);
+    STREAM_TO_UINT16   (conn_interval, p);
+    STREAM_TO_UINT16   (conn_latency, p);
+    STREAM_TO_UINT16   (conn_timeout, p);
+
+    handle = HCID_GET_HANDLE (handle);
+
+    BTM_TRACE_EVENT0 ("btm_ble_resolve_random_addr_master_cmpl");
+
+    if (match_rec)
+    {
+        BTM_TRACE_ERROR0("Random match");
+        match = TRUE;
+        match_rec->ble.active_addr_type = BTM_BLE_ADDR_RRA;
+        memcpy(match_rec->ble.cur_rand_addr, bda, BD_ADDR_LEN);
+        memcpy(bda, match_rec->bd_addr, BD_ADDR_LEN);
+    }
+    else
+    {
+        BTM_TRACE_ERROR0("Random unmatch");
+    }
+
+    btm_ble_connected(bda, handle, HCI_ENCRYPT_MODE_DISABLED, role, bda_type, match);
+
+    l2cble_conn_comp (handle, role, bda, bda_type, conn_interval,
+                      conn_latency, conn_timeout);
+
+    return;
+}
+#endif
+
 /*******************************************************************************
 **
 ** Function         btm_ble_connected
@@ -1507,6 +1547,7 @@
 {
     tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bda);
     tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
+    UNUSED(addr_matched);
 
     BTM_TRACE_EVENT0 ("btm_ble_connected");
 
@@ -1545,9 +1586,18 @@
     p_dev_rec->hci_handle = handle;
     p_dev_rec->ble.ble_addr_type = addr_type;
 
+    p_dev_rec->role_master = FALSE;
     if (role == HCI_ROLE_MASTER)
         p_dev_rec->role_master = TRUE;
 
+#if (defined BTM_BLE_PRIVACY_SPT && BTM_BLE_PRIVACY_SPT == TRUE)
+    if (!addr_matched)
+        p_dev_rec->ble.active_addr_type = BTM_BLE_ADDR_PSEUDO;
+
+    if (p_dev_rec->ble.ble_addr_type == BLE_ADDR_RANDOM && !addr_matched)
+        memcpy(p_dev_rec->ble.cur_rand_addr, bda, BD_ADDR_LEN);
+#endif
+
     if (role == HCI_ROLE_SLAVE)
         p_cb->inq_var.adv_mode  = BTM_BLE_ADV_DISABLE;
     p_cb->inq_var.directed_conn = FALSE;
@@ -1563,11 +1613,15 @@
 ******************************************************************************/
 void btm_ble_conn_complete(UINT8 *p, UINT16 evt_len)
 {
+#if (BTM_BLE_PRIVACY_SPT == TRUE )
+    UINT8       *p_data = p;
+#endif
     UINT8       role, status, bda_type;
     UINT16      handle;
     BD_ADDR     bda;
     UINT16      conn_interval, conn_latency, conn_timeout;
     BOOLEAN     match = FALSE;
+    UNUSED(evt_len);
 
     STREAM_TO_UINT8   (status, p);
     STREAM_TO_UINT16   (handle, p);
@@ -1577,14 +1631,25 @@
 
     if (status == 0)
     {
-        STREAM_TO_UINT16   (conn_interval, p);
-        STREAM_TO_UINT16   (conn_latency, p);
-        STREAM_TO_UINT16   (conn_timeout, p);
-        handle = HCID_GET_HANDLE (handle);
+#if (BTM_BLE_PRIVACY_SPT == TRUE )
+        /* possiblly receive connection complete with resolvable random on
+           slave role while the device has been paired */
+        if (!match && BTM_BLE_IS_RESOLVE_BDA(bda))
+        {
+            btm_ble_resolve_random_addr(bda, btm_ble_resolve_random_addr_on_conn_cmpl, p_data);
+        }
+        else
+#endif
+        {
+            STREAM_TO_UINT16   (conn_interval, p);
+            STREAM_TO_UINT16   (conn_latency, p);
+            STREAM_TO_UINT16   (conn_timeout, p);
+            handle = HCID_GET_HANDLE (handle);
 
-        btm_ble_connected(bda, handle, HCI_ENCRYPT_MODE_DISABLED, role, bda_type, match);
-        l2cble_conn_comp (handle, role, bda, bda_type, conn_interval,
+            btm_ble_connected(bda, handle, HCI_ENCRYPT_MODE_DISABLED, role, bda_type, match);
+            l2cble_conn_comp (handle, role, bda, bda_type, conn_interval,
                               conn_latency, conn_timeout);
+        }
     }
     else
     {
@@ -1722,8 +1787,6 @@
 }
 
     #endif  /* SMP_INCLUDED */
-#endif  /* BLE_INCLUDED */
-
 
 /*******************************************************************************
 **
@@ -1745,7 +1808,7 @@
                               BLE_SIGNATURE signature)
 {
     BOOLEAN     ret = FALSE;
-#if (BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE)
+#if SMP_INCLUDED == TRUE
     tBTM_SEC_DEV_REC    *p_rec = btm_find_dev (bd_addr);
     UINT8   *p_buf, *pp;
 
@@ -1844,7 +1907,7 @@
             }
         }
     }
-#endif  /* BLE_INCLUDED */
+#endif  /* SMP_INCLUDED */
     return ret;
 }
 
@@ -1867,7 +1930,7 @@
                                 UINT8 *p_comp)
 {
     BOOLEAN             verified = FALSE;
-#if (BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE)
+#if SMP_INCLUDED == TRUE
     tBTM_SEC_DEV_REC    *p_rec = btm_find_dev (bd_addr);
     UINT8               p_mac[BTM_CMAC_TLEN_SIZE];
 
@@ -1896,11 +1959,10 @@
             }
         }
     }
-#endif  /* BLE_INCLUDED */
+#endif  /* SMP_INCLUDED */
     return verified;
 }
 
-#if BLE_INCLUDED == TRUE
 /*******************************************************************************
 **  Utility functions for LE device IR/ER generation
 *******************************************************************************/
@@ -2239,5 +2301,4 @@
 }
 #endif /* BTM_BLE_CONFORMANCE_TESTING */
 
-
 #endif /* BLE_INCLUDED */
diff --git a/stack/btm/btm_ble_addr.c b/stack/btm/btm_ble_addr.c
index 9ae37f9..3c646e9 100644
--- a/stack/btm/btm_ble_addr.c
+++ b/stack/btm/btm_ble_addr.c
@@ -28,10 +28,10 @@
 #include "hcimsgs.h"
 #include "btu.h"
 #include "btm_int.h"
-#include "btm_ble_int.h"
 #include "gap_api.h"
 
 #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
+#include "btm_ble_int.h"
 #include "smp_api.h"
 #define BTM_BLE_PRIVATE_ADDR_INT    900           /* 15 minutes minimum for
                                                    random address refreshing */
@@ -287,7 +287,7 @@
     {
         p_dev_rec = &btm_cb.sec_dev_rec[rec_index];
 
-        BTM_TRACE_ERROR2("sec_flags = %02x device_type = %d", p_dev_rec->sec_flags, p_dev_rec->device_type);
+        BTM_TRACE_DEBUG2("sec_flags = %02x device_type = %d", p_dev_rec->sec_flags, p_dev_rec->device_type);
 
         if ((p_dev_rec->device_type == BT_DEVICE_TYPE_BLE) &&
             (p_dev_rec->ble.key_type & BTM_LE_KEY_PID))
diff --git a/stack/btm/btm_ble_bgconn.c b/stack/btm/btm_ble_bgconn.c
index 727390c..96d35c4 100644
--- a/stack/btm/btm_ble_bgconn.c
+++ b/stack/btm/btm_ble_bgconn.c
@@ -29,7 +29,7 @@
 #include "btm_int.h"
 #include "l2c_int.h"
 #include "hcimsgs.h"
-
+#include "bt_utils.h"
 
 #ifndef BTM_BLE_SCAN_PARAM_TOUT
 #define BTM_BLE_SCAN_PARAM_TOUT      50    /* 50 seconds */
@@ -73,6 +73,7 @@
     BOOLEAN             started = FALSE;
     BD_ADDR             dummy_bda = {0};
     tBT_DEVICE_TYPE dev_type;
+    UNUSED(attr);
 
     if (p_dev_rec != NULL &&
         p_dev_rec->device_type == BT_DEVICE_TYPE_BLE)
@@ -227,6 +228,8 @@
 {
     tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
     UINT8       status;
+    UNUSED(evt_len);
+
     BTM_TRACE_EVENT0 ("btm_ble_clear_white_list_complete");
     STREAM_TO_UINT8  (status, p_data);
 
@@ -259,6 +262,8 @@
 void btm_ble_remove_from_white_list_complete(UINT8 *p, UINT16 evt_len)
 {
     tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
+    UNUSED(evt_len);
+
     BTM_TRACE_EVENT0 ("btm_ble_remove_from_white_list_complete");
     if (*p == HCI_SUCCESS)
     {
@@ -299,6 +304,7 @@
     tBTM_LE_BG_CONN_DEV     *p_bg_dev = &p_cb->bg_dev_list[0], *p_next, *p_cur;
     UINT8                   i, j;
     BOOLEAN             ret = FALSE;
+    UNUSED(p_attr_tag);
 
     BTM_TRACE_EVENT0 ("btm_update_bg_conn_list");
 
diff --git a/stack/btm/btm_ble_gap.c b/stack/btm/btm_ble_gap.c
index 6e4ff9b..54f1b55 100644
--- a/stack/btm/btm_ble_gap.c
+++ b/stack/btm/btm_ble_gap.c
@@ -27,6 +27,7 @@
 #include <stddef.h>
 
 #include "bt_types.h"
+#include "bt_utils.h"
 #include "btu.h"
 #include "btm_int.h"
 #include "hcimsgs.h"
@@ -85,7 +86,10 @@
 *******************************************************************************/
 BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR remote_bda)
 {
-        return FALSE;
+    UNUSED(add_remove);
+    UNUSED(remote_bda);
+
+    return FALSE;
 }
 
 /*******************************************************************************
@@ -300,9 +304,54 @@
         tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
         p_cb->p_scan_req_cback = p_scan_req_cback;
     }
+#else
+    UNUSED(p_scan_req_cback);
 #endif
 }
 
+#if BTM_BLE_PRIVACY_SPT == TRUE
+/*******************************************************************************
+**
+** Function         btm_ble_resolve_random_addr_on_adv
+**
+** Description      resolve random address complete callback.
+**
+** Returns          void
+**
+*******************************************************************************/
+static void btm_ble_resolve_random_addr_on_adv(void * p_rec, void *p)
+{
+    tBTM_SEC_DEV_REC    *match_rec = (tBTM_SEC_DEV_REC *) p_rec;
+    UINT8       addr_type = BLE_ADDR_RANDOM;
+    BD_ADDR     bda;
+    UINT8       *pp = (UINT8 *)p + 1;
+    UINT8           evt_type;
+
+    BTM_TRACE_EVENT0 ("btm_ble_resolve_random_addr_on_adv ");
+
+    STREAM_TO_UINT8    (evt_type, pp);
+    STREAM_TO_UINT8    (addr_type, pp);
+    STREAM_TO_BDADDR   (bda, pp);
+
+    if (match_rec)
+    {
+        BTM_TRACE_ERROR0("Random match");
+        match_rec->ble.active_addr_type = BTM_BLE_ADDR_RRA;
+        memcpy(match_rec->ble.cur_rand_addr, bda, BD_ADDR_LEN);
+        memcpy(bda, match_rec->bd_addr, BD_ADDR_LEN);
+        addr_type = match_rec->ble.ble_addr_type;
+    }
+    else
+    {
+        BTM_TRACE_ERROR0("Random unmatch");
+    }
+
+    btm_ble_process_adv_pkt_cont(bda, addr_type, evt_type, pp);
+
+    return;
+}
+#endif
+
 /*******************************************************************************
 **
 ** Function         BTM_BleSetBgConnType
@@ -1412,6 +1461,7 @@
     tBTM_BLE_INQ_CB     *p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var;
     UINT8 *p_cache;
     UINT8 length;
+    UNUSED(p_cur);
 
     /* cache adv report/scan response data */
     if (evt_type != BTM_BLE_SCAN_RSP_EVT)
@@ -1539,6 +1589,7 @@
     UINT8                data_len, rssi;
     tBTM_BLE_INQ_CB     *p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var;
     UINT8 *p1;
+    UINT8               *p_uuid16;
 
     STREAM_TO_UINT8    (data_len, p);
 
@@ -1585,6 +1636,26 @@
             p_cur->flag = * p_flag;
     }
 
+    if (p_le_inq_cb->adv_len != 0)
+    {
+        if ((p_uuid16 = BTM_CheckAdvData(p_le_inq_cb->adv_data_cache,
+                                         BTM_BLE_AD_TYPE_16SRV_CMPL, &len)) != NULL)
+        {
+            UINT8 i;
+            for (i = 0; i + 2 <= len; i = i + 2)
+            {
+                /* if this BLE device support HID over LE, set HID Major in class of device */
+                if ((p_uuid16[i] | (p_uuid16[i+1] << 8)) == UUID_SERVCLASS_LE_HID)
+                {
+                    p_cur->dev_class[0] = 0;
+                    p_cur->dev_class[1] = BTM_COD_MAJOR_PERIPHERAL;
+                    p_cur->dev_class[2] = 0;
+                    break;
+                }
+            }
+        }
+    }
+
     /* if BR/EDR not supported is not set, assume is a DUMO device */
     if ((p_cur->flag & BTM_BLE_BREDR_NOT_SPT) == 0 &&
          evt_type != BTM_BLE_CONNECT_DIR_EVT)
@@ -1621,6 +1692,7 @@
 {
     UINT8   data_len, len;
     UINT8   *p_dev_name, remname[31] = {0};
+    UNUSED(addr_type);
 
     if (btm_cb.ble_ctr_cb.p_select_cback == NULL ||
         /* non-connectable device */
@@ -1666,6 +1738,9 @@
     BD_ADDR             bda;
     UINT8               evt_type = 0, *p = p_data;
     UINT8               addr_type = 0;
+#if (defined BTM_BLE_PRIVACY_SPT && BTM_BLE_PRIVACY_SPT == TRUE)
+    BOOLEAN             match = FALSE;
+#endif
 
     /* always get one device at a time */
     p ++;
@@ -1694,7 +1769,19 @@
 
     BTM_TRACE_DEBUG6("btm_ble_process_adv_pkt:bda= %0x:%0x:%0x:%0x:%0x:%0x",
                                      bda[0],bda[1],bda[2],bda[3],bda[4],bda[5]);
-    btm_ble_process_adv_pkt_cont(bda, addr_type, evt_type, p);
+#if (defined BTM_BLE_PRIVACY_SPT && BTM_BLE_PRIVACY_SPT == TRUE)
+#if SMP_INCLUDED == TRUE
+    /* always do RRA resolution on host */
+    if (!match && BTM_BLE_IS_RESOLVE_BDA(bda))
+    {
+        btm_ble_resolve_random_addr(bda, btm_ble_resolve_random_addr_on_adv, p_data);
+    }
+    else
+#endif
+#endif
+    {
+        btm_ble_process_adv_pkt_cont(bda, addr_type, evt_type, p);
+    }
 }
 
 /*******************************************************************************
@@ -2042,6 +2129,8 @@
     tACL_CONN   *pa = &btm_cb.acl_db[0];
     UINT16       xx;
     UINT8        dev_role = link_role;
+    UNUSED(bd_addr);
+    UNUSED(conn_cancel);
 
     BTM_TRACE_DEBUG1("btm_ble_update_mode_operation adv_mode = %d", btm_cb.ble_ctr_cb.inq_var.adv_mode );
 
diff --git a/stack/btm/btm_ble_int.h b/stack/btm/btm_ble_int.h
index 4aeab19..7ce4f16 100644
--- a/stack/btm/btm_ble_int.h
+++ b/stack/btm/btm_ble_int.h
@@ -289,6 +289,7 @@
 extern BOOLEAN btm_get_local_div (BD_ADDR bd_addr, UINT16 *p_div);
 extern BOOLEAN btm_ble_get_enc_key_type(BD_ADDR bd_addr, UINT8 *p_key_types);
 
+extern void btm_ble_test_command_complete(UINT8 *p);
 extern void btm_ble_rand_enc_complete (UINT8 *p, UINT16 op_code, tBTM_RAND_ENC_CB *p_enc_cplt_cback);
 extern void btm_sec_save_le_key(BD_ADDR bd_addr, tBTM_LE_KEY_TYPE key_type, tBTM_LE_KEY_VALUE *p_keys, BOOLEAN pass_to_application);
 extern void btm_ble_update_sec_key_size(BD_ADDR bd_addr, UINT8 enc_key_size);
diff --git a/stack/btm/btm_devctl.c b/stack/btm/btm_devctl.c
index 49e05b4..240bd2f 100644
--- a/stack/btm/btm_devctl.c
+++ b/stack/btm/btm_devctl.c
@@ -29,6 +29,7 @@
 #include <stddef.h>
 
 #include "bt_types.h"
+#include "bt_utils.h"
 #include "hcimsgs.h"
 #include "btu.h"
 #include "btm_int.h"
@@ -729,6 +730,7 @@
     UINT16      lm_num_acl_bufs;
     UINT16      lm_num_sco_bufs;
     UINT16      acl_buf_size;
+    UNUSED(evt_len);
 
     STREAM_TO_UINT8  (status, p);
     if (status == HCI_SUCCESS)
@@ -790,8 +792,9 @@
 {
     UINT8       status;
     UINT16      lm_num_le_bufs;
+    UNUSED(evt_len);
 
-     BTM_TRACE_DEBUG0("btm_read_ble_buf_size_complete ");
+    BTM_TRACE_DEBUG0("btm_read_ble_buf_size_complete ");
     STREAM_TO_UINT8  (status, p);
     if (status == HCI_SUCCESS)
     {
@@ -823,6 +826,7 @@
 void btm_read_ble_local_supported_features_complete (UINT8 *p, UINT16 evt_len)
 {
     UINT8       status;
+    UNUSED(evt_len);
 
     BTM_TRACE_DEBUG0("btm_read_ble_local_supported_features_complete ");
 
@@ -860,8 +864,9 @@
 void btm_read_white_list_size_complete(UINT8 *p, UINT16 evt_len)
 {
     UINT8       status;
+    UNUSED(evt_len);
 
-     BTM_TRACE_DEBUG0("btm_read_white_list_size_complete ");
+    BTM_TRACE_DEBUG0("btm_read_white_list_size_complete ");
     STREAM_TO_UINT8  (status, p);
 
     if (status == HCI_SUCCESS)
@@ -888,6 +893,7 @@
 {
     tBTM_VERSION_INFO   *p_vi = &btm_cb.devcb.local_version;
     UINT8                status;
+    UNUSED(evt_len);
 
 #ifdef BTA_PRM_CHECK_FW_VER
     if(BTA_PRM_CHECK_FW_VER(p))
@@ -1120,7 +1126,7 @@
     btu_stop_timer (&btm_cb.devcb.reset_timer);
 
     /* find the highest feature page number which contains non-zero bits */
-    for (i = HCI_EXT_FEATURES_PAGE_MAX; i >= 0; i--)
+    for (i = HCI_EXT_FEATURES_PAGE_MAX; ; i--)
     {
         for (j = 0; j < HCI_FEATURE_BYTES_PER_PAGE; j++)
         {
@@ -1326,6 +1332,7 @@
 {
     tBTM_DEVCB     *p_devcb = &btm_cb.devcb;
     UINT8           status;
+    UNUSED(evt_len);
 
     btu_stop_timer (&p_devcb->reset_timer);
 
@@ -1369,6 +1376,7 @@
     UINT8           status;
     UINT8           page_number;
     UINT8           page_number_max;
+    UNUSED(evt_len);
 
     btu_stop_timer (&btm_cb.devcb.reset_timer);
 
@@ -1644,6 +1652,7 @@
 {
     tBTM_CMPL_CB   *p_cb = btm_cb.devcb.p_rln_cmpl_cb;
     UINT8           status;
+    UNUSED(evt_len);
 
     btu_stop_timer (&btm_cb.devcb.rln_timer);
 
@@ -1708,6 +1717,7 @@
 void btm_read_local_addr_complete (UINT8 *p, UINT16 evt_len)
 {
     UINT8           status;
+    UNUSED(evt_len);
 
     STREAM_TO_UINT8  (status, p);
 
diff --git a/stack/btm/btm_int.h b/stack/btm/btm_int.h
index e449d48..7865b3e 100644
--- a/stack/btm/btm_int.h
+++ b/stack/btm/btm_int.h
@@ -499,13 +499,19 @@
     UINT32              local_counter;  /* local sign counter for sending signed write cmd*/
 }tBTM_SEC_BLE_KEYS;
 
-#endif  /* BLE_INCLUDED */
-
 typedef struct
 {
     tBLE_ADDR_TYPE      ble_addr_type;  /* LE device type: public or random address */
     tBLE_ADDR_TYPE      static_addr_type;   /* static address type */
     BD_ADDR             static_addr;    /* static address */
+#if BTM_BLE_PRIVACY_SPT == TRUE
+    BD_ADDR             cur_rand_addr;  /* current random address */
+
+#define BTM_BLE_ADDR_PSEUDO         0   /* address index device record */
+#define BTM_BLE_ADDR_RRA            1   /* cur_rand_addr */
+#define BTM_BLE_ADDR_STATIC         2   /* static_addr  */
+    UINT8               active_addr_type;
+#endif
 
 #if SMP_INCLUDED == TRUE
     tBTM_LE_KEY_TYPE    key_type;       /* bit mask of valid key types in record */
@@ -513,6 +519,8 @@
 #endif
 } tBTM_SEC_BLE;
 
+#endif  /* BLE_INCLUDED */
+
 /*
 ** Define structure for Security Device Record.
 ** A record exists for each device authenticated with this device
@@ -950,6 +958,7 @@
 extern void         btm_inq_db_init (void);
 extern void         btm_process_inq_results (UINT8 *p, UINT8 inq_res_mode);
 extern void         btm_process_inq_complete (UINT8 status, UINT8 mode);
+extern void         btm_process_cancel_complete(UINT8 status, UINT8 mode);
 extern void         btm_event_filter_complete (UINT8 *p);
 extern void         btm_inq_stop_on_ssp(void);
 extern void         btm_inq_clear_ssp(void);
@@ -1134,7 +1143,7 @@
 
 #if BLE_INCLUDED == TRUE
 extern void  btm_sec_clear_ble_keys (tBTM_SEC_DEV_REC  *p_dev_rec);
-extern  BOOLEAN btm_sec_find_bonded_dev (UINT8 start_idx, UINT8 *p_found_idx, tBTM_SEC_DEV_REC *p_rec);
+extern  BOOLEAN btm_sec_find_bonded_dev (UINT8 start_idx, UINT8 *p_found_idx, tBTM_SEC_DEV_REC **p_rec);
 extern BOOLEAN btm_sec_is_a_bonded_dev (BD_ADDR bda);
 extern BOOLEAN btm_sec_is_le_capable_dev (BD_ADDR bda);
 #endif /* BLE_INCLUDED */
diff --git a/stack/btm/btm_pm.c b/stack/btm/btm_pm.c
index 19b90d3..02e3a6a 100644
--- a/stack/btm/btm_pm.c
+++ b/stack/btm/btm_pm.c
@@ -40,7 +40,7 @@
 #include "btm_int.h"
 #include "l2c_int.h"
 #include "hcidefs.h"
-
+#include "bt_utils.h"
 
 #if BTM_PWR_MGR_INCLUDED == TRUE
 
@@ -369,8 +369,6 @@
         cb = btm_cb.pm_reg_db[btm_cb.pm_pend_id].cback;
     }
 
-    /* no command pending */
-    btm_cb.pm_pend_link = MAX_L2CAP_LINKS;
 
     /* clear the register record */
     for(xx=0; xx<BTM_MAX_PM_RECORDS; xx++)
@@ -378,8 +376,11 @@
         btm_cb.pm_reg_db[xx].mask = BTM_PM_REC_NOT_USED;
     }
 
-    if(cb != NULL)
+    if(cb != NULL && btm_cb.pm_pend_link < MAX_L2CAP_LINKS)
         (*cb)(btm_cb.acl_db[btm_cb.pm_pend_link].remote_addr, BTM_PM_STS_ERROR, BTM_DEV_RESET, 0);
+
+    /* no command pending */
+    btm_cb.pm_pend_link = MAX_L2CAP_LINKS;
 }
 
 /*******************************************************************************
@@ -922,6 +923,7 @@
     tBTM_PM_MCB *p_cb;
     tACL_CONN   *p_acl=NULL;
     UINT16      use_ssr = TRUE;
+    UNUSED(evt_len);
 
     STREAM_TO_UINT8 (status, p);
 
diff --git a/stack/btm/btm_sco.c b/stack/btm/btm_sco.c
index 3eb010c..2200b71 100644
--- a/stack/btm/btm_sco.c
+++ b/stack/btm/btm_sco.c
@@ -33,6 +33,7 @@
 #include "btm_api.h"
 #include "btm_int.h"
 #include "hcidefs.h"
+#include "bt_utils.h"
 
 #if BTM_SCO_INCLUDED == TRUE
 
@@ -93,7 +94,11 @@
                 GKI_freebuf (p_buf);
         }
     }
+#else
+    UNUSED(sco_inx);
 #endif
+#else
+    UNUSED(sco_inx);
 #endif
 }
 /*******************************************************************************
@@ -382,6 +387,8 @@
     return (status);
 
 #else
+    UNUSED(sco_inx);
+    UNUSED(p_buf);
     return (BTM_NO_RESOURCES);
 #endif
 }
diff --git a/stack/btm/btm_sec.c b/stack/btm/btm_sec.c
index 8bcf435..09f41b7 100644
--- a/stack/btm/btm_sec.c
+++ b/stack/btm/btm_sec.c
@@ -28,6 +28,7 @@
 #include "btu.h"
 #include "btm_int.h"
 #include "l2c_int.h"
+#include "bt_utils.h"
 
 #if (BT_USE_TRACES == TRUE && BT_TRACE_VERBOSE == FALSE)
 /* needed for sprintf() */
@@ -432,6 +433,13 @@
     return(btm_sec_set_security_level (conn_type, p_name, service_id,
                                        sec_level, psm, mx_proto_id, mx_chan_id));
 #else
+    UNUSED(is_originator);
+    UNUSED(p_name);
+    UNUSED(service_id);
+    UNUSED(sec_level);
+    UNUSED(psm);
+    UNUSED(mx_proto_id);
+    UNUSED(mx_chan_id);
     return FALSE;
 #endif
 }
@@ -842,6 +850,7 @@
 
     return(num_cleared);
 #else
+    UNUSED(service_id);
     return(0);
 #endif
 }
@@ -4039,6 +4048,7 @@
 static void btm_sec_connect_after_reject_timeout (TIMER_LIST_ENT *p_tle)
 {
     tBTM_SEC_DEV_REC *p_dev_rec = btm_cb.p_collided_dev_rec;
+    UNUSED(p_tle);
 
     BTM_TRACE_EVENT0 ("btm_sec_connect_after_reject_timeout()");
     btm_cb.sec_collision_tle.param = 0;
@@ -4655,6 +4665,7 @@
 #endif
 #endif
     UINT8   name[2];
+    UNUSED(p_tle);
 
     p_cb->pairing_tle.param = 0;
 /* Coverity: FALSE-POSITIVE error from Coverity tool. Please do NOT remove following comment. */
@@ -5357,6 +5368,7 @@
 static void btm_sec_collision_timeout (TIMER_LIST_ENT *p_tle)
 {
     tBTM_STATUS status;
+    UNUSED(p_tle);
 
     BTM_TRACE_EVENT0 ("btm_sec_collision_timeout()");
     btm_cb.sec_collision_tle.param = 0;
@@ -5772,7 +5784,7 @@
 ** Returns          TRUE - found a bonded device
 **
 *******************************************************************************/
-BOOLEAN btm_sec_find_bonded_dev (UINT8 start_idx, UINT8 *p_found_idx, tBTM_SEC_DEV_REC *p_rec)
+BOOLEAN btm_sec_find_bonded_dev (UINT8 start_idx, UINT8 *p_found_idx, tBTM_SEC_DEV_REC **p_rec)
 {
     BOOLEAN found= FALSE;
 
@@ -5791,7 +5803,7 @@
         if (p_dev_rec->ble.key_type || (p_dev_rec->sec_flags & BTM_SEC_LINK_KEY_KNOWN))
         {
             *p_found_idx = i;
-            p_rec = p_dev_rec;
+            *p_rec = p_dev_rec;
             break;
         }
     }
diff --git a/stack/btu/btu_hcif.c b/stack/btu/btu_hcif.c
index bd7c9ff..0081850 100644
--- a/stack/btu/btu_hcif.c
+++ b/stack/btu/btu_hcif.c
@@ -60,64 +60,64 @@
 /********************************************************************************/
 /*              L O C A L    F U N C T I O N     P R O T O T Y P E S            */
 /********************************************************************************/
-static void btu_hcif_inquiry_comp_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_inquiry_result_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_inquiry_rssi_result_evt (UINT8 *p, UINT16 evt_len);
+static void btu_hcif_inquiry_comp_evt (UINT8 *p);
+static void btu_hcif_inquiry_result_evt (UINT8 *p);
+static void btu_hcif_inquiry_rssi_result_evt (UINT8 *p);
 #if (BTM_EIR_CLIENT_INCLUDED == TRUE)
-static void btu_hcif_extended_inquiry_result_evt (UINT8 *p, UINT16 evt_len);
+static void btu_hcif_extended_inquiry_result_evt (UINT8 *p);
 #endif
 
-static void btu_hcif_connection_comp_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_connection_request_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_disconnection_comp_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_authentication_comp_evt (UINT8 *p, UINT16 evt_len);
+static void btu_hcif_connection_comp_evt (UINT8 *p);
+static void btu_hcif_connection_request_evt (UINT8 *p);
+static void btu_hcif_disconnection_comp_evt (UINT8 *p);
+static void btu_hcif_authentication_comp_evt (UINT8 *p);
 static void btu_hcif_rmt_name_request_comp_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_encryption_change_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_change_conn_link_key_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_master_link_key_comp_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_read_rmt_features_comp_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_read_rmt_ext_features_comp_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_read_rmt_version_comp_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_qos_setup_comp_evt (UINT8 *p, UINT16 evt_len);
+static void btu_hcif_encryption_change_evt (UINT8 *p);
+static void btu_hcif_change_conn_link_key_evt (UINT8 *p);
+static void btu_hcif_master_link_key_comp_evt (UINT8 *p);
+static void btu_hcif_read_rmt_features_comp_evt (UINT8 *p);
+static void btu_hcif_read_rmt_ext_features_comp_evt (UINT8 *p);
+static void btu_hcif_read_rmt_version_comp_evt (UINT8 *p);
+static void btu_hcif_qos_setup_comp_evt (UINT8 *p);
 static void btu_hcif_command_complete_evt (UINT8 controller_id, UINT8 *p, UINT16 evt_len);
-static void btu_hcif_command_status_evt (UINT8 controller_id, UINT8 *p, UINT16 evt_len);
-static void btu_hcif_hardware_error_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_flush_occured_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_role_change_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_num_compl_data_pkts_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_mode_change_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_return_link_keys_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_pin_code_request_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_link_key_request_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_link_key_notification_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_loopback_command_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_data_buf_overflow_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_max_slots_changed_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_read_clock_off_comp_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_conn_pkt_type_change_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_qos_violation_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_page_scan_mode_change_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_page_scan_rep_mode_chng_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_esco_connection_comp_evt(UINT8 *p, UINT16 evt_len);
-static void btu_hcif_esco_connection_chg_evt(UINT8 *p, UINT16 evt_len);
+static void btu_hcif_command_status_evt (UINT8 controller_id, UINT8 *p);
+static void btu_hcif_hardware_error_evt (UINT8 *p);
+static void btu_hcif_flush_occured_evt (void);
+static void btu_hcif_role_change_evt (UINT8 *p);
+static void btu_hcif_num_compl_data_pkts_evt (UINT8 *p);
+static void btu_hcif_mode_change_evt (UINT8 *p);
+static void btu_hcif_return_link_keys_evt (UINT8 *p);
+static void btu_hcif_pin_code_request_evt (UINT8 *p);
+static void btu_hcif_link_key_request_evt (UINT8 *p);
+static void btu_hcif_link_key_notification_evt (UINT8 *p);
+static void btu_hcif_loopback_command_evt (void);
+static void btu_hcif_data_buf_overflow_evt (void);
+static void btu_hcif_max_slots_changed_evt (void);
+static void btu_hcif_read_clock_off_comp_evt (UINT8 *p);
+static void btu_hcif_conn_pkt_type_change_evt (void);
+static void btu_hcif_qos_violation_evt (UINT8 *p);
+static void btu_hcif_page_scan_mode_change_evt (void);
+static void btu_hcif_page_scan_rep_mode_chng_evt (void);
+static void btu_hcif_esco_connection_comp_evt(UINT8 *p);
+static void btu_hcif_esco_connection_chg_evt(UINT8 *p);
 
 /* Simple Pairing Events */
-static void btu_hcif_host_support_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_io_cap_request_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_io_cap_response_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_user_conf_request_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_user_passkey_request_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_user_passkey_notif_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_keypress_notif_evt (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_link_super_tout_evt (UINT8 *p, UINT16 evt_len);
+static void btu_hcif_host_support_evt (UINT8 *p);
+static void btu_hcif_io_cap_request_evt (UINT8 *p);
+static void btu_hcif_io_cap_response_evt (UINT8 *p);
+static void btu_hcif_user_conf_request_evt (UINT8 *p);
+static void btu_hcif_user_passkey_request_evt (UINT8 *p);
+static void btu_hcif_user_passkey_notif_evt (UINT8 *p);
+static void btu_hcif_keypress_notif_evt (UINT8 *p);
+static void btu_hcif_link_super_tout_evt (UINT8 *p);
 
     #if BTM_OOB_INCLUDED == TRUE
-static void btu_hcif_rem_oob_request_evt (UINT8 *p, UINT16 evt_len);
+static void btu_hcif_rem_oob_request_evt (UINT8 *p);
     #endif
 
-static void btu_hcif_simple_pair_complete_evt (UINT8 *p, UINT16 evt_len);
+static void btu_hcif_simple_pair_complete_evt (UINT8 *p);
     #if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE
-static void btu_hcif_enhanced_flush_complete_evt (UINT8 *p, UINT16 evt_len);
+static void btu_hcif_enhanced_flush_complete_evt (void);
     #endif
 
     #if (BTM_SSR_INCLUDED == TRUE)
@@ -131,11 +131,11 @@
 
     #if BLE_INCLUDED == TRUE
 static void btu_ble_ll_conn_complete_evt (UINT8 *p, UINT16 evt_len);
-static void btu_ble_process_adv_pkt (UINT8 *p, UINT16 evt_len);
-static void btu_ble_read_remote_feat_evt (UINT8 *p, UINT16 evt_len);
-static void btu_ble_ll_conn_param_upd_evt (UINT8 *p, UINT16 evt_len);
-static void btu_ble_proc_ltk_req (UINT8 *p, UINT16 evt_len);
-static void btu_hcif_encyption_key_refresh_cmpl_evt (UINT8 *p, UINT16 evt_len);
+static void btu_ble_process_adv_pkt (UINT8 *p);
+static void btu_ble_read_remote_feat_evt (UINT8 *p);
+static void btu_ble_ll_conn_param_upd_evt (UINT8 *p);
+static void btu_ble_proc_ltk_req (UINT8 *p);
+static void btu_hcif_encryption_key_refresh_cmpl_evt (UINT8 *p);
     #endif
 /*******************************************************************************
 **
@@ -237,122 +237,122 @@
     switch (hci_evt_code)
     {
         case HCI_INQUIRY_COMP_EVT:
-            btu_hcif_inquiry_comp_evt (p, hci_evt_len);
+            btu_hcif_inquiry_comp_evt (p);
             break;
         case HCI_INQUIRY_RESULT_EVT:
-            btu_hcif_inquiry_result_evt (p, hci_evt_len);
+            btu_hcif_inquiry_result_evt (p);
             break;
         case HCI_INQUIRY_RSSI_RESULT_EVT:
-            btu_hcif_inquiry_rssi_result_evt (p, hci_evt_len);
+            btu_hcif_inquiry_rssi_result_evt (p);
             break;
 #if (BTM_EIR_CLIENT_INCLUDED == TRUE)
         case HCI_EXTENDED_INQUIRY_RESULT_EVT:
-            btu_hcif_extended_inquiry_result_evt (p, hci_evt_len);
+            btu_hcif_extended_inquiry_result_evt (p);
             break;
 #endif
         case HCI_CONNECTION_COMP_EVT:
-            btu_hcif_connection_comp_evt (p, hci_evt_len);
+            btu_hcif_connection_comp_evt (p);
             break;
         case HCI_CONNECTION_REQUEST_EVT:
-            btu_hcif_connection_request_evt (p, hci_evt_len);
+            btu_hcif_connection_request_evt (p);
             break;
         case HCI_DISCONNECTION_COMP_EVT:
-            btu_hcif_disconnection_comp_evt (p, hci_evt_len);
+            btu_hcif_disconnection_comp_evt (p);
             break;
         case HCI_AUTHENTICATION_COMP_EVT:
-            btu_hcif_authentication_comp_evt (p, hci_evt_len);
+            btu_hcif_authentication_comp_evt (p);
             break;
         case HCI_RMT_NAME_REQUEST_COMP_EVT:
             btu_hcif_rmt_name_request_comp_evt (p, hci_evt_len);
             break;
         case HCI_ENCRYPTION_CHANGE_EVT:
-            btu_hcif_encryption_change_evt (p, hci_evt_len);
+            btu_hcif_encryption_change_evt (p);
             break;
 #if BLE_INCLUDED == TRUE
         case HCI_ENCRYPTION_KEY_REFRESH_COMP_EVT:
-            btu_hcif_encyption_key_refresh_cmpl_evt(p, hci_evt_len);
+            btu_hcif_encryption_key_refresh_cmpl_evt(p);
             break;
 #endif
         case HCI_CHANGE_CONN_LINK_KEY_EVT:
-            btu_hcif_change_conn_link_key_evt (p, hci_evt_len);
+            btu_hcif_change_conn_link_key_evt (p);
             break;
         case HCI_MASTER_LINK_KEY_COMP_EVT:
-            btu_hcif_master_link_key_comp_evt (p, hci_evt_len);
+            btu_hcif_master_link_key_comp_evt (p);
             break;
         case HCI_READ_RMT_FEATURES_COMP_EVT:
-            btu_hcif_read_rmt_features_comp_evt (p, hci_evt_len);
+            btu_hcif_read_rmt_features_comp_evt (p);
             break;
         case HCI_READ_RMT_EXT_FEATURES_COMP_EVT:
-            btu_hcif_read_rmt_ext_features_comp_evt (p, hci_evt_len);
+            btu_hcif_read_rmt_ext_features_comp_evt (p);
             break;
         case HCI_READ_RMT_VERSION_COMP_EVT:
-            btu_hcif_read_rmt_version_comp_evt (p, hci_evt_len);
+            btu_hcif_read_rmt_version_comp_evt (p);
             break;
         case HCI_QOS_SETUP_COMP_EVT:
-            btu_hcif_qos_setup_comp_evt (p, hci_evt_len);
+            btu_hcif_qos_setup_comp_evt (p);
             break;
         case HCI_COMMAND_COMPLETE_EVT:
             btu_hcif_command_complete_evt (controller_id, p, hci_evt_len);
             break;
         case HCI_COMMAND_STATUS_EVT:
-            btu_hcif_command_status_evt (controller_id, p, hci_evt_len);
+            btu_hcif_command_status_evt (controller_id, p);
             break;
         case HCI_HARDWARE_ERROR_EVT:
-            btu_hcif_hardware_error_evt (p, hci_evt_len);
+            btu_hcif_hardware_error_evt (p);
             break;
         case HCI_FLUSH_OCCURED_EVT:
-            btu_hcif_flush_occured_evt (p, hci_evt_len);
+            btu_hcif_flush_occured_evt ();
             break;
         case HCI_ROLE_CHANGE_EVT:
-            btu_hcif_role_change_evt (p, hci_evt_len);
+            btu_hcif_role_change_evt (p);
             break;
         case HCI_NUM_COMPL_DATA_PKTS_EVT:
-            btu_hcif_num_compl_data_pkts_evt (p, hci_evt_len);
+            btu_hcif_num_compl_data_pkts_evt (p);
             break;
         case HCI_MODE_CHANGE_EVT:
-            btu_hcif_mode_change_evt (p, hci_evt_len);
+            btu_hcif_mode_change_evt (p);
             break;
         case HCI_RETURN_LINK_KEYS_EVT:
-            btu_hcif_return_link_keys_evt (p, hci_evt_len);
+            btu_hcif_return_link_keys_evt (p);
             break;
         case HCI_PIN_CODE_REQUEST_EVT:
-            btu_hcif_pin_code_request_evt (p, hci_evt_len);
+            btu_hcif_pin_code_request_evt (p);
             break;
         case HCI_LINK_KEY_REQUEST_EVT:
-            btu_hcif_link_key_request_evt (p, hci_evt_len);
+            btu_hcif_link_key_request_evt (p);
             break;
         case HCI_LINK_KEY_NOTIFICATION_EVT:
-            btu_hcif_link_key_notification_evt (p, hci_evt_len);
+            btu_hcif_link_key_notification_evt (p);
             break;
         case HCI_LOOPBACK_COMMAND_EVT:
-            btu_hcif_loopback_command_evt (p, hci_evt_len);
+            btu_hcif_loopback_command_evt ();
             break;
         case HCI_DATA_BUF_OVERFLOW_EVT:
-            btu_hcif_data_buf_overflow_evt (p, hci_evt_len);
+            btu_hcif_data_buf_overflow_evt ();
             break;
         case HCI_MAX_SLOTS_CHANGED_EVT:
-            btu_hcif_max_slots_changed_evt (p, hci_evt_len);
+            btu_hcif_max_slots_changed_evt ();
             break;
         case HCI_READ_CLOCK_OFF_COMP_EVT:
-            btu_hcif_read_clock_off_comp_evt (p, hci_evt_len);
+            btu_hcif_read_clock_off_comp_evt (p);
             break;
         case HCI_CONN_PKT_TYPE_CHANGE_EVT:
-            btu_hcif_conn_pkt_type_change_evt (p, hci_evt_len);
+            btu_hcif_conn_pkt_type_change_evt ();
             break;
         case HCI_QOS_VIOLATION_EVT:
-            btu_hcif_qos_violation_evt (p, hci_evt_len);
+            btu_hcif_qos_violation_evt (p);
             break;
         case HCI_PAGE_SCAN_MODE_CHANGE_EVT:
-            btu_hcif_page_scan_mode_change_evt (p, hci_evt_len);
+            btu_hcif_page_scan_mode_change_evt ();
             break;
         case HCI_PAGE_SCAN_REP_MODE_CHNG_EVT:
-            btu_hcif_page_scan_rep_mode_chng_evt (p, hci_evt_len);
+            btu_hcif_page_scan_rep_mode_chng_evt ();
             break;
         case HCI_ESCO_CONNECTION_COMP_EVT:
-            btu_hcif_esco_connection_comp_evt (p, hci_evt_len);
+            btu_hcif_esco_connection_comp_evt (p);
             break;
         case HCI_ESCO_CONNECTION_CHANGED_EVT:
-            btu_hcif_esco_connection_chg_evt (p, hci_evt_len);
+            btu_hcif_esco_connection_chg_evt (p);
             break;
 #if (BTM_SSR_INCLUDED == TRUE)
         case HCI_SNIFF_SUB_RATE_EVT:
@@ -360,40 +360,40 @@
             break;
 #endif  /* BTM_SSR_INCLUDED == TRUE */
         case HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT:
-            btu_hcif_host_support_evt (p, hci_evt_len);
+            btu_hcif_host_support_evt (p);
             break;
         case HCI_IO_CAPABILITY_REQUEST_EVT:
-            btu_hcif_io_cap_request_evt (p, hci_evt_len);
+            btu_hcif_io_cap_request_evt (p);
             break;
         case HCI_IO_CAPABILITY_RESPONSE_EVT:
-            btu_hcif_io_cap_response_evt (p, hci_evt_len);
+            btu_hcif_io_cap_response_evt (p);
             break;
         case HCI_USER_CONFIRMATION_REQUEST_EVT:
-            btu_hcif_user_conf_request_evt (p, hci_evt_len);
+            btu_hcif_user_conf_request_evt (p);
             break;
         case HCI_USER_PASSKEY_REQUEST_EVT:
-            btu_hcif_user_passkey_request_evt (p, hci_evt_len);
+            btu_hcif_user_passkey_request_evt (p);
             break;
 #if BTM_OOB_INCLUDED == TRUE
         case HCI_REMOTE_OOB_DATA_REQUEST_EVT:
-            btu_hcif_rem_oob_request_evt (p, hci_evt_len);
+            btu_hcif_rem_oob_request_evt (p);
             break;
 #endif
         case HCI_SIMPLE_PAIRING_COMPLETE_EVT:
-            btu_hcif_simple_pair_complete_evt (p, hci_evt_len);
+            btu_hcif_simple_pair_complete_evt (p);
             break;
         case HCI_USER_PASSKEY_NOTIFY_EVT:
-            btu_hcif_user_passkey_notif_evt (p, hci_evt_len);
+            btu_hcif_user_passkey_notif_evt (p);
             break;
         case HCI_KEYPRESS_NOTIFY_EVT:
-            btu_hcif_keypress_notif_evt (p, hci_evt_len);
+            btu_hcif_keypress_notif_evt (p);
             break;
         case HCI_LINK_SUPER_TOUT_CHANGED_EVT:
-            btu_hcif_link_super_tout_evt (p, hci_evt_len);
+            btu_hcif_link_super_tout_evt (p);
             break;
 #if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE
         case HCI_ENHANCED_FLUSH_COMPLETE_EVT:
-            btu_hcif_enhanced_flush_complete_evt (p, hci_evt_len);
+            btu_hcif_enhanced_flush_complete_evt ();
             break;
 #endif
 
@@ -407,19 +407,19 @@
             switch (ble_sub_code)
             {
                 case HCI_BLE_ADV_PKT_RPT_EVT: /* result of inquiry */
-                    btu_ble_process_adv_pkt(p, hci_evt_len);
+                    btu_ble_process_adv_pkt(p);
                     break;
                 case HCI_BLE_CONN_COMPLETE_EVT:
                     btu_ble_ll_conn_complete_evt(p, hci_evt_len);
                     break;
                 case HCI_BLE_LL_CONN_PARAM_UPD_EVT:
-                    btu_ble_ll_conn_param_upd_evt(p, hci_evt_len);
+                    btu_ble_ll_conn_param_upd_evt(p);
                     break;
                 case HCI_BLE_READ_REMOTE_FEAT_CMPL_EVT:
-                    btu_ble_read_remote_feat_evt(p, hci_evt_len);
+                    btu_ble_read_remote_feat_evt(p);
                     break;
                 case HCI_BLE_LTK_REQ_EVT: /* received only at slave device */
-                    btu_ble_proc_ltk_req(p, hci_evt_len);
+                    btu_ble_proc_ltk_req(p);
                     break;
             }
             break;
@@ -560,7 +560,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_inquiry_comp_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_inquiry_comp_evt (UINT8 *p)
 {
     UINT8   status;
 
@@ -580,7 +580,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_inquiry_result_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_inquiry_result_evt (UINT8 *p)
 {
     /* Store results in the cache */
     btm_process_inq_results (p, BTM_INQ_RESULT_STANDARD);
@@ -595,7 +595,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_inquiry_rssi_result_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_inquiry_rssi_result_evt (UINT8 *p)
 {
     /* Store results in the cache */
     btm_process_inq_results (p, BTM_INQ_RESULT_WITH_RSSI);
@@ -611,7 +611,7 @@
 **
 *******************************************************************************/
 #if (BTM_EIR_CLIENT_INCLUDED == TRUE)
-static void btu_hcif_extended_inquiry_result_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_extended_inquiry_result_evt (UINT8 *p)
 {
     /* Store results in the cache */
     btm_process_inq_results (p, BTM_INQ_RESULT_EXTENDED);
@@ -627,7 +627,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_connection_comp_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_connection_comp_evt (UINT8 *p)
 {
     UINT8       status;
     UINT16      handle;
@@ -673,7 +673,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_connection_request_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_connection_request_evt (UINT8 *p)
 {
     BD_ADDR     bda;
     DEV_CLASS   dc;
@@ -707,7 +707,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_disconnection_comp_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_disconnection_comp_evt (UINT8 *p)
 {
     UINT8   status;
     UINT16  handle;
@@ -740,7 +740,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_authentication_comp_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_authentication_comp_evt (UINT8 *p)
 {
     UINT8   status;
     UINT16  handle;
@@ -786,7 +786,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_encryption_change_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_encryption_change_evt (UINT8 *p)
 {
     UINT8   status;
     UINT16  handle;
@@ -810,7 +810,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_change_conn_link_key_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_change_conn_link_key_evt (UINT8 *p)
 {
     UINT8   status;
     UINT16  handle;
@@ -831,7 +831,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_master_link_key_comp_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_master_link_key_comp_evt (UINT8 *p)
 {
     UINT8   status;
     UINT16  handle;
@@ -854,7 +854,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_read_rmt_features_comp_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_read_rmt_features_comp_evt (UINT8 *p)
 {
     btm_read_remote_features_complete(p);
 }
@@ -868,7 +868,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_read_rmt_ext_features_comp_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_read_rmt_ext_features_comp_evt (UINT8 *p)
 {
     UINT8 *p_cur = p;
     UINT8 status;
@@ -894,7 +894,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_read_rmt_version_comp_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_read_rmt_version_comp_evt (UINT8 *p)
 {
     btm_read_remote_version_complete (p);
 }
@@ -909,7 +909,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_qos_setup_comp_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_qos_setup_comp_evt (UINT8 *p)
 {
     UINT8 status;
     UINT16 handle;
@@ -937,7 +937,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_esco_connection_comp_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_esco_connection_comp_evt (UINT8 *p)
 {
 #if BTM_SCO_INCLUDED == TRUE
     tBTM_ESCO_DATA  data;
@@ -971,7 +971,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_esco_connection_chg_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_esco_connection_chg_evt (UINT8 *p)
 {
 #if BTM_SCO_INCLUDED == TRUE
     UINT16  handle;
@@ -1004,7 +1004,7 @@
 **
 *******************************************************************************/
 static void btu_hcif_hdl_command_complete (UINT16 opcode, UINT8 *p, UINT16 evt_len,
-                                           void *p_cplt_cback, UINT8 ctr_id)
+                                           void *p_cplt_cback)
 {
     switch (opcode)
     {
@@ -1242,7 +1242,7 @@
     }
 
     /* handle event */
-    btu_hcif_hdl_command_complete (cc_opcode, p, evt_len, p_cplt_cback, controller_id);
+    btu_hcif_hdl_command_complete (cc_opcode, p, evt_len, p_cplt_cback);
 
     /* see if we can send more commands */
     btu_hcif_send_cmd (controller_id, NULL);
@@ -1259,7 +1259,7 @@
 **
 *******************************************************************************/
 static void btu_hcif_hdl_command_status (UINT16 opcode, UINT8 status, UINT8 *p_cmd,
-                                         void *p_vsc_status_cback, UINT8 controller_id)
+                                         void *p_vsc_status_cback)
 {
     BD_ADDR         bd_addr;
     UINT16          handle;
@@ -1424,7 +1424,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_command_status_evt (UINT8 controller_id, UINT8 *p, UINT16 evt_len)
+static void btu_hcif_command_status_evt (UINT8 controller_id, UINT8 *p)
 {
     tHCI_CMD_CB * p_hci_cmd_cb = &(btu_cb.hci_cmd_cb[controller_id]);
     UINT8       status;
@@ -1495,7 +1495,7 @@
     }
 
     /* handle command */
-    btu_hcif_hdl_command_status (opcode, status, p_data, p_vsc_status_cback, controller_id);
+    btu_hcif_hdl_command_status (opcode, status, p_data, p_vsc_status_cback);
 
     /* free stored command */
     if (p_cmd != NULL)
@@ -1621,7 +1621,7 @@
         case HCI_SETUP_ESCO_CONNECTION:
 #endif
             /* fake a command status */
-            btu_hcif_hdl_command_status (opcode, HCI_ERR_UNSPECIFIED, p, NULL, controller_id);
+            btu_hcif_hdl_command_status (opcode, HCI_ERR_UNSPECIFIED, p, NULL);
             break;
 
         default:
@@ -1643,7 +1643,7 @@
 
             /* fake a command complete; first create a fake event */
             event = HCI_ERR_UNSPECIFIED;
-            btu_hcif_hdl_command_complete (opcode, (UINT8 *)&event, 1, p_cplt_cback, controller_id);
+            btu_hcif_hdl_command_complete (opcode, (UINT8 *)&event, 1, p_cplt_cback);
             break;
     }
 
@@ -1683,7 +1683,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_hardware_error_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_hardware_error_evt (UINT8 *p)
 {
     BT_TRACE_1 (TRACE_LAYER_HCI, TRACE_TYPE_ERROR, "Ctlr H/w error event - code:0x%x", *p);
 
@@ -1705,7 +1705,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_flush_occured_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_flush_occured_evt (void)
 {
 }
 
@@ -1719,7 +1719,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_role_change_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_role_change_evt (UINT8 *p)
 {
     UINT8       status;
     BD_ADDR     bda;
@@ -1743,7 +1743,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_num_compl_data_pkts_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_num_compl_data_pkts_evt (UINT8 *p)
 {
     /* Process for L2CAP and SCO */
     l2c_link_process_num_completed_pkts (p);
@@ -1761,7 +1761,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_mode_change_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_mode_change_evt (UINT8 *p)
 {
     UINT8       status;
     UINT16      handle;
@@ -1816,7 +1816,7 @@
 **
 *******************************************************************************/
 
-static void btu_hcif_return_link_keys_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_return_link_keys_evt (UINT8 *p)
 {
     UINT8                       num_keys;
     tBTM_RETURN_LINK_KEYS_EVT   *result;
@@ -1846,7 +1846,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_pin_code_request_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_pin_code_request_evt (UINT8 *p)
 {
     BD_ADDR  bda;
 
@@ -1869,7 +1869,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_link_key_request_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_link_key_request_evt (UINT8 *p)
 {
     BD_ADDR  bda;
 
@@ -1887,7 +1887,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_link_key_notification_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_link_key_notification_evt (UINT8 *p)
 {
     BD_ADDR  bda;
     LINK_KEY key;
@@ -1910,7 +1910,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_loopback_command_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_loopback_command_evt (void)
 {
 }
 
@@ -1924,7 +1924,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_data_buf_overflow_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_data_buf_overflow_evt (void)
 {
 }
 
@@ -1938,7 +1938,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_max_slots_changed_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_max_slots_changed_evt (void)
 {
 }
 
@@ -1952,7 +1952,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_read_clock_off_comp_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_read_clock_off_comp_evt (UINT8 *p)
 {
     UINT8       status;
     UINT16      handle;
@@ -1983,7 +1983,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_conn_pkt_type_change_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_conn_pkt_type_change_evt (void)
 {
 }
 
@@ -1997,7 +1997,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_qos_violation_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_qos_violation_evt (UINT8 *p)
 {
     UINT16   handle;
 
@@ -2019,7 +2019,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_page_scan_mode_change_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_page_scan_mode_change_evt (void)
 {
 }
 
@@ -2033,7 +2033,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_page_scan_rep_mode_chng_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_page_scan_rep_mode_chng_evt (void)
 {
 }
 
@@ -2050,7 +2050,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_host_support_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_host_support_evt (UINT8 *p)
 {
     btm_sec_rmt_host_support_feat_evt(p);
 }
@@ -2064,7 +2064,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_io_cap_request_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_io_cap_request_evt (UINT8 *p)
 {
     btm_io_capabilities_req(p);
 }
@@ -2079,7 +2079,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_io_cap_response_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_io_cap_response_evt (UINT8 *p)
 {
     btm_io_capabilities_rsp(p);
 }
@@ -2094,7 +2094,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_user_conf_request_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_user_conf_request_evt (UINT8 *p)
 {
     btm_proc_sp_req_evt(BTM_SP_CFM_REQ_EVT, p);
 }
@@ -2109,7 +2109,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_user_passkey_request_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_user_passkey_request_evt (UINT8 *p)
 {
     btm_proc_sp_req_evt(BTM_SP_KEY_REQ_EVT, p);
 }
@@ -2123,7 +2123,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_user_passkey_notif_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_user_passkey_notif_evt (UINT8 *p)
 {
     btm_proc_sp_req_evt(BTM_SP_KEY_NOTIF_EVT, p);
 }
@@ -2137,7 +2137,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_keypress_notif_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_keypress_notif_evt (UINT8 *p)
 {
     btm_keypress_notif_evt(p);
 }
@@ -2151,7 +2151,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_link_super_tout_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_link_super_tout_evt (UINT8 *p)
 {
     UINT16 handle, timeout;
     STREAM_TO_UINT16 (handle, p);
@@ -2170,7 +2170,7 @@
 **
 *******************************************************************************/
     #if BTM_OOB_INCLUDED == TRUE
-static void btu_hcif_rem_oob_request_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_rem_oob_request_evt (UINT8 *p)
 {
     btm_rem_oob_req(p);
 }
@@ -2185,7 +2185,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void btu_hcif_simple_pair_complete_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_simple_pair_complete_evt (UINT8 *p)
 {
     btm_simple_pair_complete(p);
 }
@@ -2224,7 +2224,7 @@
 **
 *******************************************************************************/
 #if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE
-static void btu_hcif_enhanced_flush_complete_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_enhanced_flush_complete_evt (void)
 {
 /* This is empty until an upper layer cares about returning event */
 }
@@ -2238,7 +2238,7 @@
 ** BLE Events
 ***********************************************/
 #if (defined BLE_INCLUDED) && (BLE_INCLUDED == TRUE)
-static void btu_hcif_encyption_key_refresh_cmpl_evt (UINT8 *p, UINT16 evt_len)
+static void btu_hcif_encryption_key_refresh_cmpl_evt (UINT8 *p)
 {
     UINT8   status;
     UINT8   enc_enable = 0;
@@ -2252,7 +2252,7 @@
     btm_sec_encrypt_change (handle, status, enc_enable);
 }
 
-static void btu_ble_process_adv_pkt (UINT8 *p, UINT16 evt_len)
+static void btu_ble_process_adv_pkt (UINT8 *p)
 {
     BT_TRACE_0 (TRACE_LAYER_HCI, TRACE_TYPE_EVENT, "btu_ble_process_adv_pkt");
 
@@ -2264,7 +2264,7 @@
     btm_ble_conn_complete(p, evt_len);
 }
 
-static void btu_ble_ll_conn_param_upd_evt (UINT8 *p, UINT16 evt_len)
+static void btu_ble_ll_conn_param_upd_evt (UINT8 *p)
 {
     /* LE connection update has completed successfully as a master. */
     /* We can enable the update request if the result is a success. */
@@ -2278,12 +2278,12 @@
     L2CA_HandleConnUpdateEvent(handle, status);
 }
 
-static void btu_ble_read_remote_feat_evt (UINT8 *p, UINT16 evt_len)
+static void btu_ble_read_remote_feat_evt (UINT8 *p)
 {
     btm_ble_read_remote_features_complete(p);
 }
 
-static void btu_ble_proc_ltk_req (UINT8 *p, UINT16 evt_len)
+static void btu_ble_proc_ltk_req (UINT8 *p)
 {
     UINT16 ediv, handle;
     UINT8   *pp;
diff --git a/stack/btu/btu_task.c b/stack/btu/btu_task.c
index da9a54d..9c09214 100644
--- a/stack/btu/btu_task.c
+++ b/stack/btu/btu_task.c
@@ -166,6 +166,7 @@
     UINT8            i;
     UINT16           mask;
     BOOLEAN          handled;
+    UNUSED(param);
 
 #if (defined(HCISU_H4_INCLUDED) && HCISU_H4_INCLUDED == TRUE)
     /* wait an event that HCISU is ready */
diff --git a/stack/gap/gap_api.c b/stack/gap/gap_api.c
index d17895d..fb90d03 100644
--- a/stack/gap/gap_api.c
+++ b/stack/gap/gap_api.c
@@ -19,6 +19,7 @@
 #include <string.h>
 
 #include "bt_target.h"
+#include "bt_utils.h"
 #include "gap_int.h"
 #include "btm_int.h"
 #include "gki.h"
@@ -683,6 +684,10 @@
 UINT16 GAP_ReadLocalDeviceInfo(UINT8 *name, BD_ADDR *addr, tGAP_LMP_VERSION *verinfo,
                                tGAP_LMP_FEATURES *features)
 {
+    UNUSED(name);
+    UNUSED(addr);
+    UNUSED(verinfo);
+    UNUSED(features);
     return (GAP_UNSUPPORTED);
 }
 
diff --git a/stack/gap/gap_ble.c b/stack/gap/gap_ble.c
index 48f4723..d44577d 100644
--- a/stack/gap/gap_ble.c
+++ b/stack/gap/gap_ble.c
@@ -19,6 +19,7 @@
 
 #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE)
 
+#include "bt_utils.h"
 #include <string.h>
 #include "gap_int.h"
 #include "gap_api.h"
@@ -345,6 +346,7 @@
 tGATT_STATUS gap_proc_read (tGATTS_REQ_TYPE type, tGATT_READ_REQ *p_data, tGATTS_RSP *p_rsp)
 {
     tGATT_STATUS    status = GATT_NO_RESOURCES;
+    UNUSED(type);
 
     if (p_data->is_long)
         p_rsp->attr_value.offset = p_data->offset;
@@ -381,6 +383,7 @@
 {
     tGAP_ATTR   *p_db_attr = gap_cb.gatt_attr;
     UINT8   i;
+    UNUSED(type);
 
     for (i = 0; i < GAP_MAX_CHAR_NUM; i ++, p_db_attr ++)
     {
@@ -613,6 +616,7 @@
 {
     tGAP_CLCB   *p_clcb = gap_find_clcb_by_bd_addr (bda);
     UINT16      cl_op_uuid;
+    UNUSED(gatt_if);
 
     GAP_TRACE_EVENT5 ("gap_ble_c_connect_cback: from %08x%04x connected:%d conn_id=%d reason = 0x%04x",
                       (bda[0]<<24)+(bda[1]<<16)+(bda[2]<<8)+bda[3],
diff --git a/stack/gap/gap_conn.c b/stack/gap/gap_conn.c
index 43765b7..44bb5ec 100644
--- a/stack/gap/gap_conn.c
+++ b/stack/gap/gap_conn.c
@@ -18,6 +18,7 @@
 
 
 #include "bt_target.h"
+#include "bt_utils.h"
 #include "btu.h"
 #include "gap_int.h"
 #include "l2cdefs.h"
@@ -801,6 +802,7 @@
 static void gap_sec_check_complete (BD_ADDR bd_addr, void *p_ref_data, UINT8 res)
 {
     tGAP_CCB *p_ccb = (tGAP_CCB *)p_ref_data;
+    UNUSED(bd_addr);
 
     GAP_TRACE_EVENT3 ("gap_sec_check_complete conn_state:%d, conn_flags:0x%x, status:%d",
         p_ccb->con_state, p_ccb->con_flags, res);
diff --git a/stack/gap/gap_utils.c b/stack/gap/gap_utils.c
index d253a99..866ad7a 100644
--- a/stack/gap/gap_utils.c
+++ b/stack/gap/gap_utils.c
@@ -18,6 +18,7 @@
 
 #include <string.h>
 #include "bt_target.h"
+#include "bt_utils.h"
 #include "gap_int.h"
 
 /*****************************************************************************/
@@ -116,6 +117,7 @@
 {
     tGAP_INFO   *p_cb;
     UINT8        index;
+    UNUSED(p_eir);
 
     GAP_TRACE_EVENT6 ("GAP Inquiry Results Callback (bdaddr [%02x%02x%02x%02x%02x%02x])",
                 p_results->remote_bd_addr[0], p_results->remote_bd_addr[1],
@@ -305,6 +307,8 @@
 
     return (GAP_EOINQDB);
 #else
+    UNUSED(devname);
+    UNUSED(bd_addr);
     /* No data available because we are not automatically saving the data */
     return (GAP_NO_DATA_AVAIL);
 #endif
diff --git a/stack/gatt/att_protocol.c b/stack/gatt/att_protocol.c
index 9c715af..3348599 100644
--- a/stack/gatt/att_protocol.c
+++ b/stack/gatt/att_protocol.c
@@ -495,7 +495,7 @@
                 /* do not enq cmd if handle value confirmation or set request */
                 if (cmd_code != GATT_HANDLE_VALUE_CONF && cmd_code != GATT_CMD_WRITE)
                 {
-                    gatt_start_rsp_timer (p_tcb);
+                    gatt_start_rsp_timer (clcb_idx);
                     gatt_cmd_enq(p_tcb, clcb_idx, FALSE, cmd_code, NULL);
                 }
             }
diff --git a/stack/gatt/gatt_api.c b/stack/gatt/gatt_api.c
index b53b7c5..54ea0f0 100644
--- a/stack/gatt/gatt_api.c
+++ b/stack/gatt/gatt_api.c
@@ -1285,6 +1285,7 @@
                     (p_clcb->p_reg->gatt_if == gatt_if) &&
                     (p_clcb->p_tcb->tcb_idx == p_tcb->tcb_idx))
                 {
+                    btu_stop_timer(&p_clcb->rsp_timer_ent);
                     gatt_clcb_dealloc (p_clcb);
                     break;
                 }
@@ -1294,7 +1295,7 @@
 
     gatt_deregister_bgdev_list(gatt_if);
     /* update the listen mode */
-#ifdef BLE_PERIPHERAL_MODE_SUPPORT
+#if (defined(BLE_PERIPHERAL_MODE_SUPPORT) && (BLE_PERIPHERAL_MODE_SUPPORT == TRUE))
     GATT_Listen(gatt_if, FALSE, NULL);
 #endif
 
diff --git a/stack/gatt/gatt_attr.c b/stack/gatt/gatt_attr.c
index 9af6a60..1ee4ae3 100644
--- a/stack/gatt/gatt_attr.c
+++ b/stack/gatt/gatt_attr.c
@@ -24,6 +24,7 @@
  ******************************************************************************/
 
 #include "bt_target.h"
+#include "bt_utils.h"
 
 #include "gatt_api.h"
 #include "gatt_int.h"
@@ -216,6 +217,8 @@
 static void gatt_profile_connect_cback (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id,
                                         BOOLEAN connected, tGATT_DISCONN_REASON reason)
 {
+    UNUSED(gatt_if);
+
     GATT_TRACE_EVENT5 ("gatt_profile_connect_cback: from %08x%04x connected:%d conn_id=%d reason = 0x%04x",
                        (bda[0]<<24)+(bda[1]<<16)+(bda[2]<<8)+bda[3],
                        (bda[4]<<8)+bda[5], connected, conn_id, reason);
diff --git a/stack/gatt/gatt_auth.c b/stack/gatt/gatt_auth.c
index e945c90..7dc99e1 100644
--- a/stack/gatt/gatt_auth.c
+++ b/stack/gatt/gatt_auth.c
@@ -22,6 +22,7 @@
  *
  ******************************************************************************/
 #include "bt_target.h"
+#include "bt_utils.h"
 
 #if BLE_INCLUDED == TRUE
 #include <string.h>
@@ -163,6 +164,7 @@
     BOOLEAN     status = FALSE;
     tGATT_PENDING_ENC_CLCB  *p_buf;
     UINT16       count;
+    UNUSED(p_ref_data);
 
     GATT_TRACE_DEBUG0("gatt_enc_cmpl_cback");
     if ((p_tcb = gatt_find_tcb_by_addr(bd_addr)) != NULL)
diff --git a/stack/gatt/gatt_cl.c b/stack/gatt/gatt_cl.c
index b173be9..e8c41fc 100644
--- a/stack/gatt/gatt_cl.c
+++ b/stack/gatt/gatt_cl.c
@@ -402,7 +402,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-void gatt_process_find_type_value_rsp (tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT16 len, UINT8 *p_data)
+static void gatt_process_find_type_value_rsp (tGATT_CLCB *p_clcb, UINT16 len, UINT8 *p_data)
 {
     tGATT_DISC_RES      result;
     UINT8               *p = p_data;
@@ -445,8 +445,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-void gatt_process_read_info_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT8 op_code,
-                                UINT16 len, UINT8 *p_data)
+static void gatt_process_read_info_rsp(tGATT_CLCB *p_clcb, UINT16 len, UINT8 *p_data)
 {
     tGATT_DISC_RES  result;
     UINT8   *p = p_data, uuid_len = 0, type;
@@ -501,8 +500,7 @@
 ** Returns          void.
 **
 *******************************************************************************/
-void gatt_proc_disc_error_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT8 opcode,
-                              UINT16 handle, UINT8 reason)
+static void gatt_proc_disc_error_rsp(tGATT_CLCB *p_clcb, UINT8 opcode, UINT8 reason)
 {
     tGATT_STATUS    status = (tGATT_STATUS) reason;
 
@@ -538,8 +536,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-void gatt_process_error_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT8 op_code,
-                            UINT16 len, UINT8 *p_data)
+static void gatt_process_error_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT8 *p_data)
 {
     UINT8   opcode, reason, * p= p_data;
     UINT16  handle;
@@ -552,7 +549,7 @@
 
     if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY)
     {
-        gatt_proc_disc_error_rsp(p_tcb, p_clcb, opcode, handle, reason);
+        gatt_proc_disc_error_rsp(p_clcb, opcode, reason);
     }
     else
     {
@@ -924,8 +921,8 @@
 ** Returns          void
 **
 *******************************************************************************/
-void gatt_process_read_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb,  UINT8 op_code,
-                           UINT16 len, UINT8 *p_data)
+static void gatt_process_read_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb,
+                                  UINT16 len, UINT8 *p_data)
 {
     UINT16      offset = p_clcb->counter;
     UINT8       * p= p_data;
@@ -1096,7 +1093,7 @@
             /* dequeue the request if is write command or sign write */
             if (p_cmd->op_code != GATT_CMD_WRITE && p_cmd->op_code != GATT_SIGN_CMD_WRITE)
             {
-                gatt_start_rsp_timer (p_tcb);
+                gatt_start_rsp_timer (p_cmd->clcb_idx);
             }
             else
             {
@@ -1153,7 +1150,10 @@
             return;
         }
         else
-            btu_stop_timer (&p_tcb->rsp_timer_ent);
+        {
+            btu_stop_timer (&p_clcb->rsp_timer_ent);
+            p_clcb->retry_count = 0;
+        }
     }
     /* the size of the message may not be bigger than the local max PDU size*/
     /* The message has to be smaller than the agreed MTU, len does not count op_code */
@@ -1169,7 +1169,7 @@
         switch (op_code)
         {
             case GATT_RSP_ERROR:
-                gatt_process_error_rsp(p_tcb, p_clcb, op_code, len, p_data);
+                gatt_process_error_rsp(p_tcb, p_clcb, p_data);
                 break;
 
             case GATT_RSP_MTU:       /* 2 bytes mtu */
@@ -1177,7 +1177,7 @@
                 break;
 
             case GATT_RSP_FIND_INFO:
-                gatt_process_read_info_rsp(p_tcb, p_clcb, op_code, len, p_data);
+                gatt_process_read_info_rsp(p_clcb, len, p_data);
                 break;
 
             case GATT_RSP_READ_BY_TYPE:
@@ -1188,11 +1188,11 @@
             case GATT_RSP_READ:
             case GATT_RSP_READ_BLOB:
             case GATT_RSP_READ_MULTI:
-                gatt_process_read_rsp(p_tcb, p_clcb, op_code, len, p_data);
+                gatt_process_read_rsp(p_tcb, p_clcb, len, p_data);
                 break;
 
             case GATT_RSP_FIND_TYPE_VALUE: /* disc service with UUID */
-                gatt_process_find_type_value_rsp(p_tcb, p_clcb, len, p_data);
+                gatt_process_find_type_value_rsp(p_clcb, len, p_data);
                 break;
 
             case GATT_RSP_WRITE:
diff --git a/stack/gatt/gatt_db.c b/stack/gatt/gatt_db.c
index fa636fb..268bc7d 100644
--- a/stack/gatt/gatt_db.c
+++ b/stack/gatt/gatt_db.c
@@ -32,6 +32,7 @@
 #include <string.h>
 #include "gatt_int.h"
 #include "l2c_api.h"
+#include "btm_int.h"
 
 /********************************************************************************
 **              L O C A L    F U N C T I O N     P R O T O T Y P E S            *
@@ -114,7 +115,6 @@
 **
 *******************************************************************************/
 static tGATT_STATUS gatts_check_attr_readability(tGATT_ATTR16 *p_attr,
-                                                 UINT16 offset,
                                                  BOOLEAN read_long,
                                                  tGATT_SEC_FLAG sec_flag,
                                                  UINT8 key_size)
@@ -223,7 +223,7 @@
                       offset,
                       read_long);
 
-    status = gatts_check_attr_readability((tGATT_ATTR16 *)p_attr, offset, read_long, sec_flag, key_size);
+    status = gatts_check_attr_readability((tGATT_ATTR16 *)p_attr, read_long, sec_flag, key_size);
 
     if (p_attr16->uuid_type == GATT_ATTR_UUID_TYPE_16)
         uuid16 = p_attr16->uuid;
@@ -330,6 +330,9 @@
     UINT16      len = 0;
     UINT8       *p = (UINT8 *)(p_rsp + 1) + p_rsp->len + L2CAP_MIN_OFFSET;
     tBT_UUID    attr_uuid;
+#if (defined(BLE_DELAY_REQUEST_ENC) && (BLE_DELAY_REQUEST_ENC == TRUE))
+    UINT8       flag;
+#endif
 
     if (p_db && p_db->p_attr_list)
     {
@@ -394,6 +397,26 @@
         }
     }
 
+#if (defined(BLE_DELAY_REQUEST_ENC) && (BLE_DELAY_REQUEST_ENC == TRUE))
+    if (BTM_GetSecurityFlags(p_tcb->peer_bda, &flag))
+    {
+        if ((p_tcb->att_lcid == L2CAP_ATT_CID) && (status == GATT_PENDING) &&
+            (type.uu.uuid16 == GATT_UUID_GAP_DEVICE_NAME))
+        {
+            if ((flag & (BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_FLAG_ENCRYPTED)) ==
+                 BTM_SEC_LINK_KEY_KNOWN)
+            {
+                tACL_CONN         *p;
+                p = btm_bda_to_acl(p_tcb->peer_bda);
+                if ((p != NULL) && (p->link_role == BTM_ROLE_MASTER))
+                {
+                    tBTM_BLE_SEC_ACT sec_act = BTM_BLE_SEC_ENCRYPT;
+                    btm_ble_set_encryption(p_tcb->peer_bda, &sec_act, p->link_role);
+                }
+            }
+        }
+    }
+#endif
     return status;
 }
 
@@ -672,7 +695,7 @@
         {
             if (p_attr->handle == handle)
             {
-                status = gatts_check_attr_readability (p_attr, 0,
+                status = gatts_check_attr_readability (p_attr,
                                                        is_long,
                                                        sec_flag, key_size);
                 break;
diff --git a/stack/gatt/gatt_int.h b/stack/gatt/gatt_int.h
index 48278c2..1f81d63 100644
--- a/stack/gatt/gatt_int.h
+++ b/stack/gatt/gatt_int.h
@@ -78,6 +78,8 @@
 
 /* wait for ATT cmd response timeout value */
 #define GATT_WAIT_FOR_RSP_TOUT       30
+#define GATT_WAIT_FOR_DISC_RSP_TOUT  5
+#define GATT_REQ_RETRY_LIMIT         2
 
 /* characteristic descriptor type */
 #define GATT_DESCR_EXT_DSCPTOR   1    /* Characteristic Extended Properties */
@@ -360,7 +362,6 @@
     UINT8            ind_count;
 
     tGATT_CMD_Q       cl_cmd_q[GATT_CL_MAX_LCB];
-    TIMER_LIST_ENT    rsp_timer_ent;        /* peer response timer */
     TIMER_LIST_ENT    ind_ack_timer_ent;    /* local app confirm to indication timer */
     UINT8             pending_cl_req;
     UINT8             next_slot_inq;    /* index of next available slot in queue */
@@ -397,6 +398,8 @@
     BOOLEAN                 first_read_blob_after_read;
     tGATT_READ_INC_UUID128  read_uuid128;
     BOOLEAN                 in_use;
+    TIMER_LIST_ENT          rsp_timer_ent;  /* peer response timer */
+    UINT8                   retry_count;
 } tGATT_CLCB;
 
 typedef struct
@@ -556,7 +559,7 @@
 extern UINT8 gatt_build_uuid_to_stream(UINT8 **p_dst, tBT_UUID uuid);
 extern BOOLEAN gatt_uuid_compare(tBT_UUID src, tBT_UUID tar);
 extern void gatt_sr_get_sec_info(BD_ADDR rem_bda, BOOLEAN le_conn, UINT8 *p_sec_flag, UINT8 *p_key_size);
-extern void gatt_start_rsp_timer(tGATT_TCB    *p_tcb);
+extern void gatt_start_rsp_timer(UINT16 clcb_idx);
 extern void gatt_start_conf_timer(tGATT_TCB    *p_tcb);
 extern void gatt_rsp_timeout(TIMER_LIST_ENT *p_tle);
 extern void gatt_ind_ack_timeout(TIMER_LIST_ENT *p_tle);
diff --git a/stack/gatt/gatt_main.c b/stack/gatt/gatt_main.c
index 07c2c5e..d5e017b 100644
--- a/stack/gatt/gatt_main.c
+++ b/stack/gatt/gatt_main.c
@@ -31,6 +31,7 @@
 #include "l2c_api.h"
 #include "btm_int.h"
 #include "btm_ble_int.h"
+#include "bt_utils.h"
 
 /* Configuration flags. */
 #define GATT_L2C_CFG_IND_DONE   (1<<0)
@@ -66,6 +67,7 @@
     gatt_l2cif_disconnect_cfm_cback,
     NULL,
     gatt_l2cif_data_ind_cback,
+    NULL,
     NULL
 } ;
 
@@ -507,6 +509,7 @@
     UINT8       result = L2CAP_CONN_OK;
     tL2CAP_CFG_INFO cfg;
     tGATT_TCB       *p_tcb = gatt_find_tcb_by_addr(bd_addr);
+    UNUSED(psm);
 
     GATT_TRACE_ERROR1("Connection indication cid = %d", lcid);
     /* new connection ? */
@@ -766,6 +769,7 @@
 {
     tGATT_TCB       *p_tcb;
     UINT16          reason;
+    UNUSED(result);
 
     /* look up clcb for this channel */
     if ((p_tcb = gatt_find_tcb_by_cid(lcid)) != NULL)
diff --git a/stack/gatt/gatt_sr.c b/stack/gatt/gatt_sr.c
index 6817283..c006dd2 100644
--- a/stack/gatt/gatt_sr.c
+++ b/stack/gatt/gatt_sr.c
@@ -23,6 +23,7 @@
  ******************************************************************************/
 
 #include "bt_target.h"
+#include "bt_utils.h"
 
 #if BLE_INCLUDED == TRUE
 #include <string.h>
@@ -262,6 +263,7 @@
                                       tGATT_STATUS status, tGATTS_RSP *p_msg)
 {
     tGATT_STATUS    ret_code = GATT_SUCCESS;
+    UNUSED(trans_id);
 
     GATT_TRACE_DEBUG1("gatt_sr_process_app_rsp gatt_if=%d", gatt_if);
 
@@ -326,7 +328,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-void gatt_process_exec_write_req (tGATT_TCB *p_tcb, UINT8 op_code, UINT16 len, UINT8 *p_data)
+static void gatt_process_exec_write_req (tGATT_TCB *p_tcb, UINT8 op_code, UINT8 *p_data)
 {
     UINT8   *p = p_data, flag, i = 0;
     UINT32  trans_id = 0;
@@ -525,7 +527,7 @@
 *******************************************************************************/
 static tGATT_STATUS gatt_build_primary_service_rsp (BT_HDR *p_msg, tGATT_TCB *p_tcb,
                                                     UINT8 op_code, UINT16 s_hdl,
-                                                    UINT16 e_hdl, UINT8 *p_data, tBT_UUID value)
+                                                    UINT16 e_hdl, tBT_UUID value)
 {
     tGATT_STATUS    status = GATT_NOT_FOUND;
     UINT8           handle_len =4, *p ;
@@ -784,7 +786,7 @@
                 else
                 {
                     memset(p_msg, 0, msg_len);
-                    reason = gatt_build_primary_service_rsp (p_msg, p_tcb, op_code, s_hdl, e_hdl, p_data, value);
+                    reason = gatt_build_primary_service_rsp (p_msg, p_tcb, op_code, s_hdl, e_hdl, value);
                 }
             }
         }
@@ -927,6 +929,8 @@
         else
             p_tcb->payload_size = mtu;
 
+        GATT_TRACE_ERROR1("MTU request PDU with MTU size %d", p_tcb->payload_size);
+
         if ((p_buf = attp_build_sr_msg(p_tcb, GATT_RSP_MTU, (tGATT_SR_MSG *) &p_tcb->payload_size)) != NULL)
         {
             attp_send_sr_msg (p_tcb, p_buf);
@@ -1169,7 +1173,7 @@
 **
 *******************************************************************************/
 static void gatts_process_read_req(tGATT_TCB *p_tcb, tGATT_SR_REG *p_rcb, UINT8 op_code,
-                                   UINT16 handle, UINT16 len, UINT8 *p_data)
+                                   UINT16 handle, UINT8 *p_data)
 {
     UINT16          buf_len = (UINT16)(sizeof(BT_HDR) + p_tcb->payload_size + L2CAP_MIN_OFFSET);
     tGATT_STATUS    reason;
@@ -1285,7 +1289,7 @@
                         {
                             case GATT_REQ_READ: /* read char/char descriptor value */
                             case GATT_REQ_READ_BLOB:
-                                gatts_process_read_req(p_tcb, p_rcb, op_code, handle, len, p);
+                                gatts_process_read_req(p_tcb, p_rcb, op_code, handle, p);
                                 break;
 
                             case GATT_REQ_WRITE: /* write char/char descriptor value */
@@ -1502,7 +1506,7 @@
                 break;
 
             case GATT_REQ_EXEC_WRITE:
-                gatt_process_exec_write_req (p_tcb, op_code, len, p_data);
+                gatt_process_exec_write_req (p_tcb, op_code, p_data);
                 break;
 
             case GATT_REQ_READ_MULTI:
diff --git a/stack/gatt/gatt_utils.c b/stack/gatt/gatt_utils.c
index e15918c..978c88c 100644
--- a/stack/gatt/gatt_utils.c
+++ b/stack/gatt/gatt_utils.c
@@ -22,6 +22,7 @@
  *
  ******************************************************************************/
 #include "bt_target.h"
+#include "bt_utils.h"
 
 #if BLE_INCLUDED == TRUE
     #include <string.h>
@@ -477,6 +478,8 @@
 *******************************************************************************/
 void gatts_update_srv_list_elem(UINT8 i_sreg, UINT16 handle, BOOLEAN is_primary)
 {
+    UNUSED(handle);
+
     gatt_cb.srv_list[i_sreg].in_use         = TRUE;
     gatt_cb.srv_list[i_sreg].i_sreg    = i_sreg;
     gatt_cb.srv_list[i_sreg].s_hdl          = gatt_cb.sr_reg[i_sreg].s_hdl;
@@ -1116,11 +1119,18 @@
 ** Returns          TRUE if command sent, otherwise FALSE.
 **
 *******************************************************************************/
-void gatt_start_rsp_timer(tGATT_TCB    *p_tcb)
+void gatt_start_rsp_timer(UINT16 clcb_idx)
 {
-    p_tcb->rsp_timer_ent.param  = (TIMER_PARAM_TYPE)p_tcb;
-    btu_start_timer (&p_tcb->rsp_timer_ent, BTU_TTYPE_ATT_WAIT_FOR_RSP,
-                     GATT_WAIT_FOR_RSP_TOUT);
+    tGATT_CLCB *p_clcb = &gatt_cb.clcb[clcb_idx];
+    UINT32 timeout = GATT_WAIT_FOR_RSP_TOUT;
+    p_clcb->rsp_timer_ent.param  = (TIMER_PARAM_TYPE)p_clcb;
+    if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY &&
+        p_clcb->op_subtype == GATT_DISC_SRVC_ALL)
+    {
+        timeout = GATT_WAIT_FOR_DISC_RSP_TOUT;
+    }
+    btu_start_timer (&p_clcb->rsp_timer_ent, BTU_TTYPE_ATT_WAIT_FOR_RSP,
+                     timeout);
 }
 /*******************************************************************************
 **
@@ -1165,8 +1175,32 @@
 *******************************************************************************/
 void gatt_rsp_timeout(TIMER_LIST_ENT *p_tle)
 {
+    tGATT_CLCB *p_clcb = (tGATT_CLCB *)p_tle->param;
+    if (p_clcb == NULL || p_clcb->p_tcb == NULL)
+    {
+        GATT_TRACE_WARNING0("gatt_rsp_timeout clcb is already deleted");
+        return;
+    }
+    if (p_clcb->operation == GATTC_OPTYPE_DISCOVERY &&
+        p_clcb->op_subtype == GATT_DISC_SRVC_ALL &&
+        p_clcb->retry_count < GATT_REQ_RETRY_LIMIT)
+    {
+        UINT8 rsp_code;
+        GATT_TRACE_WARNING0("gatt_rsp_timeout retry discovery primary service");
+        if (p_clcb != gatt_cmd_dequeue(p_clcb->p_tcb, &rsp_code))
+        {
+            GATT_TRACE_ERROR0("gatt_rsp_timeout command queue out of sync, disconnect");
+        }
+        else
+        {
+            p_clcb->retry_count++;
+            gatt_act_discovery(p_clcb);
+            return;
+        }
+    }
+
     GATT_TRACE_WARNING0("gatt_rsp_timeout disconnecting...");
-    gatt_disconnect (((tGATT_TCB *)p_tle->param)->peer_bda);
+    gatt_disconnect (p_clcb->p_tcb->peer_bda);
 }
 
 /*******************************************************************************
@@ -1299,6 +1333,7 @@
 void gatt_sr_get_sec_info(BD_ADDR rem_bda, BOOLEAN le_conn, UINT8 *p_sec_flag, UINT8 *p_key_size)
 {
     UINT8           sec_flag = 0;
+    UNUSED(le_conn);
 
     BTM_GetSecurityFlags(rem_bda, &sec_flag);
 
@@ -2073,6 +2108,7 @@
 
     operation =  p_clcb->operation;
     conn_id = p_clcb->conn_id;
+    btu_stop_timer(&p_clcb->rsp_timer_ent);
 
     gatt_clcb_dealloc(p_clcb);
 
@@ -2114,6 +2150,7 @@
             p_clcb = &gatt_cb.clcb[i];
             if (p_clcb->in_use && p_clcb->p_tcb == p_tcb)
             {
+                btu_stop_timer(&p_clcb->rsp_timer_ent);
                 GATT_TRACE_DEBUG2 ("found p_clcb conn_id=%d clcb_idx=%d", p_clcb->conn_id, p_clcb->clcb_idx);
                 if (p_clcb->operation != GATTC_OPTYPE_NONE)
                     gatt_end_operation(p_clcb, GATT_ERROR, NULL);
@@ -2123,7 +2160,6 @@
             }
         }
 
-        btu_stop_timer (&p_tcb->rsp_timer_ent);
         btu_stop_timer (&p_tcb->ind_ack_timer_ent);
         btu_stop_timer (&p_tcb->conf_timer_ent);
         gatt_free_pending_ind(p_tcb);
diff --git a/stack/hcic/hcicmds.c b/stack/hcic/hcicmds.c
index 21222bd..778ebfb 100644
--- a/stack/hcic/hcicmds.c
+++ b/stack/hcic/hcicmds.c
@@ -783,6 +783,13 @@
     BT_HDR *p;
     UINT8 *pp;
 
+    #ifdef BDCFG_OVERRIDE_SNIFF_MODE_MAX
+    max_sniff_period = BDCFG_OVERRIDE_SNIFF_MODE_MAX;
+    min_sniff_period = BDCFG_OVERRIDE_SNIFF_MODE_MIN;
+    sniff_attempt = BDCFG_OVERRIDE_SNIFF_MODE_ATTEMPT;
+    sniff_timeout = BDCFG_OVERRIDE_SNIFF_MODE_TIMEOUT;
+    #endif
+
     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_SNIFF_MODE)) == NULL)
         return (FALSE);
 
diff --git a/stack/hid/hidh_conn.c b/stack/hid/hidh_conn.c
index d9345a0..86b41d3 100644
--- a/stack/hid/hidh_conn.c
+++ b/stack/hid/hidh_conn.c
@@ -41,6 +41,7 @@
 
 #include "hidh_api.h"
 #include "hidh_int.h"
+#include "bt_utils.h"
 
 static UINT8 find_conn_by_cid (UINT16 cid);
 static void hidh_conn_retry (UINT8 dhandle);
@@ -163,6 +164,7 @@
 void hidh_sec_check_complete_term (BD_ADDR bd_addr, void *p_ref_data, UINT8 res)
 {
     tHID_HOST_DEV_CTB *p_dev= (tHID_HOST_DEV_CTB *) p_ref_data;
+    UNUSED(bd_addr);
 
     if( res == BTM_SUCCESS && p_dev->conn.conn_state == HID_CONN_STATE_SECURITY )
     {
@@ -320,6 +322,7 @@
     UINT32 cb_res = HID_ERR_AUTH_FAILED;
 #endif
     UINT32 reason;
+    UNUSED(bd_addr);
 
     dhandle = ((UINT32)p_dev - (UINT32)&(hh_cb.devices[0]))/ sizeof(tHID_HOST_DEV_CTB);
     if( res == BTM_SUCCESS && p_dev->conn.conn_state == HID_CONN_STATE_SECURITY )
@@ -654,6 +657,7 @@
 {
     UINT8 dhandle;
     tHID_CONN    *p_hcon = NULL;
+    UNUSED(result);
 
     /* Find CCB based on CID */
     if( (dhandle = find_conn_by_cid(l2cap_cid)) < HID_HOST_MAX_DEVICES )
diff --git a/stack/include/avrc_defs.h b/stack/include/avrc_defs.h
index 16ba057..d6ff8a0 100644
--- a/stack/include/avrc_defs.h
+++ b/stack/include/avrc_defs.h
@@ -842,9 +842,7 @@
                                               (a <= AVRC_EVT_APP_SETTING_CHANGE)) ? TRUE : FALSE)
 
 #define AVRC_IS_VALID_ATTRIBUTE(a)          (((((a > 0) && a <= AVRC_PLAYER_SETTING_SCAN)) || \
-                                               ((a >= AVRC_PLAYER_SETTING_LOW_MENU_EXT) && \
-                                                (a <= AVRC_PLAYER_SETTING_HIGH_MENU_EXT))) ? TRUE : FALSE)
-
+					      (a >= AVRC_PLAYER_SETTING_LOW_MENU_EXT)) ? TRUE : FALSE)
 
 #define AVRC_IS_VALID_MEDIA_ATTRIBUTE(a)    ((a >= AVRC_MEDIA_ATTR_ID_TITLE) && \
                                              (a <= AVRC_MEDIA_ATTR_ID_PLAYING_TIME) ? TRUE : FALSE)
diff --git a/stack/include/btm_ble_api.h b/stack/include/btm_ble_api.h
index 0dcc8d2..584ce9a 100644
--- a/stack/include/btm_ble_api.h
+++ b/stack/include/btm_ble_api.h
@@ -276,8 +276,8 @@
     tBTM_BLE_MANU           manu;			/* manufactuer data */
     tBTM_BLE_INT_RANGE      int_range;      /* slave prefered conn interval range */
     tBTM_BLE_SERVICE        services;       /* services */
-    UINT8                   flag;
     UINT16                  appearance;
+    UINT8                   flag;
     tBTM_BLE_PROPRIETARY    *p_proprietary;
 }tBTM_BLE_ADV_DATA;
 
diff --git a/stack/include/gap_api.h b/stack/include/gap_api.h
index 05affed..a17510f 100644
--- a/stack/include/gap_api.h
+++ b/stack/include/gap_api.h
@@ -146,11 +146,6 @@
 #define  GAP_PREFER_CONN_SP_TOUT         2000
 #endif
 
-#if BLE_INCLUDED == TRUE
-#ifndef GAP_TRANSPORT_SUPPORTED
-#define GAP_TRANSPORT_SUPPORTED GATT_TRANSPORT_LE_BR_EDR
-#endif
-#endif
 /*****************************************************************************
 **  Type Definitions
 *****************************************************************************/
diff --git a/stack/include/gatt_api.h b/stack/include/gatt_api.h
index d9704b7..f3df8b7 100644
--- a/stack/include/gatt_api.h
+++ b/stack/include/gatt_api.h
@@ -137,10 +137,6 @@
     #define GATT_MAX_SCCB       10
 #endif
 
-#ifndef GATTP_TRANSPORT_SUPPORTED
-#define GATTP_TRANSPORT_SUPPORTED        GATT_TRANSPORT_LE_BR_EDR
-#endif
-
 
 /* GATT notification caching timer, default to be three seconds
 */
diff --git a/stack/l2cap/l2c_ble.c b/stack/l2cap/l2c_ble.c
index a440492..ba0d7ec 100644
--- a/stack/l2cap/l2c_ble.c
+++ b/stack/l2cap/l2c_ble.c
@@ -24,6 +24,7 @@
 
 #include <string.h>
 #include "bt_target.h"
+#include "bt_utils.h"
 #include "l2cdefs.h"
 #include "l2c_int.h"
 #include "btu.h"
@@ -426,6 +427,10 @@
 {
     tL2C_LCB            *p_lcb;
     tBTM_SEC_DEV_REC    *p_dev_rec;
+    UNUSED(type);
+    UNUSED(conn_interval);
+    UNUSED(conn_latency);
+    UNUSED(conn_timeout);
 
     /* See if we have a link control block for the remote device */
     p_lcb = l2cu_find_lcb_by_bd_addr (bda);
@@ -611,6 +616,14 @@
     init_addr_type = p_lcb->ble_addr_type;
     memcpy(init_addr, p_lcb->remote_bd_addr, BD_ADDR_LEN);
 
+#if BTM_BLE_PRIVACY_SPT == TRUE
+    if (p_dev_rec->ble.active_addr_type == BTM_BLE_ADDR_RRA)
+    {
+        init_addr_type = BLE_ADDR_RANDOM;
+        memcpy(init_addr, p_dev_rec->ble.cur_rand_addr, BD_ADDR_LEN);
+    }
+#endif
+
     if (!btsnd_hcic_ble_create_ll_conn (scan_int,/* UINT16 scan_int      */
                                         scan_win, /* UINT16 scan_win      */
                                         FALSE,                   /* UINT8 white_list     */
diff --git a/stack/l2cap/l2c_csm.c b/stack/l2cap/l2c_csm.c
index 0d04d8a..4e24c23 100644
--- a/stack/l2cap/l2c_csm.c
+++ b/stack/l2cap/l2c_csm.c
@@ -892,14 +892,17 @@
     case L2CEVT_L2CAP_DATA:                        /* Peer data packet rcvd    */
         L2CAP_TRACE_API1 ("L2CAP - Calling DataInd_Cb(), CID: 0x%04x", p_ccb->local_cid);
 #if (L2CAP_NUM_FIXED_CHNLS > 0)
-        if (p_ccb->local_cid < L2CAP_BASE_APPL_CID)
+        if (p_ccb->local_cid >= L2CAP_FIRST_FIXED_CHNL &&
+                p_ccb->local_cid <= L2CAP_LAST_FIXED_CHNL)
         {
-            if (l2cb.fixed_reg[p_ccb->local_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb)
-                (*l2cb.fixed_reg[p_ccb->local_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb)(p_ccb->p_lcb->remote_bd_addr,(BT_HDR *)p_data);
-            else
-                GKI_freebuf (p_data);
-
+            if (p_ccb->local_cid < L2CAP_BASE_APPL_CID)
+            {
+                if (l2cb.fixed_reg[p_ccb->local_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb)
+                    (*l2cb.fixed_reg[p_ccb->local_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb)(p_ccb->p_lcb->remote_bd_addr,(BT_HDR *)p_data);
+                else
+                    GKI_freebuf (p_data);
             break;
+            }
         }
 #endif
         (*p_ccb->p_rcb->api.pL2CA_DataInd_Cb)(p_ccb->local_cid, (BT_HDR *)p_data);
diff --git a/stack/l2cap/l2c_link.c b/stack/l2cap/l2c_link.c
index ca563d9..fd38ca2 100644
--- a/stack/l2cap/l2c_link.c
+++ b/stack/l2cap/l2c_link.c
@@ -30,6 +30,7 @@
 
 #include "gki.h"
 #include "bt_types.h"
+#include "bt_utils.h"
 #include "hcimsgs.h"
 #include "l2cdefs.h"
 #include "l2c_int.h"
@@ -949,7 +950,9 @@
             num_found++;
         }
     }
-
+#else
+    UNUSED(num_pkts);
+    UNUSED(handles);
 #endif
 
     return (num_found);
diff --git a/stack/l2cap/l2c_utils.c b/stack/l2cap/l2c_utils.c
index 1add2b6..05d5e5d 100644
--- a/stack/l2cap/l2c_utils.c
+++ b/stack/l2cap/l2c_utils.c
@@ -36,6 +36,7 @@
 #include "btm_api.h"
 #include "btm_int.h"
 #include "hcidefs.h"
+#include "bd.h"
 
 /*******************************************************************************
 **
diff --git a/stack/mcap/mca_cact.c b/stack/mcap/mca_cact.c
index 85f19f4..16a8cec 100644
--- a/stack/mcap/mca_cact.c
+++ b/stack/mcap/mca_cact.c
@@ -24,6 +24,7 @@
  ******************************************************************************/
 #include <string.h>
 #include "bt_target.h"
+#include "bt_utils.h"
 #include "gki.h"
 #include "btm_api.h"
 #include "mca_api.h"
@@ -47,6 +48,8 @@
 void mca_ccb_rsp_tout(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data)
 {
    tMCA_CTRL   evt_data;
+   UNUSED(p_data);
+
    mca_ccb_report_event(p_ccb, MCA_RSP_TOUT_IND_EVT, &evt_data);
 }
 
@@ -76,6 +79,8 @@
 *******************************************************************************/
 void mca_ccb_free_msg(tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data)
 {
+    UNUSED(p_ccb);
+
     GKI_freebuf (p_data);
 }
 
@@ -210,6 +215,8 @@
 *******************************************************************************/
 void mca_ccb_do_disconn (tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data)
 {
+    UNUSED(p_data);
+
     mca_dcb_close_by_mdl_id (p_ccb, MCA_ALL_MDL_ID);
     L2CA_DisconnectReq(p_ccb->lcid);
 }
@@ -573,6 +580,8 @@
 *******************************************************************************/
 void mca_ccb_dl_open (tMCA_CCB *p_ccb, tMCA_CCB_EVT *p_data)
 {
+    UNUSED(p_data);
+
     mca_free_buf ((void **)&p_ccb->p_tx_req);
     mca_free_buf ((void **)&p_ccb->p_rx_msg);
     p_ccb->status = MCA_CCB_STAT_NORM;
diff --git a/stack/mcap/mca_dact.c b/stack/mcap/mca_dact.c
index 353153e..d147c39 100644
--- a/stack/mcap/mca_dact.c
+++ b/stack/mcap/mca_dact.c
@@ -23,6 +23,7 @@
  *
  ******************************************************************************/
 #include "bt_target.h"
+#include "bt_utils.h"
 #include "gki.h"
 #include "mca_api.h"
 #include "mca_int.h"
@@ -99,6 +100,8 @@
 *******************************************************************************/
 void mca_dcb_free_data (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data)
 {
+    UNUSED(p_dcb);
+
     GKI_freebuf (p_data);
 }
 
@@ -114,6 +117,8 @@
 void mca_dcb_do_disconn (tMCA_DCB *p_dcb, tMCA_DCB_EVT *p_data)
 {
     tMCA_CLOSE  close;
+    UNUSED(p_data);
+
     if ((p_dcb->lcid == 0) || (L2CA_DisconnectReq(p_dcb->lcid) == FALSE))
     {
         close.param  = MCA_INT;
diff --git a/stack/mcap/mca_l2c.c b/stack/mcap/mca_l2c.c
index 23d56f5..bc6fe09 100644
--- a/stack/mcap/mca_l2c.c
+++ b/stack/mcap/mca_l2c.c
@@ -24,6 +24,7 @@
 #include <string.h>
 
 #include "bt_target.h"
+#include "bt_utils.h"
 #include "btm_api.h"
 #include "btm_int.h"
 #include "mca_api.h"
@@ -118,6 +119,7 @@
 {
     tMCA_TC_TBL     *p_tbl = (tMCA_TC_TBL *)p_ref_data;
     tL2CAP_CFG_INFO cfg;
+    UNUSED(bd_addr);
 
     MCA_TRACE_DEBUG1("mca_sec_check_complete_orig res: %d", res);
 
diff --git a/stack/pan/pan_api.c b/stack/pan/pan_api.c
index 6aa24b9..d08e527 100644
--- a/stack/pan/pan_api.c
+++ b/stack/pan/pan_api.c
@@ -34,6 +34,7 @@
 #include "l2c_api.h"
 #include "hcidefs.h"
 #include "btm_api.h"
+#include "bta_sys.h"
 
 
 /*******************************************************************************
@@ -465,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)
@@ -491,9 +492,7 @@
 ** Description      This sends data over the PAN connections. If this is called
 **                  on GN or NAP side and the packet is multicast or broadcast
 **                  it will be sent on all the links. Otherwise the correct link
-**                  is found based on the destination address and forwarded on it
-**                  If the return value is not PAN_SUCCESS the application should
-**                  take care of releasing the message buffer
+**                  is found based on the destination address and forwarded on it.
 **
 ** Parameters:      handle   - handle for the connection
 **                  dst      - MAC or BD Addr of the destination device
@@ -508,89 +507,39 @@
 **                                           there is an error in sending data
 **
 *******************************************************************************/
-tPAN_RESULT PAN_Write (UINT16 handle, BD_ADDR dst, BD_ADDR src, UINT16 protocol, UINT8 *p_data, UINT16 len, BOOLEAN ext)
+tPAN_RESULT PAN_Write(UINT16 handle, BD_ADDR dst, BD_ADDR src, UINT16 protocol, UINT8 *p_data, UINT16 len, BOOLEAN ext)
 {
-    tPAN_CONN       *pcb;
-    UINT16          i;
-    tBNEP_RESULT    result;
+    BT_HDR *buffer;
 
-    if (pan_cb.role == PAN_ROLE_INACTIVE || (!(pan_cb.num_conns)))
-    {
-        PAN_TRACE_ERROR0 ("PAN is not active Data write failed");
+    if (pan_cb.role == PAN_ROLE_INACTIVE || !pan_cb.num_conns) {
+        PAN_TRACE_ERROR1("%s PAN is not active, data write failed.", __func__);
         return PAN_FAILURE;
     }
 
-    /* Check if it is broadcast or multicast packet */
-    if (dst[0] & 0x01)
-    {
-        for (i=0; i<MAX_PAN_CONNS; i++)
-        {
+    // If the packet is broadcast or multicast, we're going to have to create
+    // a copy of the packet for each connection. We can save one extra copy
+    // by fast-pathing here and calling BNEP_Write instead of placing the packet
+    // in a BT_HDR buffer, calling BNEP_Write, and then freeing the buffer.
+    if (dst[0] & 0x01) {
+        int i;
+        for (i = 0; i < MAX_PAN_CONNS; ++i) {
             if (pan_cb.pcb[i].con_state == PAN_STATE_CONNECTED)
                 BNEP_Write (pan_cb.pcb[i].handle, dst, p_data, len, protocol, src, ext);
         }
-
         return PAN_SUCCESS;
     }
 
-    if (pan_cb.active_role == PAN_ROLE_CLIENT)
-    {
-        /* Data write is on PANU connection */
-        for (i=0; i<MAX_PAN_CONNS; i++)
-        {
-            if (pan_cb.pcb[i].con_state == PAN_STATE_CONNECTED &&
-                pan_cb.pcb[i].src_uuid == UUID_SERVCLASS_PANU)
-                break;
-        }
-
-        if (i == MAX_PAN_CONNS)
-        {
-            PAN_TRACE_ERROR0 ("PAN Don't have any user connections");
-            return PAN_FAILURE;
-        }
-
-        result = BNEP_Write (pan_cb.pcb[i].handle, dst, p_data, len, protocol, src, ext);
-        if (result == BNEP_IGNORE_CMD)
-        {
-            PAN_TRACE_DEBUG0 ("PAN ignored data for PANU connection");
-            return result;
-        }
-        else if (result != BNEP_SUCCESS)
-        {
-            PAN_TRACE_ERROR0 ("PAN failed to write data for the PANU connection");
-            return result;
-        }
-
-        PAN_TRACE_DEBUG0 ("PAN successfully wrote data for the PANU connection");
-        return PAN_SUCCESS;
+    buffer = (BT_HDR *)GKI_getpoolbuf(PAN_POOL_ID);
+    if (!buffer) {
+        PAN_TRACE_ERROR1("%s unable to acquire buffer from pool.", __func__);
+        return PAN_NO_RESOURCES;
     }
 
-    pcb = pan_get_pcb_by_handle (handle);
-    if (!pcb)
-    {
-        PAN_TRACE_ERROR0 ("PAN Data write for wrong addr");
-        return PAN_FAILURE;
-    }
+    buffer->len = len;
+    buffer->offset = PAN_MINIMUM_OFFSET;
+    memcpy((UINT8 *)buffer + sizeof(BT_HDR) + buffer->offset, p_data, buffer->len);
 
-    if (pcb->con_state != PAN_STATE_CONNECTED)
-    {
-        PAN_TRACE_ERROR0 ("PAN Data write when conn is not active");
-        return PAN_FAILURE;
-    }
-
-    result = BNEP_Write (pcb->handle, dst, p_data, len, protocol, src, ext);
-    if (result == BNEP_IGNORE_CMD)
-    {
-        PAN_TRACE_DEBUG0 ("PAN ignored data write to PANU");
-        return result;
-    }
-    else if (result != BNEP_SUCCESS)
-    {
-        PAN_TRACE_ERROR0 ("PAN failed to send data to the PANU");
-        return result;
-    }
-
-    PAN_TRACE_DEBUG0 ("PAN successfully sent data to the PANU");
-    return PAN_SUCCESS;
+    return PAN_WriteBuf(handle, dst, src, protocol, buffer, ext);
 }
 
 
@@ -623,19 +572,6 @@
     UINT16          i;
     tBNEP_RESULT    result;
 
-    /* Check if it is broadcast or multicast packet */
-    if (dst[0] & 0x01)
-    {
-        UINT8       *p_data;
-        UINT16      len;
-
-        p_data  = (UINT8 *)(p_buf + 1) + p_buf->offset;
-        len     = p_buf->len;
-        PAN_Write (handle, dst, src, protocol, p_data, len, ext);
-        GKI_freebuf (p_buf);
-        return PAN_SUCCESS;
-    }
-
     if (pan_cb.role == PAN_ROLE_INACTIVE || (!(pan_cb.num_conns)))
     {
         PAN_TRACE_ERROR0 ("PAN is not active Data write failed");
@@ -643,6 +579,18 @@
         return PAN_FAILURE;
     }
 
+    /* Check if it is broadcast or multicast packet */
+    if (dst[0] & 0x01)
+    {
+        UINT8 *data = (UINT8 *)p_buf + sizeof(BT_HDR) + p_buf->offset;
+        for (i = 0; i < MAX_PAN_CONNS; ++i) {
+            if (pan_cb.pcb[i].con_state == PAN_STATE_CONNECTED)
+                BNEP_Write(pan_cb.pcb[i].handle, dst, data, p_buf->len, protocol, src, ext);
+        }
+        GKI_freebuf(p_buf);
+        return PAN_SUCCESS;
+    }
+
     /* Check if the data write is on PANU side */
     if (pan_cb.active_role == PAN_ROLE_CLIENT)
     {
diff --git a/stack/pan/pan_main.c b/stack/pan/pan_main.c
index 6cbe1ce..bfaced6 100644
--- a/stack/pan/pan_main.c
+++ b/stack/pan/pan_main.c
@@ -26,6 +26,7 @@
 #include <string.h>
 #include "gki.h"
 #include "bt_types.h"
+#include "bt_utils.h"
 #include "bnep_api.h"
 #include "pan_api.h"
 #include "pan_int.h"
@@ -333,6 +334,7 @@
 {
     tPAN_CONN       *pcb;
     UINT8            peer_role;
+    UNUSED(rem_bda);
 
     PAN_TRACE_EVENT2 ("pan_connect_state_cb - for handle %d, result %d", handle, result);
     pcb = pan_get_pcb_by_handle (handle);
diff --git a/stack/rfcomm/port_rfc.c b/stack/rfcomm/port_rfc.c
index 3f697e1..003cbb5 100644
--- a/stack/rfcomm/port_rfc.c
+++ b/stack/rfcomm/port_rfc.c
@@ -32,6 +32,7 @@
 #include "btm_api.h"
 #include "port_int.h"
 #include "rfc_int.h"
+#include "bt_utils.h"
 
 /*
 ** Local function definitions
@@ -581,6 +582,7 @@
 void PORT_PortNegCnf (tRFC_MCB *p_mcb, UINT8 dlci, tPORT_STATE *p_pars, UINT16 result)
 {
     tPORT  *p_port = port_find_mcb_dlci_port (p_mcb, dlci);
+    UNUSED(p_pars);
 
     RFCOMM_TRACE_EVENT0 ("PORT_PortNegCnf");
 
@@ -682,6 +684,7 @@
 {
     tPORT *p_port = port_find_mcb_dlci_port (p_mcb, dlci);
     UINT32 event = 0;
+    UNUSED(p_pars);
 
     RFCOMM_TRACE_EVENT0 ("PORT_ControlCnf");
 
diff --git a/stack/rfcomm/rfc_l2cap_if.c b/stack/rfcomm/rfc_l2cap_if.c
index cb50612..9137a66 100644
--- a/stack/rfcomm/rfc_l2cap_if.c
+++ b/stack/rfcomm/rfc_l2cap_if.c
@@ -31,6 +31,7 @@
 #include "l2c_api.h"
 #include "l2cdefs.h"
 #include "rfc_int.h"
+#include "bt_utils.h"
 
 
 /*
@@ -87,6 +88,7 @@
 void RFCOMM_ConnectInd (BD_ADDR bd_addr, UINT16 lcid, UINT16 psm, UINT8 id)
 {
     tRFC_MCB *p_mcb = rfc_alloc_multiplexer_channel(bd_addr, FALSE);
+    UNUSED(psm);
 
     if ((p_mcb)&&(p_mcb->state != RFC_MX_STATE_IDLE))
     {
@@ -257,6 +259,7 @@
 *******************************************************************************/
 void RFCOMM_QoSViolationInd (BD_ADDR bd_addr)
 {
+    UNUSED(bd_addr);
 }
 
 
diff --git a/stack/rfcomm/rfc_mx_fsm.c b/stack/rfcomm/rfc_mx_fsm.c
index 842f8ee..6d8bb06 100644
--- a/stack/rfcomm/rfc_mx_fsm.c
+++ b/stack/rfcomm/rfc_mx_fsm.c
@@ -31,6 +31,7 @@
 #include "port_int.h"
 #include "l2c_api.h"
 #include "rfc_int.h"
+#include "bt_utils.h"
 
 #define L2CAP_SUCCESS   0
 #define L2CAP_ERROR     1
@@ -308,6 +309,8 @@
 *******************************************************************************/
 void rfc_mx_sm_sabme_wait_ua (tRFC_MCB *p_mcb, UINT16 event, void *p_data)
 {
+    UNUSED(p_data);
+
     RFCOMM_TRACE_EVENT1 ("rfc_mx_sm_sabme_wait_ua - evt:%d", event);
     switch (event)
     {
@@ -436,6 +439,8 @@
 *******************************************************************************/
 void rfc_mx_sm_state_connected (tRFC_MCB *p_mcb, UINT16 event, void *p_data)
 {
+    UNUSED(p_data);
+
     RFCOMM_TRACE_EVENT1 ("rfc_mx_sm_state_connected - evt:%d", event);
 
     switch (event)
@@ -614,7 +619,9 @@
         else
         {
             p_mcb->state = RFC_MX_STATE_WAIT_SABME;
-            rfc_timer_start (p_mcb, RFC_T2_TIMEOUT);
+            rfc_timer_start (p_mcb, RFCOMM_CONN_TIMEOUT); /* - increased from T2=20 to CONN=120
+                                                to allow the user more than 10 sec to type in the
+                                                pin which can be e.g. 16 digits */
         }
     }
 }
@@ -657,7 +664,9 @@
         else
         {
             p_mcb->state = RFC_MX_STATE_WAIT_SABME;
-            rfc_timer_start (p_mcb, RFC_T2_TIMEOUT);
+            rfc_timer_start (p_mcb, RFCOMM_CONN_TIMEOUT); /* - increased from T2=20 to CONN=120
+                                                to allow the user more than 10 sec to type in the
+                                                pin which can be e.g. 16 digits */
         }
     }
 }
diff --git a/stack/rfcomm/rfc_port_fsm.c b/stack/rfcomm/rfc_port_fsm.c
index d5335ad..e519a98 100644
--- a/stack/rfcomm/rfc_port_fsm.c
+++ b/stack/rfcomm/rfc_port_fsm.c
@@ -31,6 +31,7 @@
 #include "port_api.h"
 #include "port_int.h"
 #include "rfc_int.h"
+#include "bt_utils.h"
 
 /********************************************************************************/
 /*              L O C A L    F U N C T I O N     P R O T O T Y P E S            */
@@ -795,6 +796,8 @@
 *******************************************************************************/
 void rfc_process_nsc (tRFC_MCB *p_mcb, MX_FRAME *p_frame)
 {
+    UNUSED(p_mcb);
+    UNUSED(p_frame);
 }
 
 
@@ -808,6 +811,8 @@
 *******************************************************************************/
 void rfc_process_test_rsp (tRFC_MCB *p_mcb, BT_HDR *p_buf)
 {
+    UNUSED(p_mcb);
+
     GKI_freebuf (p_buf);
 }
 
diff --git a/stack/rfcomm/rfc_port_if.c b/stack/rfcomm/rfc_port_if.c
index 083d9ef..741df20 100644
--- a/stack/rfcomm/rfc_port_if.c
+++ b/stack/rfcomm/rfc_port_if.c
@@ -31,7 +31,7 @@
 #include "l2c_api.h"
 #include "port_int.h"
 #include "rfc_int.h"
-
+#include "bt_utils.h"
 
 #if RFC_DYNAMIC_MEMORY == FALSE
 tRFC_CB rfc_cb;
@@ -82,6 +82,7 @@
 void RFCOMM_DlcEstablishReq (tRFC_MCB *p_mcb, UINT8 dlci, UINT16 mtu)
 {
     tPORT *p_port = port_find_mcb_dlci_port (p_mcb, dlci);
+    UNUSED(mtu);
 
     if (p_mcb->state != RFC_MX_STATE_CONNECTED)
     {
@@ -104,6 +105,7 @@
 void RFCOMM_DlcEstablishRsp (tRFC_MCB *p_mcb, UINT8 dlci, UINT16 mtu, UINT16 result)
 {
     tPORT *p_port = port_find_mcb_dlci_port (p_mcb, dlci);
+    UNUSED(mtu);
 
     if ((p_mcb->state != RFC_MX_STATE_CONNECTED) && (result == RFCOMM_SUCCESS))
     {
diff --git a/stack/rfcomm/rfc_utils.c b/stack/rfcomm/rfc_utils.c
index 2b850fa..d2b02fc 100644
--- a/stack/rfcomm/rfc_utils.c
+++ b/stack/rfcomm/rfc_utils.c
@@ -33,6 +33,7 @@
 #include "port_int.h"
 #include "rfc_int.h"
 #include "btu.h"
+#include "bt_utils.h"
 
 #include <string.h>
 
@@ -352,6 +353,7 @@
 void rfc_sec_check_complete (BD_ADDR bd_addr, void *p_ref_data, UINT8 res)
 {
     tPORT *p_port = (tPORT *)p_ref_data;
+    UNUSED(bd_addr);
 
     /* Verify that PORT is still waiting for Security to complete */
     if (!p_port->in_use
diff --git a/stack/sdp/sdp_api.c b/stack/sdp/sdp_api.c
index cb632bd..af35cc8 100644
--- a/stack/sdp/sdp_api.c
+++ b/stack/sdp/sdp_api.c
@@ -27,6 +27,7 @@
 #include <stdio.h>
 
 #include "bt_target.h"
+#include "bt_utils.h"
 #include "gki.h"
 #include "l2cdefs.h"
 #include "hcidefs.h"
@@ -244,6 +245,8 @@
 #if SDP_CLIENT_ENABLED == TRUE
 void SDP_SetIdleTimeout (BD_ADDR addr, UINT16 timeout)
 {
+    UNUSED(addr);
+    UNUSED(timeout);
 }
 #endif
 
@@ -510,12 +513,12 @@
 
                     if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE)
                      && (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 2) ) {
-                        printf("SDP_FindServiceInDb - p_sattr value = 0x%x serviceuuid = 0x%x\r\n", p_sattr->attr_value.v.u16, service_uuid);
+                        SDP_TRACE_DEBUG2("SDP_FindServiceInDb - p_sattr value = 0x%x serviceuuid = 0x%x\r\n", p_sattr->attr_value.v.u16, service_uuid);
                         if(service_uuid == UUID_SERVCLASS_HDP_PROFILE)
                         {
-                            if( (p_sattr->attr_value.v.u16==UUID_SERVCLASS_HDP_SOURCE) || ( p_sattr->attr_value.v.u16==UUID_SERVCLASS_HDP_SOURCE))
+                            if( (p_sattr->attr_value.v.u16==UUID_SERVCLASS_HDP_SOURCE) || ( p_sattr->attr_value.v.u16==UUID_SERVCLASS_HDP_SINK))
                             {
-                                printf("SDP_FindServiceInDb found HDP source or sink\n" );
+                                SDP_TRACE_DEBUG0("SDP_FindServiceInDb found HDP source or sink\n" );
                                 return (p_rec);
                             }
                         }
@@ -683,14 +686,14 @@
                     if (SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UUID_DESC_TYPE)
                     {
 
-                        printf("uuid len=%d ", p_uuid->len);
+                        SDP_TRACE_DEBUG1("uuid len=%d ", p_uuid->len);
                         if (p_uuid->len == 2)
                         {
-                            printf("uuid=0x%x \n", p_uuid->uu.uuid16);
+                            SDP_TRACE_DEBUG1("uuid=0x%x \n", p_uuid->uu.uuid16);
                         }
                         else
                         {
-                            printf("\n");
+                            SDP_TRACE_DEBUG0("\n");
                         }
 
                         if (sdpu_compare_uuid_with_attr (p_uuid, p_sattr))
@@ -989,6 +992,34 @@
 
 /*******************************************************************************
 **
+** Function         SDP_AttrStringCopy
+**
+** Description      This function copy given attribute to specified buffer as a string
+**
+** Returns          none
+**
+*******************************************************************************/
+static void SDP_AttrStringCopy(char *dst, tSDP_DISC_ATTR *p_attr, UINT16 dst_size)
+{
+    if ( dst == NULL ) return;
+    if ( p_attr )
+    {
+        UINT16 len = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
+        if ( len > dst_size - 1 )
+        {
+            len = dst_size - 1;
+        }
+        memcpy(dst, (char *)p_attr->attr_value.v.array, len);
+        dst[len] = '\0';
+    }
+    else
+    {
+        dst[0] = '\0';
+    }
+}
+
+/*******************************************************************************
+**
 ** Function         SDP_GetDiRecord
 **
 ** Description      This function retrieves a remote device's DI record from
@@ -1028,27 +1059,16 @@
 
         /* ClientExecutableURL is optional */
         p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_CLIENT_EXE_URL );
-        if ( p_curr_attr )
-            BCM_STRNCPY_S( p_device_info->rec.client_executable_url, sizeof(p_device_info->rec.client_executable_url),
-                           (char *)p_curr_attr->attr_value.v.array, SDP_MAX_ATTR_LEN );
-        else
-            p_device_info->rec.client_executable_url[0] = '\0';
+        SDP_AttrStringCopy( p_device_info->rec.client_executable_url, p_curr_attr,
+                            SDP_MAX_ATTR_LEN );
 
         /* Service Description is optional */
         p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_SERVICE_DESCRIPTION );
-        if ( p_curr_attr )
-            BCM_STRNCPY_S( p_device_info->rec.service_description, sizeof(p_device_info->rec.service_description),
-                           (char *)p_curr_attr->attr_value.v.array, SDP_MAX_ATTR_LEN );
-        else
-            p_device_info->rec.service_description[0] = '\0';
+        SDP_AttrStringCopy( p_device_info->rec.service_description, p_curr_attr, SDP_MAX_ATTR_LEN );
 
         /* DocumentationURL is optional */
         p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_DOCUMENTATION_URL );
-        if ( p_curr_attr )
-            BCM_STRNCPY_S( p_device_info->rec.documentation_url, sizeof(p_device_info->rec.documentation_url),
-                           (char *)p_curr_attr->attr_value.v.array, SDP_MAX_ATTR_LEN );
-        else
-            p_device_info->rec.documentation_url[0] = '\0';
+        SDP_AttrStringCopy( p_device_info->rec.documentation_url, p_curr_attr, SDP_MAX_ATTR_LEN );
 
         p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_SPECIFICATION_ID );
         if ( p_curr_attr )
diff --git a/stack/sdp/sdp_discovery.c b/stack/sdp/sdp_discovery.c
index 1ad1336..4f1db1b 100644
--- a/stack/sdp/sdp_discovery.c
+++ b/stack/sdp/sdp_discovery.c
@@ -45,9 +45,9 @@
 /*              L O C A L    F U N C T I O N     P R O T O T Y P E S            */
 /********************************************************************************/
 #if SDP_CLIENT_ENABLED == TRUE
-static void          process_service_search_rsp (tCONN_CB *p_ccb, UINT8 *p_reply, UINT16 len);
-static void          process_service_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply, UINT16 len);
-static void          process_service_search_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply, UINT16 len);
+static void          process_service_search_rsp (tCONN_CB *p_ccb, UINT8 *p_reply);
+static void          process_service_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply);
+static void          process_service_search_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply);
 static UINT8         *save_attr_seq (tCONN_CB *p_ccb, UINT8 *p, UINT8 *p_msg_end);
 static tSDP_DISC_REC *add_record (tSDP_DISCOVERY_DB *p_db, BD_ADDR p_bda);
 static UINT8         *add_attr (UINT8 *p, tSDP_DISCOVERY_DB *p_db, tSDP_DISC_REC *p_rec,
@@ -215,7 +215,7 @@
     {
         p_ccb->disc_state = SDP_DISC_WAIT_SEARCH_ATTR;
 
-        process_service_search_attr_rsp (p_ccb, NULL, 0);
+        process_service_search_attr_rsp (p_ccb, NULL);
     }
     else
     {
@@ -278,7 +278,7 @@
     case SDP_PDU_SERVICE_SEARCH_RSP:
         if (p_ccb->disc_state == SDP_DISC_WAIT_HANDLES)
         {
-            process_service_search_rsp (p_ccb, p, p_msg->len);
+            process_service_search_rsp (p_ccb, p);
             invalid_pdu = FALSE;
         }
         break;
@@ -286,7 +286,7 @@
     case SDP_PDU_SERVICE_ATTR_RSP:
         if (p_ccb->disc_state == SDP_DISC_WAIT_ATTR)
         {
-            process_service_attr_rsp (p_ccb, p, p_msg->len);
+            process_service_attr_rsp (p_ccb, p);
             invalid_pdu = FALSE;
         }
         break;
@@ -294,7 +294,7 @@
     case SDP_PDU_SERVICE_SEARCH_ATTR_RSP:
         if (p_ccb->disc_state == SDP_DISC_WAIT_SEARCH_ATTR)
         {
-            process_service_search_attr_rsp (p_ccb, p, p_msg->len);
+            process_service_search_attr_rsp (p_ccb, p);
             invalid_pdu = FALSE;
         }
         break;
@@ -317,7 +317,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void process_service_search_rsp (tCONN_CB *p_ccb, UINT8 *p_reply, UINT16 len)
+static void process_service_search_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
 {
     UINT16      xx;
     UINT16      total, cur_handles, orig;
@@ -363,7 +363,7 @@
         p_ccb->disc_state = SDP_DISC_WAIT_ATTR;
 
         /* Kick off the first attribute request */
-        process_service_attr_rsp (p_ccb, NULL, 0);
+        process_service_attr_rsp (p_ccb, NULL);
     }
 }
 
@@ -378,7 +378,7 @@
 **
 *******************************************************************************/
 #if (SDP_RAW_DATA_INCLUDED == TRUE)
-static void sdp_copy_raw_data (tCONN_CB *p_ccb, UINT16 len, BOOLEAN offset)
+static void sdp_copy_raw_data (tCONN_CB *p_ccb, BOOLEAN offset)
 {
     unsigned int    cpy_len;
     UINT32          list_len;
@@ -433,15 +433,15 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void process_service_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply, UINT16 len)
+static void process_service_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
 {
     UINT8           *p_start, *p_param_len;
     UINT16          param_len, list_byte_count;
     BOOLEAN         cont_request_needed = FALSE;
 
 #if (SDP_DEBUG_RAW == TRUE)
-    SDP_TRACE_WARNING2("process_service_attr_rsp len:%d raw inc:%d",
-        len, SDP_RAW_DATA_INCLUDED);
+    SDP_TRACE_WARNING2("process_service_attr_rsp raw inc:%d",
+        SDP_RAW_DATA_INCLUDED);
 #endif
     /* If p_reply is NULL, we were called after the records handles were read */
     if (p_reply)
@@ -502,7 +502,7 @@
 
 #if (SDP_RAW_DATA_INCLUDED == TRUE)
             SDP_TRACE_WARNING0("process_service_attr_rsp");
-            sdp_copy_raw_data (p_ccb, len, FALSE);
+            sdp_copy_raw_data (p_ccb, FALSE);
 #endif
 
             /* Save the response in the database. Stop on any error */
@@ -591,7 +591,7 @@
 ** Returns          void
 **
 *******************************************************************************/
-static void process_service_search_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply, UINT16 len)
+static void process_service_search_attr_rsp (tCONN_CB *p_ccb, UINT8 *p_reply)
 {
     UINT8           *p, *p_start, *p_end, *p_param_len;
     UINT8           type;
@@ -600,7 +600,7 @@
     BOOLEAN         cont_request_needed = FALSE;
 
 #if (SDP_DEBUG_RAW == TRUE)
-    SDP_TRACE_WARNING1("process_service_search_attr_rsp len:%d", len);
+    SDP_TRACE_WARNING1("process_service_search_attr_rsp");
 #endif
     /* If p_reply is NULL, we were called for the initial read */
     if (p_reply)
@@ -734,7 +734,7 @@
 
 #if (SDP_RAW_DATA_INCLUDED == TRUE)
     SDP_TRACE_WARNING0("process_service_search_attr_rsp");
-    sdp_copy_raw_data (p_ccb, len, TRUE);
+    sdp_copy_raw_data (p_ccb, TRUE);
 #endif
 
     p = &p_ccb->rsp_list[0];
diff --git a/stack/sdp/sdp_main.c b/stack/sdp/sdp_main.c
index 14cd39b..d43c634 100644
--- a/stack/sdp/sdp_main.c
+++ b/stack/sdp/sdp_main.c
@@ -27,6 +27,7 @@
 #include <stdio.h>
 
 #include "bt_target.h"
+#include "bt_utils.h"
 #include "gki.h"
 #include "l2cdefs.h"
 #include "hcidefs.h"
@@ -170,6 +171,7 @@
 *******************************************************************************/
 static void sdp_connect_ind (BD_ADDR  bd_addr, UINT16 l2cap_cid, UINT16 psm, UINT8 l2cap_id)
 {
+    UNUSED(psm);
 #if SDP_SERVER_ENABLED == TRUE
     tCONN_CB    *p_ccb;
 
@@ -671,6 +673,7 @@
 static void sdp_disconnect_cfm (UINT16 l2cap_cid, UINT16 result)
 {
     tCONN_CB    *p_ccb;
+    UNUSED(result);
 
     /* Find CCB based on CID */
     if ((p_ccb = sdpu_find_ccb_by_cid (l2cap_cid)) == NULL)
diff --git a/stack/sdp/sdp_server.c b/stack/sdp/sdp_server.c
index 342d93e..5d11cb4 100644
--- a/stack/sdp/sdp_server.c
+++ b/stack/sdp/sdp_server.c
@@ -29,6 +29,7 @@
 
 #include "gki.h"
 #include "bt_types.h"
+#include "bt_utils.h"
 #include "btu.h"
 
 #include "l2cdefs.h"
@@ -177,6 +178,7 @@
     tSDP_RECORD    *p_rec = NULL;
     BT_HDR         *p_buf;
     BOOLEAN         is_cont = FALSE;
+    UNUSED(p_req_end);
 
     p_req = sdpu_extract_uid_seq (p_req, param_len, &uid_seq);
 
@@ -565,6 +567,7 @@
     BOOLEAN         maxxed_out = FALSE, is_cont = FALSE;
     UINT8           *p_seq_start;
     UINT16          seq_len, attr_len;
+    UNUSED(p_req_end);
 
     /* Extract the UUID sequence to search for */
     p_req = sdpu_extract_uid_seq (p_req, param_len, &uid_seq);
diff --git a/stack/smp/aes.c b/stack/smp/aes.c
index 1028d5b..65cddf5 100644
--- a/stack/smp/aes.c
+++ b/stack/smp/aes.c
@@ -510,7 +510,6 @@
         keylen = 24;
         break;
     case 32:
-    case 256:
         keylen = 32;
         break;
     default:
diff --git a/stack/smp/smp_act.c b/stack/smp/smp_act.c
index babd300..47cd2c9 100644
--- a/stack/smp/smp_act.c
+++ b/stack/smp/smp_act.c
@@ -17,6 +17,7 @@
  ******************************************************************************/
 
 #include "bt_target.h"
+#include "bt_utils.h"
 
 #if SMP_INCLUDED == TRUE
 
@@ -83,6 +84,8 @@
 {
     tSMP_EVT_DATA   cb_data;
     tSMP_STATUS callback_rc;
+    UNUSED(p_data);
+
     SMP_TRACE_DEBUG1 ("smp_send_app_cback p_cb->cb_evt=%d", p_cb->cb_evt );
     if (p_cb->p_callback && p_cb->cb_evt != 0)
     {
@@ -105,6 +108,12 @@
         {
             p_cb->loc_auth_req   = cb_data.io_req.auth_req;
             p_cb->loc_io_caps    = cb_data.io_req.io_cap;
+#if (defined(BLE_PERIPHERAL_DISPLAYONLY) && (BLE_PERIPHERAL_DISPLAYONLY == TRUE))
+            if (p_cb->role == HCI_ROLE_SLAVE)
+            {
+                p_cb->loc_io_caps    = SMP_IO_CAP_OUT;
+            }
+#endif
             p_cb->loc_oob_flag   = cb_data.io_req.oob_data;
             p_cb->loc_enc_size   = cb_data.io_req.max_key_size;
             p_cb->loc_i_key      = cb_data.io_req.init_keys;
@@ -147,6 +156,8 @@
 void smp_send_pair_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 {
     tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (p_cb->pairing_bda);
+    UNUSED(p_data);
+
     SMP_TRACE_DEBUG0 ("smp_send_pair_req  ");
 
 #if BLE_INCLUDED == TRUE
@@ -170,6 +181,8 @@
 *******************************************************************************/
 void smp_send_pair_rsp(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 {
+    UNUSED(p_data);
+
     SMP_TRACE_DEBUG0 ("smp_send_pair_rsp  ");
 
     p_cb->loc_i_key &= p_cb->peer_i_key;
@@ -187,6 +200,8 @@
 *******************************************************************************/
 void smp_send_confirm(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 {
+    UNUSED(p_data);
+
     SMP_TRACE_DEBUG0 ("smp_send_confirm  ");
     smp_send_cmd(SMP_OPCODE_CONFIRM, p_cb);
 }
@@ -196,6 +211,8 @@
 *******************************************************************************/
 void smp_send_init(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 {
+    UNUSED(p_data);
+
     SMP_TRACE_DEBUG0 ("smp_send_init  ");
 
 #if SMP_CONFORMANCE_TESTING == TRUE
@@ -215,6 +232,7 @@
 void smp_send_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 {
     tBTM_LE_LENC_KEYS   le_key;
+    UNUSED(p_data);
 
     SMP_TRACE_DEBUG1 ("smp_send_enc_info  p_cb->loc_enc_size = %d", p_cb->loc_enc_size);
     smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ENC, FALSE);
@@ -238,6 +256,8 @@
 *******************************************************************************/
 void smp_send_id_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 {
+    UNUSED(p_data);
+
     SMP_TRACE_DEBUG0 ("smp_send_id_info  ");
     smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ID, FALSE);
 
@@ -255,6 +275,8 @@
 void smp_send_csrk_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 {
     tBTM_LE_KEY_VALUE   key;
+    UNUSED(p_data);
+
     SMP_TRACE_DEBUG0 ("smp_send_csrk_info ");
     smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_CSRK, FALSE);
 
@@ -614,6 +636,8 @@
 *******************************************************************************/
 void smp_proc_discard(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 {
+    UNUSED(p_data);
+
     SMP_TRACE_DEBUG0 ("smp_proc_discard ");
     smp_reset_control_value(p_cb);
 }
@@ -623,6 +647,8 @@
 *******************************************************************************/
 void smp_proc_release_delay(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 {
+    UNUSED(p_data);
+
     SMP_TRACE_DEBUG0 ("smp_proc_release_delay ");
     btu_stop_timer (&p_cb->rsp_timer_ent);
     btu_start_timer (&p_cb->rsp_timer_ent, BTU_TTYPE_SMP_PAIRING_CMD,
@@ -635,6 +661,8 @@
 *******************************************************************************/
 void smp_proc_release_delay_tout(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 {
+    UNUSED(p_data);
+
     SMP_TRACE_DEBUG0 ("smp_proc_release_delay_tout ");
     btu_stop_timer (&p_cb->rsp_timer_ent);
     smp_proc_pairing_cmpl(p_cb);
@@ -750,6 +778,7 @@
     UINT8 int_evt = 0;
     tSMP_KEY key;
     tSMP_INT_DATA   *p = NULL;
+    UNUSED(p_data);
 
     SMP_TRACE_DEBUG3 ("smp_decide_asso_model p_cb->peer_io_caps = %d p_cb->loc_io_caps = %d \
                        p_cb->peer_auth_req = %02x",
@@ -847,6 +876,8 @@
 *******************************************************************************/
 void smp_proc_io_rsp(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 {
+    UNUSED(p_data);
+
     SMP_TRACE_DEBUG0 ("smp_proc_io_rsp ");
     if (p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD)
     {
@@ -887,9 +918,11 @@
 *******************************************************************************/
 void smp_pair_terminate(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 {
+    UNUSED(p_data);
+
     SMP_TRACE_DEBUG0 ("smp_pair_terminate ");
 
-        p_cb->status = SMP_CONN_TOUT;
+    p_cb->status = SMP_CONN_TOUT;
 
     smp_proc_pairing_cmpl(p_cb);
 }
@@ -914,11 +947,12 @@
 }
 /*******************************************************************************
 ** Function         smp_idle_terminate
-** Description      This function calledin idle state to determine to send authentication
+** Description      This function called in idle state to determine to send authentication
 **                  complete or not.
 *******************************************************************************/
 void smp_idle_terminate(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 {
+    UNUSED(p_data);
     if (p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD)
     {
         SMP_TRACE_DEBUG0("Pairing terminated at IDLE state.");
diff --git a/stack/smp/smp_api.c b/stack/smp/smp_api.c
index cfde2d4..64644da 100644
--- a/stack/smp/smp_api.c
+++ b/stack/smp/smp_api.c
@@ -25,6 +25,7 @@
 #include <string.h>
 
 #include "bt_target.h"
+#include "bt_utils.h"
 #if SMP_INCLUDED == TRUE
     #include "smp_int.h"
     #include "smp_api.h"
@@ -204,6 +205,9 @@
         memcmp (smp_cb.pairing_bda, bd_addr, BD_ADDR_LEN))
         return;
 
+    /* clear the SMP_SEC_REQUEST_EVT event after get grant */
+    /* avoid generate duplicate pair request */
+    smp_cb.cb_evt = 0;
     smp_sm_event(&smp_cb, SMP_API_SEC_GRANT_EVT, &res);
 }
 
@@ -281,6 +285,7 @@
     tSMP_CB *p_cb = & smp_cb;
     UINT8   failure = SMP_OOB_FAIL;
     tSMP_KEY        key;
+    UNUSED(bd_addr);
 
     SMP_TRACE_EVENT2 ("SMP_OobDataReply State: %d  res:%d",
                       smp_cb.state, res);
diff --git a/stack/smp/smp_keys.c b/stack/smp/smp_keys.c
index a1955f2..49612a5 100644
--- a/stack/smp/smp_keys.c
+++ b/stack/smp/smp_keys.c
@@ -24,6 +24,7 @@
  ******************************************************************************/
 
 #include "bt_target.h"
+#include "bt_utils.h"
 
 #if SMP_INCLUDED == TRUE
     #if SMP_DEBUG == TRUE
@@ -161,6 +162,8 @@
 *******************************************************************************/
 void smp_generate_passkey(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 {
+    UNUSED(p_data);
+
     SMP_TRACE_DEBUG0 ("smp_generate_passkey");
     p_cb->rand_enc_proc = SMP_GEN_TK;
 
@@ -226,6 +229,7 @@
     UINT8           *p = ptext;
     tSMP_ENC        output;
     tSMP_STATUS     status = SMP_PAIR_FAIL_UNKNOWN;
+    UNUSED(p_data);
 
     SMP_TRACE_DEBUG0 ("smp_generate_stk ");
 
@@ -266,6 +270,8 @@
 *******************************************************************************/
 void smp_generate_confirm (tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 {
+    UNUSED(p_data);
+
     SMP_TRACE_DEBUG0 ("smp_generate_confirm");
     p_cb->rand_enc_proc = SMP_GEN_SRAND_MRAND;
     /* generate MRand or SRand */
@@ -284,6 +290,8 @@
 *******************************************************************************/
 void smp_genenrate_rand_cont(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 {
+    UNUSED(p_data);
+
     SMP_TRACE_DEBUG0 ("smp_genenrate_rand_cont ");
     p_cb->rand_enc_proc = SMP_GEN_SRAND_MRAND_CONT;
     /* generate 64 MSB of MRand or SRand */
@@ -305,6 +313,7 @@
 void smp_generate_ltk(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 {
     BOOLEAN     div_status;
+    UNUSED(p_data);
 
     SMP_TRACE_DEBUG0 ("smp_generate_ltk ");
 
@@ -343,6 +352,7 @@
     UINT8       *p=buffer;
     tSMP_ENC    output;
     tSMP_STATUS   status = SMP_PAIR_FAIL_UNKNOWN;
+    UNUSED(p_data);
 
     SMP_TRACE_DEBUG1 ("smp_compute_csrk div=%x", p_cb->div);
     BTM_GetDeviceEncRoot(er);
@@ -376,6 +386,7 @@
 void smp_generate_csrk(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 {
     BOOLEAN     div_status;
+    UNUSED(p_data);
 
     SMP_TRACE_DEBUG0 ("smp_generate_csrk");
 
@@ -544,6 +555,7 @@
     BT_OCTET16      p1;
     tSMP_ENC       output;
     tSMP_STATUS     status = SMP_PAIR_FAIL_UNKNOWN;
+    UNUSED(bda);
 
     SMP_TRACE_DEBUG0 ("smp_calculate_comfirm ");
     /* generate p1 = pres || preq || rat' || iat' */
@@ -625,6 +637,8 @@
 *******************************************************************************/
 static void smp_genenrate_confirm(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 {
+    UNUSED(p_data);
+
     SMP_TRACE_DEBUG0 ("smp_genenrate_confirm ");
     p_cb->rand_enc_proc = SMP_GEN_CONFIRM;
 
@@ -645,6 +659,8 @@
 *******************************************************************************/
 void smp_generate_compare (tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
 {
+    UNUSED(p_data);
+
     SMP_TRACE_DEBUG0 ("smp_generate_compare ");
     p_cb->rand_enc_proc = SMP_GEN_COMPARE;
 
@@ -755,6 +771,7 @@
     BT_OCTET16  er;
     tSMP_ENC    output;
     tSMP_STATUS     status = SMP_PAIR_FAIL_UNKNOWN;
+    UNUSED(p_data);
 
     SMP_TRACE_DEBUG0 ("smp_genenrate_ltk_cont ");
     BTM_GetDeviceEncRoot(er);
@@ -790,7 +807,7 @@
     BT_OCTET16  dhk;
     tSMP_ENC   output;
     tSMP_STATUS     status = SMP_PAIR_FAIL_UNKNOWN;
-
+    UNUSED(p);
 
     SMP_TRACE_DEBUG0 ("smp_generate_y ");
     BTM_GetDeviceDHK(dhk);
@@ -818,6 +835,8 @@
 *******************************************************************************/
 static void smp_generate_rand_vector (tSMP_CB *p_cb, tSMP_INT_DATA *p)
 {
+    UNUSED(p);
+
     /* generate EDIV and rand now */
     /* generate random vector */
     SMP_TRACE_DEBUG0 ("smp_generate_rand_vector ");
diff --git a/stack/smp/smp_utils.c b/stack/smp/smp_utils.c
index 168d6bd..dac0cc0 100644
--- a/stack/smp/smp_utils.c
+++ b/stack/smp/smp_utils.c
@@ -26,6 +26,7 @@
 #if SMP_INCLUDED == TRUE
 
 #include "bt_types.h"
+#include "bt_utils.h"
 #include <string.h>
 #include <ctype.h>
 #include "hcidefs.h"
@@ -151,6 +152,7 @@
 {
     tSMP_CB   *p_cb = &smp_cb;
     UINT8 failure = SMP_RSP_TIMEOUT;
+    UNUSED(p_tle);
 
     SMP_TRACE_EVENT1("smp_rsp_timeout state:%d", p_cb->state);
 
@@ -207,6 +209,8 @@
 {
     BT_HDR      *p_buf = NULL ;
     UINT8       *p;
+    UNUSED(cmd_code);
+
     SMP_TRACE_EVENT0("smp_build_confirm_cmd");
     if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + SMP_CONFIRM_CMD_SIZE + L2CAP_MIN_OFFSET)) != NULL)
     {
@@ -232,6 +236,8 @@
 {
     BT_HDR      *p_buf = NULL ;
     UINT8       *p;
+    UNUSED(cmd_code);
+
     SMP_TRACE_EVENT0("smp_build_rand_cmd");
     if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + SMP_INIT_CMD_SIZE + L2CAP_MIN_OFFSET)) != NULL)
     {
@@ -257,6 +263,8 @@
 {
     BT_HDR      *p_buf = NULL ;
     UINT8       *p;
+    UNUSED(cmd_code);
+
     SMP_TRACE_EVENT0("smp_build_encrypt_info_cmd");
     if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + SMP_ENC_INFO_SIZE + L2CAP_MIN_OFFSET)) != NULL)
     {
@@ -282,6 +290,8 @@
 {
     BT_HDR      *p_buf = NULL ;
     UINT8       *p;
+    UNUSED(cmd_code);
+
     SMP_TRACE_EVENT0("smp_build_master_id_cmd ");
     if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + SMP_MASTER_ID_SIZE + L2CAP_MIN_OFFSET)) != NULL)
     {
@@ -309,6 +319,9 @@
     BT_HDR      *p_buf = NULL ;
     UINT8       *p;
     BT_OCTET16  irk;
+    UNUSED(cmd_code);
+    UNUSED(p_cb);
+
     SMP_TRACE_EVENT0("smp_build_identity_info_cmd");
     if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + SMP_ID_INFO_SIZE + L2CAP_MIN_OFFSET)) != NULL)
     {
@@ -337,7 +350,8 @@
     BT_HDR      *p_buf = NULL ;
     UINT8       *p;
     BD_ADDR     static_addr;
-
+    UNUSED(cmd_code);
+    UNUSED(p_cb);
 
     SMP_TRACE_EVENT0("smp_build_id_addr_cmd");
     if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + SMP_ID_ADDR_SIZE + L2CAP_MIN_OFFSET)) != NULL)
@@ -367,6 +381,7 @@
 {
     BT_HDR      *p_buf = NULL ;
     UINT8       *p;
+    UNUSED(cmd_code);
 
     SMP_TRACE_EVENT0("smp_build_signing_info_cmd");
     if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + SMP_SIGN_INFO_SIZE + L2CAP_MIN_OFFSET)) != NULL)
@@ -393,6 +408,8 @@
 {
     BT_HDR      *p_buf = NULL ;
     UINT8       *p;
+    UNUSED(cmd_code);
+
     SMP_TRACE_EVENT0("smp_build_pairing_fail");
     if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + SMP_PAIR_FAIL_SIZE + L2CAP_MIN_OFFSET)) != NULL)
     {
@@ -418,6 +435,8 @@
 {
     BT_HDR      *p_buf = NULL ;
     UINT8       *p;
+    UNUSED(cmd_code);
+
     SMP_TRACE_EVENT0("smp_build_security_request");
 
     if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR) + 2 + L2CAP_MIN_OFFSET)) != NULL)
diff --git a/stack/srvc/srvc_battery.c b/stack/srvc/srvc_battery.c
index 22e538b..0606fd2 100644
--- a/stack/srvc/srvc_battery.c
+++ b/stack/srvc/srvc_battery.c
@@ -17,7 +17,7 @@
  ******************************************************************************/
 
 #include "bt_target.h"
-
+#include "bt_utils.h"
 #include "gatt_api.h"
 #include "gatt_int.h"
 #include "srvc_eng_int.h"
@@ -115,10 +115,11 @@
     tBA_INST    *p_inst = &battery_cb.battery_inst[0];
     tGATT_STATUS    st = GATT_NOT_FOUND;
     UINT8       act = SRVC_ACT_RSP;
+    UNUSED(p_value);
 
-        for (i = 0; i < BA_MAX_INT_NUM; i ++, p_inst ++)
-        {
-            /* read battery level */
+    for (i = 0; i < BA_MAX_INT_NUM; i ++, p_inst ++)
+    {
+        /* read battery level */
         if (handle == p_inst->ba_level_hdl ||
             handle == p_inst->clt_cfg_hdl ||
             handle == p_inst->rpt_ref_hdl ||
@@ -164,6 +165,7 @@
 *******************************************************************************/
 BOOLEAN battery_gatt_c_read_ba_req(UINT16 conn_id)
 {
+    UNUSED(conn_id);
     return TRUE;
 }
 
@@ -179,6 +181,10 @@
 void battery_c_cmpl_cback (tSRVC_CLCB *p_clcb, tGATTC_OPTYPE op,
                               tGATT_STATUS status, tGATT_CL_COMPLETE *p_data)
 {
+    UNUSED(p_clcb);
+    UNUSED(op);
+    UNUSED(status);
+    UNUSED(p_data);
 }
 
 
@@ -395,6 +401,7 @@
 *******************************************************************************/
 BOOLEAN Battery_ReadBatteryLevel(BD_ADDR peer_bda)
 {
+    UNUSED(peer_bda);
     /* to be implemented */
     return TRUE;
 }
diff --git a/stack/srvc/srvc_dis.c b/stack/srvc/srvc_dis.c
index fcface2..90b4acd 100644
--- a/stack/srvc/srvc_dis.c
+++ b/stack/srvc/srvc_dis.c
@@ -17,7 +17,7 @@
  ******************************************************************************/
 
 #include "bt_target.h"
-
+#include "bt_utils.h"
 #include "gatt_api.h"
 #include "gatt_int.h"
 #include "srvc_eng_int.h"
@@ -76,6 +76,8 @@
 *******************************************************************************/
 UINT8 dis_write_attr_value(tGATT_WRITE_REQ * p_data, tGATT_STATUS *p_status)
 {
+    UNUSED(p_data);
+
     *p_status = GATT_WRITE_NOT_PERMIT;
     return SRVC_ACT_RSP;
 }
@@ -90,6 +92,7 @@
     UINT16          offset = p_value->offset;
     UINT8           act = SRVC_ACT_RSP;
     tGATT_STATUS    st = GATT_NOT_FOUND;
+    UNUSED(clcb_idx);
 
     for (i = 0; i < DIS_MAX_CHAR_NUM; i ++, p_db_attr ++)
     {
diff --git a/stack/srvc/srvc_eng.c b/stack/srvc/srvc_eng.c
index d8db1b0..4598738 100644
--- a/stack/srvc/srvc_eng.c
+++ b/stack/srvc/srvc_eng.c
@@ -17,7 +17,7 @@
  ******************************************************************************/
 
 #include "bt_target.h"
-
+#include "bt_utils.h"
 #include "gatt_api.h"
 #include "gatt_int.h"
 #include "srvc_eng_int.h"
@@ -230,6 +230,7 @@
 UINT8 srvc_eng_process_write_req (UINT8 clcb_idx, tGATT_WRITE_REQ *p_data, tGATTS_RSP *p_rsp, tGATT_STATUS *p_status)
 {
     UINT8       act = SRVC_ACT_RSP;
+    UNUSED(p_rsp);
 
     if (dis_valid_handle_range(p_data->handle))
     {
@@ -342,6 +343,8 @@
 static void srvc_eng_connect_cback (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id,
                                         BOOLEAN connected, tGATT_DISCONN_REASON reason)
 {
+    UNUSED(gatt_if);
+
     GATT_TRACE_EVENT5 ("srvc_eng_connect_cback: from %08x%04x connected:%d conn_id=%d reason = 0x%04x",
                        (bda[0]<<24)+(bda[1]<<16)+(bda[2]<<8)+bda[3],
                        (bda[4]<<8)+bda[5], connected, conn_id, reason);
diff --git a/udrv/ulinux/uipc.c b/udrv/ulinux/uipc.c
index 4e8a273..795f615 100644
--- a/udrv/ulinux/uipc.c
+++ b/udrv/ulinux/uipc.c
@@ -50,6 +50,7 @@
 
 #include <cutils/sockets.h>
 #include "audio_a2dp_hw.h"
+#include "bt_utils.h"
 
 /*****************************************************************************
 **  Constants & Macros
@@ -66,6 +67,8 @@
 #define UIPC_LOCK() /*BTIF_TRACE_EVENT1(" %s lock", __FUNCTION__);*/ pthread_mutex_lock(&uipc_main.mutex);
 #define UIPC_UNLOCK() /*BTIF_TRACE_EVENT1("%s unlock", __FUNCTION__);*/ pthread_mutex_unlock(&uipc_main.mutex);
 
+#define SAFE_FD_ISSET(fd, set) (((fd) == -1) ? FALSE : FD_ISSET((fd), (set)))
+
 /*****************************************************************************
 **  Local type definitions
 ******************************************************************************/
@@ -192,6 +195,7 @@
     if(socket_local_server_bind(s, name, ANDROID_SOCKET_NAMESPACE_ABSTRACT) < 0)
     {
         BTIF_TRACE_EVENT1("socket failed to create (%s)", strerror(errno));
+        close(s);
         return -1;
     }
 
@@ -318,7 +322,7 @@
 
     //BTIF_TRACE_EVENT2("CHECK SRVFD %d (ch %d)", uipc_main.ch[ch_id].srvfd, ch_id);
 
-    if (FD_ISSET(uipc_main.ch[ch_id].srvfd, &uipc_main.read_set))
+    if (SAFE_FD_ISSET(uipc_main.ch[ch_id].srvfd, &uipc_main.read_set))
     {
         BTIF_TRACE_EVENT1("INCOMING CONNECTION ON CH %d", ch_id);
 
@@ -347,7 +351,7 @@
 
     //BTIF_TRACE_EVENT2("CHECK FD %d (ch %d)", uipc_main.ch[ch_id].fd, ch_id);
 
-    if (FD_ISSET(uipc_main.ch[ch_id].fd, &uipc_main.read_set))
+    if (SAFE_FD_ISSET(uipc_main.ch[ch_id].fd, &uipc_main.read_set))
     {
         //BTIF_TRACE_EVENT1("INCOMING DATA ON CH %d", ch_id);
 
@@ -359,7 +363,7 @@
 
 static void uipc_check_interrupt_locked(void)
 {
-    if (FD_ISSET(uipc_main.signal_fds[0], &uipc_main.read_set))
+    if (SAFE_FD_ISSET(uipc_main.signal_fds[0], &uipc_main.read_set))
     {
         char sig_recv = 0;
         //BTIF_TRACE_EVENT0("UIPC INTERRUPT");
@@ -427,7 +431,7 @@
         ret = poll(&pfd, 1, 1);
         BTIF_TRACE_EVENT3("uipc_flush_ch_locked polling : fd %d, rxev %x, ret %d", pfd.fd, pfd.revents, ret);
 
-        if (pfd.revents | (POLLERR|POLLHUP))
+        if (pfd.revents & (POLLERR|POLLHUP))
             return;
 
         if (ret <= 0)
@@ -515,6 +519,7 @@
 {
     int ch_id;
     int result;
+    UNUSED(arg);
 
     prctl(PR_SET_NAME, (unsigned long)"uipc-main", 0, 0, 0);
 
@@ -605,6 +610,8 @@
 
 UDRV_API void UIPC_Init(void *p_data)
 {
+    UNUSED(p_data);
+
     BTIF_TRACE_DEBUG0("UIPC_Init");
 
     memset(&uipc_main, 0, sizeof(tUIPC_MAIN));
@@ -699,6 +706,8 @@
  *******************************************************************************/
 UDRV_API BOOLEAN UIPC_SendBuf(tUIPC_CH_ID ch_id, BT_HDR *p_msg)
 {
+    UNUSED(p_msg);
+
     BTIF_TRACE_DEBUG1("UIPC_SendBuf : ch_id %d NOT IMPLEMENTED", ch_id);
 
     UIPC_LOCK();
@@ -723,6 +732,7 @@
         UINT16 msglen)
 {
     int n;
+    UNUSED(msg_evt);
 
     BTIF_TRACE_DEBUG2("UIPC_Send : ch_id:%d %d bytes", ch_id, msglen);
 
@@ -749,6 +759,8 @@
  *******************************************************************************/
 UDRV_API void UIPC_ReadBuf(tUIPC_CH_ID ch_id, BT_HDR *p_msg)
 {
+    UNUSED(p_msg);
+
     BTIF_TRACE_DEBUG1("UIPC_ReadBuf : ch_id:%d NOT IMPLEMENTED", ch_id);
 
     UIPC_LOCK();
@@ -771,6 +783,7 @@
     int n_read = 0;
     int fd = uipc_main.ch[ch_id].fd;
     struct pollfd pfd;
+    UNUSED(p_msg_evt);
 
     if (ch_id >= UIPC_CH_NUM)
     {
@@ -797,7 +810,7 @@
         if (poll(&pfd, 1, uipc_main.ch[ch_id].read_poll_tmo_ms) == 0)
         {
             BTIF_TRACE_EVENT1("poll timeout (%d ms)", uipc_main.ch[ch_id].read_poll_tmo_ms);
-            return 0;
+            break;
         }
 
         //BTIF_TRACE_EVENT1("poll revents %x", pfd.revents);
diff --git a/utils/include/bt_utils.h b/utils/include/bt_utils.h
index ac18f07..d601f2e 100644
--- a/utils/include/bt_utils.h
+++ b/utils/include/bt_utils.h
@@ -40,4 +40,6 @@
 void bt_utils_cleanup();
 void raise_priority_a2dp(tHIGH_PRIORITY_TASK high_task);
 
+#define UNUSED(x) (void)(x)
+
 #endif /* BT_UTILS_H */