blob: c2a325a89c75758d14b1587b14365c2cae9965e8 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#!/bin/sh
2#
3# script file to start WLAN
4#
5if [ $# -lt 3 ]; then echo "Usage: $0 wlan root type"; exit 1 ; fi
6
7#echo "my: [$1] [$2] [$3]"
8
9if [ "$1" == "wlan0" ]; then
10 CONFIG_ROOT_DIR="/var/rtl8192c"
11elif [ "$1" == "wlan1" ]; then
12 CONFIG_ROOT_DIR="/var/rtl8192cd"
13else
14 echo "--interface is not right $1"
15fi
16CONFIG_DIR=$CONFIG_ROOT_DIR/$1
17
18if [ -z "$SCRIPT_DIR" ]; then
19 SCRIPT_DIR=`cat $CONFIG_ROOT_DIR/wifi_script_dir`
20fi
21START_WLAN_APP=$SCRIPT_DIR/wlanapp_8192c.sh
22
23#if [ -z "$ROOT_WLAN" ]; then
24# ROOT_WLAN=`echo $1 | cut -b -5`
25#fi
26
27OP_INTF=$1
28ROOT_WLAN=$2
29EXT=$3
30
31ROOT_CONFIG_DIR=$CONFIG_ROOT_DIR/$ROOT_WLAN
32
33SET_WLAN="iwpriv $1"
34SET_WLAN_PARAM="$SET_WLAN set_mib"
35IFCONFIG=ifconfig
36
37## Disable WLAN MAC driver and shutdown interface first ##
38$IFCONFIG $OP_INTF down
39
40GET_VALUE=
41GET_VALUE_TMP=
42GET_VALUE_WLAN_DISABLED=`cat $CONFIG_DIR/wlan_disabled`
43GET_VALUE_WLAN_MODE=`cat $CONFIG_DIR/wlan_mode`
44
45##$SET_WLAN set_mib vap_enable=0
46
47## kill wlan application daemon ##
48
49##$START_WLAN_APP kill $1
50
51## Set parameters to driver ##
52
53GET_VALUE=`cat $ROOT_CONFIG_DIR/reg_domain`
54$SET_WLAN set_mib regdomain=$GET_VALUE
55
56#EXT=`echo $1 | cut -b 7-8`
57NUM=0
58if [ "$EXT" = "va" ] ; then
59 NUM=${1#w*va};
60 NUM=$((NUM +1))
61# NUM=`echo $1 | cut -b 9`
62# NUM=`expr $NUM + 1`
63fi
64
65GET_VALUE=`cat $ROOT_CONFIG_DIR/wlan${NUM}_addr`
66$IFCONFIG $OP_INTF hw ether $GET_VALUE
67
68IS_ROOT_WLAN=0;
69if [ "$EXT" = "root" ] ; then
70 IS_ROOT_WLAN=1;
71fi
72
73if [ "$GET_VALUE_WLAN_MODE" = '1' ]; then
74 ## client mode
75 GET_VALUE=`cat $CONFIG_DIR/network_type`
76 if [ "$GET_VALUE" = '0' ]; then
77 $SET_WLAN set_mib opmode=8
78 else
79 $SET_WLAN set_mib opmode=32
80 GET_VALUE_TMP=`cat $CONFIG_DIR/default_ssid`
81 $SET_WLAN set_mib defssid="$GET_VALUE_TMP"
82 fi
83else
84 ## AP mode
85 $SET_WLAN set_mib opmode=16
86fi
87##$IFCONFIG $OP_INTF hw ether $WLAN_MAC_ADDR
88
89##if [ "$GET_VALUE_WLAN_MODE" = '2' ]; then
90## $SET_WLAN set_mib wds_pure=1
91##else
92## $SET_WLAN set_mib wds_pure=0
93##fi
94
95# set RF parameters
96if [ $IS_ROOT_WLAN = 1 ]; then
97 GET_VALUE=`cat $CONFIG_DIR/channel`
98 $SET_WLAN set_mib channel=$GET_VALUE
99
100 GET_VALUE=`cat $CONFIG_DIR/ch_hi`
101 $SET_WLAN set_mib ch_hi=$GET_VALUE
102
103 GET_VALUE=`cat $CONFIG_DIR/ch_low`
104 $SET_WLAN set_mib ch_low=$GET_VALUE
105
106 GET_VALUE=`cat $CONFIG_DIR/led_type`
107 $SET_WLAN set_mib led_type=$GET_VALUE
108
109 GET_VALUE=`cat $CONFIG_DIR/MIMO_TR_mode`
110 $SET_WLAN set_mib MIMO_TR_mode=$GET_VALUE
111
112 GET_TX_POWER_CCK_A=`cat $CONFIG_DIR/tx_power_cck_a`
113 GET_TX_POWER_CCK_B=`cat $CONFIG_DIR/tx_power_cck_b`
114 GET_TX_POWER_HT40_1S_A=`cat $CONFIG_DIR/tx_power_ht40_1s_a`
115 GET_TX_POWER_HT40_1S_B=`cat $CONFIG_DIR/tx_power_ht40_1s_b`
116
117 GET_TX_POWER_DIFF_HT40_2S=`cat $CONFIG_DIR/tx_power_diff_ht40_2s`
118 GET_TX_POWER_DIFF_HT20=`cat $CONFIG_DIR/tx_power_diff_ht20`
119 GET_TX_POWER_DIFF_OFDM=`cat $CONFIG_DIR/tx_power_diff_ofdm`
120
121 $SET_WLAN set_mib pwrlevelCCK_A=$GET_TX_POWER_CCK_A
122 $SET_WLAN set_mib pwrlevelCCK_B=$GET_TX_POWER_CCK_B
123 $SET_WLAN set_mib pwrlevelHT40_1S_A=$GET_TX_POWER_HT40_1S_A
124 $SET_WLAN set_mib pwrlevelHT40_1S_B=$GET_TX_POWER_HT40_1S_B
125 $SET_WLAN set_mib pwrdiffHT40_2S=$GET_TX_POWER_DIFF_HT40_2S
126 $SET_WLAN set_mib pwrdiffHT20=$GET_TX_POWER_DIFF_HT20
127 $SET_WLAN set_mib pwrdiffOFDM=$GET_TX_POWER_DIFF_OFDM
128
129 GET_11N_TSSI1=`cat $CONFIG_DIR/tssi_1`
130 $SET_WLAN set_mib tssi1=$GET_11N_TSSI1
131 GET_11N_TSSI2=`cat $CONFIG_DIR/tssi_2`
132 $SET_WLAN set_mib tssi2=$GET_11N_TSSI2
133
134 GET_VALUE=`cat $CONFIG_DIR/11n_ther`
135 $SET_WLAN set_mib ther=$GET_VALUE
136
137 GET_VALUE=`cat $CONFIG_DIR/trswitch`
138 $SET_WLAN set_mib trswitch=$GET_VALUE
139
140 GET_VALUE=`cat $CONFIG_DIR/11n_xcap`
141 $SET_WLAN set_mib xcap=$GET_VALUE
142
143 GET_VALUE=`cat $ROOT_CONFIG_DIR/beacon_interval`
144 $SET_WLAN set_mib bcnint=$GET_VALUE
145
146 GET_VALUE=`cat $CONFIG_DIR/dtim_period`
147 $SET_WLAN set_mib dtimperiod=$GET_VALUE
148fi # [ $IS_ROOT_WLAN = 1 ]
149
150GET_VALUE=`cat $CONFIG_DIR/basic_rates`
151$SET_WLAN set_mib basicrates=$GET_VALUE
152
153GET_VALUE=`cat $CONFIG_DIR/supported_rate`
154$SET_WLAN set_mib oprates=$GET_VALUE
155
156GET_RATE_ADAPTIVE_VALUE=`cat $CONFIG_DIR/rate_adaptive_enabled`
157if [ "$GET_RATE_ADAPTIVE_VALUE" = '0' ]; then
158 $SET_WLAN set_mib autorate=0
159 GET_FIX_RATE_VALUE=`cat $CONFIG_DIR/fix_rate`
160 $SET_WLAN set_mib fixrate=$GET_FIX_RATE_VALUE
161else
162 $SET_WLAN set_mib autorate=1
163fi
164
165GET_VALUE=`cat $CONFIG_DIR/rts_threshold`
166$SET_WLAN set_mib rtsthres=$GET_VALUE
167
168GET_VALUE=`cat $CONFIG_DIR/frag_threshold`
169$SET_WLAN set_mib fragthres=$GET_VALUE
170
171GET_VALUE=`cat $CONFIG_DIR/inactivity_time`
172$SET_WLAN set_mib expired_time=$GET_VALUE
173
174GET_VALUE=`cat $CONFIG_DIR/preamble_type`
175$SET_WLAN set_mib preamble=$GET_VALUE
176
177
178GET_VALUE=`cat $CONFIG_DIR/hidden_ssid`
179$SET_WLAN set_mib hiddenAP=$GET_VALUE
180
181
182if [ "$OP_INTF" = "$ROOT_WLAN-vxd" ]; then
183 GET_VALUE=`cat $CONFIG_ROOT_DIR/repeater_ssid`
184else
185 GET_VALUE=`cat $CONFIG_DIR/ssid`
186fi
187$SET_WLAN set_mib ssid=$GET_VALUE
188
189GET_VALUE=`cat $CONFIG_DIR/macac_enabled`
190$SET_WLAN set_mib aclmode=$GET_VALUE
191$SET_WLAN set_mib aclnum=0
192
193ACL_NUM=`cat $CONFIG_DIR/macac_num`
194ITEM="1 2 3 4 5 6 7 8 9 10"
195#for (( i=1; i<=$ACL_NUM; i=i+1 ))
196if [ "0" != "$ACL_NUM" ]; then
197 for i in $ITEM
198 do
199 #echo "acl $i"
200 GET_VALUE=`cat $CONFIG_DIR/macac_addr$i`
201 $SET_WLAN set_mib acladdr=$GET_VALUE
202 if [ "$i" = "$ACL_NUM" ]; then
203 break;
204 fi
205 done
206fi
207
208GET_WLAN_AUTH_TYPE=`cat $CONFIG_DIR/auth_type`
209AUTH_TYPE=$GET_WLAN_AUTH_TYPE
210GET_WLAN_ENCRYPT=`cat $CONFIG_DIR/encrypt`
211if [ "$GET_WLAN_AUTH_TYPE" = "1" ] && [ "$GET_WLAN_ENCRYPT" != "1" ]; then
212 # shared-key and not WEP enabled, force to open-system
213 AUTH_TYPE=0
214fi
215$SET_WLAN set_mib authtype=$AUTH_TYPE
216
217if [ "$GET_WLAN_ENCRYPT" = "0" ]; then
218 $SET_WLAN set_mib encmode=0
219elif [ "$GET_WLAN_ENCRYPT" = "1" ]; then
220 ### WEP mode ##
221 GET_WEP=`cat $CONFIG_DIR/wep`
222 GET_WEP_KEY_TYPE=`cat $CONFIG_DIR/wep_key_type`
223 GET_WEP_KEY_ID=`cat $CONFIG_DIR/wep_default_key`
224 if [ "$GET_WEP" = "1" ]; then
225 if [ "$GET_WEP_KEY_TYPE" = "0" ]; then
226 GET_WEP_KEY_1=`cat $CONFIG_DIR/wepkey1_64_asc`
227 GET_WEP_KEY_2=`cat $CONFIG_DIR/wepkey2_64_asc`
228 GET_WEP_KEY_3=`cat $CONFIG_DIR/wepkey3_64_asc`
229 GET_WEP_KEY_4=`cat $CONFIG_DIR/wepkey4_64_asc`
230 else
231 GET_WEP_KEY_1=`cat $CONFIG_DIR/wepkey1_64_hex`
232 GET_WEP_KEY_2=`cat $CONFIG_DIR/wepkey2_64_hex`
233 GET_WEP_KEY_3=`cat $CONFIG_DIR/wepkey3_64_hex`
234 GET_WEP_KEY_4=`cat $CONFIG_DIR/wepkey4_64_hex`
235 fi
236
237 $SET_WLAN set_mib encmode=1
238 $SET_WLAN set_mib wepkey1=$GET_WEP_KEY_1
239 $SET_WLAN set_mib wepkey2=$GET_WEP_KEY_2
240 $SET_WLAN set_mib wepkey3=$GET_WEP_KEY_3
241 $SET_WLAN set_mib wepkey4=$GET_WEP_KEY_4
242 $SET_WLAN set_mib wepdkeyid=$GET_WEP_KEY_ID
243 else
244 if [ "$GET_WEP_KEY_TYPE" = "0" ]; then
245 GET_WEP_KEY_1=`cat $CONFIG_DIR/wepkey1_128_asc`
246 GET_WEP_KEY_2=`cat $CONFIG_DIR/wepkey2_128_asc`
247 GET_WEP_KEY_3=`cat $CONFIG_DIR/wepkey3_128_asc`
248 GET_WEP_KEY_4=`cat $CONFIG_DIR/wepkey4_128_asc`
249 else
250 GET_WEP_KEY_1=`cat $CONFIG_DIR/wepkey1_128_hex`
251 GET_WEP_KEY_2=`cat $CONFIG_DIR/wepkey2_128_hex`
252 GET_WEP_KEY_3=`cat $CONFIG_DIR/wepkey3_128_hex`
253 GET_WEP_KEY_4=`cat $CONFIG_DIR/wepkey4_128_hex`
254 fi
255 $SET_WLAN set_mib encmode=5
256 $SET_WLAN set_mib wepkey1=$GET_WEP_KEY_1
257 $SET_WLAN set_mib wepkey2=$GET_WEP_KEY_2
258 $SET_WLAN set_mib wepkey3=$GET_WEP_KEY_3
259 $SET_WLAN set_mib wepkey4=$GET_WEP_KEY_4
260 $SET_WLAN set_mib wepdkeyid=$GET_WEP_KEY_ID
261 fi
262else
263 ## WPA mode ##
264 $SET_WLAN set_mib encmode=2
265fi
266##$SET_WLAN set_mib wds_enable=0
267##$SET_WLAN set_mib wds_encrypt=0
268
269## Set 802.1x flag ##
270_ENABLE_1X=0
271if [ $GET_WLAN_ENCRYPT -lt 2 ]; then
272 GET_ENABLE_1X=`cat $CONFIG_DIR/enable_1x`
273 GET_MAC_AUTH_ENABLED=`cat $CONFIG_DIR/mac_auth_enabled`
274 if [ "$GET_ENABLE_1X" != 0 ] || [ "$GET_MAC_AUTH_ENABLED" != 0 ]; then
275 _ENABLE_1X=1
276 fi
277else
278 _ENABLE_1X=1
279fi
280$SET_WLAN set_mib 802_1x=$_ENABLE_1X
281
282
283#set band
284GET_BAND=`cat $ROOT_CONFIG_DIR/band`
285GET_WIFI_SPECIFIC=`cat $ROOT_CONFIG_DIR/wifi_specific`
286if [ "$GET_VALUE_WLAN_MODE" != '1' ] && [ "$GET_WIFI_SPECIFIC" = 1 ] && [ "$GET_BAND" = '2' ] ; then
287 GET_BAND=3
288fi
289if [ "$GET_BAND" = '8' ]; then
290 GET_BAND=11
291 $SET_WLAN set_mib deny_legacy=3
292elif [ "$GET_BAND" = '2' ]; then
293 GET_BAND=3
294 $SET_WLAN set_mib deny_legacy=1
295elif [ "$GET_BAND" = '10' ]; then
296 GET_BAND=11
297 $SET_WLAN set_mib deny_legacy=1
298else
299 $SET_WLAN set_mib deny_legacy=0
300fi
301$SET_WLAN set_mib band=$GET_BAND
302
303###Set 11n parameter
304if [ $IS_ROOT_WLAN = 1 ]; then
305if [ $GET_BAND = 10 ] || [ $GET_BAND = 11 ] || [ $GET_BAND = 76 ] ; then
306 GET_CHANNEL_BONDING=`cat $CONFIG_DIR/channel_bonding`
307 $SET_WLAN set_mib use40M=$GET_CHANNEL_BONDING
308
309 GET_CONTROL_SIDEBAND=`cat $CONFIG_DIR/control_sideband`
310
311 if [ "$GET_CHANNEL_BONDING" = 0 ]; then
312 $SET_WLAN set_mib 2ndchoffset=0
313 else
314 if [ "$GET_CONTROL_SIDEBAND" = 0 ]; then
315 $SET_WLAN set_mib 2ndchoffset=1
316 fi
317 if [ "$GET_CONTROL_SIDEBAND" = 1 ]; then
318 $SET_WLAN set_mib 2ndchoffset=2
319 fi
320 fi
321
322 GET_SHORT_GI=`cat $CONFIG_DIR/short_gi`
323 $SET_WLAN set_mib shortGI20M=$GET_SHORT_GI
324 $SET_WLAN set_mib shortGI40M=$GET_SHORT_GI
325
326 if [ $GET_BAND = 76 ] ; then
327 $SET_WLAN set_mib shortGI80M=$GET_SHORT_GI
328 fi
329 GET_AGGREGATION=`cat $CONFIG_DIR/aggregation`
330
331 if [ "$GET_AGGREGATION" = 0 ]; then
332 $SET_WLAN set_mib ampdu=$GET_AGGREGATION
333 $SET_WLAN set_mib amsdu=$GET_AGGREGATION
334 elif [ "$GET_AGGREGATION" = 1 ]; then
335 $SET_WLAN set_mib ampdu=1
336 $SET_WLAN set_mib amsdu=0
337 elif [ "$GET_AGGREGATION" = 2 ]; then
338 $SET_WLAN set_mib ampdu=0
339 $SET_WLAN set_mib amsdu=1
340 elif [ "$GET_AGGREGATION" = 3 ]; then
341 $SET_WLAN set_mib ampdu=1
342 $SET_WLAN set_mib amsdu=1
343 fi
344
345 GET_STBC_ENABLED=`cat $CONFIG_DIR/stbc_enabled`
346 $SET_WLAN set_mib stbc=$GET_STBC_ENABLED
347 GET_COEXIST_ENABLED=`cat $CONFIG_DIR/coexist_enabled`
348 $SET_WLAN set_mib coexist=$GET_COEXIST_ENABLED
349fi # [ $GET_BAND = 10 ] || [ $GET_BAND = 11 ]
350fi # [ $IS_ROOT_WLAN = 1 ]
351##########
352
353#set nat2.5 disable when client and mac clone is set
354GET_MACCLONE_ENABLED=`cat $CONFIG_DIR/macclone_enable`
355if [ "$GET_MACCLONE_ENABLED" = '1' -a "$GET_VALUE_WLAN_MODE" = '1' ]; then
356 $SET_WLAN set_mib nat25_disable=1
357 $SET_WLAN set_mib macclone_enable=1
358else
359 $SET_WLAN set_mib nat25_disable=0
360 $SET_WLAN set_mib macclone_enable=0
361fi
362
363# set 11g protection mode
364GET_PROTECTION_DISABLED=`cat $CONFIG_DIR/protection_disabled`
365if [ "$GET_PROTECTION_DISABLED" = '1' ] ;then
366 $SET_WLAN set_mib disable_protection=1
367else
368 $SET_WLAN set_mib disable_protection=0
369fi
370
371# set block relay
372GET_BLOCK_RELAY=`cat $CONFIG_DIR/block_relay`
373$SET_WLAN set_mib block_relay=$GET_BLOCK_RELAY
374
375# set WiFi specific mode
376GET_WIFI_SPECIFIC=`cat $ROOT_CONFIG_DIR/wifi_specific`
377$SET_WLAN set_mib wifi_specific=$GET_WIFI_SPECIFIC
378
379# for WMM
380GET_WMM_ENABLED=`cat $CONFIG_DIR/wmm_enabled`
381$SET_WLAN set_mib qos_enable=$GET_WMM_ENABLED
382
383# for guest access
384GET_ACCESS=`cat $CONFIG_DIR/guest_access`
385$SET_WLAN set_mib guest_access=$GET_ACCESS
386
387
388#
389# following settings is used when driver WPA module is included
390#
391
392GET_WPA_AUTH=`cat $CONFIG_DIR/wpa_auth`
393#if [ $GET_VALUE_WLAN_MODE != 1 ] && [ $GET_WLAN_ENCRYPT -ge 2 ] && [ $GET_WLAN_ENCRYPT -lt 7 ] && [ $GET_WPA_AUTH = 2 ]; then
394if [ $GET_WLAN_ENCRYPT -ge 2 ] && [ $GET_WLAN_ENCRYPT -lt 11 ] && [ $GET_WPA_AUTH = 2 ]; then
395 if [ $GET_WLAN_ENCRYPT = 2 ]; then
396 ENABLE=1
397 elif [ $GET_WLAN_ENCRYPT = 4 ]; then
398 ENABLE=2
399 elif [ $GET_WLAN_ENCRYPT = 6 ]; then
400 ENABLE=3
401 elif [ $GET_WLAN_ENCRYPT = 8 ]; then
402 ENABLE=8
403 elif [ $GET_WLAN_ENCRYPT = 10 ]; then
404 ENABLE=10
405 else
406 echo "invalid ENCRYPT value!"; exit
407 fi
408 $SET_WLAN set_mib psk_enable=$ENABLE
409
410 if [ $GET_WLAN_ENCRYPT = 2 ] || [ $GET_WLAN_ENCRYPT = 6 ] || [ $GET_WLAN_ENCRYPT = 8 ] || [ $GET_WLAN_ENCRYPT = 10 ]; then
411 GET_WPA_CIPHER_SUITE=`cat $CONFIG_DIR/wpa_cipher`
412 if [ $GET_WPA_CIPHER_SUITE = 1 ]; then
413 CIPHER=2
414 elif [ $GET_WPA_CIPHER_SUITE = 2 ]; then
415 CIPHER=8
416 elif [ $GET_WPA_CIPHER_SUITE = 3 ]; then
417 CIPHER=10
418 elif [ $GET_WPA_CIPHER_SUITE = 0 ]; then
419 CIPHER=0
420 else
421 echo "invalid WPA_CIPHER_SUITE value!"; exit 1
422 fi
423 fi
424 $SET_WLAN set_mib wpa_cipher=$CIPHER
425
426 if [ $GET_WLAN_ENCRYPT = 4 ] || [ $GET_WLAN_ENCRYPT = 6 ] || [ $GET_WLAN_ENCRYPT = 8 ] || [ $GET_WLAN_ENCRYPT = 10 ]; then
427 GET_WPA2_CIPHER_SUITE=`cat $CONFIG_DIR/wpa2_cipher`
428 if [ $GET_WPA2_CIPHER_SUITE = 1 ]; then
429 CIPHER=2
430 elif [ $GET_WPA2_CIPHER_SUITE = 2 ]; then
431 CIPHER=8
432 elif [ $GET_WPA2_CIPHER_SUITE = 3 ]; then
433 CIPHER=10
434 elif [ $GET_WPA2_CIPHER_SUITE = 8 ]; then
435 CIPHER=8
436 else
437 echo "invalid WPA2_CIPHER_SUITE value!"; exit 1
438 fi
439 fi
440
441 if [ $GET_WLAN_ENCRYPT = 8 ] || [ $GET_WLAN_ENCRYPT = 10 ]; then
442 if [ $GET_WLAN_ENCRYPT = 8 ]; then
443 $SET_WLAN set_mib dot11IEEE80211W=2
444 else
445 $SET_WLAN set_mib dot11IEEE80211W=1
446 fi
447 $SET_WLAN set_mib enableSHA256=1
448 fi
449
450 $SET_WLAN set_mib wpa2_cipher=$CIPHER
451
452 GET_WPA_PSK=`cat $CONFIG_DIR/wpa_psk`
453 $SET_WLAN set_mib passphrase=$GET_WPA_PSK
454
455
456 GET_WPA_GROUP_REKEY_TIME=`cat $CONFIG_DIR/gk_rekey`
457 $SET_WLAN set_mib gk_rekey=$GET_WPA_GROUP_REKEY_TIME
458else
459 $SET_WLAN set_mib psk_enable=0
460fi