#include "srmutility.h"
#include "provisioningdatabasemanager.h"
#include "oxmrandompin.h"
+#include "ocpayload.h"
+#include "payload_logging.h"
#define TAG "OTM"
static OTMCallbackData_t g_OTMDatas[OIC_OXM_COUNT];
/**
- * Variable for storing provisioning tool's provisioning capabilities
- * Must be in decreasing order of preference. More prefered method should
- * have lower array index.
- */
-static OicSecDpom_t gProvisioningToolCapability[] = { SINGLE_SERVICE_CLIENT_DRIVEN };
-
-/**
- * Number of supported provisioning methods
- * current version supports only one.
- */
-static size_t gNumOfProvisioningMethodsPT = 1;
-
-/**
* Variables for pointing the OTMContext to be used in the DTLS handshake result callback.
*/
static OTMContext_t* g_otmCtx = NULL;
* @return OC_STACK_OK on success
*/
static OCStackResult SelectProvisioningMethod(const OicSecOxm_t *supportedMethods,
- size_t numberOfMethods,
- OicSecOxm_t *selectedMethod)
+ size_t numberOfMethods, OicSecOxm_t *selectedMethod)
{
OIC_LOG(DEBUG, TAG, "IN SelectProvisioningMethod");
OicSecDpom_t *selectedMode)
{
OIC_LOG(DEBUG, TAG, "IN SelectOperationMode");
-
- size_t i = 0;
- size_t j = 0;
-
- while (i < gNumOfProvisioningMethodsPT && j < selectedDeviceInfo->pstat->smLen)
- {
- if (gProvisioningToolCapability[i] < selectedDeviceInfo->pstat->sm[j])
- {
- i++;
- }
- else if (selectedDeviceInfo->pstat->sm[j] < gProvisioningToolCapability[i])
- {
- j++;
- }
- else /* if gProvisioningToolCapability[i] == deviceSupportedMethods[j] */
- {
- *selectedMode = gProvisioningToolCapability[j];
- break;
- }
- }
+ *selectedMode = selectedDeviceInfo->pstat->sm[0];
OIC_LOG_V(DEBUG, TAG, "Selected Operation Mode = %d", *selectedMode);
-
- OIC_LOG(DEBUG, TAG, "OUT SelectOperationMode");
}
/**
* @param[in] otmCtx Context value of ownership transfer.
* @return OC_STACK_OK on success
*/
-static OCStackResult PutOwnerTransferModeToResource(OTMContext_t* otmCtx);
+static OCStackResult PostOwnerTransferModeToResource(OTMContext_t* otmCtx);
/**
* Function to send request to resource to get its pstat resource information.
* @param[in] otmCtx Context value of ownership transfer.
* @return OC_STACK_OK on success
*/
-static OCStackResult PutOwnerUuid(OTMContext_t* otmCtx);
+static OCStackResult PostOwnerUuid(OTMContext_t* otmCtx);
/**
* Function to update the operation mode. As per the spec. Operation mode in client driven
* @param[in] otmCtx Context value of ownership transfer.
* @return OC_STACK_OK on success
*/
-static OCStackResult PutUpdateOperationMode(OTMContext_t* otmCtx);
+static OCStackResult PostUpdateOperationMode(OTMContext_t* otmCtx);
/**
* Function to update the owner credential to new device
* @param[in] otmCtx Context value of ownership transfer.
* @return OC_STACK_OK on success
*/
-static OCStackResult PutOwnershipInformation(OTMContext_t* otmCtx);
+static OCStackResult PostOwnershipInformation(OTMContext_t* otmCtx);
/**
- * Function to update pstat when finalize provisioning.
- * This function would update 'cm' as bx0011,1100 and 'tm' as bx0000,0000.
+ * Function to update pstat as Ready for provisioning.
+ * This function would update 'cm' from bx0000,0010 to bx0000,0000.
*
* @param[in] ctx context value passed to callback from calling function.
* @param[in] selectedDevice selected device information to performing provisioning.
* @return OC_STACK_OK on success
*/
-static OCStackResult PutProvisioningStatus(OTMContext_t* otmCtx);
+static OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx);
-/*
- * Function to finalize provisioning.
- * This function will send default ACL and commit hash.
+/**
+ * Function to update pstat as Ready for Normal Operation.
+ * This function would update 'isop' from false to true.
*
- * @param[in] otmCtx Context value of ownership transfer.
+ * @param[in] ctx context value passed to callback from calling function.
+ * @param[in] selectedDevice selected device information to performing provisioning.
* @return OC_STACK_OK on success
*/
-static OCStackResult FinalizeProvisioning(OTMContext_t* otmCtx);
-
+static OCStackResult PostNormalOperationStatus(OTMContext_t* otmCtx);
static bool IsComplete(OTMContext_t* otmCtx)
{
false == newDevDoxm->owned &&
memcmp(&(newDevDoxm->owner), &emptyUuid, sizeof(OicUuid_t)) == 0)
{
- //Send request : PUT /oic/sec/doxm [{... , "devowner":"PT's UUID"}]
- res = PutOwnerUuid(g_otmCtx);
+ //Send request : POST /oic/sec/doxm [{... , "devowner":"PT's UUID"}]
+ res = PostOwnerUuid(g_otmCtx);
if(OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "OperationModeUpdate : Failed to send owner information");
}
uint8_t ownerPSK[OWNER_PSK_LENGTH_128] = {0};
+ OicSecKey_t ownerKey = {ownerPSK, OWNER_PSK_LENGTH_128};
//Generating OwnerPSK
CAResult_t pskRet = CAGenerateOwnerPSK(&endpoint,
OIC_LOG(INFO, TAG,"ownerPSK dump:\n");
OIC_LOG_BUFFER(INFO, TAG,ownerPSK, OWNER_PSK_LENGTH_128);
//Generating new credential for provisioning tool
- size_t ownLen = 1;
- uint32_t outLen = 0;
-
- char base64Buff[B64ENCODE_OUT_SAFESIZE(sizeof(ownerPSK)) + 1] = {};
- B64Result b64Ret = b64Encode(ownerPSK, sizeof(ownerPSK), base64Buff, sizeof(base64Buff),
- &outLen);
- VERIFY_SUCCESS(TAG, B64_OK == b64Ret, ERROR);
-
OicSecCred_t *cred = GenerateCredential(&selectedDeviceInfo->doxm->deviceID,
SYMMETRIC_PAIR_WISE_KEY, NULL,
- base64Buff, ownLen, &ptDeviceID);
+ &ownerKey, &ptDeviceID);
VERIFY_NON_NULL(TAG, cred, ERROR);
res = AddCredential(cred);
SetResult(otmCtx, OC_STACK_ERROR);
return OC_STACK_DELETE_TRANSACTION;
}
-
- OicSecPstat_t* pstat = JSONToPstatBin(
- ((OCSecurityPayload*)clientResponse->payload)->securityData);
- if(NULL == pstat)
+ OicSecPstat_t* pstat = NULL;
+ OCStackResult result = CBORPayloadToPstat(
+ ((OCSecurityPayload*)clientResponse->payload)->securityData,
+ ((OCSecurityPayload*)clientResponse->payload)->payloadSize,
+ &pstat);
+ if(NULL == pstat || result != OC_STACK_OK)
{
- OIC_LOG(ERROR, TAG, "Error while converting json to pstat bin");
+ OIC_LOG(ERROR, TAG, "Error while converting cbor to pstat.");
+ SetResult(otmCtx, OC_STACK_ERROR);
+ return OC_STACK_DELETE_TRANSACTION;
+ }
+ if(false == (TAKE_OWNER & pstat->cm))
+ {
+ OIC_LOG(ERROR, TAG, "Device pairing mode enabling owner transfer operations is disabled");
SetResult(otmCtx, OC_STACK_ERROR);
return OC_STACK_DELETE_TRANSACTION;
}
//Select operation mode (Currently supported SINGLE_SERVICE_CLIENT_DRIVEN only)
SelectOperationMode(otmCtx->selectedDeviceInfo, &(otmCtx->selectedDeviceInfo->pstat->om));
- //Send request : PUT /oic/sec/pstat [{"om":"bx11", .. }]
- OCStackResult res = PutUpdateOperationMode(otmCtx);
+ //Send request : POST /oic/sec/pstat [{"om":"bx11", .. }]
+ OCStackResult res = PostUpdateOperationMode(otmCtx);
if (OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "Error while updating operation mode.");
}
}
- //PUT /oic/sec/doxm [{ ..., "owned":"TRUE" }]
- res = PutOwnershipInformation(otmCtx);
+ //POST /oic/sec/doxm [{ ..., "owned":"TRUE" }]
+ res = PostOwnershipInformation(otmCtx);
if(OC_STACK_OK != res)
{
- OIC_LOG(ERROR, TAG, "Failed to put ownership information to new device");
+ OIC_LOG(ERROR, TAG, "Failed to post ownership information to new device");
SetResult(otmCtx, res);
return OC_STACK_DELETE_TRANSACTION;
}
if(otmCtx && otmCtx->selectedDeviceInfo)
{
OIC_LOG(INFO, TAG, "Ownership transfer was successfully completed.");
- OIC_LOG(INFO, TAG, "Start defualt ACL & commit-hash provisioning.");
+ OIC_LOG(INFO, TAG, "Set Ready for provisioning state .");
- res = PutProvisioningStatus(otmCtx);
+ res = PostProvisioningStatus(otmCtx);
if(OC_STACK_OK != res)
{
OIC_LOG(ERROR, TAG, "Failed to update pstat");
VERIFY_NON_NULL(TAG, clientResponse, ERROR);
VERIFY_NON_NULL(TAG, ctx, ERROR);
- OTMContext_t* otmCtx = (OTMContext_t*)ctx;
+ OTMContext_t* otmCtx = (OTMContext_t*) ctx;
(void)UNUSED;
+ OCStackResult res = OC_STACK_OK;
+
if(OC_STACK_OK == clientResponse->result)
{
- OCStackResult res = FinalizeProvisioning(otmCtx);
- if (OC_STACK_OK != res)
- {
- OIC_LOG_V(INFO, TAG, "Failed to finalize provisioning.");
+ if(otmCtx && otmCtx->selectedDeviceInfo)
+ {
+ OIC_LOG(INFO, TAG, "Device state is in Ready for Provisionig.");
+
+ res = PostNormalOperationStatus(otmCtx);
+ if(OC_STACK_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "Failed to update pstat");
SetResult(otmCtx, res);
- return OC_STACK_DELETE_TRANSACTION;
- }
+ }
+ }
+ }
+ else
+ {
+ OIC_LOG_V(INFO, TAG, "Error occured in provisionDefaultACLCB :: %d\n",
+ clientResponse->result);
+ SetResult(otmCtx, clientResponse->result);
}
exit:
}
/**
- * Callback handler of finalize provisioning.
+ * Response handler of update provisioning status to Ready for Normal..
*
* @param[in] ctx ctx value passed to callback from calling function.
* @param[in] UNUSED handle to an invocation
* @return OC_STACK_DELETE_TRANSACTION to delete the transaction
* and OC_STACK_KEEP_TRANSACTION to keep it.
*/
-static OCStackApplicationResult FinalizeProvisioningCB(void *ctx, OCDoHandle UNUSED,
+static OCStackApplicationResult ReadyForNomalStatusHandler(void *ctx, OCDoHandle UNUSED,
OCClientResponse *clientResponse)
{
- OIC_LOG_V(INFO, TAG, "IN ProvisionDefaultACLCB.");
+ OIC_LOG_V(INFO, TAG, "IN ReadyForNomalStatusHandler.");
VERIFY_NON_NULL(TAG, clientResponse, ERROR);
VERIFY_NON_NULL(TAG, ctx, ERROR);
OTMContext_t* otmCtx = (OTMContext_t*) ctx;
(void)UNUSED;
- if (OC_STACK_RESOURCE_CREATED == clientResponse->result)
+ if (OC_STACK_OK == clientResponse->result)
{
+ OIC_LOG(INFO, TAG, "Device state is in Ready for Normal Operation.");
OCStackResult res = PDMAddDevice(&otmCtx->selectedDeviceInfo->doxm->deviceID);
if (OC_STACK_OK == res)
{
clientResponse->result);
SetResult(otmCtx, clientResponse->result);
}
+
exit:
+ OIC_LOG_V(INFO, TAG, "OUT ReadyForNomalStatusHandler.");
return OC_STACK_DELETE_TRANSACTION;
}
//Generate owner credential for new device
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
- OicSecCred_t* ownerCredential =
- GetCredResourceData(&(deviceInfo->doxm->deviceID));
+ const OicSecCred_t* ownerCredential = GetCredResourceData(&(deviceInfo->doxm->deviceID));
if(!ownerCredential)
{
OIC_LOG(ERROR, TAG, "Can not find OwnerPSK.");
//Fill private data as empty string
newCredential.privateData.data = NULL;
+ newCredential.privateData.len = 0;
+#ifdef __WITH_X509__
+ newCredential.publicData.data = NULL;
+ newCredential.publicData.len = 0;
+#endif
//Send owner credential to new device : PUT /oic/sec/cred [ owner credential ]
- secPayload->securityData = BinToCredJSON(&newCredential);
- if (NULL == secPayload->securityData)
+ if (OC_STACK_OK != CredToCBORPayload(&newCredential, &secPayload->securityData, &secPayload->payloadSize))
{
OICFree(secPayload);
- OIC_LOG(ERROR, TAG, "Error while converting bin to json");
+ OIC_LOG(ERROR, TAG, "Error while converting bin to cbor.");
return OC_STACK_ERROR;
}
- OIC_LOG_V(DEBUG, TAG, "Payload : %s", secPayload->securityData);
+ OIC_LOG(DEBUG, TAG, "Cred Payload:");
+ OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
OCCallbackData cbData;
cbData.cb = &OwnerCredentialHandler;
cbData.cd = NULL;
OCStackResult res = OCDoResource(NULL, OC_REST_PUT, query,
&deviceInfo->endpoint, (OCPayload*)secPayload,
- deviceInfo->connType, OC_LOW_QOS, &cbData, NULL, 0);
+ deviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
if (res != OC_STACK_OK)
{
OIC_LOG(ERROR, TAG, "OCStack resource error");
return OC_STACK_OK;
}
-static OCStackResult PutOwnerTransferModeToResource(OTMContext_t* otmCtx)
+static OCStackResult PostOwnerTransferModeToResource(OTMContext_t* otmCtx)
{
- OIC_LOG(DEBUG, TAG, "IN PutOwnerTransferModeToResource");
+ OIC_LOG(DEBUG, TAG, "IN PostOwnerTransferModeToResource");
if(!otmCtx || !otmCtx->selectedDeviceInfo)
{
deviceInfo->connType,
query, sizeof(query), OIC_RSRC_DOXM_URI))
{
- OIC_LOG(ERROR, TAG, "PutOwnerTransferModeToResource : Failed to generate query");
+ OIC_LOG(ERROR, TAG, "PostOwnerTransferModeToResource : Failed to generate query");
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
- secPayload->securityData = g_OTMDatas[selectedOxm].createSelectOxmPayloadCB(otmCtx);
- if (NULL == secPayload->securityData)
+ OCStackResult res = g_OTMDatas[selectedOxm].createSelectOxmPayloadCB(otmCtx,
+ &secPayload->securityData, &secPayload->payloadSize);
+ if (OC_STACK_OK != res && NULL == secPayload->securityData)
{
- OICFree(secPayload);
- OIC_LOG(ERROR, TAG, "Error while converting bin to json");
+ OCPayloadDestroy((OCPayload *)secPayload);
+ OIC_LOG(ERROR, TAG, "Error while converting bin to cbor");
return OC_STACK_ERROR;
}
cbData.cb = &OwnerTransferModeHandler;
cbData.context = (void *)otmCtx;
cbData.cd = NULL;
- OCStackResult res = OCDoResource(NULL, OC_REST_PUT, query,
- &deviceInfo->endpoint, (OCPayload*)secPayload,
- deviceInfo->connType, OC_LOW_QOS, &cbData, NULL, 0);
+ res = OCDoResource(NULL, OC_REST_POST, query,
+ &deviceInfo->endpoint, (OCPayload *)secPayload,
+ deviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
if (res != OC_STACK_OK)
{
OIC_LOG(ERROR, TAG, "OCStack resource error");
}
- OIC_LOG(DEBUG, TAG, "OUT PutOwnerTransferModeToResource");
+ OIC_LOG(DEBUG, TAG, "OUT PostOwnerTransferModeToResource");
return res;
}
cbData.context = (void *)otmCtx;
cbData.cd = NULL;
OCStackResult res = OCDoResource(NULL, OC_REST_GET, query, NULL, NULL,
- deviceInfo->connType, OC_LOW_QOS, &cbData, NULL, 0);
+ deviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
if (res != OC_STACK_OK)
{
OIC_LOG(ERROR, TAG, "OCStack resource error");
return res;
}
-static OCStackResult PutOwnerUuid(OTMContext_t* otmCtx)
+static OCStackResult PostOwnerUuid(OTMContext_t* otmCtx)
{
- OIC_LOG(DEBUG, TAG, "IN PutOwnerUuid");
+ OIC_LOG(DEBUG, TAG, "IN PostOwnerUuid");
if(!otmCtx || !otmCtx->selectedDeviceInfo)
{
deviceInfo->connType,
query, sizeof(query), OIC_RSRC_DOXM_URI))
{
- OIC_LOG(ERROR, TAG, "PutOwnershipInformation : Failed to generate query");
+ OIC_LOG(ERROR, TAG, "PostOwnerUuid : Failed to generate query");
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
- //PUT PT's uuid to new device
+ //Post PT's uuid to new device
OCSecurityPayload* secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
if(!secPayload)
{
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
- secPayload->securityData =
- g_OTMDatas[deviceInfo->doxm->oxmSel].createOwnerTransferPayloadCB(otmCtx);
- if (NULL == secPayload->securityData)
+ OCStackResult res = g_OTMDatas[deviceInfo->doxm->oxmSel].createOwnerTransferPayloadCB(
+ otmCtx, &secPayload->securityData, &secPayload->payloadSize);
+ if (OC_STACK_OK != res && NULL == secPayload->securityData)
{
- OICFree(secPayload);
- OIC_LOG(ERROR, TAG, "Error while converting doxm bin to json");
+ OCPayloadDestroy((OCPayload *)secPayload);
+ OIC_LOG(ERROR, TAG, "Error while converting doxm bin to cbor.");
return OC_STACK_INVALID_PARAM;
}
- OIC_LOG_V(DEBUG, TAG, "Payload : %s", secPayload->securityData);
+ OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
OCCallbackData cbData;
cbData.cb = &OwnerUuidUpdateHandler;
cbData.context = (void *)otmCtx;
cbData.cd = NULL;
- OCStackResult res = OCDoResource(NULL, OC_REST_PUT, query, 0, (OCPayload*)secPayload,
- deviceInfo->connType, OC_LOW_QOS, &cbData, NULL, 0);
+ res = OCDoResource(NULL, OC_REST_POST, query, 0, (OCPayload *)secPayload,
+ deviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
if (res != OC_STACK_OK)
{
OIC_LOG(ERROR, TAG, "OCStack resource error");
}
- OIC_LOG(DEBUG, TAG, "OUT PutOwnerUuid");
+ OIC_LOG(DEBUG, TAG, "OUT PostOwnerUuid");
return res;
}
-static OCStackResult PutOwnershipInformation(OTMContext_t* otmCtx)
+static OCStackResult PostOwnershipInformation(OTMContext_t* otmCtx)
{
- OIC_LOG(DEBUG, TAG, "IN PutOwnershipInformation");
+ OIC_LOG(DEBUG, TAG, "IN PostOwnershipInformation");
if(!otmCtx || !otmCtx->selectedDeviceInfo)
{
deviceInfo->connType,
query, sizeof(query), OIC_RSRC_DOXM_URI))
{
- OIC_LOG(ERROR, TAG, "PutOwnershipInformation : Failed to generate query");
+ OIC_LOG(ERROR, TAG, "PostOwnershipInformation : Failed to generate query");
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
//OwnershipInformationHandler
- OCSecurityPayload* secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
- if(!secPayload)
+ OCSecurityPayload *secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
+ if (!secPayload)
{
OIC_LOG(ERROR, TAG, "Failed to memory allocation");
return OC_STACK_NO_MEMORY;
}
otmCtx->selectedDeviceInfo->doxm->owned = true;
- secPayload->securityData = BinToDoxmJSON(otmCtx->selectedDeviceInfo->doxm);
- if (NULL == secPayload->securityData)
+
+ secPayload->base.type = PAYLOAD_TYPE_SECURITY;
+ OCStackResult res = DoxmToCBORPayload(otmCtx->selectedDeviceInfo->doxm,
+ &secPayload->securityData, &secPayload->payloadSize);
+ if (OC_STACK_OK != res && NULL == secPayload->securityData)
{
- OICFree(secPayload);
+ OCPayloadDestroy((OCPayload *)secPayload);
OIC_LOG(ERROR, TAG, "Error while converting doxm bin to json");
return OC_STACK_INVALID_PARAM;
}
- secPayload->base.type = PAYLOAD_TYPE_SECURITY;
OCCallbackData cbData;
cbData.cb = &OwnershipInformationHandler;
cbData.context = (void *)otmCtx;
cbData.cd = NULL;
- OCStackResult res = OCDoResource(NULL, OC_REST_PUT, query, 0, (OCPayload*)secPayload,
- deviceInfo->connType, OC_LOW_QOS, &cbData, NULL, 0);
+ res = OCDoResource(NULL, OC_REST_POST, query, 0, (OCPayload*)secPayload,
+ deviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
if (res != OC_STACK_OK)
{
OIC_LOG(ERROR, TAG, "OCStack resource error");
}
- OIC_LOG(DEBUG, TAG, "OUT PutOwnershipInformation");
+ OIC_LOG(DEBUG, TAG, "OUT PostOwnershipInformation");
return res;
}
-static OCStackResult PutUpdateOperationMode(OTMContext_t* otmCtx)
+static OCStackResult PostUpdateOperationMode(OTMContext_t* otmCtx)
{
- OIC_LOG(DEBUG, TAG, "IN PutUpdateOperationMode");
+ OIC_LOG(DEBUG, TAG, "IN PostUpdateOperationMode");
if(!otmCtx || !otmCtx->selectedDeviceInfo)
{
deviceInfo->connType,
query, sizeof(query), OIC_RSRC_PSTAT_URI))
{
- OIC_LOG(ERROR, TAG, "PutUpdateOperationMode : Failed to generate query");
+ OIC_LOG(ERROR, TAG, "PostUpdateOperationMode : Failed to generate query");
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
- secPayload->securityData = BinToPstatJSON(deviceInfo->pstat);
- if (NULL == secPayload->securityData)
+ OCStackResult res = PstatToCBORPayload(deviceInfo->pstat, &secPayload->securityData,
+ &secPayload->payloadSize);
+ if (OC_STACK_OK != res)
{
- OICFree(secPayload);
- OIC_LOG(ERROR, TAG, "Error while converting pstat bin to json");
+ OCPayloadDestroy((OCPayload *)secPayload);
+ OIC_LOG(ERROR, TAG, "Error while converting pstat to cbor.");
return OC_STACK_INVALID_PARAM;
}
cbData.cb = &OperationModeUpdateHandler;
cbData.context = (void *)otmCtx;
cbData.cd = NULL;
- OCStackResult res = OCDoResource(NULL, OC_REST_PUT, query, 0, (OCPayload*)secPayload,
- deviceInfo->connType, OC_LOW_QOS, &cbData, NULL, 0);
+ res = OCDoResource(NULL, OC_REST_POST, query, 0, (OCPayload *)secPayload,
+ deviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
if (res != OC_STACK_OK)
{
OIC_LOG(ERROR, TAG, "OCStack resource error");
}
- OIC_LOG(DEBUG, TAG, "OUT PutUpdateOperationMode");
+ OIC_LOG(DEBUG, TAG, "OUT PostUpdateOperationMode");
return res;
}
}
OIC_LOG_V(DEBUG, TAG, "Selected provisoning method = %d", selectedDevice->doxm->oxmSel);
- //Send Req: PUT /oic/sec/doxm [{..."OxmSel" :g_OTMDatas[Index of Selected OxM].OXMString,...}]
- res = PutOwnerTransferModeToResource(otmCtx);
+ //Send Req: POST /oic/sec/doxm [{..."OxmSel" :g_OTMDatas[Index of Selected OxM].OXMString,...}]
+ res = PostOwnerTransferModeToResource(otmCtx);
if(OC_STACK_OK != res)
{
OIC_LOG(WARNING, TAG, "Failed to select the provisioning method");
OICFree(otmCtx->ctxResultArray);
OICFree(otmCtx);
return res;
-
}
-OCStackResult PutProvisioningStatus(OTMContext_t* otmCtx)
+OCStackResult PostProvisioningStatus(OTMContext_t* otmCtx)
{
- OIC_LOG(INFO, TAG, "IN PutProvisioningStatus");
+ OIC_LOG(INFO, TAG, "IN PostProvisioningStatus");
- if(!otmCtx)
+ if(!otmCtx || !otmCtx->selectedDeviceInfo)
{
OIC_LOG(ERROR, TAG, "OTMContext is NULL");
return OC_STACK_INVALID_PARAM;
}
- if(!otmCtx->selectedDeviceInfo)
- {
- OIC_LOG(ERROR, TAG, "Can't find device information in OTMContext");
- OICFree(otmCtx);
- return OC_STACK_INVALID_PARAM;
- }
- otmCtx->selectedDeviceInfo->pstat->tm = NORMAL;
- otmCtx->selectedDeviceInfo->pstat->cm = PROVISION_ACLS | PROVISION_CREDENTIALS |
- SECURITY_MANAGEMENT_SERVICES | BOOTSTRAP_SERVICE;
- OCSecurityPayload* secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
- if(!secPayload)
+ //Change the TAKE_OWNER bit of CM to 0.
+ otmCtx->selectedDeviceInfo->pstat->cm &= (~TAKE_OWNER);
+
+ OCSecurityPayload *secPayload = (OCSecurityPayload *)OICCalloc(1, sizeof(OCSecurityPayload));
+ if (!secPayload)
{
OIC_LOG(ERROR, TAG, "Failed to memory allocation");
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
- secPayload->securityData = BinToPstatJSON(otmCtx->selectedDeviceInfo->pstat);
- if (NULL == secPayload->securityData)
+ if (OC_STACK_OK != PstatToCBORPayload(otmCtx->selectedDeviceInfo->pstat,
+ &secPayload->securityData, &secPayload->payloadSize))
{
- OICFree(secPayload);
- SetResult(otmCtx, OC_STACK_INVALID_JSON);
+ OCPayloadDestroy((OCPayload *)secPayload);
return OC_STACK_INVALID_JSON;
}
- OIC_LOG_V(INFO, TAG, "Created payload for commit hash: %s",secPayload->securityData);
+ OIC_LOG(DEBUG, TAG, "Created payload for chage to Provisiong state");
+ OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
if(!PMGenerateQuery(true,
otmCtx->selectedDeviceInfo->connType,
query, sizeof(query), OIC_RSRC_PSTAT_URI))
{
- OIC_LOG(ERROR, TAG, "PutProvisioningStatus : Failed to generate query");
+ OIC_LOG(ERROR, TAG, "PostProvisioningStatus : Failed to generate query");
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
cbData.cb = &ProvisioningStatusHandler;
cbData.context = (void*)otmCtx;
cbData.cd = NULL;
- OCStackResult ret = OCDoResource(NULL, OC_REST_PUT, query, 0, (OCPayload*)secPayload,
+ OCStackResult ret = OCDoResource(NULL, OC_REST_POST, query, 0, (OCPayload*)secPayload,
otmCtx->selectedDeviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
OIC_LOG_V(INFO, TAG, "OCDoResource returned: %d",ret);
if (ret != OC_STACK_OK)
{
OIC_LOG(ERROR, TAG, "OCStack resource error");
- SetResult(otmCtx, ret);
}
- OIC_LOG(INFO, TAG, "OUT PutProvisioningStatus");
+ OIC_LOG(INFO, TAG, "OUT PostProvisioningStatus");
return ret;
}
-OCStackResult FinalizeProvisioning(OTMContext_t* otmCtx)
+OCStackResult PostNormalOperationStatus(OTMContext_t* otmCtx)
{
- OIC_LOG(INFO, TAG, "IN FinalizeProvisioning");
+ OIC_LOG(INFO, TAG, "IN PostNormalOperationStatus");
- if(!otmCtx)
+ if(!otmCtx || !otmCtx->selectedDeviceInfo)
{
OIC_LOG(ERROR, TAG, "OTMContext is NULL");
return OC_STACK_INVALID_PARAM;
}
- if(!otmCtx->selectedDeviceInfo)
- {
- OIC_LOG(ERROR, TAG, "Can't find device information in OTMContext");
- OICFree(otmCtx);
- return OC_STACK_INVALID_PARAM;
- }
- // Provision Default ACL to device
- OicSecAcl_t defaultAcl =
- { {.id={0}},
- 1,
- NULL,
- 0x001F,
- 0,
- NULL,
- NULL,
- 1,
- NULL,
- NULL,
- };
-
- OicUuid_t provTooldeviceID = {.id={0}};
- if (OC_STACK_OK != GetDoxmDeviceID(&provTooldeviceID))
- {
- OIC_LOG(ERROR, TAG, "Error while retrieving provisioning tool's device ID");
- SetResult(otmCtx, OC_STACK_ERROR);
- return OC_STACK_ERROR;
- }
- OIC_LOG(INFO, TAG, "Retieved deviceID");
- memcpy(defaultAcl.subject.id, provTooldeviceID.id, sizeof(defaultAcl.subject.id));
- char *wildCardResource = "*";
- defaultAcl.resources = &wildCardResource;
- defaultAcl.owners = (OicUuid_t *) OICCalloc(1, UUID_LENGTH);
- if(!defaultAcl.owners)
- {
- OIC_LOG(ERROR, TAG, "Failed to memory allocation for default ACL");
- SetResult(otmCtx, OC_STACK_NO_MEMORY);
- return OC_STACK_NO_MEMORY;
- }
- memcpy(defaultAcl.owners->id, provTooldeviceID.id, UUID_LENGTH);
- OIC_LOG(INFO, TAG, "Provisioning default ACL");
+ //Set isop to true.
+ otmCtx->selectedDeviceInfo->pstat->isOp = true;
- OCSecurityPayload* secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
- if(!secPayload)
+ OCSecurityPayload *secPayload = (OCSecurityPayload *)OICCalloc(1, sizeof(OCSecurityPayload));
+ if (!secPayload)
{
OIC_LOG(ERROR, TAG, "Failed to memory allocation");
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
- secPayload->securityData = BinToAclJSON(&defaultAcl);
- OICFree(defaultAcl.owners);
- if(!secPayload->securityData)
+ if (OC_STACK_OK != PstatToCBORPayload(otmCtx->selectedDeviceInfo->pstat,
+ &secPayload->securityData, &secPayload->payloadSize))
{
- OICFree(secPayload);
- OIC_LOG(INFO, TAG, "FinalizeProvisioning : Failed to BinToAclJSON");
- SetResult(otmCtx, OC_STACK_ERROR);
- return OC_STACK_ERROR;
+ OCPayloadDestroy((OCPayload *)secPayload);
+ return OC_STACK_INVALID_JSON;
}
- OIC_LOG_V(INFO, TAG, "Provisioning default ACL : %s",secPayload->securityData);
+ OIC_LOG(DEBUG, TAG, "Created payload for chage to Provisiong state");
+ OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
if(!PMGenerateQuery(true,
otmCtx->selectedDeviceInfo->endpoint.addr,
otmCtx->selectedDeviceInfo->securePort,
otmCtx->selectedDeviceInfo->connType,
- query, sizeof(query), OIC_RSRC_ACL_URI))
+ query, sizeof(query), OIC_RSRC_PSTAT_URI))
{
- OIC_LOG(ERROR, TAG, "FinalizeProvisioning : Failed to generate query");
+ OIC_LOG(ERROR, TAG, "PostNormalOperationStatus : Failed to generate query");
return OC_STACK_ERROR;
}
OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
- OIC_LOG_V(INFO, TAG, "Request URI for Provisioning default ACL : %s", query);
-
- OCCallbackData cbData = {.context=NULL, .cb=NULL, .cd=NULL};
- cbData.cb = &FinalizeProvisioningCB;
- cbData.context = (void *)otmCtx;
+ OCCallbackData cbData = {.context=NULL, .cb=NULL, .cd=NULL};
+ cbData.cb = &ReadyForNomalStatusHandler;
+ cbData.context = (void*)otmCtx;
cbData.cd = NULL;
- OCStackResult ret = OCDoResource(NULL, OC_REST_POST, query,
- &otmCtx->selectedDeviceInfo->endpoint, (OCPayload*)secPayload,
+ OCStackResult ret = OCDoResource(NULL, OC_REST_POST, query, 0, (OCPayload*)secPayload,
otmCtx->selectedDeviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
- if (OC_STACK_OK != ret)
+ OIC_LOG_V(INFO, TAG, "OCDoResource returned: %d",ret);
+ if (ret != OC_STACK_OK)
{
- SetResult(otmCtx, ret);
- return ret;
+ OIC_LOG(ERROR, TAG, "OCStack resource error");
}
- OIC_LOG(INFO, TAG, "OUT FinalizeProvisioning");
+ OIC_LOG(INFO, TAG, "OUT PostNormalOperationStatus");
return ret;
-
}
-