file_state_cb callback;
char buffer[BUF_LEN];
- printf("\n__config_main_loop start\n");
+ _D("__config_main_loop start\n");
callback = (file_state_cb)arg;
if (callback == NULL) {
- printf("\nCcallback is null for event");
+ _D("Ccallback is null for event");
return NULL;
}
fd = inotify_init();
if (fd < 0) {
- printf("\ninotify_init error");
+ _D("inotify_init error");
return NULL;
}
wd = inotify_add_watch(fd, CONFIG_FOLDER, IN_MODIFY | IN_CREATE | IN_DELETE);
// Start callack
- printf("\nRegisterd Callback Triggered");
+ _D("Registerd Callback Triggered");
callback(SA_FILE_STATE_REGISTERED, NULL, NULL);
while (1) {
int length, i = 0;
while (i < length) {
struct inotify_event *event = (struct inotify_event *)&buffer[i];
- printf("\n[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");
+ _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)
- printf("\nThe directory %s was created", event->name);
+ if (event->mask & IN_ISDIR) {
+ _D("The directory %s was created", event->name);
+ }
else {
- printf("\nThe file %s was create.", event->name);
+ _D("The file %s was create.", event->name);
if (!strcmp(event->name, CONFIG_NAME)) {
- printf("\nconfig.json is created!!");
+ _D("config.json is created!!");
}
}
} else if (event->mask & IN_DELETE) {
- if (event->mask & IN_ISDIR)
- printf("\nThe directory %s was deleted.", event->name);
+ if (event->mask & IN_ISDIR) {
+ _D("The directory %s was deleted.", event->name);
+ }
else {
- printf("\nThe file %s was deleted", event->name);
+ _D("The file %s was deleted", event->name);
if (!strcmp(event->name, CONFIG_NAME)) {
- printf("\nconfig.json is deleted!!");
+ _D("config.json is deleted!!");
}
}
} else if (event->mask & IN_MODIFY) {
if (event->mask & IN_ISDIR) {
- printf("\nThe directory %s was modified", event->name);
+ _D("The directory %s was modified", event->name);
}
else {
if (!strcmp(event->name, CONFIG_NAME)) {
- printf("\nconfig.json is modified!!");
+ _D("config.json is modified!!");
callback(SA_FILE_STATE_CHANGED, NULL, NULL);
}
}
// Start thread to create in order to receive event
if (pthread_create(&p_thread, NULL, &__config_main_loop, callback) < 0) {
- printf("\n__init_event_listener create error");
+ _D("__init_event_listener create error");
return -1;
}
#else
return NULL;
}
- printf("\nstring object [%s]", ret_buf);
+ _D("string object [%s]", ret_buf);
return ret_buf;
}
char *secondaryDnsServer = NULL;
if (inputObj == NULL || staticInfo == NULL) {
- printf("\n__parse_network_static_info input error");
+ _D("__parse_network_static_info input error");
return -1;
}
int ret = 0;
if (inputObj == NULL || eth == NULL) {
- printf("\n__parse_network_eth input error");
+ _D("__parse_network_eth input error");
return -1;
}
} else {
ret = -1;
}
- } else {
- printf("\ndhcp is true");
}
return ret;
int ret = 0;
if (inputObj == NULL || wifi == NULL) {
- printf("\n__parse_network_wifi input error");
+ _D("__parse_network_wifi input error");
return -1;
}
// enabled
} else {
ret = -1;
}
- } else {
- printf("\ndhcp is true");
- }
+ }
return ret;
}
int wifiRet = 0, ethRet = 0;
if (inputObj == NULL) {
- printf("\n__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 {
- printf("\nnetwork->wifi malloc fail");
+ _D("network->wifi malloc fail");
}
}
}
if (setupConfig->networkData->eth != NULL) {
ethRet = __parse_network_eth(ethernetObj, setupConfig->networkData->eth);
} else {
- printf("\nnetwork->eth malloc fail");
+ _D("network->eth malloc fail");
}
}
}
} else {
- printf("\nmalloc fail etupConfig->networkData");
+ _D("malloc fail etupConfig->networkData");
}
// if both of network interfaces are failed, it would return -1
if (wifiRet != 0 && ethRet != 0) {
- printf("\n__parse_network_data fail");
+ _D("__parse_network_data fail");
return -1;
}
int ret = 0;
char *httpProxyHost = NULL;
if (inputObj == NULL) {
- printf("\n__parse_system_data input error");
+ _D("__parse_system_data input error");
return -1;
}
} else {
ret = -1;
- printf("\nmalloc fail setupConfig->systemData->proxy");
+ _D("malloc fail setupConfig->systemData->proxy");
}
} else {
ret = -1;
- printf("\nmalloc fail setupConfig->systemData");
+ _D("malloc fail setupConfig->systemData");
}
}
char *version = NULL;
if (inputObj == NULL) {
- printf("\n__parse_version input error");
+ _D("__parse_version input error");
return -1;
}
if (jsonData != NULL) {
memset(jsonData, 0x00, len + 1);
readLen = read(fd, jsonData, len);
- printf("\nJSON full data[%s]", jsonData);
+ _D("JSON full data[%s]", jsonData);
configObj = json_tokener_parse(jsonData);
}
} else {
ret = -1;
- printf("\nConfigObj is not existed");
+ _D("ConfigObj is not existed");
}
json_object_put(configObj);
free(jsonData);
} else {
ret = -1;
- printf("\nmemory allocation fail for jsonData");
+ _D("memory allocation fail for jsonData");
}
}
close(fd);
} else {
ret = -1;
- printf("\nconfig 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) {
- printf("\nConfig parsing error");
+ _D("Config parsing error");
return SA_ERROR_PARSING;
}
#include "net_connection.h"
#include "wifi-manager.h"
-static char wifi_password[99+1];
-static wifi_manager_h wifi_handle = NULL;
+typedef struct {
+ wifi_manager_h wifi_h;
+ GMainLoop *loop;
+ char *ssid;
+ char *password;
+} _wifi_data_s;
-static void __do_connect(sa_wifi_s *info);
-static void __do_exit(void);
-
-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));
- }
-
- printf("\n __set_setup_network_wifi_password[%s]", wifi_password);
- return;
-}
-
-static char *__get_setup_network_wifi_password(void)
-{
- return wifi_password;
-}
-
-
-#define NETWORK_CHECK_RETRY_MAX 10
static char *__print_connection_state(sa_network_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)
-{
- int rv = 0;
-
- if (connection == NULL) {
- return -1;
- }
-
- rv = connection_get_wifi_state(connection, &wifi_state);
- if (rv != CONNECTION_ERROR_NONE) {
- printf("\nFail to get WiFi state [%s]", __print_error(rv));
- } else {
- printf("\nRetval = [%s] WiFi state [%s]", __print_error(rv), __print_wifi_state(wifi_state));
- }
-
- return 0;
-}
-
-static void __activated_callback(wifi_manager_error_e result, void *user_data)
+static void __wifi_exit_loop(_wifi_data_s *wifi_data)
{
- if (result == WIFI_MANAGER_ERROR_NONE) {
- printf("\nMY~~~Wi-Fi Activation Succeeded");
-
+ _D("__wifi_exit_loop !!!");
+ if( wifi_data ) {
+ g_main_loop_quit( (GMainLoop*)wifi_data->loop );
}
- else
- printf("\nWi-Fi Activation Failed! error : %s", __print_wifi_error(result));
}
-static void __scan_request_callback(wifi_manager_error_e error_code, void* user_data)
-{
- printf("\n __scan_request_callback from scan request [%s]", __print_wifi_error(error_code));
- __do_connect((sa_wifi_s *)user_data);
-}
-
-static void __deactivated_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)
- printf("\nWi-Fi Deactivation Succeeded");
- else
- printf("\nWi-Fi Deactivation Failed! error : %s", __print_wifi_error(result));
-}
+ _wifi_data_s *wifi_data = (_wifi_data_s*)user_data;
-static void __connection_state_callback(wifi_manager_connection_state_e state, wifi_manager_ap_h ap, void *user_data)
-{
- switch (state) {
- case WIFI_MANAGER_CONNECTION_STATE_CONNECTED:
- printf("state : Connected");
- break;
- case WIFI_MANAGER_CONNECTION_STATE_ASSOCIATION:
- printf(", state : Association");
- break;
- case WIFI_MANAGER_CONNECTION_STATE_CONFIGURATION:
- printf(", state : Configuration");
- break;
- case WIFI_MANAGER_CONNECTION_STATE_DISCONNECTED:
- printf(", state : Disconnected");
- break;
- default:
- printf(", state : Unknown");
+ 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)
- printf("\nWi-Fi Connection Succeeded");
- else
- printf("\nWi-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)
-{
- printf("\nScan changed, scan state : %d", state);
- if (state == WIFI_MANAGER_SCAN_STATE_NOT_SCANNING) {
- wifi_manager_unset_scan_state_changed_cb(wifi_handle);
- }
-}
+ _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;
-
- printf("\n __found_connect_ap_callback called");
rv = wifi_manager_ap_get_essid(ap, &ap_name);
if (rv != WIFI_MANAGER_ERROR_NONE) {
- printf("\nFail 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();
- printf("\n passphrase1 : [%s]", passphrase);
- rv = wifi_manager_ap_set_passphrase(ap, passphrase);
- printf("\n passphrase2 : [%s]", passphrase);
+ _D(" passphrase1 : [%s]", wifi_data->password);
+ rv = wifi_manager_ap_set_passphrase(ap, wifi_data->password);
if (rv != WIFI_MANAGER_ERROR_NONE) {
- printf("\nFail to set passphrase : %s", __print_wifi_error(rv));
- if (ap_name != NULL)
- free(ap_name);;
- return;
+ _D("Fail to set passphrase : %s", __print_wifi_error(rv));
+ __wifi_exit_loop(wifi_data);
}
}
- rv = wifi_manager_connect(wifi_handle, ap, __connected_callback, NULL);
- if (rv != WIFI_MANAGER_ERROR_NONE)
- printf("\nFail to connection request [%s] : %s", ap_name, __print_wifi_error(rv));
- else {
- printf("\nSuccess to connection request [%s]", ap_name);
+ 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);
+ }
}
}
- }
-
- if (ap_name != NULL)
- free(ap_name);
+ else {
+ _D("Fail to passphrase_required request [%s]", __print_wifi_error(rv));
+ __wifi_exit_loop(wifi_data);
+ }
- __do_exit();
+ g_free(ap_name);
+ return false;
+ }
- return;
+ g_free(ap_name);
+ return true;
}
-void __activate_state_changed_cb(wifi_manager_device_state_e state, void *user_data)
+static void __wifi_scan_finished_cb(wifi_manager_error_e result, void *user_data)
{
- printf("\n__wifi_state_changed_cb() state=[%d]", state);
+ _wifi_data_s *wifi_data = (_wifi_data_s*)user_data;
- if (state == WIFI_MANAGER_DEVICE_STATE_ACTIVATED) {
- printf("\n__wifi_state_changed_cb start scan...");
- wifi_manager_scan(wifi_handle, __scan_request_callback, (void *)user_data);
- //wifi_manager_set_scan_state_changed_cb(wifi_handle, __test_scan_changed_callback, (void *)user_data);
- //wifi_manager_set_background_scan_cb(wifi_handle, __test_bg_scan_completed_callback, (void *)info);
- }
-}
+ _D("__wifi_scan_finished_cb() result=[%s]", __print_wifi_error(result));
-static void __do_exit(void)
-{
- printf("\nExit Case :: To-Do");
+ wifi_manager_foreach_found_ap(wifi_data->wifi_h, __wifi_connect_ap_cb, wifi_data);
}
-static int __do_activate(wifi_manager_h *wifi, sa_wifi_s *info)
+static void __wifi_state_changed_cb(wifi_manager_device_state_e state, void *user_data)
{
- int rv = 0;
-
- printf("\nativating state");
+ _wifi_data_s *wifi_data = (_wifi_data_s*)user_data;
- rv = wifi_manager_activate(*wifi, __activated_callback, (void *)info);
- printf("\nwifi_manager_activate:ret[%s]", __print_wifi_error(rv));
+ _D("__wifi_state_changed_cb() state=[%d]", state);
- return rv;
+ 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);
+ }
}
-static void __do_connect(sa_wifi_s *info)
+static void __wifi_activate_cb(wifi_manager_error_e result, void *user_data)
{
- int rv = 0;
- printf("\nscanned state");
-
- __set_setup_network_wifi_password(info->password);
-
- printf("\nconnecting state[%s]", info->ssid);
- rv = wifi_manager_foreach_found_ap(wifi_handle, (void *)__found_connect_ap_callback, (void *)info->ssid);
-
- if (rv != WIFI_MANAGER_ERROR_NONE) {
- printf("\nFail to connect (can't get AP list) [%s]", __print_wifi_error(rv));
- __do_exit();
- }
-
+ _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)
{
- int rv = 0;
- sa_error_e ret = SA_ERROR_UNKNOWN;
-
+ GMainLoop *gmain_loop = NULL;
GMainContext *context;
- GMainLoop *main_loop;
- context = g_main_context_new ();
- g_main_context_push_thread_default (context); // should be.. to get mainloop message in thread
- main_loop = g_main_loop_new (context, FALSE);
+ _wifi_data_s wifi_data = {0,};
- printf("\n------------------- connect_wifi -------------------");
+ int rv = 0;
+ sa_error_e ret = SA_ERROR_UNKNOWN;
+ 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;
}
- wifi_manager_h wifi = NULL;
-
- rv = wifi_manager_initialize(&wifi);
+ 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) {
- wifi_manager_set_device_state_changed_cb(wifi, __activate_state_changed_cb, (void *)info);
- wifi_manager_set_connection_state_changed_cb(wifi, __connection_state_callback, NULL);
- wifi_handle = wifi;
- rv = __do_activate(&wifi, info);
- if (rv == WIFI_MANAGER_ERROR_ALREADY_EXISTS) {
- printf("\nalready existed [%s]", __print_wifi_error(rv));
- __do_connect(info);
+ // 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 {
- printf("\\nWifi init failed [%s]", __print_wifi_error(rv));
+ }
+ else {
+ _E("Wifi init failed [%s]", __print_wifi_error(rv));
return SA_ERROR_UNKNOWN;
}
- g_main_loop_run (main_loop);
+ g_main_loop_run (gmain_loop);
+ gmain_loop = NULL;
-/*
- printf("\n thread exit");
- wifi_manager_unset_scan_state_changed_cb(wifi);
- wifi_manager_unset_connection_state_changed_cb(wifi);
+ wifi_manager_unset_scan_state_changed_cb(wifi_h);
+ wifi_manager_unset_connection_state_changed_cb(wifi_h);
- rv = wifi_manager_deinitialize(wifi);
+ rv = wifi_manager_deinitialize(wifi_h);
if (rv != WIFI_MANAGER_ERROR_NONE) {
- printf("Fail to deinitialize.\n");
+ _D("Fail to deinitialize.");
ret = SA_ERROR_UNKNOWN;
}
- wifi_handle = NULL;
+ _D("__wifi_connect_main completed.");
- printf("\n end connect_wifi");
-*/
return ret;
}
-static int connect_ethernet(sa_eth_s *info)
+
+
+
+
+
+
+
+
+
+
+
+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)
-{
- 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) {
- printf("\nFail 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) {
- printf("\nFail to get essid [%s]", __print_wifi_error(rv));
- wifi_manager_ap_destroy(ap_h);
- return -1;
- }
- printf("\nConnected 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) {
- connection_h connection = NULL;
- char *ip_addr = NULL;
+
+
+
+
+static int __network_get_wifi_state(connection_h connection, connection_wifi_state_e *wifi_state)
+{
int rv = 0;
- int ret = 0;
-
- if (info != NULL) {
- // only for ipv4
- rv = connection_create(&connection);
- printf("\nconnection_create : ret[%s]", __print_error(rv));
- if (rv != CONNECTION_ERROR_NONE) {
- printf("\ncreate connection handle error [%s]", __print_error(rv));
- return -1;
- }
- rv = connection_get_ip_address(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &ip_addr);
- if (ip_addr != NULL) {
- printf("\nIPv4 address does not exist");
- printf("\nIPv4 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);
- } else {
- ret = -1;
- }
+ if (connection == NULL) {
+ return -1;
+ }
- rv = connection_destroy(connection);
- if (rv != CONNECTION_ERROR_NONE) {
- printf("connection destroy fail [%s]\n", __print_error(rv));
- 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));
}
- return ret;
+ return 0;
}
-static sa_error_e 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_wifi_state_e wifi_state;
int rv = 0;
- printf("\nnetwork_get_state~~~");
-
rv = connection_create(&connection);
- printf("\nconnection_create : ret[%s]", __print_error(rv));
if (rv != CONNECTION_ERROR_NONE) {
- printf("\ncreate connection handle error [%s]", __print_error(rv));
+ _E("create connection handle error [%s]", __print_error(rv));
return -1;
}
// check network state(eth/wifi)
rv = connection_get_type(connection, &net_state);
- printf("\nconnection_get_type return(%d)", rv);
if (rv != CONNECTION_ERROR_NONE) {
- printf("\nFail to get network state [%s]\n", __print_error(rv));
+ _E("Fail to get network state [%s]", __print_error(rv));
} else {
ret = SA_ERROR_NONE;
- printf("\nRetval = [%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, 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) {
- printf("connection destroy fail [%s]\n", __print_error(rv));
+ _E("connection destroy fail [%s]", __print_error(rv));
return -1;
}
return ret;
}
-static sa_error_e network_set_connection(sa_network_s *info)
+
+static sa_error_e __network_connect(sa_network_s *info)
{
sa_error_e ret = SA_ERROR_NONE;
int retWifi = 0;
if (info->wifi != NULL) {
if (info->wifi->enabled == TRUE) {
- retWifi = connect_wifi(info->wifi);
- printf("\nreturn wifi [%d]", retWifi);
+ retWifi = __wifi_connect_main(info->wifi);
+ _D("return wifi [%d]", retWifi);
} else {
- printf("\nwifi enabled flag is false");
+ _D("wifi enabled flag is false");
}
}
if (info->eth != NULL) {
// decide whether it will be set according to policy
if (info->eth->enabled == TRUE){
- retEth = connect_ethernet(info->eth);
- printf("\nreturn ethernet [%d]", retEth);
+ retEth = __ethernet_connect_main(info->eth);
+ _D("return ethernet [%d]", retEth);
}
}
- printf("\nEnd setting");
-
return ret;
}
-static sa_error_e network_get_current_connection(sa_network_s *info)
-{
- connection_h connection = NULL;
- sa_error_e ret = SA_ERROR_NONE;
- connection_type_e net_state;
-
- int rv = 0;
-
- // get network state
- rv = connection_create(&connection);
- printf("\nconnection_create : ret[%s]", __print_error(rv));
- if (rv != CONNECTION_ERROR_NONE) {
- printf("\ncreate connection handle error[%s]", __print_error(rv));
- return SA_ERROR_UNKNOWN;
- }
-
- if (connection != NULL) {
- rv = connection_get_type(connection, &net_state);
- if (rv == CONNECTION_ERROR_NONE) {
- // get detail information
- if (CONNECTION_TYPE_WIFI == net_state) {
- // 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 {
- printf("\nconnection_get_type is err [%s]", __print_error(rv));
- }
- } else {
- printf("\nConnection handle is null");
- }
-
- rv = connection_destroy(connection);
- if (rv != CONNECTION_ERROR_NONE) {
- printf("connection destroy fail [%s]\n", __print_error(rv));
- return -1;
- }
-
- return ret;
-}
-
-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;
+ return SA_ERROR_INVALID_PARAMETER;
}
// 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(¤tNetwork);
- if (ret == SA_ERROR_NONE) {
- // compare network info
- if (compare_network_info(¤tNetwork, 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);
+ ret = __network_connect(network);
- free(currentNetwork.eth);
- }
- } else {
- // in case of disconnect state
- _D("Set Network Connection !!");
- ret = network_set_connection(network);
- }
- }
-
+ // 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