if (type == json_type_object) {
if (json_object_object_get_ex(inputObj, key, &bodyObj)) {
ret = json_object_get_int(bodyObj);
- }
+ }
}
return ret;
}
if (type == json_type_object) {
if (json_object_object_get_ex(inputObj, key, &bodyObj)) {
ret = json_object_get_boolean(bodyObj);
- }
+ }
}
return ret;
}
_D("Network::eth::dhcpEnabled[%d]", eth->dhcpEnabled);
if (eth->dhcpEnabled == 0)
- print_config_network_static_info(wifi->staticInfo);
+ print_config_network_static_info(eth->staticInfo);
}
}
}
//ipAddress
ipAddress = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_IPADDRESS);
if (ipAddress != NULL) {
- memcpy(staticInfo->ipAddress, ipAddress, MIN(strlen(ipAddress), sizeof(staticInfo->ipAddress)-1));
+ _D("ipaddress = %s", ipAddress);
+ memcpy(staticInfo->ipAddress, ipAddress, strlen(ipAddress));
free(ipAddress);
ipAddress = NULL;
+
}
//netmask
netmask = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_NETMASK);
if (netmask != NULL) {
- memcpy(staticInfo->netmask, netmask, MIN(strlen(netmask), sizeof(staticInfo->netmask)-1));
+ memcpy(staticInfo->netmask, netmask,strlen(netmask));
free(netmask);
netmask = NULL;
}
//defaultGateway
defaultGateway = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_DEFAULTGATEWAY);
if (defaultGateway != NULL) {
- memcpy(staticInfo->defaultGateway, defaultGateway, MIN(strlen(defaultGateway), sizeof(staticInfo->defaultGateway)-1));
+ memcpy(staticInfo->defaultGateway, defaultGateway, strlen(defaultGateway));
free(defaultGateway);
defaultGateway = NULL;
}
-
+
//primaryDnsServer
primaryDnsServer = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_PRIMARYDNSSERVER);
if (primaryDnsServer != NULL) {
- memcpy(staticInfo->primaryDnsServer, primaryDnsServer, MIN(strlen(primaryDnsServer), sizeof(staticInfo->primaryDnsServer)-1));
+ memcpy(staticInfo->primaryDnsServer, primaryDnsServer, strlen(primaryDnsServer));
free(primaryDnsServer);
primaryDnsServer = NULL;
}
-
+
//secondaryDnsServer
secondaryDnsServer = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_SECONDARYDNSSERVER);
if (secondaryDnsServer != NULL) {
- memcpy(staticInfo->secondaryDnsServer, secondaryDnsServer, MIN(strlen(secondaryDnsServer), sizeof(staticInfo->secondaryDnsServer)-1));
+ memcpy(staticInfo->secondaryDnsServer, secondaryDnsServer, strlen(secondaryDnsServer));
free(secondaryDnsServer);
secondaryDnsServer = NULL;
}
if (eth->dhcpEnabled == FALSE) {
eth->staticInfo = (sa_network_static_s *)malloc(sizeof(sa_network_static_s));
if (eth->staticInfo != NULL) {
+ _D("parse_network eth!!!\n");
ret = __parse_network_static_info(inputObj, eth->staticInfo);
} else {
ret = -1;
} else {
ret = -1;
}
- }
+ }
return ret;
}
_D("__parse_network_data fail");
return -1;
}
-
+
return 0;
}
_D("__parse_system_data input error");
return -1;
}
-
+
//httpProxyHost
httpProxyHost = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_HTTPPROXYHOST);
if (httpProxyHost != NULL) {
memcpy(setupConfig->systemData->proxy->httpProxyHost, httpProxyHost, MIN(strlen(httpProxyHost), sizeof(setupConfig->systemData->proxy->httpProxyHost)-1));
free(httpProxyHost);
httpProxyHost = NULL;
-
+
//httpProxyPort
setupConfig->systemData->proxy->httpProxyPort = json_get_int_from_obj(inputObj, SA_CONFIG_NETWORKDATA_HTTPPROXYPORT);
if (ret == 0) {
ret = __parse_system_data(configObj, setupConfig);
}
-
+
if (ret == 0) {
ret = __parse_network_data(configObj, setupConfig);
}
ret = -1;
_D("ConfigObj is not existed");
}
-
+
json_object_put(configObj);
free(jsonData);
} else {
}
print_config_info(config);
-
+
return ret;
}
if (network != NULL) {
if (network->wifi != NULL) {
if (network->wifi->staticInfo != NULL)
- free(network->wifi->staticInfo);
-
+ free(network->wifi->staticInfo);
+
free(network->wifi);
}
{
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;
/* 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
+/*{"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}*/
_D("OK!!! connect AP [%s]", ap_name);
rv = wifi_manager_ap_is_passphrase_required(ap, &required);
-
+
if (rv == WIFI_MANAGER_ERROR_NONE) {
if (required) {
_D(" passphrase1 : [%s]", wifi_data->password);
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) {
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) {
_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;
}
+connection_h eth_connect;
+
+static bool __eth_get_user_selected_profile(connection_profile_h *profile, bool select)
+{
+ int rv = 0;
+ int input = 0;
+ char *profile_name;
+ connection_profile_type_e profile_type;
+ connection_profile_state_e profile_state;
+ connection_profile_iterator_h profile_iter;
+ connection_profile_h profile_h;
+
+ rv = connection_get_profile_iterator(eth_connect, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter);
+ if (rv != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile iterator error\n" );
+ return false;
+ }
+ while (connection_profile_iterator_has_next(profile_iter)) {
+ if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile handle\n");
+ return false;
+ }
+ if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile name\n");
+ return false;
+ }
+ if (connection_profile_get_type(profile_h, &profile_type) != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile type\n");
+ g_free(profile_name);
+ return false;
+ }
+ if (connection_profile_get_state(profile_h, &profile_state) != CONNECTION_ERROR_NONE) {
+ printf("Fail to get profile state\n");
+ g_free(profile_name);
+ return false;
+ }
+ if (!strncmp(profile_name, "eth0", strlen("eth0"))) {
+ printf("profile > %s\n", profile_name);
+ if (profile) {
+ *profile = profile_h;
+ }
+ }
+ g_free(profile_name);
+ }
+ return true;
+}
+static int __eth_update_ip_info(sa_eth_s *info, connection_profile_h profile, connection_address_family_e address_family)
+{
+ int rv = 0;
+ int input_int = 0;
+ char input_str[100] = {0,};
+ _D("ipaddress =%s", info->staticInfo->ipAddress);
+ if (info->staticInfo->ipAddress != NULL) {
+ rv = connection_profile_set_ip_address(profile,
+ address_family,
+ info->staticInfo->ipAddress);
+ if (rv != CONNECTION_ERROR_NONE)
+ return -1;
+ }
+#if 0
+ _D("netmask =%s", info->staticInfo->netmask);
+ if (info->staticInfo->netmask != NULL) {
+ rv = connection_profile_set_subnet_mask(profile,
+ address_family,
+ info->staticInfo->netmask);
+ if (rv != CONNECTION_ERROR_NONE)
+ return -1;
-static int __ethernet_connect_main(sa_eth_s *info)
+ }
+
+ if (info->staticInfo->defaultGateway != NULL) {
+ rv = connection_profile_set_gateway_address(profile,
+ address_family,
+ info->staticInfo->defaultGateway);
+ if (rv != CONNECTION_ERROR_NONE)
+ return -1;
+ _D("gateway =%s", info->staticInfo->defaultGateway);
+ }
+ if (info->staticInfo->primaryDnsServer != NULL ) {
+ rv = connection_profile_set_dns_address(profile,
+ 1,
+ address_family,
+ info->staticInfo->primaryDnsServer);
+ if (rv != CONNECTION_ERROR_NONE)
+ return -1;
+
+ _D("DNS 1 =%s", info->staticInfo->primaryDnsServer);
+
+ if (info->staticInfo->secondaryDnsServer != NULL ) {
+ rv = connection_profile_set_dns_address(profile,
+ 2,
+ address_family,
+ info->staticInfo->secondaryDnsServer);
+ if (rv != CONNECTION_ERROR_NONE)
+ return -1;
+ _D("DNS 2 =%s", info->staticInfo->secondaryDnsServer);
+ }
+ }
+#endif
+
+ return 1;
+}
+
+static int __eth_update_ip(sa_eth_s *info)
{
- if (info == NULL) {
+ int rv = 0;
+
+ connection_profile_type_e prof_type;
+ connection_profile_h profile;
+ int address_family = 0; // IPv4
+
+ //printf("\n** Choose a profile to update. **\n");
+ if (__eth_get_user_selected_profile(&profile, true) == false) {
+ _D("profile failed \n");
return -1;
}
-
- // check network cable
- // check dhcp / static
- // set ip
- return 0;
+ if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE) {
+ _D("profile connection error!! \n");
+ return -1;
+ }
+
+ if (connection_profile_set_ip_config_type(profile, address_family, CONNECTION_IP_CONFIG_TYPE_STATIC) != CONNECTION_ERROR_NONE) {
+ _D("setting error !!\n");
+ return -1;
+ }
+ if (__eth_update_ip_info(info, profile, address_family) != 1) {
+ _D("ip setting error!!\n");
+ return -1;
+ }
+
+ if(connection_profile_set_proxy_type(profile,CONNECTION_PROXY_TYPE_DIRECT) != CONNECTION_ERROR_NONE)
+ return -1;
+
+ if (connection_update_profile(eth_connect, profile) != CONNECTION_ERROR_NONE) {
+ _D("profile update error !!\n");
+ return -1;
+ }
+
+ _D("operation sucess\n");
+ return 1;
+}
+
+static int __eth_register_client(void)
+{
+
+ if (CONNECTION_ERROR_NONE != connection_create(ð_connect)) {
+ _D("Client registration failed \n");
+ return -1;
+ }
+
+ _D("Client registration success\n");
+ return 1;
}
+static int __eth_deregister_client(void)
+{
+ int rv = 0;
+ GSList *list;
+ connection_profile_h profile;
+ if (eth_connect != NULL)
+ rv = connection_destroy(eth_connect);
+ else {
+ _D("Cannot deregister : Handle is NULL\n");
+ rv = CONNECTION_ERROR_INVALID_OPERATION;
+ }
+ if (rv != CONNECTION_ERROR_NONE) {
+ _D("Client deregistration fail\n");
+ return -1;
+ }
+ eth_connect = NULL;
+ _D("Client deregistration success\n");
+ return 1;
+}
+static int __ethernet_connect_main(sa_eth_s *info)
+{
+ if (info == NULL) {
+ return -1;
+ }
+ if(__eth_register_client() == 1) {
+ __eth_update_ip(info);
+ __eth_deregister_client();
+ }
+ else
+ _D("connection error!!!\n");
+
+
+ return 0;
+}
static int __network_get_wifi_state(connection_h connection, connection_wifi_state_e *wifi_state)
_E("create connection handle error [%s]", __print_error(rv));
return -1;
}
-
+
// check network state(eth/wifi)
rv = connection_get_type(connection, &net_state);
if (rv != CONNECTION_ERROR_NONE) {
_E("Fail to get network state [%s]", __print_error(rv));
} else {
ret = SA_ERROR_NONE;
- _D("Retval = [%s] network connection state [%s]", __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) {
if (info == NULL) {
return SA_ERROR_INVALID_PARAMETER;
}
-
+
+ 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);
+ }
+ }
+
if (info->wifi != NULL) {
if (info->wifi->enabled == TRUE) {
retWifi = __wifi_connect_main(info->wifi);
}
}
- 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;
}
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
+}