8 years, 5 months ago.

BLE_API and starting DFU on button press on powerup

In order to improve the security of DFU I have modified BLE.cpp and BLE.h as follows

BLE.H

was     ble_error_t init();
now     ble_error_t init(bool startDFU = true);

BLE.cpp

BLE::init(bool startDFU)
{
    ble_error_t err = transport->init();
    if (err != BLE_ERROR_NONE) {
        return err;
    }

    /* Platforms enabled for DFU should introduce the DFU Service into
     * applications automatically. */
#if defined(TARGET_OTA_ENABLED)
    if (startDFU){
       static DFUService dfu(*this); // defined static so that the object remains alive
    }
#endif // TARGET_OTA_ENABLED

    return BLE_ERROR_NONE;
}

The default functionality of BLE init is unchanged but now the user's application can decide if it wants to start the DFU service. This means that when calling ble.init() you can either have no parameter as usual and DFU service will start, have init(true) and DFU service will start or init(false) and DFU service will not start.

Testing for a button press at power up and passing the result as a parameter to init() can make the DFU service only start when a button is pressed on power up.

This will enhance the security of the DFU service.

Be the first to answer this question.