Hi
I have an ethernet protocol driver (based on Win2K DDK’s NDIS Packet
driver).
I’ve defined a FIFO in my driver that contains 100 buffers, as below:
struct {
UCHAR Store[100][1514];
UINT Length[100];
UINT InIndex;
UINT OutIndex;
} MSG_FIFO;
Question 1:
When a packet arrives from the network, the ProtocolReceive routine is
called and first copies the packet header into the buffer. It is then
supposed to copy the rest of the packet into the buffer by calling
NdisTransferData. An NDIS_PACKET structure (needed by NdisTransferData)
seems to need a pointer to my buffer in the form of an MDL. How can I
allocate an MDL to point to the FIFO’s buffer? My attempt at simply using
IoAllocateMdl() caused a bugcheck. Not sure why.
Question 2:
NdisTransferData runs asynchronously and calls NdisDataTransferComplete
when finished. My FIFO is designed such that once a buffer has been
written to, it increments the InIndex so the next buffer will subsequently
be used. Therefore I can only increment this index once
NdisDataTransferComplete is called. If another packet is indicated from
NDIS and a sencond NdisTransferData call is made before the first one is
finished, then it will overwrite the first one’s buffer. How can I prevent
this? Should I use a spinlock? Or should I simply increment the InIndex
immediately inside the ProtocolReceive routine as soon as I have that
buffer’s address? Are there better alternatives to my FIFO structure?
The reason I am implementing the FIFO is so that incoming packets get
queued instead of just being dropped if there are no pending read
requests. I have tried other methods instead, eg. loading the driver with
many read requests from my user-mode application (to prevent the driver
from dropping packets), but have found the results somewhat
unpredicatable.
I am also trying to ensure that incoming packets get queued in the FIFO in
the exact order in which they were received from the network.
Any help would be very much appreciated!!
Thanks
Aharon