From owner-svn-src-head@FreeBSD.ORG Mon Jul 30 01:42:22 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id C5C451065675; Mon, 30 Jul 2012 01:42:22 +0000 (UTC) (envelope-from adrian@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A660B8FC0C; Mon, 30 Jul 2012 01:42:22 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q6U1gMXV033757; Mon, 30 Jul 2012 01:42:22 GMT (envelope-from adrian@svn.freebsd.org) Received: (from adrian@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q6U1gMgY033755; Mon, 30 Jul 2012 01:42:22 GMT (envelope-from adrian@svn.freebsd.org) Message-Id: <201207300142.q6U1gMgY033755@svn.freebsd.org> From: Adrian Chadd Date: Mon, 30 Jul 2012 01:42:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r238893 - head/tools/tools/ath/athratestats X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Jul 2012 01:42:22 -0000 Author: adrian Date: Mon Jul 30 01:42:22 2012 New Revision: 238893 URL: http://svn.freebsd.org/changeset/base/238893 Log: Break out the parsing code from main() and modularise things a little. The eventual aim will be to support listing "one" and "all" stations for the given ath device. Modified: head/tools/tools/ath/athratestats/main.c Modified: head/tools/tools/ath/athratestats/main.c ============================================================================== --- head/tools/tools/ath/athratestats/main.c Sun Jul 29 20:04:09 2012 (r238892) +++ head/tools/tools/ath/athratestats/main.c Mon Jul 30 01:42:22 2012 (r238893) @@ -170,18 +170,69 @@ ath_rate_ioctl(struct ath_ratestats *r) err(1, "ioctl"); } -int -main(int argc, char *argv[]) +static int +rate_node_stats(struct ath_ratestats *r, struct ether_addr *e) { - struct ath_ratestats r; - struct ether_addr *e; - uint8_t *buf; struct ath_rateioctl_tlv *av; struct sample_node *sn = NULL; struct ath_rateioctl_rt *rt = NULL; + int error = 0; + uint8_t *buf = r->re.buf; + + /* + * For now, hard-code the TLV order and contents. Ew! + */ + av = (struct ath_rateioctl_tlv *) buf; + if (av->tlv_id != ATH_RATE_TLV_RATETABLE) { + fprintf(stderr, "unexpected rate control TLV (got 0x%x, " + "expected 0x%x\n", + av->tlv_id, + ATH_RATE_TLV_RATETABLE); + exit(127); + } + if (av->tlv_len != sizeof(struct ath_rateioctl_rt)) { + fprintf(stderr, "unexpected TLV len (got %d bytes, " + "expected %d bytes\n", + av->tlv_len, + sizeof(struct ath_rateioctl_rt)); + exit(127); + } + rt = (void *) (buf + sizeof(struct ath_rateioctl_tlv)); + + /* Next */ + av = (void *) (buf + sizeof(struct ath_rateioctl_tlv) + + sizeof(struct ath_rateioctl_rt)); + if (av->tlv_id != ATH_RATE_TLV_SAMPLENODE) { + fprintf(stderr, "unexpected rate control TLV (got 0x%x, " + "expected 0x%x\n", + av->tlv_id, + ATH_RATE_TLV_SAMPLENODE); + exit(127); + } + if (av->tlv_len != sizeof(struct sample_node)) { + fprintf(stderr, "unexpected TLV len (got %d bytes, " + "expected %d bytes\n", + av->tlv_len, + sizeof(struct sample_node)); + exit(127); + } + sn = (void *) (buf + sizeof(struct ath_rateioctl_tlv) + + sizeof(struct ath_rateioctl_rt) + + sizeof(struct ath_rateioctl_tlv)); + + ath_sample_stats(r, rt, sn); +} + + +int +main(int argc, char *argv[]) +{ char const *ifname = NULL, *macaddr = NULL; int c; int do_all = 0; + struct ether_addr *e; + struct ath_ratestats r; + uint8_t *buf; ifname = getenv("ATH"); if (ifname == NULL) @@ -207,18 +258,6 @@ main(int argc, char *argv[]) } } - buf = calloc(1, STATS_BUF_SIZE); - if (buf == NULL) - err(1, "calloc"); - - bzero(&r, sizeof(r)); - r.s = socket(AF_INET, SOCK_DGRAM, 0); - if (r.s < 0) { - err(1, "socket"); - } - /* XXX error check */ - ath_setifname(&r, ifname); - if (macaddr == NULL) { errx(1, "%s: macaddress wasn't supplied and no -a given\n", argv[0]); @@ -228,53 +267,40 @@ main(int argc, char *argv[]) if (e == NULL) err(1, "ether_aton"); + bzero(&r, sizeof(r)); + + /* + * Persistent buffer for each lookup + */ + buf = malloc(STATS_BUF_SIZE); + if (buf == NULL) + err(1, "calloc"); + r.re.buf = buf; r.re.len = STATS_BUF_SIZE; - ath_setsta(&r, e->octet); - ath_rate_ioctl(&r); + r.s = socket(AF_INET, SOCK_DGRAM, 0); + if (r.s < 0) { + err(1, "socket"); + } + /* XXX error check */ + ath_setifname(&r, ifname); + + /* Zero the buffer before it's passed in */ + memset(buf, '\0', STATS_BUF_SIZE); /* - * For now, hard-code the TLV order and contents. Ew! + * Set the station address for this lookup. */ - av = (struct ath_rateioctl_tlv *) buf; - if (av->tlv_id != ATH_RATE_TLV_RATETABLE) { - fprintf(stderr, "unexpected rate control TLV (got 0x%x, " - "expected 0x%x\n", - av->tlv_id, - ATH_RATE_TLV_RATETABLE); - exit(127); - } - if (av->tlv_len != sizeof(struct ath_rateioctl_rt)) { - fprintf(stderr, "unexpected TLV len (got %d bytes, " - "expected %d bytes\n", - av->tlv_len, - sizeof(struct ath_rateioctl_rt)); - exit(127); - } - rt = (void *) (buf + sizeof(struct ath_rateioctl_tlv)); + ath_setsta(&r, e->octet); - /* Next */ - av = (void *) (buf + sizeof(struct ath_rateioctl_tlv) + - sizeof(struct ath_rateioctl_rt)); - if (av->tlv_id != ATH_RATE_TLV_SAMPLENODE) { - fprintf(stderr, "unexpected rate control TLV (got 0x%x, " - "expected 0x%x\n", - av->tlv_id, - ATH_RATE_TLV_SAMPLENODE); - exit(127); - } - if (av->tlv_len != sizeof(struct sample_node)) { - fprintf(stderr, "unexpected TLV len (got %d bytes, " - "expected %d bytes\n", - av->tlv_len, - sizeof(struct sample_node)); - exit(127); - } - sn = (void *) (buf + sizeof(struct ath_rateioctl_tlv) + - sizeof(struct ath_rateioctl_rt) + - sizeof(struct ath_rateioctl_tlv)); + /* + * Fetch the data from the driver. + */ + ath_rate_ioctl(&r); - ath_sample_stats(&r, rt, sn); + /* + * Decode and parse statistics. + */ + rate_node_stats(&r, e); } -