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