/*
* This method is used by Policy engine to process AMS request
- * *
+ *
* @param context Policy engine context.
*
- * @return None
*/
void ProcessAMSRequest(PEContext_t *context);
+
+/*
+ * This method is used by Policy engine to free AMS context requestInfo
+ *
+ * @param requestInfo pointer to CARequestInfo_t.
+ *
+ */
+void FreeCARequestInfo(CARequestInfo_t *requestInfo);
+
#endif //IOTVT_SRM_AMSMGR_H
!clientResponse->payload||
(PAYLOAD_TYPE_DISCOVERY != clientResponse->payload->type)||
(OC_STACK_OK != clientResponse->result))
- {
- OC_LOG_V(ERROR, TAG, "%s Invalid Response ", __func__);
- SRMSendResponse(ACCESS_DENIED_AMS_SERVICE_ERROR);
- return OC_STACK_DELETE_TRANSACTION;
- }
+ {
+ OC_LOG_V(ERROR, TAG, "%s Invalid Response ", __func__);
+ SRMSendResponse(ACCESS_DENIED_AMS_SERVICE_ERROR);
+ return OC_STACK_DELETE_TRANSACTION;
+ }
PEContext_t *context = (PEContext_t *) ctx;
+
(void)handle;
if (context->state != AWAITING_AMS_RESPONSE)
{
SRMSendResponse(context->retVal);
return OC_STACK_DELETE_TRANSACTION;
}
+
OCResourcePayload* resPayload = ((OCDiscoveryPayload*)clientResponse->payload)->resources;
//Verifying if the ID of the sender is an AMS service that this device trusts.
memcmp(context->amsMgrContext->amsDeviceId.id, resPayload->sid,
sizeof(context->amsMgrContext->amsDeviceId.id)) != 0)
{
+ OC_LOG_V(ERROR, TAG, "%s Invalid AMS device", __func__);
context->retVal = ACCESS_DENIED_AMS_SERVICE_ERROR;
SRMSendResponse(context->retVal);
return OC_STACK_DELETE_TRANSACTION;
}
}
OC_LOG(INFO, TAG, "Can not find secure port information");
+
context->retVal = ACCESS_DENIED_AMS_SERVICE_ERROR;
SRMSendResponse(context->retVal);
return OC_STACK_DELETE_TRANSACTION;
(PAYLOAD_TYPE_SECURITY != clientResponse->payload->type) ||
(clientResponse->result != OC_STACK_OK))
{
+ OC_LOG_V(ERROR, TAG, "%s Invalid Response ", __func__);
SRMSendResponse(ACCESS_DENIED_AMS_SERVICE_ERROR);
- goto exit;
+ return OC_STACK_DELETE_TRANSACTION;
}
if (context->state != AWAITING_AMS_RESPONSE)
exit:
context->retVal = ACCESS_DENIED_AMS_SERVICE_ERROR;
SRMSendResponse(context->retVal);
- FreeCARequestInfo(context->amsMgrContext->requestInfo);
- OICFree(context->amsMgrContext->endpoint);
return OC_STACK_DELETE_TRANSACTION;
}
void FreeCARequestInfo(CARequestInfo_t *requestInfo)
{
+ if(NULL == requestInfo)
+ {
+ OC_LOG_V(ERROR, TAG, "%s: Can't free memory. Received NULL requestInfo", __func__);
+ return;
+ }
OICFree(requestInfo->info.token);
OICFree(requestInfo->info.options);
OICFree(requestInfo->info.payload);
if(OC_STACK_OK == DiscoverAmsService(context))
{
context->retVal = ACCESS_WAITING_FOR_AMS;
+ context->state = AWAITING_AMS_RESPONSE;
}
else
{
context->matchingAclFound = false;
context->amsProcessing = false;
context->retVal = ACCESS_DENIED_POLICY_ENGINE_ERROR;
+
+ FreeCARequestInfo(context->amsMgrContext->requestInfo);
+ OICFree(context->amsMgrContext->endpoint);
memset(context->amsMgrContext, 0, sizeof(AmsMgrContext_t));
// Set state.
// Capture retVal before resetting state for next request.
retVal = context->retVal;
- //Change the state of PE to "AWAITING_AMS_RESPONSE", if waiting
- //for response from AMS service else to "AWAITING_REQUEST"
- if(ACCESS_WAITING_FOR_AMS == retVal)
- {
- OC_LOG(INFO, TAG, "Setting PE State to AWAITING_AMS_RESPONSE");
- context->state = AWAITING_AMS_RESPONSE;
- }
- else if(!context->amsProcessing)
+ if(!context->amsProcessing)
{
OC_LOG(INFO, TAG, "Resetting PE context and PE State to AWAITING_REQUEST");
SetPolicyEngineState(context, AWAITING_REQUEST);
*/
OCStackResult InitPolicyEngine(PEContext_t *context)
{
- if(NULL== context)
+ if(NULL == context)
{
return OC_STACK_ERROR;
}
- context->amsMgrContext = (AmsMgrContext_t *)OICMalloc(sizeof(AmsMgrContext_t));
- SetPolicyEngineState(context, AWAITING_REQUEST);
+ context->amsMgrContext = (AmsMgrContext_t *)OICCalloc(1, sizeof(AmsMgrContext_t));
+ if(NULL == context->amsMgrContext)
+ {
+ return OC_STACK_ERROR;
+ }
+ SetPolicyEngineState(context, AWAITING_REQUEST);
return OC_STACK_OK;
}
static void SRMSendUnAuthorizedAccessresponse(PEContext_t *context)
{
CAResponseInfo_t responseInfo = {.result = CA_EMPTY};
+
+ if(NULL == context ||
+ NULL == context->amsMgrContext->requestInfo)
+ {
+ OC_LOG_V(ERROR, TAG, "%s : NULL Parameter(s)",__func__);
+ return;
+ }
+
memcpy(&responseInfo.info, &(context->amsMgrContext->requestInfo->info),
sizeof(responseInfo.info));
responseInfo.info.payload = NULL;
responseInfo.result = CA_UNAUTHORIZED_REQ;
- if (CA_STATUS_OK != CASendResponse(context->amsMgrContext->endpoint, &responseInfo))
+
+ if (CA_STATUS_OK == CASendResponse(context->amsMgrContext->endpoint, &responseInfo))
{
- OC_LOG(ERROR, TAG, "Failed in sending response to a unauthorized request!");
+ OC_LOG(DEBUG, TAG, "Succeed in sending response to a unauthorized request!");
}
else
{
- OC_LOG(INFO, TAG, "Succeed in sending response to a unauthorized request!");
+ OC_LOG(ERROR, TAG, "Failed in sending response to a unauthorized request!");
}
}
{
OC_LOG_V(INFO, TAG, "%s : Access granted. Passing Request to RI layer", __func__);
if (!g_policyEngineContext.amsMgrContext->endpoint ||
- !g_policyEngineContext.amsMgrContext->requestInfo)
+ !g_policyEngineContext.amsMgrContext->requestInfo)
{
OC_LOG_V(ERROR, TAG, "%s : Invalid arguments", __func__);
SRMSendUnAuthorizedAccessresponse(&g_policyEngineContext);
}
exit:
- //Resting PE state to AWAITING_REQUEST
+ //Resetting PE state to AWAITING_REQUEST
SetPolicyEngineState(&g_policyEngineContext, AWAITING_REQUEST);
}