summaryrefslogtreecommitdiff
path: root/wifi/java/android/net
diff options
context:
space:
mode:
authorAhmed ElArabawy <arabawy@google.com>2020-05-10 14:42:46 -0700
committerAhmed ElArabawy <arabawy@google.com>2020-05-11 09:44:53 -0700
commitf7ccda05642b55700d67a288462bada488fc7f5e (patch)
treef712f93031e575ca4d155702e38863e2a72acc92 /wifi/java/android/net
parentd8b6b0fb9284474cbc18e81882e12d7a9a7a7ad0 (diff)
Wifi: Add definitions for bands frequency boundries
Channel frequency ranges for the three bands (2.4G, 5G, and 6G) are used in different places with separate definitions or via literal numbers. Also, the values are not accurate and sometimes not consistent. This commit defines those ranges in a single place for use of other classes. It also adds some utility methods that use those definitions. Bug: 153896822 Test: atest android.net.wifi Change-Id: Ifd19e245fd808c06d48d7557e30be3e92a9e7ec5
Diffstat (limited to 'wifi/java/android/net')
-rw-r--r--wifi/java/android/net/wifi/ScanResult.java160
1 files changed, 146 insertions, 14 deletions
diff --git a/wifi/java/android/net/wifi/ScanResult.java b/wifi/java/android/net/wifi/ScanResult.java
index f5b56225b8e5..aa3a13925894 100644
--- a/wifi/java/android/net/wifi/ScanResult.java
+++ b/wifi/java/android/net/wifi/ScanResult.java
@@ -524,48 +524,180 @@ public final class ScanResult implements Parcelable {
* {@hide}
*/
public final static int UNSPECIFIED = -1;
+
/**
+ * 2.4 GHz band first channel number
* @hide
*/
- public boolean is24GHz() {
- return ScanResult.is24GHz(frequency);
+ public static final int BAND_24_GHZ_FIRST_CH_NUM = 1;
+ /**
+ * 2.4 GHz band last channel number
+ * @hide
+ */
+ public static final int BAND_24_GHZ_LAST_CH_NUM = 14;
+ /**
+ * 2.4 GHz band frequency of first channel in MHz
+ * @hide
+ */
+ public static final int BAND_24_GHZ_START_FREQ_MHZ = 2412;
+ /**
+ * 2.4 GHz band frequency of last channel in MHz
+ * @hide
+ */
+ public static final int BAND_24_GHZ_END_FREQ_MHZ = 2484;
+
+ /**
+ * 5 GHz band first channel number
+ * @hide
+ */
+ public static final int BAND_5_GHZ_FIRST_CH_NUM = 32;
+ /**
+ * 5 GHz band last channel number
+ * @hide
+ */
+ public static final int BAND_5_GHZ_LAST_CH_NUM = 173;
+ /**
+ * 5 GHz band frequency of first channel in MHz
+ * @hide
+ */
+ public static final int BAND_5_GHZ_START_FREQ_MHZ = 5160;
+ /**
+ * 5 GHz band frequency of last channel in MHz
+ * @hide
+ */
+ public static final int BAND_5_GHZ_END_FREQ_MHZ = 5865;
+
+ /**
+ * 6 GHz band first channel number
+ * @hide
+ */
+ public static final int BAND_6_GHZ_FIRST_CH_NUM = 1;
+ /**
+ * 6 GHz band last channel number
+ * @hide
+ */
+ public static final int BAND_6_GHZ_LAST_CH_NUM = 233;
+ /**
+ * 6 GHz band frequency of first channel in MHz
+ * @hide
+ */
+ public static final int BAND_6_GHZ_START_FREQ_MHZ = 5945;
+ /**
+ * 6 GHz band frequency of last channel in MHz
+ * @hide
+ */
+ public static final int BAND_6_GHZ_END_FREQ_MHZ = 7105;
+
+ /**
+ * Utility function to check if a frequency within 2.4 GHz band
+ * @param freqMhz frequency in MHz
+ * @return true if within 2.4GHz, false otherwise
+ *
+ * @hide
+ */
+ public static boolean is24GHz(int freqMhz) {
+ return freqMhz >= BAND_24_GHZ_START_FREQ_MHZ && freqMhz <= BAND_24_GHZ_END_FREQ_MHZ;
}
/**
+ * Utility function to check if a frequency within 5 GHz band
+ * @param freqMhz frequency in MHz
+ * @return true if within 5GHz, false otherwise
+ *
* @hide
- * TODO: makes real freq boundaries
*/
- public static boolean is24GHz(int freq) {
- return freq > 2400 && freq < 2500;
+ public static boolean is5GHz(int freqMhz) {
+ return freqMhz >= BAND_5_GHZ_START_FREQ_MHZ && freqMhz <= BAND_5_GHZ_END_FREQ_MHZ;
}
/**
+ * Utility function to check if a frequency within 6 GHz band
+ * @param freqMhz
+ * @return true if within 6GHz, false otherwise
+ *
* @hide
*/
- public boolean is5GHz() {
- return ScanResult.is5GHz(frequency);
+ public static boolean is6GHz(int freqMhz) {
+ return freqMhz >= BAND_6_GHZ_START_FREQ_MHZ && freqMhz <= BAND_6_GHZ_END_FREQ_MHZ;
}
/**
+ * Utility function to convert channel number/band to frequency in MHz
+ * @param channel number to convert
+ * @param band of channel to convert
+ * @return center frequency in Mhz of the channel, {@link UNSPECIFIED} if no match
+ *
* @hide
*/
- public boolean is6GHz() {
- return ScanResult.is6GHz(frequency);
+ public static int convertChannelToFrequencyMhz(int channel, @WifiScanner.WifiBand int band) {
+ if (band == WifiScanner.WIFI_BAND_24_GHZ) {
+ // Special case
+ if (channel == 14) {
+ return 2484;
+ } else if (channel >= BAND_24_GHZ_FIRST_CH_NUM && channel <= BAND_24_GHZ_LAST_CH_NUM) {
+ return ((channel - BAND_24_GHZ_FIRST_CH_NUM) * 5) + BAND_24_GHZ_START_FREQ_MHZ;
+ } else {
+ return UNSPECIFIED;
+ }
+ }
+ if (band == WifiScanner.WIFI_BAND_5_GHZ) {
+ if (channel >= BAND_5_GHZ_FIRST_CH_NUM && channel <= BAND_5_GHZ_LAST_CH_NUM) {
+ return ((channel - BAND_5_GHZ_FIRST_CH_NUM) * 5) + BAND_5_GHZ_START_FREQ_MHZ;
+ } else {
+ return UNSPECIFIED;
+ }
+ }
+ if (band == WifiScanner.WIFI_BAND_6_GHZ) {
+ if (channel >= BAND_6_GHZ_FIRST_CH_NUM && channel <= BAND_6_GHZ_LAST_CH_NUM) {
+ return ((channel - BAND_6_GHZ_FIRST_CH_NUM) * 5) + BAND_6_GHZ_START_FREQ_MHZ;
+ } else {
+ return UNSPECIFIED;
+ }
+ }
+ return UNSPECIFIED;
}
/**
+ * Utility function to convert frequency in MHz to channel number
+ * @param freqMhz frequency in MHz
+ * @return channel number associated with given frequency, {@link UNSPECIFIED} if no match
+ *
* @hide
- * TODO: makes real freq boundaries
*/
- public static boolean is5GHz(int freq) {
- return freq > 4900 && freq < 5900;
+ public static int convertFrequencyMhzToChannel(int freqMhz) {
+ // Special case
+ if (freqMhz == 2484) {
+ return 14;
+ } else if (is24GHz(freqMhz)) {
+ return (freqMhz - BAND_24_GHZ_START_FREQ_MHZ) / 5 + BAND_24_GHZ_FIRST_CH_NUM;
+ } else if (is5GHz(freqMhz)) {
+ return ((freqMhz - BAND_5_GHZ_START_FREQ_MHZ) / 5) + BAND_5_GHZ_FIRST_CH_NUM;
+ } else if (is6GHz(freqMhz)) {
+ return ((freqMhz - BAND_6_GHZ_START_FREQ_MHZ) / 5) + BAND_6_GHZ_FIRST_CH_NUM;
+ }
+
+ return UNSPECIFIED;
+ }
+
+ /**
+ * @hide
+ */
+ public boolean is24GHz() {
+ return ScanResult.is24GHz(frequency);
}
/**
* @hide
*/
- public static boolean is6GHz(int freq) {
- return freq > 5925 && freq < 7125;
+ public boolean is5GHz() {
+ return ScanResult.is5GHz(frequency);
+ }
+
+ /**
+ * @hide
+ */
+ public boolean is6GHz() {
+ return ScanResult.is6GHz(frequency);
}
/**