[IOT-2658][IOT-2443] fix unowned discovery fail 93/22293/8
authoruzchoi <uzchoi@samsung.com>
Fri, 1 Sep 2017 04:07:16 +0000 (13:07 +0900)
committerAshok Babu Channa <ashok.channa@samsung.com>
Tue, 5 Sep 2017 12:19:42 +0000 (12:19 +0000)
During the merge https://gerrit.iotivity.org/gerrit/#/c/21371/,
existing code was excluded for unowned device discovery on secured
build. This fix adds the original fix into the appropriate position.
This issue is also in https://jira.iotivity.org/browse/IOT-2658

Change-Id: I189e4e420bbafff01710a11d298bee61c23cef03
Signed-off-by: uzchoi <uzchoi@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/22293
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
resource/csdk/stack/include/internal/ocstackinternal.h
resource/csdk/stack/src/occollection.c
resource/csdk/stack/src/ocpayload.c
resource/csdk/stack/test/stacktests.cpp

index 697132e..7f2ae2b 100644 (file)
@@ -369,18 +369,19 @@ OCStackResult GetTCPPortInfo(OCDevAddr *endpoint, uint16_t *port, bool secured);
  * This function creates list of OCEndpointPayload structure,
  *  which matches with endpointType from list of CAEndpoint_t.
  *
- * @param[in] endpointType Bit combination of type for Endpoint.
+ * @param[in] colResource collection resource for endpointType and resourceProperties
  * @param[in] devAddr devAddr Structure pointing to the address.
  * @param[in] networkInfo array of CAEndpoint_t
  * @param[in] infoSize size of array
  * @param[out] listHead pointer to HeadNode pointer
- * @param[out] epSize size of array
+ * @param[out] epSize size of array(set NULL not to use it)
+ * @param[out] selfEp endpoint that matches devAddr for use in anchor(set NULL not to use it)
  *
  * @return if success return pointer else NULL
  */
-OCEndpointPayload* CreateEndpointPayloadList(OCTpsSchemeFlags endpointType,
+OCEndpointPayload* CreateEndpointPayloadList(const OCResource* colResource,
     const OCDevAddr *devAddr, CAEndpoint_t *networkInfo,
-    size_t infoSize, OCEndpointPayload **listHead, size_t* epSize);
+    size_t infoSize, OCEndpointPayload **listHead, size_t* epSize, OCEndpointPayload** selfEp);
 
 /*
 * This function returns to destroy endpoint payload
index ee20fee..e7774bc 100644 (file)
@@ -516,8 +516,8 @@ OCRepPayload** BuildCollectionLinksPayloadArray(const char* resourceUri,
             OIC_LOG_V(DEBUG, TAG, "Network Information size = %d", (int) networkSize);
 
             OCEndpointPayload *listHead = NULL;
-            CreateEndpointPayloadList(((OCResource*)colResourceHandle)->endpointType,
-                devAddr, info, networkSize, &listHead, &epSize);
+            CreateEndpointPayloadList((OCResource*)colResourceHandle,
+                devAddr, info, networkSize, &listHead, &epSize, NULL);
             OICFree(info);
             OIC_LOG_V(DEBUG, TAG, "Result of CreateEndpointPayloadList() = %s",
                                   listHead ? "true":"false");
index 58d3cd0..ab392db 100644 (file)
@@ -1803,17 +1803,21 @@ void OC_CALL OCResourcePayloadAddNewEndpoint(OCResourcePayload* payload, OCEndpo
     }
 }
 
-OCEndpointPayload* CreateEndpointPayloadList(OCTpsSchemeFlags endpointType, const OCDevAddr *devAddr,
+OCEndpointPayload* CreateEndpointPayloadList(const OCResource* colResource, const OCDevAddr *devAddr,
                                             CAEndpoint_t *networkInfo, size_t infoSize,
-                                            OCEndpointPayload **listHead, size_t* epSize)
+                         OCEndpointPayload **listHead, size_t* epSize, OCEndpointPayload** selfEp)
 {
     OCEndpointPayload *headNode = NULL;
     OCEndpointPayload *lastNode = NULL;
 
+    VERIFY_PARAM_NON_NULL(TAG, colResource, "Invalid colResource parameter");
     VERIFY_PARAM_NON_NULL(TAG, devAddr, "Invalid devAddr parameter");
     VERIFY_PARAM_NON_NULL(TAG, networkInfo, "Invalid networkInfo parameter");
     VERIFY_PARAM_NON_NULL(TAG, listHead, "Invalid listHead parameter");
-       if (epSize != NULL) *epSize = 0;
+    if (epSize != NULL) *epSize = 0;
+
+    bool includeSecure = colResource->resourceProperties & OC_SECURE;
+    bool includeNonsecure = colResource->resourceProperties & OC_NONSECURE;
 
     if ((OC_ADAPTER_IP | OC_ADAPTER_TCP) & (devAddr->adapter))
     {
@@ -1834,8 +1838,11 @@ OCEndpointPayload* CreateEndpointPayloadList(OCTpsSchemeFlags endpointType, cons
                     goto exit;
                 }
 
-                if ((endpointType) & matchedTps)
+                bool isSecure = (info->flags & OC_FLAG_SECURE);
+                if (((colResource->endpointType) & matchedTps) &&
+                        ((isSecure && includeSecure) || (!isSecure && includeNonsecure)))
                 {
+                    // create payload
                     OCEndpointPayload* tmpNode = (OCEndpointPayload*)
                         OICCalloc(1, sizeof(OCEndpointPayload));
                     if (!tmpNode)
@@ -1866,6 +1873,15 @@ OCEndpointPayload* CreateEndpointPayloadList(OCTpsSchemeFlags endpointType, cons
                     tmpNode->pri  = 1;
                     tmpNode->next = NULL;
 
+                    // remember endpoint that matches devAddr for use in anchor
+                    OCTransportFlags infoFlagsSecureFams = (OCTransportFlags)
+                            (info->flags & MASK_SECURE_FAMS);
+                    if ((selfEp != NULL) &&
+                            ((infoFlagsSecureFams & devAddr->flags) == infoFlagsSecureFams))
+                    {
+                        *selfEp = tmpNode;
+                    }
+
                     // store in list
                     if (!headNode)
                     {
@@ -1912,8 +1928,8 @@ static OCResourcePayload* OCCopyResource(const OCResource* res, uint16_t secureP
     OCEndpointPayload *selfEp = NULL;
     if (networkInfo && infoSize && devAddr)
     {
-        if(!CreateEndpointPayloadList(res->endpointType, devAddr, networkInfo, infoSize,
-                                      &(pl->eps), NULL))
+        if(!CreateEndpointPayloadList(res, devAddr, networkInfo, infoSize,
+                                      &(pl->eps), NULL, &selfEp))
         {
             return NULL;
         }
index f1419df..b6b6651 100644 (file)
@@ -2987,9 +2987,9 @@ TEST(LinksPayloadArray, BuildCollectionLinksPayloadArray)
     InitStack(OC_SERVER);
 
     size_t numResources = 0;
-    uint8_t parentBitmap = OC_DISCOVERABLE | OC_OBSERVABLE;
-    uint8_t inBitmap[2] = { OC_DISCOVERABLE | OC_OBSERVABLE,
-                            OC_DISCOVERABLE };
+    uint8_t parentBitmap = (OC_DISCOVERABLE | OC_OBSERVABLE) | OC_SECURE;
+    uint8_t inBitmap[2] = {( OC_DISCOVERABLE | OC_OBSERVABLE) | OC_SECURE,
+                            OC_DISCOVERABLE | OC_SECURE };
     int64_t outBitmap[2] = { 0 };
 
     OCResourceHandle containerHandle;
@@ -3060,7 +3060,8 @@ TEST(LinksPayloadArray, BuildCollectionLinksPayloadArray)
     {
         ASSERT_TRUE(OCRepPayloadGetPropObject(linksMap[i], OC_RSRVD_POLICY, &policyMap));
         ASSERT_TRUE(OCRepPayloadGetPropInt(policyMap, OC_RSRVD_BITMAP, &outBitmap[i]));
-        EXPECT_EQ(inBitmap[i], outBitmap[i]);
+        // check bitmap excluding secure bit
+        EXPECT_EQ(inBitmap[i] & ~OC_MASK_RESOURCE_SECURE, outBitmap[i]);
 
         if (devAddr)
         {
@@ -3126,7 +3127,8 @@ TEST(LinksPayloadArray, BuildCollectionLinksPayloadArray)
     {
         ASSERT_TRUE(OCRepPayloadGetPropObject(linksMap[i], OC_RSRVD_POLICY, &policyMap));
         ASSERT_TRUE(OCRepPayloadGetPropInt(policyMap, OC_RSRVD_BITMAP, &outBitmap[i]));
-        EXPECT_EQ(inBitmap[i], outBitmap[i]);
+        // check bitmap excluding secure bit
+        EXPECT_EQ(inBitmap[i] & ~OC_MASK_RESOURCE_SECURE, outBitmap[i]);
 
         size_t epsDim[MAX_REP_ARRAY_DEPTH] = { 0 };
         OCRepPayload **epsMap = NULL;
@@ -3157,13 +3159,13 @@ TEST(LinksPayloadArray, BuildCollectionLinksPayloadArray)
             OCRepPayloadDestroy(epsMap[k]);
         }
 
-        ASSERT_GE(coap_scheme_cnt[0], (size_t) 1);
-#ifdef __WITH_TLS__
+#ifdef __WITH_DTLS__
         ASSERT_GE(coap_scheme_cnt[1], (size_t) 1);
 #ifdef TCP_ADAPTER
         ASSERT_GE(coap_scheme_cnt[3], (size_t) 1);
 #endif
 #else
+        ASSERT_GE(coap_scheme_cnt[0], (size_t) 1);
 #ifdef TCP_ADAPTER
         ASSERT_GE(coap_scheme_cnt[2], (size_t) 1);
 #endif