diff options
author | William San Filippo <wills@runtime.io> | 2016-05-05 21:47:04 -0700 |
---|---|---|
committer | William San Filippo <wills@runtime.io> | 2016-05-05 21:47:04 -0700 |
commit | f5ee7ec08b044b0213eacf9f7f7f2b2a95522592 (patch) | |
tree | cabb3f45458b98e3179f7e3f780b901ddceaf8d0 /net | |
parent | 6c578986e0f9c2a63ed70d79b4370c5b66c1f5d0 (diff) |
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.
Diffstat (limited to 'net')
-rw-r--r-- | net/nimble/controller/include/controller/ble_ll.h | 13 | ||||
-rw-r--r-- | net/nimble/controller/include/controller/ble_ll_conn.h | 4 | ||||
-rw-r--r-- | net/nimble/controller/src/ble_ll.c | 18 | ||||
-rw-r--r-- | net/nimble/controller/src/ble_ll_adv.c | 2 | ||||
-rw-r--r-- | net/nimble/controller/src/ble_ll_conn.c | 34 | ||||
-rw-r--r-- | net/nimble/controller/src/ble_ll_conn_hci.c | 4 | ||||
-rw-r--r-- | net/nimble/controller/src/ble_ll_ctrl.c | 20 | ||||
-rw-r--r-- | net/nimble/controller/src/ble_ll_hci.c | 14 | ||||
-rw-r--r-- | net/nimble/controller/src/ble_ll_hci_ev.c | 2 | ||||
-rw-r--r-- | net/nimble/controller/src/ble_ll_rng.c | 2 | ||||
-rw-r--r-- | net/nimble/controller/src/ble_ll_scan.c | 2 | ||||
-rw-r--r-- | net/nimble/controller/src/ble_ll_supp_cmd.c | 4 | ||||
-rw-r--r-- | net/nimble/drivers/nrf51/src/ble_phy.c | 24 | ||||
-rw-r--r-- | net/nimble/drivers/nrf52/src/ble_phy.c | 16 | ||||
-rw-r--r-- | net/nimble/include/nimble/nimble_opt.h | 72 |
15 files changed, 148 insertions, 83 deletions
diff --git a/net/nimble/controller/include/controller/ble_ll.h b/net/nimble/controller/include/controller/ble_ll.h index e579a268..c30871e5 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; diff --git a/net/nimble/controller/include/controller/ble_ll_conn.h b/net/nimble/controller/include/controller/ble_ll_conn.h index da50b9bd..f0358528 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 /* diff --git a/net/nimble/controller/src/ble_ll.c b/net/nimble/controller/src/ble_ll.c index 06c91256..7ff290d7 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; diff --git a/net/nimble/controller/src/ble_ll_adv.c b/net/nimble/controller/src/ble_ll_adv.c index 53c39812..8a1e8e69 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 diff --git a/net/nimble/controller/src/ble_ll_conn.c b/net/nimble/controller/src/ble_ll_conn.c index 0ddf0b8c..5bfe9d0a 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; diff --git a/net/nimble/controller/src/ble_ll_conn_hci.c b/net/nimble/controller/src/ble_ll_conn_hci.c index 791fe4ab..f1b0cd9e 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 * diff --git a/net/nimble/controller/src/ble_ll_ctrl.c b/net/nimble/controller/src/ble_ll_ctrl.c index e72e0f91..aee7c833 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: diff --git a/net/nimble/controller/src/ble_ll_hci.c b/net/nimble/controller/src/ble_ll_hci.c index 1d3b22e8..862eebc9 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; diff --git a/net/nimble/controller/src/ble_ll_hci_ev.c b/net/nimble/controller/src/ble_ll_hci_ev.c index ed0f1ba5..773e4e6b 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) { diff --git a/net/nimble/controller/src/ble_ll_rng.c b/net/nimble/controller/src/ble_ll_rng.c index b6f12f40..d93c420c 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) { diff --git a/net/nimble/controller/src/ble_ll_scan.c b/net/nimble/controller/src/ble_ll_scan.c index 94a33e39..7ebfc462 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 diff --git a/net/nimble/controller/src/ble_ll_supp_cmd.c b/net/nimble/controller/src/ble_ll_supp_cmd.c index d921ccf0..738ee9c4 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) diff --git a/net/nimble/drivers/nrf51/src/ble_phy.c b/net/nimble/drivers/nrf51/src/ble_phy.c index ae3835bc..7dc961ec 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]; diff --git a/net/nimble/drivers/nrf52/src/ble_phy.c b/net/nimble/drivers/nrf52/src/ble_phy.c index 9a5e5618..ccc043bc 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; diff --git a/net/nimble/include/nimble/nimble_opt.h b/net/nimble/include/nimble/nimble_opt.h index d008d541..ae70de15 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" |