[IOT-1906] Disable only /oic/res response under OCStopMulticastServer.
authorTodd Malsbary <todd.malsbary@intel.com>
Thu, 2 Mar 2017 22:14:03 +0000 (14:14 -0800)
committerDan Mihai <Daniel.Mihai@microsoft.com>
Mon, 13 Mar 2017 17:57:02 +0000 (17:57 +0000)
The intent of this API is to stop responding to /oic/res responses
when resources are registered with a resource directory.  Stopping all
multicast reception prevents ownership transfer from working.

Bug: https://jira.iotivity.org/browse/IOT-1906
Change-Id: I01e183b6f5a249a4d0e32baf14f542774a3ca0cb
Signed-off-by: Todd Malsbary <todd.malsbary@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17633
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
resource/csdk/stack/include/ocstack.h
resource/csdk/stack/src/ocresource.c
resource/csdk/stack/src/ocstack.c

index 872114e..dede976 100644 (file)
@@ -101,19 +101,20 @@ OCStackResult OCSetRAInfo(const OCRAInfo_t *raInfo);
 OCStackResult OCStop();
 
 /**
- * This function starts receiving the multicast traffic. This can be only called
- * when stack is in OC_STACK_INITIALIZED state but device is not receiving multicast
- * traffic.
+ * This function starts responding to multicast /oic/res requests.  This can be
+ * only called when stack is in OC_STACK_INITIALIZED state but device is not
+ * receiving multicast traffic.
  *
  * @return ::OC_STACK_OK on success, some other value upon failure.
  */
 OCStackResult OCStartMulticastServer();
 
 /**
- * This function stops receiving the multicast traffic. The rest of the stack
- * keeps working and no resource are deleted. Device can still receive the unicast
- * traffic. Once this is set, no response to multicast /oic/res will be sent by the
- * device. This is to be used for devices that uses other entity to push resources.
+ * This function stops responding to multicast /oic/res requests.  This is to be
+ * used for devices that uses other entity to push resources.
+ *
+ * Note that other multicast requests, such as those used during ownership
+ * transfer, continue to be responded to.
  *
  * @return ::OC_STACK_OK on success, some other value upon failure.
  */
index abc4994..ae86922 100755 (executable)
@@ -83,6 +83,7 @@ static const uint16_t CBOR_SIZE = 512;
 static const uint16_t CBOR_MAX_SIZE = 4400;
 
 extern OCResource *headResource;
+extern bool g_multicastServerStopped;
 
 /**
  * Prepares a Payload for response.
@@ -1829,6 +1830,14 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource
 #endif
             )
     {
+        if (g_multicastServerStopped && !isUnicast(request))
+        {
+            // Ignore the discovery request
+            FindAndDeleteServerRequest(request);
+            discoveryResult = OC_STACK_CONTINUE;
+            goto exit;
+        }
+
         char *interfaceQuery = NULL;
         char *resourceTypeQuery = NULL;
 
@@ -1988,7 +1997,6 @@ static OCStackResult HandleVirtualResource (OCServerRequest *request, OCResource
         OIC_LOG_PAYLOAD(DEBUG, payload);
         if(discoveryResult == OC_STACK_OK)
         {
-
             SendNonPersistantDiscoveryResponse(request, resource, payload, OC_EH_OK);
         }
         else // Error handling
@@ -2083,7 +2091,6 @@ HandleResourceWithEntityHandler(OCServerRequest *request,
     if (request && request->resourceUrl && SRMIsSecurityResourceURI(request->resourceUrl))
     {
         type = PAYLOAD_TYPE_SECURITY;
-
     }
 
     result = EHRequest(&ehRequest, type, request, resource);
index ccfb97c..cbba02f 100644 (file)
@@ -167,6 +167,8 @@ uint32_t g_ocStackStartCount = 0;
 // Number of threads currently executing OCInit2 or OCStop
 volatile int32_t g_ocStackStartStopThreadCount = 0;
 
+bool g_multicastServerStopped = false;
+
 //-----------------------------------------------------------------------------
 // Macros
 //-----------------------------------------------------------------------------
@@ -2756,23 +2758,13 @@ OCStackResult OCStartMulticastServer()
         OIC_LOG(ERROR, TAG, "OCStack is not initalized. Cannot start multicast server.");
         return OC_STACK_ERROR;
     }
-    CAResult_t ret = CAStartListeningServer();
-    if (CA_STATUS_OK != ret)
-    {
-        OIC_LOG_V(ERROR, TAG, "Failed starting listening server: %d", ret);
-        return OC_STACK_ERROR;
-    }
+    g_multicastServerStopped = false;
     return OC_STACK_OK;
 }
 
 OCStackResult OCStopMulticastServer()
 {
-    CAResult_t ret = CAStopListeningServer();
-    if (CA_STATUS_OK != ret)
-    {
-        OIC_LOG_V(ERROR, TAG, "Failed stopping listening server: %d", ret);
-        return OC_STACK_ERROR;
-    }
+    g_multicastServerStopped = true;
     return OC_STACK_OK;
 }