4 years, 5 months ago.  This question has been closed. Reason: Off Topic

Issue with setting up static passkey for BLE authentication - nRF52840

I'm currently trying to set up the passkey which will be used during the BLE authentication process. I currently have this code which works as i expect:

bool enableBonding = true;
bool requireMITM   = true;
uint8_t passkey[6] = {'1', '1', '1', '1', '1', '1'};        
// uint8_t passkey[6] = {'1', '2', '3', '4', '5', '6'};        // Doesn't work
m_ble.securityManager().init(enableBonding, requireMITM, SecurityManager::IO_CAPS_DISPLAY_ONLY, passkey);

The problem which i am facing is, i am unable to change this passkey to anything more meaningful. What i mean by that is, the only passkeys which seem to work with my device are "111111", "222222", "333333" ... "999999". Whether i specify a different passkey eg. "123456" or even not specific any passkey at all and allow random generation, i enter the required passkey via the nRF Connect App and it fails to authenticate. I get the error SecurityCompletionStatus_t::SEC_STATUS_CONFIRM_VALUE.

Does anybody else see the same behaviour where only certain passkey combinations are "usable"?

I am testing with a nRF52840

After hours of trying different things, finally figured it out. For some reason, which has not been documented anywhere, the passkey which is entered via the app should be in the reverse order to the passkey specified in the passkey array! For example, if i take the code which wasn't working for me in the original question - uint8_t passkey[6] = {'1', '2', '3', '4', '5', '6'}; When entering the passkey via an app, the passkey should be entered in the order 6 5 4 3 2 1. This would explain why i was able to only enter passkey combinations of repeating numbers, since the order doesn't matter. This seems very unintuitive. I hope this post will be of help to anyone else who's struggling with the same issue :)

posted by Saaketh Chittajallu 18 Nov 2019