VOID tapReadPermanentAddress(__in PTAP_ADAPTER_CONTEXT Adapter, __in NDIS_HANDLE ConfigurationHandle, __out MACADDR PermanentAddress) { NDIS_STATUS status; NDIS_CONFIGURATION_PARAMETER *configParameter; NDIS_STRING macKey = NDIS_STRING_CONST("MAC"); ANSI_STRING macString; BOOLEAN macFromRegistry = FALSE; // Read MAC parameter from registry. NdisReadConfiguration(&status, &configParameter, ConfigurationHandle, &macKey, NdisParameterString); if (status == NDIS_STATUS_SUCCESS) { if ((configParameter->ParameterType == NdisParameterString) && (configParameter->ParameterData.StringData.Length >= 12)) { if (RtlUnicodeStringToAnsiString(&macString, &configParameter->ParameterData.StringData, TRUE) == STATUS_SUCCESS) { macFromRegistry = ParseMAC(PermanentAddress, macString.Buffer); RtlFreeAnsiString(&macString); } } } if (!macFromRegistry) { // // There is no (valid) address stashed in the registry parameter. // // Make up a dummy mac address based on the ANSI representation of the // NetCfgInstanceId GUID. // GenerateRandomMac(PermanentAddress, MINIPORT_INSTANCE_ID(Adapter)); } }
static NDIS_STATUS ReadGlobalConfigurationEntry(NDIS_HANDLE cfg, const char *_name, PULONG pValue) { NDIS_STATUS status; PNDIS_CONFIGURATION_PARAMETER pParam = NULL; NDIS_STRING name = {0}; const char *statusName; NDIS_PARAMETER_TYPE ParameterType = NdisParameterInteger; NdisInitializeString(&name, (PUCHAR)_name); #pragma warning(push) #pragma warning(disable:6102) NdisReadConfiguration( &status, &pParam, cfg, &name, ParameterType); if (status == NDIS_STATUS_SUCCESS) { *pValue = pParam->ParameterData.IntegerData; statusName = "value"; } else { statusName = "nothing"; } #pragma warning(pop) DPrintf(2, ("[%s] %s read for %s - 0x%x\n", __FUNCTION__, statusName, _name, *pValue)); if (name.Buffer) NdisFreeString(name); return status; }
UCHAR LtRegGetNodeId( IN NDIS_HANDLE ConfigHandle ) /*++ Routine Description: This routine determines the last NodeId used by the card. Arguments: ConfigHandle : The handle to the configuration database Return Value: Returns the last valid NodeId used by the card. If we find that the value stored in the configuration info is not valid, then the suggested NodeId is returned. --*/ { NDIS_STATUS Status; PNDIS_CONFIGURATION_PARAMETER Parameter; NDIS_STRING Keyword = LT_REG_KEY_NODE_ID_STRING; UCHAR NodeId = 0; NdisReadConfiguration( &Status, &Parameter, ConfigHandle, &Keyword, NdisParameterInteger); if (Status == NDIS_STATUS_SUCCESS) { NodeId = (UCHAR)Parameter->ParameterData.IntegerData; if ((NodeId < LT_NODE_ID_MIN) || (NodeId > LT_NODE_ID_MAX)) { NodeId = 0; } } return(NodeId); }
NDIS_STATUS LtRegGetBusType( IN NDIS_HANDLE ConfigHandle, OUT PNDIS_INTERFACE_TYPE BusType ) /*++ Routine Description: This routine determines the type of bus the card is installed on Arguments: ConfigHandle : The handle to the configuration database BusType : On return, the bus type is stored here Return Value: NDIS_STATUS_SUCCESS : if successfully read from the config database NDIS_STATUS_FAILURE : if unable to find the information in the config database --*/ { NDIS_STATUS Status; PNDIS_CONFIGURATION_PARAMETER Parameter; NDIS_STRING Keyword = LT_REG_KEY_BUS_TYPE_STRING; NdisReadConfiguration( &Status, &Parameter, ConfigHandle, &Keyword, NdisParameterInteger); if (Status == NDIS_STATUS_SUCCESS) { *BusType = (UINT)Parameter->ParameterData.IntegerData; } return(Status); }
UINT LtRegGetBusNumber( IN NDIS_HANDLE ConfigHandle ) /*++ Routine Description: This routine determines the bus number the card is installed on Arguments: ConfigHandle : The handle to the configuration database Return Value: Returns the bus number the card is on. If we do not find the relevant information in the database, then 0 is returned. --*/ { NDIS_STATUS Status; PNDIS_CONFIGURATION_PARAMETER Parameter; UINT BusNumber = 0; NDIS_STRING Keyword = LT_REG_KEY_BUS_NUMBER_STRING; NdisReadConfiguration( &Status, &Parameter, ConfigHandle, &Keyword, NdisParameterInteger); if (Status == NDIS_STATUS_SUCCESS) { BusNumber = (UINT)Parameter->ParameterData.IntegerData; } return(BusNumber); }
//----------------------------------------------------------------------------- // 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; }
VOID natpBindAdapter( OUT PNDIS_STATUS Status, IN NDIS_HANDLE BindContext, IN PNDIS_STRING DeviceName, IN PVOID SystemSpecific1, IN PVOID SystemSpecific2 ) { NDIS_HANDLE ConfigHandle = NULL; PNDIS_CONFIGURATION_PARAMETER Param; NDIS_STRING DeviceStr = UPPER_BINDINGS; PFILTER_ADAPTER pAdapt = NULL; NDIS_STATUS Sts; UINT MediumIndex, i; ULONG TotalSize; WCHAR DevicePrefix[] = L"\\Device\\"; UNREFERENCED_PARAMETER(BindContext); UNREFERENCED_PARAMETER(SystemSpecific2); __try{ NdisOpenProtocolConfiguration( Status, &ConfigHandle, SystemSpecific1 ); if (*Status != NDIS_STATUS_SUCCESS) __leave; NdisReadConfiguration( Status, &Param, ConfigHandle, &DeviceStr, NdisParameterString ); if (*Status != NDIS_STATUS_SUCCESS) __leave; TotalSize = sizeof(FILTER_ADAPTER) + Param->ParameterData.StringData.MaximumLength + DeviceName->MaximumLength; NdisAllocateMemoryWithTag(&pAdapt, TotalSize, NAT_TAG); if (NULL == pAdapt){ *Status = NDIS_STATUS_RESOURCES; __leave; } NdisZeroMemory(pAdapt, TotalSize); pAdapt->DeviceName.MaximumLength = Param->ParameterData.StringData.MaximumLength; pAdapt->DeviceName.Length = Param->ParameterData.StringData.Length; pAdapt->DeviceName.Buffer = (PWCHAR)((ULONG_PTR)pAdapt + sizeof(FILTER_ADAPTER)); NdisMoveMemory( pAdapt->DeviceName.Buffer, Param->ParameterData.StringData.Buffer, Param->ParameterData.StringData.MaximumLength ); if(sizeof(DevicePrefix) >= DeviceName->Length){ }else{ pAdapt->RootDeviceName.MaximumLength = DeviceName->MaximumLength; pAdapt->RootDeviceName.Length = DeviceName->Length - sizeof(DevicePrefix) + sizeof(WCHAR); pAdapt->RootDeviceName.Buffer = (PWCHAR)((ULONG_PTR)pAdapt + sizeof(FILTER_ADAPTER) + Param->ParameterData.StringData.MaximumLength); NdisMoveMemory( pAdapt->RootDeviceName.Buffer, DeviceName->Buffer + sizeof(DevicePrefix)/sizeof(WCHAR) - 1, DeviceName->MaximumLength - sizeof(DevicePrefix)/sizeof(WCHAR) + 1 ); } NdisInitializeEvent(&pAdapt->Event); NdisAllocateSpinLock(&pAdapt->Lock); natInitControlBlock(&pAdapt->ctrl); NdisAllocatePacketPoolEx( Status, &pAdapt->SndPP1, MIN_PACKET_POOL_SIZE, MAX_PACKET_POOL_SIZE, PROTOCOL_RESERVED_SIZE_IN_PACKET ); if (*Status != NDIS_STATUS_SUCCESS) __leave; NdisAllocatePacketPoolEx( Status, &pAdapt->SndPP2, MIN_PACKET_POOL_SIZE, MAX_PACKET_POOL_SIZE, PROTOCOL_RESERVED_SIZE_IN_PACKET ); if (*Status != NDIS_STATUS_SUCCESS) __leave; NdisAllocateBufferPool( Status, &pAdapt->SndBP, MIN_PACKET_POOL_SIZE ); if ( *Status != NDIS_STATUS_SUCCESS ) __leave; NdisAllocatePacketPoolEx( Status, &pAdapt->RcvPP1, MIN_PACKET_POOL_SIZE, MAX_PACKET_POOL_SIZE - MIN_PACKET_POOL_SIZE, PROTOCOL_RESERVED_SIZE_IN_PACKET ); if (*Status != NDIS_STATUS_SUCCESS) __leave; NdisAllocatePacketPoolEx( Status, &pAdapt->RcvPP2, MIN_PACKET_POOL_SIZE, MAX_PACKET_POOL_SIZE - MIN_PACKET_POOL_SIZE, PROTOCOL_RESERVED_SIZE_IN_PACKET ); if (*Status != NDIS_STATUS_SUCCESS) __leave; NdisAllocateBufferPool( Status, &pAdapt->RcvBP, MIN_PACKET_POOL_SIZE ); if ( *Status != NDIS_STATUS_SUCCESS ) __leave; NdisOpenAdapter( Status, &Sts, &pAdapt->BindingHandle, &MediumIndex, MediumArray, sizeof(MediumArray)/sizeof(NDIS_MEDIUM), ProtHandle, pAdapt, DeviceName, 0,NULL ); if (*Status == NDIS_STATUS_PENDING){ NdisWaitEvent(&pAdapt->Event, 0); *Status = pAdapt->Status; } if (*Status != NDIS_STATUS_SUCCESS) __leave; pAdapt->Medium = MediumArray[MediumIndex]; pAdapt->MiniportInitPending = TRUE; NdisInitializeEvent(&pAdapt->MiniportInitEvent); *Status = NdisIMInitializeDeviceInstanceEx( DriverHandle, &pAdapt->DeviceName, pAdapt ); if (*Status != NDIS_STATUS_SUCCESS) __leave; StartQueryInfo( pAdapt ); } __finally{ } if (ConfigHandle != NULL) NdisCloseConfiguration(ConfigHandle); if(NDIS_STATUS_SUCCESS != *Status){ if (pAdapt != NULL){ if (pAdapt->BindingHandle != NULL){ NDIS_STATUS LocalStatus; NdisResetEvent(&pAdapt->Event); NdisCloseAdapter(&LocalStatus, pAdapt->BindingHandle); pAdapt->BindingHandle = NULL; if (LocalStatus == NDIS_STATUS_PENDING){ NdisWaitEvent(&pAdapt->Event, 0); LocalStatus = pAdapt->Status; } } natFreeAllItems(&pAdapt->ctrl); natFreeAllFwSessionsAndRules(&pAdapt->ctrl); for(i = 0;i<FLT_FW_SESSION_HASH_TBL_SZ;i++) NdisFreeSpinLock(pAdapt->ctrl.FwSessionLocks + i); NdisFreeSpinLock(&pAdapt->ctrl.IcmpRuleLock); NdisFreeSpinLock(&pAdapt->ctrl.UdpRuleLock); NdisFreeSpinLock(&pAdapt->ctrl.TcpRuleLock); natmFreeAllPacketPools(pAdapt); NdisFreeSpinLock(&pAdapt->Lock); NdisFreeMemory(pAdapt, 0, 0); pAdapt = NULL; } } }
VOID PtBindAdapter( OUT PNDIS_STATUS Status, IN NDIS_HANDLE BindContext, IN PNDIS_STRING DeviceName, IN PVOID SystemSpecific1, IN PVOID SystemSpecific2 ) /*++ Routine Description: Called by NDIS to bind to a miniport below. Arguments: Status - Return status of bind here. BindContext - Can be passed to NdisCompleteBindAdapter if this call is pended. DeviceName - Device name to bind to. This is passed to NdisOpenAdapter. SystemSpecific1 - Can be passed to NdisOpenProtocolConfiguration to read per-binding information SystemSpecific2 - Unused Return Value: NDIS_STATUS_PENDING if this call is pended. In this case call NdisCompleteBindAdapter to complete. Anything else Completes this call synchronously --*/ { NDIS_HANDLE ConfigHandle = NULL; PNDIS_CONFIGURATION_PARAMETER Param; NDIS_STRING DeviceStr = NDIS_STRING_CONST("UpperBindings"); PADAPT pAdapt = NULL; NDIS_STATUS Sts; UINT MediumIndex; ULONG TotalSize; PNDIS_CONFIGURATION_PARAMETER BundleParam; NDIS_STRING BundleStr = NDIS_STRING_CONST("BundleId"); NDIS_STATUS BundleStatus; DBGPRINT(("==> Protocol BindAdapter\n")); do { // // Access the configuration section for our binding-specific // parameters. // NdisOpenProtocolConfiguration(Status, &ConfigHandle, SystemSpecific1); if (*Status != NDIS_STATUS_SUCCESS) { break; } // // Read the "UpperBindings" reserved key that contains a list // of device names representing our miniport instances corresponding // to this lower binding. Since this is a 1:1 IM driver, this key // contains exactly one name. // // If we want to implement a N:1 mux driver (N adapter instances // over a single lower binding), then UpperBindings will be a // MULTI_SZ containing a list of device names - we would loop through // this list, calling NdisIMInitializeDeviceInstanceEx once for // each name in it. // NdisReadConfiguration(Status, &Param, ConfigHandle, &DeviceStr, NdisParameterString); if (*Status != NDIS_STATUS_SUCCESS) { break; } // // Allocate memory for the Adapter structure. This represents both the // protocol context as well as the adapter structure when the miniport // is initialized. // // In addition to the base structure, allocate space for the device // instance string. // TotalSize = sizeof(ADAPT) + Param->ParameterData.StringData.MaximumLength; NdisAllocateMemoryWithTag(&pAdapt, TotalSize, TAG); if (pAdapt == NULL) { *Status = NDIS_STATUS_RESOURCES; break; } // // Initialize the adapter structure. We copy in the IM device // name as well, because we may need to use it in a call to // NdisIMCancelInitializeDeviceInstance. The string returned // by NdisReadConfiguration is active (i.e. available) only // for the duration of this call to our BindAdapter handler. // NdisZeroMemory(pAdapt, TotalSize); pAdapt->DeviceName.MaximumLength = Param->ParameterData.StringData.MaximumLength; pAdapt->DeviceName.Length = Param->ParameterData.StringData.Length; pAdapt->DeviceName.Buffer = (PWCHAR)((ULONG_PTR)pAdapt + sizeof(ADAPT)); NdisMoveMemory(pAdapt->DeviceName.Buffer, Param->ParameterData.StringData.Buffer, Param->ParameterData.StringData.MaximumLength); NdisInitializeEvent(&pAdapt->Event); // // Allocate a packet pool for sends. We need this to pass sends down. // We cannot use the same packet descriptor that came down to our send // handler (see also NDIS 5.1 packet stacking). // NdisAllocatePacketPoolEx(Status, &pAdapt->SendPacketPoolHandle, MIN_PACKET_POOL_SIZE, MAX_PACKET_POOL_SIZE - MIN_PACKET_POOL_SIZE, sizeof(SEND_RSVD)); if (*Status != NDIS_STATUS_SUCCESS) { break; } // // Allocate a packet pool for receives. We need this to indicate receives. // Same consideration as sends (see also NDIS 5.1 packet stacking). // NdisAllocatePacketPoolEx(Status, &pAdapt->RecvPacketPoolHandle, MIN_PACKET_POOL_SIZE, MAX_PACKET_POOL_SIZE - MIN_PACKET_POOL_SIZE, PROTOCOL_RESERVED_SIZE_IN_PACKET); if (*Status != NDIS_STATUS_SUCCESS) { break; } // // Now open the adapter below and complete the initialization // NdisOpenAdapter(Status, &Sts, &pAdapt->BindingHandle, &MediumIndex, MediumArray, sizeof(MediumArray)/sizeof(NDIS_MEDIUM), ProtHandle, pAdapt, DeviceName, 0, NULL); if (*Status == NDIS_STATUS_PENDING) { NdisWaitEvent(&pAdapt->Event, 0); *Status = pAdapt->Status; } if (*Status != NDIS_STATUS_SUCCESS) { break; } pAdapt->Medium = MediumArray[MediumIndex]; // // Now ask NDIS to initialize our miniport (upper) edge. // Set the flag below to synchronize with a possible call // to our protocol Unbind handler that may come in before // our miniport initialization happens. // pAdapt->MiniportInitPending = TRUE; NdisInitializeEvent(&pAdapt->MiniportInitEvent); *Status = NdisIMInitializeDeviceInstanceEx(DriverHandle, &pAdapt->DeviceName, pAdapt); if (*Status != NDIS_STATUS_SUCCESS) { DBGPRINT(("BindAdapter: Adapt %p, IMInitializeDeviceInstance error %x\n", pAdapt, *Status)); break; } } while(FALSE); // // Close the configuration handle now - see comments above with // the call to NdisIMInitializeDeviceInstanceEx. // if (ConfigHandle != NULL) { NdisCloseConfiguration(ConfigHandle); } if (*Status != NDIS_STATUS_SUCCESS) { if (pAdapt != NULL) { if (pAdapt->BindingHandle != NULL) { NDIS_STATUS LocalStatus; // // Close the binding we opened above. // NdisCloseAdapter(&LocalStatus, pAdapt->BindingHandle); pAdapt->BindingHandle = NULL; if (LocalStatus == NDIS_STATUS_PENDING) { NdisWaitEvent(&pAdapt->Event, 0); LocalStatus = pAdapt->Status; } } if (pAdapt->SendPacketPoolHandle != NULL) { NdisFreePacketPool(pAdapt->SendPacketPoolHandle); } if (pAdapt->RecvPacketPoolHandle != NULL) { NdisFreePacketPool(pAdapt->RecvPacketPoolHandle); } NdisFreeMemory(pAdapt, sizeof(ADAPT), 0); pAdapt = NULL; } } DBGPRINT(("<== Protocol BindAdapter: pAdapt %p, Status %x\n", pAdapt, *Status)); }
// 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; }
NDIS_STATUS tapReadConfiguration(__in PTAP_ADAPTER_CONTEXT Adapter) { NDIS_STATUS status = NDIS_STATUS_SUCCESS; NDIS_CONFIGURATION_OBJECT configObject; NDIS_HANDLE configHandle; DEBUGP(("[TAP] --> tapReadConfiguration\n")); // // Setup defaults in case configuration cannot be opened. // Adapter->MtuSize = ETHERNET_MTU; Adapter->MediaStateAlwaysConnected = FALSE; Adapter->LogicalMediaState = FALSE; Adapter->AllowNonAdmin = FALSE; // // Open the registry for this adapter to read advanced // configuration parameters stored by the INF file. // NdisZeroMemory(&configObject, sizeof(configObject)); { C_ASSERT(sizeof(configObject) >= NDIS_SIZEOF_CONFIGURATION_OBJECT_REVISION_1); } configObject.Header.Type = NDIS_OBJECT_TYPE_CONFIGURATION_OBJECT; configObject.Header.Size = NDIS_SIZEOF_CONFIGURATION_OBJECT_REVISION_1; configObject.Header.Revision = NDIS_CONFIGURATION_OBJECT_REVISION_1; configObject.NdisHandle = Adapter->MiniportAdapterHandle; configObject.Flags = 0; status = NdisOpenConfigurationEx(&configObject, &configHandle); // Read on the opened configuration handle. if (status == NDIS_STATUS_SUCCESS) { NDIS_CONFIGURATION_PARAMETER *configParameter; NDIS_STRING mkey = NDIS_STRING_CONST("NetCfgInstanceId"); // // Read NetCfgInstanceId from the registry. // ------------------------------------ // NetCfgInstanceId is required to create device and associated // symbolic link for the adapter device. // // NetCfgInstanceId is a GUID string provided by NDIS that identifies // the adapter instance. An example is: // // NetCfgInstanceId={410EB49D-2381-4FE7-9B36-498E22619DF0} // // Other names are derived from NetCfgInstanceId. For example, MiniportName: // // MiniportName=\DEVICE\{410EB49D-2381-4FE7-9B36-498E22619DF0} // NdisReadConfiguration(&status, &configParameter, configHandle, &mkey, NdisParameterString); if (status == NDIS_STATUS_SUCCESS) { if (configParameter->ParameterType == NdisParameterString && configParameter->ParameterData.StringData.Length <= sizeof(Adapter->NetCfgInstanceIdBuffer) - sizeof(WCHAR)) { DEBUGP(("[TAP] NdisReadConfiguration (NetCfgInstanceId=%wZ)\n", &configParameter->ParameterData.StringData)); // Save NetCfgInstanceId as UNICODE_STRING. Adapter->NetCfgInstanceId.Length = Adapter->NetCfgInstanceId.MaximumLength = configParameter->ParameterData.StringData.Length; Adapter->NetCfgInstanceId.Buffer = Adapter->NetCfgInstanceIdBuffer; NdisMoveMemory(Adapter->NetCfgInstanceId.Buffer, configParameter->ParameterData.StringData.Buffer, Adapter->NetCfgInstanceId.Length); // Save NetCfgInstanceId as ANSI_STRING as well. if (RtlUnicodeStringToAnsiString(&Adapter->NetCfgInstanceIdAnsi, &configParameter->ParameterData.StringData, TRUE) != STATUS_SUCCESS) { DEBUGP(("[TAP] NetCfgInstanceId ANSI name conversion failed\n")); status = NDIS_STATUS_RESOURCES; } } else { DEBUGP(("[TAP] NetCfgInstanceId has invalid type\n")); status = NDIS_STATUS_INVALID_DATA; } } else { DEBUGP(("[TAP] NetCfgInstanceId failed\n")); status = NDIS_STATUS_INVALID_DATA; } if (status == NDIS_STATUS_SUCCESS) { NDIS_STATUS localStatus; // Use default if these fail. NDIS_CONFIGURATION_PARAMETER *configParameter; NDIS_STRING mtuKey = NDIS_STRING_CONST("MTU"); NDIS_STRING mediaStatusKey = NDIS_STRING_CONST("MediaStatus"); #if ENABLE_NONADMIN NDIS_STRING allowNonAdminKey = NDIS_STRING_CONST("AllowNonAdmin"); #endif // Read MTU from the registry. NdisReadConfiguration(&localStatus, &configParameter, configHandle, &mtuKey, NdisParameterInteger); if (localStatus == NDIS_STATUS_SUCCESS) { if (configParameter->ParameterType == NdisParameterInteger) { int mtu = configParameter->ParameterData.IntegerData; if (mtu == 0) { mtu = ETHERNET_MTU; } // Sanity check if (mtu < MINIMUM_MTU) { mtu = MINIMUM_MTU; } else if (mtu > MAXIMUM_MTU) { mtu = MAXIMUM_MTU; } Adapter->MtuSize = mtu; } } DEBUGP(("[%s] Using MTU %d\n", MINIPORT_INSTANCE_ID(Adapter), Adapter->MtuSize)); // Read MediaStatus setting from registry. NdisReadConfiguration(&localStatus, &configParameter, configHandle, &mediaStatusKey, NdisParameterInteger); if (localStatus == NDIS_STATUS_SUCCESS) { if (configParameter->ParameterType == NdisParameterInteger) { if (configParameter->ParameterData.IntegerData == 0) { // Connect state is appplication controlled. DEBUGP(("[%s] Initial MediaConnectState: Application Controlled\n", MINIPORT_INSTANCE_ID(Adapter))); Adapter->MediaStateAlwaysConnected = FALSE; Adapter->LogicalMediaState = FALSE; } else { // Connect state is always connected. DEBUGP(("[%s] Initial MediaConnectState: Always Connected\n", MINIPORT_INSTANCE_ID(Adapter))); Adapter->MediaStateAlwaysConnected = TRUE; Adapter->LogicalMediaState = TRUE; } } } // Read MAC PermanentAddress setting from registry. tapReadPermanentAddress(Adapter, configHandle, Adapter->PermanentAddress); DEBUGP(("[%s] Using MAC PermanentAddress %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n", MINIPORT_INSTANCE_ID(Adapter), Adapter->PermanentAddress[0], Adapter->PermanentAddress[1], Adapter->PermanentAddress[2], Adapter->PermanentAddress[3], Adapter->PermanentAddress[4], Adapter->PermanentAddress[5])); // Now seed the current MAC address with the permanent address. ETH_COPY_NETWORK_ADDRESS(Adapter->CurrentAddress, Adapter->PermanentAddress); DEBUGP(("[%s] Using MAC CurrentAddress %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n", MINIPORT_INSTANCE_ID(Adapter), Adapter->CurrentAddress[0], Adapter->CurrentAddress[1], Adapter->CurrentAddress[2], Adapter->CurrentAddress[3], Adapter->CurrentAddress[4], Adapter->CurrentAddress[5])); // Read optional AllowNonAdmin setting from registry. #if ENABLE_NONADMIN NdisReadConfiguration(&localStatus, &configParameter, configHandle, &allowNonAdminKey, NdisParameterInteger); if (localStatus == NDIS_STATUS_SUCCESS) { if (configParameter->ParameterType == NdisParameterInteger) { Adapter->AllowNonAdmin = TRUE; } } #endif } // Close the configuration handle. NdisCloseConfiguration(configHandle); } else { DEBUGP(("[TAP] Couldn't open adapter registry\n")); } DEBUGP(("[TAP] <-- tapReadConfiguration; status = %8.8X\n", status)); return status; }
NDIS_STATUS LtRegGetIoBaseAddr( OUT PUINT IoBaseAddress, IN NDIS_HANDLE NdisConfigHandle, IN NDIS_HANDLE ConfigHandle, IN NDIS_INTERFACE_TYPE BusType ) /*++ Routine Description: This routine determines the port addresses used to communicate with the card. Arguments: IoBaseAddress : On return, the I/O port address is stored here ConfigHandle : The handle to the configuration database SlotNumber : For MCA machines, the indicates the slot the card is in BusType : The type of bus the card is located on Return Value: NDIS_STATUS_SUCCESS : if successful NDIS_STATUS_ADAPTER_NOT_FOUND : if running on a MCA machine and the adapter cannot be located NDIS_STATUS_BAD_CHARACTERISTICS : if the I/O base is not within the legal range --*/ { NDIS_MCA_POS_DATA McaData; NDIS_STATUS Status; PNDIS_CONFIGURATION_PARAMETER Parameter; NDIS_STRING Keyword = LT_REG_KEY_IO_BASE_ADDRESS_STRING; UINT SlotNumber = 0; // If BusType is NdisInterfaceMca, then we read the MCA POS info to // get our parameters. Otherwise, we just read the registry. if (BusType == NdisInterfaceMca) { NdisReadMcaPosInformation( &Status, NdisConfigHandle, &SlotNumber, &McaData); // *IoBaseAddress = (UINT)(McaData.PosData2 | (McaData.PosData3 << 8)); *IoBaseAddress = LT_DECODE_ADDR_FROM_POSDATA(McaData); DBGPRINT(DBG_COMP_REGISTRY, DBG_LEVEL_FATAL, ("LtRegGetIoBaseAddr: Base %lx. %lx.%lx.%lx.%lx, Id - %lx\n", *IoBaseAddress, McaData.PosData1, McaData.PosData2, McaData.PosData3, McaData.PosData4, McaData.AdapterId)); if ((Status != NDIS_STATUS_SUCCESS) || (McaData.AdapterId != LT_MCA_POS_ID)) { Status = NDIS_STATUS_ADAPTER_NOT_FOUND; } } else { NdisReadConfiguration( &Status, &Parameter, ConfigHandle, &Keyword, NdisParameterHexInteger); if (Status == NDIS_STATUS_SUCCESS) { *IoBaseAddress = (UINT)Parameter->ParameterData.IntegerData; } } if ((Status == NDIS_STATUS_SUCCESS) && ((*IoBaseAddress < LT_IO_BASE_ADDRESS_MIN) || (*IoBaseAddress > LT_IO_BASE_ADDRESS_MAX))) { DBGPRINT(DBG_COMP_REGISTRY, DBG_LEVEL_FATAL, ("LtRegGetIoBaseAddr: invalid value found for %s\n", LT_REG_KEY_IO_BASE_ADDRESS)); Status = NDIS_STATUS_BAD_CHARACTERISTICS; } return(Status); }
VOID NdisReadNetworkAddress( OUT PNDIS_STATUS Status, OUT PVOID * NetworkAddress, OUT PUINT NetworkAddressLength, IN NDIS_HANDLE ConfigurationHandle ) /*++ Routine Description: This routine is used to read the "NetworkAddress" parameter from the configuration database. It reads the value as a string separated by hyphens, then converts it to a binary array and stores the result. Arguments: Status - Returns the status of the request. NetworkAddress - Returns a pointer to the address. NetworkAddressLength - Returns the length of the address. ConfigurationHandle - Handle returned by NdisOpenConfiguration. Points to the parameter subkey. Return Value: None. --*/ { NDIS_STRING NetAddrStr = NDIS_STRING_CONST("NetworkAddress"); PNDIS_CONFIGURATION_PARAMETER ParameterValue; NTSTATUS NtStatus; UCHAR ConvertArray[3]; PWSTR CurrentReadLoc; PWSTR AddressEnd; PUCHAR CurrentWriteLoc; UINT TotalBytesRead; ULONG TempUlong; ULONG AddressLength; ASSERT (KeGetCurrentIrql() < DISPATCH_LEVEL); do { // // First read the "NetworkAddress" from the registry // NdisReadConfiguration(Status, &ParameterValue, ConfigurationHandle, &NetAddrStr, NdisParameterString); if ((*Status != NDIS_STATUS_SUCCESS) || (ParameterValue->ParameterType != NdisParameterString)) { *Status = NDIS_STATUS_FAILURE; break; } // // If there is not an address specified then exit now. // if (0 == ParameterValue->ParameterData.StringData.Length) { *Status = NDIS_STATUS_FAILURE; break; } // // Now convert the address to binary (we do this // in-place, since this allows us to use the memory // already allocated which is automatically freed // by NdisCloseConfiguration). // ConvertArray[2] = '\0'; CurrentReadLoc = (PWSTR)ParameterValue->ParameterData.StringData.Buffer; CurrentWriteLoc = (PUCHAR)CurrentReadLoc; TotalBytesRead = ParameterValue->ParameterData.StringData.Length; AddressEnd = CurrentReadLoc + (TotalBytesRead / sizeof(WCHAR)); AddressLength = 0; while ((CurrentReadLoc+2) <= AddressEnd) { // // Copy the current two-character value into ConvertArray // ConvertArray[0] = (UCHAR)(*(CurrentReadLoc++)); ConvertArray[1] = (UCHAR)(*(CurrentReadLoc++)); // // Convert it to a Ulong and update // NtStatus = RtlCharToInteger(ConvertArray, 16, &TempUlong); if (!NT_SUCCESS(NtStatus)) { *Status = NDIS_STATUS_FAILURE; break; } *(CurrentWriteLoc++) = (UCHAR)TempUlong; ++AddressLength; // // If the next character is a hyphen, skip it. // if (CurrentReadLoc < AddressEnd) { if (*CurrentReadLoc == (WCHAR)L'-') { ++CurrentReadLoc; } } } if (NtStatus != NDIS_STATUS_SUCCESS) break; *Status = STATUS_SUCCESS; *NetworkAddress = ParameterValue->ParameterData.StringData.Buffer; *NetworkAddressLength = AddressLength; if (AddressLength == 0) { *Status = NDIS_STATUS_FAILURE; } } while (FALSE); }
VOID Sta11ReadRegistryConfiguration( __in PSTATION pStation, __in NDIS_HANDLE hConfigurationHandle ) { NDIS_STATUS ndisStatus = NDIS_STATUS_SUCCESS; ULONG i, ValueRead; PUCHAR pucDestination; PMP_REG_ENTRY pRegEntry; PNDIS_CONFIGURATION_PARAMETER Parameter = NULL; // // If the station wants to read/store any parameters from the registry // we would do it here. Information that we may want to load from // registry includes tuning parameters for roaming, connecting, scan, etc // for(i = 0; i < STA_NUM_REG_PARAMS; i++) { // // Get the registry entry we will be reading // pRegEntry= &STARegTable[i]; // // Figure out where in the station/reginfo structure this value will be placed // pucDestination = (PUCHAR) &(pStation->RegInfo) + pRegEntry->FieldOffset; // // Read this entry from the registry. All parameters under NT are DWORDs // NdisReadConfiguration( &ndisStatus, &Parameter, hConfigurationHandle, &pRegEntry->RegName, NdisParameterInteger ); if (ndisStatus == NDIS_STATUS_SUCCESS) { if(Parameter->ParameterData.IntegerData < pRegEntry->Min || Parameter->ParameterData.IntegerData > pRegEntry->Max) { MpTrace(COMP_INIT_PNP, DBG_SERIOUS, ("A bad value %d read from registry. Reverting to default value %d", Parameter->ParameterData.IntegerData, pRegEntry->Default )); ValueRead = pRegEntry->Default; } else { ValueRead = Parameter->ParameterData.IntegerData; } } else { MpTrace(COMP_INIT_PNP, DBG_NORMAL, ("Unable to read from registry. Reverting to default value: %d\n", pRegEntry->Default )); ValueRead = pRegEntry->Default; } // // Moving the registry values in the adapter data structure // switch(pRegEntry->FieldSize) { case 1: *((PUCHAR) pucDestination) = (UCHAR) ValueRead; break; case 2: *((PUSHORT) pucDestination) = (USHORT) ValueRead; break; case 4: *((PULONG) pucDestination) = (ULONG) ValueRead; break; default: MpTrace(COMP_INIT_PNP, DBG_SERIOUS, ("Bogus field size %d\n", pRegEntry->FieldSize)); break; } } }
/* 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); }
// 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, ¶m, 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 = ¶m->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, ¶m, 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, ¶m, 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; }
/* ************************************************************************* * 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, ®KeyPortString, 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, ®KeyIRQString, 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, ®KeyIOString, 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, ®KeyIRTransceiverString, 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; }
//----------------------------------------------------------------------------- // 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; char regName[32]; 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; strcpy(regName, pParam->RegAscName); /* * 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 return NDIS_STATUS_SUCCESS; }