zigbee实现网络加入过滤(相当于白名单)
来源:互联网 发布:mac 隐藏磁盘 编辑:程序博客网 时间:2024/04/28 19:25
1,在app.h文件中
#if ZG_BUILD_COORDINATOR_TYPE#define WHITE_LIST_MAX_SIZE 2 //最大缓存数typedef struct { uint8 macAddress[8];//macAddress uint8 isAllow;//1 allow,0 reject }WhiteNode; typedef struct { WhiteNode *node[WHITE_LIST_MAX_SIZE]; int8 currentIndex;}WhiteList;extern WhiteList *whiteList;#endif
#if ZG_BUILD_COORDINATOR_TYPEWhiteList *whiteList;#endif
然后在对应的init方法中对数据结构初始化
#if ZG_BUILD_COORDINATOR_TYPE whiteList->currentIndex = -1; uint8 *myMac = NLME_GetExtAddr();//先用自己的mac地址随便初始一下 for(int i=0;i<WHITE_LIST_MAX_SIZE;i++) { WhiteNode *node = (WhiteNode *)osal_mem_alloc(sizeof( WhiteNode)); osal_memcpy(node->macAddress,myMac,8); node->isAllow = 0; whiteList->node[i] = node; }#endif
#if ZG_BUILD_COORDINATOR_TYPE if(SerialApp_TxBuf[0] == 0x0A) { unsigned char macAddress[8]; // printf(" sp: \r\n"); for(int index = 1;index<9;index++) { // printf(" %02X ",SerialApp_TxBuf[index]); macAddress[index - 1] = SerialApp_TxBuf[index]; } // printf(" \r\n"); char isAllow = SerialApp_TxBuf[9]; int8 currentIndex = (whiteList->currentIndex + 1)%WHITE_LIST_MAX_SIZE; WhiteNode *node = whiteList->node[currentIndex]; osal_memcpy(node->macAddress,macAddress,8); node->isAllow = isAllow; whiteList->currentIndex = currentIndex ; }#endif
3,在ZDAPP.c文件的ZDO_JoinIndicationCB添加如下代码:
ZStatus_t ZDO_JoinIndicationCB( uint16 ShortAddress, uint8 *ExtendedAddress, uint8 CapabilityInformation, uint8 type ){ (void)ShortAddress; (void)ExtendedAddress; (void)CapabilityInformation; // Notify to save info into NV ZDApp_NVUpdate(); // send notification to TC of new device.. if ( ZG_SECURE_ENABLED ) { if ( type == NWK_ASSOC_JOIN || type == NWK_ASSOC_REJOIN_UNSECURE ) { osal_start_timerEx( ZDAppTaskID, ZDO_NEW_DEVICE, 600 ); } } #if ZG_BUILD_COORDINATOR_TYPE unsigned char SerialApp_TxBuf[10]; SerialApp_TxBuf[0] = 0x0A; unsigned char mac_buf[8]; for(int i=0;i<8;i++){ mac_buf[i] = ExtendedAddress[i]; SerialApp_TxBuf[1+i] = ExtendedAddress[i]; } uint8 flag=0; WhiteNode *node; for(uint8 i=0;i<WHITE_LIST_MAX_SIZE;i++) { node = whiteList->node[i]; if(osal_memcmp(mac_buf,node->macAddress,8)==true) { flag= node->isAllow; break; } } if(flag==1){ return ( ZSuccess ); }else{ SerialApp_TxBuf[9] = 0x0D; HalUARTWrite(0x00, SerialApp_TxBuf, 10); return ( ZFailure ); } #endif return ( ZFailure ); }
注意:
1,设备的mac地址唯一
2,isAllow表示是否允许设备加入网络,由用户决定是否允许其加入(通过串口发送结果到ZigBee模块)
3,whitelist是一个循环使用的数组,在芯片上面不宜保存过多的临时数据,可以将数据用串口发送到上位机或操作系统保存。 0 0
- zigbee实现网络加入过滤(相当于白名单)
- 过滤白名单算法
- 在ZigBee网络中怎么实现节电断电之后重新加入网络
- 在ZigBee网络中怎么实现节电断电之后重新加入网络
- 在ZigBee网络中怎么实现节电断电之后重新加入网络
- 在ZigBee网络中实现节电断电之后重新加入网络
- zigbee中限制节点加入网络
- 【Practice】白名单过滤程序
- ZIgbee设备加入网络过程(方式一 关联加入)
- ZIgbee设备加入网络过程(方式一 关联加入)
- 网站白名单过滤Java代码
- KindEditor白名单过滤和视频发布
- zigbee让设备直接加入网络(DirectJion) (附代码)
- zigbee 4:协调器/路由器/终端 建立/加入 网络
- 如何防止Zigbee加入不该加的网络
- 将Android app加入小米白名单的解决方案
- mina框架:白名单实现
- 网络包过滤的实现
- 滴滴 webapp 5.0 Vue 2.0 重构经验分享
- IT职业发展
- java内存区域与内存溢出异常
- kaka-manager和kafka-offset-monitor的安装和使用
- int main(int argc,char* argv[])详解,以及与int main()有什么区别
- zigbee实现网络加入过滤(相当于白名单)
- WebService两种发布协议--SOAP和REST的区别
- IntelliJ Idea快捷键
- 计算机视觉研究群体及专家主页汇总
- js 循环 map
- android多渠道打包
- 系列:iOS开发-C语言基础
- iOS:.a静态库文件的制作
- JSP 核心标签