#ident "$Id: frsencap.h,v 1.2 1996/06/21 16:36:51 gary 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.
 * 
 *****************************************************************************/

/*****************************************************************************
 *                                                                           *
 * (c) COPYRIGHT 1991, 1992 HARRIS & JEFFRIES, INC.                          *
 *                          888 WASHINGTON STREET                            *
 *                          SUITE 130                                        *
 *                          DEDHAM, MA  02026                                *
 * ALL RIGHTS RESERVED                                                       *
 *                                                                           *
 * This software is the property of Harris & Jeffries, Inc. and is furnished *
 * under license by Harris & Jeffries, Inc. and this software may be used    *
 * only in accordance with the terms of said license.  This copyright notice *
 * may not be removed, modified or obliterated without the prior written     *
 * permission of Harris & Jeffries, Inc.                                     *
 *                                                                           *
 * This software may not be copied, transmitted, provided to or otherwise    *
 * made available to any other person, company, corporation or other entiry  *
 * except as specified in the terms of said license.                         *
 *                                                                           *
 * No right, title, ownership or other interest in the software is hereby    *
 * granted or transferred.                                                   *
 *                                                                           *
 * The information contained herein is subject to change without notice and  *
 * should not be construed as a commitment by Harris & Jeffries, Inc.        *
 *                                                                           *
 *****************************************************************************

  MODULE NAME:


  ORIGINAL AUTHOR:  Greg A. Bellucci

  REVISION HISTORY:

  Date     Version  Name          Description
  -------- -------  ------------  --------------------------------------------
  07-14-92 1.00     H&J (GB)      Original
  09-28-93 2.00H    H&J (GB)      Added new define/macro statements for 
                                   support of RFC 1490. Changed the PID table
                                   to support new PIDs (see notes below).
           Other    H&J           See H&J's bug reports

  $Log: frsencap.h,v $
  Revision 1.2  1996/06/21 16:36:51  gary
  Next stage of FRF.9 implementation complete.  The appropriate functions
  have been inserted into the transmit and receive path, but are not
  active yet.  Development is being put on hold until a more pressing
  issue (flow control) is dealt with.

  Revision 1.1  1995/03/16 17:02:27  garyp
  Initial revision

 * Revision 1.10  1994/07/27  20:31:09  stavrosm
 * Release 2.2
 *
 * Revision 1.9  1994/07/27  17:58:17  stavrosm
 * A new output (no_buffers) was added to the FSM Transition Table
 * for encap_makeframe().
 *
 * Revision 1.8  1994/06/28  14:06:04  stavrosm
 * Added IPX and ARP encapsulation.
 *
 * Revision 1.7  1994/03/16  21:29:13  deepak
 * Change to macro mGET_MAX_FRAME_LEN() reflecting change in struct LCB.
 *
 * Revision 1.6  93/11/02  11:14:40  stavrosm
 * Release 2.1
 * 
..............................................................................

  DESCRIPTION:

    This is the header file for the IETF encapsulation functionality.

..............................................................................

  REF DOCUMENTS:

  (a) U.S Sprint Frame Relay Service Interface Specification Doc #: 5136.02
  (b) Frame Relay Interface Specification, Stratacom Inc., Doc #: 001-207460
  (c) Frame Relay Stack Functional Specification Rel 1.2 Harris & Jeffries Inc.
  (d) Frame Relay Stack External Specification Rel 1.2 Harris & Jeffries Inc.
  (e) MIB for Frame Relay DTEs - RFC Draft from Internet Engr Task Force (IETF).
  (f) Multiprotocol Interconnect over Frame Relay Networks - T. Bradley, C.Brown
      Wellfleet Communications, Inc. A. Malis BBN Communications Oct 14, 1991.

..............................................................................

  SPECIAL COMPILE/LINK INSTRUCTIONS:

        see notes/instructions in frs.h
..............................................................................
*/

#ifndef FRSENCAP_H
#define FRSENCAP_H

#ifndef FRS_H
#include "frs.h"
#endif

/* MISC */
#define FRAME_TYPE_03         0x03      /* Used in frame control field */
#define FRAME_TYPE_08		  0x08		/* Used in Cisco Control Field */
#define MODULO32              32        /* Used for modulo division */
#define NULL_OCTET            0x00      /* guess what this is ? */
#define FRAGMENT_PID          0x0D      /* PID value of fragmented frame */
#define USER_SPEC             0x70      /* constant value in Q933 frame */
#define FREE                  0x01      /* Used with encap_frame_error */
#define NOFREE                0x00      /* Used with encap_frame_error */

/** Frame types - to determine the type of frame we're building or parsing.
 **/
#define ISO_NLPID_FRAME       0x00      /* Used internally */
#define ISO_Q933_FRAME        0x01      /* Used internally */
#define IETF_SNAP_HEADER      0x02      /* Used internally */
#define Q933_USER_SPEC        0x03      /* Used internally */
#define ISO_FRF9_FRAME        0x04      /* Used internally */
#define CISCO_ENCAP_FRAME	  0x05		/* Used Internally */
#define UNKNOWN_NLPID         0xFF      /* Used internally */

/** Frame Information Masks -- in frame fragments
 **/
#define FINAL_FRAME_BIT       0x8000   /* 1 = last frame */
#define FRAGMENT_RSVD         0x7800   /* Reserved stuff */
#define FRAME_OFFSET          0x07ff   /* Bits used for fragment offset */

/**/
/** PIDs used in actual encapsulation header....
 **/
#define _PID_ETHERNET_FCS      0x0001 /* Ethernet and 802.3 (w/FCS) */
#define _PID_ETHERNET          0x0007 /* Ethernet and 802.3 (no FCS) */
#define _PID_TOKEN_BUS_FCS     0x0002 /* 802.4 (w/FCS) */
#define _PID_TOKEN_BUS         0x0008 /* 802.4 (no FCS) */
#define _PID_TOKEN_RING_FCS    0x0003 /* 802.5 (w/FCS) */
#define _PID_TOKEN_RING        0x0009 /* 802.5 (no FCS) */
#define _PID_FDDI_FCS          0x0004 /* FDDI (w/FCS) */
#define _PID_FDDI              0x000A /* FDDI (no FCS) */
#define _PID_MAN_FCS           0x0005 /* 802.6 (w/FCS) */
#define _PID_MAN               0x000B /* 802.6 (no FCS) */
#define _PID_BPDU              0x000E /* 802.1(d) Bridged PDUs */
#define _PID_IP                0x00CC /* Internet Protocol */
#define _PID_ISO_CLNP          0x0081 /* ISO CLNP */
#define _PID_ISO_ESIS          0x0082 /* ISO ESIS */
#define _PID_ISO_ISIS          0x0083 /* NLPID_ISO_ISIS /* ISO ISIS */
#define _PID_OLD_ETHERNET      0x00CE /* Old style Ethernet */
#define _PID_SNA_SUBAREA       0x0081 /* SNA SUBAREA (FID4) */
#define _PID_SNA_PERIPHERAL    0x0082 /* SNA - Peripheral (FID2) */
#define _PID_SNA_APPN          0x0083 /* SNA - APPN (FID2) */
#define _PID_NETBIOS           0x0084 /* NETBIOS */
#define _PID_ARP               0x0806 /* ARP SNAP-Ethertype encapsulation */
#define _PID_IPX               0x8137 /* IPX SNAP-Ethertype encapsulation */
#define _PID_CISCO_IP 		   0x0000 /* Cisco IP Encapsulation */

/** PID values for special target system use. See PID table below.
 **/

#define _PID_RSVD_02  0x00E1 /* This pid value is reserved for specials */
#define _PID_RSVD_03  0x00E2 /* This pid value is reserved for specials */
#define _PID_RSVD_04  0x00E3 /* This pid value is reserved for specials */
#define _PID_RSVD_05  0x00E4 /* This pid value is reserved for specials */
#define _PID_RSVD_06  0x00E5 /* This pid value is reserved for specials */
#define _PID_RSVD_07  0x00E6 /* This pid value is reserved for specials */
#define _PID_RSVD_08  0x00E7 /* This pid value is reserved for specials */
#define _PID_RSVD_09  0x00E8 /* This pid value is reserved for specials */
#define _PID_RSVD_10  0x00E9 /* This pid value is reserved for specials */

/**/
/** Macros
 **/
#ifndef STREAM_MESSAGES

#define mSTARTOFRAME(p)            m_MMGR_DATA(p, u_char *)
#define mMK_HDR_SPC(p,n)           m_MMGR_DEC_OFF(p,n);m_MMGR_INC_LEN(p,n)
#define mREMOVE_FRAME_HDR(p,n)     m_MMGR_INC_OFF(p,n);m_MMGR_DEC_LEN(p,n)
#define mIS_VALID_FRAMETYPE(a)     (a == FRAME_TYPE_03)
#define mIS_PID_VALID(a)           (a != PID_UNKNOWN)
#define mIS_PID_REGISTERED(a)      (a != (FRS_PROTOCOL_ENTRY *) 0)
#define mIS_FRAGMENTED_FRAME(a)    (a == FRAGMENT_PID)
#define mIS_NULL_FRAME(a)          (a == BNULL)
#define mGET_LAST_USRBUF(a,b) for(b = a->link; b != BNULL; a = b, b = a->link);
#define mGET_MAX_FRAME_LEN(p) p->plcb->my_cfg->frs_link_max_frsize

#else

#define mSTARTOFRAME(p)            m_MMGR_DATA(p, u_char *)
#define mMK_HDR_SPC(p,n)           m_MMGR_DEC_OFF(p,n);
#define mREMOVE_FRAME_HDR(p,n)     m_MMGR_INC_OFF(p,n);
#define mIS_VALID_FRAMETYPE(a)     (a == FRAME_TYPE_03)
#define mIS_PID_VALID(a)           (a != PID_UNKNOWN)
#define mIS_PID_REGISTERED(a)      (a != (FRS_PROTOCOL_ENTRY *) 0)
#define mIS_FRAGMENTED_FRAME(a)    (a == FRAGMENT_PID)
#define mIS_NULL_FRAME(a)          (a == BNULL)
#define mGET_LAST_USRBUF(a,b) for(b = a->b_cont; b != (mblk_t *)NULL; a = b, b = a->b_cont);
#define mGET_MAX_FRAME_LEN(p) p->plcb->my_cfg->frs_link_max_frsize

#endif
/**/
/** States for various FSMs
 **/
#define _IDLE              0x00  /* start state for fsm */
#define _PARSE_FRAME       0x01  /* state for parsing a frame header */
#define _PARSE_FRAGMENT    0x02  /* state for processing a frame fragment */
#define _FRAME_ERROR       0x03  /* state entered when frame is in error */
#define _FSM_ERROR         0x04  /* state entered when state/input pair does */
                                 /* not having processing written for it */
#define _BUILD_FRAME       0x05  /* state for creating a frame relay frame */

/** FSM Inputs/Outputs
 **/
#define _done              0x00  /* Frame header processing is complete */
#define _new_frame         0x01  /* New frame encountered */
#define _snap_header       0x02  /* Snap header encountered */
#define _user_frame        0x03  /* SNAP/Fragmentation headers are stripped */
#define _iso_nlpid_frame   0x04  /* Frame is an iso frame with valid nlpid */
#define _iso_q933_frame    0x05  /* Frame has an nlpid of 0x08 */
#define _frame_fragment    0x06  /* Frame has an nlpid of 0x80 */
#define _frame_complete    0x07  /* Complete frame processed */
#define _frame_incomplete  0x08  /* Frame processed (more fragments expected) */
#define _bad_frame_control 0x09  /* Header control field is invalid/unknown */
#define _unknown_nlpid     0x0A  /* NLPID value is unknown/unsupported */
#define _unknown_oui       0x0B  /* OUI value is unknown/unsupported */
#define _unknown_pid       0x0C  /* PID value is unknown/unsupported */
#define _unregistered_pid  0x0D  /* LCN not opened using this PID value */
#define _drop_frame        0x0E  /* Frame was dropped */
#define _invalid_sequence  0x0F  /* Frame received out of sequence order */
#define _invalid_frame     0x10  /* Frame header is incorrect */
#define _lost_frame        0x11  /* Frame fragment rx out of order */
#define _invalid_bufsize   0x12  /* Frame has an invalid buffer size */
#define _bridged_frame     0x13  /* Frame requires a snap header */
#define _add_q922_addr     0x14  /* Add the DLCI to an outbound frame */
#define _begin             0x15  /* Start token for all fsms */
#define _no_buffers        0x16  /* encap_set_framebounds could not
                                    get needed buffer for header insertion */
#define	_iso_frf9_frame    0x17  /* FRF.9 Compressed frame */
#define _cisco_encap_frame 0x18  /* Cisco Encap Frame Type */

/**/
/** NOTES ON TRANSITION TABLES. All of the FSM routines written use the STATES/
 ** inputs and outputs previously defined. ALL FSMs start in the _IDLE state 
 ** with the input token _begin. All of the FSM routines terminate in the state 
 ** _IDLE with the input token _done. The transition entries are read from left
 ** to right and are in no particular order in the table. The output token from
 ** a STATE/input pair is the input token to the state indicated in the NEXT 
 ** STATE column. Some STATES may have the same input token defined several 
 ** times. However, the output token for each one will be unique; this indicates
 ** that there are several different output tokens which can be generated by a 
 ** single STATE/input pair.

 ** Here is an example of a complete series of transitions for parsing a frame
 ** with the following characteristics:

     The frame contains an encapsulated ETHERNET frame. However, the control
     field which appears after the Q922 address (DLCI) contains an invalid 
     value. The state transitions from the encap_parse_header FSM would be:

    _IDLE             _begin              _new_frame           _PARSE_FRAME
    _PARSE_FRAME      _new_frame          _bad_frame_control   _FRAME_ERROR
    _FRAME_ERROR      _bad_frame_control  _done                _IDLE
    _IDLE             _done               _done                _IDLE

              ******************************************************
              ** FSM Transition Table for encap_parse_header.      *
              ******************************************************

STATE               input                output               NEXT STATE
--------------     -----------------    ------------------   -----------------
_IDLE               _done               _done                 _IDLE
_IDLE               _frame_complete     _done                 _IDLE
_IDLE               _frame_incomplete   _done                 _IDLE
_IDLE               _begin              _new_frame            _PARSE_FRAME

_PARSE_FRAME        _new_frame          _bad_frame_control    _FRAME_ERROR
_PARSE_FRAME        _new_frame          _unknown_nlpid        _FRAME_ERROR
_PARSE_FRAME        _new_frame          _iso_nlpid_frame      _PARSE_FRAME
_PARSE_FRAME        _new_frame          _iso_q933_frame       _PARSE_FRAME
_PARSE_FRAME        _new_frame          _snap_header          _PARSE_FRAME
_PARSE_FRAME        _snap_header        _bad_frame_control    _FRAME_ERROR
_PARSE_FRAME        _snap_header        _unknown_oui          _FRAME_ERROR   
_PARSE_FRAME        _snap_header        _unknown_pid          _FRAME_ERROR   
_PARSE_FRAME        _snap_header        _unregistered_pid     _FRAME_ERROR   
_PARSE_FRAME        _snap_header        _user_frame           _PARSE_FRAME
_PARSE_FRAME        _snap_header        _frame_fragment       _PARSE_FRAGMENT
_PARSE_FRAME        _snap_header        _invalid_frame        _FRAME_ERROR
_PARSE_FRAME        _iso_nlpid_frame    _unregistered_pid     _FRAME_ERROR
_PARSE_FRAME        _iso_nlpid_frame    _user_frame           _PARSE_FRAME
_PARSE_FRAME        _iso_q933_frame     _invalid_frame        _FRAME_ERROR
_PARSE_FRAME        _iso_q933_frame     _unregistered_pid     _FRAME_ERROR
_PARSE_FRAME        _iso_q933_frame     _unknown_pid          _FRAME_ERROR
_PARSE_FRAME        _iso_q933_frame     _user_frame           _PARSE_FRAME
_PARSE_FRAME        _user_frame         _frame_complete       _IDLE
_PARSE_FRAME        _user_frame         _frame_incomplete     _IDLE

_PARSE_FRAGMENT     _frame_fragment     _new_frame            _PARSE_FRAME
_PARSE_FRAGMENT     _frame_fragment     _lost_frame           _FRAME_ERROR

_FRAME_ERROR        _unknown_nlpid      _done                 _IDLE
_FRAME_ERROR        _unknown_oui        _done                 _IDLE
_FRAME_ERROR        _unknown_pid        _done                 _IDLE
_FRAME_ERROR        _unregistered_pid   _done                 _IDLE
_FRAME_ERROR        _bad_frame_control  _done                 _IDLE
_FRAME_ERROR        _invalid_sequence   _done                 _IDLE
_FRAME_ERROR        _invalid_frame      _done                 _IDLE
_FRAME_ERROR        _lost_frame         _done                 _IDLE


             *******************************************************
             ** FSM Transition Table for encap_fragment_handler.   *
             *******************************************************

STATE               input                output               NEXT STATE
--------------     -----------------    ------------------   -----------------
_IDLE               _done               _done                 _IDLE
_IDLE               _frame_complete     _done                 _IDLE
_IDLE               _frame_incomplete   _done                 _IDLE
_IDLE               _begin              _new_frame            _PARSE_FRAME

_PARSE_FRAME        _new_frame          _drop_frame           _FRAME_ERROR
_PARSE_FRAME        _new_frame          _unknown_nlpid        _FRAME_ERROR
_PARSE_FRAME        _new_frame          _snap_header          _PARSE_FRAME
_PARSE_FRAME        _snap_header        _drop_frame           _FRAME_ERROR
_PARSE_FRAME        _snap_header        _frame_fragment       _PARSE_FRAGMENT

_PARSE_FRAGMENT     _frame_fragment     _drop_frame           _FRAME_ERROR
_PARSE_FRAGMENT     _frame_fragment     _lost_frame           _FRAME_ERROR
_PARSE_FRAGMENT     _frame_fragment     _frame_complete       _IDLE
_PARSE_FRAGMENT     _frame_fragment     _frame_incomplete     _IDLE

_FRAME_ERROR        _unknown_nlpid      _done                 _IDLE
_FRAME_ERROR        _drop_frame         _done                 _IDLE
_FRAME_ERROR        _lost_frame         _done                 _IDLE


             *******************************************************
             ** FSM Transition Table for encap_frame_complete.     *
             *******************************************************

STATE               input                output               NEXT STATE
--------------     -----------------    ------------------   -----------------
_IDLE               _done               _done                 _IDLE
_IDLE               _frame_complete     _done                 _IDLE
_IDLE               _frame_incomplete   _done                 _IDLE
_IDLE               _begin              _new_frame            _PARSE_FRAME

_PARSE_FRAME        _new_frame          _iso_nlpid_frame      _PARSE_FRAME
_PARSE_FRAME        _new_frame          _iso_q933_frame       _PARSE_FRAME
_PARSE_FRAME        _new_frame          _snap_header          _PARSE_FRAME
_PARSE_FRAME        _snap_header        _user_frame           _PARSE_FRAME
_PARSE_FRAME        _snap_header        _frame_fragment       _PARSE_FRAGMENT
_PARSE_FRAME        _iso_nlpid_frame    _user_frame           _PARSE_FRAME
_PARSE_FRAME        _iso_q933_frame     _user_frame           _PARSE_FRAME
_PARSE_FRAME        _user_frame         _frame_complete       _IDLE
_PARSE_FRAME        _user_frame         _frame_incomplete     _IDLE
_PARSE_FRAGMENT     _frame_fragment     _new_frame            _PARSE_FRAME


              ******************************************************
              ** FSM Transition Table for encap_makeframe.         *
              ******************************************************

STATE               input                output               NEXT STATE
--------------     -----------------    ------------------   -----------------
_IDLE               _done               _done                 _IDLE
_IDLE               _frame_complete     _done                 _IDLE
_IDLE               _begin              _iso_nlpid_frame      _BUILD_FRAME
_IDLE               _begin              _iso_q933_frame       _BUILD_FRAME
_IDLE               _begin              _bridged_frame        _BUILD_FRAME
_IDLE               _begin              _invalid_bufsize      _FRAME_ERROR
_IDLE               _begin              _invalid_frame        _FRAME_ERROR
_IDLE               _begin              _no_buffers           _FRAME_ERROR

_BUILD_FRAME        _iso_nlpid_frame    _frame_fragment       _BUILD_FRAME
_BUILD_FRAME        _iso_nlpid_frame    _add_q922_addr        _BUILD_FRAME
_BUILD_FRAME        _iso_q933_frame     _frame_fragment       _BUILD_FRAME
_BUILD_FRAME        _iso_q933_frame     _add_q922_addr        _BUILD_FRAME
_BUILD_FRAME        _bridged_frame      _frame_fragment       _BUILD_FRAME
_BUILD_FRAME        _bridged_frame      _add_q922_addr        _BUILD_FRAME
_BUILD_FRAME        _frame_fragment     _frame_complete       _BUILD_FRAME
_BUILD_FRAME        _frame_fragment     _invalid_bufsize      _FRAME_ERROR
_BUILD_FRAME        _add_q922_addr      _frame_complete       _IDLE

_FRAME_ERROR        _invalid_bufsize    _done                 _IDLE
_FRAME_ERROR        _invalid_frame      _done                 _IDLE
_FRAME_ERROR        _no_buffers         _done                 _IDLE

**/

#endif


/**/
/** Protocol lookup table -- maps user API to PID values...
 **/
