static Network_statistics *netconfigstatistics = NULL;
-static gboolean __find_wifi_interface_name(const char *interface_name)
+static wifi_device_data_s *__find_wifi_interface_name(const char *interface_name)
{
GSList *list = wifi_state_get_device_list();
for ( ; list; list = list->next) {
wifi_device_data_s *device_data = list->data;
if (g_strcmp0(device_data->interface_name, interface_name) == 0)
- return TRUE;
+ return device_data;
}
- return FALSE;
+ return NULL;
}
-gboolean netconfig_wifi_get_bytes_statistics(guint64 *tx, guint64 *rx)
+gboolean netconfig_wifi_get_bytes_statistics(guint64 *tx, guint64 *rx, gboolean update)
{
gboolean ret = FALSE;
FILE *fp;
gchar buf[1024];
gchar *p_ifname = NULL, *p_entry = NULL;
+ guint64 curr_tx = 0;
+ guint64 curr_rx = 0;
+ wifi_device_data_s *device_data = NULL;
*tx = 0;
*rx = 0;
p_ifname = buf;
while (*p_ifname == ' ') p_ifname++;
p_entry = strchr(p_ifname, ':');
- if (p_entry != NULL) {
+ if (p_entry != NULL)
*p_entry++ = '\0';
- if (__find_wifi_interface_name(p_ifname) == FALSE)
+ device_data = __find_wifi_interface_name(p_ifname);
+ if (device_data == NULL)
continue;
/* read interface statistics */
sscanf(p_entry,
"%llu %llu %lu %lu %lu %lu %lu %lu "
"%llu %llu %lu %lu %lu %lu %lu %lu",
- (long long unsigned int *)rx, /* rx bytes */
+ (long long unsigned int *)&curr_rx, /* rx bytes */
&llval, /* rx packet */
&lval, /* rx errors */
&lval, /* rx dropped */
&lval, /* rx compressed */
&lval, /* rx multicast */
- (long long unsigned int *)tx, /* tx bytes */
+ (long long unsigned int *)&curr_tx, /* tx bytes */
&llval, /* tx packet */
&lval, /* tx errors */
&lval, /* tx dropped */
&lval, /* tx carrier errors */
&lval /* tx compressed */
);
- } else {
- ERR("No matched Iface name in proc file");
+
+ if (update == TRUE) {
+ device_data->tx_diff = curr_tx - device_data->tx;
+ device_data->rx_diff = curr_rx - device_data->rx;
+ device_data->tx = curr_tx;
+ device_data->rx = curr_rx;
}
+
+ *tx += device_data->tx_diff;
+ *rx += device_data->rx_diff;
+
ret = TRUE;
- break;
}
endline:
+ DBG("tx[%llu] rx[%llu]", *tx, *rx);
+
fclose(fp);
return ret;
}
+void netconfig_wifi_get_bytes_default_iface(guint64 *tx, guint64 *rx)
+{
+ wifi_device_data_s *device_data = NULL;
+
+ *tx = 0;
+ *rx = 0;
+
+ device_data = __find_wifi_interface_name(netconfig_get_default_ifname());
+ if (device_data == NULL)
+ return;
+
+ *tx = device_data->tx_diff;
+ *rx = device_data->rx_diff;
+}
+
+void netconfig_wifi_set_bytes_pkt_vconf(guint64 tx_diff, guint64 rx_diff)
+{
+ int val = 0;
+ guint64 last_tx = 0, last_rx = 0;
+ guint64 total_tx = 0, total_rx = 0;
+
+ /* LAST */
+ netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, &val);
+ last_tx = (guint64)val + tx_diff;
+
+ netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, &val);
+ last_rx = (guint64)val + rx_diff;
+
+ netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, (int)last_tx);
+ netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, (int)last_rx);
+
+ /* TOTAL */
+ netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, &val);
+ total_tx = (guint64)val + tx_diff;
+
+ netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, &val);
+ total_rx = (guint64)val + rx_diff;
+
+ netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, (int)total_tx);
+ netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, (int)total_rx);
+}
+
+void netconfig_wifi_reset_last_bytes(void)
+{
+ netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, 0);
+ netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, 0);
+}
+
static gboolean handle_get_wifi_total_tx_bytes(
Network_statistics *object,
GDBusMethodInvocation *context)
{
+ int wifi_state = 0;
guint64 tx = 0, rx = 0;
guint64 tx_bytes = 0;
guint64 total_bytes = 0;
int val = 0;
+ netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
+
netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, &val);
tx_bytes = (guint64)val;
- if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE)
+ if (wifi_state != VCONFKEY_WIFI_CONNECTED) {
+ total_bytes = tx_bytes;
+ network_statistics_complete_get_wifi_total_tx_bytes(object, context, total_bytes);
+ return TRUE;
+ }
+
+ if (netconfig_wifi_get_bytes_statistics(&tx, &rx, FALSE) == TRUE)
total_bytes = tx + tx_bytes;
else
total_bytes = tx_bytes;
Network_statistics *object,
GDBusMethodInvocation *context)
{
+ int wifi_state = 0;
guint64 tx = 0, rx = 0;
guint64 rx_bytes = 0;
guint64 total_bytes = 0;
int val = 0;
+ netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
+
netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, &val);
rx_bytes = (guint64)val;
- if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE)
+ if (wifi_state != VCONFKEY_WIFI_CONNECTED) {
+ total_bytes = rx_bytes;
+ network_statistics_complete_get_wifi_total_rx_bytes(object, context, total_bytes);
+ return TRUE;
+ }
+
+ if (netconfig_wifi_get_bytes_statistics(&tx, &rx, FALSE) == TRUE)
total_bytes = rx + rx_bytes;
else
total_bytes = rx_bytes;
Network_statistics *object,
GDBusMethodInvocation *context)
{
+ int wifi_state = 0;
guint64 tx = 0, rx = 0;
guint64 tx_bytes = 0;
guint64 last_bytes = 0;
int val = 0;
+ netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
+
netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, &val);
tx_bytes = (guint64)val;
- if (wifi_state_get_service_state(netconfig_get_default_ifname()) != NETCONFIG_WIFI_CONNECTED) {
+ if (wifi_state != VCONFKEY_WIFI_CONNECTED) {
last_bytes = tx_bytes;
network_statistics_complete_get_wifi_last_tx_bytes(object, context, last_bytes);
return TRUE;
}
- if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE)
- last_bytes = tx < tx_bytes ? 0 : tx - tx_bytes;
+ if (netconfig_wifi_get_bytes_statistics(&tx, &rx, FALSE) == TRUE)
+ last_bytes = tx + tx_bytes;
else
last_bytes = tx_bytes;
Network_statistics *object,
GDBusMethodInvocation *context)
{
+ int wifi_state = 0;
guint64 tx = 0, rx = 0;
guint64 rx_bytes = 0;
guint64 last_bytes = 0;
int val = 0;
+ netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
+
netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, &val);
rx_bytes = (guint64)val;
- if (wifi_state_get_service_state(netconfig_get_default_ifname()) != NETCONFIG_WIFI_CONNECTED) {
+ if (wifi_state != VCONFKEY_WIFI_CONNECTED) {
last_bytes = rx_bytes;
network_statistics_complete_get_wifi_last_rx_bytes(object, context, last_bytes);
return TRUE;
}
- if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE)
- last_bytes = rx < rx_bytes ? 0 : rx - rx_bytes;
+ if (netconfig_wifi_get_bytes_statistics(&tx, &rx, FALSE) == TRUE)
+ last_bytes = rx + rx_bytes;
else
last_bytes = rx_bytes;
Network_statistics *object,
GDBusMethodInvocation *context)
{
- guint64 tx = 0, rx = 0;
-
- if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE)
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, -(int)tx);
- else
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, 0);
-
+ netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, 0);
network_statistics_complete_reset_wifi_total_tx_bytes(object, context);
-
return TRUE;
}
Network_statistics *object,
GDBusMethodInvocation *context)
{
- guint64 tx = 0, rx = 0;
-
- if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE)
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, -(int)rx);
- else
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, 0);
-
+ netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, 0);
network_statistics_complete_reset_wifi_total_rx_bytes(object, context);
return TRUE;
}
Network_statistics *object,
GDBusMethodInvocation *context)
{
- guint64 tx = 0, rx = 0;
-
- if (wifi_state_get_service_state(netconfig_get_default_ifname()) != NETCONFIG_WIFI_CONNECTED) {
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, 0);
- network_statistics_complete_reset_wifi_last_tx_bytes(object, context);
- return TRUE;
- }
-
- if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE)
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, (int)tx);
- else
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, 0);
-
+ netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, 0);
network_statistics_complete_reset_wifi_last_tx_bytes(object, context);
-
return TRUE;
}
Network_statistics *object,
GDBusMethodInvocation *context)
{
- guint64 tx = 0, rx = 0;
-
- if (wifi_state_get_service_state(netconfig_get_default_ifname()) != NETCONFIG_WIFI_CONNECTED) {
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, 0);
- network_statistics_complete_reset_wifi_last_rx_bytes(object, context);
- return TRUE;
- }
-
- if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE)
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, (int)rx);
- else
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, 0);
-
+ netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, 0);
network_statistics_complete_reset_wifi_last_rx_bytes(object, context);
-
return TRUE;
}
-void netconfig_wifi_statistics_update_powered_off(void)
+static void wifi_statistics_update_state(void)
{
- guint64 cur_tx = 0, cur_rx = 0;
- guint64 prev_tx = 0, prev_rx = 0;
- guint64 total_tx = 0, total_rx = 0;
- int val = 0;
-
- if (netconfig_wifi_get_bytes_statistics(&cur_tx, &cur_rx) != TRUE)
- return;
+ guint64 tx, rx;
- netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, &val);
- prev_tx = (guint64)val;
-
- netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, &val);
- prev_rx = (guint64)val;
-
- total_tx = prev_tx + cur_tx;
- total_rx = prev_rx + cur_rx;
-
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, (int)total_tx);
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, (int)total_rx);
-}
-
-static void wifi_statistics_update_state(wifi_state_notifier_s *notifier,
- char *service, wifi_service_state_e state, void *user_data)
-{
- guint64 tx = 0, rx = 0;
- guint64 last_tx = 0, last_rx = 0;
- int val = 0;
- static wifi_service_state_e prev_state = NETCONFIG_WIFI_UNKNOWN;
-
- if (prev_state == NETCONFIG_WIFI_UNKNOWN) {
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, 0);
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, 0);
-
- prev_state = NETCONFIG_WIFI_IDLE;
- return;
- }
-
- if (netconfig_wifi_get_bytes_statistics(&tx, &rx) != TRUE)
- return;
-
- if (state == NETCONFIG_WIFI_CONNECTED) {
- last_tx = tx;
- last_rx = rx;
- } else {
- if (prev_state != NETCONFIG_WIFI_CONNECTED)
- return;
-
- netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, &val);
- last_tx = (guint64)val;
-
- netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, &val);
- last_rx = (guint64)val;
-
- last_tx = tx < last_tx ? 0 : tx - last_tx;
- last_rx = rx < last_rx ? 0 : rx - last_rx;
- }
-
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, (int)last_tx);
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, (int)last_rx);
-
- prev_state = state;
+ netconfig_wifi_get_bytes_statistics(&tx, &rx, TRUE);
}
-static wifi_state_notifier_s state_notifier = {
- .notifier = NULL,
- .service = NULL,
- .wifi_state_changed = wifi_statistics_update_state,
- .user_data = NULL,
-};
-
void statistics_object_create_and_init(void)
{
DBG("Creating statistics object");
ERR("Export with path failed");
}
- wifi_statistics_update_state(&state_notifier, NULL, NETCONFIG_WIFI_IDLE, NULL);
- wifi_state_notifier_register(&state_notifier);
+ wifi_statistics_update_state();
return;
}
static void __netconfig_wifi_get_statistics(void)
{
static int last_transfer_state = 0;
- static guint64 netconfig_wifi_tx_bytes = 0;
- static guint64 netconfig_wifi_rx_bytes = 0;
static int booster_tic = 0;
static int old_level = 0;
int booster_level = 0;
- guint64 tx, rx, tx_diff, rx_diff;
+ guint64 tx, rx;
int transfer_state;
- if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) {
- tx_diff = tx - netconfig_wifi_tx_bytes;
- rx_diff = rx - netconfig_wifi_rx_bytes;
-
- if (tx_diff > 0) {
- if (rx_diff > 0)
- transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_TXRX;
- else
- transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_TX;
- } else {
- if (rx_diff > 0)
- transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_RX;
- else
- transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_NONE;
- }
+ if (netconfig_wifi_get_bytes_statistics(&tx, &rx, TRUE))
+ netconfig_wifi_set_bytes_pkt_vconf(tx, rx);
+
+ netconfig_wifi_get_bytes_default_iface(&tx, &rx);
+
+ if (tx > 0) {
+ if (rx > 0)
+ transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_TXRX;
+ else
+ transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_TX;
+ } else {
+ if (rx > 0)
+ transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_RX;
+ else
+ transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_NONE;
+ }
- if (transfer_state != last_transfer_state) {
- netconfig_set_vconf_int(VCONFKEY_WIFI_TRANSFER_STATE, transfer_state);
- last_transfer_state = transfer_state;
- }
+ if (transfer_state != last_transfer_state) {
+ netconfig_set_vconf_int(VCONFKEY_WIFI_TRANSFER_STATE, transfer_state);
+ last_transfer_state = transfer_state;
+ }
- /* NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER */
- if (tx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL1 ||
- rx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL1)
- booster_level = 1;
- else if (tx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL2 ||
- rx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL2)
- booster_level = 2;
- else if (tx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL3 ||
- rx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL3)
- booster_level = 3;
-
- if (old_level == booster_level) {
- if (--booster_tic <= 0) {
- __netconfig_wifi_data_activity_booster(booster_level);
-
- booster_tic = 2;
- }
- } else {
+ /* NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER */
+ if (tx >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL1 ||
+ rx >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL1)
+ booster_level = 1;
+ else if (tx >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL2 ||
+ rx >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL2)
+ booster_level = 2;
+ else if (tx >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL3 ||
+ rx >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL3)
+ booster_level = 3;
+
+ if (old_level == booster_level) {
+ if (--booster_tic <= 0) {
__netconfig_wifi_data_activity_booster(booster_level);
- if (booster_level > 0)
- booster_tic = 2;
- else
- booster_tic = 0;
+ booster_tic = 2;
}
+ } else {
+ __netconfig_wifi_data_activity_booster(booster_level);
- old_level = booster_level;
-
- netconfig_wifi_tx_bytes = tx;
- netconfig_wifi_rx_bytes = rx;
+ if (booster_level > 0)
+ booster_tic = 2;
+ else
+ booster_tic = 0;
}
+
+ old_level = booster_level;
}
static gboolean __netconfig_wifi_update_statistics(gpointer data)
wifi_emit_rssi_changed((Wifi *)get_wifi_object(),
interface_name, VCONFKEY_WIFI_STRENGTH_MAX);
- netconfig_start_timer_seconds(WIFI_INDICATOR_INTERVAL,
- __netconfig_wifi_update_statistics, g_strdup(interface_name),
- &netconfig_wifi_statistics_timer);
+ if (netconfig_wifi_statistics_timer == 0) {
+ netconfig_wifi_reset_last_bytes();
+ netconfig_start_timer_seconds(WIFI_INDICATOR_INTERVAL,
+ __netconfig_wifi_update_statistics, g_strdup(interface_name),
+ &netconfig_wifi_statistics_timer);
+ }
netconfig_battery_update_wifi_rssi(VCONFKEY_WIFI_STRENGTH_MAX);
}
void netconfig_wifi_indicator_stop(const char *interface_name)
{
+ int wifi_state = 0;
+ guint64 tx, rx;
+
INFO("Stop Wi-Fi indicator");
- netconfig_stop_timer(&netconfig_wifi_statistics_timer);
+ netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
+
+ if (wifi_state != VCONFKEY_WIFI_CONNECTED) {
+ if (netconfig_wifi_get_bytes_statistics(&tx, &rx, TRUE))
+ netconfig_wifi_set_bytes_pkt_vconf(tx, rx);
+
+ netconfig_stop_timer(&netconfig_wifi_statistics_timer);
+ }
__destroy_rssi_data(interface_name);
}