#define NUMBER_OF_ALPHABET (26)
static GeneratePinCallback gGenPinCallback = NULL;
+static GeneratePinCallback gSetPinCallback = NULL;
static InputPinCallback gInputPinCallback = NULL;
static ClosePinDisplayCallback gClosePinDispalyCallback = NULL;
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
};
/**
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)
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;
}