Skip to content

Protocol Documentation

whisprer edited this page Nov 18, 2025 · 1 revision

Protocol Documentation

This document provides detailed information about the IEEE 802.15.4 and Zigbee protocol layers that Zigbee Analyzer parses and analyzes.

Protocol Stack Overview

┌─────────────────────────────────┐
│   Application Layer (User Code) │
├─────────────────────────────────┤
│   Zigbee Cluster Library (ZCL)  │  ← Commands, attributes
├─────────────────────────────────┤
│   Application Support (APS)      │  ← Profiles, clusters
├─────────────────────────────────┤
│   Network Layer (NWK)            │  ← Routing, addressing
├─────────────────────────────────┤
│   IEEE 802.15.4 MAC Layer        │  ← Frames, addressing
├─────────────────────────────────┤
│   PHY Layer (2.4 GHz)            │  ← Radio, channels
└─────────────────────────────────┘

IEEE 802.15.4 MAC Layer

The foundation of all Zigbee communication.

Frame Structure

┌────────┬──────────┬─────────┬─────────┬─────────┬─────────┬─────────┐
│ Frame  │ Sequence │ Dest    │ Dest    │ Source  │ Source  │ Payload │
│ Control│  Number  │  PAN ID │ Address │ PAN ID  │ Address │         │
├────────┼──────────┼─────────┼─────────┼─────────┼─────────┼─────────┤
│ 2 bytes│  1 byte  │ 0-2 B   │ 0-8 B   │ 0-2 B   │ 0-8 B   │ ≤102 B  │
└────────┴──────────┴─────────┴─────────┴─────────┴─────────┴─────────┘
                                                                │
                                                                v
                                                            ┌────────┐
                                                            │  FCS   │
                                                            │ 2 bytes│
                                                            └────────┘

Frame Control Field

pub struct FrameControl {
    pub frame_type: FrameType,        // Bits 0-2
    pub security_enabled: bool,       // Bit 3
    pub frame_pending: bool,          // Bit 4
    pub ack_request: bool,            // Bit 5
    pub pan_id_compression: bool,     // Bit 6
    pub reserved: bool,               // Bit 7
    pub sequence_suppression: bool,   // Bit 8
    pub ie_present: bool,             // Bit 9
    pub dest_addr_mode: AddressMode,  // Bits 10-11
    pub frame_version: u8,            // Bits 12-13
    pub src_addr_mode: AddressMode,   // Bits 14-15
}

Frame Types:

0x00 = Beacon
0x01 = Data
0x02 = Acknowledgment
0x03 = MAC Command

Address Modes:

0x00 = No address (PAN coordinator)
0x01 = Reserved
0x02 = Short address (16-bit)
0x03 = Extended address (64-bit IEEE EUI-64)

Example: Data Frame

Hex dump:

41 88 01 CD AB 34 12 00 00 78 56 00 00 11 22 [payload...] [FCS]

Parsed:

Frame Control: 0x8841
  Type: Data (0x01)
  Security: No
  ACK Request: Yes
  Dest Addr Mode: Short (0x02)
  Src Addr Mode: Short (0x02)

Sequence: 0x01
Dest PAN: 0xABCD
Dest Addr: 0x1234
Src PAN: 0xABCD (compressed)
Src Addr: 0x5678

Addressing

PAN ID (Personal Area Network Identifier):

  • 16-bit value
  • Identifies the network
  • Broadcast: 0xFFFF

Short Address:

  • 16-bit
  • Assigned by coordinator
  • Broadcast: 0xFFFF
  • Coordinator: 0x0000

Extended Address (IEEE Address):

  • 64-bit globally unique
  • Factory-assigned
  • Format: AA:BB:CC:DD:EE:FF:00:11

MAC Commands

pub enum MacCommand {
    AssociationRequest,       // 0x01
    AssociationResponse,      // 0x02
    DisassociationNotice,     // 0x03
    DataRequest,              // 0x04
    PANIDConflictNotice,      // 0x05
    OrphanNotification,       // 0x06
    BeaconRequest,            // 0x07
    CoordinatorRealignment,   // 0x08
    GTSRequest,               // 0x09
}

Zigbee Network Layer (NWK)

Handles routing and network management.

Frame Structure

┌─────────┬─────────┬─────────┬────────┬──────────┬─────────┐
│ Frame   │  Dest   │  Source │ Radius │ Sequence │ Payload │
│ Control │ Address │ Address │        │  Number  │         │
├─────────┼─────────┼─────────┼────────┼──────────┼─────────┤
│ 2 bytes │ 2 bytes │ 2 bytes │ 1 byte │  1 byte  │ ≤82 B   │
└─────────┴─────────┴─────────┴────────┴──────────┴─────────┘

Frame Control

pub struct NwkFrameControl {
    pub frame_type: NwkFrameType,           // Bits 0-1
    pub protocol_version: u8,               // Bits 2-5
    pub discover_route: DiscoverRoute,      // Bits 6-7
    pub multicast: bool,                    // Bit 8
    pub security: bool,                     // Bit 9
    pub source_route: bool,                 // Bit 10
    pub dest_ieee_present: bool,            // Bit 11
    pub src_ieee_present: bool,             // Bit 12
    pub end_device_initiator: bool,         // Bit 13
    pub reserved: u8,                       // Bits 14-15
}

Frame Types:

0x00 = Data
0x01 = Command
0x02 = Reserved
0x03 = Inter-PAN

Network Addresses

Addressing Scheme:

  • 16-bit short addresses
  • Hierarchical allocation
  • Address space divided by depth

Special Addresses:

0x0000 = Coordinator
0xFFFF = Broadcast (all devices)
0xFFFD = Broadcast (all routers and coordinator)
0xFFFC = Broadcast (low power routers only)

Routing

Route Discovery:

[Device A] ──RREQ──> [Router 1] ──RREQ──> [Router 2] ──RREQ──> [Device B]
           <──RREP── [Router 1] <──RREP── [Router 2] <──RREP──

Route Request (RREQ):

  • Broadcasts to find path
  • Includes path cost
  • Creates reverse route

Route Reply (RREP):

  • Unicast back to source
  • Establishes forward route

Network Commands

pub enum NwkCommand {
    RouteRequest,           // 0x01
    RouteReply,             // 0x02
    NetworkStatus,          // 0x03
    Leave,                  // 0x04
    RouteRecord,            // 0x05
    RejoinRequest,          // 0x06
    RejoinResponse,         // 0x07
    LinkStatus,             // 0x08
    NetworkReport,          // 0x09
    NetworkUpdate,          // 0x0A
    EndDeviceTimeout,       // 0x0B
}

Application Support Sublayer (APS)

Provides endpoint addressing and reliable delivery.

Frame Structure

┌─────────┬─────────┬─────────┬─────────┬───────────┬─────────┐
│ Frame   │  Dest   │ Source  │ Cluster │   Profile │ Payload │
│ Control │Endpoint │Endpoint │   ID    │     ID    │         │
├─────────┼─────────┼─────────┼─────────┼───────────┼─────────┤
│ 1 byte  │ 1 byte  │ 1 byte  │ 2 bytes │  2 bytes  │ ≤72 B   │
└─────────┴─────────┴─────────┴─────────┴───────────┴─────────┘

Frame Control

pub struct ApsFrameControl {
    pub frame_type: ApsFrameType,      // Bits 0-1
    pub delivery_mode: DeliveryMode,   // Bits 2-3
    pub ack_format: bool,              // Bit 4
    pub security: bool,                // Bit 5
    pub ack_request: bool,             // Bit 6
    pub extended_header: bool,         // Bit 7
}

Frame Types:

0x00 = Data
0x01 = Command
0x02 = Acknowledgment
0x03 = Inter-PAN

Endpoints

Endpoint Concept:

  • Like "ports" in TCP/IP
  • Range: 1-240 (0 = ZDO, 241-255 = reserved)
  • Each endpoint runs an application

Well-Known Endpoints:

0x00 = ZDO (Zigbee Device Object)
0xFF = Broadcast endpoint

Profiles

Profile ID defines application domain:

0x0104 = Home Automation (HA)
0x0109 = Smart Energy (SE)
0x0107 = Telecom Applications
0xC05E = Light Link (ZLL)
0x0000 = ZDP (Zigbee Device Profile)

Clusters

Cluster ID defines function within profile:

Home Automation Examples:

0x0000 = Basic
0x0003 = Identify
0x0004 = Groups
0x0005 = Scenes
0x0006 = On/Off
0x0008 = Level Control
0x0300 = Color Control
0x0402 = Temperature Measurement
0x0405 = Relative Humidity Measurement
0x0702 = Metering

Zigbee Cluster Library (ZCL)

Standardized commands and attributes.

Frame Structure

┌─────────┬──────────┬─────────┬─────────┬─────────┐
│ Frame   │Manufac-  │ Trans-  │ Command │ Payload │
│ Control │turer Code│action ID│   ID    │         │
├─────────┼──────────┼─────────┼─────────┼─────────┤
│ 1 byte  │ 0-2 bytes│  1 byte │ 1 byte  │ ≤68 B   │
└─────────┴──────────┴─────────┴─────────┴─────────┘

Frame Types

pub enum ZclFrameType {
    GlobalCommand,      // 0x00
    ClusterCommand,     // 0x01
}

Global Commands

Commands that work across all clusters:

pub enum ZclGlobalCommand {
    ReadAttributes,             // 0x00
    ReadAttributesResponse,     // 0x01
    WriteAttributes,            // 0x02
    WriteAttributesUndivided,   // 0x03
    WriteAttributesResponse,    // 0x04
    WriteAttributesNoResponse,  // 0x05
    ConfigureReporting,         // 0x06
    ConfigureReportingResponse, // 0x07
    ReadReportingConfig,        // 0x08
    ReadReportingConfigResp,    // 0x09
    ReportAttributes,           // 0x0A
    DefaultResponse,            // 0x0B
    DiscoverAttributes,         // 0x0C
    DiscoverAttributesResp,     // 0x0D
}

Example: Read Attributes

Request to read the "OnOff" attribute (0x0000) from cluster 0x0006:

ZCL Frame Control: 0x00 (Global, Client to Server)
Transaction Sequence: 0x01
Command ID: 0x00 (Read Attributes)
Attribute ID: 0x00 0x00

Response:

ZCL Frame Control: 0x18 (Global, Server to Client, Disable Default Response)
Transaction Sequence: 0x01
Command ID: 0x01 (Read Attributes Response)
Attribute ID: 0x00 0x00
Status: 0x00 (Success)
Data Type: 0x10 (Boolean)
Value: 0x01 (On)

Data Types

0x00 = No data
0x10 = Boolean
0x18 = 8-bit bitmap
0x20 = Unsigned 8-bit integer
0x21 = Unsigned 16-bit integer
0x28 = Signed 8-bit integer
0x29 = Signed 16-bit integer
0x30 = 8-bit enumeration
0x42 = Character string

Security

Security Levels

0 = None (no encryption)
5 = Encryption + 32-bit MIC
6 = Encryption + 64-bit MIC
7 = Encryption + 128-bit MIC

Key Types

Network Key:

  • 128-bit AES key
  • Shared by all devices
  • Used for network-level encryption

Link Key:

  • 128-bit AES key
  • Unique per device pair
  • Higher security for sensitive commands

Trust Center Link Key:

  • Special link key with coordinator
  • Used during joining

AES-CCM* Encryption

Zigbee uses AES-CCM* (Counter with CBC-MAC):

Nonce Structure (13 bytes):

┌─────────────┬─────────┬─────────┬─────────┐
│   Source    │  Frame  │ Security│  Block  │
│   Address   │ Counter │  Level  │ Counter │
│   (8 bytes) │(4 bytes)│ (1 byte)│(variable)│
└─────────────┴─────────┴─────────┴─────────┘

Security Frame Format

┌─────────┬─────────┬─────────┬─────────┬─────────┐
│ Security│  Frame  │  Source │Encrypted│   MIC   │
│ Control │ Counter │ Address │ Payload │         │
├─────────┼─────────┼─────────┼─────────┼─────────┤
│ 1 byte  │ 4 bytes │ 8 bytes │ n bytes │ 4-16 B  │
└─────────┴─────────┴─────────┴─────────┴─────────┘

Channel and Frequency

2.4 GHz ISM Band

Channel | Center Freq | Band
--------|-------------|-------
  11    | 2405 MHz    | 802.15.4
  12    | 2410 MHz    | 
  13    | 2415 MHz    |
  14    | 2420 MHz    |
  15    | 2425 MHz    | WiFi Ch 1 overlap
  16    | 2430 MHz    |
  17    | 2435 MHz    |
  18    | 2440 MHz    |
  19    | 2445 MHz    |
  20    | 2450 MHz    | WiFi Ch 6 overlap
  21    | 2455 MHz    |
  22    | 2460 MHz    |
  23    | 2465 MHz    |
  24    | 2470 MHz    |
  25    | 2475 MHz    | WiFi Ch 11 overlap
  26    | 2480 MHz    |

Channel Spacing: 5 MHz Bandwidth: 2 MHz

Channel Selection

Avoiding WiFi Interference:

  • WiFi Ch 1 (2412 MHz) → Use Zigbee Ch 11, 12, 13, or 14
  • WiFi Ch 6 (2437 MHz) → Use Zigbee Ch 15, 16, 17, or 18
  • WiFi Ch 11 (2462 MHz) → Use Zigbee Ch 24, 25, or 26

Recommended:

  • Ch 11: Minimal WiFi overlap
  • Ch 15: Between WiFi 1 and 6
  • Ch 20: Between WiFi 6 and 11
  • Ch 25: Minimal WiFi overlap

Packet Examples

Example 1: Beacon Frame

Raw: 00 80 01 CD AB 34 12 00 00 FF FF 00 00 00 00 00 00 00 00 00 00 [FCS]

Analysis:
- Frame Type: Beacon (0x00)
- PAN ID: 0xABCD
- Source: 0x1234 (Coordinator)
- Payload: Superframe specification, GTS, pending addresses

Example 2: Data Packet (On/Off Command)

MAC: 41 88 02 CD AB 34 12 00 00 78 56 00 00
NWK: 01 00 34 12 78 56 1E 10
APS: 00 01 01 06 00 00 00
ZCL: 01 20 01 00

Interpretation:
- Dest: 0x1234 (endpoint 1)
- Src: 0x5678 (endpoint 1)
- Cluster: 0x0006 (On/Off)
- Command: Toggle (0x02)

Example 3: Route Request

MAC: 61 88 03 CD AB FF FF 00 00 34 12 00 00
NWK: 01 02 78 56 34 12 1E 11 [RREQ payload]

Interpretation:
- Broadcast (0xFFFF)
- From: 0x1234
- Seeking route to: 0x5678
- Path cost: 0

Wireshark Integration

Display Filters

# All Zigbee
zbee_nwk

# Specific device
zbee_nwk.src == 0x1234

# Specific cluster
zbee_zcl.cluster == 0x0006

# Commands only
zbee_aps.cmd

# Encrypted
zbee_nwk.sec

Decryption in Wireshark

  1. Edit → Preferences → Protocols → Zigbee
  2. Add network key (16 bytes hex)
  3. Set "Security Level" if needed

References

Standards:

Tools:

Books:

  • "Zigbee Wireless Networks and Transceivers" by Shahin Farahani
  • "Hacking Exposed: Wireless" (Zigbee chapter)

See Also:

Clone this wiki locally