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