Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2002-2005, Instant802 Networks, Inc. |
| 3 | * Copyright 2005-2006, Devicescape Software, Inc. |
| 4 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> |
| 5 | * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * utilities for mac80211 |
| 12 | */ |
| 13 | |
| 14 | #include <net/mac80211.h> |
| 15 | #include <linux/netdevice.h> |
| 16 | #include <linux/types.h> |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/skbuff.h> |
| 19 | #include <linux/etherdevice.h> |
| 20 | #include <linux/if_arp.h> |
| 21 | #include <linux/wireless.h> |
| 22 | #include <linux/bitmap.h> |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 23 | #include <net/net_namespace.h> |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 24 | #include <net/cfg80211.h> |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 25 | #include <net/rtnetlink.h> |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 26 | |
| 27 | #include "ieee80211_i.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 28 | #include "rate.h" |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 29 | #include "mesh.h" |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 30 | #include "wme.h" |
| 31 | |
| 32 | /* privid for wiphys to determine whether they belong to us or not */ |
| 33 | void *mac80211_wiphy_privid = &mac80211_wiphy_privid; |
| 34 | |
| 35 | /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */ |
| 36 | /* Ethernet-II snap header (RFC1042 for most EtherTypes) */ |
Senthil Balasubramanian | c97c23e | 2008-05-28 23:15:32 +0530 | [diff] [blame] | 37 | const unsigned char rfc1042_header[] __aligned(2) = |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 38 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 39 | |
| 40 | /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */ |
Senthil Balasubramanian | c97c23e | 2008-05-28 23:15:32 +0530 | [diff] [blame] | 41 | const unsigned char bridge_tunnel_header[] __aligned(2) = |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 42 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; |
| 43 | |
Luis R. Rodriguez | 9a95371 | 2009-01-22 15:05:53 -0800 | [diff] [blame] | 44 | struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy) |
| 45 | { |
| 46 | struct ieee80211_local *local; |
| 47 | BUG_ON(!wiphy); |
| 48 | |
| 49 | local = wiphy_priv(wiphy); |
| 50 | return &local->hw; |
| 51 | } |
| 52 | EXPORT_SYMBOL(wiphy_to_ieee80211_hw); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 53 | |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 54 | u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len, |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 55 | enum nl80211_iftype type) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 56 | { |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 57 | __le16 fc = hdr->frame_control; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 58 | |
Ron Rindjunsky | 98f0b0a | 2007-12-18 17:23:53 +0200 | [diff] [blame] | 59 | /* drop ACK/CTS frames and incorrect hdr len (ctrl) */ |
| 60 | if (len < 16) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 61 | return NULL; |
| 62 | |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 63 | if (ieee80211_is_data(fc)) { |
Ron Rindjunsky | 98f0b0a | 2007-12-18 17:23:53 +0200 | [diff] [blame] | 64 | if (len < 24) /* drop incorrect hdr len (data) */ |
| 65 | return NULL; |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 66 | |
| 67 | if (ieee80211_has_a4(fc)) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 68 | return NULL; |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 69 | if (ieee80211_has_tods(fc)) |
| 70 | return hdr->addr1; |
| 71 | if (ieee80211_has_fromds(fc)) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 72 | return hdr->addr2; |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 73 | |
| 74 | return hdr->addr3; |
| 75 | } |
| 76 | |
| 77 | if (ieee80211_is_mgmt(fc)) { |
Ron Rindjunsky | 98f0b0a | 2007-12-18 17:23:53 +0200 | [diff] [blame] | 78 | if (len < 24) /* drop incorrect hdr len (mgmt) */ |
| 79 | return NULL; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 80 | return hdr->addr3; |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | if (ieee80211_is_ctl(fc)) { |
| 84 | if(ieee80211_is_pspoll(fc)) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 85 | return hdr->addr1; |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 86 | |
| 87 | if (ieee80211_is_back_req(fc)) { |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 88 | switch (type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 89 | case NL80211_IFTYPE_STATION: |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 90 | return hdr->addr2; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 91 | case NL80211_IFTYPE_AP: |
| 92 | case NL80211_IFTYPE_AP_VLAN: |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 93 | return hdr->addr1; |
| 94 | default: |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 95 | break; /* fall through to the return */ |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 96 | } |
| 97 | } |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | return NULL; |
| 101 | } |
| 102 | |
Harvey Harrison | 6693be7 | 2008-06-11 14:21:57 -0700 | [diff] [blame] | 103 | unsigned int ieee80211_hdrlen(__le16 fc) |
| 104 | { |
| 105 | unsigned int hdrlen = 24; |
| 106 | |
| 107 | if (ieee80211_is_data(fc)) { |
| 108 | if (ieee80211_has_a4(fc)) |
| 109 | hdrlen = 30; |
| 110 | if (ieee80211_is_data_qos(fc)) |
| 111 | hdrlen += IEEE80211_QOS_CTL_LEN; |
| 112 | goto out; |
| 113 | } |
| 114 | |
| 115 | if (ieee80211_is_ctl(fc)) { |
| 116 | /* |
| 117 | * ACK and CTS are 10 bytes, all others 16. To see how |
| 118 | * to get this condition consider |
| 119 | * subtype mask: 0b0000000011110000 (0x00F0) |
| 120 | * ACK subtype: 0b0000000011010000 (0x00D0) |
| 121 | * CTS subtype: 0b0000000011000000 (0x00C0) |
| 122 | * bits that matter: ^^^ (0x00E0) |
| 123 | * value of those: 0b0000000011000000 (0x00C0) |
| 124 | */ |
| 125 | if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0)) |
| 126 | hdrlen = 10; |
| 127 | else |
| 128 | hdrlen = 16; |
| 129 | } |
| 130 | out: |
| 131 | return hdrlen; |
| 132 | } |
| 133 | EXPORT_SYMBOL(ieee80211_hdrlen); |
| 134 | |
Harvey Harrison | c9c6950 | 2008-06-11 14:21:57 -0700 | [diff] [blame] | 135 | unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 136 | { |
Harvey Harrison | c9c6950 | 2008-06-11 14:21:57 -0700 | [diff] [blame] | 137 | const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *)skb->data; |
| 138 | unsigned int hdrlen; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 139 | |
| 140 | if (unlikely(skb->len < 10)) |
| 141 | return 0; |
Harvey Harrison | c9c6950 | 2008-06-11 14:21:57 -0700 | [diff] [blame] | 142 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 143 | if (unlikely(hdrlen > skb->len)) |
| 144 | return 0; |
| 145 | return hdrlen; |
| 146 | } |
| 147 | EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb); |
| 148 | |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 149 | int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr) |
| 150 | { |
| 151 | int ae = meshhdr->flags & IEEE80211S_FLAGS_AE; |
| 152 | /* 7.1.3.5a.2 */ |
| 153 | switch (ae) { |
| 154 | case 0: |
Luis Carlos Cobo | ef26925 | 2008-05-05 12:02:35 -0700 | [diff] [blame] | 155 | return 6; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 156 | case 1: |
Luis Carlos Cobo | ef26925 | 2008-05-05 12:02:35 -0700 | [diff] [blame] | 157 | return 12; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 158 | case 2: |
Luis Carlos Cobo | ef26925 | 2008-05-05 12:02:35 -0700 | [diff] [blame] | 159 | return 18; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 160 | case 3: |
Luis Carlos Cobo | ef26925 | 2008-05-05 12:02:35 -0700 | [diff] [blame] | 161 | return 24; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 162 | default: |
Luis Carlos Cobo | ef26925 | 2008-05-05 12:02:35 -0700 | [diff] [blame] | 163 | return 6; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 164 | } |
| 165 | } |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 166 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 167 | void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 168 | { |
| 169 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data; |
| 170 | |
| 171 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 172 | if (tx->extra_frag) { |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 173 | struct ieee80211_hdr *fhdr; |
| 174 | int i; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 175 | for (i = 0; i < tx->num_extra_frag; i++) { |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 176 | fhdr = (struct ieee80211_hdr *) |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 177 | tx->extra_frag[i]->data; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 178 | fhdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | int ieee80211_frame_duration(struct ieee80211_local *local, size_t len, |
| 184 | int rate, int erp, int short_preamble) |
| 185 | { |
| 186 | int dur; |
| 187 | |
| 188 | /* calculate duration (in microseconds, rounded up to next higher |
| 189 | * integer if it includes a fractional microsecond) to send frame of |
| 190 | * len bytes (does not include FCS) at the given rate. Duration will |
| 191 | * also include SIFS. |
| 192 | * |
| 193 | * rate is in 100 kbps, so divident is multiplied by 10 in the |
| 194 | * DIV_ROUND_UP() operations. |
| 195 | */ |
| 196 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 197 | if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ || erp) { |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 198 | /* |
| 199 | * OFDM: |
| 200 | * |
| 201 | * N_DBPS = DATARATE x 4 |
| 202 | * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS) |
| 203 | * (16 = SIGNAL time, 6 = tail bits) |
| 204 | * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext |
| 205 | * |
| 206 | * T_SYM = 4 usec |
| 207 | * 802.11a - 17.5.2: aSIFSTime = 16 usec |
| 208 | * 802.11g - 19.8.4: aSIFSTime = 10 usec + |
| 209 | * signal ext = 6 usec |
| 210 | */ |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 211 | dur = 16; /* SIFS + signal ext */ |
| 212 | dur += 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */ |
| 213 | dur += 4; /* 17.3.2.3: T_SIGNAL = 4 usec */ |
| 214 | dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10, |
| 215 | 4 * rate); /* T_SYM x N_SYM */ |
| 216 | } else { |
| 217 | /* |
| 218 | * 802.11b or 802.11g with 802.11b compatibility: |
| 219 | * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime + |
| 220 | * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0. |
| 221 | * |
| 222 | * 802.11 (DS): 15.3.3, 802.11b: 18.3.4 |
| 223 | * aSIFSTime = 10 usec |
| 224 | * aPreambleLength = 144 usec or 72 usec with short preamble |
| 225 | * aPLCPHeaderLength = 48 usec or 24 usec with short preamble |
| 226 | */ |
| 227 | dur = 10; /* aSIFSTime = 10 usec */ |
| 228 | dur += short_preamble ? (72 + 24) : (144 + 48); |
| 229 | |
| 230 | dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate); |
| 231 | } |
| 232 | |
| 233 | return dur; |
| 234 | } |
| 235 | |
| 236 | /* Exported duration function for driver use */ |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 237 | __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw, |
| 238 | struct ieee80211_vif *vif, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 239 | size_t frame_len, |
| 240 | struct ieee80211_rate *rate) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 241 | { |
| 242 | struct ieee80211_local *local = hw_to_local(hw); |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 243 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 244 | u16 dur; |
| 245 | int erp; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 246 | bool short_preamble = false; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 247 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 248 | erp = 0; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 249 | if (vif) { |
| 250 | sdata = vif_to_sdata(vif); |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 251 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 252 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
| 253 | erp = rate->flags & IEEE80211_RATE_ERP_G; |
| 254 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 255 | |
| 256 | dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, erp, |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 257 | short_preamble); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 258 | |
| 259 | return cpu_to_le16(dur); |
| 260 | } |
| 261 | EXPORT_SYMBOL(ieee80211_generic_frame_duration); |
| 262 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 263 | __le16 ieee80211_rts_duration(struct ieee80211_hw *hw, |
| 264 | struct ieee80211_vif *vif, size_t frame_len, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 265 | const struct ieee80211_tx_info *frame_txctl) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 266 | { |
| 267 | struct ieee80211_local *local = hw_to_local(hw); |
| 268 | struct ieee80211_rate *rate; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 269 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 270 | bool short_preamble; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 271 | int erp; |
| 272 | u16 dur; |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 273 | struct ieee80211_supported_band *sband; |
| 274 | |
| 275 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 276 | |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 277 | short_preamble = false; |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 278 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 279 | rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 280 | |
| 281 | erp = 0; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 282 | if (vif) { |
| 283 | sdata = vif_to_sdata(vif); |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 284 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 285 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
| 286 | erp = rate->flags & IEEE80211_RATE_ERP_G; |
| 287 | } |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 288 | |
| 289 | /* CTS duration */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 290 | dur = ieee80211_frame_duration(local, 10, rate->bitrate, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 291 | erp, short_preamble); |
| 292 | /* Data frame duration */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 293 | dur += ieee80211_frame_duration(local, frame_len, rate->bitrate, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 294 | erp, short_preamble); |
| 295 | /* ACK duration */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 296 | dur += ieee80211_frame_duration(local, 10, rate->bitrate, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 297 | erp, short_preamble); |
| 298 | |
| 299 | return cpu_to_le16(dur); |
| 300 | } |
| 301 | EXPORT_SYMBOL(ieee80211_rts_duration); |
| 302 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 303 | __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw, |
| 304 | struct ieee80211_vif *vif, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 305 | size_t frame_len, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 306 | const struct ieee80211_tx_info *frame_txctl) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 307 | { |
| 308 | struct ieee80211_local *local = hw_to_local(hw); |
| 309 | struct ieee80211_rate *rate; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 310 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 311 | bool short_preamble; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 312 | int erp; |
| 313 | u16 dur; |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 314 | struct ieee80211_supported_band *sband; |
| 315 | |
| 316 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 317 | |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 318 | short_preamble = false; |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 319 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 320 | rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 321 | erp = 0; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 322 | if (vif) { |
| 323 | sdata = vif_to_sdata(vif); |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 324 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 325 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
| 326 | erp = rate->flags & IEEE80211_RATE_ERP_G; |
| 327 | } |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 328 | |
| 329 | /* Data frame duration */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 330 | dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 331 | erp, short_preamble); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 332 | if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) { |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 333 | /* ACK duration */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 334 | dur += ieee80211_frame_duration(local, 10, rate->bitrate, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 335 | erp, short_preamble); |
| 336 | } |
| 337 | |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 338 | return cpu_to_le16(dur); |
| 339 | } |
| 340 | EXPORT_SYMBOL(ieee80211_ctstoself_duration); |
| 341 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 342 | static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue, |
| 343 | enum queue_stop_reason reason) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 344 | { |
| 345 | struct ieee80211_local *local = hw_to_local(hw); |
| 346 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 347 | if (queue >= hw->queues) { |
| 348 | if (local->ampdu_ac_queue[queue - hw->queues] < 0) |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 349 | return; |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 350 | |
| 351 | /* |
| 352 | * for virtual aggregation queues, we need to refcount the |
| 353 | * internal mac80211 disable (multiple times!), keep track of |
| 354 | * driver disable _and_ make sure the regular queue is |
| 355 | * actually enabled. |
| 356 | */ |
| 357 | if (reason == IEEE80211_QUEUE_STOP_REASON_AGGREGATION) |
| 358 | local->amdpu_ac_stop_refcnt[queue - hw->queues]--; |
| 359 | else |
| 360 | __clear_bit(reason, &local->queue_stop_reasons[queue]); |
| 361 | |
| 362 | if (local->queue_stop_reasons[queue] || |
| 363 | local->amdpu_ac_stop_refcnt[queue - hw->queues]) |
| 364 | return; |
| 365 | |
| 366 | /* now go on to treat the corresponding regular queue */ |
| 367 | queue = local->ampdu_ac_queue[queue - hw->queues]; |
| 368 | reason = IEEE80211_QUEUE_STOP_REASON_AGGREGATION; |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 369 | } |
| 370 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 371 | __clear_bit(reason, &local->queue_stop_reasons[queue]); |
| 372 | |
| 373 | if (local->queue_stop_reasons[queue] != 0) |
| 374 | /* someone still has this queue stopped */ |
| 375 | return; |
| 376 | |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 377 | if (test_bit(queue, local->queues_pending)) { |
Tomas Winkler | f8e79dd | 2008-07-24 18:46:44 +0300 | [diff] [blame] | 378 | set_bit(queue, local->queues_pending_run); |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 379 | tasklet_schedule(&local->tx_pending_tasklet); |
| 380 | } else { |
David S. Miller | 51cb6db | 2008-07-15 03:34:57 -0700 | [diff] [blame] | 381 | netif_wake_subqueue(local->mdev, queue); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 382 | } |
| 383 | } |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 384 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 385 | void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue, |
| 386 | enum queue_stop_reason reason) |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 387 | { |
| 388 | struct ieee80211_local *local = hw_to_local(hw); |
| 389 | unsigned long flags; |
| 390 | |
| 391 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 392 | __ieee80211_wake_queue(hw, queue, reason); |
| 393 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 394 | } |
| 395 | |
| 396 | void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue) |
| 397 | { |
| 398 | ieee80211_wake_queue_by_reason(hw, queue, |
| 399 | IEEE80211_QUEUE_STOP_REASON_DRIVER); |
| 400 | } |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 401 | EXPORT_SYMBOL(ieee80211_wake_queue); |
| 402 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 403 | static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue, |
| 404 | enum queue_stop_reason reason) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 405 | { |
| 406 | struct ieee80211_local *local = hw_to_local(hw); |
| 407 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 408 | if (queue >= hw->queues) { |
| 409 | if (local->ampdu_ac_queue[queue - hw->queues] < 0) |
| 410 | return; |
| 411 | |
| 412 | /* |
| 413 | * for virtual aggregation queues, we need to refcount the |
| 414 | * internal mac80211 disable (multiple times!), keep track of |
| 415 | * driver disable _and_ make sure the regular queue is |
| 416 | * actually enabled. |
| 417 | */ |
| 418 | if (reason == IEEE80211_QUEUE_STOP_REASON_AGGREGATION) |
| 419 | local->amdpu_ac_stop_refcnt[queue - hw->queues]++; |
| 420 | else |
| 421 | __set_bit(reason, &local->queue_stop_reasons[queue]); |
| 422 | |
| 423 | /* now go on to treat the corresponding regular queue */ |
| 424 | queue = local->ampdu_ac_queue[queue - hw->queues]; |
| 425 | reason = IEEE80211_QUEUE_STOP_REASON_AGGREGATION; |
| 426 | } |
| 427 | |
| 428 | __set_bit(reason, &local->queue_stop_reasons[queue]); |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 429 | |
David S. Miller | 51cb6db | 2008-07-15 03:34:57 -0700 | [diff] [blame] | 430 | netif_stop_subqueue(local->mdev, queue); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 431 | } |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 432 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 433 | void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue, |
| 434 | enum queue_stop_reason reason) |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 435 | { |
| 436 | struct ieee80211_local *local = hw_to_local(hw); |
| 437 | unsigned long flags; |
| 438 | |
| 439 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 440 | __ieee80211_stop_queue(hw, queue, reason); |
| 441 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 442 | } |
| 443 | |
| 444 | void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue) |
| 445 | { |
| 446 | ieee80211_stop_queue_by_reason(hw, queue, |
| 447 | IEEE80211_QUEUE_STOP_REASON_DRIVER); |
| 448 | } |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 449 | EXPORT_SYMBOL(ieee80211_stop_queue); |
| 450 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 451 | void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw, |
| 452 | enum queue_stop_reason reason) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 453 | { |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 454 | struct ieee80211_local *local = hw_to_local(hw); |
| 455 | unsigned long flags; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 456 | int i; |
| 457 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 458 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 459 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 460 | for (i = 0; i < hw->queues; i++) |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 461 | __ieee80211_stop_queue(hw, i, reason); |
| 462 | |
| 463 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 464 | } |
| 465 | |
| 466 | void ieee80211_stop_queues(struct ieee80211_hw *hw) |
| 467 | { |
| 468 | ieee80211_stop_queues_by_reason(hw, |
| 469 | IEEE80211_QUEUE_STOP_REASON_DRIVER); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 470 | } |
| 471 | EXPORT_SYMBOL(ieee80211_stop_queues); |
| 472 | |
Tomas Winkler | 92ab853 | 2008-07-24 21:02:04 +0300 | [diff] [blame] | 473 | int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue) |
| 474 | { |
| 475 | struct ieee80211_local *local = hw_to_local(hw); |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame^] | 476 | unsigned long flags; |
| 477 | |
| 478 | if (queue >= hw->queues) { |
| 479 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 480 | queue = local->ampdu_ac_queue[queue - hw->queues]; |
| 481 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 482 | if (queue < 0) |
| 483 | return true; |
| 484 | } |
| 485 | |
Tomas Winkler | 92ab853 | 2008-07-24 21:02:04 +0300 | [diff] [blame] | 486 | return __netif_subqueue_stopped(local->mdev, queue); |
| 487 | } |
| 488 | EXPORT_SYMBOL(ieee80211_queue_stopped); |
| 489 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 490 | void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw, |
| 491 | enum queue_stop_reason reason) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 492 | { |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 493 | struct ieee80211_local *local = hw_to_local(hw); |
| 494 | unsigned long flags; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 495 | int i; |
| 496 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 497 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 498 | |
Johannes Berg | c4680470 | 2008-05-15 12:55:25 +0200 | [diff] [blame] | 499 | for (i = 0; i < hw->queues + hw->ampdu_queues; i++) |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 500 | __ieee80211_wake_queue(hw, i, reason); |
| 501 | |
| 502 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 503 | } |
| 504 | |
| 505 | void ieee80211_wake_queues(struct ieee80211_hw *hw) |
| 506 | { |
| 507 | ieee80211_wake_queues_by_reason(hw, IEEE80211_QUEUE_STOP_REASON_DRIVER); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 508 | } |
| 509 | EXPORT_SYMBOL(ieee80211_wake_queues); |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 510 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 511 | void ieee80211_iterate_active_interfaces( |
| 512 | struct ieee80211_hw *hw, |
| 513 | void (*iterator)(void *data, u8 *mac, |
| 514 | struct ieee80211_vif *vif), |
| 515 | void *data) |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 516 | { |
| 517 | struct ieee80211_local *local = hw_to_local(hw); |
| 518 | struct ieee80211_sub_if_data *sdata; |
| 519 | |
Johannes Berg | c771c9d | 2009-01-23 22:54:03 +0100 | [diff] [blame] | 520 | mutex_lock(&local->iflist_mtx); |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 521 | |
| 522 | list_for_each_entry(sdata, &local->interfaces, list) { |
| 523 | switch (sdata->vif.type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 524 | case __NL80211_IFTYPE_AFTER_LAST: |
| 525 | case NL80211_IFTYPE_UNSPECIFIED: |
| 526 | case NL80211_IFTYPE_MONITOR: |
| 527 | case NL80211_IFTYPE_AP_VLAN: |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 528 | continue; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 529 | case NL80211_IFTYPE_AP: |
| 530 | case NL80211_IFTYPE_STATION: |
| 531 | case NL80211_IFTYPE_ADHOC: |
| 532 | case NL80211_IFTYPE_WDS: |
| 533 | case NL80211_IFTYPE_MESH_POINT: |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 534 | break; |
| 535 | } |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 536 | if (netif_running(sdata->dev)) |
| 537 | iterator(data, sdata->dev->dev_addr, |
| 538 | &sdata->vif); |
| 539 | } |
| 540 | |
Johannes Berg | c771c9d | 2009-01-23 22:54:03 +0100 | [diff] [blame] | 541 | mutex_unlock(&local->iflist_mtx); |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 542 | } |
| 543 | EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces); |
| 544 | |
| 545 | void ieee80211_iterate_active_interfaces_atomic( |
| 546 | struct ieee80211_hw *hw, |
| 547 | void (*iterator)(void *data, u8 *mac, |
| 548 | struct ieee80211_vif *vif), |
| 549 | void *data) |
| 550 | { |
| 551 | struct ieee80211_local *local = hw_to_local(hw); |
| 552 | struct ieee80211_sub_if_data *sdata; |
| 553 | |
Johannes Berg | e38bad4 | 2007-11-28 10:55:32 +0100 | [diff] [blame] | 554 | rcu_read_lock(); |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 555 | |
Johannes Berg | e38bad4 | 2007-11-28 10:55:32 +0100 | [diff] [blame] | 556 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 557 | switch (sdata->vif.type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 558 | case __NL80211_IFTYPE_AFTER_LAST: |
| 559 | case NL80211_IFTYPE_UNSPECIFIED: |
| 560 | case NL80211_IFTYPE_MONITOR: |
| 561 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 562 | continue; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 563 | case NL80211_IFTYPE_AP: |
| 564 | case NL80211_IFTYPE_STATION: |
| 565 | case NL80211_IFTYPE_ADHOC: |
| 566 | case NL80211_IFTYPE_WDS: |
| 567 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 568 | break; |
| 569 | } |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 570 | if (netif_running(sdata->dev)) |
| 571 | iterator(data, sdata->dev->dev_addr, |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 572 | &sdata->vif); |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 573 | } |
Johannes Berg | e38bad4 | 2007-11-28 10:55:32 +0100 | [diff] [blame] | 574 | |
| 575 | rcu_read_unlock(); |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 576 | } |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 577 | EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic); |
Johannes Berg | 37ffc8d | 2008-09-08 16:40:36 +0200 | [diff] [blame] | 578 | |
| 579 | void ieee802_11_parse_elems(u8 *start, size_t len, |
| 580 | struct ieee802_11_elems *elems) |
| 581 | { |
| 582 | size_t left = len; |
| 583 | u8 *pos = start; |
| 584 | |
| 585 | memset(elems, 0, sizeof(*elems)); |
| 586 | elems->ie_start = start; |
| 587 | elems->total_len = len; |
| 588 | |
| 589 | while (left >= 2) { |
| 590 | u8 id, elen; |
| 591 | |
| 592 | id = *pos++; |
| 593 | elen = *pos++; |
| 594 | left -= 2; |
| 595 | |
| 596 | if (elen > left) |
| 597 | return; |
| 598 | |
| 599 | switch (id) { |
| 600 | case WLAN_EID_SSID: |
| 601 | elems->ssid = pos; |
| 602 | elems->ssid_len = elen; |
| 603 | break; |
| 604 | case WLAN_EID_SUPP_RATES: |
| 605 | elems->supp_rates = pos; |
| 606 | elems->supp_rates_len = elen; |
| 607 | break; |
| 608 | case WLAN_EID_FH_PARAMS: |
| 609 | elems->fh_params = pos; |
| 610 | elems->fh_params_len = elen; |
| 611 | break; |
| 612 | case WLAN_EID_DS_PARAMS: |
| 613 | elems->ds_params = pos; |
| 614 | elems->ds_params_len = elen; |
| 615 | break; |
| 616 | case WLAN_EID_CF_PARAMS: |
| 617 | elems->cf_params = pos; |
| 618 | elems->cf_params_len = elen; |
| 619 | break; |
| 620 | case WLAN_EID_TIM: |
| 621 | elems->tim = pos; |
| 622 | elems->tim_len = elen; |
| 623 | break; |
| 624 | case WLAN_EID_IBSS_PARAMS: |
| 625 | elems->ibss_params = pos; |
| 626 | elems->ibss_params_len = elen; |
| 627 | break; |
| 628 | case WLAN_EID_CHALLENGE: |
| 629 | elems->challenge = pos; |
| 630 | elems->challenge_len = elen; |
| 631 | break; |
| 632 | case WLAN_EID_WPA: |
| 633 | if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 && |
| 634 | pos[2] == 0xf2) { |
| 635 | /* Microsoft OUI (00:50:F2) */ |
| 636 | if (pos[3] == 1) { |
| 637 | /* OUI Type 1 - WPA IE */ |
| 638 | elems->wpa = pos; |
| 639 | elems->wpa_len = elen; |
| 640 | } else if (elen >= 5 && pos[3] == 2) { |
| 641 | if (pos[4] == 0) { |
| 642 | elems->wmm_info = pos; |
| 643 | elems->wmm_info_len = elen; |
| 644 | } else if (pos[4] == 1) { |
| 645 | elems->wmm_param = pos; |
| 646 | elems->wmm_param_len = elen; |
| 647 | } |
| 648 | } |
| 649 | } |
| 650 | break; |
| 651 | case WLAN_EID_RSN: |
| 652 | elems->rsn = pos; |
| 653 | elems->rsn_len = elen; |
| 654 | break; |
| 655 | case WLAN_EID_ERP_INFO: |
| 656 | elems->erp_info = pos; |
| 657 | elems->erp_info_len = elen; |
| 658 | break; |
| 659 | case WLAN_EID_EXT_SUPP_RATES: |
| 660 | elems->ext_supp_rates = pos; |
| 661 | elems->ext_supp_rates_len = elen; |
| 662 | break; |
| 663 | case WLAN_EID_HT_CAPABILITY: |
Johannes Berg | 0991481 | 2008-10-07 19:31:17 +0200 | [diff] [blame] | 664 | if (elen >= sizeof(struct ieee80211_ht_cap)) |
| 665 | elems->ht_cap_elem = (void *)pos; |
Johannes Berg | 37ffc8d | 2008-09-08 16:40:36 +0200 | [diff] [blame] | 666 | break; |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 667 | case WLAN_EID_HT_INFORMATION: |
| 668 | if (elen >= sizeof(struct ieee80211_ht_info)) |
Johannes Berg | 0991481 | 2008-10-07 19:31:17 +0200 | [diff] [blame] | 669 | elems->ht_info_elem = (void *)pos; |
Johannes Berg | 37ffc8d | 2008-09-08 16:40:36 +0200 | [diff] [blame] | 670 | break; |
| 671 | case WLAN_EID_MESH_ID: |
| 672 | elems->mesh_id = pos; |
| 673 | elems->mesh_id_len = elen; |
| 674 | break; |
| 675 | case WLAN_EID_MESH_CONFIG: |
| 676 | elems->mesh_config = pos; |
| 677 | elems->mesh_config_len = elen; |
| 678 | break; |
| 679 | case WLAN_EID_PEER_LINK: |
| 680 | elems->peer_link = pos; |
| 681 | elems->peer_link_len = elen; |
| 682 | break; |
| 683 | case WLAN_EID_PREQ: |
| 684 | elems->preq = pos; |
| 685 | elems->preq_len = elen; |
| 686 | break; |
| 687 | case WLAN_EID_PREP: |
| 688 | elems->prep = pos; |
| 689 | elems->prep_len = elen; |
| 690 | break; |
| 691 | case WLAN_EID_PERR: |
| 692 | elems->perr = pos; |
| 693 | elems->perr_len = elen; |
| 694 | break; |
| 695 | case WLAN_EID_CHANNEL_SWITCH: |
| 696 | elems->ch_switch_elem = pos; |
| 697 | elems->ch_switch_elem_len = elen; |
| 698 | break; |
| 699 | case WLAN_EID_QUIET: |
| 700 | if (!elems->quiet_elem) { |
| 701 | elems->quiet_elem = pos; |
| 702 | elems->quiet_elem_len = elen; |
| 703 | } |
| 704 | elems->num_of_quiet_elem++; |
| 705 | break; |
| 706 | case WLAN_EID_COUNTRY: |
| 707 | elems->country_elem = pos; |
| 708 | elems->country_elem_len = elen; |
| 709 | break; |
| 710 | case WLAN_EID_PWR_CONSTRAINT: |
| 711 | elems->pwr_constr_elem = pos; |
| 712 | elems->pwr_constr_elem_len = elen; |
| 713 | break; |
Jouni Malinen | f797eb7 | 2009-01-19 18:48:46 +0200 | [diff] [blame] | 714 | case WLAN_EID_TIMEOUT_INTERVAL: |
| 715 | elems->timeout_int = pos; |
| 716 | elems->timeout_int_len = elen; |
Jouni Malinen | 63a5ab8 | 2009-01-08 13:32:09 +0200 | [diff] [blame] | 717 | break; |
Johannes Berg | 37ffc8d | 2008-09-08 16:40:36 +0200 | [diff] [blame] | 718 | default: |
| 719 | break; |
| 720 | } |
| 721 | |
| 722 | left -= elen; |
| 723 | pos += elen; |
| 724 | } |
| 725 | } |
Johannes Berg | 5825fe10 | 2008-09-09 12:56:01 +0200 | [diff] [blame] | 726 | |
| 727 | void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata) |
| 728 | { |
| 729 | struct ieee80211_local *local = sdata->local; |
| 730 | struct ieee80211_tx_queue_params qparam; |
| 731 | int i; |
| 732 | |
| 733 | if (!local->ops->conf_tx) |
| 734 | return; |
| 735 | |
| 736 | memset(&qparam, 0, sizeof(qparam)); |
| 737 | |
| 738 | qparam.aifs = 2; |
| 739 | |
| 740 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && |
| 741 | !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)) |
| 742 | qparam.cw_min = 31; |
| 743 | else |
| 744 | qparam.cw_min = 15; |
| 745 | |
| 746 | qparam.cw_max = 1023; |
| 747 | qparam.txop = 0; |
| 748 | |
| 749 | for (i = 0; i < local_to_hw(local)->queues; i++) |
| 750 | local->ops->conf_tx(local_to_hw(local), i, &qparam); |
| 751 | } |
Johannes Berg | e50db65 | 2008-09-09 15:07:09 +0200 | [diff] [blame] | 752 | |
| 753 | void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, |
| 754 | int encrypt) |
| 755 | { |
| 756 | skb->dev = sdata->local->mdev; |
| 757 | skb_set_mac_header(skb, 0); |
| 758 | skb_set_network_header(skb, 0); |
| 759 | skb_set_transport_header(skb, 0); |
| 760 | |
| 761 | skb->iif = sdata->dev->ifindex; |
| 762 | skb->do_not_encrypt = !encrypt; |
| 763 | |
| 764 | dev_queue_xmit(skb); |
| 765 | } |
Johannes Berg | e16751c | 2008-09-11 00:01:53 +0200 | [diff] [blame] | 766 | |
| 767 | int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freqMHz) |
| 768 | { |
| 769 | int ret = -EINVAL; |
| 770 | struct ieee80211_channel *chan; |
| 771 | struct ieee80211_local *local = sdata->local; |
| 772 | |
| 773 | chan = ieee80211_get_channel(local->hw.wiphy, freqMHz); |
| 774 | |
| 775 | if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 776 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC && |
Johannes Berg | d73782f | 2008-10-07 12:04:34 +0200 | [diff] [blame] | 777 | chan->flags & IEEE80211_CHAN_NO_IBSS) |
Johannes Berg | e16751c | 2008-09-11 00:01:53 +0200 | [diff] [blame] | 778 | return ret; |
Johannes Berg | e16751c | 2008-09-11 00:01:53 +0200 | [diff] [blame] | 779 | local->oper_channel = chan; |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 780 | local->oper_channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | e16751c | 2008-09-11 00:01:53 +0200 | [diff] [blame] | 781 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 782 | if (local->sw_scanning || local->hw_scanning) |
Johannes Berg | e16751c | 2008-09-11 00:01:53 +0200 | [diff] [blame] | 783 | ret = 0; |
| 784 | else |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 785 | ret = ieee80211_hw_config( |
| 786 | local, IEEE80211_CONF_CHANGE_CHANNEL); |
Johannes Berg | e16751c | 2008-09-11 00:01:53 +0200 | [diff] [blame] | 787 | } |
| 788 | |
| 789 | return ret; |
| 790 | } |
Johannes Berg | 96dd22a | 2008-09-11 00:01:57 +0200 | [diff] [blame] | 791 | |
Johannes Berg | 881d948 | 2009-01-21 15:13:48 +0100 | [diff] [blame] | 792 | u32 ieee80211_mandatory_rates(struct ieee80211_local *local, |
Johannes Berg | 96dd22a | 2008-09-11 00:01:57 +0200 | [diff] [blame] | 793 | enum ieee80211_band band) |
| 794 | { |
| 795 | struct ieee80211_supported_band *sband; |
| 796 | struct ieee80211_rate *bitrates; |
Johannes Berg | 881d948 | 2009-01-21 15:13:48 +0100 | [diff] [blame] | 797 | u32 mandatory_rates; |
Johannes Berg | 96dd22a | 2008-09-11 00:01:57 +0200 | [diff] [blame] | 798 | enum ieee80211_rate_flags mandatory_flag; |
| 799 | int i; |
| 800 | |
| 801 | sband = local->hw.wiphy->bands[band]; |
| 802 | if (!sband) { |
| 803 | WARN_ON(1); |
| 804 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 805 | } |
| 806 | |
| 807 | if (band == IEEE80211_BAND_2GHZ) |
| 808 | mandatory_flag = IEEE80211_RATE_MANDATORY_B; |
| 809 | else |
| 810 | mandatory_flag = IEEE80211_RATE_MANDATORY_A; |
| 811 | |
| 812 | bitrates = sband->bitrates; |
| 813 | mandatory_rates = 0; |
| 814 | for (i = 0; i < sband->n_bitrates; i++) |
| 815 | if (bitrates[i].flags & mandatory_flag) |
| 816 | mandatory_rates |= BIT(i); |
| 817 | return mandatory_rates; |
| 818 | } |