<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Can’t get rid of bear hug bonding of Nrf52840</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/70020/can-t-get-rid-of-bear-hug-bonding-of-nrf52840</link><description>Hello, 
 My environment info: 
 Nrf52840-DK, PCA10059, MDBT50Q-DB 
 SDK 16.0.0 
 Win10, SES, nRF Connect v3.6.1 
 My project comprises a peripheral board connected to some sensors and a central board connected to a PC via USB. The boards exchange data</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 07 Jan 2021 13:11:02 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/70020/can-t-get-rid-of-bear-hug-bonding-of-nrf52840" /><item><title>RE: Can’t get rid of bear hug bonding of Nrf52840</title><link>https://devzone.nordicsemi.com/thread/287961?ContentTypeID=1</link><pubDate>Thu, 07 Jan 2021 13:11:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45ec0146-487c-4aff-82bf-7a95d8b6db42</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="BE"]&lt;p&gt;Anyway, I’m not sure about the SEC_PARAM_LESC functionality. The inline documentation says”&lt;/p&gt;
&lt;p&gt;define SEC_PARAM_LESC&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;1 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;strong&gt;/**&amp;lt; LE Secure Connections enabled. */&lt;/strong&gt; &amp;nbsp;&lt;/p&gt;
&lt;p&gt;So what is secured by all those nrf_Crypto’s: &amp;nbsp;the process of the connection, the data transmitted or both? Doe’s it contributes to the safe operation of the whitelist?&lt;/p&gt;[/quote]
&lt;p&gt;LE Secure Connections is a Bluetooth features that increases the security during the parigin stage. With legacy pairing, the key is exchanged on air so that an attacker can listen in. With LE Secure Connections, a shared secret is established using&amp;nbsp;Diffie–Hellman key exchange. This is more complex, but is handled for you by the nRF libraries. As long as both the central and peripheral supports it, it will be used&lt;/p&gt;
&lt;p&gt;After the pairing procedure, everything is the same, so the way the link is encrypted, whitelisting etc. is all the same. But you would have a higher degree of security as you have a much higher confidence that the key has not been compromised - that is it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can’t get rid of bear hug bonding of Nrf52840</title><link>https://devzone.nordicsemi.com/thread/287807?ContentTypeID=1</link><pubDate>Wed, 06 Jan 2021 21:51:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:52da1297-1eaa-4af8-aa50-2c16bea66ad4</guid><dc:creator>BE</dc:creator><description>&lt;p&gt;Hello &lt;span&gt;Einar&lt;/span&gt;,&lt;/p&gt;
&lt;p&gt;Thank you for your helpful answer. Your insistence &amp;ldquo;to ensure that you &lt;span&gt;delete&lt;/span&gt;&amp;nbsp;the bonds on both sides&amp;rdquo; led me to re-debug this part and I found that pressing KEY_0 on the central side didn&amp;rsquo;t called scanning_start(true) thus pm_peers_delete() didn&amp;rsquo;t&amp;nbsp; erased the central side, just as you said.&lt;/p&gt;
&lt;p&gt;So now it works as expected, as far as I can test: currently I have just one peripheral board and some centrals. Changing centrals for the same peripheral is possible only by pressing KEY_0 on both side. I hope that this will be the case with more peripheral boards as well.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;Regarding your note about the security concern in my product:&lt;/p&gt;
&lt;p&gt;The product consist of several sets of boards: Central_1/Peripheral_1, &amp;nbsp;Central_2/Peripheral_2 &amp;hellip;. Central_n/Peripheral_n. &amp;nbsp;These sets are operated by User_1, User_2 etc. &amp;nbsp;and each user can shut down each part of his set separately, just the Central_n, or just Peripheral_n. &amp;nbsp;Security means total grantee for no mismatch of set members, in any case.&amp;nbsp; Data interception by hackers is less relevant.&lt;/p&gt;
&lt;p&gt;Anyway, I&amp;rsquo;m not sure about the SEC_PARAM_LESC functionality. The inline documentation says&amp;rdquo;&lt;/p&gt;
&lt;p&gt;define SEC_PARAM_LESC&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;1 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;strong&gt;/**&amp;lt; LE Secure Connections enabled. */&lt;/strong&gt; &amp;nbsp;&lt;/p&gt;
&lt;p&gt;So what is secured by all those nrf_Crypto&amp;rsquo;s: &amp;nbsp;the process of the connection, the data transmitted or both? Doe&amp;rsquo;s it contributes to the safe operation of the whitelist?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;Please advice.&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can’t get rid of bear hug bonding of Nrf52840</title><link>https://devzone.nordicsemi.com/thread/287514?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2021 13:11:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d6a06940-866a-4bdb-ae22-d4acf7cf2538</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I do not see enough of you code to know how you handle it, but you cannot do whitelisting with no existing bonds (well, technically you can, but then you would need to keep the whitelist separately, and it is not what you want to do). However, assuming your&amp;nbsp;whitelist_set() function is similar to that of a few SDK examples, it should be good and no whitelist would be set when there are no&amp;nbsp;bonded peers.&lt;/p&gt;
&lt;p&gt;There is one important point, though. I was to quick reading the error code you get in the original post, as my first thought was whitelisting, which would give you a disconnect reason 0x3E =&amp;nbsp;&lt;span&gt;BLE_HCI_CONN_FAILED_TO_BE_ESTABLISHED on the central side if peripheral&amp;nbsp;use whitelisting and the central is not in the whitelist. However you wrote&amp;nbsp;you get,&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:inherit;"&gt;4102 = 0x1006 = PM_CONN_SEC_ERROR_PIN_OR_KEY_MISSING, so that indicates that bonding information is only deleted in one side. So you need to ensure that you &lt;/span&gt;delete&lt;span style="font-family:inherit;"&gt;&amp;nbsp;the bonds on both sides.&amp;nbsp;&lt;/span&gt;Alternatively&lt;span style="font-family:inherit;"&gt;, if that is not a security concern in your product, you could consider allowing repairing by adding this snippet to your peer manager event handler:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:inherit;"&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;        case PM_EVT_CONN_SEC_CONFIG_REQ: 
             {
                  pm_conn_sec_config_t config = {.allow_repairing = true};
                   pm_conn_sec_config_reply(p_evt-&amp;gt;conn_handle, &amp;amp;config);
             }&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can’t get rid of bear hug bonding of Nrf52840</title><link>https://devzone.nordicsemi.com/thread/287351?ContentTypeID=1</link><pubDate>Mon, 04 Jan 2021 23:16:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7e31d281-84ff-45fb-938f-913503728e0c</guid><dc:creator>BE</dc:creator><description>&lt;p&gt;Hello Einar&lt;/p&gt;
&lt;p&gt;The process of erasing the bonding is as following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;By pressing key_0 advertising_start(true) is called;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void bsp_event_handler(bsp_event_t event)
{
…
    switch (event)
    {
     …

        case  BSP_EVENT_KEY_0:             //   BSP_EVENT_CLEAR_BONDING_DATA:
          advertising_start(true);
        break;
  }
…
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span&gt;advertising_start(true)&amp;nbsp; calls&amp;nbsp; delete_bonds();&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void advertising_start(bool erase_bonds)
{
    if (erase_bonds == true)
    {
        delete_bonds();
       // Advertising is started by PM_EVT_PEERS_DELETE_SUCCEEDED event.
    }
    else
    {
       whitelist_set(PM_PEER_ID_LIST_SKIP_NO_ID_ADDR);
       ret_code_t ret = ble_advertising_start(&amp;amp;m_advertising, BLE_ADV_MODE_DIRECTED);
        
        APP_ERROR_CHECK(ret);
    }
}
&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;delete_bonds() calls pm_peers_delete();&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void delete_bonds(void)
{
    ret_code_t err_code;
    NRF_LOG_INFO(&amp;quot;Erase bonds!&amp;quot;);
    err_code = pm_peers_delete();
    APP_ERROR_CHECK(err_code);
}
&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;ul&gt;
&lt;li&gt;When the pear manager successfully deleted the bond, it sends the PM_EVT_PEERS_DELETE_SUCCEEDED event to the pm_evt_handler. On that event the NVIC_SystemReset() is invoked in the following way:&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void pm_evt_handler(pm_evt_t const * p_evt)
{
    pm_handler_on_pm_evt(p_evt);
    pm_handler_flash_clean(p_evt);

    switch (p_evt-&amp;gt;evt_id)
    {
      ………..
        case PM_EVT_PEERS_DELETE_SUCCEEDED:        

             NRF_LOG_INFO(&amp;quot;PM_EVT_PEERS_DELETE_SUCCEEDED, restarting  &amp;quot;);
             WaitCnt = 0;
             app_restart_flg = true;
             break;
   }
}


int main(void)
{
 ..
 ..
 advertising_start(false);

    for (;;)
    { 
      if(Connected_flg == true)
        {
         app_main_handler();
        }
      if(app_restart_flg == true) 
       {
        Connected_flg = false;
        app_restart();
       idle_state_handle();
      }
    }
}


void app_restart(void)
 {
   if(WaitCnt == 0)
     { 
      NVIC_SystemReset();
     }
 }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;So after NVIC_SystemReset() is executed advertising_start(false) is called,&amp;nbsp; i.e. &amp;nbsp;with whitelist!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Can’t get rid of bear hug bonding of Nrf52840</title><link>https://devzone.nordicsemi.com/thread/287268?ContentTypeID=1</link><pubDate>Mon, 04 Jan 2021 13:59:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:43d2638a-0f75-43e6-9ada-143d9e786ed9</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I wonder if the whitelist is related here. You write that you erase bonds, but you do not write if you perform a reset of some sort (like power cycle or soft reset), or explicitly start advertising and/or scan without the whitelist? If you do not restart scanning or advertising then the old whitelist would still be used even though the bonds have been deleted.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>