一般コマンドのための ZigBee フレームの生成と復号化
この例では、Communications Toolbox™ Library for ZigBee and UWB を使用して、ZigBee® 仕様 [1] の一般的なコマンド フレームを生成および復号化する方法を説明します。
背景
ZigBee 規格 [1] は、低速無線パーソナル エリア ネットワークのネットワーク (NET または NWK) レイヤーとアプリケーション (APP) レイヤーを規定します。この NET レイヤーおよび APP レイヤーの仕様は、IEEE® 802.15.4™ [2] の PHY 仕様および MAC 仕様に基づいて作成されています。ZigBee デバイスは、ホーム オートメーションやセンサー ネットワーキングに使用例があり、Internet of Things (IoT) の流行にも密接に関連しています。
ZigBee アプリケーション層は、(i) Application Support Sublayer (APS)、(ii) ZigBee Cluster Library (ZCL) という複数の下位層で構成されます。
APS および ZCL "ヘッダー" はすべてのアプリケーション プロファイルと ZigBee クラスター/コマンドに共通の形式 (それぞれ、[ 1 ] の Clause 2.2.5 および [ 3 ] の Clause 2.4 を参照) に従います。APS ヘッダーはフレームのクラスターを宣言し、ZCL ヘッダーはフレームのコマンドを宣言します。ZCL ペイロードは、一部のクラスター/コマンドのみのために存在し、コマンド固有の形式に従います。
一部のコマンドは特定のクラスターにしか利用できませんが、その他の一部の (一般的な) コマンドはすべてのクラスターに使用できます。一般的なコマンド フレームは、個々のクラスターに固有ではない属性およびその他の一般的なタスクを操作するために使用されます ([ 3 ] の Clause 2.5 を参照)。この例では、このような一般的な、ライブラリ全体にわたる ZigBee コマンドの ZCL ペイロードを生成および復号化する方法を説明します。一般的な APS および ZCL ヘッダーの生成と復号化は、ZigBee ホーム オートメーション フレームの生成と復号化の例で説明しています。
コマンド
この例では、次の一般的なコマンドのフレームの生成と復号化を説明します。
Read Attributes: このコマンドは、異なるデバイスにおける属性値を問い合わせます。
Read Attributes Response: このコマンドは、属性値をもつ応答を返します。
Write Attributes: このコマンドは、異なるデバイスにおける属性値を変更します。
Write Attributes Response: このコマンドは、Write Attributes コマンドの結果をもつ応答を返します。
さらにこの例では、次のコマンドの実装を提供します (これらは例示されていません)。
Write Attributes Undivided: このコマンドは、他のすべての指定した属性も更新可能な場合にのみ属性が更新されることを除いて "Write Attributes" と同じです。
Write Attributes No Response: このコマンドは、応答フレームが不要であることを除いて "Write Attributes" と同じです。
Report Attributes: このコマンドは、すべての属性とその値をレポートします。
Default Response: このコマンドは、汎用形式の応答フレームを生成します。
zigbee.GeneralFrameConfig
構成オブジェクトは、一般的なコマンドの ZCL ペイロードの生成と復号化の両方で使用されます。このようなオブジェクトは、一般的なコマンドのペイロードと適用可能なすべてのプロパティを表します。
一般的なコマンドの ZCL ペイロードの生成
関数 zigbee.GeneralFrameGenerator
は、一般的なコマンドのペイロードを表す zigbee.GeneralFrameConfig
オブジェクトを受け入れ、ペイロードをバイト単位で生成します。次のコードは、Read/Write Attribute コマンドとその応答のペイロードを作成します。
% Read attributes command readConfigTx = zigbee.GeneralFrameConfig( ... 'CommandType','Read Attributes','AttributeID','0000')
readConfigTx = GeneralFrameConfig with properties: CommandType: 'Read Attributes' AttributeID: '0000'
readPayload = zigbee.GeneralFrameGenerator(readConfigTx); % Read attributes response command readResponseConfigTx = zigbee.GeneralFrameConfig( ... 'CommandType','Read Attributes Response', ... 'AttributeID','0000', ... 'Status','Success', ... 'AttributeType','boolean', ... 'AttributeValue',false)
readResponseConfigTx = GeneralFrameConfig with properties: CommandType: 'Read Attributes Response' AttributeID: '0000' Status: 'Success' AttributeType: 'Boolean' AttributeValue: 0
readResponsePayload = zigbee.GeneralFrameGenerator(readResponseConfigTx); % Write attributes command writeConfigTx = zigbee.GeneralFrameConfig( ... 'CommandType','Write Attributes', ... 'AttributeID','0000', ... 'AttributeType','boolean', ... 'AttributeValue',true)
writeConfigTx = GeneralFrameConfig with properties: CommandType: 'Write Attributes' AttributeID: '0000' AttributeType: 'Boolean' AttributeValue: 1
writePayload = zigbee.GeneralFrameGenerator(writeConfigTx); % % Write attributes response command: writeResponseConfigTx = zigbee.GeneralFrameConfig( ... 'CommandType','Write Attributes Response', ... 'Status','Success')
writeResponseConfigTx = GeneralFrameConfig with properties: CommandType: 'Write Attributes Response' Status: 'Success'
writeResponsePayload = zigbee.GeneralFrameGenerator(writeResponseConfigTx);
ZigBee 無線機から取得した一般的なコマンドの ZCL ペイロードの復号化
このセクションでは、USRP® B200-mini 無線機と Communications Toolbox Support Package for USRP® radio を使用して市販のホーム オートメーション ZigBee 無線機から取得した、一般的なコマンドの ZCL ペイロードを復号化します。詳細については、ZigBee ホーム オートメーション フレームの生成と復号化の例にある「クラスターとフレームの取得」のセクションを参照してください。
load zigbeeGeneralCommandCaptures % Load captured payloads
関数 zigbee.GeneralFrameDecoder は、一般的なコマンド名とバイト単位のそのペイロードを受け入れ、一般的なコマンドのペイロードを表す zigbee.GeneralFrameConfig オブジェクトを出力します。コマンド名は、ZCL ヘッダーの復号化から取得します。ZigBee ホーム オートメーション フレームの生成と復号化の例にある「ホーム オートメーション ZigBee 無線機の ZCL ヘッダーの復号化」のセクションを参照してください。
% Read attributes readConfigRx = zigbee.GeneralFrameDecoder( ... 'Read Attributes',capturedReadPayload)
readConfigRx = GeneralFrameConfig with properties: CommandType: 'Read Attributes' AttributeID: '0000'
% Read attributes response readResponseRx = zigbee.GeneralFrameDecoder( ... 'Read Attributes Response',capturedReadResponsePayload)
readResponseRx = GeneralFrameConfig with properties: CommandType: 'Read Attributes Response' AttributeID: '0000' Status: 'Success' AttributeType: 'Boolean' AttributeValue: 1
% Default response defaultResponseRx = zigbee.GeneralFrameDecoder( ... 'Default Response',capturedDefaultResponsePayload)
defaultResponseRx = GeneralFrameConfig with properties: CommandType: 'Default Response' Status: 'Success' CommandToRespond: '01'
生成された一般的なコマンドの ZCL ペイロードの復号化
このセクションでは、生成された残りの一般的なコマンド ('Write Attributes' や 'Write Attributes Response' など) の復号化について説明します。
% Write attributes writeConfigRx = zigbee.GeneralFrameDecoder( ... 'Write Attributes',writePayload)
writeConfigRx = GeneralFrameConfig with properties: CommandType: 'Write Attributes' AttributeID: '0000' AttributeType: 'Boolean' AttributeValue: 1
% Write attributes response writeResponseRx = zigbee.GeneralFrameDecoder( ... 'Write Attributes Response',writeResponsePayload)
writeResponseRx = GeneralFrameConfig with properties: CommandType: 'Write Attributes Response' Status: 'Success'
Wireshark 復号化
生成したフレームは PCAP 形式に変換することができます。この形式は Wireshark で解析および可視化できます [4]。このプロセスは、Communications Toolbox Library for ZigBee and UWB が規格に準拠した方法でフレームを生成および復号化することを確認する追加の手順として機能します。
PCAP ファイルでは、ZCL ペイロードがすべての他の層およびサブ層 (MAC、NET、APS、ZCL) のヘッダーと共に封入される必要があります。次のコマンドは、Wireshark で読み込み可能な、この例で生成された ZCL ペイロードの PCAP ファイルを生成します。
% Profile ID profileID = zigbee.profileID('Home Automation'); onOffID = zigbee.clusterID('On/Off'); payloadsWithInfo(1) = struct( ... 'Payload',readPayload, ... 'ProfileID',profileID, ... 'ClusterSpecific',false, ... 'ClusterID',onOffID, ... 'CommandType','Read Attributes', ... 'Direction','Downlink'); payloadsWithInfo(2) = struct( ... 'Payload',readResponsePayload, ... 'ProfileID',profileID, ... 'ClusterSpecific',false, ... 'ClusterID',onOffID, ... 'CommandType','Read Attributes Response', ... 'Direction','Uplink'); payloadsWithInfo(3) = struct( ... 'Payload',writePayload, ... 'ProfileID',profileID, ... 'ClusterSpecific',false, ... 'ClusterID',onOffID, ... 'CommandType','Write Attributes', ... 'Direction','Downlink'); payloadsWithInfo(4) = struct( ... 'Payload',writeResponsePayload, ... 'ProfileID',profileID, ... 'ClusterSpecific',false, ... 'ClusterID',onOffID, ... 'CommandType','Write Attributes Response', ... 'Direction','Uplink'); % Add headers from other layers/sublayers MPDUs = zigbeeAddProtocolHeaders(payloadsWithInfo); % Export MPDUs to a PCAP format zigbeeExportToPcap(MPDUs,'zigbeeGeneralCommands.pcap'); % Open PCAP file with Wireshark
その他の調査
以下のジェネレーター関数と復号化関数、および関連する構成オブジェクトについてさらに調査できます。
zigbee.GeneralFrameConfig
,zigbee.GeneralFrameGenerator
,zigbee.GeneralFrameDecoder
zigbee.ZCLFrameConfig
,zigbee.ZCLFrameGenerator
,zigbee.ZCLFrameDecoder
zigbee.APSFrameConfig
,zigbee.APSFrameGenerator
,zigbee.APSFrameDecoder
これらのユーティリティはドキュメンテーションになく、API または機能が将来変更される可能性があります。これらのユーティリティのいずれかについてソース コードを表示するには、関数edit
を使用します。たとえば、次のように入力します。
edit zigbee.GeneralFrameConfig
MATLAB® コマンド ラインで上のように入力すると、zigbee.GeneralFrameConfig
が開きます。
参考文献
1 - ZigBee Alliance, ZigBee Specification Document 053474r17, 2007.
2 - IEEE 802.15.4-2011 - IEEE Standard for Local and Metropolitan Area Networks--Part 15.4: Low-Rate Wireless Personal Area Networks (LR-WPANs).
3 - ZigBee Alliance, ZigBee Cluster Library Specification, Revision 6, Jan. 2016.
4 - Wireshark software: https://www.wireshark.org/