From: Oleksandr Dmytrenko Date: Fri, 18 Nov 2016 13:25:14 +0000 (+0200) Subject: fix: messageID for coap over TCP always is null X-Git-Tag: 1.3.0~1052^2~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f4cb1faf50693c49bb76998cd03f2593eab2ebdc;p=platform%2Fupstream%2Fiotivity.git fix: messageID for coap over TCP always is null Change-Id: Iaf883a1a63a3b221bbcfe9f13bb4856d676de9fe Signed-off-by: Oleksandr Dmytrenko Reviewed-on: https://gerrit.iotivity.org/gerrit/14511 Tested-by: jenkins-iotivity Reviewed-by: Jongsung Lee Reviewed-by: Phil Coval Reviewed-by: Uze Choi Reviewed-by: Randeep Singh (cherry picked from commit e62ef1079225787d3c757325409c8142a93bdf22) Reviewed-on: https://gerrit.iotivity.org/gerrit/14789 --- diff --git a/resource/csdk/security/src/credresource.c b/resource/csdk/security/src/credresource.c index a295bf7..340db08 100644 --- a/resource/csdk/security/src/credresource.c +++ b/resource/csdk/security/src/credresource.c @@ -1815,7 +1815,7 @@ exit: #endif //_ENABLE_MULTIPLE_OWNER_ #endif // __WITH_DTLS__ or __WITH_TLS__ -static OCEntityHandlerResult HandlePostRequest(const OCEntityHandlerRequest * ehRequest) +static OCEntityHandlerResult HandlePostRequest(OCEntityHandlerRequest * ehRequest) { OCEntityHandlerResult ret = OC_EH_ERROR; OIC_LOG(DEBUG, TAG, "HandleCREDPostRequest IN"); @@ -1932,12 +1932,17 @@ static OCEntityHandlerResult HandlePostRequest(const OCEntityHandlerRequest * eh const OicSecDoxm_t* doxm = GetDoxmResourceData(); if(doxm) { - if(!doxm->owned && previousMsgId != ehRequest->messageID) + if(!doxm->owned) { - OIC_LOG(WARNING, TAG, "The operation failed during handle DOXM request,"\ - "DOXM will be reverted."); - RestoreDoxmToInitState(); - RestorePstatToInitState(); + OIC_LOG(WARNING, TAG, "The operation failed during handle DOXM request"); + + if((OC_ADAPTER_IP == ehRequest->devAddr.adapter && previousMsgId != ehRequest->messageID) + || OC_ADAPTER_TCP == ehRequest->devAddr.adapter) + { + RestoreDoxmToInitState(); + RestorePstatToInitState(); + OIC_LOG(WARNING, TAG, "DOXM will be reverted."); + } } } else @@ -2058,7 +2063,10 @@ static OCEntityHandlerResult HandlePostRequest(const OCEntityHandlerRequest * eh } else { - previousMsgId = ehRequest->messageID; + if(OC_ADAPTER_IP == ehRequest->devAddr.adapter) + { + previousMsgId = ehRequest->messageID++; + } } //Send response to request originator ret = ((SendSRMResponse(ehRequest, ret, NULL, 0)) == OC_STACK_OK) ? diff --git a/resource/csdk/security/src/doxmresource.c b/resource/csdk/security/src/doxmresource.c index b16f974..6bdccdd 100644 --- a/resource/csdk/security/src/doxmresource.c +++ b/resource/csdk/security/src/doxmresource.c @@ -952,7 +952,7 @@ void MultipleOwnerDTLSHandshakeCB(const CAEndpoint_t *object, #endif //_ENABLE_MULTIPLE_OWNER_ #endif // defined(__WITH_DTLS__) || defined (__WITH_TLS__) -static OCEntityHandlerResult HandleDoxmPostRequest(const OCEntityHandlerRequest * ehRequest) +static OCEntityHandlerResult HandleDoxmPostRequest(OCEntityHandlerRequest * ehRequest) { OIC_LOG (DEBUG, TAG, "Doxm EntityHandle processing POST request"); OCEntityHandlerResult ehRet = OC_EH_ERROR; @@ -1168,7 +1168,7 @@ static OCEntityHandlerResult HandleDoxmPostRequest(const OCEntityHandlerRequest ehRet = OC_EH_ERROR; } } - else if(previousMsgId != ehRequest->messageID) + else if(OC_ADAPTER_TCP == ehRequest->devAddr.adapter) { if(OC_STACK_OK == GeneratePin(ranPin, sizeof(ranPin))) { @@ -1327,12 +1327,17 @@ exit: */ if(gDoxm) { - if(!gDoxm->owned && previousMsgId != ehRequest->messageID) + if(!gDoxm->owned) { - OIC_LOG(WARNING, TAG, "The operation failed during handle DOXM request,"\ - "DOXM will be reverted."); - RestoreDoxmToInitState(); - RestorePstatToInitState(); + OIC_LOG(WARNING, TAG, "The operation failed during handle DOXM request"); + + if((OC_ADAPTER_IP == ehRequest->devAddr.adapter && previousMsgId != ehRequest->messageID) + || OC_ADAPTER_TCP == ehRequest->devAddr.adapter) + { + RestoreDoxmToInitState(); + RestorePstatToInitState(); + OIC_LOG(WARNING, TAG, "DOXM will be reverted."); + } } } else @@ -1342,7 +1347,7 @@ exit: } else { - previousMsgId = ehRequest->messageID; + previousMsgId = ehRequest->messageID++; } //Send payload to request originator diff --git a/resource/csdk/security/src/pstatresource.c b/resource/csdk/security/src/pstatresource.c index 30f9394..3a9e291 100644 --- a/resource/csdk/security/src/pstatresource.c +++ b/resource/csdk/security/src/pstatresource.c @@ -511,12 +511,12 @@ static OCEntityHandlerResult HandlePstatGetRequest (const OCEntityHandlerRequest * resource or create a new resource. * For pstat, it updates only tm and om. */ -static OCEntityHandlerResult HandlePstatPostRequest(const OCEntityHandlerRequest *ehRequest) +static OCEntityHandlerResult HandlePstatPostRequest(OCEntityHandlerRequest *ehRequest) { OCEntityHandlerResult ehRet = OC_EH_ERROR; OIC_LOG(INFO, TAG, "HandlePstatPostRequest processing POST request"); OicSecPstat_t *pstat = NULL; - static uint16_t prevMsgId = 0; + static uint16_t previousMsgId = 0; if (ehRequest->payload && NULL != gPstat) { @@ -637,10 +637,17 @@ static OCEntityHandlerResult HandlePstatPostRequest(const OCEntityHandlerRequest const OicSecDoxm_t* doxm = GetDoxmResourceData(); if(doxm) { - if(!doxm->owned && prevMsgId != ehRequest->messageID) + if(!doxm->owned) { - RestoreDoxmToInitState(); - RestorePstatToInitState(); + OIC_LOG(WARNING, TAG, "The operation failed during handle DOXM request"); + + if((OC_ADAPTER_IP == ehRequest->devAddr.adapter && previousMsgId != ehRequest->messageID) + || OC_ADAPTER_TCP == ehRequest->devAddr.adapter) + { + RestoreDoxmToInitState(); + RestorePstatToInitState(); + OIC_LOG(WARNING, TAG, "DOXM will be reverted."); + } } } else @@ -650,7 +657,10 @@ static OCEntityHandlerResult HandlePstatPostRequest(const OCEntityHandlerRequest } else { - prevMsgId = ehRequest->messageID; + if(ehRequest->devAddr.adapter == OC_ADAPTER_IP) + { + previousMsgId = ehRequest->messageID++; + } } // Send response payload to request originator diff --git a/resource/csdk/stack/src/ocstack.c b/resource/csdk/stack/src/ocstack.c index f7b2113..1ba0ae4 100644 --- a/resource/csdk/stack/src/ocstack.c +++ b/resource/csdk/stack/src/ocstack.c @@ -1379,7 +1379,8 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp { int start = 0; //First option always with option ID is COAP_OPTION_OBSERVE if it is available. - if(responseInfo->info.options[0].optionID == COAP_OPTION_OBSERVE) + if(responseInfo->info.options + && responseInfo->info.options[0].optionID == COAP_OPTION_OBSERVE) { size_t i; uint32_t observationOption; @@ -1409,8 +1410,11 @@ void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* resp for (uint8_t i = start; i < responseInfo->info.numOptions; i++) { - memcpy (&(response.rcvdVendorSpecificHeaderOptions[i-start]), - &(responseInfo->info.options[i]), sizeof(OCHeaderOption)); + if(&(responseInfo->info.options[i])) + { + memcpy (&(response.rcvdVendorSpecificHeaderOptions[i-start]), + &(responseInfo->info.options[i]), sizeof(OCHeaderOption)); + } } } @@ -1954,7 +1958,7 @@ void OCHandleRequests(const CAEndpoint_t* endPoint, const CARequestInfo_t* reque return; } serverRequest.numRcvdVendorSpecificHeaderOptions = tempNum; - if (serverRequest.numRcvdVendorSpecificHeaderOptions) + if (serverRequest.numRcvdVendorSpecificHeaderOptions && requestInfo->info.options) { memcpy (&(serverRequest.rcvdVendorSpecificHeaderOptions), requestInfo->info.options, sizeof(CAHeaderOption_t)*tempNum);