BOOL print_ndas_device_info( const NDASCOMM_CONNECTION_INFO* pci) { BOOL success = FALSE; HNDAS hNdas = NULL; NDAS_DEVICE_HARDWARE_INFO di; API_CALL_JMP(fail, hNdas = NdasCommConnect(pci)); /* NDAS device information */ ZeroMemory(&di, sizeof(NDAS_DEVICE_HARDWARE_INFO)); di.Size = sizeof(NDAS_DEVICE_HARDWARE_INFO); API_CALL_JMP(fail, NdasCommGetDeviceHardwareInfo(hNdas, &di) ); _tprintf(_T(" Hardware type : %d\n"), di.HardwareType); _tprintf(_T(" Hardware version : %d\n"), di.HardwareVersion); _tprintf(_T(" Hardware protocol type : %d\n"), di.ProtocolType); _tprintf(_T(" Hardware protocol version : %d\n"), di.ProtocolVersion); _tprintf(_T(" Number of command processing slots : %d\n"), di.NumberOfCommandProcessingSlots); _tprintf(_T(" Maximum transfer blocks : %d\n"), di.MaximumTransferBlocks); _tprintf(_T(" Maximum targets : %d\n"), di.MaximumNumberOfTargets); _tprintf(_T(" Maximum LUs : %d\n"), di.MaximumNumberOfLUs); _tprintf(_T(" Header encryption : %s\n"), bool_string(di.HeaderEncryptionMode)); _tprintf(_T(" Header digest : %s\n"), bool_string(di.HeaderDigestMode)); _tprintf(_T(" Data encryption : %s\n"), bool_string(di.DataEncryptionMode)); _tprintf(_T(" Data Digest : %s\n"), bool_string(di.DataDigestMode)); _tprintf(_T("\n")); success = TRUE; fail: if (NULL != hNdas) { API_CALL(NdasCommDisconnect(hNdas)); } return success; }
BOOL print_ndas_unitdevice_stat( const NDASCOMM_CONNECTION_INFO* pci) { BOOL success = FALSE; int i; NDAS_UNITDEVICE_STAT ustat; /* NdasCommGetUnitDeviceStat requires DISCOVER login type */ _ASSERTE(NDASCOMM_LOGIN_TYPE_DISCOVER == pci->LoginType); ZeroMemory(&ustat, sizeof(NDAS_UNITDEVICE_STAT)); ustat.Size = sizeof(NDAS_UNITDEVICE_STAT); API_CALL_JMP(fail, NdasCommGetUnitDeviceStat(pci, &ustat)); _tprintf(_T(" Present: %s\n"), bool_string(ustat.IsPresent)); if (NDAS_HOST_COUNT_UNKNOWN == ustat.RoHostCount) { _tprintf(_T(" NDAS hosts with RO access: N/A\n")); } else { _tprintf(_T(" NDAS hosts with RO access: %d\n"), ustat.RoHostCount); } if (NDAS_HOST_COUNT_UNKNOWN == ustat.RwHostCount) { _tprintf(_T(" NDAS hosts with RW access: N/A\n")); } else { _tprintf(_T(" NDAS hosts with RW access: %d\n"), ustat.RwHostCount); } _tprintf(_T(" Target data : ")); for (i = 0; i < 8; i++) { _tprintf(_T("%02X "), ustat.TargetData[i]); } _tprintf(_T("\n")); success = TRUE; fail: return success; }
UINT get_ndas_unit_device_count( const NDASCOMM_CONNECTION_INFO* pci) { NDAS_DEVICE_STAT dstat; /* NdasCommGetUnitDeviceStat requires DISCOVER login type */ _ASSERTE(NDASCOMM_LOGIN_TYPE_DISCOVER == pci->LoginType); ZeroMemory(&dstat, sizeof(NDAS_DEVICE_STAT)); dstat.Size = sizeof(NDAS_DEVICE_STAT); API_CALL_JMP(fail, NdasCommGetDeviceStat(pci, &dstat)); return dstat.NumberOfUnitDevices; fail: return (UINT)(-1); }
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(); }
/* 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, ¶m_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, ¶m_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, ¶m_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, ¶m_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, ¶m_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(); }
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(¶m_vcmd, sizeof(NDASCOMM_VCMD_PARAM)); param_vcmd.SET_RET_TIME.RetTime = retTime; API_CALL_JMP(NdasCommVendorCommand(hNDAS, ndascomm_vcmd_set_ret_time, ¶m_vcmd, NULL, 0, NULL, 0), out); _ftprintf(stderr, _T("Resetting the device...\n")); ZeroMemory(¶m_vcmd, sizeof(NDASCOMM_VCMD_PARAM)); API_CALL_JMP(NdasCommVendorCommand(hNDAS, ndascomm_vcmd_reset, ¶m_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(); }
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(¶m_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, ¶m_vcmd, NULL, 0, NULL, 0), out); _ftprintf(stderr, _T("Resetting the device...\n")); ZeroMemory(¶m_vcmd, sizeof(NDASCOMM_VCMD_PARAM)); API_CALL_JMP(NdasCommVendorCommand(hNDAS, ndascomm_vcmd_reset, ¶m_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(); }
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(¶m_vcmd, sizeof(NDASCOMM_VCMD_PARAM)); API_CALL_JMP(NdasCommVendorCommand(hNDAS, ndascomm_vcmd_get_max_conn_time, ¶m_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(); }
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(¶m_vcmd, sizeof(NDASCOMM_VCMD_PARAM)); param_vcmd.GET_OWNER_SEMA.Index = (UINT8)lockIdx; API_CALL_JMP(NdasCommVendorCommand(hNDAS, ndascomm_vcmd_get_owner_sema, ¶m_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(); }
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(); }
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(); }
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(¶m_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, ¶m_vcmd, NULL, 0, NULL, 0), out); _ftprintf(stderr, _T("Resetting the device...\n")); ZeroMemory(¶m_vcmd, sizeof(NDASCOMM_VCMD_PARAM)); API_CALL_JMP(NdasCommVendorCommand(hNDAS, ndascomm_vcmd_reset, ¶m_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(); }
BOOL print_ndas_unitdevice_info( const NDASCOMM_CONNECTION_INFO* pci) { BOOL success; int i; HNDAS hNdas = NULL; NDAS_UNITDEVICE_HARDWARE_INFO uinfo; NDASCOMM_IDE_REGISTER idereg; struct hd_driveid ideInfo; UINT64 sectors; TCHAR szBuffer[100]; const DWORD cchBuffer = sizeof(szBuffer) / sizeof(szBuffer[0]); /* NdasCommGetUnitDeviceStat requires NORMAL login type */ _ASSERTE(NDASCOMM_LOGIN_TYPE_NORMAL == pci->LoginType); API_CALL_JMP(fail, hNdas = NdasCommConnect(pci)); /* Unit Device Information */ ZeroMemory(&uinfo, sizeof(NDAS_UNITDEVICE_HARDWARE_INFO)); uinfo.Size = sizeof(NDAS_UNITDEVICE_HARDWARE_INFO); API_CALL_JMP(fail, NdasCommGetUnitDeviceHardwareInfo(hNdas, &uinfo)); sectors = _tprintf(_T(" Sector count : %I64d\n"), uinfo.SectorCount.QuadPart); _tprintf(_T(" Supports LBA : %s\n"), bool_string(uinfo.LBA)); _tprintf(_T(" Supports LBA48 : %s\n"), bool_string(uinfo.LBA48)); _tprintf(_T(" Supports PIO : %s\n"), bool_string(uinfo.PIO)); _tprintf(_T(" Supports DMA : %s\n"), bool_string(uinfo.DMA)); _tprintf(_T(" Supports UDMA : %s\n"), bool_string(uinfo.UDMA)); _tprintf(_T(" Model : %s\n"), uinfo.Model); _tprintf(_T(" Firmware Rev : %s\n"), uinfo.FirmwareRevision); _tprintf(_T(" Serial number : %s\n"), uinfo.SerialNumber); _tprintf(_T(" Media type : %s\n"), media_type_string(uinfo.MediaType)); _tprintf(_T("\n")); /* Additional IDE information using WIN_IDENTIFY command */ idereg.device.lba_head_nr = 0; idereg.device.dev = (0 == pci->UnitNo) ? 0 : 1; idereg.device.lba = 0; idereg.command.command = WIN_IDENTIFY; API_CALL_JMP(fail, NdasCommIdeCommand(hNdas, &idereg, NULL, 0, (PBYTE)&ideInfo, sizeof(ideInfo))); _tprintf(_T(" FLUSH CACHE : Supports - %s, Enabled - %s\n"), bool_string(ideInfo.command_set_2 & 0x1000), bool_string(ideInfo.cfs_enable_2 & 0x1000)); _tprintf(_T(" FLUSH CACHE EXT : Supports - %s, Enabled - %s\n"), bool_string(ideInfo.command_set_2 & 0x2000), bool_string(ideInfo.cfs_enable_2 & 0x2000)); /* Check Ultra DMA mode */ for (i = 7; i >= 0; i--) { if (ideInfo.dma_ultra & (0x01 << i)) { _tprintf(_T(" Ultra DMA mode: supports up to UDMA mode %d\n"), i); break; } } for (i = 7; i >= 0; i--) { if (ideInfo.dma_ultra & (0x01 << (i + 8))) { _tprintf(_T(" Current Ultra DMA mode: %d\n"), i); break; } } if (i < 0) { _tprintf(_T(" Ultra DMA mode is not selected\n")); } /* Check DMA mode */ for (i = 2; i >= 0; i--) { if (ideInfo.dma_mword & (0x01 << i)) { _tprintf(_T(" DMA mode: supports up to DMA mode %d\n"), i); break; } } for (i = 2; i >= 0; i--) { if (ideInfo.dma_mword & (0x01 << (i + 8))) { _tprintf(_T(" DMA mode %d selected\n"), i); break; } } if (i < 0) { _tprintf(_T(" DMA mode is not selected\n")); } _tprintf(_T("\n")); success = TRUE; fail: if (hNdas) { API_CALL(NdasCommDisconnect(hNdas)); } return success; }