<?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>Peer Manager fails to save bond</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/36051/peer-manager-fails-to-save-bond</link><description>I am working on a BLE peripheral (nRF52832 &amp;amp; SDK 15) which uses the Peer Manager to handle encryption and bonding to a previously existing central device. Sometimes bonding works, but often I am seeing a failure mode where the encryption and bonding process</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 09 Jul 2018 23:50:44 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/36051/peer-manager-fails-to-save-bond" /><item><title>RE: Peer Manager fails to save bond</title><link>https://devzone.nordicsemi.com/thread/139480?ContentTypeID=1</link><pubDate>Mon, 09 Jul 2018 23:50:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:25a57689-0970-4353-b49d-3f3dcc92b975</guid><dc:creator>darrenji</dc:creator><description>&lt;p&gt;One can use the same construct to wait for the peer manager to init fds, and then init locally. &amp;nbsp;This seems... awkward. &amp;nbsp;Is the best practice to assume fds has been initialized by the peer manager and just not do it if the app is going to make fds calls itself?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    peer_manager_init();

    wait_for_fds_ready();

    NRF_LOG_INFO(&amp;quot;App Initializing fds...&amp;quot;);
    m_fds_initialized = false;

    err_code = fds_init();
    APP_ERROR_CHECK(err_code);

    wait_for_fds_ready();
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Peer Manager fails to save bond</title><link>https://devzone.nordicsemi.com/thread/139470?ContentTypeID=1</link><pubDate>Mon, 09 Jul 2018 21:07:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:60fdceb8-f06f-4325-b570-854c84ff9808</guid><dc:creator>darrenji</dc:creator><description>&lt;p&gt;Apparently there is more to this, because when I init fds in my own code, it prevents fds from working. &amp;nbsp;If I don&amp;#39;t init, it works fine. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**@brief   Wait for fds to initialize. */
static void wait_for_fds_ready(void)
{
    while (!m_fds_initialized)
    {
        sd_app_evt_wait();
    }
}

    err_code = fds_init();/    APP_ERROR_CHECK(err_code);

    /* Wait for fds to initialize. */
    wait_for_fds_ready();
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I took this directly from fds SDK example.&lt;/p&gt;
&lt;p&gt;Seems like still there is something wrong if fds can&amp;#39;t properly handle double-init and fails silently.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Peer Manager fails to save bond</title><link>https://devzone.nordicsemi.com/thread/139308?ContentTypeID=1</link><pubDate>Fri, 06 Jul 2018 17:32:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f186a040-7e6e-402b-a2c2-6f9f59efb5cd</guid><dc:creator>darrenji</dc:creator><description>&lt;p&gt;OK I finally figured out the problem, and realize now that I should have started with this approach. &amp;nbsp;I went back in the git history to the very first version of my app that claimed to be able to bond with the central and found that it still worked. &amp;nbsp;So I tried different commits binary search style until I found the one that broke fds. &amp;nbsp;It turns out to be makefile related. &amp;nbsp;About a month ago, to try to reduce the makefile size and&amp;nbsp;complexity (and the code size), I went through and removed everything that didn&amp;#39;t break the build. &amp;nbsp;It turns out that the application needs&lt;/p&gt;
&lt;p&gt;&lt;span class="Apple-converted-space"&gt;&amp;nbsp; &lt;/span&gt;$(SDK_ROOT)/components/softdevice/common/nrf_sdh_soc.c \&lt;/p&gt;
&lt;p&gt;even though the app will compile&amp;nbsp;and run without it and generates no errors or warnings.&lt;/p&gt;
&lt;p&gt;When I put that file back in the build, all of my fds&amp;nbsp;problems went away.&lt;/p&gt;
&lt;p&gt;If this code is required for proper functioning, it seems like there should be some warning generated if you remove it.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Peer Manager fails to save bond</title><link>https://devzone.nordicsemi.com/thread/139298?ContentTypeID=1</link><pubDate>Fri, 06 Jul 2018 15:29:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b3ab9732-c408-41ef-956c-f9d8c117bee6</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Darren,&lt;/p&gt;
&lt;p&gt;The connection parameter looks fine.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you send a simplified version of your peripheral that reproduce the issue. Or you can modify the proximity application to add&amp;nbsp; some fds command to store some data. Similar to what we have &lt;a href="https://github.com/NordicPlayground/nRF5-flash-storage-examples/tree/master/fds_example"&gt;here&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Peer Manager fails to save bond</title><link>https://devzone.nordicsemi.com/thread/139289?ContentTypeID=1</link><pubDate>Fri, 06 Jul 2018 14:42:10 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c280eefb-ca88-4f23-b9bc-6b9f10b8a5e6</guid><dc:creator>darrenji</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Here are the settings I&amp;#39;m using now&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define MIN_CONN_INTERVAL               MSEC_TO_UNITS(7.5, UNIT_1_25_MS)          /**&amp;lt; Minimum acceptable connection interval. */
#define MAX_CONN_INTERVAL               MSEC_TO_UNITS(30, UNIT_1_25_MS)         /**&amp;lt; Maximum acceptable connection interval. */
#define SLAVE_LATENCY                   0                                       /**&amp;lt; Slave latency. */
#define CONN_SUP_TIMEOUT                MSEC_TO_UNITS(4000, UNIT_10_MS)         /**&amp;lt; Connection supervisory time-out (4 seconds). */
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t think this is the root of the problem though. &amp;nbsp;What I discovered yesterday is that my app can use fds to store data, if I *don&amp;#39;t* enable the soft device first... the filesystem events flow as expected and the write succeeds. &amp;nbsp;However, when the soft device is enabled, my app cannot write data with fds, even if there is no active connection to a central. &amp;nbsp;This is very weird indeed.&lt;/p&gt;
&lt;p&gt;It would be quite a lot of work to modify our central, so I&amp;#39;m hoping I can find the answer another way.&lt;/p&gt;
&lt;p&gt;Searching online, I&amp;#39;ve seen many references to this problem from an earlier version of the SDK. &amp;nbsp;For example:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/22265/can-t-get-a-callback-from-fds-no-matter-what---help"&gt;this&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/25954/nrf51-sdk-12-fds-issue-s#post-id-173330"&gt;this&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/13857/not-getting-a-write-call-back-with-fds"&gt;this&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;But with the current SDK&amp;nbsp;doesn&amp;#39;t appear to work this way since there isn&amp;#39;t a&amp;nbsp;&lt;span&gt;softdevice_sys_evt_handler_set().&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Peer Manager fails to save bond</title><link>https://devzone.nordicsemi.com/thread/139204?ContentTypeID=1</link><pubDate>Fri, 06 Jul 2018 08:53:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3dda8efc-564c-47b7-8c49-7514595cc979</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Darren,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It&amp;#39;s a very strange issue that you have. Could you try to use the same central to test with the unmodified ble_app_proximity ? I would suggest to try with a fresh copy of the SDK. Maybe you need to modify your central a little bit to work with ble_app_proximity.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What else you can try is to use a phone (use nRFConnect app) to connect to your device and bond to the device to see if bond info is stored or not.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Which connection parameter your central use ? We have &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/32061/fstorage-timeout-error/127133#127133"&gt;this case &lt;/a&gt;where flash write api failed when the connection timeout was too short, maybe it&amp;#39;s related ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;However, in your case , the API failed silently without anytime out, this is very strange. If you can provide a simple central and peripheral code that can reproduce the issue, it would be great help.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regarding the qwr module, it&amp;#39;s queued write assistance module we add to all the examples. It&amp;#39;s not needed for all application, only needed if queued write is used. You can remove it.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Peer Manager fails to save bond</title><link>https://devzone.nordicsemi.com/thread/139162?ContentTypeID=1</link><pubDate>Thu, 05 Jul 2018 20:55:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f3601be-110c-4ce7-a52a-ca68b5b3f6eb</guid><dc:creator>darrenji</dc:creator><description>&lt;p&gt;I have spent many hours tracing the execution of fds and can now see what is failing, but not why. &amp;nbsp;When I write my config data, the write request is passed down into nrf_fstorage_sd.c. &amp;nbsp;The queue_process() function tries to write the header (FDS_OP_WRITE_HEADER_BEGIN) and calls&amp;nbsp;write_execute(). &amp;nbsp;The&amp;nbsp;write_execute() function calls sd_flash_write() which returns NRF_SUCCESS, but the soft device doesn&amp;#39;t generate an event, so the fstorage state machine cannot continue to process the write. There is a comment in nrf_fstorage_sd.c in the switch() case that handles the return value from write_execute():&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;            /* The operation was accepted by the SoftDevice.
             * If the SoftDevice is enabled, wait for a system event. Otherwise,
             * the SoftDevice call is synchronous and will not send an event so we simulate it. */
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Because the soft device is enabled, the code is waiting for a system event, and never gets one.&lt;/p&gt;
&lt;p&gt;I did the same trace exercise when pairing, and the store of the bond fails for the same reason, no event is generated.&lt;/p&gt;
&lt;p&gt;Do you have any advice about how to figure out why the soft device is not posting file system events but seems to otherwise work?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Peer Manager fails to save bond</title><link>https://devzone.nordicsemi.com/thread/139153?ContentTypeID=1</link><pubDate>Thu, 05 Jul 2018 17:15:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:568b7bd1-f1eb-452a-852f-7721f5703c46</guid><dc:creator>darrenji</dc:creator><description>&lt;p&gt;I have one more specific question... I based my app on the proximity app so the code is basically identical with respect to pairing/bonding. &amp;nbsp;One question I have is why when the&amp;nbsp;BLE_GAP_EVT_CONNECTED event happens, nrf_ble_qwr_conn_handle_assign() is called. &amp;nbsp;There are no comments in the example that explain why it would need queued writes. &amp;nbsp;There are no other references to qwr in the app. &amp;nbsp;Is it necessary for something else in the sd? &amp;nbsp;If I remove the calls and take queued write manager out of the makefile, no symbols are missing. &amp;nbsp;I&amp;#39;ve searched the sdk and online but can&amp;#39;t find any obvious explanations. &amp;nbsp;I&amp;#39;m not using long writes in any characteristics.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Peer Manager fails to save bond</title><link>https://devzone.nordicsemi.com/thread/139151?ContentTypeID=1</link><pubDate>Thu, 05 Jul 2018 16:33:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:92ad8479-a0cb-4515-9777-02c20b6e0875</guid><dc:creator>darrenji</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Yes I do have SEC_PARAM_BOND = 1. &amp;nbsp;I&amp;#39;m not pairing to a phone, but to our own device. &amp;nbsp;Our Central device has been working for 3 years bonding successfully to another peripheral.&lt;/p&gt;
&lt;p&gt;What I&amp;#39;m seeing with the nRF is that fds fails silently. &amp;nbsp;The high level call to write returns SUCCESS, but the actual asynchronous write to flash never happens and no event or error is reported. I&amp;#39;ve seen this both with the peer manager&amp;#39;s internal write to save the bond data, and with my own call to fds to write config data.&lt;/p&gt;
&lt;p&gt;It seems like no matter what I&amp;#39;m doing, fds shouldn&amp;#39;t fail silently.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Peer Manager fails to save bond</title><link>https://devzone.nordicsemi.com/thread/139065?ContentTypeID=1</link><pubDate>Thu, 05 Jul 2018 08:12:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ac0d5a62-bdd4-45ba-97c1-3f3d3fb8be4b</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Darrenji&lt;/p&gt;
&lt;p&gt;Sorry that I misunderstood your issue.&lt;/p&gt;
&lt;p&gt;I assume you have set&amp;nbsp;SEC_PARAM_BOND = 1 to enable bonding, not just pairing.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I would suggest you to use the same phone to test with one of our example, the ble_app_proximity for example to make sure the central handle bonding properly.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t think it would be a problem storage your own data with fds and have the peer manager working at the same time.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Please enable debugging to get more log from the peer manager unit. You need to add DEBUG in the&amp;nbsp;preprocessor symbols and enable logging either by RTT or UART.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Peer Manager fails to save bond</title><link>https://devzone.nordicsemi.com/thread/139016?ContentTypeID=1</link><pubDate>Wed, 04 Jul 2018 16:31:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:670e0384-2b17-4f39-abad-1858ce907e32</guid><dc:creator>darrenji</dc:creator><description>&lt;p&gt;Hello and thanks for the quick response.&lt;/p&gt;
&lt;p&gt;I have set allow_repairing to true during my testing and it doesn&amp;#39;t make any difference. &amp;nbsp;In any case it shouldn&amp;#39;t matter because the problem is not that the pairing fails, it&amp;#39;s that the key data isn&amp;#39;t being saved. &amp;nbsp;In other words, I can delete all bonds on the nRF device (so it should not recognize any previously paired devices) and still when creating a new bond the key data isn&amp;#39;t saved.&lt;/p&gt;
&lt;p&gt;My steps are:&lt;/p&gt;
&lt;p&gt;1. Delete all bonds on both central and peripheral&amp;nbsp;&lt;/p&gt;
&lt;p&gt;2. Pairing initiated and succeeds, get a correct and working connection.&lt;/p&gt;
&lt;p&gt;3. power cycle the peripheral; on reconnect peripheral won&amp;#39;t connect with error &lt;span&gt;PM_CONN_SEC_ERROR_PIN_OR_KEY_MISSING&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;4.&amp;nbsp;back to step 1 above.&lt;/p&gt;
&lt;p&gt;So my issue is not that pairing fails, it&amp;#39;s that re-connecting after pairing fails because the peripheral didn&amp;#39;t save the bond even though&amp;nbsp;&lt;span&gt;write_buf_store() is being called after pairing.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;As I mentioned, my app is also using fds. &amp;nbsp;Is there anything I need to be sure to do or not do when using fds in order to not interfere&amp;nbsp;the with Peer Manager&amp;#39;s use of fds?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Peer Manager fails to save bond</title><link>https://devzone.nordicsemi.com/thread/138954?ContentTypeID=1</link><pubDate>Wed, 04 Jul 2018 12:16:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:57e93c3a-1b8a-46a6-a3f9-cea7bc3c518d</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;We would need to know what you set in your&amp;nbsp;conn_sec_config when calling&amp;nbsp;pm_conn_sec_config_reply().&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you have a look at our example, ble_app_proximity for example you can see we set allow_repairing = false inside pm_evt_handler():&amp;nbsp;&lt;/p&gt;
&lt;p&gt;case PM_EVT_CONN_SEC_CONFIG_REQ:&lt;br /&gt; {&lt;br /&gt; // Reject pairing request from an already bonded peer.&lt;br /&gt; pm_conn_sec_config_t conn_sec_config = {.allow_repairing = false};&lt;br /&gt; pm_conn_sec_config_reply(p_evt-&amp;gt;conn_handle, &amp;amp;conn_sec_config);&lt;br /&gt; } break;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This mean, if the central lose bond information, the device&amp;nbsp;would reject re-bonding. The reason for this is to avoid attacker force a device to delete original bond information and force a new bond where they can be sniff the bonding process or to be MITM.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you set allow_repairing = true, the device supposed to replace old bond information with new one. I would need you to reproduce the issue with our example so we can try here.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Peer Manager fails to save bond</title><link>https://devzone.nordicsemi.com/thread/138867?ContentTypeID=1</link><pubDate>Wed, 04 Jul 2018 01:05:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8394a5fd-df48-4eb0-9808-2611aeedb2c9</guid><dc:creator>darrenji</dc:creator><description>&lt;p&gt;I fixed this in my code, hoping that would solve the problem:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/35426/fds-example-conflicts-with-peer-manager"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/35426/fds-example-conflicts-with-peer-manager&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;But after erasing all of flash and reprogramming the soft device, no luck.&lt;/p&gt;
&lt;p&gt;I forgot to mention originally that I&amp;#39;m using fds to save a few bytes of calibration data, and there appears to be an order-of-init issue with fds. &amp;nbsp;if I init BLE and&amp;nbsp;peer manager before I init ads, I can&amp;#39;t write to flash successfully. &amp;nbsp;But if I init fds first it works. &amp;nbsp;In neither case does the peer manager save data every time. &amp;nbsp;oy.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>