@echo off


echo Generating time stamp...

rem set variables to this process/session only, not global
SETLOCAL ENABLEEXTENSIONS 

rem capture current time and remove colons
SET UNIQUETIME=%TIME::=%
rem take only first 6 characters of string
SET UNIQUETIME=%UNIQUETIME:~0,6%
rem create unique string through concatenation
SET UNIQUEPATHNAME=%COMPUTERNAME%%DATE:/=%_%UNIQUETIME%
rem strip out unnecessary characters
SET UNIQUEPATHNAME=%UNIQUEPATHNAME:.=_%
SET UNIQUEPATHNAME=%UNIQUEPATHNAME: =%

if not exist "C:\Program Files\REALTEK\Realtek Bluetooth" md "C:\Program Files\REALTEK\Realtek Bluetooth" 
set CFADIR="C:\Program Files\REALTEK\Realtek Bluetooth"

if not exist %USERPROFILE%\desktop\RtkBtTraces md %USERPROFILE%\desktop\RtkBtTraces
set LOGDIR="%USERPROFILE%\desktop\RtkBtTraces"

echo Getting System information
Systeminfo > "%userprofile%\desktop\RtkBtTraces\SystemInfo%PROCESSOR_ARCHITECTURE%%UNIQUEPATHNAME%.txt"
call:GetBtFileVersion "%userprofile%\desktop\RtkBtTraces\SystemInfo%PROCESSOR_ARCHITECTURE%%UNIQUEPATHNAME%.txt"

@echo enabling uart transport driver tracing...

@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\Rtkuart\{52939353-f219-4281-af9a-5283379bfc96}" /v EnableFlags /t  REG_DWORD /d 0xffffffff /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\Rtkuart\{52939353-f219-4281-af9a-5283379bfc96}" /v EnableLevel /t  REG_DWORD /d 0xffffffff /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\Rtkuart\{52939353-f219-4281-af9a-5283379bfc96}" /v Enabled /t  REG_DWORD /d 0x1 /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\Rtkuart\{52939353-f219-4281-af9a-5283379bfc96}" /v Status /t  REG_DWORD /d 0 /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\Rtkuart" /v GUID /t  REG_SZ /d {52939353-f219-4281-af9a-5283379bfc96} /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\Rtkuart" /v FileName /t  REG_SZ /d %LOGDIR%\%UNIQUEPATHNAME%Rtkuart.etl /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\Rtkuart" /v FileMax /t  REG_DWORD /d 20000 /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\Rtkuart" /v MaxFileSize /t  REG_DWORD /d 1000 /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\Rtkuart" /v LogFileMode /t  REG_DWORD /d 0x1202 /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\Rtkuart" /v Start /t  REG_DWORD /d 1 /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\Rtkuart" /v Status /t  REG_DWORD /d 0 /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\Rtkuart" /v FlushTimer /t REG_DWORD /d 1 /f
@REG ADD "HKLM\System\CurrentControlSet\Services\RtkUart\Parameters" /v BtSnoopEnabled /t REG_DWORD /d 1 /f

@echo enabling btdevmgr tracing
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\BTdevMgr\{4ed1fccd-EA57-433d-8C92-0A841BAA3B5C}" /v EnableFlags /t  REG_DWORD /d 0xffffffff /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\BTdevMgr\{4ed1fccd-EA57-433d-8C92-0A841BAA3B5C}" /v EnableLevel /t  REG_DWORD /d 0xffffffff /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\BTdevMgr\{4ed1fccd-EA57-433d-8C92-0A841BAA3B5C}" /v Enabled /t  REG_DWORD /d 0x1 /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\BTdevMgr\{4ed1fccd-EA57-433d-8C92-0A841BAA3B5C}" /v Status /t  REG_DWORD /d 0 /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\BTdevMgr" /v GUID /t  REG_SZ /d {4ed1fccd-EA57-433d-8C92-0A841BAA3B5C} /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\BTdevMgr" /v FileName /t  REG_SZ /d %LOGDIR%\%UNIQUEPATHNAME%BTDevMgr.etl /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\BTdevMgr" /v FileMax /t  REG_DWORD /d 20000 /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\BTdevMgr" /v MaxFileSize /t  REG_DWORD /d 1000 /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\BTdevMgr" /v LogFileMode /t  REG_DWORD /d 0x1202 /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\BTdevMgr" /v Start /t  REG_DWORD /d 1 /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\BTdevMgr" /v Status /t  REG_DWORD /d 0 /f
@REG ADD "HKLM\System\CurrentControlSet\Control\WMI\Autologger\BTdevMgr" /v FlushTimer /t REG_DWORD /d 1 /f


echo ***************************************************************************
echo ***            PLEASE close all programs and prepare to reboot          ***
echo ***                                                                     ***
echo ***            Press a key when ready, The system will reboot           ***
echo ***                                                                     ***
echo ***            In 5 seconds.  Press Ctrl-C to ABORT NOW                 ***
echo ***                                                                     ***
echo *** Note REALTEK uart tracing won't be enabled until you reboot the     ***
echo ***                                                                     ***
echo ***  systemafter rebooting, reproduce the problem and zip up            ***
echo ***                                                                     ***
echo ***      the new  folder on your desktop called "RtkBtTraces"           ***
echo ***                                                                     ***
echo ***    Don't forget to run autologUartTraceDisable.cmd after finishing  ***
echo ***************************************************************************

:end
pause
shutdown -r -t 2
goto:eof


:GetBtFileVersion

set OLDPATH=%PATH%
set PATH=%PATH%;%~dp0%
set OLDCD=%cd%

if %PROCESSOR_ARCHITECTURE%==AMD64 (
    set BTDIR="%programfiles(x86)%\\REALTEK\\Realtek Bluetooth"
)
if %PROCESSOR_ARCHITECTURE%==x86 (
    set BTDIR="%programfiles%\\REALTEK\\Realtek Bluetooth"
)
cd /d %BTDIR%


rem get driver version information
GetFileVer.exe ".\Version\RTLBTVersion.dll" >>%~1
GetFileVer.exe "%windir%\system32\drivers\RtkUart.sys" >>%~1
GetFileVer.exe "%windir%\system32\drivers\RtkA2dp.sys" >>%~1
GetFileVer.exe /fwver >>%~1
GetFileVer.exe "BTDevMgr.exe">>%~1
rem read wifi reported antenna policy in registry.
REG QUERY HKLM\SYSTEM\CurrentControlSet\services\RtlWlans\Parameters /v BtAntennaInHw >>%~1
rem read BtIsConfig antenna policy in registry
REG QUERY HKLM\SYSTEM\CurrentControlSet\services\RtkUart\Parameters /v BtIsConfigAntenna >>%~1
echo ======================IsConfig.ini========================== >>%~1
type IsConfig.ini >>%~1

set PATH=%OLDPATH%
cd /d %OLDCD%

goto:eof
