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