Skip to content

Commit

Permalink
Merge pull request #23 from ARMmbed/release-1.5.0
Browse files Browse the repository at this point in the history
mbed-cloud-client-example 1.5.0
  • Loading branch information
Jani Suonperä authored Sep 11, 2018
2 parents 33d1f56 + ec868ec commit f47856d
Show file tree
Hide file tree
Showing 42 changed files with 232 additions and 112 deletions.
16 changes: 12 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
# Changelog for Mbed Cloud Client Reference Example
# Changelog for Pelion Device Management Client Reference Example

## Release 1.5.0 (11.09.2018)
* Added a hardcoded RoT injection when application is configured to use developer mode. This preserves the Device Management Client credentials even when SOTP is erased (for example due to reflashing of the application binary).
* Updated to Mbed OS 5.9.6.
* Updated easy-connect to v1.2.16.
* Updated the storage selector with compiler warning fixes in the internal libraries.
* Replaced the notification delivery status functionality with a more generic message delivery status callback.
* Added an example on using the delayed response for execute operations.
* Added configurations for the K66F target board.

## Release 1.4.0 (13.07.2018)
* Increased application main stack-size to 5120 to fix Stack overflow with ARMCC compiled binaries when tracing is enabled.
* Linux: Updated Mbedtls to 2.10.0 in pal-platform.
* Updated to Mbed OS 5.9.2.
* Updated easy-connect to v1.2.12.
* Updated storage-selector with support for SPI flash frequency, and Nucleo F411RE board.
* Moved mbed_trace() init as first step in application init to allow printing any early debug-information from PAL-layer when debug tracing is enabled.
* Moved the initialization of `mbed_trace()` as the first step in the application initialization. This allows the printing of any early debug information from the PAL layer when debug tracing is enabled.
* Added support for Nucleo F411RE board with Wifi-X-Nucleo shield.
* Increased the Mbed Cloud Client event loop thread stack size to 8192 bytes from default value of 6144. This fixes stack overflows in some cases
where crypto operations result in deep callstacks.
* Increased the event loop thread stack size to 8192 bytes from a default value of 6144. This fixes stack overflows in some cases where crypto operations result in deep callstacks.

## Release 1.3.3 (08.06.2018)
* Updated to Mbed OS 5.8.5.
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ endif()
# mbed-cloud-client-example
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/source)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/source/include)

# This is needed for compiling and linking SW.
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/source/platform")
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
The full documentation for this example is [available on our documentation site](https://cloud.mbed.com/docs/current/connecting/mbed-cloud-client-tutorials.html)
The full documentation for this example is [available on our documentation site](https://cloud.mbed.com/docs/current/connecting/device-management-client-tutorials.html)
5 changes: 5 additions & 0 deletions configs/eth_v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
"update-client.bootloader-details" : "0x00007188",
"update-client.application-details": "(40*1024)"
},
"K66F": {
"target.mbed_app_start" : "0x0000a400",
"update-client.bootloader-details" : "0x00007188",
"update-client.application-details": "(40*1024)"
},
"NUCLEO_F429ZI": {
"target.mbed_app_start" : "0x08010400",
"update-client.bootloader-details" : "0x080078CC",
Expand Down
1 change: 1 addition & 0 deletions configs/mesh_6lowpan.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"mbed-client.event-loop-size": 32768,
"mbed-client.reconnection-count": 6,
"mbed-client.dns-use-thread": 1,
"mbed-client-pal.pal-dns-api-version": 2,
"mbed-client.sn-coap-blockwise-max-time-data-stored": 120,
"mbed-trace.enable": null,
"storage-selector.filesystem" : "FAT",
Expand Down
1 change: 1 addition & 0 deletions configs/mesh_thread.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"mbed-client.event-loop-size": 32768,
"mbed-client.reconnection-count": 6,
"mbed-client.dns-use-thread": 1,
"mbed-client-pal.pal-dns-api-version": 2,
"mbed-client.sn-coap-blockwise-max-time-data-stored": 120,
"mbed-trace.enable": null,
"storage-selector.filesystem" : "FAT",
Expand Down
2 changes: 1 addition & 1 deletion easy-connect.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/ARMmbed/easy-connect/#aaf89690919fc378799e680119a58a222402799f
https://github.com/ARMmbed/easy-connect/#bf48f5b649eba3ed7b810c77c630b5eb51301311
56 changes: 36 additions & 20 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "mbed.h"
#endif
#include "application_init.h"
#include "common_button_and_led.h"
#include "mcc_common_button_and_led.h"
#include "blinky.h"

// event based LED blinker, controlled via pattern_resource
Expand All @@ -37,6 +37,7 @@ int main(void)
// Pointers to the resources that will be created in main_application().
static M2MResource* button_res;
static M2MResource* pattern_res;
static M2MResource* blink_res;

// Pointer to mbedClient, used for calling close function.
static SimpleM2MClient *client;
Expand All @@ -46,6 +47,14 @@ void pattern_updated(const char *)
printf("PUT received, new value: %s\n", pattern_res->get_value_string().c_str());
}

void blinky_completed(void)
{
printf("Blinky completed \n");

// Send response to backend
blink_res->send_delayed_post_response();
}

void blink_callback(void *)
{
String pattern_string = pattern_res->get_value_string();
Expand All @@ -55,34 +64,39 @@ void blink_callback(void *)
// The pattern is something like 500:200:500, so parse that.
// LED blinking is done while parsing.
const bool restart_pattern = false;
if (blinky.start((char*)pattern_res->value(), pattern_res->value_length(), restart_pattern) == false) {
if (blinky.start((char*)pattern_res->value(), pattern_res->value_length(), restart_pattern, blinky_completed) == false) {
printf("out of memory error\n");
}
}

void button_notification_status_callback(const M2MBase& object, const NoticationDeliveryStatus status)
void button_status_callback(const M2MBase& object,
const M2MBase::MessageDeliveryStatus status,
const M2MBase::MessageType /*type*/)
{
switch(status) {
case NOTIFICATION_STATUS_BUILD_ERROR:
printf("Notification callback: (%s) error when building CoAP message\n", object.uri_path());
case M2MBase::MESSAGE_STATUS_BUILD_ERROR:
printf("Message status callback: (%s) error when building CoAP message\n", object.uri_path());
break;
case M2MBase::MESSAGE_STATUS_RESEND_QUEUE_FULL:
printf("Message status callback: (%s) CoAP resend queue full\n", object.uri_path());
break;
case NOTIFICATION_STATUS_RESEND_QUEUE_FULL:
printf("Notification callback: (%s) CoAP resend queue full\n", object.uri_path());
case M2MBase::MESSAGE_STATUS_SENT:
printf("Message status callback: (%s) Message sent to server\n", object.uri_path());
break;
case NOTIFICATION_STATUS_SENT:
printf("Notification callback: (%s) Notification sent to server\n", object.uri_path());
case M2MBase::MESSAGE_STATUS_DELIVERED:
printf("Message status callback: (%s) Message delivered\n", object.uri_path());
break;
case NOTIFICATION_STATUS_DELIVERED:
printf("Notification callback: (%s) Notification delivered\n", object.uri_path());
case M2MBase::MESSAGE_STATUS_SEND_FAILED:
printf("Message status callback: (%s) Message sending failed\n", object.uri_path());
break;
case NOTIFICATION_STATUS_SEND_FAILED:
printf("Notification callback: (%s) Notification sending failed\n", object.uri_path());
case M2MBase::MESSAGE_STATUS_SUBSCRIBED:
printf("Message status callback: (%s) subscribed\n", object.uri_path());
break;
case NOTIFICATION_STATUS_SUBSCRIBED:
printf("Notification callback: (%s) subscribed\n", object.uri_path());
case M2MBase::MESSAGE_STATUS_UNSUBSCRIBED:
printf("Message status callback: (%s) subscription removed\n", object.uri_path());
break;
case NOTIFICATION_STATUS_UNSUBSCRIBED:
printf("Notification callback: (%s) subscription removed\n", object.uri_path());
case M2MBase::MESSAGE_STATUS_REJECTED:
printf("Message status callback: (%s) server has rejected the message\n", object.uri_path());
break;
default:
break;
Expand Down Expand Up @@ -171,15 +185,17 @@ void main_application(void)

// Create resource for button count. Path of this resource will be: 3200/0/5501.
button_res = mbedClient.add_cloud_resource(3200, 0, 5501, "button_resource", M2MResourceInstance::INTEGER,
M2MBase::GET_ALLOWED, 0, true, NULL, (void*)button_notification_status_callback);
M2MBase::GET_ALLOWED, 0, true, NULL, (void*)button_status_callback);

// Create resource for led blinking pattern. Path of this resource will be: 3201/0/5853.
pattern_res = mbedClient.add_cloud_resource(3201, 0, 5853, "pattern_resource", M2MResourceInstance::STRING,
M2MBase::GET_PUT_ALLOWED, "500:500:500:500", false, (void*)pattern_updated, NULL);

// Create resource for starting the led blinking. Path of this resource will be: 3201/0/5850.
mbedClient.add_cloud_resource(3201, 0, 5850, "blink_resource", M2MResourceInstance::STRING,
M2MBase::POST_ALLOWED, "", false, (void*)blink_callback, NULL);
blink_res = mbedClient.add_cloud_resource(3201, 0, 5850, "blink_resource", M2MResourceInstance::STRING,
M2MBase::POST_ALLOWED, "", false, (void*)blink_callback, (void*)button_status_callback);
// Use delayed response
blink_res->set_delayed_response(true);

// Create resource for unregistering the device. Path of this resource will be: 5000/0/1.
mbedClient.add_cloud_resource(5000, 0, 1, "unregister", M2MResourceInstance::STRING,
Expand Down
2 changes: 1 addition & 1 deletion mbed-cloud-client.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/ARMmbed/mbed-cloud-client/#9b0bc6a2f3f1f5dbb5be1827db83004d531b99c9
https://github.com/ARMmbed/mbed-cloud-client/#13e0cef7f9508c10d50f3beb049eafea2af6f17b
2 changes: 1 addition & 1 deletion mbed-os.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/ARMmbed/mbed-os/#62f8b922b420626514fd4690107aff4188469833
https://github.com/ARMmbed/mbed-os/#0fdfcf7350896a9c0b57c4a18237677abfe25f1a
5 changes: 5 additions & 0 deletions mbed_app.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
"update-client.bootloader-details" : "0x00007188",
"update-client.application-details": "(40*1024)"
},
"K66F": {
"target.mbed_app_start" : "0x0000a400",
"update-client.bootloader-details" : "0x00007188",
"update-client.application-details": "(40*1024)"
},
"NUCLEO_F429ZI": {
"target.mbed_app_start" : "0x08010400",
"update-client.bootloader-details" : "0x080078CC",
Expand Down
6 changes: 6 additions & 0 deletions mbed_lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@
"sotp-section-2-address" : "(36*1024)",
"sotp-section-2-size" : "( 4*1024)"
},
"K66F": {
"sotp-section-1-address" : "(32*1024)",
"sotp-section-1-size" : "( 4*1024)",
"sotp-section-2-address" : "(36*1024)",
"sotp-section-2-size" : "( 4*1024)"
},
"NUCLEO_F411RE": {
"sotp-section-1-address" : "(0x08000000+32*1024)",
"sotp-section-1-size" : "(16*1024)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@
* limitations under the License.
*/

#include "common_setup.h"
#include "common_config.h"
#include <stdio.h>
#include "app_platform_setup.h"
#include "mcc_common_setup.h"
#include "mcc_common_config.h"
#include "factory_configurator_client.h"

#include <stdio.h>
#if MBED_CONF_APP_DEVELOPER_MODE == 1
#ifdef PAL_USER_DEFINED_CONFIGURATION
#include PAL_USER_DEFINED_CONFIGURATION
#endif
#endif // #if MBED_CONF_APP_DEVELOPER_MODE == 1


// Include this only for Developer mode and device which doesn't have in-built TRNG support
#if MBED_CONF_APP_DEVELOPER_MODE == 1
#ifdef PAL_USER_DEFINED_CONFIGURATION
#define FCC_ROT_SIZE 16
const uint8_t MBED_CLOUD_DEV_ROT[FCC_ROT_SIZE] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 };
#if !PAL_USE_HW_TRNG
#define FCC_ENTROPY_SIZE 48
const uint8_t MBED_CLOUD_DEV_ENTROPY[FCC_ENTROPY_SIZE] = { 0xf6, 0xd6, 0xc0, 0x09, 0x9e, 0x6e, 0xf2, 0x37, 0xdc, 0x29, 0x88, 0xf1, 0x57, 0x32, 0x7d, 0xde, 0xac, 0xb3, 0x99, 0x8c, 0xb9, 0x11, 0x35, 0x18, 0xeb, 0x48, 0x29, 0x03, 0x6a, 0x94, 0x6d, 0xe8, 0x40, 0xc0, 0x28, 0xcc, 0xe4, 0x04, 0xc3, 0x1f, 0x4b, 0xc2, 0xe0, 0x68, 0xa0, 0x93, 0xe6, 0x3a };
Expand Down Expand Up @@ -62,14 +64,26 @@ int mcc_platform_reset_storage(void)
int mcc_platform_fcc_init(void)
{
int status = fcc_init();
if (status != FCC_STATUS_SUCCESS && status != FCC_STATUS_ENTROPY_ERROR) {
// Ignore pre-existing RoT/Entropy in SOTP
if (status != FCC_STATUS_SUCCESS && status != FCC_STATUS_ENTROPY_ERROR && status != FCC_STATUS_ROT_ERROR) {
printf("fcc_init failed with status %d! - exit\n", status);
return status;
}
#if RESET_STORAGE
status = mcc_platform_reset_storage();
#endif
// Include this only for Developer mode and device which doesn't have in-built TRNG support
status = mcc_platform_sotp_init();
if (status != FCC_STATUS_SUCCESS) {
printf("fcc_init failed with status %d! - exit\n", status);
mcc_platform_fcc_finalize();
} else {
// We can return SUCCESS here as preexisting RoT/Entropy is expected flow.
status = FCC_STATUS_SUCCESS;
}
return status;
}

int mcc_platform_sotp_init(void)
{
int status = FCC_STATUS_SUCCESS;
// Include this only for Developer mode and a device which doesn't have in-built TRNG support.
#if MBED_CONF_APP_DEVELOPER_MODE == 1
#ifdef PAL_USER_DEFINED_CONFIGURATION
#if !PAL_USE_HW_TRNG
Expand All @@ -79,8 +93,21 @@ int mcc_platform_fcc_init(void)
printf("fcc_entropy_set failed with status %d! - exit\n", status);
mcc_platform_fcc_finalize();
return status;
}
}
#endif // PAL_USE_HW_TRNG = 0
/* Include this only for Developer mode. The application will use fixed RoT to simplify user-experience with the application.
* With this change the application be reflashed/SOTP can be erased safely without invalidating the application credentials.
*/
status = fcc_rot_set(MBED_CLOUD_DEV_ROT, FCC_ROT_SIZE);

if (status != FCC_STATUS_SUCCESS && status != FCC_STATUS_ROT_ERROR) {
printf("fcc_rot_set failed with status %d! - exit\n", status);
mcc_platform_fcc_finalize();
} else {
// We can return SUCCESS here as preexisting RoT/Entropy is expected flow.
printf("Using hardcoded Root of Trust, not suitable for production use.\n");
status = FCC_STATUS_SUCCESS;
}
#endif // PAL_USER_DEFINED_CONFIGURATION
#endif // #if MBED_CONF_APP_DEVELOPER_MODE == 1
return status;
Expand Down
34 changes: 26 additions & 8 deletions source/application_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
#include "mbed-trace/mbed_trace.h"
#include "mbed-trace-helper.h"
#include "factory_configurator_client.h"
#include "common_setup.h"
#include "common_button_and_led.h"
#include "app_platform_setup.h"
#include "mcc_common_setup.h"
#include "mcc_common_button_and_led.h"
#if defined (MBED_HEAP_STATS_ENABLED) || (MBED_STACK_STATS_ENABLED)
#include "memory_tests.h"
#endif
Expand Down Expand Up @@ -165,10 +166,10 @@ static bool application_init_verify_cloud_configuration()
int status;

#if MBED_CONF_APP_DEVELOPER_MODE == 1
printf("Start developer flow\n");
printf("Starting developer flow\n");
status = fcc_developer_flow();
if (status == FCC_STATUS_KCM_FILE_EXIST_ERROR) {
printf("Developer credentials already exists\n");
printf("Developer credentials already exist, continuing..\n");
} else if (status != FCC_STATUS_SUCCESS) {
printf("Failed to load developer credentials\n");
}
Expand All @@ -186,25 +187,43 @@ static bool application_init_fcc(void)
#ifdef MBED_STACK_STATS_ENABLED
print_stack_statistics();
#endif
int status = mcc_platform_fcc_init();
if(status != FCC_STATUS_SUCCESS && status != FCC_STATUS_ENTROPY_ERROR) {
printf("fcc_init failed with status %d! - exit\n", status);
int status = mcc_platform_fcc_init();
if(status != FCC_STATUS_SUCCESS) {
printf("application_init_fcc fcc_init failed with status %d! - exit\n", status);
return 1;
}
#if RESET_STORAGE
status = mcc_platform_reset_storage();
if(status != FCC_STATUS_SUCCESS) {
printf("application_init_fcc reset_storage failed with status %d! - exit\n", status);
return 1;
}
// Reinitialize SOTP
status = mcc_platform_sotp_init();
if (status != FCC_STATUS_SUCCESS) {
printf("application_init_fcc sotp_init failed with status %d! - exit\n", status);
return 1;
}
#endif

status = application_init_verify_cloud_configuration();
if (status != 0) {
// This is designed to simplify user-experience by auto-formatting the
// primary storage if no valid certificates exist.
// This should never be used for any kind of production devices.
#ifndef MBED_CONF_APP_MCC_NO_AUTO_FORMAT
printf("Certificate validation failed, trying autorecovery...\n");
if (mcc_platform_reformat_storage() != 0) {
return 1;
}
status = mcc_platform_reset_storage();
if (status != FCC_STATUS_SUCCESS) {
return 1;
}
status = mcc_platform_sotp_init();
if (status != FCC_STATUS_SUCCESS) {
return 1;
}
status = application_init_verify_cloud_configuration();
if (status != 0) {
return 1;
Expand All @@ -213,7 +232,6 @@ static bool application_init_fcc(void)
return 1;
#endif
}

return 0;
}

Expand Down
Loading

0 comments on commit f47856d

Please sign in to comment.