finally move buildroot-ng to trunk
[openwrt/staging/dedeckeh.git] / package / broadcom-wl / files / lib / wifi / broadcom.sh
1 bridge_interface() {
2 (
3 . /etc/functions.sh
4 include network
5 scan_interfaces
6 cfg="$(find_config "$1")"
7 [ -z "$cfg" ] && return 0
8 config_get iftype "$cfg" type
9 [ "$iftype" = bridge ] && config_get "$iftype" bridge
10 )
11 }
12
13 scan_broadcom() {
14 local device="$1"
15
16 config_get vifs "$device" vifs
17 for vif in $vifs; do
18 config_get mode "$vif" mode
19 case "$mode" in
20 adhoc)
21 adhoc=1
22 adhoc_if="$vif"
23 ;;
24 sta)
25 sta=1
26 sta_if="$vif"
27 ;;
28 ap)
29 ap=1
30 ap_if="${ap_if:+$ap_if }$vif"
31 ;;
32 *) echo "$device($vif): Invalid mode";;
33 esac
34 done
35
36 local _c=
37 for vif in ${adhoc_if:-$sta_if $ap_if}; do
38 config_set "$vif" ifname "wl0${_c:+.$_c}"
39 _c=$((${_c:-0} + 1))
40 done
41
42 ifdown="down"
43 for vif in 0 1 2 3; do
44 append ifdown "vif $vif" "$N"
45 append ifdown "enabled 0" "$N"
46 done
47
48 ap=1
49 infra=1
50 mssid=1
51 apsta=0
52 radio=1
53 case "$adhoc:$sta:$ap" in
54 1*)
55 ap=0
56 mssid=0
57 infra=0
58 ;;
59 :1:1)
60 apsta=1
61 wet=1
62 ;;
63 :1:)
64 wet=1
65 ap=0
66 mssid=0
67 ;;
68 ::)
69 radio=0
70 ;;
71 esac
72 }
73
74
75 setup_broadcom() {
76 local _c
77 config_get channel "$device" channel
78 config_get country "$device" country
79 config_get maxassoc "$device" maxassoc
80
81 _c=0
82 nas="$(which nas)"
83 nas_cmd=
84 if_up=
85 for vif in ${adhoc_if:-$sta_if $ap_if}; do
86 append vif_pre_up "vif $_c" "$N"
87 append vif_post_up "vif $_c" "$N"
88
89 [ "$vif" = "$sta_if" ] || {
90 config_get_bool hidden "$vif" hidden 1
91 append vif_pre_up "closed $hidden" "$N"
92 config_get_bool isolate "$vif" isolate
93 append vif_pre_up "ap_isolate $hidden" "$N"
94 }
95
96 wsec_r=0
97 eap_r=0
98 wsec=0
99 auth=0
100 nasopts=
101 config_get enc "$vif" encryption
102 case "$enc" in
103 WEP|wep)
104 wsec_r=1
105 ;;
106 *psk*|*PSK*)
107 wsec_r=1
108 config_get key "$vif" key
109 case "$enc" in
110 wpa2*|WPA2*|PSK2*|psk2*) auth=128; wsec=4;;
111 *) auth=4; crypto=2;;
112 esac
113 eval "${vif}_key=\"\$key\""
114 nasopts="-k \"\$${vif}_key\""
115 ;;
116 *wpa*|*WPA*)
117 wsec_r=1
118 eap_r=1
119 config_get key "$vif" key
120 config_get server "$vif" server
121 config_get port "$vif" port
122 case "$enc" in
123 wpa2*|WPA2*) auth=64; wsec=4;;
124 *) auth=2; crypto=2;;
125 esac
126 eval "${vif}_key=\"\$key\""
127 nasopts="-r \"\$${vif}_key\" -h $server -p $port"
128 ;;
129 esac
130 append vif_post_up "wsec $wsec" "$N"
131 append vif_post_up "wpa_auth $auth" "$N"
132 append vif_post_up "wsec_restrict $wsec_r" "$N"
133 append vif_post_up "eap_restrict $eap_r" "$N"
134
135 config_get ssid "$vif" ssid
136 append vif_post_up "vlan_mode 0"
137 append vif_post_up "ssid $ssid" "$N"
138 append vif_post_up "enabled 1" "$N"
139
140 config_get ifname "$vif" ifname
141 append if_up "ifconfig $ifname up" ";$N"
142 [ -z "$nasopts" ] || {
143 bridge="$(bridge_interface "$ifname")"
144 eval "${vif}_ssid=\"\$ssid\""
145 mode="-A"
146 [ "$vif" = "$sta_if" ] && mode="-S"
147 [ -z "$nas" ] || nas_cmd="${nas_cmd:+$nas_cmd$N}$nas -P /var/run/nas.$ifname.pid -H 34954 ${bridge:+ -l $bridge} -i $ifname $mode -m $auth -w $crypto -s \"\$${vif}_ssid\" -g 3600 $nasopts &"
148 }
149 _c=$(($_c + 1))
150 done
151 killall -KILL nas >&- 2>&-
152 wlc stdin <<EOF
153 $ifdown
154
155 mssid $mssid
156 ap $ap
157 apsta $apsta
158 infra $infra
159 ${wet:+wet 1}
160
161 radio ${radio:-1}
162 macfilter 0
163 maclist none
164 wds none
165 channel ${channel:-0}
166 country ${country:-IL0}
167 maxassoc ${maxassoc:-128}
168
169 $vif_pre_up
170 up
171 $vif_post_up
172 EOF
173 eval "$nas_cmd"
174 eval "$if_up"
175 }
176
177