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