2 * Copyright (c) 2007-2009 Sam Leffler, Errno Consulting
3 * Copyright (c) 2007-2009 Intel Corporation
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
33 * IEEE 802.11 TDMA mode support.
39 #ifdef IEEE80211_SUPPORT_TDMA
41 #include <sys/param.h>
42 #include <sys/systm.h>
44 #include <sys/malloc.h>
45 #include <sys/kernel.h>
47 #include <sys/socket.h>
48 #include <sys/sockio.h>
49 #include <sys/endian.h>
50 #include <sys/errno.h>
52 #include <sys/sysctl.h>
55 #include <net/if_media.h>
56 #include <net/if_llc.h>
57 #include <net/ethernet.h>
61 #include <net80211/ieee80211_var.h>
62 #include <net80211/ieee80211_tdma.h>
63 #include <net80211/ieee80211_input.h>
65 #ifndef TDMA_SLOTLEN_DEFAULT
66 #define TDMA_SLOTLEN_DEFAULT 10*1000 /* 10ms */
68 #ifndef TDMA_SLOTCNT_DEFAULT
69 #define TDMA_SLOTCNT_DEFAULT 2 /* 2x (pt-to-pt) */
71 #ifndef TDMA_BINTVAL_DEFAULT
72 #define TDMA_BINTVAL_DEFAULT 5 /* 5x ~= 100TU beacon intvl */
74 #ifndef TDMA_TXRATE_11B_DEFAULT
75 #define TDMA_TXRATE_11B_DEFAULT 2*11
77 #ifndef TDMA_TXRATE_11G_DEFAULT
78 #define TDMA_TXRATE_11G_DEFAULT 2*24
80 #ifndef TDMA_TXRATE_11A_DEFAULT
81 #define TDMA_TXRATE_11A_DEFAULT 2*24
83 #ifndef TDMA_TXRATE_TURBO_DEFAULT
84 #define TDMA_TXRATE_TURBO_DEFAULT 2*24
86 #ifndef TDMA_TXRATE_HALF_DEFAULT
87 #define TDMA_TXRATE_HALF_DEFAULT 2*12
89 #ifndef TDMA_TXRATE_QUARTER_DEFAULT
90 #define TDMA_TXRATE_QUARTER_DEFAULT 2*6
92 #ifndef TDMA_TXRATE_11NA_DEFAULT
93 #define TDMA_TXRATE_11NA_DEFAULT (4 | IEEE80211_RATE_MCS)
95 #ifndef TDMA_TXRATE_11NG_DEFAULT
96 #define TDMA_TXRATE_11NG_DEFAULT (4 | IEEE80211_RATE_MCS)
99 #define TDMA_VERSION_VALID(_version) \
100 (TDMA_VERSION_V2 <= (_version) && (_version) <= TDMA_VERSION)
101 #define TDMA_SLOTCNT_VALID(_slotcnt) \
102 (2 <= (_slotcnt) && (_slotcnt) <= TDMA_MAXSLOTS)
103 /* XXX magic constants */
104 #define TDMA_SLOTLEN_VALID(_slotlen) \
105 (2*100 <= (_slotlen) && (unsigned)(_slotlen) <= 0xfffff)
106 /* XXX probably should set a max */
107 #define TDMA_BINTVAL_VALID(_bintval) (1 <= (_bintval))
110 * This code is not prepared to handle more than 2 slots.
112 CTASSERT(TDMA_MAXSLOTS == 2);
114 static void tdma_vdetach(struct ieee80211vap *vap);
115 static int tdma_newstate(struct ieee80211vap *, enum ieee80211_state, int);
116 static void tdma_beacon_miss(struct ieee80211vap *vap);
117 static void tdma_recv_mgmt(struct ieee80211_node *, struct mbuf *,
118 int subtype, int rssi, int nf);
119 static int tdma_update(struct ieee80211vap *vap,
120 const struct ieee80211_tdma_param *tdma, struct ieee80211_node *ni,
122 static int tdma_process_params(struct ieee80211_node *ni,
123 const u_int8_t *ie, int rssi, int nf, const struct ieee80211_frame *wh);
126 settxparms(struct ieee80211vap *vap, enum ieee80211_phymode mode, int rate)
128 vap->iv_txparms[mode].ucastrate = rate;
129 vap->iv_txparms[mode].mcastrate = rate;
133 setackpolicy(struct ieee80211com *ic, int noack)
135 struct ieee80211_wme_state *wme = &ic->ic_wme;
138 for (ac = 0; ac < WME_NUM_AC; ac++) {
139 wme->wme_chanParams.cap_wmeParams[ac].wmep_noackPolicy = noack;
140 wme->wme_wmeChanParams.cap_wmeParams[ac].wmep_noackPolicy = noack;
145 ieee80211_tdma_vattach(struct ieee80211vap *vap)
147 struct ieee80211_tdma_state *ts;
149 KASSERT(vap->iv_caps & IEEE80211_C_TDMA,
150 ("not a tdma vap, caps 0x%x", vap->iv_caps));
152 ts = (struct ieee80211_tdma_state *) malloc(
153 sizeof(struct ieee80211_tdma_state), M_80211_VAP, M_NOWAIT | M_ZERO);
155 printf("%s: cannot allocate TDMA state block\n", __func__);
156 /* NB: fall back to adhdemo mode */
157 vap->iv_caps &= ~IEEE80211_C_TDMA;
160 /* NB: default configuration is passive so no beacons */
161 ts->tdma_version = TDMA_VERSION;
162 ts->tdma_slotlen = TDMA_SLOTLEN_DEFAULT;
163 ts->tdma_slotcnt = TDMA_SLOTCNT_DEFAULT;
164 ts->tdma_bintval = TDMA_BINTVAL_DEFAULT;
165 ts->tdma_slot = 1; /* passive operation */
167 /* setup default fixed rates */
168 settxparms(vap, IEEE80211_MODE_11A, TDMA_TXRATE_11A_DEFAULT);
169 settxparms(vap, IEEE80211_MODE_11B, TDMA_TXRATE_11B_DEFAULT);
170 settxparms(vap, IEEE80211_MODE_11G, TDMA_TXRATE_11G_DEFAULT);
171 settxparms(vap, IEEE80211_MODE_TURBO_A, TDMA_TXRATE_TURBO_DEFAULT);
172 settxparms(vap, IEEE80211_MODE_TURBO_G, TDMA_TXRATE_TURBO_DEFAULT);
173 settxparms(vap, IEEE80211_MODE_STURBO_A, TDMA_TXRATE_TURBO_DEFAULT);
174 settxparms(vap, IEEE80211_MODE_11NA, TDMA_TXRATE_11NA_DEFAULT);
175 settxparms(vap, IEEE80211_MODE_11NG, TDMA_TXRATE_11NG_DEFAULT);
176 settxparms(vap, IEEE80211_MODE_HALF, TDMA_TXRATE_HALF_DEFAULT);
177 settxparms(vap, IEEE80211_MODE_QUARTER, TDMA_TXRATE_QUARTER_DEFAULT);
179 setackpolicy(vap->iv_ic, 1); /* disable ACK's */
181 ts->tdma_opdetach = vap->iv_opdetach;
182 vap->iv_opdetach = tdma_vdetach;
183 ts->tdma_newstate = vap->iv_newstate;
184 vap->iv_newstate = tdma_newstate;
185 vap->iv_bmiss = tdma_beacon_miss;
186 ts->tdma_recv_mgmt = vap->iv_recv_mgmt;
187 vap->iv_recv_mgmt = tdma_recv_mgmt;
193 tdma_vdetach(struct ieee80211vap *vap)
195 struct ieee80211_tdma_state *ts = vap->iv_tdma;
198 /* NB: should not have touched any ic state */
201 ts->tdma_opdetach(vap);
202 free(vap->iv_tdma, M_80211_VAP);
205 setackpolicy(vap->iv_ic, 0); /* enable ACK's */
209 sta_leave(void *arg, struct ieee80211_node *ni)
211 struct ieee80211vap *vap = arg;
213 if (ni->ni_vap == vap && ni != vap->iv_bss)
214 ieee80211_node_leave(ni);
218 * TDMA state machine handler.
221 tdma_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
223 struct ieee80211_tdma_state *ts = vap->iv_tdma;
224 struct ieee80211com *ic = vap->iv_ic;
225 enum ieee80211_state ostate;
228 IEEE80211_LOCK_ASSERT(ic);
230 ostate = vap->iv_state;
231 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE, "%s: %s -> %s (%d)\n",
232 __func__, ieee80211_state_name[ostate],
233 ieee80211_state_name[nstate], arg);
235 if (vap->iv_flags_ext & IEEE80211_FEXT_SWBMISS)
236 callout_stop(&vap->iv_swbmiss);
237 if (nstate == IEEE80211_S_SCAN &&
238 (ostate == IEEE80211_S_INIT || ostate == IEEE80211_S_RUN) &&
239 ts->tdma_slot != 0) {
241 * Override adhoc behaviour when operating as a slave;
242 * we need to scan even if the channel is locked.
244 vap->iv_state = nstate; /* state transition */
245 ieee80211_cancel_scan(vap); /* background scan */
246 if (ostate == IEEE80211_S_RUN) {
247 /* purge station table; entries are stale */
248 ieee80211_iterate_nodes(&ic->ic_sta, sta_leave, vap);
250 if (vap->iv_flags_ext & IEEE80211_FEXT_SCANREQ) {
251 ieee80211_check_scan(vap,
252 vap->iv_scanreq_flags,
253 vap->iv_scanreq_duration,
254 vap->iv_scanreq_mindwell,
255 vap->iv_scanreq_maxdwell,
256 vap->iv_scanreq_nssid, vap->iv_scanreq_ssid);
257 vap->iv_flags_ext &= ~IEEE80211_FEXT_SCANREQ;
259 ieee80211_check_scan_current(vap);
262 status = ts->tdma_newstate(vap, nstate, arg);
265 nstate == IEEE80211_S_RUN && ostate != IEEE80211_S_RUN &&
266 (vap->iv_flags_ext & IEEE80211_FEXT_SWBMISS) &&
267 ts->tdma_slot != 0 &&
268 vap->iv_des_chan == IEEE80211_CHAN_ANYC) {
270 * Start s/w beacon miss timer for slave devices w/o
271 * hardware support. Note we do this only if we're
272 * not locked to a channel (i.e. roam to follow the
273 * master). The 2x is a fudge for our doing this in
276 vap->iv_swbmiss_period = IEEE80211_TU_TO_TICKS(
277 2 * vap->iv_bmissthreshold * ts->tdma_bintval *
278 ((ts->tdma_slotcnt * ts->tdma_slotlen) / 1024));
279 vap->iv_swbmiss_count = 0;
280 callout_reset(&vap->iv_swbmiss, vap->iv_swbmiss_period,
281 ieee80211_swbmiss, vap);
287 tdma_beacon_miss(struct ieee80211vap *vap)
289 struct ieee80211_tdma_state *ts = vap->iv_tdma;
291 IEEE80211_LOCK_ASSERT(vap->iv_ic);
293 KASSERT((vap->iv_ic->ic_flags & IEEE80211_F_SCAN) == 0, ("scanning"));
294 KASSERT(vap->iv_state == IEEE80211_S_RUN,
295 ("wrong state %d", vap->iv_state));
297 IEEE80211_DPRINTF(vap,
298 IEEE80211_MSG_STATE | IEEE80211_MSG_TDMA | IEEE80211_MSG_DEBUG,
299 "beacon miss, mode %u state %s\n",
300 vap->iv_opmode, ieee80211_state_name[vap->iv_state]);
302 callout_stop(&vap->iv_swbmiss);
304 if (ts->tdma_peer != NULL) { /* XXX? can this be null? */
305 ieee80211_notify_node_leave(vap->iv_bss);
306 ts->tdma_peer = NULL;
308 * Treat beacon miss like an associate failure wrt the
309 * scan policy; this forces the entry in the scan cache
310 * to be ignored after several tries.
312 ieee80211_scan_assoc_fail(vap, vap->iv_bss->ni_macaddr,
313 IEEE80211_STATUS_TIMEOUT);
316 ts->tdma_inuse = 0; /* clear slot usage */
318 ieee80211_new_state(vap, IEEE80211_S_SCAN, 0);
322 tdma_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m0,
323 int subtype, int rssi, int nf)
325 struct ieee80211com *ic = ni->ni_ic;
326 struct ieee80211vap *vap = ni->ni_vap;
327 struct ieee80211_tdma_state *ts = vap->iv_tdma;
329 if (subtype == IEEE80211_FC0_SUBTYPE_BEACON &&
330 (ic->ic_flags & IEEE80211_F_SCAN) == 0) {
331 struct ieee80211_frame *wh = mtod(m0, struct ieee80211_frame *);
332 struct ieee80211_scanparams scan;
334 if (ieee80211_parse_beacon(ni, m0, &scan) != 0)
336 if (scan.tdma == NULL) {
338 * TDMA stations must beacon a TDMA ie; ignore
340 * XXX detect overlapping bss and change channel
342 IEEE80211_DISCARD(vap,
343 IEEE80211_MSG_ELEMID | IEEE80211_MSG_INPUT,
344 wh, ieee80211_mgt_subtype_name[subtype >>
345 IEEE80211_FC0_SUBTYPE_SHIFT],
347 vap->iv_stats.is_rx_mgtdiscard++;
350 if (ni == vap->iv_bss &&
351 !IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_macaddr)) {
353 * Fake up a node for this newly
354 * discovered member of the IBSS.
356 ni = ieee80211_add_neighbor(vap, wh, &scan);
358 /* NB: stat kept for alloc failure */
363 * Check for state updates.
365 if (IEEE80211_ADDR_EQ(wh->i_addr3, ni->ni_bssid)) {
367 * Count frame now that we know it's to be processed.
369 vap->iv_stats.is_rx_beacon++;
370 IEEE80211_NODE_STAT(ni, rx_beacons);
372 * Record tsf of last beacon. NB: this must be
373 * done before calling tdma_process_params
374 * as deeper routines reference it.
376 memcpy(&ni->ni_tstamp.data, scan.tstamp,
377 sizeof(ni->ni_tstamp.data));
379 * Count beacon frame for s/w bmiss handling.
381 vap->iv_swbmiss_count++;
383 * Process tdma ie. The contents are used to sync
384 * the slot timing, reconfigure the bss, etc.
386 (void) tdma_process_params(ni, scan.tdma, rssi, nf, wh);
390 * NB: defer remaining work to the adhoc code; this causes
391 * 2x parsing of the frame but should happen infrequently
394 ts->tdma_recv_mgmt(ni, m0, subtype, rssi, nf);
398 * Update TDMA state on receipt of a beacon frame with
399 * a TDMA information element. The sender's identity
400 * is provided so we can track who our peer is. If pickslot
401 * is non-zero we scan the slot allocation state in the ie
402 * to locate a free slot for our use.
405 tdma_update(struct ieee80211vap *vap, const struct ieee80211_tdma_param *tdma,
406 struct ieee80211_node *ni, int pickslot)
408 struct ieee80211_tdma_state *ts = vap->iv_tdma;
409 int slot, slotlen, update;
411 KASSERT(vap->iv_caps & IEEE80211_C_TDMA,
412 ("not a tdma vap, caps 0x%x", vap->iv_caps));
415 if (tdma->tdma_slotcnt != ts->tdma_slotcnt) {
416 if (!TDMA_SLOTCNT_VALID(tdma->tdma_slotcnt)) {
417 if (ppsratecheck(&ts->tdma_lastprint, &ts->tdma_fails, 1))
418 printf("%s: bad slot cnt %u\n",
419 __func__, tdma->tdma_slotcnt);
422 update |= TDMA_UPDATE_SLOTCNT;
424 slotlen = le16toh(tdma->tdma_slotlen) * 100;
425 if (slotlen != ts->tdma_slotlen) {
426 if (!TDMA_SLOTLEN_VALID(slotlen)) {
427 if (ppsratecheck(&ts->tdma_lastprint, &ts->tdma_fails, 1))
428 printf("%s: bad slot len %u\n",
432 update |= TDMA_UPDATE_SLOTLEN;
434 if (tdma->tdma_bintval != ts->tdma_bintval) {
435 if (!TDMA_BINTVAL_VALID(tdma->tdma_bintval)) {
436 if (ppsratecheck(&ts->tdma_lastprint, &ts->tdma_fails, 1))
437 printf("%s: bad beacon interval %u\n",
438 __func__, tdma->tdma_bintval);
441 update |= TDMA_UPDATE_BINTVAL;
443 slot = ts->tdma_slot;
446 * Pick unoccupied slot. Note we never choose slot 0.
448 for (slot = tdma->tdma_slotcnt-1; slot > 0; slot--)
449 if (isclr(tdma->tdma_inuse, slot))
452 printf("%s: no free slot, slotcnt %u inuse: 0x%x\n",
453 __func__, tdma->tdma_slotcnt,
454 tdma->tdma_inuse[0]);
455 /* XXX need to do something better */
458 if (slot != ts->tdma_slot)
459 update |= TDMA_UPDATE_SLOT;
461 if (ni != ts->tdma_peer) {
462 /* update everything */
463 update = TDMA_UPDATE_SLOT
464 | TDMA_UPDATE_SLOTCNT
465 | TDMA_UPDATE_SLOTLEN
466 | TDMA_UPDATE_BINTVAL;
471 * New/changed parameters; update runtime state.
473 /* XXX overwrites user parameters */
474 if (update & TDMA_UPDATE_SLOTCNT)
475 ts->tdma_slotcnt = tdma->tdma_slotcnt;
476 if (update & TDMA_UPDATE_SLOTLEN)
477 ts->tdma_slotlen = slotlen;
478 if (update & TDMA_UPDATE_SLOT)
479 ts->tdma_slot = slot;
480 if (update & TDMA_UPDATE_BINTVAL)
481 ts->tdma_bintval = tdma->tdma_bintval;
482 /* mark beacon to be updated before next xmit */
483 ieee80211_beacon_notify(vap, IEEE80211_BEACON_TDMA);
485 IEEE80211_DPRINTF(vap, IEEE80211_MSG_TDMA,
486 "%s: slot %u slotcnt %u slotlen %u us bintval %u\n",
487 __func__, ts->tdma_slot, ts->tdma_slotcnt,
488 ts->tdma_slotlen, ts->tdma_bintval);
491 * Notify driver. Note we can be called before
492 * entering RUN state if we scanned and are
493 * joining an existing bss. In that case do not
494 * call the driver because not all necessary state
495 * has been setup. The next beacon will dtrt.
497 if (vap->iv_state == IEEE80211_S_RUN)
498 vap->iv_ic->ic_tdma_update(ni, tdma, update);
500 * Dispatch join event on first beacon from new master.
502 if (ts->tdma_peer != ni) {
503 if (ts->tdma_peer != NULL)
504 ieee80211_notify_node_leave(vap->iv_bss);
505 ieee80211_notify_node_join(ni, 1);
506 /* NB: no reference, we just use the address */
513 * Process received TDMA parameters.
516 tdma_process_params(struct ieee80211_node *ni, const u_int8_t *ie,
517 int rssi, int nf, const struct ieee80211_frame *wh)
519 struct ieee80211vap *vap = ni->ni_vap;
520 struct ieee80211_tdma_state *ts = vap->iv_tdma;
521 const struct ieee80211_tdma_param *tdma =
522 (const struct ieee80211_tdma_param *) ie;
525 KASSERT(vap->iv_caps & IEEE80211_C_TDMA,
526 ("not a tdma vap, caps 0x%x", vap->iv_caps));
528 if (len < sizeof(*tdma) - 2) {
529 IEEE80211_DISCARD_IE(vap,
530 IEEE80211_MSG_ELEMID | IEEE80211_MSG_TDMA,
531 wh, "tdma", "too short, len %u", len);
532 return IEEE80211_REASON_IE_INVALID;
534 if (tdma->tdma_version != ts->tdma_version) {
535 IEEE80211_DISCARD_IE(vap,
536 IEEE80211_MSG_ELEMID | IEEE80211_MSG_TDMA,
537 wh, "tdma", "bad version %u (ours %u)",
538 tdma->tdma_version, ts->tdma_version);
539 return IEEE80211_REASON_IE_INVALID;
542 * NB: ideally we'd check against tdma_slotcnt, but that
543 * would require extra effort so do this easy check that
544 * covers the work below; more stringent checks are done
545 * before we make more extensive use of the ie contents.
547 if (tdma->tdma_slot >= TDMA_MAXSLOTS) {
548 IEEE80211_DISCARD_IE(vap,
549 IEEE80211_MSG_ELEMID | IEEE80211_MSG_TDMA,
550 wh, "tdma", "invalid slot %u", tdma->tdma_slot);
551 return IEEE80211_REASON_IE_INVALID;
554 * Can reach here while scanning, update
555 * operational state only in RUN state.
557 if (vap->iv_state == IEEE80211_S_RUN) {
558 if (tdma->tdma_slot != ts->tdma_slot &&
559 isclr(ts->tdma_inuse, tdma->tdma_slot)) {
560 IEEE80211_NOTE(vap, IEEE80211_MSG_TDMA, ni,
561 "discovered in slot %u", tdma->tdma_slot);
562 setbit(ts->tdma_inuse, tdma->tdma_slot);
563 /* XXX dispatch event only when operating as master */
564 if (ts->tdma_slot == 0)
565 ieee80211_notify_node_join(ni, 1);
567 setbit(ts->tdma_active, tdma->tdma_slot);
568 if (tdma->tdma_slot == ts->tdma_slot-1) {
570 * Slave tsf synchronization to station
571 * just before us in the schedule. The driver
572 * is responsible for copying the timestamp
573 * of the received beacon into our beacon
574 * frame so the sender can calculate round
575 * trip time. We cannot do that here because
576 * we don't know how to update our beacon frame.
578 (void) tdma_update(vap, tdma, ni, 0);
579 /* XXX reschedule swbmiss timer on parameter change */
580 } else if (tdma->tdma_slot == ts->tdma_slot+1) {
583 uint32_t rstamp = (uint32_t) le64toh(rs->tsf);
587 * Use returned timstamp to calculate the
590 memcpy(&tstamp, tdma->tdma_tstamp, 8);
592 /* XXX use only 15 bits of rstamp */
593 rtt = rstamp - (le64toh(tstamp) & 0x7fff);
596 /* XXX hack to quiet normal use */
597 IEEE80211_DPRINTF(vap, IEEE80211_MSG_DOT1X,
598 "tdma rtt %5u [rstamp %5u tstamp %llu]\n",
600 (unsigned long long) le64toh(tstamp));
602 } else if (tdma->tdma_slot == ts->tdma_slot &&
603 le64toh(ni->ni_tstamp.tsf) > vap->iv_bss->ni_tstamp.tsf) {
605 * Station using the same slot as us and has
606 * been around longer than us; we must move.
607 * Note this can happen if stations do not
608 * see each other while scanning.
610 IEEE80211_DPRINTF(vap, IEEE80211_MSG_TDMA,
611 "slot %u collision rxtsf %llu tsf %llu\n",
613 (unsigned long long) le64toh(ni->ni_tstamp.tsf),
614 vap->iv_bss->ni_tstamp.tsf);
615 setbit(ts->tdma_inuse, tdma->tdma_slot);
617 (void) tdma_update(vap, tdma, ni, 1);
624 ieee80211_tdma_getslot(struct ieee80211vap *vap)
626 struct ieee80211_tdma_state *ts = vap->iv_tdma;
628 KASSERT(vap->iv_caps & IEEE80211_C_TDMA,
629 ("not a tdma vap, caps 0x%x", vap->iv_caps));
630 return ts->tdma_slot;
634 * Parse a TDMA ie on station join and use it to setup node state.
637 ieee80211_parse_tdma(struct ieee80211_node *ni, const uint8_t *ie)
639 struct ieee80211vap *vap = ni->ni_vap;
641 if (vap->iv_caps & IEEE80211_C_TDMA) {
642 const struct ieee80211_tdma_param *tdma =
643 (const struct ieee80211_tdma_param *)ie;
644 struct ieee80211_tdma_state *ts = vap->iv_tdma;
646 * Adopt TDMA configuration when joining an
649 setbit(ts->tdma_inuse, tdma->tdma_slot);
650 (void) tdma_update(vap, tdma, ni, 1);
652 * Propagate capabilities based on the local
653 * configuration and the remote station's advertised
654 * capabilities. In particular this permits us to
655 * enable use of QoS to disable ACK's.
657 if ((vap->iv_flags & IEEE80211_F_WME) &&
658 ni->ni_ies.wme_ie != NULL)
659 ni->ni_flags |= IEEE80211_NODE_QOS;
663 #define TDMA_OUI_BYTES 0x00, 0x03, 0x7f
665 * Add a TDMA parameters element to a frame.
668 ieee80211_add_tdma(uint8_t *frm, struct ieee80211vap *vap)
670 #define ADDSHORT(frm, v) do { \
671 frm[0] = (v) & 0xff; \
675 static const struct ieee80211_tdma_param param = {
676 .tdma_id = IEEE80211_ELEMID_VENDOR,
677 .tdma_len = sizeof(struct ieee80211_tdma_param) - 2,
678 .tdma_oui = { TDMA_OUI_BYTES },
679 .tdma_type = TDMA_OUI_TYPE,
680 .tdma_subtype = TDMA_SUBTYPE_PARAM,
681 .tdma_version = TDMA_VERSION,
683 const struct ieee80211_tdma_state *ts = vap->iv_tdma;
686 KASSERT(vap->iv_caps & IEEE80211_C_TDMA,
687 ("not a tdma vap, caps 0x%x", vap->iv_caps));
689 memcpy(frm, ¶m, sizeof(param));
690 frm += __offsetof(struct ieee80211_tdma_param, tdma_slot);
691 *frm++ = ts->tdma_slot;
692 *frm++ = ts->tdma_slotcnt;
693 /* NB: convert units to fit in 16-bits */
694 slotlen = ts->tdma_slotlen / 100; /* 100us units */
695 ADDSHORT(frm, slotlen);
696 *frm++ = ts->tdma_bintval;
697 *frm++ = ts->tdma_inuse[0];
698 frm += 10; /* pad+timestamp */
702 #undef TDMA_OUI_BYTES
705 * Update TDMA state at TBTT.
708 ieee80211_tdma_update_beacon(struct ieee80211vap *vap,
709 struct ieee80211_beacon_offsets *bo)
711 struct ieee80211_tdma_state *ts = vap->iv_tdma;
713 KASSERT(vap->iv_caps & IEEE80211_C_TDMA,
714 ("not a tdma vap, caps 0x%x", vap->iv_caps));
716 if (isset(bo->bo_flags, IEEE80211_BEACON_TDMA)) {
717 (void) ieee80211_add_tdma(bo->bo_tdma, vap);
718 clrbit(bo->bo_flags, IEEE80211_BEACON_TDMA);
720 if (ts->tdma_slot != 0) /* only on master */
722 if (ts->tdma_count <= 0) {
724 * Time to update the mask of active/inuse stations.
725 * We track stations that we've received a beacon
726 * frame from and update this mask periodically.
727 * This allows us to miss a few beacons before marking
728 * a slot free for re-use.
730 ts->tdma_inuse[0] = ts->tdma_active[0];
731 ts->tdma_active[0] = 0x01;
732 /* update next time 'round */
733 /* XXX use notify framework */
734 setbit(bo->bo_flags, IEEE80211_BEACON_TDMA);
735 /* NB: use s/w beacon miss threshold; may be too high */
736 ts->tdma_count = vap->iv_bmissthreshold-1;
742 tdma_ioctl_get80211(struct ieee80211vap *vap, struct ieee80211req *ireq)
744 struct ieee80211_tdma_state *ts = vap->iv_tdma;
746 if ((vap->iv_caps & IEEE80211_C_TDMA) == 0)
749 switch (ireq->i_type) {
750 case IEEE80211_IOC_TDMA_SLOT:
751 ireq->i_val = ts->tdma_slot;
753 case IEEE80211_IOC_TDMA_SLOTCNT:
754 ireq->i_val = ts->tdma_slotcnt;
756 case IEEE80211_IOC_TDMA_SLOTLEN:
757 ireq->i_val = ts->tdma_slotlen;
759 case IEEE80211_IOC_TDMA_BINTERVAL:
760 ireq->i_val = ts->tdma_bintval;
767 IEEE80211_IOCTL_GET(tdma, tdma_ioctl_get80211);
770 tdma_ioctl_set80211(struct ieee80211vap *vap, struct ieee80211req *ireq)
772 struct ieee80211_tdma_state *ts = vap->iv_tdma;
774 if ((vap->iv_caps & IEEE80211_C_TDMA) == 0)
777 switch (ireq->i_type) {
778 case IEEE80211_IOC_TDMA_SLOT:
779 if (!(0 <= ireq->i_val && ireq->i_val <= ts->tdma_slotcnt))
781 if (ireq->i_val != ts->tdma_slot) {
782 ts->tdma_slot = ireq->i_val;
786 case IEEE80211_IOC_TDMA_SLOTCNT:
787 if (!TDMA_SLOTCNT_VALID(ireq->i_val))
789 if (ireq->i_val != ts->tdma_slotcnt) {
790 ts->tdma_slotcnt = ireq->i_val;
794 case IEEE80211_IOC_TDMA_SLOTLEN:
797 * 150 insures at least 1/8 TU
798 * 0xfffff is the max duration for bursting
799 * (implict by way of 16-bit data type for i_val)
801 if (!TDMA_SLOTLEN_VALID(ireq->i_val))
803 if (ireq->i_val != ts->tdma_slotlen) {
804 ts->tdma_slotlen = ireq->i_val;
808 case IEEE80211_IOC_TDMA_BINTERVAL:
809 if (!TDMA_BINTVAL_VALID(ireq->i_val))
811 if (ireq->i_val != ts->tdma_bintval) {
812 ts->tdma_bintval = ireq->i_val;
821 ieee80211_beacon_notify(vap, IEEE80211_BEACON_TDMA);
824 IEEE80211_IOCTL_SET(tdma, tdma_ioctl_set80211);
826 #endif /* IEEE80211_SUPPORT_TDMA */