<?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>how to make pairing mandatory</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/43221/how-to-make-pairing-mandatory</link><description>Module: 
 ilumi H52 BLE module (nRF52832) 
 
 
 SDK: 
 nRF5_SDK_15.2.0_9412b96 
 
 
 Softdevice: 
 132_nrf52_6.1.0_softdevice.hex 
 
 
 Compiler: 
 gcc version 7.3.1 20180622 (release) [ARM/embedded-7-branch revision 261907] (15:7-2018-q2-4) 
 
 
 
 Hello</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 27 Feb 2019 09:35:42 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/43221/how-to-make-pairing-mandatory" /><item><title>RE: how to make pairing mandatory</title><link>https://devzone.nordicsemi.com/thread/173183?ContentTypeID=1</link><pubDate>Wed, 27 Feb 2019 09:35:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:768b9ad7-5a72-4ae7-866d-415dc6902c81</guid><dc:creator>lee-marc</dc:creator><description>&lt;p&gt;Thanks. That helped me. Now pairing works automatically.&lt;/p&gt;
&lt;p&gt;I enabled SEC_PARAM_LESC in main.c and changed the file components/ble/ble_services/ble_nus/ble_nus.c&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    // Add the RX Characteristic.
    memset(&amp;amp;add_char_params, 0, sizeof(add_char_params));
    add_char_params.uuid                     = BLE_UUID_NUS_RX_CHARACTERISTIC;
    add_char_params.uuid_type                = p_nus-&amp;gt;uuid_type;
    add_char_params.max_len                  = BLE_NUS_MAX_RX_CHAR_LEN;
    add_char_params.init_len                 = sizeof(uint8_t);
    add_char_params.is_var_len               = true;
    add_char_params.char_props.write         = 1;
    add_char_params.char_props.write_wo_resp = 1;

//    add_char_params.read_access  = SEC_OPEN;
//    add_char_params.write_access = SEC_OPEN;
    add_char_params.read_access  = SEC_JUST_WORKS;
    add_char_params.write_access = SEC_JUST_WORKS;

    err_code = characteristic_add(p_nus-&amp;gt;service_handle, &amp;amp;add_char_params, &amp;amp;p_nus-&amp;gt;rx_handles);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    // Add the TX Characteristic.
    /**@snippet [Adding proprietary characteristic to the SoftDevice] */
    memset(&amp;amp;add_char_params, 0, sizeof(add_char_params));
    add_char_params.uuid              = BLE_UUID_NUS_TX_CHARACTERISTIC;
    add_char_params.uuid_type         = p_nus-&amp;gt;uuid_type;
    add_char_params.max_len           = BLE_NUS_MAX_TX_CHAR_LEN;
    add_char_params.init_len          = sizeof(uint8_t);
    add_char_params.is_var_len        = true;
    add_char_params.char_props.notify = 1;

//    add_char_params.read_access       = SEC_OPEN;
//    add_char_params.write_access      = SEC_OPEN;
//    add_char_params.cccd_write_access = SEC_OPEN;
    add_char_params.read_access       = SEC_JUST_WORKS;
    add_char_params.write_access      = SEC_JUST_WORKS;
    add_char_params.cccd_write_access = SEC_JUST_WORKS;

    return characteristic_add(p_nus-&amp;gt;service_handle, &amp;amp;add_char_params, &amp;amp;p_nus-&amp;gt;tx_handles);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Unfortunately I was not able to change permissions afterwards in main.c, so I had to change the ble_nus.c from nordic SDK.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to make pairing mandatory</title><link>https://devzone.nordicsemi.com/thread/172975?ContentTypeID=1</link><pubDate>Tue, 26 Feb 2019 09:56:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6b0d37ee-7795-4b8f-a9d0-d0b7c52180d7</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Yes, it&amp;#39;s correct. It&amp;#39;s how usually things work on BLE. The central read/write the characteristic to find out if encryption is required or not and then start the pairing bonding if needed.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You would need to change the permission, not the UUID. Please study the ble_app_proximity example. For example, take a look at the&amp;nbsp;tps_init() function. You need to choose&amp;nbsp;SEC_JUST_WORKS or&amp;nbsp;SEC_MITM instead of&amp;nbsp;SEC_OPEN.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to make pairing mandatory</title><link>https://devzone.nordicsemi.com/thread/172871?ContentTypeID=1</link><pubDate>Mon, 25 Feb 2019 18:16:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0c0b0d55-b505-4738-a056-b7b7e790c47a</guid><dc:creator>lee-marc</dc:creator><description>[quote userid="2121" url="~/f/nordic-q-a/43221/how-to-make-pairing-mandatory/172795"]Again, you don&amp;#39;t have to call&amp;nbsp;&lt;span&gt;pm_conn_secure&amp;nbsp;() to enforce pairing. If your attributes (service and characteristic) require encryption, the peer device need to trigger a bonding or it won&amp;#39;t be able to access those attribute.&lt;/span&gt;[/quote]
&lt;p&gt;If I understand right the peer device (central device) will trigger a bonding automatically if an attribute like encryption is required. And to achieve this, the NUS UUID characteristics have to be changed to require encryption, right? How does the UUID have to be changed?&lt;span class="mceItem mceNonEditable mceQuote" id="mceQuote2"&gt;...&lt;/span&gt;&lt;/p&gt;
[quote userid="2121" url="~/f/nordic-q-a/43221/how-to-make-pairing-mandatory/172795"]I&amp;#39;m not familiar with CodeLoader, what is that?[/quote]
&lt;p&gt;&amp;quot;CodeLoader&amp;quot; is one of the writers or the previous messages.&lt;/p&gt;
[quote userid="2121" url="~/f/nordic-q-a/43221/how-to-make-pairing-mandatory/172795"]If you want to disconnect those peer devices that don&amp;#39;t start pairing, you can add a timer in your application. You start the timer when you are connected and after a certain time, you can disconnect if the bonded event is not arrived.&amp;nbsp;[/quote]
&lt;p&gt;I would use that as a workaround if there&amp;#39;s no avail to a better solution.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to make pairing mandatory</title><link>https://devzone.nordicsemi.com/thread/172795?ContentTypeID=1</link><pubDate>Mon, 25 Feb 2019 13:54:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9a6f39e0-aa35-4965-bff9-000e36c56de0</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Again, you don&amp;#39;t have to call&amp;nbsp;&lt;span&gt;pm_conn_secure&amp;nbsp;() to enforce pairing. If your attributes (service and characteristic) require encryption, the peer device need to trigger a bonding or it won&amp;#39;t be able to access those attribute.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I&amp;#39;m not familiar with CodeLoader, what is that?&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If you have a look at the guide line &lt;a href="https://developer.apple.com/accessories/Accessory-Design-Guidelines.pdf"&gt;here&lt;/a&gt; by Apple at section 11.10 you can find the recommendation from apple that peripheral should not request pairing.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If you want to disconnect those peer devices that don&amp;#39;t start pairing, you can add a timer in your application. You start the timer when you are connected and after a certain time, you can disconnect if the bonded event is not arrived.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to make pairing mandatory</title><link>https://devzone.nordicsemi.com/thread/172754?ContentTypeID=1</link><pubDate>Mon, 25 Feb 2019 12:53:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:55bef893-0e2c-4e4b-b32f-cd29fabd71f2</guid><dc:creator>lee-marc</dc:creator><description>&lt;p&gt;Maybe my intention is a little misleading.&lt;/p&gt;
&lt;p&gt;In other words:&lt;/p&gt;
&lt;p&gt;We want that only paired (and bonded) central devices are able to work with the peripheral device. Not paired central devices should be forced to pair. Otherwise they should be disconnected.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to make pairing mandatory</title><link>https://devzone.nordicsemi.com/thread/172730?ContentTypeID=1</link><pubDate>Mon, 25 Feb 2019 11:44:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:71c3359a-0a63-4724-ae7b-82369b382716</guid><dc:creator>lee-marc</dc:creator><description>&lt;p&gt;Hello Hung, Thank you for your message.&lt;/p&gt;
[quote userid="2121" url="~/f/nordic-q-a/43221/how-to-make-pairing-mandatory/172496"]Usually it&amp;#39;s not suggested to call&amp;nbsp;&lt;span&gt;pm_conn_secure() when you are a peripheral (Apple BLE guideline doesn&amp;#39;t suggest this, same on Android). If you are a peripheral, usually you let the central device to trigger pairing and re-pairing.&lt;/span&gt;[/quote]
&lt;p&gt;But that is what CodeLoader recommended. Otherwise let&amp;#39;s go back to my origin question: &amp;quot;how to make pairing mandatory&amp;quot; if pairing has to be initiated by central? (Please keep in mind: we are programming the peripheral part)&lt;/p&gt;
[quote userid="2121" url="~/f/nordic-q-a/43221/how-to-make-pairing-mandatory/172496"]If you still want to trigger pairing from the peripheral side, you can add code to skip calling&amp;nbsp;pm_conn_secure()&amp;nbsp;if&amp;nbsp;PM_EVT_BONDED_PEER_CONNECTED is received.[/quote]
&lt;p&gt;Unfortunately pm_conn_secure is called in case BLE_GAP_EVT_CONNECTED, &lt;strong&gt;before &lt;/strong&gt;&lt;span&gt;PM_EVT_BONDED_PEER_CONNECTED&lt;/span&gt; is received. So how should code work?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to make pairing mandatory</title><link>https://devzone.nordicsemi.com/thread/172496?ContentTypeID=1</link><pubDate>Fri, 22 Feb 2019 12:05:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:84244abf-dbce-432a-8197-00f86f77194b</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Usually it&amp;#39;s not suggested to call&amp;nbsp;&lt;span&gt;pm_conn_secure() when you are a peripheral (Apple BLE guideline doesn&amp;#39;t suggest this, same on Android). If you are a peripheral, usually you let the central device to trigger pairing and re-pairing.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If you still want to trigger pairing from the peripheral side, you can add code to skip calling&amp;nbsp;pm_conn_secure()&amp;nbsp;if&amp;nbsp;PM_EVT_BONDED_PEER_CONNECTED is received.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to make pairing mandatory</title><link>https://devzone.nordicsemi.com/thread/172278?ContentTypeID=1</link><pubDate>Thu, 21 Feb 2019 11:06:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c9c33763-816d-46b0-a548-872a3cd14715</guid><dc:creator>lee-marc</dc:creator><description>&lt;p&gt;pm_conn_secure basically works in our peripheral device, provided the connecting central device is not already bonded.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;info&amp;gt; app: Multiperipheral example started.
&amp;lt;info&amp;gt; app: Client requested that all bonds be deleted
&amp;lt;debug&amp;gt; nrf_ble_gatt: Requesting to update ATT MTU to 82 bytes on connection 0x0.
&amp;lt;debug&amp;gt; nrf_ble_gatt: Updating data length to 83 on connection 0x0.
&amp;lt;debug&amp;gt; nrf_ble_gatt: ATT MTU updated to 82 bytes on connection 0x0 (response).
&amp;lt;info&amp;gt; app: Data len is set to 0x4F(79)
&amp;lt;debug&amp;gt; app: ATT MTU exchange completed. central 0x52 peripheral 0x52
&amp;lt;debug&amp;gt; nrf_ble_gatt: Data length updated to 83 on connection 0x0.
&amp;lt;debug&amp;gt; nrf_ble_gatt: max_rx_octets: 83
&amp;lt;debug&amp;gt; nrf_ble_gatt: max_tx_octets: 83
&amp;lt;debug&amp;gt; nrf_ble_gatt: max_rx_time: 1096
&amp;lt;debug&amp;gt; nrf_ble_gatt: max_tx_time: 1096
&amp;lt;debug&amp;gt; app: ATT MTU exchange completed. central 0x52 peripheral 0x52
&amp;lt;debug&amp;gt; app: BLE_GAP_EVT_SEC_PARAMS_REQUEST
&amp;lt;info&amp;gt; peer_manager_handler: Connection secured: role: Peripheral, conn_handle: 0, procedure: Bonding
&amp;lt;info&amp;gt; app: Connection with link 0x0 established.
&amp;lt;info&amp;gt; app: BLE_GAP_EVT_AUTH_STATUS: status=0x0 bond=0x1 lv4: 0 kdist_own:0x3 kdist_peer:0x3&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If the central device disconnects and connects again, pm_conn_secure is executed again an an error occurs:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;debug&amp;gt; nrf_ble_gatt: Requesting to update ATT MTU to 82 bytes on connection 0x1.
&amp;lt;debug&amp;gt; nrf_ble_gatt: Updating data length to 83 on connection 0x1.
&amp;lt;info&amp;gt; app: PM_EVT_BONDED_PEER_CONNECTED
&amp;lt;error&amp;gt; app: ERROR 17 [NRF_ERROR_BUSY] at .//main.c:993
PC at: 0x0002DC97
&amp;lt;error&amp;gt; app: End of error report&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Line 993 in main.c is the result of APP_ERROR_CHECK after executing pm_conn_secure.&lt;/p&gt;
&lt;p&gt;My question: How can we check if the connecting device is already bonded before executing pm_conn_secure in case BLE_GAP_EVT_CONNECTED)?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to make pairing mandatory</title><link>https://devzone.nordicsemi.com/thread/169043?ContentTypeID=1</link><pubDate>Fri, 01 Feb 2019 11:53:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf14bde8-2281-4557-92f6-d048c4594581</guid><dc:creator>CodeLoader</dc:creator><description>&lt;p&gt;You can initiate&amp;nbsp;&lt;strong&gt;pm_conn_secure() &lt;/strong&gt;in&lt;strong&gt;&amp;nbsp;&lt;/strong&gt;peripheral role as well like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void onPeerManagerBlePeripheralEvent(ble_evt_t const* bleEvent) {
    switch (bleEvent-&amp;gt;header.evt_id) {
        case BLE_GAP_EVT_CONNECTED: {
            pm_conn_secure(bleEvent-&amp;gt;evt.gap_evt.conn_handle, false);
            break;
        }
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Also keep in mind that NUS service in the SDK has open read and write characteristics (their read and write access is set to&amp;nbsp;SEC_OPEN). If you want the characteristics to be secure, you might want to set&amp;nbsp;&lt;strong&gt;mitm&amp;nbsp;&lt;/strong&gt;option in security params to 1. and also change NUS read and write characteristics security access like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;add_char_params.read_access  = SEC_MITM;
add_char_params.write_access = SEC_MITM;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This way only paired devices would be able to use your NUS characteristics&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to make pairing mandatory</title><link>https://devzone.nordicsemi.com/thread/169028?ContentTypeID=1</link><pubDate>Fri, 01 Feb 2019 10:42:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7519d5a0-a6f9-4890-b24f-1e8164859d6b</guid><dc:creator>lee-marc</dc:creator><description>&lt;p&gt;Thank you for your message. But as I wrote, I&amp;#39;m working with the multiperipheral example. So I&amp;#39;m using a peripheral device, not a central device. All incoming connections from central devices should be forced to pair with the peripheral device.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: how to make pairing mandatory</title><link>https://devzone.nordicsemi.com/thread/168934?ContentTypeID=1</link><pubDate>Thu, 31 Jan 2019 17:05:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03169622-07a5-4842-961b-969fd6ad395c</guid><dc:creator>CodeLoader</dc:creator><description>&lt;p&gt;You should use Peer Manager module. After initialization it with&amp;nbsp;&lt;strong&gt;pm_init() &lt;/strong&gt;&amp;nbsp;set security params using&amp;nbsp;&lt;strong&gt;pm_sec_params_set(). &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;After peripheral device is connected, call&amp;nbsp;&lt;strong&gt;pm_conn_secure()&lt;/strong&gt;&amp;nbsp;to initiate bonding.&lt;/p&gt;
&lt;p&gt;You might want to check&amp;nbsp;ble_app_hrs_c, where it&amp;#39;s implemented.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>