+++ /dev/null
-/*
- * 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
+++ /dev/null
-/*
- * 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"
-
-#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__ */
+++ /dev/null
-/*
- * 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__ */
+++ /dev/null
-/*
- * 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);
-
-#endif/* __SETUP_NETWORK_H__ */
+++ /dev/null
-/*
- * 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__ */
%install_service multi-user.target.wants %{name}.service
%post
-systemctl daemon-reload
-if [ $1 == 1 ]; then
- # install
- systemctl start %{name}.service
-elif [ $1 == 2 ]; then
- # upgrade
- systemctl restart %{name}.service
-fi
%preun
-if [ $1 == 0 ]; then
- # uninstall
- systemctl stop %{name}.service
-fi
%postun
-systemctl daemon-reload
%files
%manifest %{name}.manifest
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include <glib.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "setup_network.h"
#include "input_file.h"
-#define NETWORK_CHECK_RETRY_MAX 10
-static char *__print_connection_state(sa_network_state_e state)
+static gboolean prepare(GSource *source, gint *timeout)
{
- 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);
- }
+ return TRUE;
}
-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)
+gboolean setup(gpointer data)
{
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)
-{
- 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;
+ sa_config_s config = {0,};
+ sa_error_e file_read = SA_ERROR_NONE;
+
+ _D("callback>>>setup start !!!");
+
+ file_read = sa_inputfile_get_config_info(&config);
+ if (file_read == SA_ERROR_NONE) {
+ if (config.systemData != NULL) {
+ ret = sa_setup_system(config.systemData);
+ if(ret != SA_ERROR_NONE) {
+ _E("sa_setup_system return error(%d)", ret);
}
}
- }
-
- 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) {
+ ret = sa_setup_network(config.networkData);
+ if(ret != SA_ERROR_NONE) {
+ _E("sa_setup_network return error(%d)", ret);
}
}
}
-
- return needChange;
+
+ sa_inputfile_release_resource(&config);
}
-static int __set_network(sa_network_s *network)
+static GSourceFuncs SourceFuncs =
{
- 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);
+ prepare, // prepare function
+ NULL, // function check
+ sa_inputfile_thread, // callback start
+ NULL
+};
+
+// config for main thread & callback function
+static gpointer adder_thread_output (gpointer data)
+{
+ GSource* src = NULL;
- 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(¤tNetwork);
- if (ret == SA_ERROR_NONE) {
- // compare network info
- if (__compare_network_info(¤tNetwork, network)) {
- // set network connection
- _D("Set Network Connection !!");
- ret = sa_network_set_connection(network);
- }
- } else {
- _E("__get_current_network_info return error");
- }
+ _D("adder_thread_output ~~~");
- if (currentNetwork.wifi != NULL) {
- if (currentNetwork.wifi->staticInfo != NULL)
- free(currentNetwork.wifi->staticInfo);
-
- free(currentNetwork.wifi);
- }
+ GMainLoop* main_loop;
+ GMainContext* context = NULL;
- if (currentNetwork.eth != NULL) {
- if (currentNetwork.eth->staticInfo != NULL)
- free(currentNetwork.eth->staticInfo);
+ context = g_main_context_new ();
+ main_loop = g_main_loop_new (context, FALSE);
- free(currentNetwork.eth);
- }
- } else {
- // in case of disconnect state
- _D("Set Network Connection !!");
- ret = sa_network_set_connection(network);
- }
- }
+ src = g_source_new(&SourceFuncs, sizeof(GSource));
+ g_source_set_name (src, "setup-adaptor-func");
+ g_source_set_priority (src, G_PRIORITY_DEFAULT);
+ g_source_set_callback(src, (GSourceFunc) setup, (gpointer) main_loop, NULL); // set callback function
+ g_source_attach (src, context);
- return ret;
-}
-
-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;
+ g_main_loop_run(main_loop);
- 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);
- }
+ g_main_loop_unref(main_loop);
+ if(data) {
+ g_main_loop_quit( (GMainLoop*)data );
}
- return ret;
+ return NULL;
}
-void __monitor_file_state_cb(sa_file_state_e state, void *param1, void *param2)
-{
- sa_config_s config = {0,};
-
- 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);
- }
+int main(int argc, char *argv[])
+{
+ sa_file_state_e file_state = SA_FILE_STATE_NOT_EXISTED;
+ sa_config_s config = {0,};
- 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;
+ _D("main function~~~");
+ // check if exists config file
+ file_state = sa_inputfile_get_config_state();
+ _D("first check for config enable(%d)", file_state);
+ if (SA_FILE_STATE_NOT_EXISTED == file_state) {
+ _D("config file is not existed, disable setup-adaptor");
+ return 0;
}
- _D("callback finshied");
-}
+ GMainLoop *main_loop;
-int main(int argc, char *argv[])
-{
- sa_error_e ret = SA_ERROR_NONE;
+ main_loop = 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(10);
- // Register callback to receive file change event
- ret = sa_inputfile_register_cb(__monitor_file_state_cb);
- if (ret == SA_ERROR_NONE) {
- // Keep checking callback from input
- while(1) {
- sleep(1);
- }
- } else {
- _E("__init_event_listener error [%d]", ret);
- }
- } else {
- _D("config file is not existed, setup-adaptor exit");
- }
+ g_thread_create((GThreadFunc) adder_thread_output, main_loop, TRUE, NULL);
+ g_main_loop_run(main_loop);
+ g_main_loop_unref(main_loop);
+
return 0;
}
\ No newline at end of file
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+#include <glib.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
callback = (file_state_cb)arg;
if (callback == NULL) {
- _E("Ccallback is null for event");
+ _D("Ccallback is null for event");
return NULL;
}
fd = inotify_init();
if (fd < 0) {
- _E("inotify_init error");
+ _D("inotify_init error");
return NULL;
}
_D("[debug] wd=%d mask=%d cookie=%d len=%d dir=%s", event->wd, event->mask, event->cookie, event->len, (event->mask & IN_ISDIR) ? "yes" : "no");
if (event->len) {
if (event->mask & IN_CREATE) {
- if (event->mask & IN_ISDIR)
+ if (event->mask & IN_ISDIR) {
_D("The directory %s was created", event->name);
+ }
else {
_D("The file %s was create.", event->name);
if (!strcmp(event->name, CONFIG_NAME)) {
}
}
} else if (event->mask & IN_DELETE) {
- if (event->mask & IN_ISDIR)
+ if (event->mask & IN_ISDIR) {
_D("The directory %s was deleted.", event->name);
+ }
else {
_D("The file %s was deleted", event->name);
if (!strcmp(event->name, CONFIG_NAME)) {
inotify_rm_watch(fd, wd);
close(fd);
- pthread_exit((void *)0);
-
return NULL;
}
static int __init_event_listener(file_state_cb callback)
{
+#if 0
pthread_t p_thread;
// Start thread to create in order to receive event
if (pthread_create(&p_thread, NULL, &__config_main_loop, callback) < 0) {
- _E("__init_event_listener create error");
+ _D("__init_event_listener create error");
return -1;
}
+#else
+ __config_main_loop(callback);
+#endif
return 0;
}
_D("string object [%s]", ret_buf);
return ret_buf;
}
-static int __parse_system_proxy(json_object *inputObj, sa_system_s *system)
+
+static void print_config_network_static_info(sa_network_static_s *staticInfo)
{
- char *httpProxyHost = NULL;
- int httpProxyPort;
- int ret = 0;
+ 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]");
+ }
+}
- if (inputObj == NULL || system == NULL) {
- _E("__parse_system_proxy input error");
- return -1;
+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);
+ }
}
+}
- system->proxy = (sa_proxy_s *)malloc(sizeof(sa_proxy_s));
- if (system->proxy != NULL) {
- //httpProxyHost
- httpProxyHost = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_HTTPPROXYHOST);
- if (httpProxyHost != NULL) {
- memcpy(system->proxy->httpProxyHost, httpProxyHost, MIN(strlen(httpProxyHost), sizeof(system->proxy->httpProxyHost)-1));
- free(httpProxyHost);
- httpProxyHost = NULL;
+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);
}
- //httpProxyPort
- httpProxyPort = json_get_int_from_obj(inputObj, SA_CONFIG_NETWORKDATA_HTTPPROXYPORT);
- } else {
- ret = -1;
- _E("system->proxy malloc fail");
}
+}
- return ret;
+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 *secondaryDnsServer = NULL;
if (inputObj == NULL || staticInfo == NULL) {
- _E("__parse_network_static_info input error");
+ _D("__parse_network_static_info input error");
return -1;
}
int ret = 0;
if (inputObj == NULL || eth == NULL) {
- _E("__parse_network_eth input error");
+ _D("__parse_network_eth input error");
return -1;
}
} else {
ret = -1;
}
- } else {
- _D("dhcp is true");
}
return ret;
int ret = 0;
if (inputObj == NULL || wifi == NULL) {
- _E("__parse_network_wifi input error");
+ _D("__parse_network_wifi input error");
return -1;
}
// enabled
} else {
ret = -1;
}
- } else {
- _D("dhcp is true");
- }
+ }
return ret;
}
int wifiRet = 0, ethRet = 0;
if (inputObj == NULL) {
- _E("__parse_network_data input error");
+ _D("__parse_network_data input error");
return -1;
}
if (setupConfig->networkData->wifi != NULL) {
wifiRet = __parse_network_wifi(wifiObj, setupConfig->networkData->wifi);
} else {
- _E("network->wifi malloc fail");
+ _D("network->wifi malloc fail");
}
}
}
if (setupConfig->networkData->eth != NULL) {
ethRet = __parse_network_eth(ethernetObj, setupConfig->networkData->eth);
} else {
- _E("network->eth malloc fail");
+ _D("network->eth malloc fail");
}
}
}
} else {
- _E("malloc fail etupConfig->networkData");
+ _D("malloc fail etupConfig->networkData");
}
// if both of network interfaces are failed, it would return -1
if (wifiRet != 0 && ethRet != 0) {
- _E("__parse_network_data fail");
+ _D("__parse_network_data fail");
return -1;
}
int ret = 0;
char *httpProxyHost = NULL;
if (inputObj == NULL) {
- _E("__parse_system_data input error");
+ _D("__parse_system_data input error");
return -1;
}
} else {
ret = -1;
- _E("malloc fail setupConfig->systemData->proxy");
+ _D("malloc fail setupConfig->systemData->proxy");
}
} else {
ret = -1;
- _E("malloc fail setupConfig->systemData");
+ _D("malloc fail setupConfig->systemData");
}
}
char *version = NULL;
if (inputObj == NULL) {
- _E("__parse_version input error");
+ _D("__parse_version input error");
return -1;
}
configObj = json_tokener_parse(jsonData);
- if (configObj != NULL) {
+ if (configObj != NULL && readLen > 0) {
// parse version
ret = __parse_version(configObj, setupConfig);
if (ret == 0) {
}
} else {
ret = -1;
- _E("ConfigObj is not existed");
+ _D("ConfigObj is not existed");
}
json_object_put(configObj);
free(jsonData);
} else {
ret = -1;
- _E("memory allocation fail for jsonData");
+ _D("memory allocation fail for jsonData");
}
}
close(fd);
} else {
ret = -1;
- _E("config file can't be opened");
+ _D("config file can't be opened");
}
return ret;
// parsing and fill into struct
ret = __parse_config(CONFIG_FILE, config);
if (ret != 0) {
- _E("Config parsing error");
+ _D("Config parsing error");
return SA_ERROR_PARSING;
}
+ print_config_info(config);
+
return ret;
}
return ret;
}
-sa_error_e sa_inputfile_register_cb(file_state_cb callback)
+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);
+ }
+}
+
+gboolean sa_inputfile_thread(GSource *source, GSourceFunc callbackFuntion, gpointer user_data)
+{
+ GMainLoop* loop = user_data;
+ GSource* src = NULL;
+
+ _D("GSourceFuncs>>>Execution !!!");
+
+#if 0
sa_error_e ret = SA_ERROR_NONE;
if (__init_event_listener(callback)) {
ret = SA_ERROR_UNKNOWN;
}
+#else
+ callbackFuntion(NULL);
+#endif
+
+ if(user_data) {
+ g_main_loop_quit( (GMainLoop*)user_data );
+ }
+
+ // if return value is "FALSE", function stop
+ // if return value is "TRUE", function restart
+ return FALSE;
+}
- return ret;
+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
--- /dev/null
+/*
+ * 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 <glib.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_thread
+ * @brief This function to call callback at the condition of file
+ * @param GSource parameter
+ * @return gboolean FALSE
+ */
+gboolean sa_inputfile_thread(GSource *source, GSourceFunc callbackFuntion, gpointer user_data);
+
+
+void sa_inputfile_release_resource(sa_config_s *config);
+
+#endif/* __INPUT_FILE_H__ */
\ No newline at end of file
--- /dev/null
+/*
+ * 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
+
+#if 1
+#define _E(fmt, arg...) LOGE(fmt, ##arg)
+#define _D(fmt, arg...) LOGD(fmt, ##arg)
+#define _W(fmt, arg...) LOGW(fmt, ##arg)
+#else
+#define _E(fmt, arg...) {printf(fmt, ##arg);printf("\n");}
+#define _D(fmt, arg...) {printf(fmt, ##arg);printf("\n");}
+#define _W(fmt, arg...) {printf(fmt, ##arg);printf("\n");}
+#endif
+
+#endif /* __SA_COMMON_H__ */
--- /dev/null
+/*
+ * 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__ */
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+#include <glib.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "net_connection.h"
#include "wifi-manager.h"
+typedef struct {
+ wifi_manager_h wifi_h;
+ GMainLoop *loop;
+ char *ssid;
+ char *password;
+} _wifi_data_s;
-char wifi_password[99+1];
-int initialize_setup_network_flag;
-sa_network_state_e setup_network_wifi_state;
-connection_h connection_handle = NULL;
-wifi_manager_h wifi_handle = NULL;
-static int __get_setup_network_initialized(void)
+static char *__print_connection_state(sa_network_state_e state)
{
- return initialize_setup_network_flag;
-}
-
-static int __set_setup_network_initialized(int val)
-{
- if (val != __get_setup_network_initialized()) {
- initialize_setup_network_flag = val;
- }
-}
-
-static int __get_setup_network_wifi_state(void)
-{
- return setup_network_wifi_state;
-}
-
-static void __set_setup_network_wifi_state(sa_network_state_e val)
-{
- if (val != __get_setup_network_wifi_state()) {
- setup_network_wifi_state = val;
- }
-}
-
-static void __set_setup_network_wifi_password(char *password)
-{
- if (strcmp(wifi_password, password)) {
- memset(wifi_password, 0x00, sizeof(wifi_password));
- memcpy(wifi_password, password, MIN(strlen(password), sizeof(wifi_password)-1));
+ 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 *__get_setup_network_wifi_password(void)
-{
- return wifi_password;
-}
-
static const char *__print_wifi_state(connection_wifi_state_e state)
{
}
}
+static const char *__print_network_type(sa_network_type_e type)
+{
+ switch (type) {
+ case SA_NETWORK_TYPE_ETH:
+ return "Ethernet";
+ case SA_NETWORK_TYPE_WIFI:
+ return "Wifi";
+ default:
+ return "Unknown";
+ }
+}
+
static const char *__print_wifi_error(wifi_manager_error_e err_type)
{
switch (err_type) {
}
-static int __check_wifi_state(connection_h connection, connection_wifi_state_e wifi_state)
+static void __wifi_exit_loop(_wifi_data_s *wifi_data)
{
- int rv = 0;
-
- if (connection == NULL) {
- return -1;
- }
-
- rv = connection_get_wifi_state(connection, &wifi_state);
- if (rv != CONNECTION_ERROR_NONE) {
- _D("Fail to get WiFi state [%s]", __print_error(rv));
- } else {
- _D("Retval = [%s] WiFi state [%s]", __print_error(rv), __print_wifi_state(wifi_state));
+ _D("__wifi_exit_loop !!!");
+ if( wifi_data ) {
+ g_main_loop_quit( (GMainLoop*)wifi_data->loop );
}
-
- return 0;
}
-static void __activated_callback(wifi_manager_error_e result, void *user_data)
+static void __wifi_connected_cb(wifi_manager_error_e result, void *user_data)
{
- if (result == WIFI_MANAGER_ERROR_NONE) {
- __set_setup_network_wifi_state(NETWORK_WIFI_STATE_ACTIVATED);
- _D("Wi-Fi Activation Succeeded");
- }
- else
- _D("Wi-Fi Activation Failed! error : %s", __print_wifi_error(result));
-}
-
-static void __scan_request_callback(wifi_manager_error_e error_code, void* user_data)
-{
- if (user_data != NULL)
- _D("user_data : %s", (char *)user_data);
-
- _D("Scan Completed from scan request [%s]", __print_wifi_error(error_code));
-}
+ _wifi_data_s *wifi_data = (_wifi_data_s*)user_data;
-static void __deactivated_callback(wifi_manager_error_e result, void* user_data)
-{
- if (result == WIFI_MANAGER_ERROR_NONE) {
- __set_setup_network_wifi_state(NETWORK_WIFI_STATE_DEACTIVATED);
- _D("Wi-Fi Deactivation Succeeded");
- } else
- _D("Wi-Fi Deactivation Failed! error : %s", __print_wifi_error(result));
+ if (result == WIFI_MANAGER_ERROR_NONE){
+ _D("__wifi_connected_cb() connected Successfully !!!");
+ }
+ else {
+ _D("__wifi_connected_cb() connection Failed!(%s)", __print_wifi_error(result));
+ }
+ __wifi_exit_loop(wifi_data);
}
-static int __compare_ap_name(const char *ap_name, const char *ap_name_part)
-{
- int ap_name_len = strlen(ap_name);
- int ap_name_part_len = strlen(ap_name_part);
-
- if (strncmp(ap_name, ap_name_part,
- ap_name_len > ap_name_part_len ? ap_name_len : ap_name_part_len) == 0)
- return TRUE;
- else
- return FALSE;
-}
-static void __connected_callback(wifi_manager_error_e result, void *user_data)
+// CAUTION : this callback function should be boolean type.
+// return true : continue search ap (not found)
+// return false : stop search ap (found)
+static bool __wifi_connect_ap_cb(wifi_manager_ap_h ap, void *user_data)
{
- if (result == WIFI_MANAGER_ERROR_NONE)
- _D("Wi-Fi Connection Succeeded");
- else
- _D("Wi-Fi Connection Failed! error : %s", __print_wifi_error(result));
-}
+ _wifi_data_s *wifi_data = (_wifi_data_s*)user_data;
-static void __scan_changed_callback(wifi_manager_scan_state_e state, void* user_data)
-{
- _D("Scan changed, scan state : %d", state);
- if (state == WIFI_MANAGER_SCAN_STATE_NOT_SCANNING) {
- __set_setup_network_wifi_state(NETWORK_WIFI_STATE_SCANNED);
- }
-}
+ _D("__wifi_connect_ap_cb()");
-static void __found_connect_ap_callback(wifi_manager_ap_h ap, void *user_data)
-{
int rv = 0;
char *ap_name = NULL;
- char *ap_name_part = (char*)user_data;
rv = wifi_manager_ap_get_essid(ap, &ap_name);
if (rv != WIFI_MANAGER_ERROR_NONE) {
- _D("Fail to get AP name [%s]\n", __print_wifi_error(rv));
- return;
+ _D("Fail to get AP name [%s]", __print_wifi_error((wifi_manager_error_e)rv));
+ g_free(ap_name);
+ return false;
+ } else {
+ _D("AP name = [%s]/[%s]", ap_name, wifi_data->ssid);
}
- if (__compare_ap_name(ap_name, ap_name_part)) {
+ if (g_strcmp0(ap_name, wifi_data->ssid) == 0) {
int required = FALSE;
+ _D("OK!!! connect AP [%s]", ap_name);
+
rv = wifi_manager_ap_is_passphrase_required(ap, &required);
if (rv == WIFI_MANAGER_ERROR_NONE) {
if (required) {
- char *passphrase = __get_setup_network_wifi_password();
- _D("password : [%s]", passphrase);
- rv = wifi_manager_ap_set_passphrase(ap, passphrase);
+ _D(" passphrase1 : [%s]", wifi_data->password);
+ rv = wifi_manager_ap_set_passphrase(ap, wifi_data->password);
if (rv != WIFI_MANAGER_ERROR_NONE) {
_D("Fail to set passphrase : %s", __print_wifi_error(rv));
- if (ap_name != NULL)
- free(ap_name);;
- return ;
+ __wifi_exit_loop(wifi_data);
}
}
-
- //rv = wifi_manager_connect(wifi, ap, __connected_callback, NULL);
- if (rv != WIFI_MANAGER_ERROR_NONE)
- _D("Fail to connection request [%s] : %s", ap_name, __print_wifi_error(rv));
- else {
- _D("Success to connection request [%s]", ap_name);
- __set_setup_network_wifi_state(NETWORK_WIFI_STATE_CONNECTED);
+ if (rv == WIFI_MANAGER_ERROR_NONE)
+ {
+ rv = wifi_manager_connect(wifi_data->wifi_h, ap, __wifi_connected_cb, wifi_data);
+ if (rv != WIFI_MANAGER_ERROR_NONE) {
+ _D("Fail to connection request [%s] : %s", ap_name, __print_wifi_error(rv));
+ __wifi_exit_loop(wifi_data);
+ }
+ else {
+ _D("Success to connection request [%s]", ap_name);
+ }
}
}
-
- }
+ else {
+ _D("Fail to passphrase_required request [%s]", __print_wifi_error(rv));
+ __wifi_exit_loop(wifi_data);
+ }
- if (ap_name != NULL)
- free(ap_name);
+ g_free(ap_name);
+ return false;
+ }
- return;
+ g_free(ap_name);
+ return true;
}
-static int __start_setup_network(void)
+static void __wifi_scan_finished_cb(wifi_manager_error_e result, void *user_data)
{
- int err_code = 0;
-
- err_code = wifi_manager_initialize(&wifi_handle);
- if (err_code == WIFI_MANAGER_ERROR_NONE ||
- err_code == WIFI_MANAGER_ERROR_ALREADY_INITIALIZED) {
- if (connection_handle != NULL) {
- err_code = connection_destroy(connection_handle);
- _D("connection handle was already created [%s]", __print_error(err_code));
- } else {
- err_code = connection_create(&connection_handle);
- if (err_code != CONNECTION_ERROR_NONE) {
- _E("create connection handle error [%s]", __print_error(err_code));
- return -1;
- }
- }
- __set_setup_network_initialized(TRUE);
- } else {
- _E("create wifi handle error [%s]", __print_wifi_error(err_code));
- return -1;
- }
+ _wifi_data_s *wifi_data = (_wifi_data_s*)user_data;
- return 0;
+ _D("__wifi_scan_finished_cb() result=[%s]", __print_wifi_error(result));
+
+ wifi_manager_foreach_found_ap(wifi_data->wifi_h, __wifi_connect_ap_cb, wifi_data);
}
-static int __init_wifi_handle(wifi_manager_h *wifi) {
+static void __wifi_state_changed_cb(wifi_manager_device_state_e state, void *user_data)
+{
+ _wifi_data_s *wifi_data = (_wifi_data_s*)user_data;
- int err_code = 0;
+ _D("__wifi_state_changed_cb() state=[%d]", state);
- err_code = wifi_manager_initialize(&wifi);
- if (err_code == WIFI_MANAGER_ERROR_NONE ||
- err_code == WIFI_MANAGER_ERROR_ALREADY_INITIALIZED) {
- _D(" Create handle for wiri");
- } else {
- _E("create wifi handle error [%s]", __print_wifi_error(err_code));
- return -1;
+ if (state == WIFI_MANAGER_DEVICE_STATE_ACTIVATED) {
+ wifi_manager_scan(wifi_data->wifi_h, __wifi_scan_finished_cb, wifi_data);
+ wifi_manager_unset_device_state_changed_cb(wifi_data->wifi_h);
}
+}
- return 0;
+static void __wifi_activate_cb(wifi_manager_error_e result, void *user_data)
+{
+ _D("__wifi_activate_cb() result=[%s]", __print_wifi_error(result));
}
-static int __connect_wifi(sa_wifi_s *info)
+static int __wifi_connect_main(sa_wifi_s *info)
{
+ GMainLoop *gmain_loop = NULL;
+ GMainContext *context;
+
+ _wifi_data_s wifi_data = {0,};
+
int rv = 0;
- bool state = false;
sa_error_e ret = SA_ERROR_UNKNOWN;
- sa_network_state_e file_state = NETWORK_WIFI_STATE_DEACTIVATED;
+ wifi_manager_h wifi_h = NULL;
+
+ _D("__wifi_connect_main (ssid=%s, pw=%s)", info->ssid, info->password);
if (info == NULL) {
+ _E("invalid input (sa_wifi_s*)");
return -1;
}
- // if wifi is already connected, it would be diconnected
- __set_setup_network_wifi_state(NETWORK_WIFI_STATE_DEACTIVATED);
-
- while(NETWORK_WIFI_STATE_CONNECTED != __get_setup_network_wifi_state()) {
-
- _D("Enter while [%d]", __get_setup_network_wifi_state());
- // check wifi state whether it is activated or not
- switch(__get_setup_network_wifi_state()) {
- case NETWORK_WIFI_STATE_DEACTIVATED:
- _D("deativated state");
- rv = wifi_manager_is_activated(wifi_handle, &state);
- if (rv != WIFI_MANAGER_ERROR_NONE) {
- _D("Fail to get Wi-Fi device state [%s]", __print_wifi_error(rv));
- ret = SA_ERROR_UNKNOWN;
- break;
- }
-
- if (state == FALSE) {
- _D("ativating state");
- rv = wifi_manager_activate(wifi_handle, __activated_callback, NULL);
- __set_setup_network_wifi_state(NETWORK_WIFI_STATE_ACTIVATING);
- if (rv == WIFI_MANAGER_ERROR_NONE ||
- rv == CONNECTION_ERROR_NOW_IN_PROGRESS ||
- rv == WIFI_MANAGER_ERROR_ALREADY_EXISTS) {
- ;
- } else {
- _D("First activate Wi-Fi device [%s]", __print_wifi_error(rv));
- break;
- }
- } else {
- _D("Already Activated");
- __set_setup_network_wifi_state(NETWORK_WIFI_STATE_ACTIVATED);
- }
- break;
- case NETWORK_WIFI_STATE_ACTIVATED:
- _D("ativated state");
-
- rv = wifi_manager_scan(wifi_handle, __scan_request_callback, NULL);
- __set_setup_network_wifi_state(NETWORK_WIFI_STATE_SCANNING);
- _D("scanning state");
- if (rv != WIFI_MANAGER_ERROR_NONE) {
- _D("Scan request failed [%s]", __print_wifi_error(rv));
- ret = SA_ERROR_UNKNOWN;
- break;
- } else {
- _D("scan request succeeded");
- }
- break;
- case NETWORK_WIFI_STATE_SCANNED:
- // connecting
- _D("scanned state");
- __set_setup_network_wifi_state(NETWORK_WIFI_STATE_CONNECTING);
- __set_setup_network_wifi_password(info->password);
- _D("connecting state");
- rv = wifi_manager_foreach_found_ap(wifi_handle, __found_connect_ap_callback, info->ssid);
-
- if (rv != WIFI_MANAGER_ERROR_NONE) {
- _D("Fail to connect (can't get AP list) [%s]", __print_wifi_error(rv));
- ret = SA_ERROR_UNKNOWN;
- break;
- }
- break;
- default:
- break;
+
+ context = g_main_context_new ();
+ g_main_context_push_thread_default (context); // should be.. to get mainloop message in thread
+ gmain_loop = g_main_loop_new (context, FALSE);
+
+ rv = wifi_manager_initialize(&wifi_h);
+
+ if (rv == WIFI_MANAGER_ERROR_NONE) {
+ // fill the token data
+ wifi_data.ssid = info->ssid;
+ wifi_data.password = info->password;
+ wifi_data.loop = gmain_loop;
+ wifi_data.wifi_h = wifi_h;
+
+ rv = wifi_manager_set_device_state_changed_cb(wifi_h, __wifi_state_changed_cb, (void *)&wifi_data);
+ rv = wifi_manager_activate(wifi_h, __wifi_activate_cb, NULL);
+ if (rv != WIFI_MANAGER_ERROR_NONE) {
+ _E("wifi_manager_activated failed.[%s]", __print_wifi_error(rv));
+ return SA_ERROR_UNKNOWN;
}
+ }
+ else {
+ _E("Wifi init failed [%s]", __print_wifi_error(rv));
+ return SA_ERROR_UNKNOWN;
+ }
+
+ g_main_loop_run (gmain_loop);
+
+ gmain_loop = NULL;
+
+ wifi_manager_unset_scan_state_changed_cb(wifi_h);
+ wifi_manager_unset_connection_state_changed_cb(wifi_h);
- sleep(1);
+ rv = wifi_manager_deinitialize(wifi_h);
+
+ if (rv != WIFI_MANAGER_ERROR_NONE) {
+ _D("Fail to deinitialize.");
+ ret = SA_ERROR_UNKNOWN;
}
-
+
+ _D("__wifi_connect_main completed.");
return ret;
}
-static int __connect_ethernet(sa_eth_s *info)
-{
- int rv = 0;
- int err = 0;
- int ret = 0;
- connection_h connection = NULL;
+
+
+
+
+
+
+
+
+
+
+static int __ethernet_connect_main(sa_eth_s *info)
+{
if (info == NULL) {
return -1;
}
return 0;
}
-static int __get_wifi_info(sa_wifi_s *info)
+
+
+
+
+
+
+
+
+
+static int __network_get_wifi_state(connection_h connection, connection_wifi_state_e *wifi_state)
{
int rv = 0;
- char *ap_name = NULL;
- wifi_manager_ap_h ap_h;
-
- rv = wifi_manager_get_connected_ap(wifi_handle, &ap_h);
- if (rv != WIFI_MANAGER_ERROR_NONE) {
- _D("Fail to get connected AP [%s]", __print_wifi_error(rv));
- return -1;
- }
- rv = wifi_manager_ap_get_essid(ap_h, &ap_name);
- if (rv != WIFI_MANAGER_ERROR_NONE) {
- _D("Fail to get essid [%s]", __print_wifi_error(rv));
- wifi_manager_ap_destroy(ap_h);
+ if (connection == NULL) {
return -1;
}
- _D("Connected AP : %s\n", ap_name);
- memcpy(info->ssid, ap_name, MIN(strlen(ap_name), sizeof(info->ssid)-1));
- free(ap_name);
- wifi_manager_ap_destroy(ap_h);
-
- return 0;
-}
-
-static int __get_ethernet_info(sa_eth_s *info) {
- char *ip_addr = NULL;
- int input;
- int rv;
-
- if (info != NULL) {
- // only for ipv4
- rv = connection_get_ip_address(connection_handle, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_addr);
- if (ip_addr == NULL) {
- _D("IPv4 address does not exist");
- return -1;
- }
- _D("IPv4 address : %s", ip_addr);
- info->staticInfo = (sa_network_static_s *)malloc(sizeof(sa_network_static_s));
- if (info->staticInfo != NULL) {
- memcpy(info->staticInfo->ipAddress, ip_addr, MIN(strlen(ip_addr), sizeof(info->staticInfo->ipAddress)-1));
- }
- free(ip_addr);
+ rv = connection_get_wifi_state(connection, wifi_state);
+ if (rv != CONNECTION_ERROR_NONE) {
+ _D("Fail to get WiFi state [%s]", __print_error(rv));
+ } else {
+ _D("Retval = [%s] WiFi state [%s]", __print_error(rv), __print_wifi_state(*wifi_state));
}
return 0;
}
-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;
connection_type_e net_state;
connection_wifi_state_e wifi_state;
int rv = 0;
- if (!__get_setup_network_initialized()) {
- if(__start_setup_network()) {
- _E("not ready to use network api due to async reply from network api");
- return SA_ERROR_NOT_AVAILABLE;
- }
+ rv = connection_create(&connection);
+ if (rv != CONNECTION_ERROR_NONE) {
+ _E("create connection handle error [%s]", __print_error(rv));
+ return -1;
}
+
// check network state(eth/wifi)
- rv = connection_get_type(connection_handle, &net_state);
+ rv = connection_get_type(connection, &net_state);
if (rv != CONNECTION_ERROR_NONE) {
- printf("Fail to get network state [%s]\n", __print_error(rv));
+ _E("Fail to get network state [%s]", __print_error(rv));
} else {
ret = SA_ERROR_NONE;
- _D("Retval = [%s] network connection state [%s]\n", __print_error(rv), __print_connection_type(net_state));
+ _D("Retval = [%s] network connection state [%s]", __print_error(rv), __print_connection_type(net_state));
if (CONNECTION_TYPE_DISCONNECTED == net_state) {
*conn_state = SA_NETWORK_STATE_DISCONNECTED;
} else if (CONNECTION_TYPE_WIFI == net_state) {
*conn_type = SA_NETWORK_TYPE_WIFI;
// check wifi state
- if (!__check_wifi_state(connection_handle, wifi_state)) {
+ if (!__network_get_wifi_state(connection, &wifi_state)) {
if (wifi_state == CONNECTION_WIFI_STATE_CONNECTED) {
*conn_state = SA_NETWORK_STATE_CONNECTED;
} else {
}
}
+ rv = connection_destroy(connection);
+ if (rv != CONNECTION_ERROR_NONE) {
+ _E("connection destroy fail [%s]", __print_error(rv));
+ return -1;
+ }
+
return ret;
}
-sa_error_e sa_network_set_connection(sa_network_s *info)
+
+static sa_error_e __network_connect(sa_network_s *info)
{
sa_error_e ret = SA_ERROR_NONE;
- connection_wifi_state_e wifi_state;
int retWifi = 0;
int retEth = 0;
if (info == NULL) {
return SA_ERROR_INVALID_PARAMETER;
}
-
- if (!__get_setup_network_initialized()) {
- if(__start_setup_network()) {
- _E("not ready to use network api due to async reply from network api");
- }
- }
-
- // first priority is wifi
+
if (info->wifi != NULL) {
if (info->wifi->enabled == TRUE) {
- // wifi setting and waiting to get response
- retWifi = __connect_wifi(info->wifi);
+ retWifi = __wifi_connect_main(info->wifi);
_D("return wifi [%d]", retWifi);
- // or if wifi is enabled but fail to connect, try to connect eth
-
- /*
- if (info->eth != NULL) {
- if (wifi_state != CONNECTION_WIFI_STATE_CONNECTED && info->eth->enabled == TRUE) {
- retEth = __connect_ethernet(info->eth);
- }
- }*/
+
} else {
_D("wifi enabled flag is false");
}
}
- _D("End setting");
-
+ if (info->eth != NULL) {
+ // decide whether it will be set according to policy
+ if (info->eth->enabled == TRUE){
+ retEth = __ethernet_connect_main(info->eth);
+ _D("return ethernet [%d]", retEth);
+ }
+ }
+
return ret;
}
-sa_error_e sa_network_get_connection(sa_network_s *info)
+sa_error_e sa_setup_network(sa_network_s *network)
{
sa_error_e ret = SA_ERROR_NONE;
- connection_type_e net_state;
- connection_wifi_state_e wifi_state;
- sa_network_state_e conn_state;
sa_network_type_e conn_type;
- int rv = 0;
+ sa_network_state_e conn_state;
- if (!__get_setup_network_initialized()) {
- if(__start_setup_network()) {
- _E("not ready to use network api due to async reply from network api");
- }
- }
- // get network state
- if (connection_handle != NULL) {
- rv = connection_get_type(connection_handle, &net_state);
- if (rv == CONNECTION_ERROR_NONE) {
- // get detail information
- if (CONNECTION_TYPE_WIFI == net_state) {
- // check wifi state
- if (!__check_wifi_state(connection_handle, wifi_state)) {
- if (wifi_state == CONNECTION_WIFI_STATE_CONNECTED) {
- // detail info for wifi
- info->wifi = (sa_wifi_s *)malloc(sizeof(sa_wifi_s));
- if (info->wifi != NULL) {
- ret = __get_wifi_info(info->wifi);
- }
- }
- }
- } else if (CONNECTION_TYPE_ETHERNET == net_state) {
- // detail info for ethernet
- info->eth = (sa_eth_s *)malloc(sizeof(sa_eth_s));
- if (info->eth != NULL) {
- ret = __get_ethernet_info(info->eth);
- }
- }
- }
- } else {
- _E("Connection handle is null");
+ if (network == NULL) {
+ _E("__set_network is null");
+ return SA_ERROR_INVALID_PARAMETER;
}
+ // 1. check network state
+ // 2. if it is connected, read detail info
+ ret = __network_connect(network);
- return ret;
-}
-
-sa_error_e sa_network_deactivate(void)
-{
- sa_error_e ret = SA_ERROR_NONE;
+ // need to delay to sync with setting...
+ sleep(2);
+ ret = __network_get_state(&conn_state, &conn_type);
+ if (ret == SA_ERROR_NONE) {
+ _D("Device Network : T[%s] S[%s]", __print_network_type(conn_type), __print_connection_state(conn_state));
+ }
return ret;
-}
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 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__ */
#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
--- /dev/null
+/*
+ * 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__ */