From a6a16b4403951d0108724160ba7b9593f77e4aaa Mon Sep 17 00:00:00 2001 From: Luigi Rizzo Date: Mon, 22 Sep 2014 15:17:01 +0200 Subject: [PATCH] remove internal files --- modified_passthru/miniport.c | 1481 ---------------------------- modified_passthru/passthru.c | 469 --------- modified_passthru/passthru.h | 500 ---------- modified_passthru/precomp.h | 11 - modified_passthru/protocol.c | 1670 -------------------------------- original_passthru/makefile | 22 - original_passthru/miniport.c | 1461 ---------------------------- original_passthru/netsf.inf | 165 ---- original_passthru/netsf_m.inf | 93 -- original_passthru/passthru.c | 458 --------- original_passthru/passthru.h | 477 --------- original_passthru/passthru.htm | 486 ---------- original_passthru/passthru.rc | 41 - original_passthru/precomp.h | 11 - original_passthru/protocol.c | 1626 ------------------------------- original_passthru/sources | 39 - 16 files changed, 9010 deletions(-) delete mode 100644 modified_passthru/miniport.c delete mode 100644 modified_passthru/passthru.c delete mode 100644 modified_passthru/passthru.h delete mode 100644 modified_passthru/precomp.h delete mode 100644 modified_passthru/protocol.c delete mode 100644 original_passthru/makefile delete mode 100644 original_passthru/miniport.c delete mode 100644 original_passthru/netsf.inf delete mode 100644 original_passthru/netsf_m.inf delete mode 100644 original_passthru/passthru.c delete mode 100644 original_passthru/passthru.h delete mode 100644 original_passthru/passthru.htm delete mode 100644 original_passthru/passthru.rc delete mode 100644 original_passthru/precomp.h delete mode 100644 original_passthru/protocol.c delete mode 100644 original_passthru/sources diff --git a/modified_passthru/miniport.c b/modified_passthru/miniport.c deleted file mode 100644 index 3baff88..0000000 --- a/modified_passthru/miniport.c +++ /dev/null @@ -1,1481 +0,0 @@ -/*++ - -Copyright (c) 1992-2000 Microsoft Corporation - -Module Name: - - miniport.c - -Abstract: - - Ndis Intermediate Miniport driver sample. This is a passthru driver. - -Author: - -Environment: - - -Revision History: - - ---*/ - -#include "precomp.h" -#pragma hdrstop - - - -NDIS_STATUS -MPInitialize( - OUT PNDIS_STATUS OpenErrorStatus, - OUT PUINT SelectedMediumIndex, - IN PNDIS_MEDIUM MediumArray, - IN UINT MediumArraySize, - IN NDIS_HANDLE MiniportAdapterHandle, - IN NDIS_HANDLE WrapperConfigurationContext - ) -/*++ - -Routine Description: - - This is the initialize handler which gets called as a result of - the BindAdapter handler calling NdisIMInitializeDeviceInstanceEx. - The context parameter which we pass there is the adapter structure - which we retrieve here. - - Arguments: - - OpenErrorStatus Not used by us. - SelectedMediumIndex Place-holder for what media we are using - MediumArray Array of ndis media passed down to us to pick from - MediumArraySize Size of the array - MiniportAdapterHandle The handle NDIS uses to refer to us - WrapperConfigurationContext For use by NdisOpenConfiguration - -Return Value: - - NDIS_STATUS_SUCCESS unless something goes wrong - ---*/ -{ - UINT i; - PADAPT pAdapt; - NDIS_STATUS Status = NDIS_STATUS_FAILURE; - NDIS_MEDIUM Medium; - - UNREFERENCED_PARAMETER(WrapperConfigurationContext); - - do - { - // - // Start off by retrieving our adapter context and storing - // the Miniport handle in it. - // - pAdapt = NdisIMGetDeviceContext(MiniportAdapterHandle); - pAdapt->MiniportIsHalted = FALSE; - - DBGPRINT(("==> Miniport Initialize: Adapt %p\n", pAdapt)); - - // - // Usually we export the medium type of the adapter below as our - // virtual miniport's medium type. However if the adapter below us - // is a WAN device, then we claim to be of medium type 802.3. - // - Medium = pAdapt->Medium; - - if (Medium == NdisMediumWan) - { - Medium = NdisMedium802_3; - } - - for (i = 0; i < MediumArraySize; i++) - { - if (MediumArray[i] == Medium) - { - *SelectedMediumIndex = i; - break; - } - } - - if (i == MediumArraySize) - { - Status = NDIS_STATUS_UNSUPPORTED_MEDIA; - break; - } - - - // - // Set the attributes now. NDIS_ATTRIBUTE_DESERIALIZE enables us - // to make up-calls to NDIS without having to call NdisIMSwitchToMiniport - // or NdisIMQueueCallBack. This also forces us to protect our data using - // spinlocks where appropriate. Also in this case NDIS does not queue - // packets on our behalf. Since this is a very simple pass-thru - // miniport, we do not have a need to protect anything. However in - // a general case there will be a need to use per-adapter spin-locks - // for the packet queues at the very least. - // - NdisMSetAttributesEx(MiniportAdapterHandle, - pAdapt, - 0, // CheckForHangTimeInSeconds - NDIS_ATTRIBUTE_IGNORE_PACKET_TIMEOUT | - NDIS_ATTRIBUTE_IGNORE_REQUEST_TIMEOUT| - NDIS_ATTRIBUTE_INTERMEDIATE_DRIVER | - NDIS_ATTRIBUTE_DESERIALIZE | - NDIS_ATTRIBUTE_NO_HALT_ON_SUSPEND, - 0); - - pAdapt->MiniportHandle = MiniportAdapterHandle; - // - // Initialize LastIndicatedStatus to be NDIS_STATUS_MEDIA_CONNECT - // - pAdapt->LastIndicatedStatus = NDIS_STATUS_MEDIA_CONNECT; - - // - // Initialize the power states for both the lower binding (PTDeviceState) - // and our miniport edge to Powered On. - // - pAdapt->MPDeviceState = NdisDeviceStateD0; - pAdapt->PTDeviceState = NdisDeviceStateD0; - - // - // Add this adapter to the global pAdapt List - // - NdisAcquireSpinLock(&GlobalLock); - - pAdapt->Next = pAdaptList; - pAdaptList = pAdapt; - - NdisReleaseSpinLock(&GlobalLock); - - // - // Create an ioctl interface - // - (VOID)PtRegisterDevice(); - - Status = NDIS_STATUS_SUCCESS; - } - while (FALSE); - - // - // If we had received an UnbindAdapter notification on the underlying - // adapter, we would have blocked that thread waiting for the IM Init - // process to complete. Wake up any such thread. - // - ASSERT(pAdapt->MiniportInitPending == TRUE); - pAdapt->MiniportInitPending = FALSE; - NdisSetEvent(&pAdapt->MiniportInitEvent); - - if (Status == NDIS_STATUS_SUCCESS) - { - PtReferenceAdapt(pAdapt); - } - - DBGPRINT(("<== Miniport Initialize: Adapt %p, Status %x\n", pAdapt, Status)); - - *OpenErrorStatus = Status; - - - return Status; -} - - -NDIS_STATUS -MPSend( - IN NDIS_HANDLE MiniportAdapterContext, - IN PNDIS_PACKET Packet, - IN UINT Flags - ) -/*++ - -Routine Description: - - Send Packet handler. Either this or our SendPackets (array) handler is called - based on which one is enabled in our Miniport Characteristics. - -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; - PVOID MediaSpecificInfo = NULL; - ULONG MediaSpecificInfoSize = 0; - - // - // The driver should fail the send if the virtual miniport is in low - // power state - // - if (pAdapt->MPDeviceState > NdisDeviceStateD0) - { - return NDIS_STATUS_FAILURE; - } - -#ifdef NDIS51 - // - // Use NDIS 5.1 packet stacking: - // - if (0) // XXX IPFW - make sure we don't go in here - { - PNDIS_PACKET_STACK pStack; - BOOLEAN Remaining; - - // - // Packet stacks: Check if we can use the same packet for sending down. - // - - pStack = NdisIMGetCurrentPacketStack(Packet, &Remaining); - if (Remaining) - { - // - // We can reuse "Packet". - // - // NOTE: if we needed to keep per-packet information in packets - // sent down, we can use pStack->IMReserved[]. - // - ASSERT(pStack); - // - // If the below miniport is going to low power state, stop sending down any packet. - // - NdisAcquireSpinLock(&pAdapt->Lock); - if (pAdapt->PTDeviceState > NdisDeviceStateD0) - { - NdisReleaseSpinLock(&pAdapt->Lock); - return NDIS_STATUS_FAILURE; - } - pAdapt->OutstandingSends++; - NdisReleaseSpinLock(&pAdapt->Lock); - NdisSend(&Status, - pAdapt->BindingHandle, - Packet); - - if (Status != NDIS_STATUS_PENDING) - { - ADAPT_DECR_PENDING_SENDS(pAdapt); - } - - return(Status); - } - } -#endif // NDIS51 - - // - // We are either not using packet stacks, or there isn't stack space - // in the original packet passed down to us. Allocate a new packet - // to wrap the data with. - // - // - // If the below miniport is going to low power state, stop sending down any packet. - // - NdisAcquireSpinLock(&pAdapt->Lock); - if (pAdapt->PTDeviceState > NdisDeviceStateD0) - { - NdisReleaseSpinLock(&pAdapt->Lock); - return NDIS_STATUS_FAILURE; - - } - pAdapt->OutstandingSends++; - NdisReleaseSpinLock(&pAdapt->Lock); - - NdisAllocatePacket(&Status, - &MyPacket, - pAdapt->SendPacketPoolHandle); - - if (Status == NDIS_STATUS_SUCCESS) - { - PSEND_RSVD SendRsvd; - - // - // Save a pointer to the original packet in our reserved - // area in the new packet. This is needed so that we can - // get back to the original packet when the new packet's send - // is completed. - // - SendRsvd = (PSEND_RSVD)(MyPacket->ProtocolReserved); - SendRsvd->OriginalPkt = Packet; - - NdisGetPacketFlags(MyPacket) = Flags; - - // - // Set up the new packet so that it describes the same - // data as the original packet. - // - NDIS_PACKET_FIRST_NDIS_BUFFER(MyPacket) = NDIS_PACKET_FIRST_NDIS_BUFFER(Packet); - NDIS_PACKET_LAST_NDIS_BUFFER(MyPacket) = NDIS_PACKET_LAST_NDIS_BUFFER(Packet); -#ifdef WIN9X - // - // Work around the fact that NDIS does not initialize this - // to FALSE on Win9x. - // - NDIS_PACKET_VALID_COUNTS(MyPacket) = FALSE; -#endif - - // - // 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)); - -#ifndef WIN9X - // - // Copy the right parts of per packet info into the new packet. - // This API is not available on Win9x since task offload is - // not supported on that platform. - // - NdisIMCopySendPerPacketInfo(MyPacket, Packet); -#endif - - // - // 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); - } -#if 1 /* IPFW: query the firewall */ - /* if dummynet keeps the packet, we mimic success. - * otherwise continue as usual. - */ - { - int ret = ipfw2_qhandler_w32(MyPacket, OUTGOING, - MiniportAdapterContext); - if (ret != PASS) { - if (ret == DROP) - return NDIS_STATUS_FAILURE; - else { //dummynet kept the packet -#ifndef WIN9X - NdisIMCopySendCompletePerPacketInfo (Packet, MyPacket); -#endif - return NDIS_STATUS_SUCCESS; //otherwise simply continue - } - } - } -#endif /* end of IPFW code */ - - NdisSend(&Status, - pAdapt->BindingHandle, - MyPacket); - - - if (Status != NDIS_STATUS_PENDING) - { -#ifndef WIN9X - NdisIMCopySendCompletePerPacketInfo (Packet, MyPacket); -#endif - NdisFreePacket(MyPacket); - ADAPT_DECR_PENDING_SENDS(pAdapt); - } - } - else - { - ADAPT_DECR_PENDING_SENDS(pAdapt); - // - // 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); -} - - -VOID -MPSendPackets( - IN NDIS_HANDLE MiniportAdapterContext, - IN PPNDIS_PACKET PacketArray, - IN UINT NumberOfPackets - ) -/*++ - -Routine Description: - - Send Packet Array handler. Either this or our SendPacket handler is called - based on which one is enabled in our Miniport Characteristics. - -Arguments: - - MiniportAdapterContext Pointer to our adapter - PacketArray Set of packets to send - NumberOfPackets Self-explanatory - -Return Value: - - None - ---*/ -{ - PADAPT pAdapt = (PADAPT)MiniportAdapterContext; - NDIS_STATUS Status; - UINT i; - PVOID MediaSpecificInfo = NULL; - UINT MediaSpecificInfoSize = 0; - - - for (i = 0; i < NumberOfPackets; i++) - { - PNDIS_PACKET Packet, MyPacket; - - Packet = PacketArray[i]; - // - // The driver should fail the send if the virtual miniport is in low - // power state - // - if (pAdapt->MPDeviceState > NdisDeviceStateD0) - { - NdisMSendComplete(ADAPT_MINIPORT_HANDLE(pAdapt), - Packet, - NDIS_STATUS_FAILURE); - continue; - } - -#ifdef NDIS51 - - // - // Use NDIS 5.1 packet stacking: - // - { - PNDIS_PACKET_STACK pStack; - BOOLEAN Remaining; - - // - // Packet stacks: Check if we can use the same packet for sending down. - // - pStack = NdisIMGetCurrentPacketStack(Packet, &Remaining); - if (Remaining) - { - // - // We can reuse "Packet". - // - // NOTE: if we needed to keep per-packet information in packets - // sent down, we can use pStack->IMReserved[]. - // - ASSERT(pStack); - // - // If the below miniport is going to low power state, stop sending down any packet. - // - NdisAcquireSpinLock(&pAdapt->Lock); - if (pAdapt->PTDeviceState > NdisDeviceStateD0) - { - NdisReleaseSpinLock(&pAdapt->Lock); - NdisMSendComplete(ADAPT_MINIPORT_HANDLE(pAdapt), - Packet, - NDIS_STATUS_FAILURE); - } - else - { - pAdapt->OutstandingSends++; - NdisReleaseSpinLock(&pAdapt->Lock); - - NdisSend(&Status, - pAdapt->BindingHandle, - Packet); - - if (Status != NDIS_STATUS_PENDING) - { - NdisMSendComplete(ADAPT_MINIPORT_HANDLE(pAdapt), - Packet, - Status); - - ADAPT_DECR_PENDING_SENDS(pAdapt); - } - } - continue; - } - } -#endif - do - { - NdisAcquireSpinLock(&pAdapt->Lock); - // - // If the below miniport is going to low power state, stop sending down any packet. - // - if (pAdapt->PTDeviceState > NdisDeviceStateD0) - { - NdisReleaseSpinLock(&pAdapt->Lock); - Status = NDIS_STATUS_FAILURE; - break; - } - pAdapt->OutstandingSends++; - NdisReleaseSpinLock(&pAdapt->Lock); - - NdisAllocatePacket(&Status, - &MyPacket, - pAdapt->SendPacketPoolHandle); - - if (Status == NDIS_STATUS_SUCCESS) - { - PSEND_RSVD SendRsvd; - - SendRsvd = (PSEND_RSVD)(MyPacket->ProtocolReserved); - SendRsvd->OriginalPkt = Packet; - - NdisGetPacketFlags(MyPacket) = NdisGetPacketFlags(Packet); - - NDIS_PACKET_FIRST_NDIS_BUFFER(MyPacket) = NDIS_PACKET_FIRST_NDIS_BUFFER(Packet); - NDIS_PACKET_LAST_NDIS_BUFFER(MyPacket) = NDIS_PACKET_LAST_NDIS_BUFFER(Packet); -#ifdef WIN9X - // - // Work around the fact that NDIS does not initialize this - // to FALSE on Win9x. - // - NDIS_PACKET_VALID_COUNTS(MyPacket) = FALSE; -#endif // WIN9X - - // - // Copy the OOB data 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 relevant parts of the per packet info into the new packet - // -#ifndef WIN9X - NdisIMCopySendPerPacketInfo(MyPacket, Packet); -#endif - - // - // 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) - { -#ifndef WIN9X - NdisIMCopySendCompletePerPacketInfo (Packet, MyPacket); -#endif - NdisFreePacket(MyPacket); - ADAPT_DECR_PENDING_SENDS(pAdapt); - } - } - else - { - // - // The driver cannot allocate a packet. - // - ADAPT_DECR_PENDING_SENDS(pAdapt); - } - } - while (FALSE); - - if (Status != NDIS_STATUS_PENDING) - { - NdisMSendComplete(ADAPT_MINIPORT_HANDLE(pAdapt), - Packet, - Status); - } - } -} - - -NDIS_STATUS -MPQueryInformation( - IN NDIS_HANDLE MiniportAdapterContext, - IN NDIS_OID Oid, - IN PVOID InformationBuffer, - IN ULONG InformationBufferLength, - OUT PULONG BytesWritten, - OUT PULONG BytesNeeded - ) -/*++ - -Routine Description: - - Entry point called by NDIS to query for the value of the specified OID. - Typical processing is to forward the query down to the underlying miniport. - - The following OIDs are filtered here: - - OID_PNP_QUERY_POWER - return success right here - - OID_GEN_SUPPORTED_GUIDS - do not forward, otherwise we will show up - multiple instances of private GUIDs supported by the underlying miniport. - - OID_PNP_CAPABILITIES - we do send this down to the lower miniport, but - the values returned are postprocessed before we complete this request; - see PtRequestComplete. - - NOTE on OID_TCP_TASK_OFFLOAD - if this IM driver modifies the contents - of data it passes through such that a lower miniport may not be able - to perform TCP task offload, then it should not forward this OID down, - but fail it here with the status NDIS_STATUS_NOT_SUPPORTED. This is to - avoid performing incorrect transformations on data. - - If our miniport edge (upper edge) is at a low-power state, fail the request. - - If our protocol edge (lower edge) has been notified of a low-power state, - we pend this request until the miniport below has been set to D0. Since - requests to miniports are serialized always, at most a single request will - be pended. - -Arguments: - - MiniportAdapterContext Pointer to the adapter structure - Oid Oid for this query - InformationBuffer Buffer for information - InformationBufferLength Size of this buffer - BytesWritten Specifies how much info is written - BytesNeeded In case the buffer is smaller than what we need, tell them how much is needed - - -Return Value: - - Return code from the NdisRequest below. - ---*/ -{ - PADAPT pAdapt = (PADAPT)MiniportAdapterContext; - NDIS_STATUS Status = NDIS_STATUS_FAILURE; - - do - { - if (Oid == OID_PNP_QUERY_POWER) - { - // - // Do not forward this. - // - Status = NDIS_STATUS_SUCCESS; - break; - } - - if (Oid == OID_GEN_SUPPORTED_GUIDS) - { - // - // Do not forward this, otherwise we will end up with multiple - // instances of private GUIDs that the underlying miniport - // supports. - // - Status = NDIS_STATUS_NOT_SUPPORTED; - break; - } - - if (Oid == OID_TCP_TASK_OFFLOAD) - { - // - // Fail this -if- this driver performs data transformations - // that can interfere with a lower driver's ability to offload - // TCP tasks. - // - // Status = NDIS_STATUS_NOT_SUPPORTED; - // break; - // - } - // - // If the miniport below is unbinding, just fail any request - // - NdisAcquireSpinLock(&pAdapt->Lock); - if (pAdapt->UnbindingInProcess == TRUE) - { - NdisReleaseSpinLock(&pAdapt->Lock); - Status = NDIS_STATUS_FAILURE; - break; - } - NdisReleaseSpinLock(&pAdapt->Lock); - // - // All other queries are failed, if the miniport is not at D0, - // - if (pAdapt->MPDeviceState > NdisDeviceStateD0) - { - Status = NDIS_STATUS_FAILURE; - break; - } - - pAdapt->Request.RequestType = NdisRequestQueryInformation; - pAdapt->Request.DATA.QUERY_INFORMATION.Oid = Oid; - pAdapt->Request.DATA.QUERY_INFORMATION.InformationBuffer = InformationBuffer; - pAdapt->Request.DATA.QUERY_INFORMATION.InformationBufferLength = InformationBufferLength; - pAdapt->BytesNeeded = BytesNeeded; - pAdapt->BytesReadOrWritten = BytesWritten; - - // - // If the miniport below is binding, fail the request - // - NdisAcquireSpinLock(&pAdapt->Lock); - - if (pAdapt->UnbindingInProcess == TRUE) - { - NdisReleaseSpinLock(&pAdapt->Lock); - Status = NDIS_STATUS_FAILURE; - break; - } - // - // If the Protocol device state is OFF, mark this request as being - // pended. We queue this until the device state is back to D0. - // - if ((pAdapt->PTDeviceState > NdisDeviceStateD0) - && (pAdapt->StandingBy == FALSE)) - { - pAdapt->QueuedRequest = TRUE; - NdisReleaseSpinLock(&pAdapt->Lock); - Status = NDIS_STATUS_PENDING; - break; - } - // - // This is in the process of powering down the system, always fail the request - // - if (pAdapt->StandingBy == TRUE) - { - NdisReleaseSpinLock(&pAdapt->Lock); - Status = NDIS_STATUS_FAILURE; - break; - } - pAdapt->OutstandingRequests = TRUE; - - NdisReleaseSpinLock(&pAdapt->Lock); - - // - // default case, most requests will be passed to the miniport below - // - NdisRequest(&Status, - pAdapt->BindingHandle, - &pAdapt->Request); - - - if (Status != NDIS_STATUS_PENDING) - { - PtRequestComplete(pAdapt, &pAdapt->Request, Status); - Status = NDIS_STATUS_PENDING; - } - - } while (FALSE); - - return(Status); - -} - - -VOID -MPQueryPNPCapabilities( - IN OUT PADAPT pAdapt, - OUT PNDIS_STATUS pStatus - ) -/*++ - -Routine Description: - - Postprocess a request for OID_PNP_CAPABILITIES that was forwarded - down to the underlying miniport, and has been completed by it. - -Arguments: - - pAdapt - Pointer to the adapter structure - pStatus - Place to return final status - -Return Value: - - None. - ---*/ - -{ - PNDIS_PNP_CAPABILITIES pPNPCapabilities; - PNDIS_PM_WAKE_UP_CAPABILITIES pPMstruct; - - if (pAdapt->Request.DATA.QUERY_INFORMATION.InformationBufferLength >= sizeof(NDIS_PNP_CAPABILITIES)) - { - pPNPCapabilities = (PNDIS_PNP_CAPABILITIES)(pAdapt->Request.DATA.QUERY_INFORMATION.InformationBuffer); - - // - // The following fields must be overwritten by an IM driver. - // - pPMstruct= & pPNPCapabilities->WakeUpCapabilities; - pPMstruct->MinMagicPacketWakeUp = NdisDeviceStateUnspecified; - pPMstruct->MinPatternWakeUp = NdisDeviceStateUnspecified; - pPMstruct->MinLinkChangeWakeUp = NdisDeviceStateUnspecified; - *pAdapt->BytesReadOrWritten = sizeof(NDIS_PNP_CAPABILITIES); - *pAdapt->BytesNeeded = 0; - - - // - // Setting our internal flags - // Default, device is ON - // - pAdapt->MPDeviceState = NdisDeviceStateD0; - pAdapt->PTDeviceState = NdisDeviceStateD0; - - *pStatus = NDIS_STATUS_SUCCESS; - } - else - { - *pAdapt->BytesNeeded= sizeof(NDIS_PNP_CAPABILITIES); - *pStatus = NDIS_STATUS_RESOURCES; - } -} - - -NDIS_STATUS -MPSetInformation( - IN NDIS_HANDLE MiniportAdapterContext, - IN NDIS_OID Oid, - __in_bcount(InformationBufferLength) IN PVOID InformationBuffer, - IN ULONG InformationBufferLength, - OUT PULONG BytesRead, - OUT PULONG BytesNeeded - ) -/*++ - -Routine Description: - - Miniport SetInfo handler. - - In the case of OID_PNP_SET_POWER, record the power state and return the OID. - Do not pass below - If the device is suspended, do not block the SET_POWER_OID - as it is used to reactivate the Passthru miniport - - - PM- If the MP is not ON (DeviceState > D0) return immediately (except for 'query power' and 'set power') - If MP is ON, but the PT is not at D0, then queue the queue the request for later processing - - Requests to miniports are always serialized - - -Arguments: - - MiniportAdapterContext Pointer to the adapter structure - Oid Oid for this query - InformationBuffer Buffer for information - InformationBufferLength Size of this buffer - BytesRead Specifies how much info is read - BytesNeeded In case the buffer is smaller than what we need, tell them how much is needed - -Return Value: - - Return code from the NdisRequest below. - ---*/ -{ - PADAPT pAdapt = (PADAPT)MiniportAdapterContext; - NDIS_STATUS Status; - - Status = NDIS_STATUS_FAILURE; - - do - { - // - // The Set Power should not be sent to the miniport below the Passthru, but is handled internally - // - if (Oid == OID_PNP_SET_POWER) - { - MPProcessSetPowerOid(&Status, - pAdapt, - InformationBuffer, - InformationBufferLength, - BytesRead, - BytesNeeded); - break; - - } - - // - // If the miniport below is unbinding, fail the request - // - NdisAcquireSpinLock(&pAdapt->Lock); - if (pAdapt->UnbindingInProcess == TRUE) - { - NdisReleaseSpinLock(&pAdapt->Lock); - Status = NDIS_STATUS_FAILURE; - break; - } - NdisReleaseSpinLock(&pAdapt->Lock); - // - // All other Set Information requests are failed, if the miniport is - // not at D0 or is transitioning to a device state greater than D0. - // - if (pAdapt->MPDeviceState > NdisDeviceStateD0) - { - Status = NDIS_STATUS_FAILURE; - break; - } - - // Set up the Request and return the result - pAdapt->Request.RequestType = NdisRequestSetInformation; - pAdapt->Request.DATA.SET_INFORMATION.Oid = Oid; - pAdapt->Request.DATA.SET_INFORMATION.InformationBuffer = InformationBuffer; - pAdapt->Request.DATA.SET_INFORMATION.InformationBufferLength = InformationBufferLength; - pAdapt->BytesNeeded = BytesNeeded; - pAdapt->BytesReadOrWritten = BytesRead; - - // - // If the miniport below is unbinding, fail the request - // - NdisAcquireSpinLock(&pAdapt->Lock); - if (pAdapt->UnbindingInProcess == TRUE) - { - NdisReleaseSpinLock(&pAdapt->Lock); - Status = NDIS_STATUS_FAILURE; - break; - } - - // - // If the device below is at a low power state, we cannot send it the - // request now, and must pend it. - // - if ((pAdapt->PTDeviceState > NdisDeviceStateD0) - && (pAdapt->StandingBy == FALSE)) - { - pAdapt->QueuedRequest = TRUE; - NdisReleaseSpinLock(&pAdapt->Lock); - Status = NDIS_STATUS_PENDING; - break; - } - // - // This is in the process of powering down the system, always fail the request - // - if (pAdapt->StandingBy == TRUE) - { - NdisReleaseSpinLock(&pAdapt->Lock); - Status = NDIS_STATUS_FAILURE; - break; - } - pAdapt->OutstandingRequests = TRUE; - - NdisReleaseSpinLock(&pAdapt->Lock); - // - // Forward the request to the device below. - // - NdisRequest(&Status, - pAdapt->BindingHandle, - &pAdapt->Request); - - if (Status != NDIS_STATUS_PENDING) - { - *BytesRead = pAdapt->Request.DATA.SET_INFORMATION.BytesRead; - *BytesNeeded = pAdapt->Request.DATA.SET_INFORMATION.BytesNeeded; - pAdapt->OutstandingRequests = FALSE; - } - - } while (FALSE); - - return(Status); -} - - -VOID -MPProcessSetPowerOid( - IN OUT PNDIS_STATUS pNdisStatus, - IN PADAPT pAdapt, - __in_bcount(InformationBufferLength) IN PVOID InformationBuffer, - IN ULONG InformationBufferLength, - OUT PULONG BytesRead, - OUT PULONG BytesNeeded - ) -/*++ - -Routine Description: - This routine does all the procssing for a request with a SetPower Oid - The miniport shoud accept the Set Power and transition to the new state - - The Set Power should not be passed to the miniport below - - If the IM miniport is going into a low power state, then there is no guarantee if it will ever - be asked go back to D0, before getting halted. No requests should be pended or queued. - - -Arguments: - pNdisStatus - Status of the operation - pAdapt - The Adapter structure - InformationBuffer - The New DeviceState - InformationBufferLength - BytesRead - No of bytes read - BytesNeeded - No of bytes needed - - -Return Value: - Status - NDIS_STATUS_SUCCESS if all the wait events succeed. - ---*/ -{ - - - NDIS_DEVICE_POWER_STATE NewDeviceState; - - DBGPRINT(("==>MPProcessSetPowerOid: Adapt %p\n", pAdapt)); - - ASSERT (InformationBuffer != NULL); - - *pNdisStatus = NDIS_STATUS_FAILURE; - - do - { - // - // Check for invalid length - // - if (InformationBufferLength < sizeof(NDIS_DEVICE_POWER_STATE)) - { - *pNdisStatus = NDIS_STATUS_INVALID_LENGTH; - break; - } - - NewDeviceState = (*(PNDIS_DEVICE_POWER_STATE)InformationBuffer); - - // - // Check for invalid device state - // - if ((pAdapt->MPDeviceState > NdisDeviceStateD0) && (NewDeviceState != NdisDeviceStateD0)) - { - // - // If the miniport is in a non-D0 state, the miniport can only receive a Set Power to D0 - // - ASSERT (!(pAdapt->MPDeviceState > NdisDeviceStateD0) && (NewDeviceState != NdisDeviceStateD0)); - - *pNdisStatus = NDIS_STATUS_FAILURE; - break; - } - - // - // Is the miniport transitioning from an On (D0) state to an Low Power State (>D0) - // If so, then set the StandingBy Flag - (Block all incoming requests) - // - if (pAdapt->MPDeviceState == NdisDeviceStateD0 && NewDeviceState > NdisDeviceStateD0) - { - pAdapt->StandingBy = TRUE; - } - - // - // If the miniport is transitioning from a low power state to ON (D0), then clear the StandingBy flag - // All incoming requests will be pended until the physical miniport turns ON. - // - if (pAdapt->MPDeviceState > NdisDeviceStateD0 && NewDeviceState == NdisDeviceStateD0) - { - pAdapt->StandingBy = FALSE; - } - - // - // Now update the state in the pAdapt structure; - // - pAdapt->MPDeviceState = NewDeviceState; - - *pNdisStatus = NDIS_STATUS_SUCCESS; - - - } while (FALSE); - - if (*pNdisStatus == NDIS_STATUS_SUCCESS) - { - // - // The miniport resume from low power state - // - if (pAdapt->StandingBy == FALSE) - { - // - // If we need to indicate the media connect state - // - if (pAdapt->LastIndicatedStatus != pAdapt->LatestUnIndicateStatus) - { - if (pAdapt->MiniportHandle != NULL) - { - NdisMIndicateStatus(pAdapt->MiniportHandle, - pAdapt->LatestUnIndicateStatus, - (PVOID)NULL, - 0); - NdisMIndicateStatusComplete(pAdapt->MiniportHandle); - pAdapt->LastIndicatedStatus = pAdapt->LatestUnIndicateStatus; - } - } - } - else - { - // - // Initialize LatestUnIndicatedStatus - // - pAdapt->LatestUnIndicateStatus = pAdapt->LastIndicatedStatus; - } - *BytesRead = sizeof(NDIS_DEVICE_POWER_STATE); - *BytesNeeded = 0; - } - else - { - *BytesRead = 0; - *BytesNeeded = sizeof (NDIS_DEVICE_POWER_STATE); - } - - DBGPRINT(("<==MPProcessSetPowerOid: Adapt %p\n", pAdapt)); -} - - -VOID -MPReturnPacket( - IN NDIS_HANDLE MiniportAdapterContext, - IN PNDIS_PACKET Packet - ) -/*++ - -Routine Description: - - NDIS Miniport entry point called whenever protocols are done with - a packet that we had indicated up and they had queued up for returning - later. - -Arguments: - - MiniportAdapterContext - pointer to ADAPT structure - Packet - packet being returned. - -Return Value: - - None. - ---*/ -{ - PADAPT pAdapt = (PADAPT)MiniportAdapterContext; - -#ifdef NDIS51 - // - // Packet stacking: Check if this packet belongs to us. - // - if (NdisGetPoolFromPacket(Packet) != pAdapt->RecvPacketPoolHandle) - { - // - // We reused the original packet in a receive indication. - // Simply return it to the miniport below us. - // - NdisReturnPackets(&Packet, 1); - } - else -#endif // NDIS51 - { - // - // This is a packet allocated from this IM's receive packet pool. - // Reclaim our packet, and return the original to the driver below. - // - - PNDIS_PACKET MyPacket; - PRECV_RSVD RecvRsvd; - - RecvRsvd = (PRECV_RSVD)(Packet->MiniportReserved); - MyPacket = RecvRsvd->OriginalPkt; - - NdisFreePacket(Packet); - NdisReturnPackets(&MyPacket, 1); - } -} - - -NDIS_STATUS -MPTransferData( - OUT PNDIS_PACKET Packet, - OUT PUINT BytesTransferred, - IN NDIS_HANDLE MiniportAdapterContext, - IN NDIS_HANDLE MiniportReceiveContext, - IN UINT ByteOffset, - IN UINT BytesToTransfer - ) -/*++ - -Routine Description: - - Miniport's transfer data handler. - -Arguments: - - Packet Destination packet - BytesTransferred Place-holder for how much data was copied - MiniportAdapterContext Pointer to the adapter structure - MiniportReceiveContext Context - ByteOffset Offset into the packet for copying data - BytesToTransfer How much to copy. - -Return Value: - - Status of transfer - ---*/ -{ - PADAPT pAdapt = (PADAPT)MiniportAdapterContext; - NDIS_STATUS Status; - - // - // Return, if the device is OFF - // - - if (IsIMDeviceStateOn(pAdapt) == FALSE) - { - return NDIS_STATUS_FAILURE; - } - - NdisTransferData(&Status, - pAdapt->BindingHandle, - MiniportReceiveContext, - ByteOffset, - BytesToTransfer, - Packet, - BytesTransferred); - - return(Status); -} - -VOID -MPHalt( - IN NDIS_HANDLE MiniportAdapterContext - ) -/*++ - -Routine Description: - - Halt handler. All the hard-work for clean-up is done here. - -Arguments: - - MiniportAdapterContext Pointer to the Adapter - -Return Value: - - None. - ---*/ -{ - PADAPT pAdapt = (PADAPT)MiniportAdapterContext; - NDIS_STATUS Status; - PADAPT *ppCursor; - - DBGPRINT(("==>MiniportHalt: Adapt %p\n", pAdapt)); - - pAdapt->MiniportHandle = NULL; - pAdapt->MiniportIsHalted = TRUE; - - // - // Remove this adapter from the global list - // - NdisAcquireSpinLock(&GlobalLock); - - for (ppCursor = &pAdaptList; *ppCursor != NULL; ppCursor = &(*ppCursor)->Next) - { - if (*ppCursor == pAdapt) - { - *ppCursor = pAdapt->Next; - break; - } - } - - NdisReleaseSpinLock(&GlobalLock); - - // - // Delete the ioctl interface that was created when the miniport - // was created. - // - (VOID)PtDeregisterDevice(); - - // - // If we have a valid bind, close the miniport below the protocol - // -#pragma prefast(suppress: __WARNING_DEREF_NULL_PTR, "pAdapt cannot be NULL") - if (pAdapt->BindingHandle != NULL) - { - // - // Close the binding below. and wait for it to complete - // - NdisResetEvent(&pAdapt->Event); - - NdisCloseAdapter(&Status, pAdapt->BindingHandle); - - if (Status == NDIS_STATUS_PENDING) - { - NdisWaitEvent(&pAdapt->Event, 0); - Status = pAdapt->Status; - } - - ASSERT (Status == NDIS_STATUS_SUCCESS); - - pAdapt->BindingHandle = NULL; - - PtDereferenceAdapt(pAdapt); - } - - if (PtDereferenceAdapt(pAdapt)) - { - pAdapt = NULL; - } - - - DBGPRINT(("<== MiniportHalt: pAdapt %p\n", pAdapt)); -} - - -#ifdef NDIS51_MINIPORT - -VOID -MPCancelSendPackets( - IN NDIS_HANDLE MiniportAdapterContext, - IN PVOID CancelId - ) -/*++ - -Routine Description: - - The miniport entry point to handle cancellation of all send packets - that match the given CancelId. If we have queued any packets that match - this, then we should dequeue them and call NdisMSendComplete for all - such packets, with a status of NDIS_STATUS_REQUEST_ABORTED. - - We should also call NdisCancelSendPackets in turn, on each lower binding - that this adapter corresponds to. This is to let miniports below cancel - any matching packets. - -Arguments: - - MiniportAdapterContext - pointer to ADAPT structure - CancelId - ID of packets to be cancelled. - -Return Value: - - None - ---*/ -{ - PADAPT pAdapt = (PADAPT)MiniportAdapterContext; - - // - // If we queue packets on our adapter structure, this would be - // the place to acquire a spinlock to it, unlink any packets whose - // Id matches CancelId, release the spinlock and call NdisMSendComplete - // with NDIS_STATUS_REQUEST_ABORTED for all unlinked packets. - // - - // - // Next, pass this down so that we let the miniport(s) below cancel - // any packets that they might have queued. - // - NdisCancelSendPackets(pAdapt->BindingHandle, CancelId); - - return; -} - -VOID -MPDevicePnPEvent( - IN NDIS_HANDLE MiniportAdapterContext, - IN NDIS_DEVICE_PNP_EVENT DevicePnPEvent, - IN PVOID InformationBuffer, - IN ULONG InformationBufferLength - ) -/*++ - -Routine Description: - - This handler is called to notify us of PnP events directed to - our miniport device object. - -Arguments: - - MiniportAdapterContext - pointer to ADAPT structure - DevicePnPEvent - the event - InformationBuffer - Points to additional event-specific information - InformationBufferLength - length of above - -Return Value: - - None ---*/ -{ - // TBD - add code/comments about processing this. - - UNREFERENCED_PARAMETER(MiniportAdapterContext); - UNREFERENCED_PARAMETER(DevicePnPEvent); - UNREFERENCED_PARAMETER(InformationBuffer); - UNREFERENCED_PARAMETER(InformationBufferLength); - - return; -} - -VOID -MPAdapterShutdown( - IN NDIS_HANDLE MiniportAdapterContext - ) -/*++ - -Routine Description: - - This handler is called to notify us of an impending system shutdown. - -Arguments: - - MiniportAdapterContext - pointer to ADAPT structure - -Return Value: - - None ---*/ -{ - UNREFERENCED_PARAMETER(MiniportAdapterContext); - - return; -} - -#endif - - -VOID -MPFreeAllPacketPools( - IN PADAPT pAdapt - ) -/*++ - -Routine Description: - - Free all packet pools on the specified adapter. - -Arguments: - - pAdapt - pointer to ADAPT structure - -Return Value: - - None - ---*/ -{ - if (pAdapt->RecvPacketPoolHandle != NULL) - { - // - // Free the packet pool that is used to indicate receives - // - NdisFreePacketPool(pAdapt->RecvPacketPoolHandle); - - pAdapt->RecvPacketPoolHandle = NULL; - } - - if (pAdapt->SendPacketPoolHandle != NULL) - { - - // - // Free the packet pool that is used to send packets below - // - - NdisFreePacketPool(pAdapt->SendPacketPoolHandle); - - pAdapt->SendPacketPoolHandle = NULL; - - } -} - diff --git a/modified_passthru/passthru.c b/modified_passthru/passthru.c deleted file mode 100644 index c366173..0000000 --- a/modified_passthru/passthru.c +++ /dev/null @@ -1,469 +0,0 @@ -/*++ - -Copyright (c) 1992-2000 Microsoft Corporation - -Module Name: - - passthru.c - -Abstract: - - Ndis Intermediate Miniport driver sample. This is a passthru driver. - -Author: - -Environment: - - -Revision History: - - ---*/ - - -#include "precomp.h" -#pragma hdrstop - -#pragma NDIS_INIT_FUNCTION(DriverEntry) - -NDIS_HANDLE ProtHandle = NULL; -NDIS_HANDLE DriverHandle = NULL; -NDIS_MEDIUM MediumArray[4] = - { - NdisMedium802_3, // Ethernet - NdisMedium802_5, // Token-ring - NdisMediumFddi, // Fddi - NdisMediumWan // NDISWAN - }; - -NDIS_SPIN_LOCK GlobalLock; - -PADAPT pAdaptList = NULL; -LONG MiniportCount = 0; - -NDIS_HANDLE NdisWrapperHandle; - -// -// To support ioctls from user-mode: -// - -#define STR2(x) #x -#define STR(x) STR2(x) -#define DOSPREFIX "\\DosDevices\\" -#define NTPREFIX "\\Device\\" -#define WIDEN2(x) L ## x -#define WIDEN(x) WIDEN2(x) -#define LINKNAME_STRING WIDEN(DOSPREFIX) WIDEN(STR(MODULENAME)) -#define NTDEVICE_STRING WIDEN(NTPREFIX) WIDEN(STR(MODULENAME)) -#define PROTOCOLNAME_STRING WIDEN(STR(MODULENAME)) - -NDIS_HANDLE NdisDeviceHandle = NULL; -PDEVICE_OBJECT ControlDeviceObject = NULL; - -enum _DEVICE_STATE -{ - PS_DEVICE_STATE_READY = 0, // ready for create/delete - PS_DEVICE_STATE_CREATING, // create operation in progress - PS_DEVICE_STATE_DELETING // delete operation in progress -} ControlDeviceState = PS_DEVICE_STATE_READY; - - - -NTSTATUS -DriverEntry( - IN PDRIVER_OBJECT DriverObject, - IN PUNICODE_STRING RegistryPath - ) -/*++ - -Routine Description: - - First entry point to be called, when this driver is loaded. - Register with NDIS as an intermediate driver. - -Arguments: - - DriverObject - pointer to the system's driver object structure - for this driver - - RegistryPath - system's registry path for this driver - -Return Value: - - STATUS_SUCCESS if all initialization is successful, STATUS_XXX - error code if not. - ---*/ -{ - NDIS_STATUS Status; - NDIS_PROTOCOL_CHARACTERISTICS PChars; - NDIS_MINIPORT_CHARACTERISTICS MChars; - NDIS_STRING Name; - - Status = NDIS_STATUS_SUCCESS; - NdisAllocateSpinLock(&GlobalLock); - - NdisMInitializeWrapper(&NdisWrapperHandle, DriverObject, RegistryPath, NULL); - - do - { - // - // Register the miniport with NDIS. Note that it is the miniport - // which was started as a driver and not the protocol. Also the miniport - // must be registered prior to the protocol since the protocol's BindAdapter - // handler can be initiated anytime and when it is, it must be ready to - // start driver instances. - // - - NdisZeroMemory(&MChars, sizeof(NDIS_MINIPORT_CHARACTERISTICS)); - - MChars.MajorNdisVersion = PASSTHRU_MAJOR_NDIS_VERSION; - MChars.MinorNdisVersion = PASSTHRU_MINOR_NDIS_VERSION; - - MChars.InitializeHandler = MPInitialize; - MChars.QueryInformationHandler = MPQueryInformation; - MChars.SetInformationHandler = MPSetInformation; - MChars.ResetHandler = NULL; - MChars.TransferDataHandler = MPTransferData; - MChars.HaltHandler = MPHalt; -#ifdef NDIS51_MINIPORT - MChars.CancelSendPacketsHandler = MPCancelSendPackets; - MChars.PnPEventNotifyHandler = MPDevicePnPEvent; - MChars.AdapterShutdownHandler = MPAdapterShutdown; -#endif // NDIS51_MINIPORT - - // - // We will disable the check for hang timeout so we do not - // need a check for hang handler! - // - MChars.CheckForHangHandler = NULL; - MChars.ReturnPacketHandler = MPReturnPacket; - - // - // Either the Send or the SendPackets handler should be specified. - // If SendPackets handler is specified, SendHandler is ignored - // - MChars.SendHandler = MPSend; // IPFW: use MPSend, not SendPackets - MChars.SendPacketsHandler = NULL; - - Status = NdisIMRegisterLayeredMiniport(NdisWrapperHandle, - &MChars, - sizeof(MChars), - &DriverHandle); - if (Status != NDIS_STATUS_SUCCESS) - { - break; - } - -#ifndef WIN9X - NdisMRegisterUnloadHandler(NdisWrapperHandle, PtUnload); -#endif - - // - // Now register the protocol. - // - NdisZeroMemory(&PChars, sizeof(NDIS_PROTOCOL_CHARACTERISTICS)); - PChars.MajorNdisVersion = PASSTHRU_PROT_MAJOR_NDIS_VERSION; - PChars.MinorNdisVersion = PASSTHRU_PROT_MINOR_NDIS_VERSION; - - // - // Make sure the protocol-name matches the service-name - // (from the INF) under which this protocol is installed. - // This is needed to ensure that NDIS can correctly determine - // the binding and call us to bind to miniports below. - // - NdisInitUnicodeString(&Name, PROTOCOLNAME_STRING); // Protocol name - PChars.Name = Name; - PChars.OpenAdapterCompleteHandler = PtOpenAdapterComplete; - PChars.CloseAdapterCompleteHandler = PtCloseAdapterComplete; - PChars.SendCompleteHandler = PtSendComplete; - PChars.TransferDataCompleteHandler = PtTransferDataComplete; - - PChars.ResetCompleteHandler = PtResetComplete; - PChars.RequestCompleteHandler = PtRequestComplete; - PChars.ReceiveHandler = PtReceive; - PChars.ReceiveCompleteHandler = PtReceiveComplete; - PChars.StatusHandler = PtStatus; - PChars.StatusCompleteHandler = PtStatusComplete; - PChars.BindAdapterHandler = PtBindAdapter; - PChars.UnbindAdapterHandler = PtUnbindAdapter; - PChars.UnloadHandler = PtUnloadProtocol; - - PChars.ReceivePacketHandler = PtReceivePacket; - PChars.PnPEventHandler= PtPNPHandler; - - NdisRegisterProtocol(&Status, - &ProtHandle, - &PChars, - sizeof(NDIS_PROTOCOL_CHARACTERISTICS)); - - if (Status != NDIS_STATUS_SUCCESS) - { - NdisIMDeregisterLayeredMiniport(DriverHandle); - break; - } - - NdisIMAssociateMiniport(DriverHandle, ProtHandle); - } - while (FALSE); - - if (Status != NDIS_STATUS_SUCCESS) - { - NdisTerminateWrapper(NdisWrapperHandle, NULL); - } - - ipfw_module_init(); // IPFW - start the system - - return(Status); -} - - -NDIS_STATUS -PtRegisterDevice( - VOID - ) -/*++ - -Routine Description: - - Register an ioctl interface - a device object to be used for this - purpose is created by NDIS when we call NdisMRegisterDevice. - - This routine is called whenever a new miniport instance is - initialized. However, we only create one global device object, - when the first miniport instance is initialized. This routine - handles potential race conditions with PtDeregisterDevice via - the ControlDeviceState and MiniportCount variables. - - NOTE: do not call this from DriverEntry; it will prevent the driver - from being unloaded (e.g. on uninstall). - -Arguments: - - None - -Return Value: - - NDIS_STATUS_SUCCESS if we successfully register a device object. - ---*/ -{ - NDIS_STATUS Status = NDIS_STATUS_SUCCESS; - UNICODE_STRING DeviceName; - UNICODE_STRING DeviceLinkUnicodeString; - PDRIVER_DISPATCH DispatchTable[IRP_MJ_MAXIMUM_FUNCTION+1]; - - DBGPRINT(("==>PtRegisterDevice\n")); - - NdisAcquireSpinLock(&GlobalLock); - - ++MiniportCount; - - if (1 == MiniportCount) - { - ASSERT(ControlDeviceState != PS_DEVICE_STATE_CREATING); - - // - // Another thread could be running PtDeregisterDevice on - // behalf of another miniport instance. If so, wait for - // it to exit. - // - while (ControlDeviceState != PS_DEVICE_STATE_READY) - { - NdisReleaseSpinLock(&GlobalLock); - NdisMSleep(1); - NdisAcquireSpinLock(&GlobalLock); - } - - ControlDeviceState = PS_DEVICE_STATE_CREATING; - - NdisReleaseSpinLock(&GlobalLock); - - - NdisZeroMemory(DispatchTable, (IRP_MJ_MAXIMUM_FUNCTION+1) * sizeof(PDRIVER_DISPATCH)); - - DispatchTable[IRP_MJ_CREATE] = PtDispatch; - DispatchTable[IRP_MJ_CLEANUP] = PtDispatch; - DispatchTable[IRP_MJ_CLOSE] = PtDispatch; - // IPFW we use DevIoControl ? - DispatchTable[IRP_MJ_DEVICE_CONTROL] = DevIoControl; - - - NdisInitUnicodeString(&DeviceName, NTDEVICE_STRING); - NdisInitUnicodeString(&DeviceLinkUnicodeString, LINKNAME_STRING); - - // - // Create a device object and register our dispatch handlers - // - - Status = NdisMRegisterDevice( - NdisWrapperHandle, - &DeviceName, - &DeviceLinkUnicodeString, - &DispatchTable[0], - &ControlDeviceObject, - &NdisDeviceHandle - ); - - NdisAcquireSpinLock(&GlobalLock); - - ControlDeviceState = PS_DEVICE_STATE_READY; - } - - NdisReleaseSpinLock(&GlobalLock); - - DBGPRINT(("<==PtRegisterDevice: %x\n", Status)); - - return (Status); -} - - -NTSTATUS -PtDispatch( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp - ) -/*++ -Routine Description: - - Process IRPs sent to this device. - -Arguments: - - DeviceObject - pointer to a device object - Irp - pointer to an I/O Request Packet - -Return Value: - - NTSTATUS - STATUS_SUCCESS always - change this when adding - real code to handle ioctls. - ---*/ -{ - PIO_STACK_LOCATION irpStack; - NTSTATUS status = STATUS_SUCCESS; - - UNREFERENCED_PARAMETER(DeviceObject); - - DBGPRINT(("==>Pt Dispatch\n")); - irpStack = IoGetCurrentIrpStackLocation(Irp); - - - switch (irpStack->MajorFunction) - { - case IRP_MJ_CREATE: - break; - - case IRP_MJ_CLEANUP: - break; - - case IRP_MJ_CLOSE: - break; - - case IRP_MJ_DEVICE_CONTROL: - // - // Add code here to handle ioctl commands sent to passthru. - // - break; - default: - break; - } - - Irp->IoStatus.Status = status; - IoCompleteRequest(Irp, IO_NO_INCREMENT); - - DBGPRINT(("<== Pt Dispatch\n")); - - return status; - -} - - -NDIS_STATUS -PtDeregisterDevice( - VOID - ) -/*++ - -Routine Description: - - Deregister the ioctl interface. This is called whenever a miniport - instance is halted. When the last miniport instance is halted, we - request NDIS to delete the device object - -Arguments: - - NdisDeviceHandle - Handle returned by NdisMRegisterDevice - -Return Value: - - NDIS_STATUS_SUCCESS if everything worked ok - ---*/ -{ - NDIS_STATUS Status = NDIS_STATUS_SUCCESS; - - DBGPRINT(("==>PassthruDeregisterDevice\n")); - - NdisAcquireSpinLock(&GlobalLock); - - ASSERT(MiniportCount > 0); - - --MiniportCount; - - if (0 == MiniportCount) - { - // - // All miniport instances have been halted. Deregister - // the control device. - // - - ASSERT(ControlDeviceState == PS_DEVICE_STATE_READY); - - // - // Block PtRegisterDevice() while we release the control - // device lock and deregister the device. - // - ControlDeviceState = PS_DEVICE_STATE_DELETING; - - NdisReleaseSpinLock(&GlobalLock); - - if (NdisDeviceHandle != NULL) - { - Status = NdisMDeregisterDevice(NdisDeviceHandle); - NdisDeviceHandle = NULL; - } - - NdisAcquireSpinLock(&GlobalLock); - ControlDeviceState = PS_DEVICE_STATE_READY; - } - - NdisReleaseSpinLock(&GlobalLock); - - DBGPRINT(("<== PassthruDeregisterDevice: %x\n", Status)); - return Status; - -} - -VOID -PtUnload( - IN PDRIVER_OBJECT DriverObject - ) -// -// PassThru driver unload function -// -{ - UNREFERENCED_PARAMETER(DriverObject); - - DBGPRINT(("PtUnload: entered\n")); - - PtUnloadProtocol(); - - NdisIMDeregisterLayeredMiniport(DriverHandle); - - NdisFreeSpinLock(&GlobalLock); - - ipfw_module_exit(); // IPFW unloading dummynet - - DBGPRINT(("PtUnload: done!\n")); -} diff --git a/modified_passthru/passthru.h b/modified_passthru/passthru.h deleted file mode 100644 index 6e79db7..0000000 --- a/modified_passthru/passthru.h +++ /dev/null @@ -1,500 +0,0 @@ -/*++ - -Copyright (c) 1992-2000 Microsoft Corporation - -Module Name: - - passthru.h - -Abstract: - - Ndis Intermediate Miniport driver sample. This is a passthru driver. - -Author: - -Environment: - - -Revision History: - - ---*/ - -#ifdef NDIS51_MINIPORT -#define PASSTHRU_MAJOR_NDIS_VERSION 5 -#define PASSTHRU_MINOR_NDIS_VERSION 1 -#else -#define PASSTHRU_MAJOR_NDIS_VERSION 4 -#define PASSTHRU_MINOR_NDIS_VERSION 0 -#endif - -#ifdef NDIS51 -#define PASSTHRU_PROT_MAJOR_NDIS_VERSION 5 -#define PASSTHRU_PROT_MINOR_NDIS_VERSION 0 -#else -#define PASSTHRU_PROT_MAJOR_NDIS_VERSION 4 -#define PASSTHRU_PROT_MINOR_NDIS_VERSION 0 -#endif - -#define MAX_BUNDLEID_LENGTH 50 - -#define TAG 'ImPa' -#define WAIT_INFINITE 0 - - - -//advance declaration -typedef struct _ADAPT ADAPT, *PADAPT; - -DRIVER_INITIALIZE DriverEntry; -extern -NTSTATUS -DriverEntry( - IN PDRIVER_OBJECT DriverObject, - IN PUNICODE_STRING RegistryPath - ); - -DRIVER_DISPATCH PtDispatch; -NTSTATUS -PtDispatch( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp - ); - -DRIVER_DISPATCH DevIoControl; -NTSTATUS -DevIoControl( - IN PDEVICE_OBJECT pDeviceObject, - IN PIRP pIrp - ); - -NDIS_STATUS -PtRegisterDevice( - VOID - ); - -NDIS_STATUS -PtDeregisterDevice( - VOID - ); - -DRIVER_UNLOAD PtUnload; -VOID -PtUnloadProtocol( - VOID - ); - -// -// Protocol proto-types -// -extern -VOID -PtOpenAdapterComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_STATUS Status, - IN NDIS_STATUS OpenErrorStatus - ); - -extern -VOID -PtCloseAdapterComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_STATUS Status - ); - -extern -VOID -PtResetComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_STATUS Status - ); - -extern -VOID -PtRequestComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN PNDIS_REQUEST NdisRequest, - IN NDIS_STATUS Status - ); - -extern -VOID -PtStatus( - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_STATUS GeneralStatus, - IN PVOID StatusBuffer, - IN UINT StatusBufferSize - ); - -extern -VOID -PtStatusComplete( - IN NDIS_HANDLE ProtocolBindingContext - ); - -extern -VOID -PtSendComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN PNDIS_PACKET Packet, - IN NDIS_STATUS Status - ); - -extern -VOID -PtTransferDataComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN PNDIS_PACKET Packet, - IN NDIS_STATUS Status, - IN UINT BytesTransferred - ); - -extern -NDIS_STATUS -PtReceive( - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_HANDLE MacReceiveContext, - IN PVOID HeaderBuffer, - IN UINT HeaderBufferSize, - IN PVOID LookAheadBuffer, - IN UINT LookaheadBufferSize, - IN UINT PacketSize - ); - -extern -VOID -PtReceiveComplete( - IN NDIS_HANDLE ProtocolBindingContext - ); - -extern -INT -PtReceivePacket( - IN NDIS_HANDLE ProtocolBindingContext, - IN PNDIS_PACKET Packet - ); - -extern -VOID -PtBindAdapter( - OUT PNDIS_STATUS Status, - IN NDIS_HANDLE BindContext, - IN PNDIS_STRING DeviceName, - IN PVOID SystemSpecific1, - IN PVOID SystemSpecific2 - ); - -extern -VOID -PtUnbindAdapter( - OUT PNDIS_STATUS Status, - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_HANDLE UnbindContext - ); - -VOID -PtUnload( - IN PDRIVER_OBJECT DriverObject - ); - - - -extern -NDIS_STATUS -PtPNPHandler( - IN NDIS_HANDLE ProtocolBindingContext, - IN PNET_PNP_EVENT pNetPnPEvent - ); - - - - -NDIS_STATUS -PtPnPNetEventReconfigure( - IN PADAPT pAdapt, - IN PNET_PNP_EVENT pNetPnPEvent - ); - -NDIS_STATUS -PtPnPNetEventSetPower ( - IN PADAPT pAdapt, - IN PNET_PNP_EVENT pNetPnPEvent - ); - - -// -// Miniport proto-types -// -NDIS_STATUS -MPInitialize( - OUT PNDIS_STATUS OpenErrorStatus, - OUT PUINT SelectedMediumIndex, - IN PNDIS_MEDIUM MediumArray, - IN UINT MediumArraySize, - IN NDIS_HANDLE MiniportAdapterHandle, - IN NDIS_HANDLE WrapperConfigurationContext - ); - -VOID -MPSendPackets( - IN NDIS_HANDLE MiniportAdapterContext, - IN PPNDIS_PACKET PacketArray, - IN UINT NumberOfPackets - ); - -NDIS_STATUS -MPSend( - IN NDIS_HANDLE MiniportAdapterContext, - IN PNDIS_PACKET Packet, - IN UINT Flags - ); - -NDIS_STATUS -MPQueryInformation( - IN NDIS_HANDLE MiniportAdapterContext, - IN NDIS_OID Oid, - IN PVOID InformationBuffer, - IN ULONG InformationBufferLength, - OUT PULONG BytesWritten, - OUT PULONG BytesNeeded - ); - -NDIS_STATUS -MPSetInformation( - IN NDIS_HANDLE MiniportAdapterContext, - IN NDIS_OID Oid, - __in_bcount(InformationBufferLength) IN PVOID InformationBuffer, - IN ULONG InformationBufferLength, - OUT PULONG BytesRead, - OUT PULONG BytesNeeded - ); - -VOID -MPReturnPacket( - IN NDIS_HANDLE MiniportAdapterContext, - IN PNDIS_PACKET Packet - ); - -NDIS_STATUS -MPTransferData( - OUT PNDIS_PACKET Packet, - OUT PUINT BytesTransferred, - IN NDIS_HANDLE MiniportAdapterContext, - IN NDIS_HANDLE MiniportReceiveContext, - IN UINT ByteOffset, - IN UINT BytesToTransfer - ); - -VOID -MPHalt( - IN NDIS_HANDLE MiniportAdapterContext - ); - - -VOID -MPQueryPNPCapabilities( - OUT PADAPT MiniportProtocolContext, - OUT PNDIS_STATUS Status - ); - - -#ifdef NDIS51_MINIPORT - -VOID -MPCancelSendPackets( - IN NDIS_HANDLE MiniportAdapterContext, - IN PVOID CancelId - ); - -VOID -MPAdapterShutdown( - IN NDIS_HANDLE MiniportAdapterContext - ); - -VOID -MPDevicePnPEvent( - IN NDIS_HANDLE MiniportAdapterContext, - IN NDIS_DEVICE_PNP_EVENT DevicePnPEvent, - IN PVOID InformationBuffer, - IN ULONG InformationBufferLength - ); - -#endif // NDIS51_MINIPORT - -VOID -MPFreeAllPacketPools( - IN PADAPT pAdapt - ); - - -VOID -MPProcessSetPowerOid( - IN OUT PNDIS_STATUS pNdisStatus, - IN PADAPT pAdapt, - __in_bcount(InformationBufferLength) IN PVOID InformationBuffer, - IN ULONG InformationBufferLength, - OUT PULONG BytesRead, - OUT PULONG BytesNeeded - ); - -VOID -PtReferenceAdapt( - IN PADAPT pAdapt - ); - -BOOLEAN -PtDereferenceAdapt( - IN PADAPT pAdapt - ); - -// -// There should be no DbgPrint's in the Free version of the driver -// -#if DBG - -#define DBGPRINT(Fmt) \ - { \ - DbgPrint("Passthru: "); \ - DbgPrint Fmt; \ - } - -#else // if DBG - -#define DBGPRINT(Fmt) - -#endif // if DBG - -#define NUM_PKTS_IN_POOL 256 - - -// -// Protocol reserved part of a sent packet that is allocated by us. -// -typedef struct _SEND_RSVD -{ - PNDIS_PACKET OriginalPkt; - struct mbuf* pMbuf; // IPFW extension, reference to the mbuf -} SEND_RSVD, *PSEND_RSVD; - -// -// Miniport reserved part of a received packet that is allocated by -// us. Note that this should fit into the MiniportReserved space -// in an NDIS_PACKET. -// -typedef struct _RECV_RSVD -{ - PNDIS_PACKET OriginalPkt; - struct mbuf* pMbuf; // IPFW extension, reference to the mbuf -} RECV_RSVD, *PRECV_RSVD; - -C_ASSERT(sizeof(RECV_RSVD) <= sizeof(((PNDIS_PACKET)0)->MiniportReserved)); - -// -// Event Codes related to the PassthruEvent Structure -// - -typedef enum -{ - Passthru_Invalid, - Passthru_SetPower, - Passthru_Unbind - -} PASSSTHRU_EVENT_CODE, *PPASTHRU_EVENT_CODE; - -// -// Passthru Event with a code to state why they have been state -// - -typedef struct _PASSTHRU_EVENT -{ - NDIS_EVENT Event; - PASSSTHRU_EVENT_CODE Code; - -} PASSTHRU_EVENT, *PPASSTHRU_EVENT; - - -// -// Structure used by both the miniport as well as the protocol part of the intermediate driver -// to represent an adapter and its corres. lower bindings -// -typedef struct _ADAPT -{ - struct _ADAPT * Next; - - NDIS_HANDLE BindingHandle; // To the lower miniport - NDIS_HANDLE MiniportHandle; // NDIS Handle to for miniport up-calls - NDIS_HANDLE SendPacketPoolHandle; - NDIS_HANDLE RecvPacketPoolHandle; - NDIS_STATUS Status; // Open Status - NDIS_EVENT Event; // Used by bind/halt for Open/Close Adapter synch. - NDIS_MEDIUM Medium; - NDIS_REQUEST Request; // This is used to wrap a request coming down - // to us. This exploits the fact that requests - // are serialized down to us. - PULONG BytesNeeded; - PULONG BytesReadOrWritten; - BOOLEAN ReceivedIndicationFlags[32]; - - BOOLEAN OutstandingRequests; // TRUE iff a request is pending - // at the miniport below - BOOLEAN QueuedRequest; // TRUE iff a request is queued at - // this IM miniport - - BOOLEAN StandingBy; // True - When the miniport or protocol is transitioning from a D0 to Standby (>D0) State - BOOLEAN UnbindingInProcess; - NDIS_SPIN_LOCK Lock; - // False - At all other times, - Flag is cleared after a transition to D0 - - NDIS_DEVICE_POWER_STATE MPDeviceState; // Miniport's Device State - NDIS_DEVICE_POWER_STATE PTDeviceState; // Protocol's Device State - NDIS_STRING DeviceName; // For initializing the miniport edge - NDIS_EVENT MiniportInitEvent; // For blocking UnbindAdapter while - // an IM Init is in progress. - BOOLEAN MiniportInitPending; // TRUE iff IMInit in progress - NDIS_STATUS LastIndicatedStatus; // The last indicated media status - NDIS_STATUS LatestUnIndicateStatus; // The latest suppressed media status - ULONG OutstandingSends; - LONG RefCount; - BOOLEAN MiniportIsHalted; -} ADAPT, *PADAPT; - -extern NDIS_HANDLE ProtHandle, DriverHandle; -extern NDIS_MEDIUM MediumArray[4]; -extern PADAPT pAdaptList; -extern NDIS_SPIN_LOCK GlobalLock; - - -#define ADAPT_MINIPORT_HANDLE(_pAdapt) ((_pAdapt)->MiniportHandle) -#define ADAPT_DECR_PENDING_SENDS(_pAdapt) \ - { \ - NdisAcquireSpinLock(&(_pAdapt)->Lock); \ - (_pAdapt)->OutstandingSends--; \ - NdisReleaseSpinLock(&(_pAdapt)->Lock); \ - } - -// -// Custom Macros to be used by the passthru driver -// -/* -BOOLEAN -IsIMDeviceStateOn( - PADAPT - ) - -*/ -#define IsIMDeviceStateOn(_pP) ((_pP)->MPDeviceState == NdisDeviceStateD0 && (_pP)->PTDeviceState == NdisDeviceStateD0 ) - -#include "winmissing.h" - -int ipfw_module_init(void); -void ipfw_module_exit(void); -int ipfw2_qhandler_w32(PNDIS_PACKET pNdisPacket, int direction, - NDIS_HANDLE Context); -int ipfw2_qhandler_w32_oldstyle(int direction, NDIS_HANDLE ProtocolBindingContext, - unsigned char* HeaderBuffer, unsigned int HeaderBufferSize, - unsigned char* LookAheadBuffer, unsigned int LookAheadBufferSize, - unsigned int PacketSize); -void CleanupReinjected(PNDIS_PACKET Packet, struct mbuf* m, PADAPT pAdapt); -void hexdump(PUCHAR,int, const char *); -void my_init(); -void my_exit(); \ No newline at end of file diff --git a/modified_passthru/precomp.h b/modified_passthru/precomp.h deleted file mode 100644 index b2870d1..0000000 --- a/modified_passthru/precomp.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma warning(disable:4214) // bit field types other than int - -#pragma warning(disable:4201) // nameless struct/union -#pragma warning(disable:4115) // named type definition in parentheses -#pragma warning(disable:4127) // conditional expression is constant -#pragma warning(disable:4054) // cast of function pointer to PVOID -#pragma warning(disable:4244) // conversion from 'int' to 'BOOLEAN', possible loss of data - -#include -#include "passthru.h" - diff --git a/modified_passthru/protocol.c b/modified_passthru/protocol.c deleted file mode 100644 index 9db4c36..0000000 --- a/modified_passthru/protocol.c +++ /dev/null @@ -1,1670 +0,0 @@ -/*++ - -Copyright(c) 1992-2000 Microsoft Corporation - -Module Name: - - protocol.c - -Abstract: - - Ndis Intermediate Miniport driver sample. This is a passthru driver. - -Author: - -Environment: - - -Revision History: - - ---*/ - - -#include "precomp.h" -#pragma hdrstop - -#define MAX_PACKET_POOL_SIZE 0x0000FFFF -#define MIN_PACKET_POOL_SIZE 0x000000FF - -// -// NDIS version as 0xMMMMmmmm, where M=Major/m=minor (0x00050001 = 5.1); -// initially unknown (0) -// -ULONG NdisDotSysVersion = 0x0; - - -#define NDIS_SYS_VERSION_51 0x00050001 - - -VOID -PtBindAdapter( - OUT PNDIS_STATUS Status, - IN NDIS_HANDLE BindContext, - IN PNDIS_STRING DeviceName, - IN PVOID SystemSpecific1, - IN PVOID SystemSpecific2 - ) -/*++ - -Routine Description: - - Called by NDIS to bind to a miniport below. - -Arguments: - - Status - Return status of bind here. - BindContext - Can be passed to NdisCompleteBindAdapter if this call is pended. - DeviceName - Device name to bind to. This is passed to NdisOpenAdapter. - SystemSpecific1 - Can be passed to NdisOpenProtocolConfiguration to read per-binding information - SystemSpecific2 - Unused - -Return Value: - - NDIS_STATUS_PENDING if this call is pended. In this case call NdisCompleteBindAdapter - to complete. - Anything else Completes this call synchronously - ---*/ -{ - NDIS_HANDLE ConfigHandle = NULL; - PNDIS_CONFIGURATION_PARAMETER Param; - NDIS_STRING DeviceStr = NDIS_STRING_CONST("UpperBindings"); - NDIS_STRING NdisVersionStr = NDIS_STRING_CONST("NdisVersion"); - PADAPT pAdapt = NULL; - NDIS_STATUS Sts; - UINT MediumIndex; - ULONG TotalSize; - BOOLEAN NoCleanUpNeeded = FALSE; - - - UNREFERENCED_PARAMETER(BindContext); - UNREFERENCED_PARAMETER(SystemSpecific2); - - DBGPRINT(("==> Protocol BindAdapter\n")); - - do - { - // - // Access the configuration section for our binding-specific - // parameters. - // - NdisOpenProtocolConfiguration(Status, - &ConfigHandle, - SystemSpecific1); - - if (*Status != NDIS_STATUS_SUCCESS) - { - break; - } - if (NdisDotSysVersion == 0) - { - NdisReadConfiguration(Status, - &Param, - ConfigHandle, - &NdisVersionStr, // "NdisVersion" - NdisParameterInteger); - if (*Status != NDIS_STATUS_SUCCESS) - { - break; - } - - NdisDotSysVersion = Param->ParameterData.IntegerData; - } - - - // - // Read the "UpperBindings" reserved key that contains a list - // of device names representing our miniport instances corresponding - // to this lower binding. Since this is a 1:1 IM driver, this key - // contains exactly one name. - // - // If we want to implement a N:1 mux driver (N adapter instances - // over a single lower binding), then UpperBindings will be a - // MULTI_SZ containing a list of device names - we would loop through - // this list, calling NdisIMInitializeDeviceInstanceEx once for - // each name in it. - // - NdisReadConfiguration(Status, - &Param, - ConfigHandle, - &DeviceStr, - NdisParameterString); - if (*Status != NDIS_STATUS_SUCCESS) - { - break; - } - - // - // Allocate memory for the Adapter structure. This represents both the - // protocol context as well as the adapter structure when the miniport - // is initialized. - // - // In addition to the base structure, allocate space for the device - // instance string. - // - TotalSize = sizeof(ADAPT) + Param->ParameterData.StringData.MaximumLength; - - NdisAllocateMemoryWithTag(&pAdapt, TotalSize, TAG); - - if (pAdapt == NULL) - { - *Status = NDIS_STATUS_RESOURCES; - break; - } - - // - // Initialize the adapter structure. We copy in the IM device - // name as well, because we may need to use it in a call to - // NdisIMCancelInitializeDeviceInstance. The string returned - // by NdisReadConfiguration is active (i.e. available) only - // for the duration of this call to our BindAdapter handler. - // - NdisZeroMemory(pAdapt, TotalSize); - pAdapt->DeviceName.MaximumLength = Param->ParameterData.StringData.MaximumLength; - pAdapt->DeviceName.Length = Param->ParameterData.StringData.Length; - pAdapt->DeviceName.Buffer = (PWCHAR)((ULONG_PTR)pAdapt + sizeof(ADAPT)); - NdisMoveMemory(pAdapt->DeviceName.Buffer, - Param->ParameterData.StringData.Buffer, - Param->ParameterData.StringData.MaximumLength); - - - - NdisInitializeEvent(&pAdapt->Event); - NdisAllocateSpinLock(&pAdapt->Lock); - - // - // Allocate a packet pool for sends. We need this to pass sends down. - // We cannot use the same packet descriptor that came down to our send - // handler (see also NDIS 5.1 packet stacking). - // - NdisAllocatePacketPoolEx(Status, - &pAdapt->SendPacketPoolHandle, - MIN_PACKET_POOL_SIZE, - MAX_PACKET_POOL_SIZE - MIN_PACKET_POOL_SIZE, - sizeof(SEND_RSVD)); - - if (*Status != NDIS_STATUS_SUCCESS) - { - break; - } - - // - // Allocate a packet pool for receives. We need this to indicate receives. - // Same consideration as sends (see also NDIS 5.1 packet stacking). - // - NdisAllocatePacketPoolEx(Status, - &pAdapt->RecvPacketPoolHandle, - MIN_PACKET_POOL_SIZE, - MAX_PACKET_POOL_SIZE - MIN_PACKET_POOL_SIZE, - PROTOCOL_RESERVED_SIZE_IN_PACKET); - - if (*Status != NDIS_STATUS_SUCCESS) - { - break; - } - - // - // Now open the adapter below and complete the initialization - // - NdisOpenAdapter(Status, - &Sts, - &pAdapt->BindingHandle, - &MediumIndex, - MediumArray, - sizeof(MediumArray)/sizeof(NDIS_MEDIUM), - ProtHandle, - pAdapt, - DeviceName, - 0, - NULL); - - if (*Status == NDIS_STATUS_PENDING) - { - NdisWaitEvent(&pAdapt->Event, 0); - *Status = pAdapt->Status; - } - - if (*Status != NDIS_STATUS_SUCCESS) - { - break; - } - PtReferenceAdapt(pAdapt); - -#pragma prefast(suppress: __WARNING_POTENTIAL_BUFFER_OVERFLOW, "Ndis guarantees MediumIndex to be within bounds"); - pAdapt->Medium = MediumArray[MediumIndex]; - - // - // Now ask NDIS to initialize our miniport (upper) edge. - // Set the flag below to synchronize with a possible call - // to our protocol Unbind handler that may come in before - // our miniport initialization happens. - // - pAdapt->MiniportInitPending = TRUE; - NdisInitializeEvent(&pAdapt->MiniportInitEvent); - - PtReferenceAdapt(pAdapt); - - *Status = NdisIMInitializeDeviceInstanceEx(DriverHandle, - &pAdapt->DeviceName, - pAdapt); - - if (*Status != NDIS_STATUS_SUCCESS) - { - if (pAdapt->MiniportIsHalted == TRUE) - { - NoCleanUpNeeded = TRUE; - } - - DBGPRINT(("BindAdapter: Adapt %p, IMInitializeDeviceInstance error %x\n", - pAdapt, *Status)); - - if (PtDereferenceAdapt(pAdapt)) - { - pAdapt = NULL; - } - - break; - } - - PtDereferenceAdapt(pAdapt); - - } while(FALSE); - - // - // Close the configuration handle now - see comments above with - // the call to NdisIMInitializeDeviceInstanceEx. - // - if (ConfigHandle != NULL) - { - NdisCloseConfiguration(ConfigHandle); - } - - if ((*Status != NDIS_STATUS_SUCCESS) && (NoCleanUpNeeded == FALSE)) - { - if (pAdapt != NULL) - { - if (pAdapt->BindingHandle != NULL) - { - NDIS_STATUS LocalStatus; - - // - // Close the binding we opened above. - // - - NdisResetEvent(&pAdapt->Event); - - NdisCloseAdapter(&LocalStatus, pAdapt->BindingHandle); - pAdapt->BindingHandle = NULL; - - if (LocalStatus == NDIS_STATUS_PENDING) - { - NdisWaitEvent(&pAdapt->Event, 0); - LocalStatus = pAdapt->Status; - - - } - if (PtDereferenceAdapt(pAdapt)) - { - pAdapt = NULL; - } - } - } - } - - - DBGPRINT(("<== Protocol BindAdapter: pAdapt %p, Status %x\n", pAdapt, *Status)); -} - - -VOID -PtOpenAdapterComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_STATUS Status, - IN NDIS_STATUS OpenErrorStatus - ) -/*++ - -Routine Description: - - Completion routine for NdisOpenAdapter issued from within the PtBindAdapter. Simply - unblock the caller. - -Arguments: - - ProtocolBindingContext Pointer to the adapter - Status Status of the NdisOpenAdapter call - OpenErrorStatus Secondary status(ignored by us). - -Return Value: - - None - ---*/ -{ - PADAPT pAdapt =(PADAPT)ProtocolBindingContext; - - UNREFERENCED_PARAMETER(OpenErrorStatus); - - DBGPRINT(("==> PtOpenAdapterComplete: Adapt %p, Status %x\n", pAdapt, Status)); - pAdapt->Status = Status; - NdisSetEvent(&pAdapt->Event); -} - - -VOID -PtUnbindAdapter( - OUT PNDIS_STATUS Status, - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_HANDLE UnbindContext - ) -/*++ - -Routine Description: - - Called by NDIS when we are required to unbind to the adapter below. - This functions shares functionality with the miniport's HaltHandler. - The code should ensure that NdisCloseAdapter and NdisFreeMemory is called - only once between the two functions - -Arguments: - - Status Placeholder for return status - ProtocolBindingContext Pointer to the adapter structure - UnbindContext Context for NdisUnbindComplete() if this pends - -Return Value: - - Status for NdisIMDeinitializeDeviceContext - ---*/ -{ - PADAPT pAdapt =(PADAPT)ProtocolBindingContext; - NDIS_STATUS LocalStatus; - - UNREFERENCED_PARAMETER(UnbindContext); - - DBGPRINT(("==> PtUnbindAdapter: Adapt %p\n", pAdapt)); - - // - // Set the flag that the miniport below is unbinding, so the request handlers will - // fail any request comming later - // - NdisAcquireSpinLock(&pAdapt->Lock); - pAdapt->UnbindingInProcess = TRUE; - if (pAdapt->QueuedRequest == TRUE) - { - pAdapt->QueuedRequest = FALSE; - NdisReleaseSpinLock(&pAdapt->Lock); - - PtRequestComplete(pAdapt, - &pAdapt->Request, - NDIS_STATUS_FAILURE ); - - } - else - { - NdisReleaseSpinLock(&pAdapt->Lock); - } -#ifndef WIN9X - // - // Check if we had called NdisIMInitializeDeviceInstanceEx and - // we are awaiting a call to MiniportInitialize. - // - if (pAdapt->MiniportInitPending == TRUE) - { - // - // Try to cancel the pending IMInit process. - // - LocalStatus = NdisIMCancelInitializeDeviceInstance( - DriverHandle, - &pAdapt->DeviceName); - - if (LocalStatus == NDIS_STATUS_SUCCESS) - { - // - // Successfully cancelled IM Initialization; our - // Miniport Initialize routine will not be called - // for this device. - // - pAdapt->MiniportInitPending = FALSE; - ASSERT(pAdapt->MiniportHandle == NULL); - } - else - { - // - // Our Miniport Initialize routine will be called - // (may be running on another thread at this time). - // Wait for it to finish. - // - NdisWaitEvent(&pAdapt->MiniportInitEvent, 0); - ASSERT(pAdapt->MiniportInitPending == FALSE); - } - - } -#endif // !WIN9X - - // - // Call NDIS to remove our device-instance. We do most of the work - // inside the HaltHandler. - // - // The Handle will be NULL if our miniport Halt Handler has been called or - // if the IM device was never initialized - // - - if (pAdapt->MiniportHandle != NULL) - { - *Status = NdisIMDeInitializeDeviceInstance(pAdapt->MiniportHandle); - - if (*Status != NDIS_STATUS_SUCCESS) - { - *Status = NDIS_STATUS_FAILURE; - } - } - else - { - // - // We need to do some work here. - // Close the binding below us - // and release the memory allocated. - // - - if(pAdapt->BindingHandle != NULL) - { - NdisResetEvent(&pAdapt->Event); - - NdisCloseAdapter(Status, pAdapt->BindingHandle); - - // - // Wait for it to complete - // - if(*Status == NDIS_STATUS_PENDING) - { - NdisWaitEvent(&pAdapt->Event, 0); - *Status = pAdapt->Status; - } - pAdapt->BindingHandle = NULL; - } - else - { - // - // Both Our MiniportHandle and Binding Handle should not be NULL. - // - *Status = NDIS_STATUS_FAILURE; - ASSERT(0); - } - - // - // Free the memory here, if was not released earlier(by calling the HaltHandler) - // - MPFreeAllPacketPools(pAdapt); - NdisFreeSpinLock(&pAdapt->Lock); - NdisFreeMemory(pAdapt, 0, 0); - } - - DBGPRINT(("<== PtUnbindAdapter: Adapt %p\n", pAdapt)); -} - -VOID -PtUnloadProtocol( - VOID -) -{ - NDIS_STATUS Status; - - if (ProtHandle != NULL) - { - NdisDeregisterProtocol(&Status, ProtHandle); - ProtHandle = NULL; - } - - DBGPRINT(("PtUnloadProtocol: done!\n")); -} - - - -VOID -PtCloseAdapterComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_STATUS Status - ) -/*++ - -Routine Description: - - Completion for the CloseAdapter call. - -Arguments: - - ProtocolBindingContext Pointer to the adapter structure - Status Completion status - -Return Value: - - None. - ---*/ -{ - PADAPT pAdapt =(PADAPT)ProtocolBindingContext; - - DBGPRINT(("CloseAdapterComplete: Adapt %p, Status %x\n", pAdapt, Status)); - pAdapt->Status = Status; - NdisSetEvent(&pAdapt->Event); -} - - -VOID -PtResetComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_STATUS Status - ) -/*++ - -Routine Description: - - Completion for the reset. - -Arguments: - - ProtocolBindingContext Pointer to the adapter structure - Status Completion status - -Return Value: - - None. - ---*/ -{ - - UNREFERENCED_PARAMETER(ProtocolBindingContext); - UNREFERENCED_PARAMETER(Status); - // - // We never issue a reset, so we should not be here. - // - ASSERT(0); -} - - -VOID -PtRequestComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN PNDIS_REQUEST NdisRequest, - IN NDIS_STATUS Status - ) -/*++ - -Routine Description: - - Completion handler for the previously posted request. All OIDS - are completed by and sent to the same miniport that they were requested for. - If Oid == OID_PNP_QUERY_POWER then the data structure needs to returned with all entries = - NdisDeviceStateUnspecified - -Arguments: - - ProtocolBindingContext Pointer to the adapter structure - NdisRequest The posted request - Status Completion status - -Return Value: - - None - ---*/ -{ - PADAPT pAdapt = (PADAPT)ProtocolBindingContext; - NDIS_OID Oid = pAdapt->Request.DATA.SET_INFORMATION.Oid ; - - // - // Since our request is not outstanding anymore - // - ASSERT(pAdapt->OutstandingRequests == TRUE); - - pAdapt->OutstandingRequests = FALSE; - - // - // Complete the Set or Query, and fill in the buffer for OID_PNP_CAPABILITIES, if need be. - // - switch (NdisRequest->RequestType) - { - case NdisRequestQueryInformation: - - // - // We never pass OID_PNP_QUERY_POWER down. - // - ASSERT(Oid != OID_PNP_QUERY_POWER); - - if ((Oid == OID_PNP_CAPABILITIES) && (Status == NDIS_STATUS_SUCCESS)) - { - MPQueryPNPCapabilities(pAdapt, &Status); - } - *pAdapt->BytesReadOrWritten = NdisRequest->DATA.QUERY_INFORMATION.BytesWritten; - *pAdapt->BytesNeeded = NdisRequest->DATA.QUERY_INFORMATION.BytesNeeded; - - if (((Oid == OID_GEN_MAC_OPTIONS) - && (Status == NDIS_STATUS_SUCCESS)) - && (NdisDotSysVersion >= NDIS_SYS_VERSION_51)) - { - // - // Only do this on Windows XP or greater (NDIS.SYS v 5.1); - // do not do in Windows 2000 (NDIS.SYS v 5.0)) - // - - // - // Remove the no-loopback bit from mac-options. In essence we are - // telling NDIS that we can handle loopback. We don't, but the - // interface below us does. If we do not do this, then loopback - // processing happens both below us and above us. This is wasteful - // at best and if Netmon is running, it will see multiple copies - // of loopback packets when sniffing above us. - // - // Only the lowest miniport is a stack of layered miniports should - // ever report this bit set to NDIS. - // - *(PULONG)NdisRequest->DATA.QUERY_INFORMATION.InformationBuffer &= ~NDIS_MAC_OPTION_NO_LOOPBACK; - } - - NdisMQueryInformationComplete(pAdapt->MiniportHandle, - Status); - break; - - case NdisRequestSetInformation: - - ASSERT( Oid != OID_PNP_SET_POWER); - - *pAdapt->BytesReadOrWritten = NdisRequest->DATA.SET_INFORMATION.BytesRead; - *pAdapt->BytesNeeded = NdisRequest->DATA.SET_INFORMATION.BytesNeeded; - NdisMSetInformationComplete(pAdapt->MiniportHandle, - Status); - break; - - default: - ASSERT(0); - break; - } - -} - - -VOID -PtStatus( - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_STATUS GeneralStatus, - IN PVOID StatusBuffer, - IN UINT StatusBufferSize - ) -/*++ - -Routine Description: - - Status handler for the lower-edge(protocol). - -Arguments: - - ProtocolBindingContext Pointer to the adapter structure - GeneralStatus Status code - StatusBuffer Status buffer - StatusBufferSize Size of the status buffer - -Return Value: - - None - ---*/ -{ - PADAPT pAdapt = (PADAPT)ProtocolBindingContext; - - // - // Pass up this indication only if the upper edge miniport is initialized - // and powered on. Also ignore indications that might be sent by the lower - // miniport when it isn't at D0. - // - if ((pAdapt->MiniportHandle != NULL) && - (pAdapt->MPDeviceState == NdisDeviceStateD0) && - (pAdapt->PTDeviceState == NdisDeviceStateD0)) - { - if ((GeneralStatus == NDIS_STATUS_MEDIA_CONNECT) || - (GeneralStatus == NDIS_STATUS_MEDIA_DISCONNECT)) - { - - pAdapt->LastIndicatedStatus = GeneralStatus; - } - NdisMIndicateStatus(pAdapt->MiniportHandle, - GeneralStatus, - StatusBuffer, - StatusBufferSize); - } - // - // Save the last indicated media status - // - else - { - if ((pAdapt->MiniportHandle != NULL) && - ((GeneralStatus == NDIS_STATUS_MEDIA_CONNECT) || - (GeneralStatus == NDIS_STATUS_MEDIA_DISCONNECT))) - { - pAdapt->LatestUnIndicateStatus = GeneralStatus; - } - } - -} - - -VOID -PtStatusComplete( - IN NDIS_HANDLE ProtocolBindingContext - ) -/*++ - -Routine Description: - - -Arguments: - - -Return Value: - - ---*/ -{ - PADAPT pAdapt = (PADAPT)ProtocolBindingContext; - - // - // Pass up this indication only if the upper edge miniport is initialized - // and powered on. Also ignore indications that might be sent by the lower - // miniport when it isn't at D0. - // - if ((pAdapt->MiniportHandle != NULL) && - (pAdapt->MPDeviceState == NdisDeviceStateD0) && - (pAdapt->PTDeviceState == NdisDeviceStateD0)) - { - NdisMIndicateStatusComplete(pAdapt->MiniportHandle); - } -} - - -VOID -PtSendComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN PNDIS_PACKET Packet, - IN NDIS_STATUS Status - ) -/*++ - -Routine Description: - - Called by NDIS when the miniport below had completed a send. We should - complete the corresponding upper-edge send this represents. - -Arguments: - - ProtocolBindingContext - Points to ADAPT structure - Packet - Low level packet being completed - Status - status of send - -Return Value: - - None - ---*/ -{ - PADAPT pAdapt = (PADAPT)ProtocolBindingContext; - PNDIS_PACKET Pkt; - NDIS_HANDLE PoolHandle; - -#ifdef NDIS51 - // - // Packet stacking: - // - // Determine if the packet we are completing is the one we allocated. If so, then - // get the original packet from the reserved area and completed it and free the - // allocated packet. If this is the packet that was sent down to us, then just - // complete it - // - PoolHandle = NdisGetPoolFromPacket(Packet); - if (PoolHandle != pAdapt->SendPacketPoolHandle) - { - // - // We had passed down a packet belonging to the protocol above us. - // - // DBGPRINT(("PtSendComp: Adapt %p, Stacked Packet %p\n", pAdapt, Packet)); - - NdisMSendComplete(pAdapt->MiniportHandle, - Packet, - Status); - } - else -#endif // NDIS51 - { - PSEND_RSVD SendRsvd; - - SendRsvd = (PSEND_RSVD)(Packet->ProtocolReserved); - Pkt = SendRsvd->OriginalPkt; - -#if 1 // IPFW - new code - //DbgPrint("SendComplete: packet %p pkt %p\n", Packet, Pkt); - if (Pkt == NULL) { //this is a reinjected packet, with no 'father' - CleanupReinjected(Packet, SendRsvd->pMbuf, pAdapt); - return; - } -#endif /* IPFW */ - -#ifndef WIN9X - NdisIMCopySendCompletePerPacketInfo (Pkt, Packet); -#endif - - NdisDprFreePacket(Packet); - - NdisMSendComplete(pAdapt->MiniportHandle, - Pkt, - Status); - } - // - // Decrease the outstanding send count - // - ADAPT_DECR_PENDING_SENDS(pAdapt); -} - - -VOID -PtTransferDataComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN PNDIS_PACKET Packet, - IN NDIS_STATUS Status, - IN UINT BytesTransferred - ) -/*++ - -Routine Description: - - Entry point called by NDIS to indicate completion of a call by us - to NdisTransferData. - - See notes under SendComplete. - -Arguments: - -Return Value: - ---*/ -{ - PADAPT pAdapt =(PADAPT)ProtocolBindingContext; - - if(pAdapt->MiniportHandle) - { - NdisMTransferDataComplete(pAdapt->MiniportHandle, - Packet, - Status, - BytesTransferred); - } -} - - -NDIS_STATUS -PtReceive( - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_HANDLE MacReceiveContext, - IN PVOID HeaderBuffer, - IN UINT HeaderBufferSize, - IN PVOID LookAheadBuffer, - IN UINT LookAheadBufferSize, - IN UINT PacketSize - ) -/*++ - -Routine Description: - - Handle receive data indicated up by the miniport below. We pass - it along to the protocol above us. - - If the miniport below indicates packets, NDIS would more - likely call us at our ReceivePacket handler. However we - might be called here in certain situations even though - the miniport below has indicated a receive packet, e.g. - if the miniport had set packet status to NDIS_STATUS_RESOURCES. - -Arguments: - - - -Return Value: - - NDIS_STATUS_SUCCESS if we processed the receive successfully, - NDIS_STATUS_XXX error code if we discarded it. - ---*/ -{ - PADAPT pAdapt = (PADAPT)ProtocolBindingContext; - PNDIS_PACKET MyPacket, Packet = NULL; - NDIS_STATUS Status = NDIS_STATUS_SUCCESS; - ULONG Proc = KeGetCurrentProcessorNumber(); - - if ((!pAdapt->MiniportHandle) || (pAdapt->MPDeviceState > NdisDeviceStateD0)) - { - Status = NDIS_STATUS_FAILURE; - } - else do - { - // - // Get at the packet, if any, indicated up by the miniport below. - // - Packet = NdisGetReceivedPacket(pAdapt->BindingHandle, MacReceiveContext); - if (Packet != NULL) - { - // - // The miniport below did indicate up a packet. Use information - // from that packet to construct a new packet to indicate up. - // - -#ifdef NDIS51 - // - // NDIS 5.1 NOTE: Do not reuse the original packet in indicating - // up a receive, even if there is sufficient packet stack space. - // If we had to do so, we would have had to overwrite the - // status field in the original packet to NDIS_STATUS_RESOURCES, - // and it is not allowed for protocols to overwrite this field - // in received packets. - // -#endif // NDIS51 - - // - // Get a packet off the pool and indicate that up - // - NdisDprAllocatePacket(&Status, - &MyPacket, - pAdapt->RecvPacketPoolHandle); - - if (Status == NDIS_STATUS_SUCCESS) - { - // - // Make our packet point to data from the original - // packet. NOTE: this works only because we are - // indicating a receive directly from the context of - // our receive indication. If we need to queue this - // packet and indicate it from another thread context, - // we will also have to allocate a new buffer and copy - // over the packet contents, OOB data and per-packet - // information. This is because the packet data - // is available only for the duration of this - // receive indication call. - // - NDIS_PACKET_FIRST_NDIS_BUFFER(MyPacket) = NDIS_PACKET_FIRST_NDIS_BUFFER(Packet); - NDIS_PACKET_LAST_NDIS_BUFFER(MyPacket) = NDIS_PACKET_LAST_NDIS_BUFFER(Packet); - - // - // Get the original packet (it could be the same packet as the - // one received or a different one based on the number of layered - // miniports below) and set it on the indicated packet so the OOB - // data is visible correctly at protocols above. If the IM driver - // modifies the packet in any way it should not set the new packet's - // original packet equal to the original packet of the packet that - // was indicated to it from the underlying driver, in this case, the - // IM driver should also ensure that the related per packet info should - // be copied to the new packet. - // we can set the original packet to the original packet of the packet - // indicated from the underlying driver because the driver doesn't modify - // the data content in the packet. - // - NDIS_SET_ORIGINAL_PACKET(MyPacket, NDIS_GET_ORIGINAL_PACKET(Packet)); - NDIS_SET_PACKET_HEADER_SIZE(MyPacket, HeaderBufferSize); - - // - // Copy packet flags. - // - NdisGetPacketFlags(MyPacket) = NdisGetPacketFlags(Packet); - - // - // Force protocols above to make a copy if they want to hang - // on to data in this packet. This is because we are in our - // Receive handler (not ReceivePacket) and we can't return a - // ref count from here. - // - NDIS_SET_PACKET_STATUS(MyPacket, NDIS_STATUS_RESOURCES); - - // - // By setting NDIS_STATUS_RESOURCES, we also know that we can reclaim - // this packet as soon as the call to NdisMIndicateReceivePacket - // returns. - // - - if (pAdapt->MiniportHandle != NULL) - { -#if 1 /* IPFW: query the firewall */ - int ret; - ret = ipfw2_qhandler_w32(MyPacket, INCOMING, - ProtocolBindingContext); - if (ret != PASS) - return 0; //otherwise simply continue -#endif /* end of IPFW code */ - NdisMIndicateReceivePacket(pAdapt->MiniportHandle, &MyPacket, 1); - } - - // - // Reclaim the indicated packet. Since we had set its status - // to NDIS_STATUS_RESOURCES, we are guaranteed that protocols - // above are done with it. - // - NdisDprFreePacket(MyPacket); - - break; - } - } - else - { - // - // The miniport below us uses the old-style (not packet) - // receive indication. Fall through. - // - } - - // - // Fall through if the miniport below us has either not - // indicated a packet or we could not allocate one - // - pAdapt->ReceivedIndicationFlags[Proc] = TRUE; - if (pAdapt->MiniportHandle == NULL) - { - break; - } - switch (pAdapt->Medium) - { - case NdisMedium802_3: - case NdisMediumWan: - //DbgPrint("EthIndicateReceive context %p, header at %p len %u, lookahead at %p len %u, packetsize %u\n",ProtocolBindingContext,HeaderBuffer,HeaderBufferSize,LookAheadBuffer,LookAheadBufferSize,PacketSize); - //hexdump(HeaderBuffer,HeaderBufferSize+LookAheadBufferSize,"EthIndicateReceive"); - { - int ret = ipfw2_qhandler_w32_oldstyle(INCOMING, ProtocolBindingContext, HeaderBuffer, HeaderBufferSize, LookAheadBuffer, LookAheadBufferSize, PacketSize); - if (ret != PASS) - return NDIS_STATUS_SUCCESS; - } - NdisMEthIndicateReceive(pAdapt->MiniportHandle, - MacReceiveContext, - HeaderBuffer, - HeaderBufferSize, - LookAheadBuffer, - LookAheadBufferSize, - PacketSize); - break; - - case NdisMedium802_5: - NdisMTrIndicateReceive(pAdapt->MiniportHandle, - MacReceiveContext, - HeaderBuffer, - HeaderBufferSize, - LookAheadBuffer, - LookAheadBufferSize, - PacketSize); - break; - -#if FDDI - case NdisMediumFddi: - NdisMFddiIndicateReceive(pAdapt->MiniportHandle, - MacReceiveContext, - HeaderBuffer, - HeaderBufferSize, - LookAheadBuffer, - LookAheadBufferSize, - PacketSize); - break; -#endif - default: - ASSERT(FALSE); - break; - } - - } while(FALSE); - - return Status; -} - - -VOID -PtReceiveComplete( - IN NDIS_HANDLE ProtocolBindingContext - ) -/*++ - -Routine Description: - - Called by the adapter below us when it is done indicating a batch of - received packets. - -Arguments: - - ProtocolBindingContext Pointer to our adapter structure. - -Return Value: - - None - ---*/ -{ - PADAPT pAdapt =(PADAPT)ProtocolBindingContext; - ULONG Proc = KeGetCurrentProcessorNumber(); - - /* Warning: this is a poor implementation of the PtReceiveComplete - * made by MS, and it's a well known (but never fixed) issue. - * Since the ProcessorNumber here can be different from the one - * that processed the PtReceive, sometimes NdisMEthIndicateReceiveComplete - * will not be called, causing poor performance in the incoming traffic. - * In our driver, PtReceive is called for IP packets ONLY by particulary - * old NIC drivers, and the poor performance can be seen even - * in traffic not handled by ipfw or dummynet. - * Fortunately, this is quite rare, all the incoming IP packets - * will arrive through PtReceivePacket, and this callback will never - * be called. For reinjected traffic, a workaround is done - * commuting the ReceivedIndicationFlag and calling - * NdisMEthIndicateReceiveComplete manually for each packet. - */ - - if (((pAdapt->MiniportHandle != NULL) - && (pAdapt->MPDeviceState == NdisDeviceStateD0)) - && (pAdapt->ReceivedIndicationFlags[Proc])) - { - switch (pAdapt->Medium) - { - case NdisMedium802_3: - case NdisMediumWan: - NdisMEthIndicateReceiveComplete(pAdapt->MiniportHandle); - break; - - case NdisMedium802_5: - NdisMTrIndicateReceiveComplete(pAdapt->MiniportHandle); - break; -#if FDDI - case NdisMediumFddi: - NdisMFddiIndicateReceiveComplete(pAdapt->MiniportHandle); - break; -#endif - default: - ASSERT(FALSE); - break; - } - } - - pAdapt->ReceivedIndicationFlags[Proc] = FALSE; -} - - -INT -PtReceivePacket( - IN NDIS_HANDLE ProtocolBindingContext, - IN PNDIS_PACKET Packet - ) -/*++ - -Routine Description: - - ReceivePacket handler. Called by NDIS if the miniport below supports - NDIS 4.0 style receives. Re-package the buffer chain in a new packet - and indicate the new packet to protocols above us. Any context for - packets indicated up must be kept in the MiniportReserved field. - - NDIS 5.1 - packet stacking - if there is sufficient "stack space" in - the packet passed to us, we can use the same packet in a receive - indication. - -Arguments: - - ProtocolBindingContext - Pointer to our adapter structure. - Packet - Pointer to the packet - -Return Value: - - == 0 -> We are done with the packet - != 0 -> We will keep the packet and call NdisReturnPackets() this - many times when done. ---*/ -{ - PADAPT pAdapt =(PADAPT)ProtocolBindingContext; - NDIS_STATUS Status; - PNDIS_PACKET MyPacket; - BOOLEAN Remaining; - - // - // Drop the packet silently if the upper miniport edge isn't initialized or - // the miniport edge is in low power state - // - if ((!pAdapt->MiniportHandle) || (pAdapt->MPDeviceState > NdisDeviceStateD0)) - { - return 0; - } - -#ifdef NDIS51 - // - // Check if we can reuse the same packet for indicating up. - // See also: PtReceive(). - // - (VOID)NdisIMGetCurrentPacketStack(Packet, &Remaining); - if (0 && Remaining) - { - // - // We can reuse "Packet". Indicate it up and be done with it. - // - Status = NDIS_GET_PACKET_STATUS(Packet); - NdisMIndicateReceivePacket(pAdapt->MiniportHandle, &Packet, 1); - return((Status != NDIS_STATUS_RESOURCES) ? 1 : 0); - } -#endif // NDIS51 - - // - // Get a packet off the pool and indicate that up - // - NdisDprAllocatePacket(&Status, - &MyPacket, - pAdapt->RecvPacketPoolHandle); - - if (Status == NDIS_STATUS_SUCCESS) - { - PRECV_RSVD RecvRsvd; - - RecvRsvd = (PRECV_RSVD)(MyPacket->MiniportReserved); - RecvRsvd->OriginalPkt = Packet; - - NDIS_PACKET_FIRST_NDIS_BUFFER(MyPacket) = NDIS_PACKET_FIRST_NDIS_BUFFER(Packet); - NDIS_PACKET_LAST_NDIS_BUFFER(MyPacket) = NDIS_PACKET_LAST_NDIS_BUFFER(Packet); - - // - // Get the original packet (it could be the same packet as the one - // received or a different one based on the number of layered miniports - // below) and set it on the indicated packet so the OOB data is visible - // correctly to protocols above us. - // - NDIS_SET_ORIGINAL_PACKET(MyPacket, NDIS_GET_ORIGINAL_PACKET(Packet)); - - // - // Set Packet Flags - // - NdisGetPacketFlags(MyPacket) = NdisGetPacketFlags(Packet); - - Status = NDIS_GET_PACKET_STATUS(Packet); - - NDIS_SET_PACKET_STATUS(MyPacket, Status); - NDIS_SET_PACKET_HEADER_SIZE(MyPacket, NDIS_GET_PACKET_HEADER_SIZE(Packet)); - - if (pAdapt->MiniportHandle != NULL) - { -#if 1 /* IPFW: query the firewall */ - int ret; - ret = ipfw2_qhandler_w32(MyPacket, INCOMING, - ProtocolBindingContext); - if (ret != PASS) - return 0; //otherwise simply continue -#endif /* end of IPFW code */ - NdisMIndicateReceivePacket(pAdapt->MiniportHandle, &MyPacket, 1); - } - - // - // Check if we had indicated up the packet with NDIS_STATUS_RESOURCES - // NOTE -- do not use NDIS_GET_PACKET_STATUS(MyPacket) for this since - // it might have changed! Use the value saved in the local variable. - // - if (Status == NDIS_STATUS_RESOURCES) - { - // - // Our ReturnPackets handler will not be called for this packet. - // We should reclaim it right here. - // - NdisDprFreePacket(MyPacket); - } - - return((Status != NDIS_STATUS_RESOURCES) ? 1 : 0); - } - else - { - // - // We are out of packets. Silently drop it. - // - return(0); - } -} - - -NDIS_STATUS -PtPNPHandler( - IN NDIS_HANDLE ProtocolBindingContext, - IN PNET_PNP_EVENT pNetPnPEvent - ) - -/*++ -Routine Description: - - This is called by NDIS to notify us of a PNP event related to a lower - binding. Based on the event, this dispatches to other helper routines. - - NDIS 5.1: forward this event to the upper protocol(s) by calling - NdisIMNotifyPnPEvent. - -Arguments: - - ProtocolBindingContext - Pointer to our adapter structure. Can be NULL - for "global" notifications - - pNetPnPEvent - Pointer to the PNP event to be processed. - -Return Value: - - NDIS_STATUS code indicating status of event processing. - ---*/ -{ - PADAPT pAdapt =(PADAPT)ProtocolBindingContext; - NDIS_STATUS Status = NDIS_STATUS_SUCCESS; - - DBGPRINT(("PtPnPHandler: Adapt %p, Event %d\n", pAdapt, pNetPnPEvent->NetEvent)); - - switch (pNetPnPEvent->NetEvent) - { - case NetEventSetPower: - Status = PtPnPNetEventSetPower(pAdapt, pNetPnPEvent); - break; - - case NetEventReconfigure: - Status = PtPnPNetEventReconfigure(pAdapt, pNetPnPEvent); - break; - - default: -#ifdef NDIS51 - // - // Pass on this notification to protocol(s) above, before - // doing anything else with it. - // - if (pAdapt && pAdapt->MiniportHandle) - { - Status = NdisIMNotifyPnPEvent(pAdapt->MiniportHandle, pNetPnPEvent); - } -#else - Status = NDIS_STATUS_SUCCESS; - -#endif // NDIS51 - - break; - } - - return Status; -} - - -NDIS_STATUS -PtPnPNetEventReconfigure( - IN PADAPT pAdapt, - IN PNET_PNP_EVENT pNetPnPEvent - ) -/*++ -Routine Description: - - This routine is called from NDIS to notify our protocol edge of a - reconfiguration of parameters for either a specific binding (pAdapt - is not NULL), or global parameters if any (pAdapt is NULL). - -Arguments: - - pAdapt - Pointer to our adapter structure. - pNetPnPEvent - the reconfigure event - -Return Value: - - NDIS_STATUS_SUCCESS - ---*/ -{ - NDIS_STATUS ReconfigStatus = NDIS_STATUS_SUCCESS; - NDIS_STATUS ReturnStatus = NDIS_STATUS_SUCCESS; - - do - { - // - // Is this is a global reconfiguration notification ? - // - if (pAdapt == NULL) - { - // - // An important event that causes this notification to us is if - // one of our upper-edge miniport instances was enabled after being - // disabled earlier, e.g. from Device Manager in Win2000. Note that - // NDIS calls this because we had set up an association between our - // miniport and protocol entities by calling NdisIMAssociateMiniport. - // - // Since we would have torn down the lower binding for that miniport, - // we need NDIS' assistance to re-bind to the lower miniport. The - // call to NdisReEnumerateProtocolBindings does exactly that. - // - NdisReEnumerateProtocolBindings (ProtHandle); - - break; - } - -#ifdef NDIS51 - // - // Pass on this notification to protocol(s) above before doing anything - // with it. - // - if (pAdapt->MiniportHandle) - { - ReturnStatus = NdisIMNotifyPnPEvent(pAdapt->MiniportHandle, pNetPnPEvent); - } -#endif // NDIS51 - - ReconfigStatus = NDIS_STATUS_SUCCESS; - - } while(FALSE); - - DBGPRINT(("<==PtPNPNetEventReconfigure: pAdapt %p\n", pAdapt)); - -#ifdef NDIS51 - // - // Overwrite status with what upper-layer protocol(s) returned. - // - ReconfigStatus = ReturnStatus; -#endif - - return ReconfigStatus; -} - - -NDIS_STATUS -PtPnPNetEventSetPower( - IN PADAPT pAdapt, - IN PNET_PNP_EVENT pNetPnPEvent - ) -/*++ -Routine Description: - - This is a notification to our protocol edge of the power state - of the lower miniport. If it is going to a low-power state, we must - wait here for all outstanding sends and requests to complete. - - NDIS 5.1: Since we use packet stacking, it is not sufficient to - check usage of our local send packet pool to detect whether or not - all outstanding sends have completed. For this, use the new API - NdisQueryPendingIOCount. - - NDIS 5.1: Use the 5.1 API NdisIMNotifyPnPEvent to pass on PnP - notifications to upper protocol(s). - -Arguments: - - pAdapt - Pointer to the adpater structure - pNetPnPEvent - The Net Pnp Event. this contains the new device state - -Return Value: - - NDIS_STATUS_SUCCESS or the status returned by upper-layer protocols. - ---*/ -{ - PNDIS_DEVICE_POWER_STATE pDeviceState =(PNDIS_DEVICE_POWER_STATE)(pNetPnPEvent->Buffer); - NDIS_DEVICE_POWER_STATE PrevDeviceState = pAdapt->PTDeviceState; - NDIS_STATUS Status; - NDIS_STATUS ReturnStatus; - - ReturnStatus = NDIS_STATUS_SUCCESS; - - // - // Set the Internal Device State, this blocks all new sends or receives - // - NdisAcquireSpinLock(&pAdapt->Lock); - pAdapt->PTDeviceState = *pDeviceState; - - // - // Check if the miniport below is going to a low power state. - // - if (pAdapt->PTDeviceState > NdisDeviceStateD0) - { - // - // If the miniport below is going to standby, fail all incoming requests - // - if (PrevDeviceState == NdisDeviceStateD0) - { - pAdapt->StandingBy = TRUE; - } - - NdisReleaseSpinLock(&pAdapt->Lock); - -#ifdef NDIS51 - // - // Notify upper layer protocol(s) first. - // - if (pAdapt->MiniportHandle != NULL) - { - ReturnStatus = NdisIMNotifyPnPEvent(pAdapt->MiniportHandle, pNetPnPEvent); - } -#endif // NDIS51 - - // - // Wait for outstanding sends and requests to complete. - // - while (pAdapt->OutstandingSends != 0) - { - NdisMSleep(2); - } - - while (pAdapt->OutstandingRequests == TRUE) - { - // - // sleep till outstanding requests complete - // - NdisMSleep(2); - } - - // - // If the below miniport is going to low power state, complete the queued request - // - NdisAcquireSpinLock(&pAdapt->Lock); - if (pAdapt->QueuedRequest) - { - pAdapt->QueuedRequest = FALSE; - NdisReleaseSpinLock(&pAdapt->Lock); - PtRequestComplete(pAdapt, &pAdapt->Request, NDIS_STATUS_FAILURE); - } - else - { - NdisReleaseSpinLock(&pAdapt->Lock); - } - - - ASSERT(NdisPacketPoolUsage(pAdapt->SendPacketPoolHandle) == 0); - ASSERT(pAdapt->OutstandingRequests == FALSE); - } - else - { - // - // If the physical miniport is powering up (from Low power state to D0), - // clear the flag - // - if (PrevDeviceState > NdisDeviceStateD0) - { - pAdapt->StandingBy = FALSE; - } - // - // The device below is being turned on. If we had a request - // pending, send it down now. - // - if (pAdapt->QueuedRequest == TRUE) - { - pAdapt->QueuedRequest = FALSE; - - pAdapt->OutstandingRequests = TRUE; - NdisReleaseSpinLock(&pAdapt->Lock); - - NdisRequest(&Status, - pAdapt->BindingHandle, - &pAdapt->Request); - - if (Status != NDIS_STATUS_PENDING) - { - PtRequestComplete(pAdapt, - &pAdapt->Request, - Status); - - } - } - else - { - NdisReleaseSpinLock(&pAdapt->Lock); - } - - -#ifdef NDIS51 - // - // Pass on this notification to protocol(s) above - // - if (pAdapt->MiniportHandle) - { - ReturnStatus = NdisIMNotifyPnPEvent(pAdapt->MiniportHandle, pNetPnPEvent); - } -#endif // NDIS51 - - } - - return ReturnStatus; -} - -VOID -PtReferenceAdapt( - IN PADAPT pAdapt - ) -{ - NdisAcquireSpinLock(&pAdapt->Lock); - - ASSERT(pAdapt->RefCount >= 0); - - pAdapt->RefCount ++; - NdisReleaseSpinLock(&pAdapt->Lock); -} - - -BOOLEAN -PtDereferenceAdapt( - IN PADAPT pAdapt - ) -{ - NdisAcquireSpinLock(&pAdapt->Lock); - - ASSERT(pAdapt->RefCount > 0); - - pAdapt->RefCount--; - - if (pAdapt->RefCount == 0) - { - NdisReleaseSpinLock(&pAdapt->Lock); - - // - // Free all resources on this adapter structure. - // - MPFreeAllPacketPools (pAdapt);; - NdisFreeSpinLock(&pAdapt->Lock); - NdisFreeMemory(pAdapt, 0 , 0); - - return TRUE; - - } - else - { - NdisReleaseSpinLock(&pAdapt->Lock); - - return FALSE; - } -} - - diff --git a/original_passthru/makefile b/original_passthru/makefile deleted file mode 100644 index c6c9e94..0000000 --- a/original_passthru/makefile +++ /dev/null @@ -1,22 +0,0 @@ -# -# DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source -# file to this component. This file merely indirects to the real make file -# that is shared by all the components of NT -# - -#!INCLUDE $(NTMAKEENV)\makefile.def - - -!IF DEFINED(_NT_TARGET_VERSION) -! IF $(_NT_TARGET_VERSION)>=0x501 -! INCLUDE $(NTMAKEENV)\makefile.def -! ELSE -# Only warn once per directory -! INCLUDE $(NTMAKEENV)\makefile.plt -! IF "$(BUILD_PASS)"=="PASS1" -! message BUILDMSG: Warning : The sample "$(MAKEDIR)" is not valid for the current OS target. -! ENDIF -! ENDIF -!ELSE -! INCLUDE $(NTMAKEENV)\makefile.def -!ENDIF diff --git a/original_passthru/miniport.c b/original_passthru/miniport.c deleted file mode 100644 index a7f3bbc..0000000 --- a/original_passthru/miniport.c +++ /dev/null @@ -1,1461 +0,0 @@ -/*++ - -Copyright (c) 1992-2000 Microsoft Corporation - -Module Name: - - miniport.c - -Abstract: - - Ndis Intermediate Miniport driver sample. This is a passthru driver. - -Author: - -Environment: - - -Revision History: - - ---*/ - -#include "precomp.h" -#pragma hdrstop - - - -NDIS_STATUS -MPInitialize( - OUT PNDIS_STATUS OpenErrorStatus, - OUT PUINT SelectedMediumIndex, - IN PNDIS_MEDIUM MediumArray, - IN UINT MediumArraySize, - IN NDIS_HANDLE MiniportAdapterHandle, - IN NDIS_HANDLE WrapperConfigurationContext - ) -/*++ - -Routine Description: - - This is the initialize handler which gets called as a result of - the BindAdapter handler calling NdisIMInitializeDeviceInstanceEx. - The context parameter which we pass there is the adapter structure - which we retrieve here. - - Arguments: - - OpenErrorStatus Not used by us. - SelectedMediumIndex Place-holder for what media we are using - MediumArray Array of ndis media passed down to us to pick from - MediumArraySize Size of the array - MiniportAdapterHandle The handle NDIS uses to refer to us - WrapperConfigurationContext For use by NdisOpenConfiguration - -Return Value: - - NDIS_STATUS_SUCCESS unless something goes wrong - ---*/ -{ - UINT i; - PADAPT pAdapt; - NDIS_STATUS Status = NDIS_STATUS_FAILURE; - NDIS_MEDIUM Medium; - - UNREFERENCED_PARAMETER(WrapperConfigurationContext); - - do - { - // - // Start off by retrieving our adapter context and storing - // the Miniport handle in it. - // - pAdapt = NdisIMGetDeviceContext(MiniportAdapterHandle); - pAdapt->MiniportIsHalted = FALSE; - - DBGPRINT(("==> Miniport Initialize: Adapt %p\n", pAdapt)); - - // - // Usually we export the medium type of the adapter below as our - // virtual miniport's medium type. However if the adapter below us - // is a WAN device, then we claim to be of medium type 802.3. - // - Medium = pAdapt->Medium; - - if (Medium == NdisMediumWan) - { - Medium = NdisMedium802_3; - } - - for (i = 0; i < MediumArraySize; i++) - { - if (MediumArray[i] == Medium) - { - *SelectedMediumIndex = i; - break; - } - } - - if (i == MediumArraySize) - { - Status = NDIS_STATUS_UNSUPPORTED_MEDIA; - break; - } - - - // - // Set the attributes now. NDIS_ATTRIBUTE_DESERIALIZE enables us - // to make up-calls to NDIS without having to call NdisIMSwitchToMiniport - // or NdisIMQueueCallBack. This also forces us to protect our data using - // spinlocks where appropriate. Also in this case NDIS does not queue - // packets on our behalf. Since this is a very simple pass-thru - // miniport, we do not have a need to protect anything. However in - // a general case there will be a need to use per-adapter spin-locks - // for the packet queues at the very least. - // - NdisMSetAttributesEx(MiniportAdapterHandle, - pAdapt, - 0, // CheckForHangTimeInSeconds - NDIS_ATTRIBUTE_IGNORE_PACKET_TIMEOUT | - NDIS_ATTRIBUTE_IGNORE_REQUEST_TIMEOUT| - NDIS_ATTRIBUTE_INTERMEDIATE_DRIVER | - NDIS_ATTRIBUTE_DESERIALIZE | - NDIS_ATTRIBUTE_NO_HALT_ON_SUSPEND, - 0); - - pAdapt->MiniportHandle = MiniportAdapterHandle; - // - // Initialize LastIndicatedStatus to be NDIS_STATUS_MEDIA_CONNECT - // - pAdapt->LastIndicatedStatus = NDIS_STATUS_MEDIA_CONNECT; - - // - // Initialize the power states for both the lower binding (PTDeviceState) - // and our miniport edge to Powered On. - // - pAdapt->MPDeviceState = NdisDeviceStateD0; - pAdapt->PTDeviceState = NdisDeviceStateD0; - - // - // Add this adapter to the global pAdapt List - // - NdisAcquireSpinLock(&GlobalLock); - - pAdapt->Next = pAdaptList; - pAdaptList = pAdapt; - - NdisReleaseSpinLock(&GlobalLock); - - // - // Create an ioctl interface - // - (VOID)PtRegisterDevice(); - - Status = NDIS_STATUS_SUCCESS; - } - while (FALSE); - - // - // If we had received an UnbindAdapter notification on the underlying - // adapter, we would have blocked that thread waiting for the IM Init - // process to complete. Wake up any such thread. - // - ASSERT(pAdapt->MiniportInitPending == TRUE); - pAdapt->MiniportInitPending = FALSE; - NdisSetEvent(&pAdapt->MiniportInitEvent); - - if (Status == NDIS_STATUS_SUCCESS) - { - PtReferenceAdapt(pAdapt); - } - - DBGPRINT(("<== Miniport Initialize: Adapt %p, Status %x\n", pAdapt, Status)); - - *OpenErrorStatus = Status; - - - return Status; -} - - -NDIS_STATUS -MPSend( - IN NDIS_HANDLE MiniportAdapterContext, - IN PNDIS_PACKET Packet, - IN UINT Flags - ) -/*++ - -Routine Description: - - Send Packet handler. Either this or our SendPackets (array) handler is called - based on which one is enabled in our Miniport Characteristics. - -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; - PVOID MediaSpecificInfo = NULL; - ULONG MediaSpecificInfoSize = 0; - - // - // The driver should fail the send if the virtual miniport is in low - // power state - // - if (pAdapt->MPDeviceState > NdisDeviceStateD0) - { - return NDIS_STATUS_FAILURE; - } - -#ifdef NDIS51 - // - // Use NDIS 5.1 packet stacking: - // - { - PNDIS_PACKET_STACK pStack; - BOOLEAN Remaining; - - // - // Packet stacks: Check if we can use the same packet for sending down. - // - - pStack = NdisIMGetCurrentPacketStack(Packet, &Remaining); - if (Remaining) - { - // - // We can reuse "Packet". - // - // NOTE: if we needed to keep per-packet information in packets - // sent down, we can use pStack->IMReserved[]. - // - ASSERT(pStack); - // - // If the below miniport is going to low power state, stop sending down any packet. - // - NdisAcquireSpinLock(&pAdapt->Lock); - if (pAdapt->PTDeviceState > NdisDeviceStateD0) - { - NdisReleaseSpinLock(&pAdapt->Lock); - return NDIS_STATUS_FAILURE; - } - pAdapt->OutstandingSends++; - NdisReleaseSpinLock(&pAdapt->Lock); - NdisSend(&Status, - pAdapt->BindingHandle, - Packet); - - if (Status != NDIS_STATUS_PENDING) - { - ADAPT_DECR_PENDING_SENDS(pAdapt); - } - - return(Status); - } - } -#endif // NDIS51 - - // - // We are either not using packet stacks, or there isn't stack space - // in the original packet passed down to us. Allocate a new packet - // to wrap the data with. - // - // - // If the below miniport is going to low power state, stop sending down any packet. - // - NdisAcquireSpinLock(&pAdapt->Lock); - if (pAdapt->PTDeviceState > NdisDeviceStateD0) - { - NdisReleaseSpinLock(&pAdapt->Lock); - return NDIS_STATUS_FAILURE; - - } - pAdapt->OutstandingSends++; - NdisReleaseSpinLock(&pAdapt->Lock); - - NdisAllocatePacket(&Status, - &MyPacket, - pAdapt->SendPacketPoolHandle); - - if (Status == NDIS_STATUS_SUCCESS) - { - PSEND_RSVD SendRsvd; - - // - // Save a pointer to the original packet in our reserved - // area in the new packet. This is needed so that we can - // get back to the original packet when the new packet's send - // is completed. - // - SendRsvd = (PSEND_RSVD)(MyPacket->ProtocolReserved); - SendRsvd->OriginalPkt = Packet; - - NdisGetPacketFlags(MyPacket) = Flags; - - // - // Set up the new packet so that it describes the same - // data as the original packet. - // - NDIS_PACKET_FIRST_NDIS_BUFFER(MyPacket) = NDIS_PACKET_FIRST_NDIS_BUFFER(Packet); - NDIS_PACKET_LAST_NDIS_BUFFER(MyPacket) = NDIS_PACKET_LAST_NDIS_BUFFER(Packet); -#ifdef WIN9X - // - // Work around the fact that NDIS does not initialize this - // to FALSE on Win9x. - // - NDIS_PACKET_VALID_COUNTS(MyPacket) = FALSE; -#endif - - // - // 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)); - -#ifndef WIN9X - // - // Copy the right parts of per packet info into the new packet. - // This API is not available on Win9x since task offload is - // not supported on that platform. - // - NdisIMCopySendPerPacketInfo(MyPacket, Packet); -#endif - - // - // 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) - { -#ifndef WIN9X - NdisIMCopySendCompletePerPacketInfo (Packet, MyPacket); -#endif - NdisFreePacket(MyPacket); - ADAPT_DECR_PENDING_SENDS(pAdapt); - } - } - else - { - ADAPT_DECR_PENDING_SENDS(pAdapt); - // - // 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); -} - - -VOID -MPSendPackets( - IN NDIS_HANDLE MiniportAdapterContext, - IN PPNDIS_PACKET PacketArray, - IN UINT NumberOfPackets - ) -/*++ - -Routine Description: - - Send Packet Array handler. Either this or our SendPacket handler is called - based on which one is enabled in our Miniport Characteristics. - -Arguments: - - MiniportAdapterContext Pointer to our adapter - PacketArray Set of packets to send - NumberOfPackets Self-explanatory - -Return Value: - - None - ---*/ -{ - PADAPT pAdapt = (PADAPT)MiniportAdapterContext; - NDIS_STATUS Status; - UINT i; - PVOID MediaSpecificInfo = NULL; - UINT MediaSpecificInfoSize = 0; - - - for (i = 0; i < NumberOfPackets; i++) - { - PNDIS_PACKET Packet, MyPacket; - - Packet = PacketArray[i]; - // - // The driver should fail the send if the virtual miniport is in low - // power state - // - if (pAdapt->MPDeviceState > NdisDeviceStateD0) - { - NdisMSendComplete(ADAPT_MINIPORT_HANDLE(pAdapt), - Packet, - NDIS_STATUS_FAILURE); - continue; - } - -#ifdef NDIS51 - - // - // Use NDIS 5.1 packet stacking: - // - { - PNDIS_PACKET_STACK pStack; - BOOLEAN Remaining; - - // - // Packet stacks: Check if we can use the same packet for sending down. - // - pStack = NdisIMGetCurrentPacketStack(Packet, &Remaining); - if (Remaining) - { - // - // We can reuse "Packet". - // - // NOTE: if we needed to keep per-packet information in packets - // sent down, we can use pStack->IMReserved[]. - // - ASSERT(pStack); - // - // If the below miniport is going to low power state, stop sending down any packet. - // - NdisAcquireSpinLock(&pAdapt->Lock); - if (pAdapt->PTDeviceState > NdisDeviceStateD0) - { - NdisReleaseSpinLock(&pAdapt->Lock); - NdisMSendComplete(ADAPT_MINIPORT_HANDLE(pAdapt), - Packet, - NDIS_STATUS_FAILURE); - } - else - { - pAdapt->OutstandingSends++; - NdisReleaseSpinLock(&pAdapt->Lock); - - NdisSend(&Status, - pAdapt->BindingHandle, - Packet); - - if (Status != NDIS_STATUS_PENDING) - { - NdisMSendComplete(ADAPT_MINIPORT_HANDLE(pAdapt), - Packet, - Status); - - ADAPT_DECR_PENDING_SENDS(pAdapt); - } - } - continue; - } - } -#endif - do - { - NdisAcquireSpinLock(&pAdapt->Lock); - // - // If the below miniport is going to low power state, stop sending down any packet. - // - if (pAdapt->PTDeviceState > NdisDeviceStateD0) - { - NdisReleaseSpinLock(&pAdapt->Lock); - Status = NDIS_STATUS_FAILURE; - break; - } - pAdapt->OutstandingSends++; - NdisReleaseSpinLock(&pAdapt->Lock); - - NdisAllocatePacket(&Status, - &MyPacket, - pAdapt->SendPacketPoolHandle); - - if (Status == NDIS_STATUS_SUCCESS) - { - PSEND_RSVD SendRsvd; - - SendRsvd = (PSEND_RSVD)(MyPacket->ProtocolReserved); - SendRsvd->OriginalPkt = Packet; - - NdisGetPacketFlags(MyPacket) = NdisGetPacketFlags(Packet); - - NDIS_PACKET_FIRST_NDIS_BUFFER(MyPacket) = NDIS_PACKET_FIRST_NDIS_BUFFER(Packet); - NDIS_PACKET_LAST_NDIS_BUFFER(MyPacket) = NDIS_PACKET_LAST_NDIS_BUFFER(Packet); -#ifdef WIN9X - // - // Work around the fact that NDIS does not initialize this - // to FALSE on Win9x. - // - NDIS_PACKET_VALID_COUNTS(MyPacket) = FALSE; -#endif // WIN9X - - // - // Copy the OOB data 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 relevant parts of the per packet info into the new packet - // -#ifndef WIN9X - NdisIMCopySendPerPacketInfo(MyPacket, Packet); -#endif - - // - // 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) - { -#ifndef WIN9X - NdisIMCopySendCompletePerPacketInfo (Packet, MyPacket); -#endif - NdisFreePacket(MyPacket); - ADAPT_DECR_PENDING_SENDS(pAdapt); - } - } - else - { - // - // The driver cannot allocate a packet. - // - ADAPT_DECR_PENDING_SENDS(pAdapt); - } - } - while (FALSE); - - if (Status != NDIS_STATUS_PENDING) - { - NdisMSendComplete(ADAPT_MINIPORT_HANDLE(pAdapt), - Packet, - Status); - } - } -} - - -NDIS_STATUS -MPQueryInformation( - IN NDIS_HANDLE MiniportAdapterContext, - IN NDIS_OID Oid, - IN PVOID InformationBuffer, - IN ULONG InformationBufferLength, - OUT PULONG BytesWritten, - OUT PULONG BytesNeeded - ) -/*++ - -Routine Description: - - Entry point called by NDIS to query for the value of the specified OID. - Typical processing is to forward the query down to the underlying miniport. - - The following OIDs are filtered here: - - OID_PNP_QUERY_POWER - return success right here - - OID_GEN_SUPPORTED_GUIDS - do not forward, otherwise we will show up - multiple instances of private GUIDs supported by the underlying miniport. - - OID_PNP_CAPABILITIES - we do send this down to the lower miniport, but - the values returned are postprocessed before we complete this request; - see PtRequestComplete. - - NOTE on OID_TCP_TASK_OFFLOAD - if this IM driver modifies the contents - of data it passes through such that a lower miniport may not be able - to perform TCP task offload, then it should not forward this OID down, - but fail it here with the status NDIS_STATUS_NOT_SUPPORTED. This is to - avoid performing incorrect transformations on data. - - If our miniport edge (upper edge) is at a low-power state, fail the request. - - If our protocol edge (lower edge) has been notified of a low-power state, - we pend this request until the miniport below has been set to D0. Since - requests to miniports are serialized always, at most a single request will - be pended. - -Arguments: - - MiniportAdapterContext Pointer to the adapter structure - Oid Oid for this query - InformationBuffer Buffer for information - InformationBufferLength Size of this buffer - BytesWritten Specifies how much info is written - BytesNeeded In case the buffer is smaller than what we need, tell them how much is needed - - -Return Value: - - Return code from the NdisRequest below. - ---*/ -{ - PADAPT pAdapt = (PADAPT)MiniportAdapterContext; - NDIS_STATUS Status = NDIS_STATUS_FAILURE; - - do - { - if (Oid == OID_PNP_QUERY_POWER) - { - // - // Do not forward this. - // - Status = NDIS_STATUS_SUCCESS; - break; - } - - if (Oid == OID_GEN_SUPPORTED_GUIDS) - { - // - // Do not forward this, otherwise we will end up with multiple - // instances of private GUIDs that the underlying miniport - // supports. - // - Status = NDIS_STATUS_NOT_SUPPORTED; - break; - } - - if (Oid == OID_TCP_TASK_OFFLOAD) - { - // - // Fail this -if- this driver performs data transformations - // that can interfere with a lower driver's ability to offload - // TCP tasks. - // - // Status = NDIS_STATUS_NOT_SUPPORTED; - // break; - // - } - // - // If the miniport below is unbinding, just fail any request - // - NdisAcquireSpinLock(&pAdapt->Lock); - if (pAdapt->UnbindingInProcess == TRUE) - { - NdisReleaseSpinLock(&pAdapt->Lock); - Status = NDIS_STATUS_FAILURE; - break; - } - NdisReleaseSpinLock(&pAdapt->Lock); - // - // All other queries are failed, if the miniport is not at D0, - // - if (pAdapt->MPDeviceState > NdisDeviceStateD0) - { - Status = NDIS_STATUS_FAILURE; - break; - } - - pAdapt->Request.RequestType = NdisRequestQueryInformation; - pAdapt->Request.DATA.QUERY_INFORMATION.Oid = Oid; - pAdapt->Request.DATA.QUERY_INFORMATION.InformationBuffer = InformationBuffer; - pAdapt->Request.DATA.QUERY_INFORMATION.InformationBufferLength = InformationBufferLength; - pAdapt->BytesNeeded = BytesNeeded; - pAdapt->BytesReadOrWritten = BytesWritten; - - // - // If the miniport below is binding, fail the request - // - NdisAcquireSpinLock(&pAdapt->Lock); - - if (pAdapt->UnbindingInProcess == TRUE) - { - NdisReleaseSpinLock(&pAdapt->Lock); - Status = NDIS_STATUS_FAILURE; - break; - } - // - // If the Protocol device state is OFF, mark this request as being - // pended. We queue this until the device state is back to D0. - // - if ((pAdapt->PTDeviceState > NdisDeviceStateD0) - && (pAdapt->StandingBy == FALSE)) - { - pAdapt->QueuedRequest = TRUE; - NdisReleaseSpinLock(&pAdapt->Lock); - Status = NDIS_STATUS_PENDING; - break; - } - // - // This is in the process of powering down the system, always fail the request - // - if (pAdapt->StandingBy == TRUE) - { - NdisReleaseSpinLock(&pAdapt->Lock); - Status = NDIS_STATUS_FAILURE; - break; - } - pAdapt->OutstandingRequests = TRUE; - - NdisReleaseSpinLock(&pAdapt->Lock); - - // - // default case, most requests will be passed to the miniport below - // - NdisRequest(&Status, - pAdapt->BindingHandle, - &pAdapt->Request); - - - if (Status != NDIS_STATUS_PENDING) - { - PtRequestComplete(pAdapt, &pAdapt->Request, Status); - Status = NDIS_STATUS_PENDING; - } - - } while (FALSE); - - return(Status); - -} - - -VOID -MPQueryPNPCapabilities( - IN OUT PADAPT pAdapt, - OUT PNDIS_STATUS pStatus - ) -/*++ - -Routine Description: - - Postprocess a request for OID_PNP_CAPABILITIES that was forwarded - down to the underlying miniport, and has been completed by it. - -Arguments: - - pAdapt - Pointer to the adapter structure - pStatus - Place to return final status - -Return Value: - - None. - ---*/ - -{ - PNDIS_PNP_CAPABILITIES pPNPCapabilities; - PNDIS_PM_WAKE_UP_CAPABILITIES pPMstruct; - - if (pAdapt->Request.DATA.QUERY_INFORMATION.InformationBufferLength >= sizeof(NDIS_PNP_CAPABILITIES)) - { - pPNPCapabilities = (PNDIS_PNP_CAPABILITIES)(pAdapt->Request.DATA.QUERY_INFORMATION.InformationBuffer); - - // - // The following fields must be overwritten by an IM driver. - // - pPMstruct= & pPNPCapabilities->WakeUpCapabilities; - pPMstruct->MinMagicPacketWakeUp = NdisDeviceStateUnspecified; - pPMstruct->MinPatternWakeUp = NdisDeviceStateUnspecified; - pPMstruct->MinLinkChangeWakeUp = NdisDeviceStateUnspecified; - *pAdapt->BytesReadOrWritten = sizeof(NDIS_PNP_CAPABILITIES); - *pAdapt->BytesNeeded = 0; - - - // - // Setting our internal flags - // Default, device is ON - // - pAdapt->MPDeviceState = NdisDeviceStateD0; - pAdapt->PTDeviceState = NdisDeviceStateD0; - - *pStatus = NDIS_STATUS_SUCCESS; - } - else - { - *pAdapt->BytesNeeded= sizeof(NDIS_PNP_CAPABILITIES); - *pStatus = NDIS_STATUS_RESOURCES; - } -} - - -NDIS_STATUS -MPSetInformation( - IN NDIS_HANDLE MiniportAdapterContext, - IN NDIS_OID Oid, - __in_bcount(InformationBufferLength) IN PVOID InformationBuffer, - IN ULONG InformationBufferLength, - OUT PULONG BytesRead, - OUT PULONG BytesNeeded - ) -/*++ - -Routine Description: - - Miniport SetInfo handler. - - In the case of OID_PNP_SET_POWER, record the power state and return the OID. - Do not pass below - If the device is suspended, do not block the SET_POWER_OID - as it is used to reactivate the Passthru miniport - - - PM- If the MP is not ON (DeviceState > D0) return immediately (except for 'query power' and 'set power') - If MP is ON, but the PT is not at D0, then queue the queue the request for later processing - - Requests to miniports are always serialized - - -Arguments: - - MiniportAdapterContext Pointer to the adapter structure - Oid Oid for this query - InformationBuffer Buffer for information - InformationBufferLength Size of this buffer - BytesRead Specifies how much info is read - BytesNeeded In case the buffer is smaller than what we need, tell them how much is needed - -Return Value: - - Return code from the NdisRequest below. - ---*/ -{ - PADAPT pAdapt = (PADAPT)MiniportAdapterContext; - NDIS_STATUS Status; - - Status = NDIS_STATUS_FAILURE; - - do - { - // - // The Set Power should not be sent to the miniport below the Passthru, but is handled internally - // - if (Oid == OID_PNP_SET_POWER) - { - MPProcessSetPowerOid(&Status, - pAdapt, - InformationBuffer, - InformationBufferLength, - BytesRead, - BytesNeeded); - break; - - } - - // - // If the miniport below is unbinding, fail the request - // - NdisAcquireSpinLock(&pAdapt->Lock); - if (pAdapt->UnbindingInProcess == TRUE) - { - NdisReleaseSpinLock(&pAdapt->Lock); - Status = NDIS_STATUS_FAILURE; - break; - } - NdisReleaseSpinLock(&pAdapt->Lock); - // - // All other Set Information requests are failed, if the miniport is - // not at D0 or is transitioning to a device state greater than D0. - // - if (pAdapt->MPDeviceState > NdisDeviceStateD0) - { - Status = NDIS_STATUS_FAILURE; - break; - } - - // Set up the Request and return the result - pAdapt->Request.RequestType = NdisRequestSetInformation; - pAdapt->Request.DATA.SET_INFORMATION.Oid = Oid; - pAdapt->Request.DATA.SET_INFORMATION.InformationBuffer = InformationBuffer; - pAdapt->Request.DATA.SET_INFORMATION.InformationBufferLength = InformationBufferLength; - pAdapt->BytesNeeded = BytesNeeded; - pAdapt->BytesReadOrWritten = BytesRead; - - // - // If the miniport below is unbinding, fail the request - // - NdisAcquireSpinLock(&pAdapt->Lock); - if (pAdapt->UnbindingInProcess == TRUE) - { - NdisReleaseSpinLock(&pAdapt->Lock); - Status = NDIS_STATUS_FAILURE; - break; - } - - // - // If the device below is at a low power state, we cannot send it the - // request now, and must pend it. - // - if ((pAdapt->PTDeviceState > NdisDeviceStateD0) - && (pAdapt->StandingBy == FALSE)) - { - pAdapt->QueuedRequest = TRUE; - NdisReleaseSpinLock(&pAdapt->Lock); - Status = NDIS_STATUS_PENDING; - break; - } - // - // This is in the process of powering down the system, always fail the request - // - if (pAdapt->StandingBy == TRUE) - { - NdisReleaseSpinLock(&pAdapt->Lock); - Status = NDIS_STATUS_FAILURE; - break; - } - pAdapt->OutstandingRequests = TRUE; - - NdisReleaseSpinLock(&pAdapt->Lock); - // - // Forward the request to the device below. - // - NdisRequest(&Status, - pAdapt->BindingHandle, - &pAdapt->Request); - - if (Status != NDIS_STATUS_PENDING) - { - *BytesRead = pAdapt->Request.DATA.SET_INFORMATION.BytesRead; - *BytesNeeded = pAdapt->Request.DATA.SET_INFORMATION.BytesNeeded; - pAdapt->OutstandingRequests = FALSE; - } - - } while (FALSE); - - return(Status); -} - - -VOID -MPProcessSetPowerOid( - IN OUT PNDIS_STATUS pNdisStatus, - IN PADAPT pAdapt, - __in_bcount(InformationBufferLength) IN PVOID InformationBuffer, - IN ULONG InformationBufferLength, - OUT PULONG BytesRead, - OUT PULONG BytesNeeded - ) -/*++ - -Routine Description: - This routine does all the procssing for a request with a SetPower Oid - The miniport shoud accept the Set Power and transition to the new state - - The Set Power should not be passed to the miniport below - - If the IM miniport is going into a low power state, then there is no guarantee if it will ever - be asked go back to D0, before getting halted. No requests should be pended or queued. - - -Arguments: - pNdisStatus - Status of the operation - pAdapt - The Adapter structure - InformationBuffer - The New DeviceState - InformationBufferLength - BytesRead - No of bytes read - BytesNeeded - No of bytes needed - - -Return Value: - Status - NDIS_STATUS_SUCCESS if all the wait events succeed. - ---*/ -{ - - - NDIS_DEVICE_POWER_STATE NewDeviceState; - - DBGPRINT(("==>MPProcessSetPowerOid: Adapt %p\n", pAdapt)); - - ASSERT (InformationBuffer != NULL); - - *pNdisStatus = NDIS_STATUS_FAILURE; - - do - { - // - // Check for invalid length - // - if (InformationBufferLength < sizeof(NDIS_DEVICE_POWER_STATE)) - { - *pNdisStatus = NDIS_STATUS_INVALID_LENGTH; - break; - } - - NewDeviceState = (*(PNDIS_DEVICE_POWER_STATE)InformationBuffer); - - // - // Check for invalid device state - // - if ((pAdapt->MPDeviceState > NdisDeviceStateD0) && (NewDeviceState != NdisDeviceStateD0)) - { - // - // If the miniport is in a non-D0 state, the miniport can only receive a Set Power to D0 - // - ASSERT (!(pAdapt->MPDeviceState > NdisDeviceStateD0) && (NewDeviceState != NdisDeviceStateD0)); - - *pNdisStatus = NDIS_STATUS_FAILURE; - break; - } - - // - // Is the miniport transitioning from an On (D0) state to an Low Power State (>D0) - // If so, then set the StandingBy Flag - (Block all incoming requests) - // - if (pAdapt->MPDeviceState == NdisDeviceStateD0 && NewDeviceState > NdisDeviceStateD0) - { - pAdapt->StandingBy = TRUE; - } - - // - // If the miniport is transitioning from a low power state to ON (D0), then clear the StandingBy flag - // All incoming requests will be pended until the physical miniport turns ON. - // - if (pAdapt->MPDeviceState > NdisDeviceStateD0 && NewDeviceState == NdisDeviceStateD0) - { - pAdapt->StandingBy = FALSE; - } - - // - // Now update the state in the pAdapt structure; - // - pAdapt->MPDeviceState = NewDeviceState; - - *pNdisStatus = NDIS_STATUS_SUCCESS; - - - } while (FALSE); - - if (*pNdisStatus == NDIS_STATUS_SUCCESS) - { - // - // The miniport resume from low power state - // - if (pAdapt->StandingBy == FALSE) - { - // - // If we need to indicate the media connect state - // - if (pAdapt->LastIndicatedStatus != pAdapt->LatestUnIndicateStatus) - { - if (pAdapt->MiniportHandle != NULL) - { - NdisMIndicateStatus(pAdapt->MiniportHandle, - pAdapt->LatestUnIndicateStatus, - (PVOID)NULL, - 0); - NdisMIndicateStatusComplete(pAdapt->MiniportHandle); - pAdapt->LastIndicatedStatus = pAdapt->LatestUnIndicateStatus; - } - } - } - else - { - // - // Initialize LatestUnIndicatedStatus - // - pAdapt->LatestUnIndicateStatus = pAdapt->LastIndicatedStatus; - } - *BytesRead = sizeof(NDIS_DEVICE_POWER_STATE); - *BytesNeeded = 0; - } - else - { - *BytesRead = 0; - *BytesNeeded = sizeof (NDIS_DEVICE_POWER_STATE); - } - - DBGPRINT(("<==MPProcessSetPowerOid: Adapt %p\n", pAdapt)); -} - - -VOID -MPReturnPacket( - IN NDIS_HANDLE MiniportAdapterContext, - IN PNDIS_PACKET Packet - ) -/*++ - -Routine Description: - - NDIS Miniport entry point called whenever protocols are done with - a packet that we had indicated up and they had queued up for returning - later. - -Arguments: - - MiniportAdapterContext - pointer to ADAPT structure - Packet - packet being returned. - -Return Value: - - None. - ---*/ -{ - PADAPT pAdapt = (PADAPT)MiniportAdapterContext; - -#ifdef NDIS51 - // - // Packet stacking: Check if this packet belongs to us. - // - if (NdisGetPoolFromPacket(Packet) != pAdapt->RecvPacketPoolHandle) - { - // - // We reused the original packet in a receive indication. - // Simply return it to the miniport below us. - // - NdisReturnPackets(&Packet, 1); - } - else -#endif // NDIS51 - { - // - // This is a packet allocated from this IM's receive packet pool. - // Reclaim our packet, and return the original to the driver below. - // - - PNDIS_PACKET MyPacket; - PRECV_RSVD RecvRsvd; - - RecvRsvd = (PRECV_RSVD)(Packet->MiniportReserved); - MyPacket = RecvRsvd->OriginalPkt; - - NdisFreePacket(Packet); - NdisReturnPackets(&MyPacket, 1); - } -} - - -NDIS_STATUS -MPTransferData( - OUT PNDIS_PACKET Packet, - OUT PUINT BytesTransferred, - IN NDIS_HANDLE MiniportAdapterContext, - IN NDIS_HANDLE MiniportReceiveContext, - IN UINT ByteOffset, - IN UINT BytesToTransfer - ) -/*++ - -Routine Description: - - Miniport's transfer data handler. - -Arguments: - - Packet Destination packet - BytesTransferred Place-holder for how much data was copied - MiniportAdapterContext Pointer to the adapter structure - MiniportReceiveContext Context - ByteOffset Offset into the packet for copying data - BytesToTransfer How much to copy. - -Return Value: - - Status of transfer - ---*/ -{ - PADAPT pAdapt = (PADAPT)MiniportAdapterContext; - NDIS_STATUS Status; - - // - // Return, if the device is OFF - // - - if (IsIMDeviceStateOn(pAdapt) == FALSE) - { - return NDIS_STATUS_FAILURE; - } - - NdisTransferData(&Status, - pAdapt->BindingHandle, - MiniportReceiveContext, - ByteOffset, - BytesToTransfer, - Packet, - BytesTransferred); - - return(Status); -} - -VOID -MPHalt( - IN NDIS_HANDLE MiniportAdapterContext - ) -/*++ - -Routine Description: - - Halt handler. All the hard-work for clean-up is done here. - -Arguments: - - MiniportAdapterContext Pointer to the Adapter - -Return Value: - - None. - ---*/ -{ - PADAPT pAdapt = (PADAPT)MiniportAdapterContext; - NDIS_STATUS Status; - PADAPT *ppCursor; - - DBGPRINT(("==>MiniportHalt: Adapt %p\n", pAdapt)); - - pAdapt->MiniportHandle = NULL; - pAdapt->MiniportIsHalted = TRUE; - - // - // Remove this adapter from the global list - // - NdisAcquireSpinLock(&GlobalLock); - - for (ppCursor = &pAdaptList; *ppCursor != NULL; ppCursor = &(*ppCursor)->Next) - { - if (*ppCursor == pAdapt) - { - *ppCursor = pAdapt->Next; - break; - } - } - - NdisReleaseSpinLock(&GlobalLock); - - // - // Delete the ioctl interface that was created when the miniport - // was created. - // - (VOID)PtDeregisterDevice(); - - // - // If we have a valid bind, close the miniport below the protocol - // -#pragma prefast(suppress: __WARNING_DEREF_NULL_PTR, "pAdapt cannot be NULL") - if (pAdapt->BindingHandle != NULL) - { - // - // Close the binding below. and wait for it to complete - // - NdisResetEvent(&pAdapt->Event); - - NdisCloseAdapter(&Status, pAdapt->BindingHandle); - - if (Status == NDIS_STATUS_PENDING) - { - NdisWaitEvent(&pAdapt->Event, 0); - Status = pAdapt->Status; - } - - ASSERT (Status == NDIS_STATUS_SUCCESS); - - pAdapt->BindingHandle = NULL; - - PtDereferenceAdapt(pAdapt); - } - - if (PtDereferenceAdapt(pAdapt)) - { - pAdapt = NULL; - } - - - DBGPRINT(("<== MiniportHalt: pAdapt %p\n", pAdapt)); -} - - -#ifdef NDIS51_MINIPORT - -VOID -MPCancelSendPackets( - IN NDIS_HANDLE MiniportAdapterContext, - IN PVOID CancelId - ) -/*++ - -Routine Description: - - The miniport entry point to handle cancellation of all send packets - that match the given CancelId. If we have queued any packets that match - this, then we should dequeue them and call NdisMSendComplete for all - such packets, with a status of NDIS_STATUS_REQUEST_ABORTED. - - We should also call NdisCancelSendPackets in turn, on each lower binding - that this adapter corresponds to. This is to let miniports below cancel - any matching packets. - -Arguments: - - MiniportAdapterContext - pointer to ADAPT structure - CancelId - ID of packets to be cancelled. - -Return Value: - - None - ---*/ -{ - PADAPT pAdapt = (PADAPT)MiniportAdapterContext; - - // - // If we queue packets on our adapter structure, this would be - // the place to acquire a spinlock to it, unlink any packets whose - // Id matches CancelId, release the spinlock and call NdisMSendComplete - // with NDIS_STATUS_REQUEST_ABORTED for all unlinked packets. - // - - // - // Next, pass this down so that we let the miniport(s) below cancel - // any packets that they might have queued. - // - NdisCancelSendPackets(pAdapt->BindingHandle, CancelId); - - return; -} - -VOID -MPDevicePnPEvent( - IN NDIS_HANDLE MiniportAdapterContext, - IN NDIS_DEVICE_PNP_EVENT DevicePnPEvent, - IN PVOID InformationBuffer, - IN ULONG InformationBufferLength - ) -/*++ - -Routine Description: - - This handler is called to notify us of PnP events directed to - our miniport device object. - -Arguments: - - MiniportAdapterContext - pointer to ADAPT structure - DevicePnPEvent - the event - InformationBuffer - Points to additional event-specific information - InformationBufferLength - length of above - -Return Value: - - None ---*/ -{ - // TBD - add code/comments about processing this. - - UNREFERENCED_PARAMETER(MiniportAdapterContext); - UNREFERENCED_PARAMETER(DevicePnPEvent); - UNREFERENCED_PARAMETER(InformationBuffer); - UNREFERENCED_PARAMETER(InformationBufferLength); - - return; -} - -VOID -MPAdapterShutdown( - IN NDIS_HANDLE MiniportAdapterContext - ) -/*++ - -Routine Description: - - This handler is called to notify us of an impending system shutdown. - -Arguments: - - MiniportAdapterContext - pointer to ADAPT structure - -Return Value: - - None ---*/ -{ - UNREFERENCED_PARAMETER(MiniportAdapterContext); - - return; -} - -#endif - - -VOID -MPFreeAllPacketPools( - IN PADAPT pAdapt - ) -/*++ - -Routine Description: - - Free all packet pools on the specified adapter. - -Arguments: - - pAdapt - pointer to ADAPT structure - -Return Value: - - None - ---*/ -{ - if (pAdapt->RecvPacketPoolHandle != NULL) - { - // - // Free the packet pool that is used to indicate receives - // - NdisFreePacketPool(pAdapt->RecvPacketPoolHandle); - - pAdapt->RecvPacketPoolHandle = NULL; - } - - if (pAdapt->SendPacketPoolHandle != NULL) - { - - // - // Free the packet pool that is used to send packets below - // - - NdisFreePacketPool(pAdapt->SendPacketPoolHandle); - - pAdapt->SendPacketPoolHandle = NULL; - - } -} - diff --git a/original_passthru/netsf.inf b/original_passthru/netsf.inf deleted file mode 100644 index 5e03a01..0000000 --- a/original_passthru/netsf.inf +++ /dev/null @@ -1,165 +0,0 @@ -; -- NETSF.INF -- -; -; Passthru driver INF file - this is the INF for the service (protocol) -; part. -; -; Copyright (c) 1993-2001, Microsoft Corporation -; -; ---------------------------------------------------------------------- -; Notes: -; 0. The term "filter" is used in this INF to refer to an NDIS IM driver that -; implements a 1:1 relationship between upper and lower bindings. -; -; 1. Items specifically required for a filter have been marked with -; "!!--Filter Specific--!!" keyword -; 2. In general a filter DOES NOT require a notify object for proper installation. -; A notify object is only required if one wants to have better control -; over binding operations or if one wants to receive notifications -; when other components get installed/removed/bound/unbound. -; Since Windows 2000 systems do not have support for CopyINF directive, -; a notify object is required to programmatically copy the miniport INF -; file to the system INF directory. Previous versions of this INF file -; erroneously used to copy the INF files directly by using the CopyFiles -; directive. -; On Windows XP, you can install a filter IM without a notify object. -; by following the instructions in (4). -; -; 3. If you want to use this INF file with your own IM driver, please -; make the following modifications: -; File netsf.inf -; -------------- -; a. In section [SourceDiskFiles] and [Passthru.Files.Sys] -; change passthru.sys to the name of your own driver binary. -; b. In section [Passthru.ndi.AddReg], change values of -; BindForm and MiniportId to appropriate values. -; File netsf_m.inf -; ---------------- -; a. Replace MS_PassthruMP with InfId of your miniport. -; b. In section [PassthruMP.AddService], -; change ServiceBinary appropriately. -; c. In section [PassthruMP.ndi.AddReg], -; change "Passthru" in the line having "Service" -; to reflect the appropriate name -; -; -; ---------------------------------------------------------------------- - -[Version] -Signature = "$Windows NT$" -Class = NetService -ClassGUID = {4D36E974-E325-11CE-BFC1-08002BE10318} -Provider = %Msft% -DriverVer =10/01/2002,6.0.5019.0 - -[Manufacturer] -%Msft% = MSFT,NTx86,NTia64,NTamd64 - -[ControlFlags] - -;========================================================================= -; -;========================================================================= -;For Win2K - -[MSFT] -%Passthru_Desc% = Passthru.ndi, ms_passthru - -;For WinXP and later - -[MSFT.NTx86] -%Passthru_Desc% = Passthru.ndi, ms_passthru - -[MSFT.NTia64] -%Passthru_Desc% = Passthru.ndi, ms_passthru - -[MSFT.NTamd64] -%Passthru_Desc% = Passthru.ndi, ms_passthru - - -[Passthru.ndi] -AddReg = Passthru.ndi.AddReg, Passthru.AddReg -Characteristics = 0x4410 ; NCF_FILTER | NCF_NDIS_PROTOCOL !--Filter Specific--!! -CopyFiles = Passthru.Files.Sys -CopyInf = netsf_m.inf - -[Passthru.ndi.Remove] -DelFiles = Passthru.Files.Sys - -[Passthru.ndi.Services] -AddService = Passthru,, Passthru.AddService - -[Passthru.AddService] -DisplayName = %PassthruService_Desc% -ServiceType = 1 ;SERVICE_KERNEL_DRIVER -StartType = 3 ;SERVICE_DEMAND_START -ErrorControl = 1 ;SERVICE_ERROR_NORMAL -ServiceBinary = %12%\passthru.sys -AddReg = Passthru.AddService.AddReg - - -[Passthru.AddService.AddReg] -; ---------------------------------------------------------------------- -; Add any miniport-specific parameters here. These are params that your -; filter device is going to use. -; -;HKR, Parameters, ParameterName, 0x10000, "MultiSz", "Parameter", "Value" -;HKR, Parameters, ParameterName2, 0x10001, 4 - - -; ---------------------------------------------------------------------- -; File copy -; -[SourceDisksNames] -1=%DiskDescription%,"",, - -[SourceDisksFiles] -passthru.sys=1 - -[DestinationDirs] -DefaultDestDir = 12 -Passthru.Files.Sys = 12 ; %windir%\System32\drivers - -[Passthru.Files.Sys] -passthru.sys,,,2 - -; ---------------------------------------------------------------------- -; Filter Install -; - -[Passthru.ndi.AddReg] -HKR, Ndi, HelpText, , %Passthru_HELP% - -; ---------------------------------------------------------------------- -; !!--Filter Specific--!! -; -; Note: -; 1. Other components may also have UpperRange/LowerRange but for filters -; the value of both of them must be noupper/nolower -; 2. The value FilterClass is required. -; 3. The value Service is required -; 4. FilterDeviceInfId is the InfId of the filter device (miniport) that will -; be installed for each filtered adapter. -; In this case this is ms_passthrump (refer to netsf_m.inf) -; -HKR, Ndi, FilterClass, , failover -HKR, Ndi, FilterDeviceInfId, , ms_passthrump -HKR, Ndi, Service, , Passthru -HKR, Ndi\Interfaces, UpperRange, , noupper -HKR, Ndi\Interfaces, LowerRange, , nolower -HKR, Ndi\Interfaces, FilterMediaTypes, , "ethernet, tokenring, fddi, wan" - -[Passthru.AddReg] -; The following key is Required -; The following key is Passthru specific -HKR, Parameters, Param1, 0, 4 - -; ---------------------------------------------------------------------- -[Strings] -Msft = "Microsoft" -DiskDescription = "Microsoft Passthru Driver Disk" - -Passthru_Desc = "Passthru Driver" -Passthru_HELP = "Passthru Driver" -PassthruService_Desc = "Passthru Service" - - diff --git a/original_passthru/netsf_m.inf b/original_passthru/netsf_m.inf deleted file mode 100644 index 6605a02..0000000 --- a/original_passthru/netsf_m.inf +++ /dev/null @@ -1,93 +0,0 @@ -; -- NETSF_M.INF -- -; -; Passsthru Miniport INF file -; -; Copyright (c) 1993-1999, Microsoft Corporation - -; ---------------------------------------------------------------------- -; Notes: -; 0. The term "filter" is used here to refer to an NDIS IM driver that -; implements a 1:1 relationship between upper and lower bindings. -; 1. Items specifically required for a filter have been marked with -; "!!--Filter Specific--!!" keyword -; 2. A filter DOES NOT require a notify object for proper installation. -; A notify object is only required if one wants to have better control -; over binding operations or if one wants to receive notifications -; when other components get installed/removed/bound/unbound. -; This sample uses a notify object as an example only. If you do not -; want to use a notify object, please comment out the lines that add -; ClsId and ComponentDll registry keys. -; ---------------------------------------------------------------------- - -[Version] -signature = "$Windows NT$" -Class = Net -ClassGUID = {4d36e972-e325-11ce-bfc1-08002be10318} -Provider = %Msft% -DriverVer =10/01/2002,6.0.5019.0 - -[ControlFlags] -ExcludeFromSelect = ms_passthrump - -[DestinationDirs] -DefaultDestDir=12 -; No files to copy - -[Manufacturer] -%Msft% = MSFT,NTx86,NTia64,NTamd64 - -;For Win2K - -[MSFT] -%PassthruMP_Desc% = PassthruMP.ndi, ms_passthrump - -;For WinXP and later - -[MSFT.NTx86] -%PassthruMP_Desc% = PassthruMP.ndi, ms_passthrump - -[MSFT.NTia64] -%PassthruMP_Desc% = PassthruMP.ndi, ms_passthrump - -[MSFT.NTamd64] -%PassthruMP_Desc% = PassthruMP.ndi, ms_passthrump - - -[PassthruMP.ndi] -AddReg = PassthruMP.ndi.AddReg -Characteristics = 0x29 ;NCF_NOT_USER_REMOVABLE | NCF_VIRTUAL | NCF_HIDDEN - -[PassthruMP.ndi.AddReg] -HKR, Ndi, Service, 0, PassthruMP - -[PassthruMP.ndi.Services] -AddService = PassthruMP,0x2, PassthruMP.AddService - - -[PassthruMP.AddService] -ServiceType = 1 ;SERVICE_KERNEL_DRIVER -StartType = 3 ;SERVICE_DEMAND_START -ErrorControl = 1 ;SERVICE_ERROR_NORMAL -ServiceBinary = %12%\passthru.sys -AddReg = PassthruMP.AddService.AddReg - - -[PassthruMP.AddService.AddReg] -; ---------------------------------------------------------------------- -; Add any miniport-specific parameters here. These are params that your -; filter device is going to use. -; -;HKR, Parameters, ParameterName, 0x10000, "MultiSz", "Parameter", "Value" -;HKR, Parameters, ParameterName2, 0x10001, 4 - -[Strings] -Msft = "Microsoft" -PassthruMP_Desc = "Passthru Miniport" - -[SourceDisksNames] -;None - -[SourceDisksFiles] -;None - - diff --git a/original_passthru/passthru.c b/original_passthru/passthru.c deleted file mode 100644 index f614f2a..0000000 --- a/original_passthru/passthru.c +++ /dev/null @@ -1,458 +0,0 @@ -/*++ - -Copyright (c) 1992-2000 Microsoft Corporation - -Module Name: - - passthru.c - -Abstract: - - Ndis Intermediate Miniport driver sample. This is a passthru driver. - -Author: - -Environment: - - -Revision History: - - ---*/ - - -#include "precomp.h" -#pragma hdrstop - -#pragma NDIS_INIT_FUNCTION(DriverEntry) - -NDIS_HANDLE ProtHandle = NULL; -NDIS_HANDLE DriverHandle = NULL; -NDIS_MEDIUM MediumArray[4] = - { - NdisMedium802_3, // Ethernet - NdisMedium802_5, // Token-ring - NdisMediumFddi, // Fddi - NdisMediumWan // NDISWAN - }; - -NDIS_SPIN_LOCK GlobalLock; - -PADAPT pAdaptList = NULL; -LONG MiniportCount = 0; - -NDIS_HANDLE NdisWrapperHandle; - -// -// To support ioctls from user-mode: -// - -#define LINKNAME_STRING L"\\DosDevices\\Passthru" -#define NTDEVICE_STRING L"\\Device\\Passthru" - -NDIS_HANDLE NdisDeviceHandle = NULL; -PDEVICE_OBJECT ControlDeviceObject = NULL; - -enum _DEVICE_STATE -{ - PS_DEVICE_STATE_READY = 0, // ready for create/delete - PS_DEVICE_STATE_CREATING, // create operation in progress - PS_DEVICE_STATE_DELETING // delete operation in progress -} ControlDeviceState = PS_DEVICE_STATE_READY; - - - -NTSTATUS -DriverEntry( - IN PDRIVER_OBJECT DriverObject, - IN PUNICODE_STRING RegistryPath - ) -/*++ - -Routine Description: - - First entry point to be called, when this driver is loaded. - Register with NDIS as an intermediate driver. - -Arguments: - - DriverObject - pointer to the system's driver object structure - for this driver - - RegistryPath - system's registry path for this driver - -Return Value: - - STATUS_SUCCESS if all initialization is successful, STATUS_XXX - error code if not. - ---*/ -{ - NDIS_STATUS Status; - NDIS_PROTOCOL_CHARACTERISTICS PChars; - NDIS_MINIPORT_CHARACTERISTICS MChars; - NDIS_STRING Name; - - Status = NDIS_STATUS_SUCCESS; - NdisAllocateSpinLock(&GlobalLock); - - NdisMInitializeWrapper(&NdisWrapperHandle, DriverObject, RegistryPath, NULL); - - do - { - // - // Register the miniport with NDIS. Note that it is the miniport - // which was started as a driver and not the protocol. Also the miniport - // must be registered prior to the protocol since the protocol's BindAdapter - // handler can be initiated anytime and when it is, it must be ready to - // start driver instances. - // - - NdisZeroMemory(&MChars, sizeof(NDIS_MINIPORT_CHARACTERISTICS)); - - MChars.MajorNdisVersion = PASSTHRU_MAJOR_NDIS_VERSION; - MChars.MinorNdisVersion = PASSTHRU_MINOR_NDIS_VERSION; - - MChars.InitializeHandler = MPInitialize; - MChars.QueryInformationHandler = MPQueryInformation; - MChars.SetInformationHandler = MPSetInformation; - MChars.ResetHandler = NULL; - MChars.TransferDataHandler = MPTransferData; - MChars.HaltHandler = MPHalt; -#ifdef NDIS51_MINIPORT - MChars.CancelSendPacketsHandler = MPCancelSendPackets; - MChars.PnPEventNotifyHandler = MPDevicePnPEvent; - MChars.AdapterShutdownHandler = MPAdapterShutdown; -#endif // NDIS51_MINIPORT - - // - // We will disable the check for hang timeout so we do not - // need a check for hang handler! - // - MChars.CheckForHangHandler = NULL; - MChars.ReturnPacketHandler = MPReturnPacket; - - // - // Either the Send or the SendPackets handler should be specified. - // If SendPackets handler is specified, SendHandler is ignored - // - MChars.SendHandler = NULL; // MPSend; - MChars.SendPacketsHandler = MPSendPackets; - - Status = NdisIMRegisterLayeredMiniport(NdisWrapperHandle, - &MChars, - sizeof(MChars), - &DriverHandle); - if (Status != NDIS_STATUS_SUCCESS) - { - break; - } - -#ifndef WIN9X - NdisMRegisterUnloadHandler(NdisWrapperHandle, PtUnload); -#endif - - // - // Now register the protocol. - // - NdisZeroMemory(&PChars, sizeof(NDIS_PROTOCOL_CHARACTERISTICS)); - PChars.MajorNdisVersion = PASSTHRU_PROT_MAJOR_NDIS_VERSION; - PChars.MinorNdisVersion = PASSTHRU_PROT_MINOR_NDIS_VERSION; - - // - // Make sure the protocol-name matches the service-name - // (from the INF) under which this protocol is installed. - // This is needed to ensure that NDIS can correctly determine - // the binding and call us to bind to miniports below. - // - NdisInitUnicodeString(&Name, L"Passthru"); // Protocol name - PChars.Name = Name; - PChars.OpenAdapterCompleteHandler = PtOpenAdapterComplete; - PChars.CloseAdapterCompleteHandler = PtCloseAdapterComplete; - PChars.SendCompleteHandler = PtSendComplete; - PChars.TransferDataCompleteHandler = PtTransferDataComplete; - - PChars.ResetCompleteHandler = PtResetComplete; - PChars.RequestCompleteHandler = PtRequestComplete; - PChars.ReceiveHandler = PtReceive; - PChars.ReceiveCompleteHandler = PtReceiveComplete; - PChars.StatusHandler = PtStatus; - PChars.StatusCompleteHandler = PtStatusComplete; - PChars.BindAdapterHandler = PtBindAdapter; - PChars.UnbindAdapterHandler = PtUnbindAdapter; - PChars.UnloadHandler = PtUnloadProtocol; - - PChars.ReceivePacketHandler = PtReceivePacket; - PChars.PnPEventHandler= PtPNPHandler; - - NdisRegisterProtocol(&Status, - &ProtHandle, - &PChars, - sizeof(NDIS_PROTOCOL_CHARACTERISTICS)); - - if (Status != NDIS_STATUS_SUCCESS) - { - NdisIMDeregisterLayeredMiniport(DriverHandle); - break; - } - - NdisIMAssociateMiniport(DriverHandle, ProtHandle); - } - while (FALSE); - - if (Status != NDIS_STATUS_SUCCESS) - { - NdisTerminateWrapper(NdisWrapperHandle, NULL); - } - - return(Status); -} - - -NDIS_STATUS -PtRegisterDevice( - VOID - ) -/*++ - -Routine Description: - - Register an ioctl interface - a device object to be used for this - purpose is created by NDIS when we call NdisMRegisterDevice. - - This routine is called whenever a new miniport instance is - initialized. However, we only create one global device object, - when the first miniport instance is initialized. This routine - handles potential race conditions with PtDeregisterDevice via - the ControlDeviceState and MiniportCount variables. - - NOTE: do not call this from DriverEntry; it will prevent the driver - from being unloaded (e.g. on uninstall). - -Arguments: - - None - -Return Value: - - NDIS_STATUS_SUCCESS if we successfully register a device object. - ---*/ -{ - NDIS_STATUS Status = NDIS_STATUS_SUCCESS; - UNICODE_STRING DeviceName; - UNICODE_STRING DeviceLinkUnicodeString; - PDRIVER_DISPATCH DispatchTable[IRP_MJ_MAXIMUM_FUNCTION+1]; - - DBGPRINT(("==>PtRegisterDevice\n")); - - NdisAcquireSpinLock(&GlobalLock); - - ++MiniportCount; - - if (1 == MiniportCount) - { - ASSERT(ControlDeviceState != PS_DEVICE_STATE_CREATING); - - // - // Another thread could be running PtDeregisterDevice on - // behalf of another miniport instance. If so, wait for - // it to exit. - // - while (ControlDeviceState != PS_DEVICE_STATE_READY) - { - NdisReleaseSpinLock(&GlobalLock); - NdisMSleep(1); - NdisAcquireSpinLock(&GlobalLock); - } - - ControlDeviceState = PS_DEVICE_STATE_CREATING; - - NdisReleaseSpinLock(&GlobalLock); - - - NdisZeroMemory(DispatchTable, (IRP_MJ_MAXIMUM_FUNCTION+1) * sizeof(PDRIVER_DISPATCH)); - - DispatchTable[IRP_MJ_CREATE] = PtDispatch; - DispatchTable[IRP_MJ_CLEANUP] = PtDispatch; - DispatchTable[IRP_MJ_CLOSE] = PtDispatch; - DispatchTable[IRP_MJ_DEVICE_CONTROL] = PtDispatch; - - - NdisInitUnicodeString(&DeviceName, NTDEVICE_STRING); - NdisInitUnicodeString(&DeviceLinkUnicodeString, LINKNAME_STRING); - - // - // Create a device object and register our dispatch handlers - // - - Status = NdisMRegisterDevice( - NdisWrapperHandle, - &DeviceName, - &DeviceLinkUnicodeString, - &DispatchTable[0], - &ControlDeviceObject, - &NdisDeviceHandle - ); - - NdisAcquireSpinLock(&GlobalLock); - - ControlDeviceState = PS_DEVICE_STATE_READY; - } - - NdisReleaseSpinLock(&GlobalLock); - - DBGPRINT(("<==PtRegisterDevice: %x\n", Status)); - - return (Status); -} - - -NTSTATUS -PtDispatch( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp - ) -/*++ -Routine Description: - - Process IRPs sent to this device. - -Arguments: - - DeviceObject - pointer to a device object - Irp - pointer to an I/O Request Packet - -Return Value: - - NTSTATUS - STATUS_SUCCESS always - change this when adding - real code to handle ioctls. - ---*/ -{ - PIO_STACK_LOCATION irpStack; - NTSTATUS status = STATUS_SUCCESS; - - UNREFERENCED_PARAMETER(DeviceObject); - - DBGPRINT(("==>Pt Dispatch\n")); - irpStack = IoGetCurrentIrpStackLocation(Irp); - - - switch (irpStack->MajorFunction) - { - case IRP_MJ_CREATE: - break; - - case IRP_MJ_CLEANUP: - break; - - case IRP_MJ_CLOSE: - break; - - case IRP_MJ_DEVICE_CONTROL: - // - // Add code here to handle ioctl commands sent to passthru. - // - break; - default: - break; - } - - Irp->IoStatus.Status = status; - IoCompleteRequest(Irp, IO_NO_INCREMENT); - - DBGPRINT(("<== Pt Dispatch\n")); - - return status; - -} - - -NDIS_STATUS -PtDeregisterDevice( - VOID - ) -/*++ - -Routine Description: - - Deregister the ioctl interface. This is called whenever a miniport - instance is halted. When the last miniport instance is halted, we - request NDIS to delete the device object - -Arguments: - - NdisDeviceHandle - Handle returned by NdisMRegisterDevice - -Return Value: - - NDIS_STATUS_SUCCESS if everything worked ok - ---*/ -{ - NDIS_STATUS Status = NDIS_STATUS_SUCCESS; - - DBGPRINT(("==>PassthruDeregisterDevice\n")); - - NdisAcquireSpinLock(&GlobalLock); - - ASSERT(MiniportCount > 0); - - --MiniportCount; - - if (0 == MiniportCount) - { - // - // All miniport instances have been halted. Deregister - // the control device. - // - - ASSERT(ControlDeviceState == PS_DEVICE_STATE_READY); - - // - // Block PtRegisterDevice() while we release the control - // device lock and deregister the device. - // - ControlDeviceState = PS_DEVICE_STATE_DELETING; - - NdisReleaseSpinLock(&GlobalLock); - - if (NdisDeviceHandle != NULL) - { - Status = NdisMDeregisterDevice(NdisDeviceHandle); - NdisDeviceHandle = NULL; - } - - NdisAcquireSpinLock(&GlobalLock); - ControlDeviceState = PS_DEVICE_STATE_READY; - } - - NdisReleaseSpinLock(&GlobalLock); - - DBGPRINT(("<== PassthruDeregisterDevice: %x\n", Status)); - return Status; - -} - -VOID -PtUnload( - IN PDRIVER_OBJECT DriverObject - ) -// -// PassThru driver unload function -// -{ - UNREFERENCED_PARAMETER(DriverObject); - - DBGPRINT(("PtUnload: entered\n")); - - PtUnloadProtocol(); - - NdisIMDeregisterLayeredMiniport(DriverHandle); - - NdisFreeSpinLock(&GlobalLock); - - DBGPRINT(("PtUnload: done!\n")); -} - diff --git a/original_passthru/passthru.h b/original_passthru/passthru.h deleted file mode 100644 index badde8a..0000000 --- a/original_passthru/passthru.h +++ /dev/null @@ -1,477 +0,0 @@ -/*++ - -Copyright (c) 1992-2000 Microsoft Corporation - -Module Name: - - passthru.h - -Abstract: - - Ndis Intermediate Miniport driver sample. This is a passthru driver. - -Author: - -Environment: - - -Revision History: - - ---*/ - -#ifdef NDIS51_MINIPORT -#define PASSTHRU_MAJOR_NDIS_VERSION 5 -#define PASSTHRU_MINOR_NDIS_VERSION 1 -#else -#define PASSTHRU_MAJOR_NDIS_VERSION 4 -#define PASSTHRU_MINOR_NDIS_VERSION 0 -#endif - -#ifdef NDIS51 -#define PASSTHRU_PROT_MAJOR_NDIS_VERSION 5 -#define PASSTHRU_PROT_MINOR_NDIS_VERSION 0 -#else -#define PASSTHRU_PROT_MAJOR_NDIS_VERSION 4 -#define PASSTHRU_PROT_MINOR_NDIS_VERSION 0 -#endif - -#define MAX_BUNDLEID_LENGTH 50 - -#define TAG 'ImPa' -#define WAIT_INFINITE 0 - - - -//advance declaration -typedef struct _ADAPT ADAPT, *PADAPT; - -DRIVER_INITIALIZE DriverEntry; -extern -NTSTATUS -DriverEntry( - IN PDRIVER_OBJECT DriverObject, - IN PUNICODE_STRING RegistryPath - ); - -DRIVER_DISPATCH PtDispatch; -NTSTATUS -PtDispatch( - IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp - ); - -NDIS_STATUS -PtRegisterDevice( - VOID - ); - -NDIS_STATUS -PtDeregisterDevice( - VOID - ); - -DRIVER_UNLOAD PtUnload; -VOID -PtUnloadProtocol( - VOID - ); - -// -// Protocol proto-types -// -extern -VOID -PtOpenAdapterComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_STATUS Status, - IN NDIS_STATUS OpenErrorStatus - ); - -extern -VOID -PtCloseAdapterComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_STATUS Status - ); - -extern -VOID -PtResetComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_STATUS Status - ); - -extern -VOID -PtRequestComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN PNDIS_REQUEST NdisRequest, - IN NDIS_STATUS Status - ); - -extern -VOID -PtStatus( - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_STATUS GeneralStatus, - IN PVOID StatusBuffer, - IN UINT StatusBufferSize - ); - -extern -VOID -PtStatusComplete( - IN NDIS_HANDLE ProtocolBindingContext - ); - -extern -VOID -PtSendComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN PNDIS_PACKET Packet, - IN NDIS_STATUS Status - ); - -extern -VOID -PtTransferDataComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN PNDIS_PACKET Packet, - IN NDIS_STATUS Status, - IN UINT BytesTransferred - ); - -extern -NDIS_STATUS -PtReceive( - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_HANDLE MacReceiveContext, - IN PVOID HeaderBuffer, - IN UINT HeaderBufferSize, - IN PVOID LookAheadBuffer, - IN UINT LookaheadBufferSize, - IN UINT PacketSize - ); - -extern -VOID -PtReceiveComplete( - IN NDIS_HANDLE ProtocolBindingContext - ); - -extern -INT -PtReceivePacket( - IN NDIS_HANDLE ProtocolBindingContext, - IN PNDIS_PACKET Packet - ); - -extern -VOID -PtBindAdapter( - OUT PNDIS_STATUS Status, - IN NDIS_HANDLE BindContext, - IN PNDIS_STRING DeviceName, - IN PVOID SystemSpecific1, - IN PVOID SystemSpecific2 - ); - -extern -VOID -PtUnbindAdapter( - OUT PNDIS_STATUS Status, - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_HANDLE UnbindContext - ); - -VOID -PtUnload( - IN PDRIVER_OBJECT DriverObject - ); - - - -extern -NDIS_STATUS -PtPNPHandler( - IN NDIS_HANDLE ProtocolBindingContext, - IN PNET_PNP_EVENT pNetPnPEvent - ); - - - - -NDIS_STATUS -PtPnPNetEventReconfigure( - IN PADAPT pAdapt, - IN PNET_PNP_EVENT pNetPnPEvent - ); - -NDIS_STATUS -PtPnPNetEventSetPower ( - IN PADAPT pAdapt, - IN PNET_PNP_EVENT pNetPnPEvent - ); - - -// -// Miniport proto-types -// -NDIS_STATUS -MPInitialize( - OUT PNDIS_STATUS OpenErrorStatus, - OUT PUINT SelectedMediumIndex, - IN PNDIS_MEDIUM MediumArray, - IN UINT MediumArraySize, - IN NDIS_HANDLE MiniportAdapterHandle, - IN NDIS_HANDLE WrapperConfigurationContext - ); - -VOID -MPSendPackets( - IN NDIS_HANDLE MiniportAdapterContext, - IN PPNDIS_PACKET PacketArray, - IN UINT NumberOfPackets - ); - -NDIS_STATUS -MPSend( - IN NDIS_HANDLE MiniportAdapterContext, - IN PNDIS_PACKET Packet, - IN UINT Flags - ); - -NDIS_STATUS -MPQueryInformation( - IN NDIS_HANDLE MiniportAdapterContext, - IN NDIS_OID Oid, - IN PVOID InformationBuffer, - IN ULONG InformationBufferLength, - OUT PULONG BytesWritten, - OUT PULONG BytesNeeded - ); - -NDIS_STATUS -MPSetInformation( - IN NDIS_HANDLE MiniportAdapterContext, - IN NDIS_OID Oid, - __in_bcount(InformationBufferLength) IN PVOID InformationBuffer, - IN ULONG InformationBufferLength, - OUT PULONG BytesRead, - OUT PULONG BytesNeeded - ); - -VOID -MPReturnPacket( - IN NDIS_HANDLE MiniportAdapterContext, - IN PNDIS_PACKET Packet - ); - -NDIS_STATUS -MPTransferData( - OUT PNDIS_PACKET Packet, - OUT PUINT BytesTransferred, - IN NDIS_HANDLE MiniportAdapterContext, - IN NDIS_HANDLE MiniportReceiveContext, - IN UINT ByteOffset, - IN UINT BytesToTransfer - ); - -VOID -MPHalt( - IN NDIS_HANDLE MiniportAdapterContext - ); - - -VOID -MPQueryPNPCapabilities( - OUT PADAPT MiniportProtocolContext, - OUT PNDIS_STATUS Status - ); - - -#ifdef NDIS51_MINIPORT - -VOID -MPCancelSendPackets( - IN NDIS_HANDLE MiniportAdapterContext, - IN PVOID CancelId - ); - -VOID -MPAdapterShutdown( - IN NDIS_HANDLE MiniportAdapterContext - ); - -VOID -MPDevicePnPEvent( - IN NDIS_HANDLE MiniportAdapterContext, - IN NDIS_DEVICE_PNP_EVENT DevicePnPEvent, - IN PVOID InformationBuffer, - IN ULONG InformationBufferLength - ); - -#endif // NDIS51_MINIPORT - -VOID -MPFreeAllPacketPools( - IN PADAPT pAdapt - ); - - -VOID -MPProcessSetPowerOid( - IN OUT PNDIS_STATUS pNdisStatus, - IN PADAPT pAdapt, - __in_bcount(InformationBufferLength) IN PVOID InformationBuffer, - IN ULONG InformationBufferLength, - OUT PULONG BytesRead, - OUT PULONG BytesNeeded - ); - -VOID -PtReferenceAdapt( - IN PADAPT pAdapt - ); - -BOOLEAN -PtDereferenceAdapt( - IN PADAPT pAdapt - ); - -// -// There should be no DbgPrint's in the Free version of the driver -// -#if DBG - -#define DBGPRINT(Fmt) \ - { \ - DbgPrint("Passthru: "); \ - DbgPrint Fmt; \ - } - -#else // if DBG - -#define DBGPRINT(Fmt) - -#endif // if DBG - -#define NUM_PKTS_IN_POOL 256 - - -// -// Protocol reserved part of a sent packet that is allocated by us. -// -typedef struct _SEND_RSVD -{ - PNDIS_PACKET OriginalPkt; -} SEND_RSVD, *PSEND_RSVD; - -// -// Miniport reserved part of a received packet that is allocated by -// us. Note that this should fit into the MiniportReserved space -// in an NDIS_PACKET. -// -typedef struct _RECV_RSVD -{ - PNDIS_PACKET OriginalPkt; -} RECV_RSVD, *PRECV_RSVD; - -C_ASSERT(sizeof(RECV_RSVD) <= sizeof(((PNDIS_PACKET)0)->MiniportReserved)); - -// -// Event Codes related to the PassthruEvent Structure -// - -typedef enum -{ - Passthru_Invalid, - Passthru_SetPower, - Passthru_Unbind - -} PASSSTHRU_EVENT_CODE, *PPASTHRU_EVENT_CODE; - -// -// Passthru Event with a code to state why they have been state -// - -typedef struct _PASSTHRU_EVENT -{ - NDIS_EVENT Event; - PASSSTHRU_EVENT_CODE Code; - -} PASSTHRU_EVENT, *PPASSTHRU_EVENT; - - -// -// Structure used by both the miniport as well as the protocol part of the intermediate driver -// to represent an adapter and its corres. lower bindings -// -typedef struct _ADAPT -{ - struct _ADAPT * Next; - - NDIS_HANDLE BindingHandle; // To the lower miniport - NDIS_HANDLE MiniportHandle; // NDIS Handle to for miniport up-calls - NDIS_HANDLE SendPacketPoolHandle; - NDIS_HANDLE RecvPacketPoolHandle; - NDIS_STATUS Status; // Open Status - NDIS_EVENT Event; // Used by bind/halt for Open/Close Adapter synch. - NDIS_MEDIUM Medium; - NDIS_REQUEST Request; // This is used to wrap a request coming down - // to us. This exploits the fact that requests - // are serialized down to us. - PULONG BytesNeeded; - PULONG BytesReadOrWritten; - BOOLEAN ReceivedIndicationFlags[32]; - - BOOLEAN OutstandingRequests; // TRUE iff a request is pending - // at the miniport below - BOOLEAN QueuedRequest; // TRUE iff a request is queued at - // this IM miniport - - BOOLEAN StandingBy; // True - When the miniport or protocol is transitioning from a D0 to Standby (>D0) State - BOOLEAN UnbindingInProcess; - NDIS_SPIN_LOCK Lock; - // False - At all other times, - Flag is cleared after a transition to D0 - - NDIS_DEVICE_POWER_STATE MPDeviceState; // Miniport's Device State - NDIS_DEVICE_POWER_STATE PTDeviceState; // Protocol's Device State - NDIS_STRING DeviceName; // For initializing the miniport edge - NDIS_EVENT MiniportInitEvent; // For blocking UnbindAdapter while - // an IM Init is in progress. - BOOLEAN MiniportInitPending; // TRUE iff IMInit in progress - NDIS_STATUS LastIndicatedStatus; // The last indicated media status - NDIS_STATUS LatestUnIndicateStatus; // The latest suppressed media status - ULONG OutstandingSends; - LONG RefCount; - BOOLEAN MiniportIsHalted; -} ADAPT, *PADAPT; - -extern NDIS_HANDLE ProtHandle, DriverHandle; -extern NDIS_MEDIUM MediumArray[4]; -extern PADAPT pAdaptList; -extern NDIS_SPIN_LOCK GlobalLock; - - -#define ADAPT_MINIPORT_HANDLE(_pAdapt) ((_pAdapt)->MiniportHandle) -#define ADAPT_DECR_PENDING_SENDS(_pAdapt) \ - { \ - NdisAcquireSpinLock(&(_pAdapt)->Lock); \ - (_pAdapt)->OutstandingSends--; \ - NdisReleaseSpinLock(&(_pAdapt)->Lock); \ - } - -// -// Custom Macros to be used by the passthru driver -// -/* -BOOLEAN -IsIMDeviceStateOn( - PADAPT - ) - -*/ -#define IsIMDeviceStateOn(_pP) ((_pP)->MPDeviceState == NdisDeviceStateD0 && (_pP)->PTDeviceState == NdisDeviceStateD0 ) - diff --git a/original_passthru/passthru.htm b/original_passthru/passthru.htm deleted file mode 100644 index ee23278..0000000 --- a/original_passthru/passthru.htm +++ /dev/null @@ -1,486 +0,0 @@ - - - - - - - - -passthru - - - - - - - - - - - - -
- -

- - - -PASSTHRU.SYS -- Sample NDIS Intermediate Driver

- -

SUMMARY

- -

Passthru Intermediate Miniport Driver

- -

The Passthru -sample is a do-nothing pass-through NDIS 5 driver that demonstrates the basic -principles underlying an NDIS Intermediate Miniport (IM) driver. This driver -exposes a virtual adapter for each binding to a real or virtual NDIS adapter. -Protocols bind to these virtual adapters as if they are real adapters.

- -

The Passthru -driver re-packages and sends down all requests and sends submitted to this -virtual adapter. The Passthru driver can be modified -to change the data before passing it along. For example, it could -encrypt/compress outgoing and decrypt/decompress incoming data.

- -

Passthru also re-packages and indicates up -all received data and status indications that it receives at its lower -(protocol) edge.

- -

BUILDING THE SAMPLE

- -

Run the build -command from this directory to build the sample—it creates the binary Passthru.sys.

- -

To install this driver on -Windows® 2000, use the PASSTHRU sample notification object and INFs, also found in this DDK.

- -

INSTALLING THE SAMPLE

- -

Passthru is installed as a service (called -“Passthru Driver” in the supplied INFs/notification -object). To install, follow the steps below.

- -

Prepare a floppy disk (or -installation directory) that contains these files: netsf.inf, -netsf_m.inf and passthru.sys.

- -

On the desktop, -right-click the My Network Places icon and choose Properties.

- -

Right-click on the -relevant Local Area Connection icon and choose Properties.

- -

Click Install, -then Service, then Add, then Have Disk. -

- -

Browse to the -drive/directory containing the files listed above. Click OK. This should -show “Passthru Driver” in a list of Network Services. -Highlight this and click OK. This should install the Passthru -driver.

- -

Click OK or Yes each time the system prompts with a warning -regarding installation of unsigned files. This is necessary because binaries -generated via the DDK build environment are not signed.

- -

Two .INF files are needed -rather than one because Passthru is installed both as -a protocol and a miniport.

- -

CODE TOUR

- -

File Manifest

- -
File           Description
 
Makefile       Used during compilation to create the object and sys files
Miniport.c     Miniport related functions of the passthru driver
Netsf.inf      Installation INF for the service (protocol side installation)
Netsf_m.inf    Installation INF for the miniport (virtual device installation)
Passthru.c     DriverEntry routine and any routines common to the passthru miniport and protocol 
Passthru.h     Prototypes of all functions and data structures used by the Passthru driver
Passthru.htm   Documentation for the Passthru driver (this file)
Passthru.rc    Resource file for the Passthru driver
Precomp.h      Precompile header file
Protocol.c     Protocol related functions of the Passthru driver
Sources        List of source files that are compiled and linked to create the passthru driver. This can be modified to create binaries that operate on previous Windows versions (e.g. Windows 2000).
- -

Programming Tour

- -

Basic steps in initializing and -halting of Passthru driver:

- -

1) During DriverEntry, -the Passthru driver registers as a protocol and an -Intermediate miniport driver.

- -

2) Later on, NDIS calls Passthru’s BindAdapterHandler, PtBindAdapter, for each underlying NDIS adapter to which it -is configured to bind.

- -

3) In the context of BindAdapterHandler and after successfully opening a binding -to the underlying adapter, the Passthru driver -queries the reserved keyword "UpperBindings" -to get a list of device names for the virtual adapters that this particular -binding is to expose. Since this driver implements a 1:1 relationship between -lower bindings and virtual adapters, this list contains a single name. “Mux” IM drivers that expose multiple virtual adapters over -a single underlying adapter will process multiple entries in UpperBindings.

- -

4) For each device name, the Passthru driver calls NdisIMInitializeDeviceInstanceEx.

- -

5) In response, NDIS will -eventually call back Passthru miniport’s MiniportInitialize entry point, MPInitialize.

- -

6) After MPInitialize -successfully returns, NDIS takes care of getting upper-layer protocols to bind -to the newly created virtual adapter(s).

- -

7) All requests and sends coming -from upper-layer protocols for the Passthru miniport -driver are repackaged and sent down to NDIS, to be passed to the underlying -NDIS adapter.

- -

8) All indications arriving from -bindings to an underlying NDIS adapter are forwarded up as if they generated -from Passthru’s virtual adapters.

- -

9) NDIS calls the Passthru driver’s ProtocolUnbind -entry point to request it to close the binding between an underlying adapter -and Passthru protocol. In processing this, the Passthru driver first calls NdisIMDeInitializeDeviceInstance -for the virtual adapter(s) representing that particular binding.

- -

10) NDIS in turn will close all -the bindings between upper-layer protocols and virtual Passthru -adapter.

- -

11) After all the bindings are -closed, NDIS calls the Passthru driver’s MiniportHalt entry point (MPHalt) -for the virtual adapter.

- -

12) The Passthru -protocol then closes the binding to the underlying adapter by calling NdisCloseAdapter, and completes the unbind request issued -in step 9.

- -

13) Handling Power Management

- -

13.1 During initialization, the Passthru miniport should set the Attribute 'NDIS_ATTRIBUTE_NO_HALT_ON_SUSPEND' -in its call to NdisMSetAttributesEx.

- -

13.2 When the Passthru -miniport is requested to report its Plug and Play capabilities -(OID_PNP_CAPABILITIES), the Passthru miniport must -pass the request to the underlying miniport. If this request succeeds, then the -Passthru miniport should overwrite the following -fields before successfully completing the original request:

- -

NDIS_DEVICE_POWER_STATE          MinMagicPacketWakeUp -= NdisDeviceStateUnspecified;

- -

NDIS_DEVICE_POWER_STATE          MinPatternWakeUp= -NdisDeviceStateUnspecified;

- -

NDIS_DEVICE_POWER_STATE          MinLinkChangeWakeUp=NdisDeviceStateUnspecified

- -

If the miniport below the Passthru protocol fails this request, then the status that -was returned should be used to respond to the original request that was made to -the Passthru miniport.

- -

13.3 OID_PNP_SET_POWER and OID_PNP_QUERY_POWER -should not be passed to the miniport below the Passthru -protocol, as those miniports will receive independent -requests from NDIS.

- -

13.4 NDIS calls the Passthru driver’s ProtocolPnPEvent -entry point (PtPnPHandler) whenever the underlying adapter -is transitioned to a different power state. If the underlying adapter is -transitioning to a low power state, the IM driver should wait for all -outstanding sends and requests to complete.

- -

14) NDIS 5.1 Features

- -

14.1 All NDIS 5.1 features in Passthru are identified by #ifdef -NDIS51 compiler directives. The following major features are illustrated (refer -to the DDK documentation for more information on these):

- -

Packet stacking: this allows an IM driver to -reuse a packet submitted to its protocol or miniport edge to forward data down -(or up) to the adjacent layer.

- -

Canceling Sends: Passthru -propagates send cancellations from protocols above it to lower miniports.

- -

PnP Event Propagation: Passthru -propagates PnP events arriving at its protocol (lower) edge to higher layer -protocols that are bound to its virtual adapter.

- -

NdisQueryPendingIOCount: Passthru -uses this new API to determine if any I/O operations are in progress on its -lower binding.

- -

15) For Win2K SP2 and WinXP, the Passthru sample no -longer requires a Notify Object. The Notify Object has been removed.

- -

 

- -

Top of page

- - - - - -
-

 

-
- -

© 1999 Microsoft -Corporation

- -
- - - - - diff --git a/original_passthru/passthru.rc b/original_passthru/passthru.rc deleted file mode 100644 index 6ae427c..0000000 --- a/original_passthru/passthru.rc +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include - -/*-----------------------------------------------*/ -/* the following lines are specific to this file */ -/*-----------------------------------------------*/ - -/* VER_FILETYPE, VER_FILESUBTYPE, VER_FILEDESCRIPTION_STR - * and VER_INTERNALNAME_STR must be defined before including COMMON.VER - * The strings don't need a '\0', since common.ver has them. - */ -#define VER_FILETYPE VFT_DRV -/* possible values: VFT_UNKNOWN - VFT_APP - VFT_DLL - VFT_DRV - VFT_FONT - VFT_VXD - VFT_STATIC_LIB -*/ -#define VER_FILESUBTYPE VFT2_DRV_NETWORK -/* possible values VFT2_UNKNOWN - VFT2_DRV_PRINTER - VFT2_DRV_KEYBOARD - VFT2_DRV_LANGUAGE - VFT2_DRV_DISPLAY - VFT2_DRV_MOUSE - VFT2_DRV_NETWORK - VFT2_DRV_SYSTEM - VFT2_DRV_INSTALLABLE - VFT2_DRV_SOUND - VFT2_DRV_COMM -*/ -#define VER_FILEDESCRIPTION_STR "Sample NDIS 4.0 Intermediate Miniport Driver" -#define VER_INTERNALNAME_STR "PASSTHRU.SYS" -#define VER_ORIGINALFILENAME_STR "PASSTHRU.SYS" -#define VER_LANGNEUTRAL - -#include "common.ver" - - diff --git a/original_passthru/precomp.h b/original_passthru/precomp.h deleted file mode 100644 index b2870d1..0000000 --- a/original_passthru/precomp.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma warning(disable:4214) // bit field types other than int - -#pragma warning(disable:4201) // nameless struct/union -#pragma warning(disable:4115) // named type definition in parentheses -#pragma warning(disable:4127) // conditional expression is constant -#pragma warning(disable:4054) // cast of function pointer to PVOID -#pragma warning(disable:4244) // conversion from 'int' to 'BOOLEAN', possible loss of data - -#include -#include "passthru.h" - diff --git a/original_passthru/protocol.c b/original_passthru/protocol.c deleted file mode 100644 index 213924c..0000000 --- a/original_passthru/protocol.c +++ /dev/null @@ -1,1626 +0,0 @@ -/*++ - -Copyright(c) 1992-2000 Microsoft Corporation - -Module Name: - - protocol.c - -Abstract: - - Ndis Intermediate Miniport driver sample. This is a passthru driver. - -Author: - -Environment: - - -Revision History: - - ---*/ - - -#include "precomp.h" -#pragma hdrstop - -#define MAX_PACKET_POOL_SIZE 0x0000FFFF -#define MIN_PACKET_POOL_SIZE 0x000000FF - -// -// NDIS version as 0xMMMMmmmm, where M=Major/m=minor (0x00050001 = 5.1); -// initially unknown (0) -// -ULONG NdisDotSysVersion = 0x0; - - -#define NDIS_SYS_VERSION_51 0x00050001 - - -VOID -PtBindAdapter( - OUT PNDIS_STATUS Status, - IN NDIS_HANDLE BindContext, - IN PNDIS_STRING DeviceName, - IN PVOID SystemSpecific1, - IN PVOID SystemSpecific2 - ) -/*++ - -Routine Description: - - Called by NDIS to bind to a miniport below. - -Arguments: - - Status - Return status of bind here. - BindContext - Can be passed to NdisCompleteBindAdapter if this call is pended. - DeviceName - Device name to bind to. This is passed to NdisOpenAdapter. - SystemSpecific1 - Can be passed to NdisOpenProtocolConfiguration to read per-binding information - SystemSpecific2 - Unused - -Return Value: - - NDIS_STATUS_PENDING if this call is pended. In this case call NdisCompleteBindAdapter - to complete. - Anything else Completes this call synchronously - ---*/ -{ - NDIS_HANDLE ConfigHandle = NULL; - PNDIS_CONFIGURATION_PARAMETER Param; - NDIS_STRING DeviceStr = NDIS_STRING_CONST("UpperBindings"); - NDIS_STRING NdisVersionStr = NDIS_STRING_CONST("NdisVersion"); - PADAPT pAdapt = NULL; - NDIS_STATUS Sts; - UINT MediumIndex; - ULONG TotalSize; - BOOLEAN NoCleanUpNeeded = FALSE; - - - UNREFERENCED_PARAMETER(BindContext); - UNREFERENCED_PARAMETER(SystemSpecific2); - - DBGPRINT(("==> Protocol BindAdapter\n")); - - do - { - // - // Access the configuration section for our binding-specific - // parameters. - // - NdisOpenProtocolConfiguration(Status, - &ConfigHandle, - SystemSpecific1); - - if (*Status != NDIS_STATUS_SUCCESS) - { - break; - } - if (NdisDotSysVersion == 0) - { - NdisReadConfiguration(Status, - &Param, - ConfigHandle, - &NdisVersionStr, // "NdisVersion" - NdisParameterInteger); - if (*Status != NDIS_STATUS_SUCCESS) - { - break; - } - - NdisDotSysVersion = Param->ParameterData.IntegerData; - } - - - // - // Read the "UpperBindings" reserved key that contains a list - // of device names representing our miniport instances corresponding - // to this lower binding. Since this is a 1:1 IM driver, this key - // contains exactly one name. - // - // If we want to implement a N:1 mux driver (N adapter instances - // over a single lower binding), then UpperBindings will be a - // MULTI_SZ containing a list of device names - we would loop through - // this list, calling NdisIMInitializeDeviceInstanceEx once for - // each name in it. - // - NdisReadConfiguration(Status, - &Param, - ConfigHandle, - &DeviceStr, - NdisParameterString); - if (*Status != NDIS_STATUS_SUCCESS) - { - break; - } - - // - // Allocate memory for the Adapter structure. This represents both the - // protocol context as well as the adapter structure when the miniport - // is initialized. - // - // In addition to the base structure, allocate space for the device - // instance string. - // - TotalSize = sizeof(ADAPT) + Param->ParameterData.StringData.MaximumLength; - - NdisAllocateMemoryWithTag(&pAdapt, TotalSize, TAG); - - if (pAdapt == NULL) - { - *Status = NDIS_STATUS_RESOURCES; - break; - } - - // - // Initialize the adapter structure. We copy in the IM device - // name as well, because we may need to use it in a call to - // NdisIMCancelInitializeDeviceInstance. The string returned - // by NdisReadConfiguration is active (i.e. available) only - // for the duration of this call to our BindAdapter handler. - // - NdisZeroMemory(pAdapt, TotalSize); - pAdapt->DeviceName.MaximumLength = Param->ParameterData.StringData.MaximumLength; - pAdapt->DeviceName.Length = Param->ParameterData.StringData.Length; - pAdapt->DeviceName.Buffer = (PWCHAR)((ULONG_PTR)pAdapt + sizeof(ADAPT)); - NdisMoveMemory(pAdapt->DeviceName.Buffer, - Param->ParameterData.StringData.Buffer, - Param->ParameterData.StringData.MaximumLength); - - - - NdisInitializeEvent(&pAdapt->Event); - NdisAllocateSpinLock(&pAdapt->Lock); - - // - // Allocate a packet pool for sends. We need this to pass sends down. - // We cannot use the same packet descriptor that came down to our send - // handler (see also NDIS 5.1 packet stacking). - // - NdisAllocatePacketPoolEx(Status, - &pAdapt->SendPacketPoolHandle, - MIN_PACKET_POOL_SIZE, - MAX_PACKET_POOL_SIZE - MIN_PACKET_POOL_SIZE, - sizeof(SEND_RSVD)); - - if (*Status != NDIS_STATUS_SUCCESS) - { - break; - } - - // - // Allocate a packet pool for receives. We need this to indicate receives. - // Same consideration as sends (see also NDIS 5.1 packet stacking). - // - NdisAllocatePacketPoolEx(Status, - &pAdapt->RecvPacketPoolHandle, - MIN_PACKET_POOL_SIZE, - MAX_PACKET_POOL_SIZE - MIN_PACKET_POOL_SIZE, - PROTOCOL_RESERVED_SIZE_IN_PACKET); - - if (*Status != NDIS_STATUS_SUCCESS) - { - break; - } - - // - // Now open the adapter below and complete the initialization - // - NdisOpenAdapter(Status, - &Sts, - &pAdapt->BindingHandle, - &MediumIndex, - MediumArray, - sizeof(MediumArray)/sizeof(NDIS_MEDIUM), - ProtHandle, - pAdapt, - DeviceName, - 0, - NULL); - - if (*Status == NDIS_STATUS_PENDING) - { - NdisWaitEvent(&pAdapt->Event, 0); - *Status = pAdapt->Status; - } - - if (*Status != NDIS_STATUS_SUCCESS) - { - break; - } - PtReferenceAdapt(pAdapt); - -#pragma prefast(suppress: __WARNING_POTENTIAL_BUFFER_OVERFLOW, "Ndis guarantees MediumIndex to be within bounds"); - pAdapt->Medium = MediumArray[MediumIndex]; - - // - // Now ask NDIS to initialize our miniport (upper) edge. - // Set the flag below to synchronize with a possible call - // to our protocol Unbind handler that may come in before - // our miniport initialization happens. - // - pAdapt->MiniportInitPending = TRUE; - NdisInitializeEvent(&pAdapt->MiniportInitEvent); - - PtReferenceAdapt(pAdapt); - - *Status = NdisIMInitializeDeviceInstanceEx(DriverHandle, - &pAdapt->DeviceName, - pAdapt); - - if (*Status != NDIS_STATUS_SUCCESS) - { - if (pAdapt->MiniportIsHalted == TRUE) - { - NoCleanUpNeeded = TRUE; - } - - DBGPRINT(("BindAdapter: Adapt %p, IMInitializeDeviceInstance error %x\n", - pAdapt, *Status)); - - if (PtDereferenceAdapt(pAdapt)) - { - pAdapt = NULL; - } - - break; - } - - PtDereferenceAdapt(pAdapt); - - } while(FALSE); - - // - // Close the configuration handle now - see comments above with - // the call to NdisIMInitializeDeviceInstanceEx. - // - if (ConfigHandle != NULL) - { - NdisCloseConfiguration(ConfigHandle); - } - - if ((*Status != NDIS_STATUS_SUCCESS) && (NoCleanUpNeeded == FALSE)) - { - if (pAdapt != NULL) - { - if (pAdapt->BindingHandle != NULL) - { - NDIS_STATUS LocalStatus; - - // - // Close the binding we opened above. - // - - NdisResetEvent(&pAdapt->Event); - - NdisCloseAdapter(&LocalStatus, pAdapt->BindingHandle); - pAdapt->BindingHandle = NULL; - - if (LocalStatus == NDIS_STATUS_PENDING) - { - NdisWaitEvent(&pAdapt->Event, 0); - LocalStatus = pAdapt->Status; - - - } - if (PtDereferenceAdapt(pAdapt)) - { - pAdapt = NULL; - } - } - } - } - - - DBGPRINT(("<== Protocol BindAdapter: pAdapt %p, Status %x\n", pAdapt, *Status)); -} - - -VOID -PtOpenAdapterComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_STATUS Status, - IN NDIS_STATUS OpenErrorStatus - ) -/*++ - -Routine Description: - - Completion routine for NdisOpenAdapter issued from within the PtBindAdapter. Simply - unblock the caller. - -Arguments: - - ProtocolBindingContext Pointer to the adapter - Status Status of the NdisOpenAdapter call - OpenErrorStatus Secondary status(ignored by us). - -Return Value: - - None - ---*/ -{ - PADAPT pAdapt =(PADAPT)ProtocolBindingContext; - - UNREFERENCED_PARAMETER(OpenErrorStatus); - - DBGPRINT(("==> PtOpenAdapterComplete: Adapt %p, Status %x\n", pAdapt, Status)); - pAdapt->Status = Status; - NdisSetEvent(&pAdapt->Event); -} - - -VOID -PtUnbindAdapter( - OUT PNDIS_STATUS Status, - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_HANDLE UnbindContext - ) -/*++ - -Routine Description: - - Called by NDIS when we are required to unbind to the adapter below. - This functions shares functionality with the miniport's HaltHandler. - The code should ensure that NdisCloseAdapter and NdisFreeMemory is called - only once between the two functions - -Arguments: - - Status Placeholder for return status - ProtocolBindingContext Pointer to the adapter structure - UnbindContext Context for NdisUnbindComplete() if this pends - -Return Value: - - Status for NdisIMDeinitializeDeviceContext - ---*/ -{ - PADAPT pAdapt =(PADAPT)ProtocolBindingContext; - NDIS_STATUS LocalStatus; - - UNREFERENCED_PARAMETER(UnbindContext); - - DBGPRINT(("==> PtUnbindAdapter: Adapt %p\n", pAdapt)); - - // - // Set the flag that the miniport below is unbinding, so the request handlers will - // fail any request comming later - // - NdisAcquireSpinLock(&pAdapt->Lock); - pAdapt->UnbindingInProcess = TRUE; - if (pAdapt->QueuedRequest == TRUE) - { - pAdapt->QueuedRequest = FALSE; - NdisReleaseSpinLock(&pAdapt->Lock); - - PtRequestComplete(pAdapt, - &pAdapt->Request, - NDIS_STATUS_FAILURE ); - - } - else - { - NdisReleaseSpinLock(&pAdapt->Lock); - } -#ifndef WIN9X - // - // Check if we had called NdisIMInitializeDeviceInstanceEx and - // we are awaiting a call to MiniportInitialize. - // - if (pAdapt->MiniportInitPending == TRUE) - { - // - // Try to cancel the pending IMInit process. - // - LocalStatus = NdisIMCancelInitializeDeviceInstance( - DriverHandle, - &pAdapt->DeviceName); - - if (LocalStatus == NDIS_STATUS_SUCCESS) - { - // - // Successfully cancelled IM Initialization; our - // Miniport Initialize routine will not be called - // for this device. - // - pAdapt->MiniportInitPending = FALSE; - ASSERT(pAdapt->MiniportHandle == NULL); - } - else - { - // - // Our Miniport Initialize routine will be called - // (may be running on another thread at this time). - // Wait for it to finish. - // - NdisWaitEvent(&pAdapt->MiniportInitEvent, 0); - ASSERT(pAdapt->MiniportInitPending == FALSE); - } - - } -#endif // !WIN9X - - // - // Call NDIS to remove our device-instance. We do most of the work - // inside the HaltHandler. - // - // The Handle will be NULL if our miniport Halt Handler has been called or - // if the IM device was never initialized - // - - if (pAdapt->MiniportHandle != NULL) - { - *Status = NdisIMDeInitializeDeviceInstance(pAdapt->MiniportHandle); - - if (*Status != NDIS_STATUS_SUCCESS) - { - *Status = NDIS_STATUS_FAILURE; - } - } - else - { - // - // We need to do some work here. - // Close the binding below us - // and release the memory allocated. - // - - if(pAdapt->BindingHandle != NULL) - { - NdisResetEvent(&pAdapt->Event); - - NdisCloseAdapter(Status, pAdapt->BindingHandle); - - // - // Wait for it to complete - // - if(*Status == NDIS_STATUS_PENDING) - { - NdisWaitEvent(&pAdapt->Event, 0); - *Status = pAdapt->Status; - } - pAdapt->BindingHandle = NULL; - } - else - { - // - // Both Our MiniportHandle and Binding Handle should not be NULL. - // - *Status = NDIS_STATUS_FAILURE; - ASSERT(0); - } - - // - // Free the memory here, if was not released earlier(by calling the HaltHandler) - // - MPFreeAllPacketPools(pAdapt); - NdisFreeSpinLock(&pAdapt->Lock); - NdisFreeMemory(pAdapt, 0, 0); - } - - DBGPRINT(("<== PtUnbindAdapter: Adapt %p\n", pAdapt)); -} - -VOID -PtUnloadProtocol( - VOID -) -{ - NDIS_STATUS Status; - - if (ProtHandle != NULL) - { - NdisDeregisterProtocol(&Status, ProtHandle); - ProtHandle = NULL; - } - - DBGPRINT(("PtUnloadProtocol: done!\n")); -} - - - -VOID -PtCloseAdapterComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_STATUS Status - ) -/*++ - -Routine Description: - - Completion for the CloseAdapter call. - -Arguments: - - ProtocolBindingContext Pointer to the adapter structure - Status Completion status - -Return Value: - - None. - ---*/ -{ - PADAPT pAdapt =(PADAPT)ProtocolBindingContext; - - DBGPRINT(("CloseAdapterComplete: Adapt %p, Status %x\n", pAdapt, Status)); - pAdapt->Status = Status; - NdisSetEvent(&pAdapt->Event); -} - - -VOID -PtResetComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_STATUS Status - ) -/*++ - -Routine Description: - - Completion for the reset. - -Arguments: - - ProtocolBindingContext Pointer to the adapter structure - Status Completion status - -Return Value: - - None. - ---*/ -{ - - UNREFERENCED_PARAMETER(ProtocolBindingContext); - UNREFERENCED_PARAMETER(Status); - // - // We never issue a reset, so we should not be here. - // - ASSERT(0); -} - - -VOID -PtRequestComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN PNDIS_REQUEST NdisRequest, - IN NDIS_STATUS Status - ) -/*++ - -Routine Description: - - Completion handler for the previously posted request. All OIDS - are completed by and sent to the same miniport that they were requested for. - If Oid == OID_PNP_QUERY_POWER then the data structure needs to returned with all entries = - NdisDeviceStateUnspecified - -Arguments: - - ProtocolBindingContext Pointer to the adapter structure - NdisRequest The posted request - Status Completion status - -Return Value: - - None - ---*/ -{ - PADAPT pAdapt = (PADAPT)ProtocolBindingContext; - NDIS_OID Oid = pAdapt->Request.DATA.SET_INFORMATION.Oid ; - - // - // Since our request is not outstanding anymore - // - ASSERT(pAdapt->OutstandingRequests == TRUE); - - pAdapt->OutstandingRequests = FALSE; - - // - // Complete the Set or Query, and fill in the buffer for OID_PNP_CAPABILITIES, if need be. - // - switch (NdisRequest->RequestType) - { - case NdisRequestQueryInformation: - - // - // We never pass OID_PNP_QUERY_POWER down. - // - ASSERT(Oid != OID_PNP_QUERY_POWER); - - if ((Oid == OID_PNP_CAPABILITIES) && (Status == NDIS_STATUS_SUCCESS)) - { - MPQueryPNPCapabilities(pAdapt, &Status); - } - *pAdapt->BytesReadOrWritten = NdisRequest->DATA.QUERY_INFORMATION.BytesWritten; - *pAdapt->BytesNeeded = NdisRequest->DATA.QUERY_INFORMATION.BytesNeeded; - - if (((Oid == OID_GEN_MAC_OPTIONS) - && (Status == NDIS_STATUS_SUCCESS)) - && (NdisDotSysVersion >= NDIS_SYS_VERSION_51)) - { - // - // Only do this on Windows XP or greater (NDIS.SYS v 5.1); - // do not do in Windows 2000 (NDIS.SYS v 5.0)) - // - - // - // Remove the no-loopback bit from mac-options. In essence we are - // telling NDIS that we can handle loopback. We don't, but the - // interface below us does. If we do not do this, then loopback - // processing happens both below us and above us. This is wasteful - // at best and if Netmon is running, it will see multiple copies - // of loopback packets when sniffing above us. - // - // Only the lowest miniport is a stack of layered miniports should - // ever report this bit set to NDIS. - // - *(PULONG)NdisRequest->DATA.QUERY_INFORMATION.InformationBuffer &= ~NDIS_MAC_OPTION_NO_LOOPBACK; - } - - NdisMQueryInformationComplete(pAdapt->MiniportHandle, - Status); - break; - - case NdisRequestSetInformation: - - ASSERT( Oid != OID_PNP_SET_POWER); - - *pAdapt->BytesReadOrWritten = NdisRequest->DATA.SET_INFORMATION.BytesRead; - *pAdapt->BytesNeeded = NdisRequest->DATA.SET_INFORMATION.BytesNeeded; - NdisMSetInformationComplete(pAdapt->MiniportHandle, - Status); - break; - - default: - ASSERT(0); - break; - } - -} - - -VOID -PtStatus( - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_STATUS GeneralStatus, - IN PVOID StatusBuffer, - IN UINT StatusBufferSize - ) -/*++ - -Routine Description: - - Status handler for the lower-edge(protocol). - -Arguments: - - ProtocolBindingContext Pointer to the adapter structure - GeneralStatus Status code - StatusBuffer Status buffer - StatusBufferSize Size of the status buffer - -Return Value: - - None - ---*/ -{ - PADAPT pAdapt = (PADAPT)ProtocolBindingContext; - - // - // Pass up this indication only if the upper edge miniport is initialized - // and powered on. Also ignore indications that might be sent by the lower - // miniport when it isn't at D0. - // - if ((pAdapt->MiniportHandle != NULL) && - (pAdapt->MPDeviceState == NdisDeviceStateD0) && - (pAdapt->PTDeviceState == NdisDeviceStateD0)) - { - if ((GeneralStatus == NDIS_STATUS_MEDIA_CONNECT) || - (GeneralStatus == NDIS_STATUS_MEDIA_DISCONNECT)) - { - - pAdapt->LastIndicatedStatus = GeneralStatus; - } - NdisMIndicateStatus(pAdapt->MiniportHandle, - GeneralStatus, - StatusBuffer, - StatusBufferSize); - } - // - // Save the last indicated media status - // - else - { - if ((pAdapt->MiniportHandle != NULL) && - ((GeneralStatus == NDIS_STATUS_MEDIA_CONNECT) || - (GeneralStatus == NDIS_STATUS_MEDIA_DISCONNECT))) - { - pAdapt->LatestUnIndicateStatus = GeneralStatus; - } - } - -} - - -VOID -PtStatusComplete( - IN NDIS_HANDLE ProtocolBindingContext - ) -/*++ - -Routine Description: - - -Arguments: - - -Return Value: - - ---*/ -{ - PADAPT pAdapt = (PADAPT)ProtocolBindingContext; - - // - // Pass up this indication only if the upper edge miniport is initialized - // and powered on. Also ignore indications that might be sent by the lower - // miniport when it isn't at D0. - // - if ((pAdapt->MiniportHandle != NULL) && - (pAdapt->MPDeviceState == NdisDeviceStateD0) && - (pAdapt->PTDeviceState == NdisDeviceStateD0)) - { - NdisMIndicateStatusComplete(pAdapt->MiniportHandle); - } -} - - -VOID -PtSendComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN PNDIS_PACKET Packet, - IN NDIS_STATUS Status - ) -/*++ - -Routine Description: - - Called by NDIS when the miniport below had completed a send. We should - complete the corresponding upper-edge send this represents. - -Arguments: - - ProtocolBindingContext - Points to ADAPT structure - Packet - Low level packet being completed - Status - status of send - -Return Value: - - None - ---*/ -{ - PADAPT pAdapt = (PADAPT)ProtocolBindingContext; - PNDIS_PACKET Pkt; - NDIS_HANDLE PoolHandle; - -#ifdef NDIS51 - // - // Packet stacking: - // - // Determine if the packet we are completing is the one we allocated. If so, then - // get the original packet from the reserved area and completed it and free the - // allocated packet. If this is the packet that was sent down to us, then just - // complete it - // - PoolHandle = NdisGetPoolFromPacket(Packet); - if (PoolHandle != pAdapt->SendPacketPoolHandle) - { - // - // We had passed down a packet belonging to the protocol above us. - // - // DBGPRINT(("PtSendComp: Adapt %p, Stacked Packet %p\n", pAdapt, Packet)); - - NdisMSendComplete(pAdapt->MiniportHandle, - Packet, - Status); - } - else -#endif // NDIS51 - { - PSEND_RSVD SendRsvd; - - SendRsvd = (PSEND_RSVD)(Packet->ProtocolReserved); - Pkt = SendRsvd->OriginalPkt; - -#ifndef WIN9X - NdisIMCopySendCompletePerPacketInfo (Pkt, Packet); -#endif - - NdisDprFreePacket(Packet); - - NdisMSendComplete(pAdapt->MiniportHandle, - Pkt, - Status); - } - // - // Decrease the outstanding send count - // - ADAPT_DECR_PENDING_SENDS(pAdapt); -} - - -VOID -PtTransferDataComplete( - IN NDIS_HANDLE ProtocolBindingContext, - IN PNDIS_PACKET Packet, - IN NDIS_STATUS Status, - IN UINT BytesTransferred - ) -/*++ - -Routine Description: - - Entry point called by NDIS to indicate completion of a call by us - to NdisTransferData. - - See notes under SendComplete. - -Arguments: - -Return Value: - ---*/ -{ - PADAPT pAdapt =(PADAPT)ProtocolBindingContext; - - if(pAdapt->MiniportHandle) - { - NdisMTransferDataComplete(pAdapt->MiniportHandle, - Packet, - Status, - BytesTransferred); - } -} - - -NDIS_STATUS -PtReceive( - IN NDIS_HANDLE ProtocolBindingContext, - IN NDIS_HANDLE MacReceiveContext, - IN PVOID HeaderBuffer, - IN UINT HeaderBufferSize, - IN PVOID LookAheadBuffer, - IN UINT LookAheadBufferSize, - IN UINT PacketSize - ) -/*++ - -Routine Description: - - Handle receive data indicated up by the miniport below. We pass - it along to the protocol above us. - - If the miniport below indicates packets, NDIS would more - likely call us at our ReceivePacket handler. However we - might be called here in certain situations even though - the miniport below has indicated a receive packet, e.g. - if the miniport had set packet status to NDIS_STATUS_RESOURCES. - -Arguments: - - - -Return Value: - - NDIS_STATUS_SUCCESS if we processed the receive successfully, - NDIS_STATUS_XXX error code if we discarded it. - ---*/ -{ - PADAPT pAdapt = (PADAPT)ProtocolBindingContext; - PNDIS_PACKET MyPacket, Packet = NULL; - NDIS_STATUS Status = NDIS_STATUS_SUCCESS; - ULONG Proc = KeGetCurrentProcessorNumber(); - - if ((!pAdapt->MiniportHandle) || (pAdapt->MPDeviceState > NdisDeviceStateD0)) - { - Status = NDIS_STATUS_FAILURE; - } - else do - { - // - // Get at the packet, if any, indicated up by the miniport below. - // - Packet = NdisGetReceivedPacket(pAdapt->BindingHandle, MacReceiveContext); - if (Packet != NULL) - { - // - // The miniport below did indicate up a packet. Use information - // from that packet to construct a new packet to indicate up. - // - -#ifdef NDIS51 - // - // NDIS 5.1 NOTE: Do not reuse the original packet in indicating - // up a receive, even if there is sufficient packet stack space. - // If we had to do so, we would have had to overwrite the - // status field in the original packet to NDIS_STATUS_RESOURCES, - // and it is not allowed for protocols to overwrite this field - // in received packets. - // -#endif // NDIS51 - - // - // Get a packet off the pool and indicate that up - // - NdisDprAllocatePacket(&Status, - &MyPacket, - pAdapt->RecvPacketPoolHandle); - - if (Status == NDIS_STATUS_SUCCESS) - { - // - // Make our packet point to data from the original - // packet. NOTE: this works only because we are - // indicating a receive directly from the context of - // our receive indication. If we need to queue this - // packet and indicate it from another thread context, - // we will also have to allocate a new buffer and copy - // over the packet contents, OOB data and per-packet - // information. This is because the packet data - // is available only for the duration of this - // receive indication call. - // - NDIS_PACKET_FIRST_NDIS_BUFFER(MyPacket) = NDIS_PACKET_FIRST_NDIS_BUFFER(Packet); - NDIS_PACKET_LAST_NDIS_BUFFER(MyPacket) = NDIS_PACKET_LAST_NDIS_BUFFER(Packet); - - // - // Get the original packet (it could be the same packet as the - // one received or a different one based on the number of layered - // miniports below) and set it on the indicated packet so the OOB - // data is visible correctly at protocols above. If the IM driver - // modifies the packet in any way it should not set the new packet's - // original packet equal to the original packet of the packet that - // was indicated to it from the underlying driver, in this case, the - // IM driver should also ensure that the related per packet info should - // be copied to the new packet. - // we can set the original packet to the original packet of the packet - // indicated from the underlying driver because the driver doesn't modify - // the data content in the packet. - // - NDIS_SET_ORIGINAL_PACKET(MyPacket, NDIS_GET_ORIGINAL_PACKET(Packet)); - NDIS_SET_PACKET_HEADER_SIZE(MyPacket, HeaderBufferSize); - - // - // Copy packet flags. - // - NdisGetPacketFlags(MyPacket) = NdisGetPacketFlags(Packet); - - // - // Force protocols above to make a copy if they want to hang - // on to data in this packet. This is because we are in our - // Receive handler (not ReceivePacket) and we can't return a - // ref count from here. - // - NDIS_SET_PACKET_STATUS(MyPacket, NDIS_STATUS_RESOURCES); - - // - // By setting NDIS_STATUS_RESOURCES, we also know that we can reclaim - // this packet as soon as the call to NdisMIndicateReceivePacket - // returns. - // - - if (pAdapt->MiniportHandle != NULL) - { - NdisMIndicateReceivePacket(pAdapt->MiniportHandle, &MyPacket, 1); - } - - // - // Reclaim the indicated packet. Since we had set its status - // to NDIS_STATUS_RESOURCES, we are guaranteed that protocols - // above are done with it. - // - NdisDprFreePacket(MyPacket); - - break; - } - } - else - { - // - // The miniport below us uses the old-style (not packet) - // receive indication. Fall through. - // - } - - // - // Fall through if the miniport below us has either not - // indicated a packet or we could not allocate one - // - pAdapt->ReceivedIndicationFlags[Proc] = TRUE; - if (pAdapt->MiniportHandle == NULL) - { - break; - } - switch (pAdapt->Medium) - { - case NdisMedium802_3: - case NdisMediumWan: - NdisMEthIndicateReceive(pAdapt->MiniportHandle, - MacReceiveContext, - HeaderBuffer, - HeaderBufferSize, - LookAheadBuffer, - LookAheadBufferSize, - PacketSize); - break; - - case NdisMedium802_5: - NdisMTrIndicateReceive(pAdapt->MiniportHandle, - MacReceiveContext, - HeaderBuffer, - HeaderBufferSize, - LookAheadBuffer, - LookAheadBufferSize, - PacketSize); - break; - -#if FDDI - case NdisMediumFddi: - NdisMFddiIndicateReceive(pAdapt->MiniportHandle, - MacReceiveContext, - HeaderBuffer, - HeaderBufferSize, - LookAheadBuffer, - LookAheadBufferSize, - PacketSize); - break; -#endif - default: - ASSERT(FALSE); - break; - } - - } while(FALSE); - - return Status; -} - - -VOID -PtReceiveComplete( - IN NDIS_HANDLE ProtocolBindingContext - ) -/*++ - -Routine Description: - - Called by the adapter below us when it is done indicating a batch of - received packets. - -Arguments: - - ProtocolBindingContext Pointer to our adapter structure. - -Return Value: - - None - ---*/ -{ - PADAPT pAdapt =(PADAPT)ProtocolBindingContext; - ULONG Proc = KeGetCurrentProcessorNumber(); - - if (((pAdapt->MiniportHandle != NULL) - && (pAdapt->MPDeviceState == NdisDeviceStateD0)) - && (pAdapt->ReceivedIndicationFlags[Proc])) - { - switch (pAdapt->Medium) - { - case NdisMedium802_3: - case NdisMediumWan: - NdisMEthIndicateReceiveComplete(pAdapt->MiniportHandle); - break; - - case NdisMedium802_5: - NdisMTrIndicateReceiveComplete(pAdapt->MiniportHandle); - break; -#if FDDI - case NdisMediumFddi: - NdisMFddiIndicateReceiveComplete(pAdapt->MiniportHandle); - break; -#endif - default: - ASSERT(FALSE); - break; - } - } - - pAdapt->ReceivedIndicationFlags[Proc] = FALSE; -} - - -INT -PtReceivePacket( - IN NDIS_HANDLE ProtocolBindingContext, - IN PNDIS_PACKET Packet - ) -/*++ - -Routine Description: - - ReceivePacket handler. Called by NDIS if the miniport below supports - NDIS 4.0 style receives. Re-package the buffer chain in a new packet - and indicate the new packet to protocols above us. Any context for - packets indicated up must be kept in the MiniportReserved field. - - NDIS 5.1 - packet stacking - if there is sufficient "stack space" in - the packet passed to us, we can use the same packet in a receive - indication. - -Arguments: - - ProtocolBindingContext - Pointer to our adapter structure. - Packet - Pointer to the packet - -Return Value: - - == 0 -> We are done with the packet - != 0 -> We will keep the packet and call NdisReturnPackets() this - many times when done. ---*/ -{ - PADAPT pAdapt =(PADAPT)ProtocolBindingContext; - NDIS_STATUS Status; - PNDIS_PACKET MyPacket; - BOOLEAN Remaining; - - // - // Drop the packet silently if the upper miniport edge isn't initialized or - // the miniport edge is in low power state - // - if ((!pAdapt->MiniportHandle) || (pAdapt->MPDeviceState > NdisDeviceStateD0)) - { - return 0; - } - -#ifdef NDIS51 - // - // Check if we can reuse the same packet for indicating up. - // See also: PtReceive(). - // - (VOID)NdisIMGetCurrentPacketStack(Packet, &Remaining); - if (Remaining) - { - // - // We can reuse "Packet". Indicate it up and be done with it. - // - Status = NDIS_GET_PACKET_STATUS(Packet); - NdisMIndicateReceivePacket(pAdapt->MiniportHandle, &Packet, 1); - return((Status != NDIS_STATUS_RESOURCES) ? 1 : 0); - } -#endif // NDIS51 - - // - // Get a packet off the pool and indicate that up - // - NdisDprAllocatePacket(&Status, - &MyPacket, - pAdapt->RecvPacketPoolHandle); - - if (Status == NDIS_STATUS_SUCCESS) - { - PRECV_RSVD RecvRsvd; - - RecvRsvd = (PRECV_RSVD)(MyPacket->MiniportReserved); - RecvRsvd->OriginalPkt = Packet; - - NDIS_PACKET_FIRST_NDIS_BUFFER(MyPacket) = NDIS_PACKET_FIRST_NDIS_BUFFER(Packet); - NDIS_PACKET_LAST_NDIS_BUFFER(MyPacket) = NDIS_PACKET_LAST_NDIS_BUFFER(Packet); - - // - // Get the original packet (it could be the same packet as the one - // received or a different one based on the number of layered miniports - // below) and set it on the indicated packet so the OOB data is visible - // correctly to protocols above us. - // - NDIS_SET_ORIGINAL_PACKET(MyPacket, NDIS_GET_ORIGINAL_PACKET(Packet)); - - // - // Set Packet Flags - // - NdisGetPacketFlags(MyPacket) = NdisGetPacketFlags(Packet); - - Status = NDIS_GET_PACKET_STATUS(Packet); - - NDIS_SET_PACKET_STATUS(MyPacket, Status); - NDIS_SET_PACKET_HEADER_SIZE(MyPacket, NDIS_GET_PACKET_HEADER_SIZE(Packet)); - - if (pAdapt->MiniportHandle != NULL) - { - NdisMIndicateReceivePacket(pAdapt->MiniportHandle, &MyPacket, 1); - } - - // - // Check if we had indicated up the packet with NDIS_STATUS_RESOURCES - // NOTE -- do not use NDIS_GET_PACKET_STATUS(MyPacket) for this since - // it might have changed! Use the value saved in the local variable. - // - if (Status == NDIS_STATUS_RESOURCES) - { - // - // Our ReturnPackets handler will not be called for this packet. - // We should reclaim it right here. - // - NdisDprFreePacket(MyPacket); - } - - return((Status != NDIS_STATUS_RESOURCES) ? 1 : 0); - } - else - { - // - // We are out of packets. Silently drop it. - // - return(0); - } -} - - -NDIS_STATUS -PtPNPHandler( - IN NDIS_HANDLE ProtocolBindingContext, - IN PNET_PNP_EVENT pNetPnPEvent - ) - -/*++ -Routine Description: - - This is called by NDIS to notify us of a PNP event related to a lower - binding. Based on the event, this dispatches to other helper routines. - - NDIS 5.1: forward this event to the upper protocol(s) by calling - NdisIMNotifyPnPEvent. - -Arguments: - - ProtocolBindingContext - Pointer to our adapter structure. Can be NULL - for "global" notifications - - pNetPnPEvent - Pointer to the PNP event to be processed. - -Return Value: - - NDIS_STATUS code indicating status of event processing. - ---*/ -{ - PADAPT pAdapt =(PADAPT)ProtocolBindingContext; - NDIS_STATUS Status = NDIS_STATUS_SUCCESS; - - DBGPRINT(("PtPnPHandler: Adapt %p, Event %d\n", pAdapt, pNetPnPEvent->NetEvent)); - - switch (pNetPnPEvent->NetEvent) - { - case NetEventSetPower: - Status = PtPnPNetEventSetPower(pAdapt, pNetPnPEvent); - break; - - case NetEventReconfigure: - Status = PtPnPNetEventReconfigure(pAdapt, pNetPnPEvent); - break; - - default: -#ifdef NDIS51 - // - // Pass on this notification to protocol(s) above, before - // doing anything else with it. - // - if (pAdapt && pAdapt->MiniportHandle) - { - Status = NdisIMNotifyPnPEvent(pAdapt->MiniportHandle, pNetPnPEvent); - } -#else - Status = NDIS_STATUS_SUCCESS; - -#endif // NDIS51 - - break; - } - - return Status; -} - - -NDIS_STATUS -PtPnPNetEventReconfigure( - IN PADAPT pAdapt, - IN PNET_PNP_EVENT pNetPnPEvent - ) -/*++ -Routine Description: - - This routine is called from NDIS to notify our protocol edge of a - reconfiguration of parameters for either a specific binding (pAdapt - is not NULL), or global parameters if any (pAdapt is NULL). - -Arguments: - - pAdapt - Pointer to our adapter structure. - pNetPnPEvent - the reconfigure event - -Return Value: - - NDIS_STATUS_SUCCESS - ---*/ -{ - NDIS_STATUS ReconfigStatus = NDIS_STATUS_SUCCESS; - NDIS_STATUS ReturnStatus = NDIS_STATUS_SUCCESS; - - do - { - // - // Is this is a global reconfiguration notification ? - // - if (pAdapt == NULL) - { - // - // An important event that causes this notification to us is if - // one of our upper-edge miniport instances was enabled after being - // disabled earlier, e.g. from Device Manager in Win2000. Note that - // NDIS calls this because we had set up an association between our - // miniport and protocol entities by calling NdisIMAssociateMiniport. - // - // Since we would have torn down the lower binding for that miniport, - // we need NDIS' assistance to re-bind to the lower miniport. The - // call to NdisReEnumerateProtocolBindings does exactly that. - // - NdisReEnumerateProtocolBindings (ProtHandle); - - break; - } - -#ifdef NDIS51 - // - // Pass on this notification to protocol(s) above before doing anything - // with it. - // - if (pAdapt->MiniportHandle) - { - ReturnStatus = NdisIMNotifyPnPEvent(pAdapt->MiniportHandle, pNetPnPEvent); - } -#endif // NDIS51 - - ReconfigStatus = NDIS_STATUS_SUCCESS; - - } while(FALSE); - - DBGPRINT(("<==PtPNPNetEventReconfigure: pAdapt %p\n", pAdapt)); - -#ifdef NDIS51 - // - // Overwrite status with what upper-layer protocol(s) returned. - // - ReconfigStatus = ReturnStatus; -#endif - - return ReconfigStatus; -} - - -NDIS_STATUS -PtPnPNetEventSetPower( - IN PADAPT pAdapt, - IN PNET_PNP_EVENT pNetPnPEvent - ) -/*++ -Routine Description: - - This is a notification to our protocol edge of the power state - of the lower miniport. If it is going to a low-power state, we must - wait here for all outstanding sends and requests to complete. - - NDIS 5.1: Since we use packet stacking, it is not sufficient to - check usage of our local send packet pool to detect whether or not - all outstanding sends have completed. For this, use the new API - NdisQueryPendingIOCount. - - NDIS 5.1: Use the 5.1 API NdisIMNotifyPnPEvent to pass on PnP - notifications to upper protocol(s). - -Arguments: - - pAdapt - Pointer to the adpater structure - pNetPnPEvent - The Net Pnp Event. this contains the new device state - -Return Value: - - NDIS_STATUS_SUCCESS or the status returned by upper-layer protocols. - ---*/ -{ - PNDIS_DEVICE_POWER_STATE pDeviceState =(PNDIS_DEVICE_POWER_STATE)(pNetPnPEvent->Buffer); - NDIS_DEVICE_POWER_STATE PrevDeviceState = pAdapt->PTDeviceState; - NDIS_STATUS Status; - NDIS_STATUS ReturnStatus; - - ReturnStatus = NDIS_STATUS_SUCCESS; - - // - // Set the Internal Device State, this blocks all new sends or receives - // - NdisAcquireSpinLock(&pAdapt->Lock); - pAdapt->PTDeviceState = *pDeviceState; - - // - // Check if the miniport below is going to a low power state. - // - if (pAdapt->PTDeviceState > NdisDeviceStateD0) - { - // - // If the miniport below is going to standby, fail all incoming requests - // - if (PrevDeviceState == NdisDeviceStateD0) - { - pAdapt->StandingBy = TRUE; - } - - NdisReleaseSpinLock(&pAdapt->Lock); - -#ifdef NDIS51 - // - // Notify upper layer protocol(s) first. - // - if (pAdapt->MiniportHandle != NULL) - { - ReturnStatus = NdisIMNotifyPnPEvent(pAdapt->MiniportHandle, pNetPnPEvent); - } -#endif // NDIS51 - - // - // Wait for outstanding sends and requests to complete. - // - while (pAdapt->OutstandingSends != 0) - { - NdisMSleep(2); - } - - while (pAdapt->OutstandingRequests == TRUE) - { - // - // sleep till outstanding requests complete - // - NdisMSleep(2); - } - - // - // If the below miniport is going to low power state, complete the queued request - // - NdisAcquireSpinLock(&pAdapt->Lock); - if (pAdapt->QueuedRequest) - { - pAdapt->QueuedRequest = FALSE; - NdisReleaseSpinLock(&pAdapt->Lock); - PtRequestComplete(pAdapt, &pAdapt->Request, NDIS_STATUS_FAILURE); - } - else - { - NdisReleaseSpinLock(&pAdapt->Lock); - } - - - ASSERT(NdisPacketPoolUsage(pAdapt->SendPacketPoolHandle) == 0); - ASSERT(pAdapt->OutstandingRequests == FALSE); - } - else - { - // - // If the physical miniport is powering up (from Low power state to D0), - // clear the flag - // - if (PrevDeviceState > NdisDeviceStateD0) - { - pAdapt->StandingBy = FALSE; - } - // - // The device below is being turned on. If we had a request - // pending, send it down now. - // - if (pAdapt->QueuedRequest == TRUE) - { - pAdapt->QueuedRequest = FALSE; - - pAdapt->OutstandingRequests = TRUE; - NdisReleaseSpinLock(&pAdapt->Lock); - - NdisRequest(&Status, - pAdapt->BindingHandle, - &pAdapt->Request); - - if (Status != NDIS_STATUS_PENDING) - { - PtRequestComplete(pAdapt, - &pAdapt->Request, - Status); - - } - } - else - { - NdisReleaseSpinLock(&pAdapt->Lock); - } - - -#ifdef NDIS51 - // - // Pass on this notification to protocol(s) above - // - if (pAdapt->MiniportHandle) - { - ReturnStatus = NdisIMNotifyPnPEvent(pAdapt->MiniportHandle, pNetPnPEvent); - } -#endif // NDIS51 - - } - - return ReturnStatus; -} - -VOID -PtReferenceAdapt( - IN PADAPT pAdapt - ) -{ - NdisAcquireSpinLock(&pAdapt->Lock); - - ASSERT(pAdapt->RefCount >= 0); - - pAdapt->RefCount ++; - NdisReleaseSpinLock(&pAdapt->Lock); -} - - -BOOLEAN -PtDereferenceAdapt( - IN PADAPT pAdapt - ) -{ - NdisAcquireSpinLock(&pAdapt->Lock); - - ASSERT(pAdapt->RefCount > 0); - - pAdapt->RefCount--; - - if (pAdapt->RefCount == 0) - { - NdisReleaseSpinLock(&pAdapt->Lock); - - // - // Free all resources on this adapter structure. - // - MPFreeAllPacketPools (pAdapt);; - NdisFreeSpinLock(&pAdapt->Lock); - NdisFreeMemory(pAdapt, 0 , 0); - - return TRUE; - - } - else - { - NdisReleaseSpinLock(&pAdapt->Lock); - - return FALSE; - } -} - - diff --git a/original_passthru/sources b/original_passthru/sources deleted file mode 100644 index d52d78f..0000000 --- a/original_passthru/sources +++ /dev/null @@ -1,39 +0,0 @@ -TARGETNAME=passthru -TARGETTYPE=DRIVER - -C_DEFINES=$(C_DEFINES) -DNDIS_MINIPORT_DRIVER -DNDIS_WDM=1 - -MSC_WARNING_LEVEL=/WX /W4 - -!if "$(DDK_TARGET_OS)"=="Win2K" -# -# The driver is built in the Win2K build environment -# -C_DEFINES=$(C_DEFINES) -DNDIS40_MINIPORT=1 -C_DEFINES=$(C_DEFINES) -DNDIS40=1 -!else -# -# The driver is built in the XP or .NET build environment -# So let us build NDIS 5.1 version. -# -C_DEFINES=$(C_DEFINES) -DNDIS51_MINIPORT=1 -C_DEFINES=$(C_DEFINES) -DNDIS51=1 -!endif - -# Uncomment the following to build for Win98/SE/WinMe -# This causes several APIs that are not present in Win9X to be -# ifdef'ed out. -# C_DEFINES=$(C_DEFINES) -DWIN9X=1 - -PRECOMPILED_INCLUDE=precomp.h - -TARGETLIBS=$(DDK_LIB_PATH)\ndis.lib - -INCLUDES= - -SOURCES=\ - miniport.c \ - passthru.c \ - passthru.rc \ - protocol.c - -- 2.43.0