replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / security / src / oxmpincommon.c
index 7fff31d..ad70a43 100644 (file)
@@ -18,7 +18,9 @@
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
+#ifndef __TIZENRT__
 #include <memory.h>
+#endif
 
 #include "ocstack.h"
 #include "ocrandom.h"
@@ -40,6 +42,7 @@
 
 static GeneratePinCallback gGenPinCallback = NULL;
 static InputPinCallback gInputPinCallback = NULL;
+static ClosePinDisplayCallback gClosePinDispalyCallback = NULL;
 
 typedef struct PinOxmData {
     uint8_t pinData[OXM_RANDOM_PIN_MAX_SIZE + 1];
@@ -110,6 +113,18 @@ void SetGeneratePinCB(GeneratePinCallback pinCB)
     gGenPinCallback = pinCB;
 }
 
+void SetClosePinDisplayCB(ClosePinDisplayCallback closeCB)
+{
+    if (NULL == closeCB)
+    {
+        OIC_LOG(ERROR, TAG, "Failed to set a callback for closing a pin.");
+        return;
+    }
+
+    gClosePinDispalyCallback = closeCB;
+}
+
+
 void UnsetInputPinCB()
 {
     gInputPinCallback = NULL;
@@ -120,6 +135,19 @@ void UnsetGeneratePinCB()
     gGenPinCallback = NULL;
 }
 
+void UnsetClosePinDisplayCB()
+{
+    gClosePinDispalyCallback = NULL;
+}
+
+void ClosePinDisplay()
+{
+    if (gClosePinDispalyCallback)
+    {
+        gClosePinDispalyCallback();
+    }
+}
+
 /**
  * Internal function to generate PIN element according to pinType.
  * This function assumes the pinType is valid.
@@ -157,6 +185,10 @@ static char GenerateRandomPinElement(OicSecPinType_t pinType)
     {
         return defaultRetValue;
     }
+    else
+    {
+        curIndex -= 1;
+    }
 
     return allowedCharacters[OCGetRandomRange(0, curIndex)];
 }
@@ -241,8 +273,8 @@ OCStackResult InputPin(char* pinBuffer, size_t bufferSize)
     if(gInputPinCallback)
     {
         gInputPinCallback(pinBuffer, bufferSize);
-        OICStrcpy(g_PinOxmData.pinData, OXM_RANDOM_PIN_MAX_SIZE + 1, pinBuffer);
-        g_PinOxmData.pinSize = strlen(g_PinOxmData.pinData);
+        OICStrcpy((char*)(g_PinOxmData.pinData), OXM_RANDOM_PIN_MAX_SIZE + 1, pinBuffer);
+        g_PinOxmData.pinSize = strlen((char*)(g_PinOxmData.pinData));
     }
     else
     {
@@ -254,7 +286,7 @@ OCStackResult InputPin(char* pinBuffer, size_t bufferSize)
     return OC_STACK_OK;
 }
 
-#ifdef _ENABLE_MULTIPLE_OWNER_
+#ifdef MULTIPLE_OWNER
 OCStackResult SetPreconfigPin(const char *pinBuffer, size_t pinLength)
 {
     if(NULL == pinBuffer || OXM_PRECONFIG_PIN_MAX_SIZE < pinLength)
@@ -267,7 +299,7 @@ OCStackResult SetPreconfigPin(const char *pinBuffer, size_t pinLength)
 
     return OC_STACK_OK;
 }
-#endif //_ENABLE_MULTIPLE_OWNER_
+#endif //MULTIPLE_OWNER
 
 #ifdef __WITH_DTLS__
 
@@ -354,7 +386,7 @@ int32_t GetDtlsPskForRandomPinOxm( CADtlsPskCredType_t type,
     return ret;
 }
 
-#ifdef _ENABLE_MULTIPLE_OWNER_
+#ifdef MULTIPLE_OWNER
 int32_t GetDtlsPskForMotRandomPinOxm( CADtlsPskCredType_t type,
               const unsigned char *UNUSED1, size_t UNUSED2,
               unsigned char *result, size_t result_length)
@@ -617,6 +649,6 @@ int32_t GetDtlsPskForMotPreconfPinOxm( CADtlsPskCredType_t type,
 
     return ret;
 }
-#endif //_ENABLE_MULTIPLE_OWNER_
+#endif //MULTIPLE_OWNER
 
 #endif //__WITH_DTLS__