83 lines
1.9 KiB
Bash
Executable File
83 lines
1.9 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# /etc/bewan/lib/phy
|
|
|
|
# Common function used by scripts
|
|
# setparam must be included
|
|
|
|
[ ${PHY_LIB:-0} = 1 ] && return
|
|
|
|
PHY_LIB=1
|
|
|
|
find_phy() {
|
|
phyid=''
|
|
accesstype=''
|
|
|
|
local sw_idx=0
|
|
while [ $sw_idx -lt ${Switch_Count:-0} ]; do
|
|
sw_idx=$(($sw_idx + 1))
|
|
local port_list; eval port_list=\${'Switch_'$sw_idx'_Port_List':-}
|
|
for port_idx in `strip $port_list`; do
|
|
local cur_accesstype cur_phyid port_en
|
|
local LANEthernetInterfaceIdx WANEthernetInterfaceIdx
|
|
local switch='Switch_'$sw_idx
|
|
eval cur_accesstype=\${$switch'_AccessType':-}
|
|
eval port_en=\${$switch'_Port_'$port_idx'_Enable':-0}
|
|
[ $port_en != 1 ] && continue
|
|
eval cur_phyid=\${$switch'_Port_'$port_idx'_PhyId':-}
|
|
[ -z "$cur_phyid" ] && continue
|
|
|
|
if [ "$IFTYPE" = "WANEthernetInterface" ]; then
|
|
eval WANEthernetInterfaceIdx=\${$switch'_Port_'$port_idx'_WANEthernetInterfaceIdx':-}
|
|
if [ "$IFINDEX" = "$WANEthernetInterfaceIdx" ]; then
|
|
phyid=$cur_phyid
|
|
accesstype=$cur_accesstype
|
|
break
|
|
fi
|
|
fi
|
|
|
|
if [ "$IFTYPE" = "LANEthernetInterface" ]; then
|
|
eval LANEthernetInterfaceIdx=\${$switch'_Port_'$port_idx'_LANEthernetInterfaceIdx':-}
|
|
if [ "$IFINDEX" = "$LANEthernetInterfaceIdx" ]; then
|
|
phyid=$cur_phyid
|
|
accesstype=$cur_accesstype
|
|
break
|
|
fi
|
|
fi
|
|
done
|
|
done
|
|
}
|
|
|
|
retrieve_phy_state() {
|
|
local IFTYPE=${1:-}
|
|
local IFINDEX=${2:-}
|
|
|
|
phy_state=0
|
|
|
|
local phyid
|
|
local accesstype
|
|
|
|
find_phy
|
|
if [ ! -z "$phyid" ] && [ ! -z "$accesstype" ]; then
|
|
phy_state=`phyctl $accesstype -p $phyid -L | grep "link ok" | wc -l`
|
|
fi
|
|
}
|
|
|
|
power_updown_phy() {
|
|
local IFTYPE=${1:-}
|
|
local IFINDEX=${2:-}
|
|
local UP=${3:-1}
|
|
|
|
local phyid
|
|
local accesstype
|
|
|
|
find_phy
|
|
if [ ! -z "$phyid" ] && [ ! -z "$accesstype" ]; then
|
|
if [ "$UP" -eq 0 ]; then
|
|
phyctl $accesstype -p $phyid -D
|
|
else
|
|
phyctl $accesstype -p $phyid -r
|
|
fi
|
|
fi
|
|
}
|