Project

General

Profile

Boardinfo rcd script

Allow to fetch and preset some early items, like set MAC address.

D-Link DIR-632 example:

#!/bin/sh

# BEFORE: ADAPTATION
# PROVIDE: boardinfo

. /etc/rc.subr
. /etc/network.subr

name="boardinfo" 
start_cmd="boardinfo_start" 

boardinfo_start()
{

    BASEMAC=`dd if=/dev/map/MAC bs=4 skip=1 count=5 2> /dev/null`

    BASEMACVNDR=`echo ${BASEMAC} | sed -E 's/\:.{2}\:.{2}\:.{2}$//'`
    BASEMACDEV=`echo ${BASEMAC} | sed -E 's/.{2}\:.{2}\:.{2}\://; s/\://g; s/^/0x/'`

    WANMACDEV=$((${BASEMACDEV} + 1))
    WLANMACDEV=$((${BASEMACDEV} + 2))

    WANMAC=`printf "${BASEMACVNDR}:%02x:%02x:%02x" $(( (${WANMACDEV} >> 16 ) & 0xff )) $(( (${WANMACDEV} >> 8 ) & 0xff )) $(( ${WANMACDEV} & 0xff ))`
    WLANMAC=`printf "${BASEMACVNDR}:%02x:%02x:%02x" $(( (${WLANMACDEV} >> 16 ) & 0xff )) $(( (${WLANMACDEV} >> 8 ) & 0xff )) $(( ${WLANMACDEV} & 0xff ))`

    kenv BASE_MAC_ADDR="${BASEMAC}" 
    kenv LAN_MAC_ADDR="${BASEMAC}" 
    kenv WAN_MAC_ADDR="${WANMAC}" 
    kenv WLAN_MAC_ADDR="${WLANMAC}" 
    echo "Using default board MAC address \"${BASEMAC}\"" 
}

load_rc_config $name

run_rc_command $*

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.