<?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>Protect only a few Bluetooth characteristics</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/74641/protect-only-a-few-bluetooth-characteristics</link><description>Hello 
 I would like to protect some Bluetooth characteristics in order to protect them from eavesdropping. 
 In fact, here is my problem: I would like to make an application (on a smartphone) which allows to quickly connect in Bluetooth to the devices</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 12 May 2021 11:34:19 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/74641/protect-only-a-few-bluetooth-characteristics" /><item><title>RE: Protect only a few Bluetooth characteristics</title><link>https://devzone.nordicsemi.com/thread/309465?ContentTypeID=1</link><pubDate>Wed, 12 May 2021 11:34:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bf832462-f769-4a32-ae96-5e06d67a642d</guid><dc:creator>QuentinD</dc:creator><description>&lt;p&gt;Now it works: I had to move &amp;quot;peer_manager_init (erase_bonds);&amp;quot; after Thread initialization.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect only a few Bluetooth characteristics</title><link>https://devzone.nordicsemi.com/thread/308106?ContentTypeID=1</link><pubDate>Tue, 04 May 2021 09:10:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:88b1d5e0-c966-4513-8e23-b36aa16dfbd8</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;If you could upload your project that would be good. You can create a new private case where you upload it.&amp;nbsp;Please refer to this thread in the new case so that it is assigned to me.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect only a few Bluetooth characteristics</title><link>https://devzone.nordicsemi.com/thread/308091?ContentTypeID=1</link><pubDate>Tue, 04 May 2021 08:33:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:365aaf2e-6725-41e0-b377-4eddd8fe68c0</guid><dc:creator>QuentinD</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;My application is based on the example &amp;quot;ble_thread_dyn_mtd_coap_cli&amp;quot; (nRF5_SDK_for_Thread_and_Zigbee_v4.1.0). To secure the bluetooth connection, I tried to use the &amp;quot;ble_app_multirole_lesc&amp;quot; example but maybe I forgot some things? (for my application, I need to use the Just Works method for LE Secure Connections).&lt;/p&gt;
&lt;p&gt;Yes I still have the same problem when I connect. But it works with the &amp;quot;ble_app_multirole_lesc&amp;quot; example so I think the problem is in my source code.&lt;br /&gt;I connect to a Samsung S10 smartphone with nRF Connect.&lt;/p&gt;
&lt;p&gt;Here are the logs on the nRF side:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;info&amp;gt; app: Connected
&amp;lt;info&amp;gt; app: Data len is set to 0xF0(240)
&amp;lt;info&amp;gt; nrf_ble_lesc: Calling sd_ble_gap_lesc_dhkey_reply on conn_handle: 0
&amp;lt;info&amp;gt; app: BLE_GAP_EVT_AUTH_STATUS
&amp;lt;info&amp;gt; app: Authorization failed with code: 139!
&amp;lt;info&amp;gt; peer_manager_handler: Connection security failed: role: Peripheral, conn_handle: 0x0, procedure: Bonding, error: 139
&amp;lt;info&amp;gt; app: Disconnected&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Do you want&amp;nbsp;that I send you my project to make it easier (private project) or only specifics files or functions?&lt;br /&gt;&lt;br /&gt;In the meantime, here are some infos:&lt;br /&gt;&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/2235.sdk_5F00_config.h"&gt;devzone.nordicsemi.com/.../2235.sdk_5F00_config.h&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Function for handling Peer Manager events.
 *
 * @param[in] p_evt  Peer Manager event.
 */
static void pm_evt_handler(pm_evt_t const * p_evt)
{
    pm_handler_on_pm_evt(p_evt);
    //pm_handler_disconnect_on_sec_failure(p_evt);
    pm_handler_flash_clean(p_evt);

    switch (p_evt-&amp;gt;evt_id)
    {
        case PM_EVT_PEERS_DELETE_SUCCEEDED:
            //adv_scan_start();
            //scan_start();
            break;

        default:
            break;
    }
}

void peer_manager_init(bool erase_bonds)
{
    ble_gap_sec_params_t sec_param;
    ret_code_t err_code;

    err_code = pm_init();
    APP_ERROR_CHECK(err_code);

    if (erase_bonds)
    {
        err_code = pm_peers_delete();
        APP_ERROR_CHECK(err_code);
    }
    memset(&amp;amp;sec_param, 0, sizeof(ble_gap_sec_params_t));
    // Security parameters to be used for all security procedures.
    sec_param.bond = false;//true;
    sec_param.mitm = false;
    sec_param.lesc = 1;
    sec_param.keypress = 0;
    sec_param.io_caps = BLE_GAP_IO_CAPS_NONE;
    sec_param.oob = false;
    sec_param.min_key_size = 7;
    sec_param.max_key_size = 16;
    sec_param.kdist_own.enc = 0;//1;
    sec_param.kdist_own.id = 0;//1;
    sec_param.kdist_peer.enc = 0;//1;
    sec_param.kdist_peer.id = 0;//1;

    err_code = pm_sec_params_set(&amp;amp;sec_param);
    APP_ERROR_CHECK(err_code);

    err_code = pm_register(pm_evt_handler);
    APP_ERROR_CHECK(err_code);
}

/**@brief Function for handling BLE events.
 *
 * @param[in]   p_ble_evt   Bluetooth stack event.
 * @param[in]   p_context   Unused.
 */
static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    uint32_t err_code;
    ble_gap_evt_t const * p_gap_evt = &amp;amp;p_ble_evt-&amp;gt;evt.gap_evt;
    //char  p_message_ble_gap_evt_connected[] = &amp;quot;Connected on bluetooth&amp;quot;;
    //char  p_message_ble_gap_evt_disconnected[] = &amp;quot;Disconnected from bluetooth&amp;quot;;

    #ifdef BLE_LE_SECURE_CONNECTIONS
        pm_handler_secure_on_connection(p_ble_evt);
    #endif

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
            APP_ERROR_CHECK(err_code);
            m_conn_handle = p_ble_evt-&amp;gt;evt.gap_evt.conn_handle;
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            m_conn_handle = BLE_CONN_HANDLE_INVALID;
            break;

#ifdef BLE_LE_SECURE_CONNECTIONS
        case BLE_GAP_EVT_AUTH_STATUS:
            NRF_LOG_INFO(&amp;quot;BLE_GAP_EVT_AUTH_STATUS&amp;quot;);
            if (p_ble_evt-&amp;gt;evt.gap_evt.params.auth_status.auth_status ==
                BLE_GAP_SEC_STATUS_SUCCESS)
            {
                NRF_LOG_INFO(&amp;quot;Authorization succeeded!&amp;quot;);
            }
            else
            {
                NRF_LOG_INFO(&amp;quot;Authorization failed with code: %u!&amp;quot;,
                             p_ble_evt-&amp;gt;evt.gap_evt.params.auth_status.auth_status);
            }
            break;

        /*#if !NFC_BLE_PAIR_LIB_ENABLED
        case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
            // Pairing not supported
            err_code = sd_ble_gap_sec_params_reply(m_conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL);
            APP_ERROR_CHECK(err_code);
            break;
        #endif*/
#endif

#ifndef BLE_LE_SECURE_CONNECTIONS
        case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
            // Pairing not supported
            err_code = sd_ble_gap_sec_params_reply(m_conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL);
            APP_ERROR_CHECK(err_code);
            break;
#endif

         case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST:
        {
            ble_gap_data_length_params_t dl_params;

            // Clearing the struct will effectivly set members to @ref BLE_GAP_DATA_LENGTH_AUTO
            memset(&amp;amp;dl_params, 0, sizeof(ble_gap_data_length_params_t));
            err_code = sd_ble_gap_data_length_update(p_ble_evt-&amp;gt;evt.gap_evt.conn_handle, &amp;amp;dl_params, NULL);
            APP_ERROR_CHECK(err_code);
        } break;

        case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
        {
            NRF_LOG_DEBUG(&amp;quot;PHY update request.&amp;quot;);
            ble_gap_phys_t const phys =
            {
                .rx_phys = BLE_GAP_PHY_AUTO,
                .tx_phys = BLE_GAP_PHY_AUTO,
            };
            err_code = sd_ble_gap_phy_update(p_ble_evt-&amp;gt;evt.gap_evt.conn_handle, &amp;amp;phys);
            APP_ERROR_CHECK(err_code);
        } break;

#ifndef BLE_LE_SECURE_CONNECTIONS
        case BLE_GATTS_EVT_SYS_ATTR_MISSING:
            // No system attributes have been stored.
            err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0);
            APP_ERROR_CHECK(err_code);
            break;
#endif

        case BLE_GATTC_EVT_TIMEOUT:
            // Disconnect on GATT Client timeout event.
            err_code = sd_ble_gap_disconnect(p_ble_evt-&amp;gt;evt.gattc_evt.conn_handle,
                                             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            APP_ERROR_CHECK(err_code);
            break;

        case BLE_GATTS_EVT_TIMEOUT:
            // Disconnect on GATT Server timeout event.
            err_code = sd_ble_gap_disconnect(p_ble_evt-&amp;gt;evt.gatts_evt.conn_handle,
                                             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            APP_ERROR_CHECK(err_code);
            break;

        case BLE_EVT_USER_MEM_REQUEST:
            err_code = sd_ble_user_mem_reply(p_ble_evt-&amp;gt;evt.gattc_evt.conn_handle, NULL);
            APP_ERROR_CHECK(err_code);
            break;

        case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
        {
            ble_gatts_evt_rw_authorize_request_t  req;
            ble_gatts_rw_authorize_reply_params_t auth_reply;

            req = p_ble_evt-&amp;gt;evt.gatts_evt.params.authorize_request;

            if (req.type != BLE_GATTS_AUTHORIZE_TYPE_INVALID)
            {
                if ((req.request.write.op == BLE_GATTS_OP_PREP_WRITE_REQ)     ||
                    (req.request.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_NOW) ||
                    (req.request.write.op == BLE_GATTS_OP_EXEC_WRITE_REQ_CANCEL))
                {
                    if (req.type == BLE_GATTS_AUTHORIZE_TYPE_WRITE)
                    {
                        auth_reply.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE;
                    }
                    else
                    {
                        auth_reply.type = BLE_GATTS_AUTHORIZE_TYPE_READ;
                    }
                    auth_reply.params.write.gatt_status = APP_FEATURE_NOT_SUPPORTED;
                    err_code = sd_ble_gatts_rw_authorize_reply(p_ble_evt-&amp;gt;evt.gatts_evt.conn_handle,
                                                               &amp;amp;auth_reply);
                    APP_ERROR_CHECK(err_code);
                }
            }
        } break; // BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST

        default:
            // No implementation needed.
            break;
    }
}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Thank you&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect only a few Bluetooth characteristics</title><link>https://devzone.nordicsemi.com/thread/308006?ContentTypeID=1</link><pubDate>Mon, 03 May 2021 18:37:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1fb7a081-f401-431c-8312-367ae4eed59c</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I do not see why the DHKey check failed. Which SDK version are you using? Can you enable logging on the nRF side and share the log? Do you always see this, or only in some situations or with some specific centrals (some phones etc)?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect only a few Bluetooth characteristics</title><link>https://devzone.nordicsemi.com/thread/307692?ContentTypeID=1</link><pubDate>Fri, 30 Apr 2021 14:03:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9afd9c88-f558-40cc-9e5a-25a9c6ccb23b</guid><dc:creator>QuentinD</dc:creator><description>&lt;p&gt;Here is my sniffer trace:&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/Test_5F00_with_5F00_pairing.pcapng"&gt;devzone.nordicsemi.com/.../Test_5F00_with_5F00_pairing.pcapng&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I have an error at the end (DHKey Check failed) but I think it&amp;#39;s another problem.&amp;nbsp;Do you have any idea what can cause this error?&lt;br /&gt;&lt;br /&gt;Thank you&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Protect only a few Bluetooth characteristics</title><link>https://devzone.nordicsemi.com/thread/307686?ContentTypeID=1</link><pubDate>Fri, 30 Apr 2021 13:49:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:43121f3e-5882-4ab7-a3ad-02d5e83b95c7</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]- Is it possible to connect to a device without having to do pairing in order to read a characteristic in &amp;quot;SEC_OPEN&amp;quot;? (while the &amp;quot;LE Secure Connection&amp;quot; is activated on the smartphone and the target device). The objective being that it is invisible for the user and that he does not have the need to pair.[/quote]
&lt;p&gt;Yes, that is no problem. Pairing is only required to access characteristics which are not open.&lt;/p&gt;
[quote user=""]- Is it normal that I see the same message twice on my smartphone when I connect to my device asking me if I want to pair the device?&lt;br /&gt;I am using the following configuration on my device:[/quote]
&lt;p&gt;No, it does not seem expected. Perhaps it would be easier to understand what causes this if you have a log from the nRF and a sniffer trace, as well as a more detailed explanation on how this happens.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>