1 /* ****************************************************************
3 * Copyright 2016 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
21 #ifndef CA_UTILS_INTERFACE_H_
22 #define CA_UTILS_INTERFACE_H_
34 * this level depends on transmission time.
35 * unicast based UDP will be checked by caretransmission.
45 /** address for all **/
46 char addr[MAX_ADDR_STR_SIZE_CA];
48 /** adapter priority of all transmissions. **/
49 CATransportAdapter_t adapter;
51 /** level about speed of response. **/
56 * CAUtilConfig_t structure.
60 CATransportBTFlags_t bleFlags;
61 CMConfigureInfo_t cmInfo;
64 #define MAX_IP_LENGTH 46
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;
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;
86 u_int8_t tcpi_ca_state;
87 u_int8_t tcpi_retransmits;
89 u_int8_t tcpi_backoff;
90 u_int8_t tcpi_options;
91 u_int8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
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;
100 u_int32_t tcpi_snd_mss;
101 u_int32_t tcpi_rcv_mss;
103 u_int32_t tcpi_unacked;
104 u_int32_t tcpi_sacked;
106 u_int32_t tcpi_retrans;
107 u_int32_t tcpi_fackets;
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;
117 u_int32_t tcpi_rcv_ssthresh;
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;
130 * Callback function type for connection status changes delivery.
131 * @param[out] info Remote endpoint information.
132 * @param[out] isConnected Current connection status info.
134 typedef void (*CAConnectionStateChangedCB)(const CAEndpoint_t *info, bool isConnected);
137 * Callback function type for adapter status changes delivery.
138 * @param[out] adapter Transport type information.
139 * @param[out] enabled Current adapter status info.
141 typedef void (*CAAdapterStateChangedCB)(CATransportAdapter_t adapter, bool enabled);
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.
149 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
151 CAResult_t CARegisterNetworkMonitorHandler(CAAdapterStateChangedCB adapterStateCB,
152 CAConnectionStateChangedCB connStateCB);
155 * Unregister network monitoring callback.
156 * @param[in] adapterStateCB Adapter state monitoring callback.
157 * @param[in] connStateCB Connection state monitoring callback.
159 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
161 CAResult_t CAUnregisterNetworkMonitorHandler(CAAdapterStateChangedCB adapterStateCB,
162 CAConnectionStateChangedCB connStateCB);
165 * Set device to handle for auto connection.
166 * @param[in] address LE address to set.
168 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED.
170 CAResult_t CASetAutoConnectionDeviceInfo(const char* address);
173 * Unset device to handle for auto connection.
174 * @param[in] address LE address to unset.
176 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED.
178 CAResult_t CAUnsetAutoConnectionDeviceInfo(const char* address);
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.
186 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED.
188 CAResult_t CASetPortNumberToAssign(CATransportAdapter_t adapter,
189 CATransportFlags_t flag, uint16_t port);
192 * Get the assigned port number currently.
193 * @param[in] adapter Transport adapter information.
194 * @param[in] flag Transport flag information.
196 * @return assigned port number information.
198 uint16_t CAGetAssignedPortNumber(CATransportAdapter_t adapter, CATransportFlags_t flag);
200 //custom advertisement data setting
201 #if defined(__TIZEN__) && defined(LE_ADAPTER) && defined(BLE_CUSTOM_ADVERTISE)
204 * Sets Custom Advertisement Data.
205 * @param[in] data Advertisment Data buffer.
206 * @param[in] length Length of buffer.
208 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_INVALID_PARAM
210 CAResult_t CASetAdvertisementData(const char* data, int length);
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.
218 void CASetAdvertisementDataGetter(CAAdvertisementDataGetterCB getter);
221 * set if advertising should be started automatically.
222 * By default advertising is automatically started.
223 * @param[in] autoAdvertisement true for automatic start
225 void CASetAutoAdvertisement(bool autoAdvertisement);
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
233 CAResult_t CASetScanResponseData(const char* data, int length);
237 #if defined(__TIZEN__)
239 * This function sets uri being used for proxy.
241 * @param uri NULL terminated resource uri for SAP Proxy.
244 * @return ::CA_STATUS_OK or ::CA_STATUS_INVALID_PARAM
246 CAResult_t CASetCloudAddressForProxy(const char *uri);
248 * This function gets proxy uri.
250 * @return resource uri or NULL
252 const char *CAGetCloudAddressForProxy();
257 * initialize client connection manager
259 CAResult_t CAUtilClientInitialize();
262 * terminate client connection manager
264 CAResult_t CAUtilClientTerminate();
268 * @return ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
270 CAResult_t CAUtilStopLEScan();
274 * @return ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
276 CAResult_t CAUtilStartLEScan();
280 * @return ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
282 CAResult_t CAUtilClientDisconnect();
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.
292 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
294 CAResult_t CAUtilClientInitialize(JNIEnv *env, JavaVM *jvm, jobject context);
297 * terminate util client for android
298 * @param[in] env JNI interface pointer.
300 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
302 CAResult_t CAUtilClientTerminate(JNIEnv *env);
306 * start discovery for BT device which has iotivity UUID.
307 * @param[in] env JNI interface pointer.
309 CAResult_t CAUtilStartScan(JNIEnv *env);
313 * @param[in] env JNI interface pointer.
315 CAResult_t CAUtilStopScan(JNIEnv *env);
318 * bonding between devices.
319 * @param[in] env JNI interface pointer.
320 * @param[in] device bluetooth device object.
322 CAResult_t CAUtilCreateBond(JNIEnv *env, jobject device);
326 * set callback listener of found device.
327 * @param[in] listener callback listener
329 void CAUtilSetFoundDeviceListener(jobject listener);
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.
336 * @return ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
338 CAResult_t CAUtilSetLEScanInterval(jint intervalTime, jint workingCount);
343 * @return ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
345 CAResult_t CAUtilStopLEScan();
350 * start BLE advertising.
351 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
353 CAResult_t CAUtilStartLEAdvertising();
356 * stop BLE advertising.
357 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
359 CAResult_t CAUtilStopLEAdvertising();
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).
366 CAResult_t CAUtilSetBTConfigure(CAUtilConfig_t config);
369 * set CAUtil log preference.
370 * @param[in] level ::CAUtilLogLevel_t value
371 * @param[in] hidePrivateLogEntries Private Log Entries.
373 * true : hide private log.
374 * false : show private log.
375 * (privacy : uid, did, access token, etc)
377 void CAUtilSetLogLevel(CAUtilLogLevel_t level, bool hidePrivateLogEntries);
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.
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.
391 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
393 CAResult_t CAUtilSetMulticastTTL(size_t ttl);
396 * Get multicast time to live value.
397 * @param[out] ttl TTL pointer to get the stored multicast time to live.
399 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
401 CAResult_t CAUtilGetMulticastTTL(size_t *ttl);
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.
412 CAResult_t CAUtilTCPDisconnectSession(const char *address,
414 CATransportFlags_t flags);
417 * Enable or disable skip closing TCP servers
418 * when network interface is down.
420 * @param[in] state true to skip closing TCP servers,
423 void CAUtilSkipTCPCloseOnInterfaceDown(bool state);
425 CAResult_t CAUtilStartGattServer();
426 CAResult_t CAUtilStopGattServer();
427 CAResult_t CAGetTCPIPHeader(CATransportAdapter_t adapter, int flag, TCPHeaderInfo* info);
433 #endif /* CA_UTILS_INTERFACE_H_ */