1df83a6a9d8d425dae959518c4a99bc6885763e4
[openwrt.git] / target / linux / lantiq / base-files / etc / uci-defaults / 02_network
1 #!/bin/sh
2 #
3 # Copyright (C) 2011-2012 OpenWrt.org
4 #
5
6 [ -e /etc/config/network ] && exit 0
7
8 set_atm_wan() {
9         local vpi=$1
10         local vci=$2
11         local encaps=$3
12         local payload=$4
13         uci batch <<EOF
14 set network.atm='atm-bridge'
15 set network.atm.vpi='$vpi'
16 set network.atm.vci='$vci'
17 set network.atm.encaps='$encaps'
18 set network.atm.payload='$payload'
19 set network.wan='interface'
20 set network.wan.ifname='nas0'
21 set network.wan.proto='pppoe'
22 set network.wan.username='foo'
23 set network.wan.password='bar'
24 set network.wan.ipv6='1'
25 set network.wan6='interface'
26 set network.wan6.ifname='@wan'
27 set network.wan6.proto='dhcpv6'
28 EOF
29 }
30
31 set_adsl_modem() {
32         local annex=$1
33         local firmware=$2
34         uci batch <<EOF
35 set network.dsl='adsl'
36 set network.dsl.annex='$annex'
37 set network.dsl.firmware='$firmware'
38 EOF
39 }
40
41 set_vdsl_modem() {
42         local annex=$1
43         local firmware=$2
44         local tone=$3
45         local xfer_mode=$4
46         uci batch <<EOF
47 set network.dsl='vdsl'
48 set network.dsl.annex='$annex'
49 set network.dsl.firmware='$firmware'
50 set network.dsl.tone='$tone'
51 set network.dsl.xfer_mode='$xfer_mode'
52 EOF
53 }
54
55 . /lib/functions/uci-defaults.sh
56 . /lib/functions/lantiq.sh
57
58 touch /etc/config/network
59
60 ucidef_set_interface_loopback
61 ucidef_set_interface_lan 'eth0'
62
63 vpi=1
64 vci=32
65 annex="a"
66 encaps="llc"
67 payload="bridged"
68 lan_mac=""
69 wan_mac=""
70
71 board=$(lantiq_board_name)
72
73 case "$board" in
74 # adm6996
75 ARV4510PW)
76         lan_mac=$(mtd_get_mac_ascii uboot_env ethaddr)
77         wan_mac=$(macaddr_add "$lan_mac" 1)
78         ucidef_set_interface_lan "eth0.1"
79         ucidef_add_switch "switch0" "1" "1"
80         ucidef_add_switch_vlan "switch0" "1" "3 2 1 0 5t"
81         ;;
82
83 ARV4520PW)
84         ucidef_set_interface_lan "eth0.1"
85         ucidef_add_switch "switch0" "1" "1"
86         ucidef_add_switch_vlan "switch0" "1" "3 2 1 0 5t"
87         ;;
88
89 ACMP252|GIGASX76X)
90         ucidef_set_interface_lan "eth0.1"
91         ucidef_add_switch "switch0" "1" "1"
92         ucidef_add_switch_vlan "switch0" "1" "4 3 2 1 5t"
93         ;;
94
95 # ar8316
96 ARV4519PW|ARV7510PW22|ARV7518PW|ARV752DPW22)
97         ucidef_set_interface_lan "eth0.1"
98         ucidef_add_switch "switch0" "1" "1"
99         ucidef_add_switch_vlan "switch0" "1" "0t 2 3 4 5"
100         ;;
101
102 # rtl8306g
103 ARV7519PW)
104         lan_mac=$(mtd_get_mac_binary board_config 22)
105         wan_mac=$(macaddr_add "$lan_mac" 1)
106         ucidef_set_interface_lan "eth0.1"
107         ucidef_add_switch "switch0" "1" "1"
108         ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 4t"
109         ;;
110
111 WBMR)
112         ucidef_set_interface_lan "eth0.1"
113         ucidef_add_switch "switch0" "1" "1"
114         ucidef_add_switch_vlan "switch0" "1" "0t 2 3 4 5"
115         ;;
116
117 VG3503J)
118         ucidef_set_interface_lan 'eth0'
119         uci set network.lan.type='none'
120         ;;
121
122 DGN3500*)
123         lan_mac=$(mtd_get_mac_ascii uboot-env ethaddr)
124         wan_mac=$(macaddr_add "$lan_mac" 1)
125         ucidef_set_interface_lan "eth0.1"
126         ucidef_add_switch "switch0" "1" "1"
127         ucidef_add_switch_vlan "switch0" "1" "3 2 1 0 5t"
128         ;;
129
130 GR7000)
131         ucidef_set_interface_wan "eth0"
132         uci set network.lan.ifname=''
133         ;;
134
135 H201L)
136         ucidef_set_interface_lan "eth0.1"
137         ucidef_add_switch "switch0" "1" "1"
138         ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 4t"
139         ;;
140
141 #rtl8306g
142 P2601HNFX)
143         ucidef_set_interface_lan "eth0.1"
144         ucidef_add_switch "switch0" "1" "1"
145         ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t"
146         ;;
147
148 P2812HNUFX)
149         ucidef_set_interface_lan 'eth0.1'
150         ucidef_add_switch "switch0" "1" "1"
151         ucidef_add_switch_vlan "switch0" "1" "0 1 2 4 5 6t"
152         ;;
153
154 TDW8970)
155         lan_mac=$(mtd_get_mac_binary boardconfig 61696)
156         wan_mac=$(macaddr_add "$lan_mac" 1)
157         ucidef_set_interface_lan 'eth0.1'
158         ucidef_add_switch "switch0" "1" "1"
159         ucidef_add_switch_vlan "switch0" "1" "0 2 4 5 6t"
160         ;;
161
162 ARV7519RW22)
163         lan_mac=$(mtd_get_mac_binary boardconfig 22)
164         wan_mac=$(macaddr_add "$lan_mac" 1)
165         ;;
166
167 BTHOMEHUBV2B|BTHOMEHUBV3A)
168         lan_mac=$(mtd_get_mac_ascii uboot_env ethaddr)
169         wan_mac=$(macaddr_add "$lan_mac" 1)
170         ;;
171
172 VGV7519)
173         lan_mac=$(mtd_get_mac_binary board_config 22)
174         wan_mac=$(macaddr_add "$lan_mac" 1)
175         ;;
176
177 esac
178
179 [ -z "$(ls /lib/modules/`uname -r`/ltq_atm*)" ] || set_atm_wan "$vpi" "$vci" "$encaps" "$payload"
180
181 if [ -n "$(grep "system type.*: VR9" /proc/cpuinfo)" ]; then
182         set_vdsl_modem "$annex" "/lib/firmware/vdsl.bin" "av" "ptm"
183 else
184         set_adsl_modem "$annex" "/lib/firmware/adsl.bin"
185 fi
186
187 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr lan $lan_mac
188 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr wan $wan_mac
189
190 uci commit network
191
192 exit 0