From: Hongkuk, Son Date: Thu, 11 Jan 2018 01:38:46 +0000 (+0900) Subject: Update snapshot(2018-01-10) X-Git-Tag: accepted/tizen/unified/20180111.074230^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F78%2F166578%2F1;p=platform%2Fupstream%2Fiotivity.git Update snapshot(2018-01-10) Signed-off-by: Hongkuk, Son Change-Id: I28f0ac1b4501582c84236f8ef8d8212790cd9e70 --- diff --git a/packaging/snapshot_history.txt b/packaging/snapshot_history.txt index 73dd60e..9ccb69a 100755 --- a/packaging/snapshot_history.txt +++ b/packaging/snapshot_history.txt @@ -1,3 +1,9 @@ +http://suprem.sec.samsung.net/jira/browse/CONPRO-1188 + +commit_info_2018-01-10.txt + +commit_id: 091fdd19b707d47409fa0c18553f4392ef6966ec +---------------------------------------------------------------------------------------------------------------------------------- http://suprem.sec.samsung.net/jira/browse/CONPRO-1180 commit_info_2018-01-04.txt diff --git a/resource/csdk/connectivity/inc/catcpadapter.h b/resource/csdk/connectivity/inc/catcpadapter.h index 9938183..caeb8d4 100644 --- a/resource/csdk/connectivity/inc/catcpadapter.h +++ b/resource/csdk/connectivity/inc/catcpadapter.h @@ -193,12 +193,14 @@ CAResult_t CAStopTCP(); */ void CATerminateTCP(); +#ifdef TCP_ADAPTER /** * Set connection status changes callback to process KeepAlive. * connection informations are delivered these callbacks. * @param[in] ConnHandler Connection status changes callback. */ void CATCPSetKeepAliveCallbacks(CAKeepAliveConnectionCallback ConnHandler); +#endif #ifdef __cplusplus } /* extern "C" */ diff --git a/resource/csdk/connectivity/inc/catcpinterface.h b/resource/csdk/connectivity/inc/catcpinterface.h index dda95e5..49b3f6a 100644 --- a/resource/csdk/connectivity/inc/catcpinterface.h +++ b/resource/csdk/connectivity/inc/catcpinterface.h @@ -110,6 +110,7 @@ void CAGetTCPHeaderDetails(unsigned char *recvBuffer, coap_transport_t *transpor size_t CAGetTotalLengthFromPacketHeader(const unsigned char *recvBuffer, size_t size); #else +#ifdef TCP_ADAPTER /** * set keepalive callback to notify connection information in TCP adapter. * @@ -117,6 +118,7 @@ size_t CAGetTotalLengthFromPacketHeader(const unsigned char *recvBuffer, size_t * in the TCP adapter. */ void CATCPSetKeepAliveCallback(CAKeepAliveConnectionCallback keepaliveHandler); +#endif /** * Start TCP server. diff --git a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.c b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.c index 4b16e70..1b5bfc0 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver.c @@ -564,6 +564,7 @@ CAResult_t CAInitLEGattServer() { OIC_LOG_V(ERROR, TAG, "bt_gatt_server_create failed with ret[%s]", CALEGetErrorMsg(ret)); + bt_gatt_server_deinitialize(); return CA_STATUS_FAILED; } } @@ -581,7 +582,8 @@ CAResult_t CADeInitLEGattServer() { OIC_LOG_V(ERROR, TAG, "bt_gatt_server_unregister_all_services failed with ret[%s]", CALEGetErrorMsg(ret)); - return CA_STATUS_FAILED; + // CONPRO-1181 continue even bt API fails during DeInit + //return CA_STATUS_FAILED; } ret = bt_gatt_server_destroy(g_gattServer); @@ -589,7 +591,8 @@ CAResult_t CADeInitLEGattServer() { OIC_LOG_V(ERROR, TAG, "bt_gatt_server_destroy failed with ret[%s]", CALEGetErrorMsg(ret)); - return CA_STATUS_FAILED; + // CONPRO-1181 continue even bt API fails during DeInit + //return CA_STATUS_FAILED; } g_gattServer = NULL; @@ -598,7 +601,8 @@ CAResult_t CADeInitLEGattServer() { OIC_LOG_V(ERROR, TAG, "bt_gatt_server_deinitialize failed with ret[%s]", CALEGetErrorMsg(ret)); - return CA_STATUS_FAILED; + // CONPRO-1181 continue even bt API fails during DeInit + //return CA_STATUS_FAILED; } OIC_LOG(DEBUG, TAG, "OUT"); diff --git a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_mcd.c b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_mcd.c index 6913289..9aa398b 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_mcd.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_mcd.c @@ -678,6 +678,7 @@ CAResult_t CAInitLEGattServer() { OIC_LOG_V(ERROR, TAG, "bt_gatt_server_create failed with ret[%s]", CALEGetErrorMsg(ret)); + bt_gatt_server_deinitialize(); return CA_STATUS_FAILED; } } @@ -695,7 +696,8 @@ CAResult_t CADeInitLEGattServer() { OIC_LOG_V(ERROR, TAG, "bt_gatt_server_unregister_all_services failed with ret[%s]", CALEGetErrorMsg(ret)); - return CA_STATUS_FAILED; + // CONPRO-1181 continue even bt API fails during DeInit + //return CA_STATUS_FAILED; } ret = bt_gatt_server_destroy(g_gattServer); @@ -703,7 +705,8 @@ CAResult_t CADeInitLEGattServer() { OIC_LOG_V(ERROR, TAG, "bt_gatt_server_destroy failed with ret[%s]", CALEGetErrorMsg(ret)); - return CA_STATUS_FAILED; + // CONPRO-1181 continue even bt API fails during DeInit + //return CA_STATUS_FAILED; } g_gattServer = NULL; @@ -712,7 +715,8 @@ CAResult_t CADeInitLEGattServer() { OIC_LOG_V(ERROR, TAG, "bt_gatt_server_deinitialize failed with ret[%s]", CALEGetErrorMsg(ret)); - return CA_STATUS_FAILED; + // CONPRO-1181 continue even bt API fails during DeInit + //return CA_STATUS_FAILED; } OIC_LOG(DEBUG, TAG, "OUT"); diff --git a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_vd.c b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_vd.c index 272f9c1..83acadc 100755 --- a/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_vd.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/tizen/caleserver_vd.c @@ -602,6 +602,7 @@ CAResult_t CAInitLEGattServer() { OIC_LOG_V(ERROR, TAG, "bt_gatt_server_create failed with ret[%s]", CALEGetErrorMsg(ret)); + bt_gatt_server_deinitialize(); return CA_STATUS_FAILED; } } @@ -619,7 +620,8 @@ CAResult_t CADeInitLEGattServer() { OIC_LOG_V(ERROR, TAG, "bt_gatt_server_unregister_all_services failed with ret[%s]", CALEGetErrorMsg(ret)); - return CA_STATUS_FAILED; + // CONPRO-1181 continue even bt API fails during DeInit + //return CA_STATUS_FAILED; } ret = bt_gatt_server_destroy(g_gattServer); @@ -627,7 +629,8 @@ CAResult_t CADeInitLEGattServer() { OIC_LOG_V(ERROR, TAG, "bt_gatt_server_destroy failed with ret[%s]", CALEGetErrorMsg(ret)); - return CA_STATUS_FAILED; + // CONPRO-1181 continue even bt API fails during DeInit + //return CA_STATUS_FAILED; } g_gattServer = NULL; @@ -636,7 +639,8 @@ CAResult_t CADeInitLEGattServer() { OIC_LOG_V(ERROR, TAG, "bt_gatt_server_deinitialize failed with ret[%s]", CALEGetErrorMsg(ret)); - return CA_STATUS_FAILED; + // CONPRO-1181 continue even bt API fails during DeInit + //return CA_STATUS_FAILED; } OIC_LOG(DEBUG, TAG, "OUT"); diff --git a/resource/csdk/connectivity/src/ip_adapter/caipadapter.c b/resource/csdk/connectivity/src/ip_adapter/caipadapter.c index 59d4449..313584c 100644 --- a/resource/csdk/connectivity/src/ip_adapter/caipadapter.c +++ b/resource/csdk/connectivity/src/ip_adapter/caipadapter.c @@ -164,7 +164,7 @@ void CAIPAdapterHandler(CATransportAdapter_t adapter, CANetworkStatus_t status) } #ifdef __WITH_DTLS__ -#ifdef WITH_TCP +#ifdef TCP_ADAPTER CATCPCloseInProgressConnections(); #endif OIC_LOG(DEBUG, TAG, "close all ssl session"); diff --git a/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c b/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c index 7136fe0..627028e 100644 --- a/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c +++ b/resource/csdk/connectivity/src/tcp_adapter/catcpserver.c @@ -288,6 +288,7 @@ static void CASelectReturned(fd_set *readFds) } else { + oc_mutex_lock(g_mutexObjectList); uint32_t length = u_arraylist_length(caglobals.tcp.svrlist); for (size_t i = 0; i < length; i++) { @@ -301,6 +302,7 @@ static void CASelectReturned(fd_set *readFds) } } } + oc_mutex_unlock(g_mutexObjectList); } } @@ -1370,7 +1372,6 @@ CASocketFd_t CAGetSocketFDFromEndpoint(const CAEndpoint_t *endpoint) CATCPSessionInfo_t *CAGetSessionInfoFromFD(int fd, size_t *index) { - oc_mutex_lock(g_mutexObjectList); // check from the last item. CATCPSessionInfo_t *svritem = NULL; @@ -1387,7 +1388,6 @@ CATCPSessionInfo_t *CAGetSessionInfoFromFD(int fd, size_t *index) } } - oc_mutex_unlock(g_mutexObjectList); return NULL; } diff --git a/resource/csdk/octbstack_product_secured.def b/resource/csdk/octbstack_product_secured.def index 1475b55..6e60c7f 100644 --- a/resource/csdk/octbstack_product_secured.def +++ b/resource/csdk/octbstack_product_secured.def @@ -49,6 +49,7 @@ SetUserConfirmCB UnsetUserConfirmCB SetVerifyOption VerifyOwnershipTransfer +SRPResetDevice SetHwPkixCallbacks SetupHwPkContext diff --git a/resource/csdk/security/provisioning/include/internal/secureresourceprovider.h b/resource/csdk/security/provisioning/include/internal/secureresourceprovider.h index a66f546..5dc50eb 100644 --- a/resource/csdk/security/provisioning/include/internal/secureresourceprovider.h +++ b/resource/csdk/security/provisioning/include/internal/secureresourceprovider.h @@ -250,7 +250,7 @@ OCStackResult SRPSyncDevice(void* ctx, unsigned short waitTimeForOwnedDeviceDisc * OC_STACK_CONTINUE means operation is success but no request is need to be initiated. */ OCStackResult SRPResetDevice(const OCProvisionDev_t* pTargetDev, - OCProvisionResultCB resultCallback); + OCClientContextDeleter deleteCallback); /* * Function to read Trust certificate chain from SVR. diff --git a/resource/csdk/security/provisioning/include/ocprovisioningmanager.h b/resource/csdk/security/provisioning/include/ocprovisioningmanager.h index b76512c..088d2a1 100644 --- a/resource/csdk/security/provisioning/include/ocprovisioningmanager.h +++ b/resource/csdk/security/provisioning/include/ocprovisioningmanager.h @@ -1,574 +1,578 @@ -/* ***************************************************************** - * - * Copyright 2015 Samsung Electronics All Rights Reserved. - * - * - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * *****************************************************************/ - -#ifndef OCPROVISIONINGMANAGER_H_ -#define OCPROVISIONINGMANAGER_H_ - -#include "octypes.h" -#include "pmtypes.h" -#include "casecurityinterface.h" -#include "ownershiptransfermanager.h" -#ifdef MULTIPLE_OWNER -#include "securevirtualresourcetypes.h" -#endif //MULTIPLE_OWNER - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -/** - * The function is responsible for initializaton of the provisioning manager. It will load - * provisioning database which have owned device's list and their linked status. - * TODO: In addition, if there is a device(s) which has not up-to-date credentials, this function will - * automatically try to update the deivce(s). - * - * @param[in] dbPath file path of the sqlite3 db - * - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCInitPM(const char* dbPath); - -/** - * API to termiante the provisioning manager - */ -void OCTerminatePM(); - -/** - * API to cleanup PDM in case of timeout. - * It will remove the PDM_DEVICE_INIT state devices from PDM. - * - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCPDMCleanupForTimeout(); - -/** - * The function is responsible for discovery of owned/unowned device is specified endpoint/deviceID. - * It will return the found device even though timeout is not exceeded. - * - * @param[in] timeout Timeout in seconds, value till which function will listen to responses from - * server before returning the device. - * @param[in] deviceID deviceID of target device. - * @param[out] ppFoundDevice OCProvisionDev_t of found device - * @return OTM_SUCCESS in case of success and other value otherwise. - */ -OCStackResult OCDiscoverSingleDevice(unsigned short timeout, const OicUuid_t* deviceID, - OCProvisionDev_t **ppFoundDevice); - -/** - * The function is responsible for discovery of owned/unowned device is specified endpoint/MAC - * address. - * It will return the found device even though timeout is not exceeded. - * - * @param[in] timeout Timeout in seconds, value till which function will listen to responses from - * server before returning the device. - * @param[in] deviceID deviceID of target device. - * @param[in] hostAddress MAC address of target device. - * @param[in] connType ConnectivityType for discovery. - * @param[out] ppFoundDevice OCProvisionDev_t of found device. - * @return OTM_SUCCESS in case of success and other value otherwise. - */ -OCStackResult OCDiscoverSingleDeviceInUnicast(unsigned short timeout, const OicUuid_t* deviceID, - const char* hostAddress, OCConnectivityType connType, - OCProvisionDev_t **ppFoundDevice); - -/** - * The function is responsible for discovery of device is current subnet. It will list - * all the device in subnet which are not yet owned. Please call OCInit with OC_CLIENT_SERVER as - * OCMode. - * - * @param[in] timeout Timeout in seconds, value till which function will listen to responses from - * server before returning the list of devices. - * @param[out] ppList List of candidate devices to be provisioned - * @return OTM_SUCCESS in case of success and other value otherwise. - */ -OCStackResult OCDiscoverUnownedDevices(unsigned short waittime, OCProvisionDev_t **ppList); - -/** - * Do ownership transfer for un-owned device. - * - * @param[in] ctx Application context would be returned in result callback - * @param[in] targetDevices List of devices to perform ownership transfer. - * @param[in] resultCallback Result callback function to be invoked when ownership transfer finished. - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCDoOwnershipTransfer(void* ctx, - OCProvisionDev_t *targetDevices, - OCProvisionResultCB resultCallback); - -/** - * API to set a allow status of OxM - * - * @param[in] oxm Owership transfer method (ref. OicSecOxm_t) - * @param[in] allowStatus allow status (true = allow, false = not allow) - * - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCSetOxmAllowStatus(const OicSecOxm_t oxm, const bool allowStatus); - - -#ifdef MULTIPLE_OWNER -/** - * API to perfrom multiple ownership transfer for MOT enabled device. - * - * @param[in] ctx Application context would be returned in result callback - * @param[in] targetDevices List of devices to perform ownership transfer. - * @param[in] resultCallback Result callback function to be invoked when ownership transfer finished. - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCDoMultipleOwnershipTransfer(void* ctx, - OCProvisionDev_t *targetDevices, - OCProvisionResultCB resultCallback); - -/** - * API to remove sub-owner from resource server - * - * @param[in] ctx Application context would be returned in result callback - * @param[in] targetDeviceInfo Selected target device. - * @param[in] subOwner sub-owner UUID to be removed - * @param[in] resultCallback callback provided by API user, callback will be invoked when - * DELETE 'subowneruuid' request recieves a response from resource server. - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCRemoveSubOwner(void* ctx, - const OCProvisionDev_t *targetDeviceInfo, - const OicUuid_t* subOwner, - OCProvisionResultCB resultCallback); - -/** - * API to remove all sub-owner from resource server - * - * @param[in] ctx Application context would be returned in result callback - * @param[in] targetDeviceInfo Selected target device. - * @param[in] resultCallback callback provided by API user, callback will be invoked when - * DELETE 'subowneruuid' request recieves a response from resource server. - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCRemoveAllSubOwner(void* ctx, - const OCProvisionDev_t *targetDeviceInfo, - OCProvisionResultCB resultCallback); - -#endif //MULTIPLE_OWNER - -/** - * API to register for particular OxM. - * - * @param[in] Ownership transfer method. - * @param[in] Implementation of callback functions for owership transfer. - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCSetOwnerTransferCallbackData(OicSecOxm_t oxm, OTMCallbackData_t* callbackData); - -/** - * The function is responsible for discovery of owned device is current subnet. It will list - * all the device in subnet which are owned by calling provisioning client. - * - * @param[in] timeout Timeout in seconds, value till which function will listen to responses from - * server before returning the list of devices. - * @param[out] ppList List of device owned by provisioning tool. - * @return OTM_SUCCESS in case of success and other value otherwise. - */ -OCStackResult OCDiscoverOwnedDevices(unsigned short timeout, OCProvisionDev_t **ppList); - -#ifdef MULTIPLE_OWNER -/** - * The function is responsible for discovery of MOT enabled device is current subnet. - * - * @param[in] timeout Timeout in seconds, value till which function will listen to responses from - * server before returning the list of devices. - * @param[out] ppList List of MOT enabled devices. - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCDiscoverMultipleOwnerEnabledDevices(unsigned short timeout, OCProvisionDev_t **ppList); - -/** - * The function is responsible for discovery of Multiple Owned device is current subnet. - * - * @param[in] timeout Timeout in seconds, value till which function will listen to responses from - * server before returning the list of devices. - * @param[out] ppList List of Multiple Owned devices. - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCDiscoverMultipleOwnedDevices(unsigned short timeout, OCProvisionDev_t **ppList); -#endif //MULTIPLE_OWNER - -/** - * API to provision credentials between two devices and ACLs for the devices who act as a server. - * - * @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] pDev1 Pointer to OCProvisionDev_t instance,respresenting device to be provisioned. - * @param[in] acl ACL for device 1. If this is not required set NULL. - * @param[in] pDev2 Pointer to OCProvisionDev_t instance,respresenting device to be provisioned. - * @param[in] acl ACL for device 2. If this is not required set NULL. - * @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 OCProvisionPairwiseDevices(void* ctx, OicSecCredType_t type, size_t keySize, - const OCProvisionDev_t *pDev1, OicSecAcl_t *pDev1Acl, - const OCProvisionDev_t *pDev2, OicSecAcl_t *pDev2Acl, - OCProvisionResultCB resultCallback); - -/** - * API to send ACL information to device. - * - * @param[in] ctx Application context would be returned in result callback. - * @param[in] selectedDeviceInfo Selected target device. - * @param[in] acl ACL to provision. - * @param[in] resultCallback callback provided by API user, callback will be called when provisioning - request recieves a response from resource server. - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCProvisionACL(void *ctx, const OCProvisionDev_t *selectedDeviceInfo, OicSecAcl_t *acl, - OCProvisionResultCB resultCallback); - -/** - * function to save ACL which has several ACE into Acl of SVR. - * - * @param acl ACL to be saved in Acl of SVR. - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCSaveACL(const OicSecAcl_t* acl); - -/** - * this function requests CRED information to resource. - * - * @param[in] ctx Application context would be returned in result callback. - * @param[in] selectedDeviceInfo Selected target device. - * @param[in] resultCallback callback provided by API user, callback will be called when provisioning - request recieves a response from resource server. - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCGetCredResource(void* ctx, const OCProvisionDev_t *selectedDeviceInfo, - OCProvisionResultCB resultCallback); - -/** - * this function requests ACL information to resource. - * - * @param[in] ctx Application context would be returned in result callback. - * @param[in] selectedDeviceInfo Selected target device. - * @param[in] resultCallback callback provided by API user, callback will be called when provisioning - request recieves a response from resource server. - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCGetACLResource(void* ctx, const OCProvisionDev_t *selectedDeviceInfo, - OCProvisionResultCB resultCallback); - -/** - * this function sends Direct-Pairing Configuration to a device. - * - * @param[in] ctx Application context would be returned in result callback. - * @param[in] selectedDeviceInfo Selected target device. - * @param[in] pconf PCONF pointer. - * @param[in] resultCallback callback provided by API user, callback will be called when provisioning - request recieves a response from resource server. - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCProvisionDirectPairing(void* ctx, const OCProvisionDev_t *selectedDeviceInfo, OicSecPconf_t *pconf, - OCProvisionResultCB resultCallback); - -/** - * API to provision credential 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] pDev1 Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned. - @param[in] pDev2 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 OCProvisionCredentials(void *ctx, OicSecCredType_t type, size_t keySize, - const OCProvisionDev_t *pDev1, - const OCProvisionDev_t *pDev2, - OCProvisionResultCB resultCallback); - -#ifdef MULTIPLE_OWNER -/** - * API to provision preconfigured PIN to device(NOT LIST). - * If device does not support the Preconfigured PIN OxM, - * OCProvisionPreconfigPin API will update the device's Doxm - * and then try preconfigured PIN provisioning once again. - * - * @param[in] ctx Application context would be returned in result callback. - * @param[in] targetDeviceInfo Selected target device. - * @param[in] preconfigPin string of preconfigured PIN. - * @param[in] preconfigPinLen string length of 'preconfigPin'. - * @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 OCProvisionPreconfigPin(void *ctx, - OCProvisionDev_t *targetDeviceInfo, - const char *preconfigPin, - size_t preconfigPinLen, - OCProvisionResultCB resultCallback); - -/** - * API to add preconfigured PIN to local SVR DB. - * - * @param[in] targetDeviceInfo Selected target device. - * @param[in] preconfigPin Preconfig PIN which is used while multiple owner authentication - * @param[in] preconfigPinLen Byte length of preconfigPin - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCAddPreconfigPin(const OCProvisionDev_t *targetDeviceInfo, - const char *preconfigPin, - size_t preconfigPinLen); - -/** - * 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); - -/** - * 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); -#endif //MULTIPLE_OWNER - -/** - * Function to unlink devices. - * This function will remove the credential & relasionship between the two devices. - * - * @param[in] ctx Application context would be returned in result callback - * @param[in] pTargetDev1 fitst device information to be unlinked. - * @param[in] pTargetDev2 second device information to be unlinked. - * @param[in] resultCallback callback provided by API user, callback will be called when - * device unlink is finished. - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCUnlinkDevices(void* ctx, - const OCProvisionDev_t* pTargetDev1, - const OCProvisionDev_t* pTargetDev2, - OCProvisionResultCB resultCallback); - -/** - * Function for device revocation - * This function will remove credential of target device from all devices in subnet. - * - * @param[in] ctx Application context would be returned in result callback - * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds) - * @param[in] pTargetDev Device information to be revoked. - * @param[in] resultCallback callback provided by API user, callback will be called when - * credential revocation is finished. - * @return OC_STACK_OK in case of success and other value otherwise. - * if OC_STACK_OK is returned, the caller of this API should wait for callback. - * OC_STACK_CONTINUE means operation is success but no need to wait for callback. - */ -OCStackResult OCRemoveDevice(void* ctx, - unsigned short waitTimeForOwnedDeviceDiscovery, - const OCProvisionDev_t* pTargetDev, - OCProvisionResultCB resultCallback); - -/* -* Function to device revocation -* This function will remove credential of target device from all devices in subnet. -* -* @param[in] ctx Application context would be returned in result callback -* @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds) -* @param[in] pTargetDev Device information to be revoked. -* @param[in] resultCallback callback provided by API user, callback will be called when -* credential revocation is finished. - * @return OC_STACK_OK in case of success and other value otherwise. -*/ -OCStackResult OCRemoveDeviceWithUuid(void* ctx, - unsigned short waitTimeForOwnedDeviceDiscovery, - const OicUuid_t* pTargetUuid, - OCProvisionResultCB resultCallback); - -/* - * Function to reset the target device. - * This function will remove credential and ACL of target device from all devices in subnet. - * - * @param[in] ctx Application context would be returned in result callback - * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds) - * @param[in] pTargetDev Device information to be revoked. - * @param[in] resultCallback callback provided by API user, callback will be called when - * credential revocation is finished. - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCResetDevice(void* ctx, unsigned short waitTimeForOwnedDeviceDiscovery, - const OCProvisionDev_t* pTargetDev, - OCProvisionResultCB resultCallback); - -/** - * This function resets SVR DB to its factory setting. - * - *@return OC_STACK_OK in case of successful reset and other value otherwise. - */ -OCStackResult OCResetSVRDB(void); - -/** - * This function configures SVR DB as self-ownership. - * - *@return OC_STACK_OK in case of successful configue and other value otherwise. - */ -OCStackResult OCConfigSelfOwnership(void); - -/** - * API to get status of all the devices in current subnet. The status include endpoint information - * and doxm information which can be extracted duing owned and unowned discovery. Along with this - * information. The API will provide information about devices' status - * Device can have following states - * - ON/OFF: Device is switched on or off. - * - * NOTE: Caller need to call OCDeleteDiscoveredDevices to delete memory allocated by this API for out - * variables pOwnedDevList and pUnownedDevList. - * - * @param[in] waitime Wait time for the API. The wait time will be divided by 2, and half of wait time - * will be used for unowned discovery and remaining half for owned discovery. So the wait time should be - * equal to or more than 2. - * @param[out] pOwnedDevList list of owned devices. - * @param[out] pUnownedDevList list of unowned devices. - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCGetDevInfoFromNetwork(unsigned short waittime, - OCProvisionDev_t** pOwnedDevList, - OCProvisionDev_t** pUnownedDevList); -/** - * This method is used to get linked devices' IDs. - * - * @param[in] uuidOfDevice a target device's uuid. - * @param[out] uuidList information about the list of linked devices' uuids. - * @param[out] numOfDevices total number of linked devices. - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCGetLinkedStatus(const OicUuid_t* uuidOfDevice, - OCUuidList_t** uuidList, - size_t* numOfDevices); - -/** - * API to delete memory allocated to linked list created by OCDiscover_XXX_Devices API. - * - * @param[in] pList Pointer to OCProvisionDev_t which should be deleted. - */ -void OCDeleteDiscoveredDevices(OCProvisionDev_t *pList); - -/** - * API to delete memory allocated to OicUuid_t list. - * - * @param[in] pList Pointer to OicUuid_t list which should be deleted. - */ -void OCDeleteUuidList(OCUuidList_t* pList); - -/** - * This function deletes ACL data. - * - * @param pAcl Pointer to OicSecAcl_t structure. - */ -void OCDeleteACLList(OicSecAcl_t* pAcl); - -/** - * This function deletes PDACL data. - * - * @param pPdAcl Pointer to OicSecPdAcl_t structure. - */ -void OCDeletePdAclList(OicSecPdAcl_t* pPdAcl); - -#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); -/** - * 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); -/** - * function to register callback, for getting notification for TrustCertChain change. - * - * @param[in] TrustCertChainChangeCB notifier callback function - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCRegisterTrustCertChainNotifier(void *cb, TrustCertChainChangeCB CB); - -/** - * function to de-register TrustCertChain notification callback. - */ -void OCRemoveTrustCertChainNotifier(void); - -/* - * Function to read Trust certificate chain from SVR. - * Caller must free when done using the returned trust certificate - * @param[in] credId CredId of trust certificate chain in SVR. - * @param[out] trustCertChain Trust certificate chain. - * @param[out] chainSize Size of trust certificate chain - * @return OC_STACK_OK in case of success and other value otherwise. - */ -OCStackResult OCReadTrustCertChain(uint16_t credId, uint8_t **trustCertChain, - size_t *chainSize); - -/** - * 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); - -/** - * This function sets the callback to utilize peer certificate information - */ -OCStackResult OCSetPeerCertCallback(void *ctx, PeerCertCallback peerCertCallback); - -#endif // __WITH_DTLS__ || __WITH_TLS__ - - -#ifdef __cplusplus -} -#endif // __cplusplus - -#endif /* OCPROVISIONINGMANAGER_H_ */ +/* ***************************************************************** + * + * Copyright 2015 Samsung Electronics All Rights Reserved. + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * *****************************************************************/ + +#ifndef OCPROVISIONINGMANAGER_H_ +#define OCPROVISIONINGMANAGER_H_ + +#include "octypes.h" +#include "pmtypes.h" +#include "casecurityinterface.h" +#include "ownershiptransfermanager.h" +#ifdef MULTIPLE_OWNER +#include "securevirtualresourcetypes.h" +#endif //MULTIPLE_OWNER + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +/** + * The function is responsible for initializaton of the provisioning manager. It will load + * provisioning database which have owned device's list and their linked status. + * TODO: In addition, if there is a device(s) which has not up-to-date credentials, this function will + * automatically try to update the deivce(s). + * + * @param[in] dbPath file path of the sqlite3 db + * + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCInitPM(const char *dbPath); + +/** + * API to termiante the provisioning manager + */ +void OCTerminatePM(); + +/** + * API to cleanup PDM in case of timeout. + * It will remove the PDM_DEVICE_INIT state devices from PDM. + * + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCPDMCleanupForTimeout(); + +/** + * The function is responsible for discovery of owned/unowned device is specified endpoint/deviceID. + * It will return the found device even though timeout is not exceeded. + * + * @param[in] timeout Timeout in seconds, value till which function will listen to responses from + * server before returning the device. + * @param[in] deviceID deviceID of target device. + * @param[out] ppFoundDevice OCProvisionDev_t of found device + * @return OTM_SUCCESS in case of success and other value otherwise. + */ +OCStackResult OCDiscoverSingleDevice(unsigned short timeout, const OicUuid_t *deviceID, + OCProvisionDev_t **ppFoundDevice); + +/** + * The function is responsible for discovery of owned/unowned device is specified endpoint/MAC + * address. + * It will return the found device even though timeout is not exceeded. + * + * @param[in] timeout Timeout in seconds, value till which function will listen to responses from + * server before returning the device. + * @param[in] deviceID deviceID of target device. + * @param[in] hostAddress MAC address of target device. + * @param[in] connType ConnectivityType for discovery. + * @param[out] ppFoundDevice OCProvisionDev_t of found device. + * @return OTM_SUCCESS in case of success and other value otherwise. + */ +OCStackResult OCDiscoverSingleDeviceInUnicast(unsigned short timeout, const OicUuid_t *deviceID, + const char *hostAddress, OCConnectivityType connType, + OCProvisionDev_t **ppFoundDevice); + +/** + * The function is responsible for discovery of device is current subnet. It will list + * all the device in subnet which are not yet owned. Please call OCInit with OC_CLIENT_SERVER as + * OCMode. + * + * @param[in] timeout Timeout in seconds, value till which function will listen to responses from + * server before returning the list of devices. + * @param[out] ppList List of candidate devices to be provisioned + * @return OTM_SUCCESS in case of success and other value otherwise. + */ +OCStackResult OCDiscoverUnownedDevices(unsigned short waittime, OCProvisionDev_t **ppList); + +/** + * Do ownership transfer for un-owned device. + * + * @param[in] ctx Application context would be returned in result callback + * @param[in] targetDevices List of devices to perform ownership transfer. + * @param[in] resultCallback Result callback function to be invoked when ownership transfer finished. + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCDoOwnershipTransfer(void *ctx, + OCProvisionDev_t *targetDevices, + OCProvisionResultCB resultCallback); + +/** + * API to set a allow status of OxM + * + * @param[in] oxm Owership transfer method (ref. OicSecOxm_t) + * @param[in] allowStatus allow status (true = allow, false = not allow) + * + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCSetOxmAllowStatus(const OicSecOxm_t oxm, const bool allowStatus); + + +#ifdef MULTIPLE_OWNER +/** + * API to perfrom multiple ownership transfer for MOT enabled device. + * + * @param[in] ctx Application context would be returned in result callback + * @param[in] targetDevices List of devices to perform ownership transfer. + * @param[in] resultCallback Result callback function to be invoked when ownership transfer finished. + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCDoMultipleOwnershipTransfer(void *ctx, + OCProvisionDev_t *targetDevices, + OCProvisionResultCB resultCallback); + +/** + * API to remove sub-owner from resource server + * + * @param[in] ctx Application context would be returned in result callback + * @param[in] targetDeviceInfo Selected target device. + * @param[in] subOwner sub-owner UUID to be removed + * @param[in] resultCallback callback provided by API user, callback will be invoked when + * DELETE 'subowneruuid' request recieves a response from resource server. + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCRemoveSubOwner(void *ctx, + const OCProvisionDev_t *targetDeviceInfo, + const OicUuid_t *subOwner, + OCProvisionResultCB resultCallback); + +/** + * API to remove all sub-owner from resource server + * + * @param[in] ctx Application context would be returned in result callback + * @param[in] targetDeviceInfo Selected target device. + * @param[in] resultCallback callback provided by API user, callback will be invoked when + * DELETE 'subowneruuid' request recieves a response from resource server. + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCRemoveAllSubOwner(void *ctx, + const OCProvisionDev_t *targetDeviceInfo, + OCProvisionResultCB resultCallback); + +#endif //MULTIPLE_OWNER + +/** + * API to register for particular OxM. + * + * @param[in] Ownership transfer method. + * @param[in] Implementation of callback functions for owership transfer. + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCSetOwnerTransferCallbackData(OicSecOxm_t oxm, OTMCallbackData_t *callbackData); + +/** + * The function is responsible for discovery of owned device is current subnet. It will list + * all the device in subnet which are owned by calling provisioning client. + * + * @param[in] timeout Timeout in seconds, value till which function will listen to responses from + * server before returning the list of devices. + * @param[out] ppList List of device owned by provisioning tool. + * @return OTM_SUCCESS in case of success and other value otherwise. + */ +OCStackResult OCDiscoverOwnedDevices(unsigned short timeout, OCProvisionDev_t **ppList); + +#ifdef MULTIPLE_OWNER +/** + * The function is responsible for discovery of MOT enabled device is current subnet. + * + * @param[in] timeout Timeout in seconds, value till which function will listen to responses from + * server before returning the list of devices. + * @param[out] ppList List of MOT enabled devices. + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCDiscoverMultipleOwnerEnabledDevices(unsigned short timeout, + OCProvisionDev_t **ppList); + +/** + * The function is responsible for discovery of Multiple Owned device is current subnet. + * + * @param[in] timeout Timeout in seconds, value till which function will listen to responses from + * server before returning the list of devices. + * @param[out] ppList List of Multiple Owned devices. + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCDiscoverMultipleOwnedDevices(unsigned short timeout, OCProvisionDev_t **ppList); +#endif //MULTIPLE_OWNER + +/** + * API to provision credentials between two devices and ACLs for the devices who act as a server. + * + * @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] pDev1 Pointer to OCProvisionDev_t instance,respresenting device to be provisioned. + * @param[in] acl ACL for device 1. If this is not required set NULL. + * @param[in] pDev2 Pointer to OCProvisionDev_t instance,respresenting device to be provisioned. + * @param[in] acl ACL for device 2. If this is not required set NULL. + * @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 OCProvisionPairwiseDevices(void *ctx, OicSecCredType_t type, size_t keySize, + const OCProvisionDev_t *pDev1, OicSecAcl_t *pDev1Acl, + const OCProvisionDev_t *pDev2, OicSecAcl_t *pDev2Acl, + OCProvisionResultCB resultCallback); + +/** + * API to send ACL information to device. + * + * @param[in] ctx Application context would be returned in result callback. + * @param[in] selectedDeviceInfo Selected target device. + * @param[in] acl ACL to provision. + * @param[in] resultCallback callback provided by API user, callback will be called when provisioning + request recieves a response from resource server. + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCProvisionACL(void *ctx, const OCProvisionDev_t *selectedDeviceInfo, + OicSecAcl_t *acl, + OCProvisionResultCB resultCallback); + +/** + * function to save ACL which has several ACE into Acl of SVR. + * + * @param acl ACL to be saved in Acl of SVR. + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCSaveACL(const OicSecAcl_t *acl); + +/** + * this function requests CRED information to resource. + * + * @param[in] ctx Application context would be returned in result callback. + * @param[in] selectedDeviceInfo Selected target device. + * @param[in] resultCallback callback provided by API user, callback will be called when provisioning + request recieves a response from resource server. + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCGetCredResource(void *ctx, const OCProvisionDev_t *selectedDeviceInfo, + OCProvisionResultCB resultCallback); + +/** + * this function requests ACL information to resource. + * + * @param[in] ctx Application context would be returned in result callback. + * @param[in] selectedDeviceInfo Selected target device. + * @param[in] resultCallback callback provided by API user, callback will be called when provisioning + request recieves a response from resource server. + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCGetACLResource(void *ctx, const OCProvisionDev_t *selectedDeviceInfo, + OCProvisionResultCB resultCallback); + +/** + * this function sends Direct-Pairing Configuration to a device. + * + * @param[in] ctx Application context would be returned in result callback. + * @param[in] selectedDeviceInfo Selected target device. + * @param[in] pconf PCONF pointer. + * @param[in] resultCallback callback provided by API user, callback will be called when provisioning + request recieves a response from resource server. + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCProvisionDirectPairing(void *ctx, const OCProvisionDev_t *selectedDeviceInfo, + OicSecPconf_t *pconf, + OCProvisionResultCB resultCallback); + +/** + * API to provision credential 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] pDev1 Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned. + @param[in] pDev2 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 OCProvisionCredentials(void *ctx, OicSecCredType_t type, size_t keySize, + const OCProvisionDev_t *pDev1, + const OCProvisionDev_t *pDev2, + OCProvisionResultCB resultCallback); + +#ifdef MULTIPLE_OWNER +/** + * API to provision preconfigured PIN to device(NOT LIST). + * If device does not support the Preconfigured PIN OxM, + * OCProvisionPreconfigPin API will update the device's Doxm + * and then try preconfigured PIN provisioning once again. + * + * @param[in] ctx Application context would be returned in result callback. + * @param[in] targetDeviceInfo Selected target device. + * @param[in] preconfigPin string of preconfigured PIN. + * @param[in] preconfigPinLen string length of 'preconfigPin'. + * @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 OCProvisionPreconfigPin(void *ctx, + OCProvisionDev_t *targetDeviceInfo, + const char *preconfigPin, + size_t preconfigPinLen, + OCProvisionResultCB resultCallback); + +/** + * API to add preconfigured PIN to local SVR DB. + * + * @param[in] targetDeviceInfo Selected target device. + * @param[in] preconfigPin Preconfig PIN which is used while multiple owner authentication + * @param[in] preconfigPinLen Byte length of preconfigPin + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCAddPreconfigPin(const OCProvisionDev_t *targetDeviceInfo, + const char *preconfigPin, + size_t preconfigPinLen); + +/** + * 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); + +/** + * 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); +#endif //MULTIPLE_OWNER + +/** + * Function to unlink devices. + * This function will remove the credential & relasionship between the two devices. + * + * @param[in] ctx Application context would be returned in result callback + * @param[in] pTargetDev1 fitst device information to be unlinked. + * @param[in] pTargetDev2 second device information to be unlinked. + * @param[in] resultCallback callback provided by API user, callback will be called when + * device unlink is finished. + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCUnlinkDevices(void *ctx, + const OCProvisionDev_t *pTargetDev1, + const OCProvisionDev_t *pTargetDev2, + OCProvisionResultCB resultCallback); + +/** + * Function for device revocation + * This function will remove credential of target device from all devices in subnet. + * + * @param[in] ctx Application context would be returned in result callback + * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds) + * @param[in] pTargetDev Device information to be revoked. + * @param[in] resultCallback callback provided by API user, callback will be called when + * credential revocation is finished. + * @return OC_STACK_OK in case of success and other value otherwise. + * if OC_STACK_OK is returned, the caller of this API should wait for callback. + * OC_STACK_CONTINUE means operation is success but no need to wait for callback. + */ +OCStackResult OCRemoveDevice(void *ctx, + unsigned short waitTimeForOwnedDeviceDiscovery, + const OCProvisionDev_t *pTargetDev, + OCProvisionResultCB resultCallback); + +/* +* Function to device revocation +* This function will remove credential of target device from all devices in subnet. +* +* @param[in] ctx Application context would be returned in result callback +* @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds) +* @param[in] pTargetDev Device information to be revoked. +* @param[in] resultCallback callback provided by API user, callback will be called when +* credential revocation is finished. + * @return OC_STACK_OK in case of success and other value otherwise. +*/ +OCStackResult OCRemoveDeviceWithUuid(void *ctx, + unsigned short waitTimeForOwnedDeviceDiscovery, + const OicUuid_t *pTargetUuid, + OCProvisionResultCB resultCallback); + +/* + * Function to reset the target device. + * This function will remove credential and ACL of target device from all devices in subnet. + * + * @param[in] ctx Application context would be returned in result callback + * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds) + * @param[in] pTargetDev Device information to be revoked. + * @param[in] resultCallback callback provided by API user, callback will be called when + * credential revocation is finished. + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCResetDevice(void *ctx, unsigned short waitTimeForOwnedDeviceDiscovery, + const OCProvisionDev_t *pTargetDev, + OCProvisionResultCB resultCallback, + OCClientContextDeleter deleteCallback); + +/** + * This function resets SVR DB to its factory setting. + * + *@return OC_STACK_OK in case of successful reset and other value otherwise. + */ +OCStackResult OCResetSVRDB(void); + +/** + * This function configures SVR DB as self-ownership. + * + *@return OC_STACK_OK in case of successful configue and other value otherwise. + */ +OCStackResult OCConfigSelfOwnership(void); + +/** + * API to get status of all the devices in current subnet. The status include endpoint information + * and doxm information which can be extracted duing owned and unowned discovery. Along with this + * information. The API will provide information about devices' status + * Device can have following states + * - ON/OFF: Device is switched on or off. + * + * NOTE: Caller need to call OCDeleteDiscoveredDevices to delete memory allocated by this API for out + * variables pOwnedDevList and pUnownedDevList. + * + * @param[in] waitime Wait time for the API. The wait time will be divided by 2, and half of wait time + * will be used for unowned discovery and remaining half for owned discovery. So the wait time should be + * equal to or more than 2. + * @param[out] pOwnedDevList list of owned devices. + * @param[out] pUnownedDevList list of unowned devices. + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCGetDevInfoFromNetwork(unsigned short waittime, + OCProvisionDev_t **pOwnedDevList, + OCProvisionDev_t **pUnownedDevList); +/** + * This method is used to get linked devices' IDs. + * + * @param[in] uuidOfDevice a target device's uuid. + * @param[out] uuidList information about the list of linked devices' uuids. + * @param[out] numOfDevices total number of linked devices. + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCGetLinkedStatus(const OicUuid_t *uuidOfDevice, + OCUuidList_t **uuidList, + size_t *numOfDevices); + +/** + * API to delete memory allocated to linked list created by OCDiscover_XXX_Devices API. + * + * @param[in] pList Pointer to OCProvisionDev_t which should be deleted. + */ +void OCDeleteDiscoveredDevices(OCProvisionDev_t *pList); + +/** + * API to delete memory allocated to OicUuid_t list. + * + * @param[in] pList Pointer to OicUuid_t list which should be deleted. + */ +void OCDeleteUuidList(OCUuidList_t *pList); + +/** + * This function deletes ACL data. + * + * @param pAcl Pointer to OicSecAcl_t structure. + */ +void OCDeleteACLList(OicSecAcl_t *pAcl); + +/** + * This function deletes PDACL data. + * + * @param pPdAcl Pointer to OicSecPdAcl_t structure. + */ +void OCDeletePdAclList(OicSecPdAcl_t *pPdAcl); + +#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); +/** + * 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); +/** + * function to register callback, for getting notification for TrustCertChain change. + * + * @param[in] TrustCertChainChangeCB notifier callback function + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCRegisterTrustCertChainNotifier(void *cb, TrustCertChainChangeCB CB); + +/** + * function to de-register TrustCertChain notification callback. + */ +void OCRemoveTrustCertChainNotifier(void); + +/* + * Function to read Trust certificate chain from SVR. + * Caller must free when done using the returned trust certificate + * @param[in] credId CredId of trust certificate chain in SVR. + * @param[out] trustCertChain Trust certificate chain. + * @param[out] chainSize Size of trust certificate chain + * @return OC_STACK_OK in case of success and other value otherwise. + */ +OCStackResult OCReadTrustCertChain(uint16_t credId, uint8_t **trustCertChain, + size_t *chainSize); + +/** + * 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); + +/** + * This function sets the callback to utilize peer certificate information + */ +OCStackResult OCSetPeerCertCallback(void *ctx, PeerCertCallback peerCertCallback); + +#endif // __WITH_DTLS__ || __WITH_TLS__ + + +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif /* OCPROVISIONINGMANAGER_H_ */ diff --git a/resource/csdk/security/provisioning/sample/provisioningclient.c b/resource/csdk/security/provisioning/sample/provisioningclient.c index 55e7db7..bb65ad5 100644 --- a/resource/csdk/security/provisioning/sample/provisioningclient.c +++ b/resource/csdk/security/provisioning/sample/provisioningclient.c @@ -257,17 +257,10 @@ static void removeDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool g_doneCB = true; } -static void syncDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) +static void resetDeviceCB(void* ctx, int nOfRes, OCProvisionResult_t* arr, bool hasError) { - if(!hasError) - { - OIC_LOG_V(INFO, TAG, "Sync Device SUCCEEDED - ctx: %s", (char*) ctx); - } - else - { - OIC_LOG_V(ERROR, TAG, "Sync Device FAILED - ctx: %s", (char*) ctx); - printResultList((const OCProvisionResult_t*) arr, nOfRes); - } + OC_UNUSED(ctx); + OIC_LOG_V(INFO, TAG, "Reset Device SUCCEEDED"); g_doneCB = true; } @@ -1638,29 +1631,52 @@ static int resetDevice(void) return 0; } - // select device for removing it - int dev_num = 0; + OCProvisionDev_t *dev = NULL; + for ( ; ; ) { - printf(" > Enter Device Number, for Resetting Device: "); - for (int ret = 0; 1 != ret; ) - { - ret = scanf("%d", &dev_num); - for ( ; 0x20 <= getchar() ; ); // for removing overflow garbages - // '0x20 <= code' is character region - } - if (0 < dev_num && g_own_cnt >= dev_num) - { + printf("************************************************************\n"); + printf("Reset device candidate list:\n"); + g_unown_cnt = printDevList(g_own_list); + if(0 == g_unown_cnt) + { + break; + } + + printf("Select number device from list\nor: -1 - escape\n"); + int c = 0; + + if (!scanf("%d",&c)) + { + continue; + } + + if(0 == c && NULL != dev) + { + break; + } + + if(-1 == c) + { + return 0; + } + + if(c > g_own_cnt) + { + continue; + } + + dev = g_own_list; + for(int lst_cnt = 1; dev && lst_cnt != c; lst_cnt++, dev = dev->next); break; - } - printf(" Entered Wrong Number. Please Enter Again\n"); + } g_doneCB = false; printf(" Resetting Selected Owned Device..\n"); - OCStackResult rst = OCResetDevice((void *) g_ctx, DISCOVERY_TIMEOUT, - getDevInst((const OCProvisionDev_t *) g_own_list, dev_num), syncDeviceCB); + OCStackResult rst = SRPResetDevice(dev, resetDeviceCB); + if (OC_STACK_OK != rst) { OIC_LOG_V(ERROR, TAG, "OCResetDevice API error: %d", rst); @@ -1669,7 +1685,7 @@ static int resetDevice(void) if (waitCallbackRet()) // input |g_doneCB| flag implicitly { - OIC_LOG(ERROR, TAG, "OCProvisionCredentials callback error"); + OIC_LOG_V(ERROR, TAG, "%s: callback error", __func__); return -1; } diff --git a/resource/csdk/security/provisioning/src/ocprovisioningmanager.c b/resource/csdk/security/provisioning/src/ocprovisioningmanager.c index ffd1256..afdc839 100644 --- a/resource/csdk/security/provisioning/src/ocprovisioningmanager.c +++ b/resource/csdk/security/provisioning/src/ocprovisioningmanager.c @@ -857,7 +857,8 @@ error: */ OCStackResult OCResetDevice(void* ctx, unsigned short waitTimeForOwnedDeviceDiscovery, const OCProvisionDev_t* pTargetDev, - OCProvisionResultCB resultCallback) + OCProvisionResultCB resultCallback, + OCClientContextDeleter deleteCallback) { OIC_LOG(INFO, TAG, "IN OCResetDevice"); OCStackResult res = OC_STACK_ERROR; @@ -866,7 +867,7 @@ OCStackResult OCResetDevice(void* ctx, unsigned short waitTimeForOwnedDeviceDisc OIC_LOG(INFO, TAG, "OCResetDevice : Invalid parameters"); return OC_STACK_INVALID_PARAM; } - if (!resultCallback) + if (!deleteCallback || !resultCallback) { OIC_LOG(INFO, TAG, "OCResetDevice : NULL Callback"); return OC_STACK_INVALID_CALLBACK; @@ -881,7 +882,7 @@ OCStackResult OCResetDevice(void* ctx, unsigned short waitTimeForOwnedDeviceDisc { resultCallback(ctx, 0, NULL, false); } - SRPResetDevice(pTargetDev, resultCallback); + SRPResetDevice(pTargetDev, deleteCallback); res = OC_STACK_OK; } else if(OC_STACK_OK != res) diff --git a/resource/csdk/security/provisioning/src/ownershiptransfermanager.c b/resource/csdk/security/provisioning/src/ownershiptransfermanager.c index fc7946b..9ce4414 100644 --- a/resource/csdk/security/provisioning/src/ownershiptransfermanager.c +++ b/resource/csdk/security/provisioning/src/ownershiptransfermanager.c @@ -955,6 +955,13 @@ exit: return OC_STACK_DELETE_TRANSACTION; } +static void deleteCallback(void *ctx) +{ + OC_UNUSED(ctx); + OIC_LOG_V(DEBUG, TAG, "%s: otm context deleted", __func__); +} + + /** * Response handler for update owner uuid request. * @@ -986,7 +993,7 @@ static OCStackApplicationResult OwnerUuidUpdateHandler(void *ctx, OCDoHandle UNU res = VerifyOwnershipTransfer(NULL, USER_CONFIRM); if (OC_STACK_OK != res) { - if (OC_STACK_OK != SRPResetDevice(otmCtx->selectedDeviceInfo, otmCtx->ctxResultCallback)) + if (OC_STACK_OK != SRPResetDevice(otmCtx->selectedDeviceInfo, deleteCallback)) { OIC_LOG(WARNING, TAG, "OwnerUuidUpdateHandler : SRPResetDevice error"); } diff --git a/resource/csdk/security/provisioning/src/secureresourceprovider.c b/resource/csdk/security/provisioning/src/secureresourceprovider.c index a5e1382..9fca96e 100644 --- a/resource/csdk/security/provisioning/src/secureresourceprovider.c +++ b/resource/csdk/security/provisioning/src/secureresourceprovider.c @@ -155,6 +155,7 @@ struct RemoveData { OCProvisionDev_t* linkedDevList; /**< A list of devices which have invalid credential.**/ OCProvisionResult_t* removeRes; /**< Result array.**/ OCProvisionResultCB resultCallback; /**< Pointer to result callback.**/ + OCClientContextDeleter deleteCallback; /**< Pointer to delete callback.**/ size_t numOfResults; /**< Number of results in result array.**/ size_t sizeOfResArray; bool hasError; @@ -1697,7 +1698,7 @@ static OCStackApplicationResult SRPSyncDeviceCredCB(void *delDevCtx, OCDoHandle RemoveData_t* removeData = (RemoveData_t*)delDevCtx; OCProvisionDev_t * pTargetDev = PMCloneOCProvisionDev(removeData->revokeTargetDev); - OCProvisionResultCB resultCallback = removeData->resultCallback; + OCClientContextDeleter deleteCallback = removeData->deleteCallback; if (clientResponse) { OicUuid_t revDevUuid = {.id={0}}; @@ -1752,7 +1753,7 @@ static OCStackApplicationResult SRPSyncDeviceCredCB(void *delDevCtx, OCDoHandle OIC_LOG(ERROR, TAG, "SRPSyncDevice received Null clientResponse"); } - SRPResetDevice(pTargetDev, resultCallback); + SRPResetDevice(pTargetDev, deleteCallback); return OC_STACK_DELETE_TRANSACTION; } @@ -2355,7 +2356,7 @@ error: * OC_STACK_CONTINUE means operation is success but no request is need to be initiated. */ OCStackResult SRPResetDevice(const OCProvisionDev_t* pTargetDev, - OCProvisionResultCB resultCallback) + OCClientContextDeleter deleteCallback) { OIC_LOG(INFO, TAG, "IN SRPResetDevice"); if (!pTargetDev) @@ -2363,7 +2364,7 @@ OCStackResult SRPResetDevice(const OCProvisionDev_t* pTargetDev, OIC_LOG(INFO, TAG, "SRPResetDevice : NULL parameters"); return OC_STACK_INVALID_PARAM; } - if (!resultCallback) + if (!deleteCallback) { OIC_LOG(INFO, TAG, "SRPResetDevice : NULL Callback"); return OC_STACK_INVALID_CALLBACK; @@ -2438,7 +2439,7 @@ OCStackResult SRPResetDevice(const OCProvisionDev_t* pTargetDev, } cbData.cb = &SRPResetDeviceCB; cbData.context = (void *) targetDev; - cbData.cd = NULL; + cbData.cd = deleteCallback; OIC_LOG(DEBUG, TAG, "Sending PSTAT info to resource server"); res = OCDoResource(&handle, method, query, &targetDev->endpoint, (OCPayload *)secPayload, diff --git a/resource/csdk/security/provisioning/unittest/secureresourceprovider.cpp b/resource/csdk/security/provisioning/unittest/secureresourceprovider.cpp index 91b8da1..6a261e2 100644 --- a/resource/csdk/security/provisioning/unittest/secureresourceprovider.cpp +++ b/resource/csdk/security/provisioning/unittest/secureresourceprovider.cpp @@ -69,6 +69,11 @@ static void provisioningCB (void* UNUSED1, int UNUSED2, OCProvisionResult_t *UNU (void) UNUSED4; } +static void resetCB (void* ctx) +{ + OC_UNUSED(ctx); +} + TEST(SRPProvisionACLTest, NullDeviceInfo) { pDev1.doxm = &defaultDoxm1; @@ -475,7 +480,7 @@ TEST(SRPProvisionTrustCertChainTest, SRPResetDeviceNoCallback) TEST(SRPProvisionTrustCertChainTest, SRPResetDeviceNoDevice) { - EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPResetDevice(NULL, provisioningCB)); + EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPResetDevice(NULL, resetCB)); } TEST(SRPProvisionTrustCertChainTest, SRPSyncDeviceNoCallback)