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