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

   lapbdll.C

Abstract:

    Physical Layer MIB SNMP Extension Agent for Windows NT.

    These files (lapbdll.c, lapbmib.c, and lapbmib.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

--*/
#ifndef lapbmib_h
#define lapbmib_h

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

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

// Offsets used in initializing LAPB Mib Admin tables {lapb 1}
#define LAPBMIB_FIRST_ADMN_NDX						0
#define LAPBMIB_FIRST_ADMN_STATION_TYPE				1
#define LAPBMIB_FIRST_ADMN_CONTROL_FIELD			2
#define LAPBMIB_FIRST_ADMN_TRANSMIT_N1_FRAME_SIZE	3
#define LAPBMIB_FIRST_ADMN_RECEIVE_N1_FRAME_SIZE	4
#define LAPBMIB_FIRST_ADMN_TRANSMIT_K_WINDOW_SIZE	5
#define LAPBMIB_FIRST_ADMN_RECEIVE_K_WINDOW_SIZE	6
#define LAPBMIB_FIRST_ADMN_N2_RXMIT_COUNT			7
#define LAPBMIB_FIRST_ADMN_T1_ACK_TIMER				8
#define LAPBMIB_FIRST_ADMN_T2_ACK_DELAY_TIMER		9
#define LAPBMIB_FIRST_ADMN_T3_DISCONNECT_TIMER		10
#define LAPBMIB_FIRST_ADMN_T4_IDLE_TIMER			11
#define LAPBMIB_FIRST_ADMN_ACTION_INITIATE			12
#define LAPBMIB_FIRST_ADMN_RECV_DM					13

// Offsets used in initializing LAPB Mib OPERATIONAL tables {lapb 2}
#define LAPBMIB_FIRST_OPER_NDX						14
#define LAPBMIB_FIRST_OPER_STATION_TYPE				15
#define LAPBMIB_FIRST_OPER_CONTROL_FIELD			16
#define LAPBMIB_FIRST_OPER_TRANSMIT_N1_FRAME_SIZE	17
#define LAPBMIB_FIRST_OPER_RECEIVE_N1_FRAME_SIZE	18
#define LAPBMIB_FIRST_OPER_TRANSMIT_K_WINDOW_SIZE	19
#define LAPBMIB_FIRST_OPER_RECEIVE_K_WINDOW_SIZE	20
#define LAPBMIB_FIRST_OPER_N2_RXMIT_COUNT			21
#define LAPBMIB_FIRST_OPER_T1_ACK_TIMER				22
#define LAPBMIB_FIRST_OPER_T2_ACK_DELAY_TIMER		23
#define LAPBMIB_FIRST_OPER_T3_DISCONNECT_TIMER		24
#define LAPBMIB_FIRST_OPER_T4_IDLE_TIMER			25
#define LAPBMIB_FIRST_OPER_PORT_ID					26
#define LAPBMIB_FIRST_OPER_PROTOCOL_VERSION			27

// Offsets used in initializing LAPB FLOW tables {lapb 3}
#define LAPBMIB_FIRST_FLOW_INDEX					28
#define LAPBMIB_FIRST_FLOW_STATE_CHANGES			29
#define LAPBMIB_FIRST_FLOW_CHANGE_REASON			30
#define LAPBMIB_FIRST_FLOW_CURRENT_MODE				31
#define LAPBMIB_FIRST_FLOW_BUSY_DEFERS				32
#define LAPBMIB_FIRST_FLOW_REJ_OUT_PKTS				33
#define LAPBMIB_FIRST_FLOW_REJ_IN_PKTS				34
#define LAPBMIB_FIRST_FLOW_T1_TIMEOUTS				35
#define LAPBMIB_FIRST_FLOW_FRMR_SENT				36
#define LAPBMIB_FIRST_FLOW_FRMR_RECEIVED			37
#define LAPBMIB_FIRST_FLOW_XID_RECEIVED				38

// Offsets used in initializing LAPB XID tables {lapb 4}
#define LAPBMIB_FIRST_XID_INDEX							39
#define LAPBMIB_FIRST_XID_AD_R_IDENTIFIER				40
#define LAPBMIB_FIRST_XID_PARAMETER_UNIQUE_IDENTIFIER	41
#define LAPBMIB_FIRST_XID_GROUP_ADDRESS					42
#define LAPBMIB_FIRST_XID_PORT_NUMBER					43
#define LAPBMIB_FIRST_XID_USER_DATA_SUBFIELD            44

// The following MIB Entries identify the version of the protocol

//// Ranges and limits for specific MIB variables.
//   Ranges for LAPB Station Type Variable
#define LAPBMIB_STATION_TYPE_DTE		1
#define LAPBMIB_STATION_TYPE_DCE		2
#define LAPBMIB_STATION_TYPE_DXE		3
#define LAPBMIB_STATION_TYPE_MIN  LAPBMIB_STATION_TYPE_DTE
#define LAPBMIB_STATION_TYPE_MAX  LAPBMIB_STATION_TYPE_DXE

//   Ranges for LAPB Control Field Variable
#define LAPBMIB_CONTROL_FIELD_MOD_8		1
#define LAPBMIB_CONTROL_FIELD_MOD_128	2
#define LAPBMIB_CONTROL_FIELD_MIN  LAPBMIB_CONTROL_FIELD_MOD_8
#define LAPBMIB_CONTROL_FIELD_MAX  LAPBMIB_CONTROL_FIELD_MOD_128

//   Ranges for LAPB Action Initiate Variable
#define LAPBMIB_ACTION_INITIATE_SEND_SABM		1
#define LAPBMIB_ACTION_INITIATE_SEND_DISC		2
#define LAPBMIB_ACTION_INITIATE_SEND_DM			3
#define LAPBMIB_ACTION_INITIATE_NONE			4
#define LAPBMIB_ACTION_INITIATE_OTHER			5
#define LAPBMIB_ACTION_INITIATE_MIN  LAPBMIB_ACTION_INITIATE_SEND_SABM
#define LAPBMIB_ACTION_INITIATE_MAX  LAPBMIB_ACTION_INITIATE_OTHER

//   Ranges for LAPB Receive DM Variable
#define LAPBMIB_ACTION_RECEIVE_DM_SEND_SABM		1
#define LAPBMIB_ACTION_RECEIVE_DM_SEND_DISC		2
#define LAPBMIB_ACTION_RECEIVE_DM_OTHER			3
#define LAPBMIB_ACTION_RECEIVE_DM_MIN  LAPBMIB_ACTION_RECEIVE_DM_SEND_SABM
#define LAPBMIB_ACTION_RECEIVE_DM_MAX  LAPBMIB_ACTION_RECEIVE_DM_OTHER

//   Ranges for LAPB Flow Change Reason Variable
#define LAPBMIB_FLOW_CHANGE_REASON_NOT_STARTED		1
#define LAPBMIB_FLOW_CHANGE_REASON_ABM_ENTERED		2
#define LAPBMIB_FLOW_CHANGE_REASON_ABME_ENTERED		3
#define LAPBMIB_FLOW_CHANGE_REASON_ABM_RESET		4
#define LAPBMIB_FLOW_CHANGE_REASON_ABME_RESET		5
#define LAPBMIB_FLOW_CHANGE_REASON_DM_RECEIVED		6
#define LAPBMIB_FLOW_CHANGE_REASON_DM_SENT			7
#define LAPBMIB_FLOW_CHANGE_REASON_DISC_RECEIVED	8
#define LAPBMIB_FLOW_CHANGE_REASON_DISC_SENT		9
#define LAPBMIB_FLOW_CHANGE_REASON_FRMR_RECEIVED	10
#define LAPBMIB_FLOW_CHANGE_REASON_FRMR_SENT		11
#define LAPBMIB_FLOW_CHANGE_REASON_N2_TIMEOUT		12
#define LAPBMIB_FLOW_CHANGE_REASON_OTHER			13
#define LAPBMIB_FLOW_CHANGE_REASON_MIN  LAPBMIB_FLOW_CHANGE_REASON_NOT_STARTED
#define LAPBMIB_FLOW_CHANGE_REASON_MAX  LAPBMIB_FLOW_CHANGE_REASON_OTHER

//   Ranges for LAPB Flow CurrentMode Variable
#define LAPBMIB_FLOW_MODE_DISCONNECTED				1
#define LAPBMIB_FLOW_MODE_LINK_SETUP				2
#define LAPBMIB_FLOW_MODE_FRAME_REJECT				3
#define LAPBMIB_FLOW_MODE_DISC_REQ					4
#define LAPBMIB_FLOW_MODE_INFO_XFER					5
#define LAPBMIB_FLOW_MODE_REJ_FRAME_SENT			6
#define LAPBMIB_FLOW_MODE_WAITING_ACK				7
#define LAPBMIB_FLOW_MODE_STATION_BUSY				8
#define LAPBMIB_FLOW_MODE_REMOTE_STATION_BUSY		9
#define LAPBMIB_FLOW_MODE_BOTH_STATIONS_BUSY		10
#define LAPBMIB_FLOW_MODE_WAITING_ACK_STATION_BUSY	11
#define LAPBMIB_FLOW_MODE_WAITING_ACK_REMOTE_BUSY	12
#define LAPBMIB_FLOW_MODE_WAITING_ACK_BOTH_BUSY		13
#define LAPBMIB_FLOW_MODE_REJ_SENT_REMOTE_BUSY		14
#define LAPBMIB_FLOW_MODE_XID_FRAME_SENT			15
#define LAPBMIB_FLOW_MODE_ERROR						16
#define LAPBMIB_FLOW_MODE_OTHER						17
#define LAPBMIB_FLOW_MODE_MIN  LAPBMIB_FLOW_MODE_DISCONNECTED
#define LAPBMIB_FLOW_MODE_MAX  LAPBMIB_FLOW_MODE_OTHER

// FIRMWARE DEFINES STOLEN FROM XSTAT.C
#define LAPB_STATE_OFF			0
#define LAPB_STATE_START		1
#define LAPB_STATE_D_CONN		2
#define LAPB_STATE_ADM			3
#define LAPB_STATE_ARM			4
#define LAPB_STATE_POLLING		5
#define LAPB_STATE_PRESETUP	6
#define LAPB_STATE_SETUP		7
#define LAPB_STATE_RESET		8
#define LAPB_STATE_ERROR		9
#define LAPB_STATE_NORMAL		10


//   Maximum and Default sizes for Variables
#define LAPBMIB_K_WINDOW_SIZE_MAX			128
#define LAPBMIB_N2_RXMIT_COUNT_MAX			65535
#define	LAPBMIB_FLOW_FRMR_MAX_SIZE			8206
#define	LAPBMIB_FLOW_XID_RECEIVED_MAX_SIZE	8206

#define LAPBMIB_DEFAULT_FRAME_SIZE			36000 // 802.2 Default (4500 BYTES * 8 BITS)
#define LAPBMIB_DEFAULT_WINDOW_SIZE			7
#define LAPBMIB_DEFAULT_RXMIT_COUNT			20
#define LAPBMIB_DEFAULT_ACK_TIMER			3000
#define LAPBMIB_DEFAULT_ACK_DELAY_TIMER		60000
#define LAPBMIB_DEFAULT_NO_TIMER			2147483647

// 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_flow_mode_leaf_func(						
        IN UINT Action,					// lapb flow state Mib leaf data return fcn
		IN MIB_ENTRY *MibPtr,
		IN RFC1157VarBind *VarBind
	);

UINT MIB_cfg_leaf_func(						
        IN UINT Action,					// Config Mib leaf data return fcn
		IN MIB_ENTRY *MibPtr,
		IN RFC1157VarBind *VarBind
	);

UINT MIB_leaf_func(						
        IN UINT Action,					// Generic Mib leaf data return fcn
		IN MIB_ENTRY *MibPtr,
		IN RFC1157VarBind *VarBind
	);

UINT InitAdmnTableMibEntries(
        IN PMIB_ENTRY pMibBase,         // MIB admin table init routines
		IN PLAPB_SXB_INFO pLapbSxbInfo	// Shared data structures
	);

UINT InitOperTableMibEntries(
        IN PMIB_ENTRY pMibBase,         // MIB operational table init routines
		IN PLAPB_SXB_INFO pLapbSxbInfo	// Shared data structures
	);

UINT InitFlowTableMibEntries(
        IN PMIB_ENTRY pMibBase,         // MIB flow table init routines
		IN PLAPB_SXB_INFO pLapbSxbInfo	// Shared data structures
	);

UINT InitXidTableMibEntries(
        IN PMIB_ENTRY pMibBase,         // MIB XID table init routines
		IN PLAPB_SXB_INFO pLapbSxbInfo	// Shared data structures
	);

UINT InitMibTableEntries(
		IN OUT PLAPB_SXB_INFO pLapbSxbInfo // 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 lapb_Update_MIB_Data(
		IN long pLapbSxbInfo);

// Stop SXB driver data collection
void lapb_Terminate_MIB_Data_Collection(
		IN PLAPB_SXB_INFO  pLapbSxbInfo,
		IN PSXB_PORT_INFO pSxbPortInfo);

// Initialize the SXB driver data collection structures
long lapb_Init_MIB_Data_Structures(
		IN PLAPB_SXB_INFO pLapbSxbInfo,
		IN PSXB_PORT_INFO pSxbPortInfo);

// Initialize the SXB port information from the registry
long lapb_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 /* LapbMib_h */
