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