diff options
-rw-r--r-- | libwifi_system/include/wifi_system/wifi.h | 4 | ||||
-rw-r--r-- | libwifi_system/wifi.cpp | 67 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WifiMonitor.java | 10 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WifiNative.java | 12 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WifiStateMachine.java | 13 | ||||
-rw-r--r-- | service/jni/com_android_server_wifi_WifiNative.cpp | 12 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java | 10 |
7 files changed, 50 insertions, 78 deletions
diff --git a/libwifi_system/include/wifi_system/wifi.h b/libwifi_system/include/wifi_system/wifi.h index 3e662a196..0cfbf3ee8 100644 --- a/libwifi_system/include/wifi_system/wifi.h +++ b/libwifi_system/include/wifi_system/wifi.h @@ -29,14 +29,14 @@ extern const char kWiFiEntropyFile[]; * * @return 0 on success, < 0 on failure. */ -int wifi_start_supplicant(int p2pSupported); +int wifi_start_supplicant(); /** * Stop supplicant. * * @return 0 on success, < 0 on failure. */ -int wifi_stop_supplicant(int p2pSupported); +int wifi_stop_supplicant(); /** * Open a connection to supplicant diff --git a/libwifi_system/wifi.cpp b/libwifi_system/wifi.cpp index 3b08cf186..4406affc0 100644 --- a/libwifi_system/wifi.cpp +++ b/libwifi_system/wifi.cpp @@ -77,10 +77,8 @@ static char primary_iface[PROPERTY_VALUE_MAX]; #define WIFI_DRIVER_LOADER_DELAY 1000000 const char IFACE_DIR[] = "/data/system/wpa_supplicant"; -const char SUPPLICANT_NAME[] = "wpa_supplicant"; -const char SUPP_PROP_NAME[] = "init.svc.wpa_supplicant"; -const char P2P_SUPPLICANT_NAME[] = "p2p_supplicant"; -const char P2P_PROP_NAME[] = "init.svc.p2p_supplicant"; +const char SUPPLICANT_SERVICE_NAME[] = "wpa_supplicant"; +const char SUPPLICANT_INIT_PROPERTY[] = "init.svc.wpa_supplicant"; const char SUPP_CONFIG_TEMPLATE[] = "/system/etc/wifi/wpa_supplicant.conf"; const char SUPP_CONFIG_FILE[] = "/data/misc/wifi/wpa_supplicant.conf"; const char P2P_CONFIG_FILE[] = "/data/misc/wifi/p2p_supplicant.conf"; @@ -93,11 +91,6 @@ unsigned char dummy_key[21] = {0x02, 0x11, 0xbe, 0x33, 0x43, 0x35, 0x68, 0x47, 0x84, 0x99, 0xa9, 0x2b, 0x1c, 0xd3, 0xee, 0xff, 0xf1, 0xe2, 0xf3, 0xf4, 0xf5}; -/* Is either SUPPLICANT_NAME or P2P_SUPPLICANT_NAME */ -char supplicant_name[PROPERTY_VALUE_MAX]; -/* Is either SUPP_PROP_NAME or P2P_PROP_NAME */ -char supplicant_prop_name[PROPERTY_KEY_MAX]; - void wifi_close_sockets() { if (ctrl_conn != NULL) { wpa_ctrl_close(ctrl_conn); @@ -187,29 +180,14 @@ int ensure_config_file_exists(const char* config_file) { const char kWiFiEntropyFile[] = "/data/misc/wifi/entropy.bin"; -int wifi_start_supplicant(int p2p_supported) { +int wifi_start_supplicant() { char supp_status[PROPERTY_VALUE_MAX] = {'\0'}; int count = 200; /* wait at most 20 seconds for completion */ const prop_info* pi; unsigned serial = 0; - 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) && + if (property_get(SUPPLICANT_INIT_PROPERTY, supp_status, NULL) && strcmp(supp_status, "running") == 0) { return 0; } @@ -220,6 +198,15 @@ int wifi_start_supplicant(int p2p_supported) { return -1; } + /* + * Some devices have another configuration file for the p2p interface. + * However, not all devices have this, and we'll let it slide if it + * is missing. For devices that do expect this file to exist, + * supplicant will refuse to start and emit a good error message. + * No need to check for it here. + */ + (void)ensure_config_file_exists(P2P_CONFIG_FILE); + if (ensure_entropy_file_exists() < 0) { ALOGE("Wi-Fi entropy file was not created"); } @@ -237,18 +224,18 @@ int wifi_start_supplicant(int p2p_supported) { * it starts in the stopped state and never manages to start * running at all. */ - pi = __system_property_find(supplicant_prop_name); + pi = __system_property_find(SUPPLICANT_INIT_PROPERTY); if (pi != NULL) { serial = __system_property_serial(pi); } property_get("wifi.interface", primary_iface, WIFI_TEST_INTERFACE); - property_set("ctl.start", supplicant_name); + property_set("ctl.start", SUPPLICANT_SERVICE_NAME); sched_yield(); while (count-- > 0) { if (pi == NULL) { - pi = __system_property_find(supplicant_prop_name); + pi = __system_property_find(SUPPLICANT_INIT_PROPERTY); } if (pi != NULL) { /* @@ -269,29 +256,21 @@ int wifi_start_supplicant(int p2p_supported) { return -1; } -int wifi_stop_supplicant(int p2p_supported) { +int wifi_stop_supplicant() { char supp_status[PROPERTY_VALUE_MAX] = {'\0'}; int count = 50; /* wait at most 5 seconds for completion */ - if (p2p_supported) { - strcpy(supplicant_name, P2P_SUPPLICANT_NAME); - strcpy(supplicant_prop_name, P2P_PROP_NAME); - } else { - strcpy(supplicant_name, SUPPLICANT_NAME); - strcpy(supplicant_prop_name, SUPP_PROP_NAME); - } - /* Check whether supplicant already stopped */ - if (property_get(supplicant_prop_name, supp_status, NULL) && + if (property_get(SUPPLICANT_INIT_PROPERTY, supp_status, NULL) && strcmp(supp_status, "stopped") == 0) { return 0; } - property_set("ctl.stop", supplicant_name); + property_set("ctl.stop", SUPPLICANT_SERVICE_NAME); sched_yield(); while (count-- > 0) { - if (property_get(supplicant_prop_name, supp_status, NULL)) { + if (property_get(SUPPLICANT_INIT_PROPERTY, supp_status, NULL)) { if (strcmp(supp_status, "stopped") == 0) return 0; } usleep(100000); @@ -306,7 +285,7 @@ int wifi_connect_on_socket_path(const char* path) { char supp_status[PROPERTY_VALUE_MAX] = {'\0'}; /* Make sure supplicant is running */ - if (!property_get(supplicant_prop_name, supp_status, NULL) || + if (!property_get(SUPPLICANT_INIT_PROPERTY, supp_status, NULL) || strcmp(supp_status, "running") != 0) { ALOGE("Supplicant not running, cannot connect"); return -1; @@ -365,7 +344,7 @@ int wifi_send_command(const char* cmd, char* reply, size_t* reply_len) { int wifi_supplicant_connection_active() { char supp_status[PROPERTY_VALUE_MAX] = {'\0'}; - if (property_get(supplicant_prop_name, supp_status, NULL)) { + if (property_get(SUPPLICANT_INIT_PROPERTY, supp_status, NULL)) { if (strcmp(supp_status, "stopped") == 0) return -1; } @@ -503,7 +482,7 @@ void wifi_close_supplicant_connection() { wifi_close_sockets(); while (count-- > 0) { - if (property_get(supplicant_prop_name, supp_status, NULL)) { + if (property_get(SUPPLICANT_INIT_PROPERTY, supp_status, NULL)) { if (strcmp(supp_status, "stopped") == 0) return; } usleep(100000); diff --git a/service/java/com/android/server/wifi/WifiMonitor.java b/service/java/com/android/server/wifi/WifiMonitor.java index 18c67e436..4b2150fb2 100644 --- a/service/java/com/android/server/wifi/WifiMonitor.java +++ b/service/java/com/android/server/wifi/WifiMonitor.java @@ -633,16 +633,12 @@ public class WifiMonitor { mWifiNative.stopSupplicant(); } - public synchronized void killSupplicant(boolean p2pSupported) { + public synchronized void killSupplicant() { String suppState = System.getProperty("init.svc.wpa_supplicant"); if (suppState == null) suppState = "unknown"; - String p2pSuppState = System.getProperty("init.svc.p2p_supplicant"); - if (p2pSuppState == null) p2pSuppState = "unknown"; - Log.e(TAG, "killSupplicant p2p" + p2pSupported - + " init.svc.wpa_supplicant=" + suppState - + " init.svc.p2p_supplicant=" + p2pSuppState); - mWifiNative.killSupplicant(p2pSupported); + Log.e(TAG, "killSupplicant init.svc.wpa_supplicant=" + suppState); + mWifiNative.killSupplicant(); mConnected = false; setMonitoringNone(); } diff --git a/service/java/com/android/server/wifi/WifiNative.java b/service/java/com/android/server/wifi/WifiNative.java index 02b73413c..91a11e821 100644 --- a/service/java/com/android/server/wifi/WifiNative.java +++ b/service/java/com/android/server/wifi/WifiNative.java @@ -176,19 +176,19 @@ public class WifiNative { /* * Supplicant management */ - private native static boolean startSupplicantNative(boolean p2pSupported); - public boolean startSupplicant(boolean p2pSupported) { + private native static boolean startSupplicantNative(); + public boolean startSupplicant() { synchronized (sLock) { - return startSupplicantNative(p2pSupported); + return startSupplicantNative(); } } /* Sends a kill signal to supplicant. To be used when we have lost connection or when the supplicant is hung */ - private native static boolean killSupplicantNative(boolean p2pSupported); - public boolean killSupplicant(boolean p2pSupported) { + private native static boolean killSupplicantNative(); + public boolean killSupplicant() { synchronized (sLock) { - return killSupplicantNative(p2pSupported); + return killSupplicantNative(); } } diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index 791ad81a5..725dbd815 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -3379,7 +3379,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss * or when the driver is hung. Ensure supplicant is stopped here. */ if (killSupplicant) { - mWifiMonitor.killSupplicant(mP2pSupported); + mWifiMonitor.killSupplicant(); } mWifiNative.closeSupplicantConnection(); sendSupplicantConnectionChangedBroadcast(false); @@ -4022,7 +4022,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss * Avoids issues with drivers that do not handle interface down * on a running supplicant properly. */ - mWifiMonitor.killSupplicant(mP2pSupported); + mWifiMonitor.killSupplicant(); mDeathRecipient.unlinkToDeath(); if (mWificond != null) { @@ -4094,7 +4094,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss Log.e(TAG, "Failed to start HAL for client mode"); } - if (!mWifiNative.startSupplicant(mP2pSupported)) { + if (!mWifiNative.startSupplicant()) { loge("Failed to start supplicant!"); setWifiState(WifiManager.WIFI_STATE_UNKNOWN); cleanup(); @@ -4185,7 +4185,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss case WifiMonitor.SUP_DISCONNECTION_EVENT: if (++mSupplicantRestartCount <= SUPPLICANT_RESTART_TRIES) { loge("Failed to setup control channel, restart supplicant"); - mWifiMonitor.killSupplicant(mP2pSupported); + mWifiMonitor.killSupplicant(); transitionTo(mInitialState); sendMessageDelayed(CMD_START_SUPPLICANT, SUPPLICANT_RESTART_INTERVAL_MSECS); } else { @@ -4538,12 +4538,9 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss String suppState = System.getProperty("init.svc.wpa_supplicant"); if (suppState == null) suppState = "unknown"; - String p2pSuppState = System.getProperty("init.svc.p2p_supplicant"); - if (p2pSuppState == null) p2pSuppState = "unknown"; logd("SupplicantStoppingState: stopSupplicant " - + " init.svc.wpa_supplicant=" + suppState - + " init.svc.p2p_supplicant=" + p2pSuppState); + + " init.svc.wpa_supplicant=" + suppState); mWifiMonitor.stopSupplicant(); /* Send ourselves a delayed message to indicate failure after a wait time */ diff --git a/service/jni/com_android_server_wifi_WifiNative.cpp b/service/jni/com_android_server_wifi_WifiNative.cpp index e86f4fc0c..a7534e55a 100644 --- a/service/jni/com_android_server_wifi_WifiNative.cpp +++ b/service/jni/com_android_server_wifi_WifiNative.cpp @@ -115,14 +115,14 @@ static jstring doStringCommand(JNIEnv* env, jstring javaCommand) { return env->NewStringUTF(reply); } -static jboolean android_net_wifi_startSupplicant(JNIEnv* env, jclass, jboolean p2pSupported) +static jboolean android_net_wifi_startSupplicant(JNIEnv* env, jclass) { - return (wifi_system::wifi_start_supplicant(p2pSupported) == 0); + return (wifi_system::wifi_start_supplicant() == 0); } -static jboolean android_net_wifi_killSupplicant(JNIEnv* env, jclass, jboolean p2pSupported) +static jboolean android_net_wifi_killSupplicant(JNIEnv* env, jclass) { - return (wifi_system::wifi_stop_supplicant(p2pSupported) == 0); + return (wifi_system::wifi_stop_supplicant() == 0); } static jboolean android_net_wifi_connectToSupplicant(JNIEnv* env, jclass) @@ -2456,8 +2456,8 @@ static jint android_net_wifi_configure_nd_offload(JNIEnv *env, jclass cls, static JNINativeMethod gWifiMethods[] = { /* name, signature, funcPtr */ - { "startSupplicantNative", "(Z)Z", (void *)android_net_wifi_startSupplicant }, - { "killSupplicantNative", "(Z)Z", (void *)android_net_wifi_killSupplicant }, + { "startSupplicantNative", "()Z", (void *)android_net_wifi_startSupplicant }, + { "killSupplicantNative", "()Z", (void *)android_net_wifi_killSupplicant }, { "connectToSupplicantNative", "()Z", (void *)android_net_wifi_connectToSupplicant }, { "closeSupplicantConnectionNative", "()V", (void *)android_net_wifi_closeSupplicantConnection }, diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index cc8adc6a2..0e2581d24 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -441,7 +441,7 @@ public class WifiStateMachineTest { @Test public void loadComponents() throws Exception { when(mWifiNative.startHal()).thenReturn(true); - when(mWifiNative.startSupplicant(anyBoolean())).thenReturn(true); + when(mWifiNative.startSupplicant()).thenReturn(true); mWsm.setSupplicantRunning(true); mLooper.dispatchAll(); @@ -474,7 +474,7 @@ public class WifiStateMachineTest { @Test public void shouldRequireSupplicantStartupToLeaveInitialState() throws Exception { - when(mWifiNative.startSupplicant(true)).thenReturn(false); + when(mWifiNative.startSupplicant()).thenReturn(false); mWsm.setSupplicantRunning(true); mLooper.dispatchAll(); assertEquals("InitialState", getCurrentState().getName()); @@ -507,7 +507,7 @@ public class WifiStateMachineTest { @Test public void loadComponentsFailure() throws Exception { when(mWifiNative.startHal()).thenReturn(false); - when(mWifiNative.startSupplicant(anyBoolean())).thenReturn(false); + when(mWifiNative.startSupplicant()).thenReturn(false); mWsm.setSupplicantRunning(true); mLooper.dispatchAll(); @@ -534,7 +534,7 @@ public class WifiStateMachineTest { @Test public void shouldStartSupplicantWhenConnectModeRequested() throws Exception { when(mWifiNative.startHal()).thenReturn(true); - when(mWifiNative.startSupplicant(anyBoolean())).thenReturn(true); + when(mWifiNative.startSupplicant()).thenReturn(true); // The first time we start out in InitialState, we sit around here. mLooper.dispatchAll(); @@ -554,7 +554,7 @@ public class WifiStateMachineTest { @Test public void checkStartInCorrectStateAfterChangingInitialState() throws Exception { when(mWifiNative.startHal()).thenReturn(true); - when(mWifiNative.startSupplicant(anyBoolean())).thenReturn(true); + when(mWifiNative.startSupplicant()).thenReturn(true); // Check initial state mLooper.dispatchAll(); |