int SoftapController::startSoftap() { pid_t pid = 1; if (mPid) { ALOGE("SoftAP is already running"); return ResponseCode::SoftapStatusResult; } if ((pid = fork()) < 0) { ALOGE("fork failed (%s)", strerror(errno)); return ResponseCode::ServiceStartFailed; } if (!pid) { ensure_entropy_file_exists(); if (execl(HOSTAPD_BIN_FILE, HOSTAPD_BIN_FILE, "-e", WIFI_ENTROPY_FILE, HOSTAPD_CONF_FILE, (char *) NULL)) { ALOGE("execl failed (%s)", strerror(errno)); } ALOGE("SoftAP failed to start"); return ResponseCode::ServiceStartFailed; } else { mPid = pid; ALOGD("SoftAP started successfully"); usleep(AP_BSS_START_DELAY); } return ResponseCode::SoftapStatusResult; }
int SoftapController::startSoftap() { pid_t pid = 1; int ret = 0; if (mPid) { ALOGE("SoftAP is already running"); return ResponseCode::SoftapStatusResult; } if (mSock < 0) { ALOGE("Softap startap - failed to open socket"); return ResponseCode::OperationFailed; } #ifdef HAVE_HOSTAPD if ((pid = fork()) < 0) { ALOGE("fork failed (%s)", strerror(errno)); return ResponseCode::ServiceStartFailed; } #endif if (!pid) { #ifdef HAVE_HOSTAPD #ifndef HOSTAPD_NO_ENTROPY ensure_entropy_file_exists(); #endif if (execl(HOSTAPD_BIN_FILE, HOSTAPD_BIN_FILE, #ifndef HOSTAPD_NO_ENTROPY "-e", WIFI_ENTROPY_FILE, #endif HOSTAPD_CONF_FILE, (char *) NULL)) { ALOGE("execl failed (%s)", strerror(errno)); } #endif ALOGE("SoftAP failed to start"); return ResponseCode::ServiceStartFailed; } else { *mBuf = 0; ret = setCommand(mIface, "AP_BSS_START"); if (ret) { ALOGE("Softap startap - failed: %d", ret); return ResponseCode::ServiceStartFailed; } else { mPid = pid; ALOGD("SoftAP started successfully"); usleep(AP_BSS_START_DELAY); } } return ResponseCode::SoftapStatusResult; }
int SoftapController::startSoftap() { pid_t pid = 1; int ret = 0; if (mPid) { LOGE("Softap already started"); return 0; } if (mSock < 0) { LOGE("Softap startap - failed to open socket"); return -1; } #ifdef HAVE_HOSTAPD if ((pid = fork()) < 0) { LOGE("fork failed (%s)", strerror(errno)); return -1; } #endif if (!pid) { #ifdef HAVE_HOSTAPD ensure_entropy_file_exists(); if (execl("/system/bin/hostapd", "/system/bin/hostapd", "-e", WIFI_ENTROPY_FILE, HOSTAPD_CONF_FILE, (char *) NULL)) { LOGE("execl failed (%s)", strerror(errno)); } #endif LOGE("Should never get here!"); return -1; } else { *mBuf = 0; ret = setCommand(mIface, "AP_BSS_START"); if (ret) { LOGE("Softap startap - failed: %d", ret); } else { mPid = pid; LOGD("Softap startap - Ok"); usleep(AP_BSS_START_DELAY); } } return ret; }
int SoftapController::startSoftap() { pid_t pid = 1; char driver_vendor[PROPERTY_VALUE_MAX] = {'\0'}; if (mPid) { ALOGE("SoftAP is already running"); return ResponseCode::SoftapStatusResult; } if ((pid = fork()) < 0) { ALOGE("fork failed (%s)", strerror(errno)); return ResponseCode::ServiceStartFailed; } if (!pid) { ensure_entropy_file_exists(); if ((property_get(DRIVER_VENDOR_NAME, driver_vendor, NULL) && (strcmp(driver_vendor, "realtek") == 0))? (execl(HOSTAPD_BIN_FILE_RTL, HOSTAPD_BIN_FILE, "-e", WIFI_ENTROPY_FILE, HOSTAPD_CONF_FILE, (char *) NULL)): (execl(HOSTAPD_BIN_FILE, HOSTAPD_BIN_FILE, "-e", WIFI_ENTROPY_FILE, HOSTAPD_CONF_FILE, (char *) NULL) )) { ALOGE("execl failed (%s)", strerror(errno)); } ALOGE("SoftAP failed to start"); return ResponseCode::ServiceStartFailed; } else { mPid = pid; ALOGD("SoftAP started successfully"); usleep(AP_BSS_START_DELAY); } return ResponseCode::SoftapStatusResult; }
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; }