blob: 016759516f5f7ed4da2f2d68a0bc23178f077f2f [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#!/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
9ERROR_SUCCESS=0
10ERROR_INVALID_PARAMETERS=1
11ERROR_NO_SUCH_DEVICE=2
12ERROR_NO_CONFIG_FILE=3
13ERROR_NO_SUCH_FILE=4
14ERROR_NO_SUCH_DIRECTORY=5
15ERROR_NULL_FILE=6
16ERROR_NET_IF_UP_FAIL=7
17ERROR_ADD_BR_FAIL=8
18ERROR_ADD_IF_FAIL=9
19
20
21if [ $# -lt 2 ]; then
22 echo "Usage: $0 br_interface lan1_interface wlan_interface ..." >> $LOG
23 exit $ERROR_INVALID_PARAMETERS;
24fi
25
26
27ROOT=`nv get wifi_root_dir`
28LOG=$ROOT/wifi/realtek/slog
29#CUR_PATH=`pwd`
30CONFIG_ROOT_DIR="$ROOT/wifi/realtek/rtl8192c"
31
32if [ -z "$WLAN_PREFIX" ]; then
33 WLAN_PREFIX=wlan
34fi
35
36LAN_PREFIX=eth
37BR_UTIL=brctl
38IFCONFIG=ifconfig
39SLEEP=sleep
40## test for to RESTART_BR be 1
41RESTART_BR=0
42RESTART_LAN=0
43RESTART_WLAN=1
44
45#set PARA for $i can't pass to function
46BR_INTF=$1
47PARA2=$2
48PARA3=$3
49PARA_ALL=$*
50
51BR_NOT_EXIST=0
52
53rtl_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
79rtl_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
147rtl_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
156rtl_bridge
157