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" |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame^] | 31 | #include "led.h" |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 32 | |
| 33 | /* privid for wiphys to determine whether they belong to us or not */ |
| 34 | void *mac80211_wiphy_privid = &mac80211_wiphy_privid; |
| 35 | |
| 36 | /* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */ |
| 37 | /* Ethernet-II snap header (RFC1042 for most EtherTypes) */ |
Senthil Balasubramanian | c97c23e | 2008-05-28 23:15:32 +0530 | [diff] [blame] | 38 | const unsigned char rfc1042_header[] __aligned(2) = |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 39 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 40 | |
| 41 | /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */ |
Senthil Balasubramanian | c97c23e | 2008-05-28 23:15:32 +0530 | [diff] [blame] | 42 | const unsigned char bridge_tunnel_header[] __aligned(2) = |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 43 | { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; |
| 44 | |
Luis R. Rodriguez | 9a95371 | 2009-01-22 15:05:53 -0800 | [diff] [blame] | 45 | struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy) |
| 46 | { |
| 47 | struct ieee80211_local *local; |
| 48 | BUG_ON(!wiphy); |
| 49 | |
| 50 | local = wiphy_priv(wiphy); |
| 51 | return &local->hw; |
| 52 | } |
| 53 | EXPORT_SYMBOL(wiphy_to_ieee80211_hw); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 54 | |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 55 | u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len, |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 56 | enum nl80211_iftype type) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 57 | { |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 58 | __le16 fc = hdr->frame_control; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 59 | |
Ron Rindjunsky | 98f0b0a | 2007-12-18 17:23:53 +0200 | [diff] [blame] | 60 | /* drop ACK/CTS frames and incorrect hdr len (ctrl) */ |
| 61 | if (len < 16) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 62 | return NULL; |
| 63 | |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 64 | if (ieee80211_is_data(fc)) { |
Ron Rindjunsky | 98f0b0a | 2007-12-18 17:23:53 +0200 | [diff] [blame] | 65 | if (len < 24) /* drop incorrect hdr len (data) */ |
| 66 | return NULL; |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 67 | |
| 68 | if (ieee80211_has_a4(fc)) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 69 | return NULL; |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 70 | if (ieee80211_has_tods(fc)) |
| 71 | return hdr->addr1; |
| 72 | if (ieee80211_has_fromds(fc)) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 73 | return hdr->addr2; |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 74 | |
| 75 | return hdr->addr3; |
| 76 | } |
| 77 | |
| 78 | if (ieee80211_is_mgmt(fc)) { |
Ron Rindjunsky | 98f0b0a | 2007-12-18 17:23:53 +0200 | [diff] [blame] | 79 | if (len < 24) /* drop incorrect hdr len (mgmt) */ |
| 80 | return NULL; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 81 | return hdr->addr3; |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | if (ieee80211_is_ctl(fc)) { |
| 85 | if(ieee80211_is_pspoll(fc)) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 86 | return hdr->addr1; |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 87 | |
| 88 | if (ieee80211_is_back_req(fc)) { |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 89 | switch (type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 90 | case NL80211_IFTYPE_STATION: |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 91 | return hdr->addr2; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 92 | case NL80211_IFTYPE_AP: |
| 93 | case NL80211_IFTYPE_AP_VLAN: |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 94 | return hdr->addr1; |
| 95 | default: |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 96 | break; /* fall through to the return */ |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 97 | } |
| 98 | } |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | return NULL; |
| 102 | } |
| 103 | |
Harvey Harrison | 6693be7 | 2008-06-11 14:21:57 -0700 | [diff] [blame] | 104 | unsigned int ieee80211_hdrlen(__le16 fc) |
| 105 | { |
| 106 | unsigned int hdrlen = 24; |
| 107 | |
| 108 | if (ieee80211_is_data(fc)) { |
| 109 | if (ieee80211_has_a4(fc)) |
| 110 | hdrlen = 30; |
| 111 | if (ieee80211_is_data_qos(fc)) |
| 112 | hdrlen += IEEE80211_QOS_CTL_LEN; |
| 113 | goto out; |
| 114 | } |
| 115 | |
| 116 | if (ieee80211_is_ctl(fc)) { |
| 117 | /* |
| 118 | * ACK and CTS are 10 bytes, all others 16. To see how |
| 119 | * to get this condition consider |
| 120 | * subtype mask: 0b0000000011110000 (0x00F0) |
| 121 | * ACK subtype: 0b0000000011010000 (0x00D0) |
| 122 | * CTS subtype: 0b0000000011000000 (0x00C0) |
| 123 | * bits that matter: ^^^ (0x00E0) |
| 124 | * value of those: 0b0000000011000000 (0x00C0) |
| 125 | */ |
| 126 | if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0)) |
| 127 | hdrlen = 10; |
| 128 | else |
| 129 | hdrlen = 16; |
| 130 | } |
| 131 | out: |
| 132 | return hdrlen; |
| 133 | } |
| 134 | EXPORT_SYMBOL(ieee80211_hdrlen); |
| 135 | |
Harvey Harrison | c9c6950 | 2008-06-11 14:21:57 -0700 | [diff] [blame] | 136 | unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 137 | { |
Harvey Harrison | c9c6950 | 2008-06-11 14:21:57 -0700 | [diff] [blame] | 138 | const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *)skb->data; |
| 139 | unsigned int hdrlen; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 140 | |
| 141 | if (unlikely(skb->len < 10)) |
| 142 | return 0; |
Harvey Harrison | c9c6950 | 2008-06-11 14:21:57 -0700 | [diff] [blame] | 143 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 144 | if (unlikely(hdrlen > skb->len)) |
| 145 | return 0; |
| 146 | return hdrlen; |
| 147 | } |
| 148 | EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb); |
| 149 | |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 150 | int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr) |
| 151 | { |
| 152 | int ae = meshhdr->flags & IEEE80211S_FLAGS_AE; |
| 153 | /* 7.1.3.5a.2 */ |
| 154 | switch (ae) { |
| 155 | case 0: |
Luis Carlos Cobo | ef26925 | 2008-05-05 12:02:35 -0700 | [diff] [blame] | 156 | return 6; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 157 | case 1: |
Luis Carlos Cobo | ef26925 | 2008-05-05 12:02:35 -0700 | [diff] [blame] | 158 | return 12; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 159 | case 2: |
Luis Carlos Cobo | ef26925 | 2008-05-05 12:02:35 -0700 | [diff] [blame] | 160 | return 18; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 161 | case 3: |
Luis Carlos Cobo | ef26925 | 2008-05-05 12:02:35 -0700 | [diff] [blame] | 162 | return 24; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 163 | default: |
Luis Carlos Cobo | ef26925 | 2008-05-05 12:02:35 -0700 | [diff] [blame] | 164 | return 6; |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 165 | } |
| 166 | } |
Luis Carlos Cobo | ee38585 | 2008-02-23 15:17:11 +0100 | [diff] [blame] | 167 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 168 | void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 169 | { |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 170 | struct sk_buff *skb = tx->skb; |
| 171 | struct ieee80211_hdr *hdr; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 172 | |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 173 | do { |
| 174 | hdr = (struct ieee80211_hdr *) skb->data; |
| 175 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
| 176 | } while ((skb = skb->next)); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | int ieee80211_frame_duration(struct ieee80211_local *local, size_t len, |
| 180 | int rate, int erp, int short_preamble) |
| 181 | { |
| 182 | int dur; |
| 183 | |
| 184 | /* calculate duration (in microseconds, rounded up to next higher |
| 185 | * integer if it includes a fractional microsecond) to send frame of |
| 186 | * len bytes (does not include FCS) at the given rate. Duration will |
| 187 | * also include SIFS. |
| 188 | * |
| 189 | * rate is in 100 kbps, so divident is multiplied by 10 in the |
| 190 | * DIV_ROUND_UP() operations. |
| 191 | */ |
| 192 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 193 | if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ || erp) { |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 194 | /* |
| 195 | * OFDM: |
| 196 | * |
| 197 | * N_DBPS = DATARATE x 4 |
| 198 | * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS) |
| 199 | * (16 = SIGNAL time, 6 = tail bits) |
| 200 | * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext |
| 201 | * |
| 202 | * T_SYM = 4 usec |
| 203 | * 802.11a - 17.5.2: aSIFSTime = 16 usec |
| 204 | * 802.11g - 19.8.4: aSIFSTime = 10 usec + |
| 205 | * signal ext = 6 usec |
| 206 | */ |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 207 | dur = 16; /* SIFS + signal ext */ |
| 208 | dur += 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */ |
| 209 | dur += 4; /* 17.3.2.3: T_SIGNAL = 4 usec */ |
| 210 | dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10, |
| 211 | 4 * rate); /* T_SYM x N_SYM */ |
| 212 | } else { |
| 213 | /* |
| 214 | * 802.11b or 802.11g with 802.11b compatibility: |
| 215 | * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime + |
| 216 | * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0. |
| 217 | * |
| 218 | * 802.11 (DS): 15.3.3, 802.11b: 18.3.4 |
| 219 | * aSIFSTime = 10 usec |
| 220 | * aPreambleLength = 144 usec or 72 usec with short preamble |
| 221 | * aPLCPHeaderLength = 48 usec or 24 usec with short preamble |
| 222 | */ |
| 223 | dur = 10; /* aSIFSTime = 10 usec */ |
| 224 | dur += short_preamble ? (72 + 24) : (144 + 48); |
| 225 | |
| 226 | dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate); |
| 227 | } |
| 228 | |
| 229 | return dur; |
| 230 | } |
| 231 | |
| 232 | /* Exported duration function for driver use */ |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 233 | __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw, |
| 234 | struct ieee80211_vif *vif, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 235 | size_t frame_len, |
| 236 | struct ieee80211_rate *rate) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 237 | { |
| 238 | struct ieee80211_local *local = hw_to_local(hw); |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 239 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 240 | u16 dur; |
| 241 | int erp; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 242 | bool short_preamble = false; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 243 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 244 | erp = 0; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 245 | if (vif) { |
| 246 | sdata = vif_to_sdata(vif); |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 247 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 248 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
| 249 | erp = rate->flags & IEEE80211_RATE_ERP_G; |
| 250 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 251 | |
| 252 | dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, erp, |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 253 | short_preamble); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 254 | |
| 255 | return cpu_to_le16(dur); |
| 256 | } |
| 257 | EXPORT_SYMBOL(ieee80211_generic_frame_duration); |
| 258 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 259 | __le16 ieee80211_rts_duration(struct ieee80211_hw *hw, |
| 260 | struct ieee80211_vif *vif, size_t frame_len, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 261 | const struct ieee80211_tx_info *frame_txctl) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 262 | { |
| 263 | struct ieee80211_local *local = hw_to_local(hw); |
| 264 | struct ieee80211_rate *rate; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 265 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 266 | bool short_preamble; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 267 | int erp; |
| 268 | u16 dur; |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 269 | struct ieee80211_supported_band *sband; |
| 270 | |
| 271 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 272 | |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 273 | short_preamble = false; |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 274 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 275 | rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 276 | |
| 277 | erp = 0; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 278 | if (vif) { |
| 279 | sdata = vif_to_sdata(vif); |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 280 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 281 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
| 282 | erp = rate->flags & IEEE80211_RATE_ERP_G; |
| 283 | } |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 284 | |
| 285 | /* CTS duration */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 286 | dur = ieee80211_frame_duration(local, 10, rate->bitrate, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 287 | erp, short_preamble); |
| 288 | /* Data frame duration */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 289 | dur += ieee80211_frame_duration(local, frame_len, rate->bitrate, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 290 | erp, short_preamble); |
| 291 | /* ACK duration */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 292 | dur += ieee80211_frame_duration(local, 10, rate->bitrate, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 293 | erp, short_preamble); |
| 294 | |
| 295 | return cpu_to_le16(dur); |
| 296 | } |
| 297 | EXPORT_SYMBOL(ieee80211_rts_duration); |
| 298 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 299 | __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw, |
| 300 | struct ieee80211_vif *vif, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 301 | size_t frame_len, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 302 | const struct ieee80211_tx_info *frame_txctl) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 303 | { |
| 304 | struct ieee80211_local *local = hw_to_local(hw); |
| 305 | struct ieee80211_rate *rate; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 306 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 307 | bool short_preamble; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 308 | int erp; |
| 309 | u16 dur; |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 310 | struct ieee80211_supported_band *sband; |
| 311 | |
| 312 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 313 | |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 314 | short_preamble = false; |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 315 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 316 | rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 317 | erp = 0; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 318 | if (vif) { |
| 319 | sdata = vif_to_sdata(vif); |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 320 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 321 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
| 322 | erp = rate->flags & IEEE80211_RATE_ERP_G; |
| 323 | } |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 324 | |
| 325 | /* Data frame duration */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 326 | dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 327 | erp, short_preamble); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 328 | if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) { |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 329 | /* ACK duration */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 330 | dur += ieee80211_frame_duration(local, 10, rate->bitrate, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 331 | erp, short_preamble); |
| 332 | } |
| 333 | |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 334 | return cpu_to_le16(dur); |
| 335 | } |
| 336 | EXPORT_SYMBOL(ieee80211_ctstoself_duration); |
| 337 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 338 | static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue, |
| 339 | enum queue_stop_reason reason) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 340 | { |
| 341 | struct ieee80211_local *local = hw_to_local(hw); |
| 342 | |
Johannes Berg | e4e72fb | 2009-03-23 17:28:42 +0100 | [diff] [blame] | 343 | if (WARN_ON(queue >= hw->queues)) |
| 344 | return; |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 345 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame] | 346 | __clear_bit(reason, &local->queue_stop_reasons[queue]); |
| 347 | |
Johannes Berg | 2a577d9 | 2009-03-23 17:28:37 +0100 | [diff] [blame] | 348 | if (!skb_queue_empty(&local->pending[queue]) && |
| 349 | local->queue_stop_reasons[queue] == |
| 350 | BIT(IEEE80211_QUEUE_STOP_REASON_PENDING)) |
| 351 | tasklet_schedule(&local->tx_pending_tasklet); |
| 352 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame] | 353 | if (local->queue_stop_reasons[queue] != 0) |
| 354 | /* someone still has this queue stopped */ |
| 355 | return; |
| 356 | |
Johannes Berg | 2a577d9 | 2009-03-23 17:28:37 +0100 | [diff] [blame] | 357 | netif_wake_subqueue(local->mdev, queue); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 358 | } |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 359 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame] | 360 | void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue, |
| 361 | enum queue_stop_reason reason) |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 362 | { |
| 363 | struct ieee80211_local *local = hw_to_local(hw); |
| 364 | unsigned long flags; |
| 365 | |
| 366 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 367 | __ieee80211_wake_queue(hw, queue, reason); |
| 368 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 369 | } |
| 370 | |
| 371 | void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue) |
| 372 | { |
| 373 | ieee80211_wake_queue_by_reason(hw, queue, |
| 374 | IEEE80211_QUEUE_STOP_REASON_DRIVER); |
| 375 | } |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 376 | EXPORT_SYMBOL(ieee80211_wake_queue); |
| 377 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 378 | static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue, |
| 379 | enum queue_stop_reason reason) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 380 | { |
| 381 | struct ieee80211_local *local = hw_to_local(hw); |
| 382 | |
Johannes Berg | e4e72fb | 2009-03-23 17:28:42 +0100 | [diff] [blame] | 383 | if (WARN_ON(queue >= hw->queues)) |
| 384 | return; |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame] | 385 | |
Johannes Berg | 2a577d9 | 2009-03-23 17:28:37 +0100 | [diff] [blame] | 386 | /* |
| 387 | * Only stop if it was previously running, this is necessary |
| 388 | * for correct pending packets handling because there we may |
| 389 | * start (but not wake) the queue and rely on that. |
| 390 | */ |
| 391 | if (!local->queue_stop_reasons[queue]) |
| 392 | netif_stop_subqueue(local->mdev, queue); |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 393 | |
Johannes Berg | 2a577d9 | 2009-03-23 17:28:37 +0100 | [diff] [blame] | 394 | __set_bit(reason, &local->queue_stop_reasons[queue]); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 395 | } |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 396 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame] | 397 | void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue, |
| 398 | enum queue_stop_reason reason) |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 399 | { |
| 400 | struct ieee80211_local *local = hw_to_local(hw); |
| 401 | unsigned long flags; |
| 402 | |
| 403 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 404 | __ieee80211_stop_queue(hw, queue, reason); |
| 405 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 406 | } |
| 407 | |
| 408 | void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue) |
| 409 | { |
| 410 | ieee80211_stop_queue_by_reason(hw, queue, |
| 411 | IEEE80211_QUEUE_STOP_REASON_DRIVER); |
| 412 | } |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 413 | EXPORT_SYMBOL(ieee80211_stop_queue); |
| 414 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 415 | void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw, |
| 416 | enum queue_stop_reason reason) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 417 | { |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 418 | struct ieee80211_local *local = hw_to_local(hw); |
| 419 | unsigned long flags; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 420 | int i; |
| 421 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 422 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 423 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame] | 424 | for (i = 0; i < hw->queues; i++) |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 425 | __ieee80211_stop_queue(hw, i, reason); |
| 426 | |
| 427 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 428 | } |
| 429 | |
| 430 | void ieee80211_stop_queues(struct ieee80211_hw *hw) |
| 431 | { |
| 432 | ieee80211_stop_queues_by_reason(hw, |
| 433 | IEEE80211_QUEUE_STOP_REASON_DRIVER); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 434 | } |
| 435 | EXPORT_SYMBOL(ieee80211_stop_queues); |
| 436 | |
Tomas Winkler | 92ab853 | 2008-07-24 21:02:04 +0300 | [diff] [blame] | 437 | int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue) |
| 438 | { |
| 439 | struct ieee80211_local *local = hw_to_local(hw); |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame] | 440 | |
Johannes Berg | e4e72fb | 2009-03-23 17:28:42 +0100 | [diff] [blame] | 441 | if (WARN_ON(queue >= hw->queues)) |
| 442 | return true; |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame] | 443 | |
Tomas Winkler | 92ab853 | 2008-07-24 21:02:04 +0300 | [diff] [blame] | 444 | return __netif_subqueue_stopped(local->mdev, queue); |
| 445 | } |
| 446 | EXPORT_SYMBOL(ieee80211_queue_stopped); |
| 447 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 448 | void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw, |
| 449 | enum queue_stop_reason reason) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 450 | { |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 451 | struct ieee80211_local *local = hw_to_local(hw); |
| 452 | unsigned long flags; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 453 | int i; |
| 454 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 455 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 456 | |
Johannes Berg | e4e72fb | 2009-03-23 17:28:42 +0100 | [diff] [blame] | 457 | for (i = 0; i < hw->queues; i++) |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 458 | __ieee80211_wake_queue(hw, i, reason); |
| 459 | |
| 460 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 461 | } |
| 462 | |
| 463 | void ieee80211_wake_queues(struct ieee80211_hw *hw) |
| 464 | { |
| 465 | ieee80211_wake_queues_by_reason(hw, IEEE80211_QUEUE_STOP_REASON_DRIVER); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 466 | } |
| 467 | EXPORT_SYMBOL(ieee80211_wake_queues); |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 468 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 469 | void ieee80211_iterate_active_interfaces( |
| 470 | struct ieee80211_hw *hw, |
| 471 | void (*iterator)(void *data, u8 *mac, |
| 472 | struct ieee80211_vif *vif), |
| 473 | void *data) |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 474 | { |
| 475 | struct ieee80211_local *local = hw_to_local(hw); |
| 476 | struct ieee80211_sub_if_data *sdata; |
| 477 | |
Johannes Berg | c771c9d | 2009-01-23 22:54:03 +0100 | [diff] [blame] | 478 | mutex_lock(&local->iflist_mtx); |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 479 | |
| 480 | list_for_each_entry(sdata, &local->interfaces, list) { |
| 481 | switch (sdata->vif.type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 482 | case __NL80211_IFTYPE_AFTER_LAST: |
| 483 | case NL80211_IFTYPE_UNSPECIFIED: |
| 484 | case NL80211_IFTYPE_MONITOR: |
| 485 | case NL80211_IFTYPE_AP_VLAN: |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 486 | continue; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 487 | case NL80211_IFTYPE_AP: |
| 488 | case NL80211_IFTYPE_STATION: |
| 489 | case NL80211_IFTYPE_ADHOC: |
| 490 | case NL80211_IFTYPE_WDS: |
| 491 | case NL80211_IFTYPE_MESH_POINT: |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 492 | break; |
| 493 | } |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 494 | if (netif_running(sdata->dev)) |
| 495 | iterator(data, sdata->dev->dev_addr, |
| 496 | &sdata->vif); |
| 497 | } |
| 498 | |
Johannes Berg | c771c9d | 2009-01-23 22:54:03 +0100 | [diff] [blame] | 499 | mutex_unlock(&local->iflist_mtx); |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 500 | } |
| 501 | EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces); |
| 502 | |
| 503 | void ieee80211_iterate_active_interfaces_atomic( |
| 504 | struct ieee80211_hw *hw, |
| 505 | void (*iterator)(void *data, u8 *mac, |
| 506 | struct ieee80211_vif *vif), |
| 507 | void *data) |
| 508 | { |
| 509 | struct ieee80211_local *local = hw_to_local(hw); |
| 510 | struct ieee80211_sub_if_data *sdata; |
| 511 | |
Johannes Berg | e38bad4 | 2007-11-28 10:55:32 +0100 | [diff] [blame] | 512 | rcu_read_lock(); |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 513 | |
Johannes Berg | e38bad4 | 2007-11-28 10:55:32 +0100 | [diff] [blame] | 514 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 515 | switch (sdata->vif.type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 516 | case __NL80211_IFTYPE_AFTER_LAST: |
| 517 | case NL80211_IFTYPE_UNSPECIFIED: |
| 518 | case NL80211_IFTYPE_MONITOR: |
| 519 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 520 | continue; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 521 | case NL80211_IFTYPE_AP: |
| 522 | case NL80211_IFTYPE_STATION: |
| 523 | case NL80211_IFTYPE_ADHOC: |
| 524 | case NL80211_IFTYPE_WDS: |
| 525 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 526 | break; |
| 527 | } |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 528 | if (netif_running(sdata->dev)) |
| 529 | iterator(data, sdata->dev->dev_addr, |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 530 | &sdata->vif); |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 531 | } |
Johannes Berg | e38bad4 | 2007-11-28 10:55:32 +0100 | [diff] [blame] | 532 | |
| 533 | rcu_read_unlock(); |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 534 | } |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 535 | EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic); |
Johannes Berg | 37ffc8d | 2008-09-08 16:40:36 +0200 | [diff] [blame] | 536 | |
| 537 | void ieee802_11_parse_elems(u8 *start, size_t len, |
| 538 | struct ieee802_11_elems *elems) |
| 539 | { |
| 540 | size_t left = len; |
| 541 | u8 *pos = start; |
| 542 | |
| 543 | memset(elems, 0, sizeof(*elems)); |
| 544 | elems->ie_start = start; |
| 545 | elems->total_len = len; |
| 546 | |
| 547 | while (left >= 2) { |
| 548 | u8 id, elen; |
| 549 | |
| 550 | id = *pos++; |
| 551 | elen = *pos++; |
| 552 | left -= 2; |
| 553 | |
| 554 | if (elen > left) |
| 555 | return; |
| 556 | |
| 557 | switch (id) { |
| 558 | case WLAN_EID_SSID: |
| 559 | elems->ssid = pos; |
| 560 | elems->ssid_len = elen; |
| 561 | break; |
| 562 | case WLAN_EID_SUPP_RATES: |
| 563 | elems->supp_rates = pos; |
| 564 | elems->supp_rates_len = elen; |
| 565 | break; |
| 566 | case WLAN_EID_FH_PARAMS: |
| 567 | elems->fh_params = pos; |
| 568 | elems->fh_params_len = elen; |
| 569 | break; |
| 570 | case WLAN_EID_DS_PARAMS: |
| 571 | elems->ds_params = pos; |
| 572 | elems->ds_params_len = elen; |
| 573 | break; |
| 574 | case WLAN_EID_CF_PARAMS: |
| 575 | elems->cf_params = pos; |
| 576 | elems->cf_params_len = elen; |
| 577 | break; |
| 578 | case WLAN_EID_TIM: |
| 579 | elems->tim = pos; |
| 580 | elems->tim_len = elen; |
| 581 | break; |
| 582 | case WLAN_EID_IBSS_PARAMS: |
| 583 | elems->ibss_params = pos; |
| 584 | elems->ibss_params_len = elen; |
| 585 | break; |
| 586 | case WLAN_EID_CHALLENGE: |
| 587 | elems->challenge = pos; |
| 588 | elems->challenge_len = elen; |
| 589 | break; |
| 590 | case WLAN_EID_WPA: |
| 591 | if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 && |
| 592 | pos[2] == 0xf2) { |
| 593 | /* Microsoft OUI (00:50:F2) */ |
| 594 | if (pos[3] == 1) { |
| 595 | /* OUI Type 1 - WPA IE */ |
| 596 | elems->wpa = pos; |
| 597 | elems->wpa_len = elen; |
| 598 | } else if (elen >= 5 && pos[3] == 2) { |
| 599 | if (pos[4] == 0) { |
| 600 | elems->wmm_info = pos; |
| 601 | elems->wmm_info_len = elen; |
| 602 | } else if (pos[4] == 1) { |
| 603 | elems->wmm_param = pos; |
| 604 | elems->wmm_param_len = elen; |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | break; |
| 609 | case WLAN_EID_RSN: |
| 610 | elems->rsn = pos; |
| 611 | elems->rsn_len = elen; |
| 612 | break; |
| 613 | case WLAN_EID_ERP_INFO: |
| 614 | elems->erp_info = pos; |
| 615 | elems->erp_info_len = elen; |
| 616 | break; |
| 617 | case WLAN_EID_EXT_SUPP_RATES: |
| 618 | elems->ext_supp_rates = pos; |
| 619 | elems->ext_supp_rates_len = elen; |
| 620 | break; |
| 621 | case WLAN_EID_HT_CAPABILITY: |
Johannes Berg | 0991481 | 2008-10-07 19:31:17 +0200 | [diff] [blame] | 622 | if (elen >= sizeof(struct ieee80211_ht_cap)) |
| 623 | elems->ht_cap_elem = (void *)pos; |
Johannes Berg | 37ffc8d | 2008-09-08 16:40:36 +0200 | [diff] [blame] | 624 | break; |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 625 | case WLAN_EID_HT_INFORMATION: |
| 626 | if (elen >= sizeof(struct ieee80211_ht_info)) |
Johannes Berg | 0991481 | 2008-10-07 19:31:17 +0200 | [diff] [blame] | 627 | elems->ht_info_elem = (void *)pos; |
Johannes Berg | 37ffc8d | 2008-09-08 16:40:36 +0200 | [diff] [blame] | 628 | break; |
| 629 | case WLAN_EID_MESH_ID: |
| 630 | elems->mesh_id = pos; |
| 631 | elems->mesh_id_len = elen; |
| 632 | break; |
| 633 | case WLAN_EID_MESH_CONFIG: |
| 634 | elems->mesh_config = pos; |
| 635 | elems->mesh_config_len = elen; |
| 636 | break; |
| 637 | case WLAN_EID_PEER_LINK: |
| 638 | elems->peer_link = pos; |
| 639 | elems->peer_link_len = elen; |
| 640 | break; |
| 641 | case WLAN_EID_PREQ: |
| 642 | elems->preq = pos; |
| 643 | elems->preq_len = elen; |
| 644 | break; |
| 645 | case WLAN_EID_PREP: |
| 646 | elems->prep = pos; |
| 647 | elems->prep_len = elen; |
| 648 | break; |
| 649 | case WLAN_EID_PERR: |
| 650 | elems->perr = pos; |
| 651 | elems->perr_len = elen; |
| 652 | break; |
| 653 | case WLAN_EID_CHANNEL_SWITCH: |
| 654 | elems->ch_switch_elem = pos; |
| 655 | elems->ch_switch_elem_len = elen; |
| 656 | break; |
| 657 | case WLAN_EID_QUIET: |
| 658 | if (!elems->quiet_elem) { |
| 659 | elems->quiet_elem = pos; |
| 660 | elems->quiet_elem_len = elen; |
| 661 | } |
| 662 | elems->num_of_quiet_elem++; |
| 663 | break; |
| 664 | case WLAN_EID_COUNTRY: |
| 665 | elems->country_elem = pos; |
| 666 | elems->country_elem_len = elen; |
| 667 | break; |
| 668 | case WLAN_EID_PWR_CONSTRAINT: |
| 669 | elems->pwr_constr_elem = pos; |
| 670 | elems->pwr_constr_elem_len = elen; |
| 671 | break; |
Jouni Malinen | f797eb7 | 2009-01-19 18:48:46 +0200 | [diff] [blame] | 672 | case WLAN_EID_TIMEOUT_INTERVAL: |
| 673 | elems->timeout_int = pos; |
| 674 | elems->timeout_int_len = elen; |
Jouni Malinen | 63a5ab8 | 2009-01-08 13:32:09 +0200 | [diff] [blame] | 675 | break; |
Johannes Berg | 37ffc8d | 2008-09-08 16:40:36 +0200 | [diff] [blame] | 676 | default: |
| 677 | break; |
| 678 | } |
| 679 | |
| 680 | left -= elen; |
| 681 | pos += elen; |
| 682 | } |
| 683 | } |
Johannes Berg | 5825fe10 | 2008-09-09 12:56:01 +0200 | [diff] [blame] | 684 | |
| 685 | void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata) |
| 686 | { |
| 687 | struct ieee80211_local *local = sdata->local; |
| 688 | struct ieee80211_tx_queue_params qparam; |
| 689 | int i; |
| 690 | |
| 691 | if (!local->ops->conf_tx) |
| 692 | return; |
| 693 | |
| 694 | memset(&qparam, 0, sizeof(qparam)); |
| 695 | |
| 696 | qparam.aifs = 2; |
| 697 | |
| 698 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && |
| 699 | !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)) |
| 700 | qparam.cw_min = 31; |
| 701 | else |
| 702 | qparam.cw_min = 15; |
| 703 | |
| 704 | qparam.cw_max = 1023; |
| 705 | qparam.txop = 0; |
| 706 | |
| 707 | for (i = 0; i < local_to_hw(local)->queues; i++) |
| 708 | local->ops->conf_tx(local_to_hw(local), i, &qparam); |
| 709 | } |
Johannes Berg | e50db65 | 2008-09-09 15:07:09 +0200 | [diff] [blame] | 710 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 711 | void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata, |
| 712 | const size_t supp_rates_len, |
| 713 | const u8 *supp_rates) |
| 714 | { |
| 715 | struct ieee80211_local *local = sdata->local; |
| 716 | int i, have_higher_than_11mbit = 0; |
| 717 | |
| 718 | /* cf. IEEE 802.11 9.2.12 */ |
| 719 | for (i = 0; i < supp_rates_len; i++) |
| 720 | if ((supp_rates[i] & 0x7f) * 5 > 110) |
| 721 | have_higher_than_11mbit = 1; |
| 722 | |
| 723 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && |
| 724 | have_higher_than_11mbit) |
| 725 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; |
| 726 | else |
| 727 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; |
| 728 | |
| 729 | ieee80211_set_wmm_default(sdata); |
| 730 | } |
| 731 | |
Johannes Berg | e50db65 | 2008-09-09 15:07:09 +0200 | [diff] [blame] | 732 | void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, |
| 733 | int encrypt) |
| 734 | { |
| 735 | skb->dev = sdata->local->mdev; |
| 736 | skb_set_mac_header(skb, 0); |
| 737 | skb_set_network_header(skb, 0); |
| 738 | skb_set_transport_header(skb, 0); |
| 739 | |
| 740 | skb->iif = sdata->dev->ifindex; |
| 741 | skb->do_not_encrypt = !encrypt; |
| 742 | |
| 743 | dev_queue_xmit(skb); |
| 744 | } |
Johannes Berg | e16751c | 2008-09-11 00:01:53 +0200 | [diff] [blame] | 745 | |
| 746 | int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freqMHz) |
| 747 | { |
| 748 | int ret = -EINVAL; |
| 749 | struct ieee80211_channel *chan; |
| 750 | struct ieee80211_local *local = sdata->local; |
| 751 | |
| 752 | chan = ieee80211_get_channel(local->hw.wiphy, freqMHz); |
| 753 | |
| 754 | if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 755 | if (sdata->vif.type == NL80211_IFTYPE_ADHOC && |
Johannes Berg | d73782f | 2008-10-07 12:04:34 +0200 | [diff] [blame] | 756 | chan->flags & IEEE80211_CHAN_NO_IBSS) |
Johannes Berg | e16751c | 2008-09-11 00:01:53 +0200 | [diff] [blame] | 757 | return ret; |
Johannes Berg | e16751c | 2008-09-11 00:01:53 +0200 | [diff] [blame] | 758 | local->oper_channel = chan; |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 759 | local->oper_channel_type = NL80211_CHAN_NO_HT; |
Johannes Berg | e16751c | 2008-09-11 00:01:53 +0200 | [diff] [blame] | 760 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 761 | if (local->sw_scanning || local->hw_scanning) |
Johannes Berg | e16751c | 2008-09-11 00:01:53 +0200 | [diff] [blame] | 762 | ret = 0; |
| 763 | else |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 764 | ret = ieee80211_hw_config( |
| 765 | local, IEEE80211_CONF_CHANGE_CHANNEL); |
Johannes Berg | e16751c | 2008-09-11 00:01:53 +0200 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | return ret; |
| 769 | } |
Johannes Berg | 96dd22a | 2008-09-11 00:01:57 +0200 | [diff] [blame] | 770 | |
Johannes Berg | 881d948 | 2009-01-21 15:13:48 +0100 | [diff] [blame] | 771 | u32 ieee80211_mandatory_rates(struct ieee80211_local *local, |
Johannes Berg | 96dd22a | 2008-09-11 00:01:57 +0200 | [diff] [blame] | 772 | enum ieee80211_band band) |
| 773 | { |
| 774 | struct ieee80211_supported_band *sband; |
| 775 | struct ieee80211_rate *bitrates; |
Johannes Berg | 881d948 | 2009-01-21 15:13:48 +0100 | [diff] [blame] | 776 | u32 mandatory_rates; |
Johannes Berg | 96dd22a | 2008-09-11 00:01:57 +0200 | [diff] [blame] | 777 | enum ieee80211_rate_flags mandatory_flag; |
| 778 | int i; |
| 779 | |
| 780 | sband = local->hw.wiphy->bands[band]; |
| 781 | if (!sband) { |
| 782 | WARN_ON(1); |
| 783 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 784 | } |
| 785 | |
| 786 | if (band == IEEE80211_BAND_2GHZ) |
| 787 | mandatory_flag = IEEE80211_RATE_MANDATORY_B; |
| 788 | else |
| 789 | mandatory_flag = IEEE80211_RATE_MANDATORY_A; |
| 790 | |
| 791 | bitrates = sband->bitrates; |
| 792 | mandatory_rates = 0; |
| 793 | for (i = 0; i < sband->n_bitrates; i++) |
| 794 | if (bitrates[i].flags & mandatory_flag) |
| 795 | mandatory_rates |= BIT(i); |
| 796 | return mandatory_rates; |
| 797 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 798 | |
| 799 | void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata, |
| 800 | u16 transaction, u16 auth_alg, |
| 801 | u8 *extra, size_t extra_len, |
| 802 | const u8 *bssid, int encrypt) |
| 803 | { |
| 804 | struct ieee80211_local *local = sdata->local; |
| 805 | struct sk_buff *skb; |
| 806 | struct ieee80211_mgmt *mgmt; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 807 | |
| 808 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + |
Jouni Malinen | 65fc73a | 2009-03-20 21:21:16 +0200 | [diff] [blame] | 809 | sizeof(*mgmt) + 6 + extra_len); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 810 | if (!skb) { |
| 811 | printk(KERN_DEBUG "%s: failed to allocate buffer for auth " |
| 812 | "frame\n", sdata->dev->name); |
| 813 | return; |
| 814 | } |
| 815 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 816 | |
| 817 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6); |
| 818 | memset(mgmt, 0, 24 + 6); |
| 819 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 820 | IEEE80211_STYPE_AUTH); |
| 821 | if (encrypt) |
| 822 | mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
| 823 | memcpy(mgmt->da, bssid, ETH_ALEN); |
| 824 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
| 825 | memcpy(mgmt->bssid, bssid, ETH_ALEN); |
| 826 | mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg); |
| 827 | mgmt->u.auth.auth_transaction = cpu_to_le16(transaction); |
| 828 | mgmt->u.auth.status_code = cpu_to_le16(0); |
| 829 | if (extra) |
| 830 | memcpy(skb_put(skb, extra_len), extra, extra_len); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 831 | |
| 832 | ieee80211_tx_skb(sdata, skb, encrypt); |
| 833 | } |
| 834 | |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 835 | int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer, |
| 836 | const u8 *ie, size_t ie_len) |
| 837 | { |
| 838 | struct ieee80211_supported_band *sband; |
| 839 | u8 *pos, *supp_rates_len, *esupp_rates_len = NULL; |
| 840 | int i; |
| 841 | |
| 842 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 843 | |
| 844 | pos = buffer; |
| 845 | |
| 846 | *pos++ = WLAN_EID_SUPP_RATES; |
| 847 | supp_rates_len = pos; |
| 848 | *pos++ = 0; |
| 849 | |
| 850 | for (i = 0; i < sband->n_bitrates; i++) { |
| 851 | struct ieee80211_rate *rate = &sband->bitrates[i]; |
| 852 | |
| 853 | if (esupp_rates_len) { |
| 854 | *esupp_rates_len += 1; |
| 855 | } else if (*supp_rates_len == 8) { |
| 856 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 857 | esupp_rates_len = pos; |
| 858 | *pos++ = 1; |
| 859 | } else |
| 860 | *supp_rates_len += 1; |
| 861 | |
| 862 | *pos++ = rate->bitrate / 5; |
| 863 | } |
| 864 | |
Johannes Berg | 5ef2d41 | 2009-03-31 12:12:07 +0200 | [diff] [blame] | 865 | if (sband->ht_cap.ht_supported) { |
| 866 | __le16 tmp = cpu_to_le16(sband->ht_cap.cap); |
| 867 | |
| 868 | *pos++ = WLAN_EID_HT_CAPABILITY; |
| 869 | *pos++ = sizeof(struct ieee80211_ht_cap); |
| 870 | memset(pos, 0, sizeof(struct ieee80211_ht_cap)); |
| 871 | memcpy(pos, &tmp, sizeof(u16)); |
| 872 | pos += sizeof(u16); |
| 873 | /* TODO: needs a define here for << 2 */ |
| 874 | *pos++ = sband->ht_cap.ampdu_factor | |
| 875 | (sband->ht_cap.ampdu_density << 2); |
| 876 | memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs)); |
| 877 | pos += sizeof(sband->ht_cap.mcs); |
| 878 | pos += 2 + 4 + 1; /* ext info, BF cap, antsel */ |
| 879 | } |
| 880 | |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 881 | /* |
| 882 | * If adding more here, adjust code in main.c |
| 883 | * that calculates local->scan_ies_len. |
| 884 | */ |
| 885 | |
| 886 | if (ie) { |
| 887 | memcpy(pos, ie, ie_len); |
| 888 | pos += ie_len; |
| 889 | } |
| 890 | |
| 891 | return pos - buffer; |
| 892 | } |
| 893 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 894 | void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 895 | const u8 *ssid, size_t ssid_len, |
| 896 | const u8 *ie, size_t ie_len) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 897 | { |
| 898 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 899 | struct sk_buff *skb; |
| 900 | struct ieee80211_mgmt *mgmt; |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 901 | u8 *pos; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 902 | |
| 903 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200 + |
Jouni Malinen | 65fc73a | 2009-03-20 21:21:16 +0200 | [diff] [blame] | 904 | ie_len); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 905 | if (!skb) { |
| 906 | printk(KERN_DEBUG "%s: failed to allocate buffer for probe " |
| 907 | "request\n", sdata->dev->name); |
| 908 | return; |
| 909 | } |
| 910 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 911 | |
| 912 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 913 | memset(mgmt, 0, 24); |
| 914 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 915 | IEEE80211_STYPE_PROBE_REQ); |
| 916 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
| 917 | if (dst) { |
| 918 | memcpy(mgmt->da, dst, ETH_ALEN); |
| 919 | memcpy(mgmt->bssid, dst, ETH_ALEN); |
| 920 | } else { |
| 921 | memset(mgmt->da, 0xff, ETH_ALEN); |
| 922 | memset(mgmt->bssid, 0xff, ETH_ALEN); |
| 923 | } |
| 924 | pos = skb_put(skb, 2 + ssid_len); |
| 925 | *pos++ = WLAN_EID_SSID; |
| 926 | *pos++ = ssid_len; |
| 927 | memcpy(pos, ssid, ssid_len); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 928 | pos += ssid_len; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 929 | |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 930 | skb_put(skb, ieee80211_build_preq_ies(local, pos, ie, ie_len)); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 931 | |
| 932 | ieee80211_tx_skb(sdata, skb, 0); |
| 933 | } |
| 934 | |
| 935 | u32 ieee80211_sta_get_rates(struct ieee80211_local *local, |
| 936 | struct ieee802_11_elems *elems, |
| 937 | enum ieee80211_band band) |
| 938 | { |
| 939 | struct ieee80211_supported_band *sband; |
| 940 | struct ieee80211_rate *bitrates; |
| 941 | size_t num_rates; |
| 942 | u32 supp_rates; |
| 943 | int i, j; |
| 944 | sband = local->hw.wiphy->bands[band]; |
| 945 | |
| 946 | if (!sband) { |
| 947 | WARN_ON(1); |
| 948 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 949 | } |
| 950 | |
| 951 | bitrates = sband->bitrates; |
| 952 | num_rates = sband->n_bitrates; |
| 953 | supp_rates = 0; |
| 954 | for (i = 0; i < elems->supp_rates_len + |
| 955 | elems->ext_supp_rates_len; i++) { |
| 956 | u8 rate = 0; |
| 957 | int own_rate; |
| 958 | if (i < elems->supp_rates_len) |
| 959 | rate = elems->supp_rates[i]; |
| 960 | else if (elems->ext_supp_rates) |
| 961 | rate = elems->ext_supp_rates |
| 962 | [i - elems->supp_rates_len]; |
| 963 | own_rate = 5 * (rate & 0x7f); |
| 964 | for (j = 0; j < num_rates; j++) |
| 965 | if (bitrates[j].bitrate == own_rate) |
| 966 | supp_rates |= BIT(j); |
| 967 | } |
| 968 | return supp_rates; |
| 969 | } |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame^] | 970 | |
| 971 | int ieee80211_reconfig(struct ieee80211_local *local) |
| 972 | { |
| 973 | struct ieee80211_hw *hw = &local->hw; |
| 974 | struct ieee80211_sub_if_data *sdata; |
| 975 | struct ieee80211_if_init_conf conf; |
| 976 | struct sta_info *sta; |
| 977 | unsigned long flags; |
| 978 | int res; |
| 979 | |
| 980 | /* restart hardware */ |
| 981 | if (local->open_count) { |
| 982 | res = local->ops->start(hw); |
| 983 | |
| 984 | ieee80211_led_radio(local, hw->conf.radio_enabled); |
| 985 | } |
| 986 | |
| 987 | /* add interfaces */ |
| 988 | list_for_each_entry(sdata, &local->interfaces, list) { |
| 989 | if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
| 990 | sdata->vif.type != NL80211_IFTYPE_MONITOR && |
| 991 | netif_running(sdata->dev)) { |
| 992 | conf.vif = &sdata->vif; |
| 993 | conf.type = sdata->vif.type; |
| 994 | conf.mac_addr = sdata->dev->dev_addr; |
| 995 | res = local->ops->add_interface(hw, &conf); |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | /* add STAs back */ |
| 1000 | if (local->ops->sta_notify) { |
| 1001 | spin_lock_irqsave(&local->sta_lock, flags); |
| 1002 | list_for_each_entry(sta, &local->sta_list, list) { |
| 1003 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
| 1004 | sdata = container_of(sdata->bss, |
| 1005 | struct ieee80211_sub_if_data, |
| 1006 | u.ap); |
| 1007 | |
| 1008 | local->ops->sta_notify(hw, &sdata->vif, |
| 1009 | STA_NOTIFY_ADD, &sta->sta); |
| 1010 | } |
| 1011 | spin_unlock_irqrestore(&local->sta_lock, flags); |
| 1012 | } |
| 1013 | |
| 1014 | /* Clear Suspend state so that ADDBA requests can be processed */ |
| 1015 | |
| 1016 | rcu_read_lock(); |
| 1017 | |
| 1018 | if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) { |
| 1019 | list_for_each_entry_rcu(sta, &local->sta_list, list) { |
| 1020 | clear_sta_flags(sta, WLAN_STA_SUSPEND); |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | rcu_read_unlock(); |
| 1025 | |
| 1026 | /* setup RTS threshold */ |
| 1027 | if (local->ops->set_rts_threshold) |
| 1028 | local->ops->set_rts_threshold(hw, local->rts_threshold); |
| 1029 | |
| 1030 | /* reconfigure hardware */ |
| 1031 | ieee80211_hw_config(local, ~0); |
| 1032 | |
| 1033 | netif_addr_lock_bh(local->mdev); |
| 1034 | ieee80211_configure_filter(local); |
| 1035 | netif_addr_unlock_bh(local->mdev); |
| 1036 | |
| 1037 | /* Finally also reconfigure all the BSS information */ |
| 1038 | list_for_each_entry(sdata, &local->interfaces, list) { |
| 1039 | u32 changed = ~0; |
| 1040 | if (!netif_running(sdata->dev)) |
| 1041 | continue; |
| 1042 | switch (sdata->vif.type) { |
| 1043 | case NL80211_IFTYPE_STATION: |
| 1044 | /* disable beacon change bits */ |
| 1045 | changed &= ~IEEE80211_IFCC_BEACON; |
| 1046 | /* fall through */ |
| 1047 | case NL80211_IFTYPE_ADHOC: |
| 1048 | case NL80211_IFTYPE_AP: |
| 1049 | case NL80211_IFTYPE_MESH_POINT: |
| 1050 | /* |
| 1051 | * Driver's config_interface can fail if rfkill is |
| 1052 | * enabled. Accommodate this return code. |
| 1053 | * FIXME: When mac80211 has knowledge of rfkill |
| 1054 | * state the code below can change back to: |
| 1055 | * WARN(ieee80211_if_config(sdata, changed)); |
| 1056 | * ieee80211_bss_info_change_notify(sdata, ~0); |
| 1057 | */ |
| 1058 | if (ieee80211_if_config(sdata, changed)) |
| 1059 | printk(KERN_DEBUG "%s: failed to configure interface during resume\n", |
| 1060 | sdata->dev->name); |
| 1061 | else |
| 1062 | ieee80211_bss_info_change_notify(sdata, ~0); |
| 1063 | break; |
| 1064 | case NL80211_IFTYPE_WDS: |
| 1065 | break; |
| 1066 | case NL80211_IFTYPE_AP_VLAN: |
| 1067 | case NL80211_IFTYPE_MONITOR: |
| 1068 | /* ignore virtual */ |
| 1069 | break; |
| 1070 | case NL80211_IFTYPE_UNSPECIFIED: |
| 1071 | case __NL80211_IFTYPE_AFTER_LAST: |
| 1072 | WARN_ON(1); |
| 1073 | break; |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | /* add back keys */ |
| 1078 | list_for_each_entry(sdata, &local->interfaces, list) |
| 1079 | if (netif_running(sdata->dev)) |
| 1080 | ieee80211_enable_keys(sdata); |
| 1081 | |
| 1082 | ieee80211_wake_queues_by_reason(hw, |
| 1083 | IEEE80211_QUEUE_STOP_REASON_SUSPEND); |
| 1084 | |
| 1085 | return 0; |
| 1086 | } |