From 59c6af158dbc40c703cd6422bc90ce91f2efa168 Mon Sep 17 00:00:00 2001
From: Matthias Ringwald <matthias@ringwald.ch>
Date: Mon, 28 Mar 2016 12:45:43 +0200
Subject: [PATCH] add classic/core.h and ble/core.h, add ENABLE_CLASSIC where
 missing

---
 port/ios/btstack_config.h                |  1 +
 src/ble/ancs_client.c                    |  1 +
 src/ble/att_db.c                         |  1 +
 src/ble/att_db_util.c                    |  1 +
 src/ble/att_dispatch.c                   |  4 +-
 src/ble/att_server.c                     | 15 ++++---
 src/ble/core.h                           | 51 ++++++++++++++++++++++++
 src/ble/gatt_client.c                    |  1 +
 src/ble/le_device_db_dummy.c             |  1 +
 src/ble/le_device_db_memory.c            |  2 +
 src/ble/sm.c                             |  1 +
 src/classic/bnep.c                       |  1 +
 src/classic/btstack_link_key_db_memory.c |  1 +
 src/classic/core.h                       | 51 ++++++++++++++++++++++++
 src/classic/hfp.c                        | 16 ++++----
 src/classic/hfp_ag.c                     |  1 +
 src/classic/hfp_gsm_model.c              |  1 +
 src/classic/hfp_hf.c                     | 19 +++++----
 src/classic/hsp_ag.c                     |  1 +
 src/classic/hsp_hs.c                     |  1 +
 src/classic/pan.c                        |  3 +-
 src/classic/rfcomm.c                     |  1 +
 src/classic/sdp_client.c                 | 11 +++--
 src/classic/sdp_client_rfcomm.c          |  1 +
 src/classic/sdp_server.c                 |  8 ++--
 src/classic/sdp_util.c                   |  7 ++--
 src/classic/spp_server.c                 |  2 +
 27 files changed, 161 insertions(+), 43 deletions(-)
 create mode 100644 src/ble/core.h
 create mode 100644 src/classic/core.h

diff --git a/port/ios/btstack_config.h b/port/ios/btstack_config.h
index 20fd52a0a..85e4f9b04 100644
--- a/port/ios/btstack_config.h
+++ b/port/ios/btstack_config.h
@@ -13,6 +13,7 @@
 #define HAVE_TIME
 
 // BTstack features that can be enabled
+#define ENABLE_CLASSIC
 #define ENABLE_LOG_ERROR
 #define ENABLE_LOG_INFO 
 #define ENABLE_LOG_INTO_HCI_DUMP
diff --git a/src/ble/ancs_client.c b/src/ble/ancs_client.c
index d1729866c..fee69dbed 100644
--- a/src/ble/ancs_client.c
+++ b/src/ble/ancs_client.c
@@ -45,6 +45,7 @@
 #include "ancs_client.h"
 
 #include "ble/att_db.h"
+#include "ble/core.h"
 #include "ble/gatt_client.h"
 #include "ble/sm.h"
 #include "btstack_debug.h"
diff --git a/src/ble/att_db.c b/src/ble/att_db.c
index 6818f7d2f..fe1465768 100644
--- a/src/ble/att_db.c
+++ b/src/ble/att_db.c
@@ -41,6 +41,7 @@
 
 #include "bluetooth.h"
 #include "ble/att_db.h"
+#include "ble/core.h"
 #include "btstack_debug.h"
 #include "btstack_util.h"
 
diff --git a/src/ble/att_db_util.c b/src/ble/att_db_util.c
index 1e779632a..6715b3e9e 100644
--- a/src/ble/att_db_util.c
+++ b/src/ble/att_db_util.c
@@ -40,6 +40,7 @@
 
 #include "att_db_util.h"
 #include "ble/att_db.h"
+#include "ble/core.h"
 #include "btstack_util.h"
 #include "btstack_debug.h"
 #include "bluetooth.h"
diff --git a/src/ble/att_dispatch.c b/src/ble/att_dispatch.c
index 7d390bc36..ec89ceb27 100644
--- a/src/ble/att_dispatch.c
+++ b/src/ble/att_dispatch.c
@@ -40,10 +40,10 @@
  * Dispatcher for independent implementation of ATT client and server
  */
 
-#include "l2cap.h"
-
 #include "att_dispatch.h"
+#include "ble/core.h"
 #include "btstack_debug.h"
+#include "l2cap.h"
 
 static btstack_packet_handler_t att_client_handler;
 static btstack_packet_handler_t att_server_handler;
diff --git a/src/ble/att_server.c b/src/ble/att_server.c
index 08946391c..2fe05d691 100644
--- a/src/ble/att_server.c
+++ b/src/ble/att_server.c
@@ -48,22 +48,21 @@
 
 #include "btstack_config.h"
 
+#include "att_dispatch.h"
+#include "ble/att_db.h"
+#include "ble/att_server.h"
+#include "ble/core.h"
+#include "ble/le_device_db.h"
+#include "ble/sm.h"
 #include "btstack_debug.h"
 #include "btstack_event.h"
 #include "btstack_memory.h"
 #include "btstack_run_loop.h"
+#include "gap.h"
 #include "hci.h"
 #include "hci_dump.h"
 #include "l2cap.h"
 
-#include "ble/sm.h"
-#include "ble/att_db.h"
-#include "att_dispatch.h"
-#include "gap.h"
-#include "ble/le_device_db.h"
-
-#include "ble/att_server.h"
-
 static void att_run(void);
 
 // max ATT request matches L2CAP PDU -- allow to use smaller buffer
diff --git a/src/ble/core.h b/src/ble/core.h
new file mode 100644
index 000000000..65e8c9ba1
--- /dev/null
+++ b/src/ble/core.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2014 BlueKitchen GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holders nor the names of
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ * 4. Any redistribution, use, or modification is done solely for
+ *    personal benefit and not for any commercial purpose or for
+ *    monetary gain.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
+ * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Please inquire about commercial licensing options at 
+ * contact@bluekitchen-gmbh.com
+ *
+ */
+
+// *****************************************************************************
+//  Core header for all BLE protocols and profiles
+// *****************************************************************************
+
+#ifndef __BLE_CORE
+#define __BLE_CORE
+
+#include "btstack_config.h"
+
+#ifndef ENABLE_BLE
+#error "ENABLE_BLE not defined but Classic protocol or profile include. Please add ENABLE_BLE in btstack_config.h, or remove all Classic protocols and profiles"
+#endif
+
+#endif
diff --git a/src/ble/gatt_client.c b/src/ble/gatt_client.c
index c703c28e0..d30dd49d4 100644
--- a/src/ble/gatt_client.c
+++ b/src/ble/gatt_client.c
@@ -45,6 +45,7 @@
 #include "att_dispatch.h"
 #include "ble/ad_parser.h"
 #include "ble/att_db.h"
+#include "ble/core.h"
 #include "ble/gatt_client.h"
 #include "ble/le_device_db.h"
 #include "ble/sm.h"
diff --git a/src/ble/le_device_db_dummy.c b/src/ble/le_device_db_dummy.c
index c2eaf1680..b3cca8a40 100644
--- a/src/ble/le_device_db_dummy.c
+++ b/src/ble/le_device_db_dummy.c
@@ -35,6 +35,7 @@
  *
  */
 #include  "le_device_db.h"
+#include "ble/core.h"
 
  // Central Device db interface
 void le_device_db_init(void){}
diff --git a/src/ble/le_device_db_memory.c b/src/ble/le_device_db_memory.c
index e5f0a40a6..61e5540cb 100644
--- a/src/ble/le_device_db_memory.c
+++ b/src/ble/le_device_db_memory.c
@@ -37,6 +37,8 @@
  
 #include "ble/le_device_db.h"
 
+#include "ble/core.h"
+
 #include <stdio.h>
 #include <string.h>
 #include "btstack_debug.h"
diff --git a/src/ble/sm.c b/src/ble/sm.c
index b66687489..6358de42c 100644
--- a/src/ble/sm.c
+++ b/src/ble/sm.c
@@ -40,6 +40,7 @@
 #include <inttypes.h>
 
 #include "ble/le_device_db.h"
+#include "ble/core.h"
 #include "ble/sm.h"
 #include "btstack_debug.h"
 #include "btstack_event.h"
diff --git a/src/classic/bnep.c b/src/classic/bnep.c
index 29eaa953b..2fdf9686d 100644
--- a/src/classic/bnep.c
+++ b/src/classic/bnep.c
@@ -51,6 +51,7 @@
 #include "btstack_event.h"
 #include "btstack_memory.h"
 #include "btstack_util.h"
+#include "classic/core.h"
 #include "classic/sdp_util.h"
 #include "hci.h"
 #include "hci_cmd.h"
diff --git a/src/classic/btstack_link_key_db_memory.c b/src/classic/btstack_link_key_db_memory.c
index 31a49a735..4ee153884 100644
--- a/src/classic/btstack_link_key_db_memory.c
+++ b/src/classic/btstack_link_key_db_memory.c
@@ -44,6 +44,7 @@
 #include "btstack_linked_list.h"
 #include "btstack_memory.h"
 #include "btstack_util.h"
+#include "classic/core.h"
 
 // This list should be directly accessed only by tests
 btstack_linked_list_t db_mem_link_keys = NULL;
diff --git a/src/classic/core.h b/src/classic/core.h
new file mode 100644
index 000000000..36dc136a5
--- /dev/null
+++ b/src/classic/core.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2014 BlueKitchen GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holders nor the names of
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ * 4. Any redistribution, use, or modification is done solely for
+ *    personal benefit and not for any commercial purpose or for
+ *    monetary gain.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
+ * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Please inquire about commercial licensing options at 
+ * contact@bluekitchen-gmbh.com
+ *
+ */
+
+// *****************************************************************************
+//  Core header for all Classic protocols and profiles
+// *****************************************************************************
+
+#ifndef __CLASSIC_CORE
+#define __CLASSIC_CORE
+
+#include "btstack_config.h"
+
+#ifndef ENABLE_CLASSIC
+#error "ENABLE_CLASSIC not defined but Classic protocol or profile include. Please add ENABLE_CLASSIC in btstack_config.h, or remove all Classic protocols and profiles"
+#endif
+
+#endif
diff --git a/src/classic/hfp.c b/src/classic/hfp.c
index 09d133ba2..83c4e9b50 100644
--- a/src/classic/hfp.c
+++ b/src/classic/hfp.c
@@ -44,18 +44,18 @@
 #include <string.h>
 #include <inttypes.h>
 
-#include "hci_cmd.h"
-#include "btstack_run_loop.h"
-
-#include "hci.h"
-#include "btstack_memory.h"
-#include "hci_dump.h"
-#include "l2cap.h"
 #include "btstack_debug.h"
+#include "btstack_event.h"
+#include "btstack_memory.h"
+#include "btstack_run_loop.h"
+#include "classic/core.h"
 #include "classic/sdp_client_rfcomm.h"
 #include "classic/sdp_server.h"
 #include "classic/sdp_util.h"
-#include "btstack_event.h"
+#include "hci.h"
+#include "hci_cmd.h"
+#include "hci_dump.h"
+#include "l2cap.h"
 
 #define HFP_HF_FEATURES_SIZE 10
 #define HFP_AG_FEATURES_SIZE 12
diff --git a/src/classic/hfp_ag.c b/src/classic/hfp_ag.c
index 756bf6559..17f9bfc83 100644
--- a/src/classic/hfp_ag.c
+++ b/src/classic/hfp_ag.c
@@ -56,6 +56,7 @@
 #include "hci_dump.h"
 #include "l2cap.h"
 #include "btstack_debug.h"
+#include "classic/core.h"
 #include "classic/hfp.h"
 #include "classic/hfp_ag.h"
 #include "classic/hfp_gsm_model.h"
diff --git a/src/classic/hfp_gsm_model.c b/src/classic/hfp_gsm_model.c
index e2bc6d096..13ebc2106 100644
--- a/src/classic/hfp_gsm_model.c
+++ b/src/classic/hfp_gsm_model.c
@@ -49,6 +49,7 @@
 #include <string.h>
 
 #include "btstack_memory.h"
+#include "classic/core.h"
 #include "classic/hfp.h"
 #include "classic/hfp_gsm_model.h"
 #include "classic/sdp_server.h"
diff --git a/src/classic/hfp_hf.c b/src/classic/hfp_hf.c
index 8fb20cebf..6991c96e9 100644
--- a/src/classic/hfp_hf.c
+++ b/src/classic/hfp_hf.c
@@ -48,20 +48,19 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "hci_cmd.h"
-#include "btstack_run_loop.h"
-
-#include "hci.h"
+#include "btstack_debug.h"
 #include "btstack_memory.h"
-#include "hci_dump.h"
-#include "l2cap.h"
+#include "btstack_run_loop.h"
+#include "classic/core.h"
+#include "classic/hfp.h"
+#include "classic/hfp_hf.h"
 #include "classic/sdp_client_rfcomm.h"
 #include "classic/sdp_server.h"
 #include "classic/sdp_util.h"
-#include "btstack_debug.h"
-#include "classic/hfp.h"
-#include "classic/hfp_hf.h"
-
+#include "hci.h"
+#include "hci_cmd.h"
+#include "hci_dump.h"
+#include "l2cap.h"
 
 static const char default_hfp_hf_service_name[] = "Hands-Free unit";
 static uint16_t hfp_supported_features = HFP_DEFAULT_HF_SUPPORTED_FEATURES;
diff --git a/src/classic/hsp_ag.c b/src/classic/hsp_ag.c
index be3ddb9f9..9c8f82eeb 100644
--- a/src/classic/hsp_ag.c
+++ b/src/classic/hsp_ag.c
@@ -52,6 +52,7 @@
 #include "btstack_event.h"
 #include "btstack_memory.h"
 #include "btstack_run_loop.h"
+#include "classic/core.h"
 #include "classic/sdp_server.h"
 #include "classic/sdp_client_rfcomm.h"
 #include "classic/sdp_util.h"
diff --git a/src/classic/hsp_hs.c b/src/classic/hsp_hs.c
index 8d32360b0..8bc39db3f 100644
--- a/src/classic/hsp_hs.c
+++ b/src/classic/hsp_hs.c
@@ -52,6 +52,7 @@
 #include "btstack_event.h"
 #include "btstack_memory.h"
 #include "btstack_run_loop.h"
+#include "classic/core.h"
 #include "classic/sdp_server.h"
 #include "classic/sdp_client_rfcomm.h"
 #include "classic/sdp_util.h"
diff --git a/src/classic/pan.c b/src/classic/pan.c
index 199e51b89..d662abfe3 100644
--- a/src/classic/pan.c
+++ b/src/classic/pan.c
@@ -47,9 +47,8 @@
 #include <string.h>
 
 #include "btstack_config.h"
-
+#include "classic/core.h"
 #include "classic/sdp_util.h"
-#include "hci_cmd.h"
 
 static const char default_panu_service_name[] = "Personal Ad-hoc User Service";
 static const char default_panu_service_desc[] = "Personal Ad-hoc User Service";
diff --git a/src/classic/rfcomm.c b/src/classic/rfcomm.c
index e7e6068d7..ab666437a 100644
--- a/src/classic/rfcomm.c
+++ b/src/classic/rfcomm.c
@@ -48,6 +48,7 @@
 #include "btstack_event.h"
 #include "btstack_memory.h"
 #include "btstack_util.h"
+#include "classic/core.h"
 #include "classic/rfcomm.h"
 #include "hci.h"
 #include "hci_cmd.h"
diff --git a/src/classic/sdp_client.c b/src/classic/sdp_client.c
index 96297f2ad..e0542591b 100644
--- a/src/classic/sdp_client.c
+++ b/src/classic/sdp_client.c
@@ -40,15 +40,14 @@
  */
 
 #include "btstack_config.h"
-#include "classic/sdp_client.h"
-
-#include "hci_cmd.h"
-
+#include "btstack_debug.h"
 #include "btstack_event.h"
-#include "l2cap.h"
+#include "classic/core.h"
+#include "classic/sdp_client.h"
 #include "classic/sdp_server.h"
 #include "classic/sdp_util.h"
-#include "btstack_debug.h"
+#include "hci_cmd.h"
+#include "l2cap.h"
 
 // Types SDP Parser - Data Element stream helper
 typedef enum { 
diff --git a/src/classic/sdp_client_rfcomm.c b/src/classic/sdp_client_rfcomm.c
index dc2905b24..5c3b43212 100644
--- a/src/classic/sdp_client_rfcomm.c
+++ b/src/classic/sdp_client_rfcomm.c
@@ -46,6 +46,7 @@
 
 #include "btstack_debug.h"
 #include "btstack_event.h"
+#include "classic/core.h"
 #include "classic/sdp_client.h"
 #include "classic/sdp_client_rfcomm.h"
 #include "classic/sdp_util.h"
diff --git a/src/classic/sdp_server.c b/src/classic/sdp_server.c
index 3d028dbce..d559ae132 100644
--- a/src/classic/sdp_server.c
+++ b/src/classic/sdp_server.c
@@ -42,14 +42,14 @@
 #include <stdio.h>
 #include <string.h>
 
-#include "btstack_memory.h"
 #include "btstack_debug.h"
 #include "btstack_event.h"
-#include "hci_dump.h"
-#include "l2cap.h"
-
+#include "btstack_memory.h"
+#include "classic/core.h"
 #include "classic/sdp_server.h"
 #include "classic/sdp_util.h"
+#include "hci_dump.h"
+#include "l2cap.h"
 
 // max reserved ServiceRecordHandle
 #define maxReservedServiceRecordHandle 0xffff
diff --git a/src/classic/sdp_util.c b/src/classic/sdp_util.c
index ad4b7c92b..0281da251 100644
--- a/src/classic/sdp_util.c
+++ b/src/classic/sdp_util.c
@@ -39,10 +39,11 @@
  *  sdp_util.c
  */
 
-#include "classic/sdp_util.h"
-#include "btstack_util.h"
-#include "btstack_config.h"
 #include "bluetooth.h"
+#include "btstack_config.h"
+#include "btstack_util.h"
+#include "classic/core.h"
+#include "classic/sdp_util.h"
  
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/src/classic/spp_server.c b/src/classic/spp_server.c
index 461d414eb..3f73bd0d6 100644
--- a/src/classic/spp_server.c
+++ b/src/classic/spp_server.c
@@ -46,6 +46,8 @@
 #include <string.h>
 
 #include "bluetooth.h"
+#include "btstack_config.h"
+#include "classic/core.h"
 #include "classic/sdp_util.h"
 
 void spp_create_sdp_record(uint8_t *service, uint32_t service_record_handle, int rfcomm_channel, const char *name){