Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

IEEE 802.15.4 - MAC Frame Generation and Decoding

This example shows how to generate and decode MAC frames of the IEEE 802.15.4 standard [ 1 ] using the Communications System Toolbox™ Library for the ZigBee® Protocol.

Background

The IEEE® 802.15.4 standard specifies the MAC and PHY layers of Low-Rate Wireless Personal Area Networks (LR-WPANs) [ 1 ]. The IEEE 802.15.4 MAC and PHY layers provide the basis of other higher-layer standards, such as ZigBee, WirelessHart®, 6LoWPAN and MiWi. Such standards find application in home automation and sensor networking and are highly relevant to the Internet of Things (IoT) trend.

Architecture

The IEEE 802.15.4 MAC layer inserts a MAC header and a MAC footer before and after a network-layer frame, respectively. The MAC footer contains a CRC check.

A lrwpan.MACFrameConfig configuration object is used both in generating and decoding IEEE 802.15.4 MAC frames. Such objects describe a MAC frame and specify its frame type and all applicable properties. The lrwpan.MACFrameGenerator function accepts a lrwpan.MACFrameConfig object describing the frame, and optionally a MAC-layer payload (NET-layer frame) in bytes (two-characters), and outputs the MAC frame in bits. The lrwpan.MACFrameDecoder function accepts a MAC Protocol Data Unit (MPDU) in bits and outputs a lrwpan.MACFrameConfig object describing the frame and possibly a NET-layer frame in bytes. Clause 5 in [ 1 ] describes the MAC frame formats.

Decoding MAC Frames of Home Automation ZigBee Radios

This section decodes MAC frames transmitted from commercial ZigBee radios enabling home automation, and captured using a USRP® B200-mini radio and the Communications System Toolbox Support Package for USRP® radio.

load lrwpanMACCaptures

First, a data frame is decoded:

[dataFrameMACConfig, netFrame] = lrwpan.MACFrameDecoder(MPDU_data);
if ~isempty(dataFrameMACConfig)
  fprintf('CRC check passed for the MAC frame.\n');
  dataFrameMACConfig %#ok<NOPTS>
end
CRC check passed for the MAC frame.

dataFrameMACConfig = 

  MACFrameConfig with properties:

                       FrameType: 'Data'

   General MAC properties:
                  SequenceNumber: 244
           AcknowledgmentRequest: 1
           DestinationAddressing: 'Short address'
        DestinationPANIdentifier: '1E16'
              DestinationAddress: '35EA'
                SourceAddressing: 'Short address'
                   SourceAddress: '0000'
    PANIdentificationCompression: 1
                    FramePending: 0
                    FrameVersion: '2003'
                        Security: 0

Next, an acknowledgement frame is decoded:

ackFrameMACConfig = lrwpan.MACFrameDecoder(MPDU_ack) %#ok<NOPTS>
ackFrameMACConfig = 

  MACFrameConfig with properties:

                FrameType: 'Acknowledgment'

   General MAC properties:
           SequenceNumber: 165
    DestinationAddressing: 'Not present'
         SourceAddressing: 'Not present'
             FramePending: 0
             FrameVersion: '2003'
                 Security: 0

Generating MAC Frames

The lrwpan.MACFrameGenerator function can generate all MAC frame types from the IEEE 802.15.4 standard [ 1 ], i.e., 'Beacon', 'Data', 'Acknowledgement', and 'MAC Command' frame types. The MAC Command frame types can be further specified as: 'Association request', 'Association response', 'Disassociation notification', 'Data request', 'PAN ID conflict notification', 'Orphan notification', 'Beacon request', and 'GTS request'.

This code illustrates how to generate frames for all frame types:

% Beacon
beaconConfig = lrwpan.MACFrameConfig('FrameType', 'Beacon');
beaconMACFrame = lrwpan.MACFrameGenerator(beaconConfig);

% Data
dataConfig = lrwpan.MACFrameConfig('FrameType', 'Data');
numOctets = 50;
payload = dec2hex(randi([0 2^8-1], numOctets, 1), 2);
dataMACFrame = lrwpan.MACFrameGenerator(dataConfig, payload);

% Acknowledgment
ackConfig = lrwpan.MACFrameConfig('FrameType', 'Acknowledgment');
ackFrame = lrwpan.MACFrameGenerator(ackConfig);

% MAC Command
commandConfig = lrwpan.MACFrameConfig('FrameType', 'MAC Command');
commandConfig.MACCommand = 'Association request';
% Valid settings for MACCommand also include: 'Association response',
% 'Disassociation notification', 'Data request', 'PAN ID conflict
% notification', 'Orphan notification', 'Beacon request', and 'GTS request'.
commandFrame = lrwpan.MACFrameGenerator(commandConfig);

Further Exploration

You can further explore the following generator and decoding functions, as well as the configuration object:

Selected Bibliography

  1. IEEE 802.15.4-2011 - IEEE Standard for Local and metropolitan area networks--Part 15.4: Low-Rate Wireless Personal Area Networks (LR-WPANs)

Was this topic helpful?