summaryrefslogtreecommitdiffstats
path: root/sys/net80211
diff options
context:
space:
mode:
authorsam <sam@FreeBSD.org>2009-01-08 17:12:47 +0000
committersam <sam@FreeBSD.org>2009-01-08 17:12:47 +0000
commit98ad45c3d3f257c3649d4e198723267231203184 (patch)
tree6038542738398db4d8d4a8e36ed50ac642a506ac /sys/net80211
parent6f4df3b74deeeb200dfc7f23a8344f50eb34942c (diff)
downloadFreeBSD-src-98ad45c3d3f257c3649d4e198723267231203184.zip
FreeBSD-src-98ad45c3d3f257c3649d4e198723267231203184.tar.gz
TDMA support for long distance point-to-point links using ath devices:
o add net80211 support for a tdma vap that is built on top of the existing adhoc-demo support o add tdma scheduling of frame transmission to the ath driver; it's conceivable other devices might be capable of this too in which case they can make use of the 802.11 protocol additions etc. o add minor bits to user tools that need to know: ifconfig to setup and configure, new statistics in athstats, and new debug mask bits While the architecture can support >2 slots in a TDMA BSS the current design is intended (and tested) for only 2 slots. Sponsored by: Intel
Diffstat (limited to 'sys/net80211')
-rw-r--r--sys/net80211/ieee80211.c17
-rw-r--r--sys/net80211/ieee80211.h24
-rw-r--r--sys/net80211/ieee80211_adhoc.c27
-rw-r--r--sys/net80211/ieee80211_ddb.c4
-rw-r--r--sys/net80211/ieee80211_freebsd.c12
-rw-r--r--sys/net80211/ieee80211_input.c6
-rw-r--r--sys/net80211/ieee80211_input.h8
-rw-r--r--sys/net80211/ieee80211_ioctl.c21
-rw-r--r--sys/net80211/ieee80211_ioctl.h11
-rw-r--r--sys/net80211/ieee80211_node.c16
-rw-r--r--sys/net80211/ieee80211_node.h3
-rw-r--r--sys/net80211/ieee80211_output.c26
-rw-r--r--sys/net80211/ieee80211_proto.h4
-rw-r--r--sys/net80211/ieee80211_scan.h3
-rw-r--r--sys/net80211/ieee80211_scan_sta.c66
-rw-r--r--sys/net80211/ieee80211_tdma.c715
-rw-r--r--sys/net80211/ieee80211_tdma.h66
-rw-r--r--sys/net80211/ieee80211_var.h15
18 files changed, 1024 insertions, 20 deletions
diff --git a/sys/net80211/ieee80211.c b/sys/net80211/ieee80211.c
index e0a9432..ae416f8 100644
--- a/sys/net80211/ieee80211.c
+++ b/sys/net80211/ieee80211.c
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2001 Atsushi Onoe
- * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
+ * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -362,6 +362,21 @@ ieee80211_vap_setup(struct ieee80211com *ic, struct ieee80211vap *vap,
if (flags & IEEE80211_CLONE_WDSLEGACY)
vap->iv_flags_ext |= IEEE80211_FEXT_WDSLEGACY;
break;
+#ifdef IEEE80211_SUPPORT_TDMA
+ case IEEE80211_M_AHDEMO:
+ if (flags & IEEE80211_CLONE_TDMA) {
+ /* NB: checked before clone operation allowed */
+ KASSERT(ic->ic_caps & IEEE80211_C_TDMA,
+ ("not TDMA capable, ic_caps 0x%x", ic->ic_caps));
+ /*
+ * Propagate TDMA capability to mark vap; this
+ * cannot be removed and is used to distinguish
+ * regular ahdemo operation from ahdemo+tdma.
+ */
+ vap->iv_caps |= IEEE80211_C_TDMA;
+ }
+ break;
+#endif
}
/* auto-enable s/w beacon miss support */
if (flags & IEEE80211_CLONE_NOBEACONS)
diff --git a/sys/net80211/ieee80211.h b/sys/net80211/ieee80211.h
index d8fc7dd..6caaefd 100644
--- a/sys/net80211/ieee80211.h
+++ b/sys/net80211/ieee80211.h
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2001 Atsushi Onoe
- * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
+ * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -1064,4 +1064,26 @@ struct ieee80211_duration {
#define ATH_FF_SNAP_ORGCODE_1 0x03
#define ATH_FF_SNAP_ORGCODE_2 0x7f
+struct ieee80211_tdma_param {
+ u_int8_t tdma_id; /* IEEE80211_ELEMID_VENDOR */
+ u_int8_t tdma_len;
+ u_int8_t tdma_oui[3]; /* 0x00, 0x03, 0x7f */
+ u_int8_t tdma_type; /* OUI type */
+ u_int8_t tdma_subtype; /* OUI subtype */
+ u_int8_t tdma_version; /* spec revision */
+ u_int8_t tdma_slot; /* station slot # */
+ u_int8_t tdma_slotcnt; /* bss slot count */
+ u_int16_t tdma_slotlen; /* bss slot len (100us) */
+ u_int8_t tdma_bintval; /* beacon interval (superframes) */
+ u_int8_t tdma_inuse[1]; /* slot occupancy map */
+ u_int8_t tdma_pad[2];
+ u_int8_t tdma_tstamp[8]; /* timestamp from last beacon */
+} __packed;
+
+/* NB: Atheros allocated the OUI for this purpose ~3 years ago but beware ... */
+#define TDMA_OUI ATH_OUI
+#define TDMA_OUI_TYPE 0x02
+#define TDMA_SUBTYPE_PARAM 0x01
+#define TDMA_VERSION 2
+
#endif /* _NET80211_IEEE80211_H_ */
diff --git a/sys/net80211/ieee80211_adhoc.c b/sys/net80211/ieee80211_adhoc.c
index b8a5f7f..7e64964 100644
--- a/sys/net80211/ieee80211_adhoc.c
+++ b/sys/net80211/ieee80211_adhoc.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting
+ * Copyright (c) 2007-2009 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -57,6 +57,9 @@ __FBSDID("$FreeBSD$");
#include <net80211/ieee80211_var.h>
#include <net80211/ieee80211_adhoc.h>
#include <net80211/ieee80211_input.h>
+#ifdef IEEE80211_SUPPORT_TDMA
+#include <net80211/ieee80211_tdma.h>
+#endif
#define IEEE80211_RATE2MBS(r) (((r) & IEEE80211_RATE_VAL) / 2)
@@ -96,6 +99,15 @@ adhoc_vattach(struct ieee80211vap *vap)
else
vap->iv_recv_mgmt = ahdemo_recv_mgmt;
vap->iv_opdetach = adhoc_vdetach;
+#ifdef IEEE80211_SUPPORT_TDMA
+ /*
+ * Throw control to tdma support. Note we do this
+ * after setting up our callbacks so it can piggyback
+ * on top of us.
+ */
+ if (vap->iv_caps & IEEE80211_C_TDMA)
+ ieee80211_tdma_vattach(vap);
+#endif
}
/*
@@ -355,6 +367,19 @@ adhoc_input(struct ieee80211_node *ni, struct mbuf *m,
ni == vap->iv_bss &&
!IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_macaddr)) {
/*
+ * Beware of frames that come in too early; we
+ * can receive broadcast frames and creating sta
+ * entries will blow up because there is no bss
+ * channel yet.
+ */
+ if (vap->iv_state != IEEE80211_S_RUN) {
+ IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
+ wh, "data", "not in RUN state (%s)",
+ ieee80211_state_name[vap->iv_state]);
+ vap->iv_stats.is_rx_badstate++;
+ goto err;
+ }
+ /*
* Fake up a node for this newly
* discovered member of the IBSS.
*/
diff --git a/sys/net80211/ieee80211_ddb.c b/sys/net80211/ieee80211_ddb.c
index 59c6a46..4451dd6 100644
--- a/sys/net80211/ieee80211_ddb.c
+++ b/sys/net80211/ieee80211_ddb.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting
+ * Copyright (c) 2007-2009 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -76,7 +76,7 @@ __FBSDID("$FreeBSD$");
"\20\1STA\7FF\10TURBOP\11IBSS\12PMGT" \
"\13HOSTAP\14AHDEMO\15SWRETRY\16TXPMGT\17SHSLOT\20SHPREAMBLE" \
"\21MONITOR\22DFS\30WPA1\31WPA2\32BURST\33WME\34WDS\36BGSCAN" \
- "\37TXFRAG"
+ "\37TXFRAG\40TDMA"
#define IEEE80211_C_CRYPTO_BITS \
"\20\1WEP\2TKIP\3AES\4AES_CCM\5TKIPMIC\6CKIP\12PMGT"
diff --git a/sys/net80211/ieee80211_freebsd.c b/sys/net80211/ieee80211_freebsd.c
index 60de0f4..5f44f1c 100644
--- a/sys/net80211/ieee80211_freebsd.c
+++ b/sys/net80211/ieee80211_freebsd.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2003-2008 Sam Leffler, Errno Consulting
+ * Copyright (c) 2003-2009 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -124,6 +124,16 @@ wlan_clone_create(struct if_clone *ifc, int unit, caddr_t params)
ieee80211_opmode_name[cp.icp_opmode]);
return EOPNOTSUPP;
}
+ if ((cp.icp_flags & IEEE80211_CLONE_TDMA) &&
+#ifdef IEEE80211_SUPPORT_TDMA
+ (ic->ic_caps & IEEE80211_C_TDMA) == 0
+#else
+ (1)
+#endif
+ ) {
+ if_printf(ifp, "TDMA not supported\n");
+ return EOPNOTSUPP;
+ }
vap = ic->ic_vap_create(ic, ifc->ifc_name, unit,
cp.icp_opmode, cp.icp_flags, cp.icp_bssid,
cp.icp_flags & IEEE80211_CLONE_MACADDR ?
diff --git a/sys/net80211/ieee80211_input.c b/sys/net80211/ieee80211_input.c
index e68bb6c..23f770b 100644
--- a/sys/net80211/ieee80211_input.c
+++ b/sys/net80211/ieee80211_input.c
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2001 Atsushi Onoe
- * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
+ * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -635,6 +635,10 @@ ieee80211_parse_beacon(struct ieee80211_node *ni, struct mbuf *m,
scan->wme = frm;
else if (isatherosoui(frm))
scan->ath = frm;
+#ifdef IEEE80211_SUPPORT_TDMA
+ else if (istdmaoui(frm))
+ scan->tdma = frm;
+#endif
else if (vap->iv_flags_ext & IEEE80211_FEXT_HTCOMPAT) {
/*
* Accept pre-draft HT ie's if the
diff --git a/sys/net80211/ieee80211_input.h b/sys/net80211/ieee80211_input.h
index dd41d7c..b656c55 100644
--- a/sys/net80211/ieee80211_input.h
+++ b/sys/net80211/ieee80211_input.h
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2007-2008 Sam Leffler, Errno Consulting
+ * Copyright (c) 2007-2009 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -125,6 +125,12 @@ isatherosoui(const uint8_t *frm)
}
static __inline int
+istdmaoui(const uint8_t *frm)
+{
+ return frm[1] > 3 && LE_READ_4(frm+2) == ((TDMA_OUI_TYPE<<24)|TDMA_OUI);
+}
+
+static __inline int
ishtcapoui(const uint8_t *frm)
{
return frm[1] > 3 && LE_READ_4(frm+2) == ((BCM_OUI_HTCAP<<24)|BCM_OUI);
diff --git a/sys/net80211/ieee80211_ioctl.c b/sys/net80211/ieee80211_ioctl.c
index b967e47..3f62850 100644
--- a/sys/net80211/ieee80211_ioctl.c
+++ b/sys/net80211/ieee80211_ioctl.c
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2001 Atsushi Onoe
- * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
+ * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -62,6 +62,9 @@ __FBSDID("$FreeBSD$");
#include <net80211/ieee80211_ioctl.h>
#include <net80211/ieee80211_regdomain.h>
#include <net80211/ieee80211_input.h>
+#ifdef IEEE80211_SUPPORT_TDMA
+#include <net80211/ieee80211_tdma.h>
+#endif
#define IS_UP_AUTO(_vap) \
(IFNET_IS_UP_RUNNING(vap->iv_ifp) && \
@@ -1089,6 +1092,14 @@ ieee80211_ioctl_get80211(struct ieee80211vap *vap, u_long cmd,
ireq->i_val =
(vap->iv_flags_ext & IEEE80211_FEXT_RIFS) != 0;
break;
+#ifdef IEEE80211_SUPPORT_TDMA
+ case IEEE80211_IOC_TDMA_SLOT:
+ case IEEE80211_IOC_TDMA_SLOTCNT:
+ case IEEE80211_IOC_TDMA_SLOTLEN:
+ case IEEE80211_IOC_TDMA_BINTERVAL:
+ error = ieee80211_tdma_ioctl_get80211(vap, ireq);
+ break;
+#endif
default:
error = EINVAL;
break;
@@ -3105,6 +3116,14 @@ ieee80211_ioctl_set80211(struct ieee80211vap *vap, u_long cmd, struct ieee80211r
if (isvapht(vap))
error = ERESTART;
break;
+#ifdef IEEE80211_SUPPORT_TDMA
+ case IEEE80211_IOC_TDMA_SLOT:
+ case IEEE80211_IOC_TDMA_SLOTCNT:
+ case IEEE80211_IOC_TDMA_SLOTLEN:
+ case IEEE80211_IOC_TDMA_BINTERVAL:
+ error = ieee80211_tdma_ioctl_set80211(vap, ireq);
+ break;
+#endif
default:
error = EINVAL;
break;
diff --git a/sys/net80211/ieee80211_ioctl.h b/sys/net80211/ieee80211_ioctl.h
index cf4678b..19c94b4 100644
--- a/sys/net80211/ieee80211_ioctl.h
+++ b/sys/net80211/ieee80211_ioctl.h
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2001 Atsushi Onoe
- * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
+ * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -216,7 +216,8 @@ struct ieee80211_stats {
uint8_t is_rx_disassoc_code; /* last rx'd disassoc reason */
uint8_t is_rx_authfail_code; /* last rx'd auth fail reason */
uint32_t is_beacon_miss; /* beacon miss notification */
- uint32_t is_spare[13];
+ uint32_t is_rx_badstate; /* rx discard state != RUN */
+ uint32_t is_spare[12];
};
/*
@@ -612,6 +613,11 @@ struct ieee80211req {
#define IEEE80211_IOC_SMPS 110 /* MIMO power save */
#define IEEE80211_IOC_RIFS 111 /* RIFS config (on, off) */
+#define IEEE80211_IOC_TDMA_SLOT 201 /* TDMA: assigned slot */
+#define IEEE80211_IOC_TDMA_SLOTCNT 202 /* TDMA: slots in bss */
+#define IEEE80211_IOC_TDMA_SLOTLEN 203 /* TDMA: slot length (usecs) */
+#define IEEE80211_IOC_TDMA_BINTERVAL 204 /* TDMA: beacon intvl (slots) */
+
/*
* Parameters for controlling a scan requested with
* IEEE80211_IOC_SCAN_REQ.
@@ -738,6 +744,7 @@ struct ieee80211_clone_params {
#define IEEE80211_CLONE_NOBEACONS 0x0002 /* don't setup beacon timers */
#define IEEE80211_CLONE_WDSLEGACY 0x0004 /* legacy WDS processing */
#define IEEE80211_CLONE_MACADDR 0x0008 /* use specified mac addr */
+#define IEEE80211_CLONE_TDMA 0x0010 /* operate in TDMA mode */
#endif /* __FreeBSD__ */
#endif /* _NET80211_IEEE80211_IOCTL_H_ */
diff --git a/sys/net80211/ieee80211_node.c b/sys/net80211/ieee80211_node.c
index d01b766..8aa9770 100644
--- a/sys/net80211/ieee80211_node.c
+++ b/sys/net80211/ieee80211_node.c
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2001 Atsushi Onoe
- * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
+ * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -43,6 +43,9 @@ __FBSDID("$FreeBSD$");
#include <net80211/ieee80211_var.h>
#include <net80211/ieee80211_input.h>
+#ifdef IEEE80211_SUPPORT_TDMA
+#include <net80211/ieee80211_tdma.h>
+#endif
#include <net80211/ieee80211_wds.h>
#include <net/bpf.h>
@@ -337,6 +340,9 @@ ieee80211_create_ibss(struct ieee80211vap* vap, struct ieee80211_channel *chan)
if (vap->iv_flags & IEEE80211_F_DESBSSID)
IEEE80211_ADDR_COPY(ni->ni_bssid, vap->iv_des_bssid);
else
+#ifdef IEEE80211_SUPPORT_TDMA
+ if ((vap->iv_caps & IEEE80211_C_TDMA) == 0)
+#endif
memset(ni->ni_bssid, 0, IEEE80211_ADDR_LEN);
}
/*
@@ -745,6 +751,10 @@ ieee80211_sta_join(struct ieee80211vap *vap, struct ieee80211_channel *chan,
ieee80211_parse_htcap(ni, ni->ni_ies.htcap_ie);
if (ni->ni_ies.htinfo_ie != NULL)
ieee80211_parse_htinfo(ni, ni->ni_ies.htinfo_ie);
+#ifdef IEEE80211_SUPPORT_TDMA
+ if (ni->ni_ies.tdma_ie != NULL)
+ ieee80211_parse_tdma(ni, ni->ni_ies.tdma_ie);
+#endif
}
vap->iv_dtim_period = se->se_dtimperiod;
@@ -858,6 +868,10 @@ ieee80211_ies_expand(struct ieee80211_ies *ies)
ies->wme_ie = ie;
else if (isatherosoui(ie))
ies->ath_ie = ie;
+#ifdef IEEE80211_SUPPORT_TDMA
+ else if (istdmaoui(ie))
+ ies->tdma_ie = ie;
+#endif
break;
case IEEE80211_ELEMID_RSN:
ies->rsn_ie = ie;
diff --git a/sys/net80211/ieee80211_node.h b/sys/net80211/ieee80211_node.h
index bd304d5..7a21f45 100644
--- a/sys/net80211/ieee80211_node.h
+++ b/sys/net80211/ieee80211_node.h
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2001 Atsushi Onoe
- * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
+ * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -80,6 +80,7 @@ struct ieee80211_ies {
uint8_t *ath_ie; /* captured Atheros ie */
uint8_t *htcap_ie; /* captured HTCAP ie */
uint8_t *htinfo_ie; /* captured HTINFO ie */
+ uint8_t *tdma_ie; /* captured TDMA ie */
/* NB: these must be the last members of this structure */
uint8_t *data; /* frame data > 802.11 header */
int len; /* data size in bytes */
diff --git a/sys/net80211/ieee80211_output.c b/sys/net80211/ieee80211_output.c
index 2f10232..f589aa9 100644
--- a/sys/net80211/ieee80211_output.c
+++ b/sys/net80211/ieee80211_output.c
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2001 Atsushi Onoe
- * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
+ * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -47,6 +47,9 @@ __FBSDID("$FreeBSD$");
#include <net80211/ieee80211_var.h>
#include <net80211/ieee80211_regdomain.h>
+#ifdef IEEE80211_SUPPORT_TDMA
+#include <net80211/ieee80211_tdma.h>
+#endif
#include <net80211/ieee80211_wds.h>
#ifdef INET
@@ -2500,6 +2503,7 @@ ieee80211_beacon_construct(struct mbuf *m, uint8_t *frm,
* [tlv] WME parameters
* [tlv] Vendor OUI HT capabilities (optional)
* [tlv] Vendor OUI HT information (optional)
+ * [tlv] TDMA parameters (optional)
* [tlv] application data (optional)
*/
@@ -2589,6 +2593,12 @@ ieee80211_beacon_construct(struct mbuf *m, uint8_t *frm,
frm = ieee80211_add_htcap_vendor(frm, ni);
frm = ieee80211_add_htinfo_vendor(frm, ni);
}
+#ifdef IEEE80211_SUPPORT_TDMA
+ if (vap->iv_caps & IEEE80211_C_TDMA) {
+ bo->bo_tdma = frm;
+ frm = ieee80211_add_tdma(frm, vap);
+ }
+#endif
if (vap->iv_appie_beacon != NULL) {
bo->bo_appie = frm;
bo->bo_appie_len = vap->iv_appie_beacon->ie_len;
@@ -2637,6 +2647,7 @@ ieee80211_beacon_alloc(struct ieee80211_node *ni,
* XXX Vendor-specific OIDs (e.g. Atheros)
* [tlv] WPA parameters
* [tlv] WME parameters
+ * [tlv] TDMA parameters (optional)
* [tlv] application data (optional)
* NB: we allocate the max space required for the TIM bitmap.
* XXX how big is this?
@@ -2661,6 +2672,10 @@ ieee80211_beacon_alloc(struct ieee80211_node *ni,
+ 4+2*sizeof(struct ieee80211_ie_htinfo)/* HT info */
+ (vap->iv_caps & IEEE80211_C_WME ? /* WME */
sizeof(struct ieee80211_wme_param) : 0)
+#ifdef IEEE80211_SUPPORT_TDMA
+ + (vap->iv_caps & IEEE80211_C_TDMA ? /* TDMA */
+ sizeof(struct ieee80211_tdma_param) : 0)
+#endif
+ IEEE80211_MAX_APPIE
;
m = ieee80211_getmgtframe(&frm,
@@ -2779,7 +2794,14 @@ ieee80211_beacon_update(struct ieee80211_node *ni,
ieee80211_ht_update_beacon(vap, bo);
clrbit(bo->bo_flags, IEEE80211_BEACON_HTINFO);
}
-
+#ifdef IEEE80211_SUPPORT_TDMA
+ if (vap->iv_caps & IEEE80211_C_TDMA) {
+ /*
+ * NB: the beacon is potentially updated every TBTT.
+ */
+ ieee80211_tdma_update_beacon(vap, bo);
+ }
+#endif
if (vap->iv_opmode == IEEE80211_M_HOSTAP) { /* NB: no IBSS support*/
struct ieee80211_tim_ie *tie =
(struct ieee80211_tim_ie *) bo->bo_tim;
diff --git a/sys/net80211/ieee80211_proto.h b/sys/net80211/ieee80211_proto.h
index e25d103..f7395b6 100644
--- a/sys/net80211/ieee80211_proto.h
+++ b/sys/net80211/ieee80211_proto.h
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2001 Atsushi Onoe
- * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
+ * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -291,6 +291,7 @@ struct ieee80211_beacon_offsets {
uint8_t *bo_cfp; /* start of CFParms element */
uint8_t *bo_tim; /* start of atim/dtim */
uint8_t *bo_wme; /* start of WME parameters */
+ uint8_t *bo_tdma; /* start of TDMA parameters */
uint8_t *bo_tim_trailer;/* start of fixed-size trailer */
uint16_t bo_tim_len; /* atim/dtim length in bytes */
uint16_t bo_tim_trailer_len;/* tim trailer length in bytes */
@@ -325,6 +326,7 @@ enum {
IEEE80211_BEACON_APPIE = 5, /* Application IE's */
IEEE80211_BEACON_CFP = 6, /* CFParms */
IEEE80211_BEACON_CSA = 7, /* Channel Switch Announcement */
+ IEEE80211_BEACON_TDMA = 9, /* TDMA Info */
};
int ieee80211_beacon_update(struct ieee80211_node *,
struct ieee80211_beacon_offsets *, struct mbuf *, int mcast);
diff --git a/sys/net80211/ieee80211_scan.h b/sys/net80211/ieee80211_scan.h
index df6ce1f7..3b58cff 100644
--- a/sys/net80211/ieee80211_scan.h
+++ b/sys/net80211/ieee80211_scan.h
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2005-2008 Sam Leffler, Errno Consulting
+ * Copyright (c) 2005-2009 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -209,6 +209,7 @@ struct ieee80211_scanparams {
uint8_t *htcap;
uint8_t *htinfo;
uint8_t *ath;
+ uint8_t *tdma;
};
/*
diff --git a/sys/net80211/ieee80211_scan_sta.c b/sys/net80211/ieee80211_scan_sta.c
index 15e4ff6..e2edaf2 100644
--- a/sys/net80211/ieee80211_scan_sta.c
+++ b/sys/net80211/ieee80211_scan_sta.c
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
+ * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -45,6 +45,9 @@ __FBSDID("$FreeBSD$");
#include <net80211/ieee80211_var.h>
#include <net80211/ieee80211_input.h>
#include <net80211/ieee80211_regdomain.h>
+#ifdef IEEE80211_SUPPORT_TDMA
+#include <net80211/ieee80211_tdma.h>
+#endif
#include <net/bpf.h>
@@ -119,6 +122,10 @@ static void sta_flush_table(struct sta_table *);
#define MATCH_NOTSEEN 0x0080 /* not seen in recent scans */
#define MATCH_RSSI 0x0100 /* rssi deemed too low to use */
#define MATCH_CC 0x0200 /* country code mismatch */
+#define MATCH_TDMA_NOIE 0x0400 /* no TDMA ie */
+#define MATCH_TDMA_NOTMASTER 0x0800 /* not TDMA master */
+#define MATCH_TDMA_NOSLOT 0x1000 /* all TDMA slots occupied */
+#define MATCH_TDMA_LOCAL 0x2000 /* local address */
static int match_bss(struct ieee80211vap *,
const struct ieee80211_scan_state *, struct sta_entry *, int);
static void adhoc_age(struct ieee80211_scan_state *);
@@ -870,6 +877,20 @@ match_ssid(const uint8_t *ie,
return 0;
}
+#ifdef IEEE80211_SUPPORT_TDMA
+static int
+tdma_isfull(const struct ieee80211_tdma_param *tdma)
+{
+ int slot, slotcnt;
+
+ slotcnt = tdma->tdma_slotcnt;
+ for (slot = slotcnt-1; slot >= 0; slot--)
+ if (isclr(tdma->tdma_inuse, slot))
+ return 0;
+ return 1;
+}
+#endif /* IEEE80211_SUPPORT_TDMA */
+
/*
* Test a scan candidate for suitability/compatibility.
*/
@@ -900,6 +921,36 @@ match_bss(struct ieee80211vap *vap,
if (vap->iv_opmode == IEEE80211_M_IBSS) {
if ((se->se_capinfo & IEEE80211_CAPINFO_IBSS) == 0)
fail |= MATCH_CAPINFO;
+#ifdef IEEE80211_SUPPORT_TDMA
+ } else if (vap->iv_opmode == IEEE80211_M_AHDEMO) {
+ /*
+ * Adhoc demo network setup shouldn't really be scanning
+ * but just in case skip stations operating in IBSS or
+ * BSS mode.
+ */
+ if (se->se_capinfo & (IEEE80211_CAPINFO_IBSS|IEEE80211_CAPINFO_ESS))
+ fail |= MATCH_CAPINFO;
+ /*
+ * TDMA operation cannot coexist with a normal 802.11 network;
+ * skip if IBSS or ESS capabilities are marked and require
+ * the beacon have a TDMA ie present.
+ */
+ if (vap->iv_caps & IEEE80211_C_TDMA) {
+ const struct ieee80211_tdma_param *tdma =
+ (const struct ieee80211_tdma_param *)se->se_ies.tdma_ie;
+
+ if (tdma == NULL)
+ fail |= MATCH_TDMA_NOIE;
+ else if (tdma->tdma_slot != 0)
+ fail |= MATCH_TDMA_NOTMASTER;
+ else if (tdma_isfull(tdma))
+ fail |= MATCH_TDMA_NOSLOT;
+#if 0
+ else if (ieee80211_local_address(se->se_macaddr))
+ fail |= MATCH_TDMA_LOCAL;
+#endif
+ }
+#endif /* IEEE80211_SUPPORT_TDMA */
} else {
if ((se->se_capinfo & IEEE80211_CAPINFO_ESS) == 0)
fail |= MATCH_CAPINFO;
@@ -977,6 +1028,12 @@ match_bss(struct ieee80211vap *vap,
fail & MATCH_FAILS ? '=' :
fail & MATCH_NOTSEEN ? '^' :
fail & MATCH_CC ? '$' :
+#ifdef IEEE80211_SUPPORT_TDMA
+ fail & MATCH_TDMA_NOIE ? '&' :
+ fail & MATCH_TDMA_NOTMASTER ? ':' :
+ fail & MATCH_TDMA_NOSLOT ? '@' :
+ fail & MATCH_TDMA_LOCAL ? '#' :
+#endif
fail ? '-' : '+', ether_sprintf(se->se_macaddr));
printf(" %s%c", ether_sprintf(se->se_bssid),
fail & MATCH_BSSID ? '!' : ' ');
@@ -1449,7 +1506,14 @@ adhoc_pick_bss(struct ieee80211_scan_state *ss, struct ieee80211vap *vap)
if (ss->ss_flags & IEEE80211_SCAN_NOJOIN)
return 0;
notfound:
+ /* NB: never auto-start a tdma network for slot !0 */
+#ifdef IEEE80211_SUPPORT_TDMA
+ if (vap->iv_des_nssid &&
+ ((vap->iv_caps & IEEE80211_C_TDMA) == 0 ||
+ ieee80211_tdma_getslot(vap) == 0)) {
+#else
if (vap->iv_des_nssid) {
+#endif
/*
* No existing adhoc network to join and we have
* an ssid; start one up. If no channel was
diff --git a/sys/net80211/ieee80211_tdma.c b/sys/net80211/ieee80211_tdma.c
new file mode 100644
index 0000000..b41e0f8
--- /dev/null
+++ b/sys/net80211/ieee80211_tdma.c
@@ -0,0 +1,715 @@
+/*-
+ * Copyright (c) 2007-2009 Sam Leffler, Errno Consulting
+ * Copyright (c) 2007-2009 Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifdef __FreeBSD__
+__FBSDID("$FreeBSD$");
+#endif
+
+/*
+ * IEEE 802.11 TDMA mode support.
+ */
+#include "opt_inet.h"
+#include "opt_wlan.h"
+
+#ifdef IEEE80211_SUPPORT_TDMA
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mbuf.h>
+#include <sys/malloc.h>
+#include <sys/kernel.h>
+
+#include <sys/socket.h>
+#include <sys/sockio.h>
+#include <sys/endian.h>
+#include <sys/errno.h>
+#include <sys/proc.h>
+#include <sys/sysctl.h>
+
+#include <net/if.h>
+#include <net/if_media.h>
+#include <net/if_llc.h>
+#include <net/ethernet.h>
+
+#include <net/bpf.h>
+
+#include <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_tdma.h>
+#include <net80211/ieee80211_input.h>
+
+#include "opt_tdma.h"
+#ifndef TDMA_SLOTLEN_DEFAULT
+#define TDMA_SLOTLEN_DEFAULT 10*1000 /* 10ms */
+#endif
+#ifndef TDMA_SLOTCNT_DEFAULT
+#define TDMA_SLOTCNT_DEFAULT 2 /* 2x (pt-to-pt) */
+#endif
+#ifndef TDMA_BINTVAL_DEFAULT
+#define TDMA_BINTVAL_DEFAULT 5 /* 5x ~= 100TU beacon intvl */
+#endif
+#ifndef TDMA_TXRATE_11B_DEFAULT
+#define TDMA_TXRATE_11B_DEFAULT 2*11
+#endif
+#ifndef TDMA_TXRATE_11G_DEFAULT
+#define TDMA_TXRATE_11G_DEFAULT 2*24
+#endif
+#ifndef TDMA_TXRATE_11A_DEFAULT
+#define TDMA_TXRATE_11A_DEFAULT 2*24
+#endif
+
+static void tdma_vdetach(struct ieee80211vap *vap);
+static int tdma_newstate(struct ieee80211vap *, enum ieee80211_state, int);
+static void tdma_beacon_miss(struct ieee80211vap *vap);
+static void tdma_recv_mgmt(struct ieee80211_node *, struct mbuf *,
+ int subtype, int rssi, int noise, uint32_t rstamp);
+static int tdma_update(struct ieee80211vap *vap,
+ const struct ieee80211_tdma_param *tdma, struct ieee80211_node *ni,
+ int pickslot);
+static int tdma_process_params(struct ieee80211_node *ni,
+ const u_int8_t *ie, u_int32_t rstamp, const struct ieee80211_frame *wh);
+
+static void
+setackpolicy(struct ieee80211com *ic, int noack)
+{
+ struct ieee80211_wme_state *wme = &ic->ic_wme;
+ int ac;
+
+ for (ac = 0; ac < WME_NUM_AC; ac++) {
+ wme->wme_chanParams.cap_wmeParams[ac].wmep_noackPolicy = noack;
+ wme->wme_wmeChanParams.cap_wmeParams[ac].wmep_noackPolicy = noack;
+ }
+}
+
+void
+ieee80211_tdma_vattach(struct ieee80211vap *vap)
+{
+ struct ieee80211_tdma_state *ts;
+
+ KASSERT(vap->iv_caps & IEEE80211_C_TDMA,
+ ("not a tdma vap, caps 0x%x", vap->iv_caps));
+
+ ts = (struct ieee80211_tdma_state *) malloc(
+ sizeof(struct ieee80211_tdma_state), M_80211_VAP, M_NOWAIT | M_ZERO);
+ if (ts == NULL) {
+ printf("%s: cannot allocate TDMA state block\n", __func__);
+ /* NB: fall back to adhdemo mode */
+ vap->iv_caps &= ~IEEE80211_C_TDMA;
+ return;
+ }
+ /* NB: default configuration is passive so no beacons */
+ ts->tdma_slotlen = TDMA_SLOTLEN_DEFAULT;
+ ts->tdma_slotcnt = TDMA_SLOTCNT_DEFAULT;
+ ts->tdma_bintval = TDMA_BINTVAL_DEFAULT;
+ ts->tdma_slot = 1; /* passive operation */
+
+ /* setup default fixed rates */
+ vap->iv_txparms[IEEE80211_MODE_11B].ucastrate = TDMA_TXRATE_11B_DEFAULT;
+ vap->iv_txparms[IEEE80211_MODE_11B].mcastrate = TDMA_TXRATE_11B_DEFAULT;
+ vap->iv_txparms[IEEE80211_MODE_11G].ucastrate = TDMA_TXRATE_11G_DEFAULT;
+ vap->iv_txparms[IEEE80211_MODE_11G].mcastrate = TDMA_TXRATE_11G_DEFAULT;
+ vap->iv_txparms[IEEE80211_MODE_11A].ucastrate = TDMA_TXRATE_11A_DEFAULT;
+ vap->iv_txparms[IEEE80211_MODE_11A].mcastrate = TDMA_TXRATE_11A_DEFAULT;
+
+ setackpolicy(vap->iv_ic, 1); /* disable ACK's */
+
+ ts->tdma_opdetach = vap->iv_opdetach;
+ vap->iv_opdetach = tdma_vdetach;
+ ts->tdma_newstate = vap->iv_newstate;
+ vap->iv_newstate = tdma_newstate;
+ vap->iv_bmiss = tdma_beacon_miss;
+ ts->tdma_recv_mgmt = vap->iv_recv_mgmt;
+ vap->iv_recv_mgmt = tdma_recv_mgmt;
+
+ vap->iv_tdma = ts;
+}
+
+static void
+tdma_vdetach(struct ieee80211vap *vap)
+{
+ struct ieee80211_tdma_state *ts = vap->iv_tdma;
+
+ ts->tdma_opdetach(vap);
+ free(vap->iv_tdma, M_80211_VAP);
+
+ setackpolicy(vap->iv_ic, 0); /* enable ACK's */
+}
+
+/*
+ * TDMA state machine handler.
+ */
+static int
+tdma_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg)
+{
+ struct ieee80211_tdma_state *ts = vap->iv_tdma;
+ enum ieee80211_state ostate;
+ int status;
+
+ IEEE80211_LOCK_ASSERT(vap->iv_ic);
+
+ ostate = vap->iv_state;
+ IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE, "%s: %s -> %s (%d)\n",
+ __func__, ieee80211_state_name[ostate],
+ ieee80211_state_name[nstate], arg);
+
+ if (vap->iv_flags_ext & IEEE80211_FEXT_SWBMISS)
+ callout_stop(&vap->iv_swbmiss);
+ if (nstate == IEEE80211_S_SCAN &&
+ (ostate == IEEE80211_S_INIT || ostate == IEEE80211_S_RUN) &&
+ ts->tdma_slot != 0) {
+ /*
+ * Override adhoc behaviour when operating as a slave;
+ * we need to scan even if the channel is locked.
+ */
+ vap->iv_state = nstate; /* state transition */
+ ieee80211_cancel_scan(vap); /* background scan */
+ if (vap->iv_flags_ext & IEEE80211_FEXT_SCANREQ) {
+ ieee80211_check_scan(vap,
+ vap->iv_scanreq_flags,
+ vap->iv_scanreq_duration,
+ vap->iv_scanreq_mindwell,
+ vap->iv_scanreq_maxdwell,
+ vap->iv_scanreq_nssid, vap->iv_scanreq_ssid);
+ vap->iv_flags_ext &= ~IEEE80211_FEXT_SCANREQ;
+ } else
+ ieee80211_check_scan_current(vap);
+ status = 0;
+ } else {
+ status = ts->tdma_newstate(vap, nstate, arg);
+ }
+ if (status == 0 &&
+ nstate == IEEE80211_S_RUN && ostate != IEEE80211_S_RUN &&
+ (vap->iv_flags_ext & IEEE80211_FEXT_SWBMISS) &&
+ ts->tdma_slot != 0) {
+ /*
+ * Start s/w beacon miss timer for slave devices w/o
+ * hardware support. The 2x is a fudge for our doing
+ * this in software.
+ */
+ vap->iv_swbmiss_period = IEEE80211_TU_TO_TICKS(
+ 2 * vap->iv_bmissthreshold * ts->tdma_bintval *
+ ((ts->tdma_slotcnt * ts->tdma_slotlen) / 1024));
+ vap->iv_swbmiss_count = 0;
+ callout_reset(&vap->iv_swbmiss, vap->iv_swbmiss_period,
+ ieee80211_swbmiss, vap);
+ }
+ return status;
+}
+
+static void
+tdma_beacon_miss(struct ieee80211vap *vap)
+{
+ struct ieee80211_tdma_state *ts = vap->iv_tdma;
+
+ KASSERT((vap->iv_ic->ic_flags & IEEE80211_F_SCAN) == 0, ("scanning"));
+ KASSERT(vap->iv_state == IEEE80211_S_RUN,
+ ("wrong state %d", vap->iv_state));
+
+ IEEE80211_DPRINTF(vap,
+ IEEE80211_MSG_STATE | IEEE80211_MSG_TDMA | IEEE80211_MSG_DEBUG,
+ "beacon miss, mode %u state %s\n",
+ vap->iv_opmode, ieee80211_state_name[vap->iv_state]);
+
+ if (ts->tdma_peer != NULL) { /* XXX? can this be null? */
+ ieee80211_notify_node_leave(vap->iv_bss);
+ ts->tdma_peer = NULL;
+ /*
+ * Treat beacon miss like an associate failure wrt the
+ * scan policy; this forces the entry in the scan cache
+ * to be ignored after several tries.
+ */
+ ieee80211_scan_assoc_fail(vap, vap->iv_bss->ni_macaddr,
+ IEEE80211_STATUS_TIMEOUT);
+ }
+#if 0
+ ts->tdma_inuse = 0; /* clear slot usage */
+#endif
+ ieee80211_new_state(vap, IEEE80211_S_SCAN, 0);
+}
+
+static void
+tdma_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m0,
+ int subtype, int rssi, int noise, uint32_t rstamp)
+{
+ struct ieee80211com *ic = ni->ni_ic;
+ struct ieee80211vap *vap = ni->ni_vap;
+ struct ieee80211_tdma_state *ts = vap->iv_tdma;
+
+ if (subtype == IEEE80211_FC0_SUBTYPE_BEACON &&
+ (ic->ic_flags & IEEE80211_F_SCAN) == 0) {
+ struct ieee80211_frame *wh = mtod(m0, struct ieee80211_frame *);
+ struct ieee80211_scanparams scan;
+
+ if (ieee80211_parse_beacon(ni, m0, &scan) != 0)
+ return;
+ if (scan.tdma == NULL) {
+ /*
+ * TDMA stations must beacon a TDMA ie; ignore
+ * any other station.
+ * XXX detect overlapping bss and change channel
+ */
+ IEEE80211_DISCARD(vap,
+ IEEE80211_MSG_ELEMID | IEEE80211_MSG_INPUT,
+ wh, ieee80211_mgt_subtype_name[subtype >>
+ IEEE80211_FC0_SUBTYPE_SHIFT],
+ "%s", "no TDMA ie");
+ vap->iv_stats.is_rx_mgtdiscard++;
+ return;
+ }
+ if (ni == vap->iv_bss &&
+ !IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_macaddr)) {
+ /*
+ * Fake up a node for this newly
+ * discovered member of the IBSS.
+ */
+ ni = ieee80211_add_neighbor(vap, wh, &scan);
+ if (ni == NULL) {
+ /* NB: stat kept for alloc failure */
+ return;
+ }
+ }
+ /*
+ * Check for state updates.
+ */
+ if (IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_bssid)) {
+ /*
+ * Count frame now that we know it's to be processed.
+ */
+ vap->iv_stats.is_rx_beacon++;
+ IEEE80211_NODE_STAT(ni, rx_beacons);
+ /*
+ * Record tsf of last beacon. NB: this must be
+ * done before calling tdma_process_params
+ * as deeper routines reference it.
+ */
+ memcpy(&ni->ni_tstamp.data, scan.tstamp,
+ sizeof(ni->ni_tstamp.data));
+ /*
+ * Count beacon frame for s/w bmiss handling.
+ */
+ vap->iv_swbmiss_count++;
+ vap->iv_bmiss_count = 0;
+ /*
+ * Process tdma ie. The contents are used to sync
+ * the slot timing, reconfigure the bss, etc.
+ */
+ (void) tdma_process_params(ni, scan.tdma, rstamp, wh);
+ return;
+ }
+ /*
+ * NB: defer remaining work to the adhoc code; this causes
+ * 2x parsing of the frame but should happen infrequently
+ */
+ }
+ ts->tdma_recv_mgmt(ni, m0, subtype, rssi, noise, rstamp);
+}
+
+/*
+ * Update TDMA state on receipt of a beacon frame with
+ * a TDMA information element. The sender's identity
+ * is provided so we can track who our peer is. If pickslot
+ * is non-zero we scan the slot allocation state in the ie
+ * locate a free slot for our use.
+ */
+static int
+tdma_update(struct ieee80211vap *vap, const struct ieee80211_tdma_param *tdma,
+ struct ieee80211_node *ni, int pickslot)
+{
+ struct ieee80211_tdma_state *ts = vap->iv_tdma;
+ int slotlen, slotcnt, slot, bintval;
+
+ KASSERT(vap->iv_caps & IEEE80211_C_TDMA,
+ ("not a tdma vap, caps 0x%x", vap->iv_caps));
+
+ slotlen = le16toh(tdma->tdma_slotlen);
+ slotcnt = tdma->tdma_slotcnt;
+ bintval = tdma->tdma_bintval;
+
+ /* XXX rate-limit printf's */
+ if (!(2 <= slotcnt && slotcnt <= IEEE80211_TDMA_MAXSLOTS)) {
+ printf("%s: bogus slot cnt %u\n", __func__, slotcnt);
+ return 0;
+ }
+ /* XXX magic constants */
+ if (slotlen < 2 || slotlen > (0xfffff/100)) {
+ printf("%s: bogus slot len %u\n", __func__, slotlen);
+ return 0;
+ }
+ if (bintval < 1) {
+ printf("%s: bogus beacon interval %u\n", __func__, bintval);
+ return 0;
+ }
+ if (pickslot) {
+ /*
+ * Pick unoccupied slot. Note we never choose slot 0.
+ */
+ for (slot = slotcnt-1; slot > 0; slot--)
+ if (isclr(tdma->tdma_inuse, slot))
+ break;
+ if (slot <= 0) {
+ printf("%s: no free slot, slotcnt %u inuse: 0x%x\n",
+ __func__, slotcnt, tdma->tdma_inuse[0]);
+ /* XXX need to do something better */
+ return 0;
+ }
+ } else
+ slot = ts->tdma_slot;
+
+ if (slotcnt != ts->tdma_slotcnt ||
+ 100*slotlen != ts->tdma_slotlen ||
+ bintval != ts->tdma_bintval ||
+ slot != ts->tdma_slot ||
+ ts->tdma_peer != ni) {
+ /*
+ * New/changed parameters; update runtime state.
+ */
+ /* XXX overwrites user parameters */
+ ts->tdma_slotcnt = slotcnt;
+ ts->tdma_slotlen = 100*slotlen;
+ ts->tdma_slot = slot;
+ ts->tdma_bintval = bintval;
+ /* mark beacon to be updated before next xmit */
+ ieee80211_beacon_notify(vap, IEEE80211_BEACON_TDMA);
+
+ IEEE80211_DPRINTF(vap, IEEE80211_MSG_TDMA,
+ "%s: slot %u slotcnt %u slotlen %u us bintval %u\n",
+ __func__, slot, slotcnt, 100*slotlen, tdma->tdma_bintval);
+ }
+ /*
+ * Notify driver. Note we can be called before
+ * entering RUN state if we scanned and are
+ * joining an existing bss. In that case do not
+ * call the driver because not all necessary state
+ * has been setup. The next beacon will dtrt.
+ */
+ if (vap->iv_state == IEEE80211_S_RUN)
+ vap->iv_ic->ic_tdma_update(ni, tdma);
+ /*
+ * Dispatch join event on first beacon from new master.
+ */
+ if (ts->tdma_peer != ni) {
+ if (ts->tdma_peer != NULL)
+ ieee80211_notify_node_leave(vap->iv_bss);
+ ieee80211_notify_node_join(ni, 1);
+ /* NB: no reference, we just use the address */
+ ts->tdma_peer = ni;
+ }
+ return 1;
+}
+
+/*
+ * Process received TDMA parameters.
+ */
+static int
+tdma_process_params(struct ieee80211_node *ni,
+ const u_int8_t *ie, u_int32_t rstamp, const struct ieee80211_frame *wh)
+{
+ struct ieee80211vap *vap = ni->ni_vap;
+ struct ieee80211_tdma_state *ts = vap->iv_tdma;
+ const struct ieee80211_tdma_param *tdma =
+ (const struct ieee80211_tdma_param *) ie;
+ u_int len = ie[1];
+
+ KASSERT(vap->iv_caps & IEEE80211_C_TDMA,
+ ("not a tdma vap, caps 0x%x", vap->iv_caps));
+
+ if (len < sizeof(*tdma) - 2) {
+ IEEE80211_DISCARD_IE(vap,
+ IEEE80211_MSG_ELEMID | IEEE80211_MSG_TDMA,
+ wh, "tdma", "too short, len %u", len);
+ return IEEE80211_REASON_IE_INVALID;
+ }
+ if (tdma->tdma_version != TDMA_VERSION) {
+ IEEE80211_DISCARD_IE(vap,
+ IEEE80211_MSG_ELEMID | IEEE80211_MSG_TDMA,
+ wh, "tdma", "bad version %u", tdma->tdma_version);
+ return IEEE80211_REASON_IE_INVALID;
+ }
+ /*
+ * Can reach here while scanning, update
+ * operational state only in RUN state.
+ */
+ if (vap->iv_state == IEEE80211_S_RUN) {
+ if (tdma->tdma_slot != ts->tdma_slot &&
+ isclr(ts->tdma_inuse, tdma->tdma_slot)) {
+ IEEE80211_NOTE(vap, IEEE80211_MSG_TDMA, ni,
+ "discovered in slot %u", tdma->tdma_slot);
+ setbit(ts->tdma_inuse, tdma->tdma_slot);
+ /* XXX dispatch event only when operating as master */
+ if (ts->tdma_slot == 0)
+ ieee80211_notify_node_join(ni, 1);
+ }
+ setbit(ts->tdma_active, tdma->tdma_slot);
+ if (tdma->tdma_slot == ts->tdma_slot-1) {
+ /*
+ * Slave tsf synchronization to station
+ * just before us in the schedule. The driver
+ * is responsible for copying the timestamp
+ * of the received beacon into our beacon
+ * frame so the sender can calculate round
+ * trip time. We cannot do that here because
+ * we don't know how to update our beacon frame.
+ */
+ (void) tdma_update(vap, tdma, ni, 0);
+ /* XXX reschedule swbmiss timer on parameter change */
+ } else if (tdma->tdma_slot == ts->tdma_slot+1) {
+ uint64_t tstamp;
+ int32_t rtt;
+ /*
+ * Use returned timstamp to calculate the
+ * roundtrip time.
+ */
+ memcpy(&tstamp, tdma->tdma_tstamp, 8);
+ /* XXX use only 15 bits of rstamp */
+ rtt = rstamp - (le64toh(tstamp) & 0x7fff);
+ if (rtt < 0)
+ rtt += 0x7fff;
+ /* XXX hack to quiet normal use */
+ IEEE80211_DPRINTF(vap, IEEE80211_MSG_DOT1X,
+ "tdma rtt %5u [rstamp %5u tstamp %llu]\n",
+ rtt, rstamp,
+ (unsigned long long) le64toh(tstamp));
+ } else if (tdma->tdma_slot == ts->tdma_slot &&
+ le64toh(ni->ni_tstamp.tsf) > vap->iv_bss->ni_tstamp.tsf) {
+ /*
+ * Station using the same slot as us and has
+ * been around longer than us; we must move.
+ * Note this can happen if stations do not
+ * see each other while scanning.
+ */
+ IEEE80211_DPRINTF(vap, IEEE80211_MSG_TDMA,
+ "slot %u collision rxtsf %llu tsf %llu\n",
+ tdma->tdma_slot,
+ (unsigned long long) le64toh(ni->ni_tstamp.tsf),
+ vap->iv_bss->ni_tstamp.tsf);
+ setbit(ts->tdma_inuse, tdma->tdma_slot);
+
+ (void) tdma_update(vap, tdma, ni, 1);
+ }
+ }
+ return 0;
+}
+
+int
+ieee80211_tdma_getslot(struct ieee80211vap *vap)
+{
+ struct ieee80211_tdma_state *ts = vap->iv_tdma;
+
+ KASSERT(vap->iv_caps & IEEE80211_C_TDMA,
+ ("not a tdma vap, caps 0x%x", vap->iv_caps));
+ return ts->tdma_slot;
+}
+
+/*
+ * Parse a TDMA ie on station join and use it to setup node state.
+ */
+void
+ieee80211_parse_tdma(struct ieee80211_node *ni, const uint8_t *ie)
+{
+ struct ieee80211vap *vap = ni->ni_vap;
+
+ if (vap->iv_caps & IEEE80211_C_TDMA) {
+ const struct ieee80211_tdma_param *tdma =
+ (const struct ieee80211_tdma_param *)ie;
+ struct ieee80211_tdma_state *ts = vap->iv_tdma;
+ /*
+ * Adopt TDMA configuration when joining an
+ * existing network.
+ */
+ setbit(ts->tdma_inuse, tdma->tdma_slot);
+ (void) tdma_update(vap, tdma, ni, 1);
+ /*
+ * Propagate capabilities based on the local
+ * configuration and the remote station's advertised
+ * capabilities. In particular this permits us to
+ * enable use of QoS to disable ACK's.
+ */
+ if ((vap->iv_flags & IEEE80211_F_WME) &&
+ ni->ni_ies.wme_ie != NULL)
+ ni->ni_flags |= IEEE80211_NODE_QOS;
+ }
+}
+
+#define TDMA_OUI_BYTES 0x00, 0x03, 0x7f
+/*
+ * Add a TDMA parameters element to a frame.
+ */
+uint8_t *
+ieee80211_add_tdma(uint8_t *frm, struct ieee80211vap *vap)
+{
+#define ADDSHORT(frm, v) do { \
+ frm[0] = (v) & 0xff; \
+ frm[1] = (v) >> 8; \
+ frm += 2; \
+} while (0)
+ static const struct ieee80211_tdma_param param = {
+ .tdma_id = IEEE80211_ELEMID_VENDOR,
+ .tdma_len = sizeof(struct ieee80211_tdma_param) - 2,
+ .tdma_oui = { TDMA_OUI_BYTES },
+ .tdma_type = TDMA_OUI_TYPE,
+ .tdma_subtype = TDMA_SUBTYPE_PARAM,
+ .tdma_version = TDMA_VERSION,
+ };
+ const struct ieee80211_tdma_state *tdma = vap->iv_tdma;
+ uint16_t slotlen;
+
+ KASSERT(vap->iv_caps & IEEE80211_C_TDMA,
+ ("not a tdma vap, caps 0x%x", vap->iv_caps));
+
+ memcpy(frm, &param, sizeof(param));
+ frm += __offsetof(struct ieee80211_tdma_param, tdma_slot);
+ *frm++ = tdma->tdma_slot;
+ *frm++ = tdma->tdma_slotcnt;
+ /* NB: convert units to fit in 16-bits */
+ slotlen = tdma->tdma_slotlen / 100; /* 100us units */
+ ADDSHORT(frm, slotlen);
+ *frm++ = tdma->tdma_bintval;
+ *frm++ = tdma->tdma_inuse[0];
+ frm += 10; /* pad+timestamp */
+ return frm;
+#undef ADDSHORT
+}
+#undef TDMA_OUI_BYTES
+
+/*
+ * Update TDMA state at TBTT.
+ */
+void
+ieee80211_tdma_update_beacon(struct ieee80211vap *vap,
+ struct ieee80211_beacon_offsets *bo)
+{
+ struct ieee80211_tdma_state *ts = vap->iv_tdma;
+
+ KASSERT(vap->iv_caps & IEEE80211_C_TDMA,
+ ("not a tdma vap, caps 0x%x", vap->iv_caps));
+
+ if (isset(bo->bo_flags, IEEE80211_BEACON_TDMA)) {
+ (void) ieee80211_add_tdma(bo->bo_tdma, vap);
+ clrbit(bo->bo_flags, IEEE80211_BEACON_TDMA);
+ }
+ if (ts->tdma_slot != 0) /* only on master */
+ return;
+ if (ts->tdma_count <= 0) {
+ /*
+ * Time to update the mask of active/inuse stations.
+ * We track stations that we've received a beacon
+ * frame from and update this mask periodically.
+ * This allows us to miss a few beacons before marking
+ * a slot free for re-use.
+ */
+ ts->tdma_inuse[0] = ts->tdma_active[0];
+ ts->tdma_active[0] = 0x01;
+ /* update next time 'round */
+ /* XXX use notify framework */
+ setbit(bo->bo_flags, IEEE80211_BEACON_TDMA);
+ /* NB: use s/w beacon miss threshold; may be too high */
+ ts->tdma_count = vap->iv_bmissthreshold-1;
+ } else
+ ts->tdma_count--;
+}
+
+int
+ieee80211_tdma_ioctl_get80211(struct ieee80211vap *vap,
+ struct ieee80211req *ireq)
+{
+ struct ieee80211_tdma_state *ts = vap->iv_tdma;
+
+ if ((vap->iv_caps & IEEE80211_C_TDMA) == 0)
+ return EOPNOTSUPP;
+
+ switch (ireq->i_type) {
+ case IEEE80211_IOC_TDMA_SLOT:
+ ireq->i_val = ts->tdma_slot;
+ break;
+ case IEEE80211_IOC_TDMA_SLOTCNT:
+ ireq->i_val = ts->tdma_slotcnt;
+ break;
+ case IEEE80211_IOC_TDMA_SLOTLEN:
+ ireq->i_val = ts->tdma_slotlen;
+ break;
+ case IEEE80211_IOC_TDMA_BINTERVAL:
+ ireq->i_val = ts->tdma_bintval;
+ break;
+ default:
+ return EINVAL;
+ }
+ return 0;
+}
+
+int
+ieee80211_tdma_ioctl_set80211(struct ieee80211vap *vap,
+ struct ieee80211req *ireq)
+{
+ struct ieee80211_tdma_state *ts = vap->iv_tdma;
+
+ if ((vap->iv_caps & IEEE80211_C_TDMA) == 0)
+ return EOPNOTSUPP;
+
+ switch (ireq->i_type) {
+ case IEEE80211_IOC_TDMA_SLOT:
+ if (!(0 <= ireq->i_val && ireq->i_val <= ts->tdma_slotcnt))
+ return EINVAL;
+ if (ireq->i_val != ts->tdma_slot) {
+ ts->tdma_slot = ireq->i_val;
+ return ERESTART;
+ }
+ break;
+ case IEEE80211_IOC_TDMA_SLOTCNT:
+ if (!(2 <= ireq->i_val &&
+ ireq->i_val <= IEEE80211_TDMA_MAXSLOTS))
+ return EINVAL;
+ if (ireq->i_val != ts->tdma_slotcnt) {
+ ts->tdma_slotcnt = ireq->i_val;
+ return ERESTART;
+ }
+ break;
+ case IEEE80211_IOC_TDMA_SLOTLEN:
+ /*
+ * XXX
+ * 150 insures at least 1/8 TU
+ * 0xfffff is the max duration for bursting
+ * (implict by way of 16-bit data type for i_val)
+ */
+ if (ireq->i_val < 150)
+ return EINVAL;
+ if (ireq->i_val != ts->tdma_slotlen) {
+ ts->tdma_slotlen = ireq->i_val;
+ return ERESTART;
+ }
+ break;
+ case IEEE80211_IOC_TDMA_BINTERVAL:
+ if (ireq->i_val < 1)
+ return EINVAL;
+ if (ireq->i_val != ts->tdma_bintval) {
+ ts->tdma_bintval = ireq->i_val;
+ return ERESTART;
+ }
+ break;
+ default:
+ return EINVAL;
+ }
+ return 0;
+}
+#endif /* IEEE80211_SUPPORT_TDMA */
diff --git a/sys/net80211/ieee80211_tdma.h b/sys/net80211/ieee80211_tdma.h
new file mode 100644
index 0000000..c5ac3a2
--- /dev/null
+++ b/sys/net80211/ieee80211_tdma.h
@@ -0,0 +1,66 @@
+/*-
+ * Copyright (c) 2007-2009 Sam Leffler, Errno Consulting
+ * Copyright (c) 2007-2009 Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+#ifndef _NET80211_IEEE80211_TDMA_H_
+#define _NET80211_IEEE80211_TDMA_H_
+
+/*
+ * TDMA-mode implementation definitions.
+ */
+struct ieee80211_tdma_state {
+ u_int tdma_slotlen; /* bss slot length (us) */
+ uint8_t tdma_slotcnt; /* bss slot count */
+ uint8_t tdma_bintval; /* beacon interval (slots) */
+ uint8_t tdma_slot; /* station slot # */
+ uint8_t tdma_inuse[1]; /* mask of slots in use */
+#define IEEE80211_TDMA_MAXSLOTS 8
+ void *tdma_peer; /* peer station cookie */
+ uint8_t tdma_active[1]; /* mask of active slots */
+ int tdma_count; /* active/inuse countdown */
+
+ /* parent method pointers */
+ int (*tdma_newstate)(struct ieee80211vap *, enum ieee80211_state,
+ int arg);
+ void (*tdma_recv_mgmt)(struct ieee80211_node *,
+ struct mbuf *, int, int, int, uint32_t);
+ void (*tdma_opdetach)(struct ieee80211vap *);
+};
+
+void ieee80211_tdma_vattach(struct ieee80211vap *);
+
+int ieee80211_tdma_getslot(struct ieee80211vap *vap);
+void ieee80211_parse_tdma(struct ieee80211_node *ni, const uint8_t *ie);
+uint8_t *ieee80211_add_tdma(uint8_t *frm, struct ieee80211vap *vap);
+struct ieee80211_beacon_offsets;
+void ieee80211_tdma_update_beacon(struct ieee80211vap *vap,
+ struct ieee80211_beacon_offsets *bo);
+struct ieee80211req;
+int ieee80211_tdma_ioctl_get80211(struct ieee80211vap *vap,
+ struct ieee80211req *ireq);
+int ieee80211_tdma_ioctl_set80211(struct ieee80211vap *vap,
+ struct ieee80211req *ireq);
+#endif /* !_NET80211_IEEE80211_TDMA_H_ */
diff --git a/sys/net80211/ieee80211_var.h b/sys/net80211/ieee80211_var.h
index ccd95d0..2e47d19 100644
--- a/sys/net80211/ieee80211_var.h
+++ b/sys/net80211/ieee80211_var.h
@@ -1,6 +1,6 @@
/*-
* Copyright (c) 2001 Atsushi Onoe
- * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
+ * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -105,6 +105,8 @@ struct ieee80211_appie {
uint8_t ie_data[]; /* user-specified IE's */
};
+struct ieee80211_tdma_param;
+
struct ieee80211com {
struct ifnet *ic_ifp; /* associated device */
ieee80211_com_lock_t ic_comlock; /* state update lock */
@@ -226,6 +228,9 @@ struct ieee80211com {
void (*ic_update_promisc)(struct ifnet *);
/* new station association callback/notification */
void (*ic_newassoc)(struct ieee80211_node *, int);
+ /* TDMA update notification */
+ void (*ic_tdma_update)(struct ieee80211_node *,
+ const struct ieee80211_tdma_param *);
/* node state management */
struct ieee80211_node* (*ic_node_alloc)(struct ieee80211vap *,
const uint8_t [IEEE80211_ADDR_LEN]);
@@ -279,6 +284,7 @@ struct ieee80211com {
};
struct ieee80211_aclator;
+struct ieee80211_tdma_state;
struct ieee80211vap {
struct ifmedia iv_media; /* interface media config */
@@ -389,6 +395,8 @@ struct ieee80211vap {
const struct ieee80211_aclator *iv_acl; /* acl glue */
void *iv_as; /* private aclator state */
+ struct ieee80211_tdma_state *iv_tdma; /* tdma state */
+
/* operate-mode detach hook */
void (*iv_opdetach)(struct ieee80211vap *);
/* receive processing */
@@ -522,11 +530,13 @@ MALLOC_DECLARE(M_80211_VAP);
/* 0x10000000 reserved */
#define IEEE80211_C_BGSCAN 0x20000000 /* CAPABILITY: bg scanning */
#define IEEE80211_C_TXFRAG 0x40000000 /* CAPABILITY: tx fragments */
+#define IEEE80211_C_TDMA 0x80000000 /* CAPABILITY: TDMA avail */
/* XXX protection/barker? */
#define IEEE80211_C_OPMODE \
(IEEE80211_C_STA | IEEE80211_C_IBSS | IEEE80211_C_HOSTAP | \
- IEEE80211_C_AHDEMO | IEEE80211_C_MONITOR | IEEE80211_C_WDS)
+ IEEE80211_C_AHDEMO | IEEE80211_C_MONITOR | IEEE80211_C_WDS | \
+ IEEE80211_C_TDMA)
/*
* ic_htcaps/iv_htcaps: HT-specific device/driver capabilities
@@ -680,6 +690,7 @@ ieee80211_htchanflags(const struct ieee80211_channel *c)
#define IEEE80211_MSG_ACTION 0x00000010 /* action frame handling */
#define IEEE80211_MSG_WDS 0x00000008 /* WDS handling */
#define IEEE80211_MSG_IOCTL 0x00000004 /* ioctl handling */
+#define IEEE80211_MSG_TDMA 0x00000002 /* TDMA handling */
#define IEEE80211_MSG_ANY 0xffffffff /* anything */
OpenPOWER on IntegriCloud