Implementation for Tizen EDR transport.
[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     CARemoteEndpoint_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     CALocalConnectivity_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  Initialize the network monitor module
107  * @param  threadPool   [IN] Threadpool Handle
108  * @return #CA_STATUS_OK or Appropriate error code
109  * @retval #CA_STATUS_OK  Successful
110  * @retval #CA_ADAPTER_NOT_ENABLED Initialization is successful, but bluetooth adapter is
111  *                                 not enabled.
112  * @retval #CA_STATUS_FAILED Operation failed
113  * @see  CAEDRTerminateNetworkMonitor()
114  */
115 CAResult_t CAEDRInitializeNetworkMonitor(const ca_thread_pool_t threadPool);
116
117 /**
118  * @brief  Deinitialize with bluetooth adapter.
119  * @return NONE
120  * @pre    CAEDRInitializeNetworkMonitor() should be invoked before using this API.
121  * @see    CAEDRInitializeNetworkMonitor()
122  */
123 void CAEDRTerminateNetworkMonitor();
124
125 /**
126  * @brief  Start Network Monitoring Process
127  * @return #CA_STATUS_OK or Appropriate error code
128  */
129 CAResult_t CAEDRStartNetworkMonitor();
130
131 /**
132  * @brief  Stop Network Monitoring Process
133  * @return #CA_STATUS_OK or Appropriate error code
134  */
135 CAResult_t CAEDRStopNetworkMonitor();
136
137 /**
138  * @brief  Sets the callback and Starts discovery for nearby OIC bluetooth devices.
139  *
140  * @return #CA_STATUS_OK or Appropriate error code
141  * @retval #CA_STATUS_OK  Successful
142  * @retval #CA_STATUS_FAILED Operation failed
143  */
144 CAResult_t CAEDRClientSetCallbacks();
145
146 /**
147  * @brief  Resetting callbacks with bluetooth framework and stop OIC device discovery.
148  * @return NONE
149  * @pre    CAEDRClientSetCallbacks() should be invoked before using this API.
150  * @see    CAEDRClientSetCallbacks()
151  */
152 void CAEDRClientUnsetCallbacks();
153
154 /**
155  * @brief  Used to initialize the EDR client module where mutex is initialized
156  * @return NONE
157  */
158 void CAEDRInitializeClient(ca_thread_pool_t handle);
159
160 /**
161  * @brief  Destroys the Device list and mutex.
162  * @return NONE
163  */
164 void CAEDRClientTerminate();
165
166 /**
167  * @brief  Closes all the client connection to peer bluetooth devices.
168  * @return NONE
169  */
170 void CAEDRClientDisconnectAll();
171
172 /**
173  * @brief  Register callback to send the received packets from remote bluetooth device to BTAdapter.
174  *
175  * @param  packetReceivedCallback [IN] Callback function to register for sending network
176  *                                     packets to EDR Adapter.
177  * @return NONE
178  */
179 void CAEDRSetPacketReceivedCallback(CAEDRDataReceivedCallback packetReceivedCallback);
180
181 /**
182  * @brief  Register callback for receiving local bluetooth adapter state.
183  *
184  * @param  networkStateChangeCallback [IN] Callback function to register for receiving local
185  *                                         bluetooth adapter status.
186  * @return NONE
187  */
188 void CAEDRSetNetworkChangeCallback(CAEDRNetworkStatusCallback networkStateChangeCallback);
189
190 /**
191  * @brief  Get the local bluetooth adapter information.
192  *
193  * @param  info [OUT] 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  * @param  handle       [IN] Threadpool Handle
211  *
212  * @return #CA_STATUS_OK or Appropriate error code
213  * @retval #CA_STATUS_OK  Successful
214  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
215  * @retval #CA_STATUS_FAILED Operation failed
216  *
217  */
218 CAResult_t CAEDRServerStart(const char *serviceUUID, int *serverFD, ca_thread_pool_t handle);
219
220 /**
221  * @brief  Stop RFCOMM server
222  *
223  * @param  serverFD [IN] The RFCOMM server socket file descriptor which needs to be stopped.
224  *
225  * @return #CA_STATUS_OK or Appropriate error code
226  * @retval #CA_STATUS_OK  Successful
227  * @retval #CA_STATUS_FAILED Operation failed
228  */
229 CAResult_t CAEDRServerStop(int serverFD);
230
231 /**
232  * @brief   Terminate server for EDR
233  * @return  None
234  */
235 void CAEDRServerTerminate();
236
237 /**
238  * @brief  All received data will be notified to upper layer.
239  *
240  * @return #CA_STATUS_OK or Appropriate error code
241  * @retval #CA_STATUS_OK  Successful
242  * @retval #CA_STATUS_FAILED Operation failed
243  *
244  */
245 CAResult_t CAEDRManagerReadData();
246
247 /**
248  * @brief  This function gets bluetooth adapter enable state.
249  * @param  state    [OUT] State of the Adapter.
250  * @return #CA_STATUS_OK or Appropriate error code
251  */
252 CAResult_t CAEDRGetAdapterEnableState(bool *state);
253
254 /**
255  * @brief  This function sends data to specified remote bluetooth device.
256  * @param  remoteAddress   [IN] Remote EDR Address
257  * @param  serviceUUID     [IN] Service UUID of the device
258  * @param  data            [IN] Data to be sent
259  * @param  dataLength      [IN] Length of the data to be sent
260  * @param  sentLength      [OUT] Length of the actual sent data
261  * @return #CA_STATUS_OK or Appropriate error code
262  */
263 CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress, const char *serviceUUID,
264                                       const void *data, uint32_t dataLength, uint32_t *sentLength);
265
266 /**
267  * @brief  This function sends data to all bluetooth devices running OIC service.
268  * @param  serviceUUID     [IN] Service UUID of the device
269  * @param  data            [IN] Data to be sent
270  * @param  dataLength      [IN] Length of the data to be sent
271  * @param  sentLength      [OUT] Length of the actual sent data
272  * @return #CA_STATUS_OK or Appropriate error code
273  */
274 CAResult_t CAEDRClientSendMulticastData(const char *serviceUUID, const void *data,
275                                         uint32_t dataLength, uint32_t *sentLength);
276
277 /**
278  * @brief This function gets bonded bluetooth device list
279  * @return #CA_STATUS_OK or Appropriate error code
280  */
281 CAResult_t CAEDRGetBondedDeviceList();
282
283 #ifdef __cplusplus
284 } /* extern "C" */
285 #endif
286
287 #endif //__CA_EDR_INTERFACE_H_
288