Changing DOXM resource to be normally discoverable
authorjs126.lee <js126.lee@samsung.com>
Tue, 7 Jun 2016 11:44:19 +0000 (20:44 +0900)
committerRandeep Singh <randeep.s@samsung.com>
Tue, 14 Jun 2016 02:32:52 +0000 (02:32 +0000)
Issue: DOXM is not listed by default in /oic/res response.
Resolve : Changeg DOXM to be normally discoverable

PT should use secure port of DOXM for OTM and Provision,
even if Device has different COAPS ports per resource.

Patch 1: Init
Patch 2: According to review of Randeep, modified form strcmp to strncmp

Change-Id: I7742681b75261694c809e98f639379332c77e3b5
Signed-off-by: js126.lee <js126.lee@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/8527
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Randeep Singh <randeep.s@samsung.com>
resource/csdk/security/provisioning/src/pmutility.c
resource/csdk/security/src/doxmresource.c
resource/csdk/stack/samples/linux/secure/occlientbasicops.cpp

index 38d1377..e36c166 100644 (file)
@@ -584,6 +584,25 @@ static OCStackApplicationResult SecurePortDiscoveryHandler(void *ctx, OCDoHandle
             uint16_t securePort = 0;
             OCResourcePayload* resPayload = ((OCDiscoveryPayload*)clientResponse->payload)->resources;
 
+            // Use seure port of doxm for OTM and Provision.
+            while (resPayload)
+            {
+                if (0 == strncmp(resPayload->uri, OIC_RSRC_DOXM_URI, sizeof(OIC_RSRC_DOXM_URI)))
+                {
+                    OIC_LOG_V(INFO,TAG,"resPaylod->uri:%s",resPayload->uri);
+                    OIC_LOG(INFO, TAG, "Found doxm resource.");
+                    break;
+                }
+                else
+                {
+                    resPayload = resPayload->next;
+                }
+            }
+            if (NULL == resPayload)
+            {
+                OIC_LOG(ERROR, TAG, "Can not find doxm resource.");
+                return OC_STACK_DELETE_TRANSACTION;
+            }
             if (resPayload && resPayload->secure)
             {
                 securePort = resPayload->port;
@@ -810,21 +829,12 @@ static OCStackResult SecurePortDiscovery(DiscoveryInfo* discoveryInfo,
     {
         return OC_STACK_INVALID_PARAM;
     }
-
-    char rsrc_uri[MAX_URI_LENGTH+1] = {0};
-    int wr_len = snprintf(rsrc_uri, sizeof(rsrc_uri), "%s?%s=%s",
-              OC_RSRVD_WELL_KNOWN_URI, OC_RSRVD_RESOURCE_TYPE, OIC_RSRC_TYPE_SEC_DOXM);
-    if(wr_len <= 0 || (size_t)wr_len >= sizeof(rsrc_uri))
-    {
-        OIC_LOG(ERROR, TAG, "rsrc_uri_string_print failed");
-        return OC_STACK_ERROR;
-    }
     //Try to the unicast discovery to getting secure port
     char query[MAX_URI_LENGTH+MAX_QUERY_LENGTH+1] = {0};
     if(!PMGenerateQuery(false,
                         clientResponse->devAddr.addr, clientResponse->devAddr.port,
                         clientResponse->connType,
-                        query, sizeof(query), rsrc_uri))
+                        query, sizeof(query), OC_RSRVD_WELL_KNOWN_URI))
     {
         OIC_LOG(ERROR, TAG, "SecurePortDiscovery : Failed to generate query");
         return OC_STACK_ERROR;
index 6cfbc4b..ccdfbc8 100644 (file)
@@ -868,7 +868,7 @@ OCStackResult CreateDoxmResource()
                                          DoxmEntityHandler,
                                          NULL,
                                          OC_OBSERVABLE | OC_SECURE |
-                                         OC_EXPLICIT_DISCOVERABLE);
+                                         OC_DISCOVERABLE);
 
     if (OC_STACK_OK != ret)
     {
index f531773..1e7421d 100644 (file)
@@ -52,7 +52,7 @@ static OCConnectivityType ocConnType;
 //of other devices which the client trusts
 static char CRED_FILE_DEVOWNER[] = "oic_svr_db_client_devowner.dat";
 static char CRED_FILE_NONDEVOWNER[] = "oic_svr_db_client_nondevowner.dat";
-
+const char * OIC_RSRC_DOXM_URI =  "/oic/sec/doxm";
 
 int gQuitFlag = 0;
 
@@ -417,9 +417,15 @@ int parseClientResponse(OCClientResponse * clientResponse)
     {
         coapServerResource.assign(res->uri);
         OIC_LOG_V(INFO, TAG, "Uri -- %s", coapServerResource.c_str());
-
+        if (0 == strcmp(coapServerResource.c_str(),OIC_RSRC_DOXM_URI))
+        {
+            OIC_LOG(INFO,TAG,"Skip: doxm is secure virtual resource");
+            res = res->next;
+            continue;
+        }
         if (res->secure)
         {
+        OIC_LOG_V(INFO,TAG,"SECUREPORT: %d",res->port);
             endpoint.port = res->port;
             coapSecureResource = 1;
         }