History
HDLC is based on IBM's SDLC protocol, which is the layer 2 protocol for IBM's Systems Network Architecture (SNA). It was extended and standardized by the ITU as LAP (Link Access Procedure), whileFraming
HDLCSynchronous framing
Because a flag sequence consists of six consecutive 1-bits, other data is coded to ensure that it never contains more than five 1-bits in a row. This is done by bit stuffing: any time that five consecutive 1-bits appear in the transmitted data, the data is paused and a 0-bit is transmitted. The receiving device knows that this is being done, and after seeing five 1-bits in a row, a following 0-bit is stripped out of the received data. If instead the sixth bit is 1, this is either a flag (if the seventh bit is 0), or an error (if the seventh bit is 1). In the latter case, the frame receive procedure is aborted, to be restarted when a flag is next seen. This bit-stuffing serves a second purpose, that of ensuring a sufficient number of signal transitions. On synchronous links, the data is NRZI encoded, so that a 0-bit is transmitted as a change in the signal on the line, and a 1-bit is sent as no change. Thus, each 0 bit provides an opportunity for a receivingAsynchronous framing
When using asynchronous serial communication such as standardStructure
The contents of an HDLC frame are shown in the following table: Note that the end flag of one frame may be (but does not have to be) the beginning (start) flag of the next frame. Data is usually sent in multiples of 8 bits, but only some variants require this; others theoretically permit data alignments on other than 8-bit boundaries. The frame check sequence (FCS) is a 16-bitTypes of stations (computers) and data transfer modes
Synchronous Data Link Control ( SDLC) was originally designed to connect one computer with multiple peripherals via a multidrop bus. The original "normal response mode" is a master-slave mode where the computer (or primary terminal) gives each peripheral (secondary terminal) permission to speak in turn. Because all communication is either to or from the primary terminal, frames include only one address, that of the secondary terminal; the primary terminal is not assigned an address. There is a distinction between commands sent by the primary to a secondary, and responses sent by a secondary to the primary, but this is not reflected in the encoding; commands and responses are indistinguishable except for the difference in the direction in which they are transmitted. Normal response mode allows the secondary-to-primary link to be shared without contention, because it has the primary give the secondaries permission to transmit one at a time. It also allows operation overHDLC operations and frame types
Three fundamental types of HDLC frames may be distinguished: * Information frames, or I-frames, transport user data from the network layer. They can also include flow and error control information piggybacked on data. * Supervisory frames, or S-frames, are used for flow and error control whenever piggybacking is impossible or inappropriate, such as when a station does not have data to send. S-frames do not have information fields. * Unnumbered frames, or U-frames, are used for various miscellaneous purposes, including link management. Some U-frames contain an information field, depending on the type.Control field
The general format of the control field is: There are also extended (two-byte) forms of I and S frames. Again, the least significant bit (rightmost in this table) is sent first.P/F bit
Poll/Final is a single bit with two names. It is called Poll when part of a command (set by the primary station to obtain a response from a secondary station), and Final when part of a response (set by the secondary station to indicate a response or the end of transmission). In all other cases, the bit is clear. The bit is used as aN(R), the receive sequence number
Both I and S frames contain a receive sequence number N(R). N(R) provides a positive acknowledgement for the receipt of I-frames from the other side of the link. Its value is always the first frame not yet received; it acknowledges that all frames with N(S) values up to N(R)−1 (modulo 8 or modulo 128) have been received and indicates the N(S) of the next frame it expects to receive. N(R) operates the same way whether it is part of a command or response. A combined station only has one sequence number space.N(S), the sequence number of the sent frame
This is incremented for successive I-frames, modulo 8 or modulo 128. Depending on the number of bits in the sequence number, up to 7 or 127 I-frames may be awaiting acknowledgment at any time.I-Frames (user data)
Information frames, or I-frames, transport user data from the network layer. In addition they also include flow and error control information piggybacked on data. The sub-fields in the control field define these functions. The least significant bit (first transmitted) defines the frame type. 0 means an I-frame. Except for the interpretation of the P/F field, there is no difference between a command I frame and a response I frame; when P/F is 0, the two forms are exactly equivalent.S-frames (control)
Supervisory Frames, or 'S-frames', are used for flow and error control whenever piggybacking is impossible or inappropriate, such as when a station does not have data to send. S-frames in HDLC do not have information fields, although some HDLC-derived protocols use information fields for "multi-selective reject". The S-frame control field includes a leading "10" indicating that it is an S-frame. This is followed by a 2-bit type, a poll/final bit, and a 3-bit sequence number. (Or a 4-bit padding field followed by a 7-bit sequence number.) The first (least significant) 2 bits mean it is an S-frame. All S frames include a P/F bit and a receive sequence number as described above. Except for the interpretation of the P/F field, there is no difference between a command S frame and a response S frame; when P/F is 0, the two forms are exactly equivalent.Receive Ready (RR)
* Bit value = 00 (0x00 to match above table type field bit order) * Indicate that the sender is ready to receive more data (cancels the effect of a previous RNR). * Send this packet if you need to send a packet but have no I frame to send. * A primary station can send this with the P-bit set to solicit data from a secondary station. * A secondary terminal can use this with the F-bit set to respond to a poll if it has no data to send.Receive Not Ready (RNR)
* Bit value = 01 (0x04 to match above table type field bit order) * Acknowledge some packets but request no more be sent until further notice. * Can be used like RR with P bit set to solicit the status of a secondary station * Can be used like RR with F bit set to respond to a poll if the station is busy.Reject (REJ)
* Bit value = 10 (0x08 to match above table type field bit order) * Requests immediate retransmission starting with N(R). * Sent in response to an observed sequence number gap; e.g. after seeing I1/I2/I3/I5, send REJ4. * Optional to generate; a working implementation may use only RR.Selective Reject (SREJ)
* Bit value = 11 (0x0c to match above table type field bit order) * Requests retransmission of only the frame N(R). * Not supported by all HDLC variants. * Optional to generate; a working implementation may use only RR, or only RR and REJ.U-Frames
Unnumbered frames, or U-frames, are primarily used for link management, although a few are used to transfer user data. They exchange session management and control information between connected devices, and some U-frames contain an information field, used for system management information or user data. The first 2 bits (11) mean it is a U-frame. The five type bits (2 before P/F bit and 3 bit after P/F bit) can create 32 different types of U-frame. In a few cases, the same encoding is used for different things as a command and a response.Mode setting
The various modes are described in . Briefly, there are two non-operational modes (initialization mode and disconnected mode) and three operational modes (normal response, asynchronous response, and asynchronous balanced modes) with 3-bit or 7-bit (extended) sequence numbers. ; Disconnected mode (DM) response : When the secondary is disconnected (the default state on power-up), it sends this generic response to any poll (command frame with the poll flag set) except an acceptable mode setting command. It may alternatively give a FRMR response to an unacceptable mode set command. ; Unnumbered acknowledge (UA) response : This is the secondary's response to an acceptable mode set command, indicating that it is now in the requested mode. ; Set ... mode (SNRM, SARM, SABM) command : Place the secondary in the specified mode, with 3-bit sequence numbers (1-byte control field). The secondary acknowledges with UA. If the secondary does not implement the mode, it responds with DM or FRMR. ; Set ... mode extended (SNRME, SARME, SABME) command : Place the secondary in the specified mode, with 7-bit sequence numbers (2-byte control field). ; Set mode (SM) command : Generic mode set, new in ISO/IEC 13239, using an information field to select parameters. ISO/IEC 13239 added many additional options to HDLC, including 15- and 31-bit sequence numbers, which can only be selected with this command. ; Disconnect (DISC) command : This command causes the secondary to acknowledge with UA and disconnect (enter disconnected mode). Any unacknowledged frames are lost. ; Request disconnect (RD) response : This response requests the primary to send a DISC command. The primary should do so promptly, but may delay long enough to ensure all pending frames are acknowledged. ; Set initialization mode (SIM) command : This rarely-implemented command is used to perform some secondary-specific initialization, such as downloadingInformation transfer
These frames may be used as part of normal information transfer. ; Unnumbered information (UI) : This frame (command or response) communicates user data, but without acknowledgement or retransmission in case of error. ; UI with header check (UIH) : This frame (command or response), a ISO/IEC 13239 addition and rarely used, is like UI but also excludes CRC protection. Only a configurable-length prefix ("header") of the frame is covered by the CRC polynomial; errors in the rest of the frame are not detected. ; Unnumbered poll (UP) command : This command solicits a response from the secondary. With the poll bit set, it acts like any other poll frame, without the acknowledgement that must be included in I or S frame. With the poll bit clear, it has a special meaning in normal response mode: the secondary ''may'' respond, even though it has not received the poll bit. This is rarely used in HDLC, but was used in the original IBM SDLC as a substitute for the lack of asynchronous response mode; where the communication channel could handle simultaneous responses, the primary would periodically send UP to the broadcast address to collect any pending responses.Error Recovery
; Frame reject (FRMR) response : The FRMR response contains a description of the unacceptable frame, in a standardized format. The first 1 or 2 bytes are a copy of the rejected control field, the next 1 or 2 contain the secondary's current send and receive sequence numbers (and a flag indicating that the frame was a response, applicable only in balanced mode), and the following 4 or 5 bits are error flags indicating the reason for the rejection. The secondary repeats the same FRMR response to every poll until the error is cleared by a mode set command or RSET. The error flags are: :* W: the frame type (control field) is not understood or not implemented. :* X: the frame type is not understood with a non-empty information field, but one was present. :* Y: the frame included an information field that is larger than the secondary can accept. :* Z: the frame included an invalid receive sequence number N(R), one which is not between the previously received value and the highest sequence number transmitted. (This error cannot be cleared by receiving RSET, but can be cleared by ''sending'' RSET.) :* V: the frame included an invalid send sequence number N(S), greater than the last number acknowledged plus the transmit window size. This error is only possible if a transmit window size smaller than the maximum has been negotiated. :* The error flags are normally padded with 0 bits to an 8-bit boundary, but HDLC permits frames which are not a multiple of a byte long. ; Reset (RSET) command : The RSET command causes a secondary to reset its receive sequence number so the next expected frame is sequence number 0. This is a possible alternative to sending a new mode set command, which resets both sequence numbers. It is acknowledged with UA, like a mode set command.Peer discovery
; Exchange identification (XID) : An XID command includes an information field specifying the primary's capabilities; the secondary responds with an XID response specifying its capabilities. This is normally done before sending a mode set command. Systems Network Architecture defined one format for the information field, in which the most significant bit of the first byte is clear (0), but HDLC implementations normally implement the variant defined in ISO 8885, which has the most significant bit of the first byte set (1). ; TEST : A TEST command is simply a ping command for debugging purposes. The payload of the TEST command is returned in the TEST response.Defined in other standards
There are several U frames which are not part of HDLC, but defined in other related standards. ; Nonreserved (NR0, NR1, NR2, NR3) : The "nonreserved" commands and responses are guaranteed by the HDLC standard to be available for other uses. ; Ack connectionless (AC0, AC1) : These are defined in the IEEE 802.2 logical link control standard. ; Configure (CFGR) : This command was defined in SDLC for debugging. It had a 1-byte payload which specified a non-standard test mode for the secondary. Even numbers disabled the mode, while odd numbers enabled it. A payload of 0 disabled all test modes. The secondary normally acknowledged a configure command by echoing it in response. ; Beacon (BCN) response : This response was defined in SDLC to indicate a communications failure. A secondary which received no frames at all for a long time would begin sending a stream of beacon responses, allowing a unidirectional fault to be located. Note that ISO/IEC 13239 assigns UIH the same encoding as BCN.Link configurations
Link configurations can be categorized as being either: *''Unbalanced'', which consists of one primary terminal, and one or more secondary terminals. *''Balanced'', which consists of two peer terminals. The three link configurations are: *''Normal Response Mode'' (NRM) is an unbalanced configuration in which only the primary terminal may initiate data transfer. The secondary terminals transmit data only in response to commands from the primary terminal. The primary terminal polls each secondary terminal to give it an opportunity to transmit any data it has. *''Asynchronous Response Mode'' (ARM) is an unbalanced configuration in which secondary terminals may transmit without permission from the primary terminal. However, there is still a distinguished primary terminal which retains responsibility for line initialization, error recovery, and logical disconnect. *''Asynchronous Balanced Mode'' (ABM) is a balanced configuration in which either station may initialize, supervise, recover from errors, and send frames at any time. There is no master/slave relationship. The DTE (HDLC Command and response repertoire
The minimal set required for operation are: *Commands: I, RR, RNR, DISC, and one of SNRM, SARM or SABM *Responses: I, RR, RNR, UA, DM, FRMRBasic operations
*Initialization can be requested by either side. When the primary sends one of the six mode-set commands, it: **Signals the other side that initialization is requested **Specifies the mode, NRM, ABM, ARM **Specifies whether 3 or 7 bit sequence numbers are in use. The HDLC module on the other end transmits (UA) frame when the request is accepted. If the request is rejected it sends (DM) disconnect mode frame.Functional extensions (options)
*For Switched Circuits **Commands: ADD – XID **Responses: ADD – XID, RD *For 2-way Simultaneous commands & responses are ADD – REJ *For Single Frame Retransmission commands & responses: ADD – SREJ *For Information Commands & Responses: ADD – Ul *For Initialization **Commands: ADD – SIM **Responses: ADD – RIM *For Group Polling **Commands: ADD – UP *Extended Addressing *Delete Response I Frames *Delete Command I Frames *Extended Numbering *For Mode Reset (ABM only) Commands are: ADD – RSET *Data Link Test Commands & Responses are: ADD – TEST *Request Disconnect. Responses are ADD – RD *32-bit FCSHDLC command and response repertoire
Unnumbered frames
Unnumbered frames are identified by the low two bits being 1. With the P/F flag, that leaves 5 bits as a frame type. Even though fewer than 32 values are in use, some types have different meanings depending on the direction they are sent: as a command or as a response. The relationship between the DISC (disconnect) command and the RD (request disconnect) response seems clear enough, but the reason for making SARM command numerically equal to the DM response is obscure. : * ISO/IEC 13239 addition : † Not part of HDLC The UI, UIH, XID, TEST frames contain a payload, and can be used as both commands and responses. The SM command and FRMR response also contain a payload. * A UI frame contains user information, but unlike an I frame it is neither acknowledged nor retransmitted if lost. * A UIH frame (an ISO/IEC 13239 addition) is like a UI frame, but additionally applies the frame check sequence only to a specified-length prefix of the frame; transmission errors after this prefix are not detected. * The XID frame is used to exchange terminal capabilities. Systems Network Architecture defined one format, but the variant defined in ISO 8885 is more commonly used. A primary advertises its capabilities with an XID command, and a secondary returns its own capabilities in an XID response. * The TEST frame is simply a ping command for debugging purposes. The payload of the TEST command is returned in the TEST response. * The SM command (an ISO/IEC 13239 addition) is a generic "set mode" command which includes an information field (in the same ISO 8885 format as XID) specifying parameters. This allows parameter values (like 15- and 31-bit sequence numbers) and parameters like window sizes and maximum frame sizes not expressible by the standard six mode-set commands to be negotiated. * The FRMR response contains a description of the unacceptable frame, in a standardized format. The first 1 or 2 bytes are a copy of the rejected control field, the next 1 or 2 contain the secondary's current send and receive sequence numbers, and the following 4 or 5 bits are error flags indicating the reason for the rejection.See also
* Point-to-Point Protocol *Notes
References
* * *External links
* *