ramips: use /lib/functions/uci-defaults.sh
[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 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 "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 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 "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 *)
60 RT3X5X=`cat /proc/cpuinfo | grep RT3.5`
61 [ -z "${RT3X5X}" ] || \
62 ucidef_set_interfaces_lan_wan "eth0.1 eth0.2"
63 ;;
64 esac
65 }
66
67 ramips_setup_macs()
68 {
69 local board="$1"
70 local lan_mac=""
71 local wan_mac=""
72
73 case $board in
74 f5d8235-v2)
75 lan_mac=$(get_mac_nvram "u-boot" 262148)
76 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
77 ;;
78
79 argus-atp52b | \
80 b2c | \
81 nw718)
82 lan_mac=$(get_mac_binary factory 4)
83 wan_mac=$(/usr/sbin/maccalc add "$lan_mac" 1)
84 ;;
85 esac
86
87 [ -n $lan_mac ] && ucidef_set_interface_macaddr lan $lan_mac
88 [ -n $wan_mac ] && ucidef_set_interface_macaddr wan $wan_mac
89 }
90
91 board=$(ramips_board_name)
92
93 ramips_setup_interfaces $board
94 ramips_setup_macs $board
95
96 uci commit network
97
98 exit 0
This page took 0.061257 seconds and 5 git commands to generate.