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