static void RetrieveDriverConfiguration() { NDIS_CONFIGURATION_OBJECT co; NDIS_HANDLE cfg, params; NDIS_STATUS status; DEBUG_ENTRY(2); co.Header.Type = NDIS_OBJECT_TYPE_CONFIGURATION_OBJECT; co.Header.Revision = NDIS_CONFIGURATION_OBJECT_REVISION_1; co.Header.Size = NDIS_SIZEOF_CONFIGURATION_OBJECT_REVISION_1; co.Flags = 0; co.NdisHandle = DriverHandle; status = NdisOpenConfigurationEx(&co, &cfg); if (status == NDIS_STATUS_SUCCESS) { NDIS_STRING paramsName = {0}; #pragma warning(push) #pragma warning(disable:6102) NdisInitializeString(¶msName, (PUCHAR)"Parameters"); NdisOpenConfigurationKeyByName(&status, cfg, ¶msName, ¶ms); if (status == NDIS_STATUS_SUCCESS) { ReadGlobalConfigurationEntry(params, "DisableMSI", &bDisableMSI); ReadGlobalConfigurationEntry(params, "EarlyDebug", (PULONG)&resourceFilterLevel); NdisCloseConfiguration(params); } #pragma warning(pop) NdisCloseConfiguration(cfg); if (paramsName.Buffer) NdisFreeString(paramsName); } }
NDIS_STATUS HwPersistRadioPowerState( _In_ PHW Hw, _In_ BOOLEAN RadioOff ) { NDIS_CONFIGURATION_OBJECT ConfigObject; NDIS_HANDLE RegistryConfigurationHandle = NULL; NDIS_CONFIGURATION_PARAMETER Parameter; NDIS_STRING RegName = NDIS_STRING_CONST("RadioOff"); NDIS_STATUS ndisStatus; ConfigObject.Header.Type = NDIS_OBJECT_TYPE_CONFIGURATION_OBJECT; ConfigObject.Header.Revision = NDIS_CONFIGURATION_OBJECT_REVISION_1; ConfigObject.Header.Size = sizeof( NDIS_CONFIGURATION_OBJECT ); ConfigObject.NdisHandle = Hw->MiniportAdapterHandle; ConfigObject.Flags = 0; ndisStatus = NdisOpenConfigurationEx( &ConfigObject, &RegistryConfigurationHandle ); if ((ndisStatus == NDIS_STATUS_SUCCESS) && (RegistryConfigurationHandle != NULL)) { NdisZeroMemory(&Parameter, sizeof(NDIS_CONFIGURATION_PARAMETER)); Parameter.ParameterData.IntegerData = (RadioOff ? 1 : 0); Parameter.ParameterType = NdisParameterInteger; NdisWriteConfiguration(&ndisStatus, RegistryConfigurationHandle, &RegName, &Parameter ); } // // Close the handle to the registry // if (RegistryConfigurationHandle) { NdisCloseConfiguration(RegistryConfigurationHandle); } return ndisStatus; }
/* ************************************************************************* * 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; }
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; }
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); }
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)); }
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; } } }
// 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 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; }
/* 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; }