From a1a11dceb96b464ba28843313edd54682427b59f Mon Sep 17 00:00:00 2001 From: billz Date: Sat, 3 Jan 2026 02:47:39 +0100 Subject: [PATCH 1/8] Initial commit --- installers/detect_adapter.sh | 62 ++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 installers/detect_adapter.sh diff --git a/installers/detect_adapter.sh b/installers/detect_adapter.sh new file mode 100755 index 000000000..b4f83f472 --- /dev/null +++ b/installers/detect_adapter.sh @@ -0,0 +1,62 @@ +#!/bin/bash +# +# RaspAP wireless adapter hardware detection +# Author: @billz +# Author URI: https://github.com/billz/ +# License: GNU General Public License v3.0 +# License URI: https://github.com/raspap/raspap-webgui/blob/master/LICENSE +# +# Usage: detect_adapter.sh +# Exit codes: 0=detected, 1=not found, 2=error +# +# Example output: +# INTERFACE=wlan1 +# DRIVER=mt7921u +# VENDOR_ID=0e8d +# ADAPTER_PROFILE=hostapd-mt7921u-ax.conf +# DETECTED=true + +INTERFACE="${1:-wlan0}" + +# Check if interface exists +if [ ! -d "/sys/class/net/$INTERFACE" ]; then + echo "ERROR: Interface $INTERFACE does not exist" >&2 + exit 2 +fi + +# Check if interface is wireless +if [ ! -d "/sys/class/net/$INTERFACE/wireless" ]; then + echo "ERROR: $INTERFACE is not a wireless interface" >&2 + exit 2 +fi + +# Fetch udev properties +UDEV_INFO=$(udevadm info "/sys/class/net/$INTERFACE" 2>/dev/null) +if [ $? -ne 0 ]; then + echo "ERROR: Failed to get udev info for $INTERFACE" >&2 + exit 2 +fi + +DRIVER=$(echo "$UDEV_INFO" | grep -oP 'E: ID_NET_DRIVER=\K.*' | head -1) +VENDOR_ID=$(echo "$UDEV_INFO" | grep -oP 'E: ID_VENDOR_ID=\K.*' | head -1) +MODEL_ID=$(echo "$UDEV_INFO" | grep -oP 'E: ID_MODEL_ID=\K.*' | head -1) +VENDOR_NAME=$(echo "$UDEV_INFO" | grep -oP 'E: ID_VENDOR_FROM_DATABASE=\K.*' | head -1) + +# Output results as key-value pairs +echo "INTERFACE=$INTERFACE" +echo "DRIVER=${DRIVER:-unknown}" +echo "VENDOR_ID=${VENDOR_ID:-unknown}" +echo "MODEL_ID=${MODEL_ID:-unknown}" +echo "VENDOR_NAME=${VENDOR_NAME:-unknown}" + +# Detect mt7921u driver, assign profile +if [ "$DRIVER" = "mt7921u" ]; then + echo "ADAPTER_PROFILE=hostapd-mt7921u-ax.conf" + echo "DETECTED=true" + exit 0 +fi + +# No profile detected +echo "DETECTED=false" +exit 1 + From e5acb405ad216402e36e7c160c9468e77136998c Mon Sep 17 00:00:00 2001 From: billz Date: Sat, 3 Jan 2026 02:50:27 +0100 Subject: [PATCH 2/8] Initial commit --- installers/apply_profile.sh | 66 +++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 installers/apply_profile.sh diff --git a/installers/apply_profile.sh b/installers/apply_profile.sh new file mode 100644 index 000000000..73470b8a5 --- /dev/null +++ b/installers/apply_profile.sh @@ -0,0 +1,66 @@ +#!/bin/bash +# +# RaspAP adapter profile application +# Author: @billz +# Author URI: https://github.com/billz +# Project URI: https://github.com/RaspAP/ +# License: GNU General Public License v3.0 +# License URI: https://github.com/RaspAP/raspap-webgui/blob/master/LICENSE +# +# Applies adapter-specific hostapd configuration while preserving user settings +# +# Usage: apply_profile.sh + +INTERFACE="$1" +PROFILE_PATH="$2" +HOSTAPD_CONF="/etc/hostapd/hostapd.conf" +BACKUP_CONF="/etc/hostapd/hostapd.conf.backup" + +# Validate parameters +if [ -z "$INTERFACE" ] || [ -z "$PROFILE_PATH" ]; then + echo "ERROR: Missing required parameters" >&2 + echo "Usage: $0 " >&2 + exit 1 +fi + +# Check if profile exists +if [ ! -f "$PROFILE_PATH" ]; then + echo "ERROR: Profile not found: $PROFILE_PATH" >&2 + exit 1 +fi + +# Preserve existing SSID and passphrase if hostapd.conf exists +EXISTING_SSID="" +EXISTING_PASSPHRASE="" + +if [ -f "$HOSTAPD_CONF" ]; then + EXISTING_SSID=$(grep -oP '^ssid=\K.*' "$HOSTAPD_CONF" | head -1) + EXISTING_PASSPHRASE=$(grep -oP '^wpa_passphrase=\K.*' "$HOSTAPD_CONF" | head -1) + + cp "$HOSTAPD_CONF" "$BACKUP_CONF" + echo "Backed up existing configuration to $BACKUP_CONF" +fi + +# Copy profile template to hostapd config +cp "$PROFILE_PATH" "$HOSTAPD_CONF" +echo "Applied profile: $PROFILE_PATH" + +# Update interface in config +sed -i "s/^interface=.*/interface=$INTERFACE/" "$HOSTAPD_CONF" +echo "Updated interface to: $INTERFACE" + +# Restore user's SSID if it exists and isn't default +if [ -n "$EXISTING_SSID" ] && [ "$EXISTING_SSID" != "RaspAP" ]; then + sed -i "s/^ssid=.*/ssid=$EXISTING_SSID/" "$HOSTAPD_CONF" + echo "Preserved existing SSID: $EXISTING_SSID" +fi + +# Restore user's passphrase if it exists and isn't default +if [ -n "$EXISTING_PASSPHRASE" ] && [ "$EXISTING_PASSPHRASE" != "ChangeMe" ]; then + sed -i "s/^wpa_passphrase=.*/wpa_passphrase=$EXISTING_PASSPHRASE/" "$HOSTAPD_CONF" + echo "Preserved existing passphrase" +fi + +echo "Successfully applied adapter profile configuration" +exit 0 + From 951fe084d63076f8b8e766650263ee99b3366d70 Mon Sep 17 00:00:00 2001 From: billz Date: Sat, 3 Jan 2026 02:52:34 +0100 Subject: [PATCH 3/8] Detect 802.11ax capable adapter, apply profile --- installers/servicestart.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/installers/servicestart.sh b/installers/servicestart.sh index 4e1cfb5a3..29a3746d2 100755 --- a/installers/servicestart.sh +++ b/installers/servicestart.sh @@ -1,8 +1,18 @@ #!/bin/bash +# +# RaspAP service start script +# +# Author: @billz +# Author URI: https://github.com/billz/ +# License: GNU General Public License v3.0 +# License URI: https://github.com/raspap/raspap-webgui/blob/master/LICENSE +# # When wireless client AP or Bridge mode is enabled, this script handles starting # up network services in a specific order and timing to avoid race conditions. +# Detects wireless adapter hardware and applies adapter-specific configuration. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin +WEBROOT_DIR="/var/www/html" NAME=raspapd DESC="Service control for RaspAP" CONFIGFILE="/etc/raspap/hostapd.ini" @@ -53,6 +63,30 @@ if [ -z "$interface" ]; then fi fi +# Hardware adapter detection +if [ -x "$WEBROOT_DIR/installers/detect_adapter.sh" ]; then + ADAPTER_INFO=$($WEBROOT_DIR/installers/detect_adapter.sh "$interface" 2>/dev/null) + DETECT_STATUS=$? + + if [ $DETECT_STATUS -eq 0 ]; then + eval "$ADAPTER_INFO" + + if [ -n "$ADAPTER_PROFILE" ]; then + PROFILE_PATH="$WEBROOT_DIR/config/$ADAPTER_PROFILE" + + if [ -f "$PROFILE_PATH" ]; then + echo "Detected hardware profile: $ADAPTER_PROFILE" + echo "Applying adapter-specific configuration for $interface..." + + # Apply profile configuration + if [ -x "$WEBROOT_DIR/installers/apply_profile.sh" ]; then + $WEBROOT_DIR/installers/apply_profile.sh "$interface" "$PROFILE_PATH" + fi + fi + fi + fi +fi + echo "Stopping network services..." if [ $OPENVPNENABLED -eq 1 ]; then systemctl stop openvpn-client@client From e85edff305c272c4c88616fdd1d879005827d84d Mon Sep 17 00:00:00 2001 From: billz Date: Sat, 3 Jan 2026 02:53:23 +0100 Subject: [PATCH 4/8] Initial commit: optimal config for mt7921u driver --- config/hostapd-mt7921u-ax.conf | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 config/hostapd-mt7921u-ax.conf diff --git a/config/hostapd-mt7921u-ax.conf b/config/hostapd-mt7921u-ax.conf new file mode 100644 index 000000000..16743c4b2 --- /dev/null +++ b/config/hostapd-mt7921u-ax.conf @@ -0,0 +1,56 @@ +# RaspAP hostapd configuration for Mediatek MT7921 802.11ax / Wi-Fi 6 +# Optimized for mt7921u driver +# This configuration is automatically applied when mt7921u adapter is detected + +# Driver and control interface +driver=nl80211 +ctrl_interface=/var/run/hostapd +ctrl_interface_group=0 + +# Network interface +interface=wlan1 + +# SSID and authentication +ssid=RaspAP +auth_algs=1 +wpa=2 +wpa_key_mgmt=WPA-PSK +wpa_pairwise=CCMP +wpa_passphrase=ChangeMe + +# Country and regulatory +country_code=US +ieee80211d=1 +ieee80211h=0 + +# Channel configuration +hw_mode=a +channel=36 + +# 802.11n HT support +ieee80211n=1 +require_ht=1 +ht_capab=[HT40+][LDPC][SHORT-GI-20][SHORT-GI-40][TX-STBC][RX-STBC1][MAX-AMSDU-7935] + +# 802.11ac VHT support +ieee80211ac=1 +require_vht=1 +vht_capab=[RXLDPC][SHORT-GI-80][TX-STBC-2BY1][RX-STBC-1][MAX-MPDU-11454][MAX-A-MPDU-LEN-EXP7] +vht_oper_chwidth=1 +vht_oper_centr_freq_seg0_idx=42 + +# 802.11ax HE Wi-Fi 6 support +ieee80211ax=1 +he_su_beamformer=1 +he_su_beamformee=1 +he_mu_beamformer=1 +he_bss_color=1 +he_oper_chwidth=1 +he_oper_centr_freq_seg0_idx=42 + +# QoS and WMM +wmm_enabled=1 + +# Beacon and timing +beacon_int=100 + From 75a2c03becd6ad1a91c27781b52a8955efadaef4 Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 4 Jan 2026 19:40:13 +0100 Subject: [PATCH 5/8] Enumerate wireless interfaces + detect adapter --- installers/apply_profile.sh | 0 installers/common.sh | 0 installers/install_feature_clients.sh | 0 installers/install_feature_firewall.sh | 0 installers/servicestart.sh | 74 +++++++++++++++++--------- installers/update_firewall.sh | 0 6 files changed, 49 insertions(+), 25 deletions(-) mode change 100644 => 100755 installers/apply_profile.sh mode change 100644 => 100755 installers/common.sh mode change 100644 => 100755 installers/install_feature_clients.sh mode change 100644 => 100755 installers/install_feature_firewall.sh mode change 100644 => 100755 installers/update_firewall.sh diff --git a/installers/apply_profile.sh b/installers/apply_profile.sh old mode 100644 new mode 100755 diff --git a/installers/common.sh b/installers/common.sh old mode 100644 new mode 100755 diff --git a/installers/install_feature_clients.sh b/installers/install_feature_clients.sh old mode 100644 new mode 100755 diff --git a/installers/install_feature_firewall.sh b/installers/install_feature_firewall.sh old mode 100644 new mode 100755 diff --git a/installers/servicestart.sh b/installers/servicestart.sh index 29a3746d2..a0ae3cab9 100755 --- a/installers/servicestart.sh +++ b/installers/servicestart.sh @@ -52,7 +52,55 @@ if [ -r "$CONFIGFILE" ]; then done < "$CONFIGFILE" fi -# Set interface from config if not set by parameter +# Detect mt7921u adapter on any wireless interface +MT7921U_DETECTED=0 +if [ -z "$interface" ] && [ -x "$WEBROOT_DIR/installers/detect_adapter.sh" ]; then + echo "Scanning for mt7921u compatible adapter..." + + # Find all wireless interfaces + for iface in /sys/class/net/*/wireless; do + if [ -d "$iface" ]; then + iface_name=$(basename $(dirname "$iface")) + + ADAPTER_INFO=$($WEBROOT_DIR/installers/detect_adapter.sh "$iface_name" 2>/dev/null) + DETECT_STATUS=$? + + if [ $DETECT_STATUS -eq 0 ]; then + eval "$ADAPTER_INFO" + + if [ "$DRIVER" = "mt7921u" ]; then + echo "Found mt7921u adapter on interface: $iface_name" + interface="$iface_name" + MT7921U_DETECTED=1 + + if [ -n "$ADAPTER_PROFILE" ]; then + PROFILE_PATH="$WEBROOT_DIR/config/$ADAPTER_PROFILE" + + if [ -f "$PROFILE_PATH" ]; then + echo "Detected hardware profile: $ADAPTER_PROFILE" + echo "Applying adapter-specific configuration for $interface..." + + # Apply profile configuration + if [ -x "$WEBROOT_DIR/installers/apply_profile.sh" ]; then + $WEBROOT_DIR/installers/apply_profile.sh "$interface" "$PROFILE_PATH" + fi + fi + fi + + if [ -w "$CONFIGFILE" ]; then + sed -i '/^WifiInterface *= */d' "$CONFIGFILE" + echo "WifiInterface = $iface_name" >> "$CONFIGFILE" + echo "Updated $CONFIGFILE with WifiInterface = $iface_name" + fi + + break + fi + fi + fi + done +fi + +# Set interface from config if not set by parameter or auto-detection if [ -z "$interface" ]; then if [ -n "${config[WifiInterface]}" ]; then interface="${config[WifiInterface]}" @@ -63,30 +111,6 @@ if [ -z "$interface" ]; then fi fi -# Hardware adapter detection -if [ -x "$WEBROOT_DIR/installers/detect_adapter.sh" ]; then - ADAPTER_INFO=$($WEBROOT_DIR/installers/detect_adapter.sh "$interface" 2>/dev/null) - DETECT_STATUS=$? - - if [ $DETECT_STATUS -eq 0 ]; then - eval "$ADAPTER_INFO" - - if [ -n "$ADAPTER_PROFILE" ]; then - PROFILE_PATH="$WEBROOT_DIR/config/$ADAPTER_PROFILE" - - if [ -f "$PROFILE_PATH" ]; then - echo "Detected hardware profile: $ADAPTER_PROFILE" - echo "Applying adapter-specific configuration for $interface..." - - # Apply profile configuration - if [ -x "$WEBROOT_DIR/installers/apply_profile.sh" ]; then - $WEBROOT_DIR/installers/apply_profile.sh "$interface" "$PROFILE_PATH" - fi - fi - fi - fi -fi - echo "Stopping network services..." if [ $OPENVPNENABLED -eq 1 ]; then systemctl stop openvpn-client@client diff --git a/installers/update_firewall.sh b/installers/update_firewall.sh old mode 100644 new mode 100755 From 9a4f8ae0e33ff74fe53dcc4735954d295a7534ac Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 4 Jan 2026 21:42:12 +0100 Subject: [PATCH 6/8] Set textarea property readonly --- templates/dhcp/logging.php | 2 +- templates/hostapd/logging.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/dhcp/logging.php b/templates/dhcp/logging.php index 975b64a3b..9c01122a8 100644 --- a/templates/dhcp/logging.php +++ b/templates/dhcp/logging.php @@ -17,7 +17,7 @@
'.htmlspecialchars($logdata, ENT_QUOTES).''; + echo ''; } else { echo ''; } diff --git a/templates/hostapd/logging.php b/templates/hostapd/logging.php index facd8365f..9a2424806 100644 --- a/templates/hostapd/logging.php +++ b/templates/hostapd/logging.php @@ -14,7 +14,7 @@
'.htmlspecialchars(implode("\n", $logOutput), ENT_QUOTES).''; + echo ''; } else { echo ''; } From 84b7097d7f2e92d43bb4a750c585bf07d823fc68 Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 4 Jan 2026 22:58:04 +0100 Subject: [PATCH 7/8] Add systemd-udev-settle dependency to fix adapter detection on boot --- installers/raspapd.service | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/installers/raspapd.service b/installers/raspapd.service index 776cb16b0..da944b8ba 100644 --- a/installers/raspapd.service +++ b/installers/raspapd.service @@ -12,7 +12,8 @@ [Unit] Description=RaspAP Service Daemon DefaultDependencies=no -After=multi-user.target +After=multi-user.target network.target systemd-udev-settle.service +Wants=network.target systemd-udev-settle.service [Service] Type=oneshot From 10bccb032a0ce528d16ff3c115cc78a72200450f Mon Sep 17 00:00:00 2001 From: billz Date: Mon, 5 Jan 2026 05:30:23 +0100 Subject: [PATCH 8/8] Minor: cleanup --- installers/apply_profile.sh | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/installers/apply_profile.sh b/installers/apply_profile.sh index 73470b8a5..a0b465176 100755 --- a/installers/apply_profile.sh +++ b/installers/apply_profile.sh @@ -1,13 +1,12 @@ #!/bin/bash # -# RaspAP adapter profile application # Author: @billz # Author URI: https://github.com/billz # Project URI: https://github.com/RaspAP/ # License: GNU General Public License v3.0 # License URI: https://github.com/RaspAP/raspap-webgui/blob/master/LICENSE # -# Applies adapter-specific hostapd configuration while preserving user settings +# Applies adapter-specific hostapd config, preserving user settings # # Usage: apply_profile.sh @@ -30,18 +29,18 @@ if [ ! -f "$PROFILE_PATH" ]; then fi # Preserve existing SSID and passphrase if hostapd.conf exists -EXISTING_SSID="" -EXISTING_PASSPHRASE="" +SSID="" +PASSPHRASE="" if [ -f "$HOSTAPD_CONF" ]; then - EXISTING_SSID=$(grep -oP '^ssid=\K.*' "$HOSTAPD_CONF" | head -1) - EXISTING_PASSPHRASE=$(grep -oP '^wpa_passphrase=\K.*' "$HOSTAPD_CONF" | head -1) + SSID=$(grep -oP '^ssid=\K.*' "$HOSTAPD_CONF" | head -1) + PASSPHRASE=$(grep -oP '^wpa_passphrase=\K.*' "$HOSTAPD_CONF" | head -1) cp "$HOSTAPD_CONF" "$BACKUP_CONF" echo "Backed up existing configuration to $BACKUP_CONF" fi -# Copy profile template to hostapd config +# Copy profile template cp "$PROFILE_PATH" "$HOSTAPD_CONF" echo "Applied profile: $PROFILE_PATH" @@ -50,14 +49,14 @@ sed -i "s/^interface=.*/interface=$INTERFACE/" "$HOSTAPD_CONF" echo "Updated interface to: $INTERFACE" # Restore user's SSID if it exists and isn't default -if [ -n "$EXISTING_SSID" ] && [ "$EXISTING_SSID" != "RaspAP" ]; then - sed -i "s/^ssid=.*/ssid=$EXISTING_SSID/" "$HOSTAPD_CONF" - echo "Preserved existing SSID: $EXISTING_SSID" +if [ -n "$SSID" ] && [ "$SSID" != "RaspAP" ]; then + sed -i "s/^ssid=.*/ssid=$SSID/" "$HOSTAPD_CONF" + echo "Preserved existing SSID: $SSID" fi # Restore user's passphrase if it exists and isn't default -if [ -n "$EXISTING_PASSPHRASE" ] && [ "$EXISTING_PASSPHRASE" != "ChangeMe" ]; then - sed -i "s/^wpa_passphrase=.*/wpa_passphrase=$EXISTING_PASSPHRASE/" "$HOSTAPD_CONF" +if [ -n "$PASSPHRASE" ] && [ "$PASSPHRASE" != "ChangeMe" ]; then + sed -i "s/^wpa_passphrase=.*/wpa_passphrase=$PASSPHRASE/" "$HOSTAPD_CONF" echo "Preserved existing passphrase" fi