replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / camessagehandler.c
old mode 100644 (file)
new mode 100755 (executable)
index 10390eb..dcc172e
@@ -28,6 +28,7 @@
 #include "caremotehandler.h"
 #include "caprotocolmessage.h"
 #include "logger.h"
+#include "trace.h"
 #ifndef WITH_UPSTREAM_LIBCOAP
 #include "coap/config.h"
 #endif
@@ -90,6 +91,19 @@ static void CALogPayloadInfo(CAInfo_t *info);
 static bool CADropSecondMessage(CAHistory_t *history, const CAEndpoint_t *endpoint, uint16_t id,
                                 CAToken_t token, uint8_t tokenLength);
 
+/**
+ * print send / receive message of CoAP.
+ * @param[in] data      CA information which has send/receive message and endpoint.
+ * @param[in] pdu       CoAP pdu low data.
+ */
+static void CALogPDUInfo(const CAData_t *data, const coap_pdu_t *pdu);
+
+#ifndef ARDUINO
+static char g_headerBuffer[MAX_LOG_BUFFER_SIZE] = {0};
+static size_t g_headerIndex = 0;
+static void CASamsungLogMessage(const CAData_t *data, const coap_pdu_t *pdu);
+#endif
+
 #ifdef WITH_BWT
 void CAAddDataToSendThread(CAData_t *data)
 {
@@ -190,7 +204,7 @@ static CAData_t* CAGenerateHandlerData(const CAEndpoint_t *endpoint,
         if (CADropSecondMessage(&caglobals.ca.requestHistory, endpoint, reqInfo->info.messageId,
                                 reqInfo->info.token, reqInfo->info.tokenLength))
         {
-            OIC_LOG(ERROR, TAG, "Second Request with same Token, Drop it");
+            OIC_LOG(INFO, TAG, "Second Request with same Token, Drop it");
             CADestroyRequestInfoInternal(reqInfo);
             goto exit;
         }
@@ -406,7 +420,9 @@ static void CAReceiveThreadProcess(void *threadData)
 {
 #ifndef SINGLE_HANDLE
     CAData_t *data = (CAData_t *) threadData;
+    OIC_TRACE_BEGIN(%s:CAProcessReceivedData, TAG);
     CAProcessReceivedData(data);
+    OIC_TRACE_END();
 #else
     (void)threadData;
 #endif
@@ -467,7 +483,7 @@ static CAResult_t CAProcessMulticastData(const CAData_t *data)
     }
 #endif // WITH_BWT
 
-    CALogPDUInfo(pdu, data->remoteEndpoint);
+    CALogPDUInfo(data, pdu);
 
     res = CASendMulticastData(data->remoteEndpoint, pdu->transport_hdr, pdu->length, data->dataType);
     if (CA_STATUS_OK != res)
@@ -494,6 +510,21 @@ static CAResult_t CAProcessSendData(const CAData_t *data)
 
     CAResult_t res = CA_STATUS_FAILED;
 
+    if (CA_NETWORK_COMMAND == data->dataType)
+    {
+        if (CA_REQ_DISCONNECT == data->eventInfo)
+        {
+#ifdef TCP_ADAPTER
+            // request TCP disconnect
+            if (CA_ADAPTER_TCP == data->remoteEndpoint->adapter)
+            {
+                OIC_LOG(INFO, TAG, "request TCP disconnect");
+                return CADisconnectSession(data->remoteEndpoint);
+            }
+#endif
+        }
+    }
+
     CASendDataType_t type = data->type;
 
     coap_pdu_t *pdu = NULL;
@@ -564,7 +595,7 @@ static CAResult_t CAProcessSendData(const CAData_t *data)
                 }
             }
 #endif // WITH_BWT
-            CALogPDUInfo(pdu, data->remoteEndpoint);
+            CALogPDUInfo(data, pdu);
 
             OIC_LOG_V(INFO, TAG, "CASendUnicastData type : %d", data->dataType);
             res = CASendUnicastData(data->remoteEndpoint, pdu->transport_hdr, pdu->length, data->dataType);
@@ -585,7 +616,7 @@ static CAResult_t CAProcessSendData(const CAData_t *data)
             else
 #endif
 #ifdef ROUTING_GATEWAY
-            if(!skipRetransmission)
+            if (!skipRetransmission)
 #endif
             {
                 // for retransmission
@@ -647,7 +678,6 @@ static CAResult_t CAProcessSendData(const CAData_t *data)
         CAProcessMulticastData(data);
 #endif
     }
-
     return CA_STATUS_OK;
 }
 
@@ -655,7 +685,9 @@ static CAResult_t CAProcessSendData(const CAData_t *data)
 static void CASendThreadProcess(void *threadData)
 {
     CAData_t *data = (CAData_t *) threadData;
+    OIC_TRACE_BEGIN(%s:CAProcessSendData, TAG);
     CAProcessSendData(data);
+    OIC_TRACE_END();
 }
 #endif
 
@@ -723,15 +755,33 @@ static bool CADropSecondMessage(CAHistory_t *history, const CAEndpoint_t *ep, ui
     return ret;
 }
 
-static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep,
-                                     const void *data, uint32_t dataLen)
+static CAResult_t CAReceivedPacketCallback(const CASecureEndpoint_t *sep,
+                                           const void *data, uint32_t dataLen)
 {
-    VERIFY_NON_NULL_VOID(sep, TAG, "remoteEndpoint");
-    VERIFY_NON_NULL_VOID(data, TAG, "data");
+    VERIFY_NON_NULL(sep, TAG, "remoteEndpoint");
+    VERIFY_NON_NULL(data, TAG, "data");
+    OIC_TRACE_BEGIN(%s:CAReceivedPacketCallback, TAG);
+
+    if (0 == dataLen)
+    {
+        OIC_LOG(ERROR, TAG, "dataLen is zero");
+        OIC_TRACE_END();
 
+        return CA_STATUS_FAILED;
+    }
+
+    // samsung log
     OIC_LOG(DEBUG, TAG, "received pdu data :");
-    OIC_LOG_BUFFER(DEBUG, TAG,  data, dataLen);
+    if (dataLen < 32)
+    {
+        OIC_LOG_BUFFER(DEBUG, TAG,  data, dataLen);
+    }
+    else
+    {
+        OIC_LOG_BUFFER(DEBUG, TAG,  data, 32);
+    }
 
+    CAResult_t res = CA_STATUS_OK;
     uint32_t code = CA_NOT_FOUND;
     CAData_t *cadata = NULL;
 
@@ -740,7 +790,8 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep,
     if (NULL == pdu)
     {
         OIC_LOG(ERROR, TAG, "Parse PDU failed");
-        return;
+        res = CA_STATUS_FAILED;
+        goto exit;
     }
 
     OIC_LOG_V(DEBUG, TAG, "code = %d", code);
@@ -751,7 +802,7 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep,
         {
             OIC_LOG(ERROR, TAG, "CAReceivedPacketCallback, CAGenerateHandlerData failed!");
             coap_delete_pdu(pdu);
-            return;
+            goto exit;
         }
     }
     else
@@ -761,7 +812,7 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep,
         {
             OIC_LOG(ERROR, TAG, "CAReceivedPacketCallback, CAGenerateHandlerData failed!");
             coap_delete_pdu(pdu);
-            return;
+            goto exit;
         }
 
 #ifdef WITH_TCP
@@ -799,6 +850,8 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep,
 
     cadata->type = SEND_TYPE_UNICAST;
 
+    CALogPDUInfo(cadata, pdu);
+
 #ifdef SINGLE_THREAD
     CAProcessReceivedData(cadata);
 #else
@@ -824,6 +877,55 @@ static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep,
 #endif // SINGLE_THREAD
 
     coap_delete_pdu(pdu);
+
+exit:
+    OIC_LOG(DEBUG, TAG, "OUT - Recv Thread");
+    OIC_TRACE_END();
+    return res;
+}
+
+static void CAAdapterStateChangedCallback(CATransportAdapter_t transportType, bool enabled)
+{
+    if (!enabled)
+    {
+        CAClearMessageHandler(transportType);
+    }
+}
+
+static bool CAClearQueueEndpointDataContext(void *data, uint32_t size, void *ctx)
+{
+    if (NULL == data || NULL == ctx)
+    {
+        return false;
+    }
+
+    CAData_t *caData = (CAData_t *)data;
+    const CAEndpoint_t *endpoint = (const CAEndpoint_t *)ctx;
+
+    if (NULL != caData && NULL != caData->remoteEndpoint)
+    {
+        if (strcmp(caData->remoteEndpoint->addr, endpoint->addr) == 0
+            && caData->remoteEndpoint->port == endpoint->port
+            && caData->remoteEndpoint->adapter == endpoint->adapter)
+        {
+            return true;
+        }
+    }
+    return false;
+}
+
+static void CAConnectionStateChangedCallback(const CAEndpoint_t *info, bool isConnected)
+{
+    if (!isConnected)
+    {
+        CAResult_t res = CAQueueingThreadClearContextData(&g_sendThread,
+                                                          CAClearQueueEndpointDataContext,
+                                                          info);
+        if (CA_STATUS_OK != res)
+        {
+            OIC_LOG(ERROR, TAG, "Could not clear the send queue");
+        }
+    }
 }
 
 void CAHandleRequestResponseCallbacks()
@@ -837,11 +939,11 @@ void CAHandleRequestResponseCallbacks()
     // #1 parse the data
     // #2 get endpoint
 
-    ca_mutex_lock(g_receiveThread.threadMutex);
+    oc_mutex_lock(g_receiveThread.threadMutex);
 
     u_queue_message_t *item = u_queue_get_element(g_receiveThread.dataQueue);
 
-    ca_mutex_unlock(g_receiveThread.threadMutex);
+    oc_mutex_unlock(g_receiveThread.threadMutex);
 
     if (NULL == item || NULL == item->msg)
     {
@@ -909,7 +1011,7 @@ static CAData_t* CAPrepareSendData(const CAEndpoint_t *endpoint, const void *sen
 #else
         // clone response info
         CAResponseInfo_t *response = CACloneResponseInfo((CAResponseInfo_t *)sendData);
-        if(!response)
+        if (!response)
         {
             OIC_LOG(ERROR, TAG, "CACloneResponseInfo failed");
             goto exit;
@@ -947,6 +1049,43 @@ exit:
     return NULL;
 }
 
+CAResult_t CADetachSendNetworkReqMessage(const CAEndpoint_t *endpoint,
+                                         CAConnectEvent_t event,
+                                         CADataType_t dataType)
+{
+    VERIFY_NON_NULL(endpoint, TAG, "endpoint");
+
+    if (false == CAIsSelectedNetworkAvailable())
+    {
+        return CA_STATUS_FAILED;
+    }
+
+#ifndef SINGLE_THREAD
+    CAData_t *cadata = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
+    if (!cadata)
+    {
+        OIC_LOG(ERROR, TAG, "cadata memory allocation failed");
+        return CA_STATUS_FAILED;
+    }
+
+    CAEndpoint_t* ep = CACloneEndpoint(endpoint);
+    if (!ep)
+    {
+        OIC_LOG(ERROR, TAG, "endpoint clone failed");
+        OICFree(cadata);
+        return CA_STATUS_FAILED;
+    }
+
+    cadata->remoteEndpoint = ep;
+    cadata->eventInfo = event;
+    cadata->dataType = dataType;
+
+    CAQueueingThreadAddData(&g_sendThread, cadata, sizeof(CAData_t));
+#endif
+
+    return CA_STATUS_OK;
+}
+
 CAResult_t CADetachSendMessage(const CAEndpoint_t *endpoint, const void *sendMsg,
                                CADataType_t dataType)
 {
@@ -974,6 +1113,8 @@ CAResult_t CADetachSendMessage(const CAEndpoint_t *endpoint, const void *sendMsg
         return CA_MEMORY_ALLOC_FAILED;
     }
 
+    OIC_LOG_V(INFO_PRIVATE, TAG, "DID of endpoint of this message is %s", endpoint->remoteId);
+
 #ifdef SINGLE_THREAD
     CAResult_t result = CAProcessSendData(data);
     if (CA_STATUS_OK != result)
@@ -989,6 +1130,7 @@ CAResult_t CADetachSendMessage(const CAEndpoint_t *endpoint, const void *sendMsg
 #ifdef WITH_BWT
     if (CAIsSupportedBlockwiseTransfer(endpoint->adapter))
     {
+        CACheckAndDeleteTimedOutBlockData();
         // send block data
         CAResult_t res = CASendBlockWiseData(data);
         if (CA_NOT_SUPPORTED == res)
@@ -1001,6 +1143,7 @@ CAResult_t CADetachSendMessage(const CAEndpoint_t *endpoint, const void *sendMsg
         {
             CADestroyData(data, sizeof(CAData_t));
         }
+
         return res;
     }
     else
@@ -1026,7 +1169,7 @@ void CASetNetworkMonitorCallback(CANetworkMonitorCallback nwMonitorHandler)
     g_nwMonitorHandler = nwMonitorHandler;
 }
 
-CAResult_t CAInitializeMessageHandler()
+CAResult_t CAInitializeMessageHandler(CATransportAdapter_t transportType)
 {
     CASetPacketReceivedCallback(CAReceivedPacketCallback);
     CASetErrorHandleCallback(CAErrorHandler);
@@ -1046,19 +1189,18 @@ CAResult_t CAInitializeMessageHandler()
     if (CA_STATUS_OK != res)
     {
         OIC_LOG(ERROR, TAG, "Failed to Initialize send queue thread");
-        ca_thread_pool_free(g_threadPoolHandle);
-        g_threadPoolHandle = NULL;
         return res;
     }
 
     // start send thread
+#ifndef __TIZENRT__
     res = CAQueueingThreadStart(&g_sendThread);
+#else
+    res = CAQueueingThreadStart(&g_sendThread, "IoT_MessageHandlerQueue");
+#endif
     if (CA_STATUS_OK != res)
     {
         OIC_LOG(ERROR, TAG, "thread start error(send thread).");
-        ca_thread_pool_free(g_threadPoolHandle);
-        g_threadPoolHandle = NULL;
-        CAQueueingThreadDestroy(&g_sendThread);
         return res;
     }
 
@@ -1068,9 +1210,6 @@ CAResult_t CAInitializeMessageHandler()
     if (CA_STATUS_OK != res)
     {
         OIC_LOG(ERROR, TAG, "Failed to Initialize receive queue thread");
-        ca_thread_pool_free(g_threadPoolHandle);
-        g_threadPoolHandle = NULL;
-        CAQueueingThreadDestroy(&g_sendThread);
         return res;
     }
 
@@ -1080,10 +1219,6 @@ CAResult_t CAInitializeMessageHandler()
     if (CA_STATUS_OK != res)
     {
         OIC_LOG(ERROR, TAG, "thread start error(receive thread).");
-        ca_thread_pool_free(g_threadPoolHandle);
-        g_threadPoolHandle = NULL;
-        CAQueueingThreadDestroy(&g_sendThread);
-        CAQueueingThreadDestroy(&g_receiveThread);
         return res;
     }
 #endif // SINGLE_HANDLE
@@ -1094,10 +1229,6 @@ CAResult_t CAInitializeMessageHandler()
     if (CA_STATUS_OK != res)
     {
         OIC_LOG(ERROR, TAG, "Failed to Initialize Retransmission.");
-        ca_thread_pool_free(g_threadPoolHandle);
-        g_threadPoolHandle = NULL;
-        CAQueueingThreadDestroy(&g_sendThread);
-        CAQueueingThreadDestroy(&g_receiveThread);
         return res;
     }
 
@@ -1107,11 +1238,6 @@ CAResult_t CAInitializeMessageHandler()
     if (CA_STATUS_OK != res)
     {
         OIC_LOG(ERROR, TAG, "Failed to Initialize BlockWiseTransfer.");
-        ca_thread_pool_free(g_threadPoolHandle);
-        g_threadPoolHandle = NULL;
-        CAQueueingThreadDestroy(&g_sendThread);
-        CAQueueingThreadDestroy(&g_receiveThread);
-        CARetransmissionDestroy(&g_retransmissionContext);
         return res;
     }
 #endif
@@ -1121,16 +1247,12 @@ CAResult_t CAInitializeMessageHandler()
     if (CA_STATUS_OK != res)
     {
         OIC_LOG(ERROR, TAG, "thread start error(retransmission thread).");
-        ca_thread_pool_free(g_threadPoolHandle);
-        g_threadPoolHandle = NULL;
-        CAQueueingThreadDestroy(&g_sendThread);
-        CAQueueingThreadDestroy(&g_receiveThread);
-        CARetransmissionDestroy(&g_retransmissionContext);
         return res;
     }
 
     // initialize interface adapters by controller
-    CAInitializeAdapters(g_threadPoolHandle);
+    CAInitializeAdapters(g_threadPoolHandle, transportType);
+    CASetNetworkMonitorCallbacks(CAAdapterStateChangedCallback, CAConnectionStateChangedCallback);
 #else
     // retransmission initialize
     CAResult_t res = CARetransmissionInitialize(&g_retransmissionContext, NULL, CASendUnicastData,
@@ -1147,6 +1269,44 @@ CAResult_t CAInitializeMessageHandler()
     return CA_STATUS_OK;
 }
 
+static bool CAClearQueueAdapterDataContext(void *data, uint32_t size, void *ctx)
+{
+    if (NULL == data || NULL == ctx)
+    {
+        return false;
+    }
+
+    CAData_t *caData = (CAData_t *)data;
+    CATransportAdapter_t *type = (CATransportAdapter_t *)ctx;
+
+    if (NULL != caData && NULL != caData->remoteEndpoint
+        && caData->remoteEndpoint->adapter == *type)
+    {
+        return true;
+    }
+    return false;
+}
+
+void CAClearMessageHandler(CATransportAdapter_t transportType)
+{
+    CATransportAdapter_t *typeCtx = &transportType;
+
+    CAResult_t res = CAQueueingThreadClearContextData(&g_sendThread,
+                                                      CAClearQueueAdapterDataContext,
+                                                      typeCtx);
+
+    if (res != CA_STATUS_OK)
+    {
+        OIC_LOG_V(ERROR, TAG, "Clear send data failed[%d]", res);
+    }
+
+    res = CARetransmissionClearAdapterData(&g_retransmissionContext, transportType);
+    if (res != CA_STATUS_OK)
+    {
+        OIC_LOG_V(ERROR, TAG, "Clear retransmission data failed[%d]", res);
+    }
+}
+
 void CATerminateMessageHandler()
 {
 #ifndef SINGLE_THREAD
@@ -1216,28 +1376,6 @@ void CATerminateMessageHandler()
 #endif // SINGLE_THREAD
 }
 
-void CALogPDUInfo(coap_pdu_t *pdu, const CAEndpoint_t *endpoint)
-{
-    VERIFY_NON_NULL_VOID(pdu, TAG, "pdu");
-    VERIFY_NON_NULL_VOID(endpoint, TAG, "endpoint");
-
-#ifdef WITH_BWT
-    if (CAIsSupportedBlockwiseTransfer(endpoint->adapter))
-    {
-        OIC_LOG_V(DEBUG, TAG, "PDU Maker - type : %d", pdu->transport_hdr->udp.type);
-
-        OIC_LOG_V(DEBUG, TAG, "PDU Maker - code : %d", pdu->transport_hdr->udp.code);
-    }
-#endif
-
-    OIC_LOG(DEBUG, TAG, "PDU Maker - token :");
-    OIC_LOG_BUFFER(DEBUG, TAG, pdu->transport_hdr->udp.token,
-                   pdu->transport_hdr->udp.token_length);
-
-    OIC_LOG(DEBUG, TAG, "PDU Maker - payload :");
-    OIC_LOG_BUFFER(DEBUG, TAG,  (const uint8_t *) pdu->transport_hdr, pdu->length);
-}
-
 static void CALogPayloadInfo(CAInfo_t *info)
 {
     if (info)
@@ -1277,11 +1415,16 @@ void CAErrorHandler(const CAEndpoint_t *endpoint,
                     CAResult_t result)
 {
     OIC_LOG(DEBUG, TAG, "CAErrorHandler IN");
-
-#ifndef SINGLE_THREAD
     VERIFY_NON_NULL_VOID(endpoint, TAG, "remoteEndpoint");
     VERIFY_NON_NULL_VOID(data, TAG, "data");
 
+    if (0 == dataLen)
+    {
+        OIC_LOG(ERROR, TAG, "dataLen is zero");
+        return;
+    }
+
+#ifndef SINGLE_THREAD
     uint32_t code = CA_NOT_FOUND;
     //Do not free remoteEndpoint and data. Currently they will be freed in data thread
     //Get PDU data
@@ -1304,6 +1447,8 @@ void CAErrorHandler(const CAEndpoint_t *endpoint,
 
     CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t));
     coap_delete_pdu(pdu);
+#else
+    (void)result;
 #endif
 
     OIC_LOG(DEBUG, TAG, "CAErrorHandler OUT");
@@ -1357,3 +1502,311 @@ static void CASendErrorInfo(const CAEndpoint_t *endpoint, const CAInfo_t *info,
 #endif
     OIC_LOG(DEBUG, TAG, "CASendErrorInfo OUT");
 }
+
+
+
+#ifndef ARDUINO
+#ifdef __TIZENRT__
+static void CALogPDUInfo(const CAData_t *data, const coap_pdu_t *pdu)
+{
+
+       if(data == NULL || pdu == NULL)
+       {
+               printf("INVALID INPUT, CALogPDUInfo FAIL\n");
+       }
+
+       char type[30] = "";
+
+       switch(data->dataType)
+       {
+               case CA_REQUEST_DATA:
+                       strncpy(type, "\e[32mREQUEST  <<<<\e[m", 30);
+                       break;
+               case CA_RESPONSE_DATA:
+                       strncpy(type, "\e[36mRESPONSE >>>>\e[m", 30);
+                       break;
+               case CA_ERROR_DATA:
+                       strncpy(type, "ERROR", 30);
+                       break;
+               case CA_RESPONSE_FOR_RES:
+                       strncpy(type, "RESP_RES >>>>", 30);
+                       break;
+               default:
+                       snprintf(type, 30, "Type : %d", data->dataType);
+                       break;
+       }
+
+
+       char method[20] = "";
+       const CAInfo_t *info = NULL;
+       if (NULL != data->requestInfo)
+       {
+               switch(data->requestInfo->method)
+               {
+                       case CA_GET:
+                               strncpy(method, "GET", 20);
+                               break;
+                       case CA_POST:
+                               strncpy(method, "POST", 20);
+                               break;
+                       case CA_PUT:
+                               strncpy(method, "PUT", 20);
+                               break;
+                       case CA_DELETE:
+                               strncpy(method, "DEL", 20);
+                               break;
+                       default:
+                               sprintf(method, "Method : %d", data->requestInfo->method);
+                               break;
+               }
+               info = &data->requestInfo->info;
+       }
+
+       if(NULL != data->responseInfo)
+       {
+
+               sprintf(method, "result : %d", data->responseInfo->result);
+               info = &data->responseInfo->info;
+       }
+
+
+       char log_buffer[1024] = "";
+       sprintf(log_buffer, "CA_LOG [%5d] | %-13s | %-12s | msg size : %4d | %s", pdu->transport_hdr->udp.id , type, method, pdu->length, info->resourceUri);
+
+       puts(log_buffer);
+}
+
+
+#else
+
+static void CALogPDUInfo(const CAData_t *data, const coap_pdu_t *pdu)
+{
+    OIC_LOG(DEBUG, TAG, "CALogPDUInfo");
+
+    VERIFY_NON_NULL_VOID(data, TAG, "data");
+    VERIFY_NON_NULL_VOID(pdu, TAG, "pdu");
+    OIC_TRACE_BEGIN(%s:CALogPDUInfo, TAG);
+
+    OIC_LOG(INFO, ANALYZER_TAG, "=================================================");
+    if(SEND_TYPE_MULTICAST == data->type)
+    {
+        OIC_LOG(INFO, ANALYZER_TAG, "Is Multicast = true");
+    }
+    else
+    {
+        OIC_LOG(INFO, ANALYZER_TAG, "Is Multicast = false");
+    }
+
+    if (NULL != data->remoteEndpoint)
+    {
+        CALogAdapterTypeInfo(data->remoteEndpoint->adapter);
+        OIC_LOG_V(INFO, ANALYZER_TAG, "Address = [%s]:[%d]", data->remoteEndpoint->addr,
+                  data->remoteEndpoint->port);
+    }
+
+    switch(data->dataType)
+    {
+        case CA_REQUEST_DATA:
+            OIC_LOG(INFO, ANALYZER_TAG, "Data Type = [CA_REQUEST_DATA]");
+            break;
+        case CA_RESPONSE_DATA:
+            OIC_LOG(INFO, ANALYZER_TAG, "Data Type = [CA_RESPONSE_DATA]");
+            break;
+        case CA_ERROR_DATA:
+            OIC_LOG(INFO, ANALYZER_TAG, "Data Type = [CA_ERROR_DATA]");
+            break;
+        case CA_RESPONSE_FOR_RES:
+            OIC_LOG(INFO, ANALYZER_TAG, "Data Type = [CA_RESPONSE_FOR_RES]");
+            break;
+        default:
+            OIC_LOG_V(INFO, ANALYZER_TAG, "Data Type = [%d]", data->dataType);
+            break;
+    }
+
+    const CAInfo_t *info = NULL;
+    if (NULL != data->requestInfo)
+    {
+        switch(data->requestInfo->method)
+        {
+            case CA_GET:
+                OIC_LOG(INFO, ANALYZER_TAG, "Method = [GET]");
+                break;
+            case CA_POST:
+                OIC_LOG(INFO, ANALYZER_TAG, "Method = [POST]");
+                break;
+            case CA_PUT:
+                OIC_LOG(INFO, ANALYZER_TAG, "Method = [PUT]");
+                break;
+            case CA_DELETE:
+                OIC_LOG(INFO, ANALYZER_TAG, "Method = [DELETE]");
+                break;
+            default:
+                OIC_LOG_V(INFO, ANALYZER_TAG, "Method = [%d]", data->requestInfo->method);
+                break;
+        }
+        info = &data->requestInfo->info;
+    }
+
+    if (NULL != data->responseInfo)
+    {
+        OIC_LOG_V(INFO, ANALYZER_TAG, "result code = [%d]", data->responseInfo->result);
+        info = &data->responseInfo->info;
+    }
+
+    if (pdu->transport_hdr)
+    {
+        OIC_LOG_V(INFO, ANALYZER_TAG, "Msg ID = [%d]", pdu->transport_hdr->udp.id);
+    }
+
+    if (info)
+    {
+        OIC_LOG(INFO, ANALYZER_TAG, "Coap Token");
+        OIC_LOG_BUFFER(INFO, ANALYZER_TAG, (const uint8_t *) info->token, info->tokenLength);
+        OIC_TRACE_BUFFER("OIC_CA_MSG_HANDLE:CALogPDUInfo:token",
+                         (const uint8_t *) info->token, info->tokenLength);
+        OIC_LOG_V(INFO, ANALYZER_TAG, "Res URI = [%s]", info->resourceUri);
+        OIC_TRACE_MARK(%s:CALogPDUInfo:uri:%s, TAG, info->resourceUri);
+
+        if (CA_FORMAT_APPLICATION_CBOR == info->payloadFormat)
+        {
+            OIC_LOG(INFO, ANALYZER_TAG, "Payload Format = [CA_FORMAT_APPLICATION_CBOR]");
+        }
+        else
+        {
+            OIC_LOG_V(INFO, ANALYZER_TAG, "Payload Format = [%d]", info->payloadFormat);
+        }
+    }
+
+    size_t payloadLen = (pdu->data) ? (unsigned char *) pdu->hdr + pdu->length - pdu->data : 0;
+    OIC_LOG_V(INFO, ANALYZER_TAG, "CoAP Message Full Size = [%lu]", pdu->length);
+    OIC_LOG(INFO, ANALYZER_TAG, "CoAP Header (+ 0xFF)");
+    OIC_LOG_BUFFER(INFO, ANALYZER_TAG,  (const uint8_t *) pdu->transport_hdr,
+                   pdu->length - payloadLen);
+    OIC_LOG_V(INFO, ANALYZER_TAG, "CoAP Header size = [%lu]", pdu->length - payloadLen);
+
+    OIC_LOG_V(INFO, ANALYZER_TAG, "CoAP Payload");
+    OIC_LOG_BUFFER(INFO_PRIVATE, ANALYZER_TAG, pdu->data, payloadLen);
+    OIC_LOG_V(INFO, ANALYZER_TAG, "CoAP Payload Size = [%lu]", payloadLen);
+    OIC_LOG(INFO, ANALYZER_TAG, "=================================================");
+
+    // samsung log
+    CASamsungLogMessage(data, pdu);
+    OIC_TRACE_END();
+}
+
+static void CASamsungLogMessage(const CAData_t *data, const coap_pdu_t *pdu)
+{
+    OIC_LOG(INFO, TAG, "CASamsungLogMessage");
+    VERIFY_NON_NULL_VOID(data, TAG, "data");
+    VERIFY_NON_NULL_VOID(pdu, TAG, "pdu");
+    VERIFY_NON_NULL_VOID(data->remoteEndpoint, TAG, "data->remoteEndpoint");
+
+    const CAInfo_t *info = NULL;
+    if (NULL != data->requestInfo)
+    {
+        info = &data->requestInfo->info;
+    }
+
+    if (NULL != data->responseInfo)
+    {
+        info = &data->responseInfo->info;
+    }
+
+    VERIFY_NON_NULL_VOID(info, TAG, "info");
+
+    memset(g_headerBuffer, 0, MAX_LOG_BUFFER_SIZE);
+    g_headerIndex = 0;
+
+    g_headerBuffer[g_headerIndex++] = data->dataType;
+    g_headerBuffer[g_headerIndex++] = '|';
+    g_headerBuffer[g_headerIndex++] = data->remoteEndpoint->adapter;
+    g_headerBuffer[g_headerIndex++] = '|';
+    g_headerBuffer[g_headerIndex++] = data->type;
+    g_headerBuffer[g_headerIndex++] = '|';
+
+    if (NULL != data->remoteEndpoint)
+    {
+        int i = 0;
+        while (NULL != data->remoteEndpoint->addr[i])
+        {
+            g_headerBuffer[g_headerIndex++] = data->remoteEndpoint->addr[i];
+            i++;
+        }
+        g_headerBuffer[g_headerIndex++] = ':';
+        g_headerBuffer[g_headerIndex++] = (data->remoteEndpoint->port >> 8) & 0x0000ff;
+        g_headerBuffer[g_headerIndex++] = data->remoteEndpoint->port & 0x000000ff;
+    }
+
+    g_headerBuffer[g_headerIndex++] = '|';
+    if (data->requestInfo)
+    {
+        g_headerBuffer[g_headerIndex++] = data->requestInfo->method;
+    }
+    else
+    {
+        g_headerBuffer[g_headerIndex++] = 0;
+    }
+
+    g_headerBuffer[g_headerIndex++] = '|';
+    if (data->responseInfo)
+    {
+        g_headerBuffer[g_headerIndex++] = data->responseInfo->result;
+    }
+    else
+    {
+        g_headerBuffer[g_headerIndex++] = 0;
+    }
+    g_headerBuffer[g_headerIndex++] = '|';
+
+    if (pdu->transport_hdr)
+    {
+        g_headerBuffer[g_headerIndex++] = (pdu->transport_hdr->udp.id >> 8) & 0x0000ff;
+        g_headerBuffer[g_headerIndex++] = pdu->transport_hdr->udp.id & 0x000000ff;
+    }
+    else
+    {
+        g_headerBuffer[g_headerIndex++] = 0;
+        g_headerBuffer[g_headerIndex++] = 0;
+    }
+    g_headerBuffer[g_headerIndex++] = '|';
+
+    if (info->token && info->tokenLength > 0)
+    {
+        for (size_t i = 0; i < info->tokenLength; i++)
+        {
+            g_headerBuffer[g_headerIndex++] = info->token[i];
+        }
+        g_headerBuffer[g_headerIndex++] = '|';
+    }
+
+    if (info->resourceUri)
+    {
+        size_t i = 0;
+        while (NULL != info->resourceUri[i])
+        {
+            g_headerBuffer[g_headerIndex++] = info->resourceUri[i];
+            i++;
+        }
+        g_headerBuffer[g_headerIndex++] = '|';
+    }
+
+    OIC_LOG_CA_BUFFER(INFO, TAG, (uint8_t *) g_headerBuffer, g_headerIndex, 1);
+    size_t payloadLen = (unsigned char *) pdu->hdr + pdu->length - pdu->data;
+    OIC_LOG_CA_BUFFER(INFO_PRIVATE, TAG, pdu->data, payloadLen, 0);
+}
+#endif
+
+#else
+static void CALogPDUInfo(const CAData_t *data, const coap_pdu_t *pdu)
+{
+    VERIFY_NON_NULL_VOID(pdu, TAG, "pdu");
+    (void)data;
+
+    OIC_LOG_V(DEBUG, TAG, "PDU Maker - payload : %s", pdu->data);
+    OIC_LOG_V(DEBUG, TAG, "PDU Maker - type : %d", pdu->transport_hdr->udp.type);
+    OIC_LOG_V(DEBUG, TAG, "PDU Maker - code : %d", pdu->transport_hdr->udp.code);
+    OIC_LOG(DEBUG, TAG, "PDU Maker - token :");
+    OIC_LOG_BUFFER(DEBUG, TAG, pdu->transport_hdr->udp.token,
+                   pdu->transport_hdr->udp.token_length);
+}
+#endif