ath79: fix leds and network for TP-Link TL-WR841 v9/v11
[openwrt/openwrt.git] / target / linux / ath79 / base-files / etc / board.d / 02_network
1 #!/bin/sh
2
3 . /lib/functions/system.sh
4 . /lib/functions/uci-defaults.sh
5 . /lib/functions/k2t.sh
6
7 ath79_setup_interfaces()
8 {
9 local board="$1"
10
11 case "$board" in
12 avm,fritz300e|\
13 ocedo,koala|\
14 ocedo,raccoon|\
15 pcs,cap324|\
16 pisen,wmm003n|\
17 tplink,re450-v2|\
18 tplink,tl-mr10u|\
19 tplink,tl-mr3020-v1|\
20 tplink,tl-mr3040-v2|\
21 tplink,tl-wr703n|\
22 ubnt,unifiac-lite|\
23 ubnt,unifiac-mesh|\
24 ubnt,unifi)
25 ucidef_set_interface_lan "eth0"
26 ;;
27 buffalo,wzr-hp-g450h)
28 ucidef_add_switch "switch0" \
29 "0@eth0" "2:lan" "3:lan" "4:lan" "5:lan" "1:wan"
30 ;;
31 buffalo,bhr-4grv2)
32 ucidef_add_switch "switch0" \
33 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan" "6@eth0"
34 ;;
35 dlink,dir-825-b1)
36 ucidef_set_interface_wan "eth1"
37 ucidef_add_switch "switch0" \
38 "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0"
39 ;;
40 embeddedwireless,dorin)
41 ucidef_add_switch "switch0" \
42 "0@eth0" "1:wan" "2:lan:3" "3:lan:2"
43 ;;
44 etactica,eg200)
45 ucidef_set_interface_lan "eth0" "dhcp"
46 ;;
47 glinet,ar150|\
48 glinet,ar300m)
49 ucidef_set_interfaces_lan_wan "eth1" "eth0"
50 ;;
51 iodata,wn-ac1600dgr2|\
52 pcs,cr5000)
53 ucidef_add_switch "switch0" \
54 "0@eth0" "1:lan" "2:lan" "3:lan" "4:lan" "5:wan"
55 ;;
56 netgear,wndr3700|\
57 netgear,wndr3700v2|\
58 netgear,wndr3800)
59 ucidef_set_interfaces_lan_wan "eth0" "eth1"
60 ucidef_add_switch "switch0" \
61 "0:lan:4" "1:lan:3" "2:lan:2" "3:lan:1" "5u@eth0"
62 ucidef_add_switch_attr "switch0" "blinkrate" 2
63 ucidef_add_switch_port_attr "switch0" 1 led 6
64 ucidef_add_switch_port_attr "switch0" 2 led 9
65 ucidef_add_switch_port_attr "switch0" 5 led 2
66 ;;
67 netgear,wnr612-v2|\
68 on,n150r)
69 ucidef_set_interface_wan "eth0"
70 ucidef_add_switch "switch0" \
71 "0@eth1" "1:lan" "2:lan" "3:lan:3" "4:lan:4"
72 ;;
73 pcs,cr3000)
74 ucidef_add_switch "switch0" \
75 "0@eth1" "1:lan:1" "2:lan:4" "3:lan:3" "4:lan:2"
76 ucidef_set_interface_wan "eth0"
77 ;;
78 phicomm,k2t)
79 ucidef_add_switch "switch0" \
80 "0@eth0" "3:lan:1" "5:lan:2" "4:wan"
81 ;;
82 tplink,archer-c7-v2|\
83 tplink,tl-wdr4900-v2)
84 ucidef_add_switch "switch0" \
85 "0@eth1" "2:lan" "3:lan" "4:lan" "5:lan" "6@eth0" "1:wan"
86 ;;
87 buffalo,whr-g301n|\
88 tplink,tl-mr3220-v1|\
89 tplink,tl-mr3420-v1|\
90 tplink,tl-wr841-v7)
91 ucidef_set_interface_wan "eth0"
92 ucidef_add_switch "switch0" \
93 "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
94 ;;
95 tplink,tl-wdr3600|\
96 tplink,tl-wdr4300)
97 ucidef_add_switch "switch0" \
98 "0@eth0" "2:lan:1" "3:lan:2" "4:lan:3" "5:lan:4" "1:wan"
99 ;;
100 tplink,tl-wr1043nd-v1)
101 ucidef_add_switch "switch0" \
102 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "5@eth0"
103 ;;
104 tplink,tl-wr1043nd-v2|\
105 tplink,tl-wr1043nd-v3)
106 ucidef_add_switch "switch0" \
107 "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan" "6@eth0"
108 ;;
109 tplink,tl-wr1043nd-v4)
110 ucidef_add_switch "switch0" \
111 "0@eth0" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1" "5:wan"
112 ;;
113 tplink,tl-wr2543-v1)
114 ucidef_add_switch "switch0" \
115 "1:lan" "2:lan" "3:lan" "4:lan" "0:wan" "9@eth0"
116 ;;
117 tplink,tl-wr740n-v1|\
118 tplink,tl-wr740n-v3|\
119 tplink,tl-wr741-v1|\
120 tplink,tl-wr743nd-v1|\
121 tplink,tl-wr841-v5|\
122 tplink,tl-wr941-v4)
123 ucidef_set_interface_wan "eth0"
124 ucidef_add_switch "switch0" \
125 "0@eth1" "1:lan" "2:lan" "3:lan" "4:lan"
126 ;;
127 tplink,tl-wr740nd-v4|\
128 tplink,tl-wr741nd-v4|\
129 tplink,tl-wr841-v9|\
130 tplink,tl-wr841-v11)
131 ucidef_set_interface_wan "eth0"
132 ucidef_add_switch "switch0" \
133 "0@eth1" "1:lan:4" "2:lan:3" "3:lan:2" "4:lan:1"
134 ;;
135 tplink,tl-wr941-v2)
136 ucidef_set_interfaces_lan_wan "lan1 lan2 lan3 lan4" "wan"
137 ;;
138 ubnt,unifiac-mesh-pro|\
139 ubnt,unifiac-pro)
140 ucidef_add_switch "switch0" \
141 "0@eth0" "2:lan" "3:wan"
142 ;;
143 *)
144 ucidef_set_interfaces_lan_wan "eth0" "eth1"
145 ;;
146 esac
147 }
148
149 ath79_setup_macs()
150 {
151 local board="$1"
152
153 case "$board" in
154 avm,fritz300e)
155 lan_mac=$(fritz_tffs -n maca -i $(find_mtd_part "tffs (1)"))
156 ;;
157 dlink,dir-825-b1)
158 lan_mac=$(mtd_get_mac_text "caldata" 65440)
159 wan_mac=$(mtd_get_mac_text "caldata" 65460)
160 ;;
161 iodata,wn-ac1600dgr2)
162 lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
163 wan_mac=$(mtd_get_mac_ascii u-boot-env wanaddr)
164 ;;
165 netgear,wndr3700|\
166 netgear,wndr3700v2|\
167 netgear,wndr3800)
168 lan_mac=$(macaddr_setbit_la "$(mtd_get_mac_binary art 0)")
169 ;;
170 phicomm,k2t)
171 lan_mac=$(k2t_get_mac "lan_mac")
172 wan_mac=$(k2t_get_mac "wan_mac")
173 ;;
174 tplink,tl-wr1043nd-v4)
175 base_mac=$(mtd_get_mac_binary product-info 8)
176 wan_mac=$(macaddr_add "$base_mac" 1)
177 ;;
178 tplink,tl-wr941-v2)
179 base_mac=$(mtd_get_mac_binary u-boot 130048)
180 wan_mac=$(macaddr_add "$base_mac" 1)
181 ;;
182 esac
183
184 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
185 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
186 }
187
188 board_config_update
189 board=$(board_name)
190 ath79_setup_interfaces $board
191 ath79_setup_macs $board
192 board_config_flush
193
194 exit 0