@ECHO OFF
cls
echo *************************
echo *** start wefuse test ***
echo *************************
rem RTNicPgW64.exe
rem WAT.EXE 1.15

:START
del nic.cfg

IF NOT EXIST SC_MAC1.INI GOTO NOFILE1
IF NOT EXIST DEF_MAC.INI GOTO NOFILE1
IF NOT EXIST 9111*.cfg GOTO NOFILE2
IF NOT EXIST golden.sou GOTO NOFILE2

:set nic variable
copy ..\..\config\nic.cfg nic.cfg /y
if not exist nic.cfg goto nofile1
for /f "tokens=1 delims= " %%i in (nic.cfg) do (set nic=%%i)

:Make Sure The SC_MAC1.INI Is Not Empty
WAT.EXE /C SC_MAC1.INI ERROR.INI
IF ERRORLEVEL 255 GOTO NEXT
IF ERRORLEVEL 0 GOTO FILE_F

:NEXT
rem *** disable lan controller dirver ***
Rtinstaller64 /vista8169 /dnicdrv

:CheckMAC
DEL CHKMAC.DAT
DEL MACCHK.DAT
RTNicPgW64.exe /# %NIC% /EFUSE /VMAC > CHKMAC.DAT
WAT.EXE -SA 34 -EA 35 -SL 14 -EL 14 /GSTR CHKMAC.DAT >MACCHK.DAT
WAT.EXE -SA 37 -EA 38 -SL 14 -EL 14 /GSTR CHKMAC.DAT >>MACCHK.DAT
WAT.EXE -SA 40 -EA 41 -SL 14 -EL 14 /GSTR CHKMAC.DAT >>MACCHK.DAT
WAT.EXE -SA 43 -EA 44 -SL 14 -EL 14 /GSTR CHKMAC.DAT >>MACCHK.DAT
WAT.EXE -SA 46 -EA 47 -SL 14 -EL 14 /GSTR CHKMAC.DAT >>MACCHK.DAT
WAT.EXE -SA 49 -EA 50 -SL 14 -EL 14 /GSTR CHKMAC.DAT >>MACCHK.DAT
REM *** Check wether the MAC are default ***
WAT.EXE -SA 1 -EA 12 /C MACCHK.DAT DEF_MAC.INI
IF ERRORLEVEL 1 GOTO nextchk
IF ERRORLEVEL 0 GOTO WriteCFG
:nextchk
REM *** Check wether the MAC are matched ***
WAT.EXE -SA 1 -EA 12 /C MACCHK.DAT SC_MAC1.INI
IF ERRORLEVEL 1 GOTO NOMATCHF
IF ERRORLEVEL 0 GOTO CheckCFG

:CheckCFG
DEL *.T
DEL TEMP3.TXT
DEL EEPROM.TXT
RTNicPgW64.exe /# %NIC% /EFUSE /R > EEPROM.TXT 
WAT.EXE -SA 2 -EA 13 -SL 27 -EL 27 /GSTR EEPROM.TXT >1.T
WAT.EXE -SA 2 -EA 13 -SL 28 -EL 28 /GSTR EEPROM.TXT >2.T
WAT.EXE -SA 2 -EA 13 -SL 29 -EL 29 /GSTR EEPROM.TXT >3.T
WAT.EXE -SA 2 -EA 13 -SL 31 -EL 31 /GSTR EEPROM.TXT >4.T
WAT.EXE -SA 2 -EA 15 -SL 33 -EL 33 /GSTR EEPROM.TXT >5.T
WAT.EXE -SA 2 -EA 16 -SL 34 -EL 34 /GSTR EEPROM.TXT >6.T
WAT.EXE -SA 2 -EA 16 -SL 35 -EL 35 /GSTR EEPROM.TXT >7.T
copy 1.t+enter+2.t+enter+3.t+enter+5.t+enter+4.t+enter+6.t+enter+7.t temp3.txt
WAT.EXE /c temp3.txt golden.sou
if errorlevel 1 goto WriteCFG
GOTO PASS

:WriteCFG
RTNicPgW64.exe /# %NIC% /EFUSE
IF ERRORLEVEL 1 GOTO WCFGFAIL
REM *** Read and check CFG ***
DEL *.T
DEL TEMP3.TXT
DEL EEPROM.TXT
RTNicPgW64.exe /# %NIC% /EFUSE /R > EEPROM.TXT 
WAT.EXE -SA 2 -EA 13 -SL 27 -EL 27 /GSTR EEPROM.TXT >1.T
WAT.EXE -SA 2 -EA 13 -SL 28 -EL 28 /GSTR EEPROM.TXT >2.T
WAT.EXE -SA 2 -EA 13 -SL 29 -EL 29 /GSTR EEPROM.TXT >3.T
WAT.EXE -SA 2 -EA 13 -SL 31 -EL 31 /GSTR EEPROM.TXT >4.T
WAT.EXE -SA 2 -EA 15 -SL 33 -EL 33 /GSTR EEPROM.TXT >5.T
WAT.EXE -SA 2 -EA 16 -SL 34 -EL 34 /GSTR EEPROM.TXT >6.T
WAT.EXE -SA 2 -EA 16 -SL 35 -EL 35 /GSTR EEPROM.TXT >7.T
copy 1.t+enter+2.t+enter+3.t+enter+5.t+enter+4.t+enter+6.t+enter+7.t temp3.txt
WAT.EXE /c temp3.txt golden.sou
if errorlevel 1 goto CCFGFAIL

:WriteMAC
Del PGMAC.TXT
Del PGMAC.BAT
WAT.EXE -SA 1 -EA 36 -SL 1 -EL 1 /GSTR PG.ini >PGMAC.TXT
WAT.EXE -SA 1 -EA 12 -SL 1 -EL 1 /GSTR SC_MAC1.INI >>PGMAC.TXT
COPY PGMAC.TXT PGMAC.BAT /Y
CALL PGMAC.BAT %NIC%
IF ERRORLEVEL 1 GOTO WMACFAIL
REM *** read and check MAC ***
DEL CHKMAC.DAT
DEL MACCHK.DAT
RTNicPgW64.exe /# %NIC% /EFUSE /VMAC > CHKMAC.DAT
WAT.EXE -SA 34 -EA 35 -SL 14 -EL 14 /GSTR CHKMAC.DAT >MACCHK.DAT
WAT.EXE -SA 37 -EA 38 -SL 14 -EL 14 /GSTR CHKMAC.DAT >>MACCHK.DAT
WAT.EXE -SA 40 -EA 41 -SL 14 -EL 14 /GSTR CHKMAC.DAT >>MACCHK.DAT
WAT.EXE -SA 43 -EA 44 -SL 14 -EL 14 /GSTR CHKMAC.DAT >>MACCHK.DAT
WAT.EXE -SA 46 -EA 47 -SL 14 -EL 14 /GSTR CHKMAC.DAT >>MACCHK.DAT
WAT.EXE -SA 49 -EA 50 -SL 14 -EL 14 /GSTR CHKMAC.DAT >>MACCHK.DAT
WAT.EXE -SA 1 -EA 12 /C SC_MAC1.INI MACCHK.DAT
IF ERRORLEVEL 1 GOTO CMACFAIL
GOTO PASS

:FILE_F
CLS
ECHO.
ECHO **************************************
ECHO * WEFUSE Fail: SC_MAC1.ini are empty *
ECHO **************************************
SET NIC=
PAUSE
GOTO FILE_F

:NOFILE1
CLS
ECHO.
ECHO **************************************************
ECHO * WEFUSE Fail: Not exist SC_MAC1 or DEF_MAC file *
ECHO **************************************************
SET NIC=
PAUSE
GOTO NOFILE1

:NOFILE2
echo.
echo **********************************************
echo *** WEFUSE Fail                            ***
echo *** not exist 9111*.cfg or golden.sou file ***
echo **********************************************
PAUSE
GOTO NOFILE2

:NOMATCHF
CLS
Rtinstaller64 /hwscan
Rtinstaller64 /vista8169 /enicdrv
ECHO.
ECHO **********************************
ECHO * WEFUSE Fail: MAC are not match *
ECHO **********************************
SET NIC=
PAUSE
GOTO NOMATCHF

:WCFGFAIL
CLS
Rtinstaller64 /hwscan
Rtinstaller64 /vista8169 /enicdrv
ECHO.
ECHO *******************************
ECHO * WEFUSE Fail: Write CFG fail *
ECHO *******************************
SET NIC=
PAUSE
GOTO WCFGFAIL

:CCFGFAIL
CLS
Rtinstaller64 /hwscan
Rtinstaller64 /vista8169 /enicdrv
ECHO.
ECHO *******************************
ECHO * WEFUSE Fail: Check CFG fail *
ECHO *******************************
SET NIC=
PAUSE
GOTO CCFGFAIL

:WMACFAIL
CLS
Rtinstaller64 /hwscan
Rtinstaller64 /vista8169 /enicdrv
ECHO.
ECHO *******************************
ECHO * WEFUSE Fail: Write MAC fail *
ECHO *******************************
SET NIC=
PAUSE
GOTO WMACFAIL

:CMACFAIL
CLS
Rtinstaller64 /hwscan
Rtinstaller64 /vista8169 /enicdrv
ECHO.
ECHO *******************************
ECHO * WEFUSE Fail: Check MAC fail *
ECHO *******************************
SET NIC=
PAUSE
GOTO CMACFAIL

:PASS
CLS
Rtinstaller64 /hwscan
Rtinstaller64 /vista8169 /enicdrv
ECHO.
ECHO ********************
ECHO * WEFUSE test PASS *
ECHO ********************
SET NIC=
DEL CHKMAC.DAT
DEL MACCHK.DAT
DEL *.T
DEL TEMP3.TXT
DEL EEPROM.TXT
Del PGMAC.TXT
Del PGMAC.BAT
DEL SC_MAC1.INI
DEL nic.cfg
CD\%PATHS%\TOOLS
Counter.exe