1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include "common.h"
18
19#define FUDGE 2
20
21static u32 ath9k_get_next_tbtt(struct ath_hw *ah, u64 tsf,
22 unsigned int interval)
23{
24 unsigned int offset, divisor;
25
26 tsf += TU_TO_USEC(FUDGE + ah->config.sw_beacon_response_time);
27 divisor = TU_TO_USEC(interval);
28 div_u64_rem(tsf, divisor, &offset);
29
30 return (u32) tsf + divisor - offset;
31}
32
33
34
35
36
37
38
39
40
41int ath9k_cmn_beacon_config_sta(struct ath_hw *ah,
42 struct ath_beacon_config *conf,
43 struct ath9k_beacon_state *bs)
44{
45 struct ath_common *common = ath9k_hw_common(ah);
46 int dtim_intval;
47 u64 tsf;
48
49
50 if (!test_bit(ATH_OP_PRIM_STA_VIF, &common->op_flags)) {
51 ath_dbg(common, BEACON,
52 "STA is not yet associated..skipping beacon config\n");
53 return -EPERM;
54 }
55
56 memset(bs, 0, sizeof(*bs));
57 conf->intval = conf->beacon_interval;
58
59
60
61
62
63 dtim_intval = conf->intval * conf->dtim_period;
64
65
66
67
68
69 tsf = ath9k_hw_gettsf64(ah);
70 conf->nexttbtt = ath9k_get_next_tbtt(ah, tsf, conf->intval);
71
72 bs->bs_intval = TU_TO_USEC(conf->intval);
73 bs->bs_dtimperiod = conf->dtim_period * bs->bs_intval;
74 bs->bs_nexttbtt = conf->nexttbtt;
75 bs->bs_nextdtim = conf->nexttbtt;
76 if (conf->dtim_period > 1)
77 bs->bs_nextdtim = ath9k_get_next_tbtt(ah, tsf, dtim_intval);
78
79
80
81
82
83
84
85 bs->bs_bmissthreshold = DIV_ROUND_UP(conf->bmiss_timeout, conf->intval);
86 if (bs->bs_bmissthreshold > 15)
87 bs->bs_bmissthreshold = 15;
88 else if (bs->bs_bmissthreshold <= 0)
89 bs->bs_bmissthreshold = 1;
90
91
92
93
94
95
96
97
98
99
100 bs->bs_sleepduration = TU_TO_USEC(roundup(IEEE80211_MS_TO_TU(100),
101 conf->intval));
102 if (bs->bs_sleepduration > bs->bs_dtimperiod)
103 bs->bs_sleepduration = bs->bs_dtimperiod;
104
105
106 bs->bs_tsfoor_threshold = ATH9K_TSFOOR_THRESHOLD;
107
108 ath_dbg(common, BEACON, "bmiss: %u sleep: %u\n",
109 bs->bs_bmissthreshold, bs->bs_sleepduration);
110 return 0;
111}
112EXPORT_SYMBOL(ath9k_cmn_beacon_config_sta);
113
114void ath9k_cmn_beacon_config_adhoc(struct ath_hw *ah,
115 struct ath_beacon_config *conf)
116{
117 struct ath_common *common = ath9k_hw_common(ah);
118
119 conf->intval = TU_TO_USEC(conf->beacon_interval);
120
121 if (conf->ibss_creator)
122 conf->nexttbtt = conf->intval;
123 else
124 conf->nexttbtt = ath9k_get_next_tbtt(ah, ath9k_hw_gettsf64(ah),
125 conf->beacon_interval);
126
127 if (conf->enable_beacon)
128 ah->imask |= ATH9K_INT_SWBA;
129 else
130 ah->imask &= ~ATH9K_INT_SWBA;
131
132 ath_dbg(common, BEACON,
133 "IBSS (%s) nexttbtt: %u intval: %u conf_intval: %u\n",
134 (conf->enable_beacon) ? "Enable" : "Disable",
135 conf->nexttbtt, conf->intval, conf->beacon_interval);
136}
137EXPORT_SYMBOL(ath9k_cmn_beacon_config_adhoc);
138
139
140
141
142
143
144void ath9k_cmn_beacon_config_ap(struct ath_hw *ah,
145 struct ath_beacon_config *conf,
146 unsigned int bc_buf)
147{
148 struct ath_common *common = ath9k_hw_common(ah);
149
150
151 conf->intval = TU_TO_USEC(conf->beacon_interval);
152 conf->intval /= bc_buf;
153 conf->nexttbtt = ath9k_get_next_tbtt(ah, ath9k_hw_gettsf64(ah),
154 conf->beacon_interval);
155
156 if (conf->enable_beacon)
157 ah->imask |= ATH9K_INT_SWBA;
158 else
159 ah->imask &= ~ATH9K_INT_SWBA;
160
161 ath_dbg(common, BEACON,
162 "AP (%s) nexttbtt: %u intval: %u conf_intval: %u\n",
163 (conf->enable_beacon) ? "Enable" : "Disable",
164 conf->nexttbtt, conf->intval, conf->beacon_interval);
165}
166EXPORT_SYMBOL(ath9k_cmn_beacon_config_ap);
167