<?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 initiate BLE pairing manually</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/86794/how-to-initiate-ble-pairing-manually</link><description>Hello, 
 
 I&amp;#39;m running nRF Connect SDK v1.9.0 on two nRF52840-DK devices, one Peripheral other Central. 
 My application requires to initiate pairing, i.e. send pair request, programmatically. 
 
 For testing, I created a Peripheral device with a Service</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 06 May 2022 13:19:32 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/86794/how-to-initiate-ble-pairing-manually" /><item><title>RE: How to initiate BLE pairing manually</title><link>https://devzone.nordicsemi.com/thread/366745?ContentTypeID=1</link><pubDate>Fri, 06 May 2022 13:19:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:45d9bb3e-8d21-46c4-b96b-470d030b3a6b</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;The MIC failures occur because the sniffer does not have the encryption key to decrypt the payload.&amp;nbsp; To be able to sniff LESC pairing you need to enable the debug DH keys: &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/kconfig/CONFIG_BT_USE_DEBUG_KEYS.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/kconfig/CONFIG_BT_USE_DEBUG_KEYS.html&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to initiate BLE pairing manually</title><link>https://devzone.nordicsemi.com/thread/366554?ContentTypeID=1</link><pubDate>Thu, 05 May 2022 22:11:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39dcd6bf-aae4-4022-adbd-233de824cafd</guid><dc:creator>ealtan</dc:creator><description>&lt;p&gt;I was using one Nordic nRF52840-DK in Peripheral mode and the other unit was another nRF52840-based module DK from another company.&amp;nbsp; So, I switched to two Nordic DKs and connection problems went away, so that&amp;#39;s good.&amp;nbsp; But pairing failures are still here, so I&amp;#39;ve put Nordic nRF52840 dongle with Wireshark capture in between.&amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p&gt;It seems like all is going well till when Slave responds with&amp;nbsp; LL_START_ENC_REQ and then I see all packets that are not empty PDU having &amp;quot;Encrypted packet decrypted incorrectly (bad MIC) &amp;quot; error.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Any idea why these bad MIC errors might be happening ?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to initiate BLE pairing manually</title><link>https://devzone.nordicsemi.com/thread/365631?ContentTypeID=1</link><pubDate>Fri, 29 Apr 2022 15:24:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:25986786-4f9e-4e5d-afaa-8917b2cd9367</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;I don&amp;#39;t think there is much you can do in FW to improve chances for a connection attempt to succeed&amp;nbsp; except for increasing the Radio&amp;#39;s TX output power ( &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/zephyr/samples/bluetooth/hci_pwr_ctrl/README.html"&gt;example&lt;/a&gt; ). Default is 0 dBm and radio is supporting up to +8 dBm. But I&amp;#39;m surprised you don&amp;#39;t see this with the other board. Maybe the other board automatically repeats the connection attempt if it fails the first time? A Bluetooth &lt;a href="https://www.nordicsemi.com/Products/Development-tools/nRF-Sniffer-for-Bluetooth-LE"&gt;sniffer &lt;/a&gt;trace may help show what the problem is.&lt;/p&gt;
&lt;p&gt;You are still using 2 Nordic DKs for this test?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to initiate BLE pairing manually</title><link>https://devzone.nordicsemi.com/thread/365621?ContentTypeID=1</link><pubDate>Fri, 29 Apr 2022 14:56:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:463366df-98bb-4f45-96f2-968864864acd</guid><dc:creator>ealtan</dc:creator><description>&lt;p&gt;Yes, it is possible, however,&amp;nbsp; I repeat the test with another MCU vendor and I don&amp;#39;t have these connection and pairing issues.&amp;nbsp; &amp;nbsp;So, my question is,&amp;nbsp; what can I change to create a more robust connection and pairing operation ?&amp;nbsp; &amp;nbsp;For example, is there more info on these parameters ?&amp;nbsp; How do they affect connections ?&amp;nbsp; &amp;nbsp;:&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;/** Connection parameters for LE connections */&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;struct&lt;/span&gt;&lt;span&gt; bt_le_conn_param {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;uint16_t&lt;/span&gt;&lt;span&gt; interval_min;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;uint16_t&lt;/span&gt;&lt;span&gt; interval_max;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;uint16_t&lt;/span&gt;&lt;span&gt; latency;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span&gt;uint16_t&lt;/span&gt;&lt;span&gt; timeout;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;};&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; .options &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; (_options), \&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; .interval &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; (_interval), \&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; .window &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; (_window), \&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; .interval_coded &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;, \&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; .window_coded &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;, \&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&amp;nbsp; &amp;nbsp; .timeout &lt;/span&gt;&lt;span&gt;=&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;span&gt;, \&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to initiate BLE pairing manually</title><link>https://devzone.nordicsemi.com/thread/365585?ContentTypeID=1</link><pubDate>Fri, 29 Apr 2022 12:22:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:712923a8-8c88-4fbf-bae8-c86e8724358c</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Could it be the environment you are testing this in? BT_HCI_ERR_CONN_FAIL_TO_ESTABLISH will happen from time to time. It means the peripheral did not respond to the connect request (only one request is sent per connect attempt) and that the central have to retry. It is normal for this error to happen from time time, but it can also occur quite frequently if there is lots of noise or interference from other nearby sources, for instance, active scanning from other BLE devices.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to initiate BLE pairing manually</title><link>https://devzone.nordicsemi.com/thread/365420?ContentTypeID=1</link><pubDate>Thu, 28 Apr 2022 12:17:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:245328a5-0f82-440f-9040-76097ac3b2aa</guid><dc:creator>ealtan</dc:creator><description>&lt;p&gt;Thank you,&amp;nbsp; I did that, but overall pairing seems to be very unreliable.&amp;nbsp; Many times it fails with&amp;nbsp;unspecified&amp;nbsp; reason.&amp;nbsp; &amp;nbsp;&lt;/p&gt;
&lt;p&gt;But before that getting into details with pairing,&amp;nbsp; connections have been pretty undeterministic, too.&amp;nbsp; &amp;nbsp; I have a Central which&amp;nbsp;issues a connect to a Peripheral,&amp;nbsp; many times Central comes back with disconnected callback with reason&amp;nbsp; BT_HCI_ERR_CONN_FAIL_TO_ESTAB.&amp;nbsp; &amp;nbsp;So,&amp;nbsp; do you have any recommendations to make connections more reliable ?&amp;nbsp; Any parameters to tweak ?&amp;nbsp; &amp;nbsp;Why would it keep disconnecting with&amp;nbsp;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;BT_HCI_ERR_CONN_FAIL_TO_ESTAB reason ?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to initiate BLE pairing manually</title><link>https://devzone.nordicsemi.com/thread/365087?ContentTypeID=1</link><pubDate>Wed, 27 Apr 2022 06:53:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5b995a9b-69bf-4c42-ab5f-000a601280a3</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;I see. In that case you can add &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/kconfig/CONFIG_BT_BONDABLE.html"&gt;CONFIG_BT_BONDABLE&lt;/a&gt;=n to your project, or call &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/zephyr/reference/bluetooth/connection_mgmt.html#c.bt_set_bondable"&gt;bt_set_bondable(&amp;#39;false&amp;#39;)&lt;/a&gt; on startup.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to initiate BLE pairing manually</title><link>https://devzone.nordicsemi.com/thread/365045?ContentTypeID=1</link><pubDate>Tue, 26 Apr 2022 21:21:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ef7a91f-2b0c-4b96-9197-a4f70071f971</guid><dc:creator>ealtan</dc:creator><description>[quote userid="4240" url="~/f/nordic-q-a/86794/how-to-initiate-ble-pairing-manually/364605#364605"]The other connections will be secured with the encryption key that was exchanged during pairing.[/quote]
&lt;p&gt;Is that because these two devices are bonded ?&amp;nbsp; &amp;nbsp; I don&amp;#39;t want them to be bonded,&amp;nbsp; I want to trigger and restart pairing process every time .&amp;nbsp; Is there a way of doing this ?&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to initiate BLE pairing manually</title><link>https://devzone.nordicsemi.com/thread/364605?ContentTypeID=1</link><pubDate>Mon, 25 Apr 2022 07:29:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ac63b5c0-76a9-438b-84d3-ed152009eb1f</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Thanks for the clarification and sorry for delayed response. The reason you are not getting the pairing_complete callback on the subsequent connections is that the pairing procedure is only performed in the first connection. The other connections will be secured with the encryption key that was exchanged during pairing.&lt;/p&gt;
&lt;p&gt;You can register the &amp;quot;security changed&amp;quot; callback if you want to monitor when the link becomes secured in both cases (i.e. after pairing or encryption with existing keys):&lt;/p&gt;
&lt;p&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/zephyr/reference/bluetooth/connection_mgmt.html#c.bt_conn_cb.security_changed"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/zephyr/reference/bluetooth/connection_mgmt.html#c.bt_conn_cb.security_changed&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Here is how the callback is used in our central uart sample for reference: &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/7848293244a0904cb401f13f420bf610d7aa8e91/samples/bluetooth/central_uart/src/main.c#L425"&gt;https://github.com/nrfconnect/sdk-nrf/blob/7848293244a0904cb401f13f420bf610d7aa8e91/samples/bluetooth/central_uart/src/main.c#L425&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to initiate BLE pairing manually</title><link>https://devzone.nordicsemi.com/thread/364065?ContentTypeID=1</link><pubDate>Thu, 21 Apr 2022 03:17:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b0495396-23b1-418e-a05b-4b9544ea0da1</guid><dc:creator>ealtan</dc:creator><description>&lt;p&gt;Thank you, Vidar,&amp;nbsp; &amp;nbsp;just one clarification,&amp;nbsp; I&amp;nbsp; initiate pairing from Central to Peripheral.&amp;nbsp; &amp;nbsp;By using bt_conn_set_security()&amp;nbsp; I can upgrade the security level and that causes&amp;nbsp; pairing_complete callback to be called.&amp;nbsp; So, that&amp;#39;s good, thank you.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;But I have a new issue.&amp;nbsp; I have a test suite that I&amp;#39;m running in a loop : Central connects to a Peripheral, Central initiates pairing,&amp;nbsp; pairing successfully completes,&amp;nbsp; Central does some characteristics&amp;nbsp; read/write and then disconnects.&amp;nbsp; This process is run in a loop.&amp;nbsp; &amp;nbsp;My problem is, after the first run,&amp;nbsp; pairing never completes, ie&amp;nbsp; I never see pairing_complete callback being&amp;nbsp; called.&amp;nbsp; &amp;nbsp;So I&amp;#39;m guessing that I need to do something else to clear old pairing info.&amp;nbsp; Any idea how I can do that ?&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Many thanks,&lt;/p&gt;
&lt;p&gt;E.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to initiate BLE pairing manually</title><link>https://devzone.nordicsemi.com/thread/362833?ContentTypeID=1</link><pubDate>Mon, 11 Apr 2022 11:49:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4f863a47-04cd-4bf0-a7b4-622bb9309ff1</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;It is generally recommended to let the central initiate the pairing request, or at least, give it a chance to send it first. From the &amp;quot;&lt;a href="https://developer.apple.com/accessories/Accessory-Design-Guidelines.pdf"&gt;Accessory Design&lt;/a&gt;&lt;br /&gt;&lt;a href="https://developer.apple.com/accessories/Accessory-Design-Guidelines.pdf"&gt;Guidelines for Apple Devices&lt;/a&gt;&amp;quot; document:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;em&gt;40.10 Pairing&lt;/em&gt;&lt;br /&gt;&lt;em&gt;The accessory should not request pairing until an ATT request is rejected using the Insufficient&lt;/em&gt;&lt;br /&gt;&lt;em&gt;Authentication error code. See the Bluetooth 4.0 specification, Volume 3, Part F, Section 4 for details.&lt;/em&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;br /&gt;&lt;em&gt;If, for security reasons, the accessory requires a bonded relationship with the Central, the Peripheral&lt;/em&gt;&lt;br /&gt;&lt;em&gt;should reject the ATT request using the Insufficient Authentication error code, as appropriate. As a&lt;/em&gt;&lt;br /&gt;&lt;em&gt;result, the device may proceed with the necessary security procedures.&lt;/em&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;em&gt;Similarly, if the device acts as a Central and a GATT server, it may reject an ATT request using the&lt;/em&gt;&lt;br /&gt;&lt;em&gt;Insufficient Authentication error code. The accessory should initiate the security procedure for pairing&lt;/em&gt;&lt;br /&gt;&lt;em&gt;in response.&lt;/em&gt;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;br /&gt;&lt;em&gt;Pairing may require user authorization depending on device. Once an accessory is paired with a device,&lt;/em&gt;&lt;br /&gt;&lt;em&gt;it shall retain the distributed keys of both central and peripheral for future use. If the pairing is no longer&lt;/em&gt;&lt;br /&gt;&lt;em&gt;required, the accessory shall delete both sets of keys.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The Insufficient Authentication error code is returned when the GATT client tries to read a characteristic that has the security level set to a level that requires authentication. The user will automatically get a pairing popup if they use iOS.&lt;/p&gt;
&lt;p&gt;Characteristic read and write permissions (i.e. security level) is configured when you initialize the service. Like here for the HIDS service: &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/35f91d3151abfaddf60d826ed87c91cfa81773a5/subsys/bluetooth/services/hids.c#L751"&gt;https://github.com/nrfconnect/sdk-nrf/blob/35f91d3151abfaddf60d826ed87c91cfa81773a5/subsys/bluetooth/services/hids.c#L751&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;But to answer your question, it should be possible to issue a security request from the peripheral by calling the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/zephyr/reference/bluetooth/connection_mgmt.html#c.bt_conn_set_security"&gt;bt_conn_set_security()&lt;/a&gt; function, or by enabling the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/kconfig/CONFIG_BT_GATT_AUTO_SEC_REQ.html"&gt;CONFIG_BT_GATT_AUTO_SEC_REQ&lt;/a&gt; option.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>