Issue #2109

Make the internal WiFi work

Added by Denis 'GNUtoo' Carikli about 1 year ago. Updated 9 days ago.

Target version:
Start date:
Due date:
% Done:


Estimated time:
Porting Replicant to Android 9 (NLnet Foundation)
Type of work:
Any programming languages (scripts, C, etc), C programming

Updated by Denis 'GNUtoo' Carikli about 1 year ago

From #replicant:

23:41 <@sensiblemn> ChronoMonochrome said he got Wifi working


Updated by Denis 'GNUtoo' Carikli about 1 year ago

  • Grant set to Porting Replicant to Android 9 (NLnet Foundation)

Updated by Denis 'GNUtoo' Carikli 11 months ago

  • Target version changed from Replicant 11.0 0001 to Replicant 11.0 0002

Updated by Victor Shilin 6 months ago

Internal wifi worked in replicant 11 (no significant efforts were required to adapt it to Android 11 since it worked in Replicant 9 already):

As Android 11 doesn't properly support kernel modules build, there is an ugly hack in the kernel without which the kernel will try to load the firmware before the system partition mounted:


Updated by _I3^ RELATIVISM 6 months ago

  • Type of work Any programming languages (scripts, C, etc), C programming added

Updated by Denis 'GNUtoo' Carikli 10 days ago

Thanks a lot,

I had the same issue that 56630895e967c78a4f7e45d869166b8418c96f6b fixes in MidasMainline (HACK: brcmfmac: defer initialization for firmware to load).

In Replicant 6 the WiFi module was loaded with insmod / modprobe anyway so it could avoid that but here we'd rather not do that as:
  • The way to build Linux in Replicant 11 doesn't support modules yet either. I half-backported the kernel build from LineageOS and I disabled the modules builds along the way to make the integration easier. Do you know a cleaner implementation (still without the modules building)?
  • It would be better not to load any modules right now as it would makes the images less generic. The downside of doing that it that the kernel images will use a bit more RAM.
  • Android is probably not meant to have modules autodetected and loaded like in GNU/Linux with udev / mdev / systemd.

So I tried to find a way to get something upstreamable, but it seems that late_initcall and late_initcall_sync don't wait for the rootfs to be mounted.

I digged more and I didn't find anything that would tell a driver to wait for the rootfs to be mounted as the code that does the mounts the rootfs (in init/main.c and init/do_mounts.c) doesn't signal it to the drivers.

We could still have userspace code trigger the driver probe again with a generic version of that code in the meantime:

echo 'mmc1:0001:2' > /sys/bus/sdio/drivers_probe

We could probably autodetect what to echo where somehow.

I then need to integrate the MidasMainline userspace changes into Replicant.

Also I tried to make usbip work to forward ath9k_htc cards for easy testing (including with multiple WiFi cards) but apparently enabling the modules required for usbip in the kernel configuration makes the device not expose adb anymore.

This is probably because we use a kernel approach to have ADB. We should probably move that to userspace setup scripts instead at some point.


edit1: add question about kernel build implementation


Updated by Denis 'GNUtoo' Carikli 10 days ago

I wrote:

We could still have userspace code trigger the driver probe again with a generic version of that code in the meantime:

It's probably a better idea to send a bugreport first than trying to workaround in userspace.

I'll try to reproduce with the lastest git revision and send a bugreport.


Updated by Denis 'GNUtoo' Carikli 10 days ago

I've sent the question to the linux-wireless mailing list:


Updated by Denis 'GNUtoo' Carikli 9 days ago

I wanted to use a stock and standard wpa_supplicant compatible WiFi HAL.

In frameworks/opt/net/wifi/libwifi_hal/ we have:

# Pick a vendor provided HAL implementation library.
# ============================================================
LIB_WIFI_HAL := libwifi-hal-fallback
ifeq ($(BOARD_WLAN_DEVICE), bcmdhd)
  LIB_WIFI_HAL := libwifi-hal-bcm
else ifeq ($(BOARD_WLAN_DEVICE), qcwcn)
  LIB_WIFI_HAL := libwifi-hal-qcom
else ifeq ($(BOARD_WLAN_DEVICE), mrvl)
  # this is commented because none of the nexus devices
  # that sport Marvell's wifi have support for HAL
  # LIB_WIFI_HAL := libwifi-hal-mrvl
else ifeq ($(BOARD_WLAN_DEVICE), MediaTek)
  # support MTK WIFI HAL
  LIB_WIFI_HAL := libwifi-hal-mt66xx
else ifeq ($(BOARD_WLAN_DEVICE), realtek)
  # support Realtek WIFI HAL
  LIB_WIFI_HAL := libwifi-hal-rtk
else ifeq ($(BOARD_WLAN_DEVICE), emulator)
  LIB_WIFI_HAL := libwifi-hal-emu


include $(CLEAR_VARS)
LOCAL_MODULE := libwifi-hal-fallback
LOCAL_CFLAGS := $(wifi_hal_cflags)
LOCAL_SRC_FILES := wifi_hal_fallback.cpp
LOCAL_HEADER_LIBRARIES := libhardware_legacy_headers

So far that looks fine and we might think that we need to use the libwifi-hal fallback, however here it's full implementation (in wifi_hal_fallback.cpp in the same directory):

 * Copyright 2016, The Android Open Source Project
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.

#include "hardware_legacy/wifi_hal.h" 

wifi_error init_wifi_vendor_hal_func_table(wifi_hal_fn *fn) {

Also available in: Atom PDF