Project

General

Profile

Actions

Issue #2109

closed

Make the internal WiFi work

Added by Denis 'GNUtoo' Carikli about 4 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Normal
Category:
Wi-Fi
Target version:
Start date:
08/25/2020
Due date:
% Done:

0%

Estimated time:
Resolution:
fixed
Device:
Galaxy S 3 (I9300)
Grant:
Porting Replicant to Android 9 (NLnet Foundation)
Type of work:
Any programming languages (scripts, C, etc), Build system integration, C programming
Actions #1

Updated by Denis 'GNUtoo' Carikli about 4 years ago

From #replicant:

23:41 <@sensiblemn> ChronoMonochrome said he got Wifi working https://github.com/CustomROMs/android_local_manifests_i9300/issues/1#issuecomment-678714702

Actions #2

Updated by Denis 'GNUtoo' Carikli about 4 years ago

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

Updated by Denis 'GNUtoo' Carikli almost 4 years ago

  • Target version changed from Replicant 11.0 0001 to Replicant 11.0 0002
Actions #4

Updated by Victor Shilin over 3 years 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):
https://github.com/Midas-Mainline/android_device_samsung_i9300/commit/376bca58403a3e187ec89e2217e782ce754bea22
https://github.com/Midas-Mainline/android_device_midas_common/commit/e65d0596187804c5b74f3e91eeba4c5f80c3600f

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:
https://github.com/Midas-Mainline/android_kernel_samsung_smdk4412/commit/e93cf91b073f44745f9e78307352bca6bddc11f7

Actions #5

Updated by _I3^ RELATIVISM over 3 years ago

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

Updated by Denis 'GNUtoo' Carikli about 3 years 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.

Denis.

edit1: add question about kernel build implementation

Actions #7

Updated by Denis 'GNUtoo' Carikli about 3 years 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.

Actions #8

Updated by Denis 'GNUtoo' Carikli about 3 years ago

I've sent the question to the linux-wireless mailing list: https://marc.info/?l=linux-wireless&m=163097506203321&w=2

Actions #9

Updated by Denis 'GNUtoo' Carikli about 3 years ago

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

In frameworks/opt/net/wifi/libwifi_hal/Android.mk we have:

# Pick a vendor provided HAL implementation library.
# ============================================================
LIB_WIFI_HAL := libwifi-hal-fallback
VENDOR_LOCAL_SHARED_LIBRARIES :=
ifeq ($(BOARD_WLAN_DEVICE), bcmdhd)
  LIB_WIFI_HAL := libwifi-hal-bcm
  VENDOR_LOCAL_SHARED_LIBRARIES := libcrypto
else ifeq ($(BOARD_WLAN_DEVICE), qcwcn)
  LIB_WIFI_HAL := libwifi-hal-qcom
  VENDOR_LOCAL_SHARED_LIBRARIES := libcld80211
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
endif

And:

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

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
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * 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) {
  return WIFI_ERROR_NOT_SUPPORTED;
}

Actions #10

Updated by Denis 'GNUtoo' Carikli about 3 years ago

  • Category set to Wi-Fi
  • Device Galaxy S 3 (I9300) added
  • Device deleted (Unknown)
  • Type of work Build system integration added

I've now managed to make the userspace stack work.

To make it work I had to make an access point with another existing smartphone (it was running Replicant 6.0 with the nonfree WiFi firmwares) and have both phones be really close to each other (both were touching, one was on the left and the other on the right both in portrait mode).

We probably need to fix that upstream as PostmarketOS has the exact same issue.

BTW, to detect if an interface is compatible with WiFi, the WiFi HAL (in hardware/replicant/wlan) it looks if the device name starts with "wlan". We probably need to fix it somehow in the future to make the code more robust.

BTW, thanks a lot to the people on #postmarketos-mainline in OFTC for the tip on having both devices be really close. To create the access point I instead had a more classical setup with hostapd and an ath9k WiFi card on GNU/Linux.

Actions #11

Updated by Denis 'GNUtoo' Carikli about 3 years ago

  • Resolution set to fixed
Actions #12

Updated by Denis 'GNUtoo' Carikli about 3 years ago

  • Status changed from New to Closed
Actions #13

Updated by Denis 'GNUtoo' Carikli about 3 years ago

Ah I forgot: it was tested with a GT-I9300, and wasn't tested yet with a GT-I9305.

Actions

Also available in: Atom PDF