Merge commit 'f7f839985b3931682363d2ef3b7c5cae55a842ee' into merge

Change-Id: Iaaec1ea0bf3009b7e32a9a60f697631a3f56e889
diff --git a/MODULE_LICENSE_APACHE2 b/MODULE_LICENSE_APACHE2
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_APACHE2
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
diff --git a/bta/Android.mk b/bta/Android.mk
index e5e853f..d41ae75 100644
--- a/bta/Android.mk
+++ b/bta/Android.mk
@@ -7,8 +7,8 @@
 	-DBOARD_HAVE_BLUETOOTH_BCM
 endif
 LOCAL_CFLAGS += -DBUILDCFG $(bdroid_CFLAGS) -std=c99
+LOCAL_CLANG_CFLAGS += -Wno-error=gnu-variable-sized-type-not-at-end
 
-LOCAL_PRELINK_MODULE:=false
 LOCAL_SRC_FILES:= \
     ./dm/bta_dm_ci.c \
     ./dm/bta_dm_act.c \
diff --git a/bta/ag/bta_ag_sco.c b/bta/ag/bta_ag_sco.c
index 4261621..a9f6d37 100644
--- a/bta/ag/bta_ag_sco.c
+++ b/bta/ag/bta_ag_sco.c
@@ -22,6 +22,8 @@
  *
  ******************************************************************************/
 
+#include <stddef.h>
+
 #include "bta_api.h"
 #include "bta_ag_api.h"
 #include "bta_ag_co.h"
diff --git a/bta/av/bta_av_aact.c b/bta/av/bta_av_aact.c
index f36f43e..fd57523 100644
--- a/bta/av/bta_av_aact.c
+++ b/bta/av/bta_av_aact.c
@@ -1118,7 +1118,6 @@
     tAVDT_CFG            *p_evt_cfg = &p_data->str_msg.cfg;
     UINT8   psc_mask = (p_evt_cfg->psc_mask | p_scb->cfg.psc_mask);
     UINT8 local_sep;    /* sep type of local handle on which connection was received */
-    UINT8 count = 0;
     tBTA_AV_STR_MSG  *p_msg = (tBTA_AV_STR_MSG *)p_data;
     UNUSED(p_data);
 
diff --git a/bta/av/bta_av_api.c b/bta/av/bta_av_api.c
index 7151ae7..ecc05e1 100644
--- a/bta/av/bta_av_api.c
+++ b/bta/av/bta_av_api.c
@@ -255,9 +255,8 @@
 *******************************************************************************/
 void BTA_AvEnable_Sink(int enable)
 {
-    BT_HDR  *p_buf;
-
 #if (BTA_AV_SINK_INCLUDED == TRUE)
+    BT_HDR  *p_buf;
     if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
     {
         p_buf->event = BTA_AV_API_SINK_ENABLE_EVT;
diff --git a/bta/av/bta_av_cfg.c b/bta/av/bta_av_cfg.c
index e2978c1..d3776f4 100644
--- a/bta/av/bta_av_cfg.c
+++ b/bta/av/bta_av_cfg.c
@@ -23,6 +23,8 @@
  *
  ******************************************************************************/
 
+#include <stddef.h>
+
 #include "bt_target.h"
 #include "gki.h"
 #include "bta_api.h"
diff --git a/bta/dm/bta_dm_act.c b/bta/dm/bta_dm_act.c
index 81e66bd..ee3ba8f 100644
--- a/bta/dm/bta_dm_act.c
+++ b/bta/dm/bta_dm_act.c
@@ -102,7 +102,10 @@
     #endif
 static void bta_dm_observe_results_cb (tBTM_INQ_RESULTS *p_inq, UINT8 *p_eir);
 static void bta_dm_observe_cmpl_cb (void * p_result);
+
+#if BLE_VND_INCLUDED == TRUE
 static void bta_dm_ctrl_features_rd_cmpl_cback(tBTM_STATUS result);
+#endif
 
 #ifndef BTA_DM_BLE_ADV_CHNL_MAP
 #define BTA_DM_BLE_ADV_CHNL_MAP (BTM_BLE_ADV_CHNL_37|BTM_BLE_ADV_CHNL_38|BTM_BLE_ADV_CHNL_39)
@@ -4233,7 +4236,6 @@
 ;
     tBTA_DM_SEARCH     result;
     tBTM_INQ_INFO      *p_inq_info;
-    UINT16             service_class;
     APPL_TRACE_DEBUG("bta_dm_observe_results_cb")
 
     bdcpy(result.inq_res.bd_addr, p_inq->remote_bd_addr);
@@ -4763,7 +4765,6 @@
 void bta_dm_ble_multi_adv_enb(tBTA_DM_MSG *p_data)
 {
     tBTM_STATUS btm_status = 0;
-    void *p_ref = NULL;
 
     bta_dm_cb.p_multi_adv_cback = p_data->ble_multi_adv_enb.p_cback;
     if(BTM_BleMaxMultiAdvInstanceCount() > 0 && NULL != p_data->ble_multi_adv_enb.p_ref)
@@ -5078,27 +5079,6 @@
 
 /*******************************************************************************
 **
-** Function         bta_ble_status_cmpl
-**
-** Description      ADV payload filtering enable / disable complete callback
-**
-**
-** Returns          None
-**
-*******************************************************************************/
-static void bta_ble_status_cmpl(tBTM_BLE_PF_ACTION action, tBTM_BLE_REF_VALUE ref_value,
-                                    tBTM_STATUS status)
-{
-    tBTA_STATUS st = (status == BTM_SUCCESS) ? BTA_SUCCESS: BTA_FAILURE;
-
-    APPL_TRACE_DEBUG("bta_ble_status_cmpl: %d, %d", action, status);
-
-    if(bta_dm_cb.p_scan_filt_status_cback)
-       bta_dm_cb.p_scan_filt_status_cback(action, ref_value, st);
-}
-
-/*******************************************************************************
-**
 ** Function         bta_dm_cfg_filter_cond
 **
 ** Description      This function configure adv payload filtering condition
@@ -5592,6 +5572,7 @@
 
 #endif /* BTA_GATT_INCLUDED */
 
+#if BLE_VND_INCLUDED == TRUE
 /*******************************************************************************
 **
 ** Function         bta_dm_ctrl_features_rd_cmpl_cback
@@ -5615,6 +5596,6 @@
     }
 
 }
-
+#endif /* BLE_VND_INCLUDED */
 
 #endif  /* BLE_INCLUDED */
diff --git a/bta/dm/bta_dm_cfg.c b/bta/dm/bta_dm_cfg.c
index 02f29e6..e16b9f3 100644
--- a/bta/dm/bta_dm_cfg.c
+++ b/bta/dm/bta_dm_cfg.c
@@ -23,6 +23,8 @@
  *
  ******************************************************************************/
 
+#include <stddef.h>
+
 #include "bt_target.h"
 #include "bta_sys.h"
 #include "bta_api.h"
diff --git a/bta/dm/bta_dm_int.h b/bta/dm/bta_dm_int.h
index 34cb530..4ab8497 100644
--- a/bta/dm/bta_dm_int.h
+++ b/bta/dm/bta_dm_int.h
@@ -515,7 +515,7 @@
 typedef struct
 {
     BT_HDR                  hdr;
-    UINT16                  data_mask;
+    UINT32                  data_mask;
     tBTA_BLE_ADV_DATA       *p_adv_cfg;
     tBTA_SET_ADV_DATA_CMPL_CBACK    *p_adv_data_cback;
 }tBTA_DM_API_SET_ADV_CONFIG;
@@ -1117,4 +1117,3 @@
 extern void bta_dm_execute_callback(tBTA_DM_MSG *p_data);
 
 #endif /* BTA_DM_INT_H */
-
diff --git a/bta/gatt/bta_gattc_utils.c b/bta/gatt/bta_gattc_utils.c
index 946d8bf..bffbc4c 100644
--- a/bta/gatt/bta_gattc_utils.c
+++ b/bta/gatt/bta_gattc_utils.c
@@ -947,7 +947,6 @@
 tBTA_GATTC_CLCB * bta_gattc_find_int_disconn_clcb(tBTA_GATTC_DATA *p_msg)
 {
     tBTA_GATTC_CLCB         *p_clcb = NULL;
-    tGATT_DISCONN_REASON    reason = p_msg->int_conn.reason;
 
     bta_gattc_conn_dealloc(p_msg->int_conn.remote_bda);
     if ((p_clcb = bta_gattc_find_clcb_by_conn_id(p_msg->int_conn.hdr.layer_specific)) == NULL)
diff --git a/bta/gatt/bta_gatts_act.c b/bta/gatt/bta_gatts_act.c
index 43befe5..bdd7f29 100644
--- a/bta/gatt/bta_gatts_act.c
+++ b/bta/gatt/bta_gatts_act.c
@@ -152,7 +152,6 @@
 void bta_gatts_api_disable(tBTA_GATTS_CB *p_cb)
 {
     UINT8 i;
-    tBTA_GATT_STATUS    status = BTA_GATT_OK;
 
     if (p_cb->enabled)
     {
diff --git a/bta/hf_client/bta_hf_client_act.c b/bta/hf_client/bta_hf_client_act.c
index 4ea5ba6..880baca 100644
--- a/bta/hf_client/bta_hf_client_act.c
+++ b/bta/hf_client/bta_hf_client_act.c
@@ -263,7 +263,6 @@
 void bta_hf_client_rfc_acp_open(tBTA_HF_CLIENT_DATA *p_data)
 {
     UINT16          lcid;
-    int             i;
     BD_ADDR         dev_addr;
     int             status;
 
@@ -391,7 +390,6 @@
 *******************************************************************************/
 void bta_hf_client_rfc_close(tBTA_HF_CLIENT_DATA *p_data)
 {
-    int i, num_active_conn = 0;
     UNUSED(p_data);
 
     /* reinitialize stuff */
diff --git a/bta/hf_client/bta_hf_client_api.c b/bta/hf_client/bta_hf_client_api.c
index b67f140..2d95ca3 100644
--- a/bta/hf_client/bta_hf_client_api.c
+++ b/bta/hf_client/bta_hf_client_api.c
@@ -58,7 +58,6 @@
 tBTA_STATUS BTA_HfClientEnable(tBTA_HF_CLIENT_CBACK *p_cback)
 {
     tBTA_HF_CLIENT_API_ENABLE  *p_buf;
-    UINT8       idx;
 
     if (bta_sys_is_register (BTA_ID_HS))
     {
diff --git a/bta/hf_client/bta_hf_client_rfc.c b/bta/hf_client/bta_hf_client_rfc.c
index aaa8d21..829c3a5 100644
--- a/bta/hf_client/bta_hf_client_rfc.c
+++ b/bta/hf_client/bta_hf_client_rfc.c
@@ -144,7 +144,6 @@
 *******************************************************************************/
 void bta_hf_client_start_server(void)
 {
-    int i;
     int port_status;
 
     if (bta_hf_client_cb.scb.serv_handle > 0)
diff --git a/bta/hf_client/bta_hf_client_sdp.c b/bta/hf_client/bta_hf_client_sdp.c
index a19912c..fd55a6c 100644
--- a/bta/hf_client/bta_hf_client_sdp.c
+++ b/bta/hf_client/bta_hf_client_sdp.c
@@ -94,7 +94,6 @@
     UINT16              version;
     UINT16              profile_uuid;
     BOOLEAN             result = TRUE;
-    BOOLEAN             codec_supported = FALSE;
     UINT8               buf[2];
     UINT16              sdp_features = 0;
 
diff --git a/bta/hh/bta_hh_le.c b/bta/hh/bta_hh_le.c
index 4f4feec..99a5627 100644
--- a/bta/hh/bta_hh_le.c
+++ b/bta/hh/bta_hh_le.c
@@ -2408,7 +2408,6 @@
 void bta_hh_le_open_fail(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
 {
     tBTA_HH_CONN            conn_dat ;
-    tBTA_HH_LE_HID_SRVC     *p_hid_srvc = &p_cb->hid_srvc[0];
 
     /* open failure in the middle of service discovery, clear all services */
     if (p_cb->disc_active & BTA_HH_LE_DISC_HIDS)
diff --git a/bta/hl/bta_hl_ci.c b/bta/hl/bta_hl_ci.c
index 46deee3..792b08f 100644
--- a/bta/hl/bta_hl_ci.c
+++ b/bta/hl/bta_hl_ci.c
@@ -22,6 +22,9 @@
  *  subsystem call-in functions.
  *
  ******************************************************************************/
+
+#include <stddef.h>
+
 #include "bta_api.h"
 #include "btm_api.h"
 #include "bta_sys.h"
diff --git a/bta/hl/bta_hl_utils.c b/bta/hl/bta_hl_utils.c
index 628f423..0a0f326 100644
--- a/bta/hl/bta_hl_utils.c
+++ b/bta/hl/bta_hl_utils.c
@@ -1601,7 +1601,6 @@
 *******************************************************************************/
 void  bta_hl_compact_mdl_cfg_time(UINT8 app_idx, UINT8 mdep_id)
 {
-    tBTA_HL_APP_CB      *p_acb = BTA_HL_GET_APP_CB_PTR(app_idx);
     tBTA_HL_MDL_CFG     *p_mdl;
     UINT8 i, time_min, cnt=0;
     UINT8   s_arr[BTA_HL_NUM_MDL_CFGS];
@@ -1700,8 +1699,6 @@
     tBTA_HL_MDL_CFG     *p_mdl;
     BOOLEAN             success = FALSE;
     UINT8               i;
-    tBTA_HL_APP_CB      *p_acb= BTA_HL_GET_APP_CB_PTR(app_idx);
-    UINT8               app_id = p_acb->app_id;
 
     for (i = 0; i< BTA_HL_NUM_MDL_CFGS; i++)
     {
diff --git a/bta/include/bta_api.h b/bta/include/bta_api.h
index f4c8337..f4fc9f2 100644
--- a/bta/include/bta_api.h
+++ b/bta/include/bta_api.h
@@ -943,20 +943,10 @@
 #define BTA_DM_BLE_PF_CONFIG_EVT       BTM_BLE_PF_CONFIG
 typedef UINT8 tBTA_DM_BLE_PF_EVT;
 
-typedef UINT8   tBTA_DM_BLE_PF_COND_TYPE;
-
-#define BTA_DM_BLE_PF_LOGIC_OR              0
-#define BTA_DM_BLE_PF_LOGIC_AND             1
-typedef UINT8 tBTA_DM_BLE_PF_LOGIC_TYPE;
-
 #define BTA_DM_BLE_PF_ENABLE       1
 #define BTA_DM_BLE_PF_CONFIG       2
 typedef UINT8 tBTA_DM_BLE_PF_ACTION;
 
-typedef UINT8 tBTA_DM_BLE_PF_FILT_INDEX;
-
-typedef UINT8 tBTA_DM_BLE_PF_AVBL_SPACE;
-
 /* Config callback */
 typedef void (tBTA_DM_BLE_PF_CFG_CBACK) (tBTA_DM_BLE_PF_ACTION action,
                                          tBTA_DM_BLE_PF_COND_TYPE cfg_cond,
diff --git a/bta/jv/bta_jv_act.c b/bta/jv/bta_jv_act.c
index 224450a..c9299e8 100644
--- a/bta/jv/bta_jv_act.c
+++ b/bta/jv/bta_jv_act.c
@@ -976,8 +976,6 @@
     tBTA_JV evt_data;
     BD_ADDR rem_bda;
     UINT16 lcid;
-    UINT8  num;
-    UINT32  si;
     APPL_TRACE_DEBUG("bta_jv_port_mgmt_sr_cback, code:%d, port_handle:%d", code, port_handle);
     if(NULL == p_cb || NULL == p_cb->p_cback)
     {
diff --git a/bta/mce/bta_mce_main.c b/bta/mce/bta_mce_main.c
index f313eb0..a7cbb01 100644
--- a/bta/mce/bta_mce_main.c
+++ b/bta/mce/bta_mce_main.c
@@ -23,6 +23,8 @@
  *
  ******************************************************************************/
 
+#include <stddef.h>
+
 #include "bta_api.h"
 #include "bta_sys.h"
 #include "bta_mce_api.h"
diff --git a/bta/sys/bta_sys_conn.c b/bta/sys/bta_sys_conn.c
index eed79d0..accff7c 100644
--- a/bta/sys/bta_sys_conn.c
+++ b/bta/sys/bta_sys_conn.c
@@ -22,6 +22,8 @@
  *
  ******************************************************************************/
 
+#include <stddef.h>
+
 #include "bta_api.h"
 #include "bta_sys.h"
 #include "bta_sys_int.h"
diff --git a/bta/sys/utl.c b/bta/sys/utl.c
index 4bb1d95..d193d6f 100644
--- a/bta/sys/utl.c
+++ b/bta/sys/utl.c
@@ -21,6 +21,8 @@
  *  This file contains utility functions.
  *
  ******************************************************************************/
+#include <stddef.h>
+
 #include "utl.h"
 #include "gki.h"
 #include "btm_api.h"
diff --git a/btif/co/bta_av_co.c b/btif/co/bta_av_co.c
index a477664..1460fca 100644
--- a/btif/co/bta_av_co.c
+++ b/btif/co/bta_av_co.c
@@ -463,7 +463,6 @@
     BOOLEAN supported;
     tBTA_AV_CO_PEER *p_peer;
     tBTA_AV_CO_SINK *p_src;
-    UINT8 codec_cfg[AVDT_CODEC_SIZE];
     UINT8 pref_cfg[AVDT_CODEC_SIZE];
     UINT8 index;
 
diff --git a/btif/co/bta_gatts_co.c b/btif/co/bta_gatts_co.c
index ae4272d..e1263d7 100644
--- a/btif/co/bta_gatts_co.c
+++ b/btif/co/bta_gatts_co.c
@@ -22,6 +22,7 @@
 #if( defined BTA_GATT_INCLUDED ) && (BTA_GATT_INCLUDED == TRUE)
 
 #include <stdlib.h>
+#include <string.h>
 #include "gki.h"
 #include "bta_gatts_co.h"
 #include "btif_util.h"
diff --git a/btif/co/bta_pan_co.c b/btif/co/bta_pan_co.c
index 7070f1a..50e0d8c 100644
--- a/btif/co/bta_pan_co.c
+++ b/btif/co/bta_pan_co.c
@@ -158,7 +158,6 @@
 void bta_pan_co_tx_path(UINT16 handle, UINT8 app_id)
 {
     BT_HDR          *p_buf;
-    UINT8           i;
     BD_ADDR            src;
     BD_ADDR            dst;
     UINT16            protocol;
diff --git a/btif/include/btif_hh.h b/btif/include/btif_hh.h
index 7edba74..dc34d65 100644
--- a/btif/include/btif_hh.h
+++ b/btif/include/btif_hh.h
@@ -21,6 +21,7 @@
 
 #include <hardware/bluetooth.h>
 #include <hardware/bt_hh.h>
+#include <pthread.h>
 #include <stdint.h>
 #include "bta_hh_api.h"
 #include "btu.h"
@@ -63,7 +64,7 @@
     UINT8                         sub_class;
     UINT8                         app_id;
     int                           fd;
-    UINT32                        hh_poll_thread_id;
+    pthread_t                     hh_poll_thread_id;
     UINT8                         hh_keep_polling;
     BOOLEAN                       vup_timer_active;
     TIMER_LIST_ENT                vup_timer;
diff --git a/btif/src/bluetooth.c b/btif/src/bluetooth.c
index 18d0339..075e9cf 100644
--- a/btif/src/bluetooth.c
+++ b/btif/src/bluetooth.c
@@ -26,6 +26,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 #include <hardware/bluetooth.h>
diff --git a/btif/src/btif_av.c b/btif/src/btif_av.c
index 28d0d9a..fe30555 100644
--- a/btif/src/btif_av.c
+++ b/btif/src/btif_av.c
@@ -27,6 +27,7 @@
 
 #include <hardware/bluetooth.h>
 #include <system/audio.h>
+#include <string.h>
 #include "hardware/bt_av.h"
 
 #define LOG_TAG "bt_btif_av"
diff --git a/btif/src/btif_core.c b/btif/src/btif_core.c
index 3dd5b2b..f202d7b 100644
--- a/btif/src/btif_core.c
+++ b/btif/src/btif_core.c
@@ -805,8 +805,6 @@
 
 static void execute_storage_request(UINT16 event, char *p_param)
 {
-    uint8_t is_local;
-    int num_entries = 0;
     bt_status_t status = BT_STATUS_SUCCESS;
 
     BTIF_TRACE_EVENT("execute storage request event : %d", event);
@@ -1116,7 +1114,6 @@
 
     if (storage_req_id != BTIF_CORE_STORAGE_NO_ACTION)
     {
-        int btif_status;
         /* pass on to storage for updating local database */
 
         memset(&(req.write_req.bd_addr), 0, sizeof(bt_bdaddr_t));
diff --git a/btif/src/btif_dm.c b/btif/src/btif_dm.c
index b11b364..a317a94 100644
--- a/btif/src/btif_dm.c
+++ b/btif/src/btif_dm.c
@@ -29,6 +29,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 #include <hardware/bluetooth.h>
@@ -435,13 +436,11 @@
 *******************************************************************************/
 BOOLEAN check_sdp_bl(const bt_bdaddr_t *remote_bdaddr)
 {
-    UINT8 i = 0;
     UINT16 manufacturer = 0;
     UINT8 lmp_ver = 0;
     UINT16 lmp_subver = 0;
     bt_property_t prop_name;
     bt_remote_version_t info;
-    bt_status_t status;
 
 
     if (remote_bdaddr == NULL)
@@ -691,7 +690,6 @@
 *******************************************************************************/
 void btif_dm_cb_remove_bond(bt_bdaddr_t *bd_addr)
 {
-     bdstr_t bdstr;
      /*special handling for HID devices */
      /*  VUP needs to be sent if its a HID Device. The HID HOST module will check if there
      is a valid hid connection with this bd_addr. If yes VUP will be issued.*/
@@ -1227,11 +1225,9 @@
         {
             /* inquiry result */
             UINT32 cod;
-            UINT8 *p_eir_remote_name = NULL;
             bt_bdname_t bdname;
             bt_bdaddr_t bdaddr;
             UINT8 remote_name_len;
-            UINT8 *p_cached_name = NULL;
             tBTA_SERVICE_MASK services = 0;
             bdstr_t bdstr;
 
@@ -1385,9 +1381,8 @@
     {
         case BTA_DM_DISC_RES_EVT:
         {
-            bt_uuid_t uuid_arr[BT_MAX_NUM_UUIDS]; /* Max 32 services */
             bt_property_t prop;
-            uint32_t i = 0,  j = 0;
+            uint32_t i = 0;
             bt_bdaddr_t bd_addr;
             bt_status_t ret;
 
@@ -1521,7 +1516,6 @@
         {
             bt_service_record_t rec;
             bt_property_t prop;
-            uint32_t i = 0;
             bt_bdaddr_t bd_addr;
 
             memset(&rec, 0, sizeof(bt_service_record_t));
@@ -1564,7 +1558,6 @@
 *******************************************************************************/
 static void btif_dm_upstreams_evt(UINT16 event, char* p_param)
 {
-    tBTA_DM_SEC_EVT dm_event = (tBTA_DM_SEC_EVT)event;
     tBTA_DM_SEC *p_data = (tBTA_DM_SEC*)p_param;
     tBTA_SERVICE_MASK service_mask;
     uint32_t i;
@@ -2502,8 +2495,6 @@
 *******************************************************************************/
 bt_status_t btif_dm_get_adapter_property(bt_property_t *prop)
 {
-    bt_status_t status;
-
     BTIF_TRACE_EVENT("%s: type=0x%x", __FUNCTION__, prop->type);
     switch (prop->type)
     {
@@ -2884,8 +2875,6 @@
 
 void    btif_dm_load_ble_local_keys(void)
 {
-    bt_status_t bt_status;
-
     memset(&ble_local_key_cb, 0, sizeof(btif_dm_local_key_cb_t));
 
     if (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_ER,(char*)&ble_local_key_cb.er[0],
diff --git a/btif/src/btif_gatt_client.c b/btif/src/btif_gatt_client.c
index 1314055..bd72e03 100644
--- a/btif/src/btif_gatt_client.c
+++ b/btif/src/btif_gatt_client.c
@@ -338,7 +338,6 @@
 
 static void btif_gattc_add_remote_bdaddr (BD_ADDR p_bda, uint8_t addr_type)
 {
-    BOOLEAN found=FALSE;
     uint8_t i;
     for (i = 0; i < BTIF_GATT_MAX_OBSERVED_DEV; i++)
     {
diff --git a/btif/src/btif_gatt_multi_adv_util.c b/btif/src/btif_gatt_multi_adv_util.c
index 7e5dc8d..bd39657 100644
--- a/btif/src/btif_gatt_multi_adv_util.c
+++ b/btif/src/btif_gatt_multi_adv_util.c
@@ -27,6 +27,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include "btu.h"
 #include "bt_target.h"
 
@@ -253,7 +254,6 @@
 
 BOOLEAN btif_gattc_copy_datacb(int cbindex, btif_adv_data_t *p_adv_data, BOOLEAN bInstData)
 {
-    int i=0;
     btgatt_multi_adv_common_data *p_multi_adv_data_cb = btif_obtain_multi_adv_data_cb();
     if (NULL == p_multi_adv_data_cb || cbindex < 0)
        return false;
diff --git a/btif/src/btif_gatt_util.c b/btif/src/btif_gatt_util.c
index 11a41ea..7e00757 100644
--- a/btif/src/btif_gatt_util.c
+++ b/btif/src/btif_gatt_util.c
@@ -237,7 +237,6 @@
 
 uint16_t set_read_value(btgatt_read_params_t *p_dest, tBTA_GATTC_READ *p_src)
 {
-    int i = 0;
     uint16_t descr_type = 0;
     uint16_t len = 0;
 
diff --git a/btif/src/btif_hf.c b/btif/src/btif_hf.c
index 25ced48..f8c118b 100644
--- a/btif/src/btif_hf.c
+++ b/btif/src/btif_hf.c
@@ -28,6 +28,7 @@
 #include <hardware/bluetooth.h>
 #include <hardware/bt_hf.h>
 #include <stdlib.h>
+#include <string.h>
 
 #define LOG_TAG "bt_btif_hf"
 #include "btif_common.h"
@@ -352,7 +353,7 @@
         int i;
         for (i = 0; i < btif_max_hf_clients; i++)
         {
-            if ((btif_hf_cb[i].state == BTHF_CONNECTION_STATE_SLC_CONNECTED))
+            if (btif_hf_cb[i].state == BTHF_CONNECTION_STATE_SLC_CONNECTED)
             {
                 BTIF_TRACE_EVENT("BTHF: %s: slc connected for idx = %d",
                                          __FUNCTION__, i);
@@ -388,7 +389,6 @@
 {
     tBTA_AG *p_data = (tBTA_AG *)p_param;
     bdstr_t bdstr;
-    bt_bdaddr_t addr;
     int idx = p_data->hdr.handle - 1;
 
     BTIF_TRACE_DEBUG("%s: event=%s", __FUNCTION__, dump_hf_event(event));
diff --git a/btif/src/btif_hf_client.c b/btif/src/btif_hf_client.c
index 7bc2d9a..ee78a8a 100644
--- a/btif/src/btif_hf_client.c
+++ b/btif/src/btif_hf_client.c
@@ -29,6 +29,7 @@
 #include <hardware/bluetooth.h>
 #include <hardware/bt_hf_client.h>
 #include <stdlib.h>
+#include <string.h>
 #include <cutils/properties.h>
 
 #define LOG_TAG "bt_btif_hfc"
@@ -137,7 +138,7 @@
     switch (event) {
         case BTIF_HF_CLIENT_CB_AUDIO_CONNECTING:
         {
-            HAL_CBACK(bt_hf_client_callbacks, audio_state_cb, BTHF_AUDIO_STATE_CONNECTING,
+            HAL_CBACK(bt_hf_client_callbacks, audio_state_cb, (bthf_client_audio_state_t)BTHF_AUDIO_STATE_CONNECTING,
                       &btif_hf_client_cb.connected_bda);
         } break;
         default:
@@ -367,8 +368,6 @@
 *******************************************************************************/
 static bt_status_t volume_control(bthf_client_volume_type_t type, int volume)
 {
-    BOOLEAN speaker;
-
     CHECK_BTHF_CLIENT_SLC_CONNECTED();
 
     switch (type)
diff --git a/btif/src/btif_hh.c b/btif/src/btif_hh.c
index 20c8e3c..997f523 100644
--- a/btif/src/btif_hh.c
+++ b/btif/src/btif_hh.c
@@ -67,7 +67,6 @@
 
 extern const int BT_UID;
 extern const int BT_GID;
-static int btif_hh_prev_keyevents=0; //The previous key events
 static int btif_hh_keylockstates=0; //The current key state of each key
 
 #define BTIF_HH_ID_1        0
@@ -623,7 +622,6 @@
     char bda_str[20];
     int i;
     BD_ADDR *bda = (BD_ADDR*)bd_addr;
-    tBTA_HH_CONN conn;
     CHECK_BTHH_INIT();
     dev = btif_hh_find_dev_by_bda(bd_addr);
     BTIF_TRACE_DEBUG("Connect _hh");
@@ -687,7 +685,6 @@
 
 void btif_hh_disconnect(bt_bdaddr_t *bd_addr)
 {
-    BD_ADDR *bda = (BD_ADDR*)bd_addr;
     btif_hh_device_t *p_dev;
     p_dev = btif_hh_find_connected_dev_by_bda(bd_addr);
     if (p_dev != NULL)
@@ -741,7 +738,6 @@
 static void btif_hh_upstreams_evt(UINT16 event, char* p_param)
 {
     tBTA_HH *p_data = (tBTA_HH *)p_param;
-    bdstr_t bdstr;
     btif_hh_device_t *p_dev = NULL;
     int i;
     int len, tmplen;
@@ -1182,7 +1178,7 @@
 void btif_hh_tmr_hdlr(TIMER_LIST_ENT *tle)
 {
     btif_hh_device_t *p_dev;
-    UINT8               i,j;
+    UINT8               i;
     tBTA_HH_EVT event;
     tBTA_HH p_data;
     int param_len = 0;
diff --git a/btif/src/btif_hl.c b/btif/src/btif_hl.c
index d11ba25..9d0c0d7 100644
--- a/btif/src/btif_hl.c
+++ b/btif/src/btif_hl.c
@@ -916,7 +916,7 @@
     btif_hl_app_cb_t            *p_acb;
     btif_hl_mcl_cb_t            *p_mcb;
     btif_hl_pending_chan_cb_t   *p_pcb;
-    UINT8                       app_idx, mcl_idx, chan_idx;
+    UINT8                       app_idx, mcl_idx;
     BOOLEAN                     status = TRUE;
 
     BTIF_TRACE_DEBUG("%s app_id=%d ctrl_psm=%d mdep_cfg_idx=%d op=%d",
@@ -1295,7 +1295,6 @@
 BOOLEAN btif_hl_find_mcl_idx(UINT8 app_idx, BD_ADDR p_bd_addr, UINT8 *p_mcl_idx){
     BOOLEAN found=FALSE;
     UINT8 i;
-    btif_hl_app_cb_t  *p_acb =BTIF_HL_GET_APP_CB_PTR(app_idx);
     btif_hl_mcl_cb_t  *p_mcb;
 
     *p_mcl_idx = 0;
@@ -1867,7 +1866,6 @@
 *******************************************************************************/
 static void btif_hl_stop_timer_using_handle( tBTA_HL_MCL_HANDLE mcl_handle){
     btif_hl_app_cb_t  *p_acb;
-    BOOLEAN         found=FALSE;
     UINT8 i,j;
 
     for (i=0; i<BTA_HL_NUM_APPS; i++)
@@ -1897,7 +1895,7 @@
                                            UINT8 p_app_idx, UINT8 *p_mcl_idx){
     btif_hl_app_cb_t  *p_acb;
     BOOLEAN         found=FALSE;
-    UINT8 i,j;
+    UINT8 j;
 
     p_acb =BTIF_HL_GET_APP_CB_PTR(p_app_idx);
     for (j=0; j < BTA_HL_NUM_MCLS ; j++)
@@ -1928,7 +1926,7 @@
     btif_hl_app_cb_t  *p_acb;
     btif_hl_mcl_cb_t  *p_mcb;
     btif_hl_mdl_cb_t  *p_dcb;
-    UINT8 i,j,x,y;
+    UINT8 j,x,y;
     bt_bdaddr_t     bd_addr;
 
         p_acb =BTIF_HL_GET_APP_CB_PTR(app_idx);
@@ -2121,7 +2119,6 @@
     UINT8                   app_idx;
     int                     app_id = 0;
     bthl_app_reg_state_t    state = BTHL_APP_REG_STATE_DEREG_SUCCESS;
-    bt_status_t             status            = BT_STATUS_SUCCESS;
 
     BTIF_TRACE_DEBUG("%s de-reg status=%d app_handle=%d", __FUNCTION__,
                 p_data->dereg_cfm.status, p_data->dereg_cfm.app_handle);
@@ -2161,7 +2158,6 @@
     btif_hl_app_cb_t       *p_acb;
     UINT8                  app_idx;
     bthl_app_reg_state_t   state = BTHL_APP_REG_STATE_REG_SUCCESS;
-    bt_status_t            bt_status;
 
     BTIF_TRACE_DEBUG("%s reg status=%d app_handle=%d", __FUNCTION__, p_data->reg_cfm.status, p_data->reg_cfm.app_handle);
 
@@ -2465,7 +2461,7 @@
 
 {
     btif_hl_mcl_cb_t         *p_mcb;
-    UINT8                   app_idx, mcl_idx;
+    UINT8                   mcl_idx;
     int                     i;
 
     BTIF_TRACE_DEBUG("%s", __FUNCTION__);
@@ -2588,7 +2584,6 @@
     btif_hl_mcl_cb_t         *p_mcb;
     UINT8                    app_idx, mcl_idx;
     BOOLEAN                  status = FALSE;
-    tBTA_HL_DCH_OPEN_PARAM   dch_open;
 
     BTIF_TRACE_DEBUG("%s", __FUNCTION__);
 
@@ -2657,7 +2652,6 @@
 static void btif_hl_proc_cch_close_ind(tBTA_HL *p_data)
 
 {
-    UINT8                   app_idx, mcl_idx;
     BTIF_TRACE_DEBUG("%s", __FUNCTION__);
 
     btif_hl_clean_mcb_using_handle(p_data->cch_close_ind.mcl_handle);
@@ -2675,7 +2669,6 @@
 *******************************************************************************/
 static void btif_hl_proc_cch_close_cfm(tBTA_HL *p_data)
 {
-    UINT8                   app_idx, mcl_idx;
     BTIF_TRACE_DEBUG("%s", __FUNCTION__);
 
     btif_hl_clean_mcb_using_handle(p_data->cch_close_ind.mcl_handle);
@@ -2694,7 +2687,7 @@
     btif_hl_app_cb_t         *p_acb;
     btif_hl_mcl_cb_t         *p_mcb;
     tBTA_HL_MDEP            *p_mdep;
-    UINT8                   app_idx, orig_app_idx, mcl_idx, mdep_cfg_idx;
+    UINT8                   orig_app_idx, mcl_idx, mdep_cfg_idx;
     BOOLEAN                 first_reliable_exist;
     BOOLEAN                 success = TRUE;
     tBTA_HL_DCH_CFG         rsp_cfg = BTA_HL_DCH_CFG_UNKNOWN;
@@ -2777,7 +2770,6 @@
 {
     btif_hl_mdl_cb_t         *p_dcb;
     UINT8                    orig_app_idx, mcl_idx, mdl_idx, mdep_cfg_idx;
-    UINT8                    dc_cfg;
     BOOLEAN close_dch = FALSE;
 
     BTIF_TRACE_DEBUG("%s", __FUNCTION__);
@@ -3006,7 +2998,7 @@
 {
     btif_hl_app_cb_t        *p_acb;
     btif_hl_mdl_cb_t        *p_dcb;
-    UINT8                   app_idx, mcl_idx, mdl_idx, mdep_cfg_idx, dc_cfg;
+    UINT8                   app_idx, mcl_idx, mdl_idx, mdep_cfg_idx;
     BOOLEAN                 close_dch = FALSE;
 
     BTIF_TRACE_DEBUG("%s", __FUNCTION__);
@@ -3139,7 +3131,6 @@
 *******************************************************************************/
 static void btif_hl_proc_abort_ind(tBTA_HL_MCL_HANDLE mcl_handle){
 
-    UINT8                   app_idx,mcl_idx;
     BTIF_TRACE_DEBUG("%s", __FUNCTION__ );
     btif_hl_app_cb_t  *p_acb;
     UINT8 i,j;
@@ -3172,8 +3163,6 @@
 **
 *******************************************************************************/
 static void btif_hl_proc_abort_cfm(tBTA_HL_MCL_HANDLE mcl_handle){
-    UINT8                   app_idx,mcl_idx;
-
     BTIF_TRACE_DEBUG("%s", __FUNCTION__ );
     btif_hl_app_cb_t  *p_acb;
     UINT8 i,j;
@@ -3260,9 +3249,6 @@
 static void btif_hl_proc_reg_request(UINT8 app_idx, UINT8  app_id,
                                      tBTA_HL_REG_PARAM *p_reg_param,
                                      tBTA_HL_CBACK *p_cback){
-    bt_status_t status= BT_STATUS_SUCCESS;
-    UINT8 i;
-    btif_hl_app_data_t *p_data;
     UNUSED(p_cback);
 
     BTIF_TRACE_DEBUG("%s app_idx=%d app_id=%d", __FUNCTION__, app_idx, app_id);
@@ -3383,7 +3369,6 @@
     UINT8                 app_idx, mcl_idx;
     btif_hl_app_cb_t      *p_acb;
     btif_hl_mcl_cb_t      *p_mcb = NULL;
-    BD_ADDR               bd_addr;
     btif_hl_pend_dch_op_t  pending_op;
     BOOLEAN status;
 
@@ -4076,11 +4061,10 @@
 **
 *******************************************************************************/
 static bt_status_t destroy_channel(int channel_id){
-    UINT8 app_idx, mcl_idx, mdl_idx, mdl_cfg_idx, app_id, mdep_cfg_idx = 0;
+    UINT8 app_idx, mcl_idx, mdl_cfg_idx, mdep_cfg_idx = 0;
     bt_status_t status = BT_STATUS_SUCCESS;
     btif_hl_mdl_cfg_t     *p_mdl;
     btif_hl_mcl_cb_t     *p_mcb;
-    btif_hl_mdl_cb_t     *p_dcb;
     btif_hl_app_cb_t     *p_acb;
 
     CHECK_BTHL_INIT();
@@ -4208,7 +4192,7 @@
     tBTA_HL_SUP_FEATURE         *p_sup;
     tBTA_HL_MDEP_CFG            *p_cfg;
     tBTA_HL_MDEP_DATA_TYPE_CFG  *p_data;
-    UINT8                       app_idx=0, i=0, pending_reg_idx=0;
+    UINT8                       app_idx=0, i=0;
     bthl_mdep_cfg_t             *p_mdep_cfg;
     bt_status_t                 status = BT_STATUS_SUCCESS;
     btif_hl_evt_cb_t            evt_param;
@@ -4338,7 +4322,7 @@
     BOOLEAN             success = FALSE;
     btif_hl_app_cb_t    *p_acb;
     btif_hl_mcl_cb_t    *p_mcb;
-    UINT8               app_idx, mcl_idx, mdl_idx, len;
+    UINT8               app_idx, mcl_idx, len;
     bt_status_t         bt_status;
     btif_hl_evt_cb_t    evt_param;
     int                 *p_channel_id;
@@ -4561,7 +4545,6 @@
 **
 *******************************************************************************/
 void btif_hl_release_mcl_sockets(UINT8 app_idx, UINT8 mcl_idx){
-    btif_hl_soc_cb_t    *p_scb = NULL;
     UINT8               i;
     btif_hl_mdl_cb_t    *p_dcb;
     BOOLEAN             found= FALSE;
@@ -4617,7 +4600,6 @@
     btif_hl_mcl_cb_t      *p_mcb = BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx);
     btif_hl_mdl_cb_t      *p_dcb = BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx);
     btif_hl_soc_cb_t      *p_scb = NULL;
-    UINT8                 soc_idx;
     BOOLEAN               status = FALSE;
 
     BTIF_TRACE_DEBUG("%s", __FUNCTION__);
diff --git a/btif/src/btif_mce.c b/btif/src/btif_mce.c
index bf4c3bd..c50ef8b 100644
--- a/btif/src/btif_mce.c
+++ b/btif/src/btif_mce.c
@@ -29,6 +29,7 @@
 #include <hardware/bluetooth.h>
 #include <hardware/bt_mce.h>
 #include <stdlib.h>
+#include <string.h>
 
 #define LOG_TAG "bt_btif_mce"
 #include "btif_common.h"
diff --git a/btif/src/btif_media_task.c b/btif/src/btif_media_task.c
index d1dac72..2d6f68a 100644
--- a/btif/src/btif_media_task.c
+++ b/btif/src/btif_media_task.c
@@ -924,7 +924,6 @@
 
 BOOLEAN btif_a2dp_on_started(tBTA_AV_START *p_av, BOOLEAN pending_start)
 {
-    tBTIF_STATUS status;
     BOOLEAN ack = FALSE;
 
     APPL_TRACE_EVENT("## ON A2DP STARTED ##");
@@ -978,8 +977,6 @@
 
 void btif_a2dp_ack_fail(void)
 {
-    tBTIF_STATUS status;
-
     APPL_TRACE_EVENT("## A2DP_CTRL_ACK_FAILURE ##");
     a2dp_cmd_acknowledge(A2DP_CTRL_ACK_FAILURE);
 }
diff --git a/btif/src/btif_pan.c b/btif/src/btif_pan.c
index d7228c3..25f27eb 100644
--- a/btif/src/btif_pan.c
+++ b/btif/src/btif_pan.c
@@ -27,6 +27,7 @@
 #include <hardware/bluetooth.h>
 #include <hardware/bt_pan.h>
 #include <assert.h>
+#include <string.h>
 #include <signal.h>
 #include <ctype.h>
 #include <sys/select.h>
@@ -42,7 +43,6 @@
 #include <net/if.h>
 #include <linux/sockios.h>
 #include <sys/prctl.h>
-#include <linux/if.h>
 #include <linux/if_tun.h>
 #include <linux/if_ether.h>
 
diff --git a/btif/src/btif_profile_queue.c b/btif/src/btif_profile_queue.c
index 87a008c..5693860 100644
--- a/btif/src/btif_profile_queue.c
+++ b/btif/src/btif_profile_queue.c
@@ -26,6 +26,7 @@
 
 #include <assert.h>
 #include <hardware/bluetooth.h>
+#include <string.h>
 
 #define LOG_TAG "bt_btif_queue"
 #include "btif_common.h"
diff --git a/btif/src/btif_rc.c b/btif/src/btif_rc.c
index 80a10da..1c26dff 100644
--- a/btif/src/btif_rc.c
+++ b/btif/src/btif_rc.c
@@ -26,6 +26,7 @@
  *****************************************************************************/
 #include <hardware/bluetooth.h>
 #include <fcntl.h>
+#include <string.h>
 #include "bta_api.h"
 #include "bta_av_api.h"
 #include "avrc_defs.h"
@@ -172,11 +173,6 @@
  * For now, only the rc_white_addr_prefix is used in the code while
  * rc_black_addr_prefix is kept here for future long term solution.
  */
-static const UINT8 rc_black_addr_prefix[][3] = {
-    {0x0, 0x18, 0x6B}, // LG HBS-730
-    {0x0, 0x26, 0x7E}  // VW Passat
-};
-
 static const UINT8 rc_white_addr_prefix[][3] = {
     {0x94, 0xCE, 0x2C}, // Sony SBH50
     {0x30, 0x17, 0xC8} // Sony wm600
@@ -273,7 +269,7 @@
 int uinput_create(char *name)
 {
     struct uinput_dev dev;
-    int fd, err, x = 0;
+    int fd, x = 0;
 
     for(x=0; x < MAX_UINPUT_PATHS; x++)
     {
@@ -421,8 +417,6 @@
 {
     BTIF_TRACE_DEBUG("%s: rc_handle: %d", __FUNCTION__, p_rc_open->rc_handle);
     bt_status_t result = BT_STATUS_SUCCESS;
-    int i;
-    char bd_str[18];
 #if (AVRC_CTLR_INCLUDED == TRUE)
     bt_bdaddr_t rc_addr;
 #endif
@@ -914,7 +908,6 @@
     tAVRC_RESPONSE *pmetamsg_resp)
 {
     UINT8 ctype;
-    tAVRC_STS status;
 
     if (!pmetamsg_resp)
     {
@@ -1088,9 +1081,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);
@@ -1250,7 +1267,6 @@
     uint32_t song_pos)
 {
     tAVRC_RESPONSE avrc_rsp;
-    UINT32 i;
     CHECK_RC_CONNECTED
     memset(&(avrc_rsp.get_play_status), 0, sizeof(tAVRC_GET_PLAY_STATUS_RSP));
     avrc_rsp.get_play_status.song_len = song_len;
@@ -1279,7 +1295,6 @@
 {
     tAVRC_RESPONSE avrc_rsp;
     UINT32 i;
-    uint8_t j;
     tAVRC_ATTR_ENTRY element_attrs[BTRC_MAX_ELEM_ATTR_SIZE];
     CHECK_RC_CONNECTED
     memset(element_attrs, 0, sizeof(tAVRC_ATTR_ENTRY) * num_attr);
@@ -1448,8 +1463,6 @@
     tAVRC_COMMAND avrc_cmd = {0};
     BT_HDR *p_msg = NULL;
     tAVRC_STS BldResp=AVRC_STS_BAD_CMD;
-    UINT16 rv = 0;
-    bt_status_t tran_status;
     rc_transaction_t *p_transaction=NULL;
 
     BTIF_TRACE_DEBUG("%s called with label:%d",__FUNCTION__,lbl);
@@ -1589,7 +1602,6 @@
                                                     key_code, key_state);
     if (btif_rc_cb.rc_features & BTA_AV_FEAT_RCTG)
     {
-        tAVRC_MSG_PASS avrc_cmd;
         bt_status_t tran_status = get_transaction(&p_transaction);
         if(BT_STATUS_SUCCESS == tran_status && NULL != p_transaction)
         {
diff --git a/btif/src/btif_sock_thread.c b/btif/src/btif_sock_thread.c
index 7e4e839..fc74089 100644
--- a/btif/src/btif_sock_thread.c
+++ b/btif/src/btif_sock_thread.c
@@ -94,7 +94,7 @@
     int poll_count;
     poll_slot_t ps[MAX_POLL];
     int psi[MAX_POLL]; //index of poll slot
-    volatile pid_t thread_id;
+    volatile pthread_t thread_id;
     btsock_signaled_cb callback;
     btsock_cmd_cb cmd_callback;
     int used;
@@ -108,70 +108,15 @@
 
 static inline void add_poll(int h, int fd, int type, int flags, uint32_t user_id);
 
-static pthread_mutex_t thread_slot_lock;
+static pthread_mutex_t thread_slot_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
 
-
-static inline void set_socket_blocking(int s, int blocking)
-{
-    int opts;
-    opts = fcntl(s, F_GETFL);
-    if (opts<0) APPL_TRACE_ERROR("set blocking (%s)", strerror(errno));
-    if(blocking)
-        opts &= ~O_NONBLOCK;
-    else opts |= O_NONBLOCK;
-    fcntl(s, F_SETFL, opts);
-}
-
-static inline int create_server_socket(const char* name)
-{
-    int s = socket(AF_LOCAL, SOCK_STREAM, 0);
-    APPL_TRACE_DEBUG("covert name to android abstract name:%s", name);
-    if(socket_local_server_bind(s, name, ANDROID_SOCKET_NAMESPACE_ABSTRACT) >= 0)
-    {
-        if(listen(s, 5) == 0)
-        {
-            APPL_TRACE_DEBUG("listen to local socket:%s, fd:%d", name, s);
-            return s;
-        }
-        else APPL_TRACE_ERROR("listen to local socket:%s, fd:%d failed, errno:%d", name, s, errno);
-    }
-    else APPL_TRACE_ERROR("create local socket:%s fd:%d, failed, errno:%d", name, s, errno);
-    close(s);
-    return -1;
-}
-static inline int connect_server_socket(const char* name)
-{
-    int s = socket(AF_LOCAL, SOCK_STREAM, 0);
-    set_socket_blocking(s, TRUE);
-    if(socket_local_client_connect(s, name, ANDROID_SOCKET_NAMESPACE_ABSTRACT, SOCK_STREAM) >= 0)
-    {
-        APPL_TRACE_DEBUG("connected to local socket:%s, fd:%d", name, s);
-        return s;
-    }
-    else APPL_TRACE_ERROR("connect to local socket:%s, fd:%d failed, errno:%d", name, s, errno);
-    close(s);
-    return -1;
-}
-static inline int accept_server_socket(int s)
-{
-    struct sockaddr_un client_address;
-    socklen_t clen;
-    int fd = accept(s, (struct sockaddr*)&client_address, &clen);
-    APPL_TRACE_DEBUG("accepted fd:%d for server fd:%d", fd, s);
-    return fd;
-}
-static inline pthread_t create_thread(void *(*start_routine)(void *), void * arg)
+static inline int create_thread(void *(*start_routine)(void *), void * arg,
+                                pthread_t * thread_id)
 {
     pthread_attr_t thread_attr;
     pthread_attr_init(&thread_attr);
     pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE);
-    pthread_t thread_id = -1;
-    if( pthread_create(&thread_id, &thread_attr, start_routine, arg)!=0 )
-    {
-        APPL_TRACE_ERROR("pthread_create : %s", strerror(errno));
-        return -1;
-    }
-    return thread_id;
+    return pthread_create(thread_id, &thread_attr, start_routine, arg);
 }
 static void init_poll(int cmd_fd);
 static int alloc_thread_slot()
@@ -206,7 +151,6 @@
     if(!initialized)
     {
         initialized = 1;
-        init_slot_lock(&thread_slot_lock);
         int h;
         for(h = 0; h < MAX_THREAD; h++)
         {
@@ -222,26 +166,27 @@
 }
 int btsock_thread_create(btsock_signaled_cb callback, btsock_cmd_cb cmd_callback)
 {
-    int ret = FALSE;
     asrt(callback || cmd_callback);
-    lock_slot(&thread_slot_lock);
+    pthread_mutex_lock(&thread_slot_lock);
     int h = alloc_thread_slot();
-    unlock_slot(&thread_slot_lock);
+    pthread_mutex_unlock(&thread_slot_lock);
     APPL_TRACE_DEBUG("alloc_thread_slot ret:%d", h);
     if(h >= 0)
     {
         init_poll(h);
-        if((ts[h].thread_id = create_thread(sock_poll_thread, (void*)(uintptr_t)h)) != -1)
+        pthread_t thread;
+        int status = create_thread(sock_poll_thread, (void*)(uintptr_t)h, &thread);
+        if (status)
         {
-            APPL_TRACE_DEBUG("h:%d, thread id:%d", h, ts[h].thread_id);
-            ts[h].callback = callback;
-            ts[h].cmd_callback = cmd_callback;
-        }
-        else
-        {
+            APPL_TRACE_ERROR("create_thread failed: %s", strerror(status));
             free_thread_slot(h);
-            h = -1;
+            return -1;
         }
+
+        ts[h].thread_id = thread;
+        APPL_TRACE_DEBUG("h:%d, thread id:%d", h, ts[h].thread_id);
+        ts[h].callback = callback;
+        ts[h].cmd_callback = cmd_callback;
     }
     return h;
 }
@@ -390,9 +335,9 @@
     if(send(ts[h].cmd_fdw, &cmd, sizeof(cmd), 0) == sizeof(cmd))
     {
         pthread_join(ts[h].thread_id, 0);
-        lock_slot(&thread_slot_lock);
+        pthread_mutex_lock(&thread_slot_lock);
         free_thread_slot(h);
-        unlock_slot(&thread_slot_lock);
+        pthread_mutex_unlock(&thread_slot_lock);
         return TRUE;
     }
     return FALSE;
diff --git a/btif/src/btif_storage.c b/btif/src/btif_storage.c
index c8e5264..2924a2a 100644
--- a/btif/src/btif_storage.c
+++ b/btif/src/btif_storage.c
@@ -434,7 +434,6 @@
 static bt_status_t btif_in_fetch_bonded_device(const char *bdstr)
 {
     BOOLEAN bt_linkkey_file_found=FALSE;
-    int device_type;
 
         LINK_KEY link_key;
         size_t size = sizeof(link_key);
@@ -574,7 +573,6 @@
     /* Special handling for adapter BD_ADDR and BONDED_DEVICES */
     if (property->type == BT_PROPERTY_BDADDR)
     {
-        BD_ADDR addr;
         bt_bdaddr_t *bd_addr = (bt_bdaddr_t*)property->val;
         /* This has been cached in btif. Just fetch it from there */
         memcpy(bd_addr, &btif_local_bd_addr, sizeof(bt_bdaddr_t));
@@ -818,7 +816,6 @@
 *******************************************************************************/
 bt_status_t btif_storage_load_bonded_devices(void)
 {
-    char *fname;
     btif_bonded_devices_t bonded_devices;
     uint32_t i = 0;
     bt_property_t adapter_props[6];
@@ -1402,7 +1399,6 @@
 {
     bt_bdaddr_t bd_addr;
     tBTA_HH_DEV_DSCP_INFO dscp_info;
-    uint32_t i;
     uint16_t attr_mask;
     uint8_t  sub_class;
     uint8_t  app_id;
@@ -1488,8 +1484,6 @@
 *******************************************************************************/
 bt_status_t btif_storage_remove_hid_info(bt_bdaddr_t *remote_bd_addr)
 {
-    char *fname;
-    int ret;
     bdstr_t bdstr;
     bdaddr_to_string(remote_bd_addr, bdstr, sizeof(bdstr));
 
@@ -1613,10 +1607,8 @@
 BOOLEAN  btif_storage_is_device_autopair_blacklisted(bt_bdaddr_t *remote_bd_addr)
 {
     char *token;
-    int ret;
     bdstr_t bdstr;
     char *dev_name_str;
-    uint8_t i = 0;
     char value[BTIF_STORAGE_MAX_LINE_SZ];
     int value_size = sizeof(value);
 
@@ -1718,10 +1710,7 @@
 *******************************************************************************/
 BOOLEAN btif_storage_is_fixed_pin_zeros_keyboard(bt_bdaddr_t *remote_bd_addr)
 {
-    int ret;
     bdstr_t bdstr;
-    char *dev_name_str;
-    uint8_t i = 0;
     char linebuf[BTIF_STORAGE_MAX_LINE_SZ];
 
     bdaddr_to_string(remote_bd_addr, bdstr, sizeof(bdstr));
diff --git a/gki/Android.mk b/gki/Android.mk
index 3268540..76f5790 100644
--- a/gki/Android.mk
+++ b/gki/Android.mk
@@ -20,7 +20,6 @@
 	-DBOARD_HAVE_BLUETOOTH_BCM
 endif
 
-LOCAL_PRELINK_MODULE := false
 LOCAL_SRC_FILES := \
 	./common/gki_buffer.c \
 	./ulinux/gki_ulinux.c
diff --git a/main/Android.mk b/main/Android.mk
index ffb2fef..631204b 100644
--- a/main/Android.mk
+++ b/main/Android.mk
@@ -151,4 +151,7 @@
 
 LOCAL_MULTILIB := 32
 
+LOCAL_CLANG_CFLAGS := -Wno-error=gnu-variable-sized-type-not-at-end
+LOCAL_CLANG_CFLAGS += -Wno-typedef-redefinition
+
 include $(BUILD_SHARED_LIBRARY)
diff --git a/osi/src/alarm.c b/osi/src/alarm.c
index 42c3da1..1ce58bc 100644
--- a/osi/src/alarm.c
+++ b/osi/src/alarm.c
@@ -22,6 +22,9 @@
 #include <errno.h>
 #include <hardware/bluetooth.h>
 #include <inttypes.h>
+#include <malloc.h>
+#include <string.h>
+#include <signal.h>
 #include <time.h>
 
 #include "osi/include/alarm.h"
diff --git a/osi/src/config.c b/osi/src/config.c
index 1944bb3..a98faa2 100644
--- a/osi/src/config.c
+++ b/osi/src/config.c
@@ -20,6 +20,7 @@
 
 #include <assert.h>
 #include <ctype.h>
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/osi/src/fixed_queue.c b/osi/src/fixed_queue.c
index 009e185..c83c516 100644
--- a/osi/src/fixed_queue.c
+++ b/osi/src/fixed_queue.c
@@ -27,7 +27,7 @@
 #include "osi/include/semaphore.h"
 #include "osi/include/reactor.h"
 
-typedef struct fixed_queue_t {
+struct fixed_queue_t {
   list_t *list;
   semaphore_t *enqueue_sem;
   semaphore_t *dequeue_sem;
diff --git a/osi/src/list.c b/osi/src/list.c
index a9701aa..75f948e 100644
--- a/osi/src/list.c
+++ b/osi/src/list.c
@@ -4,12 +4,12 @@
 #include "osi/include/list.h"
 #include "osi/include/osi.h"
 
-typedef struct list_node_t {
+struct list_node_t {
   struct list_node_t *next;
   void *data;
-} list_node_t;
+};
 
-typedef struct list_t {
+struct list_t {
   list_node_t *head;
   list_node_t *tail;
   size_t length;
diff --git a/osi/src/semaphore.c b/osi/src/semaphore.c
index b8dddcf..5ee9926 100644
--- a/osi/src/semaphore.c
+++ b/osi/src/semaphore.c
@@ -21,6 +21,7 @@
 #include <assert.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <malloc.h>
 #include <string.h>
 #include <sys/eventfd.h>
 
diff --git a/osi/src/thread.c b/osi/src/thread.c
index 1380755..98e93e8 100644
--- a/osi/src/thread.c
+++ b/osi/src/thread.c
@@ -20,6 +20,7 @@
 
 #include <assert.h>
 #include <errno.h>
+#include <malloc.h>
 #include <pthread.h>
 #include <string.h>
 #include <sys/prctl.h>
diff --git a/stack/Android.mk b/stack/Android.mk
index 9a48f62..518188e 100644
--- a/stack/Android.mk
+++ b/stack/Android.mk
@@ -43,7 +43,6 @@
 	-DBOARD_HAVE_BLUETOOTH_BCM
 endif
 
-LOCAL_PRELINK_MODULE:=false
 LOCAL_SRC_FILES:= \
     ./a2dp/a2d_api.c \
     ./a2dp/a2d_sbc.c \
@@ -161,5 +160,9 @@
 LOCAL_STATIC_LIBRARIES := libbt-hci
 LOCAL_SHARED_LIBRARIES := libcutils libc
 LOCAL_MULTILIB := 32
+# gnu-variable-sized-type-not-at-end is needed for a variable-size header in
+# a struct.
+# const-logical-operand is needed for code in l2c_utils.c that looks intentional.
+LOCAL_CLANG_CFLAGS += -Wno-error=gnu-variable-sized-type-not-at-end -Wno-error=constant-logical-operand
 
 include $(BUILD_STATIC_LIBRARY)
diff --git a/stack/avct/avct_lcb_act.c b/stack/avct/avct_lcb_act.c
index 3b28146..589af0b 100644
--- a/stack/avct/avct_lcb_act.c
+++ b/stack/avct/avct_lcb_act.c
@@ -89,17 +89,35 @@
             GKI_freebuf(p_lcb->p_rx_msg);
             AVCT_TRACE_WARNING("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_ERROR ("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 */
diff --git a/stack/avrc/avrc_pars_ct.c b/stack/avrc/avrc_pars_ct.c
index 143ce81..f268800 100644
--- a/stack/avrc/avrc_pars_ct.c
+++ b/stack/avrc/avrc_pars_ct.c
@@ -45,14 +45,6 @@
     tAVRC_STS  status = AVRC_STS_NO_ERROR;
     UINT8   *p = p_msg->p_vendor_data;
     UINT16  len;
-    UINT8   xx, yy;
-    tAVRC_NOTIF_RSP_PARAM   *p_param;
-    tAVRC_APP_SETTING       *p_app_set;
-    tAVRC_APP_SETTING_TEXT  *p_app_txt;
-    tAVRC_ATTR_ENTRY        *p_entry;
-    UINT32  *p_u32;
-    UINT8   *p_u8;
-    UINT16  size_needed;
     UINT8 eventid=0;
 
     BE_STREAM_TO_UINT8 (p_result->pdu, p);
diff --git a/stack/btm/btm_acl.c b/stack/btm/btm_acl.c
index 0b7204b..ba3e94b 100644
--- a/stack/btm/btm_acl.c
+++ b/stack/btm/btm_acl.c
@@ -204,7 +204,6 @@
                       UINT16 hci_handle, UINT8 link_role, tBT_TRANSPORT transport)
 {
     tBTM_SEC_DEV_REC *p_dev_rec = NULL;
-    UINT8             yy;
     tACL_CONN        *p;
     UINT8             xx;
 
@@ -1631,8 +1630,6 @@
 
 BOOLEAN BTM_TryAllocateSCN(UINT8 scn)
 {
-    UINT8   x;
-
     /* Make sure we don't exceed max port range.
      * Stack reserves scn 1 for HFP, HSP we still do the correct way.
      */
diff --git a/stack/btm/btm_ble.c b/stack/btm/btm_ble.c
index c69c0be..d28f6f2 100644
--- a/stack/btm/btm_ble.c
+++ b/stack/btm/btm_ble.c
@@ -694,7 +694,6 @@
 void btm_ble_test_command_complete(UINT8 *p)
 {
     tBTM_CMPL_CB   *p_cb = btm_cb.devcb.p_le_test_cmd_cmpl_cb;
-    UINT8           status;
 
     btm_cb.devcb.p_le_test_cmd_cmpl_cb = NULL;
 
diff --git a/stack/btm/btm_ble_batchscan.c b/stack/btm/btm_ble_batchscan.c
index 4e06299..7ed61dc 100644
--- a/stack/btm/btm_ble_batchscan.c
+++ b/stack/btm/btm_ble_batchscan.c
@@ -319,7 +319,6 @@
     UINT8  *p = p_params->p_param_buf;
     UINT16  len = p_params->param_len;
     tBTM_BLE_REF_VALUE ref_value = 0;
-    int index = 0;
 
     UINT8  status = 0, subcode = 0, opcode = 0;
     UINT8 report_format = 0, num_records = 0, cb_evt = 0;
@@ -802,7 +801,7 @@
     tBTM_STATUS     status = BTM_NO_RESOURCES;
     tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
     UINT8 read_scan_mode = 0;
-    UINT8  *p_data = NULL, report_format = 0, num_records = 0;
+    UINT8  *p_data = NULL, num_records = 0;
     UINT16 data_len = 0;
 
     BTM_TRACE_EVENT (" BTM_BleReadScanReports; %d, %d", scan_mode, ref_value);
diff --git a/stack/btm/btm_ble_gap.c b/stack/btm/btm_ble_gap.c
index 0776d41..c3b140e 100644
--- a/stack/btm/btm_ble_gap.c
+++ b/stack/btm/btm_ble_gap.c
@@ -55,8 +55,9 @@
 #define BTM_EXT_BLE_RMT_NAME_TIMEOUT        30
 #define MIN_ADV_LENGTH                       2
 
-static tBTM_BLE_VSC_CB cmn_ble_vsc_cb;
+#if BLE_VND_INCLUDED == TRUE
 static tBTM_BLE_CTRL_FEATURES_CBACK    *p_ctrl_le_feature_rd_cmpl_cback = NULL;
+#endif
 
 /*******************************************************************************
 **  Local functions
@@ -423,6 +424,7 @@
     return status;
 }
 
+#if BLE_VND_INCLUDED == TRUE
 /*******************************************************************************
 **
 ** Function         btm_vsc_brcm_features_complete
@@ -434,7 +436,6 @@
 *******************************************************************************/
 static void btm_ble_vendor_capability_vsc_cmpl_cback (tBTM_VSC_CMPL *p_vcs_cplt_params)
 {
-#if BLE_VND_INCLUDED == TRUE
     UINT8  status = 0xFF, *p;
 
     BTM_TRACE_DEBUG("btm_ble_vendor_capability_vsc_cmpl_cback");
@@ -480,11 +481,8 @@
 
     if (p_ctrl_le_feature_rd_cmpl_cback != NULL)
         p_ctrl_le_feature_rd_cmpl_cback(status);
-
-#else
-    UNUSED(p_vcs_cplt_params);
-#endif
 }
+#endif
 
 /*******************************************************************************
 **
@@ -3109,8 +3107,6 @@
 BOOLEAN btm_ble_topology_check(tBTM_BLE_STATE_MASK request_state_mask)
 {
     BOOLEAN rt = FALSE;
-    UINT32  llt_mask = 0;
-    UINT8   *p;
 
     UINT8   state_offset = 0;
     UINT16  cur_states = btm_cb.ble_ctr_cb.cur_states;
diff --git a/stack/btm/btm_ble_multi_adv.c b/stack/btm/btm_ble_multi_adv.c
index e3eadca..0ad97c4 100644
--- a/stack/btm/btm_ble_multi_adv.c
+++ b/stack/btm/btm_ble_multi_adv.c
@@ -368,7 +368,6 @@
 void btm_ble_multi_adv_gen_rpa_cmpl(tBTM_RAND_ENC *p)
 {
 #if (SMP_INCLUDED == TRUE)
-    tBTM_LE_RANDOM_CB *p_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb;
     tSMP_ENC    output;
     UINT8 index = 0;
     tBTM_BLE_MULTI_ADV_INST *p_inst = NULL;
diff --git a/stack/btm/btm_inq.c b/stack/btm/btm_inq.c
index 2307051..5311436 100644
--- a/stack/btm/btm_inq.c
+++ b/stack/btm/btm_inq.c
@@ -2357,7 +2357,7 @@
          /* Note: If part of the inquiry, the name is not stored, and the    */
          /*       inquiry complete callback is called.                       */
 
-        if ((hci_status == HCI_SUCCESS))
+        if (hci_status == HCI_SUCCESS)
         {
             /* Copy the name from the data stream into the return structure */
             /* Note that even if it is not being returned, it is used as a  */
diff --git a/stack/btm/btm_sec.c b/stack/btm/btm_sec.c
index af76151..68eecc5 100644
--- a/stack/btm/btm_sec.c
+++ b/stack/btm/btm_sec.c
@@ -5369,7 +5369,7 @@
 
     return("???");
 #else
-    sprintf(btm_cb.state_temp_buffer,"%hu",state);
+    sprintf(btm_cb.state_temp_buffer,"%hhu",state);
 
     return(btm_cb.state_temp_buffer);
 #endif
diff --git a/stack/gatt/gatt_sr.c b/stack/gatt/gatt_sr.c
index 5f9ddf0..ecf2427 100755
--- a/stack/gatt/gatt_sr.c
+++ b/stack/gatt/gatt_sr.c
@@ -123,7 +123,7 @@
 static BOOLEAN process_read_multi_rsp (tGATT_SR_CMD *p_cmd, tGATT_STATUS status,
                                        tGATTS_RSP *p_msg, UINT16 mtu)
 {
-    tGATTS_RSP       *p_rsp;
+    tGATTS_RSP       *p_rsp = NULL;
     UINT16          ii, total_len, len;
     BT_HDR          *p_buf = (BT_HDR *)GKI_getbuf((UINT16)sizeof(tGATTS_RSP));
     UINT8           *p;
@@ -332,7 +332,6 @@
 {
     UINT8   *p = p_data, flag, i = 0;
     UINT32  trans_id = 0;
-    BT_HDR  *p_buf;
     tGATT_IF gatt_if;
     UINT16  conn_id;
 
diff --git a/stack/l2cap/l2c_api.c b/stack/l2cap/l2c_api.c
index f717b1e..667f717 100644
--- a/stack/l2cap/l2c_api.c
+++ b/stack/l2cap/l2c_api.c
@@ -1380,7 +1380,6 @@
 {
     tL2C_LCB        *p_lcb;
     tBT_TRANSPORT   transport = BT_TRANSPORT_BR_EDR;
-    UINT16          reason;
 
     L2CAP_TRACE_API  ("L2CA_ConnectFixedChnl()  CID: 0x%04x  BDA: %08x%04x", fixed_cid,
                     (rem_bda[0]<<24)+(rem_bda[1]<<16)+(rem_bda[2]<<8)+rem_bda[3], (rem_bda[4]<<8)+rem_bda[5]);
diff --git a/stack/l2cap/l2c_main.c b/stack/l2cap/l2c_main.c
index 02f12a7..8da881c 100755
--- a/stack/l2cap/l2c_main.c
+++ b/stack/l2cap/l2c_main.c
@@ -322,7 +322,7 @@
     tL2CAP_CFG_INFO cfg_info;
     UINT16          rej_reason, rej_mtu, lcid, rcid, info_type;
     tL2C_CCB        *p_ccb;
-    tL2C_RCB        *p_rcb, *p_rcb2;
+    tL2C_RCB        *p_rcb;
     BOOLEAN         cfg_rej, pkt_size_rej = FALSE;
     UINT16          cfg_rej_len, cmd_len;
     UINT16          result;
diff --git a/stack/mcap/mca_dact.c b/stack/mcap/mca_dact.c
index d147c39..acd8cc0 100644
--- a/stack/mcap/mca_dact.c
+++ b/stack/mcap/mca_dact.c
@@ -22,6 +22,9 @@
  *  Functions.
  *
  ******************************************************************************/
+
+#include <stddef.h>
+
 #include "bt_target.h"
 #include "bt_utils.h"
 #include "gki.h"
diff --git a/stack/pan/pan_utils.c b/stack/pan/pan_utils.c
index 7a550fa..3c1f8b3 100644
--- a/stack/pan/pan_utils.c
+++ b/stack/pan/pan_utils.c
@@ -63,7 +63,6 @@
     UINT32  sdp_handle;
     UINT16  browse_list = UUID_SERVCLASS_PUBLIC_BROWSE_GROUP;
     UINT16  security = 0;
-    UINT8   availability;
     UINT32  proto_len = (UINT32)pan_proto_elem_data[1];
 
     /* Create a record */
diff --git a/stack/rfcomm/port_api.c b/stack/rfcomm/port_api.c
index f1225c0..3f38a71 100644
--- a/stack/rfcomm/port_api.c
+++ b/stack/rfcomm/port_api.c
@@ -1523,7 +1523,6 @@
     UINT16     length;
 
     RFCOMM_TRACE_API ("PORT_WriteDataCO() handle:%d", handle);
-    int written;
     *p_len = 0;
 
     /* Check if handle is valid to avoid crashing */
diff --git a/stack/rfcomm/rfc_l2cap_if.c b/stack/rfcomm/rfc_l2cap_if.c
index ffcbfe9..087e73a 100644
--- a/stack/rfcomm/rfc_l2cap_if.c
+++ b/stack/rfcomm/rfc_l2cap_if.c
@@ -22,6 +22,8 @@
  *
  ******************************************************************************/
 
+#include <stddef.h>
+
 #include "bt_target.h"
 #include "btcore/include/counter.h"
 #include "gki.h"
diff --git a/stack/rfcomm/rfc_ts_frames.c b/stack/rfcomm/rfc_ts_frames.c
index 11fbae8..9b3cdca 100644
--- a/stack/rfcomm/rfc_ts_frames.c
+++ b/stack/rfcomm/rfc_ts_frames.c
@@ -21,6 +21,9 @@
  *  This file contains functions to send TS 07.10 frames
  *
  ******************************************************************************/
+
+#include <stddef.h>
+
 #include "bt_target.h"
 #include "btcore/include/counter.h"
 #include "gki.h"
diff --git a/stack/sdp/sdp_api.c b/stack/sdp/sdp_api.c
index 890f808..6e84ded 100644
--- a/stack/sdp/sdp_api.c
+++ b/stack/sdp/sdp_api.c
@@ -425,7 +425,7 @@
 BOOLEAN SDP_FindServiceUUIDInRec_128bit(tSDP_DISC_REC *p_rec, tBT_UUID * p_uuid)
 {
 #if SDP_CLIENT_ENABLED == TRUE
-    tSDP_DISC_ATTR  *p_attr, *p_sattr, *p_extra_sattr;
+    tSDP_DISC_ATTR  *p_attr, *p_sattr;
 
     p_attr = p_rec->p_first_attr;
 
@@ -590,7 +590,7 @@
 {
 #if SDP_CLIENT_ENABLED == TRUE
     tSDP_DISC_REC   *p_rec;
-    tSDP_DISC_ATTR  *p_attr, *p_sattr, *p_extra_sattr;
+    tSDP_DISC_ATTR  *p_attr, *p_sattr;
 
     /* Must have a valid database */
     if (p_db == NULL)
diff --git a/stack/sdp/sdp_discovery.c b/stack/sdp/sdp_discovery.c
index c56459d..646a62d 100644
--- a/stack/sdp/sdp_discovery.c
+++ b/stack/sdp/sdp_discovery.c
@@ -352,7 +352,6 @@
     UINT32          list_len;
     UINT8           *p;
     UINT8           type;
-    UINT32          delta_len = 0;
 
 #if (SDP_DEBUG_RAW == TRUE)
     UINT8 num_array[SDP_MAX_LIST_BYTE_COUNT];
diff --git a/stack/smp/smp_keys.c b/stack/smp/smp_keys.c
index 31313c9..ec7d129 100644
--- a/stack/smp/smp_keys.c
+++ b/stack/smp/smp_keys.c
@@ -53,21 +53,6 @@
 static void smp_process_compare(tSMP_CB *p_cb, tSMP_ENC *p);
 static void smp_process_ediv(tSMP_CB *p_cb, tSMP_ENC *p);
 
-static const tSMP_ACT smp_encrypt_action[] =
-{
-    smp_generate_compare,           /* SMP_GEN_COMPARE */
-    smp_genenrate_confirm,          /* SMP_GEN_CONFIRM*/
-    smp_generate_stk,               /* SMP_GEN_STK*/
-    smp_genenrate_ltk_cont,          /* SMP_GEN_LTK */
-    smp_generate_ltk,               /* SMP_GEN_DIV_LTK */
-    smp_generate_rand_vector,        /* SMP_GEN_RAND_V */
-    smp_generate_y,                  /* SMP_GEN_EDIV */
-    smp_generate_passkey,           /* SMP_GEN_TK */
-    smp_generate_confirm,           /* SMP_GEN_SRAND_MRAND */
-    smp_genenrate_rand_cont         /* SMP_GEN_SRAND_MRAND_CONT */
-};
-
-
     #define SMP_PASSKEY_MASK    0xfff00000
 
     #if SMP_DEBUG == TRUE
diff --git a/test/suite/base.h b/test/suite/base.h
index 0aa7979..935ff17 100644
--- a/test/suite/base.h
+++ b/test/suite/base.h
@@ -18,6 +18,7 @@
 
 #pragma once
 
+#include <malloc.h>
 #include <stdio.h>
 #include <stdbool.h>
 #include <string.h>
diff --git a/udrv/ulinux/uipc.c b/udrv/ulinux/uipc.c
index 7619d2c..0143826 100644
--- a/udrv/ulinux/uipc.c
+++ b/udrv/ulinux/uipc.c
@@ -210,7 +210,9 @@
 static int uipc_main_init(void)
 {
     int i;
-    const pthread_mutexattr_t attr = PTHREAD_MUTEX_RECURSIVE;
+    pthread_mutexattr_t attr;
+    pthread_mutexattr_init(&attr);
+    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
     pthread_mutex_init(&uipc_main.mutex, &attr);
 
     BTIF_TRACE_EVENT("### uipc_main_init ###");
@@ -702,7 +704,6 @@
 BOOLEAN UIPC_Send(tUIPC_CH_ID ch_id, UINT16 msg_evt, UINT8 *p_buf,
         UINT16 msglen)
 {
-    int n;
     UNUSED(msg_evt);
 
     BTIF_TRACE_DEBUG("UIPC_Send : ch_id:%d %d bytes", ch_id, msglen);
diff --git a/utils/Android.mk b/utils/Android.mk
index 6425802..8e3fe39 100644
--- a/utils/Android.mk
+++ b/utils/Android.mk
@@ -12,7 +12,6 @@
 
 LOCAL_CFLAGS += $(bdroid_CFLAGS) -std=c99
 
-LOCAL_PRELINK_MODULE :=false
 LOCAL_SRC_FILES := \
 	./src/bt_utils.c
 
diff --git a/vnd/ble/vendor_ble.c b/vnd/ble/vendor_ble.c
index 72c50b3..c23d0bc 100644
--- a/vnd/ble/vendor_ble.c
+++ b/vnd/ble/vendor_ble.c
@@ -40,8 +40,6 @@
 tBTM_BLE_VENDOR_CB  btm_ble_vendor_cb;
 #endif
 
-static const BD_ADDR     na_bda= {0};
-
 /*******************************************************************************
 **         Resolve Address Using IRK List functions
 *******************************************************************************/
@@ -664,7 +662,6 @@
 #if BLE_PRIVACY_SPT == TRUE
     UINT8           param[20], *p;
     tBTM_STATUS     st = BTM_WRONG_MODE;
-    tBTM_BLE_PF_COUNT *p_bda_filter;
 
     if (btm_cb.cmn_ble_vsc_cb.max_irk_list_sz == 0)
         return BTM_MODE_UNSUPPORTED;