Etherios Cloud Connector very first porting for mbed. Tested in an LPC1768

Etherios Cloud Connector for Embedded v2.1.0.3 library for mbed. Early porting.

This port is centered mainly in the platform code. So it should work properly with the provided examples of send_data, device_request, data_points, RCI and firmware_update (stub implementation, not a real one... yet ;-)). Filesystem is not implemented yet, and some examples might need changes.

To run, it needs the following libraries: - mbed - mbed-rtos - EthernetInterface

Find more information (and the source code!) about Etherios Cloud Connector for Embedded here: http://www.etherios.com/products/devicecloud/support/connector and in: http://www.etherios.com

Committer:
spastor
Date:
Tue Dec 03 14:10:48 2013 +0000
Revision:
1:908afea5a49d
Parent:
0:1c358ea10753
Use internal Thread.h instead of Threads.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
spastor 0:1c358ea10753 1 /*
spastor 0:1c358ea10753 2 * Copyright (c) 2013 Digi International Inc.,
spastor 0:1c358ea10753 3 * All rights not expressly granted are reserved.
spastor 0:1c358ea10753 4 *
spastor 0:1c358ea10753 5 * This Source Code Form is subject to the terms of the Mozilla Public
spastor 0:1c358ea10753 6 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
spastor 0:1c358ea10753 7 * You can obtain one at http://mozilla.org/MPL/2.0/.
spastor 0:1c358ea10753 8 *
spastor 0:1c358ea10753 9 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
spastor 0:1c358ea10753 10 * =======================================================================
spastor 0:1c358ea10753 11 */
spastor 0:1c358ea10753 12
spastor 0:1c358ea10753 13 static connector_status_t connect_to_cloud(connector_data_t * const connector_ptr, char const * cloud_url)
spastor 0:1c358ea10753 14 {
spastor 0:1c358ea10753 15 connector_status_t result = connector_working;
spastor 0:1c358ea10753 16
spastor 0:1c358ea10753 17 connector_callback_status_t status;
spastor 0:1c358ea10753 18 connector_network_open_t open_data;
spastor 0:1c358ea10753 19
spastor 0:1c358ea10753 20 connector_request_id_t request_id;
spastor 0:1c358ea10753 21
spastor 0:1c358ea10753 22 open_data.device_cloud_url = cloud_url;
spastor 0:1c358ea10753 23 open_data.handle = NULL;
spastor 0:1c358ea10753 24
spastor 0:1c358ea10753 25 request_id.network_request = connector_request_id_network_open;
spastor 0:1c358ea10753 26 status = connector_callback(connector_ptr->callback, connector_class_id_network_tcp, request_id, &open_data);
spastor 0:1c358ea10753 27 ASSERT(status != connector_callback_unrecognized);
spastor 0:1c358ea10753 28 switch (status)
spastor 0:1c358ea10753 29 {
spastor 0:1c358ea10753 30 case connector_callback_continue:
spastor 0:1c358ea10753 31 connector_ptr->edp_data.network_handle = open_data.handle;
spastor 0:1c358ea10753 32 break;
spastor 0:1c358ea10753 33 case connector_callback_abort:
spastor 0:1c358ea10753 34 result = connector_abort;
spastor 0:1c358ea10753 35 break;
spastor 0:1c358ea10753 36
spastor 0:1c358ea10753 37 case connector_callback_unrecognized:
spastor 0:1c358ea10753 38 result = connector_unavailable;
spastor 0:1c358ea10753 39 break;
spastor 0:1c358ea10753 40
spastor 0:1c358ea10753 41 case connector_callback_error:
spastor 0:1c358ea10753 42 result = connector_open_error;
spastor 0:1c358ea10753 43 break;
spastor 0:1c358ea10753 44 case connector_callback_busy:
spastor 0:1c358ea10753 45 result = connector_pending;
spastor 0:1c358ea10753 46 break;
spastor 0:1c358ea10753 47 }
spastor 0:1c358ea10753 48
spastor 0:1c358ea10753 49 return result;
spastor 0:1c358ea10753 50 }
spastor 0:1c358ea10753 51
spastor 0:1c358ea10753 52 static connector_status_t send_version(connector_data_t * connector_ptr, uint16_t const type, uint32_t const version)
spastor 0:1c358ea10753 53 {
spastor 0:1c358ea10753 54 enum edp_version {
spastor 0:1c358ea10753 55 field_define(edp_version, version, uint32_t),
spastor 0:1c358ea10753 56 record_end(edp_version)
spastor 0:1c358ea10753 57 };
spastor 0:1c358ea10753 58 size_t const version_message_size = record_bytes(edp_version);
spastor 0:1c358ea10753 59
spastor 0:1c358ea10753 60 connector_status_t result = connector_pending;
spastor 0:1c358ea10753 61 uint8_t * edp_version;
spastor 0:1c358ea10753 62 uint8_t * packet;
spastor 0:1c358ea10753 63
spastor 0:1c358ea10753 64 /*
spastor 0:1c358ea10753 65 * version packet format:
spastor 0:1c358ea10753 66 * -------------------------
spastor 0:1c358ea10753 67 * | 0 - 1 | 2 - 3 | 4 - 7 |
spastor 0:1c358ea10753 68 * -------------------------
spastor 0:1c358ea10753 69 * | EDP header | version |
spastor 0:1c358ea10753 70 * -------------------------
spastor 0:1c358ea10753 71 */
spastor 0:1c358ea10753 72
spastor 0:1c358ea10753 73 packet = tcp_get_packet_buffer(connector_ptr, E_MSG_MT2_MSG_NUM, &edp_version, NULL);
spastor 0:1c358ea10753 74 if (packet != NULL)
spastor 0:1c358ea10753 75 {
spastor 0:1c358ea10753 76 message_store_be32(edp_version, version, version);
spastor 0:1c358ea10753 77
spastor 0:1c358ea10753 78 result = tcp_initiate_send_packet(connector_ptr, packet, version_message_size,
spastor 0:1c358ea10753 79 type,
spastor 0:1c358ea10753 80 tcp_release_packet_buffer,
spastor 0:1c358ea10753 81 NULL);
spastor 0:1c358ea10753 82 }
spastor 0:1c358ea10753 83
spastor 0:1c358ea10753 84 return result;
spastor 0:1c358ea10753 85 }
spastor 0:1c358ea10753 86
spastor 0:1c358ea10753 87 static connector_status_t receive_edp_version(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 88 {
spastor 0:1c358ea10753 89 #define CLOUD_OVERLOAD_RESPONSE 0x02
spastor 0:1c358ea10753 90
spastor 0:1c358ea10753 91 connector_status_t result;
spastor 0:1c358ea10753 92 uint8_t * ptr;
spastor 0:1c358ea10753 93 connector_buffer_t * packet_buffer;
spastor 0:1c358ea10753 94
spastor 0:1c358ea10753 95 result = tcp_receive_packet(connector_ptr, &packet_buffer);
spastor 0:1c358ea10753 96
spastor 0:1c358ea10753 97 if (result == connector_working && packet_buffer != NULL)
spastor 0:1c358ea10753 98 {
spastor 0:1c358ea10753 99 uint16_t type;
spastor 0:1c358ea10753 100 uint8_t response_code;
spastor 0:1c358ea10753 101 uint8_t * const packet = packet_buffer->buffer;
spastor 0:1c358ea10753 102
spastor 0:1c358ea10753 103 connector_debug_printf("Receive Mt version\n");
spastor 0:1c358ea10753 104 /*
spastor 0:1c358ea10753 105 * MT version response packet format:
spastor 0:1c358ea10753 106 * ---------------
spastor 0:1c358ea10753 107 * |0 - 1 | 2 - 3 |
spastor 0:1c358ea10753 108 * ---------------
spastor 0:1c358ea10753 109 * | Type | length |
spastor 0:1c358ea10753 110 * ---------------
spastor 0:1c358ea10753 111 *
spastor 0:1c358ea10753 112 */
spastor 0:1c358ea10753 113
spastor 0:1c358ea10753 114 ptr = GET_PACKET_DATA_POINTER(packet, PACKET_EDP_HEADER_SIZE);
spastor 0:1c358ea10753 115 {
spastor 0:1c358ea10753 116 uint8_t * edp_header = packet;
spastor 0:1c358ea10753 117 type = message_load_be16(edp_header, type);
spastor 0:1c358ea10753 118 }
spastor 0:1c358ea10753 119 response_code = *ptr;
spastor 0:1c358ea10753 120
spastor 0:1c358ea10753 121 tcp_release_receive_packet(connector_ptr, packet_buffer);
spastor 0:1c358ea10753 122 if (type != E_MSG_MT2_TYPE_VERSION_OK)
spastor 0:1c358ea10753 123 {
spastor 0:1c358ea10753 124 /*
spastor 0:1c358ea10753 125 * The received message is not acceptable.
spastor 0:1c358ea10753 126 */
spastor 0:1c358ea10753 127 switch (type)
spastor 0:1c358ea10753 128 {
spastor 0:1c358ea10753 129 /* Expected MTv2 message types... */
spastor 0:1c358ea10753 130 case E_MSG_MT2_TYPE_LEGACY_EDP_VER_RESP:
spastor 0:1c358ea10753 131 if (response_code == CLOUD_OVERLOAD_RESPONSE) {
spastor 0:1c358ea10753 132 connector_debug_printf("receive_edp_version: MTv2 legacy Cloud responded with overload msg\n");
spastor 0:1c358ea10753 133 }
spastor 0:1c358ea10753 134 else {
spastor 0:1c358ea10753 135 connector_debug_printf("receive_edp_version: MTv2 legacy bad version\n");
spastor 0:1c358ea10753 136 }
spastor 0:1c358ea10753 137 break;
spastor 0:1c358ea10753 138 case E_MSG_MT2_TYPE_VERSION_BAD:
spastor 0:1c358ea10753 139 connector_debug_printf("receive_edp_version: bad version\n");
spastor 0:1c358ea10753 140 break;
spastor 0:1c358ea10753 141 case E_MSG_MT2_TYPE_CLOUD_OVERLOAD:
spastor 0:1c358ea10753 142 connector_debug_printf("receive_edp_version: Device Cloud responded with overload msg\n");
spastor 0:1c358ea10753 143 break;
spastor 0:1c358ea10753 144 /* Unexpected/unknown MTv2 message types... */
spastor 0:1c358ea10753 145 default:
spastor 0:1c358ea10753 146 connector_debug_printf("receive_edp_version: unknown MTv2 message\n");
spastor 0:1c358ea10753 147 }
spastor 0:1c358ea10753 148 /* mt version error. let's notify user.
spastor 0:1c358ea10753 149 *
spastor 0:1c358ea10753 150 * ignore error status callback return value since Device Cloud
spastor 0:1c358ea10753 151 * will close the connection.
spastor 0:1c358ea10753 152 */
spastor 0:1c358ea10753 153 result = connector_abort;
spastor 0:1c358ea10753 154 }
spastor 0:1c358ea10753 155 }
spastor 0:1c358ea10753 156 else if (result == connector_idle) result = connector_pending;
spastor 0:1c358ea10753 157
spastor 0:1c358ea10753 158 return result;
spastor 0:1c358ea10753 159 }
spastor 0:1c358ea10753 160
spastor 0:1c358ea10753 161 static size_t build_keepalive_param(uint8_t * const edp_header, uint16_t const type, uint16_t const value)
spastor 0:1c358ea10753 162 {
spastor 0:1c358ea10753 163 enum edp_keepalive{
spastor 0:1c358ea10753 164 field_define(edp_keepalive, interval, uint16_t),
spastor 0:1c358ea10753 165 record_end(edp_keepalive)
spastor 0:1c358ea10753 166 };
spastor 0:1c358ea10753 167
spastor 0:1c358ea10753 168 size_t const keepalive_size = record_bytes(edp_keepalive);
spastor 0:1c358ea10753 169 uint8_t * edp_keepalive;
spastor 0:1c358ea10753 170
spastor 0:1c358ea10753 171 edp_keepalive = GET_PACKET_DATA_POINTER(edp_header, PACKET_EDP_HEADER_SIZE);
spastor 0:1c358ea10753 172 message_store_be16(edp_header, type, type);
spastor 0:1c358ea10753 173 {
spastor 0:1c358ea10753 174 uint16_t const keepalive_size16 = (uint16_t) keepalive_size;
spastor 0:1c358ea10753 175
spastor 0:1c358ea10753 176 ASSERT(keepalive_size <= UINT16_MAX);
spastor 0:1c358ea10753 177 message_store_be16(edp_header, length, keepalive_size16);
spastor 0:1c358ea10753 178 }
spastor 0:1c358ea10753 179 message_store_be16(edp_keepalive, interval, value);
spastor 0:1c358ea10753 180
spastor 0:1c358ea10753 181
spastor 0:1c358ea10753 182 return (PACKET_EDP_HEADER_SIZE + keepalive_size); /* return count of bytes added to buffer */
spastor 0:1c358ea10753 183 }
spastor 0:1c358ea10753 184
spastor 0:1c358ea10753 185 static connector_status_t send_keepalive(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 186 {
spastor 0:1c358ea10753 187 connector_status_t result = connector_working;
spastor 0:1c358ea10753 188
spastor 0:1c358ea10753 189 uint8_t * ptr;
spastor 0:1c358ea10753 190 uint8_t * packet;
spastor 0:1c358ea10753 191 uint8_t * start_ptr;
spastor 0:1c358ea10753 192 size_t i;
spastor 0:1c358ea10753 193
spastor 0:1c358ea10753 194 struct {
spastor 0:1c358ea10753 195 uint16_t type;
spastor 0:1c358ea10753 196 uint16_t value;
spastor 0:1c358ea10753 197 } keepalive_parameters[3];
spastor 0:1c358ea10753 198
spastor 0:1c358ea10753 199 #define init_param(i, t, v) keepalive_parameters[i].type = (t); keepalive_parameters[i].value = (v)
spastor 0:1c358ea10753 200 init_param(0, E_MSG_MT2_TYPE_KA_RX_INTERVAL, GET_RX_KEEPALIVE_INTERVAL(connector_ptr));
spastor 0:1c358ea10753 201 init_param(1, E_MSG_MT2_TYPE_KA_TX_INTERVAL, GET_TX_KEEPALIVE_INTERVAL(connector_ptr));
spastor 0:1c358ea10753 202 init_param(2, E_MSG_MT2_TYPE_KA_WAIT, GET_WAIT_COUNT(connector_ptr));
spastor 0:1c358ea10753 203 #undef init_param
spastor 0:1c358ea10753 204
spastor 0:1c358ea10753 205 connector_debug_printf("Send keepalive params \n");
spastor 0:1c358ea10753 206 connector_debug_printf("Rx keepalive parameter = %d\n", keepalive_parameters[0].value);
spastor 0:1c358ea10753 207 connector_debug_printf("Tx keepalive parameter = %d\n", keepalive_parameters[1].value);
spastor 0:1c358ea10753 208 connector_debug_printf("Wait Count parameter = %d\n", keepalive_parameters[2].value);
spastor 0:1c358ea10753 209
spastor 0:1c358ea10753 210 packet = tcp_get_packet_buffer(connector_ptr, E_MSG_MT2_MSG_NUM, &ptr, NULL);
spastor 0:1c358ea10753 211 if (packet == NULL)
spastor 0:1c358ea10753 212 {
spastor 0:1c358ea10753 213 result = connector_pending;
spastor 0:1c358ea10753 214 goto done;
spastor 0:1c358ea10753 215 }
spastor 0:1c358ea10753 216 ptr = (uint8_t *)packet;
spastor 0:1c358ea10753 217 start_ptr = ptr;
spastor 0:1c358ea10753 218
spastor 0:1c358ea10753 219 for (i=0; i < asizeof(keepalive_parameters); i++)
spastor 0:1c358ea10753 220 {
spastor 0:1c358ea10753 221 size_t const len = build_keepalive_param(ptr, keepalive_parameters[i].type, keepalive_parameters[i].value);
spastor 0:1c358ea10753 222 ptr += len;
spastor 0:1c358ea10753 223 }
spastor 0:1c358ea10753 224 /* Setting the total_length will enable tcp_send_packet_process.
spastor 0:1c358ea10753 225 * Clear length to 0 for actual length that has been sent.
spastor 0:1c358ea10753 226 */
spastor 0:1c358ea10753 227 {
spastor 0:1c358ea10753 228 size_t const total_packet_length = (size_t)(ptr - start_ptr);
spastor 0:1c358ea10753 229 ASSERT(ptr > start_ptr);
spastor 0:1c358ea10753 230 connector_ptr->edp_data.send_packet.total_length = total_packet_length;
spastor 0:1c358ea10753 231 connector_ptr->edp_data.send_packet.bytes_sent = 0;
spastor 0:1c358ea10753 232 connector_ptr->edp_data.send_packet.ptr = packet;
spastor 0:1c358ea10753 233 connector_ptr->edp_data.send_packet.complete_cb = tcp_release_packet_buffer;
spastor 0:1c358ea10753 234 }
spastor 0:1c358ea10753 235
spastor 0:1c358ea10753 236 done:
spastor 0:1c358ea10753 237 return result;
spastor 0:1c358ea10753 238 }
spastor 0:1c358ea10753 239
spastor 0:1c358ea10753 240 static connector_status_t receive_protocol_version(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 241 {
spastor 0:1c358ea10753 242 enum {
spastor 0:1c358ea10753 243 initialization_version_response_acceptable,
spastor 0:1c358ea10753 244 initialization_version_response_unacceptable,
spastor 0:1c358ea10753 245 initialization_version_response_unavailable
spastor 0:1c358ea10753 246 };
spastor 0:1c358ea10753 247
spastor 0:1c358ea10753 248 connector_status_t result;
spastor 0:1c358ea10753 249 connector_buffer_t * packet_buffer;
spastor 0:1c358ea10753 250
spastor 0:1c358ea10753 251 result = tcp_receive_packet(connector_ptr, &packet_buffer);
spastor 0:1c358ea10753 252
spastor 0:1c358ea10753 253 if (result == connector_working)
spastor 0:1c358ea10753 254 {
spastor 0:1c358ea10753 255 uint8_t * edp_header;
spastor 0:1c358ea10753 256
spastor 0:1c358ea10753 257 ASSERT(packet_buffer != NULL);
spastor 0:1c358ea10753 258
spastor 0:1c358ea10753 259 edp_header = packet_buffer->buffer;
spastor 0:1c358ea10753 260
spastor 0:1c358ea10753 261 connector_debug_printf("Receive protocol version\n");
spastor 0:1c358ea10753 262 /*
spastor 0:1c358ea10753 263 * version response packet format:
spastor 0:1c358ea10753 264 * ---------------------------------------
spastor 0:1c358ea10753 265 * | 0 - 1 | 2 - 3 | 4 |
spastor 0:1c358ea10753 266 * ---------------------------------------
spastor 0:1c358ea10753 267 * | Payload Type | length | response code |
spastor 0:1c358ea10753 268 * ----------------------------------------
spastor 0:1c358ea10753 269 */
spastor 0:1c358ea10753 270 /*
spastor 0:1c358ea10753 271 * Empty data packet
spastor 0:1c358ea10753 272 */
spastor 0:1c358ea10753 273 if (message_load_be16(edp_header, length) > 0)
spastor 0:1c358ea10753 274 {
spastor 0:1c358ea10753 275 uint8_t * const response_code = GET_PACKET_DATA_POINTER(edp_header, PACKET_EDP_HEADER_SIZE);
spastor 0:1c358ea10753 276 /* Parse the version response (0 = version response ok).
spastor 0:1c358ea10753 277 * If the protocol version number was not acceptable to Device Cloud,
spastor 0:1c358ea10753 278 * tell the application.
spastor 0:1c358ea10753 279 */
spastor 0:1c358ea10753 280 if (*response_code != initialization_version_response_acceptable)
spastor 0:1c358ea10753 281 {
spastor 0:1c358ea10753 282 edp_set_close_status(connector_ptr, connector_close_status_abort);
spastor 0:1c358ea10753 283 connector_debug_printf("receive_protocol_version:version is not accepted by Device Cloud\n");
spastor 0:1c358ea10753 284 edp_set_active_state(connector_ptr, connector_transport_close);
spastor 0:1c358ea10753 285 }
spastor 0:1c358ea10753 286 }
spastor 0:1c358ea10753 287
spastor 0:1c358ea10753 288 tcp_release_receive_packet(connector_ptr, packet_buffer);
spastor 0:1c358ea10753 289 }
spastor 0:1c358ea10753 290 else if (result == connector_idle) result = connector_pending;
spastor 0:1c358ea10753 291
spastor 0:1c358ea10753 292 return result;
spastor 0:1c358ea10753 293 }
spastor 0:1c358ea10753 294
spastor 0:1c358ea10753 295 static connector_status_t send_identity_verification(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 296 {
spastor 0:1c358ea10753 297 /* The security operations other than encryption... */
spastor 0:1c358ea10753 298 #define SECURITY_OPER_IDENT_FORM UINT32_C(0x80)
spastor 0:1c358ea10753 299
spastor 0:1c358ea10753 300 /* Identity verification form codes... */
spastor 0:1c358ea10753 301 #define SECURITY_IDENT_FORM_SIMPLE UINT32_C(0x00) /* simple verification */
spastor 0:1c358ea10753 302 #define SECURITY_IDENT_FORM_PASSWORD UINT32_C(0x02) /* password verification */
spastor 0:1c358ea10753 303
spastor 0:1c358ea10753 304 enum edp_security {
spastor 0:1c358ea10753 305 field_define(edp_security, opcode, uint8_t),
spastor 0:1c358ea10753 306 field_define(edp_security, identity, uint8_t),
spastor 0:1c358ea10753 307 record_end(edp_security)
spastor 0:1c358ea10753 308 };
spastor 0:1c358ea10753 309
spastor 0:1c358ea10753 310 connector_status_t result;
spastor 0:1c358ea10753 311 size_t const edp_security_size = record_bytes(edp_security);
spastor 0:1c358ea10753 312 uint8_t * edp_security;
spastor 0:1c358ea10753 313 uint8_t * edp_header;
spastor 0:1c358ea10753 314 uint8_t identity = SECURITY_IDENT_FORM_SIMPLE;
spastor 0:1c358ea10753 315
spastor 0:1c358ea10753 316 edp_header = tcp_get_packet_buffer(connector_ptr, E_MSG_MT2_MSG_NUM, &edp_security, NULL);
spastor 0:1c358ea10753 317 if (edp_header == NULL)
spastor 0:1c358ea10753 318 {
spastor 0:1c358ea10753 319 result = connector_pending;
spastor 0:1c358ea10753 320 goto done;
spastor 0:1c358ea10753 321 }
spastor 0:1c358ea10753 322
spastor 0:1c358ea10753 323
spastor 0:1c358ea10753 324 connector_debug_printf("Send identity verification\n");
spastor 0:1c358ea10753 325
spastor 0:1c358ea10753 326 /*
spastor 0:1c358ea10753 327 * packet format:
spastor 0:1c358ea10753 328 * -----------------------------------------------------
spastor 0:1c358ea10753 329 * | 0 - 1 | 2 - 3 | 4 | 5 |
spastor 0:1c358ea10753 330 * -----------------------------------------------------
spastor 0:1c358ea10753 331 * | EDP header | Form opcode | identity verification |
spastor 0:1c358ea10753 332 * -----------------------------------------------------
spastor 0:1c358ea10753 333 */
spastor 0:1c358ea10753 334 message_store_u8(edp_security, opcode, SECURITY_OPER_IDENT_FORM);
spastor 0:1c358ea10753 335
spastor 0:1c358ea10753 336 {
spastor 0:1c358ea10753 337
spastor 0:1c358ea10753 338 #if (defined CONNECTOR_IDENTITY_VERIFICATION)
spastor 0:1c358ea10753 339 connector_identity_verification_t const identity_verification = CONNECTOR_IDENTITY_VERIFICATION;
spastor 0:1c358ea10753 340 #else
spastor 0:1c358ea10753 341 connector_identity_verification_t const identity_verification = connector_ptr->edp_data.config.identity_verification;
spastor 0:1c358ea10753 342 #endif
spastor 0:1c358ea10753 343
spastor 0:1c358ea10753 344 switch (identity_verification)
spastor 0:1c358ea10753 345 {
spastor 0:1c358ea10753 346 case connector_identity_verification_simple:
spastor 0:1c358ea10753 347 identity = SECURITY_IDENT_FORM_SIMPLE;
spastor 0:1c358ea10753 348 break;
spastor 0:1c358ea10753 349 case connector_identity_verification_password:
spastor 0:1c358ea10753 350 identity = SECURITY_IDENT_FORM_PASSWORD;
spastor 0:1c358ea10753 351 break;
spastor 0:1c358ea10753 352 }
spastor 0:1c358ea10753 353 }
spastor 0:1c358ea10753 354
spastor 0:1c358ea10753 355 message_store_u8(edp_security, identity, identity);
spastor 0:1c358ea10753 356
spastor 0:1c358ea10753 357 result = tcp_initiate_send_packet(connector_ptr, edp_header, edp_security_size,
spastor 0:1c358ea10753 358 E_MSG_MT2_TYPE_PAYLOAD,
spastor 0:1c358ea10753 359 tcp_release_packet_buffer,
spastor 0:1c358ea10753 360 NULL);
spastor 0:1c358ea10753 361
spastor 0:1c358ea10753 362 done:
spastor 0:1c358ea10753 363 return result;
spastor 0:1c358ea10753 364 }
spastor 0:1c358ea10753 365
spastor 0:1c358ea10753 366 #if (CONNECTOR_VERSION >= 0x02010000)
spastor 0:1c358ea10753 367 static connector_status_t send_provisioning(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 368 {
spastor 0:1c358ea10753 369 #define SECURITY_OPER_PROVISION_ID 0x89
spastor 0:1c358ea10753 370 #define PROVISION_ID_LENGTH 4
spastor 0:1c358ea10753 371
spastor 0:1c358ea10753 372 enum edp_device_id {
spastor 0:1c358ea10753 373 field_define(edp_provision_id, opcode, uint8_t),
spastor 0:1c358ea10753 374 field_define(edp_provision_id, provision_id, uint32_t),
spastor 0:1c358ea10753 375 record_end(edp_provision_id)
spastor 0:1c358ea10753 376 };
spastor 0:1c358ea10753 377
spastor 0:1c358ea10753 378 connector_status_t result;
spastor 0:1c358ea10753 379 uint8_t * edp_header;
spastor 0:1c358ea10753 380 uint8_t * edp_provision_id;
spastor 0:1c358ea10753 381 size_t const provision_id_message_size = record_bytes(edp_provision_id);
spastor 0:1c358ea10753 382
spastor 0:1c358ea10753 383 edp_header = tcp_get_packet_buffer(connector_ptr, E_MSG_MT2_MSG_NUM, &edp_provision_id, NULL);
spastor 0:1c358ea10753 384 if (edp_header == NULL)
spastor 0:1c358ea10753 385 {
spastor 0:1c358ea10753 386 result = connector_pending;
spastor 0:1c358ea10753 387 goto done;
spastor 0:1c358ea10753 388 }
spastor 0:1c358ea10753 389
spastor 0:1c358ea10753 390 /*
spastor 0:1c358ea10753 391 * packet format:
spastor 0:1c358ea10753 392 * -------------------------------------------------------
spastor 0:1c358ea10753 393 * | 0 - 1 | 2 - 3 | 4 | 5 - 8 |
spastor 0:1c358ea10753 394 * -------------------------------------------------------
spastor 0:1c358ea10753 395 * | EDP header | Provision ID opcode | Provision ID ID |
spastor 0:1c358ea10753 396 * -------------------------------------------------------
spastor 0:1c358ea10753 397 */
spastor 0:1c358ea10753 398 message_store_u8(edp_provision_id, opcode, SECURITY_OPER_PROVISION_ID);
spastor 0:1c358ea10753 399
spastor 0:1c358ea10753 400 #if !(defined CONNECTOR_VENDOR_ID)
spastor 0:1c358ea10753 401 ASSERT(connector_ptr->edp_data.config.vendor_id != 0);
spastor 0:1c358ea10753 402 message_store_be32(edp_provision_id, provision_id, connector_ptr->edp_data.config.vendor_id);
spastor 0:1c358ea10753 403 #else
spastor 0:1c358ea10753 404 message_store_be32(edp_provision_id, provision_id, CONNECTOR_VENDOR_ID);
spastor 0:1c358ea10753 405 #endif
spastor 0:1c358ea10753 406
spastor 0:1c358ea10753 407 result = tcp_initiate_send_packet(connector_ptr, edp_header, provision_id_message_size,
spastor 0:1c358ea10753 408 E_MSG_MT2_TYPE_PAYLOAD, tcp_release_packet_buffer,
spastor 0:1c358ea10753 409 NULL);
spastor 0:1c358ea10753 410 done:
spastor 0:1c358ea10753 411 return result;
spastor 0:1c358ea10753 412 }
spastor 0:1c358ea10753 413 #endif
spastor 0:1c358ea10753 414
spastor 0:1c358ea10753 415 static connector_status_t send_device_id(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 416 {
spastor 0:1c358ea10753 417 #define SECURITY_OPER_DEVICE_ID 0x81
spastor 0:1c358ea10753 418
spastor 0:1c358ea10753 419 enum edp_device_id {
spastor 0:1c358ea10753 420 field_define(edp_device_id, opcode, uint8_t),
spastor 0:1c358ea10753 421 field_define_array(edp_device_id, id, DEVICE_ID_LENGTH),
spastor 0:1c358ea10753 422 record_end(edp_device_id)
spastor 0:1c358ea10753 423 };
spastor 0:1c358ea10753 424
spastor 0:1c358ea10753 425 connector_status_t result;
spastor 0:1c358ea10753 426 uint8_t * edp_header;
spastor 0:1c358ea10753 427 uint8_t * edp_device_id;
spastor 0:1c358ea10753 428 size_t const device_id_message_size = record_bytes(edp_device_id);
spastor 0:1c358ea10753 429
spastor 0:1c358ea10753 430 edp_header = tcp_get_packet_buffer(connector_ptr, E_MSG_MT2_MSG_NUM, &edp_device_id, NULL);
spastor 0:1c358ea10753 431 if (edp_header == NULL)
spastor 0:1c358ea10753 432 {
spastor 0:1c358ea10753 433 result = connector_pending;
spastor 0:1c358ea10753 434 goto done;
spastor 0:1c358ea10753 435 }
spastor 0:1c358ea10753 436
spastor 0:1c358ea10753 437 /*
spastor 0:1c358ea10753 438 * packet format:
spastor 0:1c358ea10753 439 * ----------------------------------------------
spastor 0:1c358ea10753 440 * | 0 - 1 | 2 - 3 | 4 | 5 - 20 |
spastor 0:1c358ea10753 441 * ----------------------------------------------
spastor 0:1c358ea10753 442 * | EDP header | Device ID opcode | Device ID |
spastor 0:1c358ea10753 443 * ----------------------------------------------
spastor 0:1c358ea10753 444 */
spastor 0:1c358ea10753 445 message_store_u8(edp_device_id, opcode, SECURITY_OPER_DEVICE_ID);
spastor 0:1c358ea10753 446
spastor 0:1c358ea10753 447 ASSERT(connector_ptr->device_id != NULL);
spastor 0:1c358ea10753 448 memcpy((edp_device_id + field_named_data(edp_device_id, id, offset)), connector_ptr->device_id, DEVICE_ID_LENGTH);
spastor 0:1c358ea10753 449
spastor 0:1c358ea10753 450 connector_debug_hexvalue("Sending Device ID", connector_ptr->device_id, DEVICE_ID_LENGTH);
spastor 0:1c358ea10753 451
spastor 0:1c358ea10753 452 result = tcp_initiate_send_packet(connector_ptr, edp_header, device_id_message_size,
spastor 0:1c358ea10753 453 E_MSG_MT2_TYPE_PAYLOAD, tcp_release_packet_buffer,
spastor 0:1c358ea10753 454 NULL);
spastor 0:1c358ea10753 455 done:
spastor 0:1c358ea10753 456 return result;
spastor 0:1c358ea10753 457 }
spastor 0:1c358ea10753 458
spastor 0:1c358ea10753 459 #if (CONNECTOR_VERSION >= 0x02010000)
spastor 0:1c358ea10753 460 static connector_status_t receive_device_id(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 461 {
spastor 0:1c358ea10753 462 connector_status_t result;
spastor 0:1c358ea10753 463 connector_buffer_t * packet_buffer;
spastor 0:1c358ea10753 464
spastor 0:1c358ea10753 465 result = tcp_receive_packet(connector_ptr, &packet_buffer);
spastor 0:1c358ea10753 466
spastor 0:1c358ea10753 467 if (result == connector_working)
spastor 0:1c358ea10753 468 {
spastor 0:1c358ea10753 469 uint8_t * edp_header;
spastor 0:1c358ea10753 470
spastor 0:1c358ea10753 471 ASSERT(packet_buffer != NULL);
spastor 0:1c358ea10753 472
spastor 0:1c358ea10753 473 edp_header = packet_buffer->buffer;
spastor 0:1c358ea10753 474
spastor 0:1c358ea10753 475 /*
spastor 0:1c358ea10753 476 * packet format:
spastor 0:1c358ea10753 477 * ----------------------------------------------
spastor 0:1c358ea10753 478 * | 0 - 1 | 2 - 3 | 4 | 5 - 20 |
spastor 0:1c358ea10753 479 * ----------------------------------------------
spastor 0:1c358ea10753 480 * | EDP header | Device ID opcode | Device ID |
spastor 0:1c358ea10753 481 * ----------------------------------------------
spastor 0:1c358ea10753 482 */
spastor 0:1c358ea10753 483 {
spastor 0:1c358ea10753 484 uint8_t * const opcode = GET_PACKET_DATA_POINTER(edp_header, PACKET_EDP_HEADER_SIZE);
spastor 0:1c358ea10753 485
spastor 0:1c358ea10753 486 if (*opcode != SECURITY_OPER_DEVICE_ID)
spastor 0:1c358ea10753 487 {
spastor 0:1c358ea10753 488 /* Device ID error. Notify user. */
spastor 0:1c358ea10753 489 result = connector_abort;
spastor 0:1c358ea10753 490 }
spastor 0:1c358ea10753 491 else
spastor 0:1c358ea10753 492 {
spastor 0:1c358ea10753 493 uint8_t * const device_id = opcode + sizeof(*opcode);
spastor 0:1c358ea10753 494 connector_request_id_t request_id;
spastor 0:1c358ea10753 495 connector_callback_status_t status;
spastor 0:1c358ea10753 496 connector_config_pointer_data_t device_id_data;
spastor 0:1c358ea10753 497
spastor 0:1c358ea10753 498 /* Update internal device_id, needed for future connections */
spastor 0:1c358ea10753 499 memcpy(connector_ptr->device_id, device_id, DEVICE_ID_LENGTH);
spastor 0:1c358ea10753 500 /* Call user function to save the provisioned Device ID */
spastor 0:1c358ea10753 501 device_id_data.bytes_required = DEVICE_ID_LENGTH;
spastor 0:1c358ea10753 502 device_id_data.data = device_id;
spastor 0:1c358ea10753 503
spastor 0:1c358ea10753 504 connector_debug_hexvalue("Received Device ID", device_id, DEVICE_ID_LENGTH);
spastor 0:1c358ea10753 505
spastor 0:1c358ea10753 506 request_id.config_request = connector_request_id_config_set_device_id;
spastor 0:1c358ea10753 507 status = connector_callback(connector_ptr->callback, connector_class_id_config, request_id, &device_id_data);
spastor 0:1c358ea10753 508 switch (status)
spastor 0:1c358ea10753 509 {
spastor 0:1c358ea10753 510 case connector_callback_continue:
spastor 0:1c358ea10753 511 break;
spastor 0:1c358ea10753 512 case connector_callback_abort:
spastor 0:1c358ea10753 513 result = connector_abort;
spastor 0:1c358ea10753 514 break;
spastor 0:1c358ea10753 515 case connector_callback_unrecognized:
spastor 0:1c358ea10753 516 case connector_callback_error:
spastor 0:1c358ea10753 517 result = connector_device_error;
spastor 0:1c358ea10753 518 break;
spastor 0:1c358ea10753 519 case connector_callback_busy:
spastor 0:1c358ea10753 520 result = connector_pending;
spastor 0:1c358ea10753 521 break;
spastor 0:1c358ea10753 522 }
spastor 0:1c358ea10753 523 }
spastor 0:1c358ea10753 524 }
spastor 0:1c358ea10753 525
spastor 0:1c358ea10753 526 tcp_release_receive_packet(connector_ptr, packet_buffer);
spastor 0:1c358ea10753 527 }
spastor 0:1c358ea10753 528 else if (result == connector_idle) result = connector_pending;
spastor 0:1c358ea10753 529
spastor 0:1c358ea10753 530 return result;
spastor 0:1c358ea10753 531 }
spastor 0:1c358ea10753 532 #endif
spastor 0:1c358ea10753 533
spastor 0:1c358ea10753 534 static connector_status_t send_cloud_url(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 535 {
spastor 0:1c358ea10753 536 #define SECURITY_OPER_URL UINT32_C(0x86)
spastor 0:1c358ea10753 537
spastor 0:1c358ea10753 538 /*
spastor 0:1c358ea10753 539 * packet format:
spastor 0:1c358ea10753 540 * ------------------------------------------------
spastor 0:1c358ea10753 541 * | 0 - 1 | 2 - 3 | 4 | 5 - 6 | 7... |
spastor 0:1c358ea10753 542 * ------------------------------------------------
spastor 0:1c358ea10753 543 * | EDP Header | URL opcode | URL length | URL |
spastor 0:1c358ea10753 544 * ------------------------------------------------
spastor 0:1c358ea10753 545 */
spastor 0:1c358ea10753 546 enum edp_cloud_url {
spastor 0:1c358ea10753 547 field_define(edp_cloud_url, opcode, uint8_t),
spastor 0:1c358ea10753 548 field_define(edp_cloud_url, url_length, uint16_t),
spastor 0:1c358ea10753 549 record_end(edp_cloud_url)
spastor 0:1c358ea10753 550 };
spastor 0:1c358ea10753 551 connector_status_t result;
spastor 0:1c358ea10753 552 uint8_t * edp_header;
spastor 0:1c358ea10753 553
spastor 0:1c358ea10753 554 char * cloud_url = connector_ptr->edp_data.config.cloud_url;
spastor 0:1c358ea10753 555 uint8_t * edp_cloud_url;
spastor 0:1c358ea10753 556 uint8_t * start_ptr;
spastor 0:1c358ea10753 557
spastor 0:1c358ea10753 558 static char const url_prefix[] = URL_PREFIX;
spastor 0:1c358ea10753 559 static size_t const prefix_length = sizeof url_prefix -1;
spastor 0:1c358ea10753 560
spastor 0:1c358ea10753 561 edp_header = tcp_get_packet_buffer(connector_ptr, E_MSG_MT2_MSG_NUM, &start_ptr, NULL);
spastor 0:1c358ea10753 562 if (edp_header == NULL)
spastor 0:1c358ea10753 563 {
spastor 0:1c358ea10753 564 result = connector_pending;
spastor 0:1c358ea10753 565 goto done;
spastor 0:1c358ea10753 566 }
spastor 0:1c358ea10753 567
spastor 0:1c358ea10753 568 edp_cloud_url = start_ptr;
spastor 0:1c358ea10753 569
spastor 0:1c358ea10753 570 connector_debug_printf("Send Device Cloud url = %.*s\n", (int)connector_ptr->edp_data.config.cloud_url_length, connector_ptr->edp_data.config.cloud_url);
spastor 0:1c358ea10753 571
spastor 0:1c358ea10753 572 message_store_u8(edp_cloud_url, opcode, SECURITY_OPER_URL);
spastor 0:1c358ea10753 573
spastor 0:1c358ea10753 574 {
spastor 0:1c358ea10753 575 size_t const len = connector_ptr->edp_data.config.cloud_url_length + prefix_length;
spastor 0:1c358ea10753 576 uint16_t const len16 = (uint16_t) len;
spastor 0:1c358ea10753 577
spastor 0:1c358ea10753 578 ASSERT(len <= UINT16_MAX);
spastor 0:1c358ea10753 579 message_store_be16(edp_cloud_url, url_length, len16);
spastor 0:1c358ea10753 580 }
spastor 0:1c358ea10753 581
spastor 0:1c358ea10753 582 edp_cloud_url += record_bytes(edp_cloud_url);
spastor 0:1c358ea10753 583 memcpy(edp_cloud_url, url_prefix, prefix_length);
spastor 0:1c358ea10753 584 edp_cloud_url += prefix_length;
spastor 0:1c358ea10753 585
spastor 0:1c358ea10753 586 memcpy(edp_cloud_url, cloud_url, connector_ptr->edp_data.config.cloud_url_length);
spastor 0:1c358ea10753 587 edp_cloud_url += connector_ptr->edp_data.config.cloud_url_length;
spastor 0:1c358ea10753 588
spastor 0:1c358ea10753 589 {
spastor 0:1c358ea10753 590 size_t const length = (size_t)(edp_cloud_url-start_ptr);
spastor 0:1c358ea10753 591 ASSERT(edp_cloud_url > start_ptr);
spastor 0:1c358ea10753 592
spastor 0:1c358ea10753 593 result = tcp_initiate_send_packet(connector_ptr, edp_header, length,
spastor 0:1c358ea10753 594 E_MSG_MT2_TYPE_PAYLOAD,
spastor 0:1c358ea10753 595 tcp_release_packet_buffer,
spastor 0:1c358ea10753 596 NULL);
spastor 0:1c358ea10753 597 }
spastor 0:1c358ea10753 598 done:
spastor 0:1c358ea10753 599 return result;
spastor 0:1c358ea10753 600 }
spastor 0:1c358ea10753 601
spastor 0:1c358ea10753 602 static connector_status_t send_password(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 603 {
spastor 0:1c358ea10753 604 #define SECURITY_OPER_PASSWORD 0x88
spastor 0:1c358ea10753 605
spastor 0:1c358ea10753 606 /*
spastor 0:1c358ea10753 607 * packet format:
spastor 0:1c358ea10753 608 * -----------------------------------------------------
spastor 0:1c358ea10753 609 * | 0 - 1 | 2 - 3 | 4 | 5 | 7... |
spastor 0:1c358ea10753 610 * -----------------------------------------------------
spastor 0:1c358ea10753 611 * | EDP Header | password opcode | length | password |
spastor 0:1c358ea10753 612 * -----------------------------------------------------
spastor 0:1c358ea10753 613 */
spastor 0:1c358ea10753 614 enum edp_password {
spastor 0:1c358ea10753 615 field_define(edp_password, opcode, uint8_t),
spastor 0:1c358ea10753 616 field_define(edp_password, password_length, uint16_t),
spastor 0:1c358ea10753 617 record_end(edp_password)
spastor 0:1c358ea10753 618 };
spastor 0:1c358ea10753 619 connector_status_t result;
spastor 0:1c358ea10753 620 uint8_t * edp_header;
spastor 0:1c358ea10753 621
spastor 0:1c358ea10753 622 uint8_t * edp_password;
spastor 0:1c358ea10753 623 uint8_t * start_ptr;
spastor 0:1c358ea10753 624
spastor 0:1c358ea10753 625 edp_header = tcp_get_packet_buffer(connector_ptr, E_MSG_MT2_MSG_NUM, &start_ptr, NULL);
spastor 0:1c358ea10753 626 if (edp_header == NULL)
spastor 0:1c358ea10753 627 {
spastor 0:1c358ea10753 628 result = connector_pending;
spastor 0:1c358ea10753 629 goto done;
spastor 0:1c358ea10753 630 }
spastor 0:1c358ea10753 631
spastor 0:1c358ea10753 632 edp_password = start_ptr;
spastor 0:1c358ea10753 633
spastor 0:1c358ea10753 634 message_store_u8(edp_password, opcode, SECURITY_OPER_PASSWORD);
spastor 0:1c358ea10753 635
spastor 0:1c358ea10753 636 {
spastor 0:1c358ea10753 637 uint16_t const length16 = (uint16_t) connector_ptr->edp_data.config.password_length;
spastor 0:1c358ea10753 638
spastor 0:1c358ea10753 639 ASSERT(connector_ptr->edp_data.config.password_length <= UINT16_MAX);
spastor 0:1c358ea10753 640 message_store_be16(edp_password, password_length, length16);
spastor 0:1c358ea10753 641 }
spastor 0:1c358ea10753 642 edp_password += record_bytes(edp_password);
spastor 0:1c358ea10753 643
spastor 0:1c358ea10753 644 memcpy(edp_password, connector_ptr->edp_data.config.password, connector_ptr->edp_data.config.password_length);
spastor 0:1c358ea10753 645 edp_password += connector_ptr->edp_data.config.password_length;
spastor 0:1c358ea10753 646
spastor 0:1c358ea10753 647 {
spastor 0:1c358ea10753 648 size_t const length = (size_t)(edp_password-start_ptr);
spastor 0:1c358ea10753 649
spastor 0:1c358ea10753 650 ASSERT(edp_password > start_ptr);
spastor 0:1c358ea10753 651 result = tcp_initiate_send_packet(connector_ptr, edp_header, length,
spastor 0:1c358ea10753 652 E_MSG_MT2_TYPE_PAYLOAD,
spastor 0:1c358ea10753 653 tcp_release_packet_buffer,
spastor 0:1c358ea10753 654 NULL);
spastor 0:1c358ea10753 655 }
spastor 0:1c358ea10753 656 done:
spastor 0:1c358ea10753 657 return result;
spastor 0:1c358ea10753 658 }
spastor 0:1c358ea10753 659
spastor 0:1c358ea10753 660 static connector_status_t send_vendor_id(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 661 {
spastor 0:1c358ea10753 662 /*
spastor 0:1c358ea10753 663 * packet format:
spastor 0:1c358ea10753 664 * ----------------------------------------------------------------
spastor 0:1c358ea10753 665 * | 0 - 1 | 2 - 3 | 4 | 5 | 6 - 9 |
spastor 0:1c358ea10753 666 * ----------------------------------------------------------------
spastor 0:1c358ea10753 667 * | EDP Header | security coding | vendor ID opcode | vendor ID |
spastor 0:1c358ea10753 668 * ----------------------------------------------------------------
spastor 0:1c358ea10753 669 */
spastor 0:1c358ea10753 670 enum edp_vendor_msg {
spastor 0:1c358ea10753 671 field_define(edp_vendor_msg, security_coding, uint8_t),
spastor 0:1c358ea10753 672 field_define(edp_vendor_msg, opcode, uint8_t),
spastor 0:1c358ea10753 673 field_define(edp_vendor_msg, vendor_id, uint32_t),
spastor 0:1c358ea10753 674 record_end(edp_vendor_msg)
spastor 0:1c358ea10753 675 };
spastor 0:1c358ea10753 676
spastor 0:1c358ea10753 677 connector_status_t result;
spastor 0:1c358ea10753 678 uint8_t * edp_header = NULL;
spastor 0:1c358ea10753 679
spastor 0:1c358ea10753 680 size_t const discovery_vendor_header_size = record_bytes(edp_vendor_msg);
spastor 0:1c358ea10753 681 uint8_t * edp_vendor_msg;
spastor 0:1c358ea10753 682
spastor 0:1c358ea10753 683 edp_header = tcp_get_packet_buffer(connector_ptr, E_MSG_MT2_MSG_NUM, &edp_vendor_msg, NULL);
spastor 0:1c358ea10753 684 if (edp_header == NULL)
spastor 0:1c358ea10753 685 {
spastor 0:1c358ea10753 686 result = connector_pending;
spastor 0:1c358ea10753 687 goto done;
spastor 0:1c358ea10753 688 }
spastor 0:1c358ea10753 689
spastor 0:1c358ea10753 690 message_store_u8(edp_vendor_msg, security_coding, SECURITY_PROTO_NONE);
spastor 0:1c358ea10753 691 message_store_u8(edp_vendor_msg, opcode, DISC_OP_VENDOR_ID);
spastor 0:1c358ea10753 692 #if !(defined CONNECTOR_VENDOR_ID)
spastor 0:1c358ea10753 693 message_store_be32(edp_vendor_msg, vendor_id, connector_ptr->edp_data.config.vendor_id);
spastor 0:1c358ea10753 694 #if (defined CONNECTOR_DEBUG)
spastor 0:1c358ea10753 695 connector_debug_printf("Send vendor id = 0x%08X\n", connector_ptr->edp_data.config.vendor_id);
spastor 0:1c358ea10753 696 #endif
spastor 0:1c358ea10753 697
spastor 0:1c358ea10753 698 #else
spastor 0:1c358ea10753 699 {
spastor 0:1c358ea10753 700 message_store_be32(edp_vendor_msg, vendor_id, CONNECTOR_VENDOR_ID);
spastor 0:1c358ea10753 701 connector_debug_printf("Send vendor id = 0x%08X\n", CONNECTOR_VENDOR_ID);
spastor 0:1c358ea10753 702 }
spastor 0:1c358ea10753 703 #endif
spastor 0:1c358ea10753 704
spastor 0:1c358ea10753 705 result = tcp_initiate_send_packet(connector_ptr, edp_header,
spastor 0:1c358ea10753 706 discovery_vendor_header_size,
spastor 0:1c358ea10753 707 E_MSG_MT2_TYPE_PAYLOAD,
spastor 0:1c358ea10753 708 tcp_release_packet_buffer,
spastor 0:1c358ea10753 709 NULL);
spastor 0:1c358ea10753 710 done:
spastor 0:1c358ea10753 711 return result;
spastor 0:1c358ea10753 712 }
spastor 0:1c358ea10753 713
spastor 0:1c358ea10753 714 static connector_status_t send_device_type(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 715 {
spastor 0:1c358ea10753 716 /*
spastor 0:1c358ea10753 717 * packet format:
spastor 0:1c358ea10753 718 * --------------------------------------------------------------------
spastor 0:1c358ea10753 719 * | 0 - 1 | 2 - 3 | 4 | 5 | 6 - 7 | 8... |
spastor 0:1c358ea10753 720 * --------------------------------------------------------------------
spastor 0:1c358ea10753 721 * | EDP Header | security | device type | Device type | Device type |
spastor 0:1c358ea10753 722 * | | coding | opcode | length | |
spastor 0:1c358ea10753 723 * --------------------------------------------------------------------
spastor 0:1c358ea10753 724 */
spastor 0:1c358ea10753 725 enum edp_device_type_msg {
spastor 0:1c358ea10753 726 field_define(edp_device_type, security_coding, uint8_t),
spastor 0:1c358ea10753 727 field_define(edp_device_type, opcode, uint8_t),
spastor 0:1c358ea10753 728 field_define(edp_device_type, length, uint16_t),
spastor 0:1c358ea10753 729 record_end(edp_device_type)
spastor 0:1c358ea10753 730 };
spastor 0:1c358ea10753 731 size_t const device_type_header_size = record_bytes(edp_device_type);
spastor 0:1c358ea10753 732
spastor 0:1c358ea10753 733 connector_status_t result;
spastor 0:1c358ea10753 734 uint8_t * edp_header = NULL;
spastor 0:1c358ea10753 735 uint8_t * edp_device_type;
spastor 0:1c358ea10753 736
spastor 0:1c358ea10753 737 #if (defined CONNECTOR_DEVICE_TYPE)
spastor 0:1c358ea10753 738 static const char connector_device_type[] = CONNECTOR_DEVICE_TYPE;
spastor 0:1c358ea10753 739 size_t device_type_length = sizeof connector_device_type-1;
spastor 0:1c358ea10753 740 #else
spastor 0:1c358ea10753 741 char * connector_device_type = connector_ptr->edp_data.config.device_type;
spastor 0:1c358ea10753 742 size_t const device_type_length = connector_ptr->edp_data.config.device_type_length;
spastor 0:1c358ea10753 743 #endif
spastor 0:1c358ea10753 744
spastor 0:1c358ea10753 745 edp_header = tcp_get_packet_buffer(connector_ptr, E_MSG_MT2_MSG_NUM, &edp_device_type, NULL);
spastor 0:1c358ea10753 746 if (edp_header == NULL)
spastor 0:1c358ea10753 747 {
spastor 0:1c358ea10753 748 result = connector_pending;
spastor 0:1c358ea10753 749 goto done;
spastor 0:1c358ea10753 750 }
spastor 0:1c358ea10753 751
spastor 0:1c358ea10753 752 message_store_u8(edp_device_type, security_coding, SECURITY_PROTO_NONE);
spastor 0:1c358ea10753 753 message_store_u8(edp_device_type, opcode, DISC_OP_DEVICETYPE);
spastor 0:1c358ea10753 754
spastor 0:1c358ea10753 755 {
spastor 0:1c358ea10753 756 uint16_t const length16 = (uint16_t) device_type_length;
spastor 0:1c358ea10753 757
spastor 0:1c358ea10753 758 ASSERT(device_type_length <= UINT8_MAX); /* Despite the size is a 16-bit integer, the maximum allowed is 255 */
spastor 0:1c358ea10753 759 message_store_be16(edp_device_type, length, length16);
spastor 0:1c358ea10753 760 }
spastor 0:1c358ea10753 761
spastor 0:1c358ea10753 762 edp_device_type += device_type_header_size;
spastor 0:1c358ea10753 763 memcpy(edp_device_type, connector_device_type, device_type_length);
spastor 0:1c358ea10753 764
spastor 0:1c358ea10753 765 connector_debug_printf("Send device type = %.*s\n", (int)device_type_length, connector_device_type);
spastor 0:1c358ea10753 766
spastor 0:1c358ea10753 767 result = tcp_initiate_send_packet(connector_ptr, edp_header,
spastor 0:1c358ea10753 768 (device_type_header_size + device_type_length),
spastor 0:1c358ea10753 769 E_MSG_MT2_TYPE_PAYLOAD,
spastor 0:1c358ea10753 770 tcp_release_packet_buffer,
spastor 0:1c358ea10753 771 NULL);
spastor 0:1c358ea10753 772 done:
spastor 0:1c358ea10753 773 return result;
spastor 0:1c358ea10753 774 }
spastor 0:1c358ea10753 775
spastor 0:1c358ea10753 776 static connector_status_t send_complete(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 777 {
spastor 0:1c358ea10753 778 /*
spastor 0:1c358ea10753 779 * packet format:
spastor 0:1c358ea10753 780 * -----------------------------------------
spastor 0:1c358ea10753 781 * | 0 - 1 | 2 - 3 | 4 | 5 |
spastor 0:1c358ea10753 782 * -----------------------------------------
spastor 0:1c358ea10753 783 * | EDP Header | coding | initialization |
spastor 0:1c358ea10753 784 * | | scheme | done opcode |
spastor 0:1c358ea10753 785 * -----------------------------------------
spastor 0:1c358ea10753 786 */
spastor 0:1c358ea10753 787 enum edp_discovery_complete {
spastor 0:1c358ea10753 788 field_define(edp_discovery_complete, security_coding, uint8_t),
spastor 0:1c358ea10753 789 field_define(edp_discovery_complete, opcode, uint8_t),
spastor 0:1c358ea10753 790 record_end(edp_discovery_complete)
spastor 0:1c358ea10753 791 };
spastor 0:1c358ea10753 792 size_t const discovery_complete_message_size = record_bytes(edp_discovery_complete);
spastor 0:1c358ea10753 793 uint8_t * edp_discovery_complete;
spastor 0:1c358ea10753 794 connector_status_t result;
spastor 0:1c358ea10753 795 uint8_t * edp_header = NULL;
spastor 0:1c358ea10753 796
spastor 0:1c358ea10753 797 edp_header = tcp_get_packet_buffer(connector_ptr, E_MSG_MT2_MSG_NUM, &edp_discovery_complete, NULL);
spastor 0:1c358ea10753 798 if (edp_header == NULL)
spastor 0:1c358ea10753 799 {
spastor 0:1c358ea10753 800 result = connector_pending;
spastor 0:1c358ea10753 801 goto done;
spastor 0:1c358ea10753 802 }
spastor 0:1c358ea10753 803
spastor 0:1c358ea10753 804 connector_debug_printf("Send complete\n");
spastor 0:1c358ea10753 805 message_store_u8(edp_discovery_complete, security_coding, SECURITY_PROTO_NONE);
spastor 0:1c358ea10753 806 message_store_u8(edp_discovery_complete, opcode, DISC_OP_INITCOMPLETE);
spastor 0:1c358ea10753 807
spastor 0:1c358ea10753 808 result = tcp_initiate_send_packet(connector_ptr, edp_header,
spastor 0:1c358ea10753 809 discovery_complete_message_size,
spastor 0:1c358ea10753 810 E_MSG_MT2_TYPE_PAYLOAD,
spastor 0:1c358ea10753 811 tcp_release_packet_buffer,
spastor 0:1c358ea10753 812 NULL);
spastor 0:1c358ea10753 813
spastor 0:1c358ea10753 814 done:
spastor 0:1c358ea10753 815 return result;
spastor 0:1c358ea10753 816 }
spastor 0:1c358ea10753 817
spastor 0:1c358ea10753 818 static connector_status_t layer_discovery_facility(connector_data_t * const connector_ptr);
spastor 0:1c358ea10753 819
spastor 0:1c358ea10753 820 static connector_status_t edp_tcp_open_process(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 821 {
spastor 0:1c358ea10753 822 connector_status_t result = connector_idle;
spastor 0:1c358ea10753 823
spastor 0:1c358ea10753 824 switch (edp_get_edp_state(connector_ptr))
spastor 0:1c358ea10753 825 {
spastor 0:1c358ea10753 826 case edp_communication_connect_to_cloud:
spastor 0:1c358ea10753 827 result = connect_to_cloud(connector_ptr, connector_ptr->edp_data.config.cloud_url);
spastor 0:1c358ea10753 828
spastor 0:1c358ea10753 829 switch(result)
spastor 0:1c358ea10753 830 {
spastor 0:1c358ea10753 831 case connector_working:
spastor 0:1c358ea10753 832 edp_set_edp_state(connector_ptr, edp_communication_send_version);
spastor 0:1c358ea10753 833 connector_ptr->edp_data.send_packet.packet_buffer.in_use = connector_false;
spastor 0:1c358ea10753 834 connector_ptr->edp_data.receive_packet.packet_buffer.in_use = connector_false;
spastor 0:1c358ea10753 835 connector_ptr->edp_data.receive_packet.packet_buffer.next = NULL;
spastor 0:1c358ea10753 836 connector_ptr->edp_data.receive_packet.free_packet_buffer = &connector_ptr->edp_data.receive_packet.packet_buffer;
spastor 0:1c358ea10753 837 break;
spastor 0:1c358ea10753 838 case connector_unavailable:
spastor 0:1c358ea10753 839 edp_set_active_state(connector_ptr, connector_transport_idle);
spastor 0:1c358ea10753 840 connector_ptr->edp_data.stop.auto_connect = connector_false;
spastor 0:1c358ea10753 841 break;
spastor 0:1c358ea10753 842 case connector_open_error:
spastor 0:1c358ea10753 843 {
spastor 0:1c358ea10753 844 connector_ptr->edp_data.connect_at = 0;
spastor 0:1c358ea10753 845 edp_set_active_state(connector_ptr, connector_transport_wait_for_reconnect);
spastor 0:1c358ea10753 846 #if (defined CONNECTOR_NETWORK_TCP_START)
spastor 0:1c358ea10753 847 if (CONNECTOR_NETWORK_TCP_START == connector_connect_manual)
spastor 0:1c358ea10753 848 #else
spastor 0:1c358ea10753 849 if (connector_ptr->edp_data.connect_type == connector_connect_manual)
spastor 0:1c358ea10753 850 #endif
spastor 0:1c358ea10753 851 {
spastor 0:1c358ea10753 852 /* Application must call initiate_action to Start Cloud Connector */
spastor 0:1c358ea10753 853 edp_set_active_state(connector_ptr, connector_transport_idle);
spastor 0:1c358ea10753 854 }
spastor 0:1c358ea10753 855 break;
spastor 0:1c358ea10753 856 }
spastor 0:1c358ea10753 857 case connector_success:
spastor 0:1c358ea10753 858 case connector_init_error:
spastor 0:1c358ea10753 859 case connector_invalid_data_size:
spastor 0:1c358ea10753 860 case connector_invalid_data_range:
spastor 0:1c358ea10753 861 case connector_invalid_data:
spastor 0:1c358ea10753 862 case connector_keepalive_error:
spastor 0:1c358ea10753 863 case connector_bad_version:
spastor 0:1c358ea10753 864 case connector_device_terminated:
spastor 0:1c358ea10753 865 case connector_service_busy:
spastor 0:1c358ea10753 866 case connector_invalid_response:
spastor 0:1c358ea10753 867 case connector_no_resource:
spastor 0:1c358ea10753 868 case connector_idle:
spastor 0:1c358ea10753 869 case connector_pending:
spastor 0:1c358ea10753 870 case connector_active:
spastor 0:1c358ea10753 871 case connector_abort:
spastor 0:1c358ea10753 872 case connector_device_error:
spastor 0:1c358ea10753 873 case connector_exceed_timeout:
spastor 0:1c358ea10753 874 case connector_invalid_payload_packet:
spastor 0:1c358ea10753 875 break;
spastor 0:1c358ea10753 876 }
spastor 0:1c358ea10753 877 break;
spastor 0:1c358ea10753 878
spastor 0:1c358ea10753 879 case edp_communication_send_version:
spastor 0:1c358ea10753 880 case edp_communication_send_keepalive:
spastor 0:1c358ea10753 881 case edp_initialization_send_protocol_version:
spastor 0:1c358ea10753 882 case edp_security_send_identity_verification:
spastor 0:1c358ea10753 883 case edp_security_send_device_id:
spastor 0:1c358ea10753 884 case edp_security_send_device_cloud_url:
spastor 0:1c358ea10753 885 case edp_security_send_password:
spastor 0:1c358ea10753 886 case edp_discovery_send_vendor_id:
spastor 0:1c358ea10753 887 case edp_discovery_send_device_type:
spastor 0:1c358ea10753 888 case edp_discovery_facility:
spastor 0:1c358ea10753 889 case edp_discovery_send_complete:
spastor 0:1c358ea10753 890 {
spastor 0:1c358ea10753 891 connector_edp_state_t next_state = edp_get_edp_state(connector_ptr);
spastor 0:1c358ea10753 892
spastor 0:1c358ea10753 893 switch (edp_get_edp_state(connector_ptr))
spastor 0:1c358ea10753 894 {
spastor 0:1c358ea10753 895 case edp_communication_send_version:
spastor 0:1c358ea10753 896 connector_debug_printf("Send MT Version\n");
spastor 0:1c358ea10753 897 result = send_version(connector_ptr, E_MSG_MT2_TYPE_VERSION, EDP_MT_VERSION);
spastor 0:1c358ea10753 898 if (result == connector_working)
spastor 0:1c358ea10753 899 {
spastor 0:1c358ea10753 900 next_state = edp_communication_receive_version_response;
spastor 0:1c358ea10753 901 }
spastor 0:1c358ea10753 902 break;
spastor 0:1c358ea10753 903
spastor 0:1c358ea10753 904 case edp_communication_send_keepalive:
spastor 0:1c358ea10753 905 result = send_keepalive(connector_ptr);
spastor 0:1c358ea10753 906 if (result == connector_working)
spastor 0:1c358ea10753 907 {
spastor 0:1c358ea10753 908 next_state = edp_initialization_send_protocol_version;
spastor 0:1c358ea10753 909 }
spastor 0:1c358ea10753 910 break;
spastor 0:1c358ea10753 911
spastor 0:1c358ea10753 912 case edp_initialization_send_protocol_version:
spastor 0:1c358ea10753 913 {
spastor 0:1c358ea10753 914 #define EDP_PROTOCOL_VERSION 0x120
spastor 0:1c358ea10753 915
spastor 0:1c358ea10753 916 connector_debug_printf("Send protocol version\n");
spastor 0:1c358ea10753 917 result = send_version(connector_ptr, E_MSG_MT2_TYPE_PAYLOAD, EDP_PROTOCOL_VERSION);
spastor 0:1c358ea10753 918 if (result == connector_working)
spastor 0:1c358ea10753 919 {
spastor 0:1c358ea10753 920 next_state = edp_initialization_receive_protocol_version;
spastor 0:1c358ea10753 921 }
spastor 0:1c358ea10753 922 break;
spastor 0:1c358ea10753 923 }
spastor 0:1c358ea10753 924 case edp_security_send_identity_verification:
spastor 0:1c358ea10753 925 result = send_identity_verification(connector_ptr);
spastor 0:1c358ea10753 926 if (result == connector_working)
spastor 0:1c358ea10753 927 {
spastor 0:1c358ea10753 928 next_state = edp_security_send_device_id;
spastor 0:1c358ea10753 929 }
spastor 0:1c358ea10753 930 break;
spastor 0:1c358ea10753 931 case edp_security_send_device_id:
spastor 0:1c358ea10753 932 #if (CONNECTOR_VERSION >= 0x02010000)
spastor 0:1c358ea10753 933 if (connector_ptr->connector_got_device_id)
spastor 0:1c358ea10753 934 {
spastor 0:1c358ea10753 935 result = send_device_id(connector_ptr);
spastor 0:1c358ea10753 936 if (result == connector_working)
spastor 0:1c358ea10753 937 {
spastor 0:1c358ea10753 938 next_state = edp_security_send_device_cloud_url;
spastor 0:1c358ea10753 939 }
spastor 0:1c358ea10753 940 }
spastor 0:1c358ea10753 941 else
spastor 0:1c358ea10753 942 {
spastor 0:1c358ea10753 943 result = send_provisioning(connector_ptr);
spastor 0:1c358ea10753 944 if (result == connector_working)
spastor 0:1c358ea10753 945 {
spastor 0:1c358ea10753 946 next_state = edp_security_receive_device_id;
spastor 0:1c358ea10753 947 }
spastor 0:1c358ea10753 948 }
spastor 0:1c358ea10753 949 #else
spastor 0:1c358ea10753 950 result = send_device_id(connector_ptr);
spastor 0:1c358ea10753 951 if (result == connector_working)
spastor 0:1c358ea10753 952 next_state = edp_security_send_device_cloud_url;
spastor 0:1c358ea10753 953 #endif
spastor 0:1c358ea10753 954 break;
spastor 0:1c358ea10753 955 case edp_security_send_device_cloud_url:
spastor 0:1c358ea10753 956 result = send_cloud_url(connector_ptr);
spastor 0:1c358ea10753 957 if (result == connector_working)
spastor 0:1c358ea10753 958 {
spastor 0:1c358ea10753 959 #if (defined CONNECTOR_IDENTITY_VERIFICATION)
spastor 0:1c358ea10753 960 next_state = (CONNECTOR_IDENTITY_VERIFICATION == connector_identity_verification_password) ? edp_security_send_password : edp_discovery_send_vendor_id;
spastor 0:1c358ea10753 961 #else
spastor 0:1c358ea10753 962 next_state = (connector_ptr->edp_data.config.identity_verification == connector_identity_verification_password) ? edp_security_send_password : edp_discovery_send_vendor_id;
spastor 0:1c358ea10753 963 #endif
spastor 0:1c358ea10753 964 }
spastor 0:1c358ea10753 965 break;
spastor 0:1c358ea10753 966
spastor 0:1c358ea10753 967 case edp_security_send_password:
spastor 0:1c358ea10753 968 result = send_password(connector_ptr);
spastor 0:1c358ea10753 969 if (result == connector_working)
spastor 0:1c358ea10753 970 {
spastor 0:1c358ea10753 971 next_state = edp_discovery_send_vendor_id;
spastor 0:1c358ea10753 972 }
spastor 0:1c358ea10753 973 break;
spastor 0:1c358ea10753 974
spastor 0:1c358ea10753 975 case edp_discovery_send_vendor_id:
spastor 0:1c358ea10753 976 result = send_vendor_id(connector_ptr);
spastor 0:1c358ea10753 977 if (result == connector_working)
spastor 0:1c358ea10753 978 {
spastor 0:1c358ea10753 979 next_state = edp_discovery_send_device_type;
spastor 0:1c358ea10753 980 }
spastor 0:1c358ea10753 981 break;
spastor 0:1c358ea10753 982
spastor 0:1c358ea10753 983 case edp_discovery_send_device_type:
spastor 0:1c358ea10753 984 result = send_device_type(connector_ptr);
spastor 0:1c358ea10753 985 if (result == connector_working)
spastor 0:1c358ea10753 986 {
spastor 0:1c358ea10753 987 next_state = edp_discovery_facility;
spastor 0:1c358ea10753 988 }
spastor 0:1c358ea10753 989 break;
spastor 0:1c358ea10753 990 case edp_discovery_facility:
spastor 0:1c358ea10753 991 result = layer_discovery_facility(connector_ptr);
spastor 0:1c358ea10753 992
spastor 0:1c358ea10753 993 if (result == connector_working)
spastor 0:1c358ea10753 994 {
spastor 0:1c358ea10753 995 next_state = edp_discovery_send_complete;
spastor 0:1c358ea10753 996 }
spastor 0:1c358ea10753 997 break;
spastor 0:1c358ea10753 998
spastor 0:1c358ea10753 999 case edp_discovery_send_complete:
spastor 0:1c358ea10753 1000 result = send_complete(connector_ptr);
spastor 0:1c358ea10753 1001 break;
spastor 0:1c358ea10753 1002
spastor 0:1c358ea10753 1003 default:
spastor 0:1c358ea10753 1004 break;
spastor 0:1c358ea10753 1005 }
spastor 0:1c358ea10753 1006
spastor 0:1c358ea10753 1007 if (result == connector_working || result == connector_idle || result == connector_pending)
spastor 0:1c358ea10753 1008 {
spastor 0:1c358ea10753 1009 result = edp_tcp_send_process(connector_ptr);
spastor 0:1c358ea10753 1010 if (result == connector_working)
spastor 0:1c358ea10753 1011 {
spastor 0:1c358ea10753 1012 if (edp_get_edp_state(connector_ptr) == edp_discovery_send_complete)
spastor 0:1c358ea10753 1013 {
spastor 0:1c358ea10753 1014 /* we are connected and EDP communication is fully established. */
spastor 0:1c358ea10753 1015 edp_set_edp_state(connector_ptr, edp_facility_process);
spastor 0:1c358ea10753 1016 edp_set_active_state(connector_ptr, connector_transport_receive);
spastor 0:1c358ea10753 1017
spastor 0:1c358ea10753 1018 if (notify_status(connector_ptr->callback, connector_tcp_communication_started) != connector_working)
spastor 0:1c358ea10753 1019 result = connector_abort;
spastor 0:1c358ea10753 1020
spastor 0:1c358ea10753 1021 }
spastor 0:1c358ea10753 1022
spastor 0:1c358ea10753 1023 edp_set_edp_state(connector_ptr, next_state);
spastor 0:1c358ea10753 1024 }
spastor 0:1c358ea10753 1025 }
spastor 0:1c358ea10753 1026
spastor 0:1c358ea10753 1027 goto done;
spastor 0:1c358ea10753 1028 }
spastor 0:1c358ea10753 1029 case edp_communication_receive_version_response:
spastor 0:1c358ea10753 1030 result = receive_edp_version(connector_ptr);
spastor 0:1c358ea10753 1031 if (result == connector_working)
spastor 0:1c358ea10753 1032 {
spastor 0:1c358ea10753 1033 edp_set_edp_state(connector_ptr, edp_communication_send_keepalive);
spastor 0:1c358ea10753 1034 }
spastor 0:1c358ea10753 1035
spastor 0:1c358ea10753 1036 break;
spastor 0:1c358ea10753 1037
spastor 0:1c358ea10753 1038 case edp_initialization_receive_protocol_version:
spastor 0:1c358ea10753 1039 result = receive_protocol_version(connector_ptr);
spastor 0:1c358ea10753 1040 if (result == connector_working)
spastor 0:1c358ea10753 1041 {
spastor 0:1c358ea10753 1042 edp_set_edp_state(connector_ptr, edp_security_send_identity_verification);
spastor 0:1c358ea10753 1043 }
spastor 0:1c358ea10753 1044 break;
spastor 0:1c358ea10753 1045 #if (CONNECTOR_VERSION >= 0x02010000)
spastor 0:1c358ea10753 1046 case edp_security_receive_device_id:
spastor 0:1c358ea10753 1047 result = receive_device_id(connector_ptr);
spastor 0:1c358ea10753 1048 if (result == connector_working)
spastor 0:1c358ea10753 1049 {
spastor 0:1c358ea10753 1050 connector_ptr->connector_got_device_id = connector_true;
spastor 0:1c358ea10753 1051 edp_set_edp_state(connector_ptr, edp_security_send_device_cloud_url);
spastor 0:1c358ea10753 1052 }
spastor 0:1c358ea10753 1053 break;
spastor 0:1c358ea10753 1054 #endif
spastor 0:1c358ea10753 1055 case edp_facility_process:
spastor 0:1c358ea10753 1056 /* Should not be here since active state should not be open state. */
spastor 0:1c358ea10753 1057 ASSERT(connector_false);
spastor 0:1c358ea10753 1058 break;
spastor 0:1c358ea10753 1059 }
spastor 0:1c358ea10753 1060
spastor 0:1c358ea10753 1061 done:
spastor 0:1c358ea10753 1062 if (result != connector_idle && result != connector_pending && result != connector_working)
spastor 0:1c358ea10753 1063 {
spastor 0:1c358ea10753 1064 if (edp_get_edp_state(connector_ptr) != edp_communication_connect_to_cloud)
spastor 0:1c358ea10753 1065 {
spastor 0:1c358ea10753 1066 /* set the close state and make it goes to close connection state */
spastor 0:1c358ea10753 1067 edp_set_close_status(connector_ptr, connector_close_status_device_error);
spastor 0:1c358ea10753 1068 edp_set_active_state(connector_ptr, connector_transport_close);
spastor 0:1c358ea10753 1069 result = connector_working;
spastor 0:1c358ea10753 1070 }
spastor 0:1c358ea10753 1071 }
spastor 0:1c358ea10753 1072 return result;
spastor 0:1c358ea10753 1073 }
spastor 0:1c358ea10753 1074