diff --git a/include/zephyr/net/net_stats.h b/include/zephyr/net/net_stats.h index 5a2ac84eaa2..17ca3638889 100644 --- a/include/zephyr/net/net_stats.h +++ b/include/zephyr/net/net_stats.h @@ -648,6 +648,7 @@ enum net_request_stats_cmd { NET_REQUEST_STATS_CMD_GET_PPP, NET_REQUEST_STATS_CMD_GET_PM, NET_REQUEST_STATS_CMD_GET_WIFI, + NET_REQUEST_STATS_CMD_RESET_WIFI, }; /** @endcond */ @@ -777,6 +778,14 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_PM); /** @cond INTERNAL_HIDDEN */ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_WIFI); /** @endcond */ + +/** Reset Wi-Fi statistics*/ +#define NET_REQUEST_STATS_RESET_WIFI \ + (_NET_STATS_BASE | NET_REQUEST_STATS_CMD_RESET_WIFI) + +/** @cond INTERNAL_HIDDEN */ +NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_RESET_WIFI); +/** @endcond */ #endif /* CONFIG_NET_STATISTICS_WIFI */ /** diff --git a/include/zephyr/net/wifi_mgmt.h b/include/zephyr/net/wifi_mgmt.h index 616541776e0..deab64cc756 100644 --- a/include/zephyr/net/wifi_mgmt.h +++ b/include/zephyr/net/wifi_mgmt.h @@ -863,6 +863,13 @@ struct wifi_mgmt_ops { * @return 0 if ok, < 0 if error */ int (*get_stats)(const struct device *dev, struct net_stats_wifi *stats); + /** Reset Wi-Fi statistics + * + * @param dev Pointer to the device structure for the driver instance. + * + * @return 0 if ok, < 0 if error + */ + int (*reset_stats)(const struct device *dev); #endif /* CONFIG_NET_STATISTICS_WIFI */ /** Set power save status * diff --git a/subsys/net/l2/wifi/wifi_mgmt.c b/subsys/net/l2/wifi/wifi_mgmt.c index c329db7f8f3..a3072db97f1 100644 --- a/subsys/net/l2/wifi/wifi_mgmt.c +++ b/subsys/net/l2/wifi/wifi_mgmt.c @@ -515,6 +515,20 @@ static int wifi_iface_stats(uint32_t mgmt_request, struct net_if *iface, return wifi_mgmt_api->get_stats(dev, stats); } NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_STATS_GET_WIFI, wifi_iface_stats); + +static int wifi_iface_stats_reset(uint32_t mgmt_request, struct net_if *iface, + void *data, size_t len) +{ + const struct device *dev = net_if_get_device(iface); + const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface); + + if (wifi_mgmt_api == NULL || wifi_mgmt_api->reset_stats == NULL) { + return -ENOTSUP; + } + + return wifi_mgmt_api->reset_stats(dev); +} +NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_STATS_RESET_WIFI, wifi_iface_stats_reset); #endif /* CONFIG_NET_STATISTICS_WIFI */ static int wifi_set_power_save(uint32_t mgmt_request, struct net_if *iface,