replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / cainterfacecontroller.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 contains common utility function for CA transport adaptors.
25  */
26
27 #ifndef CA_INTERFACE_CONTROLLER_H_
28 #define CA_INTERFACE_CONTROLLER_H_
29
30 #include "caadapterinterface.h"
31 #include "cainterface.h"
32 #include "cautilinterface.h"
33
34 #ifndef SINGLE_THREAD
35 #include "cathreadpool.h" /* for thread pool */
36 #endif
37
38 #ifdef __cplusplus
39 extern "C"
40 {
41 #endif
42
43 #ifdef SINGLE_THREAD
44 /**
45  * Initializes different adapters based on the compilation flags.
46  */
47 void CAInitializeAdapters();
48 #else
49 /**
50  * Initializes different adapters based on the compilation flags.
51  * @param[in]   handle           thread pool handle created by message handler
52  *                               for different adapters.
53  * @param[in]   transportType    transport type to initialize.
54  */
55 void CAInitializeAdapters(ca_thread_pool_t handle, CATransportAdapter_t transportType);
56 #endif
57
58 /**
59  * Set the received packets callback for message handler.
60  * @param[in]   callback         message handler callback to receive packets
61  *                               from different adapters.
62  */
63 void CASetPacketReceivedCallback(CANetworkPacketReceivedCallback callback);
64
65 /**
66  * Set the error handler callback for message handler.
67  * @param[in]   errorCallback    error handler callback from adapters
68  */
69 void CASetErrorHandleCallback(CAErrorHandleCallback errorCallback);
70
71 /**
72  * Set the network status changed callback for CAUtil.
73  * @param[in]   adapterCB       CAUtil callback to receive adapter status changes.
74  * @param[in]   connCB          CAUtil callback to receive connection status changes.
75  */
76 void CASetNetworkMonitorCallbacks(CAAdapterStateChangedCB adapterCB,
77                                   CAConnectionStateChangedCB connCB);
78
79 /**
80  * Unset the network status changed callback for CAUtil.
81  * @param[in]   adapterCB       CAUtil callback to receive adapter status changes.
82  * @param[in]   connCB          CAUtil callback to receive connection status changes.
83  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
84  */
85 CAResult_t CAUnsetNetworkMonitorCallbacks(CAAdapterStateChangedCB adapterCB,
86                                           CAConnectionStateChangedCB connCB);
87
88 /**
89  * Starting different connectivity adapters based on the network selection.
90  * @param[in]   transportType    interested network for starting.
91  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
92  */
93 CAResult_t CAStartAdapter(CATransportAdapter_t transportType);
94
95 /**
96  * Stopping different connectivity adapters based on the network un-selection.
97  * @param[in]   transportType    network type that want to stop.
98  */
99 void CAStopAdapter(CATransportAdapter_t transportType);
100
101 #ifdef RA_ADAPTER
102 /**
103  * Set Remote Access information for XMPP Client.
104  * @param[in]   caraInfo         remote access info..
105  *
106  * @return  CA_STATUS_OK
107  */
108 CAResult_t CASetAdapterRAInfo(const CARAInfo_t *caraInfo);
109 #endif
110
111 /**
112  * Get network information such as ipaddress and mac information.
113  * @param[out]   info           connectivity information
114  *                                  such as ipaddress and mac information.
115  * @param[out]   size           number of connectivity information structures.
116  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
117  */
118 CAResult_t CAGetNetworkInfo(CAEndpoint_t **info, uint32_t *size);
119
120 /**
121  * Sends unicast data to the remote endpoint.
122  * @param[in]   endpoint       endpoint information where the data has to be sent.
123  * @param[in]   data           data that needs to be sent.
124  * @param[in]   length         length of the data that needs to be sent.
125  * @param[in]   dataType       Data type which is REQUEST or RESPONSE.
126  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
127  */
128 CAResult_t CASendUnicastData(const CAEndpoint_t *endpoint, const void *data,
129                              uint32_t length, CADataType_t dataType);
130
131 /**
132  * Sends multicast data to all endpoints in the network.
133  * @param[in]   endpoint       endpoint information where the data has to be sent.
134  * @param[in]   data           data that needs to be sent.
135  * @param[in]   length         length of the data that needs to be sent.
136  * @param[in]   dataType       Data type which is REQUEST or RESPONSE.
137  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
138  */
139
140 CAResult_t CASendMulticastData(const CAEndpoint_t *endpoint, const void *data,
141                                uint32_t length, CADataType_t dataType);
142
143 /**
144  * Start listening servers to receive search requests from clients.
145  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
146  */
147 CAResult_t CAStartListeningServerAdapters();
148
149 /**
150  * Stop listening servers to receive search requests from clients.
151  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
152  */
153 CAResult_t CAStopListeningServerAdapters();
154
155 /**
156  * Start discovery servers to receive advertisements from server.
157  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
158  */
159 CAResult_t CAStartDiscoveryServerAdapters();
160
161 /**
162  * Terminates the adapters which are initialized during the initialization.
163  */
164 void CATerminateAdapters();
165
166 #ifdef SINGLE_THREAD
167 /**
168  * Checks for available data and reads it.
169  * @return   ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
170  */
171 CAResult_t CAReadData();
172 #endif
173
174 #ifdef IP_ADAPTER
175 /**
176  * Set multicast time to live value to control the scope of the multicasts.
177  * @param[in]  ttl         To be set to any value from 0 to 255.
178  *
179  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
180  */
181 CAResult_t CASetMulticastTTL(size_t ttl);
182
183 /**
184  * Get multicast time to live value.
185  * @param[out]  ttl        TTL pointer to get the stored multicast time to live.
186  *
187  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
188  */
189 CAResult_t CAGetMulticastTTL(size_t *ttl);
190 #endif
191
192 #ifdef TCP_ADAPTER
193 /**
194  * Disconnect TCP session.
195  * When there is no transmission for a long time.
196  * Some carrier vendor is blocking data.
197  * Thur, TCP Session is cleaned through this function.
198  * @param[in]   endpoint       endpoint information to disconnect.
199  */
200 CAResult_t CADisconnectSession(const CAEndpoint_t *endpoint);
201 #endif
202
203 #ifdef LE_ADAPTER
204 void CAStartGattServer();
205
206 void CAStopGattServer();
207 #endif
208
209 #ifdef __cplusplus
210 } /* extern "C" */
211 #endif
212
213 #endif /* CA_INTERFACE_CONTROLLER_H_ */
214