From 396ac1fe07b9a255b65b404f08130e67e4cd87f1 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sat, 29 May 2021 18:31:47 -0400 Subject: [PATCH] Update frequency calculations --- .../net/wifi/SoftApConfigurationCompat.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/SoftApConfigurationCompat.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/SoftApConfigurationCompat.kt index e867b361..a8f9a2d1 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/SoftApConfigurationCompat.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/SoftApConfigurationCompat.kt @@ -72,7 +72,8 @@ data class SoftApConfigurationCompat( /** * Based on: - * https://elixir.bootlin.com/linux/v5.7.6/source/net/wireless/util.c#L75 + * https://elixir.bootlin.com/linux/v5.12.8/source/net/wireless/util.c#L75 + * TODO: update for Android 12 * https://cs.android.com/android/platform/superproject/+/master:frameworks/base/wifi/java/android/net/wifi/ScanResult.java;l=624;drc=f7ccda05642b55700d67a288462bada488fc7f5e */ fun channelToFrequency(band: Int, chan: Int) = when (band) { @@ -86,10 +87,11 @@ data class SoftApConfigurationCompat( in 1..Int.MAX_VALUE -> 5000 + chan * 5 else -> throw IllegalArgumentException("Invalid 5GHz channel $chan") } - // TODO: update for Android 12 - BAND_6GHZ -> if (chan in 1..253) { - 5940 + chan * 5 - } else throw IllegalArgumentException("Invalid 6GHz channel $chan") + BAND_6GHZ -> when (chan) { + 2 -> 5935 + in 1..233 -> 5950 + chan * 5 + else -> throw IllegalArgumentException("Invalid 6GHz channel $chan") + } BAND_60GHZ -> if (chan in 1 until 7) { 56160 + chan * 2160 } else throw IllegalArgumentException("Invalid 60GHz channel $chan") @@ -99,8 +101,9 @@ data class SoftApConfigurationCompat( 2484 -> 14 in Int.MIN_VALUE until 2484 -> (freq - 2407) / 5 in 4910..4980 -> (freq - 4000) / 5 - in Int.MIN_VALUE until 5945 -> (freq - 5000) / 5 - in Int.MIN_VALUE..45000 -> (freq - 5940) / 5 + in Int.MIN_VALUE until 5925 -> (freq - 5000) / 5 + 5935 -> 2 + in Int.MIN_VALUE..45000 -> (freq - 5950) / 5 in 58320..70200 -> (freq - 56160) / 2160 else -> throw IllegalArgumentException("Invalid frequency $freq") }