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

   x25mib.h

Abstract:

    X.25 MIB SNMP Extension Agent for Windows NT.

    These files (x25dll.c, x25mib.c, and x25mib.h) provide an 
    Extension Agent DLL which works in conjunction with the SNMP 
    Extendible Agent for Windows NT.

    This SNMP Extension Agent was derived from the sample on the Microsoft
    Developer's Toolkit. See the "Microsoft Windows/NT SNMP Programmer's Reference".

Author:

   Carl Caldwell

Revision History:

   $History: x25mib.h $
 * 
 * *****************  Version 10  *****************
 * User: Mikez        Date: 7/08/97    Time: 9:49a
 * Updated in $/Components/Windows/NT/Sync/SxbSnmp/x25
 * Updated to support DStreams API.

--*/
#ifndef x25mib_h
#define x25mib_h

#include <snmp.h>
#include "x25sxb.h"

// MIB Specifics.
#define MIB_PREFIX_LEN            MIB_OidPrefix.idLength
#define MAX_STRING_LEN            255

// The following definitions are those of the Admin Table
//
#define X25_ADMN_FIRST_Index						0	
#define X25_ADMN_FIRST_InterfaceMode				1
#define X25_ADMN_FIRST_MaxActiveCircuits			2
#define X25_ADMN_FIRST_PacketSequencing				3
#define X25_ADMN_FIRST_RestartTimer					4
#define X25_ADMN_FIRST_CallTimer					5
#define X25_ADMN_FIRST_ResetTimer					6
#define X25_ADMN_FIRST_ClearTimer					7
#define X25_ADMN_FIRST_WindowTimer					8
#define X25_ADMN_FIRST_DataRxmtTimer				9
#define X25_ADMN_FIRST_InterruptTimer				10
#define X25_ADMN_FIRST_RejectTimer					11
#define X25_ADMN_FIRST_RegistrationRequestTimer		12
#define X25_ADMN_FIRST_MinimumRecallTimer			13
#define X25_ADMN_FIRST_RestartCount					14
#define X25_ADMN_FIRST_ResetCount					15
#define X25_ADMN_FIRST_ClearCount					16
#define X25_ADMN_FIRST_DataRxmtCount				17
#define X25_ADMN_FIRST_RejectCount					18
#define X25_ADMN_FIRST_RegistrationRequestCount		19
#define X25_ADMN_FIRST_NumberPVCs					20
#define X25_ADMN_FIRST_DefCallParamId				21
#define X25_ADMN_FIRST_LocalAddress					22
#define X25_ADMN_FIRST_ProtocolVersionSupported		23

// The following definitions are those of the operations Table
//
#define X25_OPER_FIRST_Index						24
#define X25_OPER_FIRST_InterfaceMode				25
#define X25_OPER_FIRST_MaxActiveCircuits			26
#define X25_OPER_FIRST_PacketSequencing				27
#define X25_OPER_FIRST_RestartTimer					28
#define X25_OPER_FIRST_CallTimer					29
#define X25_OPER_FIRST_ResetTimer					30
#define X25_OPER_FIRST_ClearTimer					31
#define X25_OPER_FIRST_WindowTimer					32
#define X25_OPER_FIRST_DataRxmtTimer				33
#define X25_OPER_FIRST_InterruptTimer				34
#define X25_OPER_FIRST_RejectTimer					35
#define X25_OPER_FIRST_RegistrationRequestTimer		36
#define X25_OPER_FIRST_MinimumRecallTimer			37
#define X25_OPER_FIRST_RestartCount					38
#define X25_OPER_FIRST_ResetCount					39
#define X25_OPER_FIRST_ClearCount					40
#define X25_OPER_FIRST_DataRxmtCount				41
#define X25_OPER_FIRST_RejectCount					42
#define X25_OPER_FIRST_RegistrationRequestCount		43
#define X25_OPER_FIRST_NumberPVCs					44
#define X25_OPER_FIRST_DefCallParamId				45
#define X25_OPER_FIRST_LocalAddress					46
#define X25_OPER_FIRST_DataLinkId					47
#define X25_OPER_FIRST_ProtocolVersionSupported		48

// The following definitions are those of the Stats Table
//
#define X25_STAT_FIRST_Index						49
#define X25_STAT_FIRST_InCalls						50
#define X25_STAT_FIRST_InCallRefusals				51
#define X25_STAT_FIRST_ProviderInitiatedClears		52
#define X25_STAT_FIRST_RemotelyInitiatedResets		53
#define X25_STAT_FIRST_ProviderInitiatedResets		54
#define X25_STAT_FIRST_InRestarts					55
#define X25_STAT_FIRST_InDataPackets				56
#define X25_STAT_FIRST_InAccusedOfProtocolErrors	57
#define X25_STAT_FIRST_InInterrupts					58
#define X25_STAT_FIRST_OutCallAttempts				59
#define X25_STAT_FIRST_OutCallFailures				60
#define X25_STAT_FIRST_OutInterrupts				61
#define X25_STAT_FIRST_OutDataPackets				62
#define X25_STAT_FIRST_OutgoingCircuits				63
#define X25_STAT_FIRST_IncomingCircuits				64
#define X25_STAT_FIRST_TwoWayCircuits				65
#define X25_STAT_FIRST_RestartTimeouts				66
#define X25_STAT_FIRST_CallTimeouts					67
#define X25_STAT_FIRST_ResetTimeouts				68
#define X25_STAT_FIRST_ClearTimeouts				69
#define X25_STAT_FIRST_RxmtTimeouts					70
#define X25_STAT_FIRST_InterruptTimeouts			71
#define X25_STAT_FIRST_RetryCountExceededs			72
#define X25_STAT_FIRST_ClearCountExceededs			73

// The following definitions are those of the CHANNEL_FIRST_ Table
//
#define X25_CHANNEL_FIRST_Index						74
#define X25_CHANNEL_FIRST_LIC						75
#define X25_CHANNEL_FIRST_HIC						76
#define X25_CHANNEL_FIRST_LTC						77
#define X25_CHANNEL_FIRST_HTC						78
#define X25_CHANNEL_FIRST_LOC						79
#define X25_CHANNEL_FIRST_HOC						80

// The following definitions are those of the CHANNEL_FIRST_ Table
//
#define X25_CIRCUIT_FIRST_Index						81
#define X25_CIRCUIT_FIRST_Channel					82
#define X25_CIRCUIT_FIRST_Status					83
#define X25_CIRCUIT_FIRST_EstablishTime				84
#define X25_CIRCUIT_FIRST_Direction					85
#define X25_CIRCUIT_FIRST_InOctets					86
#define X25_CIRCUIT_FIRST_InPdus					87
#define X25_CIRCUIT_FIRST_RemotelyInitiatedResets	88
#define X25_CIRCUIT_FIRST_ProviderInitiatedResets	89
#define X25_CIRCUIT_FIRST_InInterrupts				90
#define X25_CIRCUIT_FIRST_OutOctets					91
#define X25_CIRCUIT_FIRST_OutPdus					92
#define X25_CIRCUIT_FIRST_OutInterrupts				93
#define X25_CIRCUIT_FIRST_DataRetransmissionTimeouts 94
#define X25_CIRCUIT_FIRST_ResetTimeouts				95
#define X25_CIRCUIT_FIRST_InterruptTimeouts			96
#define X25_CIRCUIT_FIRST_CallParamId				97
#define X25_CIRCUIT_FIRST_CalledDteAddress			98
#define X25_CIRCUIT_FIRST_CallingDteAddress			99 
#define X25_CIRCUIT_FIRST_OriginallyCalledAddress	100
#define X25_CIRCUIT_FIRST_CircuitDescr				101
 
// The following definitions are those of the Cleared CHANNEL_FIRST Table
//
#define X25_CLEARED_CIRCUIT_EntriesRequested_NDX	102
#define X25_CLEARED_CIRCUIT_EntriesGranted_NDX		103
 
#define X25_CLEARED_CIRCUIT_FIRST_Index				104
#define X25_CLEARED_CIRCUIT_FIRST_PleIndex			105
#define X25_CLEARED_CIRCUIT_FIRST_TimeEstablished	106
#define X25_CLEARED_CIRCUIT_FIRST_TimeCleared		107
#define X25_CLEARED_CIRCUIT_FIRST_Channel			108
#define X25_CLEARED_CIRCUIT_FIRST_ClearingCause		109
#define X25_CLEARED_CIRCUIT_FIRST_DiagnosticCode	110
#define X25_CLEARED_CIRCUIT_FIRST_InPdus			111
#define X25_CLEARED_CIRCUIT_FIRST_OutPdus			112
#define X25_CLEARED_CIRCUIT_FIRST_CalledAddress		113
#define X25_CLEARED_CIRCUIT_FIRST_CallingAddress	114
#define X25_CLEARED_CIRCUIT_FIRST_Facilities		115
 
// The following definitions are those of the Call Parm Table
//
#define X25_CALL_PARM_FIRST_Index					116
#define X25_CALL_PARM_FIRST_Status					117
#define X25_CALL_PARM_FIRST_RefCount				118
#define X25_CALL_PARM_FIRST_InPacketSize			119
#define X25_CALL_PARM_FIRST_OutPacketSize			120
#define X25_CALL_PARM_FIRST_InWindowSize			121
#define X25_CALL_PARM_FIRST_OutWindowSize			122
#define X25_CALL_PARM_FIRST_AcceptReverseCharging	123
#define X25_CALL_PARM_FIRST_ProposeReverseCharging	124
#define X25_CALL_PARM_FIRST_FastSelect				125
#define X25_CALL_PARM_FIRST_InThruputClasSize		126
#define X25_CALL_PARM_FIRST_OutThruputClasSize		127
#define X25_CALL_PARM_FIRST_Cug						128
#define X25_CALL_PARM_FIRST_Cugoa					129
#define X25_CALL_PARM_FIRST_Bcug					130
#define X25_CALL_PARM_FIRST_Nui						131
#define X25_CALL_PARM_FIRST_ChargingInfo			132
#define X25_CALL_PARM_FIRST_Rpoa					133
#define X25_CALL_PARM_FIRST_TrnstDly				134
#define X25_CALL_PARM_FIRST_CallingExt				135
#define X25_CALL_PARM_FIRST_CalledExt				136
#define X25_CALL_PARM_FIRST_InMinThuPutCls			137
#define X25_CALL_PARM_FIRST_OutMinThuPutCls			138
#define X25_CALL_PARM_FIRST_EndTrnsDly				139
#define X25_CALL_PARM_FIRST_Priority				140
#define X25_CALL_PARM_FIRST_Protection				141
#define X25_CALL_PARM_FIRST_ExcptData				142
#define X25_CALL_PARM_FIRST_UserData				143
#define X25_CALL_PARM_FIRST_CallingNetworkFacilities 144
#define X25_CALL_PARM_FIRST_CalledNetworkFacilities	145

//// Ranges and limits for specific MIB variables.
//   Frame Relay DLCMI Table Constants

//   Frame Relay DLCMI State limits
#define X25_DLCMI_STATE_NO_LMI_CONFIGURED      1
#define X25_DLCMI_STATE_LMI_REV_1              2
#define X25_DLCMI_STATE_ANSI_T1_617_D          3
#define X25_DLCMI_STATE_ANSI_T1_617_B          4
#define X25_DLCMI_STATE_MIN                    X25_DLCMI_STATE_NO_LMI_CONFIGURED
#define X25_DLCMI_STATE_MAX                    X25_DLCMI_STATE_ANSI_T1_617_B 

//   Frame Relay DLCMI Address limits
#define X25_DLCMI_ADDRESS_Q921                 1
#define X25_DLCMI_ADDRESS_Q922_MARCH_90        2
#define X25_DLCMI_ADDRESS_Q922_NOVEMBER_90     3
#define X25_DLCMI_ADDRESS_Q922                 4
#define X25_DLCMI_ADDRESS_MIN                  X25_DLCMI_ADDRESS_Q921
#define X25_DLCMI_ADDRESS_MAX                  X25_DLCMI_ADDRESS_Q922

//   Frame Relay DLCMI Address Len limits
#define X25_DLCMI_ADDRESS_LEN_2_OCTETS         2
#define X25_DLCMI_ADDRESS_LEN_3_OCTETS         3
#define X25_DLCMI_ADDRESS_LEN_4_OCTETS         4
#define X25_DLCMI_ADDRESS_LEN_MIN              X25_DLCMI_ADDRESS_LEN_2_OCTETS    
#define X25_DLCMI_ADDRESS_LEN_MAX              X25_DLCMI_ADDRESS_LEN_4_OCTETS

//   Frame Relay Polling Interval limits
#define X25_DLCMI_POLLING_INTERVAL_MIN         5
#define X25_DLCMI_POLLING_INTERVAL_MAX         30

//   Frame Relay Full Enquiry Interval limits
#define X25_DLCMI_FULL_ENQUIRY_INTERVAL_MIN    1
#define X25_DLCMI_FULL_ENQUIRY_INTERVAL_MAX    255

//   Frame Relay Error Threshold limits
#define X25_DLCMI_ERROR_THRESHOLD_MIN          1
#define X25_DLCMI_ERROR_THRESHOLD_MAX          10

//   Frame Relay DLCMI Multicast variable limits
#define X25_DLCMI_MULTICAST_NON_BROADCAST      1
#define X25_DLCMI_MULTICAST_BROADCAST          2
#define X25_DLCMI_MULTICAST_MIN                X25_DLCMI_MULTICAST_NON_BROADCAST
#define X25_DLCMI_MULTICAST_MAX                X25_DLCMI_MULTICAST_BROADCAST

//   Frame Relay Circuit Table Constants
#define X25_CKT_STATE_INVALID                  1
#define X25_CKT_STATE_ACTIVE                   2
#define X25_CKT_STATE_INACTIVE                 3
#define X25_CKT_STATE_MIN                      X25_CKT_STATE_INVALID
#define X25_CKT_STATE_MAX                      X25_CKT_STATE_INACTIVE

//   Frame Relay Error Table Constants
#define X25_ERR_TYPE_UNKNOWN_ERR               1
#define X25_ERR_TYPE_RECEIVE_SHORT             2
#define X25_ERR_TYPE_RECEIVE_LONG              3
#define X25_ERR_TYPE_ILLEGAL_DLCI              4
#define X25_ERR_TYPE_UNKNOWN_DLCI              5
#define X25_ERR_TYPE_DLCMI_PROTO_ERR           6
#define X25_ERR_TYPE_DLCMI_UNKNOWN_IE          7
#define X25_ERR_TYPE_DLCMI_SEQUENCE_ERR        8
#define X25_ERR_TYPE_DLCMI_UNKNOWN_RPT         9
#define X25_ERR_TYPE_NO_ERR_SINCE_RESET        10
#define X25_ERR_TYPE_MIN                       X25_ERR_TYPE_UNKNOWN_ERR
#define X25_ERR_TYPE_MAX                       X25_ERR_TYPE_NO_ERR_SINCE_RESET

#define	X25_CALL_ADDRESS_SIZE	20
#define	X25_FACILITIES_SIZE		112
#define X25_EXTENSION_SIZE		44
#define	X25_PRIORITY_SIZE		8
#define	X25_BCUG_SIZE			4
#define X25_USER_DATA_SIZE		132

// MIB function actions.
#define MIB_ACTION_GET         ASN_RFC1157_GETREQUEST
#define MIB_ACTION_SET         ASN_RFC1157_SETREQUEST
#define MIB_ACTION_GETNEXT     ASN_RFC1157_GETNEXTREQUEST


// MIB Variable access privileges.
#define MIB_ACCESS_READ        0
#define MIB_ACCESS_WRITE       1
#define MIB_ACCESS_READWRITE   2

// Trap Definitions
#define X25_TRAP_TYPE_RESTART	1
#define X25_TRAP_TYPE_RESET		2

// Macro to determine number of sub-oid's in array.
#define OID_SIZEOF( Oid )      ( sizeof Oid / sizeof(UINT) )


// MIB variable ENTRY definition.  This structure defines the format for
// each entry in the MIB.
typedef struct mib_entry {
	       AsnObjectIdentifier Oid;
	       void *              Storage;
	       void *              pSxbRawData;
	       BYTE                Type;
	       UINT                Access;
	       UINT                (*MibFunc)( UINT, struct mib_entry *,
	                                       RFC1157VarBind * );
		   struct mib_entry *  NextMibColumn;
	       struct mib_entry *  MibNext;
	   } MIB_ENTRY, FAR * PMIB_ENTRY;


// Internal MIB structure.
extern MIB_ENTRY Mib[];
extern UINT      MIB_num_variables;


// Prefix to every variable in the MIB.
extern AsnObjectIdentifier MIB_OidPrefix;

// Trap structure //
typedef struct x25_snmp_trap_list_entry {
			AsnInteger							specificTrap;	// Trap Identifier
			AsnTimeticks						timeStamp;		// Time the event occurred
			RFC1157VarBindList *				variableBindingList;	// Variable Binding List
			struct x25_snmp_trap_list_entry FAR * pNextTrapListEntry;		// Link to next entry
		} X25SNMP_TrapListEntry, * PX25SNMP_TrapListEntry;

// 
typedef struct MIB_CircuitCallBindTable {
		AsnInteger	Circuit;
		PMIB_ENTRY	pCircuitMib;
		PMIB_ENTRY	pCallParmMib;
		struct MIB_CircuitCallBindTable FAR * pNextCircuitCallBindTable;
	} MIB_CircuitCallBindTable_t, FAR * PMIB_CircuitCallBindTable_t;

//// Function Prototypes ////
UINT ResolveVarBind(
		IN OUT RFC1157VarBind *VarBind, // Variable Binding to resolve
		IN UINT PduAction               // Action specified in PDU
	);

UINT MIB_leaf_func(
        IN UINT Action,
		IN MIB_ENTRY *MibPtr,
		IN RFC1157VarBind *VarBind
	);

UINT MIB_time_leaf_func(
        IN UINT Action,
		IN MIB_ENTRY *MibPtr,
		IN RFC1157VarBind *VarBind
	);

UINT InitCallParmTableMibEntries(
		IN PMIB_ENTRY pMibBase, 
		IN PX25_SXB_IOCTL_INFO pX25SxbInfo,
		IN PSXB_PORT_INFO pSxbPortInfo
	);

UINT InitCircuitTableMibEntries(
		IN PMIB_ENTRY pMibBase, 
		IN PX25_SXB_IOCTL_INFO pX25SxbInfo,
		IN PSXB_PORT_INFO pSxbPortInfo
	);

UINT InitMibTableEntries(
		IN PX25_SXB_IOCTL_INFO pX25SxbInfo,
		IN PSXB_PORT_INFO pSxbPortInfo
		);         // Supervisor for Mib Initialization

UINT InitAdmnTableMibEntries(
		IN PMIB_ENTRY pMibBase, 
		IN PX25_SXB_IOCTL_INFO pX25SxbInfo,
		IN PSXB_PORT_INFO pSxbPortInfo
	);

UINT InitClearedCircuitTableMibEntries(
		IN PMIB_ENTRY pMibBase, 
		IN PX25_SXB_IOCTL_INFO pX25SxbInfo,
		IN PSXB_PORT_INFO pSxbPortInfo
	);

UINT InitCircuitTableMibEntries(
		IN PMIB_ENTRY pMibBase, 
		IN PX25_SXB_IOCTL_INFO pX25SxbInfo,
		IN PSXB_PORT_INFO pSxbPortInfo
	);

UINT InitChannelTableMibEntries(
		IN PMIB_ENTRY pMibBase, 
		IN PX25_SXB_IOCTL_INFO pX25SxbInfo,
		IN PSXB_PORT_INFO pSxbPortInfo
	);

UINT InitOperTableMibEntries(
		IN PMIB_ENTRY pMibBase, 
		IN PX25_SXB_IOCTL_INFO pX25SxbInfo,
		IN PSXB_PORT_INFO pSxbPortInfo
	);

UINT InitStatTableMibEntries(
		IN PMIB_ENTRY pMibBase, 
		IN PX25_SXB_IOCTL_INFO pX25SxbInfo,
		IN PSXB_PORT_INFO pSxbPortInfo
	);

PMIB_ENTRY CreateNextMibColFrom(
        IN PMIB_ENTRY	pOldMibEntry,	// Create a new column element from a row element
        IN UINT			AdjustIndex,	// Offset for index adjustment in added column
        IN BOOL			insertInChain,	// If you wish to chain the new element to old one 
		IN PVOID		pRawData		// Pointer to raw data storage
    );

// Update the raw data from the SXB driver
long WINAPI x25_Update_MIB_Data(
		IN long pX25SxbInfo);

// SXB driver trace data collection for circuit, and call param tables, and trace
void x25_Sxb_Trace_Data_Collection(
		IN PSXB_COLLECTOR_PARM_STRUCT pSxbParmInfo);

// Stop SXB driver data collection
void x25_Terminate_MIB_Data_Collection(
		IN PX25_SXB_IOCTL_INFO pX25SxbInfo,
		IN PSXB_PORT_INFO pBaseSxbPortInfo);

// Stop SXB driver trace data collection
void x25_Terminate_Sxb_Trace_Data_Collection(void);

// Initialize the SXB driver data collection structures
long x25_Init_MIB_Data_Structures(
		IN PX25_SXB_IOCTL_INFO pX25SxbInfo,
		IN PSXB_PORT_INFO pSxbPortInfo);

// Initialize the SXB port information from the registry
long x25_Init_Sxb_Port_Info(
		IN PSXB_PORT_INFO pSxbPortInfo);

// Process the cleared circuit events from SXB
BOOL x25_Process_Cleared_Circuit_Event(
		IN PX25_SXB_EVENT_IOCTL_INFO	pX25SxbAdapterIoctl
		);

// Process the call parm events from SXB
BOOL x25_Process_Call_Parm_Event(
		IN PX25_SXB_EVENT_IOCTL_INFO	pX25SxbAdapterIoctl
		);

// Process the restart events from SXB
BOOL x25_Process_Restart_Event(
		IN PX25_SXB_EVENT_IOCTL_INFO	pX25SxbAdapterIoctl
		);

// Process the reset events from SXB
BOOL x25_Process_Reset_Event(
		IN PX25_SXB_EVENT_IOCTL_INFO	pX25SxbAdapterIoctl
		);
// Utilities to play games with unicode strings
USHORT WstrLength( 
		IN LPWSTR lpwStr);

int StrToWStr( 
		OUT LPWSTR lpwStr, 
		IN  LPSTR lpStr, 
		IN  LONG count);

// Utilities to manipulate MIB variables
BOOL MibByteStreamToOctetStringCopy(
			OUT	AsnOctetString * dstAsnOctetString,
			IN	BYTE *	srcByteStream,
			IN	UINT	streamSize);

VOID dbgPrintVarBindList ( IN RFC1157VarBindList *	pVarBindList );
#endif /* X25Mib_h */
