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 __FBSDID("$FreeBSD$"); 20 21 #include <stdio.h> 22 #include <stdlib.h> 23 #include <unistd.h> 24 #include <fcntl.h> 25 #include <errno.h> 26 #include <string.h> 27 28 #include <sys/types.h> 29 #include <sys/alq.h> 30 #include <sys/endian.h> 31 32 #include <dev/ath/if_ath_alq.h> 33 34 #include "tdma.h" 35 36 void 37 ath_tdma_beacon_state(struct if_ath_alq_payload *a) 38 { 39 struct if_ath_alq_tdma_beacon_state t; 40 static uint64_t last_beacon_tx = 0; 41 42 memcpy(&t, &a->payload, sizeof(t)); 43 44 printf("[%u.%06u] [%llu] BEACON: RX TSF=%llu Beacon TSF=%llu (%d)\n", 45 (unsigned int) be32toh(a->hdr.tstamp_sec), 46 (unsigned int) be32toh(a->hdr.tstamp_usec), 47 (unsigned long long) be64toh(a->hdr.threadid), 48 (unsigned long long) be64toh(t.rx_tsf), 49 (unsigned long long) be64toh(t.beacon_tsf), 50 be64toh(t.beacon_tsf) - last_beacon_tx); 51 52 last_beacon_tx = be64toh(t.beacon_tsf); 53 } 54 55 void 56 ath_tdma_timer_config(struct if_ath_alq_payload *a) 57 { 58 struct if_ath_alq_tdma_timer_config t; 59 60 memcpy(&t, &a->payload, sizeof(t)); 61 } 62 63 void 64 ath_tdma_slot_calc(struct if_ath_alq_payload *a) 65 { 66 struct if_ath_alq_tdma_slot_calc t; 67 68 memcpy(&t, &a->payload, sizeof(t)); 69 printf("[%u.%06u] [%llu] SLOTCALC: NEXTTBTT=%llu nextslot=%llu " 70 "tsfdelta=%d avg (%d/%d)\n", 71 (unsigned int) be32toh(a->hdr.tstamp_sec), 72 (unsigned int) be32toh(a->hdr.tstamp_usec), 73 (unsigned long long) be64toh(a->hdr.threadid), 74 (unsigned long long) be64toh(t.nexttbtt), 75 (unsigned long long) be64toh(t.next_slot), 76 (int) be32toh(t.tsfdelta), 77 (int) be32toh(t.avg_plus), 78 (int) be32toh(t.avg_minus)); 79 } 80 81 void 82 ath_tdma_tsf_adjust(struct if_ath_alq_payload *a) 83 { 84 struct if_ath_alq_tdma_tsf_adjust t; 85 86 memcpy(&t, &a->payload, sizeof(t)); 87 printf("[%u.%06u] [%llu] TSFADJUST: TSF64 was %llu, adj=%d, " 88 "now %llu\n", 89 (unsigned int) be32toh(a->hdr.tstamp_sec), 90 (unsigned int) be32toh(a->hdr.tstamp_usec), 91 (unsigned long long) be64toh(a->hdr.threadid), 92 (unsigned long long) be64toh(t.tsf64_old), 93 (int) be32toh(t.tsfdelta), 94 (unsigned long long) be64toh(t.tsf64_new)); 95 } 96 97 void 98 ath_tdma_timer_set(struct if_ath_alq_payload *a) 99 { 100 struct if_ath_alq_tdma_timer_set t; 101 102 memcpy(&t, &a->payload, sizeof(t)); 103 printf("[%u.%06u] [%llu] TIMERSET: bt_intval=%d nexttbtt=%d " 104 "nextdba=%d nextswba=%d nextatim=%d flags=0x%x tdmadbaprep=%d " 105 "tdmaswbaprep=%d\n", 106 (unsigned int) be32toh(a->hdr.tstamp_sec), 107 (unsigned int) be32toh(a->hdr.tstamp_usec), 108 (unsigned long long) be64toh(a->hdr.threadid), 109 be32toh(t.bt_intval), 110 be32toh(t.bt_nexttbtt), 111 be32toh(t.bt_nextdba), 112 be32toh(t.bt_nextswba), 113 be32toh(t.bt_nextatim), 114 be32toh(t.bt_flags), 115 be32toh(t.sc_tdmadbaprep), 116 be32toh(t.sc_tdmaswbaprep)); 117 } 118