示例#1
0
VOID
MiniportFreeAllPacketPools5(
    IN PADAPTER                    pAdapt
    )
{
	RECEIVED_PACKET			PacketArray[MAX_RECV_PACKET_POOL_SIZE];
    ULONG					NumberOfPackets = 0, i;

	//释放所有已经接收并存储的包
	NdisAcquireSpinLock(&pAdapt->Lock);
	if(pAdapt->ReceivedPacketCount > 0)
	{
		NumberOfPackets = pAdapt->ReceivedPacketCount;
		
		NdisMoveMemory(PacketArray,
						pAdapt->ReceivedPackets,
						NumberOfPackets * sizeof(RECEIVED_PACKET));
		pAdapt->ReceivedPacketCount = 0;
		for(i=0;i<NumberOfPackets;i++)
		{
			if(PacketArray[i].pNdisPacket && PacketArray[i].bReturnPacket)
			{
				MiniportReturnPacket5(pAdapt, PacketArray[i].pNdisPacket);
			}
		}
	}
	NdisReleaseSpinLock(&pAdapt->Lock);

    if (pAdapt->RecvPacketPoolHandle != NULL)
    {
        NdisFreePacketPool(pAdapt->RecvPacketPoolHandle);
        pAdapt->RecvPacketPoolHandle = NULL;
    }

    if (pAdapt->SendPacketPoolHandle != NULL)
    {
        NdisFreePacketPool(pAdapt->SendPacketPoolHandle);
        pAdapt->SendPacketPoolHandle = NULL;
    }
	if(pAdapt->RecvBufferPool != NULL)
	{
		NdisFreeBufferPool(pAdapt->RecvBufferPool);
		pAdapt->RecvBufferPool  = NULL;
	}
	if(pAdapt->SendBufferPool != NULL)
	{
		NdisFreeBufferPool(pAdapt->SendBufferPool);
		pAdapt->SendBufferPool  = NULL;
	}
}
示例#2
0
文件: epacket.c 项目: OPSF/uClinux
VOID NDIS_API PacketUnbindAdapterComplete(IN POPEN_INSTANCE Open,
                                          IN NDIS_STATUS Status)
{
  // upcall on NdisCloseAdapter completion


  // If Open->Status == NDIS_STATUS_PENDING then we must complete the pended unbinding
  if (Open->Status == NDIS_STATUS_PENDING) {
    NdisCompleteUnbindAdapter(Open->BindAdapterContext, Status);
    Open->Status = NDIS_STATUS_SUCCESS;
  }

  if (Status != NDIS_STATUS_SUCCESS)
    return;

  // Remove Adapter from global list
  RemoveEntryList(&Open->ListElement);

  // Free Memory
  NdisFreeSpinLock(&Open->RequestSpinLock);
  NdisFreeSpinLock(&Open->RcvQSpinLock);
  NdisFreeSpinLock(&Open->ResetSpinLock);

  NdisFreeBufferPool(Open->BufferPool);

  NdisFreePacketPool(Open->PacketPool);

  NdisFreeMemory(Open, sizeof(OPEN_INSTANCE), 0);
}
示例#3
0
/************************************************************
free the resources allocated by an adapter
************************************************************/
VOID PacketFreeResources( POPEN_INSTANCE Open )
{
    NdisFreeSpinLock( &Open->RequestSpinLock );
    NdisFreeSpinLock( &Open->RcvQSpinLock );
    NdisFreeSpinLock( &Open->ResetSpinLock );
    NdisFreeBufferPool( Open->BufferPool );
    NdisFreePacketPool( Open->PacketPool );
}
示例#4
0
void divert_kill(void)
{
	lock();

	free_queue(&_packet_queue);
	free_queue(&_packet_free);

	free_ifs();

	// XXX
	NdisFreeBufferPool(_buf_pool);
	NdisFreePacketPool(_packet_pool);

	unlock();

	NdisFreeSpinLock(&_lock);
}
示例#5
0
/******************************************************************************
 *
 *  Name: FreeRxQ()
 *
 *  Description: Free Rx buffer
 *
 *  Arguments:  PMRVDRV_ADAPTER Adapter
 *    
 *  Return Value: NDIS_STATUS_SUCCESS or NDIS_STATUS_FAILURE
 * 
 *  Notes:        
 *
 *****************************************************************************/
NDIS_STATUS FreeRxQ(
  IN PMRVDRV_ADAPTER Adapter
  )
{
    ULONG i;    

    DBGPRINT(DBG_BUF|DBG_RX|DBG_HELP,(L"Free Rx Q\r\n"));
   
    for ( i=0; i < MRVDRV_NUM_RX_PKT_IN_QUEUE; i++ )
    {
        if ( Adapter->pRxBufVM[i] != NULL )
        {                       
            (ULONG)Adapter->pRxBufVM[i] -= MRVDRV_ETH_RX_HIDDEN_HEADER_SIZE; 

            NdisFreeMemory(Adapter->pRxBufVM[i],
                           MRVDRV_ETH_RX_PACKET_BUFFER_SIZE,
                           0);            
            Adapter->pRxBufVM[i] = NULL;
        }

        if ( Adapter->pRxBuffer[i] != NULL )
        {
            NdisFreeBuffer(Adapter->pRxBuffer[i]);
            Adapter->pRxBuffer[i] = NULL;
        }

        if ( Adapter->pRxPacket[i] != NULL )
        {
            NdisFreePacket(Adapter->pRxPacket[i]);
            Adapter->pRxPacket[i] = NULL;
        }
    } 
    
    if ( Adapter->RxBufferPoolHandle != NULL )
    {
        NdisFreeBufferPool(Adapter->RxBufferPoolHandle);
        Adapter->RxBufferPoolHandle = NULL;
    }

    if ( Adapter->RxPacketPoolHandle != NULL )
    {
        NdisFreePacketPool(Adapter->RxPacketPoolHandle);
        Adapter->RxPacketPoolHandle = NULL;
    }
    return NDIS_STATUS_SUCCESS;
}
示例#6
0
/*
 * Frees the resources allocated
 *
 */
VOID PKTFreeResources (POPEN_INSTANCE pOI)
{
	// release the packet buffer
	if (pOI->Buffer != NULL) {
		NdisFreeMemory (pOI->Buffer, pOI->BufSize, 0);
		pOI->Buffer = NULL;
	}

	// release the bpf memory
	if (pOI->bpfprogram != NULL) {
		NdisFreeMemory (pOI->bpfprogram, pOI->bpfprogramlen, 0);
		pOI->bpfprogram = NULL;
	}

	// free the packet & buffer pools
	NdisFreeBufferPool (pOI->BufferPool);
	NdisFreePacketPool (pOI->PacketPool);

} 
示例#7
0
// Release the packet buffer
void NeoFreePacketBuffer(PACKET_BUFFER *p)
{
	// Validate arguments
	if (p == NULL)
	{
		return;
	}

	// Detach the buffer from the packet
	NdisUnchainBufferAtFront(p->NdisPacket, &p->NdisBuffer);
	// Release the packet
	NdisFreePacket(p->NdisPacket);
	// Release the packet pool
	NdisFreePacketPool(p->PacketPool);
	// Release the buffer
	NdisFreeBuffer(p->NdisBuffer);
	// Release the memory
	NeoFree(p->Buf);
	// Release the buffer pool
	NdisFreeBufferPool(p->BufferPool);
	// Release the memory
	NeoFree(p);
}
示例#8
0
文件: epacket.c 项目: OPSF/uClinux
VOID NDIS_API PacketBindAdapterComplete(IN NDIS_HANDLE  ProtocolBindingContext,
                                        IN NDIS_STATUS  Status,
                                        IN NDIS_STATUS  OpenErrorStatus)
{
  // upcall on Bind completion

  POPEN_INSTANCE Open = (POPEN_INSTANCE)ProtocolBindingContext;

  // If the binding is unsuccessful then we deallocate data structures in 
  // preparation for unloading
  if (Status != NDIS_STATUS_SUCCESS) {
    NdisFreeSpinLock(&Open->RequestSpinLock);
    NdisFreeSpinLock(&Open->RcvQSpinLock);

    NdisFreeBufferPool(Open->BufferPool);
    NdisFreePacketPool(Open->PacketPool);

    NdisFreeMemory(Open, sizeof(OPEN_INSTANCE), 0);
  }
  else {
    // Insert New Adapter into list
    InsertTailList(&GlobalDeviceExtension->OpenList, &Open->ListElement);
  }
}
示例#9
0
//
// NOTE: THIS CANNOT BE PAGEABLE
//
VOID
ArcDeleteFilter(
    IN PARC_FILTER Filter
    )

/*++

Routine Description:

    This routine is used to delete the memory associated with a filter
    database.  Note that this routines *ASSUMES* that the database
    has been cleared of any active filters.

Arguments:

    Filter - A pointer to an ARC_FILTER to be deleted.

Return Value:

    None.

--*/

{
    PARC_PACKET Packet;
    PARC_BUFFER_LIST Buffer;

    ASSERT(Filter->FreeBindingMask == (MASK)-1);
    ASSERT(Filter->OpenList == NULL);


    NdisFreeBufferPool(Filter->ReceiveBufferPool);

    //
    // Free all ARC_PACKETS
    //

    while (Filter->OutstandingPackets != NULL) {

        Packet = Filter->OutstandingPackets;
        Filter->OutstandingPackets = Packet->Next;

        //
        // This puts all the component parts on the free lists.
        //
        ArcDestroyPacket(Filter, Packet);

    }

    while (Filter->FreePackets != NULL) {

        Packet = Filter->FreePackets;
        Filter->FreePackets = Packet->Next;

        ExFreePool(Packet);

    }

    while (Filter->FreeBufferList) {

        Buffer = Filter->FreeBufferList;
        Filter->FreeBufferList = Buffer->Next;

        ExFreePool(Buffer->Buffer);
        ExFreePool(Buffer);

    }

    NdisFreeMemory(Filter, sizeof(ARC_FILTER), 0);

    ArcDereferencePackage();

}
示例#10
0
/*+
 *
 * FreeAdapterMemory
 *
 * Routine Description:
 *
 *    Frees the memory previously allocated by
 *    AllocateAdapterMemory
 *
 * Arguments:
 *
 *    Adapter - The adapter to deallocate memory for.
 *
 * Return Value:
 *
 *    None.
 *
-*/
extern
VOID
FreeAdapterMemory(
    IN PDC21X4_ADAPTER Adapter
    )
{

   PDC21X4_RECEIVE_DESCRIPTOR ReceiveDescriptor;
   PRCV_HEADER RcvHeader;
   PNDIS_PACKET Packet;
   UINT i;

   if ((PVOID)Adapter->DescriptorRing.AllocVa == (PVOID)NULL) {
      // AllocateAdapterMemory failed on the first allocation:
      // no ressources were allocated
      return;
   }

   for (i = 0,
      ReceiveDescriptor = (PDC21X4_RECEIVE_DESCRIPTOR)Adapter->ReceiveDescriptorRingVa;
      i < Adapter->ReceiveRingSize;
      i++,
      (PCHAR)ReceiveDescriptor += Adapter->DescriptorSize
      ) {

      if (ReceiveDescriptor->RcvHeader) {

         RcvHeader = ReceiveDescriptor->RcvHeader;

         if (RcvHeader->FlushBuffer) {
             NdisFreeBuffer(RcvHeader->FlushBuffer);
         }
         if (RcvHeader->Packet) {
             NdisFreePacket(RcvHeader->Packet);
         }

         if (!Adapter->RcvBufferSpace.Va)

         {
            NdisMFreeSharedMemory(
               Adapter->MiniportAdapterHandle,
               RcvHeader->AllocSize,
               TRUE,
               (PVOID)RcvHeader->AllocVa,
               RcvHeader->AllocPa
               );
         }

      }
   }

   while (Adapter->FreeRcvList != NULL) {

      RcvHeader = Adapter->FreeRcvList;
      Adapter->FreeRcvList = RcvHeader->Next;

      if (RcvHeader->FlushBuffer) {
          NdisFreeBuffer(RcvHeader->FlushBuffer);
      }
      if (  !Adapter->RcvBufferSpace.Va
         && RcvHeader->AllocVa)
      {
         NdisMFreeSharedMemory(
            Adapter->MiniportAdapterHandle,
            RcvHeader->AllocSize,
            TRUE,
            (PVOID)RcvHeader->AllocVa,
            RcvHeader->AllocPa
            );
      }
   }

	while (Adapter->FreePacketList != NULL)
	{
		Packet = Adapter->FreePacketList;
		Adapter->FreePacketList = RCV_RESERVED(Packet)->Next;
		
		if (NULL != Packet)
		{
			NdisFreePacket(Packet);
		}
	}

   if (Adapter->RcvBufferSpace.Va) {

       NdisMFreeSharedMemory(
           Adapter->MiniportAdapterHandle,
           Adapter->RcvBufferSpace.AllocSize,
           TRUE,
           (PVOID)Adapter->RcvBufferSpace.AllocVa,
           Adapter->RcvBufferSpace.AllocPa
           );
   }

   if (Adapter->ReceivePacketPool) {
      NdisFreePacketPool((PVOID)Adapter->ReceivePacketPool);
   }


   for (i = 0; i < DC21X4_NUMBER_OF_MAX_TRANSMIT_BUFFERS;i ++ ) {

      if (Adapter->MaxTransmitBuffer[i].AllocVa) {

         NdisMFreeSharedMemory(
            Adapter->MiniportAdapterHandle,
            Adapter->MaxTransmitBuffer[i].AllocSize,
            TRUE,
            (PVOID)Adapter->MaxTransmitBuffer[i].AllocVa,
            Adapter->MaxTransmitBuffer[i].AllocPa
            );

      }

      if (Adapter->MaxTransmitBuffer[i].FlushBuffer) {
         NdisFreeBuffer(Adapter->MaxTransmitBuffer[i].FlushBuffer);
      }
   }

   if (Adapter->MinTransmitBuffer[0].AllocVa &&
	   !Adapter->DontUseMinTransmitBuffer) {

      NdisMFreeSharedMemory(
         Adapter->MiniportAdapterHandle,
         Adapter->MinTransmitBuffer[0].AllocSize,
         TRUE,
         (PVOID)Adapter->MinTransmitBuffer[0].AllocVa,
         Adapter->MinTransmitBuffer[0].AllocPa
         );

   }

   for (i = 0; i < DC21X4_NUMBER_OF_MIN_TRANSMIT_BUFFERS;i ++ ) {

      if (Adapter->MinTransmitBuffer[i].FlushBuffer) {
         NdisFreeBuffer(Adapter->MinTransmitBuffer[i].FlushBuffer);
      }
   }


   if (Adapter->FlushBufferPoolHandle) {
      NdisFreeBufferPool(Adapter->FlushBufferPoolHandle);
   }


   if (Adapter->DescriptorRing.AllocVa) {

      NdisMFreeSharedMemory(
         Adapter->MiniportAdapterHandle,
         Adapter->DescriptorRing.AllocSize,
         FALSE,
         (PVOID)Adapter->DescriptorRing.AllocVa,
         Adapter->DescriptorRing.AllocPa
         );

   }

}
示例#11
0
文件: protocol.c 项目: RPG-7/reactos
static
NDIS_STATUS
BindAdapterByName(PNDIS_STRING DeviceName)
{
    NDIS_STATUS OpenErrorStatus;
    PNDISUIO_ADAPTER_CONTEXT AdapterContext;
    NDIS_MEDIUM SupportedMedia[1] = {NdisMedium802_3};
    UINT SelectedMedium;
    NDIS_STATUS Status;
    NDIS_REQUEST Request;

    /* Allocate the adapter context */
    AdapterContext = ExAllocatePool(NonPagedPool, sizeof(*AdapterContext));
    if (!AdapterContext)
    {
        return NDIS_STATUS_RESOURCES;
    }

    /* Set up the adapter context */
    RtlZeroMemory(AdapterContext, sizeof(*AdapterContext));
    KeInitializeEvent(&AdapterContext->AsyncEvent, SynchronizationEvent, FALSE);
    KeInitializeEvent(&AdapterContext->PacketReadEvent, SynchronizationEvent, FALSE);
    KeInitializeSpinLock(&AdapterContext->Spinlock);
    InitializeListHead(&AdapterContext->PacketList);
    InitializeListHead(&AdapterContext->OpenEntryList);
    AdapterContext->OpenCount = 0;

    AdapterContext->DeviceName.Length =
    AdapterContext->DeviceName.MaximumLength = DeviceName->Length;
    AdapterContext->DeviceName.Buffer = ExAllocatePool(NonPagedPool, DeviceName->Length);
    if (!AdapterContext->DeviceName.Buffer)
    {
        ExFreePool(AdapterContext);
        return NDIS_STATUS_RESOURCES;
    }

    /* Copy the device name into the adapter context */
    RtlCopyMemory(AdapterContext->DeviceName.Buffer, DeviceName->Buffer, DeviceName->Length);
    
    DPRINT("Binding adapter %wZ\n", &AdapterContext->DeviceName);

    /* Create the buffer pool */
    NdisAllocateBufferPool(&Status,
                           &AdapterContext->BufferPoolHandle,
                           50);
    if (Status != NDIS_STATUS_SUCCESS)
    {
        DPRINT1("Failed to allocate buffer pool with status 0x%x\n", Status);
        RtlFreeUnicodeString(&AdapterContext->DeviceName);
        ExFreePool(AdapterContext);
        return Status;
    }

    /* Create the packet pool */
    NdisAllocatePacketPool(&Status,
                           &AdapterContext->PacketPoolHandle,
                           25,
                           PROTOCOL_RESERVED_SIZE_IN_PACKET);
    if (Status != NDIS_STATUS_SUCCESS)
    {
        DPRINT1("Failed to allocate packet pool with status 0x%x\n", Status);
        NdisFreeBufferPool(AdapterContext->BufferPoolHandle);
        RtlFreeUnicodeString(&AdapterContext->DeviceName);
        ExFreePool(AdapterContext);
        return Status;
    }

    /* Send the open request */
    NdisOpenAdapter(&Status,
                    &OpenErrorStatus,
                    &AdapterContext->BindingHandle,
                    &SelectedMedium,
                    SupportedMedia,
                    1,
                    GlobalProtocolHandle,
                    AdapterContext,
                    DeviceName,
                    0,
                    NULL);
    
    /* Wait for a pending open */
    if (Status == NDIS_STATUS_PENDING)
    {
        KeWaitForSingleObject(&AdapterContext->AsyncEvent,
                              Executive,
                              KernelMode,
                              FALSE,
                              NULL);
        Status = AdapterContext->AsyncStatus;
    }
    
    /* Check the final status */
    if (Status != NDIS_STATUS_SUCCESS)
    {
        DPRINT1("Failed to open adapter for bind with status 0x%x\n", Status);
        NdisFreePacketPool(AdapterContext->PacketPoolHandle);
        NdisFreeBufferPool(AdapterContext->BufferPoolHandle);
        RtlFreeUnicodeString(&AdapterContext->DeviceName);
        ExFreePool(AdapterContext);
        return Status;
    }
    
    /* Get the MAC options */
    Request.RequestType = NdisRequestQueryInformation;
    Request.DATA.QUERY_INFORMATION.Oid = OID_GEN_MAC_OPTIONS;
    Request.DATA.QUERY_INFORMATION.InformationBuffer = &AdapterContext->MacOptions;
    Request.DATA.QUERY_INFORMATION.InformationBufferLength = sizeof(ULONG);
    NdisRequest(&Status,
                AdapterContext->BindingHandle,
                &Request);

    /* Wait for a pending request */
    if (Status == NDIS_STATUS_PENDING)
    {
        KeWaitForSingleObject(&AdapterContext->AsyncEvent,
                              Executive,
                              KernelMode,
                              FALSE,
                              NULL);
        Status = AdapterContext->AsyncStatus;
    }
    
    /* Check the final status */
    if (Status != NDIS_STATUS_SUCCESS)
    {
        NDIS_STATUS CloseStatus;

        DPRINT1("Failed to get MAC options with status 0x%x\n", Status);

        NdisCloseAdapter(&CloseStatus,
                         AdapterContext->BindingHandle);
        if (CloseStatus == NDIS_STATUS_PENDING)
        {
            KeWaitForSingleObject(&AdapterContext->AsyncEvent,
                                  Executive,
                                  KernelMode,
                                  FALSE,
                                  NULL);
        }

        NdisFreePacketPool(AdapterContext->PacketPoolHandle);
        NdisFreeBufferPool(AdapterContext->BufferPoolHandle);
        RtlFreeUnicodeString(&AdapterContext->DeviceName);
        ExFreePool(AdapterContext);
        return Status;
    }
    
    /* Add the adapter context to the global list */
    ExInterlockedInsertTailList(&GlobalAdapterList,
                                &AdapterContext->ListEntry,
                                &GlobalAdapterListLock);

    return STATUS_SUCCESS;
}
示例#12
0
NTSTATUS
DriverEntry (
	PDRIVER_OBJECT DriverObject,
	PUNICODE_STRING RegistryString
	)
/*++

Routine Description:

	Diver entry point. Initializes global variables and complete hook operation.


Arguments:

	DriverObject - A pointer to this driver, provided by system.

	RegistryString - A pointer to register path used by this driver, provided by system.


Return Value:

	Returns corresponding NTSTATUS to indicate success or failure.


Author:

	xiaonie

	2012/07/12


--*/
{
	NTSTATUS status;
	DbgPrint("NDIS Hook ------ start!\r\n");

	// check os version
	if (OS_VERSION_XP != GetOsVersion()) {
		DbgPrint("Only XP supported!\r\n");
		return STATUS_UNSUCCESSFUL;
	}

	// setup unload routine for this driver
	DriverObject->DriverUnload = OnUnload;

	// init global viaribles.
	KeInitializeSpinLock(&g_lock);
	InitializeListHead(&g_linkListHead);

	NdisAllocatePacketPool(&status,&g_PacketPool, 0x1000, PROTOCOL_RESERVED_SIZE_IN_PACKET);
	if (status != NDIS_STATUS_SUCCESS/* || g_PacketPool == NULL*/) {
		DbgPrint("alloc packet pool failed!\r\n");
		return status;
	}

	NdisAllocateBufferPool(&status, &g_BufferPool, 0x10);
	if(status != NDIS_STATUS_SUCCESS/* || g_BufferPool == NULL*/) {
		DbgPrint("alloc buffer pool failed!\r\n");
		NdisFreePacketPool(g_PacketPool);
		return status;
	}

	// hook nids routines
	status = HookNdis();

	if (!NT_SUCCESS(status)) {
		DbgPrint("HookNdis failed!\r\n");
		NdisFreeBufferPool(g_BufferPool);
		NdisFreePacketPool(g_PacketPool);
	}
	return status;
}
示例#13
0
VOID
OnUnload (
	IN PDRIVER_OBJECT DriverObject
	)
/*++

Routine Description:

	Diver exit point. Releases resources and unhooks NDIS routines.


Arguments:

	DriverObject - A pointer to this driver, provided by system.


Return Value:

	None.


Author:

	xiaonie

	2012/07/12


--*/
{
	PLIST_ENTRY pEntry;
	PNDIS_HOOK_LIST_NODE pNdisHookListNode;
	PNDIS_OPEN_BLOCK pOpenBlock;
	LARGE_INTEGER interval;

	// unhook NDIS routines
	while (TRUE) {
		pEntry = ExInterlockedRemoveHeadList(&g_linkListHead, &g_lock);
		if (pEntry == NULL)
			break;
		pNdisHookListNode = CONTAINING_RECORD(pEntry, NDIS_HOOK_LIST_NODE, ListEntry);

		pOpenBlock = pNdisHookListNode->pOpenBlock;

		InterlockedExchange((PLONG)&pOpenBlock->ReceiveHandler, (LONG)pNdisHookListNode->ulRealReceiveHandler);
		// InterlockedExchange((PLONG)&pOpenBlock->WanReceiveHandler, (LONG)pNdisHookListNode->ulRealWanReceivePacketHandler);
		InterlockedExchange((PLONG)&pOpenBlock->ReceivePacketHandler, (LONG)pNdisHookListNode->ulRealProtocolReceiveHandler);
		InterlockedExchange((PLONG)&pOpenBlock->TransferDataCompleteHandler, (LONG)pNdisHookListNode->ulRealTransferDataCompleteHandler);

		// release memory
		ExFreePoolWithTag(pNdisHookListNode, '!nmN');
	}

	// wait 5 sec, reduce the possibility of BSOD.
	KeSetPriorityThread(KeGetCurrentThread(), LOW_REALTIME_PRIORITY);
	interval.QuadPart = - 5L * 10L * 1000L * 1000L;
	KeDelayExecutionThread(KernelMode, FALSE, &interval);

	NdisFreeBufferPool(g_BufferPool);
	NdisFreePacketPool(g_PacketPool);

	DbgPrint("NDIS Hook ------ end!\r\n");
}
示例#14
0
VOID NTAPI TiUnload(
  PDRIVER_OBJECT DriverObject)
/*
 * FUNCTION: Unloads the driver
 * ARGUMENTS:
 *     DriverObject = Pointer to driver object created by the system
 */
{


#if DBG
  KIRQL OldIrql;

  TcpipAcquireSpinLock(&AddressFileListLock, &OldIrql);
  if (!IsListEmpty(&AddressFileListHead)) {
    TI_DbgPrint(MIN_TRACE, ("[TCPIP, TiUnload] Called. Open address file objects exists.\n"));
  }
  TcpipReleaseSpinLock(&AddressFileListLock, OldIrql);
#endif
  /* Cancel timer */
  KeCancelTimer(&IPTimer);

  /* Unregister loopback adapter */
  LoopUnregisterAdapter(NULL);

  /* Unregister protocol with NDIS */
  LANUnregisterProtocol();

  /* Shutdown transport level protocol subsystems */
  TCPShutdown();
  UDPShutdown();
  RawIPShutdown();
  ICMPShutdown();

  /* Shutdown network level protocol subsystem */
  IPShutdown();

  /* Free NDIS buffer descriptors */
  if (GlobalBufferPool)
    NdisFreeBufferPool(GlobalBufferPool);

  /* Free NDIS packet descriptors */
  if (GlobalPacketPool)
    NdisFreePacketPool(GlobalPacketPool);

  /* Release all device objects */

  if (TCPDeviceObject)
    IoDeleteDevice(TCPDeviceObject);

  if (UDPDeviceObject)
    IoDeleteDevice(UDPDeviceObject);

  if (RawIPDeviceObject)
    IoDeleteDevice(RawIPDeviceObject);

  if (IPDeviceObject) {
     ChewShutdown();
     IoDeleteDevice(IPDeviceObject);
  }

  if (EntityList)
    ExFreePoolWithTag(EntityList, TDI_ENTITY_TAG);

  TI_DbgPrint(MAX_TRACE, ("[TCPIP, TiUnload] Leaving.\n"));

}
示例#15
0
文件: main.c 项目: GYGit/reactos
NTSTATUS NTAPI
TiDispatch(
  PDEVICE_OBJECT DeviceObject,
  PIRP Irp)
/*
 * FUNCTION: Dispatch routine for IRP_MJ_DEVICE_CONTROL requests
 * ARGUMENTS:
 *     DeviceObject = Pointer to a device object for this driver
 *     Irp          = Pointer to a I/O request packet
 * RETURNS:
 *     Status of the operation
 */
{
  NTSTATUS Status;
  PIO_STACK_LOCATION IrpSp;

  IrpSp  = IoGetCurrentIrpStackLocation(Irp);

  TI_DbgPrint(DEBUG_IRP, ("[TCPIP, TiDispatch] Called. IRP is at (0x%X).\n", Irp));

  Irp->IoStatus.Information = 0;

#if 0
  Status = TdiMapUserRequest(DeviceObject, Irp, IrpSp);
  if (NT_SUCCESS(Status)) {
    TiDispatchInternal(DeviceObject, Irp);
    Status = STATUS_PENDING;
  } else {
#else
  if (TRUE) {
#endif
    /* See if this request is TCP/IP specific */
    switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) {
    case IOCTL_TCP_QUERY_INFORMATION_EX:
      TI_DbgPrint(MIN_TRACE, ("TCP_QUERY_INFORMATION_EX\n"));
      Status = DispTdiQueryInformationEx(Irp, IrpSp);
      break;

    case IOCTL_TCP_SET_INFORMATION_EX:
      TI_DbgPrint(MIN_TRACE, ("TCP_SET_INFORMATION_EX\n"));
      Status = DispTdiSetInformationEx(Irp, IrpSp);
      break;

    case IOCTL_SET_IP_ADDRESS:
      TI_DbgPrint(MIN_TRACE, ("SET_IP_ADDRESS\n"));
      Status = DispTdiSetIPAddress(Irp, IrpSp);
      break;

    case IOCTL_DELETE_IP_ADDRESS:
      TI_DbgPrint(MIN_TRACE, ("DELETE_IP_ADDRESS\n"));
      Status = DispTdiDeleteIPAddress(Irp, IrpSp);
      break;

    case IOCTL_QUERY_IP_HW_ADDRESS:
      TI_DbgPrint(MIN_TRACE, ("QUERY_IP_HW_ADDRESS\n"));
      Status = DispTdiQueryIpHwAddress(DeviceObject, Irp, IrpSp);
      break;

    default:
      TI_DbgPrint(MIN_TRACE, ("Unknown IOCTL 0x%X\n",
          IrpSp->Parameters.DeviceIoControl.IoControlCode));
      Status = STATUS_NOT_IMPLEMENTED;
      break;
    }
  }

  TI_DbgPrint(DEBUG_IRP, ("[TCPIP, TiDispatch] Leaving. Status = (0x%X).\n", Status));

  return IRPFinish( Irp, Status );
}


VOID NTAPI TiUnload(
  PDRIVER_OBJECT DriverObject)
/*
 * FUNCTION: Unloads the driver
 * ARGUMENTS:
 *     DriverObject = Pointer to driver object created by the system
 */
{
#if DBG
  KIRQL OldIrql;

  TcpipAcquireSpinLock(&AddressFileListLock, &OldIrql);
  if (!IsListEmpty(&AddressFileListHead)) {
    TI_DbgPrint(MIN_TRACE, ("[TCPIP, TiUnload] Called. Open address file objects exists.\n"));
  }
  TcpipReleaseSpinLock(&AddressFileListLock, OldIrql);
#endif
  /* Cancel timer */
  KeCancelTimer(&IPTimer);

  /* Unregister loopback adapter */
  LoopUnregisterAdapter(NULL);

  /* Unregister protocol with NDIS */
  LANUnregisterProtocol();

  /* Shutdown transport level protocol subsystems */
  TCPShutdown();
  UDPShutdown();
  RawIPShutdown();
  ICMPShutdown();

  /* Shutdown network level protocol subsystem */
  IPShutdown();

  /* Free NDIS buffer descriptors */
  if (GlobalBufferPool)
    NdisFreeBufferPool(GlobalBufferPool);

  /* Free NDIS packet descriptors */
  if (GlobalPacketPool)
    NdisFreePacketPool(GlobalPacketPool);

  /* Release all device objects */

  if (TCPDeviceObject)
    IoDeleteDevice(TCPDeviceObject);

  if (UDPDeviceObject)
    IoDeleteDevice(UDPDeviceObject);

  if (RawIPDeviceObject)
    IoDeleteDevice(RawIPDeviceObject);

  if (IPDeviceObject) {
     ChewShutdown();
     IoDeleteDevice(IPDeviceObject);
  }

  if (EntityList)
    ExFreePoolWithTag(EntityList, TDI_ENTITY_TAG);

  TI_DbgPrint(MAX_TRACE, ("[TCPIP, TiUnload] Leaving.\n"));
}