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