Jump to content

WiFi

From postmarketOS Wiki
Revision as of 22:36, 22 January 2020 by Bonsaiblue (talk | contribs)

General information

To get wireless LAN working, most WiFi chips need a proprietary firmware blob. While it would be more secure to replace that with open source software in the long term, it isn't feasible right now, so we try to get it working with that closed source firmware.
A great place to start looking for information about many available WiFi chips is this kernel.org page. It often provides driver sources and the required firmware blobs as well. For a start if you want Internet working try the USB Internet guide.

Note Instead of mounting Android's firmware partition, we package the files ourselves (see the FAQ).

Useful links:

Qualcomm WiFi

Devices with Qualcomm WiFi chips are usually very easy to get working.

You need to find the firmware files for your device, the main file is called wcnss.mdt and there should also be more files which are called wcnss.b00, wcnss.b01, etc. Copy them all onto your device info /lib/firmware/postmarketos.

Then you can run as root echo 1 > /dev/wcnss_wlan and echo sta > /sys/module/wlan/parameters/fwpath. Check the output of ip link and a wlan0 interface should have appeared! Now you can use NetworkManager to connect to a WiFi!

If that didn't work, please check the debugging section how to find out what went wrong.

For packaging, see that page and add the wcnss-wlan package (which runs the two commands above at boot automatically) as a dependency to the WiFi subpackage.

Test your packaging by flashing a new rootfs which includes your changes and see if WiFi works without any manual configuration.

Broadcom WiFi

TODO TODO: This section needs expansion.

Devices with Broadcom WiFi chips usually have the path to the firmware hardcoded in the kernel, mostly to /system/vendor/firmware.

In most cases you should be able to set CONFIG_BCMDHD_FW_PATH and CONFIG_BCMDHD_NVRAM_PATH in the kernel config. In other cases, you need to patch the kernel and change the path to /lib/firmware/postmarketos (see this patch.

You can use the command git grep "lib/firmware/postmarketos" device/linux-* in pmaports to find how it's done for other devices.

An example of how Broadcom was made to work can be found at Samsung_Galaxy_S_Advance_(samsung-i9070)#How_drebrez_made_wifi_work and in the corresponding GitHub pull request. Another example is Medion_Lifetab_S9714_(medion-kai)#How_bonsaiblue_made_wifi_work.

Mediatek WiFi

TODO TODO: No device with a Mediatek SoC actually has WiFi working yet. Further debugging is needed to get it working.

Devices with Mediatek WiFi chips are much more complicated to get working. On MT6589 devices, there is a tool called 6620_launcher which (probably) loads the firmware from the filesystem into the kernel. This tool is a binary included in the Android installation and linked against the bionic libc. There is a source code version of the tool available which can be compiled on a normal Linux system. On the Fairphone 1, the order for initialization should be the following (based on the init.rc files from Android):

# Install the files mt6628_ant_m1.cfg mt6628_patch_e1_hdr.bin mt6628_patch_e2_0_hdr.bin mt6628_patch_e2_1_hdr.bin WIFI_RAM_CODE_MT6628 WMT.cfg into /system/etc/firmware/ (path could be patched in the kernel sources)
insmod mtk_hif_sdio.ko
insmod mtk_stp_wmt.ko
insmod mtk_stp_uart.ko
insmod mtk_stp_gps.ko
insmod mtk_stp_bt.ko
insmod mtk_wmt_wifi.ko

mknod /dev/stpwmt c 190 0
mknod /dev/stpgps c 191 0
mknod /dev/stpbt  c 192 0
mknod /dev/wmtWifi c 153 0

insmod wlan_mt6628.ko

6620_launcher -p /system/etc/firmware/

echo 1 > /dev/wmtWifi

The MediaDeb project has made systemd unit files running more or less the commands above on two of their supported devices:

  • wifi_loader.service: runs mt6620_loader.sh (which does mknod) & runs wifi_loader bin
  • mt6620_launcher.service: runs 6620_launcher (/usr/sbin/6620_launcher -b 4000000 -p /lib/firmware/ -d /dev/ttyMT2)
  • wifi.service: runs echo 1 > /dev/wmtWifi

Debugging

First check, if the network interface is available by running ip link (wlan0 on most phones).

If the network interface is not listed and you've followed the section for your WiFi chip above, it's most likely an error of missing or misplaced firmware files:

  • dmesg
  • tail /var/log/firmwareload.log

In case you need any more help, just ask in our Matrix/IRC channel!

Connecting to APs

Using NetworkManager

You can use NetworkManager from the command line either with nmtui (a terminal user interface) or nmcli.

To use nmtui, just run sudo nmtui in your terminal.

To use nmcli, you can use the following commands, modified for your use case:

$ sudo nmcli device wifi list ifname wlan0
$ sudo nmcli device wifi connect "$SSID" password "$PASSWORD" ifname wlan0

Using wpa_supplicant

Note In most cases using NetworkManager is preferred!
Note You might need to set your wlan interface to unmanaged in NetworkManager or stop NetworkManager to configure it manually.

postmarketOS currently configures the wpa_supplicant service to start on boot. This service will fail to start unless /etc/wpa_supplicant/wpa_supplicant.conf has been defined. This can be configured using the wpa_passphrase utility:

$ wpa_passphrase YOUR_SSID YOUR_PASSPHRASE | sudo tee /etc/wpa_supplicant/wpa_supplicant.conf

Note: If you are connecting to a hidden wireless network, make sure to add line "scan_ssid=1" after the ssid line in your generated conf file

Next you'll need to set up the networking service by adding interfaces to /etc/network/interfaces. In some cases, the loopback device may need to precede the wlan interface:

auto lo 
iface lo inet loopback 
auto wlan0 
iface wlan0 inet dhcp

Finally, set the networking service to start on boot:

$ sudo rc-update add networking default

Note that on some systems (e.g. the RX51 [this seems not to be required on RX-51 as of 16th May 2018 but YMMV]) you may have to configure wpa_supplicant to use the Linux kernel wireless extensions by editing /etc/conf.d/wpa_supplicant:

wpa_supplicant_args="-Dwext"

You will have to reboot, or manually restart the aforementioned services, before your device will connect to the access point.

Using wpa_supplicant (manually)

If you experience problems or just want to test wifi you can start wpa supplicant (using -Dwext or nl80211 driver) and the dhcp service:

sudo wpa_supplicant -u -Dnl80211 -B -c /etc/wpa_supplicant/wpa_supplicant.conf -iwlan0
sudo udhcpc -i wlan0

See also