xref: /freebsd/tools/tools/ath/athalq/tdma.c (revision 1d386b48)
1 /*
2  * Copyright (c) 2013 Adrian Chadd <adrian@FreeBSD.org>
3  * All Rights Reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #include <sys/cdefs.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <fcntl.h>
23 #include <errno.h>
24 #include <string.h>
25 
26 #include <sys/types.h>
27 #include <sys/alq.h>
28 #include <sys/endian.h>
29 
30 #include <dev/ath/if_ath_alq.h>
31 
32 #include "tdma.h"
33 
34 void
ath_tdma_beacon_state(struct if_ath_alq_payload * a)35 ath_tdma_beacon_state(struct if_ath_alq_payload *a)
36 {
37 	struct if_ath_alq_tdma_beacon_state t;
38 	static uint64_t last_beacon_tx = 0;
39 
40 	memcpy(&t, &a->payload, sizeof(t));
41 
42 	printf("[%u.%06u] [%llu] BEACON: RX TSF=%llu Beacon TSF=%llu (%d)\n",
43 	    (unsigned int) be32toh(a->hdr.tstamp_sec),
44 	    (unsigned int) be32toh(a->hdr.tstamp_usec),
45 	    (unsigned long long) be64toh(a->hdr.threadid),
46 	    (unsigned long long) be64toh(t.rx_tsf),
47 	    (unsigned long long) be64toh(t.beacon_tsf),
48 	    be64toh(t.beacon_tsf) - last_beacon_tx);
49 
50 	last_beacon_tx = be64toh(t.beacon_tsf);
51 }
52 
53 void
ath_tdma_timer_config(struct if_ath_alq_payload * a)54 ath_tdma_timer_config(struct if_ath_alq_payload *a)
55 {
56 	struct if_ath_alq_tdma_timer_config t;
57 
58 	memcpy(&t, &a->payload, sizeof(t));
59 }
60 
61 void
ath_tdma_slot_calc(struct if_ath_alq_payload * a)62 ath_tdma_slot_calc(struct if_ath_alq_payload *a)
63 {
64 	struct if_ath_alq_tdma_slot_calc t;
65 
66 	memcpy(&t, &a->payload, sizeof(t));
67 	printf("[%u.%06u] [%llu] SLOTCALC: NEXTTBTT=%llu nextslot=%llu "
68 	    "tsfdelta=%d avg (%d/%d)\n",
69 	    (unsigned int) be32toh(a->hdr.tstamp_sec),
70 	    (unsigned int) be32toh(a->hdr.tstamp_usec),
71 	    (unsigned long long) be64toh(a->hdr.threadid),
72 	    (unsigned long long) be64toh(t.nexttbtt),
73 	    (unsigned long long) be64toh(t.next_slot),
74 	    (int) be32toh(t.tsfdelta),
75 	    (int) be32toh(t.avg_plus),
76 	    (int) be32toh(t.avg_minus));
77 }
78 
79 void
ath_tdma_tsf_adjust(struct if_ath_alq_payload * a)80 ath_tdma_tsf_adjust(struct if_ath_alq_payload *a)
81 {
82 	struct if_ath_alq_tdma_tsf_adjust t;
83 
84 	memcpy(&t, &a->payload, sizeof(t));
85 	printf("[%u.%06u] [%llu] TSFADJUST: TSF64 was %llu, adj=%d, "
86 	    "now %llu\n",
87 	    (unsigned int) be32toh(a->hdr.tstamp_sec),
88 	    (unsigned int) be32toh(a->hdr.tstamp_usec),
89 	    (unsigned long long) be64toh(a->hdr.threadid),
90 	    (unsigned long long) be64toh(t.tsf64_old),
91 	    (int) be32toh(t.tsfdelta),
92 	    (unsigned long long) be64toh(t.tsf64_new));
93 }
94 
95 void
ath_tdma_timer_set(struct if_ath_alq_payload * a)96 ath_tdma_timer_set(struct if_ath_alq_payload *a)
97 {
98 	struct if_ath_alq_tdma_timer_set t;
99 
100 	memcpy(&t, &a->payload, sizeof(t));
101 	printf("[%u.%06u] [%llu] TIMERSET: bt_intval=%d nexttbtt=%d "
102 	    "nextdba=%d nextswba=%d nextatim=%d flags=0x%x tdmadbaprep=%d "
103 	    "tdmaswbaprep=%d\n",
104 	    (unsigned int) be32toh(a->hdr.tstamp_sec),
105 	    (unsigned int) be32toh(a->hdr.tstamp_usec),
106 	    (unsigned long long) be64toh(a->hdr.threadid),
107 	    be32toh(t.bt_intval),
108 	    be32toh(t.bt_nexttbtt),
109 	    be32toh(t.bt_nextdba),
110 	    be32toh(t.bt_nextswba),
111 	    be32toh(t.bt_nextatim),
112 	    be32toh(t.bt_flags),
113 	    be32toh(t.sc_tdmadbaprep),
114 	    be32toh(t.sc_tdmaswbaprep));
115 }
116