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

add support for simulating wifi #8

Open
wants to merge 1 commit into
base: lineage-18.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions BoardConfig.mk
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,14 @@ BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE := ext4

# Disable scudo
MALLOC_SVELTE := true

# Wifi.
BOARD_WLAN_DEVICE := emulator
BOARD_HOSTAPD_DRIVER := NL80211
BOARD_WPA_SUPPLICANT_DRIVER := NL80211
#BOARD_HOSTAPD_PRIVATE_LIB := lib_driver_cmd_simulated
#BOARD_WPA_SUPPLICANT_PRIVATE_LIB := lib_driver_cmd_simulated
WPA_SUPPLICANT_VERSION := VER_0_8_X
WIFI_DRIVER_FW_PATH_PARAM := "/dev/null"
WIFI_DRIVER_FW_PATH_STA := "/dev/null"
WIFI_DRIVER_FW_PATH_AP := "/dev/null"
27 changes: 26 additions & 1 deletion device.mk
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,35 @@ PRODUCT_COPY_FILES += \
frameworks/native/data/etc/android.hardware.vulkan.level-1.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.level.xml \
frameworks/native/data/etc/android.hardware.vulkan.version-1_1.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.version.xml \
frameworks/native/data/etc/android.hardware.vulkan.compute-0.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.vulkan.compute.xml \
device/generic/goldfish/wifi/simulated_hostapd.conf:$(TARGET_COPY_OUT_VENDOR)/etc/simulated_hostapd.conf \
device/generic/goldfish/wifi/wpa_supplicant.conf:$(TARGET_COPY_OUT_VENDOR)/etc/wifi/wpa_supplicant.conf \
device/generic/goldfish/wifi/WifiConfigStore.xml:data/misc/wifi/WifiConfigStore.xml \
$(LOCAL_PATH)/init-net.sh:$(TARGET_COPY_OUT_VENDOR)/bin/init-net.sh \
$(LOCAL_PATH)/init.net.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.net.rc \
frameworks/native/data/etc/android.hardware.wifi.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.wifi.xml \
frameworks/native/data/etc/android.hardware.wifi.passpoint.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.wifi.passpoint.xml \
frameworks/native/data/etc/android.hardware.wifi.direct.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.wifi.direct.xml \
frameworks/native/data/etc/android.software.freeform_window_management.xml:system/etc/permissions/android.software.freeform_window_management.xml

# Power
PRODUCT_PACKAGES += \
[email protected] \
sh_vendor \
ip_vendor \
iw_vendor \
[email protected]

PRODUCT_PACKAGES += \
mac80211_create_radios \
createns \
dhcpclient \
execns \
hostapd \
hostapd_nohidl \
netmgr \
wifi_forwarder \
wpa_supplicant

# Remove unwanted packages
PRODUCT_PACKAGES += \
RemovePackages
Expand All @@ -198,7 +221,9 @@ PRODUCT_PACKAGES += \

# Soong
PRODUCT_SOONG_NAMESPACES += \
$(LOCAL_PATH)
$(LOCAL_PATH) \
device/generic/goldfish \
device/generic/goldfish-opengl \

# VNDK
PRODUCT_PACKAGES += \
Expand Down
9 changes: 9 additions & 0 deletions init-net.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/vendor/bin/sh


if [ ! -d /sys/class/net/wlan0 ]; then
/system/bin/ifconfig eth0 down
/system/bin/ip link set eth0 name wifi_eth
/system/bin/ifconfig wifi_eth up
/system/bin/ip link add link wifi_eth name wlan0 type virt_wifi
fi
Comment on lines +4 to +9
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs rework.

  1. Do NOT rename eth0 like that, people will not be happy to have their main ethernet connection be renamed like that.
    • Not to mention that systems can have different names instead of eth0.
      Most distros have nowerdays changed to use eno1 as default for example...
  2. Not all systems have their wifi named wlan0.
    It's better to find an automated way of finding what name the wifi card(s) use.
    Maybe something like:
    wificards=( $(iwconfig 2>/dev/null | grep 'IEEE 802.11' | cut -d ' ' -f 1) )
    for wifi in "${wificards[@]}"; do
     ...
    done

Last but not least, i would prefer it much more to use netdev files to setup this virt_wifi link.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides i don't really understand the need for all this renaming of links anyhow 🤷‍♀️

Copy link

@JamiKettunen JamiKettunen Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that part is to be moved to the host couldn't the virtual wlan setup be handled by the already existing https://github.com/waydroid/waydroid/blob/main/data/scripts/waydroid-net.sh? I'd prefer not adding dependencies on random systemd components for core fixes like "apps not detecting any networking" if that can be avoided

Copy link

@TriMoon TriMoon Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree about the place to move that part.
But strongly disagree with the "random systemd components" with same arguments for usage of non-systemd solutions on a systemd based system which most distro's use these days...

  • Pssttt they already make use of systemd stuff, see waydroid-container.service 😉

If they want to be totally politically correct they should implement all this stuff they do now in scripts, inside a compiled C++ binary that directly calls kernel functions...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The init script is different because that's just the entrypoint and easily replicatable anywhere, if other waydroid parts depend on systemd handling something it'll just be broken elsewhere silently

66 changes: 66 additions & 0 deletions init.net.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@

on post-fs-data
setprop vold.post_fs_data_done 1
mkdir /data/vendor/var 0755 root root
mkdir /data/vendor/var/run 0755 root root
mkdir /data/vendor/var/run/netns 0755 root root
start ranchu-net

on zygote-start
# Create the directories used by the Wireless subsystem
mkdir /data/vendor/wifi 0771 wifi wifi
mkdir /data/vendor/wifi/wpa 0770 wifi wifi
mkdir /data/vendor/wifi/wpa/sockets 0770 wifi wifi

service ranchu-net /vendor/bin/init-net.sh
class late_start
user root
group root wakelock wifi
oneshot
disabled # Started on post-fs-data

service emu_hostapd /vendor/bin/execns router /vendor/bin/hostapd_nohidl /data/vendor/wifi/hostapd/hostapd.conf
user root
group root wifi net_raw net_admin
disabled

service netmgr /vendor/bin/execns router /vendor/bin/netmgr --if-prefix wlan1 --bridge eth0,radio0-peer
user root
group root wifi
disabled

service wifi_forwarder /vendor/bin/wifi_forwarder
user root
group root wifi
disabled

service dhcpclient_rtr /vendor/bin/dhcpclient -i radio0 --no-gateway
user root
group root
disabled

service dhcpclient_wifi /vendor/bin/dhcpclient -i wlan0 --no-gateway
user root
group root
disabled

on property:vendor.network.bridged=1
start dhcpclient_rtr

service dhcpclient_def /vendor/bin/dhcpclient -i eth0 --no-gateway
user root
group root
disabled




service wpa_supplicant /vendor/bin/hw/wpa_supplicant -Dnl80211 -iwlan0 -g@android:wpa_wlan0
interface [email protected]::ISupplicant default
interface [email protected]::ISupplicant default
interface [email protected]::ISupplicant default
interface [email protected]::ISupplicant default
socket wpa_wlan0 dgram 660 wifi wifi
group system wifi inet
oneshot
disabled