+
+OCStackResult OCGetDevInfoFromNetwork(unsigned short waittime,
+ OCProvisionDev_t** pOwnedDevList,
+ OCProvisionDev_t** pUnownedDevList)
+{
+ //TODO will be replaced by more efficient logic
+ if (pOwnedDevList == NULL || *pOwnedDevList != NULL || pUnownedDevList == NULL
+ || *pUnownedDevList != NULL || 0 == waittime)
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ // Code for unowned discovery
+ OCProvisionDev_t *unownedDevice = NULL;
+ OCStackResult res = OCDiscoverUnownedDevices(waittime/2, &unownedDevice);
+ if (OC_STACK_OK != res)
+ {
+ OIC_LOG(ERROR,TAG, "Error in unowned discovery");
+ return res;
+ }
+
+ // Code for owned discovery
+ OCProvisionDev_t *ownedDevice = NULL;
+ res = OCDiscoverOwnedDevices(waittime/2, &ownedDevice);
+ if (OC_STACK_OK != res)
+ {
+ OIC_LOG(ERROR,TAG, "Error in owned discovery");
+ PMDeleteDeviceList(unownedDevice);
+ return res;
+ }
+
+ // Code to get list of all the owned devices.
+ OCUuidList_t *uuidList = NULL;
+ size_t numOfDevices = 0;
+ res = PDMGetOwnedDevices(&uuidList, &numOfDevices);
+ if (OC_STACK_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "Error while getting info from DB");
+ PMDeleteDeviceList(unownedDevice);
+ PMDeleteDeviceList(ownedDevice);
+ return res;
+ }
+
+ // Code to compare devices in unowned list and deviceid from DB
+ // (In case of hard reset of the device)
+ OCProvisionDev_t* pUnownedList = unownedDevice;
+ while (pUnownedList && uuidList)
+ {
+ OCUuidList_t *tmp1 = NULL,*tmp2=NULL;
+ LL_FOREACH_SAFE(uuidList, tmp1, tmp2)
+ {
+ if(0 == memcmp(tmp1->dev.id, pUnownedList->doxm->deviceID.id,
+ sizeof(pUnownedList->doxm->deviceID.id)))
+ {
+ OIC_LOG_V(INFO, TAG, "OCGetDevInfoFromNetwork : \
+ Removing device id = %s in PDM and dat.", pUnownedList->doxm->deviceID.id);
+ if (OC_STACK_OK != PDMDeleteDevice(&pUnownedList->doxm->deviceID))
+ {
+ OIC_LOG(ERROR, TAG, "OCGetDevInfoFromNetwork : \
+ Failed to remove device in PDM.");
+ }
+ //remove the cred entry from dat file
+ if (OC_STACK_OK != RemoveDeviceInfoFromLocal(pUnownedList))
+ {
+ OIC_LOG(ERROR, TAG, "OCGetDevInfoFromNetwork : \
+ Failed to remove cred entry device in dat file.");
+ }
+ LL_DELETE(uuidList, tmp1);
+ OICFree(tmp1);
+ }
+ }
+ pUnownedList = pUnownedList->next;
+ }
+ // Code to compare devices in owned list and deviceid from DB.
+ OCProvisionDev_t* pCurDev = ownedDevice;
+ size_t deleteCnt = 0;
+ while (pCurDev)
+ {
+ if(true == PMDeleteFromUUIDList(&uuidList, &pCurDev->doxm->deviceID))
+ {
+ deleteCnt++;
+ }
+ pCurDev = pCurDev->next;
+ }
+ // If there is no remaind device in uuidList, we have to assign NULL to prevent free.
+ if (deleteCnt == numOfDevices)
+ {
+ uuidList = NULL;
+ }
+ // Code to add information of the devices which are currently off in owned list.
+ OCUuidList_t *powerOffDeviceList = uuidList;
+ while (powerOffDeviceList)
+ {
+ OCProvisionDev_t *ptr = (OCProvisionDev_t *)OICCalloc(1, sizeof (OCProvisionDev_t));
+ if (NULL == ptr)
+ {
+ OIC_LOG(ERROR,TAG,"Fail to allocate memory");
+ PMDeleteDeviceList(unownedDevice);
+ PMDeleteDeviceList(ownedDevice);
+ OCDeleteUuidList(uuidList);
+ return OC_STACK_NO_MEMORY;
+ }
+
+ ptr->doxm = (OicSecDoxm_t*)OICCalloc(1, sizeof(OicSecDoxm_t));
+ if (NULL == ptr->doxm)
+ {
+ OIC_LOG(ERROR,TAG,"Fail to allocate memory");
+ PMDeleteDeviceList(unownedDevice);
+ PMDeleteDeviceList(ownedDevice);
+ OCDeleteUuidList(uuidList);
+ OICFree(ptr);
+ return OC_STACK_NO_MEMORY;
+ }
+
+ memcpy(ptr->doxm->deviceID.id, powerOffDeviceList->dev.id, sizeof(ptr->doxm->deviceID.id));
+
+ ptr->devStatus = DEV_STATUS_OFF;
+ LL_PREPEND(ownedDevice, ptr);
+ powerOffDeviceList = powerOffDeviceList->next;
+
+ }
+ OCDeleteUuidList(uuidList);
+ *pOwnedDevList = ownedDevice;
+ *pUnownedDevList = unownedDevice;
+ return OC_STACK_OK;
+}
+
+OCStackResult OCGetLinkedStatus(const OicUuid_t* uuidOfDevice, OCUuidList_t** uuidList,
+ size_t* numOfDevices)
+{
+ return PDMGetLinkedDevices(uuidOfDevice, uuidList, numOfDevices);
+}
+
+void OCDeleteUuidList(OCUuidList_t* pList)
+{
+ PDMDestoryOicUuidLinkList(pList);
+}
+
+/**
+ * This function deletes ACL data.
+ *
+ * @param pAcl Pointer to OicSecAcl_t structure.
+ */
+void OCDeleteACLList(OicSecAcl_t* pAcl)
+{
+ DeleteACLList(pAcl);
+}
+
+/**
+ * This function deletes PDACL data.
+ *
+ * @param pPdAcl Pointer to OicSecPdAcl_t structure.
+ */
+void OCDeletePdAclList(OicSecPdAcl_t* pPdAcl)
+{
+ FreePdAclList(pPdAcl);
+}
+
+#ifdef MULTIPLE_OWNER
+/**
+ * API to update 'doxm.mom' to resource server.
+ *
+ * @param[in] targetDeviceInfo Selected target device.
+ * @param[in] momType Mode of multiple ownership transfer (ref. oic.sec.mom)
+ * @param[in] resultCallback callback provided by API user, callback will be called when
+ * POST 'mom' request recieves a response from resource server.
+ * @return OC_STACK_OK in case of success and other value otherwise.
+ */
+OCStackResult OCChangeMOTMode(void *ctx, const OCProvisionDev_t *targetDeviceInfo,
+ const OicSecMomType_t momType, OCProvisionResultCB resultCallback)
+{
+ return MOTChangeMode(ctx, targetDeviceInfo, momType, resultCallback);
+}
+
+/**
+ * API to update 'doxm.oxmsel' to resource server.
+ *
+ * @param[in] targetDeviceInfo Selected target device.
+ * @param[in] oxmSelValue Method of multiple ownership transfer (ref. oic.sec.oxm)
+ * @param[in] resultCallback callback provided by API user, callback will be called when
+ * POST 'oxmsel' request recieves a response from resource server.
+ * @return OC_STACK_OK in case of success and other value otherwise.
+ */
+OCStackResult OCSelectMOTMethod(void *ctx, const OCProvisionDev_t *targetDeviceInfo,
+ const OicSecOxm_t oxmSelValue, OCProvisionResultCB resultCallback)
+{
+ return MOTSelectMOTMethod(ctx, targetDeviceInfo, oxmSelValue, resultCallback);
+}
+#endif //MULTIPLE_OWNER
+
+/**
+ * Function to select appropriate security provisioning method.
+ *
+ * @param[in] supportedMethods Array of supported methods
+ * @param[in] numberOfMethods number of supported methods
+ * @param[out] selectedMethod Selected methods
+ * @param[in] ownerType type of owner device (SUPER_OWNER or SUB_OWNER)
+ * @return OC_STACK_OK on success
+ */
+OCStackResult OCSelectOwnershipTransferMethod(const OicSecOxm_t *supportedMethods,
+ size_t numberOfMethods, OicSecOxm_t *selectedMethod, OwnerType_t ownerType)
+{
+ return OTMSelectOwnershipTransferMethod(supportedMethods, numberOfMethods,
+ selectedMethod, ownerType);
+}
+
+#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
+/**
+ * function to provision Trust certificate chain to devices.
+ *
+ * @param[in] ctx Application context would be returned in result callback.
+ * @param[in] type Type of credentials to be provisioned to the device.
+ * @param[in] credId CredId of trust certificate chain to be provisioned to the device.
+ * @param[in] selectedDeviceInfo Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.
+ * @param[in] resultCallback callback provided by API user, callback will be called when
+ * provisioning request recieves a response from first resource server.
+ * @return OC_STACK_OK in case of success and other value otherwise.
+ */
+OCStackResult OCProvisionTrustCertChain(void *ctx, OicSecCredType_t type, uint16_t credId,
+ const OCProvisionDev_t *selectedDeviceInfo,
+ OCProvisionResultCB resultCallback)
+{
+ return SRPProvisionTrustCertChain(ctx, type, credId,
+ selectedDeviceInfo, resultCallback);
+}
+
+/**
+ * function to save Trust certificate chain into Cred of SVR.
+ *
+ * @param[in] trustCertChain Trust certificate chain to be saved in Cred of SVR.
+ * @param[in] chainSize Size of trust certificate chain to be saved in Cred of SVR
+ * @param[in] encodingType Encoding type of trust certificate chain to be saved in Cred of SVR
+ * @param[out] credId CredId of saved trust certificate chain in Cred of SVR.
+ * @return OC_STACK_OK in case of success and other value otherwise.
+ */
+OCStackResult OCSaveTrustCertChain(uint8_t *trustCertChain, size_t chainSize,
+ OicEncodingType_t encodingType, uint16_t *credId)
+{
+ return SRPSaveTrustCertChain(trustCertChain, chainSize, encodingType, credId);
+}
+
+/**
+ * function to register notifier for Trustcertchain change.
+ *
+ * @param[in] ctx user context.
+ * @param[in] TrustCertChainChangeCB notification callback fucntion.
+ * @return OC_STACK_OK in case of success and other value otherwise.
+ */
+OCStackResult OCRegisterTrustCertChainNotifier(void *ctx, TrustCertChainChangeCB Callback)
+{
+ return SRPRegisterTrustCertChainNotifier(ctx, Callback);
+}
+
+/**
+ * function to de-register notifier for Trustcertchain change.
+ */
+void OCRemoveTrustCertChainNotifier()
+{
+ SRPRemoveTrustCertChainNotifier();
+}
+
+/**
+ * This function sets the callback to utilize peer certificate information
+ */
+OCStackResult OCSetPeerCertCallback(void *ctx, PeerCertCallback peerCertCallback)
+{
+ CAResult_t ret;
+
+ OIC_LOG_V(DEBUG, TAG, "IN %s", __func__);
+ ret = CAsetPeerCertCallback(ctx, peerCertCallback);
+ if (CA_STATUS_OK != ret)
+ {
+ OIC_LOG_V(ERROR, TAG, "CAsetPeerCertCallback() Failed(%d)", ret);
+ return OC_STACK_ERROR;
+ }
+ OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__);
+
+ return OC_STACK_OK;
+}
+
+#endif // __WITH_DTLS__ || __WITH_TLS__
+