*
* *****************************************************************/
#include <stdint.h>
+#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include "ocprovisioningmanager.h"
#include "pmutility.h"
#include "srmutility.h"
#include "ownershiptransfermanager.h"
-#ifdef _ENABLE_MULTIPLE_OWNER_
+#ifdef MULTIPLE_OWNER
#include "multipleownershiptransfermanager.h"
-#endif //_ENABLE_MULTIPLE_OWNER_
+#endif //MULTIPLE_OWNER
#include "oic_malloc.h"
#include "logger.h"
#include "secureresourceprovider.h"
#include "utlist.h"
#include "aclresource.h" //Note: SRM internal header
#include "pconfresource.h"
+#include "psinterface.h"
+#include "srmresourcestrings.h"
#define TAG "OIC_OCPMAPI"
};
-#ifdef _ENABLE_MULTIPLE_OWNER_
+#ifdef MULTIPLE_OWNER
typedef struct ProvPreconfPINCtx ProvPreconfPINCtx_t;
struct ProvPreconfPINCtx
{
size_t pinLen;
OCProvisionResultCB resultCallback;
};
-#endif //_ENABLE_MULTIPLE_OWNER_
+#endif //MULTIPLE_OWNER
/**
* The function is responsible for initializaton of the provisioning manager. It will load
return PDMInit(dbPath);
}
+void OCTerminatePM()
+{
+ OTMTerminate();
+}
+
+OCStackResult OCPDMCleanupForTimeout()
+{
+ return PDMDeleteDeviceWithState(PDM_DEVICE_INIT);
+}
+
/**
* The function is responsible for discovery of owned/unowned device is specified endpoint/deviceID.
* And this function will only return the specified device's response.
}
/**
+ * The function is responsible for discovery of owned/unowned device is specified endpoint/deviceID.
+ * And this function will only return the specified device's response.
+ *
+ * @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)
+{
+ if( NULL == ppFoundDevice || NULL != *ppFoundDevice || 0 == timeout || NULL == deviceID ||
+ NULL == hostAddress)
+ {
+ OIC_LOG(ERROR, TAG, "OCDiscoverSingleDeviceInUnicast : Invalid Parameter");
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ return PMSingleDeviceDiscoveryInUnicast(timeout, deviceID, hostAddress, connType,
+ 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.
return PMDeviceDiscovery(timeout, true, ppList);
}
-#ifdef _ENABLE_MULTIPLE_OWNER_
+#ifdef MULTIPLE_OWNER
/**
* The function is responsible for discovery of MOT enabled device is current subnet.
*
return MOTDoOwnershipTransfer(ctx, targetDevices, resultCallback);
}
-#endif //_ENABLE_MULTIPLE_OWNER_
+OCStackResult OCRemoveSubOwner(void* ctx,
+ const OCProvisionDev_t *targetDeviceInfo,
+ const OicUuid_t* subOwner,
+ OCProvisionResultCB resultCallback)
+{
+ if (NULL == targetDeviceInfo || NULL == subOwner)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s : NULL Param", __func__);
+ return OC_STACK_INVALID_PARAM;
+ }
+ if (NULL == resultCallback)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s : NULL Callback", __func__);
+ return OC_STACK_INVALID_CALLBACK;
+ }
+
+ return MOTRemoveSubOwner(ctx, targetDeviceInfo, subOwner, resultCallback);
+}
+
+OCStackResult OCRemoveAllSubOwner(void* ctx,
+ const OCProvisionDev_t *targetDeviceInfo,
+ OCProvisionResultCB resultCallback)
+{
+ if (NULL == targetDeviceInfo)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s : NULL Param", __func__);
+ return OC_STACK_INVALID_PARAM;
+ }
+ if (NULL == resultCallback)
+ {
+ OIC_LOG_V(ERROR, TAG, "%s : NULL Callback", __func__);
+ return OC_STACK_INVALID_CALLBACK;
+ }
+
+ return MOTRemoveSubOwner(ctx, targetDeviceInfo, &WILDCARD_SUBJECT_ID, resultCallback);
+}
+
+
+#endif //MULTIPLE_OWNER
/**
* API to register for particular OxM.
return OTMSetOwnershipTransferCallbackData(oxm, callbackData);
}
+/**
+ * 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)
+{
+ return OTMSetOxmAllowStatus(oxm, allowStatus);
+}
+
OCStackResult OCDoOwnershipTransfer(void* ctx,
OCProvisionDev_t *targetDevices,
OCProvisionResultCB resultCallback)
return OTMDoOwnershipTransfer(ctx, targetDevices, resultCallback);
}
+OCStackResult OCDoCustomOwnershipTransfer(void* ctx,
+ OCProvisionDev_t *selectedDevice,
+ OCProvisionResultCB resultCallback,
+ const OicSecOxm_t method)
+{
+ if( NULL == selectedDevice )
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+ if (!resultCallback)
+ {
+ OIC_LOG(INFO, TAG, "OCDoCustomOwnershipTransfer : NULL Callback");
+ return OC_STACK_INVALID_CALLBACK;
+ }
+ return OTMDoCustomOwnershipTransfer(ctx, selectedDevice, resultCallback, method);
+}
+
/**
* This function deletes memory allocated to linked list created by OCDiscover_XXX_Devices API.
*
return SRPProvisionDirectPairing(ctx, selectedDeviceInfo, pconf, resultCallback);
}
-#ifdef _ENABLE_MULTIPLE_OWNER_
+#ifdef MULTIPLE_OWNER
static void AddPreconfPinOxMCB(void* ctx, int nOfRes, OCProvisionResult_t *arr, bool hasError)
{
ProvPreconfPINCtx_t* provCtx = (ProvPreconfPINCtx_t*)ctx;
size_t preconfigPinLen,
OCProvisionResultCB resultCallback)
{
- if( NULL == targetDeviceInfo )
+ if( NULL == targetDeviceInfo || NULL == preconfigPin || 0 == preconfigPinLen )
{
return OC_STACK_INVALID_PARAM;
}
*/
return MOTAddMOTMethod((void*)provCtx, targetDeviceInfo, OIC_PRECONFIG_PIN, AddPreconfPinOxMCB);
}
-#endif //_ENABLE_MULTIPLE_OWNER_
+#endif //MULTIPLE_OWNER
/*
* Function to unlink devices.
// TODO: We need to add new mechanism to clean up the stale state of the device.
// Close the DTLS session of the removed device.
- CAEndpoint_t *endpoint = (CAEndpoint_t *)&pTargetDev->endpoint;
- endpoint->port = pTargetDev->securePort;
- CAResult_t caResult = CAcloseSslSession(endpoint);
+ CAResult_t caResult = CAcloseSslConnectionUsingUuid(pTargetDev->doxm->deviceID.id
+ , sizeof(pTargetDev->doxm->deviceID.id));
if(CA_STATUS_OK != caResult)
{
- OIC_LOG_V(WARNING, TAG, "OCRemoveDevice : Failed to close DTLS session : %d", caResult);
+ OIC_LOG_V(WARNING, TAG, "OCRemoveDevice : Failed to close (D)TLS session : %d", caResult);
}
-
OIC_LOG(DEBUG, TAG, "OUT RemoveDeviceInfoFromLocal");
error:
return res;
return res;
}
+#if !defined(MAX_WAIT_TIME)
+#define MAX_WAIT_TIME 15
+#endif
+
+static int g_reset;
+static void localResultCallback(void* ctx)
+{
+ OC_UNUSED(ctx);
+ g_reset = 0;
+}
/*
* Function to device revocation
* This function will remove credential of target device from all devices in subnet.
if (!pTargetUuid || 0 == waitTimeForOwnedDeviceDiscovery)
{
- OIC_LOG(INFO, TAG, "OCRemoveDeviceWithUuid : Invalied parameters");
+ OIC_LOG(INFO, TAG, "OCRemoveDeviceWithUuid : Invalid parameters");
return OC_STACK_INVALID_PARAM;
}
if (!resultCallback)
}
PDMDestoryOicUuidLinkList(linkedDevices);
- //If there is no linked devices, device revocation step can be skipped.
- if(0 != numOfLinkedDevices)
+ //2. Find owned device from the network
+ res = PMDeviceDiscovery(waitTimeForOwnedDeviceDiscovery, true, &pOwnedDevList);
+ if (OC_STACK_OK != res)
{
- OIC_LOG_V(INFO, TAG, "[%s] linked with other devices.", strUuid);
- //2. Find owned device from the network
- res = PMDeviceDiscovery(waitTimeForOwnedDeviceDiscovery, true, &pOwnedDevList);
- if (OC_STACK_OK != res)
- {
- OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid : Failed to PMDeviceDiscovery");
- goto error;
- }
+ OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid : Failed to PMDeviceDiscovery");
+ goto error;
+ }
- OCProvisionDev_t* tempDev = NULL;
- LL_FOREACH(pOwnedDevList, tempDev)
+ OCProvisionDev_t* tempDev = NULL;
+ LL_FOREACH(pOwnedDevList, tempDev)
+ {
+ if(memcmp(&tempDev->doxm->deviceID.id, pTargetUuid->id, sizeof(pTargetUuid->id)) == 0)
{
- if(memcmp(&tempDev->doxm->deviceID.id, pTargetUuid->id, sizeof(pTargetUuid->id)) == 0)
- {
- break;
- }
+ break;
}
+ }
- if(NULL == tempDev)
- {
- OIC_LOG_V(WARNING, TAG, "Can not find [%s] on the network.", strUuid);
- OIC_LOG_V(WARNING, TAG, "[%s]'s information will be deleted from local and other devices.", strUuid);
- }
- else
- {
- OICFree(pTargetDev->doxm);
- OICFree(pTargetDev);
- pTargetDev = tempDev;
- discoverdFlag = true;
- OIC_LOG_V(INFO, TAG, "[%s] is dectected on the network.", strUuid);
- }
+ if(NULL == tempDev)
+ {
+ OIC_LOG_V(WARNING, TAG, "Can not find [%s] on the network.", strUuid);
+ OIC_LOG_V(WARNING, TAG, "[%s]'s information will be deleted from local and other devices.", strUuid);
+ }
+ else
+ {
+ OICFree(pTargetDev->doxm);
+ OICFree(pTargetDev);
+ pTargetDev = tempDev;
+ discoverdFlag = true;
+ OIC_LOG_V(INFO, TAG, "[%s] is detected on the network.", strUuid);
+ }
+ //If there is no linked devices, device revocation step can be skipped.
+ if(0 != numOfLinkedDevices)
+ {
+ OIC_LOG_V(INFO, TAG, "[%s] linked with other devices.", strUuid);
OIC_LOG_V(INFO, TAG, "Trying [%s] revocation.", strUuid);
// Send DELETE requests to linked devices
OIC_LOG(INFO, TAG, "Device discovery and SRPRemoveDevice will be skipped.");
}
- res = RemoveDeviceInfoFromLocal(pTargetDev);
- if(OC_STACK_OK != res)
+ int maxWait = MAX_WAIT_TIME;
+ g_reset = 1;
+
+ res = SRPResetDevice(pTargetDev, localResultCallback);
+ if(OC_STACK_OK == res)
{
- OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid : Filed to remove the device information from local.");
- goto error;
+ while(g_reset && maxWait)
+ {
+ sleep(1);
+ maxWait--;
+ }
}
if(OC_STACK_CONTINUE == resReq)
{
- /**
- * If there is no linked device, PM does not send any request.
- * So we should directly invoke the result callback to inform the result of OCRemoveDevice.
- */
- if(resultCallback)
- {
- resultCallback(ctx, 0, NULL, false);
- }
+ resultCallback(ctx, 0, NULL, false);
res = OC_STACK_OK;
}
+ res = RemoveDeviceInfoFromLocal(pTargetDev);
+ if(OC_STACK_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "OCRemoveDeviceWithUuid : Failed to remove the device information from local.");
+ goto error;
+ }
error:
OICFree(strUuid);
PMDeleteDeviceList(pOwnedDevList);
*/
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;
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;
{
resultCallback(ctx, 0, NULL, false);
}
- SRPResetDevice(pTargetDev, resultCallback);
+ SRPResetDevice(pTargetDev, deleteCallback);
res = OC_STACK_OK;
}
else if(OC_STACK_OK != res)
}
/**
+ * 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)
+{
+ return ResetSecureResourceInPS();
+}
+
+/**
+ * This function to register callback, for getting notification if SVR DB was reseted.
+ * @param[in] ResetSVRDBCB notifier callback function.
+ * @return OC_STACK_OK in case of successful reset and other value otherwise.
+ */
+
+OCStackResult OCRegisterResetSVRDBNotifier(ResetSVRDBCB callback)
+{
+ OIC_LOG_V(INFO, TAG, "IN %s", __func__);
+
+ if(NULL != GetResetSVRDBCB()->callback)
+ {
+ OIC_LOG_V(ERROR, TAG,"%s Can't register notifier callback, unregister previous one!" ,__func__);
+ return OC_STACK_ERROR;
+ }
+
+ GetResetSVRDBCB()->callback = callback;
+
+ OIC_LOG_V(INFO, TAG, "Out %s", __func__);
+ return OC_STACK_OK;
+}
+
+
+/**
+ * This function to unregister ResetSVRDBCB notification callback.
+ */
+void OCUnregisterResetSVRDBNotifier(void)
+{
+ OIC_LOG_V(INFO, TAG, "IN %s", __func__);
+
+ if(NULL != GetResetSVRDBCB()->callback)
+ {
+ GetResetSVRDBCB()->callback = NULL;
+ }
+
+ OIC_LOG_V(INFO, TAG, "Out %s", __func__);
+}
+
+/**
+ * This function configures SVR DB as self-ownership.
+ *
+ *@return OC_STACK_OK in case of successful configue and other value otherwise.
+ */
+OCStackResult OCConfigSelfOwnership(void)
+{
+ return ConfigSelfOwnership();
+}
+
+/**
* Internal Function to update result in link result array.
*/
static void UpdateLinkResults(Linkdata_t *link, int device, OCStackResult stackresult)
FreePdAclList(pPdAcl);
}
-#ifdef _ENABLE_MULTIPLE_OWNER_
+#ifdef MULTIPLE_OWNER
/**
* API to update 'doxm.mom' to resource server.
*
{
return MOTSelectMOTMethod(ctx, targetDeviceInfo, oxmSelValue, resultCallback);
}
-#endif //_ENABLE_MULTIPLE_OWNER_
+#endif //MULTIPLE_OWNER
+
+/**
+ * Function to select appropriate security provisioning method.
+ *
+ * @param[in] supportedMethods Array of supported methods
+ * @param[in] numberOfMethods number of supported methods
+ * @param[out] selectedMethod Selected methods
+ * @param[in] ownerType type of owner device (SUPER_OWNER or SUB_OWNER)
+ * @return OC_STACK_OK on success
+ */
+OCStackResult OCSelectOwnershipTransferMethod(const OicSecOxm_t *supportedMethods,
+ size_t numberOfMethods, OicSecOxm_t *selectedMethod, OwnerType_t ownerType)
+{
+ return OTMSelectOwnershipTransferMethod(supportedMethods, numberOfMethods,
+ selectedMethod, ownerType);
+}
#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
/**
{
SRPRemoveTrustCertChainNotifier();
}
+
+/**
+ * This function sets the callback to utilize peer certificate information
+ */
+OCStackResult OCSetPeerCertCallback(void *ctx, PeerCertCallback peerCertCallback)
+{
+ CAResult_t ret;
+
+ OIC_LOG_V(DEBUG, TAG, "IN %s", __func__);
+ ret = CAsetPeerCertCallback(ctx, peerCertCallback);
+ if (CA_STATUS_OK != ret)
+ {
+ OIC_LOG_V(ERROR, TAG, "CAsetPeerCertCallback() Failed(%d)", ret);
+ return OC_STACK_ERROR;
+ }
+ OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__);
+
+ return OC_STACK_OK;
+}
+
#endif // __WITH_DTLS__ || __WITH_TLS__