ieee80211_superg.c revision 190530
1190391Ssam/*- 2190391Ssam * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting 3190391Ssam * All rights reserved. 4190391Ssam * 5190391Ssam * Redistribution and use in source and binary forms, with or without 6190391Ssam * modification, are permitted provided that the following conditions 7190391Ssam * are met: 8190391Ssam * 1. Redistributions of source code must retain the above copyright 9190391Ssam * notice, this list of conditions and the following disclaimer. 10190391Ssam * 2. Redistributions in binary form must reproduce the above copyright 11190391Ssam * notice, this list of conditions and the following disclaimer in the 12190391Ssam * documentation and/or other materials provided with the distribution. 13190391Ssam * 14190391Ssam * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15190391Ssam * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16190391Ssam * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17190391Ssam * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18190391Ssam * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19190391Ssam * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20190391Ssam * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21190391Ssam * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22190391Ssam * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23190391Ssam * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24190391Ssam */ 25190391Ssam 26190391Ssam#include <sys/cdefs.h> 27190391Ssam__FBSDID("$FreeBSD: head/sys/net80211/ieee80211_superg.c 190530 2009-03-29 21:00:27Z sam $"); 28190391Ssam 29190391Ssam#include "opt_wlan.h" 30190391Ssam 31190391Ssam#include <sys/param.h> 32190391Ssam#include <sys/systm.h> 33190391Ssam#include <sys/mbuf.h> 34190391Ssam#include <sys/kernel.h> 35190391Ssam#include <sys/endian.h> 36190391Ssam 37190391Ssam#include <sys/socket.h> 38190391Ssam 39190391Ssam#include <net/bpf.h> 40190391Ssam#include <net/ethernet.h> 41190391Ssam#include <net/if.h> 42190391Ssam#include <net/if_llc.h> 43190391Ssam#include <net/if_media.h> 44190391Ssam 45190391Ssam#include <net80211/ieee80211_var.h> 46190391Ssam#include <net80211/ieee80211_input.h> 47190391Ssam#include <net80211/ieee80211_phy.h> 48190391Ssam#include <net80211/ieee80211_superg.h> 49190391Ssam 50190455Ssam/* 51190455Ssam * Atheros fast-frame encapsulation format. 52190455Ssam * FF max payload: 53190455Ssam * 802.2 + FFHDR + HPAD + 802.3 + 802.2 + 1500 + SPAD + 802.3 + 802.2 + 1500: 54190455Ssam * 8 + 4 + 4 + 14 + 8 + 1500 + 6 + 14 + 8 + 1500 55190455Ssam * = 3066 56190455Ssam */ 57190455Ssam/* fast frame header is 32-bits */ 58190455Ssam#define ATH_FF_PROTO 0x0000003f /* protocol */ 59190455Ssam#define ATH_FF_PROTO_S 0 60190455Ssam#define ATH_FF_FTYPE 0x000000c0 /* frame type */ 61190455Ssam#define ATH_FF_FTYPE_S 6 62190455Ssam#define ATH_FF_HLEN32 0x00000300 /* optional hdr length */ 63190455Ssam#define ATH_FF_HLEN32_S 8 64190455Ssam#define ATH_FF_SEQNUM 0x001ffc00 /* sequence number */ 65190455Ssam#define ATH_FF_SEQNUM_S 10 66190455Ssam#define ATH_FF_OFFSET 0xffe00000 /* offset to 2nd payload */ 67190455Ssam#define ATH_FF_OFFSET_S 21 68190455Ssam 69190455Ssam#define ATH_FF_MAX_HDR_PAD 4 70190455Ssam#define ATH_FF_MAX_SEP_PAD 6 71190455Ssam#define ATH_FF_MAX_HDR 30 72190455Ssam 73190455Ssam#define ATH_FF_PROTO_L2TUNNEL 0 /* L2 tunnel protocol */ 74190455Ssam#define ATH_FF_ETH_TYPE 0x88bd /* Ether type for encapsulated frames */ 75190455Ssam#define ATH_FF_SNAP_ORGCODE_0 0x00 76190455Ssam#define ATH_FF_SNAP_ORGCODE_1 0x03 77190455Ssam#define ATH_FF_SNAP_ORGCODE_2 0x7f 78190455Ssam 79190391Ssam#define ETHER_HEADER_COPY(dst, src) \ 80190391Ssam memcpy(dst, src, sizeof(struct ether_header)) 81190391Ssam 82190391Ssamvoid 83190391Ssamieee80211_superg_attach(struct ieee80211com *ic) 84190391Ssam{ 85190391Ssam} 86190391Ssam 87190391Ssamvoid 88190391Ssamieee80211_superg_detach(struct ieee80211com *ic) 89190391Ssam{ 90190391Ssam} 91190391Ssam 92190391Ssamvoid 93190391Ssamieee80211_superg_vattach(struct ieee80211vap *vap) 94190391Ssam{ 95190391Ssam if (vap->iv_caps & IEEE80211_C_FF) 96190391Ssam vap->iv_flags |= IEEE80211_F_FF; 97190450Ssam /* NB: we only implement sta mode */ 98190450Ssam if (vap->iv_opmode == IEEE80211_M_STA && 99190450Ssam (vap->iv_caps & IEEE80211_C_TURBOP)) 100190391Ssam vap->iv_flags |= IEEE80211_F_TURBOP; 101190391Ssam} 102190391Ssam 103190391Ssamvoid 104190391Ssamieee80211_superg_vdetach(struct ieee80211vap *vap) 105190391Ssam{ 106190391Ssam} 107190391Ssam 108190391Ssam#define ATH_OUI_BYTES 0x00, 0x03, 0x7f 109190391Ssam/* 110190391Ssam * Add a WME information element to a frame. 111190391Ssam */ 112190391Ssamuint8_t * 113190451Ssamieee80211_add_ath(uint8_t *frm, uint8_t caps, ieee80211_keyix defkeyix) 114190391Ssam{ 115190391Ssam static const struct ieee80211_ath_ie info = { 116190391Ssam .ath_id = IEEE80211_ELEMID_VENDOR, 117190391Ssam .ath_len = sizeof(struct ieee80211_ath_ie) - 2, 118190391Ssam .ath_oui = { ATH_OUI_BYTES }, 119190391Ssam .ath_oui_type = ATH_OUI_TYPE, 120190391Ssam .ath_oui_subtype= ATH_OUI_SUBTYPE, 121190391Ssam .ath_version = ATH_OUI_VERSION, 122190391Ssam }; 123190391Ssam struct ieee80211_ath_ie *ath = (struct ieee80211_ath_ie *) frm; 124190391Ssam 125190391Ssam memcpy(frm, &info, sizeof(info)); 126190391Ssam ath->ath_capability = caps; 127190451Ssam if (defkeyix != IEEE80211_KEYIX_NONE) { 128190451Ssam ath->ath_defkeyix[0] = (defkeyix & 0xff); 129190451Ssam ath->ath_defkeyix[1] = ((defkeyix >> 8) & 0xff); 130190451Ssam } else { 131190451Ssam ath->ath_defkeyix[0] = 0xff; 132190451Ssam ath->ath_defkeyix[1] = 0x7f; 133190451Ssam } 134190391Ssam return frm + sizeof(info); 135190391Ssam} 136190391Ssam#undef ATH_OUI_BYTES 137190391Ssam 138190451Ssamuint8_t * 139190451Ssamieee80211_add_athcaps(uint8_t *frm, const struct ieee80211_node *bss) 140190451Ssam{ 141190451Ssam const struct ieee80211vap *vap = bss->ni_vap; 142190451Ssam 143190451Ssam return ieee80211_add_ath(frm, 144190451Ssam vap->iv_flags & IEEE80211_F_ATHEROS, 145190451Ssam ((vap->iv_flags & IEEE80211_F_WPA) == 0 && 146190451Ssam bss->ni_authmode != IEEE80211_AUTH_8021X) ? 147190451Ssam vap->iv_def_txkey : IEEE80211_KEYIX_NONE); 148190451Ssam} 149190451Ssam 150190391Ssamvoid 151190391Ssamieee80211_parse_ath(struct ieee80211_node *ni, uint8_t *ie) 152190391Ssam{ 153190391Ssam const struct ieee80211_ath_ie *ath = 154190391Ssam (const struct ieee80211_ath_ie *) ie; 155190391Ssam 156190391Ssam ni->ni_ath_flags = ath->ath_capability; 157190391Ssam ni->ni_ath_defkeyix = LE_READ_2(&ath->ath_defkeyix); 158190391Ssam} 159190391Ssam 160190391Ssamint 161190391Ssamieee80211_parse_athparams(struct ieee80211_node *ni, uint8_t *frm, 162190391Ssam const struct ieee80211_frame *wh) 163190391Ssam{ 164190391Ssam struct ieee80211vap *vap = ni->ni_vap; 165190391Ssam const struct ieee80211_ath_ie *ath; 166190391Ssam u_int len = frm[1]; 167190391Ssam int capschanged; 168190391Ssam uint16_t defkeyix; 169190391Ssam 170190391Ssam if (len < sizeof(struct ieee80211_ath_ie)-2) { 171190391Ssam IEEE80211_DISCARD_IE(vap, 172190391Ssam IEEE80211_MSG_ELEMID | IEEE80211_MSG_SUPERG, 173190391Ssam wh, "Atheros", "too short, len %u", len); 174190391Ssam return -1; 175190391Ssam } 176190391Ssam ath = (const struct ieee80211_ath_ie *)frm; 177190391Ssam capschanged = (ni->ni_ath_flags != ath->ath_capability); 178190391Ssam defkeyix = LE_READ_2(ath->ath_defkeyix); 179190391Ssam if (capschanged || defkeyix != ni->ni_ath_defkeyix) { 180190391Ssam ni->ni_ath_flags = ath->ath_capability; 181190391Ssam ni->ni_ath_defkeyix = defkeyix; 182190391Ssam IEEE80211_NOTE(vap, IEEE80211_MSG_SUPERG, ni, 183190391Ssam "ath ie change: new caps 0x%x defkeyix 0x%x", 184190391Ssam ni->ni_ath_flags, ni->ni_ath_defkeyix); 185190391Ssam } 186190391Ssam if (IEEE80211_ATH_CAP(vap, ni, ATHEROS_CAP_TURBO_PRIME)) { 187190391Ssam uint16_t curflags, newflags; 188190391Ssam 189190391Ssam /* 190190391Ssam * Check for turbo mode switch. Calculate flags 191190391Ssam * for the new mode and effect the switch. 192190391Ssam */ 193190391Ssam newflags = curflags = vap->iv_ic->ic_bsschan->ic_flags; 194190391Ssam /* NB: BOOST is not in ic_flags, so get it from the ie */ 195190391Ssam if (ath->ath_capability & ATHEROS_CAP_BOOST) 196190391Ssam newflags |= IEEE80211_CHAN_TURBO; 197190391Ssam else 198190391Ssam newflags &= ~IEEE80211_CHAN_TURBO; 199190391Ssam if (newflags != curflags) 200190391Ssam ieee80211_dturbo_switch(vap, newflags); 201190391Ssam } 202190391Ssam return capschanged; 203190391Ssam} 204190391Ssam 205190391Ssam/* 206190391Ssam * Decap the encapsulated frame pair and dispatch the first 207190391Ssam * for delivery. The second frame is returned for delivery 208190391Ssam * via the normal path. 209190391Ssam */ 210190391Ssamstruct mbuf * 211190391Ssamieee80211_ff_decap(struct ieee80211_node *ni, struct mbuf *m) 212190391Ssam{ 213190391Ssam#define FF_LLC_SIZE (sizeof(struct ether_header) + sizeof(struct llc)) 214190391Ssam#define MS(x,f) (((x) & f) >> f##_S) 215190391Ssam struct ieee80211vap *vap = ni->ni_vap; 216190391Ssam struct llc *llc; 217190391Ssam uint32_t ath; 218190391Ssam struct mbuf *n; 219190391Ssam int framelen; 220190391Ssam 221190391Ssam /* NB: we assume caller does this check for us */ 222190391Ssam KASSERT(IEEE80211_ATH_CAP(vap, ni, IEEE80211_NODE_FF), 223190391Ssam ("ff not negotiated")); 224190391Ssam /* 225190391Ssam * Check for fast-frame tunnel encapsulation. 226190391Ssam */ 227190391Ssam if (m->m_pkthdr.len < 3*FF_LLC_SIZE) 228190391Ssam return m; 229190391Ssam if (m->m_len < FF_LLC_SIZE && 230190391Ssam (m = m_pullup(m, FF_LLC_SIZE)) == NULL) { 231190391Ssam IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY, 232190391Ssam ni->ni_macaddr, "fast-frame", 233190391Ssam "%s", "m_pullup(llc) failed"); 234190391Ssam vap->iv_stats.is_rx_tooshort++; 235190391Ssam return NULL; 236190391Ssam } 237190391Ssam llc = (struct llc *)(mtod(m, uint8_t *) + 238190391Ssam sizeof(struct ether_header)); 239190391Ssam if (llc->llc_snap.ether_type != htons(ATH_FF_ETH_TYPE)) 240190391Ssam return m; 241190391Ssam m_adj(m, FF_LLC_SIZE); 242190391Ssam m_copydata(m, 0, sizeof(uint32_t), (caddr_t) &ath); 243190391Ssam if (MS(ath, ATH_FF_PROTO) != ATH_FF_PROTO_L2TUNNEL) { 244190391Ssam IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY, 245190391Ssam ni->ni_macaddr, "fast-frame", 246190391Ssam "unsupport tunnel protocol, header 0x%x", ath); 247190391Ssam vap->iv_stats.is_ff_badhdr++; 248190391Ssam m_freem(m); 249190391Ssam return NULL; 250190391Ssam } 251190391Ssam /* NB: skip header and alignment padding */ 252190391Ssam m_adj(m, roundup(sizeof(uint32_t) - 2, 4) + 2); 253190391Ssam 254190391Ssam vap->iv_stats.is_ff_decap++; 255190391Ssam 256190391Ssam /* 257190391Ssam * Decap the first frame, bust it apart from the 258190391Ssam * second and deliver; then decap the second frame 259190391Ssam * and return it to the caller for normal delivery. 260190391Ssam */ 261190391Ssam m = ieee80211_decap1(m, &framelen); 262190391Ssam if (m == NULL) { 263190391Ssam IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY, 264190391Ssam ni->ni_macaddr, "fast-frame", "%s", "first decap failed"); 265190391Ssam vap->iv_stats.is_ff_tooshort++; 266190391Ssam return NULL; 267190391Ssam } 268190391Ssam n = m_split(m, framelen, M_NOWAIT); 269190391Ssam if (n == NULL) { 270190391Ssam IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY, 271190391Ssam ni->ni_macaddr, "fast-frame", 272190391Ssam "%s", "unable to split encapsulated frames"); 273190391Ssam vap->iv_stats.is_ff_split++; 274190391Ssam m_freem(m); /* NB: must reclaim */ 275190391Ssam return NULL; 276190391Ssam } 277190391Ssam /* XXX not right for WDS */ 278190391Ssam vap->iv_deliver_data(vap, ni, m); /* 1st of pair */ 279190391Ssam 280190391Ssam /* 281190391Ssam * Decap second frame. 282190391Ssam */ 283190391Ssam m_adj(n, roundup2(framelen, 4) - framelen); /* padding */ 284190391Ssam n = ieee80211_decap1(n, &framelen); 285190391Ssam if (n == NULL) { 286190391Ssam IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY, 287190391Ssam ni->ni_macaddr, "fast-frame", "%s", "second decap failed"); 288190391Ssam vap->iv_stats.is_ff_tooshort++; 289190391Ssam } 290190391Ssam /* XXX verify framelen against mbuf contents */ 291190391Ssam return n; /* 2nd delivered by caller */ 292190391Ssam#undef MS 293190391Ssam#undef FF_LLC_SIZE 294190391Ssam} 295190391Ssam 296190391Ssam/* 297190391Ssam * Do Ethernet-LLC encapsulation for each payload in a fast frame 298190391Ssam * tunnel encapsulation. The frame is assumed to have an Ethernet 299190391Ssam * header at the front that must be stripped before prepending the 300190391Ssam * LLC followed by the Ethernet header passed in (with an Ethernet 301190391Ssam * type that specifies the payload size). 302190391Ssam */ 303190391Ssamstatic struct mbuf * 304190391Ssamff_encap1(struct ieee80211vap *vap, struct mbuf *m, 305190391Ssam const struct ether_header *eh) 306190391Ssam{ 307190391Ssam struct llc *llc; 308190391Ssam uint16_t payload; 309190391Ssam 310190391Ssam /* XXX optimize by combining m_adj+M_PREPEND */ 311190391Ssam m_adj(m, sizeof(struct ether_header) - sizeof(struct llc)); 312190391Ssam llc = mtod(m, struct llc *); 313190391Ssam llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP; 314190391Ssam llc->llc_control = LLC_UI; 315190391Ssam llc->llc_snap.org_code[0] = 0; 316190391Ssam llc->llc_snap.org_code[1] = 0; 317190391Ssam llc->llc_snap.org_code[2] = 0; 318190391Ssam llc->llc_snap.ether_type = eh->ether_type; 319190391Ssam payload = m->m_pkthdr.len; /* NB: w/o Ethernet header */ 320190391Ssam 321190391Ssam M_PREPEND(m, sizeof(struct ether_header), M_DONTWAIT); 322190391Ssam if (m == NULL) { /* XXX cannot happen */ 323190391Ssam IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG, 324190391Ssam "%s: no space for ether_header\n", __func__); 325190391Ssam vap->iv_stats.is_tx_nobuf++; 326190391Ssam return NULL; 327190391Ssam } 328190391Ssam ETHER_HEADER_COPY(mtod(m, void *), eh); 329190391Ssam mtod(m, struct ether_header *)->ether_type = htons(payload); 330190391Ssam return m; 331190391Ssam} 332190391Ssam 333190391Ssam/* 334190391Ssam * Fast frame encapsulation. There must be two packets 335190391Ssam * chained with m_nextpkt. We do header adjustment for 336190391Ssam * each, add the tunnel encapsulation, and then concatenate 337190391Ssam * the mbuf chains to form a single frame for transmission. 338190391Ssam */ 339190391Ssamstruct mbuf * 340190391Ssamieee80211_ff_encap(struct ieee80211vap *vap, struct mbuf *m1, int hdrspace, 341190391Ssam struct ieee80211_key *key) 342190391Ssam{ 343190391Ssam struct mbuf *m2; 344190391Ssam struct ether_header eh1, eh2; 345190391Ssam struct llc *llc; 346190391Ssam struct mbuf *m; 347190391Ssam int pad; 348190391Ssam 349190391Ssam m2 = m1->m_nextpkt; 350190391Ssam if (m2 == NULL) { 351190391Ssam IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG, 352190391Ssam "%s: only one frame\n", __func__); 353190391Ssam goto bad; 354190391Ssam } 355190391Ssam m1->m_nextpkt = NULL; 356190391Ssam /* 357190391Ssam * Include fast frame headers in adjusting header 358190391Ssam * layout; this allocates space according to what 359190391Ssam * ff_encap will do. 360190391Ssam */ 361190391Ssam m1 = ieee80211_mbuf_adjust(vap, 362190391Ssam hdrspace + sizeof(struct llc) + sizeof(uint32_t) + 2 + 363190391Ssam sizeof(struct ether_header), 364190391Ssam key, m1); 365190391Ssam if (m1 == NULL) { 366190391Ssam /* NB: ieee80211_mbuf_adjust handles msgs+statistics */ 367190391Ssam m_freem(m2); 368190391Ssam goto bad; 369190391Ssam } 370190391Ssam 371190391Ssam /* 372190391Ssam * Copy second frame's Ethernet header out of line 373190391Ssam * and adjust for encapsulation headers. Note that 374190391Ssam * we make room for padding in case there isn't room 375190391Ssam * at the end of first frame. 376190391Ssam */ 377190391Ssam KASSERT(m2->m_len >= sizeof(eh2), ("no ethernet header!")); 378190391Ssam ETHER_HEADER_COPY(&eh2, mtod(m2, caddr_t)); 379190391Ssam m2 = ieee80211_mbuf_adjust(vap, 380190391Ssam ATH_FF_MAX_HDR_PAD + sizeof(struct ether_header), 381190391Ssam NULL, m2); 382190391Ssam if (m2 == NULL) { 383190391Ssam /* NB: ieee80211_mbuf_adjust handles msgs+statistics */ 384190391Ssam goto bad; 385190391Ssam } 386190391Ssam 387190391Ssam /* 388190391Ssam * Now do tunnel encapsulation. First, each 389190391Ssam * frame gets a standard encapsulation. 390190391Ssam */ 391190391Ssam m1 = ff_encap1(vap, m1, &eh1); 392190391Ssam if (m1 == NULL) 393190391Ssam goto bad; 394190391Ssam m2 = ff_encap1(vap, m2, &eh2); 395190391Ssam if (m2 == NULL) 396190391Ssam goto bad; 397190391Ssam 398190391Ssam /* 399190391Ssam * Pad leading frame to a 4-byte boundary. If there 400190391Ssam * is space at the end of the first frame, put it 401190391Ssam * there; otherwise prepend to the front of the second 402190391Ssam * frame. We know doing the second will always work 403190391Ssam * because we reserve space above. We prefer appending 404190391Ssam * as this typically has better DMA alignment properties. 405190391Ssam */ 406190391Ssam for (m = m1; m->m_next != NULL; m = m->m_next) 407190391Ssam ; 408190391Ssam pad = roundup2(m1->m_pkthdr.len, 4) - m1->m_pkthdr.len; 409190391Ssam if (pad) { 410190391Ssam if (M_TRAILINGSPACE(m) < pad) { /* prepend to second */ 411190391Ssam m2->m_data -= pad; 412190391Ssam m2->m_len += pad; 413190391Ssam m2->m_pkthdr.len += pad; 414190391Ssam } else { /* append to first */ 415190391Ssam m->m_len += pad; 416190391Ssam m1->m_pkthdr.len += pad; 417190391Ssam } 418190391Ssam } 419190391Ssam 420190391Ssam /* 421190391Ssam * Now, stick 'em together and prepend the tunnel headers; 422190391Ssam * first the Atheros tunnel header (all zero for now) and 423190391Ssam * then a special fast frame LLC. 424190391Ssam * 425190391Ssam * XXX optimize by prepending together 426190391Ssam */ 427190391Ssam m->m_next = m2; /* NB: last mbuf from above */ 428190391Ssam m1->m_pkthdr.len += m2->m_pkthdr.len; 429190391Ssam M_PREPEND(m1, sizeof(uint32_t)+2, M_DONTWAIT); 430190391Ssam if (m1 == NULL) { /* XXX cannot happen */ 431190391Ssam IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG, 432190391Ssam "%s: no space for tunnel header\n", __func__); 433190391Ssam vap->iv_stats.is_tx_nobuf++; 434190391Ssam return NULL; 435190391Ssam } 436190391Ssam memset(mtod(m1, void *), 0, sizeof(uint32_t)+2); 437190391Ssam 438190391Ssam M_PREPEND(m1, sizeof(struct llc), M_DONTWAIT); 439190391Ssam if (m1 == NULL) { /* XXX cannot happen */ 440190391Ssam IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG, 441190391Ssam "%s: no space for llc header\n", __func__); 442190391Ssam vap->iv_stats.is_tx_nobuf++; 443190391Ssam return NULL; 444190391Ssam } 445190391Ssam llc = mtod(m1, struct llc *); 446190391Ssam llc->llc_dsap = llc->llc_ssap = LLC_SNAP_LSAP; 447190391Ssam llc->llc_control = LLC_UI; 448190391Ssam llc->llc_snap.org_code[0] = ATH_FF_SNAP_ORGCODE_0; 449190391Ssam llc->llc_snap.org_code[1] = ATH_FF_SNAP_ORGCODE_1; 450190391Ssam llc->llc_snap.org_code[2] = ATH_FF_SNAP_ORGCODE_2; 451190391Ssam llc->llc_snap.ether_type = htons(ATH_FF_ETH_TYPE); 452190391Ssam 453190391Ssam vap->iv_stats.is_ff_encap++; 454190391Ssam 455190391Ssam return m1; 456190391Ssambad: 457190391Ssam if (m1 != NULL) 458190391Ssam m_freem(m1); 459190391Ssam if (m2 != NULL) 460190391Ssam m_freem(m2); 461190391Ssam return NULL; 462190391Ssam} 463190391Ssam 464190391Ssam/* 465190391Ssam * Switch between turbo and non-turbo operating modes. 466190391Ssam * Use the specified channel flags to locate the new 467190391Ssam * channel, update 802.11 state, and then call back into 468190391Ssam * the driver to effect the change. 469190391Ssam */ 470190391Ssamvoid 471190391Ssamieee80211_dturbo_switch(struct ieee80211vap *vap, int newflags) 472190391Ssam{ 473190391Ssam struct ieee80211com *ic = vap->iv_ic; 474190391Ssam struct ieee80211_channel *chan; 475190391Ssam 476190391Ssam chan = ieee80211_find_channel(ic, ic->ic_bsschan->ic_freq, newflags); 477190391Ssam if (chan == NULL) { /* XXX should not happen */ 478190391Ssam IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG, 479190391Ssam "%s: no channel with freq %u flags 0x%x\n", 480190391Ssam __func__, ic->ic_bsschan->ic_freq, newflags); 481190391Ssam return; 482190391Ssam } 483190391Ssam 484190391Ssam IEEE80211_DPRINTF(vap, IEEE80211_MSG_SUPERG, 485190391Ssam "%s: %s -> %s (freq %u flags 0x%x)\n", __func__, 486190391Ssam ieee80211_phymode_name[ieee80211_chan2mode(ic->ic_bsschan)], 487190391Ssam ieee80211_phymode_name[ieee80211_chan2mode(chan)], 488190391Ssam chan->ic_freq, chan->ic_flags); 489190391Ssam 490190391Ssam ic->ic_bsschan = chan; 491190391Ssam ic->ic_prevchan = ic->ic_curchan; 492190391Ssam ic->ic_curchan = chan; 493190391Ssam ic->ic_set_channel(ic); 494190391Ssam /* NB: do not need to reset ERP state 'cuz we're in sta mode */ 495190391Ssam} 496190391Ssam 497190391Ssam/* 498190391Ssam * Return the current ``state'' of an Atheros capbility. 499190391Ssam * If associated in station mode report the negotiated 500190391Ssam * setting. Otherwise report the current setting. 501190391Ssam */ 502190391Ssamstatic int 503190391Ssamgetathcap(struct ieee80211vap *vap, int cap) 504190391Ssam{ 505190391Ssam if (vap->iv_opmode == IEEE80211_M_STA && 506190391Ssam vap->iv_state == IEEE80211_S_RUN) 507190391Ssam return IEEE80211_ATH_CAP(vap, vap->iv_bss, cap) != 0; 508190391Ssam else 509190391Ssam return (vap->iv_flags & cap) != 0; 510190391Ssam} 511190391Ssam 512190391Ssamstatic int 513190391Ssamsuperg_ioctl_get80211(struct ieee80211vap *vap, struct ieee80211req *ireq) 514190391Ssam{ 515190391Ssam switch (ireq->i_type) { 516190391Ssam case IEEE80211_IOC_FF: 517190391Ssam ireq->i_val = getathcap(vap, IEEE80211_F_FF); 518190391Ssam break; 519190391Ssam case IEEE80211_IOC_TURBOP: 520190391Ssam ireq->i_val = getathcap(vap, IEEE80211_F_TURBOP); 521190391Ssam break; 522190391Ssam default: 523190391Ssam return ENOSYS; 524190391Ssam } 525190391Ssam return 0; 526190391Ssam} 527190391SsamIEEE80211_IOCTL_GET(superg, superg_ioctl_get80211); 528190391Ssam 529190391Ssamstatic int 530190391Ssamsuperg_ioctl_set80211(struct ieee80211vap *vap, struct ieee80211req *ireq) 531190391Ssam{ 532190391Ssam switch (ireq->i_type) { 533190391Ssam case IEEE80211_IOC_FF: 534190391Ssam if (ireq->i_val) { 535190391Ssam if ((vap->iv_caps & IEEE80211_C_FF) == 0) 536190391Ssam return EOPNOTSUPP; 537190391Ssam vap->iv_flags |= IEEE80211_F_FF; 538190391Ssam } else 539190391Ssam vap->iv_flags &= ~IEEE80211_F_FF; 540190530Ssam return ENETRESET; 541190391Ssam case IEEE80211_IOC_TURBOP: 542190391Ssam if (ireq->i_val) { 543190391Ssam if ((vap->iv_caps & IEEE80211_C_TURBOP) == 0) 544190391Ssam return EOPNOTSUPP; 545190391Ssam vap->iv_flags |= IEEE80211_F_TURBOP; 546190391Ssam } else 547190391Ssam vap->iv_flags &= ~IEEE80211_F_TURBOP; 548190391Ssam return ENETRESET; 549190391Ssam default: 550190391Ssam return ENOSYS; 551190391Ssam } 552190391Ssam return 0; 553190391Ssam} 554190391SsamIEEE80211_IOCTL_SET(superg, superg_ioctl_set80211); 555