/etc/config/wireless support for madwifi (work in progress)
[openwrt/svn-archive/archive.git] / package / madwifi / files / lib / wifi / madwifi.sh
1 #!/bin/sh
2 set -x
3 append DRIVERS "atheros"
4
5 scan_atheros() {
6 local device="$1"
7 local wds
8 local adhoc sta ap
9
10 config_get vifs "$device" vifs
11 for vif in $vifs; do
12
13 config_get ifname "$vif" ifname
14 config_set "$vif" ifname "${ifname:-ath}"
15
16 config_get mode "$vif" mode
17 case "$mode" in
18 adhoc|sta|ap)
19 append $mode "$vif"
20 ;;
21 wds)
22 config_get addr "$vif" bssid
23 ${addr:+append wds "$addr"}
24 ;;
25 *) echo "$device($vif): Invalid mode, ignored."; continue;;
26 esac
27 done
28
29 case "${adhoc:+1}:${sta:+}:${ap+1}" in
30 # valid mode combinations
31 1::);;
32 :1:1)config_set "$device" nosbeacon 1;; # AP+STA, can't use beacon timers for STA
33 :1:);;
34 ::1);;
35 :::);;
36 *) echo "$device: Invalid mode combination in config"; return 1;;
37 esac
38
39 config_set "$device" vifs "${ap:+$ap }${adhoc:+$adhoc }${sta:+$sta }"
40
41 [ -z "$adhoc" ] && config_set "$device" wds "$wdsifs"
42 }
43
44 disable_atheros() (
45 local device="$1"
46
47 include /lib/network
48 cd /proc/sys/net
49 for dev in *; do
50 grep "$device" "$dev/%parent" >/dev/null 2>/dev/null && {
51 ifconfig "$dev" down
52 unbridge "$dev"
53 wlanconfig $dev destroy
54 }
55 done
56 )
57
58 enable_atheros() {
59 config_get channel "$device" channel
60 config_get wds "$device" wds
61 config_get vifs "$device" vifs
62
63 for vif in $vifs; do
64 nosbeacon=
65 config_get ifname "$vif" ifname
66 config_get enc "$vif" encryption
67 config_get mode "$vif" mode
68
69 [ "$mode" = sta ] && config_get nosbeacon "$device" nosbeacon
70
71 config_get ifname "$vif" ifname
72 ifname=$(wlanconfig "$ifname" create wlandev "$device" wlanmode "$mode" ${nosbeacon:+nosbeacon})
73 config_set "$vif" ifname "$ifname"
74
75 [ $? -ne 0 ] && {
76 echo "enable_atheros($device): Failed to set up vif $ifname" >&2
77 continue
78 }
79 wpa=
80 case "$enc" in
81 WEP|wep)
82 for idx in 1 2 3 4; do
83 config_get key "$vif" "key${idx}"
84 iwconfig "$ifname" enc "[$idx]" "${key:-off}"
85 done
86 config_get key "$vif" key
87 iwconfig "$ifname" enc "$key"
88 ;;
89 esac
90 case "$mode" in
91 ap)
92 local hostapd_cfg=
93 case "$enc" in
94 *psk*|*PSK*)
95 # FIXME: wpa
96 ;;
97 *wpa*|*WPA*)
98 # FIXME: add wpa+radius here
99 ;;
100 esac
101 ;;
102 sta)
103 # FIXME: implement wpa_supplicant calls here
104 ;;
105 esac
106
107 config_get ssid "$vif" ssid
108 append if_up "iwconfig $ifname essid $ssid channel $channel" ";$N"
109 append if_up "sleep 1" ";$N"
110 append if_up "ifconfig $ifname up" ";$N"
111
112 local net_cfg bridge
113 net_cfg="$(find_net_config "$vif")"
114 [ -z "$net_cfg" ] || {
115 bridge="$(bridge_interface "$net_cfg")"
116 append if_up "start_net '$ifname' '$net_cfg'" ";$N"
117 }
118 # TODO: start hostapd
119 done
120
121 #killall -KILL $hostapd >&- 2>&-
122 eval "$if_up"
123 }
124
125
126 detect_atheros() {
127 cd /proc/sys/dev
128 [ -d ath ] || return
129 for dev in wifi*; do
130 config_get type "$dev" type
131 [ "$type" = atheros ] && return
132 cat <<EOF
133 config wifi-device $dev
134 option type atheros
135 option channel 5
136
137 config wifi-iface
138 option device $dev
139 option mode ap
140 option ssid OpenWrt
141 option hidden 0
142 option encryption none
143
144 EOF
145 done
146 }
147