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; }
/********************************************************** Implements opening of adapter-specific configuration Parameters: Return value: NDIS_HANDLE Handle of open configuration NULL on error ***********************************************************/ NDIS_HANDLE ParaNdis_OpenNICConfiguration(PARANDIS_ADAPTER *pContext) { NDIS_CONFIGURATION_OBJECT co; NDIS_HANDLE cfg; 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 = sizeof(co); co.Flags = 0; co.NdisHandle = pContext->MiniportHandle; status = NdisOpenConfigurationEx(&co, &cfg); if (status != NDIS_STATUS_SUCCESS) cfg = NULL; DEBUG_EXIT_STATUS(status == NDIS_STATUS_SUCCESS ? 2 : 0, status); return cfg; }
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; }
// 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; UINT64 speed; BOOL keep; NDIS_CONFIGURATION_OBJECT config_obj; // Get the Config handle NeoZero(&config_obj, sizeof(config_obj)); config_obj.Header.Type = NDIS_OBJECT_TYPE_CONFIGURATION_OBJECT; config_obj.Header.Revision = NDIS_CONFIGURATION_OBJECT_REVISION_1; config_obj.Header.Size = NDIS_SIZEOF_CONFIGURATION_OBJECT_REVISION_1; config_obj.NdisHandle = ctx->NdisMiniport; ret = NdisOpenConfigurationEx(&config_obj, &config); 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 = (UINT64)param->ParameterData.IntegerData * 1000000ULL; } 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; }