This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf51822 bonding/whitelist creation

I am trying to scan and connect to a Polar H7 HR belt (which I can do), with m_scan_mode = BLE_NO_SCAN. Once this happens, I understand they are supposed to bond, and at that point, the H7 belt details will be saved to the whitelist. Then after doing that I can scan with m_scan_mode = BLE_WHITELIST_SCAN and be assured I am connecting to the correct HR belt.

I can connect to the belt just fine, but after restarting, my whitelist is always blank. I also put a breakpoint on the line: DM_LOG("[DM]:[CI 0x%02X]:[DI 0x%02X]: Bonded!\r\n", in my app, which is based on ble_app_hrs_c. This breakpoint never gets hit.

I've spent all day trying to get the belt added to whitelist, pulling my hair out :-( Does anyone have any ideas?

Code bits look like below. When I do my initial scan, PairingScan is set to 1, and when I am just trying to connect to the supposebly whitelisted belt, PairingScan is set to 0.

static void device_manager_init(void){
dm_application_param_t param;
dm_init_param_t        init_param;

uint32_t               err_code;

err_code = pstorage_init();
APP_ERROR_CHECK(err_code);

	if(PairingScan == 1)		//initial scan to pair a new belt
	{
		init_param.clear_persistent_data = true;
		m_scan_mode =  BLE_NO_SCAN;
		//printf("Clearing whitelist, open scanning\n\r");
	}
	else
	{
		m_scan_mode =  BLE_WHITELIST_SCAN;
		//printf("whitelist scan started\n\r");
	}
	APP_ERROR_CHECK(err_code);
	
err_code = dm_init(&init_param);
APP_ERROR_CHECK(err_code);

memset(&param.sec_param, 0, sizeof (ble_gap_sec_params_t));

// Event handler to be registered with the module.
param.evt_handler            = device_manager_event_handler;

// Service or protocol context for device manager to load, store and apply on behalf of application.
// Here set to client as application is a GATT client.
param.service_type           = DM_PROTOCOL_CNTXT_GATT_CLI_ID;

// Secuirty parameters to be used for security procedures.
param.sec_param.bond         = SEC_PARAM_BOND;
param.sec_param.mitm         = SEC_PARAM_MITM;
param.sec_param.io_caps      = SEC_PARAM_IO_CAPABILITIES;
param.sec_param.oob          = SEC_PARAM_OOB;
param.sec_param.min_key_size = SEC_PARAM_MIN_KEY_SIZE;
param.sec_param.max_key_size = SEC_PARAM_MAX_KEY_SIZE;
param.sec_param.kdist_periph.enc = 1;
param.sec_param.kdist_periph.id  = 1;

err_code = dm_register(&m_dm_app_id, &param);
APP_ERROR_CHECK(err_code);

}

and then, my scan_start() function looks like this below. I always end up hitting the 'doscan = false' line as there is nothing in my whitelist.

static void scan_start(void)

{ bool doscan = true; ble_gap_whitelist_t whitelist; ble_gap_addr_t * p_whitelist_addr[BLE_GAP_WHITELIST_ADDR_MAX_COUNT]; ble_gap_irk_t * p_whitelist_irk[BLE_GAP_WHITELIST_IRK_MAX_COUNT]; uint32_t err_code; uint32_t count;

// Verify if there is any flash access pending, if yes delay starting scanning until 
// it's complete.
err_code = pstorage_access_status_get(&count);
APP_ERROR_CHECK(err_code);

if (count != 0)
{
    m_memory_access_in_progress = true;
    return;
}

// Initialize whitelist parameters.
whitelist.addr_count = BLE_GAP_WHITELIST_ADDR_MAX_COUNT;
whitelist.irk_count  = 0;
whitelist.pp_addrs   = p_whitelist_addr;
whitelist.pp_irks    = p_whitelist_irk;

// Request creating of whitelist.

err_code = dm_whitelist_create(&m_dm_app_id,&whitelist); APP_ERROR_CHECK(err_code);

	if (m_scan_mode != BLE_WHITELIST_SCAN)
{
    // No devices in whitelist, hence non selective performed.
    m_scan_param.active       = 0;            // Active scanning set.
    m_scan_param.selective    = 0;            // Selective scanning not set.
    m_scan_param.interval     = SCAN_INTERVAL;// Scan interval.
    m_scan_param.window       = SCAN_WINDOW;  // Scan window.
    m_scan_param.p_whitelist  = NULL;         // No whitelist provided.
    m_scan_param.timeout      = 0x0000;       // No timeout.
}
else
{
		if ((whitelist.addr_count == 0) && (whitelist.irk_count == 0))
		{
			//we don't have a whitelist yet, don't scan at all.
			doscan = false;
		}
		else
		{
			// Selective scanning based on whitelist
			m_scan_param.active       = 0;            // Active scanning set.
			m_scan_param.selective    = 1;            // Selective scanning not set.
			m_scan_param.interval     = SCAN_INTERVAL;// Scan interval.
			m_scan_param.window       = SCAN_WINDOW;  // Scan window.
			m_scan_param.p_whitelist  = &whitelist;   // Provide whitelist.
			m_scan_param.timeout      = 0x0000;       // no timeout.
			// Set whitelist scanning state.
			m_scan_mode = BLE_WHITELIST_SCAN;
		}
	}

	if(doscan == true)
	{
		err_code = sd_ble_gap_scan_start(&m_scan_param);
		APP_ERROR_CHECK(err_code);
	}

}

  • Correct - with the same firmware running on BL620-SA-01 (containing nRF51822-QFAA-G0 ), the HR belt gets bonded when I do an open scan, and a whitelist is created, and I can whitelist scan and connect afterwards. Using exactly the same firmware on the newer module BL-620-SA-02 (with nRF51822-QFAA-H0 inside), when I do an open scan, I can connect to the HR belt but the connection never advances on to do bonding as it does in the other module. Therefore I can never create a whitelist. I just don't understand why the bonding step does not occur in the one module.

  • Are you 100% sure you are using the same firmware on the modules? I assume you are using the Nordic SDK and has done a full erase of both module types, before programming it with both Softdevice and application (which SDK and SD version are you using)? How many BL-620-SA-02 modules have you tested?

  • Yes, exactly the same FW. My workflow is like this: Use nrfjprog to do full erase then program in SoftDevice V2.00, then load the application code on directly from uVision via a JLINK, and run it. I've only got one '-02' variant modules on a PCB, I have just taken delivery of a few more so will try swap that one out and see if it seems an isolated issue.

  • What happens if you try to connect to a nordic SDK HRM? I guess we don't know what is going on on the polar device either. Could there be any old bonds or something that stops the bonding from happening? Do you know which device is initializing the bonding process (sniffer log or are you calling sd_ble_gap_authenticate somewhere)?

  • I don't have a Nordik SDK HRM unfortunately, but I have used a few polar belts with a few '01' variants, swapped them between devices, never had any issues until this '02' module arrive. I (try) initiate the bonding: case BLE_HRS_C_EVT_DISCOVERY_COMPLETE: // Initiate bonding. err_code = dm_security_setup_req(&m_dm_device_handle); APP_ERROR_CHECK(err_code);

    it's all very strange

Related