summaryrefslogtreecommitdiffstats
path: root/tools/tools
diff options
context:
space:
mode:
authoradrian <adrian@FreeBSD.org>2012-07-30 01:42:22 +0000
committeradrian <adrian@FreeBSD.org>2012-07-30 01:42:22 +0000
commit6a9b72c2bce5a6b5569481b81d600d788fe6c216 (patch)
treef6791b3a7cfaf73b87a9d32425aeeaa4311042df /tools/tools
parent2e17d98c0de2c9c781c756ef727f968bab7b5a26 (diff)
downloadFreeBSD-src-6a9b72c2bce5a6b5569481b81d600d788fe6c216.zip
FreeBSD-src-6a9b72c2bce5a6b5569481b81d600d788fe6c216.tar.gz
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.
Diffstat (limited to 'tools/tools')
-rw-r--r--tools/tools/ath/athratestats/main.c142
1 files changed, 84 insertions, 58 deletions
diff --git a/tools/tools/ath/athratestats/main.c b/tools/tools/ath/athratestats/main.c
index c9b55b2..ff3d646 100644
--- a/tools/tools/ath/athratestats/main.c
+++ b/tools/tools/ath/athratestats/main.c
@@ -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);
}
-
OpenPOWER on IntegriCloud