http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6bbacbd/net/nimble/controller/src/ble_ll_whitelist.c ---------------------------------------------------------------------- diff --git a/net/nimble/controller/src/ble_ll_whitelist.c b/net/nimble/controller/src/ble_ll_whitelist.c index 5ee3e84..f3af569 100644 --- a/net/nimble/controller/src/ble_ll_whitelist.c +++ b/net/nimble/controller/src/ble_ll_whitelist.c @@ -21,13 +21,21 @@ #include <string.h> #include "os/os.h" #include "nimble/ble.h" +#include "nimble/nimble_opt.h" +#include "ble/xcvr.h" #include "controller/ble_ll_whitelist.h" #include "controller/ble_ll_hci.h" #include "controller/ble_ll_adv.h" #include "controller/ble_ll_scan.h" #include "controller/ble_hw.h" +#include "hal/hal_cputime.h" + +#if (NIMBLE_OPT_LL_WHITELIST_SIZE < BLE_HW_WHITE_LIST_SIZE) +#define BLE_LL_WHITELIST_SIZE NIMBLE_OPT_LL_WHITELIST_SIZE +#else +#define BLE_LL_WHITELIST_SIZE BLE_HW_WHITE_LIST_SIZE +#endif -#ifndef BLE_USES_HW_WHITELIST struct ble_ll_whitelist_entry { uint8_t wl_valid; @@ -35,8 +43,7 @@ struct ble_ll_whitelist_entry uint8_t wl_dev_addr[BLE_DEV_ADDR_LEN]; }; -struct ble_ll_whitelist_entry g_ble_ll_whitelist[NIMBLE_OPT_LL_WHITELIST_SIZE]; -#endif +struct ble_ll_whitelist_entry g_ble_ll_whitelist[BLE_LL_WHITELIST_SIZE]; static int ble_ll_whitelist_chg_allowed(void) @@ -65,24 +72,23 @@ ble_ll_whitelist_chg_allowed(void) int ble_ll_whitelist_clear(void) { + int i; + struct ble_ll_whitelist_entry *wl; /* Check proper state */ if (!ble_ll_whitelist_chg_allowed()) { return BLE_ERR_CMD_DISALLOWED; } -#ifdef BLE_USES_HW_WHITELIST - ble_hw_whitelist_clear(); -#else - int i; - struct ble_ll_whitelist_entry *wl; - /* Set the number of entries to 0 */ wl = &g_ble_ll_whitelist[0]; - for (i = 0; i < NIMBLE_OPT_LL_WHITELIST_SIZE; ++i) { + for (i = 0; i < BLE_LL_WHITELIST_SIZE; ++i) { wl->wl_valid = 0; ++wl; } + +#if (BLE_USES_HW_WHITELIST == 1) + ble_hw_whitelist_clear(); #endif return BLE_ERR_SUCCESS; @@ -99,20 +105,17 @@ ble_ll_whitelist_clear(void) int ble_ll_whitelist_read_size(uint8_t *rspbuf, uint8_t *rsplen) { -#ifdef BLE_USES_HW_WHITELIST - rspbuf[0] = ble_hw_whitelist_size(); -#else - rspbuf[0] = NIMBLE_OPT_LL_WHITELIST_SIZE; -#endif + rspbuf[0] = BLE_LL_WHITELIST_SIZE; *rsplen = 1; return BLE_ERR_SUCCESS; } -#ifndef BLE_USES_HW_WHITELIST /** - * Used to determine if the device is on the whitelist. + * Searches the whitelist to determine if the address is present in the + * whitelist. This is an internal API that only searches the link layer + * whitelist and does not care about the hardware whitelist * - * @param addr + * @param addr Device or identity address to check. * @param addr_type Public address (0) or random address (1) * * @return int 0: device is not on whitelist; otherwise the return value @@ -120,13 +123,13 @@ ble_ll_whitelist_read_size(uint8_t *rspbuf, uint8_t *rsplen) * plus 1). */ static int -ble_ll_is_on_whitelist(uint8_t *addr, uint8_t addr_type) +ble_ll_whitelist_search(uint8_t *addr, uint8_t addr_type) { int i; struct ble_ll_whitelist_entry *wl; wl = &g_ble_ll_whitelist[0]; - for (i = 0; i < NIMBLE_OPT_LL_WHITELIST_SIZE; ++i) { + for (i = 0; i < BLE_LL_WHITELIST_SIZE; ++i) { if ((wl->wl_valid) && (wl->wl_addr_type == addr_type) && (!memcmp(&wl->wl_dev_addr[0], addr, BLE_DEV_ADDR_LEN))) { return i + 1; @@ -136,24 +139,37 @@ ble_ll_is_on_whitelist(uint8_t *addr, uint8_t addr_type) return 0; } -#endif /** - * Is there a match between the device and a device on the whitelist + * Is there a match between the device and a device on the whitelist. + * + * NOTE: This API uses the HW, if present, to determine if there was a match + * between a received address and an address in the whitelist. If the HW does + * not support whitelisting this API is the same as the whitelist search API * * @param addr * @param addr_type Public address (0) or random address (1) + * @param is_ident True if addr is an identity address; false otherwise * * @return int */ int -ble_ll_whitelist_match(uint8_t *addr, uint8_t addr_type) +ble_ll_whitelist_match(uint8_t *addr, uint8_t addr_type, int is_ident) { int rc; -#ifdef BLE_USES_HW_WHITELIST - rc = ble_hw_whitelist_match(); +#if (BLE_USES_HW_WHITELIST == 1) + /* + * XXX: This should be changed. This is HW specific: some HW may be able + * to both resolve a private address and perform a whitelist check. The + * current BLE hw cannot support this. + */ + if (is_ident) { + rc = ble_ll_whitelist_search(addr, addr_type); + } else { + rc = ble_hw_whitelist_match(); + } #else - rc = ble_ll_is_on_whitelist(addr, addr_type); + rc = ble_ll_whitelist_search(addr, addr_type); #endif return rc; } @@ -166,7 +182,9 @@ ble_ll_whitelist_match(uint8_t *addr, uint8_t addr_type) int ble_ll_whitelist_add(uint8_t *addr, uint8_t addr_type) { + int i; int rc; + struct ble_ll_whitelist_entry *wl; /* Must be in proper state */ if (!ble_ll_whitelist_chg_allowed()) { @@ -174,16 +192,10 @@ ble_ll_whitelist_add(uint8_t *addr, uint8_t addr_type) } /* Check if we have any open entries */ -#ifdef BLE_USES_HW_WHITELIST - rc = ble_hw_whitelist_add(addr, addr_type); -#else - int i; - struct ble_ll_whitelist_entry *wl; - rc = BLE_ERR_SUCCESS; - if (!ble_ll_is_on_whitelist(addr, addr_type)) { + if (!ble_ll_whitelist_search(addr, addr_type)) { wl = &g_ble_ll_whitelist[0]; - for (i = 0; i < NIMBLE_OPT_LL_WHITELIST_SIZE; ++i) { + for (i = 0; i < BLE_LL_WHITELIST_SIZE; ++i) { if (wl->wl_valid == 0) { memcpy(&wl->wl_dev_addr[0], addr, BLE_DEV_ADDR_LEN); wl->wl_addr_type = addr_type; @@ -193,11 +205,14 @@ ble_ll_whitelist_add(uint8_t *addr, uint8_t addr_type) ++wl; } - if (i == NIMBLE_OPT_LL_WHITELIST_SIZE) { + if (i == BLE_LL_WHITELIST_SIZE) { rc = BLE_ERR_MEM_CAPACITY; + } else { +#if (BLE_USES_HW_WHITELIST == 1) + rc = ble_hw_whitelist_add(addr, addr_type); +#endif } } -#endif return rc; } @@ -212,20 +227,20 @@ ble_ll_whitelist_add(uint8_t *addr, uint8_t addr_type) int ble_ll_whitelist_rmv(uint8_t *addr, uint8_t addr_type) { + int position; + /* Must be in proper state */ if (!ble_ll_whitelist_chg_allowed()) { return BLE_ERR_CMD_DISALLOWED; } -#ifdef BLE_USES_HW_WHITELIST - ble_hw_whitelist_rmv(addr, addr_type); -#else - int position; - - position = ble_ll_is_on_whitelist(addr, addr_type); + position = ble_ll_whitelist_search(addr, addr_type); if (position) { g_ble_ll_whitelist[position - 1].wl_valid = 0; } + +#if (BLE_USES_HW_WHITELIST == 1) + ble_hw_whitelist_rmv(addr, addr_type); #endif return BLE_ERR_SUCCESS; @@ -239,7 +254,7 @@ ble_ll_whitelist_rmv(uint8_t *addr, uint8_t addr_type) void ble_ll_whitelist_enable(void) { -#ifdef BLE_USES_HW_WHITELIST +#if (BLE_USES_HW_WHITELIST == 1) ble_hw_whitelist_enable(); #endif } @@ -252,9 +267,7 @@ ble_ll_whitelist_enable(void) void ble_ll_whitelist_disable(void) { -#ifdef BLE_USES_HW_WHITELIST +#if (BLE_USES_HW_WHITELIST == 1) ble_hw_whitelist_disable(); #endif } - -
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6bbacbd/net/nimble/drivers/nrf51/include/ble/xcvr.h ---------------------------------------------------------------------- diff --git a/net/nimble/drivers/nrf51/include/ble/xcvr.h b/net/nimble/drivers/nrf51/include/ble/xcvr.h index 34abd7a..7041d8d 100644 --- a/net/nimble/drivers/nrf51/include/ble/xcvr.h +++ b/net/nimble/drivers/nrf51/include/ble/xcvr.h @@ -29,4 +29,10 @@ #define XCVR_RX_SCHED_DELAY_USECS \ (XCVR_RX_START_DELAY_USECS + XCVR_PROC_DELAY_USECS) +/* + * Define HW whitelist size. This is the total possible whitelist size; + * not necessarily the size that will be used (may be smaller) + */ +#define BLE_HW_WHITE_LIST_SIZE (8) + #endif /* H_BLE_XCVR_ */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6bbacbd/net/nimble/drivers/nrf51/src/ble_hw.c ---------------------------------------------------------------------- diff --git a/net/nimble/drivers/nrf51/src/ble_hw.c b/net/nimble/drivers/nrf51/src/ble_hw.c index 498840d..43c7b9d 100644 --- a/net/nimble/drivers/nrf51/src/ble_hw.c +++ b/net/nimble/drivers/nrf51/src/ble_hw.c @@ -21,15 +21,13 @@ #include <assert.h> #include <string.h> #include "os/os.h" +#include "ble/xcvr.h" #include "nimble/ble.h" #include "nimble/nimble_opt.h" #include "mcu/nrf51_bitfields.h" #include "controller/ble_hw.h" #include "bsp/cmsis_nvic.h" -/* Total number of white list elements */ -#define BLE_HW_WHITE_LIST_SIZE (8) - /* Total number of resolving list elements */ #define BLE_HW_RESOLV_LIST_SIZE (16) @@ -399,9 +397,10 @@ ble_hw_resolv_list_rmv(int index) } /** - * Returns the size of the whitelist in HW + * Returns the size of the resolving list. NOTE: this returns the maximum + * allowable entries in the HW. Configuration options may limit this. * - * @return int Number of devices allowed in whitelist + * @return int Number of devices allowed in resolving list */ uint8_t ble_hw_resolv_list_size(void) http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6bbacbd/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 e44b04d..0c05011 100644 --- a/net/nimble/drivers/nrf51/src/ble_phy.c +++ b/net/nimble/drivers/nrf51/src/ble_phy.c @@ -266,6 +266,7 @@ ble_phy_rx_xcvr_setup(void) (2 << RADIO_PCNF0_S1LEN_Pos) | (NRF_S0_LEN << RADIO_PCNF0_S0LEN_Pos); NRF_AAR->ENABLE = AAR_ENABLE_ENABLE_Enabled; + NRF_AAR->IRKPTR = (uint32_t)&g_nrf_irk_list[0]; NRF_AAR->ADDRPTR = (uint32_t)g_ble_phy_data.rxpdu->om_data; NRF_AAR->SCRATCHPTR = (uint32_t)&g_ble_phy_data.phy_aar_scratch; NRF_AAR->EVENTS_END = 0; @@ -821,7 +822,6 @@ ble_phy_rx_set_start_time(uint32_t cputime) return rc; } - int ble_phy_tx(struct os_mbuf *txpdu, uint8_t end_trans) { @@ -869,6 +869,7 @@ ble_phy_tx(struct os_mbuf *txpdu, uint8_t end_trans) NRF_RADIO->PCNF0 = (NRF_LFLEN_BITS << RADIO_PCNF0_LFLEN_Pos) | (NRF_S0_LEN << RADIO_PCNF0_S0LEN_Pos); NRF_PPI->CHENCLR = PPI_CHEN_CH23_Msk; + NRF_AAR->IRKPTR = (uint32_t)&g_nrf_irk_list[0]; #endif /* RAM representation has S0 and LENGTH fields (2 bytes) */ dptr = (uint8_t *)&g_ble_phy_txrx_buf[0]; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6bbacbd/net/nimble/drivers/nrf52/include/ble/xcvr.h ---------------------------------------------------------------------- diff --git a/net/nimble/drivers/nrf52/include/ble/xcvr.h b/net/nimble/drivers/nrf52/include/ble/xcvr.h index f3e60fa..a05a0c7 100644 --- a/net/nimble/drivers/nrf52/include/ble/xcvr.h +++ b/net/nimble/drivers/nrf52/include/ble/xcvr.h @@ -20,7 +20,7 @@ #ifndef H_BLE_XCVR_ #define H_BLE_XCVR_ -/* Transceiver specific defintions */ +/* Transceiver specific definitions */ #define XCVR_RX_START_DELAY_USECS (140) #define XCVR_TX_START_DELAY_USECS (140) #define XCVR_PROC_DELAY_USECS (50) @@ -29,4 +29,10 @@ #define XCVR_RX_SCHED_DELAY_USECS \ (XCVR_RX_START_DELAY_USECS + XCVR_PROC_DELAY_USECS) +/* + * Define HW whitelist size. This is the total possible whitelist size; + * not necessarily the size that will be used (may be smaller) + */ +#define BLE_HW_WHITE_LIST_SIZE (8) + #endif /* H_BLE_XCVR_ */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6bbacbd/net/nimble/drivers/nrf52/src/ble_hw.c ---------------------------------------------------------------------- diff --git a/net/nimble/drivers/nrf52/src/ble_hw.c b/net/nimble/drivers/nrf52/src/ble_hw.c index ea32ce4..b461136 100644 --- a/net/nimble/drivers/nrf52/src/ble_hw.c +++ b/net/nimble/drivers/nrf52/src/ble_hw.c @@ -21,15 +21,13 @@ #include <assert.h> #include <string.h> #include "os/os.h" +#include "ble/xcvr.h" #include "nimble/ble.h" #include "nimble/nimble_opt.h" #include "mcu/nrf52_bitfields.h" #include "controller/ble_hw.h" #include "bsp/cmsis_nvic.h" -/* Total number of white list elements */ -#define BLE_HW_WHITE_LIST_SIZE (8) - /* Total number of resolving list elements */ #define BLE_HW_RESOLV_LIST_SIZE (16) @@ -399,9 +397,10 @@ ble_hw_resolv_list_rmv(int index) } /** - * Returns the size of the whitelist in HW + * Returns the size of the resolving list. NOTE: this returns the maximum + * allowable entries in the HW. Configuration options may limit this. * - * @return int Number of devices allowed in whitelist + * @return int Number of devices allowed in resolving list */ uint8_t ble_hw_resolv_list_size(void) http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6bbacbd/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 08d0d8d..541ece9 100644 --- a/net/nimble/drivers/nrf52/src/ble_phy.c +++ b/net/nimble/drivers/nrf52/src/ble_phy.c @@ -265,6 +265,7 @@ ble_phy_rx_xcvr_setup(void) #if (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]; NRF_AAR->ADDRPTR = (uint32_t)g_ble_phy_data.rxpdu->om_data; NRF_AAR->SCRATCHPTR = (uint32_t)&g_ble_phy_data.phy_aar_scratch; NRF_AAR->EVENTS_END = 0; @@ -840,6 +841,7 @@ ble_phy_tx(struct os_mbuf *txpdu, uint8_t end_trans) } else { #if (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]; } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6bbacbd/net/nimble/host/src/host_dbg.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/host_dbg.c b/net/nimble/host/src/host_dbg.c index f8c9a43..6303f62 100644 --- a/net/nimble/host/src/host_dbg.c +++ b/net/nimble/host/src/host_dbg.c @@ -39,17 +39,30 @@ host_hci_dbg_le_event_disp(uint8_t subev, uint8_t len, uint8_t *evdata) char adv_data_buf[32]; switch (subev) { + case BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE: case BLE_HCI_LE_SUBEV_CONN_COMPLETE: status = evdata[0]; if (status == BLE_ERR_SUCCESS) { BLE_HS_LOG(DEBUG, "LE connection complete. handle=%u role=%u " - "paddrtype=%u addr=%x.%x.%x.%x.%x.%x itvl=%u " - "latency=%u spvn_tmo=%u mca=%u\n", + "paddrtype=%u addr=%x.%x.%x.%x.%x.%x ", le16toh(evdata + 1), evdata[3], evdata[4], evdata[10], evdata[9], evdata[8], evdata[7], - evdata[6], evdata[5], le16toh(evdata + 11), - le16toh(evdata + 13), le16toh(evdata + 15), - evdata[17]); + evdata[6], evdata[5]); + + evdata += 11; + if (subev == BLE_HCI_LE_SUBEV_ENH_CONN_COMPLETE) { + BLE_HS_LOG(DEBUG, "local_rpa=%x.%x.%x.%x.%x.%x " + "peer_rpa=%x.%x.%x.%x.%x.%x ", + evdata[5], evdata[4], evdata[3], evdata[2], + evdata[1], evdata[0], + evdata[11], evdata[10], evdata[9], evdata[8], + evdata[7], evdata[6]); + + evdata += 12; + } + BLE_HS_LOG(DEBUG, "itvl=%u latency=%u spvn_tmo=%u mca=%u\n", + le16toh(evdata), le16toh(evdata + 2), + le16toh(evdata + 4), evdata[6]); } else { BLE_HS_LOG(DEBUG, "LE connection complete. FAIL (status=%u)\n", status); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6bbacbd/net/nimble/include/nimble/ble.h ---------------------------------------------------------------------- diff --git a/net/nimble/include/nimble/ble.h b/net/nimble/include/nimble/ble.h index f2e7976..e75a685 100644 --- a/net/nimble/include/nimble/ble.h +++ b/net/nimble/include/nimble/ble.h @@ -62,7 +62,7 @@ struct ble_mbuf_hdr_rxinfo uint8_t flags; uint8_t channel; uint8_t handle; - int8_t rssi; + int8_t rssi; }; /* Flag definitions for rxinfo */ http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6bbacbd/net/nimble/include/nimble/hci_common.h ---------------------------------------------------------------------- diff --git a/net/nimble/include/nimble/hci_common.h b/net/nimble/include/nimble/hci_common.h index be72f5b..ea19cdd 100644 --- a/net/nimble/include/nimble/hci_common.h +++ b/net/nimble/include/nimble/hci_common.h @@ -498,6 +498,7 @@ /* LE advertising report event. (sub event 0x02) */ #define BLE_HCI_LE_ADV_RPT_MIN_LEN (12) +#define BLE_HCI_LE_ADV_DIRECT_RPT_LEN (18) #define BLE_HCI_LE_ADV_RPT_NUM_RPTS_MIN (1) #define BLE_HCI_LE_ADV_RPT_NUM_RPTS_MAX (0x19) @@ -537,6 +538,9 @@ #define BLE_LMP_VER_BCS_4_1 (7) #define BLE_LMP_VER_BCS_4_2 (8) +/* Sub-event 0x0A: enhanced connection complete */ +#define BLE_HCI_LE_ENH_CONN_COMPLETE_LEN (31) + /*--- Shared data structures ---*/ /* Read local version information (OGF=0x0004, OCF=0x0001) */ struct hci_loc_ver_info
