The branch main has been updated by adrian:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=0861daf511dc9a573d71f5c3c1d0233745a8712b

commit 0861daf511dc9a573d71f5c3c1d0233745a8712b
Author:     Adrian Chadd <adr...@freebsd.org>
AuthorDate: 2025-05-31 18:51:21 +0000
Commit:     Adrian Chadd <adr...@freebsd.org>
CommitDate: 2025-06-04 03:33:33 +0000

    net80211: create net80211_vap_printf() / net80211_ic_printf() for printing
    
    Not all OSes support if_printf(), printf(), etc, so start migrating
    the printf / log routines into net80211 routines that are implemented
    in ieee80211_freebsd.c .
    
    Migrate ic_printf() to net80211_ic_printf() via a macro for testing.
    
    Differential Revision:  https://reviews.freebsd.org/D50642
    Reviewed by:    bz
---
 sys/net80211/ieee80211.c         | 13 ----------
 sys/net80211/ieee80211_freebsd.c | 52 ++++++++++++++++++++++++++++++++++++++--
 sys/net80211/ieee80211_freebsd.h |  6 +++++
 sys/net80211/ieee80211_var.h     |  4 +++-
 4 files changed, 59 insertions(+), 16 deletions(-)

diff --git a/sys/net80211/ieee80211.c b/sys/net80211/ieee80211.c
index e4de0b439ac0..74fdaa033952 100644
--- a/sys/net80211/ieee80211.c
+++ b/sys/net80211/ieee80211.c
@@ -273,19 +273,6 @@ null_update_chw(struct ieee80211com *ic)
        ic_printf(ic, "%s: need callback\n", __func__);
 }
 
-int
-ic_printf(struct ieee80211com *ic, const char * fmt, ...)
-{
-       va_list ap;
-       int retval;
-
-       retval = printf("%s: ", ic->ic_name);
-       va_start(ap, fmt);
-       retval += vprintf(fmt, ap);
-       va_end(ap);
-       return (retval);
-}
-
 static LIST_HEAD(, ieee80211com) ic_head = LIST_HEAD_INITIALIZER(ic_head);
 static struct mtx ic_list_mtx;
 MTX_SYSINIT(ic_list, &ic_list_mtx, "ieee80211com list", MTX_DEF);
diff --git a/sys/net80211/ieee80211_freebsd.c b/sys/net80211/ieee80211_freebsd.c
index 5c7ebd7c727c..b5ab79a4ad16 100644
--- a/sys/net80211/ieee80211_freebsd.c
+++ b/sys/net80211/ieee80211_freebsd.c
@@ -42,6 +42,7 @@
 #include <sys/priv.h>
 #include <sys/proc.h>
 #include <sys/sysctl.h>
+#include <sys/syslog.h>
 
 #include <sys/socket.h>
 
@@ -58,6 +59,8 @@
 #include <net/route.h>
 #include <net/vnet.h>
 
+#include <machine/stdarg.h>
+
 #include <net80211/ieee80211_var.h>
 #include <net80211/ieee80211_input.h>
 
@@ -275,8 +278,8 @@ ieee80211_sysctl_vattach(struct ieee80211vap *vap)
        ctx = (struct sysctl_ctx_list *) IEEE80211_MALLOC(sizeof(struct 
sysctl_ctx_list),
                M_DEVBUF, IEEE80211_M_NOWAIT | IEEE80211_M_ZERO);
        if (ctx == NULL) {
-               if_printf(ifp, "%s: cannot allocate sysctl context!\n",
-                       __func__);
+               net80211_vap_printf(vap,
+                   "%s: cannot allocate sysctl context!\n", __func__);
                return;
        }
        sysctl_ctx_init(ctx);
@@ -1326,6 +1329,51 @@ ieee80211_vap_get_broadcast_address(struct ieee80211vap 
*vap)
        return (if_getbroadcastaddr(vap->iv_ifp));
 }
 
+/**
+ * @brief net80211 printf() (not vap/ic related)
+ */
+void
+net80211_printf(const char *fmt, ...)
+{
+       va_list ap;
+
+       va_start(ap, fmt);
+       vprintf(fmt, ap);
+       va_end(ap);
+}
+
+/**
+ * @brief VAP specific printf()
+ */
+void
+net80211_vap_printf(const struct ieee80211vap *vap, const char *fmt, ...)
+{
+       char if_fmt[256];
+       va_list ap;
+
+       va_start(ap, fmt);
+       snprintf(if_fmt, sizeof(if_fmt), "%s: %s", if_name(vap->iv_ifp), fmt);
+       vlog(LOG_INFO, if_fmt, ap);
+       va_end(ap);
+}
+
+/**
+ * @brief ic specific printf()
+ */
+void
+net80211_ic_printf(const struct ieee80211com *ic, const char *fmt, ...)
+{
+       va_list ap;
+
+       /*
+        * TODO: do the vap_printf stuff above, use vlog(LOG_INFO, ...)
+        */
+       printf("%s: ", ic->ic_name);
+       va_start(ap, fmt);
+       vprintf(fmt, ap);
+       va_end(ap);
+}
+
 /*
  * Module glue.
  *
diff --git a/sys/net80211/ieee80211_freebsd.h b/sys/net80211/ieee80211_freebsd.h
index 5afc093ba90c..141b13f9f740 100644
--- a/sys/net80211/ieee80211_freebsd.h
+++ b/sys/net80211/ieee80211_freebsd.h
@@ -549,6 +549,12 @@ bool ieee80211_vap_ifp_check_is_running(struct 
ieee80211vap *);
 void ieee80211_vap_ifp_set_running_state(struct ieee80211vap *, bool);
 const uint8_t * ieee80211_vap_get_broadcast_address(struct ieee80211vap *);
 
+void   net80211_printf(const char *fmt, ...) __printflike(1, 2);
+void   net80211_vap_printf(const struct ieee80211vap *, const char *fmt, ...)
+           __printflike(2, 3);
+void   net80211_ic_printf(const struct ieee80211com *, const char *fmt, ...)
+           __printflike(2, 3);
+
 #endif /* _KERNEL */
 
 /* XXX this stuff belongs elsewhere */
diff --git a/sys/net80211/ieee80211_var.h b/sys/net80211/ieee80211_var.h
index 91beaec6f997..a0293f814899 100644
--- a/sys/net80211/ieee80211_var.h
+++ b/sys/net80211/ieee80211_var.h
@@ -765,7 +765,9 @@ MALLOC_DECLARE(M_80211_VAP);
 #define        IEEE80211_COM_REF_S     1
 #define        IEEE80211_COM_REF_MAX   (IEEE80211_COM_REF >> 
IEEE80211_COM_REF_S)
 
-int    ic_printf(struct ieee80211com *, const char *, ...) __printflike(2, 3);
+/* TODO: Transition macro */
+#define        ic_printf       net80211_ic_printf
+
 void   ieee80211_ifattach(struct ieee80211com *);
 void   ieee80211_ifdetach(struct ieee80211com *);
 void   ieee80211_set_software_ciphers(struct ieee80211com *,

Reply via email to