1 /* *****************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * *****************************************************************/
24 #include "ocprovisioningmanager.h"
25 #include "pmutility.h"
26 #include "srmutility.h"
27 #include "ownershiptransfermanager.h"
29 #include "multipleownershiptransfermanager.h"
30 #endif //MULTIPLE_OWNER
31 #include "oic_malloc.h"
33 #include "secureresourceprovider.h"
34 #include "provisioningdatabasemanager.h"
35 #include "credresource.h"
37 #include "aclresource.h" //Note: SRM internal header
38 #include "pconfresource.h"
39 #include "psinterface.h"
40 #include "srmresourcestrings.h"
42 #define TAG "OIC_OCPMAPI"
44 typedef struct Linkdata Linkdata_t;
48 const OCProvisionDev_t *pDev1;
49 OicSecAcl_t *pDev1Acl;
50 const OCProvisionDev_t *pDev2;
51 OicSecAcl_t *pDev2Acl;
52 OCProvisionResult_t *resArr;
54 int currentCountResults;
55 OCProvisionResultCB resultCallback;
60 typedef struct ProvPreconfPINCtx ProvPreconfPINCtx_t;
61 struct ProvPreconfPINCtx
64 const OCProvisionDev_t *devInfo;
67 OCProvisionResultCB resultCallback;
69 #endif //MULTIPLE_OWNER
72 * The function is responsible for initializaton of the provisioning manager. It will load
73 * provisioning database which have owned device's list and their linked status.
74 * TODO: In addition, if there is a device(s) which has not up-to-date credentials, this function will
75 * automatically try to update the deivce(s).
77 * @param[in] dbPath file path of the sqlite3 db
79 * @return OC_STACK_OK in case of success and other value otherwise.
81 OCStackResult OCInitPM(const char* dbPath)
83 return PDMInit(dbPath);
91 OCStackResult OCPDMCleanupForTimeout()
93 return PDMDeleteDeviceWithState(PDM_DEVICE_INIT);
97 * The function is responsible for discovery of owned/unowned device is specified endpoint/deviceID.
98 * And this function will only return the specified device's response.
100 * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
101 * server before returning the device.
102 * @param[in] deviceID deviceID of target device.
103 * @param[out] ppFoundDevice OCProvisionDev_t of found device
104 * @return OTM_SUCCESS in case of success and other value otherwise.
106 OCStackResult OCDiscoverSingleDevice(unsigned short timeout, const OicUuid_t* deviceID,
107 OCProvisionDev_t **ppFoundDevice)
109 if( NULL == ppFoundDevice || NULL != *ppFoundDevice || 0 == timeout || NULL == deviceID)
111 return OC_STACK_INVALID_PARAM;
114 return PMSingleDeviceDiscovery(timeout, deviceID, ppFoundDevice);
118 * The function is responsible for discovery of owned/unowned device is specified endpoint/deviceID.
119 * And this function will only return the specified device's response.
121 * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
122 * server before returning the device.
123 * @param[in] deviceID deviceID of target device.
124 * @param[in] hostAddress MAC address of target device.
125 * @param[in] connType ConnectivityType for discovery.
126 * @param[out] ppFoundDevice OCProvisionDev_t of found device.
127 * @return OTM_SUCCESS in case of success and other value otherwise.
129 OCStackResult OCDiscoverSingleDeviceInUnicast(unsigned short timeout, const OicUuid_t* deviceID,
130 const char* hostAddress, OCConnectivityType connType,
131 OCProvisionDev_t **ppFoundDevice)
133 if( NULL == ppFoundDevice || NULL != *ppFoundDevice || 0 == timeout || NULL == deviceID ||
136 OIC_LOG(ERROR, TAG, "OCDiscoverSingleDeviceInUnicast : Invalid Parameter");
137 return OC_STACK_INVALID_PARAM;
140 return PMSingleDeviceDiscoveryInUnicast(timeout, deviceID, hostAddress, connType,
145 * The function is responsible for discovery of device is current subnet. It will list
146 * all the device in subnet which are not yet owned. Please call OCInit with OC_CLIENT_SERVER as
149 * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
150 * server before returning the list of devices.
151 * @param[out] ppList List of candidate devices to be provisioned
152 * @return OTM_SUCCESS in case of success and other value otherwise.
154 OCStackResult OCDiscoverUnownedDevices(unsigned short timeout, OCProvisionDev_t **ppList)
156 if( ppList == NULL || *ppList != NULL || 0 == timeout)
158 return OC_STACK_INVALID_PARAM;
161 return PMDeviceDiscovery(timeout, false, ppList);
165 * The function is responsible for discovery of owned device is current subnet. It will list
166 * all the device in subnet which are owned by calling provisioning client.
168 * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
169 * server before returning the list of devices.
170 * @param[out] ppList List of device owned by provisioning tool.
171 * @return OTM_SUCCESS in case of success and other value otherwise.
173 OCStackResult OCDiscoverOwnedDevices(unsigned short timeout, OCProvisionDev_t **ppList)
175 if( ppList == NULL || *ppList != NULL || 0 == timeout)
177 return OC_STACK_INVALID_PARAM;
180 return PMDeviceDiscovery(timeout, true, ppList);
183 #ifdef MULTIPLE_OWNER
185 * The function is responsible for discovery of MOT enabled device is current subnet.
187 * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
188 * server before returning the list of devices.
189 * @param[out] ppList List of MOT enabled devices.
190 * @return OC_STACK_OK in case of success and other value otherwise.
192 OCStackResult OCDiscoverMultipleOwnerEnabledDevices(unsigned short timeout, OCProvisionDev_t **ppList)
194 if( ppList == NULL || *ppList != NULL || 0 == timeout)
196 return OC_STACK_INVALID_PARAM;
199 return PMMultipleOwnerDeviceDiscovery(timeout, false, ppList);
203 * The function is responsible for discovery of Multiple Owned device is current subnet.
205 * @param[in] timeout Timeout in seconds, value till which function will listen to responses from
206 * server before returning the list of devices.
207 * @param[out] ppList List of Multiple Owned devices.
208 * @return OC_STACK_OK in case of success and other value otherwise.
210 OCStackResult OCDiscoverMultipleOwnedDevices(unsigned short timeout, OCProvisionDev_t **ppList)
212 if( ppList == NULL || *ppList != NULL || 0 == timeout)
214 return OC_STACK_INVALID_PARAM;
217 return PMMultipleOwnerDeviceDiscovery(timeout, true, ppList);
222 * API to add preconfigured PIN to local SVR DB.
224 * @param[in] targetDeviceInfo Selected target device.
225 * @param[in] preconfigPin Preconfig PIN which is used while multiple owner authentication
226 * @param[in] preconfigPinLen Byte length of preconfigPin
228 * @return OC_STACK_OK in case of success and other value otherwise.
230 OCStackResult OCAddPreconfigPin(const OCProvisionDev_t *targetDeviceInfo,
231 const char *preconfigPin,
232 size_t preconfigPinLen)
234 return MOTAddPreconfigPIN(targetDeviceInfo, preconfigPin, preconfigPinLen);
238 OCStackResult OCDoMultipleOwnershipTransfer(void* ctx,
239 OCProvisionDev_t *targetDevices,
240 OCProvisionResultCB resultCallback)
242 if( NULL == targetDevices )
244 return OC_STACK_INVALID_PARAM;
246 if (NULL == resultCallback)
248 OIC_LOG(INFO, TAG, "OCDoOwnershipTransfer : NULL Callback");
249 return OC_STACK_INVALID_CALLBACK;
251 return MOTDoOwnershipTransfer(ctx, targetDevices, resultCallback);
254 OCStackResult OCRemoveSubOwner(void* ctx,
255 const OCProvisionDev_t *targetDeviceInfo,
256 const OicUuid_t* subOwner,
257 OCProvisionResultCB resultCallback)
259 if (NULL == targetDeviceInfo || NULL == subOwner)
261 OIC_LOG_V(ERROR, TAG, "%s : NULL Param", __func__);
262 return OC_STACK_INVALID_PARAM;
264 if (NULL == resultCallback)
266 OIC_LOG_V(ERROR, TAG, "%s : NULL Callback", __func__);
267 return OC_STACK_INVALID_CALLBACK;
270 return MOTRemoveSubOwner(ctx, targetDeviceInfo, subOwner, resultCallback);
273 OCStackResult OCRemoveAllSubOwner(void* ctx,
274 const OCProvisionDev_t *targetDeviceInfo,
275 OCProvisionResultCB resultCallback)
277 if (NULL == targetDeviceInfo)
279 OIC_LOG_V(ERROR, TAG, "%s : NULL Param", __func__);
280 return OC_STACK_INVALID_PARAM;
282 if (NULL == resultCallback)
284 OIC_LOG_V(ERROR, TAG, "%s : NULL Callback", __func__);
285 return OC_STACK_INVALID_CALLBACK;
288 return MOTRemoveSubOwner(ctx, targetDeviceInfo, &WILDCARD_SUBJECT_ID, resultCallback);
292 #endif //MULTIPLE_OWNER
295 * API to register for particular OxM.
297 * @param[in] Ownership transfer method.
298 * @param[in] Implementation of callback functions for owership transfer.
299 * @return OC_STACK_OK in case of success and other value otherwise.
301 OCStackResult OCSetOwnerTransferCallbackData(OicSecOxm_t oxm, OTMCallbackData_t* callbackData)
303 if(NULL == callbackData)
305 return OC_STACK_INVALID_CALLBACK ;
308 return OTMSetOwnershipTransferCallbackData(oxm, callbackData);
312 * API to set a allow status of OxM
314 * @param[in] oxm Owership transfer method (ref. OicSecOxm_t)
315 * @param[in] allowStatus allow status (true = allow, false = not allow)
317 * @return OC_STACK_OK in case of success and other value otherwise.
319 OCStackResult OCSetOxmAllowStatus(const OicSecOxm_t oxm, const bool allowStatus)
321 return OTMSetOxmAllowStatus(oxm, allowStatus);
324 OCStackResult OCDoOwnershipTransfer(void* ctx,
325 OCProvisionDev_t *targetDevices,
326 OCProvisionResultCB resultCallback)
328 if( NULL == targetDevices )
330 return OC_STACK_INVALID_PARAM;
334 OIC_LOG(INFO, TAG, "OCDoOwnershipTransfer : NULL Callback");
335 return OC_STACK_INVALID_CALLBACK;
337 return OTMDoOwnershipTransfer(ctx, targetDevices, resultCallback);
340 OCStackResult OCDoCustomOwnershipTransfer(void* ctx,
341 OCProvisionDev_t *selectedDevice,
342 OCProvisionResultCB resultCallback,
343 const OicSecOxm_t method)
345 if( NULL == selectedDevice )
347 return OC_STACK_INVALID_PARAM;
351 OIC_LOG(INFO, TAG, "OCDoCustomOwnershipTransfer : NULL Callback");
352 return OC_STACK_INVALID_CALLBACK;
354 return OTMDoCustomOwnershipTransfer(ctx, selectedDevice, resultCallback, method);
358 * This function deletes memory allocated to linked list created by OCDiscover_XXX_Devices API.
360 * @param[in] pList Pointer to OCProvisionDev_t which should be deleted.
362 void OCDeleteDiscoveredDevices(OCProvisionDev_t *pList)
364 PMDeleteDeviceList(pList);
368 * this function sends ACL information to resource.
370 * @param[in] ctx Application context would be returned in result callback.
371 * @param[in] selectedDeviceInfo Selected target device.
372 * @param[in] acl ACL to provision.
373 * @param[in] resultCallback callback provided by API user, callback will be called when provisioning
374 request recieves a response from resource server.
375 * @return OC_STACK_OK in case of success and other value otherwise.
377 OCStackResult OCProvisionACL(void* ctx, const OCProvisionDev_t *selectedDeviceInfo, OicSecAcl_t *acl,
378 OCProvisionResultCB resultCallback)
380 return SRPProvisionACL(ctx, selectedDeviceInfo, acl, resultCallback);
384 * function to save ACL which has several ACE into Acl of SVR.
386 * @param acl ACL to be saved in Acl of SVR.
387 * @return OC_STACK_OK in case of success and other value otherwise.
389 OCStackResult OCSaveACL(const OicSecAcl_t* acl)
391 return SRPSaveACL(acl);
395 * this function requests CRED information to resource.
397 * @param[in] ctx Application context would be returned in result callback.
398 * @param[in] selectedDeviceInfo Selected target device.
399 * @param[in] resultCallback callback provided by API user, callback will be called when provisioning
400 request recieves a response from resource server.
401 * @return OC_STACK_OK in case of success and other value otherwise.
403 OCStackResult OCGetCredResource(void* ctx, const OCProvisionDev_t *selectedDeviceInfo,
404 OCProvisionResultCB resultCallback)
406 return SRPGetCredResource(ctx, selectedDeviceInfo, resultCallback);
410 * this function requests ACL information to resource.
412 * @param[in] ctx Application context would be returned in result callback.
413 * @param[in] selectedDeviceInfo Selected target device.
414 * @param[in] resultCallback callback provided by API user, callback will be called when provisioning
415 request recieves a response from resource server.
416 * @return OC_STACK_OK in case of success and other value otherwise.
418 OCStackResult OCGetACLResource(void* ctx, const OCProvisionDev_t *selectedDeviceInfo,
419 OCProvisionResultCB resultCallback)
421 return SRPGetACLResource(ctx, selectedDeviceInfo, resultCallback);
425 OCStackResult OCReadTrustCertChain(uint16_t credId, uint8_t **trustCertChain,
428 return SRPReadTrustCertChain(credId, trustCertChain, chainSize);
431 * function to provision credential to devices.
433 * @param[in] ctx Application context would be returned in result callback.
434 * @param[in] type Type of credentials to be provisioned to the device.
435 * @param[in] pDev1 Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.
436 @param[in] pDev2 Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.
437 * @param[in] resultCallback callback provided by API user, callback will be called when
438 * provisioning request recieves a response from first resource server.
439 * @return OC_STACK_OK in case of success and other value otherwise.
441 OCStackResult OCProvisionCredentials(void *ctx, OicSecCredType_t type, size_t keySize,
442 const OCProvisionDev_t *pDev1,
443 const OCProvisionDev_t *pDev2,
444 OCProvisionResultCB resultCallback)
446 return SRPProvisionCredentials(ctx, type, keySize,
447 pDev1, pDev2, resultCallback);
452 * this function sends Direct-Pairing Configuration to a device.
454 * @param[in] ctx Application context would be returned in result callback.
455 * @param[in] selectedDeviceInfo Selected target device.
456 * @param[in] pconf PCONF pointer.
457 * @param[in] resultCallback callback provided by API user, callback will be called when provisioning
458 request recieves a response from resource server.
459 * @return OC_STACK_OK in case of success and other value otherwise.
461 OCStackResult OCProvisionDirectPairing(void* ctx, const OCProvisionDev_t *selectedDeviceInfo, OicSecPconf_t *pconf,
462 OCProvisionResultCB resultCallback)
464 return SRPProvisionDirectPairing(ctx, selectedDeviceInfo, pconf, resultCallback);
467 #ifdef MULTIPLE_OWNER
468 static void AddPreconfPinOxMCB(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError)
470 ProvPreconfPINCtx_t* provCtx = (ProvPreconfPINCtx_t*)ctx;
473 OCStackResult res = MOTProvisionPreconfigPIN(provCtx->ctx, provCtx->devInfo, provCtx->pin, provCtx->pinLen, provCtx->resultCallback);
474 if(OC_STACK_OK != res)
477 provCtx->resultCallback(provCtx->ctx, nOfRes, arr, true);
482 OCStackResult OCProvisionPreconfigPin(void *ctx,
483 OCProvisionDev_t *targetDeviceInfo,
484 const char *preconfigPin,
485 size_t preconfigPinLen,
486 OCProvisionResultCB resultCallback)
488 if( NULL == targetDeviceInfo || NULL == preconfigPin || 0 == preconfigPinLen )
490 return OC_STACK_INVALID_PARAM;
492 if (NULL == resultCallback)
494 OIC_LOG(INFO, TAG, "OCProvisionPreconfigPinCredential : NULL Callback");
495 return OC_STACK_INVALID_CALLBACK;
498 ProvPreconfPINCtx_t* provCtx = (ProvPreconfPINCtx_t*)OICCalloc(1, sizeof(ProvPreconfPINCtx_t));
501 return OC_STACK_NO_MEMORY;
504 provCtx->devInfo = targetDeviceInfo;
505 provCtx->pin = preconfigPin;
506 provCtx->pinLen = preconfigPinLen;
507 provCtx->resultCallback = resultCallback;
509 * First of all, update OxMs to support preconfigured PIN OxM.
510 * In case of Preconfigured PIN OxM already supported on the server side,
511 * MOTAddMOTMethod API will be send POST Cred request.
512 * In case of Preconfigure PIN OxM not exist on the server side,
513 * the MOTAddMOTMethod API will be send POST doxm request to update OxMs and then send POST Cred request.
515 return MOTAddMOTMethod((void*)provCtx, targetDeviceInfo, OIC_PRECONFIG_PIN, AddPreconfPinOxMCB);
517 #endif //MULTIPLE_OWNER
520 * Function to unlink devices.
521 * This function will remove the credential & relationship between the two devices.
523 * @param[in] ctx Application context would be returned in result callback
524 * @param[in] pTargetDev1 first device information to be unlinked.
525 * @param[in] pTargetDev2 second device information to be unlinked.
526 * @param[in] resultCallback callback provided by API user, callback will be called when
527 * device unlink is finished.
528 * @return OC_STACK_OK in case of success and other value otherwise.
530 OCStackResult OCUnlinkDevices(void* ctx,
531 const OCProvisionDev_t* pTargetDev1,
532 const OCProvisionDev_t* pTargetDev2,
533 OCProvisionResultCB resultCallback)
535 OIC_LOG(INFO, TAG, "IN OCUnlinkDevices");
536 OCUuidList_t* idList = NULL;
539 if (!pTargetDev1 || !pTargetDev2 || !pTargetDev1->doxm || !pTargetDev2->doxm)
541 OIC_LOG(ERROR, TAG, "OCUnlinkDevices : NULL parameters");
542 return OC_STACK_INVALID_PARAM;
546 OIC_LOG(INFO, TAG, "OCUnlinkDevices : NULL Callback");
547 return OC_STACK_INVALID_CALLBACK;
549 if (0 == memcmp(&pTargetDev1->doxm->deviceID, &pTargetDev2->doxm->deviceID, sizeof(OicUuid_t)))
551 OIC_LOG(INFO, TAG, "OCUnlinkDevices : Same device ID");
552 return OC_STACK_INVALID_PARAM;
555 // Get linked devices with the first device.
556 OCStackResult res = PDMGetLinkedDevices(&(pTargetDev1->doxm->deviceID), &idList, &numOfDev);
557 if (OC_STACK_OK != res)
559 OIC_LOG(ERROR, TAG, "OCUnlinkDevices : PDMgetOwnedDevices failed");
564 OIC_LOG(DEBUG, TAG, "OCUnlinkDevices : Can not find linked devices");
565 res = OC_STACK_INVALID_PARAM; // Input devices are not linked, No request is made
569 // Check the linked devices contains the second device. If yes send credential DELETE request.
570 OCUuidList_t* curDev = idList;
571 while (NULL != curDev)
573 if (memcmp(pTargetDev2->doxm->deviceID.id, curDev->dev.id, sizeof(curDev->dev.id)) == 0)
575 res = SRPUnlinkDevices(ctx, pTargetDev1, pTargetDev2, resultCallback);
576 if (OC_STACK_OK != res)
578 OIC_LOG(ERROR, TAG, "OCUnlinkDevices : Failed to unlink devices.");
582 curDev = curDev->next;
584 OIC_LOG(DEBUG, TAG, "No matched pair found from provisioning database");
585 res = OC_STACK_INVALID_PARAM; // Input devices are not linked, No request is made
588 OIC_LOG(INFO, TAG, "OUT OCUnlinkDevices");
590 PDMDestoryOicUuidLinkList(idList);
594 static OCStackResult RemoveDeviceInfoFromLocal(const OCProvisionDev_t* pTargetDev)
596 // Remove credential of revoked device from SVR database
597 OCStackResult res = OC_STACK_ERROR;
598 const OicSecCred_t *cred = NULL;
600 OIC_LOG(DEBUG, TAG, "IN RemoveDeviceInfoFromLocal");
601 cred = GetCredResourceData(&pTargetDev->doxm->deviceID);
604 res = RemoveCredential(&cred->subject);
605 if (res != OC_STACK_RESOURCE_DELETED)
607 OIC_LOG(ERROR, TAG, "RemoveDeviceInfoFromLocal : Failed to remove credential.");
612 * Change the device status as stale status.
613 * If all request are successed, this device information will be deleted.
615 res = PDMSetDeviceState(&pTargetDev->doxm->deviceID, PDM_DEVICE_STALE);
616 if (res != OC_STACK_OK)
618 OIC_LOG(WARNING, TAG, "OCRemoveDevice : Failed to set device status as stale");
621 // TODO: We need to add new mechanism to clean up the stale state of the device.
623 // Close the DTLS session of the removed device.
624 CAResult_t caResult = CAcloseSslConnectionUsingUuid(pTargetDev->doxm->deviceID.id
625 , sizeof(pTargetDev->doxm->deviceID.id));
626 if(CA_STATUS_OK != caResult)
628 OIC_LOG_V(WARNING, TAG, "OCRemoveDevice : Failed to close (D)TLS session : %d", caResult);
630 OIC_LOG(DEBUG, TAG, "OUT RemoveDeviceInfoFromLocal");
636 * Function to device revocation
637 * This function will remove credential of target device from all devices in subnet.
639 * @param[in] ctx Application context would be returned in result callback
640 * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds)
641 * @param[in] pTargetDev Device information to be revoked.
642 * @param[in] resultCallback callback provided by API user, callback will be called when
643 * credential revocation is finished.
644 * @return OC_STACK_OK in case of success and other value otherwise.
646 OCStackResult OCRemoveDevice(void* ctx, unsigned short waitTimeForOwnedDeviceDiscovery,
647 const OCProvisionDev_t* pTargetDev,
648 OCProvisionResultCB resultCallback)
650 OIC_LOG(INFO, TAG, "IN OCRemoveDevice");
651 OCStackResult res = OC_STACK_ERROR;
652 if (!pTargetDev || 0 == waitTimeForOwnedDeviceDiscovery)
654 OIC_LOG(INFO, TAG, "OCRemoveDevice : Invalied parameters");
655 return OC_STACK_INVALID_PARAM;
659 OIC_LOG(INFO, TAG, "OCRemoveDevice : NULL Callback");
660 return OC_STACK_INVALID_CALLBACK;
663 // Send DELETE requests to linked devices
664 OCStackResult resReq = OC_STACK_ERROR; // Check that we have to wait callback or not.
665 resReq = SRPRemoveDevice(ctx, waitTimeForOwnedDeviceDiscovery, pTargetDev, resultCallback);
666 if (OC_STACK_OK != resReq)
668 if (OC_STACK_CONTINUE == resReq)
670 OIC_LOG(DEBUG, TAG, "OCRemoveDevice : Revoked device has no linked device except PT.");
674 OIC_LOG(ERROR, TAG, "OCRemoveDevice : Failed to invoke SRPRemoveDevice");
680 res = RemoveDeviceInfoFromLocal(pTargetDev);
681 if(OC_STACK_OK != res)
683 OIC_LOG(ERROR, TAG, "Filed to remove the device information from local.");
687 if(OC_STACK_CONTINUE == resReq)
690 * If there is no linked device, PM does not send any request.
691 * So we should directly invoke the result callback to inform the result of OCRemoveDevice.
695 resultCallback(ctx, 0, NULL, false);
701 OIC_LOG(INFO, TAG, "OUT OCRemoveDevice");
705 #if !defined(MAX_WAIT_TIME)
706 #define MAX_WAIT_TIME 15
710 static void localResultCallback(void* ctx)
716 * Function to device revocation
717 * This function will remove credential of target device from all devices in subnet.
719 * @param[in] ctx Application context would be returned in result callback
720 * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds)
721 * @param[in] pTargetDev Device information to be revoked.
722 * @param[in] resultCallback callback provided by API user, callback will be called when
723 * credential revocation is finished.
724 * @return OC_STACK_OK in case of success and other value otherwise.
726 OCStackResult OCRemoveDeviceWithUuid(void* ctx, unsigned short waitTimeForOwnedDeviceDiscovery,
727 const OicUuid_t* pTargetUuid,
728 OCProvisionResultCB resultCallback)
730 OIC_LOG(INFO, TAG, "IN OCRemoveDeviceWithUuid");
732 OCStackResult res = OC_STACK_ERROR;
733 OCProvisionDev_t* pTargetDev = NULL;
734 bool discoverdFlag = false;
735 OCProvisionDev_t* pOwnedDevList = NULL;
736 OCStackResult resReq = OC_STACK_CONTINUE;
738 if (!pTargetUuid || 0 == waitTimeForOwnedDeviceDiscovery)
740 OIC_LOG(INFO, TAG, "OCRemoveDeviceWithUuid : Invalid parameters");
741 return OC_STACK_INVALID_PARAM;
745 OIC_LOG(INFO, TAG, "OCRemoveDeviceWithUuid : NULL Callback");
746 return OC_STACK_INVALID_CALLBACK;
749 char* strUuid = NULL;
750 if(OC_STACK_OK != ConvertUuidToStr(pTargetUuid, &strUuid))
752 OIC_LOG(WARNING, TAG, "Failed to covert UUID to String.");
756 //Generate OCProvisionDev_t instance to use when target device not found on the network.
757 //In this case, the device id required only.
758 pTargetDev = (OCProvisionDev_t*)OICCalloc(1, sizeof(OCProvisionDev_t));
759 if(NULL == pTargetDev)
761 OIC_LOG(ERROR, TAG, "Failed to allocate memory.");
762 res = OC_STACK_NO_MEMORY;
765 pTargetDev->doxm = (OicSecDoxm_t*)OICCalloc(1, sizeof(OicSecDoxm_t));
766 if(NULL == pTargetDev->doxm)
768 OIC_LOG(ERROR, TAG, "Failed to allocate memory.");
769 res = OC_STACK_NO_MEMORY;
772 memcpy(pTargetDev->doxm->deviceID.id, pTargetUuid->id, sizeof(pTargetUuid->id));
774 OCUuidList_t* linkedDevices = NULL;
775 size_t numOfLinkedDevices = 0;
776 res = PDMGetLinkedDevices(pTargetUuid, &linkedDevices, &numOfLinkedDevices);
777 if(OC_STACK_OK != res)
779 OIC_LOG(ERROR, TAG, "Error in PDMGetLinkedDevices");
782 PDMDestoryOicUuidLinkList(linkedDevices);
784 //2. Find owned device from the network
785 res = PMDeviceDiscovery(waitTimeForOwnedDeviceDiscovery, true, &pOwnedDevList);
786 if (OC_STACK_OK != res)
788 OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid : Failed to PMDeviceDiscovery");
792 OCProvisionDev_t* tempDev = NULL;
793 LL_FOREACH(pOwnedDevList, tempDev)
795 if(memcmp(&tempDev->doxm->deviceID.id, pTargetUuid->id, sizeof(pTargetUuid->id)) == 0)
803 OIC_LOG_V(WARNING, TAG, "Can not find [%s] on the network.", strUuid);
804 OIC_LOG_V(WARNING, TAG, "[%s]'s information will be deleted from local and other devices.", strUuid);
808 OICFree(pTargetDev->doxm);
810 pTargetDev = tempDev;
811 discoverdFlag = true;
812 OIC_LOG_V(INFO, TAG, "[%s] is detected on the network.", strUuid);
815 //If there is no linked devices, device revocation step can be skipped.
816 if(0 != numOfLinkedDevices)
818 OIC_LOG_V(INFO, TAG, "[%s] linked with other devices.", strUuid);
819 OIC_LOG_V(INFO, TAG, "Trying [%s] revocation.", strUuid);
821 // Send DELETE requests to linked devices
822 resReq = SRPRemoveDeviceWithoutDiscovery(ctx, pOwnedDevList, pTargetDev, resultCallback);
823 if (OC_STACK_OK != resReq)
825 if (OC_STACK_CONTINUE == resReq)
827 OIC_LOG(INFO, TAG, "OCRemoveDeviceWithUuid : Revoked device has no linked device except PT.");
831 OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid : Failed to invoke SRPRemoveDevice");
839 OIC_LOG_V(INFO, TAG, "There is no linked devices with [%s]", strUuid);
840 OIC_LOG(INFO, TAG, "Device discovery and SRPRemoveDevice will be skipped.");
843 int maxWait = MAX_WAIT_TIME;
846 SRPResetDevice(pTargetDev, localResultCallback);
847 while(g_reset && maxWait)
853 if(OC_STACK_CONTINUE == resReq)
855 resultCallback(ctx, 0, NULL, false);
859 res = RemoveDeviceInfoFromLocal(pTargetDev);
860 if(OC_STACK_OK != res)
862 OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid : Failed to remove the device information from local.");
867 PMDeleteDeviceList(pOwnedDevList);
868 if(pTargetDev && false == discoverdFlag)
870 OICFree(pTargetDev->doxm);
873 OIC_LOG(INFO, TAG, "OUT OCRemoveDeviceWithUuid");
878 * Function to reset the target device.
879 * This function will remove credential and ACL of target device from all devices in subnet.
881 * @param[in] ctx Application context would be returned in result callback
882 * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds)
883 * @param[in] pTargetDev Device information to be revoked.
884 * @param[in] resultCallback callback provided by API user, callback will be called when
885 * credential revocation is finished.
886 * @return OC_STACK_OK in case of success and other value otherwise.
888 OCStackResult OCResetDevice(void* ctx, unsigned short waitTimeForOwnedDeviceDiscovery,
889 const OCProvisionDev_t* pTargetDev,
890 OCProvisionResultCB resultCallback,
891 OCClientContextDeleter deleteCallback)
893 OIC_LOG(INFO, TAG, "IN OCResetDevice");
894 OCStackResult res = OC_STACK_ERROR;
895 if (!pTargetDev || 0 == waitTimeForOwnedDeviceDiscovery)
897 OIC_LOG(INFO, TAG, "OCResetDevice : Invalid parameters");
898 return OC_STACK_INVALID_PARAM;
900 if (!deleteCallback || !resultCallback)
902 OIC_LOG(INFO, TAG, "OCResetDevice : NULL Callback");
903 return OC_STACK_INVALID_CALLBACK;
906 // Send DELETE requests to linked devices
907 res = SRPSyncDevice(ctx, waitTimeForOwnedDeviceDiscovery, pTargetDev, resultCallback);
908 if (OC_STACK_CONTINUE == res)
910 OIC_LOG(DEBUG, TAG, "OCResetDevice : Target device has no linked device except PT.");
913 resultCallback(ctx, 0, NULL, false);
915 SRPResetDevice(pTargetDev, deleteCallback);
918 else if(OC_STACK_OK != res)
920 OIC_LOG(ERROR, TAG, "OCResetDevice : Failed to invoke SRPSyncDevice");
922 OIC_LOG(INFO, TAG, "OUT OCResetDevice");
927 * This function resets SVR DB to its factory setting.
929 * @return OC_STACK_OK in case of successful reset and other value otherwise.
931 OCStackResult OCResetSVRDB(void)
933 return ResetSecureResourceInPS();
937 * This function to register callback, for getting notification if SVR DB was reseted.
938 * @param[in] ResetSVRDBCB notifier callback function.
939 * @return OC_STACK_OK in case of successful reset and other value otherwise.
942 OCStackResult OCRegisterResetSVRDBNotifier(ResetSVRDBCB callback)
944 OIC_LOG_V(INFO, TAG, "IN %s", __func__);
946 if(NULL != GetResetSVRDBCB()->callback)
948 OIC_LOG_V(ERROR, TAG,"%s Can't register notifier callback, unregister previous one!" ,__func__);
949 return OC_STACK_ERROR;
952 GetResetSVRDBCB()->callback = callback;
954 OIC_LOG_V(INFO, TAG, "Out %s", __func__);
960 * This function to unregister ResetSVRDBCB notification callback.
962 void OCUnregisterResetSVRDBNotifier(void)
964 OIC_LOG_V(INFO, TAG, "IN %s", __func__);
966 if(NULL != GetResetSVRDBCB()->callback)
968 GetResetSVRDBCB()->callback = NULL;
971 OIC_LOG_V(INFO, TAG, "Out %s", __func__);
975 * This function configures SVR DB as self-ownership.
977 *@return OC_STACK_OK in case of successful configue and other value otherwise.
979 OCStackResult OCConfigSelfOwnership(void)
981 return ConfigSelfOwnership();
985 * Internal Function to update result in link result array.
987 static void UpdateLinkResults(Linkdata_t *link, int device, OCStackResult stackresult)
990 OIC_LOG_V(INFO,TAG,"value of link->currentCountResults is %d",link->currentCountResults);
993 memcpy(link->resArr[(link->currentCountResults)].deviceId.id, link->pDev1->doxm->deviceID.id,UUID_LENGTH);
997 memcpy(link->resArr[(link->currentCountResults)].deviceId.id, link->pDev2->doxm->deviceID.id,UUID_LENGTH);
999 link->resArr[(link->currentCountResults)].res = stackresult;
1000 ++(link->currentCountResults);
1005 * Callback to handle ACL provisioning for device 2.
1007 static void AclProv2CB(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError)
1012 OIC_LOG(ERROR,TAG,"Context is Null in ACLProv 2");
1016 Linkdata_t *link = (Linkdata_t*)ctx;
1017 OCProvisionResultCB resultCallback = link->resultCallback;
1022 UpdateLinkResults(link, 2,arr[0].res);
1023 OIC_LOG(ERROR,TAG,"Error occured while ACL provisioning device 1");
1024 ((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
1027 OICFree(link->resArr);
1031 UpdateLinkResults(link, 2, arr[0].res);
1032 ((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
1035 OICFree(link->resArr);
1041 * Callback to handle ACL provisioning for device 1
1043 static void AclProv1CB(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError)
1048 OIC_LOG(ERROR,TAG,"Context is Null in ACLProv1");
1052 Linkdata_t *link = (Linkdata_t*)ctx;
1053 OCProvisionResultCB resultCallback = link->resultCallback;
1057 OIC_LOG(ERROR,TAG,"Error occured while ACL provisioning device 1");
1058 UpdateLinkResults(link, 1, arr[0].res);
1059 ((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
1062 OICFree(link->resArr);
1066 UpdateLinkResults(link, 1, arr[0].res);
1067 if (NULL != link->pDev2Acl)
1069 OCStackResult res = SRPProvisionACL(ctx, link->pDev2, link->pDev2Acl, &AclProv2CB);
1070 if (OC_STACK_OK!=res)
1072 UpdateLinkResults(link, 2, res);
1073 ((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
1081 ((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
1084 OICFree(link->resArr);
1092 * Callback to handle credential provisioning.
1094 static void ProvisionCredsCB(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError)
1098 OIC_LOG(ERROR,TAG,"Error occured while credential provisioning");
1101 Linkdata_t *link = (Linkdata_t*)ctx;
1102 OCProvisionResultCB resultCallback = link->resultCallback;
1103 OIC_LOG_V(INFO, TAG, "has error returned %d",hasError);
1104 UpdateLinkResults(link, 1, arr[0].res);
1105 UpdateLinkResults(link, 2, arr[1].res);
1108 OIC_LOG(ERROR,TAG,"Error occured while credential provisioning");
1109 ((OCProvisionResultCB)(resultCallback))(link->ctx, nOfRes,
1112 OICFree(link->resArr);
1116 if (NULL != link->pDev1Acl)
1119 OCStackResult res = SRPProvisionACL(ctx, link->pDev1, link->pDev1Acl, &AclProv1CB);
1120 if (OC_STACK_OK!=res)
1122 OIC_LOG(ERROR, TAG, "Error while provisioning ACL for device 1");
1123 UpdateLinkResults(link, 1, res);
1124 ((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
1127 OICFree(link->resArr);
1131 else if (NULL!=link->pDev2Acl)
1133 OIC_LOG(ERROR, TAG, "ACL for device 1 is NULL");
1134 OCStackResult res = SRPProvisionACL(ctx, link->pDev2, link->pDev2Acl, &AclProv2CB);
1135 if (OC_STACK_OK!=res)
1137 OIC_LOG(ERROR, TAG, "Error while provisioning ACL for device 2");
1138 UpdateLinkResults(link, 2, res);
1139 ((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
1142 OICFree(link->resArr);
1148 OIC_LOG(INFO, TAG, "ACLs of both devices are NULL");
1149 ((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
1152 OICFree(link->resArr);
1158 * function to provision credentials between two devices and ACLs for the devices who act as a server.
1160 * @param[in] ctx Application context would be returned in result callback.
1161 * @param[in] type Type of credentials to be provisioned to the device.
1162 * @param[in] pDev1 Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.
1163 * @param[in] acl ACL for device 1. If this is not required set NULL.
1164 * @param[in] pDev2 Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.
1165 * @param[in] acl ACL for device 2. If this is not required set NULL.
1166 * @param[in] resultCallback callback provided by API user, callback will be called when
1167 * provisioning request recieves a response from first resource server.
1168 * @return OC_STACK_OK in case of success and other value otherwise.
1170 OCStackResult OCProvisionPairwiseDevices(void* ctx, OicSecCredType_t type, size_t keySize,
1171 const OCProvisionDev_t *pDev1, OicSecAcl_t *pDev1Acl,
1172 const OCProvisionDev_t *pDev2, OicSecAcl_t *pDev2Acl,
1173 OCProvisionResultCB resultCallback)
1176 if (!pDev1 || !pDev2 || !pDev1->doxm || !pDev2->doxm)
1178 OIC_LOG(ERROR, TAG, "OCProvisionPairwiseDevices : Invalid parameters");
1179 return OC_STACK_INVALID_PARAM;
1181 if (!resultCallback)
1183 OIC_LOG(INFO, TAG, "OCProvisionPairwiseDevices : NULL Callback");
1184 return OC_STACK_INVALID_CALLBACK;
1186 if (!(keySize == OWNER_PSK_LENGTH_128 || keySize == OWNER_PSK_LENGTH_256))
1188 OIC_LOG(INFO, TAG, "OCProvisionPairwiseDevices : Invalid key size");
1189 return OC_STACK_INVALID_PARAM;
1191 if (0 == memcmp(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID, sizeof(OicUuid_t)))
1193 OIC_LOG(INFO, TAG, "OCProvisionPairwiseDevices : Same device ID");
1194 return OC_STACK_INVALID_PARAM;
1197 OIC_LOG(DEBUG, TAG, "Checking link in DB");
1198 bool linkExists = true;
1199 OCStackResult res = PDMIsLinkExists(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID, &linkExists);
1200 if(res != OC_STACK_OK)
1202 OIC_LOG(ERROR, TAG, "Internal Error Occured");
1207 OIC_LOG(ERROR, TAG, "Link already exists");
1208 return OC_STACK_INVALID_PARAM;
1211 int noOfResults = 2; // Initial Value
1212 if (NULL != pDev1Acl)
1216 if (NULL != pDev2Acl)
1220 Linkdata_t *link = (Linkdata_t*) OICMalloc(sizeof(Linkdata_t));
1223 OIC_LOG(ERROR, TAG, "Failed to memory allocation");
1224 return OC_STACK_NO_MEMORY;
1226 OIC_LOG_V(INFO,TAG, "Maximum no od results %d",noOfResults);
1228 link->pDev1 = pDev1;
1229 link->pDev1Acl = pDev1Acl;
1230 link->pDev2 = pDev2;
1231 link->pDev2Acl = pDev2Acl;
1233 // 1 call for each device for credential provisioning. implict call by SRPProvisioning credential
1234 // 1 call for ACL provisioning for device 1 and 1 call for ACL provisioning for device 2.
1235 link->numOfResults = noOfResults;
1236 link->resultCallback = resultCallback;
1237 link->currentCountResults = 0;
1238 link->resArr = (OCProvisionResult_t*) OICMalloc(sizeof(OCProvisionResult_t)*noOfResults);
1239 res = SRPProvisionCredentials(link, type, keySize,
1240 pDev1, pDev2, &ProvisionCredsCB);
1241 if (res != OC_STACK_OK)
1243 OICFree(link->resArr);
1250 OCStackResult OCGetDevInfoFromNetwork(unsigned short waittime,
1251 OCProvisionDev_t** pOwnedDevList,
1252 OCProvisionDev_t** pUnownedDevList)
1254 //TODO will be replaced by more efficient logic
1255 if (pOwnedDevList == NULL || *pOwnedDevList != NULL || pUnownedDevList == NULL
1256 || *pUnownedDevList != NULL || 0 == waittime)
1258 return OC_STACK_INVALID_PARAM;
1261 // Code for unowned discovery
1262 OCProvisionDev_t *unownedDevice = NULL;
1263 OCStackResult res = OCDiscoverUnownedDevices(waittime/2, &unownedDevice);
1264 if (OC_STACK_OK != res)
1266 OIC_LOG(ERROR,TAG, "Error in unowned discovery");
1270 // Code for owned discovery
1271 OCProvisionDev_t *ownedDevice = NULL;
1272 res = OCDiscoverOwnedDevices(waittime/2, &ownedDevice);
1273 if (OC_STACK_OK != res)
1275 OIC_LOG(ERROR,TAG, "Error in owned discovery");
1276 PMDeleteDeviceList(unownedDevice);
1280 // Code to get list of all the owned devices.
1281 OCUuidList_t *uuidList = NULL;
1282 size_t numOfDevices = 0;
1283 res = PDMGetOwnedDevices(&uuidList, &numOfDevices);
1284 if (OC_STACK_OK != res)
1286 OIC_LOG(ERROR, TAG, "Error while getting info from DB");
1287 PMDeleteDeviceList(unownedDevice);
1288 PMDeleteDeviceList(ownedDevice);
1292 // Code to compare devices in unowned list and deviceid from DB
1293 // (In case of hard reset of the device)
1294 OCProvisionDev_t* pUnownedList = unownedDevice;
1295 while (pUnownedList && uuidList)
1297 OCUuidList_t *tmp1 = NULL,*tmp2=NULL;
1298 LL_FOREACH_SAFE(uuidList, tmp1, tmp2)
1300 if(0 == memcmp(tmp1->dev.id, pUnownedList->doxm->deviceID.id,
1301 sizeof(pUnownedList->doxm->deviceID.id)))
1303 OIC_LOG_V(INFO, TAG, "OCGetDevInfoFromNetwork : \
1304 Removing device id = %s in PDM and dat.", pUnownedList->doxm->deviceID.id);
1305 if (OC_STACK_OK != PDMDeleteDevice(&pUnownedList->doxm->deviceID))
1307 OIC_LOG(ERROR, TAG, "OCGetDevInfoFromNetwork : \
1308 Failed to remove device in PDM.");
1310 //remove the cred entry from dat file
1311 if (OC_STACK_OK != RemoveDeviceInfoFromLocal(pUnownedList))
1313 OIC_LOG(ERROR, TAG, "OCGetDevInfoFromNetwork : \
1314 Failed to remove cred entry device in dat file.");
1316 LL_DELETE(uuidList, tmp1);
1320 pUnownedList = pUnownedList->next;
1322 // Code to compare devices in owned list and deviceid from DB.
1323 OCProvisionDev_t* pCurDev = ownedDevice;
1324 size_t deleteCnt = 0;
1327 if(true == PMDeleteFromUUIDList(&uuidList, &pCurDev->doxm->deviceID))
1331 pCurDev = pCurDev->next;
1333 // If there is no remaind device in uuidList, we have to assign NULL to prevent free.
1334 if (deleteCnt == numOfDevices)
1338 // Code to add information of the devices which are currently off in owned list.
1339 OCUuidList_t *powerOffDeviceList = uuidList;
1340 while (powerOffDeviceList)
1342 OCProvisionDev_t *ptr = (OCProvisionDev_t *)OICCalloc(1, sizeof (OCProvisionDev_t));
1345 OIC_LOG(ERROR,TAG,"Fail to allocate memory");
1346 PMDeleteDeviceList(unownedDevice);
1347 PMDeleteDeviceList(ownedDevice);
1348 OCDeleteUuidList(uuidList);
1349 return OC_STACK_NO_MEMORY;
1352 ptr->doxm = (OicSecDoxm_t*)OICCalloc(1, sizeof(OicSecDoxm_t));
1353 if (NULL == ptr->doxm)
1355 OIC_LOG(ERROR,TAG,"Fail to allocate memory");
1356 PMDeleteDeviceList(unownedDevice);
1357 PMDeleteDeviceList(ownedDevice);
1358 OCDeleteUuidList(uuidList);
1360 return OC_STACK_NO_MEMORY;
1363 memcpy(ptr->doxm->deviceID.id, powerOffDeviceList->dev.id, sizeof(ptr->doxm->deviceID.id));
1365 ptr->devStatus = DEV_STATUS_OFF;
1366 LL_PREPEND(ownedDevice, ptr);
1367 powerOffDeviceList = powerOffDeviceList->next;
1370 OCDeleteUuidList(uuidList);
1371 *pOwnedDevList = ownedDevice;
1372 *pUnownedDevList = unownedDevice;
1376 OCStackResult OCGetLinkedStatus(const OicUuid_t* uuidOfDevice, OCUuidList_t** uuidList,
1377 size_t* numOfDevices)
1379 return PDMGetLinkedDevices(uuidOfDevice, uuidList, numOfDevices);
1382 void OCDeleteUuidList(OCUuidList_t* pList)
1384 PDMDestoryOicUuidLinkList(pList);
1388 * This function deletes ACL data.
1390 * @param pAcl Pointer to OicSecAcl_t structure.
1392 void OCDeleteACLList(OicSecAcl_t* pAcl)
1394 DeleteACLList(pAcl);
1398 * This function deletes PDACL data.
1400 * @param pPdAcl Pointer to OicSecPdAcl_t structure.
1402 void OCDeletePdAclList(OicSecPdAcl_t* pPdAcl)
1404 FreePdAclList(pPdAcl);
1407 #ifdef MULTIPLE_OWNER
1409 * API to update 'doxm.mom' to resource server.
1411 * @param[in] targetDeviceInfo Selected target device.
1412 * @param[in] momType Mode of multiple ownership transfer (ref. oic.sec.mom)
1413 * @param[in] resultCallback callback provided by API user, callback will be called when
1414 * POST 'mom' request recieves a response from resource server.
1415 * @return OC_STACK_OK in case of success and other value otherwise.
1417 OCStackResult OCChangeMOTMode(void *ctx, const OCProvisionDev_t *targetDeviceInfo,
1418 const OicSecMomType_t momType, OCProvisionResultCB resultCallback)
1420 return MOTChangeMode(ctx, targetDeviceInfo, momType, resultCallback);
1424 * API to update 'doxm.oxmsel' to resource server.
1426 * @param[in] targetDeviceInfo Selected target device.
1427 * @param[in] oxmSelValue Method of multiple ownership transfer (ref. oic.sec.oxm)
1428 * @param[in] resultCallback callback provided by API user, callback will be called when
1429 * POST 'oxmsel' request recieves a response from resource server.
1430 * @return OC_STACK_OK in case of success and other value otherwise.
1432 OCStackResult OCSelectMOTMethod(void *ctx, const OCProvisionDev_t *targetDeviceInfo,
1433 const OicSecOxm_t oxmSelValue, OCProvisionResultCB resultCallback)
1435 return MOTSelectMOTMethod(ctx, targetDeviceInfo, oxmSelValue, resultCallback);
1437 #endif //MULTIPLE_OWNER
1440 * Function to select appropriate security provisioning method.
1442 * @param[in] supportedMethods Array of supported methods
1443 * @param[in] numberOfMethods number of supported methods
1444 * @param[out] selectedMethod Selected methods
1445 * @param[in] ownerType type of owner device (SUPER_OWNER or SUB_OWNER)
1446 * @return OC_STACK_OK on success
1448 OCStackResult OCSelectOwnershipTransferMethod(const OicSecOxm_t *supportedMethods,
1449 size_t numberOfMethods, OicSecOxm_t *selectedMethod, OwnerType_t ownerType)
1451 return OTMSelectOwnershipTransferMethod(supportedMethods, numberOfMethods,
1452 selectedMethod, ownerType);
1455 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
1457 * function to provision Trust certificate chain to devices.
1459 * @param[in] ctx Application context would be returned in result callback.
1460 * @param[in] type Type of credentials to be provisioned to the device.
1461 * @param[in] credId CredId of trust certificate chain to be provisioned to the device.
1462 * @param[in] selectedDeviceInfo Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.
1463 * @param[in] resultCallback callback provided by API user, callback will be called when
1464 * provisioning request recieves a response from first resource server.
1465 * @return OC_STACK_OK in case of success and other value otherwise.
1467 OCStackResult OCProvisionTrustCertChain(void *ctx, OicSecCredType_t type, uint16_t credId,
1468 const OCProvisionDev_t *selectedDeviceInfo,
1469 OCProvisionResultCB resultCallback)
1471 return SRPProvisionTrustCertChain(ctx, type, credId,
1472 selectedDeviceInfo, resultCallback);
1476 * function to save Trust certificate chain into Cred of SVR.
1478 * @param[in] trustCertChain Trust certificate chain to be saved in Cred of SVR.
1479 * @param[in] chainSize Size of trust certificate chain to be saved in Cred of SVR
1480 * @param[in] encodingType Encoding type of trust certificate chain to be saved in Cred of SVR
1481 * @param[out] credId CredId of saved trust certificate chain in Cred of SVR.
1482 * @return OC_STACK_OK in case of success and other value otherwise.
1484 OCStackResult OCSaveTrustCertChain(uint8_t *trustCertChain, size_t chainSize,
1485 OicEncodingType_t encodingType, uint16_t *credId)
1487 return SRPSaveTrustCertChain(trustCertChain, chainSize, encodingType, credId);
1491 * function to register notifier for Trustcertchain change.
1493 * @param[in] ctx user context.
1494 * @param[in] TrustCertChainChangeCB notification callback fucntion.
1495 * @return OC_STACK_OK in case of success and other value otherwise.
1497 OCStackResult OCRegisterTrustCertChainNotifier(void *ctx, TrustCertChainChangeCB Callback)
1499 return SRPRegisterTrustCertChainNotifier(ctx, Callback);
1503 * function to de-register notifier for Trustcertchain change.
1505 void OCRemoveTrustCertChainNotifier()
1507 SRPRemoveTrustCertChainNotifier();
1511 * This function sets the callback to utilize peer certificate information
1513 OCStackResult OCSetPeerCertCallback(void *ctx, PeerCertCallback peerCertCallback)
1517 OIC_LOG_V(DEBUG, TAG, "IN %s", __func__);
1518 ret = CAsetPeerCertCallback(ctx, peerCertCallback);
1519 if (CA_STATUS_OK != ret)
1521 OIC_LOG_V(ERROR, TAG, "CAsetPeerCertCallback() Failed(%d)", ret);
1522 return OC_STACK_ERROR;
1524 OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__);
1529 #endif // __WITH_DTLS__ || __WITH_TLS__