I post this hoping to get some help, and not criticised for either not researching this enough first, or for not posting code. I have done both now so hope to get some constructive help.
My problem is this. I want to receive some data from the driver - a filter driver.
In the driver I am trying to populate a structure, and return it via the Irp->AssociatedIrp.SystemBuffer.
The structure within the driver looks like
typedef struct FIREWALL_STATUS_
{
int upTime; //Length of time the firewall has been running in time_t format
int packetsProcessed;
int packetsDropped;
int connectionAttemptsProcessed;
int connectionAttemptsRefused;
} FIREWALL_STATUS, *PFIREWALL_STATUS;
and I have all of my device ios firing correctly.
The one I am having trouble with is the firewall status query,
the code for this is as below
int getFirewallStatus(
__in PDEVICE_OBJECT DeviceObject,
__in PIRP Irp)
{
FIREWALL_STATUS fwallStatus;
NTSTATUS ntStatus;
PIO_STACK_LOCATION irpSp;// Pointer to current stack location
ntStatus = STATUS_SUCCESS;
irpSp = IoGetCurrentIrpStackLocation( Irp );
ntStatus = STATUS_SUCCESS;
DbgPrint(“Get firewall status message received”);
fwallStatus.upTime=999999;
fwallStatus.packetsProcessed=888888;
fwallStatus.packetsDropped=777777;
fwallStatus.connectionAttemptsProcessed=666666;
fwallStatus.connectionAttemptsRefused=555555;
Irp->AssociatedIrp.SystemBuffer = &fwallStatus;
irpSp->Parameters.DeviceIoControl.OutputBufferLength = sizeof(fwallStatus);
Irp->IoStatus.Information = sizeof(fwallStatus);
Irp->IoStatus.Status = ntStatus;
IoCompleteRequest( Irp, IO_NO_INCREMENT );
return 0;
}
Note, this is called from with the main deviceio function that is registered with the io manager. The function is called ok, but the result is a BSOD. As far as the MSDN tells me, using buffered IO the system buffer is for both input and output io, and you must pass a pointer to the output buffer to the system buffer, and also set the output buffer length. In some articles I have found they even say to set the IoStatus.Information to the size out the output buffer as well.
For completeness, the client side code I have calling this is as follows :
void getFirewallStatus(){
FIREWALL_STATUS outputBuffer;
BOOL bRc;
ULONG bytesReturned;
int errNum;
if (!hDevice){
hDevice = CreateFile(“\\.\SimpleSys”,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
}
if (hDevice == INVALID_HANDLE_VALUE){
printf(“Invalid handle value returned from CreateFile \n”);
errNum = GetLastError();
printf(“CreateFile failed! ERROR CODE = %d\n”, errNum);
return;
}
else{
bRc = DeviceIoControl ( hDevice,
IOCTL_GET_FIREWALL_STATUS,
gFirewallRules,
sizeof(TL_PORT_RULE) * gFirewallRulesCount,
&outputBuffer,
sizeof( outputBuffer),
&bytesReturned,
NULL
);
printf(“Uptime %d”,outputBuffer.upTime);
}
}