NDISUIO problem, can't retrieve NDIS packets

Discussion in 'Windows Vista Drivers' started by Tom Rixom, Sep 4, 2003.

  1. Tom Rixom

    Tom Rixom Guest

    Hello,

    I am using the NDISUIO sample and have successfully installed it under
    WIndows 98.

    I have got everything working, binding, querying OIDS and so forth but as
    soon as I try
    to read packets I get the right size for the data packet but the data itself
    is full of 0xAF(HEX).

    I have used both the MJ_READ method and a IOCTL command to retrieve the
    buffers
    into user space but both give the same result. I think it is going wrong
    when retreiving the
    actual NDIS buffer but the code for this is all Microsoft.

    Can someone point in the right direction? Maybe I am building the sample
    incorrectly?

    I build it using the Windows XP DDK, Windows 2000 FREE build with the
    following source:

    --------------------------------------------------------
    TARGETNAME=aa_ndis
    TARGETPATH=obj

    TARGETTYPE=DRIVER

    C_DEFINES=$(C_DEFINES) -DNDIS50=1 -DNDIS_WDM=1 -DBINARY_COMPATIBLE

    # C_DEFINES=$(C_DEFINES) -DDBG_SPIN_LOCK=1

    C_DEFINES=$(C_DEFINES) -DWIN9X=1

    C_DEFINES=$(C_DEFINES) -DDBG=1 -DSENDDBG=1

    PRECOMPILED_INCLUDE=precomp.h

    PRECOMPILED_PCH=precomp.pch

    PRECOMPILED_OBJ=precomp.obj

    USE_MAPSYM=1

    TARGETLIBS=\

    $(DDK_LIB_PATH)\ndis.lib

    SOURCES=\

    ndisuio.rc \

    ntdisp.c \

    ndisbind.c \

    recv.c \

    send.c \

    debug.c



    MISCFILES=ndisuio.sld
     
    Tom Rixom, Sep 4, 2003
    #1
    1. Advertisements

  2. Tom,

    Are you using NdisQueryPacket/NdisQueryBuffer to get at the data or are you
    touching the NDIS_BUFFER members directly? The NDIS_BUFFER structure in 98
    is different, but as long as you're using the functions you should be fine.

    Bryan S. Burgin


    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Bryan S. Burgin [MSFT], Sep 4, 2003
    #2
    1. Advertisements

  3. Tom Rixom

    Tom Rixom Guest

    you should be fine.

    Bryan,

    I am using the NDISUIO sample which does use the
    NdisQueryBuffer.

    I have sent the buffer I retrieve from the NDISQueryBuffer
    to the debug kernel output and all I get is
    AFAFAFAFAFAFAFAFAFAFAFAFAF but the packet sizes are
    correct.

    Did you see anything strange in the way I build the
    driver using the source file I provided?

    As I said before I am using the NDISUIO sample which
    already implements the qeueing and retrieving of
    NDIS packets but I am messing it up somehow...

    Thanks,

    Tom

    confers no rights.
     
    Tom Rixom, Sep 4, 2003
    #3
  4. Tom Rixom

    Tom Rixom Guest

    This is the code directly from the NDISUIO sample:

    The only thing I added where a few simple DEBUGP statements.

    ------------------------------------------------------------

    VOID

    ndisuioServiceReads(

    IN PNDISUIO_OPEN_CONTEXT pOpenContext

    )

    /*++

    Routine Description:

    Utility routine to copy received data into user buffers and

    complete READ IRPs.

    Arguments:

    pOpenContext - pointer to open context

    Return Value:

    None

    --*/

    {

    PIRP pIrp;

    PLIST_ENTRY pIrpEntry;

    PNDIS_PACKET pRcvPacket;

    PLIST_ENTRY pRcvPacketEntry;

    PUCHAR pSrc, pDst;

    ULONG BytesRemaining; // at pDst

    PNDIS_BUFFER pNdisBuffer;

    ULONG BytesAvailable;

    DEBUGP(DL_VERY_LOUD, ("ServiceReads: open %p/%x\n",

    pOpenContext, pOpenContext->Flags));

    NUIO_REF_OPEN(pOpenContext); // temp ref - service reads

    DEBUGP(DL_INFO, ("ServiceReads: openened context\r\n") );

    NUIO_ACQUIRE_LOCK(&pOpenContext->Lock);

    if( NUIO_IS_LIST_EMPTY(&pOpenContext->PendedReads) )

    DEBUGP(DL_INFO, ("ServiceReads: PendedReads empty\r\n"));

    if( NUIO_IS_LIST_EMPTY(&pOpenContext->RecvPktQueue) )

    DEBUGP(DL_INFO, ("ServiceReads: RecvPktQueue empty\r\n") );



    while (!NUIO_IS_LIST_EMPTY(&pOpenContext->PendedReads) &&

    !NUIO_IS_LIST_EMPTY(&pOpenContext->RecvPktQueue))

    {

    DEBUGP(DL_INFO, ("ServiceReads: entering while loop\r\n") );

    //

    // Get the first pended Read IRP

    //

    pIrpEntry = pOpenContext->PendedReads.Flink;

    pIrp = CONTAINING_RECORD(pIrpEntry, IRP, Tail.Overlay.ListEntry);

    //

    // Check to see if it is being cancelled.

    //

    if (IoSetCancelRoutine(pIrp, NULL))

    {

    //

    // It isn't being cancelled, and can't be cancelled henceforth.

    //

    NUIO_REMOVE_ENTRY_LIST(pIrpEntry);

    //

    // NOTE: we decrement PendedReadCount way below in the

    // while loop, to avoid letting through a thread trying

    // to unbind.

    //

    }

    else

    {

    //

    // The IRP is being cancelled; let the cancel routine handle it.

    //

    DEBUGP(DL_INFO, ("ServiceReads: open %p, skipping cancelled IRP %p\n",

    pOpenContext, pIrp));

    continue;

    }

    DEBUGP(DL_VERY_LOUD, ("ServiceReads: retrieving packet\r\n") );

    //

    // Get the first queued receive packet

    //

    pRcvPacketEntry = pOpenContext->RecvPktQueue.Flink;

    NUIO_REMOVE_ENTRY_LIST(pRcvPacketEntry);

    pOpenContext->RecvPktCount --;

    NUIO_RELEASE_LOCK(&pOpenContext->Lock);

    NUIO_DEREF_OPEN(pOpenContext); // Service: dequeue rcv packet

    pRcvPacket = NUIO_LIST_ENTRY_TO_RCV_PKT(pRcvPacketEntry);

    //

    // Copy as much data as possible from the receive packet to

    // the IRP MDL.

    //

    #ifndef WIN9X

    pDst = MmGetSystemAddressForMdlSafe(pIrp->MdlAddress, NormalPagePriority);

    NUIO_ASSERT(pDst != NULL); // since it was already mapped

    #else

    pDst = MmGetSystemAddressForMdl(pIrp->MdlAddress); // Win9x

    #endif

    BytesRemaining = MmGetMdlByteCount(pIrp->MdlAddress);

    DEBUGP(DL_VERY_LOUD, ("BytesRemaining: %ld\r\n", BytesRemaining));

    pNdisBuffer = pRcvPacket->Private.Head;

    while (BytesRemaining && (pNdisBuffer != NULL))

    {

    #ifndef WIN9X

    NdisQueryBufferSafe(pNdisBuffer, &pSrc, &BytesAvailable,
    NormalPagePriority);

    if (pSrc == NULL)

    {

    DEBUGP(DL_FATAL,

    ("ServiceReads: Open %p, QueryBuffer failed for buffer %p\n",

    pOpenContext, pNdisBuffer));

    break;

    }

    #else

    NdisQueryBuffer(pNdisBuffer, &pSrc, &BytesAvailable);

    #endif

    if (BytesAvailable)

    {

    ULONG BytesToCopy = MIN(BytesAvailable, BytesRemaining);

    NUIO_COPY_MEM(pDst, pSrc, BytesToCopy);

    BytesRemaining -= BytesToCopy;

    pDst += BytesToCopy;

    }

    NdisGetNextBuffer(pNdisBuffer, &pNdisBuffer);

    }

    //

    // If I dump the buffer that is being returned using the IRP here it is

    // full of AFAFAFAFAFAFAFAFA

    // I assume i can dump the pDst =
    MmGetSystemAddressForMdl(pIrp->MdlAddress)???

    //

    DEBUGP(DL_VERY_LOUD, ("ServiceReads: completing IRP\r\n"));

    //

    // Complete the IRP.

    //

    pIrp->IoStatus.Status = STATUS_SUCCESS;

    pIrp->IoStatus.Information = MmGetMdlByteCount(pIrp->MdlAddress) -
    BytesRemaining;

    DEBUGP(DL_INFO, ("ServiceReads: Open %p, IRP %p completed with %d bytes\n",

    pOpenContext, pIrp, pIrp->IoStatus.Information));

    IoCompleteRequest(pIrp, IO_NO_INCREMENT);

    //

    // Free up the receive packet - back to the miniport if it

    // belongs to it, else reclaim it (local copy).

    //

    if (NdisGetPoolFromPacket(pRcvPacket) != pOpenContext->RecvPacketPool)

    {

    NdisReturnPackets(&pRcvPacket, 1);

    }

    else

    {

    ndisuioFreeReceivePacket(pOpenContext, pRcvPacket);

    }

    NUIO_DEREF_OPEN(pOpenContext); // took out pended Read

    NUIO_ACQUIRE_LOCK(&pOpenContext->Lock);

    pOpenContext->PendedReadCount--;

    }

    NUIO_RELEASE_LOCK(&pOpenContext->Lock);

    NUIO_DEREF_OPEN(pOpenContext); // temp ref - service reads

    DEBUGP(DL_VERY_LOUD, ("ServiceReads returning\n" ));

    }

    ------------------------------------
     
    Tom Rixom, Sep 5, 2003
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.