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