OSDN Git Service

init.sh: enable virt_wifi if needed
authorChih-Wei Huang <cwhuang@linux.org.tw>
Thu, 13 Jun 2019 09:08:41 +0000 (17:08 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Thu, 13 Jun 2019 09:08:41 +0000 (17:08 +0800)
Some Android apps are not interested in ethernet devices and would rather
connect to a wireless interface. This patch allows the devices with only
ethernet interface to treat one of its network connections as wireless,
satisfying Android apps's network connection requirements.

The ethernet interface being simulated can be specified by the property
net.virt_wifi. The default is eth0.

The feature is enabled if wlan0 doesn't exist, or VIRT_WIFI=1 is set in
kernel cmdline. To disable it, set VIRT_WIFI=0 kernel cmdline.

init.sh

diff --git a/init.sh b/init.sh
index aee4614..5f09257 100644 (file)
--- a/init.sh
+++ b/init.sh
@@ -44,6 +44,20 @@ function init_misc()
                wifi=$(basename `readlink /sys/class/net/wlan0/device/driver`)
                [ "$wifi" != "wl" ] && rmmod_if_exist wl
        fi
+
+       # enable virt_wifi if needed
+       local eth=`getprop net.virt_wifi eth0`
+       if [ -d /sys/class/net/$eth -a "$VIRT_WIFI" != "0" ]; then
+               if [ -n "$wifi" -a "$VIRT_WIFI" = "1" ]; then
+                       rmmod_if_exist iwlmvm $wifi
+               fi
+               if [ ! -d /sys/class/net/wlan0 ]; then
+                       ifconfig $eth down
+                       ip link set $eth name wifi_eth
+                       ifconfig wifi_eth up
+                       ip link add link wifi_eth name wlan0 type virt_wifi
+               fi
+       fi
 }
 
 function init_hal_audio()