1
0
This repository has been archived on 2025-01-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Anderson Luiz Alves 0464e230c1 stock 103961
2017-07-30 16:48:04 -03:00

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
}