ipacm: Add support for DataWarning limit
Make changes to add support for DataWarning limit along
with Quota limit.
Change-Id: Ie80fc44d28711a6724621a1e8925a2522758b9f2
diff --git a/ipacm/Android.bp b/ipacm/Android.bp
index c6ed74b..8302634 100644
--- a/ipacm/Android.bp
+++ b/ipacm/Android.bp
@@ -57,6 +57,7 @@
"libhardware",
"android.hardware.tetheroffload.config@1.0",
"android.hardware.tetheroffload.control@1.0",
+ "android.hardware.tetheroffload.control@1.1",
],
}
diff --git a/ipacm/inc/IPACM_OffloadManager.h b/ipacm/inc/IPACM_OffloadManager.h
index 8ac904f..146fde8 100644
--- a/ipacm/inc/IPACM_OffloadManager.h
+++ b/ipacm/inc/IPACM_OffloadManager.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -83,8 +83,10 @@
/* ------------------------- STATS/POLICY --------------------------- */
virtual RET setQuota(const char * /* upstream */, uint64_t /* limit */);
+ virtual RET setQuotaWarning(const char * /* upstream */,
+ uint64_t /* quota limit */, uint64_t /* warning limit */);
virtual RET getStats(const char * /* upstream */, bool /* reset */,
- OffloadStatistics& /* ret */);
+ OffloadStatistics& /* ret */);
static IPACM_OffloadManager *pInstance;
diff --git a/ipacm/src/IPACM_Main.cpp b/ipacm/src/IPACM_Main.cpp
index 6bd117e..d8615cc 100644
--- a/ipacm/src/IPACM_Main.cpp
+++ b/ipacm/src/IPACM_Main.cpp
@@ -1,5 +1,5 @@
/*
-Copyright (c) 2013-2019, The Linux Foundation. All rights reserved.
+Copyright (c) 2013-2021, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
@@ -754,6 +754,18 @@
OffloadMng->elrInstance->onLimitReached();
}
continue;
+#ifdef IPA_WARNING_LIMIT_EVENT_MAX
+ case IPA_WARNING_LIMIT_REACHED:
+ IPACMDBG_H("Received IPA_WARNING_LIMIT_REACHED\n");
+ OffloadMng = IPACM_OffloadManager::GetInstance();
+ if (OffloadMng->elrInstance == NULL) {
+ IPACMERR("OffloadMng->elrInstance is NULL, can't forward to framework!\n");
+ } else {
+ IPACMERR("calling OffloadMng->elrInstance->onWarningReached \n");
+ OffloadMng->elrInstance->onWarningReached();
+ }
+ continue;
+#endif
case IPA_SSR_BEFORE_SHUTDOWN:
IPACMDBG_H("Received IPA_SSR_BEFORE_SHUTDOWN\n");
IPACM_Wan::clearExtProp();
diff --git a/ipacm/src/IPACM_OffloadManager.cpp b/ipacm/src/IPACM_OffloadManager.cpp
index 708725b..2b8012d 100644
--- a/ipacm/src/IPACM_OffloadManager.cpp
+++ b/ipacm/src/IPACM_OffloadManager.cpp
@@ -1,5 +1,5 @@
/*
-Copyright (c) 2017-2019, The Linux Foundation. All rights reserved.
+Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
@@ -651,6 +651,63 @@
return SUCCESS;
}
+RET IPACM_OffloadManager::setQuotaWarning(const char * upstream_name /* upstream */,
+uint64_t quota_mb/* quota limit */, uint64_t warning_mb/* warning limit */)
+{
+#ifdef WAN_IOC_SET_DATA_QUOTA_WARNING
+ wan_ioctl_set_data_quota_warning ioctl_data;
+ int fd = -1, rc = 0, err_type = 0;
+
+ if ((fd = open(DEVICE_NAME, O_RDWR)) < 0)
+ {
+ IPACMERR("Failed opening %s.\n", DEVICE_NAME);
+ return FAIL_HARDWARE;
+ }
+
+ memset(&ioctl_data, 0, sizeof(ioctl_data));
+
+ if (quota_mb != 0)
+ {
+ ioctl_data.quota_mbytes = quota_mb;
+ ioctl_data.set_quota = true;
+ }
+
+ if (warning_mb != 0)
+ {
+ ioctl_data.warning_mbytes = warning_mb;
+ ioctl_data.set_warning = true;
+ }
+
+
+ if (strlcpy(ioctl_data.interface_name, upstream_name, IFNAMSIZ) >= IFNAMSIZ) {
+ IPACMERR("String truncation occurred on upstream");
+ close(fd);
+ return FAIL_INPUT_CHECK;
+ }
+
+ IPACMDBG_H("SET_DATA_QUOTA_WARNING: Dev: %s, Quota: %llu, Warning: %llu\n",
+ ioctl_data.interface_name, (long long)quota_mb,
+ (long long)warning_mb);
+
+ rc = ioctl(fd, WAN_IOC_SET_DATA_QUOTA_WARNING, &ioctl_data);
+ close(fd);
+ if(rc != 0)
+ {
+ err_type = errno;
+ IPACMERR("IOCTL WAN_IOC_SET_DATA_QUOTA_WARNING call failed: %s err_type: %d\n", strerror(err_type), err_type);
+ if (err_type == ENODEV) {
+ IPACMDBG_H("Invalid argument.\n");
+ return FAIL_UNSUPPORTED;
+ }
+ else {
+ return FAIL_TRY_AGAIN;
+ }
+ }
+#endif
+ return SUCCESS;
+}
+
+
RET IPACM_OffloadManager::getStats(const char * upstream_name /* upstream */,
bool reset /* reset */, OffloadStatistics& offload_stats/* ret */)
{