Example #1
0
NDIS_STATUS 
NICReadRegParameters(
    PMP_ADAPTER Adapter,
    NDIS_HANDLE WrapperConfigurationContext)
/*++
Routine Description:

    Read device configuration parameters from the registry
 
Arguments:

    Adapter                         Pointer to our adapter
    WrapperConfigurationContext     For use by NdisOpenConfiguration

    Should be called at IRQL = PASSIVE_LEVEL.
    
Return Value:

    NDIS_STATUS_SUCCESS
    NDIS_STATUS_FAILURE
    NDIS_STATUS_RESOURCES                                       

--*/    
{
    NDIS_STATUS     Status = NDIS_STATUS_SUCCESS;
    NDIS_HANDLE     ConfigurationHandle;
    PUCHAR          NetworkAddress;
    UINT            Length;
    PUCHAR          pAddr;
    static ULONG    g_ulAddress = 0;
    
    DEBUGP(MP_TRACE, ("--> NICReadRegParameters\n"));

    PAGED_CODE();

    //
    // Open the registry for this adapter to read advanced 
    // configuration parameters stored by the INF file.
    //
    NdisOpenConfiguration(
        &Status,
        &ConfigurationHandle,
        WrapperConfigurationContext);
    if(Status != NDIS_STATUS_SUCCESS)
    {
        DEBUGP(MP_ERROR, ("NdisOpenConfiguration failed\n"));
        return NDIS_STATUS_FAILURE;
    }

    //
    // Read all of our configuration parameters using NdisReadConfiguration
    // and parse the value.
    //

    //
    // Just for testing purposes, let us make up a dummy mac address.
    // In order to avoid conflicts with MAC addresses, it is usually a good
    // idea to check the IEEE OUI list (e.g. at 
    // http://standards.ieee.org/regauth/oui/oui.txt). According to that
    // list 00-50-F2 is owned by Microsoft.
    //
    // An important rule to "generating" MAC addresses is to have the 
    // "locally administered bit" set in the address, which is bit 0x02 for 
    // LSB-type networks like Ethernet. Also make sure to never set the 
    // multicast bit in any MAC address: bit 0x01 in LSB networks.
    //

    pAddr = (PUCHAR) &g_ulAddress;

    ++g_ulAddress;
    Adapter->PermanentAddress[0] = 0x00;
    Adapter->PermanentAddress[1] = 0x15;   
    Adapter->PermanentAddress[2] = 0x17;   
    Adapter->PermanentAddress[3] = 0x1C;    
    Adapter->PermanentAddress[4] = 0x47;
    Adapter->PermanentAddress[5] = 0x71;

    ETH_COPY_NETWORK_ADDRESS(
                        Adapter->CurrentAddress,
                        Adapter->PermanentAddress);

   /* //
    // Read NetworkAddress registry value and use it as the current address 
    // if there is a software configurable NetworkAddress specified in 
    // the registry.
    //
    NdisReadNetworkAddress(
        &Status,
        &NetworkAddress,
        &Length,
        ConfigurationHandle);

    if((Status == NDIS_STATUS_SUCCESS) && (Length == ETH_LENGTH_OF_ADDRESS) )
    {
          if ((ETH_IS_MULTICAST(NetworkAddress) 
                    || ETH_IS_BROADCAST(NetworkAddress))
                    || !ETH_IS_LOCALLY_ADMINISTERED (NetworkAddress))
            {
                DEBUGP(MP_ERROR, 
                    ("Overriding NetworkAddress is invalid - %02x-%02x-%02x-%02x-%02x-%02x\n", 
                    NetworkAddress[0], NetworkAddress[1], NetworkAddress[2],
                    NetworkAddress[3], NetworkAddress[4], NetworkAddress[5]));
            }
            else
            {
                ETH_COPY_NETWORK_ADDRESS(Adapter->CurrentAddress, NetworkAddress);
            }    
    }*/
    
    DEBUGP(MP_LOUD, ("Permanent Address = %02x-%02x-%02x-%02x-%02x-%02x\n", 
        Adapter->PermanentAddress[0],
        Adapter->PermanentAddress[1],
        Adapter->PermanentAddress[2],
        Adapter->PermanentAddress[3],
        Adapter->PermanentAddress[4],
        Adapter->PermanentAddress[5]));

    DEBUGP(MP_LOUD, ("Current Address = %02x-%02x-%02x-%02x-%02x-%02x\n", 
        Adapter->CurrentAddress[0],
        Adapter->CurrentAddress[1],
        Adapter->CurrentAddress[2],
        Adapter->CurrentAddress[3],
        Adapter->CurrentAddress[4],
        Adapter->CurrentAddress[5]));

    Adapter->ulLinkSpeed = NIC_LINK_SPEED;

    //
    // Close the configuration registry
    //
    NdisCloseConfiguration(ConfigurationHandle);
    DEBUGP(MP_TRACE, ("<-- NICReadRegParameters\n"));

    return NDIS_STATUS_SUCCESS;
}
Example #2
0
/*
 *************************************************************************
 *  Configure
 *************************************************************************
 *
 *  Read configurable parameters out of the system registry.
 *
 */
BOOLEAN Configure(IrDevice *thisDev, NDIS_HANDLE WrapperConfigurationContext)
{
	NDIS_STATUS result = NDIS_STATUS_SUCCESS, stat;
	NDIS_HANDLE configHandle;
	PNDIS_CONFIGURATION_PARAMETER configParamPtr;
	NDIS_STRING regKeyIRQString = NDIS_STRING_CONST("INTERRUPT");
	NDIS_STRING regKeyIOString = NDIS_STRING_CONST("IOADDRESS");
	NDIS_STRING regKeyIRTransceiverString = NDIS_STRING_CONST("InfraredTransceiverType");

	DBGOUT(("Configure(0x%x)", (UINT)thisDev));

	/*
	 *  Set default values for configurable parameters.  Default to COM1.
	 */
	thisDev->portInfo.irq = comPortIRQ[1]; 
	thisDev->portInfo.ioBase = comPortIOBase[1]; 
	thisDev->transceiverType = STANDARD_UART;

	NdisOpenConfiguration(&stat, &configHandle, WrapperConfigurationContext);
	if (stat != NDIS_STATUS_SUCCESS){
		DBGERR(("NdisOpenConfiguration failed in Configure()"));
		return FALSE;
	}

#if 1
		// BUGBUG REMOVE !!! 
		// (this here because reserving system resources causes problems for UART driver)
	{
		NDIS_STRING regKeyPortString = NDIS_STRING_CONST("PORT");
		int comPort = 1;

		/*
		 *  Get infrared transceiver type for this connection.
		 */
		NdisReadConfiguration(	&stat, 
								&configParamPtr, 
								configHandle, 
								&regKeyPortString, 
								NdisParameterInteger);
		if (stat == NDIS_STATUS_SUCCESS){

			comPort = (irTransceiverType)configParamPtr->ParameterData.IntegerData;
			thisDev->portInfo.irq = comPortIRQ[comPort]; 
			thisDev->portInfo.ioBase = comPortIOBase[comPort]; 
		}
		else {
			DBGERR(("Couldn't read Com# from registry"));
		}
	}
#else

	/*
	 *  Get IRQ level for this connection.
	 */
	NdisReadConfiguration(	&stat, 
							&configParamPtr, 
							configHandle, 
							&regKeyIRQString, 
							NdisParameterInteger);
	if (stat == NDIS_STATUS_SUCCESS){
		thisDev->portInfo.irq = (UINT)configParamPtr->ParameterData.IntegerData;
	}
	else {
		DBGERR(("Couldn't read IRQ value from registry"));
	}

	/*
	 *  Get IO base address for this connection.
	 */
	NdisReadConfiguration(	&stat, 
							&configParamPtr, 
							configHandle, 
							&regKeyIOString, 
							NdisParameterHexInteger);
	if (stat == NDIS_STATUS_SUCCESS){
		thisDev->portInfo.ioBase = (UINT)configParamPtr->ParameterData.IntegerData;
	}
	else {
		DBGERR(("Couldn't read IO value from registry"));
	}
#endif

	/*
	 *  Get infrared transceiver type for this connection.
	 */
	NdisReadConfiguration(	&stat, 
							&configParamPtr, 
							configHandle, 
							&regKeyIRTransceiverString, 
							NdisParameterInteger);
	if ((stat == NDIS_STATUS_SUCCESS) &&
	    ((UINT)configParamPtr->ParameterData.IntegerData < NUM_TRANSCEIVER_TYPES)){

		thisDev->transceiverType = (irTransceiverType)configParamPtr->ParameterData.IntegerData;
	}
	else {
		DBGERR(("Couldn't read IR transceiver type from registry"));
	}


	NdisCloseConfiguration(configHandle);

	DBGOUT(("Configure done: irq=%d IO=%xh", thisDev->portInfo.irq, thisDev->portInfo.ioBase));
	return TRUE;
}
Example #3
0
void NIC_DRIVER_OBJECT::EDriverInitialize(
		OUT PNDIS_STATUS OpenErrorStatus,
		OUT PUINT SelectedMediaIndex, 
		IN PNDIS_MEDIUM MediaArray, 
		IN UINT MediaArraySize)
{
	
	m_uRecentInterruptStatus = 0;
	
	if(!m_pLower)
		m_pLower = DeviceEntry(this,NULL);
		
	if(!m_pLower)
			THROW((ERR_STRING("Error in creating device")));
	
	UINT		i;
	NDIS_STATUS		status;
	NDIS_HANDLE		hconfig;

	// Determinate media type
	for(i=0; i<MediaArraySize; i++) 
		if(MediaArray[i] == NdisMedium802_3)	break;

    if (i == MediaArraySize) 
    	THROW((ERR_STRING("Unsupported media"),NDIS_STATUS_UNSUPPORTED_MEDIA));
		

	*SelectedMediaIndex = i;

	// Read registry configurations
	NdisOpenConfiguration(
		&status,
		&hconfig,
		m_NdisWrapper);

	if(status != NDIS_STATUS_SUCCESS) 
		THROW((ERR_STRING("Error in opening configuration"),status));

	C_Exception	*pexp;	
	TRY
	{
		m_pLower->DeviceSetDefaultSettings();
		m_pLower->DeviceSetEepromFormat();	
		m_pLower->DeviceRetriveConfigurations(hconfig);
		m_pLower->EDeviceValidateConfigurations();

		FI;
	}
	CATCH(pexp)
	{
		pexp->PrintErrorMessage();
		CLEAN(pexp);
		NdisCloseConfiguration(hconfig);
		THROW((ERR_STRING("*** Error in retriving configurations.\n")));
	}

	NdisCloseConfiguration(hconfig);

	m_pLower->DeviceRegisterAdapter();
	
	/* init tx buffers */
	U32		m,uaddr;
	if(!(uaddr = (U32)malloc(sizeof(DATA_BLOCK)*
		(m=m_pLower->m_szConfigures[CID_TXBUFFER_NUMBER]*2)))) 
		THROW((ERR_STRING("Insufficient memory")));

	for(;m--;uaddr+=sizeof(DATA_BLOCK))
		m_TQueue.Enqueue((PCQUEUE_GEN_HEADER)uaddr);

	TRY
	{
		m_pLower->EDeviceRegisterIoSpace();

		m_pLower->EDeviceLoadEeprom();

		m_pLower->EDeviceInitialize(m_pLower->m_nResetCounts=0);

		m_pLower->EDeviceRegisterInterrupt();
		
		FI;
	}
	CATCH(pexp)
	{
		pexp->PrintErrorMessage();
		CLEAN(pexp);
		THROW((ERR_STRING("Device error")));
	}

	
	m_pLower->DeviceOnSetupFilter(0);

}
Example #4
0
// Called at <= DISPATCH_LEVEL
static NDIS_STATUS
XenNet_Init(
  OUT PNDIS_STATUS OpenErrorStatus,
  OUT PUINT SelectedMediumIndex,
  IN PNDIS_MEDIUM MediumArray,
  IN UINT MediumArraySize,
  IN NDIS_HANDLE MiniportAdapterHandle,
  IN NDIS_HANDLE WrapperConfigurationContext
  )
{
  NDIS_STATUS status;
  BOOLEAN medium_found = FALSE;
  struct xennet_info *xi = NULL;
  UINT nrl_length;
  PNDIS_RESOURCE_LIST nrl;
  PCM_PARTIAL_RESOURCE_DESCRIPTOR prd;
  KIRQL irq_level = 0;
  ULONG irq_vector = 0;
  ULONG irq_mode = 0;
  NDIS_HANDLE config_handle;
  NDIS_STRING config_param_name;
  PNDIS_CONFIGURATION_PARAMETER config_param;
  ULONG i;
  PUCHAR ptr;
  UCHAR type;
  PCHAR setting, value;
  ULONG length;
  //CHAR buf[128];
  PVOID network_address;
  UINT network_address_length;
  BOOLEAN qemu_hide_filter = FALSE;
  ULONG qemu_hide_flags_value = 0;
  
  UNREFERENCED_PARAMETER(OpenErrorStatus);

  FUNCTION_ENTER();

  KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));

  /* deal with medium stuff */
  for (i = 0; i < MediumArraySize; i++)
  {
    if (MediumArray[i] == NdisMedium802_3)
    {
      medium_found = TRUE;
      break;
    }
  }
  if (!medium_found)
  {
    KdPrint(("NIC_MEDIA_TYPE not in MediumArray\n"));
    return NDIS_STATUS_UNSUPPORTED_MEDIA;
  }
  *SelectedMediumIndex = i;

  /* Alloc memory for adapter private info */
  status = NdisAllocateMemoryWithTag((PVOID)&xi, sizeof(*xi), XENNET_POOL_TAG);
  if (!NT_SUCCESS(status))
  {
    KdPrint(("NdisAllocateMemoryWithTag failed with 0x%x\n", status));
    status = NDIS_STATUS_RESOURCES;
    goto err;
  }
  RtlZeroMemory(xi, sizeof(*xi));
  xi->adapter_handle = MiniportAdapterHandle;
  xi->rx_target     = RX_DFL_MIN_TARGET;
  xi->rx_min_target = RX_DFL_MIN_TARGET;
  xi->rx_max_target = RX_MAX_TARGET;
  xi->inactive      = TRUE;
  NdisMSetAttributesEx(xi->adapter_handle, (NDIS_HANDLE) xi, 0, 0 /* the last zero is to give the next | something to | with */
#ifdef NDIS51_MINIPORT
    |NDIS_ATTRIBUTE_USES_SAFE_BUFFER_APIS
#endif
    |NDIS_ATTRIBUTE_DESERIALIZE
    |NDIS_ATTRIBUTE_SURPRISE_REMOVE_OK,
    NdisInterfaceInternal); /* PnpBus option doesn't exist... */
  xi->multicast_list_size = 0;
  xi->current_lookahead = MIN_LOOKAHEAD_LENGTH;

  nrl_length = 0;
  NdisMQueryAdapterResources(&status, WrapperConfigurationContext,
    NULL, (PUINT)&nrl_length);
  KdPrint((__DRIVER_NAME "     nrl_length = %d\n", nrl_length));
  status = NdisAllocateMemoryWithTag((PVOID)&nrl, nrl_length, XENNET_POOL_TAG);
  if (status != NDIS_STATUS_SUCCESS)
  {
    KdPrint((__DRIVER_NAME "     Could not get allocate memory for Adapter Resources 0x%x\n", status));
    return NDIS_STATUS_RESOURCES;
  }
  NdisMQueryAdapterResources(&status, WrapperConfigurationContext,
    nrl, (PUINT)&nrl_length);
  if (status != NDIS_STATUS_SUCCESS)
  {
    KdPrint((__DRIVER_NAME "     Could not get Adapter Resources 0x%x\n", status));
    return NDIS_STATUS_RESOURCES;
  }
  xi->event_channel = 0;
  xi->config_csum = 1;
  xi->config_csum_rx_check = 1;
  xi->config_sg = 1;
  xi->config_gso = 61440;
  xi->config_page = NULL;
  xi->config_rx_interrupt_moderation = 0;
  
  for (i = 0; i < nrl->Count; i++)
  {
    prd = &nrl->PartialDescriptors[i];

    switch(prd->Type)
    {
    case CmResourceTypeInterrupt:
      irq_vector = prd->u.Interrupt.Vector;
      irq_level = (KIRQL)prd->u.Interrupt.Level;
      irq_mode = (prd->Flags & CM_RESOURCE_INTERRUPT_LATCHED)?NdisInterruptLatched:NdisInterruptLevelSensitive;
      KdPrint((__DRIVER_NAME "     irq_vector = %03x, irq_level = %03x, irq_mode = %s\n", irq_vector, irq_level,
        (irq_mode == NdisInterruptLatched)?"NdisInterruptLatched":"NdisInterruptLevelSensitive"));
      break;
    case CmResourceTypeMemory:
      if (xi->config_page)
      {
        KdPrint(("More than one memory range\n"));
        return NDIS_STATUS_RESOURCES;
      }
      else
      {
        status = NdisMMapIoSpace(&xi->config_page, MiniportAdapterHandle, prd->u.Memory.Start, prd->u.Memory.Length);
        if (!NT_SUCCESS(status))
        {
          KdPrint(("NdisMMapIoSpace failed with 0x%x\n", status));
          NdisFreeMemory(nrl, nrl_length, 0);
          return NDIS_STATUS_RESOURCES;
        }
      }
      break;
    }
  }
  NdisFreeMemory(nrl, nrl_length, 0);
  if (!xi->config_page)
  {
    KdPrint(("No config page given\n"));
    return NDIS_STATUS_RESOURCES;
  }

  KeInitializeDpc(&xi->suspend_dpc, XenNet_SuspendResume, xi);
  KeInitializeSpinLock(&xi->resume_lock);

  KeInitializeDpc(&xi->rxtx_dpc, XenNet_RxTxDpc, xi);
  KeSetTargetProcessorDpc(&xi->rxtx_dpc, 0);
  KeSetImportanceDpc(&xi->rxtx_dpc, HighImportance);

  NdisMGetDeviceProperty(MiniportAdapterHandle, &xi->pdo, &xi->fdo,
    &xi->lower_do, NULL, NULL);
  xi->packet_filter = 0;

  status = IoGetDeviceProperty(xi->pdo, DevicePropertyDeviceDescription,
    NAME_SIZE, xi->dev_desc, &length);
  if (!NT_SUCCESS(status))
  {
    KdPrint(("IoGetDeviceProperty failed with 0x%x\n", status));
    status = NDIS_STATUS_FAILURE;
    goto err;
  }

  ptr = xi->config_page;
  while((type = GET_XEN_INIT_RSP(&ptr, (PVOID)&setting, (PVOID)&value, (PVOID)&value)) != XEN_INIT_TYPE_END)
  {
    switch(type)
    {
    case XEN_INIT_TYPE_VECTORS:
      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_VECTORS\n"));
      if (((PXENPCI_VECTORS)value)->length != sizeof(XENPCI_VECTORS) ||
        ((PXENPCI_VECTORS)value)->magic != XEN_DATA_MAGIC)
      {
        KdPrint((__DRIVER_NAME "     vectors mismatch (magic = %08x, length = %d)\n",
          ((PXENPCI_VECTORS)value)->magic, ((PXENPCI_VECTORS)value)->length));
        FUNCTION_EXIT();
        return NDIS_STATUS_FAILURE;
      }
      else
        memcpy(&xi->vectors, value, sizeof(XENPCI_VECTORS));
      break;
    case XEN_INIT_TYPE_STATE_PTR:
      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_DEVICE_STATE - %p\n", PtrToUlong(value)));
      xi->device_state = (PXENPCI_DEVICE_STATE)value;
      break;
    case XEN_INIT_TYPE_QEMU_HIDE_FLAGS:
      qemu_hide_flags_value = PtrToUlong(value);
      break;
    case XEN_INIT_TYPE_QEMU_HIDE_FILTER:
      qemu_hide_filter = TRUE;
      break;
    default:
      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_%d\n", type));
      break;
    }
  }

  if ((qemu_hide_flags_value & QEMU_UNPLUG_ALL_IDE_DISKS) || qemu_hide_filter)
    xi->inactive = FALSE;

  xi->power_state = NdisDeviceStateD0;
  xi->power_workitem = IoAllocateWorkItem(xi->fdo);

  // now build config page
  
  NdisOpenConfiguration(&status, &config_handle, WrapperConfigurationContext);
  if (!NT_SUCCESS(status))
  {
    KdPrint(("Could not open config in registry (%08x)\n", status));
    status = NDIS_STATUS_RESOURCES;
    goto err;
  }

  NdisInitUnicodeString(&config_param_name, L"ScatterGather");
  NdisReadConfiguration(&status, &config_param, config_handle, &config_param_name, NdisParameterInteger);
  if (!NT_SUCCESS(status))
  {
    KdPrint(("Could not read ScatterGather value (%08x)\n", status));
    xi->config_sg = 1;
  }
  else
  {
    KdPrint(("ScatterGather = %d\n", config_param->ParameterData.IntegerData));
    xi->config_sg = config_param->ParameterData.IntegerData;
  }
  
  NdisInitUnicodeString(&config_param_name, L"LargeSendOffload");
  NdisReadConfiguration(&status, &config_param, config_handle, &config_param_name, NdisParameterInteger);
  if (!NT_SUCCESS(status))
  {
    KdPrint(("Could not read LargeSendOffload value (%08x)\n", status));
    xi->config_gso = 0;
  }
  else
  {
    KdPrint(("LargeSendOffload = %d\n", config_param->ParameterData.IntegerData));
    xi->config_gso = config_param->ParameterData.IntegerData;
    if (xi->config_gso > 61440)
    {
      xi->config_gso = 61440;
      KdPrint(("(clipped to %d)\n", xi->config_gso));
    }
  }

  NdisInitUnicodeString(&config_param_name, L"ChecksumOffload");
  NdisReadConfiguration(&status, &config_param, config_handle, &config_param_name, NdisParameterInteger);
  if (!NT_SUCCESS(status))
  {
    KdPrint(("Could not read ChecksumOffload value (%08x)\n", status));
    xi->config_csum = 1;
  }
  else
  {
    KdPrint(("ChecksumOffload = %d\n", config_param->ParameterData.IntegerData));
    xi->config_csum = !!config_param->ParameterData.IntegerData;
  }

  NdisInitUnicodeString(&config_param_name, L"ChecksumOffloadRxCheck");
  NdisReadConfiguration(&status, &config_param, config_handle, &config_param_name, NdisParameterInteger);
  if (!NT_SUCCESS(status))
  {
    KdPrint(("Could not read ChecksumOffloadRxCheck value (%08x)\n", status));
    xi->config_csum_rx_check = 1;
  }
  else
  {
    KdPrint(("ChecksumOffloadRxCheck = %d\n", config_param->ParameterData.IntegerData));
    xi->config_csum_rx_check = !!config_param->ParameterData.IntegerData;
  }

  NdisInitUnicodeString(&config_param_name, L"ChecksumOffloadDontFix");
  NdisReadConfiguration(&status, &config_param, config_handle, &config_param_name, NdisParameterInteger);
  if (!NT_SUCCESS(status))
  {
    KdPrint(("Could not read ChecksumOffloadDontFix value (%08x)\n", status));
    xi->config_csum_rx_dont_fix = 0;
  }
  else
  {
    KdPrint(("ChecksumOffloadDontFix = %d\n", config_param->ParameterData.IntegerData));
    xi->config_csum_rx_dont_fix = !!config_param->ParameterData.IntegerData;
  }
  
  
  
  NdisInitUnicodeString(&config_param_name, L"MTU");
  NdisReadConfiguration(&status, &config_param, config_handle, &config_param_name, NdisParameterInteger);  
  if (!NT_SUCCESS(status))
  {
    KdPrint(("Could not read MTU value (%08x)\n", status));
    xi->config_mtu = 1500;
  }
  else
  {
    KdPrint(("MTU = %d\n", config_param->ParameterData.IntegerData));
    xi->config_mtu = config_param->ParameterData.IntegerData;
  }

  NdisInitUnicodeString(&config_param_name, L"RxInterruptModeration");
  NdisReadConfiguration(&status, &config_param, config_handle, &config_param_name, NdisParameterInteger);  
  if (!NT_SUCCESS(status))
  {
    KdPrint(("Could not read RxInterruptModeration value (%08x)\n", status));
    xi->config_rx_interrupt_moderation = 1500;
  }
  else
  {
    KdPrint(("RxInterruptModeration = %d\n", config_param->ParameterData.IntegerData));
    xi->config_rx_interrupt_moderation = config_param->ParameterData.IntegerData;
  }
  

  NdisReadNetworkAddress(&status, &network_address, &network_address_length, config_handle);
  if (!NT_SUCCESS(status) || network_address_length != ETH_ALEN || ((((PUCHAR)network_address)[0] & 0x03) != 0x02))
  {
    KdPrint(("Could not read NetworkAddress value (%08x) or value is invalid\n", status));
    memset(xi->curr_mac_addr, 0, ETH_ALEN);
  }
  else
  {
    memcpy(xi->curr_mac_addr, network_address, ETH_ALEN);
    KdPrint(("     Set MAC address from registry to %02X:%02X:%02X:%02X:%02X:%02X\n",
      xi->curr_mac_addr[0], xi->curr_mac_addr[1], xi->curr_mac_addr[2], 
      xi->curr_mac_addr[3], xi->curr_mac_addr[4], xi->curr_mac_addr[5]));
  }

  xi->config_max_pkt_size = max(xi->config_mtu + XN_HDR_SIZE, xi->config_gso + XN_HDR_SIZE);
  
  NdisCloseConfiguration(config_handle);

  status = XenNet_D0Entry(xi);
  if (!NT_SUCCESS(status))
  {
    KdPrint(("Failed to go to D0 (%08x)\n", status));
    goto err;
  }
  return NDIS_STATUS_SUCCESS;
  
err:
  NdisFreeMemory(xi, 0, 0);
  *OpenErrorStatus = status;
  FUNCTION_EXIT_STATUS(status);
  return status;
}
Example #5
0
NDIS_STATUS
LtInitAddAdapter(
	IN NDIS_HANDLE 	MacMacContext,
	IN NDIS_HANDLE 	ConfigurationHandle,
	IN PNDIS_STRING AdapterName
	)
/*++

Routine Description:

	This is called by NDIS when we do a register adapter.

Arguments:

	MacMacContext		:	Context passed to Add/Unload. NULL in our case.
	ConfigurationHandle	:	Handle to configuration info.
	AdapterName			:	Name to use to register the adapter.

Return Value:

	NDIS_STATUS_SUCCESS	: 	If successful, error otherwise

--*/
{
	NDIS_HANDLE 		ConfigHandle;
	UCHAR				SuggestedNodeId;
	UINT 				BusNumber, IoBaseAddress;
	NDIS_INTERFACE_TYPE BusType;
	BOOLEAN				configHandleOpen = FALSE;
	NDIS_STATUS 		Status = NDIS_STATUS_ADAPTER_NOT_FOUND;

	if (ConfigurationHandle == NULL)
	{
		return(Status);
	}


	do
	{
		NdisOpenConfiguration(
			&Status,
			&ConfigHandle,
			ConfigurationHandle);

		if (Status != NDIS_STATUS_SUCCESS)
		{
			break;
		}

		configHandleOpen = TRUE;

		// The following functions return the parameter as specified in the
		// Configuration database or the default.  If the database has an
		// incorrect value, then the default is returned and an Error Event
		// is logged.

		BusNumber 	= LtRegGetBusNumber(ConfigHandle);

		Status 		= LtRegGetBusType(ConfigHandle, &BusType);
		if (Status != NDIS_STATUS_SUCCESS)
		{
			break;
		}

		//	Get the io base address
		Status = LtRegGetIoBaseAddr(
					&IoBaseAddress,
					ConfigurationHandle,
					ConfigHandle,
					BusType);

		if (Status != NDIS_STATUS_SUCCESS)
		{
			break;
		}

		//	Get default id or pram node id to try.
		SuggestedNodeId = LtRegGetNodeId(ConfigHandle);

	} while (FALSE);

	//	We have to register the adapter to log an error if that happened.
	Status = LtInitRegisterAdapter(
				LtMacHandle,
				ConfigurationHandle,
				AdapterName,
				BusType,
				SuggestedNodeId,
				IoBaseAddress,
				LT_MAX_ADAPTERS,
				Status);

	if (configHandleOpen)
	{
		NdisCloseConfiguration(ConfigHandle);
	}

	return Status;
}
Example #6
0
/*
 Function Name : 	GetRegistrySettings
 Description   :	
					Reads the registry values, and loads them into the adapter structure
 Parameters    :
					MINIPORT_ADAPTER *Adapter	- Pointer to the adapter structure
					NDIS_HANDLE       ConfigurationContext - Context handler, from the NDIS wrapper
			
 Return Value  :
					NDIS_STATUS		Status
*/
NDIS_STATUS GetRegistrySettings(MINIPORT_ADAPTER*	pAdapter,
								NDIS_HANDLE			hConfigurationContext)
{
	NDIS_STATUS						Status;
	NDIS_HANDLE						hConfiguration;
	PNDIS_CONFIGURATION_PARAMETER	pConfigurationParameter;
	BOOL							bSpeedDef = FALSE, bDuplexDef = FALSE;

	UCHAR*							pNewNetworkAddress = NULL;
	UINT							nNewNetworkAddressLength;

	//	EMAC specific settings
	NDIS_STRING						szBufferAddr	= NDIS_STRING_CONST("BufferAddr");
	NDIS_STRING						szTxStride		= NDIS_STRING_CONST("TxStrides");
	NDIS_STRING						szRxStride		= NDIS_STRING_CONST("RxStrides");
	NDIS_STRING						szITNum			= NDIS_STRING_CONST("IRQNumber");
	NDIS_STRING						szEMACAddr		= NDIS_STRING_CONST("IoBaseAddress");
	NDIS_STRING						szRMII			= NDIS_STRING_CONST("RMII");

	//	Eth Link settings
	NDIS_STRING						AutoNegString	= NDIS_STRING_CONST("AUTO-NEGOTIATION");
	NDIS_STRING						DuplexString	= NDIS_STRING_CONST("DUPLEX");
	NDIS_STRING						FullDupString	= NDIS_STRING_CONST("FULL");
	NDIS_STRING						HalfDupString	= NDIS_STRING_CONST("HALF");
	NDIS_STRING						SpeedString		= NDIS_STRING_CONST("SPEED");
	NDIS_STRING						Speed100String	= NDIS_STRING_CONST("100");
	NDIS_STRING						Speed10String	= NDIS_STRING_CONST("10");
	
	DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS ==> GetRegistrySettings\r\n")));

	//Open the Registry tree for this adapter.
    NdisOpenConfiguration(&Status, &hConfiguration, hConfigurationContext);
	if(Status != NDIS_STATUS_SUCCESS)
    {
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS : ERROR - No information for adapter!\r\n")));
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS <== Configure Adapter\r\n")));
        return(NDIS_STATUS_FAILURE);
    }

	//Get configured Buffer address value from registry,
	NdisReadConfiguration(	&Status,   
							&pConfigurationParameter,
							hConfiguration,
							&szBufferAddr,
							NdisParameterInteger); 
	if(Status == NDIS_STATUS_SUCCESS)
	{
		pAdapter->dwBufferPhyAddr = (DWORD) pConfigurationParameter->ParameterData.IntegerData;
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:dwBufferPhyAddr    = 0x%.8x\r\n"), pAdapter->dwBufferPhyAddr));
	}
	else
	{
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS : ERROR - BufferAddr not in Registry!\r\n")));
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS <== Configure Adapter\r\n")));
		NdisCloseConfiguration(hConfiguration);
		return(NDIS_STATUS_FAILURE);
	}

	//Get configured Number of TX Strides from registry,
	NdisReadConfiguration(	&Status,   
							&pConfigurationParameter,
							hConfiguration,
							&szTxStride,
							NdisParameterInteger); 
	if(Status == NDIS_STATUS_SUCCESS)
	{
		pAdapter->dwTxStrides = (DWORD) pConfigurationParameter->ParameterData.IntegerData;
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:dwTxStrides    = 0x%x\r\n"), pAdapter->dwTxStrides));
	}
	else
	{
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS : ERROR - TXStrides not in Registry!\r\n")));
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS <== Configure Adapter\r\n")));
		NdisCloseConfiguration(hConfiguration);
		return(NDIS_STATUS_FAILURE);
	}

	//Get configured Number of RX Strides from registry,
	NdisReadConfiguration(	&Status,   
							&pConfigurationParameter,
							hConfiguration,
							&szRxStride,
							NdisParameterInteger); 
	if(Status == NDIS_STATUS_SUCCESS)
	{
		pAdapter->dwRxStrides = (DWORD) pConfigurationParameter->ParameterData.IntegerData;
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:dwRxStrides    = 0x%x\r\n"), pAdapter->dwRxStrides));
	}
	else
	{
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS : ERROR - RXStrides not in Registry!\r\n")));
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS <== Configure Adapter\r\n")));
		NdisCloseConfiguration(hConfiguration);
		return(NDIS_STATUS_FAILURE);
	}

	//Get configured IRQ Number from registry,
	NdisReadConfiguration(	&Status,   
							&pConfigurationParameter,
							hConfiguration,
							&szITNum,
							NdisParameterInteger); 
	if(Status == NDIS_STATUS_SUCCESS)
	{
		pAdapter->dwIRQNumber = (DWORD) pConfigurationParameter->ParameterData.IntegerData;
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:dwIRQNumber    = 0x%x\r\n"), pAdapter->dwIRQNumber));
	}
	else
	{
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS : ERROR - IRQNumber not in Registry!\r\n")));
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS <== Configure Adapter\r\n")));
		NdisCloseConfiguration(hConfiguration);
		return(NDIS_STATUS_FAILURE);
	}

	//Get configured EMAC base address from registry,
	NdisReadConfiguration(	&Status,   
							&pConfigurationParameter,
							hConfiguration,
							&szEMACAddr,
							NdisParameterInteger); 
	
	if(Status == NDIS_STATUS_SUCCESS)
	{
		pAdapter->dwControllerAddress = (DWORD) pConfigurationParameter->ParameterData.IntegerData;
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:dwControllerAddress    = 0x%.8x\r\n"), pAdapter->dwControllerAddress));
		RETAILMSG(1, (TEXT("LPC3xxx NDIS:dwControllerAddress    = 0x%.8x\r\n"), pAdapter->dwControllerAddress));
	}
	else
	{
		RETAILMSG(1, (TEXT("LPC3xxx NDIS : ERROR - IoBaseAddress not in Registry!\r\n")));
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS : ERROR - IoBaseAddress not in Registry!\r\n")));
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS <== Configure Adapter\r\n")));
		NdisCloseConfiguration(hConfiguration);
		return(NDIS_STATUS_FAILURE);
	}

	
	//Get PHY interface type (MII/RMII) from registry,
	NdisReadConfiguration(	&Status,   
							&pConfigurationParameter,
							hConfiguration,
							&szRMII,
							NdisParameterInteger); 
	if(Status == NDIS_STATUS_SUCCESS)
	{
		pAdapter->bRMII = ((USHORT) pConfigurationParameter->ParameterData.IntegerData == 0) ? FALSE : TRUE;
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:bRMII    = %s\r\n"), pAdapter->bRMII ? L"TRUE" : L"FALSE"));
	}
	else
	{
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS : RMII not in Registry!\r\n")));
		pAdapter->bRMII = TRUE;
	}

	NdisReadConfiguration(	&Status,
							&pConfigurationParameter,
							hConfiguration,
							&DuplexString,
							NdisParameterString);
	
	if(Status == NDIS_STATUS_SUCCESS)
	{
		bDuplexDef = TRUE;

		if( NdisEqualString( (PNDIS_STRING) &pConfigurationParameter->ParameterData.StringData,&FullDupString, TRUE ) ) 
		{
			DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:Config is Full Duplex\r\n")));
			pAdapter->bFullDuplex = TRUE;
		}
		else if( NdisEqualString( (PNDIS_STRING) &pConfigurationParameter->ParameterData.StringData, &HalfDupString, TRUE ) ) 
		{
			DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:Config is Half Duplex\r\n")));
			pAdapter->bFullDuplex = FALSE;
		}				
	}

	NdisReadConfiguration(	&Status, 
							&pConfigurationParameter, 
							hConfiguration,
							&SpeedString,
							NdisParameterString);
	if(Status == NDIS_STATUS_SUCCESS) 
	{
		bSpeedDef = TRUE;
		if( NdisEqualString( (PNDIS_STRING) &pConfigurationParameter->ParameterData.StringData,(PNDIS_STRING) &Speed100String,TRUE ) ) 
		{
			DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:Config is 100 Mbps\r\n")));
			pAdapter->b100Mbps = TRUE;
		}
		else if( NdisEqualString( (PNDIS_STRING) &pConfigurationParameter->ParameterData.StringData,(PNDIS_STRING) &Speed10String,TRUE ) )
		{
			DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:Config is 10 Mbps\r\n")));
			pAdapter->b100Mbps = FALSE;
		}
	}

	if(bSpeedDef && bDuplexDef)
	{
		pAdapter->bAutoNeg = FALSE;
	}

	NdisReadConfiguration(	&Status,
							&pConfigurationParameter,
							hConfiguration,
							&AutoNegString,
							NdisParameterString);
	if(Status == NDIS_STATUS_SUCCESS)
	{
		if((USHORT) pConfigurationParameter->ParameterData.IntegerData == 0)
		{
			pAdapter->bAutoNeg = FALSE;
		}
		else
		{
			pAdapter->bAutoNeg = TRUE;
		}
	}

	if(pAdapter->bAutoNeg)
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:Config is AutoNeg Enabled\r\n")));
	else
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:Config is AutoNeg Disabled\r\n")));

	//See if user has defined new MAC address.
	NdisReadNetworkAddress(	&Status,
							(PVOID *) &pNewNetworkAddress,
							&nNewNetworkAddressLength,
							hConfiguration);
				
	if((Status == NDIS_STATUS_SUCCESS) && (nNewNetworkAddressLength != 0))
	{
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:Default MAC Address over-ride!\r\n")));
		if((nNewNetworkAddressLength != ETH_LENGTH_OF_ADDRESS)) 
		{
			DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:Invalid MAC address length!\r\n")));
		}
		else
		{
			pAdapter->MACAddress[0] = pNewNetworkAddress[0];
			pAdapter->MACAddress[1] = pNewNetworkAddress[1];
			pAdapter->MACAddress[2] = pNewNetworkAddress[2];
			pAdapter->MACAddress[3] = pNewNetworkAddress[3];
			pAdapter->MACAddress[4] = pNewNetworkAddress[4];
			pAdapter->MACAddress[5] = pNewNetworkAddress[5];

			DEBUGMSG(ZONE_INIT,(TEXT("Registry reads = %02X-%02X-%02X-%02X-%02X-%02X\r\n"),
				pNewNetworkAddress[0], 
				pNewNetworkAddress[1],
				pNewNetworkAddress[2],
				pNewNetworkAddress[3],
				pNewNetworkAddress[4],
				pNewNetworkAddress[5]));

			DEBUGMSG(ZONE_INIT,(TEXT("Adapter->MACAddress reads = %02X-%02X-%02X-%02X-%02X-%02X\r\n"),
				pAdapter->MACAddress[0],
				pAdapter->MACAddress[1],
				pAdapter->MACAddress[2],
				pAdapter->MACAddress[3],
				pAdapter->MACAddress[4],
				pAdapter->MACAddress[5]));
		}
	}
	else
	{
		Status = NDIS_STATUS_SUCCESS;
	}

	NdisCloseConfiguration(hConfiguration);

	if(Status != NDIS_STATUS_SUCCESS)
	{
			DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:ERROR: Specific Configuration Handler Failed!\r\n")));
			DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:<== Configure Adapter\r\n")));
			return(Status);
	}
	
	DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS <== GetRegistrySettings  \r\n")));
	return(Status);
}
Example #7
0
// Read the information from the registry
BOOL NeoLoadRegistory()
{
	void *buf;
	NDIS_STATUS ret;
	UINT size;
	NDIS_HANDLE config;
	NDIS_CONFIGURATION_PARAMETER *param;
	UNICODE *name;
	ANSI_STRING ansi;
	UNICODE_STRING *unicode;
	UINT speed;
	BOOL keep;

	// Get the config handle
	NdisOpenConfiguration(&ret, &config, ctx->NdisConfig);
	if (NG(ret))
	{
		// Failure
		return FALSE;
	}

	// Read the MAC address
	NdisReadNetworkAddress(&ret, &buf, &size, config);
	if (NG(ret))
	{
		// Failure
		NdisCloseConfiguration(config);
		return FALSE;
	}

	// Copy the MAC address
	if (size != NEO_MAC_ADDRESS_SIZE)
	{
		// Invalid size
		NdisCloseConfiguration(config);
		return FALSE;
	}
	NeoCopy(ctx->MacAddress, buf, NEO_MAC_ADDRESS_SIZE);

	if (ctx->MacAddress[0] == 0x00 &&
		ctx->MacAddress[1] == 0x00 &&
		ctx->MacAddress[2] == 0x01 &&
		ctx->MacAddress[3] == 0x00 &&
		ctx->MacAddress[4] == 0x00 &&
		ctx->MacAddress[5] == 0x01)
	{
		// Special MAC address
		UINT ptr32 = (UINT)((UINT64)ctx);

		ctx->MacAddress[0] = 0x00;
		ctx->MacAddress[1] = 0xAD;
		ctx->MacAddress[2] = ((UCHAR *)(&ptr32))[0];
		ctx->MacAddress[3] = ((UCHAR *)(&ptr32))[1];
		ctx->MacAddress[4] = ((UCHAR *)(&ptr32))[2];
		ctx->MacAddress[5] = ((UCHAR *)(&ptr32))[3];
	}

	// Initialize the key name of the device name
	name = NewUnicode("MatchingDeviceId");

	// Read the hardware ID
	NdisReadConfiguration(&ret, &param, config, GetUnicode(name), NdisParameterString);
	FreeUnicode(name);
	if (NG(ret))
	{
		// Failure
		NdisCloseConfiguration(config);
		return FALSE;
	}
	// Type checking
	if (param->ParameterType != NdisParameterString)
	{
		// Failure
		NdisCloseConfiguration(config);
		return FALSE;
	}
	unicode = &param->ParameterData.StringData;

	// Prepare a buffer for ANSI string
	NeoZero(&ansi, sizeof(ANSI_STRING));
	ansi.MaximumLength = MAX_SIZE - 1;
	ansi.Buffer = NeoZeroMalloc(MAX_SIZE);

	// Convert to ANSI string
	NdisUnicodeStringToAnsiString(&ansi, unicode);
	// Copy
	strcpy(ctx->HardwareID, ansi.Buffer);
	strcpy(ctx->HardwareID_Raw, ctx->HardwareID);
	// Convert to upper case
	_strupr(ctx->HardwareID);
	// Release the memory
	NeoFree(ansi.Buffer);

	// Read the bit rate
	name = NewUnicode("MaxSpeed");
	NdisReadConfiguration(&ret, &param, config, GetUnicode(name), NdisParameterInteger);
	FreeUnicode(name);

	if (NG(ret) || param->ParameterType != NdisParameterInteger)
	{
		speed = NEO_MAX_SPEED_DEFAULT;
	}
	else
	{
		speed = param->ParameterData.IntegerData * 10000;
	}

	max_speed = speed;

	// Read the link keeping flag
	name = NewUnicode("KeepLink");
	NdisReadConfiguration(&ret, &param, config, GetUnicode(name), NdisParameterInteger);
	FreeUnicode(name);

	if (NG(ret) || param->ParameterType != NdisParameterInteger)
	{
		keep = false;
	}
	else
	{
		keep = (param->ParameterData.IntegerData == 0 ? false : true);
	}

	keep_link = keep;

	// Close the Config handle
	NdisCloseConfiguration(config);

	return TRUE;
}