return bRet;
}
+OCStackResult SetDoxmDeviceIDResetPF(const OicUuid_t *deviceID)
+{
+ OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
+
+ OCStackResult res = OC_STACK_ERROR;
+ size_t dbSize = 0;
+ uint8_t *dbData = NULL;
+ uint8_t *aclCbor = NULL;
+ uint8_t *credCbor = NULL;
+ uint8_t *pstatCbor = NULL;
+ uint8_t *doxmCbor = NULL;
+ uint8_t *resetPfCbor = NULL;
+ int64_t cborEncoderResult = CborNoError;
+
+ if (NULL == deviceID)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s - deviceID is NULL!", __func__);
+ return res;
+ }
+
+ res = GetSecureVirtualDatabaseFromPS(NULL, &dbData, &dbSize);
+ if (OC_STACK_OK != res)
+ {
+ OIC_LOG_V(ERROR, TAG, "GetSecureVirtualDatabaseFromPS() is failed(%d)", res);
+ return res;
+ }
+ if (dbData && dbSize)
+ {
+ size_t aclCborLen = 0;
+ size_t credCborLen = 0;
+ size_t pstatCborLen = 0;
+ size_t doxmCborLen = 0;
+ size_t resetPfCborLen = 0;
+ OicSecDoxm_t *tmpDoxm = NULL;
+
+ {
+ CborParser parser;
+ CborValue cbor;
+ cbor_parser_init(dbData, dbSize, 0, &parser, &cbor);
+ CborValue curVal = {0};
+ CborError cborFindResult = CborNoError;
+
+ // abort if reset profile doesn't exist
+ cborFindResult = cbor_value_map_find_value(&cbor, OIC_JSON_RESET_PF_NAME, &curVal);
+ if (CborNoError != cborFindResult || !cbor_value_is_byte_string(&curVal))
+ {
+ OIC_LOG(DEBUG, TAG, "Reset Profile doesn't exist!");
+ res=OC_STACK_ERROR;
+ goto exit;
+ }
+ cborFindResult = cbor_value_map_find_value(&cbor, OIC_JSON_ACL_NAME, &curVal);
+ if (CborNoError == cborFindResult && cbor_value_is_byte_string(&curVal))
+ {
+ cborFindResult = cbor_value_dup_byte_string(&curVal, &aclCbor, &aclCborLen, NULL);
+ VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding ACL Name Value.");
+ }
+ cborFindResult = cbor_value_map_find_value(&cbor, OIC_JSON_CRED_NAME, &curVal);
+ if (CborNoError == cborFindResult && cbor_value_is_byte_string(&curVal))
+ {
+ cborFindResult = cbor_value_dup_byte_string(&curVal, &credCbor, &credCborLen, NULL);
+ VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding CRED Name Value.");
+ }
+ cborFindResult = cbor_value_map_find_value(&cbor, OIC_JSON_PSTAT_NAME, &curVal);
+ if (CborNoError == cborFindResult && cbor_value_is_byte_string(&curVal))
+ {
+ cborFindResult = cbor_value_dup_byte_string(&curVal, &pstatCbor, &pstatCborLen, NULL);
+ VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding PSTAT Name Value.");
+ }
+ cborFindResult = cbor_value_map_find_value(&cbor, OIC_JSON_DOXM_NAME, &curVal);
+ if (CborNoError == cborFindResult && cbor_value_is_byte_string(&curVal))
+ {
+ cborFindResult = cbor_value_dup_byte_string(&curVal, &doxmCbor, &doxmCborLen, NULL);
+ VERIFY_CBOR_SUCCESS(TAG, cborFindResult, "Failed Finding DOXM Name Value.");
+
+ res = CBORPayloadToDoxm(doxmCbor, doxmCborLen, &tmpDoxm);
+ if (OC_STACK_OK != res)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s - CBORPayloadToDoxm error : %d", __func__, res);
+ goto exit;
+ }
+ VERIFY_NON_NULL(TAG, tmpDoxm, ERROR);
+ memcpy(tmpDoxm->deviceID.id, deviceID->id, sizeof(deviceID->id));
+ OICFree(doxmCbor);
+ doxmCbor = NULL;
+ doxmCborLen = 0;
+ res = DoxmToCBORPayload(tmpDoxm, &doxmCbor, &doxmCborLen, false);
+ if (OC_STACK_OK != res || 0 == doxmCborLen || NULL == doxmCbor)
+ {
+ OIC_LOG_V(ERROR, TAG,"%s - DoxmToCBORPayload error : %d", __func__, res);
+ goto exit;
+ }
+ }
+ }
+
+ {
+ size_t size = aclCborLen + credCborLen + pstatCborLen + doxmCborLen + 255;
+ resetPfCbor = (uint8_t *) OICCalloc(1, size);
+ VERIFY_NON_NULL(TAG, resetPfCbor, ERROR);
+ CborEncoder encoder; // will be initialized in |cbor_parser_init|
+ cbor_encoder_init(&encoder, resetPfCbor, size, 0);
+ CborEncoder secRsrc; // will be initialized in |cbor_encoder_create_map|
+ cborEncoderResult |= cbor_encoder_create_map(&encoder, &secRsrc, CborIndefiniteLength);
+
+ cborEncoderResult |= cbor_encode_text_string(&secRsrc, OIC_JSON_ACL_NAME, strlen(OIC_JSON_ACL_NAME));
+ VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding ACL Name.");
+ cborEncoderResult |= cbor_encode_byte_string(&secRsrc, aclCbor, aclCborLen);
+ VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding ACL Value.");
+
+ if (credCborLen)
+ {
+ cborEncoderResult |= cbor_encode_text_string(&secRsrc, OIC_JSON_CRED_NAME, strlen(OIC_JSON_CRED_NAME));
+ VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding CRED Name.");
+ cborEncoderResult |= cbor_encode_byte_string(&secRsrc, credCbor, credCborLen);
+ VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding CRED Value.");
+ }
+
+ cborEncoderResult |= cbor_encode_text_string(&secRsrc, OIC_JSON_PSTAT_NAME, strlen(OIC_JSON_PSTAT_NAME));
+ VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding PSTAT Name.");
+ cborEncoderResult |= cbor_encode_byte_string(&secRsrc, pstatCbor, pstatCborLen);
+ VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding PSTAT Value.");
+
+ cborEncoderResult |= cbor_encode_text_string(&secRsrc, OIC_JSON_DOXM_NAME, strlen(OIC_JSON_DOXM_NAME));
+ VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding Doxm Name.");
+ cborEncoderResult |= cbor_encode_byte_string(&secRsrc, doxmCbor, doxmCborLen);
+ VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Adding Doxm Value.");
+
+ cborEncoderResult |= cbor_encoder_close_container(&encoder, &secRsrc);
+ VERIFY_CBOR_SUCCESS(TAG, cborEncoderResult, "Failed Closing Array.");
+ resetPfCborLen = cbor_encoder_get_buffer_size(&encoder, resetPfCbor);
+ }
+
+ res = UpdateSecureResourceInPS(OIC_JSON_RESET_PF_NAME, resetPfCbor, resetPfCborLen);
+ if (OC_STACK_OK != res)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s - Error in UpdateSecureResourceInPS", __func__);
+ }
+ }
+ OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
+
+exit:
+ OICFree(dbData);
+ OICFree(aclCbor);
+ OICFree(credCbor);
+ OICFree(pstatCbor);
+ OICFree(doxmCbor);
+ OICFree(resetPfCbor);
+
+ return res;
+}
+
static bool ValidateQuery(const char * query)
{
// Send doxm resource data if the state of doxm resource