PelionIoT / mbed-cloud-client

Izuma Device Management Client library

Home Page:https://izumanetworks.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Errors when disabling bootstrapping

msiglreith opened this issue · comments

Disabling the bootstrap features causes some issues with version 4.10.
Below a list of issues I faced so far, but might not be exhaustive:

Compile-time:

  • ConnectorClient uses bootstrap related functions which are excluded when disabling the feature
  • ConnectorClient doesn't derive from M2MTimerObserver anymore but relays on observation for some timers.

Runtime:

Thanks for the report @msiglreith

We'll take a look.

Internal ref: https://armiot.atlassian.net/browse/IOTCLT-5013

Bootstrap related states in M2mIntefaceImpl are excluded, but the states are not excluded as well in the generated state machines, which leads to incorrect state transitions

https://github.com/PelionIoT/mbed-cloud-client/blob/master/mbed-client/source/m2minterfaceimpl.cpp#L160

This whole function is flagged at line 144:

#ifndef MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE

I checked the code and all calls for BOOTSTRAP states(STATE_BOOTSTRAP, STATE_BOOTSTRAP_ADDRESS_RESOLVED, STATE_BOOTSTRAP_RESOURCE_CREATED, STATE_BOOTSTRAP_WAIT, STATE_BOOTSTRAP_ERROR_WAIT, STATE_BOOTSTRAPPED) are flagged.

Also state_function() is flagging the bootstrap states:

#ifndef MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE

An error trace could be added to default case when the required state didn't match any of switch cases.

@mirelachirica Thanks for taking a look!

This whole function is flagged at line 144:

Right, sorry I just picked the first occurence where such state transition arrays are generated. It affects the others as well.
My understanding is that it's related to the way these arrays are generated by the #defines defined here:

#define BEGIN_TRANSITION_MAP \
static const uint8_t TRANSITIONS[] = {\
#define TRANSITION_MAP_ENTRY(entry)\
entry,
#define END_TRANSITION_MAP(data) \
0 };\
external_event(TRANSITIONS[_current_state], data);

There is an implicit ordering defined by the state machine definitions and the ordering in the E_States enum, but this is not enforced at compile-time.

BEGIN_TRANSITION_MAP // - Current State -
TRANSITION_MAP_ENTRY(STATE_REGISTER) // state_idle
TRANSITION_MAP_ENTRY(EVENT_IGNORED) // state_bootstrap
TRANSITION_MAP_ENTRY(EVENT_IGNORED) // state__bootstrap_address_resolved
TRANSITION_MAP_ENTRY(EVENT_IGNORED) // state_bootstrap_resource_created
TRANSITION_MAP_ENTRY(EVENT_IGNORED) // state_bootstrap_wait
TRANSITION_MAP_ENTRY(EVENT_IGNORED) // state_bootstrap_error_wait
TRANSITION_MAP_ENTRY(STATE_REGISTER) // state_bootstrapped
TRANSITION_MAP_ENTRY(STATE_REGISTER) // state_register
TRANSITION_MAP_ENTRY(STATE_REGISTER) // state_register_address_resolved
TRANSITION_MAP_ENTRY(STATE_REGISTER) // state_registered
TRANSITION_MAP_ENTRY(EVENT_IGNORED) // state_update_registration
TRANSITION_MAP_ENTRY(EVENT_IGNORED) // state_unregister
TRANSITION_MAP_ENTRY(EVENT_IGNORED) // state_unregistered
TRANSITION_MAP_ENTRY(EVENT_IGNORED) // state_sending_coap_data
TRANSITION_MAP_ENTRY(EVENT_IGNORED) // state_coap_data_sent
TRANSITION_MAP_ENTRY(EVENT_IGNORED) // state_coap_data_received
TRANSITION_MAP_ENTRY(EVENT_IGNORED) // state_processing_coap_data
TRANSITION_MAP_ENTRY(EVENT_IGNORED) // state_coap_data_processed
TRANSITION_MAP_ENTRY(STATE_REGISTER) // state_waiting
END_TRANSITION_MAP(&data)

Example: When defining MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE , STATE_REGISTER would be assigned to 1 by the enum but the corresponding function would be at index 7 in the state machine array. When looking up the transition in the state machine it would pick the transition for STATE_BOOTSTRAP.

enum E_States {
STATE_IDLE = 0,
#ifndef MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE
STATE_BOOTSTRAP,
STATE_BOOTSTRAP_ADDRESS_RESOLVED,
STATE_BOOTSTRAP_RESOURCE_CREATED,
STATE_BOOTSTRAP_WAIT,
STATE_BOOTSTRAP_ERROR_WAIT, // 5
STATE_BOOTSTRAPPED,
#endif //MBED_CLIENT_DISABLE_BOOTSTRAP_FEATURE
STATE_REGISTER,
STATE_REGISTER_ADDRESS_RESOLVED,
STATE_REGISTERED,
STATE_UPDATE_REGISTRATION, // 10
STATE_UNREGISTER,
STATE_UNREGISTERED,
STATE_SENDING_COAP_DATA,
STATE_COAP_DATA_SENT,
STATE_COAP_DATA_RECEIVED, // 15
STATE_PROCESSING_COAP_DATA,
STATE_COAP_DATA_PROCESSED,
STATE_WAITING,
STATE_MAX_STATES
};

Should be fixed now with 4.11.0 release.