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);
	}

}

Parents
  • this is what I get out of the debug output, no mention of bonding:

    [APPL]: af0[APPL]: 180d[APPL]: >> DM_EVT_CONNECTION[APPL]:[88 B7 DB D0 22 00]: onnection Established[APPL]: << DM_EVT_CONNECTION[APPL]: Battery Service discovered.[APPL]: Reading battery level.[APPL]: Enabling Battery Level Notification.[APPL]: >> M_EVT_SECURITY_SETUP_COMPLETE[APPL]: << DM_EVT_SECURITY_SETUP_COMPLETE[APPL]: HR easurement received 0û[APPL]: HR Measurement received 0[APPL]: Battery Level Read as 100 %[APPL]: HR Measurement received 0[APPL]: HR Measurement received 0

Reply
  • this is what I get out of the debug output, no mention of bonding:

    [APPL]: af0[APPL]: 180d[APPL]: >> DM_EVT_CONNECTION[APPL]:[88 B7 DB D0 22 00]: onnection Established[APPL]: << DM_EVT_CONNECTION[APPL]: Battery Service discovered.[APPL]: Reading battery level.[APPL]: Enabling Battery Level Notification.[APPL]: >> M_EVT_SECURITY_SETUP_COMPLETE[APPL]: << DM_EVT_SECURITY_SETUP_COMPLETE[APPL]: HR easurement received 0û[APPL]: HR Measurement received 0[APPL]: Battery Level Read as 100 %[APPL]: HR Measurement received 0[APPL]: HR Measurement received 0

Children
No Data
Related