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:11 UTC

[mynewt-nimble] branch master updated (0aa3fe6 -> a3c7ec4)

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

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


    from 0aa3fe6  porting: fix typo in CROSS_COMPILE
     new 3a9d1d8  host/ble_gap.c: optimize code Not all function bodies or methods must compile always. Added preprocessor directives to exclude such code fragments if not required, depending on roles/features.
     new 43c759d  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.
     new a3c7ec4  apps: add roles to config sample apps had default config, but we can minimize their size by disabling unused roles.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 {nimble/host/util => apps/advertiser}/syscfg.yml |   8 +-
 {nimble/host/util => apps/central}/syscfg.yml    |   8 +-
 {nimble/host/util => apps/peripheral}/syscfg.yml |   8 +-
 {nimble/host/util => apps/scanner}/syscfg.yml    |   8 +-
 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_gap.c                        | 135 ++++++++++++++++++++---
 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 +
 23 files changed, 236 insertions(+), 38 deletions(-)
 copy {nimble/host/util => apps/advertiser}/syscfg.yml (86%)
 copy {nimble/host/util => apps/central}/syscfg.yml (86%)
 copy {nimble/host/util => apps/peripheral}/syscfg.yml (86%)
 copy {nimble/host/util => apps/scanner}/syscfg.yml (86%)


[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.

Posted by ko...@apache.org.
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


[mynewt-nimble] 03/03: apps: add roles to config sample apps had default config, but we can minimize their size by disabling unused roles.

Posted by ko...@apache.org.
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 a3c7ec4ef5bad515e53393a4a15b2b29123f617c
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Tue Feb 16 08:18:58 2021 +0100

    apps: add roles to config
    sample apps had default config, but we can minimize their size by
    disabling unused roles.
---
 apps/advertiser/syscfg.yml | 23 +++++++++++++++++++++++
 apps/central/syscfg.yml    | 23 +++++++++++++++++++++++
 apps/peripheral/syscfg.yml | 23 +++++++++++++++++++++++
 apps/scanner/syscfg.yml    | 23 +++++++++++++++++++++++
 4 files changed, 92 insertions(+)

diff --git a/apps/advertiser/syscfg.yml b/apps/advertiser/syscfg.yml
new file mode 100644
index 0000000..963839f
--- /dev/null
+++ b/apps/advertiser/syscfg.yml
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+
+syscfg.vals:
+    BLE_ROLE_BROADCASTER: 1
+    BLE_ROLE_CENTRAL: 0
+    BLE_ROLE_OBSERVER: 0
+    BLE_ROLE_PERIPHERAL: 0
diff --git a/apps/central/syscfg.yml b/apps/central/syscfg.yml
new file mode 100644
index 0000000..1e24f90
--- /dev/null
+++ b/apps/central/syscfg.yml
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+
+syscfg.vals:
+    BLE_ROLE_BROADCASTER: 0
+    BLE_ROLE_CENTRAL: 1
+    BLE_ROLE_OBSERVER: 1
+    BLE_ROLE_PERIPHERAL: 0
diff --git a/apps/peripheral/syscfg.yml b/apps/peripheral/syscfg.yml
new file mode 100644
index 0000000..dd02ee6
--- /dev/null
+++ b/apps/peripheral/syscfg.yml
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+
+syscfg.vals:
+    BLE_ROLE_BROADCASTER: 1
+    BLE_ROLE_CENTRAL: 0
+    BLE_ROLE_OBSERVER: 0
+    BLE_ROLE_PERIPHERAL: 1
diff --git a/apps/scanner/syscfg.yml b/apps/scanner/syscfg.yml
new file mode 100644
index 0000000..a926575
--- /dev/null
+++ b/apps/scanner/syscfg.yml
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+
+
+syscfg.vals:
+    BLE_ROLE_BROADCASTER: 0
+    BLE_ROLE_CENTRAL: 0
+    BLE_ROLE_OBSERVER: 1
+    BLE_ROLE_PERIPHERAL: 0


[mynewt-nimble] 01/03: host/ble_gap.c: optimize code Not all function bodies or methods must compile always. Added preprocessor directives to exclude such code fragments if not required, depending on roles/features.

Posted by ko...@apache.org.
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 3a9d1d85977a8be91cd8e93a138785e3521291b0
Author: Krzysztof Kopyściński <kr...@codecoup.pl>
AuthorDate: Fri Feb 12 14:33:07 2021 +0100

    host/ble_gap.c: optimize code
    Not all function bodies or methods must compile always. Added
    preprocessor directives to exclude such code fragments if not required,
    depending on roles/features.
---
 nimble/host/src/ble_gap.c | 135 ++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 120 insertions(+), 15 deletions(-)

diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c
index bbedc31..45747ff 100644
--- a/nimble/host/src/ble_gap.c
+++ b/nimble/host/src/ble_gap.c
@@ -225,7 +225,9 @@ ble_gap_update_entry_remove(uint16_t conn_handle);
 static int ble_gap_adv_enable_tx(int enable);
 #endif
 
+#if NIMBLE_BLE_CONNECT
 static int ble_gap_conn_cancel_tx(void);
+#endif
 
 #if NIMBLE_BLE_SCAN && !MYNEWT_VAL(BLE_EXT_ADV)
 static int ble_gap_disc_enable_tx(int enable, int filter_duplicates);
@@ -387,6 +389,7 @@ ble_gap_log_adv(uint8_t own_addr_type, const ble_addr_t *direct_addr,
  * $snapshot                                                                 *
  *****************************************************************************/
 
+#if NIMBLE_BLE_CONNECT
 static void
 ble_gap_fill_conn_desc(struct ble_hs_conn *conn,
                        struct ble_gap_conn_desc *desc)
@@ -443,10 +446,12 @@ ble_gap_find_snapshot(uint16_t handle, struct ble_gap_snapshot *snap)
         return 0;
     }
 }
+#endif
 
 int
 ble_gap_conn_find(uint16_t handle, struct ble_gap_conn_desc *out_desc)
 {
+#if NIMBLE_BLE_CONNECT
     struct ble_hs_conn *conn;
 
     ble_hs_lock();
@@ -463,12 +468,16 @@ ble_gap_conn_find(uint16_t handle, struct ble_gap_conn_desc *out_desc)
     } else {
         return 0;
     }
+#else
+    return BLE_HS_ENOTSUP;
+#endif
 }
 
 int
 ble_gap_conn_find_by_addr(const ble_addr_t *addr,
                           struct ble_gap_conn_desc *out_desc)
 {
+#if NIMBLE_BLE_CONNECT
     struct ble_hs_conn *conn;
 
     ble_hs_lock();
@@ -485,8 +494,12 @@ ble_gap_conn_find_by_addr(const ble_addr_t *addr,
     }
 
     return 0;
+#else
+    return BLE_HS_ENOTSUP;
+#endif
 }
 
+#if NIMBLE_BLE_CONNECT
 static int
 ble_gap_extract_conn_cb(uint16_t conn_handle,
                         ble_gap_event_fn **out_cb, void **out_cb_arg)
@@ -514,16 +527,22 @@ ble_gap_extract_conn_cb(uint16_t conn_handle,
         return 0;
     }
 }
+#endif
 
 int
 ble_gap_set_priv_mode(const ble_addr_t *peer_addr, uint8_t priv_mode)
 {
+#if NIMBLE_BLE_CONNECT
     return ble_hs_pvcy_set_mode(peer_addr, priv_mode);
+#else
+    return BLE_HS_ENOTSUP;
+#endif
 }
 
 int
 ble_gap_read_le_phy(uint16_t conn_handle, uint8_t *tx_phy, uint8_t *rx_phy)
 {
+#if NIMBLE_BLE_CONNECT
     struct ble_hci_le_rd_phy_cp cmd;
     struct ble_hci_le_rd_phy_rp rsp;
     struct ble_hs_conn *conn;
@@ -554,11 +573,15 @@ ble_gap_read_le_phy(uint16_t conn_handle, uint8_t *tx_phy, uint8_t *rx_phy)
     *rx_phy = rsp.rx_phy;
 
     return 0;
+#else
+    return BLE_HS_ENOTSUP;
+#endif
 }
 
 int
 ble_gap_set_prefered_default_le_phy(uint8_t tx_phys_mask, uint8_t rx_phys_mask)
 {
+#if NIMBLE_BLE_CONNECT
     struct ble_hci_le_set_default_phy_cp cmd;
 
     if (tx_phys_mask > (BLE_HCI_LE_PHY_1M_PREF_MASK |
@@ -590,12 +613,16 @@ ble_gap_set_prefered_default_le_phy(uint8_t tx_phys_mask, uint8_t rx_phys_mask)
     return ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_LE,
                                         BLE_HCI_OCF_LE_SET_DEFAULT_PHY),
                             &cmd, sizeof(cmd), NULL, 0);
+#else
+    return BLE_HS_ENOTSUP;
+#endif
 }
 
 int
 ble_gap_set_prefered_le_phy(uint16_t conn_handle, uint8_t tx_phys_mask,
                    uint8_t rx_phys_mask, uint16_t phy_opts)
 {
+#if NIMBLE_BLE_CONNECT
     struct ble_hci_le_set_phy_cp cmd;
     struct ble_hs_conn *conn;
 
@@ -642,6 +669,9 @@ ble_gap_set_prefered_le_phy(uint16_t conn_handle, uint8_t tx_phys_mask,
 
     return ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_LE, BLE_HCI_OCF_LE_SET_PHY),
                              &cmd, sizeof(cmd), NULL, 0);
+#else
+    return BLE_HS_ENOTSUP;
+#endif
 }
 
 /*****************************************************************************
@@ -673,7 +703,7 @@ ble_gap_call_event_cb(struct ble_gap_event *event,
     return rc;
 }
 
-
+#if NIMBLE_BLE_CONNECT
 static int
 ble_gap_call_conn_event_cb(struct ble_gap_event *event, uint16_t conn_handle)
 {
@@ -693,28 +723,32 @@ ble_gap_call_conn_event_cb(struct ble_gap_event *event, uint16_t conn_handle)
 
     return 0;
 }
+#endif
 
 static bool
 ble_gap_is_preempted(void)
 {
+#if NIMBLE_BLE_ADVERTISE
     int i;
-
+#endif
     BLE_HS_DBG_ASSERT(ble_hs_locked_by_cur_task());
 
+#if MYNEWT_VAL(BLE_ROLE_CENTRAL) || MYNEWT_VAL(BLE_ROLE_OBSERVER)
     if (ble_gap_master.preempted_op != BLE_GAP_OP_NULL) {
         return true;
     }
-
+#endif
+#if NIMBLE_BLE_ADVERTISE
     for (i = 0; i < BLE_ADV_INSTANCES; i++) {
         if (ble_gap_slave[i].preempted) {
             return true;
         }
     }
-
+#endif
     return false;
 }
 
-#if NIMBLE_BLE_CONNECT
+#if MYNEWT_VAL(BLE_ROLE_OBSERVER) || NIMBLE_BLE_CONNECT
 static void
 ble_gap_master_reset_state(void)
 {
@@ -726,6 +760,7 @@ ble_gap_master_reset_state(void)
 }
 #endif
 
+#if NIMBLE_BLE_ADVERTISE || NIMBLE_BLE_CONNECT
 static void
 ble_gap_slave_reset_state(uint8_t instance)
 {
@@ -736,8 +771,9 @@ ble_gap_slave_reset_state(uint8_t instance)
     ble_hs_timer_resched();
 #endif
 }
+#endif
 
-#if NIMBLE_BLE_CONNECT
+#if MYNEWT_VAL(BLE_ROLE_CENTRAL) || MYNEWT_VAL(BLE_ROLE_PERIPHERAL) || MYNEWT_VAL(BLE_ROLE_OBSERVER)
 static bool
 ble_gap_has_client(struct ble_gap_master_state *out_state)
 {
@@ -747,7 +783,9 @@ ble_gap_has_client(struct ble_gap_master_state *out_state)
 
     return out_state->cb != NULL;
 }
+#endif
 
+#if MYNEWT_VAL(BLE_ROLE_OBSERVER) || NIMBLE_BLE_CONNECT
 static void
 ble_gap_master_extract_state(struct ble_gap_master_state *out_state,
                              int reset_state)
@@ -765,6 +803,7 @@ ble_gap_master_extract_state(struct ble_gap_master_state *out_state,
 }
 #endif
 
+#if NIMBLE_BLE_ADVERTISE || NIMBLE_BLE_CONNECT
 static void
 ble_gap_slave_extract_cb(uint8_t instance,
                          ble_gap_event_fn **out_cb, void **out_cb_arg)
@@ -802,6 +841,7 @@ ble_gap_adv_finished(uint8_t instance, int reason, uint16_t conn_handle,
         cb(&event, cb_arg);
     }
 }
+#endif
 
 #if NIMBLE_BLE_CONNECT
 static int
@@ -875,22 +915,27 @@ ble_gap_disc_report(void *desc)
 static void
 ble_gap_disc_complete(void)
 {
+#if NIMBLE_BLE_CONNECT
     struct ble_gap_master_state state;
+#endif
     struct ble_gap_event event;
 
     memset(&event, 0, sizeof event);
     event.type = BLE_GAP_EVENT_DISC_COMPLETE;
     event.disc_complete.reason = 0;
 
+#if NIMBLE_BLE_CONNECT
     ble_gap_master_extract_state(&state, 1);
     if (ble_gap_has_client(&state)) {
         ble_gap_call_event_cb(&event, state.cb, state.cb_arg);
     }
+#endif
 
     ble_gap_event_listener_call(&event);
 }
 #endif
 
+#if NIMBLE_BLE_CONNECT
 static void
 ble_gap_update_notify(uint16_t conn_handle, int status)
 {
@@ -909,6 +954,7 @@ ble_gap_update_notify(uint16_t conn_handle, int status)
         ble_gap_terminate(conn_handle, BLE_ERR_REM_USER_CONN_TERM);
     }
 }
+#endif
 
 static uint32_t
 ble_gap_master_ticks_until_exp(void)
@@ -1029,10 +1075,12 @@ static void
 ble_gap_master_failed(int status)
 {
     switch (ble_gap_master.op) {
+#if NIMBLE_BLE_CONNECT
     case BLE_GAP_OP_M_CONN:
         STATS_INC(ble_gap_stats, initiate_fail);
         ble_gap_master_connect_failure(status);
         break;
+#endif
 
 #if NIMBLE_BLE_SCAN
     case BLE_GAP_OP_M_DISC:
@@ -1070,6 +1118,7 @@ ble_gap_update_failed(uint16_t conn_handle, int status)
 void
 ble_gap_conn_broken(uint16_t conn_handle, int reason)
 {
+#if NIMBLE_BLE_CONNECT
     struct ble_gap_update_entry *entry;
     struct ble_gap_snapshot snap;
     struct ble_gap_event event;
@@ -1115,6 +1164,7 @@ ble_gap_conn_broken(uint16_t conn_handle, int reason)
     ble_gap_call_event_cb(&event, snap.cb, snap.cb_arg);
 
     STATS_INC(ble_gap_stats, disconnect);
+#endif
 }
 
 #if NIMBLE_BLE_CONNECT
@@ -1237,15 +1287,21 @@ ble_gap_rx_update_complete(const struct ble_hci_ev_le_subev_conn_upd_complete *e
 int
 ble_gap_master_in_progress(void)
 {
+#if MYNEWT_VAL(BLE_ROLE_CENTRAL) || MYNEWT_VAL(BLE_ROLE_OBSERVER)
     return ble_gap_master.op != BLE_GAP_OP_NULL;
+#else
+    return false;
+#endif
 }
 
+#if NIMBLE_BLE_ADVERTISE || NIMBLE_BLE_CONNECT
 static int
 ble_gap_adv_active_instance(uint8_t instance)
 {
     /* Assume read is atomic; mutex not necessary. */
     return ble_gap_slave[instance].op == BLE_GAP_OP_S_ADV;
 }
+#endif
 
 /**
  * Clears advertisement and discovery state.  This function is necessary
@@ -1856,6 +1912,7 @@ int
 ble_gap_rx_l2cap_update_req(uint16_t conn_handle,
                             struct ble_gap_upd_params *params)
 {
+#if NIMBLE_BLE_CONNECT
     struct ble_gap_event event;
     int rc;
 
@@ -1866,11 +1923,15 @@ ble_gap_rx_l2cap_update_req(uint16_t conn_handle,
 
     rc = ble_gap_call_conn_event_cb(&event, conn_handle);
     return rc;
+#else
+    return BLE_HS_ENOTSUP;
+#endif
 }
 
 void
 ble_gap_rx_phy_update_complete(const struct ble_hci_ev_le_subev_phy_update_complete *ev)
 {
+#if NIMBLE_BLE_CONNECT
     struct ble_gap_event event;
     uint16_t conn_handle = le16toh(ev->conn_handle);
 
@@ -1883,13 +1944,16 @@ ble_gap_rx_phy_update_complete(const struct ble_hci_ev_le_subev_phy_update_compl
 
     ble_gap_event_listener_call(&event);
     ble_gap_call_conn_event_cb(&event, conn_handle);
+#endif
 }
 
 static int32_t
 ble_gap_master_timer(void)
 {
     uint32_t ticks_until_exp;
+#if NIMBLE_BLE_SCAN || NIMBLE_BLE_CONNECT
     int rc;
+#endif
 
     ticks_until_exp = ble_gap_master_ticks_until_exp();
     if (ticks_until_exp != 0) {
@@ -1900,6 +1964,7 @@ ble_gap_master_timer(void)
     /*** Timer expired; process event. */
 
     switch (ble_gap_master.op) {
+#if NIMBLE_BLE_CONNECT
     case BLE_GAP_OP_M_CONN:
         rc = ble_gap_conn_cancel_tx();
         if (rc != 0) {
@@ -1917,6 +1982,7 @@ ble_gap_master_timer(void)
              */
         }
         break;
+#endif
 
     case BLE_GAP_OP_M_DISC:
 #if NIMBLE_BLE_SCAN && !MYNEWT_VAL(BLE_EXT_ADV)
@@ -2003,6 +2069,7 @@ ble_gap_update_timer(void)
 int
 ble_gap_set_event_cb(uint16_t conn_handle, ble_gap_event_fn *cb, void *cb_arg)
 {
+#if NIMBLE_BLE_CONNECT
     struct ble_hs_conn *conn;
 
     ble_hs_lock();
@@ -2020,6 +2087,9 @@ ble_gap_set_event_cb(uint16_t conn_handle, ble_gap_event_fn *cb, void *cb_arg)
     }
 
     return 0;
+#else
+    return BLE_HS_ENOTCONN;
+#endif
 }
 
 /**
@@ -2581,7 +2651,11 @@ ble_gap_adv_rsp_set_fields(const struct ble_hs_adv_fields *rsp_fields)
 int
 ble_gap_adv_active(void)
 {
+#if NIMBLE_BLE_ADVERTISE
     return ble_gap_adv_active_instance(0);
+#else
+    return 0;
+#endif
 }
 
 #if MYNEWT_VAL(BLE_EXT_ADV)
@@ -4487,8 +4561,12 @@ done:
 int
 ble_gap_disc_active(void)
 {
+#if MYNEWT_VAL(BLE_ROLE_CENTRAL) || MYNEWT_VAL(BLE_ROLE_OBSERVER)
     /* Assume read is atomic; mutex not necessary. */
     return ble_gap_master.op == BLE_GAP_OP_M_DISC;
+#else
+    return 0;
+#endif
 }
 
 #if MYNEWT_VAL(BLE_ROLE_CENTRAL) && !MYNEWT_VAL(BLE_EXT_ADV)
@@ -4993,8 +5071,12 @@ done:
 int
 ble_gap_conn_active(void)
 {
+#if MYNEWT_VAL(BLE_ROLE_CENTRAL) || MYNEWT_VAL(BLE_ROLE_OBSERVER)
     /* Assume read is atomic; mutex not necessary. */
     return ble_gap_master.op == BLE_GAP_OP_M_CONN;
+#else
+    return 0;
+#endif
 }
 
 /*****************************************************************************
@@ -5003,6 +5085,7 @@ ble_gap_conn_active(void)
 int
 ble_gap_terminate_with_conn(struct ble_hs_conn *conn, uint8_t hci_reason)
 {
+#if NIMBLE_BLE_CONNECT
     struct ble_hci_lc_disconnect_cp cmd;
     int rc;
 
@@ -5027,11 +5110,15 @@ ble_gap_terminate_with_conn(struct ble_hs_conn *conn, uint8_t hci_reason)
 
     conn->bhc_flags |= BLE_HS_CONN_F_TERMINATING;
     return 0;
+#else
+    return BLE_HS_ENOTSUP;
+#endif
 }
 
 int
 ble_gap_terminate(uint16_t conn_handle, uint8_t hci_reason)
 {
+#if NIMBLE_BLE_CONNECT
     struct ble_hs_conn *conn;
     int rc;
 
@@ -5054,12 +5141,16 @@ done:
         STATS_INC(ble_gap_stats, terminate_fail);
     }
     return rc;
+#else
+    return BLE_HS_ENOTSUP;
+#endif
 }
 
 /*****************************************************************************
  * $cancel                                                                   *
  *****************************************************************************/
 
+#if NIMBLE_BLE_CONNECT
 static int
 ble_gap_conn_cancel_tx(void)
 {
@@ -5075,7 +5166,6 @@ ble_gap_conn_cancel_tx(void)
     return 0;
 }
 
-#if NIMBLE_BLE_CONNECT
 static int
 ble_gap_conn_cancel_no_lock(void)
 {
@@ -5559,6 +5649,7 @@ ble_gap_encryption_initiate(uint16_t conn_handle,
 int
 ble_gap_unpair(const ble_addr_t *peer_addr)
 {
+#if NIMBLE_BLE_SM
     struct ble_hs_conn *conn;
 
     if (ble_addr_cmp(peer_addr, BLE_ADDR_ANY) == 0) {
@@ -5578,11 +5669,15 @@ ble_gap_unpair(const ble_addr_t *peer_addr)
                              peer_addr->val);
 
     return ble_store_util_delete_peer(peer_addr);
+#else
+    return BLE_HS_ENOTSUP;
+#endif
 }
 
 int
 ble_gap_unpair_oldest_peer(void)
 {
+#if NIMBLE_BLE_SM
     ble_addr_t oldest_peer_id_addr;
     int num_peers;
     int rc;
@@ -5603,11 +5698,15 @@ ble_gap_unpair_oldest_peer(void)
     }
 
     return 0;
+#else
+    return BLE_HS_ENOTSUP;
+#endif
 }
 
 int
 ble_gap_unpair_oldest_except(const ble_addr_t *peer_addr)
 {
+#if NIMBLE_BLE_SM
     ble_addr_t peer_id_addrs[MYNEWT_VAL(BLE_STORE_MAX_BONDS)];
     int num_peers;
     int rc, i;
@@ -5633,13 +5732,16 @@ ble_gap_unpair_oldest_except(const ble_addr_t *peer_addr)
     }
 
     return ble_gap_unpair(&peer_id_addrs[i]);
+#else
+    return BLE_HS_ENOTSUP;
+#endif
 }
 
 void
 ble_gap_passkey_event(uint16_t conn_handle,
                       struct ble_gap_passkey_params *passkey_params)
 {
-#if NIMBLE_BLE_SM
+#if NIMBLE_BLE_SM && NIMBLE_BLE_CONNECT
     struct ble_gap_event event;
 
     BLE_HS_LOG(DEBUG, "send passkey action request %d\n",
@@ -5657,7 +5759,7 @@ void
 ble_gap_enc_event(uint16_t conn_handle, int status,
                   int security_restored, int bonded)
 {
-#if NIMBLE_BLE_SM
+#if NIMBLE_BLE_SM && NIMBLE_BLE_CONNECT
     struct ble_gap_event event;
 
     memset(&event, 0, sizeof event);
@@ -5693,7 +5795,7 @@ ble_gap_enc_event(uint16_t conn_handle, int status,
 void
 ble_gap_identity_event(uint16_t conn_handle)
 {
-#if NIMBLE_BLE_SM
+#if NIMBLE_BLE_SM && NIMBLE_BLE_CONNECT
     struct ble_gap_event event;
 
     BLE_HS_LOG(DEBUG, "send identity changed");
@@ -5708,7 +5810,7 @@ ble_gap_identity_event(uint16_t conn_handle)
 int
 ble_gap_repeat_pairing_event(const struct ble_gap_repeat_pairing *rp)
 {
-#if NIMBLE_BLE_SM
+#if NIMBLE_BLE_SM && NIMBLE_BLE_CONNECT
     struct ble_gap_event event;
     int rc;
 
@@ -5743,9 +5845,7 @@ void
 ble_gap_notify_rx_event(uint16_t conn_handle, uint16_t attr_handle,
                         struct os_mbuf *om, int is_indication)
 {
-#if !MYNEWT_VAL(BLE_GATT_NOTIFY) && !MYNEWT_VAL(BLE_GATT_INDICATE)
-    return;
-#endif
+#if (MYNEWT_VAL(BLE_GATT_NOTIFY) || MYNEWT_VAL(BLE_GATT_INDICATE)) && NIMBLE_BLE_CONNECT
 
     struct ble_gap_event event;
 
@@ -5759,13 +5859,14 @@ ble_gap_notify_rx_event(uint16_t conn_handle, uint16_t attr_handle,
     ble_gap_call_conn_event_cb(&event, conn_handle);
 
     os_mbuf_free_chain(event.notify_rx.om);
+#endif
 }
 
 void
 ble_gap_notify_tx_event(int status, uint16_t conn_handle, uint16_t attr_handle,
                         int is_indication)
 {
-#if MYNEWT_VAL(BLE_GATT_NOTIFY) || MYNEWT_VAL(BLE_GATT_INDICATE)
+#if (MYNEWT_VAL(BLE_GATT_NOTIFY) || MYNEWT_VAL(BLE_GATT_INDICATE)) && NIMBLE_BLE_CONNECT
     struct ble_gap_event event;
 
     memset(&event, 0, sizeof event);
@@ -5789,6 +5890,7 @@ ble_gap_subscribe_event(uint16_t conn_handle, uint16_t attr_handle,
                         uint8_t prev_notify, uint8_t cur_notify,
                         uint8_t prev_indicate, uint8_t cur_indicate)
 {
+#if NIMBLE_BLE_CONNECT
     struct ble_gap_event event;
 
     BLE_HS_DBG_ASSERT(prev_notify != cur_notify ||
@@ -5809,6 +5911,7 @@ ble_gap_subscribe_event(uint16_t conn_handle, uint16_t attr_handle,
 
     ble_gap_event_listener_call(&event);
     ble_gap_call_conn_event_cb(&event, conn_handle);
+#endif
 }
 
 /*****************************************************************************
@@ -5818,6 +5921,7 @@ ble_gap_subscribe_event(uint16_t conn_handle, uint16_t attr_handle,
 void
 ble_gap_mtu_event(uint16_t conn_handle, uint16_t cid, uint16_t mtu)
 {
+#if NIMBLE_BLE_CONNECT
     struct ble_gap_event event;
 
     memset(&event, 0, sizeof event);
@@ -5828,6 +5932,7 @@ ble_gap_mtu_event(uint16_t conn_handle, uint16_t cid, uint16_t mtu)
 
     ble_gap_event_listener_call(&event);
     ble_gap_call_conn_event_cb(&event, conn_handle);
+#endif
 }
 
 /*****************************************************************************