AES Advanced Encryption Standard
AF Application Framework
AFDE AF sub-layer Data Entity
AFME AF sub-layer Management Entity
API Application Programming Interface
APS Application Support sub-layer
BOS Basic Operating System
BPSK Bipolar Phase-Shift Keying
HCL Home Controls-Lighting
MAC Media Access Control
NWK Network layer
OEM Original Equipment Manufacturer
PAN Personal Area Network
PDU Protocol Data Unit
RF Radio Frequency
SAP Service Access Point
ZDO ZigBee Device Objects
ZDP ZigBee Device Profile（规约）
Profile：每一个ZigBee 的网络设备都应该使用一个Profile, Profile 定义了设备的应用场景，WSN)，另外定义了设备的类型还有设备之间的信息交换规范。以便不同的节点甚至是不同厂商生产的节点能够协作。
有两种profile，一种是stack profile，一种是application profile。
stack profile决定了zigbee stack为网络结构提供什么样的资源（resource）——比如网络类型，拓扑，以及与application相适应的特征（如安全类型）。
zigbee联盟已经制定了多个常见的stack profiles，应用在不同的场合如：Home Controls，Building
除此之外，用户可以自定义自己需要的私有应用程序规约（private application profile）
一个Application Profile 关联一个特定的stack profile，并制定一些application profile自己特定的应用。
Application Profiles可以分为Public Profiles和Private Profiles
Private Profiles (also known as ‘non-public’ profiles)
一个节点上的程序，它的结构可以认为分为3层次（level不是layer）：PHY/LINK level，zigbee stack level，application level。
application level和application layer是否是一个概念呢？文档没有说清楚。
2.网络层次概念（Network Level Concepts）
Router（允许子节点通过它加入网络） End Device（不能转发消息）。
The depth of a device is the number of nodes from the root of the network tree (the Co-ordinator) to the device. The maximum network depth is then the maximum number of hops to the most distant device in the network from the Co-ordinator. This is set at configuration time and determines the overall diameter for the network. Note that a Star network has a network depth of 1.
router子节点（Number of Children）
Each Router in the network can have a number of child devices attached to it. These may be either Routers or End Devices. The Co-ordinator specifies the number of child devices allowed per Router, and how many of these child devices can be Routers.
网络短地址分配（Network Address Allocation）
Network addresses are allocated during initialisation of the network. The Co-ordinator allocates each child Router a block of consecutive addresses to allocate to its children. These address blocks provide each Router with enough addresses to allocate to all of its potential children, as defined by the maximum routers, maximum children and maximum depth parameters. In turn, the block of addresses given to a Router will be subdivided amongst its child Routers and so on down the tree. Since the topology of a deployed network is not necessarily uniform (as many nodes may be needed in one geographic area and relatively fewer in another), it is possible for one Router to have all of its allocated addresses in use while those on another may be unused.（网络初始化的时候，coordinator会进行短地址分配，根据每个router子节点个数的最大值，分配给router一段地址，供它分配给其子节点。）
The new node first scans the available channels to find operating networks and identifies which one it should join. Multiple networks may operate in the same channel and are differentiated by their PAN IDs.（一个节点周围有多个PAN时该选择哪个？）
The node may be able to ‘see’ multiple Routers and a Co-ordinator from the same network, in which case it selects which one it should connect to. Usually, this is the one with the best signal.（一个节点周围既有coordinator又有router时通常根据信号的好坏选择跟谁建立连接）
The node then sends a message to the Router asking to join the network.（节点请求加入网络）
The Router decides whether the node is a permitted device, whether the Router is currently allowing devices to join and whether it has address space available. If all these criteria are satisfied, the Router will then allow the device to join and allocate it an address.（router考察能否让节点加入网络）
一个Stack Profiles规定了网络的depth，网络拓扑，子节点个数等。zigbee联盟已经针对特定应用定义了一些stack profile。对于一些特定的应用中，标准stack profile不适用，这是stack参数由设计者指定。
注意：对于节点上的应用程序来说，并不知道要传递的消息和消息的内容，转发机制（relaying mechanism）是由zigbee stack管理的（除非是在路由发现的情况下）。
ZigBee stack network layer支持路由发现（route discovery），通过路由发现网络可以找到到达目标节点的最佳路由，路由发现有三种选择：
SUPPRESS route discovery（禁止路由发现）: The message is routed along the tree.只是简单的将消息沿着树传播。
ENABLE route discovery: 消息会沿着已经被发现的路由传播，如果不存在这样的路由，Router就开始一次新的路由发现。找到合适的路由之后就沿着路由传播消息。如果Router没有空间存储新路由时，就沿着树传播消息。The message is routed along an already discovered mesh route, if one exists, otherwise the Router initiates a route discovery. Once this is complete, the message will be sent along the calculated route. If the Router does not have the capacity to store the new route, it will direct the message along the tree.
FORCE route discovery:这个选择要谨慎，因为它会大大增加网络业务。 If the Router has the route capacity, it will initiate a route discovery, even if a known route already exists. Once this is complete, the message will be sent along the calculated route. If the Router does not have the route capacity, it will route the message along the tree. This option should be used sparingly, as it generates a great deal of network traffic.
• A route discovery broadcast is sent by the parent Router of the source End Device, containing the target destination End Device network address.
• All routers will eventually receive the broadcast, one of which is the parent of the destination End Device
• The parent Router of the destination node sends back a reply addressed to the parent router of the source.
• As the reply travels back through the network, the hop count and a signal quality measure for each hop are recorded. Each Router in the path can build a routing table entry containing the best path to the destination End Device
The choice of best path is usually the one with the least number of hops, although if a hop on the most direct route has a poor signal quality (and hence a greater chance that retries will be needed), a route with more hops may be chosen.
• Eventually each Router in the path will have a routing table entry and the route from source to destination End Device is established. Note that the corresponding route from destination to source is not known – the route discovered is unidirectional.
通常情况下路由对于应用程序是透明的，但是在mesh网络拓扑中，当节点要发送信息时，如果没有可用的路由，在发消息之前，在 Co-ordinator or Router的application level（我怀疑只是调用stack里的函数进行初始化，而真正的路由发现机制的程序代码是无法修改的，或者说想添加自己的DTN转发机制是很难得，就我目前的理解来看）会初始化并完成路由发现。我的理解是，mesh网络中如果没有可用路由，而是任信息在网络中转发的话，由于router很多，会造成网络业务增加，相比之下，有一条路由更可靠，而移动DTN就像一个router之间时而连接时而断开的mesh网络，用路由发现的方法寻找消息传播最佳路径是不可能的，使用路由转发机制才靠谱，但问题是，jennic是够给予我们增加转发机制的API。Message routing is normally performed automatically by the ZigBee stack, without any intervention from the applications running on the Router or Co-ordinator. Therefore, routing is usually, but not always, transparent to the applications.
Routing is not transparent in a Mesh topology when a direct or indirect message is sent to a destination address for which a route has not already been discovered (and route discovery is active). In this case, the Co-ordinator or Router must initiate and complete a route discovery (at application level) before sending the message.
3.应用程序层次概念（Application Level Concepts）
1）多应用程序和端点（Multiple Applications and Endpoints）
一个节点可以有多个应用程序运行，比如监测温度和监测湿度的两个应用程序，然后每个应用程序对应一个端点，类似套接字里的端口。Endpoint addresses for user applications are numbered from 1 to 240.Endpoint 255 is the broadcast endpoint address; the same data can be sent to all applications on a node by sending the message to that address.所以两个节点的程序通信的时候，一个节点不仅要知道dest节点的地址，还要知道那个程序对应的endpoint。
The ZigBee Alliance has defined a number of standard profiles for ZigBee devices. A profile relates to a particular application and/or market and contains descriptions of the types of devices and interfaces which are needed for that particular application.
Within each Application Profile, a number of Device Descriptions are defined, describing the types of devices the profile supports.在Application Profile里描述了特定应用中会用到的节点上的设备（如开关，led，一些控制器。节点上的device很多，在某一个应用中不是所有的devices都会用的上），每个设备在Application Profile里对应一个device ID。
As well as defining the devices types supported, the profile also specifies the information that a device can generate as output and can use as input, together with the format this information takes. The individual pieces of information are called attributes, and their possible values and format or type (e.g. 8- or 16-bit integer, time value etc) are defined as part of the Device Descriptions in the profile. Attributes aregrouped together into “clusters” for the device, which can be either inputs or outputs. Clusters and attributes are described in detail below.
A given ZigBee device profile has associated “attributes” and “clusters” which define the type of data that a device with this profile may exchange with other ZigBee devices.
Each data item that passes between devices of a ZigBee network is called an attribute. Each attribute has its own unique identifier. For example, a switch device can have an attribute with identifier OnOff whose value represents the action to be performed: On (0xFF), Off (0x00), Toggle (0xF0).
A number of attributes are grouped into a “cluster”, where each cluster has its own unique identifier. For example, for an HCL Switch Remote Control (SRC) device, there is a cluster with identifier OnOffSRC containing the attribute OnOff. Clusters may be mandatory or optional for a device to support.
A cluster may contain several attributes.A profile can have several associated clusters.
The Application Profile defines which clusters are mandatory（强制的） and which clusters are optional for the device. The clusters supported by a device determine the other devices with which it can communicate.比如，温度传感器读取得clusters和温度控制的clusters的格式应该是兼容的（compatible）。
zigbee specification是设备容易了解网络中其他节点的能力（capacity），如他们的地址（MAC地址或短地址）点上运行的应用程序类型，他们的供电，休眠行为。这些信息存储在节点的Descriptors中，查询节点（enquiring node ）用它来调整自己的行为来适应网络的需要。（ This information is stored in descriptors (see below) on each node, and is used by the enquiring node to tailor its behaviour to the requirements of the network.） Discovery的典型应用是在被介绍进一个用户定义网络（如一个安全或者灯控制系统）中时使用。为了让节点加入网络，用户可能需要按某个按钮，打开某个开关等行为；首先节点需要找到是否有合适的节点进行对话。比如在HCL（灯控制系统）中，一个节点要适应HCL profile，它需要尝试找到一个controller节点——好把自己的开关状态信息发送过去。 （For a device implementing the switch conforming to the HCL profile, it tries to find devices containing HCL load controllers to which it would make sense to send its switch state information.）
Device Discovery returns information about the addresses of a network node. The retrieved information返回信息 can be the MAC (IEEE) address of the node with a given network address, or the network address of a node with a given MAC address.对于router和coordinator除了返回自己的地址之外，还会有选择的返回与之相关的节点的地址。. In this way, it is possible to discover all the devices in a network by requesting this information from the Co-ordinator (network address 0) and then using the list of addresses corresponding to the children of the Co-ordinator to launch other queries about their child nodes.
Service Discovery allows a node to request information from a remote node about the remote node’s capabilities. This information is stored in a number of descriptors (see below) on the remote node, and includes:
• The device type and capabilities of the node
• The power characteristics of the node
• Information about each application running on the node
• Optional information such as serial numbers
• Other user-defined information; for example, easily understandable names such as “MtgRoomLight”.
Requests for these descriptors are made by a device as part of the discovery process that is typically part of the device’s configuration and integration into a ZigBee network.
节点中存储了3个强制的描述（descriptors ）和两个可选择的描述。其中3个强制描述是Node, Node Power and Simple descriptors。可选择的两个描述是the Complex and User descriptors 。
For each node, there is only one Node and Node Power descriptor. For each application running on an endpoint, there is a Simple descriptor and there may also be Complex and User descriptors in the device.
The Node, Power Node and Simple descriptors are outlined below. For full details of descriptors, refer to the ZigBee Application Framework API Reference Manual（在这里我不得不抱怨一下，jennic的中文参考资料少的可怜，只能读英文手册，蛋疼无比）.
The Node descriptor contains information on the capabilities of the node, including:
• Type (End Device, Router or Co-ordinator)
• Frequency band in use (868 MHz, 902 MHz or 2400 MHz)
• MAC capabilities – that is, whether:
�� the device can be a PAN Co-ordinator
�� the node implements a Full-Function or Reduced-Function IEEE 802.15.4 device
�� the device is mains powered
�� the device is capable of using MAC security
�� the receiver stays on during idle periods
• Manufacturer code
• Maximum buffer size (the largest data packet that can be sent by an application in one operation)
Node Power Descriptor
This Node Power descriptor contains information on how the node is powered:
• Power mode – whether the device receiver is on all the time, wakes up periodically as determined by the network or only when an application requires (e.g. button press or period measurement)
• Available power sources – indicates whether mains, rechargeable or disposable batteries (or any combination) can be used to power the device
• Current power sources - indicates which power source (from mains, rechargeable or disposable batteries) is currently being used to power the device
• Current power source level – indicates the level of charge of the current power source
The Simple descriptor for an application includes:
• The endpoint in the device that the application resides on
• The Application Profile that it implements
• The Application Profile device identifier and version
• Whether there are corresponding Complex and User descriptors
• Lists of input and output clusters (see Section 2.3.3) that the application uses and provides, respectively
6）ZDO（ZigBee Device Objects）
ZDO是一个应用程序，管理各种被描述过的进程（processes），它在应用层，对应end point 0，扮演一下角色。
• Defines the type of network device: Co-ordinator, Router or End Device.
• Initialises the node to allow applications to be run
• Performs the Device and Service Discovery process
• Implements the processes needed to allow a Co-ordinator to create a network, and Routers and End Devices to join and leave a network
• Initiates and responds to binding requests (see Section 2.4.2)
• Provides security services which allow secure relationships to be established between applications
• Allows remote nodes to retrieve information from the node, such as routing and binding tables, and to perform remote management of the node, such as instructing it to leave the network。
ZDO功能的实现是基于stack提供的服务，ZDO通过zigbee device profile和cluster mechanism（应用程序之间用来进行交互）种方式使得用户程序可以使用（access）stack服务。
The Service Discovery and Binding mechanisms are described in the subsections below.
The above diagram shows (from bottom to top):
Physical/Data Link Level
This consists of the IEEE 802.15.4 PHY and MAC layers, described in Section 2.1.
ZigBee Stack Level
• Network (NWK) layer: The NWK layer handles network addressing and routing by invoking actions in the MAC layer. Its tasks include:
�� Starting the network and assigning network addresses (Co-ordinator only)
�� Adding devices to and removing them from the network
�� Routing messages to their intended destinations
�� Applying security to outgoing messages
�� Implementing Route Discovery in Mesh topologies and storing routing table information
• Security plane: If implemented (not available in the Jennic ZigBee stack), this plane spans the NWK and APS layers (see below), and provides security services; for example, security key management, datastream encryption and decryption. It may use hardware functions provided in the node to perform the encode and decode functions efficiently.
• Applications: Up to 240 application instances are supported on a single ZigBee node. Each application instance is a network endpoint and is numbered between 1 and 240 (note that endpoint 0 is reserved for the ZigBee Device Objects of the node).
• Application Framework (AF): The AF facilitates interaction between the applications and the APS layer (see below) through an interface known as a Service Access Point or SAP (see Section 2.5.2). All application instances are contained inside this framework.（是否可以理解为，AF由一系列SAP构成）
plication Support sub-layer (APS): The APS layer is responsible for:
�� Communicating with the relevant application; for example, when a message arrives to illuminate an LED, the APS layer relays this instruction to the responsible application using the endpoint information in the message. The message is passed through the Service Access Point which exists between the APS layer and each application (endpoint).
�� Maintaining binding tables (see Section 2.4.2) and sending messages between bound nodes.
• ZigBee Device Objects (ZDO): The ZDO represents the ZigBee node type of the device (Co-ordinator, Router or End Device) and has a number of communication roles. The ZDO is an endpoint, numbered 0. For more information, refer to Section 2.3.6.
• ZDO Management plane: This plane spans the NWK and APS layers, and allows the ZigBee Device Objects (ZDO) to communicate with these layers when performing its internal tasks. It also allows the ZDO to deal with requests from applications for network access and security functions using ZigBee Device Profile messages.
2）ervice Access Points
A Service Access Point or SAP implements a set of operations to pass information and commands between layers. There are usually four types of operation implemented by a SAP:
• Request: Typically, a layer using the services of another layer generates a Request to the lower layer.
• Confirm: In general, the lower layer responds with a Confirm, which indicates whether it has accepted or rejected the request. A rejection could occur if the Request is invalid or the layer does not implement the operation concerned (the operation could be defined as optional).
• Response: Normally, Requests result in some sort of Response from the lower layer. This may be a simple status message indicating that the Request has been performed, or may contain further information that the Request has asked for. Responses can be immediate or delayed:
�� Synchronous Response: Responses may be generated immediately after the Request has been issued; for instance, if the information or command is available on the local node.
�� Asynchronous Response: A Request may require messages to be sent over the network to a remote node, in which case there will be a delay between issuing the Request and the arrival of the Response.
The SAP mechanism allows both types of Response to be handled and delivered to the higher layer.
• Indication: An Indication is generated when the lower layer has unsolicited（主动提供的） information or commands to be delivered to the higher layer, possibly as a result of a Request for information local to the node from a remote node.如当底层接到远端节点发来的请求时会向上层主动提供信息。