brcm47xx: migrate network config to board detection framework
[openwrt/svn-archive/archive.git] / target / linux / brcm47xx / base-files / etc / board.d / 01_detect
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006-2015 OpenWrt.org
3
4 . /lib/functions/system.sh
5 . /lib/functions/uci-defaults-new.sh
6
7 detect_by_vlanports() {
8 local vlan0ports="$(nvram get vlan0ports)"
9 local vlan1ports="$(nvram get vlan1ports)"
10 local vlan2ports="$(nvram get vlan2ports)"
11 local cpuport="$(swconfig dev switch0 help 2>/dev/null | sed -ne "s|.*cpu @ \([0-9]*\).*|\1|p")"
12
13 if [ "${vlan0ports:0:9}" = "0 1 2 3 8" -a "${vlan1ports:0:3}" = "4 8" -a ${cpuport:-0} -eq 8 ] || \
14 [ "${vlan1ports:0:9}" = "0 1 2 3 8" -a "${vlan2ports:0:3}" = "4 8" -a ${cpuport:-0} -eq 8 ] || \
15 [ "${vlan2ports:0:9}" = "0 1 2 3 8" -a "${vlan1ports:0:3}" = "4 8" -a ${cpuport:-0} -eq 8 ];
16 then
17 ucidef_add_switch "switch0" \
18 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "8@eth0"
19
20 elif [ "${vlan0ports:0:9}" = "0 1 2 3 5" -a "${vlan1ports:0:3}" = "4 5" -a ${cpuport:-0} -eq 5 ] || \
21 [ "${vlan1ports:0:9}" = "0 1 2 3 5" -a "${vlan2ports:0:3}" = "4 5" -a ${cpuport:-0} -eq 5 ] || \
22 [ "${vlan2ports:0:9}" = "0 1 2 3 5" -a "${vlan1ports:0:3}" = "4 5" -a ${cpuport:-0} -eq 5 ];
23 then
24 ucidef_add_switch "switch0" \
25 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
26
27 else
28 logger -t "01_detect" "Unable to determine network configuration"
29 ucidef_set_interface_lan "eth0"
30 fi
31 }
32
33 detect_by_boardnum() {
34 local boardnum="$1"
35
36 case "$boardnum" in
37 # WAP54G, Sitecom WL-105b
38 "2" | \
39 "1024")
40 ucidef_set_interface_lan "eth0"
41 ;;
42
43 # Generic detection fallback
44 *)
45 detect_by_vlanports
46 ;;
47 esac
48 }
49
50 detect_by_boardtype() {
51 local boardtype="$1"
52 local boardnum="$2"
53
54 case "$boardtype" in
55 "bcm94710r4")
56 ucidef_set_interfaces_lan_wan "eth0" "eth1"
57 ;;
58
59 "0x0467")
60 ucidef_add_switch "switch0" \
61 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
62 ;;
63
64 "0x042f" | \
65 "0x0472")
66 # WL-500gP
67 if [ "$boardnum" = "45" ]; then
68 ucidef_add_switch "switch0" \
69 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0"
70
71 # Generic BCM94704
72 else
73 ucidef_set_interface_wan "eth1"
74 ucidef_add_switch "switch0" \
75 "0:lan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0"
76
77 # MAC addresses on 4704 tend to be screwed up. Add a workaround here
78 local mac="$(nvram get et0macaddr)"
79 local pat="[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]"
80 pat="$pat:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]"
81 pat="$pat:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]"
82
83 case "$mac" in
84 $pat)
85 ucidef_set_interface_macaddr "lan" "$mac"
86 ucidef_set_interface_macaddr "wan" "$(macaddr_add "$mac" 1)"
87 ;;
88 esac
89 fi
90 ;;
91
92 # Buffalo WBR-B11 and Buffalo WBR-G54
93 "bcm94710ap")
94 ucidef_set_interface_wan "eth1"
95 ucidef_add_switch "switch0" \
96 "0:lan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0"
97 ;;
98
99 *)
100 detect_by_boardnum "$boardnum"
101 ;;
102 esac
103 }
104
105 detect_by_model() {
106 local model="$1"
107 local boardtype="$2"
108 local boardnum="$3"
109
110 # Netgear WGT634U exception
111 if grep -sqE 'mtd0: 000(6|a)0000' /proc/mtd; then
112 ucidef_add_switch "switch0" \
113 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0"
114 return
115 fi
116
117 case "$model" in
118 "Asus WLHDD" | \
119 "Asus WL300G")
120 ucidef_set_interface_lan "eth1"
121 ;;
122
123 "Asus WL330GE")
124 ucidef_add_switch "switch0" "4:lan" "5t@eth0"
125 ;;
126
127 "Asus WL500G" | \
128 "Asus WL500W" | \
129 "Microsoft MN-700")
130 ucidef_set_interfaces_lan_wan "eth0" "eth1"
131 ;;
132
133 "Asus WL500GP V2" | \
134 "Buffalo WHR-G125" | \
135 "Motorola WR850G" | \
136 "Siemens SE505 V2")
137 ucidef_add_switch "switch0" \
138 "0:lan" "1:lan" "2:lan" "3:lan" "4:wan" "5@eth0"
139 ;;
140
141 "Asus WL700")
142 ucidef_add_switch "switch0" \
143 "0:wan" "1:lan" "2:lan" "3:lan" "4:lan" "5@eth0"
144 ;;
145
146 "Dell TrueMobile 2300")
147 ucidef_set_interface_wan "eth1"
148 ucidef_add_switch "switch0" \
149 "0:lan" "1:lan" "2:lan" "3:lan" "5@eth0"
150 ;;
151
152 *)
153 detect_by_boardtype "$boardtype" "$boardnum"
154 ;;
155 esac
156 }
157
158
159 local model="$(sed -ne 's/^machine[ \t]*: //p' /proc/cpuinfo)"
160 local boardtype="$(nvram get boardtype)"
161 local boardnum="$(nvram get boardnum)"
162
163 board_config_update
164
165 ucidef_set_board_id "$boardtype${boardnum:+:$boardnum}"
166 ucidef_set_model_name "$model"
167
168 detect_by_model "$model" "$boardtype" "$boardnum"
169
170 board_config_flush