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

   IsdnTrace.h

Abstract:

   Code for doing ISDN DChannel trace.

Author:

   Michael Zarns

--*/

// class CIsdnTraceSheet;
// class CIsdnTracer;
// class CIsdnTraceData;
// class CIsdnDataSource;

class CIsdnFrame : public CFrame
{
	void TreeDataLapd(CTreeCtrl&, HTREEITEM hParentNode);
	void TreeDataLapdAddress(CTreeCtrl&, HTREEITEM hParentNode);
	void TreeDataLapdInfoFrame(CTreeCtrl&, HTREEITEM hParentNode);
	void TreeDataLapdSupervisoryFrame(CTreeCtrl&, HTREEITEM hParentNode);
	void TreeDataLapdUnnumberedFrame(CTreeCtrl&, HTREEITEM hParentNode, HTREEITEM hRootNode);
	void TreeDataServiceMessage(CTreeCtrl&, HTREEITEM hParentNode, ULONG Start);
	void TreeDataIl3Frame(CTreeCtrl&, HTREEITEM hParentNode, ULONG Start);
	void TreeDataIl3Ie(CTreeCtrl&, HTREEITEM hParentNode, ULONG Offset);
	void AddLapdFrameType( CString& msg ) const;
	void AddIl3MessageType( CString& msg ) const;

public :
	CIsdnFrame(const CTraceData *td) : CFrame(td) { };

	virtual DWORD GetSeqNum()    const { return ((isdn_trc_ctl_t *)GetControl())->l_trc_seq; }
	virtual DWORD GetTimeStamp() const { return ((isdn_trc_ctl_t *)GetControl())->l_trc_time; }
	virtual DWORD GetTxRx()      const { return ((isdn_trc_ctl_t *)GetControl())->l_trc_rcv; }
	virtual DWORD GetCircuit()   const { return (GetData()[1] & 0xFE) >> 1; }

	virtual LPCSTR GetProtocol() const;
	virtual void GetDescription(CString&) const;
	virtual void DisplayTreeData(CTreeCtrl&, const CTraceData *, CFrame *);
};


class CIsdnTraceData : public CTraceData
{
	friend class CIsdnTraceIl3View;
	friend class CIsdnTraceLapdView;
	friend class CIsdnFrame;

	DECLARE_SERIAL(CIsdnTraceData);

private :

// ************************************************
// ************************************************
// LAYER 2 (Q921) Frames
	DWORD nInfo[2];	// Info frames (i.e. Layer 3 messages)
	DWORD nRR[2];		// Receiver Ready
	DWORD nRNR[2];		// Receiver Not Ready
	DWORD nREJ[2];		// Reject
	DWORD nSABME[2];	// Set Asynchronous Balance Mode Extended
	DWORD nDM[2];		// Disconnect Mode
	DWORD nDISC[2];	// Disconnect
	DWORD nUA[2];		// Unnumbered Acknowledge
	DWORD nFRMR[2];	// Frame Reject
	DWORD nUI[2];
	DWORD nL2Unknown[2];	// Can't decipher it
// ************************************************
// LAYER 3 (Q931) Frames
	DWORD nAlerting[2];
	DWORD nCallProceeding[2];
	DWORD nConnect[2];
	DWORD nConnectAck[2];
	DWORD nProgress[2];
	DWORD nSetup[2];
	DWORD nSetupAck[2];
	DWORD nResume[2];
	DWORD nResumeAck[2];
	DWORD nResumeReject[2];
	DWORD nSuspend[2];
	DWORD nSuspendAck[2];
	DWORD nSuspendReject[2];
	DWORD nUserInfo[2];
	DWORD nDisconnect[2];
	DWORD nRelease[2];
	DWORD nReleaseComplete[2];
	DWORD nRestart[2];
	DWORD nRestartAck[2];
	DWORD nSegment[2];
	DWORD nCongestionControl[2];
	DWORD nFacility[2];
	DWORD nInformation[2];
	DWORD nNotify[2];
	DWORD nStatus[2];
	DWORD nStatusEnquiry[2];
	DWORD nMaintenance[2];	// Not really Q931, it's an AT&T Maintenance message
	DWORD nL3Unknown[2];
// ************************************************
// ************************************************

// creates a CIsdnFrame
	virtual CFrame *CreateFrame() const { return new CIsdnFrame(this); };

// ************************************************
// Isdn only helper functions
// ************************************************

public:
	CIsdnTraceData() : CTraceData() {};
	CIsdnTraceData(DWORD baud, CDWordArray&);
	~CIsdnTraceData();

// attributes
	virtual double TimeInSeconds(DWORD t) const {return (t - m_FirstTimeStamp) / 1000.0f;}
	virtual LPCSTR GetEndPointName() const { return "TEI"; };

// operations
	virtual CTraceSheet *CreateTraceSheet();
	virtual void Serialize(CArchive&);
	virtual void DoVCNextSecond(DWORD) {};
	virtual BOOL DoFilterOptions(DWORD&, CDWordArray *);
	virtual void ProcessFrame(const strbuf& control, const strbuf& data);
	virtual void ClearTraceStats();
};


// trace class
class CIsdnTracer : public CTracer
{
public :
	CIsdnTracer(CDataSource *);
	virtual ~CIsdnTracer();
};


/////////////////////////////////////////////////////////////////////////////
// CIsdnFilter dialog

class CIsdnFilter : public CDialog
{
// Construction
public:
	CIsdnFilter(CWnd* pParent = NULL);   // standard constructor

// Dialog Data
	//{{AFX_DATA(CIsdnFilter)
	enum { IDD = IDD_IsdnFilter };
	int		m_FilterRadio;
	//}}AFX_DATA

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CIsdnFilter)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:

	// Generated message map functions
	//{{AFX_MSG(CIsdnFilter)
	virtual BOOL OnInitDialog();
	virtual void OnOK();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};
