| 1 | #! /bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | # |
| 3 | # xpp_debug: Turn on/off debugging flags via /sys/module/*/parameters/debug |
| 4 | # |
| 5 | |
| 6 | modules="xpp xpp_usb xpd_fxs xpd_fxo xpd_bri xpd_pri xpd_echo" |
| 7 | dbg_names="DEFAULT PCM LEDS SYNC SIGNAL PROC REGS DEVICES COMMANDS" |
| 8 | |
| 9 | usagescip-shell shell shell-project 0.0.0 usage().() { |
| 10 | echoscip-shell system . . echo. 1>&2 "Usage: $0 [module_name] [[-]flags...]" |
| 11 | echoscip-shell system . . echo. 1>&2 " module_name => $modules" |
| 12 | echoscip-shell system . . echo. 1>&2 " flags => NONE $dbg_names ANY" |
| 13 | echoscip-shell system . . echo. 1>&2 "" |
| 14 | echoscip-shell system . . echo. 1>&2 " Example: $0 xpp ANY -PCM -LEDS" |
| 15 | echoscip-shell system . . echo. 1>&2 "" |
| 16 | } |
| 17 | |
| 18 | sysfs_namescip-shell shell shell-project 0.0.0 sysfs_name().() { |
| 19 | f='' |
| 20 | if [scip-shell system . . `[`. -f "/sys/module/$1/parameters/debug" ]; then |
| 21 | f="/sys/module/$1/parameters/debug" |
| 22 | elif [scip-shell system . . `[`. -f "/sys/module/$1/debug" ]; then |
| 23 | f="/sys/module/$1/debug" |
| 24 | fi |
| 25 | echoscip-shell system . . echo. "$f" |
| 26 | } |
| 27 | |
| 28 | sysfs_valuescip-shell shell shell-project 0.0.0 sysfs_value().() { |
| 29 | f=`sysfs_namescip-shell shell shell-project 0.0.0 sysfs_name(). "$1"` |
| 30 | if [scip-shell system . . `[`. "$f" != "" ]; then |
| 31 | catscip-shell system . . cat. "$f" |
| 32 | fi |
| 33 | } |
| 34 | |
| 35 | show_debugscip-shell shell shell-project 0.0.0 show_debug().() { |
| 36 | usagescip-shell shell shell-project 0.0.0 usage(). |
| 37 | for i in $modules |
| 38 | do |
| 39 | f=`sysfs_namescip-shell shell shell-project 0.0.0 sysfs_name(). "$i"` |
| 40 | if [scip-shell system . . `[`. -f "$f" ]; then |
| 41 | val=`catscip-shell system . . cat. $f` |
| 42 | j=0 |
| 43 | list='' |
| 44 | for n in $dbg_names |
| 45 | do |
| 46 | if [scip-shell system . . `[`. $(( val & (1 << j) )) -ne 0 ]; then |
| 47 | list="$list $n" |
| 48 | fi |
| 49 | j=$((j+1)) |
| 50 | done |
| 51 | if [scip-shell system . . `[`. "$list" = "" ]; then |
| 52 | list=' NONE' |
| 53 | fi |
| 54 | echoscip-shell system . . echo. "$i $list" |
| 55 | fi |
| 56 | done |
| 57 | } |
| 58 | |
| 59 | calc_debugscip-shell shell shell-project 0.0.0 calc_debug().() { |
| 60 | val="$1" |
| 61 | shift |
| 62 | for wanted in $* |
| 63 | do |
| 64 | j=0 |
| 65 | found=0 |
| 66 | for n in $dbg_names |
| 67 | do |
| 68 | if [scip-shell system . . `[`. "$wanted" = "$n" ]; then |
| 69 | : $(( val |= (1 << j) )) |
| 70 | found=1 |
| 71 | elif [scip-shell system . . `[`. "$wanted" = -"$n" ]; then |
| 72 | : $(( val &= ~(1 << j) )) |
| 73 | found=1 |
| 74 | elif [scip-shell system . . `[`. "$wanted" = "ANY" ]; then |
| 75 | : $(( val = ~0 )) |
| 76 | found=1 |
| 77 | elif [scip-shell system . . `[`. "$wanted" = -"ANY" -o "$wanted" = "NONE" ]; then |
| 78 | val=0 |
| 79 | found=1 |
| 80 | fi |
| 81 | j=$((j+1)) |
| 82 | done |
| 83 | if [scip-shell system . . `[`. "$found" -eq 0 ]; then |
| 84 | echoscip-shell system . . echo. >&2 "$0: Unknown debug flag '$wanted'" |
| 85 | exit 1 |
| 86 | fi |
| 87 | done |
| 88 | echoscip-shell system . . echo. $val |
| 89 | } |
| 90 | |
| 91 | if [scip-shell system . . `[`. "$#" = 0 ]; then |
| 92 | show_debugscip-shell shell shell-project 0.0.0 show_debug(). |
| 93 | exit 0 |
| 94 | fi |
| 95 | |
| 96 | module="$1" |
| 97 | shift |
| 98 | |
| 99 | if ! echoscip-shell system . . echo. "$modules" | grepscip-shell system . . grep. -w "$module" > /dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 100 | echoscip-shell system . . echo. >&2 "$0: Unknown module $module" |
| 101 | exit 1 |
| 102 | fi |
| 103 | |
| 104 | oldval=`sysfs_valuescip-shell shell shell-project 0.0.0 sysfs_value(). "$module"` |
| 105 | val=`calc_debugscip-shell shell shell-project 0.0.0 calc_debug(). "$oldval" $*` |
| 106 | file=`sysfs_namescip-shell shell shell-project 0.0.0 sysfs_name(). $module` |
| 107 | |
| 108 | echoscip-shell system . . echo. "$val" > "$file" |
| 109 | show_debugscip-shell shell shell-project 0.0.0 show_debug(). |