Please note: This project is no longer active. The website is kept online for historic purposes only.
If you´re looking for a Linux driver for your Atheros WLAN device, you should continue here .

UserDocs/Tools/GraphingIwconfig: graf_wlan.2.sh

File graf_wlan.2.sh, 19.0 kB (added by paolo, 13 years ago)

vs. 0.1.4 - tx-power=off fix (should overwrite 0.1.3)

Line 
1 #!/bin/sh
2 #
3 # ASCII graphing madness of $IWCONFIG output
4 # (C) oopla <ten.fs.sresu@alpoo> - GPL 2
5 # versions:
6 # 0.1   - initial release
7 # 0.1.1 - fixed sed regex ('Sensitivity')
8 # 0.1.2 - fixed missing init *_1 values; iwconfig path
9 #         added -d (debug) -s0 (alt regex) opts; fixed \3 <-> \4 order in subst
10 #         fixed missing -tp (for Tx-Power), -Mn (for MAXNL); fixed MAXLQ
11 #         changed -Ml -> -Ms, -ml -> -ms (MAX/MIN SL)
12 # 0.1.3 - fixed sed regexs for no ap, kBps, channel instead of freq, mW
13 #         added -pt -pr -pd: paths to antenna tx,rx,diversity flags
14 #         missing init val for TR; fixes for -ts; added -D opt
15 #         fixes for printing header
16 # 0.1.4 - tx-power=off fix
17 #
18 # needs bash(1) or any shell that's capable of doing $[ma*th] and ${s:ub:s}
19 # not too difficult to make it work in any POSIX minimal sh like (d)ash.
20 # sure ...
21 # - colorful would be cool(er) - yet slower
22 # - sticking header on top line w/ ncurses trick would be cool(er)
23 # - a C/C++ would be much faster and likely shorter
24 # - convert it in awk/perl/python/your-f-scr-lang
25 # - and, why not just hacking $IWCONFIG(8) to do the same natively, eh?
26 # your turn ;)
27 #
28 # If something breaks, check the sed(1) REGEX below against $IWCONFIG(8) output
29 #
30 AP="-"; SL=0; NL=0; SN=0; IFACE=; T=1; TX=0; RX=0; TR=0; PTA=; PRA=; PAD=
31 pIM=0; pIC=0; pIF=0; pIN=0; pTXR=0; pMB=0; CSV=0; pL=0
32 DELTA=0; pTP=0; pBR=0; pSL=0; pNL=0; pSN=0; pAP=0; pTX=0; pRX=0; pTS=0
33 LCSV=0; LSYS=0; LOGF=; ATS=0; HEADER=0; TSF=+%s
34 NFL=95; NL=$NFL; MAXSL=30; MINSL=85; SL=$NL; MAXBR=54; BR=0; MAXTP=20
35 MAXNL=75; MAXLQ=; LQ=0; N=10
36 MAXBRK=$[MAXBR*64]      #max tx/rx rate - top at half the link MAXBR, in kiBps
37 MAXTX=; MAXRX=
38 DIALC="-"; NDLC="+"
39 S=""; SI=""
40 TTY=${TTY:-`tty`}; r=$LINES; c=$COLUMNS
41 DEBUG=0; SED_RE=1
42 IWCONFIG=`which iwconfig`
43 [ "$IWCONFIG" ] || {
44   for p in /sbin /usr/sbin /usr/local/sbin;do
45     [ -x $p/iwconfig ] && IWCONFIG=$p/iwconfig && break
46   done
47 }
48 [ "$IWCONFIG" ] || {
49   echo "${0##*/}: unable to find iwconfig" >&2
50   exit 1
51 }
52
53 dialstr () {
54   i=1
55   S=""  # build our 'dial' string
56   Sx=""
57   while [ $i -lt $N ];do                # N slots + 1 needle = SW slots
58     S="$S$DIALC"
59     Sx="${Sx}_"
60     i=$[i+1]
61   done
62   # fix at 4 chars width of invalid*/missed beacon scales, incl. needle
63   SI="${DIALC}${DIALC}${DIALC}${DIALC}"
64   S2="${Sx:0:$[($N-1)/2]}"
65   S3="${Sx:$[($N-1)/2+1]}"
66 }
67
68 usage () {
69   echo "Usage: ${0##*/} options"
70   echo
71   echo "  Available options:"
72   grep '^[[:space:]]\+-[^ ]\+)' $0 | \
73      sed -e "s/) shift;[ ]*\([^ =]\+\)=.*#/ \1;/" -e "s/).*#/;/" |\
74   while read l;do
75     l1=${l%;*} l2=${l#*;}
76     l="printf \"    %-12s %-s\n\" \"$l1\" \"$l2\""
77     eval "$l"
78   done
79   dialstr
80   echo
81   printf "    dial:        |%s|\n" "${S:0:$[N/2]}$NDLC${S:$[N/2]}"
82   printf "                 |%s|\n" $SI
83   echo
84   exit 0
85 }
86
87 get_tty_rxc () {
88   if [ "$TTY" ]; then
89     if [ "$LINES" ] && [ "$COLUMNS" ]; then
90       r=$LINES
91       c=$COLUMNS
92     else
93       rc=`stty size`
94       r=${rc% *}
95       c=${rc#* }
96     fi
97   else
98     r=0; c=0
99   fi
100 }
101
102 # by default print just/at least ESSID and Link Quality
103 # print at least 10chars from ESSID, each graph is 10+2 chars wide
104 while [ "$1" ];do
105   case $1 in
106     -ap) pAP=1 ;;               #print AP MAC
107     -ts) shift; TSF=$1          #print timestamp (date "TSF" - default "$TSF")
108          pTS=1
109          case $1 in
110            +*) ;;
111            *) TSF=+%s ; continue ;;
112          esac
113          ;;
114     -D)  DELTA=1 ;;             #print iff output has changed (i.e. |uniq)
115     -br) pBR=1 ;;               #print bitrate
116     -sl) pSL=1 ;;               #print signal level
117     -nl) pNL=1 ;;               #print noise level
118     -sn) pSN=1 ;;               #print signal/noise ratio
119     -I) shift; IFACE=$1 ;;              #interface to watch
120     -i) shift; T=$1 ;;          #update interval (x.x s - default $T)
121     -tx) pTX=1 ;;               #print tx rate
122     -rx) pRX=1 ;;               #print rx rate
123     -tp) pTP=1 ;;               #print Tx-Power
124     -im) pIM=1 ;;               #print invalid misc (var)
125     -ic) pIC=1 ;;               #print invalid crypt (var)
126     -if) pIF=1 ;;               #print invalid frag (var)
127     -in) pIN=1 ;;               #print invalid nwid (var)
128     -te) pTXR=1 ;;              #print tx excess retry (var)
129     -pt) shift; PTA=$1 ;;       #path to tx antenna
130     -pr) shift; PRA=$1 ;;       #path to rx antenna
131     -pd) shift; PAD=$1 ;;       #path to diversity
132     -mb) pMB=1 ;;               #print missed beacons (var)
133     -nf) shift; NFL=$1 ;;       #set noise floor (-dBm - default $NFL)
134     -Ms) shift; MAXSL=$1 ;;     #set max signal  (-dBm - default $MAXSL)
135     -ms) shift; MINSL=$1 ;;     #set min signal  (-dBm - default $MINSL)
136     -Mn) shift; MAXNL=$1 ;;     #set max noise   (-dBm - default $MAXNL)
137     -Mb) shift; MAXBR=$1 ;;     #set max bitrate (Mibps - default $MAXBR)
138     -Mt) shift; MAXTX=$1 ;;     #set max Tx rate (kiBps - default $MAXBRK)
139     -Mr) shift; MAXRX=$1 ;;     #set max Rx rate (kiBps - default $MAXBRK)
140     -Mq) shift; MAXLQ=$1 ;;     #set max link quality (default $[NFL-$MAXSL])
141     -Mp) shift; MAXTP=$1 ;;     #set max Tx power (+dBm - default $MAXTP)
142     -nc) shift; NDLC=${1:0:1} ;;        #needle char (default '$NDLC')
143     -vc) shift; DIALC=${1:0:1} ;;       #dial chars (default '$DIALC')
144     -sw) shift; N=$1 ;;         #scale width in chars (default $N)
145     -wh) HEADER=1 ;;            #always have an header line within screen
146     -ls) LSYS=1 ;;              #log to syslog (as well)
147     -lf) shift; FLOG=$1 ;;      #log to named file
148     -cs) CSV=1 ;;               #output CSV data
149     -lc) LCSV=1 ;;              #log CSV data
150     -at) ATS=1 ;;               #adapt to terminal size
151     -d) DEBUG=1 ;;              #print some debugging on stderr
152     -s0) SED_RE=0 ;;            #select alternative sed(1) regex
153     *) usage ;;
154   esac
155   shift
156 done
157 [ "$IFACE" ] || {
158   echo "You must specify -I interface." >&2
159   exit 1
160 }
161 [ "$FLOG" ] && {
162   touch "$FLOG" || {
163     echo "${0##*/}: can't write to $FLOG" >&2
164     exit 1
165   }
166 }
167 ft=${T#*.}; t=${T%.*}   #decimals
168 t=${T%.*}; [ "$t" ] || t=0
169 # sleepenh(1) allows for fractional and <1s timing
170 SLEEP=sleepenh
171 hash sleepenh || {
172   SLEEP=sleep
173   [ $t = 0 ] && t=1
174   case "$ft" in [5-9]*) t=$[t+1] ;; *) ;; esac
175   ft=0
176   T=$t
177   echo "Note: sleepenh(1) not found - loop interval is $T s" >&2
178 }
179 dialstr
180 if [ $pTS = 1 ]; then
181   TS=`date "$TSF"`
182   CTSH="TimeStamp"
183   TSH="${CTSH}__________________"
184   if [ ${#TS} -lt ${#CTSH} ]
185   then l=${#CTSH}
186   else l=${#TS}
187   fi
188   TSH=${TSH:0:$l}
189   lTSH=$[1+${#TSH}]     #TSH+' '
190   clTSH=$[3+${#CTSH}]   #"+CTSH+"+,
191 else
192   lTSH=0
193   clTSH=0
194   TSH=""
195   CTSH=""
196 fi
197 [ "$PTA" ] && {
198   case "$PTA" in
199     /proc/*|/sys/*) ;;
200     *) [ -r "/proc/sys/$PTA" ] && PTA="/proc/sys/$PTA"
201        [ -r "/sys/$PTA" ] && PTA="/sys/$PTA"
202        [ -r "$PTA" ] || PTA=
203        ;;
204   esac
205 }
206 [ "$PRA" ] && {
207   case "$PRA" in
208     /proc/*|/sys/*) ;;
209     *) [ -r "/proc/sys/$PRA" ] && PRA="/proc/sys/$PRA"
210        [ -r "/sys/$PRA" ] && PRA="/sys/$PRA"
211        [ -r "$PRA" ] || PRA=
212        ;;
213   esac
214 }
215 [ "$PAD" ] && {
216   case "$PAD" in
217     /proc/*|/sys/*) ;;
218     *) [ -r "/proc/sys/$PAD" ] && PAD="/proc/sys/$PAD"
219        [ -r "/sys/$PAD" ] && PAD="/sys/$PAD"
220        [ -r "$PAD" ] || PAD=
221        ;;
222   esac
223 }
224 [ $HEADER = 1 ] && {
225       [ $CSV = 0 ] && {
226         [ $pTS = 1 ] && H="$TSH "     
227         H="${H}__ESSID___"
228         [ $pAP = 1 ] && H="$H _____AP(MAC)_____"
229         H="$H |${S2}LQ${S3}|"
230         [ $pBR = 1 ] && H="$H${S2}BR${S3}|"
231         [ $pSL = 1 ] && H="$H${S2}SL${S3}|"
232         [ $pNL = 1 ] && H="$H${S2}NL${S3}|"
233         [ $pTP = 1 ] && H="$H${S2}TP${S3}|"
234         [ $pSN = 1 ] && H="$H${S2}SN${S3}|"
235         [ $pTX = 1 ] && H="$H${S2}TX${S3}|"
236         [ $pRX = 1 ] && H="$H${S2}RX${S3}|"
237         [ "$PTA" ] || [ "$PRA" ] || [ "$PAD" ] && H="${H}TRD|"
238         [ $pMB = 1 ] && H="${H}_MB_|"
239         [ $pIN = 1 ] && H="${H}_IN_|"
240         [ $pIC = 1 ] && H="${H}_IC_|"
241         [ $pIM = 1 ] && H="${H}_IM_|"
242         [ $pIF = 1 ] && H="${H}_IF_|"
243         [ $pTXR = 1 ] && H="${H}_TR_|"
244       }
245       [ $CSV = 1 ] || [ $LCSV = 1 ] && {
246         [ $pTS = 1 ] && CH="\"$CTSH\","
247         CH="$CH\"ESSID\""
248         [ $pAP = 1 ] && CH="$CH,\"AP\""
249         CH="$CH,\"LQ\""
250         [ $pBR = 1 ] && CH="$CH,\"BR\""
251         [ $pSL = 1 ] && CH="$CH,\"SL\""
252         [ $pNL = 1 ] && CH="$CH,\"NL\""
253         [ $pTP = 1 ] && CH="$CH,\"TP\""
254         [ $pSN = 1 ] && CH="$CH,\"SN\""
255         [ $pTX = 1 ] && CH="$CH,\"TX\""
256         [ $pRX = 1 ] && CH="$CH,\"RX\""
257         [ "$PTA" ] || [ "$PRA" ] || [ "$PAD" ] && CH="$CH,\"ATRD\""
258         [ $pMB = 1 ] && CH="$CH,\"MB\""
259         [ $pIN = 1 ] && CH="$CH,\"IN\""
260         [ $pIC = 1 ] && CH="$CH,\"IC\""
261         [ $pIM = 1 ] && CH="$CH,\"IM\""
262         [ $pIF = 1 ] && CH="$CH,\"IF\""
263         [ $pTXR = 1 ] && CH="$CH,\"TXR\""
264       }
265 }
266 get_tty_rxc
267 MAXSN=$[NFL-$MAXSL]
268 MAXLQ=${MAXLQ:-$[NFL-$MAXSL]}
269 NR=$[NFL-$MAXNL]        #noise range for graph
270 SR=$[MINSL-$MAXSL]      #signal range for graph
271 MAXBRK=$[MAXBR*64]
272 MAXTX=${MAXTX:-$MAXBRK}; MAXRX=${MAXRX:-$MAXBRK}
273 [ $DEBUG = 1 ] && cat <<__F>&2
274 TTY=$TTY r,c=$r,$c T=$T t=$t ft=$ft t10=$[t*10+${ft:0:1}]
275 MAXSN=$MAXSN MAXLQ=$MAXLQ NR=$NR SR=$SR MAXBR=$MAXBR
276 MAXTX=$MAXTX MAXRX=$MAXRX MAXBRK=$MAXBRK
277 __F
278
279 # print header once at least
280 if [ $CSV = 0 ]; then
281   if [ $ATS = 1 ] && [ $c -gt 0 ];then
282     if [ ${#H} -gt $c ]
283     then echo "${H:0:$[c-1]}>"
284     else echo $H
285     fi
286   else
287     echo $H
288   fi
289 else
290   if [ $ATS = 1 ] && [ $c -gt 0 ];then
291     if [ ${#CH} -gt $c ]
292     then echo "${CH:0:$[c-1]}>"
293     else echo $CH
294     fi
295   else
296     echo $CH
297   fi
298 fi
299 i=1
300 [ $LSYS = 1 ] && \
301   #drop our timestamp anyway as logger(1) already does it
302   if [ $LCSV = 0 ]
303   then logger -t iwconf.$IFACE "${H:$lTSH}"
304   else logger -t iwconf.$IFACE "${CH:$clTSH}"
305   fi
306 [ "$FLOG" ] && \
307   if [ $LCSV = 0 ]
308   then echo "$H" > "$FLOG"
309   else echo "$CH" > "$FLOG"
310   fi
311
312 while true;do
313   # choose your method; either try to grab subexpressions (default) or
314   # try to delete everything but the wanted values (opt -s0)
315   # Hope Jean won't change these labels in $IWCONFIG(8)
316   if [ $SED_RE = 1 ]; then
317     # need LANG=C to avoid locale msgs
318     IWC=`LANG=C $IWCONFIG $IFACE | tr '\n' ' '`
319     set -- `echo $IWC |\
320       sed  -n "s/.\+ESSID[=:]\"\?\([^\"]*\)\".\+\(Frequency\|Channel\)[=:][ ]*\([.0-9]*\).\+Access Point[:=][ ]*\([^ ]*\).\+Bit Rate[=:][ ]*\([0-9]*\).\+Tx-Power[:=][ ]*\(off\|[-+.0-9]*\).\+Link Quality[:=][ ]*\([0-9]*\).\+Signal level[:=][- ]*\([0-9]*\).\+Noise level[:=][- ]*\([0-9]*\).\+/\"\1\" \3 \4 \5 \6 \7 \8 \9/p"`
321     [ $DEBUG = 1 ] && echo -n "sed_re=$SED_RE: $@" >&2
322     ESSID=${1%\"}; ESSID=${ESSID#\"}
323     FREQ=$2
324     AP=$3
325     BR=$4
326     TXP=$5
327     LQ=$6
328     SL=$7
329     NL=$8
330     # grab&print next bunch of replacements
331     set -- `echo $IWC |\
332       sed -n "s/.*Rx invalid nwid[=:][ ]*\([0-9]*\)[ ]\+Rx invalid crypt[=:][ ]*\([0-9]*\)[ ]\+Rx invalid frag[=:][ ]*\([0-9]*\)[ ]\+Tx excessive retries[=:][ ]*\([0-9]*\)[ ]\+Invalid misc[=:][ ]*\([0-9]*\)[ ]\+Missed beacon[=:][ ]*\([0-9]*\).*/\1 \2 \3 \4 \5 \6/p"`
333     [ $DEBUG = 1 ] && echo $@ >&2
334     IN=$1
335     IC=$2
336     IF=$3
337     TXER=$4
338     IM=$5
339     MB=$6
340   else
341     # do all at once by subctraction
342     # note: the tx-power=off rule adds a 'mW' for the next rule
343     set -- `LANG=C $IWCONFIG $IFACE | tr '\n' ' ' |\
344       sed -e s/.*ESSID[=:]// \
345         -e 's/Tx-Power[:=][ ]*off/& mW/' \
346         -e "s/[ ]*Mode[:=].*Frequency[:=][ ]*/ /" \
347         -e "s/ \(GHz\)\?[ ]*Access Point[:=][ ]*/ /" \
348         -e "s/[ ]*Bit Rate[:=][ ]*/ /" \
349         -e "s, [kM]b/s[ ]*Tx-Power[:=][ ]*, ," \
350         -e "s/ \(mW\|dBm\)[ ]*\(Sens.*\)\?.*Link Quality[:=][ ]*/ /" \
351         -e "s/[ ]*Signal level[:=][- ]*/ /" \
352         -e "s/ dBm[ ]*Noise level[:=][- ]*/ /" \
353         -e "s/ dBm[ ]*Rx invalid nwid[:=][ ]*/ /" \
354         -e "s/[ ]*Rx invalid crypt[:=][ ]*/ /" \
355         -e "s/[ ]*Rx invalid frag[:=][ ]*/ /" \
356         -e "s/[ ]*Tx excessive retries[:=][ ]*/ /" \
357         -e "s/[ ]*Invalid misc[:=][ ]*/ /" \
358         -e "s/[ ]*Missed beacon[:=][ ]*/ /"`
359     [ $DEBUG = 1 ] && echo "sed_re=$SED_RE: $@" >&2
360     ESSID=${1%\"}; ESSID=${ESSID#\"}
361     FREQ=$2
362     AP=$3
363     BR=$4
364     TXP=$5
365     LQ=$6
366     SL=$7
367     NL=$8
368     IN=$9
369     IC=${10}
370     IF=${11}
371     TXER=${12}
372     IM=${13}
373     MB=${14}
374   fi
375   LQ=${LQ%/*}
376   [ $ATS = 1 ] && get_tty_rxc
377   [ $HEADER = 1 ] && [ "$TTY" ] && [ $r -gt 0 ] && {
378     [ $i = 0 ] && {
379       if [ $CSV = 0 ]; then
380         if [ $ATS = 1 ] && [ $c -gt 0 ];then
381           if [ ${#H} -gt $c ]
382           then echo "${H:0:$[c-1]}>"
383           else echo $H
384           fi
385         else
386          echo $H
387         fi
388       else
389         if [ $ATS = 1 ] && [ $c -gt 0 ];then
390           if [ ${#CH} -gt $c ]
391           then echo "${CH:0:$[c-1]}>"
392           else echo $CH
393           fi
394         else
395           echo $CH
396         fi
397       fi
398     }
399     [ $DELTA = 0 ] || [ $pL = 1 ] || [ $i = 0 ] && i=$[($i+1)%$[r-2]]
400     pL=0
401   }
402   [ $pTX = 1 ] || [ $pRX = 1 ] && {
403     #set -- `grep $IFACE: /proc/net/dev|cut -d: -f2`
404     #this in 1000 cycles loop is ~8 times faster on my pc ...
405     while read l;do
406       case $l in
407         $IFACE:*) l=${l#*:}; set $l; break ;;
408         *) ;;
409       esac
410     done < /proc/net/dev
411     RX=$1
412     TX=$9
413     [ "$TX_1" ] || TX_1=$TX
414     [ "$RX_1" ] || RX_1=$RX
415     if [ $t = $ft ]; then
416       # time interval has no decimals
417       tx=$[($TX-$TX_1)/$t/1024] # in kiBps
418       rx=$[($RX-$RX_1)/$t/1024] # in kiBps
419     else
420       # 1st decimal pos is enough
421       t10=$[t*10+${ft:0:1}]
422       tx=$[($TX-$TX_1)*10/$t10/1024] # in kiBps
423       rx=$[($RX-$RX_1)*10/$t10/1024] # in kiBps
424     fi
425     #or just use bc(1) instead of above mess:
426     #tx=`echo "tx=($TX-$TX_1)/$T; scale=0; print tx/1024"|bc -l`
427     #rx=`echo "rx=($RX-$RX_1)/$T; scale=0; print rx/1024"|bc -l`
428     TX_1=$TX
429     RX_1=$RX
430   }
431   L=""; CL=""
432   [ "$PTA" ] || [ "$PRA" ] || [ "$PAD" ] && {
433     if [ "$PTA" ]
434     then ta=`cat $PTA`; ta=${ta:0:1}
435     else ta=x
436     fi
437     if [ "$PRA" ]
438     then ra=`cat $PRA`; ra=${ra:0:1}
439     else ra=x
440     fi
441     if [ "$PAD" ]
442     then ad=`cat $PAD`; ad=${ad:0:1}
443     else ad=x
444     fi
445   }
446   if [ $CSV = 1 ] || [ $LCSV = 1 ]; then
447     [ $pTS = 1 ] && L="\"`date "$TSF"`\","
448     CL="$L\"$ESSID\""
449     [ $pAP = 1 ] && CL="$CL,\"$AP\""
450     CL="$CL,\"$LQ\""
451     [ $pBR = 1 ] && CL="$CL,\"$BR\""
452     [ $pSL = 1 ] && CL="$CL,\"$SL\""
453     [ $pNL = 1 ] && CL="$CL,\"$NL\""
454     [ $pTP = 1 ] && CL="$CL,\"$TXP\""
455     [ $pSN = 1 ] && CL="$CL,\"$SN\""
456     [ $pTX = 1 ] && CL="$CL,\"$tx\""
457     [ $pRX = 1 ] && CL="$CL,\"$rx\""
458     [ "$PTA" ] || [ "$PRA" ] || [ "$PAD" ] && CL="$CL,\"$ta$ra$ad\""
459     [ $pMB = 1 ] && CL="$CL,\"$MB\""
460     [ $pIN = 1 ] && CL="$CL,\"$IN\""
461     [ $pIC = 1 ] && CL="$CL,\"$IC\""
462     [ $pIM = 1 ] && CL="$CL,\"$IM\""
463     [ $pIF = 1 ] && CL="$CL,\"$IF\""
464     [ $pTXR = 1 ] && CL="$CL,\"$TR\""
465   else
466     [ $pTS = 1 ] && {
467       TS=`date "$TSF"`
468       TS="$TS          "
469       L="${TS:0:${#TSH}} "
470     }
471     essid="$ESSID                "; essid="${essid:0:10}"
472     L="$L$essid"
473     [ $pAP = 1 ] && {
474       AP="$AP                 "; AP=${AP:0:17}
475       L="$L $AP"
476     }
477     lq=$LQ; [ $lq -gt $MAXLQ ] && lq=$MAXLQ
478     L="$L |${S:0:$[lq*$N/$MAXLQ]}+${S:$[lq*$N/$MAXLQ]}|"
479     [ $pBR = 1 ] && {
480       br=$BR; [ $br -gt $MAXBR ] && br=$MAXBR
481       L="$L${S:0:$[br*$N/$MAXBR]}+${S:$[br*$N/$MAXBR]}|"
482     }
483     [ $pSL = 1 ] && {
484       sl=$[MINSL-$SL]; [ $sl -lt 0 ] && sl=0
485       L="$L${S:0:$[sl*$N/$SR]}+${S:$[sl*$N/$SR]}|"
486     }
487     [ $pNL = 1 ] && {
488       nl=$[NL-$MAXNL]; [ $nl -lt 0 ] && nl=0
489       L="$L${S:$[nl*$N/$NR]}+${S:0:$[nl*$N/$NR]}|"
490     }
491     [ $pTP = 1 ] && {
492       case $TXP in
493         off)  L="$L$S$DIALC|" ;;
494         *) tp=$TXP ; [ $tp -gt $MAXTP ] && tp=$MAXTP
495            L="$L${S:0:$[tp*$N/$MAXTP]}+${S:$[tp*$N/$MAXTP]}|"
496            ;;
497       esac
498     }
499     #LQ should bear same info, but that's driver/card dependent
500     [ $pSN = 1 ] && {
501       sn=$[NL-$SL]; [ $sn -lt 0 ] && sn=0
502       L="$L${S:0:$[sn*$N/$MAXSN]}+${S:$[sn*$N/$MAXSN]}|"
503     }
504     [ $pTX = 1 ] && {
505       [ $tx -gt $MAXTX ] && tx=$MAXTX
506       L="$L${S:0:$[tx*$N/$MAXTX]}+${S:$[tx*$N/$MAXTX]}|"
507     }
508     [ $pRX = 1 ] && {
509       [ $rx -gt $MAXRX ] && rx=$MAXRX
510       L="$L${S:0:$[rx*$N/$MAXRX]}+${S:$[rx*$N/$MAXRX]}|"
511     }
512     [ "$PTA" ] || [ "$PRA" ] || [ "$PAD" ] && L="$L$ta$ra$ad|"
513     [ $pMB = 1 ] && {
514       [ "$MB_1" ] || MB_1=$MB
515       if [ $MB = 0 ] || [ $MB = $MB_1 ]; then
516         L="$L${SI:0}|"
517       else
518         dMB=$[MB-$MB_1]
519         if [ $dMB -gt $[t*4] ]  ; then L="$L${SI:0:3}+|"
520         elif [ $dMB -gt $[t*3] ]; then L="$L${SI:0:2}+${SI:3}|"
521         elif [ $dMB -gt $[t*2] ]; then L="$L${SI:0:1}+${SI:2}|"
522         else L="$L+${SI:1}|"
523         fi
524       fi
525       MB_1=$MB
526     }
527     [ $pIN = 1 ] && {
528       [ "$IN_1" ] || IN_1=$IN
529       if [ $IN = 0 ] || [ $IN = $IN_1 ]; then
530         L="$L${SI:0}|"
531       else
532         dIN=$[IN-$IN_1]
533         if [ $dIN -gt $[t*4] ]  ; then L="$L${SI:0:3}+|"
534         elif [ $dIN -gt $[t*3] ]; then L="$L${SI:0:2}+${SI:3}|"
535         elif [ $dIN -gt $[t*2] ]; then L="$L${SI:0:1}+${SI:2}|"
536         else L="$L+${SI:1}|"
537         fi
538       fi
539       IN_1=$IN
540     }
541     [ $pIC = 1 ] && {
542       [ "$IC_1" ] || IC_1=$IC
543       if [ $IC = 0 ] || [ $IC = $IC_1 ]; then
544         L="$L${SI:0}|"
545       else
546         dIC=$[IC-$IC_1]
547         if [ $dIC -gt $[t*4] ]  ; then L="$L${SI:0:3}+|"
548         elif [ $dIC -gt $[t*3] ]; then L="$L${SI:0:2}+${SI:3}|"
549         elif [ $dIC -gt $[t*2] ]; then L="$L${SI:0:1}+${SI:2}|"
550         else L="$L+${SI:1}|"
551         fi
552       fi
553       IC_1=$IC
554     }
555     [ $pIM = 1 ] && {
556       [ "$IM_1" ] || IM_1=$IM
557       if [ $IM = 0 ] || [ $IM = $IM_1 ]; then
558         L="$L${SI:0}|"
559       else
560         dIM=$[IM-$IM_1]
561         if [ $dIM -gt $[t*4] ]  ; then L="$L${SI:0:3}+|"
562         elif [ $dIM -gt $[t*3] ]; then L="$L${SI:0:2}+${SI:3}|"
563         elif [ $dIM -gt $[t*2] ]; then L="$L${SI:0:1}+${SI:2}|"
564         else L="$L+${SI:1}|"
565         fi
566       fi
567       IM_1=$IM
568     }
569     [ $pIF = 1 ] && {
570       [ "$IF_1" ] || IF_1=$IF
571       if [ $IF = 0 ] || [ $IF = $IF_1 ]; then
572         L="$L${SI:0}|"
573       else
574         dIF=$[IF-$IF_1]
575         if [ $dIF -gt $[t*4] ]  ; then L="$L${SI:0:3}+|"
576         elif [ $dIF -gt $[t*3] ]; then L="$L${SI:0:2}+${SI:3}|"
577         elif [ $dIF -gt $[t*2] ]; then L="$L${SI:0:1}+${SI:2}|"
578         else L="$L+${SI:1}|"
579         fi
580       fi
581       IN_1=$IN
582     }
583     [ $pTXR = 1 ] && {
584       [ "$TR_1" ] || TR_1=$TR
585       if [ $TR = 0 ] || [ $TR = $TR_1 ]; then
586         L="$L${SI:0}|"
587       else
588         dTR=$[TR-$TR_1]
589         if [ $dTR -gt $[t*4] ]  ; then L="$L${SI:0:3}+|"
590         elif [ $dTR -gt $[t*3] ]; then L="$L${SI:0:2}+${SI:3}|"
591         elif [ $dTR -gt $[t*2] ]; then L="$L${SI:0:1}+${SI:2}|"
592         else L="$L+${SI:1}|"
593         fi
594       fi
595       TR_1=$TR
596     }
597   fi
598   if [ $CSV = 0 ]; then
599     [ $DELTA = 0 ] || [ "${_L:$lTSH}" != "${L:$lTSH}" ] && {
600       if [ $ATS = 1 ] && [ $c -gt 0 ]; then
601         if [ ${#L} -gt $c ]
602         then echo "${L:0:$[c-1]}>"
603         else echo "$L"
604         fi
605       else
606         echo "$L"
607       fi
608       pL=1
609     }
610   else
611     [ $DELTA = 0 ] || [ "${_CL:$clTSH}" != "${CL:$clTSH}" ] && {
612       if [ $ATS = 1 ] && [ $c -gt 0 ]; then
613         if [ ${#CL} -gt $c ]
614         then echo "${CL:0:$[c-1]}>"
615         else echo "$CL"
616         fi
617       else
618         echo "$CL"
619       fi
620       pL=1
621     }
622   fi
623   [ $LSYS = 1 ] && {
624     #drop our timestamp anyway as logger(1) already does it
625     if [ $LCSV = 0 ]; then
626       [ $DELTA = 0 ] || [ "${_L:$lTSH}" != "${L:$lTSH}" ] && \
627       logger -t iwconf.$IFACE "${L:$lTSH}"
628     else
629       [ $DELTA = 0 ] || [ "${_CL:$clTSH}" != "${CL:$clTSH}" ] && \
630       logger -t iwconf.$IFACE "${CL:$clTSH}"
631     fi
632   }
633   [ "$FLOG" ] && {
634     if [ $LCSV = 0 ]; then
635       [ $DELTA = 0 ] || [ "${_L:$lTSH}" != "${L:$lTSH}" ] && \
636       echo "$L" >> "$FLOG"
637     else
638       [ $DELTA = 0 ] || [ "${_CL:$clTSH}" != "${CL:$clTSH}" ] && \
639       echo "$CL" >> "$FLOG"
640     fi
641   }
642   _L=$L
643   _CL=$CL
644   $SLEEP $T &>/dev/null
645 done
646