#include "generated-code.h"
#define NETCONFIG_PROCDEV "/proc/net/dev"
+#define WIFI_VCONF_UPDATE_INTERVAL 3600
+static struct {
+ guint64 tx_diff;
+ guint64 rx_diff;
+ guint64 last_tx_offset;
+ guint64 last_rx_offset;
+} stat_count;
+
+static guint wifi_vconf_update_timer = 0;
static Network_statistics *netconfigstatistics = NULL;
static wifi_device_data_s *__find_wifi_interface_name(const char *interface_name)
*rx = device_data->rx_diff;
}
-void netconfig_wifi_set_bytes_pkt_vconf(guint64 tx_diff, guint64 rx_diff)
+void netconfig_wifi_set_bytes_pkt_vconf(guint64 tx_diff, guint64 rx_diff, gboolean update)
{
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;
+ stat_count.tx_diff += tx_diff;
+ stat_count.rx_diff += rx_diff;
- netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, &val);
- last_rx = (guint64)val + rx_diff;
+ if (update) {
+ /* LAST */
+ netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, &val);
+ last_tx = (guint64)val + stat_count.tx_diff - stat_count.last_tx_offset;
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, (int)last_tx, FALSE);
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, (int)last_rx, FALSE);
+ netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, &val);
+ last_rx = (guint64)val + stat_count.rx_diff - stat_count.last_rx_offset;
- /* TOTAL */
- netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, &val);
- total_tx = (guint64)val + tx_diff;
+ netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, (int)last_tx, FALSE);
+ netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, (int)last_rx, FALSE);
- netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, &val);
- total_rx = (guint64)val + rx_diff;
+ stat_count.last_tx_offset = 0;
+ stat_count.last_rx_offset = 0;
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, (int)total_tx, FALSE);
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, (int)total_rx, FALSE);
+ /* TOTAL */
+ netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, &val);
+ total_tx = (guint64)val + stat_count.tx_diff;
+
+ netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, &val);
+ total_rx = (guint64)val + stat_count.rx_diff;
+
+ netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, (int)total_tx, FALSE);
+ netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, (int)total_rx, FALSE);
+
+ stat_count.rx_diff = 0;
+ stat_count.tx_diff = 0;
+ }
}
void netconfig_wifi_reset_last_bytes(void)
{
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, 0, FALSE);
- netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, 0, FALSE);
+ int val = 0;
+
+ netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, &val);
+ stat_count.last_tx_offset = (guint64)val + stat_count.tx_diff;
+
+ netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, &val);
+ stat_count.last_rx_offset = (guint64)val + stat_count.rx_diff;
}
static gboolean handle_get_wifi_total_tx_bytes(
netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, &val);
- tx_bytes = (guint64)val;
+ tx_bytes = (guint64)val + stat_count.tx_diff;
if (wifi_state != VCONFKEY_WIFI_CONNECTED) {
total_bytes = tx_bytes;
return TRUE;
}
- if (netconfig_wifi_get_bytes_statistics(&tx, &rx, FALSE) == TRUE)
+ if (netconfig_wifi_get_bytes_statistics(&tx, &rx, FALSE) == TRUE) {
total_bytes = tx + tx_bytes;
- else
+ stat_count.tx_diff += tx;
+ stat_count.rx_diff += rx;
+ } else {
total_bytes = tx_bytes;
+ }
network_statistics_complete_get_wifi_total_tx_bytes(object, context, total_bytes);
return TRUE;
netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, &val);
- rx_bytes = (guint64)val;
+ rx_bytes = (guint64)val + stat_count.rx_diff;
if (wifi_state != VCONFKEY_WIFI_CONNECTED) {
total_bytes = rx_bytes;
return TRUE;
}
- if (netconfig_wifi_get_bytes_statistics(&tx, &rx, FALSE) == TRUE)
+ if (netconfig_wifi_get_bytes_statistics(&tx, &rx, FALSE) == TRUE) {
total_bytes = rx + rx_bytes;
- else
+ stat_count.tx_diff += tx;
+ stat_count.rx_diff += rx;
+ } else {
total_bytes = rx_bytes;
+ }
network_statistics_complete_get_wifi_total_rx_bytes(object, context, total_bytes);
return TRUE;
netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, &val);
- tx_bytes = (guint64)val;
+ tx_bytes = (guint64)val + stat_count.tx_diff - stat_count.last_tx_offset;
if (wifi_state != VCONFKEY_WIFI_CONNECTED) {
last_bytes = tx_bytes;
return TRUE;
}
- if (netconfig_wifi_get_bytes_statistics(&tx, &rx, FALSE) == TRUE)
+ if (netconfig_wifi_get_bytes_statistics(&tx, &rx, FALSE) == TRUE) {
last_bytes = tx + tx_bytes;
- else
+ stat_count.tx_diff += tx;
+ stat_count.rx_diff += rx;
+ } else {
last_bytes = tx_bytes;
+ }
network_statistics_complete_get_wifi_last_tx_bytes(object, context, last_bytes);
return TRUE;
netconfig_vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state);
netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, &val);
- rx_bytes = (guint64)val;
+ rx_bytes = (guint64)val + stat_count.rx_diff - stat_count.last_rx_offset;
if (wifi_state != VCONFKEY_WIFI_CONNECTED) {
last_bytes = rx_bytes;
return TRUE;
}
- if (netconfig_wifi_get_bytes_statistics(&tx, &rx, FALSE) == TRUE)
+ if (netconfig_wifi_get_bytes_statistics(&tx, &rx, FALSE) == TRUE) {
last_bytes = rx + rx_bytes;
- else
+ stat_count.tx_diff += tx;
+ stat_count.rx_diff += rx;
+ } else {
last_bytes = rx_bytes;
+ }
network_statistics_complete_get_wifi_last_rx_bytes(object, context, last_bytes);
return TRUE;
Network_statistics *object,
GDBusMethodInvocation *context)
{
+ int val = 0;
+ guint64 last_tx = 0;
+
+ netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, &val);
+ last_tx = (guint64)val + stat_count.tx_diff - stat_count.last_tx_offset;
+
+ netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, (int)last_tx, FALSE);
+ stat_count.last_tx_offset = 0;
+ stat_count.tx_diff = 0;
+
netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, 0, TRUE);
network_statistics_complete_reset_wifi_total_tx_bytes(object, context);
return TRUE;
Network_statistics *object,
GDBusMethodInvocation *context)
{
+ int val = 0;
+ guint64 last_rx = 0;
+
+ netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, &val);
+ last_rx = (guint64)val + stat_count.rx_diff - stat_count.last_rx_offset;
+
+ netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, (int)last_rx, FALSE);
+ stat_count.last_rx_offset = 0;
+ stat_count.rx_diff = 0;
+
netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, 0, TRUE);
network_statistics_complete_reset_wifi_total_rx_bytes(object, context);
return TRUE;
Network_statistics *object,
GDBusMethodInvocation *context)
{
+ int val = 0;
+ guint64 total_tx = 0;
+
+ netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, &val);
+ total_tx = (guint64)val + stat_count.tx_diff;
+
+ netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, (int)total_tx, FALSE);
+ stat_count.tx_diff = 0;
+
netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, 0, TRUE);
+ stat_count.last_tx_offset = 0;
network_statistics_complete_reset_wifi_last_tx_bytes(object, context);
return TRUE;
}
Network_statistics *object,
GDBusMethodInvocation *context)
{
+ int val = 0;
+ guint64 total_rx = 0;
+
+ netconfig_vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, &val);
+ total_rx = (guint64)val + stat_count.rx_diff;
+
+ netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, (int)total_rx, FALSE);
+ stat_count.rx_diff = 0;
+
netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, 0, TRUE);
+ stat_count.last_rx_offset = 0;
network_statistics_complete_reset_wifi_last_rx_bytes(object, context);
return TRUE;
}
netconfig_wifi_get_bytes_statistics(&tx, &rx, TRUE);
}
+static gboolean __statistics_update_wifi_vconf(gpointer data)
+{
+ if (stat_count.tx_diff ||
+ stat_count.rx_diff ||
+ stat_count.last_tx_offset ||
+ stat_count.last_rx_offset)
+ netconfig_wifi_set_bytes_pkt_vconf(0, 0, TRUE);
+
+ return TRUE;
+}
+
void statistics_object_create_and_init(void)
{
DBG("Creating statistics object");
}
wifi_statistics_update_state();
+ netconfig_start_timer_seconds(WIFI_VCONF_UPDATE_INTERVAL,
+ __statistics_update_wifi_vconf, NULL, &wifi_vconf_update_timer);
return;
}
void statistics_object_deinit(void)
{
+ netconfig_wifi_set_bytes_pkt_vconf(0, 0, TRUE);
+ netconfig_stop_timer(&wifi_vconf_update_timer);
g_object_unref(netconfigstatistics);
}