2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "stc-manager.h"
20 #include "stc-manager-plugin-pcap.h"
22 static gboolean stc_plugin_enabled = FALSE;
23 static void *handle_plugin;
24 static stc_plugin_pcap_s *stc_plugin;
27 int stc_plugin_pcap_init(void)
29 __STC_LOG_FUNC_ENTER__;
31 handle_plugin = dlopen(STC_PLUGIN_PCAP_FILEPATH, RTLD_NOW);
33 STC_LOGE("Can't load %s: %s", STC_PLUGIN_PCAP_FILEPATH, dlerror());
34 __STC_LOG_FUNC_EXIT__;
35 return STC_ERROR_UNINITIALIZED;
38 stc_plugin = dlsym(handle_plugin, "stc_plugin_pcap");
40 STC_LOGE("Can't load symbol: %s", dlerror());
41 dlclose(handle_plugin);
42 __STC_LOG_FUNC_EXIT__;
43 return STC_ERROR_UNINITIALIZED;
46 stc_plugin->initialize_plugin();
47 stc_plugin_enabled = TRUE;
49 __STC_LOG_FUNC_EXIT__;
50 return STC_ERROR_NONE;
53 int stc_plugin_pcap_deinit(void)
55 __STC_LOG_FUNC_ENTER__;
57 if (!stc_plugin_enabled) {
58 __STC_LOG_FUNC_EXIT__;
59 return STC_ERROR_UNINITIALIZED;
62 stc_plugin->deinitialize_plugin();
63 stc_plugin_enabled = FALSE;
64 dlclose(handle_plugin);
66 __STC_LOG_FUNC_EXIT__;
67 return STC_ERROR_NONE;
70 int stc_plugin_pcap_lookup_dev(void)
72 __STC_LOG_FUNC_ENTER__;
74 if (!stc_plugin_enabled) {
75 STC_LOGE("Plugin wasn't enabled");
76 __STC_LOG_FUNC_EXIT__;
77 return STC_ERROR_UNINITIALIZED;
81 STC_LOGE("Plugin wasn't loaded");
82 __STC_LOG_FUNC_EXIT__;
83 return STC_ERROR_UNINITIALIZED;
86 __STC_LOG_FUNC_EXIT__;
87 return stc_plugin->lookup_dev();
90 int stc_plugin_pcap_lookup_net(void)
92 __STC_LOG_FUNC_ENTER__;
94 if (!stc_plugin_enabled) {
95 STC_LOGE("Plugin wasn't enabled");
96 __STC_LOG_FUNC_EXIT__;
97 return STC_ERROR_UNINITIALIZED;
101 STC_LOGE("Plugin wasn't loaded");
102 __STC_LOG_FUNC_EXIT__;
103 return STC_ERROR_UNINITIALIZED;
106 __STC_LOG_FUNC_EXIT__;
107 return stc_plugin->lookup_net();
110 int stc_plugin_pcap_find_alldevs(void)
112 __STC_LOG_FUNC_ENTER__;
114 if (!stc_plugin_enabled) {
115 STC_LOGE("Plugin wasn't enabled");
116 __STC_LOG_FUNC_EXIT__;
117 return STC_ERROR_UNINITIALIZED;
121 STC_LOGE("Plugin wasn't loaded");
122 __STC_LOG_FUNC_EXIT__;
123 return STC_ERROR_UNINITIALIZED;
126 __STC_LOG_FUNC_EXIT__;
127 return stc_plugin->find_alldevs();
130 int stc_plugin_pcap_register_loop_pcap(const char *ifname,
133 __STC_LOG_FUNC_ENTER__;
135 if (!stc_plugin_enabled) {
136 STC_LOGE("Plugin wasn't enabled");
137 __STC_LOG_FUNC_EXIT__;
138 return STC_ERROR_UNINITIALIZED;
142 STC_LOGE("Plugin wasn't loaded");
143 __STC_LOG_FUNC_EXIT__;
144 return STC_ERROR_UNINITIALIZED;
147 __STC_LOG_FUNC_EXIT__;
148 return stc_plugin->register_loop_pcap(ifname, group);
151 int stc_plugin_pcap_unregister_loop_pcap(const char *ifname,
154 __STC_LOG_FUNC_ENTER__;
156 if (!stc_plugin_enabled) {
157 STC_LOGE("Plugin wasn't enabled");
158 __STC_LOG_FUNC_EXIT__;
159 return STC_ERROR_UNINITIALIZED;
163 STC_LOGE("Plugin wasn't loaded");
164 __STC_LOG_FUNC_EXIT__;
165 return STC_ERROR_UNINITIALIZED;
168 __STC_LOG_FUNC_EXIT__;
169 return stc_plugin->unregister_loop_pcap(ifname, group);