02328ac5f74866be9d02bc97ba5452dd580817ce
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caedradapter.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  * @file caedradapter.h
22  * @brief This file contains the APIs for EDR adapters to be implemented
23  */
24 #ifndef __CA_EDRADAPTER_H_
25 #define __CA_EDRADAPTER_H_
26
27 /**
28  * BT Interface AP
29  **/
30 #include "cacommon.h"
31 #include "caadapterinterface.h"
32 #ifndef ARDUINO
33 #include "uthreadpool.h" /* for thread pool */
34 #endif  //ARDUINO
35
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #endif
40
41 /**
42  * @fn  CAInitializeEDR
43  * @brief  Initialize EDR connectivity interface.
44  *
45  * @param[in]  registerCallback  To register EDR interfaces to Connectivity Abstraction Layer
46  * @param[in]  reqRespCallback  Callback to be notified on receival of request/responses from
47  * peer bluetooth devices.
48  * @param[in]  netCallback  Callback to be notified when network adapter state changes.
49  * @param[in]  threadPool  Thread pool for handling asynchronous tasks.
50  *
51  * @return  #CA_STATUS_OK or #CA_ADAPTER_NOT_ENABLED on success otherwise proper error code.
52  * @retval  #CA_STATUS_OK  Successful
53  * @retval  #CA_STATUS_INVALID_PARAM  Invalid input parameters
54  * @retval  #CA_ADAPTER_NOT_ENABLED Initialization is successful, but bluetooth adapter is
55  * not enabled
56  * @retval  #CA_STATUS_FAILED Operation failed
57  */
58 #ifdef ARDUINO
59 CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
60                            CANetworkPacketReceivedCallback reqRespCallback,
61                            CANetworkChangeCallback netCallback);
62 #else
63 CAResult_t CAInitializeEDR(CARegisterConnectivityCallback registerCallback,
64                            CANetworkPacketReceivedCallback reqRespCallback,
65                            CANetworkChangeCallback netCallback,
66                            u_thread_pool_t handle);
67 #endif //#ifdef ARDUINO
68
69
70 /**
71  * @fn  CAStartEDR
72  * @brief  Starting EDR connectivity adapters. As its peer to peer it doesnot require to start
73  * any servers.
74  *
75  * @return  #CA_STATUS_OK on success otherwise proper error code.
76  * @retval  #CA_STATUS_OK  Successful
77  * @retval  #CA_ADAPTER_NOT_ENABLED Bluetooth adapter is not enabled
78  * @retval  #CA_STATUS_FAILED Operation failed
79  *
80  */
81 CAResult_t CAStartEDR();
82
83 /**
84  * @fn  CAStartEDRListeningServer
85  * @brief  Starting listening server for receiving multicast search requests.
86  * Starts RFCOMM Server with prefixed UUID as per OIC specification.
87  *
88  * @return  #CA_STATUS_OK on success otherwise proper error code.
89  * @retval  #CA_STATUS_OK  Successful
90  * @retval  #CA_SERVER_STARTED_ALREADY  Server is already started and running for the predefined
91  *                                                            service UUID
92  * @retval  #CA_STATUS_FAILED Operation failed
93  *
94  */
95 CAResult_t CAStartEDRListeningServer();
96
97 /**
98  * @fn  CAStartEDRDiscoveryServer
99  * @brief  Starting discovery server for receiving multicast advertisements.
100  * Starts RFCOMM Server with prefixed UUID as per OIC specification.
101  *
102  * @return  #CA_STATUS_OK on success otherwise proper error code.
103  * @retval  #CA_STATUS_OK  Successful
104  * @retval  #CA_SERVER_STARTED_ALREADY  Server is already started and running for the predefined
105  * service UUID
106  * @retval  #CA_STATUS_FAILED Operation failed
107  *
108  */
109 CAResult_t CAStartEDRDiscoveryServer();
110
111 /**
112  * @fn  CASendEDRUnicastData
113  * @brief  Sends data to the peer bluetooth OIC device using the adapter connectivity.
114  *
115  * @param[in]  remoteEndpoint  Information about peer device to which data needs to be send.
116  * @param[in]  data  Data which needs to be send to peer OIC device.
117  * @param[in]  dataLength  Length of data in bytes.
118  *
119  * @return  Number of bytes sent on the network. 0 indicates failed to send data.
120  *
121  */
122 uint32_t CASendEDRUnicastData(const CARemoteEndpoint_t *remoteEndpoint, void *data,
123                               uint32_t dataLength);
124
125 /**
126  * @fn  CASendEDRMulticastData
127  * @brief  Sends multicast data to all discovered bluetooth OIC devices using the adapter
128  * connectivity.
129  *
130  * @param[in]  data  Data which needs to be send to all discovered bluetooth OIC device.
131  * @param[in]  dataLength  Length of data in bytes.
132  *
133  * @return  Number of bytes sent on the network. 0 indicates failed to send data.
134  *
135  */
136 uint32_t CASendEDRMulticastData(void *data, uint32_t dataLength);
137
138 /**
139  * @fn  CAGetEDRInterfaceInformation
140  * @brief  Get EDR Connectivity network information.
141  *
142  * @param[out]  info  Array of local connectivity information structures.
143  * @param[out]  size  Size of the array @info.
144  *
145  * @return  #CA_STATUS_OK on success otherwise proper error code.
146  * @retval  #CA_STATUS_OK  Successful
147  * @retval  #CA_STATUS_INVALID_PARAM  Invalid input parameters
148  * @retval  #CA_MEMORY_ALLOC_FAILED  Failed to allocate memory
149  * @retval  #CA_STATUS_FAILED Operation failed
150  *
151  */
152 CAResult_t CAGetEDRInterfaceInformation(CALocalConnectivity_t **info, uint32_t *size);
153
154 /**
155  * @fn  CAReadEDRData
156  * @brief  Read Synchronous API callback.
157  *
158  * @return  #CA_STATUS_OK on success otherwise proper error code.
159  * @retval  #CA_STATUS_OK  Successful
160  * @retval  #CA_STATUS_FAILED Operation failed
161  *
162  */
163 CAResult_t CAReadEDRData();
164
165 /**
166  * @fn  CAStopEDR
167  * @brief  Stopping the adapters and close socket connections
168  * EDR Stops all RFCOMM servers and close sockets.
169  *
170  * @return  #CA_STATUS_OK on success
171  *
172  */
173 CAResult_t CAStopEDR();
174
175 /**
176  * @fn  CATerminateEDR
177  * @brief  Terminate the EDR connectivity adapter.
178  * Configuration information will be deleted from further use.
179  *
180  */
181 void CATerminateEDR();
182
183 #ifdef __cplusplus
184 } /* extern "C" */
185 #endif
186
187 #endif  //__CA_EDRADAPTER_H_