I don’t see you calling NdisAllocateBuffer, or NdisChainBufferAtFront. How
are you hooking the new buffer to
your new packet descriptor?
Also, your packet calculations may not work all the time. Look through
TCP/IP Illustrated by Stevens for
a complete description of the different types of ethernet header. 802.3
versus DIX to be exact.
-Jeff
-----Original Message-----
From: vinaya chandra [mailto:xxxxx@yahoo.com]
Sent: Friday, September 26, 2003 7:19 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] NDIS Intrmediate Filter Driver Question.
HI ALL,
We are writing some ndis Im driver.
Our objective is to encrypt the data before sending to miniport driver.
We modified MPSend function of the passthru sample.
We encripted the data in this function before calling NDISSend api.
We recalulated the IP and TCP checksums too.
We were able to install my driver and we have written a socket sample to
check the functionality.
On one machine we installed our driver and on other machine we haven’t.
We expected that socket program running on destination machine will receive
encrypted data . But this is not happening.
It is getting original data(data before encryption).
Here with we are attaching code snapshot .
Please let us know what cause the problem.
-
Can we change data content pointing at virtual address in the new packet
what we created?
-
or do we need to call
NdisAllocatememorywithTag(),NdisAllocateBuffer(),NdisChainBufferAtFront() in
sequence ?..before calling NdisSend() ?
-
Where can we get the information about developing NDIS Intermediate
Driver ?..tutorials ?..NDIS IM Driver(Encryption/decryption) samples ?
here is the Code snip.
NDIS_STATUS
MPSend(
IN NDIS_HANDLE MiniportAdapterContext,
IN PNDIS_PACKET Packet,
IN UINT Flags
)
/*++
Routine Description:
Send handler. Just re-wrap the packet and send it below. Re-wrapping is
necessary since
NDIS uses the WrapperReserved for its own use.
LBFO- All sends will be done in the secondary miniport of the bundle.
We are using the Secondary Miniport as the Send path. All sends should use
that pAdapt structure.
Arguments:
MiniportAdapterContext Pointer to the adapter
Packet Packet to send
Flags Unused, passed down below
Return Value:
Return code from NdisSend
–*/
{
PADAPT pAdapt = (PADAPT)MiniportAdapterContext;
NDIS_STATUS Status;
PNDIS_PACKET MyPacket;
PRSVD Rsvd;
PVOID MediaSpecificInfo = NULL;
ULONG MediaSpecificInfoSize = 0;
// ADDED BY CAIR
// retrieve the IP packet header information
#define szPayloadCopy ETH_MAX_PACKET_SIZE
char PayloadCopy[szPayloadCopy];
pEthHdr pETH;
pIPHdr pIPH;
pTCPHdr pTCPH;
pEncapPktHdr pEncPkt;
NDIS_STATUS lclStatus;
USHORT usIPHdr,usTCPHdr,usNewHdrs;
ULONG ulOrigPayload;
//
// According to our LBFO design, all sends will be performed on the
secondary miniport
// However, the must be completed on the primary’s miniport handle
//
ASSERT (pAdapt->pSecondaryAdapt);
pAdapt = pAdapt->pSecondaryAdapt;
if (IsIMDeviceStateOn (pAdapt) == FALSE)
{
return NDIS_STATUS_FAILURE;
}
NdisAllocatePacket(&Status,
&MyPacket,
pAdapt->SendPacketPoolHandle);
if (Status == NDIS_STATUS_SUCCESS)
{
PNDIS_PACKET_EXTENSION Old, New;
Rsvd = (PRSVD)(MyPacket->ProtocolReserved);
Rsvd->OriginalPkt = Packet;
MyPacket->Private.Flags = Flags;
MyPacket->Private.Head = Packet->Private.Head;
MyPacket->Private.Tail = Packet->Private.Tail;
NdisSetPacketFlags(MyPacket, NDIS_FLAGS_DONT_LOOPBACK);
//
// Copy the OOB Offset from the original packet to the new
// packet.
//
NdisMoveMemory(NDIS_OOB_DATA_FROM_PACKET(MyPacket),
NDIS_OOB_DATA_FROM_PACKET(Packet),
sizeof(NDIS_PACKET_OOB_DATA));
//
// Copy the per packet info into the new packet
// This includes ClassificationHandle, etc.
// Make sure other stuff is not copied !!!
//
NdisIMCopySendPerPacketInfo(MyPacket, Packet);
//
// Copy the Media specific information
//
NDIS_GET_PACKET_MEDIA_SPECIFIC_INFO(Packet,
&MediaSpecificInfo,
&MediaSpecificInfoSize);
if (MediaSpecificInfo || MediaSpecificInfoSize)
{
NDIS_SET_PACKET_MEDIA_SPECIFIC_INFO(MyPacket,
MediaSpecificInfo,
MediaSpecificInfoSize);
}
// ADDED BY
// retrieve the IP packet header information
GetPktPayload(MyPacket, // Copy payload
PayloadCopy, // to area.
szPayloadCopy, // Amount of space in
area.
&ulOrigPayload // Return number of
bytes in packet.
);
pIPH = (pIPHdr)(PayloadCopy + // Point to IP header in local
copy of payload.
sizeof(EthHdr));
usIPHdr = pIPH->IPHdrLen * 4; // Get length of IP header.
pTCPH = // Point t! o TCP datagram
(header + data) in local copy of payload.
(pTCPHdr)(PayloadCopy +
sizeof(EthHdr) +
usIPHdr);
usTCPHdr = pTCPH->DataOffset * 4; // Length of this TCP header,
which will be largely duplicated.
DBGPRINT(“**************NEW *****IPPACKET HEADER INFO************”);
{
char msg[256];
// char TempMsg[256];
memset(msg,0,256);
// memset(TempMsg,0,256);
sprintf(msg,“Total Length %d”,pIPH->TotalLength);
DBGPRINT(msg);
sprintf(msg,“Source Address %u”,pIPH->SourceAddress);
DBGPRINT(msg);
sprintf(msg,“Destination Address %u”,pIPH->DestinationAddress);
DBGPRINT(msg);
if(pIPH->DestinationAddress == 2868904065)
{
UCHAR Data[256];
UCHAR Data1[256];
UCHAR Data2[256];
PUCHAR pData ;
ULONG ulDataLen;
DBGPRINT(“SENDING PACKET TO GFPC005”);
ulDataLen = ulOrigPayload - sizeof(EthHdr) - usIPHdr - usTCPHdr;
sprintf(msg,“Data Length %u”,ulDataLen-1);
DBGPRINT(msg);
if((int)ulDataLen != 0)
{
UINT index = 0;
pData = (char *)(pTCPH+usTCPHdr);
memcpy(Data,pData+1,ulDataLen-3);
DBGPRINT(“*** NEW DISPLAYING SOCKET DATA****”);
sprintf(msg,“The Socket Data is %s”,Data);
DBGPRINT(msg);
DBGPRINT(“%s”,Data);
DBGPRINT(“**************NEW BEFORE ENCRYPTION *****”);
sprintf(msg,“%s”,Data);
DBGPRINT(msg);
DbgPrint(“%s”,pData);
for(index ; index < ulDataLen-3;index++)
{
pData[index + 1] = pData[index + 1] + 1;
}
DBGPRINT(“**************NEW AFTER ENCRIPTION *****”);
sprintf(msg,“%s”,Data);
DBGPRINT(msg);
DbgPrint(“%s”,pData);
sprintf(msg," Old IP Checksum is %u",pIPH->Checksum);
DBGPRINT(msg);
sprintf(msg," Old TCP Checksum is %u",pTCPH->Checksum);
DBGPRINT(msg);
DBGPRINT(“**************RECALCULATING CHECKSUMS *****”);
pIPH->Checksum = 0; // Clear old IP
checksum value.
pIPH->Checksum = // Get new IP checksum value,
which depends on new IP header only.
GetIPChecksum((PUSHORT)pIPH, usIPHdr);
sprintf(msg," new IP Checksum is %u",pIPH->Checksum);
DBGPRINT(msg);
pTCPH->Checksum = 0; // Clear TCP checksum.
pTCPH->Checksum = // Get new TCP checksum.
GetTCPChecksum((PUSHORT)pTCPH,
(PUSHORT)&pIPH->SourceAddress,
(PUSHORT)&pIPH->DestinationAddress,
(USHORT)(RtlUshortByteSwap(pIPH->TotalLeng!
th) - usIPHdr)
);
sprintf(msg," new TCP Checksum is %u",pTCPH->Checksum);
DBGPRINT(msg);
}
}
DBGPRINT(“**************NEW IPPACKET HEADER INFO END*********”);
}
// CAIR END
NdisSend(&Status,
pAdapt->BindingHandle,
MyPacket);
if (Status != NDIS_STATUS_PENDING)
{
NdisIMCopySendCompletePerPacketInfo (Packet, MyPacket);
NdisFreePacket(MyPacket);
}
}
else
{
//
// We are out of packets. Silently drop it. Alternatively we can deal with
it:
// - By keeping separate send and receive pools
// - Dynamically allocate more pools as needed and free them when not
needed
//
}
return(Status);
}
Thanks in advance.
Nayak Vinay.
Bangalore
Do you Yahoo!?
The
http:%2Csec%3Amail> New Yahoo! Shopping - with improved product search —
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 You are currently subscribed to
ntdev as: xxxxx@concord.com To unsubscribe send a blank email to
xxxxx@lists.osr.com
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
This footnote also confirms that this email message has been swept by
the latest virus scan software available for the presence of computer
viruses.
</http:>