zbSize_t Mgmt_Direct_Join_req ( zbMgmtDirectJoinRequest_t *pMsgComingIn ) { zdoNlmeMessage_t *pZdoNlmeMsg; #if ((gStandardSecurity_d || gHighSecurity_d) && gApsMaxEntriesForPermissionsTable_c) nlmeZdoMessage_t zdoMsg; #endif #if ((gStandardSecurity_d || gHighSecurity_d) && gApsMaxEntriesForPermissionsTable_c) if (!CommandHasPermission(NlmeGetRequest(gNwkShortAddress_c), gNetworkSettingsPermission_c)) { zdoMsg.msgData.directJoinConf.status = gZdpNotAuthorized_c; Zdp_Mgmt_Direct_Join_conf((void *)&zdoMsg); return 0; } #endif pZdoNlmeMsg = MSG_Alloc(MbrSizeof(zdoNlmeMessage_t, msgType) + sizeof(nlmeDirectJoinReq_t)); if (pZdoNlmeMsg) { pZdoNlmeMsg->msgType = gNlmeDirectJoinRequest_c; FLib_MemCpy(&pZdoNlmeMsg->msgData.directJoinReq, pMsgComingIn, sizeof(nlmeDirectJoinReq_t)); ZDO_SendEvent(gZdoEvent_ManagementCommand_c); (void)ZDO_NLME_SapHandler((void *)pZdoNlmeMsg); } return 0; }
/************************************************************************************ * Does a local energy scan, pass the confirm to the application using the ZDP_APP * Sap handler. Not available to ZEDs * * Interface assumptions: * The parameter aChannelList, is a valid channel list and is on little endian. * The parameter duration, is a non zero value. * * Return value: * NONE. * * Revison history: * Date Author Comments * ------ ------ -------- * 180208 MN Created ************************************************************************************/ void ZdoNwkMng_EnergyScanRequest ( zbChannels_t aChannelList, uint8_t duration ) { uintn32_t localList = 0; zdoNlmeMessage_t *pEnergyScan; nlmeEnergyScanReq_t *pEnergyRequest; pEnergyScan = MSG_Alloc(sizeof(nlmeEnergyScanReq_t) + sizeof(zbMsgId_t)); if (!pEnergyScan) return; /* NOTE: this function is used on FA and on regular ZDO state machine some times it receives the parameter on little endian and some times on big endian. */ /* Check if it's a valid channel list */ if( aChannelList[0] & 0xFF || aChannelList[1] & 0x07 || aChannelList[3] & 0xF8 ) { #ifdef __IAR_SYSTEMS_ICC__ FLib_MemCpyReverseOrder(&localList, aChannelList, sizeof(uint32_t)); #else localList = *((uint32_t *)aChannelList); localList = Native2OTA32(localList); #endif } pEnergyScan->msgType = gNlmeEnergyScanRequest_c; pEnergyRequest = &pEnergyScan->msgData.EnergyScanReq; if (localList) { FLib_MemCpy(pEnergyRequest->aScanChannels, &localList, sizeof(localList)); } else { FLib_MemCpy(pEnergyRequest->aScanChannels, aChannelList, sizeof(localList)); } pEnergyRequest->scanDuration = duration; if(ZDO_NLME_SapHandler(pEnergyScan)) { } }
void HcOutgoingZtcTaskEventMonitor(OepOutgoingMessage_t *message) { hcZtcMessage_t* pMsgFromSAPHandler; /* cleaner access to the 11073 apdu */ oepGenericApdu_t *pApdu = (oepGenericApdu_t *)message->pApdu; uint8_t* pSrcDataPtr; uint8_t* pDstDataPtr; /* first fragment flag is initially set to True */ uint8_t firstFragment = TRUE; uint16_t apduLen = message->length - MbrSizeof(oepGenericApdu_t, apduLen); uint8_t dataCopyLen; /* iterate the fragments */ do { /* allocate a new buffer as the ZTC frames are quite different from the actual 11073 frames */ pMsgFromSAPHandler = (hcZtcMessage_t *) MSG_Alloc(mSapHandlerMsgTotalLen_c); if (firstFragment) { oepMsgType_t oepMsgType; firstFragment = FALSE; /* is it a cfg, prst, other kind of frame? */ oepMsgType = GetOepMsgType(pApdu); /* get ZTC opcode id for the frame */ pMsgFromSAPHandler->msgType = GetMsgZtcOpCode(pApdu); /* frame is an object configuration frame */ if (oepMsgType == msgType_ObjCfgMsg) { hcZtcObjCfgFrame_t* pHcZtcObjCfgFrame = (hcZtcObjCfgFrame_t *)pMsgFromSAPHandler->data; apduLen -= MbrSizeof(oepGenericApdu_t, choice); if (apduLen > mSapHandlerMsgTotalLen_c - MbrOfs(hcZtcObjCfgFrame_t, objCfgFrame)) { dataCopyLen = mSapHandlerMsgTotalLen_c - MbrOfs(hcZtcObjCfgFrame_t, objCfgFrame); apduLen -= dataCopyLen; pHcZtcObjCfgFrame->nextFragmentPresent = TRUE; } else { dataCopyLen = (uint8_t)apduLen; apduLen = 0; pHcZtcObjCfgFrame->nextFragmentPresent = FALSE; } pMsgFromSAPHandler->msgLen = dataCopyLen + MbrOfs(hcZtcObjCfgFrame_t, objCfgFrame); pSrcDataPtr = (uint8_t *)pApdu->payload; pDstDataPtr = (uint8_t *)pHcZtcObjCfgFrame->objCfgFrame; pHcZtcObjCfgFrame->endPoint = message->srcEndPoint; } else { /* Aarq, Aars, Prst, etc type of frame */ hcZtcFrame_t* pZtcFrameGeneric = (hcZtcFrame_t *)pMsgFromSAPHandler->data; if (apduLen > mSapHandlerMsgTotalLen_c - MbrOfs(hcZtcFrame_t, apdu)) { dataCopyLen = mSapHandlerMsgTotalLen_c - MbrOfs(hcZtcFrame_t, apdu); apduLen -= dataCopyLen; pZtcFrameGeneric->nextFragmentPresent = TRUE; } else { dataCopyLen = (uint8_t)apduLen; apduLen = 0; pZtcFrameGeneric->nextFragmentPresent = FALSE; } pMsgFromSAPHandler->msgLen = dataCopyLen + MbrOfs(hcZtcFrame_t, apdu); pSrcDataPtr = (uint8_t *)&pApdu->choice; pDstDataPtr = (uint8_t *)pZtcFrameGeneric->apdu; Copy2Bytes(pZtcFrameGeneric->aSrcDstAddr, message->aDstAddr); pZtcFrameGeneric->dstEndPoint = message->dstEndPoint; pZtcFrameGeneric->srcEndPoint = message->srcEndPoint; } } else { /* this is not the first fragment; */ hcZtcFragmentContinuationFrame_t* pZtcFragmentCont = (hcZtcFragmentContinuationFrame_t *)pMsgFromSAPHandler->data; /* set fragment continuation opcode */ pMsgFromSAPHandler->msgType = gHcZtcOpcode_FragmentContinuation_d; if (apduLen > mSapHandlerMsgTotalLen_c - MbrOfs(hcZtcFragmentContinuationFrame_t, fragmentData)) { dataCopyLen = mSapHandlerMsgTotalLen_c - MbrOfs(hcZtcFragmentContinuationFrame_t, fragmentData); apduLen -= dataCopyLen; pZtcFragmentCont->nextFragmentPresent = TRUE; } else { dataCopyLen = (uint8_t)apduLen; apduLen = 0; pZtcFragmentCont->nextFragmentPresent = FALSE; } pMsgFromSAPHandler->msgLen = dataCopyLen + MbrSizeof(hcZtcFragmentContinuationFrame_t, fragmentData); pDstDataPtr = (uint8_t *)pZtcFragmentCont->fragmentData; } FLib_MemCpy(pDstDataPtr, pSrcDataPtr, dataCopyLen); pSrcDataPtr += dataCopyLen; /* send message to ZTC */ #ifndef gHostApp_d ZTC_TaskEventMonitor(gHcApp_SAPHandlerId_c, (uint8_t *)pMsgFromSAPHandler, gZbSuccess_c); #else ZTC_TaskEventMonitor(gpHostAppUart, gHcApp_SAPHandlerId_c, (uint8_t *)pMsgFromSAPHandler, gZbSuccess_c); #endif /* free the message if ZTC hasn't already done that */ if (pMsgFromSAPHandler) MSG_Free(pMsgFromSAPHandler); } while (apduLen > 0); }
void HcIncomingZtcTaskEventMonitor(OepFragmentedApdu_t *message) { hcZtcMessage_t* pMsgFromSAPHandler; /* pCurrentFragment points initially to the fragment in OepFragmentedApdu_t */ OepApduFragment_t* pCurrentFragment = &message->fragment; /* cleaner access to the 11073 apdu */ oepGenericApdu_t *pApdu = (oepGenericApdu_t *)pCurrentFragment->data; /* first fragment flag is initially set to True */ uint8_t firstFragment = TRUE; /* iterate the fragments */ do { uint8_t srcOffset, dstOffset, dataCopyLen; /* allocate a new buffer as the ZTC frames are quite different from the actual 11073 frames */ pMsgFromSAPHandler = (hcZtcMessage_t *) MSG_Alloc(mSapHandlerMsgTotalLen_c); /* set default values for mem copy offsets and length */ /* by default copy data beginning with the choice member in the apdu */ srcOffset = MbrOfs(oepGenericApdu_t, choice); /* by default copy data to the apdu member in the ztc frame*/ dstOffset = MbrOfs(hcZtcFrame_t, apdu); /* data copy length adjusted to omit apduLen field */ dataCopyLen = pCurrentFragment->len - MbrOfs(oepGenericApdu_t, choice); if (firstFragment) { oepMsgType_t oepMsgType; firstFragment = FALSE; /* is it a cfg, prst, other kind of frame? */ oepMsgType = GetOepMsgType(pApdu); /* get ZTC opcode id for the frame */ pMsgFromSAPHandler->msgType = GetMsgZtcOpCode(pApdu); /* frame is an object configuration frame */ if (oepMsgType == msgType_ObjCfgMsg) { /* msgLen is the length of the ZTC payload; this includes the actual apdu payload, without the choice and apduLen as well as the src/dstEndPoint and nextFragmentPresent bytes */ pMsgFromSAPHandler->msgLen = (uint8_t)(pCurrentFragment->len - MbrOfs(oepGenericApdu_t, payload) + MbrOfs(hcZtcObjCfgFrame_t, objCfgFrame)); /* adjust source offset for data copy to not include choice */ srcOffset = MbrOfs(oepGenericApdu_t, payload); /* adjust dst offset for data copy as srcAddress and an endpoint are no longer included */ dstOffset = MbrOfs(hcZtcObjCfgFrame_t, objCfgFrame); /* adjust data length for data copy as choice is no longer included */ dataCopyLen -= MbrSizeof(oepGenericApdu_t, choice); /* set destination endpoint as second byte in the ZTC packet based on frame direction */ pMsgFromSAPHandler->data[1] = message->dstEndPoint; } else { /* Aarq, Aars, Prst, etc type of frame */ hcZtcFrame_t* pZtcFrameGeneric = (hcZtcFrame_t *)pMsgFromSAPHandler->data; /* msgLen is the length of the ZTC payload; this includes the actual apdu payload, without the apduLen as well as the addressing information and nextFragmentPresent bytes */ pMsgFromSAPHandler->msgLen = pCurrentFragment->len - MbrOfs(oepGenericApdu_t, choice) + MbrOfs(hcZtcFrame_t, apdu); /* copy addressing info */ Copy2Bytes(pZtcFrameGeneric->aSrcDstAddr, message->aSrcAddr); pZtcFrameGeneric->dstEndPoint = message->dstEndPoint; pZtcFrameGeneric->srcEndPoint = message->srcEndPoint; } } else { /* this is not the first fragment; */ /* set data copy and copy size accordingly */ srcOffset = 0; dstOffset = 1; dataCopyLen = pCurrentFragment->len; pApdu = (oepGenericApdu_t *)pCurrentFragment->data; /* set fragment continuation opcode */ pMsgFromSAPHandler->msgType = gHcZtcOpcode_FragmentContinuation_d; /* msgLen includes the actualapdu payload and the nextFragmentPresent byte */ pMsgFromSAPHandler->msgLen = pCurrentFragment->len + MbrSizeof(hcZtcFrame_t, nextFragmentPresent); } /* nextFragmentPresent */ pMsgFromSAPHandler->data[0] = FALSE; /* set nextFramgentPresent byte in ZTC frame to 1 if there is another fragment to be processed */ if (pCurrentFragment->nextFragment != NULL) pMsgFromSAPHandler->data[0] = TRUE; /* do the fragment iteration */ pCurrentFragment = pCurrentFragment->nextFragment; /* copy payload data */ FLib_MemCpy((uint8_t*)pMsgFromSAPHandler->data + dstOffset, (uint8_t*)pApdu + srcOffset, dataCopyLen); /* send message to ZTC */ #ifndef gHostApp_d ZTC_TaskEventMonitor(gAppHc_SAPHandlerId_c, (uint8_t *)pMsgFromSAPHandler, gZbSuccess_c); #else ZTC_TaskEventMonitor(gpHostAppUart, gAppHc_SAPHandlerId_c, (uint8_t *)pMsgFromSAPHandler, gZbSuccess_c); #endif /* free the message if ZTC hasn't already done that */ if (pMsgFromSAPHandler) MSG_Free(pMsgFromSAPHandler); } while (pCurrentFragment != NULL); }