Beispiel #1
0
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));
  }
}
Beispiel #2
0
NTSTATUS DriverEntry(
	IN PDRIVER_OBJECT DriverObject,
	IN PUNICODE_STRING RegistryPath
)
{
  NDIS_PROTOCOL_CHARACTERISTICS  ProtocolChar;

  UNICODE_STRING MacDriverName;
  UNICODE_STRING UnicodeDeviceName;

  PDEVICE_OBJECT DeviceObject = NULL;
  PDEVICE_EXTENSION DeviceExtension = NULL;

  NTSTATUS Status = STATUS_SUCCESS;
  NTSTATUS ErrorCode = STATUS_SUCCESS;
  NDIS_STRING ProtoName = NDIS_STRING_CONST("PacketDriver");

  ULONG          DevicesCreated=0;

  PWSTR          BindString;
  PWSTR          ExportString;

  PWSTR          BindStringSave;
  PWSTR          ExportStringSave;

  NDIS_HANDLE    NdisProtocolHandle;

  IF_LOUD(DbgPrint("\n\nPacket: DriverEntry\n");)
Beispiel #3
0
NTSTATUS NDIS_API DriverEntry(IN PDRIVER_OBJECT  DriverObject,
                              IN PUNICODE_STRING RegistryPath)

{
  // initialiae the driver

  NDIS_PROTOCOL_CHARACTERISTICS ProtocolChar;
  NDIS_STRING ProtoName = NDIS_STRING_CONST("EPACKET");
  NDIS_STATUS Status;


  // Because the driver can be loaded once for each Netcard on the system,
  // and because DriverEntry is called each time, we must ensure that
  // initialization is performed only once.
  if (GlobalDeviceExtension != NULL)
    return NDIS_STATUS_SUCCESS;
        
  NdisAllocateMemory((PVOID *)&GlobalDeviceExtension, sizeof(DEVICE_EXTENSION), 0, -1 );
  if (GlobalDeviceExtension == NULL)
    return NDIS_STATUS_RESOURCES;

  NdisZeroMemory((UCHAR*)GlobalDeviceExtension, sizeof(DEVICE_EXTENSION));
  NdisZeroMemory((UCHAR*)&ProtocolChar, sizeof(NDIS_PROTOCOL_CHARACTERISTICS));
  ProtocolChar.MajorNdisVersion            = 0x03;
  ProtocolChar.MinorNdisVersion            = 0x0a;
  ProtocolChar.Reserved                    = 0;
  ProtocolChar.OpenAdapterCompleteHandler  = PacketBindAdapterComplete;
  ProtocolChar.CloseAdapterCompleteHandler = PacketUnbindAdapterComplete;
  ProtocolChar.SendCompleteHandler         = PacketSendComplete;
  ProtocolChar.TransferDataCompleteHandler = PacketTransferDataComplete;
  ProtocolChar.ResetCompleteHandler        = PacketResetComplete;
  ProtocolChar.RequestCompleteHandler      = PacketRequestComplete;
  ProtocolChar.ReceiveHandler              = PacketReceiveIndicate;
  ProtocolChar.ReceiveCompleteHandler      = PacketReceiveComplete;
  ProtocolChar.StatusHandler               = PacketStatus;
  ProtocolChar.StatusCompleteHandler       = PacketStatusComplete;
  ProtocolChar.BindAdapterHandler          = PacketBindAdapter;
  ProtocolChar.UnbindAdapterHandler        = PacketUnbindAdapter;
  ProtocolChar.UnloadProtocolHandler       = PacketUnload;
  ProtocolChar.Name                        = ProtoName;
  
  NdisRegisterProtocol(&Status,
                       &GlobalDeviceExtension->NdisProtocolHandle,
                       &ProtocolChar,
                       sizeof(NDIS_PROTOCOL_CHARACTERISTICS));
  
  if (Status != NDIS_STATUS_SUCCESS) {
    NdisFreeMemory(GlobalDeviceExtension, sizeof(DEVICE_EXTENSION), 0);
    return Status;
  }
  
  // initialize open list
  InitializeListHead(&GlobalDeviceExtension->OpenList);
  
  // initialize global device extension
  GlobalDeviceExtension->DriverObject = DriverObject;
  
  return Status;
}
Beispiel #4
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;
}
Beispiel #5
0
NTSTATUS
DriverEntry(
    IN PDRIVER_OBJECT   pDriverObject,
    IN PUNICODE_STRING  pRegistryPath
    )
/*++

Routine Description:

    Called on loading. We create a device object to handle user-mode requests
    on, and register ourselves as a protocol with NDIS.

Arguments:

    pDriverObject - Pointer to driver object created by system.

    pRegistryPath - Pointer to the Unicode name of the registry path
        for this driver.

Return Value:

    NT Status code
    
--*/
{
    NDIS_PROTOCOL_DRIVER_CHARACTERISTICS   protocolChar = {0};
    NTSTATUS                        status = STATUS_SUCCESS;
    NDIS_STRING                     protoName = NDIS_STRING_CONST("NDISPROT");     
    UNICODE_STRING                  ntDeviceName;
    UNICODE_STRING                  win32DeviceName;
    BOOLEAN                         fSymbolicLink = FALSE;
    PDEVICE_OBJECT                  deviceObject = NULL;
    NDIS_HANDLE  ProtocolDriverContext={0};

    UNREFERENCED_PARAMETER(pRegistryPath);
	
    DEBUGP(DL_LOUD, ("DriverEntry\n"));

    Globals.pDriverObject = pDriverObject;
    Globals.EthType = NPROT_ETH_TYPE;
    NPROT_INIT_EVENT(&Globals.BindsComplete);

    do
    {
        //
        // Create our device object using which an application can
        // access NDIS devices.
        //
        RtlInitUnicodeString(&ntDeviceName, NT_DEVICE_NAME);

        status = IoCreateDevice (pDriverObject,
                                 0,
                                 &ntDeviceName,
                                 FILE_DEVICE_NETWORK,
                                 FILE_DEVICE_SECURE_OPEN,
                                 FALSE,
                                 &deviceObject);
    
        if (!NT_SUCCESS (status))
        {
            //
            // Either not enough memory to create a deviceobject or another
            // deviceobject with the same name exits. This could happen
            // if you install another instance of this device.
            //
            break;
        }

        RtlInitUnicodeString(&win32DeviceName, DOS_DEVICE_NAME);

        status = IoCreateSymbolicLink(&win32DeviceName, &ntDeviceName);

        if (!NT_SUCCESS(status))
        {
            break;
        }

        fSymbolicLink = TRUE;
    
        deviceObject->Flags |= DO_DIRECT_IO;
        Globals.ControlDeviceObject = deviceObject;

        NPROT_INIT_LIST_HEAD(&Globals.OpenList);
        NPROT_INIT_LOCK(&Globals.GlobalLock);

        //
        // Initialize the protocol characterstic structure
        //     
#if (NDIS_SUPPORT_NDIS630)
        {C_ASSERT(sizeof(protocolChar) >= NDIS_SIZEOF_PROTOCOL_DRIVER_CHARACTERISTICS_REVISION_2);}
        protocolChar.Header.Type        = NDIS_OBJECT_TYPE_PROTOCOL_DRIVER_CHARACTERISTICS,
        protocolChar.Header.Size        = NDIS_SIZEOF_PROTOCOL_DRIVER_CHARACTERISTICS_REVISION_2;
        protocolChar.Header.Revision    = NDIS_PROTOCOL_DRIVER_CHARACTERISTICS_REVISION_2;
#elif (NDIS_SUPPORT_NDIS6)
        {C_ASSERT(sizeof(protocolChar) >= NDIS_SIZEOF_PROTOCOL_DRIVER_CHARACTERISTICS_REVISION_1);}
        protocolChar.Header.Type        = NDIS_OBJECT_TYPE_PROTOCOL_DRIVER_CHARACTERISTICS,
        protocolChar.Header.Size        = NDIS_SIZEOF_PROTOCOL_DRIVER_CHARACTERISTICS_REVISION_1;
        protocolChar.Header.Revision    = NDIS_PROTOCOL_DRIVER_CHARACTERISTICS_REVISION_1;
#endif // NDIS MINIPORT VERSION

        protocolChar.MajorNdisVersion            = NDIS_PROT_MAJOR_VERSION;
        protocolChar.MinorNdisVersion            = NDIS_PROT_MINOR_VERSION;
        protocolChar.MajorDriverVersion          = MAJOR_DRIVER_VERSION;
        protocolChar.MinorDriverVersion          = MINOR_DRIVER_VERISON;
        protocolChar.Name                        = protoName;
        protocolChar.SetOptionsHandler           = NULL;
        protocolChar.OpenAdapterCompleteHandlerEx  = NdisprotOpenAdapterComplete;
        protocolChar.CloseAdapterCompleteHandlerEx = NdisprotCloseAdapterComplete;
        protocolChar.SendNetBufferListsCompleteHandler = NdisprotSendComplete;
        protocolChar.OidRequestCompleteHandler   = NdisprotRequestComplete;
        protocolChar.StatusHandlerEx             = NdisprotStatus;
        protocolChar.UninstallHandler            = NULL;
        protocolChar.ReceiveNetBufferListsHandler = NdisprotReceiveNetBufferLists;
        protocolChar.NetPnPEventHandler          = NdisprotPnPEventHandler;
        protocolChar.BindAdapterHandlerEx        = NdisprotBindAdapter;
        protocolChar.UnbindAdapterHandlerEx      = NdisprotUnbindAdapter;

        //
        // Register as a protocol driver
        //
    
        status = NdisRegisterProtocolDriver(ProtocolDriverContext,           // driver context
                                            &protocolChar,
                                            &Globals.NdisProtocolHandle);

        if (status != NDIS_STATUS_SUCCESS)
        {
            DEBUGP(DL_WARN, ("Failed to register protocol with NDIS\n"));
            status = STATUS_UNSUCCESSFUL;
            break;
        }

        Globals.PartialCancelId = NdisGeneratePartialCancelId();
        Globals.PartialCancelId <<= ((sizeof(PVOID) - 1) * 8);
        DEBUGP(DL_LOUD, ("DriverEntry: CancelId %lx\n", Globals.PartialCancelId));

        //
        // Now set only the dispatch points we would like to handle.
        //

        pDriverObject->MajorFunction[IRP_MJ_CREATE] = NdisprotOpen;

        pDriverObject->MajorFunction[IRP_MJ_CLOSE]  = NdisprotClose;

        pDriverObject->MajorFunction[IRP_MJ_READ]   = NdisprotRead;

        pDriverObject->MajorFunction[IRP_MJ_WRITE]  = NdisprotWrite;

        pDriverObject->MajorFunction[IRP_MJ_CLEANUP]  = NdisprotCleanup;

        pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL]  = NdisprotIoControl;
        

        pDriverObject->DriverUnload = NdisprotUnload;

        status = STATUS_SUCCESS;

        
    }
    while (FALSE);
       

    if (!NT_SUCCESS(status))
    {
        if (deviceObject)
        {
            KeEnterCriticalRegion();
            #pragma prefast(suppress:28107, "The deviceObject is held within the critical section")
            IoDeleteDevice(deviceObject);
            KeLeaveCriticalRegion();
            Globals.ControlDeviceObject = NULL;
        }

        if (fSymbolicLink)
        {
            IoDeleteSymbolicLink(&win32DeviceName);
            fSymbolicLink = FALSE;
        }
        
        if (Globals.NdisProtocolHandle)
        {
            NdisDeregisterProtocolDriver(Globals.NdisProtocolHandle);
            Globals.NdisProtocolHandle = NULL;
        }        
    }
    
    return status;
}
Beispiel #6
0
#include "precomp.h"
#include "hw_main.h"
#include "hw_isr.h"
#include "hw_oids.h"
#include "hw_phy.h"
#include "hw_mac.h"

#if DOT11_TRACE_ENABLED
#include "hw_main.tmh"
#endif



MP_REG_ENTRY HWRegTable[] = {
    {
        NDIS_STRING_CONST("*ReceiveBuffers"), 
        NdisParameterInteger,
        FIELD_OFFSET(HW,RegInfo),
        FIELD_OFFSET(NIC_REG_INFO, NumRXBuffers),
        sizeof(ULONG),
        HW11_DEF_RX_MSDUS,  
        HW11_MIN_RX_MSDUS,  
        HW11_MAX_RX_MSDUS
    },
    {
        NDIS_STRING_CONST("*TransmitBuffers"), 
        NdisParameterInteger,
        FIELD_OFFSET(HW,RegInfo),
        FIELD_OFFSET(NIC_REG_INFO, NumTXBuffers),
        sizeof(ULONG),
        HW11_DEF_TX_MSDUS,  
Beispiel #7
0
//
//  Packet Driver's entry routine.
//
NTSTATUS
DriverEntry(
    IN PDRIVER_OBJECT DriverObject,
    IN PUNICODE_STRING RegistryPath
    )
{

    NDIS_PROTOCOL_CHARACTERISTICS  ProtocolChar;
    PDEVICE_OBJECT DeviceObject = NULL;
    PDEVICE_EXTENSION DeviceExtension = NULL;
    NTSTATUS Status = STATUS_SUCCESS;
    NTSTATUS ErrorCode = STATUS_SUCCESS;
    NDIS_STRING ProtoName = NDIS_STRING_CONST("PacketDriver");
    ULONG          DevicesCreated=0;
    NDIS_HANDLE    NdisProtocolHandle;
	WCHAR* bindT;
	PKEY_VALUE_PARTIAL_INFORMATION tcpBindingsP;
	UNICODE_STRING macName;
	ULONG			OsMajorVersion, OsMinorVersion;
	
	PsGetVersion(&OsMajorVersion, &OsMinorVersion, NULL, NULL);
	//
	// Define the correct flag to skip the loopback packets, according to the OS
	//
	if((OsMajorVersion == 5) && (OsMinorVersion == 0))
	{
		// Windows 2000 wants both NDIS_FLAGS_DONT_LOOPBACK and NDIS_FLAGS_SKIP_LOOPBACK
		g_SendPacketFlags = NDIS_FLAGS_DONT_LOOPBACK | NDIS_FLAGS_SKIP_LOOPBACK_W2K;
	}
	else
	{
		// Windows XP, 2003 and following want only  NDIS_FLAGS_DONT_LOOPBACK
		g_SendPacketFlags =  NDIS_FLAGS_DONT_LOOPBACK;
	}

	if (((OsMajorVersion == 6) && (OsMinorVersion >= 1)) || (OsMajorVersion >= 7))
	{
		// Use KeQueryActiveProcessors to get the number of CPUs in Windows 7 or later
		KAFFINITY cpus = KeQueryActiveProcessors();
		NCpu = 0;

		while (cpus)
		{
			if (cpus % 2)
			{
				NCpu++;
			}

			cpus = cpus / 2;
		}
	}
	else
	{
		// Use NdisSystemProcessorCount in Windows Vista or earlier
		NCpu = NdisSystemProcessorCount();
	}

	
	ReadTimeStampModeFromRegistry(RegistryPath);

	IF_LOUD(DbgPrint("%ws",RegistryPath->Buffer);)
Beispiel #8
0
NTSTATUS
DriverEntry(
    IN PDRIVER_OBJECT   pDriverObject,
    IN PUNICODE_STRING  pRegistryPath
    )
/*++

Routine Description:

    Called on loading. We create a device object to handle user-mode requests
    on, and register ourselves as a protocol with NDIS.

Arguments:

    pDriverObject - Pointer to driver object created by system.

    pRegistryPath - Pointer to the Unicode name of the registry path
        for this driver.

Return Value:

    NT Status code
    
--*/
{
    NDIS_PROTOCOL_CHARACTERISTICS   protocolChar;
    NTSTATUS                        status = STATUS_SUCCESS;
    NDIS_STRING                     protoName = NDIS_STRING_CONST("NdisProt");     
    UNICODE_STRING                  ntDeviceName;
    UNICODE_STRING                  win32DeviceName;
    BOOLEAN                         fSymbolicLink = FALSE;
    PDEVICE_OBJECT                  deviceObject = NULL;

    UNREFERENCED_PARAMETER(pRegistryPath);

    DEBUGP(DL_LOUD, ("DriverEntry\n"));

    Globals.pDriverObject = pDriverObject;
    NPROT_INIT_EVENT(&Globals.BindsComplete);

    do
    {

        //
        // Create our device object using which an application can
        // access NDIS devices.
        //
        RtlInitUnicodeString(&ntDeviceName, NT_DEVICE_NAME);
#ifndef WIN9X
        status = IoCreateDeviceSecure(pDriverObject,
                                 0,
                                 &ntDeviceName,
                                 FILE_DEVICE_NETWORK,
                                 FILE_DEVICE_SECURE_OPEN,
                                 FALSE,
                                 &SDDL_DEVOBJ_SYS_ALL_ADM_ALL,
                                 NULL,
                                 &deviceObject);

#elif     
        status = IoCreateDevice(pDriverObject,
                                 0,
                                 &ntDeviceName,
                                 FILE_DEVICE_NETWORK,
                                 FILE_DEVICE_SECURE_OPEN,
                                 FALSE,
                                 &deviceObject);
#endif
        if (!NT_SUCCESS (status))
        {
            //
            // Either not enough memory to create a deviceobject or another
            // deviceobject with the same name exits. This could happen
            // if you install another instance of this device.
            //
            break;
        }

        RtlInitUnicodeString(&win32DeviceName, DOS_DEVICE_NAME);

        status = IoCreateSymbolicLink(&win32DeviceName, &ntDeviceName);

        if (!NT_SUCCESS(status))
        {
            break;
        }

        fSymbolicLink = TRUE;
    
        deviceObject->Flags |= DO_DIRECT_IO;
        Globals.ControlDeviceObject = deviceObject;

        NPROT_INIT_LIST_HEAD(&Globals.OpenList);
        NPROT_INIT_LOCK(&Globals.GlobalLock);

        //
        // Initialize the protocol characterstic structure
        //
    
        NdisZeroMemory(&protocolChar,sizeof(NDIS_PROTOCOL_CHARACTERISTICS));

        protocolChar.MajorNdisVersion            = 5;
        protocolChar.MinorNdisVersion            = 0;
        protocolChar.Name                        = protoName;
        protocolChar.OpenAdapterCompleteHandler  = NdisProtOpenAdapterComplete;
        protocolChar.CloseAdapterCompleteHandler = NdisProtCloseAdapterComplete;
        protocolChar.SendCompleteHandler         = NdisProtSendComplete;
        protocolChar.TransferDataCompleteHandler = NdisProtTransferDataComplete;
        protocolChar.ResetCompleteHandler        = NdisProtResetComplete;
        protocolChar.RequestCompleteHandler      = NdisProtRequestComplete;
        protocolChar.ReceiveHandler              = NdisProtReceive;
        protocolChar.ReceiveCompleteHandler      = NdisProtReceiveComplete;
        protocolChar.StatusHandler               = NdisProtStatus;
        protocolChar.StatusCompleteHandler       = NdisProtStatusComplete;
        protocolChar.BindAdapterHandler          = NdisProtBindAdapter;
        protocolChar.UnbindAdapterHandler        = NdisProtUnbindAdapter;
        protocolChar.UnloadHandler               = NULL;
        protocolChar.ReceivePacketHandler        = NdisProtReceivePacket;
        protocolChar.PnPEventHandler             = NdisProtPnPEventHandler;

        //
        // Register as a protocol driver
        //
    
        NdisRegisterProtocol(
            (PNDIS_STATUS)&status,
            &Globals.NdisProtocolHandle,
            &protocolChar,
            sizeof(NDIS_PROTOCOL_CHARACTERISTICS));

        if (status != NDIS_STATUS_SUCCESS)
        {
            DEBUGP(DL_WARN, ("Failed to register protocol with NDIS\n"));
            status = STATUS_UNSUCCESSFUL;
            break;
        }

#ifdef NDIS51
        Globals.PartialCancelId = NdisGeneratePartialCancelId();
        Globals.PartialCancelId <<= ((sizeof(PVOID) - 1) * 8);
        DEBUGP(DL_LOUD, ("DriverEntry: CancelId %lx\n", Globals.PartialCancelId));
#endif

        //
        // Now set only the dispatch points we would like to handle.
        //
        pDriverObject->MajorFunction[IRP_MJ_CREATE] = NdisProtOpen;
        pDriverObject->MajorFunction[IRP_MJ_CLOSE]  = NdisProtClose;
        pDriverObject->MajorFunction[IRP_MJ_READ]   = NdisProtRead;
        pDriverObject->MajorFunction[IRP_MJ_WRITE]  = NdisProtWrite;
        pDriverObject->MajorFunction[IRP_MJ_CLEANUP]  = NdisProtCleanup;
        pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL]  = NdisProtIoControl;
        pDriverObject->DriverUnload = NdisProtUnload;

        status = STATUS_SUCCESS;
        
    }
    while (FALSE);
       

    if (!NT_SUCCESS(status))
    {
        if (deviceObject)
        {
            IoDeleteDevice(deviceObject);
            Globals.ControlDeviceObject = NULL;
        }

        if (fSymbolicLink)
        {
            IoDeleteSymbolicLink(&win32DeviceName);
        }
        
    }
    
    return status;

}
Beispiel #9
0
NTSTATUS DriverEntry(PDRIVER_OBJECT driver, PUNICODE_STRING str)
{
	DbgBreakPoint();
	NTSTATUS sta;
	global.contextnum = 0;
	global.mininum = 0;
	globalinfopool.count = 0;
	global.controlobj = NULL;
	NDIS_STATUS ndissta;
	NDIS_HANDLE wraphandle=NULL;
	NDIS_MINIPORT_CHARACTERISTICS minicha;
	NDIS_PROTOCOL_CHARACTERISTICS pc;
	NDIS_STRING ns = NDIS_STRING_CONST("zlzpass");
	NdisZeroMemory(&global, sizeof(GLOBAL));
	NdisInitializeWrapper(&wraphandle, driver, str, NULL);
	if (wraphandle == NULL)
	{
		return STATUS_UNSUCCESSFUL;
	}
	NdisZeroMemory(&minicha, sizeof(NDIS_MINIPORT_CHARACTERISTICS));
	minicha.MajorNdisVersion = NDIS_MINIPORT_MAJOR_VERSION;
	minicha.MinorNdisVersion = NDIS_MINIPORT_MINOR_VERSION;
	minicha.InitializeHandler = MPInitialize;
	minicha.HaltHandler = MPHalt;
	minicha.SetInformationHandler = MPSetInformation;
	minicha.QueryInformationHandler = MPQueryInformation;
	minicha.ReturnPacketHandler = MPReturnPacket;
	minicha.ResetHandler = NULL;
	minicha.CheckForHangHandler = NULL;
	minicha.TransferDataHandler = MPTransferData;
	minicha.SendHandler = MPSend;
	ndissta=NdisIMRegisterLayeredMiniport(wraphandle, &minicha, sizeof(NDIS_MINIPORT_CHARACTERISTICS), &global.driverhandle);
	if (ndissta!=NDIS_STATUS_SUCCESS)
	{
		return STATUS_UNSUCCESSFUL;
	}
	sysadddevfunc = driver->DriverExtension->AddDevice;

	driver->DriverExtension->AddDevice = myAddDevice;

	pc.MajorNdisVersion = 5;
	pc.MinorNdisVersion = 0;
	pc.Name = ns;
	pc.CloseAdapterCompleteHandler = NdisProtCloseAdapterComplete;
	pc.SendCompleteHandler = NdisProtSendComplete;
	pc.TransferDataCompleteHandler = NdisProtTransferDataComplete;
	pc.ResetCompleteHandler = NdisProtResetComplete;
	pc.RequestCompleteHandler = NdisProtRequestComplete;
	pc.ReceiveHandler = NdisProtReceive;
	pc.ReceiveCompleteHandler = NdisProtReceiveComplete;
	pc.StatusHandler = NdisProtStatus;
	pc.StatusCompleteHandler = NdisProtStatusComplete;
	pc.BindAdapterHandler = NdisProtBindAdapter;
	pc.OpenAdapterCompleteHandler = NdisOpenAdapterComplete;
	pc.UnbindAdapterHandler = NdisProtUnbindAdapter;
	pc.UnloadHandler = NULL;
	pc.ReceivePacketHandler = NdisProtReceivePacket;
	pc.PnPEventHandler = NdisProtPnPEventHandler;
	pc.CoAfRegisterNotifyHandler = NdisProtRegisterAf;
	NdisRegisterProtocol(&ndissta,&global.protocolhandle, &pc, sizeof(NDIS_PROTOCOL_CHARACTERISTICS));
	if (ndissta != NDIS_STATUS_SUCCESS)
	{
		return STATUS_UNSUCCESSFUL;
	}
	NdisIMAssociateMiniport(global.driverhandle, global.protocolhandle);

	sta = ZlzCreateDevice(driver,wraphandle);
	if (!NT_SUCCESS(sta))
	{
		return STATUS_UNSUCCESSFUL;
	}

	NdisMRegisterUnloadHandler(wraphandle, unload);
    return STATUS_SUCCESS;
}
Beispiel #10
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);
		}
	}
}
Beispiel #11
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;
}
Beispiel #12
0
--*/
#include "precomp.h"
#include "St_main.h"
#include "St_aplst.h"
#include "St_conn.h"
#include "St_adhoc.h"
#include "St_scan.h"
#include "St_oids.h"

#if DOT11_TRACE_ENABLED
#include "Sta_main.tmh"
#endif

MP_REG_ENTRY STARegTable[] = {
    {NDIS_STRING_CONST("RSSIRoamBeaconCount"),  // reg value name
     STA_OFFSET(RSSIRoamBeaconCount),           // Offset in STA_REG_INFO
     STA_SIZE(RSSIRoamBeaconCount),             // Field size
     STA_INFRA_RSSI_ROAM_BEACON_COUNT_DEFAULT,  // Default Value
     STA_INFRA_RSSI_ROAM_BEACON_COUNT_MIN,      // Min
     STA_INFRA_RSSI_ROAM_BEACON_COUNT_MAX       // Max
     },

    {NDIS_STRING_CONST("RSSILinkQualityThreshold"),
     STA_OFFSET(RSSILinkQualityThreshold),
     STA_SIZE(RSSILinkQualityThreshold),
     STA_INFRA_LINK_QUALITY_ROAM_THRESHOLD_DEFAULT,
     STA_INFRA_LINK_QUALITY_ROAM_THRESHOLD_MIN,
     STA_INFRA_LINK_QUALITY_ROAM_THRESHOLD_MAX
     },
Beispiel #13
0
/*
 Function Name : 	GetRegistrySettings
 Description   :	
					Reads the registry values, and loads them into the adapter structure
 Parameters    :
					MINIPORT_ADAPTER *Adapter	- Pointer to the adapter structure
					NDIS_HANDLE       ConfigurationContext - Context handler, from the NDIS wrapper
			
 Return Value  :
					NDIS_STATUS		Status
*/
NDIS_STATUS GetRegistrySettings(MINIPORT_ADAPTER*	pAdapter,
								NDIS_HANDLE			hConfigurationContext)
{
	NDIS_STATUS						Status;
	NDIS_HANDLE						hConfiguration;
	PNDIS_CONFIGURATION_PARAMETER	pConfigurationParameter;
	BOOL							bSpeedDef = FALSE, bDuplexDef = FALSE;

	UCHAR*							pNewNetworkAddress = NULL;
	UINT							nNewNetworkAddressLength;

	//	EMAC specific settings
	NDIS_STRING						szBufferAddr	= NDIS_STRING_CONST("BufferAddr");
	NDIS_STRING						szTxStride		= NDIS_STRING_CONST("TxStrides");
	NDIS_STRING						szRxStride		= NDIS_STRING_CONST("RxStrides");
	NDIS_STRING						szITNum			= NDIS_STRING_CONST("IRQNumber");
	NDIS_STRING						szEMACAddr		= NDIS_STRING_CONST("IoBaseAddress");
	NDIS_STRING						szRMII			= NDIS_STRING_CONST("RMII");

	//	Eth Link settings
	NDIS_STRING						AutoNegString	= NDIS_STRING_CONST("AUTO-NEGOTIATION");
	NDIS_STRING						DuplexString	= NDIS_STRING_CONST("DUPLEX");
	NDIS_STRING						FullDupString	= NDIS_STRING_CONST("FULL");
	NDIS_STRING						HalfDupString	= NDIS_STRING_CONST("HALF");
	NDIS_STRING						SpeedString		= NDIS_STRING_CONST("SPEED");
	NDIS_STRING						Speed100String	= NDIS_STRING_CONST("100");
	NDIS_STRING						Speed10String	= NDIS_STRING_CONST("10");
	
	DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS ==> GetRegistrySettings\r\n")));

	//Open the Registry tree for this adapter.
    NdisOpenConfiguration(&Status, &hConfiguration, hConfigurationContext);
	if(Status != NDIS_STATUS_SUCCESS)
    {
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS : ERROR - No information for adapter!\r\n")));
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS <== Configure Adapter\r\n")));
        return(NDIS_STATUS_FAILURE);
    }

	//Get configured Buffer address value from registry,
	NdisReadConfiguration(	&Status,   
							&pConfigurationParameter,
							hConfiguration,
							&szBufferAddr,
							NdisParameterInteger); 
	if(Status == NDIS_STATUS_SUCCESS)
	{
		pAdapter->dwBufferPhyAddr = (DWORD) pConfigurationParameter->ParameterData.IntegerData;
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:dwBufferPhyAddr    = 0x%.8x\r\n"), pAdapter->dwBufferPhyAddr));
	}
	else
	{
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS : ERROR - BufferAddr not in Registry!\r\n")));
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS <== Configure Adapter\r\n")));
		NdisCloseConfiguration(hConfiguration);
		return(NDIS_STATUS_FAILURE);
	}

	//Get configured Number of TX Strides from registry,
	NdisReadConfiguration(	&Status,   
							&pConfigurationParameter,
							hConfiguration,
							&szTxStride,
							NdisParameterInteger); 
	if(Status == NDIS_STATUS_SUCCESS)
	{
		pAdapter->dwTxStrides = (DWORD) pConfigurationParameter->ParameterData.IntegerData;
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:dwTxStrides    = 0x%x\r\n"), pAdapter->dwTxStrides));
	}
	else
	{
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS : ERROR - TXStrides not in Registry!\r\n")));
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS <== Configure Adapter\r\n")));
		NdisCloseConfiguration(hConfiguration);
		return(NDIS_STATUS_FAILURE);
	}

	//Get configured Number of RX Strides from registry,
	NdisReadConfiguration(	&Status,   
							&pConfigurationParameter,
							hConfiguration,
							&szRxStride,
							NdisParameterInteger); 
	if(Status == NDIS_STATUS_SUCCESS)
	{
		pAdapter->dwRxStrides = (DWORD) pConfigurationParameter->ParameterData.IntegerData;
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:dwRxStrides    = 0x%x\r\n"), pAdapter->dwRxStrides));
	}
	else
	{
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS : ERROR - RXStrides not in Registry!\r\n")));
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS <== Configure Adapter\r\n")));
		NdisCloseConfiguration(hConfiguration);
		return(NDIS_STATUS_FAILURE);
	}

	//Get configured IRQ Number from registry,
	NdisReadConfiguration(	&Status,   
							&pConfigurationParameter,
							hConfiguration,
							&szITNum,
							NdisParameterInteger); 
	if(Status == NDIS_STATUS_SUCCESS)
	{
		pAdapter->dwIRQNumber = (DWORD) pConfigurationParameter->ParameterData.IntegerData;
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:dwIRQNumber    = 0x%x\r\n"), pAdapter->dwIRQNumber));
	}
	else
	{
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS : ERROR - IRQNumber not in Registry!\r\n")));
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS <== Configure Adapter\r\n")));
		NdisCloseConfiguration(hConfiguration);
		return(NDIS_STATUS_FAILURE);
	}

	//Get configured EMAC base address from registry,
	NdisReadConfiguration(	&Status,   
							&pConfigurationParameter,
							hConfiguration,
							&szEMACAddr,
							NdisParameterInteger); 
	
	if(Status == NDIS_STATUS_SUCCESS)
	{
		pAdapter->dwControllerAddress = (DWORD) pConfigurationParameter->ParameterData.IntegerData;
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:dwControllerAddress    = 0x%.8x\r\n"), pAdapter->dwControllerAddress));
		RETAILMSG(1, (TEXT("LPC3xxx NDIS:dwControllerAddress    = 0x%.8x\r\n"), pAdapter->dwControllerAddress));
	}
	else
	{
		RETAILMSG(1, (TEXT("LPC3xxx NDIS : ERROR - IoBaseAddress not in Registry!\r\n")));
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS : ERROR - IoBaseAddress not in Registry!\r\n")));
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS <== Configure Adapter\r\n")));
		NdisCloseConfiguration(hConfiguration);
		return(NDIS_STATUS_FAILURE);
	}

	
	//Get PHY interface type (MII/RMII) from registry,
	NdisReadConfiguration(	&Status,   
							&pConfigurationParameter,
							hConfiguration,
							&szRMII,
							NdisParameterInteger); 
	if(Status == NDIS_STATUS_SUCCESS)
	{
		pAdapter->bRMII = ((USHORT) pConfigurationParameter->ParameterData.IntegerData == 0) ? FALSE : TRUE;
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:bRMII    = %s\r\n"), pAdapter->bRMII ? L"TRUE" : L"FALSE"));
	}
	else
	{
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS : RMII not in Registry!\r\n")));
		pAdapter->bRMII = TRUE;
	}

	NdisReadConfiguration(	&Status,
							&pConfigurationParameter,
							hConfiguration,
							&DuplexString,
							NdisParameterString);
	
	if(Status == NDIS_STATUS_SUCCESS)
	{
		bDuplexDef = TRUE;

		if( NdisEqualString( (PNDIS_STRING) &pConfigurationParameter->ParameterData.StringData,&FullDupString, TRUE ) ) 
		{
			DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:Config is Full Duplex\r\n")));
			pAdapter->bFullDuplex = TRUE;
		}
		else if( NdisEqualString( (PNDIS_STRING) &pConfigurationParameter->ParameterData.StringData, &HalfDupString, TRUE ) ) 
		{
			DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:Config is Half Duplex\r\n")));
			pAdapter->bFullDuplex = FALSE;
		}				
	}

	NdisReadConfiguration(	&Status, 
							&pConfigurationParameter, 
							hConfiguration,
							&SpeedString,
							NdisParameterString);
	if(Status == NDIS_STATUS_SUCCESS) 
	{
		bSpeedDef = TRUE;
		if( NdisEqualString( (PNDIS_STRING) &pConfigurationParameter->ParameterData.StringData,(PNDIS_STRING) &Speed100String,TRUE ) ) 
		{
			DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:Config is 100 Mbps\r\n")));
			pAdapter->b100Mbps = TRUE;
		}
		else if( NdisEqualString( (PNDIS_STRING) &pConfigurationParameter->ParameterData.StringData,(PNDIS_STRING) &Speed10String,TRUE ) )
		{
			DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:Config is 10 Mbps\r\n")));
			pAdapter->b100Mbps = FALSE;
		}
	}

	if(bSpeedDef && bDuplexDef)
	{
		pAdapter->bAutoNeg = FALSE;
	}

	NdisReadConfiguration(	&Status,
							&pConfigurationParameter,
							hConfiguration,
							&AutoNegString,
							NdisParameterString);
	if(Status == NDIS_STATUS_SUCCESS)
	{
		if((USHORT) pConfigurationParameter->ParameterData.IntegerData == 0)
		{
			pAdapter->bAutoNeg = FALSE;
		}
		else
		{
			pAdapter->bAutoNeg = TRUE;
		}
	}

	if(pAdapter->bAutoNeg)
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:Config is AutoNeg Enabled\r\n")));
	else
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:Config is AutoNeg Disabled\r\n")));

	//See if user has defined new MAC address.
	NdisReadNetworkAddress(	&Status,
							(PVOID *) &pNewNetworkAddress,
							&nNewNetworkAddressLength,
							hConfiguration);
				
	if((Status == NDIS_STATUS_SUCCESS) && (nNewNetworkAddressLength != 0))
	{
		DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:Default MAC Address over-ride!\r\n")));
		if((nNewNetworkAddressLength != ETH_LENGTH_OF_ADDRESS)) 
		{
			DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:Invalid MAC address length!\r\n")));
		}
		else
		{
			pAdapter->MACAddress[0] = pNewNetworkAddress[0];
			pAdapter->MACAddress[1] = pNewNetworkAddress[1];
			pAdapter->MACAddress[2] = pNewNetworkAddress[2];
			pAdapter->MACAddress[3] = pNewNetworkAddress[3];
			pAdapter->MACAddress[4] = pNewNetworkAddress[4];
			pAdapter->MACAddress[5] = pNewNetworkAddress[5];

			DEBUGMSG(ZONE_INIT,(TEXT("Registry reads = %02X-%02X-%02X-%02X-%02X-%02X\r\n"),
				pNewNetworkAddress[0], 
				pNewNetworkAddress[1],
				pNewNetworkAddress[2],
				pNewNetworkAddress[3],
				pNewNetworkAddress[4],
				pNewNetworkAddress[5]));

			DEBUGMSG(ZONE_INIT,(TEXT("Adapter->MACAddress reads = %02X-%02X-%02X-%02X-%02X-%02X\r\n"),
				pAdapter->MACAddress[0],
				pAdapter->MACAddress[1],
				pAdapter->MACAddress[2],
				pAdapter->MACAddress[3],
				pAdapter->MACAddress[4],
				pAdapter->MACAddress[5]));
		}
	}
	else
	{
		Status = NDIS_STATUS_SUCCESS;
	}

	NdisCloseConfiguration(hConfiguration);

	if(Status != NDIS_STATUS_SUCCESS)
	{
			DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:ERROR: Specific Configuration Handler Failed!\r\n")));
			DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS:<== Configure Adapter\r\n")));
			return(Status);
	}
	
	DEBUGMSG(ZONE_INIT, (TEXT("LPC3xxx NDIS <== GetRegistrySettings  \r\n")));
	return(Status);
}
Beispiel #14
0
 *
 * Copyright (c) 2000-2005 Davicom Inc.  All rights reserved.
 *
 ********************************************************************************/

#include	"dm9isa.h"


/*******************************************************************************
 *
 *
 *
 ********************************************************************************/
CONFIG_PARAMETER	g_szDm9ConfigParams[] =
{
	{ CID_CONNECTION_TYPE, -1, NDIS_STRING_CONST("ConnectionType") },
	{ CID_SLOT_NUMBER, -1, NDIS_STRING_CONST("SlotNumber")},
	{ CID_BUFFER_PHYSICAL_ADDRESS, 0, NDIS_STRING_CONST("BufferPhysicalAddress")},
	{ CID_TXBUFFER_NUMBER, 0x20, NDIS_STRING_CONST("XmitBuffer")},
	{ CID_RXBUFFER_NUMBER, 0x10, NDIS_STRING_CONST("RecvBuffer")},
	{ CID_ADAPTER_NUMBER, 0, NDIS_STRING_CONST("AdapterNumber")},
	{ CID_IO_BASE_ADDRESS, 0x18000300, NDIS_STRING_CONST("IoAddress")},
	{ CID_IO_RANGE, 0x10, NDIS_STRING_CONST("IoRange")},
	{ CID_IRQ_NUMBER, 12, NDIS_STRING_CONST("IrqNumber")},
	{ -1,-1,NULL}
};

/*******************************************************************************
 *
 * Device attributes and characteristics
 *
Beispiel #15
0
NTSTATUS
DriverEntry(
    IN PDRIVER_OBJECT   DriverObject,
    IN PUNICODE_STRING  RegistryPath
    )
/*++

Routine Description:

    Called on loading. We create a device object to handle user-mode requests
    on, and register ourselves as a protocol with NDIS.

Arguments:

    pDriverObject - Pointer to driver object created by system.

    pRegistryPath - Pointer to the Unicode name of the registry path
        for this driver.

Return Value:

    NT Status code

--*/
{
    NDIS_PROTOCOL_DRIVER_CHARACTERISTICS   protocolChar;
    NTSTATUS                        status = STATUS_SUCCESS;
    NDIS_STRING                     protoName = NDIS_STRING_CONST("NDISPROT");
    WDF_DRIVER_CONFIG               config;
    WDFDRIVER                       hDriver;
    PWDFDEVICE_INIT                 pInit = NULL;

    UNREFERENCED_PARAMETER(RegistryPath);

    DEBUGP(DL_LOUD, ("DriverEntry\n"));

    Globals.DriverObject = DriverObject;
    Globals.EthType = NPROT_ETH_TYPE;
    NPROT_INIT_EVENT(&Globals.BindsComplete);

    WDF_DRIVER_CONFIG_INIT(
        &config,
        WDF_NO_EVENT_CALLBACK // This is a non-pnp driver.
    );

    //
    // Tell the framework that this is non-pnp driver so that it doesn't
    // set the default AddDevice routine.
    //
    config.DriverInitFlags |= WdfDriverInitNonPnpDriver;


    //
    // We need an unload routine to free control device created below. For
    // non-pnp drivers, framework doesn't provide Unload routine.
    //
    config.EvtDriverUnload = NdisProtEvtDriverUnload;

    //
    // Create a framework driver object to represent our driver.
    //
    status = WdfDriverCreate(DriverObject,
                            RegistryPath,
                            WDF_NO_OBJECT_ATTRIBUTES,
                            &config,
                            &hDriver);
    if (!NT_SUCCESS(status)) {
        DEBUGP(DL_ERROR, ("WdfDriverCreate failed with status 0x%x\n", status));
        return status;
    }

    //
    //
    // In order to create a control device, we first need to allocate a
    // WDFDEVICE_INIT structure and set all properties.
    //
    pInit = WdfControlDeviceInitAllocate(
                            hDriver,
                            &SDDL_DEVOBJ_SYS_ALL_ADM_RWX_WORLD_RW_RES_R
                            );

    if (pInit == NULL) {
        status = STATUS_INSUFFICIENT_RESOURCES;
        return status;
    }

    //
    // Call NdisProtDeviceAdd to create WDFDEVICE to represent our
    // software device.
    //
    status = NdisProtCreateControlDevice(hDriver, pInit);
    if (!NT_SUCCESS(status)) {
        DEBUGP (DL_ERROR, ("NdisProtCreateControlDevice failed with status 0x%x\n", status));
        return status;
    }

    //
    // Initialize the protocol characterstic structure
    //

    NdisZeroMemory(&protocolChar,sizeof(NDIS_PROTOCOL_DRIVER_CHARACTERISTICS));


    protocolChar.Header.Type                = NDIS_OBJECT_TYPE_PROTOCOL_DRIVER_CHARACTERISTICS,
    protocolChar.Header.Size                = sizeof(NDIS_PROTOCOL_DRIVER_CHARACTERISTICS);
    protocolChar.Header.Revision            = NDIS_PROTOCOL_DRIVER_CHARACTERISTICS_REVISION_1;

    protocolChar.MajorNdisVersion            = 6;
    protocolChar.MinorNdisVersion            = 0;
    protocolChar.Name                        = protoName;
    protocolChar.SetOptionsHandler           = NULL;
    protocolChar.OpenAdapterCompleteHandlerEx  = NdisprotOpenAdapterComplete;
    protocolChar.CloseAdapterCompleteHandlerEx = NdisprotCloseAdapterComplete;
    protocolChar.SendNetBufferListsCompleteHandler = NdisprotSendComplete;
    protocolChar.OidRequestCompleteHandler   = NdisprotRequestComplete;
    protocolChar.StatusHandlerEx             = NdisprotStatus;
    protocolChar.UninstallHandler            = NULL;
    protocolChar.ReceiveNetBufferListsHandler = NdisprotReceiveNetBufferLists;
    protocolChar.NetPnPEventHandler          = NdisprotPnPEventHandler;
    protocolChar.BindAdapterHandlerEx        = NdisprotBindAdapter;
    protocolChar.UnbindAdapterHandlerEx      = NdisprotUnbindAdapter;

    //
    // Register as a protocol driver
    //

    status = NdisRegisterProtocolDriver(NULL,           // driver context
                                        &protocolChar,
                                        &Globals.NdisProtocolHandle);

    if (status != NDIS_STATUS_SUCCESS)
    {
        DEBUGP(DL_WARN, ("Failed to register protocol with NDIS\n"));
        return STATUS_UNSUCCESSFUL;
    }

    NPROT_INIT_LIST_HEAD(&Globals.OpenList);
    NPROT_INIT_LOCK(&Globals.GlobalLock);

    Globals.PartialCancelId = NdisGeneratePartialCancelId();
    Globals.PartialCancelId <<= ((sizeof(PVOID) - 1) * 8);
    DEBUGP(DL_LOUD, ("DriverEntry: CancelId %lx\n", Globals.PartialCancelId));

    return status;

}
Beispiel #16
0
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;
}
Beispiel #17
0
// 初始化协议驱动
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObj, PUNICODE_STRING pRegistryString)
{
	NTSTATUS status = STATUS_SUCCESS;
	PDEVICE_OBJECT pDeviceObj = NULL;
	NDIS_STRING protoName = NDIS_STRING_CONST("Packet");
	// 给用户使用的符号连接名称
	UNICODE_STRING ustrSymbolicLink;
	BOOLEAN bSymbolicLink = FALSE;

	DbgPrint(" ProtoDrv: DriverEntry...  \n");

	// 保存驱动对象指针。这里,g_data是GLOBAL类型的全局变量
	g_data.pDriverObj = pDriverObj;

	do
	{
			// 为此驱动创建一个控制设备对象。用户程序向这个设备发送IOCTL代码,
			// 以便获取绑定的适配器信息
		UNICODE_STRING ustrDevName;
		RtlInitUnicodeString(&ustrDevName, DEVICE_NAME);
		status = IoCreateDevice(pDriverObj, 
			0,
			&ustrDevName, 
			FILE_DEVICE_UNKNOWN,
			0,
			FALSE,
			&pDeviceObj);
		if(!NT_SUCCESS(status))
		{
			DbgPrint(" ProtoDrv: CreateDevice failed \n");
			break;
		}
		// 为上面的设备创建符号连接
		RtlInitUnicodeString(&ustrSymbolicLink, LINK_NAME);
		status = IoCreateSymbolicLink(&ustrSymbolicLink, &ustrDevName);  
		if(!NT_SUCCESS(status))
		{
			DbgPrint(" ProtoDrv: CreateSymbolicLink failed \n");
			break;
		}
		bSymbolicLink = TRUE;
		// 设置为缓冲区I/O方式
		pDeviceObj->Flags |= DO_BUFFERED_IO;

			// 初始化全局变量
		g_data.pControlDevice = pDeviceObj;
		InitializeListHead(&g_data.AdapterList);
		KeInitializeSpinLock(&g_data.GlobalLock);

			// 初始化协议特征结构
		NDIS_PROTOCOL_CHARACTERISTICS protocolChar;
		NdisZeroMemory(&protocolChar, sizeof(protocolChar));
		protocolChar.Ndis40Chars.Ndis30Chars.MajorNdisVersion = 5;
		protocolChar.Ndis40Chars.Ndis30Chars.MinorNdisVersion = 0;

		protocolChar.Ndis40Chars.Ndis30Chars.Name = protoName;

		protocolChar.Ndis40Chars.BindAdapterHandler = ProtocolBindAdapter;
		protocolChar.Ndis40Chars.UnbindAdapterHandler = ProtocolUnbindAdapter;
		
		protocolChar.Ndis40Chars.Ndis30Chars.OpenAdapterCompleteHandler  = ProtocolOpenAdapterComplete;
		protocolChar.Ndis40Chars.Ndis30Chars.CloseAdapterCompleteHandler = ProtocolCloseAdapterComplete;

		protocolChar.Ndis40Chars.Ndis30Chars.ReceiveHandler              = ProtocolReceive;
//		protocolChar.Ndis40Chars.ReceivePacketHandler					= ProtocolReceivePacket;
		protocolChar.Ndis40Chars.Ndis30Chars.TransferDataCompleteHandler = ProtocolTransferDataComplete;

		protocolChar.Ndis40Chars.Ndis30Chars.SendCompleteHandler         = ProtocolSendComplete;

		
		protocolChar.Ndis40Chars.Ndis30Chars.ResetCompleteHandler        = ProtocolResetComplete;
		protocolChar.Ndis40Chars.Ndis30Chars.RequestCompleteHandler      = ProtocolRequestComplete;
		
		protocolChar.Ndis40Chars.Ndis30Chars.ReceiveCompleteHandler      = ProtocolReceiveComplete;
		
		protocolChar.Ndis40Chars.Ndis30Chars.StatusHandler               = ProtocolStatus;
		protocolChar.Ndis40Chars.Ndis30Chars.StatusCompleteHandler       = ProtocolStatusComplete;
		protocolChar.Ndis40Chars.PnPEventHandler						= ProtocolPNPHandler; 
		
			// 注册为协议驱动
		NdisRegisterProtocol((PNDIS_STATUS)&status, 
			&g_data.hNdisProtocol, &protocolChar, sizeof(protocolChar));
		if(status != NDIS_STATUS_SUCCESS)
		{
			status = STATUS_UNSUCCESSFUL;
			break;
		}
		DbgPrint(" ProtoDrv: NdisRegisterProtocol success \n");

			// 现在,设置我们要处理的派遣例程
		pDriverObj->MajorFunction[IRP_MJ_CREATE] = DispatchCreate;
		pDriverObj->MajorFunction[IRP_MJ_CLOSE] = DispatchClose;
		pDriverObj->MajorFunction[IRP_MJ_READ]  = DispatchRead;
		pDriverObj->MajorFunction[IRP_MJ_WRITE]  = DispatchWrite;
		pDriverObj->MajorFunction[IRP_MJ_CLEANUP]  = DispatchCleanup;

		pDriverObj->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DispatchIoctl;
		pDriverObj->DriverUnload = DriverUnload;	
		status = STATUS_SUCCESS;
	}while(FALSE);
	
	if(!NT_SUCCESS(status))		// 错误处理
	{
		if(pDeviceObj != NULL)
		{
			// 删除设备对象
			IoDeleteDevice(pDeviceObj); 
			g_data.pControlDevice = NULL;
		}
		if(bSymbolicLink)
		{
			// 删除符号连接
			IoDeleteSymbolicLink(&ustrSymbolicLink);
		}
	}
	return status;
}
Beispiel #18
0
DWORD _stdcall PacketIOControl(DWORD           dwService,
                               DWORD           dwDDB,
                               DWORD           hDevice,
                               PDIOCPARAMETERS pDiocParms) 
{
  // called from applications

  POPEN_INSTANCE  Open;
  NDIS_STATUS     Status;
  UCHAR           AdapterBuffer[5];
  NDIS_STRING     AdapterName = NDIS_STRING_CONST(AdapterBuffer);


  switch (dwService) {
    case DIOC_OPEN:
      return NDIS_STATUS_SUCCESS;
    
    case DIOC_CLOSEHANDLE:
      if ((Open = GetOpen(hDevice)) != NULL)
        PacketUnbindAdapter(&Status, Open, NULL);
      return NDIS_STATUS_SUCCESS;

    case IOCTL_EPACKET_VERSION:
      if (pDiocParms->cbOutBuffer < 2)
        *(DWORD *)(pDiocParms->lpcbBytesReturned) = 0;
      else {
        ((BYTE *)pDiocParms->lpvOutBuffer)[0] = MAJOR_VERSION;
        ((BYTE *)pDiocParms->lpvOutBuffer)[1] = MINOR_VERSION;
        *(DWORD *)pDiocParms->lpcbBytesReturned = 2;
      }
      return NDIS_STATUS_SUCCESS;

    case IOCTL_EPACKET_BIND:
      memcpy(AdapterName.Buffer, (BYTE *)pDiocParms->lpvInBuffer,
             min(strlen((char *)pDiocParms->lpvInBuffer), sizeof(AdapterBuffer)-1));
      AdapterName.Buffer[sizeof(AdapterBuffer)-1] = '\0';
      PacketBindAdapter(&Status,
                        GlobalDeviceExtension->NdisProtocolHandle,
                        &AdapterName,
                        (PVOID)hDevice, /* special */
                        NULL);
      // Note: If the above usage of the 4'th arg to PacketBindAdapter
      //       causes problems, use a global variable instead.
      if (Status == NDIS_STATUS_SUCCESS || Status == NDIS_STATUS_PENDING) {
        *(DWORD *)pDiocParms->lpcbBytesReturned = 1;
        return NDIS_STATUS_SUCCESS;
      }
      break;

    case IOCTL_EPACKET_SET_OID:
    case IOCTL_EPACKET_QUERY_OID:
      if ((Open = GetOpen(hDevice)) != NULL)
        return PacketRequest(Open, dwService, dwDDB, hDevice, pDiocParms);
      break;
    
    case IOCTL_EPACKET_READ:
      if ((Open = GetOpen(hDevice)) != NULL)
        return PacketRead(Open, dwDDB, hDevice, pDiocParms);
      break;
    
    case IOCTL_EPACKET_WRITE:
      if ((Open = GetOpen(hDevice)) != NULL)
        return PacketWrite(Open, dwDDB, hDevice, pDiocParms);
      break;
  }

  *(DWORD *)pDiocParms->lpcbBytesReturned = 0;
  return NDIS_STATUS_SUCCESS;
}
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));
}
Beispiel #20
0
NTSTATUS
DriverEntry(
	IN PDRIVER_OBJECT 	DriverObject,
	IN PUNICODE_STRING 	RegistryPath
	)
/*++

Routine Description:

	This is the entry routine for the localtalk driver.

Arguments:

	DriverObject: The IO driver object for this driver object.
	RegistryPath: The path to the registry config for this driver.

Return Value:

	STATUS_SUCCESS: If load was successful
	Error 		  : Otherwise

--*/
{
	NDIS_STATUS 				Status;
	NDIS_MAC_CHARACTERISTICS 	LtChar;
	static const NDIS_STRING 	MacName = NDIS_STRING_CONST("LT200");

	DBGPRINT(DBG_COMP_INIT, DBG_LEVEL_INFO,
			("Debugging breakpoint, Hit G <cr> to continue\n"));

	DBGBREAK(DBG_LEVEL_INFO);

	// Initialize the NDIS Wrapper.
	NdisInitializeWrapper(
		&LtNdisWrapperHandle,
		DriverObject,
		RegistryPath,
		NULL);

	// Setup the MAC Characteristics
	LtChar.MajorNdisVersion 				= NDIS_MAJOR_VERSION;
	LtChar.MinorNdisVersion 				= NDIS_MINOR_VERSION;
	LtChar.OpenAdapterHandler 				= LtInitOpenAdapter;
	LtChar.CloseAdapterHandler 				= LtInitCloseAdapter;
	LtChar.SendHandler 						= LtSend;
	LtChar.RequestHandler 					= LtRequest;
	LtChar.TransferDataHandler 				= LtRecvTransferData;
	LtChar.ResetHandler 					= LtReset;
	LtChar.QueryGlobalStatisticsHandler 	= LtReqQueryGlobalStatistics;
	LtChar.UnloadMacHandler 				= LtInitUnload;
	LtChar.AddAdapterHandler 				= LtInitAddAdapter;
	LtChar.RemoveAdapterHandler 			= LtInitRemoveAdapter;
	LtChar.Name 							= MacName;

	NdisRegisterMac(
		&Status,
		&LtMacHandle,
		LtNdisWrapperHandle,
		NULL,					//	Context for AddAdapter/Unload
		&LtChar,
		sizeof(LtChar));

	if (Status != NDIS_STATUS_SUCCESS)
	{
		// Can only get here if something went wrong registering the MAC or
		// all of the adapters
		NdisTerminateWrapper(LtNdisWrapperHandle, DriverObject);
	}

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

    PNDIS_CONFIGURATION_PARAMETER pParamValue;


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

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

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

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

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

        found = (status == NDIS_STATUS_SUCCESS);

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

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


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

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


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

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

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

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

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

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

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

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


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

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

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

   return NDIS_STATUS_SUCCESS;
}
Beispiel #22
0
VOID
NdisReadConfiguration(
	OUT PNDIS_STATUS					Status,
	OUT PNDIS_CONFIGURATION_PARAMETER *	ParameterValue,
	IN NDIS_HANDLE						ConfigurationHandle,
	IN PNDIS_STRING						Keyword,
	IN NDIS_PARAMETER_TYPE				ParameterType
	)
/*++

Routine Description:

	This routine is used to read the parameter for a configuration
	keyword from the configuration database.

Arguments:

	Status - Returns the status of the request.

	ParameterValue - Returns the value for this keyword.

	ConfigurationHandle - Handle returned by NdisOpenConfiguration. Points
	to the parameter subkey.

	Keyword - The keyword to search for.

	ParameterType - Ignored on NT, specifies the type of the value.

Return Value:

	None.

--*/
{
	//
	// Status of our requests
	//
	NTSTATUS RegistryStatus;

	//
	// Holds a null-terminated version of the keyword.
	//
	PWSTR KeywordBuffer;

	//
	// index variable
	//
	UINT i;

	//
	// Obtain the actual configuration handle structure
	//
	PNDIS_CONFIGURATION_HANDLE	ConfigHandle = (PNDIS_CONFIGURATION_HANDLE)ConfigurationHandle;
#define	PQueryTable				ConfigHandle->KeyQueryTable

	//
	// There are some built-in parameters which can always be
	// read, even if not present in the registry. This is the
	// number of them.
	//
#define BUILT_IN_COUNT 3

	//
	// The names of the built-in parameters.
	//
	static NDIS_STRING BuiltInStrings[BUILT_IN_COUNT] =
	{
		NDIS_STRING_CONST ("Environment"),
		NDIS_STRING_CONST ("ProcessorType"),
		NDIS_STRING_CONST ("NdisVersion")
	};

	//
	// The values to return for the built-in parameters.
	//
	static NDIS_CONFIGURATION_PARAMETER BuiltInParameters[BUILT_IN_COUNT] =
		{ { NdisParameterInteger, NdisEnvironmentWindowsNt },
		  { NdisParameterInteger,
#if defined(_M_IX86)
			NdisProcessorX86
#elif defined(_M_MRX000)
			NdisProcessorMips
#elif defined(_ALPHA_)
			NdisProcessorAlpha
#else
			NdisProcessorPpc
#endif
		  },
		  { NdisParameterInteger, 0x00040001 }
		};

	ASSERT (KeGetCurrentIrql() < DISPATCH_LEVEL);

	do
	{
		//
		// First check if this is one of the built-in parameters.
		//
		for (i = 0; i < BUILT_IN_COUNT; i++)
		{
			if (RtlEqualUnicodeString(Keyword, &BuiltInStrings[i], TRUE))
			{
				*Status = NDIS_STATUS_SUCCESS;
				*ParameterValue = &BuiltInParameters[i];
				break;
			}
		}
		if (i < BUILT_IN_COUNT)
			break;

		//
		// Allocate room for a null-terminated version of the keyword
		//
		KeywordBuffer = Keyword->Buffer;
		if (Keyword->MaximumLength < (Keyword->Length + sizeof(WCHAR)))
		{
			KeywordBuffer = (PWSTR)ALLOC_FROM_POOL(Keyword->Length + sizeof(WCHAR), NDIS_TAG_DEFAULT);
			if (KeywordBuffer == NULL)
			{
				*Status = NDIS_STATUS_RESOURCES;
				break;
			}
			CopyMemory(KeywordBuffer, Keyword->Buffer, Keyword->Length);
		}
		*(PWCHAR)(((PUCHAR)KeywordBuffer)+Keyword->Length) = (WCHAR)L'\0';

		//
		// Finish initializing the table for this query.
		//
		PQueryTable[0].Name = KeywordBuffer;
		PQueryTable[0].EntryContext = ParameterValue;

		//
		// Get the value from the registry; this chains it on to the
		// parameter list at NdisConfigHandle.
		//

		RegistryStatus = RtlQueryRegistryValues(RTL_REGISTRY_SERVICES,
												PQueryTable[3].Name,
												PQueryTable,
												ConfigHandle,					// context
												NULL);

		if (KeywordBuffer != Keyword->Buffer)
		{
			FREE_POOL(KeywordBuffer);	// no longer needed
		}

		*Status = NDIS_STATUS_SUCCESS;
		if (!NT_SUCCESS(RegistryStatus))
		{
			*Status = NDIS_STATUS_FAILURE;
		}
	} while (FALSE);
#undef	PQueryTable
}
Beispiel #23
0
#include "packet.h"
#include "win_bpf.h"
#include "win_bpf_filter_init.h"

#if DBG
// Declare the global debug flag for this driver.
ULONG PacketDebugFlag = PACKET_DEBUG_LOUD;

#endif

PDEVICE_EXTENSION GlobalDeviceExtension;

//
// Global strings
//
NDIS_STRING NPF_Prefix = NDIS_STRING_CONST("SEE_");
NDIS_STRING devicePrefix = NDIS_STRING_CONST("\\Device\\");
NDIS_STRING symbolicLinkPrefix = NDIS_STRING_CONST("\\DosDevices\\");
NDIS_STRING tcpLinkageKeyName = NDIS_STRING_CONST("\\Registry\\Machine\\System"
								L"\\CurrentControlSet\\Services\\Tcpip\\Linkage");
NDIS_STRING AdapterListKey = NDIS_STRING_CONST("\\Registry\\Machine\\System"
								L"\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}");
NDIS_STRING bindValueName = NDIS_STRING_CONST("Bind");

/// Global variable that points to the names of the bound adapters
WCHAR* bindP = NULL;

extern struct time_conv G_Start_Time; // from openclos.c

extern NDIS_SPIN_LOCK Opened_Instances_Lock;
Beispiel #24
0
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);
}
Beispiel #25
0
/*
 *************************************************************************
 *  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, 
								&regKeyPortString, 
								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, 
							&regKeyIRQString, 
							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, 
							&regKeyIOString, 
							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, 
							&regKeyIRTransceiverString, 
							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;
}
Beispiel #26
0
#include "precomp.h"
#include "st_aplst.h"
#include "st_conn.h"
#include "st_adhoc.h"
#include "st_scan.h"
#include "st_oids.h"

#if DOT11_TRACE_ENABLED
#include "st_main.tmh"
#endif

MP_REG_ENTRY STARegTable[] = {

    {
        NDIS_STRING_CONST("AdhocStationMaxCount"), 
        NdisParameterInteger,
        0,
        FIELD_OFFSET(STA_REG_INFO, AdhocStationMaxCount),
        sizeof(ULONG),
        STA_ADHOC_STA_MAX_ENTRIES_DEFAULT,
        STA_ADHOC_STA_MAX_ENTRIES_MIN,
        STA_ADHOC_STA_MAX_ENTRIES_MAX 
    },

    {
        NDIS_STRING_CONST("BSSEntryExpireTime"), 
        NdisParameterInteger,
        0,
        FIELD_OFFSET(STA_REG_INFO, BSSEntryExpireTime),
        sizeof(ULONG),