Once an HDLC link has been started, bits are transmitted continuously, even when the link is idle, in which case the flag sequence – 01111110 (or 0x7E) is transmitted. Frames are transmitted within the gaps between flags, so the receiver can determine when a frame starts and stops by synchronising with the flags.
To ensure transparency, a 0 bit is inserted by the transmitter after 5 continuous 1s within the frame contents, and removed by the receiver whenever it detects 5 continuous 1s followed by a 0. This prevents data within the frame being confused with the flags, and is known as “bit-stuffing”.
Normal frames are terminated with a flag – any frame which terminates with 7 1s or more is assumed to be aborted, and discarded. The transmitter can deliberately abort a frame if it chooses – this can sometimes happen if frames need to be retransmitted, and the transmitter knows that the frame currently being sent will be discarded by the receiver.
Only a single flag is necessary between frames – the ending flag of one frame can be the starting flag of the next. The flag is therefore not actually part of the HDLC frame itself.
HDLC Frame Structure
The HDLC Frame (before transmission – i.e. before bit-stuffing and wrapping with flags) consists of the following fields:
|Address field||Control field||Information field||Frame Check Sequence|
The frame is transmitted with the lowest order bit of each byte first – and indeed the frame structure within the X.25 specification shows the field encodings such that the lowest order bit is on the left, which can be rather confusing to those used to normal computing notation. Since all the fields are in reality byte-aligned, this guide uses standard ordering of each byte – for example, the LAPB Address fields are described as 0x03 and 0x01.
The Address field in theory can be number of bytes; if the byte value is even, that means that another address byte follows.
The Address field for LAPB is always a single byte, and takes the value 0x01 or 0x03, as follows:
|0x03||Command frames DCE to DTE|
|Response frames DTE to DCE|
|0x01||Command frames DTE to DCE|
|Response Frames DCE to DTE|
Note that the different address field values mean that a LAPB link is not symmetrical – one end must be a DTE and one a DCE, and thus the link will not work if misconfigured. To get round this, the FarSync X.25 software employs rather clever algorithm which causes one end of the link to reconfigure itself if it encounters the situation in which both ends of the link are configured in the same way, but this only happens if Auto Link Role is enabled.
The Control Field is usually 1 byte, but can be 2 bytes long for LAPB. This depends on the frame type, and whether normal (modulo-8) or extended (modulo-128) sequence numbers are used. Modulo-8 sequence numbers are used most of the time, in which case the Control Field is always 1 byte.
The Information Field contains the higher layer data being carried by the Link Layer – for X.25, this is typically the X.25 Packet.
Frame Check Sequence (CRC)
The Frame Check Sequence is 16-bits long for LAPB (a 32-bit FCS is possible for other types of HDLC). It contains a Cyclic Redundancy Check sequence, and thus is often referred to as the CRC instead of the FCS.
The FCS is generated when a frame is transmitted (before any bit-stuffing) and is checked when a frame is received. If one or more bits have been modified during transmission by a line error, then the CRC check should fail, in which case the entire frame is discarded.