ramips: use unified switch identifiers in uci-defaults/network
[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_interfaces()
13 {
14         local board="$1"
15
16         ucidef_set_interface_loopback
17
18         case $board in
19         all0256n)
20                 ucidef_set_interface_lan "eth0.1"
21                 ;;
22
23         argus-atp52b | \
24         b2c | \
25         nw718 | \
26         sl-r7205 | \
27         w502u | \
28         wr6202)
29                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
30                 ;;
31
32         f5d8235-v1)
33                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
34                 ucidef_add_switch "switch0" "1" "1"
35                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
36                 ucidef_add_switch_vlan "switch0" "2" "0 5t"
37                 ;;
38
39         f5d8235-v2)
40                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
41                 ucidef_add_switch "switch0" "1" "1"
42                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
43                 ucidef_add_switch_vlan "switch0" "2" "0 5t"
44                 ;;
45
46         rt-n15)
47                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
48                 ucidef_add_switch "switch0" "1" "1"
49                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
50                 ucidef_add_switch_vlan "switch0" "2" "4 5t"
51                 ;;
52
53         rt-n56u)
54                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
55                 ucidef_add_switch "switch0" "1" "1"
56                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 8t"
57                 ucidef_add_switch_vlan "switch0" "2" "4 8t"
58                 ;;
59
60         v11st-fe)
61                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
62                 ucidef_add_switch "switch0" "1" "1"
63                 ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t"
64                 ucidef_add_switch_vlan "switch0" "2" "0 5t"
65                 ;;
66
67         wcr-150gn)
68                 ucidef_set_interface_lan_wan "eth0.2" "eth0.1"
69                 ;;
70
71         wl-351)
72                 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
73                 ucidef_add_switch "switch0" "1" "1"
74                 ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
75                 ucidef_add_switch_vlan "switch0" "2" "4 5t"
76                 ;;
77
78         wli-tx4-ag300n)
79                 ucidef_set_interface_lan "eth0"
80                 ;;
81
82         *)
83                 RT3X5X=`cat /proc/cpuinfo | grep RT3.5`
84                 if [ -n "${RT3X5X}" ]; then
85                         ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
86                 else
87                         ucidef_set_interfaces_lan_wan "eth0" "eth1"
88                 fi
89                 ;;
90         esac
91 }
92
93 ramips_setup_macs()
94 {
95         local board="$1"
96         local lan_mac=""
97         local wan_mac=""
98
99         case $board in
100         all0256n)
101                 lan_mac=$(ramips_get_mac_binary factory 40)
102                 ;;
103
104         argus-atp52b | \
105         b2c | \
106         f5d8235-v1 | \
107         nw718 | \
108         rt-n15 | \
109         sl-r7205 | \
110         wl-351)
111                 lan_mac=$(ramips_get_mac_binary factory 4)
112                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
113                 ;;
114
115         dir-300-b1 |\
116         dir-300-b2 |\
117         dir-600-b1)
118                 lan_mac=$(ramips_get_mac_binary devdata 16388)
119                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
120                 ;;
121
122         esr-9753 | \
123         nbg-419n | \
124         wcr-150gn)
125                 lan_mac=$(ramips_get_mac_binary factory 4)
126                 wan_mac=$(ramips_get_mac_binary factory 40)
127                 ;;
128
129         f5d8235-v2)
130                 lan_mac=$(ramips_get_mac_binary "u-boot" 262148)
131                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
132                 ;;
133
134         rt-n56u)
135                 lan_mac=$(ramips_get_mac_binary factory 4)
136                 wan_mac=$(ramips_get_mac_binary factory 32772)
137                 ;;
138
139         w502u)
140                 lan_mac=$(ramips_get_mac_binary factory 40)
141                 wan_mac=$(ramips_get_mac_binary factory 46)
142                 ;;
143
144         wl341v3)
145                 lan_mac=$(ramips_get_mac_binary board-nvram 65440)
146                 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
147                 ;;
148
149         wli-tx4-ag300n)
150                 lan_mac=$(ramips_get_mac_binary factory 4)
151                 ;;
152
153         esac
154
155         [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
156         [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
157 }
158
159 [ -e /etc/config/network ] && exit 0
160
161 touch /etc/config/network
162
163 board=$(ramips_board_name)
164
165 ramips_setup_interfaces $board
166 ramips_setup_macs $board
167
168 uci commit network
169
170 exit 0