Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

PIB Attributes Reference

The PAN Information Base (PIB) is the MAC-layer configuration interface defined by IEEE 802.15.4. The zigbee-mac crate exposes PIB attributes through the MacDriver trait’s mlme_get() and mlme_set() methods.

#![allow(unused)]
fn main() {
use zigbee_mac::{PibAttribute, PibValue, MacDriver};

// Read current channel
let channel = mac.mlme_get(PibAttribute::PhyCurrentChannel).await?;

// Set short address after joining
mac.mlme_set(
    PibAttribute::MacShortAddress,
    PibValue::ShortAddress(ShortAddress(0x1234)),
).await?;
}

PibAttribute Variants

Addressing (set during join)

AttributeIDPibValue TypeDefaultDescription
MacShortAddress0x53ShortAddress0xFFFF (unassigned)Own 16-bit network short address. Set by the coordinator during association.
MacPanId0x50PanId0xFFFF (not associated)PAN identifier of the network. Set during join or network formation.
MacExtendedAddress0x6FExtendedAddressHardware-programmedOwn 64-bit IEEE address. Usually read-only, burned into radio hardware.
MacCoordShortAddress0x4BShortAddress0xFFFFShort address of the parent coordinator or router. Set during association.
MacCoordExtendedAddress0x4AExtendedAddress[0; 8]Extended address of the parent coordinator or router.

Network Configuration

AttributeIDPibValue TypeDefaultDescription
MacAssociatedPanCoord0x56Boolfalsetrue if this device is the PAN coordinator. Set during network formation.
MacRxOnWhenIdle0x52BooltrueWhether the radio receiver is on during idle. Set true for coordinators and routers, false for sleepy end devices. Controls how the device is addressed in network discovery.
MacAssociationPermit0x41BoolfalseWhether the device is accepting association requests (join permit open). Set by permit_joining commands.

Beacon (Non-Beacon Mode)

AttributeIDPibValue TypeDefaultDescription
MacBeaconOrder0x47U815Beacon order. Always 15 for Zigbee PRO (non-beacon mode). Do not change.
MacSuperframeOrder0x54U815Superframe order. Always 15 for Zigbee PRO. Do not change.
MacBeaconPayload0x45PayloadEmptyBeacon payload bytes. Contains NWK beacon content for coordinators and routers. Max 52 bytes.
MacBeaconPayloadLength0x46U80Length of the beacon payload in bytes.

TX/RX Tuning

AttributeIDPibValue TypeDefaultDescription
MacAutoRequest0x42BooltrueAutomatically send data request after receiving a beacon with the pending bit set. Used by end devices to retrieve buffered data from their parent.
MacMaxCsmaBackoffs0x4EU84Maximum number of CSMA-CA backoff attempts before declaring channel access failure. Range: 0–5.
MacMinBe0x4FU83Minimum backoff exponent for CSMA-CA (2.4 GHz default: 3). Lower values mean more aggressive channel access.
MacMaxBe0x57U85Maximum backoff exponent for CSMA-CA. Range: 3–8.
MacMaxFrameRetries0x59U83Number of retransmission attempts after an ACK failure. Range: 0–7.
MacMaxFrameTotalWaitTime0x58U32PHY-dependentMaximum time (in symbols) to wait for an indirect transmission frame. Used by end devices polling their parent.
MacResponseWaitTime0x5AU832Maximum time to wait for a response frame (in units of aBaseSuperframeDuration). Used during association.

Sequence Numbers

AttributeIDPibValue TypeDefaultDescription
MacDsn0x4CU8RandomData/command frame sequence number. Incremented automatically per transmission.
MacBsn0x49U8RandomBeacon sequence number. Incremented per beacon transmission.

Indirect TX (Coordinator/Router)

AttributeIDPibValue TypeDefaultDescription
MacTransactionPersistenceTime0x55U160x01F4How long (in unit periods) a coordinator stores indirect frames for sleepy children before discarding.

Debug / Special

AttributeIDPibValue TypeDefaultDescription
MacPromiscuousMode0x51BoolfalseWhen true, the radio receives all frames regardless of addressing. Used for sniffing/debugging.

PHY Attributes (via MAC GET/SET)

AttributeIDPibValue TypeDefaultDescription
PhyCurrentChannel0x00U811Current 2.4 GHz channel (11–26). Set during network formation or join.
PhyChannelsSupported0x01U320x07FFF800Bitmask of supported channels. For 2.4 GHz Zigbee: bits 11–26 set. Read-only on most hardware.
PhyTransmitPower0x02I8Hardware-dependentTX power in dBm. Range depends on radio hardware (typically −20 to +20 dBm).
PhyCcaMode0x03U81Clear Channel Assessment mode. Mode 1 = energy above threshold. Rarely changed.
PhyCurrentPage0x04U80Channel page. Always 0 for 2.4 GHz Zigbee. Do not change.

PibValue Variants

The PibValue enum is the value container for all PIB GET/SET operations:

VariantContained TypeUsed By
Bool(bool)boolMacAssociatedPanCoord, MacRxOnWhenIdle, MacAssociationPermit, MacAutoRequest, MacPromiscuousMode
U8(u8)u8MacBeaconOrder, MacSuperframeOrder, MacBeaconPayloadLength, MacMaxCsmaBackoffs, MacMinBe, MacMaxBe, MacMaxFrameRetries, MacResponseWaitTime, MacDsn, MacBsn, PhyCurrentChannel, PhyCcaMode, PhyCurrentPage
U16(u16)u16MacTransactionPersistenceTime
U32(u32)u32MacMaxFrameTotalWaitTime, PhyChannelsSupported
I8(i8)i8PhyTransmitPower
ShortAddress(ShortAddress)ShortAddress (newtype over u16)MacShortAddress, MacCoordShortAddress
PanId(PanId)PanId (newtype over u16)MacPanId
ExtendedAddress(IeeeAddress)[u8; 8]MacExtendedAddress, MacCoordExtendedAddress
Payload(PibPayload)PibPayload (max 52 bytes)MacBeaconPayload

PibPayload

Fixed-capacity beacon payload buffer:

#![allow(unused)]
fn main() {
pub struct PibPayload {
    buf: [u8; 52],
    len: usize,
}

impl PibPayload {
    pub fn new() -> Self;                       // Empty payload
    pub fn from_slice(data: &[u8]) -> Option<Self>;  // None if > 52 bytes
    pub fn as_slice(&self) -> &[u8];            // Current content
}
}

Convenience Accessors on PibValue

Each variant has a corresponding accessor that returns Option:

MethodReturns
as_bool()Option<bool>
as_u8()Option<u8>
as_u16()Option<u16>
as_u32()Option<u32>
as_short_address()Option<ShortAddress>
as_pan_id()Option<PanId>
as_extended_address()Option<IeeeAddress>

PHY Constants & Helpers

#![allow(unused)]
fn main() {
/// Base superframe duration in symbols (960)
pub const A_BASE_SUPERFRAME_DURATION: u32 = 960;

/// Symbol rate at 2.4 GHz in symbols/second
pub const SYMBOL_RATE_2_4GHZ: u32 = 62_500;

/// Calculate scan duration per channel in symbols
pub fn scan_duration_symbols(exponent: u8) -> u32;

/// Calculate scan duration per channel in microseconds
pub fn scan_duration_us(exponent: u8) -> u64;
}
Scan Duration (exponent)SymbolsMillisecondsTypical Use
01,92030.7Ultra-fast scan
24,80076.8Quick scan
38,640138Default for Zigbee
416,320261Standard scan
531,680507Extended scan
8247,2963,957Deep scan

Usage Patterns

Reading current network state

#![allow(unused)]
fn main() {
let short = mac.mlme_get(PibAttribute::MacShortAddress).await?
    .as_short_address().unwrap();
let pan = mac.mlme_get(PibAttribute::MacPanId).await?
    .as_pan_id().unwrap();
let channel = mac.mlme_get(PibAttribute::PhyCurrentChannel).await?
    .as_u8().unwrap();
}

Configuring TX performance

#![allow(unused)]
fn main() {
// More aggressive: fewer backoffs, more retries
mac.mlme_set(PibAttribute::MacMaxCsmaBackoffs, PibValue::U8(3)).await?;
mac.mlme_set(PibAttribute::MacMaxFrameRetries, PibValue::U8(5)).await?;
mac.mlme_set(PibAttribute::MacMinBe, PibValue::U8(2)).await?;
}

Setting up a sleepy end device

#![allow(unused)]
fn main() {
// Disable RX during idle for battery saving
mac.mlme_set(PibAttribute::MacRxOnWhenIdle, PibValue::Bool(false)).await?;
// Enable auto data request after beacon
mac.mlme_set(PibAttribute::MacAutoRequest, PibValue::Bool(true)).await?;
}

Adjusting TX power

#![allow(unused)]
fn main() {
// Set to +4 dBm
mac.mlme_set(PibAttribute::PhyTransmitPower, PibValue::I8(4)).await?;
// Read back actual power (may be clamped by hardware)
let actual = mac.mlme_get(PibAttribute::PhyTransmitPower).await?;
}