1、The APL Layer The application (APL) layer is the highest protocol layer in a ZigBee wireless network. The ZigBee APL layer consists of three sections, shown in Figure 3.44 : the application support (APS) sublayer, ZigBee Device Objects (ZDO), and the application framework. The application support su
2、blayer (APS) provides an interface between the network layer (NWK) and the application layer (APL). The APS sublayer, similar to all lower layers, supports two types of services: data and management. The APS data service is provided by APS Data Entity (APSDE) and is accessed through the APSDE Servic
3、e Access Point (SAP). The management capabilities are offered by APS Management Entity (APSME) and are accessed through APSME-SAP. The APS sublayer constants and attributes start with apsc and aps , respectively. The APS attributes are contained in the APS Information Base (APS IB or AIB). The list
4、of APS constants and attributes is provided in the ZigBee specification 3. Network The application framework in ZigBee is the environment in which application objects are hosted to control and manage the protocol layers in a ZigBee device. Application objects are developed by manufacturers, and that
5、 is where a device is customized for various applications. There can be up to 240 application objects in a single device. The application objects use APSDE-SAP to send and receive data between peer application objects ( Figure 3.44 ). Each application object has a unique endpoint address (endpoint 1
6、 to endpoint 240). The endpoint address of zero is used for the ZDO. To broadcast a message to all application objects, the endpoint address is set to 255. Endpoint addressing allows multiple devices to share the same radio. In the light control example in Section 2.1.4, multiple lights were connect
7、ed to a single radio. Each light has a unique endpoint address and can be turned on and off independently. The ZigBee Device Objects (ZDO) provide an interface between the APS sublayer and the application framework. The ZDO contains the functionalities that are common in all applications operating o
8、n a ZigBee protocol stack. For example, it is the responsibility of the ZDO to configure the device in one of three possible logical types of ZigBee coordinator, ZigBee router, or ZigBee end device. The ZDO uses primitives to perform its duties and accesses the APS sublayer Management Entity via APS
9、ME-SAP. The application framework interacts with the ZDO through the ZDO public interface. The details of application framework, ZDO, and APS sublayer are reviewed in the following three subsections. The Application Framework The ZigBee standard offers the option to use application profiles in devel
10、oping an application. The use of an application profile allows further interoperability between the products developed by different vendors for a specific application. For instance, in a light control scenario, if two vendors use the same application profile to develop their products, the switches f
11、rom one vendor will be able to turn on and turn off the lights manufactured by the other vendor. The application profiles are also referred to as ZigBee profiles. Each application profile is identified by a 16-bit value known as a profile identifier . Only the ZigBee alliance can issue profile ident
12、ifiers. A vendor that has developed a profile can request a profile identifier from the ZigBee alliance. The ZigBee alliance evaluates the proposed application profile and if it meets the alliance guidelines, a profile identifier will be issued. The application profiles are named after their corresp
13、onding application use. For example, the home automation application profile provides a common platform for vendors developing ZigBee-based products for home automation use. The general structure of an application profile is shown in Figure 3.45. The application profile consists of two main componen
14、ts: clusters and device descriptions. A cluster is a set of attributes grouped together. Each cluster is identified by a unique 16-bit number called a cluster identifier . Each attribute in a cluster is also identified by a unique 16bit number known as a attribute identifier . These attributes are u
15、sed to store data or state values. For example, in a temperature control application, a device that acts as the temperature sensor can store the value of the current temperature in an attribute. Then another device that acts as the furnace controller can receive the value of this attribute and turn
16、on or turn off the furnace accordingly. The application profile does not contain the cluster itself. Instead, the application profile has a list of the cluster identifiers. Each cluster identifier uniquely points to the cluster itself. The other part of an application profile is the device descripti
17、ons ( Figure 3.45 ). The descriptions provide information regarding the device itself. For example, the supported frequency bands of operation, the logical type of the device (coordinator, router, or end device), and the remaining energy of the battery are provided by the device descriptions. Each d
18、evice description is identified by a 16-bit value. The ZigBee application profile uses the concept of descriptor data structure . In this method, instead of including the data in the application profile, a 16-bit value is kept and acts as a pointer to the location of the data. This pointer is referr
19、ed to as the data descriptor . When a device discovers the presence of another device in the network, the device descriptions are transferred to provide the essential information regarding the new device. The device descriptions consist of five sections: node descriptor, node power descriptor, simpl
20、e descriptor, complex descriptor, and user descriptor. The node descriptor provides information such as the node logical type and the manufacturer code. The node power descriptor determines whether the device is battery powered and provides the current level of the battery. The profile identifier an
21、d clusters are provided in the simple descriptor . The complex descriptor is an optional part of the device descriptions and contains information such as the serial number and the device model name. Any additional information regarding the device can be included as the user descriptor . The user des
22、criptor can be up to 16 ASCII characters. For example, in a light control application, the user descriptor field of a wall switch installed in a hallway can read Hall switch . The node descriptor fields for ZigBee-2006 are provided in Figure 3.46 . The node descriptor is a mandatory part of the devi
23、ce descriptions. The logical type can be ZigBee coordinator, router, or end device. The complex descriptor and user descriptor are optional and if their corresponding fields in the node descriptor are set to zero, they are not provided as part of the device descriptions. The APS flag field determine
24、s the APS sublayer capabilities. The frequency band (868 MHz, 915MHz, or 2.4 GHz) is specified in the frequency band field. The MAC capacity flags field is the same as the MAC capacity field presented before in Figure 3.25 . A manufacturer can request and receive a manufacturer code from the ZigBee
25、alliance. This code is included in the node descriptor. The maximum size of the APS Sublayer Data Unit (ASDU), in octets, is specified in the maximum buffer size field. The maximum size of a single message that can be transferred to or from a node is provided in the maximum transfer size field (in o
26、ctets). In ZigBeePro, the maximum incoming transfer size and maximum outgoing transfer size are two separate fields (16 bits each). The server mask field provides information regarding the system server capabilities of this node. A server is a device that provides specific services to other devices
27、in the network. If each bit is set to one, the device has the corresponding capability shown in Figure 3.46 . The trust center is the device trusted by devices within a network to distribute security keys for the purpose of network and end-to-end application configuration management. The security fe
28、atures are reviewed in Section 3.6. The primary binding table cache is a device that allows other devices to store their binding tables with it as long as it has storage space left. The binding procedure is further clarified in this subsection. The primary binding table cache can be used to back up
29、the content of binding tables and restore them whenever necessary. A device can choose to keep its own binding table, known as a source binding table , instead of storing it with a primary binding table cache. However, any device can store a backup of the source binding table in the primary biding t
30、able cache device and recover it later if necessary. A ZigBee network may have a primary discovery cache device. This device is a ZigBee coordinator or router used to store the descriptors such as node descriptors and power descriptors of some other devices. An end device, for example, that sleeps f
31、or long durations can store its descriptors in the primary discovery cache device. If a device in the network tries to locate the information regarding this sleeping end device while the device is inactive, it can get the information from the primary discovery cache device instead. If a network cont
32、ains sleeping ZigBee end devices, the network must have at least one primary discovery cache device. 应用层(APL)是在 ZigBee 无线网络协议栈中最高的一层。应用层包含三个组成部分,见下图 3.44:应用支持子层(APS ), ZigBee 设备对象(ZDO),以及应用层框架( AF)。应用支持子层(APS)提供了网络层( NWK)和应用层(APL )之间的接口。该层和所有较低层相似,支持两种服务:数据和管理服务。APS 层数据服务由 APS 数据实体( APSDE)通过 APSDE 服
33、务接入点(APSDE-SAP)提供。管理功能由 APS 管理实体(APSME)通过 APSME 服务接入点(APSME-SAP)提供。APS 子层的常量和属性分别始于 apsc 和 aps。APS 属性包含在 APS 信息库(APS IB 或 AIB)中。APS 常量和属性列表由 ZigBee 协议栈规范提供3。ZigBee 应用层框架(AF)是为驻扎在 ZigBee 设备中的应用对象控制和管理协议栈各层提供活动的环境。应用对象由制造商开发,也正是在这里定制了基于各种不同应用的设备。在一个设备中可以有多达 240 个应用对象。应用对象使用 APSDE-SAP 在应用对象节点之间发送和接收数据(
34、图 3.44)。每个应用对象都有一个专有的终端节点地址(端点 1端点 240)。端点 0 用于 ZDO。端点地址 255 被设置用来广播消息到所有的应用对象。设定终端地址允许多个设备共享同一频段。在 2.1.4 节的灯控制例程中,多个灯连接在同一个频段里。每个灯都有一个专用的端点地址,并且能够独立的打开或关闭。ZigBee 设备对象(ZDO)提供了 APS 子层和应用层框架(AF)之间的接口。ZDO 包含了所有运行在 ZigBee 协议栈上的应用所共有的功能。例如,定义设备属于 ZigBee 协调器、路由器或终端设备三种逻辑类型之一就是 ZDO 的职责。ZDO 使用原语来执行它的任务,并通过
35、APSME-SAP 进入APS 子层管理实体。应用层框架(AF)通过 ZDO 公共接口与 ZDO 相互作用。关于应用层框架(AF)、ZDO 和 APS 子层的细节的详细回顾见于以下三节。3.5.1 应用层框架(AF)ZigBee 标准提供了在开发应用时使用应用 profiles 的选项。应用 profiles 的使用使得不同开发商开发的基于某种特定应用的产品之间有更多的共同使用性。比如,在灯控制情景中,如果两个开发商使用同一个应用 profiles 来开发他们的产品,一个开发商制造的开关将能够打开或关闭另一个开发商制造的灯。应用 profiles 也是基于 ZigBee profiles 的。
36、每个应用 profiles 都由一个被称作 profile 标识符的 16 位数值所标记的。只有 ZigBee 联盟能够设定 profile 标识符。开发商如果自行开发了一个 profile,他可以向 ZigBee 申请一个 profile 标识符。ZigBee 联盟评估被提议的应用 profile,如果其符合联盟准则,一个新的 profile 标识符就会被设定。应用 profiles 以与其相应的应用来命名。例如,家庭自动化应用 profile 提供一个公共平台给开发用于家庭自动化的基于 ZigBee 产品的开发商们。应用 profile 的总体结构见图 3.45。应用 profile 包含
37、两个主要组成部分:簇(clusters )和设备描述(device descriptions)。簇是一组整合在一起的属性。每个簇都由称为簇标识符(cluster identifier)的唯一 16 位数字所标记。簇中的每个属性也由称作属性标识符(attribute identifier)的唯一 16 位数字所标记。这些属性用来存储数据或状态值。例如,在温度控制应用中,作为温度传感器的设备能在属性中存储当前温度数值。然后另一个作为火炉控制器的设备就能接受该属性值,并据此打开或关闭火炉。应用 profile 不包含簇本身,而是包含一个簇标识符列表。每个簇标识符都专一地指向该簇本身。应用 profi
38、le 的另一个部分是设备描述(device descriptions)(图 3.45)。设备描述提供关于设备自身的信息。例如,可供使用的频率波段,设备的逻辑类型(协调器、路由器或终端设备),以及设备提供的剩余电量,都是由设备描述所提供的。每个设备描述由一个 16 位数值所标记。ZigBee 应用 profile 使用描述数据结构(descriptor data structure)这一概念。正是用这一取代了包含应用 profile 数据的方法,一个 16 位数值作为指向数据所在地址的指针而被保存。该指针称为数据描述指针。当一个设备发现网络中另一个设备的出现时,设备描述就会被传送以提供关于该新设
39、备的基本信息。设备描述由 5 个部分组成:节点描述(node descriptor),节点电源描述(node power descriptor),简单描述(simple descriptor),复杂描述(complex descriptor)和用户描述(user descriptor)。节点描述提供诸如节点逻辑类型和制造商编码这类信息。节点电源描述决定了设备是否由电池供电,并提供当前电量。Profile 标识符和簇由简单描述提供。复杂描述是设备描述的可选部分,它包含诸如序列号和设备模型名称之类的信息。任何关于设备的附加信息都可以被用户描述所包含。用户描述可以多达 16 位 ASCII 码。例如
40、,在灯控制应用中,安装在过道的墙上开关的用户描述区域就被读作“过道开关(Hall switch)”。ZigBee-2006 的节点描述区域见图 3.46。节点描述是设备描述的命令部分。逻辑类型可能是协调器、路由器或终端设备。复杂描述和用户描述是可选项,如果它们在节点描述中的相应区域被设为 0,则不会作为设备描述的组成部分而被提供。APS 标志区域决定了 APS 子层的功能。频段(868MHz, 915MHz, 或 2.4 GHz) 在频段区域中被指定。MAC 功能标志和之前在图 3.25 中显示的 MAC 功能区域一样。制造商可以向 ZigBee 联盟申请并获得一个制造商编码。该编码包含在节点
41、描述中。8 进制的 APS 子层数据单元( APSDU)长度极大值在长度极大值缓存区域中被指定。送往或来自节点的单个消息的长度极大值由传送极大值区域提供(8 进制)。在 ZigBee-Pro 版本中,传送输入长度极大值和传送输出长度极大值是分离的两个区域(每个 16 位)。服务器掩码区域提供关于该节点系统服务功能的信息。服务器(server)是为网络中其它设备提供特定服务的设备。如果每一位都被置位为 1,设备就拥有如图 3.46 所示的相关功能。信托中心(trust center)被网络中的所有设备所信任,并为网络的用途和终端-终端应用结构管理分配安全密钥。安全特征见于 3.6 节。初始绑定表
42、缓存设备只要还有存储空间剩余,就允许其它设备使用该设备来存储它们的绑定表。绑定过程在这一子区域中被进一步阐明。初始绑定表缓存能用来备份绑定表目录,并能在任何必要的时候加以存储。一个设备可以选择保存被称为源绑定表的自身绑定表,而不储存初始绑定表缓存。然而,任何设备都能在初始绑定表缓存设备中存储源绑定表的备份,并且能在必要的情况下予以恢复。一个 ZigBee 网络也许会有一个初始发现表缓存设备。该设备是 ZigBee 协调器或路由器,其被用以储存诸如其它设备的节点描述和电源描述之类的各种描述。像长时间休眠这样的终端设备可以在初始发现缓存中储存它的描述。如果网络中的某设备尝试找到此正处于不活动状态的休眠终端设备的相关信息,它可以从初始发现缓存设备获得此信息以作替代。如果一个网络包含休眠中的 ZigBee终端设备,则其必须拥有至少一个初始发现缓存设备。