You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/09/13 03:42:19 UTC

[26/41] incubator-mynewt-core git commit: syscfg / sysinit

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/drivers/nrf52/src/ble_phy.c
----------------------------------------------------------------------
diff --git a/net/nimble/drivers/nrf52/src/ble_phy.c b/net/nimble/drivers/nrf52/src/ble_phy.c
index 7389b20..46bb39a 100644
--- a/net/nimble/drivers/nrf52/src/ble_phy.c
+++ b/net/nimble/drivers/nrf52/src/ble_phy.c
@@ -20,6 +20,7 @@
 #include <stdint.h>
 #include <string.h>
 #include <assert.h>
+#include "syscfg/syscfg.h"
 #include "os/os.h"
 #include "ble/xcvr.h"
 #include "bsp/cmsis_nvic.h"
@@ -89,7 +90,7 @@ struct ble_phy_obj g_ble_phy_data;
 /* Global transmit/receive buffer */
 static uint32_t g_ble_phy_txrx_buf[(BLE_PHY_MAX_PDU_LEN + 3) / 4];
 
-#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
 /* Make sure word-aligned for faster copies */
 static uint32_t g_ble_phy_enc_buf[(BLE_PHY_MAX_PDU_LEN + 3) / 4];
 #endif
@@ -159,7 +160,7 @@ STATS_NAME_END(ble_phy_stats)
  *  bit in the NVIC just to be sure when we disable the PHY.
  */
 
-#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
 
 /*
  * Per nordic, the number of bytes needed for scratch is 16 + MAX_PKT_SIZE.
@@ -168,7 +169,7 @@ STATS_NAME_END(ble_phy_stats)
  * space for 267 bytes of scratch. I used 268 bytes since not sure if this
  * needs to be aligned and burning a byte is no big deal.
  */
-//#define NRF_ENC_SCRATCH_WORDS (((NIMBLE_OPT_LL_MAX_PKT_SIZE + 16) + 3) / 4)
+//#define NRF_ENC_SCRATCH_WORDS (((MYNEWT_VAL(BLE_LL_MAX_PKT_SIZE) + 16) + 3) / 4)
 #define NRF_ENC_SCRATCH_WORDS   (67)
 
 uint32_t g_nrf_encrypt_scratchpad[NRF_ENC_SCRATCH_WORDS];
@@ -243,7 +244,7 @@ nrf_wait_disabled(void)
 static void
 ble_phy_rx_xcvr_setup(void)
 {
-#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
     if (g_ble_phy_data.phy_encrypted) {
         NRF_RADIO->PACKETPTR = (uint32_t)&g_ble_phy_enc_buf[0];
         NRF_CCM->INPTR = (uint32_t)&g_ble_phy_enc_buf[0];
@@ -262,7 +263,7 @@ ble_phy_rx_xcvr_setup(void)
     NRF_RADIO->PACKETPTR = (uint32_t)g_ble_phy_data.rxpdu->om_data;
 #endif
 
-#if (BLE_LL_CFG_FEAT_LL_PRIVACY == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1)
     if (g_ble_phy_data.phy_privacy) {
         NRF_AAR->ENABLE = AAR_ENABLE_ENABLE_Enabled;
         NRF_AAR->IRKPTR = (uint32_t)&g_nrf_irk_list[0];
@@ -325,7 +326,7 @@ ble_phy_tx_end_isr(void)
     NRF_RADIO->EVENTS_END = 0;
     wfr_time = NRF_RADIO->SHORTS;
 
-#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
     /*
      * XXX: not sure what to do. We had a HW error during transmission.
      * For now I just count a stat but continue on like all is good.
@@ -403,7 +404,7 @@ ble_phy_rx_end_isr(void)
     } else {
         STATS_INC(ble_phy_stats, rx_valid);
         ble_hdr->rxinfo.flags |= BLE_MBUF_HDR_F_CRC_OK;
-#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
         if (g_ble_phy_data.phy_encrypted) {
             /* Only set MIC failure flag if frame is not zero length */
             if ((dptr[1] != 0) && (NRF_CCM->MICSTATUS == 0)) {
@@ -499,7 +500,7 @@ ble_phy_rx_start_isr(void)
         g_ble_phy_data.phy_rx_started = 1;
         NRF_RADIO->INTENSET = RADIO_INTENSET_END_Msk;
 
-#if (BLE_LL_CFG_FEAT_LL_PRIVACY == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1)
         /* Must start aar if we need to  */
         if (g_ble_phy_data.phy_privacy) {
             NRF_RADIO->EVENTS_BCMATCH = 0;
@@ -611,14 +612,14 @@ ble_phy_init(void)
     /* Captures tx/rx start in timer0 capture 1 */
     NRF_PPI->CHENSET = PPI_CHEN_CH26_Msk;
 
-#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
     NRF_CCM->INTENCLR = 0xffffffff;
     NRF_CCM->SHORTS = CCM_SHORTS_ENDKSGEN_CRYPT_Msk;
     NRF_CCM->EVENTS_ERROR = 0;
     memset(g_nrf_encrypt_scratchpad, 0, sizeof(g_nrf_encrypt_scratchpad));
 #endif
 
-#if (BLE_LL_CFG_FEAT_LL_PRIVACY == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1)
     g_ble_phy_data.phy_aar_scratch = 0;
     NRF_AAR->IRKPTR = (uint32_t)&g_nrf_irk_list[0];
     NRF_AAR->INTENCLR = 0xffffffff;
@@ -689,7 +690,7 @@ ble_phy_rx(void)
     return 0;
 }
 
-#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
 /**
  * Called to enable encryption at the PHY. Note that this state will persist
  * in the PHY; in other words, if you call this function you have to call
@@ -826,7 +827,7 @@ ble_phy_tx(struct os_mbuf *txpdu, uint8_t end_trans)
     ble_hdr = BLE_MBUF_HDR_PTR(txpdu);
     payload_len = ble_hdr->txinfo.pyld_len;
 
-#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LE_ENCRYPTION) == 1)
     if (g_ble_phy_data.phy_encrypted) {
         dptr = (uint8_t *)&g_ble_phy_enc_buf[0];
         NRF_CCM->SHORTS = 1;
@@ -839,14 +840,14 @@ ble_phy_tx(struct os_mbuf *txpdu, uint8_t end_trans)
         NRF_PPI->CHENCLR = PPI_CHEN_CH25_Msk | PPI_CHEN_CH23_Msk;
         NRF_PPI->CHENSET = PPI_CHEN_CH24_Msk;
     } else {
-#if (BLE_LL_CFG_FEAT_LL_PRIVACY == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1)
         NRF_PPI->CHENCLR = PPI_CHEN_CH23_Msk;
         NRF_AAR->IRKPTR = (uint32_t)&g_nrf_irk_list[0];
 #endif
         dptr = (uint8_t *)&g_ble_phy_txrx_buf[0];
     }
 #else
-#if (BLE_LL_CFG_FEAT_LL_PRIVACY == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1)
     NRF_PPI->CHENCLR = PPI_CHEN_CH23_Msk;
 #endif
     dptr = (uint8_t *)&g_ble_phy_txrx_buf[0];
@@ -1106,7 +1107,7 @@ ble_phy_max_data_pdu_pyld(void)
     return BLE_LL_DATA_PDU_MAX_PYLD;
 }
 
-#if (BLE_LL_CFG_FEAT_LL_PRIVACY == 1)
+#if (MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY) == 1)
 void
 ble_phy_resolv_list_enable(void)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/include/host/ble_gatt.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_gatt.h b/net/nimble/host/include/host/ble_gatt.h
index fbc32a2..c5bc769 100644
--- a/net/nimble/host/include/host/ble_gatt.h
+++ b/net/nimble/host/include/host/ble_gatt.h
@@ -436,8 +436,7 @@ int ble_gatts_register_svcs(const struct ble_gatt_svc_def *svcs,
 int ble_gatts_add_svcs(const struct ble_gatt_svc_def *svcs);
 int ble_gatts_count_resources(const struct ble_gatt_svc_def *svcs,
                               struct ble_gatt_resources *res);
-int ble_gatts_count_cfg(const struct ble_gatt_svc_def *defs,
-                        struct ble_hs_cfg *cfg);
+int ble_gatts_count_cfg(const struct ble_gatt_svc_def *defs);
 
 void ble_gatts_chr_updated(uint16_t chr_def_handle);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/include/host/ble_hs.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs.h b/net/nimble/host/include/host/ble_hs.h
index 954d278..7b520a5 100644
--- a/net/nimble/host/include/host/ble_hs.h
+++ b/net/nimble/host/include/host/ble_hs.h
@@ -94,58 +94,10 @@ typedef void ble_hs_reset_fn(int reason);
 typedef void ble_hs_sync_fn(void);
 
 struct ble_hs_cfg {
-    /**
-     * An HCI buffer is a "flat" 260-byte buffer.  HCI buffers are used by the
-     * controller to send unsolicited events to the host.
-     *
-     * HCI buffers can get tied up when the controller sends lots of
-     * asynchronous / unsolicited events (i.e., non-acks).  When the controller
-     * needs to send one of these events, it allocates an HCI buffer, fills it
-     * with the event payload, and puts it on a host queue.  If the controller
-     * sends a quick burst of these events, the buffer pool may be exhausted,
-     * preventing the host from sending an HCI command to the controller.
-     *
-     * Every time the controller sends a non-ack HCI event to the host, it also
-     * allocates an OS event (it is unfortunate that these are both called
-     * "events").  The OS event is put on the host-parent-task's event queue;
-     * it is what wakes up the host-parent-task and indicates that an HCI event
-     * needs to be processsed.  The pool of OS events is allocated with the
-     * same number of elements as the HCI buffer pool.
-     */
-    /* XXX: This should either be renamed to indicate it is only used for OS
-     * events, or it should go away entirely (copy the number from the
-     * transport's config).
-     */
-    uint8_t max_hci_bufs;
-
-    /*** Connection settings. */
-    /**
-     * The maximum number of concurrent connections.  This is set
-     * automatically according to the build-time option
-     * NIMBLE_OPT_MAX_CONNECTIONS.
-     */
-    uint8_t max_connections;
+    struct os_eventq *parent_evq;
 
     /*** GATT server settings. */
     /**
-     * These are acquired at service registration time and never freed.  You
-     * need one of these for every service that you register.
-     */
-    uint16_t max_services;
-
-    /**
-     * The total number of in-RAM client characteristic configuration
-     * descriptors (CCCDs).  One of these is consumed each time a peer
-     * subscribes to notifications or indications for a characteristic that
-     * your device serves.  In addition, at service registration time, the host
-     * uses one of these for each characteristic that supports notifications or
-     * indications.  So, the formula which guarantees no resource exhaustion
-     * is:
-     *     (num-subscribable-characteristics) * (max-connections + 1)
-     */
-    uint16_t max_client_configs;
-
-    /**
      * An optional callback that gets executed upon registration of each GATT
      * resource (service, characteristic, or descriptor).
      */
@@ -157,62 +109,10 @@ struct ble_hs_cfg {
      */
     void *gatts_register_arg;
 
-    /*** GATT client settings. */
-    /**
-     * The maximum number of concurrent GATT client procedures.  When you
-     * initiate a GATT procedure (e.g., read a characteristic, discover
-     * services, etc.), one of these is consumed.  The resource is freed when
-     * the procedure completes.
-     */
-    uint8_t max_gattc_procs;
-
-    /*** ATT server settings. */
-    /**
-     * The total number of local ATT attributes.  Attributes are consumed at
-     * service registration time and are never freed.  Attributes are used by
-     * GATT server entities: services, characteristics, and descriptors
-     * according to the following formula:
-     *     (num-services + (num-characteristics * 2) + num-descriptors)
-     *
-     * Every characteristic that supports indications or notifications
-     * automatically gets a descriptor.  All other descriptors are specified by
-     * the application at service registration time.
-     */
-    uint16_t max_attrs;
-
-    /**
-     * A GATT server uses these when a peer performs a "write long
-     * characteristic values" or "write long characteristic descriptors"
-     * procedure.  One of these resources is consumed each time a peer sends a
-     * partial write.  These procedures are not used often.
-     */
-    uint8_t max_prep_entries;
-
-    /*** L2CAP settings. */
-    /**
-     * Each connection requires three L2CAP channels (signal, ATT, and security
-     * manager).  In addition, the nimble host may allow channels to be created
-     * "on the fly" (connection-oriented channels).  This functionality is not
-     * available at the moment, so a safe formula to use is:
-     *     (max-connections * 3)
-     */
-    uint8_t max_l2cap_chans;
-
-    /**
-     * The maximum number of concurrent L2CAP signalling procedures.  Only one
-     * L2CAP signalling procedure is supported: slave-initiated connection
-     * update.  You will never need more of these than the max number of
-     * connections.
-     */
-    uint8_t max_l2cap_sig_procs;
-
-    /**
-     * The maximum number of concurrent security manager procedures.  Security
-     * manager procedures include pairing and restoration of a bonded link.
+    /***
+     * Security manager settings.  The only reason these are configurable at
+     * runtime is to simplify security testing.
      */
-    uint8_t max_l2cap_sm_procs;
-
-    /*** Security manager settings. */
     uint8_t sm_io_cap;
     unsigned sm_oob_data_flag:1;
     unsigned sm_bonding:1;
@@ -239,23 +139,18 @@ struct ble_hs_cfg {
     /**
      * These function callbacks handle persistence of sercurity material
      * (bonding).
+     * XXX: These need to go away.  Instead, the nimble host package should
+     * require the host-store API (not yet implemented)..
      */
     ble_store_read_fn *store_read_cb;
     ble_store_write_fn *store_write_cb;
     ble_store_delete_fn *store_delete_cb;
-
-    /*** Privacy settings. */
-    /**
-     * The frequency at which new resovlable private addresses are generated.
-     * Units are seconds.
-     */
-    uint16_t rpa_timeout;
 };
 
-extern const struct ble_hs_cfg ble_hs_cfg_dflt;
+extern struct ble_hs_cfg ble_hs_cfg;
 
 int ble_hs_synced(void);
 int ble_hs_start(void);
-int ble_hs_init(struct os_eventq *app_evq, struct ble_hs_cfg *cfg);
+void ble_hs_init(void);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/include/host/ble_sm.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_sm.h b/net/nimble/host/include/host/ble_sm.h
index 51052ea..748ff2d 100644
--- a/net/nimble/host/include/host/ble_sm.h
+++ b/net/nimble/host/include/host/ble_sm.h
@@ -21,7 +21,7 @@
 #define H_BLE_SM_
 
 #include <inttypes.h>
-#include "nimble/nimble_opt.h"
+#include "syscfg/syscfg.h"
 
 #define BLE_SM_ERR_PASSKEY                      0x01
 #define BLE_SM_ERR_OOB                          0x02
@@ -91,7 +91,7 @@ struct ble_sm_io {
     };
 };
 
-#if NIMBLE_OPT(SM)
+#if NIMBLE_BLE_SM
 int ble_sm_inject_io(uint16_t conn_handle, struct ble_sm_io *pkey);
 #else
 #define ble_sm_inject_io(conn_handle, pkey) \

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/pkg.yml b/net/nimble/host/pkg.yml
index a45ba1e..c08545b 100644
--- a/net/nimble/host/pkg.yml
+++ b/net/nimble/host/pkg.yml
@@ -30,29 +30,203 @@ pkg.deps:
     - sys/stats
     - libs/os
     - libs/util
-    - libs/mbedtls
     - net/nimble
 
-    # Tinycrypt is only required when secure connections (NIMBPLE_OPT_SM_SC)
-    # is enabled.  It always gets built as a dependency, but not is not
-    # included by the linker unless SC is enabled.  XXX: We should not build
-    # this library if it is not required.
+pkg.deps.BLE_SM:
+    - libs/mbedtls
+
+pkg.deps.BLE_SM_SC:
     - libs/tinycrypt
 
 pkg.req_apis:
     - ble_transport
     - console
 
-pkg.features:
-    - BLE_HOST
+pkg.init_function: "ble_hs_init"
+pkg.init_stage: 2
+
+pkg.syscfg_defs:
+    # Debug settings.
+    BLE_HS_DEBUG:
+        description: 'TBD'
+        value: 0
+    BLE_HS_PHONY_HCI_ACKS:
+        description: 'TBD'
+        value: 0
+    BLE_HS_REQUIRE_OS:
+        description: 'TBD'
+        value: 1
+
+    # Misc settings.
+    BLE_HS_HEARTBEAT_FREQ:
+        description: 'Milliseconds.'
+        value: 1000
+
+    # L2CAP settings.
+    BLE_L2CAP_MAX_CHANS:
+        description: 'TBD'
+        value: '3*MYNEWT_VAL_BLE_MAX_CONNECTIONS'
+    BLE_L2CAP_SIG_MAX_PROCS:
+        description: 'TBD'
+        value: 1
+
+    # Security manager settings.
+    BLE_SM:
+        description: 'Security manager legacy pairing.'
+        value: 1
+    BLE_SM_SC:
+        description: 'Security manager secure connections (4.2).'
+        value: 0
+
+    BLE_SM_MAX_PROCS:
+        description: 'TBD'
+        value: 1
+    BLE_SM_IO_CAP:
+        description: 'TBD'
+        value: 'BLE_HS_IO_NO_INPUT_OUTPUT'
+    BLE_SM_OOB_DATA_FLAG:
+        description: 'TBD'
+        value: 0
+    BLE_SM_BONDING:
+        description: 'TBD'
+        value: 0
+    BLE_SM_MITM:
+        description: 'TBD'
+        value: 0
+    BLE_SM_KEYPRESS:
+        description: 'TBD'
+        value: 0
+    BLE_SM_OUR_KEY_DIST:
+        description: 'TBD'
+        value: 0
+    BLE_SM_THEIR_KEY_DIST:
+        description: 'TBD'
+        value: 0
+
+    # Supported GATT procedures.  By default:
+    #     o Notify and indicate are enabled;
+    #     o All other procedures are enabled for centrals.
+    BLE_GATT_DISC_ALL_SVCS:
+        description: 'TBD'
+        value: MYNEWT_VAL_BLE_ROLE_CENTRAL
+    BLE_GATT_DISC_SVC_UUID:
+        description: 'TBD'
+        value: MYNEWT_VAL_BLE_ROLE_CENTRAL
+    BLE_GATT_FIND_INC_SVCS:
+        description: 'TBD'
+        value: MYNEWT_VAL_BLE_ROLE_CENTRAL
+    BLE_GATT_DISC_ALL_CHRS:
+        description: 'TBD'
+        value: MYNEWT_VAL_BLE_ROLE_CENTRAL
+    BLE_GATT_DISC_CHR_UUID:
+        description: 'TBD'
+        value: MYNEWT_VAL_BLE_ROLE_CENTRAL
+    BLE_GATT_DISC_ALL_DSCS:
+        description: 'TBD'
+        value: MYNEWT_VAL_BLE_ROLE_CENTRAL
+    BLE_GATT_READ:
+        description: 'TBD'
+        value: MYNEWT_VAL_BLE_ROLE_CENTRAL
+    BLE_GATT_READ_UUID:
+        description: 'TBD'
+        value: MYNEWT_VAL_BLE_ROLE_CENTRAL
+    BLE_GATT_READ_LONG:
+        description: 'TBD'
+        value: MYNEWT_VAL_BLE_ROLE_CENTRAL
+    BLE_GATT_READ_MULT:
+        description: 'TBD'
+        value: MYNEWT_VAL_BLE_ROLE_CENTRAL
+    BLE_GATT_WRITE_NO_RSP:
+        description: 'TBD'
+        value: MYNEWT_VAL_BLE_ROLE_CENTRAL
+    BLE_GATT_SIGNED_WRITE:
+        description: 'TBD'
+        value: MYNEWT_VAL_BLE_ROLE_CENTRAL
+    BLE_GATT_WRITE:
+        description: 'TBD'
+        value: MYNEWT_VAL_BLE_ROLE_CENTRAL
+    BLE_GATT_WRITE_LONG:
+        description: 'TBD'
+        value: MYNEWT_VAL_BLE_ROLE_CENTRAL
+    BLE_GATT_WRITE_RELIABLE:
+        description: 'TBD'
+        value: MYNEWT_VAL_BLE_ROLE_CENTRAL
+    BLE_GATT_NOTIFY:
+        description: 'TBD'
+        value: 1
+    BLE_GATT_INDICATE:
+        description: 'TBD'
+        value: 1
+
+    # GATT options.
+    BLE_GATT_WRITE_MAX_ATTRS:
+        description: >
+            The maximum number of attributes that can be written with a single
+            GATT Reliable Write procedure.
+        value: 4
+    BLE_GATT_MAX_PROCS:
+        description: 'TBD'
+        value: 4
+
+    # Supported server ATT commands.
+    BLE_ATT_SVR_FIND_INFO:
+        description: 'TBD'
+        value: 1
+    BLE_ATT_SVR_FIND_TYPE:
+        description: 'TBD'
+        value: 1
+    BLE_ATT_SVR_READ_TYPE:
+        description: 'TBD'
+        value: 1
+    BLE_ATT_SVR_READ:
+        description: 'TBD'
+        value: 1
+    BLE_ATT_SVR_READ_BLOB:
+        description: 'TBD'
+        value: 1
+    BLE_ATT_SVR_READ_MULT:
+        description: 'TBD'
+        value: 1
+    BLE_ATT_SVR_READ_GROUP_TYPE:
+        description: 'TBD'
+        value: 1
+    BLE_ATT_SVR_WRITE:
+        description: 'TBD'
+        value: 1
+    BLE_ATT_SVR_WRITE_NO_RSP:
+        description: 'TBD'
+        value: 1
+    BLE_ATT_SVR_SIGNED_WRITE:
+        description: 'TBD'
+        value: 1
+    BLE_ATT_SVR_PREP_WRITE:
+        description: 'TBD'
+        value: 1
+    BLE_ATT_SVR_EXEC_WRITE:
+        description: 'TBD'
+        value: 1
+    BLE_ATT_SVR_NOTIFY:
+        description: 'TBD'
+        value: 1
+    BLE_ATT_SVR_INDICATE:
+        description: 'TBD'
+        value: 1
+
+    # ATT options.
+    BLE_ATT_MAX_PREP_ENTRIES:
+        description: >
+            A GATT server uses these when a peer performs a "write long
+            characteristic values" or "write long characteristic descriptors"
+            procedure.  One of these resources is consumed each time a peer
+            sends a partial write.
+        value: 64
 
-# Satisfy capability dependencies for the self-contained test executable.
-pkg.deps.SELFTEST:
-    - libs/console/stub
-    - net/nimble/transport/ram
+    # Privacy options.
+    BLE_RPA_TIMEOUT:
+        description: 'TBD'
+        value: 300
 
-pkg.cflags.SELFTEST:
-    - "-DPHONY_HCI_ACKS=1"
-    - "-DNIMBLE_OPT_SM=1"
-    - "-DNIMBLE_OPT_SM_SC=1"
-pkg.cflags.TEST: -DBLE_HS_DEBUG
+    # Miscellaneous features.
+    BLE_EDDYSTONE:
+        description: 'TBD'
+        value: 1

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/services/mandatory/include/services/mandatory/ble_svc_gap.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/mandatory/include/services/mandatory/ble_svc_gap.h b/net/nimble/host/services/mandatory/include/services/mandatory/ble_svc_gap.h
index 95d4226..dcc2712 100644
--- a/net/nimble/host/services/mandatory/include/services/mandatory/ble_svc_gap.h
+++ b/net/nimble/host/services/mandatory/include/services/mandatory/ble_svc_gap.h
@@ -34,6 +34,6 @@ struct ble_hs_cfg;
 const char *ble_svc_gap_device_name(void);
 int ble_svc_gap_device_name_set(const char *name);
 
-int ble_svc_gap_init(struct ble_hs_cfg *cfg);
+int ble_svc_gap_init(void);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/services/mandatory/include/services/mandatory/ble_svc_gatt.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/mandatory/include/services/mandatory/ble_svc_gatt.h b/net/nimble/host/services/mandatory/include/services/mandatory/ble_svc_gatt.h
index d2438c2..721946f 100644
--- a/net/nimble/host/services/mandatory/include/services/mandatory/ble_svc_gatt.h
+++ b/net/nimble/host/services/mandatory/include/services/mandatory/ble_svc_gatt.h
@@ -5,6 +5,6 @@ struct ble_hs_cfg;
 
 #define BLE_SVC_GATT_CHR_SERVICE_CHANGED_UUID16     0x2a05
 
-int ble_svc_gatt_init(struct ble_hs_cfg *cfg);
+int ble_svc_gatt_init(void);
 
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/services/mandatory/pkg.yml
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/mandatory/pkg.yml b/net/nimble/host/services/mandatory/pkg.yml
index b63c634..255d49b 100644
--- a/net/nimble/host/services/mandatory/pkg.yml
+++ b/net/nimble/host/services/mandatory/pkg.yml
@@ -30,3 +30,6 @@ pkg.keywords:
 
 pkg.deps:
     - net/nimble/host
+
+pkg.init_function: ble_svc_mandatory_pkg_init
+pkg.init_stage: 3

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/services/mandatory/src/ble_svc_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/mandatory/src/ble_svc_gap.c b/net/nimble/host/services/mandatory/src/ble_svc_gap.c
index d49396d..11f9d23 100644
--- a/net/nimble/host/services/mandatory/src/ble_svc_gap.c
+++ b/net/nimble/host/services/mandatory/src/ble_svc_gap.c
@@ -149,11 +149,11 @@ ble_svc_gap_device_name_set(const char *name)
 }
 
 int
-ble_svc_gap_init(struct ble_hs_cfg *cfg)
+ble_svc_gap_init(void)
 {
     int rc;
 
-    rc = ble_gatts_count_cfg(ble_svc_gap_defs, cfg);
+    rc = ble_gatts_count_cfg(ble_svc_gap_defs);
     if (rc != 0) {
         return rc;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/services/mandatory/src/ble_svc_gatt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/mandatory/src/ble_svc_gatt.c b/net/nimble/host/services/mandatory/src/ble_svc_gatt.c
index 0e8a139..616aa42 100644
--- a/net/nimble/host/services/mandatory/src/ble_svc_gatt.c
+++ b/net/nimble/host/services/mandatory/src/ble_svc_gatt.c
@@ -72,11 +72,11 @@ ble_svc_gatt_access(uint16_t conn_handle, uint16_t attr_handle,
 }
 
 int
-ble_svc_gatt_init(struct ble_hs_cfg *cfg)
+ble_svc_gatt_init(void)
 {
     int rc;
 
-    rc = ble_gatts_count_cfg(ble_svc_gatt_defs, cfg);
+    rc = ble_gatts_count_cfg(ble_svc_gatt_defs);
     if (rc != 0) {
         return rc;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/services/mandatory/src/ble_svc_mandatory.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/services/mandatory/src/ble_svc_mandatory.c b/net/nimble/host/services/mandatory/src/ble_svc_mandatory.c
new file mode 100644
index 0000000..90fdb4b
--- /dev/null
+++ b/net/nimble/host/services/mandatory/src/ble_svc_mandatory.c
@@ -0,0 +1,36 @@
+/**
+ * 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.
+ */
+
+#include <assert.h>
+
+#include "sysinit/sysinit.h"
+#include "services/mandatory/ble_svc_gap.h"
+#include "services/mandatory/ble_svc_gatt.h"
+
+void
+ble_svc_mandatory_pkg_init(void)
+{
+    int rc;
+
+    rc = ble_svc_gap_init();
+    SYSINIT_PANIC_ASSERT(rc == 0);
+
+    rc = ble_svc_gatt_init();
+    SYSINIT_PANIC_ASSERT(rc == 0);
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_att_clt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_clt.c b/net/nimble/host/src/ble_att_clt.c
index 87e2f44..e9a882c 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -187,7 +187,7 @@ int
 ble_att_clt_tx_find_info(uint16_t conn_handle,
                          const struct ble_att_find_info_req *req)
 {
-#if !NIMBLE_OPT(ATT_CLT_FIND_INFO)
+#if !NIMBLE_BLE_ATT_CLT_FIND_INFO
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -273,7 +273,7 @@ ble_att_clt_parse_find_info_entry(struct os_mbuf **rxom, uint8_t rsp_format,
 int
 ble_att_clt_rx_find_info(uint16_t conn_handle, struct os_mbuf **om)
 {
-#if !NIMBLE_OPT(ATT_CLT_FIND_INFO)
+#if !NIMBLE_BLE_ATT_CLT_FIND_INFO
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -320,7 +320,7 @@ ble_att_clt_tx_find_type_value(uint16_t conn_handle,
                                const struct ble_att_find_type_value_req *req,
                                const void *attribute_value, int value_len)
 {
-#if !NIMBLE_OPT(ATT_CLT_FIND_TYPE)
+#if !NIMBLE_BLE_ATT_CLT_FIND_TYPE
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -384,7 +384,7 @@ ble_att_clt_parse_find_type_value_hinfo(
 int
 ble_att_clt_rx_find_type_value(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_CLT_FIND_TYPE)
+#if !NIMBLE_BLE_ATT_CLT_FIND_TYPE
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -426,7 +426,7 @@ ble_att_clt_tx_read_type(uint16_t conn_handle,
                          const struct ble_att_read_type_req *req,
                          const void *uuid128)
 {
-#if !NIMBLE_OPT(ATT_CLT_READ_TYPE)
+#if !NIMBLE_BLE_ATT_CLT_READ_TYPE
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -491,7 +491,7 @@ ble_att_clt_parse_read_type_adata(struct os_mbuf **om, int data_len,
 int
 ble_att_clt_rx_read_type(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_CLT_READ_TYPE)
+#if !NIMBLE_BLE_ATT_CLT_READ_TYPE
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -536,7 +536,7 @@ done:
 int
 ble_att_clt_tx_read(uint16_t conn_handle, const struct ble_att_read_req *req)
 {
-#if !NIMBLE_OPT(ATT_CLT_READ)
+#if !NIMBLE_BLE_ATT_CLT_READ
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -566,7 +566,7 @@ ble_att_clt_tx_read(uint16_t conn_handle, const struct ble_att_read_req *req)
 int
 ble_att_clt_rx_read(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_CLT_READ)
+#if !NIMBLE_BLE_ATT_CLT_READ
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -590,7 +590,7 @@ int
 ble_att_clt_tx_read_blob(uint16_t conn_handle,
                          const struct ble_att_read_blob_req *req)
 {
-#if !NIMBLE_OPT(ATT_CLT_READ_BLOB)
+#if !NIMBLE_BLE_ATT_CLT_READ_BLOB
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -621,7 +621,7 @@ ble_att_clt_tx_read_blob(uint16_t conn_handle,
 int
 ble_att_clt_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_CLT_READ_BLOB)
+#if !NIMBLE_BLE_ATT_CLT_READ_BLOB
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -681,7 +681,7 @@ int
 ble_att_clt_tx_read_mult(uint16_t conn_handle, const uint16_t *att_handles,
                          int num_att_handles)
 {
-#if !NIMBLE_OPT(ATT_CLT_READ_MULT)
+#if !NIMBLE_BLE_ATT_CLT_READ_MULT
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -710,7 +710,7 @@ ble_att_clt_tx_read_mult(uint16_t conn_handle, const uint16_t *att_handles,
 int
 ble_att_clt_rx_read_mult(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_CLT_READ_MULT)
+#if !NIMBLE_BLE_ATT_CLT_READ_MULT
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -735,7 +735,7 @@ ble_att_clt_tx_read_group_type(uint16_t conn_handle,
                                const struct ble_att_read_group_type_req *req,
                                const void *uuid128)
 {
-#if !NIMBLE_OPT(ATT_CLT_READ_GROUP_TYPE)
+#if !NIMBLE_BLE_ATT_CLT_READ_GROUP_TYPE
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -805,7 +805,7 @@ ble_att_clt_parse_read_group_type_adata(
 int
 ble_att_clt_rx_read_group_type(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_CLT_READ_GROUP_TYPE)
+#if !NIMBLE_BLE_ATT_CLT_READ_GROUP_TYPE
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -878,7 +878,7 @@ ble_att_clt_tx_write_req(uint16_t conn_handle,
                          const struct ble_att_write_req *req,
                          struct os_mbuf *txom)
 {
-#if !NIMBLE_OPT(ATT_CLT_WRITE)
+#if !NIMBLE_BLE_ATT_CLT_WRITE
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -895,7 +895,7 @@ ble_att_clt_tx_write_cmd(uint16_t conn_handle,
                          const struct ble_att_write_req *req,
                          struct os_mbuf *txom)
 {
-#if !NIMBLE_OPT(ATT_CLT_WRITE_NO_RSP)
+#if !NIMBLE_BLE_ATT_CLT_WRITE_NO_RSP
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -910,7 +910,7 @@ ble_att_clt_tx_write_cmd(uint16_t conn_handle,
 int
 ble_att_clt_rx_write(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_CLT_WRITE)
+#if !NIMBLE_BLE_ATT_CLT_WRITE
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -930,7 +930,7 @@ ble_att_clt_tx_prep_write(uint16_t conn_handle,
                           const struct ble_att_prep_write_cmd *req,
                           struct os_mbuf *txom)
 {
-#if !NIMBLE_OPT(ATT_CLT_PREP_WRITE)
+#if !NIMBLE_BLE_ATT_CLT_PREP_WRITE
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -981,7 +981,7 @@ err:
 int
 ble_att_clt_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_CLT_PREP_WRITE)
+#if !NIMBLE_BLE_ATT_CLT_PREP_WRITE
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -1017,7 +1017,7 @@ int
 ble_att_clt_tx_exec_write(uint16_t conn_handle,
                           const struct ble_att_exec_write_req *req)
 {
-#if !NIMBLE_OPT(ATT_CLT_EXEC_WRITE)
+#if !NIMBLE_BLE_ATT_CLT_EXEC_WRITE
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -1048,7 +1048,7 @@ ble_att_clt_tx_exec_write(uint16_t conn_handle,
 int
 ble_att_clt_rx_exec_write(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_CLT_EXEC_WRITE)
+#if !NIMBLE_BLE_ATT_CLT_EXEC_WRITE
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -1074,7 +1074,7 @@ ble_att_clt_tx_notify(uint16_t conn_handle,
                       const struct ble_att_notify_req *req,
                       struct os_mbuf *txom)
 {
-#if !NIMBLE_OPT(ATT_CLT_NOTIFY)
+#if !NIMBLE_BLE_ATT_CLT_NOTIFY
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -1116,7 +1116,7 @@ ble_att_clt_tx_indicate(uint16_t conn_handle,
                         const struct ble_att_indicate_req *req,
                         struct os_mbuf *txom)
 {
-#if !NIMBLE_OPT(ATT_CLT_INDICATE)
+#if !NIMBLE_BLE_ATT_CLT_INDICATE
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -1155,7 +1155,7 @@ err:
 int
 ble_att_clt_rx_indicate(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_CLT_INDICATE)
+#if !NIMBLE_BLE_ATT_CLT_INDICATE
     return BLE_HS_ENOTSUP;
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index edf9dce..04e4365 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -174,6 +174,8 @@ int ble_att_init(void);
 
 /*** @svr */
 
+int ble_att_svr_start(void);
+
 struct ble_att_svr_entry *
 ble_att_svr_find_by_uuid(struct ble_att_svr_entry *start_at,
                          const uint8_t *uuid,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index 93c57ff..0caf7ca 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -33,7 +33,11 @@ static uint16_t ble_att_svr_id;
 static void *ble_att_svr_entry_mem;
 static struct os_mempool ble_att_svr_entry_pool;
 
-static void *ble_att_svr_prep_entry_mem;
+static os_membuf_t ble_att_svr_prep_entry_mem[
+    OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_ATT_MAX_PREP_ENTRIES),
+                    sizeof (struct ble_att_prep_entry))
+];
+
 static struct os_mempool ble_att_svr_prep_entry_pool;
 
 static struct ble_att_svr_entry *
@@ -876,7 +880,7 @@ done:
 int
 ble_att_svr_rx_find_info(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_SVR_FIND_INFO)
+#if !MYNEWT_VAL(BLE_ATT_SVR_FIND_INFO)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -1193,7 +1197,7 @@ done:
 int
 ble_att_svr_rx_find_type_value(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_SVR_FIND_TYPE)
+#if !MYNEWT_VAL(BLE_ATT_SVR_FIND_TYPE)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -1372,7 +1376,7 @@ done:
 int
 ble_att_svr_rx_read_type(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_SVR_READ_TYPE)
+#if !MYNEWT_VAL(BLE_ATT_SVR_READ_TYPE)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -1456,7 +1460,7 @@ done:
 int
 ble_att_svr_rx_read(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_SVR_READ)
+#if !MYNEWT_VAL(BLE_ATT_SVR_READ)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -1512,7 +1516,7 @@ done:
 int
 ble_att_svr_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_SVR_READ_BLOB)
+#if !MYNEWT_VAL(BLE_ATT_SVR_READ_BLOB)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -1653,7 +1657,7 @@ done:
 int
 ble_att_svr_rx_read_mult(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_SVR_READ_MULT)
+#if !MYNEWT_VAL(BLE_ATT_SVR_READ_MULT)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -1960,7 +1964,7 @@ done:
 int
 ble_att_svr_rx_read_group_type(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_SVR_READ_GROUP_TYPE)
+#if !MYNEWT_VAL(BLE_ATT_SVR_READ_GROUP_TYPE)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -2066,7 +2070,7 @@ done:
 int
 ble_att_svr_rx_write(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_SVR_WRITE)
+#if !MYNEWT_VAL(BLE_ATT_SVR_WRITE)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -2120,7 +2124,7 @@ done:
 int
 ble_att_svr_rx_write_no_rsp(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_SVR_WRITE_NO_RSP)
+#if !MYNEWT_VAL(BLE_ATT_SVR_WRITE_NO_RSP)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -2415,7 +2419,7 @@ ble_att_svr_insert_prep_entry(uint16_t conn_handle,
 int
 ble_att_svr_rx_prep_write(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_SVR_PREP_WRITE)
+#if !MYNEWT_VAL(BLE_ATT_SVR_PREP_WRITE)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -2529,7 +2533,7 @@ done:
 int
 ble_att_svr_rx_exec_write(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_SVR_EXEC_WRITE)
+#if !MYNEWT_VAL(BLE_ATT_SVR_EXEC_WRITE)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -2603,7 +2607,7 @@ done:
 int
 ble_att_svr_rx_notify(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_SVR_NOTIFY)
+#if !MYNEWT_VAL(BLE_ATT_SVR_NOTIFY)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -2670,7 +2674,7 @@ done:
 int
 ble_att_svr_rx_indicate(uint16_t conn_handle, struct os_mbuf **rxom)
 {
-#if !NIMBLE_OPT(ATT_SVR_INDICATE)
+#if !MYNEWT_VAL(BLE_ATT_SVR_INDICATE)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -2721,29 +2725,29 @@ done:
 }
 
 static void
-ble_att_svr_free_mem(void)
+ble_att_svr_free_start_mem(void)
 {
     free(ble_att_svr_entry_mem);
     ble_att_svr_entry_mem = NULL;
 }
 
 int
-ble_att_svr_init(void)
+ble_att_svr_start(void)
 {
     int rc;
 
-    ble_att_svr_free_mem();
+    ble_att_svr_free_start_mem();
 
-    if (ble_hs_cfg.max_attrs > 0) {
+    if (ble_hs_max_attrs > 0) {
         ble_att_svr_entry_mem = malloc(
-            OS_MEMPOOL_BYTES(ble_hs_cfg.max_attrs,
+            OS_MEMPOOL_BYTES(ble_hs_max_attrs,
                              sizeof (struct ble_att_svr_entry)));
         if (ble_att_svr_entry_mem == NULL) {
             rc = BLE_HS_ENOMEM;
             goto err;
         }
 
-        rc = os_mempool_init(&ble_att_svr_entry_pool, ble_hs_cfg.max_attrs,
+        rc = os_mempool_init(&ble_att_svr_entry_pool, ble_hs_max_attrs,
                              sizeof (struct ble_att_svr_entry),
                              ble_att_svr_entry_mem, "ble_att_svr_entry_pool");
         if (rc != 0) {
@@ -2752,23 +2756,26 @@ ble_att_svr_init(void)
         }
     }
 
-    if (ble_hs_cfg.max_prep_entries > 0) {
-        ble_att_svr_prep_entry_mem = malloc(
-            OS_MEMPOOL_BYTES(ble_hs_cfg.max_prep_entries,
-                             sizeof (struct ble_att_prep_entry)));
-        if (ble_att_svr_prep_entry_mem == NULL) {
-            rc = BLE_HS_ENOMEM;
-            goto err;
-        }
+    return 0;
+
+err:
+    ble_att_svr_free_start_mem();
+    return rc;
+}
 
+int
+ble_att_svr_init(void)
+{
+    int rc;
+
+    if (MYNEWT_VAL(BLE_ATT_MAX_PREP_ENTRIES) > 0) {
         rc = os_mempool_init(&ble_att_svr_prep_entry_pool,
-                             ble_hs_cfg.max_prep_entries,
+                             MYNEWT_VAL(BLE_ATT_MAX_PREP_ENTRIES),
                              sizeof (struct ble_att_prep_entry),
                              ble_att_svr_prep_entry_mem,
                              "ble_att_svr_prep_entry_pool");
         if (rc != 0) {
-            rc = BLE_HS_EOS;
-            goto err;
+            return BLE_HS_EOS;
         }
     }
 
@@ -2777,8 +2784,4 @@ ble_att_svr_init(void)
     ble_att_svr_id = 0;
 
     return 0;
-
-err:
-    ble_att_svr_free_mem();
-    return rc;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_eddystone.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_eddystone.c b/net/nimble/host/src/ble_eddystone.c
index 2ca496f..ca43828 100644
--- a/net/nimble/host/src/ble_eddystone.c
+++ b/net/nimble/host/src/ble_eddystone.c
@@ -122,7 +122,7 @@ ble_eddystone_set_adv_data_gen(struct ble_hs_adv_fields *adv_fields,
 int
 ble_eddystone_set_adv_data_uid(struct ble_hs_adv_fields *adv_fields, void *uid)
 {
-#if !NIMBLE_OPT(EDDYSTONE)
+#if !MYNEWT_VAL(BLE_EDDYSTONE)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -167,7 +167,7 @@ ble_eddystone_set_adv_data_url(struct ble_hs_adv_fields *adv_fields,
                                uint8_t url_scheme, char *url_body,
                                uint8_t url_body_len, uint8_t url_suffix)
 {
-#if !NIMBLE_OPT(EDDYSTONE)
+#if !MYNEWT_VAL(BLE_EDDYSTONE)
     return BLE_HS_ENOTSUP;
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index 49d678e..81be873 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -743,7 +743,7 @@ ble_gap_conn_broken(uint16_t conn_handle, int reason)
 void
 ble_gap_rx_disconn_complete(struct hci_disconn_complete *evt)
 {
-#if !NIMBLE_OPT(CONNECT)
+#if !NIMBLE_BLE_CONNECT
     return;
 #endif
 
@@ -766,7 +766,7 @@ ble_gap_rx_disconn_complete(struct hci_disconn_complete *evt)
 void
 ble_gap_rx_update_complete(struct hci_le_conn_upd_complete *evt)
 {
-#if !NIMBLE_OPT(CONNECT)
+#if !NIMBLE_BLE_CONNECT
     return;
 #endif
 
@@ -905,7 +905,7 @@ ble_gap_accept_slave_conn(uint8_t addr_type, uint8_t *addr)
 void
 ble_gap_rx_adv_report(struct ble_gap_disc_desc *desc)
 {
-#if !NIMBLE_OPT(ROLE_OBSERVER)
+#if !MYNEWT_VAL(BLE_ROLE_OBSERVER)
     return;
 #endif
 
@@ -943,7 +943,7 @@ ble_gap_rx_adv_report(struct ble_gap_disc_desc *desc)
 int
 ble_gap_rx_conn_complete(struct hci_le_conn_complete *evt)
 {
-#if !NIMBLE_OPT(CONNECT)
+#if !NIMBLE_BLE_CONNECT
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -1183,7 +1183,7 @@ ble_gap_heartbeat(void)
 static int
 ble_gap_wl_busy(void)
 {
-#if !NIMBLE_OPT(WHITELIST)
+#if !MYNEWT_VAL(BLE_WHITELIST)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -1241,7 +1241,7 @@ int
 ble_gap_wl_set(const struct ble_gap_white_entry *white_list,
                uint8_t white_list_count)
 {
-#if !NIMBLE_OPT(WHITELIST)
+#if !MYNEWT_VAL(BLE_WHITELIST)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -1330,7 +1330,7 @@ ble_gap_adv_enable_tx(int enable)
 int
 ble_gap_adv_stop(void)
 {
-#if !NIMBLE_OPT(ADVERTISE)
+#if !NIMBLE_BLE_ADVERTISE
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -1674,7 +1674,7 @@ ble_gap_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type,
                   const struct ble_gap_adv_params *adv_params,
                   ble_gap_event_fn *cb, void *cb_arg)
 {
-#if !NIMBLE_OPT(ADVERTISE)
+#if !NIMBLE_BLE_ADVERTISE
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -1768,7 +1768,7 @@ done:
 int
 ble_gap_adv_set_fields(const struct ble_hs_adv_fields *adv_fields)
 {
-#if !NIMBLE_OPT(ADVERTISE)
+#if !NIMBLE_BLE_ADVERTISE
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -1825,7 +1825,7 @@ done:
 int
 ble_gap_adv_rsp_set_fields(const struct ble_hs_adv_fields *rsp_fields)
 {
-#if !NIMBLE_OPT(ADVERTISE)
+#if !NIMBLE_BLE_ADVERTISE
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -2038,7 +2038,7 @@ ble_gap_disc(uint8_t own_addr_type, int32_t duration_ms,
              const struct ble_gap_disc_params *disc_params,
              ble_gap_event_fn *cb, void *cb_arg)
 {
-#if !NIMBLE_OPT(ROLE_OBSERVER)
+#if !MYNEWT_VAL(BLE_ROLE_OBSERVER)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -2223,7 +2223,7 @@ ble_gap_connect(uint8_t own_addr_type,
                 const struct ble_gap_conn_params *conn_params,
                 ble_gap_event_fn *cb, void *cb_arg)
 {
-#if !NIMBLE_OPT(ROLE_CENTRAL)
+#if !MYNEWT_VAL(BLE_ROLE_CENTRAL)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -2493,7 +2493,7 @@ ble_gap_tx_param_neg_reply(uint16_t conn_handle, uint8_t reject_reason)
 void
 ble_gap_rx_param_req(struct hci_le_conn_param_req *evt)
 {
-#if !NIMBLE_OPT(CONNECT)
+#if !NIMBLE_BLE_CONNECT
     return;
 #endif
 
@@ -2592,7 +2592,7 @@ int
 ble_gap_update_params(uint16_t conn_handle,
                       const struct ble_gap_upd_params *params)
 {
-#if !NIMBLE_OPT(CONNECT)
+#if !NIMBLE_BLE_CONNECT
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -2654,7 +2654,7 @@ done:
 int
 ble_gap_security_initiate(uint16_t conn_handle)
 {
-#if !NIMBLE_OPT(SM)
+#if !NIMBLE_BLE_SM
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -2737,7 +2737,7 @@ ble_gap_encryption_initiate(uint16_t conn_handle,
                             uint64_t rand_val,
                             int auth)
 {
-#if !NIMBLE_OPT(SM)
+#if !NIMBLE_BLE_SM
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -2761,7 +2761,7 @@ void
 ble_gap_passkey_event(uint16_t conn_handle,
                       struct ble_gap_passkey_params *passkey_params)
 {
-#if !NIMBLE_OPT(SM)
+#if !NIMBLE_BLE_SM
     return;
 #endif
 
@@ -2780,7 +2780,7 @@ ble_gap_passkey_event(uint16_t conn_handle,
 void
 ble_gap_enc_event(uint16_t conn_handle, int status, int security_restored)
 {
-#if !NIMBLE_OPT(SM)
+#if !NIMBLE_BLE_SM
     return;
 #endif
 
@@ -2831,7 +2831,7 @@ void
 ble_gap_notify_rx_event(uint16_t conn_handle, uint16_t attr_handle,
                         struct os_mbuf *om, int is_indication)
 {
-#if !NIMBLE_OPT(GATT_NOTIFY) && !NIMBLE_OPT(GATT_INDICATE)
+#if !MYNEWT_VAL(BLE_GATT_NOTIFY) && !MYNEWT_VAL(BLE_GATT_INDICATE)
     return;
 #endif
 
@@ -2852,7 +2852,7 @@ void
 ble_gap_notify_tx_event(int status, uint16_t conn_handle, uint16_t attr_handle,
                         int is_indication)
 {
-#if !NIMBLE_OPT(GATT_NOTIFY) && !NIMBLE_OPT(GATT_INDICATE)
+#if !MYNEWT_VAL(BLE_GATT_NOTIFY) && !MYNEWT_VAL(BLE_GATT_INDICATE)
     return;
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_gattc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c
index 43d2134..e37deaf 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -182,7 +182,7 @@ struct ble_gattc_proc {
         } write_long;
 
         struct {
-            struct ble_gatt_attr attrs[NIMBLE_OPT(GATT_WRITE_MAX_ATTRS)];
+            struct ble_gatt_attr attrs[MYNEWT_VAL(BLE_GATT_WRITE_MAX_ATTRS)];
             uint8_t num_attrs;
             uint8_t cur_attr;
             uint16_t length;
@@ -317,7 +317,11 @@ static const struct ble_gattc_rx_exec_entry {
 };
 
 /* Maintains the list of active GATT client procedures. */
-static void *ble_gattc_proc_mem;
+static os_membuf_t ble_gattc_proc_mem[
+    OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_GATT_MAX_PROCS),
+                    sizeof (struct ble_gattc_proc))
+];
+
 static struct os_mempool ble_gattc_proc_pool;
 static struct ble_gattc_proc_list ble_gattc_procs;
 
@@ -368,7 +372,7 @@ STATS_NAME_END(ble_gattc_stats)
 static void
 ble_gattc_dbg_assert_proc_not_inserted(struct ble_gattc_proc *proc)
 {
-#if BLE_HS_DEBUG
+#if MYNEWT_VAL(BLE_HS_DEBUG)
     struct ble_gattc_proc *cur;
 
     ble_hs_lock();
@@ -1250,7 +1254,7 @@ int
 ble_gattc_disc_all_svcs(uint16_t conn_handle, ble_gatt_disc_svc_fn *cb,
                         void *cb_arg)
 {
-#if !NIMBLE_OPT(GATT_DISC_ALL_SVCS)
+#if !MYNEWT_VAL(BLE_GATT_DISC_ALL_SVCS)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -1454,7 +1458,7 @@ int
 ble_gattc_disc_svc_by_uuid(uint16_t conn_handle, const void *svc_uuid128,
                            ble_gatt_disc_svc_fn *cb, void *cb_arg)
 {
-#if !NIMBLE_OPT(GATT_DISC_SVC_UUID)
+#if !MYNEWT_VAL(BLE_GATT_DISC_SVC_UUID)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -1775,7 +1779,7 @@ ble_gattc_find_inc_svcs(uint16_t conn_handle, uint16_t start_handle,
                         uint16_t end_handle,
                         ble_gatt_disc_svc_fn *cb, void *cb_arg)
 {
-#if !NIMBLE_OPT(GATT_FIND_INC_SVCS)
+#if !MYNEWT_VAL(BLE_GATT_FIND_INC_SVCS)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -2007,7 +2011,7 @@ ble_gattc_disc_all_chrs(uint16_t conn_handle, uint16_t start_handle,
                         uint16_t end_handle, ble_gatt_chr_fn *cb,
                         void *cb_arg)
 {
-#if !NIMBLE_OPT(GATT_DISC_ALL_CHRS)
+#if !MYNEWT_VAL(BLE_GATT_DISC_ALL_CHRS)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -2252,7 +2256,7 @@ ble_gattc_disc_chrs_by_uuid(uint16_t conn_handle, uint16_t start_handle,
                             uint16_t end_handle, const void *uuid128,
                             ble_gatt_chr_fn *cb, void *cb_arg)
 {
-#if !NIMBLE_OPT(GATT_DISC_CHR_UUID)
+#if !MYNEWT_VAL(BLE_GATT_DISC_CHR_UUID)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -2458,7 +2462,7 @@ ble_gattc_disc_all_dscs(uint16_t conn_handle, uint16_t chr_val_handle,
                         uint16_t chr_end_handle,
                         ble_gatt_dsc_fn *cb, void *cb_arg)
 {
-#if !NIMBLE_OPT(GATT_DISC_ALL_DSCS)
+#if !MYNEWT_VAL(BLE_GATT_DISC_ALL_DSCS)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -2587,7 +2591,7 @@ int
 ble_gattc_read(uint16_t conn_handle, uint16_t attr_handle,
                ble_gatt_attr_fn *cb, void *cb_arg)
 {
-#if !NIMBLE_OPT(GATT_READ)
+#if !MYNEWT_VAL(BLE_GATT_READ)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -2755,7 +2759,7 @@ ble_gattc_read_by_uuid(uint16_t conn_handle, uint16_t start_handle,
                        uint16_t end_handle, const void *uuid128,
                        ble_gatt_attr_fn *cb, void *cb_arg)
 {
-#if !NIMBLE_OPT(GATT_READ_UUID)
+#if !MYNEWT_VAL(BLE_GATT_READ_UUID)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -2944,7 +2948,7 @@ int
 ble_gattc_read_long(uint16_t conn_handle, uint16_t handle,
                     ble_gatt_attr_fn *cb, void *cb_arg)
 {
-#if !NIMBLE_OPT(GATT_READ_LONG)
+#if !MYNEWT_VAL(BLE_GATT_READ_LONG)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -3063,7 +3067,7 @@ ble_gattc_read_mult(uint16_t conn_handle, const uint16_t *handles,
                     uint8_t num_handles, ble_gatt_attr_fn *cb,
                     void *cb_arg)
 {
-#if !NIMBLE_OPT(GATT_READ_MULT)
+#if !MYNEWT_VAL(BLE_GATT_READ_MULT)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -3119,7 +3123,7 @@ int
 ble_gattc_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle,
                        struct os_mbuf *txom)
 {
-#if !NIMBLE_OPT(GATT_WRITE_NO_RSP)
+#if !MYNEWT_VAL(BLE_GATT_WRITE_NO_RSP)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -3242,7 +3246,7 @@ int
 ble_gattc_write(uint16_t conn_handle, uint16_t attr_handle,
                 struct os_mbuf *txom, ble_gatt_attr_fn *cb, void *cb_arg)
 {
-#if !NIMBLE_OPT(GATT_WRITE)
+#if !MYNEWT_VAL(BLE_GATT_WRITE)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -3570,7 +3574,7 @@ int
 ble_gattc_write_long(uint16_t conn_handle, uint16_t attr_handle,
                      struct os_mbuf *txom, ble_gatt_attr_fn *cb, void *cb_arg)
 {
-#if !NIMBLE_OPT(GATT_WRITE_LONG)
+#if !MYNEWT_VAL(BLE_GATT_WRITE_LONG)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -3852,7 +3856,7 @@ ble_gattc_write_reliable(uint16_t conn_handle,
                          int num_attrs,
                          ble_gatt_reliable_attr_fn *cb, void *cb_arg)
 {
-#if !NIMBLE_OPT(GATT_WRITE_RELIABLE)
+#if !MYNEWT_VAL(BLE_GATT_WRITE_RELIABLE)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -3864,7 +3868,7 @@ ble_gattc_write_reliable(uint16_t conn_handle,
 
     STATS_INC(ble_gattc_stats, write_reliable);
 
-    if (num_attrs > NIMBLE_OPT(GATT_WRITE_MAX_ATTRS)) {
+    if (num_attrs > MYNEWT_VAL(BLE_GATT_WRITE_MAX_ATTRS)) {
         rc = BLE_HS_EINVAL;
         goto done;
     }
@@ -3932,7 +3936,7 @@ int
 ble_gattc_notify_custom(uint16_t conn_handle, uint16_t chr_val_handle,
                         struct os_mbuf *txom)
 {
-#if !NIMBLE_OPT(GATT_NOTIFY)
+#if !MYNEWT_VAL(BLE_GATT_NOTIFY)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -3995,7 +3999,7 @@ err:
 int
 ble_gattc_notify(uint16_t conn_handle, uint16_t chr_val_handle)
 {
-#if !NIMBLE_OPT(GATT_NOTIFY)
+#if !MYNEWT_VAL(BLE_GATT_NOTIFY)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -4093,7 +4097,7 @@ ble_gatts_indicate_fail_notconn(uint16_t conn_handle)
 int
 ble_gattc_indicate(uint16_t conn_handle, uint16_t chr_val_handle)
 {
-#if !NIMBLE_OPT(GATT_INDICATE)
+#if !MYNEWT_VAL(BLE_GATT_INDICATE)
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -4212,7 +4216,7 @@ void
 ble_gattc_rx_find_info_idata(uint16_t conn_handle,
                              struct ble_att_find_info_idata *idata)
 {
-#if !NIMBLE_OPT(ATT_CLT_FIND_INFO)
+#if !NIMBLE_BLE_ATT_CLT_FIND_INFO
     return;
 #endif
 
@@ -4233,7 +4237,7 @@ ble_gattc_rx_find_info_idata(uint16_t conn_handle,
 void
 ble_gattc_rx_find_info_complete(uint16_t conn_handle, int status)
 {
-#if !NIMBLE_OPT(ATT_CLT_FIND_INFO)
+#if !NIMBLE_BLE_ATT_CLT_FIND_INFO
     return;
 #endif
 
@@ -4255,7 +4259,7 @@ void
 ble_gattc_rx_find_type_value_hinfo(uint16_t conn_handle,
                                    struct ble_att_find_type_value_hinfo *hinfo)
 {
-#if !NIMBLE_OPT(ATT_CLT_FIND_TYPE)
+#if !NIMBLE_BLE_ATT_CLT_FIND_TYPE
     return;
 #endif
 
@@ -4276,7 +4280,7 @@ ble_gattc_rx_find_type_value_hinfo(uint16_t conn_handle,
 void
 ble_gattc_rx_find_type_value_complete(uint16_t conn_handle, int status)
 {
-#if !NIMBLE_OPT(ATT_CLT_FIND_TYPE)
+#if !NIMBLE_BLE_ATT_CLT_FIND_TYPE
     return;
 #endif
 
@@ -4298,7 +4302,7 @@ void
 ble_gattc_rx_read_type_adata(uint16_t conn_handle,
                              struct ble_att_read_type_adata *adata)
 {
-#if !NIMBLE_OPT(ATT_CLT_READ_TYPE)
+#if !NIMBLE_BLE_ATT_CLT_READ_TYPE
     return;
 #endif
 
@@ -4322,7 +4326,7 @@ ble_gattc_rx_read_type_adata(uint16_t conn_handle,
 void
 ble_gattc_rx_read_type_complete(uint16_t conn_handle, int status)
 {
-#if !NIMBLE_OPT(ATT_CLT_READ_TYPE)
+#if !NIMBLE_BLE_ATT_CLT_READ_TYPE
     return;
 #endif
 
@@ -4347,7 +4351,7 @@ void
 ble_gattc_rx_read_group_type_adata(uint16_t conn_handle,
                                    struct ble_att_read_group_type_adata *adata)
 {
-#if !NIMBLE_OPT(ATT_CLT_READ_GROUP_TYPE)
+#if !NIMBLE_BLE_ATT_CLT_READ_GROUP_TYPE
     return;
 #endif
 
@@ -4368,7 +4372,7 @@ ble_gattc_rx_read_group_type_adata(uint16_t conn_handle,
 void
 ble_gattc_rx_read_group_type_complete(uint16_t conn_handle, int status)
 {
-#if !NIMBLE_OPT(ATT_CLT_READ_GROUP_TYPE)
+#if !NIMBLE_BLE_ATT_CLT_READ_GROUP_TYPE
     return;
 #endif
 
@@ -4389,7 +4393,7 @@ ble_gattc_rx_read_group_type_complete(uint16_t conn_handle, int status)
 void
 ble_gattc_rx_read_rsp(uint16_t conn_handle, int status, struct os_mbuf **om)
 {
-#if !NIMBLE_OPT(ATT_CLT_READ)
+#if !NIMBLE_BLE_ATT_CLT_READ
     return;
 #endif
 
@@ -4414,7 +4418,7 @@ void
 ble_gattc_rx_read_blob_rsp(uint16_t conn_handle, int status,
                            struct os_mbuf **om)
 {
-#if !NIMBLE_OPT(ATT_CLT_READ_BLOB)
+#if !NIMBLE_BLE_ATT_CLT_READ_BLOB
     return;
 #endif
 
@@ -4436,7 +4440,7 @@ void
 ble_gattc_rx_read_mult_rsp(uint16_t conn_handle, int status,
                            struct os_mbuf **om)
 {
-#if !NIMBLE_OPT(ATT_CLT_READ_MULT)
+#if !NIMBLE_BLE_ATT_CLT_READ_MULT
     return;
 #endif
 
@@ -4456,7 +4460,7 @@ ble_gattc_rx_read_mult_rsp(uint16_t conn_handle, int status,
 void
 ble_gattc_rx_write_rsp(uint16_t conn_handle)
 {
-#if !NIMBLE_OPT(ATT_CLT_WRITE)
+#if !NIMBLE_BLE_ATT_CLT_WRITE
     return;
 #endif
 
@@ -4478,7 +4482,7 @@ ble_gattc_rx_prep_write_rsp(uint16_t conn_handle, int status,
                             struct ble_att_prep_write_cmd *rsp,
                             struct os_mbuf **om)
 {
-#if !NIMBLE_OPT(ATT_CLT_PREP_WRITE)
+#if !NIMBLE_BLE_ATT_CLT_PREP_WRITE
     return;
 #endif
 
@@ -4502,7 +4506,7 @@ ble_gattc_rx_prep_write_rsp(uint16_t conn_handle, int status,
 void
 ble_gattc_rx_exec_write_rsp(uint16_t conn_handle, int status)
 {
-#if !NIMBLE_OPT(ATT_CLT_EXEC_WRITE)
+#if !NIMBLE_BLE_ATT_CLT_EXEC_WRITE
     return;
 #endif
 
@@ -4525,7 +4529,7 @@ ble_gattc_rx_exec_write_rsp(uint16_t conn_handle, int status)
 void
 ble_gattc_rx_indicate_rsp(uint16_t conn_handle)
 {
-#if !NIMBLE_OPT(ATT_CLT_INDICATE)
+#if !NIMBLE_BLE_ATT_CLT_INDICATE
     return;
 #endif
 
@@ -4570,26 +4574,16 @@ ble_gattc_init(void)
 {
     int rc;
 
-    free(ble_gattc_proc_mem);
-
     STAILQ_INIT(&ble_gattc_procs);
 
-    if (ble_hs_cfg.max_gattc_procs > 0) {
-        ble_gattc_proc_mem = malloc(
-            OS_MEMPOOL_BYTES(ble_hs_cfg.max_gattc_procs,
-                             sizeof (struct ble_gattc_proc)));
-        if (ble_gattc_proc_mem == NULL) {
-            rc = BLE_HS_ENOMEM;
-            goto err;
-        }
-
+    if (MYNEWT_VAL(BLE_GATT_MAX_PROCS) > 0) {
         rc = os_mempool_init(&ble_gattc_proc_pool,
-                             ble_hs_cfg.max_gattc_procs,
+                             MYNEWT_VAL(BLE_GATT_MAX_PROCS),
                              sizeof (struct ble_gattc_proc),
                              ble_gattc_proc_mem,
                              "ble_gattc_proc_pool");
         if (rc != 0) {
-            goto err;
+            return rc;
         }
     }
 
@@ -4597,15 +4591,8 @@ ble_gattc_init(void)
         STATS_HDR(ble_gattc_stats), STATS_SIZE_INIT_PARMS(ble_gattc_stats,
         STATS_SIZE_32), STATS_NAME_INIT_PARMS(ble_gattc_stats), "ble_gattc");
     if (rc != 0) {
-        rc = BLE_HS_EOS;
-        goto err;
+        return BLE_HS_EOS;
     }
 
     return 0;
-
-err:
-    free(ble_gattc_proc_mem);
-    ble_gattc_proc_mem = NULL;
-
-    return rc;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_gatts.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gatts.c b/net/nimble/host/src/ble_gatts.c
index 4bdc6c7..0286790 100644
--- a/net/nimble/host/src/ble_gatts.c
+++ b/net/nimble/host/src/ble_gatts.c
@@ -779,7 +779,7 @@ ble_gatts_register_chr(const struct ble_gatt_svc_def *svc,
     }
 
     if (ble_gatts_chr_clt_cfg_allowed(chr) != 0) {
-        if (ble_gatts_num_cfgable_chrs > ble_hs_cfg.max_client_configs) {
+        if (ble_gatts_num_cfgable_chrs > ble_hs_max_client_configs) {
             return BLE_HS_ENOMEM;
         }
         ble_gatts_num_cfgable_chrs++;
@@ -1020,7 +1020,7 @@ ble_gatts_register_svcs(const struct ble_gatt_svc_def *svcs,
 
     for (i = 0; svcs[i].type != BLE_GATT_SVC_TYPE_END; i++) {
         idx = ble_gatts_num_svc_entries + i;
-        if (idx >= ble_hs_cfg.max_services) {
+        if (idx >= ble_hs_max_services) {
             return BLE_HS_ENOMEM;
         }
 
@@ -1110,6 +1110,24 @@ ble_gatts_connection_broken(uint16_t conn_handle)
     }
 }
 
+static void
+ble_gatts_free_svc_defs(void)
+{
+    free(ble_gatts_svc_defs);
+    ble_gatts_svc_defs = NULL;
+    ble_gatts_num_svc_defs = 0;
+}
+
+static void
+ble_gatts_free_mem(void)
+{
+    free(ble_gatts_clt_cfg_mem);
+    ble_gatts_clt_cfg_mem = NULL;
+
+    free(ble_gatts_svc_entries);
+    ble_gatts_svc_entries = NULL;
+}
+
 int
 ble_gatts_start(void)
 {
@@ -1120,18 +1138,53 @@ ble_gatts_start(void)
     int num_elems;
     int idx;
     int rc;
+    int i;
+
+    ble_gatts_free_mem();
+
+    if (ble_hs_max_client_configs > 0) {
+        ble_gatts_clt_cfg_mem = malloc(
+            OS_MEMPOOL_BYTES(ble_hs_max_client_configs,
+                             sizeof (struct ble_gatts_clt_cfg)));
+        if (ble_gatts_clt_cfg_mem == NULL) {
+            rc = BLE_HS_ENOMEM;
+            goto err;
+        }
+    }
+
+    if (ble_hs_max_services > 0) {
+        ble_gatts_svc_entries =
+            malloc(ble_hs_max_services * sizeof *ble_gatts_svc_entries);
+        if (ble_gatts_svc_entries == NULL) {
+            rc = BLE_HS_ENOMEM;
+            goto err;
+        }
+    }
+
+
+    ble_gatts_num_svc_entries = 0;
+    for (i = 0; i < ble_gatts_num_svc_defs; i++) {
+        rc = ble_gatts_register_svcs(ble_gatts_svc_defs[i],
+                                     ble_hs_cfg.gatts_register_cb,
+                                     ble_hs_cfg.gatts_register_arg);
+        if (rc != 0) {
+            goto err;
+        }
+    }
+    ble_gatts_free_svc_defs();
 
     if (ble_gatts_num_cfgable_chrs == 0) {
         return 0;
     }
 
     /* Initialize client-configuration memory pool. */
-    num_elems = ble_hs_cfg.max_client_configs / ble_gatts_num_cfgable_chrs;
+    num_elems = ble_hs_max_client_configs / ble_gatts_num_cfgable_chrs;
     rc = os_mempool_init(&ble_gatts_clt_cfg_pool, num_elems,
                          ble_gatts_clt_cfg_size(), ble_gatts_clt_cfg_mem,
                          "ble_gatts_clt_cfg_pool");
     if (rc != 0) {
-        return BLE_HS_EOS;
+        rc = BLE_HS_EOS;
+        goto err;
     }
 
     /* Allocate the cached array of handles for the configuration
@@ -1139,7 +1192,8 @@ ble_gatts_start(void)
      */
     ble_gatts_clt_cfgs = os_memblock_get(&ble_gatts_clt_cfg_pool);
     if (ble_gatts_clt_cfgs == NULL) {
-        return BLE_HS_ENOMEM;
+        rc = BLE_HS_ENOMEM;
+        goto err;
     }
 
     /* Fill the cache. */
@@ -1161,6 +1215,11 @@ ble_gatts_start(void)
     }
 
     return 0;
+
+err:
+    ble_gatts_free_mem();
+    ble_gatts_free_svc_defs();
+    return rc;
 }
 
 int
@@ -1997,8 +2056,7 @@ ble_gatts_count_resources(const struct ble_gatt_svc_def *svcs,
  *                                  invalid resource definition.
  */
 int
-ble_gatts_count_cfg(const struct ble_gatt_svc_def *defs,
-                    struct ble_hs_cfg *cfg)
+ble_gatts_count_cfg(const struct ble_gatt_svc_def *defs)
 {
     struct ble_gatt_resources res = { 0 };
     int rc;
@@ -2008,85 +2066,31 @@ ble_gatts_count_cfg(const struct ble_gatt_svc_def *defs,
         return rc;
     }
 
-    cfg->max_services += res.svcs;
-    cfg->max_attrs += res.attrs;
+    ble_hs_max_services += res.svcs;
+    ble_hs_max_attrs += res.attrs;
 
     /* Reserve an extra CCCD for the cache. */
-    cfg->max_client_configs += res.cccds * (cfg->max_connections + 1);
+    ble_hs_max_client_configs +=
+        res.cccds * (MYNEWT_VAL(BLE_MAX_CONNECTIONS) + 1);
 
     return 0;
 }
 
-static void
-ble_gatts_free_svc_defs(void)
-{
-    free(ble_gatts_svc_defs);
-    ble_gatts_svc_defs = NULL;
-    ble_gatts_num_svc_defs = 0;
-}
-
-static void
-ble_gatts_free_mem(void)
-{
-    free(ble_gatts_clt_cfg_mem);
-    ble_gatts_clt_cfg_mem = NULL;
-
-    free(ble_gatts_svc_entries);
-    ble_gatts_svc_entries = NULL;
-}
-
 int
 ble_gatts_init(void)
 {
     int rc;
-    int i;
 
-    ble_gatts_free_mem();
     ble_gatts_num_cfgable_chrs = 0;
     ble_gatts_clt_cfgs = NULL;
 
-    if (ble_hs_cfg.max_client_configs > 0) {
-        ble_gatts_clt_cfg_mem = malloc(
-            OS_MEMPOOL_BYTES(ble_hs_cfg.max_client_configs,
-                             sizeof (struct ble_gatts_clt_cfg)));
-        if (ble_gatts_clt_cfg_mem == NULL) {
-            rc = BLE_HS_ENOMEM;
-            goto err;
-        }
-    }
-
-    if (ble_hs_cfg.max_services > 0) {
-        ble_gatts_svc_entries =
-            malloc(ble_hs_cfg.max_services * sizeof *ble_gatts_svc_entries);
-        if (ble_gatts_svc_entries == NULL) {
-            rc = BLE_HS_ENOMEM;
-            goto err;
-        }
-    }
-
-    ble_gatts_num_svc_entries = 0;
-    for (i = 0; i < ble_gatts_num_svc_defs; i++) {
-        rc = ble_gatts_register_svcs(ble_gatts_svc_defs[i],
-                                     ble_hs_cfg.gatts_register_cb,
-                                     ble_hs_cfg.gatts_register_arg);
-        if (rc != 0) {
-            goto err;
-        }
-    }
-    ble_gatts_free_svc_defs();
-
     rc = stats_init_and_reg(
         STATS_HDR(ble_gatts_stats), STATS_SIZE_INIT_PARMS(ble_gatts_stats,
         STATS_SIZE_32), STATS_NAME_INIT_PARMS(ble_gatts_stats), "ble_gatts");
     if (rc != 0) {
-        rc = BLE_HS_EOS;
-        goto err;
+        return BLE_HS_EOS;
     }
 
     return 0;
 
-err:
-    ble_gatts_free_mem();
-    ble_gatts_free_svc_defs();
-    return rc;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
index 02db879..84a69a6 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -19,6 +19,8 @@
 
 #include <assert.h>
 #include <errno.h>
+#include "sysinit/sysinit.h"
+#include "syscfg/syscfg.h"
 #include "bsp/bsp.h"
 #include "stats/stats.h"
 #include "util/tpq.h"
@@ -26,6 +28,10 @@
 #include "nimble/ble_hci_trans.h"
 #include "ble_hs_priv.h"
 
+#define BLE_HS_HCI_EVT_COUNT                    \
+    (MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT) +     \
+     MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT))
+
 /**
  * The maximum number of events the host will process in a row before returning
  * control to the parent task.
@@ -35,7 +41,9 @@
 static struct log_handler ble_hs_log_console_handler;
 
 struct os_mempool ble_hs_hci_ev_pool;
-static void *ble_hs_hci_os_event_buf;
+static os_membuf_t ble_hs_hci_os_event_buf[
+    OS_MEMPOOL_SIZE(BLE_HS_HCI_EVT_COUNT, sizeof (struct os_event))
+];
 
 /** OS event - triggers tx of pending notifications and indications. */
 static struct os_event ble_hs_event_tx_notifications = {
@@ -52,15 +60,13 @@ static struct os_event ble_hs_event_reset = {
 uint8_t ble_hs_sync_state;
 static int ble_hs_reset_reason;
 
-#if MYNEWT_SELFTEST
-/** Use a higher frequency timer to allow tests to run faster. */
-#define BLE_HS_HEARTBEAT_OS_TICKS       (OS_TICKS_PER_SEC / 10)
-#else
-#define BLE_HS_HEARTBEAT_OS_TICKS       OS_TICKS_PER_SEC
-#endif
+#define BLE_HS_HEARTBEAT_OS_TICKS       \
+    (MYNEWT_VAL(BLE_HS_HEARTBEAT_FREQ) * OS_TICKS_PER_SEC / 1000)
 
 #define BLE_HS_SYNC_RETRY_RATE          (OS_TICKS_PER_SEC / 10)    
 
+static struct os_task *ble_hs_parent_task;
+
 /**
  * Handles unresponsive timeouts and periodic retries in case of resource
  * shortage.
@@ -71,16 +77,20 @@ static struct os_callout_func ble_hs_event_co;
 /* Queue for host-specific OS events. */
 static struct os_eventq ble_hs_evq;
 
-/* Task structures for the host's parent task. */
-static struct os_eventq *ble_hs_parent_evq;
-static struct os_task *ble_hs_parent_task;
-
 static struct os_mqueue ble_hs_rx_q;
 static struct os_mqueue ble_hs_tx_q;
 
 static struct os_mutex ble_hs_mutex;
 
-#if BLE_HS_DEBUG
+/** These values keep track of required ATT and GATT resources counts.  They
+ * increase as services are added, and are read when the ATT server and GATT
+ * server are started.
+ */
+uint16_t ble_hs_max_attrs;
+uint16_t ble_hs_max_services;
+uint16_t ble_hs_max_client_configs;
+
+#if MYNEWT_VAL(BLE_HS_DEBUG)
 static uint8_t ble_hs_dbg_mutex_locked;
 #endif
 
@@ -102,7 +112,7 @@ ble_hs_locked_by_cur_task(void)
 {
     struct os_task *owner;
 
-#if BLE_HS_DEBUG
+#if MYNEWT_VAL(BLE_HS_DEBUG)
     if (!os_started()) {
         return ble_hs_dbg_mutex_locked;
     }
@@ -118,7 +128,8 @@ ble_hs_locked_by_cur_task(void)
 int
 ble_hs_is_parent_task(void)
 {
-    return !os_started() || os_sched_get_current_task() == ble_hs_parent_task;
+    return !os_started() ||
+           os_sched_get_current_task() == ble_hs_parent_task;
 }
 
 void
@@ -128,7 +139,7 @@ ble_hs_lock(void)
 
     BLE_HS_DBG_ASSERT(!ble_hs_locked_by_cur_task());
 
-#if BLE_HS_DEBUG
+#if MYNEWT_VAL(BLE_HS_DEBUG)
     if (!os_started()) {
         ble_hs_dbg_mutex_locked = 1;
         return;
@@ -144,7 +155,7 @@ ble_hs_unlock(void)
 {
     int rc;
 
-#if BLE_HS_DEBUG
+#if MYNEWT_VAL(BLE_HS_DEBUG)
     if (!os_started()) {
         BLE_HS_DBG_ASSERT(ble_hs_dbg_mutex_locked);
         ble_hs_dbg_mutex_locked = 0;
@@ -345,7 +356,7 @@ ble_hs_event_handle(void *unused)
          * task's eventq to indicate that more host events are enqueued.
          */
         if (i >= BLE_HS_MAX_EVS_IN_A_ROW) {
-            os_eventq_put(ble_hs_parent_evq, &ble_hs_event_co.cf_c.c_ev);
+            os_eventq_put(ble_hs_cfg.parent_evq, &ble_hs_event_co.cf_c.c_ev);
             break;
         }
         i++;
@@ -395,7 +406,7 @@ void
 ble_hs_event_enqueue(struct os_event *ev)
 {
     os_eventq_put(&ble_hs_evq, ev);
-    os_eventq_put(ble_hs_parent_evq, &ble_hs_event_co.cf_c.c_ev);
+    os_eventq_put(ble_hs_cfg.parent_evq, &ble_hs_event_co.cf_c.c_ev);
 }
 
 void
@@ -421,7 +432,7 @@ ble_hs_enqueue_hci_event(uint8_t *hci_evt)
 void
 ble_hs_notifications_sched(void)
 {
-#if MYNEWT_SELFTEST
+#if !MYNEWT_VAL(BLE_HS_REQUIRE_OS)
     if (!os_started()) {
         ble_gatts_tx_notifications();
         return;
@@ -464,12 +475,31 @@ ble_hs_start(void)
 {
     int rc;
 
+    if (ble_hs_cfg.parent_evq == NULL) {
+        return BLE_HS_EINVAL;
+    }
+
     ble_hs_parent_task = os_sched_get_current_task();
 
-    ble_gatts_start();
+    os_callout_func_init(&ble_hs_heartbeat_timer, ble_hs_cfg.parent_evq,
+                         ble_hs_heartbeat, NULL);
+
+    rc = ble_att_svr_start();
+    if (rc != 0) {
+        return rc;
+    }
+
+    rc = ble_gatts_start();
+    if (rc != 0) {
+        return rc;
+    }
 
     rc = ble_hs_sync();
-    return rc;
+    if (rc != 0) {
+        return rc;
+    }
+
+    return 0;
 }
 
 /**
@@ -488,7 +518,7 @@ ble_hs_rx_data(struct os_mbuf *om, void *arg)
 
     rc = os_mqueue_put(&ble_hs_rx_q, &ble_hs_evq, om);
     if (rc == 0) {
-        os_eventq_put(ble_hs_parent_evq, &ble_hs_event_co.cf_c.c_ev);
+        os_eventq_put(ble_hs_cfg.parent_evq, &ble_hs_event_co.cf_c.c_ev);
     } else {
         os_mbuf_free_chain(om);
         rc = BLE_HS_EOS;
@@ -515,113 +545,58 @@ ble_hs_tx_data(struct os_mbuf *om)
         os_mbuf_free_chain(om);
         return BLE_HS_EOS;
     }
-    os_eventq_put(ble_hs_parent_evq, &ble_hs_event_co.cf_c.c_ev);
+    os_eventq_put(ble_hs_cfg.parent_evq, &ble_hs_event_co.cf_c.c_ev);
 
     return 0;
 }
 
-static void
-ble_hs_free_mem(void)
-{
-    free(ble_hs_hci_os_event_buf);
-    ble_hs_hci_os_event_buf = NULL;
-}
-
 /**
  * Initializes the NimBLE host.  This function must be called before the OS is
  * started.  The NimBLE stack requires an application task to function.  One
  * application task in particular is designated as the "host parent task".  In
  * addition to application-specific work, the host parent task does work for
  * NimBLE by processing events generated by the host.
- *
- * @param app_evq               The event queue associated with the host parent
- *                                  task.
- * @param cfg                   The set of configuration settings to initialize
- *                                  the host with.  Specify null for defaults.
- *
- * @return                      0 on success;
- *                              BLE_HS_ENOMEM if initialization failed due to
- *                                  resource exhaustion.
- *                              Other nonzero on error.
  */
-int
-ble_hs_init(struct os_eventq *app_evq, struct ble_hs_cfg *cfg)
+void
+ble_hs_init(void)
 {
     int rc;
 
-    ble_hs_free_mem();
-
-    if (app_evq == NULL) {
-        rc = BLE_HS_EINVAL;
-        goto err;
-    }
-    ble_hs_parent_evq = app_evq;
-
-    ble_hs_cfg_init(cfg);
-
     log_init();
     log_console_handler_init(&ble_hs_log_console_handler);
     log_register("ble_hs", &ble_hs_log, &ble_hs_log_console_handler);
 
-    ble_hs_hci_os_event_buf = malloc(
-        OS_MEMPOOL_BYTES(ble_hs_cfg.max_hci_bufs, sizeof (struct os_event)));
-    if (ble_hs_hci_os_event_buf == NULL) {
-        rc = BLE_HS_ENOMEM;
-        goto err;
-    }
-
     /* Create memory pool of OS events */
-    rc = os_mempool_init(&ble_hs_hci_ev_pool, ble_hs_cfg.max_hci_bufs,
+    rc = os_mempool_init(&ble_hs_hci_ev_pool, BLE_HS_HCI_EVT_COUNT,
                          sizeof (struct os_event), ble_hs_hci_os_event_buf,
                          "ble_hs_hci_ev_pool");
-    assert(rc == 0);
+    SYSINIT_PANIC_ASSERT(rc == 0);
 
     /* Initialize eventq */
     os_eventq_init(&ble_hs_evq);
 
-    /* Initialize stats. */
-    rc = stats_module_init();
-    if (rc != 0) {
-        rc = BLE_HS_EOS;
-        goto err;
-    }
-
     ble_hs_hci_init();
 
     rc = ble_hs_conn_init();
-    if (rc != 0) {
-        goto err;
-    }
+    SYSINIT_PANIC_ASSERT(rc == 0);
 
     rc = ble_l2cap_init();
-    if (rc != 0) {
-        goto err;
-    }
+    SYSINIT_PANIC_ASSERT(rc == 0);
 
     rc = ble_att_init();
-    if (rc != 0) {
-        goto err;
-    }
+    SYSINIT_PANIC_ASSERT(rc == 0);
 
     rc = ble_att_svr_init();
-    if (rc != 0) {
-        goto err;
-    }
+    SYSINIT_PANIC_ASSERT(rc == 0);
 
     rc = ble_gap_init();
-    if (rc != 0) {
-        goto err;
-    }
+    SYSINIT_PANIC_ASSERT(rc == 0);
 
     rc = ble_gattc_init();
-    if (rc != 0) {
-        goto err;
-    }
+    SYSINIT_PANIC_ASSERT(rc == 0);
 
     rc = ble_gatts_init();
-    if (rc != 0) {
-        goto err;
-    }
+    SYSINIT_PANIC_ASSERT(rc == 0);
 
     os_mqueue_init(&ble_hs_rx_q, NULL);
     os_mqueue_init(&ble_hs_tx_q, NULL);
@@ -629,31 +604,21 @@ ble_hs_init(struct os_eventq *app_evq, struct ble_hs_cfg *cfg)
     rc = stats_init_and_reg(
         STATS_HDR(ble_hs_stats), STATS_SIZE_INIT_PARMS(ble_hs_stats,
         STATS_SIZE_32), STATS_NAME_INIT_PARMS(ble_hs_stats), "ble_hs");
-    if (rc != 0) {
-        rc = BLE_HS_EOS;
-        goto err;
-    }
+    SYSINIT_PANIC_ASSERT(rc == 0);
 
-    os_callout_func_init(&ble_hs_heartbeat_timer, ble_hs_parent_evq,
-                         ble_hs_heartbeat, NULL);
     os_callout_func_init(&ble_hs_event_co, &ble_hs_evq,
                          ble_hs_event_handle, NULL);
 
     rc = os_mutex_init(&ble_hs_mutex);
-    if (rc != 0) {
-        rc = BLE_HS_EOS;
-        goto err;
-    }
-#if BLE_HS_DEBUG
+    SYSINIT_PANIC_ASSERT(rc == 0);
+
+#if MYNEWT_VAL(BLE_HS_DEBUG)
     ble_hs_dbg_mutex_locked = 0;
 #endif
 
     /* Configure the HCI transport to communicate with a host. */
     ble_hci_trans_cfg_hs(ble_hs_hci_rx_evt, NULL, ble_hs_rx_data, NULL);
 
-    return 0;
-
-err:
-    ble_hs_free_mem();
-    return rc;
+    /* Configure storage mechanism. */
+    /* XXX */
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_hs_adv.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_adv.c b/net/nimble/host/src/ble_hs_adv.c
index da0d5c1..7bd7612 100644
--- a/net/nimble/host/src/ble_hs_adv.c
+++ b/net/nimble/host/src/ble_hs_adv.c
@@ -48,7 +48,7 @@ int
 ble_hs_adv_set_flat(uint8_t type, int data_len, const void *data,
                     uint8_t *dst, uint8_t *dst_len, uint8_t max_len)
 {
-#if !NIMBLE_OPT(ADVERTISE)
+#if !NIMBLE_BLE_ADVERTISE
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -118,7 +118,7 @@ int
 ble_hs_adv_set_fields(const struct ble_hs_adv_fields *adv_fields,
                       uint8_t *dst, uint8_t *dst_len, uint8_t max_len)
 {
-#if !NIMBLE_OPT(ADVERTISE)
+#if !NIMBLE_BLE_ADVERTISE
     return BLE_HS_ENOTSUP;
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_hs_cfg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_cfg.c b/net/nimble/host/src/ble_hs_cfg.c
index fb5fb45..31da94f 100644
--- a/net/nimble/host/src/ble_hs_cfg.c
+++ b/net/nimble/host/src/ble_hs_cfg.c
@@ -17,64 +17,19 @@
  * under the License.
  */
 
-#include "ble_hs_priv.h"
+#include "syscfg/syscfg.h"
+#include "host/ble_hs.h"
 
-#if NIMBLE_OPT(CONNECT)
-#define BLE_HS_CFG_MAX_CONNECTIONS NIMBLE_OPT(MAX_CONNECTIONS)
-#else
-#define BLE_HS_CFG_MAX_CONNECTIONS 0
-#endif
-
-const struct ble_hs_cfg ble_hs_cfg_dflt = {
-    /** HCI settings. */
-    .max_hci_bufs = 3,
-
-    /** Connection settings. */
-    .max_connections = BLE_HS_CFG_MAX_CONNECTIONS,
-
-    /** GATT server settings. */
-    /* These get set to zero with the expectation that they will be increased
-     * as needed when each supported GATT service is initialized.
-     */
-    .max_services = 0,
-    .max_client_configs = 0,
-
-    /** GATT client settings. */
-    .max_gattc_procs = 4,
-
-    /** ATT server settings. */
-    /* This is set to 0; see note above re: GATT server settings. */
-    .max_attrs = 0,
-    .max_prep_entries = 6,
-
-    /** L2CAP settings. */
-    /* Three channels per connection (sig, att, and sm). */
-    .max_l2cap_chans = 3 * BLE_HS_CFG_MAX_CONNECTIONS,
-    .max_l2cap_sig_procs = 1,
-    .max_l2cap_sm_procs = 1,
+struct ble_hs_cfg ble_hs_cfg = {
+    .parent_evq = NULL,
 
     /** Security manager settings. */
-    .sm_io_cap = BLE_HS_IO_NO_INPUT_OUTPUT,
-    .sm_oob_data_flag = 0,
-    .sm_bonding = 0,
-    .sm_mitm = 0,
-    .sm_sc = 0,
-    .sm_keypress = 0,
-    .sm_our_key_dist = 0,
-    .sm_their_key_dist = 0,
-
-    /** Privacy settings. */
-    .rpa_timeout = 300,
+    .sm_io_cap = MYNEWT_VAL(BLE_SM_IO_CAP),
+    .sm_oob_data_flag = MYNEWT_VAL(BLE_SM_OOB_DATA_FLAG),
+    .sm_bonding = MYNEWT_VAL(BLE_SM_BONDING),
+    .sm_mitm = MYNEWT_VAL(BLE_SM_MITM),
+    .sm_sc = MYNEWT_VAL(BLE_SM_SC),
+    .sm_keypress = MYNEWT_VAL(BLE_SM_KEYPRESS),
+    .sm_our_key_dist = MYNEWT_VAL(BLE_SM_OUR_KEY_DIST),
+    .sm_their_key_dist = MYNEWT_VAL(BLE_SM_THEIR_KEY_DIST),
 };
-
-struct ble_hs_cfg ble_hs_cfg;
-
-void
-ble_hs_cfg_init(struct ble_hs_cfg *cfg)
-{
-    if (cfg == NULL) {
-        ble_hs_cfg = ble_hs_cfg_dflt;
-    } else {
-        ble_hs_cfg = *cfg;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_hs_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_conn.c b/net/nimble/host/src/ble_hs_conn.c
index 76196ef..c0d08d0 100644
--- a/net/nimble/host/src/ble_hs_conn.c
+++ b/net/nimble/host/src/ble_hs_conn.c
@@ -19,6 +19,7 @@
 
 #include <string.h>
 #include <errno.h>
+#include "syscfg/syscfg.h"
 #include "os/os.h"
 #include "host/ble_hs_id.h"
 #include "ble_hs_priv.h"
@@ -29,14 +30,17 @@
 static SLIST_HEAD(, ble_hs_conn) ble_hs_conns;
 static struct os_mempool ble_hs_conn_pool;
 
-static os_membuf_t *ble_hs_conn_elem_mem;
+static os_membuf_t ble_hs_conn_elem_mem[
+    OS_MEMPOOL_SIZE(MYNEWT_VAL(BLE_MAX_CONNECTIONS),
+                    sizeof (struct ble_hs_conn))
+];
 
 static const uint8_t ble_hs_conn_null_addr[6];
 
 int
 ble_hs_conn_can_alloc(void)
 {
-#if !NIMBLE_OPT(CONNECT)
+#if !NIMBLE_BLE_CONNECT
     return 0;
 #endif
 
@@ -48,7 +52,7 @@ ble_hs_conn_can_alloc(void)
 struct ble_l2cap_chan *
 ble_hs_conn_chan_find(struct ble_hs_conn *conn, uint16_t cid)
 {
-#if !NIMBLE_OPT(CONNECT)
+#if !NIMBLE_BLE_CONNECT
     return NULL;
 #endif
 
@@ -69,7 +73,7 @@ ble_hs_conn_chan_find(struct ble_hs_conn *conn, uint16_t cid)
 int
 ble_hs_conn_chan_insert(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
 {
-#if !NIMBLE_OPT(CONNECT)
+#if !NIMBLE_BLE_CONNECT
     return BLE_HS_ENOTSUP;
 #endif
 
@@ -100,7 +104,7 @@ ble_hs_conn_chan_insert(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
 struct ble_hs_conn *
 ble_hs_conn_alloc(void)
 {
-#if !NIMBLE_OPT(CONNECT)
+#if !NIMBLE_BLE_CONNECT
     return NULL;
 #endif
 
@@ -137,7 +141,7 @@ ble_hs_conn_alloc(void)
     /* XXX: We should create the SM channel even if not configured.  We need it
      * to reject SM messages.
      */
-#if NIMBLE_OPT(SM)
+#if NIMBLE_BLE_SM
     chan = ble_sm_create_chan();
     if (chan == NULL) {
         goto err;
@@ -176,7 +180,7 @@ ble_hs_conn_delete_chan(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan)
 void
 ble_hs_conn_free(struct ble_hs_conn *conn)
 {
-#if !NIMBLE_OPT(CONNECT)
+#if !NIMBLE_BLE_CONNECT
     return;
 #endif
 
@@ -202,7 +206,7 @@ ble_hs_conn_free(struct ble_hs_conn *conn)
 void
 ble_hs_conn_insert(struct ble_hs_conn *conn)
 {
-#if !NIMBLE_OPT(CONNECT)
+#if !NIMBLE_BLE_CONNECT
     return;
 #endif
 
@@ -215,7 +219,7 @@ ble_hs_conn_insert(struct ble_hs_conn *conn)
 void
 ble_hs_conn_remove(struct ble_hs_conn *conn)
 {
-#if !NIMBLE_OPT(CONNECT)
+#if !NIMBLE_BLE_CONNECT
     return;
 #endif
 
@@ -227,7 +231,7 @@ ble_hs_conn_remove(struct ble_hs_conn *conn)
 struct ble_hs_conn *
 ble_hs_conn_find(uint16_t conn_handle)
 {
-#if !NIMBLE_OPT(CONNECT)
+#if !NIMBLE_BLE_CONNECT
     return NULL;
 #endif
 
@@ -247,7 +251,7 @@ ble_hs_conn_find(uint16_t conn_handle)
 struct ble_hs_conn *
 ble_hs_conn_find_by_addr(uint8_t addr_type, uint8_t *addr)
 {
-#if !NIMBLE_OPT(CONNECT)
+#if !NIMBLE_BLE_CONNECT
     return NULL;
 #endif
 
@@ -269,7 +273,7 @@ ble_hs_conn_find_by_addr(uint8_t addr_type, uint8_t *addr)
 struct ble_hs_conn *
 ble_hs_conn_find_by_idx(int idx)
 {
-#if !NIMBLE_OPT(CONNECT)
+#if !NIMBLE_BLE_CONNECT
     return NULL;
 #endif
 
@@ -293,7 +297,7 @@ ble_hs_conn_find_by_idx(int idx)
 int
 ble_hs_conn_exists(uint16_t conn_handle)
 {
-#if !NIMBLE_OPT(CONNECT)
+#if !NIMBLE_BLE_CONNECT
     return 0;
 #endif
     return ble_hs_conn_find(conn_handle) != NULL;
@@ -305,7 +309,7 @@ ble_hs_conn_exists(uint16_t conn_handle)
 struct ble_hs_conn *
 ble_hs_conn_first(void)
 {
-#if !NIMBLE_OPT(CONNECT)
+#if !NIMBLE_BLE_CONNECT
     return NULL;
 #endif
 
@@ -363,40 +367,19 @@ ble_hs_conn_addrs(const struct ble_hs_conn *conn,
     }
 }
 
-static void
-ble_hs_conn_free_mem(void)
-{
-    free(ble_hs_conn_elem_mem);
-    ble_hs_conn_elem_mem = NULL;
-}
-
 int 
 ble_hs_conn_init(void)
 {
     int rc;
 
-    ble_hs_conn_free_mem();
-
-    ble_hs_conn_elem_mem = malloc(
-        OS_MEMPOOL_BYTES(ble_hs_cfg.max_connections,
-                         sizeof (struct ble_hs_conn)));
-    if (ble_hs_conn_elem_mem == NULL) {
-        rc = BLE_HS_ENOMEM;
-        goto err;
-    }
-    rc = os_mempool_init(&ble_hs_conn_pool, ble_hs_cfg.max_connections,
+    rc = os_mempool_init(&ble_hs_conn_pool, MYNEWT_VAL(BLE_MAX_CONNECTIONS),
                          sizeof (struct ble_hs_conn),
                          ble_hs_conn_elem_mem, "ble_hs_conn_pool");
     if (rc != 0) {
-        rc = BLE_HS_EOS;
-        goto err;
+        return BLE_HS_EOS;
     }
 
     SLIST_INIT(&ble_hs_conns);
 
     return 0;
-
-err:
-    ble_hs_conn_free_mem();
-    return rc;
 }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_hs_dbg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_dbg.c b/net/nimble/host/src/ble_hs_dbg.c
index bb6ebdf..915090d 100644
--- a/net/nimble/host/src/ble_hs_dbg.c
+++ b/net/nimble/host/src/ble_hs_dbg.c
@@ -455,7 +455,7 @@ ble_hs_dbg_cmd_status_disp(uint8_t *evdata, uint8_t len)
 void
 ble_hs_dbg_event_disp(uint8_t *evbuf)
 {
-#if LOG_LEVEL > LOG_LEVEL_DEBUG
+#if MYNEWT_VAL(LOG_LEVEL) > LOG_LEVEL_DEBUG
     return;
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_hs_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_hci.c b/net/nimble/host/src/ble_hs_hci.c
index 433c2e0..2b2d275 100644
--- a/net/nimble/host/src/ble_hs_hci.c
+++ b/net/nimble/host/src/ble_hs_hci.c
@@ -34,11 +34,11 @@ static uint8_t *ble_hs_hci_ack;
 static uint16_t ble_hs_hci_buf_sz;
 static uint8_t ble_hs_hci_max_pkts;
 
-#if PHONY_HCI_ACKS
+#if MYNEWT_VAL(BLE_HS_PHONY_HCI_ACKS)
 static ble_hs_hci_phony_ack_fn *ble_hs_hci_phony_ack_cb;
 #endif
 
-#if PHONY_HCI_ACKS
+#if MYNEWT_VAL(BLE_HS_PHONY_HCI_ACKS)
 void
 ble_hs_hci_set_phony_ack_cb(ble_hs_hci_phony_ack_fn *cb)
 {
@@ -218,7 +218,7 @@ ble_hs_hci_wait_for_ack(void)
 {
     int rc;
 
-#if PHONY_HCI_ACKS
+#if MYNEWT_VAL(BLE_HS_PHONY_HCI_ACKS)
     if (ble_hs_hci_phony_ack_cb == NULL) {
         rc = BLE_HS_ETIMEOUT_HCI;
     } else {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_hs_hci_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_hci_priv.h b/net/nimble/host/src/ble_hs_hci_priv.h
index 7d2fb12..e9df8ea 100644
--- a/net/nimble/host/src/ble_hs_hci_priv.h
+++ b/net/nimble/host/src/ble_hs_hci_priv.h
@@ -38,7 +38,7 @@ int ble_hs_hci_cmd_tx_empty_ack(void *cmd);
 void ble_hs_hci_rx_ack(uint8_t *ack_ev);
 void ble_hs_hci_init(void);
 
-#if PHONY_HCI_ACKS
+#if MYNEWT_VAL(BLE_HS_PHONY_HCI_ACKS)
 typedef int ble_hs_hci_phony_ack_fn(uint8_t *ack, int ack_buf_len);
 void ble_hs_hci_set_phony_ack_cb(ble_hs_hci_phony_ack_fn *cb);
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_hs_misc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_misc.c b/net/nimble/host/src/ble_hs_misc.c
index 216196b..74a661f 100644
--- a/net/nimble/host/src/ble_hs_misc.c
+++ b/net/nimble/host/src/ble_hs_misc.c
@@ -26,26 +26,6 @@
 const uint8_t ble_hs_misc_null_addr[6];
 
 int
-ble_hs_misc_malloc_mempool(void **mem, struct os_mempool *pool,
-                           int num_entries, int entry_size, char *name)
-{
-    int rc;
-
-    *mem = malloc(OS_MEMPOOL_BYTES(num_entries, entry_size));
-    if (*mem == NULL) {
-        return BLE_HS_ENOMEM;
-    }
-
-    rc = os_mempool_init(pool, num_entries, entry_size, *mem, name);
-    if (rc != 0) {
-        free(*mem);
-        return BLE_HS_EOS;
-    }
-
-    return 0;
-}
-
-int
 ble_hs_misc_conn_chan_find(uint16_t conn_handle, uint16_t cid,
                            struct ble_hs_conn **out_conn,
                            struct ble_l2cap_chan **out_chan)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_hs_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_priv.h b/net/nimble/host/src/ble_hs_priv.h
index d61f0ba..1d77ae6 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -58,6 +58,12 @@ struct os_event;
 #define BLE_HS_SYNC_STATE_BRINGUP       1
 #define BLE_HS_SYNC_STATE_GOOD          2
 
+#if NIMBLE_BLE_CONNECT
+#define BLE_HS_MAX_CONNECTIONS MYNEWT_VAL(BLE_MAX_CONNECTIONS)
+#else
+#define BLE_HS_MAX_CONNECTIONS 0
+#endif
+
 STATS_SECT_START(ble_hs_stats)
     STATS_SECT_ENTRY(conn_create)
     STATS_SECT_ENTRY(conn_delete)
@@ -71,12 +77,15 @@ STATS_SECT_START(ble_hs_stats)
 STATS_SECT_END
 extern STATS_SECT_DECL(ble_hs_stats) ble_hs_stats;
 
-extern struct ble_hs_cfg ble_hs_cfg;
 extern struct os_mbuf_pool ble_hs_mbuf_pool;
 extern uint8_t ble_hs_sync_state;
 
 extern const uint8_t ble_hs_misc_null_addr[6];
 
+extern uint16_t ble_hs_max_attrs;
+extern uint16_t ble_hs_max_services;
+extern uint16_t ble_hs_max_client_configs;
+
 void ble_hs_process_tx_data_queue(void);
 void ble_hs_process_rx_data_queue(void);
 int ble_hs_tx_data(struct os_mbuf *om);
@@ -86,8 +95,6 @@ void ble_hs_event_enqueue(struct os_event *ev);
 int ble_hs_hci_rx_evt(uint8_t *hci_ev, void *arg);
 int ble_hs_hci_evt_acl_process(struct os_mbuf *om);
 
-int ble_hs_misc_malloc_mempool(void **mem, struct os_mempool *pool,
-                               int num_entries, int entry_size, char *name);
 int ble_hs_misc_conn_chan_find(uint16_t conn_handle, uint16_t cid,
                                struct ble_hs_conn **out_conn,
                                struct ble_l2cap_chan **out_chan);
@@ -96,8 +103,6 @@ int ble_hs_misc_conn_chan_find_reqd(uint16_t conn_handle, uint16_t cid,
                                     struct ble_l2cap_chan **out_chan);
 uint8_t ble_hs_misc_addr_type_to_id(uint8_t addr_type);
 
-void ble_hs_cfg_init(struct ble_hs_cfg *cfg);
-
 int ble_hs_locked_by_cur_task(void);
 int ble_hs_is_parent_task(void);
 void ble_hs_lock(void);
@@ -107,7 +112,7 @@ void ble_hs_hw_error(uint8_t hw_code);
 void ble_hs_heartbeat_sched(int32_t ticks);
 void ble_hs_notifications_sched(void);
 
-#if LOG_LEVEL <= LOG_LEVEL_DEBUG
+#if MYNEWT_VAL(LOG_LEVEL) <= LOG_LEVEL_DEBUG
 
 #define BLE_HS_LOG_CMD(is_tx, cmd_type, cmd_name, conn_handle,                \
                        log_cb, cmd) do                                        \
@@ -132,7 +137,7 @@ void ble_hs_notifications_sched(void);
 
 #endif
 
-#if BLE_HS_DEBUG
+#if MYNEWT_VAL(BLE_HS_DEBUG)
     #define BLE_HS_DBG_ASSERT(x) assert(x)
     #define BLE_HS_DBG_ASSERT_EVAL(x) assert(x)
 #else

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d98ddc1c/net/nimble/host/src/ble_hs_pvcy.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_pvcy.c b/net/nimble/host/src/ble_hs_pvcy.c
index ad3fa0c..e471f36 100644
--- a/net/nimble/host/src/ble_hs_pvcy.c
+++ b/net/nimble/host/src/ble_hs_pvcy.c
@@ -135,7 +135,7 @@ ble_hs_pvcy_ensure_started(void)
     }
 
     /* Set up the periodic change of our RPA. */
-    rc = ble_hs_pvcy_set_addr_timeout(ble_hs_cfg.rpa_timeout);
+    rc = ble_hs_pvcy_set_addr_timeout(MYNEWT_VAL(BLE_RPA_TIMEOUT));
     if (rc != 0) {
         return rc;
     }