add temp code
authorjiehwan.park <jiehwan.park@samsung.com>
Tue, 26 Dec 2017 01:46:39 +0000 (10:46 +0900)
committerjiehwan.park <jiehwan.park@samsung.com>
Tue, 26 Dec 2017 01:46:39 +0000 (10:46 +0900)
Signed-off-by: jiehwan.park <jiehwan.park@samsung.com>
14 files changed:
include/input_file.h [deleted file]
include/sa_common.h [deleted file]
include/sa_types.h [deleted file]
include/setup_network.h [deleted file]
include/setup_system.h [deleted file]
src/adaptor.c
src/input_file.c
src/input_file.h [new file with mode: 0644]
src/sa_common.h [new file with mode: 0644]
src/sa_types.h [new file with mode: 0644]
src/setup_network.c
src/setup_network.h [new file with mode: 0644]
src/setup_system.c
src/setup_system.h [new file with mode: 0644]

diff --git a/include/input_file.h b/include/input_file.h
deleted file mode 100644 (file)
index 4d41641..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __INPUT_FILE_H__
-#define __INPUT_FILE_H__
-
-/**
- * @fn        int sa_inputfile_get_config_info(sa_config_s *config)
- * @brief     This function to get config info
- * @param     sa_config_s              [out]  parsed config info
- * @return    sa_file_state_e  return of state
- */
-sa_error_e sa_inputfile_get_config_info(sa_config_s *config);
-
-/**
- * @fn        int sa_inputfile_get_config_state(void)
- * @brief     This function to get config state
- * @return    sa_file_state_e  return of state
- */
-sa_file_state_e sa_inputfile_get_config_state(void);
-
-/**
- * @fn        int sa_inputfile_register_cb(file_status_cb callback)
- * @brief     This function to register callback for config file
- * @param     file_state_cb            [inout] callback function
- * @return    sa_error_e               return of function
- */
-sa_error_e sa_inputfile_register_cb(file_state_cb callback);
-
-#endif/* __INPUT_FILE_H__ */
\ No newline at end of file
diff --git a/include/sa_common.h b/include/sa_common.h
deleted file mode 100644 (file)
index 01de5e8..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __SA_COMMON_H__
-#define __SA_COMMON_H__
-
-#include <unistd.h>
-#include <dlog.h>
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "SETUP-ADAPTOR"
-
-#ifdef MIN
-#undef MIN
-#endif
-
-#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
-#ifndef TRUE
-#define TRUE 1
-#endif
-#ifndef FALSE
-#define FALSE 0
-#endif
-#define _E(fmt, arg...) LOGE(fmt, ##arg)
-#define _D(fmt, arg...) LOGD(fmt, ##arg)
-#define _W(fmt, arg...) LOGW(fmt, ##arg)
-
-#endif                                                 /* __SA_COMMON_H__ */
diff --git a/include/sa_types.h b/include/sa_types.h
deleted file mode 100644 (file)
index b891dc7..0000000
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __SA_TYPES_H__
-#define __SA_TYPES_H__
-
-#define SA_CONFIG_VERSION                                                      "version"
-#define SA_CONFIG_NETWORKDATA                                          "networkData"
-#define SA_CONFIG_SYSTEMDATA                                           "systemData"
-
-#define SA_CONFIG_NETWORKDATA_WIFI                                     "wifi"
-#define SA_CONFIG_NETWORKDATA_WIFI_SSID                                "ssid"
-#define SA_CONFIG_NETWORKDATA_WIFI_PASSWORD                    "password"
-
-#define SA_CONFIG_NETWORKDATA_ETHERNET                         "ethernet"
-
-#define SA_CONFIG_NETWORKDATA_ENABLED                          "enabled"
-#define SA_CONFIG_NETWORKDATA_DHCPENABLED                      "dhcpEnabled"
-#define SA_CONFIG_NETWORKDATA_IPADDRESS                        "ipAddress"
-#define SA_CONFIG_NETWORKDATA_NETMASK                          "netmask"
-#define SA_CONFIG_NETWORKDATA_DEFAULTGATEWAY           "defaultGateway"
-#define SA_CONFIG_NETWORKDATA_PRIMARYDNSSERVER         "primaryDnsServer"
-#define SA_CONFIG_NETWORKDATA_SECONDARYDNSSERVER    "SecondaryDnsServer"
-
-#define SA_CONFIG_NETWORKDATA_HTTPPROXYHOST                    "httpProxyHost"
-#define SA_CONFIG_NETWORKDATA_HTTPPROXYPORT                    "httpProxyPort"
-
-
-/**
- * @brief  This enum contains setup-adaptor error information
- *
- * The sa_error_e indicates what error is happened
- *
- */
-typedef enum {
-       SA_ERROR_NONE = 0,                      /**< Successful */
-       SA_ERROR_NOT_AVAILABLE,         /**< Not Available */
-       SA_ERROR_PARSING,                       /**< Parsing error */
-       SA_ERROR_INVALID_PARAMETER,     /**< Invalid parameter */
-       SA_ERROR_INVALID_CONTENTS,      /**< Invalid contents */
-       SA_ERROR_OUT_OF_MEMORY,         /**< Out of memory */
-       SA_ERROR_PERMISSION_DENIED,     /**< Permission denied */
-       SA_ERROR_NOT_SUPPORTED,         /**< Not supported  */
-       SA_ERROR_UNKNOWN,                       /**< UNKNOWN  */
-} sa_error_e;
-
-/**
- * @brief  This enum contains setup-adaptor error information
- *
- * The sa_error_e indicates what error is happened
- *
- */
-typedef enum {
-       SA_NETWORK_TYPE_NONE = 0,               /**< none */
-       SA_NETWORK_TYPE_ETH,                    /**< eth */
-       SA_NETWORK_TYPE_WIFI,                   /**< wifi  */
-} sa_network_type_e;
-
-/**
- * @brief  This enum contains setup-adaptor error information
- *
- * The sa_network_state_e indicates connection info in the system
- *
- */
-typedef enum {
-       SA_NETWORK_STATE_DISCONNECTED = 0,              /**< Disconnected */
-       SA_NETWORK_STATE_PROGRESSING,                   /**< Connecting/Association/Configuration */
-       SA_NETWORK_STATE_CONNECTED,                             /**< connected */
-       SA_NETWORK_STATE_UNKNOWN,                               /**< UNKNOWN  */
-} sa_network_state_e;
-
-/**
- * @brief  This enum contains file status information
- *
- * The sa_file_state_e indicates when the status of file is changed
- *
- */
-typedef enum {
-       SA_FILE_STATE_NOT_EXISTED = 0,  /**< Not Existed */
-       SA_FILE_STATE_EXIST,                    /**< Existed */
-       SA_FILE_STATE_REGISTERED,               /**< Registered */
-       SA_FILE_STATE_REMOVED,                  /**< Removed */
-       SA_FILE_STATE_CHANGED,                  /**< Changed  */
-} sa_file_state_e;
-
-/**
- * @brief  This type is definition of status file change callback
- *
- * The file_state_cb includes state, param1 and param2 in the one data
- *
- */
-typedef void (*file_state_cb) (sa_network_state_e state, void *param1, void *param2);
-
-
-/**
- * @struct sa_network_static_s
- * @brief  This struct contains network static information in the config
- *
- * The sa_network_static_s struct encapsulate ip, netmast, gateway and dns information in the one data
- *
- */
-typedef struct {
-       char ipAddress[255+1];
-       char netmask[255+1];
-       char defaultGateway[255+1];
-       char primaryDnsServer[255+1];
-       char secondaryDnsServer[255+1];
-} sa_network_static_s;
-
-/**
- * @struct sa_wifi_s
- * @brief  This struct contains wifi information in the config
- *
- * The sa_wifi_s struct encapsulate enabled, dhcpEnabled, ssid, password and static information in the one data
- *
- */
-typedef struct {
-       int enabled;
-       int dhcpEnabled;
-       char ssid[255+1];
-       char password[255+1];
-       sa_network_static_s *staticInfo;
-} sa_wifi_s;
-
-/**
- * @struct sa_eth_s
- * @brief  This struct contains ethernet information in the config
- *
- * The sa_eth_s struct encapsulate enabled, dhcpEnabled and static information in the one data
- *
- */
-typedef struct {
-       int enabled;
-       int dhcpEnabled;
-       sa_network_static_s *staticInfo;
-} sa_eth_s;
-
-/**
- * @struct sa_proxy_s
- * @brief  This struct contains proxy information 
- *
- * The sa_network_s struct encapsulate httpproxyHost and httpProxyPort information in the one data
- *
- */
-typedef struct {
-       char httpProxyHost[255+1];
-       int httpProxyPort; 
-} sa_proxy_s;
-
-/**
- * @struct sa_network_s
- * @brief  This struct contains network information in the config
- *
- * The sa_network_s struct encapsulate wifi, ethernet and proxy information in the one data
- *
- */
-typedef struct {
-       sa_wifi_s *wifi;
-       sa_eth_s *eth;
-} sa_network_s;
-
-
-/**
- * @struct sa_system_s
- * @brief  This struct contains system data information in the config
- *
- * The sa_system_s struct encapsulate device name information in the one data
- *
- */
-typedef struct {
-       char deviceName[255+1];
-       sa_proxy_s *proxy;
-} sa_system_s;
-
-/**
- * @struct sa_config_s
- * @brief  This struct contains config information
- *
- * The sa_config_s struct encapsulate version, network and system data information in the one data
- *
- */
-typedef struct {
-       char version[127+1];
-       sa_network_s *networkData;
-       sa_system_s *systemData;
-} sa_config_s;
-
-#endif                                                 /* __SA_TYPES_H__ */
diff --git a/include/setup_network.h b/include/setup_network.h
deleted file mode 100644 (file)
index 1f8ed34..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __SETUP_NETWORK_H__
-#define __SETUP_NETWORK_H__
-
-typedef enum {
-       NETWORK_WIFI_STATE_DEINIT,
-       NETWORK_WIFI_STATE_DEACTIVATING,
-       NETWORK_WIFI_STATE_DEACTIVATED,
-       NETWORK_WIFI_STATE_ACTIVATING,
-       NETWORK_WIFI_STATE_ACTIVATED,
-       NETWORK_WIFI_STATE_SCANNING,
-       NETWORK_WIFI_STATE_SCANNED,
-       NETWORK_WIFI_STATE_CONNECTING,
-       NETWORK_WIFI_STATE_CONNECTED,
-} network_wifi_state_e;
-
-/**
- * @fn        int sa_network_get_state(int conn_state)
- * @brief     This function to get connection state
- * @param     conn_state               [out] state of connection
- * @param     conn_type                        [out] type of connection
- * @return    int               return of function
- */
-sa_error_e sa_network_get_state(sa_network_state_e *conn_state, sa_network_type_e *conn_type);
-
-/**
- * @fn        int sa_network_set_connection(sa_network_s *info)
- * @brief     This function to set connection with info
-   @param     conn_type                        [in] type of connection
- * @return    sa_error_e               return of function
- */
-sa_error_e sa_network_set_connection(sa_network_s *info);
-
-/**
- * @fn        int sa_network_get_connection(sa_network_s *info)
- * @brief     This function to get connection with info
- * @param     conn_type                        [out] connection info
- * @return    sa_error_e               return of function
- */
-sa_error_e sa_network_get_connection(sa_network_s *info);
-
-/**
- * @fn        int sa_network_deactivate(void)
- * @brief     This function to deactivate current connection
- * @return    sa_error_e               return of function
- */
-sa_error_e sa_network_deactivate(void);
-
-void sa_network_test(void);
-
-#endif/* __SETUP_NETWORK_H__ */
diff --git a/include/setup_system.h b/include/setup_system.h
deleted file mode 100644 (file)
index 4d72df0..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __SETUP_SYSTEMDATA_H__
-#define __SETUP_SYSTEMDATA_H__
-
-/**
- * @fn        int sa_system_set_proxy(sa_network_s *info)
- * @brief     This function to set connection with info
-   @param     conn_type                        [in] proxy info to set
- * @return    sa_error_e               return of function
- */
-sa_error_e sa_system_set_proxy(sa_proxy_s *info);
-
-/**
- * @fn        int sa_system_get_proxy(sa_network_s *info)
- * @brief     This function to get connection with info
- * @param     conn_type                        [out] proxy info to get
- * @return    sa_error_e               return of function
- */
-sa_error_e sa_system_get_proxy(sa_proxy_s *info);
-
-#endif/* __SETUP_SYSTEMDATA_H__ */
index 99a1cc1d7bf9ef0e3022f850844b2fd779e5eb72..0c24dcaa77511ab9828e3c4bff4ab1b0a9616d87 100644 (file)
 #include "setup_network.h"
 #include "input_file.h"
 
-#define NETWORK_CHECK_RETRY_MAX 10
-
-static char *__print_connection_state(sa_network_state_e state)
-{
-       switch (state) {
-       case SA_NETWORK_STATE_DISCONNECTED:
-               return "Disconnected";
-       case SA_NETWORK_STATE_PROGRESSING:
-               return "Progressing";
-       case SA_NETWORK_STATE_CONNECTED:
-               return "connected";
-       default:
-               return "Unknown";
-       }
-}
-
-static char *__print_connection_type(sa_network_type_e type)
-{
-       switch (type) {
-       case SA_NETWORK_TYPE_WIFI:
-               return "wifi";
-       case SA_NETWORK_TYPE_ETH:
-               return "ethernet";
-       default:
-               return "Unknown";
-       }
-}
-
-static void __print_config_network_static_info(sa_network_static_s *staticInfo)
-{
-       if (staticInfo != NULL) {
-               if (staticInfo->ipAddress != NULL)
-                       _D("static::ipAddress[%s]");
-               if (staticInfo->netmask != NULL)
-                       _D("static::netmask[%s]");
-               if (staticInfo->defaultGateway != NULL)
-                       _D("static::defaultGateway[%s]");
-               if (staticInfo->primaryDnsServer != NULL)
-                       _D("static::primaryDnsServer[%s]");
-               if (staticInfo->secondaryDnsServer != NULL)
-                       _D("static::secondaryDnsServer[%s]");
-       }
-}
-
-static void __print_config_info(sa_config_s *config)
-{
-       sa_network_s *network = NULL;
-       sa_system_s *systemData = NULL;
-       sa_wifi_s *wifi = NULL;
-       sa_eth_s *eth = NULL;
-
-       if (config != NULL) {
-               if (config->version != NULL)
-                       _D("Version [%s]", config->version);
-                       network = config->networkData;
-                       if (network != NULL) {
-                               wifi = network->wifi;
-                               if (wifi != NULL) {
-                                       _D("Network::wifi::enabled[%d]", wifi->enabled);
-                                       _D("Network::wifi::dhcpEnabled[%d]", wifi->dhcpEnabled);
-                                       if (wifi->ssid != NULL)
-                                               _D("Network::wifi::ssid[%s]", wifi->ssid);
-                                       if (wifi->password != NULL)
-                                               _D("Network::wifi::password[%s]", wifi->password);
-
-                                       if (wifi->dhcpEnabled == 0)
-                                               __print_config_network_static_info(wifi->staticInfo);
-                               }
-
-                               eth = network->eth;
-                               if (eth != NULL) {
-                                       _D("Network::eth::enabled[%d]", eth->enabled);
-                                       _D("Network::eth::dhcpEnabled[%d]", eth->dhcpEnabled);
-
-                                       if (eth->dhcpEnabled == 0)
-                                               __print_config_network_static_info(wifi->staticInfo);
-                               }
-                       }
-
-                       systemData = config->systemData;
-                       if (systemData != NULL) {
-                               if (systemData->proxy != NULL) {
-                                       _D("systemData::httpProxyHost [%s]", systemData->proxy->httpProxyHost);
-                                       _D("systemData::HttpProxyPort [%d]", systemData->proxy->httpProxyPort);
-                               }
-                       }
-       }
-}
-
-static void __release_network_resource(sa_network_s *network)
-{
-       if (network != NULL) {
-               if (network->wifi != NULL) {
-                       if (network->wifi->staticInfo != NULL)
-                               free(network->wifi->staticInfo);        
-                       
-                       free(network->wifi);
-               }
-
-               if (network->eth != NULL) {
-                       if (network->eth->staticInfo != NULL)
-                               free(network->eth->staticInfo);
-
-                       free(network->eth);
-               }
-
-               free(network);
-       }
-}
-
-static void __release_system_resource(sa_system_s *system)
-{
-       if (system != NULL) {
-               if (system->proxy != NULL)
-                       free(system->proxy);
-
-               free(system);
-       }
-}
-
-static void __release_config_resource(sa_config_s *config)
-{
-
-       if (config != NULL) {
-               if (config->networkData != NULL)
-                       __release_network_resource(config->networkData);
-
-               if (config->systemData != NULL)
-                       __release_system_resource(config->systemData);
-       }
-}
-
-static int __parsing_config(sa_config_s *config)
-{
-       sa_error_e ret = SA_ERROR_NONE;
-       // memory will be allocated from interface layer
-       ret = sa_inputfile_get_config_info(config);
-       if (ret == SA_ERROR_NONE) {
-               _D("Success to get config");
-               // check config info
-               if (config != NULL)
-                       __print_config_info(config);
-
-       } else {
-               _E("sa_inputfile_get_config_info return error [%d]", ret);
-       }
-
-       return ret;
-}
-
-static int __compare_network_info(sa_network_s *devNetwork, sa_network_s *newNetwork)
+void setup(void)
 {
-       int needChange = FALSE;
+       sa_config_s config = {0,};
+       sa_error_e file_read = SA_ERROR_NONE;
 
-       if (devNetwork == NULL || newNetwork == NULL) {
-               return -1;
-       }
-
-       // compare wifi
-       // wifi has higher priority to compare. 
-       // If wifi info is changed, it doesn't have to compare ethernet info
-       if (newNetwork->wifi != NULL) {
-               if (newNetwork->wifi->enabled == TRUE) {
-                       // in case of using wifi / check dev wifi
-                       if (devNetwork->wifi != NULL) {
-                               if (newNetwork->wifi->enabled == TRUE) {
-                                       // check ssid/password only
-                                       if (strcmp(devNetwork->wifi->ssid, newNetwork->wifi->ssid)) {
-                                               needChange = TRUE;
-                                       }
-
-                                       if (needChange == FALSE && strcmp(devNetwork->wifi->password, newNetwork->wifi->password)) {
-                                               needChange = TRUE;
-                                       }
-                                       // TBD for checking other members such as, ipaddress, dns, gateway....
-                               }
-                       } else {
-                               needChange = TRUE;
-                       }
+       file_read = sa_inputfile_get_config_info(&config);
+       if (file_read == SA_ERROR_NONE) {
+               if (config.systemData != NULL) {
+                       sa_setup_system(config.systemData);
                }
-       }
 
-       
-       if (needChange == FALSE && newNetwork->eth != NULL) {
-               if (newNetwork->eth->enabled == TRUE) {
-                       if (devNetwork->eth != NULL) {
-                               // check ip address only
-                               if (devNetwork->eth->staticInfo != NULL && newNetwork->eth->staticInfo != NULL) {
-                                       if (strcmp(devNetwork->eth->staticInfo->ipAddress, newNetwork->eth->staticInfo->ipAddress)) {
-                                               needChange = TRUE;
-                                       }
-                               }
-                       } else {
-                               needChange = TRUE;
-                       }
+               if (config.networkData != NULL) {
+                       sa_setup_network(config.networkData);
                }
        }
-       
-       return needChange;      
-}
-
-static int __set_network(sa_network_s *network)
-{
-       sa_network_s currentNetwork = {0,};
-       sa_error_e ret = SA_ERROR_NONE;
-       sa_network_type_e conn_type;
-       sa_network_state_e conn_state;
-
-       if (network == NULL) {
-               _E("__set_network is null");
-               return -1;
-       }
-       // 1. check network state
-       // 2. if it is connected, read detail info
-       ret = sa_network_get_state(&conn_state, &conn_type);
-       _D("sa_network_get_state return(%d)", ret);
-       if (ret == SA_ERROR_NONE) {
-               _D("Device Network : T[%s] S[%s]", __print_connection_type(conn_type), __print_connection_state(conn_state));
-               if (conn_state == SA_NETWORK_STATE_CONNECTED) {
-               // read current network info
-                       ret = sa_network_get_connection(&currentNetwork);
-                       if (ret == SA_ERROR_NONE) {
-                               // compare network info
-                               if (__compare_network_info(&currentNetwork, network)) {
-                                       // set network connection
-                                       _D("Set Network Connection !!");
-                                       ret = sa_network_set_connection(network);
-                               }
-                       } else {
-                               _E("__get_current_network_info return error");
-                       }
 
-                       if (currentNetwork.wifi != NULL) {
-                               if (currentNetwork.wifi->staticInfo != NULL)
-                                       free(currentNetwork.wifi->staticInfo);
-                               
-                               free(currentNetwork.wifi);
-                       }
-
-                       if (currentNetwork.eth != NULL) {
-                               if (currentNetwork.eth->staticInfo != NULL)
-                                       free(currentNetwork.eth->staticInfo);
-
-                               free(currentNetwork.eth);
-                       }
-               } else {
-                       // in case of disconnect state
-                       _D("Set Network Connection !!");
-                       ret = sa_network_set_connection(network);
-               }
-       } 
-       
-
-       return ret;
+       sa_inputfile_release_resource(&config);
 }
 
-static int compare_proxy_info(sa_proxy_s *devProxy, sa_proxy_s *newProxy)
-{
-       // comapre proxy
-       if (devProxy != NULL && newProxy != NULL) {
-               if (strlen(devProxy->httpProxyHost) > 0) {
-                       if (strcmp(devProxy->httpProxyHost, newProxy->httpProxyHost)) {
-                               // proxy info is different
-                               return 1;
-                       } else {
-                               // Host address is the same, but port is different
-                               if (devProxy->httpProxyPort != newProxy->httpProxyPort) {
-                                       return 1;
-                               }
-                       }
-               }
-       }
-
-       return 0;
-}
-
-static int __set_system(sa_system_s *system)
-{
-       sa_proxy_s *devProxy = NULL;
-       sa_error_e ret = SA_ERROR_NONE;
-
-       if (system == NULL) {
-               _E("__set_system is null");
-               return -1;
-       }
-       
-       if (system->proxy != NULL) {
-               ret = sa_system_get_proxy(devProxy);
-               if (ret == SA_ERROR_NONE && compare_proxy_info(devProxy, system->proxy)) {
-                       // set proxy
-                       ret = sa_system_set_proxy(system->proxy);
-               }
-       }
-
-       return ret;
-}
+int main(int argc, char *argv[])
+{      
+       sa_file_state_e file_state = SA_FILE_STATE_NOT_EXISTED;
+       sa_config_s config = {0,};
 
-void __monitor_file_state_cb(sa_file_state_e state, void *param1, void *param2)
-{
-       sa_config_s config = {0,};      
-       _D("******************__monitor_file_state_cb ******************");
-       switch (state) {
-       case SA_FILE_STATE_REGISTERED:
-               _D("SA_FILE_STATE_REGISTERED");
-               if (SA_ERROR_NONE == __parsing_config(&config)) {
-                       if (config.systemData != NULL) {
-                               _D("Set system data");
-                               __set_system(config.systemData);
-                       }
 
-                       if (config.networkData != NULL) {
-                               _D("Set nework data");
-                               __set_network(config.networkData);
-                       }
-                       __release_config_resource(&config);
-               } 
-               break;
-       case SA_FILE_STATE_CHANGED:
-               _D("SA_FILE_STATE_CHANGED");
-               break;
-       default:
-               _W("Not Support");
-               break;
+       // check if exists config file
+       file_state = sa_inputfile_get_config_state();
+       if (SA_FILE_STATE_NOT_EXISTED == file_state) {
+               _D("config file is not existed, disable setup-adaptor");
+               return 0;
        }
 
-       _D("callback finshied");
-}
-
-int main(int argc, char *argv[])
-{      
-       sa_error_e ret = SA_ERROR_NONE;
-
        GMainLoop *mainloop;
-
 #if !GLIB_CHECK_VERSION(2, 36, 0)
        g_type_init();
 #endif
-
        mainloop = g_main_loop_new(NULL, FALSE);
 
-       _D("start setup-adaptor");
-       //Check Config file
-       if (SA_FILE_STATE_EXIST == sa_inputfile_get_config_state()) {
-               // Waiting for booting
-               sleep(1);
-               // Register callback to receive file change event
-               ret = sa_inputfile_register_cb((file_state_cb)__monitor_file_state_cb);
-               if (ret == SA_ERROR_NONE) {
-                       // Keep checking callback from input
-               } else {
-                       _E("__init_event_listener error [%d]", ret);
-               }
-       } else {
-               _D("config file is not existed, setup-adaptor exit");
+       // check if setup was executed
+       if(1)
+       {
+               // start first setup with config file
+               setup();
        }
 
        g_main_loop_run(mainloop);
index 4d501f1ece22ff6bba336324ae9a0da9375123f8..d7d54d714fad673bcfd55862c92d92bfa693a30e 100644 (file)
@@ -188,6 +188,79 @@ static char *json_get_string_from_obj(json_object *inputObj, char *key)
        return ret_buf;
 }
 
+static void print_config_network_static_info(sa_network_static_s *staticInfo)
+{
+       if (staticInfo != NULL) {
+               if (staticInfo->ipAddress != NULL)
+                       _D("static::ipAddress[%s]");
+               if (staticInfo->netmask != NULL)
+                       _D("static::netmask[%s]");
+               if (staticInfo->defaultGateway != NULL)
+                       _D("static::defaultGateway[%s]");
+               if (staticInfo->primaryDnsServer != NULL)
+                       _D("static::primaryDnsServer[%s]");
+               if (staticInfo->secondaryDnsServer != NULL)
+                       _D("static::secondaryDnsServer[%s]");
+       }
+}
+
+static void print_network_config(sa_network_s *network)
+{
+       sa_wifi_s *wifi = NULL;
+       sa_eth_s *eth = NULL;
+
+       if (network != NULL) {
+               wifi = network->wifi;
+               if (wifi != NULL) {
+                       _D("Network::wifi::enabled[%d]", wifi->enabled);
+                       _D("Network::wifi::dhcpEnabled[%d]", wifi->dhcpEnabled);
+                       if (wifi->ssid != NULL)
+                               _D("Network::wifi::ssid[%s]", wifi->ssid);
+                       if (wifi->password != NULL)
+                               _D("Network::wifi::password[%s]", wifi->password);
+
+                       if (wifi->dhcpEnabled == 0)
+                               print_config_network_static_info(wifi->staticInfo);
+               }
+
+               eth = network->eth;
+               if (eth != NULL) {
+                       _D("Network::eth::enabled[%d]", eth->enabled);
+                       _D("Network::eth::dhcpEnabled[%d]", eth->dhcpEnabled);
+
+                       if (eth->dhcpEnabled == 0)
+                               print_config_network_static_info(wifi->staticInfo);
+               }
+       }
+}
+
+static void print_system_config(sa_system_s *systemData)
+{
+       if (systemData != NULL) {
+               if (systemData->proxy != NULL) {
+                       _D("systemData::httpProxyHost [%s]", systemData->proxy->httpProxyHost);
+                       _D("systemData::HttpProxyPort [%d]", systemData->proxy->httpProxyPort);
+               }
+       }
+}
+
+static void print_config_info(sa_config_s *config)
+{
+       if (config != NULL) {
+               if (config->version != NULL) {
+                       _D("Version [%s]", config->version);
+               }
+               if(config->networkData)
+               {
+                       print_network_config(config->networkData);
+               }
+               if(config->networkData)
+               {
+                       print_system_config(config->systemData);
+               }
+       }
+}
+
 static int __parse_network_static_info(json_object *inputObj, sa_network_static_s *staticInfo)
 {
        char *ipAddress = NULL;
@@ -499,6 +572,8 @@ sa_error_e sa_inputfile_get_config_info(sa_config_s *config)
                return SA_ERROR_PARSING;
        }
 
+       print_config_info(config);
+       
        return ret;
 }
 
@@ -526,5 +601,49 @@ sa_error_e sa_inputfile_register_cb(file_state_cb callback)
        return ret;
 }
 
+static void release_system_resource(sa_system_s *system)
+{
+       if (system != NULL) {
+               if (system->proxy != NULL)
+                       free(system->proxy);
+
+               free(system);
+       }
+}
+
+static void release_network_resource(sa_network_s *network)
+{
+       if (network != NULL) {
+               if (network->wifi != NULL) {
+                       if (network->wifi->staticInfo != NULL)
+                               free(network->wifi->staticInfo);        
+                       
+                       free(network->wifi);
+               }
+
+               if (network->eth != NULL) {
+                       if (network->eth->staticInfo != NULL)
+                               free(network->eth->staticInfo);
+
+                       free(network->eth);
+               }
+
+               free(network);
+       }
+}
+
+void sa_inputfile_release_resource(sa_config_s *config)
+{
+
+       if (config != NULL) {
+               if (config->networkData != NULL)
+                       release_network_resource(config->networkData);
+
+               if (config->systemData != NULL)
+                       release_system_resource(config->systemData);
+       }
+}
+
+
 /* Sample Config */
 /*{"version":"0.1","wifi":{"ssid":"XXXX","password":"XXXXXX","enabled":true,"dhcpEnabled":true,"ipAddress":"127.0.0.1","netmask":"127.0.0.1","defaultGateway":"127.0.0.1","primaryDNSServer":"127.0.0.1","secondaryDNSServer":"127.0.0.1"},"ethernet":{"enabled":false,"dhcpEnabled":true,"ipAddress":"127.0.0.1","netmask":"127.0.0.1","defaultGateway":"127.0.0.1","primaryDnsServer":"127.0.0.1","secondaryDnsServer":"127.0.0.1"},"httpProxyHost":"127.0.0.1","httpProxyPort":8080}*/
\ No newline at end of file
diff --git a/src/input_file.h b/src/input_file.h
new file mode 100644 (file)
index 0000000..b2289fb
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __INPUT_FILE_H__
+#define __INPUT_FILE_H__
+
+#include "sa_types.h"
+
+/**
+ * @fn        int sa_inputfile_get_config_info(sa_config_s *config)
+ * @brief     This function to get config info
+ * @param     sa_config_s              [out]  parsed config info
+ * @return    sa_file_state_e  return of state
+ */
+sa_error_e sa_inputfile_get_config_info(sa_config_s *config);
+
+/**
+ * @fn        int sa_inputfile_get_config_state(void)
+ * @brief     This function to get config state
+ * @return    sa_file_state_e  return of state
+ */
+sa_file_state_e sa_inputfile_get_config_state(void);
+
+/**
+ * @fn        int sa_inputfile_register_cb(file_status_cb callback)
+ * @brief     This function to register callback for config file
+ * @param     file_state_cb            [inout] callback function
+ * @return    sa_error_e               return of function
+ */
+sa_error_e sa_inputfile_register_cb(file_state_cb callback);
+
+
+void sa_inputfile_release_resource(sa_config_s *config);
+
+#endif/* __INPUT_FILE_H__ */
\ No newline at end of file
diff --git a/src/sa_common.h b/src/sa_common.h
new file mode 100644 (file)
index 0000000..01de5e8
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __SA_COMMON_H__
+#define __SA_COMMON_H__
+
+#include <unistd.h>
+#include <dlog.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "SETUP-ADAPTOR"
+
+#ifdef MIN
+#undef MIN
+#endif
+
+#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
+#ifndef TRUE
+#define TRUE 1
+#endif
+#ifndef FALSE
+#define FALSE 0
+#endif
+#define _E(fmt, arg...) LOGE(fmt, ##arg)
+#define _D(fmt, arg...) LOGD(fmt, ##arg)
+#define _W(fmt, arg...) LOGW(fmt, ##arg)
+
+#endif                                                 /* __SA_COMMON_H__ */
diff --git a/src/sa_types.h b/src/sa_types.h
new file mode 100644 (file)
index 0000000..b891dc7
--- /dev/null
@@ -0,0 +1,200 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __SA_TYPES_H__
+#define __SA_TYPES_H__
+
+#define SA_CONFIG_VERSION                                                      "version"
+#define SA_CONFIG_NETWORKDATA                                          "networkData"
+#define SA_CONFIG_SYSTEMDATA                                           "systemData"
+
+#define SA_CONFIG_NETWORKDATA_WIFI                                     "wifi"
+#define SA_CONFIG_NETWORKDATA_WIFI_SSID                                "ssid"
+#define SA_CONFIG_NETWORKDATA_WIFI_PASSWORD                    "password"
+
+#define SA_CONFIG_NETWORKDATA_ETHERNET                         "ethernet"
+
+#define SA_CONFIG_NETWORKDATA_ENABLED                          "enabled"
+#define SA_CONFIG_NETWORKDATA_DHCPENABLED                      "dhcpEnabled"
+#define SA_CONFIG_NETWORKDATA_IPADDRESS                        "ipAddress"
+#define SA_CONFIG_NETWORKDATA_NETMASK                          "netmask"
+#define SA_CONFIG_NETWORKDATA_DEFAULTGATEWAY           "defaultGateway"
+#define SA_CONFIG_NETWORKDATA_PRIMARYDNSSERVER         "primaryDnsServer"
+#define SA_CONFIG_NETWORKDATA_SECONDARYDNSSERVER    "SecondaryDnsServer"
+
+#define SA_CONFIG_NETWORKDATA_HTTPPROXYHOST                    "httpProxyHost"
+#define SA_CONFIG_NETWORKDATA_HTTPPROXYPORT                    "httpProxyPort"
+
+
+/**
+ * @brief  This enum contains setup-adaptor error information
+ *
+ * The sa_error_e indicates what error is happened
+ *
+ */
+typedef enum {
+       SA_ERROR_NONE = 0,                      /**< Successful */
+       SA_ERROR_NOT_AVAILABLE,         /**< Not Available */
+       SA_ERROR_PARSING,                       /**< Parsing error */
+       SA_ERROR_INVALID_PARAMETER,     /**< Invalid parameter */
+       SA_ERROR_INVALID_CONTENTS,      /**< Invalid contents */
+       SA_ERROR_OUT_OF_MEMORY,         /**< Out of memory */
+       SA_ERROR_PERMISSION_DENIED,     /**< Permission denied */
+       SA_ERROR_NOT_SUPPORTED,         /**< Not supported  */
+       SA_ERROR_UNKNOWN,                       /**< UNKNOWN  */
+} sa_error_e;
+
+/**
+ * @brief  This enum contains setup-adaptor error information
+ *
+ * The sa_error_e indicates what error is happened
+ *
+ */
+typedef enum {
+       SA_NETWORK_TYPE_NONE = 0,               /**< none */
+       SA_NETWORK_TYPE_ETH,                    /**< eth */
+       SA_NETWORK_TYPE_WIFI,                   /**< wifi  */
+} sa_network_type_e;
+
+/**
+ * @brief  This enum contains setup-adaptor error information
+ *
+ * The sa_network_state_e indicates connection info in the system
+ *
+ */
+typedef enum {
+       SA_NETWORK_STATE_DISCONNECTED = 0,              /**< Disconnected */
+       SA_NETWORK_STATE_PROGRESSING,                   /**< Connecting/Association/Configuration */
+       SA_NETWORK_STATE_CONNECTED,                             /**< connected */
+       SA_NETWORK_STATE_UNKNOWN,                               /**< UNKNOWN  */
+} sa_network_state_e;
+
+/**
+ * @brief  This enum contains file status information
+ *
+ * The sa_file_state_e indicates when the status of file is changed
+ *
+ */
+typedef enum {
+       SA_FILE_STATE_NOT_EXISTED = 0,  /**< Not Existed */
+       SA_FILE_STATE_EXIST,                    /**< Existed */
+       SA_FILE_STATE_REGISTERED,               /**< Registered */
+       SA_FILE_STATE_REMOVED,                  /**< Removed */
+       SA_FILE_STATE_CHANGED,                  /**< Changed  */
+} sa_file_state_e;
+
+/**
+ * @brief  This type is definition of status file change callback
+ *
+ * The file_state_cb includes state, param1 and param2 in the one data
+ *
+ */
+typedef void (*file_state_cb) (sa_network_state_e state, void *param1, void *param2);
+
+
+/**
+ * @struct sa_network_static_s
+ * @brief  This struct contains network static information in the config
+ *
+ * The sa_network_static_s struct encapsulate ip, netmast, gateway and dns information in the one data
+ *
+ */
+typedef struct {
+       char ipAddress[255+1];
+       char netmask[255+1];
+       char defaultGateway[255+1];
+       char primaryDnsServer[255+1];
+       char secondaryDnsServer[255+1];
+} sa_network_static_s;
+
+/**
+ * @struct sa_wifi_s
+ * @brief  This struct contains wifi information in the config
+ *
+ * The sa_wifi_s struct encapsulate enabled, dhcpEnabled, ssid, password and static information in the one data
+ *
+ */
+typedef struct {
+       int enabled;
+       int dhcpEnabled;
+       char ssid[255+1];
+       char password[255+1];
+       sa_network_static_s *staticInfo;
+} sa_wifi_s;
+
+/**
+ * @struct sa_eth_s
+ * @brief  This struct contains ethernet information in the config
+ *
+ * The sa_eth_s struct encapsulate enabled, dhcpEnabled and static information in the one data
+ *
+ */
+typedef struct {
+       int enabled;
+       int dhcpEnabled;
+       sa_network_static_s *staticInfo;
+} sa_eth_s;
+
+/**
+ * @struct sa_proxy_s
+ * @brief  This struct contains proxy information 
+ *
+ * The sa_network_s struct encapsulate httpproxyHost and httpProxyPort information in the one data
+ *
+ */
+typedef struct {
+       char httpProxyHost[255+1];
+       int httpProxyPort; 
+} sa_proxy_s;
+
+/**
+ * @struct sa_network_s
+ * @brief  This struct contains network information in the config
+ *
+ * The sa_network_s struct encapsulate wifi, ethernet and proxy information in the one data
+ *
+ */
+typedef struct {
+       sa_wifi_s *wifi;
+       sa_eth_s *eth;
+} sa_network_s;
+
+
+/**
+ * @struct sa_system_s
+ * @brief  This struct contains system data information in the config
+ *
+ * The sa_system_s struct encapsulate device name information in the one data
+ *
+ */
+typedef struct {
+       char deviceName[255+1];
+       sa_proxy_s *proxy;
+} sa_system_s;
+
+/**
+ * @struct sa_config_s
+ * @brief  This struct contains config information
+ *
+ * The sa_config_s struct encapsulate version, network and system data information in the one data
+ *
+ */
+typedef struct {
+       char version[127+1];
+       sa_network_s *networkData;
+       sa_system_s *systemData;
+} sa_config_s;
+
+#endif                                                 /* __SA_TYPES_H__ */
index e09a828124524fea5fd8861722b021acdcbd8ed2..6550aa22c528f668de838a735d9c7f5d1ccfe49c 100644 (file)
@@ -47,6 +47,23 @@ static char *__get_setup_network_wifi_password(void)
 }
 
 
+#define NETWORK_CHECK_RETRY_MAX 10
+
+static char *__print_connection_state(sa_network_state_e state)
+{
+       switch (state) {
+       case SA_NETWORK_STATE_DISCONNECTED:
+               return "Disconnected";
+       case SA_NETWORK_STATE_PROGRESSING:
+               return "Progressing";
+       case SA_NETWORK_STATE_CONNECTED:
+               return "connected";
+       default:
+               return "Unknown";
+       }
+}
+
+
 static const char *__print_wifi_state(connection_wifi_state_e state)
 {
        switch (state) {
@@ -365,12 +382,12 @@ static void __do_connect(sa_wifi_s *info)
        
 }
 
-static int __connect_wifi(sa_wifi_s *info)
+static int connect_wifi(sa_wifi_s *info)
 {
        int rv = 0;
        sa_error_e ret = SA_ERROR_UNKNOWN;
        
-       printf("\n------------------- __connect_wifi -------------------");
+       printf("\n------------------- connect_wifi -------------------");
 
        if (info == NULL) {
                return -1;
@@ -413,12 +430,12 @@ static int __connect_wifi(sa_wifi_s *info)
 
        wifi_handle = NULL;
 
-       printf("\n end __connect_wifi");
+       printf("\n end connect_wifi");
 
        return ret;
 }
 
-static int __connect_ethernet(sa_eth_s *info)
+static int connect_ethernet(sa_eth_s *info)
 {
        if (info == NULL) {
                return -1;
@@ -496,7 +513,7 @@ static int __get_ethernet_info(sa_eth_s *info) {
        return ret;
 }
 
-sa_error_e sa_network_get_state(sa_network_state_e *conn_state, sa_network_type_e *conn_type)
+static sa_error_e network_get_state(sa_network_state_e *conn_state, sa_network_type_e *conn_type)
 {
        connection_h connection = NULL;
        sa_error_e ret = SA_ERROR_UNKNOWN;
@@ -504,7 +521,7 @@ sa_error_e sa_network_get_state(sa_network_state_e *conn_state, sa_network_type_
        connection_wifi_state_e wifi_state;
        int rv = 0;
 
-       printf("\nsa_network_get_state~~~");
+       printf("\nnetwork_get_state~~~");
 
        rv = connection_create(&connection);
        printf("\nconnection_create : ret[%s]", __print_error(rv));
@@ -551,7 +568,7 @@ sa_error_e sa_network_get_state(sa_network_state_e *conn_state, sa_network_type_
        return ret;
 }
 
-sa_error_e sa_network_set_connection(sa_network_s *info)
+static sa_error_e network_set_connection(sa_network_s *info)
 {
        sa_error_e ret = SA_ERROR_NONE;
        int retWifi = 0;
@@ -563,7 +580,7 @@ sa_error_e sa_network_set_connection(sa_network_s *info)
        
        if (info->wifi != NULL) {
                if (info->wifi->enabled == TRUE) {
-                       retWifi = __connect_wifi(info->wifi);
+                       retWifi = connect_wifi(info->wifi);
                        printf("\nreturn wifi [%d]", retWifi);
 
                } else {
@@ -574,7 +591,7 @@ sa_error_e sa_network_set_connection(sa_network_s *info)
        if (info->eth != NULL) {
                // decide whether it will be set according to policy
                if (info->eth->enabled == TRUE){
-                       retEth = __connect_ethernet(info->eth);
+                       retEth = connect_ethernet(info->eth);
                        printf("\nreturn ethernet [%d]", retEth);
                }
        }
@@ -584,7 +601,7 @@ sa_error_e sa_network_set_connection(sa_network_s *info)
        return ret;
 }
 
-sa_error_e sa_network_get_connection(sa_network_s *info)
+static sa_error_e network_get_current_connection(sa_network_s *info)
 {
        connection_h connection = NULL;
        sa_error_e ret = SA_ERROR_NONE;
@@ -633,9 +650,116 @@ sa_error_e sa_network_get_connection(sa_network_s *info)
        return ret;
 }
 
-sa_error_e sa_network_deactivate(void)
+static sa_error_e network_deactivate(void)
+{
+       sa_error_e ret = SA_ERROR_NONE;
+
+       return ret;
+}
+
+
+static int compare_network_info(sa_network_s *devNetwork, sa_network_s *newNetwork)
+{
+       int needChange = FALSE;
+
+       if (devNetwork == NULL || newNetwork == NULL) {
+               return -1;
+       }
+
+       // compare wifi
+       // wifi has higher priority to compare. 
+       // If wifi info is changed, it doesn't have to compare ethernet info
+       if (newNetwork->wifi != NULL) {
+               if (newNetwork->wifi->enabled == TRUE) {
+                       // in case of using wifi / check dev wifi
+                       if (devNetwork->wifi != NULL) {
+                               if (newNetwork->wifi->enabled == TRUE) {
+                                       // check ssid/password only
+                                       if (strcmp(devNetwork->wifi->ssid, newNetwork->wifi->ssid)) {
+                                               needChange = TRUE;
+                                       }
+
+                                       if (needChange == FALSE && strcmp(devNetwork->wifi->password, newNetwork->wifi->password)) {
+                                               needChange = TRUE;
+                                       }
+                                       // TBD for checking other members such as, ipaddress, dns, gateway....
+                               }
+                       } else {
+                               needChange = TRUE;
+                       }
+               }
+       }
+
+       
+       if (needChange == FALSE && newNetwork->eth != NULL) {
+               if (newNetwork->eth->enabled == TRUE) {
+                       if (devNetwork->eth != NULL) {
+                               // check ip address only
+                               if (devNetwork->eth->staticInfo != NULL && newNetwork->eth->staticInfo != NULL) {
+                                       if (strcmp(devNetwork->eth->staticInfo->ipAddress, newNetwork->eth->staticInfo->ipAddress)) {
+                                               needChange = TRUE;
+                                       }
+                               }
+                       } else {
+                               needChange = TRUE;
+                       }
+               }
+       }
+       
+       return needChange;      
+}
+
+sa_error_e sa_setup_network(sa_network_s *network)
 {
+       sa_network_s currentNetwork = {0,};
        sa_error_e ret = SA_ERROR_NONE;
+       sa_network_type_e conn_type;
+       sa_network_state_e conn_state;
+
+       if (network == NULL) {
+               _E("__set_network is null");
+               return -1;
+       }
+       // 1. check network state
+       // 2. if it is connected, read detail info
+       ret = network_get_state(&conn_state, &conn_type);
+       _D("network_get_state return(%d)", ret);
+       if (ret == SA_ERROR_NONE) {
+               _D("Device Network : T[%s] S[%s]", __print_connection_type(conn_type), __print_connection_state(conn_state));
+               if (conn_state == SA_NETWORK_STATE_CONNECTED) {
+               // read current network info
+                       ret = network_get_current_connection(&currentNetwork);
+                       if (ret == SA_ERROR_NONE) {
+                               // compare network info
+                               if (compare_network_info(&currentNetwork, network)) {
+                                       // set network connection
+                                       _D("Set Network Connection !!");
+                                       ret = network_set_connection(network);
+                               }
+                       } else {
+                               _E("__get_current_network_info return error");
+                       }
+
+                       if (currentNetwork.wifi != NULL) {
+                               if (currentNetwork.wifi->staticInfo != NULL)
+                                       free(currentNetwork.wifi->staticInfo);
+                               
+                               free(currentNetwork.wifi);
+                       }
+
+                       if (currentNetwork.eth != NULL) {
+                               if (currentNetwork.eth->staticInfo != NULL)
+                                       free(currentNetwork.eth->staticInfo);
+
+                               free(currentNetwork.eth);
+                       }
+               } else {
+                       // in case of disconnect state
+                       _D("Set Network Connection !!");
+                       ret = network_set_connection(network);
+               }
+       } 
+       
 
        return ret;
 }
\ No newline at end of file
diff --git a/src/setup_network.h b/src/setup_network.h
new file mode 100644 (file)
index 0000000..07afe87
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __SETUP_NETWORK_H__
+#define __SETUP_NETWORK_H__
+
+#include "sa_types.h"
+
+/**
+ * @fn        int sa_setup_network(sa_network_s *info)
+ * @brief     This function to set network connection
+   @param     sa_network_s     [in] network info struture
+ * @return    sa_error_e               return of function
+ */
+sa_error_e sa_setup_network(sa_network_s *network);
+
+
+#endif/* __SETUP_NETWORK_H__ */
index 209b4515c08142de4579be0d493d0b81736b25ec..539398f1a4d42f0bed58f1ee95d96e3e6cc74ef8 100644 (file)
 #include "sa_types.h"
 #include "setup_system.h"
 
-sa_error_e sa_system_set_proxy(sa_proxy_s *info)
+static sa_error_e system_set_proxy(sa_proxy_s *info)
 {
        return SA_ERROR_NOT_SUPPORTED;
 }
 
-sa_error_e sa_system_get_proxy(sa_proxy_s *info)
+static sa_error_e system_get_proxy(sa_proxy_s *info)
 {
        return SA_ERROR_NOT_SUPPORTED;
+}
+
+static int compare_proxy_info(sa_proxy_s *devProxy, sa_proxy_s *newProxy)
+{
+       // comapre proxy
+       if (devProxy != NULL && newProxy != NULL) {
+               if (strlen(devProxy->httpProxyHost) > 0) {
+                       if (strcmp(devProxy->httpProxyHost, newProxy->httpProxyHost)) {
+                               // proxy info is different
+                               return 1;
+                       } else {
+                               // Host address is the same, but port is different
+                               if (devProxy->httpProxyPort != newProxy->httpProxyPort) {
+                                       return 1;
+                               }
+                       }
+               }
+       }
+
+       return 0;
+}
+
+
+
+sa_error_e sa_setup_system(sa_system_s *system)
+{
+       sa_proxy_s *devProxy = NULL;
+       sa_error_e ret = SA_ERROR_NONE;
+
+       if (system == NULL) {
+               _E("__set_system is null");
+               return -1;
+       }
+       
+       if (system->proxy != NULL) {
+               ret = system_get_proxy(devProxy);
+               if (ret == SA_ERROR_NONE && compare_proxy_info(devProxy, system->proxy)) {
+                       // set proxy
+                       ret = system_set_proxy(system->proxy);
+               }
+       }
+
+       return ret;
 }
\ No newline at end of file
diff --git a/src/setup_system.h b/src/setup_system.h
new file mode 100644 (file)
index 0000000..4e683ba
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __SETUP_SYSTEMDATA_H__
+#define __SETUP_SYSTEMDATA_H__
+
+#include "sa_types.h"
+
+/**
+ * @fn        int sa_setup_system(sa_network_s *info)
+ * @brief     This function to set system info info
+   @param     sa_system_s                      [in] system info
+ * @return    sa_error_e            return of function
+ */
+sa_error_e sa_setup_system(sa_system_s *system);
+
+
+#endif/* __SETUP_SYSTEMDATA_H__ */