1 /*
2  * Copyright 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.server.wifi;
17 
18 import static com.android.server.wifi.util.InformationElementUtil.BssLoad.INVALID;
19 import static com.android.server.wifi.util.InformationElementUtil.BssLoad.MAX_CHANNEL_UTILIZATION;
20 import static com.android.server.wifi.util.InformationElementUtil.BssLoad.MIN_CHANNEL_UTILIZATION;
21 
22 import android.annotation.NonNull;
23 import android.content.Context;
24 import android.net.wifi.ScanResult;
25 import android.net.wifi.WifiAnnotations.WifiStandard;
26 import android.net.wifi.WifiInfo;
27 import android.net.wifi.nl80211.DeviceWiphyCapabilities;
28 import android.util.Log;
29 
30 import com.android.wifi.resources.R;
31 
32 /**
33  * A class that predicts network throughput based on RSSI, channel utilization, channel width,
34  * WiFi standard (PHY/MAC mode), Nss and other radio information.
35  */
36 public class ThroughputPredictor {
37     private static final String TAG = "WifiThroughputPredictor";
38     private boolean mVerboseLoggingEnabled = false;
39 
40     // Default value of channel utilization at 2G when channel utilization is not available from
41     // BssLoad IE or from link layer stats
42     public static final int CHANNEL_UTILIZATION_DEFAULT_2G = MAX_CHANNEL_UTILIZATION * 6 / 16;
43     // Default value of channel utilization at 5G when channel utilization is not available from
44     // BssLoad IE or from link layer stats
45     public static final int CHANNEL_UTILIZATION_DEFAULT_ABOVE_2G = MAX_CHANNEL_UTILIZATION / 16;
46     // Channel utilization boost when bluetooth is in the connected mode
47     public static final int CHANNEL_UTILIZATION_BOOST_BT_CONNECTED_2G = MAX_CHANNEL_UTILIZATION / 4;
48     //TODO: b/145133625 Need to consider 6GHz
49 
50     // Number of data tones per OFDM symbol
51     private static final int NUM_TONE_PER_SYM_LEGACY = 48;
52     private static final int NUM_TONE_PER_SYM_11N_20MHZ = 52;
53     private static final int NUM_TONE_PER_SYM_11N_40MHZ = 108;
54     private static final int NUM_TONE_PER_SYM_11AC_20MHZ = 52;
55     private static final int NUM_TONE_PER_SYM_11AC_40MHZ = 108;
56     private static final int NUM_TONE_PER_SYM_11AC_80MHZ = 234;
57     private static final int NUM_TONE_PER_SYM_11AC_160MHZ = 468;
58     private static final int NUM_TONE_PER_SYM_11AX_20MHZ = 234;
59     private static final int NUM_TONE_PER_SYM_11AX_40MHZ = 468;
60     private static final int NUM_TONE_PER_SYM_11AX_80MHZ = 980;
61     private static final int NUM_TONE_PER_SYM_11AX_160MHZ = 1960;
62 
63     // 11ag OFDM symbol duration in ns
64     private static final int SYM_DURATION_LEGACY_NS = 4000;
65     // 11n OFDM symbol duration in ns with 0.4us guard interval
66     private static final int SYM_DURATION_11N_NS = 3600;
67     // 11ac OFDM symbol duration in ns with 0.4us guard interval
68     private static final int SYM_DURATION_11AC_NS = 3600;
69     // 11ax OFDM symbol duration in ns with 0.8us guard interval
70     private static final int SYM_DURATION_11AX_NS = 13600;
71     private static final int MICRO_TO_NANO_RATIO = 1000;
72 
73     // The scaling factor for integer representation of bitPerTone and MAX_BITS_PER_TONE_XXX
74     private static final int BIT_PER_TONE_SCALE = 1000;
75     private static final int MAX_BITS_PER_TONE_LEGACY =
76             (int) Math.round((6 * 3.0 * BIT_PER_TONE_SCALE) / 4.0);
77     private static final int MAX_BITS_PER_TONE_11N =
78             (int) Math.round((6 * 5.0 * BIT_PER_TONE_SCALE) / 6.0);
79     private static final int MAX_BITS_PER_TONE_11AC =
80             (int) Math.round((8 * 5.0 * BIT_PER_TONE_SCALE) / 6.0);
81     private static final int MAX_BITS_PER_TONE_11AX =
82             (int) Math.round((10 * 5.0 * BIT_PER_TONE_SCALE) / 6.0);
83 
84     // snrDb-to-bitPerTone lookup table (LUT) used at low SNR
85     // snr = Math.pow(10.0, snrDb / 10.0);
86     // bitPerTone = (int) (Math.log10(1 + snr) / Math.log10(2.0) * BIT_PER_TONE_SCALE)
87     private static final int TWO_IN_DB = 3;
88     private static final int SNR_DB_TO_BIT_PER_TONE_HIGH_SNR_SCALE = BIT_PER_TONE_SCALE / TWO_IN_DB;
89     private static final int SNR_DB_TO_BIT_PER_TONE_LUT_MIN = -10; // minimum snrDb supported by LUT
90     private static final int SNR_DB_TO_BIT_PER_TONE_LUT_MAX = 9; // maximum snrDb supported by LUT
91     private static final int[] SNR_DB_TO_BIT_PER_TONE_LUT = {0, 171, 212, 262, 323, 396, 484, 586,
92             706, 844, 1000, 1176, 1370, 1583, 1812, 2058, 2317, 2588, 2870, 3161};
93     // Thermal noise floor power in dBm integrated over 20MHz with 5.5dB noise figure at 25C
94     private static final int NOISE_FLOOR_20MHZ_DBM = -96;
95     // A fudge factor to represent HW implementation margin in dB.
96     // Predicted throughput matches pretty well with OTA throughput with this fudge factor.
97     private static final int SNR_MARGIN_DB = 16;
98     private static final int MAX_NUM_SPATIAL_STREAM_11AX = 8;
99     private static final int MAX_NUM_SPATIAL_STREAM_11AC = 8;
100     private static final int MAX_NUM_SPATIAL_STREAM_11N = 4;
101     private static final int MAX_NUM_SPATIAL_STREAM_LEGACY = 1;
102 
103     private final Context mContext;
104 
ThroughputPredictor(Context context)105     ThroughputPredictor(Context context) {
106         mContext = context;
107     }
108 
109     /**
110      * Enable/Disable verbose logging.
111      *
112      * @param verbose true to enable and false to disable.
113      */
enableVerboseLogging(boolean verbose)114     public void enableVerboseLogging(boolean verbose) {
115         mVerboseLoggingEnabled = verbose;
116     }
117 
118     /**
119      * Predict maximum Tx throughput supported by connected network at the highest RSSI
120      * with the lowest channel utilization
121      * @return predicted maximum Tx throughput in Mbps
122      */
predictMaxTxThroughput(@onNull WifiNative.ConnectionCapabilities capabilities)123     public int predictMaxTxThroughput(@NonNull WifiNative.ConnectionCapabilities capabilities) {
124         return predictThroughputInternal(capabilities.wifiStandard, capabilities.channelBandwidth,
125                 WifiInfo.MAX_RSSI, capabilities.maxNumberTxSpatialStreams, MIN_CHANNEL_UTILIZATION);
126     }
127 
128     /**
129      * Predict maximum Rx throughput supported by connected network at the highest RSSI
130      * with the lowest channel utilization
131      * @return predicted maximum Rx throughput in Mbps
132      */
predictMaxRxThroughput(@onNull WifiNative.ConnectionCapabilities capabilities)133     public int predictMaxRxThroughput(@NonNull WifiNative.ConnectionCapabilities capabilities) {
134         return predictThroughputInternal(capabilities.wifiStandard, capabilities.channelBandwidth,
135                 WifiInfo.MAX_RSSI, capabilities.maxNumberRxSpatialStreams, MIN_CHANNEL_UTILIZATION);
136     }
137 
138     /**
139      * Predict Tx throughput with current connection capabilities, RSSI and channel utilization
140      * @return predicted Tx throughput in Mbps
141      */
predictTxThroughput(@onNull WifiNative.ConnectionCapabilities capabilities, int rssiDbm, int frequency, int channelUtilization)142     public int predictTxThroughput(@NonNull WifiNative.ConnectionCapabilities capabilities,
143             int rssiDbm, int frequency, int channelUtilization) {
144         int channelUtilizationFinal = getValidChannelUtilization(frequency,
145                 INVALID, channelUtilization, false);
146         return predictThroughputInternal(capabilities.wifiStandard, capabilities.channelBandwidth,
147                 rssiDbm, capabilities.maxNumberTxSpatialStreams, channelUtilizationFinal);
148     }
149 
150     /**
151      * Predict Rx throughput with current connection capabilities, RSSI and channel utilization
152      * @return predicted Rx throughput in Mbps
153      */
predictRxThroughput(@onNull WifiNative.ConnectionCapabilities capabilities, int rssiDbm, int frequency, int channelUtilization)154     public int predictRxThroughput(@NonNull WifiNative.ConnectionCapabilities capabilities,
155             int rssiDbm, int frequency, int channelUtilization) {
156         int channelUtilizationFinal = getValidChannelUtilization(frequency,
157                 INVALID, channelUtilization, false);
158         return predictThroughputInternal(capabilities.wifiStandard, capabilities.channelBandwidth,
159                 rssiDbm, capabilities.maxNumberRxSpatialStreams, channelUtilizationFinal);
160     }
161 
162     /**
163      * Predict network throughput given by the current channel condition and RSSI
164      * @param deviceCapabilities Phy Capabilities of the device
165      * @param wifiStandardAp the highest wifi standard supported by AP
166      * @param channelWidthAp the channel bandwidth of AP
167      * @param rssiDbm the scan RSSI in dBm
168      * @param frequency the center frequency of primary 20MHz channel
169      * @param maxNumSpatialStreamAp the maximum number of spatial streams supported by AP
170      * @param channelUtilizationBssLoad the channel utilization ratio indicated from BssLoad IE
171      * @param channelUtilizationLinkLayerStats the channel utilization ratio detected from scan
172      * @param isBluetoothConnected whether the bluetooth adaptor is in connected mode
173      * @return predicted throughput in Mbps
174      */
predictThroughput(DeviceWiphyCapabilities deviceCapabilities, @WifiStandard int wifiStandardAp, int channelWidthAp, int rssiDbm, int frequency, int maxNumSpatialStreamAp, int channelUtilizationBssLoad, int channelUtilizationLinkLayerStats, boolean isBluetoothConnected)175     public int predictThroughput(DeviceWiphyCapabilities deviceCapabilities,
176             @WifiStandard int wifiStandardAp,
177             int channelWidthAp, int rssiDbm, int frequency, int maxNumSpatialStreamAp,
178             int channelUtilizationBssLoad, int channelUtilizationLinkLayerStats,
179             boolean isBluetoothConnected) {
180 
181         if (deviceCapabilities == null) {
182             Log.e(TAG, "Null device capabilities passed to throughput predictor");
183             return 0;
184         }
185 
186         int maxNumSpatialStreamDevice = Math.min(deviceCapabilities.getMaxNumberTxSpatialStreams(),
187                 deviceCapabilities.getMaxNumberRxSpatialStreams());
188 
189         if (mContext.getResources().getBoolean(
190                 R.bool.config_wifiFrameworkMaxNumSpatialStreamDeviceOverrideEnable)) {
191             maxNumSpatialStreamDevice = mContext.getResources().getInteger(
192                     R.integer.config_wifiFrameworkMaxNumSpatialStreamDeviceOverrideValue);
193         }
194 
195         int maxNumSpatialStream = Math.min(maxNumSpatialStreamDevice, maxNumSpatialStreamAp);
196 
197         // Get minimum standard support between device and AP
198         int wifiStandard;
199         switch (wifiStandardAp) {
200             case ScanResult.WIFI_STANDARD_11AX:
201                 if (deviceCapabilities.isWifiStandardSupported(ScanResult.WIFI_STANDARD_11AX)) {
202                     wifiStandard = ScanResult.WIFI_STANDARD_11AX;
203                     break;
204                 }
205                 //FALL THROUGH
206             case ScanResult.WIFI_STANDARD_11AC:
207                 if (deviceCapabilities.isWifiStandardSupported(ScanResult.WIFI_STANDARD_11AC)) {
208                     wifiStandard = ScanResult.WIFI_STANDARD_11AC;
209                     break;
210                 }
211                 //FALL THROUGH
212             case ScanResult.WIFI_STANDARD_11N:
213                 if (deviceCapabilities.isWifiStandardSupported(ScanResult.WIFI_STANDARD_11N)) {
214                     wifiStandard = ScanResult.WIFI_STANDARD_11N;
215                     break;
216                 }
217                 //FALL THROUGH
218             default:
219                 wifiStandard = ScanResult.WIFI_STANDARD_LEGACY;
220         }
221 
222         // Calculate channel width
223         int channelWidth;
224         switch (channelWidthAp) {
225             case ScanResult.CHANNEL_WIDTH_160MHZ:
226                 if (deviceCapabilities.isChannelWidthSupported(ScanResult.CHANNEL_WIDTH_160MHZ)) {
227                     channelWidth = ScanResult.CHANNEL_WIDTH_160MHZ;
228                     break;
229                 }
230                 // FALL THROUGH
231             case ScanResult.CHANNEL_WIDTH_80MHZ:
232                 if (deviceCapabilities.isChannelWidthSupported(ScanResult.CHANNEL_WIDTH_80MHZ)) {
233                     channelWidth = ScanResult.CHANNEL_WIDTH_80MHZ;
234                     break;
235                 }
236                 // FALL THROUGH
237             case ScanResult.CHANNEL_WIDTH_40MHZ:
238                 if (deviceCapabilities.isChannelWidthSupported(ScanResult.CHANNEL_WIDTH_40MHZ)) {
239                     channelWidth = ScanResult.CHANNEL_WIDTH_40MHZ;
240                     break;
241                 }
242                 // FALL THROUGH
243             default:
244                 channelWidth = ScanResult.CHANNEL_WIDTH_20MHZ;
245         }
246 
247         if (mVerboseLoggingEnabled) {
248             StringBuilder sb = new StringBuilder();
249             Log.d(TAG, sb.append("AP Nss: ").append(maxNumSpatialStreamAp)
250                     .append(", Device Nss: ").append(maxNumSpatialStreamDevice)
251                     .append(", freq: ").append(frequency)
252                     .toString());
253         }
254 
255         int channelUtilization = getValidChannelUtilization(frequency,
256                 channelUtilizationBssLoad,
257                 channelUtilizationLinkLayerStats,
258                 isBluetoothConnected);
259 
260         return predictThroughputInternal(wifiStandard, channelWidth, rssiDbm, maxNumSpatialStream,
261                 channelUtilization);
262     }
263 
predictThroughputInternal(@ifiStandard int wifiStandard, int channelWidth, int rssiDbm, int maxNumSpatialStream, int channelUtilization)264     private int predictThroughputInternal(@WifiStandard int wifiStandard,
265             int channelWidth, int rssiDbm, int maxNumSpatialStream,  int channelUtilization) {
266 
267         // channel bandwidth in MHz = 20MHz * (2 ^ channelWidthFactor);
268         int channelWidthFactor;
269         int numTonePerSym;
270         int symDurationNs;
271         int maxBitsPerTone;
272         if (maxNumSpatialStream < 1) {
273             Log.e(TAG, "maxNumSpatialStream < 1 due to wrong implementation. Overridden to 1");
274             maxNumSpatialStream = 1;
275         }
276         if (wifiStandard == ScanResult.WIFI_STANDARD_UNKNOWN) {
277             return WifiInfo.LINK_SPEED_UNKNOWN;
278         } else if (wifiStandard == ScanResult.WIFI_STANDARD_LEGACY) {
279             numTonePerSym = NUM_TONE_PER_SYM_LEGACY;
280             channelWidthFactor = 0;
281             maxNumSpatialStream = MAX_NUM_SPATIAL_STREAM_LEGACY;
282             maxBitsPerTone = MAX_BITS_PER_TONE_LEGACY;
283             symDurationNs = SYM_DURATION_LEGACY_NS;
284         } else if (wifiStandard == ScanResult.WIFI_STANDARD_11N) {
285             if (channelWidth == ScanResult.CHANNEL_WIDTH_20MHZ) {
286                 numTonePerSym = NUM_TONE_PER_SYM_11N_20MHZ;
287                 channelWidthFactor = 0;
288             } else {
289                 numTonePerSym = NUM_TONE_PER_SYM_11N_40MHZ;
290                 channelWidthFactor = 1;
291             }
292             maxNumSpatialStream = Math.min(maxNumSpatialStream, MAX_NUM_SPATIAL_STREAM_11N);
293             maxBitsPerTone = MAX_BITS_PER_TONE_11N;
294             symDurationNs = SYM_DURATION_11N_NS;
295         } else if (wifiStandard == ScanResult.WIFI_STANDARD_11AC) {
296             if (channelWidth == ScanResult.CHANNEL_WIDTH_20MHZ) {
297                 numTonePerSym = NUM_TONE_PER_SYM_11AC_20MHZ;
298                 channelWidthFactor = 0;
299             } else if (channelWidth == ScanResult.CHANNEL_WIDTH_40MHZ) {
300                 numTonePerSym = NUM_TONE_PER_SYM_11AC_40MHZ;
301                 channelWidthFactor = 1;
302             } else if (channelWidth == ScanResult.CHANNEL_WIDTH_80MHZ) {
303                 numTonePerSym = NUM_TONE_PER_SYM_11AC_80MHZ;
304                 channelWidthFactor = 2;
305             } else {
306                 numTonePerSym = NUM_TONE_PER_SYM_11AC_160MHZ;
307                 channelWidthFactor = 3;
308             }
309             maxNumSpatialStream = Math.min(maxNumSpatialStream, MAX_NUM_SPATIAL_STREAM_11AC);
310             maxBitsPerTone = MAX_BITS_PER_TONE_11AC;
311             symDurationNs = SYM_DURATION_11AC_NS;
312         } else { // ScanResult.WIFI_STANDARD_11AX
313             if (channelWidth == ScanResult.CHANNEL_WIDTH_20MHZ) {
314                 numTonePerSym = NUM_TONE_PER_SYM_11AX_20MHZ;
315                 channelWidthFactor = 0;
316             } else if (channelWidth == ScanResult.CHANNEL_WIDTH_40MHZ) {
317                 numTonePerSym = NUM_TONE_PER_SYM_11AX_40MHZ;
318                 channelWidthFactor = 1;
319             } else if (channelWidth == ScanResult.CHANNEL_WIDTH_80MHZ) {
320                 numTonePerSym = NUM_TONE_PER_SYM_11AX_80MHZ;
321                 channelWidthFactor = 2;
322             } else {
323                 numTonePerSym = NUM_TONE_PER_SYM_11AX_160MHZ;
324                 channelWidthFactor = 3;
325             }
326             maxNumSpatialStream = Math.min(maxNumSpatialStream, MAX_NUM_SPATIAL_STREAM_11AX);
327             maxBitsPerTone = MAX_BITS_PER_TONE_11AX;
328             symDurationNs = SYM_DURATION_11AX_NS;
329         }
330         // noiseFloorDbBoost = 10 * log10 * (2 ^ channelWidthFactor)
331         int noiseFloorDbBoost = TWO_IN_DB * channelWidthFactor;
332         int noiseFloorDbm = NOISE_FLOOR_20MHZ_DBM + noiseFloorDbBoost + SNR_MARGIN_DB;
333         int snrDb  = rssiDbm - noiseFloorDbm;
334 
335         int bitPerTone = calculateBitPerTone(snrDb);
336         bitPerTone = Math.min(bitPerTone, maxBitsPerTone);
337 
338         long bitPerToneTotal = bitPerTone * maxNumSpatialStream;
339         long numBitPerSym = bitPerToneTotal * numTonePerSym;
340         int phyRateMbps =  (int) ((numBitPerSym * MICRO_TO_NANO_RATIO)
341                 / (symDurationNs * BIT_PER_TONE_SCALE));
342 
343         int airTimeFraction = calculateAirTimeFraction(channelUtilization, channelWidthFactor);
344 
345         int throughputMbps = (phyRateMbps * airTimeFraction) / MAX_CHANNEL_UTILIZATION;
346 
347         if (mVerboseLoggingEnabled) {
348             StringBuilder sb = new StringBuilder();
349             Log.d(TAG, sb.append(" BW: ").append(channelWidth)
350                     .append(" RSSI: ").append(rssiDbm)
351                     .append(" Nss: ").append(maxNumSpatialStream)
352                     .append(" Mode: ").append(wifiStandard)
353                     .append(" symDur: ").append(symDurationNs)
354                     .append(" snrDb ").append(snrDb)
355                     .append(" bitPerTone: ").append(bitPerTone)
356                     .append(" rate: ").append(phyRateMbps)
357                     .append(" throughput: ").append(throughputMbps)
358                     .toString());
359         }
360         return throughputMbps;
361     }
362 
363     // Calculate the number of bits per tone based on the input of SNR in dB
364     // The output is scaled up by BIT_PER_TONE_SCALE for integer representation
calculateBitPerTone(int snrDb)365     private static int calculateBitPerTone(int snrDb) {
366         int bitPerTone;
367         if (snrDb <= SNR_DB_TO_BIT_PER_TONE_LUT_MAX) {
368             int lut_in_idx = Math.max(snrDb, SNR_DB_TO_BIT_PER_TONE_LUT_MIN)
369                     - SNR_DB_TO_BIT_PER_TONE_LUT_MIN;
370             lut_in_idx = Math.min(lut_in_idx, SNR_DB_TO_BIT_PER_TONE_LUT.length - 1);
371             bitPerTone = SNR_DB_TO_BIT_PER_TONE_LUT[lut_in_idx];
372         } else {
373             // bitPerTone = Math.log10(1+snr)/Math.log10(2) can be approximated as
374             // Math.log10(snr) / 0.3 = log10(10^(snrDb/10)) / 0.3 = snrDb / 3
375             // SNR_DB_TO_BIT_PER_TONE_HIGH_SNR_SCALE = BIT_PER_TONE_SCALE / 3
376             bitPerTone = snrDb * SNR_DB_TO_BIT_PER_TONE_HIGH_SNR_SCALE;
377         }
378         return bitPerTone;
379     }
380 
getValidChannelUtilization(int frequency, int channelUtilizationBssLoad, int channelUtilizationLinkLayerStats, boolean isBluetoothConnected)381     private int getValidChannelUtilization(int frequency, int channelUtilizationBssLoad,
382             int channelUtilizationLinkLayerStats, boolean isBluetoothConnected) {
383         int channelUtilization;
384         boolean is2G = ScanResult.is24GHz(frequency);
385         if (isValidUtilizationRatio(channelUtilizationBssLoad)) {
386             channelUtilization = channelUtilizationBssLoad;
387         } else if (isValidUtilizationRatio(channelUtilizationLinkLayerStats)) {
388             channelUtilization = channelUtilizationLinkLayerStats;
389         } else {
390             channelUtilization = is2G ? CHANNEL_UTILIZATION_DEFAULT_2G :
391                     CHANNEL_UTILIZATION_DEFAULT_ABOVE_2G;
392         }
393 
394         if (is2G && isBluetoothConnected) {
395             channelUtilization += CHANNEL_UTILIZATION_BOOST_BT_CONNECTED_2G;
396             channelUtilization = Math.min(channelUtilization, MAX_CHANNEL_UTILIZATION);
397         }
398         if (mVerboseLoggingEnabled) {
399             StringBuilder sb = new StringBuilder();
400             Log.d(TAG, sb.append(" utilization (BssLoad) ").append(channelUtilizationBssLoad)
401                     .append(" utilization (LLStats) ").append(channelUtilizationLinkLayerStats)
402                     .append(" isBluetoothConnected: ").append(isBluetoothConnected)
403                     .append(" final utilization: ").append(channelUtilization)
404                     .toString());
405         }
406         return channelUtilization;
407     }
408 
409     /**
410      * Check if the channel utilization ratio is valid
411      */
isValidUtilizationRatio(int utilizationRatio)412     private static boolean isValidUtilizationRatio(int utilizationRatio) {
413         return (utilizationRatio <= MAX_CHANNEL_UTILIZATION
414                 && utilizationRatio >= MIN_CHANNEL_UTILIZATION);
415     }
416 
417     // Calculate the available airtime fraction value which is multiplied by
418     // MAX_CHANNEL_UTILIZATION for integer representation. It is calculated as
419     // (1 - channelUtilization / MAX_CHANNEL_UTILIZATION) * MAX_CHANNEL_UTILIZATION
calculateAirTimeFraction(int channelUtilization, int channelWidthFactor)420     private int calculateAirTimeFraction(int channelUtilization, int channelWidthFactor) {
421         int airTimeFraction20MHz = MAX_CHANNEL_UTILIZATION - channelUtilization;
422         int airTimeFraction = airTimeFraction20MHz;
423         // For the cases of 40MHz or above, need to take
424         // (1 - channelUtilization / MAX_CHANNEL_UTILIZATION) ^ (2 ^ channelWidthFactor)
425         // because channelUtilization is defined for primary 20MHz channel
426         for (int i = 1; i <= channelWidthFactor; ++i) {
427             airTimeFraction *= airTimeFraction;
428             airTimeFraction /= MAX_CHANNEL_UTILIZATION;
429         }
430         if (mVerboseLoggingEnabled) {
431             Log.d(TAG, " airTime20: " + airTimeFraction20MHz + " airTime: " + airTimeFraction);
432         }
433         return airTimeFraction;
434     }
435 }
436