2 * Network Configuration Module
4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
24 #include <sys/ioctl.h>
25 #include <netinet/in.h>
26 #include <netinet/ip.h>
27 #include <linux/wireless.h>
29 #include <vconf-keys.h>
34 #include "wifi-state.h"
35 #include "network-state.h"
36 #include "network-statistics.h"
37 #include "netsupplicant.h"
38 #include "wifi-indicator.h"
40 #define VCONFKEY_WIFI_SNR_MIN -89
42 #if !defined TIZEN_WEARABLE
43 #define WIFI_INDICATOR_INTERVAL 1
45 #define WIFI_INDICATOR_INTERVAL 10
48 #if defined TIZEN_WEARABLE
49 #define NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL1 (19200 * 1024)
50 #define NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL2 (2560 * 1024)
51 #define NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL3 (1536 * 1024)
53 #define NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL1 (19200 * 1024)
54 #define NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL2 (7680 * 1024)
55 #define NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL3 (3840 * 1024)
57 #define NETCONFIG_PROCWIRELESS "/proc/net/wireless"
59 static int netconfig_wifi_rssi = VCONFKEY_WIFI_SNR_MIN;
60 static guint netconfig_wifi_indicator_timer = 0;
62 int netconfig_wifi_get_rssi(void)
64 return netconfig_wifi_rssi;
67 static int __netconfig_wifi_update_and_get_rssi(void)
70 GVariant *message = NULL;
71 GVariant *value = NULL;
76 int rssi_dbm = VCONFKEY_WIFI_SNR_MIN;
78 if_path = netconfig_wifi_get_supplicant_interface();
79 if (if_path == NULL) {
80 ERR("Fail to get wpa_supplicant DBus path");
84 message = netconfig_invoke_dbus_method(SUPPLICANT_SERVICE, if_path,
85 SUPPLICANT_INTERFACE ".Interface", "SignalPoll", NULL);
86 if (message == NULL) {
87 ERR("Fail to get SignalPoll from wpa_supplicant");
92 g_variant_get(message, "(v)", &value);
94 g_variant_get(value, "a{sv}", &iter);
95 while (g_variant_iter_loop(iter, "{sv}", &key, &variant)) {
96 key_value = g_variant_get_int32(variant);
98 if (g_strcmp0(key, "rssi") == 0) {
99 rssi_dbm = (int)key_value;
100 DBG("Currently signal dbm value [%d]", rssi_dbm);
101 g_variant_unref(variant);
107 g_variant_iter_free(iter);
110 g_variant_unref(value);
112 g_variant_unref(message);
116 netconfig_wifi_rssi = rssi_dbm;
121 int netconfig_wifi_rssi_level(const int rssi_dbm)
125 /* Wi-Fi Signal Strength Display
134 else if (rssi_dbm >= -74)
136 else if (rssi_dbm >= -82)
144 static void __netconfig_wifi_set_rssi_level(const int snr_level)
146 static int last_snr_level = 0;
148 if (snr_level != last_snr_level) {
149 netconfig_set_vconf_int(VCONFKEY_WIFI_STRENGTH, snr_level);
150 last_snr_level = snr_level;
154 static void __netconfig_wifi_data_activity_booster(int level)
156 gboolean reply = FALSE;
157 GVariant *params = NULL;
165 static int old_level = 0;
174 params = g_variant_new("(ii)", level1, lock);
177 params = g_variant_new("(ii)", level2, lock);
180 params = g_variant_new("(ii)", level3, lock);
183 ERR("Invalid level");
187 reply = netconfig_invoke_dbus_method_nonblock(
188 "org.tizen.system.deviced",
189 "/Org/Tizen/System/DeviceD/PmQos",
190 "org.tizen.system.deviced.PmQos",
198 /* disable previous booster */
199 if (old_level == 0 || old_level == level)
204 params = g_variant_new("(ii)", level1, unlock);
207 params = g_variant_new("(ii)", level2, unlock);
210 params = g_variant_new("(ii)", level3, unlock);
213 ERR("Invalid level");
217 reply = netconfig_invoke_dbus_method_nonblock(
218 "org.tizen.system.deviced",
219 "/Org/Tizen/System/DeviceD/PmQos",
220 "org.tizen.system.deviced.PmQos",
230 static void __netconfig_wifi_update_indicator(void)
232 static int last_transfer_state = 0;
233 static guint64 netconfig_wifi_tx_bytes = 0;
234 static guint64 netconfig_wifi_rx_bytes = 0;
235 static int booster_tic = 0;
236 static int old_level = 0;
237 int booster_level = 0;
238 guint64 tx, rx, tx_diff, rx_diff;
241 if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) {
242 tx_diff = tx - netconfig_wifi_tx_bytes;
243 rx_diff = rx - netconfig_wifi_rx_bytes;
247 transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_TXRX;
249 transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_TX;
252 transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_RX;
254 transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_NONE;
257 if (transfer_state != last_transfer_state) {
258 netconfig_set_vconf_int(VCONFKEY_WIFI_TRANSFER_STATE, transfer_state);
259 last_transfer_state = transfer_state;
262 /* NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER */
263 if (tx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL1 ||
264 rx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL1)
266 else if (tx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL2 ||
267 rx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL2)
269 else if (tx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL3 ||
270 rx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL3)
273 if (old_level == booster_level) {
274 if (--booster_tic <= 0) {
275 __netconfig_wifi_data_activity_booster(booster_level);
280 __netconfig_wifi_data_activity_booster(booster_level);
282 if (booster_level > 0)
288 old_level = booster_level;
290 netconfig_wifi_tx_bytes = tx;
291 netconfig_wifi_rx_bytes = rx;
295 static gboolean __wifi_indicator_monitor(gpointer data)
299 int pm_state = VCONFKEY_PM_STATE_NORMAL;
301 if (wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED)
304 /* In case of LCD off, we don't need to update Wi-Fi indicator */
305 netconfig_vconf_get_int(VCONFKEY_PM_STATE, &pm_state);
306 if (pm_state >= VCONFKEY_PM_STATE_LCDOFF)
309 rssi_dbm = __netconfig_wifi_update_and_get_rssi();
310 /* INFO("%d dbm", rssi_dbm); */
311 snr_level = netconfig_wifi_rssi_level(rssi_dbm);
312 __netconfig_wifi_set_rssi_level(snr_level);
314 __netconfig_wifi_update_indicator();
319 void netconfig_wifi_indicator_start(void)
321 INFO("Start Wi-Fi indicator");
323 netconfig_set_vconf_int(VCONFKEY_WIFI_STRENGTH, VCONFKEY_WIFI_STRENGTH_MAX);
324 netconfig_start_timer_seconds(WIFI_INDICATOR_INTERVAL, __wifi_indicator_monitor, NULL, &netconfig_wifi_indicator_timer);
327 void netconfig_wifi_indicator_stop(void)
329 INFO("Stop Wi-Fi indicator");
331 netconfig_stop_timer(&netconfig_wifi_indicator_timer);
333 netconfig_wifi_rssi = VCONFKEY_WIFI_SNR_MIN;