*/
OCStackResult RMHandlePacket(bool isRequest, void *message, const CAEndpoint_t *sender,
- bool *selfDestination)
+ bool *selfDestination, bool *isEmptyMsg)
{
RM_NULL_CHECK_WITH_RET(message, RM_TAG, "message");
RM_NULL_CHECK_WITH_RET(sender, RM_TAG, "sender");
RM_NULL_CHECK_WITH_RET(selfDestination, RM_TAG, "selfDestination");
bool forward = false;
+ bool isEMPTYPacket = false;
CAEndpoint_t nextHop = {.adapter = CA_DEFAULT_ADAPTER};
CAInfo_t *info = NULL;
if (isRequest)
else if (g_GatewayID == routeOption.destGw)
{
OIC_LOG(INFO, RM_TAG, "GatewayId found in destination");
+
+ // Check the MSGType of RouteOption to find if the packet is EMPTY packet.
+ if (ACK == routeOption.msgType || RST == routeOption.msgType)
+ {
+ isEMPTYPacket = true;
+ }
+
/*
* This unicast packet either belongs to us or any of our connected end devices
* check if packet belongs to end device.
if (forward)
{
// Don't forward any packet meant for gateway resource.
- if (info->resourceUri && (0 == strcmp(info->resourceUri, OC_RSRVD_GATEWAY_URI)))
+ if (info->resourceUri && (0 == strcmp(info->resourceUri, OC_RSRVD_GATEWAY_URI)) &&
+ (ACK != routeOption.msgType))
{
OIC_LOG(ERROR, RM_TAG, "Not forwarding gateway resource packet");
}
OIC_LOG(ERROR, RM_TAG, "This is secured request. Not supported by routing manager");
return OC_STACK_ERROR;
}
+ else if (isEMPTYPacket)
+ {
+ OC_LOG(DEBUG, TAG, "The message to be Forwarded is a EMPTY message");
+ CAResponseInfo_t responseMessage = {.result = CA_EMPTY};
+ if (ACK == routeOption.msgType)
+ {
+ responseMessage.info.type = CA_MSG_ACKNOWLEDGE;
+ }
+ else
+ {
+ responseMessage.info.type = CA_MSG_RESET;
+ }
+
+ responseMessage.info.messageId = info->messageId;
+
+ CAResult_t caRes = CASendResponse(&nextHop, &responseMessage);
+ if (CA_STATUS_OK != caRes)
+ {
+ OC_LOG_V(ERROR, RM_TAG, "Failed to forward response to next hop [%d][%s]",
+ caRes, nextHop.addr);
+ // Since a response is always unicast, return error here.
+ return OC_STACK_ERROR;
+ }
+ }
else
{
// rewrite any changes in routing option.
}
}
}
+ else
+ {
+ if (isEMPTYPacket)
+ {
+ if (isRequest)
+ {
+ OC_LOG(DEBUG, TAG, "POST message with type ACK in Route Option");
+ if (NULL != isEmptyMsg)
+ {
+ *isEmptyMsg = true;
+ }
+ }
+ else
+ {
+ OC_LOG(DEBUG, TAG, "Response for EMPTY message is received");
+ CAResponseInfo_t *msg = message;
+ if (ACK == (MSGType)routeOption.msgType)
+ {
+ msg->info.type = CA_MSG_ACKNOWLEDGE;
+ }
+ else
+ {
+ msg->info.type = CA_MSG_RESET;
+ }
+ msg->result = CA_EMPTY;
+ OICFree(msg->info.token);
+ msg->info.token = NULL;
+ msg->info.tokenLength = 0;
+ }
+ }
+ }
OIC_LOG_V(INFO, RM_TAG, "Sender: [%u] Destination: [%u]", routeOption.srcGw, routeOption.destGw);
return OC_STACK_OK;
}
OCStackResult RMHandleRequest(CARequestInfo_t *message, const CAEndpoint_t *sender,
- bool *selfDestination)
+ bool *selfDestination, bool *isEmptyMsg)
{
if (!g_isRMInitialized)
{
*selfDestination = true;
return OC_STACK_OK;
}
- OCStackResult res = RMHandlePacket(true, message, sender, selfDestination);
+ OCStackResult res = RMHandlePacket(true, message, sender, selfDestination, isEmptyMsg);
return res;
}
*selfDestination = true;
return OC_STACK_OK;
}
- OCStackResult res = RMHandlePacket(false, message, sender, selfDestination);
+ OCStackResult res = RMHandlePacket(false, message, sender, selfDestination, NULL);
return res;
}
/**
* Minimum routing option data length is
- * length of src address(1byte) + length of destination address(1byte) + hop count(2bytes)
+ * length of src address(1byte) + length of destination address(1byte) +
+ * Seq Num(2bytes) + Msg Type(1 bytes)
*/
-#define MIN_ROUTE_OPTION_LEN 4
+#define MIN_ROUTE_OPTION_LEN 5
+
+/**
+ * Stack mode.
+ */
+static OCMode g_rmStackMode = OC_CLIENT;
+
+void RMSetStackMode(OCMode mode)
+{
+ g_rmStackMode = mode;
+}
// destination and source are <GatewayId><ClientId> here, where ClientId is optional.
-OCStackResult RMAddInfo(const char *destination, CAHeaderOption_t **options,
- uint8_t *numOptions)
+OCStackResult RMAddInfo(const char *destination, void *message, bool isRequest,
+ bool *doPost)
{
OIC_LOG(DEBUG, TAG, "IN");
- RM_NULL_CHECK_WITH_RET(options, TAG, "options");
- RM_NULL_CHECK_WITH_RET(numOptions, TAG, "numOptions");
+ RM_NULL_CHECK_WITH_RET(message, TAG, "options");
+
+ CAHeaderOption_t **options = NULL;
+ uint8_t *numOptions = NULL;
+
+ if (isRequest)
+ {
+ CARequestInfo_t *requestMsg = message;
+ options = &(requestMsg->info.options);
+ RM_NULL_CHECK_WITH_RET(options, TAG, "options");
+ numOptions = &(requestMsg->info.numOptions);
+ RM_NULL_CHECK_WITH_RET(numOptions, TAG, "numOptions");
+ }
+ else
+ {
+ CAResponseInfo_t *respMsg = message;
+ if ('\0' == destination[0] && (CA_EMPTY == respMsg->result))
+ {
+ OC_LOG(DEBUG, TAG, "Response is for an Endpoint, No need to add the routing Option");
+ return OC_STACK_OK;
+ }
+ options = &(respMsg->info.options);
+ RM_NULL_CHECK_WITH_RET(options, TAG, "options");
+ numOptions = &(respMsg->info.numOptions);
+ RM_NULL_CHECK_WITH_RET(numOptions, TAG, "numOptions");
+ }
+
CAHeaderOption_t *optionPtr = NULL;
int8_t index = -1;
}
}
+ if (!isRequest)
+ {
+ CAResponseInfo_t *respMsg = message;
+ if (CA_EMPTY == respMsg->result && CA_MSG_ACKNOWLEDGE == respMsg->info.type)
+ {
+ OC_LOG(DEBUG, TAG, "CA_EMPTY WITH ACKNOWLEDGEMENT");
+ routeOption.msgType = ACK;
+ if (OC_SERVER == g_rmStackMode)
+ {
+ OC_LOG(DEBUG, TAG, "This is server mode");
+ // Send the Empty message in the response with adding the MSGType in Route option.
+ respMsg->info.type = CA_MSG_NONCONFIRM;
+ respMsg->result = CA_CONTENT;
+ }
+ else
+ {
+ OC_LOG(DEBUG, TAG, "Send a POST request");
+ if (NULL != doPost)
+ {
+ *doPost = true;
+ }
+ }
+ }
+ else if (CA_EMPTY == respMsg->result && CA_MSG_RESET == respMsg->info.type)
+ {
+ OC_LOG(DEBUG, TAG, "CA_EMPTY WITH RESET");
+ routeOption.msgType = RST;
+ respMsg->info.type = CA_MSG_NONCONFIRM;
+ respMsg->result = CA_CONTENT;
+ }
+ }
+
if(destination)
{
memcpy(&(routeOption.destGw), destination, sizeof(routeOption.destGw));
}
memcpy(tempData + count, &optValue->mSeqNum, sizeof(optValue->mSeqNum));
+ count += sizeof(optValue->mSeqNum);
+ memcpy(tempData + count, &optValue->msgType, sizeof(optValue->msgType));
memcpy(options->optionData, tempData, totalLength);
options->optionID = RM_OPTION_MESSAGE_SWITCHING;
}
}
memcpy(&optValue->mSeqNum, options->optionData + count, sizeof(optValue->mSeqNum));
+ count += sizeof(optValue->mSeqNum);
+ memcpy(&optValue->msgType, options->optionData + count, sizeof(optValue->msgType));
OIC_LOG_V(INFO, RM_TAG, "Option hopcount is %d", optValue->mSeqNum);
OIC_LOG_V(INFO, RM_TAG, "Option Sender Addr is [%u][%u]", optValue->srcGw, optValue->srcEp);
OIC_LOG_V(INFO, RM_TAG, "Option Dest Addr is [%u][%u]", optValue->destGw, optValue->destEp);
+ OIC_LOG_V(INFO, RM_TAG, "Message Type is [%u]", optValue->msgType);
OIC_LOG(DEBUG, RM_TAG, "OUT");
return OC_STACK_OK;
}
VERIFY_NON_NULL(requestInfo, FATAL, OC_STACK_INVALID_PARAM);
#if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
- OCStackResult rmResult = RMAddInfo(object->routeData, &(requestInfo->info.options),
- &(requestInfo->info.numOptions));
+ OCStackResult rmResult = RMAddInfo(object->routeData, requestInfo, true, NULL);
if (OC_STACK_OK != rmResult)
{
OIC_LOG(ERROR, TAG, "Add destination option failed");
return result;
}
-void HandleCAResponses(const CAEndpoint_t* endPoint, const CAResponseInfo_t* responseInfo)
+void OCHandleResponse(const CAEndpoint_t* endPoint, const CAResponseInfo_t* responseInfo)
{
- VERIFY_NON_NULL_NR(endPoint, FATAL);
- VERIFY_NON_NULL_NR(responseInfo, FATAL);
-
- OIC_LOG(INFO, TAG, "Enter HandleCAResponses");
-
-#if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
-#ifdef ROUTING_GATEWAY
- bool needRIHandling = false;
- /*
- * Routing manager is going to update either of endpoint or response or both.
- * This typecasting is done to avoid unnecessary duplication of Endpoint and responseInfo
- * RM can update "routeData" option in endPoint so that future RI requests can be sent to proper
- * destination.
- */
- OCStackResult ret = RMHandleResponse((CAResponseInfo_t *)responseInfo, (CAEndpoint_t *)endPoint,
- &needRIHandling);
- if(ret != OC_STACK_OK || !needRIHandling)
- {
- OIC_LOG_V(INFO, TAG, "Routing status![%d]. Not forwarding to RI", ret);
- return;
- }
-#endif
-
- /*
- * Put source in sender endpoint so that the next packet from application can be routed to
- * proper destination and remove "RM" coap header option before passing request / response to
- * RI as this option will make no sense to either RI or application.
- */
- RMUpdateInfo((CAHeaderOption_t **) &(responseInfo->info.options),
- (uint8_t *) &(responseInfo->info.numOptions),
- (CAEndpoint_t *) endPoint);
-#endif
+ OC_LOG(DEBUG, TAG, "Enter OCHandleResponse");
if(responseInfo->info.resourceUri &&
strcmp(responseInfo->info.resourceUri, OC_RSRVD_PRESENCE_URI) == 0)
OIC_LOG(INFO, TAG, "Exit HandleCAResponses");
}
+void HandleCAResponses(const CAEndpoint_t* endPoint, const CAResponseInfo_t* responseInfo)
+{
+ VERIFY_NON_NULL_NR(endPoint, FATAL);
+ VERIFY_NON_NULL_NR(responseInfo, FATAL);
+
+ OC_LOG(INFO, TAG, "Enter HandleCAResponses");
+
+#if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
+#ifdef ROUTING_GATEWAY
+ bool needRIHandling = false;
+ /*
+ * Routing manager is going to update either of endpoint or response or both.
+ * This typecasting is done to avoid unnecessary duplication of Endpoint and responseInfo
+ * RM can update "routeData" option in endPoint so that future RI requests can be sent to proper
+ * destination.
+ */
+ OCStackResult ret = RMHandleResponse((CAResponseInfo_t *)responseInfo, (CAEndpoint_t *)endPoint,
+ &needRIHandling);
+ if(ret != OC_STACK_OK || !needRIHandling)
+ {
+ OC_LOG_V(INFO, TAG, "Routing status![%d]. Not forwarding to RI", ret);
+ return;
+ }
+#endif
+
+ /*
+ * Put source in sender endpoint so that the next packet from application can be routed to
+ * proper destination and remove "RM" coap header option before passing request / response to
+ * RI as this option will make no sense to either RI or application.
+ */
+ RMUpdateInfo((CAHeaderOption_t **) &(responseInfo->info.options),
+ (uint8_t *) &(responseInfo->info.numOptions),
+ (CAEndpoint_t *) endPoint);
+#endif
+
+ OCHandleResponse(endPoint, responseInfo);
+
+ OIC_LOG(INFO, TAG, "Exit HandleCAResponses");
+}
+
/*
* This function handles error response from CA
* code shall be added to handle the errors
const uint8_t numOptions, const CAHeaderOption_t *options,
CAToken_t token, uint8_t tokenLength, const char *resourceUri)
{
+ OIC_LOG(DEBUG, TAG, "Entering SendDirectStackResponse");
CAResponseInfo_t respInfo = {
.result = responseResult
};
#if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
// Add the destination to route option from the endpoint->routeData.
- OCStackResult result = RMAddInfo(endPoint->routeData,
- &(respInfo.info.options),
- &(respInfo.info.numOptions));
+ bool doPost = false;
+ OCStackResult result = RMAddInfo(endPoint->routeData, &respInfo, false, &doPost);
if(OC_STACK_OK != result)
{
OIC_LOG_V(ERROR, TAG, "Add routing option failed [%d]", result);
return result;
}
-#endif
-
- CAResult_t caResult = CASendResponse(endPoint, &respInfo);
+ if (doPost)
+ {
+ OC_LOG(DEBUG, TAG, "Sending a POST message for EMPTY ACK in Client Mode");
+ CARequestInfo_t reqInfo = {.method = CA_POST };
+ /* The following initialization is not done in a single initializer block as in
+ * arduino, .c file is compiled as .cpp and moves it from C99 to C++11. The latter
+ * does not have designated initalizers. This is a work-around for now.
+ */
+ reqInfo.info.type = CA_MSG_NONCONFIRM;
+ reqInfo.info.messageId = coapID;
+ reqInfo.info.tokenLength = tokenLength;
+ reqInfo.info.token = token;
+ reqInfo.info.numOptions = respInfo.info.numOptions;
+ reqInfo.info.payload = NULL;
+ reqInfo.info.resourceUri = OICStrdup (OC_RSRVD_GATEWAY_URI);
+ if (reqInfo.info.numOptions)
+ {
+ reqInfo.info.options =
+ (CAHeaderOption_t *)OICCalloc(reqInfo.info.numOptions, sizeof(CAHeaderOption_t));
+ if (NULL == reqInfo.info.options)
+ {
+ OC_LOG(ERROR, TAG, "Calloc failed");
+ return OC_STACK_NO_MEMORY;
+ }
+ memcpy (reqInfo.info.options, respInfo.info.options,
+ sizeof(CAHeaderOption_t) * reqInfo.info.numOptions);
- // resourceUri in the info field is cloned in the CA layer and
- // thus ownership is still here.
- OICFree (respInfo.info.resourceUri);
- OICFree (respInfo.info.options);
- if(CA_STATUS_OK != caResult)
+ }
+ CAResult_t caResult = CASendRequest(endPoint, &reqInfo);
+ OICFree (reqInfo.info.resourceUri);
+ OICFree (reqInfo.info.options);
+ OICFree (respInfo.info.resourceUri);
+ OICFree (respInfo.info.options);
+ if (CA_STATUS_OK != caResult)
+ {
+ OC_LOG(ERROR, TAG, "CASendRequest error");
+ return CAResultToOCResult(caResult);
+ }
+ }
+ else
+#endif
{
- OIC_LOG(ERROR, TAG, "CASendResponse error");
- return CAResultToOCResult(caResult);
+ CAResult_t caResult = CASendResponse(endPoint, &respInfo);
+
+ // resourceUri in the info field is cloned in the CA layer and
+ // thus ownership is still here.
+ OICFree (respInfo.info.resourceUri);
+ OICFree (respInfo.info.options);
+ if(CA_STATUS_OK != caResult)
+ {
+ OIC_LOG(ERROR, TAG, "CASendResponse error");
+ return CAResultToOCResult(caResult);
+ }
}
+ OC_LOG(DEBUG, TAG, "Exit SendDirectStackResponse");
return OC_STACK_OK;
}
-//This function will be called back by CA layer when a request is received
-void HandleCARequests(const CAEndpoint_t* endPoint, const CARequestInfo_t* requestInfo)
+OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest)
{
- OIC_LOG(INFO, TAG, "Enter HandleCARequests");
- if(!endPoint)
+ OIC_LOG(INFO, TAG, "Entering HandleStackRequests (OCStack Layer)");
+ OCStackResult result = OC_STACK_ERROR;
+ if(!protocolRequest)
{
- OIC_LOG(ERROR, TAG, "endPoint is NULL");
- return;
+ OIC_LOG(ERROR, TAG, "protocolRequest is NULL");
+ return OC_STACK_INVALID_PARAM;
}
- if(!requestInfo)
+ OCServerRequest * request = GetServerRequestUsingToken(protocolRequest->requestToken,
+ protocolRequest->tokenLength);
+ if(!request)
{
- OIC_LOG(ERROR, TAG, "requestInfo is NULL");
- return;
+ OIC_LOG(INFO, TAG, "This is a new Server Request");
+ result = AddServerRequest(&request, protocolRequest->coapID,
+ protocolRequest->delayedResNeeded, 0, protocolRequest->method,
+ protocolRequest->numRcvdVendorSpecificHeaderOptions,
+ protocolRequest->observationOption, protocolRequest->qos,
+ protocolRequest->query, protocolRequest->rcvdVendorSpecificHeaderOptions,
+ protocolRequest->payload, protocolRequest->requestToken,
+ protocolRequest->tokenLength, protocolRequest->resourceUrl,
+ protocolRequest->reqTotalSize, protocolRequest->acceptFormat,
+ &protocolRequest->devAddr);
+ if (OC_STACK_OK != result)
+ {
+ OIC_LOG(ERROR, TAG, "Error adding server request");
+ return result;
+ }
+
+ if(!request)
+ {
+ OIC_LOG(ERROR, TAG, "Out of Memory");
+ return OC_STACK_NO_MEMORY;
+ }
+
+ if(!protocolRequest->reqMorePacket)
+ {
+ request->requestComplete = 1;
+ }
+ }
+ else
+ {
+ OIC_LOG(INFO, TAG, "This is either a repeated or blocked Server Request");
}
-#if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
-#ifdef ROUTING_GATEWAY
- bool needRIHandling = false;
- /*
- * Routing manager is going to update either of endpoint or request or both.
- * This typecasting is done to avoid unnecessary duplication of Endpoint and requestInfo
- * RM can update "routeData" option in endPoint so that future RI requests can be sent to proper
- * destination. It can also remove "RM" coap header option before passing request / response to
- * RI as this option will make no sense to either RI or application.
- */
- OCStackResult ret = RMHandleRequest((CARequestInfo_t *)requestInfo, (CAEndpoint_t *)endPoint,
- &needRIHandling);
- if(OC_STACK_OK != ret || !needRIHandling)
+ if(request->requestComplete)
{
- OIC_LOG_V(INFO, TAG, "Routing status![%d]. Not forwarding to RI", ret);
- return;
+ OIC_LOG(INFO, TAG, "This Server Request is complete");
+ ResourceHandling resHandling = OC_RESOURCE_VIRTUAL;
+ OCResource *resource = NULL;
+ result = DetermineResourceHandling (request, &resHandling, &resource);
+ if (result == OC_STACK_OK)
+ {
+ result = ProcessRequest(resHandling, resource, request);
+ }
}
-#endif
+ else
+ {
+ OIC_LOG(INFO, TAG, "This Server Request is incomplete");
+ result = OC_STACK_CONTINUE;
+ }
+ return result;
+}
- /*
- * Put source in sender endpoint so that the next packet from application can be routed to
- * proper destination and remove RM header option.
- */
- RMUpdateInfo((CAHeaderOption_t **) &(requestInfo->info.options),
- (uint8_t *) &(requestInfo->info.numOptions),
- (CAEndpoint_t *) endPoint);
-#endif
+void OCHandleRequests(const CAEndpoint_t* endPoint, const CARequestInfo_t* requestInfo)
+{
+ OC_LOG(DEBUG, TAG, "Enter OCHandleRequests");
#ifdef TCP_ADAPTER
if (requestInfo->info.resourceUri &&
// The token is copied in there, and is thus still owned by this function.
OICFree(serverRequest.payload);
OICFree(serverRequest.requestToken);
- OIC_LOG(INFO, TAG, "Exit HandleCARequests");
+ OIC_LOG(INFO, TAG, "Exit OCHandleRequests");
}
-OCStackResult HandleStackRequests(OCServerProtocolRequest * protocolRequest)
+//This function will be called back by CA layer when a request is received
+void HandleCARequests(const CAEndpoint_t* endPoint, const CARequestInfo_t* requestInfo)
{
- OIC_LOG(INFO, TAG, "Entering HandleStackRequests (OCStack Layer)");
- OCStackResult result = OC_STACK_ERROR;
- ResourceHandling resHandling;
- OCResource *resource;
- if(!protocolRequest)
+ OIC_LOG(INFO, TAG, "Enter HandleCARequests");
+ if(!endPoint)
{
- OIC_LOG(ERROR, TAG, "protocolRequest is NULL");
- return OC_STACK_INVALID_PARAM;
+ OIC_LOG(ERROR, TAG, "endPoint is NULL");
+ return;
}
- OCServerRequest * request = GetServerRequestUsingToken(protocolRequest->requestToken,
- protocolRequest->tokenLength);
- if(!request)
+ if(!requestInfo)
{
- OIC_LOG(INFO, TAG, "This is a new Server Request");
- result = AddServerRequest(&request, protocolRequest->coapID,
- protocolRequest->delayedResNeeded, 0, protocolRequest->method,
- protocolRequest->numRcvdVendorSpecificHeaderOptions,
- protocolRequest->observationOption, protocolRequest->qos,
- protocolRequest->query, protocolRequest->rcvdVendorSpecificHeaderOptions,
- protocolRequest->payload, protocolRequest->requestToken,
- protocolRequest->tokenLength, protocolRequest->resourceUrl,
- protocolRequest->reqTotalSize, protocolRequest->acceptFormat,
- &protocolRequest->devAddr);
- if (OC_STACK_OK != result)
- {
- OIC_LOG(ERROR, TAG, "Error adding server request");
- return result;
- }
-
- if(!request)
- {
- OIC_LOG(ERROR, TAG, "Out of Memory");
- return OC_STACK_NO_MEMORY;
- }
-
- if(!protocolRequest->reqMorePacket)
- {
- request->requestComplete = 1;
- }
+ OIC_LOG(ERROR, TAG, "requestInfo is NULL");
+ return;
}
- else
+
+#if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
+#ifdef ROUTING_GATEWAY
+ bool needRIHandling = false;
+ bool isEmptyMsg = false;
+ /*
+ * Routing manager is going to update either of endpoint or request or both.
+ * This typecasting is done to avoid unnecessary duplication of Endpoint and requestInfo
+ * RM can update "routeData" option in endPoint so that future RI requests can be sent to proper
+ * destination. It can also remove "RM" coap header option before passing request / response to
+ * RI as this option will make no sense to either RI or application.
+ */
+ OCStackResult ret = RMHandleRequest((CARequestInfo_t *)requestInfo, (CAEndpoint_t *)endPoint,
+ &needRIHandling, &isEmptyMsg);
+ if(OC_STACK_OK != ret || !needRIHandling)
{
- OIC_LOG(INFO, TAG, "This is either a repeated or blocked Server Request");
+ OIC_LOG_V(INFO, TAG, "Routing status![%d]. Not forwarding to RI", ret);
+ return;
}
+#endif
- if(request->requestComplete)
- {
- OIC_LOG(INFO, TAG, "This Server Request is complete");
- result = DetermineResourceHandling (request, &resHandling, &resource);
- if (result == OC_STACK_OK)
- {
- result = ProcessRequest(resHandling, resource, request);
- }
+ /*
+ * Put source in sender endpoint so that the next packet from application can be routed to
+ * proper destination and remove RM header option.
+ */
+ RMUpdateInfo((CAHeaderOption_t **) &(requestInfo->info.options),
+ (uint8_t *) &(requestInfo->info.numOptions),
+ (CAEndpoint_t *) endPoint);
+
+#ifdef ROUTING_GATEWAY
+ if (isEmptyMsg)
+ {
+ /*
+ * In Gateways, the MSGType in route option is used to check if the actual
+ * response is EMPTY message(4 bytes CoAP Header). In case of Client, the
+ * EMPTY response is sent in the form of POST request which need to be changed
+ * to a EMPTY response by RM. This translation is done in this part of the code.
+ */
+ OIC_LOG(INFO, TAG, "This is a Empty response from the Client");
+ CAResponseInfo_t respInfo = {.result = CA_EMPTY,
+ .info.messageId = requestInfo->info.messageId,
+ .info.type = CA_MSG_ACKNOWLEDGE};
+ OCHandleResponse(endPoint, &respInfo);
}
else
+#endif
+#endif
{
- OIC_LOG(INFO, TAG, "This Server Request is incomplete");
- result = OC_STACK_CONTINUE;
+ // Normal handling of the packet
+ OCHandleRequests(endPoint, requestInfo);
}
- return result;
+ OIC_LOG(INFO, TAG, "Exit HandleCARequests");
}
bool validatePlatformInfo(OCPlatformInfo info)
result = SRMInitPolicyEngine();
// TODO after BeachHead delivery: consolidate into single SRMInit()
}
-
+#if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
+ RMSetStackMode(mode);
#ifdef ROUTING_GATEWAY
if (OC_GATEWAY == myStackMode)
{
result = RMInitialize();
}
#endif
+#endif
#ifdef TCP_ADAPTER
if(result == OC_STACK_OK)