Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caedradapter_singlethread.h
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 contains the APIs for EDR adapters to be implemented.
25  */
26
27 #ifndef CA_EDRADAPTER_SINGLETHREAD_H_
28 #define CA_EDRADAPTER_SINGLETHREAD_H_
29
30 /**
31  * EDR Interface AP
32  **/
33 #include "cacommon.h"
34 #include "caadapterinterface.h"
35
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #endif
40
41 /**
42  * @brief  Initialize EDR Interface.
43  * @param  registerCallback  [IN] Callback to register EDR interface to Connectivity
44  *                                Abstraction Layer
45  * @param  reqRespCallback   [IN] Callback to notify request and response messages from server(s)
46  *                                started at Connectivity Abstraction Layer.
47  * @param  netCallback       [IN] Callback to notify the network additions to Connectivity
48  *                                Abstraction Layer.
49  * @return #CA_STATUS_OK or Appropriate error code
50  * @retval #CA_STATUS_OK Successful
51  * @retval #CA_STATUS_INVALID_PARAM Invalid input parameters
52  * @retval #CA_ADAPTER_NOT_ENABLED Initialization is successful, but bluetooth adapter is not
53  *                                 enabled
54  * @retval #CA_STATUS_FAILED Operation failed
55  */
56 CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
57                            CANetworkPacketReceivedCallback reqRespCallback,
58                            CANetworkChangeCallback netCallback);
59
60 /**
61  * @brief  Starting EDR connectivity adapters. As its peer to peer it doesnot require to start
62  *         any servers.
63  * @return #CA_STATUS_OK or Appropriate error code
64  * @retval #CA_STATUS_OK  Successful
65  * @retval #CA_ADAPTER_NOT_ENABLED Bluetooth adapter is not enabled
66  * @retval #CA_STATUS_FAILED Operation failed
67  */
68 CAResult_t CAStartEDR();
69
70 /**
71  * @brief  Starts listening server for receiving multicast search requests.
72  *         Starts RFCOMM Server with prefixed UUID as per OIC specification.
73  * @return #CA_STATUS_OK or Appropriate error code
74  * @retval #CA_STATUS_OK  Successful
75  * @retval #CA_SERVER_STARTED_ALREADY  Server is already started and running for the predefined
76  *                                     service UUID
77  * @retval #CA_STATUS_FAILED Operation failed
78  */
79 CAResult_t CAStartEDRListeningServer();
80
81 /**
82  * @brief  Starts discovery server for receiving multicast advertisements.
83  *         Starts RFCOMM Server with prefixed UUID as per OIC specification.
84  * @return #CA_STATUS_OK or Appropriate error code
85  * @retval #CA_STATUS_OK  Successful
86  * @retval #CA_SERVER_STARTED_ALREADY Server is already started and running for the predefined
87  *                                    service UUID
88  * @retval #CA_STATUS_FAILED Operation failed
89  */
90 CAResult_t CAStartEDRDiscoveryServer();
91
92 /**
93  * @brief  Sends data to the peer bluetooth OIC device using the adapter connectivity.
94  * @param  endpoint        [IN] Remote Endpoint information (like ipaddress, port, reference uri and
95  *                              connectivity type) to which the unicast data has to be sent.
96  * @param  data            [IN] Data to be sent.
97  * @param  dataLength      [IN] Size of data to be sent.
98  * @return Number of bytes sent on the network. Returns -1 on error.
99  */
100 int32_t CASendEDRUnicastData(const CAEndpoint_t *remoteEndpoint, const void *data,
101                               uint32_t dataLength);
102
103 /**
104  * @brief  Sends multicast data to all discovered bluetooth OIC devices using the adapter
105  *         connectivity.
106  * @param  data         [IN]  Data which needs to be sent to all discovered bluetooth OIC device.
107  * @param  dataLength   [IN]  Length of data in bytes.
108  * @return Number of bytes sent on the network. Returns -1 on error.
109  */
110 int32_t CASendEDRMulticastData(const void *data, uint32_t dataLength);
111
112 /**
113  * @brief  Get EDR Connectivity network information.
114  *
115  * @param  info [OUT] Array of local connectivity information structures.
116  * @param  size [OUT] Size of the array @info.
117  *
118  * @return #CA_STATUS_OK or Appropriate error code
119  * @retval #CA_STATUS_OK  Successful
120  * @retval #CA_STATUS_INVALID_PARAM  Invalid input parameters
121  * @retval #CA_MEMORY_ALLOC_FAILED  Failed to allocate memory
122  * @retval #CA_STATUS_FAILED Operation failed
123  * @remarks info is allocated in this API and should be freed by the caller.
124  */
125 CAResult_t CAGetEDRInterfaceInformation(CAEndpoint_t **info, uint32_t *size);
126
127 /**
128  * @brief  Read Synchronous API callback.
129  * @return #CA_STATUS_OK on success otherwise proper error code.
130  * @retval #CA_STATUS_OK  Successful
131  * @retval #CA_STATUS_FAILED Operation failed
132  */
133 CAResult_t CAReadEDRData();
134
135 /**
136  * @brief  EDR Stops all RFCOMM servers and close sockets.
137  * @return #CA_STATUS_OK or Appropriate error code
138  */
139 CAResult_t CAStopEDR();
140
141 /**
142  * @brief  Terminate the EDR connectivity adapter.
143  * Configuration information will be deleted from further use.
144  * @return NONE
145  */
146 void CATerminateEDR();
147
148 #ifdef __cplusplus
149 } /* extern "C" */
150 #endif
151
152 #endif  /* CA_EDRADAPTER_SINGLETHREAD_H_ */
153