Fix to resolve discovery issue when built with "scons"
authorvimala.v <vimala.v@samsung.com>
Mon, 29 Feb 2016 11:37:30 +0000 (17:07 +0530)
committerAshok Babu Channa <ashok.channa@samsung.com>
Wed, 2 Mar 2016 06:11:18 +0000 (06:11 +0000)
TARGET_TRANSPORT=ALL is the default value and TCP support is
enabled in this case.  As currently multicast is not supported via TCP,
Discovery is not working.  This patch resolves the issue by sending UDP based
packet via IP adapter while TCP based packet via other adapters.

Change-Id: I6fb7556c2d5053c4c14c8fc21892b23c06602608
Signed-off-by: vimala.v <vimala.v@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/5271
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jaehong Jo <jaehong.jo@samsung.com>
Reviewed-by: Ashok Babu Channa <ashok.channa@samsung.com>
resource/csdk/connectivity/src/cainterfacecontroller.c
resource/csdk/connectivity/src/camessagehandler.c

index 9b47eeb..7ef5926 100644 (file)
@@ -416,7 +416,7 @@ CAResult_t CASendMulticastData(const CAEndpoint_t *endpoint, const void *data, u
         return CA_SEND_FAILED;
     }
 
-    CATransportFlags_t requestedAdapter = endpoint->adapter ? endpoint->adapter : CA_ALL_ADAPTERS;
+    CATransportAdapter_t requestedAdapter = endpoint->adapter ? endpoint->adapter : CA_ALL_ADAPTERS;
     size_t selectedLength = u_arraylist_length(list);
     for (size_t i = 0; i < selectedLength; i++)
     {
index 8ed955a..3da692b 100644 (file)
@@ -394,6 +394,123 @@ static void CAReceiveThreadProcess(void *threadData)
 }
 #endif // SINGLE_THREAD
 
+static CAResult_t CAProcessMulticastData(const CAData_t *data)
+{
+    VERIFY_NON_NULL(data, TAG, "data");
+    VERIFY_NON_NULL(data->remoteEndpoint, TAG, "remoteEndpoint");
+
+    CAResult_t res = CA_STATUS_FAILED;
+
+    coap_pdu_t *pdu = NULL;
+    CAInfo_t *info = NULL;
+    coap_list_t *options = NULL;
+    coap_transport_type transport;
+    if (NULL != data->requestInfo)
+    {
+        OIC_LOG(DEBUG, TAG, "requestInfo is available..");
+
+        info = &data->requestInfo->info;
+        pdu = CAGeneratePDU(CA_GET, info, data->remoteEndpoint, &options, &transport);
+
+        if (NULL != pdu)
+        {
+#ifdef WITH_BWT
+            if (CA_ADAPTER_GATT_BTLE != data->remoteEndpoint->adapter
+#ifdef WITH_TCP
+                    && !CAIsSupportedCoAPOverTCP(data->remoteEndpoint->adapter)
+#endif
+                    )
+            {
+                // Blockwise transfer
+                CAResult_t res = CAAddBlockOption(&pdu, info,
+                                                  data->remoteEndpoint,
+                                                  &options);
+                if (CA_STATUS_OK != res)
+                {
+                    OIC_LOG(DEBUG, TAG, "CAAddBlockOption has failed");
+                    CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
+                    coap_delete_list(options);
+                    coap_delete_pdu(pdu);
+                    return res;
+                }
+            }
+#endif // WITH_BWT
+        }
+        else
+        {
+            OIC_LOG(ERROR,TAG,"Failed to generate multicast PDU");
+            CASendErrorInfo(data->remoteEndpoint, info, CA_SEND_FAILED);
+            return CA_SEND_FAILED;
+        }
+    }
+    else if (NULL != data->responseInfo)
+    {
+        OIC_LOG(DEBUG, TAG, "responseInfo is available..");
+
+        info = &data->responseInfo->info;
+        pdu = CAGeneratePDU(data->responseInfo->result, info, data->remoteEndpoint,
+                            &options, &transport);
+
+        if (NULL != pdu)
+        {
+#ifdef WITH_BWT
+            if (CA_ADAPTER_GATT_BTLE != data->remoteEndpoint->adapter
+#ifdef WITH_TCP
+                    && !CAIsSupportedCoAPOverTCP(data->remoteEndpoint->adapter)
+#endif
+                    )
+            {
+                // Blockwise transfer
+                if (NULL != info)
+                {
+                    CAResult_t res = CAAddBlockOption(&pdu, info,
+                                                      data->remoteEndpoint,
+                                                      &options);
+                    if (CA_STATUS_OK != res)
+                    {
+                        OIC_LOG(INFO, TAG, "to write block option has failed");
+                        CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
+                        coap_delete_list(options);
+                        coap_delete_pdu(pdu);
+                        return res;
+                    }
+                }
+            }
+#endif // WITH_BWT
+        }
+        else
+        {
+            OIC_LOG(ERROR,TAG,"Failed to generate multicast PDU");
+            CASendErrorInfo(data->remoteEndpoint, info, CA_SEND_FAILED);
+            return CA_SEND_FAILED;
+        }
+    }
+    else
+    {
+        OIC_LOG(ERROR, TAG, "request or response info is empty");
+        return CA_SEND_FAILED;
+    }
+
+    CALogPDUInfo(pdu, data->remoteEndpoint);
+
+    OIC_LOG(DEBUG, TAG, "pdu to send :");
+    OIC_LOG_BUFFER(DEBUG, TAG,  (uint8_t*)pdu->hdr, pdu->length);
+
+    res = CASendMulticastData(data->remoteEndpoint, pdu->hdr, pdu->length);
+    if (CA_STATUS_OK != res)
+    {
+        OIC_LOG_V(ERROR, TAG, "send failed:%d", res);
+        CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
+        coap_delete_list(options);
+        coap_delete_pdu(pdu);
+        return res;
+    }
+
+    coap_delete_list(options);
+    coap_delete_pdu(pdu);
+    return CA_STATUS_OK;
+}
+
 static CAResult_t CAProcessSendData(const CAData_t *data)
 {
     VERIFY_NON_NULL(data, TAG, "data");
@@ -523,109 +640,29 @@ static CAResult_t CAProcessSendData(const CAData_t *data)
     else if (SEND_TYPE_MULTICAST == type)
     {
         OIC_LOG(DEBUG,TAG,"Multicast message");
-        if (NULL != data->requestInfo)
-        {
-            OIC_LOG(DEBUG, TAG, "requestInfo is available..");
-
-            info = &data->requestInfo->info;
-            pdu = CAGeneratePDU(CA_GET, info, data->remoteEndpoint, &options, &transport);
-
-            if (NULL != pdu)
-            {
-#ifdef WITH_BWT
-                if (CA_ADAPTER_GATT_BTLE != data->remoteEndpoint->adapter
 #ifdef WITH_TCP
-                        && !CAIsSupportedCoAPOverTCP(data->remoteEndpoint->adapter)
-#endif
-                        )
-                {
-                    // Blockwise transfer
-                    CAResult_t res = CAAddBlockOption(&pdu, info,
-                                                      data->remoteEndpoint,
-                                                      &options);
-                    if (CA_STATUS_OK != res)
-                    {
-                        OIC_LOG(DEBUG, TAG, "CAAddBlockOption has failed");
-                        CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
-                        coap_delete_list(options);
-                        coap_delete_pdu(pdu);
-                        return res;
-                    }
-                }
-#endif // WITH_BWT
-            }
-            else
-            {
-                OIC_LOG(ERROR,TAG,"Failed to generate multicast PDU");
-                CASendErrorInfo(data->remoteEndpoint, info, CA_SEND_FAILED);
-                return CA_SEND_FAILED;
-            }
-        }
-        else if (NULL != data->responseInfo)
+        /*
+         * If CoAP over TCP is enabled, the CoAP pdu wont be same for IP and other adapters.
+         * That's why we need to generate two pdu's, one for IP and second for other transports.
+         * Two possible cases we might have to split: a) when adapter is CA_DEFAULT_ADAPTER
+         * b) when one of the adapter is IP adapter(ex: CA_ADAPTER_IP | CA_ADAPTER_GATT_BTLE)
+         */
+        if (data->remoteEndpoint->adapter == CA_DEFAULT_ADAPTER ||
+                (CA_ADAPTER_IP & data->remoteEndpoint->adapter &&
+                    CA_ADAPTER_IP != data->remoteEndpoint->adapter))
         {
-            OIC_LOG(DEBUG, TAG, "responseInfo is available..");
-
-            info = &data->responseInfo->info;
-            pdu = CAGeneratePDU(data->responseInfo->result, info, data->remoteEndpoint,
-                                &options, &transport);
-
-            if (NULL != pdu)
-            {
-#ifdef WITH_BWT
-                if (CA_ADAPTER_GATT_BTLE != data->remoteEndpoint->adapter
-#ifdef WITH_TCP
-                        && !CAIsSupportedCoAPOverTCP(data->remoteEndpoint->adapter)
-#endif
-                        )
-                {
-                    // Blockwise transfer
-                    if (NULL != info)
-                    {
-                        CAResult_t res = CAAddBlockOption(&pdu, info,
-                                                          data->remoteEndpoint,
-                                                          &options);
-                        if (CA_STATUS_OK != res)
-                        {
-                            OIC_LOG(INFO, TAG, "to write block option has failed");
-                            CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
-                            coap_delete_list(options);
-                            coap_delete_pdu(pdu);
-                            return res;
-                        }
-                    }
-                }
-#endif // WITH_BWT
-            }
-            else
-            {
-                OIC_LOG(ERROR,TAG,"Failed to generate multicast PDU");
-                CASendErrorInfo(data->remoteEndpoint, info, CA_SEND_FAILED);
-                return CA_SEND_FAILED;
-            }
+            data->remoteEndpoint->adapter = data->remoteEndpoint->adapter ^ CA_ADAPTER_IP;
+            CAProcessMulticastData(data);
+            data->remoteEndpoint->adapter = CA_ADAPTER_IP;
+            CAProcessMulticastData(data);
         }
         else
         {
-            OIC_LOG(ERROR, TAG, "request or response info is empty");
-            return CA_SEND_FAILED;
+            CAProcessMulticastData(data);
         }
-
-        CALogPDUInfo(pdu, data->remoteEndpoint);
-
-        OIC_LOG(DEBUG, TAG, "pdu to send :");
-        OIC_LOG_BUFFER(DEBUG, TAG,  (uint8_t*)pdu->hdr, pdu->length);
-
-        res = CASendMulticastData(data->remoteEndpoint, pdu->hdr, pdu->length);
-        if (CA_STATUS_OK != res)
-        {
-            OIC_LOG_V(ERROR, TAG, "send failed:%d", res);
-            CAErrorHandler(data->remoteEndpoint, pdu->hdr, pdu->length, res);
-            coap_delete_list(options);
-            coap_delete_pdu(pdu);
-            return res;
-        }
-
-        coap_delete_list(options);
-        coap_delete_pdu(pdu);
+#else
+        CAProcessMulticastData(data);
+#endif
     }
 
     return CA_STATUS_OK;