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