z-stack home 1.2.2a 父节点收到入网请求与密匙分配过程代码分析与白名单实现方法

1 概述

        本文将分析z-stack协议栈设备加入安全使能网络时的相关代码,采用集中式安全的网络,从mac连接成功到密匙分配或收到密匙的过程,包含父节点和子节点(加网设备)。设备搜网过程不在本文讨论范围内,这方面的可参阅TI 中文社区的一篇分享贴:

        点击打开链接

        该分析基于z-stack home 1.2.2a 协议栈,也适用于较早的协议版本与z-stack3.0,但是在z-stack3.0中增加一层对新设备Link key验证的机制,未进行验证的新设备默认会在15秒后被移除。验证link key的目的在于,防止link key不一致导致的新设备收到无法解析的网络密匙后离网,而信任中心确认为新设备已经入网的现象出现。这块内容本文不详细阐述,相关函数为bdb_TCAddJoiningDevice、bdb_TCProcessJoiningList、bdb_TCjoiningDeviceComplete、APSME_ConfirmKeyReq、APSME_VerifyKeyReq,读者可自行分析。

2 父节点处理过程

        在一个新设备在mac连接成功并获得地址后,父节点网络层会回调ZDO_JoinIndicationCB告诉zdo新设备的短地址、mac地址与设备类型(全功能设备or半功能设备),回调前新设备信息已经添加到关联表AssociatedDevList与地址管理表(地址映射表)。

2.1  ZDO_JoinIndicationCB 中

        a 延时6.5s设置ZDO_NWK_UPDATE_NV事件,用于处理完新设备后保存nv

        b 将新设备的短地址信息加入单链表ZDApp_NewDeviceList中,并设置一个600ms延时事件ZDO_NEW_DEVICE。

2.2 在ZDO_NEW_DEVICE事件中

        a 调用ZDSecMgrNewDeviceEvent 处理新设备事件

        b 释放链表节点并延时启动下一次ZDO_NEW_DEVICE事件,确保事件执行时在新设备mac层入网成功600ms后

2.3 ZDSecMgrNewDeviceEvent 函数

        a 如果是预配置网络密匙模式则直接标记设备状态为已认证:authenticated

        b 构建ZDSecMgrDevice_t实例device,对于新设备device.secure = FALSE,表示未经验证

        b 传递device给 ZDSecMgrDeviceNew 处理新设备

        c 如果ZDSecMgrDeviceNew 返回失败则将其从关联表与地址管理表中清除。

2.4 ZDSecMgrDeviceNew 函数: 

        a 如果自己是协调器或者是分布式安全网络(作者没研究)则调用ZDSecMgrDeviceJoinDirect

         b 否则(自己是路由器节点)调用ZDSecMgrDeviceJoinFwd(2.7节)

2.5 ZDSecMgrDeviceJoinDirect 函数

        a 直接调用 ZDSecMgrDeviceJoin 处理直接设备加入

        b 如果ZDSecMgrDeviceJoin 成功,将设备标记为已认证

2.6 ZDSecMgrDeviceJoin 函数:(加到路由器的设备会通过aps层UpdateDevice命令调用到该函数)

        a 调用 ZDSecMgrDeviceValidate 验证新设备能否加入网络,白名单功能可修改该函数实现,返回成功设备才能入网

        b 验证通过调用ZDSecMgrSendNwkKey发送网络密匙给新的设备:直接发送或通过aps层隧道tunnel发送

        c 验证不通过或密匙发送失败则将新设备移除:移除自身子节点或通过aps层RemoveDevice命令告诉路由器移除其子节点

2.7 ZDSecMgrDeviceJoinFwd函数

        a 通过aps层UpdateDevice将新设备信息发送到信任中心验证是否入网

2.8 路由节点附加描述

        新设备加到路由器节点会通过UpdateDevice发送到信任中心验证是否入网,信任中心通过tunnel:TransportKey命令告诉路由器新设备可入网,或者通过RemoveDevice告诉路由器不允许新设备入网。

3 子节点处理过程

        新设备在mac连接成功并获得地址后,网络层会回调ZDO_JoinConfirmCB告诉zdo。

3.1 ZDO_JoinConfirmCB 函数

        a 清除邻居表

        b ZDO_NWK_UPDATE_NV,用于处理完入网过程后保存nv

        c 发送任务消息ZDO_NWK_JOIN_IND到zdo任务,在ZDO_NWK_JOIN_IND消息中调用ZDApp_ProcessNetworkJoin

3.2 ZDApp_ProcessNetworkJoin 函数

        a 将设备标记为等待验证状态

        b 启动验证超时定时器,默认为MAX_DEVICE_UNAUTH_TIMEOUT毫秒,这个时间可自己修改,建议3~5秒。这个时间内如果未收到TransportKey消息设备将重新搜网。

3.3 收到密匙调用 ZDSecMgrTransportKeyInd( ZDO_TransportKeyInd_t* ind )

          a 更新网络密匙SSP_UpdateNwkKey

          b 调用ZDSecMgrAuthNwkKey设置ZDO_DEVICE_AUTH 事件以更改设备状态为已认证


转载请注明出处:https://blog.csdn.net/jason_lm/article/details/80950479

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Z-Stack 3.0.x is TI's Zigbee 3.0 compliant protocol suite for the CC2530, CC2531, and CC2538 Wireless MCU. Supports the CC2592 and CC2590 RF front ends which extend up to +22dBm and +14dBm transmit power, respectively, and provide improved receiver sensitivity Z-Stack 3.0 combines multiple previous Zigbee profiles into one unified standard Incorporates the unified Zigbee Cluster Library which is at the foundation of dotdot, the universal language for IoT applications defining data objects, models and functionalities for embedded IoT applications Implements Zigbee Base Device Behavior specification, which defines a common set of mechanisms for network forming, discovering, and application provisioning to be used by all Zigbee devices Based on Zigbee PRO 2015 stack, it provides new and improved security modes, including Install Codes for out-of-band key exchange, and Distributed Security Networks for Coordinator-less network topology Supports Green Power Proxy, allowing energy-harvesting and ultra-low power devices to connect seamlessly to a Zigbee network Forwards and backwards compatibility with previous Zigbee PRO and application profiles is maintained Sample Applications included for quick prototyping, including door lock, thermostat, light and switch, and temperature sensor Zigbee Network Processor firmware, providing an abstracted access to the Zigbee Pro 2015 stack and Base Device Behavior functionality via a serial port for two-chip architectures Zigbee-based applications Over-the-air firmware upgrade and serial bootloader capability, allowing for future updates of deployed systems Compatible with TI's Z-Stack Linux Gateway, a reference implementation of an Ethernet-to-Zigbee gateway using a Linux-based platform as host processor, that makes it easy to integrate applications on top of an IP-based interface which abstracts Zigbee protocol functionality to the users.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值