blob: b361e2acfce9e23ce5998ca4e44f41b5acc6b19c [file] [log] [blame]
Johannes Bergc2d15602007-07-27 15:43:23 +02001/*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
5 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * utilities for mac80211
12 */
13
14#include <net/mac80211.h>
15#include <linux/netdevice.h>
16#include <linux/types.h>
17#include <linux/slab.h>
18#include <linux/skbuff.h>
19#include <linux/etherdevice.h>
20#include <linux/if_arp.h>
21#include <linux/wireless.h>
22#include <linux/bitmap.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070023#include <net/net_namespace.h>
Johannes Bergc2d15602007-07-27 15:43:23 +020024#include <net/cfg80211.h>
Johannes Bergdabeb342007-11-09 01:57:29 +010025#include <net/rtnetlink.h>
Johannes Bergc2d15602007-07-27 15:43:23 +020026
27#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040028#include "rate.h"
Luis Carlos Coboee385852008-02-23 15:17:11 +010029#include "mesh.h"
Johannes Bergc2d15602007-07-27 15:43:23 +020030#include "wme.h"
Johannes Bergf2753dd2009-04-14 10:09:24 +020031#include "led.h"
Johannes Bergc2d15602007-07-27 15:43:23 +020032
33/* privid for wiphys to determine whether they belong to us or not */
34void *mac80211_wiphy_privid = &mac80211_wiphy_privid;
35
36/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
37/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
Senthil Balasubramanianc97c23e2008-05-28 23:15:32 +053038const unsigned char rfc1042_header[] __aligned(2) =
Johannes Bergc2d15602007-07-27 15:43:23 +020039 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
40
41/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
Senthil Balasubramanianc97c23e2008-05-28 23:15:32 +053042const unsigned char bridge_tunnel_header[] __aligned(2) =
Johannes Bergc2d15602007-07-27 15:43:23 +020043 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
44
Luis R. Rodriguez9a953712009-01-22 15:05:53 -080045struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy)
46{
47 struct ieee80211_local *local;
48 BUG_ON(!wiphy);
49
50 local = wiphy_priv(wiphy);
51 return &local->hw;
52}
53EXPORT_SYMBOL(wiphy_to_ieee80211_hw);
Johannes Bergc2d15602007-07-27 15:43:23 +020054
Ron Rindjunsky71364712007-12-25 17:00:36 +020055u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
Johannes Berg05c914f2008-09-11 00:01:58 +020056 enum nl80211_iftype type)
Johannes Bergc2d15602007-07-27 15:43:23 +020057{
Harvey Harrisona494bb12008-06-11 14:21:58 -070058 __le16 fc = hdr->frame_control;
Johannes Bergc2d15602007-07-27 15:43:23 +020059
Ron Rindjunsky98f0b0a2007-12-18 17:23:53 +020060 /* drop ACK/CTS frames and incorrect hdr len (ctrl) */
61 if (len < 16)
Johannes Bergc2d15602007-07-27 15:43:23 +020062 return NULL;
63
Harvey Harrisona494bb12008-06-11 14:21:58 -070064 if (ieee80211_is_data(fc)) {
Ron Rindjunsky98f0b0a2007-12-18 17:23:53 +020065 if (len < 24) /* drop incorrect hdr len (data) */
66 return NULL;
Harvey Harrisona494bb12008-06-11 14:21:58 -070067
68 if (ieee80211_has_a4(fc))
Johannes Bergc2d15602007-07-27 15:43:23 +020069 return NULL;
Harvey Harrisona494bb12008-06-11 14:21:58 -070070 if (ieee80211_has_tods(fc))
71 return hdr->addr1;
72 if (ieee80211_has_fromds(fc))
Johannes Bergc2d15602007-07-27 15:43:23 +020073 return hdr->addr2;
Harvey Harrisona494bb12008-06-11 14:21:58 -070074
75 return hdr->addr3;
76 }
77
78 if (ieee80211_is_mgmt(fc)) {
Ron Rindjunsky98f0b0a2007-12-18 17:23:53 +020079 if (len < 24) /* drop incorrect hdr len (mgmt) */
80 return NULL;
Johannes Bergc2d15602007-07-27 15:43:23 +020081 return hdr->addr3;
Harvey Harrisona494bb12008-06-11 14:21:58 -070082 }
83
84 if (ieee80211_is_ctl(fc)) {
85 if(ieee80211_is_pspoll(fc))
Johannes Bergc2d15602007-07-27 15:43:23 +020086 return hdr->addr1;
Harvey Harrisona494bb12008-06-11 14:21:58 -070087
88 if (ieee80211_is_back_req(fc)) {
Ron Rindjunsky71364712007-12-25 17:00:36 +020089 switch (type) {
Johannes Berg05c914f2008-09-11 00:01:58 +020090 case NL80211_IFTYPE_STATION:
Ron Rindjunsky71364712007-12-25 17:00:36 +020091 return hdr->addr2;
Johannes Berg05c914f2008-09-11 00:01:58 +020092 case NL80211_IFTYPE_AP:
93 case NL80211_IFTYPE_AP_VLAN:
Ron Rindjunsky71364712007-12-25 17:00:36 +020094 return hdr->addr1;
95 default:
Harvey Harrisona494bb12008-06-11 14:21:58 -070096 break; /* fall through to the return */
Ron Rindjunsky71364712007-12-25 17:00:36 +020097 }
98 }
Johannes Bergc2d15602007-07-27 15:43:23 +020099 }
100
101 return NULL;
102}
103
Harvey Harrison6693be72008-06-11 14:21:57 -0700104unsigned int ieee80211_hdrlen(__le16 fc)
105{
106 unsigned int hdrlen = 24;
107
108 if (ieee80211_is_data(fc)) {
109 if (ieee80211_has_a4(fc))
110 hdrlen = 30;
111 if (ieee80211_is_data_qos(fc))
112 hdrlen += IEEE80211_QOS_CTL_LEN;
113 goto out;
114 }
115
116 if (ieee80211_is_ctl(fc)) {
117 /*
118 * ACK and CTS are 10 bytes, all others 16. To see how
119 * to get this condition consider
120 * subtype mask: 0b0000000011110000 (0x00F0)
121 * ACK subtype: 0b0000000011010000 (0x00D0)
122 * CTS subtype: 0b0000000011000000 (0x00C0)
123 * bits that matter: ^^^ (0x00E0)
124 * value of those: 0b0000000011000000 (0x00C0)
125 */
126 if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0))
127 hdrlen = 10;
128 else
129 hdrlen = 16;
130 }
131out:
132 return hdrlen;
133}
134EXPORT_SYMBOL(ieee80211_hdrlen);
135
Harvey Harrisonc9c69502008-06-11 14:21:57 -0700136unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
Johannes Bergc2d15602007-07-27 15:43:23 +0200137{
Harvey Harrisonc9c69502008-06-11 14:21:57 -0700138 const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *)skb->data;
139 unsigned int hdrlen;
Johannes Bergc2d15602007-07-27 15:43:23 +0200140
141 if (unlikely(skb->len < 10))
142 return 0;
Harvey Harrisonc9c69502008-06-11 14:21:57 -0700143 hdrlen = ieee80211_hdrlen(hdr->frame_control);
Johannes Bergc2d15602007-07-27 15:43:23 +0200144 if (unlikely(hdrlen > skb->len))
145 return 0;
146 return hdrlen;
147}
148EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
149
Luis Carlos Coboee385852008-02-23 15:17:11 +0100150int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
151{
152 int ae = meshhdr->flags & IEEE80211S_FLAGS_AE;
153 /* 7.1.3.5a.2 */
154 switch (ae) {
155 case 0:
Luis Carlos Coboef269252008-05-05 12:02:35 -0700156 return 6;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100157 case 1:
Luis Carlos Coboef269252008-05-05 12:02:35 -0700158 return 12;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100159 case 2:
Luis Carlos Coboef269252008-05-05 12:02:35 -0700160 return 18;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100161 case 3:
Luis Carlos Coboef269252008-05-05 12:02:35 -0700162 return 24;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100163 default:
Luis Carlos Coboef269252008-05-05 12:02:35 -0700164 return 6;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100165 }
166}
Luis Carlos Coboee385852008-02-23 15:17:11 +0100167
Johannes Berg5cf121c2008-02-25 16:27:43 +0100168void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx)
Johannes Bergc2d15602007-07-27 15:43:23 +0200169{
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100170 struct sk_buff *skb = tx->skb;
171 struct ieee80211_hdr *hdr;
Johannes Bergc2d15602007-07-27 15:43:23 +0200172
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100173 do {
174 hdr = (struct ieee80211_hdr *) skb->data;
175 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
176 } while ((skb = skb->next));
Johannes Bergc2d15602007-07-27 15:43:23 +0200177}
178
179int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
180 int rate, int erp, int short_preamble)
181{
182 int dur;
183
184 /* calculate duration (in microseconds, rounded up to next higher
185 * integer if it includes a fractional microsecond) to send frame of
186 * len bytes (does not include FCS) at the given rate. Duration will
187 * also include SIFS.
188 *
189 * rate is in 100 kbps, so divident is multiplied by 10 in the
190 * DIV_ROUND_UP() operations.
191 */
192
Johannes Berg8318d782008-01-24 19:38:38 +0100193 if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ || erp) {
Johannes Bergc2d15602007-07-27 15:43:23 +0200194 /*
195 * OFDM:
196 *
197 * N_DBPS = DATARATE x 4
198 * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
199 * (16 = SIGNAL time, 6 = tail bits)
200 * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
201 *
202 * T_SYM = 4 usec
203 * 802.11a - 17.5.2: aSIFSTime = 16 usec
204 * 802.11g - 19.8.4: aSIFSTime = 10 usec +
205 * signal ext = 6 usec
206 */
Johannes Bergc2d15602007-07-27 15:43:23 +0200207 dur = 16; /* SIFS + signal ext */
208 dur += 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */
209 dur += 4; /* 17.3.2.3: T_SIGNAL = 4 usec */
210 dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10,
211 4 * rate); /* T_SYM x N_SYM */
212 } else {
213 /*
214 * 802.11b or 802.11g with 802.11b compatibility:
215 * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
216 * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
217 *
218 * 802.11 (DS): 15.3.3, 802.11b: 18.3.4
219 * aSIFSTime = 10 usec
220 * aPreambleLength = 144 usec or 72 usec with short preamble
221 * aPLCPHeaderLength = 48 usec or 24 usec with short preamble
222 */
223 dur = 10; /* aSIFSTime = 10 usec */
224 dur += short_preamble ? (72 + 24) : (144 + 48);
225
226 dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate);
227 }
228
229 return dur;
230}
231
232/* Exported duration function for driver use */
Johannes Berg32bfd352007-12-19 01:31:26 +0100233__le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
234 struct ieee80211_vif *vif,
Johannes Berg8318d782008-01-24 19:38:38 +0100235 size_t frame_len,
236 struct ieee80211_rate *rate)
Johannes Bergc2d15602007-07-27 15:43:23 +0200237{
238 struct ieee80211_local *local = hw_to_local(hw);
Johannes Berg25d834e2008-09-12 22:52:47 +0200239 struct ieee80211_sub_if_data *sdata;
Johannes Bergc2d15602007-07-27 15:43:23 +0200240 u16 dur;
241 int erp;
Johannes Berg25d834e2008-09-12 22:52:47 +0200242 bool short_preamble = false;
Johannes Bergc2d15602007-07-27 15:43:23 +0200243
Johannes Berg8318d782008-01-24 19:38:38 +0100244 erp = 0;
Johannes Berg25d834e2008-09-12 22:52:47 +0200245 if (vif) {
246 sdata = vif_to_sdata(vif);
Johannes Bergbda39332008-10-11 01:51:51 +0200247 short_preamble = sdata->vif.bss_conf.use_short_preamble;
Johannes Berg25d834e2008-09-12 22:52:47 +0200248 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
249 erp = rate->flags & IEEE80211_RATE_ERP_G;
250 }
Johannes Berg8318d782008-01-24 19:38:38 +0100251
252 dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, erp,
Johannes Berg25d834e2008-09-12 22:52:47 +0200253 short_preamble);
Johannes Bergc2d15602007-07-27 15:43:23 +0200254
255 return cpu_to_le16(dur);
256}
257EXPORT_SYMBOL(ieee80211_generic_frame_duration);
258
Johannes Berg32bfd352007-12-19 01:31:26 +0100259__le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
260 struct ieee80211_vif *vif, size_t frame_len,
Johannes Berge039fa42008-05-15 12:55:29 +0200261 const struct ieee80211_tx_info *frame_txctl)
Johannes Bergc2d15602007-07-27 15:43:23 +0200262{
263 struct ieee80211_local *local = hw_to_local(hw);
264 struct ieee80211_rate *rate;
Johannes Berg25d834e2008-09-12 22:52:47 +0200265 struct ieee80211_sub_if_data *sdata;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100266 bool short_preamble;
Johannes Bergc2d15602007-07-27 15:43:23 +0200267 int erp;
268 u16 dur;
Johannes Berg2e92e6f2008-05-15 12:55:27 +0200269 struct ieee80211_supported_band *sband;
270
271 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
Johannes Bergc2d15602007-07-27 15:43:23 +0200272
Johannes Berg25d834e2008-09-12 22:52:47 +0200273 short_preamble = false;
Daniel Drake7e9ed182007-07-27 15:43:24 +0200274
Johannes Berge039fa42008-05-15 12:55:29 +0200275 rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
Johannes Berg8318d782008-01-24 19:38:38 +0100276
277 erp = 0;
Johannes Berg25d834e2008-09-12 22:52:47 +0200278 if (vif) {
279 sdata = vif_to_sdata(vif);
Johannes Bergbda39332008-10-11 01:51:51 +0200280 short_preamble = sdata->vif.bss_conf.use_short_preamble;
Johannes Berg25d834e2008-09-12 22:52:47 +0200281 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
282 erp = rate->flags & IEEE80211_RATE_ERP_G;
283 }
Johannes Bergc2d15602007-07-27 15:43:23 +0200284
285 /* CTS duration */
Johannes Berg8318d782008-01-24 19:38:38 +0100286 dur = ieee80211_frame_duration(local, 10, rate->bitrate,
Johannes Bergc2d15602007-07-27 15:43:23 +0200287 erp, short_preamble);
288 /* Data frame duration */
Johannes Berg8318d782008-01-24 19:38:38 +0100289 dur += ieee80211_frame_duration(local, frame_len, rate->bitrate,
Johannes Bergc2d15602007-07-27 15:43:23 +0200290 erp, short_preamble);
291 /* ACK duration */
Johannes Berg8318d782008-01-24 19:38:38 +0100292 dur += ieee80211_frame_duration(local, 10, rate->bitrate,
Johannes Bergc2d15602007-07-27 15:43:23 +0200293 erp, short_preamble);
294
295 return cpu_to_le16(dur);
296}
297EXPORT_SYMBOL(ieee80211_rts_duration);
298
Johannes Berg32bfd352007-12-19 01:31:26 +0100299__le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
300 struct ieee80211_vif *vif,
Johannes Bergc2d15602007-07-27 15:43:23 +0200301 size_t frame_len,
Johannes Berge039fa42008-05-15 12:55:29 +0200302 const struct ieee80211_tx_info *frame_txctl)
Johannes Bergc2d15602007-07-27 15:43:23 +0200303{
304 struct ieee80211_local *local = hw_to_local(hw);
305 struct ieee80211_rate *rate;
Johannes Berg25d834e2008-09-12 22:52:47 +0200306 struct ieee80211_sub_if_data *sdata;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100307 bool short_preamble;
Johannes Bergc2d15602007-07-27 15:43:23 +0200308 int erp;
309 u16 dur;
Johannes Berg2e92e6f2008-05-15 12:55:27 +0200310 struct ieee80211_supported_band *sband;
311
312 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
Johannes Bergc2d15602007-07-27 15:43:23 +0200313
Johannes Berg25d834e2008-09-12 22:52:47 +0200314 short_preamble = false;
Daniel Drake7e9ed182007-07-27 15:43:24 +0200315
Johannes Berge039fa42008-05-15 12:55:29 +0200316 rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
Johannes Berg8318d782008-01-24 19:38:38 +0100317 erp = 0;
Johannes Berg25d834e2008-09-12 22:52:47 +0200318 if (vif) {
319 sdata = vif_to_sdata(vif);
Johannes Bergbda39332008-10-11 01:51:51 +0200320 short_preamble = sdata->vif.bss_conf.use_short_preamble;
Johannes Berg25d834e2008-09-12 22:52:47 +0200321 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
322 erp = rate->flags & IEEE80211_RATE_ERP_G;
323 }
Johannes Bergc2d15602007-07-27 15:43:23 +0200324
325 /* Data frame duration */
Johannes Berg8318d782008-01-24 19:38:38 +0100326 dur = ieee80211_frame_duration(local, frame_len, rate->bitrate,
Johannes Bergc2d15602007-07-27 15:43:23 +0200327 erp, short_preamble);
Johannes Berge039fa42008-05-15 12:55:29 +0200328 if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) {
Johannes Bergc2d15602007-07-27 15:43:23 +0200329 /* ACK duration */
Johannes Berg8318d782008-01-24 19:38:38 +0100330 dur += ieee80211_frame_duration(local, 10, rate->bitrate,
Johannes Bergc2d15602007-07-27 15:43:23 +0200331 erp, short_preamble);
332 }
333
Johannes Bergc2d15602007-07-27 15:43:23 +0200334 return cpu_to_le16(dur);
335}
336EXPORT_SYMBOL(ieee80211_ctstoself_duration);
337
Kalle Valoce7c9112008-12-18 23:35:20 +0200338static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue,
339 enum queue_stop_reason reason)
Johannes Bergc2d15602007-07-27 15:43:23 +0200340{
341 struct ieee80211_local *local = hw_to_local(hw);
342
Johannes Berge4e72fb2009-03-23 17:28:42 +0100343 if (WARN_ON(queue >= hw->queues))
344 return;
Kalle Valoce7c9112008-12-18 23:35:20 +0200345
Johannes Berg96f5e662009-02-12 00:51:53 +0100346 __clear_bit(reason, &local->queue_stop_reasons[queue]);
347
Johannes Berg2a577d92009-03-23 17:28:37 +0100348 if (!skb_queue_empty(&local->pending[queue]) &&
349 local->queue_stop_reasons[queue] ==
350 BIT(IEEE80211_QUEUE_STOP_REASON_PENDING))
351 tasklet_schedule(&local->tx_pending_tasklet);
352
Johannes Berg96f5e662009-02-12 00:51:53 +0100353 if (local->queue_stop_reasons[queue] != 0)
354 /* someone still has this queue stopped */
355 return;
356
Johannes Berg2a577d92009-03-23 17:28:37 +0100357 netif_wake_subqueue(local->mdev, queue);
Johannes Bergc2d15602007-07-27 15:43:23 +0200358}
Kalle Valoce7c9112008-12-18 23:35:20 +0200359
Johannes Berg96f5e662009-02-12 00:51:53 +0100360void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
361 enum queue_stop_reason reason)
Kalle Valoce7c9112008-12-18 23:35:20 +0200362{
363 struct ieee80211_local *local = hw_to_local(hw);
364 unsigned long flags;
365
366 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
367 __ieee80211_wake_queue(hw, queue, reason);
368 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
369}
370
371void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
372{
373 ieee80211_wake_queue_by_reason(hw, queue,
374 IEEE80211_QUEUE_STOP_REASON_DRIVER);
375}
Johannes Bergc2d15602007-07-27 15:43:23 +0200376EXPORT_SYMBOL(ieee80211_wake_queue);
377
Kalle Valoce7c9112008-12-18 23:35:20 +0200378static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue,
379 enum queue_stop_reason reason)
Johannes Bergc2d15602007-07-27 15:43:23 +0200380{
381 struct ieee80211_local *local = hw_to_local(hw);
382
Johannes Berge4e72fb2009-03-23 17:28:42 +0100383 if (WARN_ON(queue >= hw->queues))
384 return;
Johannes Berg96f5e662009-02-12 00:51:53 +0100385
Johannes Berg2a577d92009-03-23 17:28:37 +0100386 /*
387 * Only stop if it was previously running, this is necessary
388 * for correct pending packets handling because there we may
389 * start (but not wake) the queue and rely on that.
390 */
391 if (!local->queue_stop_reasons[queue])
392 netif_stop_subqueue(local->mdev, queue);
Kalle Valoce7c9112008-12-18 23:35:20 +0200393
Johannes Berg2a577d92009-03-23 17:28:37 +0100394 __set_bit(reason, &local->queue_stop_reasons[queue]);
Johannes Bergc2d15602007-07-27 15:43:23 +0200395}
Kalle Valoce7c9112008-12-18 23:35:20 +0200396
Johannes Berg96f5e662009-02-12 00:51:53 +0100397void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue,
398 enum queue_stop_reason reason)
Kalle Valoce7c9112008-12-18 23:35:20 +0200399{
400 struct ieee80211_local *local = hw_to_local(hw);
401 unsigned long flags;
402
403 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
404 __ieee80211_stop_queue(hw, queue, reason);
405 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
406}
407
408void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue)
409{
410 ieee80211_stop_queue_by_reason(hw, queue,
411 IEEE80211_QUEUE_STOP_REASON_DRIVER);
412}
Johannes Bergc2d15602007-07-27 15:43:23 +0200413EXPORT_SYMBOL(ieee80211_stop_queue);
414
Kalle Valoce7c9112008-12-18 23:35:20 +0200415void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw,
416 enum queue_stop_reason reason)
Johannes Bergc2d15602007-07-27 15:43:23 +0200417{
Kalle Valoce7c9112008-12-18 23:35:20 +0200418 struct ieee80211_local *local = hw_to_local(hw);
419 unsigned long flags;
Johannes Bergc2d15602007-07-27 15:43:23 +0200420 int i;
421
Kalle Valoce7c9112008-12-18 23:35:20 +0200422 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
423
Johannes Berg96f5e662009-02-12 00:51:53 +0100424 for (i = 0; i < hw->queues; i++)
Kalle Valoce7c9112008-12-18 23:35:20 +0200425 __ieee80211_stop_queue(hw, i, reason);
426
427 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
428}
429
430void ieee80211_stop_queues(struct ieee80211_hw *hw)
431{
432 ieee80211_stop_queues_by_reason(hw,
433 IEEE80211_QUEUE_STOP_REASON_DRIVER);
Johannes Bergc2d15602007-07-27 15:43:23 +0200434}
435EXPORT_SYMBOL(ieee80211_stop_queues);
436
Tomas Winkler92ab8532008-07-24 21:02:04 +0300437int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue)
438{
439 struct ieee80211_local *local = hw_to_local(hw);
Johannes Berg96f5e662009-02-12 00:51:53 +0100440
Johannes Berge4e72fb2009-03-23 17:28:42 +0100441 if (WARN_ON(queue >= hw->queues))
442 return true;
Johannes Berg96f5e662009-02-12 00:51:53 +0100443
Tomas Winkler92ab8532008-07-24 21:02:04 +0300444 return __netif_subqueue_stopped(local->mdev, queue);
445}
446EXPORT_SYMBOL(ieee80211_queue_stopped);
447
Kalle Valoce7c9112008-12-18 23:35:20 +0200448void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw,
449 enum queue_stop_reason reason)
Johannes Bergc2d15602007-07-27 15:43:23 +0200450{
Kalle Valoce7c9112008-12-18 23:35:20 +0200451 struct ieee80211_local *local = hw_to_local(hw);
452 unsigned long flags;
Johannes Bergc2d15602007-07-27 15:43:23 +0200453 int i;
454
Kalle Valoce7c9112008-12-18 23:35:20 +0200455 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
456
Johannes Berge4e72fb2009-03-23 17:28:42 +0100457 for (i = 0; i < hw->queues; i++)
Kalle Valoce7c9112008-12-18 23:35:20 +0200458 __ieee80211_wake_queue(hw, i, reason);
459
460 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
461}
462
463void ieee80211_wake_queues(struct ieee80211_hw *hw)
464{
465 ieee80211_wake_queues_by_reason(hw, IEEE80211_QUEUE_STOP_REASON_DRIVER);
Johannes Bergc2d15602007-07-27 15:43:23 +0200466}
467EXPORT_SYMBOL(ieee80211_wake_queues);
Johannes Bergdabeb342007-11-09 01:57:29 +0100468
Johannes Berg32bfd352007-12-19 01:31:26 +0100469void ieee80211_iterate_active_interfaces(
470 struct ieee80211_hw *hw,
471 void (*iterator)(void *data, u8 *mac,
472 struct ieee80211_vif *vif),
473 void *data)
Johannes Bergdabeb342007-11-09 01:57:29 +0100474{
475 struct ieee80211_local *local = hw_to_local(hw);
476 struct ieee80211_sub_if_data *sdata;
477
Johannes Bergc771c9d2009-01-23 22:54:03 +0100478 mutex_lock(&local->iflist_mtx);
Ivo van Doorn2f561fe2008-05-10 13:40:49 +0200479
480 list_for_each_entry(sdata, &local->interfaces, list) {
481 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200482 case __NL80211_IFTYPE_AFTER_LAST:
483 case NL80211_IFTYPE_UNSPECIFIED:
484 case NL80211_IFTYPE_MONITOR:
485 case NL80211_IFTYPE_AP_VLAN:
Ivo van Doorn2f561fe2008-05-10 13:40:49 +0200486 continue;
Johannes Berg05c914f2008-09-11 00:01:58 +0200487 case NL80211_IFTYPE_AP:
488 case NL80211_IFTYPE_STATION:
489 case NL80211_IFTYPE_ADHOC:
490 case NL80211_IFTYPE_WDS:
491 case NL80211_IFTYPE_MESH_POINT:
Ivo van Doorn2f561fe2008-05-10 13:40:49 +0200492 break;
493 }
Ivo van Doorn2f561fe2008-05-10 13:40:49 +0200494 if (netif_running(sdata->dev))
495 iterator(data, sdata->dev->dev_addr,
496 &sdata->vif);
497 }
498
Johannes Bergc771c9d2009-01-23 22:54:03 +0100499 mutex_unlock(&local->iflist_mtx);
Ivo van Doorn2f561fe2008-05-10 13:40:49 +0200500}
501EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces);
502
503void ieee80211_iterate_active_interfaces_atomic(
504 struct ieee80211_hw *hw,
505 void (*iterator)(void *data, u8 *mac,
506 struct ieee80211_vif *vif),
507 void *data)
508{
509 struct ieee80211_local *local = hw_to_local(hw);
510 struct ieee80211_sub_if_data *sdata;
511
Johannes Berge38bad42007-11-28 10:55:32 +0100512 rcu_read_lock();
Johannes Bergdabeb342007-11-09 01:57:29 +0100513
Johannes Berge38bad42007-11-28 10:55:32 +0100514 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Berg51fb61e2007-12-19 01:31:27 +0100515 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200516 case __NL80211_IFTYPE_AFTER_LAST:
517 case NL80211_IFTYPE_UNSPECIFIED:
518 case NL80211_IFTYPE_MONITOR:
519 case NL80211_IFTYPE_AP_VLAN:
Johannes Bergdabeb342007-11-09 01:57:29 +0100520 continue;
Johannes Berg05c914f2008-09-11 00:01:58 +0200521 case NL80211_IFTYPE_AP:
522 case NL80211_IFTYPE_STATION:
523 case NL80211_IFTYPE_ADHOC:
524 case NL80211_IFTYPE_WDS:
525 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergdabeb342007-11-09 01:57:29 +0100526 break;
527 }
Johannes Bergdabeb342007-11-09 01:57:29 +0100528 if (netif_running(sdata->dev))
529 iterator(data, sdata->dev->dev_addr,
Johannes Berg32bfd352007-12-19 01:31:26 +0100530 &sdata->vif);
Johannes Bergdabeb342007-11-09 01:57:29 +0100531 }
Johannes Berge38bad42007-11-28 10:55:32 +0100532
533 rcu_read_unlock();
Johannes Bergdabeb342007-11-09 01:57:29 +0100534}
Ivo van Doorn2f561fe2008-05-10 13:40:49 +0200535EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic);
Johannes Berg37ffc8d2008-09-08 16:40:36 +0200536
537void ieee802_11_parse_elems(u8 *start, size_t len,
538 struct ieee802_11_elems *elems)
539{
540 size_t left = len;
541 u8 *pos = start;
542
543 memset(elems, 0, sizeof(*elems));
544 elems->ie_start = start;
545 elems->total_len = len;
546
547 while (left >= 2) {
548 u8 id, elen;
549
550 id = *pos++;
551 elen = *pos++;
552 left -= 2;
553
554 if (elen > left)
555 return;
556
557 switch (id) {
558 case WLAN_EID_SSID:
559 elems->ssid = pos;
560 elems->ssid_len = elen;
561 break;
562 case WLAN_EID_SUPP_RATES:
563 elems->supp_rates = pos;
564 elems->supp_rates_len = elen;
565 break;
566 case WLAN_EID_FH_PARAMS:
567 elems->fh_params = pos;
568 elems->fh_params_len = elen;
569 break;
570 case WLAN_EID_DS_PARAMS:
571 elems->ds_params = pos;
572 elems->ds_params_len = elen;
573 break;
574 case WLAN_EID_CF_PARAMS:
575 elems->cf_params = pos;
576 elems->cf_params_len = elen;
577 break;
578 case WLAN_EID_TIM:
579 elems->tim = pos;
580 elems->tim_len = elen;
581 break;
582 case WLAN_EID_IBSS_PARAMS:
583 elems->ibss_params = pos;
584 elems->ibss_params_len = elen;
585 break;
586 case WLAN_EID_CHALLENGE:
587 elems->challenge = pos;
588 elems->challenge_len = elen;
589 break;
590 case WLAN_EID_WPA:
591 if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
592 pos[2] == 0xf2) {
593 /* Microsoft OUI (00:50:F2) */
594 if (pos[3] == 1) {
595 /* OUI Type 1 - WPA IE */
596 elems->wpa = pos;
597 elems->wpa_len = elen;
598 } else if (elen >= 5 && pos[3] == 2) {
599 if (pos[4] == 0) {
600 elems->wmm_info = pos;
601 elems->wmm_info_len = elen;
602 } else if (pos[4] == 1) {
603 elems->wmm_param = pos;
604 elems->wmm_param_len = elen;
605 }
606 }
607 }
608 break;
609 case WLAN_EID_RSN:
610 elems->rsn = pos;
611 elems->rsn_len = elen;
612 break;
613 case WLAN_EID_ERP_INFO:
614 elems->erp_info = pos;
615 elems->erp_info_len = elen;
616 break;
617 case WLAN_EID_EXT_SUPP_RATES:
618 elems->ext_supp_rates = pos;
619 elems->ext_supp_rates_len = elen;
620 break;
621 case WLAN_EID_HT_CAPABILITY:
Johannes Berg09914812008-10-07 19:31:17 +0200622 if (elen >= sizeof(struct ieee80211_ht_cap))
623 elems->ht_cap_elem = (void *)pos;
Johannes Berg37ffc8d2008-09-08 16:40:36 +0200624 break;
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200625 case WLAN_EID_HT_INFORMATION:
626 if (elen >= sizeof(struct ieee80211_ht_info))
Johannes Berg09914812008-10-07 19:31:17 +0200627 elems->ht_info_elem = (void *)pos;
Johannes Berg37ffc8d2008-09-08 16:40:36 +0200628 break;
629 case WLAN_EID_MESH_ID:
630 elems->mesh_id = pos;
631 elems->mesh_id_len = elen;
632 break;
633 case WLAN_EID_MESH_CONFIG:
634 elems->mesh_config = pos;
635 elems->mesh_config_len = elen;
636 break;
637 case WLAN_EID_PEER_LINK:
638 elems->peer_link = pos;
639 elems->peer_link_len = elen;
640 break;
641 case WLAN_EID_PREQ:
642 elems->preq = pos;
643 elems->preq_len = elen;
644 break;
645 case WLAN_EID_PREP:
646 elems->prep = pos;
647 elems->prep_len = elen;
648 break;
649 case WLAN_EID_PERR:
650 elems->perr = pos;
651 elems->perr_len = elen;
652 break;
653 case WLAN_EID_CHANNEL_SWITCH:
654 elems->ch_switch_elem = pos;
655 elems->ch_switch_elem_len = elen;
656 break;
657 case WLAN_EID_QUIET:
658 if (!elems->quiet_elem) {
659 elems->quiet_elem = pos;
660 elems->quiet_elem_len = elen;
661 }
662 elems->num_of_quiet_elem++;
663 break;
664 case WLAN_EID_COUNTRY:
665 elems->country_elem = pos;
666 elems->country_elem_len = elen;
667 break;
668 case WLAN_EID_PWR_CONSTRAINT:
669 elems->pwr_constr_elem = pos;
670 elems->pwr_constr_elem_len = elen;
671 break;
Jouni Malinenf797eb72009-01-19 18:48:46 +0200672 case WLAN_EID_TIMEOUT_INTERVAL:
673 elems->timeout_int = pos;
674 elems->timeout_int_len = elen;
Jouni Malinen63a5ab82009-01-08 13:32:09 +0200675 break;
Johannes Berg37ffc8d2008-09-08 16:40:36 +0200676 default:
677 break;
678 }
679
680 left -= elen;
681 pos += elen;
682 }
683}
Johannes Berg5825fe102008-09-09 12:56:01 +0200684
685void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata)
686{
687 struct ieee80211_local *local = sdata->local;
688 struct ieee80211_tx_queue_params qparam;
689 int i;
690
691 if (!local->ops->conf_tx)
692 return;
693
694 memset(&qparam, 0, sizeof(qparam));
695
696 qparam.aifs = 2;
697
698 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
699 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE))
700 qparam.cw_min = 31;
701 else
702 qparam.cw_min = 15;
703
704 qparam.cw_max = 1023;
705 qparam.txop = 0;
706
707 for (i = 0; i < local_to_hw(local)->queues; i++)
708 local->ops->conf_tx(local_to_hw(local), i, &qparam);
709}
Johannes Berge50db652008-09-09 15:07:09 +0200710
Johannes Berg46900292009-02-15 12:44:28 +0100711void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
712 const size_t supp_rates_len,
713 const u8 *supp_rates)
714{
715 struct ieee80211_local *local = sdata->local;
716 int i, have_higher_than_11mbit = 0;
717
718 /* cf. IEEE 802.11 9.2.12 */
719 for (i = 0; i < supp_rates_len; i++)
720 if ((supp_rates[i] & 0x7f) * 5 > 110)
721 have_higher_than_11mbit = 1;
722
723 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
724 have_higher_than_11mbit)
725 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
726 else
727 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
728
729 ieee80211_set_wmm_default(sdata);
730}
731
Johannes Berge50db652008-09-09 15:07:09 +0200732void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
733 int encrypt)
734{
735 skb->dev = sdata->local->mdev;
736 skb_set_mac_header(skb, 0);
737 skb_set_network_header(skb, 0);
738 skb_set_transport_header(skb, 0);
739
740 skb->iif = sdata->dev->ifindex;
741 skb->do_not_encrypt = !encrypt;
742
743 dev_queue_xmit(skb);
744}
Johannes Berge16751c2008-09-11 00:01:53 +0200745
746int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freqMHz)
747{
748 int ret = -EINVAL;
749 struct ieee80211_channel *chan;
750 struct ieee80211_local *local = sdata->local;
751
752 chan = ieee80211_get_channel(local->hw.wiphy, freqMHz);
753
754 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200755 if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
Johannes Bergd73782f2008-10-07 12:04:34 +0200756 chan->flags & IEEE80211_CHAN_NO_IBSS)
Johannes Berge16751c2008-09-11 00:01:53 +0200757 return ret;
Johannes Berge16751c2008-09-11 00:01:53 +0200758 local->oper_channel = chan;
Sujith094d05d2008-12-12 11:57:43 +0530759 local->oper_channel_type = NL80211_CHAN_NO_HT;
Johannes Berge16751c2008-09-11 00:01:53 +0200760
Johannes Bergc2b13452008-09-11 00:01:55 +0200761 if (local->sw_scanning || local->hw_scanning)
Johannes Berge16751c2008-09-11 00:01:53 +0200762 ret = 0;
763 else
Johannes Berge8975582008-10-09 12:18:51 +0200764 ret = ieee80211_hw_config(
765 local, IEEE80211_CONF_CHANGE_CHANNEL);
Johannes Berge16751c2008-09-11 00:01:53 +0200766 }
767
768 return ret;
769}
Johannes Berg96dd22a2008-09-11 00:01:57 +0200770
Johannes Berg881d9482009-01-21 15:13:48 +0100771u32 ieee80211_mandatory_rates(struct ieee80211_local *local,
Johannes Berg96dd22a2008-09-11 00:01:57 +0200772 enum ieee80211_band band)
773{
774 struct ieee80211_supported_band *sband;
775 struct ieee80211_rate *bitrates;
Johannes Berg881d9482009-01-21 15:13:48 +0100776 u32 mandatory_rates;
Johannes Berg96dd22a2008-09-11 00:01:57 +0200777 enum ieee80211_rate_flags mandatory_flag;
778 int i;
779
780 sband = local->hw.wiphy->bands[band];
781 if (!sband) {
782 WARN_ON(1);
783 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
784 }
785
786 if (band == IEEE80211_BAND_2GHZ)
787 mandatory_flag = IEEE80211_RATE_MANDATORY_B;
788 else
789 mandatory_flag = IEEE80211_RATE_MANDATORY_A;
790
791 bitrates = sband->bitrates;
792 mandatory_rates = 0;
793 for (i = 0; i < sband->n_bitrates; i++)
794 if (bitrates[i].flags & mandatory_flag)
795 mandatory_rates |= BIT(i);
796 return mandatory_rates;
797}
Johannes Berg46900292009-02-15 12:44:28 +0100798
799void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
800 u16 transaction, u16 auth_alg,
801 u8 *extra, size_t extra_len,
802 const u8 *bssid, int encrypt)
803{
804 struct ieee80211_local *local = sdata->local;
805 struct sk_buff *skb;
806 struct ieee80211_mgmt *mgmt;
Johannes Berg46900292009-02-15 12:44:28 +0100807
808 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200809 sizeof(*mgmt) + 6 + extra_len);
Johannes Berg46900292009-02-15 12:44:28 +0100810 if (!skb) {
811 printk(KERN_DEBUG "%s: failed to allocate buffer for auth "
812 "frame\n", sdata->dev->name);
813 return;
814 }
815 skb_reserve(skb, local->hw.extra_tx_headroom);
816
817 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
818 memset(mgmt, 0, 24 + 6);
819 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
820 IEEE80211_STYPE_AUTH);
821 if (encrypt)
822 mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
823 memcpy(mgmt->da, bssid, ETH_ALEN);
824 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
825 memcpy(mgmt->bssid, bssid, ETH_ALEN);
826 mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg);
827 mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
828 mgmt->u.auth.status_code = cpu_to_le16(0);
829 if (extra)
830 memcpy(skb_put(skb, extra_len), extra, extra_len);
Johannes Berg46900292009-02-15 12:44:28 +0100831
832 ieee80211_tx_skb(sdata, skb, encrypt);
833}
834
Johannes Bergde95a542009-04-01 11:58:36 +0200835int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
836 const u8 *ie, size_t ie_len)
837{
838 struct ieee80211_supported_band *sband;
839 u8 *pos, *supp_rates_len, *esupp_rates_len = NULL;
840 int i;
841
842 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
843
844 pos = buffer;
845
846 *pos++ = WLAN_EID_SUPP_RATES;
847 supp_rates_len = pos;
848 *pos++ = 0;
849
850 for (i = 0; i < sband->n_bitrates; i++) {
851 struct ieee80211_rate *rate = &sband->bitrates[i];
852
853 if (esupp_rates_len) {
854 *esupp_rates_len += 1;
855 } else if (*supp_rates_len == 8) {
856 *pos++ = WLAN_EID_EXT_SUPP_RATES;
857 esupp_rates_len = pos;
858 *pos++ = 1;
859 } else
860 *supp_rates_len += 1;
861
862 *pos++ = rate->bitrate / 5;
863 }
864
Johannes Berg5ef2d412009-03-31 12:12:07 +0200865 if (sband->ht_cap.ht_supported) {
866 __le16 tmp = cpu_to_le16(sband->ht_cap.cap);
867
868 *pos++ = WLAN_EID_HT_CAPABILITY;
869 *pos++ = sizeof(struct ieee80211_ht_cap);
870 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
871 memcpy(pos, &tmp, sizeof(u16));
872 pos += sizeof(u16);
873 /* TODO: needs a define here for << 2 */
874 *pos++ = sband->ht_cap.ampdu_factor |
875 (sband->ht_cap.ampdu_density << 2);
876 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
877 pos += sizeof(sband->ht_cap.mcs);
878 pos += 2 + 4 + 1; /* ext info, BF cap, antsel */
879 }
880
Johannes Bergde95a542009-04-01 11:58:36 +0200881 /*
882 * If adding more here, adjust code in main.c
883 * that calculates local->scan_ies_len.
884 */
885
886 if (ie) {
887 memcpy(pos, ie, ie_len);
888 pos += ie_len;
889 }
890
891 return pos - buffer;
892}
893
Johannes Berg46900292009-02-15 12:44:28 +0100894void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
Johannes Bergde95a542009-04-01 11:58:36 +0200895 const u8 *ssid, size_t ssid_len,
896 const u8 *ie, size_t ie_len)
Johannes Berg46900292009-02-15 12:44:28 +0100897{
898 struct ieee80211_local *local = sdata->local;
Johannes Berg46900292009-02-15 12:44:28 +0100899 struct sk_buff *skb;
900 struct ieee80211_mgmt *mgmt;
Johannes Bergde95a542009-04-01 11:58:36 +0200901 u8 *pos;
Johannes Berg46900292009-02-15 12:44:28 +0100902
903 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200 +
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200904 ie_len);
Johannes Berg46900292009-02-15 12:44:28 +0100905 if (!skb) {
906 printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
907 "request\n", sdata->dev->name);
908 return;
909 }
910 skb_reserve(skb, local->hw.extra_tx_headroom);
911
912 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
913 memset(mgmt, 0, 24);
914 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
915 IEEE80211_STYPE_PROBE_REQ);
916 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
917 if (dst) {
918 memcpy(mgmt->da, dst, ETH_ALEN);
919 memcpy(mgmt->bssid, dst, ETH_ALEN);
920 } else {
921 memset(mgmt->da, 0xff, ETH_ALEN);
922 memset(mgmt->bssid, 0xff, ETH_ALEN);
923 }
924 pos = skb_put(skb, 2 + ssid_len);
925 *pos++ = WLAN_EID_SSID;
926 *pos++ = ssid_len;
927 memcpy(pos, ssid, ssid_len);
Johannes Bergde95a542009-04-01 11:58:36 +0200928 pos += ssid_len;
Johannes Berg46900292009-02-15 12:44:28 +0100929
Johannes Bergde95a542009-04-01 11:58:36 +0200930 skb_put(skb, ieee80211_build_preq_ies(local, pos, ie, ie_len));
Johannes Berg46900292009-02-15 12:44:28 +0100931
932 ieee80211_tx_skb(sdata, skb, 0);
933}
934
935u32 ieee80211_sta_get_rates(struct ieee80211_local *local,
936 struct ieee802_11_elems *elems,
937 enum ieee80211_band band)
938{
939 struct ieee80211_supported_band *sband;
940 struct ieee80211_rate *bitrates;
941 size_t num_rates;
942 u32 supp_rates;
943 int i, j;
944 sband = local->hw.wiphy->bands[band];
945
946 if (!sband) {
947 WARN_ON(1);
948 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
949 }
950
951 bitrates = sband->bitrates;
952 num_rates = sband->n_bitrates;
953 supp_rates = 0;
954 for (i = 0; i < elems->supp_rates_len +
955 elems->ext_supp_rates_len; i++) {
956 u8 rate = 0;
957 int own_rate;
958 if (i < elems->supp_rates_len)
959 rate = elems->supp_rates[i];
960 else if (elems->ext_supp_rates)
961 rate = elems->ext_supp_rates
962 [i - elems->supp_rates_len];
963 own_rate = 5 * (rate & 0x7f);
964 for (j = 0; j < num_rates; j++)
965 if (bitrates[j].bitrate == own_rate)
966 supp_rates |= BIT(j);
967 }
968 return supp_rates;
969}
Johannes Bergf2753dd2009-04-14 10:09:24 +0200970
971int ieee80211_reconfig(struct ieee80211_local *local)
972{
973 struct ieee80211_hw *hw = &local->hw;
974 struct ieee80211_sub_if_data *sdata;
975 struct ieee80211_if_init_conf conf;
976 struct sta_info *sta;
977 unsigned long flags;
978 int res;
979
980 /* restart hardware */
981 if (local->open_count) {
982 res = local->ops->start(hw);
983
984 ieee80211_led_radio(local, hw->conf.radio_enabled);
985 }
986
987 /* add interfaces */
988 list_for_each_entry(sdata, &local->interfaces, list) {
989 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
990 sdata->vif.type != NL80211_IFTYPE_MONITOR &&
991 netif_running(sdata->dev)) {
992 conf.vif = &sdata->vif;
993 conf.type = sdata->vif.type;
994 conf.mac_addr = sdata->dev->dev_addr;
995 res = local->ops->add_interface(hw, &conf);
996 }
997 }
998
999 /* add STAs back */
1000 if (local->ops->sta_notify) {
1001 spin_lock_irqsave(&local->sta_lock, flags);
1002 list_for_each_entry(sta, &local->sta_list, list) {
1003 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
1004 sdata = container_of(sdata->bss,
1005 struct ieee80211_sub_if_data,
1006 u.ap);
1007
1008 local->ops->sta_notify(hw, &sdata->vif,
1009 STA_NOTIFY_ADD, &sta->sta);
1010 }
1011 spin_unlock_irqrestore(&local->sta_lock, flags);
1012 }
1013
1014 /* Clear Suspend state so that ADDBA requests can be processed */
1015
1016 rcu_read_lock();
1017
1018 if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
1019 list_for_each_entry_rcu(sta, &local->sta_list, list) {
1020 clear_sta_flags(sta, WLAN_STA_SUSPEND);
1021 }
1022 }
1023
1024 rcu_read_unlock();
1025
1026 /* setup RTS threshold */
1027 if (local->ops->set_rts_threshold)
1028 local->ops->set_rts_threshold(hw, local->rts_threshold);
1029
1030 /* reconfigure hardware */
1031 ieee80211_hw_config(local, ~0);
1032
1033 netif_addr_lock_bh(local->mdev);
1034 ieee80211_configure_filter(local);
1035 netif_addr_unlock_bh(local->mdev);
1036
1037 /* Finally also reconfigure all the BSS information */
1038 list_for_each_entry(sdata, &local->interfaces, list) {
1039 u32 changed = ~0;
1040 if (!netif_running(sdata->dev))
1041 continue;
1042 switch (sdata->vif.type) {
1043 case NL80211_IFTYPE_STATION:
1044 /* disable beacon change bits */
1045 changed &= ~IEEE80211_IFCC_BEACON;
1046 /* fall through */
1047 case NL80211_IFTYPE_ADHOC:
1048 case NL80211_IFTYPE_AP:
1049 case NL80211_IFTYPE_MESH_POINT:
1050 /*
1051 * Driver's config_interface can fail if rfkill is
1052 * enabled. Accommodate this return code.
1053 * FIXME: When mac80211 has knowledge of rfkill
1054 * state the code below can change back to:
1055 * WARN(ieee80211_if_config(sdata, changed));
1056 * ieee80211_bss_info_change_notify(sdata, ~0);
1057 */
1058 if (ieee80211_if_config(sdata, changed))
1059 printk(KERN_DEBUG "%s: failed to configure interface during resume\n",
1060 sdata->dev->name);
1061 else
1062 ieee80211_bss_info_change_notify(sdata, ~0);
1063 break;
1064 case NL80211_IFTYPE_WDS:
1065 break;
1066 case NL80211_IFTYPE_AP_VLAN:
1067 case NL80211_IFTYPE_MONITOR:
1068 /* ignore virtual */
1069 break;
1070 case NL80211_IFTYPE_UNSPECIFIED:
1071 case __NL80211_IFTYPE_AFTER_LAST:
1072 WARN_ON(1);
1073 break;
1074 }
1075 }
1076
1077 /* add back keys */
1078 list_for_each_entry(sdata, &local->interfaces, list)
1079 if (netif_running(sdata->dev))
1080 ieee80211_enable_keys(sdata);
1081
1082 ieee80211_wake_queues_by_reason(hw,
1083 IEEE80211_QUEUE_STOP_REASON_SUSPEND);
1084
1085 return 0;
1086}