Update resource models of easy setup in Enrollee side
authorJihun Ha <jihun.ha@samsung.com>
Fri, 3 Jun 2016 05:58:55 +0000 (14:58 +0900)
committerUze Choi <uzchoi@samsung.com>
Tue, 7 Jun 2016 04:20:01 +0000 (04:20 +0000)
There are 4 resource modesl in Enrollee side:
1. Provisioning resource
 - provisioning status and trigger properties
2. WiFi resource
 - WiFi ssid, password, security type, etc.
3. CloudServer resource
 - Auth code, Auth provider, etc.
4. DevConf resource
 - Device name, language, country

Change-Id: I31a088b7cde8178d9ddd951ac0641989706dc249
Signed-off-by: Jihun Ha <jihun.ha@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8429
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/easy-setup/enrollee/SConscript
service/easy-setup/enrollee/src/easysetup.c [changed mode: 0644->0755]
service/easy-setup/enrollee/src/resourcehandler.c
service/easy-setup/enrollee/src/resourcehandler.h [changed mode: 0644->0755]
service/easy-setup/inc/escommon.h
service/easy-setup/mediator/SConscript

index f129242d4d39b8201402230d0ec7775da375961b..d856cd279403c9c3a974384a6c554b7dd4e61f49 100644 (file)
@@ -90,12 +90,11 @@ if target_os == 'linux':
 # Tizen Enrollee
 ######################################################################
 if target_os == 'tizen':
-       enrollee_env.AppendUnique(LIBPATH = [enrollee_env.get('BUILD_DIR')])
-       enrollee_env.AppendUnique(RPATH = [enrollee_env.get('BUILD_DIR')])
-       enrollee_env.AppendUnique(CXXFLAGS = ['-pthread'])
-       enrollee_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'pthread', 'connectivity_abstraction'])
-       enrollee_env.AppendUnique(CPPPATH = [
-                              enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/tizen/wifi'])
+   enrollee_env.AppendUnique(LIBPATH = [enrollee_env.get('BUILD_DIR')])
+   enrollee_env.AppendUnique(RPATH = [enrollee_env.get('BUILD_DIR')])
+   enrollee_env.AppendUnique(CXXFLAGS = ['-pthread'])
+   enrollee_env.PrependUnique(LIBS = ['oc', 'octbstack', 'oc_logger', 'pthread', 'connectivity_abstraction'])
+   enrollee_env.AppendUnique(CPPPATH = [enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/tizen/wifi'])
 
 ######################################################################
 # Arduino Enrollee
@@ -113,7 +112,7 @@ if target_os == 'arduino':
 es_enrollee_src = None
 
 if target_os == 'linux':
-       es_enrollee_common_src =        [enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/easysetup.c',
+       es_enrollee_common_src = [enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/easysetup.c',
                enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/onboarding.c',
                enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/resourcehandler.c',
                enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/softap.c',
@@ -126,31 +125,39 @@ if target_os == 'linux':
        enrollee_env.InstallTarget(enrollee_sdk_shared, 'libESEnrollee')
 
 if target_os == 'tizen':
-       enrollee_sdk_shared = enrollee_env.SharedLibrary('ESEnrolleeSDK', [
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/easysetup.c',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/onboarding.c',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/softap.c',
+       es_enrollee_common_src = [enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/easysetup.c',
+               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/onboarding.c',
                enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/resourcehandler.c',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/tizen/wifi/networkhandler.c',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/tizen/wifi/softapnative.c'])
-       enrollee_env.InstallTarget(enrollee_sdk_shared, 'libESEnrolleeSDK')
+               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/softap.c',
+               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/linux/wifi/softapnative.c',
+               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/linux/wifi/networkhandler.c']
+
+       enrollee_env.AppendUnique(es_enrollee_src = es_enrollee_common_src)
+       enrollee_sdk_shared = enrollee_env.SharedLibrary('ESEnrolleeSDK', enrollee_env.get('es_enrollee_src'))
+       enrollee_env.InstallTarget(enrollee_sdk_shared, 'libESEnrollee')
        enrollee_env.UserInstallTargetLib(enrollee_sdk_shared, 'libESEnrolleeSDK')
 
 if target_os == 'arduino':
        es_sdk_static = enrollee_env.StaticLibrary('ESEnrolleeSDK', [
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/easysetup.cpp',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/onboarding.cpp',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/softap.cpp',
-               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/resourcehandler.cpp',
+#              enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/easysetup.cpp',
+#              enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/onboarding.cpp',
+#              enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/softap.cpp',
+#              enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/resourcehandler.cpp',
+#              enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/wifi/networkhandler.cpp'])
+               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/easysetup.c',
+               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/onboarding.c',
+               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/softap.c',
+               enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/src/resourcehandler.c',
                enrollee_env.get('SRC_DIR') + '/service/easy-setup/enrollee/arduino/wifi/networkhandler.cpp'])
+
        enrollee_env.InstallTarget(es_sdk_static, 'libESEnrolleeSDK')
 
 #Go to build sample apps
-if target_os == 'arduino':
-       SConscript('../sampleapp/enrollee/arduino/SConscript')
+#if target_os == 'arduino':
+#      SConscript('../sampleapp/enrollee/arduino/SConscript')
 
 if target_os == 'linux':
        SConscript('../sampleapp/enrollee/linux/SConscript')
        #Build UnitTestcases for Enrollee
-       SConscript('../enrollee/unittests/SConscript')
+#      SConscript('../enrollee/unittests/SConscript')
 
old mode 100644 (file)
new mode 100755 (executable)
index cb6d260..0da1f68
@@ -159,7 +159,7 @@ ESResult ESTerminateEnrollee()
     UnRegisterResourceEventCallBack();
 
     //Delete Prov resource
-    if (DeleteProvisioningResource() != OC_STACK_OK)
+    if (DeleteEasySetupResources() != OC_STACK_OK)
     {
         OIC_LOG(ERROR, ES_ENROLLEE_TAG, "Deleting prov resource error!!");
         return ES_ERROR;
@@ -173,7 +173,7 @@ ESResult ESInitProvisioning()
 {
     OIC_LOG(INFO, ES_ENROLLEE_TAG, "ESInitProvisioning <<IN>>");
 
-    if (CreateProvisioningResource(gIsSecured) != OC_STACK_OK)
+    if (CreateEasySetupResources(gIsSecured) != OC_STACK_OK)
     {
         OIC_LOG(ERROR, ES_ENROLLEE_TAG, "CreateProvisioningResource error");
         return ES_ERROR;
index 249d5861d18ce4ea851f6965ccc0a77ef5248031..c0a24df8f7b1015019e098a5025e6c9b4bd584f0 100755 (executable)
  * connect to the target network
  */
 static ProvResource gProvResource;
-
-/**
- * @var gNetResource
- * @brief Structure forr holding the Provisioning status of network information
- */
-static NetResource gNetResource;
+static WiFiResource gWiFiResource;
+static CloudResource gCloudResource;
+static DevConfResource gDevConfResource;
 
 //-----------------------------------------------------------------------------
 // Private internal function prototypes
@@ -77,40 +74,361 @@ void GetTargetNetworkInfoFromProvResource(char *name, char *pass)
 {
     if (name != NULL && pass != NULL)
     {
-        OICStrcpy(name, MAXSSIDLEN, gProvResource.tnn);
-        OICStrcpy(pass, MAXNETCREDLEN, gProvResource.cd);
+        OICStrcpy(name, MAXSSIDLEN, gWiFiResource.ssid);
+        OICStrcpy(pass, MAXNETCREDLEN, gWiFiResource.cred);
     }
 }
 
-OCStackResult CreateProvisioningResource(bool isSecured)
+OCStackResult initProvResource(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.cd, sizeof(gProvResource.cd), "Unknown");
+    gProvResource.status = NO_PROVISION;
+    gProvResource.trigger = false;
 
     OCStackResult res = OC_STACK_ERROR;
     if (isSecured)
     {
-        res = OCCreateResource(&gProvResource.handle, OC_RSRVD_ES_PROV_RES_TYPE,
+        res = OCCreateResource(&gProvResource.handle, OC_RSRVD_ES_RES_TYPE_PROV,
         OC_RSRVD_INTERFACE_DEFAULT,
         OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,
         NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
-    }
-    else
+    }else
     {
-        res = OCCreateResource(&gProvResource.handle, OC_RSRVD_ES_PROV_RES_TYPE,
+        res = OCCreateResource(&gProvResource.handle, OC_RSRVD_ES_RES_TYPE_PROV,
         OC_RSRVD_INTERFACE_DEFAULT,
         OC_RSRVD_ES_URI_PROV, OCEntityHandlerCb,
         NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
     }
+    if(res)
+    {
+        OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
+        return res;
+    }
+
+    res = OCBindResourceInterfaceToResource(gProvResource.handle, OC_RSRVD_INTERFACE_LL);
+    if(res)
+    {
+        OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
+        return res;
+    }
+    res = OCBindResourceInterfaceToResource(gProvResource.handle, OC_RSRVD_INTERFACE_BATCH);
+    if(res)
+    {
+        OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
+        return res;
+    }
 
     OIC_LOG_V(INFO, ES_RH_TAG, "Created Prov resource with result: %s", getResult(res));
     return res;
 }
 
+OCStackResult initWiFiResource(bool isSecured)
+{
+    OCStackResult res = OC_STACK_ERROR;
+
+    gWiFiResource.supportedFreq = WiFi_BOTH;
+    gWiFiResource.supportedMode[0] = WiFi_11A;
+    gWiFiResource.supportedMode[1] = WiFi_11B;
+    gWiFiResource.supportedMode[2] = WiFi_11G;
+    gWiFiResource.supportedMode[3] = WiFi_11N;
+    gWiFiResource.numMode = 4;
+    gWiFiResource.authType = NONE_AUTH;
+    gWiFiResource.encType = NONE_ENC;
+    OICStrcpy(gWiFiResource.ssid, sizeof(gWiFiResource.ssid), "");
+    OICStrcpy(gWiFiResource.cred, sizeof(gWiFiResource.cred), "");
+
+    if (isSecured)
+    {
+        res = OCCreateResource(&gWiFiResource.handle, OC_RSRVD_ES_RES_TYPE_WIFI,
+        OC_RSRVD_INTERFACE_DEFAULT,
+        OC_RSRVD_ES_URI_WIFI, OCEntityHandlerCb,
+        NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
+    }else
+    {
+        res = OCCreateResource(&gWiFiResource.handle, OC_RSRVD_ES_RES_TYPE_WIFI,
+        OC_RSRVD_INTERFACE_DEFAULT,
+        OC_RSRVD_ES_URI_WIFI, OCEntityHandlerCb,
+        NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
+    }
+
+    OIC_LOG_V(INFO, ES_RH_TAG, "Created WiFi resource with result: %s", getResult(res));
+    return res;
+
+}
+
+OCStackResult initCloudServerResource(bool isSecured)
+{
+    OCStackResult res = OC_STACK_ERROR;
+
+    OICStrcpy(gCloudResource.authCode, sizeof(gCloudResource.authCode), "");
+    OICStrcpy(gCloudResource.authProvider, sizeof(gCloudResource.authProvider), "");
+    OICStrcpy(gCloudResource.ciServer, sizeof(gCloudResource.ciServer), "");
+
+    if (isSecured)
+    {
+        res = OCCreateResource(&gCloudResource.handle, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER,
+        OC_RSRVD_INTERFACE_DEFAULT,
+        OC_RSRVD_ES_URI_CLOUDSERVER, OCEntityHandlerCb,
+        NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
+    }else
+    {
+        res = OCCreateResource(&gCloudResource.handle, OC_RSRVD_ES_RES_TYPE_CLOUDSERVER,
+        OC_RSRVD_INTERFACE_DEFAULT,
+        OC_RSRVD_ES_URI_CLOUDSERVER, OCEntityHandlerCb,
+        NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
+    }
+
+    OIC_LOG_V(INFO, ES_RH_TAG, "Created CloudServer resource with result: %s", getResult(res));
+    return res;
+
+}
+
+OCStackResult initDevConfResource(bool isSecured)
+{
+    OCStackResult res = OC_STACK_ERROR;
+
+    OICStrcpy(gDevConfResource.devName, sizeof(gDevConfResource.devName), "");
+    OICStrcpy(gDevConfResource.country, sizeof(gDevConfResource.country), "");
+    OICStrcpy(gDevConfResource.language, sizeof(gDevConfResource.language), "");
+
+    if (isSecured)
+    {
+        res = OCCreateResource(&gDevConfResource.handle, OC_RSRVD_ES_RES_TYPE_DEVCONF,
+        OC_RSRVD_INTERFACE_DEFAULT,
+        OC_RSRVD_ES_URI_DEVCONF, OCEntityHandlerCb,
+        NULL, OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE);
+    }else
+    {
+        res = OCCreateResource(&gDevConfResource.handle, OC_RSRVD_ES_RES_TYPE_DEVCONF,
+        OC_RSRVD_INTERFACE_DEFAULT,
+        OC_RSRVD_ES_URI_DEVCONF, OCEntityHandlerCb,
+        NULL, OC_DISCOVERABLE | OC_OBSERVABLE);
+    }
+
+    OIC_LOG_V(INFO, ES_RH_TAG, "Created DevConf resource with result: %s", getResult(res));
+    return res;
+
+}
+
+void updateProvResource(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;
+    }
+}
+
+void updateWiFiResource(OCRepPayload* input)
+{
+    char* ssid;
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_SSID, &ssid))
+    {
+        OICStrcpy(gWiFiResource.ssid, sizeof(gWiFiResource.ssid), ssid);
+        OIC_LOG(INFO, ES_RH_TAG, "got ssid");
+    }
+
+    char* cred;
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CRED, &cred))
+    {
+        OICStrcpy(gWiFiResource.cred, sizeof(gWiFiResource.cred), cred);
+        OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.cred %s", gWiFiResource.cred);
+    }
+
+    int64_t authType;
+    if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_AUTHTYPE, &authType))
+    {
+        gWiFiResource.authType = authType;
+        OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.authType %u", gWiFiResource.authType);
+    }
+
+    int64_t encType;
+    if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_ENCTYPE, &encType))
+    {
+        gWiFiResource.encType = encType;
+        OIC_LOG_V(INFO, ES_RH_TAG, "gWiFiResource.encType %u", gWiFiResource.encType);
+    }
+}
+void updateCloudResource(OCRepPayload* input)
+{
+    char *authCode;
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHCODE, &authCode))
+    {
+        OICStrcpy(gCloudResource.authCode, sizeof(gCloudResource.authCode), authCode);
+        OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.authCode %s", gCloudResource.authCode);
+    }
+
+    char *authProvider;
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHPROVIDER, &authProvider))
+    {
+        OICStrcpy(gCloudResource.authProvider, sizeof(gCloudResource.authProvider), authProvider);
+        OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.authServerUrl %s", gCloudResource.authProvider);
+    }
+
+    char *ciServer;
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CISERVER, &ciServer))
+    {
+        OICStrcpy(gCloudResource.ciServer, sizeof(gCloudResource.ciServer), ciServer);
+        OIC_LOG_V(INFO, ES_RH_TAG, "gCloudResource.ciServer %s", gCloudResource.ciServer);
+    }
+}
+
+void updateDevConfResource(OCRepPayload* input)
+{
+    char *country;
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHCODE, &country))
+    {
+        OICStrcpy(gDevConfResource.country, sizeof(gDevConfResource.country), country);
+        OIC_LOG_V(INFO, ES_RH_TAG, "gDevConfResource.country %s", gDevConfResource.country);
+    }
+
+    char *language;
+    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_AUTHPROVIDER, &language))
+    {
+        OICStrcpy(gDevConfResource.language, sizeof(gDevConfResource.language), language);
+        OIC_LOG_V(INFO, ES_RH_TAG, "gDevConfResource.language %s", gDevConfResource.language);
+    }
+}
+
+OCRepPayload* constructResponseOfWiFi(OCEntityHandlerRequest *ehRequest)
+{
+    OCRepPayload* payload = OCRepPayloadCreate();
+    if (!payload)
+    {
+        OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+        return NULL;
+    }
+
+    OIC_LOG(INFO, ES_RH_TAG, "constructResponse wifi res");
+    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);
+
+    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);
+
+    printf("%s\n", gWiFiResource.ssid);
+
+    return payload;
+}
+
+OCRepPayload* constructResponseOfCloud(OCEntityHandlerRequest *ehRequest)
+{
+    OCRepPayload* payload = OCRepPayloadCreate();
+    if (!payload)
+    {
+        OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+        return NULL;
+    }
+
+    OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
+    OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_CLOUDSERVER);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHCODE, gCloudResource.authCode);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_AUTHPROVIDER, gCloudResource.authProvider);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_CISERVER, gCloudResource.ciServer);
+
+    return payload;
+}
+
+OCRepPayload* constructResponseOfDevConf(OCEntityHandlerRequest *ehRequest)
+{
+    OCRepPayload* payload = OCRepPayloadCreate();
+    if (!payload)
+    {
+        OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+        return NULL;
+    }
+
+    OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
+    OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_DEVCONF);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_DEVNAME, gDevConfResource.devName);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_LANGUAGE, gDevConfResource.language);
+    OCRepPayloadSetPropString(payload, OC_RSRVD_ES_COUNTRY, gDevConfResource.country);
+
+    return payload;
+}
+
+OCRepPayload* constructResponseOfProv(OCEntityHandlerRequest *ehRequest)
+{
+    OCRepPayload* payload = OCRepPayloadCreate();
+    if (!payload)
+    {
+        OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
+        return NULL;
+    }
+
+    OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
+    OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV);
+    OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PROVSTATUS, gProvResource.status);
+    OCRepPayloadSetPropBool(payload, OC_RSRVD_ES_TRIGGER, gProvResource.trigger);
+
+    if(ehRequest->query)
+    {
+        if(strstr(ehRequest->query, OC_RSRVD_INTERFACE_BATCH))
+        {// When Provisioning resource has a GET with BatchInterface
+            payload->next = constructResponseOfWiFi(ehRequest);
+
+            if(payload->next)
+                payload->next->next = constructResponseOfCloud(ehRequest);
+            else
+                return payload;
+
+            if(payload->next->next)
+                payload->next->next->next = constructResponseOfDevConf(ehRequest);
+            else
+                return payload;
+        }
+    }
+
+    return payload;
+}
+
+
+OCStackResult CreateEasySetupResources(bool isSecured)
+{
+    OCStackResult res = OC_STACK_ERROR;
+
+    res = initProvResource(isSecured);
+    if(res)
+    {
+        // TODO: destroy logic will be added
+        return res;
+    }
+
+    res = initWiFiResource(isSecured);
+    if(res)
+    {
+        // TODO: destroy logic will be added
+        return res;
+    }
+
+    res = initCloudServerResource(isSecured);
+    if(res)
+    {
+        // TODO: destroy logic will be added
+        return res;
+    }
+
+    res = initDevConfResource(isSecured);
+    if(res)
+    {
+        // TODO: destroy logic will be added
+        return res;
+    }
+
+    OCBindResource(gProvResource.handle, gWiFiResource.handle);
+    OCBindResource(gProvResource.handle, gCloudResource.handle);
+    OCBindResource(gProvResource.handle, gDevConfResource.handle);
+
+    OIC_LOG_V(INFO, ES_RH_TAG, "Created all resources with result: %s", getResult(res));
+    return res;
+}
+
 OCStackResult DeleteProvisioningResource()
 {
     OCStackResult res = OCDeleteResource(gProvResource.handle);
@@ -122,6 +440,32 @@ OCStackResult DeleteProvisioningResource()
     return res;
 }
 
+OCStackResult DeleteEasySetupResources()
+{
+    OCStackResult res = OCDeleteResource(gProvResource.handle);
+    if (res != OC_STACK_OK)
+    {
+        OIC_LOG_V(INFO, ES_RH_TAG, "Deleting Prov resource error with result: %s", getResult(res));
+    }
+    res = OCDeleteResource(gWiFiResource.handle);
+    if (res != OC_STACK_OK)
+    {
+        OIC_LOG_V(INFO, ES_RH_TAG, "Deleting WiFi resource error with result: %s", getResult(res));
+    }
+    res = OCDeleteResource(gCloudResource.handle);
+    if (res != OC_STACK_OK)
+    {
+        OIC_LOG_V(INFO, ES_RH_TAG, "Deleting CloudServer resource error with result: %s", getResult(res));
+    }
+    res = OCDeleteResource(gDevConfResource.handle);
+    if (res != OC_STACK_OK)
+    {
+        OIC_LOG_V(INFO, ES_RH_TAG, "Deleting DevConf resource error with result: %s", getResult(res));
+    }
+
+    return res;
+}
+
 OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRepPayload **payload)
 {
     OCEntityHandlerResult ehResult = OC_EH_ERROR;
@@ -136,7 +480,17 @@ OCEntityHandlerResult ProcessGetRequest(OCEntityHandlerRequest *ehRequest, OCRep
         return ehResult;
     }
 
-    OCRepPayload *getResp = constructResponse(ehRequest);
+    OCRepPayload *getResp = NULL;
+
+    if(ehRequest->resource == gProvResource.handle)
+        getResp = constructResponseOfProv(ehRequest);
+    else if(ehRequest->resource == gWiFiResource.handle)
+        getResp = constructResponseOfWiFi(ehRequest);
+    else if(ehRequest->resource == gCloudResource.handle)
+        getResp = constructResponseOfCloud(ehRequest);
+    else if(ehRequest->resource == gDevConfResource.handle)
+        getResp = constructResponseOfDevConf(ehRequest);
+
     if (!getResp)
     {
         OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
@@ -166,34 +520,18 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe
         return ehResult;
     }
 
-    char* tnn;
-    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_TNN, &tnn))
-    {
-        OICStrcpy(gProvResource.tnn, sizeof(gProvResource.tnn), tnn);
-        OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.tnn %s", gProvResource.tnn);
-
-        gProvResource.ps = ES_PS_PROVISIONING_COMPLETED;
-    }
-
-    char* cd;
-    if (OCRepPayloadGetPropString(input, OC_RSRVD_ES_CD, &cd))
-    {
-        OICStrcpy(gProvResource.cd, sizeof(gProvResource.cd), cd);
-        OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.cd %s", gProvResource.cd);
-    }
-
-    OIC_LOG_V(INFO, ES_RH_TAG, "gProvResource.ps %lld", gProvResource.ps);
-
-    int64_t tr;
-    if (OCRepPayloadGetPropInt(input, OC_RSRVD_ES_TR, &tr))
-    {
-        // Triggering
-        gProvResource.tr = tr;
-    }
+    if(ehRequest->resource == gProvResource.handle)
+        updateProvResource(input);
+    else if(ehRequest->resource == gWiFiResource.handle)
+        updateWiFiResource(input);
+    else if(ehRequest->resource == gCloudResource.handle)
+        updateCloudResource(input);
+    else if(ehRequest->resource == gDevConfResource.handle)
+        updateDevConfResource(input);
 
     //ES_PS_PROVISIONING_COMPLETED state indicates that already provisioning is completed.
     // A new request for provisioning means overriding existing network provisioning information.
-    if (gProvResource.ps == ES_PS_PROVISIONING_COMPLETED && tr == ES_PS_TRIGGER_CONNECTION)
+    if (gProvResource.trigger)
     {
         OIC_LOG(DEBUG, ES_RH_TAG, "Provisioning already completed."
                 "Tiggering the network connection");
@@ -205,25 +543,30 @@ OCEntityHandlerResult ProcessPostRequest(OCEntityHandlerRequest *ehRequest, OCRe
         }
         else
         {
-            gProvResource.tr = ES_PS_TRIGGER_INIT_VALUE;
             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;
         }
-
-        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.");
     }
 
-    OCRepPayload *getResp = constructResponse(ehRequest);
+    OCRepPayload *getResp = NULL;
+    if(ehRequest->resource == gProvResource.handle)
+        getResp = constructResponseOfProv(ehRequest);
+    else if(ehRequest->resource == gWiFiResource.handle)
+        getResp = constructResponseOfWiFi(ehRequest);
+    else if(ehRequest->resource == gCloudResource.handle)
+        getResp = constructResponseOfCloud(ehRequest);
+    else if(ehRequest->resource == gDevConfResource.handle)
+        getResp = constructResponseOfDevConf(ehRequest);
+
+    if (gProvResource.trigger)// Trigger false should be restored after executed
+        gProvResource.trigger = false;
+
     if (!getResp)
     {
         OIC_LOG(ERROR, ES_RH_TAG, "constructResponse failed");
@@ -243,32 +586,6 @@ OCEntityHandlerResult ProcessPutRequest(OCEntityHandlerRequest * ehRequest,
 
     return ehResult;
 }
-
-OCRepPayload* constructResponse(OCEntityHandlerRequest *ehRequest)
-{
-    OCRepPayload* payload = OCRepPayloadCreate();
-    if (!payload)
-    {
-        OIC_LOG(ERROR, ES_RH_TAG, "Failed to allocate Payload");
-        return NULL;
-    }
-
-    if (ehRequest->resource == gProvResource.handle)
-    {
-        OIC_LOG(INFO, ES_RH_TAG, "constructResponse prov res");
-        OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_PROV);
-        OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_PS, gProvResource.ps);
-        OCRepPayloadSetPropInt(payload, OC_RSRVD_ES_TNT, gProvResource.tnt);
-    }
-    else if (ehRequest->requestHandle == gNetResource.handle)
-    {
-
-        OCRepPayloadSetUri(payload, OC_RSRVD_ES_URI_NET);
-        OCRepPayloadSetPropInt(payload, "ant", gNetResource.ant[0]);
-    }
-    return payload;
-}
-
 /**
  * This is the entity handler for the registered resource.
  * This is invoked by OCStack whenever it recevies a request for this resource.
@@ -296,8 +613,7 @@ OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
             OIC_LOG(INFO, ES_RH_TAG, "Received PUT request");
 
             //PUT request will be handled in the internal implementation
-            if (gProvResource.handle != NULL
-                    && entityHandlerRequest->resource == gProvResource.handle)
+            if (gProvResource.handle != NULL)
             {
                 ehRet = ProcessPutRequest(entityHandlerRequest, &payload);
             }
@@ -310,8 +626,7 @@ OCEntityHandlerResult OCEntityHandlerCb(OCEntityHandlerFlag flag,
         else if (OC_REST_POST == entityHandlerRequest->method)
         {
             OIC_LOG(INFO, ES_RH_TAG, "Received OC_REST_POST from client");
-            if (gProvResource.handle != NULL
-                    && entityHandlerRequest->resource == gProvResource.handle)
+            if (gProvResource.handle != NULL)
             {
                 ehRet = ProcessPostRequest(entityHandlerRequest, &payload);
             }
old mode 100644 (file)
new mode 100755 (executable)
index ad470dc..14446ff
@@ -40,25 +40,45 @@ typedef void (*ESEnrolleeResourceEventCallback)(ESResult);
 typedef struct PROVRESOURCE
 {
     OCResourceHandle handle;
-    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.
+    int64_t status; // provisiong status, 1 : need to provisioning, 2 : Connected to Enroller.
+    bool trigger; // Trigger network connection, 0 : Init value, 1 : Connected to the target network.
+    int64_t errorCode;
 } ProvResource;
 
-/* Structure to represent a Light resource */
-typedef struct NETRESOURCE
+typedef struct
 {
     OCResourceHandle handle;
-    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;
+    int64_t supportedMode[NUM_WIFIMODE];
+    uint8_t numMode;
+    int64_t 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;
+} WiFiResource;
+
+typedef struct
+{
+    OCResourceHandle handle;
+    char authCode[OIC_STRING_MAX_VALUE];
+    char authProvider[OIC_STRING_MAX_VALUE];
+    char ciServer[OIC_STRING_MAX_VALUE];
+} CloudResource;
+
+typedef struct
+{
+    OCResourceHandle handle;
+    char devName[OIC_STRING_MAX_VALUE];
+    char language[OIC_STRING_MAX_VALUE];
+    char country[OIC_STRING_MAX_VALUE];
+} DevConfResource;
+
 
 OCStackResult CreateProvisioningResource(bool isSecured);
+OCStackResult CreateEasySetupResources(bool isSecured);
 OCStackResult DeleteProvisioningResource();
+OCStackResult DeleteEasySetupResources();
+
 
 void GetTargetNetworkInfoFromProvResource(char *, char *);
 void RegisterResourceEventCallBack(ESEnrolleeResourceEventCallback);
@@ -68,4 +88,4 @@ void UnRegisterResourceEventCallBack(void);
 }
 #endif
 
-#endif //ES_RESOURCE_HANDLER_H_
\ No newline at end of file
+#endif //ES_RESOURCE_HANDLER_H_
index 17ec815fa0f9f9ad150cf7c886f876948259f138..680a3f2d846e105dd0fc39640ef20f04b7f92b7b 100755 (executable)
 /**
  * Attributes used to form a proper easysetup conforming JSON message.
  */
-#define OC_RSRVD_ES_PS                     "ps"
-#define OC_RSRVD_ES_TNN                    "tnn"
-#define OC_RSRVD_ES_CD                     "cd"
-#define OC_RSRVD_ES_TR                     "tr"
-#define OC_RSRVD_ES_TNT                    "tnt"
-#define OC_RSRVD_ES_ANT                    "ant"
+#define OC_RSRVD_ES_PROVSTATUS             "ps"
+#define OC_RSRVD_ES_ERRORCODE              "ec"
+#define OC_RSRVD_ES_TRIGGER                "tr"
+#define OC_RSRVD_ES_SUPPORTEDWIFIMODE      "swmt"
+#define OC_RSRVD_ES_SUPPORTEDWIFIFREQ      "swf"
+#define OC_RSRVD_ES_SSID                   "tnn"
+#define OC_RSRVD_ES_CRED                   "cd"
+#define OC_RSRVD_ES_AUTHTYPE               "wat"
+#define OC_RSRVD_ES_ENCTYPE                "wet"
+#define OC_RSRVD_ES_AUTHCODE               "ac"
+#define OC_RSRVD_ES_AUTHPROVIDER           "apn"
+#define OC_RSRVD_ES_CISERVER               "cisurl"
+#define OC_RSRVD_ES_DEVNAME                "dn"
+#define OC_RSRVD_ES_LANGUAGE               "lang"
+#define OC_RSRVD_ES_COUNTRY                "cont"
 
 /**
  * Easysetup defined resoruce types and uris.
  */
-#define OC_RSRVD_ES_PROV_RES_TYPE           "oic.r.prov"
-#define OC_RSRVD_ES_URI_PROV               "/oic/prov"
-#define OC_RSRVD_ES_URI_NET                "/oic/net"
+#define OC_RSRVD_ES_RES_TYPE_PROV         "ocf.r.prov"
+#define OC_RSRVD_ES_URI_PROV              "/.well-known/ocf/prov"
+#define OC_RSRVD_ES_RES_TYPE_WIFI         "ocf.r.wifi"
+#define OC_RSRVD_ES_URI_WIFI              "/.well-known/ocf/prov/wifi"
+#define OC_RSRVD_ES_RES_TYPE_CLOUDSERVER  "ocf.r.cloudserver"
+#define OC_RSRVD_ES_URI_CLOUDSERVER       "/.well-known/ocf/prov/cloudserver"
+#define OC_RSRVD_ES_RES_TYPE_DEVCONF      "ocf.r.devconf"
+#define OC_RSRVD_ES_URI_DEVCONF           "/.well-known/ocf/prov/devconf"
 
-/**
- * @brief Defines for Provisioning status accepted values
- */
-#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
+#define OC_RSRVD_ES_URI_NET               "/oic/net"
+
+#define NUM_WIFIMODE    10
+
+typedef enum
+{
+    NO_PROVISION = 0,
+    CONNECTED_ENROLLER,
+    FAILED_CONNECTION
+} PROV_STATUS;
+
+typedef enum
+{
+    WiFi_11A = 0,
+    WiFi_11B,
+    WiFi_11G,
+    WiFi_11N,
+    WiFi_11AC
+} WIFI_MODE;
 
+typedef enum
+{
+    WiFi_24G = 0,
+    WiFi_5G,
+    WiFi_BOTH
+} WIFI_FREQ;
+
+typedef enum
+{
+    NONE_AUTH = 0,
+    WEP,
+    WPA_PSK,
+    WPA2_PSK
+} WIFI_AUTHTYPE;
+
+typedef enum
+{
+    NONE_ENC = 0,
+    WEP_64,
+    WEP_128,
+    TKIP,
+    AES,
+    TKIP_AES
+} WIFI_ENCTYPE;
 
 /**
 * Device Roles defined for each device type used in easy setup
index 0e35382420206ee960fdfebcb1b5b8490b547377..57de9b6911a9529e7c6c902f0f98d62607f6cdb3 100644 (file)
@@ -26,7 +26,7 @@ Import('env')
 target_os = env.get('TARGET_OS')
 
 # Build easy-setup Mediator C SDK
-SConscript('csdk/SConscript')
+#SConscript('csdk/SConscript')
 
 # Build easy-setup Mediator Rich [C++] SDK
 SConscript('richsdk/SConscript')