fcc2630b3fec00df06e301b92a7fc6b9561ccb4e
[openwrt/openwrt.git] / target / linux / ramips / mt76x8 / base-files / etc / board.d / 02_network
1 #!/bin/sh
2
3 . /lib/functions.sh
4 . /lib/functions/uci-defaults.sh
5 . /lib/functions/system.sh
6
7 ramips_setup_interfaces()
8 {
9 local board="$1"
10
11 case $board in
12 alfa-network,awusfree1|\
13 d-team,pbr-d1|\
14 glinet,microuter-n300|\
15 glinet,vixmini|\
16 hak5,wifi-pineapple-mk7|\
17 mediatek,linkit-smart-7688|\
18 onion,omega2p|\
19 onion,omega2|\
20 ravpower,rp-wd009|\
21 tama,w06|\
22 tplink,re200-v2|\
23 tplink,re200-v3|\
24 tplink,re200-v4|\
25 tplink,re220-v2|\
26 tplink,re305-v1|\
27 tplink,tl-mr3020-v3|\
28 tplink,tl-wr802n-v4|\
29 tplink,tl-wa801nd-v5|\
30 widora,neo-16m|\
31 widora,neo-32m)
32 ucidef_add_switch "switch0"
33 ucidef_add_switch_attr "switch0" "enable" "false"
34 ucidef_set_interface_lan "eth0"
35 ;;
36 asus,rt-n10p-v3|\
37 asus,rt-n11p-b1|\
38 asus,rt-n12-vp-b1|\
39 hiwifi,hc5661a|\
40 mediatek,mt7628an-eval-board|\
41 mercury,mac1200r-v2|\
42 totolink,lr1200|\
43 wavlink,wl-wn570ha1|\
44 wavlink,wl-wn575a3)
45 ucidef_add_switch "switch0" \
46 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
47 ;;
48 buffalo,wcr-1166ds|\
49 wavlink,wl-wn577a2)
50 ucidef_add_switch "switch0" \
51 "3:lan" "4:wan" "6@eth0"
52 ;;
53 cudy,wr1000)
54 ucidef_add_switch "switch0" \
55 "2:lan:2" "3:lan:1" "4:wan" "6@eth0"
56 ;;
57 duzun,dm06)
58 ucidef_add_switch "switch0" \
59 "1:lan" "0:wan" "6@eth0"
60 ;;
61 glinet,gl-mt300n-v2)
62 ucidef_add_switch "switch0" \
63 "1:lan" "0:wan" "6@eth0"
64 ;;
65 hilink,hlk-7628n|\
66 hiwifi,hc5861b|\
67 skylab,skw92a|\
68 tplink,archer-c20-v4|\
69 tplink,archer-c20-v5|\
70 tplink,archer-c50-v3|\
71 tplink,archer-c50-v4|\
72 tplink,tl-mr3420-v5|\
73 tplink,tl-wr840n-v4|\
74 tplink,tl-wr840n-v5|\
75 tplink,tl-wr841n-v13|\
76 tplink,tl-wr841n-v14|\
77 tplink,tl-wr842n-v5|\
78 tplink,tl-wr850n-v2|\
79 unielec,u7628-01-16m|\
80 wrtnode,wrtnode2p|\
81 wrtnode,wrtnode2r|\
82 zyxel,keenetic-extra-ii)
83 ucidef_add_switch "switch0" \
84 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
85 ;;
86 hiwifi,hc5761a)
87 ucidef_add_switch "switch0" \
88 "0:lan" "1:lan" "4:wan" "6@eth0"
89 ;;
90 iptime,a3|\
91 totolink,a3)
92 ucidef_add_switch "switch0" \
93 "2:lan:2" "3:lan:1" "0:wan" "6@eth0"
94 ;;
95 iptime,a604m)
96 ucidef_add_switch "switch0" \
97 "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "0:wan" "6@eth0"
98 ;;
99 jotale,js76x8-8m|\
100 jotale,js76x8-16m|\
101 jotale,js76x8-32m)
102 ucidef_add_switch "switch0" \
103 "0:lan" "1:lan" "2:lan" "6@eth0"
104 ;;
105 netgear,r6020|\
106 netgear,r6080|\
107 netgear,r6120)
108 ucidef_add_switch "switch0" \
109 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4:wan" "6@eth0"
110 ;;
111 rakwireless,rak633)
112 ucidef_add_switch "switch0" \
113 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "6t@eth0"
114 ;;
115 tplink,tl-mr6400-v4)
116 ucidef_add_switch "switch0" \
117 "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
118 ;;
119 tplink,tl-mr6400-v5)
120 ucidef_add_switch "switch0" \
121 "0:lan" "1:lan" "2:lan" "3:wan" "6@eth0"
122 ;;
123 tplink,tl-wr902ac-v3)
124 ucidef_add_switch "switch0" \
125 "4:lan" "6@eth0"
126 ;;
127 vocore,vocore2|\
128 vocore,vocore2-lite)
129 ucidef_add_switch "switch0" \
130 "0:lan" "2:lan" "6t@eth0"
131 ;;
132 wiznet,wizfi630s)
133 ucidef_add_switch "switch0" \
134 "0:wan" "3:lan" "4:lan" "6@eth0"
135 ;;
136 xiaomi,mi-router-4a-100m)
137 ucidef_add_switch "switch0" \
138 "4:lan:1" "2:lan:2" "0:wan" "6@eth0"
139 ;;
140 xiaomi,mi-router-4c)
141 ucidef_add_switch "switch0" \
142 "4:lan:1" "2:lan:2" "1:wan" "6@eth0"
143 ;;
144 xiaomi,miwifi-nano)
145 ucidef_add_switch "switch0" \
146 "0:lan:2" "2:lan:1" "4:wan" "6@eth0"
147 ;;
148 zbtlink,zbt-we1226)
149 ucidef_add_switch "switch0" \
150 "0:lan:2" "1:lan:1" "4:wan" "6@eth0"
151 ;;
152 esac
153 }
154
155 ramips_setup_macs()
156 {
157 local board="$1"
158 local lan_mac=""
159 local wan_mac=""
160 local label_mac=""
161
162 case $board in
163 buffalo,wcr-1166ds)
164 local index="$(find_mtd_index "board_data")"
165 wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)"
166 lan_mac=$wan_mac
167 ;;
168 cudy,wr1000|\
169 wavlink,wl-wn577a2)
170 wan_mac=$(mtd_get_mac_binary factory 0x2e)
171 label_mac=$(mtd_get_mac_binary factory 0x4)
172 ;;
173 duzun,dm06|\
174 netgear,r6020|\
175 netgear,r6080|\
176 netgear,r6120|\
177 wrtnode,wrtnode2p|\
178 wrtnode,wrtnode2r|\
179 zyxel,keenetic-extra-ii)
180 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0x4)" 1)
181 ;;
182 hilink,hlk-7628n)
183 lan_mac=$(macaddr_setbit_la "$(cat /sys/class/net/eth0/address)")
184 wan_mac=$(macaddr_add "$lan_mac" 1)
185 ;;
186 hiwifi,hc5661a|\
187 hiwifi,hc5761a|\
188 hiwifi,hc5861b)
189 lan_mac=$(mtd_get_mac_ascii bdinfo "Vfac_mac ")
190 label_mac=$lan_mac
191 [ -n "$lan_mac" ] || lan_mac=$(cat /sys/class/net/eth0/address)
192 wan_mac=$(macaddr_add "$lan_mac" 1)
193 ;;
194 iptime,a3|\
195 iptime,a604m|\
196 totolink,a3)
197 wan_mac=$(mtd_get_mac_binary u-boot 0x1fc40)
198 ;;
199 jotale,js76x8-8m|\
200 jotale,js76x8-16m|\
201 jotale,js76x8-32m|\
202 skylab,skw92a|\
203 totolink,lr1200)
204 wan_mac=$(mtd_get_mac_binary factory 0x2e)
205 ;;
206 mercury,mac1200r-v2)
207 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory_info 0xd)" 1)
208 ;;
209 rakwireless,rak633|\
210 unielec,u7628-01-16m|\
211 wavlink,wl-wn575a3)
212 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0x28)" 1)
213 ;;
214 tplink,archer-c20-v4|\
215 tplink,archer-c50-v3|\
216 tplink,tl-mr3420-v5|\
217 tplink,tl-wr840n-v4|\
218 tplink,tl-wr840n-v5|\
219 tplink,tl-wr841n-v13|\
220 tplink,tl-wr841n-v14|\
221 tplink,tl-wr842n-v5|\
222 tplink,tl-wr850n-v2)
223 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0xf100)" 1)
224 ;;
225 tplink,archer-c20-v5|\
226 tplink,archer-c50-v4)
227 wan_mac=$(macaddr_add "$(mtd_get_mac_binary rom 0xf100)" 1)
228 ;;
229 vocore,vocore2|\
230 vocore,vocore2-lite)
231 label_mac=$(mtd_get_mac_binary factory 0x4)
232 ;;
233 wavlink,wl-wn570ha1|\
234 zbtlink,zbt-we1226)
235 wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0x2e)" 1)
236 ;;
237 wiznet,wizfi630s)
238 label_mac=$(mtd_get_mac_binary factory 0x4)
239 wan_mac=$(mtd_get_mac_binary factory 0x28)
240 ;;
241 xiaomi,mi-router-4a-100m|\
242 xiaomi,mi-router-4c)
243 wan_mac=$(mtd_get_mac_binary factory 0x4)
244 ;;
245 esac
246
247 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
248 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
249 [ -n "$label_mac" ] && ucidef_set_label_macaddr $label_mac
250 }
251
252 board_config_update
253 board=$(board_name)
254 ramips_setup_interfaces $board
255 ramips_setup_macs $board
256 board_config_flush
257
258 exit 0