You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by we...@apache.org on 2016/05/06 18:12:01 UTC

[1/2] incubator-mynewt-core git commit: LL feature configuration for controller moved to nimble_opt.h

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop 6c578986e -> 4d2b24c5e


LL feature configuration for controller moved to nimble_opt.h

The features supported by the controller which were previously
configured in the controller (ble_ll.h) have been moved into
nimble_opt.h to allow for targets to configure whether or not
the controller supports the feature.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/f5ee7ec0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/f5ee7ec0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/f5ee7ec0

Branch: refs/heads/develop
Commit: f5ee7ec08b044b0213eacf9f7f7f2b2a95522592
Parents: 6c57898
Author: William San Filippo <wi...@runtime.io>
Authored: Thu May 5 21:47:04 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Thu May 5 21:47:04 2016 -0700

----------------------------------------------------------------------
 apps/bletest/src/bletest_hci.c                  |  6 +-
 apps/bletest/src/bletest_priv.h                 |  2 +-
 apps/bletest/src/main.c                         | 12 ++--
 .../controller/include/controller/ble_ll.h      | 13 +---
 .../controller/include/controller/ble_ll_conn.h |  4 +-
 net/nimble/controller/src/ble_ll.c              | 18 ++---
 net/nimble/controller/src/ble_ll_adv.c          |  2 +-
 net/nimble/controller/src/ble_ll_conn.c         | 34 ++++-----
 net/nimble/controller/src/ble_ll_conn_hci.c     |  4 +-
 net/nimble/controller/src/ble_ll_ctrl.c         | 20 +++---
 net/nimble/controller/src/ble_ll_hci.c          | 14 ++--
 net/nimble/controller/src/ble_ll_hci_ev.c       |  2 +-
 net/nimble/controller/src/ble_ll_rng.c          |  2 +-
 net/nimble/controller/src/ble_ll_scan.c         |  2 +-
 net/nimble/controller/src/ble_ll_supp_cmd.c     |  4 +-
 net/nimble/drivers/nrf51/src/ble_phy.c          | 24 +++----
 net/nimble/drivers/nrf52/src/ble_phy.c          | 16 ++---
 net/nimble/include/nimble/nimble_opt.h          | 72 ++++++++++++++++++++
 18 files changed, 159 insertions(+), 92 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5ee7ec0/apps/bletest/src/bletest_hci.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/bletest_hci.c b/apps/bletest/src/bletest_hci.c
index b4dcd8b..1eee29c 100755
--- a/apps/bletest/src/bletest_hci.c
+++ b/apps/bletest/src/bletest_hci.c
@@ -61,7 +61,7 @@ bletest_send_conn_update(uint16_t handle)
     assert(rc == 0);
 }
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 void
 bletest_ltk_req_reply(uint16_t handle)
 {
@@ -154,7 +154,7 @@ bletest_hci_rd_bd_addr(void)
     return rc;
 }
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 int
 bletest_hci_le_encrypt(uint8_t *key, uint8_t *pt)
 {
@@ -373,7 +373,7 @@ bletest_hci_le_set_adv_data(uint8_t *data, uint8_t len)
     return ble_hci_cmd_tx_empty_ack(buf);
 }
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 int
 bletest_hci_le_start_encrypt(struct hci_start_encrypt *cmd)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5ee7ec0/apps/bletest/src/bletest_priv.h
----------------------------------------------------------------------
diff --git a/apps/bletest/src/bletest_priv.h b/apps/bletest/src/bletest_priv.h
index db4d4b9..4a00aef 100644
--- a/apps/bletest/src/bletest_priv.h
+++ b/apps/bletest/src/bletest_priv.h
@@ -22,7 +22,7 @@
 
 void bletest_send_conn_update(uint16_t handle);
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 void bletest_ltk_req_reply(uint16_t handle);
 int bletest_send_ltk_req_neg_reply(uint16_t handle);
 int bletest_send_ltk_req_reply(uint16_t handle);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5ee7ec0/apps/bletest/src/main.c
----------------------------------------------------------------------
diff --git a/apps/bletest/src/main.c b/apps/bletest/src/main.c
index f951d0e..5657b09 100755
--- a/apps/bletest/src/main.c
+++ b/apps/bletest/src/main.c
@@ -176,7 +176,7 @@ const uint8_t g_ble_ll_encrypt_test_encrypted_data[16] =
     0x05, 0x8e, 0x3b, 0x8e, 0x27, 0xc2, 0xc6, 0x66
 };
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 /* LTK 0x4C68384139F574D836BCF34E9DFB01BF */
 const uint8_t g_bletest_LTK[16] =
 {
@@ -509,7 +509,7 @@ bletest_execute_initiator(void)
                 new_chan_map[4] = 0;
                 bletest_hci_le_set_host_chan_class(new_chan_map);
             } else if (g_bletest_state == 4) {
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
                 struct hci_start_encrypt hsle;
                 for (i = 0; i < g_bletest_current_conns; ++i) {
                     if (ble_ll_conn_find_active_conn(i + 1)) {
@@ -523,7 +523,7 @@ bletest_execute_initiator(void)
                 }
 #endif
             } else if (g_bletest_state == 8) {
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
                 struct hci_start_encrypt hsle;
                 for (i = 0; i < g_bletest_current_conns; ++i) {
                     if (ble_ll_conn_find_active_conn(i + 1)) {
@@ -647,7 +647,7 @@ bletest_execute_advertiser(void)
 #if (BLETEST_CONCURRENT_CONN_TEST == 1)
     /* See if it is time to hand a data packet to the connection */
     if ((int32_t)(os_time_get() - g_next_os_time) >= 0) {
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
         /* Do we need to send a LTK reply? */
         if (g_bletest_ltk_reply_handle) {
             //bletest_send_ltk_req_neg_reply(g_bletest_ltk_reply_handle);
@@ -876,6 +876,7 @@ bletest_task_handler(void *arg)
     rc = bletest_hci_le_rd_max_datalen();
     assert(rc == 0);
 
+#if (BLE_LL_CFG_FEAT_DATA_LEN_EXT == 1)
     /* Read suggested data length */
     rc = bletest_hci_le_rd_sugg_datalen();
     assert(rc == 0);
@@ -893,9 +894,10 @@ bletest_task_handler(void *arg)
     rc = bletest_hci_le_set_datalen(0x1234, BLETEST_CFG_SUGG_DEF_TXOCTETS,
                                     BLETEST_CFG_SUGG_DEF_TXTIME);
     assert(rc != 0);
+#endif
 
     /* Encrypt a block */
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     rc = bletest_hci_le_encrypt((uint8_t *)g_ble_ll_encrypt_test_key,
                                 (uint8_t *)g_ble_ll_encrypt_test_plain_text);
     assert(rc == 0);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5ee7ec0/net/nimble/controller/include/controller/ble_ll.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll.h b/net/nimble/controller/include/controller/ble_ll.h
index e579a26..c30871e 100644
--- a/net/nimble/controller/include/controller/ble_ll.h
+++ b/net/nimble/controller/include/controller/ble_ll.h
@@ -22,16 +22,7 @@
 
 #include "stats/stats.h"
 #include "hal/hal_cputime.h"
-
-/* Configuration for supported features */
-//#define  BLE_LL_CFG_FEAT_LE_ENCRYPTION
-//#define  BLE_LL_CFG_FEAT_CONN_PARAM_REQ
-//#define  BLE_LL_CFG_FEAT_EXT_REJECT_IND
-#define BLE_LL_CFG_FEAT_SLAVE_INIT_FEAT_XCHG
-//#define  BLE_LL_CFG_FEAT_LE_PING
-#define  BLE_LL_CFG_FEAT_DATA_LEN_EXT
-//#define  BLE_LL_CFG_FEAT_LL_PRIVACY
-//#define  BLE_LL_CFG_FEAT_EXT_SCAN_FILT
+#include "nimble/nimble_opt.h"
 
 /* Controller revision. */
 #define BLE_LL_SUB_VERS_NR      (0x0000)
@@ -396,7 +387,7 @@ void ble_ll_log(uint8_t id, uint8_t arg8, uint16_t arg16, uint32_t arg32);
 #define ble_ll_log(m,n,o,p)
 #endif
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 /* LTK 0x4C68384139F574D836BCF34E9DFB01BF */
 extern const uint8_t g_bletest_LTK[];
 extern uint16_t g_bletest_EDIV;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5ee7ec0/net/nimble/controller/include/controller/ble_ll_conn.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_conn.h b/net/nimble/controller/include/controller/ble_ll_conn.h
index da50b9b..f035852 100644
--- a/net/nimble/controller/include/controller/ble_ll_conn.h
+++ b/net/nimble/controller/include/controller/ble_ll_conn.h
@@ -53,7 +53,7 @@
 /* Definition for RSSI when the RSSI is unknown */
 #define BLE_LL_CONN_UNKNOWN_RSSI        (127)
 
-#if defined(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 /*
  * Encryption states for a connection
  *
@@ -235,7 +235,7 @@ struct ble_ll_conn_sm
      * allocate these from a pool? Not sure what to do. For now, I just use
      * a large chunk of memory per connection.
      */
-#if defined(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     struct ble_ll_conn_enc_data enc_data;
 #endif
     /*

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5ee7ec0/net/nimble/controller/src/ble_ll.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll.c b/net/nimble/controller/src/ble_ll.c
index 06c9125..7ff290d 100644
--- a/net/nimble/controller/src/ble_ll.c
+++ b/net/nimble/controller/src/ble_ll.c
@@ -1120,23 +1120,23 @@ ble_ll_init(uint8_t ll_task_prio, uint8_t num_acl_pkts, uint16_t acl_pkt_size)
     /* Initialize the connection module */
     ble_ll_conn_module_init();
 
-    /* Set the supported features */
-    features = 0;
-#ifdef BLE_LL_CFG_FEAT_DATA_LEN_EXT
+    /* Set the supported features. NOTE: we always support extended reject. */
+    features = BLE_LL_FEAT_EXTENDED_REJ;
+
+#if (BLE_LL_CFG_FEAT_DATA_LEN_EXT == 1)
     features |= BLE_LL_FEAT_DATA_LEN_EXT;
 #endif
-#ifdef BLE_LL_CFG_FEAT_CONN_PARAM_REQ
+#if (BLE_LL_CFG_FEAT_CONN_PARAM_REQ == 1)
     features |= BLE_LL_FEAT_CONN_PARM_REQ;
 #endif
-#ifdef BLE_LL_CFG_FEAT_EXT_REJECT_IND
-    features |= BLE_LL_FEAT_EXTENDED_REJ;
-#endif
-#ifdef BLE_LL_CFG_FEAT_SLAVE_INIT_FEAT_XCHG
+#if (BLE_LL_CFG_FEAT_SLAVE_INIT_FEAT_XCHG == 1)
     features |= BLE_LL_FEAT_SLAVE_INIT;
 #endif
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     features |= BLE_LL_FEAT_LE_ENCRYPTION;
 #endif
+
+    /* Initialize random number generation */
     ble_ll_rand_init();
 
     lldata->ll_supp_features = features;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5ee7ec0/net/nimble/controller/src/ble_ll_adv.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_adv.c b/net/nimble/controller/src/ble_ll_adv.c
index 53c3981..8a1e8e6 100644
--- a/net/nimble/controller/src/ble_ll_adv.c
+++ b/net/nimble/controller/src/ble_ll_adv.c
@@ -358,7 +358,7 @@ ble_ll_adv_tx_start_cb(struct ble_ll_sched_item *sch)
         goto adv_tx_done;
     }
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     /* XXX: automatically do this in the phy based on channel? */
     ble_phy_encrypt_disable();
 #endif

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5ee7ec0/net/nimble/controller/src/ble_ll_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn.c b/net/nimble/controller/src/ble_ll_conn.c
index 0ddf0b8..5bfe9d0 100644
--- a/net/nimble/controller/src/ble_ll_conn.c
+++ b/net/nimble/controller/src/ble_ll_conn.c
@@ -209,7 +209,7 @@ STATS_NAME_START(ble_ll_conn_stats)
     STATS_NAME(ble_ll_conn_stats, mic_failures)
 STATS_NAME_END(ble_ll_conn_stats)
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 /**
  * Called to determine if the received PDU is an empty PDU or not.
  */
@@ -596,7 +596,7 @@ ble_ll_conn_wait_txend(void *arg)
     ble_ll_event_send(&connsm->conn_ev_end);
 }
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 static void
 ble_ll_conn_start_rx_encrypt(void *arg)
 {
@@ -697,7 +697,7 @@ ble_ll_conn_chk_csm_flags(struct ble_ll_conn_sm *connsm)
 {
     uint8_t update_status;
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     if (connsm->csmflags.cfbit.send_ltk_req) {
         /*
          * Send Long term key request event to host. If masked, we need to
@@ -787,7 +787,7 @@ ble_ll_conn_tx_data_pdu(struct ble_ll_conn_sm *connsm)
         m = OS_MBUF_PKTHDR_TO_MBUF(pkthdr);
         nextpkthdr = STAILQ_NEXT(pkthdr, omp_next);
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
         /*
          * If we are encrypting, we are only allowed to send certain
          * kinds of LL control PDU's. If none is enqueued, send empty pdu!
@@ -837,7 +837,7 @@ ble_ll_conn_tx_data_pdu(struct ble_ll_conn_sm *connsm)
             if (cur_offset == 0) {
                 hdr_byte = ble_hdr->txinfo.hdr_byte & BLE_LL_DATA_HDR_LLID_MASK;
             }
-#if defined(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
             if (connsm->enc_data.enc_state > CONN_ENC_S_ENCRYPTED) {
                 /* We will allow a next packet if it itself is allowed */
                 pkthdr = OS_MBUF_PKTHDR(connsm->cur_tx_pdu);
@@ -852,7 +852,7 @@ ble_ll_conn_tx_data_pdu(struct ble_ll_conn_sm *connsm)
             /* Empty PDU here. NOTE: header byte gets set later */
             pktlen = 0;
             cur_txlen = 0;
-#if defined(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
             if (connsm->enc_data.enc_state > CONN_ENC_S_ENCRYPTED) {
                 /* We will allow a next packet if it itself is allowed */
                 if (nextpkthdr && !ble_ll_ctrl_enc_allowed_pdu(nextpkthdr)) {
@@ -975,7 +975,7 @@ conn_tx_pdu:
         txend_func = NULL;
     }
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     int is_ctrl;
     uint8_t llid;
     uint8_t opcode;
@@ -1119,7 +1119,7 @@ ble_ll_conn_event_start_cb(struct ble_ll_sched_item *sch)
         /* Set start time of transmission */
         rc = ble_phy_tx_set_start_time(sch->start_time + XCVR_PROC_DELAY_USECS);
         if (!rc) {
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
             if (CONN_F_ENCRYPTED(connsm)) {
                 ble_phy_encrypt_enable(connsm->enc_data.tx_pkt_cntr,
                                        connsm->enc_data.iv,
@@ -1141,7 +1141,7 @@ ble_ll_conn_event_start_cb(struct ble_ll_sched_item *sch)
             rc = BLE_LL_SCHED_STATE_DONE;
         }
     } else {
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
             if (CONN_F_ENCRYPTED(connsm)) {
                 ble_phy_encrypt_enable(connsm->enc_data.rx_pkt_cntr,
                                        connsm->enc_data.iv,
@@ -1419,7 +1419,7 @@ ble_ll_conn_sm_new(struct ble_ll_conn_sm *connsm)
     connsm->eff_max_rx_octets = BLE_LL_CONN_SUPP_BYTES_MIN;
 
     /* Reset encryption data */
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     memset(&connsm->enc_data, 0, sizeof(struct ble_ll_conn_enc_data));
     connsm->enc_data.enc_state = CONN_ENC_S_UNENCRYPTED;
 #endif
@@ -2284,7 +2284,7 @@ ble_ll_conn_rx_data_pdu(struct os_mbuf *rxpdu, struct ble_mbuf_hdr *hdr)
                     goto conn_rx_data_pdu_end;
                 }
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
                 /*
                  * XXX: should we check to see if we are in a state where we
                  * might expect to get an encrypted PDU?
@@ -2436,14 +2436,14 @@ ble_ll_conn_rx_isr_end(struct os_mbuf *rxpdu, uint32_t aa)
         conn_nesn = connsm->next_exp_seqnum;
         if ((hdr_sn && conn_nesn) || (!hdr_sn && !conn_nesn)) {
             connsm->next_exp_seqnum ^= 1;
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
             if (CONN_F_ENCRYPTED(connsm) && !ble_ll_conn_is_empty_pdu(rxpdu)) {
                 ++connsm->enc_data.rx_pkt_cntr;
             }
 #endif
         }
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
         ble_ll_log(BLE_LL_LOG_ID_CONN_RX,
                    hdr_byte,
                    (uint16_t)connsm->tx_seqnum << 8 | conn_nesn,
@@ -2481,7 +2481,7 @@ ble_ll_conn_rx_isr_end(struct os_mbuf *rxpdu, uint32_t aa)
                  */
                 txpdu = connsm->cur_tx_pdu;
                 if (txpdu) {
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
                     if (connsm->enc_data.tx_encrypted) {
                         ++connsm->enc_data.tx_pkt_cntr;
                     }
@@ -2543,7 +2543,7 @@ chk_rx_terminate_ind:
         } else {
             /* A slave always replies */
             reply = 1;
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
             if (is_ctrl && (opcode == BLE_LL_CTRL_PAUSE_ENC_RSP)) {
                 connsm->enc_data.enc_state = CONN_ENC_S_UNENCRYPTED;
             }
@@ -2613,7 +2613,7 @@ ble_ll_conn_enqueue_pkt(struct ble_ll_conn_sm *connsm, struct os_mbuf *om,
     }
 
     lifo = 0;
-#if defined(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     if (connsm->enc_data.enc_state > CONN_ENC_S_ENCRYPTED) {
         uint8_t llid;
 
@@ -2885,6 +2885,8 @@ ble_ll_conn_module_reset(void)
         ble_ll_conn_end(connsm, BLE_ERR_SUCCESS);
     }
 
+    /* Get the maximum supported PHY PDU size from the PHY */
+
     /* Configure the global LL parameters */
     conn_params = &g_ble_ll_conn_params;
     maxbytes = NIMBLE_OPT_LL_SUPP_MAX_RX_BYTES + BLE_LL_DATA_MIC_LEN;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5ee7ec0/net/nimble/controller/src/ble_ll_conn_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn_hci.c b/net/nimble/controller/src/ble_ll_conn_hci.c
index 791fe4a..f1b0cd9 100644
--- a/net/nimble/controller/src/ble_ll_conn_hci.c
+++ b/net/nimble/controller/src/ble_ll_conn_hci.c
@@ -874,7 +874,7 @@ ble_ll_conn_hci_set_chan_class(uint8_t *cmdbuf)
     return rc;
 }
 
-#ifdef BLE_LL_CFG_FEAT_DATA_LEN_EXT
+#if (BLE_LL_CFG_FEAT_DATA_LEN_EXT == 1)
 int
 ble_ll_conn_hci_set_data_len(uint8_t *cmdbuf, uint8_t *rspbuf, uint8_t *rsplen)
 {
@@ -915,7 +915,7 @@ ble_ll_conn_hci_set_data_len(uint8_t *cmdbuf, uint8_t *rspbuf, uint8_t *rsplen)
 }
 #endif
 
-#if defined(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 /**
  * LE start encrypt command
  *

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5ee7ec0/net/nimble/controller/src/ble_ll_ctrl.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_ctrl.c b/net/nimble/controller/src/ble_ll_ctrl.c
index e72e0f9..aee7c83 100644
--- a/net/nimble/controller/src/ble_ll_ctrl.c
+++ b/net/nimble/controller/src/ble_ll_ctrl.c
@@ -328,7 +328,7 @@ ble_ll_ctrl_datalen_upd_make(struct ble_ll_conn_sm *connsm, uint8_t *dptr)
     htole16(dptr + 7, connsm->max_tx_time);
 }
 
-#if defined(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 void
 ble_ll_calc_session_key(struct ble_ll_conn_sm *connsm)
 {
@@ -925,7 +925,7 @@ ble_ll_ctrl_rx_reject_ind(struct ble_ll_conn_sm *connsm, uint8_t *dptr,
             ble_ll_hci_ev_conn_update(connsm, ble_error);
         }
         break;
-#if defined(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     case BLE_LL_CTRL_PROC_ENCRYPT:
         ble_ll_ctrl_proc_stop(connsm, BLE_LL_CTRL_PROC_ENCRYPT);
         ble_ll_hci_ev_encrypt_chg(connsm, ble_error);
@@ -1278,7 +1278,7 @@ ble_ll_ctrl_proc_init(struct ble_ll_conn_sm *connsm, int ctrl_proc)
             opcode = BLE_LL_CTRL_LENGTH_REQ;
             ble_ll_ctrl_datalen_upd_make(connsm, dptr);
             break;
-#if defined(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
         /* XXX: deal with already encrypted connection.*/
         case BLE_LL_CTRL_PROC_ENCRYPT:
             /* If we are already encrypted we do pause procedure */
@@ -1493,7 +1493,7 @@ ble_ll_ctrl_rx_pdu(struct ble_ll_conn_sm *connsm, struct os_mbuf *om)
     uint8_t *dptr;
     uint8_t *rspbuf;
     uint8_t *rspdata;
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     int restart_encryption;
 #endif
 
@@ -1538,7 +1538,7 @@ ble_ll_ctrl_rx_pdu(struct ble_ll_conn_sm *connsm, struct os_mbuf *om)
         goto rx_malformed_ctrl;
     }
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     restart_encryption = 0;
 #endif
 
@@ -1646,7 +1646,7 @@ ble_ll_ctrl_rx_pdu(struct ble_ll_conn_sm *connsm, struct os_mbuf *om)
     case BLE_LL_CTRL_SLAVE_FEATURE_REQ:
         rsp_opcode = ble_ll_ctrl_rx_feature_req(connsm, dptr, rspbuf, opcode);
         break;
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     case BLE_LL_CTRL_ENC_REQ:
         rsp_opcode = ble_ll_ctrl_rx_enc_req(connsm, dptr, rspdata);
         break;
@@ -1704,7 +1704,7 @@ ll_ctrl_send_rsp:
         }
         len = g_ble_ll_ctrl_pkt_lengths[rsp_opcode] + 1;
         ble_ll_conn_enqueue_pkt(connsm, om, BLE_LL_LLID_CTRL, len);
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
         if (restart_encryption) {
             /* XXX: what happens if this fails? Meaning we cant allocate
                mbuf? */
@@ -1793,18 +1793,18 @@ ble_ll_ctrl_tx_done(struct os_mbuf *txpdu, struct ble_ll_conn_sm *connsm)
             connsm->reject_reason = txpdu->om_data[2];
             connsm->csmflags.cfbit.host_expects_upd_event = 1;
         }
-#if defined (BLE_LL_CFG_FEAT_LE_ENCRYPTION)
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
         if (connsm->enc_data.enc_state > CONN_ENC_S_ENCRYPTED) {
             connsm->enc_data.enc_state = CONN_ENC_S_UNENCRYPTED;
         }
 #endif
         break;
     case BLE_LL_CTRL_REJECT_IND:
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
         connsm->enc_data.enc_state = CONN_ENC_S_UNENCRYPTED;
 #endif
         break;
-#if defined (BLE_LL_CFG_FEAT_LE_ENCRYPTION)
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     case BLE_LL_CTRL_PAUSE_ENC_REQ:
         /* note: fall-through intentional */
     case BLE_LL_CTRL_ENC_REQ:

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5ee7ec0/net/nimble/controller/src/ble_ll_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_hci.c b/net/nimble/controller/src/ble_ll_hci.c
index 1d3b22e..862eebc 100644
--- a/net/nimble/controller/src/ble_ll_hci.c
+++ b/net/nimble/controller/src/ble_ll_hci.c
@@ -101,7 +101,7 @@ ble_ll_hci_send_noop(void)
     return rc;
 }
 
-#if defined(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 /**
  * LE encrypt command
  *
@@ -279,7 +279,7 @@ ble_ll_hci_le_read_bufsize(uint8_t *rspbuf, uint8_t *rsplen)
     return BLE_ERR_SUCCESS;
 }
 
-#ifdef BLE_LL_CFG_FEAT_DATA_LEN_EXT
+#if (BLE_LL_CFG_FEAT_DATA_LEN_EXT == 1)
 /**
  * HCI write suggested default data length command.
  *
@@ -342,6 +342,7 @@ ble_ll_hci_le_rd_sugg_data_len(uint8_t *rspbuf, uint8_t *rsplen)
     *rsplen = BLE_HCI_RD_SUGG_DATALEN_RSPLEN;
     return BLE_ERR_SUCCESS;
 }
+#endif
 
 /**
  * HCI read maximum data length command. Returns the controllers max supported
@@ -363,7 +364,6 @@ ble_ll_hci_le_rd_max_data_len(uint8_t *rspbuf, uint8_t *rsplen)
     *rsplen = BLE_HCI_RD_MAX_DATALEN_RSPLEN;
     return BLE_ERR_SUCCESS;
 }
-#endif
 
 /**
  * HCI read local supported features command. Returns the features
@@ -601,7 +601,7 @@ ble_ll_hci_le_cmd_proc(uint8_t *cmdbuf, uint16_t ocf, uint8_t *rsplen)
     case BLE_HCI_OCF_LE_RD_REM_FEAT:
         rc = ble_ll_conn_hci_read_rem_features(cmdbuf);
         break;
-#if defined(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     case BLE_HCI_OCF_LE_ENCRYPT:
         rc = ble_ll_hci_le_encrypt(cmdbuf, rspbuf, rsplen);
         break;
@@ -609,7 +609,7 @@ ble_ll_hci_le_cmd_proc(uint8_t *cmdbuf, uint16_t ocf, uint8_t *rsplen)
     case BLE_HCI_OCF_LE_RAND:
         rc = ble_ll_hci_le_rand(rspbuf, rsplen);
         break;
-#if defined(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     case BLE_HCI_OCF_LE_START_ENCRYPT:
         rc = ble_ll_conn_hci_le_start_encrypt(cmdbuf);
         break;
@@ -628,7 +628,7 @@ ble_ll_hci_le_cmd_proc(uint8_t *cmdbuf, uint16_t ocf, uint8_t *rsplen)
     case BLE_HCI_OCF_LE_REM_CONN_PARAM_RR:
         rc = ble_ll_conn_hci_param_reply(cmdbuf, 1);
         break;
-#ifdef BLE_LL_CFG_FEAT_DATA_LEN_EXT
+#if (BLE_LL_CFG_FEAT_DATA_LEN_EXT == 1)
     case BLE_HCI_OCF_LE_SET_DATA_LEN:
         rc = ble_ll_conn_hci_set_data_len(cmdbuf, rspbuf, rsplen);
         break;
@@ -638,10 +638,10 @@ ble_ll_hci_le_cmd_proc(uint8_t *cmdbuf, uint16_t ocf, uint8_t *rsplen)
     case BLE_HCI_OCF_LE_WR_SUGG_DEF_DATA_LEN:
         rc = ble_ll_hci_le_wr_sugg_data_len(cmdbuf);
         break;
+#endif
     case BLE_HCI_OCF_LE_RD_MAX_DATA_LEN:
         rc = ble_ll_hci_le_rd_max_data_len(rspbuf, rsplen);
         break;
-#endif
     default:
         rc = BLE_ERR_UNKNOWN_HCI_CMD;
         break;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5ee7ec0/net/nimble/controller/src/ble_ll_hci_ev.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_hci_ev.c b/net/nimble/controller/src/ble_ll_hci_ev.c
index ed0f1ba..773e4e6 100644
--- a/net/nimble/controller/src/ble_ll_hci_ev.c
+++ b/net/nimble/controller/src/ble_ll_hci_ev.c
@@ -110,7 +110,7 @@ ble_ll_hci_ev_conn_update(struct ble_ll_conn_sm *connsm, uint8_t status)
     }
 }
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 void
 ble_ll_hci_ev_encrypt_chg(struct ble_ll_conn_sm *connsm, uint8_t status)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5ee7ec0/net/nimble/controller/src/ble_ll_rng.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_rng.c b/net/nimble/controller/src/ble_ll_rng.c
index b6f12f4..d93c420 100644
--- a/net/nimble/controller/src/ble_ll_rng.c
+++ b/net/nimble/controller/src/ble_ll_rng.c
@@ -34,7 +34,7 @@ struct ble_ll_rnum_data
     uint8_t _pad;
 };
 
-#if defined BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 int
 ble_ll_rng_init(void)
 {

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5ee7ec0/net/nimble/controller/src/ble_ll_scan.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_scan.c b/net/nimble/controller/src/ble_ll_scan.c
index 94a33e3..7ebfc46 100644
--- a/net/nimble/controller/src/ble_ll_scan.c
+++ b/net/nimble/controller/src/ble_ll_scan.c
@@ -505,7 +505,7 @@ ble_ll_scan_start(struct ble_ll_scan_sm *scansm, uint8_t chan)
      */
     ble_phy_set_txend_cb(NULL, NULL);
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     ble_phy_encrypt_disable();
 #endif
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5ee7ec0/net/nimble/controller/src/ble_ll_supp_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_supp_cmd.c b/net/nimble/controller/src/ble_ll_supp_cmd.c
index d921ccf..738ee9c 100644
--- a/net/nimble/controller/src/ble_ll_supp_cmd.c
+++ b/net/nimble/controller/src/ble_ll_supp_cmd.c
@@ -106,7 +106,7 @@
 #define BLE_SUPP_CMD_LE_SET_HOST_CHAN_CLASS (1 << 3)
 #define BLE_SUPP_CMD_LE_RD_CHAN_MAP         (1 << 4)
 #define BLE_SUPP_CMD_LE_RD_REM_USED_FEAT    (1 << 5)
-#if defined(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 #define BLE_SUPP_CMD_LE_ENCRYPT             (1 << 6)
 #else
 #define BLE_SUPP_CMD_LE_ENCRYPT             (0 << 6)
@@ -126,7 +126,7 @@
 )
 
 /* Octet 28 */
-#if defined(BLE_LL_CFG_FEAT_LE_ENCRYPTION)
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 #define BLE_SUPP_CMD_LE_START_ENCRYPT       (1 << 0)
 #else
 #define BLE_SUPP_CMD_LE_START_ENCRYPT       (0 << 0)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5ee7ec0/net/nimble/drivers/nrf51/src/ble_phy.c
----------------------------------------------------------------------
diff --git a/net/nimble/drivers/nrf51/src/ble_phy.c b/net/nimble/drivers/nrf51/src/ble_phy.c
index ae3835b..7dc961e 100644
--- a/net/nimble/drivers/nrf51/src/ble_phy.c
+++ b/net/nimble/drivers/nrf51/src/ble_phy.c
@@ -42,7 +42,7 @@
  */
 
 /* The NRF51 does not support encryption for payload size < 27 bytes */
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 #if (NIMBLE_OPT_LL_MAX_PKT_SIZE > 27)
 #error "nrf51 does not support encryption with packet size > 27 bytes!"
 #endif
@@ -89,7 +89,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];
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 static uint32_t g_ble_phy_enc_buf[(BLE_PHY_MAX_PDU_LEN + 3) / 4];
 #endif
 
@@ -158,7 +158,7 @@ STATS_NAME_END(ble_phy_stats)
  *  bit in the NVIC just to be sure when we disable the PHY.
  */
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 
 /* Per nordic, the number of bytes needed for scratch is 16 + MAX_PKT_SIZE */
 #define NRF_ENC_SCRATCH_WORDS   (((NIMBLE_OPT_LL_MAX_PKT_SIZE + 16) + 3) / 4)
@@ -235,7 +235,7 @@ nrf_wait_disabled(void)
 static void
 ble_phy_rx_xcvr_setup(void)
 {
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (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];
@@ -301,7 +301,7 @@ ble_phy_tx_end_isr(void)
     NRF_RADIO->EVENTS_END = 0;
     wfr_time = NRF_RADIO->SHORTS;
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (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.
@@ -353,7 +353,7 @@ static void
 ble_phy_rx_end_isr(void)
 {
     int rc;
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     uint8_t *dptr;
 #endif
     uint8_t crcok;
@@ -371,7 +371,7 @@ ble_phy_rx_end_isr(void)
     ble_hdr = BLE_MBUF_HDR_PTR(g_ble_phy_data.rxpdu);
     assert(NRF_RADIO->EVENTS_RSSIEND != 0);
     ble_hdr->rxinfo.rssi = -1 * NRF_RADIO->RSSISAMPLE;
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     dptr = g_ble_phy_data.rxpdu->om_data;
 #endif
     /* Count PHY crc errors and valid packets */
@@ -381,7 +381,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;
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (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)) {
@@ -416,7 +416,7 @@ ble_phy_rx_end_isr(void)
     rxpdu = g_ble_phy_data.rxpdu;
     g_ble_phy_data.rxpdu = NULL;
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     if (g_ble_phy_data.phy_encrypted) {
         /*
          * XXX: This is a horrible ugly hack to deal with the RAM S1 byte.
@@ -581,7 +581,7 @@ ble_phy_init(void)
     /* Captures tx/rx start in timer0 capture 1 */
     NRF_PPI->CHENSET = PPI_CHEN_CH26_Msk;
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     NRF_CCM->INTENCLR = 0xffffffff;
     NRF_CCM->SHORTS = CCM_SHORTS_ENDKSGEN_CRYPT_Msk;
     NRF_CCM->ENABLE = CCM_ENABLE_ENABLE_Enabled;
@@ -650,7 +650,7 @@ ble_phy_rx(void)
     return 0;
 }
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (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
@@ -793,7 +793,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;
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     if (g_ble_phy_data.phy_encrypted) {
         /* RAM representation has S0, LENGTH and S1 fields. (3 bytes) */
         dptr = (uint8_t *)&g_ble_phy_enc_buf[0];

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5ee7ec0/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 9a5e561..ccc043b 100644
--- a/net/nimble/drivers/nrf52/src/ble_phy.c
+++ b/net/nimble/drivers/nrf52/src/ble_phy.c
@@ -77,7 +77,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];
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 static uint32_t g_ble_phy_enc_buf[(BLE_PHY_MAX_PDU_LEN + 3) / 4];
 #endif
 
@@ -146,7 +146,7 @@ STATS_NAME_END(ble_phy_stats)
  *  bit in the NVIC just to be sure when we disable the PHY.
  */
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
 
 /*
  * Per nordic, the number of bytes needed for scratch is 16 + MAX_PKT_SIZE.
@@ -230,7 +230,7 @@ nrf_wait_disabled(void)
 static void
 ble_phy_rx_xcvr_setup(void)
 {
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (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];
@@ -296,7 +296,7 @@ ble_phy_tx_end_isr(void)
     NRF_RADIO->EVENTS_END = 0;
     wfr_time = NRF_RADIO->SHORTS;
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (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.
@@ -374,7 +374,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;
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (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)) {
@@ -573,7 +573,7 @@ ble_phy_init(void)
     /* Captures tx/rx start in timer0 capture 1 */
     NRF_PPI->CHENSET = PPI_CHEN_CH26_Msk;
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
     NRF_CCM->INTENCLR = 0xffffffff;
     NRF_CCM->SHORTS = CCM_SHORTS_ENDKSGEN_CRYPT_Msk;
     NRF_CCM->ENABLE = CCM_ENABLE_ENABLE_Enabled;
@@ -642,7 +642,7 @@ ble_phy_rx(void)
     return 0;
 }
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (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
@@ -775,7 +775,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;
 
-#ifdef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#if (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;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/f5ee7ec0/net/nimble/include/nimble/nimble_opt.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/nimble_opt.h b/net/nimble/include/nimble/nimble_opt.h
index d008d54..ae70de1 100644
--- a/net/nimble/include/nimble/nimble_opt.h
+++ b/net/nimble/include/nimble/nimble_opt.h
@@ -287,6 +287,78 @@
 #define NIMBLE_OPT_LL_RNG_BUFSIZE               (32)
 #endif
 
+/*
+ * Configuration for LL supported features.
+ *
+ * There are a total 8 features that the LL can support. These can be found in
+ * v4.2, Vol 6 Part B Section 4.6.
+ *
+ * These feature definitions are used to inform a host or other controller
+ * about the LL features supported by the controller.
+ *
+ * NOTE: the controller always supports extended reject indicate and thus is
+ * not listed here.
+ */
+
+ /*
+  * This option enables/disables encryption support in the controller. This
+  * option saves both both code and RAM.
+  */
+#ifndef BLE_LL_CFG_FEAT_LE_ENCRYPTION
+#define BLE_LL_CFG_FEAT_LE_ENCRYPTION           (0)
+#endif
+
+/*
+ * This option enables/disables the connection parameter request procedure.
+ * This is implemented in the controller but is disabled by default.
+ */
+#ifndef BLE_LL_CFG_FEAT_CONN_PARAM_REQ
+#define BLE_LL_CFG_FEAT_CONN_PARAM_REQ          (0)
+#endif
+
+/*
+ * This option allows a slave to initiate the feature exchange procedure.
+ * This feature is implemented but currently has no impact on code or ram size
+ */
+#ifndef BLE_LL_CFG_FEAT_SLAVE_INIT_FEAT_XCHG
+#define BLE_LL_CFG_FEAT_SLAVE_INIT_FEAT_XCHG    (1)
+#endif
+
+/*
+ * This option allows a controller to send/receive LE pings. Currently,
+ * this feature is not implemented by the controller so turning it on or off
+ * has no effect.
+ */
+#ifndef BLE_LL_CFG_FEAT_LE_PING
+#define  BLE_LL_CFG_FEAT_LE_PING                (0)
+#endif
+
+/*
+ * This option enables/disables the data length update procedure in the
+ * controller. If enabled, the controller is allowed to change the size of
+ * tx/rx pdu's used in a connection. This option has only minor impact on
+ * code size and non on RAM.
+ */
+#ifndef BLE_LL_CFG_FEAT_DATA_LEN_EXT
+#define  BLE_LL_CFG_FEAT_DATA_LEN_EXT           (1)
+#endif
+
+/*
+ * This option is used to enable/disable LL privacy. Currently, this feature
+ * is not supported by the nimble controller.
+ */
+#ifndef BLE_LL_CFG_FEAT_LL_PRIVACY
+#define BLE_LL_CFG_FEAT_LL_PRIVACY              (0)
+#endif
+
+/*
+ * This option is used to enable/disable the extended scanner filter policy
+ * feature. Currently, this feature is not supported by the nimble controller.
+ */
+#ifndef BLE_LL_CFG_FEAT_EXT_SCAN_FILT
+#define  BLE_LL_CFG_FEAT_EXT_SCAN_FILT          (0)
+#endif
+
 /* Include automatically-generated settings. */
 #include "nimble/nimble_opt_auto.h"
 



[2/2] incubator-mynewt-core git commit: Code now asks PHY maximum data pdu payload size

Posted by we...@apache.org.
Code now asks PHY maximum data pdu payload size

The connection initialization code now asks the PHY for its
maximum supported PDU. If this size is smaller than the
configured size, the PHY maximum supported size is used.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/4d2b24c5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/4d2b24c5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/4d2b24c5

Branch: refs/heads/develop
Commit: 4d2b24c5ed6a14ba9fae61c10aa89dfd8c7d9293
Parents: f5ee7ec
Author: William San Filippo <wi...@runtime.io>
Authored: Fri May 6 11:05:34 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Fri May 6 11:05:34 2016 -0700

----------------------------------------------------------------------
 .../controller/include/controller/ble_ll.h      |  1 +
 .../controller/include/controller/ble_phy.h     | 13 +++++++
 net/nimble/controller/src/ble_ll_conn.c         | 28 ++++++++------
 net/nimble/drivers/nrf51/src/ble_phy.c          | 39 ++++++++++++++++----
 net/nimble/drivers/nrf52/src/ble_phy.c          | 13 +++++++
 net/nimble/include/nimble/nimble_opt.h          |  2 +-
 6 files changed, 76 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4d2b24c5/net/nimble/controller/include/controller/ble_ll.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll.h b/net/nimble/controller/include/controller/ble_ll.h
index c30871e..8c8cb54 100644
--- a/net/nimble/controller/include/controller/ble_ll.h
+++ b/net/nimble/controller/include/controller/ble_ll.h
@@ -241,6 +241,7 @@ struct ble_dev_addr
 #define BLE_LL_DATA_HDR_SN_MASK         (0x08)
 #define BLE_LL_DATA_HDR_MD_MASK         (0x10)
 #define BLE_LL_DATA_HDR_RSRVD_MASK      (0xE0)
+#define BLE_LL_DATA_PDU_MAX_PYLD        (251)
 #define BLE_LL_DATA_MIC_LEN             (4)
 
 /* LLID definitions */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4d2b24c5/net/nimble/controller/include/controller/ble_phy.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_phy.h b/net/nimble/controller/include/controller/ble_phy.h
index 5c22d24..edbfd89 100644
--- a/net/nimble/controller/include/controller/ble_phy.h
+++ b/net/nimble/controller/include/controller/ble_phy.h
@@ -118,12 +118,25 @@ uint8_t ble_phy_xcvr_state_get(void);
 /* Returns 'true' if a reception has started */
 int ble_phy_rx_started(void);
 
+/*
+ * Returns the maximum supported tx/rx PDU payload size, in bytes, for data
+ * channel PDUs (this does not apply to advertising channel PDUs). Note
+ * that the data channel PDU is composed of a 2-byte header, the payload, and
+ * an optional MIC. The maximum payload is 251 bytes.
+ */
+uint8_t ble_phy_max_data_pdu_pyld(void);
+
 /* Gets the current access address */
 uint32_t ble_phy_access_addr_get(void);
 
+/* Enable encryption */
 void ble_phy_encrypt_enable(uint64_t pkt_counter, uint8_t *iv, uint8_t *key,
                             uint8_t is_master);
+
+/* Disable encryption */
 void ble_phy_encrypt_disable(void);
+
+/* Set the packet counters and dir used by LE encyption */
 void ble_phy_encrypt_set_pkt_cntr(uint64_t pkt_counter, int dir);
 
 #endif /* H_BLE_PHY_ */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4d2b24c5/net/nimble/controller/src/ble_ll_conn.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn.c b/net/nimble/controller/src/ble_ll_conn.c
index 5bfe9d0..ad2b21a 100644
--- a/net/nimble/controller/src/ble_ll_conn.c
+++ b/net/nimble/controller/src/ble_ll_conn.c
@@ -2865,6 +2865,7 @@ err_slave_start:
 void
 ble_ll_conn_module_reset(void)
 {
+    uint8_t max_phy_pyld;
     uint16_t maxbytes;
     struct ble_ll_conn_sm *connsm;
     struct ble_ll_conn_global_params *conn_params;
@@ -2889,17 +2890,22 @@ ble_ll_conn_module_reset(void)
 
     /* Configure the global LL parameters */
     conn_params = &g_ble_ll_conn_params;
-    maxbytes = NIMBLE_OPT_LL_SUPP_MAX_RX_BYTES + BLE_LL_DATA_MIC_LEN;
-    conn_params->supp_max_rx_time = BLE_TX_DUR_USECS_M(maxbytes);
-    conn_params->supp_max_rx_octets = NIMBLE_OPT_LL_SUPP_MAX_RX_BYTES;
-
-    maxbytes = NIMBLE_OPT_LL_SUPP_MAX_TX_BYTES + BLE_LL_DATA_MIC_LEN;
-    conn_params->supp_max_tx_time = BLE_TX_DUR_USECS_M(maxbytes);
-    conn_params->supp_max_tx_octets = NIMBLE_OPT_LL_SUPP_MAX_TX_BYTES;
-
-    maxbytes = NIMBLE_OPT_LL_CONN_INIT_MAX_TX_BYTES + BLE_LL_DATA_MIC_LEN;
-    conn_params->conn_init_max_tx_time = BLE_TX_DUR_USECS_M(maxbytes);
-    conn_params->conn_init_max_tx_octets = NIMBLE_OPT_LL_CONN_INIT_MAX_TX_BYTES;
+    max_phy_pyld = ble_phy_max_data_pdu_pyld();
+
+    maxbytes = min(NIMBLE_OPT_LL_SUPP_MAX_RX_BYTES, max_phy_pyld);
+    conn_params->supp_max_rx_octets = maxbytes;
+    conn_params->supp_max_rx_time =
+        BLE_TX_DUR_USECS_M(maxbytes + BLE_LL_DATA_MIC_LEN);
+
+    maxbytes = min(NIMBLE_OPT_LL_SUPP_MAX_TX_BYTES, max_phy_pyld);
+    conn_params->supp_max_tx_octets = maxbytes;
+    conn_params->supp_max_tx_time =
+        BLE_TX_DUR_USECS_M(maxbytes + BLE_LL_DATA_MIC_LEN);
+
+    maxbytes = min(NIMBLE_OPT_LL_CONN_INIT_MAX_TX_BYTES, max_phy_pyld);
+    conn_params->conn_init_max_tx_octets = maxbytes;
+    conn_params->conn_init_max_tx_time =
+        BLE_TX_DUR_USECS_M(maxbytes + BLE_LL_DATA_MIC_LEN);
 
     conn_params->sugg_tx_octets = BLE_LL_CONN_SUPP_BYTES_MIN;
     conn_params->sugg_tx_time = BLE_LL_CONN_SUPP_TIME_MIN;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4d2b24c5/net/nimble/drivers/nrf51/src/ble_phy.c
----------------------------------------------------------------------
diff --git a/net/nimble/drivers/nrf51/src/ble_phy.c b/net/nimble/drivers/nrf51/src/ble_phy.c
index 7dc961e..e0f1fb2 100644
--- a/net/nimble/drivers/nrf51/src/ble_phy.c
+++ b/net/nimble/drivers/nrf51/src/ble_phy.c
@@ -41,13 +41,6 @@
  * crystal accuracy
  */
 
-/* The NRF51 does not support encryption for payload size < 27 bytes */
-#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
-#if (NIMBLE_OPT_LL_MAX_PKT_SIZE > 27)
-#error "nrf51 does not support encryption with packet size > 27 bytes!"
-#endif
-#endif
-
 /* To disable all radio interrupts */
 #define NRF_RADIO_IRQ_MASK_ALL  (0x34FF)
 
@@ -67,6 +60,12 @@
 #define NRF_TX_PWR_MAX_DBM      (4)
 #define NRF_TX_PWR_MIN_DBM      (-40)
 
+/* Max. encrypted payload length */
+#define NRF_MAX_ENCRYPTED_PYLD_LEN  (27)
+#define NRF_ENC_HDR_SIZE            (3)
+#define NRF_ENC_BUF_SIZE            \
+    (NRF_MAX_ENCRYPTED_PYLD_LEN + NRF_ENC_HDR_SIZE + BLE_LL_DATA_MIC_LEN)
+
 /* BLE PHY data structure */
 struct ble_phy_obj
 {
@@ -90,7 +89,8 @@ struct ble_phy_obj g_ble_phy_data;
 static uint32_t g_ble_phy_txrx_buf[(BLE_PHY_MAX_PDU_LEN + 3) / 4];
 
 #if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
-static uint32_t g_ble_phy_enc_buf[(BLE_PHY_MAX_PDU_LEN + 3) / 4];
+/* Make sure word-aligned for faster copies */
+static uint32_t g_ble_phy_enc_buf[(NRF_ENC_BUF_SIZE + 3) / 4];
 #endif
 
 /* Statistics */
@@ -1061,3 +1061,26 @@ ble_phy_xcvr_state_get(void)
     return (uint8_t)state;
 }
 
+/*
+ * Returns the maximum supported tx/rx PDU payload size, in bytes, for data
+ * channel PDUs (this does not apply to advertising channel PDUs). Note
+ * that the data channel PDU is composed of a 2-byte header, the payload, and
+ * an optional MIC. The maximum payload is 251 bytes.
+ */
+
+/**
+ * Called to return the maximum data pdu payload length supported by the
+ * phy. For this chip, if encryption is enabled, the maximum payload is 27
+ * bytes.
+ *
+ * @return uint8_t Maximum data channel PDU payload size supported
+ */
+uint8_t
+ble_phy_max_data_pdu_pyld(void)
+{
+#if (BLE_LL_CFG_FEAT_LE_ENCRYPTION == 1)
+    return NRF_MAX_ENCRYPTED_PYLD_LEN;
+#else
+    return BLE_LL_DATA_PDU_MAX_PYLD;
+#endif
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4d2b24c5/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 ccc043b..13e75fd 100644
--- a/net/nimble/drivers/nrf52/src/ble_phy.c
+++ b/net/nimble/drivers/nrf52/src/ble_phy.c
@@ -1034,3 +1034,16 @@ ble_phy_xcvr_state_get(void)
     state = NRF_RADIO->STATE;
     return (uint8_t)state;
 }
+
+/**
+ * Called to return the maximum data pdu payload length supported by the
+ * phy. For this chip, if encryption is enabled, the maximum payload is 27
+ * bytes.
+ *
+ * @return uint8_t Maximum data channel PDU payload size supported
+ */
+uint8_t
+ble_phy_max_data_pdu_pyld(void)
+{
+    return BLE_LL_DATA_PDU_MAX_PYLD;
+}

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/4d2b24c5/net/nimble/include/nimble/nimble_opt.h
----------------------------------------------------------------------
diff --git a/net/nimble/include/nimble/nimble_opt.h b/net/nimble/include/nimble/nimble_opt.h
index ae70de1..1587015 100644
--- a/net/nimble/include/nimble/nimble_opt.h
+++ b/net/nimble/include/nimble/nimble_opt.h
@@ -305,7 +305,7 @@
   * option saves both both code and RAM.
   */
 #ifndef BLE_LL_CFG_FEAT_LE_ENCRYPTION
-#define BLE_LL_CFG_FEAT_LE_ENCRYPTION           (0)
+#define BLE_LL_CFG_FEAT_LE_ENCRYPTION           (1)
 #endif
 
 /*