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 res = SRPResetDevice(pTargetDev, localResultCallback);
847 if(OC_STACK_OK == res)
849 while(g_reset && maxWait)
856 if(OC_STACK_CONTINUE == resReq)
858 resultCallback(ctx, 0, NULL, false);
862 res = RemoveDeviceInfoFromLocal(pTargetDev);
863 if(OC_STACK_OK != res)
865 OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid : Failed to remove the device information from local.");
870 PMDeleteDeviceList(pOwnedDevList);
871 if(pTargetDev && false == discoverdFlag)
873 OICFree(pTargetDev->doxm);
876 OIC_LOG(INFO, TAG, "OUT OCRemoveDeviceWithUuid");
881 * Function to reset the target device.
882 * This function will remove credential and ACL of target device from all devices in subnet.
884 * @param[in] ctx Application context would be returned in result callback
885 * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds)
886 * @param[in] pTargetDev Device information to be revoked.
887 * @param[in] resultCallback callback provided by API user, callback will be called when
888 * credential revocation is finished.
889 * @return OC_STACK_OK in case of success and other value otherwise.
891 OCStackResult OCResetDevice(void* ctx, unsigned short waitTimeForOwnedDeviceDiscovery,
892 const OCProvisionDev_t* pTargetDev,
893 OCProvisionResultCB resultCallback,
894 OCClientContextDeleter deleteCallback)
896 OIC_LOG(INFO, TAG, "IN OCResetDevice");
897 OCStackResult res = OC_STACK_ERROR;
898 if (!pTargetDev || 0 == waitTimeForOwnedDeviceDiscovery)
900 OIC_LOG(INFO, TAG, "OCResetDevice : Invalid parameters");
901 return OC_STACK_INVALID_PARAM;
903 if (!deleteCallback || !resultCallback)
905 OIC_LOG(INFO, TAG, "OCResetDevice : NULL Callback");
906 return OC_STACK_INVALID_CALLBACK;
909 // Send DELETE requests to linked devices
910 res = SRPSyncDevice(ctx, waitTimeForOwnedDeviceDiscovery, pTargetDev, resultCallback);
911 if (OC_STACK_CONTINUE == res)
913 OIC_LOG(DEBUG, TAG, "OCResetDevice : Target device has no linked device except PT.");
916 resultCallback(ctx, 0, NULL, false);
918 SRPResetDevice(pTargetDev, deleteCallback);
921 else if(OC_STACK_OK != res)
923 OIC_LOG(ERROR, TAG, "OCResetDevice : Failed to invoke SRPSyncDevice");
925 OIC_LOG(INFO, TAG, "OUT OCResetDevice");
930 * This function resets SVR DB to its factory setting.
932 * @return OC_STACK_OK in case of successful reset and other value otherwise.
934 OCStackResult OCResetSVRDB(void)
936 return ResetSecureResourceInPS();
940 * This function to register callback, for getting notification if SVR DB was reseted.
941 * @param[in] ResetSVRDBCB notifier callback function.
942 * @return OC_STACK_OK in case of successful reset and other value otherwise.
945 OCStackResult OCRegisterResetSVRDBNotifier(ResetSVRDBCB callback)
947 OIC_LOG_V(INFO, TAG, "IN %s", __func__);
949 if(NULL != GetResetSVRDBCB()->callback)
951 OIC_LOG_V(ERROR, TAG,"%s Can't register notifier callback, unregister previous one!" ,__func__);
952 return OC_STACK_ERROR;
955 GetResetSVRDBCB()->callback = callback;
957 OIC_LOG_V(INFO, TAG, "Out %s", __func__);
963 * This function to unregister ResetSVRDBCB notification callback.
965 void OCUnregisterResetSVRDBNotifier(void)
967 OIC_LOG_V(INFO, TAG, "IN %s", __func__);
969 if(NULL != GetResetSVRDBCB()->callback)
971 GetResetSVRDBCB()->callback = NULL;
974 OIC_LOG_V(INFO, TAG, "Out %s", __func__);
978 * This function configures SVR DB as self-ownership.
980 *@return OC_STACK_OK in case of successful configue and other value otherwise.
982 OCStackResult OCConfigSelfOwnership(void)
984 return ConfigSelfOwnership();
988 * Internal Function to update result in link result array.
990 static void UpdateLinkResults(Linkdata_t *link, int device, OCStackResult stackresult)
993 OIC_LOG_V(INFO,TAG,"value of link->currentCountResults is %d",link->currentCountResults);
996 memcpy(link->resArr[(link->currentCountResults)].deviceId.id, link->pDev1->doxm->deviceID.id,UUID_LENGTH);
1000 memcpy(link->resArr[(link->currentCountResults)].deviceId.id, link->pDev2->doxm->deviceID.id,UUID_LENGTH);
1002 link->resArr[(link->currentCountResults)].res = stackresult;
1003 ++(link->currentCountResults);
1008 * Callback to handle ACL provisioning for device 2.
1010 static void AclProv2CB(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError)
1015 OIC_LOG(ERROR,TAG,"Context is Null in ACLProv 2");
1019 Linkdata_t *link = (Linkdata_t*)ctx;
1020 OCProvisionResultCB resultCallback = link->resultCallback;
1025 UpdateLinkResults(link, 2,arr[0].res);
1026 OIC_LOG(ERROR,TAG,"Error occured while ACL provisioning device 1");
1027 ((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
1030 OICFree(link->resArr);
1034 UpdateLinkResults(link, 2, arr[0].res);
1035 ((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
1038 OICFree(link->resArr);
1044 * Callback to handle ACL provisioning for device 1
1046 static void AclProv1CB(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError)
1051 OIC_LOG(ERROR,TAG,"Context is Null in ACLProv1");
1055 Linkdata_t *link = (Linkdata_t*)ctx;
1056 OCProvisionResultCB resultCallback = link->resultCallback;
1060 OIC_LOG(ERROR,TAG,"Error occured while ACL provisioning device 1");
1061 UpdateLinkResults(link, 1, arr[0].res);
1062 ((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
1065 OICFree(link->resArr);
1069 UpdateLinkResults(link, 1, arr[0].res);
1070 if (NULL != link->pDev2Acl)
1072 OCStackResult res = SRPProvisionACL(ctx, link->pDev2, link->pDev2Acl, &AclProv2CB);
1073 if (OC_STACK_OK!=res)
1075 UpdateLinkResults(link, 2, res);
1076 ((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
1084 ((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
1087 OICFree(link->resArr);
1095 * Callback to handle credential provisioning.
1097 static void ProvisionCredsCB(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError)
1101 OIC_LOG(ERROR,TAG,"Error occured while credential provisioning");
1104 Linkdata_t *link = (Linkdata_t*)ctx;
1105 OCProvisionResultCB resultCallback = link->resultCallback;
1106 OIC_LOG_V(INFO, TAG, "has error returned %d",hasError);
1107 UpdateLinkResults(link, 1, arr[0].res);
1108 UpdateLinkResults(link, 2, arr[1].res);
1111 OIC_LOG(ERROR,TAG,"Error occured while credential provisioning");
1112 ((OCProvisionResultCB)(resultCallback))(link->ctx, nOfRes,
1115 OICFree(link->resArr);
1119 if (NULL != link->pDev1Acl)
1122 OCStackResult res = SRPProvisionACL(ctx, link->pDev1, link->pDev1Acl, &AclProv1CB);
1123 if (OC_STACK_OK!=res)
1125 OIC_LOG(ERROR, TAG, "Error while provisioning ACL for device 1");
1126 UpdateLinkResults(link, 1, res);
1127 ((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
1130 OICFree(link->resArr);
1134 else if (NULL!=link->pDev2Acl)
1136 OIC_LOG(ERROR, TAG, "ACL for device 1 is NULL");
1137 OCStackResult res = SRPProvisionACL(ctx, link->pDev2, link->pDev2Acl, &AclProv2CB);
1138 if (OC_STACK_OK!=res)
1140 OIC_LOG(ERROR, TAG, "Error while provisioning ACL for device 2");
1141 UpdateLinkResults(link, 2, res);
1142 ((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
1145 OICFree(link->resArr);
1151 OIC_LOG(INFO, TAG, "ACLs of both devices are NULL");
1152 ((OCProvisionResultCB)(resultCallback))(link->ctx, link->currentCountResults,
1155 OICFree(link->resArr);
1161 * function to provision credentials between two devices and ACLs for the devices who act as a server.
1163 * @param[in] ctx Application context would be returned in result callback.
1164 * @param[in] type Type of credentials to be provisioned to the device.
1165 * @param[in] pDev1 Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.
1166 * @param[in] acl ACL for device 1. If this is not required set NULL.
1167 * @param[in] pDev2 Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.
1168 * @param[in] acl ACL for device 2. If this is not required set NULL.
1169 * @param[in] resultCallback callback provided by API user, callback will be called when
1170 * provisioning request recieves a response from first resource server.
1171 * @return OC_STACK_OK in case of success and other value otherwise.
1173 OCStackResult OCProvisionPairwiseDevices(void* ctx, OicSecCredType_t type, size_t keySize,
1174 const OCProvisionDev_t *pDev1, OicSecAcl_t *pDev1Acl,
1175 const OCProvisionDev_t *pDev2, OicSecAcl_t *pDev2Acl,
1176 OCProvisionResultCB resultCallback)
1179 if (!pDev1 || !pDev2 || !pDev1->doxm || !pDev2->doxm)
1181 OIC_LOG(ERROR, TAG, "OCProvisionPairwiseDevices : Invalid parameters");
1182 return OC_STACK_INVALID_PARAM;
1184 if (!resultCallback)
1186 OIC_LOG(INFO, TAG, "OCProvisionPairwiseDevices : NULL Callback");
1187 return OC_STACK_INVALID_CALLBACK;
1189 if (!(keySize == OWNER_PSK_LENGTH_128 || keySize == OWNER_PSK_LENGTH_256))
1191 OIC_LOG(INFO, TAG, "OCProvisionPairwiseDevices : Invalid key size");
1192 return OC_STACK_INVALID_PARAM;
1194 if (0 == memcmp(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID, sizeof(OicUuid_t)))
1196 OIC_LOG(INFO, TAG, "OCProvisionPairwiseDevices : Same device ID");
1197 return OC_STACK_INVALID_PARAM;
1200 OIC_LOG(DEBUG, TAG, "Checking link in DB");
1201 bool linkExists = true;
1202 OCStackResult res = PDMIsLinkExists(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID, &linkExists);
1203 if(res != OC_STACK_OK)
1205 OIC_LOG(ERROR, TAG, "Internal Error Occured");
1210 OIC_LOG(ERROR, TAG, "Link already exists");
1211 return OC_STACK_INVALID_PARAM;
1214 int noOfResults = 2; // Initial Value
1215 if (NULL != pDev1Acl)
1219 if (NULL != pDev2Acl)
1223 Linkdata_t *link = (Linkdata_t*) OICMalloc(sizeof(Linkdata_t));
1226 OIC_LOG(ERROR, TAG, "Failed to memory allocation");
1227 return OC_STACK_NO_MEMORY;
1229 OIC_LOG_V(INFO,TAG, "Maximum no od results %d",noOfResults);
1231 link->pDev1 = pDev1;
1232 link->pDev1Acl = pDev1Acl;
1233 link->pDev2 = pDev2;
1234 link->pDev2Acl = pDev2Acl;
1236 // 1 call for each device for credential provisioning. implict call by SRPProvisioning credential
1237 // 1 call for ACL provisioning for device 1 and 1 call for ACL provisioning for device 2.
1238 link->numOfResults = noOfResults;
1239 link->resultCallback = resultCallback;
1240 link->currentCountResults = 0;
1241 link->resArr = (OCProvisionResult_t*) OICMalloc(sizeof(OCProvisionResult_t)*noOfResults);
1242 res = SRPProvisionCredentials(link, type, keySize,
1243 pDev1, pDev2, &ProvisionCredsCB);
1244 if (res != OC_STACK_OK)
1246 OICFree(link->resArr);
1253 OCStackResult OCGetDevInfoFromNetwork(unsigned short waittime,
1254 OCProvisionDev_t** pOwnedDevList,
1255 OCProvisionDev_t** pUnownedDevList)
1257 //TODO will be replaced by more efficient logic
1258 if (pOwnedDevList == NULL || *pOwnedDevList != NULL || pUnownedDevList == NULL
1259 || *pUnownedDevList != NULL || 0 == waittime)
1261 return OC_STACK_INVALID_PARAM;
1264 // Code for unowned discovery
1265 OCProvisionDev_t *unownedDevice = NULL;
1266 OCStackResult res = OCDiscoverUnownedDevices(waittime/2, &unownedDevice);
1267 if (OC_STACK_OK != res)
1269 OIC_LOG(ERROR,TAG, "Error in unowned discovery");
1273 // Code for owned discovery
1274 OCProvisionDev_t *ownedDevice = NULL;
1275 res = OCDiscoverOwnedDevices(waittime/2, &ownedDevice);
1276 if (OC_STACK_OK != res)
1278 OIC_LOG(ERROR,TAG, "Error in owned discovery");
1279 PMDeleteDeviceList(unownedDevice);
1283 // Code to get list of all the owned devices.
1284 OCUuidList_t *uuidList = NULL;
1285 size_t numOfDevices = 0;
1286 res = PDMGetOwnedDevices(&uuidList, &numOfDevices);
1287 if (OC_STACK_OK != res)
1289 OIC_LOG(ERROR, TAG, "Error while getting info from DB");
1290 PMDeleteDeviceList(unownedDevice);
1291 PMDeleteDeviceList(ownedDevice);
1295 // Code to compare devices in unowned list and deviceid from DB
1296 // (In case of hard reset of the device)
1297 OCProvisionDev_t* pUnownedList = unownedDevice;
1298 while (pUnownedList && uuidList)
1300 OCUuidList_t *tmp1 = NULL,*tmp2=NULL;
1301 LL_FOREACH_SAFE(uuidList, tmp1, tmp2)
1303 if(0 == memcmp(tmp1->dev.id, pUnownedList->doxm->deviceID.id,
1304 sizeof(pUnownedList->doxm->deviceID.id)))
1306 OIC_LOG_V(INFO, TAG, "OCGetDevInfoFromNetwork : \
1307 Removing device id = %s in PDM and dat.", pUnownedList->doxm->deviceID.id);
1308 if (OC_STACK_OK != PDMDeleteDevice(&pUnownedList->doxm->deviceID))
1310 OIC_LOG(ERROR, TAG, "OCGetDevInfoFromNetwork : \
1311 Failed to remove device in PDM.");
1313 //remove the cred entry from dat file
1314 if (OC_STACK_OK != RemoveDeviceInfoFromLocal(pUnownedList))
1316 OIC_LOG(ERROR, TAG, "OCGetDevInfoFromNetwork : \
1317 Failed to remove cred entry device in dat file.");
1319 LL_DELETE(uuidList, tmp1);
1323 pUnownedList = pUnownedList->next;
1325 // Code to compare devices in owned list and deviceid from DB.
1326 OCProvisionDev_t* pCurDev = ownedDevice;
1327 size_t deleteCnt = 0;
1330 if(true == PMDeleteFromUUIDList(&uuidList, &pCurDev->doxm->deviceID))
1334 pCurDev = pCurDev->next;
1336 // If there is no remaind device in uuidList, we have to assign NULL to prevent free.
1337 if (deleteCnt == numOfDevices)
1341 // Code to add information of the devices which are currently off in owned list.
1342 OCUuidList_t *powerOffDeviceList = uuidList;
1343 while (powerOffDeviceList)
1345 OCProvisionDev_t *ptr = (OCProvisionDev_t *)OICCalloc(1, sizeof (OCProvisionDev_t));
1348 OIC_LOG(ERROR,TAG,"Fail to allocate memory");
1349 PMDeleteDeviceList(unownedDevice);
1350 PMDeleteDeviceList(ownedDevice);
1351 OCDeleteUuidList(uuidList);
1352 return OC_STACK_NO_MEMORY;
1355 ptr->doxm = (OicSecDoxm_t*)OICCalloc(1, sizeof(OicSecDoxm_t));
1356 if (NULL == ptr->doxm)
1358 OIC_LOG(ERROR,TAG,"Fail to allocate memory");
1359 PMDeleteDeviceList(unownedDevice);
1360 PMDeleteDeviceList(ownedDevice);
1361 OCDeleteUuidList(uuidList);
1363 return OC_STACK_NO_MEMORY;
1366 memcpy(ptr->doxm->deviceID.id, powerOffDeviceList->dev.id, sizeof(ptr->doxm->deviceID.id));
1368 ptr->devStatus = DEV_STATUS_OFF;
1369 LL_PREPEND(ownedDevice, ptr);
1370 powerOffDeviceList = powerOffDeviceList->next;
1373 OCDeleteUuidList(uuidList);
1374 *pOwnedDevList = ownedDevice;
1375 *pUnownedDevList = unownedDevice;
1379 OCStackResult OCGetLinkedStatus(const OicUuid_t* uuidOfDevice, OCUuidList_t** uuidList,
1380 size_t* numOfDevices)
1382 return PDMGetLinkedDevices(uuidOfDevice, uuidList, numOfDevices);
1385 void OCDeleteUuidList(OCUuidList_t* pList)
1387 PDMDestoryOicUuidLinkList(pList);
1391 * This function deletes ACL data.
1393 * @param pAcl Pointer to OicSecAcl_t structure.
1395 void OCDeleteACLList(OicSecAcl_t* pAcl)
1397 DeleteACLList(pAcl);
1401 * This function deletes PDACL data.
1403 * @param pPdAcl Pointer to OicSecPdAcl_t structure.
1405 void OCDeletePdAclList(OicSecPdAcl_t* pPdAcl)
1407 FreePdAclList(pPdAcl);
1410 #ifdef MULTIPLE_OWNER
1412 * API to update 'doxm.mom' to resource server.
1414 * @param[in] targetDeviceInfo Selected target device.
1415 * @param[in] momType Mode of multiple ownership transfer (ref. oic.sec.mom)
1416 * @param[in] resultCallback callback provided by API user, callback will be called when
1417 * POST 'mom' request recieves a response from resource server.
1418 * @return OC_STACK_OK in case of success and other value otherwise.
1420 OCStackResult OCChangeMOTMode(void *ctx, const OCProvisionDev_t *targetDeviceInfo,
1421 const OicSecMomType_t momType, OCProvisionResultCB resultCallback)
1423 return MOTChangeMode(ctx, targetDeviceInfo, momType, resultCallback);
1427 * API to update 'doxm.oxmsel' to resource server.
1429 * @param[in] targetDeviceInfo Selected target device.
1430 * @param[in] oxmSelValue Method of multiple ownership transfer (ref. oic.sec.oxm)
1431 * @param[in] resultCallback callback provided by API user, callback will be called when
1432 * POST 'oxmsel' request recieves a response from resource server.
1433 * @return OC_STACK_OK in case of success and other value otherwise.
1435 OCStackResult OCSelectMOTMethod(void *ctx, const OCProvisionDev_t *targetDeviceInfo,
1436 const OicSecOxm_t oxmSelValue, OCProvisionResultCB resultCallback)
1438 return MOTSelectMOTMethod(ctx, targetDeviceInfo, oxmSelValue, resultCallback);
1440 #endif //MULTIPLE_OWNER
1443 * Function to select appropriate security provisioning method.
1445 * @param[in] supportedMethods Array of supported methods
1446 * @param[in] numberOfMethods number of supported methods
1447 * @param[out] selectedMethod Selected methods
1448 * @param[in] ownerType type of owner device (SUPER_OWNER or SUB_OWNER)
1449 * @return OC_STACK_OK on success
1451 OCStackResult OCSelectOwnershipTransferMethod(const OicSecOxm_t *supportedMethods,
1452 size_t numberOfMethods, OicSecOxm_t *selectedMethod, OwnerType_t ownerType)
1454 return OTMSelectOwnershipTransferMethod(supportedMethods, numberOfMethods,
1455 selectedMethod, ownerType);
1458 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
1460 * function to provision Trust certificate chain to devices.
1462 * @param[in] ctx Application context would be returned in result callback.
1463 * @param[in] type Type of credentials to be provisioned to the device.
1464 * @param[in] credId CredId of trust certificate chain to be provisioned to the device.
1465 * @param[in] selectedDeviceInfo Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.
1466 * @param[in] resultCallback callback provided by API user, callback will be called when
1467 * provisioning request recieves a response from first resource server.
1468 * @return OC_STACK_OK in case of success and other value otherwise.
1470 OCStackResult OCProvisionTrustCertChain(void *ctx, OicSecCredType_t type, uint16_t credId,
1471 const OCProvisionDev_t *selectedDeviceInfo,
1472 OCProvisionResultCB resultCallback)
1474 return SRPProvisionTrustCertChain(ctx, type, credId,
1475 selectedDeviceInfo, resultCallback);
1479 * function to save Trust certificate chain into Cred of SVR.
1481 * @param[in] trustCertChain Trust certificate chain to be saved in Cred of SVR.
1482 * @param[in] chainSize Size of trust certificate chain to be saved in Cred of SVR
1483 * @param[in] encodingType Encoding type of trust certificate chain to be saved in Cred of SVR
1484 * @param[out] credId CredId of saved trust certificate chain in Cred of SVR.
1485 * @return OC_STACK_OK in case of success and other value otherwise.
1487 OCStackResult OCSaveTrustCertChain(uint8_t *trustCertChain, size_t chainSize,
1488 OicEncodingType_t encodingType, uint16_t *credId)
1490 return SRPSaveTrustCertChain(trustCertChain, chainSize, encodingType, credId);
1494 * function to register notifier for Trustcertchain change.
1496 * @param[in] ctx user context.
1497 * @param[in] TrustCertChainChangeCB notification callback fucntion.
1498 * @return OC_STACK_OK in case of success and other value otherwise.
1500 OCStackResult OCRegisterTrustCertChainNotifier(void *ctx, TrustCertChainChangeCB Callback)
1502 return SRPRegisterTrustCertChainNotifier(ctx, Callback);
1506 * function to de-register notifier for Trustcertchain change.
1508 void OCRemoveTrustCertChainNotifier()
1510 SRPRemoveTrustCertChainNotifier();
1514 * This function sets the callback to utilize peer certificate information
1516 OCStackResult OCSetPeerCertCallback(void *ctx, PeerCertCallback peerCertCallback)
1520 OIC_LOG_V(DEBUG, TAG, "IN %s", __func__);
1521 ret = CAsetPeerCertCallback(ctx, peerCertCallback);
1522 if (CA_STATUS_OK != ret)
1524 OIC_LOG_V(ERROR, TAG, "CAsetPeerCertCallback() Failed(%d)", ret);
1525 return OC_STACK_ERROR;
1527 OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__);
1532 #endif // __WITH_DTLS__ || __WITH_TLS__