(2/6) bcm57xx: netconfig
[librecmc/librecmc.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 "$(find_mtd_part nvram)"
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 (model == "ASUS WL-500g") {
61                         c["wan_ifname"] = "eth1"
62                         c["lan_ifname"] = "eth0"
63                 }
64                 if (model == "ASUS WL-500g Premium V2") {
65                                 c["vlan0ports"] = "0 1 2 3 5*"
66                                 c["vlan1ports"] = "4 5"
67                 }
68
69                 if (model == "Dell TrueMobile 2300") {
70                         c["vlan0ports"] = "0 1 2 3 5*"
71                         c["vlan1ports"] = "4 5"
72                 }
73                 if (nvram["boardtype"] == "bcm94710r4") {
74                         # Toshiba WRC-1000
75                         c["lan_ifname"] = "eth0"
76                         c["wan_ifname"] = "eth1"
77                 }
78                 if (nvram["boardtype"] == "wgt634u") {
79                         c["vlan0ports"] = "0 1 2 3 5*"
80                         c["vlan1ports"] = "4 5"
81                 }
82                 if (nvram["boardtype"] == "0x0467") {
83                         c["vlan0ports"] = "0 1 2 3 5*"
84                         c["vlan1ports"] = "4 5"
85                 }
86                 if ((nvram["boardtype"] == "0x042f") || (nvram["boardtype"] == "0x0472")) {
87                         if (nvram["boardnum"] == "45") {
88                                 # WL-500gP
89                                 c["vlan0ports"] = "1 2 3 4 5*"
90                                 c["vlan1ports"] = "0 5"
91                         } else {
92                                 # Generic BCM94704
93                                 c["vlan0ports"] = "0 1 2 3 4 5u"
94                                 c["vlan1ports"] = ""
95                                 c["lan_ifname"] = "eth0"
96                                 c["wan_ifname"] = "eth1"
97
98                                 # MAC addresses on 4704 tend to be screwed up. Add a workaround here
99                                 if (nvram["et0macaddr"] ~ mac_check) {
100                                         c["lan_macaddr"] = nvram["et0macaddr"]
101                                         c["wan_macaddr"] = macinc(c["lan_macaddr"])
102                                 }
103                         }
104                 }
105                 if (nvram["boardtype"] == "0x478") {
106                         # generic broadcom 4785 processor with 5397 switch?
107                         c["vlan0ports"] = "1 2 3 4 8*"
108                         c["vlan1ports"] = "0 8"
109                 }
110
111                 # WAP54G
112                 if ((nvram["boardnum"] == "2") || \
113                         (nvram["boardnum"] == "1024")) {
114                         c["lan_ifname"]="eth0"
115                         c["wan_ifname"]=""
116                 }
117
118                 # Sitecom WL-105b
119                 if ((nvram["boardum"] == "2") && \
120                         (nvram["GemtekPmonVer"] == "1")) {
121                         c["lan_ifname"]="eth0"
122                         c["wan_ifname"]=""
123                 }
124
125                 # ASUS WL-700gE
126                 # These are actually same as defaults above. For some reason this script applies
127                 # Generic BCM94704 settings instead so we revert to proper settings here.
128                 # Hopefully someone will fix this properly soon.
129                 if (model == "ASUS WL-700gE") {
130                         c["lan_ifname"]="eth0.0"
131                         c["wan_ifname"]="eth0.1"
132                         c["vlan0ports"]="1 2 3 4 5*"
133                         c["vlan1ports"]="0 5"
134                 }
135
136                 if (model == "Motorola WR850G V2/V3") {
137                         c["vlan0ports"]="0 1 2 3 5*"
138                         c["vlan1ports"]="4 5"
139                 }
140                 if (model == "ASUS WL-500W") {
141                         c["lan_ifname"] = "eth0"
142                         c["wan_ifname"] = "eth1"
143                         c["vlan0ports"] = "0 1 2 3 4 5u"
144                         c["vlan1ports"] = ""
145                 }
146
147                 print "#### VLAN configuration "
148                 print "config switch eth0"
149                 p("vlan0", "vlan0ports")
150                 p("vlan1", "vlan1ports")
151                 print ""
152                 print ""
153                 print "#### Loopback configuration"
154                 print "config interface loopback"
155                 print " option ifname   \"lo\""
156                 print " option proto    static"
157                 print " option ipaddr   127.0.0.1"
158                 print " option netmask  255.0.0.0"
159                 print ""
160                 print ""
161                 print "#### LAN configuration"
162                 print "config interface lan"
163                 print " option type     bridge"
164                 p("ifname", "lan_ifname")
165                 p("macaddr", "lan_macaddr")
166                 print " option proto    static"
167                 print " option ipaddr   192.168.1.1"
168                 print " option netmask  255.255.255.0"
169                 print ""
170                 print ""
171                 print "#### WAN configuration"
172                 print "config interface wan"
173                 p("ifname", "wan_ifname")
174                 p("macaddr", "wan_macaddr")
175                 print " option proto    dhcp"
176         }' > /etc/config/network
177 }