UG435.02: Using Silicon Labs Connect v3.x with IEEE 802.15.4 (Rev. 0.1)

Connect v3.x User’s Guide 的本章介绍了如何将 Silicon Labs Connect stack v3.x 与 IEEE 802.15.4 结合使用。 Connect v3.x User’s Guide 假定您已经安装了 Simplicity Studio 开发环境和 Flex SDK,并且熟悉配置、编译、刷写 Connect-based 应用程序的基础知识。有关 Connect v3.x User’s Guide 中各章的概述,请参阅 UG435.01: About the Connect v3.x User’s Guide

1. 引言

Silicon Labs Connect 基于 IEEE 802.15.4-2011 标准(缩写为 IEEE 802.15.4)。因此,要了解 Silicon Labs Connect stack,还需要具备 802.15.4 的基础知识。802.15.4 定义了各种物理层和媒体访问控制层,这些设计用于低数据速率、低功耗、低复杂度、短距离的个域网通信。IEEE 802.15.4 也是网状网络协议(如 Zigbee 或 Thread)的基础。

本文档简要地介绍了 Connect 中使用的 IEEE 802.15.4 功能,因此您无需阅读 IEEE 802.15.4 规范即可了解其 MAC 层。

有关 IEEE 802.15.4 的更多信息,请参阅 https://standards.ieee.org/standard/802_15_4-2011.html

2. 基本术语

在研究技术细节之前,定义一些通用术语是很重要的。

2.1 物理层

物理(PHY,Physical)层是通信栈中的最底层。它负责通过介质传输非结构化数据。在无线网络栈中,PHY 定义了成功接收数据所需的调制、比特率和帧的一部分(如前导码(preamble)和同步字(sync word))。

2.2 数据链路层

数据链路层(DLL,Data Link Layer)构建在通信栈中的 PHY 之上。它负责在两个设备之间进行可靠的数据传输(如寻址、确认和完整性检查)。在 IEEE 802 协议中,DLL 由两层组成。较低的一层称为媒体访问控制(MAC,Media Access Control)层。由于 IEEE 802.15.4 没有较上的一层,因此 MAC 层可与 DLL 互换。

译者注:IEEE 802 将 OSI 的数据链路层分成了两个子层,分别是逻辑链路控制(LLC,Logical Link Control)和媒体访问控制(MAC,Media Access Control)。

2.3 个域网

个域网(PAN,Personal Area Network)是一个可以互相通信的逻辑设备组。基于 IEEE 802.15.4 构建的协议通常在 PAN 内部通信。

2.4 PAN Coordinator

PAN Coordinator(协调器)可以在某些协议中执行特殊服务(如分配短地址)。

2.5 Intra-PAN Message

Intra-PAN Message 是源设备和目标设备位于同一 PAN 中的消息。

2.6 Inter-PAN Message

Inter-PAN Message 是源设备和目标设备位于不同 PAN 中的消息。

2.7 长地址

长地址(Long Address)是全局唯一的 64-bit 地址(EUI64)。每个 Silicon Labs Wireless Gecko 在出厂时都分配了一个 EUI64 地址。这在大多数 IEEE 802 协议中都是标准化的(如 IPv6 使用与 MAC 地址相同的 EUI64)。

2.8 短地址

短地址(Short Address)是仅在 PAN 中唯一的 16-bit 地址。因为 IEEE 802.15.4 具有一个相当短的帧,所以使用长地址将消耗大量帧。因此,如果设备知道 PAN ID 时,则可以使用短地址。0xFFFE 是一个保留的特殊地址,这意味着设备位于 PAN 中,但没有源地址(source address),因此应使用其长地址进行通信。

2.9 PAN ID

PAN ID 是一个标识 PAN 的 16-bit 长地址。没有分配 PAN ID 的标准化方法,因此应用程序应确保使用未在同一网络中使用的 PAN ID。

2.10 广播地址

广播地址(Broadcast Address)是一个任何设备都应接收的特殊地址。0xFFFF 短地址是广播短地址。0xFFFF PAN ID 是广播 PAN ID。

2.11 CSMA/CA

CSMA/CA(Carrier Sense Multiple Access with Collision Avoidance)是一个“listen-before-talk”协议:为了避免冲突,无线电在传输之前应先侦听信道。如果信道为“空闲(free)”(即未接收到任何内容),则设备可以发送。如果信道为“忙(busy)”(即接收到某些内容),则设备将等待,然后重试。重试一定次数后,传输将失败并且错误将报告给应用程序。

2.12 消息完整性检查

消息完整性检查(MIC,Message Integrity Check)用于数据认证:只有真正的发送者才能计算帧的 MIC。

3. 帧格式

IEEE 802.15.4 将帧(在 Silicon Labs Connect 中使用)中的每个字段都指定为最低有效位(LSB,Least Significant Bit)优先。

3.1 Physical Protocol Data Unit (PPDU)

Figure 3.1. Format of the PPDU

  • SHR: Synchronization Header
    • Preamble: Required for bit synchronization (clock recovery) on the receiver.
    • SFD: Start of Frame Delimiter (often called sync word)—required for byte synchronization on the receiver.
  • PHR: Physical Header
    • Frame Length: the length of the PSDU—because it is 7 bits, this limits the PSDU size to be a maximum of 127 bytes.

      IEEE 802.15.4-2015 defines a different, 16-bit PHR with an 11-bit length field. Silicon Labs Connect does not currently support this format.
  • PHY Payload
    • PSDU (Physical Service Data Unit): The payload of the PPDU.

3.2 MAC Protocol Data Unit (MPDU)

Figure 3.2. General MAC Frame Format

  • MHR: MAC Header
    • Frame Control Field (FCF): see Section 3.2.1 Frame Control Field.
    • Sequence Number: sequentially increasing number, used to pair ACK frames with normal frames.
    • Addressing fields: see Section.
    • Aux. Security header: see Section 3.3 MAC Security.
  • MAC payload: the payload of the Medium Access Control Protocol Data Unit (MPDU).
  • MFR (MAC footer): has a single field—Frame Check Sequence (FCS), which is a 2-byte Cyclic Redundancy Check (CRC) of the MHR and the payload.

3.2.1 Frame Control Field

Figure 3.3. Format of the Frame Control Field

  • Frame Type: Sets the frame type to one of these:
    • 0 – Beacon. used to advertise a PAN
    • 1 – Data. data used by an upper layer
    • 2 – Acknowledgement (ACK)
    • 3 – MAC Command which is the frame intended for the MAC layer (for example, part of the join process
  • Security Enabled: the Auxiliary Security Header is enabled when this bit is set to 1.
  • Frame Pending: used for data polling.
  • Acknowledgement Request (AR): frame should be ACKed by the receiver.
  • Addressing modes: As the table above shows, IEEE 802.15.4 frames are both source and destination addressed. However, both fields can be configured for various addressing modes:
    • 0 – no address. For example, both addresses are missing from ACK frames. For data and command frames only one (either source or destination) field can be omitted: If the source address is omitted, it means the PAN coordinator sent the frame. If the destination address is missing, it means it should be received by the PAN coordinator.
    • 2 – short address: The address field includes a short address and a PAN ID (total of 32 bits).
    • 3 – long address: The address field includes a long address and a PAN ID (total of 80 bits).
  • PAN ID Compression: If both source and destination addresses are present and the PAN ID is the same for both (intra-PAN message), this bit should be set and the source PAN ID should be omitted. This shortens the addressing fields for short-addressed intraPAN messages to 48 bits (one 16-bit source address, one 16-bit destination address, and one 16-bit PAN ID).
  • Frame Version: Selects the frame version for compatibility with other versions of IEEE 802.15.4.

3.3 MAC Security

IEEE 802.15.4 支持以下安全服务:

  • 数据机密性
  • 数据真实性
  • 重放攻击保护

Auxiliary Security Header 可以有各种安排,具体取决于可用的安全性和密钥设置。但是,对于 Silicon Labs Connect,启用安全性后:

  • 始终使用由应用程序设置的 128-bit 密钥(即没有 IEEE 802.15.4 key identifier field)。
  • 使用所有上述三个服务。

这意味着 Auxiliary Security Header 的长度为五个字节,如下图所示:

Figure 3.4. Format of the Auxiliary Security Header

Security Control 仅使用最低的三位,这用于选择安全模式(始终为 5)。

Frame Counter 是每个设备上用于启用重放保护的计数器:计数器是认证数据的一部分(即 MIC 是通过其计算的),并且接收方不应接受相同/较低的帧。即使设备重启,Frame Counter 也必须有效。

为了保证数据的可靠性,将在 MAC 有效负载(payload)的末尾(在 FCS 之前)添加一个 4-byte MIC。在 Silicon Labs Connect 支持的安全模式下,security header 和 footer 使用九个字节的 MAC 有效负载。

4. 一般的 802.15.4 MAC 过程

4.1 ACK 过程

如果设备发送设置了 ACK request bit 的数据或命令帧,则接收它的设备应以 ACK 帧作为响应。ACK 帧包括与其响应的帧的相同 sequence number。ACK 帧仅包含来自 MAC field 中的 FCF、sequence number 和 FCS,并且没有有效负载。这意味着 ACK 帧的 PSDU 为五个字节。

4.2 数据轮询过程

一台设备可以轮询来自另一台设备的消息。通常,End Device(不经常打开无线电功能)将轮询 Coordinator。此过程从 End Device 向 Coordinator 发送数据请求命令开始。Coordinator 以 ACK 作为响应,其中在 FCF 中设置了 frame pending bit。然后,End Device 必须打开无线电以等待 Coordinator 发送下一帧(或超时)。

4.3 关联过程

要加入网络,设备应经过关联(association)过程。在下表中描述了该过程,其中“E”(End Device)希望加入到“C”(PAN Coordinator)。所有命令帧都是 MAC 命令帧。

Step Direction Frame Type Source Address Destination Address PAN Addressing Other Fields
1 E → C Beacon request command broadcast broadcast destination
2 C → E Beacon short source specified Superframe specification1
3 E → C Association request command long short destination specified Capability information2
4 C → E Acknowledgement
5 E → C Data request command long short intra-pan
6 C → E Acknowledgement Frame pending bit set
7 C → E Association request command long short intra-pan Given short address and status3
8 E → C Acknowledgement
Notes:
  1. Superframe specification lets E know that C is a PAN coordinator and if it permits joining (among other things)\
  2. Capability info tells the coordinator how to handle the new device (for example, does it need a short address assigned to it, does it have the radio on when in idle, and so on.).
  3. The association response includes a status (that is, success or reason of failure) and the assigned short address. If a short address was not assigned, it is set to the special 0xfffe address. After association, E can communicate with its short address in the PAN. If E did not request a short address, it can still communicate within the PAN using its long address.