[package] iptables: fix layer7 patch to place the source in extensions/, I doubt...
[openwrt.git] / package / acx / files / lib / wifi / acx.sh
1 #!/bin/sh
2 append DRIVERS "acx"
3
4 scan_acx() {
5 local device="$1"
6 local adhoc sta ap
7
8 config_get vifs "$device" vifs
9 for vif in $vifs; do
10
11 config_get ifname "$vif" ifname
12 config_set "$vif" ifname "${ifname:-$device}"
13
14 config_get mode "$vif" mode
15 case "$mode" in
16 adhoc|sta|ap|monitor)
17 append $mode "$vif"
18 ;;
19 *) echo "$device($vif): Invalid mode, ignored."; continue;;
20 esac
21 done
22
23 config_set "$device" vifs "${ap:+$ap }${adhoc:+$adhoc }${ahdemo:+$ahdemo }${sta:+$sta }${wds:+$wds }${monitor:+$monitor}"
24 }
25
26
27 disable_acx() (
28 local device="$1"
29
30 set_wifi_down "$device"
31 # kill all running hostapd and wpa_supplicant processes that
32 # are running on atheros/mac80211 vifs
33 for pid in `pidof hostapd wpa_supplicant`; do
34 grep wlan /proc/$pid/cmdline >/dev/null && \
35 kill $pid
36 done
37
38 include /lib/network
39 cd /proc/sys/net
40 for dev in *; do
41 grep "$device" "$dev/%parent" >/dev/null 2>/dev/null && {
42 ifconfig "$dev" down
43 unbridge "$dev"
44 }
45 done
46 return 0
47 )
48
49 enable_acx() {
50 local device="$1"
51 config_get channel "$device" channel
52 config_get vifs "$device" vifs
53 config_get country "$device" country
54
55 local first=1
56 for vif in $vifs; do
57 config_get ifname "$vif" ifname
58 ifconfig "$ifname" down
59 config_get enc "$vif" encryption
60 config_get eap_type "$vif" eap_type
61 config_get mode "$vif" mode
62
63 config_get ifname "$vif" ifname
64 [ $? -ne 0 ] && {
65 echo "enable_acx($device): Failed to set up $mode vif $ifname" >&2
66 continue
67 }
68 config_set "$vif" ifname "$ifname"
69
70 [ "$first" = 1 ] && {
71 # only need to change freq band and channel on the first vif
72 case $country in
73 us)
74 iwpriv "$device" SetRegDomain 1
75 ;;
76 ca)
77 iwpriv "$device" SetRegDomain 2
78 ;;
79 de|uk|be|hu|nl|pt|pl|se|dk)
80 iwpriv "$device" SetRegDomain 3
81 ;;
82 es)
83 iwpriv "$device" SetRegDomain 4
84 ;;
85 fr)
86 iwpriv "$device" SetRegDomain 5
87 ;;
88 jp)
89 iwpriv "$device" SetRegDomain 7
90 ;;
91 il)
92 iwpriv "$device" SetRegDomain 8
93 esac
94
95 iwconfig "$ifname" channel "$channel" >/dev/null 2>/dev/null
96 if [ "$mode" = adhoc ]; then
97 iwlist "$ifname" scan >/dev/null 2>/dev/null
98 sleep 1
99 iwconfig "$ifname" mode ad-hoc >/dev/null 2>/dev/null
100 fi
101 sleep 1
102 iwconfig "$ifname" channel "$channel" >/dev/null 2>/dev/null
103 }
104
105 case "$mode" in
106 sta)
107 iwconfig "$ifname" mode managed >/dev/null 2>/dev/null
108 ;;
109 ap)
110 iwconfig "$ifname" mode master >/dev/null 2>/dev/null
111 ;;
112 *)
113 iwconfig "$ifname" mode $mode >/dev/null 2>/dev/null
114 esac
115
116 wpa=
117 case "$enc" in
118 WEP|wep)
119 for idx in 1 2 3 4; do
120 config_get key "$vif" "key${idx}"
121 iwconfig "$ifname" enc "[$idx]" "${key:-off}"
122 done
123 config_get key "$vif" key
124 key="${key:-1}"
125 case "$key" in
126 [1234]) iwconfig "$ifname" enc restricted "[$key]";;
127 *) iwconfig "$ifname" enc restricted "$key";;
128 esac
129 ;;
130 PSK|psk|PSK2|psk2)
131 echo "WARNING WPA / WPA2 not supported by acx driver"
132 config_get key "$vif" key
133 ;;
134 esac
135
136 case "$mode" in
137 adhoc)
138 config_get addr "$vif" bssid
139 [ -z "$addr" ] || {
140 iwconfig "$ifname" ap "$addr"
141 }
142 ;;
143 esac
144 config_get ssid "$vif" ssid
145
146 config_get txpwr "$vif" txpower
147 if [ -n "$txpwr" ]; then
148 iwconfig "$ifname" txpower "${txpwr%%.*}"
149 fi
150
151 config_get frag "$vif" frag
152 if [ -n "$frag" ]; then
153 iwconfig "$ifname" frag "${frag%%.*}"
154 fi
155
156 config_get rts "$vif" rts
157 if [ -n "$rts" ]; then
158 iwconfig "$ifname" rts "${rts%%.*}"
159 fi
160
161 ifconfig "$ifname" up
162 iwconfig "$ifname" channel "$channel" >/dev/null 2>/dev/null
163
164 local net_cfg bridge
165 net_cfg="$(find_net_config "$vif")"
166 [ -z "$net_cfg" ] || {
167 bridge="$(bridge_interface "$net_cfg")"
168 config_set "$vif" bridge "$bridge"
169 start_net "$ifname" "$net_cfg"
170 }
171 iwconfig "$ifname" essid "$ssid"
172 set_wifi_up "$vif" "$ifname"
173 first=0
174 done
175
176 echo 1 >/sys/class/leds/wifi/brightness
177 }
178
179
180 detect_acx() {
181 cd /sys/class/net
182 for dev in $(ls -d wlan* 2>&-); do
183 config_get type "$dev" type
184 [ "$type" = acx ] && return
185 cat <<EOF
186 config wifi-device $dev
187 option type acx
188 option channel 11
189
190 # REMOVE THIS LINE TO ENABLE WIFI:
191 option disabled 1
192
193 config wifi-iface
194 option device $dev
195 option network lan
196 option mode ap
197 option ssid OpenWrt
198 option encryption none
199 EOF
200 done
201 }
This page took 0.053698 seconds and 5 git commands to generate.