* Callback functions
*****************************************************************************/
+typedef stc_callback_ret_e (*stc_pcap_info_cb)(stc_pcap_h info_h, void *user_data);
+
/*****************************************************************************
* Core API functions
*****************************************************************************/
* @brief Starts packet capture.
* @since_tizen 5.0
*
+ * @param[in] stc The stc handle
* @param[in] pcap_h The pcap handle
*
* @return 0 on success, otherwise a negative error value
* @see stc_pcap_create()
* @see stc_pcap_destroy()
*/
-int stc_pcap_start(stc_pcap_h pcap_h);
+int stc_pcap_start(stc_h stc, stc_pcap_h pcap_h);
/**
* @brief Stops packet capture.
* @since_tizen 5.0
*
+ * @param[in] stc The stc handle
* @param[in] pcap_h The pcap handle
*
* @return 0 on success, otherwise a negative error value
* @see stc_pcap_create()
* @see stc_pcap_destroy()
*/
-int stc_pcap_stop(stc_pcap_h pcap_h);
+int stc_pcap_stop(stc_h stc, stc_pcap_h pcap_h);
+
+/**
+ * @brief Gets all packet capture.
+ * @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_foreach(stc_h stc, stc_pcap_info_cb callback, void *user_data);
/**
* @brief Sets interface name to pcap.
#define STC_MANAGER_PCAP_METHOD_START "Start"
#define STC_MANAGER_PCAP_METHOD_STOP "Stop"
+#define STC_MANAGER_PCAP_METHOD_GETALL "GetAll"
#define STC_PCAP_IFNAME "ifname"
#define STC_PCAP_NFLOG_GROUP "nflog_group"
stc_fw_chain_s *chain = (stc_fw_chain_s *)data;
FREE(chain->chain);
FREE(chain);
- chain = NULL;
}
static void __stc_fw_init_rule(void *data)
g_variant_builder_unref(builder);
}
+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);
+}
stc_error_e _stc_pcap_start(stc_pcap_s *pcap)
{
return STC_ERROR_NONE;
}
-EXPORT_API int stc_pcap_start(stc_pcap_h pcap_h)
+EXPORT_API int stc_pcap_start(stc_h stc, stc_pcap_h pcap_h)
{
int ret = STC_ERROR_NONE;
CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC);
+ if (!(_stc_handle_check_validity(stc))) {
+ STC_LOGE("Invalid parameter");
+ return STC_ERROR_INVALID_PARAMETER;
+ }
+
if (__stc_pcap_check_validity(pcap_h) == false) {
STC_LOGE("Invalid parameter");
return STC_ERROR_INVALID_PARAMETER;
return STC_ERROR_NONE;
}
-EXPORT_API int stc_pcap_stop(stc_pcap_h pcap_h)
+EXPORT_API int stc_pcap_stop(stc_h stc, stc_pcap_h pcap_h)
{
int ret = STC_ERROR_NONE;
CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC);
+ if (!(_stc_handle_check_validity(stc))) {
+ STC_LOGE("Invalid parameter");
+ return STC_ERROR_INVALID_PARAMETER;
+ }
+
if (__stc_pcap_check_validity(pcap_h) == false) {
STC_LOGE("Invalid parameter");
return STC_ERROR_INVALID_PARAMETER;
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)
+{
+ 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;
+}
+
+EXPORT_API int stc_pcap_foreach(stc_h stc,
+ stc_pcap_info_cb callback, void *user_data)
+{
+ int ret = STC_ERROR_NONE;
+
+ CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC);
+
+ if (!(_stc_handle_check_validity(stc))) {
+ STC_LOGE("Invalid parameter");
+ return STC_ERROR_INVALID_PARAMETER;
+ }
+
+ if (callback == NULL) {
+ STC_LOGE("Invalid parameter");
+ return STC_ERROR_INVALID_PARAMETER;
+ }
+
+ 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;
+ }
+
+ return STC_ERROR_NONE;
+}
+
EXPORT_API int stc_pcap_set_ifname(stc_pcap_h pcap_h, char *ifname)
{
CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_STC);
return STC_ERROR_NONE;
}
+static stc_callback_ret_e __test_stc_pcap_cb(stc_pcap_h pcap_h,
+ void *user_data)
+{
+ int ret = STC_ERROR_NONE;
+ char *ifname;
+ int group;
+
+ msg(HR_SINGLE);
+
+ ret = stc_pcap_get_ifname(pcap_h, &ifname);
+ if (ret == STC_ERROR_NONE)
+ msg("Ifname: " LOG_CYAN "[%s]" LOG_END, ifname);
+
+ ret = stc_pcap_get_nflog_group(pcap_h, &group);
+ if (ret == STC_ERROR_NONE)
+ msg("Nflog group: " LOG_CYAN "[%d]" LOG_END, group);
+
+ msg(HR_SINGLE);
+
+ return TRUE;
+}
+
+static int __test_stc_pcap_get_all(MManager *mm, struct menu_data *menu)
+{
+ int ret = STC_ERROR_NONE;
+
+ ret = stc_pcap_foreach(g_stc, __test_stc_pcap_cb, NULL);
+ if (ret == STC_ERROR_NONE)
+ msg(LOG_GREEN "Success to get all pcap" LOG_END);
+ else
+ msg("Fail to get all pcap " 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;
- ret = stc_pcap_start(g_pcap_h);
+ ret = stc_pcap_start(g_stc, g_pcap_h);
if (ret == STC_ERROR_NONE)
msg(LOG_GREEN "Success to start pcap" LOG_END);
{
int ret = STC_ERROR_NONE;
- ret = stc_pcap_stop(g_pcap_h);
+ ret = stc_pcap_stop(g_stc, g_pcap_h);
if (ret == STC_ERROR_NONE)
msg(LOG_GREEN "Success to stop pcap" LOG_END);
struct menu_data menu_pcap[] = {
{ "1", LOG_LIGHTMAGENTA "[Set]" LOG_END " pcap info", menu_pcap_info, NULL, NULL},
- { "2", LOG_LIGHTMAGENTA "[Start]" LOG_END " pcap", NULL, __test_stc_pcap_start, NULL},
- { "3", LOG_LIGHTMAGENTA "[Stop]" LOG_END " pcap", NULL, __test_stc_pcap_stop, NULL},
+ { "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},
{ NULL, NULL, },
};