Пример #1
0
//-----------------------------------------------------------------------------
// Procedure:   ParseRegistryParameters
//
// Description: This routine will parse all of the parameters out of the
//              registry and store the values in the passed config structure.
//              Structure.  If the parameter is not present in the registry,
//              then the default value for the parameter will be placed into
//              the config structure.  This routine also checks the validity
//              of the parameter value.  If the value is out of range, the
//              default value will be used.
//-----------------------------------------------------------------------------
NDIS_STATUS
CAR6KMini::ParseRegistryParameters(NDIS_HANDLE ConfigHandle,
                        WLAN_STA_CONFIG *pConfig)
{
    NDIS_STATUS  status;
    CONFIG_PARAM *pParam;
    UINT         i;
    ULONG        value;
    PUCHAR       basePtr;
    PUCHAR       fieldPtr;
    PVOID        macAddr;
    UINT         macAddrLen;

    PNDIS_CONFIGURATION_PARAMETER pParamValue;


    /* Loop through the registry values specified in the above array */
    for (i = 0, pParam = paramTable; i < NUM_REG_PARAM; i++, pParam++) {
        BOOLEAN found;
        BOOLEAN useDefault = FALSE;

        switch (pParam->StructureName) {
        case sCONFIG:
            ASSERT(pConfig);
            basePtr = (PUCHAR)pConfig;
            break;
        case sNONE:
            basePtr = (PUCHAR)0;
            break;
        default:
            ASSERT(0);
        }

        fieldPtr = basePtr + pParam->FieldOffset;
        if (!fieldPtr)
        {
            continue;
        }

        /*
         * All of the registry parameters are stored as strings.
         * On NT 4, using NdisReadConfiguration with parameterType ==
         * NdisParameterInteger on a string will succeed (status wise), but
         * the parameter type returned will be string and the
         * buffer contents will be invalid.
         * To fix this, force NdisReadConfiguration to read all
         * parameters as strings, and then convert to integers as needed.
         */

        /* Get the configuration value for the parameter. */
        NdisReadConfiguration(&status, &pParamValue, ConfigHandle,
                              &pParam->RegVarName,
                              RT_ENUM_2_NDIS(pParam->RegVarType));

        found = (status == NDIS_STATUS_SUCCESS);

        /* Process the registry value based on type, currently
                only Integer type is supported  */

    switch (pParam->RegVarType) {
        case tDEC:
        default:
            if (found) {
                    value = pParamValue->ParameterData.IntegerData;


        /* Validate that the value falls within the specified range */
                if (!useDefault &&
                    (value < pParam->Min || value > pParam->Max))
                {
                    useDefault = TRUE;
                }
            }
            else {
                useDefault = TRUE;
            }

            if (useDefault) {
                /* A parameter wasn't present or was invalid */
                value = pParam->Default;
            }


            /* Store away the value into its proper spot */
            switch (pParam->FieldSize) {
            case sizeof(UCHAR):
                *((PUCHAR)fieldPtr)  = (UCHAR)value;
                break;

            case sizeof(USHORT):
                *((PUSHORT)fieldPtr) = (USHORT)value;
                break;

            case sizeof(ULONG):
                *((PULONG)fieldPtr)  = (ULONG)value;
                break;

            default:
                /* Needs to be one of the sizes above */
                ASSERT(0);
                break;
            }
            break;

        } // switch on overall type
    } // for loop for each config parameter

    {
        // Binary file path
        NDIS_STRING strPath[] = NDIS_STRING_CONST("binRoot");

        /* Get the configuration value for the parameter. */
        NdisReadConfiguration (&status, &pParamValue, ConfigHandle,
                               strPath,
                               NdisParameterString);

        if (status == NDIS_STATUS_SUCCESS)
        {
            // use the registry entry
            wcscpy (pConfig->binRoot, pParamValue->ParameterData.StringData.Buffer);
        }
        else
        {
            // use the default one
            wcscpy (pConfig->binRoot, L"\\Windows");
        }


        /* Get the configuration value for the parameter. */
        NDIS_STRING eepFileStr[] = NDIS_STRING_CONST("eepromFile");
        NdisReadConfiguration (&status, &pParamValue, ConfigHandle,
                               eepFileStr,
                               NdisParameterString);

        if (status == NDIS_STATUS_SUCCESS)
        {
            // use the registry entry
            wcscpy (pConfig->eepromFile, pParamValue->ParameterData.StringData.Buffer);
        }
        else
        {
            // use the default one
            wcscpy (pConfig->eepromFile, TEXT("\0"));
        }

        NdisReadNetworkAddress(&status, &macAddr, &macAddrLen, ConfigHandle);
        if ((status == NDIS_STATUS_SUCCESS) &&
            (macAddrLen == ETHERNET_MAC_ADDRESS_LENGTH))
        {
            NdisMoveMemory(pConfig->swMacAddr, macAddr, ETHERNET_MAC_ADDRESS_LENGTH);
        } else {
#ifdef GENERATE_MAC_ADDRESS
            if ( !wcscmp(pConfig->eepromFile, TEXT("\0")) )
#endif
            NdisMoveMemory(pConfig->swMacAddr, NullMacAddr, ETHERNET_MAC_ADDRESS_LENGTH);
#ifdef GENERATE_MAC_ADDRESS
            else
            {
                //generate MAC address when using eepromFile
                srand(GetTickCount());
                pConfig->swMacAddr[0] = 0x00;
                pConfig->swMacAddr[1] = 0x03;
                pConfig->swMacAddr[2] = 0x7f;
                pConfig->swMacAddr[3] = (unsigned char) rand();
                pConfig->swMacAddr[4] = (unsigned char) rand();
                pConfig->swMacAddr[5] = (unsigned char) rand();
            }
#endif
        }
    }

   return NDIS_STATUS_SUCCESS;
}
Пример #2
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;
}
Пример #3
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;
}
Пример #4
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);
}
Пример #5
0
VOID
Hw11ReadRegistryConfiguration(
    __in  PHW                     Hw,
    __in  NDIS_HANDLE             ConfigurationHandle
    )
{
    NDIS_STATUS                 ndisStatus = NDIS_STATUS_SUCCESS;
    PUCHAR                      NetworkAddress;
    UINT                        Length;

    // TODO: These should be read from the registry
    Hw->RegInfo.RTSThreshold = 2347;
    Hw->RegInfo.FragmentationThreshold = 2346;
    Hw->RegInfo.BeaconPeriod = 100;

    Hw->RegInfo.NumRXBuffersUpperLimit = HW11_MAX_RX_MSDUS;
    Hw->RegInfo.NumRXBuffersLowerBase = HW11_MIN_RX_MSDUS;
    
    //
    // read all the non-hardware specific registry values 
    //
    MpReadRegistry((PVOID)Hw, ConfigurationHandle, HWRegTable, HW_NUM_REG_PARAMS);

    //
    // Read NetworkAddress registry value. Use it as the current address if any.
    //
    if (ConfigurationHandle != NULL) 
    {
        NdisReadNetworkAddress(&ndisStatus,
                               (void **)&NetworkAddress,
                               &Length,
                               ConfigurationHandle);

        //
        // If there is a valid NetworkAddress override in registry,use it 
        //
        if ((ndisStatus == NDIS_STATUS_SUCCESS) && (Length == sizeof(DOT11_MAC_ADDRESS))) 
        {
            // Dont use multicast/broadcast or 00* addresses
            if (!ETH_IS_MULTICAST(NetworkAddress) && !ETH_IS_BROADCAST(NetworkAddress)) 
            {
                if ((NetworkAddress[0] == 0x00) &&
                    (NetworkAddress[1] == 0x00) &&
                    (NetworkAddress[2] == 0x00) &&
                    (NetworkAddress[3] == 0x00) &&
                    (NetworkAddress[4] == 0x00) &&
                    (NetworkAddress[5] == 0x00)) 
                {   
                    // Network addr = 00 00 00 00 00 00
                    Hw->RegInfo.AddressOverrideEnabled = FALSE;
                }
                else if ((NetworkAddress[0] & 0x02) != 0x02)
                {
                    // Not a locally administered address
                    Hw->RegInfo.AddressOverrideEnabled = FALSE;
                }
                else
                {
                    ETH_COPY_NETWORK_ADDRESS(Hw->RegInfo.OverrideAddress,NetworkAddress);
                    Hw->RegInfo.AddressOverrideEnabled = TRUE;
                }
            }
        }

        ndisStatus = NDIS_STATUS_SUCCESS;

    }

}