Index: head/sys/net80211/ieee80211.h =================================================================== --- head/sys/net80211/ieee80211.h (revision 190454) +++ head/sys/net80211/ieee80211.h (revision 190455) @@ -1,1118 +1,1031 @@ /*- * Copyright (c) 2001 Atsushi Onoe * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting * 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_H_ #define _NET80211_IEEE80211_H_ /* * 802.11 protocol definitions. */ #define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */ /* is 802.11 address multicast/broadcast? */ #define IEEE80211_IS_MULTICAST(_a) (*(_a) & 0x01) /* IEEE 802.11 PLCP header */ struct ieee80211_plcp_hdr { uint16_t i_sfd; uint8_t i_signal; uint8_t i_service; uint16_t i_length; uint16_t i_crc; } __packed; #define IEEE80211_PLCP_SFD 0xF3A0 #define IEEE80211_PLCP_SERVICE 0x00 #define IEEE80211_PLCP_SERVICE_LOCKED 0x04 #define IEEE80211_PLCL_SERVICE_PBCC 0x08 #define IEEE80211_PLCP_SERVICE_LENEXT5 0x20 #define IEEE80211_PLCP_SERVICE_LENEXT6 0x40 #define IEEE80211_PLCP_SERVICE_LENEXT7 0x80 /* * generic definitions for IEEE 802.11 frames */ struct ieee80211_frame { uint8_t i_fc[2]; uint8_t i_dur[2]; uint8_t i_addr1[IEEE80211_ADDR_LEN]; uint8_t i_addr2[IEEE80211_ADDR_LEN]; uint8_t i_addr3[IEEE80211_ADDR_LEN]; uint8_t i_seq[2]; /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */ /* see below */ } __packed; struct ieee80211_qosframe { uint8_t i_fc[2]; uint8_t i_dur[2]; uint8_t i_addr1[IEEE80211_ADDR_LEN]; uint8_t i_addr2[IEEE80211_ADDR_LEN]; uint8_t i_addr3[IEEE80211_ADDR_LEN]; uint8_t i_seq[2]; uint8_t i_qos[2]; /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */ /* see below */ } __packed; struct ieee80211_qoscntl { uint8_t i_qos[2]; }; struct ieee80211_frame_addr4 { uint8_t i_fc[2]; uint8_t i_dur[2]; uint8_t i_addr1[IEEE80211_ADDR_LEN]; uint8_t i_addr2[IEEE80211_ADDR_LEN]; uint8_t i_addr3[IEEE80211_ADDR_LEN]; uint8_t i_seq[2]; uint8_t i_addr4[IEEE80211_ADDR_LEN]; } __packed; struct ieee80211_qosframe_addr4 { uint8_t i_fc[2]; uint8_t i_dur[2]; uint8_t i_addr1[IEEE80211_ADDR_LEN]; uint8_t i_addr2[IEEE80211_ADDR_LEN]; uint8_t i_addr3[IEEE80211_ADDR_LEN]; uint8_t i_seq[2]; uint8_t i_addr4[IEEE80211_ADDR_LEN]; uint8_t i_qos[2]; } __packed; #define IEEE80211_FC0_VERSION_MASK 0x03 #define IEEE80211_FC0_VERSION_SHIFT 0 #define IEEE80211_FC0_VERSION_0 0x00 #define IEEE80211_FC0_TYPE_MASK 0x0c #define IEEE80211_FC0_TYPE_SHIFT 2 #define IEEE80211_FC0_TYPE_MGT 0x00 #define IEEE80211_FC0_TYPE_CTL 0x04 #define IEEE80211_FC0_TYPE_DATA 0x08 #define IEEE80211_FC0_SUBTYPE_MASK 0xf0 #define IEEE80211_FC0_SUBTYPE_SHIFT 4 /* for TYPE_MGT */ #define IEEE80211_FC0_SUBTYPE_ASSOC_REQ 0x00 #define IEEE80211_FC0_SUBTYPE_ASSOC_RESP 0x10 #define IEEE80211_FC0_SUBTYPE_REASSOC_REQ 0x20 #define IEEE80211_FC0_SUBTYPE_REASSOC_RESP 0x30 #define IEEE80211_FC0_SUBTYPE_PROBE_REQ 0x40 #define IEEE80211_FC0_SUBTYPE_PROBE_RESP 0x50 #define IEEE80211_FC0_SUBTYPE_BEACON 0x80 #define IEEE80211_FC0_SUBTYPE_ATIM 0x90 #define IEEE80211_FC0_SUBTYPE_DISASSOC 0xa0 #define IEEE80211_FC0_SUBTYPE_AUTH 0xb0 #define IEEE80211_FC0_SUBTYPE_DEAUTH 0xc0 #define IEEE80211_FC0_SUBTYPE_ACTION 0xd0 /* for TYPE_CTL */ #define IEEE80211_FC0_SUBTYPE_BAR 0x80 #define IEEE80211_FC0_SUBTYPE_PS_POLL 0xa0 #define IEEE80211_FC0_SUBTYPE_RTS 0xb0 #define IEEE80211_FC0_SUBTYPE_CTS 0xc0 #define IEEE80211_FC0_SUBTYPE_ACK 0xd0 #define IEEE80211_FC0_SUBTYPE_CF_END 0xe0 #define IEEE80211_FC0_SUBTYPE_CF_END_ACK 0xf0 /* for TYPE_DATA (bit combination) */ #define IEEE80211_FC0_SUBTYPE_DATA 0x00 #define IEEE80211_FC0_SUBTYPE_CF_ACK 0x10 #define IEEE80211_FC0_SUBTYPE_CF_POLL 0x20 #define IEEE80211_FC0_SUBTYPE_CF_ACPL 0x30 #define IEEE80211_FC0_SUBTYPE_NODATA 0x40 #define IEEE80211_FC0_SUBTYPE_CFACK 0x50 #define IEEE80211_FC0_SUBTYPE_CFPOLL 0x60 #define IEEE80211_FC0_SUBTYPE_CF_ACK_CF_ACK 0x70 #define IEEE80211_FC0_SUBTYPE_QOS 0x80 #define IEEE80211_FC0_SUBTYPE_QOS_NULL 0xc0 #define IEEE80211_FC1_DIR_MASK 0x03 #define IEEE80211_FC1_DIR_NODS 0x00 /* STA->STA */ #define IEEE80211_FC1_DIR_TODS 0x01 /* STA->AP */ #define IEEE80211_FC1_DIR_FROMDS 0x02 /* AP ->STA */ #define IEEE80211_FC1_DIR_DSTODS 0x03 /* AP ->AP */ #define IEEE80211_FC1_MORE_FRAG 0x04 #define IEEE80211_FC1_RETRY 0x08 #define IEEE80211_FC1_PWR_MGT 0x10 #define IEEE80211_FC1_MORE_DATA 0x20 #define IEEE80211_FC1_WEP 0x40 #define IEEE80211_FC1_ORDER 0x80 #define IEEE80211_SEQ_FRAG_MASK 0x000f #define IEEE80211_SEQ_FRAG_SHIFT 0 #define IEEE80211_SEQ_SEQ_MASK 0xfff0 #define IEEE80211_SEQ_SEQ_SHIFT 4 #define IEEE80211_SEQ_RANGE 4096 #define IEEE80211_SEQ_ADD(seq, incr) \ (((seq) + (incr)) & (IEEE80211_SEQ_RANGE-1)) #define IEEE80211_SEQ_INC(seq) IEEE80211_SEQ_ADD(seq,1) #define IEEE80211_SEQ_SUB(a, b) \ (((a) + IEEE80211_SEQ_RANGE - (b)) & (IEEE80211_SEQ_RANGE-1)) #define IEEE80211_SEQ_BA_RANGE 2048 /* 2^11 */ #define IEEE80211_SEQ_BA_BEFORE(a, b) \ (IEEE80211_SEQ_SUB(b, a+1) < IEEE80211_SEQ_BA_RANGE-1) #define IEEE80211_NWID_LEN 32 #define IEEE80211_QOS_TXOP 0x00ff /* bit 8 is reserved */ #define IEEE80211_QOS_AMSDU 0x80 #define IEEE80211_QOS_AMSDU_S 7 #define IEEE80211_QOS_ACKPOLICY 0x60 #define IEEE80211_QOS_ACKPOLICY_S 5 #define IEEE80211_QOS_ACKPOLICY_NOACK 0x20 /* No ACK required */ #define IEEE80211_QOS_ACKPOLICY_BA 0x60 /* Block ACK */ #define IEEE80211_QOS_EOSP 0x10 /* EndOfService Period*/ #define IEEE80211_QOS_EOSP_S 4 #define IEEE80211_QOS_TID 0x0f /* does frame have QoS sequence control data */ #define IEEE80211_QOS_HAS_SEQ(wh) \ (((wh)->i_fc[0] & \ (IEEE80211_FC0_TYPE_MASK | IEEE80211_FC0_SUBTYPE_QOS)) == \ (IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_QOS)) /* * WME/802.11e information element. */ struct ieee80211_wme_info { uint8_t wme_id; /* IEEE80211_ELEMID_VENDOR */ uint8_t wme_len; /* length in bytes */ uint8_t wme_oui[3]; /* 0x00, 0x50, 0xf2 */ uint8_t wme_type; /* OUI type */ uint8_t wme_subtype; /* OUI subtype */ uint8_t wme_version; /* spec revision */ uint8_t wme_info; /* QoS info */ } __packed; /* * WME/802.11e Tspec Element */ struct ieee80211_wme_tspec { uint8_t ts_id; uint8_t ts_len; uint8_t ts_oui[3]; uint8_t ts_oui_type; uint8_t ts_oui_subtype; uint8_t ts_version; uint8_t ts_tsinfo[3]; uint8_t ts_nom_msdu[2]; uint8_t ts_max_msdu[2]; uint8_t ts_min_svc[4]; uint8_t ts_max_svc[4]; uint8_t ts_inactv_intv[4]; uint8_t ts_susp_intv[4]; uint8_t ts_start_svc[4]; uint8_t ts_min_rate[4]; uint8_t ts_mean_rate[4]; uint8_t ts_max_burst[4]; uint8_t ts_min_phy[4]; uint8_t ts_peak_rate[4]; uint8_t ts_delay[4]; uint8_t ts_surplus[2]; uint8_t ts_medium_time[2]; } __packed; /* * WME AC parameter field */ struct ieee80211_wme_acparams { uint8_t acp_aci_aifsn; uint8_t acp_logcwminmax; uint16_t acp_txop; } __packed; #define WME_NUM_AC 4 /* 4 AC categories */ #define WME_NUM_TID 16 /* 16 tids */ #define WME_PARAM_ACI 0x60 /* Mask for ACI field */ #define WME_PARAM_ACI_S 5 /* Shift for ACI field */ #define WME_PARAM_ACM 0x10 /* Mask for ACM bit */ #define WME_PARAM_ACM_S 4 /* Shift for ACM bit */ #define WME_PARAM_AIFSN 0x0f /* Mask for aifsn field */ #define WME_PARAM_AIFSN_S 0 /* Shift for aifsn field */ #define WME_PARAM_LOGCWMIN 0x0f /* Mask for CwMin field (in log) */ #define WME_PARAM_LOGCWMIN_S 0 /* Shift for CwMin field */ #define WME_PARAM_LOGCWMAX 0xf0 /* Mask for CwMax field (in log) */ #define WME_PARAM_LOGCWMAX_S 4 /* Shift for CwMax field */ #define WME_AC_TO_TID(_ac) ( \ ((_ac) == WME_AC_VO) ? 6 : \ ((_ac) == WME_AC_VI) ? 5 : \ ((_ac) == WME_AC_BK) ? 1 : \ 0) #define TID_TO_WME_AC(_tid) ( \ ((_tid) == 0 || (_tid) == 3) ? WME_AC_BE : \ ((_tid) < 3) ? WME_AC_BK : \ ((_tid) < 6) ? WME_AC_VI : \ WME_AC_VO) /* * WME Parameter Element */ struct ieee80211_wme_param { uint8_t param_id; uint8_t param_len; uint8_t param_oui[3]; uint8_t param_oui_type; uint8_t param_oui_subtype; uint8_t param_version; uint8_t param_qosInfo; #define WME_QOSINFO_COUNT 0x0f /* Mask for param count field */ uint8_t param_reserved; struct ieee80211_wme_acparams params_acParams[WME_NUM_AC]; } __packed; /* * Management Notification Frame */ struct ieee80211_mnf { uint8_t mnf_category; uint8_t mnf_action; uint8_t mnf_dialog; uint8_t mnf_status; } __packed; #define MNF_SETUP_REQ 0 #define MNF_SETUP_RESP 1 #define MNF_TEARDOWN 2 /* * 802.11n Management Action Frames */ /* generic frame format */ struct ieee80211_action { uint8_t ia_category; uint8_t ia_action; } __packed; #define IEEE80211_ACTION_CAT_QOS 0 /* QoS */ #define IEEE80211_ACTION_CAT_BA 3 /* BA */ #define IEEE80211_ACTION_CAT_HT 7 /* HT */ #define IEEE80211_ACTION_HT_TXCHWIDTH 0 /* recommended xmit chan width*/ #define IEEE80211_ACTION_HT_MIMOPWRSAVE 1 /* MIMO power save */ /* HT - recommended transmission channel width */ struct ieee80211_action_ht_txchwidth { struct ieee80211_action at_header; uint8_t at_chwidth; } __packed; #define IEEE80211_A_HT_TXCHWIDTH_20 0 #define IEEE80211_A_HT_TXCHWIDTH_2040 1 /* HT - MIMO Power Save (NB: D2.04) */ struct ieee80211_action_ht_mimopowersave { struct ieee80211_action am_header; uint8_t am_control; } __packed; #define IEEE80211_A_HT_MIMOPWRSAVE_ENA 0x01 /* PS enabled */ #define IEEE80211_A_HT_MIMOPWRSAVE_MODE 0x02 #define IEEE80211_A_HT_MIMOPWRSAVE_MODE_S 1 #define IEEE80211_A_HT_MIMOPWRSAVE_DYNAMIC 0x02 /* Dynamic Mode */ #define IEEE80211_A_HT_MIMOPWRSAVE_STATIC 0x00 /* no SM packets */ /* bits 2-7 reserved */ /* Block Ack actions */ #define IEEE80211_ACTION_BA_ADDBA_REQUEST 0 /* ADDBA request */ #define IEEE80211_ACTION_BA_ADDBA_RESPONSE 1 /* ADDBA response */ #define IEEE80211_ACTION_BA_DELBA 2 /* DELBA */ /* Block Ack Parameter Set */ #define IEEE80211_BAPS_BUFSIZ 0xffc0 /* buffer size */ #define IEEE80211_BAPS_BUFSIZ_S 6 #define IEEE80211_BAPS_TID 0x003c /* TID */ #define IEEE80211_BAPS_TID_S 2 #define IEEE80211_BAPS_POLICY 0x0002 /* block ack policy */ #define IEEE80211_BAPS_POLICY_S 1 #define IEEE80211_BAPS_POLICY_DELAYED (0< IEEE80211_MIN_LEN. The default * mtu is Ethernet-compatible; it's set by ether_ifattach. */ #define IEEE80211_MTU_MAX 2290 #define IEEE80211_MTU_MIN 32 #define IEEE80211_MAX_LEN (2300 + IEEE80211_CRC_LEN + \ (IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN + IEEE80211_WEP_CRCLEN)) #define IEEE80211_ACK_LEN \ (sizeof(struct ieee80211_frame_ack) + IEEE80211_CRC_LEN) #define IEEE80211_MIN_LEN \ (sizeof(struct ieee80211_frame_min) + IEEE80211_CRC_LEN) /* * The 802.11 spec says at most 2007 stations may be * associated at once. For most AP's this is way more * than is feasible so we use a default of IEEE80211_AID_DEF. * This number may be overridden by the driver and/or by * user configuration but may not be less than IEEE80211_AID_MIN * (see _ieee80211.h for implementation-specific settings). */ #define IEEE80211_AID_MAX 2007 #define IEEE80211_AID(b) ((b) &~ 0xc000) /* * RTS frame length parameters. The default is specified in * the 802.11 spec as 512; we treat it as implementation-dependent * so it's defined in ieee80211_var.h. The max may be wrong * for jumbo frames. */ #define IEEE80211_RTS_MIN 1 #define IEEE80211_RTS_MAX 2346 /* * TX fragmentation parameters. As above for RTS, we treat * default as implementation-dependent so define it elsewhere. */ #define IEEE80211_FRAG_MIN 256 #define IEEE80211_FRAG_MAX 2346 /* * Beacon interval (TU's). Min+max come from WiFi requirements. * As above, we treat default as implementation-dependent so * define it elsewhere. */ #define IEEE80211_BINTVAL_MAX 1000 /* max beacon interval (TU's) */ #define IEEE80211_BINTVAL_MIN 25 /* min beacon interval (TU's) */ /* * DTIM period (beacons). Min+max are not really defined * by the protocol but we want them publicly visible so * define them here. */ #define IEEE80211_DTIM_MAX 15 /* max DTIM period */ #define IEEE80211_DTIM_MIN 1 /* min DTIM period */ /* * Beacon miss threshold (beacons). As for DTIM, we define * them here to be publicly visible. Note the max may be * clamped depending on device capabilities. */ #define IEEE80211_HWBMISS_MIN 1 #define IEEE80211_HWBMISS_MAX 255 /* * 802.11 frame duration definitions. */ struct ieee80211_duration { uint16_t d_rts_dur; uint16_t d_data_dur; uint16_t d_plcp_len; uint8_t d_residue; /* unused octets in time slot */ }; /* One Time Unit (TU) is 1Kus = 1024 microseconds. */ #define IEEE80211_DUR_TU 1024 /* IEEE 802.11b durations for DSSS PHY in microseconds */ #define IEEE80211_DUR_DS_LONG_PREAMBLE 144 #define IEEE80211_DUR_DS_SHORT_PREAMBLE 72 #define IEEE80211_DUR_DS_SLOW_PLCPHDR 48 #define IEEE80211_DUR_DS_FAST_PLCPHDR 24 #define IEEE80211_DUR_DS_SLOW_ACK 112 #define IEEE80211_DUR_DS_FAST_ACK 56 #define IEEE80211_DUR_DS_SLOW_CTS 112 #define IEEE80211_DUR_DS_FAST_CTS 56 #define IEEE80211_DUR_DS_SLOT 20 #define IEEE80211_DUR_DS_SIFS 10 #define IEEE80211_DUR_DS_PIFS (IEEE80211_DUR_DS_SIFS + IEEE80211_DUR_DS_SLOT) #define IEEE80211_DUR_DS_DIFS (IEEE80211_DUR_DS_SIFS + \ 2 * IEEE80211_DUR_DS_SLOT) #define IEEE80211_DUR_DS_EIFS (IEEE80211_DUR_DS_SIFS + \ IEEE80211_DUR_DS_SLOW_ACK + \ IEEE80211_DUR_DS_LONG_PREAMBLE + \ IEEE80211_DUR_DS_SLOW_PLCPHDR + \ IEEE80211_DUR_DIFS) - -/* - * Atheros fast-frame encapsulation format. - * FF max payload: - * 802.2 + FFHDR + HPAD + 802.3 + 802.2 + 1500 + SPAD + 802.3 + 802.2 + 1500: - * 8 + 4 + 4 + 14 + 8 + 1500 + 6 + 14 + 8 + 1500 - * = 3066 - */ -/* fast frame header is 32-bits */ -#define ATH_FF_PROTO 0x0000003f /* protocol */ -#define ATH_FF_PROTO_S 0 -#define ATH_FF_FTYPE 0x000000c0 /* frame type */ -#define ATH_FF_FTYPE_S 6 -#define ATH_FF_HLEN32 0x00000300 /* optional hdr length */ -#define ATH_FF_HLEN32_S 8 -#define ATH_FF_SEQNUM 0x001ffc00 /* sequence number */ -#define ATH_FF_SEQNUM_S 10 -#define ATH_FF_OFFSET 0xffe00000 /* offset to 2nd payload */ -#define ATH_FF_OFFSET_S 21 - -#define ATH_FF_MAX_HDR_PAD 4 -#define ATH_FF_MAX_SEP_PAD 6 -#define ATH_FF_MAX_HDR 30 - -#define ATH_FF_PROTO_L2TUNNEL 0 /* L2 tunnel protocol */ -#define ATH_FF_ETH_TYPE 0x88bd /* Ether type for encapsulated frames */ -#define ATH_FF_SNAP_ORGCODE_0 0x00 -#define ATH_FF_SNAP_ORGCODE_1 0x03 -#define ATH_FF_SNAP_ORGCODE_2 0x7f - -/* NB: Atheros allocated the OUI for this purpose ~2005 but beware ... */ -#define TDMA_OUI ATH_OUI -#define TDMA_OUI_TYPE 0x02 -#define TDMA_VERSION_V2 2 -#define TDMA_VERSION TDMA_VERSION_V2 - -/* NB: we only support 2 right now but protocol handles up to 8 */ -#define TDMA_MAXSLOTS 2 /* max slots/sta's */ - -#define TDMA_PARAM_LEN_V2 sizeof(struct ieee80211_tdma_param) - -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 */ -#define TDMA_SUBTYPE_PARAM 0x01 - u_int8_t tdma_version; /* spec revision */ - u_int8_t tdma_slot; /* station slot # [0..7] */ - u_int8_t tdma_slotcnt; /* bss slot count [1..8] */ - 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; - -#define TDMA_VERSION_VALID(_version) \ - (TDMA_VERSION_V2 <= (_version) && (_version) <= TDMA_VERSION) -#define TDMA_SLOTCNT_VALID(_slotcnt) \ - (2 <= (_slotcnt) && (_slotcnt) <= TDMA_MAXSLOTS) -/* XXX magic constants */ -#define TDMA_SLOTLEN_VALID(_slotlen) \ - (2*100 <= (_slotlen) && (unsigned)(_slotlen) <= 0xfffff) -/* XXX probably should set a max */ -#define TDMA_BINTVAL_VALID(_bintval) (1 <= (_bintval)) #endif /* _NET80211_IEEE80211_H_ */ Index: head/sys/net80211/ieee80211_superg.c =================================================================== --- head/sys/net80211/ieee80211_superg.c (revision 190454) +++ head/sys/net80211/ieee80211_superg.c (revision 190455) @@ -1,525 +1,554 @@ /*- * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting * 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 __FBSDID("$FreeBSD$"); #include "opt_wlan.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include +/* + * Atheros fast-frame encapsulation format. + * FF max payload: + * 802.2 + FFHDR + HPAD + 802.3 + 802.2 + 1500 + SPAD + 802.3 + 802.2 + 1500: + * 8 + 4 + 4 + 14 + 8 + 1500 + 6 + 14 + 8 + 1500 + * = 3066 + */ +/* fast frame header is 32-bits */ +#define ATH_FF_PROTO 0x0000003f /* protocol */ +#define ATH_FF_PROTO_S 0 +#define ATH_FF_FTYPE 0x000000c0 /* frame type */ +#define ATH_FF_FTYPE_S 6 +#define ATH_FF_HLEN32 0x00000300 /* optional hdr length */ +#define ATH_FF_HLEN32_S 8 +#define ATH_FF_SEQNUM 0x001ffc00 /* sequence number */ +#define ATH_FF_SEQNUM_S 10 +#define ATH_FF_OFFSET 0xffe00000 /* offset to 2nd payload */ +#define ATH_FF_OFFSET_S 21 + +#define ATH_FF_MAX_HDR_PAD 4 +#define ATH_FF_MAX_SEP_PAD 6 +#define ATH_FF_MAX_HDR 30 + +#define ATH_FF_PROTO_L2TUNNEL 0 /* L2 tunnel protocol */ +#define ATH_FF_ETH_TYPE 0x88bd /* Ether type for encapsulated frames */ +#define ATH_FF_SNAP_ORGCODE_0 0x00 +#define ATH_FF_SNAP_ORGCODE_1 0x03 +#define ATH_FF_SNAP_ORGCODE_2 0x7f + #define ETHER_HEADER_COPY(dst, src) \ memcpy(dst, src, sizeof(struct ether_header)) void ieee80211_superg_attach(struct ieee80211com *ic) { } void ieee80211_superg_detach(struct ieee80211com *ic) { } void ieee80211_superg_vattach(struct ieee80211vap *vap) { if (vap->iv_caps & IEEE80211_C_FF) vap->iv_flags |= IEEE80211_F_FF; /* NB: we only implement sta mode */ if (vap->iv_opmode == IEEE80211_M_STA && (vap->iv_caps & IEEE80211_C_TURBOP)) vap->iv_flags |= IEEE80211_F_TURBOP; } void ieee80211_superg_vdetach(struct ieee80211vap *vap) { } #define ATH_OUI_BYTES 0x00, 0x03, 0x7f /* * Add a WME information element to a frame. */ uint8_t * ieee80211_add_ath(uint8_t *frm, uint8_t caps, ieee80211_keyix defkeyix) { static const struct ieee80211_ath_ie info = { .ath_id = IEEE80211_ELEMID_VENDOR, .ath_len = sizeof(struct ieee80211_ath_ie) - 2, .ath_oui = { ATH_OUI_BYTES }, .ath_oui_type = ATH_OUI_TYPE, .ath_oui_subtype= ATH_OUI_SUBTYPE, .ath_version = ATH_OUI_VERSION, }; struct ieee80211_ath_ie *ath = (struct ieee80211_ath_ie *) frm; memcpy(frm, &info, sizeof(info)); ath->ath_capability = caps; if (defkeyix != IEEE80211_KEYIX_NONE) { ath->ath_defkeyix[0] = (defkeyix & 0xff); ath->ath_defkeyix[1] = ((defkeyix >> 8) & 0xff); } else { ath->ath_defkeyix[0] = 0xff; ath->ath_defkeyix[1] = 0x7f; } return frm + sizeof(info); } #undef ATH_OUI_BYTES uint8_t * ieee80211_add_athcaps(uint8_t *frm, const struct ieee80211_node *bss) { const struct ieee80211vap *vap = bss->ni_vap; return ieee80211_add_ath(frm, vap->iv_flags & IEEE80211_F_ATHEROS, ((vap->iv_flags & IEEE80211_F_WPA) == 0 && bss->ni_authmode != IEEE80211_AUTH_8021X) ? vap->iv_def_txkey : IEEE80211_KEYIX_NONE); } void ieee80211_parse_ath(struct ieee80211_node *ni, uint8_t *ie) { const struct ieee80211_ath_ie *ath = (const struct ieee80211_ath_ie *) ie; ni->ni_ath_flags = ath->ath_capability; ni->ni_ath_defkeyix = LE_READ_2(&ath->ath_defkeyix); } int ieee80211_parse_athparams(struct ieee80211_node *ni, uint8_t *frm, const struct ieee80211_frame *wh) { struct ieee80211vap *vap = ni->ni_vap; const struct ieee80211_ath_ie *ath; u_int len = frm[1]; int capschanged; uint16_t defkeyix; if (len < sizeof(struct ieee80211_ath_ie)-2) { IEEE80211_DISCARD_IE(vap, IEEE80211_MSG_ELEMID | IEEE80211_MSG_SUPERG, wh, "Atheros", "too short, len %u", len); return -1; } ath = (const struct ieee80211_ath_ie *)frm; capschanged = (ni->ni_ath_flags != ath->ath_capability); defkeyix = LE_READ_2(ath->ath_defkeyix); if (capschanged || defkeyix != ni->ni_ath_defkeyix) { ni->ni_ath_flags = ath->ath_capability; ni->ni_ath_defkeyix = defkeyix; IEEE80211_NOTE(vap, IEEE80211_MSG_SUPERG, ni, "ath ie change: new caps 0x%x defkeyix 0x%x", ni->ni_ath_flags, ni->ni_ath_defkeyix); } if (IEEE80211_ATH_CAP(vap, ni, ATHEROS_CAP_TURBO_PRIME)) { uint16_t curflags, newflags; /* * Check for turbo mode switch. Calculate flags * for the new mode and effect the switch. */ newflags = curflags = vap->iv_ic->ic_bsschan->ic_flags; /* NB: BOOST is not in ic_flags, so get it from the ie */ if (ath->ath_capability & ATHEROS_CAP_BOOST) newflags |= IEEE80211_CHAN_TURBO; else newflags &= ~IEEE80211_CHAN_TURBO; if (newflags != curflags) ieee80211_dturbo_switch(vap, newflags); } return capschanged; } /* * Decap the encapsulated frame pair and dispatch the first * for delivery. The second frame is returned for delivery * via the normal path. */ struct mbuf * ieee80211_ff_decap(struct ieee80211_node *ni, struct mbuf *m) { #define FF_LLC_SIZE (sizeof(struct ether_header) + sizeof(struct llc)) #define MS(x,f) (((x) & f) >> f##_S) struct ieee80211vap *vap = ni->ni_vap; struct llc *llc; uint32_t ath; struct mbuf *n; int framelen; /* NB: we assume caller does this check for us */ KASSERT(IEEE80211_ATH_CAP(vap, ni, IEEE80211_NODE_FF), ("ff not negotiated")); /* * Check for fast-frame tunnel encapsulation. */ if (m->m_pkthdr.len < 3*FF_LLC_SIZE) return m; if (m->m_len < FF_LLC_SIZE && (m = m_pullup(m, FF_LLC_SIZE)) == NULL) { IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY, ni->ni_macaddr, "fast-frame", "%s", "m_pullup(llc) failed"); vap->iv_stats.is_rx_tooshort++; return NULL; } llc = (struct llc *)(mtod(m, uint8_t *) + sizeof(struct ether_header)); if (llc->llc_snap.ether_type != htons(ATH_FF_ETH_TYPE)) return m; m_adj(m, FF_LLC_SIZE); m_copydata(m, 0, sizeof(uint32_t), (caddr_t) &ath); if (MS(ath, ATH_FF_PROTO) != ATH_FF_PROTO_L2TUNNEL) { IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY, ni->ni_macaddr, "fast-frame", "unsupport tunnel protocol, header 0x%x", ath); vap->iv_stats.is_ff_badhdr++; m_freem(m); return NULL; } /* NB: skip header and alignment padding */ m_adj(m, roundup(sizeof(uint32_t) - 2, 4) + 2); vap->iv_stats.is_ff_decap++; /* * Decap the first frame, bust it apart from the * second and deliver; then decap the second frame * and return it to the caller for normal delivery. */ m = ieee80211_decap1(m, &framelen); if (m == NULL) { IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY, ni->ni_macaddr, "fast-frame", "%s", "first decap failed"); vap->iv_stats.is_ff_tooshort++; return NULL; } n = m_split(m, framelen, M_NOWAIT); if (n == NULL) { IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY, ni->ni_macaddr, "fast-frame", "%s", "unable to split encapsulated frames"); vap->iv_stats.is_ff_split++; m_freem(m); /* NB: must reclaim */ return NULL; } /* XXX not right for WDS */ vap->iv_deliver_data(vap, ni, m); /* 1st of pair */ /* * Decap second frame. */ m_adj(n, roundup2(framelen, 4) - framelen); /* padding */ n = ieee80211_decap1(n, &framelen); if (n == NULL) { IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY, ni->ni_macaddr, "fast-frame", "%s", "second decap failed"); vap->iv_stats.is_ff_tooshort++; } /* XXX verify framelen against mbuf contents */ return n; /* 2nd delivered by caller */ #undef MS #undef FF_LLC_SIZE } /* * Do Ethernet-LLC encapsulation for each payload in a fast frame * tunnel encapsulation. The frame is assumed to have an Ethernet * header at the front that must be stripped before prepending the * LLC followed by the Ethernet header passed in (with an Ethernet * type that specifies the payload size). */ static struct mbuf * ff_encap1(struct ieee80211vap *vap, struct mbuf *m, const struct ether_header *eh) { struct llc *llc; uint16_t payload; /* XXX optimize by combining m_adj+M_PREPEND */ m_adj(m, sizeof(struct ether_header) - sizeof(struct llc)); llc = mtod(m, struct llc *); llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP; llc->llc_control = LLC_UI; llc->llc_snap.org_code[0] = 0; llc->llc_snap.org_code[1] = 0; llc->llc_snap.org_code[2] = 0; llc->llc_snap.ether_type = eh->ether_type; payload = m->m_pkthdr.len; /* NB: w/o Ethernet header */ M_PREPEND(m, sizeof(struct ether_header), M_DONTWAIT); if (m == NULL) { /* XXX cannot happen */ IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG, "%s: no space for ether_header\n", __func__); vap->iv_stats.is_tx_nobuf++; return NULL; } ETHER_HEADER_COPY(mtod(m, void *), eh); mtod(m, struct ether_header *)->ether_type = htons(payload); return m; } /* * Fast frame encapsulation. There must be two packets * chained with m_nextpkt. We do header adjustment for * each, add the tunnel encapsulation, and then concatenate * the mbuf chains to form a single frame for transmission. */ struct mbuf * ieee80211_ff_encap(struct ieee80211vap *vap, struct mbuf *m1, int hdrspace, struct ieee80211_key *key) { struct mbuf *m2; struct ether_header eh1, eh2; struct llc *llc; struct mbuf *m; int pad; m2 = m1->m_nextpkt; if (m2 == NULL) { IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG, "%s: only one frame\n", __func__); goto bad; } m1->m_nextpkt = NULL; /* * Include fast frame headers in adjusting header * layout; this allocates space according to what * ff_encap will do. */ m1 = ieee80211_mbuf_adjust(vap, hdrspace + sizeof(struct llc) + sizeof(uint32_t) + 2 + sizeof(struct ether_header), key, m1); if (m1 == NULL) { /* NB: ieee80211_mbuf_adjust handles msgs+statistics */ m_freem(m2); goto bad; } /* * Copy second frame's Ethernet header out of line * and adjust for encapsulation headers. Note that * we make room for padding in case there isn't room * at the end of first frame. */ KASSERT(m2->m_len >= sizeof(eh2), ("no ethernet header!")); ETHER_HEADER_COPY(&eh2, mtod(m2, caddr_t)); m2 = ieee80211_mbuf_adjust(vap, ATH_FF_MAX_HDR_PAD + sizeof(struct ether_header), NULL, m2); if (m2 == NULL) { /* NB: ieee80211_mbuf_adjust handles msgs+statistics */ goto bad; } /* * Now do tunnel encapsulation. First, each * frame gets a standard encapsulation. */ m1 = ff_encap1(vap, m1, &eh1); if (m1 == NULL) goto bad; m2 = ff_encap1(vap, m2, &eh2); if (m2 == NULL) goto bad; /* * Pad leading frame to a 4-byte boundary. If there * is space at the end of the first frame, put it * there; otherwise prepend to the front of the second * frame. We know doing the second will always work * because we reserve space above. We prefer appending * as this typically has better DMA alignment properties. */ for (m = m1; m->m_next != NULL; m = m->m_next) ; pad = roundup2(m1->m_pkthdr.len, 4) - m1->m_pkthdr.len; if (pad) { if (M_TRAILINGSPACE(m) < pad) { /* prepend to second */ m2->m_data -= pad; m2->m_len += pad; m2->m_pkthdr.len += pad; } else { /* append to first */ m->m_len += pad; m1->m_pkthdr.len += pad; } } /* * Now, stick 'em together and prepend the tunnel headers; * first the Atheros tunnel header (all zero for now) and * then a special fast frame LLC. * * XXX optimize by prepending together */ m->m_next = m2; /* NB: last mbuf from above */ m1->m_pkthdr.len += m2->m_pkthdr.len; M_PREPEND(m1, sizeof(uint32_t)+2, M_DONTWAIT); if (m1 == NULL) { /* XXX cannot happen */ IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG, "%s: no space for tunnel header\n", __func__); vap->iv_stats.is_tx_nobuf++; return NULL; } memset(mtod(m1, void *), 0, sizeof(uint32_t)+2); M_PREPEND(m1, sizeof(struct llc), M_DONTWAIT); if (m1 == NULL) { /* XXX cannot happen */ IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG, "%s: no space for llc header\n", __func__); vap->iv_stats.is_tx_nobuf++; return NULL; } llc = mtod(m1, struct llc *); llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP; llc->llc_control = LLC_UI; llc->llc_snap.org_code[0] = ATH_FF_SNAP_ORGCODE_0; llc->llc_snap.org_code[1] = ATH_FF_SNAP_ORGCODE_1; llc->llc_snap.org_code[2] = ATH_FF_SNAP_ORGCODE_2; llc->llc_snap.ether_type = htons(ATH_FF_ETH_TYPE); vap->iv_stats.is_ff_encap++; return m1; bad: if (m1 != NULL) m_freem(m1); if (m2 != NULL) m_freem(m2); return NULL; } /* * Switch between turbo and non-turbo operating modes. * Use the specified channel flags to locate the new * channel, update 802.11 state, and then call back into * the driver to effect the change. */ void ieee80211_dturbo_switch(struct ieee80211vap *vap, int newflags) { struct ieee80211com *ic = vap->iv_ic; struct ieee80211_channel *chan; chan = ieee80211_find_channel(ic, ic->ic_bsschan->ic_freq, newflags); if (chan == NULL) { /* XXX should not happen */ IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG, "%s: no channel with freq %u flags 0x%x\n", __func__, ic->ic_bsschan->ic_freq, newflags); return; } IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG, "%s: %s -> %s (freq %u flags 0x%x)\n", __func__, ieee80211_phymode_name[ieee80211_chan2mode(ic->ic_bsschan)], ieee80211_phymode_name[ieee80211_chan2mode(chan)], chan->ic_freq, chan->ic_flags); ic->ic_bsschan = chan; ic->ic_prevchan = ic->ic_curchan; ic->ic_curchan = chan; ic->ic_set_channel(ic); /* NB: do not need to reset ERP state 'cuz we're in sta mode */ } /* * Return the current ``state'' of an Atheros capbility. * If associated in station mode report the negotiated * setting. Otherwise report the current setting. */ static int getathcap(struct ieee80211vap *vap, int cap) { if (vap->iv_opmode == IEEE80211_M_STA && vap->iv_state == IEEE80211_S_RUN) return IEEE80211_ATH_CAP(vap, vap->iv_bss, cap) != 0; else return (vap->iv_flags & cap) != 0; } static int superg_ioctl_get80211(struct ieee80211vap *vap, struct ieee80211req *ireq) { switch (ireq->i_type) { case IEEE80211_IOC_FF: ireq->i_val = getathcap(vap, IEEE80211_F_FF); break; case IEEE80211_IOC_TURBOP: ireq->i_val = getathcap(vap, IEEE80211_F_TURBOP); break; default: return ENOSYS; } return 0; } IEEE80211_IOCTL_GET(superg, superg_ioctl_get80211); static int superg_ioctl_set80211(struct ieee80211vap *vap, struct ieee80211req *ireq) { switch (ireq->i_type) { case IEEE80211_IOC_FF: if (ireq->i_val) { if ((vap->iv_caps & IEEE80211_C_FF) == 0) return EOPNOTSUPP; vap->iv_flags |= IEEE80211_F_FF; } else vap->iv_flags &= ~IEEE80211_F_FF; return ERESTART; case IEEE80211_IOC_TURBOP: if (ireq->i_val) { if ((vap->iv_caps & IEEE80211_C_TURBOP) == 0) return EOPNOTSUPP; vap->iv_flags |= IEEE80211_F_TURBOP; } else vap->iv_flags &= ~IEEE80211_F_TURBOP; return ENETRESET; default: return ENOSYS; } return 0; } IEEE80211_IOCTL_SET(superg, superg_ioctl_set80211); Index: head/sys/net80211/ieee80211_superg.h =================================================================== --- head/sys/net80211/ieee80211_superg.h (revision 190454) +++ head/sys/net80211/ieee80211_superg.h (revision 190455) @@ -1,57 +1,84 @@ /*- * Copyright (c) 2009 Sam Leffler, Errno Consulting * 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_SUPERG_H_ #define _NET80211_IEEE80211_SUPERG_H_ /* * Atheros' 802.11 SuperG protocol support. */ +/* + * Atheros advanced capability information element. + */ +struct ieee80211_ath_ie { + uint8_t ath_id; /* IEEE80211_ELEMID_VENDOR */ + uint8_t ath_len; /* length in bytes */ + uint8_t ath_oui[3]; /* ATH_OUI */ + uint8_t ath_oui_type; /* ATH_OUI_TYPE */ + uint8_t ath_oui_subtype; /* ATH_OUI_SUBTYPE */ + uint8_t ath_version; /* spec revision */ + uint8_t ath_capability; /* capability info */ +#define ATHEROS_CAP_TURBO_PRIME 0x01 /* dynamic turbo--aka Turbo' */ +#define ATHEROS_CAP_COMPRESSION 0x02 /* data compression */ +#define ATHEROS_CAP_FAST_FRAME 0x04 /* fast (jumbo) frames */ +#define ATHEROS_CAP_XR 0x08 /* Xtended Range support */ +#define ATHEROS_CAP_AR 0x10 /* Advanded Radar support */ +#define ATHEROS_CAP_BURST 0x20 /* Bursting - not negotiated */ +#define ATHEROS_CAP_WME 0x40 /* CWMin tuning */ +#define ATHEROS_CAP_BOOST 0x80 /* use turbo/!turbo mode */ + uint8_t ath_defkeyix[2]; +} __packed; + +#define ATH_OUI_VERSION 0x00 +#define ATH_OUI_SUBTYPE 0x01 + +#ifdef _KERNEL void ieee80211_superg_attach(struct ieee80211com *); void ieee80211_superg_detach(struct ieee80211com *); void ieee80211_superg_vattach(struct ieee80211vap *); void ieee80211_superg_vdetach(struct ieee80211vap *); uint8_t *ieee80211_add_ath(uint8_t *, uint8_t, ieee80211_keyix); uint8_t *ieee80211_add_athcaps(uint8_t *, const struct ieee80211_node *); void ieee80211_parse_ath(struct ieee80211_node *, uint8_t *); int ieee80211_parse_athparams(struct ieee80211_node *, uint8_t *, const struct ieee80211_frame *); struct mbuf *ieee80211_ff_encap(struct ieee80211vap *, struct mbuf *, int, struct ieee80211_key *); struct mbuf *ieee80211_ff_decap(struct ieee80211_node *, struct mbuf *); static __inline struct mbuf * ieee80211_decap_fastframe(struct ieee80211vap *vap, struct ieee80211_node *ni, struct mbuf *m) { return IEEE80211_ATH_CAP(vap, ni, IEEE80211_NODE_FF) ? ieee80211_ff_decap(ni, m) : m; } +#endif /* _KERNEL */ #endif /* _NET80211_IEEE80211_SUPERG_H_ */ Index: head/sys/net80211/ieee80211_tdma.c =================================================================== --- head/sys/net80211/ieee80211_tdma.c (revision 190454) +++ head/sys/net80211/ieee80211_tdma.c (revision 190455) @@ -1,788 +1,798 @@ /*- * 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 #ifdef __FreeBSD__ __FBSDID("$FreeBSD$"); #endif /* * IEEE 802.11 TDMA mode support. */ #include "opt_inet.h" +#include "opt_tdma.h" #include "opt_wlan.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include -#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 #ifndef TDMA_TXRATE_STURBO_A_DEFAULT #define TDMA_TXRATE_STURBO_A_DEFAULT 2*24 #endif #ifndef TDMA_TXRATE_HALF_DEFAULT #define TDMA_TXRATE_HALF_DEFAULT 2*12 #endif #ifndef TDMA_TXRATE_QUARTER_DEFAULT #define TDMA_TXRATE_QUARTER_DEFAULT 2*6 #endif #ifndef TDMA_TXRATE_11NA_DEFAULT #define TDMA_TXRATE_11NA_DEFAULT (4 | IEEE80211_RATE_MCS) #endif #ifndef TDMA_TXRATE_11NG_DEFAULT #define TDMA_TXRATE_11NG_DEFAULT (4 | IEEE80211_RATE_MCS) #endif + +#define TDMA_VERSION_VALID(_version) \ + (TDMA_VERSION_V2 <= (_version) && (_version) <= TDMA_VERSION) +#define TDMA_SLOTCNT_VALID(_slotcnt) \ + (2 <= (_slotcnt) && (_slotcnt) <= TDMA_MAXSLOTS) +/* XXX magic constants */ +#define TDMA_SLOTLEN_VALID(_slotlen) \ + (2*100 <= (_slotlen) && (unsigned)(_slotlen) <= 0xfffff) +/* XXX probably should set a max */ +#define TDMA_BINTVAL_VALID(_bintval) (1 <= (_bintval)) 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 settxparms(struct ieee80211vap *vap, enum ieee80211_phymode mode, int rate) { vap->iv_txparms[mode].ucastrate = rate; vap->iv_txparms[mode].mcastrate = rate; } 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_version = TDMA_VERSION; 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 */ settxparms(vap, IEEE80211_MODE_11A, TDMA_TXRATE_11A_DEFAULT); settxparms(vap, IEEE80211_MODE_11B, TDMA_TXRATE_11B_DEFAULT); settxparms(vap, IEEE80211_MODE_11G, TDMA_TXRATE_11G_DEFAULT); settxparms(vap, IEEE80211_MODE_STURBO_A, TDMA_TXRATE_STURBO_A_DEFAULT); settxparms(vap, IEEE80211_MODE_11NA, TDMA_TXRATE_11NA_DEFAULT); settxparms(vap, IEEE80211_MODE_11NG, TDMA_TXRATE_11NG_DEFAULT); settxparms(vap, IEEE80211_MODE_HALF, TDMA_TXRATE_HALF_DEFAULT); settxparms(vap, IEEE80211_MODE_QUARTER, TDMA_TXRATE_QUARTER_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 */ } static void sta_leave(void *arg, struct ieee80211_node *ni) { struct ieee80211vap *vap = arg; if (ni->ni_vap == vap && ni != vap->iv_bss) ieee80211_node_leave(ni); } /* * 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; struct ieee80211com *ic = vap->iv_ic; enum ieee80211_state ostate; int status; IEEE80211_LOCK_ASSERT(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 (ostate == IEEE80211_S_RUN) { /* purge station table; entries are stale */ ieee80211_iterate_nodes(&ic->ic_sta, sta_leave, vap); } 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 && vap->iv_des_chan == IEEE80211_CHAN_ANYC) { /* * Start s/w beacon miss timer for slave devices w/o * hardware support. Note we do this only if we're * not locked to a channel (i.e. roam to follow the * master). 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++; /* * 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 * to 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 slot, slotlen, update; KASSERT(vap->iv_caps & IEEE80211_C_TDMA, ("not a tdma vap, caps 0x%x", vap->iv_caps)); update = 0; if (tdma->tdma_slotcnt != ts->tdma_slotcnt) { if (!TDMA_SLOTCNT_VALID(tdma->tdma_slotcnt)) { if (ppsratecheck(&ts->tdma_lastprint, &ts->tdma_fails, 1)) printf("%s: bad slot cnt %u\n", __func__, tdma->tdma_slotcnt); return 0; } update |= TDMA_UPDATE_SLOTCNT; } slotlen = le16toh(tdma->tdma_slotlen) * 100; if (slotlen != ts->tdma_slotlen) { if (!TDMA_SLOTLEN_VALID(slotlen)) { if (ppsratecheck(&ts->tdma_lastprint, &ts->tdma_fails, 1)) printf("%s: bad slot len %u\n", __func__, slotlen); return 0; } update |= TDMA_UPDATE_SLOTLEN; } if (tdma->tdma_bintval != ts->tdma_bintval) { if (!TDMA_BINTVAL_VALID(tdma->tdma_bintval)) { if (ppsratecheck(&ts->tdma_lastprint, &ts->tdma_fails, 1)) printf("%s: bad beacon interval %u\n", __func__, tdma->tdma_bintval); return 0; } update |= TDMA_UPDATE_BINTVAL; } slot = ts->tdma_slot; if (pickslot) { /* * Pick unoccupied slot. Note we never choose slot 0. */ for (slot = tdma->tdma_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__, tdma->tdma_slotcnt, tdma->tdma_inuse[0]); /* XXX need to do something better */ return 0; } if (slot != ts->tdma_slot) update |= TDMA_UPDATE_SLOT; } if (ni != ts->tdma_peer) { /* update everything */ update = TDMA_UPDATE_SLOT | TDMA_UPDATE_SLOTCNT | TDMA_UPDATE_SLOTLEN | TDMA_UPDATE_BINTVAL; } if (update) { /* * New/changed parameters; update runtime state. */ /* XXX overwrites user parameters */ if (update & TDMA_UPDATE_SLOTCNT) ts->tdma_slotcnt = tdma->tdma_slotcnt; if (update & TDMA_UPDATE_SLOTLEN) ts->tdma_slotlen = slotlen; if (update & TDMA_UPDATE_SLOT) ts->tdma_slot = slot; if (update & TDMA_UPDATE_BINTVAL) ts->tdma_bintval = tdma->tdma_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__, ts->tdma_slot, ts->tdma_slotcnt, 100*ts->tdma_slotlen, ts->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, update); /* * 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 != ts->tdma_version) { IEEE80211_DISCARD_IE(vap, IEEE80211_MSG_ELEMID | IEEE80211_MSG_TDMA, wh, "tdma", "bad version %u (ours %u)", tdma->tdma_version, ts->tdma_version); return IEEE80211_REASON_IE_INVALID; } /* * NB: ideally we'd check against tdma_slotcnt, but that * would require extra effort so do this easy check that * covers the work below; more stringent checks are done * before we make more extensive use of the ie contents. */ if (tdma->tdma_slot >= TDMA_MAXSLOTS) { IEEE80211_DISCARD_IE(vap, IEEE80211_MSG_ELEMID | IEEE80211_MSG_TDMA, wh, "tdma", "invalid slot %u", tdma->tdma_slot); 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 *ts = 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, ¶m, sizeof(param)); frm += __offsetof(struct ieee80211_tdma_param, tdma_slot); *frm++ = ts->tdma_slot; *frm++ = ts->tdma_slotcnt; /* NB: convert units to fit in 16-bits */ slotlen = ts->tdma_slotlen / 100; /* 100us units */ ADDSHORT(frm, slotlen); *frm++ = ts->tdma_bintval; *frm++ = ts->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--; } static int 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 ENOSYS; } return 0; } IEEE80211_IOCTL_GET(tdma, tdma_ioctl_get80211); static int 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 (!TDMA_SLOTCNT_VALID(ireq->i_val)) 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 (!TDMA_SLOTLEN_VALID(ireq->i_val)) return EINVAL; if (ireq->i_val != ts->tdma_slotlen) { ts->tdma_slotlen = ireq->i_val; return ERESTART; } break; case IEEE80211_IOC_TDMA_BINTERVAL: if (!TDMA_BINTVAL_VALID(ireq->i_val)) return EINVAL; if (ireq->i_val != ts->tdma_bintval) { ts->tdma_bintval = ireq->i_val; return ERESTART; } break; default: return ENOSYS; } return 0; } IEEE80211_IOCTL_SET(tdma, tdma_ioctl_set80211); Index: head/sys/net80211/ieee80211_tdma.h =================================================================== --- head/sys/net80211/ieee80211_tdma.h (revision 190454) +++ head/sys/net80211/ieee80211_tdma.h (revision 190455) @@ -1,68 +1,102 @@ /*- * 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. */ + +#define TDMA_SUBTYPE_PARAM 0x01 +#define TDMA_VERSION_V2 2 +#define TDMA_VERSION TDMA_VERSION_V2 + +/* NB: we only support 2 right now but protocol handles up to 8 */ +#define TDMA_MAXSLOTS 2 /* max slots/sta's */ + +#define TDMA_PARAM_LEN_V2 sizeof(struct ieee80211_tdma_param) + +/* + * TDMA information element. + */ +struct ieee80211_tdma_param { + u_int8_t tdma_id; /* IEEE80211_ELEMID_VENDOR */ + u_int8_t tdma_len; + u_int8_t tdma_oui[3]; /* TDMA_OUI */ + u_int8_t tdma_type; /* TDMA_OUI_TYPE */ + u_int8_t tdma_subtype; /* TDMA_SUBTYPE_PARAM */ + u_int8_t tdma_version; /* spec revision */ + u_int8_t tdma_slot; /* station slot # [0..7] */ + u_int8_t tdma_slotcnt; /* bss slot count [1..8] */ + 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; + +#ifdef _KERNEL +/* + * Implementation state. + */ struct ieee80211_tdma_state { u_int tdma_slotlen; /* bss slot length (us) */ uint8_t tdma_version; /* protocol version to use */ 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 */ uint8_t tdma_active[1]; /* mask of active slots */ int tdma_count; /* active/inuse countdown */ void *tdma_peer; /* peer station cookie */ struct timeval tdma_lastprint; /* time of last rate-limited printf */ int tdma_fails; /* fail count for rate-limiting */ /* 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 *); }; #define TDMA_UPDATE_SLOT 0x0001 /* tdma_slot changed */ #define TDMA_UPDATE_SLOTCNT 0x0002 /* tdma_slotcnt changed */ #define TDMA_UPDATE_SLOTLEN 0x0004 /* tdma_slotlen changed */ #define TDMA_UPDATE_BINTVAL 0x0008 /* tdma_bintval changed */ 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); +#endif /* _KERNEL */ #endif /* !_NET80211_IEEE80211_TDMA_H_ */