Project

General

Profile

Boardinfo rcd script » History » Version 1

Oleksandr Rybalko, 05/28/2012 09:35 AM

1 1 Oleksandr Rybalko
h1. Boardinfo rcd script
2 1 Oleksandr Rybalko
3 1 Oleksandr Rybalko
Allow to fetch and preset some early items, like set MAC address.
4 1 Oleksandr Rybalko
5 1 Oleksandr Rybalko
D-Link DIR-632 example:
6 1 Oleksandr Rybalko
<pre>
7 1 Oleksandr Rybalko
#!/bin/sh
8 1 Oleksandr Rybalko
9 1 Oleksandr Rybalko
# BEFORE: ADAPTATION
10 1 Oleksandr Rybalko
# PROVIDE: boardinfo
11 1 Oleksandr Rybalko
12 1 Oleksandr Rybalko
. /etc/rc.subr
13 1 Oleksandr Rybalko
. /etc/network.subr
14 1 Oleksandr Rybalko
15 1 Oleksandr Rybalko
name="boardinfo"
16 1 Oleksandr Rybalko
start_cmd="boardinfo_start"
17 1 Oleksandr Rybalko
18 1 Oleksandr Rybalko
boardinfo_start()
19 1 Oleksandr Rybalko
{
20 1 Oleksandr Rybalko
21 1 Oleksandr Rybalko
	BASEMAC=`dd if=/dev/map/MAC bs=4 skip=1 count=5 2> /dev/null`
22 1 Oleksandr Rybalko
23 1 Oleksandr Rybalko
	BASEMACVNDR=`echo ${BASEMAC} | sed -E 's/\:.{2}\:.{2}\:.{2}$//'`
24 1 Oleksandr Rybalko
	BASEMACDEV=`echo ${BASEMAC} | sed -E 's/.{2}\:.{2}\:.{2}\://; s/\://g; s/^/0x/'`
25 1 Oleksandr Rybalko
26 1 Oleksandr Rybalko
	WANMACDEV=$((${BASEMACDEV} + 1))
27 1 Oleksandr Rybalko
	WLANMACDEV=$((${BASEMACDEV} + 2))
28 1 Oleksandr Rybalko
29 1 Oleksandr Rybalko
	WANMAC=`printf "${BASEMACVNDR}:%02x:%02x:%02x" $(( (${WANMACDEV} >> 16 ) & 0xff )) $(( (${WANMACDEV} >> 8 ) & 0xff )) $(( ${WANMACDEV} & 0xff ))`
30 1 Oleksandr Rybalko
	WLANMAC=`printf "${BASEMACVNDR}:%02x:%02x:%02x" $(( (${WLANMACDEV} >> 16 ) & 0xff )) $(( (${WLANMACDEV} >> 8 ) & 0xff )) $(( ${WLANMACDEV} & 0xff ))`
31 1 Oleksandr Rybalko
32 1 Oleksandr Rybalko
	kenv BASE_MAC_ADDR="${BASEMAC}"
33 1 Oleksandr Rybalko
	kenv LAN_MAC_ADDR="${BASEMAC}"
34 1 Oleksandr Rybalko
	kenv WAN_MAC_ADDR="${WANMAC}"
35 1 Oleksandr Rybalko
	kenv WLAN_MAC_ADDR="${WLANMAC}"
36 1 Oleksandr Rybalko
	echo "Using default board MAC address \"${BASEMAC}\""
37 1 Oleksandr Rybalko
}
38 1 Oleksandr Rybalko
39 1 Oleksandr Rybalko
load_rc_config $name
40 1 Oleksandr Rybalko
41 1 Oleksandr Rybalko
run_rc_command $*
42 1 Oleksandr Rybalko
</pre>
43 1 Oleksandr Rybalko
44 1 Oleksandr Rybalko
In this example, script read special block of flash (/dev/map/MAC), parse base MAC address from it, and calculate and introduce via kenv(1) MAC addresses for different purposes.