Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discuss ways to improve Virtual Wifi #791

Open
lurenJBD opened this issue Nov 26, 2024 · 4 comments
Open

Discuss ways to improve Virtual Wifi #791

lurenJBD opened this issue Nov 26, 2024 · 4 comments

Comments

@lurenJBD
Copy link

Regarding the Virtual Wifi implementation, it's all based on the mac80211_hwsim kernel module.

By creating two virtual wifi devices, wlan0 and wlan1, and adding namespace divisions to differentiate between main and router, so you can simulate a wireless AP and a wifi receiver.

Here's the structure.

Clip_2024-11-26_21-56-37

But this method has been abandoned at AOSP13

72ff3aa0df2531d03a8d1d607785f9f0

There is actually a better solution now, using the virt_wifi kernel module.

Masquerade a wired network card as a wireless network card

I tried it in Ubuntu 22.04, it does work.

sudo modprobe virt_wifi
sudo ip link set enp0s1 down
sudo ip link set enp0s1 name wifi_eth
sudo ip link set wifi_eth up
sudo ip link add link wifi_eth name wlan0 type virt_wifi

Clip_2024-11-26_22-08-13

Clip_2024-11-26_22-09-00

But I don't know the Android source code well enough to figure out how to implement it, although I've looked at the code for blissOS

https://github.com/BlissRoms-x86/device_generic_common/blob/6017b7d8071e148623efca41531fc1c5ff2a6092/init.sh#L49
https://github.com/BlissRoms-x86/device_generic_common/blob/6017b7d8071e148623efca41531fc1c5ff2a6092/init.x86.rc#L92

I tried to run these commands in redroid, and it does create wlan0, but this causes adb to be inaccessible, so there's no way to tell if the wifi is working properly

I think I also need to fix the wifi autoconnect to keep adb accessible, because by running these commands, the only network eth0 in the container is changed to wifi_eth, which in turn Android assumes there is no network connection.

@rtedpro-cpu
Copy link

Maybe try creating a docker network and then assigning it to the container and then try that way

@ice-black-tea
Copy link

Here is my redroid WiFi solution, which relies on the mac80211_hwsim kernel module. I have currently abandoned creating a router namespace, and the WiFi is running correctly. I think replacing it with the virt_wifi module should also work properly.

image

@lurenJBD
Copy link
Author

Here is my redroid WiFi solution, which relies on the mac80211_hwsim kernel module. I have currently abandoned creating a router namespace, and the WiFi is running correctly. I think replacing it with the virt_wifi module should also work properly.

good job!

I investigated the virt_wifi module and if need to change the name of the virtual wifi hotspot, need to make changes to the source code, which is a bit of a pain

https://github.com/torvalds/linux/blob/master/drivers/net/wireless/virtual/virt_wifi.c#L139

@lurenJBD
Copy link
Author

Here is my redroid WiFi solution, which relies on the mac80211_hwsim kernel module. I have currently abandoned creating a router namespace, and the WiFi is running correctly. I think replacing it with the virt_wifi module should also work properly.

I'm trying to replace the mac80211_hwsim kernel module with virt_wifi kernel module.

rmmod mac80211_hwsim
modprobe virt_wifi

Then I modified init.redroid.net.sh

diff --git a/network/init.redroid.net.sh b/network/init.redroid.net.sh
index 37e273d..d39882f 100755
--- a/network/init.redroid.net.sh
+++ b/network/init.redroid.net.sh
@@ -95,7 +54,9 @@ if [ "$redroid_wifi" -eq "1" -o "$redroid_radio" -eq "1" ]; then
   /system/bin/ip route add default via ${eth0_gw} dev veth0

   if [ "$redroid_wifi" -eq "1" ]; then
-    init_wlan
+    #init_wlan
+    /system/bin/ip link add link veth0 name wlan0 type virt_wifi
+    /system/bin/ip link set wlan0 up
   fi

After that I started the redroid container and indeed I could access the android interface via scrcpy. But when I try to start the wifi it doesn't start successfully.

This is the logcat log.

12-21 10:26:59.358   382   481 I WifiVendorHal: Vendor Hal started successfully
12-21 10:26:59.359   140   140 W [email protected]: No active wlan interfaces in use! Using default
12-21 10:26:59.359   140   140 E [email protected]: Unknown iface name: wlan0
12-21 10:26:59.359   140   140 E [email protected]: Unknown iface name: wlan0
12-21 10:26:59.360   140   140 I [email protected]: Adding interface handle for wlan0
12-21 10:26:59.360   140   140 W [email protected]: No active wlan interfaces in use! Using default
12-21 10:26:59.360   140   140 E [email protected]: Failed to register radio mode change callback
12-21 10:26:59.360   140   140 W [email protected]: No active wlan interfaces in use! Using default
12-21 10:26:59.360   382   410 I EthernetTracker: interfaceLinkStateChanged, iface: wlan0, up: false
12-21 10:26:59.360   140   140 I [email protected]: Configured chip in mode 0
12-21 10:26:59.360   140   140 W [email protected]: No active wlan interfaces in use! Using default
12-21 10:26:59.360   382   481 D HalDevMgr: updateRttController: no one is interested in RTT controllers
12-21 10:26:59.360   140   140 I [email protected]: Adding interface handle for wlan0
12-21 10:26:59.360   140   140 E [email protected]: Failed to set DFS flag; DFS channels may be unavailable.
12-21 10:26:59.361   382   481 D WifiNl80211Manager: Setting up interface for client mode: wlan0
12-21 10:26:59.361   205   205 I wificond: No wiphy is found
12-21 10:26:59.361   205   205 E wificond: Failed to get wiphy index
12-21 10:26:59.361   382   481 E WifiNl80211Manager: Could not get IClientInterface instance from wificond
12-21 10:26:59.361   382   481 E WifiNative: Failed to setup iface in wificond=wlan0
12-21 10:26:59.362   140   140 I [email protected]: Adding interface handle for wlan0
12-21 10:26:59.362   140   140 W [email protected]: No active wlan interfaces in use! Using default
12-21 10:26:59.362   382   481 E WifiNative: Failed to unregister network observer on Iface:{Name=wlan0,Id=13,Type=STA_SCAN}
12-21 10:26:59.362   382   481 E WifiNl80211Manager: No valid wificond client interface handler for iface=wlan0
12-21 10:26:59.362   382   481 E WifiNative: Failed to teardown iface in wificond on Iface:{Name=wlan0,Id=13,Type=STA_SCAN}
12-21 10:26:59.362   382   481 D WifiNl80211Manager: tearing down interfaces in wificond
12-21 10:26:59.362   140   140 I [email protected]: Legacy HAL stop complete callback received
12-21 10:26:59.362   382   410 I EthernetTracker: interfaceLinkStateChanged, iface: wlan0, up: false
12-21 10:26:59.362   140   140 I [email protected]: Wifi HAL stopped
12-21 10:26:59.363   382   481 I WifiVendorHal: Vendor Hal stopped
12-21 10:26:59.363   382   481 I WifiNative: Successfully torn down Iface:{Name=wlan0,Id=13,Type=STA_SCAN}
12-21 10:26:59.363   382   481 I WifiNative: Successfully initiated teardown for iface=wlan0
12-21 10:26:59.363   382   481 E WifiClientModeManager[unknown]: Failed to create ClientInterface. Sit in Idle
12-21 10:26:59.363   382   481 E WifiActiveModeWarden: ClientModeManager start failed!ConcreteClientModeManager{id=2047209 iface=null role=null}
12-21 10:26:59.363   382   481 D WifiScanRequestProxy: Sending scan available broadcast: false
12-21 10:26:59.363   382   485 I WifiScanningService: Received a request to disable scanning, UID = 1000
12-21 10:26:59.363   382   481 I WifiScanRequestProxy: Scanning is disabled
12-21 10:26:59.363   382   485 I WifiScanningService: wifi driver unloaded
12-21 10:26:59.363   382   481 D WifiController: STA disabled, return to DisabledState.
12-21 10:26:59.363   382   481 D WifiController: EnabledState.exit()
12-21 10:26:59.363   382   481 D WifiController: DisabledState.enter()

Then I checked the NIC device information in the shell

:/ # ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: veth0@if7: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether bc:24:11:f6:b9:e5 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 192.168.1.100/24 brd 192.168.1.255 scope global veth0
       valid_lft forever preferred_lft forever
    inet6 fe80::be24:11ff:fef6:b9e5/64 scope link tentative 
       valid_lft forever preferred_lft forever
3: wlan0@veth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
    link/ether bc:24:11:f6:b9:e5 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::be24:11ff:fef6:b9e5/64 scope link tentative 
       valid_lft forever preferred_lft forever

:/ # ifconfig -a
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0 
          inet6 addr: ::1/128 Scope: Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:2 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000 
          RX bytes:80 TX bytes:80 

veth0     Link encap:Ethernet  HWaddr bc:24:11:f6:b9:e5
          inet addr:192.168.1.100  Bcast:192.168.1.255  Mask:255.255.255.0 
          inet6 addr: fe80::be24:11ff:fef6:b9e5/64 Scope: Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:70 errors:0 dropped:3 overruns:0 frame:0 
          TX packets:41 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000 
          RX bytes:18123 TX bytes:7035 

wlan0     Link encap:Ethernet  HWaddr bc:24:11:f6:b9:e5
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000 
          RX bytes:0 TX bytes:0 

Tried to manually start the wlan0 device, but it didn't work

:/ # /system/bin/ip link set wlan0 up
:/ # /system/bin/ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: veth0@if7: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether bc:24:11:f6:b9:e5 brd ff:ff:ff:ff:ff:ff link-netnsid 0
3: wlan0@veth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
    link/ether bc:24:11:f6:b9:e5 brd ff:ff:ff:ff:ff:ff
:/ # ifconfig wlan0 up
:/ # /system/bin/ip link                                                                                                                                 
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: veth0@if7: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether bc:24:11:f6:b9:e5 brd ff:ff:ff:ff:ff:ff link-netnsid 0
3: wlan0@veth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000
    link/ether bc:24:11:f6:b9:e5 brd ff:ff:ff:ff:ff:ff

Maybe I'm missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants