Hi, Tim.
I copy the code below:
(a) open the driver
HANDLE GetDeviceViaInterface(GUID* pGuid, DWORD instance)
{
SP_INTERFACE_DEVICE_DATA ifdata;
DWORD ReqLen;
PSP_INTERFACE_DEVICE_DETAIL_DATA ifDetail;
HANDLE rv;
// Get handle to relevant device information set
HDEVINFO info = SetupDiGetClassDevs(pGuid, NULL, NULL,
DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
if (info == INVALID_HANDLE_VALUE)
{
printf(“info error %d 0x%x\n”, info, GetLastError());
return NULL;
}
// Get interface data for the requested instance
ifdata.cbSize = sizeof(ifdata);
if (!SetupDiEnumDeviceInterfaces(info, NULL, pGuid, instance,
&ifdata))
{
SetupDiDestroyDeviceInfoList(info);
printf(" SetupDiEnumDeviceInterfaces error 0x%x \n",
GetLastError());
return NULL;
}
SetupDiGetDeviceInterfaceDetail(info, &ifdata, NULL, 0, &ReqLen,
NULL);
ifDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA) malloc(ReqLen);
if (ifDetail==NULL)
{
printf(" ifDetail = NULL\n");
SetupDiDestroyDeviceInfoList(info);
return NULL;
}
// Get symbolic link name
ifDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
if (!SetupDiGetDeviceInterfaceDetail(info, &ifdata, ifDetail,
ReqLen, NULL, NULL))
{
SetupDiDestroyDeviceInfoList(info);
printf(“SetupDiGetDeviceInterfaceDetail error\n”);
free(ifDetail);
return NULL;
}
// Open handle
rv = CreateFile(ifDetail->DevicePath,
GENERIC_READ | GENERIC_WRITE,
0,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (rv == INVALID_HANDLE_VALUE)
{
printf(“create error %d 0x%x\n”, rv, GetLastError());
rv = NULL;
}
free (ifDetail);
SetupDiDestroyDeviceInfoList(info);
return rv;
}
(b) calls DeviceIoControl and GetLastError,
The subroutine accesses the Dpram on the hardware to
find the board ID.
The board ID it bring back is correct even the
DeviceIoControl return’s FALTE
static BOOL GetBoardId(char board_number, PUCHAR buffer)
{
BOOL bOK; // boolean
return code
ULONG datalength = 0;
XDS_DPRAM DrvBoard_ram; // pointer to xds driver message
structure
DrvBoard_ram.board_number = board_number;
DrvBoard_ram.offset = 0x1F00;
DrvBoard_ram.size = 4; // size of ID string to read
DrvBoard_ram.buffer = buffer;
// call low level driver
bOK = DeviceIoControl(
gl_hdriver,
(DWORD)READ_DPRAM,
&DrvBoard_ram,
sizeof(XDS_DPRAM),
NULL,
0,
&datalength,
NULL);
if (!bOK)
{
printf(" read dpram error 0x%x \n", GetLastError());
return 1;
}
// terminate string
buffer[DrvBoard_ram.size] = 0;
return 0;
}
(c) handles and completes an ioctl in the driver?
The return status initialize to STATUS_SUCCCESS at
declare area. The driver handle go through without error. It calls
completes with status = 0.
case READ_DPRAM:
DbgPrint (“get in read dpram\n”);
pRAM = (PXDS_DPRAM)inBuffer;
//pOutRam = (PXDS_DPRAM)outBuffer;
// Check buffer space.
if (InputBufferLength < sizeof(XDS_DPRAM))
{
Status = STATUS_BUFFER_TOO_SMALL;
DbgPrint(“error 1\n”);
break;
}
else if ((pRAM->buffer == 0) || (pRAM->size <=
0))
{
Status = STATUS_BUFFER_TOO_SMALL;
DbgPrint(“error 3\n”);
break;
}
else
{
// translate to low-level board number
from user-level board number
if (!GetBoardNumByUserNum(pExt,
pRAM->board_number, &board_number))
{
Status = STATUS_DATA_ERROR;
DbgPrint(“error 4\n”);
break;
}
if
(!pExt->BoardMessage[board_number].PciBoardActive)
{
Status = STATUS_DATA_ERROR;
DbgPrint(“error 5\n”);
break;
}
else if ((pRAM->offset + pRAM->size) >
pExt->BoardMessage[board_number].XdsBaseMemAddressSize)
{
Status = STATUS_DATA_ERROR;
DbgPrint(“error 6\n”);
break;
}
// If everything ok, read buffer.
memcpy((PVOID)pRAM->buffer,
(PVOID)((PUCHAR)(pExt->BoardMessage[board_number].XdsVirtualMemAddress
+
pRAM->offset)),
pRAM->size);
// return the number of bytes in
the output buffer.
//bytesReturned =
sizeof(XDS_DPRAM);
}
DbgPrint(“read dprm done\n”);
break;
…
/* - default case - */
default:
Status = STATUS_UNSUCCESSFUL;
break;
}
if(bytesReturned > 0)
WdfRequestCompleteWithInformation(Request, Status,
bytesReturned );
else
{
WdfRequestComplete( Request, Status);
DbgPrint(“ioctl comlete with status = 0x%X\n” ,status);
}
Thank you very much for help.
Bob Bao
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Tim Roberts
Sent: Friday, October 24, 2008 4:59 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Ioctl request question.
Bob Bao wrote:
Thanks for reply. I am not sure what is the problem. I open the
driver
with FILE_ATRIBUTE_NOMAL. In driver, I configure the IoCtrol queue
with
WdfIoQueueDispatchParallel. But all the ioctl calls did not pending.
They are all completed in the driver with no error.(
WdfRequestComplete
called). Could you please explain more detail about the problem.
That last sentence is really what we should be asking YOU.
Why don’t you show us the code that (a) calls CreateFile, (b) calls
DeviceIoControl and GetLastError, and (c) handles and completes an ioctl
in the driver?
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer