rM-docker icon indicating copy to clipboard operation
rM-docker copied to clipboard

WiFi for xochitl

Open yannickulrich opened this issue 1 year ago • 3 comments

Thanks for making this, it seems really useful!

I was hoping to use this to play with the cloud synchronisation (in relation to ddvk/rmfakecloud) but xochitl doesn't work in the absence of wlan0

$ QT_LOGGING_RULES=rm.*=true xochitl
05:43:55.887 rm.wifi                  Connected to netlink
05:43:55.936 rm.wifi                  Changed desired interface state to:  up
05:43:55.992 rm.wifi                  Failed to get interface flags: No such device
...
05:43:56.382 rm.network.httpmanager   RequestId 1: queued up (2 transaction(s) pending) (setupTransaction /__w/xochitl/xochitl/src/network/src/httpmanager.cpp:265)
05:43:56.382 rm.network.httpmanager   RequestId 1: is postponed, because we are offline (setupTransaction /__w/xochitl/xochitl/src/network/src/httpmanager.cpp:275)

Obviously the emulated system does have internet via eth0 but the remarkable refuses to connect to the cloud if it doesn't detect any wifi. Note that it doesn't seem like the wlan0 interface needs to do anything, it just needs to exist.

It might be possible to create a dummy interface but that isn't supported by the kernel config

$ ip link add eth10 type dummy
ip: RTNETLINK answers: Operation not supported

Thanks for your help, any input would be appreciated!

yannickulrich avatar Aug 18 '24 10:08 yannickulrich

Interesting, do you know which kernel options are needed for creating dummy interfaces? Adding it to the configuration changes should be trivial.

timower avatar Sep 05 '24 20:09 timower

Thanks for your reply! I have managed to get the dummy interface working and the tablet connected to a virtual access point (see below) but that doesn't seem quite enough for xochitl to pair. I will investigate this a bit further soon but am currently a bit busy with other things. I'm writing some of this from memory so I might have made small mistakes here or there, will fix them as soon as I can. Once I've worked out how to do this start-to-finish, I'm happy to open a PR as well. Still, let me share already here what I've discovered:

Kernel parameters: faking the hardware

I've enabled the following, I'm not 100% sure all of them are needed as iterative development is a bit annoying when I have to wait 30min between attempts.

  • CONFIG_DUMMY
  • CONFIG_MAC80211_HWSIM
  • CONFIG_VIRT_WIFI

Then I disabled these, can't exactly remember why..

  • CONFIG_SATA_AHCI_PLATFORM
  • CONFIG_AHCI_IMX

hostapd: faking an access point

Next, one needs to compile libnl-tiny (git) and hostapd (tar) for the tablet.

git clone https://git.openwrt.org/project/libnl-tiny.git
curl -o - https://w1.fi/releases/hostapd-2.11.tar.gz | tar xz

I had to patch the former

diff --git a/include/netlink/msg.h b/include/netlink/msg.h
index f034691..26be4b8 100644
--- a/include/netlink/msg.h
+++ b/include/netlink/msg.h
@@ -42,6 +42,9 @@ struct nla_policy;
 #define NL_AUTO_SEQ	0
 
 #define NL_MSG_CRED_PRESENT 1
+struct ucred {
+    uint32_t pid, uid, gid;
+};
 
 struct nl_msg
 {

but it might be possible to engineer around that. Once that's done, compile libnl (again there are probably better ways but this worked for me)

for file in $(ls libnl-tiny/*.c) ; do
    armv7l-unknown-linux-gnueabihf-gcc -Ilibnl-tiny/include -c -o $file.o $file
done
armv7l-unknown-linux-gnueabihf-ar crs libnl-tiny/libnl-tiny.a libnl-tiny/*.o

configure hostapd by creating a file hostapd-2.11/hostapd/.config (change $PWD accordingly for it to find libnl)

CONFIG_LIBNL_TINY=y
CONFIG_DRIVER_HOSTAP=y
CONFIG_DRIVER_NL80211=y
CONFIG_DRIVER_WEXT=y
CONFIG_DRIVER_NDIS=y
CONFIG_DRIVER_WIRED=y
CONFIG_IPV6=y
CONFIG_RSN_PREAUTH=y
CONFIG_TLS=internal
CONFIG_INTERNAL_LIBTOMMATH=y
LIBS=-L$PWD/libnl-tiny
EXTRA_CFLAGS=-I$PWD/libnl-tiny/include
LDFLAGS=-static -static-libgcc
CONFIG_ACS=y

Finally, we compile

make CC=armv7l-unknown-linux-gnueabihf-gcc  -C hostapd-2.11/hostapd

For convenience, I've attached a script that does all of this. Naturally, the resulting hostapd-2.11/hostapd/hostapd needs to be copied to the VM.

Running

First, create a virtual access point by creating a file called hostapd.conf

interface=wlan1
country_code=DE
ssid=Virtual Wifi
channel=0
hw_mode=b
wpa=3
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
wpa_passphrase=12345678
auth_algs=3
beacon_int=100

and copy that over as well. Then simplify execute hostapd

yannickulrich avatar Sep 08 '24 08:09 yannickulrich

It took a bit longer than expected but I think I got the WiFi to work. My solution isn't the prettiest yet and I build and install a bunch of things that are almost certainly not needed. Once I get a minute, I'll try to clean this up a bit and open a PR.

yannickulrich avatar Nov 10 '24 19:11 yannickulrich