📄 wmisample.c
字号:
//
// iSCSI Version supported
//
IScsiHBAInformation->VersionMin = ISCSI_CLI_VERSION_MIN;
IScsiHBAInformation->VersionMax = ISCSI_CLI_VERSION_MAX;
IScsiHBAInformation->NumberOfPorts = 1;
IScsiHBAInformation->MaxCDBLength = 16;
IScsiHBAInformation->Status = 0;
IScsiHBAInformation->FunctionalitySupported =
(ISCSI_HBA_PRESHARED_KEY_CACHE |
ISCSI_HBA_ISCSI_AUTHENTICATION_CACHE |
ISCSI_HBA_IPSEC_TUNNEL_MODE);
*IScsiHBAInformation->VendorID = 255*sizeof(WCHAR);
status = RtlStringCchCopyNW((IScsiHBAInformation->VendorID+1), 255,
ISCSI_VENDOR_ID, wcslen(ISCSI_VENDOR_ID));
*IScsiHBAInformation->VendorModel = 255*sizeof(WCHAR);
status = RtlStringCchCopyNW((IScsiHBAInformation->VendorModel+1), 255,
ISCSI_VENDOR_MODEL,
wcslen(ISCSI_VENDOR_MODEL));
*IScsiHBAInformation->VendorVersion = 255*sizeof(WCHAR);
status = RtlStringCchCopyNW((IScsiHBAInformation->VendorVersion+1), 255,
ISCSI_VENDOR_VERSION,
wcslen(ISCSI_VENDOR_VERSION));
*IScsiHBAInformation->FirmwareVersion = 255*sizeof(WCHAR);
status = RtlStringCchCopyNW((IScsiHBAInformation->FirmwareVersion+1), 255,
ISCSI_VENDOR_VERSION,
wcslen(ISCSI_VENDOR_VERSION));
*IScsiHBAInformation->AsicVersion = 255*sizeof(WCHAR);
status = RtlStringCchCopyNW((IScsiHBAInformation->AsicVersion+1), 255,
ISCSI_VENDOR_VERSION,
wcslen(ISCSI_VENDOR_VERSION));
*IScsiHBAInformation->OptionRomVersion = 255*sizeof(WCHAR);
*IScsiHBAInformation->SerialNumber = 255*sizeof(WCHAR);
status = RtlStringCchCopyNW((IScsiHBAInformation->SerialNumber+1), 255,
ISCSI_SERIAL_NUMBER,
wcslen(ISCSI_SERIAL_NUMBER));
*IScsiHBAInformation->DriverName = 255*sizeof(WCHAR);
status = RtlStringCchCopyNW((IScsiHBAInformation->DriverName+1), 255,
ISCSI_INITIATOR_DRIVER_NAME,
wcslen(ISCSI_INITIATOR_DRIVER_NAME));
}
UCHAR
iSpBuildInitiatorSessionInfo(
IN PISCSI_ADAPTER_EXTENSION AdapterExtension,
IN PSCSIWMI_REQUEST_CONTEXT DispatchContext,
IN ULONG BufferAvail,
OUT PUCHAR Buffer,
OUT PULONG SizeNeeded
)
{
PWMI_CONNECTION_LIST connectionList;
ULONG size, sessionInx;
ULONG numberOfSessions, numberOfConnections;
UCHAR status;
connectionList = iSpGetConnectionList(AdapterExtension,
&numberOfSessions,
&numberOfConnections);
DebugPrint((iScsiPrtDebugInfo,
"Number of Sessions %d, Number of Connections %d\n",
numberOfSessions, numberOfConnections));
//
// determine the size of buffer needed to build all of the session
// and connection data structures
//
//
// Account for the fixed part of the iScsiInitiatorSessionInfo
//
size = FIELD_OFFSET(MSiSCSI_InitiatorSessionInfo,
SessionsList);
if (connectionList == NULL) {
if (BufferAvail >= size)
{
PMSiSCSI_InitiatorSessionInfo sessionInfo;
sessionInfo = (PMSiSCSI_InitiatorSessionInfo)Buffer;
sessionInfo->UniqueAdapterId = (ULONGLONG) AdapterExtension;
sessionInfo->SessionCount = 0;
*SizeNeeded = size;
return(SRB_STATUS_SUCCESS);
} else {
*SizeNeeded = size;
return(SRB_STATUS_DATA_OVERRUN);
}
}
//
// Loop over all sessions and account for the space needed for each
// session plus all of the connections within each session
//
sessionInx = 0;
while (sessionInx < numberOfSessions) {
//
// Since the session structure needs to be 8 bytes aligned, we
// pad out to 8 bytes
//
size = (size + 7) & ~7;
//
// Add the fixed size needed for the session structure
//
size += FIELD_OFFSET(ISCSI_SessionStaticInfo,
ConnectionsList);
//
// Account for the size of all connection structures, being
// sure that the connection structure is padded out to 8 bytes
// in order to maintain 8 byte alignment
//
size += connectionList[sessionInx].Count *
( (sizeof(ISCSI_ConnectionStaticInfo)+7) & ~7);
sessionInx++;
}
*SizeNeeded = size;
if (size <= BufferAvail)
{
//
// If we do have enough space to build the session info data
// structures then we do so
//
RtlZeroMemory(Buffer, size);
status = iSpReadInitiatorSessionInfo(
AdapterExtension,
connectionList,
numberOfSessions,
Buffer);
} else {
//
// If there is not enough space to build the session info data
// structures then return this error
//
status = SRB_STATUS_DATA_OVERRUN;
}
iSpReleaseConnectionReferences(connectionList,
numberOfSessions);
return status;
}
UCHAR
iSpBuildConnectionStatistics(
IN PISCSI_ADAPTER_EXTENSION AdapterExtension,
IN PSCSIWMI_REQUEST_CONTEXT DispatchContext,
IN ULONG GuidIndex,
IN ULONG InstanceIndex,
IN ULONG InstanceCount,
IN OUT PULONG InstanceLengthArray,
IN ULONG BufferAvail,
OUT PUCHAR Buffer,
OUT PULONG SizeNeeded
)
{
PWMI_CONNECTION_LIST connectionList;
PISCSI_CONNECTION iScsiConnection;
PWCHAR NameOffset;
PUCHAR currentDataPos;
ULONG instanceInx;
ULONG newOutBufferAvil;
WMIString DynamicInstanceName;
ULONG numberOfSessions;
ULONG numberOfConnections;
UCHAR srbStatus;
srbStatus = SRB_STATUS_SUCCESS;
*SizeNeeded = 0;
connectionList = iSpGetConnectionList(AdapterExtension,
&numberOfSessions,
&numberOfConnections);
if (connectionList == NULL) {
DebugPrint((iScsiPrtDebugError,
"Failed to allocate array for connections\n"));
return SRB_STATUS_ERROR;
}
DebugPrint((iScsiPrtDebugInfo,
"Number of Sessions %d, Number of Connections %d\n",
numberOfSessions, numberOfConnections));
if (DispatchContext->MinorFunction == IRP_MN_QUERY_ALL_DATA) {
ULONG sessionInx;
ULONG connectionInx;
ULONG connectionCount;
BOOLEAN dynamicNameStatus;
dynamicNameStatus = ScsiPortWmiSetInstanceCount(DispatchContext,
numberOfConnections,
&newOutBufferAvil,
SizeNeeded);
if (!dynamicNameStatus)
{
DebugPrint((iScsiPrtDebugError,
"iscsiprt: wnode is not for a dynamic instance named GUID\n"));
*SizeNeeded = 0;
srbStatus = SRB_STATUS_ERROR;
} else {
if (newOutBufferAvil == 0) {
//
// The buffer passed to return the data is too small
//
srbStatus = SRB_STATUS_DATA_OVERRUN;
}
//
// For the data itself
//
instanceInx = 0;
sessionInx = 0;
while (sessionInx < numberOfSessions) {
connectionCount = connectionList[sessionInx].Count;
connectionInx = 0;
while (connectionInx < connectionCount) {
iScsiConnection = connectionList[sessionInx].ISCSIConnection[connectionInx];
if (iScsiConnection != NULL) {
currentDataPos = (PUCHAR) ScsiPortWmiSetData(DispatchContext,
instanceInx,
sizeof(MSiSCSI_ConnectionStatistics),
&newOutBufferAvil,
SizeNeeded);
if (newOutBufferAvil == 0)
{
//
// The buffer passed to return the data is too small
//
srbStatus = SRB_STATUS_DATA_OVERRUN;
}
if ((srbStatus != SRB_STATUS_DATA_OVERRUN) &&
(currentDataPos != NULL)) {
srbStatus = iSpReadConnStatistics(AdapterExtension,
iScsiConnection,
currentDataPos);
if (srbStatus == SRB_STATUS_ERROR)
{
break;
}
}
RtlZeroMemory(&DynamicInstanceName,
sizeof(DynamicInstanceName));
srbStatus = iSpGetDynamicConnectionInstanceName(
iScsiConnection,
&DynamicInstanceName);
if (srbStatus == SRB_STATUS_ERROR)
{
break;
}
NameOffset = ScsiPortWmiSetInstanceName(
DispatchContext,
instanceInx,
DynamicInstanceName.Length+sizeof(USHORT),
&newOutBufferAvil,
SizeNeeded);
if ((newOutBufferAvil == 0) && (NameOffset == NULL))
{
//
// The buffer passed to return the data is too small
//
srbStatus = SRB_STATUS_DATA_OVERRUN;
}
if (srbStatus != SRB_STATUS_DATA_OVERRUN)
{
//
// copy the instance anme into NameOffset
//
RtlCopyMemory(NameOffset, (PUCHAR)(&DynamicInstanceName),
(DynamicInstanceName.Length + sizeof(USHORT)));
}
instanceInx++;
}
connectionInx++;
}
if (srbStatus == SRB_STATUS_ERROR)
{
break;
}
sessionInx++;
}
}
} else {
PWCHAR instanceName;
ULONG givenInstanceNameLength = 0;
ULONG instanceNameLength;
ULONG sessionInx;
ULONG connectionInx;
ULONG connectionCount;
BOOLEAN found = FALSE;
//
// single instance
//
//
// get the instance name
//
instanceName = ScsiPortWmiGetInstanceName(DispatchContext);
if (instanceName != NULL) {
givenInstanceNameLength = ((USHORT) *instanceName) / sizeof(WCHAR);
}
*SizeNeeded = sizeof(MSiSCSI_ConnectionStatistics);
if (BufferAvail < *SizeNeeded)
{
//
// The buffer passed to return the data is too small
//
srbStatus = SRB_STATUS_DATA_OVERRUN;
} else {
instanceInx = 0;
sessionInx = 0;
while (sessionInx < numberOfSessions) {
if (connectionList[sessionInx].Count) {
connectionInx = 0;
while (connectionInx < numberOfConnections) {
iScsiConnection = connectionList[sessionInx].ISCSIConnection[0];
if (iScsiConnection != NULL) {
RtlZeroMemory(&DynamicInstanceName,
sizeof(DynamicInstanceName));
srbStatus = iSpGetDynamicConnectionInstanceName(
iScsiConnection,
&DynamicInstanceName);
if ((srbStatus != SRB_STATUS_ERROR) &&
(instanceName != NULL))
{
if (!wcsncmp((PWCHAR)(&DynamicInstanceName),
instanceName,
(DynamicInstanceName.Length/sizeof(WCHAR)+1))) {
srbStatus = iSpReadConnStatistics(AdapterExtension,
iScsiConnection,
Buffer);
if (srbStatus == SRB_STATUS_ERROR)
{
*SizeNeeded = 0;
} else {
*InstanceLengthArray = *SizeNeeded;
}
found = TRUE;
break;
}
} else {
*SizeNeeded = 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -