02_network 6.94 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/sh

. /lib/functions.sh
. /lib/functions/uci-defaults.sh
. /lib/functions/system.sh

ramips_setup_interfaces()
{
	local board="$1"

	case $board in
	adslr,g7|\
	afoundry,ew1200|\
	d-team,pbr-m1|\
	firefly,firewrt|\
16
	jcg,jhr-ac876m|\
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
	mediatek,ap-mt7621a-v60|\
	mediatek,mt7621-eval-board|\
	mqmaker,witi|\
	mtc,wr1201|\
	phicomm,k2p|\
	planex,vr500|\
	samknows,whitebox-v8|\
	storylink,sap-g3200u3|\
	telco-electronics,x1|\
	totolink,a7000r|\
	unielec,u7621-06-16m|\
	unielec,u7621-06-64m|\
	xiaoyu,xy-c5|\
	xzwifi,creativebox-v1|\
	youku,yk-l2|\
	zbtlink,zbt-we1326|\
	zbtlink,zbt-we3526|\
	zbtlink,zbt-wg2626|\
	zbtlink,zbt-wg3526-16m|\
	zbtlink,zbt-wg3526-32m)
		ucidef_add_switch "switch0" \
			"0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
		;;
40
41
42
43
	alfa-network,quad-e4g|\
	netgear,r6220|\
	netgear,r6260|\
	netgear,r6350|\
44
	netgear,r6700-v2|\
45
	netgear,r6800|\
46
47
	netgear,r6850|\
	netgear,wndr3700-v5|\
48
	netis,wf2881|\
49
	wevo,11acnas|\
50
51
	wevo,w2914ns-v2|\
	zio,freezio)
52
53
54
		ucidef_add_switch "switch0" \
			"0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4:wan" "6@eth0"
		;;
55
56
57
58
59
60
	asiarf,ap7621-001)
		ucidef_add_switch "switch0" "0:lan" "4:wan" "6@eth0"
		;;
	asiarf,ap7621-nv1)
		ucidef_add_switch "switch0" "0:wan" "2:lan" "3:lan" "6@eth0"
		;;
61
	asus,rt-ac65p|\
62
	asus,rt-ac57u|\
63
	asus,rt-ac85p|\
64
	iptime,a6ns-m|\
65
66
67
68
69
70
71
72
73
74
75
76
	mikrotik,rb750gr3|\
	ubiquiti,edgerouterx|\
	ubiquiti,edgerouterx-sfp|\
	youhua,wr1200js)
		ucidef_add_switch "switch0" \
			"1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "6@eth0"
		;;
	dlink,dir-860l-b1|\
	elecom,wrc-1167ghbk2-s|\
	elecom,wrc-1900gst|\
	elecom,wrc-2533gst|\
	iodata,wn-ax1167gr|\
77
	iodata,wn-ax1167gr2|\
78
	iodata,wn-dx1167r|\
79
	iodata,wn-gx300gr|\
80
81
	iodata,wnpr2600g|\
	iptime,a8004t)
82
83
84
85
86
87
88
89
		ucidef_add_switch "switch0" \
			"1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "0:wan" "6@eth0"
		;;
	buffalo,wsr-1166dhp|\
	buffalo,wsr-600dhp)
		ucidef_add_switch "switch0" \
			"0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "4:wan:5" "6@eth0"
		;;
90
	d-team,newifi-d2)
91
92
93
		ucidef_add_switch "switch0" \
			"0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "4:wan:5" "6@eth0"
		;;
94
	edimax,ra21s|\
95
96
97
98
99
100
101
102
103
104
105
106
107
	edimax,rg21s)
		ucidef_add_switch "switch0" \
			"1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "0:wan" "6@eth0"
		;;
	gehua,ghl-r-001)
		ucidef_add_switch "switch0" \
			"0:lan" "1:lan" "2:lan" "4:wan" "6@eth0"
		;;
	gnubee,gb-pc1|\
	gnubee,gb-pc2)
		ucidef_add_switch "switch0" \
			"0:lan" "4:lan" "6@eth0"
		;;
108
109
110
111
	hiwifi,hc5962)
		ucidef_add_switch "switch0" \
			"1:lan" "2:lan" "3:lan" "4:wan" "6@eth0"
		;;
112
113
114
115
116
117
118
119
120
121
122
123
124
125
	lenovo,newifi-d1)
		ucidef_add_switch "switch0" \
		"1:lan:2" "2:lan:1" "4:wan" "6@eth0"
		;;
	linksys,re6500)
		ucidef_add_switch "switch0" \
			"0:lan:1" "1:lan:2" "2:lan:3" "3:lan:4" "6@eth0"
		;;
	mikrotik,rbm11g|\
	thunder,timecloud)
		ucidef_add_switch "switch0"
		ucidef_add_switch_attr "switch0" "enable" "false"
		ucidef_set_interface_lan "eth0"
		;;
126
127
128
129
	mikrotik,rbm33g)
		ucidef_add_switch "switch0" \
			"1:lan" "2:lan" "0:wan" "6@eth0"
		;;
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
	netgear,ex6150|\
	tplink,re350-v1|\
	tplink,re650-v1)
		ucidef_add_switch "switch0" \
			"0:lan" "6@eth0"
		;;
	xiaomi,mir3g)
		ucidef_add_switch "switch0" \
			"2:lan:2" "3:lan:1" "1:wan" "6t@eth0"
		;;
	xiaomi,mir3g-v2)
		ucidef_add_switch "switch0" \
			"2:lan:2" "3:lan:1" "4:wan" "6@eth0"
		;;
	xiaomi,mir3p)
		ucidef_add_switch "switch0" \
			"1:lan:3" "2:lan:2" "3:lan:1" "4:wan" "6@eth0"
		;;
	*)
		ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
		;;
	esac
}

ramips_setup_macs()
{
	local board="$1"
	local lan_mac=""
	local wan_mac=""
	local label_mac=""

	case $board in
162
163
164
	adslr,g7)
		wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0xe00c)" 1)
		;;
165
166
167
168
169
170
171
172
173
174
175
	afoundry,ew1200|\
	asiarf,ap7621-001|\
	asiarf,ap7621-nv1|\
	firefly,firewrt|\
	gehua,ghl-r-001|\
	mqmaker,witi|\
	totolink,a7000r|\
	unielec,u7621-06-16m|\
	unielec,u7621-06-64m|\
	xzwifi,creativebox-v1|\
	zbtlink,zbt-wg2626)
176
		wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0xe000)" 1)
177
		;;
178
	alfa-network,quad-e4g|\
179
180
181
182
183
184
185
	asus,rt-ac57u|\
	d-team,newifi-d2|\
	d-team,pbr-m1|\
	elecom,wrc-1167ghbk2-s|\
	elecom,wrc-1900gst|\
	elecom,wrc-2533gst|\
	lenovo,newifi-d1|\
186
	netis,wf2881|\
187
188
189
190
191
192
193
194
195
196
197
	phicomm,k2p|\
	planex,vr500|\
	samknows,whitebox-v8|\
	youhua,wr1200js|\
	youku,yk-l2|\
	zbtlink,zbt-we3526)
		wan_mac=$(mtd_get_mac_binary factory 0xe006)
		;;
	asus,rt-ac65p|\
	asus,rt-ac85p)
		wan_mac=$(mtd_get_mac_ascii u-boot-env et1macaddr)
198
		label_mac=$(mtd_get_mac_binary factory 0x4)
199
200
201
202
203
204
205
206
207
		;;
	buffalo,wsr-1166dhp)
		local index="$(find_mtd_index "board_data")"
		wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)"
		lan_mac=$wan_mac
		;;
	dlink,dir-860l-b1)
		lan_mac=$(mtd_get_mac_ascii factory lanmac)
		wan_mac=$(mtd_get_mac_ascii factory wanmac)
208
		label_mac=$(mtd_get_mac_binary radio 0x4)
209
		;;
210
	edimax,ra21s|\
211
212
213
214
215
216
217
218
219
220
221
	edimax,rg21s)
		lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
		wan_mac=$(mtd_get_mac_ascii u-boot-env wanaddr)
		;;
	hiwifi,hc5962)
		lan_mac=$(mtd_get_mac_ascii bdinfo "Vfac_mac ")
		label_mac=$lan_mac
		[ -n "$lan_mac" ] || lan_mac=$(cat /sys/class/net/eth0/address)
		wan_mac=$(macaddr_add "$lan_mac" 1)
		;;
	iodata,wn-ax1167gr|\
222
223
224
225
226
	iodata,wn-gx300gr|\
	mtc,wr1201|\
	netgear,r6220|\
	netgear,wndr3700-v5|\
	xiaoyu,xy-c5)
227
228
		wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0x4)" 1)
		;;
229
	iodata,wn-ax1167gr2|\
230
231
232
233
234
	iodata,wn-dx1167r|\
	xiaomi,mir3g-v2)
		wan_mac=$(mtd_get_mac_binary factory 0xe006)
		label_mac=$wan_mac
		;;
235
236
237
238
	iodata,wnpr2600g)
		wan_mac=$(mtd_get_mac_ascii u-boot-env wanaddr)
		label_mac=$wan_mac
		;;
239
240
	iptime,a6ns-m|\
	iptime,a8004t)
241
242
		wan_mac=$(mtd_get_mac_binary u-boot 0x1fc40)
		;;
243
244
245
246
	jcg,jhr-ac876m)
		label_mac=$(mtd_get_mac_binary factory 0x4)
		wan_mac=$label_mac
		;;
247
248
249
	mediatek,ap-mt7621a-v60)
		wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0x5)" 1)
		;;
250
	mikrotik,rb750gr3|\
251
252
	mikrotik,rbm33g)
		wan_mac=$(macaddr_add "$(mtd_get_mac_binary hard_config 0x10)" 2)
253
		label_mac=$(mtd_get_mac_binary hard_config 0x10)
254
		;;
255
256
	netgear,r6260|\
	netgear,r6350|\
257
	netgear,r6700-v2|\
258
	netgear,r6800|\
259
	netgear,r6850)
260
261
262
263
264
265
266
267
268
		wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0x4)" 2)
		;;
	storylink,sap-g3200u3|\
	telco-electronics,x1)
		wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0xe006)" 1)
		;;
	ubiquiti,edgerouterx|\
	ubiquiti,edgerouterx-sfp)
		wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0x22)" 1)
269
		;;
270
	wevo,11acnas|\
271
272
	wevo,w2914ns-v2|\
	zio,freezio)
273
274
275
		wan_mac=$(mtd_get_mac_binary factory 0x2e)
		label_mac=$wan_mac
		;;
276
277
	xiaomi,mir3g|\
	xiaomi,mir3p)
278
		lan_mac=$(mtd_get_mac_binary factory 0xe006)
279
		label_mac=$lan_mac
280
281
282
		;;
	zbtlink,zbt-we1326)
		wan_mac=$(mtd_get_mac_binary factory 0xe006)
283
		label_mac=$(mtd_get_mac_binary factory 0x4)
284
285
286
		;;
	zbtlink,zbt-wg3526-16m|\
	zbtlink,zbt-wg3526-32m)
287
		wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0xe000)" 1)
288
		label_mac=$(mtd_get_mac_binary factory 0x4)
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
		;;
	esac

	[ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
	[ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
	[ -n "$label_mac" ] && ucidef_set_label_macaddr $label_mac
}

board_config_update
board=$(board_name)
ramips_setup_interfaces $board
ramips_setup_macs $board
board_config_flush

exit 0