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

Problems pairing with iOS device using LE Secure Connections

Hello. I am trying using the nRF52832 with SoftDevice S132 v4.0.2 and SDK v13.0.0 along with the uECC.c/h files that I downloaded from github.com/.../micro-ecc. My device is acting in a peripheral role, and am trying to get LE Secure Connections working. I'm testing against an iPhone 7 running iOS 11.3.1. I am using a full-featured sniffer with BT 4.2 support.

What I see on the sniffer is that the iPhone is sending a LL_TERMINATE_IND to terminate the connection during SMP Authentication Stage 1, immediately after the peripheral has sent the SMP Pairing Confirm value containing the value of Cb. In some cases the iPhone first sends an SMP Pairing Failed packet with reason code 0x08 (Unspecified Reason) just before sending the terminate request, though in most cases the LL_TERMINATE_IND happens without any SMP Pairing Failed packet.

Before the failure happens, I can see the SMP Pairing Request and Response packets as well as the SMP Pairing Public Key packets from both the central and the peripheral, and those packets all appear to be properly formed.

I'm not sure why the iPhone is terminating the connection, though I can only speculate that there is something wrong with my SMP Pairing Confirm packet - perhaps the Cb value is incorrectly calculated?

Below is the code that I'm using to initialize the peer manager. Am I doing anything incorrectly here? Thanks for your help.

__ALIGN(4) static ble_gap_lesc_p256_pk_t lesc_publicKey; // LESC ECC Public Key
__ALIGN(4) static ble_gap_lesc_p256_pk_t lesc_secretKey; // LESC ECC Secret Key
__ALIGN(4) static ble_gap_lesc_dhkey_t lesc_dhKey; // LESC ECC DH Key
__ALIGN(4) static ble_gap_lesc_p256_pk_t lesc_peerEccKey; // LESC Peer

static void X_InitPeerManager()

static void X_InitPeerManager()
{

ble_gap_sec_params_t sec_param;
ret_code_t err_code;

err_code = nrf_drv_rng_init(NULL);
APP_ERROR_CHECK(err_code);

err_code = pm_init();
APP_ERROR_CHECK(err_code);

err_code = pm_register(X_PeerManagerEvent);
APP_ERROR_CHECK(err_code);

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

sec_param.bond = 1;
sec_param.mitm = 0;
sec_param.lesc = 1;
sec_param.keypress = 0;
sec_param.io_caps = BLE_GAP_IO_CAPS_NONE;
sec_param.oob = SEC_PARAM_OOB;
sec_param.min_key_size = 16;
sec_param.max_key_size = 16;
sec_param.kdist_own.enc = 1;
sec_param.kdist_own.id = 1;
sec_param.kdist_peer.enc = 1;
sec_param.kdist_peer.id = 1;

err_code = pm_sec_params_set(&sec_param);
APP_ERROR_CHECK(err_code);

ecc_init(TRUE);

err_code = ecc_p256_keypair_gen(lesc_secretKey.pk, lesc_publicKey.pk);
APP_ERROR_CHECK(err_code);

err_code = pm_lesc_public_key_set(&lesc_publicKey);
APP_ERROR_CHECK(err_code);

}

  • I spent a bit more time investigating this and have a couple more comments:

    1. Rather than using my own iOS app, I tried using LightBlue, and saw that the iPhone is sending the SMP Pairing Failed packet with reason code 0x08 (Unspecified Reason) every time I attempt the pairing, immediately after the peripheral sends the SMP Pairing Confirm packet, and the phone is longer terminating the connection. It realized that the connection termination was actually being done by my app and not the iOS CoreBluetooth stack. I was not seeing the SMP Pairing Failed packet some of the time because the app was sending the terminate request before the SMP Pairing Failed packet could be sent.

    This reinforces the possibility that there is something wrong with the SMP Pairing Confirm Packet that is causing the a pairing failure.

    2. I tried to use the "Debug Mode" keys that are given in the BT 4.2 core spec (Vol 3, Part H, Section 2.3.5.6.1) in order to make sure that my public key was valid. Doing this did not change the result - the iPhone still sends the SMP Pairing Failed Packet with core 0x08 (Unspecified Reason).

    Any idea what might be happening? Thanks.

  • Hi,

    Have you also tried your application with Android, to see if it works?

    I suggest you to have a look at the LE Secure Connections Multirole Example

Related