You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ko...@apache.org on 2021/02/18 14:30:13 UTC

[mynewt-nimble] 02/03: nimble/host: Compile ATT, GATT, L2CAP and SM files if NIMBLE_BLE_CONNECT ATT, GATT, L2CAP and SM are used only when connection is established, there's no need to compile them otherwise.

This is an automated email from the ASF dual-hosted git repository.

kopyscinski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 43c759de4ed821738483ad335ac52027e0f037b7
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Mon Feb 15 14:51:00 2021 +0100

    nimble/host: Compile ATT, GATT, L2CAP and SM files if NIMBLE_BLE_CONNECT
    ATT, GATT, L2CAP and SM  are used only when connection is established,
    there's no need to compile them otherwise.
---
 nimble/host/services/gap/src/ble_svc_gap.c |  6 +++++
 nimble/host/src/ble_att.c                  |  3 +++
 nimble/host/src/ble_att_clt.c              |  3 +++
 nimble/host/src/ble_att_cmd.c              |  3 +++
 nimble/host/src/ble_att_svr.c              |  3 +++
 nimble/host/src/ble_gattc.c                |  3 +++
 nimble/host/src/ble_gatts_lcl.c            |  2 ++
 nimble/host/src/ble_hs.c                   | 25 +++++++++++++++------
 nimble/host/src/ble_hs_hci_evt.c           | 36 ++++++++++++++++++++++++------
 nimble/host/src/ble_l2cap.c                |  3 +++
 nimble/host/src/ble_l2cap_coc.c            |  2 +-
 nimble/host/src/ble_l2cap_sig.c            |  3 +++
 nimble/host/src/ble_l2cap_sig_cmd.c        |  3 +++
 nimble/host/src/ble_sm.c                   |  3 +++
 nimble/host/src/ble_sm_alg.c               |  2 ++
 nimble/host/src/ble_sm_cmd.c               |  3 +++
 nimble/host/src/ble_sm_lgcy.c              |  2 ++
 nimble/host/src/ble_sm_sc.c                |  2 ++
 18 files changed, 92 insertions(+), 15 deletions(-)

diff --git a/nimble/host/services/gap/src/ble_svc_gap.c b/nimble/host/services/gap/src/ble_svc_gap.c
index e79b2b8..0775a41 100644
--- a/nimble/host/services/gap/src/ble_svc_gap.c
+++ b/nimble/host/services/gap/src/ble_svc_gap.c
@@ -41,6 +41,7 @@ static char ble_svc_gap_name[BLE_SVC_GAP_NAME_MAX_LEN + 1] =
         MYNEWT_VAL(BLE_SVC_GAP_DEVICE_NAME);
 static uint16_t ble_svc_gap_appearance = MYNEWT_VAL(BLE_SVC_GAP_APPEARANCE);
 
+#if NIMBLE_BLE_CONNECT
 static int
 ble_svc_gap_access(uint16_t conn_handle, uint16_t attr_handle,
                    struct ble_gatt_access_ctxt *ctxt, void *arg);
@@ -239,6 +240,7 @@ ble_svc_gap_access(uint16_t conn_handle, uint16_t attr_handle,
         return BLE_ATT_ERR_UNLIKELY;
     }
 }
+#endif
 
 const char *
 ble_svc_gap_device_name(void)
@@ -285,14 +287,18 @@ ble_svc_gap_set_chr_changed_cb(ble_svc_gap_chr_changed_fn *cb)
 void
 ble_svc_gap_init(void)
 {
+#if NIMBLE_BLE_CONNECT
     int rc;
+#endif
 
     /* Ensure this function only gets called by sysinit. */
     SYSINIT_ASSERT_ACTIVE();
 
+#if NIMBLE_BLE_CONNECT
     rc = ble_gatts_count_cfg(ble_svc_gap_defs);
     SYSINIT_PANIC_ASSERT(rc == 0);
 
     rc = ble_gatts_add_svcs(ble_svc_gap_defs);
     SYSINIT_PANIC_ASSERT(rc == 0);
+#endif
 }
diff --git a/nimble/host/src/ble_att.c b/nimble/host/src/ble_att.c
index cc7a1f1..8aab7f9 100644
--- a/nimble/host/src/ble_att.c
+++ b/nimble/host/src/ble_att.c
@@ -21,6 +21,7 @@
 #include <errno.h>
 #include "ble_hs_priv.h"
 
+#if NIMBLE_BLE_CONNECT
 static uint16_t ble_att_preferred_mtu_val;
 
 /** Dispatch table for incoming ATT requests.  Sorted by op code. */
@@ -587,3 +588,5 @@ ble_att_init(void)
 
     return 0;
 }
+
+#endif
diff --git a/nimble/host/src/ble_att_clt.c b/nimble/host/src/ble_att_clt.c
index 09fc9ea..1a76297 100644
--- a/nimble/host/src/ble_att_clt.c
+++ b/nimble/host/src/ble_att_clt.c
@@ -26,6 +26,7 @@
 #include "host/ble_uuid.h"
 #include "ble_hs_priv.h"
 
+#if NIMBLE_BLE_CONNECT
 /*****************************************************************************
  * $error response                                                           *
  *****************************************************************************/
@@ -954,3 +955,5 @@ ble_att_clt_rx_indicate(uint16_t conn_handle, struct os_mbuf **rxom)
     ble_gattc_rx_indicate_rsp(conn_handle);
     return 0;
 }
+
+#endif
diff --git a/nimble/host/src/ble_att_cmd.c b/nimble/host/src/ble_att_cmd.c
index 81b070f..e719235 100644
--- a/nimble/host/src/ble_att_cmd.c
+++ b/nimble/host/src/ble_att_cmd.c
@@ -26,6 +26,7 @@
 #include "host/ble_uuid.h"
 #include "ble_hs_priv.h"
 
+#if NIMBLE_BLE_CONNECT
 void *
 ble_att_cmd_prepare(uint8_t opcode, size_t len, struct os_mbuf *txom)
 {
@@ -634,3 +635,5 @@ ble_att_indicate_rsp_write(void *payload, int len)
     ble_att_init_write(BLE_ATT_OP_INDICATE_RSP, payload,
                        BLE_ATT_INDICATE_RSP_SZ, len);
 }
+
+#endif
diff --git a/nimble/host/src/ble_att_svr.c b/nimble/host/src/ble_att_svr.c
index be61e4b..0cfbc7d 100644
--- a/nimble/host/src/ble_att_svr.c
+++ b/nimble/host/src/ble_att_svr.c
@@ -25,6 +25,7 @@
 #include "host/ble_uuid.h"
 #include "ble_hs_priv.h"
 
+#if NIMBLE_BLE_CONNECT
 /**
  * ATT server - Attribute Protocol
  *
@@ -2727,3 +2728,5 @@ ble_att_svr_init(void)
 
     return 0;
 }
+
+#endif
diff --git a/nimble/host/src/ble_gattc.c b/nimble/host/src/ble_gattc.c
index a6e114c..d1036ff 100644
--- a/nimble/host/src/ble_gattc.c
+++ b/nimble/host/src/ble_gattc.c
@@ -60,6 +60,7 @@
 #include "host/ble_gap.h"
 #include "ble_hs_priv.h"
 
+#if NIMBLE_BLE_CONNECT
 /*****************************************************************************
  * $definitions / declarations                                               *
  *****************************************************************************/
@@ -4804,3 +4805,5 @@ ble_gattc_init(void)
 
     return 0;
 }
+
+#endif
diff --git a/nimble/host/src/ble_gatts_lcl.c b/nimble/host/src/ble_gatts_lcl.c
index a45f397..938d736 100644
--- a/nimble/host/src/ble_gatts_lcl.c
+++ b/nimble/host/src/ble_gatts_lcl.c
@@ -24,6 +24,7 @@
 #include "nimble/ble.h"
 #include "ble_hs_priv.h"
 
+#if NIMBLE_BLE_CONNECT
 static const ble_uuid_t *uuid_ccc =
         BLE_UUID16_DECLARE(BLE_GATT_DSC_CLT_CFG_UUID16);
 
@@ -209,3 +210,4 @@ ble_gatts_show_local(void)
     ble_gatts_lcl_svc_foreach(ble_gatt_show_local_svc, NULL);
 }
 
+#endif
diff --git a/nimble/host/src/ble_hs.c b/nimble/host/src/ble_hs.c
index 731e815..9f39c8e 100644
--- a/nimble/host/src/ble_hs.c
+++ b/nimble/host/src/ble_hs.c
@@ -36,7 +36,9 @@
      MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT))
 
 static void ble_hs_event_rx_hci_ev(struct ble_npl_event *ev);
+#if NIMBLE_BLE_CONNECT
 static void ble_hs_event_tx_notify(struct ble_npl_event *ev);
+#endif
 static void ble_hs_event_reset(struct ble_npl_event *ev);
 static void ble_hs_event_start_stage1(struct ble_npl_event *ev);
 static void ble_hs_event_start_stage2(struct ble_npl_event *ev);
@@ -401,12 +403,10 @@ ble_hs_timer_exp(struct ble_npl_event *ev)
 
     switch (ble_hs_sync_state) {
     case BLE_HS_SYNC_STATE_GOOD:
+#if NIMBLE_BLE_CONNECT
         ticks_until_next = ble_gattc_timer();
         ble_hs_timer_sched(ticks_until_next);
 
-        ticks_until_next = ble_gap_timer();
-        ble_hs_timer_sched(ticks_until_next);
-
         ticks_until_next = ble_l2cap_sig_timer();
         ble_hs_timer_sched(ticks_until_next);
 
@@ -415,6 +415,11 @@ ble_hs_timer_exp(struct ble_npl_event *ev)
 
         ticks_until_next = ble_hs_conn_timer();
         ble_hs_timer_sched(ticks_until_next);
+#endif
+
+        ticks_until_next = ble_gap_timer();
+        ble_hs_timer_sched(ticks_until_next);
+
         break;
 
     case BLE_HS_SYNC_STATE_BAD:
@@ -509,11 +514,13 @@ ble_hs_event_rx_hci_ev(struct ble_npl_event *ev)
     ble_hs_hci_evt_process(hci_ev);
 }
 
+#if NIMBLE_BLE_CONNECT
 static void
 ble_hs_event_tx_notify(struct ble_npl_event *ev)
 {
     ble_gatts_tx_notifications();
 }
+#endif
 
 static void
 ble_hs_event_rx_data(struct ble_npl_event *ev)
@@ -646,11 +653,12 @@ ble_hs_start(void)
 
     ble_npl_callout_init(&ble_hs_timer, ble_hs_evq, ble_hs_timer_exp, NULL);
 
+#if NIMBLE_BLE_CONNECT
     rc = ble_gatts_start();
     if (rc != 0) {
         return rc;
     }
-
+#endif
     ble_hs_sync();
 
     return 0;
@@ -723,8 +731,10 @@ ble_hs_init(void)
     ble_hs_reset_reason = 0;
     ble_hs_enabled_state = BLE_HS_ENABLED_STATE_OFF;
 
+#if NIMBLE_BLE_CONNECT
     ble_npl_event_init(&ble_hs_ev_tx_notifications, ble_hs_event_tx_notify,
                        NULL);
+#endif
     ble_npl_event_init(&ble_hs_ev_reset, ble_hs_event_reset, NULL);
     ble_npl_event_init(&ble_hs_ev_start_stage1, ble_hs_event_start_stage1,
                        NULL);
@@ -741,6 +751,7 @@ ble_hs_init(void)
     SYSINIT_PANIC_ASSERT(rc == 0);
 #endif
 
+#if NIMBLE_BLE_CONNECT
     rc = ble_l2cap_init();
     SYSINIT_PANIC_ASSERT(rc == 0);
 
@@ -750,14 +761,14 @@ ble_hs_init(void)
     rc = ble_att_svr_init();
     SYSINIT_PANIC_ASSERT(rc == 0);
 
-    rc = ble_gap_init();
-    SYSINIT_PANIC_ASSERT(rc == 0);
-
     rc = ble_gattc_init();
     SYSINIT_PANIC_ASSERT(rc == 0);
 
     rc = ble_gatts_init();
     SYSINIT_PANIC_ASSERT(rc == 0);
+#endif
+    rc = ble_gap_init();
+    SYSINIT_PANIC_ASSERT(rc == 0);
 
     ble_hs_stop_init();
 
diff --git a/nimble/host/src/ble_hs_hci_evt.c b/nimble/host/src/ble_hs_hci_evt.c
index e8ba711..108ee64 100644
--- a/nimble/host/src/ble_hs_hci_evt.c
+++ b/nimble/host/src/ble_hs_hci_evt.c
@@ -32,22 +32,27 @@ _Static_assert(sizeof (struct hci_data_hdr) == BLE_HCI_DATA_HDR_SZ,
 
 typedef int ble_hs_hci_evt_fn(uint8_t event_code, const void *data,
                               unsigned int len);
-static ble_hs_hci_evt_fn ble_hs_hci_evt_disconn_complete;
-static ble_hs_hci_evt_fn ble_hs_hci_evt_encrypt_change;
 static ble_hs_hci_evt_fn ble_hs_hci_evt_hw_error;
 static ble_hs_hci_evt_fn ble_hs_hci_evt_num_completed_pkts;
+#if NIMBLE_BLE_CONNECT
+static ble_hs_hci_evt_fn ble_hs_hci_evt_disconn_complete;
+static ble_hs_hci_evt_fn ble_hs_hci_evt_encrypt_change;
 static ble_hs_hci_evt_fn ble_hs_hci_evt_enc_key_refresh;
+#endif
 static ble_hs_hci_evt_fn ble_hs_hci_evt_le_meta;
 
 typedef int ble_hs_hci_evt_le_fn(uint8_t subevent, const void *data,
                                  unsigned int len);
-static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_conn_complete;
 static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_adv_rpt;
+#if NIMBLE_BLE_CONNECT
+static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_conn_complete;
 static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_conn_upd_complete;
 static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_lt_key_req;
 static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_conn_parm_req;
-static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_dir_adv_rpt;
 static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_phy_update_complete;
+static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_enh_conn_complete;
+#endif
+static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_dir_adv_rpt;
 static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_ext_adv_rpt;
 static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_rd_rem_used_feat_complete;
 static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_scan_timeout;
@@ -56,7 +61,6 @@ static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_periodic_adv_sync_estab;
 static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_periodic_adv_rpt;
 static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_periodic_adv_sync_lost;
 static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_scan_req_rcvd;
-static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_enh_conn_complete;
 static ble_hs_hci_evt_le_fn ble_hs_hci_evt_le_periodic_adv_sync_transfer;
 
 /* Statistics */
@@ -79,9 +83,11 @@ struct ble_hs_hci_evt_dispatch_entry {
 static const struct ble_hs_hci_evt_dispatch_entry ble_hs_hci_evt_dispatch[] = {
     { BLE_HCI_EVCODE_LE_META, ble_hs_hci_evt_le_meta },
     { BLE_HCI_EVCODE_NUM_COMP_PKTS, ble_hs_hci_evt_num_completed_pkts },
+#if NIMBLE_BLE_CONNECT
     { BLE_HCI_EVCODE_DISCONN_CMP, ble_hs_hci_evt_disconn_complete },
     { BLE_HCI_EVCODE_ENCRYPT_CHG, ble_hs_hci_evt_encrypt_change },
     { BLE_HCI_EVCODE_ENC_KEY_REFRESH, ble_hs_hci_evt_enc_key_refresh },
+#endif
     { BLE_HCI_EVCODE_HW_ERROR, ble_hs_hci_evt_hw_error },
 };
 
@@ -89,14 +95,20 @@ static const struct ble_hs_hci_evt_dispatch_entry ble_hs_hci_evt_dispatch[] = {
     (sizeof ble_hs_hci_evt_dispatch / sizeof ble_hs_hci_evt_dispatch[0])
 
 static ble_hs_hci_evt_le_fn * const ble_hs_hci_evt_le_dispatch[] = {
+#if NIMBLE_BLE_CONNECT
     [BLE_HCI_LE_SUBEV_CONN_COMPLETE] = ble_hs_hci_evt_le_conn_complete,
+#endif
     [BLE_HCI_LE_SUBEV_ADV_RPT] = ble_hs_hci_evt_le_adv_rpt,
+#if NIMBLE_BLE_CONNECT
     [BLE_HCI_LE_SUBEV_CONN_UPD_COMPLETE] = ble_hs_hci_evt_le_conn_upd_complete,
     [BLE_HCI_LE_SUBEV_LT_KEY_REQ] = ble_hs_hci_evt_le_lt_key_req,
     [BLE_HCI_LE_SUBEV_REM_CONN_PARM_REQ] = ble_hs_hci_evt_le_conn_parm_req,
     [BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE] = ble_hs_hci_evt_le_enh_conn_complete,
+#endif
     [BLE_HCI_LE_SUBEV_DIRECT_ADV_RPT] = ble_hs_hci_evt_le_dir_adv_rpt,
+#if NIMBLE_BLE_CONNECT
     [BLE_HCI_LE_SUBEV_PHY_UPDATE_COMPLETE] = ble_hs_hci_evt_le_phy_update_complete,
+#endif
     [BLE_HCI_LE_SUBEV_EXT_ADV_RPT] = ble_hs_hci_evt_le_ext_adv_rpt,
     [BLE_HCI_LE_SUBEV_PERIODIC_ADV_SYNC_ESTAB] = ble_hs_hci_evt_le_periodic_adv_sync_estab,
     [BLE_HCI_LE_SUBEV_PERIODIC_ADV_RPT] = ble_hs_hci_evt_le_periodic_adv_rpt,
@@ -137,6 +149,7 @@ ble_hs_hci_evt_le_dispatch_find(uint8_t event_code)
     return ble_hs_hci_evt_le_dispatch[event_code];
 }
 
+#if NIMBLE_BLE_CONNECT
 static int
 ble_hs_hci_evt_disconn_complete(uint8_t event_code, const void *data,
                                 unsigned int len)
@@ -180,7 +193,7 @@ ble_hs_hci_evt_encrypt_change(uint8_t event_code, const void *data,
 
     return 0;
 }
-
+#endif
 static int
 ble_hs_hci_evt_hw_error(uint8_t event_code, const void *data, unsigned int len)
 {
@@ -195,6 +208,7 @@ ble_hs_hci_evt_hw_error(uint8_t event_code, const void *data, unsigned int len)
     return 0;
 }
 
+#if NIMBLE_BLE_CONNECT
 static int
 ble_hs_hci_evt_enc_key_refresh(uint8_t event_code, const void *data,
                                unsigned int len)
@@ -209,6 +223,7 @@ ble_hs_hci_evt_enc_key_refresh(uint8_t event_code, const void *data,
 
     return 0;
 }
+#endif
 
 static int
 ble_hs_hci_evt_num_completed_pkts(uint8_t event_code, const void *data,
@@ -270,6 +285,7 @@ ble_hs_hci_evt_le_meta(uint8_t event_code, const void *data, unsigned int len)
 static struct ble_gap_conn_complete pend_conn_complete;
 #endif
 
+#if NIMBLE_BLE_CONNECT
 static int
 ble_hs_hci_evt_le_enh_conn_complete(uint8_t subevent, const void *data,
                                     unsigned int len)
@@ -301,7 +317,6 @@ ble_hs_hci_evt_le_enh_conn_complete(uint8_t subevent, const void *data,
         evt.connection_handle = BLE_HS_CONN_HANDLE_NONE;
 #endif
     }
-
 #if MYNEWT_VAL(BLE_EXT_ADV)
     if (evt.status == BLE_ERR_DIR_ADV_TMO ||
                             evt.role == BLE_HCI_LE_CONN_COMPLETE_ROLE_SLAVE) {
@@ -355,6 +370,7 @@ ble_hs_hci_evt_le_conn_complete(uint8_t subevent, const void *data,
 #endif
     return ble_gap_rx_conn_complete(&evt, 0);
 }
+#endif
 
 static int
 ble_hs_hci_evt_le_adv_rpt_first_pass(const void *data, unsigned int len)
@@ -697,6 +713,7 @@ ble_hs_hci_evt_le_scan_req_rcvd(uint8_t subevent, const void *data,
     return 0;
 }
 
+#if NIMBLE_BLE_CONNECT
 static int
 ble_hs_hci_evt_le_conn_upd_complete(uint8_t subevent, const void *data,
                                     unsigned int len)
@@ -775,6 +792,7 @@ ble_hs_hci_evt_le_phy_update_complete(uint8_t subevent, const void *data,
 
     return 0;
 }
+#endif
 
 int
 ble_hs_hci_evt_process(const struct ble_hci_ev *ev)
@@ -811,6 +829,7 @@ ble_hs_hci_evt_process(const struct ble_hci_ev *ev)
 int
 ble_hs_hci_evt_acl_process(struct os_mbuf *om)
 {
+#if NIMBLE_BLE_CONNECT
     struct hci_data_hdr hci_hdr;
     struct ble_hs_conn *conn;
     ble_l2cap_rx_fn *rx_cb;
@@ -881,4 +900,7 @@ ble_hs_hci_evt_acl_process(struct os_mbuf *om)
 err:
     os_mbuf_free_chain(om);
     return rc;
+#else
+    return BLE_HS_ENOTSUP;
+#endif
 }
diff --git a/nimble/host/src/ble_l2cap.c b/nimble/host/src/ble_l2cap.c
index 0d9f082..2bc50e0 100644
--- a/nimble/host/src/ble_l2cap.c
+++ b/nimble/host/src/ble_l2cap.c
@@ -26,6 +26,7 @@
 #include "ble_hs_priv.h"
 #include "ble_l2cap_coc_priv.h"
 
+#if NIMBLE_BLE_CONNECT
 _Static_assert(sizeof (struct ble_l2cap_hdr) == BLE_L2CAP_HDR_SZ,
                "struct ble_l2cap_hdr must be 4 bytes");
 
@@ -504,3 +505,5 @@ ble_l2cap_init(void)
 
     return 0;
 }
+
+#endif
diff --git a/nimble/host/src/ble_l2cap_coc.c b/nimble/host/src/ble_l2cap_coc.c
index 8dc367e..aa953d7 100644
--- a/nimble/host/src/ble_l2cap_coc.c
+++ b/nimble/host/src/ble_l2cap_coc.c
@@ -25,7 +25,7 @@
 #include "ble_l2cap_coc_priv.h"
 #include "ble_l2cap_sig_priv.h"
 
-#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0
+#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) != 0 && NIMBLE_BLE_CONNECT
 
 #define BLE_L2CAP_SDU_SIZE              2
 
diff --git a/nimble/host/src/ble_l2cap_sig.c b/nimble/host/src/ble_l2cap_sig.c
index ad81c64..02f805f 100644
--- a/nimble/host/src/ble_l2cap_sig.c
+++ b/nimble/host/src/ble_l2cap_sig.c
@@ -48,6 +48,7 @@
 #include "host/ble_monitor.h"
 #include "ble_hs_priv.h"
 
+#if NIMBLE_BLE_CONNECT
 /*****************************************************************************
  * $definitions / declarations                                               *
  *****************************************************************************/
@@ -1953,3 +1954,5 @@ ble_l2cap_sig_init(void)
 
     return 0;
 }
+
+#endif
diff --git a/nimble/host/src/ble_l2cap_sig_cmd.c b/nimble/host/src/ble_l2cap_sig_cmd.c
index 510420f..d9e507e 100644
--- a/nimble/host/src/ble_l2cap_sig_cmd.c
+++ b/nimble/host/src/ble_l2cap_sig_cmd.c
@@ -20,6 +20,7 @@
 #include <string.h>
 #include "ble_hs_priv.h"
 
+#if NIMBLE_BLE_CONNECT
 int
 ble_l2cap_sig_tx(uint16_t conn_handle, struct os_mbuf *txom)
 {
@@ -112,3 +113,5 @@ ble_l2cap_sig_cmd_get(uint8_t opcode, uint8_t id, uint16_t len,
 
     return hdr->data;
 }
+
+#endif
diff --git a/nimble/host/src/ble_sm.c b/nimble/host/src/ble_sm.c
index 91afb75..d405589 100644
--- a/nimble/host/src/ble_sm.c
+++ b/nimble/host/src/ble_sm.c
@@ -48,6 +48,7 @@
 #include "host/ble_sm.h"
 #include "ble_hs_priv.h"
 
+#if NIMBLE_BLE_CONNECT
 #if NIMBLE_BLE_SM
 
 /** Procedure timeout; 30 seconds. */
@@ -2812,3 +2813,5 @@ ble_sm_create_chan(uint16_t conn_handle)
 
     return chan;
 }
+
+#endif
diff --git a/nimble/host/src/ble_sm_alg.c b/nimble/host/src/ble_sm_alg.c
index 7f5eda6..8b3326d 100644
--- a/nimble/host/src/ble_sm_alg.c
+++ b/nimble/host/src/ble_sm_alg.c
@@ -23,6 +23,7 @@
 #include "syscfg/syscfg.h"
 #include "nimble/nimble_opt.h"
 
+#if NIMBLE_BLE_CONNECT
 #if NIMBLE_BLE_SM
 
 #include "nimble/ble.h"
@@ -533,3 +534,4 @@ ble_sm_alg_ecc_init(void)
 
 #endif
 #endif
+#endif
diff --git a/nimble/host/src/ble_sm_cmd.c b/nimble/host/src/ble_sm_cmd.c
index 01651f1..2983102 100644
--- a/nimble/host/src/ble_sm_cmd.c
+++ b/nimble/host/src/ble_sm_cmd.c
@@ -24,6 +24,7 @@
 #include "host/ble_sm.h"
 #include "ble_hs_priv.h"
 
+#if NIMBLE_BLE_CONNECT
 void *
 ble_sm_cmd_get(uint8_t opcode, size_t len, struct os_mbuf **txom)
 {
@@ -66,3 +67,5 @@ ble_sm_tx(uint16_t conn_handle, struct os_mbuf *txom)
 
     return rc;
 }
+
+#endif
diff --git a/nimble/host/src/ble_sm_lgcy.c b/nimble/host/src/ble_sm_lgcy.c
index bb2d66d..0259ff4 100644
--- a/nimble/host/src/ble_sm_lgcy.c
+++ b/nimble/host/src/ble_sm_lgcy.c
@@ -24,6 +24,7 @@
 #include "host/ble_sm.h"
 #include "ble_hs_priv.h"
 
+#if NIMBLE_BLE_CONNECT
 #if MYNEWT_VAL(BLE_SM_LEGACY)
 
 /**
@@ -252,3 +253,4 @@ ble_sm_lgcy_random_rx(struct ble_sm_proc *proc, struct ble_sm_result *res)
 }
 
 #endif
+#endif
diff --git a/nimble/host/src/ble_sm_sc.c b/nimble/host/src/ble_sm_sc.c
index 562f33b..7fae5b1 100644
--- a/nimble/host/src/ble_sm_sc.c
+++ b/nimble/host/src/ble_sm_sc.c
@@ -24,6 +24,7 @@
 #include "ble_hs_priv.h"
 #include "ble_sm_priv.h"
 
+#if NIMBLE_BLE_CONNECT
 #if MYNEWT_VAL(BLE_SM_SC)
 
 #define BLE_SM_SC_PASSKEY_BYTES     4
@@ -907,3 +908,4 @@ ble_sm_sc_init(void)
 }
 
 #endif  /* MYNEWT_VAL(BLE_SM_SC) */
+#endif