<?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>Bonding lost on Android 8.1 when reconnecting from the central</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/58750/bonding-lost-on-android-8-1-when-reconnecting-from-the-central</link><description>Hi, 
 I&amp;#39;m developping an application for nRF52840 as a BLE central. It is supposed to connect to an Android device (BLE peripheral) using a bond (encrypted connection with keys stored on both sides). The Android device implements a GATT service with readable</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 12 Mar 2020 08:40:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/58750/bonding-lost-on-android-8-1-when-reconnecting-from-the-central" /><item><title>RE: Bonding lost on Android 8.1 when reconnecting from the central</title><link>https://devzone.nordicsemi.com/thread/239462?ContentTypeID=1</link><pubDate>Thu, 12 Mar 2020 08:40:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e5ca91c0-4a23-40ba-a8e3-1715816cd952</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Look at how this is done in this example. You need to change the&amp;nbsp;hrs_c_init() with your custom service_c. Also, update the discovery handler to handle your service.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding lost on Android 8.1 when reconnecting from the central</title><link>https://devzone.nordicsemi.com/thread/239455?ContentTypeID=1</link><pubDate>Thu, 12 Mar 2020 08:12:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b0667e0c-4557-4503-afca-95ea82b0d1b4</guid><dc:creator>cecile</dc:creator><description>&lt;p&gt;Hello Edvin and thank you for you reply.&lt;br /&gt;&lt;br /&gt;Actually I can connect to the peripheral, I added a target name&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static char const m_target_periph_name[] = &amp;quot;N80&amp;quot;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So that my central can contact to the peripheral (the tablet):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void on_adv_report(ble_gap_evt_adv_report_t const * p_adv_report)
{
    if (strlen(m_target_periph_name) != 0)
    {
        if (ble_advdata_name_find(p_adv_report-&amp;gt;data.p_data,
                                  p_adv_report-&amp;gt;data.len,
                                  m_target_periph_name))
        {
            do_connect = true;
            printf(&amp;quot;Name match send connect_request.\n&amp;quot;);
        }
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I can connected and start discovering the services:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    ret_code_t            err_code;
    ble_gap_evt_t const * p_gap_evt = &amp;amp;p_ble_evt-&amp;gt;evt.gap_evt;

    switch (p_ble_evt-&amp;gt;header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
        {
            printf(&amp;quot;Connected.\n&amp;quot;);

            // Discover peer&amp;#39;s services.
            err_code = ble_db_discovery_start(&amp;amp;m_db_disc, p_ble_evt-&amp;gt;evt.gap_evt.conn_handle);
            APP_ERROR_CHECK(err_code);

            err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
            APP_ERROR_CHECK(err_code);

            if (ble_conn_state_central_conn_count() &amp;lt; NRF_SDH_BLE_CENTRAL_LINK_COUNT)
            {
                scan_start();
            }
        } break;
    }
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But now I&amp;#39;d like to be able to discover the service offered by the peripheral to be able to test:&lt;/p&gt;
&lt;p&gt;* the securing of the connection&lt;/p&gt;
&lt;p&gt;* write and read to/from the secured characteristics of the peripheral&amp;#39;s GATT service&lt;/p&gt;
&lt;p&gt;Thank you in advance for you help,&lt;/p&gt;
&lt;p&gt;C&amp;eacute;cile&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding lost on Android 8.1 when reconnecting from the central</title><link>https://devzone.nordicsemi.com/thread/239398?ContentTypeID=1</link><pubDate>Wed, 11 Mar 2020 16:27:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a196f96b-aecc-403e-a52c-70ef1d1a8fd0</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;That is correct, you must change one of these, so that the peripheral is advertising with the service that the central is looking for.&lt;/p&gt;
&lt;p&gt;However, it may be a bit more complex than that. The ble_app_hrs_c is looking for the Heart rate UUID, which is a short UUID (standardized by Bluetooth).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Perhaps it is actually easier to start with the ble_app_multilink_central example, which is looking for an advertisement name (&amp;quot;Nordic_Blinky&amp;quot;).&lt;/p&gt;
&lt;p&gt;The other alternative is to don&amp;#39;t care about the scan_filters, and find some specific bytes in the advertising packet yourself that you can check before connecting. You can add the&amp;nbsp;BLE_GAP_EVT_ADV_REPORT event to your ble_evt_handler in main.c.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding lost on Android 8.1 when reconnecting from the central</title><link>https://devzone.nordicsemi.com/thread/239381?ContentTypeID=1</link><pubDate>Wed, 11 Mar 2020 15:33:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ac3b537-680b-4d22-a2d0-003e0b0dc3cd</guid><dc:creator>cecile</dc:creator><description>&lt;p&gt;Hello Edvin,&lt;br /&gt;&lt;br /&gt;Could you please help me understand how I can modify the base UUID of the service the central is looking for with the example ble_app_hrsc ? I&amp;#39;d like to make as few modifications as possible to test with my tablet and being able to compare this method with the one I have now.&lt;/p&gt;
&lt;p&gt;Here is what I&amp;#39;m used to configure with the current implementation:&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define PERIPHERAL_UUID_BASE {0x23, 0xD1, 0xBC, 0xEA, 0x5F, 0x78, 0x23, 0x15, 0xDE, 0xEF, 0x12, 0x12, 0x00, 0x00, 0x00, 0x00}

ble_uuid128_t peripheral_uuid_base = {PERIPHERAL_UUID_BASE};

err_code err_code = sd_ble_uuid_vs_add(&amp;amp;peripheral_uuid_base, &amp;amp;p_service_c-&amp;gt;uuid_type);
VERIFY_SUCCESS(err_code);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If I&amp;#39;m not wrong, I need to change the peripheral&amp;#39;s 128bits- UUID to match the one the central is looking for, or change the 128-bits UUID the central is looking for when discovering the services offered by the peripheral&amp;#39;s GATT server with the one configured in the tablet.&lt;br /&gt;&lt;br /&gt;Thank you in advance for your help!&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;C&amp;eacute;cile&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding lost on Android 8.1 when reconnecting from the central</title><link>https://devzone.nordicsemi.com/thread/238996?ContentTypeID=1</link><pubDate>Tue, 10 Mar 2020 08:23:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:85b4f5c9-ae79-4f93-a06f-3f1d1f3d3a45</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;I see. The reason I asked is because the phone will often act as a central in a BLE connection. FYI, it is possible to be central in one connection and peripheral in another. The reason the phone is often the central is because scanning draws a lot more current than advertising. But I guess if you are scanning for other peripherals as well, that wouldn&amp;#39;t really make a huge difference.&lt;/p&gt;
&lt;p&gt;Appart from if it is actually a bug in the Bluetootoh FW on the tablet.&lt;/p&gt;
&lt;p&gt;Try out the ble_app_hrsc example, and let me know how it behaves.&lt;/p&gt;
&lt;p&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><item><title>RE: Bonding lost on Android 8.1 when reconnecting from the central</title><link>https://devzone.nordicsemi.com/thread/238888?ContentTypeID=1</link><pubDate>Mon, 09 Mar 2020 15:17:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a1d58e9b-876c-4bac-b61b-563a4616b646</guid><dc:creator>cecile</dc:creator><description>&lt;p&gt;Hello Edvin,&lt;/p&gt;
&lt;p&gt;I&amp;#39;m about to test this example as soon as possible and let you know how it behaves.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m afraid I did not understand the second part of your response. The Android device (Fieldbook tablet) is a peripheral here and the nRF52840 is the central.&lt;/p&gt;
&lt;p&gt;It has been designed that way because other devices can connect to this nRF52840. Several peripherals (the tablet and other boards that embed a nRF52840 chip) can connect to the master board (central).&lt;/p&gt;
&lt;p&gt;Thank you,&lt;/p&gt;
&lt;p&gt;C&amp;eacute;cile&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding lost on Android 8.1 when reconnecting from the central</title><link>https://devzone.nordicsemi.com/thread/238875?ContentTypeID=1</link><pubDate>Mon, 09 Mar 2020 14:41:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5b9c5db6-1e0c-4eb1-9e51-737830e10558</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello Cécile,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;It looks like like in packet 390 that the master doesn&amp;#39;t support pairing.&lt;/p&gt;
&lt;p&gt;Can you please try one of the other examples in the SDK that supports pairing? You can test the ble_app_hrs_c. Does the phone behave similar there?&lt;/p&gt;
&lt;p&gt;It may be a bug in the android OS. The phone being a central is not a common use case, so it may not have been discovered in that particular phone. Is there any particular reason for why the phone is the peripheral/slave, and not the other way around?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding lost on Android 8.1 when reconnecting from the central</title><link>https://devzone.nordicsemi.com/thread/238850?ContentTypeID=1</link><pubDate>Mon, 09 Mar 2020 13:52:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:72ce96df-a63a-4be9-9619-a7d5e6ee8f7c</guid><dc:creator>cecile</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;br /&gt;Many thanks for your reply and recommendations!&lt;br /&gt;&lt;br /&gt;The Android device I&amp;#39;m using is a Fieldbook N80 rugged tablet, running Android 8.1. I&amp;#39;ve also tried using a Nexus 6P but there were many issues (the phone gets disconnected just after the board connects to it for instance) and from what I read online, the BLE behavior can be quite different depending on the manufacturer so I decided to focus on the N80, which is the only target for my project.&lt;/p&gt;
&lt;p&gt;I looked at several examples including the ble_app_gls but I didn&amp;#39;t run them since in my case the Android device is a peripheral (I thought it would be too different to bring something interesting to the debate). You think I should try anyway?&lt;/p&gt;
&lt;p&gt;I setup the nRF Sniffer and captured the BLE trafic including the following steps:&lt;/p&gt;
&lt;p&gt;* peripheral (Android tablet) advertising&lt;/p&gt;
&lt;p&gt;* central connection request&lt;/p&gt;
&lt;p&gt;* pairing/bonding negociation&lt;/p&gt;
&lt;p&gt;* bonding finished&lt;/p&gt;
&lt;p&gt;* after a while, reboot of the board&lt;/p&gt;
&lt;p&gt;* peripheral (Android tablet) advertising&lt;/p&gt;
&lt;p&gt;* central connection request&lt;/p&gt;
&lt;p&gt;I&amp;#39;m joining the capture file in case you see something interesting.&lt;/p&gt;
&lt;p&gt;What I saw is that during the second connection (the devices are supposed to be bonded already), the slave (the tablet) sends a LL_REJECT_IND during the securing of the connection, with error code 0x06, &amp;quot;PIN or key missing&amp;quot;. I don&amp;#39;t understand this error because with the &amp;quot;Just works&amp;quot; pairing method, no PIN/key shall be needed.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;3541	105.973607	Master_0xb927e11f	Slave_0xb927e11f	LE LL	49	Control Opcode: LL_ENC_REQ
3544	105.981600	Slave_0xb927e11f	Master_0xb927e11f	LE LL	39	Control Opcode: LL_ENC_RSP
3546	105.988594	Slave_0xb927e11f	Master_0xb927e11f	LE LL	28	Control Opcode: LL_REJECT_IND
3551	106.018568	Master_0xb927e11f	Slave_0xb927e11f	LE LL	38	Control Opcode: LL_CONNECTION_UPDATE_REQ&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Do you see something in the ble exchange that would let the Android device &amp;#39;think&amp;#39; the pairing method implies a key?&lt;/p&gt;
&lt;p&gt;Thank you in advance!&lt;/p&gt;
&lt;p&gt;C&amp;eacute;cile&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/full_5F00_exhange_5F00_bonding_5F00_plus_5F00_reconnection.pcapng"&gt;devzone.nordicsemi.com/.../full_5F00_exhange_5F00_bonding_5F00_plus_5F00_reconnection.pcapng&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Bonding lost on Android 8.1 when reconnecting from the central</title><link>https://devzone.nordicsemi.com/thread/238566?ContentTypeID=1</link><pubDate>Fri, 06 Mar 2020 14:54:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eae6160b-4493-416c-ade4-c6399dd64fda</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello Cécile,&lt;/p&gt;
&lt;p&gt;Have you tried to do this with other phones, or just one?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And have you tried other examples from the SDK? One of them that should work out of the box is the example found in SDK\examples\ble_peripheral\ble_app_gls. This is an example that uses pairing and bonding, and you should get the 6-digit numerical pairing key on the first connect, and not on the second (because they are bonded).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So can you try the following:&lt;/p&gt;
&lt;p&gt;Another Android/iPhone with your project. What is the behavior like?&lt;/p&gt;
&lt;p&gt;Another example from the SDK (ble_app_gls) with the same phone you are currently using.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Do any of them behave differently?&lt;/p&gt;
&lt;p&gt;I assume that you have added the peer manager into your project? Or was it there by default (did you start with any of the examples from the SDK)?&lt;/p&gt;
&lt;p&gt;It looks like, from your snippets and the description that you give, that things are set up correctly from the nRF project. Is it possible to do a sniffer trace? Do you have a spare Development Kit that you can use as the sniffer?&lt;/p&gt;
&lt;p&gt;The &lt;a href="https://www.nordicsemi.com/Software-and-tools/Development-Tools/nRF-Sniffer-for-Bluetooth-LE" rel="noopener noreferrer" target="_blank"&gt;nRF Sniffer&lt;/a&gt; is a quite useful tool that you can use to sniff BLE connections. I just wanted to check whether there is anything suspicious in the packets over the air from any of the devices.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;As you say, since the Android API tells you that the device is bonded, everything should be ok, but perhaps the phone is reacting to something suspicious from the nRF side.&lt;/p&gt;
&lt;p&gt;Also, what phone model do you use? And what Android OS version?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And by the way, when you are trying to sniff the connection, set sec_params.lesc back to 0, or else the link is not possible to sniff.&lt;/p&gt;
&lt;p&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><item><title>RE: Bonding lost on Android 8.1 when reconnecting from the central</title><link>https://devzone.nordicsemi.com/thread/238343?ContentTypeID=1</link><pubDate>Thu, 05 Mar 2020 14:58:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3e1db8d9-5d6e-4245-98f8-edc247d1216f</guid><dc:creator>cecile</dc:creator><description>&lt;p&gt;One more precision: I tried to enable the pairing parameter lesc (&amp;quot;sec_param.lesc&amp;nbsp; = 1;&amp;quot; at line 7 in the first code section), but the behavior was the same.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>