typedef void(*DisplayPinCallbackWithContext)(char* pinData, size_t pinSize, void* context);
/**
+ * Function pointer to close the displied PIN.
+ */
+typedef void (*ClosePinDisplayCallback)(void);
+
+/**
* Function pointer to input pin code.
*/
typedef void (*InputPinCallback)(char* pinBuf, size_t bufSize);
* @param context context to return in the callback.
*
* @return OC_STACK_OK in case of success or other value in case of error.
- * OC_STACK_INVALID_PARAM if pinCB is invalid.
+ * OC_STACK_INVALID_PARAM if pinCB is invalid.
* OC_STACK_DUPLICATE_REQUEST if an input pin callback has already been set.
*/
OCStackResult SetInputPinWithContextCB(InputPinCallbackWithContext inputPinCB, void* context);
/**
+ * Function to set the close PIN callback
+ * This callback will be invoked when PIN based OTM is finished.
+ *
+ * @param closeCB implementation of close PIN callback.
+ */
+void SetClosePinDisplayCB(ClosePinDisplayCallback closeCB);
+
+/**
* Function to unset the input PIN callback.
* NOTE : Do not call this function while PIN based ownership transfer is in progress.
*
void UnsetDisplayPinWithContextCB();
/**
+ * Function to unset the PIN close callback.
+ * NOTE : Do not call this function while PIN based ownership transfer is in progress.
+ */
+void UnsetClosePinCB();
+
+/**
* Function to generate a random PIN.
* This function will send a generated PIN to the user via the callback that was set in
* SetGeneratePinCB or SetGeneratePinWithContextCB.
/**
* Function to get a pin for a device.
- * This function will acquire a pin from the user via the callback that was set in
- * SetInputPinCB or SetInputPinWithContextCB.
+ * This function will acquire a pin from the user via the callback that was set in
+ * SetInputPinCB or SetInputPinWithContextCB.
*
* @param[in] deviceId is the device that is requesting a pin
* @param[in,out] pinBuffer is the reference to the buffer to store the inputed PIN data.
*/
OCStackResult InputPin(OicUuid_t deviceId, char* pinBuffer, size_t bufferSize);
+/**
+ * Function to invoke the callback for close a PIN display.
+ */
+void ClosePinDisplay();
+
+
#ifdef MULTIPLE_OWNER
/**
* Function to save the Pre-configured PIN.
OIC_LOG(INFO, TAG, "============================");
}
+void ClosePinDisplayCB(void)
+{
+ OIC_LOG(INFO, TAG, "============================");
+ OIC_LOG(INFO, TAG, " PIN DISPLAY CLOSED.");
+ OIC_LOG(INFO, TAG, "============================");
+}
+
int main()
{
OIC_LOG(DEBUG, TAG, "OCServer is starting...");
SetDisplayPinWithContextCB(DisplayPinCB, NULL);
/**
+ * If the 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.
+ */
+ SetClosePinDisplayCB(ClosePinDisplayCB);
+
+ /**
* Random PIN generation policy can be changed through SetRandomPinPolicy() API.
* first param : byte length of random PIN ( 4 <= first param <= 32)
* second param : PIN type (This is bitmask)
//Save the owner's UUID to derive owner credential
memcpy(&(gDoxm->owner), &(newDoxm->owner), sizeof(OicUuid_t));
+ // In case of random-pin based OTM, close the PIN display if callback is registered.
+ if (!isDuplicatedMsg)
+ {
+ ClosePinDisplay();
+ }
+
//Update new state in persistent storage
if (UpdatePersistentStorage(gDoxm) == true)
{
{
GeneratePinCallback callback;
DisplayPinCallbackWithContext contextCallback;
+ ClosePinDisplayCallback closePinDisplayCallback;
void* context;
} DisplayPinCallbacks_t;
void* context;
} InputPinCallbacks_t;
-static DisplayPinCallbacks_t g_displayPinCallbacks = { .callback = NULL, .contextCallback = NULL, .context = NULL };
+static DisplayPinCallbacks_t g_displayPinCallbacks = { .callback = NULL, .contextCallback = NULL, .closePinDisplayCallback = NULL, .context = NULL };
static InputPinCallbacks_t g_inputPinCallbacks = { .callback = NULL, .contextCallback = NULL, .context = NULL };
typedef struct PinOxmData {
return OC_STACK_OK;
}
+void SetClosePinDisplayCB(ClosePinDisplayCallback closeCB)
+{
+ if (NULL == closeCB)
+ {
+ OIC_LOG(ERROR, TAG, "Failed to set a callback for closing a pin.");
+ return;
+ }
+
+ if (NULL != g_displayPinCallbacks.closePinDisplayCallback)
+ {
+ OIC_LOG(ERROR, TAG, "Callback for closing a pin is already set.");
+ return;
+ }
+
+ g_displayPinCallbacks.closePinDisplayCallback = closeCB;
+}
+
void UnsetInputPinCB()
{
UnsetInputPinWithContextCB();
g_displayPinCallbacks.context = NULL;
}
+void UnsetClosePinDisplayCB()
+{
+ g_displayPinCallbacks.closePinDisplayCallback = NULL;
+}
+
+void ClosePinDisplay()
+{
+ if (g_displayPinCallbacks.closePinDisplayCallback)
+ {
+ g_displayPinCallbacks.closePinDisplayCallback();
+ }
+}
+
/**
* Internal function to generate PIN element according to pinType.
* This function assumes the pinType is valid.