#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
+#include <ctype.h>
#include <vconf-keys.h>
#include <tzplatform_config.h>
#include <system_info.h>
static struct netconfig_headed_plugin_t *headed_plugin;
static struct netconfig_telephony_plugin_t *telephony_plugin;
+static bool is_feature_checked[NETCONFIG_SUPPORTED_FEATURE_MAX] = {0, };
+static bool feature_supported[NETCONFIG_SUPPORTED_FEATURE_MAX] = {0, };
+
+gboolean netconfig_check_passphrase(const gchar *service, const char *passphrase)
+{
+ gsize length;
+
+ if (!passphrase)
+ return FALSE;
+
+ length = strlen(passphrase);
+
+ if (g_str_has_suffix(service, "psk") == TRUE) {
+ if (length == 64) {
+ for (int i = 0; i < 64; i++)
+ if (!isxdigit((unsigned char)passphrase[i]))
+ return FALSE;
+ } else if (length < 8 || length > 63)
+ return FALSE;
+ } else if (g_str_has_suffix(service, "wep") == TRUE) {
+ if (length == 10 || length == 26) {
+ for (int i = 0; i < length; i++)
+ if (!isxdigit((unsigned char)passphrase[i]))
+ return FALSE;
+ } else if (length != 5 && length != 13)
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
GKeyFile *netconfig_keyfile_load(const char *pathname)
{
GKeyFile *keyfile = NULL;
gboolean netconfig_is_wifi_direct_on(void)
{
-#if defined TIZEN_P2P_ENABLE
+ if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT))
+ return FALSE;
+
int wifi_direct_state = 0;
netconfig_vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wifi_direct_state);
DBG("Wi-Fi direct mode %d", wifi_direct_state);
return (wifi_direct_state != 0) ? TRUE : FALSE;
-#else
- return FALSE;
-#endif
}
gboolean netconfig_is_wifi_tethering_on(void)
{
-#if defined TIZEN_TETHERING_ENABLE
- int wifi_tethering_state = 0;
-
- netconfig_vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &wifi_tethering_state);
- DBG("Wi-Ti tethering mode %d", wifi_tethering_state);
- if ((wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI)
- || (wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP)) {
- DBG("Mobile AP is on");
- return TRUE;
+ if (netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_TETHERING)) {
+ int wifi_tethering_state = 0;
+
+ netconfig_vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &wifi_tethering_state);
+ DBG("Wi-Ti tethering mode %d", wifi_tethering_state);
+ if ((wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI)
+ || (wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP)) {
+ DBG("Mobile AP is on");
+ return TRUE;
+ }
}
-#endif
+
DBG("Mobile AP is off");
return FALSE;
}
return -EIO;
}
+static void no_wait_signal_handler()
+{
+ pid_t child_pid = 0;
+ int state = 0;
+
+ child_pid = waitpid(-1, &state, WNOHANG);
+
+ DBG("child_id(%d) state(%d)", child_pid, WEXITSTATUS(state));
+}
+
+int netconfig_execute_file_no_wait(const char *file_path, char *const args[])
+{
+ pid_t pid = 0;
+ int rv = 0;
+ errno = 0;
+ register unsigned int index = 0;
+
+ struct sigaction act;
+ int state = 0;
+ char error_buf[MAX_SIZE_ERROR_BUFFER] = {0, };
+
+ act.sa_handler = no_wait_signal_handler;
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = 0;
+
+ state = sigaction(SIGCHLD, &act, 0);
+ if (state != 0) {
+ DBG("sigaction() : %d");
+ return -1;
+ }
+
+ while (args[index] != NULL) {
+ DBG("%s", args[index]);
+ index++;
+ }
+
+ if (!(pid = fork())) {
+ DBG("pid(%d), ppid (%d)", getpid(), getppid());
+ DBG("Inside child, exec (%s) command", file_path);
+
+ errno = 0;
+ if (execvp(file_path, args) == -1) {
+ ERR("Fail to execute command (%s)",
+ strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
+ return -1;
+ }
+ } else if (pid > 0) {
+ ERR("Successfully launched child process");
+ return rv;
+ }
+
+ DBG("failed to fork(%s)",
+ strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER));
+ return -EIO;
+}
+
int __netconfig_get_interface_index(const char *interface_name)
{
struct ifreq ifr;
close(sock);
if (result < 0) {
+ strerror_r(errno, error_buf, MAX_SIZE_ERROR_BUFFER);
DBG("Failed to get ifr index: %s", error_buf);
return -1;
}
gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context)
{
-#if defined TIZEN_P2P_ENABLE
+ if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT)) {
+ wifi_complete_launch_direct(wifi, context);
+ return TRUE;
+ }
+
int ret = 0;
DBG("Launch Wi-Fi direct daemon");
if (ret < 0) {
ERR("Failed to launch Wi-Fi direct daemon");
netconfig_error_wifi_direct_failed(context);
- return FALSE;
+ return TRUE;
}
wifi_complete_launch_direct(wifi, context);
return TRUE;
-#else
- wifi_complete_launch_direct(wifi, context);
- return FALSE;
-#endif
}
int execute_mdnsd_script(char* op)
if (execute_mdnsd_script("start") < 0) {
ERR("Failed to launch mdnsresponder daemon");
netconfig_error_invalid_parameter(context);
- return FALSE;
+ return TRUE;
}
mdnsd_ref_count++;
return netconfig_plugin_telephony_enabled;
}
+bool netconfig_check_feature_supported(netconfig_supported_feature_e feature)
+{
+ const char *key = NULL;
+
+ if (!is_feature_checked[feature]) {
+ switch (feature) {
+ case NETCONFIG_SUPPORTED_FEATURE_ETHERNET:
+ key = ETHERNET_FEATURE;
+ break;
+ case NETCONFIG_SUPPORTED_FEATURE_TETHERING:
+ key = TETHERING_FEATURE;
+ break;
+ case NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT:
+ key = WIFI_DIRECT_FEATURE;
+ break;
+ case NETCONFIG_SUPPORTED_FEATURE_WIFI_SOFTAP:
+ key = WIFI_SOFTAP_FEATURE;
+ break;
+ default:
+ ERR("Uknown feature");
+ return false;
+ }
+
+ if (system_info_get_platform_bool(key, &feature_supported[feature]) < 0) {
+ ERR("Get feature is failed");
+ return false;
+ }
+ is_feature_checked[feature] = true;
+ }
+ return feature_supported[feature];
+}