* updated maddy (0.7.1 -> 0.8.1), untested
[t2sde.git] / package / network / wireless-tools / rocknet_wireless.sh
blob9a506b8f52b251f60a47dffc428097e3ac58af7a
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: package/*/wireless-tools/rocknet_wireless.sh
3 # Copyright (C) 2004 - 2022 The T2 SDE Project
4 #
5 # This Copyright note is generated by scripts/Create-CopyPatch,
6 # more information can be found in the files COPYING and README.
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License version 2.
10 # --- T2-COPYRIGHT-NOTE-END ---
12 iwdetect_mangle_cells() {
13 local essid=none mode= encryption= quality=
14 local line=
16 mkdir -p $rocknet_tmp_base/$if/
18 iwlist $if scan | while read line; do
19 if [[ $line = *ESSID* ]]; then
20 [ -n "$essid" ] && echo -e "$essid\t$mode\t$encryption\t$quality"
21 essid="$( echo "$line" | sed -e 's,.*"\(.*\)",\1,g' )"
22 mode=
23 encryption=
24 quality=
25 elif [[ $line = Mode:* ]]; then
26 mode=${line#*:}
27 elif [[ $line = Encryption* ]]; then
28 encryption=${line#*:}
29 elif [[ $line = *Quality* ]]; then
30 quality=$( echo "$line" | sed -e 's,:\([^ ]*\),:\1\n,g' | sed -e 's,^.*:,,g' | head -n 2 | tr '\n' '\t' )
31 elif [ -z "$line" ]; then
32 [ "$essid" != "none" ] && echo -e "$essid\t$mode\t$encryption\t$quality"
34 done > $rocknet_tmp_base/$if/detected_cells
36 iwdetect_select_cell() {
37 local networkfile=${1:-/etc/conf/network-nettab}
38 local essid= key= extra=
39 local line=
41 if [ -f $networkfile ]; then
42 while read -r essid key extra; do
43 line="$( grep -e "^$essid" $rocknet_tmp_base/$if/detected_cells )"
44 if [ -n "$line" ]; then
45 echo "'$essid' selected..."
46 echo "$line" | ( read -r -d '\t' essid mode encryption quality signal;
47 iwconfig $if essid "$essid"
48 case "$mode" in
49 Master) iwconfig $if mode Managed ;;
50 Ad-Hoc) iwconfig $if mode "Ad-Hoc" ;;
51 *) echo "WARNING: Unknown mode '$mode'." ;;
52 esac
54 break
56 done < $networkfile
57 else
58 echo "INFO: to use iwdetect you need to set a $networkfile."
62 public_iwdetect() {
63 addcode up 4 2 "ip link set $if up"
64 addcode up 4 3 "iwdetect_mangle_cells"
65 addcode up 4 4 "iwdetect_select_cell $1"
66 addcode down 4 5 "iwconfig $if essid any"
69 public_essid() {
70 addcode up 4 5 "iwconfig $if essid $*"
71 addcode down 4 5 "iwconfig $if essid any"
74 public_nwid() {
75 addcode up 4 5 "iwconfig $if nwid $*"
76 addcode down 4 5 "iwconfig $if nwid off"
79 public_domain() {
80 addcode up 4 5 "iwconfig $if domain $*"
81 addcode down 4 5 "iwconfig $if domain off"
84 public_freq() {
85 addcode up 4 5 "iwconfig $if freq $*"
88 public_channel() {
89 addcode up 4 5 "iwconfig $if channel $*"
92 public_sens() {
93 addcode up 4 5 "iwconfig $if sens $*"
96 public_mode() {
97 addcode up 4 4 "iwconfig $if mode $*"
98 addcode down 4 4 "iwconfig $if mode Auto"
101 public_ap() {
102 addcode up 4 5 "iwconfig $if ap $*"
103 addcode down 4 5 "iwconfig $if ap any"
106 public_nick() {
107 addcode up 4 5 "iwconfig $if nick $*"
110 public_rate() {
111 addcode up 4 5 "iwconfig $if rate $*"
112 addcode down 4 5 "iwconfig $if rate auto"
115 public_rts() {
116 addcode up 4 5 "iwconfig $if rts $*"
119 public_frag() {
120 addcode up 4 5 "iwconfig $if frag $*"
123 public_key() {
124 addcode up 4 5 "iwconfig $if key $*"
125 addcode down 4 5 "iwconfig $if key off"
128 public_enc() {
129 addcode up 4 5 "iwconfig $if enc $*"
130 addcode down 4 5 "iwconfig $if enc off"
133 public_power() {
134 addcode up 4 5 "iwconfig $if power $*"
137 public_txpower() {
138 addcode up 4 5 "iwconfig $if txpower $*"
139 addcode down 4 5 "iwconfig $if txpower auto"
142 public_retry() {
143 addcode up 4 5 "iwconfig $if retry $*"
146 public_commit() {
147 addcode up 4 9 "iwconfig $if commit"