home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / rfc / 1500s / rfc1549.txt < prev    next >
Text File  |  1993-12-02  |  36KB  |  1,011 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. Network Working Group                                 W. Simpson, Editor
  8. Request for Comments: 1549                                    Daydreamer
  9. Category: Standards Track                                  December 1993
  10.  
  11.  
  12.                           PPP in HDLC Framing
  13.  
  14. Status of this Memo
  15.  
  16.    This document specifies an Internet standards track protocol for the
  17.    Internet community, and requests discussion and suggestions for
  18.    improvements.  Please refer to the current edition of the "Internet
  19.    Official Protocol Standards" (STD 1) for the standardization state
  20.    and status of this protocol.  Distribution of this memo is unlimited.
  21.  
  22. Abstract
  23.  
  24.    The Point-to-Point Protocol (PPP) [1] provides a standard method for
  25.    transporting multi-protocol datagrams over point-to-point links.
  26.  
  27.    This document describes the use of HDLC for framing PPP encapsulated
  28.    packets. This document is the product of the Point-to-Point Protocol
  29.    Working Group of the Internet Engineering Task Force (IETF).
  30.    Comments should be submitted to the ietf-ppp@ucdavis.edu mailing
  31.    list.
  32.  
  33. Table of Contents
  34.  
  35.    1.   Introduction ..................................................2
  36.    1.1  Specification of Requirements .................................2
  37.    1.2  Terminology ...................................................3
  38.    2.   Physical Layer Requirements ...................................3
  39.    3.   The Data Link Layer ...........................................4
  40.    3.1  Frame Format ..................................................5
  41.    3.2  Modification of the Basic Frame ...............................7
  42.    4.   Asynchronous HDLC .............................................7
  43.    5.   Bit-synchronous HDLC ..........................................5
  44.    6.   Octet-synchronous HDLC ........................................12
  45.    APPENDIX A. Fast Frame Check Sequence (FCS) Implementation .........13
  46.    A.1  FCS Computation Method ........................................13
  47.    A.2  Fast FCS table generator ......................................15
  48.    SECURITY CONSIDERATIONS ............................................16
  49.    REFERENCES .........................................................17
  50.    ACKNOWLEDGEMENTS ...................................................17
  51.    CHAIR'S ADDRESS ....................................................18
  52.    EDITOR'S ADDRESS ...................................................18
  53.  
  54.  
  55.  
  56.  
  57.  
  58. Simpson                                                         [Page 1]
  59.  
  60. RFC 1549                      HDLC Framing                Decvember 1993
  61.  
  62.  
  63. 1.  Introduction
  64.  
  65.    This specification provides for framing over both bit-oriented and
  66.    octet-oriented synchronous links, and asynchronous links with 8 bits
  67.    of data and no parity.  These links MUST be full-duplex, but MAY be
  68.    either dedicated or circuit-switched.  PPP uses HDLC as a basis for
  69.    the framing.
  70.  
  71.    An escape mechanism is specified to allow control data such as
  72.    XON/XOFF to be transmitted transparently over the link, and to remove
  73.    spurious control data which may be injected into the link by
  74.    intervening hardware and software.
  75.  
  76.    Some protocols expect error free transmission, and either provide
  77.    error detection only on a conditional basis, or do not provide it at
  78.    all.  PPP uses the HDLC Frame Check Sequence for error detection.
  79.    This is commonly available in hardware implementations, and a
  80.    software implementation is provided.
  81.  
  82. 1.1 Specification of Requirements
  83.  
  84.    In this document, several words are used to signify the requirements
  85.    of the specification.  These words are often capitalized.
  86.  
  87.     MUST
  88.  
  89.       This word, or the adjective "required", means that the definition
  90.       is an absolute requirement of the specification.
  91.  
  92.     MUST NOT
  93.  
  94.       This phrase means that the definition is an absolute prohibition
  95.       of the specification.
  96.  
  97.     SHOULD
  98.  
  99.       This word, or the adjective "recommended", means that there may
  100.       exist valid reasons in particular circumstances to ignore this
  101.       item, but the full implications must be understood and carefully
  102.       weighed before choosing a different course.
  103.  
  104.     MAY
  105.  
  106.       This word, or the adjective "optional", means that this item is
  107.       one of an allowed set of alternatives.  An implementation which
  108.       does not include this option MUST be prepared to interoperate with
  109.       another implementation which does include the option.
  110.  
  111.  
  112.  
  113.  
  114. Simpson                                                         [Page 2]
  115.  
  116. RFC 1549                      HDLC Framing                Decvember 1993
  117.  
  118.  
  119. 1.2 Terminology
  120.  
  121.    This document frequently uses the following terms:
  122.  
  123.     datagram
  124.  
  125.       The unit of transmission in the network layer (such as IP).  A
  126.       datagram may be encapsulated in one or more packets passed to the
  127.       data link layer.
  128.  
  129.     frame
  130.  
  131.       The unit of transmission at the data link layer.  A frame may
  132.       include a header and/or a trailer, along with some number of units
  133.       of data.
  134.  
  135.     packet
  136.  
  137.       The basic unit of encapsulation, which is passed across the
  138.       interface between the network layer and the data link layer.  A
  139.       packet is usually mapped to a frame; the exceptions are when data
  140.       link layer fragmentation is being performed, or when multiple
  141.       packets are incorporated into a single frame.
  142.  
  143.     peer
  144.  
  145.       The other end of the point-to-point link.
  146.  
  147.     silently discard
  148.  
  149.       This means the implementation discards the packet without further
  150.       processing.  The implementation SHOULD provide the capability of
  151.       logging the error, including the contents of the silently
  152.       discarded packet, and SHOULD record the event in a statistics
  153.       counter.
  154.  
  155. 2. Physical Layer Requirements
  156.  
  157.    PPP is capable of operating across most DTE/DCE interfaces (such as,
  158.    EIA RS-232-C, EIA RS-422, EIA RS-423 and CCITT V.35).  The only
  159.    absolute requirement imposed by PPP is the provision of a full-duplex
  160.    circuit, either dedicated or circuit-switched, which can operate in
  161.    either an asynchronous (start/stop), bit-synchronous, or octet-
  162.    synchronous mode, transparent to PPP Data Link Layer frames.
  163.  
  164.     Interface Format
  165.  
  166.       PPP presents an octet interface to the physical layer.  There is
  167.  
  168.  
  169.  
  170. Simpson                                                         [Page 3]
  171.  
  172. RFC 1549                      HDLC Framing                Decvember 1993
  173.  
  174.  
  175.       no provision for sub-octets to be supplied or accepted.
  176.  
  177.  
  178.     PPP does not impose any restrictions regarding transmission rate,
  179.       other than that of the particular DTE/DCE interface.
  180.  
  181.     Control Signals
  182.  
  183.       PPP does not require the use of control signals, such as Request
  184.       To Send (RTS), Clear To Send (CTS), Data Carrier Detect (DCD), and
  185.       Data Terminal Ready (DTR).
  186.  
  187.       When available, using such signals can allow greater functionality
  188.       and performance.  In particular, such signals SHOULD be used to
  189.       signal the Up and Down events in the LCP Option Negotiation
  190.       Automaton [1].  When such signals are not available, the
  191.       implementation MUST signal the Up event to LCP upon
  192.       initialization, and SHOULD NOT signal the Down event.
  193.  
  194.       Because signalling is not required, the physical layer MAY be
  195.       decoupled from the data link layer, hiding the transient details
  196.       of the physical transport.  This has implications for mobility in
  197.       cellular radio networks, and other rapidly switching links.
  198.  
  199.       When moving from cell to cell within the same zone, an
  200.       implementation MAY choose to treat the entire zone as a single
  201.       link, even though transmission is switched among several
  202.       frequencies.  The link is considered to be with the central
  203.       control unit for the zone, rather than the individual cell
  204.       transceivers.  However, the link SHOULD re-establish its
  205.       configuration whenever the link is switched to a different
  206.       administration.
  207.  
  208.       Due to the bursty nature of data traffic, some implementations
  209.       have choosen to disconnect the physical layer during periods of
  210.       inactivity, and reconnect when traffic resumes, without informing
  211.       the data link layer.  Robust implementations should avoid using
  212.       this trick over-zealously, since the price for decreased setup
  213.       latency is decreased security.  Implementations SHOULD signal the
  214.       Down event whenever "significant time" has elapsed since the link
  215.       was disconnected.  The value for "significant time" is a matter of
  216.       considerable debate, and is based on the tariffs, call setup
  217.       times, and security concerns of the installation.
  218.  
  219. 3. The Data Link Layer
  220.  
  221.    PPP uses the principles, terminology, and frame structure of the
  222.    International Organization For Standardization's (ISO) 3309-1979
  223.  
  224.  
  225.  
  226. Simpson                                                         [Page 4]
  227.  
  228. RFC 1549                      HDLC Framing                Decvember 1993
  229.  
  230.  
  231.    High-level Data Link Control (HDLC) frame structure [2], as modified
  232.    by "Addendum 1: Start/stop transmission" [3], which specifies
  233.    modifications to allow HDLC use in asynchronous environments.
  234.  
  235.    The PPP control procedures use the definitions and Control field
  236.    encodings standardized in ISO 4335-1979 [4] and ISO 4335-
  237.    1979/Addendum 1-1979 [5].  PPP framing is also consistent with CCITT
  238.    Recommendation X.25 LAPB [6], and CCITT Recommendation Q.922 [7],
  239.    since those are also based on HDLC.
  240.  
  241.    The purpose of this specification is not to document what is already
  242.    standardized in ISO 3309.  It is assumed that the reader is already
  243.    familiar with HDLC, or has access to a copy of [2] or [6].  Instead,
  244.    this document attempts to give a concise summary and point out
  245.    specific options and features used by PPP.
  246.  
  247.    To remain consistent with standard Internet practice, and avoid
  248.    confusion for people used to reading RFCs, all binary numbers in the
  249.    following descriptions are in Most Significant Bit to Least
  250.    Significant Bit order, reading from left to right, unless otherwise
  251.    indicated.  Note that this is contrary to standard ISO and CCITT
  252.    practice which orders bits as transmitted (network bit order).  Keep
  253.    this in mind when comparing this document with the international
  254.    standards documents.
  255.  
  256. 3.1 Frame Format
  257.  
  258.    A summary of the PPP HDLC frame structure is shown below.  This
  259.    figure does not include start/stop bits (for asynchronous links), nor
  260.    any bits or octets inserted for transparency.  The fields are
  261.    transmitted from left to right.
  262.  
  263.               +----------+----------+----------+
  264.               |   Flag   | Address  | Control  |
  265.               | 01111110 | 11111111 | 00000011 |
  266.               +----------+----------+----------+
  267.               +----------+-------------+---------+
  268.               | Protocol | Information | Padding |
  269.               | 16 bits  |      *      |    *    |
  270.               +----------+-------------+---------+
  271.               +----------+----------+------------------+
  272.               |   FCS    |   Flag   | Inter-frame Fill |
  273.               | 16 bits  | 01111110 | or next Address  |
  274.               +----------+----------+------------------+
  275.  
  276.    The Protocol, Information and Padding fields are described in the
  277.    Point-to-Point Protocol Encapsulation [1].
  278.  
  279.  
  280.  
  281.  
  282. Simpson                                                         [Page 5]
  283.  
  284. RFC 1549                      HDLC Framing                Decvember 1993
  285.  
  286.  
  287.     Flag Sequence
  288.  
  289.       The Flag Sequence indicates the beginning or end of a frame, and
  290.       always consists of the binary sequence 01111110 (hexadecimal
  291.       0x7e).
  292.  
  293.       The Flag Sequence is a frame separator.  Only one Flag Sequence is
  294.       required between two frames.  Two consecutive Flag Sequences
  295.       constitute an empty frame, which is ignored, and not counted as a
  296.       FCS error.
  297.  
  298.     Address Field
  299.  
  300.       The Address field is a single octet and contains the binary
  301.       sequence 11111111 (hexadecimal 0xff), the All-Stations address.
  302.       PPP does not assign individual station addresses.  The All-
  303.       Stations address MUST always be recognized and received.  The use
  304.       of other address lengths and values may be defined at a later
  305.       time, or by prior agreement.  Frames with unrecognized Addresses
  306.       SHOULD be silently discarded.
  307.  
  308.     Control Field
  309.  
  310.       The Control field is a single octet and contains the binary
  311.       sequence 00000011 (hexadecimal 0x03), the Unnumbered Information
  312.       (UI) command with the P/F bit set to zero.  The use of other
  313.       Control field values may be defined at a later time, or by prior
  314.       agreement.  Frames with unrecognized Control field values SHOULD
  315.       be silently discarded.
  316.  
  317.     Frame Check Sequence (FCS) Field
  318.  
  319.       The Frame Check Sequence field is normally 16 bits (two octets).
  320.       The use of other FCS lengths may be defined at a later time, or by
  321.       prior agreement.  The FCS is transmitted with the coefficient of
  322.       the highest term first.
  323.  
  324.       The FCS field is calculated over all bits of the Address, Control,
  325.       Protocol, Information and Padding fields, not including any start
  326.       and stop bits (asynchronous) nor any bits (synchronous) or octets
  327.       (asynchronous or synchronous) inserted for transparency.  This
  328.       also does not include the Flag Sequences nor the FCS field itself.
  329.  
  330.          Note: When octets are received which are flagged in the Async-
  331.          Control-Character-Map, they are discarded before calculating
  332.          the FCS.
  333.  
  334.          For more information on the specification of the FCS, see ISO
  335.  
  336.  
  337.  
  338. Simpson                                                         [Page 6]
  339.  
  340. RFC 1549                      HDLC Framing                Decvember 1993
  341.  
  342.  
  343.          3309 [2] or CCITT X.25 [6].
  344.  
  345.    The end of the Information and Padding fields is found by locating
  346.    the closing Flag Sequence and removing the Frame Check Sequence
  347.    field.
  348.  
  349. 3.2.  Modification of the Basic Frame
  350.  
  351.    The Link Control Protocol can negotiate modifications to the basic
  352.    HDLC frame structure.  However, modified frames will always be
  353.    clearly distinguishable from standard frames.
  354.  
  355.     Address-and-Control-Field-Compression
  356.  
  357.       When using the default HDLC framing, the Address and Control
  358.       fields contain the hexadecimal values 0xff and 0x03 respectively.
  359.  
  360.       On transmission, compressed Address and Control fields are formed
  361.       by simply omitting them.
  362.  
  363.       On reception, the Address and Control fields are decompressed by
  364.       examining the first two octets.  If they contain the values 0xff
  365.       and 0x03, they are assumed to be the Address and Control fields.
  366.       If not, it is assumed that the fields were compressed and were not
  367.       transmitted.
  368.  
  369.       By definition, the first octet of a two octet Protocol field will
  370.       never be 0xff (since it is not even).  The Protocol field value
  371.       0x00ff is not allowed (reserved) to avoid ambiguity when
  372.       Protocol-Field-Compression is enabled and the first Information
  373.       field octet is 0x03.
  374.  
  375.       When other Address or Control field values are in use, Address-
  376.       and-Control-Field-Compression MUST NOT be negotiated.
  377.  
  378. 4.  Asynchronous HDLC
  379.  
  380.    This section summarizes the use of HDLC with 8-bit asynchronous
  381.    links.
  382.  
  383.     Flag Sequence
  384.  
  385.       The Flag Sequence indicates the beginning or end of a frame.  The
  386.       octet stream is examined on an octet-by-octet basis for the value
  387.       01111110 (hexadecimal 0x7e).
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394. Simpson                                                         [Page 7]
  395.  
  396. RFC 1549                      HDLC Framing                Decvember 1993
  397.  
  398.  
  399.     Transparency
  400.  
  401.       An octet stuffing procedure is used.  The Control Escape octet is
  402.       defined as binary 01111101 (hexadecimal 0x7d) where the bit
  403.       positions are numbered 87654321 (not 76543210, BEWARE).
  404.  
  405.       Each end of the link maintains two Async-Control-Character-Maps.
  406.       The receiving ACCM is 32 bits, but the sending ACCM may be up to
  407.       256 bits.  This results in four distinct ACCMs, two in each
  408.       direction of the link.
  409.  
  410.       The default receiving ACCM is 0xffffffff.  The default sending
  411.       ACCM is 0xffffffff, plus the Control Escape and Flag Sequence
  412.       characters themselves, plus whatever other outgoing characters are
  413.       known to be intercepted.
  414.  
  415.       After FCS computation, the transmitter examines the entire frame
  416.       between the two Flag Sequences.  Each Flag Sequence, Control
  417.       Escape octet, and octet with value less than hexadecimal 0x20
  418.       which is flagged in the sending Async-Control-Character-Map, is
  419.       replaced by a two octet sequence consisting of the Control Escape
  420.       octet and the original octet with bit 6 complemented (exclusive-
  421.       or'd with hexadecimal 0x20).
  422.  
  423.       Prior to FCS computation, the receiver examines the entire frame
  424.       between the two Flag Sequences.  Each octet with value less than
  425.       hexadecimal 0x20 is checked.  If it is flagged in the receiving
  426.       Async-Control-Character-Map, it is simply removed (it may have
  427.       been inserted by intervening data communications equipment).  For
  428.       each Control Escape octet, that octet is also removed, but bit 6
  429.       of the following octet is complemented, unless it is the Flag
  430.       Sequence.
  431.  
  432.          Note: The inclusion of all octets less than hexadecimal 0x20
  433.          allows all ASCII control characters [8] excluding DEL (Delete)
  434.          to be transparently communicated through all known data
  435.          communications equipment.
  436.  
  437.       The transmitter may also send octets with value in the range 0x40
  438.       through 0xff (except 0x5e) in Control Escape format.  Since these
  439.       octet values are not negotiable, this does not solve the problem
  440.       of receivers which cannot handle all non-control characters.
  441.       Also, since the technique does not affect the 8th bit, this does
  442.       not solve problems for communications links that can send only 7-
  443.       bit characters.
  444.  
  445.       A few examples may make this more clear.  Packet data is
  446.       transmitted on the link as follows:
  447.  
  448.  
  449.  
  450. Simpson                                                         [Page 8]
  451.  
  452. RFC 1549                      HDLC Framing                Decvember 1993
  453.  
  454.  
  455.          0x7e is encoded as 0x7d, 0x5e.  0x7d is encoded as 0x7d, 0x5d.
  456.          0x01 is encoded as 0x7d, 0x21.
  457.  
  458.       Some modems with software flow control may intercept outgoing DC1
  459.       and DC3 ignoring the 8th (parity) bit.  This data would be
  460.       transmitted on the link as follows:
  461.  
  462.          0x11 is encoded as 0x7d, 0x31.  0x13 is encoded as 0x7d, 0x33.
  463.          0x91 is encoded as 0x7d, 0xb1.  0x93 is encoded as 0x7d, 0xb3.
  464.  
  465.     Aborting a Transmission
  466.  
  467.       On asynchronous links, frames may be aborted by transmitting a "0"
  468.       stop bit where a "1" bit is expected (framing error) or by
  469.       transmitting a Control Escape octet followed immediately by a
  470.       closing Flag Sequence.
  471.  
  472.     Time Fill
  473.  
  474.       For asynchronous links, inter-octet and inter-frame time fill MUST
  475.       be accomplished by transmitting continuous "1" bits (mark-hold
  476.       state).
  477.  
  478.       Inter-frame time fill can be viewed as extended inter-octet time
  479.       fill.  Doing so can save one octet for every frame, decreasing
  480.       delay and increasing bandwidth.  This is possible since a Flag
  481.       Sequence may serve as both a frame close and a frame begin.  After
  482.       having received any frame, an idle receiver will always be in a
  483.       frame begin state.
  484.  
  485.       Robust transmitters should avoid using this trick over-zealously,
  486.       since the price for decreased delay is decreased reliability.
  487.       Noisy links may cause the receiver to receive garbage characters
  488.       and interpret them as part of an incoming frame.  If the
  489.       transmitter does not send a new opening Flag Sequence before
  490.       sending the next frame, then that frame will be appended to the
  491.       noise characters causing an invalid frame (with high reliability).
  492.       It is suggested that implementations will achieve the best results
  493.       by always sending an opening Flag Sequence if the new frame is not
  494.       back-to-back with the last.  Transmitters SHOULD send an open Flag
  495.       Sequence whenever "appreciable time" has elapsed after the prior
  496.       closing Flag Sequence.  The maximum value for "appreciable time"
  497.       is likely to be no greater than the typing rate of a slow typist,
  498.       say 1 second.
  499.  
  500.     Encoding
  501.  
  502.       All octets are transmitted with one start bit, eight bits of data,
  503.  
  504.  
  505.  
  506. Simpson                                                         [Page 9]
  507.  
  508. RFC 1549                      HDLC Framing                Decvember 1993
  509.  
  510.  
  511.       and one stop bit.  There is no provision for seven bit
  512.       asynchronous links.
  513.  
  514. 5. Bit-synchronous HDLC
  515.  
  516.    This section summarizes the use of HDLC with bit-synchronous links.
  517.  
  518.     Flag Sequence
  519.  
  520.       The Flag Sequence indicates the beginning or end of a frame, and
  521.       is used for frame synchronization.  The bit stream is examined on
  522.       a bit-by-bit basis for the binary sequence 01111110 (hexadecimal
  523.       0x7e).
  524.  
  525.       The "shared zero mode" Flag Sequence "011111101111110" SHOULD NOT
  526.       be used.  When not avoidable, such an implementation MUST ensure
  527.       that the first Flag Sequence detected (the end of the frame) is
  528.       promptly communicated to the link layer.  Use of the shared zero
  529.       mode hinders interoperability with synchronous-to-asynchronous
  530.       converters.
  531.  
  532.     Transparency
  533.  
  534.       The transmitter examines the entire frame between the two Flag
  535.       Sequences.  A "0" bit is inserted after all sequences of five
  536.       contiguous "1" bits (including the last 5 bits of the FCS) to
  537.       ensure that a Flag Sequence is not simulated.
  538.  
  539.       When receiving, any "0" bit that directly follows five contiguous
  540.       "1" bits is discarded.
  541.  
  542.       Since the Control Escape octet-stuffing method is not used, the
  543.       default receiving and sending Async-Control-Character-Maps are 0.
  544.  
  545.       There may be some use of synchronous-to-asynchronous converters
  546.       (some built into modems) in point-to-point links resulting in a
  547.       synchronous PPP implementation on one end of a link and an
  548.       asynchronous implementation on the other.  It is the
  549.       responsibility of the converter to do all mapping conversions
  550.       during operation.
  551.  
  552.       To enable this functionality, bit-synchronous PPP implementations
  553.       MUST always respond to the Async-Control-Character-Map
  554.       Configuration Option with an LCP Configure-Ack.  However,
  555.       acceptance of the Configuration Option does not imply that the
  556.       bit-synchronous implementation will do any octet mapping.
  557.       Instead, all such octet mapping will be performed by the
  558.       asynchronous-to-synchronous converter.
  559.  
  560.  
  561.  
  562. Simpson                                                        [Page 10]
  563.  
  564. RFC 1549                      HDLC Framing                Decvember 1993
  565.  
  566.  
  567.     Aborting a Transmission
  568.  
  569.       A sequence of more than six "1" bits indicates an invalid frame,
  570.       which is ignored, and not counted as a FCS error.
  571.  
  572.     Inter-frame Time Fill
  573.  
  574.       For bit-synchronous links, the Flag Sequence SHOULD be transmitted
  575.       during inter-frame time fill.  There is no provision for inter-
  576.       octet time fill.
  577.  
  578.       Mark idle (continuous ones) SHOULD NOT be used for inter-frame
  579.       ill.  However, certain types of circuit-switched links require the
  580.       use of mark idle, particularly those that calculate accounting
  581.       based on periods of bit activity.  When mark idle is used on a
  582.       bit-synchronous link, the implementation MUST ensure at least 15
  583.       consecutive "1" bits between Flags during the idle period, and
  584.       that the Flag Sequence is always generated at the beginning of a
  585.       frame after an idle period.
  586.  
  587.     Encoding
  588.  
  589.       The definition of various encodings and scrambling is the
  590.       responsibility of the DTE/DCE equipment in use, and is outside the
  591.       scope of this specification.
  592.  
  593.       While PPP will operate without regard to the underlying
  594.       representation of the bit stream, lack of standards for
  595.       transmission will hinder interoperability as surely as lack of
  596.       data link standards.  At speeds of 56 Kbps through 2.0 Mbps, NRZ
  597.       is currently most widely available, and on that basis is
  598.       recommended as a default.
  599.  
  600.       When configuration of the encoding is allowed, NRZI is recommended
  601.       as an alternative, because of its relative immunity to signal
  602.       inversion configuration errors, and instances when it MAY allow
  603.       connection without an expensive DSU/CSU.  Unfortunately, NRZI
  604.       encoding obviates the (1 + x) factor of the 16-bit FCS, so that
  605.       one error in 2**15 goes undetected (instead of one in 2**16), and
  606.       triple errors are not detected.  Therefore, when NRZI is in use,
  607.       it is recommended that the 32-bit FCS be negotiated, which does
  608.       not include the (1 + x) factor.
  609.  
  610.       At higher speeds of up to 45 Mbps, some implementors have chosen
  611.       the ANSI High Speed Synchronous Interface [HSSI].  While this
  612.       experience is currently limited, implementors are encouraged to
  613.       cooperate in choosing transmission encoding.
  614.  
  615.  
  616.  
  617.  
  618. Simpson                                                        [Page 11]
  619.  
  620. RFC 1549                      HDLC Framing                Decvember 1993
  621.  
  622.  
  623. 6.  Octet-synchronous HDLC
  624.  
  625.    This section summarizes the use of HDLC with octet-synchronous links,
  626.    such as SONET and optionally ISDN B or H channels.
  627.  
  628.    Although the bit rate is synchronous, there is no bit-stuffing.
  629.    Instead, the octet-stuffing feature of 8-bit asynchronous HDLC is
  630.    used.
  631.  
  632.     Flag Sequence
  633.  
  634.       The Flag Sequence indicates the beginning or end of a frame.  The
  635.       octet stream is examined on an octet-by-octet basis for the value
  636.       01111110 (hexadecimal 0x7e).
  637.  
  638.     Transparency
  639.  
  640.       An octet stuffing procedure is used.  The Control Escape octet is
  641.       defined as binary 01111101 (hexadecimal 0x7d).
  642.  
  643.       The octet stuffing procedure is described in "Asynchronous HDLC"
  644.       above.
  645.  
  646.       The sending and receiving implementations need escape only the
  647.       Flag Sequence and Control Escape octets.
  648.  
  649.       Considerations concerning the use of converters are described in
  650.       "Bit-synchronous HDLC" above.
  651.  
  652.     Aborting a Transmission
  653.  
  654.       Frames may be aborted by transmitting a Control Escape octet
  655.       followed immediately by a closing Flag Sequence.  The preceding
  656.       frame is ignored, and not counted as a FCS error.
  657.  
  658.     Inter-frame Time Fill
  659.  
  660.       The Flag Sequence MUST be transmitted during inter-frame time
  661.       fill.  There is no provision for inter-octet time fill.
  662.  
  663.     Encoding
  664.  
  665.       The definition of various encodings and scrambling is the
  666.       responsibility of the DTE/DCE equipment in use, and is outside the
  667.       scope of this specification.
  668.  
  669.  
  670.  
  671.  
  672.  
  673.  
  674. Simpson                                                        [Page 12]
  675.  
  676. RFC 1549                      HDLC Framing                Decvember 1993
  677.  
  678.  
  679. A.  Fast Frame Check Sequence (FCS) Implementation
  680.  
  681.    The FCS was originally designed with hardware implementations in
  682.    mind.  A serial bit stream is transmitted on the wire, the FCS is
  683.    calculated over the serial data as it goes out, and the complement of
  684.    the resulting FCS is appended to the serial stream, followed by the
  685.    Flag Sequence.
  686.  
  687.    The receiver has no way of determining that it has finished
  688.    calculating the received FCS until it detects the Flag Sequence.
  689.    Therefore, the FCS was designed so that a particular pattern results
  690.    when the FCS operation passes over the complemented FCS.  A good
  691.    frame is indicated by this "good FCS" value.
  692.  
  693. A.1 FCS Computation Method
  694.  
  695.    The following code provides a table lookup computation for
  696.    calculating the Frame Check Sequence as data arrives at the
  697.    interface.  This implementation is based on [9], [10], and [11].  The
  698.    table is created by the code in section B.2.
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730. Simpson                                                        [Page 13]
  731.  
  732. RFC 1549                      HDLC Framing                Decvember 1993
  733.  
  734.  
  735. /*
  736.  * u16 represents an unsigned 16-bit number.  Adjust the typedef for
  737.  * your hardware.
  738.  */
  739. typedef unsigned short u16;
  740.  
  741. /*
  742.  * FCS lookup table as calculated by the table generator in section B.2
  743.  */
  744. static u16 fcstab[256] = {
  745.    0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
  746.    0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
  747.    0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
  748.    0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
  749.    0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
  750.    0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
  751.    0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
  752.    0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
  753.    0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
  754.    0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
  755.    0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
  756.    0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
  757.    0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
  758.    0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
  759.    0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
  760.    0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
  761.    0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
  762.    0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
  763.    0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
  764.    0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
  765.    0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
  766.    0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
  767.    0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
  768.    0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
  769.    0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
  770.    0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
  771.    0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
  772.    0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
  773.    0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
  774.    0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
  775.    0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
  776.    0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78
  777.    };
  778.  
  779. #define PPPINITFCS16    0xffff  /* Initial FCS value */
  780. #define PPPGOODFCS16    0xf0b8  /* Good final FCS value */
  781.  
  782. /*
  783.  
  784.  
  785.  
  786. Simpson                                                        [Page 14]
  787.  
  788. RFC 1549                      HDLC Framing                Decvember 1993
  789.  
  790.  
  791.  * Calculate a new fcs given the current fcs and the new data.
  792.  */
  793. u16 pppfcs16(fcs, cp, len)
  794.     register u16 fcs;
  795.     register unsigned char *cp;
  796.     register int len;
  797. {
  798.     ASSERT(sizeof (u16) == 2);
  799.     ASSERT(((u16) -1) > 0);
  800.     while (len--)
  801.         fcs = (fcs >> 8) ^ fcstab[(fcs ^ *cp++) & 0xff];
  802.  
  803.     return (fcs);
  804. }
  805.  
  806. /*
  807.  * How to use the fcs
  808.  */
  809. tryfcs16(cp, len)
  810.     register unsigned char *cp;
  811.     register int len;
  812. {
  813.     u16 trialfcs;
  814.  
  815.     /* add on output */
  816.     trialfcs = pppfcs16( PPPINITFCS16, cp, len );
  817.     trialfcs ^= 0xffff;             /* complement */
  818.     cp[len] = (trialfcs & 0x00ff);  /* least significant byte first */
  819.     cp[len+1] = ((trialfcs >> 8) & 0x00ff);
  820.  
  821.     /* check on input */
  822.     trialfcs = pppfcs16( PPPINITFCS16, cp, len + 2 );
  823.     if ( trialfcs == PPPGOODFCS16 )
  824.         printf("Good FCS0);
  825. }
  826.  
  827. A.2.  Fast FCS table generator
  828.  
  829. The following code creates the lookup table used to calculate the FCS.
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842. Simpson                                                        [Page 15]
  843.  
  844. RFC 1549                      HDLC Framing                Decvember 1993
  845.  
  846.  
  847. /*
  848.  * Generate a FCS table for the HDLC FCS.
  849.  *
  850.  * Drew D. Perkins at Carnegie Mellon University.
  851.  *
  852.  * Code liberally borrowed from Mohsen Banan and D. Hugh Redelmeier.
  853.  */
  854.  
  855. /*
  856.  * The HDLC polynomial: x**0 + x**5 + x**12 + x**16 (0x8408).
  857.  */
  858. #define P       0x8408
  859.  
  860.  
  861. main()
  862. {
  863.     register unsigned int b, v;
  864.     register int i;
  865.  
  866.     printf("typedef unsigned short u16;0);
  867.     printf("static u16 fcstab[256] = {");
  868.     for (b = 0; ; ) {
  869.         if (b % 8 == 0)
  870.             printf("0);
  871.  
  872.         v = b;
  873.         for (i = 8; i--; )
  874.             v = v & 1 ? (v >> 1) ^ P : v >> 1;
  875.  
  876.         printf("0x%04x", v & 0xFFFF);
  877.         if (++b == 256)
  878.             break;
  879.         printf(",");
  880.     }
  881.     printf("0;0);
  882. }
  883.  
  884. Security Considerations
  885.  
  886.    As noted in the Physical Layer Requirements section, the link layer
  887.    might not be informed when the connected state of physical layer is
  888.    changed.  This results in possible security lapses due to over-
  889.    reliance on the integrity and security of switching systems and
  890.    administrations.  An insertion attack might be undetected.  An
  891.    attacker which is able to spoof the same calling identity might be
  892.    able to avoid link authentication.
  893.  
  894.  
  895.  
  896.  
  897.  
  898. Simpson                                                        [Page 16]
  899.  
  900. RFC 1549                      HDLC Framing                Decvember 1993
  901.  
  902.  
  903. References
  904.  
  905.    [1]  Simpson, W., Editor, "The Point-to-Point Protocol (PPP)",
  906.         RFC 1548, December 1993
  907.  
  908.    [2]  International Organization For Standardization, ISO Standard
  909.         3309-1979, "Data communication - High-level data link control
  910.         procedures - Frame structure", 1979.
  911.  
  912.    [3]  International Organization For Standardization, Proposed Draft
  913.         International Standard ISO 3309-1991/PDAD1, "Information
  914.         processing systems - Data communication - High-level data link
  915.         control procedures - Frame structure - Addendum 1: Start/stop
  916.         transmission", 1991.
  917.  
  918.    [4]  International Organization For Standardization, ISO Standard
  919.         4335-1979, "Data communication - High-level data link control
  920.         procedures - Elements of procedures", 1979.
  921.  
  922.    [5]  International Organization For Standardization, ISO Standard
  923.         4335-1979/Addendum 1, "Data communication - High-level data
  924.         link control procedures - Elements of procedures - Addendum 1",
  925.         1979.
  926.  
  927.    [6]  International Telecommunication Union, CCITT Recommendation
  928.         X.25, "Interface Between Data Terminal Equipment (DTE) and Data
  929.         Circuit Terminating Equipment (DCE) for Terminals Operating in
  930.         the Packet Mode on Public Data Networks", CCITT Red Book,
  931.         Volume VIII, Fascicle VIII.3, Rec. X.25., October 1984.
  932.  
  933.    [7]  International Telegraph and Telephone Consultative Committee,
  934.         CCITT Recommendation Q.922, "ISDN Data Link Layer Specification
  935.         for Frame Mode Bearer Services", April 1991.
  936.  
  937.    [8]  American National Standards Institute, ANSI X3.4-1977,
  938.         "American National Standard Code for Information Interchange",
  939.         1977.
  940.  
  941.    [9]  Perez, "Byte-wise CRC Calculations", IEEE Micro, June, 1983.
  942.  
  943.    [10] Morse, G., "Calculating CRC's by Bits and Bytes", Byte,
  944.         September 1986.
  945.  
  946.    [11] LeVan, J., "A Fast CRC", Byte, November 1987.
  947.  
  948. Acknowledgments
  949.  
  950.    This specification is based on previous RFCs, where many
  951.  
  952.  
  953.  
  954. Simpson                                                        [Page 17]
  955.  
  956. RFC 1549                      HDLC Framing                Decvember 1993
  957.  
  958.  
  959.    contributions have been acknowleged.
  960.  
  961.    Additional implementation detail for this version was provided by
  962.    Fred Baker (ACC), Craig Fox (NSC), and Phil Karn (Qualcomm).
  963.  
  964.    Special thanks to Morning Star Technologies for providing computing
  965.    resources and network access support for writing this specification.
  966.  
  967. Chair's Address
  968.  
  969.    The working group can be contacted via the current chair:
  970.  
  971.       Fred Baker
  972.       Advanced Computer Communications
  973.       315 Bollay Drive
  974.       Santa Barbara, California, 93111
  975.  
  976.       EMail: fbaker@acc.com
  977.  
  978. Editor's Address
  979.  
  980.    Questions about this memo can also be directed to:
  981.  
  982.       William Allen Simpson
  983.       Daydreamer
  984.       Computer Systems Consulting Services
  985.       1384 Fontaine
  986.       Madison Heights, Michigan  48071
  987.  
  988.       EMail: Bill.Simpson@um.cc.umich.edu
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002.  
  1003.  
  1004.  
  1005.  
  1006.  
  1007.  
  1008.  
  1009.  
  1010. Simpson                                                        [Page 18]
  1011.