replace : iotivity -> iotivity-sec
[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  * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
93  * @pre Callback must be registered using CAEDRSetPacketReceivedCallback().
94  */
95 typedef CAResult_t (*CAEDRDataReceivedCallback)(const char *remoteAddress, const uint8_t *data,
96                                                 uint32_t dataLength, uint32_t *sentLength);
97
98 /**
99  * This will be used during change in network status.
100  * @param[in] status        Network Status of the adapter.
101  */
102 typedef void (*CAEDRNetworkStatusCallback)(CANetworkStatus_t status);
103
104 /**
105  * Callback to notify the error in the EDR adapter.
106  * @param[in]  remoteAddress   Remote EDR Address.
107  * @param[in]  data            data containing token, uri and coap data.
108  * @param[in]  dataLength      length of data.
109  * @param[in]  result          error code as defined in ::CAResult_t.
110  * @pre Callback must be registered using CAEDRSetPacketReceivedCallback().
111  */
112 typedef void (*CAEDRErrorHandleCallback)(const char *remoteAddress,
113                                          const uint8_t *data,
114                                          uint32_t dataLength,
115                                          CAResult_t result);
116
117 /**
118  * Initialize the network monitor module
119  * @param[in]  threadPool   Threadpool Handle.
120  * @return ::CA_STATUS_OK or Appropriate error code.
121  * @retval ::CA_STATUS_OK  Successful.
122  * @retval ::CA_ADAPTER_NOT_ENABLED Initialization is successful, but
123  * bluetooth adapter is not enabled.
124  * @retval ::CA_STATUS_FAILED Operation failed.
125  * @see  CAEDRTerminateNetworkMonitor().
126  */
127 CAResult_t CAEDRInitializeNetworkMonitor(const ca_thread_pool_t threadPool);
128
129 /**
130  * Deinitialize with bluetooth adapter.
131  * @pre    CAEDRInitializeNetworkMonitor() should be invoked before using
132  * this API.
133  * @see    CAEDRInitializeNetworkMonitor().
134  */
135 void CAEDRTerminateNetworkMonitor();
136
137 /**
138  * Start Network Monitoring Process.
139  * @return ::CA_STATUS_OK or Appropriate error code.
140  */
141 CAResult_t CAEDRStartNetworkMonitor();
142
143 /**
144  * Stop Network Monitoring Process.
145  * @return ::CA_STATUS_OK or Appropriate error code.
146  */
147 CAResult_t CAEDRStopNetworkMonitor();
148
149 /**
150  * Sets the callback and Starts discovery for nearby OIC bluetooth devices.
151  *
152  * @return ::CA_STATUS_OK or Appropriate error code.
153  * @retval ::CA_STATUS_OK  Successful.
154  * @retval ::CA_STATUS_FAILED Operation failed.
155  */
156 CAResult_t CAEDRClientSetCallbacks();
157
158 /**
159  * Resetting callbacks with bluetooth framework and stop OIC device discovery.
160  * @pre    CAEDRClientSetCallbacks() should be invoked before using this API.
161  * @see    CAEDRClientSetCallbacks().
162  */
163 void CAEDRClientUnsetCallbacks();
164
165 /**
166  * Used to initialize the EDR client module where mutex is initialized.
167  * @return ::CA_STATUS_OK or Appropriate error code.
168  */
169 CAResult_t CAEDRClientInitialize();
170
171 /**
172  * Destroys the Device list and mutex.
173  */
174 void CAEDRClientTerminate();
175
176 /**
177  * Closes all the client connection to peer bluetooth devices.
178  */
179 void CAEDRClientDisconnectAll();
180
181 /**
182  * Register callback to send the received packets from remote bluetooth
183  * device to BTAdapter.
184  *
185  * @param[in]  packetReceivedCallback Callback function to register for
186  * sending network packets to EDR Adapter.
187  */
188 void CAEDRSetPacketReceivedCallback(CAEDRDataReceivedCallback packetReceivedCallback);
189
190 /**
191  * Register callback for receiving local bluetooth adapter state.
192  *
193  * @param[in]  networkStateChangeCallback Callback function to register
194  * for receiving local bluetooth adapter status.
195  */
196 void CAEDRSetNetworkChangeCallback(CAEDRNetworkStatusCallback networkStateChangeCallback);
197
198 /**
199  * set error callback to notify error in EDR adapter.
200  *
201  * @param[in]  errorHandleCallback Callback function to notify the error
202  * in the EDR adapter.
203  */
204 void CAEDRSetErrorHandler(CAEDRErrorHandleCallback errorHandleCallback);
205
206
207 /**
208  * Get the local bluetooth adapter information.
209  *
210  * @param[out]  info Local bluetooth adapter information.
211  *
212  * @return ::CA_STATUS_OK or Appropriate error code.
213  * @retval ::CA_STATUS_OK  Successful.
214  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
215  * @retval ::CA_STATUS_FAILED Operation failed.
216  *
217  * @see CALocalConnectivity_t
218  *
219  */
220 CAResult_t CAEDRGetInterfaceInformation(CAEndpoint_t **info);
221
222 /**
223  * Start RFCOMM server for given service UUID
224  *
225  * @return ::CA_STATUS_OK or Appropriate error code.
226  * @retval ::CA_STATUS_OK  Successful.
227  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
228  * @retval ::CA_STATUS_FAILED Operation failed.
229  *
230  */
231 CAResult_t CAEDRServerStart();
232
233 /**
234  * Stop RFCOMM server
235  *
236  * @return ::CA_STATUS_OK or Appropriate error code.
237  * @retval ::CA_STATUS_OK  Successful.
238  * @retval ::CA_STATUS_FAILED Operation failed.
239  */
240 CAResult_t CAEDRServerStop();
241
242 /**
243  * Used to initialize the EDR server module where mutex is initialized.
244  * @param[in]  threadPool   Threadpool Handle.
245  * @return ::CA_STATUS_OK or Appropriate error code.
246  */
247 CAResult_t CAEDRServerInitialize(ca_thread_pool_t handle);
248
249 /**
250  * Terminate server for EDR.
251  */
252 void CAEDRServerTerminate();
253
254 /**
255  * All received data will be notified to upper layer.
256  *
257  * @return ::CA_STATUS_OK or Appropriate error code.
258  * @retval ::CA_STATUS_OK  Successful.
259  * @retval ::CA_STATUS_FAILED Operation failed.
260  *
261  */
262 CAResult_t CAEDRManagerReadData();
263
264 /**
265  * This function gets bluetooth adapter enable state.
266  * @param[out]  state    State of the Adapter.
267  * @return ::CA_STATUS_OK or Appropriate error code.
268  */
269 CAResult_t CAEDRGetAdapterEnableState(bool *state);
270
271 /**
272  * This function sends data to specified remote bluetooth device.
273  * @param[in]  remoteAddress   Remote EDR Address.
274  * @param[in]  data            Data to be sent.
275  * @param[in]  dataLength      Length of the data to be sent.
276  * @return ::CA_STATUS_OK or Appropriate error code.
277  */
278 CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress,
279                                       const uint8_t *data,
280                                       uint32_t dataLength);
281
282 /**
283  * This function sends data to all bluetooth devices running OIC service.
284  * @param[in]  data            Data to be sent.
285  * @param[in]  dataLength      Length of the data to be sent.
286  * @return ::CA_STATUS_OK or Appropriate error code.
287  */
288 CAResult_t CAEDRClientSendMulticastData(const uint8_t *data,
289                                         uint32_t dataLength);
290
291 /**
292  * This function gets bonded bluetooth device list
293  * @return ::CA_STATUS_OK or Appropriate error code.
294  */
295 CAResult_t CAEDRGetBondedDeviceList();
296
297 #ifdef __TIZEN__
298 /**
299  * This function starts device discovery.
300  */
301 CAResult_t CAEDRStartDeviceDiscovery(void);
302 #endif
303
304 #ifdef __cplusplus
305 } /* extern "C" */
306 #endif
307
308 #endif /* CA_EDR_INTERFACE_H_ */