[Enrollee] Implement ESInitEnrollee() API
authorsy01.youn <sy01.youn@samsung.com>
Thu, 23 Jun 2016 07:49:33 +0000 (16:49 +0900)
committerMadan Lanka <lanka.madan@samsung.com>
Mon, 27 Jun 2016 06:38:27 +0000 (06:38 +0000)
1. Add new data structure
  : ResourceMask, ESProvisioningCallbacks, ESWiFiProvData, ESDevConfProvData, ESCloudProvData
2. Update ResourceHandler's post handling
  : update wifi data, dev conf data, cloud prov data which are delivered to easysetup callback

* Need to develop sample app. (enrollee side)
* Need to erase unused code

Change-Id: Iaae6776f476566b9fd3dd0d883843d131d755630
Signed-off-by: sy01.youn <sy01.youn@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8805
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/easy-setup/enrollee/inc/easysetup.h
service/easy-setup/enrollee/src/easysetup.c
service/easy-setup/enrollee/src/resourcehandler.c
service/easy-setup/enrollee/src/resourcehandler.h
service/easy-setup/inc/escommon.h
service/easy-setup/sampleapp/enrollee/linux/enrolleewifi.c

index 00102a9..f80ffa0 100755 (executable)
@@ -42,27 +42,28 @@ extern "C" {
  */
 typedef void (*ESEnrolleeEventCallback)(ESResult esResult, ESEnrolleeState enrolleeState);
 
+
+
+typedef struct
+{
+    void (*WiFiProvCb) (ESWiFiProvData *);
+    void (*DevConfProvCb) (ESDevConfProvData *);
+    void (*CloudDataProvCb) (ESCloudProvData *);
+} ESProvisioningCallbacks;
+
 /**
  * This function Initializes the EasySetup. This API must be called prior to invoking any other API
  *
- * @param networkType       NetworkType on which OnBoarding has to be performed.
- * @param ssid              SSID of the target SoftAP network to which the Enrollee is connecting.
- * @param passwd            Password of the target SoftAP network to which the Enrollee is
- *                          connecting
  * @param isSecured         True if the Enrollee is operating in secured mode.
- * @param eventCallback     ESEnrolleeEventCallback for for updating the Enrollee OnBoarding status
- *                          result to the application
+ * @param resourceMask      Provisining Resource Type which application wants to make
+ *                          ES_WIFI_RESOURCE = 0x01,
+ *                          ES_CLOUD_RESOURCE = 0x02,
+ *                          ES_DEVCONF_RESOURCE = 0x04
+ * @param callbacks         ESProvisioningCallbacks for updating Provisioning Resources' data to the application
  * @return ::ES_OK on success, some other value upon failure.
  */
-ESResult ESInitEnrollee(OCConnectivityType networkType, const char *ssid, const char *passwd,
-                                bool isSecured, ESEnrolleeEventCallback eventCallback);
+ESResult ESInitEnrollee(bool isSecured, ESResourceMask resourceMask, ESProvisioningCallbacks callbacks);
 
-/**
- * This function performs initialization of Provisioning and Network resources needed for EasySetup
- * process.
- * @return ::ES_OK on success, some other value upon failure.
- */
-ESResult ESInitProvisioning();
 
 /**
  * This function performs termination of Provisioning and Network resources.
index 35984ce..032416d 100755 (executable)
@@ -25,8 +25,6 @@
  */
 
 #include "easysetup.h"
-//#include "softap.h"
-//#include "onboarding.h"
 #include "logger.h"
 #include "resourcehandler.h"
 #include "easysetupcallbacks.h"
 //-----------------------------------------------------------------------------
 // Private variables
 //-----------------------------------------------------------------------------
+static bool gIsSecured = false;
 
-/**
- * @var gTargetSsid
- * @brief Target SSID of the Soft Access point to which the device has to connect
- */
-static char gTargetSsid[MAXSSIDLEN];
+static ESProvisioningCallbacks gESProvisioningCb;
 
-/**
- * @var gTargetPass
- * @brief Password of the target access point to which the device has to connect
- */
-static char gTargetPass[MAXNETCREDLEN];
-
-/**
- * @var gEnrolleeStatusCb
- * @brief Fucntion pointer holding the callback for intimation of EasySetup Enrollee status callback
- */
-static ESEnrolleeEventCallback gEnrolleeStatusCb = NULL;
+void ESWiFiRsrcCallback(ESResult esResult, ESWiFiProvData *eventData)
+{
+    OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESWiFiRsrcCallback IN");
 
-/**
- * @var gIsSecured
- * @brief Variable to check if secure mode is enabled or not.
- */
-static bool gIsSecured = false;
+    if(esResult != ES_OK)
+    {
+        OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "ESWiFiRsrcCallback Error Occured");
+        return;
+    }
 
-void ESOnboardingCallback(ESResult esResult)
-{
-        OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESOnboardingCallback with  result = %d", esResult);
-        if(esResult == ES_OK)
-        {
-            gEnrolleeStatusCb(esResult, ES_ON_BOARDED_STATE);
-        }
-        else
-        {
-            OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG,
-                        "Onboarding is failed callback result is = %d", esResult);
-            gEnrolleeStatusCb(esResult, ES_INIT_STATE);
-        }
+    // deliver data to ESProvisioningCallbacks
+    if(gESProvisioningCb.WiFiProvCb != NULL)
+    {
+        gESProvisioningCb.WiFiProvCb(eventData);
+    }
+    else
+    {
+        OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "WiFiProvCb is NULL");
+        return;
+    }
 }
 
-void ESProvisioningCallback(ESResult esResult)
+void ESCloudRsrcCallback(ESResult esResult, ESCloudProvData *eventData)
 {
-    OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESProvisioningCallback with  result = %d", esResult);
+    OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESCloudRsrcCallback IN");
 
-    if (esResult == ES_RECVTRIGGEROFPROVRES)
+    if(esResult != ES_OK)
     {
-        GetTargetNetworkInfoFromProvResource(gTargetSsid, gTargetPass);
-        gEnrolleeStatusCb(ES_OK, ES_PROVISIONED_STATE);
-        OIC_LOG(DEBUG, ES_ENROLLEE_TAG, "Connecting with target network");
+        OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "ESCloudRsrcCallback Error Occured");
+        return;
+    }
 
-        // Connecting/onboarding to target network
-        //ConnectToWiFiNetwork(gTargetSsid, gTargetPass, ESOnboardingCallbackTargetNet);
+    if(gESProvisioningCb.CloudDataProvCb != NULL)
+    {
+        gESProvisioningCb.CloudDataProvCb(eventData);
     }
     else
     {
-       OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "Provisioning is failed callback result is = %d", esResult);
-       // Resetting Enrollee to ONBOARDED_STATE as Enrollee is alreday onboarded in previous step
-       gEnrolleeStatusCb(ES_OK, ES_ON_BOARDED_STATE);
+        OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "CloudDataProvCb is NULL");
+        return;
     }
 }
 
-void ESOnboardingCallbackTargetNet(ESResult esResult)
+void ESDevconfRsrcallback(ESResult esResult, ESDevConfProvData *eventData)
 {
-    OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESOnboardingCallback on target network with result = %d",
-                                                                                        esResult);
-    if(esResult == ES_OK)
+    OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG, "ESDevconfRsrcallback IN");
+
+    if(esResult != ES_OK)
+    {
+        OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "ESDevconfRsrcallback Error Occured");
+        return;
+    }
+
+    if(gESProvisioningCb.DevConfProvCb != NULL)
     {
-        gEnrolleeStatusCb(esResult, ES_ON_BOARDED_TARGET_NETWORK_STATE);
+        gESProvisioningCb.DevConfProvCb(eventData);
     }
     else
     {
-        OIC_LOG_V(DEBUG, ES_ENROLLEE_TAG,
-                    "Onboarding is failed on target network and callback result is = %d", esResult);
-        // Resetting Enrollee state to the ES_PROVISIONED_STATE
-        // as device is already being provisioned with target network creds.
-        gEnrolleeStatusCb(esResult, ES_PROVISIONED_STATE);
+        OIC_LOG_V(ERROR, ES_ENROLLEE_TAG, "DevConfProvCb is NULL");
+        return;
     }
 }
 
-ESResult ESInitEnrollee(OCConnectivityType networkType, const char *ssid, const char *passwd,
-        bool isSecured,
-        ESEnrolleeEventCallback cb)
+ESResult ESInitEnrollee(bool isSecured, ESResourceMask resourceMask, ESProvisioningCallbacks callbacks)
 {
     OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESInitEnrollee IN");
-    if(!ESEnrolleeValidateParam(networkType,ssid,passwd,cb))
-    {
-        OIC_LOG(ERROR, ES_ENROLLEE_TAG,
-                            "ESInitEnrollee::Stopping Easy setup due to invalid parameters");
-        return ES_ERROR;
-    }
-
-    //Init callback
-    gEnrolleeStatusCb = cb;
 
     gIsSecured = isSecured;
 
-    // TODO : This onboarding state has to be set by lower layer, as they better
-    // knows when actually on-boarding started.
-    cb(ES_ERROR,ES_ON_BOARDING_STATE);
-
-    /*
-    OIC_LOG(INFO, ES_ENROLLEE_TAG, "received callback");
-    OIC_LOG(INFO, ES_ENROLLEE_TAG, "onboarding now..");
+    if((resourceMask & ES_WIFI_RESOURCE) == ES_WIFI_RESOURCE)
+    {
+        if(callbacks.WiFiProvCb != NULL)
+        {
+            gESProvisioningCb.WiFiProvCb = callbacks.WiFiProvCb;
+            RegisterWifiRsrcEventCallBack(ESWiFiRsrcCallback);
+        }
+        else
+        {
+            OIC_LOG(ERROR, ES_ENROLLEE_TAG, "WiFiProvCb NULL");
+            return ES_ERROR;
+        }
+    }
+    if((resourceMask & ES_DEVCONF_RESOURCE) == ES_DEVCONF_RESOURCE)
+    {
+        if(callbacks.DevConfProvCb != NULL)
+        {
+            gESProvisioningCb.DevConfProvCb = callbacks.DevConfProvCb;
+            RegisterDevConfRsrcEventCallBack(ESDevconfRsrcallback);
+        }
+        else
+        {
+            OIC_LOG(ERROR, ES_ENROLLEE_TAG, "DevConfProvCb NULL");
+            return ES_ERROR;
+        }
+    }
+    if((resourceMask & ES_CLOUD_RESOURCE) == ES_CLOUD_RESOURCE)
+    {
+        if(callbacks.DevConfProvCb != NULL)
+        {
+            gESProvisioningCb.CloudDataProvCb = callbacks.CloudDataProvCb;
+            RegisterCloudRsrcEventCallBack(ESCloudRsrcCallback);
+        }
+        else
+        {
+            OIC_LOG(ERROR, ES_ENROLLEE_TAG, "CloudDataProvCb NULL");
+            return ES_ERROR;
+        }
+    }
 
-    if(!ESOnboard(ssid, passwd, ESOnboardingCallback))
+    if(CreateEasySetupResources(gIsSecured, resourceMask) != OC_STACK_OK)
     {
-        OIC_LOG(ERROR, ES_ENROLLEE_TAG, "ESInitEnrollee::On-boarding failed");
-        cb(ES_ERROR, ES_INIT_STATE);
+        // TODO : Error Handling
         return ES_ERROR;
     }
-    */
+
 
     OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESInitEnrollee OUT");
     return ES_OK;
@@ -171,22 +178,6 @@ ESResult ESTerminateEnrollee()
     return ES_OK;
 }
 
-ESResult ESInitProvisioning()
-{
-    OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESInitProvisioning <<IN>>");
-
-    if (CreateEasySetupResources(gIsSecured) != OC_STACK_OK)
-    {
-        OIC_LOG(ERROR, ES_ENROLLEE_TAG, "CreateProvisioningResource error");
-        return ES_ERROR;
-    }
-
-    RegisterResourceEventCallBack(ESProvisioningCallback);
-
-    OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESInitProvisioning <<OUT>>");
-    return ES_RESOURCECREATED;
-}
-
 static bool ESEnrolleeValidateParam(OCConnectivityType networkType, const char *ssid,
                                                 const char *passwd, ESEnrolleeEventCallback cb)
 {
index aab3e3b..5038c69 100755 (executable)
@@ -44,6 +44,28 @@ static WiFiResource gWiFiResource;
 static CloudResource gCloudResource;
 static DevConfResource gDevConfResource;
 
+/**
+ * @var gWiFiData
+ * @brief Structure for holding the target information required to
+ * connect to the target network
+ */
+ static ESWiFiProvData gWiFiData;
+
+/**
+ * @var gDevConfData
+ * @brief Structure for holding the device information
+ */
+ static ESDevConfProvData gDevConfData;
+
+/**
+ * @var gCloudData
+ * @brief Structure for holding the cloud information required to
+ * connect to CI Server
+ */
+ static ESCloudProvData gCloudData;
+
+
+
 //-----------------------------------------------------------------------------
 // Private internal function prototypes
 //-----------------------------------------------------------------------------
@@ -54,22 +76,42 @@ OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRep
 OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
 OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload** payload);
 void updateProvResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
-void updateWiFiResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
-void updateCloudResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
-void updateDevConfResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input);
+void updateWiFiResource(OCRepPayload* input);
+void updateCloudResource(OCRepPayload* input);
+void updateDevConfResource(OCRepPayload* input);
 
-ESEnrolleeResourceEventCallback gNetworkInfoProvEventCb = NULL;
+ESWiFiCB gWifiRsrcEvtCb = NULL;
+ESCloudCB gCloudRsrcEvtCb = NULL;
+ESDevConfCB gDevConfRsrcEvtCb = NULL;
 
-void RegisterResourceEventCallBack(ESEnrolleeResourceEventCallback cb)
+void RegisterWifiRsrcEventCallBack(ESWiFiCB cb)
 {
-    gNetworkInfoProvEventCb = cb;
+    gWifiRsrcEvtCb = cb;
+}
+
+void RegisterCloudRsrcEventCallBack(ESCloudCB cb)
+{
+    gCloudRsrcEvtCb = cb;
+}
+
+void RegisterDevConfRsrcEventCallBack(ESDevConfCB cb)
+{
+    gDevConfRsrcEvtCb = cb;
 }
 
 void UnRegisterResourceEventCallBack()
 {
-    if (gNetworkInfoProvEventCb)
+    if (gWifiRsrcEvtCb)
     {
-        gNetworkInfoProvEventCb = NULL;
+        gWifiRsrcEvtCb = NULL;
+    }
+    if (gCloudRsrcEvtCb)
+    {
+        gCloudRsrcEvtCb = NULL;
+    }
+    if (gDevConfRsrcEvtCb)
+    {
+        gDevConfRsrcEvtCb = NULL;
     }
 }
 
@@ -212,104 +254,151 @@ OCStackResult initDevConfResource(bool isSecured)
 
 }
 
-void updateProvResource(OCEntityHandlerRequest *ehRequest, OCRepPayload* input)
+void updateProvResource(OCEntityHandlerRequestehRequest, OCRepPayload* input)
 {
     OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.status %lld", gProvResource.status);
-    bool trigger;
-    if (OCRepPayloadGetPropBool(input, OC_RSRVD_ES_TRIGGER, &trigger))
-    {
-        // Triggering
-        gProvResource.trigger = trigger;
-    }
 
     if(ehRequest->query)
     {
         if(strstr(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
-        {// When Provisioning resource has a POST with BatchInterface
-            updateCloudResource(ehRequest, input);
-            updateWiFiResource(ehRequest, input);
-            updateDevConfResource(ehRequest, input);
+        {
+        // When Provisioning resource has a POST with BatchInterface
+            updateCloudResource(input);
+            updateWiFiResource(input);
+            updateDevConfResource(input);
         }
     }
 }
 
-void updateWiFiResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
+void updateWiFiResource(OCRepPayload* input)
 {
-    (void) ehRequest;
-    char* ssid;
+    char* ssid = NULL;
     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_SSID, &ssid))
     {
         OICStrcpy(gWiFiResource.ssid, sizeof(gWiFiResource.ssid), ssid);
-        OIC_LOG(INFO, ES_RH_TAG, "got ssid");
+        OICStrcpy(gWiFiData.ssid, sizeof(gWiFiData.ssid), ssid);
+        OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.ssid : %s", gWiFiResource.ssid);
     }
 
-    char* cred;
+    char* cred = NULL;
     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CRED, &cred))
     {
         OICStrcpy(gWiFiResource.cred, sizeof(gWiFiResource.cred), cred);
+        OICStrcpy(gWiFiData.pwd, sizeof(gWiFiData.pwd), cred);
         OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.cred %s", gWiFiResource.cred);
     }
 
-    int64_t authType;
+    int64_t authType = -1;
     if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_AUTHTYPE, &authType))
     {
         gWiFiResource.authType = authType;
+        gWiFiData.authtype = gWiFiResource.authType;
         OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.authType %u", gWiFiResource.authType);
     }
 
-    int64_t encType;
+    int64_t encType = -1;
     if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_ENCTYPE, &encType))
     {
         gWiFiResource.encType = encType;
+        gWiFiData.enctype = gWiFiResource.encType;
         OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.encType %u", gWiFiResource.encType);
     }
+
+    if(ssid || cred || authType!= -1 || encType != -1)
+    {
+        OIC_LOG(INFO, ES_RH_TAG, "Send WiFiRsrc Callback To ES");
+
+        // TODO : Need to check appropriateness of gWiFiData
+        if(gWifiRsrcEvtCb != NULL)
+        {
+            gWifiRsrcEvtCb(ES_OK, &gWiFiData);
+        }
+        else
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "gWifiRsrcEvtCb is NULL");
+        }
+    }
+
 }
-void updateCloudResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
+
+void updateCloudResource(OCRepPayload* input)
 {
-    (void) ehRequest;
-    char *authCode;
+    char *authCode = NULL;
     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHCODE, &authCode))
     {
         OICStrcpy(gCloudResource.authCode, sizeof(gCloudResource.authCode), authCode);
+        OICStrcpy(gCloudData.authCode, sizeof(gCloudData.authCode), authCode);
         OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.authCode %s", gCloudResource.authCode);
     }
 
-    char *authProvider;
+    char *authProvider = NULL;
     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHPROVIDER, &authProvider))
     {
         OICStrcpy(gCloudResource.authProvider, sizeof(gCloudResource.authProvider), authProvider);
+        OICStrcpy(gCloudData.authProvider, sizeof(gCloudData.authProvider), authProvider);
         OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.authServerUrl %s", gCloudResource.authProvider);
     }
 
-    char *ciServer;
+    char *ciServer = NULL;
     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CISERVER, &ciServer))
     {
         OICStrcpy(gCloudResource.ciServer, sizeof(gCloudResource.ciServer), ciServer);
+        OICStrcpy(gCloudData.ciServer, sizeof(gCloudData.ciServer), ciServer);
         OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.ciServer %s", gCloudResource.ciServer);
     }
+
+    if(authCode || authProvider || ciServer)
+    {
+        OIC_LOG(INFO, ES_RH_TAG, "Send CloudRsrc Callback To ES");
+
+        // TODO : Need to check appropriateness of gCloudData
+        if(gCloudRsrcEvtCb != NULL)
+        {
+            gCloudRsrcEvtCb(ES_OK, &gCloudData);
+        }
+        else
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "gCloudRsrcEvtCb is NULL");
+        }
+    }
 }
 
-void updateDevConfResource(OCEntityHandlerRequest* ehRequest, OCRepPayload* input)
+void updateDevConfResource(OCRepPayload* input)
 {
-    (void) ehRequest;
-    char *country;
+    char *country = NULL;
     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHCODE, &country))
     {
         OICStrcpy(gDevConfResource.country, sizeof(gDevConfResource.country), country);
+        OICStrcpy(gDevConfData.country, sizeof(gDevConfData.country), country);
         OIC_LOG_V(INFO, ES_RH_TAG, "gDevConfResource.country %s", gDevConfResource.country);
     }
 
-    char *language;
+    char *language = NULL;
     if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHPROVIDER, &language))
     {
         OICStrcpy(gDevConfResource.language, sizeof(gDevConfResource.language), language);
+        OICStrcpy(gDevConfData.language, sizeof(gDevConfData.language), language);
         OIC_LOG_V(INFO, ES_RH_TAG, "gDevConfResource.language %s", gDevConfResource.language);
     }
+
+    if(country || language)
+    {
+        OIC_LOG(INFO, ES_RH_TAG, "Send DevConfRsrc Callback To ES");
+
+        // TODO : Need to check appropriateness of gDevConfData
+        if(gDevConfRsrcEvtCb != NULL)
+        {
+            gDevConfRsrcEvtCb(ES_OK, &gDevConfData);
+        }
+        else
+        {
+            OIC_LOG(ERROR, ES_RH_TAG, "gDevConfRsrcEvtCb is NULL");
+        }
+    }
 }
 
-OCRepPayload* constructResponseOfWiFi(OCEntityHandlerRequest *ehRequest)
+OCRepPayload* constructResponseOfWiFi()
 {
-    (void) ehRequest;
     OCRepPayload* payload = OCRepPayloadCreate();
     if (!payload)
     {
@@ -321,22 +410,21 @@ OCRepPayload* constructResponseOfWiFi(OCEntityHandlerRequest *ehRequest)
     OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_WIFI);
 
     size_t dimensions[MAX_REP_ARRAY_DEPTH] = {gWiFiResource.numMode, 0, 0};
-    OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, gWiFiResource.supportedMode, dimensions);
+    OCRepPayloadSetIntArray(payload, OC_RSRVD_ES_SUPPORTEDWIFIMODE, (int64_t *)gWiFiResource.supportedMode, dimensions);
 
     OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_SUPPORTEDWIFIFREQ, gWiFiResource.supportedFreq);
     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_SSID, gWiFiResource.ssid);
     OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CRED, gWiFiResource.cred);
-    OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_AUTHTYPE, gWiFiResource.authType);
-    OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_ENCTYPE, gWiFiResource.encType);
+    OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_AUTHTYPE, (int) gWiFiResource.authType);
+    OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_ENCTYPE, (int) gWiFiResource.encType);
 
     printf("%s\n", gWiFiResource.ssid);
 
     return payload;
 }
 
-OCRepPayload* constructResponseOfCloud(OCEntityHandlerRequest *ehRequest)
+OCRepPayload* constructResponseOfCloud()
 {
-    (void) ehRequest;
     OCRepPayload* payload = OCRepPayloadCreate();
     if (!payload)
     {
@@ -353,9 +441,8 @@ OCRepPayload* constructResponseOfCloud(OCEntityHandlerRequest *ehRequest)
     return payload;
 }
 
-OCRepPayload* constructResponseOfDevConf(OCEntityHandlerRequest *ehRequest)
+OCRepPayload* constructResponseOfDevConf()
 {
-    (void) ehRequest;
     OCRepPayload* payload = OCRepPayloadCreate();
     if (!payload)
     {
@@ -390,15 +477,15 @@ OCRepPayload* constructResponseOfProv(OCEntityHandlerRequest *ehRequest)
     {
         if(strstr(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
         {// When Provisioning resource has a GET with BatchInterface
-            payload->next = constructResponseOfWiFi(ehRequest);
+            payload->next = constructResponseOfWiFi();
 
             if(payload->next)
-                payload->next->next = constructResponseOfCloud(ehRequest);
+                payload->next->next = constructResponseOfCloud();
             else
                 return payload;
 
             if(payload->next->next)
-                payload->next->next->next = constructResponseOfDevConf(ehRequest);
+                payload->next->next->next = constructResponseOfDevConf();
             else
                 return payload;
         }
@@ -408,42 +495,95 @@ OCRepPayload* constructResponseOfProv(OCEntityHandlerRequest *ehRequest)
 }
 
 
-OCStackResult CreateEasySetupResources(bool isSecured)
+OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMask)
 {
     OCStackResult res = OC_STACK_ERROR;
+    bool maskFlag = false;
 
     res = initProvResource(isSecured);
-    if(res)
+    if(res != OC_STACK_OK)
     {
         // TODO: destroy logic will be added
+        OIC_LOG_V(ERROR, ES_RH_TAG, "initProvResource result: %s", getResult(res));
+
         return res;
     }
 
-    res = initWiFiResource(isSecured);
-    if(res)
+    if((resourceMask & ES_WIFI_RESOURCE) == ES_WIFI_RESOURCE)
     {
-        // TODO: destroy logic will be added
-        return res;
+        maskFlag = true;
+        res = initWiFiResource(isSecured);
+        if(res != OC_STACK_OK)
+        {
+            // TODO: destroy logic will be added
+            OIC_LOG_V(ERROR, ES_RH_TAG, "initWiFiResource result: %s", getResult(res));
+
+            return res;
+        }
+
+        res = OCBindResource(gProvResource.handle, gWiFiResource.handle);
+        if(res != OC_STACK_OK)
+        {
+            // TODO : Error Handling
+            OIC_LOG_V(ERROR, ES_RH_TAG, "Bind WiFiResource result: %s", getResult(res));
+
+            return res;
+        }
+
     }
 
-    res = initCloudServerResource(isSecured);
-    if(res)
+    if((resourceMask & ES_CLOUD_RESOURCE) == ES_CLOUD_RESOURCE)
     {
-        // TODO: destroy logic will be added
-        return res;
+        maskFlag = true;
+        res = initCloudServerResource(isSecured);
+        if(res != OC_STACK_OK)
+        {
+            // TODO: destroy logic will be added
+            OIC_LOG_V(ERROR, ES_RH_TAG, "initCloudResource result: %s", getResult(res));
+
+            return res;
+        }
+
+        res = OCBindResource(gProvResource.handle, gCloudResource.handle);
+        if(res != OC_STACK_OK)
+        {
+            // TODO : Error Handling
+            OIC_LOG_V(ERROR, ES_RH_TAG, "Bind CloudResource result: %s", getResult(res));
+
+            return res;
+        }
     }
 
-    res = initDevConfResource(isSecured);
-    if(res)
+    if((resourceMask & ES_DEVCONF_RESOURCE) == ES_DEVCONF_RESOURCE)
     {
-        // TODO: destroy logic will be added
-        return res;
+        maskFlag = true;
+        res = initDevConfResource(isSecured);
+        if(res != OC_STACK_OK)
+        {
+            // TODO: destroy logic will be added
+            OIC_LOG_V(ERROR, ES_RH_TAG, "initDevConf result: %s", getResult(res));
+
+            return res;
+        }
+
+        res = OCBindResource(gProvResource.handle, gDevConfResource.handle);
+        if(res != OC_STACK_OK)
+        {
+            // TODO : Error Handling
+            OIC_LOG_V(ERROR, ES_RH_TAG, "Bind DevConfResource result: %s", getResult(res));
+
+            return res;
+        }
     }
 
-    OCBindResource(gProvResource.handle, gWiFiResource.handle);
-    OCBindResource(gProvResource.handle, gCloudResource.handle);
-    OCBindResource(gProvResource.handle, gDevConfResource.handle);
 
+    if(maskFlag == false)
+    {
+        // TODO: destroy logic will be added
+        OIC_LOG_V(ERROR, ES_RH_TAG, "Invalid ResourceMask");
+        return OC_STACK_ERROR;
+
+    }
     OIC_LOG_V(INFO, ES_RH_TAG, "Created all resources with result: %s", getResult(res));
     return res;
 }
@@ -504,11 +644,11 @@ OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRep
     if(ehRequest->resource == gProvResource.handle)
         getResp = constructResponseOfProv(ehRequest);
     else if(ehRequest->resource == gWiFiResource.handle)
-        getResp = constructResponseOfWiFi(ehRequest);
+        getResp = constructResponseOfWiFi();
     else if(ehRequest->resource == gCloudResource.handle)
-        getResp = constructResponseOfCloud(ehRequest);
+        getResp = constructResponseOfCloud();
     else if(ehRequest->resource == gDevConfResource.handle)
-        getResp = constructResponseOfDevConf(ehRequest);
+        getResp = constructResponseOfDevConf();
 
     if (!getResp)
     {
@@ -542,46 +682,47 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe
     if(ehRequest->resource == gProvResource.handle)
         updateProvResource(ehRequest, input);
     else if(ehRequest->resource == gWiFiResource.handle)
-        updateWiFiResource(ehRequest, input);
+        updateWiFiResource(input);
     else if(ehRequest->resource == gCloudResource.handle)
-        updateCloudResource(ehRequest, input);
+        updateCloudResource(input);
     else if(ehRequest->resource == gDevConfResource.handle)
-        updateDevConfResource(ehRequest, input);
+        updateDevConfResource(input);
 
+    // TBD : Discuss about triggering flag (to be existed or not)
     // ES_PS_PROVISIONING_COMPLETED state indicates that already provisioning is completed.
     // A new request for provisioning means overriding existing network provisioning information.
-    if (gProvResource.trigger)
-    {
-        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
-    {
-        OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning the network information to the Enrollee.");
-    }
+    // if (gProvResource.trigger)
+    // {
+    //     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
+    // {
+    //     OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning the network information to the Enrollee.");
+    // }
 
     OCRepPayload *getResp = NULL;
     if(ehRequest->resource == gProvResource.handle)
         getResp = constructResponseOfProv(ehRequest);
     else if(ehRequest->resource == gWiFiResource.handle)
-        getResp = constructResponseOfWiFi(ehRequest);
+        getResp = constructResponseOfWiFi();
     else if(ehRequest->resource == gCloudResource.handle)
-        getResp = constructResponseOfCloud(ehRequest);
+        getResp = constructResponseOfCloud();
     else if(ehRequest->resource == gDevConfResource.handle)
-        getResp = constructResponseOfDevConf(ehRequest);
+        getResp = constructResponseOfDevConf();
 
     if (gProvResource.trigger)// Trigger false should be restored after executed
         gProvResource.trigger = false;
index 7ca5d0b..d0dd4cc 100755 (executable)
@@ -24,7 +24,6 @@
 #include "logger.h"
 #include "ocstack.h"
 #include "escommon.h"
-//#include "networkhandler.h"
 #include "octypes.h"
 
 #ifndef ES_RESOURCE_HANDLER_H_
@@ -34,7 +33,9 @@
 extern "C" {
 #endif
 
-typedef void (*ESEnrolleeResourceEventCallback)(ESResult);
+typedef void (*ESWiFiCB) (ESResult, ESWiFiProvData *);
+typedef void (*ESCloudCB) (ESResult, ESCloudProvData *);
+typedef void (*ESDevConfCB) (ESResult, ESDevConfProvData *);
 
 /* Structure to represent a Light resource */
 typedef struct PROVRESOURCE
@@ -48,13 +49,13 @@ typedef struct PROVRESOURCE
 typedef struct
 {
     OCResourceHandle handle;
-    int64_t supportedMode[NUM_WIFIMODE];
+    WIFI_MODE supportedMode[NUM_WIFIMODE];
     uint8_t numMode;
-    int64_t supportedFreq;
+    WIFI_FREQ supportedFreq;
     char ssid[MAXSSIDLEN]; // target network name, i.e. SSID for WLAN, MAC address for BT.
     char cred[MAXNETCREDLEN]; // credential information.
-    int64_t authType;
-    int64_t encType;
+    WIFI_AUTHTYPE authType;
+    WIFI_ENCTYPE encType;
 } WiFiResource;
 
 typedef struct
@@ -74,14 +75,14 @@ typedef struct
 } DevConfResource;
 
 
-OCStackResult CreateProvisioningResource(bool isSecured);
-OCStackResult CreateEasySetupResources(bool isSecured);
-OCStackResult DeleteProvisioningResource();
+OCStackResult CreateEasySetupResources(bool isSecured, ESResourceMask resourceMask);
 OCStackResult DeleteEasySetupResources();
 
 
 void GetTargetNetworkInfoFromProvResource(char *, char *);
-void RegisterResourceEventCallBack(ESEnrolleeResourceEventCallback);
+void RegisterWifiRsrcEventCallBack(ESWiFiCB);
+void RegisterCloudRsrcEventCallBack(ESCloudCB);
+void RegisterDevConfRsrcEventCallBack(ESDevConfCB);
 void UnRegisterResourceEventCallBack(void);
 
 #ifdef __cplusplus
index b8ea724..e06a69e 100755 (executable)
@@ -149,6 +149,36 @@ typedef enum
 
 typedef enum
 {
+    ES_WIFI_RESOURCE = 0x01,
+    ES_CLOUD_RESOURCE = 0x02,
+    ES_DEVCONF_RESOURCE = 0x04
+} ESResourceMask;
+
+typedef struct
+{
+    char ssid[NET_WIFI_SSID_SIZE]; /**< ssid of the Enroller**/
+    char pwd[NET_WIFI_PWD_SIZE]; /**< pwd of the Enroller**/
+    WIFI_AUTHTYPE authtype; /**< auth type of the Enroller**/
+    WIFI_ENCTYPE enctype; /**< encryption type of the Enroller**/
+} ESWiFiProvData;
+
+typedef struct
+{
+    char language[OIC_STRING_MAX_VALUE];
+    char country[OIC_STRING_MAX_VALUE];
+} ESDevConfProvData;
+
+typedef struct
+{
+    char authCode[OIC_STRING_MAX_VALUE];
+    char authProvider[OIC_STRING_MAX_VALUE];
+    char ciServer[OIC_STRING_MAX_VALUE];
+} ESCloudProvData;
+
+
+// TODO : Need to be erased
+typedef enum
+{
     /**
      * Default state of the device
      */
@@ -298,4 +328,5 @@ typedef struct {
    bool isSecured;                 /**< Secure connection**/
 }WiFiOnboadingConnection;
 
+
 #endif //ES_COMMON_H_
index e645bc4..934549d 100644 (file)
 #include <stdio.h>
 #include <pthread.h>
 
-#define TAG "TS"
+#define TAG "ENROLLEE_SAMPLE"
 
 void *listeningFunc(void *);
 
-/**
- * @var ssid
- * @brief Target SSID of the Soft Access point to which the device has to connect
- */
-static char ssid[] = "EasySetup123";
-
-/**
- * @var passwd
- * @brief Password of the Soft Access point to which the device has to connect
- */
-static char passwd[] = "EasySetup123";
 
 /**
  * Secure Virtual Resource database for Iotivity Server
@@ -62,44 +51,139 @@ void PrintMenu()
 {
     printf("============\n");
     printf("S: Enabled Security\n");
-    printf("I: Init easy setup\n");
-    printf("P: start provisioning resources\n");
-    printf("T: terminate\n");
-    printf("Q: quit\n");
+    printf("I: Init & Start EasySetup\n");
+    printf("D: Set DeviceInfo\n");
+    printf("T: Terminate\n");
+    printf("Q: Quit\n");
     printf("============\n");
 }
 
-void EventCallbackInApp(ESResult esResult, ESEnrolleeState enrolleeState)
+void WiFiProvCbInApp(ESWiFiProvData *eventData)
 {
-    printf("Easy setup event callback\n");
+    printf("WiFiProvCbInApp IN\n");
 
-    if(esResult == ES_OK)
+    if(eventData->ssid != NULL)
     {
-        if(enrolleeState == ES_ON_BOARDED_STATE)
-        {
-            printf("Device is successfully OnBoared on Adhoc network\n");
-        }
-        else if (enrolleeState == ES_PROVISIONED_STATE)
-        {
-            printf("Device is provisioned with target network's credentials\n");
-        }
-        else if (enrolleeState == ES_ON_BOARDED_TARGET_NETWORK_STATE)
-        {
-            printf("Device is onboarded/connected with target network\n");
-        }
-        else
-        {
-            printf("Wrong state !! Easy setup is failed at Enrollee state = %d\n",enrolleeState);
-        }
+        printf("SSID : %s\n", eventData->ssid);
+    }
+    else
+    {
+        printf("ERROR! SSID IS NULL\n");
+        return;
+    }
+
+    if(eventData->pwd != NULL)
+    {
+        printf("Password : %s\n", eventData->pwd);
+    }
+    else
+    {
+        printf("ERROR! Password IS NULL\n");
+        return;
+    }
+
+    if(eventData->authtype == NONE_AUTH || eventData->authtype == WEP || \
+        eventData->authtype == WPA_PSK || eventData->authtype == WPA2_PSK)
+    {
+        printf("AuthType : %d\n", eventData->authtype);
+    }
+    else
+    {
+        printf("ERROR! AuthType IS NULL\n");
+        return;
+    }
+
+    if(eventData->enctype == NONE_ENC || eventData->enctype == WEP_64 || \
+        eventData->enctype == WEP_128 || eventData->enctype == TKIP || \
+        eventData->enctype == AES || eventData->enctype == TKIP_AES)
+    {
+        printf("EncType : %d\n", eventData->enctype);
+    }
+    else
+    {
+        printf("ERROR! EncType IS NULL\n");
+        return;
+    }
+
+    printf("WiFiProvCbInApp OUT\n");
+
+    PrintMenu();
+}
+
+void DevConfProvCbInApp(ESDevConfProvData *eventData)
+{
+    printf("DevConfProvCbInApp IN\n");
+
+    if(eventData->language != NULL)
+    {
+        printf("Language : %s\n", eventData->language);
+    }
+    else
+    {
+        printf("ERROR! Language IS NULL\n");
+        return;
+    }
+
+    if(eventData->country != NULL)
+    {
+        printf("Country : %s\n", eventData->country);
+    }
+    else
+    {
+        printf("ERROR! Country IS NULL\n");
+        return;
+    }
+
+    printf("DevConfProvCbInApp OUT\n");
+
+    PrintMenu();
+}
+
+void CloudDataProvCbInApp(ESCloudProvData *eventData)
+{
+    printf("CloudDataProvCbInApp IN\n");
+
+    if(eventData->authCode != NULL)
+    {
+        printf("AuthCode : %s\n", eventData->authCode);
+    }
+    else
+    {
+        printf("ERROR! AuthCode IS NULL\n");
+        return;
+    }
+
+    if(eventData->authProvider != NULL)
+    {
+        printf("AuthProvider : %s\n", eventData->authProvider);
+    }
+    else
+    {
+        printf("ERROR! AuthProvider IS NULL\n");
+        return;
+    }
+
+    if(eventData->ciServer != NULL)
+    {
+        printf("CI Server : %s\n", eventData->ciServer);
     }
     else
     {
-        printf("Easy stup is failed at Enrollee state = %d\n",enrolleeState);;
+        printf("ERROR! CI Server IS NULL\n");
+        return;
     }
 
+    printf("CloudDataProvCbInApp OUT\n");
+
     PrintMenu();
 }
 
+ESProvisioningCallbacks gCallbacks = {
+    .WiFiProvCb = &WiFiProvCbInApp,
+    .DevConfProvCb = &DevConfProvCbInApp,
+    .CloudDataProvCb = &CloudDataProvCbInApp
+};
+
 FILE* server_fopen(const char *path, const char *mode)
 {
     (void) path;
@@ -119,31 +203,21 @@ void EnableSecurity()
 
 void StartEasySetup()
 {
-    printf("StartEasySetup and onboarding started..\n");
+    printf("StartEasySetup IN\n");
 
-    if(ESInitEnrollee(CT_ADAPTER_IP, ssid, passwd, gIsSecured, EventCallbackInApp) == ES_ERROR)
-    {
-        printf("StartEasySetup and onboarding Fail!!\n");
-        return;
-    }
-}
-
-void ESInitResources()
-{
-    printf("Starting Enrollee Provisioning\n");
-
-    // Initialize the OC Stack in Server mode
     if (OCInit(NULL, 0, OC_SERVER) != OC_STACK_OK)
     {
         printf("OCStack init error!!\n");
         return;
     }
 
-    if (ESInitProvisioning() == ES_ERROR)
+    ESResourceMask resourcemMask = ES_WIFI_RESOURCE | ES_CLOUD_RESOURCE | ES_DEVCONF_RESOURCE;
+    if(ESInitEnrollee(gIsSecured, resourcemMask, gCallbacks) != ES_OK)
     {
-        printf("Init Provisioning Failed!!\n");
+        printf("OCStack init error!!\n");
         return;
     }
+    printf("ESInitEnrollee Success\n");
 
     pthread_t thread_handle;
     if (pthread_create(&thread_handle, NULL, listeningFunc, NULL))
@@ -151,7 +225,7 @@ void ESInitResources()
         printf("Thread creation failed\n");
     }
 
-    printf("ESInitProvisioning Success\n");
+    printf("StartEasySetup OUT\n");
 }
 
 void StopEasySetup()
@@ -184,10 +258,14 @@ int main()
 
     while(true)
     {
-        scanf("%c",&option);
+        if(scanf("%c", &option) != 1)
+        {
+            printf("Failed to read input data\n");
+            continue;
+        }
 
-       if(option!= '\n')
-      {
+        if(option!= '\n')
+        {
             switch (option)
             {
                 case 'H': // help
@@ -210,10 +288,9 @@ int main()
                     StartEasySetup();
                     break;
 
-                case 'P': // start provisioning
-                case 'p':
-                    ESInitResources();
-                    break;
+                case 'D': // Set Device Info
+                case 'd':
+                    // TODO
 
                 case 'T': // stop easy setup
                 case 't':
@@ -230,7 +307,7 @@ int main()
     return 0;
 }
 
-void *listeningFunc(void * a)
+void *listeningFunc(void * data)
 {
     OCStackResult result;