#include "setup_network.h"
#include "input_file.h"
-
-static gboolean prepare(GSource *source, gint *timeout)
+static gboolean prepare(GSource * source, gint * timeout)
{
return TRUE;
}
gboolean setup_cb(gpointer data)
{
sa_error_e ret = SA_ERROR_NONE;
- sa_config_s config = {0,};
+ sa_config_s config = { 0, };
sa_error_e file_read = SA_ERROR_NONE;
-
+
_D("callback>>>setup_cb start !!!");
file_read = sa_inputfile_get_config_info(&config);
if (file_read == SA_ERROR_NONE) {
_D("flag_completion(system=%d)(eth=%d)(wifi=%d)", sa_inputfile_get_completion_flag(SA_FILE_CONFIG_SYSTEM)
- , sa_inputfile_get_completion_flag(SA_FILE_CONFIG_ETHERNET)
- , sa_inputfile_get_completion_flag(SA_FILE_CONFIG_WIFI) );
+ , sa_inputfile_get_completion_flag(SA_FILE_CONFIG_ETHERNET)
+ , sa_inputfile_get_completion_flag(SA_FILE_CONFIG_WIFI));
- if (config.systemData != NULL && !sa_inputfile_get_completion_flag(SA_FILE_CONFIG_SYSTEM) ) {
+ if (config.systemData != NULL && !sa_inputfile_get_completion_flag(SA_FILE_CONFIG_SYSTEM)) {
ret = sa_setup_system(config.systemData);
- if(ret != SA_ERROR_NONE) {
+ if (ret != SA_ERROR_NONE)
_E("sa_setup_system return error(%d)", ret);
- }
}
sa_inputfile_set_completion_flag(SA_FILE_CONFIG_SYSTEM);
-
if (config.networkData != NULL) {
ret = sa_setup_network(config.networkData);
- if(ret != SA_ERROR_NONE) {
+ if (ret != SA_ERROR_NONE)
_E("sa_setup_network return error(%d)", ret);
- }
- }
- else {
+ } else {
sa_inputfile_set_completion_flag(SA_FILE_CONFIG_ETHERNET);
sa_inputfile_set_completion_flag(SA_FILE_CONFIG_WIFI);
}
sa_inputfile_remove();
}
-static GSourceFuncs SourceFuncs =
-{
- prepare, // prepare function
- NULL, // function check
- sa_inputfile_thread, // main function to execute
+static GSourceFuncs SourceFuncs = {
+ prepare, // prepare function
+ NULL, // function check
+ sa_inputfile_thread, // main function to execute
NULL
};
-// config for main thread & callback function
-static gpointer main_thread (gpointer data)
+// config for main thread & callback function
+static gpointer main_thread(gpointer data)
{
- GSource* src = NULL;
+ GSource *src = NULL;
_D("main_thread ~~~");
- GMainLoop* main_loop;
- GMainContext* context = NULL;
+ GMainLoop *main_loop;
+ GMainContext *context = NULL;
- context = g_main_context_new ();
- main_loop = g_main_loop_new (context, FALSE);
+ context = g_main_context_new();
+ main_loop = g_main_loop_new(context, FALSE);
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, // GSourceFuncs prototype
- (GSourceFunc) setup_cb, // callabck function
- (gpointer) main_loop, // gpointer : set as GMainLoop handle to destroy in thread
- NULL);
- g_source_attach (src, context);
+
+ g_source_set_name(src, "setup-adaptor-func");
+ g_source_set_priority(src, G_PRIORITY_DEFAULT);
+ g_source_set_callback(src, // GSourceFuncs prototype
+ (GSourceFunc) setup_cb, // callabck function
+ (gpointer) main_loop, // gpointer : set as GMainLoop handle to destroy in thread
+ NULL);
+ g_source_attach(src, context);
g_main_loop_run(main_loop);
g_main_loop_unref(main_loop);
- if(data) {
- g_main_loop_quit( (GMainLoop*)data );
- }
+
+ if (data)
+ g_main_loop_quit((GMainLoop *) data);
+
_D("main_thread exit~~~");
return NULL;
}
int main(int argc, char *argv[])
-{
+{
sa_file_state_e file_state = SA_FILE_STATE_NOT_EXISTED;
- sa_config_s config = {0,};
+ sa_config_s config = { 0, };
// check if exists config file
file_state = sa_inputfile_get_config_state();
g_main_loop_run(main_loop);
g_main_loop_unref(main_loop);
-
+
return 0;
-}
\ No newline at end of file
+}
_D("__config_main_loop start\n");
- callback = (file_state_cb)arg;
+ callback = (file_state_cb) arg;
if (callback == NULL) {
_D("Ccallback is null for event");
if (event->mask & IN_CREATE) {
if (event->mask & IN_ISDIR) {
_D("The directory %s was created", event->name);
- }
- else {
+ } else {
_D("The file %s was create.", event->name);
- if (!strcmp(event->name, CONFIG_NAME)) {
+ if (!strcmp(event->name, CONFIG_NAME))
_D("config.json is created!!");
- }
}
} else if (event->mask & IN_DELETE) {
if (event->mask & IN_ISDIR) {
_D("The directory %s was deleted.", event->name);
- }
- else {
+ } else {
_D("The file %s was deleted", event->name);
- if (!strcmp(event->name, CONFIG_NAME)) {
+ if (!strcmp(event->name, CONFIG_NAME))
_D("config.json is deleted!!");
- }
}
} else if (event->mask & IN_MODIFY) {
if (event->mask & IN_ISDIR) {
_D("The directory %s was modified", event->name);
- }
- else {
+ } else {
if (!strcmp(event->name, CONFIG_NAME)) {
_D("config.json is modified!!");
callback(SA_FILE_STATE_CHANGED, NULL, NULL);
return 0;
}
-static int json_get_int_from_obj(json_object *inputObj, char *key)
+static int json_get_int_from_obj(json_object * inputObj, char *key)
{
struct json_object *bodyObj;
enum json_type type;
type = json_object_get_type(inputObj);
if (type == json_type_object) {
- if (json_object_object_get_ex(inputObj, key, &bodyObj)) {
+ if (json_object_object_get_ex(inputObj, key, &bodyObj))
ret = json_object_get_int(bodyObj);
- }
}
return ret;
}
-static int json_get_boolean_from_obj(json_object *inputObj, char *key)
+static int json_get_boolean_from_obj(json_object * inputObj, char *key)
{
struct json_object *bodyObj;
enum json_type type;
type = json_object_get_type(inputObj);
if (type == json_type_object) {
- if (json_object_object_get_ex(inputObj, key, &bodyObj)) {
+ if (json_object_object_get_ex(inputObj, key, &bodyObj))
ret = json_object_get_boolean(bodyObj);
- }
}
return ret;
}
-static char *json_get_string_from_obj(json_object *inputObj, char *key)
+static char *json_get_string_from_obj(json_object * inputObj, char *key)
{
const char *buf = NULL;
char *ret_buf = NULL;
return ret_buf;
}
-static void print_config_network_static_info(sa_network_static_s *staticInfo)
+static void print_config_network_static_info(sa_network_static_s * staticInfo)
{
if (staticInfo != NULL) {
if (staticInfo->ipAddress != NULL)
}
}
-static void print_network_config(sa_network_s *network)
+static void print_network_config(sa_network_s * network)
{
sa_wifi_s *wifi = NULL;
sa_eth_s *eth = NULL;
}
}
-static void print_system_config(sa_system_s *systemData)
+static void print_system_config(sa_system_s * systemData)
{
if (systemData != NULL) {
if (systemData->proxy != NULL) {
}
}
-static void print_config_info(sa_config_s *config)
+static void print_config_info(sa_config_s * config)
{
if (config != NULL) {
- if (config->version != NULL) {
+ if (config->version != NULL)
_D("Version [%s]", config->version);
- }
- if(config->networkData)
- {
+
+ if (config->networkData)
print_network_config(config->networkData);
- }
- if(config->systemData)
- {
+
+ if (config->systemData)
print_system_config(config->systemData);
- }
}
}
-static int __parse_network_static_info(json_object *inputObj, sa_network_static_s *staticInfo)
+static int __parse_network_static_info(json_object * inputObj, sa_network_static_s * staticInfo)
{
char *ipAddress = NULL;
char *netmask = NULL;
_D("__parse_network_static_info input error");
return -1;
}
-
//ipAddress
ipAddress = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_IPADDRESS);
if (ipAddress != NULL) {
free(ipAddress);
ipAddress = NULL;
}
-
//netmask
netmask = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_NETMASK);
if (netmask != NULL) {
- memcpy(staticInfo->netmask, netmask,strlen(netmask));
+ 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) {
free(defaultGateway);
defaultGateway = NULL;
}
-
//primaryDnsServer
primaryDnsServer = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_PRIMARYDNSSERVER);
if (primaryDnsServer != NULL) {
free(primaryDnsServer);
primaryDnsServer = NULL;
}
-
//secondaryDnsServer
secondaryDnsServer = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_SECONDARYDNSSERVER);
if (secondaryDnsServer != NULL) {
return 0;
}
-static int __parse_network_eth(json_object *inputObj, sa_eth_s *eth)
+static int __parse_network_eth(json_object * inputObj, sa_eth_s * eth)
{
int ret = 0;
_D("__parse_network_eth input error");
return -1;
}
-
// enabled
eth->enabled = json_get_boolean_from_obj(inputObj, SA_CONFIG_NETWORKDATA_ENABLED);
// dhcpEnabled
eth->dhcpEnabled = json_get_boolean_from_obj(inputObj, SA_CONFIG_NETWORKDATA_DHCPENABLED);
if (eth->dhcpEnabled == FALSE) {
- eth->staticInfo = (sa_network_static_s *)malloc(sizeof(sa_network_static_s));
- if (eth->staticInfo != NULL) {
+ eth->staticInfo = (sa_network_static_s *) malloc(sizeof(sa_network_static_s));
+ if (eth->staticInfo != NULL)
ret = __parse_network_static_info(inputObj, eth->staticInfo);
- } else {
+ else
ret = -1;
- }
}
return ret;
}
-static int __parse_network_wifi(json_object *inputObj, sa_wifi_s *wifi)
+static int __parse_network_wifi(json_object * inputObj, sa_wifi_s * wifi)
{
char *ssid = NULL;
char *password = NULL;
// ssid
ssid = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_WIFI_SSID);
if (ssid != NULL) {
- memcpy(wifi->ssid, ssid, MIN(strlen(ssid), sizeof(wifi->ssid)-1));
+ memcpy(wifi->ssid, ssid, MIN(strlen(ssid), sizeof(wifi->ssid) - 1));
free(ssid);
ssid = NULL;
} else {
// password
password = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_WIFI_PASSWORD);
if (password != NULL) {
- memcpy(wifi->password, password, MIN(strlen(password), sizeof(wifi->password)-1));
+ memcpy(wifi->password, password, MIN(strlen(password), sizeof(wifi->password) - 1));
free(password);
password = NULL;
} else {
// dhcpEnabled
wifi->dhcpEnabled = json_get_boolean_from_obj(inputObj, SA_CONFIG_NETWORKDATA_DHCPENABLED);
if (wifi->dhcpEnabled == FALSE) {
- wifi->staticInfo = (sa_network_static_s *)malloc(sizeof(sa_network_static_s));
- if (wifi->staticInfo != NULL) {
+ wifi->staticInfo = (sa_network_static_s *) malloc(sizeof(sa_network_static_s));
+ if (wifi->staticInfo != NULL)
ret = __parse_network_static_info(inputObj, wifi->staticInfo);
- } else {
+ else
ret = -1;
- }
- }
+ }
return ret;
}
-static int __parse_network_data(json_object *inputObj, sa_config_s *setupConfig)
+static int __parse_network_data(json_object * inputObj, sa_config_s * setupConfig)
{
struct json_object *wifiObj = NULL;
struct json_object *ethernetObj = NULL;
return -1;
}
- setupConfig->networkData = (sa_network_s *)malloc(sizeof(sa_network_s));
+ setupConfig->networkData = (sa_network_s *) malloc(sizeof(sa_network_s));
if (setupConfig->networkData != NULL) {
//parse wifi
if (json_object_object_get_ex(inputObj, SA_CONFIG_NETWORKDATA_WIFI, &wifiObj)) {
if (json_object_get_type(wifiObj) == json_type_object) {
// malloc
- setupConfig->networkData->wifi = (sa_wifi_s *)malloc(sizeof(sa_wifi_s));
- if (setupConfig->networkData->wifi != NULL) {
+ setupConfig->networkData->wifi = (sa_wifi_s *) malloc(sizeof(sa_wifi_s));
+ if (setupConfig->networkData->wifi != NULL)
wifiRet = __parse_network_wifi(wifiObj, setupConfig->networkData->wifi);
- } else {
+ else
_D("network->wifi malloc fail");
- }
}
}
-
//parse eth
if (json_object_object_get_ex(inputObj, SA_CONFIG_NETWORKDATA_ETHERNET, ðernetObj)) {
if (json_object_get_type(ethernetObj) == json_type_object) {
// malloc
- setupConfig->networkData->eth = (sa_eth_s *)malloc(sizeof(sa_eth_s));
- if (setupConfig->networkData->eth != NULL) {
+ setupConfig->networkData->eth = (sa_eth_s *) malloc(sizeof(sa_eth_s));
+ if (setupConfig->networkData->eth != NULL)
ethRet = __parse_network_eth(ethernetObj, setupConfig->networkData->eth);
- } else {
+ else
_D("network->eth malloc fail");
- }
}
}
} else {
return 0;
}
-
-static int __parse_system_data(json_object *inputObj, sa_config_s *setupConfig)
+static int __parse_system_data(json_object * inputObj, sa_config_s * setupConfig)
{
int ret = 0;
char *httpProxyHost = NULL;
_D("__parse_system_data input error");
return -1;
}
-
//httpProxyHost
httpProxyHost = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_HTTPPROXYHOST);
if (httpProxyHost != NULL) {
- setupConfig->systemData = (sa_system_s *)malloc(sizeof(sa_system_s));
+ setupConfig->systemData = (sa_system_s *) malloc(sizeof(sa_system_s));
if (setupConfig->systemData != NULL) {
- setupConfig->systemData->proxy = (sa_proxy_s *)malloc(sizeof(sa_proxy_s));
+ setupConfig->systemData->proxy = (sa_proxy_s *) malloc(sizeof(sa_proxy_s));
if (setupConfig->systemData->proxy != NULL) {
- memcpy(setupConfig->systemData->proxy->httpProxyHost, httpProxyHost, MIN(strlen(httpProxyHost), sizeof(setupConfig->systemData->proxy->httpProxyHost)-1));
+ memcpy(setupConfig->systemData->proxy->httpProxyHost, httpProxyHost, MIN(strlen(httpProxyHost), sizeof(setupConfig->systemData->proxy->httpProxyHost) - 1));
free(httpProxyHost);
httpProxyHost = NULL;
return ret;
}
-
-static int __parse_version(json_object *inputObj, sa_config_s *setupConfig)
+static int __parse_version(json_object * inputObj, sa_config_s * setupConfig)
{
char *version = NULL;
version = json_get_string_from_obj(inputObj, SA_CONFIG_VERSION);
if (version != NULL) {
- memcpy(setupConfig->version, version, MIN(strlen(version), sizeof(setupConfig->version)-1));
+ memcpy(setupConfig->version, version, MIN(strlen(version), sizeof(setupConfig->version) - 1));
free(version);
version = NULL;
}
return 0;
}
-static int __parse_config(char *file, sa_config_s *setupConfig)
+static int __parse_config(char *file, sa_config_s * setupConfig)
{
struct json_object *configObj = NULL;
char *jsonData = NULL;
if (configObj != NULL && readLen > 0) {
// parse version
ret = __parse_version(configObj, setupConfig);
- if (ret == 0) {
+ if (ret == 0)
ret = __parse_system_data(configObj, setupConfig);
- }
- if (ret == 0) {
+ if (ret == 0)
ret = __parse_network_data(configObj, setupConfig);
- }
+
} else {
ret = -1;
_D("ConfigObj is not existed");
return ret;
}
-sa_error_e sa_inputfile_get_config_info(sa_config_s *config)
+sa_error_e sa_inputfile_get_config_info(sa_config_s * config)
{
sa_error_e ret = SA_ERROR_NONE;
// check file
- if (access(CONFIG_FILE, 0) != 0) {
+ if (access(CONFIG_FILE, 0) != 0)
return SA_ERROR_NOT_SUPPORTED;
- }
+
// parsing and fill into struct
ret = __parse_config(CONFIG_FILE, config);
if (ret != 0) {
{
sa_file_state_e ret = SA_FILE_STATE_NOT_EXISTED;
- if (access(CONFIG_FILE, F_OK) != -1) {
+ if (access(CONFIG_FILE, F_OK) != -1)
ret = SA_FILE_STATE_EXIST;
- } else {
+ else
ret = SA_FILE_STATE_NOT_EXISTED;
- }
return ret;
}
-static void release_system_resource(sa_system_s *system)
+static void release_system_resource(sa_system_s * system)
{
if (system != NULL) {
if (system->proxy != NULL)
}
}
-static void release_network_resource(sa_network_s *network)
+static void release_network_resource(sa_network_s * network)
{
if (network != NULL) {
if (network->wifi != NULL) {
}
}
-gboolean sa_inputfile_thread(GSource *source, GSourceFunc callbackFuntion, gpointer user_data)
+gboolean sa_inputfile_thread(GSource * source, GSourceFunc callbackFuntion, gpointer user_data)
{
- GMainLoop* loop = user_data;
- GSource* src = NULL;
+ GMainLoop *loop = user_data;
+ GSource *src = NULL;
_D("GSourceFuncs>>>Execution !!!");
#if 0
sa_error_e ret = SA_ERROR_NONE;
- if (__init_event_listener(callback)) {
+ if (__init_event_listener(callback))
ret = SA_ERROR_UNKNOWN;
- }
#else
callbackFuntion(NULL);
#endif
- if(user_data) {
- g_main_loop_quit( (GMainLoop*)user_data );
- }
+ 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;
}
-void sa_inputfile_release_resource(sa_config_s *config)
+void sa_inputfile_release_resource(sa_config_s * config)
{
if (config != NULL) {
}
}
-#define FLAG_FILE_SYSTEM "/etc/setup-adaptor/system_executed"
-#define FLAG_FILE_ETH "/etc/setup-adaptor/ethernet_executed"
-#define FLAG_FILE_WIFI "/etc/setup-adaptor/wifi_executed"
+#define FLAG_FILE_SYSTEM "/etc/setup-adaptor/system_executed"
+#define FLAG_FILE_ETH "/etc/setup-adaptor/ethernet_executed"
+#define FLAG_FILE_WIFI "/etc/setup-adaptor/wifi_executed"
void sa_inputfile_remove(void)
{
- if (remove(CONFIG_FILE) != 0) {
+ if (remove(CONFIG_FILE) != 0)
_E("Can't remove file{%s}! %s", CONFIG_FILE, strerror(errno));
- }
- else {
+ else
_D("file removed successfully..{%s}", CONFIG_FILE);
- }
+
}
void sa_inputfile_clear_completion_flag(void)
{
- if (remove(FLAG_FILE_SYSTEM) == 0) {
+ if (remove(FLAG_FILE_SYSTEM) == 0)
_D("file removed successfully..{%s}", FLAG_FILE_SYSTEM);
- }
- if (remove(FLAG_FILE_ETH) == 0) {
+
+ if (remove(FLAG_FILE_ETH) == 0)
_D("file removed successfully..{%s}", FLAG_FILE_ETH);
- }
- if (remove(FLAG_FILE_WIFI) == 0) {
+
+ if (remove(FLAG_FILE_WIFI) == 0)
_D("file removed successfully..{%s}", FLAG_FILE_WIFI);
- }
+
}
void sa_inputfile_set_completion_flag(sa_file_config_e config_type)
{
int fd;
-
- switch(config_type)
- {
- case SA_FILE_CONFIG_SYSTEM:
- fd = creat(FLAG_FILE_SYSTEM, NULL);
- break;
- case SA_FILE_CONFIG_ETHERNET:
- fd = creat(FLAG_FILE_ETH, NULL);
- break;
- case SA_FILE_CONFIG_WIFI:
- fd = creat(FLAG_FILE_WIFI, NULL);
- break;
- default:
- _E("unknown parameter (%d)", config_type);
- break;
- }
-
- if(fd == -1) {
+
+ switch (config_type) {
+ case SA_FILE_CONFIG_SYSTEM:
+ fd = creat(FLAG_FILE_SYSTEM, NULL);
+ break;
+ case SA_FILE_CONFIG_ETHERNET:
+ fd = creat(FLAG_FILE_ETH, NULL);
+ break;
+ case SA_FILE_CONFIG_WIFI:
+ fd = creat(FLAG_FILE_WIFI, NULL);
+ break;
+ default:
+ _E("unknown parameter (%d)", config_type);
+ break;
+ }
+
+ if (fd == -1)
_E("Can't create file for (%d)! %s", config_type, strerror(errno));
- }
}
// return TRUE if set
{
int ret = 0;
- switch(config_type)
- {
- case SA_FILE_CONFIG_SYSTEM:
- ret = access(FLAG_FILE_SYSTEM, 0);
- break;
- case SA_FILE_CONFIG_ETHERNET:
+ switch (config_type) {
+ case SA_FILE_CONFIG_SYSTEM:
+ ret = access(FLAG_FILE_SYSTEM, 0);
+ break;
+ case SA_FILE_CONFIG_ETHERNET:
+ ret = access(FLAG_FILE_ETH, 0);
+ break;
+ case SA_FILE_CONFIG_WIFI:
+ ret = access(FLAG_FILE_WIFI, 0);
+ break;
+ case SA_FILE_CONFIG_ALL:
+ ret = access(FLAG_FILE_SYSTEM, 0);
+ if (ret == 0)
ret = access(FLAG_FILE_ETH, 0);
- break;
- case SA_FILE_CONFIG_WIFI:
+
+ if (ret == 0)
ret = access(FLAG_FILE_WIFI, 0);
- break;
- case SA_FILE_CONFIG_ALL:
- ret = access(FLAG_FILE_SYSTEM, 0);
- if(ret == 0) {
- ret = access(FLAG_FILE_ETH, 0);
- }
- if(ret == 0) {
- ret = access(FLAG_FILE_WIFI, 0);
- }
- break;
- default:
- _E("unknown parameter (%d)", config_type);
- break;
+
+ break;
+ default:
+ _E("unknown parameter (%d)", config_type);
+ break;
}
- if (ret == 0) {
+ if (ret == 0)
return TRUE;
- } else {
+ else
return FALSE;
- }
}
-
* @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);
+sa_error_e sa_inputfile_get_config_info(sa_config_s * config);
/**
* @fn int 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
+ * @return gboolean FALSE
*/
-gboolean sa_inputfile_thread(GSource *source, GSourceFunc callbackFuntion, gpointer user_data);
+gboolean sa_inputfile_thread(GSource * source, GSourceFunc callbackFuntion, gpointer user_data);
/**
* @fn void sa_inputfile_release_resource
* @param sa_config_s
* @return void
*/
-void sa_inputfile_release_resource(sa_config_s *config);
+void sa_inputfile_release_resource(sa_config_s * config);
/**
* @fn void sa_inputfile_remove
*/
gboolean sa_inputfile_get_completion_flag(sa_file_config_e config_type);
-#endif/* __INPUT_FILE_H__ */
\ No newline at end of file
+#endif /* __INPUT_FILE_H__ */
#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__ */
#define __SA_TYPES_H__
#define SA_CONFIG_VERSION "version"
-#define SA_CONFIG_NETWORKDATA "networkData"
-#define SA_CONFIG_SYSTEMDATA "systemData"
+#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_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_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
*
SA_FILE_STATE_CHANGED, /**< Changed */
} sa_file_state_e;
-
typedef enum {
SA_FILE_CONFIG_SYSTEM = 0, /**< system configuration type */
SA_FILE_CONFIG_ETHERNET, /**< ethernet configuration type */
*/
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
*
*/
typedef struct {
- char ipAddress[255+1];
- char netmask[255+1];
- char defaultGateway[255+1];
- char primaryDnsServer[255+1];
- char secondaryDnsServer[255+1];
+ char ipAddress[255 + 1];
+ char netmask[255 + 1];
+ char defaultGateway[255 + 1];
+ char primaryDnsServer[255 + 1];
+ char secondaryDnsServer[255 + 1];
} sa_network_static_s;
/**
typedef struct {
int enabled;
int dhcpEnabled;
- char ssid[255+1];
- char password[255+1];
+ char ssid[255 + 1];
+ char password[255 + 1];
sa_network_static_s *staticInfo;
} sa_wifi_s;
/**
* @struct sa_proxy_s
- * @brief This struct contains proxy information
+ * @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;
+ char httpProxyHost[255 + 1];
+ int httpProxyPort;
} sa_proxy_s;
/**
sa_eth_s *eth;
} sa_network_s;
-
/**
* @struct sa_system_s
* @brief This struct contains system data information in the config
*
*/
typedef struct {
- char deviceName[255+1];
+ char deviceName[255 + 1];
sa_proxy_s *proxy;
} sa_system_s;
*
*/
typedef struct {
- char version[127+1];
+ char version[127 + 1];
sa_network_s *networkData;
sa_system_s *systemData;
} sa_config_s;
char *password;
} _wifi_data_s;
-
static char *__print_connection_state(sa_network_state_e state)
{
switch (state) {
}
}
-
static const char *__print_wifi_state(connection_wifi_state_e state)
{
switch (state) {
}
}
-
-static void __wifi_exit_loop(_wifi_data_s *wifi_data)
+static void __wifi_exit_loop(_wifi_data_s * wifi_data)
{
_D("__wifi_exit_loop !!!");
- if( wifi_data ) {
- g_main_loop_quit( (GMainLoop*)wifi_data->loop );
- }
+ if (wifi_data)
+ g_main_loop_quit((GMainLoop *) wifi_data->loop);
}
static void __wifi_connected_cb(wifi_manager_error_e result, void *user_data)
{
- _wifi_data_s *wifi_data = (_wifi_data_s*)user_data;
+ _wifi_data_s *wifi_data = (_wifi_data_s *) user_data;
- if (result == WIFI_MANAGER_ERROR_NONE){
+ if (result == WIFI_MANAGER_ERROR_NONE)
_D("__wifi_connected_cb() connected Successfully !!!");
- }
- else {
+ else
_D("__wifi_connected_cb() connection Failed!(%s)", __print_wifi_error(result));
- }
+
__wifi_exit_loop(wifi_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)
{
- _wifi_data_s *wifi_data = (_wifi_data_s*)user_data;
+ _wifi_data_s *wifi_data = (_wifi_data_s *) user_data;
_D("__wifi_connect_ap_cb()");
rv = wifi_manager_ap_get_essid(ap, &ap_name);
if (rv != WIFI_MANAGER_ERROR_NONE) {
- _D("Fail to get AP name [%s]", __print_wifi_error((wifi_manager_error_e)rv));
+ _D("Fail to get AP name [%s]", __print_wifi_error((wifi_manager_error_e) rv));
g_free(ap_name);
return false;
} else {
_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);
__wifi_exit_loop(wifi_data);
}
}
- if (rv == WIFI_MANAGER_ERROR_NONE)
- {
+ 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 {
+ } else {
_D("Success to connection request [%s]", ap_name);
}
}
- }
- else {
+ } else {
_D("Fail to passphrase_required request [%s]", __print_wifi_error(rv));
__wifi_exit_loop(wifi_data);
}
static void __wifi_scan_finished_cb(wifi_manager_error_e result, void *user_data)
{
- _wifi_data_s *wifi_data = (_wifi_data_s*)user_data;
+ _wifi_data_s *wifi_data = (_wifi_data_s *) user_data;
_D("__wifi_scan_finished_cb() result=[%s]", __print_wifi_error(result));
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;
+ _wifi_data_s *wifi_data = (_wifi_data_s *) user_data;
_D("__wifi_state_changed_cb() state=[%d]", state);
_D("__wifi_activate_cb() result=[%s]", __print_wifi_error(result));
}
-static int __wifi_connect_main(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,};
+ _wifi_data_s wifi_data = { 0, };
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) {
return -1;
}
- 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);
-
+ 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 {
+ } else {
_E("Wifi init failed [%s]", __print_wifi_error(rv));
return SA_ERROR_UNKNOWN;
}
- g_main_loop_run (gmain_loop);
+ g_main_loop_run(gmain_loop);
gmain_loop = NULL;
return ret;
}
-
connection_h eth_connect;
-static bool __eth_get_user_selected_profile(connection_profile_h *profile, bool select)
+static bool __eth_get_user_selected_profile(connection_profile_h * profile, bool select)
{
int rv = 0;
int input = 0;
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" );
+ printf("Fail to get profile iterator error\n");
return false;
}
if (!strncmp(profile_name, "eth0", strlen("eth0"))) {
printf("profile > %s\n", profile_name);
- if (profile) {
+ 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)
+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,};
+ 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);
+ rv = connection_profile_set_ip_address(profile, address_family, info->staticInfo->ipAddress);
if (rv != CONNECTION_ERROR_NONE)
return -1;
}
_D("netmask =%s", info->staticInfo->netmask);
if (info->staticInfo->netmask != NULL) {
- rv = connection_profile_set_subnet_mask(profile,
- address_family,
- info->staticInfo->netmask);
+ rv = connection_profile_set_subnet_mask(profile, address_family, info->staticInfo->netmask);
if (rv != CONNECTION_ERROR_NONE)
return -1;
}
if (info->staticInfo->defaultGateway != NULL) {
- rv = connection_profile_set_gateway_address(profile,
- address_family,
- info->staticInfo->defaultGateway);
+ 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 (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 (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);
return 1;
}
-static int __eth_update_ip(sa_eth_s *info)
+static int __eth_update_ip(sa_eth_s * info)
{
int rv = 0;
connection_profile_type_e prof_type;
connection_profile_h profile;
- int address_family = 0; // IPv4
+ int address_family = 0; // IPv4
//printf("\n** Choose a profile to update. **\n");
if (__eth_get_user_selected_profile(&profile, true) == false) {
return -1;
}
- if(connection_profile_set_proxy_type(profile,CONNECTION_PROXY_TYPE_DIRECT) != CONNECTION_ERROR_NONE)
+ 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) {
return 1;
}
-static int __ethernet_connect_main(sa_eth_s *info)
+static int __ethernet_connect_main(sa_eth_s * info)
{
- if (info == NULL) {
+ if (info == NULL)
return -1;
- }
- if(__eth_register_client() == 1) {
+ if (__eth_register_client() == 1) {
__eth_update_ip(info);
__eth_deregister_client();
- }
- else
+ } else
_D("connection error!!!\n");
-
return 0;
}
-
-static int __network_get_wifi_state(connection_h connection, connection_wifi_state_e *wifi_state)
+static int __network_get_wifi_state(connection_h connection, connection_wifi_state_e * wifi_state)
{
int rv = 0;
- if (connection == NULL) {
+ if (connection == NULL)
return -1;
- }
rv = connection_get_wifi_state(connection, wifi_state);
- if (rv != CONNECTION_ERROR_NONE) {
+ if (rv != CONNECTION_ERROR_NONE)
_D("Fail to get WiFi state [%s]", __print_error(rv));
- } else {
+ else
_D("Retval = [%s] WiFi state [%s]", __print_error(rv), __print_wifi_state(*wifi_state));
- }
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;
_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) {
*conn_type = SA_NETWORK_TYPE_WIFI;
// check wifi state
if (!__network_get_wifi_state(connection, &wifi_state)) {
- if (wifi_state == CONNECTION_WIFI_STATE_CONNECTED) {
+ if (wifi_state == CONNECTION_WIFI_STATE_CONNECTED)
*conn_state = SA_NETWORK_STATE_CONNECTED;
- } else {
+ else
*conn_state = SA_NETWORK_STATE_DISCONNECTED;
- }
}
} else if (CONNECTION_TYPE_ETHERNET == net_state) {
*conn_type = SA_NETWORK_TYPE_ETH;
return ret;
}
-
extern void sa_inputfile_flag(void);
-static sa_error_e __network_connect(sa_network_s *info)
+static sa_error_e __network_connect(sa_network_s * info)
{
sa_error_e ret = SA_ERROR_NONE;
int retWifi = 0;
_D("info|wifi|staticInfo|secondaryDnsServer(%s)", info->wifi->staticInfo->secondaryDnsServer);
}
}
-
+
if (info->eth != NULL) {
_D("----------- ethernet info -----------");
_D("info|eth|enabled(%d)", info->eth->enabled);
}
if (info->eth != NULL) {
// decide whether it will be set according to policy
- if ( (info->eth->enabled == TRUE) && !sa_inputfile_get_completion_flag(SA_FILE_CONFIG_ETHERNET) ){
+ if ((info->eth->enabled == TRUE) && !sa_inputfile_get_completion_flag(SA_FILE_CONFIG_ETHERNET)) {
retEth = __ethernet_connect_main(info->eth);
_D("return ethernet [%d]", retEth);
}
sa_inputfile_set_completion_flag(SA_FILE_CONFIG_ETHERNET);
if (info->wifi != NULL) {
- if ( (info->wifi->enabled == TRUE) && !sa_inputfile_get_completion_flag(SA_FILE_CONFIG_WIFI) ) {
+ if ((info->wifi->enabled == TRUE) && !sa_inputfile_get_completion_flag(SA_FILE_CONFIG_WIFI)) {
retWifi = __wifi_connect_main(info->wifi);
_D("return wifi [%d]", retWifi);
} else {
return ret;
}
-sa_error_e sa_setup_network(sa_network_s *network)
+sa_error_e sa_setup_network(sa_network_s * network)
{
sa_error_e ret = SA_ERROR_NONE;
sa_network_type_e conn_type;
ret = __network_connect(network);
return ret;
-}
\ No newline at end of file
+}
/**
* @fn int sa_setup_network(sa_network_s *info)
* @brief This function to set network connection
- @param sa_network_s [in] network info struture
+ @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);
+sa_error_e sa_setup_network(sa_network_s * network);
-
-#endif/* __SETUP_NETWORK_H__ */
+#endif /* __SETUP_NETWORK_H__ */
#include "sa_types.h"
#include "setup_system.h"
-static sa_error_e system_set_proxy(sa_proxy_s *info)
+static sa_error_e system_set_proxy(sa_proxy_s * info)
{
return SA_ERROR_NOT_SUPPORTED;
}
-static sa_error_e 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)
+static int compare_proxy_info(sa_proxy_s * devProxy, sa_proxy_s * newProxy)
{
// comapre proxy
if (devProxy != NULL && newProxy != NULL) {
return 1;
} else {
// Host address is the same, but port is different
- if (devProxy->httpProxyPort != newProxy->httpProxyPort) {
+ if (devProxy->httpProxyPort != newProxy->httpProxyPort)
return 1;
- }
}
}
}
return 0;
}
-
-
-sa_error_e sa_setup_system(sa_system_s *system)
+sa_error_e sa_setup_system(sa_system_s * system)
{
sa_proxy_s *devProxy = NULL;
sa_error_e ret = SA_ERROR_NONE;
_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)) {
}
return ret;
-}
\ No newline at end of file
+}
@param sa_system_s [in] system info
* @return sa_error_e return of function
*/
-sa_error_e sa_setup_system(sa_system_s *system);
+sa_error_e sa_setup_system(sa_system_s * system);
-
-#endif/* __SETUP_SYSTEMDATA_H__ */
+#endif /* __SETUP_SYSTEMDATA_H__ */