Merge "Enabling build of simpleclientblescan application" into tizen
[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 #if defined(__TIZEN__)
65
66 #define MAX_IP_LENGTH 46
67
68 typedef struct
69 {
70     /* These 4 values are Kernel dependent and can be extracted only when Kernel is
71     built with enabling to monitor these values*/
72     u_int32_t tcpi_snd_nxt;
73     u_int32_t tcpi_rcv_nxt;
74     u_int32_t tcpi_rcv_wnd;
75     u_int8_t tcpi_rcv_wscale;
76     /*....*/
77     u_int8_t tcpi_src_addr[MAX_IP_LENGTH];
78     u_int32_t tcpi_src_port;
79     u_int8_t tcpi_dst_addr[MAX_IP_LENGTH];
80     u_int32_t tcpi_dst_port;
81     u_int32_t ip_version;
82     void* info;
83 } TCPHeaderInfo;
84
85 typedef struct
86 {
87     u_int8_t tcpi_state;
88     u_int8_t tcpi_ca_state;
89     u_int8_t tcpi_retransmits;
90     u_int8_t tcpi_probes;
91     u_int8_t tcpi_backoff;
92     u_int8_t tcpi_options;
93     u_int8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
94
95     /* TCP Keep Alive Offload */
96     u_int32_t tcpi_snd_nxt;
97     u_int32_t tcpi_rcv_nxt;
98     u_int32_t tcpi_rcv_wnd;
99
100     u_int32_t tcpi_rto;
101     u_int32_t tcpi_ato;
102     u_int32_t tcpi_snd_mss;
103     u_int32_t tcpi_rcv_mss;
104
105     u_int32_t tcpi_unacked;
106     u_int32_t tcpi_sacked;
107     u_int32_t tcpi_lost;
108     u_int32_t tcpi_retrans;
109     u_int32_t tcpi_fackets;
110
111     /* Times. */
112     u_int32_t tcpi_last_data_sent;
113     u_int32_t tcpi_last_ack_sent;
114     u_int32_t tcpi_last_data_recv;
115     u_int32_t tcpi_last_ack_recv;
116
117     /* Metrics. */
118     u_int32_t tcpi_pmtu;
119     u_int32_t tcpi_rcv_ssthresh;
120     u_int32_t tcpi_rtt;
121     u_int32_t tcpi_rttvar;
122     u_int32_t tcpi_snd_ssthresh;
123     u_int32_t tcpi_snd_cwnd;
124     u_int32_t tcpi_advmss;
125     u_int32_t tcpi_reordering;
126     u_int32_t tcpi_rcv_rtt;
127     u_int32_t tcpi_rcv_space;
128     u_int32_t tcpi_total_retrans;
129 } TCPInfo;
130
131 #endif
132
133 /**
134  * Callback function type for connection status changes delivery.
135  * @param[out]   info           Remote endpoint information.
136  * @param[out]   isConnected    Current connection status info.
137  */
138 typedef void (*CAConnectionStateChangedCB)(const CAEndpoint_t *info, bool isConnected);
139
140 /**
141  * Callback function type for adapter status changes delivery.
142  * @param[out]   adapter    Transport type information.
143  * @param[out]   enabled    Current adapter status info.
144  */
145 typedef void (*CAAdapterStateChangedCB)(CATransportAdapter_t adapter, bool enabled);
146
147 /**
148  * Register network monitoring callback.
149  * Network status changes are delivered these callback.
150  * @param[in]   adapterStateCB  Adapter state monitoring callback.
151  * @param[in]   connStateCB     Connection state monitoring callback.
152  *
153  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
154  */
155 CAResult_t CARegisterNetworkMonitorHandler(CAAdapterStateChangedCB adapterStateCB,
156                                            CAConnectionStateChangedCB connStateCB);
157
158 /**
159  * Unregister network monitoring callback.
160  * @param[in]   adapterStateCB  Adapter state monitoring callback.
161  * @param[in]   connStateCB     Connection state monitoring callback.
162  *
163  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
164  */
165 CAResult_t CAUnregisterNetworkMonitorHandler(CAAdapterStateChangedCB adapterStateCB,
166                                              CAConnectionStateChangedCB connStateCB);
167
168 /**
169  * Set device to handle for auto connection.
170  * @param[in]   address         LE address to set.
171  *
172  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED.
173  */
174 CAResult_t CASetAutoConnectionDeviceInfo(const char* address);
175
176 /**
177  * Unset device to handle for auto connection.
178  * @param[in]   address         LE address to unset.
179  *
180  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED.
181  */
182 CAResult_t CAUnsetAutoConnectionDeviceInfo(const char* address);
183
184 /**
185  * Set the port number to assign .
186  * @param[in]   adapter     Transport adapter information.
187  * @param[in]   flag        Transport flag information.
188  * @param[in]   port        The port number to use.
189  *
190  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED.
191  */
192 CAResult_t CASetPortNumberToAssign(CATransportAdapter_t adapter,
193                                    CATransportFlags_t flag, uint16_t port);
194
195 /**
196  * Get the assigned port number currently.
197  * @param[in]   adapter     Transport adapter information.
198  * @param[in]   flag        Transport flag information.
199  *
200  * @return  assigned port number information.
201  */
202 uint16_t CAGetAssignedPortNumber(CATransportAdapter_t adapter, CATransportFlags_t flag);
203
204 //custom advertisement data setting
205 #if defined(__TIZEN__) && defined(LE_ADAPTER) && defined(BLE_CUSTOM_ADVERTISE)
206
207 /**
208  * Sets Custom Advertisement Data.
209  * @param[in]   data    Advertisment Data buffer.
210  * @param[in]   length  Length of buffer.
211  *
212  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_INVALID_PARAM
213  */
214 CAResult_t CASetAdvertisementData(const char* data, int length);
215
216 /**
217  * Set function that will be called before starting advertising.
218  * Provided data and length will be used to set advertisement data.
219  * @param[in]  getter     Custom advertisement data getter callback.
220  *
221  */
222 void CASetAdvertisementDataGetter(CAAdvertisementDataGetterCB getter);
223
224 /**
225  * set if advertising should be started automatically.
226  * By default advertising is automatically started.
227  * @param[in]  autoAdvertisement         true for automatic start
228  */
229 void CASetAutoAdvertisement(bool autoAdvertisement);
230
231 /**
232  * Scan and set data for custom bluetooth advertisement.
233  * @param[in]   data                   Array with custom bluetooth advertisement data.
234  * @param[in]   length                 Length of data array.
235  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_INVALID_PARAM
236  */
237 CAResult_t CASetScanResponseData(const char* data, int length);
238
239 #endif
240
241 #if defined(__TIZEN__)
242 /**
243  * This function sets uri being used for proxy.
244  *
245  * @param uri            NULL terminated resource uri for SAP Proxy.
246  *
247  *
248  * @return  ::CA_STATUS_OK or ::CA_STATUS_INVALID_PARAM
249  */
250 CAResult_t CASetCloudAddressForProxy(const char *uri);
251 /**
252  * This function gets proxy uri.
253  *
254  * @return  resource uri or NULL
255  */
256 const char *CAGetCloudAddressForProxy();
257 #endif
258
259 #ifdef __APPLE__
260 /**
261  * initialize client connection manager
262  */
263 CAResult_t CAUtilClientInitialize();
264
265 /**
266  * terminate client connection manager
267  */
268 CAResult_t CAUtilClientTerminate();
269
270 /**
271  * stop LE scan.
272  * @return  ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
273  */
274 CAResult_t CAUtilStopLEScan();
275
276 /**
277  * start LE scan.
278  * @return  ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
279  */
280 CAResult_t CAUtilStartLEScan();
281
282 /**
283  * Client disconnect.
284  * @return  ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
285  */
286 CAResult_t CAUtilClientDisconnect();
287 #endif
288
289 #ifdef __ANDROID__
290 /**
291  * initialize util client for android
292  * @param[in]   env                   JNI interface pointer.
293  * @param[in]   jvm                   invocation inferface for JAVA virtual machine.
294  * @param[in]   context               application context.
295  *
296  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
297  */
298 CAResult_t CAUtilClientInitialize(JNIEnv *env, JavaVM *jvm, jobject context);
299
300 /**
301  * terminate util client for android
302  * @param[in]   env                   JNI interface pointer.
303  *
304  * @return  ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
305  */
306 CAResult_t CAUtilClientTerminate(JNIEnv *env);
307
308 // BT pairing
309 /**
310  * start discovery for BT device which has iotivity UUID.
311  * @param[in]  env              JNI interface pointer.
312  */
313 CAResult_t CAUtilStartScan(JNIEnv *env);
314
315 /**
316  * stop discovery
317  * @param[in]  env              JNI interface pointer.
318  */
319 CAResult_t CAUtilStopScan(JNIEnv *env);
320
321 /**
322  * bonding between devices.
323  * @param[in]  env              JNI interface pointer.
324  * @param[in]  device           bluetooth device object.
325  */
326 CAResult_t CAUtilCreateBond(JNIEnv *env, jobject device);
327
328
329 /**
330  * set callback listener of found device.
331  * @param[in]  listener         callback listener
332  */
333 void CAUtilSetFoundDeviceListener(jobject listener);
334
335 /**
336  * set interval time and working count for LE scan.
337  * @param[in]  intervalTime         interval time(Seconds).
338  * @param[in]  workingCount         working cycle for selected interval time.
339  *
340  * @return  ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
341  */
342 CAResult_t CAUtilSetLEScanInterval(jint intervalTime, jint workingCount);
343
344 /**
345  * stop LE scan.
346  *
347  * @return  ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
348  */
349 CAResult_t CAUtilStopLEScan();
350 #endif
351
352 // BLE util
353 /**
354  * start BLE advertising.
355  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
356  */
357 CAResult_t CAUtilStartLEAdvertising();
358
359 /**
360  * stop BLE advertising.
361  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
362  */
363 CAResult_t CAUtilStopLEAdvertising();
364
365 /**
366  * set CAUtil BT configure.
367  * @param[in]  config       ::CAUtilConfig_t value
368  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
369  */
370 CAResult_t CAUtilSetBTConfigure(CAUtilConfig_t config);
371
372 /**
373  * set CAUtil log preference.
374  * @param[in]  level                     ::CAUtilLogLevel_t value
375  * @param[in]  hidePrivateLogEntries     Private Log Entries.
376  *                                       Example:
377  *                                       true : hide private log.
378  *                                       false : show private log.
379  *                                       (privacy : uid, did, access token, etc)
380  */
381 void CAUtilSetLogLevel(CAUtilLogLevel_t level, bool hidePrivateLogEntries);
382
383 /**
384  * Set multicast time to live value to control the scope of the multicasts.
385  * @param[in]  ttl         To be set to any value from 0 to 255.
386  *                         Example:
387  *                         0: Are restricted to the same host.
388  *                         1: Are restricted to the same subnet.
389  *                         32: Are restricted to the same site.
390  *                         64: Are restricted to the same region.
391  *                         128: Are restricted to the same continent.
392  *                         255: Are unrestricted in scope.
393  *                         We cannot support region, continent and unrestricted in scope.
394  *
395  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
396  */
397 CAResult_t CAUtilSetMulticastTTL(size_t ttl);
398
399 /**
400  * Get multicast time to live value.
401  * @param[out]  ttl        TTL pointer to get the stored multicast time to live.
402  *
403  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
404  */
405 CAResult_t CAUtilGetMulticastTTL(size_t *ttl);
406
407 /**
408  * Disconnect TCP session.
409  * When there is no transmission for a long time.
410  * Some carrier Vendor is blocking data.
411  * Thur, TCP Session is cleaned through this function.
412  * @param[in]   address        Address.
413  * @param[in]   port           Port.
414  * @param[in]   flags          Transport flag.
415  */
416 CAResult_t CAUtilTCPDisconnectSession(const char *address,
417                                       uint16_t port,
418                                       CATransportFlags_t flags);
419
420 /**
421  * Enable or disable skip closing TCP servers
422  * when network interface is down.
423  *
424  * @param[in]   state    true to skip closing TCP servers,
425  *                       otherwise false.
426  */
427 void CAUtilSkipTCPCloseOnInterfaceDown(bool state);
428
429 CAResult_t CAUtilStartGattServer();
430 CAResult_t CAUtilStopGattServer();
431
432 #if defined(__TIZEN__)
433 CAResult_t CAGetTCPIPHeader(CATransportAdapter_t adapter, int flag, TCPHeaderInfo* info);
434 #endif
435
436 #ifdef __cplusplus
437 } /* extern "C" */
438 #endif
439
440 #endif /* CA_UTILS_INTERFACE_H_ */
441