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 + diff --git a/installers/apply_profile.sh b/installers/apply_profile.sh new file mode 100755 index 000000000..a0b465176 --- /dev/null +++ b/installers/apply_profile.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# +# 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 config, 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 +SSID="" +PASSPHRASE="" + +if [ -f "$HOSTAPD_CONF" ]; then + 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 +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 "$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 "$PASSPHRASE" ] && [ "$PASSPHRASE" != "ChangeMe" ]; then + sed -i "s/^wpa_passphrase=.*/wpa_passphrase=$PASSPHRASE/" "$HOSTAPD_CONF" + echo "Preserved existing passphrase" +fi + +echo "Successfully applied adapter profile configuration" +exit 0 + diff --git a/installers/common.sh b/installers/common.sh old mode 100644 new mode 100755 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 + 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/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 diff --git a/installers/servicestart.sh b/installers/servicestart.sh index 4e1cfb5a3..a0ae3cab9 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" @@ -42,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]}" diff --git a/installers/update_firewall.sh b/installers/update_firewall.sh old mode 100644 new mode 100755 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 ''; }