From 0965581cc4cec9b4018597974a4b43d941f7023d Mon Sep 17 00:00:00 2001 From: Mygod Date: Thu, 4 Jun 2020 21:49:02 -0400 Subject: [PATCH] Specify reason for blacklisting MACs --- .../java/be/mygod/vpnhotspot/net/MacAddressCompat.kt | 1 + .../vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/MacAddressCompat.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/MacAddressCompat.kt index a2d35c90..04f9d104 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/MacAddressCompat.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/MacAddressCompat.kt @@ -21,6 +21,7 @@ inline class MacAddressCompat(val addr: Long) : Parcelable { * @hide */ val ALL_ZEROS_ADDRESS = MacAddressCompat(0) + val ANY_ADDRESS = MacAddressCompat(2L shl 40) fun bytesToString(addr: ByteArray): String { require(addr.size == ETHER_ADDR_LEN) { addr.contentToString() + " was not a valid MAC address" } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt index 6873d856..90bbc113 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt @@ -4,6 +4,7 @@ import android.net.wifi.p2p.WifiP2pGroup import android.os.Build import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.RepeaterService +import be.mygod.vpnhotspot.net.MacAddressCompat import be.mygod.vpnhotspot.util.RootSession import com.google.firebase.crashlytics.FirebaseCrashlytics import java.io.File @@ -54,7 +55,14 @@ class P2pSupplicantConfiguration(private val group: WifiP2pGroup, ownerAddress: try { val bssids = listOfNotNull(group.owner.deviceAddress, ownerAddress, RepeaterService.lastMac) .distinct() - .filter { it != "00:00:00:00:00:00" && it != "02:00:00:00:00:00" } + .filter { + try { + val mac = MacAddressCompat.fromString(it) + mac != MacAddressCompat.ALL_ZEROS_ADDRESS && mac != MacAddressCompat.ANY_ADDRESS + } catch (_: IllegalArgumentException) { + false + } + } while (parser.next()) { if (parser.trimmed.startsWith("network={")) { val block = NetworkBlock()