协议驱动的开发流程:
首先,一个协议驱动调用函数ndisRegisterProtocol()先把自己注册为协议驱动,此举的意义告诉windows,我是一个ndis协议驱动,并将约定好的回调函数的列表告诉windows,这样以后当有与网络相关的事件发生时,windows会调用相应的回调函数,并且在参数中传入适当的信息,当然这些回调函数是我们要自己实现的。
NdisRegisterProtocol(
(PNDIS_STATUS)&status,
&Globals.NdisProtocolHandle,
&protocolChar,
sizeof(NDIS50_PROTOCOL_CHARACTERISTICS));
其中,第三个参数protocolChar中存放的是一系列的回调函数指针,
protocolChar.MajorNdisVersion = 5;
protocolChar.MinorNdisVersion = 0;
protocolChar.Name = protoName;
protocolChar.OpenAdapterCompleteHandler = NdisProtOpenAdapterComplete;
protocolChar.CloseAdapterCompleteHandler = NdisProtCloseAdapterComplete;
protocolChar.SendCompleteHandler = NdisProtSendComplete;
protocolChar.TransferDataCompleteHandler = NdisProtTransferDataComplete;
protocolChar.ResetCompleteHandler = NdisProtResetComplete;
protocolChar.RequestCompleteHandler = NdisProtRequestComplete;
protocolChar.ReceiveHandler = NdisProtReceive; //当网卡接到数据时,系统会
//调用此函数或者ReceivePacketHandler,把接收到的数据传进来。
protocolChar.ReceiveCompleteHandler = NdisProtReceiveComplete;
protocolChar.StatusHandler = NdisProtStatus;
protocolChar.StatusCompleteHandler = NdisProtStatusComplete;
protocolChar.BindAdapterHandler = NdisProtBindAdapter;//当系统发现一个网卡时,调用//此函数。传入网卡信息。
protocolChar.UnbindAdapterHandler = NdisProtUnbindAdapter;
protocolChar.UnloadHandler = NULL;
protocolChar.ReceivePacketHandler = NdisProtReceivePacket;//当网卡接到数据时,系统会//调用此函数或者NdisProtReceive,把接收到的数据传进来。
protocolChar.PnPEventHandler = NdisProtPnPEventHandler;
NdisRegisterProtocol()的第二个参数Globals.NdisProtocolHandle(NDIS_HANDLE)中保存的系统返回的ndis_handle, Pointer to a caller-supplied variable in which thisfunction returns a handle representing the registered driver.
但是这个参数在后面并没有什么用。
回调函数详解:
VOID
NdisProtBindAdapter(
OUT PNDIS_STATUS pStatus,
IN NDIS_HANDLE