Documentation
¶
Overview ¶
Package zigbee decodes Zigbee Network Layer (NWK) frames — the layer that sits on top of IEEE 802.15.4 MAC frames in the Zigbee stack. Pure offline parser; no transport, no hardware.
Wrap-vs-native judgement: Zigbee NWK is a public Zigbee Alliance specification (Zigbee Pro 2015 R21+). The walker is bit-level decoding over a documented Frame Control + address + optional fields layout. Wrapping a FAP for this would add an SD-card install step + a firmware-fork dependency for a pure parser. Native delivers offline analysis — operators decode the IEEE 802.15.4 MAC frame with ieee802154_decode, then dispatch the MAC payload here for NWK-layer fields.
Pairs with the existing ieee802154_decode — chain the two for full Zigbee frame analysis.
What this package covers:
- NWK Frame Control (16 bits): frame type (Data / NWK Command / Reserved / Inter-PAN), protocol version (R22 = 0x2), discover route (0/1/2), multicast / security / source route / destination IEEE / source IEEE flags
- 16-bit destination + source NWK addresses
- Radius (hop limit) + sequence number
- Optional 64-bit destination + source IEEE addresses (when the corresponding presence flag is set)
- Multicast control byte (when multicast flag is set)
- Source route subframe (when source-route flag is set): relay count + relay index + relay list
- Auxiliary Security Header (when security flag is set): security control + frame counter + source address + key sequence number — surfaced as hex; decryption needs the network key out-of-band
- NWK payload — surfaced as hex; APS (Application Support Sublayer) and ZCL (Zigbee Cluster Library) dissection is deferred to follow-on Specs
What this package does NOT cover (deliberately out of scope):
- NWK Command frame body decoding (Route Request / Response / Leave / Rejoin / Link Status / Network Status / End Device Timeout) — separate Spec when a caller materialises
- APS / ZDO / ZCL — higher-layer protocols
- Decryption (needs the network key)
- MIC validation (needs key + frame-counter context)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DiscoverRoute ¶
type DiscoverRoute int
DiscoverRoute is the 2-bit discover-route field.
const ( DiscoverRouteSuppress DiscoverRoute = 0 DiscoverRouteEnable DiscoverRoute = 1 DiscoverRouteReserved DiscoverRoute = 2 )
func (DiscoverRoute) String ¶
func (d DiscoverRoute) String() string
type Frame ¶
type Frame struct {
FrameControl FrameControl `json:"frame_control"`
// DestinationAddress is the 16-bit short address of the
// destination node (or broadcast 0xFFFF / 0xFFFD / 0xFFFC /
// 0xFFFB for documented broadcast classes).
DestinationAddress string `json:"destination_address"`
DestinationAddressRaw int `json:"destination_address_raw"`
// SourceAddress is the 16-bit short address of the source.
SourceAddress string `json:"source_address"`
SourceAddressRaw int `json:"source_address_raw"`
// Radius is the hop limit (decremented at each forwarding hop).
Radius int `json:"radius"`
// SequenceNumber is the NWK-layer sequence number.
SequenceNumber int `json:"sequence_number"`
// DestinationIEEEHex / SourceIEEEHex are populated when the
// respective presence flag is set. Stored little-endian on
// wire, rendered big-endian to match the form printed on
// device labels.
DestinationIEEEHex string `json:"destination_ieee,omitempty"`
SourceIEEEHex string `json:"source_ieee,omitempty"`
// MulticastControl is populated when the multicast flag is
// set. The byte encodes mode + non-member radius + max
// non-member radius.
MulticastControl *MulticastControl `json:"multicast_control,omitempty"`
// SourceRouteHex is the raw source-route subframe when the
// flag is set (relay count + relay index + relay list).
SourceRouteHex string `json:"source_route_hex,omitempty"`
// AuxSecurityHeaderHex is the raw security header when the
// flag is set. Walking it (security level / key identifier /
// frame counter) is deferred to a follow-on Spec.
AuxSecurityHeaderHex string `json:"aux_security_header_hex,omitempty"`
// PayloadHex is the NWK payload after all headers.
PayloadHex string `json:"payload_hex,omitempty"`
// BroadcastClass names the well-known broadcast destination
// when applicable.
BroadcastClass string `json:"broadcast_class,omitempty"`
}
Frame is the top-level decoded NWK frame.
func Decode ¶
Decode parses a hex-encoded Zigbee NWK frame. Tolerates ':' / '-' / '_' / whitespace separators.
func DecodeBytes ¶
DecodeBytes is the byte-slice variant of Decode.
type FrameControl ¶
type FrameControl struct {
Raw int `json:"raw"`
// Frame Type (bits 1..0).
FrameType int `json:"frame_type"`
FrameTypeName string `json:"frame_type_name"`
// Protocol Version (bits 5..2) — Zigbee Pro R22 uses 2.
ProtocolVersion int `json:"protocol_version"`
// Discover Route (bits 7..6).
DiscoverRoute int `json:"discover_route"`
DiscoverRouteName string `json:"discover_route_name"`
// Bit 8: Multicast (when set, multicast control byte follows
// the addressing fields).
Multicast bool `json:"multicast"`
// Bit 9: Security (auxiliary security header present).
Security bool `json:"security"`
// Bit 10: Source Route (source route subframe present).
SourceRoute bool `json:"source_route"`
// Bit 11: Destination IEEE Address present (8 bytes after
// source NWK address).
DestinationIEEE bool `json:"destination_ieee_present"`
// Bit 12: Source IEEE Address present.
SourceIEEE bool `json:"source_ieee_present"`
}
FrameControl is the decoded 16-bit NWK Frame Control field.
type MulticastControl ¶
type MulticastControl struct {
Raw int `json:"raw"`
Mode int `json:"mode"`
ModeName string `json:"mode_name"`
NonMemberRadius int `json:"non_member_radius"`
MaxNonMemberRadius int `json:"max_non_member_radius"`
}
MulticastControl is the decoded multicast control byte (present when the Multicast flag is set in Frame Control).
bits 0..1: Multicast Mode (0 = non-member, 1 = member) bits 2..4: Non-Member Radius (3 bits) bits 5..7: Max Non-Member Radius (3 bits)
type NWKFrameType ¶
type NWKFrameType int
NWKFrameType is the 2-bit frame type field.
const ( NWKFrameTypeData NWKFrameType = 0 NWKFrameTypeCommand NWKFrameType = 1 NWKFrameTypeReserved NWKFrameType = 2 NWKFrameTypeInterPAN NWKFrameType = 3 )
func (NWKFrameType) String ¶
func (t NWKFrameType) String() string