/*++
*******************************************************************************
* 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:

   miniport.h

Abstract:

   This is the header file fro the xwan driver. It contains function prototypes.

Author:

   Jeff Romatoski

Revision History:

--*/

#ifndef MINIPORTH_D
#define MINIPORTH_D

typedef LONG INT;

#define DEVICE_MAX 127

typedef enum XWAN_DEVICE_STATE
{
	XWAN_DEVICE_STATE_OFF,
	XWAN_DEVICE_STATE_DIRECT,
	XWAN_DEVICE_STATE_QUEUING
} XWAN_DEVICE_STATE, *PXWAN_DEVICE_STATE;


// Use the DStreams Miniport DLL interface

#if NT5_BUILD


typedef struct XWAN_ADAPTER
{

	DSMP_DLL_ADAPTER_HANDLE			hAdapter;
	PDSMP_DLL_INTERFACE_ROUTINES	hDllInterface;

} XWAN_ADAPTER, *PXWAN_ADAPTER, **PPXWAN_ADAPTER;

//
// This is the private data structure for each device of this driver. The
// q_ptr element of the read and write queue structures is set to point to this
// structure.
//

typedef struct XWAN_MINIPORT_INSTANCE
{
	LIST_ENTRY				ListEntry;
	PXWAN_ADAPTER			pXwanAdapter;
	ULONG					ulSnid;
	ULONG					ulLineNumber;
	BOOLEAN					bInUse;
} XWAN_MINIPORT_INSTANCE, *PXWAN_MINIPORT_INSTANCE;


//
// This is the private data structure for each open device of this driver. The
// q_ptr element of the read and write queue structures is set to point to this
// structure.
//

typedef struct XWAN_DEVICE_CONTROL
{
	LIST_ENTRY				ListEntry;
	PXWAN_MINIPORT_INSTANCE pXwanMiniportInstance;  // Found at WAN_SID Time
	ULONG					Snid;
	DSMP_DLL_DEVICE_HANDLE	hDevice;				// Handle to the DLL Device for this line
	PQUEUE					pReadQ;		            // back pointer to read queue
	SHORT					DeviceNumber;
	XWAN_DEVICE_STATE		State;
	ULONG					LineStatus;
	ULONG					MaxFrameSize;
	ULONG					BaudRate;
	ULONG					LinkOptions;
	ULONG					Interface;
	queue_t					*traceq ;				// Queue for traces
	ULONG					trace_seq_num;
	ULONG					trace_last_modem;
} XWAN_DEVICE_CONTROL, *PXWAN_DEVICE_CONTROL;


extern NTSTATUS
XwanStartAdapter(	IN	PCWSTR				pOption,
					IN	PDRIVER_OBJECT		pDriverObject,
					IN	PDEVICE_OBJECT		pDeviceObject,
					IN  PUNICODE_STRING		pAdapterName,
					IN	PDIGI_RESOURCE_LIST	pResources,
					IN	ULONG				dwLineCount,
					OUT PPXWAN_ADAPTER		ppXwanAdapter						
	);


extern NTSTATUS
XwanRegisterMiniport( IN PXWAN_ADAPTER	pXwanAdapter,
					  IN ULONG			ulLineNumber,
					  IN ULONG			ulSnid
	);


extern void
XwanDeregisterMiniports(IN PXWAN_ADAPTER	pXwanAdapter
	);

extern NTSTATUS
XwanStopAdapter(	IN PXWAN_ADAPTER	pXwanAdapter						
	);


// Macros
#define XWAN_CONNECTED(ptr) (((PXWAN_DEVICE_CONTROL) ptr)->hDevice ? TRUE : FALSE)


#else	// NT5_BUILD

// Use the NT IOCTL Miniport Interface (used by NT4)

//
// This is the private data structure for each open device of this driver. The
// q_ptr element of the read and write queue structures is set to point to this
// structure.
//

typedef struct XWAN_MINIPORT_INSTANCE
{
	LIST_ENTRY      ListEntry;
	UNICODE_STRING	ucMiniportDeviceName;
	ULONG		    ulSnid;
	BOOLEAN		    bInUse;
} XWAN_MINIPORT_INSTANCE, *PXWAN_MINIPORT_INSTANCE;


//
// This is the private data structure for each open device of this driver. The
// q_ptr element of the read and write queue structures is set to point to this
// structure.
//

typedef struct XWAN_DEVICE_CONTROL
{
	LIST_ENTRY				ListEntry;
	PXWAN_MINIPORT_INSTANCE pXwanMiniportInstance;  // Found at WAN_SID Time
	ULONG					Snid;
	PFILE_OBJECT			pMiniportFileObject;
	PDEVICE_OBJECT			pMiniportDeviceObject;
	PQUEUE					pReadQ;		            // back pointer to read queue
	SHORT					DeviceNumber;
	XWAN_DEVICE_STATE		State;
	ULONG					LineStatus;
	ULONG					MaxFrameSize;
	ULONG					BaudRate;
	ULONG					LinkOptions;
	ULONG					Interface;
	queue_t					*traceq ;				// Queue for traces
	ULONG					trace_seq_num;
	ULONG					trace_last_modem;
} XWAN_DEVICE_CONTROL, *PXWAN_DEVICE_CONTROL;


static NTSTATUS
XwanPutFrame( IN PXWAN_DEVICE_CONTROL pDevCtl,
			  IN PMSGB pMsgData
	);

static PMSGB
XwanGetFrame( IN PXWAN_DEVICE_CONTROL pDevCtl,
			  IN SHORT FrameSize
	);

extern NTSTATUS
XwanRegisterMiniport( IN PWSTR pwMiniPortAdapterName,
					  IN PWSTR pwDeviceSuffix,
					  IN ULONG ulSnid
	);

extern void
XwanDeregisterMiniports(
	);

// Macros
#define XWAN_CONNECTED(ptr) (((PXWAN_DEVICE_CONTROL) ptr)->pMiniportDeviceObject ? TRUE : FALSE)


#endif	// NT5_BUILD	

BOOLEAN
XwanConnectToMiniport( IN PXWAN_DEVICE_CONTROL pDevCtl,
					   IN ULONG ulSnid
	);

NTSTATUS
XwanLinkMiniport( IN PXWAN_DEVICE_CONTROL		pDevCtl,
				  IN PXWAN_MINIPORT_INSTANCE	pXwanMiniportInstance
	);

VOID
XwanDisconnectFromMiniport( IN PXWAN_DEVICE_CONTROL		pDevCtl,
						    IN PXWAN_MINIPORT_INSTANCE	pXwanMiniportInstance
	);

NTSTATUS
XwanMiniportIo( IN ULONG IoCode,
				IN PXWAN_DEVICE_CONTROL pDevCtl,
				IN PVOID pIoBuffer,
				IN ULONG IoBufferLength 
	);

static PXWAN_DEVICE_CONTROL
XwanFindDevice( IN PQUEUE pQ,
			    IN ULONG Snid
	);

#endif	// MINIPORTH_D
