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