Add ability to specify device address for wifi p2p
This commit is contained in:
@@ -28,6 +28,7 @@ import be.mygod.vpnhotspot.util.*
|
|||||||
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
import java.lang.IllegalArgumentException
|
||||||
import java.lang.reflect.InvocationTargetException
|
import java.lang.reflect.InvocationTargetException
|
||||||
import java.net.NetworkInterface
|
import java.net.NetworkInterface
|
||||||
|
|
||||||
@@ -44,6 +45,7 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
|
|||||||
private const val KEY_PASSPHRASE = "service.repeater.passphrase"
|
private const val KEY_PASSPHRASE = "service.repeater.passphrase"
|
||||||
private const val KEY_OPERATING_BAND = "service.repeater.band"
|
private const val KEY_OPERATING_BAND = "service.repeater.band"
|
||||||
private const val KEY_OPERATING_CHANNEL = "service.repeater.oc"
|
private const val KEY_OPERATING_CHANNEL = "service.repeater.oc"
|
||||||
|
private const val KEY_DEVICE_ADDRESS = "service.repeater.mac"
|
||||||
/**
|
/**
|
||||||
* Placeholder for bypassing networkName check.
|
* Placeholder for bypassing networkName check.
|
||||||
*/
|
*/
|
||||||
@@ -90,6 +92,17 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
|
|||||||
return if (result in 1..165) result else 0
|
return if (result in 1..165) result else 0
|
||||||
}
|
}
|
||||||
set(value) = app.pref.edit { putString(KEY_OPERATING_CHANNEL, value.toString()) }
|
set(value) = app.pref.edit { putString(KEY_OPERATING_CHANNEL, value.toString()) }
|
||||||
|
var deviceAddress: MacAddressCompat?
|
||||||
|
get() = try {
|
||||||
|
MacAddressCompat(app.pref.getLong(KEY_DEVICE_ADDRESS, MacAddressCompat.ANY_ADDRESS.addr)).run {
|
||||||
|
validate()
|
||||||
|
if (this == MacAddressCompat.ANY_ADDRESS) null else this
|
||||||
|
}
|
||||||
|
} catch (e: IllegalArgumentException) {
|
||||||
|
Timber.w(e)
|
||||||
|
null
|
||||||
|
}
|
||||||
|
set(value) = app.pref.edit { putLong(KEY_DEVICE_ADDRESS, (value ?: MacAddressCompat.ANY_ADDRESS).addr) }
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class Status {
|
enum class Status {
|
||||||
@@ -317,6 +330,7 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
|
|||||||
if (oc == 0) setGroupOperatingBand(operatingBand)
|
if (oc == 0) setGroupOperatingBand(operatingBand)
|
||||||
else setGroupOperatingFrequency(SoftApConfigurationCompat.channelToFrequency(oc))
|
else setGroupOperatingFrequency(SoftApConfigurationCompat.channelToFrequency(oc))
|
||||||
}
|
}
|
||||||
|
setDeviceAddress(deviceAddress?.toPlatform())
|
||||||
}.build().run {
|
}.build().run {
|
||||||
useParcel { p ->
|
useParcel { p ->
|
||||||
p.writeParcelable(this, 0)
|
p.writeParcelable(this, 0)
|
||||||
|
|||||||
@@ -192,13 +192,15 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
|||||||
else -> throw IllegalArgumentException("Unknown operatingBand")
|
else -> throw IllegalArgumentException("Unknown operatingBand")
|
||||||
}
|
}
|
||||||
channel = RepeaterService.operatingChannel
|
channel = RepeaterService.operatingChannel
|
||||||
|
bssid = RepeaterService.deviceAddress
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val group = binder?.group
|
val group = binder?.group
|
||||||
if (group != null) try {
|
if (group != null) try {
|
||||||
val config = withContext(Dispatchers.Default) {
|
val config = withContext(Dispatchers.Default) {
|
||||||
P2pSupplicantConfiguration(group, binder?.thisDevice?.deviceAddress)
|
P2pSupplicantConfiguration(group,
|
||||||
|
binder?.thisDevice?.deviceAddress, RepeaterService.deviceAddress?.toString())
|
||||||
}
|
}
|
||||||
holder.config = config
|
holder.config = config
|
||||||
return SoftApConfigurationCompat.empty().apply {
|
return SoftApConfigurationCompat.empty().apply {
|
||||||
@@ -209,6 +211,7 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
|||||||
band = SoftApConfigurationCompat.BAND_ANY
|
band = SoftApConfigurationCompat.BAND_ANY
|
||||||
channel = RepeaterService.operatingChannel
|
channel = RepeaterService.operatingChannel
|
||||||
}
|
}
|
||||||
|
bssid = RepeaterService.deviceAddress
|
||||||
}
|
}
|
||||||
} catch (e: RuntimeException) {
|
} catch (e: RuntimeException) {
|
||||||
Timber.w(e)
|
Timber.w(e)
|
||||||
@@ -239,5 +242,6 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
|
|||||||
holder.config = null
|
holder.config = null
|
||||||
}
|
}
|
||||||
if (Build.VERSION.SDK_INT >= 23) RepeaterService.operatingChannel = config.channel
|
if (Build.VERSION.SDK_INT >= 23) RepeaterService.operatingChannel = config.channel
|
||||||
|
RepeaterService.deviceAddress = config.bssid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,8 @@ inline class MacAddressCompat(val addr: Long) : Parcelable {
|
|||||||
fun MacAddress.toCompat() = fromBytes(toByteArray())
|
fun MacAddress.toCompat() = fromBytes(toByteArray())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun validate() = require(addr and ((1L shl 48) - 1).inv() == 0L)
|
||||||
|
|
||||||
fun toList() = ByteBuffer.allocate(8).run {
|
fun toList() = ByteBuffer.allocate(8).run {
|
||||||
order(ByteOrder.LITTLE_ENDIAN)
|
order(ByteOrder.LITTLE_ENDIAN)
|
||||||
putLong(addr)
|
putLong(addr)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import java.io.File
|
|||||||
* https://android.googlesource.com/platform/external/wpa_supplicant_8/+/d2986c2/wpa_supplicant/config.c#488
|
* https://android.googlesource.com/platform/external/wpa_supplicant_8/+/d2986c2/wpa_supplicant/config.c#488
|
||||||
* https://android.googlesource.com/platform/external/wpa_supplicant_8/+/6fa46df/wpa_supplicant/config_file.c#182
|
* https://android.googlesource.com/platform/external/wpa_supplicant_8/+/6fa46df/wpa_supplicant/config_file.c#182
|
||||||
*/
|
*/
|
||||||
class P2pSupplicantConfiguration(private val group: WifiP2pGroup, ownerAddress: String?) {
|
class P2pSupplicantConfiguration(private val group: WifiP2pGroup, vararg ownerAddresses: String?) {
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "P2pSupplicantConfiguration"
|
private const val TAG = "P2pSupplicantConfiguration"
|
||||||
private const val CONF_PATH_TREBLE = "/data/vendor/wifi/wpa/p2p_supplicant.conf"
|
private const val CONF_PATH_TREBLE = "/data/vendor/wifi/wpa/p2p_supplicant.conf"
|
||||||
@@ -53,7 +53,8 @@ class P2pSupplicantConfiguration(private val group: WifiP2pGroup, ownerAddress:
|
|||||||
RootSession.checkOutput(command, shell, false, false)
|
RootSession.checkOutput(command, shell, false, false)
|
||||||
val parser = Parser(shell.out)
|
val parser = Parser(shell.out)
|
||||||
try {
|
try {
|
||||||
val bssids = listOfNotNull(group.owner.deviceAddress, ownerAddress, RepeaterService.lastMac)
|
val bssids = (listOf(group.owner.deviceAddress, RepeaterService.lastMac) + ownerAddresses)
|
||||||
|
.filterNotNull()
|
||||||
.distinct()
|
.distinct()
|
||||||
.filter {
|
.filter {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user