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