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