예제 #1
0
_Must_inspect_result_
PAGEABLE_FUNCTION
NDIS_STATUS AX25Adapter::SetMiniportAttributes()
{
    ASSERT(driverHandle != nullptr);
    // Validate the driver handle
    if (driverHandle == nullptr)
    {
        // Don't try to call NDIS with a bad pointer - fail out
        TraceEvents(TRACE_LEVEL_CRITICAL, TRACE_ADAPTER, "Cannot set miniport attributes: driver handle is nullptr");
        return STATUS_INVALID_ADDRESS;
    }

    // Call to NDIS - the attributes should already have been set as part of the state of this object
    NDIS_STATUS status = NdisMSetMiniportAttributes(driverHandle, registrationAttributes);
    if (NDIS_STATUS_SUCCESS != status)
    {
        // Something went wrong - report it and give up
        TraceEvents(TRACE_LEVEL_ERROR, TRACE_ADAPTER, "Failed to set miniport adapter registration attributes: %!STATUS!", status);
        return status;
    }
    status = NdisMSetMiniportAttributes(driverHandle, generalAttributes);
    if (NDIS_STATUS_SUCCESS != status)
    {
        // Report the error
        TraceEvents(TRACE_LEVEL_ERROR, TRACE_ADAPTER, "Failed to set miniport adapter general attributes: %!STATUS!", status);
        return status;
    }


    return status;
}
예제 #2
0
파일: mp_pnp_6x.c 프로젝트: PaulJing/Sora
NDIS_STATUS
MpSetRegistrationAttributes(
    __in  PHWT_ADAPTER                Adapter
    )
{
    NDIS_STATUS ndisStatus = NDIS_STATUS_SUCCESS;
    NDIS_MINIPORT_ADAPTER_ATTRIBUTES    miniportAttributes;

    //
    // First we we set the registration attributes
    //
    NdisZeroMemory(&miniportAttributes, sizeof(miniportAttributes));
    miniportAttributes.RegistrationAttributes.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES;
    miniportAttributes.RegistrationAttributes.Header.Revision = NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES_REVISION_1;
    miniportAttributes.RegistrationAttributes.Header.Size = sizeof(NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES);
    
    miniportAttributes.RegistrationAttributes.MiniportAdapterContext = Adapter;

    miniportAttributes.RegistrationAttributes.AttributeFlags = NDIS_MINIPORT_ATTRIBUTES_BUS_MASTER |
    														   NDIS_MINIPORT_ATTRIBUTES_NO_HALT_ON_SUSPEND |
    														   NDIS_MINIPORT_ATTRIBUTES_NDIS_WDM;
    miniportAttributes.RegistrationAttributes.CheckForHangTimeInSeconds = 6;
    miniportAttributes.RegistrationAttributes.InterfaceType = 0;

    ndisStatus = NdisMSetMiniportAttributes(
                    Adapter->AdapterHandle, 
                    &miniportAttributes);
    if (ndisStatus != NDIS_STATUS_SUCCESS)
    {
        DbgPrint("Failed to set miniport registration attributes. Status = 0x%08x\n", ndisStatus);
    }

    return ndisStatus;
}
static NDIS_STATUS  ParaNdis6_AddDevice(IN NDIS_HANDLE  MiniportAdapterHandle, IN NDIS_HANDLE  MiniportDriverContext)
{
    NDIS_MINIPORT_ADAPTER_ATTRIBUTES  MiniportAttributes;
    NDIS_STATUS status;

    UNREFERENCED_PARAMETER(MiniportDriverContext);

    DEBUG_ENTRY(0);
    MiniportAttributes.AddDeviceRegistrationAttributes.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADD_DEVICE_REGISTRATION_ATTRIBUTES;
    MiniportAttributes.AddDeviceRegistrationAttributes.Header.Revision = NDIS_MINIPORT_ADD_DEVICE_REGISTRATION_ATTRIBUTES_REVISION_1;
    MiniportAttributes.AddDeviceRegistrationAttributes.Header.Size = NDIS_SIZEOF_MINIPORT_ADD_DEVICE_REGISTRATION_ATTRIBUTES_REVISION_1;
    MiniportAttributes.AddDeviceRegistrationAttributes.MiniportAddDeviceContext = MiniportAdapterHandle;
    MiniportAttributes.AddDeviceRegistrationAttributes.Flags = 0;
    status = NdisMSetMiniportAttributes(MiniportAdapterHandle, &MiniportAttributes);
    return status;
}
예제 #4
0
NDIS_STATUS
VenetSetRegistrationAttributes(NDIS_HANDLE handle, PADAPTER a)
{
    NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES	attr;

    NdisZeroMemory(&attr, sizeof(attr));
    attr.Header.Type =
        NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES;
    attr.Header.Revision =
        NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES_REVISION_1;
    attr.Header.Size =
        sizeof(NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES);

    attr.MiniportAdapterContext = a;
    attr.AttributeFlags = NDIS_MINIPORT_ATTRIBUTES_NO_HALT_ON_SUSPEND |
                          NDIS_MINIPORT_ATTRIBUTES_NOT_CO_NDIS |
                          NDIS_MINIPORT_ATTRIBUTES_BUS_MASTER;
    attr.CheckForHangTimeInSeconds = 128;
    attr.InterfaceType = NdisInterfaceInternal;

    return (NdisMSetMiniportAttributes(handle,
                                       (PNDIS_MINIPORT_ADAPTER_ATTRIBUTES) &attr));
}
/**********************************************************
Required NDIS handler
Initialize adapter context, prepare it for operation,
set in PAUSED STATE
Return value:
    SUCCESS or kind of error
***********************************************************/
static NDIS_STATUS ParaNdis6_Initialize(
    NDIS_HANDLE miniportAdapterHandle,
    NDIS_HANDLE miniportDriverContext,
    PNDIS_MINIPORT_INIT_PARAMETERS miniportInitParameters)
{
    NDIS_MINIPORT_ADAPTER_ATTRIBUTES        miniportAttributes;
    NDIS_STATUS  status = NDIS_STATUS_SUCCESS;
    BOOLEAN bNoPauseOnSuspend = FALSE;
    PARANDIS_ADAPTER *pContext;

    UNREFERENCED_PARAMETER(miniportDriverContext);
    DEBUG_ENTRY(0);
#pragma warning( suppress: 28197)
    /* allocate context structure */
    pContext = (PARANDIS_ADAPTER *)
        NdisAllocateMemoryWithTagPriority(
            miniportAdapterHandle,
            sizeof(PARANDIS_ADAPTER),
            PARANDIS_MEMORY_TAG,
            NormalPoolPriority);

    /* This call is for Static Driver Verifier only - has no real functionality*/
    __sdv_save_adapter_context(pContext);

    if (!pContext)
    {
        DPrintf(0, ("[%s] ERROR: Memory allocation failed!\n", __FUNCTION__));
        status = NDIS_STATUS_RESOURCES;
    }

    if (status == NDIS_STATUS_SUCCESS)
    {
        /* set mandatory fields which Common use */
        NdisZeroMemory(pContext, sizeof(PARANDIS_ADAPTER));
        pContext->ulUniqueID = NdisInterlockedIncrement(&gID);
        pContext->DriverHandle = DriverHandle;
        pContext->MiniportHandle = miniportAdapterHandle;
    }

    if (status == NDIS_STATUS_SUCCESS)
    {
        NdisZeroMemory(&miniportAttributes, sizeof(miniportAttributes));
        miniportAttributes.RegistrationAttributes.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES;
        miniportAttributes.RegistrationAttributes.Header.Revision = NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES_REVISION_1;
        miniportAttributes.RegistrationAttributes.Header.Size = NDIS_SIZEOF_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES_REVISION_1;
        miniportAttributes.RegistrationAttributes.MiniportAdapterContext = pContext;
        miniportAttributes.RegistrationAttributes.AttributeFlags =
            // actual for USB
            // NDIS_MINIPORT_ATTRIBUTES_SURPRISE_REMOVE_OK
            NDIS_MINIPORT_ATTRIBUTES_HARDWARE_DEVICE |
            NDIS_MINIPORT_ATTRIBUTES_BUS_MASTER;
#ifndef NO_VISTA_POWER_MANAGEMENT
        miniportAttributes.RegistrationAttributes.AttributeFlags |= NDIS_MINIPORT_ATTRIBUTES_NO_HALT_ON_SUSPEND;
#endif
#if NDIS_SUPPORT_NDIS630
        miniportAttributes.RegistrationAttributes.AttributeFlags |= NDIS_MINIPORT_ATTRIBUTES_NO_PAUSE_ON_SUSPEND;
        bNoPauseOnSuspend = TRUE;
#endif
        miniportAttributes.RegistrationAttributes.CheckForHangTimeInSeconds = 4;
        miniportAttributes.RegistrationAttributes.InterfaceType = NdisInterfacePci;
        status = NdisMSetMiniportAttributes(miniportAdapterHandle, &miniportAttributes);
        if (status != NDIS_STATUS_SUCCESS)
        {
            DPrintf(0, ("[%s] ERROR: NdisMSetMiniportAttributes 1 failed (%X)!\n", __FUNCTION__, status));
        }
    }

    if (status == NDIS_STATUS_SUCCESS)
    {
        /* prepare statistics struct for further reports */
        pContext->Statistics.Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
        pContext->Statistics.Header.Revision = NDIS_STATISTICS_INFO_REVISION_1;
        pContext->Statistics.Header.Size = NDIS_SIZEOF_STATISTICS_INFO_REVISION_1;
        /* let Common do all the rest */
        status = ParaNdis_InitializeContext(pContext, miniportInitParameters->AllocatedResources);
        if (status != NDIS_STATUS_SUCCESS)
        {
            DPrintf(0, ("[%s] ERROR: ParaNdis6_InitializeContext failed (%X)!\n", __FUNCTION__, status));
        }
        pContext->bNoPauseOnSuspend = bNoPauseOnSuspend; 
    }

    if (status == NDIS_STATUS_SUCCESS)
    {
        ULONG i;
        NDIS_PNP_CAPABILITIES power60Caps;
#if NDIS_SUPPORT_NDIS620
        NDIS_PM_CAPABILITIES power620Caps;
#endif
#ifdef NO_VISTA_POWER_MANAGEMENT
        pPowerCaps = NULL;
#endif
        ParaNdis_FillPowerCapabilities(&power60Caps);

        NdisZeroMemory(&miniportAttributes, sizeof(miniportAttributes));
        miniportAttributes.GeneralAttributes.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES;
        miniportAttributes.GeneralAttributes.Header.Revision = NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_1;
        miniportAttributes.GeneralAttributes.Header.Size = NDIS_SIZEOF_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_1;
#if NDIS_SUPPORT_NDIS620
        miniportAttributes.GeneralAttributes.Header.Revision = NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_2;
        miniportAttributes.GeneralAttributes.Header.Size = NDIS_SIZEOF_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_2;
        miniportAttributes.GeneralAttributes.PowerManagementCapabilitiesEx = &power620Caps;
        ParaNdis6_Fill620PowerCapabilities(&power620Caps);
#else
        miniportAttributes.GeneralAttributes.PowerManagementCapabilities = &power60Caps;
#endif
        miniportAttributes.GeneralAttributes.MediaType = NdisMedium802_3;
        miniportAttributes.GeneralAttributes.PhysicalMediumType = NdisPhysicalMedium802_3;
        miniportAttributes.GeneralAttributes.MtuSize = pContext->MaxPacketSize.nMaxDataSize;
        miniportAttributes.GeneralAttributes.LookaheadSize = pContext->MaxPacketSize.nMaxFullSizeOS;
        miniportAttributes.GeneralAttributes.MaxXmitLinkSpeed =
        miniportAttributes.GeneralAttributes.MaxRcvLinkSpeed  =  PARANDIS_FORMAL_LINK_SPEED;
        miniportAttributes.GeneralAttributes.MediaConnectState =
            pContext->bConnected ? MediaConnectStateConnected : MediaConnectStateDisconnected;
        miniportAttributes.GeneralAttributes.XmitLinkSpeed =
        miniportAttributes.GeneralAttributes.RcvLinkSpeed = pContext->bConnected ?
            PARANDIS_FORMAL_LINK_SPEED : NDIS_LINK_SPEED_UNKNOWN;
        miniportAttributes.GeneralAttributes.MediaDuplexState = MediaDuplexStateFull;
        miniportAttributes.GeneralAttributes.MacOptions =
                    NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA |       /* NIC has no internal loopback support */
                    NDIS_MAC_OPTION_TRANSFERS_NOT_PEND  |       /* Must be set since using  NdisMIndicateReceivePacket */
                    NDIS_MAC_OPTION_NO_LOOPBACK;                /* NIC has no internal loopback support */
        if (IsPrioritySupported(pContext))
            miniportAttributes.GeneralAttributes.MacOptions |= NDIS_MAC_OPTION_8021P_PRIORITY;
        if (IsVlanSupported(pContext))
            miniportAttributes.GeneralAttributes.MacOptions |= NDIS_MAC_OPTION_8021Q_VLAN;
        miniportAttributes.GeneralAttributes.SupportedPacketFilters = PARANDIS_PACKET_FILTERS;
        miniportAttributes.GeneralAttributes.MaxMulticastListSize = PARANDIS_MULTICAST_LIST_SIZE;
        miniportAttributes.GeneralAttributes.MacAddressLength =     ETH_LENGTH_OF_ADDRESS;

#if PARANDIS_SUPPORT_RSS
        if(pContext->bRSSOffloadSupported)
        {
            miniportAttributes.GeneralAttributes.RecvScaleCapabilities =
                ParaNdis6_RSSCreateConfiguration(
                                                &pContext->RSSParameters,
                                                &pContext->RSSCapabilities,
                                                pContext->RSSMaxQueuesNumber);
            pContext->bRSSInitialized = TRUE;
        }
#endif

        for(i = 0; i < ARRAYSIZE(pContext->ReceiveQueues); i++)
        {
            NdisAllocateSpinLock(&pContext->ReceiveQueues[i].Lock);
            InitializeListHead(&pContext->ReceiveQueues[i].BuffersList);

            pContext->ReceiveQueues[i].BatchReceiveArray =
                ParaNdis_AllocateMemory(pContext, sizeof(*pContext->ReceiveQueues[i].BatchReceiveArray)*pContext->NetMaxReceiveBuffers);
            if(!pContext->ReceiveQueues[i].BatchReceiveArray)
            {
                pContext->ReceiveQueues[i].BatchReceiveArray = &pContext->ReceiveQueues[i].BatchReceiveEmergencyItem;
                pContext->ReceiveQueues[i].BatchReceiveArraySize = 1;
            }
            else
            {
                pContext->ReceiveQueues[i].BatchReceiveArraySize = pContext->NetMaxReceiveBuffers;
            }
        }

        pContext->ReceiveQueuesInitialized = TRUE;

        miniportAttributes.GeneralAttributes.AccessType = NET_IF_ACCESS_BROADCAST;
        miniportAttributes.GeneralAttributes.DirectionType = NET_IF_DIRECTION_SENDRECEIVE;
        miniportAttributes.GeneralAttributes.IfType = IF_TYPE_ETHERNET_CSMACD;
        miniportAttributes.GeneralAttributes.IfConnectorPresent = TRUE;
        miniportAttributes.GeneralAttributes.ConnectionType = NET_IF_CONNECTION_DEDICATED;

        ETH_COPY_NETWORK_ADDRESS(miniportAttributes.GeneralAttributes.PermanentMacAddress, pContext->PermanentMacAddress);
        ETH_COPY_NETWORK_ADDRESS(miniportAttributes.GeneralAttributes.CurrentMacAddress, pContext->CurrentMacAddress);

        ParaNdis6_GetSupportedOid(&miniportAttributes.GeneralAttributes);
        /* update also SupportedStatistics in ready to use statistics block */
        pContext->Statistics.SupportedStatistics = ParaNdis6_GetSupportedStatisticsFlags();
        status = NdisMSetMiniportAttributes(miniportAdapterHandle, &miniportAttributes);
        if (status != NDIS_STATUS_SUCCESS)
        {
            DPrintf(0, ("[%s] ERROR: NdisMSetMiniportAttributes 2 failed (%X)!\n", __FUNCTION__, status));
        }
    }

    if (pContext && status != NDIS_STATUS_SUCCESS && status != NDIS_STATUS_PENDING)
    {
        // no need to cleanup
        NdisFreeMemory(pContext, 0, 0);
        pContext = NULL;
    }

    if (pContext && status == NDIS_STATUS_SUCCESS)
    {
        status = ParaNdis_FinishInitialization(pContext);
        if (status != NDIS_STATUS_SUCCESS)
        {
            ParaNdis_CleanupContext(pContext);
            NdisFreeMemory(pContext, 0, 0);
            pContext = NULL;
        }
    }
    if (pContext && status == NDIS_STATUS_SUCCESS)
    {
        if (NDIS_STATUS_SUCCESS ==
            ParaNdis6_GetRegistrationOffloadInfo(pContext,
                &miniportAttributes.OffloadAttributes))
            status = NdisMSetMiniportAttributes(miniportAdapterHandle, &miniportAttributes);
            if (status != NDIS_STATUS_SUCCESS)
            {
                DPrintf(0, ("[%s] ERROR: NdisMSetMiniportAttributes 3 failed (%X)!\n", __FUNCTION__, status));
            }
    }

    if (pContext && status == NDIS_STATUS_SUCCESS)
    {
        ParaNdis_DebugRegisterMiniport(pContext, TRUE);
    }

    DEBUG_EXIT_STATUS(status ? 0 : 2, status);
    return status;
}
예제 #6
0
// Initialization handler of adapter
NDIS_STATUS NeoNdisInitEx(NDIS_HANDLE MiniportAdapterHandle,
						  NDIS_HANDLE MiniportDriverContext,
						  PNDIS_MINIPORT_INIT_PARAMETERS MiniportInitParameters)
{
	NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES attr;
	NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES gen;
	NDIS_PM_CAPABILITIES pnpcap;

	if (ctx == NULL)
	{
		return NDIS_STATUS_FAILURE;
	}

	if (ctx->NdisMiniportDriverHandle == NULL)
	{
		ctx->NdisMiniportDriverHandle = ndis_miniport_driver_handle;
	}

	// Prevention of multiple start
	if (ctx->Initing != FALSE)
	{
		// Multiple started
		return NDIS_STATUS_FAILURE;
	}
	ctx->Initing = TRUE;

	// Examine whether it has already been initialized
	if (ctx->Inited != FALSE)
	{
		// Driver is started on another instance already.
		// VPN driver can start only one instance per one service.
		// User can start multiple drivers with different instance ID
		return NDIS_STATUS_FAILURE;
	}

	// Current value of the packet filter
	ctx->CurrentPacketFilter = NDIS_PACKET_TYPE_ALL_LOCAL | NDIS_PACKET_TYPE_BROADCAST | NDIS_PACKET_TYPE_DIRECTED | NDIS_PACKET_TYPE_ALL_FUNCTIONAL;

	// Initialize the adapter information
	ctx->NdisMiniport = MiniportAdapterHandle;
	ctx->NdisContext = ctx;
	ctx->HardwareStatus = NdisHardwareStatusReady;
	ctx->Halting = FALSE;
	ctx->Connected = ctx->ConnectedOld = FALSE;

	//if (keep_link == false)
	{
		ctx->ConnectedForce = TRUE;
	}

	// Read the information from the registry
	if (NeoLoadRegistory() == FALSE)
	{
		// Failure
		ctx->Initing = FALSE;
		return NDIS_STATUS_FAILURE;
	}

	// Register the device attributes
	NeoZero(&attr, sizeof(attr));
	attr.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES;
	attr.Header.Revision = NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES_REVISION_1;
	attr.Header.Size = sizeof(NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES);
	attr.AttributeFlags = NDIS_MINIPORT_ATTRIBUTES_NO_HALT_ON_SUSPEND;
	attr.InterfaceType = NdisInterfaceInternal;
	attr.MiniportAdapterContext = ctx->NdisContext;

	NdisMSetMiniportAttributes(ctx->NdisMiniport, (PNDIS_MINIPORT_ADAPTER_ATTRIBUTES)&attr);

	NeoZero(&pnpcap, sizeof(pnpcap));

	NeoZero(&gen, sizeof(gen));
	gen.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES;
	gen.Header.Revision = NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_2;
	gen.Header.Size = NDIS_SIZEOF_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_2;
	gen.MediaType = NdisMedium802_3;
	gen.PhysicalMediumType = NdisPhysicalMedium802_3;
	gen.MtuSize = NEO_MAX_PACKET_SIZE_ANNOUNCE - NEO_MIN_PACKET_SIZE;
	gen.MaxXmitLinkSpeed = gen.MaxRcvLinkSpeed = max_speed;
	gen.RcvLinkSpeed = gen.XmitLinkSpeed = max_speed;
	gen.MediaConnectState = MediaConnectStateDisconnected;
	gen.LookaheadSize = NEO_MAX_PACKET_SIZE_ANNOUNCE - NEO_MIN_PACKET_SIZE;
	gen.MacOptions = NDIS_MAC_OPTION_TRANSFERS_NOT_PEND | NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA | NDIS_MAC_OPTION_NO_LOOPBACK;
	gen.SupportedPacketFilters = NDIS_PACKET_TYPE_ALL_LOCAL | NDIS_PACKET_TYPE_BROADCAST | NDIS_PACKET_TYPE_DIRECTED | NDIS_PACKET_TYPE_ALL_FUNCTIONAL;
	gen.MaxMulticastListSize = NEO_MAX_MULTICASE;
	gen.MacAddressLength = NEO_MAC_ADDRESS_SIZE;
	NeoCopy(gen.PermanentMacAddress, ctx->MacAddress, NEO_MAC_ADDRESS_SIZE);
	NeoCopy(gen.CurrentMacAddress, ctx->MacAddress, NEO_MAC_ADDRESS_SIZE);
	gen.AccessType = NET_IF_ACCESS_BROADCAST;
	gen.DirectionType = NET_IF_DIRECTION_SENDRECEIVE;
	gen.ConnectionType = NET_IF_CONNECTION_DEDICATED;
	gen.IfType = IF_TYPE_ETHERNET_CSMACD;
	gen.IfConnectorPresent = TRUE;
	gen.SupportedStatistics =
		NDIS_STATISTICS_FLAGS_VALID_DIRECTED_FRAMES_RCV |
		NDIS_STATISTICS_FLAGS_VALID_MULTICAST_FRAMES_RCV |
		NDIS_STATISTICS_FLAGS_VALID_BROADCAST_FRAMES_RCV |
		NDIS_STATISTICS_FLAGS_VALID_BYTES_RCV |
		NDIS_STATISTICS_FLAGS_VALID_RCV_DISCARDS |
		NDIS_STATISTICS_FLAGS_VALID_RCV_ERROR |
		NDIS_STATISTICS_FLAGS_VALID_DIRECTED_FRAMES_XMIT |
		NDIS_STATISTICS_FLAGS_VALID_MULTICAST_FRAMES_XMIT |
		NDIS_STATISTICS_FLAGS_VALID_BROADCAST_FRAMES_XMIT |
		NDIS_STATISTICS_FLAGS_VALID_BYTES_XMIT |
		NDIS_STATISTICS_FLAGS_VALID_XMIT_ERROR |
		NDIS_STATISTICS_FLAGS_VALID_XMIT_DISCARDS |
		NDIS_STATISTICS_FLAGS_VALID_DIRECTED_BYTES_RCV |
		NDIS_STATISTICS_FLAGS_VALID_MULTICAST_BYTES_RCV |
		NDIS_STATISTICS_FLAGS_VALID_BROADCAST_BYTES_RCV |
		NDIS_STATISTICS_FLAGS_VALID_DIRECTED_BYTES_XMIT |
		NDIS_STATISTICS_FLAGS_VALID_MULTICAST_BYTES_XMIT |
		NDIS_STATISTICS_FLAGS_VALID_BROADCAST_BYTES_XMIT;
	gen.SupportedPauseFunctions = NdisPauseFunctionsUnsupported;
	gen.AutoNegotiationFlags = NDIS_LINK_STATE_XMIT_LINK_SPEED_AUTO_NEGOTIATED |
		NDIS_LINK_STATE_RCV_LINK_SPEED_AUTO_NEGOTIATED |
		NDIS_LINK_STATE_DUPLEX_AUTO_NEGOTIATED |
		NDIS_LINK_STATE_PAUSE_FUNCTIONS_AUTO_NEGOTIATED;
	gen.SupportedOidList = SupportedOids;
	gen.SupportedOidListLength = sizeof(SupportedOids);

	NeoZero(&pnpcap, sizeof(pnpcap));
	pnpcap.Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
	pnpcap.Header.Revision = NDIS_PM_CAPABILITIES_REVISION_1;
	pnpcap.Header.Size = NDIS_SIZEOF_NDIS_PM_CAPABILITIES_REVISION_1;
	pnpcap.MinMagicPacketWakeUp = NdisDeviceStateUnspecified;
	pnpcap.MinPatternWakeUp  = NdisDeviceStateUnspecified;
	pnpcap.MinLinkChangeWakeUp = NdisDeviceStateUnspecified;
	gen.PowerManagementCapabilitiesEx = &pnpcap;

	NdisMSetMiniportAttributes(ctx->NdisMiniport, (PNDIS_MINIPORT_ADAPTER_ATTRIBUTES)&gen);

	// Initialize the received packet array
	NeoInitPacketArray();

	// Initialize the control device
	NeoInitControlDevice();

	// Start the adapter
	NeoStartAdapter();

	// Flag setting
	ctx->Initing = FALSE;
	ctx->Inited = TRUE;

	// Notify the connection state
	NeoSetConnectState(FALSE);

	return NDIS_STATUS_SUCCESS;
}
예제 #7
0
NDIS_STATUS
AdapterCreate(__in NDIS_HANDLE MiniportAdapterHandle, __in NDIS_HANDLE MiniportDriverContext,
              __in PNDIS_MINIPORT_INIT_PARAMETERS MiniportInitParameters) {
  PTAP_ADAPTER_CONTEXT adapter = NULL;
  NDIS_STATUS status;

  UNREFERENCED_PARAMETER(MiniportDriverContext);
  UNREFERENCED_PARAMETER(MiniportInitParameters);

  DEBUGP(("[TAP] --> AdapterCreate\n"));

  do {
    NDIS_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES regAttributes = {0};
    NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES genAttributes = {0};
    NDIS_PNP_CAPABILITIES pnpCapabilities = {0};

    //
    // Allocate adapter context structure and initialize all the
    // memory resources for sending and receiving packets.
    //
    // Returns with reference count initialized to one.
    //
    adapter = tapAdapterContextAllocate(MiniportAdapterHandle);

    if (adapter == NULL) {
      DEBUGP(("[TAP] Couldn't allocate adapter memory\n"));
      status = NDIS_STATUS_RESOURCES;
      break;
    }

    // Enter the Initializing state.
    DEBUGP(("[TAP] Miniport State: Initializing\n"));

    tapAdapterAcquireLock(adapter, FALSE);
    adapter->Locked.AdapterState = MiniportInitializingState;
    tapAdapterReleaseLock(adapter, FALSE);

    //
    // First read adapter configuration from registry.
    // -----------------------------------------------
    // Subsequent device registration will fail if NetCfgInstanceId
    // has not been successfully read.
    //
    status = tapReadConfiguration(adapter);

    //
    // Set the registration attributes.
    //
    {
      C_ASSERT(sizeof(regAttributes) >=
               NDIS_SIZEOF_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES_REVISION_1);
    }
    regAttributes.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES;
    regAttributes.Header.Size = NDIS_SIZEOF_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES_REVISION_1;
    regAttributes.Header.Revision = NDIS_SIZEOF_MINIPORT_ADAPTER_REGISTRATION_ATTRIBUTES_REVISION_1;

    regAttributes.MiniportAdapterContext = adapter;
    regAttributes.AttributeFlags = TAP_ADAPTER_ATTRIBUTES_FLAGS;

    regAttributes.CheckForHangTimeInSeconds = TAP_ADAPTER_CHECK_FOR_HANG_TIME_IN_SECONDS;
    regAttributes.InterfaceType = TAP_INTERFACE_TYPE;

    // NDIS_DECLARE_MINIPORT_ADAPTER_CONTEXT(TAP_ADAPTER_CONTEXT);
    status = NdisMSetMiniportAttributes(MiniportAdapterHandle,
                                        (PNDIS_MINIPORT_ADAPTER_ATTRIBUTES)&regAttributes);

    if (status != NDIS_STATUS_SUCCESS) {
      DEBUGP(("[TAP] NdisSetOptionalHandlers failed; Status 0x%08x\n", status));
      break;
    }

    //
    // Next, set the general attributes.
    //
    {
      C_ASSERT(sizeof(genAttributes) >= NDIS_SIZEOF_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_1);
    }
    genAttributes.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES;
    genAttributes.Header.Size = NDIS_SIZEOF_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_1;
    genAttributes.Header.Revision = NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_1;

    //
    // Specify the medium type that the NIC can support but not
    // necessarily the medium type that the NIC currently uses.
    //
    genAttributes.MediaType = TAP_MEDIUM_TYPE;

    //
    // Specifiy medium type that the NIC currently uses.
    //
    genAttributes.PhysicalMediumType = TAP_PHYSICAL_MEDIUM;

    //
    // Specifiy the maximum network frame size, in bytes, that the NIC
    // supports excluding the header.
    //
    genAttributes.MtuSize = TAP_FRAME_MAX_DATA_SIZE;
    genAttributes.MaxXmitLinkSpeed = TAP_XMIT_SPEED;
    genAttributes.XmitLinkSpeed = TAP_XMIT_SPEED;
    genAttributes.MaxRcvLinkSpeed = TAP_RECV_SPEED;
    genAttributes.RcvLinkSpeed = TAP_RECV_SPEED;

    if (adapter->MediaStateAlwaysConnected) {
      DEBUGP(("[%s] Initial MediaConnectState: Connected\n", MINIPORT_INSTANCE_ID(adapter)));

      genAttributes.MediaConnectState = MediaConnectStateConnected;
    } else {
      DEBUGP(("[%s] Initial MediaConnectState: Disconnected\n", MINIPORT_INSTANCE_ID(adapter)));

      genAttributes.MediaConnectState = MediaConnectStateDisconnected;
    }

    genAttributes.MediaDuplexState = MediaDuplexStateFull;

    //
    // The maximum number of bytes the NIC can provide as lookahead data.
    // If that value is different from the size of the lookahead buffer
    // supported by bound protocols, NDIS will call MiniportOidRequest to
    // set the size of the lookahead buffer provided by the miniport driver
    // to the minimum of the miniport driver and protocol(s) values. If the
    // driver always indicates up full packets with
    // NdisMIndicateReceiveNetBufferLists, it should set this value to the
    // maximum total frame size, which excludes the header.
    //
    // Upper-layer drivers examine lookahead data to determine whether a
    // packet that is associated with the lookahead data is intended for
    // one or more of their clients. If the underlying driver supports
    // multipacket receive indications, bound protocols are given full net
    // packets on every indication. Consequently, this value is identical
    // to that returned for OID_GEN_RECEIVE_BLOCK_SIZE.
    //
    genAttributes.LookaheadSize = TAP_MAX_LOOKAHEAD;
    genAttributes.MacOptions = TAP_MAC_OPTIONS;
    genAttributes.SupportedPacketFilters = TAP_SUPPORTED_FILTERS;

    //
    // The maximum number of multicast addresses the NIC driver can manage.
    // This list is global for all protocols bound to (or above) the NIC.
    // Consequently, a protocol can receive NDIS_STATUS_MULTICAST_FULL from
    // the NIC driver when attempting to set the multicast address list,
    // even if the number of elements in the given list is less than the
    // number originally returned for this query.
    //
    genAttributes.MaxMulticastListSize = TAP_MAX_MCAST_LIST;
    genAttributes.MacAddressLength = MACADDR_SIZE;

    //
    // Return the MAC address of the NIC burnt in the hardware.
    //
    ETH_COPY_NETWORK_ADDRESS(genAttributes.PermanentMacAddress, adapter->PermanentAddress);

    //
    // Return the MAC address the NIC is currently programmed to use. Note
    // that this address could be different from the permananent address as
    // the user can override using registry. Read NdisReadNetworkAddress
    // doc for more info.
    //
    ETH_COPY_NETWORK_ADDRESS(genAttributes.CurrentMacAddress, adapter->CurrentAddress);

    genAttributes.RecvScaleCapabilities = NULL;
    genAttributes.AccessType = TAP_ACCESS_TYPE;
    genAttributes.DirectionType = TAP_DIRECTION_TYPE;
    genAttributes.ConnectionType = TAP_CONNECTION_TYPE;
    genAttributes.IfType = TAP_IFTYPE;
    genAttributes.IfConnectorPresent = TAP_HAS_PHYSICAL_CONNECTOR;
    genAttributes.SupportedStatistics = TAP_SUPPORTED_STATISTICS;
    genAttributes.SupportedPauseFunctions =
        NdisPauseFunctionsUnsupported;  // IEEE 802.3 pause frames
    genAttributes.DataBackFillSize = 0;
    genAttributes.ContextBackFillSize = 0;

    //
    // The SupportedOidList is an array of OIDs for objects that the
    // underlying driver or its NIC supports.  Objects include general,
    // media-specific, and implementation-specific objects. NDIS forwards a
    // subset of the returned list to protocols that make this query. That
    // is, NDIS filters any supported statistics OIDs out of the list
    // because protocols never make statistics queries.
    //
    genAttributes.SupportedOidList = TAPSupportedOids;
    genAttributes.SupportedOidListLength = sizeof(TAPSupportedOids);
    genAttributes.AutoNegotiationFlags = NDIS_LINK_STATE_DUPLEX_AUTO_NEGOTIATED;

    //
    // Set power management capabilities
    //
    NdisZeroMemory(&pnpCapabilities, sizeof(pnpCapabilities));
    pnpCapabilities.WakeUpCapabilities.MinMagicPacketWakeUp = NdisDeviceStateUnspecified;
    pnpCapabilities.WakeUpCapabilities.MinPatternWakeUp = NdisDeviceStateUnspecified;
    genAttributes.PowerManagementCapabilities = &pnpCapabilities;

    status = NdisMSetMiniportAttributes(MiniportAdapterHandle,
                                        (PNDIS_MINIPORT_ADAPTER_ATTRIBUTES)&genAttributes);

    if (status != NDIS_STATUS_SUCCESS) {
      DEBUGP(("[TAP] NdisMSetMiniportAttributes failed; Status 0x%08x\n", status));
      break;
    }

    //
    // Create the Win32 device I/O interface.
    //
    status = CreateTapDevice(adapter);

    if (status == NDIS_STATUS_SUCCESS) {
      // Add this adapter to the global adapter list.
      tapAdapterContextAddToGlobalList(adapter);
    } else {
      DEBUGP(("[TAP] CreateTapDevice failed; Status 0x%08x\n", status));
      break;
    }
  } while (FALSE);

  if (status == NDIS_STATUS_SUCCESS) {
    // Enter the Paused state if initialization is complete.
    DEBUGP(("[TAP] Miniport State: Paused\n"));

    tapAdapterAcquireLock(adapter, FALSE);
    adapter->Locked.AdapterState = MiniportPausedState;
    tapAdapterReleaseLock(adapter, FALSE);
  } else {
    if (adapter != NULL) {
      DEBUGP(("[TAP] Miniport State: Halted\n"));

      //
      // Remove reference when adapter context was allocated
      // ---------------------------------------------------
      // This should result in freeing adapter context memory
      // and assiciated resources.
      //
      tapAdapterContextDereference(adapter);
      adapter = NULL;
    }
  }

  DEBUGP(("[TAP] <-- AdapterCreate; status = %8.8X\n", status));

  return status;
}
예제 #8
0
static NDIS_STATUS
VenetSetGeneralAttributes(NDIS_HANDLE handle, PADAPTER a)
{
    NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES attr;

    NdisZeroMemory(&attr, sizeof(NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES));
    attr.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES;
    attr.Header.Revision =
        NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_1;
    attr.Header.Size = sizeof(NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES);

    attr.MediaType = NdisMedium802_3;
    attr.MtuSize = ETH_MAX_DATA_SIZE;
    attr.MaxXmitLinkSpeed = NIC_MEDIA_MAX_SPEED;
    attr.MaxRcvLinkSpeed = NIC_MEDIA_MAX_SPEED;
    attr.XmitLinkSpeed = NDIS_LINK_SPEED_UNKNOWN;
    attr.RcvLinkSpeed = NDIS_LINK_SPEED_UNKNOWN;
    attr.MediaConnectState = MediaConnectStateUnknown;
    attr.MediaDuplexState = MediaDuplexStateUnknown;
    attr.LookaheadSize = ETH_MAX_DATA_SIZE;
    attr.PowerManagementCapabilities = NULL;

    attr.MacOptions = NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA |
                      NDIS_MAC_OPTION_TRANSFERS_NOT_PEND |
                      NDIS_MAC_OPTION_8021P_PRIORITY |
                      NDIS_MAC_OPTION_NO_LOOPBACK;

    attr.SupportedPacketFilters = NDIS_PACKET_TYPE_DIRECTED |
                                  NDIS_PACKET_TYPE_MULTICAST |
                                  NDIS_PACKET_TYPE_ALL_MULTICAST |
                                  NDIS_PACKET_TYPE_BROADCAST;

    attr.MaxMulticastListSize = NIC_MAX_MCAST_LIST;
    attr.MacAddressLength = ETH_LENGTH_OF_ADDRESS;
    NdisMoveMemory(attr.PermanentMacAddress, a->permAddress,
                   ETH_LENGTH_OF_ADDRESS);
    NdisMoveMemory(attr.CurrentMacAddress, a->currAddress,
                   ETH_LENGTH_OF_ADDRESS);

    /* Must be NdisPhysicalMedium802_3 to pass WHQL test. */
    attr.PhysicalMediumType = NdisPhysicalMedium802_3;
    attr.RecvScaleCapabilities = NULL;
    attr.AccessType = NET_IF_ACCESS_BROADCAST;
    attr.DirectionType = NET_IF_DIRECTION_SENDRECEIVE;
    attr.ConnectionType = NET_IF_CONNECTION_DEDICATED;
    attr.IfType = IF_TYPE_ETHERNET_CSMACD;
    attr.IfConnectorPresent = TRUE; // RFC 2665 TRUE if physical adapter

    attr.SupportedStatistics =
        NDIS_STATISTICS_DIRECTED_FRAMES_RCV_SUPPORTED |
        NDIS_STATISTICS_MULTICAST_FRAMES_RCV_SUPPORTED |
        NDIS_STATISTICS_BROADCAST_FRAMES_RCV_SUPPORTED |
        NDIS_STATISTICS_BYTES_RCV_SUPPORTED |
        NDIS_STATISTICS_RCV_DISCARDS_SUPPORTED |
        NDIS_STATISTICS_RCV_ERROR_SUPPORTED |
        NDIS_STATISTICS_DIRECTED_FRAMES_XMIT_SUPPORTED |
        NDIS_STATISTICS_MULTICAST_FRAMES_XMIT_SUPPORTED |
        NDIS_STATISTICS_BROADCAST_FRAMES_XMIT_SUPPORTED |
        NDIS_STATISTICS_BYTES_XMIT_SUPPORTED |
        NDIS_STATISTICS_XMIT_ERROR_SUPPORTED |
        NDIS_STATISTICS_XMIT_DISCARDS_SUPPORTED |
        NDIS_STATISTICS_DIRECTED_BYTES_RCV_SUPPORTED |
        NDIS_STATISTICS_MULTICAST_BYTES_RCV_SUPPORTED |
        NDIS_STATISTICS_BROADCAST_BYTES_RCV_SUPPORTED |
        NDIS_STATISTICS_DIRECTED_BYTES_XMIT_SUPPORTED |
        NDIS_STATISTICS_MULTICAST_BYTES_XMIT_SUPPORTED |
        NDIS_STATISTICS_BROADCAST_BYTES_XMIT_SUPPORTED;

    attr.SupportedOidList = VenetSupportedOids;
    attr.SupportedOidListLength = sizeof(*VenetSupportedOids);

    return (NdisMSetMiniportAttributes(handle,
                                       (PNDIS_MINIPORT_ADAPTER_ATTRIBUTES) &attr));
}
예제 #9
0
파일: mp_pnp_6x.c 프로젝트: PaulJing/Sora
NDIS_STATUS
MpSetMiniportAttributes(
    __in  PHWT_ADAPTER                Adapter
    )
{
    NDIS_STATUS                 ndisStatus = NDIS_STATUS_SUCCESS;
    NDIS_MINIPORT_ADAPTER_ATTRIBUTES    miniportAttributes;
    NDIS_PM_CAPABILITIES        pmCapabilities;    

    NdisZeroMemory(&miniportAttributes, sizeof(miniportAttributes));
        
    miniportAttributes.GeneralAttributes.Header.Type = NDIS_OBJECT_TYPE_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES;
    miniportAttributes.GeneralAttributes.Header.Revision = NDIS_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_2;
    miniportAttributes.GeneralAttributes.Header.Size = NDIS_SIZEOF_MINIPORT_ADAPTER_GENERAL_ATTRIBUTES_REVISION_2;
    
    miniportAttributes.GeneralAttributes.MediaType = NdisMedium802_3;
    miniportAttributes.GeneralAttributes.PhysicalMediumType = NdisPhysicalMediumUnspecified;    
    
    miniportAttributes.GeneralAttributes.MtuSize = 1500;
    miniportAttributes.GeneralAttributes.MaxXmitLinkSpeed = XMIT_SPEED;
    miniportAttributes.GeneralAttributes.MaxRcvLinkSpeed = RECV_SPEED;
    miniportAttributes.GeneralAttributes.XmitLinkSpeed = RECV_SPEED;
    miniportAttributes.GeneralAttributes.RcvLinkSpeed = RECV_SPEED;
    miniportAttributes.GeneralAttributes.MediaConnectState = MediaConnectStateConnected;
    miniportAttributes.GeneralAttributes.MediaDuplexState = MediaDuplexStateFull;
    miniportAttributes.GeneralAttributes.LookaheadSize = 1500;
    
    NdisZeroMemory(&pmCapabilities, sizeof(NDIS_PM_CAPABILITIES));
    pmCapabilities.Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
    pmCapabilities.Header.Revision = NDIS_PM_CAPABILITIES_REVISION_1;
    pmCapabilities.Header.Size = NDIS_SIZEOF_NDIS_PM_CAPABILITIES_REVISION_1;
    miniportAttributes.GeneralAttributes.PowerManagementCapabilitiesEx = &pmCapabilities;

    miniportAttributes.GeneralAttributes.MacOptions = NDIS_MAC_OPTION_COPY_LOOKAHEAD_DATA | 
                                                            NDIS_MAC_OPTION_TRANSFERS_NOT_PEND |
                                                            NDIS_MAC_OPTION_NO_LOOPBACK;

    miniportAttributes.GeneralAttributes.SupportedPacketFilters = NDIS_PACKET_TYPE_DIRECTED |
                                                            NDIS_PACKET_TYPE_MULTICAST |
                                                            NDIS_PACKET_TYPE_ALL_MULTICAST |
                                                            NDIS_PACKET_TYPE_BROADCAST;

    miniportAttributes.GeneralAttributes.MaxMulticastListSize = 32;
    miniportAttributes.GeneralAttributes.MacAddressLength = sizeof(DOT11_MAC_ADDRESS);

    NdisMoveMemory(
        &miniportAttributes.GeneralAttributes.PermanentMacAddress,
        Adapter->CurrentAddress,
        sizeof(DOT11_MAC_ADDRESS));

    NdisMoveMemory(
        &miniportAttributes.GeneralAttributes.CurrentMacAddress,
        Adapter->CurrentAddress, 
        sizeof(DOT11_MAC_ADDRESS)
        );
    miniportAttributes.GeneralAttributes.RecvScaleCapabilities = NULL;
    miniportAttributes.GeneralAttributes.AccessType = NET_IF_ACCESS_BROADCAST;
    miniportAttributes.GeneralAttributes.DirectionType = NET_IF_DIRECTION_SENDRECEIVE;
    miniportAttributes.GeneralAttributes.IfType = IF_TYPE_ETHERNET_CSMACD;
    miniportAttributes.GeneralAttributes.IfConnectorPresent = TRUE;
    miniportAttributes.GeneralAttributes.DataBackFillSize = 8;

    MpQuerySupportedOidsList(
        &miniportAttributes.GeneralAttributes.SupportedOidList, 
        &miniportAttributes.GeneralAttributes.SupportedOidListLength);

    ndisStatus = NdisMSetMiniportAttributes(
            Adapter->AdapterHandle,
            &miniportAttributes
            );
    if (ndisStatus != NDIS_STATUS_SUCCESS)
    {
        DbgPrint("Failed to set general attributes");
    }
    return ndisStatus;
}