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?;
}
Attribute ID PibValue Type Default Description
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-programmed Own 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.
Attribute ID PibValue Type Default Description
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.
Attribute ID PibValue Type Default Description
MacBeaconOrder0x47U815Beacon order. Always 15 for Zigbee PRO (non-beacon mode). Do not change.
MacSuperframeOrder0x54U815Superframe order. Always 15 for Zigbee PRO. Do not change.
MacBeaconPayload0x45PayloadEmpty Beacon payload bytes. Contains NWK beacon content for coordinators and routers. Max 52 bytes.
MacBeaconPayloadLength0x46U80Length of the beacon payload in bytes.
Attribute ID PibValue Type Default Description
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-dependent Maximum 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.
Attribute ID PibValue Type Default Description
MacDsn0x4CU8Random Data/command frame sequence number. Incremented automatically per transmission.
MacBsn0x49U8Random Beacon sequence number. Incremented per beacon transmission.
Attribute ID PibValue Type Default Description
MacTransactionPersistenceTime0x55U160x01F4How long (in unit periods) a coordinator stores indirect frames for sleepy children before discarding.
Attribute ID PibValue Type Default Description
MacPromiscuousMode0x51BoolfalseWhen true, the radio receives all frames regardless of addressing. Used for sniffing/debugging.
Attribute ID PibValue Type Default Description
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-dependent TX 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.
The PibValue enum is the value container for all PIB GET/SET operations:
Variant Contained Type Used 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
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
}
}
Each variant has a corresponding accessor that returns Option:
Method Returns
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>
#![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) Symbols Milliseconds Typical Use
0 1,920 30.7 Ultra-fast scan
2 4,800 76.8 Quick scan
3 8,640 138 Default for Zigbee
4 16,320 261 Standard scan
5 31,680 507 Extended scan
8 247,296 3,957 Deep scan
#![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();
}
#![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?;
}
#![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?;
}
#![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?;
}