lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # script file to start bridge |
| 4 | # |
| 5 | # Usage: bridge.sh br_interface lan1_interface wlan_interface[1]..wlan_interface[N] |
| 6 | # |
| 7 | |
| 8 | ## error code |
| 9 | ERROR_SUCCESS=0 |
| 10 | ERROR_INVALID_PARAMETERS=1 |
| 11 | ERROR_NO_SUCH_DEVICE=2 |
| 12 | ERROR_NO_CONFIG_FILE=3 |
| 13 | ERROR_NO_SUCH_FILE=4 |
| 14 | ERROR_NO_SUCH_DIRECTORY=5 |
| 15 | ERROR_NULL_FILE=6 |
| 16 | ERROR_NET_IF_UP_FAIL=7 |
| 17 | ERROR_ADD_BR_FAIL=8 |
| 18 | ERROR_ADD_IF_FAIL=9 |
| 19 | |
| 20 | |
| 21 | if [ $# -lt 2 ]; then |
| 22 | echo "Usage: $0 br_interface lan1_interface wlan_interface ..." >> $LOG |
| 23 | exit $ERROR_INVALID_PARAMETERS; |
| 24 | fi |
| 25 | |
| 26 | |
| 27 | ROOT=`nv get wifi_root_dir` |
| 28 | LOG=$ROOT/wifi/realtek/slog |
| 29 | #CUR_PATH=`pwd` |
| 30 | CONFIG_ROOT_DIR="$ROOT/wifi/realtek/rtl8192c" |
| 31 | |
| 32 | if [ -z "$WLAN_PREFIX" ]; then |
| 33 | WLAN_PREFIX=wlan |
| 34 | fi |
| 35 | |
| 36 | LAN_PREFIX=eth |
| 37 | BR_UTIL=brctl |
| 38 | IFCONFIG=ifconfig |
| 39 | SLEEP=sleep |
| 40 | ## test for to RESTART_BR be 1 |
| 41 | RESTART_BR=0 |
| 42 | RESTART_LAN=0 |
| 43 | RESTART_WLAN=1 |
| 44 | |
| 45 | #set PARA for $i can't pass to function |
| 46 | BR_INTF=$1 |
| 47 | PARA2=$2 |
| 48 | PARA3=$3 |
| 49 | PARA_ALL=$* |
| 50 | |
| 51 | BR_NOT_EXIST=0 |
| 52 | |
| 53 | rtl_shutdown_net_if() { |
| 54 | if [ $BR_NOT_EXIST != 0 ]; then |
| 55 | return; |
| 56 | fi |
| 57 | |
| 58 | # shutdown network interface (ethernet, wlan) |
| 59 | for ARG in $PARA_ALL ; do |
| 60 | case $ARG in |
| 61 | $LAN_PREFIX*) |
| 62 | if [ $RESTART_LAN != 0 ]; then |
| 63 | $IFCONFIG $ARG down |
| 64 | $BR_UTIL delif $BR_INTF $ARG 2> /dev/null |
| 65 | fi |
| 66 | ;; |
| 67 | $WLAN_PREFIX*) |
| 68 | if [ $RESTART_WLAN != 0 ]; then |
| 69 | $IFCONFIG $ARG down |
| 70 | $BR_UTIL delif $BR_INTF $ARG 2> /dev/null |
| 71 | fi |
| 72 | ;; |
| 73 | *) |
| 74 | ;; |
| 75 | esac |
| 76 | done |
| 77 | } |
| 78 | |
| 79 | rtl_enable_net_if() { |
| 80 | # Enable network interface (Ethernet, wlan, WDS, bridge) |
| 81 | if [ $RESTART_BR != 0 ]; then |
| 82 | echo 'Setup bridge...' >> $LOG |
| 83 | if [ $BR_NOT_EXIST != 0 ]; then |
| 84 | $BR_UTIL addbr $BR_INTF |
| 85 | if [ $? != 0 ]; then |
| 86 | echo "Failed: $BR_UTIL addbr $BR_INTF" |
| 87 | exit $ERROR_ADD_BR_FAIL; |
| 88 | fi |
| 89 | fi |
| 90 | #$BR_UTIL setfd $BR_INTF 0 |
| 91 | #$BR_UTIL stp $BR_INTF 0 |
| 92 | fi |
| 93 | #IP_ADDR=`cat $CONFIG_ROOT_DIR/ip_addr` |
| 94 | #SUBNET_MASK=`cat $CONFIG_ROOT_DIR/net_mask` |
| 95 | #$IFCONFIG $BR_INTF $IP_ADDR netmask $SUBNET_MASK |
| 96 | |
| 97 | #Add lan port to bridge interface |
| 98 | if [ $RESTART_LAN != 0 ]; then |
| 99 | for ARG in $PARA_ALL ; do |
| 100 | case $ARG in |
| 101 | $LAN_PREFIX*) |
| 102 | $BR_UTIL addif $BR_INTF $ARG 2> /dev/null |
| 103 | $IFCONFIG $ARG 0.0.0.0 |
| 104 | ;; |
| 105 | *) |
| 106 | ;; |
| 107 | esac |
| 108 | done |
| 109 | fi |
| 110 | |
| 111 | if [ $RESTART_WLAN != 0 ]; then |
| 112 | for ARG in $PARA_ALL ; do |
| 113 | case $ARG in |
| 114 | $WLAN_PREFIX*) |
| 115 | CONFIG_DIR=$CONFIG_ROOT_DIR/$ARG |
| 116 | WLAN_DISABLED_VALUE=`cat $CONFIG_DIR/wlan_disabled` |
| 117 | if [ "$WLAN_DISABLED_VALUE" = 0 ]; then |
| 118 | |
| 119 | |
| 120 | echo "$IFCONFIG $ARG up" >> $LOG |
| 121 | $IFCONFIG $ARG up |
| 122 | if [ $? != 0 ]; then |
| 123 | echo "Failed: $IFCONFIG $ARG up" >> $LOG |
| 124 | exit $ERROR_NET_IF_UP_FAIL; |
| 125 | fi |
| 126 | |
| 127 | echo "$BR_UTIL addif $BR_INTF $ARG" >> $LOG |
| 128 | $BR_UTIL addif $BR_INTF $ARG 2> /dev/null |
| 129 | if [ $? != 0 ]; then |
| 130 | echo "Failed: $BR_UTIL addif $BR_INTF $ARG" >> $LOG |
| 131 | exit $ERROR_ADD_IF_FAIL; |
| 132 | fi |
| 133 | # IP_ADDR=`cat $CONFIG_DIR/ip_addr` |
| 134 | # $IFCONFIG $ARG $IP_ADDR |
| 135 | |
| 136 | #$SLEEP 1 |
| 137 | fi |
| 138 | ;; |
| 139 | *) |
| 140 | ;; |
| 141 | esac |
| 142 | done |
| 143 | fi |
| 144 | } |
| 145 | #end of rtl_enable_net_if |
| 146 | |
| 147 | rtl_bridge() { |
| 148 | BR_NOT_EXIST=`$IFCONFIG $BR_INTF > /dev/null 2>&1; echo $?` |
| 149 | if [ "$PARA3" != "null" ]; then |
| 150 | #rtl_shutdown_net_if |
| 151 | rtl_enable_net_if |
| 152 | fi |
| 153 | } |
| 154 | |
| 155 | |
| 156 | rtl_bridge |
| 157 | |