Dash:
[t2.git] / package / network / wireless-tools / rocknet_wireless.sh
blobbc5c763457cfaeef8e6de7a5304098e5b40b812c
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
3 #
4 # T2 SDE: package/.../wireless-tools/rocknet_wireless.sh
5 # Copyright (C) 2004 - 2005 The T2 SDE Project
6 #
7 # More information can be found in the files COPYING and README.
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; version 2 of the License. A copy of the
12 # GNU General Public License can be found in the file COPYING.
13 # --- T2-COPYRIGHT-NOTE-END ---
15 iwdetect_mangle_cells() {
16 local essid=none mode= encryption= quality=
17 local line=
19 mkdir -p $rocknet_tmp_base/$if/
21 iwlist $if scan | while read line; do
22 if [[ $line = *ESSID* ]]; then
23 [ -n "$essid" ] && echo -e "$essid\t$mode\t$encryption\t$quality"
24 essid="$( echo "$line" | sed -e 's,.*"\(.*\)",\1,g' )"
25 mode=
26 encryption=
27 quality=
28 elif [[ $line = Mode:* ]]; then
29 mode=${line#*:}
30 elif [[ $line = Encryption* ]]; then
31 encryption=${line#*:}
32 elif [[ $line = *Quality* ]]; then
33 quality=$( echo "$line" | sed -e 's,:\([^ ]*\),:\1\n,g' | sed -e 's,^.*:,,g' | head -n 2 | tr '\n' '\t' )
34 elif [ -z "$line" ]; then
35 [ "$essid" != "none" ] && echo -e "$essid\t$mode\t$encryption\t$quality"
37 done > $rocknet_tmp_base/$if/detected_cells
39 iwdetect_select_cell() {
40 local networkfile=${1:-/etc/conf/network-nettab}
41 local essid= key= extra=
42 local line=
44 if [ -f $networkfile ]; then
45 while read -r essid key extra; do
46 line="$( grep -e "^$essid" $rocknet_tmp_base/$if/detected_cells )"
47 if [ -n "$line" ]; then
48 echo "'$essid' selected..."
49 echo "$line" | ( read -r -d '\t' essid mode encryption quality signal;
50 iwconfig $if essid "$essid"
51 case "$mode" in
52 Master) iwconfig $if mode Managed ;;
53 Ad-Hoc) iwconfig $if mode "Ad-Hoc" ;;
54 *) echo "WARNING: Unknown mode '$mode'." ;;
55 esac
57 break
59 done < $networkfile
60 else
61 echo "INFO: to use iwdetect you need to set a $networkfile."
65 public_iwdetect() {
66 addcode up 4 2 "ip link set $if up"
67 addcode up 4 3 "iwdetect_mangle_cells"
68 addcode up 4 4 "iwdetect_select_cell $1"
69 addcode down 4 5 "iwconfig $if essid any"
72 public_essid() {
73 addcode up 4 5 "iwconfig $if essid $*"
74 addcode down 4 5 "iwconfig $if essid any"
77 public_nwid() {
78 addcode up 4 5 "iwconfig $if nwid $*"
79 addcode down 4 5 "iwconfig $if nwid off"
82 public_domain() {
83 addcode up 4 5 "iwconfig $if domain $*"
84 addcode down 4 5 "iwconfig $if domain off"
87 public_freq() {
88 addcode up 4 5 "iwconfig $if freq $*"
91 public_channel() {
92 addcode up 4 5 "iwconfig $if channel $*"
95 public_sens() {
96 addcode up 4 5 "iwconfig $if sens $*"
99 public_mode() {
100 addcode up 4 4 "iwconfig $if mode $*"
101 addcode down 4 4 "iwconfig $if mode Auto"
104 public_ap() {
105 addcode up 4 5 "iwconfig $if ap $*"
106 addcode down 4 5 "iwconfig $if ap any"
109 public_nick() {
110 addcode up 4 5 "iwconfig $if nick $*"
113 public_rate() {
114 addcode up 4 5 "iwconfig $if rate $*"
115 addcode down 4 5 "iwconfig $if rate auto"
118 public_rts() {
119 addcode up 4 5 "iwconfig $if rts $*"
122 public_frag() {
123 addcode up 4 5 "iwconfig $if frag $*"
126 public_key() {
127 addcode up 4 5 "iwconfig $if key $*"
128 addcode down 4 5 "iwconfig $if key off"
131 public_enc() {
132 addcode up 4 5 "iwconfig $if enc $*"
133 addcode down 4 5 "iwconfig $if enc off"
136 public_power() {
137 addcode up 4 5 "iwconfig $if power $*"
140 public_txpower() {
141 addcode up 4 5 "iwconfig $if txpower $*"
142 addcode down 4 5 "iwconfig $if txpower auto"
145 public_retry() {
146 addcode up 4 5 "iwconfig $if retry $*"
149 public_commit() {
150 addcode up 4 9 "iwconfig $if commit"