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