📄 zdcache.lst
字号:
873 status = ZDP_NOT_PERMITTED;
874 }
875 else
876 {
877 msg += (2 + Z_EXTADDR_LEN);
878
879 switch ( cmd )
880 {
881 case Node_Desc_store_req:
882 osal_memcpy( NodeDesc+idx, msg, sizeof( NodeDescriptorFormat_t ) );
883 break;
884
885 case Power_Desc_store_req:
886 osal_memcpy( NodePwr+idx, msg, sizeof( NodePowerDescriptorFormat_t ) );
887 break;
888
889 case Active_EP_store_req:
890 if ( *msg < CACHE_EP_MAX )
891 {
892 EPCnt[idx] = *msg++;
893 osal_memcpy( EPArr+idx, msg, EPCnt[idx] );
894 }
895 else
896 {
897 status = ZDP_INSUFFICIENT_SPACE;
898 }
899 break;
900
901 case Simple_Desc_store_req:
902 status = processSimpleDescStoreReq( msg, idx );
903 break;
904 }
905 }
906 }
907
908 if ( !sent )
909 {
910 SendMsg( (cmd | ZDO_RESPONSE_BIT ), 1, &status );
911 }
912 }
913
914 /*********************************************************************
915 * @fn ZDCacheProcessMatchDescReq
916 *
917 * @brief Build and send a response to a Broadcast Discovery Cache request.
918 *
919 * @return None.
920 */
921 void ZDCacheProcessMatchDescReq( byte seq, zAddrType_t *src,
922 byte inCnt, uint16 *inClusters, byte outCnt, uint16 *outClusters,
923 uint16 profileID, uint16 aoi, byte sty )
924 {
925 byte buf[ 1 + 2 + 1 + CACHE_EP_MAX ]; // Status + AOI + Len + EP list.
926 byte aoiMatch = (aoi == NWK_BROADCAST_SHORTADDR) ? TRUE : FALSE;
927 SimpleDescriptionFormat_t *sDesc;
928 byte idx, epIdx, epCnt;
929 secUse = sty;
930
931 if ( !CACHE_SERVER )
932 {
933 return;
934 }
935
936 buf[0] = ZDP_SUCCESS;
937 buf[1] = LO_UINT16( aoi );
938 buf[2] = HI_UINT16( aoi );
939 buf[3] = 0;
940
941 msgAddr.addr.shortAddr = src->addr.shortAddr;
942
943 // Respond by proxy for all devices that have registered an endpoint.
944 for ( idx = 0; idx < CACHE_DEV_MAX; idx++ )
945 {
946 if ( ((aoi == NWK_BROADCAST_SHORTADDR) &&
947 (NwkAddr[idx] != INVALID_NODE_ADDR)) || (aoi == NwkAddr[idx]) )
948 {
949 sDesc = SimpDesc[idx];
950 epCnt = 4;
951
952 for ( epIdx = 0; epIdx < EPCnt[idx]; epIdx++, sDesc++ )
953 {
954 if ( sDesc->AppProfId == profileID )
955 {
956 // If there are no search input/ouput clusters - respond.
957 if ( ((inCnt == 0) && (outCnt == 0)) ||
958 ZDO_AnyClusterMatches( inCnt, inClusters,
959 sDesc->AppNumInClusters, sDesc->pAppInClusterList ) ||
960 ZDO_AnyClusterMatches( outCnt, outClusters,
961 sDesc->AppNumOutClusters, sDesc->pAppOutClusterList ))
962 {
963 buf[epCnt++] = sDesc->EndPoint;
964 }
965 }
966 }
967
968 if ( epCnt > 4 )
969 {
970 buf[1] = LO_UINT16( NwkAddr[idx] );
971 buf[2] = HI_UINT16( NwkAddr[idx] );
972 buf[3] = epCnt-4;
973 SendMsg( Match_Desc_rsp, epCnt, buf );
974 }
975
976 if ( aoi == NwkAddr[idx] )
977 {
978 aoiMatch = TRUE;
979
980 if ( epCnt == 4 )
981 {
982 buf[0] = ZDP_NO_MATCH;
983 SendMsg( Match_Desc_rsp, 4, buf );
984 }
985 break;
986 }
987 }
988 }
989
990 if ( !aoiMatch )
991 {
992 buf[0] = ZDP_DEVICE_NOT_FOUND;
993 SendMsg( Match_Desc_rsp, 4, buf );
994 }
995 }
996
997 /*********************************************************************
998 * @fn ZDCacheGetDesc
999 *
1000 * @brief Return the cached descriptor requested.
1001 *
1002 * @param aoi - NWK AddrOfInterest
1003 *
1004 * @return The corresponding descriptor *, if the aoi is found,
1005 * NULL otherwise.
1006 */
1007 void *ZDCacheGetDesc( uint16 aoi, eDesc_t type, byte *stat )
1008 {
1009 byte epIdx, idx = getIdx( aoi );
1010 void *rtrn = NULL;
1011 byte *ptr;
1012
1013 if ( idx != CACHE_DEV_MAX )
1014 {
1015 byte cnt;
1016
1017 *stat = ZDP_SUCCESS;
1018
1019 switch ( type )
1020 {
1021 case eNodeDesc:
1022 rtrn = (void *)(NodeDesc+idx);
1023 break;
1024
1025 case ePowerDesc:
1026 rtrn = (void *)(NodePwr+idx);
1027 break;
1028
1029 case eActEPDesc:
1030 /* Tricky overload of return values:
1031 * if rtrn val is zero (NULL), status is put in stat[0] -
1032 * either ZDP_DEVICE_NOT_FOUND or ZDP_SUCCESS.
1033 * otherwise, w/ rtrn val > 0, stat is loaded byte for byte w/
1034 * all active endpts other than ZDO. Thus, stat must be pointing to
1035 * an array of at least CACHE_EP_MAX bytes.
1036 */
1037 ptr = EPArr[ idx ];
1038 for ( cnt = 0, idx = 0; idx < CACHE_EP_MAX; idx++ )
1039 {
1040 if ( ptr[idx] == 0xff )
1041 break;
1042 else if ( ptr[idx] == ZDO_EP )
1043 continue;
1044 else
1045 {
1046 *stat++ = ptr[idx];
1047 cnt++;
1048 }
1049 }
1050 rtrn = (void *)cnt;
1051 break;
1052
1053 case eSimpDesc:
1054 // Tricky re-use of status parameter as endPoint to find.
1055 epIdx = getIdxEP( idx, *stat );
1056
1057 if ( epIdx == CACHE_EP_MAX )
1058 {
1059 *stat = ZDP_DEVICE_NOT_FOUND;
1060 }
1061 else
1062 {
1063 rtrn = (void *)(&SimpDesc[idx][epIdx]);
1064 }
1065 break;
1066
1067 default:
1068 *stat = ZDP_INVALID_REQTYPE;
1069 break;
1070 }
1071 }
1072 else
1073 {
1074 *stat = ZDP_DEVICE_NOT_FOUND;
1075 }
1076
1077 return rtrn;
1078 }
1079
1080 /*********************************************************************
1081 * @fn ZDCacheGetNwkAddr
1082 *
1083 * @brief Find the Network Address of a discovery cache entry that
1084 * corresponds to the given IEEE address.
1085 *
1086 * @param byte * - a valid buffer containing an extended IEEE address.
1087 *
1088 * @return If address found, return the nwk addr, else INVALIDE_NODE_ADDR.
1089 *
1090 */
1091 uint16 ZDCacheGetNwkAddr( byte *ieee )
1092 {
1093 uint16 addr = INVALID_NODE_ADDR;
1094 byte idx;
1095
1096 for ( idx = 0; idx < CACHE_DEV_MAX; idx++ )
1097 {
1098 if ( osal_ExtAddrEqual( ieee, ExtAddr[idx] ) &&
1099 (NwkAddr[idx] != INVALID_NODE_ADDR) )
1100 {
1101 addr = NwkAddr[idx];
1102 break;
1103 }
1104 }
1105
1106 return addr;
1107 }
1108
1109 /*********************************************************************
1110 * @fn ZDCacheGetExtAddr
1111 *
1112 * @brief Find the Extended Address of a discovery cache entry that
1113 * corresponds to the given Network address.
1114 *
1115 * @param aoi - the Network Address of interest.
1116 *
1117 * @return If address found, return a ptr to the extended ieee addr, else NULL.
1118 *
1119 */
1120 byte * ZDCacheGetExtAddr( uint16 aoi )
1121 {
1122 byte *ieee = NULL;
1123 byte idx;
1124
1125 for ( idx = 0; idx < CACHE_DEV_MAX; idx++ )
1126 {
1127 if ( aoi == NwkAddr[idx] )
1128 {
1129 ieee = ExtAddr[idx];
1130 break;
1131 }
1132 }
1133
1134 return ieee;
1135 }
1136 #endif
1137
1138 #if ( CACHE_DEV_MAX == 0 )
1139 /*********************************************************************
1140 * @fn ZDCacheProcessRsp
1141 *
1142 * @brief Process a response to a Discovery Cache request.
1143 *
1144 * @return none
1145 */
1146 void ZDCacheProcessRsp(
1147 zAddrType_t *src, byte *msg, byte len, byte cmd, byte seq )
1148 {
1149 if ( ((cmd==Find_node_cache_rsp) && (*msg==ZDP_NOT_SUPPORTED) && (len==3)) ||
1150 ((cmd!=Find_node_cache_rsp) &&
1151 ((*msg != ZDP_SUCCESS) || (seq != (tranSeq-1)))) )
1152 {
1153 return;
1154 }
1155
1156 cacheRsp = ZDP_SUCCESS;
1157
1158 switch ( cmd )
1159 {
1160 case Discovery_Register_rsp:
1161 case Find_node_cache_rsp:
1162 if ( cacheCnt < FIND_RSP_MAX )
1163 {
1164 byte idx;
1165
1166 // Only log unique response addresses.
1167 for ( idx = 0; idx < cacheCnt; idx++ )
1168 {
1169 if ( cacheFindAddr[idx] == src->addr.shortAddr )
1170 {
1171 break;
1172 }
1173 }
1174
1175 if ( idx == cacheCnt )
1176 {
1177 cacheFindAddr[cacheCnt++] = src->addr.shortAddr;
1178 }
1179 }
1180 break;
1181
1182 default:
1183 break;
1184 }
1185
1186 }
1187 #endif
1188
1189
1190 /*********************************************************************
1191 *********************************************************************/
1192
1193 #endif //#if defined( ZDO_CACHE )
Segment part sizes:
Function/Label Bytes
-------------- -----
0 bytes of memory
Errors: none
Warnings: none
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -