ramips: add ramips_ prefix to get_mac_{binary,nvram} functions
[openwrt.git] / target / linux / ramips / base-files / etc / uci-defaults / network
1 #!/bin/sh
2
3 . /etc/functions.sh
4 . /lib/ramips.sh
5 . /lib/functions/uci-defaults.sh
6
7 if [ ! -x /usr/sbin/maccalc ]; then
8 echo "$0: maccalc not found!"
9 return
10 fi
11
12 ramips_get_mac_binary()
13 {
14 local mtdname="$1"
15 local seek="$2"
16 local part
17
18 part=$(find_mtd_part "$mtdname")
19 if [ -z "$part" ]; then
20 echo "ramips_get_mac_binary: partition $mtdname not found!" >&2
21 return
22 fi
23
24 dd bs=1 skip=$seek count=6 if=$part 2>/dev/null | /usr/sbin/maccalc bin2mac
25 }
26
27 ramips_get_mac_nvram()
28 {
29 local mtdname="$1"
30 local key="$2"
31 local part
32 local mac_dirty
33
34 part=$(find_mtd_part "$mtdname")
35 if [ -z "$part" ]; then
36 echo "ramips_get_mac_nvram: partition $mtdname not found!" >&2
37 return
38 fi
39
40 mac_dirty=$(strings "$part" | sed -n 's/'"$key"'=//p')
41 # "canonicalize" mac
42 maccalc add "$mac_dirty" 0
43 }
44
45 ramips_setup_interfaces()
46 {
47 local board="$1"
48
49 ucidef_set_interface_loopback
50
51 case $board in
52 argus-atp52b | \
53 b2c | \
54 f5d8235-v2 | \
55 nw718)
56 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
57 ;;
58
59 rt-n15)
60 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
61 ucidef_add_switch "rtl8366s" "1" "1"
62 ucidef_add_switch_vlan "rtl8366s" "1" "1 2 3 4 5t"
63 ucidef_add_switch_vlan "rtl8366s" "2" "0 5t"
64 ;;
65
66 *)
67 RT3X5X=`cat /proc/cpuinfo | grep RT3.5`
68 if [ -n "${RT3X5X}" ]; then
69 ucidef_set_interfaces_lan_wan "eth0.1" "eth0.2"
70 else
71 ucidef_set_interfaces_lan_wan "eth0" "eth1"
72 fi
73 ;;
74 esac
75 }
76
77 ramips_setup_macs()
78 {
79 local board="$1"
80 local lan_mac=""
81 local wan_mac=""
82
83 case $board in
84 f5d8235-v2)
85 lan_mac=$(ramips_get_mac_nvram "u-boot" 262148)
86 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
87 ;;
88
89 argus-atp52b | \
90 b2c | \
91 nw718 | \
92 rt-n15)
93 lan_mac=$(ramips_get_mac_binary factory 4)
94 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
95 ;;
96 esac
97
98 [ -n $lan_mac ] && ucidef_set_interface_macaddr lan $lan_mac
99 [ -n $wan_mac ] && ucidef_set_interface_macaddr wan $wan_mac
100 }
101
102 [ -e /etc/config/network ] && exit 0
103
104 touch /etc/config/network
105
106 board=$(ramips_board_name)
107
108 ramips_setup_interfaces $board
109 ramips_setup_macs $board
110
111 uci commit network
112
113 exit 0
This page took 0.054121 seconds and 5 git commands to generate.