#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 "OCPMAPI"
+#define TAG "OIC_OCPMAPI"
typedef struct Linkdata Linkdata_t;
struct Linkdata
};
-#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.
*
* API to add preconfigured PIN to local SVR DB.
*
* @param[in] targetDeviceInfo Selected target device.
- * @param[in] preconfPIN Preconfig PIN which is used while multiple owner authentication
- * @param[in] preconfPINLen Byte length of preconfig PIN
+ * @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* preconfPIN, size_t preconfPINLen)
+OCStackResult OCAddPreconfigPin(const OCProvisionDev_t *targetDeviceInfo,
+ const char *preconfigPin,
+ size_t preconfigPinLen)
{
- return MOTAddPreconfigPIN( targetDeviceInfo, preconfPIN, preconfPINLen);
+ return MOTAddPreconfigPIN(targetDeviceInfo, preconfigPin, preconfigPinLen);
}
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 SRPGetACLResource(ctx, selectedDeviceInfo, resultCallback);
}
+
+OCStackResult OCReadTrustCertChain(uint16_t credId, uint8_t **trustCertChain,
+ size_t *chainSize)
+{
+ return SRPReadTrustCertChain(credId, trustCertChain, chainSize);
+}
/**
* function to provision credential to devices.
*
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;
}
}
-OCStackResult OCProvisionPreconfPin(void* ctx,
- OCProvisionDev_t *targetDeviceInfo,
- const char * preconfPin, size_t preconfPinLen,
- OCProvisionResultCB resultCallback)
+OCStackResult OCProvisionPreconfigPin(void *ctx,
+ OCProvisionDev_t *targetDeviceInfo,
+ const char *preconfigPin,
+ size_t preconfigPinLen,
+ OCProvisionResultCB resultCallback)
{
- if( NULL == targetDeviceInfo )
+ if( NULL == targetDeviceInfo || NULL == preconfigPin || 0 == preconfigPinLen )
{
return OC_STACK_INVALID_PARAM;
}
if (NULL == resultCallback)
{
- OIC_LOG(INFO, TAG, "OCProvisionPreconfPINCredential : NULL Callback");
+ OIC_LOG(INFO, TAG, "OCProvisionPreconfigPinCredential : NULL Callback");
return OC_STACK_INVALID_CALLBACK;
}
}
provCtx->ctx = ctx;
provCtx->devInfo = targetDeviceInfo;
- provCtx->pin = preconfPin;
- provCtx->pinLen = preconfPinLen;
+ provCtx->pin = preconfigPin;
+ provCtx->pinLen = preconfigPinLen;
provCtx->resultCallback = resultCallback;
/*
* First of all, update OxMs to support preconfigured PIN OxM.
*/
return MOTAddMOTMethod((void*)provCtx, targetDeviceInfo, OIC_PRECONFIG_PIN, AddPreconfPinOxMCB);
}
-#endif //_ENABLE_MULTIPLE_OWNER_
+#endif //MULTIPLE_OWNER
/*
* Function to unlink devices.
* Change the device status as stale status.
* If all request are successed, this device information will be deleted.
*/
- res = PDMSetDeviceStale(&pTargetDev->doxm->deviceID);
+ res = PDMSetDeviceState(&pTargetDev->doxm->deviceID, PDM_DEVICE_STALE);
if (res != OC_STACK_OK)
{
OIC_LOG(WARNING, TAG, "OCRemoveDevice : Failed to set device status as stale");
// 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;
}
/**
+ * 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 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__)
/**
return SRPSaveTrustCertChain(trustCertChain, chainSize, encodingType, credId);
}
+/**
+ * function to register notifier for Trustcertchain change.
+ *
+ * @param[in] ctx user context.
+ * @param[in] TrustCertChainChangeCB notification callback fucntion.
+ * @return OC_STACK_OK in case of success and other value otherwise.
+ */
+OCStackResult OCRegisterTrustCertChainNotifier(void *ctx, TrustCertChainChangeCB Callback)
+{
+ return SRPRegisterTrustCertChainNotifier(ctx, Callback);
+}
+
+/**
+ * function to de-register notifier for Trustcertchain change.
+ */
+void OCRemoveTrustCertChainNotifier()
+{
+ SRPRemoveTrustCertChainNotifier();
+}
+
+/**
+ * This function sets the callback to utilize peer certificate information
+ */
+OCStackResult OCSetPeerCertCallback(void *ctx, PeerCertCallback peerCertCallback)
+{
+ CAResult_t ret;
+
+ OIC_LOG_V(DEBUG, TAG, "IN %s", __func__);
+ ret = CAsetPeerCertCallback(ctx, peerCertCallback);
+ if (CA_STATUS_OK != ret)
+ {
+ OIC_LOG_V(ERROR, TAG, "CAsetPeerCertCallback() Failed(%d)", ret);
+ return OC_STACK_ERROR;
+ }
+ OIC_LOG_V(DEBUG, TAG, "OUT %s", __func__);
+
+ return OC_STACK_OK;
+}
+
#endif // __WITH_DTLS__ || __WITH_TLS__