Allow unicast discovery of Resources and Devices
authorJohn Light <john.j.light@intel.com>
Fri, 24 Jul 2015 19:49:22 +0000 (12:49 -0700)
committerErich Keane <erich.keane@intel.com>
Mon, 3 Aug 2015 16:34:29 +0000 (16:34 +0000)
Response to JIRA IOT-646

Change-Id: I14dea66de0628897b109c2340bf69caa9e40c5a0
Signed-off-by: John Light <john.j.light@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1898
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Rami Jung <rami.jung@samsung.com>
Reviewed-by: Erich Keane <erich.keane@intel.com>
resource/csdk/connectivity/src/ip_adapter/caipserver.c
resource/csdk/stack/src/ocstack.c
resource/src/InProcClientWrapper.cpp

index be047bd..710d69d 100644 (file)
@@ -445,6 +445,7 @@ CAResult_t CAIPStartServer(const ca_thread_pool_t threadPool)
         NEWSOCKET(AF_INET6, u6s)
         NEWSOCKET(AF_INET6, m6)
         NEWSOCKET(AF_INET6, m6s)
+        OIC_LOG_V(INFO, TAG, "IPv6 unicast port: %u", caglobals.ip.u6.port);
     }
     if (caglobals.ip.ipv4enabled)
     {
@@ -452,6 +453,7 @@ CAResult_t CAIPStartServer(const ca_thread_pool_t threadPool)
         NEWSOCKET(AF_INET, u4s)
         NEWSOCKET(AF_INET, m4)
         NEWSOCKET(AF_INET, m4s)
+        OIC_LOG_V(INFO, TAG, "IPv4 unicast port: %u", caglobals.ip.u4.port);
     }
 
     OIC_LOG_V(DEBUG, TAG,
@@ -822,8 +824,13 @@ void CAIPSendData(CAEndpoint_t *endpoint, const void *data, uint32_t datalen,
     }
     else
     {
+        if (!endpoint->port)    // unicast discovery
+        {
+            endpoint->port = isSecure ? CA_SECURE_COAP : CA_COAP;
+        }
+
         int fd;
-        if (endpoint->flags & CA_IPV6)
+        if (caglobals.ip.ipv6enabled && (endpoint->flags & CA_IPV6))
         {
             fd = isSecure ? caglobals.ip.u6s.fd : caglobals.ip.u6.fd;
             #ifndef __WITH_DTLS__
@@ -831,7 +838,7 @@ void CAIPSendData(CAEndpoint_t *endpoint, const void *data, uint32_t datalen,
             #endif
             sendData(fd, endpoint, data, datalen, "unicast", "ipv6");
         }
-        if (endpoint->flags & CA_IPV4)
+        if (caglobals.ip.ipv4enabled && (endpoint->flags & CA_IPV4))
         {
             fd = isSecure ? caglobals.ip.u4s.fd : caglobals.ip.u4.fd;
             #ifndef __WITH_DTLS__
index c5ffe33..e08b430 100644 (file)
@@ -1847,7 +1847,7 @@ static OCStackResult ParseRequestUri(const char *fullUri,
             {
                 return OC_STACK_INVALID_URI;
             }
-            // use standard multicast port
+            // collect port, if any
             if (colon && colon < slash)
             {
                 for (colon++; colon < slash; colon++)
@@ -2049,13 +2049,17 @@ OCStackResult OCDoResource(OCDoHandle *handle,
         break;
     case OC_REST_DISCOVER:
         qos = OC_LOW_QOS;
-        if (!destination && !devAddr)
+        if (destination || devAddr)
+        {
+            requestInfo.isMulticast = false;
+        }
+        else
         {
             destination = &tmpDevAddr;
+            requestInfo.isMulticast = true;
         }
         // CA_DISCOVER will become GET and isMulticast
         requestInfo.method = CA_GET;
-        requestInfo.isMulticast = true;
         break;
     #ifdef WITH_PRESENCE
     case OC_REST_PRESENCE:
index bb794e1..987c0f5 100644 (file)
@@ -177,7 +177,7 @@ namespace OC
     }
 
     OCStackResult InProcClientWrapper::ListenForResource(
-            const std::string& serviceUrl,  // unused
+            const std::string& serviceUrl,
             const std::string& resourceType,
             OCConnectivityType connectivityType,
             FindCallback& callback, QualityOfService QoS)
@@ -188,6 +188,8 @@ namespace OC
         }
 
         OCStackResult result;
+        ostringstream resourceUri;
+        resourceUri << serviceUrl << resourceType;
 
         ClientCallbackContext::ListenContext* context =
             new ClientCallbackContext::ListenContext(callback, shared_from_this());
@@ -202,7 +204,7 @@ namespace OC
         {
             std::lock_guard<std::recursive_mutex> lock(*cLock);
             result = OCDoResource(nullptr, OC_REST_DISCOVER,
-                                  resourceType.c_str(),
+                                  resourceUri.str().c_str(),
                                   nullptr, nullptr, connectivityType,
                                   static_cast<OCQualityOfService>(QoS),
                                   &cbdata,
@@ -238,7 +240,7 @@ namespace OC
     }
 
     OCStackResult InProcClientWrapper::ListenForDevice(
-            const std::string& serviceUrl,  // unused
+            const std::string& serviceUrl,
             const std::string& deviceURI,
             OCConnectivityType connectivityType,
             FindDeviceCallback& callback,
@@ -249,6 +251,8 @@ namespace OC
             return OC_STACK_INVALID_PARAM;
         }
         OCStackResult result;
+        ostringstream deviceUri;
+        deviceUri << serviceUrl << deviceURI;
 
         ClientCallbackContext::DeviceListenContext* context =
             new ClientCallbackContext::DeviceListenContext(callback, shared_from_this());
@@ -263,7 +267,7 @@ namespace OC
         {
             std::lock_guard<std::recursive_mutex> lock(*cLock);
             result = OCDoResource(nullptr, OC_REST_DISCOVER,
-                                  deviceURI.c_str(),
+                                  deviceUri.str().c_str(),
                                   nullptr, nullptr, connectivityType,
                                   static_cast<OCQualityOfService>(QoS),
                                   &cbdata,