IPACM: Suppor IPA stats update in ENFORCE mode
Add support in IPACM to update android tethering stats
in Android ENFORCE mode to CNE and Android framework.
Change-Id: I1fd833db63f92f8240b80954b400efbd0d3c9a8b
diff --git a/ipacm/inc/IPACM_Defs.h b/ipacm/inc/IPACM_Defs.h
index ed2eb9b..405de30 100644
--- a/ipacm/inc/IPACM_Defs.h
+++ b/ipacm/inc/IPACM_Defs.h
@@ -55,7 +55,6 @@
#define IPA_MAX_FILE_LEN 64
#define IPA_IFACE_NAME_LEN 16
#define IPA_ALG_PROTOCOL_NAME_LEN 10
-#define MAX_COMMAND_LEN 1024
#define IPA_WLAN_PARTIAL_HDR_OFFSET 0 // dst mac first then src mac
//#define IPA_ETH_PARTIAL_HDR_OFFSET 8 // dst mac first then src mac
diff --git a/ipacm/inc/IPACM_Lan.h b/ipacm/inc/IPACM_Lan.h
index 5031c05..69f76c9 100644
--- a/ipacm/inc/IPACM_Lan.h
+++ b/ipacm/inc/IPACM_Lan.h
@@ -61,7 +61,7 @@
/* ndc bandwidth ipatetherstats <ifaceIn> <ifaceOut> */
/* <in->out_bytes> <in->out_pkts> <out->in_bytes> <out->in_pkts */
-#define PIPE_STATS "echo %s %s %lu %lu %lu %lu > %s"
+#define PIPE_STATS "%s %s %lu %lu %lu %lu"
#define IPA_PIPE_STATS_FILE_NAME "/data/misc/ipa/tether_stats"
/* store each lan-iface unicast routing rule and its handler*/
diff --git a/ipacm/inc/IPACM_Wan.h b/ipacm/inc/IPACM_Wan.h
index 1452edb..159cc46 100644
--- a/ipacm/inc/IPACM_Wan.h
+++ b/ipacm/inc/IPACM_Wan.h
@@ -58,7 +58,7 @@
#define IPA_V2_NUM_DEFAULT_WAN_FILTER_RULE_IPV6 3
#endif
-#define NETWORK_STATS "echo %s %lu %lu %lu %lu > %s"
+#define NETWORK_STATS "%s %lu %lu %lu %lu"
#define IPA_NETWORK_STATS_FILE_NAME "/data/misc/ipa/network_stats"
typedef struct _wan_client_rt_hdl
diff --git a/ipacm/src/IPACM_Lan.cpp b/ipacm/src/IPACM_Lan.cpp
index e108d15..67eec43 100644
--- a/ipacm/src/IPACM_Lan.cpp
+++ b/ipacm/src/IPACM_Lan.cpp
@@ -6774,7 +6774,8 @@
uint64_t num_ul_packets, num_ul_bytes;
uint64_t num_dl_packets, num_dl_bytes;
bool ul_pipe_found, dl_pipe_found;
- char command[MAX_COMMAND_LEN];
+ FILE *fp = NULL;
+
fd = open(IPA_DEVICE_NAME, O_RDWR);
if (fd < 0)
{
@@ -6843,6 +6844,7 @@
}
}
}
+ close(fd);
if (ul_pipe_found || dl_pipe_found)
{
@@ -6853,17 +6855,22 @@
num_dl_bytes,
dev_name,
IPACM_Wan::wan_up_dev_name);
- memset(command, 0, sizeof(command));
- snprintf(command, sizeof(command), PIPE_STATS,
+ fp = fopen(IPA_PIPE_STATS_FILE_NAME, "w");
+ if ( fp == NULL )
+ {
+ IPACMERR("Failed to write pipe stats to %s, error is %d - %s\n",
+ IPA_PIPE_STATS_FILE_NAME, errno, strerror(errno));
+ return IPACM_FAILURE;
+ }
+
+ fprintf(fp, PIPE_STATS,
dev_name,
IPACM_Wan::wan_up_dev_name,
num_ul_bytes,
num_ul_packets,
num_dl_bytes,
- num_dl_packets,
- IPA_PIPE_STATS_FILE_NAME);
- system(command);
+ num_dl_packets);
+ fclose(fp);
}
- close(fd);
return IPACM_SUCCESS;
}
diff --git a/ipacm/src/IPACM_Wan.cpp b/ipacm/src/IPACM_Wan.cpp
index e2ed53e..5294972 100644
--- a/ipacm/src/IPACM_Wan.cpp
+++ b/ipacm/src/IPACM_Wan.cpp
@@ -5504,7 +5504,8 @@
/*handle eth client */
int IPACM_Wan::handle_network_stats_update(ipa_get_apn_data_stats_resp_msg_v01 *data)
{
- char command[MAX_COMMAND_LEN];
+ FILE *fp = NULL;
+
for (int apn_index =0; apn_index < data->apn_data_stats_list_len; apn_index++)
{
if(data->apn_data_stats_list[apn_index].mux_id == ext_prop->ext[0].mux_id)
@@ -5515,15 +5516,21 @@
data->apn_data_stats_list[apn_index].num_ul_bytes,
data->apn_data_stats_list[apn_index].num_dl_packets,
data->apn_data_stats_list[apn_index].num_dl_bytes);
- memset(command, 0, sizeof(command));
- snprintf(command, sizeof(command), NETWORK_STATS,
+ fp = fopen(IPA_NETWORK_STATS_FILE_NAME, "w");
+ if ( fp == NULL )
+ {
+ IPACMERR("Failed to write pipe stats to %s, error is %d - %s\n",
+ IPA_NETWORK_STATS_FILE_NAME, errno, strerror(errno));
+ return IPACM_FAILURE;
+ }
+
+ fprintf(fp, NETWORK_STATS,
dev_name,
data->apn_data_stats_list[apn_index].num_ul_packets,
data->apn_data_stats_list[apn_index].num_ul_bytes,
data->apn_data_stats_list[apn_index].num_dl_packets,
- data->apn_data_stats_list[apn_index].num_dl_bytes,
- IPA_NETWORK_STATS_FILE_NAME);
- system(command);
+ data->apn_data_stats_list[apn_index].num_dl_bytes);
+ fclose(fp);
break;
};
}