From: hyunuktak Date: Thu, 6 Dec 2018 05:18:11 +0000 (+0900) Subject: Add some APIs to find all devices X-Git-Tag: submit/tizen/20181211.125217~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6f8310a41a48e6b2041da4576539c96eb2affab2;p=platform%2Fcore%2Fapi%2Fsmart-traffic-control.git Add some APIs to find all devices Change-Id: Id95bb65fd56cd4a5b5aaef11a2e0d1b22b3799e7 Signed-off-by: hyunuktak --- diff --git a/include/stc_pcap_internal.h b/include/stc_pcap_internal.h index 8851aed..4dcd625 100755 --- a/include/stc_pcap_internal.h +++ b/include/stc_pcap_internal.h @@ -185,6 +185,30 @@ int stc_pcap_stop(stc_h stc, stc_pcap_h pcap_h); */ int stc_pcap_foreach(stc_h stc, stc_pcap_info_cb callback, void *user_data); +/** + * @brief Finds all devices. + * @since_tizen 5.0 + * + * @param[in] stc The stc handle + * @param[in] callback The callback to be called + * @param[in] user_data The user data passed to the callback function + * + * @return 0 on success, otherwise a negative error value + * @retval #STC_ERROR_NONE Successful + * @retval #STC_ERROR_OPERATION_FAILED General error + * @retval #STC_ERROR_OUT_OF_MEMORY Out of memory + * @retval #STC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STC_ERROR_INVALID_OPERATION Invalid operation + * @retval #STC_ERROR_NOT_INITIALIZED Not initialized + * @retval #STC_ERROR_NOT_SUPPORTED Not supported + * @retval #STC_ERROR_PERMISSION_DENIED Permission denied + * + * @see #stc_pcap_h + * @see stc_pcap_create() + * @see stc_pcap_destroy() + */ +int stc_pcap_find_all_devs(stc_h stc, stc_pcap_info_cb callback, void *user_data); + /** * @brief Sets interface name to pcap. * @since_tizen 5.0 @@ -281,6 +305,98 @@ int stc_pcap_get_ifname(stc_pcap_h pcap_h, char **ifname); */ int stc_pcap_get_nflog_group(stc_pcap_h pcap_h, int *group); +/** + * @brief Gets name of device. + * @since_tizen 5.0 + * + * @param[in] pcap_h The pcap handle + * @param[out] name The name of device + * + * @return 0 on success, otherwise a negative error value + * @retval #STC_ERROR_NONE Successful + * @retval #STC_ERROR_OPERATION_FAILED General error + * @retval #STC_ERROR_OUT_OF_MEMORY Out of memory + * @retval #STC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STC_ERROR_INVALID_OPERATION Invalid operation + * @retval #STC_ERROR_NOT_INITIALIZED Not initialized + * @retval #STC_ERROR_NOT_SUPPORTED Not supported + * @retval #STC_ERROR_PERMISSION_DENIED Permission denied + * + * @see #stc_pcap_h + * @see stc_pcap_create() + * @see stc_pcap_destroy() + */ +int stc_pcap_get_dev_name(stc_pcap_h pcap_h, char **name); + +/** + * @brief Gets description of device. + * @since_tizen 5.0 + * + * @param[in] pcap_h The pcap handle + * @param[out] decs The description of device + * + * @return 0 on success, otherwise a negative error value + * @retval #STC_ERROR_NONE Successful + * @retval #STC_ERROR_OPERATION_FAILED General error + * @retval #STC_ERROR_OUT_OF_MEMORY Out of memory + * @retval #STC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STC_ERROR_INVALID_OPERATION Invalid operation + * @retval #STC_ERROR_NOT_INITIALIZED Not initialized + * @retval #STC_ERROR_NOT_SUPPORTED Not supported + * @retval #STC_ERROR_PERMISSION_DENIED Permission denied + * + * @see #stc_pcap_h + * @see stc_pcap_create() + * @see stc_pcap_destroy() + */ +int stc_pcap_get_dev_decs(stc_pcap_h pcap_h, char **decs); + +/** + * @brief Gets net of device. + * @since_tizen 5.0 + * + * @param[in] pcap_h The pcap handle + * @param[out] net The net of device + * + * @return 0 on success, otherwise a negative error value + * @retval #STC_ERROR_NONE Successful + * @retval #STC_ERROR_OPERATION_FAILED General error + * @retval #STC_ERROR_OUT_OF_MEMORY Out of memory + * @retval #STC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STC_ERROR_INVALID_OPERATION Invalid operation + * @retval #STC_ERROR_NOT_INITIALIZED Not initialized + * @retval #STC_ERROR_NOT_SUPPORTED Not supported + * @retval #STC_ERROR_PERMISSION_DENIED Permission denied + * + * @see #stc_pcap_h + * @see stc_pcap_create() + * @see stc_pcap_destroy() + */ +int stc_pcap_get_dev_net(stc_pcap_h pcap_h, char **net); + +/** + * @brief Gets mask of device. + * @since_tizen 5.0 + * + * @param[in] pcap_h The pcap handle + * @param[out] mask The mask of device + * + * @return 0 on success, otherwise a negative error value + * @retval #STC_ERROR_NONE Successful + * @retval #STC_ERROR_OPERATION_FAILED General error + * @retval #STC_ERROR_OUT_OF_MEMORY Out of memory + * @retval #STC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STC_ERROR_INVALID_OPERATION Invalid operation + * @retval #STC_ERROR_NOT_INITIALIZED Not initialized + * @retval #STC_ERROR_NOT_SUPPORTED Not supported + * @retval #STC_ERROR_PERMISSION_DENIED Permission denied + * + * @see #stc_pcap_h + * @see stc_pcap_create() + * @see stc_pcap_destroy() + */ +int stc_pcap_get_dev_mask(stc_pcap_h pcap_h, char **mask); + /** * @} */ diff --git a/src/include/stc-pcap.h b/src/include/stc-pcap.h index f61b136..d3b0e93 100755 --- a/src/include/stc-pcap.h +++ b/src/include/stc-pcap.h @@ -54,13 +54,24 @@ extern "C" { #define STC_MANAGER_PCAP_METHOD_START "Start" #define STC_MANAGER_PCAP_METHOD_STOP "Stop" #define STC_MANAGER_PCAP_METHOD_GETALL "GetAll" +#define STC_MANAGER_PCAP_METHOD_FINDALLDEVS "FindAllDevs" #define STC_PCAP_IFNAME "ifname" #define STC_PCAP_NFLOG_GROUP "nflog_group" +#define STC_PCAP_DEV_NAME "dev" +#define STC_PCAP_DEV_DECS "decs" +#define STC_PCAP_DEV_NET "net" +#define STC_PCAP_DEV_MASK "mask" + typedef struct { char *ifname; int nflog_group; + + char *dev_name; + char *dev_decs; + char *dev_net; + char *dev_mask; } stc_pcap_s; /***************************************************************************** diff --git a/src/internal/include/stc-event.h b/src/internal/include/stc-event.h index 73fc193..15c6eed 100755 --- a/src/internal/include/stc-event.h +++ b/src/internal/include/stc-event.h @@ -59,6 +59,7 @@ typedef enum { STC_EVENT_RESTRICTION_GET_ALL_RSP, STC_EVENT_WARN_THRESHOLD_CROSSED_RSP, STC_EVENT_RESTRICTION_THRESHOLD_CROSSED_RSP, + STC_EVENT_PCAP_FIND_ALL_DEVS_RSP, STC_EVENT_LAST_ELEM, } stc_event_e; @@ -69,6 +70,7 @@ typedef enum { STC_REQUEST_TABLE_STATS_GET_TOTAL, STC_REQUEST_TABLE_RESTRICTION_GET, STC_REQUEST_TABLE_RESTRICTION_GET_ALL, + STC_REQUEST_TABLE_PCAP_FIND_ALL_DEVS, STC_REQUEST_TABLE_LAST_ELEM, } stc_request_table_e; diff --git a/src/internal/include/stc-private.h b/src/internal/include/stc-private.h index 0f6bd68..7ac0a39 100755 --- a/src/internal/include/stc-private.h +++ b/src/internal/include/stc-private.h @@ -74,6 +74,9 @@ typedef struct { void *restriction_crossed_user_data; stc_threshold_crossed_cb warn_crossed_cb; void *warn_crossed_user_data; + + stc_pcap_info_cb pcap_info_cb; + void *pcap_info_user_data; } stc_handle_s; /** diff --git a/src/internal/stc-private.c b/src/internal/stc-private.c index 2306c51..ef809d5 100755 --- a/src/internal/stc-private.c +++ b/src/internal/stc-private.c @@ -505,6 +505,29 @@ static void __stc_callback_foreach(stc_event_e e, handle->restriction_all_user_data = NULL; } break; + case STC_EVENT_PCAP_FIND_ALL_DEVS_RSP: + if (handle->pcap_info_cb) { + if (err == STC_ERROR_NONE) { + if (info_data != NULL) { + for (data = info_data; data; data = data->next) { + stc_pcap_h pcap = data->data; + ret = handle->pcap_info_cb(pcap, + handle->pcap_info_user_data); + + if (ret == STC_CALLBACK_CANCEL) + break; + } + } else { + handle->pcap_info_cb(NULL, NULL); //LCOV_EXCL_LINE + } + } else { + handle->pcap_info_cb(NULL, NULL); //LCOV_EXCL_LINE + } + + handle->pcap_info_cb = NULL; + handle->pcap_info_user_data = NULL; + } + break; //LCOV_EXCL_STOP default: break; @@ -547,6 +570,7 @@ static void __stc_event_cb(stc_event_info_s *event_info, void *user_data) case STC_EVENT_STATS_GET_TOTAL_RSP: case STC_EVENT_RESTRICTION_GET_RSP: case STC_EVENT_RESTRICTION_GET_ALL_RSP: + case STC_EVENT_PCAP_FIND_ALL_DEVS_RSP: { stc_error_e error = event_info->error; GSList *info_data = (GSList *)event_info->info_data; diff --git a/src/stc-pcap.c b/src/stc-pcap.c index 31f5875..17fd5d5 100755 --- a/src/stc-pcap.c +++ b/src/stc-pcap.c @@ -40,6 +40,7 @@ *****************************************************************************/ #include "stc.h" +#include "stc-event.h" #include "stc-private.h" #include "stc-dbus.h" @@ -75,9 +76,40 @@ static void __stc_pcap_deinit(void *data) stc_pcap_s *pcap = (stc_pcap_s *)data; FREE(pcap->ifname); + + FREE(pcap->dev_name); + FREE(pcap->dev_decs); + FREE(pcap->dev_net); + FREE(pcap->dev_mask); + FREE(pcap); } +static void __stc_pcap_print(stc_pcap_s *pcap) +{ + if (pcap == NULL) + return; + + STC_LOGD(STC_HR_SINGLE); + + STC_LOGD("[%s][%d]", pcap->ifname, pcap->nflog_group); + + STC_LOGD(STC_HR_SINGLE); +} + +static void __stc_pcap_dev_print(stc_pcap_s *pcap) +{ + if (pcap == NULL) + return; + + STC_LOGD(STC_HR_SINGLE); + + STC_LOGD("[%s][%s][%s][%s]", pcap->dev_name, + pcap->dev_decs, pcap->dev_net, pcap->dev_mask); + + STC_LOGD(STC_HR_SINGLE); +} + static void __stc_pcap_add_to_list(stc_pcap_h pcap_h) { g_pcap_list = g_slist_append(g_pcap_list, pcap_h); @@ -132,16 +164,113 @@ static void __stc_pcap_make_params( g_variant_builder_unref(builder); } -static void __stc_pcap_print(stc_pcap_s *pcap) +static void __stc_pcap_extract(const char *key, + GVariant *value, void *user_data) { + stc_pcap_s *pcap = (stc_pcap_s *)user_data; + if (pcap == NULL) return; - STC_LOGD(STC_HR_SINGLE); + if (!g_strcmp0(key, STC_PCAP_IFNAME)) { + guint str_length; + const gchar *str = g_variant_get_string(value, &str_length); + pcap->ifname = g_strdup(str); - STC_LOGD("[%s][%d]", pcap->ifname, pcap->nflog_group); + } else if (!g_strcmp0(key, STC_PCAP_NFLOG_GROUP)) { + pcap->nflog_group = g_variant_get_uint32(value); - STC_LOGD(STC_HR_SINGLE); + } +} + +static void __stc_pcap_dev_extract(const char *key, + GVariant *value, void *user_data) +{ + stc_pcap_s *pcap = (stc_pcap_s *)user_data; + + if (pcap == NULL) + return; + + if (!g_strcmp0(key, STC_PCAP_DEV_NAME)) { + guint str_length; + const gchar *str = g_variant_get_string(value, &str_length); + pcap->dev_name = g_strdup(str); + + } else if (!g_strcmp0(key, STC_PCAP_DEV_DECS)) { + guint str_length; + const gchar *str = g_variant_get_string(value, &str_length); + pcap->dev_decs = g_strdup(str); + + } else if (!g_strcmp0(key, STC_PCAP_DEV_NET)) { + guint str_length; + const gchar *str = g_variant_get_string(value, &str_length); + pcap->dev_net = g_strdup(str); + + } else if (!g_strcmp0(key, STC_PCAP_DEV_MASK)) { + guint str_length; + const gchar *str = g_variant_get_string(value, &str_length); + pcap->dev_mask = g_strdup(str); + + } +} + +static void __stc_pcap_find_all_devs_reply( + GObject *source_object, GAsyncResult *res, gpointer user_data) +{ + GDBusConnection *conn = NULL; + GError *dbus_error = NULL; + GVariant *dbus_data = NULL; + GVariantIter *iter = NULL; + GVariantIter *iter_row = NULL; + stc_error_e error = STC_ERROR_NONE; + GSList *dev_list = NULL; + stc_event_info_s event_data = { 0, }; + + conn = G_DBUS_CONNECTION(source_object); + dbus_data = g_dbus_connection_call_finish(conn, res, &dbus_error); + if (dbus_error != NULL) { + error = _stc_convert_error_string_to_enum(dbus_error->message); //LCOV_EXCL_LINE + g_error_free(dbus_error); //LCOV_EXCL_LINE + } + + if (_stc_event_get_request_table_state(STC_REQUEST_TABLE_PCAP_FIND_ALL_DEVS)) + _stc_event_set_request_table_state(STC_REQUEST_TABLE_PCAP_FIND_ALL_DEVS, false); + + if (error == STC_ERROR_NONE) { + g_variant_get(dbus_data, "(aa{sv})", &iter); + + while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { + stc_pcap_s *pcap = MALLOC0(stc_pcap_s, 1); + if (pcap != NULL) { + _stc_dbus_dictionary_foreach(iter_row, + __stc_pcap_dev_extract, pcap); + + __stc_pcap_dev_print(pcap); + + dev_list = g_slist_append(dev_list, (stc_pcap_s *)pcap); + + g_variant_iter_free(iter_row); + } + } + g_variant_iter_free(iter); + + event_data.event = STC_EVENT_PCAP_FIND_ALL_DEVS_RSP; + event_data.info_data = (GSList *)dev_list; + event_data.datalength = g_slist_length(dev_list); + event_data.error = STC_ERROR_NONE; + } else { + //LCOV_EXCL_START + STC_LOGE("Find all devs response error [%s]", + _stc_convert_error_type_to_string(error)); + + event_data.event = STC_EVENT_PCAP_FIND_ALL_DEVS_RSP; + event_data.info_data = NULL; + event_data.datalength = 0; + event_data.error = error; + //LCOV_EXCL_STOP + } + + _stc_event_add_client_idle_cb(&event_data, user_data); } stc_error_e _stc_pcap_start(stc_pcap_s *pcap) @@ -198,6 +327,109 @@ stc_error_e _stc_pcap_stop(stc_pcap_s *pcap) return STC_ERROR_NONE; } +stc_error_e _stc_pcap_foreach(stc_pcap_info_cb callback, + void *user_data) +{ + GVariant *message = NULL; + stc_error_e error = STC_ERROR_NONE; + GVariantIter *iter = NULL; + GVariantIter *iter_row = NULL; + GSList *pcap_list = NULL; + GSList *list = NULL; + stc_callback_ret_e rv = STC_CALLBACK_CANCEL; + + message = _stc_dbus_invoke_method( + STC_MANAGER_SERVICE, + STC_MANAGER_PCAP_PATH, + STC_MANAGER_PCAP_INTERFACE, + STC_MANAGER_PCAP_METHOD_GETALL, + NULL, + &error); + + STC_RETURN_VAL_IF(message == NULL, + error, "Failed to invoke dbus method"); + + g_variant_get(message, "(aa{sv})", &iter); + + while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { + stc_pcap_s *pcap = MALLOC0(stc_pcap_s, 1); + + _stc_dbus_dictionary_foreach(iter_row, + __stc_pcap_extract, pcap); + + __stc_pcap_print(pcap); + + pcap_list = g_slist_append(pcap_list, (stc_pcap_s *)pcap); + + g_variant_iter_free(iter_row); + } + + g_variant_iter_free(iter); + g_variant_unref(message); + + if ((int)g_slist_length(pcap_list) == 0) { + STC_LOGD("There are no pcap loop"); + return STC_ERROR_NONE; + } + + for (list = pcap_list; list; list = list->next) { + stc_pcap_s *pcap = (stc_pcap_s *)list->data; + __stc_pcap_add_to_list((stc_pcap_h)pcap); + rv = callback((stc_pcap_h)pcap, user_data); + __stc_pcap_remove_from_list((stc_pcap_h)pcap); + if (rv == false) + break; + } + + g_slist_free_full(pcap_list, __stc_pcap_deinit); + + return STC_ERROR_NONE; +} + +stc_error_e _stc_pcap_find_all_devs(stc_pcap_info_cb callback, + void *user_data) +{ + stc_error_e error = STC_ERROR_NONE; + + STC_RETURN_VAL_IF( + _stc_event_get_request_table_state( + STC_REQUEST_TABLE_PCAP_FIND_ALL_DEVS), + STC_ERROR_IN_PROGRESS, + "Request in progress"); + + _stc_event_set_request_table_state( + STC_REQUEST_TABLE_PCAP_FIND_ALL_DEVS, true); + + error = _stc_dbus_invoke_method_nonblock( + STC_MANAGER_SERVICE, + STC_MANAGER_PCAP_PATH, + STC_MANAGER_PCAP_INTERFACE, + STC_MANAGER_PCAP_METHOD_FINDALLDEVS, + NULL, + STC_DBUS_REPLY_TIMEOUT, + __stc_pcap_find_all_devs_reply, + NULL); + + if (error != STC_ERROR_NONE) { + STC_LOGE("Failed to invoke dbus method nonblock"); //LCOV_EXCL_LINE + + _stc_event_set_request_table_state( //LCOV_EXCL_LINE + STC_REQUEST_TABLE_PCAP_FIND_ALL_DEVS, false); + return error; //LCOV_EXCL_LINE + } + + return STC_ERROR_NONE; +} + +void _stc_pcap_set_callback(stc_h stc, + stc_pcap_info_cb user_cb, void *user_data) +{ + stc_handle_s *handle = (stc_handle_s *)stc; + + handle->pcap_info_cb = user_cb; + handle->pcap_info_user_data = user_data; +} + EXPORT_API int stc_pcap_create(stc_h stc, stc_pcap_h *pcap_h) { CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC); @@ -307,85 +539,34 @@ EXPORT_API int stc_pcap_stop(stc_h stc, stc_pcap_h pcap_h) return STC_ERROR_NONE; } -static void __stc_pcap_extract(const char *key, - GVariant *value, void *user_data) -{ - stc_pcap_s *pcap = (stc_pcap_s *)user_data; - - if (pcap == NULL) - return; - - if (!g_strcmp0(key, STC_PCAP_IFNAME)) { - guint str_length; - const gchar *str = g_variant_get_string(value, &str_length); - pcap->ifname = g_strdup(str); - - } else if (!g_strcmp0(key, STC_PCAP_NFLOG_GROUP)) { - pcap->nflog_group = g_variant_get_uint32(value); - - } -} - -stc_error_e _stc_pcap_foreach(stc_pcap_info_cb callback, - void *user_data) +EXPORT_API int stc_pcap_foreach(stc_h stc, + stc_pcap_info_cb callback, void *user_data) { - GVariant *message = NULL; - stc_error_e error = STC_ERROR_NONE; - GVariantIter *iter = NULL; - GVariantIter *iter_row = NULL; - GSList *pcap_list = NULL; - GSList *list = NULL; - stc_callback_ret_e rv = STC_CALLBACK_CANCEL; - - message = _stc_dbus_invoke_method( - STC_MANAGER_SERVICE, - STC_MANAGER_PCAP_PATH, - STC_MANAGER_PCAP_INTERFACE, - STC_MANAGER_PCAP_METHOD_GETALL, - NULL, - &error); - - STC_RETURN_VAL_IF(message == NULL, - error, "Failed to invoke dbus method"); - - g_variant_get(message, "(aa{sv})", &iter); - - while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { - stc_pcap_s *pcap = MALLOC0(stc_pcap_s, 1); - - _stc_dbus_dictionary_foreach(iter_row, - __stc_pcap_extract, pcap); - - __stc_pcap_print(pcap); + int ret = STC_ERROR_NONE; - pcap_list = g_slist_append(pcap_list, (stc_pcap_s *)pcap); + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC); - g_variant_iter_free(iter_row); + if (!(_stc_handle_check_validity(stc))) { + STC_LOGE("Invalid parameter"); + return STC_ERROR_INVALID_PARAMETER; } - g_variant_iter_free(iter); - g_variant_unref(message); - - if ((int)g_slist_length(pcap_list) == 0) { - STC_LOGD("There are no pcap loop"); - return STC_ERROR_NONE; + if (callback == NULL) { + STC_LOGE("Invalid parameter"); + return STC_ERROR_INVALID_PARAMETER; } - for (list = pcap_list; list; list = list->next) { - stc_pcap_s *pcap = (stc_pcap_s *)list->data; - __stc_pcap_add_to_list((stc_pcap_h)pcap); - rv = callback((stc_pcap_h)pcap, user_data); - __stc_pcap_remove_from_list((stc_pcap_h)pcap); - if (rv == false) - break; + ret = _stc_pcap_foreach(callback, user_data); + if (ret != STC_ERROR_NONE) { + STC_LOGE("Failed to get all pcap [%s]", + _stc_convert_error_type_to_string(ret)); + return ret; } - g_slist_free_full(pcap_list, __stc_pcap_deinit); - return STC_ERROR_NONE; } -EXPORT_API int stc_pcap_foreach(stc_h stc, +EXPORT_API int stc_pcap_find_all_devs(stc_h stc, stc_pcap_info_cb callback, void *user_data) { int ret = STC_ERROR_NONE; @@ -402,9 +583,11 @@ EXPORT_API int stc_pcap_foreach(stc_h stc, return STC_ERROR_INVALID_PARAMETER; } - ret = _stc_pcap_foreach(callback, user_data); + _stc_pcap_set_callback(stc, callback, user_data); + + ret = _stc_pcap_find_all_devs(callback, user_data); if (ret != STC_ERROR_NONE) { - STC_LOGE("Failed to get all pcap [%s]", + STC_LOGE("Failed to find all devs [%s]", _stc_convert_error_type_to_string(ret)); return ret; } @@ -494,4 +677,76 @@ EXPORT_API int stc_pcap_get_nflog_group(stc_pcap_h pcap_h, int *group) return STC_ERROR_NONE; } + +EXPORT_API int stc_pcap_get_dev_name(stc_pcap_h pcap_h, char **name) +{ + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC); + + if (!name) { + STC_LOGE("Invalid parameter"); + return STC_ERROR_INVALID_PARAMETER; + } + + stc_pcap_s *pcap = (stc_pcap_s *)pcap_h; + + *name = g_strdup(pcap->dev_name); + + STC_LOGI("Device name [%s]", *name); + + return STC_ERROR_NONE; +} + +EXPORT_API int stc_pcap_get_dev_decs(stc_pcap_h pcap_h, char **decs) +{ + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC); + + if (!decs) { + STC_LOGE("Invalid parameter"); + return STC_ERROR_INVALID_PARAMETER; + } + + stc_pcap_s *pcap = (stc_pcap_s *)pcap_h; + + *decs = g_strdup(pcap->dev_decs); + + STC_LOGI("Device description [%s]", *decs); + + return STC_ERROR_NONE; +} + +EXPORT_API int stc_pcap_get_dev_net(stc_pcap_h pcap_h, char **net) +{ + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC); + + if (!net) { + STC_LOGE("Invalid parameter"); + return STC_ERROR_INVALID_PARAMETER; + } + + stc_pcap_s *pcap = (stc_pcap_s *)pcap_h; + + *net = g_strdup(pcap->dev_net); + + STC_LOGI("Device net [%s]", *net); + + return STC_ERROR_NONE; +} + +EXPORT_API int stc_pcap_get_dev_mask(stc_pcap_h pcap_h, char **mask) +{ + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC); + + if (!mask) { + STC_LOGE("Invalid parameter"); + return STC_ERROR_INVALID_PARAMETER; + } + + stc_pcap_s *pcap = (stc_pcap_s *)pcap_h; + + *mask = g_strdup(pcap->dev_mask); + + STC_LOGI("Device mask [%s]", *mask); + + return STC_ERROR_NONE; +} //LCOV_EXCL_STOP diff --git a/test/pcap.c b/test/pcap.c index 52f89d2..f157f7b 100755 --- a/test/pcap.c +++ b/test/pcap.c @@ -99,8 +99,10 @@ static stc_callback_ret_e __test_stc_pcap_cb(stc_pcap_h pcap_h, msg(HR_SINGLE); ret = stc_pcap_get_ifname(pcap_h, &ifname); - if (ret == STC_ERROR_NONE) + if (ret == STC_ERROR_NONE) { msg("Ifname: " LOG_CYAN "[%s]" LOG_END, ifname); + g_free(ifname); + } ret = stc_pcap_get_nflog_group(pcap_h, &group); if (ret == STC_ERROR_NONE) @@ -111,6 +113,54 @@ static stc_callback_ret_e __test_stc_pcap_cb(stc_pcap_h pcap_h, return TRUE; } +static stc_callback_ret_e __test_stc_pcap_dev_cb(stc_pcap_h pcap_h, + void *user_data) +{ + int ret = STC_ERROR_NONE; + char *name; + char *decs; + char *net; + char *mask; + + msg(HR_SINGLE); + + ret = stc_pcap_get_dev_name(pcap_h, &name); + if (ret == STC_ERROR_NONE) { + if (name) { + msg("Name: " LOG_CYAN "[%s]" LOG_END, name); + g_free(name); + } + } + + ret = stc_pcap_get_dev_decs(pcap_h, &decs); + if (ret == STC_ERROR_NONE) { + if (decs) { + msg("Decs: " LOG_CYAN "[%s]" LOG_END, decs); + g_free(decs); + } + } + + ret = stc_pcap_get_dev_net(pcap_h, &net); + if (ret == STC_ERROR_NONE) { + if (net) { + msg("Net: " LOG_CYAN "[%s]" LOG_END, net); + g_free(net); + } + } + + ret = stc_pcap_get_dev_mask(pcap_h, &mask); + if (ret == STC_ERROR_NONE) { + if (mask) { + msg("Mask: " LOG_CYAN "[%s]" LOG_END, mask); + g_free(mask); + } + } + + msg(HR_SINGLE); + + return TRUE; +} + static int __test_stc_pcap_get_all(MManager *mm, struct menu_data *menu) { int ret = STC_ERROR_NONE; @@ -125,6 +175,20 @@ static int __test_stc_pcap_get_all(MManager *mm, struct menu_data *menu) return ret; } +static int __test_stc_pcap_find_all_devs(MManager *mm, struct menu_data *menu) +{ + int ret = STC_ERROR_NONE; + + ret = stc_pcap_find_all_devs(g_stc, __test_stc_pcap_dev_cb, NULL); + if (ret == STC_ERROR_NONE) + msg(LOG_GREEN "Success to find all devs" LOG_END); + else + msg("Fail to find all devs " LOG_RED "[%s]" LOG_END, + test_stc_convert_error_type_to_string(ret)); + + return ret; +} + static int __test_stc_pcap_start(MManager *mm, struct menu_data *menu) { int ret = STC_ERROR_NONE; @@ -197,5 +261,6 @@ struct menu_data menu_pcap[] = { { "2", LOG_LIGHTBLUE "[GetAll]" LOG_END " pcap", NULL, __test_stc_pcap_get_all, NULL}, { "3", LOG_LIGHTMAGENTA "[Start]" LOG_END " pcap", NULL, __test_stc_pcap_start, NULL}, { "4", LOG_LIGHTMAGENTA "[Stop]" LOG_END " pcap", NULL, __test_stc_pcap_stop, NULL}, + { "5", LOG_LIGHTBLUE "[FindAll]" LOG_END " devs", NULL, __test_stc_pcap_find_all_devs, NULL}, { NULL, NULL, }, };