#include "credresource.h"
#include "utlist.h"
#include "aclresource.h" //Note: SRM internal header
+#include "pconfresource.h"
#define TAG "OCPMAPI"
*/
OCStackResult OCDiscoverUnownedDevices(unsigned short timeout, OCProvisionDev_t **ppList)
{
- if( ppList == NULL || *ppList != NULL)
+ if( ppList == NULL || *ppList != NULL || 0 == timeout)
{
return OC_STACK_INVALID_PARAM;
}
*/
OCStackResult OCDiscoverOwnedDevices(unsigned short timeout, OCProvisionDev_t **ppList)
{
- if( ppList == NULL || *ppList != NULL)
+ if( ppList == NULL || *ppList != NULL || 0 == timeout)
{
return OC_STACK_INVALID_PARAM;
}
{
if(NULL == callbackData)
{
- return OC_STACK_INVALID_PARAM;
+ return OC_STACK_INVALID_CALLBACK ;
}
return OTMSetOwnershipTransferCallbackData(oxm, callbackData);
{
return OC_STACK_INVALID_PARAM;
}
-
+ if (!resultCallback)
+ {
+ OIC_LOG(INFO, TAG, "OCDoOwnershipTransfer : NULL Callback");
+ return OC_STACK_INVALID_CALLBACK;
+ }
return OTMDoOwnershipTransfer(ctx, targetDevices, resultCallback);
}
}
+/**
+ * this function sends Direct-Pairing Configuration to a device.
+ *
+ * @param[in] ctx Application context would be returned in result callback.
+ * @param[in] selectedDeviceInfo Selected target device.
+ * @param[in] pconf PCONF pointer.
+ * @param[in] resultCallback callback provided by API user, callback will be called when provisioning
+ request recieves a response from resource server.
+ * @return OC_STACK_OK in case of success and other value otherwise.
+ */
+OCStackResult OCProvisionDirectPairing(void* ctx, const OCProvisionDev_t *selectedDeviceInfo, OicSecPconf_t *pconf,
+ OCProvisionResultCB resultCallback)
+{
+ return SRPProvisionDirectPairing(ctx, selectedDeviceInfo, pconf, resultCallback);
+}
+
/*
* Function to unlink devices.
* This function will remove the credential & relationship between the two devices.
const OCProvisionDev_t* pTargetDev2,
OCProvisionResultCB resultCallback)
{
- OC_LOG(INFO, TAG, "IN OCUnlinkDevices");
+ OIC_LOG(INFO, TAG, "IN OCUnlinkDevices");
OCUuidList_t* idList = NULL;
size_t numOfDev = 0;
- if (!pTargetDev1 || !pTargetDev2 || !resultCallback)
+ if (!pTargetDev1 || !pTargetDev2 || !pTargetDev1->doxm || !pTargetDev2->doxm)
+ {
+ OIC_LOG(ERROR, TAG, "OCUnlinkDevices : NULL parameters");
+ return OC_STACK_INVALID_PARAM;
+ }
+ if (!resultCallback)
{
- OC_LOG(ERROR, TAG, "OCUnlinkDevices : NULL parameters");
+ OIC_LOG(INFO, TAG, "OCUnlinkDevices : NULL Callback");
+ return OC_STACK_INVALID_CALLBACK;
+ }
+ if (0 == memcmp(&pTargetDev1->doxm->deviceID, &pTargetDev2->doxm->deviceID, sizeof(OicUuid_t)))
+ {
+ OIC_LOG(INFO, TAG, "OCUnlinkDevices : Same device ID");
return OC_STACK_INVALID_PARAM;
}
OCStackResult res = PDMGetLinkedDevices(&(pTargetDev1->doxm->deviceID), &idList, &numOfDev);
if (OC_STACK_OK != res)
{
- OC_LOG(ERROR, TAG, "OCUnlinkDevices : PDMgetOwnedDevices failed");
+ OIC_LOG(ERROR, TAG, "OCUnlinkDevices : PDMgetOwnedDevices failed");
goto error;
}
if (1 > numOfDev)
{
- OC_LOG(DEBUG, TAG, "OCUnlinkDevices : Can not find linked devices");
+ OIC_LOG(DEBUG, TAG, "OCUnlinkDevices : Can not find linked devices");
res = OC_STACK_INVALID_PARAM; // Input devices are not linked, No request is made
goto error;
}
res = SRPUnlinkDevices(ctx, pTargetDev1, pTargetDev2, resultCallback);
if (OC_STACK_OK != res)
{
- OC_LOG(ERROR, TAG, "OCUnlinkDevices : Failed to unlink devices.");
+ OIC_LOG(ERROR, TAG, "OCUnlinkDevices : Failed to unlink devices.");
}
goto error;
}
curDev = curDev->next;
}
- OC_LOG(DEBUG, TAG, "No matched pair found from provisioning database");
+ OIC_LOG(DEBUG, TAG, "No matched pair found from provisioning database");
res = OC_STACK_INVALID_PARAM; // Input devices are not linked, No request is made
error:
- OC_LOG(INFO, TAG, "OUT OCUnlinkDevices");
+ OIC_LOG(INFO, TAG, "OUT OCUnlinkDevices");
PDMDestoryOicUuidLinkList(idList);
return res;
const OCProvisionDev_t* pTargetDev,
OCProvisionResultCB resultCallback)
{
- OC_LOG(INFO, TAG, "IN OCRemoveDevice");
+ OIC_LOG(INFO, TAG, "IN OCRemoveDevice");
OCStackResult res = OC_STACK_ERROR;
- if (!pTargetDev || !resultCallback || 0 == waitTimeForOwnedDeviceDiscovery)
+ if (!pTargetDev || 0 == waitTimeForOwnedDeviceDiscovery)
{
- OC_LOG(INFO, TAG, "OCRemoveDevice : Invalied parameters");
+ OIC_LOG(INFO, TAG, "OCRemoveDevice : Invalied parameters");
return OC_STACK_INVALID_PARAM;
}
+ if (!resultCallback)
+ {
+ OIC_LOG(INFO, TAG, "OCRemoveDevice : NULL Callback");
+ return OC_STACK_INVALID_CALLBACK;
+ }
// Send DELETE requests to linked devices
OCStackResult resReq = OC_STACK_ERROR; // Check that we have to wait callback or not.
{
if (OC_STACK_CONTINUE == resReq)
{
- OC_LOG(DEBUG, TAG, "OCRemoveDevice : Revoked device has no linked device except PT.");
+ OIC_LOG(DEBUG, TAG, "OCRemoveDevice : Revoked device has no linked device except PT.");
}
else
{
- OC_LOG(ERROR, TAG, "OCRemoveDevice : Failed to invoke SRPRemoveDevice");
+ OIC_LOG(ERROR, TAG, "OCRemoveDevice : Failed to invoke SRPRemoveDevice");
res = resReq;
goto error;
}
cred = GetCredResourceData(&pTargetDev->doxm->deviceID);
if (cred == NULL)
{
- OC_LOG(ERROR, TAG, "OCRemoveDevice : Failed to get credential of remove device.");
+ OIC_LOG(ERROR, TAG, "OCRemoveDevice : Failed to get credential of remove device.");
goto error;
}
res = RemoveCredential(&cred->subject);
if (res != OC_STACK_RESOURCE_DELETED)
{
- OC_LOG(ERROR, TAG, "OCRemoveDevice : Failed to remove credential.");
+ OIC_LOG(ERROR, TAG, "OCRemoveDevice : Failed to remove credential.");
goto error;
}
res = PDMSetDeviceStale(&pTargetDev->doxm->deviceID);
if (res != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "OCRemoveDevice : Failed to set device status as stale");
+ OIC_LOG(ERROR, TAG, "OCRemoveDevice : Failed to set device status as stale");
goto error;
}
CAResult_t caResult = CACloseDtlsSession(endpoint);
if(CA_STATUS_OK != caResult)
{
- OC_LOG_V(WARNING, TAG, "OCRemoveDevice : Failed to close DTLS session : %d", caResult);
+ OIC_LOG_V(WARNING, TAG, "OCRemoveDevice : Failed to close DTLS session : %d", caResult);
}
/**
}
error:
- OC_LOG(INFO, TAG, "OUT OCRemoveDevice");
+ OIC_LOG(INFO, TAG, "OUT OCRemoveDevice");
return res;
}
static void UpdateLinkResults(Linkdata_t *link, int device, OCStackResult stackresult)
{
- OC_LOG_V(INFO,TAG,"value of link->currentCountResults is %d",link->currentCountResults);
+ OIC_LOG_V(INFO,TAG,"value of link->currentCountResults is %d",link->currentCountResults);
if (1 == device)
{
memcpy(link->resArr[(link->currentCountResults)].deviceId.id, link->pDev1->doxm->deviceID.id,UUID_LENGTH);
if (NULL == ctx)
{
- OC_LOG(ERROR,TAG,"Context is Null in ACLProv 2");
+ OIC_LOG(ERROR,TAG,"Context is Null in ACLProv 2");
return;
}
(void)nOfRes;
if (hasError)
{
UpdateLinkResults(link, 2,arr[0].res);
- OC_LOG(ERROR,TAG,"Error occured while ACL provisioning device 1");
+ OIC_LOG(ERROR,TAG,"Error occured while ACL provisioning device 1");
((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
link->resArr,
true);
if (NULL == ctx)
{
- OC_LOG(ERROR,TAG,"Context is Null in ACLProv1");
+ OIC_LOG(ERROR,TAG,"Context is Null in ACLProv1");
return;
}
(void)nOfRes;
if (hasError)
{
- OC_LOG(ERROR,TAG,"Error occured while ACL provisioning device 1");
+ OIC_LOG(ERROR,TAG,"Error occured while ACL provisioning device 1");
UpdateLinkResults(link, 1, arr[0].res);
((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
link->resArr,
{
if (NULL == ctx)
{
- OC_LOG(ERROR,TAG,"Error occured while credential provisioning");
+ OIC_LOG(ERROR,TAG,"Error occured while credential provisioning");
return;
}
Linkdata_t *link = (Linkdata_t*)ctx;
OCProvisionResultCB resultCallback = link->resultCallback;
- OC_LOG_V(INFO, TAG, "has error returned %d",hasError);
+ OIC_LOG_V(INFO, TAG, "has error returned %d",hasError);
UpdateLinkResults(link, 1, arr[0].res);
UpdateLinkResults(link, 2, arr[1].res);
if (hasError)
{
- OC_LOG(ERROR,TAG,"Error occured while credential provisioning");
+ OIC_LOG(ERROR,TAG,"Error occured while credential provisioning");
((OCProvisionResultCB)(resultCallback))(link->ctx, nOfRes,
link->resArr,
true);
OCStackResult res = SRPProvisionACL(ctx, link->pDev1, link->pDev1Acl, &AclProv1CB);
if (OC_STACK_OK!=res)
{
- OC_LOG(ERROR, TAG, "Error while provisioning ACL for device 1");
+ OIC_LOG(ERROR, TAG, "Error while provisioning ACL for device 1");
UpdateLinkResults(link, 1, res);
((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
link->resArr,
}
else if (NULL!=link->pDev2Acl)
{
- OC_LOG(ERROR, TAG, "ACL for device 1 is NULL");
+ OIC_LOG(ERROR, TAG, "ACL for device 1 is NULL");
OCStackResult res = SRPProvisionACL(ctx, link->pDev2, link->pDev2Acl, &AclProv2CB);
if (OC_STACK_OK!=res)
{
- OC_LOG(ERROR, TAG, "Error while provisioning ACL for device 2");
+ OIC_LOG(ERROR, TAG, "Error while provisioning ACL for device 2");
UpdateLinkResults(link, 2, res);
((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
link->resArr,
}
else
{
- OC_LOG(INFO, TAG, "ACLs of both devices are NULL");
+ OIC_LOG(INFO, TAG, "ACLs of both devices are NULL");
((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
link->resArr,
false);
OCProvisionResultCB resultCallback)
{
- if (!pDev1 || !pDev2 || !resultCallback)
+ if (!pDev1 || !pDev2 || !pDev1->doxm || !pDev2->doxm)
{
- OC_LOG(ERROR, TAG, "OCProvisionPairwiseDevices : Invalid parameters");
+ OIC_LOG(ERROR, TAG, "OCProvisionPairwiseDevices : Invalid parameters");
return OC_STACK_INVALID_PARAM;
}
+ if (!resultCallback)
+ {
+ OIC_LOG(INFO, TAG, "OCProvisionPairwiseDevices : NULL Callback");
+ return OC_STACK_INVALID_CALLBACK;
+ }
if (!(keySize == OWNER_PSK_LENGTH_128 || keySize == OWNER_PSK_LENGTH_256))
{
- OC_LOG(INFO, TAG, "OCProvisionPairwiseDevices : Invalid key size");
+ OIC_LOG(INFO, TAG, "OCProvisionPairwiseDevices : Invalid key size");
+ return OC_STACK_INVALID_PARAM;
+ }
+ if (0 == memcmp(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID, sizeof(OicUuid_t)))
+ {
+ OIC_LOG(INFO, TAG, "OCProvisionPairwiseDevices : Same device ID");
return OC_STACK_INVALID_PARAM;
}
- OC_LOG(DEBUG, TAG, "Checking link in DB");
+ OIC_LOG(DEBUG, TAG, "Checking link in DB");
bool linkExists = true;
OCStackResult res = PDMIsLinkExists(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID, &linkExists);
if(res != OC_STACK_OK)
{
- OC_LOG(ERROR, TAG, "Internal Error Occured");
+ OIC_LOG(ERROR, TAG, "Internal Error Occured");
return res;
}
if (linkExists)
{
- OC_LOG(ERROR, TAG, "Link already exists");
+ OIC_LOG(ERROR, TAG, "Link already exists");
return OC_STACK_INVALID_PARAM;
}
Linkdata_t *link = (Linkdata_t*) OICMalloc(sizeof(Linkdata_t));
if (!link)
{
- OC_LOG(ERROR, TAG, "Failed to memory allocation");
+ OIC_LOG(ERROR, TAG, "Failed to memory allocation");
return OC_STACK_NO_MEMORY;
}
- OC_LOG_V(INFO,TAG, "Maximum no od results %d",noOfResults);
+ OIC_LOG_V(INFO,TAG, "Maximum no od results %d",noOfResults);
link->pDev1 = pDev1;
link->pDev1Acl = pDev1Acl;
{
//TODO will be replaced by more efficient logic
if (pOwnedDevList == NULL || *pOwnedDevList != NULL || pUnownedDevList == NULL
- || *pUnownedDevList != NULL)
+ || *pUnownedDevList != NULL || 0 == waittime)
{
return OC_STACK_INVALID_PARAM;
}
OCStackResult res = OCDiscoverUnownedDevices(waittime/2, &unownedDevice);
if (OC_STACK_OK != res)
{
- OC_LOG(ERROR,TAG, "Error in unowned discovery");
+ OIC_LOG(ERROR,TAG, "Error in unowned discovery");
return res;
}
res = OCDiscoverOwnedDevices(waittime/2, &ownedDevice);
if (OC_STACK_OK != res)
{
- OC_LOG(ERROR,TAG, "Error in owned discovery");
+ OIC_LOG(ERROR,TAG, "Error in owned discovery");
PMDeleteDeviceList(unownedDevice);
return res;
}
res = PDMGetOwnedDevices(&uuidList, &numOfDevices);
if (OC_STACK_OK != res)
{
- OC_LOG(ERROR, TAG, "Error while getting info from DB");
+ OIC_LOG(ERROR, TAG, "Error while getting info from DB");
PMDeleteDeviceList(unownedDevice);
PMDeleteDeviceList(ownedDevice);
return res;
OCProvisionDev_t *ptr = (OCProvisionDev_t *)OICCalloc(1, sizeof (OCProvisionDev_t));
if (NULL == ptr)
{
- OC_LOG(ERROR,TAG,"Fail to allocate memory");
+ OIC_LOG(ERROR,TAG,"Fail to allocate memory");
PMDeleteDeviceList(unownedDevice);
PMDeleteDeviceList(ownedDevice);
OCDeleteUuidList(uuidList);
ptr->doxm = (OicSecDoxm_t*)OICCalloc(1, sizeof(OicSecDoxm_t));
if (NULL == ptr->doxm)
{
- OC_LOG(ERROR,TAG,"Fail to allocate memory");
+ OIC_LOG(ERROR,TAG,"Fail to allocate memory");
PMDeleteDeviceList(unownedDevice);
PMDeleteDeviceList(ownedDevice);
OCDeleteUuidList(uuidList);
DeleteACLList(pAcl);
}
+/**
+ * This function deletes PDACL data.
+ *
+ * @param pPdAcl Pointer to OicSecPdAcl_t structure.
+ */
+void OCDeletePdAclList(OicSecPdAcl_t* pPdAcl)
+{
+ FreePdAclList(pPdAcl);
+}
+
#ifdef __WITH_X509__
/**