OCMulticast start and stop APIs
authorHabib Virji <habib.virji@samsung.com>
Fri, 25 Sep 2015 01:25:39 +0000 (02:25 +0100)
committerPatrick Lankswert <patrick.lankswert@intel.com>
Tue, 29 Sep 2015 23:16:31 +0000 (23:16 +0000)
APIs to start and stop multicast traffic. For stopping and staring multicast traffic
it manipulates multicast fd and IP_DROP_MEMBERSHIP.

OCStopMulticastTraffic interface is called from rd_client. It stops the multicast traffic.

OCStartMulticastTraffic is implemented but it is not called as this functionality is
not yet implemented.

Change-Id: If56c7af074cbba097b7b23d1abd787093872418a
Signed-off-by: Habib Virji <habib.virji@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2387
Reviewed-by: Abhishek Sharma <ce.abhishek@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Abhishek Pandey <abhi.siso@samsung.com>
Reviewed-by: Patrick Lankswert <patrick.lankswert@intel.com>
25 files changed:
resource/csdk/connectivity/api/cainterface.h
resource/csdk/connectivity/inc/caadapterinterface.h
resource/csdk/connectivity/inc/caedradapter.h
resource/csdk/connectivity/inc/caedradapter_singlethread.h
resource/csdk/connectivity/inc/cainterfacecontroller.h
resource/csdk/connectivity/inc/cainterfacecontroller_singlethread.h
resource/csdk/connectivity/inc/caipadapter.h
resource/csdk/connectivity/inc/caipinterface.h
resource/csdk/connectivity/inc/caraadapter.h
resource/csdk/connectivity/inc/catcpadapter.h
resource/csdk/connectivity/src/bt_edr_adapter/caedradapter.c
resource/csdk/connectivity/src/bt_edr_adapter/linux/caedradapter.c
resource/csdk/connectivity/src/bt_le_adapter/caleadapter.c
resource/csdk/connectivity/src/caconnectivitymanager.c
resource/csdk/connectivity/src/cainterfacecontroller.c
resource/csdk/connectivity/src/ip_adapter/arduino/caipserver_eth.cpp
resource/csdk/connectivity/src/ip_adapter/arduino/caipserver_wifi.cpp
resource/csdk/connectivity/src/ip_adapter/caipadapter.c
resource/csdk/connectivity/src/ip_adapter/caipserver.c
resource/csdk/connectivity/src/ra_adapter/caraadapter.c
resource/csdk/connectivity/src/tcp_adapter/catcpadapter.c
resource/csdk/stack/include/ocstack.h
resource/csdk/stack/src/ocstack.c
service/SConscript
service/resource-directory/src/rd_client.c

index 7449b28..0c16260 100644 (file)
@@ -111,6 +111,13 @@ void CATerminate();
 CAResult_t CAStartListeningServer();
 
 /**
+ * Stops the server from receiving the multicast traffic. This is used by sleeping
+ * device to not receives the multicast traffic.
+ * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED
+ */
+CAResult_t CAStopListeningServer();
+
+/**
  * Starts discovery servers.
  * This API is used by resource required clients for listening multicast requests.
  * Based on the adapters configurations, different kinds of servers are started.
index a750291..50df459 100644 (file)
@@ -59,6 +59,17 @@ typedef CAResult_t (*CAAdapterStart)();
 typedef CAResult_t (*CAAdapterStartListeningServer)();
 
 /**
+ * Stopping listening server to not receive multicast search requests
+ * Transport Specific Behavior:
+ * WIFI/ETH Stops multicast server on  all available IPs. This is required for the
+ * thin device that call this function once all local resources are pushed to the
+ * resource directory.
+ * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED
+ * ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+typedef CAResult_t (*CAAdapterStopListeningServer)();
+
+/**
  * for starting discovery servers for receiving multicast advertisements
  * Transport Specific Behavior:
  * WIFI/ETH Starts multicast server on all available IPs and defined port
@@ -134,6 +145,9 @@ typedef struct
     /** Listening Server function address. */
     CAAdapterStartListeningServer startListenServer;
 
+    /** Stops receiving the multicast traffic. */
+    CAAdapterStopListeningServer stopListenServer;
+
     /** Discovery Server function address. **/
     CAAdapterStartDiscoveryServer startDiscoveryServer;
 
index 7c4a868..88794e3 100644 (file)
@@ -72,6 +72,14 @@ CAResult_t CAStartEDR();
 CAResult_t CAStartEDRListeningServer();
 
 /**
+ * Stop listening server for receiving multicast search requests.
+ * Stop  RFCOMM Server with prefixed UUID as per OIC specification.
+ *
+ * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CAStopEDRListeningServer();
+
+/**
  * Starting discovery server for receiving multicast advertisements.
  * Starts  RFCOMM Server with prefixed UUID as per OIC specification.
  *
index eea4e42..f2422ae 100644 (file)
@@ -79,6 +79,13 @@ CAResult_t CAStartEDR();
 CAResult_t CAStartEDRListeningServer();
 
 /**
+ * @brief  Stops listening server for receiving multicast search requests.
+ *
+ * @return #CA_STATUS_OK or Appropriate error code
+ */
+CAResult_t CAStopEDRListeningServer();
+
+/**
  * @brief  Starts discovery server for receiving multicast advertisements.
  *         Starts RFCOMM Server with prefixed UUID as per OIC specification.
  * @return #CA_STATUS_OK or Appropriate error code
index 94216d8..5240935 100644 (file)
@@ -130,6 +130,12 @@ CAResult_t CASendMulticastData(const CAEndpoint_t *endpoint, const void *data, u
 CAResult_t CAStartListeningServerAdapters();
 
 /**
+ * Stop listening servers to receive search requests from clients.
+ * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
+ */
+CAResult_t CAStopListeningServerAdapters();
+
+/**
  * Start discovery servers to receive advertisements from server.
  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
  */
index db003a2..b8234f9 100644 (file)
@@ -113,6 +113,12 @@ CAResult_t CASendMulticastData(const CAEndpoint_t *endpoint, const void *data, u
 CAResult_t CAStartListeningServerAdapters();
 
 /**
+ * @brief   Stops listening servers to receive search requests from clients
+ * @return   CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
+ */
+CAResult_t CAStopListeningServerAdapters();
+
+/**
  * @brief   Start discovery servers to receive advertisements from server
  * @return   CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
  */
index fe280f8..e7fa8c0 100644 (file)
@@ -69,6 +69,14 @@ CAResult_t CAStartIP();
 CAResult_t CAStartIPListeningServer();
 
 /**
+ * Stop listening server from receiving multicast search requests.
+ * Transport Specific Behavior:
+ * IP closes open multicast socket for a particular interface.
+ * @return  ::CA_STATUS_OK or Appropriate error code.
+ */
+CAResult_t CAStopIPListeningServer();
+
+/**
  * Start discovery servers for receiving multicast advertisements.
  * Transport Specific Behavior:
  * IP Starts multicast server on a particular interface and prefixed port
index 7aeb391..ff344f0 100644 (file)
@@ -99,6 +99,23 @@ CAResult_t CAIPStartServer(const ca_thread_pool_t threadPool);
 void CAIPStopServer();
 
 /**
+ * Starts receiving the multicast traffic.
+ *
+ * This will be used in case sleepy device wants to start back receiving the multicast
+ * traffic.
+ */
+CAResult_t CAIPStartListenServer();
+
+/**
+ * Stops the multicast traffic.
+ *
+ * This is to be used by the sleeping device to stop receiving multicast traffic.
+ * Once this is set no multicast traffic will be received. Device can still receive
+ * the unicast traffic.
+ */
+CAResult_t CAIPStopListenServer();
+
+/**
  * Set this callback for receiving data packets from peer devices.
  *
  * @param[in]  callback    Callback to be notified on reception of unicast/multicast data packets.
index 32656ba..5b9c04c 100644 (file)
@@ -115,6 +115,12 @@ int32_t CASendRAMulticastData(const CAEndpoint_t *endpoint,
 CAResult_t CAStartRAListeningServer();
 
 /**
+ * Stops listening server from receiving search requests.
+ * @return  ::CA_NOT_SUPPORTED.
+ */
+CAResult_t CAStopRAListeningServer();
+
+/**
  * Start discovery servers for receiving advertisements.
  * @return  ::CA_NOT_SUPPORTED.
  */
index 1938221..14b2c8e 100644 (file)
@@ -78,6 +78,15 @@ CAResult_t CAStartTCP();
 CAResult_t CAStartTCPListeningServer();
 
 /**
+ * Stops listening server from receiving connect requests.
+ * Transport Specific Behavior:
+ * TCP Stops Listening Server on a particular interface and prefixed port
+ * number and as per OIC Specification.
+ * @return  ::CA_STATUS_OK or Appropriate error code.
+ */
+CAResult_t CAStopTCPListeningServer();
+
+/**
  * Start discovery servers for receiving advertisements.
  * Transport Specific Behavior:
  * TCP Starts Discovery server on a particular interface and prefixed port
index ab48394..cf90302 100644 (file)
@@ -199,6 +199,7 @@ CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
     CAConnectivityHandler_t handler;
     handler.startAdapter = CAStartEDR;
     handler.startListenServer = CAStartEDRListeningServer;
+    handler.stopListenServer = CAStopEDRListeningServer;
     handler.startDiscoveryServer = CAStartEDRDiscoveryServer;
     handler.sendData = CASendEDRUnicastData;
     handler.sendDataToAll = CASendEDRMulticastData;
@@ -268,6 +269,13 @@ CAResult_t CAStartEDRListeningServer()
     return CAStartServer();
 }
 
+CAResult_t CAStopEDRListeningServer()
+{
+    OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
+
+    return CAEDRServerStop();
+}
+
 CAResult_t CAStartEDRDiscoveryServer()
 {
     OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
index 9304797..4ed9085 100644 (file)
@@ -46,6 +46,7 @@ CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
     CAConnectivityHandler_t handler = {
         .startAdapter = CAStartEDR,
         .startListenServer = CAStartEDRListeningServer,
+        .stopListenServer = CAStopEDRListeningServer,
         .startDiscoveryServer = CAStartEDRDiscoveryServer,
         .sendData = CASendEDRUnicastData,
         .sendDataToAll = CASendEDRMulticastData,
@@ -74,6 +75,13 @@ CAResult_t CAStartEDRListeningServer()
     return CA_STATUS_OK;
 }
 
+CAResult_t CAStopEDRListeningServer()
+{
+    OIC_LOG(DEBUG, TAG, "CAStopEDRListeningServer");
+
+    return CA_STATUS_OK;
+}
+
 CAResult_t CAStartEDRDiscoveryServer()
 {
     OIC_LOG(DEBUG, TAG, "CAStartEDRDiscoveryServer");
index 60cffdb..571a890 100644 (file)
@@ -1447,6 +1447,16 @@ static CAResult_t CAStartLE();
 static CAResult_t CAStartLEListeningServer();
 
 /**
+ * Stops listening server from receiving multicast search requests.
+ *
+ * Transport Specific Behavior:
+ *   LE  Starts GATT Server with prefixed UUID and Characteristics
+ *   per OIC Specification.
+ * @return  ::CA_STATUS_OK or Appropriate error code.
+ */
+static CAResult_t CAStopLEListeningServer();
+
+/**
  * Sarting discovery of servers for receiving multicast
  * advertisements.
  *
@@ -1661,6 +1671,7 @@ CAResult_t CAInitializeLE(CARegisterConnectivityCallback registerCallback,
             .startAdapter = CAStartLE,
             .stopAdapter = CAStopLE,
             .startListenServer = CAStartLEListeningServer,
+            .stopListenServer = CAStopLEListeningServer,
             .startDiscoveryServer = CAStartLEDiscoveryServer,
             .sendData = CASendLEUnicastData,
             .sendDataToAll = CASendLEMulticastData,
@@ -1778,6 +1789,12 @@ static CAResult_t CAStartLEListeningServer()
 #endif
 }
 
+static CAResult_t CAStopLEListeningServer()
+{
+    OIC_LOG(ERROR, CALEADAPTER_TAG, "Listen server stop not supported.");
+    return CA_NOT_SUPPORTED;
+}
+
 static CAResult_t CAStartLEDiscoveryServer()
 {
     OIC_LOG(DEBUG, CALEADAPTER_TAG, "IN");
index f37f38e..b9f8f04 100644 (file)
@@ -92,6 +92,18 @@ CAResult_t CAStartListeningServer()
     return CAStartListeningServerAdapters();
 }
 
+CAResult_t CAStopListeningServer()
+{
+    OIC_LOG(DEBUG, TAG, "CAStopListeningServer");
+
+    if(!g_isInitialized)
+    {
+        return CA_STATUS_NOT_INITIALIZED;
+    }
+
+    return CAStopListeningServerAdapters();
+}
+
 CAResult_t CAStartDiscoveryServer()
 {
     OIC_LOG(DEBUG, TAG, "CAStartDiscoveryServer");
index 0e06e6b..71124d3 100644 (file)
@@ -97,6 +97,7 @@ static void CARegisterCallback(CAConnectivityHandler_t handler, CATransportAdapt
 
     if(handler.startAdapter == NULL ||
         handler.startListenServer == NULL ||
+        handler.stopListenServer == NULL ||
         handler.startDiscoveryServer == NULL ||
         handler.sendData == NULL ||
         handler.sendDataToAll == NULL ||
@@ -503,6 +504,44 @@ CAResult_t CAStartListeningServerAdapters()
     return CA_STATUS_OK;
 }
 
+CAResult_t CAStopListeningServerAdapters()
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+
+    u_arraylist_t *list = CAGetSelectedNetworkList();
+    if (!list)
+    {
+        OIC_LOG(ERROR, TAG, "No selected network");
+        return CA_STATUS_FAILED;
+    }
+
+    for (uint32_t i = 0; i < u_arraylist_length(list); i++)
+    {
+        void* ptrType = u_arraylist_get(list, i);
+        if(ptrType == NULL)
+        {
+            continue;
+        }
+
+        CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType;
+
+        int index = CAGetAdapterIndex(connType);
+        if (index == -1)
+        {
+            OIC_LOG(ERROR, TAG, "unknown connectivity type!");
+            continue;
+        }
+
+        if (g_adapterHandler[index].stopListenServer != NULL)
+        {
+            g_adapterHandler[index].stopListenServer();
+        }
+    }
+
+    OIC_LOG(DEBUG, TAG, "OUT");
+    return CA_STATUS_OK;
+}
+
 CAResult_t CAStartDiscoveryServerAdapters()
 {
     OIC_LOG(DEBUG, TAG, "IN");
index 5f46dd3..b28c7e5 100644 (file)
 // Length of the IP address decimal notation string
 #define IPNAMESIZE (16)
 
+/** Multicast IP address.*/
+#define IPv4_MULTICAST      "224.0.1.187"
+
+/** Multicast Port.*/
+#define IPv4_MULTICAST_PORT 5683
+
 CAResult_t CAIPStartUnicastServer(const char *localAddress, uint16_t *port,
                                         const bool forceStart, int32_t *serverFD);
 static CAResult_t CAArduinoRecvData(int32_t sockFd);
@@ -146,7 +152,7 @@ CAResult_t CAIPStartServer()
         OIC_LOG_V(ERROR, TAG, "Start unicast server failed[%d]", ret);
         return ret;
     }
-    ret = CAIPStartMulticastServer("0.0.0.0", "224.0.1.187", 5683);
+    ret = CAIPStartMulticastServer("0.0.0.0", IPv4_MULTICAST, IPv4_MULTICAST_PORT);
     if (CA_STATUS_OK != ret)
     {
         OIC_LOG_V(ERROR, TAG, "Start multicast failed[%d]", ret);
@@ -173,6 +179,30 @@ CAResult_t CAIPStopMulticastServer()
     return CA_STATUS_OK;
 }
 
+CAResult_t CAIPStartListenServer()
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    CAResult_t ret = CAIPStartMulticastServer("0.0.0.0", IPv4_MULTICAST, IPv4_MULTICAST_PORT);
+    if (CA_STATUS_OK != ret)
+    {
+        OIC_LOG_V(ERROR, TAG, "Start multicast failed[%d]", ret);
+    }
+    OIC_LOG(DEBUG, TAG, "OUT");
+    return CA_STATUS_OK;
+}
+
+CAResult_t CAIPStopListenServer()
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    CAResult_t ret = CAIPStopMulticastServer();
+    if (CA_STATUS_OK != ret)
+    {
+        OIC_LOG_V(ERROR, TAG, "Stop multicast failed[%d]", ret);
+    }
+    OIC_LOG(DEBUG, TAG, "OUT");
+    return CA_STATUS_OK;
+}
+
 void CAIPStopServer()
 {
     OIC_LOG(DEBUG, TAG, "IN");
index ce2b57d..a3da9a3 100644 (file)
 // Length of the IP address decimal notation string
 #define IPNAMESIZE (16)
 
+/** Multicast IP address.*/
+#define IPv4_MULTICAST      "224.0.1.187"
+
+/** Multicast Port.*/
+#define IPv4_MULTICAST_PORT 5683
+
 // Start offsets based on end of received data buffer
 #define IP_RECBUF_IPADDR_OFFSET  (6)
 #define IP_RECBUF_PORT_OFFSET    (2)
@@ -134,7 +140,7 @@ CAResult_t CAIPStartServer()
         OIC_LOG_V(ERROR, TAG, "Start unicast server failed[%d]", ret);
         return ret;
     }
-    ret = CAIPStartMulticastServer("0.0.0.0", "224.0.1.187", 5683);
+    ret = CAIPStartMulticastServer("0.0.0.0", IPv4_MULTICAST, IPv4_MULTICAST_PORT);
     if (CA_STATUS_OK != ret)
     {
         OIC_LOG_V(ERROR, TAG, "Start multicast failed[%d]", ret);
@@ -158,6 +164,21 @@ CAResult_t CAIPStopMulticastServer()
     return CAIPStopUnicastServer();
 }
 
+CAResult_t CAIPStartListenServer()
+{
+    CAResult_t ret = CAIPStartMulticastServer("0.0.0.0", IPv4_MULTICAST, IPv4_MULTICAST_PORT);
+    if (CA_STATUS_OK != ret)
+    {
+        OIC_LOG_V(ERROR, TAG, "Start multicast failed[%d]", ret);
+    }
+    return ret;
+}
+
+CAResult_t CAIPStopListenServer()
+{
+    return CAIPStopMulticastServer();
+}
+
 void CAIPStopServer()
 {
     OIC_LOG(DEBUG, TAG, "IN");
@@ -294,4 +315,3 @@ CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
     OIC_LOG(DEBUG, TAG, "OUT");
     return CA_STATUS_OK;
 }
-
index 2528db8..f7abd4a 100644 (file)
@@ -273,6 +273,7 @@ CAResult_t CAInitializeIP(CARegisterConnectivityCallback registerCallback,
     CAConnectivityHandler_t ipHandler;
     ipHandler.startAdapter = CAStartIP;
     ipHandler.startListenServer = CAStartIPListeningServer;
+    ipHandler.stopListenServer = CAStopIPListeningServer;
     ipHandler.startDiscoveryServer = CAStartIPDiscoveryServer;
     ipHandler.sendData = CASendIPUnicastData;
     ipHandler.sendDataToAll = CASendIPMulticastData;
@@ -331,7 +332,25 @@ CAResult_t CAStartIP()
 CAResult_t CAStartIPListeningServer()
 {
     OIC_LOG(DEBUG, TAG, "IN");
+    CAResult_t ret = CAIPStartListenServer();
+    if (CA_STATUS_OK != ret)
+    {
+        OIC_LOG_V(ERROR, TAG, "Failed to start listening server![%d]", ret);
+        return ret;
+    }
+    OIC_LOG(DEBUG, TAG, "OUT");
+    return CA_STATUS_OK;
+}
 
+CAResult_t CAStopIPListeningServer()
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+    CAResult_t ret = CAIPStopListenServer();
+    if (CA_STATUS_OK != ret)
+    {
+        OIC_LOG_V(ERROR, TAG, "Failed to stop listening server![%d]", ret);
+        return ret;
+    }
     OIC_LOG(DEBUG, TAG, "OUT");
     return CA_STATUS_OK;
 }
index a463c83..2dea10f 100644 (file)
@@ -96,7 +96,6 @@ static CAIPExceptionCallback g_exceptionCallback;
 static CAIPPacketReceivedCallback g_packetReceivedCallback;
 
 static void CAHandleNetlink();
-static void CAApplyInterfaces();
 static void CAFindReadyMessage();
 static void CASelectReturned(fd_set *readFds, int ret);
 static void CAProcessNewInterface(CAInterface_t *ifchanged);
@@ -479,7 +478,12 @@ CAResult_t CAIPStartServer(const ca_thread_pool_t threadPool)
 
     caglobals.ip.selectTimeout = CAGetPollingInterval(caglobals.ip.selectTimeout);
 
-    CAApplyInterfaces();
+    res = CAIPStartListenServer();
+    if (CA_STATUS_OK != res)
+    {
+        OIC_LOG_V(ERROR, TAG, "Failed to start listening server![%d]", res);
+        return res;
+    }
 
     caglobals.ip.terminate = false;
     res = ca_thread_pool_add_task(threadPool, CAReceiveHandler, NULL);
@@ -590,13 +594,13 @@ static void applyMulticastToInterface6(uint32_t interface)
     //applyMulticast6(caglobals.ip.m6s.fd, &IPv6MulticastAddressGlb, interface);
 }
 
-static void CAApplyInterfaces()
+CAResult_t CAIPStartListenServer()
 {
     u_arraylist_t *iflist = CAIPGetInterfaceInformation(0);
     if (!iflist)
     {
         OIC_LOG_V(ERROR, TAG, "get interface info failed: %s", strerror(errno));
-        return;
+        return CA_STATUS_FAILED;
     }
 
     uint32_t len = u_arraylist_length(iflist);
@@ -629,6 +633,53 @@ static void CAApplyInterfaces()
     }
 
     u_arraylist_destroy(iflist);
+    return CA_STATUS_OK;
+}
+
+CAResult_t CAIPStopListenServer()
+{
+    u_arraylist_t *iflist = CAIPGetInterfaceInformation(0);
+    if (!iflist)
+    {
+        OIC_LOG_V(ERROR, TAG, "Get interface info failed: %s", strerror(errno));
+        return CA_STATUS_FAILED;
+    }
+
+    uint32_t len = u_arraylist_length(iflist);
+    OIC_LOG_V(DEBUG, TAG, "IP network interfaces found: %d", len);
+
+    for (uint32_t i = 0; i < len; i++)
+    {
+        CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
+
+        if (!ifitem)
+        {
+            continue;
+        }
+
+        if ((ifitem->flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
+        {
+            continue;
+        }
+        if (ifitem->family == AF_INET)
+        {
+            close(caglobals.ip.m4.fd);
+            close(caglobals.ip.m4s.fd);
+            caglobals.ip.m4.fd = -1;
+            caglobals.ip.m4s.fd = -1;
+            OIC_LOG_V(DEBUG, TAG, "IPv4 network interface: %s cloed", ifitem->name);
+        }
+        if (ifitem->family == AF_INET6)
+        {
+            close(caglobals.ip.m6.fd);
+            close(caglobals.ip.m6s.fd);
+            caglobals.ip.m6.fd = -1;
+            caglobals.ip.m6s.fd = -1;
+            OIC_LOG_V(DEBUG, TAG, "IPv6 network interface: %s", ifitem->name);
+        }
+    }
+    u_arraylist_destroy(iflist);
+    return CA_STATUS_OK;
 }
 
 static void CAProcessNewInterface(CAInterface_t *ifitem)
@@ -974,4 +1025,3 @@ CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
     OIC_LOG(DEBUG, TAG, "OUT");
     return CA_STATUS_OK;
 }
-
index 4ae741f..ff84862 100644 (file)
@@ -231,6 +231,7 @@ CAResult_t CAInitializeRA(CARegisterConnectivityCallback registerCallback,
     CAConnectivityHandler_t raHandler = {};
     raHandler.startAdapter = CAStartRA;
     raHandler.startListenServer = CAStartRAListeningServer;
+    raHandler.stopListenServer = CAStopRAListeningServer;
     raHandler.startDiscoveryServer = CAStartRADiscoveryServer;
     raHandler.sendData = CASendRAUnicastData;
     raHandler.sendDataToAll = CASendRAMulticastData;
@@ -410,6 +411,12 @@ CAResult_t CAStartRAListeningServer()
     return CA_NOT_SUPPORTED;
 }
 
+CAResult_t CAStopRAListeningServer()
+{
+    OIC_LOG(INFO, RA_ADAPTER_TAG, "RA adapter does not support listening for multicast data");
+    return CA_NOT_SUPPORTED;
+}
+
 CAResult_t CAStartRADiscoveryServer()
 {
     OIC_LOG(INFO, RA_ADAPTER_TAG, "RA adapter does not support discovery of multicast servers");
index 56cc8f6..31eca32 100644 (file)
@@ -218,6 +218,7 @@ CAResult_t CAInitializeTCP(CARegisterConnectivityCallback registerCallback,
     CAConnectivityHandler_t TCPHandler = {
         .startAdapter = CAStartTCP,
         .startListenServer = CAStartTCPListeningServer,
+        .stopListenServer = CAStopTCPListeningServer,
         .startDiscoveryServer = CAStartTCPDiscoveryServer,
         .sendData = CASendTCPUnicastData,
         .sendDataToAll = CASendTCPMulticastData,
@@ -268,6 +269,14 @@ CAResult_t CAStartTCPListeningServer()
     return CA_STATUS_OK;
 }
 
+CAResult_t CAStopTCPListeningServer()
+{
+    OIC_LOG(DEBUG, TAG, "IN");
+
+    OIC_LOG(DEBUG, TAG, "OUT");
+    return CA_STATUS_OK;
+}
+
 CAResult_t CAStartTCPDiscoveryServer()
 {
     OIC_LOG(DEBUG, TAG, "IN");
index 6108e34..29f39b5 100644 (file)
@@ -88,6 +88,25 @@ 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.
+ *
+ * @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.
+ *
+ * @return ::OC_STACK_OK on success, some other value upon failure.
+ */
+OCStackResult OCStopMulticastServer();
+
+/**
  * This function is Called in main loop of OC client or server.
  * Allows low-level processing of stack services.
  *
index 8bb0209..187ad81 100644 (file)
@@ -1986,6 +1986,33 @@ OCStackResult OCStop()
     return OC_STACK_OK;
 }
 
+OCStackResult OCStartMulticastServer()
+{
+    if(stackState != OC_STACK_INITIALIZED)
+    {
+        OC_LOG(ERROR, TAG, "OCStack is not initalized. Cannot start multicast server.");
+        return OC_STACK_ERROR;
+    }
+    CAResult_t ret = CAStartListeningServer();
+    if (CA_STATUS_OK != ret)
+    {
+        OC_LOG_V(ERROR, TAG, "Failed starting listening server: %d", ret);
+        return OC_STACK_ERROR;
+    }
+    return OC_STACK_OK;
+}
+
+OCStackResult OCStopMulticastServer()
+{
+    CAResult_t ret = CAStopListeningServer();
+    if (CA_STATUS_OK != ret)
+    {
+        OC_LOG_V(ERROR, TAG, "Failed stopping listening server: %d", ret);
+        return OC_STACK_ERROR;
+    }
+    return OC_STACK_OK;
+}
+
 CAMessageType_t qualityOfServiceToMessageType(OCQualityOfService qos)
 {
     switch (qos)
index f712f25..348329b 100644 (file)
@@ -40,7 +40,7 @@ if target_os not in ['arduino','darwin']:
 
        # Build notification manager project
        SConscript('notification-manager/SConscript')
-       
+
        # Build resource-encapsulation project
        if target_os not in ['tizen']:
                SConscript('resource-encapsulation/SConscript')
index 74096e3..6b90b86 100644 (file)
@@ -69,7 +69,14 @@ static OCStackApplicationResult handlePublishCB(__attribute__((unused))void *ctx
     OCStackApplicationResult ret = OC_STACK_DELETE_TRANSACTION;
     OC_LOG(DEBUG, TAG, "Successfully published resources.");
 
-    // TOOO: Stop multicast traffic on the client.
+    if (OC_STACK_OK == OCStopMulticastServer())
+    {
+        OC_LOG_V(DEBUG, TAG, "Stopped receiving the multicast traffic.");
+    }
+    else
+    {
+        OC_LOG_V(DEBUG, TAG, "Failed stopping the multicast traffic.");
+    }
 
     return ret;
 }