Protocol Stack

MAC Layer —
The scheduler's domain

The Medium Access Control layer is where resources meet data. MAC multiplexes logical channels, runs the HARQ processes, performs scheduling, and assembles the transport blocks that get encoded and transmitted. This section traces the complete MAC PDU structure and explains priority-based logical channel multiplexing.

TS 38.321 TS 38.300 §6.2

MAC position in the protocol stack

The protocol stack from application to air interface has four radio protocol layers. From top to bottom: PDCP → RLC → MAC → PHY. Each layer adds headers, performs error control, and handles a specific function. The MAC layer sits directly above the physical layer — it is the last stop before bits become radio waves.

The MAC layer provides services to the RLC layer in the form of logical channels. The MAC layer uses services from the physical layer in the form of transport channels. The MAC layer performs mapping between logical channels and transport channels, multiplexing/demultiplexing of MAC SDUs, scheduling information reporting, error correction through HARQ, and priority handling.
3GPP TS 38.321, Section 4.2
Mux
Multiplexing
Combines multiple logical channels into one transport block
HARQ
Retransmission
16 DL / 16 UL processes, soft combining
BSR
Buffer reports
Reports UL buffer status to gNB scheduler
CE
Control Elements
MAC CEs for TA, BSR, power headroom etc.

MAC PDU structure

A MAC PDU (the transport block handed to the PHY layer) is built from subheaders and payloads. Each subheader identifies what follows — either a MAC SDU (data from an RLC bearer) or a MAC Control Element (MAC-layer control information).

MAC PDU structure — subheaders and payloads TS 38.321 §6.1

MAC subheader format

A MAC subheader consists of the following fields: R (reserved, set to 0), F (format flag), LCID (Logical Channel ID), and L (length). The F bit indicates whether the L field is 8 bits (F=0) or 16 bits (F=1). The LCID identifies the logical channel or the type of control element.
3GPP TS 38.321, Section 6.1.2
MAC subheader — LCID values and their meaningsTS 38.321 §6.2.1
// LCID values for DL-SCH:
LCID 0:     CCCH      (SRB0 — pre-connection control)
LCID 1:     DCCH      (SRB1 — RRC signalling)
LCID 2:     DCCH       (SRB2 — NAS signalling)
LCID 3–10:  DTCH       (DRB1–DRB8 — user data)
LCID 60:    DAPS HO Command
LCID 61:    Timing Advance Command   ← MAC CE we received in Msg2
LCID 62:    Contention Resolution ID ← MAC CE in Msg4
LCID 63:    Padding

// LCID values for UL-SCH:
LCID 1:     DCCH (SRB1)
LCID 3–10:  DTCH (DRBs)
LCID 57:    Short BSR
LCID 58:    Long BSR
LCID 59:    Short Truncated BSR
LCID 60:    Power Headroom Report
LCID 63:    Padding

Logical channel prioritisation

When assembling a MAC PDU, the MAC entity must decide which logical channels get how many bytes. The algorithm is defined in TS 38.321 and ensures high-priority channels are always served before low-priority ones.

The MAC entity shall prioritize the logical channels in the following order: first, all logical channels with a configured prioritizedBitRate other than zero, ordered by priority; then, all other logical channels, ordered by priority. MAC CEs shall have higher priority than data from logical channels.
3GPP TS 38.321, Section 5.4.3.1
Logical channel prioritisation — our UE, 22 RBs UL grantTS 38.321 §5.4.3.1
// Available bytes in UL grant (22 RBs, MCS 16, 64-QAM):
TBS ≈ 12,032 bits = 1,504 bytes

// Logical channel priority order (RRC configured):
Priority 1: SRB1 (DCCH)      → pending: 0 bytes     → allocate: 0
Priority 2: Short BSR MAC CE → pending: 4 bytes     → allocate: 4  (MAC CE first)
Priority 3: DRB1 (DTCH)      → pending: 300,000 bytes → allocate: 1,496

// MAC PDU assembly:
[Subheader LCID=57 len=4] [Short BSR: LCG1=18] [Subheader LCID=3 len=1496 F=1] [DRB1 data: 1496 bytes]
Total PDU size = 1,504 bytes  (fits exactly in TBS)

MAC Control Elements (MAC CEs)

MAC CEs are control information generated and consumed by the MAC layer itself — they don't come from upper layers. The most important ones we have already seen:

Key MAC Control ElementsTS 38.321 §6.1.3
MAC CELCIDSizePurpose
Timing Advance Command612 bytesTA group + TA value — adjust UL timing
Contention Resolution ID626 bytesCopy of Msg3 CCCH SDU — resolves RACH collision
Short BSR571 byteReports one LCG's buffer status
Long BSR58variableReports all LCGs' buffer status
Power Headroom Report601 byteReports UE's available power margin above current TX power
C-RNTI522 bytesUE's C-RNTI — used when TC-RNTI active (Msg3)
DRX Command60 (DL)0 bytesNetwork commands UE to enter DRX sleep immediately
MAC layer summary
Core function      → mux logical channels into transport blocks
PDU structure     → subheaders + payloads + MAC CEs + padding
Priority order    → MAC CEs first, then by LCH priority and PBR
HARQ integration  → 16 DL + 16 UL processes, NDI toggle signals new vs retransmit