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> |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 21 | #include <linux/bitmap.h> |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 22 | #include <net/net_namespace.h> |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 23 | #include <net/cfg80211.h> |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 24 | #include <net/rtnetlink.h> |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 25 | |
| 26 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 27 | #include "driver-ops.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 | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 32 | #include "wep.h" |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 33 | |
| 34 | /* privid for wiphys to determine whether they belong to us or not */ |
| 35 | void *mac80211_wiphy_privid = &mac80211_wiphy_privid; |
| 36 | |
Luis R. Rodriguez | 9a95371 | 2009-01-22 15:05:53 -0800 | [diff] [blame] | 37 | struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy) |
| 38 | { |
| 39 | struct ieee80211_local *local; |
| 40 | BUG_ON(!wiphy); |
| 41 | |
| 42 | local = wiphy_priv(wiphy); |
| 43 | return &local->hw; |
| 44 | } |
| 45 | EXPORT_SYMBOL(wiphy_to_ieee80211_hw); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 46 | |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 47 | u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len, |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 48 | enum nl80211_iftype type) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 49 | { |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 50 | __le16 fc = hdr->frame_control; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 51 | |
Ron Rindjunsky | 98f0b0a | 2007-12-18 17:23:53 +0200 | [diff] [blame] | 52 | /* drop ACK/CTS frames and incorrect hdr len (ctrl) */ |
| 53 | if (len < 16) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 54 | return NULL; |
| 55 | |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 56 | if (ieee80211_is_data(fc)) { |
Ron Rindjunsky | 98f0b0a | 2007-12-18 17:23:53 +0200 | [diff] [blame] | 57 | if (len < 24) /* drop incorrect hdr len (data) */ |
| 58 | return NULL; |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 59 | |
| 60 | if (ieee80211_has_a4(fc)) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 61 | return NULL; |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 62 | if (ieee80211_has_tods(fc)) |
| 63 | return hdr->addr1; |
| 64 | if (ieee80211_has_fromds(fc)) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 65 | return hdr->addr2; |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 66 | |
| 67 | return hdr->addr3; |
| 68 | } |
| 69 | |
| 70 | if (ieee80211_is_mgmt(fc)) { |
Ron Rindjunsky | 98f0b0a | 2007-12-18 17:23:53 +0200 | [diff] [blame] | 71 | if (len < 24) /* drop incorrect hdr len (mgmt) */ |
| 72 | return NULL; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 73 | return hdr->addr3; |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | if (ieee80211_is_ctl(fc)) { |
| 77 | if(ieee80211_is_pspoll(fc)) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 78 | return hdr->addr1; |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 79 | |
| 80 | if (ieee80211_is_back_req(fc)) { |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 81 | switch (type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 82 | case NL80211_IFTYPE_STATION: |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 83 | return hdr->addr2; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 84 | case NL80211_IFTYPE_AP: |
| 85 | case NL80211_IFTYPE_AP_VLAN: |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 86 | return hdr->addr1; |
| 87 | default: |
Harvey Harrison | a494bb1 | 2008-06-11 14:21:58 -0700 | [diff] [blame] | 88 | break; /* fall through to the return */ |
Ron Rindjunsky | 7136471 | 2007-12-25 17:00:36 +0200 | [diff] [blame] | 89 | } |
| 90 | } |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | return NULL; |
| 94 | } |
| 95 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 96 | void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 97 | { |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 98 | struct sk_buff *skb = tx->skb; |
| 99 | struct ieee80211_hdr *hdr; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 100 | |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 101 | do { |
| 102 | hdr = (struct ieee80211_hdr *) skb->data; |
| 103 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
| 104 | } while ((skb = skb->next)); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | int ieee80211_frame_duration(struct ieee80211_local *local, size_t len, |
| 108 | int rate, int erp, int short_preamble) |
| 109 | { |
| 110 | int dur; |
| 111 | |
| 112 | /* calculate duration (in microseconds, rounded up to next higher |
| 113 | * integer if it includes a fractional microsecond) to send frame of |
| 114 | * len bytes (does not include FCS) at the given rate. Duration will |
| 115 | * also include SIFS. |
| 116 | * |
| 117 | * rate is in 100 kbps, so divident is multiplied by 10 in the |
| 118 | * DIV_ROUND_UP() operations. |
| 119 | */ |
| 120 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 121 | if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ || erp) { |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 122 | /* |
| 123 | * OFDM: |
| 124 | * |
| 125 | * N_DBPS = DATARATE x 4 |
| 126 | * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS) |
| 127 | * (16 = SIGNAL time, 6 = tail bits) |
| 128 | * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext |
| 129 | * |
| 130 | * T_SYM = 4 usec |
| 131 | * 802.11a - 17.5.2: aSIFSTime = 16 usec |
| 132 | * 802.11g - 19.8.4: aSIFSTime = 10 usec + |
| 133 | * signal ext = 6 usec |
| 134 | */ |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 135 | dur = 16; /* SIFS + signal ext */ |
| 136 | dur += 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */ |
| 137 | dur += 4; /* 17.3.2.3: T_SIGNAL = 4 usec */ |
| 138 | dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10, |
| 139 | 4 * rate); /* T_SYM x N_SYM */ |
| 140 | } else { |
| 141 | /* |
| 142 | * 802.11b or 802.11g with 802.11b compatibility: |
| 143 | * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime + |
| 144 | * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0. |
| 145 | * |
| 146 | * 802.11 (DS): 15.3.3, 802.11b: 18.3.4 |
| 147 | * aSIFSTime = 10 usec |
| 148 | * aPreambleLength = 144 usec or 72 usec with short preamble |
| 149 | * aPLCPHeaderLength = 48 usec or 24 usec with short preamble |
| 150 | */ |
| 151 | dur = 10; /* aSIFSTime = 10 usec */ |
| 152 | dur += short_preamble ? (72 + 24) : (144 + 48); |
| 153 | |
| 154 | dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate); |
| 155 | } |
| 156 | |
| 157 | return dur; |
| 158 | } |
| 159 | |
| 160 | /* Exported duration function for driver use */ |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 161 | __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw, |
| 162 | struct ieee80211_vif *vif, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 163 | size_t frame_len, |
| 164 | struct ieee80211_rate *rate) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 165 | { |
| 166 | struct ieee80211_local *local = hw_to_local(hw); |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 167 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 168 | u16 dur; |
| 169 | int erp; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 170 | bool short_preamble = false; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 171 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 172 | erp = 0; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 173 | if (vif) { |
| 174 | sdata = vif_to_sdata(vif); |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 175 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 176 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
| 177 | erp = rate->flags & IEEE80211_RATE_ERP_G; |
| 178 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 179 | |
| 180 | dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, erp, |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 181 | short_preamble); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 182 | |
| 183 | return cpu_to_le16(dur); |
| 184 | } |
| 185 | EXPORT_SYMBOL(ieee80211_generic_frame_duration); |
| 186 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 187 | __le16 ieee80211_rts_duration(struct ieee80211_hw *hw, |
| 188 | struct ieee80211_vif *vif, size_t frame_len, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 189 | const struct ieee80211_tx_info *frame_txctl) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 190 | { |
| 191 | struct ieee80211_local *local = hw_to_local(hw); |
| 192 | struct ieee80211_rate *rate; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 193 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 194 | bool short_preamble; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 195 | int erp; |
| 196 | u16 dur; |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 197 | struct ieee80211_supported_band *sband; |
| 198 | |
| 199 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 200 | |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 201 | short_preamble = false; |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 202 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 203 | rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 204 | |
| 205 | erp = 0; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 206 | if (vif) { |
| 207 | sdata = vif_to_sdata(vif); |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 208 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 209 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
| 210 | erp = rate->flags & IEEE80211_RATE_ERP_G; |
| 211 | } |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 212 | |
| 213 | /* CTS duration */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 214 | dur = ieee80211_frame_duration(local, 10, rate->bitrate, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 215 | erp, short_preamble); |
| 216 | /* Data frame duration */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 217 | dur += ieee80211_frame_duration(local, frame_len, rate->bitrate, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 218 | erp, short_preamble); |
| 219 | /* ACK duration */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 220 | dur += ieee80211_frame_duration(local, 10, rate->bitrate, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 221 | erp, short_preamble); |
| 222 | |
| 223 | return cpu_to_le16(dur); |
| 224 | } |
| 225 | EXPORT_SYMBOL(ieee80211_rts_duration); |
| 226 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 227 | __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw, |
| 228 | struct ieee80211_vif *vif, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 229 | size_t frame_len, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 230 | const struct ieee80211_tx_info *frame_txctl) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 231 | { |
| 232 | struct ieee80211_local *local = hw_to_local(hw); |
| 233 | struct ieee80211_rate *rate; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 234 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 235 | bool short_preamble; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 236 | int erp; |
| 237 | u16 dur; |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 238 | struct ieee80211_supported_band *sband; |
| 239 | |
| 240 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 241 | |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 242 | short_preamble = false; |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 243 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 244 | rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 245 | erp = 0; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 246 | if (vif) { |
| 247 | sdata = vif_to_sdata(vif); |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 248 | short_preamble = sdata->vif.bss_conf.use_short_preamble; |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 249 | if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
| 250 | erp = rate->flags & IEEE80211_RATE_ERP_G; |
| 251 | } |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 252 | |
| 253 | /* Data frame duration */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 254 | dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 255 | erp, short_preamble); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 256 | if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) { |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 257 | /* ACK duration */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 258 | dur += ieee80211_frame_duration(local, 10, rate->bitrate, |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 259 | erp, short_preamble); |
| 260 | } |
| 261 | |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 262 | return cpu_to_le16(dur); |
| 263 | } |
| 264 | EXPORT_SYMBOL(ieee80211_ctstoself_duration); |
| 265 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 266 | static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue, |
| 267 | enum queue_stop_reason reason) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 268 | { |
| 269 | struct ieee80211_local *local = hw_to_local(hw); |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 270 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 271 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 272 | trace_wake_queue(local, queue, reason); |
| 273 | |
Johannes Berg | e4e72fb | 2009-03-23 17:28:42 +0100 | [diff] [blame] | 274 | if (WARN_ON(queue >= hw->queues)) |
| 275 | return; |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 276 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame] | 277 | __clear_bit(reason, &local->queue_stop_reasons[queue]); |
| 278 | |
| 279 | if (local->queue_stop_reasons[queue] != 0) |
| 280 | /* someone still has this queue stopped */ |
| 281 | return; |
| 282 | |
Johannes Berg | 7236fe2 | 2010-03-22 13:42:43 -0700 | [diff] [blame] | 283 | if (skb_queue_empty(&local->pending[queue])) { |
| 284 | rcu_read_lock(); |
Johannes Berg | 5b714c6 | 2010-08-27 13:45:28 +0200 | [diff] [blame] | 285 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
| 286 | if (test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)) |
| 287 | continue; |
Johannes Berg | 2337db8 | 2010-08-27 13:36:49 +0200 | [diff] [blame] | 288 | netif_wake_subqueue(sdata->dev, queue); |
Johannes Berg | 5b714c6 | 2010-08-27 13:45:28 +0200 | [diff] [blame] | 289 | } |
Johannes Berg | 7236fe2 | 2010-03-22 13:42:43 -0700 | [diff] [blame] | 290 | rcu_read_unlock(); |
| 291 | } else |
Johannes Berg | 3b8d81e | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 292 | tasklet_schedule(&local->tx_pending_tasklet); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 293 | } |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 294 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame] | 295 | void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue, |
| 296 | enum queue_stop_reason reason) |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 297 | { |
| 298 | struct ieee80211_local *local = hw_to_local(hw); |
| 299 | unsigned long flags; |
| 300 | |
| 301 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 302 | __ieee80211_wake_queue(hw, queue, reason); |
| 303 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 304 | } |
| 305 | |
| 306 | void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue) |
| 307 | { |
| 308 | ieee80211_wake_queue_by_reason(hw, queue, |
| 309 | IEEE80211_QUEUE_STOP_REASON_DRIVER); |
| 310 | } |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 311 | EXPORT_SYMBOL(ieee80211_wake_queue); |
| 312 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 313 | static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue, |
| 314 | enum queue_stop_reason reason) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 315 | { |
| 316 | struct ieee80211_local *local = hw_to_local(hw); |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 317 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 318 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 319 | trace_stop_queue(local, queue, reason); |
| 320 | |
Johannes Berg | e4e72fb | 2009-03-23 17:28:42 +0100 | [diff] [blame] | 321 | if (WARN_ON(queue >= hw->queues)) |
| 322 | return; |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame] | 323 | |
Johannes Berg | 2a577d9 | 2009-03-23 17:28:37 +0100 | [diff] [blame] | 324 | __set_bit(reason, &local->queue_stop_reasons[queue]); |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 325 | |
| 326 | rcu_read_lock(); |
| 327 | list_for_each_entry_rcu(sdata, &local->interfaces, list) |
Johannes Berg | 2337db8 | 2010-08-27 13:36:49 +0200 | [diff] [blame] | 328 | netif_stop_subqueue(sdata->dev, queue); |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 329 | rcu_read_unlock(); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 330 | } |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 331 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame] | 332 | void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue, |
| 333 | enum queue_stop_reason reason) |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 334 | { |
| 335 | struct ieee80211_local *local = hw_to_local(hw); |
| 336 | unsigned long flags; |
| 337 | |
| 338 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 339 | __ieee80211_stop_queue(hw, queue, reason); |
| 340 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 341 | } |
| 342 | |
| 343 | void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue) |
| 344 | { |
| 345 | ieee80211_stop_queue_by_reason(hw, queue, |
| 346 | IEEE80211_QUEUE_STOP_REASON_DRIVER); |
| 347 | } |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 348 | EXPORT_SYMBOL(ieee80211_stop_queue); |
| 349 | |
Johannes Berg | 8f77f38 | 2009-06-07 21:58:37 +0200 | [diff] [blame] | 350 | void ieee80211_add_pending_skb(struct ieee80211_local *local, |
| 351 | struct sk_buff *skb) |
| 352 | { |
| 353 | struct ieee80211_hw *hw = &local->hw; |
| 354 | unsigned long flags; |
| 355 | int queue = skb_get_queue_mapping(skb); |
Johannes Berg | a7bc376 | 2009-07-27 10:33:31 +0200 | [diff] [blame] | 356 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 357 | |
| 358 | if (WARN_ON(!info->control.vif)) { |
Roel Kluin | 0819663 | 2009-10-06 15:52:35 +0200 | [diff] [blame] | 359 | kfree_skb(skb); |
Johannes Berg | a7bc376 | 2009-07-27 10:33:31 +0200 | [diff] [blame] | 360 | return; |
| 361 | } |
Johannes Berg | 8f77f38 | 2009-06-07 21:58:37 +0200 | [diff] [blame] | 362 | |
| 363 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 364 | __ieee80211_stop_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD); |
Johannes Berg | 3b8d81e | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 365 | __skb_queue_tail(&local->pending[queue], skb); |
Johannes Berg | 8f77f38 | 2009-06-07 21:58:37 +0200 | [diff] [blame] | 366 | __ieee80211_wake_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD); |
| 367 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 368 | } |
| 369 | |
Johannes Berg | b0b97a8 | 2011-09-29 16:04:30 +0200 | [diff] [blame] | 370 | void ieee80211_add_pending_skbs_fn(struct ieee80211_local *local, |
| 371 | struct sk_buff_head *skbs, |
| 372 | void (*fn)(void *data), void *data) |
Johannes Berg | 8f77f38 | 2009-06-07 21:58:37 +0200 | [diff] [blame] | 373 | { |
| 374 | struct ieee80211_hw *hw = &local->hw; |
| 375 | struct sk_buff *skb; |
| 376 | unsigned long flags; |
Johannes Berg | b0b97a8 | 2011-09-29 16:04:30 +0200 | [diff] [blame] | 377 | int queue, i; |
Johannes Berg | 8f77f38 | 2009-06-07 21:58:37 +0200 | [diff] [blame] | 378 | |
| 379 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 380 | for (i = 0; i < hw->queues; i++) |
| 381 | __ieee80211_stop_queue(hw, i, |
| 382 | IEEE80211_QUEUE_STOP_REASON_SKB_ADD); |
| 383 | |
| 384 | while ((skb = skb_dequeue(skbs))) { |
Johannes Berg | a7bc376 | 2009-07-27 10:33:31 +0200 | [diff] [blame] | 385 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 386 | |
| 387 | if (WARN_ON(!info->control.vif)) { |
Roel Kluin | 0819663 | 2009-10-06 15:52:35 +0200 | [diff] [blame] | 388 | kfree_skb(skb); |
Johannes Berg | a7bc376 | 2009-07-27 10:33:31 +0200 | [diff] [blame] | 389 | continue; |
| 390 | } |
| 391 | |
Johannes Berg | 8f77f38 | 2009-06-07 21:58:37 +0200 | [diff] [blame] | 392 | queue = skb_get_queue_mapping(skb); |
Johannes Berg | 3b8d81e | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 393 | __skb_queue_tail(&local->pending[queue], skb); |
Johannes Berg | 8f77f38 | 2009-06-07 21:58:37 +0200 | [diff] [blame] | 394 | } |
| 395 | |
Johannes Berg | 50a9432 | 2010-11-16 11:50:28 -0800 | [diff] [blame] | 396 | if (fn) |
| 397 | fn(data); |
| 398 | |
Johannes Berg | 3b8d81e | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 399 | for (i = 0; i < hw->queues; i++) |
Johannes Berg | 8f77f38 | 2009-06-07 21:58:37 +0200 | [diff] [blame] | 400 | __ieee80211_wake_queue(hw, i, |
| 401 | IEEE80211_QUEUE_STOP_REASON_SKB_ADD); |
Johannes Berg | 8f77f38 | 2009-06-07 21:58:37 +0200 | [diff] [blame] | 402 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
Johannes Berg | 8f77f38 | 2009-06-07 21:58:37 +0200 | [diff] [blame] | 403 | } |
| 404 | |
Johannes Berg | b0b97a8 | 2011-09-29 16:04:30 +0200 | [diff] [blame] | 405 | void ieee80211_add_pending_skbs(struct ieee80211_local *local, |
| 406 | struct sk_buff_head *skbs) |
Johannes Berg | 50a9432 | 2010-11-16 11:50:28 -0800 | [diff] [blame] | 407 | { |
Johannes Berg | b0b97a8 | 2011-09-29 16:04:30 +0200 | [diff] [blame] | 408 | ieee80211_add_pending_skbs_fn(local, skbs, NULL, NULL); |
Johannes Berg | 50a9432 | 2010-11-16 11:50:28 -0800 | [diff] [blame] | 409 | } |
| 410 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 411 | void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw, |
| 412 | enum queue_stop_reason reason) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 413 | { |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 414 | struct ieee80211_local *local = hw_to_local(hw); |
| 415 | unsigned long flags; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 416 | int i; |
| 417 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 418 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 419 | |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame] | 420 | for (i = 0; i < hw->queues; i++) |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 421 | __ieee80211_stop_queue(hw, i, reason); |
| 422 | |
| 423 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 424 | } |
| 425 | |
| 426 | void ieee80211_stop_queues(struct ieee80211_hw *hw) |
| 427 | { |
| 428 | ieee80211_stop_queues_by_reason(hw, |
| 429 | IEEE80211_QUEUE_STOP_REASON_DRIVER); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 430 | } |
| 431 | EXPORT_SYMBOL(ieee80211_stop_queues); |
| 432 | |
Tomas Winkler | 92ab853 | 2008-07-24 21:02:04 +0300 | [diff] [blame] | 433 | int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue) |
| 434 | { |
| 435 | struct ieee80211_local *local = hw_to_local(hw); |
Johannes Berg | 3b8d81e | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 436 | unsigned long flags; |
| 437 | int ret; |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame] | 438 | |
Johannes Berg | e4e72fb | 2009-03-23 17:28:42 +0100 | [diff] [blame] | 439 | if (WARN_ON(queue >= hw->queues)) |
| 440 | return true; |
Johannes Berg | 96f5e66 | 2009-02-12 00:51:53 +0100 | [diff] [blame] | 441 | |
Johannes Berg | 3b8d81e | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 442 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 443 | ret = !!local->queue_stop_reasons[queue]; |
| 444 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 445 | return ret; |
Tomas Winkler | 92ab853 | 2008-07-24 21:02:04 +0300 | [diff] [blame] | 446 | } |
| 447 | EXPORT_SYMBOL(ieee80211_queue_stopped); |
| 448 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 449 | void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw, |
| 450 | enum queue_stop_reason reason) |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 451 | { |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 452 | struct ieee80211_local *local = hw_to_local(hw); |
| 453 | unsigned long flags; |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 454 | int i; |
| 455 | |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 456 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 457 | |
Johannes Berg | e4e72fb | 2009-03-23 17:28:42 +0100 | [diff] [blame] | 458 | for (i = 0; i < hw->queues; i++) |
Kalle Valo | ce7c911 | 2008-12-18 23:35:20 +0200 | [diff] [blame] | 459 | __ieee80211_wake_queue(hw, i, reason); |
| 460 | |
| 461 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 462 | } |
| 463 | |
| 464 | void ieee80211_wake_queues(struct ieee80211_hw *hw) |
| 465 | { |
| 466 | ieee80211_wake_queues_by_reason(hw, IEEE80211_QUEUE_STOP_REASON_DRIVER); |
Johannes Berg | c2d1560 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 467 | } |
| 468 | EXPORT_SYMBOL(ieee80211_wake_queues); |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 469 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 470 | void ieee80211_iterate_active_interfaces( |
| 471 | struct ieee80211_hw *hw, |
| 472 | void (*iterator)(void *data, u8 *mac, |
| 473 | struct ieee80211_vif *vif), |
| 474 | void *data) |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 475 | { |
| 476 | struct ieee80211_local *local = hw_to_local(hw); |
| 477 | struct ieee80211_sub_if_data *sdata; |
| 478 | |
Johannes Berg | c771c9d | 2009-01-23 22:54:03 +0100 | [diff] [blame] | 479 | mutex_lock(&local->iflist_mtx); |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 480 | |
| 481 | list_for_each_entry(sdata, &local->interfaces, list) { |
| 482 | switch (sdata->vif.type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 483 | case NL80211_IFTYPE_MONITOR: |
| 484 | case NL80211_IFTYPE_AP_VLAN: |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 485 | continue; |
Johannes Berg | 2ca27bc | 2010-09-16 14:58:23 +0200 | [diff] [blame] | 486 | default: |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 487 | break; |
| 488 | } |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 489 | if (ieee80211_sdata_running(sdata)) |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 490 | iterator(data, sdata->vif.addr, |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 491 | &sdata->vif); |
| 492 | } |
| 493 | |
Johannes Berg | c771c9d | 2009-01-23 22:54:03 +0100 | [diff] [blame] | 494 | mutex_unlock(&local->iflist_mtx); |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 495 | } |
| 496 | EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces); |
| 497 | |
| 498 | void ieee80211_iterate_active_interfaces_atomic( |
| 499 | struct ieee80211_hw *hw, |
| 500 | void (*iterator)(void *data, u8 *mac, |
| 501 | struct ieee80211_vif *vif), |
| 502 | void *data) |
| 503 | { |
| 504 | struct ieee80211_local *local = hw_to_local(hw); |
| 505 | struct ieee80211_sub_if_data *sdata; |
| 506 | |
Johannes Berg | e38bad4 | 2007-11-28 10:55:32 +0100 | [diff] [blame] | 507 | rcu_read_lock(); |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 508 | |
Johannes Berg | e38bad4 | 2007-11-28 10:55:32 +0100 | [diff] [blame] | 509 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 510 | switch (sdata->vif.type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 511 | case NL80211_IFTYPE_MONITOR: |
| 512 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 513 | continue; |
Johannes Berg | 2ca27bc | 2010-09-16 14:58:23 +0200 | [diff] [blame] | 514 | default: |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 515 | break; |
| 516 | } |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 517 | if (ieee80211_sdata_running(sdata)) |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 518 | iterator(data, sdata->vif.addr, |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 519 | &sdata->vif); |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 520 | } |
Johannes Berg | e38bad4 | 2007-11-28 10:55:32 +0100 | [diff] [blame] | 521 | |
| 522 | rcu_read_unlock(); |
Johannes Berg | dabeb34 | 2007-11-09 01:57:29 +0100 | [diff] [blame] | 523 | } |
Ivo van Doorn | 2f561fe | 2008-05-10 13:40:49 +0200 | [diff] [blame] | 524 | EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic); |
Johannes Berg | 37ffc8d | 2008-09-08 16:40:36 +0200 | [diff] [blame] | 525 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 526 | /* |
| 527 | * Nothing should have been stuffed into the workqueue during |
| 528 | * the suspend->resume cycle. If this WARN is seen then there |
| 529 | * is a bug with either the driver suspend or something in |
| 530 | * mac80211 stuffing into the workqueue which we haven't yet |
| 531 | * cleared during mac80211's suspend cycle. |
| 532 | */ |
| 533 | static bool ieee80211_can_queue_work(struct ieee80211_local *local) |
| 534 | { |
Johannes Berg | ceb99fe | 2009-11-19 14:29:39 +0100 | [diff] [blame] | 535 | if (WARN(local->suspended && !local->resuming, |
| 536 | "queueing ieee80211 work while going to suspend\n")) |
| 537 | return false; |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 538 | |
| 539 | return true; |
| 540 | } |
| 541 | |
| 542 | void ieee80211_queue_work(struct ieee80211_hw *hw, struct work_struct *work) |
| 543 | { |
| 544 | struct ieee80211_local *local = hw_to_local(hw); |
| 545 | |
| 546 | if (!ieee80211_can_queue_work(local)) |
| 547 | return; |
| 548 | |
| 549 | queue_work(local->workqueue, work); |
| 550 | } |
| 551 | EXPORT_SYMBOL(ieee80211_queue_work); |
| 552 | |
| 553 | void ieee80211_queue_delayed_work(struct ieee80211_hw *hw, |
| 554 | struct delayed_work *dwork, |
| 555 | unsigned long delay) |
| 556 | { |
| 557 | struct ieee80211_local *local = hw_to_local(hw); |
| 558 | |
| 559 | if (!ieee80211_can_queue_work(local)) |
| 560 | return; |
| 561 | |
| 562 | queue_delayed_work(local->workqueue, dwork, delay); |
| 563 | } |
| 564 | EXPORT_SYMBOL(ieee80211_queue_delayed_work); |
| 565 | |
Johannes Berg | 37ffc8d | 2008-09-08 16:40:36 +0200 | [diff] [blame] | 566 | void ieee802_11_parse_elems(u8 *start, size_t len, |
| 567 | struct ieee802_11_elems *elems) |
| 568 | { |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 569 | ieee802_11_parse_elems_crc(start, len, elems, 0, 0); |
| 570 | } |
| 571 | |
Johannes Berg | 5825fe1 | 2008-09-09 12:56:01 +0200 | [diff] [blame] | 572 | void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata) |
| 573 | { |
| 574 | struct ieee80211_local *local = sdata->local; |
| 575 | struct ieee80211_tx_queue_params qparam; |
Johannes Berg | aa837e1 | 2009-05-07 16:16:24 +0200 | [diff] [blame] | 576 | int queue; |
| 577 | bool use_11b; |
| 578 | int aCWmin, aCWmax; |
Johannes Berg | 5825fe1 | 2008-09-09 12:56:01 +0200 | [diff] [blame] | 579 | |
| 580 | if (!local->ops->conf_tx) |
| 581 | return; |
| 582 | |
| 583 | memset(&qparam, 0, sizeof(qparam)); |
| 584 | |
Johannes Berg | aa837e1 | 2009-05-07 16:16:24 +0200 | [diff] [blame] | 585 | use_11b = (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) && |
| 586 | !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE); |
Johannes Berg | 5825fe1 | 2008-09-09 12:56:01 +0200 | [diff] [blame] | 587 | |
Johannes Berg | aa837e1 | 2009-05-07 16:16:24 +0200 | [diff] [blame] | 588 | for (queue = 0; queue < local_to_hw(local)->queues; queue++) { |
| 589 | /* Set defaults according to 802.11-2007 Table 7-37 */ |
| 590 | aCWmax = 1023; |
| 591 | if (use_11b) |
| 592 | aCWmin = 31; |
| 593 | else |
| 594 | aCWmin = 15; |
Johannes Berg | 5825fe1 | 2008-09-09 12:56:01 +0200 | [diff] [blame] | 595 | |
Johannes Berg | aa837e1 | 2009-05-07 16:16:24 +0200 | [diff] [blame] | 596 | switch (queue) { |
| 597 | case 3: /* AC_BK */ |
Johannes Berg | 7ba10a8 | 2009-05-27 09:41:06 +0200 | [diff] [blame] | 598 | qparam.cw_max = aCWmax; |
| 599 | qparam.cw_min = aCWmin; |
Johannes Berg | aa837e1 | 2009-05-07 16:16:24 +0200 | [diff] [blame] | 600 | qparam.txop = 0; |
| 601 | qparam.aifs = 7; |
| 602 | break; |
| 603 | default: /* never happens but let's not leave undefined */ |
| 604 | case 2: /* AC_BE */ |
Johannes Berg | 7ba10a8 | 2009-05-27 09:41:06 +0200 | [diff] [blame] | 605 | qparam.cw_max = aCWmax; |
| 606 | qparam.cw_min = aCWmin; |
Johannes Berg | aa837e1 | 2009-05-07 16:16:24 +0200 | [diff] [blame] | 607 | qparam.txop = 0; |
| 608 | qparam.aifs = 3; |
| 609 | break; |
| 610 | case 1: /* AC_VI */ |
| 611 | qparam.cw_max = aCWmin; |
| 612 | qparam.cw_min = (aCWmin + 1) / 2 - 1; |
| 613 | if (use_11b) |
| 614 | qparam.txop = 6016/32; |
| 615 | else |
| 616 | qparam.txop = 3008/32; |
| 617 | qparam.aifs = 2; |
| 618 | break; |
| 619 | case 0: /* AC_VO */ |
| 620 | qparam.cw_max = (aCWmin + 1) / 2 - 1; |
| 621 | qparam.cw_min = (aCWmin + 1) / 4 - 1; |
| 622 | if (use_11b) |
| 623 | qparam.txop = 3264/32; |
| 624 | else |
| 625 | qparam.txop = 1504/32; |
| 626 | qparam.aifs = 2; |
| 627 | break; |
| 628 | } |
Johannes Berg | 5825fe1 | 2008-09-09 12:56:01 +0200 | [diff] [blame] | 629 | |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 630 | qparam.uapsd = false; |
| 631 | |
Eliad Peller | f6f3def | 2011-09-25 20:06:54 +0300 | [diff] [blame] | 632 | sdata->tx_conf[queue] = qparam; |
| 633 | drv_conf_tx(local, sdata, queue, &qparam); |
Johannes Berg | aa837e1 | 2009-05-07 16:16:24 +0200 | [diff] [blame] | 634 | } |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 635 | |
| 636 | /* after reinitialize QoS TX queues setting to default, |
| 637 | * disable QoS at all */ |
Sujith | d973497 | 2010-07-23 10:47:11 +0530 | [diff] [blame] | 638 | |
| 639 | if (sdata->vif.type != NL80211_IFTYPE_MONITOR) { |
| 640 | sdata->vif.bss_conf.qos = |
| 641 | sdata->vif.type != NL80211_IFTYPE_STATION; |
| 642 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS); |
| 643 | } |
Johannes Berg | 5825fe1 | 2008-09-09 12:56:01 +0200 | [diff] [blame] | 644 | } |
Johannes Berg | e50db65 | 2008-09-09 15:07:09 +0200 | [diff] [blame] | 645 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 646 | void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata, |
| 647 | const size_t supp_rates_len, |
| 648 | const u8 *supp_rates) |
| 649 | { |
| 650 | struct ieee80211_local *local = sdata->local; |
| 651 | int i, have_higher_than_11mbit = 0; |
| 652 | |
| 653 | /* cf. IEEE 802.11 9.2.12 */ |
| 654 | for (i = 0; i < supp_rates_len; i++) |
| 655 | if ((supp_rates[i] & 0x7f) * 5 > 110) |
| 656 | have_higher_than_11mbit = 1; |
| 657 | |
| 658 | if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ && |
| 659 | have_higher_than_11mbit) |
| 660 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; |
| 661 | else |
| 662 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; |
| 663 | |
| 664 | ieee80211_set_wmm_default(sdata); |
| 665 | } |
| 666 | |
Johannes Berg | 881d948 | 2009-01-21 15:13:48 +0100 | [diff] [blame] | 667 | u32 ieee80211_mandatory_rates(struct ieee80211_local *local, |
Johannes Berg | 96dd22a | 2008-09-11 00:01:57 +0200 | [diff] [blame] | 668 | enum ieee80211_band band) |
| 669 | { |
| 670 | struct ieee80211_supported_band *sband; |
| 671 | struct ieee80211_rate *bitrates; |
Johannes Berg | 881d948 | 2009-01-21 15:13:48 +0100 | [diff] [blame] | 672 | u32 mandatory_rates; |
Johannes Berg | 96dd22a | 2008-09-11 00:01:57 +0200 | [diff] [blame] | 673 | enum ieee80211_rate_flags mandatory_flag; |
| 674 | int i; |
| 675 | |
| 676 | sband = local->hw.wiphy->bands[band]; |
| 677 | if (!sband) { |
| 678 | WARN_ON(1); |
| 679 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 680 | } |
| 681 | |
| 682 | if (band == IEEE80211_BAND_2GHZ) |
| 683 | mandatory_flag = IEEE80211_RATE_MANDATORY_B; |
| 684 | else |
| 685 | mandatory_flag = IEEE80211_RATE_MANDATORY_A; |
| 686 | |
| 687 | bitrates = sband->bitrates; |
| 688 | mandatory_rates = 0; |
| 689 | for (i = 0; i < sband->n_bitrates; i++) |
| 690 | if (bitrates[i].flags & mandatory_flag) |
| 691 | mandatory_rates |= BIT(i); |
| 692 | return mandatory_rates; |
| 693 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 694 | |
| 695 | void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata, |
| 696 | u16 transaction, u16 auth_alg, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 697 | u8 *extra, size_t extra_len, const u8 *bssid, |
| 698 | const u8 *key, u8 key_len, u8 key_idx) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 699 | { |
| 700 | struct ieee80211_local *local = sdata->local; |
| 701 | struct sk_buff *skb; |
| 702 | struct ieee80211_mgmt *mgmt; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 703 | int err; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 704 | |
| 705 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + |
Jouni Malinen | 65fc73a | 2009-03-20 21:21:16 +0200 | [diff] [blame] | 706 | sizeof(*mgmt) + 6 + extra_len); |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 707 | if (!skb) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 708 | return; |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 709 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 710 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 711 | |
| 712 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6); |
| 713 | memset(mgmt, 0, 24 + 6); |
| 714 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 715 | IEEE80211_STYPE_AUTH); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 716 | memcpy(mgmt->da, bssid, ETH_ALEN); |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 717 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 718 | memcpy(mgmt->bssid, bssid, ETH_ALEN); |
| 719 | mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg); |
| 720 | mgmt->u.auth.auth_transaction = cpu_to_le16(transaction); |
| 721 | mgmt->u.auth.status_code = cpu_to_le16(0); |
| 722 | if (extra) |
| 723 | memcpy(skb_put(skb, extra_len), extra, extra_len); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 724 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 725 | if (auth_alg == WLAN_AUTH_SHARED_KEY && transaction == 3) { |
| 726 | mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
| 727 | err = ieee80211_wep_encrypt(local, skb, key, key_len, key_idx); |
| 728 | WARN_ON(err); |
| 729 | } |
| 730 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 731 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 732 | ieee80211_tx_skb(sdata, skb); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 733 | } |
| 734 | |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 735 | int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer, |
Johannes Berg | 4d36ec5 | 2009-10-27 20:59:55 +0100 | [diff] [blame] | 736 | const u8 *ie, size_t ie_len, |
Jouni Malinen | 651b522 | 2010-08-28 19:37:51 +0300 | [diff] [blame] | 737 | enum ieee80211_band band, u32 rate_mask, |
| 738 | u8 channel) |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 739 | { |
| 740 | struct ieee80211_supported_band *sband; |
Johannes Berg | 8e664fb | 2009-12-23 13:15:38 +0100 | [diff] [blame] | 741 | u8 *pos; |
| 742 | size_t offset = 0, noffset; |
| 743 | int supp_rates_len, i; |
Jouni Malinen | 8dcb200 | 2010-08-28 19:36:10 +0300 | [diff] [blame] | 744 | u8 rates[32]; |
| 745 | int num_rates; |
| 746 | int ext_rates_len; |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 747 | |
Johannes Berg | 4d36ec5 | 2009-10-27 20:59:55 +0100 | [diff] [blame] | 748 | sband = local->hw.wiphy->bands[band]; |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 749 | |
| 750 | pos = buffer; |
| 751 | |
Jouni Malinen | 8dcb200 | 2010-08-28 19:36:10 +0300 | [diff] [blame] | 752 | num_rates = 0; |
| 753 | for (i = 0; i < sband->n_bitrates; i++) { |
| 754 | if ((BIT(i) & rate_mask) == 0) |
| 755 | continue; /* skip rate */ |
| 756 | rates[num_rates++] = (u8) (sband->bitrates[i].bitrate / 5); |
| 757 | } |
| 758 | |
| 759 | supp_rates_len = min_t(int, num_rates, 8); |
Johannes Berg | 8e664fb | 2009-12-23 13:15:38 +0100 | [diff] [blame] | 760 | |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 761 | *pos++ = WLAN_EID_SUPP_RATES; |
Johannes Berg | 8e664fb | 2009-12-23 13:15:38 +0100 | [diff] [blame] | 762 | *pos++ = supp_rates_len; |
Jouni Malinen | 8dcb200 | 2010-08-28 19:36:10 +0300 | [diff] [blame] | 763 | memcpy(pos, rates, supp_rates_len); |
| 764 | pos += supp_rates_len; |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 765 | |
Johannes Berg | 8e664fb | 2009-12-23 13:15:38 +0100 | [diff] [blame] | 766 | /* insert "request information" if in custom IEs */ |
| 767 | if (ie && ie_len) { |
| 768 | static const u8 before_extrates[] = { |
| 769 | WLAN_EID_SSID, |
| 770 | WLAN_EID_SUPP_RATES, |
| 771 | WLAN_EID_REQUEST, |
| 772 | }; |
| 773 | noffset = ieee80211_ie_split(ie, ie_len, |
| 774 | before_extrates, |
| 775 | ARRAY_SIZE(before_extrates), |
| 776 | offset); |
| 777 | memcpy(pos, ie + offset, noffset - offset); |
| 778 | pos += noffset - offset; |
| 779 | offset = noffset; |
| 780 | } |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 781 | |
Jouni Malinen | 8dcb200 | 2010-08-28 19:36:10 +0300 | [diff] [blame] | 782 | ext_rates_len = num_rates - supp_rates_len; |
| 783 | if (ext_rates_len > 0) { |
Johannes Berg | 8e664fb | 2009-12-23 13:15:38 +0100 | [diff] [blame] | 784 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
Jouni Malinen | 8dcb200 | 2010-08-28 19:36:10 +0300 | [diff] [blame] | 785 | *pos++ = ext_rates_len; |
| 786 | memcpy(pos, rates + supp_rates_len, ext_rates_len); |
| 787 | pos += ext_rates_len; |
Johannes Berg | 8e664fb | 2009-12-23 13:15:38 +0100 | [diff] [blame] | 788 | } |
| 789 | |
Jouni Malinen | 651b522 | 2010-08-28 19:37:51 +0300 | [diff] [blame] | 790 | if (channel && sband->band == IEEE80211_BAND_2GHZ) { |
| 791 | *pos++ = WLAN_EID_DS_PARAMS; |
| 792 | *pos++ = 1; |
| 793 | *pos++ = channel; |
| 794 | } |
| 795 | |
Johannes Berg | 8e664fb | 2009-12-23 13:15:38 +0100 | [diff] [blame] | 796 | /* insert custom IEs that go before HT */ |
| 797 | if (ie && ie_len) { |
| 798 | static const u8 before_ht[] = { |
| 799 | WLAN_EID_SSID, |
| 800 | WLAN_EID_SUPP_RATES, |
| 801 | WLAN_EID_REQUEST, |
| 802 | WLAN_EID_EXT_SUPP_RATES, |
| 803 | WLAN_EID_DS_PARAMS, |
| 804 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, |
| 805 | }; |
| 806 | noffset = ieee80211_ie_split(ie, ie_len, |
| 807 | before_ht, ARRAY_SIZE(before_ht), |
| 808 | offset); |
| 809 | memcpy(pos, ie + offset, noffset - offset); |
| 810 | pos += noffset - offset; |
| 811 | offset = noffset; |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 812 | } |
| 813 | |
Johannes Berg | 5ef2d41 | 2009-03-31 12:12:07 +0200 | [diff] [blame] | 814 | if (sband->ht_cap.ht_supported) { |
Johannes Berg | f38fd12 | 2009-12-01 18:29:42 +0100 | [diff] [blame] | 815 | u16 cap = sband->ht_cap.cap; |
| 816 | __le16 tmp; |
| 817 | |
Johannes Berg | 5ef2d41 | 2009-03-31 12:12:07 +0200 | [diff] [blame] | 818 | *pos++ = WLAN_EID_HT_CAPABILITY; |
| 819 | *pos++ = sizeof(struct ieee80211_ht_cap); |
| 820 | memset(pos, 0, sizeof(struct ieee80211_ht_cap)); |
Johannes Berg | f38fd12 | 2009-12-01 18:29:42 +0100 | [diff] [blame] | 821 | tmp = cpu_to_le16(cap); |
Johannes Berg | 5ef2d41 | 2009-03-31 12:12:07 +0200 | [diff] [blame] | 822 | memcpy(pos, &tmp, sizeof(u16)); |
| 823 | pos += sizeof(u16); |
Johannes Berg | 5ef2d41 | 2009-03-31 12:12:07 +0200 | [diff] [blame] | 824 | *pos++ = sband->ht_cap.ampdu_factor | |
Johannes Berg | f38fd12 | 2009-12-01 18:29:42 +0100 | [diff] [blame] | 825 | (sband->ht_cap.ampdu_density << |
| 826 | IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT); |
Johannes Berg | 5ef2d41 | 2009-03-31 12:12:07 +0200 | [diff] [blame] | 827 | memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs)); |
| 828 | pos += sizeof(sband->ht_cap.mcs); |
| 829 | pos += 2 + 4 + 1; /* ext info, BF cap, antsel */ |
| 830 | } |
| 831 | |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 832 | /* |
| 833 | * If adding more here, adjust code in main.c |
| 834 | * that calculates local->scan_ies_len. |
| 835 | */ |
| 836 | |
Johannes Berg | 8e664fb | 2009-12-23 13:15:38 +0100 | [diff] [blame] | 837 | /* add any remaining custom IEs */ |
| 838 | if (ie && ie_len) { |
| 839 | noffset = ie_len; |
| 840 | memcpy(pos, ie + offset, noffset - offset); |
| 841 | pos += noffset - offset; |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | return pos - buffer; |
| 845 | } |
| 846 | |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 847 | struct sk_buff *ieee80211_build_probe_req(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 85a237f | 2011-07-18 18:08:36 +0200 | [diff] [blame] | 848 | u8 *dst, u32 ratemask, |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 849 | const u8 *ssid, size_t ssid_len, |
Paul Stewart | a806c55 | 2011-06-23 09:00:11 -0800 | [diff] [blame] | 850 | const u8 *ie, size_t ie_len, |
| 851 | bool directed) |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 852 | { |
| 853 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 854 | struct sk_buff *skb; |
| 855 | struct ieee80211_mgmt *mgmt; |
Kalle Valo | 7c12ce8 | 2010-01-05 20:16:44 +0200 | [diff] [blame] | 856 | size_t buf_len; |
| 857 | u8 *buf; |
Jouni Malinen | 651b522 | 2010-08-28 19:37:51 +0300 | [diff] [blame] | 858 | u8 chan; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 859 | |
Kalle Valo | 7c12ce8 | 2010-01-05 20:16:44 +0200 | [diff] [blame] | 860 | /* FIXME: come up with a proper value */ |
| 861 | buf = kmalloc(200 + ie_len, GFP_KERNEL); |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 862 | if (!buf) |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 863 | return NULL; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 864 | |
Paul Stewart | a806c55 | 2011-06-23 09:00:11 -0800 | [diff] [blame] | 865 | /* |
| 866 | * Do not send DS Channel parameter for directed probe requests |
| 867 | * in order to maximize the chance that we get a response. Some |
| 868 | * badly-behaved APs don't respond when this parameter is included. |
| 869 | */ |
| 870 | if (directed) |
| 871 | chan = 0; |
| 872 | else |
| 873 | chan = ieee80211_frequency_to_channel( |
| 874 | local->hw.conf.channel->center_freq); |
Jouni Malinen | 651b522 | 2010-08-28 19:37:51 +0300 | [diff] [blame] | 875 | |
Kalle Valo | 7c12ce8 | 2010-01-05 20:16:44 +0200 | [diff] [blame] | 876 | buf_len = ieee80211_build_preq_ies(local, buf, ie, ie_len, |
Jouni Malinen | 8dcb200 | 2010-08-28 19:36:10 +0300 | [diff] [blame] | 877 | local->hw.conf.channel->band, |
Johannes Berg | 85a237f | 2011-07-18 18:08:36 +0200 | [diff] [blame] | 878 | ratemask, chan); |
Kalle Valo | 7c12ce8 | 2010-01-05 20:16:44 +0200 | [diff] [blame] | 879 | |
| 880 | skb = ieee80211_probereq_get(&local->hw, &sdata->vif, |
| 881 | ssid, ssid_len, |
| 882 | buf, buf_len); |
| 883 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 884 | if (dst) { |
Kalle Valo | 7c12ce8 | 2010-01-05 20:16:44 +0200 | [diff] [blame] | 885 | mgmt = (struct ieee80211_mgmt *) skb->data; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 886 | memcpy(mgmt->da, dst, ETH_ALEN); |
| 887 | memcpy(mgmt->bssid, dst, ETH_ALEN); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 888 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 889 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 890 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
Ming Lei | 145b6d1 | 2010-01-15 21:44:21 +0800 | [diff] [blame] | 891 | kfree(buf); |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 892 | |
| 893 | return skb; |
| 894 | } |
| 895 | |
| 896 | void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst, |
| 897 | const u8 *ssid, size_t ssid_len, |
Paul Stewart | a806c55 | 2011-06-23 09:00:11 -0800 | [diff] [blame] | 898 | const u8 *ie, size_t ie_len, |
Rajkumar Manoharan | aad14ce | 2011-09-25 14:53:31 +0530 | [diff] [blame] | 899 | u32 ratemask, bool directed, bool no_cck) |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 900 | { |
| 901 | struct sk_buff *skb; |
| 902 | |
Johannes Berg | 85a237f | 2011-07-18 18:08:36 +0200 | [diff] [blame] | 903 | skb = ieee80211_build_probe_req(sdata, dst, ratemask, ssid, ssid_len, |
| 904 | ie, ie_len, directed); |
Rajkumar Manoharan | aad14ce | 2011-09-25 14:53:31 +0530 | [diff] [blame] | 905 | if (skb) { |
| 906 | if (no_cck) |
| 907 | IEEE80211_SKB_CB(skb)->flags |= |
| 908 | IEEE80211_TX_CTL_NO_CCK_RATE; |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 909 | ieee80211_tx_skb(sdata, skb); |
Rajkumar Manoharan | aad14ce | 2011-09-25 14:53:31 +0530 | [diff] [blame] | 910 | } |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | u32 ieee80211_sta_get_rates(struct ieee80211_local *local, |
| 914 | struct ieee802_11_elems *elems, |
| 915 | enum ieee80211_band band) |
| 916 | { |
| 917 | struct ieee80211_supported_band *sband; |
| 918 | struct ieee80211_rate *bitrates; |
| 919 | size_t num_rates; |
| 920 | u32 supp_rates; |
| 921 | int i, j; |
| 922 | sband = local->hw.wiphy->bands[band]; |
| 923 | |
| 924 | if (!sband) { |
| 925 | WARN_ON(1); |
| 926 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 927 | } |
| 928 | |
| 929 | bitrates = sband->bitrates; |
| 930 | num_rates = sband->n_bitrates; |
| 931 | supp_rates = 0; |
| 932 | for (i = 0; i < elems->supp_rates_len + |
| 933 | elems->ext_supp_rates_len; i++) { |
| 934 | u8 rate = 0; |
| 935 | int own_rate; |
| 936 | if (i < elems->supp_rates_len) |
| 937 | rate = elems->supp_rates[i]; |
| 938 | else if (elems->ext_supp_rates) |
| 939 | rate = elems->ext_supp_rates |
| 940 | [i - elems->supp_rates_len]; |
| 941 | own_rate = 5 * (rate & 0x7f); |
| 942 | for (j = 0; j < num_rates; j++) |
| 943 | if (bitrates[j].bitrate == own_rate) |
| 944 | supp_rates |= BIT(j); |
| 945 | } |
| 946 | return supp_rates; |
| 947 | } |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 948 | |
Johannes Berg | 84f6a01 | 2009-08-20 20:02:20 +0200 | [diff] [blame] | 949 | void ieee80211_stop_device(struct ieee80211_local *local) |
| 950 | { |
| 951 | ieee80211_led_radio(local, false); |
Johannes Berg | 67408c8 | 2010-11-30 08:59:23 +0100 | [diff] [blame] | 952 | ieee80211_mod_tpt_led_trig(local, 0, IEEE80211_TPT_LEDTRIG_FL_RADIO); |
Johannes Berg | 84f6a01 | 2009-08-20 20:02:20 +0200 | [diff] [blame] | 953 | |
| 954 | cancel_work_sync(&local->reconfig_filter); |
Johannes Berg | 84f6a01 | 2009-08-20 20:02:20 +0200 | [diff] [blame] | 955 | |
| 956 | flush_workqueue(local->workqueue); |
Lennert Buytenhek | 678f415 | 2010-01-10 14:07:53 +0100 | [diff] [blame] | 957 | drv_stop(local); |
Johannes Berg | 84f6a01 | 2009-08-20 20:02:20 +0200 | [diff] [blame] | 958 | } |
| 959 | |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 960 | int ieee80211_reconfig(struct ieee80211_local *local) |
| 961 | { |
| 962 | struct ieee80211_hw *hw = &local->hw; |
| 963 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 964 | struct sta_info *sta; |
Eliad Peller | 2683d65 | 2011-07-14 20:29:42 +0300 | [diff] [blame] | 965 | int res, i; |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 966 | |
Johannes Berg | eecc480 | 2011-05-04 15:37:29 +0200 | [diff] [blame] | 967 | #ifdef CONFIG_PM |
Johannes Berg | ceb99fe | 2009-11-19 14:29:39 +0100 | [diff] [blame] | 968 | if (local->suspended) |
| 969 | local->resuming = true; |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 970 | |
Johannes Berg | eecc480 | 2011-05-04 15:37:29 +0200 | [diff] [blame] | 971 | if (local->wowlan) { |
| 972 | local->wowlan = false; |
| 973 | res = drv_resume(local); |
| 974 | if (res < 0) { |
| 975 | local->resuming = false; |
| 976 | return res; |
| 977 | } |
| 978 | if (res == 0) |
| 979 | goto wake_up; |
| 980 | WARN_ON(res > 1); |
| 981 | /* |
| 982 | * res is 1, which means the driver requested |
| 983 | * to go through a regular reset on wakeup. |
| 984 | */ |
| 985 | } |
| 986 | #endif |
| 987 | |
Johannes Berg | 94f9b97 | 2011-07-14 16:48:54 +0200 | [diff] [blame] | 988 | /* setup fragmentation threshold */ |
| 989 | drv_set_frag_threshold(local, hw->wiphy->frag_threshold); |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 990 | |
Johannes Berg | 94f9b97 | 2011-07-14 16:48:54 +0200 | [diff] [blame] | 991 | /* setup RTS threshold */ |
| 992 | drv_set_rts_threshold(local, hw->wiphy->rts_threshold); |
| 993 | |
| 994 | /* reset coverage class */ |
| 995 | drv_set_coverage_class(local, hw->wiphy->coverage_class); |
| 996 | |
| 997 | /* everything else happens only if HW was up & running */ |
| 998 | if (!local->open_count) |
| 999 | goto wake_up; |
| 1000 | |
| 1001 | /* |
| 1002 | * Upon resume hardware can sometimes be goofy due to |
| 1003 | * various platform / driver / bus issues, so restarting |
| 1004 | * the device may at times not work immediately. Propagate |
| 1005 | * the error. |
| 1006 | */ |
| 1007 | res = drv_start(local); |
| 1008 | if (res) { |
| 1009 | WARN(local->suspended, "Hardware became unavailable " |
| 1010 | "upon resume. This could be a software issue " |
| 1011 | "prior to suspend or a hardware issue.\n"); |
| 1012 | return res; |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1013 | } |
| 1014 | |
Johannes Berg | 94f9b97 | 2011-07-14 16:48:54 +0200 | [diff] [blame] | 1015 | ieee80211_led_radio(local, true); |
| 1016 | ieee80211_mod_tpt_led_trig(local, |
| 1017 | IEEE80211_TPT_LEDTRIG_FL_RADIO, 0); |
| 1018 | |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1019 | /* add interfaces */ |
| 1020 | list_for_each_entry(sdata, &local->interfaces, list) { |
| 1021 | if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
| 1022 | sdata->vif.type != NL80211_IFTYPE_MONITOR && |
Johannes Berg | 1ed32e4 | 2009-12-23 13:15:45 +0100 | [diff] [blame] | 1023 | ieee80211_sdata_running(sdata)) |
| 1024 | res = drv_add_interface(local, &sdata->vif); |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | /* add STAs back */ |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 1028 | mutex_lock(&local->sta_mtx); |
| 1029 | list_for_each_entry(sta, &local->sta_list, list) { |
| 1030 | if (sta->uploaded) { |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 1031 | sdata = sta->sdata; |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1032 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
| 1033 | sdata = container_of(sdata->bss, |
| 1034 | struct ieee80211_sub_if_data, |
| 1035 | u.ap); |
| 1036 | |
Eliad Peller | f785d83 | 2011-08-08 16:50:22 +0300 | [diff] [blame] | 1037 | memset(&sta->sta.drv_priv, 0, hw->sta_data_size); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 1038 | WARN_ON(drv_sta_add(local, sdata, &sta->sta)); |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1039 | } |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1040 | } |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 1041 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1042 | |
Eliad Peller | 2683d65 | 2011-07-14 20:29:42 +0300 | [diff] [blame] | 1043 | /* reconfigure tx conf */ |
Eliad Peller | f6f3def | 2011-09-25 20:06:54 +0300 | [diff] [blame] | 1044 | list_for_each_entry(sdata, &local->interfaces, list) { |
| 1045 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN || |
| 1046 | sdata->vif.type == NL80211_IFTYPE_MONITOR || |
| 1047 | !ieee80211_sdata_running(sdata)) |
| 1048 | continue; |
| 1049 | |
| 1050 | for (i = 0; i < hw->queues; i++) |
| 1051 | drv_conf_tx(local, sdata, i, &sdata->tx_conf[i]); |
| 1052 | } |
Eliad Peller | 2683d65 | 2011-07-14 20:29:42 +0300 | [diff] [blame] | 1053 | |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1054 | /* reconfigure hardware */ |
| 1055 | ieee80211_hw_config(local, ~0); |
| 1056 | |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1057 | ieee80211_configure_filter(local); |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1058 | |
| 1059 | /* Finally also reconfigure all the BSS information */ |
| 1060 | list_for_each_entry(sdata, &local->interfaces, list) { |
Johannes Berg | ac8dd50 | 2010-05-05 09:44:02 +0200 | [diff] [blame] | 1061 | u32 changed; |
| 1062 | |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 1063 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1064 | continue; |
Johannes Berg | ac8dd50 | 2010-05-05 09:44:02 +0200 | [diff] [blame] | 1065 | |
| 1066 | /* common change flags for all interface types */ |
| 1067 | changed = BSS_CHANGED_ERP_CTS_PROT | |
| 1068 | BSS_CHANGED_ERP_PREAMBLE | |
| 1069 | BSS_CHANGED_ERP_SLOT | |
| 1070 | BSS_CHANGED_HT | |
| 1071 | BSS_CHANGED_BASIC_RATES | |
| 1072 | BSS_CHANGED_BEACON_INT | |
| 1073 | BSS_CHANGED_BSSID | |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 1074 | BSS_CHANGED_CQM | |
| 1075 | BSS_CHANGED_QOS; |
Johannes Berg | ac8dd50 | 2010-05-05 09:44:02 +0200 | [diff] [blame] | 1076 | |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1077 | switch (sdata->vif.type) { |
| 1078 | case NL80211_IFTYPE_STATION: |
Johannes Berg | ac8dd50 | 2010-05-05 09:44:02 +0200 | [diff] [blame] | 1079 | changed |= BSS_CHANGED_ASSOC; |
Eliad Peller | a7b545f | 2011-02-08 18:43:19 +0200 | [diff] [blame] | 1080 | mutex_lock(&sdata->u.mgd.mtx); |
Johannes Berg | ac8dd50 | 2010-05-05 09:44:02 +0200 | [diff] [blame] | 1081 | ieee80211_bss_info_change_notify(sdata, changed); |
Eliad Peller | a7b545f | 2011-02-08 18:43:19 +0200 | [diff] [blame] | 1082 | mutex_unlock(&sdata->u.mgd.mtx); |
Johannes Berg | ac8dd50 | 2010-05-05 09:44:02 +0200 | [diff] [blame] | 1083 | break; |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1084 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | ac8dd50 | 2010-05-05 09:44:02 +0200 | [diff] [blame] | 1085 | changed |= BSS_CHANGED_IBSS; |
| 1086 | /* fall through */ |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1087 | case NL80211_IFTYPE_AP: |
Arik Nemtsov | 7827493 | 2011-09-04 11:11:32 +0300 | [diff] [blame] | 1088 | changed |= BSS_CHANGED_SSID; |
| 1089 | /* fall through */ |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1090 | case NL80211_IFTYPE_MESH_POINT: |
Johannes Berg | ac8dd50 | 2010-05-05 09:44:02 +0200 | [diff] [blame] | 1091 | changed |= BSS_CHANGED_BEACON | |
| 1092 | BSS_CHANGED_BEACON_ENABLED; |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1093 | ieee80211_bss_info_change_notify(sdata, changed); |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1094 | break; |
| 1095 | case NL80211_IFTYPE_WDS: |
| 1096 | break; |
| 1097 | case NL80211_IFTYPE_AP_VLAN: |
| 1098 | case NL80211_IFTYPE_MONITOR: |
| 1099 | /* ignore virtual */ |
| 1100 | break; |
| 1101 | case NL80211_IFTYPE_UNSPECIFIED: |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 1102 | case NUM_NL80211_IFTYPES: |
Johannes Berg | 2ca27bc | 2010-09-16 14:58:23 +0200 | [diff] [blame] | 1103 | case NL80211_IFTYPE_P2P_CLIENT: |
| 1104 | case NL80211_IFTYPE_P2P_GO: |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1105 | WARN_ON(1); |
| 1106 | break; |
| 1107 | } |
| 1108 | } |
| 1109 | |
Johannes Berg | 2a41905 | 2010-06-10 10:21:29 +0200 | [diff] [blame] | 1110 | /* |
| 1111 | * Clear the WLAN_STA_BLOCK_BA flag so new aggregation |
| 1112 | * sessions can be established after a resume. |
| 1113 | * |
| 1114 | * Also tear down aggregation sessions since reconfiguring |
| 1115 | * them in a hardware restart scenario is not easily done |
| 1116 | * right now, and the hardware will have lost information |
| 1117 | * about the sessions, but we and the AP still think they |
| 1118 | * are active. This is really a workaround though. |
| 1119 | */ |
Wey-Yi Guy | 74e2bd1 | 2010-02-03 09:28:55 -0800 | [diff] [blame] | 1120 | if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) { |
Johannes Berg | 2a41905 | 2010-06-10 10:21:29 +0200 | [diff] [blame] | 1121 | mutex_lock(&local->sta_mtx); |
| 1122 | |
| 1123 | list_for_each_entry(sta, &local->sta_list, list) { |
Johannes Berg | 53f73c0 | 2010-10-05 19:37:40 +0200 | [diff] [blame] | 1124 | ieee80211_sta_tear_down_BA_sessions(sta, true); |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1125 | clear_sta_flag(sta, WLAN_STA_BLOCK_BA); |
Wey-Yi Guy | 74e2bd1 | 2010-02-03 09:28:55 -0800 | [diff] [blame] | 1126 | } |
Johannes Berg | 2a41905 | 2010-06-10 10:21:29 +0200 | [diff] [blame] | 1127 | |
| 1128 | mutex_unlock(&local->sta_mtx); |
Wey-Yi Guy | 74e2bd1 | 2010-02-03 09:28:55 -0800 | [diff] [blame] | 1129 | } |
Wey-Yi Guy | 74e2bd1 | 2010-02-03 09:28:55 -0800 | [diff] [blame] | 1130 | |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1131 | /* add back keys */ |
| 1132 | list_for_each_entry(sdata, &local->interfaces, list) |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 1133 | if (ieee80211_sdata_running(sdata)) |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1134 | ieee80211_enable_keys(sdata); |
| 1135 | |
Johannes Berg | eecc480 | 2011-05-04 15:37:29 +0200 | [diff] [blame] | 1136 | wake_up: |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1137 | ieee80211_wake_queues_by_reason(hw, |
| 1138 | IEEE80211_QUEUE_STOP_REASON_SUSPEND); |
| 1139 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 1140 | /* |
| 1141 | * If this is for hw restart things are still running. |
| 1142 | * We may want to change that later, however. |
| 1143 | */ |
Johannes Berg | ceb99fe | 2009-11-19 14:29:39 +0100 | [diff] [blame] | 1144 | if (!local->suspended) |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 1145 | return 0; |
| 1146 | |
| 1147 | #ifdef CONFIG_PM |
Johannes Berg | ceb99fe | 2009-11-19 14:29:39 +0100 | [diff] [blame] | 1148 | /* first set suspended false, then resuming */ |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 1149 | local->suspended = false; |
Johannes Berg | ceb99fe | 2009-11-19 14:29:39 +0100 | [diff] [blame] | 1150 | mb(); |
| 1151 | local->resuming = false; |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 1152 | |
| 1153 | list_for_each_entry(sdata, &local->interfaces, list) { |
| 1154 | switch(sdata->vif.type) { |
| 1155 | case NL80211_IFTYPE_STATION: |
| 1156 | ieee80211_sta_restart(sdata); |
| 1157 | break; |
| 1158 | case NL80211_IFTYPE_ADHOC: |
| 1159 | ieee80211_ibss_restart(sdata); |
| 1160 | break; |
| 1161 | case NL80211_IFTYPE_MESH_POINT: |
| 1162 | ieee80211_mesh_restart(sdata); |
| 1163 | break; |
| 1164 | default: |
| 1165 | break; |
| 1166 | } |
| 1167 | } |
| 1168 | |
Johannes Berg | 26d5953 | 2011-04-01 13:52:48 +0200 | [diff] [blame] | 1169 | mod_timer(&local->sta_cleanup, jiffies + 1); |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 1170 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 1171 | mutex_lock(&local->sta_mtx); |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 1172 | list_for_each_entry(sta, &local->sta_list, list) |
| 1173 | mesh_plink_restart(sta); |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 1174 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 1175 | #else |
| 1176 | WARN_ON(1); |
| 1177 | #endif |
Johannes Berg | f2753dd | 2009-04-14 10:09:24 +0200 | [diff] [blame] | 1178 | return 0; |
| 1179 | } |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 1180 | |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 1181 | void ieee80211_resume_disconnect(struct ieee80211_vif *vif) |
| 1182 | { |
| 1183 | struct ieee80211_sub_if_data *sdata; |
| 1184 | struct ieee80211_local *local; |
| 1185 | struct ieee80211_key *key; |
| 1186 | |
| 1187 | if (WARN_ON(!vif)) |
| 1188 | return; |
| 1189 | |
| 1190 | sdata = vif_to_sdata(vif); |
| 1191 | local = sdata->local; |
| 1192 | |
| 1193 | if (WARN_ON(!local->resuming)) |
| 1194 | return; |
| 1195 | |
| 1196 | if (WARN_ON(vif->type != NL80211_IFTYPE_STATION)) |
| 1197 | return; |
| 1198 | |
| 1199 | sdata->flags |= IEEE80211_SDATA_DISCONNECT_RESUME; |
| 1200 | |
| 1201 | mutex_lock(&local->key_mtx); |
| 1202 | list_for_each_entry(key, &sdata->key_list, list) |
| 1203 | key->flags |= KEY_FLAG_TAINTED; |
| 1204 | mutex_unlock(&local->key_mtx); |
| 1205 | } |
| 1206 | EXPORT_SYMBOL_GPL(ieee80211_resume_disconnect); |
| 1207 | |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 1208 | static int check_mgd_smps(struct ieee80211_if_managed *ifmgd, |
| 1209 | enum ieee80211_smps_mode *smps_mode) |
| 1210 | { |
| 1211 | if (ifmgd->associated) { |
| 1212 | *smps_mode = ifmgd->ap_smps; |
| 1213 | |
| 1214 | if (*smps_mode == IEEE80211_SMPS_AUTOMATIC) { |
| 1215 | if (ifmgd->powersave) |
| 1216 | *smps_mode = IEEE80211_SMPS_DYNAMIC; |
| 1217 | else |
| 1218 | *smps_mode = IEEE80211_SMPS_OFF; |
| 1219 | } |
| 1220 | |
| 1221 | return 1; |
| 1222 | } |
| 1223 | |
| 1224 | return 0; |
| 1225 | } |
| 1226 | |
| 1227 | /* must hold iflist_mtx */ |
Johannes Berg | 025e6be | 2010-10-05 10:41:47 +0200 | [diff] [blame] | 1228 | void ieee80211_recalc_smps(struct ieee80211_local *local) |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 1229 | { |
| 1230 | struct ieee80211_sub_if_data *sdata; |
| 1231 | enum ieee80211_smps_mode smps_mode = IEEE80211_SMPS_OFF; |
| 1232 | int count = 0; |
| 1233 | |
Johannes Berg | 46a5eba | 2010-09-15 13:28:15 +0200 | [diff] [blame] | 1234 | lockdep_assert_held(&local->iflist_mtx); |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 1235 | |
| 1236 | /* |
| 1237 | * This function could be improved to handle multiple |
| 1238 | * interfaces better, but right now it makes any |
| 1239 | * non-station interfaces force SM PS to be turned |
| 1240 | * off. If there are multiple station interfaces it |
| 1241 | * could also use the best possible mode, e.g. if |
| 1242 | * one is in static and the other in dynamic then |
| 1243 | * dynamic is ok. |
| 1244 | */ |
| 1245 | |
| 1246 | list_for_each_entry(sdata, &local->interfaces, list) { |
Johannes Berg | 26a5845 | 2010-08-27 12:35:55 +0200 | [diff] [blame] | 1247 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 1248 | continue; |
| 1249 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 1250 | goto set; |
Johannes Berg | 025e6be | 2010-10-05 10:41:47 +0200 | [diff] [blame] | 1251 | |
| 1252 | count += check_mgd_smps(&sdata->u.mgd, &smps_mode); |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 1253 | |
| 1254 | if (count > 1) { |
| 1255 | smps_mode = IEEE80211_SMPS_OFF; |
| 1256 | break; |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | if (smps_mode == local->smps_mode) |
| 1261 | return; |
| 1262 | |
| 1263 | set: |
| 1264 | local->smps_mode = smps_mode; |
| 1265 | /* changed flag is auto-detected for this */ |
| 1266 | ieee80211_hw_config(local, 0); |
| 1267 | } |
Johannes Berg | 8e664fb | 2009-12-23 13:15:38 +0100 | [diff] [blame] | 1268 | |
| 1269 | static bool ieee80211_id_in_list(const u8 *ids, int n_ids, u8 id) |
| 1270 | { |
| 1271 | int i; |
| 1272 | |
| 1273 | for (i = 0; i < n_ids; i++) |
| 1274 | if (ids[i] == id) |
| 1275 | return true; |
| 1276 | return false; |
| 1277 | } |
| 1278 | |
| 1279 | /** |
| 1280 | * ieee80211_ie_split - split an IE buffer according to ordering |
| 1281 | * |
| 1282 | * @ies: the IE buffer |
| 1283 | * @ielen: the length of the IE buffer |
| 1284 | * @ids: an array with element IDs that are allowed before |
| 1285 | * the split |
| 1286 | * @n_ids: the size of the element ID array |
| 1287 | * @offset: offset where to start splitting in the buffer |
| 1288 | * |
| 1289 | * This function splits an IE buffer by updating the @offset |
| 1290 | * variable to point to the location where the buffer should be |
| 1291 | * split. |
| 1292 | * |
| 1293 | * It assumes that the given IE buffer is well-formed, this |
| 1294 | * has to be guaranteed by the caller! |
| 1295 | * |
| 1296 | * It also assumes that the IEs in the buffer are ordered |
| 1297 | * correctly, if not the result of using this function will not |
| 1298 | * be ordered correctly either, i.e. it does no reordering. |
| 1299 | * |
| 1300 | * The function returns the offset where the next part of the |
| 1301 | * buffer starts, which may be @ielen if the entire (remainder) |
| 1302 | * of the buffer should be used. |
| 1303 | */ |
| 1304 | size_t ieee80211_ie_split(const u8 *ies, size_t ielen, |
| 1305 | const u8 *ids, int n_ids, size_t offset) |
| 1306 | { |
| 1307 | size_t pos = offset; |
| 1308 | |
| 1309 | while (pos < ielen && ieee80211_id_in_list(ids, n_ids, ies[pos])) |
| 1310 | pos += 2 + ies[pos + 1]; |
| 1311 | |
| 1312 | return pos; |
| 1313 | } |
| 1314 | |
| 1315 | size_t ieee80211_ie_split_vendor(const u8 *ies, size_t ielen, size_t offset) |
| 1316 | { |
| 1317 | size_t pos = offset; |
| 1318 | |
| 1319 | while (pos < ielen && ies[pos] != WLAN_EID_VENDOR_SPECIFIC) |
| 1320 | pos += 2 + ies[pos + 1]; |
| 1321 | |
| 1322 | return pos; |
| 1323 | } |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 1324 | |
| 1325 | static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata, |
| 1326 | int rssi_min_thold, |
| 1327 | int rssi_max_thold) |
| 1328 | { |
| 1329 | trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold); |
| 1330 | |
| 1331 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
| 1332 | return; |
| 1333 | |
| 1334 | /* |
| 1335 | * Scale up threshold values before storing it, as the RSSI averaging |
| 1336 | * algorithm uses a scaled up value as well. Change this scaling |
| 1337 | * factor if the RSSI averaging algorithm changes. |
| 1338 | */ |
| 1339 | sdata->u.mgd.rssi_min_thold = rssi_min_thold*16; |
| 1340 | sdata->u.mgd.rssi_max_thold = rssi_max_thold*16; |
| 1341 | } |
| 1342 | |
| 1343 | void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif, |
| 1344 | int rssi_min_thold, |
| 1345 | int rssi_max_thold) |
| 1346 | { |
| 1347 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 1348 | |
| 1349 | WARN_ON(rssi_min_thold == rssi_max_thold || |
| 1350 | rssi_min_thold > rssi_max_thold); |
| 1351 | |
| 1352 | _ieee80211_enable_rssi_reports(sdata, rssi_min_thold, |
| 1353 | rssi_max_thold); |
| 1354 | } |
| 1355 | EXPORT_SYMBOL(ieee80211_enable_rssi_reports); |
| 1356 | |
| 1357 | void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif) |
| 1358 | { |
| 1359 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 1360 | |
| 1361 | _ieee80211_enable_rssi_reports(sdata, 0, 0); |
| 1362 | } |
| 1363 | EXPORT_SYMBOL(ieee80211_disable_rssi_reports); |
Arik Nemtsov | 768db34 | 2011-09-28 14:12:51 +0300 | [diff] [blame] | 1364 | |
| 1365 | int ieee80211_add_srates_ie(struct ieee80211_vif *vif, struct sk_buff *skb) |
| 1366 | { |
| 1367 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 1368 | struct ieee80211_local *local = sdata->local; |
| 1369 | struct ieee80211_supported_band *sband; |
| 1370 | int rate; |
| 1371 | u8 i, rates, *pos; |
| 1372 | |
| 1373 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 1374 | rates = sband->n_bitrates; |
| 1375 | if (rates > 8) |
| 1376 | rates = 8; |
| 1377 | |
| 1378 | if (skb_tailroom(skb) < rates + 2) |
| 1379 | return -ENOMEM; |
| 1380 | |
| 1381 | pos = skb_put(skb, rates + 2); |
| 1382 | *pos++ = WLAN_EID_SUPP_RATES; |
| 1383 | *pos++ = rates; |
| 1384 | for (i = 0; i < rates; i++) { |
| 1385 | rate = sband->bitrates[i].bitrate; |
| 1386 | *pos++ = (u8) (rate / 5); |
| 1387 | } |
| 1388 | |
| 1389 | return 0; |
| 1390 | } |
| 1391 | |
| 1392 | int ieee80211_add_ext_srates_ie(struct ieee80211_vif *vif, struct sk_buff *skb) |
| 1393 | { |
| 1394 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 1395 | struct ieee80211_local *local = sdata->local; |
| 1396 | struct ieee80211_supported_band *sband; |
| 1397 | int rate; |
| 1398 | u8 i, exrates, *pos; |
| 1399 | |
| 1400 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 1401 | exrates = sband->n_bitrates; |
| 1402 | if (exrates > 8) |
| 1403 | exrates -= 8; |
| 1404 | else |
| 1405 | exrates = 0; |
| 1406 | |
| 1407 | if (skb_tailroom(skb) < exrates + 2) |
| 1408 | return -ENOMEM; |
| 1409 | |
| 1410 | if (exrates) { |
| 1411 | pos = skb_put(skb, exrates + 2); |
| 1412 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 1413 | *pos++ = exrates; |
| 1414 | for (i = 8; i < sband->n_bitrates; i++) { |
| 1415 | rate = sband->bitrates[i].bitrate; |
| 1416 | *pos++ = (u8) (rate / 5); |
| 1417 | } |
| 1418 | } |
| 1419 | return 0; |
| 1420 | } |