Fixed klockwork memory leaks and modified the logs
[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   caedrinterface.h
23  * @brief  This file provides APIs for EDR adapter - client, server, network monitor modules
24  */
25
26 #ifndef __CA_EDR_INTERFACE_H_
27 #define __CA_EDR_INTERFACE_H_
28
29 #include <string.h>
30 #include "caedradapter.h"
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #endif
36
37 #ifndef OIC_EDR_SERVICE_ID
38 #define OIC_EDR_SERVICE_ID "12341234-1C25-481F-9DFB-59193D238280"
39 #endif //OIC_EDR_SERVICE_ID
40
41
42 typedef struct connected_state {
43     char address[CA_MACADDR_SIZE];
44     uint32_t state;
45 } state_t;
46
47 /**
48  * @enum CAAdapterServerType_t
49  * @brief Enum for defining different server types.
50  */
51 typedef enum
52 {
53     CA_UNICAST_SERVER = 0,      /**< Unicast Server */
54     CA_MULTICAST_SERVER,        /**< Multicast Server */
55     CA_SECURED_UNICAST_SERVER   /**< Secured Unicast Server */
56 } CAAdapterServerType_t;
57
58 /**
59  * @struct CAEDRData
60  * @brief Structure to maintain the information of data in message queue.
61  */
62 typedef struct
63 {
64     CARemoteEndpoint_t *remoteEndpoint; /**< Remote Endpoint */
65     void *data;                         /**< Data to be sent */
66     uint32_t dataLen;                   /**< Length of the data to be sent */
67 } CAEDRData;
68
69 /**
70  * @struct CAEDRNetworkEvent
71  * @brief Structure to maintain the adapter information and its status.
72  */
73 typedef struct
74 {
75     CALocalConnectivity_t *info;    /**< Local Connectivity Information */
76     CANetworkStatus_t status;       /**< Network Status */
77 } CAEDRNetworkEvent;
78
79 /**
80  * @brief This will be used during the recive of network requests and response.
81  * @param remoteAddress [IN] EDR address of remote OIC device
82  * @param data          [IN] Data received
83  * @param dataLength    [IN] Length of the Data received
84  * @param sentLength    [IN] Length of the sent data
85  * @return NONE
86  * @pre Callback must be registered using CAEDRSetPacketReceivedCallback()
87  */
88 typedef void (*CAEDRDataReceivedCallback)(const char *remoteAddress, void *data, uint32_t dataLength,
89                                          uint32_t *sentLength);
90
91 /**
92  * @brief This will be used during change in network status.
93  * @param status [IN] Network Status of the adapter
94  * @return NONE
95  */
96 typedef void (*CAEDRNetworkStatusCallback)(CANetworkStatus_t status);
97
98 /**
99  * @brief  Initialize the network monitor module
100  *
101  * @return #CA_STATUS_OK or Appropriate error code
102  * @retval #CA_STATUS_OK  Successful
103  * @retval #CA_ADAPTER_NOT_ENABLED Initialization is successful, but bluetooth adapter is
104  *                                 not enabled.
105  * @retval #CA_STATUS_FAILED Operation failed
106  * @see  CAEDRTerminateNetworkMonitor()
107  */
108 CAResult_t CAEDRInitializeNetworkMonitor();
109
110 /**
111  * @brief  Deinitialize with bluetooth adapter.
112  * @return NONE
113  * @pre  CAEDRInitializeNetworkMonitor() should be invoked before using this API.
114  * @see  CAEDRInitializeNetworkMonitor()
115  */
116 void CAEDRTerminateNetworkMonitor(void);
117
118 /**
119  * @brief Start Network Monitoring Process
120  * @return #CA_STATUS_OK or Appropriate error code
121  */
122 CAResult_t CAEDRStartNetworkMonitor();
123
124 /**
125  * @brief Stop Network Monitoring Process
126  * @return #CA_STATUS_OK or Appropriate error code
127  */
128 CAResult_t CAEDRStopNetworkMonitor();
129
130 /**
131  * @brief  Sets the callback and Starts discovery for nearby OIC bluetooth devices.
132  *
133  * @return #CA_STATUS_OK or Appropriate error code
134  * @retval #CA_STATUS_OK  Successful
135  * @retval #CA_STATUS_FAILED Operation failed
136  */
137 CAResult_t CAEDRClientSetCallbacks(void);
138
139 /**
140  * @brief  Resetting callbacks with bluetooth framework and stop OIC device discovery.
141  * @return NONE
142  * @pre  CAEDRClientSetCallbacks() should be invoked before using this API.
143  * @see  CAEDRClientSetCallbacks()
144  */
145 void CAEDRClientUnsetCallbacks(void);
146
147 /**
148  * @brief Used to initialize the EDR client module where mutex is initialized
149  * @return NONE
150  */
151 void CAEDRInitializeClient(u_thread_pool_t handle);
152
153 /**
154  * @brief Destroys the Device list and mutex.
155  * @return NONE
156  */
157 void CAEDRTerminateClient();
158
159 /**
160  * @brief Closes all the client connection to peer bluetooth devices.
161  * @return NONE
162  */
163 void CAEDRClientDisconnectAll(void);
164
165 /**
166  * @brief  Register callback to send the received packets from remote bluetooth device to BTAdapter.
167  *
168  * @param  packetReceivedCallback [IN] Callback function to register for sending network
169  *                                     packets to EDR Adapter.
170  * @return NONE
171  */
172 void CAEDRSetPacketReceivedCallback(CAEDRDataReceivedCallback packetReceivedCallback);
173
174 /**
175  * @brief  Register callback for receiving local bluetooth adapter state.
176  *
177  * @param  networkStateChangeCallback [IN] Callback function to register for receiving local
178  *                                         bluetooth adapter status.
179  * @return NONE
180  */
181 void CAEDRSetNetworkChangeCallback(CAEDRNetworkStatusCallback networkStateChangeCallback);
182
183
184 /**
185  * @brief  Get the local bluetooth adapter information.
186  *
187  * @param  info [IN] Local bluetooth adapter information
188  *
189  * @return #CA_STATUS_OK or Appropriate error code
190  * @retval #CA_STATUS_OK  Successful
191  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
192  * @retval #CA_STATUS_FAILED Operation failed
193  *
194  * @see #CALocalConnectivity_t
195  *
196  */
197 CAResult_t CAEDRGetInterfaceInformation(CALocalConnectivity_t **info);
198
199 /**
200  * @brief  Start RFCOMM server for given service UUID
201  *
202  * @param  serviceUUID  [IN] The UUID of service with which RFCOMM server needs to be started.
203  * @param  serverFD     [IN] The RFCOMM server socket file descriptor.
204  *
205  * @return #CA_STATUS_OK or Appropriate error code
206  * @retval #CA_STATUS_OK  Successful
207  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
208  * @retval #CA_STATUS_FAILED Operation failed
209  *
210  */
211 CAResult_t CAEDRServerStart(const char *serviceUUID, int32_t *serverFD, u_thread_pool_t handle);
212
213 /**
214  * @brief  Stop RFCOMM server
215  *
216  * @param  serverFD [IN] The RFCOMM server socket file descriptor which needs to be stopped.
217  *
218  * @return #CA_STATUS_OK or Appropriate error code
219  * @retval #CA_STATUS_OK  Successful
220  * @retval #CA_STATUS_FAILED Operation failed
221  */
222 CAResult_t CAEDRServerStop(const int32_t serverFD);
223
224 /**
225  * @brief  All received data will be notified to upper layer.
226  *
227  * @return #CA_STATUS_OK or Appropriate error code
228  * @retval #CA_STATUS_OK  Successful
229  * @retval #CA_STATUS_FAILED Operation failed
230  *
231  */
232 CAResult_t CAEDRManagerReadData(void);
233
234 /**
235  * @brief This function gets bluetooth adapter enable state.
236  * @param state    [OUT] State of the Adapter.
237  * @return #CA_STATUS_OK or Appropriate error code
238  */
239 CAResult_t CAEDRGetAdapterEnableState(CABool_t *state);
240
241 /**
242  * @brief This function sends data to specified remote bluetooth device.
243  * @param remoteAddress   [IN] Remote EDR Address
244  * @param serviceUUID     [IN] Service UUID of the device
245  * @param data            [IN] Data to be sent
246  * @param dataLength      [IN] Length of the data to be sent
247  * @param sentLength      [IN] Length of the actual sent data
248  * @return #CA_STATUS_OK or Appropriate error code
249  */
250 CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress, const char *serviceUUID,
251                                       void *data, uint32_t dataLength, uint32_t *sentLength);
252
253 /**
254  * @brief This function sends data to all bluetooth devices running OIC service.
255  * @param serviceUUID     [IN] Service UUID of the device
256  * @param data            [IN] Data to be sent
257  * @param dataLength      [IN] Length of the data to be sent
258  * @param sentLength      [IN] Length of the actual sent data
259  * @return #CA_STATUS_OK or Appropriate error code
260  */
261 CAResult_t CAEDRClientSendMulticastData(const char *serviceUUID, void *data,
262                                         uint32_t dataLength, uint32_t *sentLength);
263
264 #ifdef __cplusplus
265 } /* extern "C" */
266 #endif
267
268 #endif //__CA_EDR_INTERFACE_H_
269