Exemplo n.º 1
0
/*-------------------------------------------------------------------------
  ssh_driver_initialize()
  
  Sets up virtual NIC so that it is ready for network I/O operations.

  Arguments:
  open_error_status - additional error information
  selected_medium_index - index to specified media type in medium array 
  medium_array - media array
  medium_array_size - length of media array
  miniport_handle - handle that identifies virtual NIC
  configuration_context -  handle to registry configuration of virtual NIC

  Returns:
  NDIS_STATUS_SUCCESS - initialization succeeded
  NDIS_STATUS_FAILURE - otherwise

  Notes:
  This handler is called after successful binding creation with 
  underlaying NIC.

  Default IRQL: PASSIVE_LEVEL
  -------------------------------------------------------------------------*/
static NDIS_STATUS
ssh_driver_initialize(PNDIS_STATUS open_error_status,
                      PUINT selected_medium_index,
                      PNDIS_MEDIUM medium_array,
                      UINT medium_array_size,
                      NDIS_HANDLE miniport_handle,
                      NDIS_HANDLE configuration_context)
{
  NDIS_STATUS status;
  SshNdisIMAdapter adapter;

  SSH_ASSERT(SSH_GET_IRQL() < SSH_DISPATCH_LEVEL);

  /* Retrieve the adapter context and then initialize our adapter */
  adapter = (SshNdisIMAdapter) NdisIMGetDeviceContext(miniport_handle);

  SSH_ASSERT(adapter != NULL);

  SSH_DEBUG(SSH_D_HIGHSTART, 
            ("Adapter %@ MiniportInitialize", 
             ssh_adapter_id_st_render, adapter));

  status = ssh_adapter_initialize(adapter,
                                  miniport_handle,
                                  configuration_context,
                                  medium_array_size,
                                  medium_array,
                                  selected_medium_index);

  if (status == NDIS_STATUS_SUCCESS)
    SSH_DEBUG(SSH_D_HIGHOK,
              ("Adapter %@ MiniportInitialize: status=%@, "
               "selected medium index %u",
               ssh_adapter_id_st_render, adapter,
               ssh_ndis_status_render, &status, 
               *selected_medium_index));
  else if (status == NDIS_STATUS_OPEN_FAILED)
    SSH_DEBUG(SSH_D_FAIL,
              ("Adapter %@ MiniportInitialize: status=%@, "
               "open error status %@",
               ssh_adapter_id_st_render, adapter,
               ssh_ndis_status_render, &status, 
               ssh_ndis_status_render, open_error_status));
  else
    SSH_DEBUG(SSH_D_FAIL,
              ("Adapter %@ MiniportInitialize: status=%@", 
               ssh_adapter_id_st_render, adapter,
               ssh_ndis_status_render, &status));

  return (status);
}
Exemplo n.º 2
0
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->MiniportHandle = MiniportAdapterHandle;

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

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

    DBGPRINT(("<== Miniport Initialize: Adapt %p, Status %x\n", pAdapt, Status));

    *OpenErrorStatus = Status;
    
    return Status;
}
Exemplo n.º 3
0
NDIS_STATUS
MiniportInitialize5(
    OUT PNDIS_STATUS             OpenErrorStatus,
    OUT PUINT                    SelectedMediumIndex,
    IN  PNDIS_MEDIUM             MediumArray,
    IN  UINT                     MediumArraySize,
    IN  NDIS_HANDLE              MiniportAdapterHandle,
    IN  NDIS_HANDLE              WrapperConfigurationContext
    )
{
    UINT            i;
    PADAPTER        pAdapt;
    NDIS_STATUS     Status = NDIS_STATUS_FAILURE;
    NDIS_MEDIUM     Medium;

    UNREFERENCED_PARAMETER(WrapperConfigurationContext);
    
    do
    {
        pAdapt = NdisIMGetDeviceContext(MiniportAdapterHandle);
        pAdapt->MiniportHandle = MiniportAdapterHandle;

        Medium = pAdapt->Medium;

        if (Medium == NdisMediumWan)
        {
            Medium = NdisMedium802_3;
			pAdapt->bWanAdapter = TRUE;
        }

        for (i = 0; i < MediumArraySize; i++)
        {
            if (MediumArray[i] == Medium)
            {
                *SelectedMediumIndex = i;
                break;
            }
        }

        if (i == MediumArraySize)
        {
            Status = NDIS_STATUS_UNSUPPORTED_MEDIA;
            break;
        }

        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->LastIndicatedStatus = NDIS_STATUS_MEDIA_CONNECT;
        
        pAdapt->MiniportDeviceState = NdisDeviceStateD0;

        //
        // Create an ioctl interface
        //
        (VOID)ProtocolRegisterDevice();
        
		Status = NDIS_STATUS_SUCCESS;
    }
    while (FALSE);

    ASSERT(pAdapt->MiniportInitPending == TRUE);
    pAdapt->MiniportInitPending = FALSE;
    NdisSetEvent(&pAdapt->MiniportInitEvent);

    *OpenErrorStatus = Status;
    
    return Status;
}