Ejemplo n.º 1
0
PNDASPhysicalDrive::PNDASPhysicalDrive()
{
	m_bInitialized = NULL;
	m_hNDAS = NULL;
	ZeroMemory(&m_Info, sizeof(m_Info));
	ZeroMemory(&m_UnitInfo, sizeof(m_UnitInfo));
	ZeroMemory(&m_UnitDynInfo, sizeof(m_UnitDynInfo));

	BOOL bResults = NdasCommInitialize();	
	m_bInitialized = bResults;
} // PNDASPhysicalDrive()
Ejemplo n.º 2
0
int Run(LPTSTR lpstrCmdLine = NULL, int nCmdShow = SW_SHOWDEFAULT)
{
	CMessageLoop theLoop;
	_Module.AddMessageLoop(&theLoop);

	HRESULT hr = S_FALSE;
	BOOL fSuccess = FALSE;

	fSuccess = InitSystemCfg();
	if (!fSuccess) {
		pAppInitErrMessage(IDS_APP_INIT_ERROR_OUT_OF_MEMORY);
		return ::GetLastError();
	}

	fSuccess = InitUserCfg();
	if (!fSuccess) {
		pAppInitErrMessage(IDS_APP_INIT_ERROR_OUT_OF_MEMORY);
		return ::GetLastError();
	}

	// command line override the registry settings
	LANGID wPrefLangID = pGetPreferredLangID(lpstrCmdLine);
	fSuccess = pLoadResourceModule(wPrefLangID);
	if (!fSuccess) {
		return 255;
	}

	// not need to initialize each time.
	fSuccess = NdasCommInitialize();
	if (!fSuccess) {
		return 254;
	}



	CMainFrame wndMain;

	if(wndMain.CreateEx() == NULL)
	{
		ATLTRACE(_T("Main window creation failed!\n"));
		return 0;
	}

	wndMain.ShowWindow(nCmdShow);

	int nRet = theLoop.Run();

	_Module.RemoveMessageLoop();
	return nRet;
}
Ejemplo n.º 3
0
int 
_tWinMain(
	__in HINSTANCE hInstance, 
	__in_opt HINSTANCE hPrevInstance, 
	__in_opt LPTSTR lpCmdLine,
	__in int nShowCmd )
{
	COMVERIFY(CoInitialize(NULL));

	// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
	(void) DefWindowProc(NULL, 0, 0, 0L);

	// add flags to support other controls
	ATLVERIFY(AtlInitCommonControls(ICC_WIN95_CLASSES | ICC_INTERNET_CLASSES));	

	COMVERIFY(_Module.Init(NULL, hInstance));

	int retCode = -1;

	if (!VerifyNdasComm())
	{
		AtlMessageBox(
			NULL, 
			IDS_NDASCOMM_NOT_AVAILABLE, 
			IDS_APP_ERROR_TITLE, 
			MB_OK | MB_ICONSTOP);
	}
	else
	{
		ATLVERIFY( NdasCommInitialize() );
		retCode = Run(lpCmdLine, nShowCmd);
		ATLVERIFY( NdasCommUninitialize() );
	}

	_Module.Term();

	CoUninitialize();

	return retCode;
}
Ejemplo n.º 4
0
int __cdecl main()
{
	BOOL ret;
	NDASCOMM_CONNECTION_INFO ci;
	UINT32 nDiskCount = 1;

	ci.Size = sizeof(NDASCOMM_CONNECTION_INFO);
	ci.AddressType = NDASCOMM_CIT_DEVICE_ID;
	ci.Address.DeviceId.Node[0] = 0x00;
	ci.Address.DeviceId.Node[1] = 0x0b;
	ci.Address.DeviceId.Node[2] = 0xd0;
	ci.Address.DeviceId.Node[3] = 0x00;
	ci.Address.DeviceId.Node[4] = 0xa8;
	ci.Address.DeviceId.Node[5] = 0x4d;
	ci.UnitNo = 0;

	ret = NdasCommInitialize();
	if (!ret)
	{
		return GetLastError();
	}

	ret = NdasOpBind(nDiskCount, &ci, NMT_SINGLE, 0);

	if(ret != nDiskCount)
	{
		DWORD error = GetLastError();
		_tprintf(_T("Error %d (0x%08x)\n"), error, error);

		(void) NdasCommUninitialize();

		return error;
	}

	_tprintf(_T("Success\n"));

	(void) NdasCommUninitialize();

	return 0;
}
Ejemplo n.º 5
0
/*
main function
returns non-zero if any function fails.
*/
int __cdecl wmain( int argc, wchar_t *argv[ ], wchar_t *envp[ ] )
{
	BOOL bResult;
	DWORD dwError = 0;
	DWORD i;

	DWORD dwVersion;

	HNDAS hNDAS = NULL;
	NDASCOMM_CONNECTION_INFO ci;
	BYTE DeviceID[6];
	DWORD dwUnitNo;

	PBYTE Buffer;
	DWORD dwBufferLen;
	BYTE data[512]; /* 1 sector sized buffer */
	INT64 i64Location;
	UINT ui64SectorCount;
	NDASCOMM_IDE_REGISTER IdeRegister;
	BYTE pbData[8];
	DWORD cbData = sizeof(pbData);
	NDASCOMM_VCMD_PARAM param_vcmd;
	UINT32 uiTimeValue;
	BOOL bEnableTimer;

	NDAS_DEVICE_HARDWARE_INFO dinfo;

	BYTE vid;

	/* simple check parameter */
	if(2 != argc)
	{
		wprintf(
			L"usage : apitest.exe ID-KEY\n"
			L"\n"
			L"ID-KEY : 20 chars of id and 5 chars of key of the NDAS Device ex(01234ABCDE56789FGHIJ13579)\n"
			L"ex : apitest.exe 01234ABCDE56789FGHIJ13579\n"
			);
		wprintf(L"\n");
		return -1;
	}

	wprintf(L"\n\n\n* Start NDASComm API test on the NDAS Device : %s\n", argv[1]);

	wprintf(L"* Initialize NdasComm library : NdasCommInitialize()\n");
	API_CALL(NdasCommInitialize());

	wprintf(L"* Get API Version : NdasCommGetAPIVersion()\n");
	API_CALL_JMP(dwVersion = NdasCommGetAPIVersion(), out);
	wprintf(L"- Version : Major %d, Minor %d\n",
		(int)LOWORD(dwVersion), (int)HIWORD(dwVersion));

//////////////////////////////////////////////////////////////
//#define	TEST_SET_PASSWORD

#ifdef TEST_SET_PASSWORD
	wprintf(L"### TESTING 'Set user password' ###\n");

	ZeroMemory(&ci, sizeof(ci));
	ci.Size = sizeof(NDASCOMM_CONNECTION_INFO);
	ci.AddressType = NDASCOMM_CIT_NDAS_IDW; /* wide char set */
	ci.UnitNo = 0; /* Use first Unit Device */
	ci.WriteAccess = TRUE; /* Connect with read-write privilege */
	ci.Protocol = NDASCOMM_TRANSPORT_LPX; /* Use LPX protocol */

	CopyMemory(
		ci.OEMCode.Bytes,
		NdasOemCodeX1, 
		sizeof(NdasOemCodeX1)); /* HASH_KEY_USER_X1 */ /* Use default password */

	CopyMemory(
		ci.PrivilegedOEMCode.Bytes, 
		NdasPrivOemCodeX1, 
		sizeof(NdasPrivOemCodeX1)); /* HASH_KEY_SUPER_X1 */ /* Log in as super user */

	ci.LoginType = NDASCOMM_LOGIN_TYPE_NORMAL; /* Normal operations */

	wcsncpy(ci.NdasIdW.Id, argv[1], 20); /* ID */
	wcsncpy(ci.NdasIdW.Key, argv[1] +20, 5); /* Key */

	wprintf(L"* Connect to the NDAS Device : NdasCommConnect()\n");
	API_CALL_JMP(
		hNDAS = NdasCommConnect(
		&ci,
		0 /* synchronous mode */,
		NULL /* no connection hint */
		),
		out);

	wprintf(L"* Setting user password : NdasCommVendorCommand()\n");

	*(UINT64 *)param_vcmd.SET_SUPERVISOR_PW.SupervisorPassword = HASH_KEY_SUPER_X1;
	bResult = NdasCommVendorCommand(hNDAS, ndascomm_vcmd_set_supervisor_pw, &param_vcmd, NULL, 0, NULL, 0);
	if(!bResult)
	{
		if(NDASCOMM_ERROR_HARDWARE_UNSUPPORTED != GetLastError())
		{
			API_CALL_JMP(FALSE && "NdasCommVendorCommand", out);
		}
		wprintf(L"- Not supported for this Hardware version\n");
	}

	*(UINT64 *)param_vcmd.SET_USER_PW.UserPassword = HASH_KEY_USER_X1;
	bResult = NdasCommVendorCommand(hNDAS, ndascomm_vcmd_set_user_pw, &param_vcmd, NULL, 0, NULL, 0);
	if(!bResult)
	{
		if(NDASCOMM_ERROR_HARDWARE_UNSUPPORTED != GetLastError())
		{
			API_CALL_JMP(FALSE && "NdasCommVendorCommand", out);
		}
		wprintf(L"- Not supported for this Hardware version\n");
	}

#define TEST_SET_PASSWORD_RESET
#ifdef TEST_SET_PASSWORD_RESET
	wprintf(L"* Resetting : NdasCommVendorCommand()\n");
	bResult = NdasCommVendorCommand(hNDAS, ndascomm_vcmd_reset, &param_vcmd, NULL, 0, NULL, 0);
	if(!bResult)
	{
		if(NDASCOMM_ERROR_HARDWARE_UNSUPPORTED != GetLastError())
		{
			API_CALL_JMP(FALSE && "NdasCommVendorCommand", out);
		}
		wprintf(L"- Not supported for this Hardware version\n");
	}
#else
	wprintf(L"* Disconnect the connection from the NDAS Device : NdasCommDisconnect()\n");
	API_CALL_JMP(NdasCommDisconnect(hNDAS), out);
#endif //TEST_SET_PASSWORD_RESET
	wprintf(L"### TESTED 'Set user passoword' ###\n");

#endif //TEST_SET_PASSWORD
//////////////////////////////////////////////////////////////

	wprintf(L"* Initialize connection info to create connection to the NDAS Device\n");
	ZeroMemory(&ci, sizeof(ci));
	ci.Size = sizeof(NDASCOMM_CONNECTION_INFO);
	ci.AddressType = NDASCOMM_CIT_NDAS_IDW; /* wide char set */
	ci.UnitNo = 0; /* Use first Unit Device */
	ci.WriteAccess = TRUE; /* Connect with read-write privilege */
	ci.Protocol = NDASCOMM_TRANSPORT_LPX; /* Use LPX protocol */
	ci.OEMCode.UI64Value = 0; /* Use default password */
	ci.PrivilegedOEMCode.UI64Value = 0; /* Log in as normal user */
	ci.LoginType = NDASCOMM_LOGIN_TYPE_NORMAL; /* Normal operations */
	wcsncpy(ci.Address.NdasIdW.Id, argv[1], 20); /* ID */
	wcsncpy(ci.Address.NdasIdW.Key, argv[1] + 20, 5); /* Key */

	wprintf(L"* Connect to the NDAS Device : NdasCommConnect()\n");
	API_CALL_JMP( hNDAS = NdasCommConnect(&ci), out );

	wprintf(L"* Retrieve NDAS Device ID & unit number : NdasCommGetDeviceID()\n");
	API_CALL_JMP(NdasCommGetDeviceID(hNDAS, NULL, DeviceID, &dwUnitNo, &vid), out);
	wprintf(L"- DeviceID : %02X%02X%02X%02X%02X%02X, Unit No. : %d\n",
		DeviceID[0], DeviceID[1], DeviceID[2], DeviceID[3], DeviceID[4], DeviceID[5],
		(int)dwUnitNo);

	wprintf(L"* Retrieve the address of the host attached to the NDAS Device : NdasCommGetHostAddress()\n");
	API_CALL_JMP(NdasCommGetHostAddress(hNDAS, NULL, &dwBufferLen), out);
	wprintf(L"- buffer length : %d\n", dwBufferLen);
	Buffer = malloc(dwBufferLen);
	API_CALL_JMP(NdasCommGetHostAddress(hNDAS, Buffer, &dwBufferLen), out);
	wprintf(L"- Host Address : ");
	for(i = 0 ; i < dwBufferLen; i++)
	{
		wprintf(L"%02X", (UINT)Buffer[i]);
	}
	wprintf(L"\n");
	free(Buffer);

	ui64SectorCount = 1;
	i64Location = 0;

	wprintf(L"* Read %d sector(s) of data from Address %d : NdasCommBlockDeviceRead()\n",
		ui64SectorCount, i64Location);
	API_CALL_JMP(NdasCommBlockDeviceRead(hNDAS, i64Location, ui64SectorCount, data), out);

	i64Location = 1;
	wprintf(L"* Write %d sector(s) of data to Address %d : NdasCommBlockDeviceWriteSafeBuffer()\n",
		ui64SectorCount, i64Location);
	API_CALL_JMP(NdasCommBlockDeviceWriteSafeBuffer(hNDAS, i64Location, ui64SectorCount, data), out);

	ui64SectorCount = 2;
	i64Location = 2;
	wprintf(L"* Verify %d sector(s) from Address %d : NdasCommBlockDeviceVerify()\n",
		ui64SectorCount, i64Location);
	API_CALL_JMP(NdasCommBlockDeviceVerify(hNDAS, i64Location, ui64SectorCount), out);

	IdeRegister.command.command = 0xEC; /* WIN_IDENTIFY */
	IdeRegister.device.dev = 0;
	wprintf(L"* Identify the NDAS Unit Device : NdasCommIdeCommand()\n");
	API_CALL_JMP(NdasCommIdeCommand(hNDAS, &IdeRegister, NULL, 0, data, 512), out);
	/* data[] now has 512 bytes of identified data as per ANSI NCITS ATA6 rev.1b spec */


	ZeroMemory(&dinfo, sizeof(NDAS_DEVICE_HARDWARE_INFO));
	dinfo.Size = sizeof(NDAS_DEVICE_HARDWARE_INFO);
	API_CALL_JMP(NdasCommGetDeviceHardwareInfo(hNDAS,&dinfo), out);
	wprintf(L"Hardware Version : %d\n", dinfo.HardwareVersion);

	wprintf(L"* get standby timer : NdasCommVendorCommand()\n");
	bResult = NdasCommVendorCommand(hNDAS, ndascomm_vcmd_get_ret_time, &param_vcmd, NULL, 0, NULL, 0);
	if(!bResult)
	{
		if(NDASCOMM_ERROR_HARDWARE_UNSUPPORTED != GetLastError())
		{
			API_CALL_JMP(FALSE && "NdasCommVendorCommand", out);
		}
		wprintf(L"- Not supported for this Hardware version\n");
	}
	else
	{
		uiTimeValue = param_vcmd.GET_STANDBY_TIMER.TimeValue;
		bEnableTimer = param_vcmd.GET_STANDBY_TIMER.EnableTimer;
		wprintf(L"- standby timer : %d, enable : %d\n", uiTimeValue, bEnableTimer);

		param_vcmd.SET_STANDBY_TIMER.TimeValue = uiTimeValue;
		param_vcmd.SET_STANDBY_TIMER.EnableTimer = bEnableTimer ? 0 : 1;
		wprintf(L"* set standby timer : NdasCommVendorCommand()\n");
		API_CALL_JMP(NdasCommVendorCommand(hNDAS, ndascomm_vcmd_set_ret_time, &param_vcmd, NULL, 0, NULL, 0), out);

		uiTimeValue = param_vcmd.SET_STANDBY_TIMER.TimeValue;
		bEnableTimer = param_vcmd.SET_STANDBY_TIMER.EnableTimer;
		wprintf(L"- standby timer : %d, enable : %d\n", uiTimeValue, bEnableTimer);
	}

	wprintf(L"* Disconnect the connection from the NDAS Device : NdasCommDisconnect()\n");
	API_CALL_JMP(NdasCommDisconnect(hNDAS), out);

	wprintf(L"* Uninitialize NDASComm API : NdasCommUninitialize()\n");

out:
	if(hNDAS)
	{
		NdasCommDisconnect(hNDAS);
		hNDAS = NULL;
	}

	API_CALL(NdasCommUninitialize());
	return GetLastError();
}
Ejemplo n.º 6
0
int
CpSetRetTime(int argc, _TCHAR* argv[])
{
    HNDAS hNDAS = NULL;
    NDASCOMM_CONNECTION_INFO ci;
    BYTE DeviceID[6];
    DWORD dwUnitNo;
    NDASCOMM_VCMD_PARAM param_vcmd;
    ULONG				retTime;

    //
    //	Get arguments.
    //
    if(argc < 3) {
        _ftprintf(stderr, _T("ERROR: More parameter needed.\n"));
        return -1;
    }

    retTime = _tcstoul(argv[2], NULL, 10);
    if(retTime == 0) {

        //
        //	Check to see if a user inputs the zero.
        //

        if( argv[2][0] != _T('0') ||
                argv[2][1] != _T('\0')
          ) {
            _ftprintf(stderr, _T("ERROR: Invalid timeout value.\n"));
            return -1;
        }
    }



    _ftprintf(stdout, _T("Starting the operation...\n"));
    SetLastError(0);
    API_CALL(NdasCommInitialize());


    //
    //	Connect and login
    //

    ZeroMemory(&ci, sizeof(ci));
    ci.Size = sizeof(NDASCOMM_CONNECTION_INFO);
    ci.AddressType = NDASCOMM_CIT_NDAS_ID; /* Use NDAS ID */
    ci.UnitNo = 0; /* Use first Unit Device */
    ci.WriteAccess = FALSE; /* Connect with read-write privilege */
    ci.Protocol = NDASCOMM_TRANSPORT_LPX; /* Use LPX protocol */
    ci.OEMCode.UI64Value = 0; /* Use default password */

    /* Log in as super user */
    ci.PrivilegedOEMCode = NDAS_DEFAULT_PRIVILEGED_OEM_CODE;
    /* Privileged Connection cannot use lock commands */
    ci.Flags = NDASCOMM_CNF_DISABLE_LOCK_CLEANUP_ON_CONNECT;

    ci.LoginType = NDASCOMM_LOGIN_TYPE_NORMAL; /* Normal operations */
    _tcsncpy(ci.Address.NdasId.Id, argv[0], 20); /* ID */
    _tcsncpy(ci.Address.NdasId.Key, argv[1], 5); /* Key */
    API_CALL_JMP( hNDAS = NdasCommConnect(&ci), out);

    //
    //	Display NDAS device info
    //

    API_CALL_JMP(NdasCommGetDeviceID(hNDAS, DeviceID, &dwUnitNo), out);
    _tprintf(L"DeviceID : %02X%02X%02X%02X%02X%02X, Unit No. : %d\n",
             DeviceID[0], DeviceID[1], DeviceID[2], DeviceID[3], DeviceID[4], DeviceID[5],
             (int)dwUnitNo);


    //
    //	Set connection timeout
    //

    _ftprintf(stderr, _T("Applying setting to the device...\n"));
    ZeroMemory(&param_vcmd, sizeof(NDASCOMM_VCMD_PARAM));

    param_vcmd.SET_RET_TIME.RetTime = retTime;
    API_CALL_JMP(NdasCommVendorCommand(hNDAS, ndascomm_vcmd_set_ret_time, &param_vcmd, NULL, 0, NULL, 0), out);

    _ftprintf(stderr, _T("Resetting the device...\n"));
    ZeroMemory(&param_vcmd, sizeof(NDASCOMM_VCMD_PARAM));
    API_CALL_JMP(NdasCommVendorCommand(hNDAS, ndascomm_vcmd_reset, &param_vcmd, NULL, 0, NULL, 0), out);

out:
    if(GetLastError()) {
        _ftprintf(stdout, _T("Error! Code:%08lx\n"), GetLastError());
    }

    if(hNDAS)
    {
        NdasCommDisconnect(hNDAS);
        hNDAS = NULL;
    }

    NdasCommUninitialize();

    _ftprintf(stdout, _T("Finished the operation.\n"));

    return GetLastError();
}
Ejemplo n.º 7
0
int
CpSetMacAddress(int argc, _TCHAR* argv[])
{
    HNDAS hNDAS = NULL;
    NDASCOMM_CONNECTION_INFO ci;
    BYTE DeviceID[6];
    DWORD dwUnitNo;
    NDASCOMM_VCMD_PARAM param_vcmd;
    _TCHAR *MacAddress;
    size_t argv_len;
    ULONG	MacAddressSegs[6];

    //
    //	Get arguments.
    //
    if(argc < 3) {
        _ftprintf(stderr, _T("ERROR: More parameter needed.\n"));
        return -1;
    }

    // Mac address : XX:XX:XX:XX:XX:XX
    MacAddress = argv[2];

    if(17 != _tcslen(MacAddress) ||
            _T(':') != MacAddress[2] ||
            _T(':') != MacAddress[5] ||
            _T(':') != MacAddress[8] ||
            _T(':') != MacAddress[11] ||
            _T(':') != MacAddress[14])
    {
        _ftprintf(stderr, _T("ERROR: Invalid MAC address. \n"));
        return -1;
    }

    if(6 != _stscanf(MacAddress, _T("%02X:%02X:%02X:%02X:%02X:%02X"),
                     &MacAddressSegs[0],
                     &MacAddressSegs[1],
                     &MacAddressSegs[2],
                     &MacAddressSegs[3],
                     &MacAddressSegs[4],
                     &MacAddressSegs[5]))
    {
        _ftprintf(stderr, _T("ERROR: Invalid MAC address. \n"));
        return -1;
    }

    _ftprintf(stdout, _T("Starting the operation...\n"));
    SetLastError(0);
    API_CALL(NdasCommInitialize());


    //
    //	Connect and login
    //

    ZeroMemory(&ci, sizeof(ci));
    ci.Size = sizeof(NDASCOMM_CONNECTION_INFO);
    ci.AddressType = NDASCOMM_CIT_NDAS_ID; /* Use NDAS ID */
    ci.UnitNo = 0; /* Use first Unit Device */
    ci.WriteAccess = FALSE; /* Connect with read-write privilege */
    ci.Protocol = NDASCOMM_TRANSPORT_LPX; /* Use LPX protocol */
    ci.OEMCode.UI64Value = 0; /* Use default password */

    /* Log in as super user */
    ci.PrivilegedOEMCode = NDAS_DEFAULT_PRIVILEGED_OEM_CODE;
    /* Privileged Connection cannot use lock commands */
    ci.Flags = NDASCOMM_CNF_DISABLE_LOCK_CLEANUP_ON_CONNECT;

    ci.LoginType = NDASCOMM_LOGIN_TYPE_NORMAL; /* Normal operations */
    _tcsncpy(ci.Address.NdasId.Id, argv[0], 20); /* ID */
    _tcsncpy(ci.Address.NdasId.Key, argv[1], 5); /* Key */
    API_CALL_JMP( hNDAS = NdasCommConnect(&ci), out);

    //
    //	Display NDAS device info
    //

    API_CALL_JMP(NdasCommGetDeviceID(hNDAS, DeviceID, &dwUnitNo), out);
    _tprintf(L"DeviceID : %02X%02X%02X%02X%02X%02X, Unit No. : %d\n",
             DeviceID[0], DeviceID[1], DeviceID[2], DeviceID[3], DeviceID[4], DeviceID[5],
             (int)dwUnitNo);


    //
    //	Set Mac address
    //

    _ftprintf(stderr, _T("Applying setting to the device...\n"));
    ZeroMemory(&param_vcmd, sizeof(NDASCOMM_VCMD_PARAM));

    param_vcmd.SET_LPX_ADDRESS.AddressLPX[0] = (BYTE)MacAddressSegs[0];
    param_vcmd.SET_LPX_ADDRESS.AddressLPX[1] = (BYTE)MacAddressSegs[1];
    param_vcmd.SET_LPX_ADDRESS.AddressLPX[2] = (BYTE)MacAddressSegs[2];
    param_vcmd.SET_LPX_ADDRESS.AddressLPX[3] = (BYTE)MacAddressSegs[3];
    param_vcmd.SET_LPX_ADDRESS.AddressLPX[4] = (BYTE)MacAddressSegs[4];
    param_vcmd.SET_LPX_ADDRESS.AddressLPX[5] = (BYTE)MacAddressSegs[5];
    API_CALL_JMP(NdasCommVendorCommand(hNDAS, ndascomm_vcmd_set_lpx_address, &param_vcmd, NULL, 0, NULL, 0), out);

    _ftprintf(stderr, _T("Resetting the device...\n"));
    ZeroMemory(&param_vcmd, sizeof(NDASCOMM_VCMD_PARAM));
    API_CALL_JMP(NdasCommVendorCommand(hNDAS, ndascomm_vcmd_reset, &param_vcmd, NULL, 0, NULL, 0), out);

out:
    if(GetLastError()) {
        _ftprintf(stdout, _T("Error! Code:%08lx\n"), GetLastError());
    }

    if(hNDAS)
    {
        NdasCommDisconnect(hNDAS);
        hNDAS = NULL;
    }

    NdasCommUninitialize();

    _ftprintf(stdout, _T("Finished the operation.\n"));

    return GetLastError();
}
Ejemplo n.º 8
0
int
CpQueryConTimeout(int argc, _TCHAR* argv[])
{
    HNDAS hNDAS = NULL;
    NDASCOMM_CONNECTION_INFO ci;
    BYTE DeviceID[6];
    DWORD dwUnitNo;
    NDASCOMM_VCMD_PARAM param_vcmd;

    //
    //	Get arguments.
    //
    if(argc < 2) {
        _ftprintf(stderr, _T("ERROR: More parameter needed.\n"));
        return -1;
    }

    _ftprintf(stdout, _T("Starting the operation...\n"));
    SetLastError(0);
    API_CALL(NdasCommInitialize());


    //
    //	Connect and login
    //

    ZeroMemory(&ci, sizeof(ci));
    ci.Size = sizeof(NDASCOMM_CONNECTION_INFO);
    ci.AddressType = NDASCOMM_CIT_NDAS_ID; /* Use NDAS ID */
    ci.UnitNo = 0; /* Use first Unit Device */
    ci.WriteAccess = FALSE; /* Connect with read-write privilege */
    ci.Protocol = NDASCOMM_TRANSPORT_LPX; /* Use LPX protocol */
    ci.OEMCode.UI64Value = 0; /* Use default password */
    ci.PrivilegedOEMCode.UI64Value = 0; /* Log in as normal user */
    ci.LoginType = NDASCOMM_LOGIN_TYPE_NORMAL; /* Normal operations */
    _tcsncpy(ci.Address.NdasId.Id, argv[0], 20); /* ID */
    _tcsncpy(ci.Address.NdasId.Key, argv[1], 5); /* Key */
    API_CALL_JMP( hNDAS = NdasCommConnect(&ci), out);

    //
    //	Display NDAS device info
    //

    API_CALL_JMP(NdasCommGetDeviceID(hNDAS, DeviceID, &dwUnitNo), out);
    _tprintf(L"DeviceID : %02X%02X%02X%02X%02X%02X, Unit No. : %d\n",
             DeviceID[0], DeviceID[1], DeviceID[2], DeviceID[3], DeviceID[4], DeviceID[5],
             (int)dwUnitNo);


    //
    //	Query Connection timeout
    //

    ZeroMemory(&param_vcmd, sizeof(NDASCOMM_VCMD_PARAM));
    API_CALL_JMP(NdasCommVendorCommand(hNDAS, ndascomm_vcmd_get_max_conn_time, &param_vcmd, NULL, 0, NULL, 0), out);

out:
    if(GetLastError()) {
        _ftprintf(stdout, _T("Error! Code:%08lx\n"), GetLastError());
    }

    if(hNDAS)
    {
        NdasCommDisconnect(hNDAS);
        hNDAS = NULL;
    }

    NdasCommUninitialize();

    _ftprintf(stdout, _T("Finished the operation.\n"));

    _ftprintf(stderr, _T("\nConnection timeout: %d.\n"), param_vcmd.GET_MAX_CONN_TIME.MaxConnTime);

    return GetLastError();
}
Ejemplo n.º 9
0
int
CpDeviceStandby(int argc, _TCHAR* argv[])
{
    HNDAS hNDAS = NULL;
    NDASCOMM_CONNECTION_INFO ci;
    BYTE DeviceID[6];
    DWORD dwUnitNo;
    NDASCOMM_IDE_REGISTER IdeRegister;

    //
    //	Get arguments.
    //
    if(argc < 2) {
        _ftprintf(stderr, _T("ERROR: More parameter needed.\n"));
        return -1;
    }

    _ftprintf(stdout, _T("Starting the operation...\n"));
    SetLastError(0);
    API_CALL(NdasCommInitialize());


    //
    //	Connect and login
    //

    ZeroMemory(&ci, sizeof(ci));
    ci.Size = sizeof(NDASCOMM_CONNECTION_INFO);
    ci.AddressType = NDASCOMM_CIT_NDAS_ID; /* Use NDAS ID*/
    ci.UnitNo = 0; /* Use first Unit Device */
    ci.WriteAccess = TRUE; /* Connect with read-write privilege */
    ci.Protocol = NDASCOMM_TRANSPORT_LPX; /* Use LPX protocol */
    ci.OEMCode.UI64Value = 0; /* Use default password */
    ci.PrivilegedOEMCode.UI64Value = 0; /* Log in as normal user */
    ci.LoginType = NDASCOMM_LOGIN_TYPE_NORMAL; /* Normal operations */
    _tcsncpy(ci.Address.NdasId.Id, argv[0], 20); /* ID */
    _tcsncpy(ci.Address.NdasId.Key, argv[1], 5); /* Key */
    API_CALL_JMP( hNDAS = NdasCommConnect(&ci), out);

    //
    //	Display NDAS device info
    //

    API_CALL_JMP(NdasCommGetDeviceID(hNDAS, DeviceID, &dwUnitNo), out);
    _tprintf(L"DeviceID : %02X%02X%02X%02X%02X%02X, Unit No. : %d\n",
             DeviceID[0], DeviceID[1], DeviceID[2], DeviceID[3], DeviceID[4], DeviceID[5],
             (int)dwUnitNo);


    //
    //	Request the NDAS device to enter Standby mode
    //
    ZeroMemory(&IdeRegister, sizeof(NDASCOMM_IDE_REGISTER));
    IdeRegister.command.command = 0xE0; /* WIN_STANDBYNOW1 */
    IdeRegister.device.dev = 0;
    API_CALL_JMP(NdasCommIdeCommand(hNDAS, &IdeRegister, NULL, 0, NULL, 0), out);

out:
    if(GetLastError()) {
        _ftprintf(stdout, _T("Error! Code:%08lx\n"), GetLastError());
    }

    if(hNDAS)
    {
        NdasCommDisconnect(hNDAS);
        hNDAS = NULL;
    }

    NdasCommUninitialize();

    _ftprintf(stdout, _T("Finished the operation.\n"));

    return GetLastError();
}
Ejemplo n.º 10
0
int
CpGetEncryptionMode(int argc, _TCHAR* argv[])
{
    HNDAS hNDAS = NULL;
    NDASCOMM_CONNECTION_INFO ci;
    BYTE DeviceID[6];
    DWORD dwUnitNo;
    NDASCOMM_VCMD_PARAM param_vcmd;
    /*	PNDASCOMM_HANDLE_CONTEXT Context;
    	UINT16 HeaderEnc=FALSE;
    	UINT16 DataEnc = FALSE;  */
    //
    //	Get arguments.
    //
    if(argc < 2) {
        _ftprintf(stderr, _T("ERROR: More parameter needed.\n"));
        return -1;
    }

    _ftprintf(stdout, _T("Starting the operation...\n"));
    SetLastError(0);
    API_CALL(NdasCommInitialize());


    //
    //	Connect and login
    //

    ZeroMemory(&ci, sizeof(ci));
    ci.Size = sizeof(NDASCOMM_CONNECTION_INFO);
    ci.AddressType = NDASCOMM_CIT_NDAS_ID; /* Use NDAS ID */
    ci.UnitNo = 0; /* Use first Unit Device */
    ci.WriteAccess = FALSE; /* Connect with read-write privilege */
    ci.Protocol = NDASCOMM_TRANSPORT_LPX; /* Use LPX protocol */
    ci.OEMCode.UI64Value = 0; /* Use default password */
    ci.PrivilegedOEMCode.UI64Value = 0; /* Log in as normal user */
    ci.LoginType = NDASCOMM_LOGIN_TYPE_NORMAL; /* Normal operations */
    _tcsncpy(ci.Address.NdasId.Id, argv[0], 20); /* ID */
    _tcsncpy(ci.Address.NdasId.Key, argv[1], 5); /* Key */
    API_CALL_JMP( hNDAS = NdasCommConnect(&ci), out);

    //
    //	Display NDAS device info
    //

    API_CALL_JMP(NdasCommGetDeviceID(hNDAS, DeviceID, &dwUnitNo), out);
    _tprintf(L"DeviceID : %02X%02X%02X%02X%02X%02X, Unit No. : %d\n",
             DeviceID[0], DeviceID[1], DeviceID[2], DeviceID[3], DeviceID[4], DeviceID[5],
             (int)dwUnitNo);

    _tprintf(L"This vendor operation is not supported yet\n");
    /*
    	Context = NdasHandleToContext(hNDAS);

    	lsp_get_handle_info(
    		Context->hLSP,
    		lsp_handle_info_hw_header_encrypt_algo,
    		&HeaderEnc,  sizeof(HeaderEnc));
    	lsp_get_handle_info(
    		Context->hLSP,
    		lsp_handle_info_hw_data_encrypt_algo,
    		&DataEnc,  sizeof(DataEnc));
    */

out:
    if(GetLastError()) {
        _ftprintf(stdout, _T("Error! Code:%08lx\n"), GetLastError());
    }

    if(hNDAS)
    {
        NdasCommDisconnect(hNDAS);
        hNDAS = NULL;
    }

    NdasCommUninitialize();

    _ftprintf(stdout, _T("Finished the operation.\n"));

//	_ftprintf(stderr, _T("\nRetransmission time: %d milli-seconds.\n"), param_vcmd.GET_MAX_CONN_TIME.MaxConnTime);

    return GetLastError();
}
Ejemplo n.º 11
0
int
CpSetEncryptionMode(int argc, _TCHAR* argv[])
{
    HNDAS hNDAS = NULL;
    NDASCOMM_CONNECTION_INFO ci;
    BYTE DeviceID[6];
    DWORD dwUnitNo;
    NDASCOMM_VCMD_PARAM param_vcmd;
    ULONG				HeaderEnc;
    ULONG				DataEnc;

    //
    //	Get arguments.
    //
    if(argc < 4) {
        _ftprintf(stderr, _T("ERROR: Header encryption mode and data encryption mode is required.\n"));
        return -1;
    }

    HeaderEnc = _tcstoul(argv[2], NULL, 10);
    if(HeaderEnc != 0 && HeaderEnc!=1) {
        _ftprintf(stderr, _T("ERROR: Avaiable header encryption mode is 0 (off) or 1 (hash encryption).\n"));
        return -1;
    }

    DataEnc = _tcstoul(argv[2], NULL, 10);
    if(DataEnc != 0 && DataEnc!=1) {
        _ftprintf(stderr, _T("ERROR: Avaiable header encryption mode is 0 (off) or 1 (hash encryption).\n"));
        return -1;
    }

    SetLastError(0);
    API_CALL(NdasCommInitialize());


    //
    //	Connect and login
    //

    ZeroMemory(&ci, sizeof(ci));
    ci.Size = sizeof(NDASCOMM_CONNECTION_INFO);
    ci.AddressType = NDASCOMM_CIT_NDAS_ID; /* Use NDAS ID */
    ci.UnitNo = 0; /* Use first Unit Device */
    ci.WriteAccess = FALSE; /* Connect with read-write privilege */
    ci.Protocol = NDASCOMM_TRANSPORT_LPX; /* Use LPX protocol */
    ci.OEMCode.UI64Value = 0; /* Use default password */

    /* Log in as super user */
    ci.PrivilegedOEMCode = NDAS_DEFAULT_PRIVILEGED_OEM_CODE;
    /* Privileged Connection cannot use lock commands */
    ci.Flags = NDASCOMM_CNF_DISABLE_LOCK_CLEANUP_ON_CONNECT;

    ci.LoginType = NDASCOMM_LOGIN_TYPE_NORMAL; /* Normal operations */
    _tcsncpy(ci.Address.NdasId.Id, argv[0], 20); /* ID */
    _tcsncpy(ci.Address.NdasId.Key, argv[1], 5); /* Key */
    API_CALL_JMP( hNDAS = NdasCommConnect(&ci), out);

    //
    //	Display NDAS device info
    //

    API_CALL_JMP(NdasCommGetDeviceID(hNDAS, DeviceID, &dwUnitNo), out);
    _tprintf(L"DeviceID : %02X%02X%02X%02X%02X%02X, Unit No. : %d\n",
             DeviceID[0], DeviceID[1], DeviceID[2], DeviceID[3], DeviceID[4], DeviceID[5],
             (int)dwUnitNo);


    //
    //	Set encryption mode
    //

    _ftprintf(stderr, _T("Applying setting to the device...\n"));
    ZeroMemory(&param_vcmd, sizeof(NDASCOMM_VCMD_PARAM));

    param_vcmd.SET_ENC_OPT.EncryptHeader = HeaderEnc;
    param_vcmd.SET_ENC_OPT.EncryptData = DataEnc;

    API_CALL_JMP(NdasCommVendorCommand(hNDAS, ndascomm_vcmd_set_enc_opt, &param_vcmd, NULL, 0, NULL, 0), out);

    _ftprintf(stderr, _T("Resetting the device...\n"));
    ZeroMemory(&param_vcmd, sizeof(NDASCOMM_VCMD_PARAM));
    API_CALL_JMP(NdasCommVendorCommand(hNDAS, ndascomm_vcmd_reset, &param_vcmd, NULL, 0, NULL, 0), out);

out:
    if(GetLastError()) {
        _ftprintf(stdout, _T("Error! Code:%08lx\n"), GetLastError());
    }

    if(hNDAS)
    {
        NdasCommDisconnect(hNDAS);
        hNDAS = NULL;
    }

    NdasCommUninitialize();

    _ftprintf(stdout, _T("Finished the operation.\n"));

    return GetLastError();
}
Ejemplo n.º 12
0
int 
__cdecl 
_tmain(int argc, TCHAR** argv)
{
	BOOL success;
	UINT32 i;
	UINT32 nUnitDevices;

	NDASCOMM_CONNECTION_INFO ci = {0};

//	getc(stdin);
//	Sleep(3000);
	ci.Size = sizeof(NDASCOMM_CONNECTION_INFO);

    if (!check_ndascomm_api_version())
    {
        return 1;
    }
    
	ci.UnitNo = 0; /* Use first Unit Device */
	ci.WriteAccess = FALSE; /* Connect with read-write privilege */
	ci.Protocol = NDASCOMM_TRANSPORT_LPX; /* Use LPX protocol */
	ci.PrivilegedOEMCode.UI64Value = 0; /* Log in as normal user */

	success = (argc > 1) && parse_connection_info(&ci, argc - 1, argv + 1);
	if (!success)
	{
		usage();
		return 1;
	}

	API_CALL(success = NdasCommInitialize());

	if (!success)
	{
		_tprintf(_T("Subsystem initialization failed\n"));
		print_last_error_message();
		return 1;
	}

	ci.LoginType= NDASCOMM_LOGIN_TYPE_NORMAL; /* Normal operations */
	_tprintf(_T("\n"));
	_tprintf(_T("NDAS device information\n\n"));
	success = print_ndas_device_info(&ci);

	ci.LoginType = NDASCOMM_LOGIN_TYPE_DISCOVER;
	nUnitDevices = get_ndas_unit_device_count(&ci);

	if (0 == nUnitDevices)
	{
		_tprintf(_T(" No unit devices are found.\n"));
	} 
	else if ((UINT)-1 == nUnitDevices) 
	{
		_tprintf(_T(" Failed to get device count\n"));
		nUnitDevices = 0;
	}

	for (i = 0; i < nUnitDevices; i++)
	{
		_tprintf(_T(" Unit device [%d/%d]\n\n"), i + 1, nUnitDevices);

		ci.UnitNo = i;

		ci.LoginType = NDASCOMM_LOGIN_TYPE_NORMAL;
		success = print_ndas_unitdevice_info(&ci);

		ci.LoginType = NDASCOMM_LOGIN_TYPE_DISCOVER;
		success = print_ndas_unitdevice_stat(&ci);

		_tprintf(_T("\n"));
	}

	API_CALL(NdasCommUninitialize());

	return GetLastError();
}
Ejemplo n.º 13
0
int __cdecl _tmain(int argc, TCHAR** argv)
{
	//
	// API Version Check
	//
	if (0 != check_ndas_api_version())
	{
		return 1;
	}

    BOOL success = NdasCommInitialize();

    if (!success)
    {
        _tprintf(_T("NdasCommInitialization failed\n"));
        return 1;
    }

	if (argc != 4)
	{
		return usage();
	}

	NDAS_DEVICE_ID deviceId = {0};
	if (!parse_ndas_device_id(deviceId, argv[1]))
	{
		_tprintf(_T("Device ID format is invalid.\n"));
		return usage();
	}

	int i;

	NDAS_OEM_CODE currentOemCode;
	for (i = 0; i < RTL_NUMBER_OF(OemCodeTable); ++i)
	{
		if (0 == lstrcmpi(argv[2], OemCodeTable[i].Name))
		{
			currentOemCode = OemCodeTable[i].OemCode;
			break;
		}
	}

	if (i >= RTL_NUMBER_OF(OemCodeTable))
	{
		_tprintf(_T("Current OEM Code Name is invalid.\n"));
		return usage();
	}

	NDAS_OEM_CODE newOemCode;
	for (i = 0; i < RTL_NUMBER_OF(OemCodeTable); ++i)
	{
		if (0 == lstrcmpi(argv[3], OemCodeTable[i].Name))
		{
			newOemCode = OemCodeTable[i].OemCode;
			break;
		}
	}

	if (i >= RTL_NUMBER_OF(OemCodeTable))
	{
		_tprintf(_T("New OEM Code Name is invalid.\n"));
		return usage();
	}

	NDASCOMM_CONNECTION_INFO nci = {0};
	nci.Size = sizeof(NDASCOMM_CONNECTION_INFO);
	nci.Flags = NDASCOMM_CNF_DISABLE_LOCK_CLEANUP_ON_CONNECT;
	nci.LoginType = NDASCOMM_LOGIN_TYPE_NORMAL;
	nci.UnitNo = 0;
	nci.WriteAccess = TRUE;
	nci.Protocol = NDASCOMM_TRANSPORT_LPX;
	nci.PrivilegedOEMCode = NDAS_PRIVILEGED_OEM_CODE_DEFAULT;
	nci.OEMCode = currentOemCode;
	nci.AddressType = NDASCOMM_CIT_DEVICE_ID;
	nci.Address.DeviceId = deviceId;
	nci.ReceiveTimeout = 1000; /* we do not access hard disk, so we can use the shorter timeout */

	_tprintf(_T("Connecting..."));

	HNDAS ndasCommHandle = NdasCommConnect(&nci);

	_tprintf(_T("\r              \r"));

	if (NULL == ndasCommHandle)
	{
		_tprintf(_T("NdasCommConnect failed, error=0x%X\n"), GetLastError());
		(void) NdasCommUninitialize();
		return 1;
	}

	_tprintf(_T("Connected!\n"));

	_tprintf(_T("WARNING: If the current OEM code is invalid,")
			 _T(" the current process will be stalled and")
			 _T(" it will take several minutes to stop it!\n"));

	int retcode = set_oem_code(ndasCommHandle, &newOemCode);

	if (0 == retcode)
	{
		reset_device(ndasCommHandle);
	}

	/* Disconnection may fail! */

#ifdef NDASOC_USE_DISCONNECT
	_tprintf(_T("Disconnecting (It takes a while.)..."));

	success = NdasCommDisconnect(ndasCommHandle);

	_tprintf(_T("\r                                      \r"));

	if (!success)
	{
		_tprintf(_T("Disconnect failed, error=0x%X\n"), GetLastError());
	}
	else
	{
		_tprintf(_T("Disconnected\n"));
	}
#endif

	_tprintf(_T("*** Power-cycle the NDAS device to ensure proper operation! ***\n"));

    (void) NdasCommUninitialize();

	return retcode;
}
Ejemplo n.º 14
0
int __cdecl main()
{
	DWORD dwError = 0;
	BOOL bRet;
	HNDAS hNdas;
	CHAR data[512 * 128];

	_hModule = LoadLibrary(L"ndascomm.dll");
	if (NULL == _hModule) {
		wprintf(L"Unable to load ndascomm.dll.\n");
		return 1;
	}

  NdasCommInitialize();

  NDAS_CONNECTION_INFO ci;
  ZeroMemory(&ci, sizeof(ci));
  ci.type = NDAS_CONNECTION_INFO_TYPE_MAC_ADDRESS;
  ci.UnitNo = 0;
  ci.bWriteAccess = FALSE;
  ci.protocol = IPPROTO_LPXTCP;
  ci.MacAddress[0] = 0x00;
  ci.MacAddress[1] = 0x0b;
  ci.MacAddress[2] = 0xd0;
  ci.MacAddress[3] = 0x00;
  ci.MacAddress[4] = 0xb8;
  ci.MacAddress[5] = 0xad;

  HNDAS hNDAS;
  hNDAS = NdasCommConnect(&ci);
  if(NULL == hNDAS)
  {
    printf("NULL == hNDAS %08X\n", ::GetLastError());
    return FALSE;
  }

  NdasCommDisconnect(hNDAS);
  hNDAS = NdasCommConnect(&ci);
  if(NULL == hNDAS)
  {
    printf("NULL == hNDAS %08X\n", ::GetLastError());
    return FALSE;
  }

  bRet = NdasCommBlockDeviceRead(hNDAS, 0, 128, data);

  NDAS_UNIT_DEVICE_DYN_INFO dynInfo;
  BOOL bResults;
  bResults = NdasCommGetUnitDeviceDynInfo(&ci, &dynInfo);
  if(FALSE == bResults)
  {
    printf("FALSE == bResults %08X\n", ::GetLastError());
    return FALSE;
  }

  printf("%d %d %d %d",
    dynInfo.iNRTargets,
    dynInfo.bPresent,
    dynInfo.NRRWHost,
    dynInfo.NRROHost);


//  hNdas = NdasRawConnectW(L"GNVXGA4MPQSVY6CSLJ7K", L"3CG70", 0x1F4A50731530EABB /* HASH_KEY_USER */, 214 /* IPPROTO_LPXTCP */);
//  ZeroMemory(data, 512*128);
//  data[0] = 0xff;
//  data[3] = 0xff;
//  NdasRawBlockDeviceWriteSafeBuffer(hNdas, 0, 1, data);
//  ZeroMemory(data, 512*128);
//  NdasRawBlockDeviceRead(hNdas, 0, 1, data);
//  NdasRawDisconnect(hNdas);



//	dwError = t1();
//	dwError = t12();
//	dwError = t2();
//	NdasRawConnectW proc = (NdasRawConnect)GetProcAddress(_hModule, "NdasRawConnectW");
//	if(!proc) {
//		wprintf(L"Unable to load function NdasRawConnectW.\n");
//		return 1;
//	}

//	dwError = proc(NULL, NULL, 0, 0);

	wprintf(_T("Error %d (0x%08x)\n"), GetLastError(), GetLastError());

	FreeLibrary(_hModule);
}
Ejemplo n.º 15
0
int 
CpComare(int argc, _TCHAR* argv[])
{
	HNDAS hNDAS1 = NULL;
	HNDAS hNDAS2 = NULL;	
	NDASCOMM_CONNECTION_INFO ci;
	BOOL bResults;
	PBYTE Buffer1 = NULL, Buffer2 = NULL;
	NDAS_DIB_V2 Dib;
	static const SectorPerOp = 64;
	NDAS_DEVICE_ID SrcAddr1, SrcAddr2;
	UINT64 StartAddr;
	UINT64 IoLength;
	UINT32 MisMatchCount;
	//
	//	Get arguments.
	//
	if(argc < 2) {
		_ftprintf(stderr, _T("ERROR: More parameter needed.\n"));
		return -1;
	}
	
	_ftprintf(stderr, _T("%s %s\n"), argv[0], argv[1]);
	
	// Argv[0]: SrcAddr1
	bResults = ConvertMacToNodeId(argv[0], &SrcAddr1);
	if (!bResults) {
		_ftprintf(stderr, _T("Invalid device ID.\n"));
		return -1;
	}
	SrcAddr1.VID = 1;
	
	bResults = ConvertMacToNodeId(argv[1], &SrcAddr2);
	if (!bResults) {
		_ftprintf(stderr, _T("Invalid device ID.\n"));
		return -1;
	}
	SrcAddr2.VID = 1;
	
	Buffer1 = (PBYTE)malloc(SectorPerOp * 512);
	Buffer2 = (PBYTE)malloc(SectorPerOp * 512);
	
	SetLastError(0);
	API_CALL(NdasCommInitialize());

	//
	//	Connect and login to source 1
	//

	ZeroMemory(&ci, sizeof(ci));
	ci.Size = sizeof(NDASCOMM_CONNECTION_INFO);
	ci.AddressType = NDASCOMM_CIT_DEVICE_ID; 
	ci.UnitNo = 0; /* Use first Unit Device */
	ci.WriteAccess = FALSE; /* Connect with read-write privilege */
	ci.Protocol = NDASCOMM_TRANSPORT_LPX; /* Use LPX protocol */
	ci.OEMCode.UI64Value = 0; /* Use default password */
	ci.PrivilegedOEMCode.UI64Value = 0; /* Log in as normal user */
	ci.LoginType = NDASCOMM_LOGIN_TYPE_NORMAL; /* Normal operations */

	ci.Address.DeviceId = SrcAddr1;
	
	API_CALL_JMP( hNDAS1 = NdasCommConnect(&ci), out);

	//
	//	Connect and login to source 2
	//

	ZeroMemory(&ci, sizeof(ci));
	ci.Size = sizeof(NDASCOMM_CONNECTION_INFO);
	ci.AddressType = NDASCOMM_CIT_DEVICE_ID; 
	ci.UnitNo = 0; /* Use first Unit Device */
	ci.WriteAccess = FALSE; /* Connect with read-write privilege */
	ci.Protocol = NDASCOMM_TRANSPORT_LPX; /* Use LPX protocol */
	ci.OEMCode.UI64Value = 0; /* Use default password */
	ci.PrivilegedOEMCode.UI64Value = 0; /* Log in as normal user */
	ci.LoginType = NDASCOMM_LOGIN_TYPE_NORMAL; /* Normal operations */

	ci.Address.DeviceId = SrcAddr2;
	
	API_CALL_JMP( hNDAS2 = NdasCommConnect(&ci), out);

	bResults = NdasCommBlockDeviceRead(
		hNDAS1, 
		NDAS_BLOCK_LOCATION_DIB_V2, 
		1, 
		(PBYTE)&Dib);
	if (!bResults) {
		goto out;
	}
	if (Dib.Signature != NDAS_DIB_V2_SIGNATURE) {
		_ftprintf(stdout, _T("Dib not found\n"));
		goto out;
	}
	// Compare 
	_ftprintf(stdout, _T("Comparing 0x%I64x sectors\n"), Dib.sizeUserSpace);
	StartAddr = 0;
	IoLength = SectorPerOp;
	MisMatchCount = 0;
	while(TRUE) {
		if (StartAddr + IoLength >= Dib.sizeUserSpace) {
			// Last part.
			IoLength = Dib.sizeUserSpace - StartAddr;
		} 
		bResults = NdasCommBlockDeviceRead(
			hNDAS1, 
			StartAddr, 
			IoLength, 
			Buffer1);
		if (!bResults) {
			_ftprintf(stdout, _T("Failed to read from source 1\n"));
			goto out;
		}
		bResults = NdasCommBlockDeviceRead(
			hNDAS2, 
			StartAddr, 
			IoLength, 
			Buffer2);
		if (!bResults) {
			_ftprintf(stdout, _T("Failed to read from source 2\n"));
			goto out;
		}
		if (memcmp(Buffer1, Buffer2, (size_t)IoLength * 512) == 0) {
			
		} else {
			MisMatchCount++;
			_ftprintf(stdout, _T("Mismatch at 0x%I64x:%x\n"), StartAddr, IoLength);
			if (MisMatchCount > 20) {
				_ftprintf(stdout, _T("Too much mismatch. Exiting\n"));	
				break;
			}
		}
		if (StartAddr%(100 * 1024 * 2)==0) { // Print progress in every 100M
			_ftprintf(stdout, _T("%d%%\n"), StartAddr*100/Dib.sizeUserSpace);
		}
		StartAddr += IoLength;
		if (StartAddr >= Dib.sizeUserSpace) {
			break;
		}
	}
out:
	if(GetLastError()) {
		_ftprintf(stdout, _T("Error! Code:%08lx\n"), GetLastError());
	}
	if (Buffer1)
		free(Buffer1);
	if (Buffer2)
		free(Buffer2);
	if(hNDAS1)
	{
		NdasCommDisconnect(hNDAS1);
		hNDAS1 = NULL;
	}

	if(hNDAS2)
	{
		NdasCommDisconnect(hNDAS2);
		hNDAS2 = NULL;
	}

	NdasCommUninitialize();

	return GetLastError();
}
Ejemplo n.º 16
0
int
CpQueryLockOwner(int argc, _TCHAR* argv[])
{
    HNDAS hNDAS = NULL;
    NDASCOMM_CONNECTION_INFO ci;
    BYTE DeviceID[6];
    DWORD dwUnitNo;
    NDASCOMM_VCMD_PARAM param_vcmd;
    ULONG		lockIdx;

    //
    //	Get arguments.
    //
    if(argc < 3) {
        _ftprintf(stderr, _T("ERROR: More parameter needed.\n"));
        return -1;
    }

    lockIdx = _tcstoul(argv[2], NULL, 10);
    if(lockIdx == 0) {

        //
        //	Check to see if a user inputs the zero.
        //

        if( argv[2][0] != _T('0') ||
                argv[2][1] != _T('\0')
          ) {
            _ftprintf(stderr, _T("ERROR: Invalid timeout value.\n"));
            return -1;
        }
    }



    _ftprintf(stdout, _T("Starting the operation...\n"));
    SetLastError(0);
    API_CALL(NdasCommInitialize());


    //
    //	Connect and login
    //

    ZeroMemory(&ci, sizeof(ci));
    ci.Size = sizeof(NDASCOMM_CONNECTION_INFO);
    ci.AddressType = NDASCOMM_CIT_NDAS_ID; /* Use NDAS ID */
    ci.UnitNo = 0; /* Use first Unit Device */
    ci.WriteAccess = FALSE; /* Connect with read-only privilege */
    ci.Protocol = NDASCOMM_TRANSPORT_LPX; /* Use LPX protocol */
    ci.OEMCode.UI64Value = 0; /* Use default password */
    ci.PrivilegedOEMCode.UI64Value = 0; /* Log in as normal user */
    ci.LoginType = NDASCOMM_LOGIN_TYPE_NORMAL; /* Normal operations */
    _tcsncpy(ci.Address.NdasId.Id, argv[0], 20); /* ID */
    _tcsncpy(ci.Address.NdasId.Key, argv[1], 5); /* Key */
    API_CALL_JMP( hNDAS = NdasCommConnect(&ci), out );

    //
    //	Display NDAS device info
    //

    API_CALL_JMP(NdasCommGetDeviceID(hNDAS, DeviceID, &dwUnitNo), out);
    _tprintf(L"DeviceID : %02X%02X%02X%02X%02X%02X, Unit No. : %d\n",
             DeviceID[0], DeviceID[1], DeviceID[2], DeviceID[3], DeviceID[4], DeviceID[5],
             (int)dwUnitNo);


    //
    //	Query lock owner
    //

    _ftprintf(stderr, _T("Querying lock #%u's owner of  the device...\n"), (ULONG)(UINT8)lockIdx);
    ZeroMemory(&param_vcmd, sizeof(NDASCOMM_VCMD_PARAM));
    param_vcmd.GET_OWNER_SEMA.Index = (UINT8)lockIdx;
    API_CALL_JMP(NdasCommVendorCommand(hNDAS, ndascomm_vcmd_get_owner_sema, &param_vcmd, NULL, 0, NULL, 0), out);


out:
    if(GetLastError()) {
        _ftprintf(stdout, _T("Error! Code:%08lx\n"), GetLastError());
    } else {
        _ftprintf(stdout, _T("Owner's addr:%02X%02X%02X%02X%02X%02X%02X%02X\n"),
                  param_vcmd.GET_OWNER_SEMA.AddressLPX[0],
                  param_vcmd.GET_OWNER_SEMA.AddressLPX[1],
                  param_vcmd.GET_OWNER_SEMA.AddressLPX[2],
                  param_vcmd.GET_OWNER_SEMA.AddressLPX[3],
                  param_vcmd.GET_OWNER_SEMA.AddressLPX[4],
                  param_vcmd.GET_OWNER_SEMA.AddressLPX[5],
                  param_vcmd.GET_OWNER_SEMA.AddressLPX[6],
                  param_vcmd.GET_OWNER_SEMA.AddressLPX[7]);
    }

    if(hNDAS)
    {
        NdasCommDisconnect(hNDAS);
        hNDAS = NULL;
    }

    NdasCommUninitialize();

    _ftprintf(stdout, _T("Finished the operation.\n"));

    return GetLastError();
}
Ejemplo n.º 17
0
int 
CpInfo(int argc, _TCHAR* argv[])
{
	HNDAS hNDAS = NULL;
	NDASCOMM_CONNECTION_INFO ci;
	BOOL bResults;
	NDAS_DEVICE_ID SrcAddr1;
	NDASOP_RAID_INFO RaidInfo = {0};
	PTCHAR str;
	PTCHAR EmptyStr=_T("");
	DWORD MemberCount;
	DWORD i, j;
	DWORD Flags;
	PNDAS_OOS_BITMAP_BLOCK BmpBuffer = NULL;
	
	//
	//	Get arguments.
	//
	if(argc < 1) {
		_ftprintf(stderr, _T("ERROR: More parameter needed.\n"));
		return -1;
	}
	_ftprintf(stderr, _T("RAID Info using %s as primary device \n"), argv[0]);

	// Argv[0]: SrcAddr1
	bResults = ConvertMacToNodeId(argv[0], &SrcAddr1);
	if (!bResults) {
		_ftprintf(stderr, _T("Invalid device ID.\n"));
		return -1;
	}
	SrcAddr1.VID = 1; // to do: get VID as parameter

	SetLastError(0);
	API_CALL(NdasCommInitialize());

	ZeroMemory(&ci, sizeof(ci));
	ci.Size = sizeof(NDASCOMM_CONNECTION_INFO);
	ci.AddressType = NDASCOMM_CIT_DEVICE_ID; 
	ci.UnitNo = 0; /* Use first Unit Device */
	ci.WriteAccess = FALSE; /* Connect with read-write privilege */
	ci.Protocol = NDASCOMM_TRANSPORT_LPX; /* Use LPX protocol */
	ci.OEMCode.UI64Value = 0; /* Use default password */
	ci.PrivilegedOEMCode.UI64Value = 0; /* Log in as normal user */
	ci.LoginType = NDASCOMM_LOGIN_TYPE_NORMAL; /* Normal operations */

	ci.Address.DeviceId = SrcAddr1;
	ci.Address.DeviceId.VID = 1;
	
	hNDAS = NdasCommConnect(&ci);
	if (!hNDAS) {
		_ftprintf(stdout, _T("Cannot connect\n"));
		goto out;
	}

	//
	// Get and dump RAID info
	//
	RaidInfo.Size = sizeof(RaidInfo);
 	bResults = NdasOpGetRaidInfo(hNDAS,&RaidInfo);
	switch(RaidInfo.Type) {
		case NMT_SINGLE:		str=_T("Single"); break;
		case NMT_MIRROR:		str=_T("Mirror without repair info"); break;
		case NMT_AGGREGATE:		str=_T("Aggregation"); break;
		case NMT_RAID0:			str=_T("RAID0"); break;
		case NMT_RAID1:			str=_T("RAID1R1(~3.10)"); break;
		case NMT_RAID4:			str=_T("RAID4R1(~3.10)"); break;
		case NMT_RAID1R2:		str=_T("RAID1R2(3.11~)"); break;
		case NMT_RAID4R2:		str=_T("RAID4R2(3.11~)"); break;
		case NMT_RAID1R3:		str=_T("RAID1R3(3.20~)"); break;
		case NMT_RAID4R3:		str=_T("RAID4R3(3.20~)"); break;
		case NMT_AOD:			str=_T("Append only disk"); break;
		case NMT_VDVD:			str=_T("Virtual DVD"); break;
		case NMT_CDROM:		str=_T("packet device, CD / DVD"); break;
		case NMT_OPMEM:			str=_T("packet device, Magnetic Optical"); break;
		case NMT_FLASH:			str=_T("flash card"); break;
		case NMT_CONFLICT:		str=_T("DIB is conflicting"); break;
		default: str=_T("Unknown"); break;
	}
	_ftprintf(stdout, _T("Type: %s\n"), str);
	
	_ftprintf(stdout, _T("Mountability Flags: %x(%s%s%s%s%s%s)\n"), RaidInfo.MountablityFlags, 
		(RaidInfo.MountablityFlags & NDAS_RAID_MOUNTABILITY_UNMOUNTABLE)?_T("Unmountable "):EmptyStr,
		(RaidInfo.MountablityFlags & NDAS_RAID_MOUNTABILITY_MOUNTABLE)?_T("Mountable "):EmptyStr,
		(RaidInfo.MountablityFlags & NDAS_RAID_MOUNTABILITY_NORMAL)?_T("in normal mode "):EmptyStr,
		(RaidInfo.MountablityFlags & NDAS_RAID_MOUNTABILITY_DEGRADED)?_T("in degraded mode "):EmptyStr,
		(RaidInfo.MountablityFlags & NDAS_RAID_MOUNTABILITY_MISSING_SPARE)?_T("with missing spare"):EmptyStr,
		(RaidInfo.MountablityFlags & NDAS_RAID_MOUNTABILITY_SPARE_EXIST)?_T("with spare"):EmptyStr
	);

	_ftprintf(stdout, _T("Fail reason: %x(%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s)\n"), RaidInfo.FailReason, 
		(RaidInfo.FailReason == NDAS_RAID_FAIL_REASON_NONE)?_T("None"):EmptyStr,
		(RaidInfo.FailReason & NDAS_RAID_FAIL_REASON_RMD_CORRUPTED)?_T("RMD corrupted "):EmptyStr,
		(RaidInfo.FailReason & NDAS_RAID_FAIL_REASON_MEMBER_OFFLINE)?_T("Offline "):EmptyStr,
		(RaidInfo.FailReason & NDAS_RAID_FAIL_REASON_DIB_MISMATCH)?_T("DIB mismatch "):EmptyStr,
		(RaidInfo.FailReason & NDAS_RAID_FAIL_REASON_SPARE_USED)?_T("Spare used "):EmptyStr,
		(RaidInfo.FailReason & NDAS_RAID_FAIL_REASON_INCONSISTENT_DIB)?_T("Inconsistent DIB "):EmptyStr,
		(RaidInfo.FailReason & NDAS_RAID_FAIL_REASON_UNSUPPORTED_DIB_VERSION)?_T("Unsupported DIB version "):EmptyStr,
		(RaidInfo.FailReason & NDAS_RAID_FAIL_REASON_MIGRATION_REQUIRED)?_T("Migration required"):EmptyStr,
		(RaidInfo.FailReason & NDAS_RAID_FAIL_REASON_UNSUPPORTED_RAID)?_T("Unsupported RAID type"):EmptyStr,
		(RaidInfo.FailReason & NDAS_RAID_FAIL_REASON_DEFECTIVE)?_T("Defective disk "):EmptyStr,
		(RaidInfo.FailReason & NDAS_RAID_FAIL_REASON_DIFFERENT_RAID_SET)?_T("RAID set ID mismatch "):EmptyStr,
		(RaidInfo.FailReason & NDAS_RAID_FAIL_REASON_MEMBER_NOT_REGISTERED)?_T("Unregistered "):EmptyStr,		
		(RaidInfo.FailReason & NDAS_RAID_FAIL_REASON_MEMBER_IO_FAIL)?_T("IO failure "):EmptyStr,
		(RaidInfo.FailReason & NDAS_RAID_FAIL_REASON_NOT_A_RAID)?_T("Not a RAID "):EmptyStr,
		(RaidInfo.FailReason & NDAS_RAID_FAIL_REASON_IRRECONCILABLE)?_T("Irreconcilable "):EmptyStr,
		(RaidInfo.FailReason & NDAS_RAID_FAIL_REASON_MEMBER_DISABLED)?_T("Disabled member "):EmptyStr
	);

	MemberCount = RaidInfo.MemberCount;
	
	_ftprintf(stdout, _T("RAID Set ID  = %08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x\n"),
		RaidInfo.RaidSetId.Data1, RaidInfo.RaidSetId.Data2, RaidInfo.RaidSetId.Data3,
		RaidInfo.RaidSetId.Data4[0], RaidInfo.RaidSetId.Data4[1], RaidInfo.RaidSetId.Data4[2], RaidInfo.RaidSetId.Data4[3], 
		RaidInfo.RaidSetId.Data4[4], RaidInfo.RaidSetId.Data4[5], RaidInfo.RaidSetId.Data4[6], RaidInfo.RaidSetId.Data4[7]
	);
	_ftprintf(stdout, _T("Config Set ID= %08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x\n"),
		RaidInfo.ConfigSetId.Data1, RaidInfo.ConfigSetId.Data2, RaidInfo.ConfigSetId.Data3,
		RaidInfo.ConfigSetId.Data4[0], RaidInfo.ConfigSetId.Data4[1], RaidInfo.ConfigSetId.Data4[2], RaidInfo.ConfigSetId.Data4[3], 
		RaidInfo.ConfigSetId.Data4[4], RaidInfo.ConfigSetId.Data4[5], RaidInfo.ConfigSetId.Data4[6], RaidInfo.ConfigSetId.Data4[7]
	);

	for(i=0;i<MemberCount;i++) {
		_ftprintf(stdout, _T(" * Member %d - DeviceId %02x:%02x:%02x:%02x:%02x:%02x-%02x Unit %d\n"),
			i, 
			RaidInfo.Members[i].DeviceId.Node[0], RaidInfo.Members[i].DeviceId.Node[1], RaidInfo.Members[i].DeviceId.Node[2], 
			RaidInfo.Members[i].DeviceId.Node[3], RaidInfo.Members[i].DeviceId.Node[4], RaidInfo.Members[i].DeviceId.Node[5], 
			RaidInfo.Members[i].DeviceId.VID, RaidInfo.Members[i].UnitNo
		);
		Flags = RaidInfo.Members[i].Flags;
		_ftprintf(stdout, _T("                Flags: %x(%s%s%s%s%s%s%s%s%s%s%s%s%s)\n"),
			Flags,
			(Flags & NDAS_RAID_MEMBER_FLAG_ACTIVE)?_T("Active member "):EmptyStr,
			(Flags & NDAS_RAID_MEMBER_FLAG_SPARE)?_T("Spare "):EmptyStr,
			(Flags & NDAS_RAID_MEMBER_FLAG_ONLINE)?_T("Online "):EmptyStr,
			(Flags & NDAS_RAID_MEMBER_FLAG_OFFLINE)?_T("Offline "):EmptyStr,
			(Flags & NDAS_RAID_MEMBER_FLAG_DIFFERENT_RAID_SET)?_T("Different RAID Set ID "):EmptyStr,
			(Flags & NDAS_RAID_MEMBER_FLAG_IO_FAILURE)?_T("IO failure "):EmptyStr,
			(Flags & NDAS_RAID_MEMBER_FLAG_RMD_CORRUPTED)?_T("RMD corrupted "):EmptyStr,
			(Flags & NDAS_RAID_MEMBER_FLAG_DIB_MISMATCH)?_T("DIB mismatch "):EmptyStr,
			(Flags & NDAS_RAID_MEMBER_FLAG_OUT_OF_SYNC)?_T("Out-of-sync "):EmptyStr,
			(Flags & NDAS_RAID_MEMBER_FLAG_BAD_SECTOR)?_T("Bad sector "):EmptyStr,
			(Flags & NDAS_RAID_MEMBER_FLAG_BAD_DISK)?_T("Bad disk "):EmptyStr,			
			(Flags & NDAS_RAID_MEMBER_FLAG_REPLACED_BY_SPARE)?_T("Replaced by spare "):EmptyStr,
			(Flags & NDAS_RAID_MEMBER_FLAG_IRRECONCILABLE)?_T("Irreconcilable "):EmptyStr,
			(Flags & NDAS_RAID_MEMBER_FLAG_NOT_REGISTERED)?_T("Unregistered "):EmptyStr
		);
	}

	// Dump Bitmap info.
	if (RaidInfo.Type == NMT_RAID1R3) {
		NDAS_DIB_V2 DIB_V2;
		UINT32 OnBitCount;
		UINT32 BitCount;
		UINT32 BmpSectorCount;
		UINT32 CurBitCount;
		UCHAR OnBits[] = {1<<0, 1<<1, 1<<2, 1<<3, 1<<4, 1<<5, 1<<6, 1<<7};
		UINT32 BitOn, BitOnStart, BitOnEnd;
		
		bResults = NdasCommBlockDeviceRead(
			hNDAS, 
			NDAS_BLOCK_LOCATION_DIB_V2, 
			1, 
			(PBYTE)&DIB_V2);
		if (!bResults) {
			goto out;
		}
		BitCount = (UINT32)((DIB_V2.sizeUserSpace + DIB_V2.iSectorsPerBit - 1)/DIB_V2.iSectorsPerBit);
		BmpSectorCount = (BitCount + NDAS_BIT_PER_OOS_BITMAP_BLOCK -1)/NDAS_BIT_PER_OOS_BITMAP_BLOCK;
		OnBitCount = 0;
		_ftprintf(stdout, _T("Bitmap sector per bit=0x%x, Bit count =0x%x, BmpSector count=0x%x\n"), 
			DIB_V2.iSectorsPerBit, BitCount, BmpSectorCount);
		BmpBuffer = (PNDAS_OOS_BITMAP_BLOCK) malloc(BmpSectorCount* 512);

		bResults =NdasCommBlockDeviceRead(hNDAS, NDAS_BLOCK_LOCATION_BITMAP, BmpSectorCount, (PBYTE)BmpBuffer);
		if (!bResults) {
			_ftprintf(stdout, _T("Failed to read BMP.\n"));
			goto out;
		}
		CurBitCount = 0;
		for(i=0;i<BmpSectorCount;i++) {
			_ftprintf(stdout, _T("  Bitmap sector %d, Seq head=%I64x, tail=%I64x\n"), i, BmpBuffer[i].SequenceNumHead,BmpBuffer[i].SequenceNumTail);
			BitOn = FALSE;
			BitOnStart = BitOnEnd = 0;
			for(j=0;j<NDAS_BYTE_PER_OOS_BITMAP_BLOCK * 8;j++) {
				if (BitOn == FALSE && (BmpBuffer[i].Bits[j/8] & OnBits[j%8])) {
					BitOn = TRUE;
					BitOnStart = i * NDAS_BYTE_PER_OOS_BITMAP_BLOCK * 8 + j;
					_ftprintf(stdout, _T("    Bit on from bit %x ~ "), BitOnStart);
				}
				if (BitOn == TRUE && (BmpBuffer[i].Bits[j/8] & OnBits[j%8]) == 0) {
					BitOn = FALSE;
					BitOnEnd = i * NDAS_BYTE_PER_OOS_BITMAP_BLOCK * 8 + j;
					_ftprintf(stdout, _T("%x\n"), BitOnEnd-1);
				}
				if (BmpBuffer[i].Bits[j/8] & OnBits[j%8]) 
					OnBitCount++;
				CurBitCount++;
				if (CurBitCount >= BitCount)
					break;
			}
			if (BitOn == TRUE) {
				_ftprintf(stdout, _T("%x\n"), i * NDAS_BYTE_PER_OOS_BITMAP_BLOCK * 8 + j);
			}
		}
		_ftprintf(stdout, _T("%d bit is on out of %d bits. %.1lf%% out-of-sync.\n"), OnBitCount, BitCount, ((double)OnBitCount)/BitCount*100);
	}
out:
	if(GetLastError()) {
		_ftprintf(stdout, _T("Error! Code:%08lx\n"), GetLastError());
	}
	if(hNDAS)
	{
		NdasCommDisconnect(hNDAS);
		hNDAS = NULL;
	}
	if (BmpBuffer)
	{
		free(BmpBuffer);
	}
	NdasCommUninitialize();

	return GetLastError();


}
Ejemplo n.º 18
0
/*
main function
returns non-zero if any function fails.
*/
int __cdecl main(int argc, char *argv[])
{
	DWORD dwError = 0;
	BOOL bResult;
	HNDAS hNdas;
	BYTE data[512]; // 1 sector sized buffer

	// simple check parameter
	if(2 != argc)
	{
		printf(
			"usage : apitest.exe ID-KEY\n"
			"\n"
			"ID-KEY : 20 chars of id and 5 chars of key of the NDAS Device ex(01234ABCDE56789FGHIJ13579)\n"
			"ex : apitest.exe 01234ABCDE56789FGHIJ13579\n"
			);
		printf("\n");
		return -1;
	}

	printf("\n\n\n* Start NDASComm API test on the NDAS Device : %s\n", argv[1]);

	printf("* Initialize NdasComm library : NdasCommInitialize()\n");
	API_CALL(NdasCommInitialize());

	DWORD dwVersion;
	printf("* Get API Version : NdasCommGetAPIVersion()\n");
	API_CALL(dwVersion = NdasCommGetAPIVersion());
	printf("- Version : Major %d, Minor %d\n",
		(int)LOWORD(dwVersion), (int)HIWORD(dwVersion));

	printf("* Initialize connection info to create connection to the NDAS Device\n");
	NDASCOMM_CONNECTION_INFO ci;
	ZeroMemory(&ci, sizeof(ci));
	ci.address_type = NDASCOMM_CONNECTION_INFO_TYPE_ID_A; // ASCII char set
	ci.UnitNo = 0; // Use first Unit Device
	ci.bWriteAccess = TRUE; // Connect with read-write privilege
	ci.protocol = NDASCOMM_TRANSPORT_LPX; // Use LPX protocol
	ci.ui64OEMCode = 0; // Use default password
	ci.bSupervisor = FALSE; // Log in as normal user
	ci.login_type = NDASCOMM_LOGIN_TYPE_NORMAL; // Normal operations
	strncpy(ci.DeviceIDA.szDeviceStringId, argv[1], 20); // ID
	strncpy(ci.DeviceIDA.szDeviceStringKey, argv[1] +20, 5); // Key

	HNDAS hNDAS;
	printf("* Connect to the NDAS Device : NdasCommConnect()\n");
	API_CALL(
		hNDAS = NdasCommConnect(
			&ci,
			0 /* synchronous mode */,
			NULL /* no connection hint */
			)
		);

	BYTE DeviceID[6];
	DWORD UnitNo;
	printf("* Retrieve NDAS Device ID & unit number : NdasCommGetDeviceID()\n");
	API_CALL(NdasCommGetDeviceID(hNDAS, DeviceID, &UnitNo));
	printf("- DeviceID : %02X%02X%02X%02X%02X%02X, Unit No. : %d\n",
		DeviceID[0], DeviceID[1], DeviceID[2], DeviceID[3], DeviceID[4], DeviceID[5],
		(int)UnitNo);

	PBYTE Buffer;
	DWORD BufferLen;
	printf("* Retrieve the address of the host attached to the NDAS Device : NdasCommGetHostAddress()\n");
	API_CALL(NdasCommGetHostAddress(hNDAS, NULL, &BufferLen));
	printf("- buffer length : %d\n", BufferLen);
	Buffer = new BYTE[BufferLen];
	API_CALL(NdasCommGetHostAddress(hNDAS, Buffer, &BufferLen));
	printf("- Host Address : ");
	for(DWORD i = 0 ; i < BufferLen; i++)
	{
		printf("%02X", (UINT)Buffer[i]);
	}
	printf("\n");
	delete [] Buffer;

	INT64 i64Location;
	UINT ui64SectorCount;

	ui64SectorCount = 1;
	i64Location = 0;

	printf("* Read %d sector(s) of data from Address %d : NdasCommBlockDeviceRead()\n",
		ui64SectorCount, i64Location);
	API_CALL(NdasCommBlockDeviceRead(hNDAS, i64Location, ui64SectorCount, data));

	i64Location = 1;
	printf("* Write %d sector(s) of data to Address %d : NdasCommBlockDeviceWriteSafeBuffer()\n",
		ui64SectorCount, i64Location);
	API_CALL(NdasCommBlockDeviceWriteSafeBuffer(hNDAS, i64Location, ui64SectorCount, data));

	ui64SectorCount = 2;
	i64Location = 2;
	printf("* Verify %d sector(s) from Address %d : NdasCommBlockDeviceVerify()\n",
		ui64SectorCount, i64Location);
	API_CALL(NdasCommBlockDeviceVerify(hNDAS, i64Location, ui64SectorCount));

	NDASCOMM_IDE_REGISTER IdeRegister;
	IdeRegister.command.command = 0xEC; // WIN_IDENTIFY
	printf("* Identify the NDAS Unit Device : NdasCommIdeCommand()\n");
	API_CALL(NdasCommIdeCommand(hNDAS, &IdeRegister, NULL, 0, data, 512));
	// data[] now has 512 bytes of identified data as per ANSI NCITS ATA6 rev.1b spec

	BYTE pbData[8];
	const DWORD cbData = sizeof(pbData);


	API_CALL(NdasCommGetDeviceInfo(hNDAS,ndascomm_handle_info_hw_version, pbData, cbData));
	printf("Hardware Version : %d\n", *(BYTE*)pbData);

	NDASCOMM_VCMD_PARAM param_vcmd;
	printf("* get standby timer : NdasCommVendorCommand()\n");
	bResult = NdasCommVendorCommand(hNDAS, ndascomm_vcmd_get_ret_time, &param_vcmd, NULL, 0, NULL, 0);
	if(!bResult)
	{
		if(NDASCOMM_ERROR_HARDWARE_UNSUPPORTED != ::GetLastError())
		{
			API_CALL(FALSE && "NdasCommVendorCommand");
		}
		printf("- Not supported for this Hardware version\n");
	}
	else
	{
		UINT32 TimeValue = param_vcmd.GET_STANDBY_TIMER.TimeValue;
		BOOL EnableTimer = param_vcmd.GET_STANDBY_TIMER.EnableTimer;
		printf("- standby timer : %d, enable : %d\n", TimeValue, EnableTimer);

		param_vcmd.SET_STANDBY_TIMER.TimeValue = TimeValue;
		param_vcmd.SET_STANDBY_TIMER.EnableTimer = EnableTimer ? 0 : 1;
		printf("* set standby timer : NdasCommVendorCommand()\n");
		API_CALL(NdasCommVendorCommand(hNDAS, ndascomm_vcmd_set_ret_time, &param_vcmd, NULL, 0, NULL, 0));

		TimeValue = param_vcmd.SET_STANDBY_TIMER.TimeValue;
		EnableTimer = param_vcmd.SET_STANDBY_TIMER.EnableTimer;
		printf("- standby timer : %d, enable : %d\n", TimeValue, EnableTimer);
	}

	printf("* Disconnect the connection from the NDAS Device : NdasCommDisconnect()\n");
	API_CALL(NdasCommDisconnect(hNDAS));

	printf("* Uninitialize NDASComm API : NdasCommUninitialize()\n");
	API_CALL(NdasCommUninitialize());

	return 0;
}