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

   rs232sxb.h

Abstract:

    Physical Layer MIB SNMP Extension Agent for Windows NT.

    These files (rs232dll.c, rs232mib.c, and rs232mib.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: rs232mib.h $
 * 
 * *****************  Version 6  *****************
 * User: Mikez        Date: 7/08/97    Time: 9:48a
 * Updated in $/Components/Windows/NT/Sync/SxbSnmp/physical
 * Updated to support DStreams API.

--*/
#ifndef rs232mib_h
#define rs232mib_h

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

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

// Offsets used in initializing RS232 Mib port tables {rs232 2}
#define RS232MIB_PORT_NUMBER_NDX				0

// Offsets used in initializing RS232 Mib port tables {rs232 2}
#define RS232MIB_FIRST_PORT_NDX                 1
#define RS232MIB_FIRST_PORT_TYPE                2
#define RS232MIB_FIRST_IN_SIG_NUM               3
#define RS232MIB_FIRST_OUT_SIG_NUM              4
#define RS232MIB_FIRST_IN_PORT_SPEED            5
#define RS232MIB_FIRST_OUT_PORT_SPEED           6

// Offsets used in initializing RS232 Mib sync port tables {rs232 4}
#define RS232MIB_FIRST_SYNC_PORT_NDX            7
#define RS232MIB_FIRST_SYNC_PORT_CLK_SRC        8
#define RS232MIB_FIRST_SYNC_PORT_FCS_ERRS       9
#define RS232MIB_FIRST_SYNC_PORT_XUR_ERRS       10
#define RS232MIB_FIRST_SYNC_PORT_ROR_ERRS       11
#define RS232MIB_FIRST_SYNC_PORT_INT_FRM_ERRS   12
#define RS232MIB_FIRST_SYNC_PORT_ABT_FRM_ERRS   13

// Offsets used in initializing RS232 Mib input signal tables {rs232 5}
#define RS232MIB_FIRST_IN_SIG_NDX               14
#define RS232MIB_FIRST_IN_SIG_NAME_RTS          15
#define RS232MIB_FIRST_IN_SIG_NAME_CTS          16
#define RS232MIB_FIRST_IN_SIG_NAME_DSR          17
#define RS232MIB_FIRST_IN_SIG_NAME_DTR          18
#define RS232MIB_FIRST_IN_SIG_NAME_RI           19
#define RS232MIB_FIRST_IN_SIG_NAME_DCD          20
#define RS232MIB_FIRST_IN_SIG_STATE_RTS         21
#define RS232MIB_FIRST_IN_SIG_STATE_CTS         22
#define RS232MIB_FIRST_IN_SIG_STATE_DSR         23
#define RS232MIB_FIRST_IN_SIG_STATE_DTR         24
#define RS232MIB_FIRST_IN_SIG_STATE_RI          25
#define RS232MIB_FIRST_IN_SIG_STATE_DCD         26
#define RS232MIB_FIRST_IN_SIG_CHANGES_RTS       27
#define RS232MIB_FIRST_IN_SIG_CHANGES_CTS       28
#define RS232MIB_FIRST_IN_SIG_CHANGES_DSR       29
#define RS232MIB_FIRST_IN_SIG_CHANGES_DTR       30
#define RS232MIB_FIRST_IN_SIG_CHANGES_RI        31
#define RS232MIB_FIRST_IN_SIG_CHANGES_DCD       32

// Offsets used in initializing RS232 Mib input signal tables {rs232 5}
#define RS232MIB_FIRST_OUT_SIG_NDX              33
#define RS232MIB_FIRST_OUT_SIG_NAME_RTS         34
#define RS232MIB_FIRST_OUT_SIG_NAME_CTS         35
#define RS232MIB_FIRST_OUT_SIG_NAME_DSR         36
#define RS232MIB_FIRST_OUT_SIG_NAME_DTR         37
#define RS232MIB_FIRST_OUT_SIG_NAME_RI          38
#define RS232MIB_FIRST_OUT_SIG_NAME_DCD         39
#define RS232MIB_FIRST_OUT_SIG_STATE_RTS        40
#define RS232MIB_FIRST_OUT_SIG_STATE_CTS        41
#define RS232MIB_FIRST_OUT_SIG_STATE_DSR        42
#define RS232MIB_FIRST_OUT_SIG_STATE_DTR        43
#define RS232MIB_FIRST_OUT_SIG_STATE_RI         44
#define RS232MIB_FIRST_OUT_SIG_STATE_DCD        45
#define RS232MIB_FIRST_OUT_SIG_CHANGES_RTS      46
#define RS232MIB_FIRST_OUT_SIG_CHANGES_CTS      47
#define RS232MIB_FIRST_OUT_SIG_CHANGES_DSR      48
#define RS232MIB_FIRST_OUT_SIG_CHANGES_DTR      49
#define RS232MIB_FIRST_OUT_SIG_CHANGES_RI       50
#define RS232MIB_FIRST_OUT_SIG_CHANGES_DCD      51

//// Ranges and limits for specific MIB variables.
//   Ranges for RS232 Port Type Variable
#define RS232MIB_PORT_TYPE_OTHER                1
#define RS232MIB_PORT_TYPE_RS232                2
#define RS232MIB_PORT_TYPE_RS422                3
#define RS232MIB_PORT_TYPE_RS423                4
#define RS232MIB_PORT_TYPE_V35                  5
#define RS232MIB_PORT_TYPE_MIN  RS232MIB_PORT_TYPE_OTHER
#define RS232MIB_PORT_TYPE_MAX  RS232MIB_PORT_TYPE_V35

//   Ranges for RS232 Sync Port Clock Source Variable
#define RS232MIB_SYNC_PORT_CLOCK_SOURCE_INTERNAL    1
#define RS232MIB_SYNC_PORT_CLOCK_SOURCE_EXTERNAL    2
#define RS232MIB_SYNC_PORT_CLOCK_SOURCE_SPLIT       3
#define RS232MIB_PORT_CLOCK_SOURCE_MIN  RS232MIB_SYNC_PORT_CLOCK_SOURCE_INTERNAL
#define RS232MIB_PORT_CLOCK_SOURCE_MAX  RS232MIB_SYNC_PORT_CLOCK_SOURCE_SPLIT

//   Ranges for RS232 Port Signal Name Variable
#define RS232MIB_SIG_NAME_RTS                   1
#define RS232MIB_SIG_NAME_CTS                   2
#define RS232MIB_SIG_NAME_DSR                   3
#define RS232MIB_SIG_NAME_DTR                   4
#define RS232MIB_SIG_NAME_RI                    5
#define RS232MIB_SIG_NAME_DCD                   6
#define RS232MIB_SIG_NAME_SQ                    7
#define RS232MIB_SIG_NAME_SRS                   8
#define RS232MIB_SIG_NAME_SRTS                  9
#define RS232MIB_SIG_NAME_SCTS                  10
#define RS232MIB_SIG_NAME_SDCD                  11
#define RS232MIB_SIG_NAME_MIN  RS232MIB_SIG_NAME_RTS
#define RS232MIB_SIG_NAME_MAX  RS232MIB_SIG_NAME_DCD

//   Ranges for RS232 Port Signal State Variable
#define RS232MIB_SIG_STATE_NONE                 1
#define RS232MIB_SIG_STATE_ON                   2
#define RS232MIB_SIG_STATE_OFF                  3
#define RS232MIB_SIG_STATE_MIN  RS232MIB_SIG_STATE_NONE
#define RS232MIB_SIG_STATE_MAX  RS232MIB_SIG_STATE_OFF

// 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


// 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 *  MibNext;
	   } MIB_ENTRY, * 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;


// 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,					// Generic Mib leaf data return fcn
		IN MIB_ENTRY *MibPtr,
		IN RFC1157VarBind *VarBind
	);

UINT MIB_Interface_Type_func(
		IN UINT Action,					// Interface type fcn (translates)
	    IN MIB_ENTRY *MibPtr,
	    IN RFC1157VarBind *VarBind
	 );

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

UINT InitPortTableMibEntries(
        IN PMIB_ENTRY pMibBase,         // MIB port table init routines
		IN PWAN_SXB_INFO pWanSxbInfo	// Shared data structures
	);

UINT InitSyncPortTableMibEntries(
        IN PMIB_ENTRY pMibBase,         // MIB sync port table init routines
		IN PWAN_SXB_INFO pWanSxbInfo	// Shared data structures
	);

UINT InitInSigTableMibEntries(
        IN PMIB_ENTRY pMibBase,         // MIB input signal table init routines
		IN PWAN_SXB_INFO pWanSxbInfo	// Shared data structures
	);

UINT InitOutSigTableMibEntries(
        IN PMIB_ENTRY pMibBase,         // MIB output signal table init routines
		IN PWAN_SXB_INFO pWanSxbInfo	// Shared data structures
	);

UINT InitMibTableEntries(
		IN OUT PWAN_SXB_INFO pWanSxbInfo // Supervisor for Mib Initialization
	);

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 rs232_Update_MIB_Data(
		IN long pWanSxbInfo);

// Stop SXB driver data collection
void rs232_Terminate_MIB_Data_Collection(
		IN PWAN_SXB_INFO  pWanSxbInfo,
		IN PSXB_PORT_INFO pSxbPortInfo);

// Initialize the SXB driver data collection structures
long rs232_Init_MIB_Data_Structures(
		IN PWAN_SXB_INFO pWanSxbInfo,
		IN PSXB_PORT_INFO pSxbPortInfo);

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

// Utilities to play games with unicode strings
USHORT WstrLength( 
		IN LPWSTR lpwStr);

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

#endif /* Rs232Mib_h */
