Tahoe

The HDLC protocol

Synchronous links allow bit streams to be transmitted. In computer networks, however, it is important to preserve the division of the stream into bytes, and also to preserve the division of the sequence of bytes into packets. A simple protocol such as HDLC makes it possible to preserve exactly this division.

The bit sequence 01111110 is used to mark the beginning and end of a data packet. It is a special marker (flag) which cannot appear inside a packet. Thanks to it, the receiver can be certain that the bits following it are, in turn, the first, second, etc. byte of the transmitted data.

A single HDLC flag may simultaneously be the end of one packet and the beginning of the next.

01111110
Fig. 1 HDLC packet start and end flag

Because the bit sequence 01111110 is reserved, the transmitted data must be modified accordingly so that it does not appear inside a packet and is not misinterpreted. Therefore, whenever 5 consecutive ones appear in the data stream, the transmitter inserts an additional zero after them. The receiver, in turn, after receiving 5 consecutive ones, skips the zero that follows them. In this way the transmitted bit sequence is reconstructed. This operation is called bit stuffing.

Additionally, to ensure the integrity of the transmitted data, a 16-bit CRC16 checksum is appended at the end of the packet.

The example below shows how the bit sequence changes when the HDLC protocol is applied.

Three-byte packet 0x15 0xff 0x3e:

00
010101
11111111
00111110

HDLC packet with flags and bit stuffing:
(darker fields - bits added by the HDLC protocol, c - bits of the CRC16 checksum)

011111100001010111110111100111110cccccccccccccccc01111110

Fig. 2 Three-byte packet (0x15 0xff 0x3e) before and after applying HDLC

If no data are to be sent over the transmission line, the transmitter should continuously send the sequence 01111110.

Sending a sequence of all ones is used to abort the transmission and to inform the other side that an error has occurred.