diff --git a/examples/ble_peripheral/ble_app_hrs/main.c b/examples/ble_peripheral/ble_app_hrs/main.c index 8e7c6f1..4bbfadc 100644 --- a/examples/ble_peripheral/ble_app_hrs/main.c +++ b/examples/ble_peripheral/ble_app_hrs/main.c @@ -130,6 +130,8 @@ #define DEAD_BEEF 0xDEADBEEF /**< Value used as error code on stack dump, can be used to identify stack location on stack unwind. */ +#define WHITELIST_ADDRESS {0xD8, 0x1E, 0x41, 0x50, 0x54, 0xE4} + BLE_HRS_DEF(m_hrs); /**< Heart rate service instance. */ BLE_BAS_DEF(m_bas); /**< Structure used to identify the battery service. */ @@ -189,6 +191,27 @@ static void delete_bonds(void) } +/**@brief Function for setting filtered whitelist. + * + * @param[in] skip Filter passed to @ref pm_peer_id_list. + */ +static void whitelist_set(void) +{ + ret_code_t err_code; + + ble_gap_addr_t whitelist_addr = + { + .addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC, + .addr = WHITELIST_ADDRESS + }; + + ble_gap_addr_t const * const p_whitelist_addr = &whitelist_addr; + + err_code = sd_ble_gap_whitelist_set(&p_whitelist_addr, 1); + APP_ERROR_CHECK(err_code); +} + + /**@brief Function for starting advertising. */ void advertising_start(bool erase_bonds) @@ -202,6 +225,8 @@ void advertising_start(bool erase_bonds) { ret_code_t err_code; + whitelist_set(); + err_code = ble_advertising_start(&m_advertising, BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); } @@ -663,9 +688,9 @@ static void on_adv_evt(ble_adv_evt_t ble_adv_evt) switch (ble_adv_evt) { - case BLE_ADV_EVT_FAST: - NRF_LOG_INFO("Fast advertising."); - err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING); + case BLE_ADV_EVT_FAST_WHITELIST: + NRF_LOG_INFO("Fast advertising with whitelist."); + err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING_WHITELIST); APP_ERROR_CHECK(err_code); break; @@ -673,6 +698,25 @@ static void on_adv_evt(ble_adv_evt_t ble_adv_evt) sleep_mode_enter(); break; + case BLE_ADV_EVT_WHITELIST_REQUEST: + { + NRF_LOG_INFO("Whitelist request") + ble_gap_addr_t whitelist_addr = + { + .addr_type = BLE_GAP_ADDR_TYPE_RANDOM_STATIC, + .addr = WHITELIST_ADDRESS + }; + + // Apply the whitelist. + err_code = ble_advertising_whitelist_reply(&m_advertising, + &whitelist_addr, + 1, + NULL, + 0); + APP_ERROR_CHECK(err_code); + } + break; + default: break; } @@ -881,6 +925,7 @@ static void advertising_init(void) init.advdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]); init.advdata.uuids_complete.p_uuids = m_adv_uuids; + init.config.ble_adv_whitelist_enabled = true; init.config.ble_adv_fast_enabled = true; init.config.ble_adv_fast_interval = APP_ADV_INTERVAL; init.config.ble_adv_fast_timeout = APP_ADV_DURATION;