Changed PUT to POST, fix for not sending SSID/PWD in the get response & added a trigg...
authorlankamadan <lanka.madan@samsung.com>
Thu, 3 Mar 2016 10:27:00 +0000 (19:27 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Fri, 4 Mar 2016 00:39:59 +0000 (00:39 +0000)
- Changed PUT to POST
- Fix for not sending SSID/PWD in the get response
- Added a trigger for making Enrollee connect to network

Change-Id: I4e041bb1ea3543c595f37a6b59dbc55b420ae838
Signed-off-by: lankamadan <lanka.madan@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5257
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
13 files changed:
service/easy-setup/enrollee/inc/resourcehandler.h
service/easy-setup/enrollee/src/resourcehandler.cpp [changed mode: 0644->0755]
service/easy-setup/inc/escommon.h
service/easy-setup/mediator/csdk/inc/provisioning.h [changed mode: 0644->0755]
service/easy-setup/mediator/csdk/inc/provisioningapi.h [changed mode: 0644->0755]
service/easy-setup/mediator/csdk/src/provisioning.cpp [changed mode: 0644->0755]
service/easy-setup/mediator/csdk/src/provisioningapi.cpp [changed mode: 0644->0755]
service/easy-setup/mediator/csdk/src/wifiprovisioning.cpp [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/inc/ESRichCommon.h [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/inc/RemoteEnrolleeResource.h [changed mode: 0644->0755]
service/easy-setup/mediator/richsdk/src/RemoteEnrolleeResource.cpp
service/easy-setup/sampleapp/mediator/linux/csdk_sample/mediator.cpp [changed mode: 0644->0755]
service/easy-setup/sampleapp/mediator/linux/richsdk_sample/mediator_cpp.cpp

index a927892..243f8f2 100755 (executable)
@@ -36,20 +36,21 @@ typedef void (*ResourceEventCallback)(ESResult);
 typedef struct PROVRESOURCE
 {
     OCResourceHandle handle;
-    int ps; // provisiong status, 1 : need to provisioning, 2 : Connected to Enroller
-    int tnt; // target network type, 1: WLAN, 2: BT, 3: BLE, 4: Zigbee, ...
-    char tnn[MAXSSIDLEN]; // target network name, i.e. SSID for WLAN, MAC address for BT
-    char cd[MAXNETCREDLEN]; // credential information
+    int64_t ps; // provisiong status, 1 : need to provisioning, 2 : Connected to Enroller.
+    int64_t tr; // Trigger network connection, 0 : Init value, 1 : Connected to the target network.
+    int64_t tnt; // target network type, 1: WLAN, 2: BT, 3: BLE, 4: Zigbee.
+    char tnn[MAXSSIDLEN]; // target network name, i.e. SSID for WLAN, MAC address for BT.
+    char cd[MAXNETCREDLEN]; // credential information.
 } ProvResource;
 
 /* Structure to represent a Light resource */
 typedef struct NETRESOURCE
 {
     OCResourceHandle handle;
-    int cnt; // current network type, 1: WLAN, 2: BT, 3: BLE, 4: Zigbee, ...
-    int ant[MAXNUMTYPE]; // available network type, 1: WLAN, 2: BT, 3: BLE, 4: Zigbee, ...
-    char ipaddr[MAXADDRLEN]; // ip address
-    char cnn[MAXSSIDLEN]; // current network name
+    int64_t cnt; // current network type, 1: WLAN, 2: BT, 3: BLE, 4: Zigbee.
+    int64_t ant[MAXNUMTYPE]; // available network type, 1: WLAN, 2: BT, 3: BLE, 4: Zigbee.
+    char ipaddr[MAXADDRLEN]; // ip address.
+    char cnn[MAXSSIDLEN]; // current network name.
 } NetResource;
 
 OCStackResult CreateProvisioningResource(bool isSecured);
old mode 100644 (file)
new mode 100755 (executable)
index dc9f1f2..a02610d
@@ -36,7 +36,8 @@
 
 /**
  * @var gProvResource
- * @brief Structure for holding the Provisioning status and target information required to connect to the target network
+ * @brief Structure for holding the Provisioning status and target information required to
+ * connect to the target network
  */
 static ProvResource gProvResource;
 
@@ -49,19 +50,14 @@ static NetResource gNetResource;
 //-----------------------------------------------------------------------------
 // Private internal function prototypes
 //-----------------------------------------------------------------------------
-OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
-                                                OCEntityHandlerRequest *ehRequest, void *callback);
+OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag, OCEntityHandlerRequest *ehRequest,
+        void *callback);
 const char *getResult(OCStackResult result);
-OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest,
-                                               OCRepPayload** payload);
-OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest,
-                                               OCRepPayload** payload);
-OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest,
-                                                OCRepPayload** payload);
+OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
+OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
+OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
 OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest);
 
-static int g_flag = 0;
-
 ResourceEventCallback gNetworkInfoProvEventCb = NULL;
 
 void RegisterResourceEventCallBack(ResourceEventCallback cb)
@@ -89,29 +85,26 @@ void GetTargetNetworkInfoFromProvResource(char *name, char *pass)
 OCStackResult CreateProvisioningResource(bool isSecured)
 {
     gProvResource.ps = ES_PS_NEED_PROVISIONING;
+    gProvResource.tr = ES_PS_TRIGGER_INIT_VALUE;
 
     gProvResource.tnt = CT_ADAPTER_IP;
-    OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn),"Unknown");
+    OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), "Unknown");
     OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), "Unknown");
 
     OCStackResult res = OC_STACK_ERROR;
     if (isSecured)
     {
         res = OCCreateResource(&gProvResource.handle, OC_RSRVD_ES_PROV_RES_TYPE,
-                OC_RSRVD_INTERFACE_DEFAULT,
-                OC_RSRVD_ES_URI_PROV,
-                OCEntityHandlerCb,
-                NULL,
-                OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
+        OC_RSRVD_INTERFACE_DEFAULT,
+        OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,
+        NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
     }
     else
     {
         res = OCCreateResource(&gProvResource.handle, OC_RSRVD_ES_PROV_RES_TYPE,
-                OC_RSRVD_INTERFACE_DEFAULT,
-                OC_RSRVD_ES_URI_PROV,
-                OCEntityHandlerCb,
-                NULL,
-                OC_DISCOVERABLE | OC_OBSERVABLE);
+        OC_RSRVD_INTERFACE_DEFAULT,
+        OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,
+        NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
     }
 
     OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
@@ -129,8 +122,7 @@ OCStackResult DeleteProvisioningResource()
     return res;
 }
 
-OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest,
-                                                OCRepPayload **payload)
+OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload **payload)
 {
     OCEntityHandlerResult ehResult = OC_EH_ERROR;
     if (!ehRequest)
@@ -157,10 +149,9 @@ OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest,
     return ehResult;
 }
 
-OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest,
-                                               OCRepPayload** payload)
+OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload)
 {
-    OIC_LOG(INFO, ES_RH_TAG, "ProcessPutRequest enter");
+    OIC_LOG(INFO, ES_RH_TAG, "ProcessPostRequest enter");
     OCEntityHandlerResult ehResult = OC_EH_ERROR;
     if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
     {
@@ -175,20 +166,44 @@ OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest,
         return ehResult;
     }
 
-    //TODO : ES_PS_PROVISIONING_COMPLETED state indicates that already provisioning is completed.
+    int64_t tr;
+    if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_TR, &tr))
+    {
+        // Triggering
+        gProvResource.tr = tr;
+    }
+
+    //ES_PS_PROVISIONING_COMPLETED state indicates that already provisioning is completed.
     // A new request for provisioning means overriding existing network provisioning information.
-    // Metadata to indicate that it is override is needed. The metadata can be a new attribute
-    // should be added to the /oic/prov resource indicating to override the existing network
-    // information.
-    if (gProvResource.ps == ES_PS_PROVISIONING_COMPLETED)
+    if (gProvResource.ps == ES_PS_PROVISIONING_COMPLETED && tr == ES_PS_TRIGGER_CONNECTION)
+    {
+        OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning already completed."
+                "Tiggering the network connection");
+
+        if (gNetworkInfoProvEventCb)
+        {
+            gNetworkInfoProvEventCb(ES_RECVTRIGGEROFPROVRES);
+            ehResult = OC_EH_OK;
+        }
+        else
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "gNetworkInfoProvEventCb is NULL."
+                    "Network handler not registered. Failed to connect to the network");
+            ehResult = OC_EH_ERROR;
+        }
+
+        return ehResult;
+    }
+    else if (gProvResource.ps == ES_PS_PROVISIONING_COMPLETED)
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning already completed. "
                 "This a request to override the existing the network provisioning information");
     }
+    else
+    {
+        OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning the network information to the Enrollee.");
+    }
 
-    // PUT request is appropriate for provisioning information to the enrollee.
-    // When an enrollee receives the put request, the entire resource information should
-    // be overwritten.
     OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), "");
     OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), "");
 
@@ -200,16 +215,17 @@ OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest,
     }
 
     OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.tnn %s", gProvResource.tnn);
+
     char* cd;
     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd))
     {
         OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), cd);
         OIC_LOG(INFO, ES_RH_TAG, "got password");
-    }
-    OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.cd %s", gProvResource.cd);
-    gProvResource.ps = 2;
-    OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.ps %d", gProvResource.ps);
-    g_flag = 1;
+    }OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.cd %s", gProvResource.cd);
+
+    gProvResource.ps = ES_PS_PROVISIONING_COMPLETED;
+
+    OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.ps %lld", gProvResource.ps);
 
     OCRepPayload *getResp = constructResponse(ehRequest);
     if (!getResp)
@@ -224,34 +240,10 @@ OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest,
     return ehResult;
 }
 
-OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest,
-                                                OCRepPayload** /*payload*/)
+OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest * /*ehRequest*/,
+        OCRepPayload** /*payload*/)
 {
     OCEntityHandlerResult ehResult = OC_EH_ERROR;
-    if (!ehRequest)
-    {
-        OIC_LOG(ERROR, ES_RH_TAG, "Request is Null");
-        return ehResult;
-    }
-    if (ehRequest->payload && ehRequest->payload->type != PAYLOAD_TYPE_REPRESENTATION)
-    {
-        OIC_LOG(ERROR, ES_RH_TAG, "Incoming payload not a representation");
-        return ehResult;
-    }
-
-    OCRepPayload* input = (OCRepPayload*) (ehRequest->payload);
-    if (!input)
-    {
-        OIC_LOG(ERROR, ES_RH_TAG, "Failed to parse");
-        return ehResult;
-    }
-    char* tr;
-    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TR, &tr))
-    {
-        // Triggering
-        ehResult = OC_EH_OK;
-    }
-    g_flag = 1;
 
     return ehResult;
 }
@@ -271,8 +263,6 @@ OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest)
         OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV);
         OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PS, gProvResource.ps);
         OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_TNT, gProvResource.tnt);
-        OCRepPayloadSetPropString(payload, OC_RSRVD_ES_TNN, gProvResource.tnn);
-        OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CD, gProvResource.cd);
     }
     else if (ehRequest->requestHandle == gNetResource.handle)
     {
@@ -292,8 +282,12 @@ OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
 {
     (void) callback;
     OCEntityHandlerResult ehRet = OC_EH_OK;
-    OCEntityHandlerResponse response = { 0, 0, OC_EH_ERROR, 0, 0, { },{ 0 }, false };
+    OCEntityHandlerResponse response =
+    { 0, 0, OC_EH_ERROR, 0, 0,
+    { },
+    { 0 }, false };
     OCRepPayload* payload = NULL;
+
     if (entityHandlerRequest && (flag & OC_REQUEST_FLAG))
     {
         if (OC_REST_GET == entityHandlerRequest->method)
@@ -305,7 +299,9 @@ OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
         {
             OIC_LOG(INFO, ES_RH_TAG, "Received PUT request");
 
-            if (gProvResource.handle != NULL && entityHandlerRequest->resource == gProvResource.handle)
+            //PUT request will be handled in the internal implementation
+            if (gProvResource.handle != NULL
+                    && entityHandlerRequest->resource == gProvResource.handle)
             {
                 ehRet = ProcessPutRequest(entityHandlerRequest, &payload);
             }
@@ -317,9 +313,17 @@ OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
         }
         else if (OC_REST_POST == entityHandlerRequest->method)
         {
-            // TODO: As of now, POST request will be not received.
             OIC_LOG(INFO, ES_RH_TAG, "Received OC_REST_POST from client");
-            //ehRet = ProcessPostRequest (entityHandlerRequest, payload, sizeof(payload) - 1);
+            if (gProvResource.handle != NULL
+                    && entityHandlerRequest->resource == gProvResource.handle)
+            {
+                ehRet = ProcessPostRequest(entityHandlerRequest, &payload);
+            }
+            else
+            {
+                OIC_LOG(ERROR, ES_RH_TAG, "Cannot process put");
+                ehRet = OC_EH_ERROR;
+            }
         }
 
         if (ehRet == OC_EH_OK)
@@ -332,8 +336,8 @@ OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
             response.payload = (OCPayload*) (payload);
             response.numSendVendorSpecificHeaderOptions = 0;
             memset(response.sendVendorSpecificHeaderOptions, 0,
-                    sizeof response.sendVendorSpecificHeaderOptions);
-            memset(response.resourceUri, 0, sizeof response.resourceUri);
+                    sizeof(response.sendVendorSpecificHeaderOptions));
+            memset(response.resourceUri, 0, sizeof(response.resourceUri));
             // Indicate that response is NOT in a persistent buffer
             response.persistentBufferFlag = 0;
 
@@ -346,12 +350,6 @@ OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
         }
     }
 
-    if (g_flag == 1)
-    {
-        gNetworkInfoProvEventCb(ES_RECVTRIGGEROFPROVRES);
-        g_flag = 0;
-    }
-
     return ehRet;
 }
 
index 43191c9..ea1a650 100755 (executable)
@@ -66,6 +66,9 @@ using namespace std;
  */
 #define ES_PS_NEED_PROVISIONING         1
 #define ES_PS_PROVISIONING_COMPLETED    2
+#define ES_PS_TRIGGER_INIT_VALUE        0
+#define ES_PS_TRIGGER_CONNECTION        1
+
 
 /**
 * Device Roles defined for each device type used in easy setup
old mode 100644 (file)
new mode 100755 (executable)
index 31dd601..f9a6d61
@@ -18,9 +18,8 @@
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
-
-#ifndef __PROVISIONING_HANDLER_H_
-#define __PROVISIONING_HANDLER_H_
+#ifndef __ES_PROVISIONING_HANDLER_H_
+#define __ES_PROVISIONING_HANDLER_H_
 
 #include "octypes.h"
 
 //-----------------------------------------------------------------------------
 #define EASY_SETUP_DEFAULT_CONTEXT_VALUE 0x99
 
-
-//-----------------------------------------------------------------------------
-// Typedefs
-//-----------------------------------------------------------------------------
-
 /**
  * List of methods that can be inititated from the client
  */
@@ -45,41 +39,48 @@ OCStackResult InitProvisioningHandler();
 
 OCStackResult TerminateProvisioningHandler();
 
-void *listeningFunc(void *);
+OCStackResult GetProvisioningStatus(OCQualityOfService qos, const char *query,
+        const OCDevAddr *destination);
+
+OCStackResult StartProvisioningProcess(const ProvConfig *netInfo,
+        WiFiOnboadingConnection *onboardConn, OCProvisioningStatusCB provisioningStatusCallback,
+        char *findResQuery);
+
+void StopProvisioningProcess();
+
+/**
+ * Internal worker functions.
+ */
+OCStackResult TriggerNetworkConnection(OCQualityOfService qos, const char *query,
+        const char *resUri, OCDevAddr *destination, int /*pauseBeforeStart*/);
+
+OCStackApplicationResult TriggerNetworkConnectionResponse(void *ctx, OCDoHandle handle,
+        OCClientResponse *clientResponse);
 
 OCStackApplicationResult ProvisionEnrolleeResponse(void *ctx, OCDoHandle handle,
-                                                   OCClientResponse *clientResponse);
+        OCClientResponse *clientResponse);
 
 OCStackResult ProvisionEnrollee(OCQualityOfService qos, const char *query, const char *resUri,
-                                OCDevAddr *destination, int pauseBeforeStart);
+        OCDevAddr *destination, int pauseBeforeStart);
 
 OCStackApplicationResult GetProvisioningStatusResponse(void *ctx, OCDoHandle handle,
-                                                       OCClientResponse *clientResponse);
+        OCClientResponse *clientResponse);
 
 OCStackResult InvokeOCDoResource(const char *query, OCMethod method, const OCDevAddr *dest,
-                                 OCQualityOfService qos, OCClientResponseHandler cb,
-                                 OCRepPayload *payload,
-                                 OCHeaderOption *options, uint8_t numOptions);
-
-OCStackResult GetProvisioningStatus(OCQualityOfService qos, const char *query,
-                                    const OCDevAddr *destination);
-
-OCStackResult StartProvisioningProcess(const ProvConfig *netInfo,WiFiOnboadingConnection *onboardConn,
-                                       OCProvisioningStatusCB provisioningStatusCallback,
-                                       char *findResQuery);
-
-void StopProvisioningProcess();
+        OCQualityOfService qos, OCClientResponseHandler cb, OCRepPayload *payload,
+        OCHeaderOption *options, uint8_t numOptions);
 
 OCStackApplicationResult FindProvisioningResourceResponse(void *ctx, OCDoHandle handle,
-                                                          OCClientResponse *clientResponse);
+        OCClientResponse *clientResponse);
 
 void *FindProvisioningResource(void *data);
 
-//Invoke Provisioning Status Callback
 ProvisioningInfo *PrepareProvisioingStatusCB(OCClientResponse *clientResponse,
-                                             ProvStatus provStatus);
-
+        ProvStatus provStatus);
 
+/**
+ * Internal Util functions.
+ */
 void LogProvisioningResponse(OCRepPayloadValue * val);
 
 bool ConfigEnrolleeObject(const ProvConfig *netInfo, WiFiOnboadingConnection *onboardConn);
@@ -90,12 +91,14 @@ void SuccessCallback(OCClientResponse * clientResponse);
 
 void ErrorCallback(ProvStatus status);
 
-bool ValidateEnrolleResponse(OCClientResponse * clientResponse);
+bool ValidateEnrolleeResponse(OCClientResponse * clientResponse);
 
-bool ValidateFinddResourceResponse(OCClientResponse * clientResponse);
+bool ValidateFindResourceResponse(OCClientResponse * clientResponse);
+
+bool ValidateEnrolleeBasicResponse(OCClientResponse * clientResponse);
 
 ProvisioningInfo *GetCallbackObjectOnSuccess(OCClientResponse *clientResponse,
-                                             ProvStatus provStatus);
+        ProvStatus provStatus);
 
 ProvisioningInfo *GetCallbackObjectOnError(ProvStatus status);
 
@@ -107,11 +110,10 @@ bool SetProgress(OCProvisioningStatusCB provisioningStatusCallback);
 
 bool InProgress();
 
-bool ValidateEasySetupParams(const ProvConfig *netInfo,WiFiOnboadingConnection *onboardConn,
-                             OCProvisioningStatusCB provisioningStatusCallback);
+bool ValidateEasySetupParams(const ProvConfig *netInfo, WiFiOnboadingConnection *onboardConn,
+        OCProvisioningStatusCB provisioningStatusCallback);
 
 bool IsSetupStopped();
 
-
-#endif
+#endif //__ES_PROVISIONING_HANDLER_H_
 
old mode 100644 (file)
new mode 100755 (executable)
index c80e0af..5fa60fa
 
 #include "provisioning.h"
 
-
 //-----------------------------------------------------------------------------
 // Defines
 //-----------------------------------------------------------------------------
 
 #ifdef __cplusplus
-extern "C" {
+extern "C"
+{
 #endif
+    OCStackResult InitProvProcess();
 
-OCStackResult InitProvProcess();
-
-OCStackResult ResetProvProcess();
-
-OCStackResult RegisterCallback(
-        OCProvisioningStatusCB provisioningStatusCallback);
+    OCStackResult ResetProvProcess();
 
-void UnRegisterCallback();
+    OCStackResult RegisterCallback(OCProvisioningStatusCB provisioningStatusCallback);
 
-OCStackResult StartProvisioning(const ProvConfig *netInfo, WiFiOnboadingConnection *onboardConn);
+    void UnRegisterCallback();
 
-OCStackResult StopProvisioning(OCConnectivityType connectivityType);
+    OCStackResult StartProvisioning(const ProvConfig *netInfo,
+            WiFiOnboadingConnection *onboardConn);
 
+    OCStackResult StopProvisioning(OCConnectivityType connectivityType);
 #ifdef __cplusplus
 }
 #endif
old mode 100644 (file)
new mode 100755 (executable)
index c71fd7a..ac6ac5b
@@ -32,7 +32,6 @@
 #include "ocpayload.h"
 #include "escommon.h"
 
-
 // External includes
 #include "logger.h"
 #include "oic_malloc.h"
@@ -44,7 +43,8 @@ bool gProvisioningCondFlag = false;
 
 static ProvConfig *gProvConfig;
 static WiFiOnboadingConnection *gOnboardConn;
-static char gSzFindResourceQueryUri[64] = {0};
+static char gSzFindResourceQueryUri[64] =
+{ 0 };
 
 /**
  * @var cbData
@@ -52,148 +52,40 @@ static char gSzFindResourceQueryUri[64] = {0};
  */
 static OCProvisioningStatusCB cbData = NULL;
 
-
-void ErrorCallback(ProvStatus status) {
+/**
+ * Utility function for error callback.
+ */
+void ErrorCallback(ProvStatus status)
+{
     ProvisioningInfo *provInfo = GetCallbackObjectOnError(status);
-    cbData(provInfo);
-    ResetProgress();
+    if(cbData != NULL)
+    {
+        cbData(provInfo);
+    }
 }
 
-
-OCStackResult InitProvisioningHandler() {
+/**
+ * Functions implementing the exposed APIs.
+ */
+OCStackResult InitProvisioningHandler()
+{
     OCStackResult ret = OC_STACK_ERROR;
     /* Initialize OCStack*/
-    if (OCInit(NULL, 0, OC_CLIENT) != OC_STACK_OK) {
+    if (OCInit(NULL, 0, OC_CLIENT) != OC_STACK_OK)
+    {
         OIC_LOG(ERROR, ES_PROV_TAG, "OCStack init error");
         return ret;
     }
 
-
-    pthread_t thread_handle;
-
-    if (pthread_create(&thread_handle, NULL, listeningFunc, NULL)) {
-        OIC_LOG(DEBUG, ES_PROV_TAG, "Thread creation failed");
-        return OC_STACK_ERROR;
-    }
-
     return OC_STACK_OK;
 }
 
-OCStackResult TerminateProvisioningHandler() {
-    OCStackResult ret = OC_STACK_ERROR;
-    if (OCStop() != OC_STACK_OK) {
-        OIC_LOG(ERROR, ES_PROV_TAG, "OCStack stop error");
-    }
-
-    gProvisioningCondFlag = true;
-
-    ret = OC_STACK_OK;
-    return ret;
-}
-
-void *listeningFunc(void* /*data*/) {
-    while (!gProvisioningCondFlag) {
-        OCStackResult result;
-
-        result = OCProcess();
-
-        if (result != OC_STACK_OK) {
-            OIC_LOG(ERROR, ES_PROV_TAG, "OCStack stop error");
-        }
-
-        // To minimize CPU utilization we may wish to do this with sleep
-        sleep(1);
-    }
-    return NULL;
-}
-
-
-OCStackApplicationResult ProvisionEnrolleeResponse(void* /*ctx*/, OCDoHandle /*handle*/,
-                                                   OCClientResponse *clientResponse) {
-    OIC_LOG_V(DEBUG, ES_PROV_TAG, "INSIDE ProvisionEnrolleeResponse");
-
-    // If user stopped the process then return from this function;
-    if (IsSetupStopped()) {
-        ErrorCallback(DEVICE_NOT_PROVISIONED);
-        ClearMemory();
-        return OC_STACK_DELETE_TRANSACTION;
-    }
+OCStackResult StartProvisioningProcess(const ProvConfig *netInfo,
+        WiFiOnboadingConnection *onboardConn, OCProvisioningStatusCB provisioningStatusCallback,
+        char *findResQuery)
+{
 
-    if (!ValidateEnrolleResponse(clientResponse)) {
-        ErrorCallback(DEVICE_NOT_PROVISIONED);
-        return OC_STACK_DELETE_TRANSACTION;
-    }
-
-    char *tnn = NULL;
-    char *cd = NULL;
-
-    OCRepPayload *input = (OCRepPayload * )(clientResponse->payload);
-
-    while (input) {
-
-        int64_t ps;
-        if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_PS, &ps)) {
-
-            if (ps == 2) {
-                input = input->next;
-                continue;
-            }
-            else {
-                OIC_LOG_V(DEBUG, ES_PROV_TAG, "PS is NOT proper");
-                goto Error;
-
-            }
-        }
-
-        if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TNN, &tnn)) {
-            if (!strcmp(tnn, gProvConfig->provData.WIFI.ssid)) {
-                OIC_LOG_V(DEBUG, ES_PROV_TAG, "SSID is proper");
-                input = input->next;
-                OICFree(tnn);
-                continue;
-            }
-            else {
-                OIC_LOG_V(DEBUG, ES_PROV_TAG, "SSID is NOT proper");
-                OICFree(tnn);
-                goto Error;
-            }
-        }
-
-        if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd)) {
-            if (!strcmp(cd, gProvConfig->provData.WIFI.pwd)) {
-                OIC_LOG_V(DEBUG, ES_PROV_TAG, "Password is proper");
-                input = input->next;
-                OICFree(cd);
-                continue;
-            }
-            else {
-                OIC_LOG_V(DEBUG, ES_PROV_TAG, "Password is NOT proper");
-                OICFree(cd);
-                goto Error;
-            }
-        }
-
-        LogProvisioningResponse(input->values);
-
-        input = input->next;
-    }
-
-    SuccessCallback(clientResponse);
-    return OC_STACK_KEEP_TRANSACTION;
-
-    Error:
-    {
-        ErrorCallback(DEVICE_NOT_PROVISIONED);
-        return OC_STACK_DELETE_TRANSACTION;
-    }
-
-}
-
-OCStackResult StartProvisioningProcess(const ProvConfig *netInfo,WiFiOnboadingConnection *onboardConn,
-                                       OCProvisioningStatusCB provisioningStatusCallback,
-                                       char *findResQuery) {
-
-    if(findResQuery != NULL)
+    if (findResQuery != NULL)
     {
         OICStrcpy(gSzFindResourceQueryUri, sizeof(gSzFindResourceQueryUri) - 1, findResQuery);
     }
@@ -205,28 +97,31 @@ OCStackResult StartProvisioningProcess(const ProvConfig *netInfo,WiFiOnboadingCo
 
     pthread_t thread_handle;
 
-    if (!ValidateEasySetupParams(netInfo, onboardConn, provisioningStatusCallback)) {
+    if (!ValidateEasySetupParams(netInfo, onboardConn, provisioningStatusCallback))
+    {
         goto Error;
     }
 
-    if (!SetProgress(provisioningStatusCallback)) {
+    if (!SetProgress(provisioningStatusCallback))
+    {
         // Device provisioning session is running already.
         OIC_LOG(INFO, ES_PROV_TAG, PCF("Device provisioning session is running already"));
         goto Error;
     }
 
-    if (!ConfigEnrolleeObject(netInfo, onboardConn)) {
+    if (!ConfigEnrolleeObject(netInfo, onboardConn))
+    {
         goto Error;
     }
 
-    if (pthread_create(&thread_handle, NULL, FindProvisioningResource, NULL)) {
+    if (pthread_create(&thread_handle, NULL, FindProvisioningResource, NULL))
+    {
         goto Error;
 
     }
 
     pthread_join(thread_handle, NULL);
 
-
     return OC_STACK_OK;
 
     Error:
@@ -238,12 +133,71 @@ OCStackResult StartProvisioningProcess(const ProvConfig *netInfo,WiFiOnboadingCo
 
 }
 
-void StopProvisioningProcess() {
-    //Only basis test is done for below API
+void StopProvisioningProcess()
+{
+    ResetProgress();
+}
+
+OCStackResult TerminateProvisioningHandler()
+{
+    OCStackResult ret = OC_STACK_ERROR;
+    if (OCStop() != OC_STACK_OK)
+    {
+        OIC_LOG(ERROR, ES_PROV_TAG, "OCStack stop error");
+    }
+
+    gProvisioningCondFlag = true;
     ResetProgress();
+
+    ret = OC_STACK_OK;
+    return ret;
 }
 
-bool ClearMemory() {
+OCStackApplicationResult TriggerNetworkConnectionResponse(void* /*ctx*/, OCDoHandle /*handle*/,
+        OCClientResponse *clientResponse)
+{
+    OIC_LOG_V(DEBUG, ES_PROV_TAG, "INSIDE TriggerNetworkConnectionResponse");
+
+    // If user stopped the process then return from this function;
+    if (IsSetupStopped())
+    {
+        ErrorCallback(DEVICE_NOT_PROVISIONED);
+        ClearMemory();
+        return OC_STACK_DELETE_TRANSACTION;
+    }
+
+    if (!ValidateEnrolleeBasicResponse(clientResponse))
+    {
+        ErrorCallback(DEVICE_NOT_PROVISIONED);
+        return OC_STACK_DELETE_TRANSACTION;
+    }
+
+    SuccessCallback(clientResponse);
+    return OC_STACK_KEEP_TRANSACTION;
+}
+
+OCStackResult TriggerNetworkConnection(OCQualityOfService qos, const char *query,
+        const char *resUri, OCDevAddr *destination, int /*pauseBeforeStart*/)
+{
+    OIC_LOG_V(INFO, ES_PROV_TAG, "Inside TriggerNetworkConnection");
+
+    OCRepPayload *payload = OCRepPayloadCreate();
+
+    OCRepPayloadSetUri(payload, resUri);
+    OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_TR, ES_PS_TRIGGER_CONNECTION);
+
+    OIC_LOG_V(DEBUG, ES_PROV_TAG, "Triggering network connection from Mediator");
+
+    OCStackResult ret = InvokeOCDoResource(query, OC_REST_POST, destination, qos,
+            TriggerNetworkConnectionResponse, payload, NULL, 0);
+
+    return ret;
+}
+
+
+
+bool ClearMemory()
+{
 
     OIC_LOG(DEBUG, ES_PROV_TAG, "thread_pool_add_task of FindProvisioningResource failed");
     OICFree(gProvConfig);
@@ -253,18 +207,21 @@ bool ClearMemory() {
 
 }
 
-bool ConfigEnrolleeObject(const ProvConfig *netInfo, WiFiOnboadingConnection *connection) {
+bool ConfigEnrolleeObject(const ProvConfig *netInfo, WiFiOnboadingConnection *connection)
+{
 
     //Copy Network Provisioning  Information
     gProvConfig = (ProvConfig *) OICCalloc(1, sizeof(ProvConfig));
     gOnboardConn = (WiFiOnboadingConnection *) OICCalloc(1, sizeof(WiFiOnboadingConnection));
 
-    if (gProvConfig == NULL) {
+    if (gProvConfig == NULL)
+    {
         OIC_LOG(ERROR, ES_PROV_TAG, "Invalid input..");
         return false;
     }
 
-    if (gOnboardConn == NULL) {
+    if (gOnboardConn == NULL)
+    {
         OIC_LOG(ERROR, ES_PROV_TAG, "Invalid input..");
         return false;
     }
@@ -273,18 +230,20 @@ bool ConfigEnrolleeObject(const ProvConfig *netInfo, WiFiOnboadingConnection *co
     memcpy(gOnboardConn, connection, sizeof(WiFiOnboadingConnection));
 
     OIC_LOG_V(DEBUG, ES_PROV_TAG, "Network Provisioning Info. SSID = %s",
-              gProvConfig->provData.WIFI.ssid);
+            gProvConfig->provData.WIFI.ssid);
 
     OIC_LOG_V(DEBUG, ES_PROV_TAG, "Network Provisioning Info. PWD = %s",
-              gProvConfig->provData.WIFI.pwd);
+            gProvConfig->provData.WIFI.pwd);
 
     return true;
 
 }
 
-void LogProvisioningResponse(OCRepPayloadValue * val) {
+void LogProvisioningResponse(OCRepPayloadValue * val)
+{
 
-    switch (val->type) {
+    switch (val->type)
+    {
         case OCREP_PROP_NULL:
             OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s: NULL", val->name);
             break;
@@ -306,36 +265,37 @@ void LogProvisioningResponse(OCRepPayloadValue * val) {
             OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(OCRep):%s", val->name, val->obj->uri);
             break;
         case OCREP_PROP_ARRAY:
-            switch (val->arr.type) {
+            switch (val->arr.type)
+            {
                 case OCREP_PROP_INT:
                     OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(int array):%zu x %zu x %zu",
-                              val->name,
-                              val->arr.dimensions[0], val->arr.dimensions[1],
-                              val->arr.dimensions[2]);
+                            val->name,
+                            val->arr.dimensions[0], val->arr.dimensions[1],
+                            val->arr.dimensions[2]);
                     break;
                 case OCREP_PROP_DOUBLE:
                     OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(double array):%zu x %zu x %zu",
-                              val->name,
-                              val->arr.dimensions[0], val->arr.dimensions[1],
-                              val->arr.dimensions[2]);
+                            val->name,
+                            val->arr.dimensions[0], val->arr.dimensions[1],
+                            val->arr.dimensions[2]);
                     break;
                 case OCREP_PROP_BOOL:
                     OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(bool array):%zu x %zu x %zu",
-                              val->name,
-                              val->arr.dimensions[0], val->arr.dimensions[1],
-                              val->arr.dimensions[2]);
+                            val->name,
+                            val->arr.dimensions[0], val->arr.dimensions[1],
+                            val->arr.dimensions[2]);
                     break;
                 case OCREP_PROP_STRING:
                     OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(string array):%zu x %zu x %zu",
-                              val->name,
-                              val->arr.dimensions[0], val->arr.dimensions[1],
-                              val->arr.dimensions[2]);
+                            val->name,
+                            val->arr.dimensions[0], val->arr.dimensions[1],
+                            val->arr.dimensions[2]);
                     break;
                 case OCREP_PROP_OBJECT:
                     OIC_LOG_V(DEBUG, ES_PROV_TAG, "\t\t%s(OCRep array):%zu x %zu x %zu",
-                              val->name,
-                              val->arr.dimensions[0], val->arr.dimensions[1],
-                              val->arr.dimensions[2]);
+                            val->name,
+                            val->arr.dimensions[0], val->arr.dimensions[1],
+                            val->arr.dimensions[2]);
                     break;
                 default:
                     break;
@@ -346,9 +306,11 @@ void LogProvisioningResponse(OCRepPayloadValue * val) {
     }
 }
 
-OCStackResult FindNetworkResource() {
+OCStackResult FindNetworkResource()
+{
     OCStackResult ret = OC_STACK_ERROR;
-    if (OCStop() != OC_STACK_OK) {
+    if (OCStop() != OC_STACK_OK)
+    {
         OIC_LOG(ERROR, ES_PROV_TAG, "OCStack stop error");
     }
 
@@ -356,18 +318,21 @@ OCStackResult FindNetworkResource() {
 }
 
 ProvisioningInfo *PrepareProvisioingStatusCB(OCClientResponse *clientResponse,
-                                             ProvStatus provStatus) {
+        ProvStatus provStatus)
+{
 
     ProvisioningInfo *provInfo = (ProvisioningInfo *) OICCalloc(1, sizeof(ProvisioningInfo));
 
-    if (provInfo == NULL) {
+    if (provInfo == NULL)
+    {
         OIC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory");
         return NULL;
     }
 
     OCDevAddr *devAddr = (OCDevAddr *) OICCalloc(1, sizeof(OCDevAddr));
 
-    if (devAddr == NULL) {
+    if (devAddr == NULL)
+    {
         OIC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory");
         OICFree(provInfo);
         return NULL;
@@ -384,11 +349,12 @@ ProvisioningInfo *PrepareProvisioingStatusCB(OCClientResponse *clientResponse,
     return provInfo;
 }
 
-
-bool InProgress() {
+bool InProgress()
+{
 
     // It means already Easy Setup provisioning session is going on.
-    if (NULL != cbData) {
+    if (NULL != cbData)
+    {
         OIC_LOG(ERROR, ES_PROV_TAG, "Easy setup session is already in progress");
         return true;
     }
@@ -396,35 +362,39 @@ bool InProgress() {
     return false;
 }
 
-bool SetProgress(OCProvisioningStatusCB provisioningStatusCallback) {
+bool SetProgress(OCProvisioningStatusCB provisioningStatusCallback)
+{
 
     if (InProgress())
         return false;
 
     cbData = provisioningStatusCallback;
 
-
     return true;
 }
 
-bool ResetProgress() {
+bool ResetProgress()
+{
 
     cbData = NULL;
     return true;
 }
 
-ProvisioningInfo *CreateCallBackObject() {
+ProvisioningInfo *CreateCallBackObject()
+{
 
     ProvisioningInfo *provInfo = (ProvisioningInfo *) OICCalloc(1, sizeof(ProvisioningInfo));
 
-    if (provInfo == NULL) {
+    if (provInfo == NULL)
+    {
         OIC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory");
         return NULL;
     }
 
     OCDevAddr *devAddr = (OCDevAddr *) OICCalloc(1, sizeof(OCDevAddr));
 
-    if (devAddr == NULL) {
+    if (devAddr == NULL)
+    {
         OIC_LOG_V(ERROR, ES_PROV_TAG, "Failed to allocate memory");
         OICFree(provInfo);
         return NULL;
@@ -436,11 +406,12 @@ ProvisioningInfo *CreateCallBackObject() {
 
 }
 
-ProvisioningInfo *GetCallbackObjectOnError(ProvStatus status) {
+ProvisioningInfo *GetCallbackObjectOnError(ProvStatus status)
+{
 
     ProvisioningInfo *provInfo = CreateCallBackObject();
     OICStrcpy(provInfo->provDeviceInfo.addr->addr, sizeof(provInfo->provDeviceInfo.addr->addr),
-        gOnboardConn->ipAddress);
+            gOnboardConn->ipAddress);
 
     provInfo->provDeviceInfo.addr->port = IP_PORT;
     provInfo->provStatus = status;
@@ -448,60 +419,86 @@ ProvisioningInfo *GetCallbackObjectOnError(ProvStatus status) {
 }
 
 ProvisioningInfo *GetCallbackObjectOnSuccess(OCClientResponse *clientResponse,
-                                             ProvStatus provStatus) {
+        ProvStatus provStatus)
+{
     ProvisioningInfo *provInfo = CreateCallBackObject();
     OICStrcpy(provInfo->provDeviceInfo.addr->addr, sizeof(provInfo->provDeviceInfo.addr->addr),
-                        clientResponse->addr->addr);
+            clientResponse->addr->addr);
 
     provInfo->provDeviceInfo.addr->port = clientResponse->addr->port;
     provInfo->provStatus = provStatus;
     return provInfo;
 }
 
-bool ValidateFinddResourceResponse(OCClientResponse * clientResponse) {
-
-    if (!(clientResponse) || !(clientResponse->payload)) {
-
-        OIC_LOG_V(INFO, ES_PROV_TAG, "ProvisionEnrolleeResponse received Null clientResponse");
-
+bool ValidateFindResourceResponse(OCClientResponse * clientResponse)
+{
+    if (!(clientResponse) || !(clientResponse->payload))
+    {
+        OIC_LOG_V(INFO, ES_PROV_TAG, "Received Null clientResponse");
         return false;
+    }
 
+    if (clientResponse->payload->type != PAYLOAD_TYPE_DISCOVERY)
+    {
+        OIC_LOG_V(DEBUG, ES_PROV_TAG, "Payload is not discovery type");
+        return false;
     }
+
     return true;
 }
 
-bool ValidateEnrolleResponse(OCClientResponse * clientResponse) {
-
-    if (!(clientResponse) || !(clientResponse->payload)) {
-
-        OIC_LOG_V(INFO, ES_PROV_TAG, "ProvisionEnrolleeResponse received Null clientResponse");
-
+bool ValidateEnrolleeResponse(OCClientResponse * clientResponse)
+{
+    if (!(clientResponse) || !(clientResponse->payload))
+    {
+        OIC_LOG_V(INFO, ES_PROV_TAG, "Received Null clientResponse");
         return false;
+    }
 
+    if (clientResponse->payload->type != PAYLOAD_TYPE_REPRESENTATION)
+    {
+        OIC_LOG_V(DEBUG, ES_PROV_TAG, "Incoming payload is not a representation");
+        return false;
     }
 
-    if (clientResponse->payload->type != PAYLOAD_TYPE_REPRESENTATION) {
+    // If flow reachese here means no error condition hit.
+    return true;
+}
 
-        OIC_LOG_V(DEBUG, ES_PROV_TAG, "Incoming payload not a representation");
+bool ValidateEnrolleeBasicResponse(OCClientResponse * clientResponse)
+{
+    if (!clientResponse)
+    {
+        OIC_LOG_V(INFO, ES_PROV_TAG, "Received Null clientResponse");
         return false;
+    }
 
+    if(clientResponse->result != OC_STACK_OK)
+    {
+        OIC_LOG_V(INFO, ES_PROV_TAG, "Received error response");
+        return false;
     }
 
-    // If flow reachese here means no error condition hit.
+    // If flow reaches, then there no error condition hit.
     return true;
-
 }
 
-void SuccessCallback(OCClientResponse * clientResponse) {
+
+void SuccessCallback(OCClientResponse * clientResponse)
+{
     ProvisioningInfo *provInfo = GetCallbackObjectOnSuccess(clientResponse, DEVICE_PROVISIONED);
-    cbData(provInfo);
-    ResetProgress();
+    if(cbData != NULL)
+    {
+        cbData(provInfo);
+    }
 }
 
-void* FindProvisioningResource(void* /*data*/) {
+void* FindProvisioningResource(void* /*data*/)
+{
 
     // If user stopped the process before thread get scheduled then check and return from this function;
-    if (IsSetupStopped()) {
+    if (IsSetupStopped())
+    {
         ErrorCallback(DEVICE_NOT_PROVISIONED);
         ClearMemory();
         return NULL;
@@ -517,12 +514,11 @@ void* FindProvisioningResource(void* /*data*/) {
     ocCBData.context = (void *) EASY_SETUP_DEFAULT_CONTEXT_VALUE;
     ocCBData.cd = NULL;
 
-
     ret = OCDoResource(NULL, OC_REST_DISCOVER, gSzFindResourceQueryUri, NULL, NULL,
-                       gProvConfig->connType, OC_LOW_QOS,
-                       &ocCBData, NULL, 0);
+            gProvConfig->connType, OC_LOW_QOS, &ocCBData, NULL, 0);
 
-    if (ret != OC_STACK_OK) {
+    if (ret != OC_STACK_OK)
+    {
         ErrorCallback(DEVICE_NOT_PROVISIONED);
         ClearMemory();
     }
@@ -531,9 +527,9 @@ void* FindProvisioningResource(void* /*data*/) {
 }
 
 OCStackResult InvokeOCDoResource(const char *query, OCMethod method, const OCDevAddr *dest,
-                                 OCQualityOfService qos, OCClientResponseHandler cb,
-                                 OCRepPayload *payload,
-                                 OCHeaderOption *options, uint8_t numOptions) {
+        OCQualityOfService qos, OCClientResponseHandler cb, OCRepPayload *payload,
+        OCHeaderOption *options, uint8_t numOptions)
+{
     OCStackResult ret;
     OCCallbackData cbData;
 
@@ -542,9 +538,10 @@ OCStackResult InvokeOCDoResource(const char *query, OCMethod method, const OCDev
     cbData.cd = NULL;
 
     ret = OCDoResource(NULL, method, query, dest, (OCPayload *) payload, gProvConfig->connType, qos,
-                       &cbData, options, numOptions);
+            &cbData, options, numOptions);
 
-    if (ret != OC_STACK_OK) {
+    if (ret != OC_STACK_OK)
+    {
         OIC_LOG_V(ERROR, ES_PROV_TAG, "OCDoResource returns error %d with method %d", ret, method);
     }
 
@@ -552,8 +549,8 @@ OCStackResult InvokeOCDoResource(const char *query, OCMethod method, const OCDev
 }
 
 OCStackResult ProvisionEnrollee(OCQualityOfService qos, const char *query, const char *resUri,
-                                OCDevAddr *destination, int pauseBeforeStart) {
-
+        OCDevAddr *destination, int pauseBeforeStart)
+{
 
     // This sleep is required in case of BLE provisioning due to packet drop issue.
     OIC_LOG_V(INFO, ES_PROV_TAG, "Sleeping for %d seconds", pauseBeforeStart);
@@ -568,12 +565,13 @@ OCStackResult ProvisionEnrollee(OCQualityOfService qos, const char *query, const
 
     OIC_LOG_V(DEBUG, ES_PROV_TAG, "OCPayload ready for ProvisionEnrollee");
 
-    OCStackResult ret = InvokeOCDoResource(query, OC_REST_PUT, destination, qos,
-                                           ProvisionEnrolleeResponse, payload, NULL, 0);
+    OCStackResult ret = InvokeOCDoResource(query, OC_REST_POST, destination, qos,
+            ProvisionEnrolleeResponse, payload, NULL, 0);
 
     return ret;
 }
 
-bool IsSetupStopped() {
+bool IsSetupStopped()
+{
     return (cbData == NULL) ? true : false;
 }
old mode 100644 (file)
new mode 100755 (executable)
index 537f17a..988921e
 #include "provisioningapi.h"
 #include "oic_string.h"
 
-
 #define ES_PROV_ADAP_TAG "ES_PROVISIONING_ADAPTER"
 
 //Use ipv4addr for both InitDiscovery and InitDeviceDiscovery
-char ipv4addr[IPV4_ADDR_SIZE] = {0};
+char ipv4addr[IPV4_ADDR_SIZE] =
+{ 0 };
 
 #ifdef REMOTE_ARDUINO_ENROLEE
-    //Arduino Enrollee needs mediator application provide IP and port55555 which is specific
-    // to Arduino WiFi enrollee
-    static const char * UNICAST_PROVISIONING_QUERY = "coap://%s:%d/oic/res?rt=oic.r.prov";
+//Arduino Enrollee needs mediator application provide IP and port55555 which is specific
+// to Arduino WiFi enrollee
+static const char * UNICAST_PROVISIONING_QUERY = "coap://%s:%d/oic/res?rt=oic.r.prov";
 #else
-    static const char * UNICAST_PROVISIONING_QUERY = "/oic/res?rt=oic.r.prov";
+static const char * UNICAST_PROVISIONING_QUERY = "/oic/res?rt=oic.r.prov";
 #endif
 
 volatile static OCProvisioningStatusCB cbData = NULL;
 
-OCStackResult InitProvProcess() {
-
+OCStackResult InitProvProcess()
+{
 
     OCStackResult result = OC_STACK_ERROR;
 
-    if (InitProvisioningHandler() == OC_STACK_OK) {
+    if (InitProvisioningHandler() == OC_STACK_OK)
+    {
         result = OC_STACK_OK;
         OIC_LOG(DEBUG, ES_PROV_ADAP_TAG, "InitProvisioningHandler returned Success");
-    } else {
+    }
+    else
+    {
         result = OC_STACK_ERROR;
         OIC_LOG_V(ERROR, ES_PROV_ADAP_TAG, "InitProvisioningHandler returned error = %d",
-                  result);
+                result);
     }
 
     return result;
 }
 
-OCStackResult ResetProvProcess() {
+OCStackResult ResetProvProcess()
+{
     return TerminateProvisioningHandler();
 }
 
-OCStackResult RegisterCallback(OCProvisioningStatusCB provisioningStatusCallback) {
+OCStackResult RegisterCallback(OCProvisioningStatusCB provisioningStatusCallback)
+{
     OCStackResult result = OC_STACK_OK;
 
-    if (provisioningStatusCallback != NULL) {
+    if (provisioningStatusCallback != NULL)
+    {
         cbData = provisioningStatusCallback;
     }
-    else {
+    else
+    {
         result = OC_STACK_ERROR;
         OIC_LOG(ERROR, ES_PROV_ADAP_TAG, "provisioningStatusCallback is NULL");
     }
@@ -79,17 +86,22 @@ OCStackResult RegisterCallback(OCProvisioningStatusCB provisioningStatusCallback
     return result;
 }
 
-void UnRegisterCallback() {
-    if (cbData) {
+void UnRegisterCallback()
+{
+    if (cbData)
+    {
         cbData = NULL;
     }
 }
 
-OCStackResult StartProvisioning(const ProvConfig *provConfig, WiFiOnboadingConnection *onboardConn) {
+OCStackResult StartProvisioning(const ProvConfig *provConfig, WiFiOnboadingConnection *onboardConn)
+{
 
-    char findQuery[64] = {0};
+    char findQuery[64] =
+    { 0 };
 
-    if(provConfig == NULL || onboardConn == NULL){
+    if (provConfig == NULL || onboardConn == NULL)
+    {
         return OC_STACK_ERROR;
     }
 
@@ -97,15 +109,16 @@ OCStackResult StartProvisioning(const ProvConfig *provConfig, WiFiOnboadingConne
     //Arduino Enrollee needs mediator application provide IP and port55555 which is specific
     // to Arduino WiFi enrollee
     snprintf(findQuery, sizeof(findQuery) - 1, UNICAST_PROVISIONING_QUERY,
-             onboardConn->ipAddress, IP_PORT);
+            onboardConn->ipAddress, IP_PORT);
 #else
-    OICStrcpy(findQuery, sizeof(findQuery)-1, UNICAST_PROVISIONING_QUERY);
+    OICStrcpy(findQuery, sizeof(findQuery) - 1, UNICAST_PROVISIONING_QUERY);
 #endif
 
     return StartProvisioningProcess(provConfig, onboardConn, cbData, findQuery);
 }
 
-OCStackResult StopProvisioning(OCConnectivityType /*connectivityType*/) {
+OCStackResult StopProvisioning(OCConnectivityType /*connectivityType*/)
+{
     OCStackResult result = OC_STACK_OK;
 
     StopProvisioningProcess();
old mode 100644 (file)
new mode 100755 (executable)
index 5a056ea..d8d40fe
 
 // External includes
 #include "logger.h"
+#include "oic_string.h"
 
 #define ES_WIFI_PROV_TAG "ES_WIFI_PROVISIONING"
 
 static const char * UNICAST_PROV_STATUS_QUERY = "coap://%s:%d%s";
 
-OCStackApplicationResult GetProvisioningStatusResponse(void* /*ctx*/,
-                                                        OCDoHandle /*handle*/,
-                                                        OCClientResponse *clientResponse) {
+OCStackApplicationResult ProvisionEnrolleeResponse(void* /*ctx*/, OCDoHandle /*handle*/,
+        OCClientResponse *clientResponse)
+{
+    OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "Inside ProvisionEnrolleeResponse");
 
+    // If user stopped the process then return from this function;
+    if (IsSetupStopped())
+    {
+        ErrorCallback(DEVICE_NOT_PROVISIONED);
+        ClearMemory();
+        return OC_STACK_DELETE_TRANSACTION;
+    }
+
+    if (!ValidateEnrolleeResponse(clientResponse))
+    {
+        ErrorCallback(DEVICE_NOT_PROVISIONED);
+        return OC_STACK_DELETE_TRANSACTION;
+    }
+
+    char query[OIC_STRING_MAX_VALUE] =
+    { '\0' };
+    char resUri[MAX_URI_LENGTH] =
+    { '\0' };
 
+    OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "Resource URI = %s", clientResponse->resourceUri);
+
+    OICStrcpy(resUri, sizeof(resUri), clientResponse->resourceUri);
+
+#ifdef REMOTE_ARDUINO_ENROLEE
+    //Arduino Enrollee needs mediator application provide IP and port55555 which is specific
+    // to Arduino WiFi enrollee
+    // REMOTE_ARDUINO_ENROLEE has to be defined if Mediator is being tested with Arduino
+    snprintf(query, sizeof(query), UNICAST_PROV_STATUS_QUERY, clientResponse->addr->addr, IP_PORT,
+            resUri);
+#else
+    snprintf(query, sizeof(query), UNICAST_PROV_STATUS_QUERY, clientResponse->addr->addr,
+            clientResponse->addr->port, resUri);
+#endif
+
+    if (TriggerNetworkConnection(OC_HIGH_QOS, query, OC_RSRVD_ES_URI_PROV, clientResponse->addr, 0)
+            != OC_STACK_OK)
+    {
+        OIC_LOG(INFO, ES_WIFI_PROV_TAG, "GetProvisioningStatusResponse received NULL clientResponse");
+
+        ErrorCallback(DEVICE_NOT_PROVISIONED);
+        ClearMemory();
+    }
+
+    return OC_STACK_DELETE_TRANSACTION;
+}
+
+OCStackApplicationResult GetProvisioningStatusResponse(void* /*ctx*/, OCDoHandle /*handle*/,
+        OCClientResponse *clientResponse)
+{
     // If user stopped the process then return from this function;
-    if (IsSetupStopped()) {
+    if (IsSetupStopped())
+    {
         ErrorCallback(DEVICE_NOT_PROVISIONED);
         ClearMemory();
         return OC_STACK_DELETE_TRANSACTION;
     }
 
-    if (!ValidateEnrolleResponse(clientResponse)) {
+    if (!ValidateEnrolleeResponse(clientResponse))
+    {
         ErrorCallback(DEVICE_NOT_PROVISIONED);
         ClearMemory();
         return OC_STACK_DELETE_TRANSACTION;
     }
 
-    OCRepPayload *input = (OCRepPayload * )(clientResponse->payload);
+    OCRepPayload *input = (OCRepPayload *(clientResponse->payload);
 
-    char query[OIC_STRING_MAX_VALUE] =
-            {'\0'};
-    char resURI[MAX_URI_LENGTH] =
-            {'\0'};
+    char resUri[MAX_URI_LENGTH] = { '\0' };
 
-    OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "resUri = %s", input->uri);
+    OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "resUri = %s", clientResponse->resourceUri);
 
-    strncpy(resURI, input->uri, sizeof(resURI) - 1);
+    OICStrcpy(resUri, sizeof(resUri), clientResponse->resourceUri);
 
+    while (input)
+    {
+        int64_t ps;
+        if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_PS, &ps))
+        {
+
+            if (ps == ES_PS_NEED_PROVISIONING)
+            {
+                input = input->next;
+                continue;
+            }
+            else
+            {
+                ErrorCallback(DEVICE_NOT_PROVISIONED);
+                ClearMemory();
+                return OC_STACK_DELETE_TRANSACTION;
+            }
+        }
+
+        LogProvisioningResponse(input->values);
+        input = input->next;
+    }
+
+    char query[OIC_STRING_MAX_VALUE] =
+    { '\0' };
 
 #ifdef REMOTE_ARDUINO_ENROLEE
     //Arduino Enrollee needs mediator application provide IP and port55555 which is specific
     // to Arduino WiFi enrollee
     // REMOTE_ARDUINO_ENROLEE has to be defined if Mediator is being tested with Arduino
     snprintf(query, sizeof(query), UNICAST_PROV_STATUS_QUERY, clientResponse->addr->addr, IP_PORT,
-            resURI);
+            resUri);
 #else
     snprintf(query, sizeof(query), UNICAST_PROV_STATUS_QUERY, clientResponse->addr->addr,
-            clientResponse->addr->port,
-            resURI);
+            clientResponse->addr->port, resUri);
 #endif
 
-
     if (ProvisionEnrollee(OC_HIGH_QOS, query, OC_RSRVD_ES_URI_PROV, clientResponse->addr, 0)
-        != OC_STACK_OK) {
+            != OC_STACK_OK)
+    {
         OIC_LOG(INFO, ES_WIFI_PROV_TAG, "GetProvisioningStatusResponse received NULL clientResponse");
 
         ErrorCallback(DEVICE_NOT_PROVISIONED);
@@ -98,16 +171,17 @@ OCStackApplicationResult GetProvisioningStatusResponse(void* /*ctx*/,
 }
 
 OCStackResult GetProvisioningStatus(OCQualityOfService qos, const char *query,
-                                    const OCDevAddr *destination) {
+        const OCDevAddr *destination)
+{
     OCStackResult ret = OC_STACK_ERROR;
     OCHeaderOption options[MAX_HEADER_OPTIONS];
 
-    OIC_LOG_V(INFO, ES_WIFI_PROV_TAG, "\n\nExecuting %s", __func__);
+    OIC_LOG(DEBUG, ES_WIFI_PROV_TAG, "Inside GetProvisioningStatus");
 
     uint8_t option0[] =
-            {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
+    { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
     uint8_t option1[] =
-            {11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
+    { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
     memset(options, 0, sizeof(OCHeaderOption) * MAX_HEADER_OPTIONS);
     options[0].protocolID = OC_COAP_ID;
     options[0].optionID = 2048;
@@ -118,35 +192,37 @@ OCStackResult GetProvisioningStatus(OCQualityOfService qos, const char *query,
     memcpy(options[1].optionData, option1, sizeof(option1));
     options[1].optionLength = 10;
 
-    ret = InvokeOCDoResource(query, OC_REST_GET, destination, qos,
-                             GetProvisioningStatusResponse, NULL, options, 2);
+    ret = InvokeOCDoResource(query, OC_REST_GET, destination, qos, GetProvisioningStatusResponse,
+    NULL, options, 2);
     return ret;
 }
 
-
 // This is a function called back when a device is discovered
-OCStackApplicationResult FindProvisioningResourceResponse(void* /*ctx*/,
-                                                            OCDoHandle /*handle*/,
-                                                            OCClientResponse *clientResponse) {
+OCStackApplicationResult FindProvisioningResourceResponse(void* /*ctx*/, OCDoHandle /*handle*/,
+        OCClientResponse *clientResponse)
+{
 
     OIC_LOG_V(INFO, ES_WIFI_PROV_TAG, "Entering FindProvisioningResourceResponse %s",
             clientResponse->devAddr.addr);
 
     // If user stopped the process then return from this function;
-    if (IsSetupStopped()) {
+    if (IsSetupStopped())
+    {
         ErrorCallback(DEVICE_NOT_PROVISIONED);
         ClearMemory();
         return OC_STACK_DELETE_TRANSACTION;
     }
 
-    if (!ValidateFinddResourceResponse(clientResponse)) {
+    if (!ValidateFindResourceResponse(clientResponse))
+    {
         ErrorCallback(DEVICE_NOT_PROVISIONED);
         return OC_STACK_DELETE_TRANSACTION;
     }
 
-    char szQueryUri[64] = {0};
+    char szQueryUri[64] =
+    { 0 };
 
-    OCDiscoveryPayload *discoveryPayload = (OCDiscoveryPayload * )(clientResponse->payload);
+    OCDiscoveryPayload *discoveryPayload = (OCDiscoveryPayload *(clientResponse->payload);
 
     OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "resUri = %s", discoveryPayload->resources->uri);
 
@@ -155,19 +231,19 @@ OCStackApplicationResult FindProvisioningResourceResponse(void* /*ctx*/,
     // to Arduino WiFi enrollee
     // REMOTE_ARDUINO_ENROLEE has to be defined if Mediator is being tested with Arduino
     snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_PROV_STATUS_QUERY,
-             clientResponse->addr->addr,
-             IP_PORT,
-             discoveryPayload->resources->uri);
+            clientResponse->addr->addr,
+            IP_PORT,
+            discoveryPayload->resources->uri);
 #else
     snprintf(szQueryUri, sizeof(szQueryUri), UNICAST_PROV_STATUS_QUERY,
-             clientResponse->devAddr.addr,
-             clientResponse->devAddr.port,
-             discoveryPayload->resources->uri);
+            clientResponse->devAddr.addr, clientResponse->devAddr.port,
+            discoveryPayload->resources->uri);
 #endif
 
     OIC_LOG_V(DEBUG, ES_WIFI_PROV_TAG, "query before GetProvisioningStatus call = %s", szQueryUri);
 
-    if (GetProvisioningStatus(OC_HIGH_QOS, szQueryUri, &clientResponse->devAddr) != OC_STACK_OK) {
+    if (GetProvisioningStatus(OC_HIGH_QOS, szQueryUri, &clientResponse->devAddr) != OC_STACK_OK)
+    {
         ErrorCallback(DEVICE_NOT_PROVISIONED);
         return OC_STACK_DELETE_TRANSACTION;
     }
@@ -176,16 +252,18 @@ OCStackApplicationResult FindProvisioningResourceResponse(void* /*ctx*/,
 
 }
 
-bool ValidateEasySetupParams(const ProvConfig *netInfo,WiFiOnboadingConnection *onboardConn,
-                             OCProvisioningStatusCB provisioningStatusCallback) {
-
+bool ValidateEasySetupParams(const ProvConfig */*netInfo*/, WiFiOnboadingConnection *onboardConn,
+        OCProvisioningStatusCB provisioningStatusCallback)
+{
 
-    if (onboardConn == NULL || strlen(onboardConn->ipAddress) == 0) {
+    if (onboardConn == NULL || strlen(onboardConn->ipAddress) == 0)
+    {
         OIC_LOG(ERROR, ES_WIFI_PROV_TAG, "Request URI is NULL");
         return false;
     }
 
-    if (provisioningStatusCallback == NULL) {
+    if (provisioningStatusCallback == NULL)
+    {
         OIC_LOG(ERROR, ES_WIFI_PROV_TAG, "ProvisioningStatusCallback is NULL");
         return false;
     }
@@ -194,5 +272,3 @@ bool ValidateEasySetupParams(const ProvConfig *netInfo,WiFiOnboadingConnection *
 
 }
 
-
-
old mode 100644 (file)
new mode 100755 (executable)
index 95a61e1..e9e344b
@@ -66,6 +66,8 @@ using namespace std;
  */
 #define ES_PS_NEED_PROVISIONING         1
 #define ES_PS_PROVISIONING_COMPLETED    2
+#define ES_PS_TRIGGER_INIT_VALUE        0
+#define ES_PS_TRIGGER_CONNECTION        1
 
 #ifndef WITH_ARDUINO
 namespace OIC
old mode 100644 (file)
new mode 100755 (executable)
index 62cd648..019a514
@@ -118,6 +118,12 @@ namespace OIC
             ESResult ESDiscoveryTimeout(unsigned short waittime);
 
             void onDeviceDiscovered(std::shared_ptr<OC::OCResource> resource);
+
+            void triggerNetworkConnection();
+
+            void triggerNetworkConnectionCb(
+                    const HeaderOptions& headerOptions, const OCRepresentation& rep,
+                    const int eCode);
         };
     }
 }
index 43673e4..1a6a1ae 100755 (executable)
@@ -47,6 +47,54 @@ namespace OIC
             m_discoveryResponse = false;
         }
 
+        void RemoteEnrolleeResource::triggerNetworkConnectionCb(
+                const HeaderOptions& /*headerOptions*/, const OCRepresentation& rep,
+                const int eCode)
+        {
+            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "checkProvInformationCb : %s, eCode = %d",
+                    rep.getUri().c_str(),
+                    eCode);
+
+            if (eCode != 0)
+            {
+                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
+                        "triggerNetworkConnectionCb : Trigger action failed ");
+                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
+                        ProvisioningStatus >(ESResult::ES_ERROR, ESState::ES_PROVISIONING_ERROR);
+                m_provStatusCb(provStatus);
+                return;
+            }
+            else
+            {
+                OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
+                        "triggerNetworkConnectionCb : Provisioning is success ");
+                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
+                        ProvisioningStatus >(ESResult::ES_OK, ESState::ES_PROVISIONING_SUCCESS);
+                m_provStatusCb(provStatus);
+                return;
+            }
+        }
+
+        void RemoteEnrolleeResource::triggerNetworkConnection()
+        {
+            if (m_ocResource == nullptr)
+            {
+                throw ESBadRequestException("Resource is not initialized");
+            }
+
+            OCRepresentation provisioningRepresentation;
+
+            provisioningRepresentation.setValue(OC_RSRVD_ES_TR, 1);
+
+            m_ocResource->post(provisioningRepresentation, QueryParamsMap(),
+                    std::function<
+                            void(const HeaderOptions& headerOptions, const OCRepresentation& rep,
+                                    const int eCode) >(
+                            std::bind(&RemoteEnrolleeResource::triggerNetworkConnectionCb, this,
+                                    std::placeholders::_1, std::placeholders::_2,
+                                    std::placeholders::_3)));
+        }
+
         void RemoteEnrolleeResource::checkProvInformationCb(const HeaderOptions& /*headerOptions*/,
                 const OCRepresentation& rep, const int eCode)
         {
@@ -65,51 +113,19 @@ namespace OIC
             }
 
             int ps = -1;
-            std::string tnn = "";
-            std::string cd = "";
 
             rep.getValue(OC_RSRVD_ES_PS, ps);
-            rep.getValue(OC_RSRVD_ES_TNN, tnn);
-            rep.getValue(OC_RSRVD_ES_CD, cd);
 
             OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "checkProvInformationCb : ps - %d", ps);
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                    "checkProvInformationCb : tnn - %s", tnn.c_str());
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                    "checkProvInformationCb : cd - %s", cd.c_str());
 
             //Provisioning status check
             if (ps == ES_PS_PROVISIONING_COMPLETED)
             {
-                if (tnn != std::string(m_ProvConfig.provData.WIFI.ssid))
-                {
-                    OIC_LOG_V (ERROR, ES_REMOTE_ENROLLEE_RES_TAG,
-                            "checkProvInformationCb : Network SSID is not the same as the "
-                            "SSID provisioned");
-                    std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
-                            ProvisioningStatus >(ESResult::ES_ERROR,
-                            ESState::ES_PROVISIONING_ERROR);
-                    m_provStatusCb(provStatus);
-                    return;
-                }
-
-                if (cd != std::string(m_ProvConfig.provData.WIFI.pwd))
-                {
-                    OIC_LOG_V (ERROR, ES_REMOTE_ENROLLEE_RES_TAG,
-                            "checkProvInformationCb : Network PWD is not the same as the "
-                            "PWD provisioned");
-                    std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
-                            ProvisioningStatus >(ESResult::ES_ERROR,
-                            ESState::ES_PROVISIONING_ERROR);
-                    m_provStatusCb(provStatus);
-                    return;
-                }
-
                 OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG,
-                        "checkProvInformationCb : Provisioning is success ");
-                std::shared_ptr< ProvisioningStatus > provStatus = std::make_shared<
-                        ProvisioningStatus >(ESResult::ES_OK, ESState::ES_PROVISIONING_SUCCESS);
-                m_provStatusCb(provStatus);
+                        "checkProvInformationCb : Provisioning is success. "
+                        "Now trigger network connection ");
+
+                triggerNetworkConnection();
                 return;
             }
             else
@@ -141,19 +157,11 @@ namespace OIC
             }
 
             int ps = -1;
-            std::string tnn = "";
-            std::string cd = "";
 
             rep.getValue(OC_RSRVD_ES_PS, ps);
-            rep.getValue(OC_RSRVD_ES_TNN, tnn);
-            rep.getValue(OC_RSRVD_ES_CD, cd);
 
             OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : ps - %d",
                     ps);
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : tnn - %s",
-                    tnn.c_str());
-            OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : cd - %s",
-                    cd.c_str());
 
             if (ps == ES_PS_NEED_PROVISIONING) //Indicates the need for provisioning
             {
@@ -169,7 +177,7 @@ namespace OIC
                 OIC_LOG_V (DEBUG, ES_REMOTE_ENROLLEE_RES_TAG, "getProvStatusResponse : pwd - %s",
                         m_ProvConfig.provData.WIFI.pwd);
 
-                m_ocResource->put(provisioningRepresentation, QueryParamsMap(),
+                m_ocResource->post(provisioningRepresentation, QueryParamsMap(),
                         std::function<
                                 void(const HeaderOptions& headerOptions,
                                         const OCRepresentation& rep, const int eCode) >(
old mode 100644 (file)
new mode 100755 (executable)
index 27678dd..31ae79d
@@ -73,7 +73,7 @@ int main(int argc, char **argv) {
     InitProvProcess();
 
 
-    RegisterCallback(ProvisioningStatusCallback);
+    RegisterCallback(&ProvisioningStatusCallback);
 
     while ((opt = getopt(argc, argv, "d:s:p:")) != -1) {
         switch (opt) {
@@ -102,6 +102,16 @@ int main(int argc, char **argv) {
 
     signal(SIGINT, handleSigInt);
     while (!quitFlag) {
+        OCStackResult result;
+
+        result = OCProcess();
+
+        if (result != OC_STACK_OK)
+        {
+            OIC_LOG(ERROR, "Mediator_CSDK", "OCStack stop error");
+        }
+
+        // To minimize CPU utilization we may wish to do this with sleep
         sleep(1);
     }
 
index a1696c1..32adbd3 100755 (executable)
@@ -96,20 +96,10 @@ void initEasySetup()
     easySetupIntance = EasySetup::getInstance();
 
     ipaddress = "192.168.1.104";
-    //std::cout << "Enter the target enrollee ipv4 address ";
-
-
     ssid = "hub2.4G";
-    //std::cout << "Enter the ssid of the target Enrolleer ";
-    //std:: cin >> ssid;
-
     pwd = "22221111";
-    //std::cout << "Enter the pwd of the target Enrolleer ";
-    //std::cin >> pwd;
 
     netInfo.connType = CT_ADAPTER_IP;
-    //netInfo.isSecured = false;
-    //netInfo.needSecuredEasysetup = false;
 
     OICStrcpy(netInfo.provData.WIFI.ssid, NET_WIFI_SSID_SIZE - 1, ssid.c_str());
     OICStrcpy(netInfo.provData.WIFI.pwd, NET_WIFI_PWD_SIZE - 1, pwd.c_str());
@@ -117,7 +107,6 @@ void initEasySetup()
     onboardingConn.isSecured = false;
     OICStrcpy(onboardingConn.ipAddress, IPV4_ADDR_SIZE - 1, ipaddress.c_str());
 
-
     try
     {
         remoteEnrollee = easySetupIntance->createEnrolleeDevice(netInfo,onboardingConn);