From d599f492799bdd256b9537ea3f63f9e3b844d1ce Mon Sep 17 00:00:00 2001 From: Sashi Penta Date: Fri, 19 Dec 2014 21:59:10 -0800 Subject: [PATCH] [CA-Integration] : Add support for sequence number for observe Change-Id: I776308ad20911da52ca408c1cbca406bf9747353 Signed-off-by: Sashi Penta --- resource/csdk/stack/src/ocserverrequest.c | 34 +++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/resource/csdk/stack/src/ocserverrequest.c b/resource/csdk/stack/src/ocserverrequest.c index 3cca1ec..15715a8 100644 --- a/resource/csdk/stack/src/ocserverrequest.c +++ b/resource/csdk/stack/src/ocserverrequest.c @@ -353,6 +353,7 @@ OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse) OCStackResult result = OC_STACK_ERROR; CARemoteEndpoint_t responseEndpoint; CAResponseInfo_t responseInfo; + CAHeaderOption_t* optionsPointer; OC_LOG_V(INFO, TAG, "Inside HandleSingleResponse: %s", ehResponse->payload); @@ -413,10 +414,39 @@ OCStackResult HandleSingleResponse(OCEntityHandlerResponse * ehResponse) } responseInfo.info.token = serverRequest->token; - responseInfo.info.numOptions = ehResponse->numSendVendorSpecificHeaderOptions; + + if(serverRequest->observeResult == OC_STACK_OK) + { + responseInfo.info.numOptions = ehResponse->numSendVendorSpecificHeaderOptions + 1; + } + + responseInfo.info.options = (CAHeaderOption_t *) + malloc(sizeof(CAHeaderOption_t) * responseInfo.info.numOptions); + + optionsPointer = responseInfo.info.options; + + if(serverRequest->observeResult == OC_STACK_OK) + { + responseInfo.info.numOptions = ehResponse->numSendVendorSpecificHeaderOptions + 1; + } + + // TODO-CA Revisit this logic + if(serverRequest->observeResult == OC_STACK_OK) + { + responseInfo.info.options[0].protocolID = CA_COAP_ID; + responseInfo.info.options[0].optionID = COAP_OPTION_OBSERVE; + // TODO-CA Remove the magic number 4 + responseInfo.info.options[0].optionLength = 4; + memcpy(responseInfo.info.options[0].optionData, &(serverRequest->observationOption), 4); + + // Point to the next header option before copying vender specific header options + optionsPointer += 1; + } + if (ehResponse->numSendVendorSpecificHeaderOptions) { - memcpy(responseInfo.info.options, ehResponse->sendVendorSpecificHeaderOptions, sizeof(OCHeaderOption) * ehResponse->numSendVendorSpecificHeaderOptions); + memcpy(optionsPointer, ehResponse->sendVendorSpecificHeaderOptions, + sizeof(OCHeaderOption) * ehResponse->numSendVendorSpecificHeaderOptions); } // Allocate memory for the payload. -- 2.7.4