#! /bin/bash
#
# Copyright (C) 2006 by Matthieu CASTET

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

if ! [ -d /sys/bus/usb/drivers/ueagle-atm ]
then
	echo "ueagle-atm isn't loaded"
	exit 1
fi

for DIR in $(ls -d /sys/bus/usb/drivers/ueagle-atm/*0 2>/dev/null)
do

ID=$(basename $DIR)
ID=${ID%%:*}
DIRM=/sys/bus/usb/devices/$ID
printf "ueagle-atm status display\n"
printf -- "-------------------------------------------------------------\n"
#printf "Driver version: %s     Chipset: %s\n" xx yy
printf "Vendor ID : 0x%x     Product ID : 0x%x   Rev: 0x%x" "0x$(<$DIRM/idVendor)" "0x$(<$DIRM/idProduct)" "0x$(<$DIRM/bcdDevice)"
if [ "$(( 0x$(<$DIRM/bcdDevice) & 0x80 ))" = 0 ]
then
	printf "(%s)\n" "pots"
else
	printf "(%s)\n" "isdn"
fi

printf "USB Bus : %03d\t USB Device : %03d\t Dbg : %d\n" ${ID%%-*} $(<$DIRM/devnum) $(</sys/module/ueagle_atm/parameters/debug)
if [ -e $DIR/stat_firmid ] ; then
	printf "VID-CPE   %10d     Firmware version %08x\n\n" 0x$(<$DIR/stat_vidcpe) 0x$(<$DIR/stat_firmid)
else
	printf "VID-CPE   %10d\n\n" 0x$(<$DIR/stat_vidcpe) 
fi
printf "Tx Rate   %10d Kps Rx Rate   %10d Kps\n" 0x$(<$DIR/stat_usrate) 0x$(<$DIR/stat_dsrate)
printf "Tx Atten  %10d dB  Rx Atten  %10d dB\n" 0x$(<$DIR/stat_usattenuation) 0x$(<$DIR/stat_dsattenuation)
printf "Tx Margin %10d dB  Rx Margin %10d dB\n" 0x$(<$DIR/stat_usmargin) 0x$(<$DIR/stat_dsmargin)
printf "Tx Blocks %10d     Rx Blocks %10d\n" 0x$(<$DIR/stat_txflow) 0x$(<$DIR/stat_rxflow)
printf "Tx FEC    %10d     Rx FEC    %10d\n" 0x$(<$DIR/stat_uscorr) 0x$(<$DIR/stat_dscorr)
printf "Tx Error  %10d     Rx Error  %10d\n" 0x$(<$DIR/stat_usunc) 0x$(<$DIR/stat_dsunc)
FLAGS="0x$(<$DIR/stat_mflags)"
printf "Delin          %5s" "$(<$DIR/stat_delin)"
printf "     Flags     %10.10x\n" $FLAGS
printf "%s\n" "$(<$DIR/stat_human_status)"
printf "\n"

done
