示例#1
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();
}
示例#2
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();
}
示例#3
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();
}
示例#4
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();
}
示例#5
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();
}
示例#6
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();
}
示例#7
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();
}
示例#8
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();
}
示例#9
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;
}