92de5002a8c03e130625741babeadf4514d5efa4
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caedrinterface.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 provides APIs for EDR adapter - client, server, network monitor
25  * modules.
26  */
27
28 #ifndef CA_EDR_INTERFACE_H_
29 #define CA_EDR_INTERFACE_H_
30
31 #include "caedradapter.h"
32
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #endif
37
38 #ifndef OIC_EDR_SERVICE_ID
39 #define OIC_EDR_SERVICE_ID "12341234-1C25-481F-9DFB-59193D238280"
40 #endif //OIC_EDR_SERVICE_ID
41
42 typedef enum
43 {
44     STATE_DISCONNECTED, /**< State is Disconnected. */
45     STATE_CONNECTED     /**< State is Connected. */
46 } CAConnectedState_t;
47
48 typedef struct connected_device
49 {
50     uint8_t address[CA_MACADDR_SIZE];
51     CAConnectedState_t state;
52     uint8_t *recvData;
53     size_t recvDataLen;
54     size_t totalDataLen;
55 } CAConnectedDeviceInfo_t;
56
57 /**
58  * Enum for defining different server types.
59  */
60 typedef enum
61 {
62     CA_UNICAST_SERVER = 0,    /**< Unicast Server. */
63     CA_MULTICAST_SERVER,      /**< Multicast Server. */
64     CA_SECURED_UNICAST_SERVER /**< Secured Unicast Server. */
65 } CAAdapterServerType_t;
66
67 /**
68  * Structure to maintain the information of data in message queue.
69  */
70 typedef struct
71 {
72     CAEndpoint_t *remoteEndpoint;       /**< Remote Endpoint. */
73     uint8_t *data;                      /**< Data to be sent. */
74     uint32_t dataLen;                   /**< Length of the data to be sent. */
75 } CAEDRData;
76
77 /**
78  * Structure to maintain the adapter information and its status.
79  */
80 typedef struct
81 {
82     CAEndpoint_t *info;          /**< Local Connectivity Information. */
83     CANetworkStatus_t status;    /**< Network Status. */
84 } CAEDRNetworkEvent;
85
86 /**
87  * This will be used during the Receiver of network requests and response.
88  * @param[in] remoteAddress EDR address of remote OIC device from which data received.
89  * @param[in] data          Data received.
90  * @param[in] dataLength    Length of the Data received.
91  * @param[out] sentLength    Length of the sent data.
92  * @pre Callback must be registered using CAEDRSetPacketReceivedCallback().
93  */
94 typedef void (*CAEDRDataReceivedCallback)(const char *remoteAddress, const uint8_t *data,
95                                           uint32_t dataLength, uint32_t *sentLength);
96
97 /**
98  * This will be used during change in network status.
99  * @param[in] status        Network Status of the adapter.
100  */
101 typedef void (*CAEDRNetworkStatusCallback)(CANetworkStatus_t status);
102
103 /**
104  * Callback to notify the error in the EDR adapter.
105  * @param[in]  remoteAddress   Remote EDR Address.
106  * @param[in]  data            data containing token, uri and coap data.
107  * @param[in]  dataLength      length of data.
108  * @param[in]  result          error code as defined in ::CAResult_t.
109  * @pre Callback must be registered using CAEDRSetPacketReceivedCallback().
110  */
111 typedef void (*CAEDRErrorHandleCallback)(const char *remoteAddress,
112                                          const uint8_t *data,
113                                          uint32_t dataLength,
114                                          CAResult_t result);
115
116 /**
117  * Initialize the network monitor module
118  * @param[in]  threadPool   Threadpool Handle.
119  * @return ::CA_STATUS_OK or Appropriate error code.
120  * @retval ::CA_STATUS_OK  Successful.
121  * @retval ::CA_ADAPTER_NOT_ENABLED Initialization is successful, but
122  * bluetooth adapter is not enabled.
123  * @retval ::CA_STATUS_FAILED Operation failed.
124  * @see  CAEDRTerminateNetworkMonitor().
125  */
126 CAResult_t CAEDRInitializeNetworkMonitor(const ca_thread_pool_t threadPool);
127
128 /**
129  * Deinitialize with bluetooth adapter.
130  * @pre    CAEDRInitializeNetworkMonitor() should be invoked before using
131  * this API.
132  * @see    CAEDRInitializeNetworkMonitor().
133  */
134 void CAEDRTerminateNetworkMonitor();
135
136 /**
137  * Start Network Monitoring Process.
138  * @return ::CA_STATUS_OK or Appropriate error code.
139  */
140 CAResult_t CAEDRStartNetworkMonitor();
141
142 /**
143  * Stop Network Monitoring Process.
144  * @return ::CA_STATUS_OK or Appropriate error code.
145  */
146 CAResult_t CAEDRStopNetworkMonitor();
147
148 /**
149  * Sets the callback and Starts discovery for nearby OIC bluetooth devices.
150  *
151  * @return ::CA_STATUS_OK or Appropriate error code.
152  * @retval ::CA_STATUS_OK  Successful.
153  * @retval ::CA_STATUS_FAILED Operation failed.
154  */
155 CAResult_t CAEDRClientSetCallbacks();
156
157 /**
158  * Resetting callbacks with bluetooth framework and stop OIC device discovery.
159  * @pre    CAEDRClientSetCallbacks() should be invoked before using this API.
160  * @see    CAEDRClientSetCallbacks().
161  */
162 void CAEDRClientUnsetCallbacks();
163
164 /**
165  * Used to initialize the EDR client module where mutex is initialized.
166  * @return ::CA_STATUS_OK or Appropriate error code.
167  */
168 CAResult_t CAEDRClientInitialize();
169
170 /**
171  * Destroys the Device list and mutex.
172  */
173 void CAEDRClientTerminate();
174
175 /**
176  * Closes all the client connection to peer bluetooth devices.
177  */
178 void CAEDRClientDisconnectAll();
179
180 /**
181  * Register callback to send the received packets from remote bluetooth
182  * device to BTAdapter.
183  *
184  * @param[in]  packetReceivedCallback Callback function to register for
185  * sending network packets to EDR Adapter.
186  */
187 void CAEDRSetPacketReceivedCallback(CAEDRDataReceivedCallback packetReceivedCallback);
188
189 /**
190  * Register callback for receiving local bluetooth adapter state.
191  *
192  * @param[in]  networkStateChangeCallback Callback function to register
193  * for receiving local bluetooth adapter status.
194  */
195 void CAEDRSetNetworkChangeCallback(CAEDRNetworkStatusCallback networkStateChangeCallback);
196
197 /**
198  * set error callback to notify error in EDR adapter.
199  *
200  * @param[in]  errorHandleCallback Callback function to notify the error
201  * in the EDR adapter.
202  */
203 void CAEDRSetErrorHandler(CAEDRErrorHandleCallback errorHandleCallback);
204
205
206 /**
207  * Get the local bluetooth adapter information.
208  *
209  * @param[out]  info Local bluetooth adapter information.
210  *
211  * @return ::CA_STATUS_OK or Appropriate error code.
212  * @retval ::CA_STATUS_OK  Successful.
213  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
214  * @retval ::CA_STATUS_FAILED Operation failed.
215  *
216  * @see CALocalConnectivity_t
217  *
218  */
219 CAResult_t CAEDRGetInterfaceInformation(CAEndpoint_t **info);
220
221 /**
222  * Start RFCOMM server for given service UUID
223  *
224  * @return ::CA_STATUS_OK or Appropriate error code.
225  * @retval ::CA_STATUS_OK  Successful.
226  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
227  * @retval ::CA_STATUS_FAILED Operation failed.
228  *
229  */
230 CAResult_t CAEDRServerStart();
231
232 /**
233  * Stop RFCOMM server
234  *
235  * @return ::CA_STATUS_OK or Appropriate error code.
236  * @retval ::CA_STATUS_OK  Successful.
237  * @retval ::CA_STATUS_FAILED Operation failed.
238  */
239 CAResult_t CAEDRServerStop();
240
241 /**
242  * Used to initialize the EDR server module where mutex is initialized.
243  * @param[in]  threadPool   Threadpool Handle.
244  * @return ::CA_STATUS_OK or Appropriate error code.
245  */
246 CAResult_t CAEDRServerInitialize(ca_thread_pool_t handle);
247
248 /**
249  * Terminate server for EDR.
250  */
251 void CAEDRServerTerminate();
252
253 /**
254  * All received data will be notified to upper layer.
255  *
256  * @return ::CA_STATUS_OK or Appropriate error code.
257  * @retval ::CA_STATUS_OK  Successful.
258  * @retval ::CA_STATUS_FAILED Operation failed.
259  *
260  */
261 CAResult_t CAEDRManagerReadData();
262
263 /**
264  * This function gets bluetooth adapter enable state.
265  * @param[out]  state    State of the Adapter.
266  * @return ::CA_STATUS_OK or Appropriate error code.
267  */
268 CAResult_t CAEDRGetAdapterEnableState(bool *state);
269
270 /**
271  * This function sends data to specified remote bluetooth device.
272  * @param[in]  remoteAddress   Remote EDR Address.
273  * @param[in]  data            Data to be sent.
274  * @param[in]  dataLength      Length of the data to be sent.
275  * @return ::CA_STATUS_OK or Appropriate error code.
276  */
277 CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress,
278                                       const uint8_t *data,
279                                       uint32_t dataLength);
280
281 /**
282  * This function sends data to all bluetooth devices running OIC service.
283  * @param[in]  data            Data to be sent.
284  * @param[in]  dataLength      Length of the data to be sent.
285  * @return ::CA_STATUS_OK or Appropriate error code.
286  */
287 CAResult_t CAEDRClientSendMulticastData(const uint8_t *data,
288                                         uint32_t dataLength);
289
290 /**
291  * This function gets bonded bluetooth device list
292  * @return ::CA_STATUS_OK or Appropriate error code.
293  */
294 CAResult_t CAEDRGetBondedDeviceList();
295
296 #ifdef __TIZEN__
297 /**
298  * This function starts device discovery.
299  */
300 CAResult_t CAEDRStartDeviceDiscovery(void);
301 #endif
302
303 #ifdef __cplusplus
304 } /* extern "C" */
305 #endif
306
307 #endif /* CA_EDR_INTERFACE_H_ */