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-tether.h"
22 static gboolean stc_tether_plugin_enabled = FALSE;
23 static void *tether_plugin_handle;
24 static stc_plugin_tether_s *plugin;
26 int stc_plugin_tether_init(void)
28 __STC_LOG_FUNC_ENTER__;
30 tether_plugin_handle = dlopen(STC_PLUGIN_TETHER_FILEPATH, RTLD_NOW);
31 if (!tether_plugin_handle) {
32 STC_LOGE("Can't load %s: %s", STC_PLUGIN_TETHER_FILEPATH, dlerror());
33 __STC_LOG_FUNC_EXIT__;
34 return STC_ERROR_UNINITIALIZED;
37 plugin = dlsym(tether_plugin_handle, "tether_plugin");
39 STC_LOGE("Can't load symbol: %s", dlerror());
40 dlclose(tether_plugin_handle);
41 __STC_LOG_FUNC_EXIT__;
42 return STC_ERROR_UNINITIALIZED;
46 stc_tether_plugin_enabled = TRUE;
48 __STC_LOG_FUNC_EXIT__;
49 return STC_ERROR_NONE;
52 int stc_plugin_tether_deinit(void)
54 __STC_LOG_FUNC_ENTER__;
56 if (!stc_tether_plugin_enabled) {
57 __STC_LOG_FUNC_EXIT__;
58 return STC_ERROR_UNINITIALIZED;
62 stc_tether_plugin_enabled = FALSE;
63 dlclose(tether_plugin_handle);
65 __STC_LOG_FUNC_EXIT__;
66 return STC_ERROR_NONE;
69 int stc_plugin_tether_get_station_ip(const char *mac, char **ipaddr)
71 __STC_LOG_FUNC_ENTER__;
72 char ip[INET_ADDRSTRLEN+1];
74 if (!stc_tether_plugin_enabled ||
75 mac == NULL || ipaddr == NULL) {
76 STC_LOGE("invalid args");
77 __STC_LOG_FUNC_EXIT__;
78 return STC_ERROR_INVALID_PARAMETER;
81 memset(ip, 0, sizeof(ip));
83 if (plugin->get_station_ip(mac, ip) != STC_ERROR_NONE)
84 return STC_ERROR_FAIL;
86 *ipaddr = g_strdup(ip);
87 STC_LOGI("station ip(%s)", *ipaddr);
89 __STC_LOG_FUNC_EXIT__;
90 return STC_ERROR_NONE;
93 int stc_plugin_tether_get_station_by_classid(const int classid, char **mac)
95 __STC_LOG_FUNC_ENTER__;
96 char mac_addr[STATION_MAC_STR_LEN+1];
98 if (!stc_tether_plugin_enabled || mac == NULL) {
99 STC_LOGE("invalid args");
100 __STC_LOG_FUNC_EXIT__;
101 return STC_ERROR_INVALID_PARAMETER;
104 memset(mac_addr, 0, sizeof(mac_addr));
106 if (plugin->get_station_by_classid(classid, mac_addr) != STC_ERROR_NONE)
107 return STC_ERROR_FAIL;
109 *mac = g_strdup(mac_addr);
110 STC_LOGI("station mac(%s)", *mac);
112 __STC_LOG_FUNC_EXIT__;
113 return STC_ERROR_NONE;
116 int stc_plugin_tether_set_station_classid(const char *mac, int classid)
118 __STC_LOG_FUNC_ENTER__;
120 if (!stc_tether_plugin_enabled || mac == NULL) {
121 STC_LOGE("invalid args");
122 __STC_LOG_FUNC_EXIT__;
123 return STC_ERROR_INVALID_PARAMETER;
126 if (plugin->set_station_classid(mac, classid) != STC_ERROR_NONE)
127 return STC_ERROR_FAIL;
129 STC_LOGI("classid(%d) for station mac(%s) is set successfully",
131 __STC_LOG_FUNC_EXIT__;
132 return STC_ERROR_NONE;