Tdi Client Driver

Hi all,

I try to write a tdi client driver. In my first test, I try to send a
datagram so to do that, I use ZwCreateFile with “\Device\Udp” after I use
TdiBuildInternalDeviceControlIrp, after I do an IoAllocateMdl and the
MmProbeAndLockPages return a access violation, I don’t know why, I suppose
that I put wrong parameters in the IoAllocateMdl but I don’t know what
paramaters.

Are there someone, who help me to resolve this problem

Thanks for your help.

Laurent F.

Following a part of my code :

status = ZwCreateFile(
&FileHandle,
DesiredAccess,
&ObjectAttributes,
&IoStatusBlock,
NULL, /* optional */
FileAttributes,
ShareAccess,
CreateDisposition,
0,
pEa, /* optional */
eaLength
);
if (status != STATUS_SUCCESS)
{
E1Print(TheDriverObject, L"ZwCreateFile Error", (ULONG)status);
return status;
}
EPrint(TheDriverObject, L"ZwCreateFile Ok");

status = ObReferenceObjectByHandle(
FileHandle,
FILE_ALL_ACCESS,
NULL,
KernelMode,
(PVOID*) &pFileObject,
NULL
);
if (status != STATUS_SUCCESS)
{
E1Print(TheDriverObject, L"ObReferenceObjectByHandle Error",
(ULONG)status);
return status;
}

EPrint(TheDriverObject, L"ObReferenceObjectByHandle Ok");

KeInitializeEvent(
&Event,
NotificationEvent,
FALSE
);

pIrp = TdiBuildInternalDeviceControlIrp(
TDI_SEND_DATAGRAM,
DeviceObject,
pFileObject,
&Event,
&IoStatusBlock
);
if (pIrp == NULL)
{
EPrint(TheDriverObject, L"TdiBuildInternalDeviceControlIrp
Error");
return status;
}

EPrint(TheDriverObject, L"TdiBuildInternalDeviceControlIrp Ok");

pMdl = IoAllocateMdl(
MmGetMdlVirtualAddress(pIrp->MdlAddress),
MmGetMdlByteCount(pIrp->MdlAddress),
TRUE,
FALSE,
pIrp
);
if (pMdl == NULL)
{
EPrint(TheDriverObject, L"IoAllocateMdl Error");
return status;
}
try
{
MmProbeAndLockPages(
pMdl,
KernelMode,
IoReadAccess
);
} except(EXCEPTION_EXECUTE_HANDLER) {
status = STATUS_INVALID_USER_BUFFER; }