firmware/src/packages/fff/fff-wireless/files/lib/functions/fff/wireless

123 lines
2.5 KiB
Plaintext

# SPDX-License-Identifier: GPL-3.0-only
#
# Copyright 2016 Tim Niemeyer
# Copyright 2022 Fabian Bläse
wifiListRadio() {
if [ $# -ne "0" ]
then
echo "Usage: wifiListRadio"
return 1
fi
uci -q show wireless | sed -n 's,.*\.\([a-z0-9]*\)=wifi-device,\1,p'
return 0
}
wifiGetFreq() {
if [ $# -ne "1" ]
then
echo "Usage: wifiGetFreq <radio>"
return 1
fi
local radio=$1
# Use uci radio band for switching, since this is always set by firmware (effectively hard-coded)
# Do not use channel, as this might be "auto" for both
[ "$(uci get "wireless.${radio}.band")" = "5g" ] && echo "5" || echo "2"
return 0
}
wifiRadioSupportsOWE() {
if [ $# -ne "1" ]
then
echo "Usage: wifiGetMacIndexDriver <path>"
return 1
fi
local phy=$(ls /sys/devices/$1/ieee80211/ | head -n1)
[ -n "$phy" ] || return 1
local file="/sys/kernel/debug/ieee80211/$phy/hwflags"
grep -q "MFP_CAPABLE" "$file" || return 1
return 0
}
wifiGetMacIndexDriver() {
# adopted from OpenWrt: /lib/netifd/wireless/mac80211.sh -> mac80211_get_addr()
if [ $# -ne "2" ]
then
echo "Usage: wifiGetMacIndexDriver <phy> <index>"
return 1
fi
local phy="$1"
local idx="$(($2 + 1))"
head -n $idx /sys/class/ieee80211/${phy}/addresses | tail -n1
return 0
}
wifiGetMacIndex() {
# adopted from OpenWrt: /lib/netifd/wireless/mac80211.sh -> mac80211_generate_mac()
if [ $# -ne "2" ]
then
echo "Usage: wifiGetMacIndex <path> <index>"
return 1
fi
local phy=$(ls /sys/devices/$1/ieee80211/ | head -n1)
local id="$2"
[ -n "$phy" ] || return 1
local ref="$(cat /sys/class/ieee80211/${phy}/macaddress)"
local mask="$(cat /sys/class/ieee80211/${phy}/address_mask)"
[ "$mask" = "00:00:00:00:00:00" ] && {
mask="ff:ff:ff:ff:ff:ff";
[ "$(wc -l < /sys/class/ieee80211/${phy}/addresses)" -gt $id ] && {
addr="$(wifiGetMacIndexDriver "$phy" "$id")"
[ -n "$addr" ] && {
echo "$addr"
return 0
}
}
}
local oIFS="$IFS"; IFS=":"; set -- $mask; IFS="$oIFS"
local mask1=$1
local mask6=$6
local oIFS="$IFS"; IFS=":"; set -- $ref; IFS="$oIFS"
macidx=$(($id + 1))
[ "$((0x$mask1))" -gt 0 ] && {
b1="0x$1"
[ "$id" -gt 0 ] && \
b1=$(($b1 ^ ((($id - !($b1 & 2)) << 2)) | 0x2))
printf "%02x:%s:%s:%s:%s:%s" $b1 $2 $3 $4 $5 $6
return
}
[ "$((0x$mask6))" -lt 255 ] && {
printf "%s:%s:%s:%s:%s:%02x" $1 $2 $3 $4 $5 $(( 0x$6 ^ $id ))
return
}
off2=$(( (0x$6 + $id) / 0x100 ))
printf "%s:%s:%s:%s:%02x:%02x" \
$1 $2 $3 $4 \
$(( (0x$5 + $off2) % 0x100 )) \
$(( (0x$6 + $id) % 0x100 ))
return 0
}
# vim: set noexpandtab:tabstop=4