Tethering: Add data usage feature 64/5664/1
authorLiu, Guoqiang <guoqiangx.liu@intel.com>
Mon, 25 Mar 2013 09:25:14 +0000 (17:25 +0800)
committerZhang zhengguang <zhengguang.zhang@intel.com>
Fri, 12 Jul 2013 00:55:18 +0000 (08:55 +0800)
Signed-off-by: Liu, Guoqiang <guoqiangx.liu@intel.com>
include/mobileap_agent.h
src/mobileap_agent.c
src/mobileap_main.c

index f619316..2cc43f0 100644 (file)
@@ -54,6 +54,8 @@
 #define USB_IF                 "usb0"
 #define IP_ADDRESS_USB         0xC0A88103      /* 192.168.129.3 */
 
+#define TETHER_IF              "tether"
+
 #define BT_IF_PREFIX           "bnep"
 #define BT_IF_ALL              BT_IF_PREFIX"+"
 #define IP_ADDRESS_BT_1                0xC0A88201      /* 192.168.130.1 */
index 0b29a75..6fd898d 100644 (file)
@@ -884,32 +884,7 @@ int _mh_core_enable_masquerade(const char *ext_if)
                return MOBILE_AP_ERROR_INVALID_PARAM;
        }
 
-       int fd = -1;
-       char cmd[MAX_BUF_SIZE] = {0, };
-
-       fd = open(IP_FORWARD, O_WRONLY);
-       if (fd < 0) {
-               ERR("open failed\n");
-               return MOBILE_AP_ERROR_RESOURCE;
-       }
-
-       if (write(fd, "1", 1) != 1) {
-               ERR("write failed\n");
-               close(fd);
-               return MOBILE_AP_ERROR_INTERNAL;
-       }
-       close(fd);
-
-       snprintf(cmd, sizeof(cmd), "%s -t nat -A POSTROUTING "MASQUERADE_RULE,
-                       IPTABLES, ext_if);
-       if (_execute_command(cmd)) {
-               ERR("iptables failed : %s\n", cmd);
-               return MOBILE_AP_ERROR_INTERNAL;
-       }
-
-       _add_data_usage_rule(WIFI_IF, ext_if);
-       _add_data_usage_rule(BT_IF_ALL, ext_if);
-       _add_data_usage_rule(USB_IF, ext_if);
+       _add_data_usage_rule(TETHER_IF, ext_if);
 
        return MOBILE_AP_ERROR_NONE;
 }
@@ -921,32 +896,7 @@ int _mh_core_disable_masquerade(const char *ext_if)
                return MOBILE_AP_ERROR_INVALID_PARAM;
        }
 
-       int fd = -1;
-       char cmd[MAX_BUF_SIZE] = {0, };
-
-       fd = open(IP_FORWARD, O_WRONLY);
-       if (fd < 0) {
-               ERR("open failed\n");
-               return MOBILE_AP_ERROR_RESOURCE;
-       }
-
-       if (write(fd, "0", 1) != 1) {
-               ERR("write failed\n");
-               close(fd);
-               return MOBILE_AP_ERROR_INTERNAL;
-       }
-       close(fd);
-
-       snprintf(cmd, sizeof(cmd), "%s -t nat -D POSTROUTING "MASQUERADE_RULE,
-                       IPTABLES, ext_if);
-       if (_execute_command(cmd)) {
-               ERR("iptables failed : %s\n", cmd);
-               return MOBILE_AP_ERROR_INTERNAL;
-       }
-
-       _del_data_usage_rule(WIFI_IF, ext_if);
-       _del_data_usage_rule(BT_IF_ALL, ext_if);
-       _del_data_usage_rule(USB_IF, ext_if);
+       _del_data_usage_rule(TETHER_IF, ext_if);
 
        return MOBILE_AP_ERROR_NONE;
 }
index 273454b..ed17c4e 100644 (file)
@@ -345,12 +345,6 @@ gboolean tethering_get_data_packet_usage(TetheringObject *obj,
                                                DBusGMethodInvocation *context)
 {
        char *if_name = NULL;
-       unsigned long long wifi_tx_bytes = 0;
-       unsigned long long wifi_rx_bytes = 0;
-       unsigned long long bt_tx_bytes = 0;
-       unsigned long long bt_rx_bytes = 0;
-       unsigned long long usb_tx_bytes = 0;
-       unsigned long long usb_rx_bytes = 0;
        unsigned long long tx_bytes = 0;
        unsigned long long rx_bytes = 0;
 
@@ -361,22 +355,11 @@ gboolean tethering_get_data_packet_usage(TetheringObject *obj,
                return FALSE;
        }
 
-       if (_mobileap_is_enabled(MOBILE_AP_STATE_WIFI))
-               _get_data_usage(WIFI_IF, if_name,
-                               &wifi_tx_bytes, &wifi_rx_bytes);
-
-       if (_mobileap_is_enabled(MOBILE_AP_STATE_BT))
-               _get_data_usage(BT_IF_ALL, if_name,
-                               &bt_tx_bytes, &bt_rx_bytes);
-
-       if (_mobileap_is_enabled(MOBILE_AP_STATE_USB))
-               _get_data_usage(USB_IF, if_name,
-                               &usb_tx_bytes, &usb_rx_bytes);
+       if (!_mobileap_is_disabled())
+               _get_data_usage(TETHER_IF, if_name,
+                               &tx_bytes, &rx_bytes);
        free(if_name);
 
-       tx_bytes = wifi_tx_bytes + bt_tx_bytes + usb_tx_bytes;
-       rx_bytes = wifi_rx_bytes + bt_rx_bytes + usb_rx_bytes;
-
        dbus_g_method_return(context, MOBILE_AP_GET_DATA_PACKET_USAGE_CFM,
                        tx_bytes, rx_bytes);