2a8465b9fd4e94dc10153c249e8118aa5bc1ae60
[openwrt.git] / package / madwifi / files / lib / wifi / madwifi.sh
1 #!/bin/sh
2 append DRIVERS "atheros"
3
4 scan_atheros() {
5 local device="$1"
6 local wds
7 local adhoc sta ap
8
9 config_get vifs "$device" vifs
10 for vif in $vifs; do
11
12 config_get ifname "$vif" ifname
13 config_set "$vif" ifname "${ifname:-ath}"
14
15 config_get mode "$vif" mode
16 case "$mode" in
17 adhoc|sta|ap)
18 append $mode "$vif"
19 ;;
20 wds)
21 config_get addr "$vif" bssid
22 config_get ssid "$vif" ssid
23 [ -z "$addr" -a -n "$ssid" ] && {
24 config_set "$vif" wds 1
25 config_set "$vif" mode sta
26 mode="sta"
27 addr="$ssid"
28 }
29 ${addr:+append $mode "$vif"}
30 ;;
31 *) echo "$device($vif): Invalid mode, ignored."; continue;;
32 esac
33 done
34
35 case "${adhoc:+1}:${sta:+1}:${ap+1}" in
36 # valid mode combinations
37 1::) wds="";;
38 :1:1)config_set "$device" nosbeacon 1;; # AP+STA, can't use beacon timers for STA
39 :1:);;
40 ::1);;
41 :::);;
42 *) echo "$device: Invalid mode combination in config"; return 1;;
43 esac
44
45 config_set "$device" vifs "${ap:+$ap }${adhoc:+$adhoc }${sta:+$sta }${wds:+$wds }"
46 }
47
48
49 disable_atheros() (
50 local device="$1"
51
52 # kill all running hostapd and wpa_supplicant processes that
53 # are running on atheros vifs
54 for pid in `pidof hostapd wpa_supplicant`; do
55 grep ath /proc/$pid/cmdline >/dev/null && \
56 kill $pid
57 done
58
59 include /lib/network
60 cd /proc/sys/net
61 for dev in *; do
62 grep "$device" "$dev/%parent" >/dev/null 2>/dev/null && {
63 ifconfig "$dev" down
64 unbridge "$dev"
65 wlanconfig "$dev" destroy
66 }
67 done
68 return 0
69 )
70
71 enable_atheros() {
72 config_get channel "$device" channel
73 config_get vifs "$device" vifs
74
75 disable_atheros "$device"
76 for vif in $vifs; do
77 nosbeacon=
78 config_get ifname "$vif" ifname
79 config_get enc "$vif" encryption
80 config_get mode "$vif" mode
81
82 [ "$mode" = sta ] && config_get nosbeacon "$device" nosbeacon
83
84 config_get ifname "$vif" ifname
85 ifname=$(wlanconfig "$ifname" create wlandev "$device" wlanmode "$mode" ${nosbeacon:+nosbeacon})
86 [ $? -ne 0 ] && {
87 echo "enable_atheros($device): Failed to set up $mode vif $ifname" >&2
88 continue
89 }
90 config_set "$vif" ifname "$ifname"
91
92 config_get "$device" mode
93 iwpriv "$ifname" mode "${mode:-11g}"
94
95 config_get wds "$vif" wds
96 case "$wds" in
97 1|on|enabled) wds=1;;
98 *) wds=0;;
99 esac
100 iwpriv "$ifname" wds "$wds"
101
102 wpa=
103 case "$enc" in
104 WEP|wep)
105 for idx in 1 2 3 4; do
106 config_get key "$vif" "key${idx}"
107 iwconfig "$ifname" enc "[$idx]" "${key:-off}"
108 done
109 config_get key "$vif" key
110 iwconfig "$ifname" enc "[${key:-1}]"
111 ;;
112 esac
113
114 case "$mode" in
115 wds)
116 config_get addr "$vif" bssid
117 iwpriv "$ifname" wds_add "$addr"
118 ;;
119 *)
120 config_get ssid "$vif" ssid
121 ;;
122 esac
123 iwconfig "$ifname" channel "$channel"
124 ifconfig "$ifname" up
125
126 local net_cfg bridge
127 net_cfg="$(find_net_config "$vif")"
128 [ -z "$net_cfg" ] || {
129 bridge="$(bridge_interface "$net_cfg")"
130 config_set "$vif" bridge "$bridge"
131 start_net "$ifname" "$net_cfg"
132 }
133 case "$mode" in
134 ap)
135 hostapd_setup_vif "$vif" madwifi || {
136 echo "enable_atheros($device): Failed to set up wpa for interface $ifname" >&2
137 # make sure this wifi interface won't accidentally stay open without encryption
138 ifconfig "$ifname" down
139 wlanconfig "$ifname" destroy
140 continue
141 }
142 ;;
143 wds|sta)
144 iwconfig "$ifname" essid "$ssid"
145 # FIXME: implement wpa_supplicant calls here
146 ;;
147 esac
148 done
149 }
150
151
152 detect_atheros() {
153 cd /proc/sys/dev
154 [ -d ath ] || return
155 for dev in wifi*; do
156 config_get type "$dev" type
157 [ "$type" = atheros ] && return
158 cat <<EOF
159 config wifi-device $dev
160 option type atheros
161 option channel 5
162
163 config wifi-iface
164 option device $dev
165 # option network lan
166 option mode ap
167 option ssid OpenWrt
168 option hidden 0
169 option encryption none
170
171 EOF
172 done
173 }
174
This page took 0.047401 seconds and 3 git commands to generate.