Protocol Layers — State Machines and Error Handling
Overview
Communication protocols rely on well‑defined state machines to coordinate transmission, reception, retries, synchronization, and error handling. A protocol FSM is not just a sequence of states: it is a control mechanism that ensures consistency, forward progress, and recovery in the presence of faults.
This page introduces typical protocol state machines, common failure modes, and the mechanisms used to detect and recover from errors.
Protocol State Machine Fundamentals
A protocol FSM manages:
- transmission startup
- acknowledgment handling
- timeout supervision
- retry logic
- transaction completion
- recovery from illegal or unexpected conditions
Typical states include:
- IDLE — no active transaction
- SEND — frame transmission
- WAIT_ACK — waiting for acknowledgment
- RETRY — retransmission after timeout
- ERROR / RECOVERY — handling faults or illegal conditions
- COMPLETE — transaction successfully finished
State Transitions
Transitions are triggered by:
- events (frame received, ACK, interrupt)
- conditions (valid CRC, correct sequence number)
- timers (timeout expiration)
- errors (unexpected frame, illegal state)
A robust FSM must guarantee:
- deterministic transitions
- no unintended loops
- explicit handling of terminal states
- recovery paths for undefined or illegal conditions
Failure Modes
Protocol FSMs can fail in several ways:
1. Illegal Transitions
Transitions not defined by the protocol specification, often caused by:
- SEUs
- logic glitches
- corrupted state registers
2. Stuck States
The FSM remains trapped in a state with no valid outgoing transitions.
3. Lost Events
An expected event (ACK, frame, interrupt) is not detected.
4. Unexpected Events
Frames or signals arrive in a state where they are not valid.
5. Timer Failures
Timeouts not detected or timer corruption leading to incorrect behavior.
Error Handling Mechanisms
Protocols implement several mechanisms to handle errors:
1. Timeout Supervision
If the ACK does not arrive within the expected window:
- a retry is triggered
- or the FSM enters an error state
2. Retry Logic
Controlled retransmission of the frame:
- retry counters
- exponential backoff
- fallback to safe modes
3. Illegal State Detection
The FSM detects an invalid state and:
- enters a SAFE RECOVERY STATE
- resets the transaction
- returns to IDLE
4. Unexpected Frame Handling
Out‑of‑sequence or invalid frames are:
- discarded
- logged
- used to trigger recovery
5. Sequence Counter Validation
Sequence numbers are checked to:
- detect duplicates
- detect missing frames
- prevent replay
Safety Considerations
Protocol FSMs are safety‑critical because:
- illegal transitions can lead to nondeterministic behavior
- infinite retry loops can stall communication
- undetected timeouts can cause deadlock
- corrupted states can break synchronization
Safety‑critical systems adopt:
- safe state encoding
- redundant state registers
- illegal state detection logic
- watchdog supervision
- mandatory recovery paths
Related Technical Pages
Protocol Layer Fundamentals
- Protocol Layering — Architecture Fundamentals
- Protocol Layers & Packet Processing — Overview & Families