summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleksii Beketov <ol.beketov@samsung.com>2019-08-06 13:49:33 +0300
committerSudipto <sudipto.bal@samsung.com>2019-08-26 12:27:11 +0530
commita12c7ce3b4bf756a885ffd70b36f22b69c141b3f (patch)
treef118dc9ae9660577fda068b0417df194dcebfddc
parent79180296017c57ab0e042b7a51c5f02c6d4ed25d (diff)
downloadiotivity-a12c7ce3b4bf756a885ffd70b36f22b69c141b3f.tar.gz
iotivity-a12c7ce3b4bf756a885ffd70b36f22b69c141b3f.tar.bz2
iotivity-a12c7ce3b4bf756a885ffd70b36f22b69c141b3f.zip
QR Code Random Pin CB
Added an API to set preconfigured PIN code https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/553/commits/d5ebdbfdb3287aea754fc6a637ba771d6485004f (cherry-picked from d5ebdbfdb3287aea754fc6a637ba771d6485004f) Change-Id: I0d1ccdf352ddabe9bb57c59a15c9a5ac8eb6f189 Signed-off-by: Oleksii Beketov <ol.beketov@samsung.com> Signed-off-by: Sudipto <sudipto.bal@samsung.com>
-rw-r--r--resource/csdk/security/include/pinoxmcommon.h13
-rw-r--r--resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp7
-rw-r--r--resource/csdk/security/src/oxmpincommon.c45
3 files changed, 55 insertions, 10 deletions
diff --git a/resource/csdk/security/include/pinoxmcommon.h b/resource/csdk/security/include/pinoxmcommon.h
index aa40dd5c2..729b410f6 100644
--- a/resource/csdk/security/include/pinoxmcommon.h
+++ b/resource/csdk/security/include/pinoxmcommon.h
@@ -78,6 +78,19 @@ typedef void (*ClosePinDisplayCallback)(void);
void SetGeneratePinCB(GeneratePinCallback pinCB);
/**
+ * Function to set preconfigured PIN value.
+ *
+ * @param[in] pin PIN data
+ * @param[in] pinLen byte length of PIN
+ */
+OCStackResult SetPin(const char * pin, size_t pinLen);
+
+/**
+ * Function to unset preconfigured PIN.
+ */
+OCStackResult UnSetPin();
+
+/**
* Function to setting input PIN callback from user.
*
* @param pinCB implementation of input PIN callback.
diff --git a/resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp b/resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp
index 0f750a083..dcc729eab 100644
--- a/resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp
+++ b/resource/csdk/security/provisioning/sample/sampleserver_randompin.cpp
@@ -481,13 +481,18 @@ int main()
return 0;
}
- /**
+ /**
* If server supported random pin based ownership transfer,
* callback of print PIN should be registered before runing server.
*/
SetGeneratePinCB(GeneratePinCB);
/**
+ * Set preconfigured PIN code
+ */
+ //SetPin("78563412", 8);
+
+ /**
* If ther server supports random pin based OTM,
* the callback to close PIN display can be registered.
* This callback will be invoked when random PIN based OTM is done.
diff --git a/resource/csdk/security/src/oxmpincommon.c b/resource/csdk/security/src/oxmpincommon.c
index 3646605d8..189f07c39 100644
--- a/resource/csdk/security/src/oxmpincommon.c
+++ b/resource/csdk/security/src/oxmpincommon.c
@@ -41,6 +41,7 @@
#define NUMBER_OF_ALPHABET (26)
static GeneratePinCallback gGenPinCallback = NULL;
+static GeneratePinCallback gSetPinCallback = NULL;
static InputPinCallback gInputPinCallback = NULL;
static ClosePinDisplayCallback gClosePinDispalyCallback = NULL;
@@ -49,12 +50,14 @@ typedef struct PinOxmData {
size_t pinSize;
OicSecPinType_t pinType;
OicUuid_t newDevice;
+ int pinPreset;
}PinOxmData_t;
static PinOxmData_t g_PinOxmData = {
- .pinData={0},
+ .pinData = {0},
.pinSize = OXM_RANDOM_PIN_DEFAULT_SIZE,
.pinType = (OicSecPinType_t)(OXM_RANDOM_PIN_DEFAULT_PIN_TYPE),
+ .pinPreset = 0
};
/**
@@ -192,6 +195,27 @@ static char GenerateRandomPinElement(OicSecPinType_t pinType)
return allowedCharacters[OCGetRandomRange(0, curIndex)];
}
+OCStackResult SetPin(const char * pin, size_t pinLen)
+{
+ if(NULL == pin || OXM_PRECONFIG_PIN_MAX_SIZE < pinLen)
+ {
+ return OC_STACK_INVALID_PARAM;
+ }
+
+ memcpy(g_PinOxmData.pinData, pin, pinLen);
+ g_PinOxmData.pinSize = pinLen;
+ g_PinOxmData.pinData[pinLen] = '\0';
+ g_PinOxmData.pinPreset = 1;
+
+ return OC_STACK_OK;
+}
+
+OCStackResult UnSetPin()
+{
+ g_PinOxmData.pinPreset = 0;
+ return OC_STACK_OK;
+}
+
OCStackResult GeneratePin(char* pinBuffer, size_t bufferSize)
{
if(!pinBuffer)
@@ -211,23 +235,26 @@ OCStackResult GeneratePin(char* pinBuffer, size_t bufferSize)
return OC_STACK_ERROR;
}
- for(size_t i = 0; i < g_PinOxmData.pinSize; i++)
+ if (!g_PinOxmData.pinPreset)
{
- pinBuffer[i] = GenerateRandomPinElement(g_PinOxmData.pinType);
- g_PinOxmData.pinData[i] = pinBuffer[i];
- }
+ for(size_t i = 0; i < g_PinOxmData.pinSize; i++)
+ {
+ pinBuffer[i] = GenerateRandomPinElement(g_PinOxmData.pinType);
+ g_PinOxmData.pinData[i] = pinBuffer[i];
+ }
- pinBuffer[g_PinOxmData.pinSize] = '\0';
- g_PinOxmData.pinData[g_PinOxmData.pinSize] = '\0';
+ pinBuffer[g_PinOxmData.pinSize] = '\0';
+ g_PinOxmData.pinData[g_PinOxmData.pinSize] = '\0';
+ }
if(gGenPinCallback)
{
- gGenPinCallback(pinBuffer, g_PinOxmData.pinSize);
+ gGenPinCallback(g_PinOxmData.pinData, g_PinOxmData.pinSize);
}
else
{
OIC_LOG(ERROR, TAG, "Invoke PIN callback failed!");
- OIC_LOG(ERROR, TAG, "Callback for genrate PIN should be registered to use PIN based OxM.");
+ OIC_LOG(ERROR, TAG, "Callback for generate PIN should be registered to use PIN based OxM.");
return OC_STACK_ERROR;
}