Fixed network autoconfiguration as explained in #200, fixes #200
[openwrt/svn-archive/archive.git] / openwrt / target / linux / package / base-files / files / brcm-2.6 / etc / init.d / S05netconfig
1 #!/bin/sh
2 [ -e /etc/config/network ] && exit 0
3
4 mkdir -p /etc/config
5
6 (
7 if [ "$(/usr/bin/head -c4 /dev/mtdblock/1 | /usr/bin/tail -c3)" = "ELF" ]; then
8 # WGT634u
9 echo boardtype=wgt634u
10 else
11 strings /dev/mtdblock/3
12 fi
13 ) | awk '
14 function p(name) {
15 if (c[name] != "") print name "=\"" c[name] "\""
16 }
17
18 BEGIN {
19 FS="="
20 c["lan_ifname"]="br0"
21 c["lan_ifnames"]="vlan0 eth1"
22 c["wan_proto"]="none"
23 c["wan_ifname"]="vlan1"
24 c["vlan0ports"]="1 2 3 4 5*"
25 c["vlan1ports"]="0 5"
26 }
27
28 ($1 == "boardnum") || ($1 == "boardtype") || ($1 == "boardflags") {
29 nvram[$1] = $2
30 }
31
32 END {
33 # v1 hardware
34 if (nvram["boardtype"] == "bcm4710dev") {
35 # Linksys WRT54G v1.x
36 if (nvram["boardnum"] == "42") {
37 c["vlan0ports"]=""
38 c["vlan1ports"]=""
39 c["lan_ifnames"]="vlan2 eth2"
40 }
41
42 # Asus WL-500g
43 if (nvram["boardnum"] == "asusX") {
44 c["lan_ifnames"]="eth0 eth1 eth2" # FIXME
45 # wan_ifname=eth1
46 }
47 }
48 if (nvram["boardtype"] == "wgt634u") {
49 c["vlan0ports"] = "0 1 2 3 5*"
50 c["vlan1ports"] = "4 5"
51 }
52 if (nvram["boardtype"] == "0x0467") {
53 c["vlan0ports"] = "0 1 2 3 5*"
54 c["vlan1ports"] = "4 5"
55 }
56
57 # WAP54G
58 if ((nvram["boardnum"] == "2") || \
59 (nvram["boardnum"] == "1024")) {
60 c["lan_ifnames"]="eth1 eth2"
61 c["wan_ifname"]=""
62 }
63
64 print "#### VLAN configuration "
65 print "vlan0hwname=et0"
66 print "vlan1hwname=et0"
67 p("vlan0ports")
68 p("vlan1ports")
69 print ""
70 print ""
71
72 print "#### LAN configuration"
73 print "lan_proto=\"static\""
74 p("lan_ifname")
75 p("lan_ifnames")
76 print "lan_ipaddr=\"192.168.1.1\""
77 print "# lan_dns=\"192.168.1.1\""
78 print "# lan_gateway=\"192.168.1.1\""
79
80 print ""
81 p("unused_ifnames")
82 print ""
83
84 print "#### WAN configuration"
85 print "# wan_proto: WAN protocol, available protocols:"
86 print "# none: disable"
87 print "# dhcp: DHCP"
88 print "# static: Static IP"
89 print "# pppoe: PPP over Ethernet"
90 print "# pptp: Point-to-Point tunneling Protocol"
91 print "# for pppoe and pptp you need to use wan_ifname=\"ppp0\""
92 print "# and {pppoe,pptp}ifname=\"" c["wan_ifname"] "\")"
93 print ""
94 print "wan_proto=dhcp"
95 p("wan_ifname")
96 print "# wan_ipaddr=\"192.168.0.2\""
97 print "# wan_netmask=\"255.255.255.0\""
98 print "# wan_gateway=\"192.168.0.1\""
99 print "# wan_dns=\"192.168.0.1\""
100 print ""
101 print "## PPP over Ethernet and PPTP"
102 print "# wan_ifname=\"ppp0\""
103 print "# pppoe_ifname=\"" c["wan_ifname"] "\""
104 print "# pptp_ifname=\"" c["wan_ifname"] "\""
105 print "# pptp_server_ip=\"192.168.0.1\""
106 }
107 ' > /etc/config/network