Adding x.com.samsung.deployenv prop 76/196176/1
authorHarish Kumara M <h.marappa@samsung.com>
Wed, 19 Dec 2018 14:43:00 +0000 (20:13 +0530)
committerAmit KS <amit.s12@samsung.com>
Mon, 24 Dec 2018 11:17:43 +0000 (16:47 +0530)
Adding new additional properties "x.com.samsung.deployenv"
and "x.com.samsung.iatt" as vendor properties to
"oic.r.coapcloudconf" easysetup resource.

https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/380
(cherry picked from commit 5b0e8e760da8069c53cf5dd5ef083148c39a2cd2)

Change-Id: Ic307cc1fc2551da143fcdfa15b53db83a7871cb4
Signed-off-by: Harish Kumara M <h.marappa@samsung.com>
Signed-off-by: Amit KS <amit.s12@samsung.com>
service/easy-setup/enrollee/inc/samsung/sc_easysetup.h
service/easy-setup/enrollee/src/samsung/sc_easysetup.c
service/easy-setup/mediator/richsdk/inc/ESSCCommon.h
service/easy-setup/sampleapp/enrollee/linux-samsung/sc_enrollee.c
service/easy-setup/sampleapp/enrollee/linux/enrolleewifi.c
service/easy-setup/sampleapp/mediator/linux-samsung/richsdk_sample/mediator_sc.cpp

index aa56a04..90c5d7d 100644 (file)
@@ -63,6 +63,8 @@
 #define SC_RSRVD_ES_VENDOR_SSID                 "x.com.samsung.ssid"
 #define SC_RSRVD_ES_VENDOR_PASSPHRASE           "x.com.samsung.passphrase"
 #define SC_RSRVD_ES_VENDOR_CANDIDATE_CHANNEL    "x.com.samsung.channel"
+#define SC_RSRVD_ES_VENDOR_DEPLOY_ENVIRONMENT   "x.com.samsung.deployenv"
+#define SC_RSRVD_ES_VENDOR_IATT                 "x.com.samsung.iatt"
 
 #define WIFI_DISCOVERY_CHANNEL_INIT             -1
 
@@ -89,7 +91,7 @@ typedef struct SCWiFiConfProperties
 {
     int discoveryChannel;                   /**< Wi-Fi AP Channel used for fast discovery **/
     char bssid[MAXLEN_STRING];              /**< Wi-Fi bssid information. **/
-    bool isHidden;    
+    bool isHidden;
     int numCandidateAP;
     SCCandidateAPInfo candidateAPInfo[MAXNUM_CANDIDATE_AP];
 } SCWiFiConfProperties;
@@ -125,6 +127,8 @@ typedef struct SCCoapCloudServerConfProperties
     char tncResult[MAXLEN_STRING];              /**< Samsung-specific Terms & Conditions result **/
     char refreshToken[MAXLEN_STRING];           /**< Samsung-specific refreshToken information. Indicate refresh token to be used if the access token is expired**/
     char uid[MAXLEN_STRING];                    /**< Samsung-specific aac information. Indicate user ID corresponding to user account **/
+    char deployEnv[MAXLEN_STRING];              /**< Samsung-specific deployment server with which device is connected to. For example "PROD", "STG" and etc **/
+    int iatt;                                   /**< Samsung-specific Access token type indicator. 0 for SA token, 1 for IoT JWT **/
 } SCCoapCloudServerConfProperties;
 
 typedef struct SCProperties
@@ -161,6 +165,8 @@ typedef struct SCProperties
     char hubId[MAXLEN_STRING];                /**< HubId of device **/
     int numCandidateAP;
     SCCandidateAPInfo candidateAPInfo[MAXNUM_CANDIDATE_AP];
+    char deployEnv[MAXLEN_STRING];
+    int iatt;
 } SCProperties;
 
 void ReadUserdataCb(OCRepPayload* payload, char* resourceType, void** userdata);
index 7ebdbee..0f515fe 100644 (file)
@@ -356,7 +356,7 @@ void ReadUserdataCb(OCRepPayload* payload, char* resourceType, void** userdata)
                 pWifiConfProp->numCandidateAP = (int)dimensions[0];
                 g_SCProperties.numCandidateAP = (int)dimensions[0];
             }
-            
+
             if (OCRepPayloadGetPropBool(payload, SC_RSRVD_ES_VENDOR_HIDDEN, &isHidden))
             {
                 if(*userdata == NULL)
@@ -484,7 +484,8 @@ void ReadUserdataCb(OCRepPayload* payload, char* resourceType, void** userdata)
                     if( *userdata == NULL )
                     {
                         OIC_LOG(ERROR, SC_ENROLLEE_TAG, "OICMalloc for SCCoapCloudServerConfProperties is failed");
-                        return ;
+                        OICFree(clientID);
+                        return;
                     }
                     memset(*userdata, 0, sizeof(SCCoapCloudServerConfProperties));
                 }
@@ -494,6 +495,7 @@ void ReadUserdataCb(OCRepPayload* payload, char* resourceType, void** userdata)
 
                 OICStrcpy(pCloudProp->clientID, strlen(clientID)+1, clientID);
                 OICStrcpy(g_SCProperties.clientID, strlen(clientID)+1, clientID);
+                OICFree(clientID);
 
                 OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %s",
                                         SC_RSRVD_ES_VENDOR_CLIENTID, pCloudProp->clientID);
@@ -509,7 +511,8 @@ void ReadUserdataCb(OCRepPayload* payload, char* resourceType, void** userdata)
                     if( *userdata == NULL )
                     {
                         OIC_LOG(ERROR, SC_ENROLLEE_TAG, "OICMalloc for SCCoapCloudServerConfProperties is failed");
-                        return ;
+                        OICFree(aac);
+                        return;
                     }
                     memset(*userdata, 0, sizeof(SCCoapCloudServerConfProperties));
                 }
@@ -539,7 +542,8 @@ void ReadUserdataCb(OCRepPayload* payload, char* resourceType, void** userdata)
                     if( *userdata == NULL )
                     {
                         OIC_LOG(ERROR, SC_ENROLLEE_TAG, "OICMalloc for SCCoapCloudServerConfProperties is failed");
-                        return ;
+                        OICFree(uid);
+                        return;
                     }
                     memset(*userdata, 0, sizeof(SCCoapCloudServerConfProperties));
                 }
@@ -569,7 +573,8 @@ void ReadUserdataCb(OCRepPayload* payload, char* resourceType, void** userdata)
                     if( *userdata == NULL )
                     {
                         OIC_LOG(ERROR, SC_ENROLLEE_TAG, "OICMalloc for SCCoapCloudServerConfProperties is failed");
-                        return ;
+                        OICFree(refreshToken);
+                        return;
                     }
                     memset(*userdata, 0, sizeof(SCCoapCloudServerConfProperties));
                 }
@@ -589,6 +594,60 @@ void ReadUserdataCb(OCRepPayload* payload, char* resourceType, void** userdata)
                 }
             }
 
+            // SC_RSRVD_ES_VENDOR_DEPLOY_ENVIRONMENT
+            char *deployEnv = NULL;
+            if (OCRepPayloadGetPropString(payload, SC_RSRVD_ES_VENDOR_DEPLOY_ENVIRONMENT, &deployEnv))
+            {
+                if(*userdata == NULL)
+                {
+                    *userdata = (void*)OICMalloc(sizeof(SCCoapCloudServerConfProperties));
+                    if( *userdata == NULL )
+                    {
+                        OIC_LOG(ERROR, SC_ENROLLEE_TAG, "OICMalloc for SCCoapCloudServerConfProperties is failed");
+                        OICFree(deployEnv);
+                        return;
+                    }
+                    memset(*userdata, 0, sizeof(SCCoapCloudServerConfProperties));
+                }
+
+                if (*userdata != NULL)
+                {
+                    SCCoapCloudServerConfProperties *pCloudProp =
+                                                    (SCCoapCloudServerConfProperties*) (*userdata);
+                    OICStrcpy(pCloudProp->deployEnv, MAXLEN_STRING, deployEnv);
+                    OICStrcpy(g_SCProperties.deployEnv, MAXLEN_STRING, deployEnv);
+                    OICFree(deployEnv);
+
+                    OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %s",
+                            SC_RSRVD_ES_VENDOR_REFRESH_TOKEN, pCloudProp->deployEnv);
+                }
+            }
+
+            // SC_RSRVD_ES_VENDOR_IATT
+            int64_t iatt;
+            if (OCRepPayloadGetPropInt(payload, SC_RSRVD_ES_VENDOR_IATT, &iatt))
+            {
+                if(*userdata == NULL)
+                {
+                    *userdata = (void*)OICMalloc(sizeof(SCCoapCloudServerConfProperties));
+                    if( *userdata == NULL )
+                    {
+                        OIC_LOG(ERROR, SC_ENROLLEE_TAG, "OICMalloc for SCCoapCloudServerConfProperties is failed");
+                        return;
+                    }
+                    memset(*userdata, 0, sizeof(SCCoapCloudServerConfProperties));
+                }
+
+                SCCoapCloudServerConfProperties *pCloudProp =
+                                                (SCCoapCloudServerConfProperties*) (*userdata);
+
+                pCloudProp->iatt = iatt;
+                g_SCProperties.iatt = iatt;
+
+                OIC_LOG_V(INFO_PRIVATE, SC_ENROLLEE_TAG, "[User specific property] %s : %d",
+                        SC_RSRVD_ES_VENDOR_REFRESH_TOKEN, pCloudProp->iatt);
+            }
+
             ReadTnCdata(payload,userdata);
         }
     }
@@ -632,7 +691,7 @@ void WriteUserdataCb(OCRepPayload* payload, char* resourceType)
             size_t dimensions[MAX_REP_ARRAY_DEPTH] = {g_SCProperties.numCandidateAP, 0, 0};
             OCRepPayloadSetPropObjectArray(payload,SC_RSRVD_ES_VENDOR_CANDIDATEAPS, (const struct OCRepPayload **)repPayload, dimensions);
         }
-        if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_DEVCONF))
+        else if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_DEVCONF))
         {
 #ifndef __TIZENRT__
             OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_DEVICE_TYPE, g_SCProperties.deviceType);
@@ -705,6 +764,17 @@ void WriteUserdataCb(OCRepPayload* payload, char* resourceType)
             }
 #endif
         }
+        else if(strstr(resourceType, OC_RSRVD_ES_RES_TYPE_COAPCLOUDCONF))
+        {
+            // x.com.samsung.deployenv
+            if (g_SCProperties.deployEnv != NULL)
+            {
+                OCRepPayloadSetPropString(payload, SC_RSRVD_ES_VENDOR_DEPLOY_ENVIRONMENT, g_SCProperties.deployEnv);
+            }
+
+            // x.com.samsung.iatt
+            OCRepPayloadSetPropInt(payload, SC_RSRVD_ES_VENDOR_IATT, g_SCProperties.iatt);
+        }
     }
 
     WriteTnCdata(payload, resourceType);
index db59319..ff298c2 100644 (file)
@@ -33,10 +33,10 @@ using namespace std;
 #define SC_RSRVD_ES_VENDOR_LOCATION             "x.com.samsung.location"
 #define SC_RSRVD_ES_VENDOR_CLIENTID             "x.com.samsung.clientid"
 #define SC_RSRVD_ES_VENDOR_ACCOUNT              "x.com.samsung.account"
-#define SC_RSRVD_ES_VENDOR_SSO_LIST            "x.com.samsung.ssolist"
+#define SC_RSRVD_ES_VENDOR_SSO_LIST             "x.com.samsung.ssolist"
 #define SC_RSRVD_ES_VENDOR_ADDITIONAL_AUTH_CODE "x.com.samsung.aac"
-#define SC_RSRVD_ES_VENDOR_SA_API_SERVER       "x.com.samsung.saapiserver"
-#define SC_RSRVD_ES_VENDOR_SA_AUTH_SERVER      "x.com.samsung.saauthserver"
+#define SC_RSRVD_ES_VENDOR_SA_API_SERVER        "x.com.samsung.saapiserver"
+#define SC_RSRVD_ES_VENDOR_SA_AUTH_SERVER       "x.com.samsung.saauthserver"
 #define SC_RSRVD_ES_VENDOR_SA_DEVICE_SECURITY_CODE "x.com.samsung.sadsc"
 #define SC_RSRVD_ES_VENDOR_ACCESS_TOKEN         "x.com.samsung.accesstoken"
 #define SC_RSRVD_ES_VENDOR_REFRESH_TOKEN        "x.com.samsung.refreshtoken"
@@ -64,8 +64,9 @@ using namespace std;
 #define SC_RSRVD_ES_VENDOR_SERVER_ID            "x.com.samsung.serverid"
 #define SC_RSRVD_ES_VENDOR_TIMEZONE_ID          "x.com.samsung.timezoneid"
 #define SC_RSRVD_ES_VENDOR_HIDDEN               "x.com.samsung.hidden"
-#define SC_RSRVD_ES_VENDOR_HUB_ID              "x.com.samsung.hubid"
-#define SC_RSRVD_ES_VENDOR_SERVER_DEPLOYMENT_ENVIRONMENT "x.com.samsung.deployenv"
+#define SC_RSRVD_ES_VENDOR_HUB_ID               "x.com.samsung.hubid"
+#define SC_RSRVD_ES_VENDOR_DEPLOY_ENVIRONMENT   "x.com.samsung.deployenv"
+#define SC_RSRVD_ES_VENDOR_IATT                 "x.com.samsung.iatt"
 #define SC_RSRVD_ES_VENDOR_CANDIDATEAPS         "x.com.samsung.candidateaps"
 #define SC_RSRVD_ES_VENDOR_SSID                 "x.com.samsung.ssid"
 #define SC_RSRVD_ES_VENDOR_PASSPHRASE           "x.com.samsung.passphrase"
@@ -631,7 +632,7 @@ namespace OIC
              */
             void setServerDeploymentEnv(const std::string &serverDeploymentEnv)
             {
-                m_rep.setValue(SC_RSRVD_ES_VENDOR_SERVER_DEPLOYMENT_ENVIRONMENT, serverDeploymentEnv);
+                m_rep.setValue(SC_RSRVD_ES_VENDOR_DEPLOY_ENVIRONMENT, serverDeploymentEnv);
             }
 
             /**
@@ -641,14 +642,38 @@ namespace OIC
              */
             std::string getServerDeploymentEnv()
             {
-                if (m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_SERVER_DEPLOYMENT_ENVIRONMENT))
+                if (m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_DEPLOY_ENVIRONMENT))
                 {
-                    return m_rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_SERVER_DEPLOYMENT_ENVIRONMENT);
+                    return m_rep.getValue<std::string>(SC_RSRVD_ES_VENDOR_DEPLOY_ENVIRONMENT);
                 }
                 return {};
             }
 
             /**
+             * Set Access token type.
+             *
+             * @param type - Access token type
+             */
+            void setAccessTokenType(const int type)
+            {
+                m_rep.setValue(SC_RSRVD_ES_VENDOR_IATT, type);
+            }
+
+            /**
+             * Get Access token type.
+             *
+             * @return Access token type.
+             */
+            int getAccessTokenType(void)
+            {
+                if (m_rep.hasAttribute(SC_RSRVD_ES_VENDOR_IATT))
+                {
+                    return m_rep.getValue<int>(SC_RSRVD_ES_VENDOR_IATT);
+                }
+                return 0;
+            }
+
+            /**
              * Set samsung-specific refresh token property to be delivered to Enrollee
              *
              * @param refreshtoken - Refresh token.
@@ -1323,7 +1348,7 @@ namespace OIC
                 }
                 return std::string("");
             }
-            
+
             /**
              * Gets the HubId of the device
              *
index 67e2c99..149f516 100644 (file)
@@ -125,25 +125,31 @@ void DevConfProvCbInApp(ESDevConfData *eventData)
 
 void CloudDataProvCbInApp(ESCoapCloudConfData *eventData)
 {
-    printf("CloudDataProvCbInApp IN\n");
+    printf("Cloud provisioning data received\n");
 
     if(eventData == NULL)
     {
         printf("ESCloudProvData is NULL\n");
-        return ;
+        return;
     }
 
     printf("AuthCode : %s\n", eventData->authCode);
+    printf("AcessToken : %s\n", eventData->accessToken);
+    printf("AcessTokenType : %d\n", eventData->accessTokenType);
     printf("AuthProvider : %s\n", eventData->authProvider);
     printf("CI Server : %s\n", eventData->ciServer);
 
     if(eventData->userdata != NULL)
     {
         SCCoapCloudServerConfProperties *data = eventData->userdata;
-        printf("[SC] ClientID : %s\n", data->clientID);
+        printf("[SC] Client id : %s\n", data->clientID);
+        printf("[SC] aac : %s\n", data->aac);
+        printf("[SC] TNC result : %s\n", data->tncResult);
+        printf("[SC] Refresh token : %s\n", data->refreshToken);
+        printf("[SC] UID : %s\n", data->uid);
+        printf("[SC] Deploy Env : %s\n", data->deployEnv);
+        printf("[SC] iatt : %d\n", data->iatt);
     }
-
-    printf("CloudDataProvCbInApp OUT\n");
 }
 
 ESProvisioningCallbacks gCallbacks = {
index 9382581..ed828c8 100755 (executable)
@@ -123,12 +123,12 @@ void DevConfProvCbInApp(ESDevConfData *eventData)
 
 void CoapCloudConfProvCbInApp(ESCoapCloudConfData *eventData)
 {
-    printf("CoapCloudConfProvCbInApp IN\n");
+    printf("Cloud provisioning data received\n");
 
     if(eventData == NULL)
     {
         printf("ESCoapCloudConfData is NULL\n");
-        return ;
+        return;
     }
 
     printf("AuthCode : %s\n", eventData->authCode);
@@ -136,8 +136,6 @@ void CoapCloudConfProvCbInApp(ESCoapCloudConfData *eventData)
     printf("AcessTokenType : %d\n", eventData->accessTokenType);
     printf("AuthProvider : %s\n", eventData->authProvider);
     printf("CI Server : %s\n", eventData->ciServer);
-
-    printf("CoapCloudConfProvCbInApp OUT\n");
 }
 
 ESProvisioningCallbacks gCallbacks = {
@@ -329,7 +327,7 @@ void *listeningFunc(void * data)
            printf("OCProcess error");
         }
 
-               // Sleep for 100 ms to avoid high CPU Utilization.              
+               // Sleep for 100 ms to avoid high CPU Utilization.
                usleep(100 * 1000); // 100 milli-seconds
     }
     return NULL;
index 2cffbf6..b25b28a 100644 (file)
@@ -312,6 +312,10 @@ void provisionCloudProperty()
     cloudProp.setCredID(1);
     cloudProp.setClientID("166135d296");
 
+    // Set samsung specific properties
+    cloudProp.setServerDeploymentEnv("PROD");
+    cloudProp.setAccessTokenType(1);
+
     try
     {
         remoteEnrollee->provisionCloudProperties(cloudProp, cloudProvisioningStatusCallback);