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.
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 subheader format
// 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.
// 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:
| MAC CE | LCID | Size | Purpose |
|---|---|---|---|
| Timing Advance Command | 61 | 2 bytes | TA group + TA value — adjust UL timing |
| Contention Resolution ID | 62 | 6 bytes | Copy of Msg3 CCCH SDU — resolves RACH collision |
| Short BSR | 57 | 1 byte | Reports one LCG's buffer status |
| Long BSR | 58 | variable | Reports all LCGs' buffer status |
| Power Headroom Report | 60 | 1 byte | Reports UE's available power margin above current TX power |
| C-RNTI | 52 | 2 bytes | UE's C-RNTI — used when TC-RNTI active (Msg3) |
| DRX Command | 60 (DL) | 0 bytes | Network commands UE to enter DRX sleep immediately |