#ident "$Id: lapb.h,v 1.1 1995/03/16 17:05:45 garyp Exp $"
/*****************************************************************************
 * Copyright (c) 1988-95 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 copyright work  Digi   International
 * Inc.    Except   as   permitted   by  federal  law,  17 USC 117, copying is
 * strictly prohibited.
 * 
 * Digi  International  Inc.  CONFIDENTIAL  -   (Digi    International    Inc.
 * Confidential  when   combined   with   the   aggregated  modules  for  this
 * product) OBJECT CODE ONLY SOURCE MATERIALS
 * 
 * (C) COPYRIGHT Digi International Inc. 1995
 * 
 * All Rights Reserved
 * 
 * US   Government   Users   Restricted   Rights   -   Use,   duplication   or
 * disclosure  restricted by GSA ADP Schedule Contract with Digi International
 * Inc.
 * 
 *****************************************************************************/

/******************************************************************
 *
 *  SpiderX25 - LAPB STREAMS Multiplexer
 *
 *  Copyright 1991 Spider Systems Limited
 *
 *  LAPB.H
 *
 *    Private header file.
 *
 ******************************************************************/

/*
 *	 /projects/common/PBRAIN/SCCS/pbrainF/dev/sys/lapb/0/s.lapb.h
 *	@(#)lapb.h	1.29
 *
 *	Last delta created	12:42:58 7/6/92
 *	This file extracted	22:30:16 11/19/92
 *
 */


/* Permanent definitions */
#define A_ADDRESS        3
#define B_ADDRESS        1
#define P_BIT         0x10

/* States */
#define OFF		 0
#define START		 1
#define D_CONN		 2
#define ADM		 3
#define ARM		 4
#define POLLING		 5
#define PRESETUP         6
#define SETUP		 7
#define RESET		 8
#ifdef	ERROR
#undef	ERROR
#endif
#define ERROR		 9
#define NORMAL		 10

/*  Number of timers */
#define NTIMERS   6

/* Timer IDs (index in timer array) */
#define PTIMER    0
#define ACKTIMER  1
#define REJTIMER  2
#define BUSYTIMER 3
#define RRTIMER   4
#define IDLETIMER 5

/* LAPB link control structure */
typedef struct lapblink {
    mblk_t     *ackq;
    mblk_t     *datq;
    mblk_t     *adqtail;
    mblk_t     *rxqueue;
    mblk_t     *rxqtail;
    queue_t    *downq;
    queue_t    *upq;
    uint3264	nethandle;	/* for interface to network layer */
    thead_t	thead;
    timer_t	tmtab[NTIMERS];
    lapbtune_t  tunetab;
    lapbstats_t statstab;
    int		rxqcnt;
    int		index;
    int		discard;
    uint16	netcid;
    uint32	snid;
    uint8	upcmd;
    uint8	upstatus;
    uint8	seqmask;
    uint8	extended;
    uint8	myaddr;
    uint8	busyflag;
	uint8	i_frame_cnt ;
    uint8	awaitflag;
    uint8	clashflag;
    uint8	pollflag;
    uint8	connected;
    uint8	pflag;
    uint8	wclosed;
    uint8	txstopped;

    uint8	state;
    uint8	reject;

    /* 
     *  causeflag is only used in D_CONN and RESET states to remember
     *  originator of request, and is only changed on entry to these states
     */
    uint8	causeflag;

    /*
     *  the following are the sequence bytes and retrycount which are zeroed by
     *  zero_v_vals, which also empties the queues and clears rem_busy,
     *  akqnum and txqnum
     */
    uint8	vr;
    uint8	vs;
    uint8	ar;
    uint8	as;
    uint8	retry_count;
    uint8	rem_busy;
    /* the following are zeroed by lapb_goto_adm */
    uint8	dataflag;
    uint8	sflag;
    /* the following are evaluated when an appropriate input frame is received */
    uint8	need_fbit;
    uint8	need_ack;
   /*
    *  the values used for retry and timing during the lifetime of the
    *  connection, they are copied from lapb_tune[] by lapb_goto_adm
    *  and thereafter are read only
    */
    uint8	frmr_ctl1;
    uint8	frmr_ctl2;
    uint8	frmr_addr;
    uint8	frmr_reason;

    /*
     *  mode indicates LAPB or LAP procedures.
     */
    uint8	mode;
   /*
    * records whether tracing is active or inactive on this subnetwork
    * and the queue to send trace messages up on.
    */
    uint8	trace_active;
    queue_t    *trace_queue;

#ifndef NO_WAN_CONTROL
    mblk_t     *WAN_queue;
    mblk_t     *WAN_qtail;
    int		WAN_qcnt;
    uint8	WAN_state;
    uint8	WAN_remsize;
    uint8	WAN_remaddr[12];
#endif

} lapb_t;

#define p_timer     tmtab[PTIMER]
#define ack_timer   tmtab[ACKTIMER]
#define rej_timer   tmtab[REJTIMER]
#define busy_timer  tmtab[BUSYTIMER]
#define idle_timer  tmtab[IDLETIMER]
#define RR_timer    tmtab[RRTIMER]

#define		LAPB_MODE	1
#define		LAP_MODE	2


#ifndef NO_WAN_CONTROL
/*
    WAN states
*/
#define WAN_IDLE  0
#define WAN_CONN  1
#define WAN_ESTB  2
#define WAN_DISC  3
#endif



/* per-link stats macro */
#define LAPBMONITOR(i) { \
if(lp->statstab.lapbmonarray[i]<0XFFFFFFFF) \
	lp->statstab.lapbmonarray[i]++; \
}


// Prototypes
int	close_lapb_tracestrm(queue_t *);
void lapb_stop(lapb_t *);
void lapb_rxframe(lapb_t *, mblk_t *);
STATIC void UA_in(lapb_t *, unsigned int);
void lapb_start(lapb_t *);
void uplapb(lapb_t *, mblk_t *);
void init_mode(lapb_t *, int);
void lapb_expired(lapb_t *, unchar);
void txlapb(lapb_t *, mblk_t *, int);
void lapb_CONOK(lapb_t *);
void lapb_CONNAK(lapb_t *);
void lapb_RESET(lapb_t *);
void lapb_DISC(lapb_t *);
void lapb_CONNECT();
int lapb_init(lapb_t *, int, int, int);
void lapb_rxwctl(lapb_t *,mblk_t *);
void lapb_wdata(lapb_t *);
void discard_data(lapb_t *);
void lapb_txack(lapb_t *);

#ifdef SOH
// Common Prototypes
#include "commonpt.h"
#endif
