#include "psinterface.h"
#include "srmresourcestrings.h"
#include "srmutility.h"
+#include "aclresource.h"
+#include "credresource.h"
+#include "ocprovisioningmanager.h"
#define TAG "OIC_SRM_PSTAT"
}
/**
+ * Checks if device can change state to Ready for Normal Operation.
+ */
+static OCEntityHandlerResult ValidateReadyForNOP(const OicSecPstat_t *pstat)
+{
+ OIC_LOG_V(DEBUG, TAG, "%s: IN", __func__);
+
+ const OicSecDoxm_t *doxm = GetDoxmResourceData();
+ OicUuid_t rowneruuid;
+
+ if (!doxm)
+ {
+ OIC_LOG(WARNING, TAG, "DOXM is NULL");
+ return OC_EH_NOT_ACCEPTABLE;
+ }
+
+ if (!doxm->owned)
+ {
+ OIC_LOG(WARNING, TAG, "Can't change state to Ready for Normal Operation: the device is unowned");
+ return OC_EH_NOT_ACCEPTABLE;
+ }
+
+ if (IsNilUuid(&doxm->owner))
+ {
+ OIC_LOG(WARNING, TAG, "Can't change state to Ready for Normal Operation: the device owner is NIL");
+ return OC_EH_INTERNAL_SERVER_ERROR;
+ }
+
+ if (IsNilUuid(&doxm->deviceID))
+ {
+ OIC_LOG(WARNING, TAG,
+ "Can't change state to Ready for Normal Operation: the device owner ID is NIL");
+ return OC_EH_INTERNAL_SERVER_ERROR;
+ }
+
+ if (IsNilUuid(&doxm->rownerID))
+ {
+ OIC_LOG(WARNING, TAG, "Can't change state to Ready for Normal Operation: the doxm rowner is NIL");
+ return OC_EH_INTERNAL_SERVER_ERROR;
+ }
+
+
+ if (IsNilUuid(&pstat->rownerID))
+ {
+ OIC_LOG(WARNING, TAG, "Can't change state to Ready for Normal Operation: the pstat rowner is NIL");
+ return OC_EH_INTERNAL_SERVER_ERROR;
+ }
+
+ memset(&rowneruuid, 0, sizeof(OicUuid_t));
+ if (OC_STACK_OK != GetAclRownerId(&rowneruuid))
+ {
+ OIC_LOG(WARNING, TAG, "Can't change state to Ready for Normal Operation: can't get acl");
+ return OC_EH_INTERNAL_SERVER_ERROR;
+ }
+
+ if (IsNilUuid(&rowneruuid))
+ {
+ OIC_LOG(WARNING, TAG, "Can't change state to Ready for Normal Operation: the acl rowner is NIL");
+ return OC_EH_INTERNAL_SERVER_ERROR;
+ }
+
+ memset(&rowneruuid, 0, sizeof(OicUuid_t));
+ if (OC_STACK_OK != GetCredRownerId(&rowneruuid))
+ {
+ OIC_LOG(WARNING, TAG, "Can't change state to Ready for Normal Operation: can't get cred");
+ return OC_EH_INTERNAL_SERVER_ERROR;
+ }
+
+ if (IsNilUuid(&rowneruuid))
+ {
+ OIC_LOG(WARNING, TAG, "Can't change state to Ready for Normal Operation: the cred rowner is NIL");
+ return OC_EH_INTERNAL_SERVER_ERROR;
+ }
+
+ OIC_LOG_V(DEBUG, TAG, "%s: OUT", __func__);
+
+ return OC_EH_OK;
+
+}
+
+/**
* The entity handler determines how to process a POST request.
* Per the REST paradigm, POST can also be used to update representation of existing
* resource or create a new resource.
}
else if (false == (pstat->cm & TAKE_OWNER) && true == pstat->isOp)
{
+ ehRet = ValidateReadyForNOP(pstat);
+ if(OC_EH_OK != ehRet)
+ {
+ goto exit;
+ }
validReq = true;
OIC_LOG (INFO, TAG, "State changed to Ready for Normal Operation");
}
* ownership transfer related resource should be revert back to initial status.
*/
const OicSecDoxm_t* doxm = GetDoxmResourceData();
- if(doxm)
+ if(doxm && !doxm->owned)
{
- if(!doxm->owned)
- {
- OIC_LOG(WARNING, TAG, "The operation failed during handle DOXM request");
+ OIC_LOG(WARNING, TAG, "The operation failed during handle DOXM request");
- if (!isDuplicatedMsg)
- {
+ if (!isDuplicatedMsg)
+ {
#if defined (__WITH_TLS__) || defined(__WITH_DTLS__)
- InvokeOtmEventHandler(ehRequest->devAddr.addr, ehRequest->devAddr.port,
+ InvokeOtmEventHandler(ehRequest->devAddr.addr, ehRequest->devAddr.port,
NULL, OIC_OTM_ERROR);
#endif
- RestoreDoxmToInitState();
- RestorePstatToInitState();
- OIC_LOG(WARNING, TAG, "DOXM will be reverted.");
- }
- }
+ RestoreDoxmToInitState();
+ RestorePstatToInitState();
+ OIC_LOG(WARNING, TAG, "DOXM will be reverted.");
+ }
}
else
{
OIC_LOG(ERROR, TAG, "Invalid DOXM resource.");
+ ResetSecureResourceInPS();
}
}
else
}
OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
}
+
+const OicUuid_t THE_NIL_UUID = {.id={0000000000000000}};
+
+/**
+ * Compares two OicUuid_t structs.
+ *
+ * @return true if the two OicUuid_t structs are equal, else false.
+ */
+bool UuidCmp(const OicUuid_t *firstId, const OicUuid_t *secondId)
+{
+ bool ret = false;
+ VERIFY_NON_NULL(TAG, firstId, ERROR);
+ VERIFY_NON_NULL(TAG, secondId, ERROR);
+
+ if (0 == memcmp(firstId, secondId, sizeof(OicUuid_t)))
+ {
+ ret = true;
+ }
+
+exit:
+ OIC_LOG_V(DEBUG, TAG, "%s: returning %s.", __func__, ret?"true":"false");
+ return ret;
+}
+
+/**
+ * Compares OicUuid_t to Nil UUID {.id={0000000000000000}}
+ *
+ * @return true if the OicUuid_t is the Nil UUID.
+ */
+bool IsNilUuid(const OicUuid_t *uuid)
+{
+#if !defined(NDEBUG)
+ char *strUuid = NULL;
+ ConvertUuidToStr(uuid, &strUuid);
+ if (strUuid)
+ {
+ OIC_LOG_V(DEBUG, TAG, "%s: uuid: %s.", __func__, strUuid);
+ OICFree(strUuid);
+ }
+#endif
+ return UuidCmp(uuid, &THE_NIL_UUID);
+}
+
#endif