summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceHal.java68
-rw-r--r--tests/wifitests/src/com/android/server/wifi/p2p/SupplicantP2pIfaceHalTest.java43
2 files changed, 85 insertions, 26 deletions
diff --git a/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceHal.java b/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceHal.java
index fe91b27d4..f944e6cba 100644
--- a/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceHal.java
+++ b/service/java/com/android/server/wifi/p2p/SupplicantP2pIfaceHal.java
@@ -62,6 +62,7 @@ public class SupplicantP2pIfaceHal {
private static final String TAG = "SupplicantP2pIfaceHal";
private static final int RESULT_NOT_VALID = -1;
private static final int DEFAULT_GROUP_OWNER_INTENT = 6;
+ private static final int DEFAULT_OPERATING_CLASS = 81;
/**
* Regex pattern for extracting the wps device type bytes.
* Matches a strings like the following: "<categ>-<OUI>-<subcateg>";
@@ -1148,39 +1149,60 @@ public class SupplicantP2pIfaceHal {
/**
- * Set P2P Listen channel.
+ * Set P2P Listen channel and operating chanel.
*
- * When specifying a social channel on the 2.4 GHz band (1/6/11) there is no
- * need to specify the operating class since it defaults to 81. When
- * specifying a social channel on the 60 GHz band (2), specify the 60 GHz
- * operating class (180).
- *
- * @param channel Wifi channel. eg, 1, 6, 11.
- * @param operatingClass Operating Class indicates the channel set of the AP
- * indicated by this BSSID
+ * @param listenChannel Wifi channel. eg, 1, 6, 11.
+ * @param operatingChannel Wifi channel. eg, 1, 6, 11.
*
* @return true, if operation was successful.
*/
- public boolean setListenChannel(int channel, int operatingClass) {
+ public boolean setListenChannel(int listenChannel, int operatingChannel) {
synchronized (mLock) {
if (!checkSupplicantP2pIfaceAndLogFailure("setListenChannel")) return false;
- // Verify that the integers are not negative. Leave actual parameter validation to
- // supplicant.
- if (channel < 0 || operatingClass < 0) {
- Log.e(TAG, "Invalid values supplied to setListenChannel: " + channel + ", "
- + operatingClass);
+
+ if (listenChannel >= 1 && listenChannel <= 11) {
+ SupplicantResult<Void> result = new SupplicantResult(
+ "setListenChannel(" + listenChannel + ", " + DEFAULT_OPERATING_CLASS + ")");
+ try {
+ result.setResult(mISupplicantP2pIface.setListenChannel(
+ listenChannel, DEFAULT_OPERATING_CLASS));
+ } catch (RemoteException e) {
+ Log.e(TAG, "ISupplicantP2pIface exception: " + e);
+ supplicantServiceDiedHandler();
+ }
+ if (!result.isSuccess()) {
+ return false;
+ }
+ } else if (listenChannel != 0) {
+ // listenChannel == 0 does not set any listen channel.
return false;
}
- SupplicantResult<Void> result = new SupplicantResult(
- "setListenChannel(" + channel + ", " + operatingClass + ")");
- try {
- result.setResult(mISupplicantP2pIface.setListenChannel(channel, operatingClass));
- } catch (RemoteException e) {
- Log.e(TAG, "ISupplicantP2pIface exception: " + e);
- supplicantServiceDiedHandler();
+ if (operatingChannel >= 0 && operatingChannel <= 165) {
+ ArrayList<ISupplicantP2pIface.FreqRange> ranges = new ArrayList<>();
+ // operatingChannel == 0 enables all freqs.
+ if (operatingChannel >= 1 && operatingChannel <= 165) {
+ int freq = (operatingChannel <= 14 ? 2407 : 5000) + operatingChannel * 5;
+ ISupplicantP2pIface.FreqRange range1 = new ISupplicantP2pIface.FreqRange();
+ range1.min = 1000;
+ range1.max = freq - 5;
+ ISupplicantP2pIface.FreqRange range2 = new ISupplicantP2pIface.FreqRange();
+ range2.min = freq + 5;
+ range2.max = 6000;
+ ranges.add(range1);
+ ranges.add(range2);
+ }
+ SupplicantResult<Void> result = new SupplicantResult(
+ "setDisallowedFrequencies(" + ranges + ")");
+ try {
+ result.setResult(mISupplicantP2pIface.setDisallowedFrequencies(ranges));
+ } catch (RemoteException e) {
+ Log.e(TAG, "ISupplicantP2pIface exception: " + e);
+ supplicantServiceDiedHandler();
+ }
+ return result.isSuccess();
}
- return result.isSuccess();
+ return false;
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/p2p/SupplicantP2pIfaceHalTest.java b/tests/wifitests/src/com/android/server/wifi/p2p/SupplicantP2pIfaceHalTest.java
index de5f0c0ab..4f5864bca 100644
--- a/tests/wifitests/src/com/android/server/wifi/p2p/SupplicantP2pIfaceHalTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/p2p/SupplicantP2pIfaceHalTest.java
@@ -1381,12 +1381,45 @@ public class SupplicantP2pIfaceHalTest {
*/
@Test
public void testSetListenChannel_success() throws Exception {
- when(mISupplicantP2pIfaceMock.setListenChannel(eq(123), eq(456)))
+ int lc = 4;
+ int oc = 163;
+ ISupplicantP2pIface.FreqRange range1 = new ISupplicantP2pIface.FreqRange();
+ range1.min = 1000;
+ range1.max = 5810;
+ ISupplicantP2pIface.FreqRange range2 = new ISupplicantP2pIface.FreqRange();
+ range2.min = 5820;
+ range2.max = 6000;
+ ArrayList<ISupplicantP2pIface.FreqRange> ranges = new ArrayList<>();
+ ranges.add(range1);
+ ranges.add(range2);
+
+ when(mISupplicantP2pIfaceMock.setListenChannel(eq(lc), anyInt()))
+ .thenReturn(mStatusSuccess);
+ when(mISupplicantP2pIfaceMock.setDisallowedFrequencies(eq(ranges)))
+ .thenReturn(mStatusSuccess);
+ // Default value when service is not initialized.
+ assertFalse(mDut.setListenChannel(lc, oc));
+ executeAndValidateInitializationSequence(false, false, false);
+ assertTrue(mDut.setListenChannel(lc, oc));
+ }
+
+ /**
+ * Sunny day scenario for setListenChannel()
+ */
+ @Test
+ public void testSetListenChannel_successResetDisallowedFreq() throws Exception {
+ int lc = 2;
+ int oc = 0;
+ ArrayList<ISupplicantP2pIface.FreqRange> ranges = new ArrayList<>();
+
+ when(mISupplicantP2pIfaceMock.setListenChannel(eq(lc), anyInt()))
+ .thenReturn(mStatusSuccess);
+ when(mISupplicantP2pIfaceMock.setDisallowedFrequencies(eq(ranges)))
.thenReturn(mStatusSuccess);
// Default value when service is not initialized.
- assertFalse(mDut.setListenChannel(123, 456));
+ assertFalse(mDut.setListenChannel(lc, oc));
executeAndValidateInitializationSequence(false, false, false);
- assertTrue(mDut.setListenChannel(123, 456));
+ assertTrue(mDut.setListenChannel(lc, oc));
}
/**
@@ -1397,6 +1430,8 @@ public class SupplicantP2pIfaceHalTest {
executeAndValidateInitializationSequence(false, false, false);
when(mISupplicantP2pIfaceMock.setListenChannel(anyInt(), anyInt()))
.thenReturn(mStatusSuccess);
+ when(mISupplicantP2pIfaceMock.setDisallowedFrequencies(any(ArrayList.class)))
+ .thenReturn(mStatusSuccess);
assertFalse(mDut.setListenChannel(-1, 1));
assertFalse(mDut.setListenChannel(1, -1));
}
@@ -1409,6 +1444,8 @@ public class SupplicantP2pIfaceHalTest {
executeAndValidateInitializationSequence(false, false, false);
when(mISupplicantP2pIfaceMock.setListenChannel(anyInt(), anyInt()))
.thenReturn(mStatusFailure);
+ when(mISupplicantP2pIfaceMock.setDisallowedFrequencies(any(ArrayList.class)))
+ .thenReturn(mStatusSuccess);
assertFalse(mDut.setListenChannel(1, 1));
// Check that service is still alive.
assertTrue(mDut.isInitializationComplete());