blob: 91e37fcbf592479059b6708012ca0806e7821272 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#!/bin/sh
2#
3# script file to start network
4#
5# Usage: init.sh {gw | ap} {all | bridge | wan}
6#
7
8##if [ $# -lt 2 ]; then echo "Usage: $0 {gw | ap} {all | bridge | wan}"; exit 1 ; fi
9
10
11
12## error code
13ERROR_SUCCESS=0
14ERROR_INVALID_PARAMETERS=1
15ERROR_NO_SUCH_DEVICE=2
16ERROR_NO_CONFIG_FILE=3
17ERROR_NO_SUCH_FILE=4
18ERROR_NO_SUCH_DIRECTORY=5
19ERROR_NULL_FILE=6
20ERROR_NET_IF_UP_FAIL=7
21#CUR_PATH=`pwd`
22
23
24ROOT=`nv get wifi_root_dir`
25LOG=$ROOT/wifi/realtek/slog
26CONFIG_ROOT_DIR="$ROOT/wifi/realtek/rtl8192c"
27
28LOG1=$ROOT/wifi/realtek/slog1
29LOG_LIMIT=128 #128K
30#if [ -e "$LOG"]; then
31 LOG_SIZE=`du $LOG | cut -f1`
32 if [ $LOG_SIZE -ge $LOG_LIMIT ]; then
33 mv $LOG $LOG1
34 fi
35#else
36# touch $LOG
37#fi
38
39SCRIPT_DIR=`cat $CONFIG_ROOT_DIR/wifi_script_dir`
40BIN_DIR=`cat $CONFIG_ROOT_DIR/wifi_bin_dir`
41
42if [ -z "$SCRIPT_DIR" ] || [ -z "$BIN_DIR" ]; then
43 wifi_startup_fail_nvset
44 exit $ERROR_NULL_FILE;
45fi
46if [ ! -d "$SCRIPT_DIR" ]; then
47 echo "ERROR: $SCRIPT_DIR specify the path NOT exist." >> $LOG
48 wifi_startup_fail_nvset
49 exit $ERROR_NO_SUCH_DIRECTORY;
50fi
51if [ ! -d "$BIN_DIR" ]; then
52 echo "ERROR: $BIN_DIR specify the path NOT exist." >> $LOG
53 wifi_startup_fail_nvset
54 exit $ERROR_NO_SUCH_DIRECTORY;
55fi
56
57#PATH=$PATH:$BIN_DIR
58#export PATH
59
60START_BRIDGE=$SCRIPT_DIR/bridge1.sh
61#START_WLAN_APP=$SCRIPT_DIR/wlanapp_8192c.sh
62START_WLAN=$SCRIPT_DIR/wlan_8192c1.sh
63
64WLAN_PREFIX=wlan
65
66# the following fields must manually set depends on system configuration. Not support auto config.
67ROOT_WLAN=wlan0
68ROOT_CONFIG_DIR=$CONFIG_ROOT_DIR/$ROOT_WLAN
69WLAN_INTERFACE=$ROOT_WLAN
70NUM_INTERFACE=0
71#VIRTUAL_WLAN_INTERFACE="$ROOT_WLAN-va0 $ROOT_WLAN-va1 $ROOT_WLAN-va2 $ROOT_WLAN-va3"
72VIRTUAL_WLAN_INTERFACE=""
73NUM_VIRTUAL_INTERFACE=0
74VXD_INTERFACE=""
75ALL_WLAN_INTERFACE="$WLAN_INTERFACE $VIRTUAL_WLAN_INTERFACE $VXD_INTERFACE"
76
77BR_UTIL=brctl
78IFCONFIG=ifconfig
79IWPRIV=iwpriv
80FLASH_PROG=flash
81
82export SCRIPT_DIR
83export BIN_DIR
84export WLAN_PREFIX
85export ROOT_WLAN
86export BR_UTIL
87
88
89wifi_startup_fail_nvset() {
90 date +[%H:%M:%S]init1.shenddddddddddddddddddd >> $LOG
91 echo "wlan0 start failed " >> $LOG
92 echo " " >> $LOG
93}
94rtl_get_available_wlan() {
95 NUM=0
96 VALID_WLAN_INTERFACE=""
97 for WLAN in $WLAN_INTERFACE ; do
98 NOT_EXIST=`$IFCONFIG $WLAN > /dev/null 2>&1; echo $?`
99 if [ $NOT_EXIST = 0 ]; then
100 CONFIG_DIR=$CONFIG_ROOT_DIR/$WLAN
101 if [ ! -d "$CONFIG_DIR" ]; then
102 echo "$CONFIG_DIR: No such directory" >> $LOG
103 wifi_startup_fail_nvset
104 exit $ERROR_NO_CONFIG_FILE
105 fi
106
107 if [ -z "$VALID_WLAN_INTERFACE" ]; then
108 VALID_WLAN_INTERFACE="$WLAN"
109 else
110 VALID_WLAN_INTERFACE="$VALID_WLAN_INTERFACE $WLAN"
111 fi
112 NUM=`expr $NUM + 1`
113 fi
114 done
115
116 if [ "$NUM" = "0" ]; then
117 echo "$WLAN_INTERFACE: No such device" >> $LOG
118 wifi_startup_fail_nvset
119 exit $ERROR_NO_SUCH_DEVICE;
120 fi
121 WLAN_INTERFACE=$VALID_WLAN_INTERFACE
122 NUM_INTERFACE=$NUM
123
124 ALL_WLAN_INTERFACE="$WLAN_INTERFACE"
125}
126
127BR_INTERFACE=br0
128BR_LAN1_INTERFACE=eth0
129
130ENABLE_BR=1
131
132
133# Generate WPS PIN number
134rtl_generate_wps_pin() {
135 for WLAN in $WLAN_INTERFACE ; do
136 CONFIG_DIR=$CONFIG_ROOT_DIR/$WLAN
137 GET_VALUE=`cat $CONFIG_DIR/wsc_pin`
138 if [ "$GET_VALUE" = "00000000" ]; then
139 ##echo "27006672" > $CONFIG_DIR/wsc_pin
140 $BIN_DIR/$FLASH_PROG gen-pin $WLAN
141 $BIN_DIR/$FLASH_PROG gen-pin $WLAN-vxd
142 fi
143 done
144}
145
146rtl_set_mac_addr() {
147 # Set Ethernet 0 MAC address
148 GET_VALUE=`cat $ROOT_CONFIG_DIR/nic0_addr`
149 ELAN_MAC_ADDR=$GET_VALUE
150 $IFCONFIG $BR_LAN1_INTERFACE down
151 $IFCONFIG $BR_LAN1_INTERFACE hw ether $ELAN_MAC_ADDR
152}
153
154# Usage: rtl_has_enable_vap wlan_interface
155rtl_has_enable_vap() {
156 for INTF in $VIRTUAL_WLAN_INTERFACE ; do
157 case $INTF in
158 $1-va[0-9])
159 CONFIG_DIR=$CONFIG_ROOT_DIR/$INTF
160 WLAN_DISABLED_VALUE=`cat $CONFIG_DIR/wlan_disabled`
161 if [ "$WLAN_DISABLED_VALUE" = "0" ]; then
162 return 1
163 fi
164 ;;
165 *)
166 ;;
167 esac
168 done
169
170 return 0
171}
172
173# Start WLAN interface
174rtl_start_wlan_if() {
175 for WLAN in $ALL_WLAN_INTERFACE ; do
176 echo "Initialize $WLAN interface" >> $LOG
177 $IFCONFIG $WLAN down
178
179 case $WLAN in
180 $WLAN_PREFIX[0-9]) #ROOT_INTERFACE
181 NO_VAP=`$IFCONFIG $WLAN-va0 > /dev/null 2>&1; echo $?`
182 if [ $NO_VAP = 0 ]; then
183 rtl_has_enable_vap $WLAN
184 HAS_VAP=`echo $?`
185 $IWPRIV $WLAN set_mib vap_enable=$HAS_VAP
186 echo "$IWPRIV $WLAN set_mib vap_enable=$HAS_VAP" >> $LOG
187 fi
188 ;;
189 $WLAN_PREFIX[0-9]-vxd) ## station interface
190# echo "$IWPRIV $WLAN copy_mib" >> $LOG
191# $IWPRIV $WLAN copy_mib
192# WPA_SUPPLICAT=`ps | grep wpa_supplicant | grep -v grep`
193# echo "SUPPLICAT=$WPA_SUPPLICAT" >> $LOG
194 ;;
195 *)
196 ;;
197 esac
198
199 CONFIG_DIR=$CONFIG_ROOT_DIR/$WLAN
200 WLAN_DISABLED_VALUE=`cat $CONFIG_DIR/wlan_disabled`
201
202 if [ "$WLAN_DISABLED_VALUE" = 0 ]; then
203 echo "<<<${START_WLAN##*/} $WLAN>>>" >> $LOG
204 $START_WLAN $WLAN
205 ERR=`echo $?`
206 if [ $ERR != 0 ]; then
207 echo "$START_WLAN $WLAN failed" >> $LOG
208 wifi_startup_fail_nvset
209 exit $ERR;
210 fi
211 else
212 echo "$WLAN WLAN_DISABLED_VALUE=$WLAN_DISABLED_VALUE" >> $LOG
213 fi
214 done
215}
216
217# Enable WLAN interface
218rtl_enable_wlan_if() {
219 for WLAN in $ALL_WLAN_INTERFACE ; do
220 CONFIG_DIR=$CONFIG_ROOT_DIR/$WLAN
221 WLAN_DISABLED_VALUE=`cat $CONFIG_DIR/wlan_disabled`
222 if [ "$WLAN_DISABLED_VALUE" = 0 ]; then
223 echo "<<<ENABLE $WLAN>>>"
224 IP_ADDR=`cat $CONFIG_DIR/ip_addr`
225 $IFCONFIG $WLAN $IP_ADDR
226 $IFCONFIG $WLAN up
227 if [ $? != 0 ]; then
228 wifi_startup_fail_nvset
229 echo "ERROR ifconfig $WLAN up fail" >> $LOG
230 exit $ERROR_NET_IF_UP_FAIL;
231 fi
232 fi
233 done
234}
235
236rtl_start_no_gw() {
237 echo "<<<${START_BRIDGE##*/} $BR_INTERFACE $BR_LAN1_INTERFACE $WLAN_INTERFACE>>>" >> $LOG
238 $START_BRIDGE $BR_INTERFACE $WLAN_INTERFACE
239 ERR=`echo $?`
240 if [ $ERR != 0 ]; then
241 wifi_startup_fail_nvset
242 exit $ERR;
243 fi
244 #CONFIG_DIR=$CONFIG_ROOT_DIR/$WLAN
245 #GET_WPA_PSK=`cat $CONFIG_DIR/wpa_psk`
246 #echo "222 GET_WPA_PSK is "$GET_WPA_PSK
247 #echo "<<<${START_WLAN_APP##*/} start $WLAN_INTERFACE $VIRTUAL_WLAN_INTERFACE $BR_INTERFACE>>>"
248 #$START_WLAN_APP start $WLAN_INTERFACE $VIRTUAL_WLAN_INTERFACE $BR_INTERFACE
249 #ERR=`echo $?`
250 #if [ $ERR != 0 ]; then
251 # exit $ERR;
252 #fi
253}
254
255
256rtl_init() {
257 date +[%H:%M:%S]init1.shstarttttttttttttttttt >> $LOG
258 killall webs 2> /dev/null
259 $BIN_DIR/webs -x
260
261 echo "realtek rtl_get_available_wlan" >> $LOG
262 rtl_get_available_wlan
263## rtl_set_mac_addr
264
265
266
267 echo "realtek rtl_start_wlan_if" >> $LOG
268 rtl_start_wlan_if
269
270#NO_EXIST=1
271 NO_EXIST=`$BR_UTIL > /dev/null 2>&1; echo $?`
272 if [ "$NO_EXIST" = "127" ]; then
273 echo "$BR_UTIL: NOT exist." >> $LOG
274 rtl_enable_wlan_if
275 else
276 #rtl_generate_wps_pin
277 echo "realtek rtl_start_no_gw" >> $LOG
278 rtl_start_no_gw
279 fi
280
281 #iwpriv wlan0 stopps 1
282 #iwpriv wlan0 set_mib ps_level=0
283
284
285 date +[%H:%M:%S]init1.shenddddddddddddddddddd >> $LOG
286 echo " " >> $LOG
287 echo " " >> $LOG
288}
289
290rtl_init