blob: 0247d8022f5f509305a69cbc9fb429078497cc9d [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"
31
32/* privid for wiphys to determine whether they belong to us or not */
33void *mac80211_wiphy_privid = &mac80211_wiphy_privid;
34
35/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
36/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
Senthil Balasubramanianc97c23e2008-05-28 23:15:32 +053037const unsigned char rfc1042_header[] __aligned(2) =
Johannes Bergc2d15602007-07-27 15:43:23 +020038 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
39
40/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
Senthil Balasubramanianc97c23e2008-05-28 23:15:32 +053041const unsigned char bridge_tunnel_header[] __aligned(2) =
Johannes Bergc2d15602007-07-27 15:43:23 +020042 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
43
Luis R. Rodriguez9a953712009-01-22 15:05:53 -080044struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy)
45{
46 struct ieee80211_local *local;
47 BUG_ON(!wiphy);
48
49 local = wiphy_priv(wiphy);
50 return &local->hw;
51}
52EXPORT_SYMBOL(wiphy_to_ieee80211_hw);
Johannes Bergc2d15602007-07-27 15:43:23 +020053
Ron Rindjunsky71364712007-12-25 17:00:36 +020054u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
Johannes Berg05c914f2008-09-11 00:01:58 +020055 enum nl80211_iftype type)
Johannes Bergc2d15602007-07-27 15:43:23 +020056{
Harvey Harrisona494bb12008-06-11 14:21:58 -070057 __le16 fc = hdr->frame_control;
Johannes Bergc2d15602007-07-27 15:43:23 +020058
Ron Rindjunsky98f0b0a2007-12-18 17:23:53 +020059 /* drop ACK/CTS frames and incorrect hdr len (ctrl) */
60 if (len < 16)
Johannes Bergc2d15602007-07-27 15:43:23 +020061 return NULL;
62
Harvey Harrisona494bb12008-06-11 14:21:58 -070063 if (ieee80211_is_data(fc)) {
Ron Rindjunsky98f0b0a2007-12-18 17:23:53 +020064 if (len < 24) /* drop incorrect hdr len (data) */
65 return NULL;
Harvey Harrisona494bb12008-06-11 14:21:58 -070066
67 if (ieee80211_has_a4(fc))
Johannes Bergc2d15602007-07-27 15:43:23 +020068 return NULL;
Harvey Harrisona494bb12008-06-11 14:21:58 -070069 if (ieee80211_has_tods(fc))
70 return hdr->addr1;
71 if (ieee80211_has_fromds(fc))
Johannes Bergc2d15602007-07-27 15:43:23 +020072 return hdr->addr2;
Harvey Harrisona494bb12008-06-11 14:21:58 -070073
74 return hdr->addr3;
75 }
76
77 if (ieee80211_is_mgmt(fc)) {
Ron Rindjunsky98f0b0a2007-12-18 17:23:53 +020078 if (len < 24) /* drop incorrect hdr len (mgmt) */
79 return NULL;
Johannes Bergc2d15602007-07-27 15:43:23 +020080 return hdr->addr3;
Harvey Harrisona494bb12008-06-11 14:21:58 -070081 }
82
83 if (ieee80211_is_ctl(fc)) {
84 if(ieee80211_is_pspoll(fc))
Johannes Bergc2d15602007-07-27 15:43:23 +020085 return hdr->addr1;
Harvey Harrisona494bb12008-06-11 14:21:58 -070086
87 if (ieee80211_is_back_req(fc)) {
Ron Rindjunsky71364712007-12-25 17:00:36 +020088 switch (type) {
Johannes Berg05c914f2008-09-11 00:01:58 +020089 case NL80211_IFTYPE_STATION:
Ron Rindjunsky71364712007-12-25 17:00:36 +020090 return hdr->addr2;
Johannes Berg05c914f2008-09-11 00:01:58 +020091 case NL80211_IFTYPE_AP:
92 case NL80211_IFTYPE_AP_VLAN:
Ron Rindjunsky71364712007-12-25 17:00:36 +020093 return hdr->addr1;
94 default:
Harvey Harrisona494bb12008-06-11 14:21:58 -070095 break; /* fall through to the return */
Ron Rindjunsky71364712007-12-25 17:00:36 +020096 }
97 }
Johannes Bergc2d15602007-07-27 15:43:23 +020098 }
99
100 return NULL;
101}
102
Harvey Harrison6693be72008-06-11 14:21:57 -0700103unsigned int ieee80211_hdrlen(__le16 fc)
104{
105 unsigned int hdrlen = 24;
106
107 if (ieee80211_is_data(fc)) {
108 if (ieee80211_has_a4(fc))
109 hdrlen = 30;
110 if (ieee80211_is_data_qos(fc))
111 hdrlen += IEEE80211_QOS_CTL_LEN;
112 goto out;
113 }
114
115 if (ieee80211_is_ctl(fc)) {
116 /*
117 * ACK and CTS are 10 bytes, all others 16. To see how
118 * to get this condition consider
119 * subtype mask: 0b0000000011110000 (0x00F0)
120 * ACK subtype: 0b0000000011010000 (0x00D0)
121 * CTS subtype: 0b0000000011000000 (0x00C0)
122 * bits that matter: ^^^ (0x00E0)
123 * value of those: 0b0000000011000000 (0x00C0)
124 */
125 if ((fc & cpu_to_le16(0x00E0)) == cpu_to_le16(0x00C0))
126 hdrlen = 10;
127 else
128 hdrlen = 16;
129 }
130out:
131 return hdrlen;
132}
133EXPORT_SYMBOL(ieee80211_hdrlen);
134
Harvey Harrisonc9c69502008-06-11 14:21:57 -0700135unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
Johannes Bergc2d15602007-07-27 15:43:23 +0200136{
Harvey Harrisonc9c69502008-06-11 14:21:57 -0700137 const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *)skb->data;
138 unsigned int hdrlen;
Johannes Bergc2d15602007-07-27 15:43:23 +0200139
140 if (unlikely(skb->len < 10))
141 return 0;
Harvey Harrisonc9c69502008-06-11 14:21:57 -0700142 hdrlen = ieee80211_hdrlen(hdr->frame_control);
Johannes Bergc2d15602007-07-27 15:43:23 +0200143 if (unlikely(hdrlen > skb->len))
144 return 0;
145 return hdrlen;
146}
147EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
148
Luis Carlos Coboee385852008-02-23 15:17:11 +0100149int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
150{
151 int ae = meshhdr->flags & IEEE80211S_FLAGS_AE;
152 /* 7.1.3.5a.2 */
153 switch (ae) {
154 case 0:
Luis Carlos Coboef269252008-05-05 12:02:35 -0700155 return 6;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100156 case 1:
Luis Carlos Coboef269252008-05-05 12:02:35 -0700157 return 12;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100158 case 2:
Luis Carlos Coboef269252008-05-05 12:02:35 -0700159 return 18;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100160 case 3:
Luis Carlos Coboef269252008-05-05 12:02:35 -0700161 return 24;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100162 default:
Luis Carlos Coboef269252008-05-05 12:02:35 -0700163 return 6;
Luis Carlos Coboee385852008-02-23 15:17:11 +0100164 }
165}
Luis Carlos Coboee385852008-02-23 15:17:11 +0100166
Johannes Berg5cf121c2008-02-25 16:27:43 +0100167void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx)
Johannes Bergc2d15602007-07-27 15:43:23 +0200168{
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100169 struct sk_buff *skb = tx->skb;
170 struct ieee80211_hdr *hdr;
Johannes Bergc2d15602007-07-27 15:43:23 +0200171
Johannes Berg2de8e0d2009-03-23 17:28:35 +0100172 do {
173 hdr = (struct ieee80211_hdr *) skb->data;
174 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
175 } while ((skb = skb->next));
Johannes Bergc2d15602007-07-27 15:43:23 +0200176}
177
178int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
179 int rate, int erp, int short_preamble)
180{
181 int dur;
182
183 /* calculate duration (in microseconds, rounded up to next higher
184 * integer if it includes a fractional microsecond) to send frame of
185 * len bytes (does not include FCS) at the given rate. Duration will
186 * also include SIFS.
187 *
188 * rate is in 100 kbps, so divident is multiplied by 10 in the
189 * DIV_ROUND_UP() operations.
190 */
191
Johannes Berg8318d782008-01-24 19:38:38 +0100192 if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ || erp) {
Johannes Bergc2d15602007-07-27 15:43:23 +0200193 /*
194 * OFDM:
195 *
196 * N_DBPS = DATARATE x 4
197 * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
198 * (16 = SIGNAL time, 6 = tail bits)
199 * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
200 *
201 * T_SYM = 4 usec
202 * 802.11a - 17.5.2: aSIFSTime = 16 usec
203 * 802.11g - 19.8.4: aSIFSTime = 10 usec +
204 * signal ext = 6 usec
205 */
Johannes Bergc2d15602007-07-27 15:43:23 +0200206 dur = 16; /* SIFS + signal ext */
207 dur += 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */
208 dur += 4; /* 17.3.2.3: T_SIGNAL = 4 usec */
209 dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10,
210 4 * rate); /* T_SYM x N_SYM */
211 } else {
212 /*
213 * 802.11b or 802.11g with 802.11b compatibility:
214 * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
215 * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
216 *
217 * 802.11 (DS): 15.3.3, 802.11b: 18.3.4
218 * aSIFSTime = 10 usec
219 * aPreambleLength = 144 usec or 72 usec with short preamble
220 * aPLCPHeaderLength = 48 usec or 24 usec with short preamble
221 */
222 dur = 10; /* aSIFSTime = 10 usec */
223 dur += short_preamble ? (72 + 24) : (144 + 48);
224
225 dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate);
226 }
227
228 return dur;
229}
230
231/* Exported duration function for driver use */
Johannes Berg32bfd352007-12-19 01:31:26 +0100232__le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
233 struct ieee80211_vif *vif,
Johannes Berg8318d782008-01-24 19:38:38 +0100234 size_t frame_len,
235 struct ieee80211_rate *rate)
Johannes Bergc2d15602007-07-27 15:43:23 +0200236{
237 struct ieee80211_local *local = hw_to_local(hw);
Johannes Berg25d834e2008-09-12 22:52:47 +0200238 struct ieee80211_sub_if_data *sdata;
Johannes Bergc2d15602007-07-27 15:43:23 +0200239 u16 dur;
240 int erp;
Johannes Berg25d834e2008-09-12 22:52:47 +0200241 bool short_preamble = false;
Johannes Bergc2d15602007-07-27 15:43:23 +0200242
Johannes Berg8318d782008-01-24 19:38:38 +0100243 erp = 0;
Johannes Berg25d834e2008-09-12 22:52:47 +0200244 if (vif) {
245 sdata = vif_to_sdata(vif);
Johannes Bergbda39332008-10-11 01:51:51 +0200246 short_preamble = sdata->vif.bss_conf.use_short_preamble;
Johannes Berg25d834e2008-09-12 22:52:47 +0200247 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
248 erp = rate->flags & IEEE80211_RATE_ERP_G;
249 }
Johannes Berg8318d782008-01-24 19:38:38 +0100250
251 dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, erp,
Johannes Berg25d834e2008-09-12 22:52:47 +0200252 short_preamble);
Johannes Bergc2d15602007-07-27 15:43:23 +0200253
254 return cpu_to_le16(dur);
255}
256EXPORT_SYMBOL(ieee80211_generic_frame_duration);
257
Johannes Berg32bfd352007-12-19 01:31:26 +0100258__le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
259 struct ieee80211_vif *vif, size_t frame_len,
Johannes Berge039fa42008-05-15 12:55:29 +0200260 const struct ieee80211_tx_info *frame_txctl)
Johannes Bergc2d15602007-07-27 15:43:23 +0200261{
262 struct ieee80211_local *local = hw_to_local(hw);
263 struct ieee80211_rate *rate;
Johannes Berg25d834e2008-09-12 22:52:47 +0200264 struct ieee80211_sub_if_data *sdata;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100265 bool short_preamble;
Johannes Bergc2d15602007-07-27 15:43:23 +0200266 int erp;
267 u16 dur;
Johannes Berg2e92e6f2008-05-15 12:55:27 +0200268 struct ieee80211_supported_band *sband;
269
270 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
Johannes Bergc2d15602007-07-27 15:43:23 +0200271
Johannes Berg25d834e2008-09-12 22:52:47 +0200272 short_preamble = false;
Daniel Drake7e9ed182007-07-27 15:43:24 +0200273
Johannes Berge039fa42008-05-15 12:55:29 +0200274 rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
Johannes Berg8318d782008-01-24 19:38:38 +0100275
276 erp = 0;
Johannes Berg25d834e2008-09-12 22:52:47 +0200277 if (vif) {
278 sdata = vif_to_sdata(vif);
Johannes Bergbda39332008-10-11 01:51:51 +0200279 short_preamble = sdata->vif.bss_conf.use_short_preamble;
Johannes Berg25d834e2008-09-12 22:52:47 +0200280 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
281 erp = rate->flags & IEEE80211_RATE_ERP_G;
282 }
Johannes Bergc2d15602007-07-27 15:43:23 +0200283
284 /* CTS duration */
Johannes Berg8318d782008-01-24 19:38:38 +0100285 dur = ieee80211_frame_duration(local, 10, rate->bitrate,
Johannes Bergc2d15602007-07-27 15:43:23 +0200286 erp, short_preamble);
287 /* Data frame duration */
Johannes Berg8318d782008-01-24 19:38:38 +0100288 dur += ieee80211_frame_duration(local, frame_len, rate->bitrate,
Johannes Bergc2d15602007-07-27 15:43:23 +0200289 erp, short_preamble);
290 /* ACK duration */
Johannes Berg8318d782008-01-24 19:38:38 +0100291 dur += ieee80211_frame_duration(local, 10, rate->bitrate,
Johannes Bergc2d15602007-07-27 15:43:23 +0200292 erp, short_preamble);
293
294 return cpu_to_le16(dur);
295}
296EXPORT_SYMBOL(ieee80211_rts_duration);
297
Johannes Berg32bfd352007-12-19 01:31:26 +0100298__le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
299 struct ieee80211_vif *vif,
Johannes Bergc2d15602007-07-27 15:43:23 +0200300 size_t frame_len,
Johannes Berge039fa42008-05-15 12:55:29 +0200301 const struct ieee80211_tx_info *frame_txctl)
Johannes Bergc2d15602007-07-27 15:43:23 +0200302{
303 struct ieee80211_local *local = hw_to_local(hw);
304 struct ieee80211_rate *rate;
Johannes Berg25d834e2008-09-12 22:52:47 +0200305 struct ieee80211_sub_if_data *sdata;
Johannes Berg471b3ef2007-12-28 14:32:58 +0100306 bool short_preamble;
Johannes Bergc2d15602007-07-27 15:43:23 +0200307 int erp;
308 u16 dur;
Johannes Berg2e92e6f2008-05-15 12:55:27 +0200309 struct ieee80211_supported_band *sband;
310
311 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
Johannes Bergc2d15602007-07-27 15:43:23 +0200312
Johannes Berg25d834e2008-09-12 22:52:47 +0200313 short_preamble = false;
Daniel Drake7e9ed182007-07-27 15:43:24 +0200314
Johannes Berge039fa42008-05-15 12:55:29 +0200315 rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
Johannes Berg8318d782008-01-24 19:38:38 +0100316 erp = 0;
Johannes Berg25d834e2008-09-12 22:52:47 +0200317 if (vif) {
318 sdata = vif_to_sdata(vif);
Johannes Bergbda39332008-10-11 01:51:51 +0200319 short_preamble = sdata->vif.bss_conf.use_short_preamble;
Johannes Berg25d834e2008-09-12 22:52:47 +0200320 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
321 erp = rate->flags & IEEE80211_RATE_ERP_G;
322 }
Johannes Bergc2d15602007-07-27 15:43:23 +0200323
324 /* Data frame duration */
Johannes Berg8318d782008-01-24 19:38:38 +0100325 dur = ieee80211_frame_duration(local, frame_len, rate->bitrate,
Johannes Bergc2d15602007-07-27 15:43:23 +0200326 erp, short_preamble);
Johannes Berge039fa42008-05-15 12:55:29 +0200327 if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) {
Johannes Bergc2d15602007-07-27 15:43:23 +0200328 /* ACK duration */
Johannes Berg8318d782008-01-24 19:38:38 +0100329 dur += ieee80211_frame_duration(local, 10, rate->bitrate,
Johannes Bergc2d15602007-07-27 15:43:23 +0200330 erp, short_preamble);
331 }
332
Johannes Bergc2d15602007-07-27 15:43:23 +0200333 return cpu_to_le16(dur);
334}
335EXPORT_SYMBOL(ieee80211_ctstoself_duration);
336
Kalle Valoce7c9112008-12-18 23:35:20 +0200337static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue,
338 enum queue_stop_reason reason)
Johannes Bergc2d15602007-07-27 15:43:23 +0200339{
340 struct ieee80211_local *local = hw_to_local(hw);
341
Johannes Berg96f5e662009-02-12 00:51:53 +0100342 if (queue >= hw->queues) {
343 if (local->ampdu_ac_queue[queue - hw->queues] < 0)
Kalle Valoce7c9112008-12-18 23:35:20 +0200344 return;
Johannes Berg96f5e662009-02-12 00:51:53 +0100345
346 /*
347 * for virtual aggregation queues, we need to refcount the
348 * internal mac80211 disable (multiple times!), keep track of
349 * driver disable _and_ make sure the regular queue is
350 * actually enabled.
351 */
352 if (reason == IEEE80211_QUEUE_STOP_REASON_AGGREGATION)
353 local->amdpu_ac_stop_refcnt[queue - hw->queues]--;
354 else
355 __clear_bit(reason, &local->queue_stop_reasons[queue]);
356
357 if (local->queue_stop_reasons[queue] ||
358 local->amdpu_ac_stop_refcnt[queue - hw->queues])
359 return;
360
361 /* now go on to treat the corresponding regular queue */
362 queue = local->ampdu_ac_queue[queue - hw->queues];
363 reason = IEEE80211_QUEUE_STOP_REASON_AGGREGATION;
Kalle Valoce7c9112008-12-18 23:35:20 +0200364 }
365
Johannes Berg96f5e662009-02-12 00:51:53 +0100366 __clear_bit(reason, &local->queue_stop_reasons[queue]);
367
Johannes Berg2a577d92009-03-23 17:28:37 +0100368 if (!skb_queue_empty(&local->pending[queue]) &&
369 local->queue_stop_reasons[queue] ==
370 BIT(IEEE80211_QUEUE_STOP_REASON_PENDING))
371 tasklet_schedule(&local->tx_pending_tasklet);
372
Johannes Berg96f5e662009-02-12 00:51:53 +0100373 if (local->queue_stop_reasons[queue] != 0)
374 /* someone still has this queue stopped */
375 return;
376
Johannes Berg2a577d92009-03-23 17:28:37 +0100377 netif_wake_subqueue(local->mdev, queue);
Johannes Bergc2d15602007-07-27 15:43:23 +0200378}
Kalle Valoce7c9112008-12-18 23:35:20 +0200379
Johannes Berg96f5e662009-02-12 00:51:53 +0100380void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
381 enum queue_stop_reason reason)
Kalle Valoce7c9112008-12-18 23:35:20 +0200382{
383 struct ieee80211_local *local = hw_to_local(hw);
384 unsigned long flags;
385
386 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
387 __ieee80211_wake_queue(hw, queue, reason);
388 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
389}
390
391void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
392{
393 ieee80211_wake_queue_by_reason(hw, queue,
394 IEEE80211_QUEUE_STOP_REASON_DRIVER);
395}
Johannes Bergc2d15602007-07-27 15:43:23 +0200396EXPORT_SYMBOL(ieee80211_wake_queue);
397
Kalle Valoce7c9112008-12-18 23:35:20 +0200398static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue,
399 enum queue_stop_reason reason)
Johannes Bergc2d15602007-07-27 15:43:23 +0200400{
401 struct ieee80211_local *local = hw_to_local(hw);
402
Johannes Berg96f5e662009-02-12 00:51:53 +0100403 if (queue >= hw->queues) {
404 if (local->ampdu_ac_queue[queue - hw->queues] < 0)
405 return;
406
407 /*
408 * for virtual aggregation queues, we need to refcount the
409 * internal mac80211 disable (multiple times!), keep track of
410 * driver disable _and_ make sure the regular queue is
411 * actually enabled.
412 */
413 if (reason == IEEE80211_QUEUE_STOP_REASON_AGGREGATION)
414 local->amdpu_ac_stop_refcnt[queue - hw->queues]++;
415 else
416 __set_bit(reason, &local->queue_stop_reasons[queue]);
417
418 /* now go on to treat the corresponding regular queue */
419 queue = local->ampdu_ac_queue[queue - hw->queues];
420 reason = IEEE80211_QUEUE_STOP_REASON_AGGREGATION;
421 }
422
Johannes Berg2a577d92009-03-23 17:28:37 +0100423 /*
424 * Only stop if it was previously running, this is necessary
425 * for correct pending packets handling because there we may
426 * start (but not wake) the queue and rely on that.
427 */
428 if (!local->queue_stop_reasons[queue])
429 netif_stop_subqueue(local->mdev, queue);
Kalle Valoce7c9112008-12-18 23:35:20 +0200430
Johannes Berg2a577d92009-03-23 17:28:37 +0100431 __set_bit(reason, &local->queue_stop_reasons[queue]);
Johannes Bergc2d15602007-07-27 15:43:23 +0200432}
Kalle Valoce7c9112008-12-18 23:35:20 +0200433
Johannes Berg96f5e662009-02-12 00:51:53 +0100434void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue,
435 enum queue_stop_reason reason)
Kalle Valoce7c9112008-12-18 23:35:20 +0200436{
437 struct ieee80211_local *local = hw_to_local(hw);
438 unsigned long flags;
439
440 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
441 __ieee80211_stop_queue(hw, queue, reason);
442 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
443}
444
445void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue)
446{
447 ieee80211_stop_queue_by_reason(hw, queue,
448 IEEE80211_QUEUE_STOP_REASON_DRIVER);
449}
Johannes Bergc2d15602007-07-27 15:43:23 +0200450EXPORT_SYMBOL(ieee80211_stop_queue);
451
Kalle Valoce7c9112008-12-18 23:35:20 +0200452void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw,
453 enum queue_stop_reason reason)
Johannes Bergc2d15602007-07-27 15:43:23 +0200454{
Kalle Valoce7c9112008-12-18 23:35:20 +0200455 struct ieee80211_local *local = hw_to_local(hw);
456 unsigned long flags;
Johannes Bergc2d15602007-07-27 15:43:23 +0200457 int i;
458
Kalle Valoce7c9112008-12-18 23:35:20 +0200459 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
460
Johannes Berg96f5e662009-02-12 00:51:53 +0100461 for (i = 0; i < hw->queues; i++)
Kalle Valoce7c9112008-12-18 23:35:20 +0200462 __ieee80211_stop_queue(hw, i, reason);
463
464 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
465}
466
467void ieee80211_stop_queues(struct ieee80211_hw *hw)
468{
469 ieee80211_stop_queues_by_reason(hw,
470 IEEE80211_QUEUE_STOP_REASON_DRIVER);
Johannes Bergc2d15602007-07-27 15:43:23 +0200471}
472EXPORT_SYMBOL(ieee80211_stop_queues);
473
Tomas Winkler92ab8532008-07-24 21:02:04 +0300474int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue)
475{
476 struct ieee80211_local *local = hw_to_local(hw);
Johannes Berg96f5e662009-02-12 00:51:53 +0100477 unsigned long flags;
478
479 if (queue >= hw->queues) {
480 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
481 queue = local->ampdu_ac_queue[queue - hw->queues];
482 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
483 if (queue < 0)
484 return true;
485 }
486
Tomas Winkler92ab8532008-07-24 21:02:04 +0300487 return __netif_subqueue_stopped(local->mdev, queue);
488}
489EXPORT_SYMBOL(ieee80211_queue_stopped);
490
Kalle Valoce7c9112008-12-18 23:35:20 +0200491void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw,
492 enum queue_stop_reason reason)
Johannes Bergc2d15602007-07-27 15:43:23 +0200493{
Kalle Valoce7c9112008-12-18 23:35:20 +0200494 struct ieee80211_local *local = hw_to_local(hw);
495 unsigned long flags;
Johannes Bergc2d15602007-07-27 15:43:23 +0200496 int i;
497
Kalle Valoce7c9112008-12-18 23:35:20 +0200498 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
499
Johannes Bergc4680472008-05-15 12:55:25 +0200500 for (i = 0; i < hw->queues + hw->ampdu_queues; i++)
Kalle Valoce7c9112008-12-18 23:35:20 +0200501 __ieee80211_wake_queue(hw, i, reason);
502
503 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
504}
505
506void ieee80211_wake_queues(struct ieee80211_hw *hw)
507{
508 ieee80211_wake_queues_by_reason(hw, IEEE80211_QUEUE_STOP_REASON_DRIVER);
Johannes Bergc2d15602007-07-27 15:43:23 +0200509}
510EXPORT_SYMBOL(ieee80211_wake_queues);
Johannes Bergdabeb342007-11-09 01:57:29 +0100511
Johannes Berg32bfd352007-12-19 01:31:26 +0100512void ieee80211_iterate_active_interfaces(
513 struct ieee80211_hw *hw,
514 void (*iterator)(void *data, u8 *mac,
515 struct ieee80211_vif *vif),
516 void *data)
Johannes Bergdabeb342007-11-09 01:57:29 +0100517{
518 struct ieee80211_local *local = hw_to_local(hw);
519 struct ieee80211_sub_if_data *sdata;
520
Johannes Bergc771c9d2009-01-23 22:54:03 +0100521 mutex_lock(&local->iflist_mtx);
Ivo van Doorn2f561fe2008-05-10 13:40:49 +0200522
523 list_for_each_entry(sdata, &local->interfaces, list) {
524 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200525 case __NL80211_IFTYPE_AFTER_LAST:
526 case NL80211_IFTYPE_UNSPECIFIED:
527 case NL80211_IFTYPE_MONITOR:
528 case NL80211_IFTYPE_AP_VLAN:
Ivo van Doorn2f561fe2008-05-10 13:40:49 +0200529 continue;
Johannes Berg05c914f2008-09-11 00:01:58 +0200530 case NL80211_IFTYPE_AP:
531 case NL80211_IFTYPE_STATION:
532 case NL80211_IFTYPE_ADHOC:
533 case NL80211_IFTYPE_WDS:
534 case NL80211_IFTYPE_MESH_POINT:
Ivo van Doorn2f561fe2008-05-10 13:40:49 +0200535 break;
536 }
Ivo van Doorn2f561fe2008-05-10 13:40:49 +0200537 if (netif_running(sdata->dev))
538 iterator(data, sdata->dev->dev_addr,
539 &sdata->vif);
540 }
541
Johannes Bergc771c9d2009-01-23 22:54:03 +0100542 mutex_unlock(&local->iflist_mtx);
Ivo van Doorn2f561fe2008-05-10 13:40:49 +0200543}
544EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces);
545
546void ieee80211_iterate_active_interfaces_atomic(
547 struct ieee80211_hw *hw,
548 void (*iterator)(void *data, u8 *mac,
549 struct ieee80211_vif *vif),
550 void *data)
551{
552 struct ieee80211_local *local = hw_to_local(hw);
553 struct ieee80211_sub_if_data *sdata;
554
Johannes Berge38bad42007-11-28 10:55:32 +0100555 rcu_read_lock();
Johannes Bergdabeb342007-11-09 01:57:29 +0100556
Johannes Berge38bad42007-11-28 10:55:32 +0100557 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Berg51fb61e2007-12-19 01:31:27 +0100558 switch (sdata->vif.type) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200559 case __NL80211_IFTYPE_AFTER_LAST:
560 case NL80211_IFTYPE_UNSPECIFIED:
561 case NL80211_IFTYPE_MONITOR:
562 case NL80211_IFTYPE_AP_VLAN:
Johannes Bergdabeb342007-11-09 01:57:29 +0100563 continue;
Johannes Berg05c914f2008-09-11 00:01:58 +0200564 case NL80211_IFTYPE_AP:
565 case NL80211_IFTYPE_STATION:
566 case NL80211_IFTYPE_ADHOC:
567 case NL80211_IFTYPE_WDS:
568 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergdabeb342007-11-09 01:57:29 +0100569 break;
570 }
Johannes Bergdabeb342007-11-09 01:57:29 +0100571 if (netif_running(sdata->dev))
572 iterator(data, sdata->dev->dev_addr,
Johannes Berg32bfd352007-12-19 01:31:26 +0100573 &sdata->vif);
Johannes Bergdabeb342007-11-09 01:57:29 +0100574 }
Johannes Berge38bad42007-11-28 10:55:32 +0100575
576 rcu_read_unlock();
Johannes Bergdabeb342007-11-09 01:57:29 +0100577}
Ivo van Doorn2f561fe2008-05-10 13:40:49 +0200578EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic);
Johannes Berg37ffc8d2008-09-08 16:40:36 +0200579
580void ieee802_11_parse_elems(u8 *start, size_t len,
581 struct ieee802_11_elems *elems)
582{
583 size_t left = len;
584 u8 *pos = start;
585
586 memset(elems, 0, sizeof(*elems));
587 elems->ie_start = start;
588 elems->total_len = len;
589
590 while (left >= 2) {
591 u8 id, elen;
592
593 id = *pos++;
594 elen = *pos++;
595 left -= 2;
596
597 if (elen > left)
598 return;
599
600 switch (id) {
601 case WLAN_EID_SSID:
602 elems->ssid = pos;
603 elems->ssid_len = elen;
604 break;
605 case WLAN_EID_SUPP_RATES:
606 elems->supp_rates = pos;
607 elems->supp_rates_len = elen;
608 break;
609 case WLAN_EID_FH_PARAMS:
610 elems->fh_params = pos;
611 elems->fh_params_len = elen;
612 break;
613 case WLAN_EID_DS_PARAMS:
614 elems->ds_params = pos;
615 elems->ds_params_len = elen;
616 break;
617 case WLAN_EID_CF_PARAMS:
618 elems->cf_params = pos;
619 elems->cf_params_len = elen;
620 break;
621 case WLAN_EID_TIM:
622 elems->tim = pos;
623 elems->tim_len = elen;
624 break;
625 case WLAN_EID_IBSS_PARAMS:
626 elems->ibss_params = pos;
627 elems->ibss_params_len = elen;
628 break;
629 case WLAN_EID_CHALLENGE:
630 elems->challenge = pos;
631 elems->challenge_len = elen;
632 break;
633 case WLAN_EID_WPA:
634 if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
635 pos[2] == 0xf2) {
636 /* Microsoft OUI (00:50:F2) */
637 if (pos[3] == 1) {
638 /* OUI Type 1 - WPA IE */
639 elems->wpa = pos;
640 elems->wpa_len = elen;
641 } else if (elen >= 5 && pos[3] == 2) {
642 if (pos[4] == 0) {
643 elems->wmm_info = pos;
644 elems->wmm_info_len = elen;
645 } else if (pos[4] == 1) {
646 elems->wmm_param = pos;
647 elems->wmm_param_len = elen;
648 }
649 }
650 }
651 break;
652 case WLAN_EID_RSN:
653 elems->rsn = pos;
654 elems->rsn_len = elen;
655 break;
656 case WLAN_EID_ERP_INFO:
657 elems->erp_info = pos;
658 elems->erp_info_len = elen;
659 break;
660 case WLAN_EID_EXT_SUPP_RATES:
661 elems->ext_supp_rates = pos;
662 elems->ext_supp_rates_len = elen;
663 break;
664 case WLAN_EID_HT_CAPABILITY:
Johannes Berg09914812008-10-07 19:31:17 +0200665 if (elen >= sizeof(struct ieee80211_ht_cap))
666 elems->ht_cap_elem = (void *)pos;
Johannes Berg37ffc8d2008-09-08 16:40:36 +0200667 break;
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200668 case WLAN_EID_HT_INFORMATION:
669 if (elen >= sizeof(struct ieee80211_ht_info))
Johannes Berg09914812008-10-07 19:31:17 +0200670 elems->ht_info_elem = (void *)pos;
Johannes Berg37ffc8d2008-09-08 16:40:36 +0200671 break;
672 case WLAN_EID_MESH_ID:
673 elems->mesh_id = pos;
674 elems->mesh_id_len = elen;
675 break;
676 case WLAN_EID_MESH_CONFIG:
677 elems->mesh_config = pos;
678 elems->mesh_config_len = elen;
679 break;
680 case WLAN_EID_PEER_LINK:
681 elems->peer_link = pos;
682 elems->peer_link_len = elen;
683 break;
684 case WLAN_EID_PREQ:
685 elems->preq = pos;
686 elems->preq_len = elen;
687 break;
688 case WLAN_EID_PREP:
689 elems->prep = pos;
690 elems->prep_len = elen;
691 break;
692 case WLAN_EID_PERR:
693 elems->perr = pos;
694 elems->perr_len = elen;
695 break;
696 case WLAN_EID_CHANNEL_SWITCH:
697 elems->ch_switch_elem = pos;
698 elems->ch_switch_elem_len = elen;
699 break;
700 case WLAN_EID_QUIET:
701 if (!elems->quiet_elem) {
702 elems->quiet_elem = pos;
703 elems->quiet_elem_len = elen;
704 }
705 elems->num_of_quiet_elem++;
706 break;
707 case WLAN_EID_COUNTRY:
708 elems->country_elem = pos;
709 elems->country_elem_len = elen;
710 break;
711 case WLAN_EID_PWR_CONSTRAINT:
712 elems->pwr_constr_elem = pos;
713 elems->pwr_constr_elem_len = elen;
714 break;
Jouni Malinenf797eb72009-01-19 18:48:46 +0200715 case WLAN_EID_TIMEOUT_INTERVAL:
716 elems->timeout_int = pos;
717 elems->timeout_int_len = elen;
Jouni Malinen63a5ab82009-01-08 13:32:09 +0200718 break;
Johannes Berg37ffc8d2008-09-08 16:40:36 +0200719 default:
720 break;
721 }
722
723 left -= elen;
724 pos += elen;
725 }
726}
Johannes Berg5825fe12008-09-09 12:56:01 +0200727
728void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata)
729{
730 struct ieee80211_local *local = sdata->local;
731 struct ieee80211_tx_queue_params qparam;
732 int i;
733
734 if (!local->ops->conf_tx)
735 return;
736
737 memset(&qparam, 0, sizeof(qparam));
738
739 qparam.aifs = 2;
740
741 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
742 !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE))
743 qparam.cw_min = 31;
744 else
745 qparam.cw_min = 15;
746
747 qparam.cw_max = 1023;
748 qparam.txop = 0;
749
750 for (i = 0; i < local_to_hw(local)->queues; i++)
751 local->ops->conf_tx(local_to_hw(local), i, &qparam);
752}
Johannes Berge50db652008-09-09 15:07:09 +0200753
Johannes Berg46900292009-02-15 12:44:28 +0100754void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
755 const size_t supp_rates_len,
756 const u8 *supp_rates)
757{
758 struct ieee80211_local *local = sdata->local;
759 int i, have_higher_than_11mbit = 0;
760
761 /* cf. IEEE 802.11 9.2.12 */
762 for (i = 0; i < supp_rates_len; i++)
763 if ((supp_rates[i] & 0x7f) * 5 > 110)
764 have_higher_than_11mbit = 1;
765
766 if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
767 have_higher_than_11mbit)
768 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
769 else
770 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
771
772 ieee80211_set_wmm_default(sdata);
773}
774
Johannes Berge50db652008-09-09 15:07:09 +0200775void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
776 int encrypt)
777{
778 skb->dev = sdata->local->mdev;
779 skb_set_mac_header(skb, 0);
780 skb_set_network_header(skb, 0);
781 skb_set_transport_header(skb, 0);
782
783 skb->iif = sdata->dev->ifindex;
784 skb->do_not_encrypt = !encrypt;
785
786 dev_queue_xmit(skb);
787}
Johannes Berge16751c2008-09-11 00:01:53 +0200788
789int ieee80211_set_freq(struct ieee80211_sub_if_data *sdata, int freqMHz)
790{
791 int ret = -EINVAL;
792 struct ieee80211_channel *chan;
793 struct ieee80211_local *local = sdata->local;
794
795 chan = ieee80211_get_channel(local->hw.wiphy, freqMHz);
796
797 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200798 if (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
Johannes Bergd73782f2008-10-07 12:04:34 +0200799 chan->flags & IEEE80211_CHAN_NO_IBSS)
Johannes Berge16751c2008-09-11 00:01:53 +0200800 return ret;
Johannes Berge16751c2008-09-11 00:01:53 +0200801 local->oper_channel = chan;
Sujith094d05d2008-12-12 11:57:43 +0530802 local->oper_channel_type = NL80211_CHAN_NO_HT;
Johannes Berge16751c2008-09-11 00:01:53 +0200803
Johannes Bergc2b13452008-09-11 00:01:55 +0200804 if (local->sw_scanning || local->hw_scanning)
Johannes Berge16751c2008-09-11 00:01:53 +0200805 ret = 0;
806 else
Johannes Berge8975582008-10-09 12:18:51 +0200807 ret = ieee80211_hw_config(
808 local, IEEE80211_CONF_CHANGE_CHANNEL);
Johannes Berge16751c2008-09-11 00:01:53 +0200809 }
810
811 return ret;
812}
Johannes Berg96dd22a2008-09-11 00:01:57 +0200813
Johannes Berg881d9482009-01-21 15:13:48 +0100814u32 ieee80211_mandatory_rates(struct ieee80211_local *local,
Johannes Berg96dd22a2008-09-11 00:01:57 +0200815 enum ieee80211_band band)
816{
817 struct ieee80211_supported_band *sband;
818 struct ieee80211_rate *bitrates;
Johannes Berg881d9482009-01-21 15:13:48 +0100819 u32 mandatory_rates;
Johannes Berg96dd22a2008-09-11 00:01:57 +0200820 enum ieee80211_rate_flags mandatory_flag;
821 int i;
822
823 sband = local->hw.wiphy->bands[band];
824 if (!sband) {
825 WARN_ON(1);
826 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
827 }
828
829 if (band == IEEE80211_BAND_2GHZ)
830 mandatory_flag = IEEE80211_RATE_MANDATORY_B;
831 else
832 mandatory_flag = IEEE80211_RATE_MANDATORY_A;
833
834 bitrates = sband->bitrates;
835 mandatory_rates = 0;
836 for (i = 0; i < sband->n_bitrates; i++)
837 if (bitrates[i].flags & mandatory_flag)
838 mandatory_rates |= BIT(i);
839 return mandatory_rates;
840}
Johannes Berg46900292009-02-15 12:44:28 +0100841
842void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
843 u16 transaction, u16 auth_alg,
844 u8 *extra, size_t extra_len,
845 const u8 *bssid, int encrypt)
846{
847 struct ieee80211_local *local = sdata->local;
848 struct sk_buff *skb;
849 struct ieee80211_mgmt *mgmt;
Johannes Berg46900292009-02-15 12:44:28 +0100850
851 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200852 sizeof(*mgmt) + 6 + extra_len);
Johannes Berg46900292009-02-15 12:44:28 +0100853 if (!skb) {
854 printk(KERN_DEBUG "%s: failed to allocate buffer for auth "
855 "frame\n", sdata->dev->name);
856 return;
857 }
858 skb_reserve(skb, local->hw.extra_tx_headroom);
859
860 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
861 memset(mgmt, 0, 24 + 6);
862 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
863 IEEE80211_STYPE_AUTH);
864 if (encrypt)
865 mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
866 memcpy(mgmt->da, bssid, ETH_ALEN);
867 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
868 memcpy(mgmt->bssid, bssid, ETH_ALEN);
869 mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg);
870 mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
871 mgmt->u.auth.status_code = cpu_to_le16(0);
872 if (extra)
873 memcpy(skb_put(skb, extra_len), extra, extra_len);
Johannes Berg46900292009-02-15 12:44:28 +0100874
875 ieee80211_tx_skb(sdata, skb, encrypt);
876}
877
878void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
Jouni Malinen70692ad2009-02-16 19:39:13 +0200879 u8 *ssid, size_t ssid_len,
880 u8 *ie, size_t ie_len)
Johannes Berg46900292009-02-15 12:44:28 +0100881{
882 struct ieee80211_local *local = sdata->local;
883 struct ieee80211_supported_band *sband;
884 struct sk_buff *skb;
885 struct ieee80211_mgmt *mgmt;
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200886 u8 *pos, *supp_rates, *esupp_rates = NULL;
887 int i;
Johannes Berg46900292009-02-15 12:44:28 +0100888
889 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt) + 200 +
Jouni Malinen65fc73a2009-03-20 21:21:16 +0200890 ie_len);
Johannes Berg46900292009-02-15 12:44:28 +0100891 if (!skb) {
892 printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
893 "request\n", sdata->dev->name);
894 return;
895 }
896 skb_reserve(skb, local->hw.extra_tx_headroom);
897
898 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
899 memset(mgmt, 0, 24);
900 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
901 IEEE80211_STYPE_PROBE_REQ);
902 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
903 if (dst) {
904 memcpy(mgmt->da, dst, ETH_ALEN);
905 memcpy(mgmt->bssid, dst, ETH_ALEN);
906 } else {
907 memset(mgmt->da, 0xff, ETH_ALEN);
908 memset(mgmt->bssid, 0xff, ETH_ALEN);
909 }
910 pos = skb_put(skb, 2 + ssid_len);
911 *pos++ = WLAN_EID_SSID;
912 *pos++ = ssid_len;
913 memcpy(pos, ssid, ssid_len);
914
915 supp_rates = skb_put(skb, 2);
916 supp_rates[0] = WLAN_EID_SUPP_RATES;
917 supp_rates[1] = 0;
918 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
919
920 for (i = 0; i < sband->n_bitrates; i++) {
921 struct ieee80211_rate *rate = &sband->bitrates[i];
922 if (esupp_rates) {
923 pos = skb_put(skb, 1);
924 esupp_rates[1]++;
925 } else if (supp_rates[1] == 8) {
926 esupp_rates = skb_put(skb, 3);
927 esupp_rates[0] = WLAN_EID_EXT_SUPP_RATES;
928 esupp_rates[1] = 1;
929 pos = &esupp_rates[2];
930 } else {
931 pos = skb_put(skb, 1);
932 supp_rates[1]++;
933 }
934 *pos = rate->bitrate / 5;
935 }
936
Jouni Malinen70692ad2009-02-16 19:39:13 +0200937 if (ie)
938 memcpy(skb_put(skb, ie_len), ie, ie_len);
Johannes Berg46900292009-02-15 12:44:28 +0100939
940 ieee80211_tx_skb(sdata, skb, 0);
941}
942
943u32 ieee80211_sta_get_rates(struct ieee80211_local *local,
944 struct ieee802_11_elems *elems,
945 enum ieee80211_band band)
946{
947 struct ieee80211_supported_band *sband;
948 struct ieee80211_rate *bitrates;
949 size_t num_rates;
950 u32 supp_rates;
951 int i, j;
952 sband = local->hw.wiphy->bands[band];
953
954 if (!sband) {
955 WARN_ON(1);
956 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
957 }
958
959 bitrates = sband->bitrates;
960 num_rates = sband->n_bitrates;
961 supp_rates = 0;
962 for (i = 0; i < elems->supp_rates_len +
963 elems->ext_supp_rates_len; i++) {
964 u8 rate = 0;
965 int own_rate;
966 if (i < elems->supp_rates_len)
967 rate = elems->supp_rates[i];
968 else if (elems->ext_supp_rates)
969 rate = elems->ext_supp_rates
970 [i - elems->supp_rates_len];
971 own_rate = 5 * (rate & 0x7f);
972 for (j = 0; j < num_rates; j++)
973 if (bitrates[j].bitrate == own_rate)
974 supp_rates |= BIT(j);
975 }
976 return supp_rates;
977}