f2d4c5293dd3b61481a909f6106f85272a4742d7
[openwrt/svn-archive/archive.git] / target / linux / brcm-2.4 / base-files / etc / init.d / netconfig
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006 OpenWrt.org
3
4 START=05
5
6 start() {
7 [ -e /etc/config/network ] && exit 0
8
9 mkdir -p /etc/config
10
11 (
12 if grep -E 'mtd0: 000(6|a)0000' /proc/mtd 2>&- >&-; then
13 # WGT634u
14 echo boardtype=wgt634u
15 else
16 strings /dev/mtdblock/3
17 fi
18 ) | awk '
19 function p(cfgname, name) {
20 if (c[name] != "") print " option " cfgname " \"" c[name] "\""
21 }
22
23 function macinc(mac, maca, i, result) {
24 split(mac, maca, ":")
25 for (i = 1; i <= 6; i++) maca[i] = "0x" maca[i]
26 if (++maca[6] > 0xff) {
27 maca[5]++
28 maca[6] = 0
29 }
30 for (i = 1; i <= 6; i++) {
31 if (i != 1) result = result ":"
32 result = result sprintf("%02x", maca[i])
33 }
34 return result
35 }
36
37 BEGIN {
38 FS="="
39 c["lan_ifname"]="eth0.0"
40 c["wan_ifname"]="eth0.1"
41 c["vlan0ports"]="1 2 3 4 5*"
42 c["vlan1ports"]="0 5"
43 getline < "/proc/diag/model"
44 model=$0
45 for (i = 0; i < 6; i++) {
46 if (mac_check != "") mac_check = mac_check ":"
47 mac_check = mac_check "[0-9a-fA-F][0-9a-fA-F]"
48 }
49 }
50
51 ($1 == "boardnum") || ($1 == "boardtype") || ($1 == "boardflags") || ($1 ~ /macaddr/) {
52 nvram[$1] = $2
53 }
54
55 END {
56 if ((model == "ASUS WL-HDD") || (model == "ASUS WL-300g") || (model == "Linksys WAP54G V1")) {
57 c["wan_ifname"] = ""
58 c["lan_ifname"] = "eth1"
59 }
60 if (nvram["boardtype"] == "bcm94710r4") {
61 # Toshiba WRC-1000
62 c["lan_ifname"] = "eth0"
63 c["wan_ifname"] = "eth1"
64 }
65 if (nvram["boardtype"] == "wgt634u") {
66 c["vlan0ports"] = "0 1 2 3 5*"
67 c["vlan1ports"] = "4 5"
68 }
69 if (nvram["boardtype"] == "0x0467") {
70 c["vlan0ports"] = "0 1 2 3 5*"
71 c["vlan1ports"] = "4 5"
72 }
73 if ((nvram["boardtype"] == "0x042f") || (nvram["boardtype"] == "0x0472")) {
74 if (nvram["boardnum"] == "45") {
75 # WL-500gP
76 c["vlan0ports"] = "1 2 3 4 5*"
77 c["vlan1ports"] = "0 5"
78 } else {
79 # Generic BCM94704
80 c["vlan0ports"] = "0 1 2 3 4 5u"
81 c["vlan1ports"] = ""
82 c["lan_ifname"] = "eth0"
83 c["wan_ifname"] = "eth1"
84
85 # MAC addresses on 4704 tend to be screwed up. Add a workaround here
86 if (nvram["et0macaddr"] ~ mac_check) {
87 c["lan_macaddr"] = nvram["et0macaddr"]
88 c["wan_macaddr"] = macinc(c["lan_macaddr"])
89 }
90 }
91 }
92
93 # WAP54G
94 if ((nvram["boardnum"] == "2") || \
95 (nvram["boardnum"] == "1024")) {
96 c["lan_ifname"]="eth0"
97 c["wan_ifname"]=""
98 }
99
100 print "#### VLAN configuration "
101 print "config switch eth0"
102 p("vlan0", "vlan0ports")
103 p("vlan1", "vlan1ports")
104 print ""
105 print ""
106 print "#### Loopback configuration"
107 print "config interface loopback"
108 print " option ifname \"lo\""
109 print " option proto static"
110 print " option ipaddr 127.0.0.1"
111 print " option netmask 255.0.0.0"
112 print ""
113 print ""
114 print "#### LAN configuration"
115 print "config interface lan"
116 print " option type bridge"
117 p("ifname", "lan_ifname")
118 p("macaddr", "lan_macaddr")
119 print " option proto static"
120 print " option ipaddr 192.168.1.1"
121 print " option netmask 255.255.255.0"
122 print ""
123 print ""
124 print "#### WAN configuration"
125 print "config interface wan"
126 p("ifname", "wan_ifname")
127 p("macaddr", "wan_macaddr")
128 print " option proto dhcp"
129 }' > /etc/config/network
130 }