summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/HostapdHal.java55
-rw-r--r--tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java144
2 files changed, 183 insertions, 16 deletions
diff --git a/service/java/com/android/server/wifi/HostapdHal.java b/service/java/com/android/server/wifi/HostapdHal.java
index c246f0f10..2f461667e 100644
--- a/service/java/com/android/server/wifi/HostapdHal.java
+++ b/service/java/com/android/server/wifi/HostapdHal.java
@@ -434,22 +434,15 @@ public class HostapdHal {
band = config.getBand();
}
- IHostapd.NetworkParams nwParams = new IHostapd.NetworkParams();
- // TODO(b/67745880) Note that config.SSID is intended to be either a
- // hex string or "double quoted".
- // However, it seems that whatever is handing us these configurations does not obey
- // this convention.
- nwParams.ssid.addAll(NativeUtil.stringToByteArrayList(config.getSsid()));
- nwParams.isHidden = config.isHiddenSsid();
- nwParams.encryptionType = getEncryptionType(config);
- nwParams.pskPassphrase = (config.getPassphrase() != null)
- ? config.getPassphrase() : "";
+ android.hardware.wifi.hostapd.V1_2.IHostapd.NetworkParams nwParamsV1_2 =
+ prepareNetworkParams(config);
+ if (nwParamsV1_2 == null) return false;
if (!checkHostapdAndLogFailure(methodStr)) return false;
try {
HostapdStatus status;
if (!isV1_1() && !isV1_2()) {
ifaceParams.channelParams.band = getHalBand(band);
- status = mIHostapd.addAccessPoint(ifaceParams, nwParams);
+ status = mIHostapd.addAccessPoint(ifaceParams, nwParamsV1_2.V1_0);
if (!checkStatusAndLogFailure(status, methodStr)) {
return false;
}
@@ -477,7 +470,7 @@ public class HostapdHal {
getHostapdMockableV1_1();
if (iHostapdV1_1 == null) return false;
- status = iHostapdV1_1.addAccessPoint_1_1(ifaceParams1_1, nwParams);
+ status = iHostapdV1_1.addAccessPoint_1_1(ifaceParams1_1, nwParamsV1_2.V1_0);
if (!checkStatusAndLogFailure(status, methodStr)) {
return false;
}
@@ -530,7 +523,7 @@ public class HostapdHal {
android.hardware.wifi.hostapd.V1_2.IHostapd iHostapdV1_2 =
getHostapdMockableV1_2();
if (iHostapdV1_2 == null) return false;
- status12 = iHostapdV1_2.addAccessPoint_1_2(ifaceParams1_2, nwParams);
+ status12 = iHostapdV1_2.addAccessPoint_1_2(ifaceParams1_2, nwParamsV1_2);
if (!checkStatusAndLogFailure12(status12, methodStr)) {
return false;
}
@@ -784,6 +777,34 @@ public class HostapdHal {
}
}
+ private android.hardware.wifi.hostapd.V1_2.IHostapd.NetworkParams
+ prepareNetworkParams(SoftApConfiguration config) {
+ android.hardware.wifi.hostapd.V1_2.IHostapd.NetworkParams nwParamsV1_2 =
+ new android.hardware.wifi.hostapd.V1_2.IHostapd.NetworkParams();
+ nwParamsV1_2.V1_0.ssid.addAll(NativeUtil.stringToByteArrayList(config.getSsid()));
+ nwParamsV1_2.V1_0.isHidden = config.isHiddenSsid();
+ int encryptionType = getEncryptionType(config);
+ nwParamsV1_2.encryptionType = encryptionType;
+ nwParamsV1_2.passphrase = (config.getPassphrase() != null)
+ ? config.getPassphrase() : "";
+ if (encryptionType
+ == android.hardware.wifi.hostapd.V1_2.IHostapd.EncryptionType.WPA3_SAE
+ || encryptionType == android.hardware.wifi.hostapd.V1_2.IHostapd
+ .EncryptionType.WPA3_SAE_TRANSITION) {
+ if (!isV1_2()) {
+ // It should not happen since we should reject configuration in SoftApManager
+ Log.e(TAG, "Unsupported Configuration found: " + config);
+ return null;
+ }
+ } else {
+ // Fill old parameter for old hidl.
+ nwParamsV1_2.V1_0.encryptionType = encryptionType;
+ nwParamsV1_2.V1_0.pskPassphrase = (config.getPassphrase() != null)
+ ? config.getPassphrase() : "";
+ }
+ return nwParamsV1_2;
+ }
+
private static int getEncryptionType(SoftApConfiguration localConfig) {
int encryptionType;
switch (localConfig.getSecurityType()) {
@@ -793,6 +814,14 @@ public class HostapdHal {
case SoftApConfiguration.SECURITY_TYPE_WPA2_PSK:
encryptionType = IHostapd.EncryptionType.WPA2;
break;
+ case SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION:
+ encryptionType = android.hardware.wifi.hostapd.V1_2
+ .IHostapd.EncryptionType.WPA3_SAE_TRANSITION;
+ break;
+ case SoftApConfiguration.SECURITY_TYPE_WPA3_SAE:
+ encryptionType = android.hardware.wifi.hostapd.V1_2
+ .IHostapd.EncryptionType.WPA3_SAE;
+ break;
default:
// We really shouldn't default to None, but this was how NetworkManagementService
// used to do this.
diff --git a/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java b/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java
index 14f40fd5a..ad7b14831 100644
--- a/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java
@@ -89,8 +89,14 @@ public class HostapdHalTest extends WifiBaseTest {
private ArgumentCaptor<android.hardware.wifi.hostapd.V1_1.IHostapd.IfaceParams>
mIfaceParamsCaptorV1_1 =
ArgumentCaptor.forClass(android.hardware.wifi.hostapd.V1_1.IHostapd.IfaceParams.class);
+ private ArgumentCaptor<android.hardware.wifi.hostapd.V1_2.IHostapd.IfaceParams>
+ mIfaceParamsCaptorV12 =
+ ArgumentCaptor.forClass(android.hardware.wifi.hostapd.V1_2.IHostapd.IfaceParams.class);
private ArgumentCaptor<IHostapd.NetworkParams> mNetworkParamsCaptor =
ArgumentCaptor.forClass(IHostapd.NetworkParams.class);
+ private ArgumentCaptor<android.hardware.wifi.hostapd.V1_2.IHostapd.NetworkParams>
+ mNetworkParamsV12Captor = ArgumentCaptor.forClass(
+ android.hardware.wifi.hostapd.V1_2.IHostapd.NetworkParams.class);
private ArgumentCaptor<Long> mDeathRecipientCookieCaptor = ArgumentCaptor.forClass(Long.class);
private InOrder mInOrder;
@@ -754,13 +760,15 @@ public class HostapdHalTest extends WifiBaseTest {
boolean causeCallbackFailure) throws Exception {
boolean shouldSucceed = !causeCallbackFailure;
mInOrder = inOrder(mServiceManagerMock, mIHostapdMock);
+ when(mIHostapdMockV12.setDebugParams(anyInt()))
+ .thenReturn(mStatusSuccess12);
if (causeCallbackFailure) {
doAnswer(new MockAnswerUtil.AnswerWithArguments() {
public HostapdStatus answer(IHostapdCallback cb)
throws RemoteException {
return mStatusFailure;
}
- }).when(mIHostapdMockV12).registerCallback(any(IHostapdCallback.class));
+ }).when(mIHostapdMockV11).registerCallback(any(IHostapdCallback.class));
} else {
doAnswer(new MockAnswerUtil.AnswerWithArguments() {
public HostapdStatus answer(IHostapdCallback cb)
@@ -768,7 +776,7 @@ public class HostapdHalTest extends WifiBaseTest {
mIHostapdCallback = cb;
return mStatusSuccess;
}
- }).when(mIHostapdMockV12).registerCallback(any(IHostapdCallback.class));
+ }).when(mIHostapdMockV11).registerCallback(any(IHostapdCallback.class));
}
// Initialize HostapdHal, should call serviceManager.registerForNotifications
assertTrue(mHostapdHal.initialize());
@@ -781,7 +789,7 @@ public class HostapdHalTest extends WifiBaseTest {
mServiceNotificationCaptor.getValue().onRegistration(IHostapd.kInterfaceName, "", true);
assertEquals(shouldSucceed, mHostapdHal.isInitializationComplete());
mInOrder.verify(mIHostapdMock).linkToDeath(mHostapdDeathCaptor.capture(), anyLong());
- verify(mIHostapdMockV12).registerCallback(any(IHostapdCallback.class));
+ verify(mIHostapdMockV11).registerCallback(any(IHostapdCallback.class));
}
private HostapdStatus createHostapdStatus(int code) {
@@ -880,5 +888,135 @@ public class HostapdHalTest extends WifiBaseTest {
.setDebugParams(eq(DebugLevel.INFO));
}
+ /*
+ * Sunny day scenario for V1.2 HostapdHal initialization
+ * Asserts successful initialization
+ */
+ @Test
+ public void testInitialize_successV1_2() throws Exception {
+ when(mServiceManagerMock.getTransport(anyString(), anyString()))
+ .thenReturn(IServiceManager.Transport.HWBINDER);
+ mIHostapdMockV11 = mock(android.hardware.wifi.hostapd.V1_1.IHostapd.class);
+ mIHostapdMockV12 = mock(android.hardware.wifi.hostapd.V1_2.IHostapd.class);
+ executeAndValidateInitializationSequenceV1_2(false);
+ }
+
+ /**
+ * Verifies the successful addition of access point with SAE.
+ */
+ @Test
+ public void testAddAccessPointSuccess_SAE_WithoutACS() throws Exception {
+ when(mServiceManagerMock.getTransport(anyString(), anyString()))
+ .thenReturn(IServiceManager.Transport.HWBINDER);
+ mIHostapdMockV11 = mock(android.hardware.wifi.hostapd.V1_1.IHostapd.class);
+ mIHostapdMockV12 = mock(android.hardware.wifi.hostapd.V1_2.IHostapd.class);
+ // Disable ACS in the config.
+ mResources.setBoolean(R.bool.config_wifi_softap_acs_supported, false);
+ mHostapdHal = new HostapdHalSpy();
+
+ executeAndValidateInitializationSequenceV1_2(false);
+
+ Builder configurationBuilder = new SoftApConfiguration.Builder();
+ configurationBuilder.setSsid(NETWORK_SSID);
+ configurationBuilder.setHiddenSsid(false);
+ configurationBuilder.setPassphrase(NETWORK_PSK,
+ SoftApConfiguration.SECURITY_TYPE_WPA3_SAE);
+ configurationBuilder.setBand(SoftApConfiguration.BAND_ANY);
+
+ when(mIHostapdMockV12.addAccessPoint_1_2(
+ mIfaceParamsCaptorV12.capture(), mNetworkParamsV12Captor.capture()))
+ .thenReturn(mStatusSuccess12);
+
+
+ assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME,
+ configurationBuilder.build(),
+ () -> mSoftApListener.onFailure()));
+ verify(mIHostapdMockV12).addAccessPoint_1_2(any(), any());
+
+ assertEquals(IFACE_NAME, mIfaceParamsCaptorV12.getValue().V1_1.V1_0.ifaceName);
+ assertTrue(mIfaceParamsCaptorV12.getValue().V1_1.V1_0.hwModeParams.enable80211N);
+ assertFalse(mIfaceParamsCaptorV12.getValue().V1_1.V1_0.hwModeParams.enable80211AC);
+ assertFalse(mIfaceParamsCaptorV12.getValue().V1_1.V1_0.channelParams.enableAcs);
+
+ assertEquals(NativeUtil.stringToByteArrayList(NETWORK_SSID),
+ mNetworkParamsV12Captor.getValue().V1_0.ssid);
+ assertFalse(mNetworkParamsV12Captor.getValue().V1_0.isHidden);
+ assertEquals(android.hardware.wifi.hostapd.V1_2.IHostapd.EncryptionType.WPA3_SAE,
+ mNetworkParamsV12Captor.getValue().encryptionType);
+ assertEquals(NETWORK_PSK, mNetworkParamsV12Captor.getValue().passphrase);
+ assertEquals("", mNetworkParamsV12Captor.getValue().V1_0.pskPassphrase);
+ }
+
+ /**
+ * Verifies the successful addition of access point with SAE Transition.
+ */
+ @Test
+ public void testAddAccessPointSuccess_SAE_Transition_WithoutACS() throws Exception {
+ when(mServiceManagerMock.getTransport(anyString(), anyString()))
+ .thenReturn(IServiceManager.Transport.HWBINDER);
+ mIHostapdMockV11 = mock(android.hardware.wifi.hostapd.V1_1.IHostapd.class);
+ mIHostapdMockV12 = mock(android.hardware.wifi.hostapd.V1_2.IHostapd.class);
+ // Disable ACS in the config.
+ mResources.setBoolean(R.bool.config_wifi_softap_acs_supported, false);
+ mHostapdHal = new HostapdHalSpy();
+
+ executeAndValidateInitializationSequenceV1_2(false);
+
+ Builder configurationBuilder = new SoftApConfiguration.Builder();
+ configurationBuilder.setSsid(NETWORK_SSID);
+ configurationBuilder.setHiddenSsid(false);
+ configurationBuilder.setPassphrase(NETWORK_PSK,
+ SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION);
+ configurationBuilder.setBand(SoftApConfiguration.BAND_ANY);
+
+ when(mIHostapdMockV12.addAccessPoint_1_2(
+ mIfaceParamsCaptorV12.capture(), mNetworkParamsV12Captor.capture()))
+ .thenReturn(mStatusSuccess12);
+
+
+ assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME,
+ configurationBuilder.build(),
+ () -> mSoftApListener.onFailure()));
+ verify(mIHostapdMockV12).addAccessPoint_1_2(any(), any());
+
+ assertEquals(IFACE_NAME, mIfaceParamsCaptorV12.getValue().V1_1.V1_0.ifaceName);
+ assertTrue(mIfaceParamsCaptorV12.getValue().V1_1.V1_0.hwModeParams.enable80211N);
+ assertFalse(mIfaceParamsCaptorV12.getValue().V1_1.V1_0.hwModeParams.enable80211AC);
+ assertFalse(mIfaceParamsCaptorV12.getValue().V1_1.V1_0.channelParams.enableAcs);
+
+ assertEquals(NativeUtil.stringToByteArrayList(NETWORK_SSID),
+ mNetworkParamsV12Captor.getValue().V1_0.ssid);
+ assertFalse(mNetworkParamsV12Captor.getValue().V1_0.isHidden);
+ assertEquals(android.hardware.wifi.hostapd.V1_2.IHostapd.EncryptionType.WPA3_SAE_TRANSITION,
+ mNetworkParamsV12Captor.getValue().encryptionType);
+ assertEquals(NETWORK_PSK, mNetworkParamsV12Captor.getValue().passphrase);
+ assertEquals("", mNetworkParamsV12Captor.getValue().V1_0.pskPassphrase);
+ }
+
+ /**
+ * Verifies the failure handling addition of access point with SAE Transition in old hal.
+ */
+ @Test
+ public void testAddAccessPointFailure_SAEWithOldHal() throws Exception {
+ when(mServiceManagerMock.getTransport(anyString(), anyString()))
+ .thenReturn(IServiceManager.Transport.HWBINDER);
+ mIHostapdMockV11 = mock(android.hardware.wifi.hostapd.V1_1.IHostapd.class);
+ // Disable ACS in the config.
+ mResources.setBoolean(R.bool.config_wifi_softap_acs_supported, false);
+ mHostapdHal = new HostapdHalSpy();
+
+ executeAndValidateInitializationSequenceV1_1(false);
+
+ Builder configurationBuilder = new SoftApConfiguration.Builder();
+ configurationBuilder.setSsid(NETWORK_SSID);
+ configurationBuilder.setHiddenSsid(false);
+ configurationBuilder.setPassphrase(NETWORK_PSK,
+ SoftApConfiguration.SECURITY_TYPE_WPA3_SAE);
+ configurationBuilder.setBand(SoftApConfiguration.BAND_ANY);
+
+ assertFalse(mHostapdHal.addAccessPoint(IFACE_NAME,
+ configurationBuilder.build(),
+ () -> mSoftApListener.onFailure()));
+ }
}