FRDM K64F Metronome

Committer:
ram54288
Date:
Sun May 14 18:37:05 2017 +0000
Revision:
0:dbad57390bd1
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ram54288 0:dbad57390bd1 1 /*
ram54288 0:dbad57390bd1 2 * Copyright (c) 2015 ARM Limited. All rights reserved.
ram54288 0:dbad57390bd1 3 * SPDX-License-Identifier: Apache-2.0
ram54288 0:dbad57390bd1 4 * Licensed under the Apache License, Version 2.0 (the License); you may
ram54288 0:dbad57390bd1 5 * not use this file except in compliance with the License.
ram54288 0:dbad57390bd1 6 * You may obtain a copy of the License at
ram54288 0:dbad57390bd1 7 *
ram54288 0:dbad57390bd1 8 * http://www.apache.org/licenses/LICENSE-2.0
ram54288 0:dbad57390bd1 9 *
ram54288 0:dbad57390bd1 10 * Unless required by applicable law or agreed to in writing, software
ram54288 0:dbad57390bd1 11 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
ram54288 0:dbad57390bd1 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ram54288 0:dbad57390bd1 13 * See the License for the specific language governing permissions and
ram54288 0:dbad57390bd1 14 * limitations under the License.
ram54288 0:dbad57390bd1 15 */
ram54288 0:dbad57390bd1 16 #ifndef M2M_INTERFACE_IMPL_H
ram54288 0:dbad57390bd1 17 #define M2M_INTERFACE_IMPL_H
ram54288 0:dbad57390bd1 18
ram54288 0:dbad57390bd1 19 #include "mbed-client/m2minterface.h"
ram54288 0:dbad57390bd1 20 #include "mbed-client/m2mserver.h"
ram54288 0:dbad57390bd1 21 #include "mbed-client/m2mconnectionobserver.h"
ram54288 0:dbad57390bd1 22 #include "mbed-client/m2mconnectionsecurity.h"
ram54288 0:dbad57390bd1 23 #include "include/m2mnsdlobserver.h"
ram54288 0:dbad57390bd1 24 #include "include/m2mnsdlinterface.h"
ram54288 0:dbad57390bd1 25 #include "mbed-client/m2mtimerobserver.h"
ram54288 0:dbad57390bd1 26 #include "mbed-client/m2mtimer.h"
ram54288 0:dbad57390bd1 27 #include "mbed-client/m2mconnectionhandler.h"
ram54288 0:dbad57390bd1 28
ram54288 0:dbad57390bd1 29 //FORWARD DECLARATION
ram54288 0:dbad57390bd1 30 class M2MConnectionSecurity;
ram54288 0:dbad57390bd1 31 class EventData;
ram54288 0:dbad57390bd1 32 class M2MUpdateRegisterData;
ram54288 0:dbad57390bd1 33 /**
ram54288 0:dbad57390bd1 34 * @brief M2MInterfaceImpl.
ram54288 0:dbad57390bd1 35 * This class implements handling of all mbed Client Interface operations
ram54288 0:dbad57390bd1 36 * defined in OMA LWM2M specifications.
ram54288 0:dbad57390bd1 37 * This includes Bootstrapping, Client Registration, Device Management &
ram54288 0:dbad57390bd1 38 * Service Enablement and Information Reporting.
ram54288 0:dbad57390bd1 39 */
ram54288 0:dbad57390bd1 40
ram54288 0:dbad57390bd1 41 class M2MInterfaceImpl : public M2MInterface,
ram54288 0:dbad57390bd1 42 public M2MNsdlObserver,
ram54288 0:dbad57390bd1 43 public M2MConnectionObserver,
ram54288 0:dbad57390bd1 44 public M2MTimerObserver
ram54288 0:dbad57390bd1 45 {
ram54288 0:dbad57390bd1 46 private:
ram54288 0:dbad57390bd1 47 // Prevents the use of assignment operator by accident.
ram54288 0:dbad57390bd1 48 M2MInterfaceImpl& operator=( const M2MInterfaceImpl& /*other*/ );
ram54288 0:dbad57390bd1 49
ram54288 0:dbad57390bd1 50 // Prevents the use of copy constructor by accident
ram54288 0:dbad57390bd1 51 M2MInterfaceImpl( const M2MInterfaceImpl& /*other*/ );
ram54288 0:dbad57390bd1 52
ram54288 0:dbad57390bd1 53 friend class M2MInterfaceFactory;
ram54288 0:dbad57390bd1 54
ram54288 0:dbad57390bd1 55 private:
ram54288 0:dbad57390bd1 56
ram54288 0:dbad57390bd1 57 /**
ram54288 0:dbad57390bd1 58 * @brief Constructor
ram54288 0:dbad57390bd1 59 * @param observer, Observer to pass the event callbacks for various
ram54288 0:dbad57390bd1 60 * interface operations.
ram54288 0:dbad57390bd1 61 * @param endpoint_name Endpoint name of the client.
ram54288 0:dbad57390bd1 62 * @param endpoint_type Endpoint type of the client.
ram54288 0:dbad57390bd1 63 * @param life_time Life time of the client in seconds
ram54288 0:dbad57390bd1 64 * @param listen_port Listening port for the endpoint, default is 8000.
ram54288 0:dbad57390bd1 65 * @param domain Domain of the client.
ram54288 0:dbad57390bd1 66 * @param mode Binding mode of the client, default is UDP
ram54288 0:dbad57390bd1 67 * @param stack Network stack to be used for connection, default is LwIP_IPv4.
ram54288 0:dbad57390bd1 68 * @param context_address Context address, default is empty.
ram54288 0:dbad57390bd1 69 */
ram54288 0:dbad57390bd1 70 M2MInterfaceImpl(M2MInterfaceObserver& observer,
ram54288 0:dbad57390bd1 71 const String &endpoint_name,
ram54288 0:dbad57390bd1 72 const String &endpoint_type,
ram54288 0:dbad57390bd1 73 const int32_t life_time,
ram54288 0:dbad57390bd1 74 const uint16_t listen_port,
ram54288 0:dbad57390bd1 75 const String &domain = "",
ram54288 0:dbad57390bd1 76 BindingMode mode = M2MInterface::NOT_SET,
ram54288 0:dbad57390bd1 77 M2MInterface::NetworkStack stack = M2MInterface::LwIP_IPv4,
ram54288 0:dbad57390bd1 78 const String &context_address = "");
ram54288 0:dbad57390bd1 79
ram54288 0:dbad57390bd1 80 public:
ram54288 0:dbad57390bd1 81
ram54288 0:dbad57390bd1 82 /**
ram54288 0:dbad57390bd1 83 * @brief Destructor
ram54288 0:dbad57390bd1 84 */
ram54288 0:dbad57390bd1 85 virtual ~M2MInterfaceImpl();
ram54288 0:dbad57390bd1 86
ram54288 0:dbad57390bd1 87 /**
ram54288 0:dbad57390bd1 88 * @brief Initiates bootstrapping of the client with the provided Bootstrap
ram54288 0:dbad57390bd1 89 * server information.
ram54288 0:dbad57390bd1 90 * @param security_object Security object which contains information
ram54288 0:dbad57390bd1 91 * required for successful bootstrapping of the client.
ram54288 0:dbad57390bd1 92 */
ram54288 0:dbad57390bd1 93 virtual void bootstrap(M2MSecurity *security);
ram54288 0:dbad57390bd1 94
ram54288 0:dbad57390bd1 95 /**
ram54288 0:dbad57390bd1 96 * @brief Cancels on going bootstrapping operation of the client. If the client has
ram54288 0:dbad57390bd1 97 * already successfully bootstrapped then this function deletes existing
ram54288 0:dbad57390bd1 98 * bootstrap information from the client.
ram54288 0:dbad57390bd1 99 */
ram54288 0:dbad57390bd1 100 virtual void cancel_bootstrap();
ram54288 0:dbad57390bd1 101
ram54288 0:dbad57390bd1 102 /**
ram54288 0:dbad57390bd1 103 * @brief Initiates registration of the provided Security object to the
ram54288 0:dbad57390bd1 104 * corresponding LWM2M server.
ram54288 0:dbad57390bd1 105 * @param security_object Security object which contains information
ram54288 0:dbad57390bd1 106 * required for registering to the LWM2M server.
ram54288 0:dbad57390bd1 107 * If client wants to register to multiple LWM2M servers then it has call
ram54288 0:dbad57390bd1 108 * this function once for each of LWM2M server object separately.
ram54288 0:dbad57390bd1 109 * @param object_list Objects which contains information
ram54288 0:dbad57390bd1 110 * which the client want to register to the LWM2M server.
ram54288 0:dbad57390bd1 111 */
ram54288 0:dbad57390bd1 112 virtual void register_object(M2MSecurity *security_object, const M2MObjectList &object_list);
ram54288 0:dbad57390bd1 113
ram54288 0:dbad57390bd1 114 /**
ram54288 0:dbad57390bd1 115 * @brief Updates or refreshes the client's registration on the LWM2M
ram54288 0:dbad57390bd1 116 * server.
ram54288 0:dbad57390bd1 117 * @param security_object Security object from which the device object
ram54288 0:dbad57390bd1 118 * needs to update registration, if there is only one LWM2M server registered
ram54288 0:dbad57390bd1 119 * then this parameter can be NULL.
ram54288 0:dbad57390bd1 120 * @param lifetime Lifetime for the endpoint client in seconds.
ram54288 0:dbad57390bd1 121 */
ram54288 0:dbad57390bd1 122 virtual void update_registration(M2MSecurity *security_object, const uint32_t lifetime = 0);
ram54288 0:dbad57390bd1 123
ram54288 0:dbad57390bd1 124 /**
ram54288 0:dbad57390bd1 125 * @brief Updates or refreshes the client's registration on the LWM2M
ram54288 0:dbad57390bd1 126 * server. Use this function to publish new objects to LWM2M server.
ram54288 0:dbad57390bd1 127 * @param security_object The security object from which the device object
ram54288 0:dbad57390bd1 128 * needs to update the registration. If there is only one LWM2M server registered,
ram54288 0:dbad57390bd1 129 * this parameter can be NULL.
ram54288 0:dbad57390bd1 130 * @param object_list Objects that contain information about the
ram54288 0:dbad57390bd1 131 * client attempting to register to the LWM2M server.
ram54288 0:dbad57390bd1 132 * @param lifetime The lifetime of the endpoint client in seconds. If the same value
ram54288 0:dbad57390bd1 133 * has to be passed, set the default value to 0.
ram54288 0:dbad57390bd1 134 */
ram54288 0:dbad57390bd1 135 virtual void update_registration(M2MSecurity *security_object, const M2MObjectList &object_list,
ram54288 0:dbad57390bd1 136 const uint32_t lifetime = 0);
ram54288 0:dbad57390bd1 137
ram54288 0:dbad57390bd1 138 /**
ram54288 0:dbad57390bd1 139 * @brief Unregisters the registered object from the LWM2M server
ram54288 0:dbad57390bd1 140 * @param security_object Security object from which the device object
ram54288 0:dbad57390bd1 141 * needs to be unregistered. If there is only one LWM2M server registered
ram54288 0:dbad57390bd1 142 * this parameter can be NULL.
ram54288 0:dbad57390bd1 143 */
ram54288 0:dbad57390bd1 144 virtual void unregister_object(M2MSecurity* security = NULL);
ram54288 0:dbad57390bd1 145
ram54288 0:dbad57390bd1 146 /**
ram54288 0:dbad57390bd1 147 * @brief Sets the function which will be called indicating client
ram54288 0:dbad57390bd1 148 * is going to sleep when the Binding mode is selected with Queue mode.
ram54288 0:dbad57390bd1 149 * @param callback A function pointer that will be called when client
ram54288 0:dbad57390bd1 150 * goes to sleep.
ram54288 0:dbad57390bd1 151 */
ram54288 0:dbad57390bd1 152 virtual void set_queue_sleep_handler(callback_handler handler);
ram54288 0:dbad57390bd1 153
ram54288 0:dbad57390bd1 154 /**
ram54288 0:dbad57390bd1 155 * @brief Sets the network interface handler that is used by client to connect
ram54288 0:dbad57390bd1 156 * to a network over IP.
ram54288 0:dbad57390bd1 157 * @param handler A network interface handler that is used by client to connect.
ram54288 0:dbad57390bd1 158 * This API is optional but provides a mechanism for different platforms to
ram54288 0:dbad57390bd1 159 * manage usage of underlying network interface by client.
ram54288 0:dbad57390bd1 160 */
ram54288 0:dbad57390bd1 161 virtual void set_platform_network_handler(void *handler = NULL);
ram54288 0:dbad57390bd1 162
ram54288 0:dbad57390bd1 163 /**
ram54288 0:dbad57390bd1 164 * \brief Sets the function callback that will be called by mbed-client for
ram54288 0:dbad57390bd1 165 * fetching random number from application for ensuring strong entropy.
ram54288 0:dbad57390bd1 166 * \param random_callback A function pointer that will be called by mbed-client
ram54288 0:dbad57390bd1 167 * while performing secure handshake.
ram54288 0:dbad57390bd1 168 * Function signature should be uint32_t (*random_number_callback)(void);
ram54288 0:dbad57390bd1 169 */
ram54288 0:dbad57390bd1 170 virtual void set_random_number_callback(random_number_cb callback);
ram54288 0:dbad57390bd1 171
ram54288 0:dbad57390bd1 172 /**
ram54288 0:dbad57390bd1 173 * \brief Sets the function callback that will be called by mbed-client for
ram54288 0:dbad57390bd1 174 * providing entropy source from application for ensuring strong entropy.
ram54288 0:dbad57390bd1 175 * \param entropy_callback A function pointer that will be called by mbed-client
ram54288 0:dbad57390bd1 176 * while performing secure handshake.
ram54288 0:dbad57390bd1 177 * Function signature , if using mbed-client-mbedtls should be
ram54288 0:dbad57390bd1 178 * int (*mbedtls_entropy_f_source_ptr)(void *data, unsigned char *output,
ram54288 0:dbad57390bd1 179 * size_t len, size_t *olen);
ram54288 0:dbad57390bd1 180 */
ram54288 0:dbad57390bd1 181 virtual void set_entropy_callback(entropy_cb callback);
ram54288 0:dbad57390bd1 182
ram54288 0:dbad57390bd1 183
ram54288 0:dbad57390bd1 184 protected: // From M2MNsdlObserver
ram54288 0:dbad57390bd1 185
ram54288 0:dbad57390bd1 186 virtual void coap_message_ready(uint8_t *data_ptr,
ram54288 0:dbad57390bd1 187 uint16_t data_len,
ram54288 0:dbad57390bd1 188 sn_nsdl_addr_s *address_ptr);
ram54288 0:dbad57390bd1 189
ram54288 0:dbad57390bd1 190 virtual void client_registered(M2MServer *server_object);
ram54288 0:dbad57390bd1 191
ram54288 0:dbad57390bd1 192 virtual void registration_updated(const M2MServer &server_object);
ram54288 0:dbad57390bd1 193
ram54288 0:dbad57390bd1 194 virtual void registration_error(uint8_t error_code, bool retry = false);
ram54288 0:dbad57390bd1 195
ram54288 0:dbad57390bd1 196 virtual void client_unregistered();
ram54288 0:dbad57390bd1 197
ram54288 0:dbad57390bd1 198 virtual void bootstrap_done(M2MSecurity *security_object);
ram54288 0:dbad57390bd1 199
ram54288 0:dbad57390bd1 200 virtual void bootstrap_wait(M2MSecurity *security_object);
ram54288 0:dbad57390bd1 201
ram54288 0:dbad57390bd1 202 virtual void bootstrap_error();
ram54288 0:dbad57390bd1 203
ram54288 0:dbad57390bd1 204 virtual void coap_data_processed();
ram54288 0:dbad57390bd1 205
ram54288 0:dbad57390bd1 206 virtual void value_updated(M2MBase *base);
ram54288 0:dbad57390bd1 207
ram54288 0:dbad57390bd1 208 protected: // From M2MConnectionObserver
ram54288 0:dbad57390bd1 209
ram54288 0:dbad57390bd1 210 virtual void data_available(uint8_t* data,
ram54288 0:dbad57390bd1 211 uint16_t data_size,
ram54288 0:dbad57390bd1 212 const M2MConnectionObserver::SocketAddress &address);
ram54288 0:dbad57390bd1 213
ram54288 0:dbad57390bd1 214 virtual void socket_error(uint8_t error_code, bool retry = true);
ram54288 0:dbad57390bd1 215
ram54288 0:dbad57390bd1 216 virtual void address_ready(const M2MConnectionObserver::SocketAddress &address,
ram54288 0:dbad57390bd1 217 M2MConnectionObserver::ServerType server_type,
ram54288 0:dbad57390bd1 218 const uint16_t server_port);
ram54288 0:dbad57390bd1 219
ram54288 0:dbad57390bd1 220 virtual void data_sent();
ram54288 0:dbad57390bd1 221
ram54288 0:dbad57390bd1 222 protected: // from M2MTimerObserver
ram54288 0:dbad57390bd1 223
ram54288 0:dbad57390bd1 224 virtual void timer_expired(M2MTimerObserver::Type type);
ram54288 0:dbad57390bd1 225
ram54288 0:dbad57390bd1 226
ram54288 0:dbad57390bd1 227 private: // state machine state functions
ram54288 0:dbad57390bd1 228
ram54288 0:dbad57390bd1 229 /**
ram54288 0:dbad57390bd1 230 * When the state is Idle.
ram54288 0:dbad57390bd1 231 */
ram54288 0:dbad57390bd1 232 void state_idle(EventData* data);
ram54288 0:dbad57390bd1 233
ram54288 0:dbad57390bd1 234 /**
ram54288 0:dbad57390bd1 235 * When the client starts bootstrap.
ram54288 0:dbad57390bd1 236 */
ram54288 0:dbad57390bd1 237 void state_bootstrap( EventData *data);
ram54288 0:dbad57390bd1 238
ram54288 0:dbad57390bd1 239 /**
ram54288 0:dbad57390bd1 240 * When the bootstrap server address is resolved.
ram54288 0:dbad57390bd1 241 */
ram54288 0:dbad57390bd1 242 void state_bootstrap_address_resolved( EventData *data);
ram54288 0:dbad57390bd1 243
ram54288 0:dbad57390bd1 244 /**
ram54288 0:dbad57390bd1 245 * When the bootstrap resource is created.
ram54288 0:dbad57390bd1 246 */
ram54288 0:dbad57390bd1 247 void state_bootstrap_resource_created( EventData *data);
ram54288 0:dbad57390bd1 248
ram54288 0:dbad57390bd1 249 /**
ram54288 0:dbad57390bd1 250 * When the server has sent response and bootstrapping is done.
ram54288 0:dbad57390bd1 251 */
ram54288 0:dbad57390bd1 252 void state_bootstrapped( EventData *data);
ram54288 0:dbad57390bd1 253
ram54288 0:dbad57390bd1 254 /**
ram54288 0:dbad57390bd1 255 * When the client starts register.
ram54288 0:dbad57390bd1 256 */
ram54288 0:dbad57390bd1 257 void state_register( EventData *data);
ram54288 0:dbad57390bd1 258
ram54288 0:dbad57390bd1 259 /**
ram54288 0:dbad57390bd1 260 * When the server address for register is resolved.
ram54288 0:dbad57390bd1 261 */
ram54288 0:dbad57390bd1 262 void state_register_address_resolved( EventData *data);
ram54288 0:dbad57390bd1 263
ram54288 0:dbad57390bd1 264 /**
ram54288 0:dbad57390bd1 265 * When the client is registered.
ram54288 0:dbad57390bd1 266 */
ram54288 0:dbad57390bd1 267 void state_registered( EventData *data);
ram54288 0:dbad57390bd1 268
ram54288 0:dbad57390bd1 269 /**
ram54288 0:dbad57390bd1 270 * When the client is updating registration.
ram54288 0:dbad57390bd1 271 */
ram54288 0:dbad57390bd1 272 void state_update_registration( EventData *data);
ram54288 0:dbad57390bd1 273
ram54288 0:dbad57390bd1 274 /**
ram54288 0:dbad57390bd1 275 * When the client starts unregister.
ram54288 0:dbad57390bd1 276 */
ram54288 0:dbad57390bd1 277 void state_unregister( EventData *data);
ram54288 0:dbad57390bd1 278
ram54288 0:dbad57390bd1 279 /**
ram54288 0:dbad57390bd1 280 * When the client has been unregistered.
ram54288 0:dbad57390bd1 281 */
ram54288 0:dbad57390bd1 282 void state_unregistered( EventData *data);
ram54288 0:dbad57390bd1 283
ram54288 0:dbad57390bd1 284 /**
ram54288 0:dbad57390bd1 285 * When the coap data is been sent through socket.
ram54288 0:dbad57390bd1 286 */
ram54288 0:dbad57390bd1 287 void state_sending_coap_data( EventData *data);
ram54288 0:dbad57390bd1 288
ram54288 0:dbad57390bd1 289 /**
ram54288 0:dbad57390bd1 290 * When the coap data is sent successfully.
ram54288 0:dbad57390bd1 291 */
ram54288 0:dbad57390bd1 292 void state_coap_data_sent( EventData *data);
ram54288 0:dbad57390bd1 293
ram54288 0:dbad57390bd1 294 /**
ram54288 0:dbad57390bd1 295 * When the socket is receiving coap data.
ram54288 0:dbad57390bd1 296 */
ram54288 0:dbad57390bd1 297 void state_receiving_coap_data( EventData *data);
ram54288 0:dbad57390bd1 298
ram54288 0:dbad57390bd1 299 /**
ram54288 0:dbad57390bd1 300 * When the socket has received coap data.
ram54288 0:dbad57390bd1 301 */
ram54288 0:dbad57390bd1 302 void state_coap_data_received( EventData *data);
ram54288 0:dbad57390bd1 303
ram54288 0:dbad57390bd1 304 /**
ram54288 0:dbad57390bd1 305 * When the coap message is being processed.
ram54288 0:dbad57390bd1 306 */
ram54288 0:dbad57390bd1 307 void state_processing_coap_data( EventData *data);
ram54288 0:dbad57390bd1 308
ram54288 0:dbad57390bd1 309 /**
ram54288 0:dbad57390bd1 310 * When the coap message has been processed.
ram54288 0:dbad57390bd1 311 */
ram54288 0:dbad57390bd1 312 void state_coap_data_processed( EventData *data);
ram54288 0:dbad57390bd1 313
ram54288 0:dbad57390bd1 314 /**
ram54288 0:dbad57390bd1 315 * When the client is waiting to receive or send data.
ram54288 0:dbad57390bd1 316 */
ram54288 0:dbad57390bd1 317 void state_waiting( EventData *data);
ram54288 0:dbad57390bd1 318
ram54288 0:dbad57390bd1 319 /**
ram54288 0:dbad57390bd1 320 * Start registration update.
ram54288 0:dbad57390bd1 321 */
ram54288 0:dbad57390bd1 322 void start_register_update(M2MUpdateRegisterData *data);
ram54288 0:dbad57390bd1 323
ram54288 0:dbad57390bd1 324 /**
ram54288 0:dbad57390bd1 325 * State enumeration order must match the order of state
ram54288 0:dbad57390bd1 326 * method entries in the state map
ram54288 0:dbad57390bd1 327 */
ram54288 0:dbad57390bd1 328 enum E_States {
ram54288 0:dbad57390bd1 329 STATE_IDLE = 0,
ram54288 0:dbad57390bd1 330 STATE_BOOTSTRAP,
ram54288 0:dbad57390bd1 331 STATE_BOOTSTRAP_ADDRESS_RESOLVED,
ram54288 0:dbad57390bd1 332 STATE_BOOTSTRAP_RESOURCE_CREATED,
ram54288 0:dbad57390bd1 333 STATE_BOOTSTRAP_WAIT,
ram54288 0:dbad57390bd1 334 STATE_BOOTSTRAPPED, //5
ram54288 0:dbad57390bd1 335 STATE_REGISTER,
ram54288 0:dbad57390bd1 336 STATE_REGISTER_ADDRESS_RESOLVED,
ram54288 0:dbad57390bd1 337 STATE_REGISTERED,
ram54288 0:dbad57390bd1 338 STATE_UPDATE_REGISTRATION,
ram54288 0:dbad57390bd1 339 STATE_UNREGISTER, //10
ram54288 0:dbad57390bd1 340 STATE_UNREGISTERED,
ram54288 0:dbad57390bd1 341 STATE_SENDING_COAP_DATA,
ram54288 0:dbad57390bd1 342 STATE_COAP_DATA_SENT,
ram54288 0:dbad57390bd1 343 STATE_COAP_DATA_RECEIVED,
ram54288 0:dbad57390bd1 344 STATE_PROCESSING_COAP_DATA, //15
ram54288 0:dbad57390bd1 345 STATE_COAP_DATA_PROCESSED,
ram54288 0:dbad57390bd1 346 STATE_WAITING,
ram54288 0:dbad57390bd1 347 STATE_MAX_STATES
ram54288 0:dbad57390bd1 348 };
ram54288 0:dbad57390bd1 349
ram54288 0:dbad57390bd1 350 /**
ram54288 0:dbad57390bd1 351 * @brief Redirects the state machine to right function.
ram54288 0:dbad57390bd1 352 * @param current_state Current state to be set.
ram54288 0:dbad57390bd1 353 * @param data Data to be passed to the state function.
ram54288 0:dbad57390bd1 354 */
ram54288 0:dbad57390bd1 355 void state_function( uint8_t current_state, EventData* data );
ram54288 0:dbad57390bd1 356
ram54288 0:dbad57390bd1 357 /**
ram54288 0:dbad57390bd1 358 * @brief State Engine maintaining state machine logic.
ram54288 0:dbad57390bd1 359 */
ram54288 0:dbad57390bd1 360 void state_engine(void);
ram54288 0:dbad57390bd1 361
ram54288 0:dbad57390bd1 362 /**
ram54288 0:dbad57390bd1 363 * External event which can trigger the state machine.
ram54288 0:dbad57390bd1 364 * @param New The state to which the state machine should go.
ram54288 0:dbad57390bd1 365 * @param data The data to be passed to the state machine.
ram54288 0:dbad57390bd1 366 */
ram54288 0:dbad57390bd1 367 void external_event(uint8_t, EventData* = NULL);
ram54288 0:dbad57390bd1 368
ram54288 0:dbad57390bd1 369 /**
ram54288 0:dbad57390bd1 370 * Internal event generated by state machine.
ram54288 0:dbad57390bd1 371 * @param New State which the state machine should go to.
ram54288 0:dbad57390bd1 372 * @param data The data to be passed to the state machine.
ram54288 0:dbad57390bd1 373 */
ram54288 0:dbad57390bd1 374 void internal_event(uint8_t, EventData* = NULL);
ram54288 0:dbad57390bd1 375
ram54288 0:dbad57390bd1 376 enum
ram54288 0:dbad57390bd1 377 {
ram54288 0:dbad57390bd1 378 EVENT_IGNORED = 0xFE,
ram54288 0:dbad57390bd1 379 CANNOT_HAPPEN
ram54288 0:dbad57390bd1 380 };
ram54288 0:dbad57390bd1 381
ram54288 0:dbad57390bd1 382 /**
ram54288 0:dbad57390bd1 383 * Helper method for extracting the IP address part and port from the
ram54288 0:dbad57390bd1 384 * given server address.
ram54288 0:dbad57390bd1 385 * @param server_address Source URL (without "coap" or "coaps" prefix).
ram54288 0:dbad57390bd1 386 * @param ip_address The extracted IP.
ram54288 0:dbad57390bd1 387 * @param port The extracted port.
ram54288 0:dbad57390bd1 388 */
ram54288 0:dbad57390bd1 389 static void process_address(const String& server_address, String& ip_address, uint16_t& port);
ram54288 0:dbad57390bd1 390
ram54288 0:dbad57390bd1 391 private:
ram54288 0:dbad57390bd1 392
ram54288 0:dbad57390bd1 393 EventData *_event_data;
ram54288 0:dbad57390bd1 394 M2MTimer *_bootstrap_timer;
ram54288 0:dbad57390bd1 395 uint16_t _server_port;
ram54288 0:dbad57390bd1 396 uint16_t _listen_port;
ram54288 0:dbad57390bd1 397 String _endpoint_type;
ram54288 0:dbad57390bd1 398 String _domain;
ram54288 0:dbad57390bd1 399 int32_t _life_time;
ram54288 0:dbad57390bd1 400 String _context_address;
ram54288 0:dbad57390bd1 401 String _server_ip_address;
ram54288 0:dbad57390bd1 402 M2MSecurity *_register_server; //TODO: to be the list not owned
ram54288 0:dbad57390bd1 403 M2MTimer _queue_sleep_timer;
ram54288 0:dbad57390bd1 404 M2MTimer _retry_timer;
ram54288 0:dbad57390bd1 405 callback_handler _callback_handler;
ram54288 0:dbad57390bd1 406 const uint8_t _max_states;
ram54288 0:dbad57390bd1 407 bool _event_ignored;
ram54288 0:dbad57390bd1 408 bool _event_generated;
ram54288 0:dbad57390bd1 409 bool _reconnecting;
ram54288 0:dbad57390bd1 410 bool _retry_timer_expired;
ram54288 0:dbad57390bd1 411 bool _bootstrapped;
ram54288 0:dbad57390bd1 412 uint8_t _current_state;
ram54288 0:dbad57390bd1 413 uint8_t _retry_count;
ram54288 0:dbad57390bd1 414 BindingMode _binding_mode;
ram54288 0:dbad57390bd1 415 M2MInterfaceObserver &_observer;
ram54288 0:dbad57390bd1 416 M2MConnectionSecurity *_security_connection; // Doesn't own
ram54288 0:dbad57390bd1 417 M2MConnectionHandler _connection_handler;
ram54288 0:dbad57390bd1 418 M2MNsdlInterface _nsdl_interface;
ram54288 0:dbad57390bd1 419 M2MSecurity *_security;
ram54288 0:dbad57390bd1 420
ram54288 0:dbad57390bd1 421 friend class Test_M2MInterfaceImpl;
ram54288 0:dbad57390bd1 422
ram54288 0:dbad57390bd1 423 };
ram54288 0:dbad57390bd1 424
ram54288 0:dbad57390bd1 425 #define BEGIN_TRANSITION_MAP \
ram54288 0:dbad57390bd1 426 static const uint8_t TRANSITIONS[] = {\
ram54288 0:dbad57390bd1 427
ram54288 0:dbad57390bd1 428 #define TRANSITION_MAP_ENTRY(entry)\
ram54288 0:dbad57390bd1 429 entry,
ram54288 0:dbad57390bd1 430
ram54288 0:dbad57390bd1 431 #define END_TRANSITION_MAP(data) \
ram54288 0:dbad57390bd1 432 0 };\
ram54288 0:dbad57390bd1 433 external_event(TRANSITIONS[_current_state], data);
ram54288 0:dbad57390bd1 434
ram54288 0:dbad57390bd1 435 #endif //M2M_INTERFACE_IMPL_H
ram54288 0:dbad57390bd1 436
ram54288 0:dbad57390bd1 437