+static OCStackResult StartCustomOwnershipTransfer(void* ctx, OCProvisionDev_t* selectedDevice,const OicSecOxm_t method)
+{
+ OIC_LOG(INFO, TAG, "IN StartOwnershipTransfer");
+ OCStackResult res = OC_STACK_INVALID_PARAM;
+
+ VERIFY_NON_NULL(TAG, selectedDevice, ERROR);
+ VERIFY_NON_NULL(TAG, selectedDevice->doxm, ERROR);
+
+ OTMContext_t* otmCtx = (OTMContext_t*)ctx;
+ otmCtx->selectedDeviceInfo = selectedDevice;
+
+ //Setup PDM to perform the OTM, PDM will be cleanup if necessary.
+ res = SetupPDM(selectedDevice);
+ if(OC_STACK_OK != res)
+ {
+ OIC_LOG_V(ERROR, TAG, "SetupPDM error : %d", res);
+ SetResult(otmCtx, res);
+ return res;
+ }
+
+ //Select the OxM to performing ownership transfer
+ selectedDevice->doxm->oxmSel = method;
+ OIC_LOG_V(DEBUG, TAG, "Selected provisoning method = %d", selectedDevice->doxm->oxmSel);
+
+ res = OTMSetOTCallback(selectedDevice->doxm->oxmSel, &otmCtx->otmCallback);
+ if(OC_STACK_OK != res)
+ {
+ OIC_LOG_V(ERROR, TAG, "Error in OTMSetOTCallback : %d", res);
+ return res;
+ }
+
+#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
+ //Register TLS event handler, to catch the TLS handshake event
+ if(CA_STATUS_OK != CAregisterSslHandshakeCallback(DTLSHandshakeCB))
+ {
+ OIC_LOG(WARNING, TAG, "StartOwnershipTransfer : Failed to register TLS handshake callback.");
+ }
+#endif // __WITH_DTLS__ or __WITH_TLS__
+
+ //Send Req: POST /oic/sec/doxm [{..."OxmSel" :g_OTMCbDatas[Index of Selected OxM].OXMString,...}]
+ res = PostOwnerTransferModeToResource(otmCtx);
+ if(OC_STACK_OK != res)
+ {
+ OIC_LOG_V(WARNING, TAG, "Failed to select the provisioning method : %d", res);
+ SetResult(otmCtx, res);
+ return res;
+ }
+
+ OIC_LOG(INFO, TAG, "OUT StartOwnershipTransfer");
+
+exit:
+ return res;
+}
+