28fc94e468bc79239daec39e4de79b78d6c944bc
[platform/upstream/iotivity.git] / resource / csdk / connectivity / api / cautilinterface.h
1 /* ****************************************************************
2  *
3  * Copyright 2016 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 #ifndef CA_UTILS_INTERFACE_H_
22 #define CA_UTILS_INTERFACE_H_
23
24 #include "cacommon.h"
25 #ifdef __ANDROID__
26 #include "jni.h"
27 #endif
28 #ifdef __cplusplus
29 extern "C"
30 {
31 #endif
32
33 /**
34  * this level depends on transmission time.
35  * unicast based UDP will be checked by caretransmission.
36  */
37 typedef enum
38 {
39     HIGH_SPEED = 0,
40     NORMAL_SPEED
41 } CMSpeedLevel_t;
42
43 typedef struct
44 {
45     /** address for all **/
46     char addr[MAX_ADDR_STR_SIZE_CA];
47
48     /** adapter priority of all transmissions. **/
49     CATransportAdapter_t adapter;
50
51     /** level about speed of response. **/
52     CMSpeedLevel_t level;
53 } CMConfigureInfo_t;
54
55 /*
56  * CAUtilConfig_t structure.
57  */
58 typedef struct
59 {
60     CATransportBTFlags_t bleFlags;
61     CMConfigureInfo_t cmInfo;
62 } CAUtilConfig_t;
63
64 /**
65  * Callback function type for connection status changes delivery.
66  * @param[out]   info           Remote endpoint information.
67  * @param[out]   isConnected    Current connection status info.
68  */
69 typedef void (*CAConnectionStateChangedCB)(const CAEndpoint_t *info, bool isConnected);
70
71 /**
72  * Callback function type for adapter status changes delivery.
73  * @param[out]   adapter    Transport type information.
74  * @param[out]   enabled    Current adapter status info.
75  */
76 typedef void (*CAAdapterStateChangedCB)(CATransportAdapter_t adapter, bool enabled);
77
78 /**
79  * Register network monitoring callback.
80  * Network status changes are delivered these callback.
81  * @param[in]   adapterStateCB  Adapter state monitoring callback.
82  * @param[in]   connStateCB     Connection state monitoring callback.
83  *
84  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
85  */
86 CAResult_t CARegisterNetworkMonitorHandler(CAAdapterStateChangedCB adapterStateCB,
87                                            CAConnectionStateChangedCB connStateCB);
88
89 /**
90  * Unregister network monitoring callback.
91  * @param[in]   adapterStateCB  Adapter state monitoring callback.
92  * @param[in]   connStateCB     Connection state monitoring callback.
93  *
94  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
95  */
96 CAResult_t CAUnregisterNetworkMonitorHandler(CAAdapterStateChangedCB adapterStateCB,
97                                              CAConnectionStateChangedCB connStateCB);
98
99 /**
100  * Set device to handle for auto connection.
101  * @param[in]   address         LE address to set.
102  *
103  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED.
104  */
105 CAResult_t CASetAutoConnectionDeviceInfo(const char* address);
106
107 /**
108  * Unset device to handle for auto connection.
109  * @param[in]   address         LE address to unset.
110  *
111  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED.
112  */
113 CAResult_t CAUnsetAutoConnectionDeviceInfo(const char* address);
114
115 /**
116  * Set the port number to assign .
117  * @param[in]   adapter     Transport adapter information.
118  * @param[in]   flag        Transport flag information.
119  * @param[in]   port        The port number to use.
120  *
121  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED.
122  */
123 CAResult_t CASetPortNumberToAssign(CATransportAdapter_t adapter,
124                                    CATransportFlags_t flag, uint16_t port);
125
126 /**
127  * Get the assigned port number currently.
128  * @param[in]   adapter     Transport adapter information.
129  * @param[in]   flag        Transport flag information.
130  *
131  * @return  assigned port number information.
132  */
133 uint16_t CAGetAssignedPortNumber(CATransportAdapter_t adapter, CATransportFlags_t flag);
134
135 //custom advertisement data setting
136 #if defined(__TIZEN__) && defined(LE_ADAPTER) && defined(BLE_CUSTOM_ADVERTISE)
137
138 /**
139  * Sets Custom Advertisement Data.
140  * @param[in]   data    Advertisment Data buffer.
141  * @param[in]   length  Length of buffer.
142  *
143  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_INVALID_PARAM 
144  */
145 CAResult_t CASetAdvertisementData(const char* data, int length);
146
147 /**
148  * Set function that will be called before starting advertising.
149  * Provided data and length will be used to set advertisement data.
150  * @param[in]  getter     Custom advertisement data getter callback. 
151  *
152  */
153 void CASetAdvertisementDataGetter(CAAdvertisementDataGetterCB getter);
154
155 /**
156  * set if advertising should be started automatically.
157  * By default advertising is automatically started.
158  * @param[in]  autoAdvertisement         true for automatic start
159  */
160 void CASetAutoAdvertisement(bool autoAdvertisement);
161
162 /**
163  * Scan and set data for custom bluetooth advertisement.
164  * @param[in]   data                   Array with custom bluetooth advertisement data.
165  * @param[in]   length                 Length of data array.
166  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_INVALID_PARAM 
167  */
168 CAResult_t CASetScanResponseData(const char* data, int length);
169
170 #endif
171
172 #if defined(__TIZEN__)
173 /**
174  * This function sets uri being used for proxy.
175  *
176  * @param uri            NULL terminated resource uri for SAP Proxy.
177  *
178  *
179  * @return  ::CA_STATUS_OK or ::CA_STATUS_INVALID_PARAM
180  */
181 CAResult_t CASetCloudAddressForProxy(const char *uri);
182 /**
183  * This function gets proxy uri.
184  *
185  * @return  resource uri or NULL
186  */
187 const char *CAGetCloudAddressForProxy();
188 #endif
189
190 #ifdef __APPLE__
191 /**
192  * initialize client connection manager
193  */
194 CAResult_t CAUtilClientInitialize();
195
196 /**
197  * terminate client connection manager
198  */
199 CAResult_t CAUtilClientTerminate();
200
201 /**
202  * stop LE scan.
203  * @return  ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
204  */
205 CAResult_t CAUtilStopLEScan();
206
207 /**
208  * start LE scan.
209  * @return  ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
210  */
211 CAResult_t CAUtilStartLEScan();
212
213 /**
214  * Client disconnect.
215  * @return  ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
216  */
217 CAResult_t CAUtilClientDisconnect();
218 #endif
219
220 #ifdef __ANDROID__
221 /**
222  * initialize util client for android
223  * @param[in]   env                   JNI interface pointer.
224  * @param[in]   jvm                   invocation inferface for JAVA virtual machine.
225  * @param[in]   context               application context.
226  *
227  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
228  */
229 CAResult_t CAUtilClientInitialize(JNIEnv *env, JavaVM *jvm, jobject context);
230
231 /**
232  * terminate util client for android
233  * @param[in]   env                   JNI interface pointer.
234  *
235  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
236  */
237 CAResult_t CAUtilClientTerminate(JNIEnv *env);
238
239 // BT pairing
240 /**
241  * start discovery for BT device which has iotivity UUID.
242  * @param[in]  env              JNI interface pointer.
243  */
244 CAResult_t CAUtilStartScan(JNIEnv *env);
245
246 /**
247  * stop discovery
248  * @param[in]  env              JNI interface pointer.
249  */
250 CAResult_t CAUtilStopScan(JNIEnv *env);
251
252 /**
253  * bonding between devices.
254  * @param[in]  env              JNI interface pointer.
255  * @param[in]  device           bluetooth device object.
256  */
257 CAResult_t CAUtilCreateBond(JNIEnv *env, jobject device);
258
259
260 /**
261  * set callback listener of found device.
262  * @param[in]  listener         callback listener
263  */
264 void CAUtilSetFoundDeviceListener(jobject listener);
265
266 /**
267  * set interval time and working count for LE scan.
268  * @param[in]  intervalTime         interval time(Seconds).
269  * @param[in]  workingCount         working cycle for selected interval time.
270  *
271  * @return  ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
272  */
273 CAResult_t CAUtilSetLEScanInterval(jint intervalTime, jint workingCount);
274
275 /**
276  * stop LE scan.
277  *
278  * @return  ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
279  */
280 CAResult_t CAUtilStopLEScan();
281 #endif
282
283 // BLE util
284 /**
285  * start BLE advertising.
286  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
287  */
288 CAResult_t CAUtilStartLEAdvertising();
289
290 /**
291  * stop BLE advertising.
292  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
293  */
294 CAResult_t CAUtilStopLEAdvertising();
295
296 /**
297  * set CAUtil BT configure.
298  * @param[in]  config       ::CAUtilConfig_t value
299  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
300  */
301 CAResult_t CAUtilSetBTConfigure(CAUtilConfig_t config);
302
303 /**
304  * set CAUtil log preference.
305  * @param[in]  level                     ::CAUtilLogLevel_t value
306  * @param[in]  hidePrivateLogEntries     Private Log Entries.
307  *                                       Example:
308  *                                       true : hide private log.
309  *                                       false : show private log.
310  *                                       (privacy : uid, did, access token, etc)
311  */
312 void CAUtilSetLogLevel(CAUtilLogLevel_t level, bool hidePrivateLogEntries);
313
314 /**
315  * Set multicast time to live value to control the scope of the multicasts.
316  * @param[in]  ttl         To be set to any value from 0 to 255.
317  *                         Example:
318  *                         0: Are restricted to the same host.
319  *                         1: Are restricted to the same subnet.
320  *                         32: Are restricted to the same site.
321  *                         64: Are restricted to the same region.
322  *                         128: Are restricted to the same continent.
323  *                         255: Are unrestricted in scope.
324  *                         We cannot support region, continent and unrestricted in scope.
325  *
326  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
327  */
328 CAResult_t CAUtilSetMulticastTTL(size_t ttl);
329
330 /**
331  * Get multicast time to live value.
332  * @param[out]  ttl        TTL pointer to get the stored multicast time to live.
333  *
334  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
335  */
336 CAResult_t CAUtilGetMulticastTTL(size_t *ttl);
337
338 /**
339  * Disconnect TCP session.
340  * When there is no transmission for a long time.
341  * Some carrier Vendor is blocking data.
342  * Thur, TCP Session is cleaned through this function.
343  * @param[in]   address        Address.
344  * @param[in]   port           Port.
345  * @param[in]   flags          Transport flag.
346  */
347 CAResult_t CAUtilTCPDisconnectSession(const char *address,
348                                       uint16_t port,
349                                       CATransportFlags_t flags);
350
351 /**
352  * Enable or disable skip closing TCP servers
353  * when network interface is down.
354  *
355  * @param[in]   state    true to skip closing TCP servers,
356  *                       otherwise false.
357  */
358 void CAUtilSkipTCPCloseOnInterfaceDown(bool state);
359
360 CAResult_t CAUtilStartGattServer();
361 CAResult_t CAUtilStopGattServer();
362
363 #ifdef __cplusplus
364 } /* extern "C" */
365 #endif
366
367 #endif /* CA_UTILS_INTERFACE_H_ */
368