I *got* wifi sharing working! (wifi repeating, vpn repeating), need help with dhcp

I desperately want my sailfishOS phone to act as access point from specifically connecting to an existing wifi connection, and then using that connection to be the basis of creating your own wifi access point, colloquial known as “wifi repeating”.

in my investigation, i was able to make some progress on this front.

firstly, i want to address the sentiment that what i am trying to do is not possible, and that i’m wasting my time. this is bluntly false. virtually android smartphone released in the last 14 years supports this functionality (natively supported by the wifi driver).

moving on, i need to address the role of wpa_supplicant in sailfishos startup proccess.
if you are to run the command:
ps aux | grep "wpa_supp"

we see that it is this process is created at startup:
2671 root /usr/sbin/wpa_supplicant -u -c /etc/wpa_supplicant/wpa_supplicant.conf -O/var/run/wpa_supplicant -u -P /var/run/wpa_supplicant.pid

from what i gather, this is responsible for enabling “bgscan”, a process necessary for the wifi device to perform wifi scanning capabilities for the device wlan0.

i had success killing the currently running wpa_supplicant command, and starting 2 new wpa_supplicant commands with different command line arguments. I was able to create a new wifi device called “wlan1” that has the ssid “test_ap”, and the second command restores the original functionality bgscan process needed for wlan0 to connect to wifi.

#create wlan1
/usr/sbin/wpa_supplicant -B -c /tmp/wpa_supplicant_ap.conf -O /var/run/wpa_supplicant -i wlan1

#bring up adapter scanning mechansim on interval bgscan=“simple:30:-45:300” (default)
/usr/sbin/wpa_supplicant -B -u -c /etc/wpa_supplicant/wpa_supplicant.conf -O/var/run/wpa_supplicant -u -P /var/run/wpa_supplicant.pid -i wlan0

in this state, my sailfishos device has created access point, while simultaneously be connected to the internet. In the attached picture, i see on my android 13 device, the “test_ap” access point however if fails to connect to because it fails to obtain an ip address. On my sailfishos device, i am connected to my router’s ssid “4050” and web browsing works as normal.

These are my 2 educated guesses, i am speculating on the further work needed in order for devices to be able to successfully connect to the access point sailfishos is making.

  1. there needs to be some mechanism or command line connman arguments needed for wlan1 to provide a ip address to a connecting wifi device (dhcp). chatgpt also mentioned that potentially a python script can be used instead for this purpose, but i am unsure of this process.

  2. there needs to be defined network routing between wlan0 and wlan1.

output of terminal:

wlan0 Link encap:Ethernet HWaddr 3C:01:EF:F1:D9:88
inet addr:192.168.1.14 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::3e01:efff:fef1:d988/64 Scope:Link
inet6 addr: 240e:3bb:2e77:fb00:3e01:efff:fef1:d988/64 Scope:Global
UP BROADCAST RUNNING MULTICAST DYNAMIC MTU:1500 Metric:1
RX packets:66 errors:0 dropped:0 overruns:0 frame:0
TX packets:87 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3000
RX bytes:8722 (8.5 KiB) TX bytes:7556 (7.3 KiB)

wlan1 Link encap:Ethernet HWaddr 3E:01:EF:78:D9:88
inet addr:192.168.27.1 Bcast:192.168.27.255 Mask:255.255.255.0
inet6 addr: fe80::3c01:efff:fe78:d988/64 Scope:Link
UP BROADCAST RUNNING MULTICAST DYNAMIC MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:3 overruns:0 carrier:0
collisions:0 txqueuelen:3000
RX bytes:0 (0.0 b) TX bytes:460 (460.0 b)

[root@Xperia10III defaultuser]# ping -I wlan1 192.168.1.14
PING 192.168.1.14 (192.168.1.14): 56 data bytes
^C
— 192.168.1.14 ping statistics —
3 packets transmitted, 0 packets received, 100% packet loss
[root@Xperia10III defaultuser]#

i need help creating routes between wlan1 and wlan0.

i have made a bash script (insert below) that replicates all the commands needed in order to get where i am at. Also i want to say that rebooting your device will revert all changes as nothing in my script is permanent.

#script start
rm -f /tmp/wpa_supplicant_ap.conf #ensure file does not exist
echo ‘ctrl_interface=/var/run/wpa_supplicant’ > /tmp/wpa_supplicant_ap.conf
echo ‘ctrl_interface_group=0’ >> /tmp/wpa_supplicant_ap.conf
echo ‘update_config=1’ >> /tmp/wpa_supplicant_ap.conf
echo ‘’ >> /tmp/wpa_supplicant_ap.conf
echo ‘network={’ >> /tmp/wpa_supplicant_ap.conf
echo ’ mode=2’ >> /tmp/wpa_supplicant_ap.conf
echo ’ ssid=“test_ap”’ >> /tmp/wpa_supplicant_ap.conf
echo ’ frequency=2412’ >> /tmp/wpa_supplicant_ap.conf
echo ’ key_mgmt=WPA-PSK’ >> /tmp/wpa_supplicant_ap.conf
echo ’ psk=“12345678”’ >> /tmp/wpa_supplicant_ap.conf
echo ‘}’ >> /tmp/wpa_supplicant_ap.conf

#showcase instance of wpa_supplicant is running
ps aux | grep “wpa_supp”

#kill the instance of wpa_supplicant
pkill wpa_supplicant

iw dev wlan0 interface add wlan1 type __ap addr 12:34:56:78:ab:ce
ifconfig wlan1 192.168.27.1 up #attempting to give it networking

#create wlan1
/usr/sbin/wpa_supplicant -B -c /tmp/wpa_supplicant_ap.conf -O /var/run/wpa_supplicant -i wlan1

#bring up adapter scanning mechansim on interval bgscan=“simple:30:-45:300” (default)
/usr/sbin/wpa_supplicant -B -u -c /etc/wpa_supplicant/wpa_supplicant.conf -O/var/run/wpa_supplicant -u -P /var/run/wpa_supplicant.pid -i wlan0

#toggle wifi on and off (necessary)
dbus-send --system --print-reply --dest=net.connman /net/connman/technology/wifi net.connman.Technology.SetProperty string:“Powered” variant:boolean:false
dbus-send --system --print-reply --dest=net.connman /net/connman/technology/wifi net.connman.Technology.SetProperty string:“Powered” variant:boolean:true

echo “now we see test_ap is online”
#script end

any help and investigation into this matter would be greatly appreciated!

1 Like

If you can get connman with its tethering to handle your new wlan device you’ll get at least dhcp. Not sure about routing but it probably will handle that as well.

1 Like

can you point me in the right direction. i have looked at the man page and i feel lost. :sob:

ok, i will write a update. i was able to connect to the device via the static ip assignment (not using dhcp) :partying_face:.

ip addr add 10.10.0.1/24 dev wlan1
ip link set wlan1 up
iptables -t nat -A POSTROUTING -s 10.10.0.0/16 -o ppp0 -j MASQUERADE

i was following a article on median and changed some command line arguments. the following commands created the 10.10.0.1 subnet for the wlan1 device.

i have edited my script in my original post so you can be at the point where i am.

right now i am 100% focusing on trying to give internet to the wlan1 device. dhcp can come later.

so close.

1 Like

MASQUERADING should happen on wlan0 and you will need to enable ip_forwarding, e.g. with

# sysctl net.ipv4.conf.all.forwarding=1
2 Likes

GOOD NEWS, i figured it out. I got wifi repeating working, with a working internet connection!!! so far it only works with static ip assignment, but this is a big first step!

i made a github repo that contains my working script. Can someone help me investiage DHCP?

8 Likes

Busybox has a builtin DHCP server.

4 Likes

i edited the config file /etc/udhcpd.conf

start   10.10.0.1
end     10.10.0.16
interface       wlan1
option  subnet  255.255.255.0
option  lease   3600
max_leases      15

when i try udhcpc -i wlan1 -s /etc/udhcpd.conf, it does not work when attempting to connect my phone. i ip addr flush dev wlan1 so you do not need to consider the ipp address trying to overlap.

more good news, i updated my github script to now work with a currently active vpn connection. i have added a for loop that looks at interfaces of the ifconfig command, and adds iptables nat rules accordingly iptables -t nat -A POSTROUTING -s 10.10.0.0/16 -o "$iface" -j MASQUERADE

this is super nice because you can now share your vpn as a wireless hotspot to all of your devices.

i highly recommend to install the app qCommand , it makes it very convenient to run scripts from your phone without needing to open a terminal.

2 Likes

Careful!

At least on my system, that file is a symlink:

lrwxrwxrwx    1 root     root            26 May  3  2024 /etc/udhcpd.conf -> /run/usb-moded/udhcpd.conf

So editing that may break access via USB networking.

1 Like

Regarding DHCP I’ld run e.g. tcpdump -i wlan1 in a second terminal while trying to connect. The output will tell you, if udhcpd gets a request, answers it and a lot more. Just tried with udhcpd -f /tmp/xx.conf (wlan0 in my config) and got a lot of logs like 10.10.0.6 belongs to someone... due to another DHCP server on my network.

The interface for external traffic should be in the output of e.g. ip route get 8.8.8.8.

1 Like

what is your opinion to use 3rd party dhcp software? i investigated some leads, like a pure rust 0 dependency dhcp server, or a pure python dhcp server.

i can’t seem to get busy box dhcp to work. the tcpdump does not yeild any meaning results so i am assuming this functionality is bugged as it only scans wlan0 despite me specifying wlan1.

You could try dnsmasq (available from Chum).

Note however that it´s known to break other SFOS native networking stuff.

1 Like

i was able to make a proof of concept dhcp server in a simple python script. in the screenshot provided, we see my android phone was detected and the steps of the dhcp negotiation resulted in a success.

the only caveat is that you need to use a python virtual environment and install the package scapy

i added this to my github repo

i am 50/50 debating to make this whole thing into sailfishos app, it is going to take some work

1 Like