Merge tizen_5.0 codes into tizen_4.0
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / src / ownershiptransfermanager.c
index 326376b..a483e7a 100644 (file)
@@ -104,6 +104,8 @@ static uint8_t g_OxmAllowStatus[OXM_IDX_COUNT] = {ALLOWED_OXM, ALLOWED_OXM, ALLO
                                                   NOT_ALLOWED_OXM};
 #endif
 
+static OTMSelectMethodCallback g_selectOTMCB = NULL;
+
 OCStackResult OTMSetOTCallback(OicSecOxm_t oxm, OTMCallbackData_t* callbacks)
 {
     OCStackResult res = OC_STACK_INVALID_PARAM;
@@ -180,6 +182,18 @@ exit:
     return res;
 }
 
+void SetSelectOTMCB(OTMSelectMethodCallback selectOTMcb)
+{
+    g_selectOTMCB = selectOTMcb;
+    return;
+}
+
+void UnsetSelectOTMCB()
+{
+    g_selectOTMCB = NULL;
+    return;
+}
+
 /**
  * Internal API to convert OxM value to index of oxm allow table.
  */
@@ -237,6 +251,11 @@ OCStackResult OTMSelectOwnershipTransferMethod(const OicSecOxm_t *supportedMetho
     {
         case SUPER_OWNER:
         {
+            if (g_selectOTMCB)
+            {
+                uint32_t methNum = 0;
+                OicSecOxm_t list[10] = {0};
+
             for (size_t i = 0; i < numberOfMethods; i++)
             {
                 selectedOxmIdx = GetOxmAllowTableIdx(supportedMethods[i]);
@@ -245,19 +264,45 @@ OCStackResult OTMSelectOwnershipTransferMethod(const OicSecOxm_t *supportedMetho
                     OIC_LOG(WARNING, TAG, "Invalid oxm index to access OxM allow table");
                     continue;
                 }
-#ifdef MULTIPLE_OWNER
+    #ifdef MULTIPLE_OWNER
+                    if (ALLOWED_OXM == g_OxmAllowStatus[selectedOxmIdx] &&
+                       OXM_IDX_PRECONFIG_PIN != selectedOxmIdx)
+    #else
+
+                    if (ALLOWED_OXM == g_OxmAllowStatus[selectedOxmIdx])
+    #endif //MULTIPLE_OWNER
+                    {
+                        list[methNum] = supportedMethods[i];
+                        methNum++;
+                    }
+                }
+                *selectedMethod = g_selectOTMCB(list, methNum);
+                isOxmSelected = true;
+            }
+            else
+            {
+                for (size_t i = 0; i < numberOfMethods; i++)
+                {
+                    selectedOxmIdx = GetOxmAllowTableIdx(supportedMethods[i]);
+                    if (OXM_IDX_COUNT <= selectedOxmIdx)
+                    {
+                        OIC_LOG(WARNING, TAG, "Invalid oxm index to access OxM allow table");
+                        continue;
+                    }
+    #ifdef MULTIPLE_OWNER
                 if (ALLOWED_OXM == g_OxmAllowStatus[selectedOxmIdx] &&
                    OXM_IDX_PRECONFIG_PIN != selectedOxmIdx)
-#else
+    #else
 
                 if (ALLOWED_OXM == g_OxmAllowStatus[selectedOxmIdx])
-#endif //MULTIPLE_OWNER
+    #endif //MULTIPLE_OWNER
                 {
                     *selectedMethod  = supportedMethods[i];
                     isOxmSelected = true;
                 }
             }
         }
+        }
         break;
 #ifdef MULTIPLE_OWNER
         case SUB_OWNER:
@@ -2144,7 +2189,7 @@ static OCStackResult StartOwnershipTransfer(void* ctx, OCProvisionDev_t* selecte
         SetResult(otmCtx, res);
         return res;
     }
-    OIC_LOG_V(DEBUG, TAG, "Selected provisoning method = %d", selectedDevice->doxm->oxmSel);
+    OIC_LOG_V(DEBUG, TAG, "Selected provisioning method = %d", selectedDevice->doxm->oxmSel);
 
     res = OTMSetOTCallback(selectedDevice->doxm->oxmSel, &otmCtx->otmCallback);
     if(OC_STACK_OK != res)
@@ -2197,7 +2242,7 @@ static OCStackResult StartCustomOwnershipTransfer(void* ctx, OCProvisionDev_t* s
 
     //Select the OxM to performing ownership transfer
     selectedDevice->doxm->oxmSel = method;
-    OIC_LOG_V(DEBUG, TAG, "Selected provisoning method = %d", selectedDevice->doxm->oxmSel);
+    OIC_LOG_V(DEBUG, TAG, "Selected provisioning method = %d", selectedDevice->doxm->oxmSel);
 
     res = OTMSetOTCallback(selectedDevice->doxm->oxmSel, &otmCtx->otmCallback);
     if(OC_STACK_OK != res)