#include "srmresourcestrings.h"
#include "credresource.h"
#include "doxmresource.h"
+#include "pconfresource.h"
#include "credentialgenerator.h"
#include "cainterface.h"
#include "cJSON.h"
#include "provisioningdatabasemanager.h"
#include "base64.h"
#include "utlist.h"
+#include "ocpayload.h"
#ifdef __WITH_X509__
#include "crlresource.h"
* eg: VERIFY_NON_NULL(TAG, ptrData, ERROR,OC_STACK_ERROR);
*/
#define VERIFY_NON_NULL(tag, arg, logLevel, retValue) { if (NULL == (arg)) \
- { OC_LOG((logLevel), tag, (#arg " is NULL")); return retValue; } }
+ { OIC_LOG((logLevel), tag, #arg " is NULL"); return retValue; } }
/**
* Macro to verify success of operation.
* eg: VERIFY_SUCCESS(TAG, OC_STACK_OK == foo(), ERROR, OC_STACK_ERROR);
*/
#define VERIFY_SUCCESS(tag, op, logLevel, retValue) { if (!(op)) \
- {OC_LOG((logLevel), tag, (#op " failed!!")); return retValue;} }
+ {OIC_LOG((logLevel), tag, #op " failed!!"); return retValue;} }
/**
* Structure to carry credential data to callback.
int numOfResults; /**< Number of results in result array.**/
};
+/**
+ * Structure to carry PCONF provision API data to callback.
+ */
+typedef struct PconfData PconfData_t;
+struct PconfData
+{
+ void *ctx; /**< Pointer to user context.**/
+ const OCProvisionDev_t *deviceInfo; /**< Pointer to PMDevInfo_t.**/
+ OCProvisionResultCB resultCallback; /**< Pointer to result callback.**/
+ OCProvisionResult_t *resArr; /**< Result array.**/
+ int numOfResults; /**< Number of results in result array.**/
+};
+
// Enum type index for unlink callback.
typedef enum {
IDX_FIRST_DEVICE_RES = 0, // index for resulf of the first device
OCStackResult stackresult, int cause)
{
- OC_LOG_V(INFO,TAG,"value of credData->numOfResults is %d",credData->numOfResults);
+ OIC_LOG_V(INFO,TAG,"value of credData->numOfResults is %d",credData->numOfResults);
if(1 == cause)
{
memcpy(credData->resArr[(credData->numOfResults)].deviceId.id,
(void)UNUSED;
OCProvisionResultCB resultCallback = credData->resultCallback;
- OC_LOG(INFO, TAG, "provisionCredentialCB2 called");
+ OIC_LOG(INFO, TAG, "provisionCredentialCB2 called");
if (clientResponse)
{
if(OC_STACK_RESOURCE_CREATED == clientResponse->result)
&credData->deviceInfo2->doxm->deviceID);
if (OC_STACK_OK != res)
{
- OC_LOG(ERROR, TAG, "Error occured on PDMLinkDevices");
+ OIC_LOG(ERROR, TAG, "Error occured on PDMLinkDevices");
return OC_STACK_DELETE_TRANSACTION;
}
- OC_LOG(INFO, TAG, "Link created successfully");
+ OIC_LOG(INFO, TAG, "Link created successfully");
((OCProvisionResultCB)(resultCallback))(credData->ctx, credData->numOfResults,
credData->resArr,
}
}
- OC_LOG(INFO, TAG, "provisionCredentialCB2 received Null clientResponse");
+ OIC_LOG(INFO, TAG, "provisionCredentialCB2 received Null clientResponse");
registerResultForCredProvisioning(credData, OC_STACK_ERROR, 2);
((OCProvisionResultCB)(resultCallback))(credData->ctx, credData->numOfResults,
credData->resArr,
}
else
{
- OC_LOG(INFO, TAG, "provisionCredentialCB received Null clientResponse for first device");
+ OIC_LOG(INFO, TAG, "provisionCredentialCB received Null clientResponse for first device");
registerResultForCredProvisioning(credData, OC_STACK_ERROR,1);
((OCProvisionResultCB)(resultCallback))(credData->ctx, credData->numOfResults,
credData->resArr,
OCClientResponseHandler responseHandler)
{
OCSecurityPayload* secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
- if(!secPayload)
+ if (!secPayload)
{
- OC_LOG(ERROR, TAG, "Failed to memory allocation");
+ OIC_LOG(ERROR, TAG, "Failed to memory allocation");
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
- secPayload->securityData = BinToCredJSON(cred);
- if(NULL == secPayload->securityData)
+ OCStackResult res = CredToCBORPayload(cred, &secPayload->securityData, &secPayload->payloadSize);
+ if((OC_STACK_OK != res) && (NULL == secPayload->securityData))
{
- OICFree(secPayload);
- OC_LOG(ERROR, TAG, "Failed to BinToCredJSON");
+ OCPayloadDestroy((OCPayload *)secPayload);
+ OIC_LOG(ERROR, TAG, "Failed to CredToCBORPayload");
return OC_STACK_NO_MEMORY;
}
- OC_LOG_V(INFO, TAG, "Credential for provisioning : %s",secPayload->securityData);
+ OIC_LOG(DEBUG, TAG, "Created payload for Cred:");
+ OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
if(!PMGenerateQuery(true,
deviceInfo->endpoint.addr,
deviceInfo->connType,
query, sizeof(query), OIC_RSRC_CRED_URI))
{
- OC_LOG(ERROR, TAG, "DeviceDiscoveryHandler : Failed to generate query");
+ OIC_LOG(ERROR, TAG, "DeviceDiscoveryHandler : Failed to generate query");
return OC_STACK_ERROR;
}
- OC_LOG_V(DEBUG, TAG, "Query=%s", query);
+ OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
OCCallbackData cbData = {.context=NULL, .cb=NULL, .cd=NULL};
cbData.cb = responseHandler;
OCMethod method = OC_REST_POST;
OCStackResult ret = OCDoResource(&handle, method, query, 0, (OCPayload*)secPayload,
deviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
- OC_LOG_V(INFO, TAG, "OCDoResource::Credential provisioning returned : %d",ret);
+ OIC_LOG_V(INFO, TAG, "OCDoResource::Credential provisioning returned : %d",ret);
if (ret != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "OCStack resource error");
+ OIC_LOG(ERROR, TAG, "OCStack resource error");
return ret;
}
return OC_STACK_OK;
OCStackResult stackresult)
{
- OC_LOG_V(INFO,TAG,"value of credData->numOfResults is %d",certData->numOfResults);
+ OIC_LOG_V(INFO,TAG,"value of credData->numOfResults is %d",certData->numOfResults);
memcpy(certData->resArr[(certData->numOfResults)].deviceId.id,
certData->deviceInfo->doxm->deviceID.id,UUID_LENGTH);
certData->resArr[(certData->numOfResults)].res = stackresult;
static void registerResultForCRLProvisioning(CRLData_t *crlData,
OCStackResult stackresult)
{
- OC_LOG_V(INFO, TAG, "Inside registerResultForCRLProvisioning crlData->numOfResults is %d\n",
+ OIC_LOG_V(INFO, TAG, "Inside registerResultForCRLProvisioning crlData->numOfResults is %d\n",
crlData->numOfResults);
memcpy(crlData->resArr[(crlData->numOfResults)].deviceId.id,
crlData->deviceInfo->doxm->deviceID.id, UUID_LENGTH);
static OCStackApplicationResult SRPProvisionCRLCB(void *ctx, OCDoHandle UNUSED,
OCClientResponse *clientResponse)
{
- OC_LOG_V(INFO, TAG, "Inside SRPProvisionCRLCB.");
+ OIC_LOG_V(INFO, TAG, "Inside SRPProvisionCRLCB.");
(void)UNUSED;
VERIFY_NON_NULL(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION);
CRLData_t *crlData = (CRLData_t*)ctx;
((OCProvisionResultCB)(resultCallback))(crlData->ctx, crlData->numOfResults,
crlData->resArr,
true);
- OC_LOG_V(ERROR, TAG, "SRPProvisionCRLCB received Null clientResponse");
+ OIC_LOG_V(ERROR, TAG, "SRPProvisionCRLCB received Null clientResponse");
OICFree(crlData->resArr);
OICFree(crlData);
return OC_STACK_DELETE_TRANSACTION;
OCSecurityPayload* secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
if (!secPayload)
{
- OC_LOG(ERROR, TAG, "Failed to memory allocation");
+ OIC_LOG(ERROR, TAG, "Failed to memory allocation");
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
- secPayload->securityData = BinToCrlJSON(crl);
- if (NULL == secPayload->securityData)
+ OCStackResult res = CrlToCBORPayload(crl, &secPayload->securityData, &secPayload->payloadSize);
+ if((OC_STACK_OK != res) && (NULL == secPayload->securityData))
{
OICFree(secPayload);
- OC_LOG(ERROR, TAG, "Failed to BinToCrlJSON");
+ OIC_LOG(ERROR, TAG, "Failed to BinToCrlJSON");
return OC_STACK_NO_MEMORY;
}
- OC_LOG_V(INFO, TAG, "CRL : %s", secPayload->securityData);
+ OIC_LOG(DEBUG, TAG, "Created payload for CRL:");
+ OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
if(!PMGenerateQuery(true,
selectedDeviceInfo->connType,
query, sizeof(query), OIC_RSRC_CRL_URI))
{
- OC_LOG(ERROR, TAG, "DeviceDiscoveryHandler : Failed to generate query");
- OICFree(secPayload->securityData);
- OICFree(secPayload);
+ OIC_LOG(ERROR, TAG, "DeviceDiscoveryHandler : Failed to generate query");
+ OCPayloadDestroy((OCPayload *)secPayload);
return OC_STACK_ERROR;
}
- OC_LOG_V(DEBUG, TAG, "Query=%s", query);
+ OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
OCCallbackData cbData = {.context=NULL, .cb=NULL, .cd=NULL};
cbData.cb = &SRPProvisionCRLCB;
CRLData_t *crlData = (CRLData_t *) OICCalloc(1, sizeof(CRLData_t));
if (crlData == NULL)
{
- OICFree(secPayload->securityData);
- OICFree(secPayload);
- OC_LOG(ERROR, TAG, "Unable to allocate memory");
+ OCPayloadDestroy((OCPayload *)secPayload);
+ OIC_LOG(ERROR, TAG, "Unable to allocate memory");
return OC_STACK_NO_MEMORY;
}
crlData->resArr = (OCProvisionResult_t*)OICCalloc(1, sizeof(OCProvisionResult_t));
if (crlData->resArr == NULL)
{
- OICFree(secPayload->securityData);
- OICFree(secPayload);
- OC_LOG(ERROR, TAG, "Unable to allocate memory");
+ OCPayloadDestroy((OCPayload *)secPayload);
+ OIC_LOG(ERROR, TAG, "Unable to allocate memory");
return OC_STACK_NO_MEMORY;
}
cbData.cd = NULL;
OCMethod method = OC_REST_POST;
OCDoHandle handle = NULL;
- OC_LOG(DEBUG, TAG, "Sending CRL info to resource server");
+ OIC_LOG(DEBUG, TAG, "Sending CRL info to resource server");
OCStackResult ret = OCDoResource(&handle, method, query,
&selectedDeviceInfo->endpoint, (OCPayload*)secPayload,
OCSecurityPayload* secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
if(!secPayload)
{
- OC_LOG(ERROR, TAG, "Failed to memory allocation");
+ OIC_LOG(ERROR, TAG, "Failed to memory allocation");
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
- secPayload->securityData = BinToCredJSON(cred);
+ OCStackResult res = CredToCBORPayload(cred, &secPayload->securityData,
+ &secPayload->payloadSize);
- if (NULL == secPayload->securityData)
+ if ((OC_STACK_OK != res) || (NULL == secPayload->securityData))
{
OICFree(secPayload);
- OC_LOG(ERROR, TAG, "Failed to BinToCredJSON");
+ OIC_LOG(ERROR, TAG, "Failed to CredToCBORPayload");
return OC_STACK_NO_MEMORY;
}
- OC_LOG_V(INFO, TAG, "Credential for provisioning : %s",secPayload->securityData);
+ OIC_LOG(DEBUG, TAG, "Created payload for Cred:");
+ OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
if(!PMGenerateQuery(true,
deviceInfo->endpoint.addr,
deviceInfo->connType,
query, sizeof(query), OIC_RSRC_CRED_URI))
{
- OC_LOG(ERROR, TAG, "DeviceDiscoveryHandler : Failed to generate query");
- OICFree(secPayload->securityData);
- OICFree(secPayload);
+ OIC_LOG(ERROR, TAG, "DeviceDiscoveryHandler : Failed to generate query");
+ OCPayloadDestroy((OCPayload *)secPayload);
return OC_STACK_ERROR;
}
- OC_LOG_V(DEBUG, TAG, "Query=%s", query);
+ OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
OCCallbackData cbData = {.context=NULL, .cb=NULL, .cd=NULL};
cbData.cb = responseHandler;
OCMethod method = OC_REST_POST;
OCStackResult ret = OCDoResource(&handle, method, query, 0, (OCPayload*)secPayload,
deviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
- OC_LOG_V(INFO, TAG, "OCDoResource::Certificate provisioning returned : %d",ret);
+ OIC_LOG_V(INFO, TAG, "OCDoResource::Certificate provisioning returned : %d",ret);
if (ret != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "OCStack resource error");
+ OIC_LOG(ERROR, TAG, "OCStack resource error");
}
return ret;
(void)UNUSED;
OCProvisionResultCB resultCallback = certData->resultCallback;
- OC_LOG(INFO, TAG, "provisionCertCred called");
+ OIC_LOG(INFO, TAG, "provisionCertCred called");
if (clientResponse)
{
if(OC_STACK_RESOURCE_CREATED == clientResponse->result)
}
}
- OC_LOG(INFO, TAG, "provisionCertCredCB received Null clientResponse");
+ OIC_LOG(INFO, TAG, "provisionCertCredCB received Null clientResponse");
registerResultForCertProvisioning(certData, OC_STACK_ERROR);
((OCProvisionResultCB)(resultCallback))(certData->ctx, certData->numOfResults,
certData->resArr,
OCProvisionResultCB resultCallback)
{
VERIFY_NON_NULL(TAG, pDev1, ERROR, OC_STACK_INVALID_PARAM);
- VERIFY_NON_NULL(TAG, pDev2, ERROR, OC_STACK_INVALID_PARAM);
- VERIFY_NON_NULL(TAG, resultCallback, ERROR, OC_STACK_INVALID_CALLBACK);
+ if (SYMMETRIC_PAIR_WISE_KEY == type)
+ {
+ VERIFY_NON_NULL(TAG, pDev2, ERROR, OC_STACK_INVALID_PARAM);
+ }
+ if (!resultCallback)
+ {
+ OIC_LOG(INFO, TAG, "SRPUnlinkDevices : NULL Callback");
+ return OC_STACK_INVALID_CALLBACK;
+ }
+ if (SYMMETRIC_PAIR_WISE_KEY == type &&
+ 0 == memcmp(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID, sizeof(OicUuid_t)))
+ {
+ OIC_LOG(INFO, TAG, "SRPUnlinkDevices : Same device ID");
+ return OC_STACK_INVALID_PARAM;
+ }
- if (!(keySize == OWNER_PSK_LENGTH_128 || keySize == OWNER_PSK_LENGTH_256))
+ if (SYMMETRIC_PAIR_WISE_KEY == type &&
+ !(OWNER_PSK_LENGTH_128 == keySize || OWNER_PSK_LENGTH_256 == keySize))
{
- OC_LOG(INFO, TAG, "Invalid key size");
+ OIC_LOG(INFO, TAG, "Invalid key size");
return OC_STACK_INVALID_PARAM;
}
- OC_LOG(INFO, TAG, "In SRPProvisionCredentials");
+ OIC_LOG(INFO, TAG, "In SRPProvisionCredentials");
+
+ if (SYMMETRIC_PAIR_WISE_KEY == type)
+ {
+ bool linkExisits = true;
+ OCStackResult res = PDMIsLinkExists(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID, &linkExisits);
+
+ if (res != OC_STACK_OK)
+ {
+ OIC_LOG(ERROR, TAG, "Internal error occured");
+ return res;
+ }
+ if (linkExisits)
+ {
+ OIC_LOG(ERROR, TAG, "Link already exists");
+ return OC_STACK_INVALID_PARAM;
+ }
+ }
OicUuid_t provTooldeviceID = {{0,}};
if (OC_STACK_OK != GetDoxmDeviceID(&provTooldeviceID))
{
- OC_LOG(ERROR, TAG, "Error while retrieving provisioning tool's device ID");
+ OIC_LOG(ERROR, TAG, "Error while retrieving provisioning tool's device ID");
return OC_STACK_ERROR;
}
- OC_LOG(INFO, TAG, "retrieved deviceid");
+ OIC_LOG(INFO, TAG, "retrieved deviceid");
switch (type)
{
case SYMMETRIC_PAIR_WISE_KEY:
&firstDevice->doxm->deviceID, &secondDevice->doxm->deviceID,
&firstCred, &secondCred);
VERIFY_SUCCESS(TAG, (res==OC_STACK_OK), ERROR, OC_STACK_ERROR);
- OC_LOG(INFO, TAG, "Credentials generated successfully");
- CredentialData_t *credData = (CredentialData_t *) OICMalloc(sizeof(CredentialData_t));
+ OIC_LOG(INFO, TAG, "Credentials generated successfully");
+ CredentialData_t *credData =
+ (CredentialData_t *) OICCalloc(1, sizeof(CredentialData_t));
if (NULL == credData)
{
- OC_LOG(ERROR, TAG, "Memory allocation problem");
+ OICFree(firstCred);
+ OICFree(secondCred);
+ OIC_LOG(ERROR, TAG, "Memory allocation problem");
return OC_STACK_NO_MEMORY;
}
- memset(credData, 0x00, sizeof(CredentialData_t));
credData->deviceInfo1 = firstDevice;
credData->deviceInfo2 = secondDevice;
credData->credInfo = secondCred;
// second call to provision creds to device2.
int noOfRiCalls = 2;
credData->resArr =
- (OCProvisionResult_t*)OICMalloc(sizeof(OCProvisionResult_t) * noOfRiCalls);
+ (OCProvisionResult_t*)OICCalloc(noOfRiCalls, sizeof(OCProvisionResult_t));
if (NULL == credData->resArr)
{
- OC_LOG(ERROR, TAG, "Memory allocation problem");
+ OICFree(firstCred);
+ OICFree(secondCred);
+ OICFree(credData);
+ OIC_LOG(ERROR, TAG, "Memory allocation problem");
return OC_STACK_NO_MEMORY;
}
- memset(credData->resArr, 0x00, sizeof(sizeof(OCProvisionResult_t)*noOfRiCalls));
res = provisionCredentials(firstCred, firstDevice, credData, &provisionCredentialCB1);
if (OC_STACK_OK != res)
{
OICFree(credData->resArr);
OICFree(credData);
}
- OC_LOG_V(INFO, TAG, "provisionCredentials returned: %d",res);
+ OIC_LOG_V(INFO, TAG, "provisionCredentials returned: %d",res);
VERIFY_SUCCESS(TAG, (res==OC_STACK_OK), ERROR, OC_STACK_ERROR);
return res;
}
OCStackResult res = PMGenerateCertificateCredentials(&provTooldeviceID,
&firstDevice->doxm->deviceID,&cred);
VERIFY_SUCCESS(TAG, (res==OC_STACK_OK), ERROR, OC_STACK_ERROR);
- OC_LOG(INFO, TAG, "Certificate credentials generated successfully");
+ OIC_LOG(INFO, TAG, "Certificate credentials generated successfully");
CertData_t *certData = (CertData_t *) OICCalloc(1, sizeof(CertData_t));
if (NULL == certData)
{
- OC_LOG(ERROR, TAG, "Memory allocation problem");
+ OICFree(cred);
+ OIC_LOG(ERROR, TAG, "Memory allocation problem");
return OC_STACK_NO_MEMORY;
}
{
DeleteCredList(cred);
OICFree(certData);
- OC_LOG(ERROR, TAG, "Memory allocation problem");
+ OIC_LOG(ERROR, TAG, "Memory allocation problem");
return OC_STACK_NO_MEMORY;
}
OICFree(certData);
}
DeleteCredList(cred);
- OC_LOG_V(INFO, TAG, "provisionCertCredentials returned: %d",res);
+ OIC_LOG_V(INFO, TAG, "provisionCertCredentials returned: %d",res);
return res;
}
#endif
default:
{
- OC_LOG(ERROR, TAG, "Invalid option.");
+ OIC_LOG(ERROR, TAG, "Invalid option.");
return OC_STACK_INVALID_PARAM;
}
}
static void registerResultForACLProvisioning(ACLData_t *aclData,
OCStackResult stackresult)
{
- OC_LOG_V(INFO, TAG, "Inside registerResultForACLProvisioning aclData->numOfResults is %d\n",
+ OIC_LOG_V(INFO, TAG, "Inside registerResultForACLProvisioning aclData->numOfResults is %d\n",
aclData->numOfResults);
memcpy(aclData->resArr[(aclData->numOfResults)].deviceId.id,
aclData->deviceInfo->doxm->deviceID.id, UUID_LENGTH);
static OCStackApplicationResult SRPProvisionACLCB(void *ctx, OCDoHandle UNUSED,
OCClientResponse *clientResponse)
{
- OC_LOG_V(INFO, TAG, "Inside SRPProvisionACLCB.");
+ OIC_LOG_V(INFO, TAG, "Inside SRPProvisionACLCB.");
(void)UNUSED;
VERIFY_NON_NULL(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION);
ACLData_t *aclData = (ACLData_t*)ctx;
((OCProvisionResultCB)(resultCallback))(aclData->ctx, aclData->numOfResults,
aclData->resArr,
true);
- OC_LOG_V(ERROR, TAG, "SRPProvisionACLCB received Null clientResponse");
+ OIC_LOG_V(ERROR, TAG, "SRPProvisionACLCB received Null clientResponse");
OICFree(aclData->resArr);
OICFree(aclData);
return OC_STACK_DELETE_TRANSACTION;
OCSecurityPayload* secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
if(!secPayload)
{
- OC_LOG(ERROR, TAG, "Failed to memory allocation");
+ OIC_LOG(ERROR, TAG, "Failed to memory allocation");
return OC_STACK_NO_MEMORY;
}
secPayload->base.type = PAYLOAD_TYPE_SECURITY;
- secPayload->securityData = BinToAclJSON(acl);
- if(NULL == secPayload->securityData)
+ if(OC_STACK_OK != AclToCBORPayload(acl, &secPayload->securityData, &secPayload->payloadSize))
{
- OICFree(secPayload);
- OC_LOG(ERROR, TAG, "Failed to BinToAclJSON");
+ OCPayloadDestroy((OCPayload *)secPayload);
+ OIC_LOG(ERROR, TAG, "Failed to AclToCBORPayload");
return OC_STACK_NO_MEMORY;
}
- OC_LOG_V(INFO, TAG, "ACL : %s", secPayload->securityData);
-
char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
if(!PMGenerateQuery(true,
selectedDeviceInfo->endpoint.addr,
selectedDeviceInfo->connType,
query, sizeof(query), OIC_RSRC_ACL_URI))
{
- OC_LOG(ERROR, TAG, "DeviceDiscoveryHandler : Failed to generate query");
+ OIC_LOG(ERROR, TAG, "DeviceDiscoveryHandler : Failed to generate query");
return OC_STACK_ERROR;
}
- OC_LOG_V(DEBUG, TAG, "Query=%s", query);
+ OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
OCCallbackData cbData = {.context=NULL, .cb=NULL, .cd=NULL};
cbData.cb = &SRPProvisionACLCB;
- ACLData_t *aclData = (ACLData_t *) OICMalloc(sizeof(ACLData_t));
+ ACLData_t *aclData = (ACLData_t *) OICCalloc(1, sizeof(ACLData_t));
if (aclData == NULL)
{
- OICFree(secPayload);
- OC_LOG(ERROR, TAG, "Unable to allocate memory");
+ OCPayloadDestroy((OCPayload *)secPayload);
+ OIC_LOG(ERROR, TAG, "Unable to allocate memory");
return OC_STACK_NO_MEMORY;
}
- memset(aclData, 0x00, sizeof(ACLData_t));
aclData->deviceInfo = selectedDeviceInfo;
aclData->resultCallback = resultCallback;
aclData->numOfResults=0;
aclData->ctx = ctx;
// call to provision ACL to device1.
int noOfRiCalls = 1;
- aclData->resArr = (OCProvisionResult_t*)OICMalloc(sizeof(OCProvisionResult_t)*noOfRiCalls);
+ aclData->resArr = (OCProvisionResult_t*)OICCalloc(noOfRiCalls, sizeof(OCProvisionResult_t));
if (aclData->resArr == NULL)
{
- OICFree(secPayload);
- OC_LOG(ERROR, TAG, "Unable to allocate memory");
+ OICFree(aclData);
+ OCPayloadDestroy((OCPayload *)secPayload);
+ OIC_LOG(ERROR, TAG, "Unable to allocate memory");
return OC_STACK_NO_MEMORY;
}
- memset(aclData->resArr, 0x00, sizeof(sizeof(OCProvisionResult_t)*noOfRiCalls));
cbData.context = (void *)aclData;
cbData.cd = NULL;
OCMethod method = OC_REST_POST;
OCDoHandle handle = NULL;
- OC_LOG(DEBUG, TAG, "Sending ACL info to resource server");
+ OIC_LOG(DEBUG, TAG, "Sending ACL info to resource server");
OCStackResult ret = OCDoResource(&handle, method, query,
&selectedDeviceInfo->endpoint, (OCPayload*)secPayload,
selectedDeviceInfo->connType, OC_HIGH_QOS, &cbData, NULL, 0);
return OC_STACK_OK;
}
+/**
+ * Internal Function to store results in result array during Direct-Pairing provisioning.
+ */
+static void registerResultForDirectPairingProvisioning(PconfData_t *pconfData,
+ OCStackResult stackresult)
+{
+ OIC_LOG_V(INFO, TAG, "Inside registerResultForDirectPairingProvisioning "
+ "pconfData->numOfResults is %d\n", pconfData->numOfResults);
+ memcpy(pconfData->resArr[(pconfData->numOfResults)].deviceId.id,
+ pconfData->deviceInfo->doxm->deviceID.id, UUID_LENGTH);
+ pconfData->resArr[(pconfData->numOfResults)].res = stackresult;
+ ++(pconfData->numOfResults);
+}
+
+/**
+ * Callback handler of SRPProvisionDirectPairing.
+ *
+ * @param[in] ctx ctx value passed to callback from calling function.
+ * @param[in] UNUSED handle to an invocation
+ * @param[in] clientResponse Response from queries to remote servers.
+ * @return OC_STACK_DELETE_TRANSACTION to delete the transaction
+ * and OC_STACK_KEEP_TRANSACTION to keep it.
+ */
+static OCStackApplicationResult SRPProvisionDirectPairingCB(void *ctx, OCDoHandle UNUSED,
+ OCClientResponse *clientResponse)
+{
+ OIC_LOG_V(INFO, TAG, "Inside SRPProvisionDirectPairingCB.");
+ (void)UNUSED;
+ VERIFY_NON_NULL(TAG, ctx, ERROR, OC_STACK_DELETE_TRANSACTION);
+ PconfData_t *pconfData = (PconfData_t*)ctx;
+ OCProvisionResultCB resultCallback = pconfData->resultCallback;
+
+ if (clientResponse)
+ {
+ if(OC_STACK_RESOURCE_CREATED == clientResponse->result)
+ {
+ registerResultForDirectPairingProvisioning(pconfData, OC_STACK_OK);
+ ((OCProvisionResultCB)(resultCallback))(pconfData->ctx, pconfData->numOfResults,
+ pconfData->resArr,
+ false);
+ OICFree(pconfData->resArr);
+ OICFree(pconfData);
+ return OC_STACK_DELETE_TRANSACTION;
+ }
+ }
+ registerResultForDirectPairingProvisioning(pconfData, OC_STACK_ERROR);
+ ((OCProvisionResultCB)(resultCallback))(pconfData->ctx, pconfData->numOfResults,
+ pconfData->resArr,
+ true);
+ OIC_LOG_V(ERROR, TAG, "SRPProvisionDirectPairingCB received Null clientResponse");
+ OICFree(pconfData->resArr);
+ OICFree(pconfData);
+ return OC_STACK_DELETE_TRANSACTION;
+}
+
+OCStackResult SRPProvisionDirectPairing(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
+ OicSecPconf_t *pconf, OCProvisionResultCB resultCallback)
+{
+ VERIFY_NON_NULL(TAG, selectedDeviceInfo, ERROR, OC_STACK_INVALID_PARAM);
+ VERIFY_NON_NULL(TAG, pconf, ERROR, OC_STACK_INVALID_PARAM);
+ VERIFY_NON_NULL(TAG, resultCallback, ERROR, OC_STACK_INVALID_CALLBACK);
+
+ // check direct-pairing capability
+ if (true != selectedDeviceInfo->doxm->dpc)
+ {
+ OIC_LOG(ERROR, TAG, "Resouce server does not have Direct-Pairing Capability ");
+ return OC_STACK_UNAUTHORIZED_REQ;
+ }
+
+ OicUuid_t provTooldeviceID = {.id={0}};
+ if (OC_STACK_OK != GetDoxmDeviceID(&provTooldeviceID))
+ {
+ OIC_LOG(ERROR, TAG, "Error while retrieving provisioning tool's device ID");
+ return OC_STACK_ERROR;
+ }
+ memcpy(&pconf->rownerID, &provTooldeviceID, sizeof(OicUuid_t));
+
+ 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;
+
+ if (OC_STACK_OK != PconfToCBORPayload(pconf, &(secPayload->securityData),
+ &(secPayload->payloadSize)))
+ {
+ OCPayloadDestroy((OCPayload*)secPayload);
+ OIC_LOG(ERROR, TAG, "Failed to PconfToCborPayload");
+ return OC_STACK_NO_MEMORY;
+ }
+ OIC_LOG(DEBUG, TAG, "Created payload for pconf set");
+ OIC_LOG_BUFFER(DEBUG, TAG, secPayload->securityData, secPayload->payloadSize);
+
+
+ char query[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
+ if(!PMGenerateQuery(true,
+ selectedDeviceInfo->endpoint.addr,
+ selectedDeviceInfo->securePort,
+ selectedDeviceInfo->connType,
+ query, sizeof(query), OIC_RSRC_PCONF_URI))
+ {
+ OIC_LOG(ERROR, TAG, "SRPProvisionDirectPairing : Failed to generate query");
+ return OC_STACK_ERROR;
+ }
+ OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
+
+ OCCallbackData cbData = {.context=NULL, .cb=NULL, .cd=NULL};
+ cbData.cb = &SRPProvisionDirectPairingCB;
+ PconfData_t *pconfData = (PconfData_t *) OICCalloc(1, sizeof(PconfData_t));
+ if (NULL == pconfData)
+ {
+ OCPayloadDestroy((OCPayload*)secPayload);
+ OIC_LOG(ERROR, TAG, "Unable to allocate memory");
+ return OC_STACK_NO_MEMORY;
+ }
+ pconfData->deviceInfo = selectedDeviceInfo;
+ pconfData->resultCallback = resultCallback;
+ pconfData->numOfResults=0;
+ pconfData->ctx = ctx;
+ // call to provision PCONF to device1.
+ int noOfRiCalls = 1;
+ pconfData->resArr = (OCProvisionResult_t*)OICCalloc(noOfRiCalls, sizeof(OCProvisionResult_t));
+ if (NULL == pconfData->resArr)
+ {
+ OICFree(pconfData);
+ OCPayloadDestroy((OCPayload*)secPayload);
+ OIC_LOG(ERROR, TAG, "Unable to allocate memory");
+ return OC_STACK_NO_MEMORY;
+ }
+ cbData.context = (void *)pconfData;
+ cbData.cd = NULL;
+ OCMethod method = OC_REST_POST;
+ OCDoHandle handle = NULL;
+ OIC_LOG(DEBUG, TAG, "Sending PCONF info to resource server");
+ OCStackResult ret = OCDoResource(&handle, method, query,
+ &selectedDeviceInfo->endpoint, (OCPayload*)secPayload,
+ selectedDeviceInfo->connType, OC_LOW_QOS, &cbData, NULL, 0);
+ if (OC_STACK_OK != ret)
+ {
+ OICFree(pconfData->resArr);
+ OICFree(pconfData);
+ }
+ VERIFY_SUCCESS(TAG, (OC_STACK_OK == ret), ERROR, OC_STACK_ERROR);
+ return OC_STACK_OK;
+}
+
static void DeleteUnlinkData_t(UnlinkData_t *unlinkData)
{
if (unlinkData)
{
if (NULL != unlinkData)
{
- OC_LOG_V(INFO, TAG, "Inside registerResultForUnlinkDevices unlinkData->numOfResults is %d\n",
+ OIC_LOG_V(INFO, TAG, "Inside registerResultForUnlinkDevices unlinkData->numOfResults is %d\n",
unlinkData->numOfResults);
- OC_LOG_V(INFO, TAG, "Stack result :: %d", stackresult);
+ OIC_LOG_V(INFO, TAG, "Stack result :: %d", stackresult);
OicUuid_t *pUuid = &unlinkData->unlinkRes[(unlinkData->numOfResults)].deviceId;
}
unlinkData->unlinkRes[(unlinkData->numOfResults)].res = stackresult;
++(unlinkData->numOfResults);
- OC_LOG (INFO, TAG, "Out registerResultForUnlinkDevices");
+ OIC_LOG (INFO, TAG, "Out registerResultForUnlinkDevices");
}
}
const OCProvisionDev_t* revokedDev,
const OCProvisionDev_t* destDev)
{
- OC_LOG(DEBUG, TAG, "IN SendDeleteCredentialRequest");
+ OIC_LOG(DEBUG, TAG, "IN SendDeleteCredentialRequest");
if (NULL == ctx || NULL == respHandler || NULL == revokedDev || NULL == destDev)
{
return OC_STACK_INVALID_PARAM;
}
- char base64Buff[B64ENCODE_OUT_SAFESIZE(sizeof(revokedDev->doxm->deviceID.id)) + 1] = {};
- uint32_t base64Len = 0;
- if (B64_OK != b64Encode(revokedDev->doxm->deviceID.id, sizeof(revokedDev->doxm->deviceID.id),
- base64Buff, sizeof(base64Buff), &base64Len))
+ char *subID = NULL;
+ OCStackResult ret = ConvertUuidToStr(&revokedDev->doxm->deviceID, &subID);
+ if(OC_STACK_OK != ret)
{
- OC_LOG(ERROR, TAG, "SendDeleteCredentialRequest : Failed to base64 encoding");
+ OIC_LOG(ERROR, TAG, "SendDeleteCredentialRequest : Failed to canonical UUID encoding");
return OC_STACK_ERROR;
}
char reqBuf[MAX_URI_LENGTH + MAX_QUERY_LENGTH] = {0};
int snRet = 0;
- //coaps://0.0.0.0:5684/oic/sec/cred?sub=(BASE64 ENCODED UUID)
+ //coaps://0.0.0.0:5684/oic/sec/cred?subjectid=(Canonical ENCODED UUID)
snRet = snprintf(reqBuf, sizeof(reqBuf), SRP_FORM_DELETE_CREDENTIAL, destDev->endpoint.addr,
- destDev->securePort, OIC_RSRC_CRED_URI, OIC_JSON_SUBJECT_NAME, base64Buff);
+ destDev->securePort, OIC_RSRC_CRED_URI, OIC_JSON_SUBJECTID_NAME, subID);
+ OICFree(subID);
if (snRet < 0)
{
- OC_LOG_V(ERROR, TAG, "SendDeleteCredentialRequest : Error (snprintf) %d\n", snRet);
+ OIC_LOG_V(ERROR, TAG, "SendDeleteCredentialRequest : Error (snprintf) %d\n", snRet);
return OC_STACK_ERROR;
}
else if ((size_t)snRet >= sizeof(reqBuf))
{
- OC_LOG_V(ERROR, TAG, "SendDeleteCredentialRequest : Truncated (snprintf) %d\n", snRet);
+ OIC_LOG_V(ERROR, TAG, "SendDeleteCredentialRequest : Truncated (snprintf) %d\n", snRet);
return OC_STACK_ERROR;
}
cbData.context = ctx;
cbData.cb = respHandler;
cbData.cd = NULL;
- OC_LOG_V(INFO, TAG, "URI: %s",reqBuf);
+ OIC_LOG_V(INFO, TAG, "URI: %s",reqBuf);
- OC_LOG(DEBUG, TAG, "Sending remove credential request to resource server");
+ OIC_LOG(DEBUG, TAG, "Sending remove credential request to resource server");
- OCStackResult ret = OCDoResource(NULL, OC_REST_DELETE, reqBuf,
+ ret = OCDoResource(NULL, OC_REST_DELETE, reqBuf,
&destDev->endpoint, NULL,
CT_ADAPTER_IP, OC_HIGH_QOS, &cbData, NULL, 0);
if (OC_STACK_OK != ret)
{
- OC_LOG_V(ERROR, TAG, "SendDeleteCredentialRequest : Error in OCDoResource %d", ret);
+ OIC_LOG_V(ERROR, TAG, "SendDeleteCredentialRequest : Error in OCDoResource %d", ret);
}
- OC_LOG(DEBUG, TAG, "OUT SendDeleteCredentialRequest");
+ OIC_LOG(DEBUG, TAG, "OUT SendDeleteCredentialRequest");
return ret;
}
OCClientResponse *clientResponse)
{
(void) handle;
- OC_LOG(DEBUG, TAG, "IN SRPUnlinkDevice2CB");
+ OIC_LOG(DEBUG, TAG, "IN SRPUnlinkDevice2CB");
VERIFY_NON_NULL(TAG, unlinkCtx, ERROR, OC_STACK_DELETE_TRANSACTION);
UnlinkData_t* unlinkData = (UnlinkData_t*)unlinkCtx;
if (clientResponse)
{
- OC_LOG(DEBUG, TAG, "Valid client response for device 2");
+ OIC_LOG(DEBUG, TAG, "Valid client response for device 2");
registerResultForUnlinkDevices(unlinkData, clientResponse->result, IDX_SECOND_DEVICE_RES);
if (OC_STACK_RESOURCE_DELETED == clientResponse->result)
{
- OC_LOG(DEBUG, TAG, "Credential of device2 revoked");
+ OIC_LOG(DEBUG, TAG, "Credential of device2 revoked");
}
else
{
- OC_LOG(ERROR, TAG, "Unable to delete credential information from device 2");
+ OIC_LOG(ERROR, TAG, "Unable to delete credential information from device 2");
unlinkData->resultCallback(unlinkData->ctx,
unlinkData->numOfResults, unlinkData->unlinkRes, true);
goto error;
IDX_SECOND_DEVICE_RES);
unlinkData->resultCallback(unlinkData->ctx,
unlinkData->numOfResults, unlinkData->unlinkRes, true);
- OC_LOG(ERROR, TAG, "SRPUnlinkDevice2CB received Null clientResponse");
+ OIC_LOG(ERROR, TAG, "SRPUnlinkDevice2CB received Null clientResponse");
goto error;
}
if (OC_STACK_OK != PDMUnlinkDevices(&unlinkData->unlinkDev[0].doxm->deviceID,
&unlinkData->unlinkDev[1].doxm->deviceID))
{
- OC_LOG(FATAL, TAG, "All requests are successfully done but update provisioning DB FAILED.");
+ OIC_LOG(FATAL, TAG, "All requests are successfully done but update provisioning DB FAILED.");
registerResultForUnlinkDevices(unlinkData, OC_STACK_INCONSISTENT_DB, IDX_DB_UPDATE_RES);
unlinkData->resultCallback(unlinkData->ctx,
unlinkData->numOfResults, unlinkData->unlinkRes, true);
error:
DeleteUnlinkData_t(unlinkData);
- OC_LOG(DEBUG, TAG, "OUT SRPUnlinkDevice2CB");
+ OIC_LOG(DEBUG, TAG, "OUT SRPUnlinkDevice2CB");
return OC_STACK_DELETE_TRANSACTION;
}
static OCStackApplicationResult SRPUnlinkDevice1CB(void *unlinkCtx, OCDoHandle handle,
OCClientResponse *clientResponse)
{
- OC_LOG_V(INFO, TAG, "Inside SRPUnlinkDevice1CB ");
+ OIC_LOG_V(INFO, TAG, "Inside SRPUnlinkDevice1CB ");
VERIFY_NON_NULL(TAG, unlinkCtx, ERROR, OC_STACK_DELETE_TRANSACTION);
UnlinkData_t* unlinkData = (UnlinkData_t*)unlinkCtx;
(void) handle;
if (clientResponse)
{
- OC_LOG(DEBUG, TAG, "Valid client response for device 1");
+ OIC_LOG(DEBUG, TAG, "Valid client response for device 1");
registerResultForUnlinkDevices(unlinkData, clientResponse->result, IDX_FIRST_DEVICE_RES);
if (OC_STACK_RESOURCE_DELETED == clientResponse->result)
{
- OC_LOG(DEBUG, TAG, "Credential of device 1 is revoked");
+ OIC_LOG(DEBUG, TAG, "Credential of device 1 is revoked");
// Second revocation request to second device.
OCStackResult res = SendDeleteCredentialRequest((void*)unlinkData, &SRPUnlinkDevice2CB,
&unlinkData->unlinkDev[0],
&unlinkData->unlinkDev[1] /*Dest*/);
- OC_LOG_V(DEBUG, TAG, "Credential revocation request device 2, result :: %d",res);
+ OIC_LOG_V(DEBUG, TAG, "Credential revocation request device 2, result :: %d",res);
if (OC_STACK_OK != res)
{
- OC_LOG(ERROR, TAG, "Error while sending revocation request for device 2");
+ OIC_LOG(ERROR, TAG, "Error while sending revocation request for device 2");
registerResultForUnlinkDevices(unlinkData, OC_STACK_INVALID_REQUEST_HANDLE,
IDX_SECOND_DEVICE_RES);
unlinkData->resultCallback(unlinkData->ctx,
}
else
{
- OC_LOG(DEBUG, TAG, "Request for credential revocation successfully sent");
+ OIC_LOG(DEBUG, TAG, "Request for credential revocation successfully sent");
return OC_STACK_DELETE_TRANSACTION;
}
}
else
{
- OC_LOG(ERROR, TAG, "Unable to delete credential information from device 1");
+ OIC_LOG(ERROR, TAG, "Unable to delete credential information from device 1");
unlinkData->resultCallback(unlinkData->ctx, unlinkData->numOfResults,
unlinkData->unlinkRes, true);
}
else
{
- OC_LOG(DEBUG, TAG, "Invalid response from server");
+ OIC_LOG(DEBUG, TAG, "Invalid response from server");
registerResultForUnlinkDevices(unlinkData, OC_STACK_INVALID_REQUEST_HANDLE,
IDX_FIRST_DEVICE_RES );
unlinkData->resultCallback(unlinkData->ctx,
unlinkData->numOfResults, unlinkData->unlinkRes,
true);
- OC_LOG(ERROR, TAG, "SRPUnlinkDevice1CB received Null clientResponse");
+ OIC_LOG(ERROR, TAG, "SRPUnlinkDevice1CB received Null clientResponse");
}
error:
- OC_LOG_V(INFO, TAG, "Out SRPUnlinkDevice1CB");
+ OIC_LOG_V(INFO, TAG, "Out SRPUnlinkDevice1CB");
DeleteUnlinkData_t(unlinkData);
return OC_STACK_DELETE_TRANSACTION;
}
const OCProvisionDev_t* pTargetDev2,
OCProvisionResultCB resultCallback)
{
- OC_LOG(INFO, TAG, "IN SRPUnlinkDevices");
+ OIC_LOG(INFO, TAG, "IN SRPUnlinkDevices");
- if (!pTargetDev1 || !pTargetDev2 || !resultCallback)
+ if (!pTargetDev1 || !pTargetDev2 || !pTargetDev1->doxm || !pTargetDev2->doxm)
{
- OC_LOG(INFO, TAG, "SRPUnlinkDevices : NULL parameters");
+ OIC_LOG(INFO, TAG, "SRPUnlinkDevices : NULL parameters");
return OC_STACK_INVALID_PARAM;
}
- OC_LOG(INFO, TAG, "Unlinking following devices: ");
+ if (!resultCallback)
+ {
+ OIC_LOG(INFO, TAG, "SRPUnlinkDevices : NULL Callback");
+ return OC_STACK_INVALID_CALLBACK;
+ }
+ if (0 == memcmp(&pTargetDev1->doxm->deviceID, &pTargetDev2->doxm->deviceID, sizeof(OicUuid_t)))
+ {
+ OIC_LOG(INFO, TAG, "SRPUnlinkDevices : Same device ID");
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ OIC_LOG(INFO, TAG, "Unlinking following devices: ");
PMPrintOCProvisionDev(pTargetDev1);
PMPrintOCProvisionDev(pTargetDev2);
OCStackResult res = PDMSetLinkStale(&pTargetDev1->doxm->deviceID, &pTargetDev2->doxm->deviceID);
if (OC_STACK_OK != res)
{
- OC_LOG(FATAL, TAG, "unable to update DB. Try again.");
+ OIC_LOG(FATAL, TAG, "unable to update DB. Try again.");
return res;
}
unlinkData->unlinkDev = (OCProvisionDev_t*)OICCalloc(2, sizeof(OCProvisionDev_t));
if (NULL == unlinkData->unlinkDev)
{
- OC_LOG(ERROR, TAG, "Memory allocation failed");
+ OIC_LOG(ERROR, TAG, "Memory allocation failed");
res = OC_STACK_NO_MEMORY;
goto error;
}
unlinkData->unlinkRes = (OCProvisionResult_t*)OICCalloc(3, sizeof(OCProvisionResult_t));
if (NULL == unlinkData->unlinkRes)
{
- OC_LOG(ERROR, TAG, "Memory allocation failed");
+ OIC_LOG(ERROR, TAG, "Memory allocation failed");
res = OC_STACK_NO_MEMORY;
goto error;
}
&unlinkData->unlinkDev[1], &unlinkData->unlinkDev[0]);
if (OC_STACK_OK != res)
{
- OC_LOG(ERROR, TAG, "SRPUnlinkDevices : SendDeleteCredentialRequest failed");
+ OIC_LOG(ERROR, TAG, "SRPUnlinkDevices : SendDeleteCredentialRequest failed");
goto error;
}
return res;
error:
- OC_LOG(INFO, TAG, "OUT SRPUnlinkDevices");
+ OIC_LOG(INFO, TAG, "OUT SRPUnlinkDevices");
DeleteUnlinkData_t(unlinkData);
return res;
}
static void registerResultForRemoveDevice(RemoveData_t *removeData, OicUuid_t *pLinkedDevId,
OCStackResult stackresult, bool hasError)
{
- OC_LOG_V(INFO, TAG, "Inside registerResultForRemoveDevice removeData->numOfResults is %d\n",
+ OIC_LOG_V(INFO, TAG, "Inside registerResultForRemoveDevice removeData->numOfResults is %zu\n",
removeData->numOfResults + 1);
if (pLinkedDevId)
{
// If we get suffcient result from linked devices, we have to call user callback and do free
if (removeData->sizeOfResArray == removeData->numOfResults)
{
+ if(!removeData->hasError)
+ {
+ // Remove device info from prvisioning database
+ if (OC_STACK_OK != PDMDeleteDevice(&removeData->revokeTargetDev->doxm->deviceID))
+ {
+ OIC_LOG(ERROR, TAG, "ResultForRemoveDevice : Failed to remove device in PDM.");
+ removeData->hasError = true;
+ }
+ }
removeData->resultCallback(removeData->ctx, removeData->numOfResults, removeData->removeRes,
removeData->hasError);
DeleteRemoveData_t(removeData);
//Update the delete credential into delete device context
//Save the deleted status in delDevCtx
(void)handle;
- OC_LOG_V(INFO, TAG, "Inside SRPRemoveDeviceCB.");
+ OIC_LOG_V(INFO, TAG, "Inside SRPRemoveDeviceCB.");
VERIFY_NON_NULL(TAG, delDevCtx, ERROR, OC_STACK_DELETE_TRANSACTION);
OCStackResult res = OC_STACK_ERROR;
RemoveData_t* removeData = (RemoveData_t*)delDevCtx;
+
if (clientResponse)
{
- // If we can get device's UUID from OCClientResponse, it'd be good to use it in here
- // but OCIdentity in OCClientResponse is emtpy now.
- // It seems that we can set identity to CAData_t *cadata in CAPrepareSendData() API
- // but CA doesn't have deviceID yet.
- //
- //TODO: Get OCIdentity from OCClientResponse and use it for 'registerResultForRemoveDevice'
- // If we can't complete this task, Provisioning Database has always stale link status
- // when Remove device is called.
-
- if (OC_STACK_RESOURCE_DELETED == clientResponse->result)
+ OicUuid_t revDevUuid = {.id={0}};
+ if(UUID_LENGTH == clientResponse->identity.id_length)
{
- res = PDMUnlinkDevices(&removeData->revokeTargetDev->doxm->deviceID,
- NULL /*TODO: Replace NULL to uuid from OCClientResponse*/);
- if (OC_STACK_OK != res)
+ memcpy(revDevUuid.id, clientResponse->identity.id, sizeof(revDevUuid.id));
+ if (OC_STACK_RESOURCE_DELETED == clientResponse->result)
{
- OC_LOG(FATAL, TAG, "PDMSetLinkStale() FAIL: PDB is an obsolete one.");
- registerResultForRemoveDevice(removeData,
- NULL /*TODO: Replace NULL to uuid from OCClientResponse*/,
- OC_STACK_INCONSISTENT_DB, true);
- return OC_STACK_DELETE_TRANSACTION;
+ res = PDMUnlinkDevices(&removeData->revokeTargetDev->doxm->deviceID, &revDevUuid);
+ if (OC_STACK_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "PDMSetLinkStale() FAIL: PDB is an obsolete one.");
+ registerResultForRemoveDevice(removeData, &revDevUuid,
+ OC_STACK_INCONSISTENT_DB, true);
+
+ return OC_STACK_DELETE_TRANSACTION;
+ }
+
+ registerResultForRemoveDevice(removeData, &revDevUuid,
+ OC_STACK_RESOURCE_DELETED, false);
+ }
+ else
+ {
+ registerResultForRemoveDevice(removeData, &revDevUuid,
+ clientResponse->result, true);
+ OIC_LOG(ERROR, TAG, "Unexpected result from DELETE credential request!");
}
- registerResultForRemoveDevice(removeData,
- NULL /*TODO: Replace NULL to uuid from OCClientResponse*/,
- OC_STACK_RESOURCE_DELETED, false);
}
else
{
- registerResultForRemoveDevice(removeData,
- NULL /*TODO: Replace NULL to uuid from OCClientResponse*/,
- clientResponse->result, true);
- OC_LOG(ERROR, TAG, "Unexpected result from DELETE credential request!");
+ OIC_LOG_V(WARNING, TAG, "Incorrect length of device UUID was sent from %s:%d",
+ clientResponse->devAddr.addr, clientResponse->devAddr.port);
+
+ if (OC_STACK_RESOURCE_DELETED == clientResponse->result)
+ {
+ /**
+ * Since server's credential was deleted,
+ * register result as OC_STACK_INCONSISTENT_DB with NULL UUID.
+ */
+ OIC_LOG_V(ERROR, TAG, "But server's credential was deleted.");
+ registerResultForRemoveDevice(removeData, NULL, OC_STACK_INCONSISTENT_DB, true);
+ }
+ else
+ {
+ registerResultForRemoveDevice(removeData, NULL, clientResponse->result, true);
+ }
}
}
else
{
registerResultForRemoveDevice(removeData, NULL, OC_STACK_ERROR, true);
- OC_LOG(ERROR, TAG, "SRPRemoveDevices received Null clientResponse");
+ OIC_LOG(ERROR, TAG, "SRPRemoveDevices received Null clientResponse");
}
+
return OC_STACK_DELETE_TRANSACTION;
}
OCStackResult res = PDMSetLinkStale(&curUuid->dev, &pRevokeTargetDev->doxm->deviceID);
if (OC_STACK_OK != res)
{
- OC_LOG(FATAL, TAG, "PDMSetLinkStale() FAIL: PDB is an obsolete one.");
+ OIC_LOG(FATAL, TAG, "PDMSetLinkStale() FAIL: PDB is an obsolete one.");
return OC_STACK_INCONSISTENT_DB;
}
OCProvisionDev_t* targetDev = PMCloneOCProvisionDev(curDev);
if (NULL == targetDev)
{
- OC_LOG(ERROR, TAG, "SRPRemoveDevice : Cloning OCProvisionDev_t Failed.");
+ OIC_LOG(ERROR, TAG, "SRPRemoveDevice : Cloning OCProvisionDev_t Failed.");
return OC_STACK_NO_MEMORY;
}
OCStackResult SRPRemoveDevice(void* ctx, unsigned short waitTimeForOwnedDeviceDiscovery,
const OCProvisionDev_t* pTargetDev, OCProvisionResultCB resultCallback)
{
- OC_LOG(INFO, TAG, "IN SRPRemoveDevice");
+ OIC_LOG(INFO, TAG, "IN SRPRemoveDevice");
- if (!pTargetDev || !resultCallback || 0 == waitTimeForOwnedDeviceDiscovery)
+ if (!pTargetDev || 0 == waitTimeForOwnedDeviceDiscovery)
{
- OC_LOG(INFO, TAG, "SRPRemoveDevice : NULL parameters");
+ OIC_LOG(INFO, TAG, "SRPRemoveDevice : NULL parameters");
return OC_STACK_INVALID_PARAM;
}
+ if (!resultCallback)
+ {
+ OIC_LOG(INFO, TAG, "SRPRemoveDevice : NULL Callback");
+ return OC_STACK_INVALID_CALLBACK;
+ }
// Declare variables in here to handle error cases with goto statement.
OCProvisionDev_t* pOwnedDevList = NULL;
res = PDMGetLinkedDevices(&pTargetDev->doxm->deviceID, &pLinkedUuidList, &numOfDevices);
if (OC_STACK_OK != res)
{
- OC_LOG(ERROR, TAG, "SRPRemoveDevice : Failed to get linked devices information");
+ OIC_LOG(ERROR, TAG, "SRPRemoveDevice : Failed to get linked devices information");
return res;
}
// if there is no related device, we can skip further process.
if (0 == numOfDevices)
{
- OC_LOG(DEBUG, TAG, "SRPRemoveDevice : No linked device found.");
+ OIC_LOG(DEBUG, TAG, "SRPRemoveDevice : No linked device found.");
res = OC_STACK_CONTINUE;
goto error;
}
res = PMDeviceDiscovery(waitTimeForOwnedDeviceDiscovery, true, &pOwnedDevList);
if (OC_STACK_OK != res)
{
- OC_LOG(ERROR, TAG, "SRPRemoveDevice : Failed to PMDeviceDiscovery");
+ OIC_LOG(ERROR, TAG, "SRPRemoveDevice : Failed to PMDeviceDiscovery");
goto error;
}
&pLinkedDevList, &numOfLinkedDev);
if (OC_STACK_OK != res)
{
- OC_LOG(ERROR, TAG, "SRPRemoveDevice : GetListofDevToReqDeleteCred() failed");
+ OIC_LOG(ERROR, TAG, "SRPRemoveDevice : GetListofDevToReqDeleteCred() failed");
goto error;
}
if (0 == numOfLinkedDev) // This case means, there is linked device but it's not alive now.
{ // So we don't have to send request message.
- OC_LOG(DEBUG, TAG, "SRPRemoveDevice : No alived & linked device found.");
+ OIC_LOG(DEBUG, TAG, "SRPRemoveDevice : No alived & linked device found.");
res = OC_STACK_CONTINUE;
goto error;
}
removeData = (RemoveData_t*)OICCalloc(1, sizeof(RemoveData_t));
if (!removeData)
{
- OC_LOG(ERROR, TAG, "SRPRemoveDevices : Failed to memory allocation");
+ OIC_LOG(ERROR, TAG, "SRPRemoveDevices : Failed to memory allocation");
res = OC_STACK_NO_MEMORY;
goto error;
}
removeData->revokeTargetDev = PMCloneOCProvisionDev(pTargetDev);
if (!removeData->revokeTargetDev)
{
- OC_LOG(ERROR, TAG, "SRPRemoveDevices : PMCloneOCProvisionDev Failed");
+ OIC_LOG(ERROR, TAG, "SRPRemoveDevices : PMCloneOCProvisionDev Failed");
res = OC_STACK_NO_MEMORY;
goto error;
}
(OCProvisionResult_t*)OICCalloc(numOfLinkedDev, sizeof(OCProvisionResult_t));
if (!removeData->removeRes)
{
- OC_LOG(ERROR, TAG, "SRPRemoveDevices : Failed to memory allocation");
+ OIC_LOG(ERROR, TAG, "SRPRemoveDevices : Failed to memory allocation");
res = OC_STACK_NO_MEMORY;
goto error;
}
removeData->revokeTargetDev, curDev);
if (OC_STACK_OK != res)
{
- OC_LOG_V(ERROR, TAG, "SRPRemoveDevice : Fail to send the DELETE credential request to\
+ OIC_LOG_V(ERROR, TAG, "SRPRemoveDevice : Fail to send the DELETE credential request to\
%s:%u", curDev->endpoint.addr, curDev->endpoint.port);
}
else
PDMDestoryOicUuidLinkList(pLinkedUuidList); //TODO: Modify API name to have unified convention.
PMDeleteDeviceList(pOwnedDevList);
- OC_LOG(INFO, TAG, "OUT SRPRemoveDevice");
+ OIC_LOG(INFO, TAG, "OUT SRPRemoveDevice");
return totalRes; // Caller of this API should wait callback if totalRes == OC_STACK_OK.
OICFree(removeData->removeRes);
OICFree(removeData);
}
- OC_LOG(INFO, TAG, "OUT ERROR case SRPRemoveDevice");
+ OIC_LOG(INFO, TAG, "OUT ERROR case SRPRemoveDevice");
return res;
}