Sebastián Pastor / EtheriosCloudConnector
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers config.c Source File

config.c

00001 /*
00002  * Copyright (c) 2013 Digi International Inc.,
00003  * All rights not expressly granted are reserved.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
00007  * You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
00010  * =======================================================================
00011  */
00012 
00013 #include <ctype.h>
00014 #include "connector_config.h"
00015 #include "connector_debug.h"
00016 #include "connector_api.h"
00017 #include "ecc_platform.h"
00018 
00019 /* Cloud Connector Configuration routines */
00020 
00021 /*
00022  * Routine to get the IP address, you will need to modify this routine for your
00023  * platform.
00024  */
00025 static uint32_t ipaddress(uint32_t a, uint32_t b, uint32_t c, uint32_t d)
00026 {
00027     return ((d & 0xFF) << 24) | ((c & 0xFF) << 16) | ((b & 0xFF) << 8) | (a & 0xFF);
00028 }
00029 static connector_callback_status_t app_get_ip_address(connector_config_ip_address_t * const config_ip)
00030 {
00031     /* Fill in the size and IP address */
00032     static uint32_t ipaddr;
00033     ipaddr = ipaddress(10,101,2,70);
00034     config_ip->ip_address_type = connector_ip_address_ipv4;
00035     config_ip->address = &ipaddr;
00036     
00037     return connector_callback_continue;
00038 }
00039 
00040 #define MAC_ADDR_LENGTH     6
00041 static uint8_t const device_mac_addr[MAC_ADDR_LENGTH] = {0x00, 0x04, 0x9D, 0xAB, 0xCD, 0xEF};
00042 
00043 static connector_callback_status_t app_get_mac_addr(connector_config_pointer_data_t * const config_mac)
00044 {
00045 /*#error "Specify device MAC address for LAN connection"*/
00046     ASSERT(config_mac->bytes_required == MAC_ADDR_LENGTH);
00047 
00048     config_mac->data = (uint8_t *)device_mac_addr;
00049 
00050     return connector_callback_continue;
00051 }
00052 
00053 #define DEVICE_ID_LENGTH    16
00054 #define DEVICE_ID_FILENAME  "device_id.cfg"
00055 #define EXECUTABLE_NAME     "connector"
00056 
00057 static uint8_t provisioned_device_id[DEVICE_ID_LENGTH];
00058 
00059 static connector_callback_status_t app_load_device_id(connector_config_pointer_data_t * const config_device_id)
00060 {
00061     config_device_id->data = provisioned_device_id;
00062 
00063     return connector_callback_continue;
00064 }
00065 
00066 static connector_callback_status_t app_save_device_id(connector_config_pointer_data_t * const config_device_id)
00067 {
00068     memcpy(config_device_id->data, provisioned_device_id, sizeof provisioned_device_id);
00069 
00070     return connector_callback_continue;
00071 }
00072 
00073 #if !(defined CONNECTOR_VENDOR_ID)
00074 static connector_callback_status_t app_get_vendor_id(connector_config_vendor_id_t * const config_vendor)
00075 {
00076 /*#error  "Specify vendor id"*/
00077 
00078     static uint32_t const device_vendor_id = 0x030000DB;
00079     config_vendor->id  =  device_vendor_id;
00080 
00081     return connector_callback_continue;
00082 }
00083 #endif
00084 
00085 #if !(defined CONNECTOR_DEVICE_TYPE)
00086 static connector_callback_status_t app_get_device_type(connector_config_pointer_string_t * const config_device_type)
00087 {
00088     static char const device_type[] = "Linux Application";
00089 
00090     /* Return pointer to device type. */
00091     config_device_type->string = (char *)device_type;
00092     config_device_type->length = sizeof device_type -1;
00093 
00094     return connector_callback_continue;
00095 }
00096 #endif
00097 
00098 #if !(defined CONNECTOR_CLOUD_URL)
00099 static connector_callback_status_t app_get_device_cloud_url(connector_config_pointer_string_t * const config_url)
00100 {
00101     static  char const connector_cloud_url[] = "login.etherios.com";
00102 
00103     config_url->string = (char *)connector_cloud_url;
00104     config_url->length = sizeof connector_cloud_url - 1;
00105 
00106     return connector_callback_continue;
00107 }
00108 #endif
00109 
00110 #if !(defined CONNECTOR_CLOUD_PHONE)
00111 
00112 /* Configure the phone number of the server where to send SMSs.
00113  * Will be updated if a SMSs provisioning message arrives from the server.
00114  * If set to nothing, will require a provisioning message from the server for initialization.
00115  */
00116 static char connector_cloud_phone[] = "447786201216"; /* phone number corresponding to login.etherios.com */
00117 
00118 static connector_callback_status_t app_get_device_cloud_phone(connector_config_pointer_string_t * const config_phone)
00119 {
00120 
00121     config_phone->string = (char *)connector_cloud_phone;
00122     config_phone->length = sizeof connector_cloud_phone - 1;
00123 
00124     return connector_callback_continue;
00125 }
00126 
00127 static connector_callback_status_t app_set_device_cloud_phone(connector_config_pointer_string_t * const config_phone)
00128 {
00129     if (config_phone->length > (sizeof connector_cloud_phone -1))
00130     {
00131         APP_DEBUG("app_set_device_cloud_phone: Not enough room to store cloud_phone.\n");
00132         return connector_callback_error;
00133     }
00134 
00135     strcpy(connector_cloud_phone, config_phone->string);
00136 
00137     /* Maybe user want to save connector_cloud_phone to persistent storage */
00138 
00139     return connector_callback_continue;
00140 }
00141 #endif
00142 
00143 #if !(defined CONNECTOR_CLOUD_SERVICE_ID)
00144 
00145 /* Service-Id used to communicate with the server through SMS
00146  * if empty, not shared-code used (default when using long codes)
00147  * When using shared-codes within US you may need to use "idgp" 
00148  */
00149 static char connector_cloud_service_id[] = "";  /* empty: No shared-code used */
00150 
00151 static connector_callback_status_t app_get_device_cloud_service_id(connector_config_pointer_string_t * const config_service_id)
00152 {
00153 
00154     config_service_id->string = (char *)connector_cloud_service_id;
00155     config_service_id->length = strlen(connector_cloud_service_id);
00156 
00157     return connector_callback_continue;
00158 }
00159 #endif
00160 
00161 #if !(defined CONNECTOR_CONNECTION_TYPE)
00162 static connector_callback_status_t app_get_connection_type(connector_config_connection_type_t * const config_connection)
00163 {
00164 
00165     /* Return pointer to connection type */
00166     config_connection->type = connector_connection_type_lan;
00167 
00168     return connector_callback_continue;
00169 }
00170 #endif
00171 
00172 #if !(defined CONNECTOR_WAN_LINK_SPEED_IN_BITS_PER_SECOND)
00173 static connector_callback_status_t app_get_link_speed(connector_config_link_speed_t * const config_link)
00174 {
00175     config_link->speed = 0;
00176 
00177     return connector_callback_continue;
00178 }
00179 #endif
00180 
00181 #if !(defined CONNECTOR_WAN_PHONE_NUMBER_DIALED)
00182 static connector_callback_status_t app_get_phone_number(connector_config_pointer_string_t * const config_phone_number)
00183 {
00184     /*
00185      * Return pointer to phone number for WAN connection type.
00186      */
00187     static char const phone_number[] ="000-000-0000";
00188 
00189     config_phone_number->string = (char *)phone_number;
00190     config_phone_number->length = sizeof phone_number -1;
00191 
00192     return connector_callback_continue;
00193 }
00194 #endif
00195 
00196 #if !(defined CONNECTOR_TX_KEEPALIVE_IN_SECONDS)
00197 /* Keep alives are from the prospective of Device Cloud */
00198 /* This keep alive is sent from Device Cloud to the device */
00199 static connector_callback_status_t app_get_tx_keepalive_interval(connector_config_keepalive_t * const config_keepalive)
00200 {
00201 
00202 #define DEVICE_TX_KEEPALIVE_INTERVAL_IN_SECONDS     90
00203     /* Return Tx keepalive interval in seconds */
00204     config_keepalive->interval_in_seconds = DEVICE_TX_KEEPALIVE_INTERVAL_IN_SECONDS;
00205 
00206     return connector_callback_continue;
00207 }
00208 #endif
00209 
00210 #if !(defined CONNECTOR_RX_KEEPALIVE_IN_SECONDS)
00211 /* This keep alive is sent from the device to Device Cloud  */
00212 static connector_callback_status_t app_get_rx_keepalive_interval(connector_config_keepalive_t * const config_keepalive)
00213 {
00214 #define DEVICE_RX_KEEPALIVE_INTERVAL_IN_SECONDS     60
00215     /* Return Rx keepalive interval in seconds */
00216     config_keepalive->interval_in_seconds = DEVICE_RX_KEEPALIVE_INTERVAL_IN_SECONDS;
00217 
00218     return connector_callback_continue;
00219 }
00220 #endif
00221 
00222 #if !(defined CONNECTOR_WAIT_COUNT)
00223 static connector_callback_status_t app_get_wait_count(connector_config_wait_count_t * const config_wait)
00224 {
00225 #define DEVICE_WAIT_COUNT     5
00226     /*
00227      * Return wait count (number of times not receiving Tx keepalive
00228      * from Device Cloud is allowed).
00229      */
00230     config_wait->count = DEVICE_WAIT_COUNT;
00231 
00232     return connector_callback_continue;
00233 }
00234 #endif
00235 
00236 #if (defined CONNECTOR_FIRMWARE_SERVICE) && !(defined CONNECTOR_FIRMWARE_SUPPORT)
00237 static connector_callback_status_t app_get_firmware_support(connector_config_supported_t * const config_status)
00238 {
00239     config_status->supported = connector_true;
00240 
00241     return connector_callback_continue;
00242 }
00243 #endif
00244 
00245 #if (defined CONNECTOR_DATA_SERVICE) && !(defined CONNECTOR_DATA_SERVICE_SUPPORT)
00246 static connector_callback_status_t app_get_data_service_support(connector_config_supported_t * const config_status)
00247 {
00248     config_status->supported = connector_true;
00249 
00250     return connector_callback_continue;
00251 }
00252 #endif
00253 
00254 #if (defined CONNECTOR_FILE_SYSTEM) && !(defined CONNECTOR_FILE_SYSTEM_SUPPORT)
00255 static connector_callback_status_t app_get_file_system_support(connector_config_supported_t * const config_status)
00256 {
00257     config_status->supported = connector_true;
00258 
00259     return connector_callback_continue;
00260 }
00261 #endif
00262 
00263 #if (defined CONNECTOR_RCI_SERVICE) && !(defined CONNECTOR_REMOTE_CONFIGURATION_SUPPORT)
00264 static connector_callback_status_t app_get_remote_configuration_support(connector_config_supported_t * const config_status)
00265 {
00266     config_status->supported = connector_true;
00267 
00268     return connector_callback_continue;
00269 }
00270 #endif
00271 
00272 #if ((defined CONNECTOR_DATA_SERVICE) || (defined CONNECTOR_FILE_SYSTEM) || (defined CONNECTOR_RCI_SERVICE)) && !(defined CONNECTOR_MSG_MAX_TRANSACTION)
00273 static connector_callback_status_t app_get_max_message_transactions(connector_config_max_transaction_t * const config_max_transaction)
00274 {
00275 #define CONNECTOR_MAX_MSG_TRANSACTIONS   1
00276 
00277     config_max_transaction->count = CONNECTOR_MAX_MSG_TRANSACTIONS;
00278 
00279     return connector_callback_continue;
00280 }
00281 #endif
00282 
00283 #if !(defined CONNECTOR_DEVICE_ID_METHOD)
00284 static connector_callback_status_t app_get_device_id_method(connector_config_device_id_method_t * const config_device)
00285 {
00286 
00287     config_device->method = connector_device_id_method_auto;
00288 
00289     return connector_callback_continue;
00290 }
00291 #endif
00292 
00293 /* Converts the first digit char ('0' to '9') to a nibble starting at index and working backwards. */
00294 static unsigned int digit_to_nibble(char const * const string, int * const index)
00295 {
00296     unsigned int nibble = 0;
00297     int current;
00298      
00299     for (current = *index; current >= 0; current--)
00300     {
00301         int const ch = string[current];
00302          
00303         if (isxdigit(ch))
00304         {
00305             if (isdigit(ch))
00306                 nibble = ch - '0';
00307             else
00308                 nibble = toupper(ch) - 'A' + 0xA;
00309             break;
00310         }
00311     }
00312     *index = current - 1;
00313  
00314     return nibble;
00315 }
00316   
00317 /* Parse a string with non-digit characters into an array (i.e.: 0123456-78-901234-5 will be stored in {0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x23, 0x45}) */
00318 static int str_to_uint8_array(char const * const str, uint8_t * const array, size_t const array_size)
00319 {
00320     int i;
00321     int const string_length = strlen(str);
00322     int index = string_length - 1;
00323  
00324     for (i = array_size - 1; i >= 0; i--)
00325     {
00326         unsigned int const ls_nibble = digit_to_nibble(str, &index);
00327         unsigned int const ms_nibble = digit_to_nibble(str, &index);
00328  
00329         array[i] = (ms_nibble << 4) + ls_nibble;
00330     }
00331  
00332     return 0;
00333 }
00334 
00335 static connector_callback_status_t app_get_imei_number(connector_config_pointer_data_t * const config_imei)
00336 {
00337 #define APP_IMEI_LENGTH         8
00338 #define APP_IMEI_STRING_LENGTH  (sizeof("000000-00-000000-0") - 1)
00339     /* Each nibble corresponds a decimal digit.
00340      * Most upper nibble must be 0.
00341      */
00342     char const app_imei_number_string[APP_IMEI_STRING_LENGTH] = "000000-00-000000-0";
00343     static uint8_t app_imei_number[APP_IMEI_LENGTH] = {0};
00344     
00345     str_to_uint8_array(app_imei_number_string, app_imei_number, sizeof app_imei_number);
00346 
00347     config_imei->data = app_imei_number;
00348     ASSERT(config_imei->bytes_required == sizeof app_imei_number);
00349     return connector_callback_continue;
00350 }
00351 
00352 static connector_callback_status_t app_start_network_tcp(connector_config_connect_type_t * const config_connect)
00353 {
00354     config_connect->type = connector_connect_auto;
00355     return connector_callback_continue;
00356 }
00357 
00358 static connector_callback_status_t app_start_network_udp(connector_config_connect_type_t * const config_connect)
00359 {
00360     config_connect->type = connector_connect_auto;
00361     return connector_callback_continue;
00362 }
00363 
00364 static connector_callback_status_t app_start_network_sms(connector_config_connect_type_t * const config_connect)
00365 {
00366     config_connect->type = connector_connect_auto;
00367     return connector_callback_continue;
00368 }
00369 
00370 #if !(defined CONNECTOR_WAN_TYPE)
00371 static connector_callback_status_t app_get_wan_type(connector_config_wan_type_t * const config_wan)
00372 {
00373 
00374     config_wan->type = connector_wan_type_imei;
00375 
00376     return connector_callback_continue;
00377 }
00378 #endif
00379 
00380 static connector_callback_status_t app_get_esn(connector_config_pointer_data_t * const config_esn)
00381 {
00382 #define APP_ESN_HEX_LENGTH              4
00383 #define APP_ESN_HEX_STRING_LENGTH       (sizeof("00000000") - 1)
00384     /* Each nibble corresponds a decimal digit.
00385      * Most upper nibble must be 0.
00386      */
00387     char const app_esn_hex_string[APP_ESN_HEX_STRING_LENGTH] = "00000000";
00388     static uint8_t app_esn_hex[APP_ESN_HEX_LENGTH] = {0};
00389     
00390     str_to_uint8_array(app_esn_hex_string, app_esn_hex, sizeof app_esn_hex);
00391     config_esn->data = app_esn_hex;
00392     ASSERT(config_esn->bytes_required == sizeof app_esn_hex);
00393 
00394     return connector_callback_continue;
00395 }
00396 
00397 static connector_callback_status_t app_get_meid(connector_config_pointer_data_t * const config_meid)
00398 {
00399 #define APP_MEID_HEX_LENGTH             7
00400 #define APP_MEID_HEX_STRING_LENGTH      (sizeof("00000000000000") - 1)
00401     /* Each nibble corresponds a decimal digit.
00402      * Most upper nibble must be 0.
00403      */
00404     char const app_meid_hex_string[APP_MEID_HEX_STRING_LENGTH] = "00000000000000";
00405     static uint8_t app_meid_hex[APP_MEID_HEX_LENGTH] = {0};
00406 
00407     str_to_uint8_array(app_meid_hex_string, app_meid_hex, sizeof app_meid_hex);
00408 
00409     config_meid->data = app_meid_hex;
00410     ASSERT(config_meid->bytes_required == sizeof app_meid_hex);
00411 
00412     return connector_callback_continue;
00413 }
00414 
00415 #if !(defined CONNECTOR_IDENTITY_VERIFICATION)
00416 static connector_callback_status_t app_get_identity_verification(connector_config_identity_verification_t * const config_identity)
00417 {
00418 
00419     config_identity->type = connector_identity_verification_simple;
00420 
00421     return connector_callback_continue;
00422 }
00423 #endif
00424 
00425 static connector_callback_status_t app_get_password(connector_config_pointer_string_t * const config_password)
00426 {
00427     static  char const connector_password[] = "";
00428 
00429     /* Return pointer to password. */
00430     config_password->string = (char *)connector_password;
00431     config_password->length = sizeof connector_password -1;
00432 
00433     return connector_callback_continue;
00434 }
00435 
00436 /* End of Cloud Connector configuration routines */
00437 #if (defined CONNECTOR_DEBUG)
00438 
00439 #define enum_to_case(name)  case name:  result = #name;             break
00440 
00441 static char const * app_class_to_string(connector_class_id_t const value)
00442 {
00443     char const * result = NULL;
00444     switch (value)
00445     {
00446         enum_to_case(connector_class_id_config);
00447         enum_to_case(connector_class_id_operating_system);
00448         enum_to_case(connector_class_id_firmware);
00449         enum_to_case(connector_class_id_data_service);
00450         enum_to_case(connector_class_id_remote_config);
00451         enum_to_case(connector_class_id_file_system);
00452         enum_to_case(connector_class_id_network_tcp);
00453         enum_to_case(connector_class_id_network_udp);
00454         enum_to_case(connector_class_id_network_sms);
00455         enum_to_case(connector_class_id_status);
00456         enum_to_case(connector_class_id_short_message);
00457         enum_to_case(connector_class_id_data_point);
00458     }
00459     return result;
00460 }
00461 
00462 static char const * app_config_class_to_string(connector_request_id_config_t const value)
00463 {
00464     char const * result = NULL;
00465     switch (value)
00466     {
00467         enum_to_case(connector_request_id_config_device_id);
00468         enum_to_case(connector_request_id_config_set_device_id);
00469         enum_to_case(connector_request_id_config_vendor_id);
00470         enum_to_case(connector_request_id_config_device_type);
00471         enum_to_case(connector_request_id_config_device_cloud_url);
00472         enum_to_case(connector_request_id_config_get_device_cloud_phone);
00473         enum_to_case(connector_request_id_config_set_device_cloud_phone);
00474         enum_to_case(connector_request_id_config_device_cloud_service_id);
00475         enum_to_case(connector_request_id_config_connection_type);
00476         enum_to_case(connector_request_id_config_mac_addr);
00477         enum_to_case(connector_request_id_config_link_speed);
00478         enum_to_case(connector_request_id_config_phone_number);
00479         enum_to_case(connector_request_id_config_tx_keepalive);
00480         enum_to_case(connector_request_id_config_rx_keepalive);
00481         enum_to_case(connector_request_id_config_wait_count);
00482         enum_to_case(connector_request_id_config_ip_addr);
00483         enum_to_case(connector_request_id_config_error_status);
00484         enum_to_case(connector_request_id_config_firmware_facility);
00485         enum_to_case(connector_request_id_config_data_service);
00486         enum_to_case(connector_request_id_config_file_system);
00487         enum_to_case(connector_request_id_config_remote_configuration);
00488         enum_to_case(connector_request_id_config_max_transaction);
00489         enum_to_case(connector_request_id_config_device_id_method);
00490         enum_to_case(connector_request_id_config_imei_number);
00491         enum_to_case(connector_request_id_config_network_tcp);
00492         enum_to_case(connector_request_id_config_network_udp);
00493         enum_to_case(connector_request_id_config_network_sms);
00494         enum_to_case(connector_request_id_config_wan_type);
00495         enum_to_case(connector_request_id_config_esn);
00496         enum_to_case(connector_request_id_config_meid);
00497         enum_to_case(connector_request_id_config_identity_verification);
00498         enum_to_case(connector_request_id_config_password);
00499     }
00500     return result;
00501 }
00502 
00503 static char const * app_network_class_to_string(connector_request_id_network_t const value)
00504 {
00505     char const * result = NULL;
00506     switch (value)
00507     {
00508         enum_to_case(connector_request_id_network_open);
00509         enum_to_case(connector_request_id_network_send);
00510         enum_to_case(connector_request_id_network_receive);
00511         enum_to_case(connector_request_id_network_close);
00512     }
00513     return result;
00514 }
00515 
00516 static char const * app_os_class_to_string(connector_request_id_os_t const value)
00517 {
00518     char const * result = NULL;
00519     switch (value)
00520     {
00521         enum_to_case(connector_request_id_os_malloc);
00522         enum_to_case(connector_request_id_os_free);
00523         enum_to_case(connector_request_id_os_system_up_time);
00524         enum_to_case(connector_request_id_os_yield);
00525         enum_to_case(connector_request_id_os_reboot);
00526     }
00527     return result;
00528 }
00529 
00530 #if (defined CONNECTOR_FIRMWARE_SERVICE)
00531 static char const * app_firmware_class_to_string(connector_request_id_firmware_t const value)
00532 {
00533     char const * result = NULL;
00534     switch (value)
00535     {
00536         enum_to_case(connector_request_id_firmware_target_count);
00537         enum_to_case(connector_request_id_firmware_info);
00538         enum_to_case(connector_request_id_firmware_download_start);
00539         enum_to_case(connector_request_id_firmware_download_data);
00540         enum_to_case(connector_request_id_firmware_download_complete);
00541         enum_to_case(connector_request_id_firmware_download_abort);
00542         enum_to_case(connector_request_id_firmware_target_reset);
00543     }
00544     return result;
00545 }
00546 #endif
00547 
00548 #if (defined CONNECTOR_RCI_SERVICE)
00549 static char const * app_remote_config_class_to_string(connector_request_id_remote_config_t const value)
00550 {
00551     char const * result = NULL;
00552     switch (value)
00553     {
00554         enum_to_case(connector_request_id_remote_config_session_start);
00555         enum_to_case(connector_request_id_remote_config_action_start);
00556         enum_to_case(connector_request_id_remote_config_group_start);
00557         enum_to_case(connector_request_id_remote_config_group_process);
00558         enum_to_case(connector_request_id_remote_config_group_end);
00559         enum_to_case(connector_request_id_remote_config_action_end);
00560         enum_to_case(connector_request_id_remote_config_session_end);
00561         enum_to_case(connector_request_id_remote_config_session_cancel);
00562     }
00563     return result;
00564 }
00565 #endif
00566 
00567 #if (defined CONNECTOR_FILE_SYSTEM)
00568 static char const * app_file_system_class_to_string(connector_request_id_file_system_t const value)
00569 {
00570     char const * result = NULL;
00571     switch (value)
00572     {
00573         enum_to_case(connector_request_id_file_system_open);
00574         enum_to_case(connector_request_id_file_system_read);
00575         enum_to_case(connector_request_id_file_system_write);
00576         enum_to_case(connector_request_id_file_system_lseek);
00577         enum_to_case(connector_request_id_file_system_ftruncate);
00578         enum_to_case(connector_request_id_file_system_close);
00579         enum_to_case(connector_request_id_file_system_remove);
00580         enum_to_case(connector_request_id_file_system_stat);
00581         enum_to_case(connector_request_id_file_system_stat_dir_entry);
00582         enum_to_case(connector_request_id_file_system_opendir);
00583         enum_to_case(connector_request_id_file_system_readdir);
00584         enum_to_case(connector_request_id_file_system_closedir);
00585         enum_to_case(connector_request_id_file_system_get_error);
00586         enum_to_case(connector_request_id_file_system_session_error);
00587         enum_to_case(connector_request_id_file_system_hash);
00588     }
00589     return result;
00590 }
00591 #endif
00592 
00593 #if (defined CONNECTOR_DATA_SERVICE)
00594 static char const * app_data_service_class_to_string(connector_request_id_data_service_t const value)
00595 {
00596     char const * result = NULL;
00597     switch (value)
00598     {
00599         enum_to_case(connector_request_id_data_service_send_length);
00600         enum_to_case(connector_request_id_data_service_send_data);
00601         enum_to_case(connector_request_id_data_service_send_status);
00602         enum_to_case(connector_request_id_data_service_send_response);
00603         enum_to_case(connector_request_id_data_service_receive_target);
00604         enum_to_case(connector_request_id_data_service_receive_data);
00605         enum_to_case(connector_request_id_data_service_receive_status);
00606         enum_to_case(connector_request_id_data_service_receive_reply_length);
00607         enum_to_case(connector_request_id_data_service_receive_reply_data);
00608     }
00609     return result;
00610 }
00611 #endif
00612 
00613 #if (defined CONNECTOR_DATA_POINTS)
00614 static char const * app_data_point_class_to_string(connector_request_id_data_point_t const value)
00615 {
00616     char const * result = NULL;
00617     switch (value)
00618     {
00619         enum_to_case(connector_request_id_data_point_binary_response);
00620         enum_to_case(connector_request_id_data_point_binary_status);
00621         enum_to_case(connector_request_id_data_point_single_response);
00622         enum_to_case(connector_request_id_data_point_single_status);
00623     }
00624     return result;
00625 }
00626 #endif
00627 
00628 static char const * app_status_class_to_string(connector_request_id_status_t const value)
00629 {
00630     char const * result = NULL;
00631     switch (value)
00632     {
00633         enum_to_case(connector_request_id_status_tcp);
00634         enum_to_case(connector_request_id_status_stop_completed);
00635     }
00636     return result;
00637 }
00638 
00639 #if (defined CONNECTOR_SHORT_MESSAGE)
00640 static char const * app_sm_class_to_string(connector_request_id_sm_t const value)
00641 {
00642     char const * result = NULL;
00643     switch (value)
00644     {
00645         enum_to_case(connector_request_id_sm_ping_request);
00646         enum_to_case(connector_request_id_sm_ping_response);
00647         enum_to_case(connector_request_id_sm_cli_request);
00648         enum_to_case(connector_request_id_sm_cli_response);
00649         enum_to_case(connector_request_id_sm_cli_response_length);
00650         enum_to_case(connector_request_id_sm_cli_status);
00651         enum_to_case(connector_request_id_sm_more_data);
00652         enum_to_case(connector_request_id_sm_opaque_response);
00653         enum_to_case(connector_request_id_sm_config_request);
00654     }
00655     return result;
00656 }
00657 #endif
00658 
00659 static char const * app_status_error_to_string(connector_status_t const value)
00660 {
00661     char const * result = NULL;
00662     switch (value)
00663     {
00664         enum_to_case(connector_success);
00665         enum_to_case(connector_init_error);
00666         enum_to_case(connector_abort);
00667         enum_to_case(connector_invalid_data_size);
00668         enum_to_case(connector_invalid_data_range);
00669         enum_to_case(connector_keepalive_error);
00670         enum_to_case(connector_invalid_data);
00671         enum_to_case(connector_device_terminated);
00672         enum_to_case(connector_service_busy);
00673         enum_to_case(connector_invalid_response);
00674         enum_to_case(connector_no_resource);
00675         enum_to_case(connector_unavailable);
00676         enum_to_case(connector_idle);
00677         enum_to_case(connector_working);
00678         enum_to_case(connector_pending);
00679         enum_to_case(connector_active);
00680         enum_to_case(connector_device_error);
00681         enum_to_case(connector_open_error);
00682 
00683         enum_to_case(connector_invalid_payload_packet);
00684         enum_to_case(connector_bad_version);
00685         enum_to_case(connector_exceed_timeout);
00686 
00687     }
00688     return result;
00689 }
00690 
00691 /*
00692  * This routine is called when a configuration error is encountered by Cloud Connector.
00693  * This is currently used as a debug tool for finding configuration errors.
00694  */
00695 static connector_callback_status_t app_config_error(connector_config_error_status_t const * const error_data)
00696 {
00697 
00698     connector_callback_status_t result = connector_callback_continue;
00699 
00700     APP_DEBUG("app_config_error: Class: %s (%d) ", app_class_to_string(error_data->class_id), error_data->class_id);
00701 
00702     switch (error_data->class_id)
00703     {
00704     case connector_class_id_config:
00705         APP_DEBUG("Request: %s (%d) ", app_config_class_to_string(error_data->request_id.config_request), error_data->request_id.config_request);
00706         break;
00707     case connector_class_id_network_tcp:
00708     case connector_class_id_network_udp:
00709     case connector_class_id_network_sms:
00710         APP_DEBUG("Request: %s (%d) ", app_network_class_to_string(error_data->request_id.network_request), error_data->request_id.network_request);
00711         break;
00712     case connector_class_id_operating_system:
00713         APP_DEBUG("Request: %s (%d) ", app_os_class_to_string(error_data->request_id.os_request), error_data->request_id.os_request);
00714         break;
00715 
00716 #if (defined CONNECTOR_FIRMWARE_SERVICE)
00717     case connector_class_id_firmware:
00718         APP_DEBUG("Request: %s (%d) ", app_firmware_class_to_string(error_data->request_id.firmware_request), error_data->request_id.firmware_request);
00719         break;
00720 #endif
00721 
00722 #if (defined CONNECTOR_DATA_SERVICE)
00723     case connector_class_id_data_service:
00724         APP_DEBUG("Request: %s (%d) ", app_data_service_class_to_string(error_data->request_id.data_service_request), error_data->request_id.data_service_request);
00725         break;
00726 #endif
00727 
00728 #if (defined CONNECTOR_DATA_POINTS)
00729     case connector_class_id_data_point:
00730         APP_DEBUG("Request: %s (%d) ", app_data_point_class_to_string(error_data->request_id.data_point_request), error_data->request_id.data_point_request);
00731         break;
00732 #endif
00733 
00734 #if (defined CONNECTOR_FILE_SYSTEM)
00735     case connector_class_id_file_system:
00736         APP_DEBUG("Request: %s (%d) ", app_file_system_class_to_string(error_data->request_id.file_system_request), error_data->request_id.file_system_request);
00737            break;
00738 #endif
00739 
00740 #if (defined CONNECTOR_RCI_SERVICE)
00741     case connector_class_id_remote_config:
00742         APP_DEBUG("Request: %s (%d) ", app_remote_config_class_to_string(error_data->request_id.remote_config_request), error_data->request_id.remote_config_request);
00743            break;
00744 #endif
00745 
00746     case connector_class_id_status:
00747         APP_DEBUG("Request: %s (%d) ", app_status_class_to_string(error_data->request_id.status_request), error_data->request_id.status_request);
00748         break;
00749 
00750 #if (defined CONNECTOR_SHORT_MESSAGE)
00751     case connector_class_id_short_message:
00752         APP_DEBUG("Request: %s (%d) ", app_sm_class_to_string(error_data->request_id.sm_request), error_data->request_id.sm_request);
00753         break;
00754 #endif
00755 
00756     default:
00757         APP_DEBUG("unknown class id = %d ", error_data->class_id);
00758         break;
00759     }
00760 
00761     APP_DEBUG("Error status: %s (%d)\n", app_status_error_to_string(error_data->status), error_data->status);
00762 
00763     return result;
00764 }
00765 #endif
00766 
00767 /*
00768  * Configuration callback routine.
00769  */
00770 connector_callback_status_t app_config_handler(connector_request_id_config_t const request_id, void * const data)
00771 {
00772     connector_callback_status_t status;
00773 
00774 
00775     switch (request_id)
00776     {
00777     case connector_request_id_config_device_id:
00778         status = app_load_device_id(data);
00779         break;
00780 
00781     case connector_request_id_config_set_device_id:
00782         status = app_save_device_id(data);
00783         break;
00784 
00785     case connector_request_id_config_mac_addr:
00786         status = app_get_mac_addr(data);
00787         break;
00788 
00789 #if !(defined CONNECTOR_VENDOR_ID)
00790     case connector_request_id_config_vendor_id:
00791         status = app_get_vendor_id(data);
00792         break;
00793 #endif
00794 
00795 #if !(defined CONNECTOR_DEVICE_TYPE)
00796     case connector_request_id_config_device_type:
00797         status = app_get_device_type(data);
00798         break;
00799 #endif
00800 
00801 #if !(defined CONNECTOR_CLOUD_URL)
00802     case connector_request_id_config_device_cloud_url:
00803         status = app_get_device_cloud_url(data);
00804         break;
00805 #endif
00806 
00807 #if !(defined CONNECTOR_CLOUD_PHONE)
00808     case connector_request_id_config_get_device_cloud_phone:
00809         status = app_get_device_cloud_phone(data);
00810         break;
00811 
00812     case connector_request_id_config_set_device_cloud_phone:
00813         status = app_set_device_cloud_phone(data);
00814         break;
00815 #endif
00816 
00817 #if !(defined CONNECTOR_CLOUD_SERVICE_ID)
00818     case connector_request_id_config_device_cloud_service_id:
00819         status = app_get_device_cloud_service_id(data);
00820         break;
00821 #endif
00822 
00823 #if !(defined CONNECTOR_CONNECTION_TYPE)
00824     case connector_request_id_config_connection_type:
00825         status = app_get_connection_type(data);
00826         break;
00827 #endif
00828 
00829 #if !(defined CONNECTOR_WAN_LINK_SPEED_IN_BITS_PER_SECOND)
00830     case connector_request_id_config_link_speed:
00831         status = app_get_link_speed(data);
00832         break;
00833 #endif
00834 
00835 #if !(defined CONNECTOR_WAN_PHONE_NUMBER_DIALED)
00836     case connector_request_id_config_phone_number:
00837         status = app_get_phone_number(data);
00838        break;
00839 #endif
00840 
00841 #if !(defined CONNECTOR_TX_KEEPALIVE_IN_SECONDS)
00842     case connector_request_id_config_tx_keepalive:
00843         status = app_get_tx_keepalive_interval(data);
00844         break;
00845 #endif
00846 
00847 #if !(defined CONNECTOR_RX_KEEPALIVE_IN_SECONDS)
00848     case connector_request_id_config_rx_keepalive:
00849         status = app_get_rx_keepalive_interval(data);
00850         break;
00851 #endif
00852 
00853 #if !(defined CONNECTOR_WAIT_COUNT)
00854     case connector_request_id_config_wait_count:
00855         status = app_get_wait_count(data);
00856         break;
00857 #endif
00858 
00859     case connector_request_id_config_ip_addr:
00860         status = app_get_ip_address(data);
00861         break;
00862 
00863 #ifdef CONNECTOR_DEBUG
00864     case connector_request_id_config_error_status:
00865         status = app_config_error(data);
00866         break;
00867 #endif
00868 
00869 #if (defined CONNECTOR_FIRMWARE_SERVICE) && !(defined CONNECTOR_FIRMWARE_SUPPORT)
00870     case connector_request_id_config_firmware_facility:
00871         status = app_get_firmware_support(data);
00872         break;
00873 #endif
00874 
00875 #if (defined CONNECTOR_DATA_SERVICE) && !(defined CONNECTOR_DATA_SERVICE_SUPPORT)
00876     case connector_request_id_config_data_service:
00877         status = app_get_data_service_support(data);
00878         break;
00879 #endif
00880 
00881 #if (defined CONNECTOR_FILE_SYSTEM) && !(defined CONNECTOR_FILE_SYSTEM_SUPPORT)
00882     case connector_request_id_config_file_system:
00883         status = app_get_file_system_support(data);
00884         break;
00885 #endif
00886 
00887 #if (defined CONNECTOR_RCI_SERVICE) && !(defined CONNECTOR_REMOTE_CONFIGURATION_SUPPORT)
00888     case connector_request_id_config_remote_configuration:
00889         status = app_get_remote_configuration_support(data);
00890         break;
00891 #endif
00892 
00893 #if ((defined CONNECTOR_DATA_SERVICE) || (defined CONNECTOR_FILE_SYSTEM) || (defined CONNECTOR_RCI_SERVICE)) && !(defined CONNECTOR_MSG_MAX_TRANSACTION)
00894     case connector_request_id_config_max_transaction:
00895         status = app_get_max_message_transactions(data);
00896         break;
00897 #endif
00898 
00899 #if !(defined CONNECTOR_DEVICE_ID_METHOD)
00900     case connector_request_id_config_device_id_method:
00901         status = app_get_device_id_method(data);
00902         break;
00903 #endif
00904 
00905      case connector_request_id_config_imei_number:
00906          status = app_get_imei_number(data);
00907          break;
00908 
00909 #if !(defined CONNECTOR_NETWORK_TCP_START)
00910      case connector_request_id_config_network_tcp:
00911          status = app_start_network_tcp(data);
00912          break;
00913 #endif
00914 
00915 #if !(defined CONNECTOR_NETWORK_UDP_START)
00916      case connector_request_id_config_network_udp:
00917          status = app_start_network_udp(data);
00918          break;
00919 #endif
00920 
00921 #if !(defined CONNECTOR_NETWORK_SMS_START)
00922      case connector_request_id_config_network_sms:
00923          status = app_start_network_sms(data);
00924          break;
00925 #endif
00926 
00927 #if !(defined CONNECTOR_WAN_TYPE)
00928      case connector_request_id_config_wan_type:
00929          status = app_get_wan_type(data);
00930          break;
00931 #endif
00932 
00933      case connector_request_id_config_esn:
00934          status = app_get_esn(data);
00935          break;
00936 
00937      case connector_request_id_config_meid:
00938          status = app_get_meid(data);
00939          break;
00940 
00941 #if !(defined CONNECTOR_IDENTITY_VERIFICATION)
00942      case connector_request_id_config_identity_verification:
00943          status = app_get_identity_verification(data);
00944          break;
00945 #endif
00946 
00947      case connector_request_id_config_password:
00948          status = app_get_password(data);
00949          break;
00950 
00951     default:
00952         APP_DEBUG("app_config_callback: unknown configuration request= %d\n", request_id);
00953         status = connector_callback_unrecognized;
00954         break;
00955     }
00956 
00957     return status;
00958 }
00959 
00960