PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
pkg=0; chan=0
tempaddr="/var/run/tempaddr"
ncsi_recv="/usr/local/bin/ncsi_recv"
ncs_cmd="/usr/local/bin/ncsi_cmd"

count=0
while [ -z "$(ifconfig eth0)" ]
do
    count=$((count+1))
    sleep 1
    if [ "$count" -gt 4 ]
    then
        exit 1
    fi
done

if [ ! -e /tmp/cur_iid_eth0 ] ; then
    echo 1 >> /tmp/cur_iid_eth0
    chmod 777 /tmp/cur_iid_eth0
fi

if [ ! -e /tmp/cur_iid_eth1 ] ; then
    echo 1 >> /tmp/cur_iid_eth1
    chmod 777 /tmp/cur_iid_eth1
fi

cat /sys/class/net/eth0/address | sed -e 's|:| |g' >> $tempaddr

value=$(cat $tempaddr)

kill -9 $(pidof ncsi_recv)

script_cmds="ncsi_cmd eth0 $pkg 1f 1 0 0 0 1
ncsi_cmd eth0 $pkg $chan 0 
ncsi_cmd eth0 $pkg $chan e  $value 1 1
ncsi_cmd eth0 $pkg $chan 10  0 0 0 f
ncsi_cmd eth0 $pkg $chan 12  0 0 0 7
ncsi_cmd eth0 $pkg $chan 8  0 0 0 0 0 0 0 7
ncsi_cmd eth0 $pkg $chan 3 
ncsi_cmd eth0 $pkg $chan 6 
ncsi_cmd eth0 $pkg $chan 50 00 00 01 57 40 03
ncsi_cmd eth0 $pkg $chan a"

platid=$(cat /var/run/platform)
brdrev=$(cat /var/run/boardrev)
razorl_rev_p2i=3

if [ $platid == "RazorL" ] && [ $brdrev -lt $razorl_rev_p2i ]
then
    printf %s "$script_cmds" | while IFS= read -r line
    do
        for loop in $(seq 1 5)
        do
            eval $line
            if [ $? -eq 0 ]
            then
                break
            fi
            sleep 1
        done
    done

    ncsi_recv eth0 &
fi

rm -f $tempaddr

pkg=0; chan=0

count=0
while [ -z "$(ifconfig eth1)" ]
do
    count=$((count+1))
    sleep 1
    if [ "$count" -gt 4 ]
    then
        exit 1
    fi
done

cat /sys/class/net/eth1/address | sed -e 's|:| |g' >> $tempaddr

value=$(cat $tempaddr)

ncsi_cmd eth1 $pkg 1f 1 0 0 0 1
ncsi_cmd eth1 $pkg $chan 0 
ncsi_cmd eth1 $pkg $chan e  $value 1 1
ncsi_cmd eth1 $pkg $chan 10  0 0 0 f
ncsi_cmd eth1 $pkg $chan 12 0 0 0 7
ncsi_cmd eth1 $pkg $chan 8  0 0 0 0 0 0 0 7
ncsi_cmd eth1 $pkg $chan 3 
ncsi_cmd eth1 $pkg $chan 6 
ncsi_cmd eth1 $pkg $chan 50 00 00 00 6c 00 03 00 00 00 00 00 00 00 00 00 00
ncsi_cmd eth1 $pkg $chan a 
#ncsi_recv eth1 &

rm -f $tempaddr

exit 0;

