replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_edr_adapter / tizen / caedrendpoint.c
index 054b1fa..319af2b 100644 (file)
@@ -1,4 +1,4 @@
-/******************************************************************
+/* ****************************************************************
  *
  * Copyright 2014 Samsung Electronics All Rights Reserved.
  *
@@ -19,8 +19,9 @@
  ******************************************************************/
 
 /**
- * @file  cabtendpoint.c
- * @brief  This file provides the APIs to send data on established RFCOMM connections.
+ * @file
+ *
+ * This file provides the APIs to send data on established RFCOMM connections.
  */
 
 #include "caedrendpoint.h"
 #include "caedrutils.h"
 #include "logger.h"
 
-CAResult_t CAEDRSendData(const int32_t serverFD, const void *data, const uint32_t dataLength,
-                         uint32_t *sentDataLen)
+CAResult_t CAEDRSendData(int serverFD, const char *addr, const void *data, uint32_t dataLength)
 {
-    OIC_LOG_V(DEBUG, EDR_ADAPTER_TAG, "IN");
+    OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
 
     VERIFY_NON_NULL(data, EDR_ADAPTER_TAG, "Data is null");
-    VERIFY_NON_NULL(sentDataLen, EDR_ADAPTER_TAG, "Sent data length holder is null");
+    VERIFY_NON_NULL(addr, EDR_ADAPTER_TAG, "Addr is null");
 
     if (0 > serverFD)
     {
-        OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "Invalid input: Negative socket id");
+        OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Invalid input: Negative socket id");
         return CA_STATUS_INVALID_PARAM;
     }
 
-    int32_t dataLen = 0;
-    dataLen = bt_socket_send_data(serverFD, (const char *)data, dataLength);
-    if (dataLen == -1)
+    int dataLen = bt_socket_send_data(serverFD, (const char *)data, dataLength);
+    int errcode = get_last_result();
+
+    if (TIZEN_ERROR_NONE == errcode)
     {
-        OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "sending data failed!, soketid [%d]", serverFD);
-        *sentDataLen = 0;
-        return CA_STATUS_FAILED;
+        CALogSendStateInfo(CA_ADAPTER_RFCOMM_BTEDR, addr, 0, dataLength, true, NULL);
     }
+    else
+    {
+        if (dataLen == -1)
+        {
+            OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "sending data failed!, soketid [%d] errmsg [%s]",
+                      serverFD, get_error_message(errcode));
+        }
+        else if (dataLen == 0)
+        {
+            OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "soketid [%d] may be disconnected? errmsg [%s]",
+                      serverFD, get_error_message(errcode));
+        }
+
+        CALogSendStateInfo(CA_ADAPTER_RFCOMM_BTEDR, addr, 0, dataLength,
+                           false, get_error_message(errcode));
 
-    *sentDataLen = dataLen;
-    OIC_LOG_V(DEBUG, EDR_ADAPTER_TAG, "OUT");
+        return CA_SOCKET_OPERATION_FAILED;
+    }
+
+    OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
     return CA_STATUS_OK;
 }
+