From eb0843aa481264e5a0e9cd95018702c8ec10f0e2 Mon Sep 17 00:00:00 2001
From: Johan Peeters <johan.peeters@airties.com>
Date: Mon, 7 Oct 2024 12:54:44 +0200
Subject: [PATCH] Add unicast and multicast stats for wifi stations

---
 docs/api/wifi.ap.md       | 112 ++++++++++++++++++++++++++++++++++++++
 schemas/ubus/wifi.ap.json |  32 +++++++++++
 wifimngr.c                |  12 ++++
 3 files changed, 156 insertions(+)

diff --git a/docs/api/wifi.ap.md b/docs/api/wifi.ap.md
index fa81140..15c81ba 100644
--- a/docs/api/wifi.ap.md
+++ b/docs/api/wifi.ap.md
@@ -2188,6 +2188,14 @@ All items must be of the type: `integer`
 | `tx_pkts_retries`     | integer | **Required** |
 | `tx_total_bytes`      | integer | **Required** |
 | `tx_total_pkts`       | integer | **Required** |
+| `tx_ucast_pkts`       | integer | **Required** |
+| `tx_ucast_bytes`      | integer | **Required** |
+| `tx_mcast_pkts`       | integer | **Required** |
+| `tx_mcast_bytes`      | integer | **Required** |
+| `rx_ucast_pkts`       | integer | **Required** |
+| `rx_ucast_bytes`      | integer | **Required** |
+| `rx_mcast_pkts`       | integer | **Required** |
+| `rx_mcast_bytes`      | integer | **Required** |
 
 #### rate_of_last_rx_pkt
 
@@ -2306,6 +2314,110 @@ All items must be of the type: `integer`
 
 - minimum value: `0`
 
+#### tx_ucast_pkts
+
+`tx_ucast_pkts`
+
+- is **required**
+- type: reference
+
+##### tx_ucast_pkts Type
+
+`integer`
+
+- minimum value: `0`
+
+#### tx_ucast_bytes
+
+`tx_ucast_bytes`
+
+- is **required**
+- type: reference
+
+##### tx_ucast_bytes Type
+
+`integer`
+
+- minimum value: `0`
+
+#### tx_mcast_pkts
+
+`tx_mcast_pkts`
+
+- is **required**
+- type: reference
+
+##### tx_mcast_pkts Type
+
+`integer`
+
+- minimum value: `0`
+
+#### tx_mcast_bytes
+
+`tx_mcast_bytes`
+
+- is **required**
+- type: reference
+
+##### tx_mcast_bytes Type
+
+`integer`
+
+- minimum value: `0`
+
+#### rx_ucast_pkts
+
+`rx_ucast_pkts`
+
+- is **required**
+- type: reference
+
+##### rx_ucast_pkts Type
+
+`integer`
+
+- minimum value: `0`
+
+#### rx_ucast_bytes
+
+`rx_ucast_bytes`
+
+- is **required**
+- type: reference
+
+##### rx_ucast_bytes Type
+
+`integer`
+
+- minimum value: `0`
+
+#### rx_mcast_pkts
+
+`rx_mcast_pkts`
+
+- is **required**
+- type: reference
+
+##### rx_mcast_pkts Type
+
+`integer`
+
+- minimum value: `0`
+
+#### rx_mcast_bytes
+
+`rx_mcast_bytes`
+
+- is **required**
+- type: reference
+
+##### rx_mcast_bytes Type
+
+`integer`
+
+- minimum value: `0`
+
 #### status
 
 `status`
diff --git a/schemas/ubus/wifi.ap.json b/schemas/ubus/wifi.ap.json
index 19b960d..8f03943 100644
--- a/schemas/ubus/wifi.ap.json
+++ b/schemas/ubus/wifi.ap.json
@@ -1172,9 +1172,17 @@
                                             "tx_total_bytes",
                                             "tx_failures",
                                             "tx_pkts_retries",
+                                            "tx_ucast_pkts",
+                                            "tx_ucast_bytes",
+                                            "tx_mcast_pkts",
+                                            "tx_mcast_bytes",
                                             "rx_data_pkts",
                                             "rx_data_bytes",
                                             "rx_failures",
+                                            "rx_ucast_pkts",
+                                            "rx_ucast_bytes",
+                                            "rx_mcast_pkts",
+                                            "rx_mcast_bytes",
                                             "tx_rate_latest",
                                             "rx_rate_latest"
                                         ],
@@ -1191,6 +1199,18 @@
                                             "tx_pkts_retries": {
                                                 "$ref": "#/definitions/rxtx_t"
                                             },
+                                            "tx_ucast_pkts": {
+                                                "$ref": "#/definitions/rxtx_t"
+                                            },
+                                            "tx_ucast_bytes": {
+                                                "$ref": "#/definitions/rxtx_t"
+                                            },
+                                            "tx_mcast_pkts": {
+                                                "$ref": "#/definitions/rxtx_t"
+                                            },
+                                            "tx_mcast_bytes": {
+                                                "$ref": "#/definitions/rxtx_t"
+                                            },
                                             "rx_data_pkts": {
                                                 "$ref": "#/definitions/rxtx_t"
                                             },
@@ -1200,6 +1220,18 @@
                                             "rx_failures": {
                                                 "$ref": "#/definitions/rxtx_t"
                                             },
+                                            "rx_ucast_pkts": {
+                                                "$ref": "#/definitions/rxtx_t"
+                                            },
+                                            "rx_ucast_bytes": {
+                                                "$ref": "#/definitions/rxtx_t"
+                                            },
+                                            "rx_mcast_pkts": {
+                                                "$ref": "#/definitions/rxtx_t"
+                                            },
+                                            "rx_mcast_bytes": {
+                                                "$ref": "#/definitions/rxtx_t"
+                                            },
                                             "tx_rate_latest": {
                                                 "$ref": "#/definitions/rxtx_latest_t"
                                             },
diff --git a/wifimngr.c b/wifimngr.c
index 6d84bdf..e04f642 100644
--- a/wifimngr.c
+++ b/wifimngr.c
@@ -907,9 +907,21 @@ static void wl_print_sta_stats(struct blob_buf *bb, struct wifi_sta_stats *stats
 	blobmsg_add_u64(bb, "tx_total_bytes", stats->tx_bytes);
 	blobmsg_add_u64(bb, "tx_failures", stats->tx_fail_pkts);
 	blobmsg_add_u64(bb, "tx_pkts_retries", stats->tx_retry_pkts);
+
+	blobmsg_add_u64(bb, "tx_ucast_pkts", stats->tx_ucast_pkts);
+	blobmsg_add_u64(bb, "tx_ucast_bytes", stats->tx_ucast_bytes);
+	blobmsg_add_u64(bb, "tx_mcast_pkts", stats->tx_mcast_pkts);
+	blobmsg_add_u64(bb, "tx_mcast_bytes", stats->tx_mcast_bytes);
+
 	blobmsg_add_u64(bb, "rx_data_pkts", stats->rx_pkts);
 	blobmsg_add_u64(bb, "rx_data_bytes", stats->rx_bytes);
 	blobmsg_add_u64(bb, "rx_failures", stats->rx_fail_pkts);
+
+	blobmsg_add_u64(bb, "rx_ucast_pkts", stats->rx_ucast_pkts);
+	blobmsg_add_u64(bb, "rx_ucast_bytes", stats->rx_ucast_bytes);
+	blobmsg_add_u64(bb, "rx_mcast_pkts", stats->rx_mcast_pkts);
+	blobmsg_add_u64(bb, "rx_mcast_bytes", stats->rx_mcast_bytes);
+
 	blobmsg_close_table(bb, t);
 }
 
-- 
GitLab