#!/bin/bash
exec 2>/dev/null


. /tmp/cmdline 

startS2MIsdnAtomBox() {
    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=3 --slot-index=a --configuration-index=7 --l2-protocol=pp --l3-protocol=dss1 --max-b-channels=30 --bchannel-map=111111111111111111111111111111 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii >/tmp/selftest_isdn_1a.log 2>&1 &

    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=3 --slot-index=b --configuration-index=8 --l2-protocol=ppnt --nt-mode --l3-protocol=dss1 --max-b-channels=30 --bchannel-map=111111111111111111111111111111 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii >/tmp/selftest_isdn_1b.log 2>&1 &
}

startS0IsdnAtomBox() {
    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=1 --slot-index=a --configuration-index=1 --l2-protocol=pp --l3-protocol=dss1 --max-b-channels=2 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii  >/tmp/selftest_isdn_3a.log 2>&1 &

    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=1 --slot-index=b --configuration-index=2 --l2-protocol=ppnt --nt-mode --l3-protocol=dss1 --max-b-channels=2 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii --resistor >/tmp/selftest_isdn_3b.log 2>&1 &

    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=1 --slot-index=c --configuration-index=3 --l2-protocol=pp  --l3-protocol=dss1 --max-b-channels=2 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii >/tmp/selftest_isdn_3d.log 2>&1 &

    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=1 --slot-index=d --configuration-index=4 --l2-protocol=ppnt --nt-mode --l3-protocol=dss1 --max-b-channels=2 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii --resistor >/tmp/selftest_isdn_3c.log 2>&1 &
}

startS2MIsdnMgb() {
    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=1 --slot-index=a --configuration-index=1 --l2-protocol=pp --l3-protocol=dss1 --max-b-channels=30 --bchannel-map=111111111111111111111111111111 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii >/tmp/selftest_isdn_1a.log 2>&1 &

    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=1 --slot-index=b --configuration-index=2 --l2-protocol=ppnt --nt-mode --l3-protocol=dss1 --max-b-channels=30 --bchannel-map=111111111111111111111111111111 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii >/tmp/selftest_isdn_1b.log 2>&1 &
}

startS0IsdnMgb() {
    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=3 --slot-index=a --configuration-index=3 --l2-protocol=pp --l3-protocol=dss1 --max-b-channels=2 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii  >/tmp/selftest_isdn_3a.log 2>&1 &

    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=3 --slot-index=b --configuration-index=4 --l2-protocol=ppnt --nt-mode --l3-protocol=dss1 --max-b-channels=2 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii --resistor >/tmp/selftest_isdn_3b.log 2>&1 &

    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=3 --slot-index=c --configuration-index=5 --l2-protocol=pp --l3-protocol=dss1 --max-b-channels=2 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii >/tmp/selftest_isdn_3d.log 2>&1 &

    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=3 --slot-index=d --configuration-index=6 --l2-protocol=ppnt --nt-mode --l3-protocol=dss1 --max-b-channels=2 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii --resistor >/tmp/selftest_isdn_3c.log 2>&1 &
}

startS2MIsdnS2MPCIE() {
    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=1 --slot-index=a --configuration-index=1 --l2-protocol=pp --l3-protocol=dss1 --max-b-channels=30 --bchannel-map=111111111111111111111111111111 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii >/tmp/selftest_isdn_1a.log 2>&1 &

    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=1 --slot-index=b --configuration-index=2 --l2-protocol=ppnt --nt-mode --l3-protocol=dss1 --max-b-channels=30 --bchannel-map=111111111111111111111111111111 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii >/tmp/selftest_isdn_1b.log 2>&1 &
}

startS2MIsdnQUADE1() {
    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=1 --slot-index=a --configuration-index=1 --l2-protocol=pp --l3-protocol=dss1 --max-b-channels=30 --bchannel-map=111111111111111111111111111111 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii >/tmp/selftest_isdn_1a.log 2>&1 &

    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=1 --slot-index=b --configuration-index=2 --l2-protocol=ppnt --nt-mode --l3-protocol=dss1 --max-b-channels=30 --bchannel-map=111111111111111111111111111111 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii >/tmp/selftest_isdn_1b.log 2>&1 &

    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=3 --slot-index=a --configuration-index=1 --l2-protocol=pp --l3-protocol=dss1 --max-b-channels=30 --bchannel-map=111111111111111111111111111111 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii >/tmp/selftest_isdn_1a.log 2>&1 &

    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=3 --slot-index=b --configuration-index=2 --l2-protocol=ppnt --nt-mode --l3-protocol=dss1 --max-b-channels=30 --bchannel-map=111111111111111111111111111111 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii >/tmp/selftest_isdn_1b.log 2>&1 &
}

startS0IsdnSingleUnit4S0() {
    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=1 --slot-index=a --configuration-index=3 --l2-protocol=pp --l3-protocol=dss1 --max-b-channels=2 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii  >/tmp/selftest_isdn_3a.log 2>&1 &

    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=1 --slot-index=b --configuration-index=4 --l2-protocol=ppnt --nt-mode --l3-protocol=dss1 --max-b-channels=2 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii --resistor >/tmp/selftest_isdn_3b.log 2>&1 &

    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=1 --slot-index=c --configuration-index=5 --l2-protocol=pp  --l3-protocol=dss1 --max-b-channels=2 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii >/tmp/selftest_isdn_3d.log 2>&1 &

    tail -f /dev/null | /usr/fb/bin/isdn.prc --slot=1 --slot-index=d --configuration-index=6 --l2-protocol=ppnt --nt-mode --l3-protocol=dss1 --max-b-channels=2 --CallingPartyNumberInternationalPrefix= --CallingPartyNumberNationalPrefix= --CallingPartyNumberSubscriberPrefix= --PrefixAlsoOnCpn=0 --OutboundTypeOfNumber=1 --OutboundNumberingPlan=2 --debug-l1=0 --debug-l2=1 --debug-l3=0 --debug-l4=0 --ulaw --country=49 --device=/dev/ilid --read-fd=-1 --write-fd=-1 --app-pipe-ascii --resistor >/tmp/selftest_isdn_3c.log 2>&1 &
}

if [ "${HWTYPE}" = "AtomBox" ] ; then
    echo "stopping running Tasks"
    omgstopall 2>/dev/null >/dev/null
    echo "loading modules" 
    omgstartilid
    
    rm /tmp/L2State* 2>/dev/null >/dev/nul
    rm /tmp/selftest_isdn_*.log 2>/dev/null >/dev/nul

    echo "clk_show" | confTool /dev/ilid 0.a/X

    #set internal clock as master on all three prioritys
    echo "clk_master 8 8 8" | confTool /dev/ilid 0.a/X
    
    echo "clk_show" | confTool /dev/ilid 0.a/X

    echo "starting S2M ports"
    startS2MIsdnAtomBox
    echo "starting S0  ports"
    startS0IsdnAtomBox

    sleep 3

    let oneFalse=1
    let maxCount=45
    while test ${oneFalse} -gt 0 -a ${maxCount} -gt 0;do
        sleep 1
        #printf "%02d (%d)================\n" ${maxCount} ${oneFalse}
        let oneFalse=0
        for i in /tmp/L2State*; do
            port=$(echo ${i} | cut -d "-" -f 2) 
            type=$(echo ${i} | cut -d "-" -f 4) 
            state=$(cat ${i} | cut -d "=" -f 2)
       
            if [ "$state" != "MULTIPLE_FRAME_ESTABLISHED" ] ; then
                let oneFalse=1
            fi

            #printf "    %-3.3s %s %s\n" ${type} ${port} ${state}
        done
        let maxCount=${maxCount}-1
    done
    
    echo states are:
    for i in /tmp/L2State*; do
        port=$(echo ${i} | cut -d "-" -f 2) 
        type=$(echo ${i} | cut -d "-" -f 4) 
        state=$(cat ${i} | cut -d "=" -f 2)
        
        printf "    %-3.3s %s %s\n" ${type} ${port} ${state}
    done

    #following is standard setting
    echo "clk_master 0 1 8" | confTool /dev/ilid 0.a/X

    echo restarting normal service
    omgrestart 2>/dev/null >/dev/null
    echo done
fi

if [ "${HWTYPE}" = "MGB" ] ; then
    echo "stopping running Tasks"
    omgstopall 2>/dev/null >/dev/null
    echo "loading modules" 
    omgstartilid
    
    rm /tmp/L2State* 2>/dev/null >/dev/nul
    rm /tmp/selftest_isdn_*.log 2>/dev/null >/dev/nul

    echo "clk_show" | confTool /dev/ilid 0.a/X

    #set internal clock as master on all three prioritys
    echo "clk_master 8 8 8" | confTool /dev/ilid 0.a/X
    
    echo "clk_show" | confTool /dev/ilid 0.a/X

    echo "starting S2M ports"
    startS2MIsdnMgb
    echo "starting S0  ports"
    startS0IsdnMgb

    echo "set termination S0  ports"
    i2cutil -y ${I2CBUS} 0x08 0x0a 0x0a b

    sleep 3

    let oneFalse=1
    let maxCount=45
    while test ${oneFalse} -gt 0 -a ${maxCount} -gt 0;do
        sleep 1
        #printf "%02d (%d)================\n" ${maxCount} ${oneFalse}
        let oneFalse=0
        for i in /tmp/L2State*; do
            port=$(echo ${i} | cut -d "-" -f 2) 
            type=$(echo ${i} | cut -d "-" -f 4) 
            state=$(cat ${i} | cut -d "=" -f 2)
       
            if [ "$state" != "MULTIPLE_FRAME_ESTABLISHED" ] ; then
                let oneFalse=1
            fi

            #printf "    %-3.3s %s %s\n" ${type} ${port} ${state}
        done
        let maxCount=${maxCount}-1
    done
    
    echo states are:
    for i in /tmp/L2State*; do
        port=$(echo ${i} | cut -d "-" -f 2) 
        type=$(echo ${i} | cut -d "-" -f 4) 
        state=$(cat ${i} | cut -d "=" -f 2)
        
        printf "    %-3.3s %s %s\n" ${type} ${port} ${state}
    done

    #following is standard setting
    echo "clk_master 0 1 8" | confTool /dev/ilid 0.a/X

    echo restarting normal service
    omgrestart 2>/dev/null >/dev/null
    echo done
fi

if [ "$HWTYPE" = "QUADE1" ] ; then
    echo "stopping running Tasks"
    omgstopall 2>/dev/null >/dev/null
    echo "loading modules" 
    omgstartilid
    
    rm /tmp/L2State* 2>/dev/null >/dev/nul
    rm /tmp/selftest_isdn_*.log 2>/dev/null >/dev/nul

    echo "clk_show" | confTool /dev/ilid 0.a/X

    #set internal clock as master on all three prioritys
    echo "clk_master 8 8 8" | confTool /dev/ilid 0.a/X
    
    echo "clk_show" | confTool /dev/ilid 0.a/X

    echo "starting S2M ports"
    startS2MIsdnQUADE1

    sleep 3

    let oneFalse=1
    let maxCount=45
    while test ${oneFalse} -gt 0 -a ${maxCount} -gt 0;do
        sleep 1
        #printf "%02d (%d)================\n" ${maxCount} ${oneFalse}
        let oneFalse=0
        for i in /tmp/L2State*; do
            port=$(echo ${i} | cut -d "-" -f 2) 
            type=$(echo ${i} | cut -d "-" -f 4) 
            state=$(cat ${i} | cut -d "=" -f 2)
       
            if [ "$state" != "MULTIPLE_FRAME_ESTABLISHED" ] ; then
                let oneFalse=1
            fi

            #printf "    %-3.3s %s %s\n" ${type} ${port} ${state}
        done
        let maxCount=${maxCount}-1
    done
    
    echo states are:
    for i in /tmp/L2State*; do
        port=$(echo ${i} | cut -d "-" -f 2) 
        type=$(echo ${i} | cut -d "-" -f 4) 
        state=$(cat ${i} | cut -d "=" -f 2)
        
        printf "    %-3.3s %s %s\n" ${type} ${port} ${state}
    done

    #following is standard setting
    echo "clk_master 0 1 8" | confTool /dev/ilid 0.a/X

    echo restarting normal service
    omgrestart 2>/dev/null >/dev/null
    echo done
fi

if [ "$HWTYPE" = "S2MPCIE" ] ; then
    echo "stopping running Tasks"
    omgstopall 2>/dev/null >/dev/null
    echo "loading modules" 
    omgstartilid
    
    rm /tmp/L2State* 2>/dev/null >/dev/nul
    rm /tmp/selftest_isdn_*.log 2>/dev/null >/dev/nul

    echo "clk_show" | confTool /dev/ilid 0.a/X

    #set internal clock as master on all three prioritys
    echo "clk_master 8 8 8" | confTool /dev/ilid 0.a/X
    
    echo "clk_show" | confTool /dev/ilid 0.a/X

    echo "starting S2M ports"
    startS2MIsdnS2MPCIE

    sleep 3

    let oneFalse=1
    let maxCount=45
    while test ${oneFalse} -gt 0 -a ${maxCount} -gt 0;do
        sleep 1
        #printf "%02d (%d)================\n" ${maxCount} ${oneFalse}
        let oneFalse=0
        for i in /tmp/L2State*; do
            port=$(echo ${i} | cut -d "-" -f 2) 
            type=$(echo ${i} | cut -d "-" -f 4) 
            state=$(cat ${i} | cut -d "=" -f 2)
       
            if [ "$state" != "MULTIPLE_FRAME_ESTABLISHED" ] ; then
                let oneFalse=1
            fi

            #printf "    %-3.3s %s %s\n" ${type} ${port} ${state}
        done
        let maxCount=${maxCount}-1
    done
    
    echo states are:
    for i in /tmp/L2State*; do
        port=$(echo ${i} | cut -d "-" -f 2) 
        type=$(echo ${i} | cut -d "-" -f 4) 
        state=$(cat ${i} | cut -d "=" -f 2)
        
        printf "    %-3.3s %s %s\n" ${type} ${port} ${state}
    done

    #following is standard setting
    echo "clk_master 0 8 8" | confTool /dev/ilid 0.a/X

    echo restarting normal service
    omgrestart 2>/dev/null >/dev/null
    echo done
fi

if [ "$HWTYPE" = "SingleUnit4S0" ] ; then
    echo "stopping running Tasks"
    omgstopall 2>/dev/null >/dev/null
    echo "loading modules" 
    omgstartilid
    
    rm /tmp/L2State* 2>/dev/null >/dev/nul
    rm /tmp/selftest_isdn_*.log 2>/dev/null >/dev/nul

    echo "starting S0 ports"
    startS0IsdnSingleUnit4S0

    sleep 3

    let oneFalse=1
    let maxCount=45
    while test ${oneFalse} -gt 0 -a ${maxCount} -gt 0;do
        sleep 1
        #printf "%02d (%d)================\n" ${maxCount} ${oneFalse}
        let oneFalse=0
        for i in /tmp/L2State*; do
            port=$(echo ${i} | cut -d "-" -f 2) 
            type=$(echo ${i} | cut -d "-" -f 4) 
            state=$(cat ${i} | cut -d "=" -f 2)
       
            if [ "$state" != "MULTIPLE_FRAME_ESTABLISHED" ] ; then
                let oneFalse=1
            fi

            #printf "    %-3.3s %s %s\n" ${type} ${port} ${state}
        done
        let maxCount=${maxCount}-1
    done
    
    echo states are:
    for i in /tmp/L2State*; do
        port=$(echo ${i} | cut -d "-" -f 2) 
        type=$(echo ${i} | cut -d "-" -f 4) 
        state=$(cat ${i} | cut -d "=" -f 2)
        
        printf "    %-3.3s %s %s\n" ${type} ${port} ${state}
    done

    echo restarting normal service
    omgrestart 2>/dev/null >/dev/null
    echo done
fi
