UserDocs/Tools/ath+802_debug-wrapper: athdbg-dlg.sh

File athdbg-dlg.sh, 2.2 kB (added by paolo, 2 years ago)

dialog(1) wrapper for {ath,80211}debug

Line 
1 #!/bin/sh
2 # Public Domain - paolo <ten.fs.sresu@alpoo> Tue, 22 Aug 2006 10:07:57 +0200
3 # dialog(1) interface to {ath,80211}debug(8)
4 #
5 IFACE=; O=
6 XDEBUG=athdebug
7
8 bits () {
9   a=$1; b=$2
10   rc=1
11   case $a in
12     1) [ $[0x$b%2] = 1 ] && rc=0 ;;
13     2) z=$[0x$b/2]; [ $[0x$z%2] = 1 ] && rc=0 ;;
14     4) z=$[0x$b/4]; [ $[0x$z%2] = 1 ] && rc=0 ;;
15     8) [ $[0x$b/8] = 1 ] && rc=0 ;;
16     *) ;;
17   esac
18   return $rc
19 }
20
21 while [ "$1" ];do
22   case $1 in
23     -8) XDEBUG=80211debug ;;
24     -a) XDEBUG=athdebug ;;
25     -i) shift; IFACE=$1 ;;
26     -?|-h) cat <<__F
27 Usage: ${0##*/} [-i interface] [-8a] [-?|-h] [athdebug opts]
28        -8 - use 80211debug
29        -a - use athdebug (default)
30
31 __F
32        exit 0
33        ;;
34     *) O="$O $1" ;;
35   esac
36   shift
37 done
38 [ "$IFACE" ] && IFACE="-i $IFACE"
39 #$XDEBUG -? 2>/dev/null|\
40 #  sed 's/[[:space:]]\+\([^[:space:]]\+\)[[:space:]]\+[^[:space:]]\+[[:space:]]\+\(.*\)/\1 "\2"/' \
41 #
42 $XDEBUG -? 2>/dev/null  > .${XDEBUG##*/}-flags
43 DS=`$XDEBUG $IFACE $O`
44 while true;do
45   # athdebug outputs <flags> as well, but 80211debug doesn't (yet)
46   # so in 1st case a grep suffice while in the latter the 0x* status need
47   # be decoded 'bit-wise' - more general though
48   case "$DS" in
49     *"<"*) CF=`echo $DS|sed 's/.*<\(.*\)>/\1/'|tr ',' ' '`
50          ds=${DS%%<*}
51          ;;
52     *) CF=$DS; ds=$DS ;;
53   esac
54   if [ "$LINES" ] && [ "$COLUMNS" ]; then
55    r=$LINES; c=$COLUMNS
56   else
57    echo "no LINES,COLUMNS??" >&2
58    rc=`stty size`
59    r=${rc% *}; c=${rc#* }
60   fi
61   DIALOG="dialog --single-quoted --backtitle \">$XDEBUG<\" --title \"$ds\" "
62   DIALOG="$DIALOG --no-shadow --checklist flags: $[r-4] $[c-6] $[r-11]"
63   while read f x d;do
64     S=off
65     case "$DS" in
66       *"<"*) echo $CF|grep -qw $f && S=on ;;
67       *) A=${x%%0*}; B=${CF:$[${#A}-1]:1}; A=${A:$[${#A}-1]:1}
68          bits $A $B && S=on
69          ;;
70     esac
71     DIALOG="$DIALOG $f \"$d\" $S"
72   done < .${XDEBUG##*/}-flags
73   #echo "$DIALOG"
74   #exit
75   tmf=.athdbgf
76   DIALOG="$DIALOG 2>$tmf"
77   eval $DIALOG
78   [ $? = 0 ] || exit 1
79   [ -f $tmf ] && {
80     while read f x d;do
81       if grep -qw $f $tmf
82       then FF="$FF +$f"
83       else FF="$FF -$f"
84       fi
85     done < .${XDEBUG##*/}-flags
86   }
87   rm -f $tmf
88   #echo $FF; exit
89   DS=`$XDEBUG $IFACE $FF`
90 done
91