int wifi_start_supplicant() { /* Before starting the daemon, make sure its config file exists */ if (ensure_config_file_exists() < 0) { LOGE("Wi-Fi will not be enabled"); return -1; } return control_supplicant(1); }
int wifi_start_supplicant(int p2p_supported) { char supp_status[PROPERTY_VALUE_MAX] = {'\0'}; int count = 200; /* wait at most 20 seconds for completion */ #ifdef HAVE_LIBC_SYSTEM_PROPERTIES const prop_info *pi; unsigned serial = 0, i; #endif if (p2p_supported) { strcpy(supplicant_name, P2P_SUPPLICANT_NAME); strcpy(supplicant_prop_name, P2P_PROP_NAME); /* Ensure p2p config file is created */ if (ensure_config_file_exists(P2P_CONFIG_FILE) < 0) { ALOGE("Failed to create a p2p config file"); return -1; } } else { strcpy(supplicant_name, SUPPLICANT_NAME); strcpy(supplicant_prop_name, SUPP_PROP_NAME); } /* Check whether already running */ if (property_get(supplicant_prop_name, supp_status, NULL) && strcmp(supp_status, "running") == 0) { return 0; } /* Before starting the daemon, make sure its config file exists */ if (ensure_config_file_exists(SUPP_CONFIG_FILE) < 0) { ALOGE("Wi-Fi will not be enabled"); return -1; } if (ensure_entropy_file_exists() < 0) { ALOGE("Wi-Fi entropy file was not created"); } /* Clear out any stale socket files that might be left over. */ wpa_ctrl_cleanup(); /* Reset sockets used for exiting from hung state */ exit_sockets[0] = exit_sockets[1] = -1; #ifdef HAVE_LIBC_SYSTEM_PROPERTIES /* * Get a reference to the status property, so we can distinguish * the case where it goes stopped => running => stopped (i.e., * it start up, but fails right away) from the case in which * it starts in the stopped state and never manages to start * running at all. */ pi = __system_property_find(supplicant_prop_name); if (pi != NULL) { serial = __system_property_serial(pi); } #endif property_get("wifi.interface", primary_iface, WIFI_TEST_INTERFACE); property_set("ctl.start", supplicant_name); sched_yield(); while (count-- > 0) { #ifdef HAVE_LIBC_SYSTEM_PROPERTIES if (pi == NULL) { pi = __system_property_find(supplicant_prop_name); } if (pi != NULL) { /* * property serial updated means that init process is scheduled * after we sched_yield, further property status checking is based on this */ if (__system_property_serial(pi) != serial) { __system_property_read(pi, NULL, supp_status); if (strcmp(supp_status, "running") == 0) { return 0; } else if (strcmp(supp_status, "stopped") == 0) { return -1; } } } #else if (property_get(supplicant_prop_name, supp_status, NULL)) { if (strcmp(supp_status, "running") == 0) return 0; } #endif usleep(100000); } return -1; }
int wifi_start_supplicant_common(const char *config_file) { char daemon_cmd[PROPERTY_VALUE_MAX]; char supp_status[PROPERTY_VALUE_MAX] = {'\0'}; int count = 200; /* wait at most 20 seconds for completion */ #ifdef HAVE_LIBC_SYSTEM_PROPERTIES const prop_info *pi; unsigned serial = 0; #endif /* Check whether already running */ if (property_get(SUPP_PROP_NAME, supp_status, NULL) && strcmp(supp_status, "running") == 0) { return 0; } /* Before starting the daemon, make sure its config file exists */ if (ensure_config_file_exists(config_file) < 0) { LOGE("Wi-Fi will not be enabled"); return -1; } if (ensure_entropy_file_exists() < 0) { LOGE("Wi-Fi entropy file was not created"); } /* Clear out any stale socket files that might be left over. */ wifi_wpa_ctrl_cleanup(); #ifdef HAVE_LIBC_SYSTEM_PROPERTIES /* * Get a reference to the status property, so we can distinguish * the case where it goes stopped => running => stopped (i.e., * it start up, but fails right away) from the case in which * it starts in the stopped state and never manages to start * running at all. */ pi = __system_property_find(SUPP_PROP_NAME); if (pi != NULL) { serial = pi->serial; } #endif property_get("wifi.interface", iface, WIFI_TEST_INTERFACE); snprintf(daemon_cmd, PROPERTY_VALUE_MAX, "%s:-i%s -c%s", SUPPLICANT_NAME, iface, config_file); property_set("ctl.start", daemon_cmd); sched_yield(); while (count-- > 0) { #ifdef HAVE_LIBC_SYSTEM_PROPERTIES if (pi == NULL) { pi = __system_property_find(SUPP_PROP_NAME); } if (pi != NULL) { __system_property_read(pi, NULL, supp_status); if (strcmp(supp_status, "running") == 0) { return 0; } else if (pi->serial != serial && strcmp(supp_status, "stopped") == 0) { return -1; } } #else if (property_get(SUPP_PROP_NAME, supp_status, NULL)) { if (strcmp(supp_status, "running") == 0) return 0; } #endif usleep(100000); } return -1; }
int start_supplicant(const struct _SUPPLICANT_PARA_T * prTar, const char *pcIface) { char daemon_cmd[PROPERTY_VALUE_MAX]; char supp_status[PROPERTY_VALUE_MAX] = {'\0'}; int count = 200; /* wait at most 20 seconds for completion */ #ifdef HAVE_LIBC_SYSTEM_PROPERTIES const prop_info *pi; unsigned serial = 0; #endif /* Check whether already running */ if (property_get(prTar->acSuppPropName, supp_status, NULL) && strcmp(supp_status, "running") == 0) { return 0; } /* Before starting the daemon, make sure its config file exists */ if (ensure_config_file_exists(prTar->acSuppConfigFile, prTar->acSuppConfigTemplate) < 0) { LOGE("[%s] %s will not be enabled", pcIface, prTar->acSuppName); return -1; } /*Set interface UP (ifconfig "iface" up)*/ if(set_iface(pcIface, 1) < 0 ) { /*If interface up failed, skip the following actions*/ return -1; } /* Clear out any stale socket files that might be left over. */ LOGD("[%s] clear out stale sockets with prefix \"%s\" in %s", pcIface, prTar->acSuppCtrlPrefix, CONFIG_CTRL_IFACE_CLIENT_DIR); ctrl_cleanup(prTar->acSuppCtrlPrefix); LOGI("[%s] start %s", pcIface, prTar->acSuppName); #ifdef HAVE_LIBC_SYSTEM_PROPERTIES /* * Get a reference to the status property, so we can distinguish * the case where it goes stopped => running => stopped (i.e., * it start up, but fails right away) from the case in which * it starts in the stopped state and never manages to start * running at all. */ pi = __system_property_find(prTar->acSuppPropName); if (pi != NULL) { serial = pi->serial; } #endif property_get(prTar->acIfPropName, (char *)pcIface, prTar->acIfDefName); snprintf(daemon_cmd, PROPERTY_VALUE_MAX, prTar->acSuppDeamonCmd, prTar->acSuppName, pcIface, prTar->acSuppConfigFile); property_set("ctl.start", daemon_cmd); LOGD("[%s] supplicant start command: \"%s\"", pcIface, daemon_cmd); //property_set("ctl.start", prTar->acSuppName); sched_yield(); while (count-- > 0) { #ifdef HAVE_LIBC_SYSTEM_PROPERTIES if (pi == NULL) { pi = __system_property_find(prTar->acSuppPropName); } if (pi != NULL) { __system_property_read(pi, NULL, supp_status); if (strcmp(supp_status, "running") == 0) { return 0; } else if (pi->serial != serial && strcmp(supp_status, "stopped") == 0) { return -1; } } #else if (property_get(prTar->acSuppPropName, supp_status, NULL)) { if (strcmp(supp_status, "running") == 0) return 0; } #endif usleep(100000); } return -1; }
int wifi_start_supplicant() { char supp_status[PROPERTY_VALUE_MAX] = {'\0'}; int count = 200; /* wait at most 20 seconds for completion */ #ifdef HAVE_LIBC_SYSTEM_PROPERTIES const prop_info *pi; unsigned serial = 0; #endif /* Check whether already running */ if (property_get(SUPP_PROP_NAME, supp_status, NULL) && strcmp(supp_status, "running") == 0) { return 0; } /* Before starting the daemon, make sure its config file exists */ if (ensure_config_file_exists() < 0) { LOGE("Wi-Fi will not be enabled"); return -1; } /* Clear out any stale socket files that might be left over. */ wpa_ctrl_cleanup(); #ifdef HAVE_LIBC_SYSTEM_PROPERTIES /* * Get a reference to the status property, so we can distinguish * the case where it goes stopped => running => stopped (i.e., * it start up, but fails right away) from the case in which * it starts in the stopped state and never manages to start * running at all. */ pi = __system_property_find(SUPP_PROP_NAME); if (pi != NULL) { serial = pi->serial; } #endif /* The ar6k driver needs the interface up in order to scan! */ if (!strncmp(DRIVER_MODULE_NAME, "ar6000", 6)) { ifc_init(); ifc_up("wlan0"); sleep(1); } property_set("ctl.start", SUPPLICANT_NAME); sched_yield(); while (count-- > 0) { #ifdef HAVE_LIBC_SYSTEM_PROPERTIES if (pi == NULL) { pi = __system_property_find(SUPP_PROP_NAME); } if (pi != NULL) { __system_property_read(pi, NULL, supp_status); if (strcmp(supp_status, "running") == 0) { return 0; } else if (pi->serial != serial && strcmp(supp_status, "stopped") == 0) { return -1; } } #else if (property_get(SUPP_PROP_NAME, supp_status, NULL)) { if (strcmp(supp_status, "running") == 0) return 0; } #endif usleep(100000); } return -1; }