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 13:34:02 2013 +0000
Revision:
0:1c358ea10753
First commit

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 notify_error_status(connector_callback_t const callback, connector_class_id_t const class_number, connector_request_id_t const request_number, connector_status_t const status)
spastor 0:1c358ea10753 14 {
spastor 0:1c358ea10753 15 connector_status_t result = connector_working;
spastor 0:1c358ea10753 16
spastor 0:1c358ea10753 17 #if (defined CONNECTOR_DEBUG)
spastor 0:1c358ea10753 18 connector_config_error_status_t err_status;
spastor 0:1c358ea10753 19 connector_request_id_t request_id;
spastor 0:1c358ea10753 20
spastor 0:1c358ea10753 21 request_id.config_request = connector_request_id_config_error_status;
spastor 0:1c358ea10753 22 err_status.class_id = class_number;
spastor 0:1c358ea10753 23 err_status.request_id = request_number;
spastor 0:1c358ea10753 24 err_status.status = status;
spastor 0:1c358ea10753 25
spastor 0:1c358ea10753 26 {
spastor 0:1c358ea10753 27 connector_callback_status_t const callback_status = connector_callback(callback, connector_class_id_config, request_id, &err_status);
spastor 0:1c358ea10753 28 switch (callback_status)
spastor 0:1c358ea10753 29 {
spastor 0:1c358ea10753 30 case connector_callback_continue:
spastor 0:1c358ea10753 31 break;
spastor 0:1c358ea10753 32 default:
spastor 0:1c358ea10753 33 result = connector_abort;
spastor 0:1c358ea10753 34 break;
spastor 0:1c358ea10753 35 }
spastor 0:1c358ea10753 36 }
spastor 0:1c358ea10753 37
spastor 0:1c358ea10753 38 #else
spastor 0:1c358ea10753 39 UNUSED_PARAMETER(callback);
spastor 0:1c358ea10753 40 UNUSED_PARAMETER(class_number);
spastor 0:1c358ea10753 41 UNUSED_PARAMETER(request_number);
spastor 0:1c358ea10753 42 UNUSED_PARAMETER(status);
spastor 0:1c358ea10753 43 #endif
spastor 0:1c358ea10753 44 return result;
spastor 0:1c358ea10753 45 }
spastor 0:1c358ea10753 46
spastor 0:1c358ea10753 47 static connector_status_t get_config_device_id(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 48 {
spastor 0:1c358ea10753 49 connector_status_t result = connector_working;
spastor 0:1c358ea10753 50 connector_callback_status_t callback_status;
spastor 0:1c358ea10753 51 connector_request_id_t request_id;
spastor 0:1c358ea10753 52 connector_config_pointer_data_t device_id;
spastor 0:1c358ea10753 53
spastor 0:1c358ea10753 54 device_id.bytes_required = DEVICE_ID_LENGTH;
spastor 0:1c358ea10753 55
spastor 0:1c358ea10753 56 request_id.config_request = connector_request_id_config_device_id;
spastor 0:1c358ea10753 57
spastor 0:1c358ea10753 58 callback_status = connector_callback(connector_ptr->callback, connector_class_id_config, request_id, &device_id);
spastor 0:1c358ea10753 59 switch (callback_status)
spastor 0:1c358ea10753 60 {
spastor 0:1c358ea10753 61 case connector_callback_continue:
spastor 0:1c358ea10753 62 if (device_id.bytes_required != DEVICE_ID_LENGTH)
spastor 0:1c358ea10753 63 result = connector_invalid_data_size;
spastor 0:1c358ea10753 64 /* coverity[uninit_use] */
spastor 0:1c358ea10753 65 else if (device_id.data == NULL)
spastor 0:1c358ea10753 66 result = connector_invalid_data;
spastor 0:1c358ea10753 67 else
spastor 0:1c358ea10753 68 memcpy(connector_ptr->device_id, device_id.data, DEVICE_ID_LENGTH);
spastor 0:1c358ea10753 69 break;
spastor 0:1c358ea10753 70 case connector_callback_busy:
spastor 0:1c358ea10753 71 result = connector_pending;
spastor 0:1c358ea10753 72 break;
spastor 0:1c358ea10753 73 case connector_callback_unrecognized:
spastor 0:1c358ea10753 74 case connector_callback_abort:
spastor 0:1c358ea10753 75 case connector_callback_error:
spastor 0:1c358ea10753 76 result = connector_abort;
spastor 0:1c358ea10753 77 goto done;
spastor 0:1c358ea10753 78 }
spastor 0:1c358ea10753 79
spastor 0:1c358ea10753 80 if (result != connector_working)
spastor 0:1c358ea10753 81 {
spastor 0:1c358ea10753 82 notify_error_status(connector_ptr->callback, connector_class_id_config, request_id, result);
spastor 0:1c358ea10753 83 result = connector_abort;
spastor 0:1c358ea10753 84 }
spastor 0:1c358ea10753 85
spastor 0:1c358ea10753 86 done:
spastor 0:1c358ea10753 87 return result;
spastor 0:1c358ea10753 88 }
spastor 0:1c358ea10753 89
spastor 0:1c358ea10753 90 #if !(defined CONNECTOR_CLOUD_URL)
spastor 0:1c358ea10753 91 static connector_status_t get_config_device_cloud_url(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 92 {
spastor 0:1c358ea10753 93 connector_status_t result = connector_working;
spastor 0:1c358ea10753 94 connector_callback_status_t callback_status;
spastor 0:1c358ea10753 95 connector_config_pointer_string_t cloud_url;
spastor 0:1c358ea10753 96 connector_request_id_t request_id;
spastor 0:1c358ea10753 97
spastor 0:1c358ea10753 98 request_id.config_request = connector_request_id_config_device_cloud_url;
spastor 0:1c358ea10753 99
spastor 0:1c358ea10753 100
spastor 0:1c358ea10753 101 callback_status = connector_callback(connector_ptr->callback, connector_class_id_config, request_id, &cloud_url);
spastor 0:1c358ea10753 102 switch (callback_status)
spastor 0:1c358ea10753 103 {
spastor 0:1c358ea10753 104 case connector_callback_continue:
spastor 0:1c358ea10753 105 /* coverity[uninit_use] */
spastor 0:1c358ea10753 106 if ((cloud_url.length == 0) || (cloud_url.length > CLOUD_URL_LENGTH-1))
spastor 0:1c358ea10753 107 {
spastor 0:1c358ea10753 108 result = connector_invalid_data_size;
spastor 0:1c358ea10753 109 }
spastor 0:1c358ea10753 110 /* coverity[uninit_use] */
spastor 0:1c358ea10753 111 else if (cloud_url.string == NULL)
spastor 0:1c358ea10753 112 {
spastor 0:1c358ea10753 113 result = connector_invalid_data;
spastor 0:1c358ea10753 114 }
spastor 0:1c358ea10753 115 else
spastor 0:1c358ea10753 116 {
spastor 0:1c358ea10753 117 connector_ptr->device_cloud_url_length = cloud_url.length;
spastor 0:1c358ea10753 118 connector_ptr->device_cloud_url = cloud_url.string;
spastor 0:1c358ea10753 119 }
spastor 0:1c358ea10753 120 break;
spastor 0:1c358ea10753 121
spastor 0:1c358ea10753 122 case connector_callback_busy:
spastor 0:1c358ea10753 123 case connector_callback_unrecognized:
spastor 0:1c358ea10753 124 case connector_callback_abort:
spastor 0:1c358ea10753 125 case connector_callback_error:
spastor 0:1c358ea10753 126 result = connector_abort;
spastor 0:1c358ea10753 127 goto done;
spastor 0:1c358ea10753 128 }
spastor 0:1c358ea10753 129
spastor 0:1c358ea10753 130 if (result != connector_working)
spastor 0:1c358ea10753 131 {
spastor 0:1c358ea10753 132 notify_error_status(connector_ptr->callback, connector_class_id_config, request_id, result);
spastor 0:1c358ea10753 133 result = connector_abort;
spastor 0:1c358ea10753 134 }
spastor 0:1c358ea10753 135
spastor 0:1c358ea10753 136 done:
spastor 0:1c358ea10753 137 return result;
spastor 0:1c358ea10753 138 }
spastor 0:1c358ea10753 139 #endif
spastor 0:1c358ea10753 140
spastor 0:1c358ea10753 141 #if (defined CONNECTOR_TRANSPORT_SMS)
spastor 0:1c358ea10753 142 #if (CONNECTOR_VERSION >= 0x02010000)
spastor 0:1c358ea10753 143 #if !(defined CONNECTOR_CLOUD_PHONE)
spastor 0:1c358ea10753 144 static connector_status_t get_config_device_cloud_phone(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 145 {
spastor 0:1c358ea10753 146 connector_status_t result = connector_working;
spastor 0:1c358ea10753 147 connector_callback_status_t callback_status;
spastor 0:1c358ea10753 148 connector_config_pointer_string_t cloud_phone;
spastor 0:1c358ea10753 149 connector_request_id_t request_id;
spastor 0:1c358ea10753 150
spastor 0:1c358ea10753 151 request_id.config_request = connector_request_id_config_get_device_cloud_phone;
spastor 0:1c358ea10753 152
spastor 0:1c358ea10753 153 callback_status = connector_callback(connector_ptr->callback, connector_class_id_config, request_id, &cloud_phone);
spastor 0:1c358ea10753 154 switch (callback_status)
spastor 0:1c358ea10753 155 {
spastor 0:1c358ea10753 156 case connector_callback_continue:
spastor 0:1c358ea10753 157 /* coverity[uninit_use] */
spastor 0:1c358ea10753 158 if (cloud_phone.length == 0)
spastor 0:1c358ea10753 159 {
spastor 0:1c358ea10753 160 result = connector_invalid_data_size;
spastor 0:1c358ea10753 161 }
spastor 0:1c358ea10753 162 /* coverity[uninit_use] */
spastor 0:1c358ea10753 163 else if (cloud_phone.string == NULL)
spastor 0:1c358ea10753 164 {
spastor 0:1c358ea10753 165 result = connector_invalid_data;
spastor 0:1c358ea10753 166 }
spastor 0:1c358ea10753 167 else
spastor 0:1c358ea10753 168 {
spastor 0:1c358ea10753 169 connector_ptr->device_cloud_phone_length = cloud_phone.length;
spastor 0:1c358ea10753 170 connector_ptr->device_cloud_phone = cloud_phone.string;
spastor 0:1c358ea10753 171 }
spastor 0:1c358ea10753 172 break;
spastor 0:1c358ea10753 173
spastor 0:1c358ea10753 174 case connector_callback_busy:
spastor 0:1c358ea10753 175 case connector_callback_unrecognized:
spastor 0:1c358ea10753 176 case connector_callback_abort:
spastor 0:1c358ea10753 177 case connector_callback_error:
spastor 0:1c358ea10753 178 result = connector_abort;
spastor 0:1c358ea10753 179 goto done;
spastor 0:1c358ea10753 180 }
spastor 0:1c358ea10753 181
spastor 0:1c358ea10753 182 if (result != connector_working)
spastor 0:1c358ea10753 183 {
spastor 0:1c358ea10753 184 notify_error_status(connector_ptr->callback, connector_class_id_config, request_id, result);
spastor 0:1c358ea10753 185 result = connector_abort;
spastor 0:1c358ea10753 186 }
spastor 0:1c358ea10753 187
spastor 0:1c358ea10753 188 done:
spastor 0:1c358ea10753 189 return result;
spastor 0:1c358ea10753 190 }
spastor 0:1c358ea10753 191
spastor 0:1c358ea10753 192 /* This function will only be called under SMS transport when a 'provisioning' message is received */
spastor 0:1c358ea10753 193 static connector_status_t set_config_device_cloud_phone(connector_data_t * const connector_ptr, char * phone_number)
spastor 0:1c358ea10753 194 {
spastor 0:1c358ea10753 195 connector_status_t result = connector_working;
spastor 0:1c358ea10753 196 connector_callback_status_t callback_status;
spastor 0:1c358ea10753 197 connector_config_pointer_string_t cloud_phone;
spastor 0:1c358ea10753 198 connector_request_id_t request_id;
spastor 0:1c358ea10753 199
spastor 0:1c358ea10753 200 request_id.config_request = connector_request_id_config_set_device_cloud_phone;
spastor 0:1c358ea10753 201
spastor 0:1c358ea10753 202 cloud_phone.string = phone_number;
spastor 0:1c358ea10753 203 cloud_phone.length = strlen(phone_number);
spastor 0:1c358ea10753 204
spastor 0:1c358ea10753 205 callback_status = connector_callback(connector_ptr->callback, connector_class_id_config, request_id, &cloud_phone);
spastor 0:1c358ea10753 206 switch (callback_status)
spastor 0:1c358ea10753 207 {
spastor 0:1c358ea10753 208 case connector_callback_continue:
spastor 0:1c358ea10753 209 /* User may have changed the pointer during reconfiguration... So reload it again */
spastor 0:1c358ea10753 210 get_config_device_cloud_phone(connector_ptr);
spastor 0:1c358ea10753 211 break;
spastor 0:1c358ea10753 212
spastor 0:1c358ea10753 213 case connector_callback_busy:
spastor 0:1c358ea10753 214 case connector_callback_unrecognized:
spastor 0:1c358ea10753 215 case connector_callback_abort:
spastor 0:1c358ea10753 216 case connector_callback_error:
spastor 0:1c358ea10753 217 result = connector_abort;
spastor 0:1c358ea10753 218 goto error;
spastor 0:1c358ea10753 219 }
spastor 0:1c358ea10753 220 error:
spastor 0:1c358ea10753 221 if (result != connector_working)
spastor 0:1c358ea10753 222 {
spastor 0:1c358ea10753 223 notify_error_status(connector_ptr->callback, connector_class_id_config, request_id, result);
spastor 0:1c358ea10753 224 result = connector_abort;
spastor 0:1c358ea10753 225 }
spastor 0:1c358ea10753 226
spastor 0:1c358ea10753 227 return result;
spastor 0:1c358ea10753 228 }
spastor 0:1c358ea10753 229 #endif
spastor 0:1c358ea10753 230
spastor 0:1c358ea10753 231 #if !(defined CONNECTOR_CLOUD_SERVICE_ID)
spastor 0:1c358ea10753 232 static connector_status_t get_config_device_cloud_service_id(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 233 {
spastor 0:1c358ea10753 234 connector_status_t result = connector_working;
spastor 0:1c358ea10753 235 connector_callback_status_t callback_status;
spastor 0:1c358ea10753 236 connector_config_pointer_string_t cloud_service_id;
spastor 0:1c358ea10753 237 connector_request_id_t request_id;
spastor 0:1c358ea10753 238
spastor 0:1c358ea10753 239 request_id.config_request = connector_request_id_config_device_cloud_service_id;
spastor 0:1c358ea10753 240
spastor 0:1c358ea10753 241 callback_status = connector_callback(connector_ptr->callback, connector_class_id_config, request_id, &cloud_service_id);
spastor 0:1c358ea10753 242 switch (callback_status)
spastor 0:1c358ea10753 243 {
spastor 0:1c358ea10753 244 case connector_callback_continue:
spastor 0:1c358ea10753 245 /* coverity[uninit_use] */
spastor 0:1c358ea10753 246 if (cloud_service_id.string == NULL)
spastor 0:1c358ea10753 247 {
spastor 0:1c358ea10753 248 result = connector_invalid_data;
spastor 0:1c358ea10753 249 }
spastor 0:1c358ea10753 250 else
spastor 0:1c358ea10753 251 {
spastor 0:1c358ea10753 252 connector_ptr->device_cloud_service_id_length = cloud_service_id.length;
spastor 0:1c358ea10753 253 connector_ptr->device_cloud_service_id = cloud_service_id.string;
spastor 0:1c358ea10753 254 }
spastor 0:1c358ea10753 255 break;
spastor 0:1c358ea10753 256
spastor 0:1c358ea10753 257 case connector_callback_busy:
spastor 0:1c358ea10753 258 case connector_callback_unrecognized:
spastor 0:1c358ea10753 259 case connector_callback_abort:
spastor 0:1c358ea10753 260 case connector_callback_error:
spastor 0:1c358ea10753 261 result = connector_abort;
spastor 0:1c358ea10753 262 goto done;
spastor 0:1c358ea10753 263 }
spastor 0:1c358ea10753 264
spastor 0:1c358ea10753 265 if (result != connector_working)
spastor 0:1c358ea10753 266 {
spastor 0:1c358ea10753 267 notify_error_status(connector_ptr->callback, connector_class_id_config, request_id, result);
spastor 0:1c358ea10753 268 result = connector_abort;
spastor 0:1c358ea10753 269 }
spastor 0:1c358ea10753 270
spastor 0:1c358ea10753 271 done:
spastor 0:1c358ea10753 272 return result;
spastor 0:1c358ea10753 273 }
spastor 0:1c358ea10753 274 #endif
spastor 0:1c358ea10753 275 #endif
spastor 0:1c358ea10753 276 #endif
spastor 0:1c358ea10753 277
spastor 0:1c358ea10753 278 static connector_status_t get_config_connection_type(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 279 {
spastor 0:1c358ea10753 280 connector_status_t result = connector_working;
spastor 0:1c358ea10753 281
spastor 0:1c358ea10753 282 #if (defined CONNECTOR_CONNECTION_TYPE)
spastor 0:1c358ea10753 283 ASSERT((CONNECTOR_CONNECTION_TYPE == connector_connection_type_lan) || (CONNECTOR_CONNECTION_TYPE == connector_connection_type_wan));
spastor 0:1c358ea10753 284 connector_ptr->connection_type = CONNECTOR_CONNECTION_TYPE;
spastor 0:1c358ea10753 285 #else
spastor 0:1c358ea10753 286 connector_config_connection_type_t config_connection;
spastor 0:1c358ea10753 287 connector_callback_status_t callback_status;
spastor 0:1c358ea10753 288 connector_request_id_t request_id;
spastor 0:1c358ea10753 289
spastor 0:1c358ea10753 290 request_id.config_request = connector_request_id_config_connection_type;
spastor 0:1c358ea10753 291 callback_status = connector_callback(connector_ptr->callback, connector_class_id_config, request_id, &config_connection);
spastor 0:1c358ea10753 292
spastor 0:1c358ea10753 293 switch (callback_status)
spastor 0:1c358ea10753 294 {
spastor 0:1c358ea10753 295 case connector_callback_continue:
spastor 0:1c358ea10753 296
spastor 0:1c358ea10753 297 /* coverity[uninit_use] */
spastor 0:1c358ea10753 298 switch (config_connection.type)
spastor 0:1c358ea10753 299 {
spastor 0:1c358ea10753 300 case connector_connection_type_lan:
spastor 0:1c358ea10753 301 case connector_connection_type_wan:
spastor 0:1c358ea10753 302 connector_ptr->connection_type = config_connection.type;
spastor 0:1c358ea10753 303 break;
spastor 0:1c358ea10753 304
spastor 0:1c358ea10753 305 default:
spastor 0:1c358ea10753 306 notify_error_status(connector_ptr->callback, connector_class_id_config, request_id, connector_invalid_data_range);
spastor 0:1c358ea10753 307 result = connector_abort;
spastor 0:1c358ea10753 308 break;
spastor 0:1c358ea10753 309 }
spastor 0:1c358ea10753 310 break;
spastor 0:1c358ea10753 311
spastor 0:1c358ea10753 312 case connector_callback_busy:
spastor 0:1c358ea10753 313 result = connector_pending;
spastor 0:1c358ea10753 314 break;
spastor 0:1c358ea10753 315
spastor 0:1c358ea10753 316 case connector_callback_unrecognized:
spastor 0:1c358ea10753 317 case connector_callback_abort:
spastor 0:1c358ea10753 318 case connector_callback_error:
spastor 0:1c358ea10753 319 result = connector_abort;
spastor 0:1c358ea10753 320 break;
spastor 0:1c358ea10753 321 }
spastor 0:1c358ea10753 322 #endif
spastor 0:1c358ea10753 323
spastor 0:1c358ea10753 324 return result;
spastor 0:1c358ea10753 325 }
spastor 0:1c358ea10753 326
spastor 0:1c358ea10753 327 static connector_status_t get_config_mac_addr(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 328 {
spastor 0:1c358ea10753 329 connector_status_t result = connector_working;
spastor 0:1c358ea10753 330
spastor 0:1c358ea10753 331 if (connector_ptr->mac_addr == NULL)
spastor 0:1c358ea10753 332 {
spastor 0:1c358ea10753 333 connector_callback_status_t callback_status;
spastor 0:1c358ea10753 334 connector_request_id_t request_id;
spastor 0:1c358ea10753 335 connector_config_pointer_data_t mac_addr;
spastor 0:1c358ea10753 336
spastor 0:1c358ea10753 337 mac_addr.bytes_required = MAC_ADDR_LENGTH;
spastor 0:1c358ea10753 338
spastor 0:1c358ea10753 339 request_id.config_request = connector_request_id_config_mac_addr;
spastor 0:1c358ea10753 340
spastor 0:1c358ea10753 341 callback_status = connector_callback(connector_ptr->callback, connector_class_id_config, request_id, &mac_addr);
spastor 0:1c358ea10753 342 switch (callback_status)
spastor 0:1c358ea10753 343 {
spastor 0:1c358ea10753 344 case connector_callback_continue:
spastor 0:1c358ea10753 345 if (mac_addr.bytes_required != MAC_ADDR_LENGTH)
spastor 0:1c358ea10753 346 result = connector_invalid_data_size;
spastor 0:1c358ea10753 347 /* coverity[uninit_use] */
spastor 0:1c358ea10753 348 else if (mac_addr.data == NULL)
spastor 0:1c358ea10753 349 result = connector_invalid_data;
spastor 0:1c358ea10753 350 else
spastor 0:1c358ea10753 351 connector_ptr->mac_addr = mac_addr.data;
spastor 0:1c358ea10753 352 break;
spastor 0:1c358ea10753 353
spastor 0:1c358ea10753 354 case connector_callback_busy:
spastor 0:1c358ea10753 355 case connector_callback_unrecognized:
spastor 0:1c358ea10753 356 case connector_callback_abort:
spastor 0:1c358ea10753 357 case connector_callback_error:
spastor 0:1c358ea10753 358 result = connector_abort;
spastor 0:1c358ea10753 359 goto done;
spastor 0:1c358ea10753 360 }
spastor 0:1c358ea10753 361
spastor 0:1c358ea10753 362 if (result != connector_working)
spastor 0:1c358ea10753 363 {
spastor 0:1c358ea10753 364 notify_error_status(connector_ptr->callback, connector_class_id_config, request_id, result);
spastor 0:1c358ea10753 365 result = connector_abort;
spastor 0:1c358ea10753 366 }
spastor 0:1c358ea10753 367 }
spastor 0:1c358ea10753 368
spastor 0:1c358ea10753 369 done:
spastor 0:1c358ea10753 370 return result;
spastor 0:1c358ea10753 371 }
spastor 0:1c358ea10753 372
spastor 0:1c358ea10753 373 #if !(defined CONNECTOR_WAN_LINK_SPEED_IN_BITS_PER_SECOND)
spastor 0:1c358ea10753 374 static connector_status_t get_config_link_speed(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 375 {
spastor 0:1c358ea10753 376 connector_status_t result = connector_working;
spastor 0:1c358ea10753 377 connector_callback_status_t callback_status;
spastor 0:1c358ea10753 378 connector_request_id_t request_id;
spastor 0:1c358ea10753 379 connector_config_link_speed_t config_link;
spastor 0:1c358ea10753 380
spastor 0:1c358ea10753 381 request_id.config_request = connector_request_id_config_link_speed;
spastor 0:1c358ea10753 382
spastor 0:1c358ea10753 383 callback_status = connector_callback(connector_ptr->callback, connector_class_id_config, request_id, &config_link);
spastor 0:1c358ea10753 384 switch (callback_status)
spastor 0:1c358ea10753 385 {
spastor 0:1c358ea10753 386 case connector_callback_continue:
spastor 0:1c358ea10753 387 /* coverity[uninit_use] */
spastor 0:1c358ea10753 388 connector_ptr->link_speed = config_link.speed;
spastor 0:1c358ea10753 389 break;
spastor 0:1c358ea10753 390 case connector_callback_busy:
spastor 0:1c358ea10753 391 case connector_callback_unrecognized:
spastor 0:1c358ea10753 392 case connector_callback_abort:
spastor 0:1c358ea10753 393 case connector_callback_error:
spastor 0:1c358ea10753 394 result = connector_abort;
spastor 0:1c358ea10753 395 break;
spastor 0:1c358ea10753 396 }
spastor 0:1c358ea10753 397 return result;
spastor 0:1c358ea10753 398 }
spastor 0:1c358ea10753 399 #endif
spastor 0:1c358ea10753 400
spastor 0:1c358ea10753 401 #if !(defined CONNECTOR_WAN_PHONE_NUMBER_DIALED)
spastor 0:1c358ea10753 402 static connector_status_t get_config_phone_number(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 403 {
spastor 0:1c358ea10753 404 connector_status_t result = connector_working;
spastor 0:1c358ea10753 405 if (connector_ptr->phone_dialed == NULL)
spastor 0:1c358ea10753 406 {
spastor 0:1c358ea10753 407 connector_callback_status_t callback_status;
spastor 0:1c358ea10753 408 connector_request_id_t request_id;
spastor 0:1c358ea10753 409 connector_config_pointer_string_t phone_number;
spastor 0:1c358ea10753 410
spastor 0:1c358ea10753 411 request_id.config_request = connector_request_id_config_phone_number;
spastor 0:1c358ea10753 412
spastor 0:1c358ea10753 413 callback_status = connector_callback(connector_ptr->callback, connector_class_id_config, request_id, &phone_number);
spastor 0:1c358ea10753 414 switch (callback_status)
spastor 0:1c358ea10753 415 {
spastor 0:1c358ea10753 416 case connector_callback_continue:
spastor 0:1c358ea10753 417 /* coverity[uninit_use] */
spastor 0:1c358ea10753 418 if (phone_number.string == NULL)
spastor 0:1c358ea10753 419 {
spastor 0:1c358ea10753 420 result = connector_invalid_data;
spastor 0:1c358ea10753 421 }
spastor 0:1c358ea10753 422 /* coverity[uninit_use] */
spastor 0:1c358ea10753 423 else if (phone_number.length == 0)
spastor 0:1c358ea10753 424 {
spastor 0:1c358ea10753 425 result = connector_invalid_data_size;
spastor 0:1c358ea10753 426 }
spastor 0:1c358ea10753 427 else
spastor 0:1c358ea10753 428 {
spastor 0:1c358ea10753 429 connector_ptr->phone_dialed_length = phone_number.length;
spastor 0:1c358ea10753 430 connector_ptr->phone_dialed = phone_number.string;
spastor 0:1c358ea10753 431 }
spastor 0:1c358ea10753 432 break;
spastor 0:1c358ea10753 433 case connector_callback_busy:
spastor 0:1c358ea10753 434 case connector_callback_unrecognized:
spastor 0:1c358ea10753 435 case connector_callback_abort:
spastor 0:1c358ea10753 436 case connector_callback_error:
spastor 0:1c358ea10753 437 result = connector_abort;
spastor 0:1c358ea10753 438 goto done;
spastor 0:1c358ea10753 439 }
spastor 0:1c358ea10753 440
spastor 0:1c358ea10753 441 if (result != connector_working)
spastor 0:1c358ea10753 442 {
spastor 0:1c358ea10753 443 notify_error_status(connector_ptr->callback, connector_class_id_config, request_id, result);
spastor 0:1c358ea10753 444 result = connector_abort;
spastor 0:1c358ea10753 445 }
spastor 0:1c358ea10753 446 }
spastor 0:1c358ea10753 447
spastor 0:1c358ea10753 448 done:
spastor 0:1c358ea10753 449 return result;
spastor 0:1c358ea10753 450 }
spastor 0:1c358ea10753 451 #endif
spastor 0:1c358ea10753 452
spastor 0:1c358ea10753 453 static connector_status_t get_config_device_id_method(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 454 {
spastor 0:1c358ea10753 455 connector_status_t result = connector_working;
spastor 0:1c358ea10753 456
spastor 0:1c358ea10753 457 #if (defined CONNECTOR_DEVICE_ID_METHOD)
spastor 0:1c358ea10753 458 ASSERT((CONNECTOR_DEVICE_ID_METHOD == connector_device_id_method_auto) || (CONNECTOR_DEVICE_ID_METHOD == connector_device_id_method_manual));
spastor 0:1c358ea10753 459 connector_ptr->device_id_method = CONNECTOR_DEVICE_ID_METHOD;
spastor 0:1c358ea10753 460 #else
spastor 0:1c358ea10753 461 connector_callback_status_t callback_status;
spastor 0:1c358ea10753 462
spastor 0:1c358ea10753 463 connector_request_id_t request_id;
spastor 0:1c358ea10753 464 connector_config_device_id_method_t device_id;
spastor 0:1c358ea10753 465
spastor 0:1c358ea10753 466 request_id.config_request = connector_request_id_config_device_id_method;
spastor 0:1c358ea10753 467 callback_status = connector_callback(connector_ptr->callback, connector_class_id_config, request_id, &device_id);
spastor 0:1c358ea10753 468 switch (callback_status)
spastor 0:1c358ea10753 469 {
spastor 0:1c358ea10753 470 case connector_callback_continue:
spastor 0:1c358ea10753 471 /* coverity[uninit_use] */
spastor 0:1c358ea10753 472 switch (device_id.method)
spastor 0:1c358ea10753 473 {
spastor 0:1c358ea10753 474 case connector_device_id_method_manual:
spastor 0:1c358ea10753 475 case connector_device_id_method_auto:
spastor 0:1c358ea10753 476 connector_ptr->device_id_method = device_id.method;
spastor 0:1c358ea10753 477 break;
spastor 0:1c358ea10753 478
spastor 0:1c358ea10753 479 default:
spastor 0:1c358ea10753 480 notify_error_status(connector_ptr->callback, connector_class_id_config, request_id, connector_invalid_data_range);
spastor 0:1c358ea10753 481 result = connector_abort;
spastor 0:1c358ea10753 482 break;
spastor 0:1c358ea10753 483 }
spastor 0:1c358ea10753 484 break;
spastor 0:1c358ea10753 485
spastor 0:1c358ea10753 486 case connector_callback_unrecognized:
spastor 0:1c358ea10753 487 connector_ptr->device_id_method = connector_device_id_method_manual;
spastor 0:1c358ea10753 488 break;
spastor 0:1c358ea10753 489
spastor 0:1c358ea10753 490 case connector_callback_busy:
spastor 0:1c358ea10753 491 case connector_callback_abort:
spastor 0:1c358ea10753 492 case connector_callback_error:
spastor 0:1c358ea10753 493 result = connector_abort;
spastor 0:1c358ea10753 494 break;
spastor 0:1c358ea10753 495 }
spastor 0:1c358ea10753 496 #endif
spastor 0:1c358ea10753 497
spastor 0:1c358ea10753 498 return result;
spastor 0:1c358ea10753 499 }
spastor 0:1c358ea10753 500
spastor 0:1c358ea10753 501 #define MAX_DECIMAL_DIGIT 9
spastor 0:1c358ea10753 502 #define MAX_HEXADECIMAL_DIGIT 0xF
spastor 0:1c358ea10753 503
spastor 0:1c358ea10753 504 static connector_bool_t check_digit_array(uint8_t * const digits, size_t const length, uint8_t const max_digit)
spastor 0:1c358ea10753 505 {
spastor 0:1c358ea10753 506 connector_bool_t isDigit = connector_true;
spastor 0:1c358ea10753 507 size_t i;
spastor 0:1c358ea10753 508
spastor 0:1c358ea10753 509 for (i=0; i < length; i++)
spastor 0:1c358ea10753 510 {
spastor 0:1c358ea10753 511 unsigned char const up_digit = (digits[i] >> 4) & 0xF;
spastor 0:1c358ea10753 512 unsigned char const lo_digit = digits[i] & 0x0F;
spastor 0:1c358ea10753 513
spastor 0:1c358ea10753 514 if (up_digit > max_digit || lo_digit > max_digit)
spastor 0:1c358ea10753 515 {
spastor 0:1c358ea10753 516 isDigit = connector_false;
spastor 0:1c358ea10753 517 break;
spastor 0:1c358ea10753 518 }
spastor 0:1c358ea10753 519 }
spastor 0:1c358ea10753 520
spastor 0:1c358ea10753 521 return isDigit;
spastor 0:1c358ea10753 522 }
spastor 0:1c358ea10753 523
spastor 0:1c358ea10753 524 static connector_status_t get_config_wan_id(connector_data_t * const connector_ptr,
spastor 0:1c358ea10753 525 connector_request_id_config_t const config_request_id)
spastor 0:1c358ea10753 526 {
spastor 0:1c358ea10753 527 connector_status_t result = connector_working;
spastor 0:1c358ea10753 528 connector_callback_status_t callback_status;
spastor 0:1c358ea10753 529 connector_config_pointer_data_t request_data;
spastor 0:1c358ea10753 530 size_t bytes_required;
spastor 0:1c358ea10753 531 uint8_t max_digits;
spastor 0:1c358ea10753 532
spastor 0:1c358ea10753 533 connector_request_id_t request_id;
spastor 0:1c358ea10753 534
spastor 0:1c358ea10753 535 switch (config_request_id)
spastor 0:1c358ea10753 536 {
spastor 0:1c358ea10753 537 case connector_request_id_config_imei_number:
spastor 0:1c358ea10753 538 bytes_required = CONNECTOR_GSM_IMEI_LENGTH;
spastor 0:1c358ea10753 539 max_digits = MAX_DECIMAL_DIGIT;
spastor 0:1c358ea10753 540 break;
spastor 0:1c358ea10753 541
spastor 0:1c358ea10753 542 case connector_request_id_config_esn:
spastor 0:1c358ea10753 543 bytes_required = CONNECTOR_ESN_HEX_LENGTH;
spastor 0:1c358ea10753 544 max_digits = MAX_HEXADECIMAL_DIGIT;
spastor 0:1c358ea10753 545 break;
spastor 0:1c358ea10753 546
spastor 0:1c358ea10753 547 case connector_request_id_config_meid:
spastor 0:1c358ea10753 548 bytes_required = CONNECTOR_MEID_HEX_LENGTH;
spastor 0:1c358ea10753 549 max_digits = MAX_HEXADECIMAL_DIGIT;
spastor 0:1c358ea10753 550 break;
spastor 0:1c358ea10753 551
spastor 0:1c358ea10753 552 default:
spastor 0:1c358ea10753 553 ASSERT(connector_false);
spastor 0:1c358ea10753 554 result = connector_abort;
spastor 0:1c358ea10753 555 goto done;
spastor 0:1c358ea10753 556 }
spastor 0:1c358ea10753 557
spastor 0:1c358ea10753 558 request_data.bytes_required = bytes_required;
spastor 0:1c358ea10753 559 request_id.config_request = config_request_id;
spastor 0:1c358ea10753 560
spastor 0:1c358ea10753 561 callback_status = connector_callback(connector_ptr->callback, connector_class_id_config, request_id, &request_data);
spastor 0:1c358ea10753 562 switch (callback_status)
spastor 0:1c358ea10753 563 {
spastor 0:1c358ea10753 564 case connector_callback_continue:
spastor 0:1c358ea10753 565 /* coverity[uninit_use] */
spastor 0:1c358ea10753 566 if (request_data.data == NULL)
spastor 0:1c358ea10753 567 {
spastor 0:1c358ea10753 568 result = connector_invalid_data;
spastor 0:1c358ea10753 569 }
spastor 0:1c358ea10753 570 else if (request_data.bytes_required != bytes_required)
spastor 0:1c358ea10753 571 {
spastor 0:1c358ea10753 572 result = connector_invalid_data_size;
spastor 0:1c358ea10753 573 }
spastor 0:1c358ea10753 574 else if (check_digit_array(request_data.data, request_data.bytes_required, max_digits) != connector_true)
spastor 0:1c358ea10753 575 {
spastor 0:1c358ea10753 576 result = connector_invalid_data_range;
spastor 0:1c358ea10753 577 }
spastor 0:1c358ea10753 578 else
spastor 0:1c358ea10753 579 {
spastor 0:1c358ea10753 580 connector_ptr->wan_id = request_data.data;
spastor 0:1c358ea10753 581 connector_ptr->wan_id_length = bytes_required;
spastor 0:1c358ea10753 582 }
spastor 0:1c358ea10753 583 break;
spastor 0:1c358ea10753 584 case connector_callback_busy:
spastor 0:1c358ea10753 585 case connector_callback_unrecognized:
spastor 0:1c358ea10753 586 case connector_callback_abort:
spastor 0:1c358ea10753 587 case connector_callback_error:
spastor 0:1c358ea10753 588 result = connector_abort;
spastor 0:1c358ea10753 589 goto done;
spastor 0:1c358ea10753 590 }
spastor 0:1c358ea10753 591
spastor 0:1c358ea10753 592 if (result != connector_working)
spastor 0:1c358ea10753 593 {
spastor 0:1c358ea10753 594 notify_error_status(connector_ptr->callback, connector_class_id_config, request_id, result);
spastor 0:1c358ea10753 595 result = connector_abort;
spastor 0:1c358ea10753 596 }
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 get_config_wan_type(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 603 {
spastor 0:1c358ea10753 604 connector_status_t result = connector_working;
spastor 0:1c358ea10753 605 #if (defined CONNECTOR_WAN_TYPE)
spastor 0:1c358ea10753 606 ASSERT((CONNECTOR_WAN_TYPE == connector_wan_type_imei) || (CONNECTOR_WAN_TYPE == connector_wan_type_esn) || (CONNECTOR_WAN_TYPE == connector_wan_type_meid));
spastor 0:1c358ea10753 607 connector_ptr->wan_type = CONNECTOR_WAN_TYPE;
spastor 0:1c358ea10753 608 #else
spastor 0:1c358ea10753 609 connector_callback_status_t callback_status;
spastor 0:1c358ea10753 610 connector_request_id_t request_id;
spastor 0:1c358ea10753 611 connector_config_wan_type_t config_wan;
spastor 0:1c358ea10753 612
spastor 0:1c358ea10753 613
spastor 0:1c358ea10753 614 request_id.config_request = connector_request_id_config_wan_type;
spastor 0:1c358ea10753 615 callback_status = connector_callback(connector_ptr->callback, connector_class_id_config, request_id, &config_wan);
spastor 0:1c358ea10753 616 switch (callback_status)
spastor 0:1c358ea10753 617 {
spastor 0:1c358ea10753 618 case connector_callback_continue:
spastor 0:1c358ea10753 619 /* coverity[uninit_use] */
spastor 0:1c358ea10753 620 switch (config_wan.type)
spastor 0:1c358ea10753 621 {
spastor 0:1c358ea10753 622 case connector_wan_type_imei:
spastor 0:1c358ea10753 623 case connector_wan_type_esn:
spastor 0:1c358ea10753 624 case connector_wan_type_meid:
spastor 0:1c358ea10753 625 connector_ptr->wan_type = config_wan.type;
spastor 0:1c358ea10753 626 break;
spastor 0:1c358ea10753 627 default:
spastor 0:1c358ea10753 628 notify_error_status(connector_ptr->callback, connector_class_id_config, request_id, connector_invalid_data_range);
spastor 0:1c358ea10753 629 result = connector_abort;
spastor 0:1c358ea10753 630 break;
spastor 0:1c358ea10753 631 }
spastor 0:1c358ea10753 632 break;
spastor 0:1c358ea10753 633 case connector_callback_busy:
spastor 0:1c358ea10753 634 case connector_callback_unrecognized:
spastor 0:1c358ea10753 635 case connector_callback_abort:
spastor 0:1c358ea10753 636 case connector_callback_error:
spastor 0:1c358ea10753 637 result = connector_abort;
spastor 0:1c358ea10753 638 break;
spastor 0:1c358ea10753 639 }
spastor 0:1c358ea10753 640 #endif
spastor 0:1c358ea10753 641 return result;
spastor 0:1c358ea10753 642 }
spastor 0:1c358ea10753 643
spastor 0:1c358ea10753 644
spastor 0:1c358ea10753 645