/*++
 * Copyright (c) 1990-96 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
 *
 *
 * 
--*/

#ifndef _DSMP_H
#define _DSMP_H

#include "DgDevice.h"

//  GETFRAME function parameters 

//  Structure for GETFRAME 

typedef struct _DSMP_GETFRAME
{
	HANDLE	Context;
	ULONG	DataMaxLength;
	ULONG	DataLength;
	PUCHAR	pUserDataBuffer;	// ptr to user data (for client use)
	PUCHAR	pDataBuffer;		// ptr to locked data (for service provider use)
} DSMP_GETFRAME, *PDSMP_GETFRAME;



// PUTFRAME function parameters 

//	Structure for PUTFRAME 

typedef struct _DSMP_PUTFRAME
{
	HANDLE	Context;
	ULONG	DataLength;
	PUCHAR	pUserDataBuffer;	// ptr to user data (for client use)
	PUCHAR	pDataBuffer;		// ptr to locked data (for service provider use)
} DSMP_PUTFRAME, *PDSMP_PUTFRAME;




// SETCONFIG/GETCONFIG function parameters

//    Values for wInterface field 

#define DSMP_X21		0	// V.11/EIA-422 - DB 15 
#define DSMP_V28		1	// V.28/EIA-232 - DB 25 (V24 would be a better name)
#define DSMP_V35		2	// V.11/EIA-422 data, V.28/EIA-232 control - 34 pin
#define DSMP_V36		3	// V.11/EIA-422 - DB25
#define DSMP_CSUDSU		6	// integrated CSU/DSU with leased line
#define DSMP_SW56		7	// integrated CSU/DSU with SW56 service
#define DSMP_V35RS232	8	// V35 or RS232
#define DSMP_530		9	// EIA 530
#define DSMP_LOOPBACK	10	// LOOPBACK
#define DSMP_NO_CABLE 	11	// NO_CABLE
#define	DSMP_UNKNOWN	12

//    Values for LinkOptions field 
#define	DSMP_LO_NRZI		0x1		// 0000 000x NRZI = 1, NRZ = 0
#define	DSMP_LO_RTS_HIGH	0x2		// 0000 00x0 RTS HIGH = 1, TOGGLE RTS = 0
#define	DSMP_LO_EXT_CLOCK	0x4		// 0000 0x00 EXT CLOCK = 1, INT CLOCK = 0
#define	DSMP_LO_WAIT_CTS	0x8		// 0000 x000 WAIT CTS = 1, SEND DONT WAIT = 0

//	Structure containing configurable elements 

typedef struct _DSMP_CONFIG
{
	HANDLE	Context;		// context for completion routine 
    USHORT	MaxFrameSize;	// maximum frame size
	USHORT	Interface;		// phys interface: V.24, V.11, V.35, CSU/DSU, SW56 
    ULONG	BaudRate;		// baud rate
	UCHAR	StationAddress1;// Station Filter address 1
	UCHAR	StationAddress2;// Station Filter address 2
	UCHAR	LinkOptions;	// Link Options
} DSMP_CONFIG, *PDSMP_CONFIG;


//  SETMODEM/GETMODEM function parameters 

//  Bit values for modem signals

#define	DSMP_DTR	0x01
#define	DSMP_RTS	0x02
#define	DSMP_CTS	0x04
#define	DSMP_DSR	0x08
#define	DSMP_DCD	0x10

//  Structure containing current modem signal state and mask

typedef struct _DSMP_MODEM
{
    UCHAR	Mask;				// Mask of bits to affect (SET only) 
    UCHAR	State;				// State of bits (SET/GET)  
} DSMP_MODEM, *PDSMP_MODEM;


// GETSTATs function parameters 

//	Structure for HDLC statistics

typedef struct _DSMP_STATS
{
	ULONG	TxFrames;			// Number of good frames transmitted
	ULONG	TxBytes;			// Number of good UCHARs transmitted
	ULONG	TxUnderrun;			// Number of transmit underruns
	ULONG	RxFrames;			// Number of good frames received
	ULONG	RxBytes;			// Number of good UCHARs received
	ULONG	RxOverrun;			// Number of receive overruns
	ULONG	RxCrc;				// Number of receive CRC/Framing errors
	ULONG	RxNoBuf;			// Number of Rx frames with no buffer
	ULONG	RxNoFlow;			// Number of Rx frames with no flow ctl
	ULONG	RxOverflow;			// Number of receive buffer overflows
	ULONG	RxAbort;			// Number of receive aborts
	ULONG	TxAbort;			// Number of tx aborts (hdplx only)
} DSMP_STATS, *PDSMP_STATS;


//
// Miniport Driver DLL API interface defintions
//

#if NT5_BUILD


typedef enum DllInterfaceId {
	DDL_INTF_GETFRAME = 5000,
	DDL_INTF_PUTFRAME,
	DDL_INTF_GETCONFIG,
	DDL_INTF_SETCONFIG,
	DDL_INTF_GETMODEM,
	DDL_INTF_SETMODEM,
	DDL_INTF_GETSTATS,
	DDL_INTF_ZEROSTATS

} DllInterfaceId_t;

// Generic Interface Defines
#define DSMP_GENERIC_GETFRAME	DDL_INTF_GETFRAME 
#define DSMP_GENERIC_PUTFRAME	DDL_INTF_PUTFRAME 
#define DSMP_GENERIC_GETCONFIG	DDL_INTF_GETCONFIG 
#define DSMP_GENERIC_SETCONFIG	DDL_INTF_SETCONFIG 
#define DSMP_GENERIC_GETMODEM	DDL_INTF_GETMODEM 
#define DSMP_GENERIC_SETMODEM	DDL_INTF_SETMODEM 
#define DSMP_GENERIC_GETSTATS	DDL_INTF_GETSTATS 
#define DSMP_GENERIC_ZEROSTATS	DDL_INTF_ZEROSTATS 

typedef HANDLE DSMP_DLL_ADAPTER_HANDLE, *PDSMP_DLL_ADAPTER_HANDLE;
typedef HANDLE DSMP_DLL_DEVICE_HANDLE,  *PDSMP_DLL_DEVICE_HANDLE;


typedef NTSTATUS 
	(*PDSMP_DLL_START_ADAPTER) ( 
		IN	PDRIVER_OBJECT				pDriverObject,
		IN	PDEVICE_OBJECT				pDeviceObject,
		IN  PUNICODE_STRING				pAdapterName,
		IN	PDIGI_RESOURCE_LIST			pResources,
		IN	ULONG						dwLineCount,
		OUT	PDSMP_DLL_ADAPTER_HANDLE	phAdapter
	);

typedef NTSTATUS 
	(*PDSMP_DLL_OPEN_DEVICE) ( 
		IN	DSMP_DLL_ADAPTER_HANDLE		hAdapter,
		IN	ULONG						ulLineNumber,
		OUT	PDSMP_DLL_DEVICE_HANDLE		phDevice
	);

typedef NTSTATUS 
	(*PDSMP_DLL_GET_FRAME) ( 
		IN	DSMP_DLL_DEVICE_HANDLE		hDevice,
		IN	PDSMP_GETFRAME				pGetFrame
	);


typedef NTSTATUS 
	(*PDSMP_DLL_PUT_FRAME) ( 
		IN	DSMP_DLL_DEVICE_HANDLE		hDevice,
		IN	PDSMP_PUTFRAME				pPutFrame
	);

typedef NTSTATUS 
	(*PDSMP_DLL_GET_CONFIG) ( 
		IN	DSMP_DLL_DEVICE_HANDLE		hDevice,
		IN	PDSMP_CONFIG				pConfig
	);

typedef NTSTATUS 
	(*PDSMP_DLL_SET_CONFIG) ( 
		IN	DSMP_DLL_DEVICE_HANDLE		hDevice,
		IN	PDSMP_CONFIG				pConfig
	);


typedef NTSTATUS 
	(*PDSMP_DLL_GET_MODEM) ( 
		IN	DSMP_DLL_DEVICE_HANDLE		hDevice,
		IN	PDSMP_MODEM					pModem
	);

typedef NTSTATUS 
	(*PDSMP_DLL_SET_MODEM) ( 
		IN	DSMP_DLL_DEVICE_HANDLE		hDevice,
		IN	PDSMP_MODEM					pModem
	);


typedef NTSTATUS 
	(*PDSMP_DLL_GET_STATS) ( 
		IN	DSMP_DLL_DEVICE_HANDLE		hDevice,
		IN	PDSMP_STATS					pStats
	);

typedef NTSTATUS 
	(*PDSMP_DLL_ZERO_STATS) ( 
		IN	DSMP_DLL_DEVICE_HANDLE		hDevice
	);

typedef NTSTATUS 
	(*PDSMP_DLL_CLOSE_DEVICE) ( 
		IN	DSMP_DLL_DEVICE_HANDLE		hDevice
	);


typedef NTSTATUS 
	(*PDSMP_DLL_STOP_ADAPTER) ( 
		IN	DSMP_DLL_ADAPTER_HANDLE		hAdapter
	);

// Interface Routines - Routines pointers are set at Init Time
typedef struct DSMP_DLL_INTERFACE_ROUTINES
{
	PDSMP_DLL_START_ADAPTER	StartAdapter;	// Start the Adapter 
	PDSMP_DLL_OPEN_DEVICE	OpenDevice;		// Open a Device (A line on the board)
	PDSMP_DLL_GET_FRAME		GetFrame;		// Receive a Frame
	PDSMP_DLL_PUT_FRAME		PutFrame;		// Send a Frame
	PDSMP_DLL_GET_CONFIG		GetConfig;		// Get the Configuration Information
	PDSMP_DLL_SET_CONFIG		SetConfig;		// Set the Configuration Information
	PDSMP_DLL_GET_MODEM		GetModem;		// Get the Modem Information
	PDSMP_DLL_SET_MODEM		SetModem;		// Set the Modem Information
	PDSMP_DLL_GET_STATS		GetStats;		// Get the Stats for a device
	PDSMP_DLL_ZERO_STATS		ZeroStats;		// Zero the Stats for a device
	PDSMP_DLL_CLOSE_DEVICE	CloseDevice;	// Close a Device (A line on the board)
	PDSMP_DLL_STOP_ADAPTER	StopAdapter;	// Stop the Adapter 

} DSMP_DLL_INTERFACE_ROUTINES, *PDSMP_DLL_INTERFACE_ROUTINES, **PPDSMP_DLL_INTERFACE_ROUTINES;


// Initialization interface routine
typedef PDSMP_DLL_INTERFACE_ROUTINES 
	(*PDSMP_DLL_INITIALIZE) (
	);

// Options Table
typedef struct DSMP_DLL_ADAPTER_OPTION
{
	PCWSTR					Name;			// Adapter Option name string
	PDSMP_DLL_INITIALIZE	InitRoutine;	// DLL Initialization routine
	ULONG					ulCount;		// Count of DLL users

} DSMP_DLL_ADAPTER_OPTION, *PDSMP_DLL_ADAPTER_OPTION;

#else	// NT5_BUILD

//
// Miniport Driver IOCTL API definitions
//

//
// We start our own function codes at 2048, because Microsoft has reserved
// 0-2047 for itself, and 2048-4095 for others.
//
#define DIGI_DSMP_FUNCTION_CODE_START   2048

//
// Define our Ioctl functions
//

#define IOCTL_DSMP_GETFRAME		CTL_CODE(FILE_DEVICE_DSMP, \
									DIGI_DSMP_FUNCTION_CODE_START, \
									METHOD_BUFFERED, \
									FILE_ANY_ACCESS)

#define IOCTL_DSMP_PUTFRAME		CTL_CODE(FILE_DEVICE_DSMP, \
									DIGI_DSMP_FUNCTION_CODE_START + 1, \
									METHOD_BUFFERED, \
									FILE_ANY_ACCESS)
																		   
#define IOCTL_DSMP_GETCONFIG	CTL_CODE(FILE_DEVICE_DSMP, \
									DIGI_DSMP_FUNCTION_CODE_START + 2, \
									METHOD_BUFFERED, \
									FILE_ANY_ACCESS)

#define IOCTL_DSMP_SETCONFIG	CTL_CODE(FILE_DEVICE_DSMP, \
									DIGI_DSMP_FUNCTION_CODE_START + 3, \
									METHOD_BUFFERED, \
									FILE_ANY_ACCESS)

#define IOCTL_DSMP_GETMODEM		CTL_CODE(FILE_DEVICE_DSMP, \
									DIGI_DSMP_FUNCTION_CODE_START + 4, \
									METHOD_BUFFERED, \
									FILE_ANY_ACCESS)

#define IOCTL_DSMP_SETMODEM		CTL_CODE(FILE_DEVICE_DSMP, \
									DIGI_DSMP_FUNCTION_CODE_START + 5, \
									METHOD_BUFFERED, \
									FILE_ANY_ACCESS)

#define IOCTL_DSMP_GETSTATS		CTL_CODE(FILE_DEVICE_DSMP, \
									DIGI_DSMP_FUNCTION_CODE_START + 6, \
									METHOD_BUFFERED, \
									FILE_ANY_ACCESS)

#define IOCTL_DSMP_ZEROSTATS	CTL_CODE(FILE_DEVICE_DSMP, \
									DIGI_DSMP_FUNCTION_CODE_START + 7, \
									METHOD_BUFFERED, \
									FILE_ANY_ACCESS)


// Generic Interface Defines
#define DSMP_GENERIC_GETFRAME	IOCTL_DSMP_GETFRAME 
#define DSMP_GENERIC_PUTFRAME	IOCTL_DSMP_PUTFRAME
#define DSMP_GENERIC_GETCONFIG	IOCTL_DSMP_GETCONFIG 
#define DSMP_GENERIC_SETCONFIG	IOCTL_DSMP_SETCONFIG 
#define DSMP_GENERIC_GETMODEM	IOCTL_DSMP_GETMODEM 
#define DSMP_GENERIC_SETMODEM	IOCTL_DSMP_SETMODEM 
#define DSMP_GENERIC_GETSTATS	IOCTL_DSMP_GETSTATS 
#define DSMP_GENERIC_ZEROSTATS	IOCTL_DSMP_ZEROSTATS 


#endif // NT5_BUILD

#endif // _DSMP_H


