<?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>Using encryption between central and peripheral.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/40842/using-encryption-between-central-and-peripheral</link><description>Hi there, 
 I am working with softdevice v5.0.0, and trying to have central and peripheral do encryption. 
 The peripheral has a r/w characteristic, and another one with read with notify (cccd r/w), but no write. 
 When I enable BOND, LESC and the usual</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 29 Nov 2018 08:49:02 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/40842/using-encryption-between-central-and-peripheral" /><item><title>RE: Using encryption between central and peripheral.</title><link>https://devzone.nordicsemi.com/thread/159500?ContentTypeID=1</link><pubDate>Thu, 29 Nov 2018 08:49:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:60a8f593-bad3-42aa-af36-dd527643d458</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Glad it worked. Regarding event handling, I can&amp;#39;t think of anything that must be changed when adding pairing support. It&amp;#39;s common to do service discovery before securing the link.&amp;nbsp; The ble_app_hrs and ble_hrs_c support bonding if you want something to compare against.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using encryption between central and peripheral.</title><link>https://devzone.nordicsemi.com/thread/159393?ContentTypeID=1</link><pubDate>Wed, 28 Nov 2018 11:01:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b490fdd3-c629-4f70-bd92-b2fc9d79ccd3</guid><dc:creator>David Fernandez</dc:creator><description>&lt;p&gt;That was it!&lt;/p&gt;
&lt;p&gt;Moving the notification enable to the PM event for conn sec succeeded makes it work.&lt;/p&gt;
&lt;p&gt;---&lt;/p&gt;
&lt;p&gt;I wonder if there might be other things that I should move to the PM events, rather than leave them in the existing events, for example, all the gatt local and remote databases stored by PM, should the discovery be done differently, e.g. after the conn sec succeeded or the db applied events? Currently I am doing it on BLE_CONNECTED, which might not be the right thing to do.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using encryption between central and peripheral.</title><link>https://devzone.nordicsemi.com/thread/159384?ContentTypeID=1</link><pubDate>Wed, 28 Nov 2018 10:17:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3f034452-6cf8-4a63-9f6b-9d844a178724</guid><dc:creator>David Fernandez</dc:creator><description>&lt;p&gt;The answer is quite likely to be no. I enable it in the discovery complete event, just after calling pm_conn_secure.&lt;/p&gt;
&lt;p&gt;So is it just a matter of moving that to the pm conn sec succeeded event?&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using encryption between central and peripheral.</title><link>https://devzone.nordicsemi.com/thread/159355?ContentTypeID=1</link><pubDate>Wed, 28 Nov 2018 07:57:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0358c3bd-d8b2-4e2e-8a93-b88ab3b47520</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;On the central side, is the notification being enabled after the link is secured? Otherwise the CCCD write request will return&amp;nbsp;BLE_GATT_STATUS_ATTERR_INSUF_AUTHENTICATION and notification will not get enabled (&lt;a href="https://devzone.nordicsemi.com/support-private/support/218429/BLE_GATT_STATUS_ATTERR_INSUF_AUTHENTICATION"&gt;MSC write&lt;/a&gt;).&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using encryption between central and peripheral.</title><link>https://devzone.nordicsemi.com/thread/159349?ContentTypeID=1</link><pubDate>Wed, 28 Nov 2018 07:31:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7330aa73-a1be-436b-8d70-db586eea0061</guid><dc:creator>David Fernandez</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;Yes, I was suspecting that the read should be kept open, but did not know where to look for proper documentation, as the infocenter only mentions some vague constrains for the API, and there is no source code to check what they actually are.&lt;/p&gt;
&lt;p&gt;So I am using two nRF52832 devices, one is a central, the other is the peripheral.&lt;/p&gt;
&lt;p&gt;The code for the central, AFAIK does not have anything about the encryption, other than configuring the peer manager to support LESC, as I do in both devices.&lt;/p&gt;
&lt;p&gt;I have made sure that I test with the device peer data clear, otherwise the peer manager will issue a SEC_FAILED event.&lt;/p&gt;
&lt;p&gt;Despite all that, if I do the change for the cccd write to ENC_NO_MITM, then the button notifications are not received in the central anymore.&lt;/p&gt;
&lt;p&gt;Let me know what bits do you want me to check.&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using encryption between central and peripheral.</title><link>https://devzone.nordicsemi.com/thread/159301?ContentTypeID=1</link><pubDate>Tue, 27 Nov 2018 16:39:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:765066b9-05e7-4fc7-8be6-9a206b1648a2</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Read permission must be set to &amp;quot;open&amp;quot; according to the specification (ref. core spec. 5.0, vol 3, Part G, section 3.3.3.3 (table 3.10)). The softdevice enforces this requirement and is probably why you get the invalid param error. However, it should work if you only require authentication for write access. What central are you using for test? In case it&amp;#39;s an&amp;nbsp;iOS device, try to &amp;#39;forget&amp;#39; the device from ios settings -&amp;gt; Bluetooth, enable and disable flight mode (clears device cache on phone), then re-connect.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using encryption between central and peripheral.</title><link>https://devzone.nordicsemi.com/thread/159286?ContentTypeID=1</link><pubDate>Tue, 27 Nov 2018 15:36:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:132ccd25-0c4f-4258-bcdf-a578d4959069</guid><dc:creator>David Fernandez</dc:creator><description>&lt;p&gt;Hi Vidar,&lt;/p&gt;
&lt;p&gt;This is the initialization code in the peripheral:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static uint32_t button_char_add(ble_mydev_t * p_mydev, const ble_mydev_init_t * p_mydev_init)
{
    ble_gatts_char_md_t char_md;
    ble_gatts_attr_md_t cccd_md;
    ble_gatts_attr_t    attr_char_value;
    ble_uuid_t          ble_uuid;
    ble_gatts_attr_md_t attr_md;

    memset(&amp;amp;cccd_md, 0, sizeof(cccd_md));

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;cccd_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;cccd_md.write_perm);
    cccd_md.vloc = BLE_GATTS_VLOC_STACK;

    memset(&amp;amp;char_md, 0, sizeof(char_md));

    char_md.char_props.read   = 1;
    char_md.char_props.notify = 1;
    char_md.p_char_user_desc  = NULL;
    char_md.p_char_pf         = NULL;
    char_md.p_user_desc_md    = NULL;
    char_md.p_cccd_md         = &amp;amp;cccd_md;
    char_md.p_sccd_md         = NULL;

    ble_uuid.type = p_mydev-&amp;gt;uuid_type;
    ble_uuid.uuid = MYDEV_UUID_BUTTON_CHAR;

    memset(&amp;amp;attr_md, 0, sizeof(attr_md));

    BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&amp;amp;attr_md.read_perm);
    BLE_GAP_CONN_SEC_MODE_SET_NO_ACCESS(&amp;amp;attr_md.write_perm);
    attr_md.vloc    = BLE_GATTS_VLOC_STACK;
    attr_md.rd_auth = 0;
    attr_md.wr_auth = 0;
    attr_md.vlen    = 0;

    memset(&amp;amp;attr_char_value, 0, sizeof(attr_char_value));

    attr_char_value.p_uuid    = &amp;amp;ble_uuid;
    attr_char_value.p_attr_md = &amp;amp;attr_md;
    attr_char_value.init_len  = sizeof(uint8_t);
    attr_char_value.init_offs = 0;
    attr_char_value.max_len   = sizeof(uint8_t);
    attr_char_value.p_value   = NULL;

    return sd_ble_gatts_characteristic_add(p_mydev-&amp;gt;service_handle,
                                           &amp;amp;char_md,
                                           &amp;amp;attr_char_value,
                                           &amp;amp;p_mydev-&amp;gt;button_char_handles);
}


uint32_t ble_mydev_init(ble_mydev_t * p_mydev, const ble_mydev_init_t * p_mydev_init)
{
    uint32_t   err_code;
    ble_uuid_t ble_uuid;

    // Initialize service structure.
    p_mydev-&amp;gt;led_write_handler = p_mydev_init-&amp;gt;led_write_handler;

    // Add service.
    ble_uuid128_t base_uuid = {MYDEV_UUID_BASE};
    err_code = sd_ble_uuid_vs_add(&amp;amp;base_uuid, &amp;amp;p_mydev-&amp;gt;uuid_type);
    VERIFY_SUCCESS(err_code);

    ble_uuid.type = p_mydev-&amp;gt;uuid_type;
    ble_uuid.uuid = MYDEV_UUID_SERVICE;

    err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &amp;amp;ble_uuid, &amp;amp;p_mydev-&amp;gt;service_handle);
    VERIFY_SUCCESS(err_code);

    // Add characteristics.
    err_code = button_char_add(p_mydev, p_mydev_init);
    VERIFY_SUCCESS(err_code);
...&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If I replace the:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;cccd_md.read_perm);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;cccd_md.write_perm);&lt;/p&gt;
&lt;p&gt;with&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM(&amp;amp;cccd_md.read_perm);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM(&amp;amp;cccd_md.write_perm);&lt;/p&gt;
&lt;p&gt;The function sd_ble_gatts_characteristic_add will return invalid param.&lt;/p&gt;
&lt;p&gt;If I only replace:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BLE_GAP_CONN_SEC_MODE_SET_OPEN(&amp;amp;cccd_md.write_perm);&lt;/p&gt;
&lt;p&gt;with&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; BLE_GAP_CONN_SEC_MODE_ENC_NO_MITM(&amp;amp;cccd_md.write_perm);&lt;/p&gt;
&lt;p&gt;Then the notifications for the button won&amp;#39;t work anymore.&lt;/p&gt;
&lt;p&gt;I wonder if I am missing some required change either in the peripheral or the central when setting the cccd_md.write_perm as encoded with no mitm protection.&lt;/p&gt;
&lt;p&gt;I know there are examples that do it and work, but comming from an old code base, I have applied the changes that seem required to do it, so I may be missing one of the required changes.&lt;/p&gt;
&lt;p&gt;I would need help to trouble shoot that.&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using encryption between central and peripheral.</title><link>https://devzone.nordicsemi.com/thread/159276?ContentTypeID=1</link><pubDate>Tue, 27 Nov 2018 15:14:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c35bfa3b-554b-4967-aff5-fd002262f64a</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;This should work, I just verified it with the hrs example from SDK 14.2.0 (s132 v5). Can you check which softdevice function it is that returns invalid param?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>