[ramips] unbreak port mapping detection
[openwrt.git] / target / linux / ramips / base-files / etc / uci-defaults / network
1 #!/bin/sh
2
3 . /etc/functions.sh
4 . /lib/ramips.sh
5 . /lib/functions/uci-defaults.sh
6
7 if [ ! -x /usr/sbin/maccalc ]; then
8         echo "$0: maccalc not found!"
9         return
10 fi
11
12 ramips_setup_rt3x5x_vlans()
13 {
14         if [ ! -x /sbin/swconfig ]; then
15                 # legacy default
16                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
17                 return
18         fi
19         local wanports=""
20         local lanports=""
21         swconfig dev rt305x set reset 1
22         for port in 5 4 3 2 1 0; do
23                 if [ `swconfig dev rt305x port $port get disable` = "1" ]; then
24                         continue
25                 fi
26                 if [ `swconfig dev rt305x port $port get lan` = "0" ]; then
27                         wanports="$port $wanports"
28                 else
29                         lanports="$port $lanports"
30                 fi
31         done
32         ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
33         ucidef_add_switch "rt305x" "1" "1"
34         ucidef_add_switch_vlan "rt305x" "1" "$lanports 6t"
35         ucidef_add_switch_vlan "rt305x" "2" "$wanports 6t"
36 }
37
38 ramips_setup_interfaces()
39 {
40         local board="$1"
41
42         ucidef_set_interface_loopback
43
44         case $board in
45         all0256n | \
46         all5002)
47                 ucidef_set_interface_lan "eth0"
48                 ;;
49
50         dir-615-h1 | \
51         wl-330n)
52                 ucidef_set_interface_lan "eth0.1"
53                 ;;
54
55         3g-6200n | \
56         argus-atp52b | \
57         b2c | \
58         nw718 | \
59         psr-680w | \
60         sl-r7205 | \
61         w502u | \
62         wr6202)
63                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
64                 ;;
65
66         f5d8235-v1 | \
67         f5d8235-v2 | \
68         ur-336un)
69                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
70                 ;;
71
72         v11st-fe)
73                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
74                 ucidef_add_switch "switch0" "1" "1"
75                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
76                 ucidef_add_switch_vlan "switch0" "2" "0 5t"
77                 ;;
78
79         rt-n15 | \
80         wl-351)
81                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
82                 ucidef_add_switch "switch0" "1" "1"
83                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
84                 ucidef_add_switch_vlan "switch0" "2" "4 5t"
85                 ;;
86
87         rt-n56u)
88                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
89                 ucidef_add_switch "switch0" "1" "1"
90                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
91                 ucidef_add_switch_vlan "switch0" "2" "4 8t"
92                 ;;
93
94         freestation5 | \
95         wcr-150gn)
96                 ucidef_set_interfaces_lan_wan "eth0.2" "eth0.1"
97                 ;;
98
99         wli-tx4-ag300n)
100                 ucidef_set_interface_lan "eth0"
101                 ;;
102
103         *)
104                 RT3X5X=`cat /proc/cpuinfo | grep RT3.5`
105                 if [ -n "${RT3X5X}" ]; then
106                         ramips_setup_rt3x5x_vlans
107                 else
108                         ucidef_set_interfaces_lan_wan "eth0" "eth1"
109                 fi
110                 ;;
111         esac
112 }
113
114 ramips_setup_macs()
115 {
116         local board="$1"
117         local lan_mac=""
118         local wan_mac=""
119
120         case $board in
121         all0256n | \
122         all5002 | \
123         dir-615-h1)
124                 lan_mac=$(ramips_get_mac_binary factory 40)
125                 ;;
126         3g-6200n | \
127         argus-atp52b | \
128         bc2 | \
129         f5d8235-v1 | \
130         nw718 | \
131         psr-680w | \
132         rt-n15 | \
133         sl-r7205 | \
134         wl-351)
135                 lan_mac=$(ramips_get_mac_binary factory 4)
136                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
137                 ;;
138
139         w306r-v20)
140                 lan_mac=$(ramips_get_mac_binary factory 4)
141                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 5)
142                 ;;
143
144         fonera20n)
145                 lan_mac=$(ramips_get_mac_binary factory 40)
146                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
147                 ;;
148
149         dir-300-b1 |\
150         dir-300-b2 |\
151         dir-600-b1)
152                 lan_mac=$(ramips_get_mac_binary devdata 16388)
153                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
154                 ;;
155
156         dir-620-a1)
157                 lan_mac=$(ramips_get_mac_binary factory 4)
158                 lan_mac=$(maccalc or "$lan_mac" "02:00:00:00:00:00")
159                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
160                 ;;
161
162         esr-9753 | \
163         ur-336un)
164                 lan_mac=$(ramips_get_mac_binary devdata 16388)
165                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
166                 ;;
167
168         nbg-419n | \
169         wcr-150gn)
170                 lan_mac=$(ramips_get_mac_binary factory 4)
171                 wan_mac=$(ramips_get_mac_binary factory 40)
172                 ;;
173
174         f5d8235-v2)
175                 lan_mac=$(ramips_get_mac_binary "u-boot" 262148)
176                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
177                 ;;
178
179         rt-n56u)
180                 lan_mac=$(ramips_get_mac_binary factory 4)
181                 wan_mac=$(ramips_get_mac_binary factory 32772)
182                 ;;
183
184         all0239-3g | \
185         carambola | \
186         w502u)
187                 lan_mac=$(ramips_get_mac_binary factory 40)
188                 wan_mac=$(ramips_get_mac_binary factory 46)
189                 ;;
190
191         wl341v3)
192                 lan_mac=$(ramips_get_mac_binary board-nvram 65440)
193                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
194                 ;;
195
196         wli-tx4-ag300n)
197                 lan_mac=$(ramips_get_mac_binary factory 4)
198                 ;;
199
200         esac
201
202         [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
203         [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
204 }
205
206 [ -e /etc/config/network ] && exit 0
207
208 touch /etc/config/network
209
210 board=$(ramips_board_name)
211
212 ramips_setup_interfaces $board
213 ramips_setup_macs $board
214
215 uci commit network
216
217 exit 0