BLE master or slave binding information loss problem

In the Nordic product development, we have encountered a host and establish a binding between slaves, and when after a party (master / slave) binding information lost connection failures, are the following scenarios:

Scenario 1: Host-side binding information deleted, but nRF52 end the slave still retained the original binding information, nRF52 slave need to allow re-pair, the new binding information to overwrite the original binding information, the need for code the following modifications:

        case PM_EVT_CONN_SEC_CONFIG_REQ:

        {

            NRF_LOG_INFO("PM_EVT_CONN_SEC_CONFIG_REQ: peer_id=%d, accept to fix bonding\r\n",

                           p_evt->peer_id);

            // Accept pairing request from an already bonded peer.

            pm_conn_sec_config_t conn_sec_config = {.allow_repairing = true};

            pm_conn_sec_config_reply(p_evt->conn_handle, &conn_sec_config);

        } break;

 Scene 2: The host side retained the original binding information, but nRF52 removed from the machine end of the binding information, nRF52 end needs to remain connected in the password more experience failure, the code is modified as follows:

      case PM_EVT_CONN_SEC_FAILED:

        {

            NRF_LOG_INFO("PM_EVT_CONN_SEC_FAILED: peer_id=%d, procedure=%d, error=0x%04x\r\n",

                          p_evt->peer_id,

                          p_evt->params.conn_sec_failed.procedure,

                          p_evt->params.conn_sec_failed.error);

            if (p_evt->params.conn_sec_failed.procedure == PM_LINK_SECURED_PROCEDURE_ENCRYPTION &&

                p_evt->params.conn_sec_failed.error == PM_CONN_SEC_ERROR_PIN_OR_KEY_MISSING)

            {

                // Local device lost bond info, don't disconnect and wait for re-bond

                NRF_LOG_INFO("Waiting for host to fix bonding\r\n");

            }

            else

            {

              sprintf(m_message, "Security procedure failed, disconnect.\r\n");

              dev_ctrl_send_msg(m_message, strlen(m_message));

              (void)sd_ble_gap_disconnect(p_evt->conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);

            }

        } break;

 

If the host is a mobile phone or tablet, there are different approaches in accordance with the difference between the operating system: 

iOS: There is no solution, only binding information by manually deleting the host side.

Android: new binding procedures can be performed, delete the old binding information.

If the host-side device is nRF52 be forced to re-establish a binding pair and connect the new binding information generated, modify the code as follows:

       case PM_EVT_CONN_SEC_FAILED:

        {

            NRF_LOG_INFO("PM_EVT_CONN_SEC_FAILED: peer_id=%d, procedure=%d, error=0x%04x\r\n",

                          p_evt->peer_id,

                          p_evt->params.conn_sec_failed.procedure,

                          p_evt->params.conn_sec_failed.error);

            if (p_evt->params.conn_sec_failed.procedure == PM_LINK_SECURED_PROCEDURE_ENCRYPTION &&

                p_evt->params.conn_sec_failed.error == PM_CONN_SEC_ERROR_PIN_OR_KEY_MISSING)

            {

                // Peer device lost bond info, do re-bonding

                NRF_LOG_INFO("Peer lost bond info. Start re-bonding\r\n");

                err_code = pm_conn_secure(p_evt->conn_handle, true);

                if (err_code != NRF_SUCCESS)

                {

                    NRF_LOG_WARNING("Cannot fix out-of-sync bonding: 0x%08x\r\n", err_code);

                }

            }

            else

            {

                sprintf(m_message, "Connection failed, disconnect.\r\n");

                dev_ctrl_send_msg(m_message, strlen(m_message));

                (void)sd_ble_gap_disconnect(p_evt->conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);

            }

        } break;

 

Summarized as follows:

Scenes

iOS

Android

nRF52

Comment

Host lost binding information

O

O

O

i.e. Central side bond info is removed

Binding information is missing from the machine

X

O

O

i.e. Peripheral side bond info is removed

Guess you like

Origin www.cnblogs.com/lim11/p/11132131.html