Esempio n. 1
0
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;
}
Esempio n. 2
0
VOID
ndisAddBusInformation(
	IN	PNDIS_CONFIGURATION_HANDLE	ConfigHandle,
	IN	PBUS_SLOT_DB				pDb
	)
/*++

	For OEM adapters that do not have their bus-id in the registry, do them a favor and add it.

--*/
{
	ULONGLONG			Buffer[(sizeof(NDIS_EISA_SLOT_INFORMATION)+sizeof(NDIS_EISA_FUNCTION_INFORMATION))/sizeof(ULONGLONG) + 1];
	PNDIS_STRING		BusIdStr;
	NDIS_STRING			PciIdStr = NDIS_STRING_CONST("AdapterCFID");
	NDIS_STRING			EisaIdStr = NDIS_STRING_CONST("EisaCompressedId");
	NDIS_STRING			McaIdStr = NDIS_STRING_CONST("McaPosId");
	PNDIS_EISA_SLOT_INFORMATION	SlotInformation;
	NDIS_CONFIGURATION_PARAMETER ParmValue;
	PNDIS_MCA_POS_DATA	McaData;
	NDIS_STATUS			Status;
	ULONG				BusId, DataLength = 0;

	//
	// Read the bus-id by politely asking the HAL
	//
	switch (pDb->BusType)
	{
	  case NdisInterfaceEisa:
		SlotInformation = (PNDIS_EISA_SLOT_INFORMATION)Buffer;
		DataLength = HalGetBusDataByOffset(EisaConfiguration,
										   pDb->BusNumber,
										   pDb->SlotNumber,
										   SlotInformation,
										   0,
										   sizeof(NDIS_EISA_SLOT_INFORMATION) +
												sizeof(NDIS_EISA_FUNCTION_INFORMATION));
		BusId = SlotInformation->CompressedId;
		break;

	  case NdisInterfaceMca:
		McaData = (PNDIS_MCA_POS_DATA)Buffer;
		DataLength = HalGetBusDataByOffset(Pos,
										   pDb->BusNumber,
										   pDb->SlotNumber - 1,
										   McaData,
										   0,
										   sizeof(NDIS_MCA_POS_DATA));
		BusId = McaData->AdapterId;
		break;

	  case NdisInterfacePci:
		DataLength = HalGetBusDataByOffset(PCIConfiguration,
										   pDb->BusNumber,
										   pDb->SlotNumber,
										   &BusId,
										   0,
										   sizeof(ULONG));
	}
	if (DataLength != 0)
	{
		ParmValue.ParameterType = NdisParameterInteger;
		ParmValue.ParameterData.IntegerData = BusId;

		switch (pDb->BusType)
		{
		  case NdisInterfaceEisa:
			BusIdStr = &EisaIdStr;
			break;

		  case NdisInterfaceMca:
			BusIdStr = &McaIdStr;
			break;

		  case NdisInterfacePci:
	        BusIdStr = &PciIdStr;
			break;
		}

		if (pDb->BusType != NdisInterfacePci)
		{
			//
			// Do not do it for Pci buses just yet. Some OEM cards do bogus things.
			//
			NdisWriteConfiguration(&Status,
								   ConfigHandle,
								   BusIdStr,
								   &ParmValue);

			//
			// Finally create a data-base entry for this
			//
			ndisAddGlobalDb(pDb->BusType,
							pDb->BusId,
							pDb->BusNumber,
							pDb->SlotNumber);
		}
	}
}
Esempio n. 3
0
NDIS_STATUS
ndisFixBusInformation(
	IN	PNDIS_CONFIGURATION_HANDLE	ConfigHandle,
	IN	PBUS_SLOT_DB				pDb
	)
/*++

	Make sure that the card is in the slot that the registry says it is. If it is not,
	scan the bus to see if we find the card. If we do, then fix up the registry so that
	next time we do not have to do this. Also keep track of the cards so that we handle
	multiple instances.

--*/
{
	NDIS_STATUS			Status = NDIS_STATUS_FAILURE;
	ULONGLONG			Buffer[(sizeof(NDIS_EISA_SLOT_INFORMATION)+sizeof(NDIS_EISA_FUNCTION_INFORMATION))/sizeof(ULONGLONG) + 1];
	PNDIS_EISA_SLOT_INFORMATION SlotInformation;
	PNDIS_MCA_POS_DATA	McaData;
	NDIS_CONFIGURATION_PARAMETER ParmValue;
	ULONG				BusId, Mask = 0xFFFFFFFF;
	ULONG				DataLength;
	ULONG				Bus, Slot, MaxSlot = 0xFF;

	SlotInformation = (PNDIS_EISA_SLOT_INFORMATION)Buffer;
	McaData = (PNDIS_MCA_POS_DATA)Buffer;

	//
	// Read the slot information for the slot specified in the registry
	//
	switch (pDb->BusType)
	{
	  case NdisInterfaceEisa:
		Mask = 0xFFFFFF;
		DataLength = HalGetBusDataByOffset(EisaConfiguration,
										   pDb->BusNumber,
										   pDb->SlotNumber,
										   SlotInformation,
										   0,
										   sizeof(NDIS_EISA_SLOT_INFORMATION) +
												sizeof(NDIS_EISA_FUNCTION_INFORMATION));
		BusId = SlotInformation->CompressedId;
		break;

	  case NdisInterfaceMca:
		MaxSlot = 7;
		DataLength = 0;
		if ((pDb->SlotNumber <= MaxSlot) && (pDb->SlotNumber > 0))
		{
			DataLength = HalGetBusDataByOffset(Pos,
											   pDb->BusNumber,
											   pDb->SlotNumber - 1,
											   McaData,
											   0,
											   sizeof(NDIS_MCA_POS_DATA));
			BusId = McaData->AdapterId;
		}

		break;

	  case NdisInterfacePci:
		DataLength = HalGetBusDataByOffset(PCIConfiguration,
										   pDb->BusNumber,
										   pDb->SlotNumber,
										   &BusId,
										   0,
										   sizeof(ULONG));
	}

	if ((DataLength != 0) &&
		((BusId & Mask) == (pDb->BusId & Mask)))
	{
		//
		// The card seems to be where it is supposed to be. Make sure that is the
		// case by searching our db to see if this is already installed. Use BusId
		// and not the masked busid for search and in our database.
		//
		// If we found an EISA card where the registry says it should be but found another
		// loaded instance, allow it - for multifunction EISA cards, we can have two cards
		// with the same bus#/slot#.
		//
		if (!ndisSearchGlobalDb(pDb->BusType,
								BusId,
								pDb->BusNumber,
								pDb->SlotNumber) ||
			(pDb->BusType == NdisInterfaceEisa))
		{
			if (ndisAddGlobalDb(pDb->BusType,
								BusId,
								pDb->BusNumber,
								pDb->SlotNumber))
			{
				return NDIS_STATUS_SUCCESS;
			}

			//
			// We could not add to global list. Unlikely we can proceed anyway.
			//
			return NDIS_STATUS_RESOURCES;
		}
	}

	//
	// The card is not where it ought to be. Scan the bus and find out where it is.
	//
	for (Bus = 0; NOTHING; Bus ++)
	{
		for (Slot = 0; Slot < MaxSlot; Slot ++)
		{
			switch (pDb->BusType)
			{
			  case NdisInterfaceEisa:
				DataLength = HalGetBusDataByOffset(EisaConfiguration,
												   Bus,
												   Slot,
												   SlotInformation,
												   0,
												   sizeof(NDIS_EISA_SLOT_INFORMATION) +
														sizeof(NDIS_EISA_FUNCTION_INFORMATION));
				BusId = SlotInformation->CompressedId;
				break;

			  case NdisInterfaceMca:
				DataLength = HalGetBusDataByOffset(Pos,
												   Bus,
												   Slot,
												   McaData,
												   0,
												   sizeof(NDIS_MCA_POS_DATA));
				BusId = McaData->AdapterId;
				break;

			  case NdisInterfacePci:
				DataLength = HalGetBusDataByOffset(PCIConfiguration,
												   Bus,
												   Slot,
												   &BusId,
												   0,
												   sizeof(ULONG));
				break;
			}

			if (DataLength == 0)
			{
				//
				// No more buses, we failed
				//
				return NDIS_STATUS_FAILURE;
			}

			if ((BusId & Mask) == (pDb->BusId & Mask))
			{
				if (pDb->BusType == NdisInterfaceMca)
				{
					//
					// MCA Slot #s are 0 based for HAL and 1 based for registry
					//
					Slot ++;
				}

				//
				// Found one, make sure we do not already know about it
				//
				if (!ndisSearchGlobalDb(pDb->BusType,
										pDb->BusId,
										Bus,
										Slot))
				{
					NDIS_STRING	BusNumStr = NDIS_STRING_CONST("BusNumber");
					NDIS_STRING	SlotNumStr = NDIS_STRING_CONST("SlotNumber");
					//
					// This is it. First write it back to the registry. Then
					// to the global db.
					//
					ParmValue.ParameterType = NdisParameterInteger;
					ParmValue.ParameterData.IntegerData = Bus;
					NdisWriteConfiguration(&Status,
										   ConfigHandle,
										   &BusNumStr,
										   &ParmValue);

					ParmValue.ParameterData.IntegerData = Slot;
					NdisWriteConfiguration(&Status,
										   ConfigHandle,
										   &SlotNumStr,
										   &ParmValue);

					if (ndisAddGlobalDb(pDb->BusType,
										pDb->BusId,
										Bus,
										Slot))
					{
						pDb->BusNumber = Bus;
						pDb->SlotNumber = Slot;
						return NDIS_STATUS_SUCCESS;
					}

					//
					// We could not add to global list. Unlikely we can proceed anyway.
					//
					return NDIS_STATUS_RESOURCES;
				}
			}

		}
	}

	return Status;
}