wirelessboy
驱动牛犊
驱动牛犊
  • 注册日期2002-04-21
  • 最后登录2003-12-17
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1903回复:4

刚刚写了一个MPSend对发送数据加密的程序模板,大家讨论一下有没有什么错误

楼主#
更多 发布于:2002-05-13 14:16
NDIS_STATUS
   MiniportSend(
       IN NDIS_HANDLE MiniportAdapterContext,
       IN PNDIS_PACKET Packet,
       IN UINT Flags
       )
{
PADAPT pAdapt = (PADAPT)MiniportAdapterContext;
NDIS_STATUS Status;
PNDIS_PACKET MyPacket;
PRSVD Rsvd;
PVOID MediaSpecificInfo = NULL;
ULONG MediaSpecificInfoSize = 0;

//
// Other variables
//
PVOID MemoryVA;
UINT BufferCount;
UINT TotalPacketLength;
PNDIS_BUFFER CurrentBuffer;
UINT CurrentBufferLength;
PVOID CurrentBufferVA;
PUCHAR TempVA = NULL;
PNDIS_BUFFER PktBuffer;
PNDIS_HANDLE PktBufferPool;
NDIS_PHYSICAL_ADDRESS HighestAcceptableAddress;

//
//  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)
{
//
// 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
//

//
// Output debug information
//
DbgPrint(\"\\n* Debug Report @ MPSend: NdisAllocatePacket dose not renturn NDIS_STATUS_SUCCESS\\n\");
DbgPrint(\"and MPSend will return NDIS_STATUS_FAILURE\\n\");

return (NDIS_STATUS_FAILURE);
}

//
// Get information from the packet received from up-protocol
//
NdisQueryPacket(Packet,
NULL,
BufferCount,
&CurrentBuffer,
&TotalPacketLength);

if(!BufferCount)
{
//
// Output debug information
//
DbgPrint(\"\\n* Debug Report @ MPSend: BufferCount of Packet is 0,\\n\");
DbgPrint(\"and MPSend will return NDIS_STATUS_FAILURE\\n\");

return (NDIS_STATUS_FAILURE);
}

//
// Allocate memory with NdisAllocateMemory
//
HighestAcceptableAddress.LowPart = -1;
HighestAcceptableAddress.HighPart = -1;
Status = NdisAllocateMemory(&MemoryVA,
TotalPacketLength, //Maybe add a checksum length
0,
HighestAcceptableAddress);
if(Status == NDIS_STATUS_FAILURE)
{
//
// Output debug information
//
DbgPrint(\"\\n* Debug Report @ MPSend: NdisAllocateMemory returns NDIS_STATUS_FAILURE,\\n\");
DbgPrint(\"and MPSend will return NDIS_STATUS_FAILURE\\n\");

return (NDIS_STATUS_FAILURE);
}

//
// Allocate buffer-pool
//
NdisAllocateBufferPool(&Status,
PktBufferPool,
1);

//
// Allocate buffer
//
NdisAllocateBuffer(&Status,
&PktBuffer,
PktBufferPool,
MemoryVA,
TotalPacketLength);//Maybe add a checksum length
if(Status == NDIS_STATUS_FAILURE)
{
//
// Release the memory
//
NdisFreeMemory(MemoryVA,
TotalPacketLength, //Maybe add a checksum length
0);

//
// Output debug information
//
DbgPrint(\"\\n* Debug Report @ MPSend: NdisAllocateBuffer returns NDIS_STATUS_FAILURE,\\n\");
DbgPrint(\"and MPSend will return NDIS_STATUS_FAILURE\\n\");

return (NDIS_STATUS_FAILURE);
}

//
// Copy the packet to the buffer
//
TempVA = (PUCHAR)MemoryVA;
NdisQueryBuffer(CurrentBuffer, &CurrentBufferVA, &CurrentBufferLength);
while(CurrentBuffer != NULL)
{
NdisMoveMemory(TempVA, CurrentBufferVA, CurrentBufferLength);
TempVA = (PUCHAR)TempVA + CurrentBufferLength;
NdisGetNextBuffer(CurrentBuffer, &CurrentBuffer);
if(CurrentBuffer == NULL)
break;
NdisQueryBuffer(CurrentBuffer, &CurrentBufferVA, &CurrentBufferLength);
}

//
// TODO ...
//

//
// Chain the buffer to Mypacket
//
NdisChainBufferAtBack(MyPacket,PktBuffer);

//
// Set the attribute of the packet
//
PNDIS_PACKET_EXTENSION Old, New;

Rsvd = (PRSVD)(MyPacket->ProtocolReserved);
Rsvd->OriginalPkt = Packet;
MyPacket->Private.Flags = Flags;

MyPacket->Private.Head = PktBuffer;
MyPacket->Private.Tail = PktBuffer;
NdisSetPacketFlags(MyPacket, NDIS_FLAGS_DONT_LOOPBACK);

//
// Copy the per packet info into the new packet
// This includes ClassificationHandle, etc.
// Make sure other stuff is not copied !!!
//
Old = NDIS_PACKET_EXTENSION_FROM_PACKET(Packet);
New = NDIS_PACKET_EXTENSION_FROM_PACKET(MyPacket);

New->NdisPacketInfo[TcpIpChecksumPacketInfo] = Old->NdisPacketInfo[TcpIpChecksumPacketInfo];
New->NdisPacketInfo[IpSecPacketInfo] = Old->NdisPacketInfo[IpSecPacketInfo];
New->NdisPacketInfo[TcpLargeSendPacketInfo] = Old->NdisPacketInfo[TcpLargeSendPacketInfo];
New->NdisPacketInfo[ClassificationHandlePacketInfo] = Old->NdisPacketInfo[ClassificationHandlePacketInfo];
New->NdisPacketInfo[Ieee8021pPriority] = Old->NdisPacketInfo[Ieee8021pPriority];

//
// 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);
}


NdisSend(&Status,
pAdapt->BindingHandle,
MyPacket);

if(Status != NDIS_STATUS_PENDING)
{
NdisUnchainBufferAtBack(MyPacket,&PktBuffer);
NdisFreeBuffer(PktBuffer);
NdisFreeBufferPool(PktBufferPool);
NdisFreeMemory(MemoryVA,
TotalPacketLength, //Maybe add a checksum length
0);
NdisFreePacket(MyPacket);
}

return (Status);
}


cp_swust
驱动牛犊
驱动牛犊
  • 注册日期2002-04-16
  • 最后登录2003-03-12
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2002-05-17 10:07
   看你的称呼,你是不是做无线的。我也是做wlan的网卡的加密传送的毕业设计的,希望以后多交流,我的email:cp_swust@163.com.不过我是新手,水平较差,希望能多向你请教。
   你作加密有无考虑接受方的解密问题,否则怎么通信?  
blue
驱动大牛
驱动大牛
  • 注册日期2001-04-25
  • 最后登录2010-10-15
  • 粉丝0
  • 关注0
  • 积分55分
  • 威望12点
  • 贡献值0点
  • 好评度4点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2002-05-17 10:59
你这里已经用
    NdisChainBufferAtBack(MyPacket,PktBuffer);
就不要再用    
MyPacket->Private.Head = PktBuffer;
    MyPacket->Private.Tail = PktBuffer;
胡大侠也说过\"对使用MyPacket->Private.Head = 很不解\",再说你看它Private,这是个私有的,最好就不要去直接赋值了。
另外,你如加密,就会扩张,你打算怎么解决?是分片还是改MTU?
我现在分片,但一造一个新包,就会出很多问题!唉...
moqingsong
论坛版主
论坛版主
  • 注册日期2002-04-07
  • 最后登录2011-02-03
  • 粉丝0
  • 关注0
  • 积分74分
  • 威望71点
  • 贡献值0点
  • 好评度10点
  • 原创分0分
  • 专家分0分
地板#
发布于:2002-05-17 14:53
数据报发送正确吗?
按第一贴的“给分”键,给分。
wirelessboy
驱动牛犊
驱动牛犊
  • 注册日期2002-04-21
  • 最后登录2003-12-17
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2002-05-17 16:45
这段代码可能是我的一个早期的版本,用ddk编译的时候可能会出现一些错误,更正之后就可以用了
游客

返回顶部