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);
- }
+ 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);
+ 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);
+ 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);
+ 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)
- free(network->wifi->staticInfo);
+ 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);
// compare wifi
// wifi has higher priority to compare.
// If wifi info is changed, it doesn't have to compare ethernet info
- if (devNetwork->wifi != NULL && newNetwork->wifi != NULL) {
+ if (newNetwork->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)) {
+ // 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;
}
- // TBD for checking other members such as, ipaddress, dns, gateway....
}
}
- if (needChange == FALSE && (devNetwork->eth != NULL && newNetwork->eth != NULL)) {
+ if (needChange == FALSE && newNetwork->eth != NULL) {
if (newNetwork->eth->enabled == TRUE) {
- // 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;
+ 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;
}
static int __set_network(sa_network_s *network)
{
- sa_network_s *currentNetwork = NULL;
+ 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) {
+ 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);
if (ret == SA_ERROR_NONE) {
- _D("Device Network : Type[%d][%s] State[%d][%s]", conn_type, __print_connection_type(conn_type), conn_state, __print_connection_state(conn_state));
+ _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 && currentNetwork != NULL) {
+ ret = sa_network_get_connection(¤tNetwork);
+ if (ret == SA_ERROR_NONE) {
// compare network info
- if (__compare_network_info(currentNetwork, network)) {
+ 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]", ret);
+ _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);
}
}
sa_proxy_s *devProxy = NULL;
sa_error_e ret = SA_ERROR_NONE;
- if (system != NULL) {
- 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);
- }
+ 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);
}
}
switch (state) {
case SA_FILE_STATE_REGISTERED:
_D("SA_FILE_STATE_REGISTERED");
- _D("start parsing");
if (SA_ERROR_NONE == __parsing_config(&config)) {
if (config.systemData != NULL) {
+ _D("Set system data");
__set_system(config.systemData);
}
if (config.networkData != NULL) {
- //__set_network(config->networkData);
+ _D("Set nework data");
+ __set_network(config.networkData);
}
__release_config_resource(&config);
}
//Check Config file
if (SA_FILE_STATE_EXIST == sa_inputfile_get_config_state()) {
// Register callback to receive file change event
+ sleep(10);
ret = sa_inputfile_register_cb(__monitor_file_state_cb);
if (ret != SA_ERROR_NONE) {
_E("__init_event_listener error [%d]", ret);
_D("config file is not existed, setup-adaptor exit");
}
- _D("main thread end");
while(1) {
sleep(1);
}
+
return 0;
}
\ No newline at end of file
#include "net_connection.h"
#include "wifi-manager.h"
-static int initialize_setup_network_flag;
-static sa_network_state_e setup_network_wifi_state;
-static char wifi_password[99+1];
-static connection_h connection_handle = NULL;
-static wifi_manager_h *wifi_handle = NULL;
+
+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)
{
return initialize_setup_network_flag;
}
-static void __set_setup_network_wifi_state(sa_network_state_e val)
+static int __set_setup_network_initialized(int val)
{
if (val != __get_setup_network_initialized()) {
- setup_network_wifi_state = val;
+ initialize_setup_network_flag = val;
}
}
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)) {
}
static void __scan_request_callback(wifi_manager_error_e error_code, void* user_data)
-{
- __set_setup_network_wifi_state(NETWORK_WIFI_STATE_ACTIVATED);
-
- if (error_code == WIFI_MANAGER_ERROR_NONE) {
- __set_setup_network_wifi_state(NETWORK_WIFI_STATE_SCANNED);
- _D("Scan Completed from scan request");
- }
- else
- _D("Wi-Fi Scan Failed! error : %s", __print_wifi_error(error_code));
+{
+ if (user_data != NULL)
+ _D("user_data : %s", (char *)user_data);
+ _D("Scan Completed from scan request [%s]", __print_wifi_error(error_code));
+}
+
+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));
}
static int __compare_ap_name(const char *ap_name, const char *ap_name_part)
_D("Wi-Fi Connection Failed! error : %s", __print_wifi_error(result));
}
+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);
+ }
+}
+
static void __found_connect_ap_callback(wifi_manager_ap_h ap, void *user_data)
{
int rv = 0;
return;
}
+static int __start_setup_network(void)
+{
+ 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;
+ }
+
+ return 0;
+}
static int __connect_wifi(sa_wifi_s *info)
{
int rv = 0;
bool state = false;
- int ret = 0;
- sa_network_state_e wifi_state = SA_NETWORK_STATE_DISCONNECTED;
+ sa_error_e ret = SA_ERROR_UNKNOWN;
+ sa_network_state_e file_state = NETWORK_WIFI_STATE_DEACTIVATED;
if (info == NULL) {
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
- if (NETWORK_WIFI_STATE_DEACTIVATED == __get_setup_network_wifi_state()) {
+ 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) {
- printf("Fail to get Wi-Fi device state [%s]", __print_wifi_error(rv));
+ _D("Fail to get Wi-Fi device state [%s]", __print_wifi_error(rv));
+ ret = SA_ERROR_UNKNOWN;
break;
}
- __set_setup_network_wifi_state(NETWORK_WIFI_STATE_ACTIVATING);
- rv = wifi_manager_activate(wifi_handle, __activated_callback, NULL);
- if (rv != WIFI_MANAGER_ERROR_NONE) {
- printf("Fail to activate Wi-Fi device [%s]", __print_wifi_error(rv));
- 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);
}
- }
-
- if (NETWORK_WIFI_STATE_ACTIVATED == __get_setup_network_wifi_state()) {
- // scan ap
- __set_setup_network_wifi_state(NETWORK_WIFI_STATE_SCANNING);
- rv = wifi_manager_scan(wifi_handle, __scan_request_callback, NULL);
+ 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");
}
- }
-
- if (NETWORK_WIFI_STATE_SCANNED == __get_setup_network_wifi_state()) {
+ 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;
+ }
sleep(1);
}
- return rv;
+ return ret;
}
static int __connect_ethernet(sa_eth_s *info)
return 0;
}
-static int __start_setup_network(void)
-{
- int ret = 0;
- int err_code = 0;
-
- err_code = wifi_manager_initialize(wifi_handle);
- if (err_code == WIFI_MANAGER_ERROR_NONE) {
- err_code = connection_create(&connection_handle);
- if (err_code != CONNECTION_ERROR_NONE)
- return -1;
- } else {
- return -1;
- }
-
- return 0;
-}
-
static int __get_wifi_info(sa_wifi_s *info)
{
int rv = 0;
free(ap_name);
wifi_manager_ap_destroy(ap_h);
- return rv;
+ return 0;
}
static int __get_ethernet_info(sa_eth_s *info) {
return -1;
}
_D("IPv4 address : %s", ip_addr);
- memcpy(info->staticInfo->ipAddress, ip_addr, MIN(strlen(ip_addr), sizeof(info->staticInfo->ipAddress)-1));
+ 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);
}
- return rv;
+ return 0;
}
-int sa_network_get_state(sa_network_state_e *conn_state, sa_network_type_e *conn_type)
+sa_error_e sa_network_get_state(sa_network_state_e *conn_state, sa_network_type_e *conn_type)
{
sa_error_e ret = SA_ERROR_UNKNOWN;
connection_type_e net_state;
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;
}
}
// check network state(eth/wifi)
retEth = __connect_ethernet(info->eth);
}
}*/
+ } else {
+ _D("wifi enabled flag is false");
}
}
+
+ _D("End setting");
- return 0;
+ return ret;
}
sa_error_e sa_network_get_connection(sa_network_s *info)
{
- sa_error_e ret;
+ sa_error_e ret = SA_ERROR_NONE;
connection_type_e net_state;
connection_wifi_state_e wifi_state;
sa_network_state_e conn_state;
}
}
// get network state
- 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);
- }
- }
+ 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");
}
return ret;