<?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>Security as Central a</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/50784/security-as-central-a</link><description>Hello 
 I&amp;#39;m using SDK 15.2 on nRF52 DK to test the ble_app_multirole_lesc example. 
 I downloaded the code to nRF52 DK to act as central. 
 I commented the scan_start() function then I downloaded the code to the other nRF52 DK to act as peripheral. 
</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 09 Aug 2019 09:19:47 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/50784/security-as-central-a" /><item><title>RE: Security as Central a</title><link>https://devzone.nordicsemi.com/thread/203245?ContentTypeID=1</link><pubDate>Fri, 09 Aug 2019 09:19:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:950f2087-ff42-40e6-a657-d1d9b1f77268</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;If you look at the on_ble_evt() function in main.c, it calls pm_handler_secure_on_connection(p_ble_evt); before the switch(p_ble_evt-&amp;gt;header.evt_id).&lt;/p&gt;
&lt;p&gt;If you look in the case BLE_GAP_EVT_CONNECTED inside the pm_handler_on_secure_connection() function you see that it will secure the connection using conn_secure();&lt;/p&gt;
&lt;p&gt;You can try to do this only if it is a peripheral or a central connection. If you are connecting to a phone, and you don&amp;#39;t want to encrypt this connection,&amp;nbsp; I assume that the phone acts as a central, and the nRF as a peripheral in this connection.&lt;/p&gt;
&lt;p&gt;The BLE_GAP_EVT_CONNECTED has a variable called role, which you can see in ble_gap.h on line 1016.&lt;/p&gt;
&lt;p&gt;Try to add a check to see if the nRF is a peripheral or a central in this connection, and only secure the connection if you are a central in your on_ble_evt() in main.c:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void on_ble_evt(uint16_t conn_handle, ble_evt_t const * p_ble_evt)
{
    char        passkey[BLE_GAP_PASSKEY_LEN + 1];
    uint16_t    role = ble_conn_state_role(conn_handle);

    if (p_ble_evt-&amp;gt;evt.gap_evt.params.connected.role == BLE_GAP_ROLE_CENTRAL)
    {
        pm_handler_secure_on_connection(p_ble_evt);
    }

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            m_connected_peers[conn_handle].is_connected = true;
            m_connected_peers[conn_handle].address = p_ble_evt-&amp;gt;evt.gap_evt.params.connected.peer_addr;
            multi_qwr_conn_handle_assign(conn_handle);
            break;
        case ...&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>