LSBUSCTLAPI BOOL WINAPI LsBusCtlQueryNodeAlive( DWORD SlotNo, LPBOOL pbAlive, LPBOOL pbAdapterHasError) { BOOL fSuccess = FALSE; HANDLE hDevice = INVALID_HANDLE_VALUE; DWORD cbReturned = 0; DWORD err; BUSENUM_NODE_ALIVE_IN nodeAliveIn; BUSENUM_NODE_ALIVE_OUT nodeAliveOut; hDevice = OpenBusInterface(); if (INVALID_HANDLE_VALUE == hDevice) { return FALSE; } nodeAliveIn.SlotNo = SlotNo; fSuccess = DeviceIoControl( hDevice, IOCTL_BUSENUM_QUERY_NODE_ALIVE, &nodeAliveIn, sizeof(BUSENUM_NODE_ALIVE_IN), &nodeAliveOut, sizeof(BUSENUM_NODE_ALIVE_OUT), &cbReturned, NULL); if (!fSuccess) { DebugPrintErrEx(_T("LsBusCtlQueryNodeAlive: BUSENUM_QUERY_NODE_ALIVE failed: ")); } else { *pbAlive = nodeAliveOut.bAlive; *pbAdapterHasError = nodeAliveOut.bHasError; } err = GetLastError(); CloseHandle(hDevice); SetLastError(err); return fSuccess; }
NDASBUSCTLAPI BOOL WINAPI NdasBusCtlQueryDvdStatus( DWORD SlotNo, PULONG pDvdStatus) { BOOL fSuccess = FALSE; HANDLE hDevice = INVALID_HANDLE_VALUE; DWORD cbReturned = 0; DWORD err; NDASBUS_DVD_STATUS DvdStatusIn; NDASBUS_DVD_STATUS DvdStatusOut; hDevice = OpenBusInterface(); if (INVALID_HANDLE_VALUE == hDevice) { return FALSE; } DvdStatusIn.SlotNo = SlotNo; DvdStatusIn.Size = sizeof(NDASBUS_DVD_STATUS); fSuccess = DeviceIoControl( hDevice, IOCTL_NDASBUS_DVD_GET_STATUS, &DvdStatusIn, sizeof(NDASBUS_DVD_STATUS), &DvdStatusOut, sizeof(NDASBUS_DVD_STATUS), &cbReturned, NULL); if (!fSuccess) { DebugPrintErrEx(_T("NdasBusCtlQueryDvdStatus: BUSENUM_QUERY_NODE_ALIVE failed: ")); } else { DebugPrint(3, _T("NdasBusCtlQueryDvdStatus: Slot %d, Status %d\n"), SlotNo, DvdStatusOut.Status); *pDvdStatus = DvdStatusOut.Status; } err = GetLastError(); CloseHandle(hDevice); SetLastError(err); return fSuccess; }
NDASBUSCTLAPI BOOL WINAPI NdasBusCtlUnplug( ULONG SlotNo) { BOOL fSuccess = FALSE; HANDLE hDevice = INVALID_HANDLE_VALUE; DWORD cbReturned = 0; DWORD err; NDASBUS_UNPLUG_HARDWARE unplug; DebugPrint(3, _T("NdasBusCtlUnplug at slot %d.\n"), SlotNo); hDevice = OpenBusInterface(); if(INVALID_HANDLE_VALUE == hDevice) { return FALSE; } ZeroMemory(&unplug, sizeof(NDASBUS_UNPLUG_HARDWARE)); unplug.SerialNo = SlotNo; unplug.Size = sizeof (unplug); fSuccess = DeviceIoControl ( hDevice, IOCTL_NDASBUS_UNPLUG_HARDWARE, &unplug, sizeof (unplug), &unplug, sizeof (unplug), &cbReturned, NULL); if (!fSuccess) { DebugPrintErrEx(_T("NdasBusCtlUnplug at slot %d failed :"), SlotNo); } else { DebugPrint(3, _T("NdasBusCtlUnplug at slot %d completed successfully.\n"), SlotNo); } err = GetLastError(); CloseHandle(hDevice); SetLastError(err); return fSuccess; }
NDASBUSCTLAPI BOOL WINAPI NdasBusCtlRemoveTarget(DWORD SlotNo) { BOOL fSuccess = FALSE; HANDLE hDevice = INVALID_HANDLE_VALUE; DWORD cbReturned = 0; DWORD err; NDASBUS_REMOVE_TARGET_DATA RemoveTargetData; DebugPrint(3, _T("NdasBusCtlRemoveTarget: Slot %d\n"), SlotNo); hDevice = OpenBusInterface(); if(INVALID_HANDLE_VALUE == hDevice) { return FALSE; } ZeroMemory(&RemoveTargetData, sizeof(RemoveTargetData)); RemoveTargetData.ulSlotNo = SlotNo; // RemoveTargetData->MasterUnitDisk; fSuccess = DeviceIoControl( hDevice, IOCTL_NDASBUS_REMOVE_TARGET, &RemoveTargetData, sizeof(NDASBUS_REMOVE_TARGET_DATA), &RemoveTargetData, sizeof(NDASBUS_REMOVE_TARGET_DATA), &cbReturned, NULL); if (!fSuccess) { DebugPrintErrEx(_T("LanscsiRemoveTarget at slot %d failed: "), SlotNo); } else { DebugPrint(3, _T("LanscsiRemoveTarget at slot %d completed successfully.\n"), SlotNo); } err = GetLastError(); CloseHandle(hDevice); SetLastError(err); return fSuccess; }
LSBUSCTLAPI BOOL WINAPI LsBusCtlEject( ULONG SlotNo) { BOOL fSuccess = FALSE; HANDLE hDevice = INVALID_HANDLE_VALUE; DWORD cbReturned = 0; DWORD err; BUSENUM_EJECT_HARDWARE eject; DebugPrint(3, _T("LsBusCtlEject at slot %d.\n"), SlotNo); hDevice = OpenBusInterface(); if(INVALID_HANDLE_VALUE == hDevice) { return FALSE; } ZeroMemory(&eject, sizeof(BUSENUM_EJECT_HARDWARE)); eject.SlotNo = SlotNo; eject.Size = sizeof (eject); fSuccess = DeviceIoControl ( hDevice, IOCTL_BUSENUM_EJECT_HARDWARE, &eject, sizeof (eject), &eject, sizeof (eject), &cbReturned, NULL); if (!fSuccess) { DebugPrintErrEx(_T("LsBusCtlEject at slot %d failed :"), SlotNo); } else { DebugPrint(3, _T("LsBusCtlEject at slot %d completed successfully.\n"), SlotNo); } err = GetLastError(); CloseHandle(hDevice); SetLastError(err); return fSuccess; }
NDASBUSCTLAPI BOOL WINAPI NdasBusCtlUnregisterDevice( ULONG SlotNo) { BOOL fSuccess = FALSE; HANDLE hDevice = INVALID_HANDLE_VALUE; DWORD cbReturned = 0; DWORD err; NDASBUS_UNREGISTER_NDASDEV unregisterDev; DebugPrint(3, _T("NdasBusCtlUnplug at slot %d.\n"), SlotNo); hDevice = OpenBusInterface(); if(INVALID_HANDLE_VALUE == hDevice) { return FALSE; } ZeroMemory(&unregisterDev, sizeof(NDASBUS_UNREGISTER_NDASDEV)); unregisterDev.SlotNo = SlotNo; fSuccess = DeviceIoControl ( hDevice, IOCTL_NDASBUS_UNREGISTER_DEVICE, &unregisterDev, sizeof (unregisterDev), &unregisterDev, sizeof (unregisterDev), &cbReturned, NULL); if (!fSuccess) { DebugPrintErrEx(_T("NdasBusCtlUnregisterDevice at slot %d failed :"), SlotNo); } else { DebugPrint(3, _T("NdasBusCtlUnregisterDevice at slot %d completed successfully.\n"), SlotNo); } err = GetLastError(); CloseHandle(hDevice); SetLastError(err); return fSuccess; }
NDASBUSCTLAPI BOOL WINAPI NdasBusCtlStartStopRegistrarEnum( BOOL bOnOff, LPBOOL pbPrevState) { BOOL fSuccess = FALSE; HANDLE hDevice = INVALID_HANDLE_VALUE; DWORD cbReturned = 0; DWORD err; DWORD onOff; hDevice = OpenBusInterface(); if (INVALID_HANDLE_VALUE == hDevice) { return FALSE; } onOff = bOnOff; fSuccess = DeviceIoControl( hDevice, IOCTL_NDASBUS_STARTSTOP_REGISTRARENUM, &onOff, sizeof(DWORD), &onOff, sizeof(DWORD), &cbReturned, NULL); if (!fSuccess) { DebugPrintErrEx(_T("LsBusCtlOnOffRegistrar: STOP_REGISTRAR failed: ")); } else { if(pbPrevState) *pbPrevState = (onOff != 0); } err = GetLastError(); CloseHandle(hDevice); SetLastError(err); return fSuccess; }
BOOLEAN LsBusCtlQueryDvdStatus( ULONG SlotNo, PULONG pDvdStatus) { HANDLE file; BOOLEAN bResult; ULONG bytesReturned; BUSENUM_DVD_STATUS DVDSTATUS_IN; file = OpenBusInterface(); if(file == NULL) { return FALSE; } DVDSTATUS_IN.SlotNo = SlotNo; DVDSTATUS_IN.Size = sizeof(BUSENUM_DVD_STATUS); if (!DeviceIoControl( file, IOCTL_DVD_GET_STATUS, &DVDSTATUS_IN, sizeof(BUSENUM_DVD_STATUS), &DVDSTATUS_IN, sizeof(BUSENUM_DVD_STATUS), &bytesReturned, NULL)) { PrintErrorCode("[LanscsiLib]LanscsiQueryDvdStatus: failed ", GetLastError()); bResult = FALSE; } else { bResult = TRUE; *pDvdStatus = DVDSTATUS_IN.Status; } CloseHandle(file); return bResult; }
BOOLEAN LsBusCtlQueryLsmpInformation( PLSMPIOCTL_QUERYINFO Query, ULONG QueryLength, PVOID Information, ULONG InformationLength) { HANDLE file; BOOLEAN bResult; ULONG bytesReturned; file = OpenBusInterface(); if(file == NULL) { return FALSE; } if (!DeviceIoControl( file, IOCTL_LANSCSI_QUERY_LSMPINFORMATION, Query, QueryLength, Information, InformationLength, &bytesReturned, NULL)) { // PrintErrorCode("[LanscsiLib]LanscsiQueryLsmpInformation: failed ", GetLastError()); bResult = FALSE; } else { // PrintErrorCode("[LanscsiLib]LanscsiQueryLsmpInformation: succeeded.", GetLastError()); bResult = TRUE; } CloseHandle(file); return bResult; }
BOOLEAN LsBusCtlQueryNodeAlive( ULONG SlotNo, PBOOL pbAdapterHasError) { HANDLE file; BOOLEAN bResult; ULONG bytesReturned; BUSENUM_NODE_ALIVE_IN nodeAliveIn; BUSENUM_NODE_ALIVE_OUT nodeAliveOut; file = OpenBusInterface(); if(file == NULL) { return FALSE; } nodeAliveIn.SlotNo = SlotNo; if (!DeviceIoControl( file, IOCTL_BUSENUM_QUERY_NODE_ALIVE, &nodeAliveIn, sizeof(BUSENUM_NODE_ALIVE_IN), &nodeAliveOut, sizeof(BUSENUM_NODE_ALIVE_OUT), &bytesReturned, NULL)) { PrintErrorCode("[LanscsiLib]LanscsiQueryNodeAlive: failed ", GetLastError()); bResult = FALSE; } else { bResult = nodeAliveOut.bAlive; *pbAdapterHasError = nodeAliveOut.bHasError; } CloseHandle(file); return bResult; }
NDASBUSCTLAPI BOOL WINAPI NdasBusCtlAddTarget( PNDASBUS_ADD_TARGET_DATA AddTargetData) { BOOL fSuccess = FALSE; HANDLE hDevice = INVALID_HANDLE_VALUE; DWORD cbReturned = 0; DWORD err; DebugPrint(1, _T("NdasBusCtlAddTarget: Slot %d.\n"), AddTargetData->ulSlotNo); // Sleep(1000*5); hDevice = OpenBusInterface(); if(INVALID_HANDLE_VALUE == hDevice) { return FALSE; } fSuccess = DeviceIoControl( hDevice, IOCTL_NDASBUS_ADD_TARGET, AddTargetData, AddTargetData->ulSize, AddTargetData, AddTargetData->ulSize, &cbReturned, NULL); if (!fSuccess) { DebugPrintErrEx(_T("NdasBusCtlAddTarget at slot %d failed :"), AddTargetData->ulSlotNo); } else { DebugPrint(3, _T("NdasBusCtlAddTarget at slot %d completed successfully.\n"), AddTargetData->ulSlotNo); } err = GetLastError(); CloseHandle(hDevice); SetLastError(err); return fSuccess; }
BOOLEAN LsBusCtlUnplug( ULONG SlotNo) { HANDLE file; BOOLEAN result; ULONG bytesReturned; BUSENUM_UNPLUG_HARDWARE unplug; DebugPrint(3, ("[LanscsiLib]LanscsiUnplug: SlotNo. of the device to be unpluged: %d\n", SlotNo)); file = OpenBusInterface(); if(file == NULL) { return FALSE; } ZeroMemory(&unplug, sizeof(BUSENUM_UNPLUG_HARDWARE)); unplug.SlotNo = SlotNo; unplug.Size = sizeof (unplug); if (!DeviceIoControl ( file, IOCTL_BUSENUM_UNPLUG_HARDWARE, &unplug, sizeof (unplug), &unplug, sizeof (unplug), &bytesReturned, NULL)) { PrintErrorCode("[LanscsiLib]LanscsiUnplug: LanscsiUnplug failed ", GetLastError()); result = FALSE; } else result = TRUE; CloseHandle(file); return result; }
BOOLEAN LsBusCtlEject( ULONG SlotNo) { HANDLE file; BOOLEAN result; ULONG bytesReturned; BUSENUM_EJECT_HARDWARE eject; DebugPrint(3, ("[LanscsiLib]LanscsiEject: SlotNo. of the device to be ejected: %d\n", SlotNo)); file = OpenBusInterface(); if(file == NULL) { return FALSE; } ZeroMemory(&eject, sizeof(BUSENUM_EJECT_HARDWARE)); eject.SlotNo = SlotNo; eject.Size = sizeof (eject); if (!DeviceIoControl ( file, IOCTL_BUSENUM_EJECT_HARDWARE, &eject, sizeof (eject), &eject, sizeof (eject), &bytesReturned, NULL)) { PrintErrorCode("[LanscsiLib]LanscsiEject: LanscsiEject failed ", GetLastError()); result = FALSE; } else result = TRUE; CloseHandle(file); return result; }
BOOLEAN LsBusCtlAddTarget( PLANSCSI_ADD_TARGET_DATA AddTargetData) { HANDLE file; BOOLEAN result; ULONG bytesReturned; DebugPrint(1, ("[LanscsiLib]LanscsiAddTarget: SlotNo. of the device to add target: %d\n", AddTargetData->ulSlotNo)); // Sleep(1000*5); file = OpenBusInterface(); if(file == NULL) { return FALSE; } if (!DeviceIoControl ( file, IOCTL_LANSCSI_ADD_TARGET, AddTargetData, AddTargetData->ulSize, AddTargetData, AddTargetData->ulSize, &bytesReturned, NULL)) { PrintErrorCode("[LanscsiLib]LanscsiAddTarget: Add Target failed ", GetLastError()); result = FALSE; } else { result = TRUE; } CloseHandle(file); return result; }
NDASBUSCTLAPI BOOL WINAPI NdasBusCtlRegisterDevice( ULONG SlotNo, ULONG MaxOsDataTransferLength ) { BOOL fSuccess = FALSE; HANDLE hDevice = INVALID_HANDLE_VALUE; DWORD cbReturned = 0; DWORD err; PNDASBUS_PLUGIN_HARDWARE_EX2 registerDev; DWORD cbRegisterDev = 0; DebugPrint(1, _T("NdasBusCtlRegisterDevice: Slot %d, MaxRequestBlock %d\n"), SlotNo, MaxOsDataTransferLength); hDevice = OpenBusInterface(); if(INVALID_HANDLE_VALUE == hDevice) { return FALSE; } cbReturned = sizeof (NDASBUS_PLUGIN_HARDWARE_EX2) + NDASMINIPORT_HARDWARE_IDS_W_SIZE; registerDev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, cbReturned); // // The size field should be set to the sizeof the struct as declared // and *not* the size of the struct plus the multi_sz // registerDev->Size = sizeof(NDASBUS_PLUGIN_HARDWARE_EX2); registerDev->SerialNo = SlotNo; registerDev->MaxOsDataTransferLength = MaxOsDataTransferLength; registerDev->HardwareIDLen = NDASMINIPORT_HARDWARE_IDS_W_SIZE / sizeof(WCHAR); CopyMemory( registerDev->HardwareIDs, NDASMINIPORT_HARDWARE_IDS_W, NDASMINIPORT_HARDWARE_IDS_W_SIZE); fSuccess = DeviceIoControl ( hDevice, IOCTL_NDASBUS_REGISTER_DEVICE, registerDev, cbReturned, registerDev, cbReturned, &cbReturned, NULL); if (!fSuccess) { DebugPrintErrEx(_T("NdasBusCtlRegisterDevice at slot %d failed: "), SlotNo); } else { DebugPrintErrEx(_T("NdasBusCtlRegisterDevice at slot %d completed successfully.\n"), SlotNo); } err = GetLastError(); HeapFree(GetProcessHeap(), 0, registerDev); CloseHandle(hDevice); SetLastError(err); return fSuccess; }
LSBUSCTLAPI BOOL WINAPI LsBusCtlPlugInEx2( ULONG SlotNo, ULONG MaxRequestBlocks, HANDLE hEvent, HANDLE hAlarmEvent, BOOL NotRegister ) { BOOL fSuccess = FALSE; HANDLE hDevice = INVALID_HANDLE_VALUE; DWORD cbReturned = 0; DWORD err; PBUSENUM_PLUGIN_HARDWARE_EX2 pLanscsiPluginData; DWORD cbLanscsiPluginData = 0; DebugPrint(1, _T("LsBusCtlPlugInEx2: Slot %d, MaxRequestBlock %d, hEvent %p, hAlarmEvent %p\n"), SlotNo, MaxRequestBlocks, hEvent, hAlarmEvent); hDevice = OpenBusInterface(); if(INVALID_HANDLE_VALUE == hDevice) { return FALSE; } cbLanscsiPluginData = sizeof (BUSENUM_PLUGIN_HARDWARE_EX2) + LSMINIPORT_HARDWARE_IDS_W_SIZE; pLanscsiPluginData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, cbLanscsiPluginData); // // The size field should be set to the sizeof the struct as declared // and *not* the size of the struct plus the multi_sz // pLanscsiPluginData->Size = sizeof(BUSENUM_PLUGIN_HARDWARE_EX2); pLanscsiPluginData->SlotNo = SlotNo; pLanscsiPluginData->MaxRequestBlocks = MaxRequestBlocks; pLanscsiPluginData->phEvent = &hEvent; pLanscsiPluginData->phAlarmEvent = &hAlarmEvent; pLanscsiPluginData->HardwareIDLen = LSMINIPORT_HARDWARE_IDS_W_SIZE / sizeof(WCHAR); CopyMemory( pLanscsiPluginData->HardwareIDs, LSMINIPORT_HARDWARE_IDS_W, LSMINIPORT_HARDWARE_IDS_W_SIZE); if(NotRegister) { pLanscsiPluginData->Flags |= PLUGINFLAG_NOT_REGISTER; } fSuccess = DeviceIoControl ( hDevice, IOCTL_BUSENUM_PLUGIN_HARDWARE_EX2, pLanscsiPluginData, cbLanscsiPluginData, pLanscsiPluginData, cbLanscsiPluginData, &cbReturned, NULL); if (!fSuccess) { DebugPrintErrEx(_T("LsBusCtlPlugInEx2 at slot %d failed: "), SlotNo); } else { DebugPrintErrEx(_T("LsBusCtlPlugInEx2 at slot %d completed successfully.\n"), SlotNo); } err = GetLastError(); HeapFree(GetProcessHeap(), 0, pLanscsiPluginData); CloseHandle(hDevice); SetLastError(err); return fSuccess; }
NDASBUSCTLAPI BOOL WINAPI NdasBusCtlPlugInEx2 ( ULONG SlotNo, ULONG MaxOsDataTransferLength, // in bytes PNDASBUS_ADD_TARGET_DATA NdasBusAddTargetData, HANDLE hEvent, HANDLE hAlarmEvent, BOOL NotRegister ) { BOOL fSuccess = FALSE; HANDLE hDevice = INVALID_HANDLE_VALUE; DWORD cbReturned = 0; DWORD err; PNDASBUS_PLUGIN_HARDWARE_EX2 pLanscsiPluginData; DWORD cbLanscsiPluginData = 0; DebugPrint(1, _T("NdasBusCtlPlugInEx2: Slot %d, MaxRequestLength %d bytes, hEvent %p, hAlarmEvent %p\n"), SlotNo, MaxOsDataTransferLength, hEvent, hAlarmEvent); hDevice = OpenBusInterface(); if(INVALID_HANDLE_VALUE == hDevice) { return FALSE; } cbLanscsiPluginData = sizeof (NDASBUS_PLUGIN_HARDWARE_EX2) + NDASMINIPORT_HARDWARE_IDS_W_SIZE; pLanscsiPluginData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, cbLanscsiPluginData); // // The size field should be set to the sizeof the struct as declared // and *not* the size of the struct plus the multi_sz // pLanscsiPluginData->Size = sizeof(NDASBUS_PLUGIN_HARDWARE_EX2); pLanscsiPluginData->SerialNo = SlotNo; pLanscsiPluginData->MaxOsDataTransferLength = MaxOsDataTransferLength; pLanscsiPluginData->DisconEvent = hEvent; pLanscsiPluginData->AlarmEvent = hAlarmEvent; pLanscsiPluginData->HardwareIDLen = NDASMINIPORT_HARDWARE_IDS_W_SIZE / sizeof(WCHAR); CopyMemory( pLanscsiPluginData->HardwareIDs, NDASMINIPORT_HARDWARE_IDS_W, NDASMINIPORT_HARDWARE_IDS_W_SIZE); if(NotRegister) { pLanscsiPluginData->Flags |= PLUGINFLAG_NOT_REGISTER; } RtlCopyMemory( &pLanscsiPluginData->NdasBusAddTargetData, NdasBusAddTargetData, NdasBusAddTargetData->ulSize ); fSuccess = DeviceIoControl ( hDevice, IOCTL_NDASBUS_PLUGIN_HARDWARE_EX2, pLanscsiPluginData, cbLanscsiPluginData, pLanscsiPluginData, cbLanscsiPluginData, &cbReturned, NULL); if (!fSuccess) { DebugPrintErrEx(_T("NdasBusCtlPlugInEx2 at slot %d failed: "), SlotNo); } else { DebugPrintErrEx(_T("NdasBusCtlPlugInEx2 at slot %d completed successfully.\n"), SlotNo); } err = GetLastError(); HeapFree(GetProcessHeap(), 0, pLanscsiPluginData); CloseHandle(hDevice); SetLastError(err); return fSuccess; }