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

   DsIoctl.h

Abstract:

   Header file for DSTREAMS API IOCTL function definitions, typedefs and
   structures.

Author:

   Ron Gredvig

--*/

#ifndef _DSIOCTL_
#define _DSIOCTL_

#ifdef _NTDDK_
#include <devioctl.h>		// Kernelmode drivers need this.  Resides in ddk.
#else
#include <winioctl.h>		// Usermode apps need this.  Resides in msdev\include.
#endif

#include "DgDevice.h"

// Define RSVD.  RSVD is used in struct definitions to identify fields which
// are reserved for the DStreams Service Provider.  These fields should be 
// initialized to zero before passing the request to the Provider.

#define RSVD



///////////////////////////////////////////////////////////////////////////////
//
// DStreams API IOCTLs
//

// Open request
#define IOCTL_DS_OPEN			CTL_CODE(FILE_DEVICE_DS,		\
										DIGI_FUNCTION_CODE_START,		\
										METHOD_BUFFERED, 					\
										FILE_ANY_ACCESS)

// Close request
#define IOCTL_DS_CLOSE			CTL_CODE(FILE_DEVICE_DS,		\
										DIGI_FUNCTION_CODE_START + 1,	\
										METHOD_BUFFERED,					\
										FILE_ANY_ACCESS)


#define IOCTL_DS_READ			CTL_CODE(FILE_DEVICE_DS,		\
										DIGI_FUNCTION_CODE_START + 2,	\
										METHOD_BUFFERED,					\
										FILE_ANY_ACCESS)


#define IOCTL_DS_WRITE			CTL_CODE(FILE_DEVICE_DS,		\
										DIGI_FUNCTION_CODE_START + 3,	\
										METHOD_BUFFERED,					\
										FILE_ANY_ACCESS)

// Getmsg request
#define IOCTL_DS_GETMSG			CTL_CODE(FILE_DEVICE_DS,		\
										DIGI_FUNCTION_CODE_START + 4,	\
										METHOD_BUFFERED,					\
										FILE_ANY_ACCESS)

// Putmsg request
#define IOCTL_DS_PUTMSG			CTL_CODE(FILE_DEVICE_DS,		\
										DIGI_FUNCTION_CODE_START + 5,	\
										METHOD_BUFFERED,					\
										FILE_ANY_ACCESS)

// Ioctl request (equivalent to I_STR ioctl command)
#define IOCTL_DS_IOCTL			CTL_CODE(FILE_DEVICE_DS,		\
										DIGI_FUNCTION_CODE_START + 6,	\
										METHOD_BUFFERED,					\
										FILE_ANY_ACCESS)

// Push request (equivalent to I_PUSH ioctl command)
#define IOCTL_DS_PUSH			CTL_CODE(FILE_DEVICE_DS,		\
										DIGI_FUNCTION_CODE_START + 7,	\
										METHOD_BUFFERED,					\
										FILE_ANY_ACCESS)


#define IOCTL_DS_POP				CTL_CODE(FILE_DEVICE_DS,		\
										DIGI_FUNCTION_CODE_START + 8,	\
										METHOD_BUFFERED,					\
										FILE_ANY_ACCESS)

// Link request (equivalent to I_LINK ioctl command)
#define IOCTL_DS_LINK			CTL_CODE(FILE_DEVICE_DS,		\
										DIGI_FUNCTION_CODE_START + 9,	\
										METHOD_BUFFERED,					\
										FILE_ANY_ACCESS)


#define IOCTL_DS_UNLINK			CTL_CODE(FILE_DEVICE_DS,		\
										DIGI_FUNCTION_CODE_START + 10,\
										METHOD_BUFFERED,					\
										FILE_ANY_ACCESS)

// Purge request
#define IOCTL_DS_PURGE			CTL_CODE(FILE_DEVICE_DS,		\
										DIGI_FUNCTION_CODE_START + 11,\
										METHOD_BUFFERED,					\
										FILE_ANY_ACCESS)

//  Request to retrieve number of queued buffers:
#define IOCTL_DS_GETINFO		CTL_CODE(FILE_DEVICE_DS,		\
										DIGI_FUNCTION_CODE_START + 12,\
										METHOD_BUFFERED,					\
										FILE_ANY_ACCESS)


///////////////////////////////////////////////////////////////////////////////
//
// IOCTL Structures
// 
// These structures define the data passed to and from a DStreams Provider
// via the DStreams IOCTLs defined above.  Structure field labeling 
// conventions: 
// 
//    IN:   Input to the request.
//    OUT:  Output returned when the request has completed.  Should be
//          initialized to zero.
//    RSVD: Reserved for use by the DStreams Provider.  Must be initialized
//          to zero.
//

#define DS_DEVICENAME_SIZE  12

typedef struct DS_OPEN
{	
	IN CHAR    DeviceName[DS_DEVICENAME_SIZE];// input DStreams devicename string
	IN ULONG   FixedCost OPTIONAL;		// Optional FCost value.  DxbV2 only.  Limits: 0-255.
	IN PVOID   pUserData OPTIONAL;		// Optional data.  Typically, the device minor number.
	IN ULONG   cbUserData;					// sizeof user data
	OUT HANDLE hStream;						// handle returned identifying opened stream
	OUT LONG   ErrorCode;					// output returned on failure
	RSVD PVOID pProviderData;				// locked data for service provider use
} DS_OPEN, *PDS_OPEN;


typedef struct DS_CLOSE
{
	IN HANDLE hStream;
} DS_CLOSE, *PDS_CLOSE;


typedef struct DS_IOCTL
{
	IN HANDLE  hStream;
	IN ULONG   Command;						// DStreams module Ioctl command
	IN LONG    Timeout;						// timeout value, see below
	IN PVOID   pDataIn;						// data buffer 
	IN ULONG   cbDataIn;						// length of data
	IN PVOID   pDataOut;						// data buffer 
	IN ULONG   cbMaxDataOut;				// length of output data buffer
	OUT ULONG  cbDataOut;					// count of bytes placed in output buffer
	OUT LONG   ReturnValue;					// 0 upon success or -1 if error
	OUT LONG   ErrorCode;					// DSTREAM error code
	RSVD PVOID pProviderDataIn;			// locked data for service provider use 
	RSVD PVOID pProviderDataOut;			// locked data for service provider use 
} DS_IOCTL, *PDS_IOCTL;


// DS_IOCTL.Timeout value:
//   -1  : infinite
//    0  : 15 sec (default)
//    1+ : timeout in seconds


typedef struct DS_PUSH
{
	IN HANDLE hStream;
	IN CHAR   ModuleName[DS_DEVICENAME_SIZE];	// input DStreams module name
	OUT LONG  ReturnValue;					// 0 upon success or -1 if error
	OUT LONG  ErrorCode;						// output DStreams DSTREAM error code
} DS_PUSH, *PDS_PUSH;


typedef struct DS_LINK
{
	IN HANDLE hStreamUpper;
	IN HANDLE hStreamLower;
	OUT LONG  MuxId;							// Muxid upon success or -1 if error
	OUT LONG  ErrorCode;						// DSTREAM error code
} DS_LINK, *PDS_LINK;


typedef enum DS_PRIORITY
{
	DS_PRIORITY_MIN   = 0,
	DS_PRIORITY_ANY   = DS_PRIORITY_MIN,
	DS_PRIORITY_LOW   = DS_PRIORITY_MIN,
	DS_PRIORITY_HIGH,
	DS_PRIORITY_LIM,
	DS_PRIORITY_COUNT = DS_PRIORITY_LIM,
	DS_PRIORITY_MAX   = DS_PRIORITY_LIM-1
} DS_PRIORITY;


typedef struct DS_PUTMSG
{
	IN HANDLE      hStream;
	IN PVOID       pControl;				// input control buffer
	IN ULONG       cbControl;				// length of control
	IN PVOID       pData;					// input data buffer
	IN ULONG       cbData;					// length of data
	IN DS_PRIORITY Priority;				// DS_PRIORITY_* level.  Specify priority level
													// at which this msg should be sent.
	RSVD PVOID     pProviderControl;		// locked control for serviceProvider use
	RSVD PVOID     pProviderData;			// locked data for service provider use
} DS_PUTMSG, *PDS_PUTMSG;


typedef struct DS_GETMSG
{
	IN HANDLE      hStream;
	IN OUT PVOID   pControl;				// control buffer
	IN ULONG       cbMaxControl;			// length of control buffer
	OUT ULONG      cbControl;				// count of bytes placed in control buffer
	IN OUT PVOID   pData;					// data buffer
	IN ULONG       cbMaxData;				// length of data buffer
	OUT ULONG      cbData;					// count of bytes placed in data buffer
	IN DS_PRIORITY Priority;				// DS_PRIORITY_* level.  Accept only messages of
	                                    // this or higher priority level.
	RSVD PVOID     pProviderControl;		// locked control for serviceProvider use
	RSVD PVOID     pProviderData;			// locked data for service provider use
} DS_GETMSG, *PDS_GETMSG;


typedef struct DS_PURGE
{
	IN HANDLE hStream;
	IN ULONG  Flags;							// DS_PURGE_xxx flags defining queue to purge
} DS_PURGE, *PDS_PURGE;

typedef struct DS_GETINFO
{
	IN HANDLE hStream;
	OUT unsigned int CntQueued; // number of queued buffers
} DS_GETINFO, *PDS_GETINFO;


// Flags used in the DS_PURGE Mask field defining which queues should be 
// purged.  These Purge constants are duplicated in DsApi.h!  If you change 
// them here, be sure to update DsApi.h!
#define DS_PURGE_WRITE    0x00000001
#define DS_PURGE_READ     0x00000002
#define DS_PURGE_PUTMSG   0x00000004
#define DS_PURGE_GETMSG   0x00000008
#define DS_PURGE_ALL      0x0000000F

#endif // _DSIOCTL_

