194 lines
4.8 KiB
Bash
194 lines
4.8 KiB
Bash
#!/bin/sh
|
|
#
|
|
# Copyright (c) 2023, hanwckf <hanwckf@vip.qq.com>
|
|
#
|
|
|
|
. /lib/netifd/netifd-wireless.sh
|
|
|
|
init_wireless_driver "$@"
|
|
|
|
LOCK_FILE="/tmp/mtwifi.lock"
|
|
|
|
MTWIFI_MAX_AP_IDX=15
|
|
MTWIFI_MAX_APCLI_IDX=0
|
|
MTWIFI_CFG_IFNAME_KEY="mtwifi_ifname"
|
|
|
|
drv_mtwifi_init_device_config() {
|
|
config_add_int txpower beacon_int dtim_period
|
|
config_add_boolean mu_beamformer dbdc_main whnat bandsteering
|
|
config_add_string country twt
|
|
}
|
|
|
|
drv_mtwifi_init_iface_config() {
|
|
config_add_string 'ssid:string' macfilter bssid kicklow assocthres steeringthresold
|
|
config_add_boolean wmm hidden isolate ieee80211k ieee80211r
|
|
config_add_int wpa_group_rekey frag rts
|
|
config_add_array 'maclist:list(macaddr)' 'steeringbssid:list(macaddr)'
|
|
config_add_boolean mumimo_dl mumimo_ul ofdma_dl ofdma_ul amsdu autoba uapsd
|
|
}
|
|
|
|
drv_mtwifi_cleanup() {
|
|
return
|
|
}
|
|
|
|
mtwifi_vif_ap_config() {
|
|
local name="$1"
|
|
local ifname=""
|
|
local disabled=""
|
|
|
|
json_select config
|
|
json_get_var disabled disabled
|
|
json_select ..
|
|
|
|
[ "$disabled" = "1" ] && return
|
|
|
|
json_get_var ifname $MTWIFI_CFG_IFNAME_KEY
|
|
[ -z "$ifname" ] && return
|
|
|
|
# v33: record vif for the deferred physical remap (see
|
|
# mtwifi_deferred_phys_remap). The ra*/rax* <-> PHY binding is random
|
|
# per boot and the second netdev may not exist yet at this point, so
|
|
# the remap runs after setup completes.
|
|
echo "$name $ifname" >> "/tmp/mtwifi_vifs.$MTWIFI_CUR_DEV"
|
|
|
|
logger -t "netifd-mtwifi" "add $ifname to vifidx $name"
|
|
wireless_add_vif "$name" "$ifname"
|
|
}
|
|
|
|
mtwifi_phys_ifname() {
|
|
# Echo the netdev that PHYSICALLY carries the given device's content.
|
|
# The section's dat (l1profile profile_path) always programs its own
|
|
# PHY, and the dat's MacAddress equals the MAC of whichever netdev
|
|
# physically carries it this boot.
|
|
local dat mac n
|
|
dat=$(l1util get "${1//_/.}" profile_path 2>/dev/null)
|
|
[ -f "$dat" ] || return
|
|
mac=$(sed -n 's/^MacAddress=//p' "$dat" | head -1)
|
|
[ -n "$mac" ] || return
|
|
for n in /sys/class/net/ra* /sys/class/net/rax*; do
|
|
[ -f "$n/address" ] || continue
|
|
if [ "$(cat "$n/address")" = "$mac" ]; then
|
|
basename "$n"
|
|
return
|
|
fi
|
|
done
|
|
}
|
|
|
|
mtwifi_deferred_phys_remap() {
|
|
# Re-notify netifd with the physical ifname for each vif of device $1
|
|
# once the netdev shows up, so ubus status (and everything derived
|
|
# from it: LuCI title, freqlist, channel dropdown, bridge membership)
|
|
# matches reality. UCI writes stay section-based and unaffected.
|
|
local dev="$1" vifs="/tmp/mtwifi_vifs.$1"
|
|
local name static_if phys tries=0
|
|
[ -s "$vifs" ] || return
|
|
while [ $tries -lt 45 ]; do
|
|
phys=$(mtwifi_phys_ifname "$dev")
|
|
[ -n "$phys" ] && break
|
|
sleep 1
|
|
tries=$((tries+1))
|
|
done
|
|
[ -n "$phys" ] || return
|
|
while read -r name static_if; do
|
|
[ -n "$name" ] || continue
|
|
[ "$phys" = "$static_if" ] && continue
|
|
logger -t "netifd-mtwifi" "deferred physical remap: $dev $static_if -> $phys"
|
|
__netifd_device="$dev"
|
|
wireless_add_vif "$name" "$phys"
|
|
done < "$vifs"
|
|
rm -f "$vifs"
|
|
}
|
|
|
|
mtwifi_vif_sta_config() {
|
|
local name="$1"
|
|
local ifname=""
|
|
local disabled=""
|
|
|
|
json_select config
|
|
json_get_var disabled disabled
|
|
json_select ..
|
|
|
|
[ "$disabled" = "1" ] && return
|
|
|
|
json_get_var ifname $MTWIFI_CFG_IFNAME_KEY
|
|
|
|
if [ -n "$ifname" ]; then
|
|
logger -t "netifd-mtwifi" "add $ifname to vifidx $name"
|
|
wireless_add_vif "$name" "$ifname"
|
|
fi
|
|
}
|
|
|
|
mtwifi_vif_ap_set_data() {
|
|
local ifname=""
|
|
|
|
if [ ! $AP_IDX -gt $MTWIFI_MAX_AP_IDX ]; then
|
|
ifname="${MTWIFI_AP_IF_PREFIX}${AP_IDX}"
|
|
AP_IDX=$((AP_IDX+1))
|
|
fi
|
|
|
|
json_add_string "$MTWIFI_CFG_IFNAME_KEY" "$ifname"
|
|
}
|
|
|
|
mtwifi_vif_sta_set_data() {
|
|
local ifname=""
|
|
|
|
if [ ! $APCLI_IDX -gt $MTWIFI_MAX_APCLI_IDX ]; then
|
|
ifname="${MTWIFI_APCLI_IF_PREFIX}${APCLI_IDX}"
|
|
APCLI_IDX=$((APCLI_IDX+1))
|
|
fi
|
|
|
|
json_add_string "$MTWIFI_CFG_IFNAME_KEY" "$ifname"
|
|
}
|
|
|
|
drv_mtwifi_setup() {
|
|
ubus -t 120 wait_for network.interface.lan
|
|
|
|
local dev="$1"
|
|
# UCI section names use underscores (e.g., MT7981_1_1) but l1util/l1dat
|
|
# expect dotted names (e.g., MT7981.1.1). Convert before any lookup.
|
|
local dev_dot="${dev//_/.}"
|
|
|
|
json_add_string device "$dev_dot"
|
|
MTWIFI_CUR_DEV="$dev"
|
|
rm -f "/tmp/mtwifi_vifs.$dev"
|
|
|
|
lock $LOCK_FILE
|
|
|
|
logger -t "netifd-mtwifi" "up: $dev ($dev_dot)"
|
|
|
|
MTWIFI_AP_IF_PREFIX="$(l1util get $dev_dot ext_ifname)"
|
|
MTWIFI_APCLI_IF_PREFIX="$(l1util get $dev_dot apcli_ifname)"
|
|
|
|
AP_IDX=0
|
|
for_each_interface ap mtwifi_vif_ap_set_data
|
|
|
|
APCLI_IDX=0
|
|
for_each_interface sta mtwifi_vif_sta_set_data
|
|
|
|
json_dump | /sbin/mtwifi_cfg setup
|
|
|
|
for_each_interface ap mtwifi_vif_ap_config
|
|
for_each_interface sta mtwifi_vif_sta_config
|
|
|
|
wireless_set_up
|
|
|
|
lock -u $LOCK_FILE
|
|
|
|
( mtwifi_deferred_phys_remap "$dev" ) >/dev/null 2>&1 </dev/null &
|
|
}
|
|
|
|
drv_mtwifi_teardown() {
|
|
local dev="$1"
|
|
local dev_dot="${dev//_/.}"
|
|
|
|
lock $LOCK_FILE
|
|
|
|
logger -t "netifd-mtwifi" "down: $dev ($dev_dot)"
|
|
|
|
rm -f "/tmp/mtwifi_vifs.$dev"
|
|
/sbin/mtwifi_cfg down "$dev_dot"
|
|
|
|
lock -u $LOCK_FILE
|
|
}
|
|
|
|
add_driver mtwifi |