Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 28 Feb 2016 06:29:25 +0000 (UTC)
From:      Adrian Chadd <adrian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r296153 - head/tools/tools/ath/athstats
Message-ID:  <201602280629.u1S6TP0x004612@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: adrian
Date: Sun Feb 28 06:29:25 2016
New Revision: 296153
URL: https://svnweb.freebsd.org/changeset/base/296153

Log:
  Migrate athstats to use the new stats API.

Modified:
  head/tools/tools/ath/athstats/Makefile
  head/tools/tools/ath/athstats/athstats.c

Modified: head/tools/tools/ath/athstats/Makefile
==============================================================================
--- head/tools/tools/ath/athstats/Makefile	Sun Feb 28 06:29:07 2016	(r296152)
+++ head/tools/tools/ath/athstats/Makefile	Sun Feb 28 06:29:25 2016	(r296153)
@@ -10,6 +10,10 @@ PROG=	athstats
 
 SRCS=	main.c athstats.c opt_ah.h ah_osdep.h
 
+CFLAGS+=	-I${.CURDIR}/../common/
+.PATH.c: ${.CURDIR}/../common/
+SRCS+=	ctrl.c
+
 CLEANFILES+=	opt_ah.h
 
 .include <../Makefile.inc>

Modified: head/tools/tools/ath/athstats/athstats.c
==============================================================================
--- head/tools/tools/ath/athstats/athstats.c	Sun Feb 28 06:29:07 2016	(r296152)
+++ head/tools/tools/ath/athstats/athstats.c	Sun Feb 28 06:29:25 2016	(r296153)
@@ -60,6 +60,8 @@
 
 #include "athstats.h"
 
+#include "ctrl.h"
+
 #ifdef ATH_SUPPORT_ANI
 #define HAL_EP_RND(x,mul) \
 	((((x)%(mul)) >= ((mul)/2)) ? ((x) + ((mul) - 1)) / (mul) : (x)/(mul))
@@ -441,10 +443,9 @@ struct _athstats {
 
 struct athstatfoo_p {
 	struct athstatfoo base;
-	int s;
 	int optstats;
+	struct ath_driver_req req;
 #define	ATHSTATS_ANI	0x0001
-	struct ifreq ifr;
 	struct ath_diag atd;
 	struct _athstats cur;
 	struct _athstats total;
@@ -455,7 +456,8 @@ ath_setifname(struct athstatfoo *wf0, co
 {
 	struct athstatfoo_p *wf = (struct athstatfoo_p *) wf0;
 
-	strncpy(wf->ifr.ifr_name, ifname, sizeof (wf->ifr.ifr_name));
+	ath_driver_req_close(&wf->req);
+	(void) ath_driver_req_open(&wf->req, ifname);
 #ifdef ATH_SUPPORT_ANI
 	strncpy(wf->atd.ad_name, ifname, sizeof (wf->atd.ad_name));
 	wf->optstats |= ATHSTATS_ANI;
@@ -467,30 +469,34 @@ ath_zerostats(struct athstatfoo *wf0)
 {
 	struct athstatfoo_p *wf = (struct athstatfoo_p *) wf0;
 
-	if (ioctl(wf->s, SIOCZATHSTATS, &wf->ifr) < 0)
-		err(-1, "ioctl: %s", wf->ifr.ifr_name);
+	if (ath_driver_req_zero_stats(&wf->req) < 0)
+		exit(-1);
 }
 
 static void
 ath_collect(struct athstatfoo_p *wf, struct _athstats *stats)
 {
-	wf->ifr.ifr_data = (caddr_t) &stats->ath;
-	if (ioctl(wf->s, SIOCGATHSTATS, &wf->ifr) < 0)
-		err(1, "ioctl: %s", wf->ifr.ifr_name);
+
+	if (ath_driver_req_fetch_stats(&wf->req, &stats->ath) < 0)
+		exit(1);
 #ifdef ATH_SUPPORT_ANI
 	if (wf->optstats & ATHSTATS_ANI) {
+
+		/* XXX TODO: convert */
 		wf->atd.ad_id = HAL_DIAG_ANI_CURRENT; /* HAL_DIAG_ANI_CURRENT */
 		wf->atd.ad_out_data = (caddr_t) &stats->ani_state;
 		wf->atd.ad_out_size = sizeof(stats->ani_state);
-		if (ioctl(wf->s, SIOCGATHDIAG, &wf->atd) < 0) {
-			warn("ioctl: %s", wf->atd.ad_name);
+		if (ath_driver_req_fetch_diag(&wf->req, SIOCGATHDIAG,
+		    &wf->atd) < 0) {
 			wf->optstats &= ~ATHSTATS_ANI;
 		}
+
+		/* XXX TODO: convert */
 		wf->atd.ad_id = HAL_DIAG_ANI_STATS; /* HAL_DIAG_ANI_STATS */
 		wf->atd.ad_out_data = (caddr_t) &stats->ani_stats;
 		wf->atd.ad_out_size = sizeof(stats->ani_stats);
-		if (ioctl(wf->s, SIOCGATHDIAG, &wf->atd) < 0)
-			warn("ioctl: %s", wf->atd.ad_name);
+		(void) ath_driver_req_fetch_diag(&wf->req, SIOCGATHDIAG,
+		    &wf->atd);
 	}
 #endif /* ATH_SUPPORT_ANI */
 }
@@ -1064,6 +1070,7 @@ athstats_new(const char *ifname, const c
 
 	wf = calloc(1, sizeof(struct athstatfoo_p));
 	if (wf != NULL) {
+		ath_driver_req_init(&wf->req);
 		bsdstat_init(&wf->base.base, "athstats", athstats,
 		    nitems(athstats));
 		/* override base methods */
@@ -1083,10 +1090,6 @@ athstats_new(const char *ifname, const c
 		wf->base.setstamac = wlan_setstamac;
 #endif
 		wf->base.zerostats = ath_zerostats;
-		wf->s = socket(AF_INET, SOCK_DGRAM, 0);
-		if (wf->s < 0)
-			err(1, "socket");
-
 		ath_setifname(&wf->base, ifname);
 		wf->base.setfmt(&wf->base, fmtstring);
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201602280629.u1S6TP0x004612>