/*++
*******************************************************************************
* Copyright (c) 1990-97 Digi International Inc., All Rights Reserved
* 
* This software contains proprietary and confidential information of Digi
* International Inc.  By accepting transfer of this copy, Recipient agrees
* to retain this software in confidence, to prevent disclosure to others,
* and to make no use of this software other than that for which it was
* delivered.  This is an unpublished copyrighted work of Digi International
* Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
* prohibited.
* 
* Restricted Rights Legend
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7031 or
* subparagraphs (c)(1) and (2) of the Commercial Computer Software -
* Restricted Rights at 48 CFR 52.227-19, as applicable.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
*
*******************************************************************************

Module Name:

   init.c

Abstract:

   Common startup and initialization code for driver.

Author:

   Michael Zarns

--*/

#include <ntddk.h>
#include "digilib.h"
#include "debug.h"
#include "Stress.h"
#include "dsapi.h"


///////////////////////////////////////////////////////////////////////////////
//
// Global Data
//

PDRIVER_OBJECT gpDriverObject;

// Debug 
BOOLEAN bShouldBreak = FALSE;
BOOLEAN bDontLoadDriver = FALSE;


///////////////////////////////////////////////////////////////////////////////
//
// Routines
//

VOID
StressUnload(
	PDRIVER_OBJECT pDriverObject )
/*++

Description:

	Called before unloading driver to cleaup resource allocation.

Parameters:

	pDriverObject
		Identifies our Driver object.

Return Value:

	None

--*/
{
	DigiDump( DIGIFLOW, ( "Stress: Enter StressUnload\n"
								 "   pDriverObject 0x%x\n",
								 pDriverObject ) );

	ASSERT( pDriverObject == gpDriverObject );

	Cleanup();
	DigiDump( DIGIFLOW, ( "Stress: Leave StressUnload\n" ) );

#if DBG
	MemPrintQuit();
#endif
}


NTSTATUS
DriverEntry(
	IN PDRIVER_OBJECT pDriverObject, 
	IN PUNICODE_STRING pRegistryPath )
/*++

Description:

	Standard NT driver entry point.

Parameters:

	pDriverObject
		Address of driver object for this driver.

	pRegistryPath
		Unicode string defining the CurrentControlSet\Services\Xxx key for this driver.

Return Value:

	STATUS_SUCCESS to stay loaded,
	STATUS_FAILURE or other error explaining why it couldn't load.

--*/
{
	NTSTATUS Status = STATUS_SUCCESS;

	// Save the pointer to my driver object
	gpDriverObject = pDriverObject;

	DigiInitMem( 'rtSD' );	//  DigiAllocMemory tag (in reverse 'DStr')

	DebugGetRegParams( pRegistryPath, &bShouldBreak );

	if ( bShouldBreak )
		DbgBreakPoint();

	if ( bDontLoadDriver )
		return( STATUS_CANCELLED );

#if DBG
	MemPrintInitialize( "\\SystemRoot\\DigiGen.log" );
#endif

	DigiDump( DIGIINIT, ( "Stress: Enter DriverEntry\n" 
	                      "   pDriverObject 0x%x\n"
	                      "   RegistryPath %x\n", 
	                      pDriverObject, pRegistryPath ) );

	// Initialize driver object dispatch table
	pDriverObject->DriverUnload                         = StressUnload;
	pDriverObject->MajorFunction[IRP_MJ_CREATE]         = StressCreate;
	pDriverObject->MajorFunction[IRP_MJ_CLOSE]          = StressClose;
	pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = StressDeviceControl;

	// Test Code
	Status = OpenLinks();
	if ( Status == STATUS_SUCCESS )
		RunStress();

	DigiDump( DIGIINIT, ( "Stress: Leave DriverEntry, status 0x%x\n", Status ) );

#if DBG
	if ( !NT_SUCCESS( Status ) )
		MemPrintQuit();
#endif
	return( Status );
}


