Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

IEEE 802.15.4 - MAC フレームの生成および復号化

この例では、Communications Toolbox™ を使用して、IEEE® 802.15.4™ 規格 [1] の MAC フレームを生成および復号化する方法を示します。

背景

IEEE 802.15.4 規格は、低速無線パーソナル エリア ネットワーク (LR-WPAN) [1] の MAC レイヤーと PHY レイヤーを規定します。IEEE 802.15.4 の MAC レイヤーと PHY レイヤーは、ZigBee、WirelessHart®、6LoWPAN、および MiWi などの他の上位レイヤーの規格のベースを提供します。このような規格は、ホーム オートメーションやセンサー ネットワーキングに使用例があり、モノのインターネット (IoT) の流行にも密接に関連しています。

アーキテクチャ

IEEE 802.15.4 MAC レイヤーは、MAC ヘッダーと MAC フッターをそれぞれネットワーク層フレームの前後に挿入します。MAC フッターは CRC チェックを含みます。

lrwpan.MACFrameConfig 構成オブジェクトは、IEEE 802.15.4 MAC フレームの生成と復号化の両方で使用されます。このようなオブジェクトは、MAC フレームを表し、そのフレーム タイプと適用可能なすべてのプロパティを指定します。

関数 lrwpan.MACFrameGenerator は、フレームを表す lrwpan.MACFrameConfig オブジェクト、およびオプションで MAC レイヤー ペイロード (NET 層フレーム) をバイト単位 (2 文字) で受け入れ、MAC フレームをビット単位で出力します。

関数 lrwpan.MACFrameDecoder は、MAC プロトコル データ ユニット (MPDU) をビット単位で受け入れ、フレームと場合によっては NET 層フレームを表す lrwpan.MACFrameConfig オブジェクトをバイト単位で出力します。[1] の Clause 5 では、MAC フレーム形式について説明されています。

ホーム オートメーション ZigBee 無線機の MAC フレームの復号化

この節では、ホーム オートメーションを実現する市販の ZigBee 無線機から送信され、USRP® B200-mini 無線機と Communications Toolbox Support Package for USRP® radio を使用して取得された MAC フレームを復号化します。取得した波形の PHY レイヤーは、IEEE 802.15.4 OQPSK 信号の復元の例で説明されている方法論に従って復号化されています。結果として得られる MPDU は MAT ファイルに保存されます。

load lrwpanMACCaptures

はじめに、データ フレームを復号化します。

[dataFrameMACConfig, netFrame] = lrwpan.MACFrameDecoder(MPDU_data);
if ~isempty(dataFrameMACConfig)
    fprintf('CRC check passed for the MAC frame.\n');
    dataFrameMACConfig
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

   Security properties:
    No properties.

   Beacon properties:
    No properties.

   "MAC Command" properties:
    No properties.

次に、肯定応答フレームを復号化します。

ackFrameMACConfig = lrwpan.MACFrameDecoder(MPDU_ack)
ackFrameMACConfig = 
  MACFrameConfig with properties:

                FrameType: 'Acknowledgment'

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

   Security properties:
    No properties.

   Beacon properties:
    No properties.

   "MAC Command" properties:
    No properties.

MAC フレームの生成

関数 lrwpan.MACFrameGenerator は、IEEE 802.15.4 規格 [1] のすべての MAC フレーム タイプ ('ビーコン'、'データ'、'肯定応答'、および 'MAC コマンド' フレーム タイプ) を生成できます。MAC コマンド フレーム タイプはさらに以下として規定できます。'アソシエーション要求'、'アソシエーション応答'、'アソシエーション解除通知'、'データ要求'、'PAN ID 競合通知'、'孤立通知'、'ビーコン要求'、'GTS 要求'。

このコードは、すべてのフレーム タイプのフレームを生成する方法を示します。

% 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);

その他の調査

この例では、ドキュメンテーションにない以下のユーティリティを使用します。ドキュメンテーションにないユーティリティの API と機能は、将来変更される可能性があります。ユーティリティのソース コードを表示するには、関数editを使用します。

  • lrwpan.MACFrameGenerator および lrwpan.MACFrameDecoder: IEEE 802.15.4 MAC フレームの作成および復号化。

  • lrwpan.MACFrameConfig: IEEE 802.15.4 フレーム構成の作成。

参考文献

1 - "IEEE Standard for Local and Metropolitan Area Networks--Part 15.4: Low-Rate Wireless Personal Area Networks (LR-WPANs)," in IEEE Std 802.15.4-2011 (Revision of IEEE Std 802.15.4-2006) , vol., no., pp.1-314, 5 Sept. 2011, doi: 10.1109/IEEESTD.2011.6012487.

関連するトピック