hi,
here is the code snipet…
I am trying to get handle to the SCSI controller , send a IOCTL_GET_SCSI_ADDRESS to get the scsi port number of the controller.
SEtupdigetclassdevs() uses the setup class guid instead of interface GUID.
SetupDiGetDeviceInstanceId( ppd->DeviceInfoSet,
ppd->DeviceInfoData,
NULL,
0,
&NumBytes );
// Allocate Buffer used to get the Device ID
pDeviceId = malloc(NumBytes);
if( (NumBytes <= 0) || !pDeviceId )
{
status = FALSE;
__leave;
}
// Zero out DeviceId
memset(pDeviceId, 0, NumBytes);
// Call SetupDiGetDeviceInstanceId second to actually get the DeviceId.
status = SetupDiGetDeviceInstanceId( ppd->DeviceInfoSet,
ppd->DeviceInfoData,
pDeviceId,
NumBytes,
NULL );
if( !status )
{
__leave;
}
else
{
DEBUGPRINT((0, " pDeviceId Value:%s\n",pDeviceId));
}
// Once we have the DeviceID, we can get the device information set
hDevInfo = SetupDiGetClassDevs( &GUID_DEVINTERFACE_SCSIADAPTER,
pDeviceId,
NULL,
DIGCF_ALLCLASSES | DIGCF_PRESENT);
if( INVALID_HANDLE_VALUE == hDevInfo )
{
DEBUGPRINT((0, " SetupDiGetClassDevs Fails\n"));
status = FALSE;
__leave;
}
memset(&DeviceInterfaceData, 0, sizeof(SP_DEVICE_INTERFACE_DATA));
DeviceInterfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
// Given the Device Information Set, enumerate the Device interfaces, should only be one.
status = SetupDiEnumDeviceInterfaces( hDevInfo,
NULL,
&GUID_DEVINTERFACE_SCSIADAPTER, 0,
&DeviceInterfaceData );
if( !status )
{
DEBUGPRINT((0, " SetupDiEnumDeviceInterfaces Fails:%d\n",GetLastError()));
__leave;
}
// Call SetupDiGetDeviceInterfaceDetail first to determine the size of the Buffer. (Expected to Return FALSE)
SetupDiGetDeviceInterfaceDetail( hDevInfo,
&DeviceInterfaceData,
NULL,
0,
&NumBytes,
NULL );
// Allocate struct for Interface Detail Data
pDeviceInterfaceDetailData = malloc( NumBytes );
if( !pDeviceInterfaceDetailData )
{
DEBUGPRINT((0, " Memory allocation for pDeviceInterfaceDetailData Fails …\n"));
status = FALSE;
__leave;
}
// Clear out struct, and set cb.size to the correct value
memset(pDeviceInterfaceDetailData, 0, NumBytes);
pDeviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
// Next call this to get the device path we need to pass to CreateFile
status = SetupDiGetDeviceInterfaceDetail( hDevInfo,
&DeviceInterfaceData,
pDeviceInterfaceDetailData,
NumBytes,
NULL,
NULL );
if(!status)
{
DEBUGPRINT((0, " Memory allocation for pDeviceInterfaceDetailData Fails Again…\n"));
__leave;
}
DEBUGPRINT((0, " CreateFile(Handle to ):%s\n",pDeviceInterfaceDetailData->DevicePath));
// Now get the Handle.
hDevice = CreateFile( pDeviceInterfaceDetailData->DevicePath,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL );
if ( (hDevice == NULL) || (hDevice == INVALID_HANDLE_VALUE) )
{
DEBUGPRINT((0, " GetDeviceHandle - Unable to obtain handle.\n"));
status = FALSE;
}
status = IOCTL_ReadDevice( hDevice,
IOCTL_SCSI_GET_ADDRESS,
(PULONG) pScsiAddress,
sizeof(SCSI_ADDRESS),
&NumBytes );
if (!status)
{
DEBUGPRINT((0, " Not able to Get SCSI ADDRESS…\n"));
dwErrorCode = GetLastError();
DEBUGPRINT((0, " GetSCSIAddress(GetLastError) : %d\n",dwErrorCode));
}
dwIndexNumber = pScsiAddress->PortNumber;
DEBUGPRINT((0, " GetSCSIAddress(IndexNumber) : %d\n",dwIndexNumber));