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 #if defined(__TIZEN__)
66 #define MAX_IP_LENGTH 46
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;
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;
88 u_int8_t tcpi_ca_state;
89 u_int8_t tcpi_retransmits;
91 u_int8_t tcpi_backoff;
92 u_int8_t tcpi_options;
93 u_int8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
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;
102 u_int32_t tcpi_snd_mss;
103 u_int32_t tcpi_rcv_mss;
105 u_int32_t tcpi_unacked;
106 u_int32_t tcpi_sacked;
108 u_int32_t tcpi_retrans;
109 u_int32_t tcpi_fackets;
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;
119 u_int32_t tcpi_rcv_ssthresh;
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;
134 * Callback function type for connection status changes delivery.
135 * @param[out] info Remote endpoint information.
136 * @param[out] isConnected Current connection status info.
138 typedef void (*CAConnectionStateChangedCB)(const CAEndpoint_t *info, bool isConnected);
141 * Callback function type for adapter status changes delivery.
142 * @param[out] adapter Transport type information.
143 * @param[out] enabled Current adapter status info.
145 typedef void (*CAAdapterStateChangedCB)(CATransportAdapter_t adapter, bool enabled);
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.
153 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
155 CAResult_t CARegisterNetworkMonitorHandler(CAAdapterStateChangedCB adapterStateCB,
156 CAConnectionStateChangedCB connStateCB);
159 * Unregister network monitoring callback.
160 * @param[in] adapterStateCB Adapter state monitoring callback.
161 * @param[in] connStateCB Connection state monitoring callback.
163 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
165 CAResult_t CAUnregisterNetworkMonitorHandler(CAAdapterStateChangedCB adapterStateCB,
166 CAConnectionStateChangedCB connStateCB);
169 * Set device to handle for auto connection.
170 * @param[in] address LE address to set.
172 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED.
174 CAResult_t CASetAutoConnectionDeviceInfo(const char* address);
177 * Unset device to handle for auto connection.
178 * @param[in] address LE address to unset.
180 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED.
182 CAResult_t CAUnsetAutoConnectionDeviceInfo(const char* address);
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.
190 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED.
192 CAResult_t CASetPortNumberToAssign(CATransportAdapter_t adapter,
193 CATransportFlags_t flag, uint16_t port);
196 * Get the assigned port number currently.
197 * @param[in] adapter Transport adapter information.
198 * @param[in] flag Transport flag information.
200 * @return assigned port number information.
202 uint16_t CAGetAssignedPortNumber(CATransportAdapter_t adapter, CATransportFlags_t flag);
204 //custom advertisement data setting
205 #if defined(__TIZEN__) && defined(LE_ADAPTER) && defined(BLE_CUSTOM_ADVERTISE)
208 * Sets Custom Advertisement Data.
209 * @param[in] data Advertisment Data buffer.
210 * @param[in] length Length of buffer.
212 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_STATUS_INVALID_PARAM
214 CAResult_t CASetAdvertisementData(const char* data, int length);
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.
222 void CASetAdvertisementDataGetter(CAAdvertisementDataGetterCB getter);
225 * set if advertising should be started automatically.
226 * By default advertising is automatically started.
227 * @param[in] autoAdvertisement true for automatic start
229 void CASetAutoAdvertisement(bool autoAdvertisement);
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
237 CAResult_t CASetScanResponseData(const char* data, int length);
241 #if defined(__TIZEN__)
243 * This function sets uri being used for proxy.
245 * @param uri NULL terminated resource uri for SAP Proxy.
248 * @return ::CA_STATUS_OK or ::CA_STATUS_INVALID_PARAM
250 CAResult_t CASetCloudAddressForProxy(const char *uri);
252 * This function gets proxy uri.
254 * @return resource uri or NULL
256 const char *CAGetCloudAddressForProxy();
261 * initialize client connection manager
263 CAResult_t CAUtilClientInitialize();
266 * terminate client connection manager
268 CAResult_t CAUtilClientTerminate();
272 * @return ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
274 CAResult_t CAUtilStopLEScan();
278 * @return ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
280 CAResult_t CAUtilStartLEScan();
284 * @return ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
286 CAResult_t CAUtilClientDisconnect();
289 #if defined(__ANDROID__)
291 * set UUID for setting scanfilter, which will add another scanfilter for BLE scanning in android client based on the UUID or manufacture data provided
292 * @param[in] uuid service UUID string or manufacture Data
293 * @param[in] uuid_type Type of scanfilter to be added i.e. service UUID based or manufacture data based
295 void CASetLEScanUuid(char* uuid, int uuid_type);
300 * initialize util client for android
301 * @param[in] env JNI interface pointer.
302 * @param[in] jvm invocation inferface for JAVA virtual machine.
303 * @param[in] context application context.
305 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
307 CAResult_t CAUtilClientInitialize(JNIEnv *env, JavaVM *jvm, jobject context);
310 * terminate util client for android.
311 * @param[in] env JNI interface pointer.
313 * @return ::CA_STATUS_OK or ::CA_STATUS_FAILED or ::CA_MEMORY_ALLOC_FAILED
315 CAResult_t CAUtilClientTerminate(JNIEnv *env);
319 * start discovery for BT device which has iotivity UUID.
320 * @param[in] env JNI interface pointer.
322 CAResult_t CAUtilStartScan(JNIEnv *env);
326 * @param[in] env JNI interface pointer.
328 CAResult_t CAUtilStopScan(JNIEnv *env);
331 * bonding between devices.
332 * @param[in] env JNI interface pointer.
333 * @param[in] device bluetooth device object.
335 CAResult_t CAUtilCreateBond(JNIEnv *env, jobject device);
339 * set callback listener of found device.
340 * @param[in] listener callback listener
342 void CAUtilSetFoundDeviceListener(jobject listener);
345 * set interval time and working count for LE scan.
346 * @param[in] intervalTime interval time(Seconds).
347 * @param[in] workingCount working cycle for selected interval time.
349 * @return ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
351 CAResult_t CAUtilSetLEScanInterval(jint intervalTime, jint workingCount);
356 * @return ::CA_STATUS_OK or ::CA_NOT_SUPPORTED
358 CAResult_t CAUtilStopLEScan();
363 * start BLE advertising.
364 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
366 CAResult_t CAUtilStartLEAdvertising();
369 * stop BLE advertising.
370 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
372 CAResult_t CAUtilStopLEAdvertising();
375 * set CAUtil BT configure.
376 * @param[in] config ::CAUtilConfig_t value
377 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
379 CAResult_t CAUtilSetBTConfigure(CAUtilConfig_t config);
382 * set CAUtil log preference.
383 * @param[in] level ::CAUtilLogLevel_t value
384 * @param[in] hidePrivateLogEntries Private Log Entries.
386 * true : hide private log.
387 * false : show private log.
388 * (privacy : uid, did, access token, etc)
390 void CAUtilSetLogLevel(CAUtilLogLevel_t level, bool hidePrivateLogEntries);
393 * Set multicast time to live value to control the scope of the multicasts.
394 * @param[in] ttl To be set to any value from 0 to 255.
396 * 0: Are restricted to the same host.
397 * 1: Are restricted to the same subnet.
398 * 32: Are restricted to the same site.
399 * 64: Are restricted to the same region.
400 * 128: Are restricted to the same continent.
401 * 255: Are unrestricted in scope.
402 * We cannot support region, continent and unrestricted in scope.
404 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
406 CAResult_t CAUtilSetMulticastTTL(size_t ttl);
409 * Get multicast time to live value.
410 * @param[out] ttl TTL pointer to get the stored multicast time to live.
412 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
414 CAResult_t CAUtilGetMulticastTTL(size_t *ttl);
417 * Disconnect TCP session.
418 * When there is no transmission for a long time.
419 * Some carrier Vendor is blocking data.
420 * Thur, TCP Session is cleaned through this function.
421 * @param[in] address Address.
422 * @param[in] port Port.
423 * @param[in] flags Transport flag.
425 CAResult_t CAUtilTCPDisconnectSession(const char *address,
427 CATransportFlags_t flags);
430 * Enable or disable skip closing TCP servers
431 * when network interface is down.
433 * @param[in] state true to skip closing TCP servers,
436 void CAUtilSkipTCPCloseOnInterfaceDown(bool state);
440 * Set a secure endpoint identity with uuid.
442 * @param[in] peer peer information includs IP address and port.
443 * @param[in] uuid UUID of target device.
445 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
447 CAResult_t CASetSecureEndpointUuid(const CAEndpoint_t *peer, const char *uuid);
449 CAResult_t CAUtilStartGattServer();
450 CAResult_t CAUtilStopGattServer();
452 #if defined(__TIZEN__)
453 CAResult_t CAGetTCPIPHeader(CATransportAdapter_t adapter, int flag, TCPHeaderInfo* info);
456 * Enables keep-alive on the given endpoint & configures it with user defined values.
458 * @param[in] endpoint Endpoint on keep-alive needs to be enabled.
459 * @param[in] time The number of seconds a connection needs to be idle
460 * before TCP begins sending out keep-alive probes.
461 * @param[in] cnt The maximum number of TCP keep-alive probes to send before
462 * giving up and killing the connection if no response is obtained from the other end
463 * @param[in] intvl The number of seconds between TCP keep-alive probes.
465 * @return ::CA_STATUS_OK or Appropriate error code.
467 CAResult_t CASetTCPKeepAlive(const CAEndpoint_t *endpoint, int time, int cnt, int intvl);
470 * Disables keep-alive on the given endpoint.
472 * @param[in] endpoint Endpoint on which keep-alive needs to be disabled.
474 * @return ::CA_STATUS_OK or Appropriate error code.
476 CAResult_t CAUnSetTCPKeepAlive(const CAEndpoint_t *endpoint);
479 * Get the last error code (errno) to identify the reason
480 * when disconnection happens during keep-alive.
482 * @return - Direct 'errno' value from kernel
484 int CAGetTCPLastErrorCode();
487 * Set the interface to be used for outgoing TCP packets.
488 * Tcp client sockets (before establishing connection) will be bound to the IP address of the given WiFi interface.
489 * Internally, Iotivity reads the IP address assigned to the given interace
490 * and binds it with the TCP client socket before connect().
492 * @param[in] ifname WiFi interface name.
494 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
496 CAResult_t CASetTCPServerSocketBindIP(const char* ifname);
503 #endif /* CA_UTILS_INTERFACE_H_ */