blob: 3848dbfec0e274db891249413afec91871ffc4ee [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001#!/bin/sh
2#
3# script file to start wlan applications (IAPP, Auth, Autoconf) daemon
4#
5# Usage: wlanapp.sh [start|kill] wlan_interface...br_interface
6#
7
8## error code
9ERROR_WSCD_START_FAIL=8
10
11if [ $# -lt 2 ] || [ $1 != 'start' -a $1 != 'kill' ] ; then
12 echo "Usage: $0 [start|kill] wlan_interface...br_interface" >> $LOG
13 exit 1
14fi
15#CUR_PATH=`pwd`
16#TOP_VAR_DIR="/etc_ro"
17ROOT=`nv get wifi_root_dir`
18LOG=$ROOT/wifi/realtek/slog
19
20TOP_VAR_DIR="$ROOT/wifi/realtek"
21TOP_ETC_DIR="/etc_ro/realtek/ath"
22TOP_TMP_DIR="$ROOT/tmp"
23CONFIG_ROOT_DIR="$ROOT/wifi/realtek/rtl8192c"
24
25if [ ! -d "$TOP_TMP_DIR" ]; then
26 mkdir $TOP_TMP_DIR
27fi
28
29if [ -z "$BIN_DIR" ]; then
30 BIN_DIR=`cat $CONFIG_ROOT_DIR/wifi_bin_dir`
31fi
32
33if [ -z "$WLAN_PREFIX" ]; then
34 WLAN_PREFIX=wlan
35fi
36#WLAN_PREFIX_LEN=${#WLAN_PREFIX}
37#WLAN_NAME_LEN=$((WLAN_PREFIX_LEN + 1))
38
39if [ -z "$ROOT_WLAN" ]; then
40# ROOT_WLAN=${2:0:$WLAN_NAME_LEN}
41 ROOT_WLAN=${2%%-*}
42fi
43ROOT_CONFIG_DIR=$CONFIG_ROOT_DIR/$ROOT_WLAN
44
45GET_VALUE=
46GET_VALUE_TMP=
47KILLALL=killall
48FLASH_PROG=flash
49SLEEP=sleep
50
51START=1
52PARAM_NUM=$#
53PARAM_ALL=$*
54PARAM1=$1
55PARAM_BR=
56WLAN_INTERFACE=
57
58WLAN0_MODE=
59WLAN0_DISABLED=
60WLAN0_WSC_DISABLED=
61
62WLAN1_MODE=0
63WLAN1_DISABLED=1
64WLAN1_WSC_DISABLED=1
65both_band_ap=0
66
67rtl_check_wlan_band(){
68
69 WLAN0_MODE=`cat $CONFIG_ROOT_DIR/wlan0/wlan_mode`
70 WLAN0_DISABLED=`cat $CONFIG_ROOT_DIR/wlan0/wlan_disabled`
71 WLAN0_WSC_DISABLED=`cat $CONFIG_ROOT_DIR/wlan0/wsc_disabled`
72
73 if [ -d "$CONFIG_ROOT_DIR/wlan1" ] ; then
74 WLAN1_MODE=`cat $CONFIG_ROOT_DIR/wlan1/wlan_mode`
75 WLAN1_DISABLED=`cat $CONFIG_ROOT_DIR/wlan1/wlan_disabled`
76 WLAN1_WSC_DISABLED=`cat $CONFIG_ROOT_DIR/wlan1/wsc_disabled`
77 fi
78
79 if [ "$WLAN0_MODE" = "0" -o "$WLAN0_MODE" = "3" ] && [ "$WLAN1_MODE" = "0" -o "$WLAN1_MODE" = "3" ] && [ "$WLAN0_DISABLED" = "0" ] && [ "$WLAN1_DISABLED" = "0" ] && [ "$WLAN0_WSC_DISABLED" = "0" ] && [ "$WLAN1_WSC_DISABLED" = "0" ]; then
80 both_band_ap = 1
81 fi
82}
83
84rtl_check_wlan_if() {
85
86 echo "wlanapp_8192c.sh --rtl_check_wlan_if" >> $LOG
87
88 if [ $PARAM_NUM -ge 1 ]; then
89 for ARG in $PARAM_ALL ; do
90 case $ARG in
91 $WLAN_PREFIX*)
92 if [ -z "$WLAN_INTERFACE" ]; then
93 WLAN_INTERFACE="$ARG"
94 else
95 WLAN_INTERFACE="$WLAN_INTERFACE $ARG"
96 fi
97 ;;
98 *)
99 PARAM_BR=$ARG
100 ;;
101 esac
102 done
103 fi
104}
105
106DEBUG_EASYCONF=
107VXD_INTERFACE=
108
109
110## kill 802.1x, autoconf and IAPP daemon ##
111rtl_kill_iwcontrol_pid() {
112 PIDFILE="$TOP_VAR_DIR/run/iwcontrol.pid"
113 echo "wlanapp_8192c.sh --rtl_kill_iwcontrol_pid" >> $LOG
114 if [ -f $PIDFILE ] ; then
115 PID=`cat $PIDFILE`
116 echo "IWCONTROL_PID=$PID" >> $LOG
117 if [ "$PID" != "0" ]; then
118 kill -9 $PID 2>/dev/null
119 fi
120 rm -f $PIDFILE
121 fi
122}
123
124
125rtl_kill_wlan_pid() {
126
127 echo "wlanapp_8192c.sh --rtl_kill_wlan_pid" >> $LOG
128 for WLAN in $WLAN_INTERFACE ; do
129 PIDFILE=$TOP_VAR_DIR/run/auth-$WLAN.pid
130 if [ -f $PIDFILE ] ; then
131 PID=`cat $PIDFILE`
132 echo "AUTH_PID=$PID"
133 if [ "$PID" != "0" ]; then
134 kill -9 $PID 2>/dev/null
135 fi
136 rm -f $PIDFILE
137
138 PIDFILE=$TOP_VAR_DIR/run/auth-$WLAN-vxd.pid
139 if [ -f $PIDFILE ] ; then
140 PID=`cat $PIDFILE`
141 if [ "$PID" != "0" ]; then
142 kill -9 $PID 2>/dev/null
143 fi
144 rm -f $PIDFILE
145 fi
146 fi
147
148 # for WPS ---------------------------------->>
149 PIDFILE=$TOP_VAR_DIR/run/wscd-$WLAN.pid
150 if [ "$both_band_ap" = "1" ]; then
151 PIDFILE=$TOP_VAR_DIR/run/wscd-wlan0-wlan1.pid
152 fi
153
154 if [ -f $PIDFILE ] ; then
155 PID=`cat $PIDFILE`
156 echo "WSCD_PID=$PID" >> $LOG
157 if [ "$PID" != "0" ]; then
158 kill -9 $PID 2>/dev/null
159 fi
160 rm -f $PIDFILE
161 fi
162 done
163 #<<----------------------------------- for WPS
164}
165
166## start 802.1x daemon ##
167DEAMON_CREATED=0
168VALID_WLAN_INTERFACE=
169
170
171rtl_start_wlan() {
172 echo "rtl_start_wlan WLAN_INTERFACE is "$WLAN_INTERFACE >> $LOG
173 for WLAN in $WLAN_INTERFACE ; do
174 CONFIG_DIR=$CONFIG_ROOT_DIR/$WLAN
175 echo "rtl_start_wlan start-1------------ CONFIG_DIR is "$CONFIG_DIR >> $LOG
176 GET_VALUE_WLAN_DISABLED=`cat $CONFIG_DIR/wlan_disabled`
177 if [ "$GET_VALUE_WLAN_DISABLED" != 0 ]; then
178 continue
179 fi
180
181 GET_VALUE_WLAN_MODE=`cat $CONFIG_DIR/wlan_mode`
182 GET_WLAN_WPA_AUTH_TYPE=`cat $CONFIG_DIR/wpa_auth`
183 GET_WLAN_ENCRYPT=`cat $CONFIG_DIR/encrypt`
184
185 EXT=${WLAN#$WLAN_PREFIX[0-9]}
186 EXT=${EXT#-}
187 VAP_AUTH_ENABLE=0
188 ROOT_AUTH_ENABLE=0
189
190 _ENABLE_1X=0
191 _USE_RS=0
192
193 if [ "$GET_WLAN_ENCRYPT" -lt 2 ]; then
194 GET_ENABLE_1X=`cat $CONFIG_DIR/enable_1x`
195 GET_MAC_AUTH_ENABLED=`cat $ROOT_CONFIG_DIR/mac_auth_enabled`
196 if [ "$GET_ENABLE_1X" != 0 ] || [ "$GET_MAC_AUTH_ENABLED" != 0 ]; then
197 _ENABLE_1X=1
198 _USE_RS=1
199 fi
200 else
201 _ENABLE_1X=1
202 if [ "$GET_WLAN_WPA_AUTH_TYPE" = 1 ]; then
203 _USE_RS=1
204 fi
205 fi
206
207 echo "_ENABLE_1X= $_ENABLE_1X" >> $LOG
208 ROLE=
209 if [ "$_ENABLE_1X" != 0 ]; then
210 echo "$BIN_DIR/$FLASH_PROG wpa $WLAN $TOP_VAR_DIR/wpa-$WLAN.conf $WLAN" >> $LOG
211 $BIN_DIR/$FLASH_PROG wpa $WLAN $TOP_VAR_DIR/wpa-$WLAN.conf $WLAN
212 if [ "$GET_VALUE_WLAN_MODE" = '1' ]; then
213 GET_VALUE=`cat $CONFIG_DIR/network_type`
214 if [ "$GET_VALUE" = '0' ]; then
215 ROLE=client-infra
216 else
217 ROLE=client-adhoc
218 fi
219 else
220 ROLE=auth
221 fi
222
223 VAP_NOT_IN_PURE_AP_MODE=0
224
225
226 if [ "$GET_VALUE_WLAN_MODE" = '0' ] && [ "$VAP_NOT_IN_PURE_AP_MODE" = '0' ]; then
227 if [ "$GET_WLAN_WPA_AUTH_TYPE" != 2 ] || [ "$_USE_RS" != 0 ]; then
228 echo "$BIN_DIR/auth $WLAN $PARAM_BR $ROLE $TOP_VAR_DIR/wpa-$WLAN.conf" >> $LOG
229 $BIN_DIR/auth $WLAN $PARAM_BR $ROLE $TOP_VAR_DIR/wpa-$WLAN.conf
230
231 DEAMON_CREATED=1
232 ROOT_AUTH_ENABLE=1
233 fi
234
235 fi
236 fi
237
238 if [ "$EXT" = "vxd" ]; then
239 if [ "$ROLE" != "auth" ] || [ "$ROLE" = "auth" -a "$_USE_RS" != 0 ]; then
240 VXD_INTERFACE=$WLAN
241 fi
242 else
243 GET_WSC_DISABLE=`cat $CONFIG_DIR/wsc_disabled`
244 #|| [ $GET_WSC_DISABLE = 0 ]
245 if [ $ROOT_AUTH_ENABLE = 1 ] || [ $GET_WSC_DISABLE = 0 ]; then
246 if [ -z "$VALID_WLAN_INTERFACE" ]; then
247 VALID_WLAN_INTERFACE="$WLAN"
248 else
249 VALID_WLAN_INTERFACE="$VALID_WLAN_INTERFACE $WLAN"
250 fi
251 fi
252 fi
253
254 done
255
256}
257
258#end of start wlan
259
260
261# for WPS ------------------------------------------------->>
262rtl_start_wps() {
263
264
265 if [ ! -e $BIN_DIR/wscd ]; then
266 echo "wscd not exist $BIN_DIR is " $BIN_DIR >> $LOG
267 return;
268 fi
269 echo "rtl_start_wps WLAN is " $WLAN >> $LOG
270 echo "VALID_WLAN_INTERFACE is " $VALID_WLAN_INTERFACE >> $LOG
271
272
273 for WLAN in $VALID_WLAN_INTERFACE ; do
274 EXT=${WLAN#$WLAN_PREFIX[0-9]}
275 EXT=${EXT#-}
276 echo "EXT=$EXT" >> $LOG
277 if [ "$EXT" = "" ] || [ "$EXT" = "va0" ] || [ "$EXT" = "va1" ] || [ "$EXT" = "vxd" ]; then
278
279 USE_IWCONTROL=1
280 DEBUG_ON=0
281 _ENABLE_1X=0
282 WSC=1
283 CONFIG_DIR=$CONFIG_ROOT_DIR/$WLAN
284 CONF_FILE=$TOP_VAR_DIR/wsc-$WLAN.conf
285 FiFO_File=$TOP_VAR_DIR/wscd-$WLAN.fifo
286
287 echo "rtl_start_wps CONFIG_DIR is " $CONFIG_DIR >> $LOG
288
289 GET_WSC_DISABLE=`cat $CONFIG_DIR/wsc_disabled`
290 GET_VALUE_WLAN_DISABLED=`cat $CONFIG_DIR/wlan_disabled`
291 GET_VALUE_WLAN_MODE=`cat $CONFIG_DIR/wlan_mode`
292 GET_WLAN_ENCRYPT=`cat $CONFIG_DIR/encrypt`
293 GET_WLAN_WPA_AUTH_TYPE=`cat $CONFIG_DIR/wpa_auth`
294
295 if [ "$GET_WLAN_ENCRYPT" -lt 2 ]; then
296 GET_ENABLE_1X=`cat $CONFIG_DIR/enable_1x`
297 GET_MAC_AUTH_ENABLED=`cat $CONFIG_DIR/mac_auth_enabled`
298 if [ "$GET_ENABLE_1X" != 0 ] || [ "$GET_MAC_AUTH_ENABLED" != 0 ]; then
299 _ENABLE_1X=1
300 fi
301 else
302 _ENABLE_1X=1
303 fi
304 echo "_ENABLE_1X is " $_ENABLE_1X >> $LOG
305 if [ "$EXT" = "vxd" ]; then
306 GET_VALUE_WLAN_CURR_MODE=`cat $CONFIG_DIR/wlan_mode`
307 if [ $GET_VALUE_WLAN_CURR_MODE = 1 ]; then
308 GET_WSC_DISABLE = 1
309 fi
310 fi
311
312 if [ $GET_WSC_DISABLE != 0 ]; then
313 echo "GET_WSC_DISABLE is " $GET_WSC_DISABLE >> $LOG
314 WSC=0
315 else
316 if [ "$GET_VALUE_WLAN_DISABLED" != 0 ] || [ "$GET_VALUE_WLAN_MODE" = 2 ]; then
317 echo "GET_VALUE_WLAN_DISABLED is "$GET_VALUE_WLAN_DISABLED >> $LOG
318 echo "GET_VALUE_WLAN_MODE is "$GET_VALUE_WLAN_MODE >> $LOG
319 WSC=0
320 else
321 if [ $GET_VALUE_WLAN_MODE = 1 ]; then
322 GET_VALUE=`cat $CONFIG_DIR/network_type`
323 if [ "$GET_VALUE" != 0 ]; then
324 echo "network_type is "$GET_VALUE >> $LOG
325 WSC=0
326 fi
327 fi
328 if [ $GET_VALUE_WLAN_MODE = 0 ]; then
329 if [ $GET_WLAN_ENCRYPT -lt 2 ] && [ $_ENABLE_1X != 0 ]; then
330 echo "GET_WLAN_ENCRYPT is "$GET_WLAN_ENCRYPT >> $LOG
331 echo "_ENABLE_1X is "$_ENABLE_1X >> $LOG
332 WSC=0
333 fi
334 if [ $GET_WLAN_ENCRYPT -ge 2 ] && [ $GET_WLAN_WPA_AUTH_TYPE = 1 ]; then
335 echo "GET_WLAN_ENCRYPT is "$GET_WLAN_ENCRYPT >> $LOG
336 echo "GET_WLAN_WPA_AUTH_TYPE is "$GET_WLAN_WPA_AUTH_TYPE >> $LOG
337 WSC=0
338 fi
339 fi
340 fi
341 fi
342 echo "-----------------WSC is "$WSC >> $LOG
343 if [ $WSC = 1 ]; then
344 if [ ! -f $TOP_VAR_DIR/wps/simplecfgservice.xml ]; then
345 if [ -e $TOP_VAR_DIR/wps ]; then
346 rm $TOP_VAR_DIR/wps -rf
347 fi
348 mkdir $TOP_VAR_DIR/wps
349 #cp $TOP_ETC_DIR/simplecfg*.xml $TOP_VAR_DIR/wps
350 cat $TOP_ETC_DIR/simplecfgservice.xml > $TOP_VAR_DIR/wps/simplecfgservice.xml
351 fi
352
353 if [ $GET_VALUE_WLAN_MODE = 1 ]; then
354 UPNP=0
355 _CMD="-mode 2"
356 else
357 GET_WSC_UPNP_ENABLED=`cat $CONFIG_DIR/wsc_upnp_enabled`
358 UPNP=$GET_WSC_UPNP_ENABLED
359 _CMD="-start"
360 fi
361 WPS_MODE=`cat $CONFIG_DIR/wsc_method`
362 if [ "$WPS_MODE" = "1" ]; then
363 _CMD="$_CMD -method 1"
364 fi
365 echo " UPNP is " $UPNP >> $LOG
366 if [ $UPNP = 1 ]; then
367 route del -net 239.255.255.250 netmask 255.255.255.255 dev "$PARAM_BR"
368 route add -net 239.255.255.250 netmask 255.255.255.255 dev "$PARAM_BR"
369 fi
370
371 if [ "$both_band_ap" = "1" ]; then
372 _CMD="$_CMD -both_band_ap"
373 fi
374 echo "$BIN_DIR/$FLASH_PROG upd-wsc-conf $TOP_ETC_DIR/wscd.conf $CONF_FILE $WLAN" >> $LOG
375 $BIN_DIR/$FLASH_PROG upd-wsc-conf $TOP_ETC_DIR/wscd.conf $CONF_FILE $WLAN
376
377 _CMD="$_CMD -c $CONF_FILE -w $WLAN"
378
379 if [ $DEBUG_ON = 1 ]; then
380 _CMD="$_CMD -debug"
381 fi
382 if [ $USE_IWCONTROL = 1 ]; then
383 _CMD="$_CMD -fi $FiFO_File"
384 DEAMON_CREATED=1
385 echo "DEAMON_CREATED=1" >> $LOG
386 fi
387
388 if [ -f "$TOP_VAR_DIR/wps_start_pbc" ]; then
389 _CMD="$_CMD -start_pbc"
390 rm -f $TOP_VAR_DIR/wps_start_pbc
391 fi
392
393 if [ -f "$TOP_VAR_DIR/wps_start_pin" ]; then
394 _CMD="$_CMD -start"
395 rm -f $TOP_VAR_DIR/wps_start_pin
396 fi
397 if [ -f "$TOP_VAR_DIR/wps_local_pin" ]; then
398 PIN=`cat $TOP_VAR_DIR/wps_local_pin`
399 _CMD="$_CMD -local_pin $PIN"
400 rm -f $TOP_VAR_DIR/wps_local_pin
401 fi
402 if [ -f "$TOP_VAR_DIR/wps_peer_pin" ]; then
403 PIN=`cat $TOP_VAR_DIR/wps_peer_pin`
404 _CMD="$_CMD -peer_pin $PIN"
405 rm -f $TOP_VAR_DIR/wps_peer_pin
406 fi
407 WSC_CMD=$_CMD
408 echo "$BIN_DIR/wscd $WSC_CMD -daemon" >> $LOG
409 $BIN_DIR/wscd $WSC_CMD -daemon
410 echo "<<<<<<<<<<wscd >>>>>>>>>>> over" >> $LOG
411 WAIT=5
412 while [ $USE_IWCONTROL != 0 -a $WAIT != 0 ]
413 do
414 if [ -e $FiFO_File ]; then
415 break;
416 else
417 $SLEEP 1
418 WAIT=`expr $WAIT - 1`
419 #WAIT=$((WAIT - 1))
420 fi
421 done
422 if [ $WAIT = 0 ]; then
423 exit $ERROR_WSCD_START_FAIL;
424 fi
425 fi
426 fi
427 done
428}
429#<<--------------------------------------------------- for WPS
430
431rtl_start_iwcontrol() {
432 echo "rtl_start_iwcontrol" >> $LOG
433 if [ $DEAMON_CREATED = 1 ]; then
434 echo "$BIN_DIR/iwcontrol $VALID_WLAN_INTERFACE $VXD_INTERFACE $POLL" >> $LOG
435 $BIN_DIR/iwcontrol $VALID_WLAN_INTERFACE $VXD_INTERFACE $POLL
436 fi
437}
438
439rtl_wlanapp() {
440
441 echo "rtl_wlanapp" >> $LOG
442
443 if [ $PARAM1 = 'kill' ]; then
444 START=0
445 fi
446 rtl_check_wlan_if
447 if [ -z "$WLAN_INTERFACE" ]; then
448 echo "Error in $0, no wlan interface is given!" >> $LOG
449 exit 0
450 fi
451 rtl_kill_iwcontrol_pid
452 rtl_kill_wlan_pid
453 rm -f $TOP_VAR_DIR/*.fifo
454 if [ $START = 0 ]; then
455 return;
456 fi
457
458# rtl_check_wlan_band
459 rtl_start_wlan
460 rtl_start_wps
461 rtl_start_iwcontrol
462}
463
464rtl_wlanapp