replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_edr_adapter / tizen / caedrendpoint.c
1 /* ****************************************************************
2  *
3  * Copyright 2014 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************/
20
21 /**
22  * @file
23  *
24  * This file provides the APIs to send data on established RFCOMM connections.
25  */
26
27 #include "caedrendpoint.h"
28 #include "caadapterutils.h"
29 #include "caedrutils.h"
30 #include "logger.h"
31
32 CAResult_t CAEDRSendData(int serverFD, const char *addr, const void *data, uint32_t dataLength)
33 {
34     OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "IN");
35
36     VERIFY_NON_NULL(data, EDR_ADAPTER_TAG, "Data is null");
37     VERIFY_NON_NULL(addr, EDR_ADAPTER_TAG, "Addr is null");
38
39     if (0 > serverFD)
40     {
41         OIC_LOG(ERROR, EDR_ADAPTER_TAG, "Invalid input: Negative socket id");
42         return CA_STATUS_INVALID_PARAM;
43     }
44
45     int dataLen = bt_socket_send_data(serverFD, (const char *)data, dataLength);
46     int errcode = get_last_result();
47
48     if (TIZEN_ERROR_NONE == errcode)
49     {
50         CALogSendStateInfo(CA_ADAPTER_RFCOMM_BTEDR, addr, 0, dataLength, true, NULL);
51     }
52     else
53     {
54         if (dataLen == -1)
55         {
56             OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "sending data failed!, soketid [%d] errmsg [%s]",
57                       serverFD, get_error_message(errcode));
58         }
59         else if (dataLen == 0)
60         {
61             OIC_LOG_V(ERROR, EDR_ADAPTER_TAG, "soketid [%d] may be disconnected? errmsg [%s]",
62                       serverFD, get_error_message(errcode));
63         }
64
65         CALogSendStateInfo(CA_ADAPTER_RFCOMM_BTEDR, addr, 0, dataLength,
66                            false, get_error_message(errcode));
67
68         return CA_SOCKET_OPERATION_FAILED;
69     }
70
71     OIC_LOG(DEBUG, EDR_ADAPTER_TAG, "OUT");
72     return CA_STATUS_OK;
73 }
74