<?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>DFU with extra authentication</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/55597/dfu-with-extra-authentication</link><description>Hello, I want to put extra authentication when device is preparing for boot loader. I found callback &amp;quot;ble_dfu_evt_handler&amp;quot;. I think inside case BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE , I can add that condition like below: 
 
 I am unable to find api to</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 02 Jan 2020 12:21:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/55597/dfu-with-extra-authentication" /><item><title>RE: DFU with extra authentication</title><link>https://devzone.nordicsemi.com/thread/227225?ContentTypeID=1</link><pubDate>Thu, 02 Jan 2020 12:21:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0c32e757-1c08-4f23-b592-9a25409dc6ba</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Great! Glad to hear that your issue has been solved.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU with extra authentication</title><link>https://devzone.nordicsemi.com/thread/227222?ContentTypeID=1</link><pubDate>Thu, 02 Jan 2020 11:18:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9ae0f15e-0786-4fd7-b9b5-923938ff6d27</guid><dc:creator>chandan</dc:creator><description>&lt;p&gt;Yes&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU with extra authentication</title><link>https://devzone.nordicsemi.com/thread/227202?ContentTypeID=1</link><pubDate>Thu, 02 Jan 2020 09:15:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:192ba9a8-1b48-4d89-84ff-77b63657caa9</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Hi Chandan, so calling&amp;nbsp;&lt;span&gt;sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_AUTHENTICATION_FAILURE)&amp;nbsp;before ble_advertising_start() resolves the issue with error code 0x12?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU with extra authentication</title><link>https://devzone.nordicsemi.com/thread/226858?ContentTypeID=1</link><pubDate>Thu, 26 Dec 2019 09:18:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9cd15730-8225-473b-9e19-43fe3c20f6db</guid><dc:creator>chandan</dc:creator><description>&lt;p&gt;Hi, For disconnecting I am using&amp;nbsp;sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_AUTHENTICATION_FAILURE) nut getting error as 0x12&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU with extra authentication</title><link>https://devzone.nordicsemi.com/thread/225600?ContentTypeID=1</link><pubDate>Mon, 16 Dec 2019 11:23:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:90f17b36-c2fd-4182-88a2-3d899b18fcde</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;0x12 corresponds to NRF_ERROR_CONN_COUNT. Looking at the documentation for&amp;nbsp;sd_ble_gap_adv_start which is called by&amp;nbsp;&lt;span&gt;ble_advertising_start&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;@retval ::NRF_ERROR_CONN_COUNT The limit of available connections for this connection configuration
* tag has been reached; connectable advertiser cannot be started.
* To increase the number of available connections,
* use @ref sd_ble_cfg_set with @ref BLE_GAP_CFG_ROLE_COUNT or @ref BLE_CONN_CFG_GAP.&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So you are in a connection when calling&amp;nbsp;&lt;span&gt;ble_advertising_start() and the&amp;nbsp;NRF_SDH_BLE_PERIPHERAL_LINK_COUNT is set 1. So if you want to advertise, you will either have to disconnect the existing connection or increase the peripheral link count. Note you also have to increase the&amp;nbsp;NRF_SDH_BLE_TOTAL_LINK_COUNT if you go for the second option.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU with extra authentication</title><link>https://devzone.nordicsemi.com/thread/225595?ContentTypeID=1</link><pubDate>Mon, 16 Dec 2019 11:07:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5227be57-29ef-4ee5-ba0f-ba18bf020ea1</guid><dc:creator>chandan</dc:creator><description>&lt;p&gt;I am getting error number 0x12 when calling&amp;nbsp;&lt;span&gt;ble_advertising_start().&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1576494435937v1.png" alt=" " /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU with extra authentication</title><link>https://devzone.nordicsemi.com/thread/225573?ContentTypeID=1</link><pubDate>Mon, 16 Dec 2019 10:24:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ea9c8e88-ad62-46d6-b49e-12b4116dca5d</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;ble_advertising_start() should work just fine.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU with extra authentication</title><link>https://devzone.nordicsemi.com/thread/225528?ContentTypeID=1</link><pubDate>Mon, 16 Dec 2019 05:48:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:70e91712-cde8-473f-bef1-3abaa91ede2c</guid><dc:creator>chandan</dc:creator><description>&lt;p&gt;Thanks, I can find only&amp;nbsp;ble_advertising_start, but don&amp;#39;t think its correct one. Found ble_advertising_restart_without_whitelist&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU with extra authentication</title><link>https://devzone.nordicsemi.com/thread/225384?ContentTypeID=1</link><pubDate>Fri, 13 Dec 2019 13:51:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9171f95f-a5cb-41d5-885d-d7e384ac7707</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;If&amp;nbsp;ble_dfu_buttonless_bootloader_start_prepare returns a non-zero error code, then the&amp;nbsp;&lt;span&gt;ble_dfu_evt_handler() will be called with the as&lt;/span&gt;&amp;nbsp;BLE_DFU_EVT_BOOTLOADER_ENTER_FAILED as the event type.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void on_hvc(ble_evt_t const * p_ble_evt)
{
    uint32_t err_code;
    ble_gatts_evt_hvc_t const * p_hvc = &amp;amp;p_ble_evt-&amp;gt;evt.gatts_evt.params.hvc;

    if (p_hvc-&amp;gt;handle == m_dfu.control_point_char.value_handle)
    {
        // Enter bootloader if we were waiting for reset after hvc indication confimation.
        if (m_dfu.is_waiting_for_reset)
        {
            err_code = ble_dfu_buttonless_bootloader_start_prepare();
            if (err_code != NRF_SUCCESS)
            {
                m_dfu.evt_handler(BLE_DFU_EVT_BOOTLOADER_ENTER_FAILED);
            }
        }
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Hence, you can restart advertisment in&amp;nbsp;ble_dfu_evt_handler() under case BLE_DFU_EVT_BOOTLOADER_ENTER_FAILED:&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU with extra authentication</title><link>https://devzone.nordicsemi.com/thread/225371?ContentTypeID=1</link><pubDate>Fri, 13 Dec 2019 13:15:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1d1da5ef-58b8-4642-8061-6d0261f71b67</guid><dc:creator>chandan</dc:creator><description>&lt;p&gt;I tried below code, when&amp;nbsp;authentication_ok is false,&amp;nbsp; NRF doesn&amp;#39;t start DFU and disconnect device but post NRF stop BLE advertisement. I tried calling&amp;nbsp; event handler post authentication check.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;uint32_t ble_dfu_buttonless_bootloader_start_prepare(void)
{
    uint32_t err_code;

    // Indicate to main app that DFU mode is starting.
    mp_dfu-&amp;gt;evt_handler(BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE);
    
    if(authentication_ok)
    {
        err_code = ble_dfu_buttonless_bootloader_start_finalize();
        return err_code;
    }else
    {
        //Authentication failed. Do not enter bootloader mode
        return NRF_ERROR_FORBIDDEN;
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU with extra authentication</title><link>https://devzone.nordicsemi.com/thread/225345?ContentTypeID=1</link><pubDate>Fri, 13 Dec 2019 12:17:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8b46ab88-dcbf-437f-8f8c-af3bd7fb5553</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Hi Chandan,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;from the point you receive the&amp;nbsp;BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE event, then there is no way to halt the reset process with out modifying the SDK source as&amp;nbsp;ble_dfu_buttonless_bootloader_start_finalize will be called immediately after the evt_handler, i.e.&amp;nbsp;ble_dfu_evt_handler()&amp;nbsp; returns. As you see below&amp;nbsp;ble_dfu_buttonless_bootloader_start_finalize() calls nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_DFU) and there is no API in the power management module to abort this.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t ble_dfu_buttonless_bootloader_start_finalize(void)
{
    uint32_t err_code;

    NRF_LOG_DEBUG(&amp;quot;In ble_dfu_buttonless_bootloader_start_finalize\r\n&amp;quot;);

    err_code = sd_power_gpregret_clr(0, 0xffffffff);
    VERIFY_SUCCESS(err_code);

    err_code = sd_power_gpregret_set(0, BOOTLOADER_DFU_START);
    VERIFY_SUCCESS(err_code);

    // Indicate that the Secure DFU bootloader will be entered
    m_dfu.evt_handler(BLE_DFU_EVT_BOOTLOADER_ENTER);

    // Signal that DFU mode is to be enter to the power management module
    nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_DFU);

    return NRF_SUCCESS;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So its not possible to prevent the reset, but it is possible to make the device boot straight back to the application by calling sd_power_gpregret_clr(0, 0xffffffff) when you get the&amp;nbsp;&amp;nbsp;BLE_DFU_EVT_BOOTLOADER_ENTER event. The GPREGRET register is checked by the bootloader and if it does not contain the&amp;nbsp;BOOTLOADER_DFU_START value, then the bootloader will jump to the application.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Bjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU with extra authentication</title><link>https://devzone.nordicsemi.com/thread/225332?ContentTypeID=1</link><pubDate>Fri, 13 Dec 2019 10:51:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:303d1eb2-4a42-487b-ab48-823a4c68cbb0</guid><dc:creator>chandan</dc:creator><description>&lt;p&gt;Thanks for quick reply.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t want to make change in any SDK file. Its difficult to update same change in all member&amp;#39;s SDK file. Please suggest similar to callback function change.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: DFU with extra authentication</title><link>https://devzone.nordicsemi.com/thread/225330?ContentTypeID=1</link><pubDate>Fri, 13 Dec 2019 10:38:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a42e8af5-51da-45fd-a9ce-d7cb2c9f30ef</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;HI Chandan,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;the&amp;nbsp;BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE event will be generated when&amp;nbsp;ble_dfu_buttonless_bootloader_start_prepare is called.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t ble_dfu_buttonless_bootloader_start_prepare(void)
{
    uint32_t err_code;

    // Indicate to main app that DFU mode is starting.
    mp_dfu-&amp;gt;evt_handler(BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE);

    err_code = ble_dfu_buttonless_bootloader_start_finalize();
    return err_code;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;As you can see&amp;nbsp;ble_dfu_buttonless_bootloader_start_finalize() is called when the evt_handler has returned. So if you want to prevent the device from entering bootloader moder, then you will have to set a flag or similar when the extra authentication fails and then check this in&amp;nbsp;ble_dfu_buttonless_bootloader_start_prepare() after the evt_handler has returned. One way to do this is as follows:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t ble_dfu_buttonless_bootloader_start_prepare(void)
{
    uint32_t err_code;

    // Indicate to main app that DFU mode is starting.
    mp_dfu-&amp;gt;evt_handler(BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE);
    
    if(authentication_ok)
    {
        err_code = ble_dfu_buttonless_bootloader_start_finalize();
        return err_code;
    }else
    {
        //Authentication failed. Do not enter bootloader mode
        return NRF_ERROR_FORBIDDEN;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;/p&gt;
&lt;p&gt;Bjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>