Added APIs get the tcp dump and network state 79/157279/11
authortaesub kim <taesub.kim@samsung.com>
Tue, 24 Oct 2017 05:00:07 +0000 (14:00 +0900)
committertaesub kim <taesub.kim@samsung.com>
Tue, 5 Dec 2017 05:05:33 +0000 (14:05 +0900)
Change-Id: I1b12e22d94a9cd6e0874697c24b1c5f534773009
Signed-off-by: Taesub Kim <taesub.kim@samsung.com>
include/connection_extension.h [new file with mode: 0755]
include/net_connection_private.h
packaging/capi-network-connection.spec
src/connection.c
src/libnetwork.c
test/connection_test.c

diff --git a/include/connection_extension.h b/include/connection_extension.h
new file mode 100755 (executable)
index 0000000..961b11d
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2011-2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TIZEN_NETWORK_CONNECTION_EXTENSION_H__
+#define __TIZEN_NETWORK_CONNECTION_EXTENSION_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file connection_extension.h
+ */
+
+/**
+ * @brief Start TCP Dump.
+ *
+ * @param[in] connection        The connection handle
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #CONNECTION_ERROR_NONE                    Successful
+ * @retval #CONNECTION_ERROR_OPERATION_FAILED        Operation failed
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER       Invalid parameter
+*/
+int connection_profile_start_tcpdump(connection_h connection);
+
+/**
+ * @brief Stop TCP Dump.
+ *
+ * @param[in] connection        The connection handle
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #CONNECTION_ERROR_NONE                    Successful
+ * @retval #CONNECTION_ERROR_OPERATION_FAILED        Operation failed
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER       Invalid parameter
+*/
+int connection_profile_stop_tcpdump(connection_h connection);
+
+/**
+ * @brief Get TCP Dump Running Status.
+ *
+ * @param[in] connection        The connection handle
+ * @param[out] tcpdump_state    The state of tcpdump, tcpdump is in progress or not
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ * @retval #CONNECTION_ERROR_NONE                    Successful
+ * @retval #CONNECTION_ERROR_OPERATION_FAILED        Operation failed
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER       Invalid parameter
+*/
+int connection_profile_get_tcpdump_state(connection_h connection, gboolean *tcpdump_state);
+
+/**
+* @}
+*/
+
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+
+#endif /* __TIZEN_NETWORK_CONNECTION_EXTENSION_H__ */
index 797893f..7fdf8c7 100755 (executable)
@@ -168,6 +168,11 @@ net_state_type_t _connection_profile_convert_to_net_state(connection_profile_sta
 
 int _connection_libnet_set_cellular_subscriber_id(connection_profile_h profile, connection_cellular_subscriber_id_e sim_id);
 
+int _connection_libnet_start_tcpdump(void);
+int _connection_libnet_stop_tcpdump(void);
+int _connection_libnet_get_tcpdump_state(gboolean *tcpdump_state);
+
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index a3e91e1..b5f9f6e 100755 (executable)
@@ -1,6 +1,6 @@
 Name:          capi-network-connection
 Summary:       Network Connection library in TIZEN C API
-Version:       1.0.105
+Version:       1.0.106
 Release:       1
 Group:         System/Network
 License:       Apache-2.0
index 9c09e55..0bf2f23 100755 (executable)
@@ -1555,3 +1555,56 @@ EXPORT_API int connection_foreach_ipv6_address(connection_h connection,
        return CONNECTION_ERROR_NONE;
 }
 
+EXPORT_API int connection_profile_start_tcpdump(connection_h connection)
+{
+       int ret = 0;
+
+       if (!(__connection_check_handle_validity(connection))) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = _connection_libnet_start_tcpdump();
+       if (ret != CONNECTION_ERROR_NONE) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Failed to start tcpdump (%d)", ret);
+               return ret;
+       }
+
+       return CONNECTION_ERROR_NONE;
+}
+
+EXPORT_API int connection_profile_stop_tcpdump(connection_h connection)
+{
+       int ret = 0;
+
+       if (!(__connection_check_handle_validity(connection))) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = _connection_libnet_stop_tcpdump();
+       if (ret != CONNECTION_ERROR_NONE) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Failed to stop tcpdump (%d)", ret);
+               return ret;
+       }
+
+       return CONNECTION_ERROR_NONE;
+}
+
+EXPORT_API int connection_profile_get_tcpdump_state(connection_h connection, gboolean *tcpdump_state)
+{
+       int ret = 0;
+
+       if (!(__connection_check_handle_validity(connection)) || !tcpdump_state) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       ret = _connection_libnet_get_tcpdump_state(tcpdump_state);
+       if (ret != CONNECTION_ERROR_NONE) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Failed to get the tcpdump state (%d)", ret);
+               return ret;
+       }
+
+       return CONNECTION_ERROR_NONE;
+}
index 9e5b09a..fb5eaf2 100755 (executable)
@@ -1654,3 +1654,36 @@ int _connection_check_feature_supported(const char *feature_name, ...)
        set_last_result(CONNECTION_ERROR_NONE);
        return CONNECTION_ERROR_NONE;
 }
+
+int _connection_libnet_start_tcpdump(void)
+{
+       connection_error_e result = CONNECTION_ERROR_NONE;
+       net_err_t ret = NET_ERR_NONE;
+
+       ret = net_start_tcpdump();
+       result = __libnet_convert_to_cp_error_type(ret);
+
+       return result;
+}
+
+int _connection_libnet_stop_tcpdump(void)
+{
+       connection_error_e result = CONNECTION_ERROR_NONE;
+       net_err_t ret = NET_ERR_NONE;
+
+       ret = net_stop_tcpdump();
+       result = __libnet_convert_to_cp_error_type(ret);
+
+       return result;
+}
+
+int _connection_libnet_get_tcpdump_state(gboolean *tcpdump_state)
+{
+       connection_error_e result = CONNECTION_ERROR_NONE;
+       net_err_t ret = NET_ERR_NONE;
+
+       ret = net_get_tcpdump_state(tcpdump_state);
+       result = __libnet_convert_to_cp_error_type(ret);
+
+       return result;
+}
index 815a918..b931a52 100755 (executable)
@@ -22,6 +22,7 @@
 #include <glib.h>
 
 #include "net_connection.h"
+#include "connection_extension.h"
 
 #include <tizen_error.h>
 
@@ -2125,6 +2126,41 @@ int test_is_metered_network(void)
        return 1;
 }
 
+int test_start_tcpdump(void)
+{
+       if (connection_profile_start_tcpdump(connection) != CONNECTION_ERROR_NONE) {
+               return -1;
+       }
+
+       printf("Successfully started tcpdump\n");
+
+       return 1;
+}
+
+int test_stop_tcpdump(void)
+{
+       if (connection_profile_stop_tcpdump(connection) != CONNECTION_ERROR_NONE) {
+               return -1;
+       }
+
+       printf("Successfully stopped tcpdump\n");
+
+       return 1;
+}
+
+int test_get_tcpdump_state(void)
+{
+       gboolean tcpdump_state = FALSE;
+
+       if (connection_profile_get_tcpdump_state(connection, &tcpdump_state) != CONNECTION_ERROR_NONE) {
+               return -1;
+       }
+
+       printf("tcpdump %s running\n", tcpdump_state ? "is" : "is not");
+
+       return 1;
+}
+
 int main(int argc, char **argv)
 {
        GMainLoop *mainloop;
@@ -2158,8 +2194,10 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
        }
 
        if (*a == '\n' || *a == '\r') {
+/* Public API */
                printf("\n\n Network Connection API Test App\n\n");
                printf("Options..\n");
+               printf(LOG_BLUE "[Public APIs]\n" LOG_END);
                printf(LOG_GREEN "1   - Create Handle and set callbacks\n" LOG_END);
                printf("2   - Destroy Handle(unset callbacks automatically)\n");
                printf(LOG_GREEN "3   - Get network state\n" LOG_END);
@@ -2199,11 +2237,17 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
                printf("E   - Remove route entry\n");
                printf("F   - Get all IPv6 address\n");
                printf("G   - Get metered state\n");
+/* Extension API */
+               printf(LOG_BLUE "[Extension API]\n" LOG_END);
+               printf("H   - Start TCP Dump\n");
+               printf("I   - Stop TCP Dump\n");
+               printf("J   - Get TCP Dump State\n");
                printf(LOG_RED "0   - Exit \n" LOG_END);
                printf("ENTER   - Show options menu.......\n");
        }
 
        switch (a[0]) {
+/* Public API */
        case '1':
                rv = test_register_client();
                break;
@@ -2321,6 +2365,17 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data)
        case 'G':
                rv = test_is_metered_network();
                break;
+/* Extension API */
+       case 'H':
+               rv = test_start_tcpdump();
+               break;
+       case 'I':
+               rv = test_stop_tcpdump();
+               break;
+       case 'J':
+               rv = test_get_tcpdump_state();
+               break;
+
        }
 
        if (rv == 1)