tychovrahe/T3W1/devkit1_with_ble_crypto2
tychovrahe 9 months ago
parent 1a46decd3b
commit 36b4f2f529

@ -109,7 +109,6 @@ CPPPATH_MOD += [
'embed/sdk/nrf52/components/libraries/crypto/backend/nrf_sw',
'embed/sdk/nrf52/modules/nrfx/mdk',
'embed/sdk/nrf52/external/nrf_cc310/include',
'embed/sdk/nrf52/external/nano-pb',
'embed/sdk/nrf52/components/libraries/queue',
'embed/sdk/nrf52/components/libraries/mutex',
'embed/sdk/nrf52/components/libraries/ringbuf',
@ -119,6 +118,7 @@ CPPPATH_MOD += [
'embed/lib',
'vendor/trezor-crypto',
'vendor/nanopb',
]
SOURCE_MOD += [
]
@ -165,8 +165,6 @@ SOURCE_NRFHAL = [
'embed/sdk/nrf52/components/libraries/bootloader/nrf_bootloader_fw_activation.c',
'embed/sdk/nrf52/components/libraries/bootloader/nrf_bootloader_info.c',
'embed/sdk/nrf52/components/libraries/bootloader/nrf_bootloader_wdt.c',
'embed/sdk/nrf52/external/nano-pb/pb_common.c',
'embed/sdk/nrf52/external/nano-pb/pb_decode.c',
'embed/sdk/nrf52/components/libraries/bootloader/dfu/dfu-cc.pb.c',
'embed/sdk/nrf52/components/libraries/bootloader/dfu/nrf_dfu.c',
'embed/sdk/nrf52/components/libraries/bootloader/dfu/nrf_dfu_flash.c',
@ -197,6 +195,10 @@ SOURCE_BLE_BOOTLOADER = [
'vendor/trezor-crypto/ed25519-donna/modm-donna-32bit.c',
'vendor/trezor-crypto/memzero.c',
'vendor/trezor-crypto/sha2.c',
'vendor/nanopb/pb_common.c',
'vendor/nanopb/pb_decode.c',
'vendor/nanopb/pb_encode.c',
]
if DEBUG:

@ -79,12 +79,12 @@ NRF_LOG_MODULE_REGISTER();
* is not yet fully transferred. This value will also be correct after reset.
*/
static bool m_valid_init_cmd_present = false;
static dfu_packet_t m_packet = DFU_PACKET_INIT_DEFAULT;
static dfu_Packet m_packet = dfu_Packet_init_default;
static uint8_t* m_init_packet_data_ptr = 0;
static uint32_t m_init_packet_data_len = 0;
static pb_istream_t m_pb_stream;
static dfu_init_command_t const * mp_init = NULL;
static dfu_InitCommand const * mp_init = NULL;
extern const uint8_t NRF_BOOTLOADER_KEY_M;
extern const uint8_t NRF_BOOTLOADER_KEY_N;
@ -94,43 +94,43 @@ extern const uint8_t * const NRF_BOOTLOADER_KEYS[];
/** @brief Flag used by parser code to indicate that the init command has been found to be invalid.
*/
static bool m_init_packet_valid = false;
static void pb_decoding_callback(pb_istream_t *str,
uint32_t tag,
pb_wire_type_t wire_type,
void *iter)
{
pb_field_iter_t* p_iter = (pb_field_iter_t *) iter;
// Match the beginning of the init command.
if (p_iter->pos->ptr == &dfu_init_command_fields[0])
{
uint8_t * ptr = (uint8_t *)str->state;
uint32_t size = str->bytes_left;
if (m_init_packet_data_ptr != NULL || m_init_packet_data_len != 0)
{
m_init_packet_valid = false;
return;
}
// Remove tag.
while (*ptr & 0x80)
{
ptr++;
size--;
}
ptr++;
size--;
// Store the info in init_packet_data.
m_init_packet_data_ptr = ptr;
m_init_packet_data_len = size;
m_init_packet_valid = true;
NRF_LOG_DEBUG("PB: Init packet data len: %d", size);
}
}
//
//static void pb_decoding_callback(pb_istream_t *str,
// uint32_t tag,
// pb_wire_type_t wire_type,
// void *iter)
//{
// pb_field_iter_t* p_iter = (pb_field_iter_t *) iter;
//
// // Match the beginning of the init command.
// if (p_iter->pos->ptr == &dfu_init_command_fields[0])
// {
// uint8_t * ptr = (uint8_t *)str->state;
// uint32_t size = str->bytes_left;
//
// if (m_init_packet_data_ptr != NULL || m_init_packet_data_len != 0)
// {
// m_init_packet_valid = false;
// return;
// }
//
// // Remove tag.
// while (*ptr & 0x80)
// {
// ptr++;
// size--;
// }
// ptr++;
// size--;
//
// // Store the info in init_packet_data.
// m_init_packet_data_ptr = ptr;
// m_init_packet_data_len = size;
// m_init_packet_valid = true;
//
// NRF_LOG_DEBUG("PB: Init packet data len: %d", size);
// }
//}
/** @brief Function for decoding byte stream into variable.
*
@ -142,22 +142,36 @@ static bool stored_init_cmd_decode(void)
m_pb_stream = pb_istream_from_buffer(s_dfu_settings.init_command,
s_dfu_settings.progress.command_size);
dfu_init_command_t * p_init;
dfu_InitCommand * p_init;
// Attach our callback to follow the field decoding.
m_pb_stream.decoding_callback = pb_decoding_callback;
//m_pb_stream.decoding_callback = pb_decoding_callback;
m_init_packet_valid = false;
m_init_packet_data_ptr = NULL;
m_init_packet_data_len = 0;
memset(&m_packet, 0, sizeof(m_packet));
if (!pb_decode(&m_pb_stream, dfu_packet_fields, &m_packet))
if (!pb_decode(&m_pb_stream, dfu_Packet_fields, &m_packet))
{
NRF_LOG_ERROR("Handler: Invalid protocol buffer m_pb_stream");
return false;
}
if (m_packet.has_signed_command && m_packet.has_command)
{
NRF_LOG_ERROR("Handler: Invalid init command.");
return false;
}
if (m_packet.has_signed_command) {
//TODO: this is where signed init command is stored, but is it guaranteed to be there always?
// pb_decoding_callback was meant to find it, how to do that without nanopb modifications?
m_init_packet_data_ptr = &s_dfu_settings.init_command[11];
m_init_packet_data_len = 128;
m_init_packet_valid = true;
}
if (!m_init_packet_valid || (m_packet.has_signed_command && m_packet.has_command))
{
NRF_LOG_ERROR("Handler: Invalid init command.");
@ -168,9 +182,9 @@ static bool stored_init_cmd_decode(void)
p_init = &m_packet.signed_command.command.init;
m_pb_stream = pb_istream_from_buffer(m_init_packet_data_ptr, m_init_packet_data_len);
memset(p_init, 0, sizeof(dfu_init_command_t));
memset(p_init, 0, sizeof(dfu_InitCommand));
if (!pb_decode(&m_pb_stream, dfu_init_command_fields, p_init))
if (!pb_decode(&m_pb_stream, dfu_InitCommand_fields, p_init))
{
NRF_LOG_ERROR("Handler: Invalid protocol buffer m_pb_stream (init command)");
return false;
@ -272,14 +286,14 @@ bool nrf_dfu_validation_init_cmd_present(void)
// Function determines if init command signature is obligatory.
static bool signature_required(dfu_fw_type_t fw_type_to_be_updated)
static bool signature_required(dfu_FwType fw_type_to_be_updated)
{
bool result = true;
// DFU_FW_TYPE_EXTERNAL_APPLICATION and bootloader updates always require
// signature check
if ((!DFU_REQUIRES_SOFTDEVICE && (fw_type_to_be_updated == DFU_FW_TYPE_SOFTDEVICE)) ||
(fw_type_to_be_updated == DFU_FW_TYPE_APPLICATION))
if ((!DFU_REQUIRES_SOFTDEVICE && (fw_type_to_be_updated == dfu_FwType_SOFTDEVICE)) ||
(fw_type_to_be_updated == dfu_FwType_APPLICATION))
{
result = NRF_DFU_REQUIRE_SIGNED_APP_UPDATE;
}
@ -389,25 +403,25 @@ static nrf_dfu_result_t nrf_dfu_validation_signature_check(uint32_t sigmask,
// Function to calculate the total size of the firmware(s) in the update.
static nrf_dfu_result_t update_data_size_get(dfu_init_command_t const * p_init, uint32_t * p_size)
static nrf_dfu_result_t update_data_size_get(dfu_InitCommand const * p_init, uint32_t * p_size)
{
nrf_dfu_result_t ret_val = EXT_ERR(NRF_DFU_EXT_ERROR_INIT_COMMAND_INVALID);
uint32_t fw_sz = 0;
if ((p_init->type == DFU_FW_TYPE_APPLICATION ||
p_init->type == DFU_FW_TYPE_EXTERNAL_APPLICATION) &&
if ((p_init->type == dfu_FwType_APPLICATION ||
p_init->type == dfu_FwType_EXTERNAL_APPLICATION) &&
(p_init->has_app_size == true))
{
fw_sz = p_init->app_size;
}
else
{
if ((p_init->type & DFU_FW_TYPE_SOFTDEVICE) && (p_init->has_sd_size == true))
if ((p_init->type & dfu_FwType_SOFTDEVICE) && (p_init->has_sd_size == true))
{
fw_sz = p_init->sd_size;
}
if ((p_init->type & DFU_FW_TYPE_BOOTLOADER) && (p_init->has_bl_size == true))
if ((p_init->type & dfu_FwType_BOOTLOADER) && (p_init->has_bl_size == true))
{
if (p_init->bl_size <= BOOTLOADER_SIZE)
{
@ -441,13 +455,13 @@ static nrf_dfu_result_t update_data_size_get(dfu_init_command_t const * p_init,
*
* @param new_fw_type Firmware type.
*/
static bool use_single_bank(dfu_fw_type_t new_fw_type)
static bool use_single_bank(dfu_FwType new_fw_type)
{
bool result = false;
// DFU_FW_TYPE_EXTERNAL_APPLICATION never uses single bank
if (((new_fw_type == DFU_FW_TYPE_APPLICATION) ||
(new_fw_type == DFU_FW_TYPE_SOFTDEVICE)) &&
if (((new_fw_type == dfu_FwType_APPLICATION) ||
(new_fw_type == dfu_FwType_SOFTDEVICE)) &&
NRF_DFU_SINGLE_BANK_APP_UPDATES)
{
result = true;
@ -458,14 +472,14 @@ static bool use_single_bank(dfu_fw_type_t new_fw_type)
// Function to determine whether the new firmware needs a SoftDevice to be present.
static bool update_requires_softdevice(dfu_init_command_t const * p_init)
static bool update_requires_softdevice(dfu_InitCommand const * p_init)
{
return ((p_init->sd_req_count > 0) && (p_init->sd_req[0] != SD_REQ_APP_OVERWRITES_SD));
}
// Function to determine whether the SoftDevice can be removed during the update or not.
static bool keep_softdevice(dfu_init_command_t const * p_init)
static bool keep_softdevice(dfu_InitCommand const * p_init)
{
UNUSED_PARAMETER(p_init); // It's unused when DFU_REQUIRES_SOFTDEVICE is true.
return DFU_REQUIRES_SOFTDEVICE || update_requires_softdevice(p_init);
@ -484,7 +498,7 @@ static bool keep_softdevice(dfu_init_command_t const * p_init)
* an address was found.
* @retval NRF_DFU_RES_CODE_INSUFFICIENT_RESOURCES If the size check failed.
*/
static nrf_dfu_result_t update_data_addr_get(dfu_init_command_t const * p_init,
static nrf_dfu_result_t update_data_addr_get(dfu_InitCommand const * p_init,
uint32_t fw_size,
uint32_t * p_addr)
{
@ -510,7 +524,7 @@ static nrf_dfu_result_t update_data_addr_get(dfu_init_command_t const * p_init,
nrf_dfu_result_t nrf_dfu_validation_prevalidate(void)
{
nrf_dfu_result_t ret_val = NRF_DFU_RES_CODE_SUCCESS;
dfu_command_t const * p_command = &m_packet.command;
dfu_Command const * p_command = &m_packet.command;
uint32_t sigmask = 0;
uint8_t const * p_signature = NULL;
uint32_t signature_len = 0;
@ -638,7 +652,7 @@ static bool nrf_dfu_validation_hash_ok(uint8_t const * p_hash, uint32_t src_addr
// Function to check the hash received in the init command against the received firmware.
bool fw_hash_ok(dfu_init_command_t const * p_init, uint32_t fw_start_addr, uint32_t fw_size)
bool fw_hash_ok(dfu_InitCommand const * p_init, uint32_t fw_start_addr, uint32_t fw_size)
{
ASSERT(p_init != NULL);
return nrf_dfu_validation_hash_ok((uint8_t *)p_init->hash.hash.bytes, fw_start_addr, fw_size);
@ -702,7 +716,7 @@ static bool softdevice_info_ok(uint32_t sd_start_addr, uint32_t sd_size)
static bool boot_validation_extract(boot_validation_t * p_boot_validation,
dfu_init_command_t const * p_init,
dfu_InitCommand const * p_init,
uint32_t index,
uint32_t start_addr,
uint32_t data_len,
@ -722,11 +736,11 @@ static bool boot_validation_extract(boot_validation_t * p_boot_validation,
// The is_trusted argument specifies whether the function should have side effects.
static bool postvalidate_app(dfu_init_command_t const * p_init, uint32_t src_addr, uint32_t data_len, bool is_trusted)
static bool postvalidate_app(dfu_InitCommand const * p_init, uint32_t src_addr, uint32_t data_len, bool is_trusted)
{
boot_validation_t boot_validation;
ASSERT(p_init->type == DFU_FW_TYPE_APPLICATION);
ASSERT(p_init->type == dfu_FwType_APPLICATION);
if (!boot_validation_extract(&boot_validation, p_init, 0, src_addr, data_len, VALIDATE_ECDSA_P256_SHA256))
{
@ -772,7 +786,7 @@ static bool postvalidate_app(dfu_init_command_t const * p_init, uint32_t src_add
// Function to check a received SoftDevice or Bootloader firmware, or both,
// before it is copied into place.
// The is_trusted argument specifies whether the function should have side effects.
static bool postvalidate_sd_bl(dfu_init_command_t const * p_init,
static bool postvalidate_sd_bl(dfu_InitCommand const * p_init,
bool with_sd,
bool with_bl,
uint32_t start_addr,
@ -878,7 +892,7 @@ bool nrf_dfu_validation_boot_validate(boot_validation_t const * p_validation, ui
nrf_dfu_result_t postvalidate(uint32_t data_addr, uint32_t data_len, bool is_trusted)
{
nrf_dfu_result_t ret_val = NRF_DFU_RES_CODE_SUCCESS;
dfu_init_command_t const * p_init = mp_init;
dfu_InitCommand const * p_init = mp_init;
if (!fw_hash_ok(p_init, data_addr, data_len))
{
@ -886,7 +900,7 @@ nrf_dfu_result_t postvalidate(uint32_t data_addr, uint32_t data_len, bool is_tru
}
else
{
if (p_init->type == DFU_FW_TYPE_APPLICATION)
if (p_init->type == dfu_FwType_APPLICATION)
{
if (!postvalidate_app(p_init, data_addr, data_len, is_trusted))
{
@ -909,8 +923,8 @@ nrf_dfu_result_t postvalidate(uint32_t data_addr, uint32_t data_len, bool is_tru
#endif // NRF_DFU_SUPPORTS_EXTERNAL_APP
else
{
bool with_sd = p_init->type & DFU_FW_TYPE_SOFTDEVICE;
bool with_bl = p_init->type & DFU_FW_TYPE_BOOTLOADER;
bool with_sd = p_init->type & dfu_FwType_SOFTDEVICE;
bool with_bl = p_init->type & dfu_FwType_BOOTLOADER;
if (!postvalidate_sd_bl(p_init, with_sd, with_bl, data_addr, data_len, is_trusted))
{

@ -1,123 +1,31 @@
/**
* Copyright (c) 2017 - 2021, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Automatically generated nanopb constant definitions */
/* Generated by nanopb-0.3.6-dev at Tue Sep 11 14:37:18 2018. */
/* Generated by nanopb-0.4.5 */
#include "dfu-cc.pb.h"
/* @@protoc_insertion_point(includes) */
#if PB_PROTO_HEADER_VERSION != 30
#if PB_PROTO_HEADER_VERSION != 40
#error Regenerate this file with the current version of nanopb generator.
#endif
const bool dfu_init_command_is_debug_default = false;
const pb_field_t dfu_hash_fields[3] = {
PB_FIELD( 1, UENUM , REQUIRED, STATIC , FIRST, dfu_hash_t, hash_type, hash_type, 0),
PB_FIELD( 2, BYTES , REQUIRED, STATIC , OTHER, dfu_hash_t, hash, hash_type, 0),
PB_LAST_FIELD
};
const pb_field_t dfu_boot_validation_fields[3] = {
PB_FIELD( 1, UINT32 , REQUIRED, STATIC , FIRST, dfu_boot_validation_t, sigmask, type, 0),
PB_FIELD( 2, BYTES , REQUIRED, STATIC , OTHER, dfu_boot_validation_t, bytes, sigmask, 0),
PB_LAST_FIELD
};
const pb_field_t dfu_init_command_fields[11] = {
PB_FIELD( 1, UINT32 , OPTIONAL, STATIC , FIRST, dfu_init_command_t, fw_version, fw_version, 0),
PB_FIELD( 2, UINT32 , OPTIONAL, STATIC , OTHER, dfu_init_command_t, hw_version, fw_version, 0),
PB_FIELD( 3, UINT32 , REPEATED, STATIC , OTHER, dfu_init_command_t, sd_req, hw_version, 0),
PB_FIELD( 4, UENUM , OPTIONAL, STATIC , OTHER, dfu_init_command_t, type, sd_req, 0),
PB_FIELD( 5, UINT32 , OPTIONAL, STATIC , OTHER, dfu_init_command_t, sd_size, type, 0),
PB_FIELD( 6, UINT32 , OPTIONAL, STATIC , OTHER, dfu_init_command_t, bl_size, sd_size, 0),
PB_FIELD( 7, UINT32 , OPTIONAL, STATIC , OTHER, dfu_init_command_t, app_size, bl_size, 0),
PB_FIELD( 8, MESSAGE , OPTIONAL, STATIC , OTHER, dfu_init_command_t, hash, app_size, &dfu_hash_fields),
PB_FIELD( 9, BOOL , OPTIONAL, STATIC , OTHER, dfu_init_command_t, is_debug, hash, &dfu_init_command_is_debug_default),
PB_FIELD( 10, MESSAGE , REPEATED, STATIC , OTHER, dfu_init_command_t, boot_validation, is_debug, &dfu_boot_validation_fields),
PB_LAST_FIELD
};
const pb_field_t dfu_command_fields[3] = {
PB_FIELD( 1, UENUM , OPTIONAL, STATIC , FIRST, dfu_command_t, op_code, op_code, 0),
PB_FIELD( 2, MESSAGE , OPTIONAL, STATIC , OTHER, dfu_command_t, init, op_code, &dfu_init_command_fields),
PB_LAST_FIELD
};
const pb_field_t dfu_signed_command_fields[4] = {
PB_FIELD( 1, MESSAGE , REQUIRED, STATIC , FIRST, dfu_signed_command_t, command, command, &dfu_command_fields),
PB_FIELD( 2, UINT32 , REQUIRED, STATIC , OTHER, dfu_signed_command_t, sigmask, command, 0),
PB_FIELD( 3, BYTES , REQUIRED, STATIC , OTHER, dfu_signed_command_t, signature, sigmask, 0),
PB_LAST_FIELD
};
const pb_field_t dfu_packet_fields[3] = {
PB_FIELD( 1, MESSAGE , OPTIONAL, STATIC , FIRST, dfu_packet_t, command, command, &dfu_command_fields),
PB_FIELD( 2, MESSAGE , OPTIONAL, STATIC , OTHER, dfu_packet_t, signed_command, command, &dfu_signed_command_fields),
PB_LAST_FIELD
};
/* Check that field information fits in pb_field_t */
#if !defined(PB_FIELD_32BIT)
/* If you get an error here, it means that you need to define PB_FIELD_32BIT
* compile-time option. You can do that in pb.h or on compiler command line.
*
* The reason you need to do this is that some of your messages contain tag
* numbers or field sizes that are larger than what can fit in 8 or 16 bit
* field descriptors.
*/
PB_STATIC_ASSERT((pb_membersize(dfu_init_command_t, hash) < 65536 && pb_membersize(dfu_init_command_t, boot_validation[0]) < 65536 && pb_membersize(dfu_command_t, init) < 65536 && pb_membersize(dfu_signed_command_t, command) < 65536 && pb_membersize(dfu_packet_t, command) < 65536 && pb_membersize(dfu_packet_t, signed_command) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_dfu_hash_dfu_boot_validation_dfu_init_command_dfu_command_dfu_signed_command_dfu_packet)
#endif
PB_BIND(dfu_Hash, dfu_Hash, AUTO)
PB_BIND(dfu_BootValidation, dfu_BootValidation, AUTO)
PB_BIND(dfu_InitCommand, dfu_InitCommand, 2)
PB_BIND(dfu_Command, dfu_Command, 2)
PB_BIND(dfu_SignedCommand, dfu_SignedCommand, 2)
PB_BIND(dfu_Packet, dfu_Packet, 2)
#if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT)
/* If you get an error here, it means that you need to define PB_FIELD_16BIT
* compile-time option. You can do that in pb.h or on compiler command line.
*
* The reason you need to do this is that some of your messages contain tag
* numbers or field sizes that are larger than what can fit in the default
* 8 bit descriptors.
*/
PB_STATIC_ASSERT((pb_membersize(dfu_init_command_t, hash) < 256 && pb_membersize(dfu_init_command_t, boot_validation[0]) < 256 && pb_membersize(dfu_command_t, init) < 256 && pb_membersize(dfu_signed_command_t, command) < 256 && pb_membersize(dfu_packet_t, command) < 256 && pb_membersize(dfu_packet_t, signed_command) < 256), YOU_MUST_DEFINE_PB_FIELD_16BIT_FOR_MESSAGES_dfu_hash_dfu_boot_validation_dfu_init_command_dfu_command_dfu_signed_command_dfu_packet)
#endif
/* @@protoc_insertion_point(eof) */

@ -1,221 +1,239 @@
/**
* Copyright (c) 2017 - 2021, Nordic Semiconductor ASA
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form, except as embedded into a Nordic
* Semiconductor ASA integrated circuit in a product or a software update for
* such product, must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* 4. This software, with or without modification, must only be used with a
* Nordic Semiconductor ASA integrated circuit.
*
* 5. Any software provided in binary form under this license must not be reverse
* engineered, decompiled, modified and/or disassembled.
*
* THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* Automatically generated nanopb header */
/* Generated by nanopb-0.3.6-dev at Tue Sep 11 14:37:18 2018. */
/* Generated by nanopb-0.4.5 */
#ifndef PB_DFU_CC_PB_H_INCLUDED
#define PB_DFU_CC_PB_H_INCLUDED
#ifndef PB_DFU_DFU_CC_PB_H_INCLUDED
#define PB_DFU_DFU_CC_PB_H_INCLUDED
#include <pb.h>
/* @@protoc_insertion_point(includes) */
#if PB_PROTO_HEADER_VERSION != 30
#if PB_PROTO_HEADER_VERSION != 40
#error Regenerate this file with the current version of nanopb generator.
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Enum definitions */
typedef enum
{
DFU_FW_TYPE_APPLICATION = 0,
DFU_FW_TYPE_SOFTDEVICE = 1,
DFU_FW_TYPE_BOOTLOADER = 2,
DFU_FW_TYPE_SOFTDEVICE_BOOTLOADER = 3,
DFU_FW_TYPE_EXTERNAL_APPLICATION = 4
} dfu_fw_type_t;
#define DFU_FW_TYPE_MIN DFU_FW_TYPE_APPLICATION
#define DFU_FW_TYPE_MAX DFU_FW_TYPE_EXTERNAL_APPLICATION
#define DFU_FW_TYPE_ARRAYSIZE ((dfu_fw_type_t)(DFU_FW_TYPE_EXTERNAL_APPLICATION+1))
typedef enum
{
DFU_HASH_TYPE_NO_HASH = 0,
DFU_HASH_TYPE_CRC = 1,
DFU_HASH_TYPE_SHA128 = 2,
DFU_HASH_TYPE_SHA256 = 3,
DFU_HASH_TYPE_SHA512 = 4
} dfu_hash_type_t;
#define DFU_HASH_TYPE_MIN DFU_HASH_TYPE_NO_HASH
#define DFU_HASH_TYPE_MAX DFU_HASH_TYPE_SHA512
#define DFU_HASH_TYPE_ARRAYSIZE ((dfu_hash_type_t)(DFU_HASH_TYPE_SHA512+1))
typedef enum
{
DFU_OP_CODE_INIT = 1
} dfu_op_code_t;
#define DFU_OP_CODE_MIN DFU_OP_CODE_INIT
#define DFU_OP_CODE_MAX DFU_OP_CODE_INIT
#define DFU_OP_CODE_ARRAYSIZE ((dfu_op_code_t)(DFU_OP_CODE_INIT+1))
typedef enum _dfu_FwType {
dfu_FwType_APPLICATION = 0,
dfu_FwType_SOFTDEVICE = 1,
dfu_FwType_BOOTLOADER = 2,
dfu_FwType_SOFTDEVICE_BOOTLOADER = 3,
dfu_FwType_EXTERNAL_APPLICATION = 4
} dfu_FwType;
typedef enum _dfu_HashType {
dfu_HashType_NO_HASH = 0,
dfu_HashType_CRC = 1,
dfu_HashType_SHA128 = 2,
dfu_HashType_SHA256 = 3,
dfu_HashType_SHA512 = 4
} dfu_HashType;
typedef enum _dfu_OpCode {
dfu_OpCode_INIT = 1
} dfu_OpCode;
typedef enum _dfu_ValidationType {
dfu_ValidationType_NO_VALIDATION = 0,
dfu_ValidationType_VALIDATE_GENERATED_CRC = 1,
dfu_ValidationType_VALIDATE_SHA256 = 2,
dfu_ValidationType_VALIDATE_ECDSA_P256_SHA256 = 3
} dfu_ValidationType;
/* Struct definitions */
typedef PB_BYTES_ARRAY_T(64) dfu_boot_validation_bytes_t;
typedef struct {
uint32_t sigmask;
dfu_boot_validation_bytes_t bytes;
/* @@protoc_insertion_point(struct:dfu_boot_validation_t) */
} dfu_boot_validation_t;
typedef PB_BYTES_ARRAY_T(32) dfu_hash_hash_t;
typedef struct {
dfu_hash_type_t hash_type;
dfu_hash_hash_t hash;
/* @@protoc_insertion_point(struct:dfu_hash_t) */
} dfu_hash_t;
typedef struct {
typedef PB_BYTES_ARRAY_T(64) dfu_BootValidation_bytes_t;
typedef struct _dfu_BootValidation {
uint32_t sigmask;
dfu_BootValidation_bytes_t bytes;
} dfu_BootValidation;
typedef PB_BYTES_ARRAY_T(32) dfu_Hash_hash_t;
typedef struct _dfu_Hash {
dfu_HashType hash_type;
dfu_Hash_hash_t hash;
} dfu_Hash;
/* Commands data */
typedef struct _dfu_InitCommand {
bool has_fw_version;
uint32_t fw_version;
uint32_t fw_version;
bool has_hw_version;
uint32_t hw_version;
uint32_t hw_version;
pb_size_t sd_req_count;
uint32_t sd_req[16];
uint32_t sd_req[16];
bool has_type;
dfu_fw_type_t type;
dfu_FwType type;
bool has_sd_size;
uint32_t sd_size;
uint32_t sd_size;
bool has_bl_size;
uint32_t bl_size;
uint32_t bl_size;
bool has_app_size;
uint32_t app_size;
uint32_t app_size;
bool has_hash;
dfu_hash_t hash;
dfu_Hash hash;
bool has_is_debug;
bool is_debug;
bool is_debug;
pb_size_t boot_validation_count;
dfu_boot_validation_t boot_validation[3];
/* @@protoc_insertion_point(struct:dfu_init_command_t) */
} dfu_init_command_t;
dfu_BootValidation boot_validation[3];
} dfu_InitCommand;
typedef struct {
/* Command type */
typedef struct _dfu_Command {
bool has_op_code;
dfu_op_code_t op_code;
dfu_OpCode op_code;
bool has_init;
dfu_init_command_t init;
/* @@protoc_insertion_point(struct:dfu_command_t) */
} dfu_command_t;
typedef PB_BYTES_ARRAY_T(64) dfu_signed_command_signature_t;
typedef struct {
dfu_command_t command;
uint32_t sigmask;
dfu_signed_command_signature_t signature;
/* @@protoc_insertion_point(struct:dfu_signed_command_t) */
} dfu_signed_command_t;
typedef struct {
dfu_InitCommand init;
} dfu_Command;
typedef PB_BYTES_ARRAY_T(64) dfu_SignedCommand_signature_t;
typedef struct _dfu_SignedCommand {
dfu_Command command;
uint32_t sigmask;
dfu_SignedCommand_signature_t signature;
} dfu_SignedCommand;
/* Parent packet type */
typedef struct _dfu_Packet {
bool has_command;
dfu_command_t command;
dfu_Command command;
bool has_signed_command;
dfu_signed_command_t signed_command;
/* @@protoc_insertion_point(struct:dfu_packet_t) */
} dfu_packet_t;
dfu_SignedCommand signed_command;
} dfu_Packet;
/* Default values for struct fields */
extern const bool dfu_init_command_is_debug_default;
/* Initializer values for message structs */
#define DFU_HASH_INIT_DEFAULT {(dfu_hash_type_t)0, {0, {0}}}
#define DFU_BOOT_VALIDATION_INIT_DEFAULT {0, {0, {0}}}
#define DFU_INIT_COMMAND_INIT_DEFAULT {false, 0, false, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, false, (dfu_fw_type_t)0, false, 0, false, 0, false, 0, false, DFU_HASH_INIT_DEFAULT, false, false, 0, {DFU_BOOT_VALIDATION_INIT_DEFAULT, DFU_BOOT_VALIDATION_INIT_DEFAULT, DFU_BOOT_VALIDATION_INIT_DEFAULT}}
#define DFU_COMMAND_INIT_DEFAULT {false, (dfu_op_code_t)0, false, DFU_INIT_COMMAND_INIT_DEFAULT}
#define DFU_SIGNED_COMMAND_INIT_DEFAULT {DFU_COMMAND_INIT_DEFAULT, 0, {0, {0}}}
#define DFU_PACKET_INIT_DEFAULT {false, DFU_COMMAND_INIT_DEFAULT, false, DFU_SIGNED_COMMAND_INIT_DEFAULT}
#define DFU_HASH_INIT_ZERO {(dfu_hash_type_t)0, {0, {0}}}
#define DFU_BOOT_VALIDATION_INIT_ZERO {0, {0, {0}}}
#define DFU_INIT_COMMAND_INIT_ZERO {false, 0, false, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, false, (dfu_fw_type_t)0, false, 0, false, 0, false, 0, false, DFU_HASH_INIT_ZERO, false, 0, 0, {DFU_BOOT_VALIDATION_INIT_ZERO, DFU_BOOT_VALIDATION_INIT_ZERO, DFU_BOOT_VALIDATION_INIT_ZERO}}
#define DFU_COMMAND_INIT_ZERO {false, (dfu_op_code_t)0, false, DFU_INIT_COMMAND_INIT_ZERO}
#define DFU_SIGNED_COMMAND_INIT_ZERO {DFU_COMMAND_INIT_ZERO, 0, {0, {0}}}
#define DFU_PACKET_INIT_ZERO {false, DFU_COMMAND_INIT_ZERO, false, DFU_SIGNED_COMMAND_INIT_ZERO}
/* Helper constants for enums */
#define _dfu_FwType_MIN dfu_FwType_APPLICATION
#define _dfu_FwType_MAX dfu_FwType_EXTERNAL_APPLICATION
#define _dfu_FwType_ARRAYSIZE ((dfu_FwType)(dfu_FwType_EXTERNAL_APPLICATION+1))
/* Field tags (for use in manual encoding/decoding) */
#define DFU_BOOT_VALIDATION_TYPE_TAG 1
#define DFU_BOOT_VALIDATION_BYTES_TAG 2
#define DFU_HASH_HASH_TYPE_TAG 1
#define DFU_HASH_HASH_TAG 2
#define DFU_INIT_COMMAND_FW_VERSION_TAG 1
#define DFU_INIT_COMMAND_HW_VERSION_TAG 2
#define DFU_INIT_COMMAND_SD_REQ_TAG 3
#define DFU_INIT_COMMAND_TYPE_TAG 4
#define DFU_INIT_COMMAND_SD_SIZE_TAG 5
#define DFU_INIT_COMMAND_BL_SIZE_TAG 6
#define DFU_INIT_COMMAND_APP_SIZE_TAG 7
#define DFU_INIT_COMMAND_HASH_TAG 8
#define DFU_INIT_COMMAND_IS_DEBUG_TAG 9
#define DFU_INIT_COMMAND_BOOT_VALIDATION_TAG 10
#define DFU_COMMAND_OP_CODE_TAG 1
#define DFU_COMMAND_INIT_TAG 2
#define DFU_SIGNED_COMMAND_COMMAND_TAG 1
#define DFU_SIGNED_COMMAND_SIGNATURE_TYPE_TAG 2
#define DFU_SIGNED_COMMAND_SIGNATURE_TAG 3
#define DFU_PACKET_COMMAND_TAG 1
#define DFU_PACKET_SIGNED_COMMAND_TAG 2
#define _dfu_HashType_MIN dfu_HashType_NO_HASH
#define _dfu_HashType_MAX dfu_HashType_SHA512
#define _dfu_HashType_ARRAYSIZE ((dfu_HashType)(dfu_HashType_SHA512+1))
/* Struct field encoding specification for nanopb */
extern const pb_field_t dfu_hash_fields[3];
extern const pb_field_t dfu_boot_validation_fields[3];
extern const pb_field_t dfu_init_command_fields[11];
extern const pb_field_t dfu_command_fields[3];
extern const pb_field_t dfu_signed_command_fields[4];
extern const pb_field_t dfu_packet_fields[3];
#define _dfu_OpCode_MIN dfu_OpCode_INIT
#define _dfu_OpCode_MAX dfu_OpCode_INIT
#define _dfu_OpCode_ARRAYSIZE ((dfu_OpCode)(dfu_OpCode_INIT+1))
#define _dfu_ValidationType_MIN dfu_ValidationType_NO_VALIDATION
#define _dfu_ValidationType_MAX dfu_ValidationType_VALIDATE_ECDSA_P256_SHA256
#define _dfu_ValidationType_ARRAYSIZE ((dfu_ValidationType)(dfu_ValidationType_VALIDATE_ECDSA_P256_SHA256+1))
/* Maximum encoded size of messages (where known) */
#define DFU_HASH_SIZE 36
#define DFU_BOOT_VALIDATION_SIZE 68
#define DFU_INIT_COMMAND_SIZE 378
#define DFU_COMMAND_SIZE 383
#define DFU_SIGNED_COMMAND_SIZE 454
#define DFU_PACKET_SIZE 843
/* Message IDs (where set with "msgid" option) */
#ifdef PB_MSGID
#ifdef __cplusplus
extern "C" {
#endif
#define DFU_CC_MESSAGES \
/* Initializer values for message structs */
#define dfu_Hash_init_default {_dfu_HashType_MIN, {0, {0}}}
#define dfu_BootValidation_init_default {0, {0, {0}}}
#define dfu_InitCommand_init_default {false, 0, false, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, false, _dfu_FwType_MIN, false, 0, false, 0, false, 0, false, dfu_Hash_init_default, false, false, 0, {dfu_BootValidation_init_default, dfu_BootValidation_init_default, dfu_BootValidation_init_default}}
#define dfu_Command_init_default {false, _dfu_OpCode_MIN, false, dfu_InitCommand_init_default}
#define dfu_SignedCommand_init_default {dfu_Command_init_default, 0, {0, {0}}}
#define dfu_Packet_init_default {false, dfu_Command_init_default, false, dfu_SignedCommand_init_default}
#define dfu_Hash_init_zero {_dfu_HashType_MIN, {0, {0}}}
#define dfu_BootValidation_init_zero {0, {0, {0}}}
#define dfu_InitCommand_init_zero {false, 0, false, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, false, _dfu_FwType_MIN, false, 0, false, 0, false, 0, false, dfu_Hash_init_zero, false, 0, 0, {dfu_BootValidation_init_zero, dfu_BootValidation_init_zero, dfu_BootValidation_init_zero}}
#define dfu_Command_init_zero {false, _dfu_OpCode_MIN, false, dfu_InitCommand_init_zero}
#define dfu_SignedCommand_init_zero {dfu_Command_init_zero, 0, {0, {0}}}
#define dfu_Packet_init_zero {false, dfu_Command_init_zero, false, dfu_SignedCommand_init_zero}
/* Field tags (for use in manual encoding/decoding) */
#define dfu_BootValidation_sigmask_tag 1
#define dfu_BootValidation_bytes_tag 2
#define dfu_Hash_hash_type_tag 1
#define dfu_Hash_hash_tag 2
#define dfu_InitCommand_fw_version_tag 1
#define dfu_InitCommand_hw_version_tag 2
#define dfu_InitCommand_sd_req_tag 3
#define dfu_InitCommand_type_tag 4
#define dfu_InitCommand_sd_size_tag 5
#define dfu_InitCommand_bl_size_tag 6
#define dfu_InitCommand_app_size_tag 7
#define dfu_InitCommand_hash_tag 8
#define dfu_InitCommand_is_debug_tag 9
#define dfu_InitCommand_boot_validation_tag 10
#define dfu_Command_op_code_tag 1
#define dfu_Command_init_tag 2
#define dfu_SignedCommand_command_tag 1
#define dfu_SignedCommand_sigmask_tag 2
#define dfu_SignedCommand_signature_tag 3
#define dfu_Packet_command_tag 1
#define dfu_Packet_signed_command_tag 2
#endif
/* Struct field encoding specification for nanopb */
#define dfu_Hash_FIELDLIST(X, a) \
X(a, STATIC, REQUIRED, UENUM, hash_type, 1) \
X(a, STATIC, REQUIRED, BYTES, hash, 2)
#define dfu_Hash_CALLBACK NULL
#define dfu_Hash_DEFAULT NULL
#define dfu_BootValidation_FIELDLIST(X, a) \
X(a, STATIC, REQUIRED, UINT32, sigmask, 1) \
X(a, STATIC, REQUIRED, BYTES, bytes, 2)
#define dfu_BootValidation_CALLBACK NULL
#define dfu_BootValidation_DEFAULT NULL
#define dfu_InitCommand_FIELDLIST(X, a) \
X(a, STATIC, OPTIONAL, UINT32, fw_version, 1) \
X(a, STATIC, OPTIONAL, UINT32, hw_version, 2) \
X(a, STATIC, REPEATED, UINT32, sd_req, 3) \
X(a, STATIC, OPTIONAL, UENUM, type, 4) \
X(a, STATIC, OPTIONAL, UINT32, sd_size, 5) \
X(a, STATIC, OPTIONAL, UINT32, bl_size, 6) \
X(a, STATIC, OPTIONAL, UINT32, app_size, 7) \
X(a, STATIC, OPTIONAL, MESSAGE, hash, 8) \
X(a, STATIC, OPTIONAL, BOOL, is_debug, 9) \
X(a, STATIC, REPEATED, MESSAGE, boot_validation, 10)
#define dfu_InitCommand_CALLBACK NULL
#define dfu_InitCommand_DEFAULT (const pb_byte_t*)"\x48\x00\x00"
#define dfu_InitCommand_hash_MSGTYPE dfu_Hash
#define dfu_InitCommand_boot_validation_MSGTYPE dfu_BootValidation
#define dfu_Command_FIELDLIST(X, a) \
X(a, STATIC, OPTIONAL, UENUM, op_code, 1) \
X(a, STATIC, OPTIONAL, MESSAGE, init, 2)
#define dfu_Command_CALLBACK NULL
#define dfu_Command_DEFAULT (const pb_byte_t*)"\x08\x01\x00"
#define dfu_Command_init_MSGTYPE dfu_InitCommand
#define dfu_SignedCommand_FIELDLIST(X, a) \
X(a, STATIC, REQUIRED, MESSAGE, command, 1) \
X(a, STATIC, REQUIRED, UINT32, sigmask, 2) \
X(a, STATIC, REQUIRED, BYTES, signature, 3)
#define dfu_SignedCommand_CALLBACK NULL
#define dfu_SignedCommand_DEFAULT NULL
#define dfu_SignedCommand_command_MSGTYPE dfu_Command
#define dfu_Packet_FIELDLIST(X, a) \
X(a, STATIC, OPTIONAL, MESSAGE, command, 1) \
X(a, STATIC, OPTIONAL, MESSAGE, signed_command, 2)
#define dfu_Packet_CALLBACK NULL
#define dfu_Packet_DEFAULT NULL
#define dfu_Packet_command_MSGTYPE dfu_Command
#define dfu_Packet_signed_command_MSGTYPE dfu_SignedCommand
extern const pb_msgdesc_t dfu_Hash_msg;
extern const pb_msgdesc_t dfu_BootValidation_msg;
extern const pb_msgdesc_t dfu_InitCommand_msg;
extern const pb_msgdesc_t dfu_Command_msg;
extern const pb_msgdesc_t dfu_SignedCommand_msg;
extern const pb_msgdesc_t dfu_Packet_msg;
/* Defines for backwards compatibility with code written before nanopb-0.4.0 */
#define dfu_Hash_fields &dfu_Hash_msg
#define dfu_BootValidation_fields &dfu_BootValidation_msg
#define dfu_InitCommand_fields &dfu_InitCommand_msg
#define dfu_Command_fields &dfu_Command_msg
#define dfu_SignedCommand_fields &dfu_SignedCommand_msg
#define dfu_Packet_fields &dfu_Packet_msg
/* Maximum encoded size of messages (where known) */
#define dfu_BootValidation_size 72
#define dfu_Command_size 395
#define dfu_Hash_size 36
#define dfu_InitCommand_size 390
#define dfu_Packet_size 871
#define dfu_SignedCommand_size 470
#ifdef __cplusplus
} /* extern "C" */
#endif
/* @@protoc_insertion_point(eof) */
#endif

@ -71,7 +71,7 @@ NRF_LOG_MODULE_REGISTER();
#define NRF_DFU_PROTOCOL_REDUCED 0
#endif
STATIC_ASSERT(DFU_SIGNED_COMMAND_SIZE <= INIT_COMMAND_MAX_SIZE);
STATIC_ASSERT(dfu_SignedCommand_size <= INIT_COMMAND_MAX_SIZE);
static uint32_t m_firmware_start_addr; /**< Start address of the current firmware image. */
static uint32_t m_firmware_size_req; /**< The size of the entire firmware image. Defined by the init command. */

@ -185,7 +185,7 @@ nrf_dfu_result_t nrf_dfu_validation_activation_prepare(uint32_t data_addr, uint3
*
* @return Operation result. see @ref nrf_dfu_result_t.
*/
nrf_dfu_result_t nrf_dfu_validation_post_external_app_execute(dfu_init_command_t const * p_init, bool is_trusted);
nrf_dfu_result_t nrf_dfu_validation_post_external_app_execute(dfu_InitCommand const * p_init, bool is_trusted);
/**
* @brief Function to check if there is a valid external app in Bank 1.

@ -78,7 +78,7 @@ static bool sd_req_check(uint32_t const * p_sd_req, uint8_t sd_req_cnt, bool acc
}
static bool sd_req_ok(dfu_init_command_t const * p_init)
static bool sd_req_ok(dfu_InitCommand const * p_init)
{
ASSERT(p_init != NULL);
bool result;
@ -100,9 +100,9 @@ static bool sd_req_ok(dfu_init_command_t const * p_init)
{
result = sd_req_check(p_init->sd_req,
p_init->sd_req_count,
(p_init->type == DFU_FW_TYPE_EXTERNAL_APPLICATION));
(p_init->type == dfu_FwType_EXTERNAL_APPLICATION));
}
else if (p_init->type == DFU_FW_TYPE_APPLICATION)
else if (p_init->type == dfu_FwType_APPLICATION)
{
// The application wants to overwrite the SoftDevice.
if (prevent_downgrade && (p_init->sd_req_count > 1) && (p_init->sd_req[0] == SD_REQ_APP_OVERWRITES_SD))
@ -131,7 +131,7 @@ static bool sd_req_ok(dfu_init_command_t const * p_init)
else
{
// Don't allow SoftDevice updates which assume no SD is present already.
result = !prevent_downgrade || (p_init->type != DFU_FW_TYPE_SOFTDEVICE);
result = !prevent_downgrade || (p_init->type != dfu_FwType_SOFTDEVICE);
}
}
@ -158,23 +158,23 @@ static bool sd_req_ok(dfu_init_command_t const * p_init)
}
static bool fw_hash_type_ok(dfu_init_command_t const * p_init)
static bool fw_hash_type_ok(dfu_InitCommand const * p_init)
{
ASSERT(p_init != NULL);
return (p_init->hash.hash_type == DFU_HASH_TYPE_SHA256);
return (p_init->hash.hash_type == dfu_HashType_SHA256);
}
static bool fw_version_required(dfu_fw_type_t new_fw_type)
static bool fw_version_required(dfu_FwType new_fw_type)
{
bool result = true;
if (new_fw_type == DFU_FW_TYPE_SOFTDEVICE)
if (new_fw_type == dfu_FwType_SOFTDEVICE)
{
result = false; // fw_version is optional in SoftDevice updates. If present, it will be checked against the app version.
}
else if (new_fw_type == DFU_FW_TYPE_APPLICATION)
else if (new_fw_type == dfu_FwType_APPLICATION)
{
result = NRF_DFU_APP_DOWNGRADE_PREVENTION; // fw_version is configurable in app updates.
}
@ -191,15 +191,15 @@ static bool fw_version_required(dfu_fw_type_t new_fw_type)
}
static bool fw_type_ok(dfu_init_command_t const * p_init)
static bool fw_type_ok(dfu_InitCommand const * p_init)
{
ASSERT(p_init != NULL);
return ((p_init->has_type)
&& ( (p_init->type == DFU_FW_TYPE_APPLICATION)
|| (p_init->type == DFU_FW_TYPE_SOFTDEVICE)
|| (p_init->type == DFU_FW_TYPE_BOOTLOADER)
|| (p_init->type == DFU_FW_TYPE_SOFTDEVICE_BOOTLOADER)
&& ( (p_init->type == dfu_FwType_APPLICATION)
|| (p_init->type == dfu_FwType_SOFTDEVICE)
|| (p_init->type == dfu_FwType_BOOTLOADER)
|| (p_init->type == dfu_FwType_SOFTDEVICE_BOOTLOADER)
#if NRF_DFU_SUPPORTS_EXTERNAL_APP
|| (p_init->type == DFU_FW_TYPE_EXTERNAL_APPLICATION)
#endif // NRF_DFU_SUPPORTS_EXTERNAL_APP
@ -214,13 +214,13 @@ static bool fw_type_ok(dfu_init_command_t const * p_init)
// This function assumes p_init->has_fw_version.
static bool fw_version_ok(dfu_init_command_t const * p_init)
static bool fw_version_ok(dfu_InitCommand const * p_init)
{
ASSERT(p_init != NULL);
ASSERT(p_init->has_fw_version);
if ((p_init->type == DFU_FW_TYPE_APPLICATION) ||
(p_init->type == DFU_FW_TYPE_SOFTDEVICE))
if ((p_init->type == dfu_FwType_APPLICATION) ||
(p_init->type == dfu_FwType_SOFTDEVICE))
{
if (!NRF_DFU_APP_DOWNGRADE_PREVENTION)
{
@ -259,7 +259,7 @@ static bool fw_version_ok(dfu_init_command_t const * p_init)
}
nrf_dfu_result_t nrf_dfu_ver_validation_check(dfu_init_command_t const * p_init)
nrf_dfu_result_t nrf_dfu_ver_validation_check(dfu_InitCommand const * p_init)
{
nrf_dfu_result_t ret_val = NRF_DFU_RES_CODE_SUCCESS;
if (!fw_type_ok(p_init))

@ -59,6 +59,6 @@
*
* @return NRF_DFU_RES_CODE_SUCCESS if successful or error code otherwise
*/
nrf_dfu_result_t nrf_dfu_ver_validation_check(dfu_init_command_t const * p_init);
nrf_dfu_result_t nrf_dfu_ver_validation_check(dfu_InitCommand const * p_init);
#endif //__NRF_DFU_VER_VALIDATION_H

Loading…
Cancel
Save