blob: 92339105aa3b3b30468f5373657105d5ba202fe5 [file] [log] [blame]
Johannes Berg2a519312009-02-10 21:25:55 +01001/*
2 * cfg80211 scan result handling
3 *
4 * Copyright 2008 Johannes Berg <johannes@sipsolutions.net>
5 */
6#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09007#include <linux/slab.h>
Johannes Berg2a519312009-02-10 21:25:55 +01008#include <linux/module.h>
9#include <linux/netdevice.h>
10#include <linux/wireless.h>
11#include <linux/nl80211.h>
12#include <linux/etherdevice.h>
13#include <net/arp.h>
14#include <net/cfg80211.h>
Johannes Berg262eb9b22011-07-13 10:39:09 +020015#include <net/cfg80211-wext.h>
Johannes Berg2a519312009-02-10 21:25:55 +010016#include <net/iw_handler.h>
17#include "core.h"
18#include "nl80211.h"
Johannes Berga9a11622009-07-27 12:01:53 +020019#include "wext-compat.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030020#include "rdev-ops.h"
Johannes Berg2a519312009-02-10 21:25:55 +010021
Rajkumar Manoharanf9616e02012-04-13 16:38:40 +053022#define IEEE80211_SCAN_RESULT_EXPIRE (30 * HZ)
Johannes Berg2a519312009-02-10 21:25:55 +010023
Amitkumar Karware8e27c62012-10-11 21:03:33 -070024static void bss_release(struct kref *ref)
25{
26 struct cfg80211_internal_bss *bss;
27
28 bss = container_of(ref, struct cfg80211_internal_bss, ref);
Johannes Bergb629ea32012-11-28 22:14:56 +010029
30 if (WARN_ON(atomic_read(&bss->hold)))
31 return;
32
Amitkumar Karware8e27c62012-10-11 21:03:33 -070033 if (bss->pub.free_priv)
34 bss->pub.free_priv(&bss->pub);
35
36 if (bss->beacon_ies_allocated)
37 kfree(bss->pub.beacon_ies);
38 if (bss->proberesp_ies_allocated)
39 kfree(bss->pub.proberesp_ies);
40
Amitkumar Karware8e27c62012-10-11 21:03:33 -070041 kfree(bss);
42}
43
44/* must hold dev->bss_lock! */
45static void __cfg80211_unlink_bss(struct cfg80211_registered_device *dev,
46 struct cfg80211_internal_bss *bss)
47{
48 list_del_init(&bss->list);
49 rb_erase(&bss->rbn, &dev->bss_tree);
50 kref_put(&bss->ref, bss_release);
51}
52
Sam Leffler15d60302012-10-11 21:03:34 -070053/* must hold dev->bss_lock! */
54static void __cfg80211_bss_expire(struct cfg80211_registered_device *dev,
55 unsigned long expire_time)
56{
57 struct cfg80211_internal_bss *bss, *tmp;
58 bool expired = false;
59
60 list_for_each_entry_safe(bss, tmp, &dev->bss_list, list) {
61 if (atomic_read(&bss->hold))
62 continue;
63 if (!time_after(expire_time, bss->ts))
64 continue;
65
66 __cfg80211_unlink_bss(dev, bss);
67 expired = true;
68 }
69
70 if (expired)
71 dev->bss_generation++;
72}
73
Johannes Berg01a0ac42009-08-20 21:36:16 +020074void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev, bool leak)
Johannes Berg2a519312009-02-10 21:25:55 +010075{
Johannes Berg667503d2009-07-07 03:56:11 +020076 struct cfg80211_scan_request *request;
Johannes Bergfd014282012-06-18 19:17:03 +020077 struct wireless_dev *wdev;
Johannes Berg3d23e342009-09-29 23:27:28 +020078#ifdef CONFIG_CFG80211_WEXT
Johannes Berg2a519312009-02-10 21:25:55 +010079 union iwreq_data wrqu;
80#endif
81
Johannes Berg01a0ac42009-08-20 21:36:16 +020082 ASSERT_RDEV_LOCK(rdev);
83
Johannes Berg667503d2009-07-07 03:56:11 +020084 request = rdev->scan_req;
85
Johannes Berg01a0ac42009-08-20 21:36:16 +020086 if (!request)
87 return;
88
Johannes Bergfd014282012-06-18 19:17:03 +020089 wdev = request->wdev;
Johannes Berg2a519312009-02-10 21:25:55 +010090
Johannes Berg6829c8782009-07-02 09:13:27 +020091 /*
92 * This must be before sending the other events!
93 * Otherwise, wpa_supplicant gets completely confused with
94 * wext events.
95 */
Johannes Bergfd014282012-06-18 19:17:03 +020096 if (wdev->netdev)
97 cfg80211_sme_scan_done(wdev->netdev);
Johannes Berg6829c8782009-07-02 09:13:27 +020098
Sam Leffler15d60302012-10-11 21:03:34 -070099 if (request->aborted) {
Johannes Bergfd014282012-06-18 19:17:03 +0200100 nl80211_send_scan_aborted(rdev, wdev);
Sam Leffler15d60302012-10-11 21:03:34 -0700101 } else {
102 if (request->flags & NL80211_SCAN_FLAG_FLUSH) {
103 /* flush entries from previous scans */
104 spin_lock_bh(&rdev->bss_lock);
105 __cfg80211_bss_expire(rdev, request->scan_start);
106 spin_unlock_bh(&rdev->bss_lock);
107 }
Johannes Bergfd014282012-06-18 19:17:03 +0200108 nl80211_send_scan_done(rdev, wdev);
Sam Leffler15d60302012-10-11 21:03:34 -0700109 }
Johannes Berg2a519312009-02-10 21:25:55 +0100110
Johannes Berg3d23e342009-09-29 23:27:28 +0200111#ifdef CONFIG_CFG80211_WEXT
Johannes Bergfd014282012-06-18 19:17:03 +0200112 if (wdev->netdev && !request->aborted) {
Johannes Berg2a519312009-02-10 21:25:55 +0100113 memset(&wrqu, 0, sizeof(wrqu));
114
Johannes Bergfd014282012-06-18 19:17:03 +0200115 wireless_send_event(wdev->netdev, SIOCGIWSCAN, &wrqu, NULL);
Johannes Berg2a519312009-02-10 21:25:55 +0100116 }
117#endif
118
Johannes Bergfd014282012-06-18 19:17:03 +0200119 if (wdev->netdev)
120 dev_put(wdev->netdev);
Johannes Berg2a519312009-02-10 21:25:55 +0100121
Johannes Berg36e6fea2009-08-12 22:21:21 +0200122 rdev->scan_req = NULL;
Johannes Berg01a0ac42009-08-20 21:36:16 +0200123
124 /*
125 * OK. If this is invoked with "leak" then we can't
126 * free this ... but we've cleaned it up anyway. The
127 * driver failed to call the scan_done callback, so
128 * all bets are off, it might still be trying to use
129 * the scan request or not ... if it accesses the dev
130 * in there (it shouldn't anyway) then it may crash.
131 */
132 if (!leak)
133 kfree(request);
Johannes Berg2a519312009-02-10 21:25:55 +0100134}
Johannes Berg667503d2009-07-07 03:56:11 +0200135
Johannes Berg36e6fea2009-08-12 22:21:21 +0200136void __cfg80211_scan_done(struct work_struct *wk)
137{
138 struct cfg80211_registered_device *rdev;
139
140 rdev = container_of(wk, struct cfg80211_registered_device,
141 scan_done_wk);
142
143 cfg80211_lock_rdev(rdev);
Johannes Berg01a0ac42009-08-20 21:36:16 +0200144 ___cfg80211_scan_done(rdev, false);
Johannes Berg36e6fea2009-08-12 22:21:21 +0200145 cfg80211_unlock_rdev(rdev);
146}
147
Johannes Berg667503d2009-07-07 03:56:11 +0200148void cfg80211_scan_done(struct cfg80211_scan_request *request, bool aborted)
149{
Beni Lev4ee3e062012-08-27 12:49:39 +0300150 trace_cfg80211_scan_done(request, aborted);
Johannes Berg667503d2009-07-07 03:56:11 +0200151 WARN_ON(request != wiphy_to_dev(request->wiphy)->scan_req);
152
153 request->aborted = aborted;
Alban Browaeyse60d7442009-11-25 15:13:00 +0100154 queue_work(cfg80211_wq, &wiphy_to_dev(request->wiphy)->scan_done_wk);
Johannes Berg667503d2009-07-07 03:56:11 +0200155}
Johannes Berg2a519312009-02-10 21:25:55 +0100156EXPORT_SYMBOL(cfg80211_scan_done);
157
Luciano Coelho807f8a82011-05-11 17:09:35 +0300158void __cfg80211_sched_scan_results(struct work_struct *wk)
159{
160 struct cfg80211_registered_device *rdev;
Sam Leffler15d60302012-10-11 21:03:34 -0700161 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +0300162
163 rdev = container_of(wk, struct cfg80211_registered_device,
164 sched_scan_results_wk);
165
Sam Leffler15d60302012-10-11 21:03:34 -0700166 request = rdev->sched_scan_req;
167
Luciano Coelhoc10841c2011-06-30 08:32:41 +0300168 mutex_lock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +0300169
170 /* we don't have sched_scan_req anymore if the scan is stopping */
Sam Leffler15d60302012-10-11 21:03:34 -0700171 if (request) {
172 if (request->flags & NL80211_SCAN_FLAG_FLUSH) {
173 /* flush entries from previous scans */
174 spin_lock_bh(&rdev->bss_lock);
175 __cfg80211_bss_expire(rdev, request->scan_start);
176 spin_unlock_bh(&rdev->bss_lock);
177 request->scan_start =
178 jiffies + msecs_to_jiffies(request->interval);
179 }
180 nl80211_send_sched_scan_results(rdev, request->dev);
181 }
Luciano Coelho807f8a82011-05-11 17:09:35 +0300182
Luciano Coelhoc10841c2011-06-30 08:32:41 +0300183 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +0300184}
185
186void cfg80211_sched_scan_results(struct wiphy *wiphy)
187{
Beni Lev4ee3e062012-08-27 12:49:39 +0300188 trace_cfg80211_sched_scan_results(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +0300189 /* ignore if we're not scanning */
190 if (wiphy_to_dev(wiphy)->sched_scan_req)
191 queue_work(cfg80211_wq,
192 &wiphy_to_dev(wiphy)->sched_scan_results_wk);
193}
194EXPORT_SYMBOL(cfg80211_sched_scan_results);
195
Luciano Coelho85a99942011-05-12 16:28:29 +0300196void cfg80211_sched_scan_stopped(struct wiphy *wiphy)
Luciano Coelho807f8a82011-05-11 17:09:35 +0300197{
Luciano Coelho85a99942011-05-12 16:28:29 +0300198 struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +0300199
Beni Lev4ee3e062012-08-27 12:49:39 +0300200 trace_cfg80211_sched_scan_stopped(wiphy);
201
Luciano Coelhoc10841c2011-06-30 08:32:41 +0300202 mutex_lock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +0300203 __cfg80211_stop_sched_scan(rdev, true);
Luciano Coelhoc10841c2011-06-30 08:32:41 +0300204 mutex_unlock(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +0300205}
Luciano Coelho807f8a82011-05-11 17:09:35 +0300206EXPORT_SYMBOL(cfg80211_sched_scan_stopped);
207
208int __cfg80211_stop_sched_scan(struct cfg80211_registered_device *rdev,
209 bool driver_initiated)
210{
Luciano Coelho807f8a82011-05-11 17:09:35 +0300211 struct net_device *dev;
212
Luciano Coelhoc10841c2011-06-30 08:32:41 +0300213 lockdep_assert_held(&rdev->sched_scan_mtx);
Luciano Coelho807f8a82011-05-11 17:09:35 +0300214
215 if (!rdev->sched_scan_req)
Luciano Coelho1a84ff72011-07-08 11:16:16 +0300216 return -ENOENT;
Luciano Coelho807f8a82011-05-11 17:09:35 +0300217
218 dev = rdev->sched_scan_req->dev;
219
Luciano Coelho85a99942011-05-12 16:28:29 +0300220 if (!driver_initiated) {
Hila Gonene35e4d22012-06-27 17:19:42 +0300221 int err = rdev_sched_scan_stop(rdev, dev);
Luciano Coelho85a99942011-05-12 16:28:29 +0300222 if (err)
223 return err;
224 }
Luciano Coelho807f8a82011-05-11 17:09:35 +0300225
226 nl80211_send_sched_scan(rdev, dev, NL80211_CMD_SCHED_SCAN_STOPPED);
227
228 kfree(rdev->sched_scan_req);
229 rdev->sched_scan_req = NULL;
230
Jesper Juhl3b4670f2011-06-29 22:49:33 +0200231 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +0300232}
233
Johannes Berg2a519312009-02-10 21:25:55 +0100234/* must hold dev->bss_lock! */
Dan Williamscb3a8ee2009-02-11 17:14:43 -0500235void cfg80211_bss_age(struct cfg80211_registered_device *dev,
236 unsigned long age_secs)
237{
238 struct cfg80211_internal_bss *bss;
239 unsigned long age_jiffies = msecs_to_jiffies(age_secs * MSEC_PER_SEC);
240
Johannes Berg915de2f2012-11-28 22:39:37 +0100241 list_for_each_entry(bss, &dev->bss_list, list)
Dan Williamscb3a8ee2009-02-11 17:14:43 -0500242 bss->ts -= age_jiffies;
Dan Williamscb3a8ee2009-02-11 17:14:43 -0500243}
244
Johannes Berg2a519312009-02-10 21:25:55 +0100245void cfg80211_bss_expire(struct cfg80211_registered_device *dev)
246{
Sam Leffler15d60302012-10-11 21:03:34 -0700247 __cfg80211_bss_expire(dev, jiffies - IEEE80211_SCAN_RESULT_EXPIRE);
Johannes Berg2a519312009-02-10 21:25:55 +0100248}
249
Johannes Bergc21dbf92010-01-26 14:15:46 +0100250const u8 *cfg80211_find_ie(u8 eid, const u8 *ies, int len)
Johannes Berg2a519312009-02-10 21:25:55 +0100251{
Johannes Bergc21dbf92010-01-26 14:15:46 +0100252 while (len > 2 && ies[0] != eid) {
Johannes Berg2a519312009-02-10 21:25:55 +0100253 len -= ies[1] + 2;
254 ies += ies[1] + 2;
255 }
256 if (len < 2)
257 return NULL;
258 if (len < 2 + ies[1])
259 return NULL;
260 return ies;
261}
Johannes Bergc21dbf92010-01-26 14:15:46 +0100262EXPORT_SYMBOL(cfg80211_find_ie);
Johannes Berg2a519312009-02-10 21:25:55 +0100263
Eliad Peller0c28ec52011-09-15 11:53:01 +0300264const u8 *cfg80211_find_vendor_ie(unsigned int oui, u8 oui_type,
265 const u8 *ies, int len)
266{
267 struct ieee80211_vendor_ie *ie;
268 const u8 *pos = ies, *end = ies + len;
269 int ie_oui;
270
271 while (pos < end) {
272 pos = cfg80211_find_ie(WLAN_EID_VENDOR_SPECIFIC, pos,
273 end - pos);
274 if (!pos)
275 return NULL;
276
277 if (end - pos < sizeof(*ie))
278 return NULL;
279
280 ie = (struct ieee80211_vendor_ie *)pos;
281 ie_oui = ie->oui[0] << 16 | ie->oui[1] << 8 | ie->oui[2];
282 if (ie_oui == oui && ie->oui_type == oui_type)
283 return pos;
284
285 pos += 2 + ie->len;
286 }
287 return NULL;
288}
289EXPORT_SYMBOL(cfg80211_find_vendor_ie);
290
Johannes Berg2a519312009-02-10 21:25:55 +0100291static int cmp_ies(u8 num, u8 *ies1, size_t len1, u8 *ies2, size_t len2)
292{
Johannes Bergc21dbf92010-01-26 14:15:46 +0100293 const u8 *ie1 = cfg80211_find_ie(num, ies1, len1);
294 const u8 *ie2 = cfg80211_find_ie(num, ies2, len2);
Johannes Berg2a519312009-02-10 21:25:55 +0100295
Johannes Berg3b6ef632011-11-04 11:01:46 +0100296 /* equal if both missing */
Johannes Berg2a519312009-02-10 21:25:55 +0100297 if (!ie1 && !ie2)
298 return 0;
Johannes Berg3b6ef632011-11-04 11:01:46 +0100299 /* sort missing IE before (left of) present IE */
300 if (!ie1)
Johannes Berg2a519312009-02-10 21:25:55 +0100301 return -1;
Johannes Berg3b6ef632011-11-04 11:01:46 +0100302 if (!ie2)
303 return 1;
Johannes Berg2a519312009-02-10 21:25:55 +0100304
Johannes Berg3b6ef632011-11-04 11:01:46 +0100305 /* sort by length first, then by contents */
306 if (ie1[1] != ie2[1])
Johannes Berg2a519312009-02-10 21:25:55 +0100307 return ie2[1] - ie1[1];
Johannes Berg3b6ef632011-11-04 11:01:46 +0100308 return memcmp(ie1 + 2, ie2 + 2, ie1[1]);
Johannes Berg2a519312009-02-10 21:25:55 +0100309}
310
Johannes Berg915de2f2012-11-28 22:39:37 +0100311static bool is_bss(struct cfg80211_bss *a, const u8 *bssid,
Johannes Berg2a519312009-02-10 21:25:55 +0100312 const u8 *ssid, size_t ssid_len)
313{
314 const u8 *ssidie;
315
Joe Perchesac422d32012-05-08 18:56:55 +0000316 if (bssid && !ether_addr_equal(a->bssid, bssid))
Johannes Berg2a519312009-02-10 21:25:55 +0100317 return false;
318
Johannes Berg79420f02009-02-10 21:25:59 +0100319 if (!ssid)
320 return true;
321
Johannes Bergc21dbf92010-01-26 14:15:46 +0100322 ssidie = cfg80211_find_ie(WLAN_EID_SSID,
323 a->information_elements,
324 a->len_information_elements);
Johannes Berg2a519312009-02-10 21:25:55 +0100325 if (!ssidie)
326 return false;
327 if (ssidie[1] != ssid_len)
328 return false;
329 return memcmp(ssidie + 2, ssid, ssid_len) == 0;
330}
331
Eliad Peller333ba732011-05-29 15:53:20 +0300332static bool is_mesh_bss(struct cfg80211_bss *a)
333{
334 const u8 *ie;
335
336 if (!WLAN_CAPABILITY_IS_STA_BSS(a->capability))
337 return false;
338
339 ie = cfg80211_find_ie(WLAN_EID_MESH_ID,
340 a->information_elements,
341 a->len_information_elements);
342 if (!ie)
343 return false;
344
345 ie = cfg80211_find_ie(WLAN_EID_MESH_CONFIG,
346 a->information_elements,
347 a->len_information_elements);
348 if (!ie)
349 return false;
350
351 return true;
352}
353
Johannes Berg2a519312009-02-10 21:25:55 +0100354static bool is_mesh(struct cfg80211_bss *a,
355 const u8 *meshid, size_t meshidlen,
356 const u8 *meshcfg)
357{
358 const u8 *ie;
359
Eliad Peller333ba732011-05-29 15:53:20 +0300360 if (!WLAN_CAPABILITY_IS_STA_BSS(a->capability))
Johannes Berg2a519312009-02-10 21:25:55 +0100361 return false;
362
Johannes Bergc21dbf92010-01-26 14:15:46 +0100363 ie = cfg80211_find_ie(WLAN_EID_MESH_ID,
364 a->information_elements,
365 a->len_information_elements);
Johannes Berg2a519312009-02-10 21:25:55 +0100366 if (!ie)
367 return false;
368 if (ie[1] != meshidlen)
369 return false;
370 if (memcmp(ie + 2, meshid, meshidlen))
371 return false;
372
Johannes Bergc21dbf92010-01-26 14:15:46 +0100373 ie = cfg80211_find_ie(WLAN_EID_MESH_CONFIG,
374 a->information_elements,
375 a->len_information_elements);
Johannes Bergcd3468b2009-07-29 22:07:44 +0200376 if (!ie)
377 return false;
Rui Paulo136cfa22009-11-18 18:40:00 +0000378 if (ie[1] != sizeof(struct ieee80211_meshconf_ie))
Johannes Berg2a519312009-02-10 21:25:55 +0100379 return false;
380
381 /*
382 * Ignore mesh capability (last two bytes of the IE) when
383 * comparing since that may differ between stations taking
384 * part in the same mesh.
385 */
Rui Paulo136cfa22009-11-18 18:40:00 +0000386 return memcmp(ie + 2, meshcfg,
Johannes Berg915de2f2012-11-28 22:39:37 +0100387 sizeof(struct ieee80211_meshconf_ie) - 2) == 0;
Johannes Berg2a519312009-02-10 21:25:55 +0100388}
389
Johannes Berg915de2f2012-11-28 22:39:37 +0100390static int cmp_bss_core(struct cfg80211_bss *a, struct cfg80211_bss *b)
Johannes Berg2a519312009-02-10 21:25:55 +0100391{
392 int r;
393
394 if (a->channel != b->channel)
395 return b->channel->center_freq - a->channel->center_freq;
396
Eliad Peller333ba732011-05-29 15:53:20 +0300397 if (is_mesh_bss(a) && is_mesh_bss(b)) {
Johannes Berg2a519312009-02-10 21:25:55 +0100398 r = cmp_ies(WLAN_EID_MESH_ID,
399 a->information_elements,
400 a->len_information_elements,
401 b->information_elements,
402 b->len_information_elements);
403 if (r)
404 return r;
405 return cmp_ies(WLAN_EID_MESH_CONFIG,
406 a->information_elements,
407 a->len_information_elements,
408 b->information_elements,
409 b->len_information_elements);
410 }
411
Emmanuel Grumbachef9456a2012-04-30 10:23:36 +0300412 /*
413 * we can't use compare_ether_addr here since we need a < > operator.
414 * The binary return value of compare_ether_addr isn't enough
415 */
416 return memcmp(a->bssid, b->bssid, sizeof(a->bssid));
Dmitry Tarnyagindd9dfb92011-11-04 17:12:07 +0100417}
418
419static int cmp_bss(struct cfg80211_bss *a,
420 struct cfg80211_bss *b)
421{
422 int r;
423
424 r = cmp_bss_core(a, b);
Javier Cardona0a35d362011-05-04 10:24:56 -0700425 if (r)
426 return r;
427
Johannes Berg2a519312009-02-10 21:25:55 +0100428 return cmp_ies(WLAN_EID_SSID,
429 a->information_elements,
430 a->len_information_elements,
431 b->information_elements,
432 b->len_information_elements);
433}
434
Johannes Berg915de2f2012-11-28 22:39:37 +0100435static int cmp_hidden_bss(struct cfg80211_bss *a, struct cfg80211_bss *b)
Dmitry Tarnyagindd9dfb92011-11-04 17:12:07 +0100436{
437 const u8 *ie1;
438 const u8 *ie2;
439 int i;
440 int r;
441
442 r = cmp_bss_core(a, b);
443 if (r)
444 return r;
445
446 ie1 = cfg80211_find_ie(WLAN_EID_SSID,
Johannes Berg915de2f2012-11-28 22:39:37 +0100447 a->information_elements,
448 a->len_information_elements);
Dmitry Tarnyagindd9dfb92011-11-04 17:12:07 +0100449 ie2 = cfg80211_find_ie(WLAN_EID_SSID,
Johannes Berg915de2f2012-11-28 22:39:37 +0100450 b->information_elements,
451 b->len_information_elements);
Dmitry Tarnyagindd9dfb92011-11-04 17:12:07 +0100452
453 /* Key comparator must use same algorithm in any rb-tree
454 * search function (order is important), otherwise ordering
455 * of items in the tree is broken and search gives incorrect
456 * results. This code uses same order as cmp_ies() does. */
457
458 /* sort missing IE before (left of) present IE */
459 if (!ie1)
460 return -1;
461 if (!ie2)
462 return 1;
463
464 /* zero-size SSID is used as an indication of the hidden bss */
465 if (!ie2[1])
466 return 0;
467
468 /* sort by length first, then by contents */
469 if (ie1[1] != ie2[1])
470 return ie2[1] - ie1[1];
471
472 /* zeroed SSID ie is another indication of a hidden bss */
473 for (i = 0; i < ie2[1]; i++)
474 if (ie2[i + 2])
475 return -1;
476
477 return 0;
478}
479
Johannes Berg2a519312009-02-10 21:25:55 +0100480struct cfg80211_bss *cfg80211_get_bss(struct wiphy *wiphy,
481 struct ieee80211_channel *channel,
482 const u8 *bssid,
Johannes Berg79420f02009-02-10 21:25:59 +0100483 const u8 *ssid, size_t ssid_len,
484 u16 capa_mask, u16 capa_val)
Johannes Berg2a519312009-02-10 21:25:55 +0100485{
486 struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy);
487 struct cfg80211_internal_bss *bss, *res = NULL;
Johannes Bergccb6c132010-07-13 10:55:38 +0200488 unsigned long now = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +0100489
Beni Lev4ee3e062012-08-27 12:49:39 +0300490 trace_cfg80211_get_bss(wiphy, channel, bssid, ssid, ssid_len, capa_mask,
491 capa_val);
492
Johannes Berg2a519312009-02-10 21:25:55 +0100493 spin_lock_bh(&dev->bss_lock);
494
495 list_for_each_entry(bss, &dev->bss_list, list) {
Johannes Berg79420f02009-02-10 21:25:59 +0100496 if ((bss->pub.capability & capa_mask) != capa_val)
497 continue;
Johannes Berg2a519312009-02-10 21:25:55 +0100498 if (channel && bss->pub.channel != channel)
499 continue;
Johannes Bergccb6c132010-07-13 10:55:38 +0200500 /* Don't get expired BSS structs */
501 if (time_after(now, bss->ts + IEEE80211_SCAN_RESULT_EXPIRE) &&
502 !atomic_read(&bss->hold))
503 continue;
Johannes Berg2a519312009-02-10 21:25:55 +0100504 if (is_bss(&bss->pub, bssid, ssid, ssid_len)) {
505 res = bss;
506 kref_get(&res->ref);
507 break;
508 }
509 }
510
511 spin_unlock_bh(&dev->bss_lock);
512 if (!res)
513 return NULL;
Beni Lev4ee3e062012-08-27 12:49:39 +0300514 trace_cfg80211_return_bss(&res->pub);
Johannes Berg2a519312009-02-10 21:25:55 +0100515 return &res->pub;
516}
517EXPORT_SYMBOL(cfg80211_get_bss);
518
519struct cfg80211_bss *cfg80211_get_mesh(struct wiphy *wiphy,
520 struct ieee80211_channel *channel,
521 const u8 *meshid, size_t meshidlen,
522 const u8 *meshcfg)
523{
524 struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy);
525 struct cfg80211_internal_bss *bss, *res = NULL;
526
527 spin_lock_bh(&dev->bss_lock);
528
529 list_for_each_entry(bss, &dev->bss_list, list) {
530 if (channel && bss->pub.channel != channel)
531 continue;
532 if (is_mesh(&bss->pub, meshid, meshidlen, meshcfg)) {
533 res = bss;
534 kref_get(&res->ref);
535 break;
536 }
537 }
538
539 spin_unlock_bh(&dev->bss_lock);
540 if (!res)
541 return NULL;
542 return &res->pub;
543}
544EXPORT_SYMBOL(cfg80211_get_mesh);
545
546
547static void rb_insert_bss(struct cfg80211_registered_device *dev,
548 struct cfg80211_internal_bss *bss)
549{
550 struct rb_node **p = &dev->bss_tree.rb_node;
551 struct rb_node *parent = NULL;
552 struct cfg80211_internal_bss *tbss;
553 int cmp;
554
555 while (*p) {
556 parent = *p;
557 tbss = rb_entry(parent, struct cfg80211_internal_bss, rbn);
558
559 cmp = cmp_bss(&bss->pub, &tbss->pub);
560
561 if (WARN_ON(!cmp)) {
562 /* will sort of leak this BSS */
563 return;
564 }
565
566 if (cmp < 0)
567 p = &(*p)->rb_left;
568 else
569 p = &(*p)->rb_right;
570 }
571
572 rb_link_node(&bss->rbn, parent, p);
573 rb_insert_color(&bss->rbn, &dev->bss_tree);
574}
575
576static struct cfg80211_internal_bss *
577rb_find_bss(struct cfg80211_registered_device *dev,
578 struct cfg80211_internal_bss *res)
579{
580 struct rb_node *n = dev->bss_tree.rb_node;
581 struct cfg80211_internal_bss *bss;
582 int r;
583
584 while (n) {
585 bss = rb_entry(n, struct cfg80211_internal_bss, rbn);
586 r = cmp_bss(&res->pub, &bss->pub);
587
588 if (r == 0)
589 return bss;
590 else if (r < 0)
591 n = n->rb_left;
592 else
593 n = n->rb_right;
594 }
595
596 return NULL;
597}
598
599static struct cfg80211_internal_bss *
Dmitry Tarnyagindd9dfb92011-11-04 17:12:07 +0100600rb_find_hidden_bss(struct cfg80211_registered_device *dev,
Johannes Berg915de2f2012-11-28 22:39:37 +0100601 struct cfg80211_internal_bss *res)
Dmitry Tarnyagindd9dfb92011-11-04 17:12:07 +0100602{
603 struct rb_node *n = dev->bss_tree.rb_node;
604 struct cfg80211_internal_bss *bss;
605 int r;
606
607 while (n) {
608 bss = rb_entry(n, struct cfg80211_internal_bss, rbn);
609 r = cmp_hidden_bss(&res->pub, &bss->pub);
610
611 if (r == 0)
612 return bss;
613 else if (r < 0)
614 n = n->rb_left;
615 else
616 n = n->rb_right;
617 }
618
619 return NULL;
620}
621
622static void
623copy_hidden_ies(struct cfg80211_internal_bss *res,
Johannes Berg915de2f2012-11-28 22:39:37 +0100624 struct cfg80211_internal_bss *hidden)
Dmitry Tarnyagindd9dfb92011-11-04 17:12:07 +0100625{
626 if (unlikely(res->pub.beacon_ies))
627 return;
628 if (WARN_ON(!hidden->pub.beacon_ies))
629 return;
630
631 res->pub.beacon_ies = kmalloc(hidden->pub.len_beacon_ies, GFP_ATOMIC);
632 if (unlikely(!res->pub.beacon_ies))
633 return;
634
635 res->beacon_ies_allocated = true;
636 res->pub.len_beacon_ies = hidden->pub.len_beacon_ies;
637 memcpy(res->pub.beacon_ies, hidden->pub.beacon_ies,
Johannes Berg915de2f2012-11-28 22:39:37 +0100638 res->pub.len_beacon_ies);
Dmitry Tarnyagindd9dfb92011-11-04 17:12:07 +0100639}
640
641static struct cfg80211_internal_bss *
Johannes Berg2a519312009-02-10 21:25:55 +0100642cfg80211_bss_update(struct cfg80211_registered_device *dev,
Jouni Malinen34a6edd2010-01-06 16:19:24 +0200643 struct cfg80211_internal_bss *res)
Johannes Berg2a519312009-02-10 21:25:55 +0100644{
645 struct cfg80211_internal_bss *found = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +0100646
647 /*
648 * The reference to "res" is donated to this function.
649 */
650
651 if (WARN_ON(!res->pub.channel)) {
652 kref_put(&res->ref, bss_release);
653 return NULL;
654 }
655
656 res->ts = jiffies;
657
Johannes Berg2a519312009-02-10 21:25:55 +0100658 spin_lock_bh(&dev->bss_lock);
659
660 found = rb_find_bss(dev, res);
661
Johannes Bergcd1658f2009-04-16 15:00:58 +0200662 if (found) {
Johannes Berg2a519312009-02-10 21:25:55 +0100663 found->pub.beacon_interval = res->pub.beacon_interval;
664 found->pub.tsf = res->pub.tsf;
665 found->pub.signal = res->pub.signal;
Johannes Berg2a519312009-02-10 21:25:55 +0100666 found->pub.capability = res->pub.capability;
667 found->ts = res->ts;
Johannes Bergcd1658f2009-04-16 15:00:58 +0200668
Jouni Malinen34a6edd2010-01-06 16:19:24 +0200669 /* Update IEs */
670 if (res->pub.proberesp_ies) {
Johannes Bergcd1658f2009-04-16 15:00:58 +0200671 size_t used = dev->wiphy.bss_priv_size + sizeof(*res);
Jouni Malinen34a6edd2010-01-06 16:19:24 +0200672 size_t ielen = res->pub.len_proberesp_ies;
Johannes Bergcd1658f2009-04-16 15:00:58 +0200673
Jouni Malinen34a6edd2010-01-06 16:19:24 +0200674 if (found->pub.proberesp_ies &&
675 !found->proberesp_ies_allocated &&
676 ksize(found) >= used + ielen) {
677 memcpy(found->pub.proberesp_ies,
678 res->pub.proberesp_ies, ielen);
679 found->pub.len_proberesp_ies = ielen;
Johannes Bergcd1658f2009-04-16 15:00:58 +0200680 } else {
Jouni Malinen34a6edd2010-01-06 16:19:24 +0200681 u8 *ies = found->pub.proberesp_ies;
Johannes Bergcd1658f2009-04-16 15:00:58 +0200682
Jouni Malinen34a6edd2010-01-06 16:19:24 +0200683 if (found->proberesp_ies_allocated)
Michael Buesch273de922009-04-25 22:28:55 +0200684 ies = krealloc(ies, ielen, GFP_ATOMIC);
685 else
Johannes Bergcd1658f2009-04-16 15:00:58 +0200686 ies = kmalloc(ielen, GFP_ATOMIC);
687
688 if (ies) {
Jouni Malinen34a6edd2010-01-06 16:19:24 +0200689 memcpy(ies, res->pub.proberesp_ies,
690 ielen);
691 found->proberesp_ies_allocated = true;
692 found->pub.proberesp_ies = ies;
693 found->pub.len_proberesp_ies = ielen;
694 }
695 }
696
697 /* Override possible earlier Beacon frame IEs */
698 found->pub.information_elements =
699 found->pub.proberesp_ies;
700 found->pub.len_information_elements =
701 found->pub.len_proberesp_ies;
702 }
Johannes Berg915de2f2012-11-28 22:39:37 +0100703
Jouni Malinen34a6edd2010-01-06 16:19:24 +0200704 if (res->pub.beacon_ies) {
705 size_t used = dev->wiphy.bss_priv_size + sizeof(*res);
706 size_t ielen = res->pub.len_beacon_ies;
Sven Neumann01123e22010-12-09 15:05:24 +0100707 bool information_elements_is_beacon_ies =
708 (found->pub.information_elements ==
709 found->pub.beacon_ies);
Jouni Malinen34a6edd2010-01-06 16:19:24 +0200710
711 if (found->pub.beacon_ies &&
712 !found->beacon_ies_allocated &&
713 ksize(found) >= used + ielen) {
714 memcpy(found->pub.beacon_ies,
715 res->pub.beacon_ies, ielen);
716 found->pub.len_beacon_ies = ielen;
717 } else {
718 u8 *ies = found->pub.beacon_ies;
719
720 if (found->beacon_ies_allocated)
721 ies = krealloc(ies, ielen, GFP_ATOMIC);
722 else
723 ies = kmalloc(ielen, GFP_ATOMIC);
724
725 if (ies) {
726 memcpy(ies, res->pub.beacon_ies,
727 ielen);
728 found->beacon_ies_allocated = true;
729 found->pub.beacon_ies = ies;
730 found->pub.len_beacon_ies = ielen;
Johannes Bergcd1658f2009-04-16 15:00:58 +0200731 }
732 }
Sven Neumann01123e22010-12-09 15:05:24 +0100733
734 /* Override IEs if they were from a beacon before */
735 if (information_elements_is_beacon_ies) {
736 found->pub.information_elements =
737 found->pub.beacon_ies;
738 found->pub.len_information_elements =
739 found->pub.len_beacon_ies;
740 }
Johannes Bergcd1658f2009-04-16 15:00:58 +0200741 }
742
Johannes Berg2a519312009-02-10 21:25:55 +0100743 kref_put(&res->ref, bss_release);
744 } else {
Dmitry Tarnyagindd9dfb92011-11-04 17:12:07 +0100745 struct cfg80211_internal_bss *hidden;
746
747 /* First check if the beacon is a probe response from
748 * a hidden bss. If so, copy beacon ies (with nullified
749 * ssid) into the probe response bss entry (with real ssid).
750 * It is required basically for PSM implementation
751 * (probe responses do not contain tim ie) */
752
753 /* TODO: The code is not trying to update existing probe
754 * response bss entries when beacon ies are
755 * getting changed. */
756 hidden = rb_find_hidden_bss(dev, res);
757 if (hidden)
758 copy_hidden_ies(res, hidden);
759
Johannes Berg2a519312009-02-10 21:25:55 +0100760 /* this "consumes" the reference */
761 list_add_tail(&res->list, &dev->bss_list);
762 rb_insert_bss(dev, res);
763 found = res;
764 }
765
766 dev->bss_generation++;
767 spin_unlock_bh(&dev->bss_lock);
768
769 kref_get(&found->ref);
770 return found;
771}
772
Johannes Berg0172bb72012-11-23 14:23:30 +0100773static struct ieee80211_channel *
774cfg80211_get_bss_channel(struct wiphy *wiphy, const u8 *ie, size_t ielen,
775 struct ieee80211_channel *channel)
776{
777 const u8 *tmp;
778 u32 freq;
779 int channel_number = -1;
780
781 tmp = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ie, ielen);
782 if (tmp && tmp[1] == 1) {
783 channel_number = tmp[2];
784 } else {
785 tmp = cfg80211_find_ie(WLAN_EID_HT_OPERATION, ie, ielen);
786 if (tmp && tmp[1] >= sizeof(struct ieee80211_ht_operation)) {
787 struct ieee80211_ht_operation *htop = (void *)(tmp + 2);
788
789 channel_number = htop->primary_chan;
790 }
791 }
792
793 if (channel_number < 0)
794 return channel;
795
796 freq = ieee80211_channel_to_frequency(channel_number, channel->band);
797 channel = ieee80211_get_channel(wiphy, freq);
798 if (!channel)
799 return NULL;
800 if (channel->flags & IEEE80211_CHAN_DISABLED)
801 return NULL;
802 return channel;
803}
804
Jussi Kivilinna06aa7af2009-03-26 23:40:09 +0200805struct cfg80211_bss*
806cfg80211_inform_bss(struct wiphy *wiphy,
807 struct ieee80211_channel *channel,
Johannes Berg7b8bcff2012-03-13 13:57:04 +0100808 const u8 *bssid, u64 tsf, u16 capability,
809 u16 beacon_interval, const u8 *ie, size_t ielen,
Jussi Kivilinna06aa7af2009-03-26 23:40:09 +0200810 s32 signal, gfp_t gfp)
811{
812 struct cfg80211_internal_bss *res;
813 size_t privsz;
814
815 if (WARN_ON(!wiphy))
816 return NULL;
817
818 privsz = wiphy->bss_priv_size;
819
Sujith22fe88d2010-05-13 10:34:08 +0530820 if (WARN_ON(wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC &&
Jussi Kivilinna06aa7af2009-03-26 23:40:09 +0200821 (signal < 0 || signal > 100)))
822 return NULL;
823
Johannes Berg0172bb72012-11-23 14:23:30 +0100824 channel = cfg80211_get_bss_channel(wiphy, ie, ielen, channel);
825 if (!channel)
826 return NULL;
827
Jussi Kivilinna06aa7af2009-03-26 23:40:09 +0200828 res = kzalloc(sizeof(*res) + privsz + ielen, gfp);
829 if (!res)
830 return NULL;
831
832 memcpy(res->pub.bssid, bssid, ETH_ALEN);
833 res->pub.channel = channel;
834 res->pub.signal = signal;
Johannes Berg7b8bcff2012-03-13 13:57:04 +0100835 res->pub.tsf = tsf;
Jussi Kivilinna06aa7af2009-03-26 23:40:09 +0200836 res->pub.beacon_interval = beacon_interval;
837 res->pub.capability = capability;
Jouni Malinen34a6edd2010-01-06 16:19:24 +0200838 /*
839 * Since we do not know here whether the IEs are from a Beacon or Probe
840 * Response frame, we need to pick one of the options and only use it
841 * with the driver that does not provide the full Beacon/Probe Response
842 * frame. Use Beacon frame pointer to avoid indicating that this should
843 * override the information_elements pointer should we have received an
844 * earlier indication of Probe Response data.
845 *
846 * The initial buffer for the IEs is allocated with the BSS entry and
847 * is located after the private area.
848 */
849 res->pub.beacon_ies = (u8 *)res + sizeof(*res) + privsz;
850 memcpy(res->pub.beacon_ies, ie, ielen);
851 res->pub.len_beacon_ies = ielen;
852 res->pub.information_elements = res->pub.beacon_ies;
853 res->pub.len_information_elements = res->pub.len_beacon_ies;
Jussi Kivilinna06aa7af2009-03-26 23:40:09 +0200854
855 kref_init(&res->ref);
856
Jouni Malinen34a6edd2010-01-06 16:19:24 +0200857 res = cfg80211_bss_update(wiphy_to_dev(wiphy), res);
Jussi Kivilinna06aa7af2009-03-26 23:40:09 +0200858 if (!res)
859 return NULL;
860
861 if (res->pub.capability & WLAN_CAPABILITY_ESS)
862 regulatory_hint_found_beacon(wiphy, channel, gfp);
863
Beni Lev4ee3e062012-08-27 12:49:39 +0300864 trace_cfg80211_return_bss(&res->pub);
Jussi Kivilinna06aa7af2009-03-26 23:40:09 +0200865 /* cfg80211_bss_update gives us a referenced result */
866 return &res->pub;
867}
868EXPORT_SYMBOL(cfg80211_inform_bss);
869
Johannes Berg2a519312009-02-10 21:25:55 +0100870struct cfg80211_bss *
871cfg80211_inform_bss_frame(struct wiphy *wiphy,
872 struct ieee80211_channel *channel,
873 struct ieee80211_mgmt *mgmt, size_t len,
Johannes Berg77965c92009-02-18 18:45:06 +0100874 s32 signal, gfp_t gfp)
Johannes Berg2a519312009-02-10 21:25:55 +0100875{
876 struct cfg80211_internal_bss *res;
877 size_t ielen = len - offsetof(struct ieee80211_mgmt,
878 u.probe_resp.variable);
Mariusz Kozlowskibef9bac2011-03-26 19:26:55 +0100879 size_t privsz;
880
Johannes Berg0172bb72012-11-23 14:23:30 +0100881 BUILD_BUG_ON(offsetof(struct ieee80211_mgmt, u.probe_resp.variable) !=
882 offsetof(struct ieee80211_mgmt, u.beacon.variable));
883
Beni Lev4ee3e062012-08-27 12:49:39 +0300884 trace_cfg80211_inform_bss_frame(wiphy, channel, mgmt, len, signal);
885
Mariusz Kozlowskibef9bac2011-03-26 19:26:55 +0100886 if (WARN_ON(!mgmt))
887 return NULL;
888
889 if (WARN_ON(!wiphy))
890 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +0100891
Sujith22fe88d2010-05-13 10:34:08 +0530892 if (WARN_ON(wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC &&
Hila Gonen768be592012-08-26 11:00:28 +0300893 (signal < 0 || signal > 100)))
Johannes Berg2a519312009-02-10 21:25:55 +0100894 return NULL;
895
Mariusz Kozlowskibef9bac2011-03-26 19:26:55 +0100896 if (WARN_ON(len < offsetof(struct ieee80211_mgmt, u.probe_resp.variable)))
Johannes Berg2a519312009-02-10 21:25:55 +0100897 return NULL;
898
Mariusz Kozlowskibef9bac2011-03-26 19:26:55 +0100899 privsz = wiphy->bss_priv_size;
900
Johannes Berg0172bb72012-11-23 14:23:30 +0100901 channel = cfg80211_get_bss_channel(wiphy, mgmt->u.beacon.variable,
902 ielen, channel);
903 if (!channel)
904 return NULL;
905
Johannes Berg2a519312009-02-10 21:25:55 +0100906 res = kzalloc(sizeof(*res) + privsz + ielen, gfp);
907 if (!res)
908 return NULL;
909
910 memcpy(res->pub.bssid, mgmt->bssid, ETH_ALEN);
911 res->pub.channel = channel;
Johannes Berg2a519312009-02-10 21:25:55 +0100912 res->pub.signal = signal;
913 res->pub.tsf = le64_to_cpu(mgmt->u.probe_resp.timestamp);
914 res->pub.beacon_interval = le16_to_cpu(mgmt->u.probe_resp.beacon_int);
915 res->pub.capability = le16_to_cpu(mgmt->u.probe_resp.capab_info);
Jouni Malinen34a6edd2010-01-06 16:19:24 +0200916 /*
917 * The initial buffer for the IEs is allocated with the BSS entry and
918 * is located after the private area.
919 */
920 if (ieee80211_is_probe_resp(mgmt->frame_control)) {
921 res->pub.proberesp_ies = (u8 *) res + sizeof(*res) + privsz;
922 memcpy(res->pub.proberesp_ies, mgmt->u.probe_resp.variable,
923 ielen);
924 res->pub.len_proberesp_ies = ielen;
925 res->pub.information_elements = res->pub.proberesp_ies;
926 res->pub.len_information_elements = res->pub.len_proberesp_ies;
927 } else {
928 res->pub.beacon_ies = (u8 *) res + sizeof(*res) + privsz;
929 memcpy(res->pub.beacon_ies, mgmt->u.beacon.variable, ielen);
930 res->pub.len_beacon_ies = ielen;
931 res->pub.information_elements = res->pub.beacon_ies;
932 res->pub.len_information_elements = res->pub.len_beacon_ies;
933 }
Johannes Berg2a519312009-02-10 21:25:55 +0100934
935 kref_init(&res->ref);
936
Jouni Malinen34a6edd2010-01-06 16:19:24 +0200937 res = cfg80211_bss_update(wiphy_to_dev(wiphy), res);
Johannes Berg2a519312009-02-10 21:25:55 +0100938 if (!res)
939 return NULL;
940
Luis R. Rodrigueze38f8a72009-02-21 00:20:39 -0500941 if (res->pub.capability & WLAN_CAPABILITY_ESS)
942 regulatory_hint_found_beacon(wiphy, channel, gfp);
943
Beni Lev4ee3e062012-08-27 12:49:39 +0300944 trace_cfg80211_return_bss(&res->pub);
Johannes Berg2a519312009-02-10 21:25:55 +0100945 /* cfg80211_bss_update gives us a referenced result */
946 return &res->pub;
947}
948EXPORT_SYMBOL(cfg80211_inform_bss_frame);
949
Johannes Berg4c0c0b72012-01-20 13:55:26 +0100950void cfg80211_ref_bss(struct cfg80211_bss *pub)
951{
952 struct cfg80211_internal_bss *bss;
953
954 if (!pub)
955 return;
956
957 bss = container_of(pub, struct cfg80211_internal_bss, pub);
958 kref_get(&bss->ref);
959}
960EXPORT_SYMBOL(cfg80211_ref_bss);
961
Johannes Berg2a519312009-02-10 21:25:55 +0100962void cfg80211_put_bss(struct cfg80211_bss *pub)
963{
964 struct cfg80211_internal_bss *bss;
965
966 if (!pub)
967 return;
968
969 bss = container_of(pub, struct cfg80211_internal_bss, pub);
970 kref_put(&bss->ref, bss_release);
971}
972EXPORT_SYMBOL(cfg80211_put_bss);
973
Johannes Bergd491af12009-02-10 21:25:58 +0100974void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *pub)
975{
976 struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy);
977 struct cfg80211_internal_bss *bss;
978
979 if (WARN_ON(!pub))
980 return;
981
982 bss = container_of(pub, struct cfg80211_internal_bss, pub);
983
984 spin_lock_bh(&dev->bss_lock);
Johannes Berg32073902010-10-06 21:18:04 +0200985 if (!list_empty(&bss->list)) {
Juuso Oikarinen2b78ac92011-03-28 14:32:32 +0300986 __cfg80211_unlink_bss(dev, bss);
Johannes Berg32073902010-10-06 21:18:04 +0200987 dev->bss_generation++;
Johannes Berg32073902010-10-06 21:18:04 +0200988 }
Johannes Bergd491af12009-02-10 21:25:58 +0100989 spin_unlock_bh(&dev->bss_lock);
Johannes Bergd491af12009-02-10 21:25:58 +0100990}
991EXPORT_SYMBOL(cfg80211_unlink_bss);
992
Johannes Berg3d23e342009-09-29 23:27:28 +0200993#ifdef CONFIG_CFG80211_WEXT
Johannes Berg2a519312009-02-10 21:25:55 +0100994int cfg80211_wext_siwscan(struct net_device *dev,
995 struct iw_request_info *info,
996 union iwreq_data *wrqu, char *extra)
997{
998 struct cfg80211_registered_device *rdev;
999 struct wiphy *wiphy;
1000 struct iw_scan_req *wreq = NULL;
Johannes Berg65486c8b2009-12-23 15:33:35 +01001001 struct cfg80211_scan_request *creq = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01001002 int i, err, n_channels = 0;
1003 enum ieee80211_band band;
1004
1005 if (!netif_running(dev))
1006 return -ENETDOWN;
1007
Holger Schurigb2e3abd2009-09-09 13:09:54 +02001008 if (wrqu->data.length == sizeof(struct iw_scan_req))
1009 wreq = (struct iw_scan_req *)extra;
1010
Johannes Berg463d0182009-07-14 00:33:35 +02001011 rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex);
Johannes Berg2a519312009-02-10 21:25:55 +01001012
1013 if (IS_ERR(rdev))
1014 return PTR_ERR(rdev);
1015
1016 if (rdev->scan_req) {
1017 err = -EBUSY;
1018 goto out;
1019 }
1020
1021 wiphy = &rdev->wiphy;
1022
Holger Schurigb2e3abd2009-09-09 13:09:54 +02001023 /* Determine number of channels, needed to allocate creq */
1024 if (wreq && wreq->num_channels)
1025 n_channels = wreq->num_channels;
1026 else {
1027 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
1028 if (wiphy->bands[band])
1029 n_channels += wiphy->bands[band]->n_channels;
1030 }
Johannes Berg2a519312009-02-10 21:25:55 +01001031
1032 creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
1033 n_channels * sizeof(void *),
1034 GFP_ATOMIC);
1035 if (!creq) {
1036 err = -ENOMEM;
1037 goto out;
1038 }
1039
1040 creq->wiphy = wiphy;
Johannes Bergfd014282012-06-18 19:17:03 +02001041 creq->wdev = dev->ieee80211_ptr;
Johannes Berg5ba63532009-08-07 17:54:07 +02001042 /* SSIDs come after channels */
1043 creq->ssids = (void *)&creq->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01001044 creq->n_channels = n_channels;
1045 creq->n_ssids = 1;
Sam Leffler15d60302012-10-11 21:03:34 -07001046 creq->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01001047
Holger Schurigb2e3abd2009-09-09 13:09:54 +02001048 /* translate "Scan on frequencies" request */
Johannes Berg2a519312009-02-10 21:25:55 +01001049 i = 0;
1050 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
1051 int j;
Johannes Berg584991d2009-11-02 13:32:03 +01001052
Johannes Berg2a519312009-02-10 21:25:55 +01001053 if (!wiphy->bands[band])
1054 continue;
Johannes Berg584991d2009-11-02 13:32:03 +01001055
Johannes Berg2a519312009-02-10 21:25:55 +01001056 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01001057 /* ignore disabled channels */
1058 if (wiphy->bands[band]->channels[j].flags &
1059 IEEE80211_CHAN_DISABLED)
1060 continue;
Holger Schurigb2e3abd2009-09-09 13:09:54 +02001061
1062 /* If we have a wireless request structure and the
1063 * wireless request specifies frequencies, then search
1064 * for the matching hardware channel.
1065 */
1066 if (wreq && wreq->num_channels) {
1067 int k;
1068 int wiphy_freq = wiphy->bands[band]->channels[j].center_freq;
1069 for (k = 0; k < wreq->num_channels; k++) {
Holger Schuriga4e7b732009-09-11 10:13:53 +02001070 int wext_freq = cfg80211_wext_freq(wiphy, &wreq->channel_list[k]);
Holger Schurigb2e3abd2009-09-09 13:09:54 +02001071 if (wext_freq == wiphy_freq)
1072 goto wext_freq_found;
1073 }
1074 goto wext_freq_not_found;
1075 }
1076
1077 wext_freq_found:
Johannes Berg2a519312009-02-10 21:25:55 +01001078 creq->channels[i] = &wiphy->bands[band]->channels[j];
1079 i++;
Holger Schurigb2e3abd2009-09-09 13:09:54 +02001080 wext_freq_not_found: ;
Johannes Berg2a519312009-02-10 21:25:55 +01001081 }
1082 }
Holger Schurig8862dc52009-09-11 10:13:55 +02001083 /* No channels found? */
1084 if (!i) {
1085 err = -EINVAL;
1086 goto out;
1087 }
Johannes Berg2a519312009-02-10 21:25:55 +01001088
Holger Schurigb2e3abd2009-09-09 13:09:54 +02001089 /* Set real number of channels specified in creq->channels[] */
1090 creq->n_channels = i;
Johannes Berg2a519312009-02-10 21:25:55 +01001091
Holger Schurigb2e3abd2009-09-09 13:09:54 +02001092 /* translate "Scan for SSID" request */
1093 if (wreq) {
Johannes Berg2a519312009-02-10 21:25:55 +01001094 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
Johannes Berg65486c8b2009-12-23 15:33:35 +01001095 if (wreq->essid_len > IEEE80211_MAX_SSID_LEN) {
1096 err = -EINVAL;
1097 goto out;
1098 }
Johannes Berg2a519312009-02-10 21:25:55 +01001099 memcpy(creq->ssids[0].ssid, wreq->essid, wreq->essid_len);
1100 creq->ssids[0].ssid_len = wreq->essid_len;
1101 }
1102 if (wreq->scan_type == IW_SCAN_TYPE_PASSIVE)
1103 creq->n_ssids = 0;
1104 }
1105
Johannes Berg34850ab2011-07-18 18:08:35 +02001106 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02001107 if (wiphy->bands[i])
1108 creq->rates[i] = (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02001109
Johannes Berg2a519312009-02-10 21:25:55 +01001110 rdev->scan_req = creq;
Hila Gonene35e4d22012-06-27 17:19:42 +03001111 err = rdev_scan(rdev, creq);
Johannes Berg2a519312009-02-10 21:25:55 +01001112 if (err) {
1113 rdev->scan_req = NULL;
Johannes Berg65486c8b2009-12-23 15:33:35 +01001114 /* creq will be freed below */
Johannes Berg463d0182009-07-14 00:33:35 +02001115 } else {
Johannes Bergfd014282012-06-18 19:17:03 +02001116 nl80211_send_scan_start(rdev, dev->ieee80211_ptr);
Johannes Berg65486c8b2009-12-23 15:33:35 +01001117 /* creq now owned by driver */
1118 creq = NULL;
Johannes Berg463d0182009-07-14 00:33:35 +02001119 dev_hold(dev);
1120 }
Johannes Berg2a519312009-02-10 21:25:55 +01001121 out:
Johannes Berg65486c8b2009-12-23 15:33:35 +01001122 kfree(creq);
Johannes Berg4d0c8ae2009-07-07 03:56:09 +02001123 cfg80211_unlock_rdev(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01001124 return err;
1125}
Johannes Bergba44cb72009-04-20 18:49:39 +02001126EXPORT_SYMBOL_GPL(cfg80211_wext_siwscan);
Johannes Berg2a519312009-02-10 21:25:55 +01001127
1128static void ieee80211_scan_add_ies(struct iw_request_info *info,
1129 struct cfg80211_bss *bss,
1130 char **current_ev, char *end_buf)
1131{
1132 u8 *pos, *end, *next;
1133 struct iw_event iwe;
1134
1135 if (!bss->information_elements ||
1136 !bss->len_information_elements)
1137 return;
1138
1139 /*
1140 * If needed, fragment the IEs buffer (at IE boundaries) into short
1141 * enough fragments to fit into IW_GENERIC_IE_MAX octet messages.
1142 */
1143 pos = bss->information_elements;
1144 end = pos + bss->len_information_elements;
1145
1146 while (end - pos > IW_GENERIC_IE_MAX) {
1147 next = pos + 2 + pos[1];
1148 while (next + 2 + next[1] - pos < IW_GENERIC_IE_MAX)
1149 next = next + 2 + next[1];
1150
1151 memset(&iwe, 0, sizeof(iwe));
1152 iwe.cmd = IWEVGENIE;
1153 iwe.u.data.length = next - pos;
1154 *current_ev = iwe_stream_add_point(info, *current_ev,
1155 end_buf, &iwe, pos);
1156
1157 pos = next;
1158 }
1159
1160 if (end > pos) {
1161 memset(&iwe, 0, sizeof(iwe));
1162 iwe.cmd = IWEVGENIE;
1163 iwe.u.data.length = end - pos;
1164 *current_ev = iwe_stream_add_point(info, *current_ev,
1165 end_buf, &iwe, pos);
1166 }
1167}
1168
Dan Williamscb3a8ee2009-02-11 17:14:43 -05001169static inline unsigned int elapsed_jiffies_msecs(unsigned long start)
1170{
1171 unsigned long end = jiffies;
1172
1173 if (end >= start)
1174 return jiffies_to_msecs(end - start);
1175
1176 return jiffies_to_msecs(end + (MAX_JIFFY_OFFSET - start) + 1);
1177}
Johannes Berg2a519312009-02-10 21:25:55 +01001178
1179static char *
Johannes Berg77965c92009-02-18 18:45:06 +01001180ieee80211_bss(struct wiphy *wiphy, struct iw_request_info *info,
1181 struct cfg80211_internal_bss *bss, char *current_ev,
1182 char *end_buf)
Johannes Berg2a519312009-02-10 21:25:55 +01001183{
1184 struct iw_event iwe;
1185 u8 *buf, *cfg, *p;
1186 u8 *ie = bss->pub.information_elements;
Johannes Berga77b8552009-02-18 18:27:22 +01001187 int rem = bss->pub.len_information_elements, i, sig;
Johannes Berg2a519312009-02-10 21:25:55 +01001188 bool ismesh = false;
1189
1190 memset(&iwe, 0, sizeof(iwe));
1191 iwe.cmd = SIOCGIWAP;
1192 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1193 memcpy(iwe.u.ap_addr.sa_data, bss->pub.bssid, ETH_ALEN);
1194 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1195 IW_EV_ADDR_LEN);
1196
1197 memset(&iwe, 0, sizeof(iwe));
1198 iwe.cmd = SIOCGIWFREQ;
1199 iwe.u.freq.m = ieee80211_frequency_to_channel(bss->pub.channel->center_freq);
1200 iwe.u.freq.e = 0;
1201 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1202 IW_EV_FREQ_LEN);
1203
1204 memset(&iwe, 0, sizeof(iwe));
1205 iwe.cmd = SIOCGIWFREQ;
1206 iwe.u.freq.m = bss->pub.channel->center_freq;
1207 iwe.u.freq.e = 6;
1208 current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe,
1209 IW_EV_FREQ_LEN);
1210
Johannes Berg77965c92009-02-18 18:45:06 +01001211 if (wiphy->signal_type != CFG80211_SIGNAL_TYPE_NONE) {
Johannes Berg2a519312009-02-10 21:25:55 +01001212 memset(&iwe, 0, sizeof(iwe));
1213 iwe.cmd = IWEVQUAL;
1214 iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED |
1215 IW_QUAL_NOISE_INVALID |
Johannes Berga77b8552009-02-18 18:27:22 +01001216 IW_QUAL_QUAL_UPDATED;
Johannes Berg77965c92009-02-18 18:45:06 +01001217 switch (wiphy->signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01001218 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berga77b8552009-02-18 18:27:22 +01001219 sig = bss->pub.signal / 100;
1220 iwe.u.qual.level = sig;
Johannes Berg2a519312009-02-10 21:25:55 +01001221 iwe.u.qual.updated |= IW_QUAL_DBM;
Johannes Berga77b8552009-02-18 18:27:22 +01001222 if (sig < -110) /* rather bad */
1223 sig = -110;
1224 else if (sig > -40) /* perfect */
1225 sig = -40;
1226 /* will give a range of 0 .. 70 */
1227 iwe.u.qual.qual = sig + 110;
Johannes Berg2a519312009-02-10 21:25:55 +01001228 break;
1229 case CFG80211_SIGNAL_TYPE_UNSPEC:
1230 iwe.u.qual.level = bss->pub.signal;
Johannes Berga77b8552009-02-18 18:27:22 +01001231 /* will give range 0 .. 100 */
1232 iwe.u.qual.qual = bss->pub.signal;
Johannes Berg2a519312009-02-10 21:25:55 +01001233 break;
1234 default:
1235 /* not reached */
1236 break;
1237 }
1238 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1239 &iwe, IW_EV_QUAL_LEN);
1240 }
1241
1242 memset(&iwe, 0, sizeof(iwe));
1243 iwe.cmd = SIOCGIWENCODE;
1244 if (bss->pub.capability & WLAN_CAPABILITY_PRIVACY)
1245 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1246 else
1247 iwe.u.data.flags = IW_ENCODE_DISABLED;
1248 iwe.u.data.length = 0;
1249 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1250 &iwe, "");
1251
1252 while (rem >= 2) {
1253 /* invalid data */
1254 if (ie[1] > rem - 2)
1255 break;
1256
1257 switch (ie[0]) {
1258 case WLAN_EID_SSID:
1259 memset(&iwe, 0, sizeof(iwe));
1260 iwe.cmd = SIOCGIWESSID;
1261 iwe.u.data.length = ie[1];
1262 iwe.u.data.flags = 1;
1263 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1264 &iwe, ie + 2);
1265 break;
1266 case WLAN_EID_MESH_ID:
1267 memset(&iwe, 0, sizeof(iwe));
1268 iwe.cmd = SIOCGIWESSID;
1269 iwe.u.data.length = ie[1];
1270 iwe.u.data.flags = 1;
1271 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1272 &iwe, ie + 2);
1273 break;
1274 case WLAN_EID_MESH_CONFIG:
1275 ismesh = true;
Rui Paulo136cfa22009-11-18 18:40:00 +00001276 if (ie[1] != sizeof(struct ieee80211_meshconf_ie))
Johannes Berg2a519312009-02-10 21:25:55 +01001277 break;
1278 buf = kmalloc(50, GFP_ATOMIC);
1279 if (!buf)
1280 break;
1281 cfg = ie + 2;
1282 memset(&iwe, 0, sizeof(iwe));
1283 iwe.cmd = IWEVCUSTOM;
Rui Paulo76aa5e72009-11-18 18:22:59 +00001284 sprintf(buf, "Mesh Network Path Selection Protocol ID: "
1285 "0x%02X", cfg[0]);
Johannes Berg2a519312009-02-10 21:25:55 +01001286 iwe.u.data.length = strlen(buf);
1287 current_ev = iwe_stream_add_point(info, current_ev,
1288 end_buf,
1289 &iwe, buf);
Rui Paulo76aa5e72009-11-18 18:22:59 +00001290 sprintf(buf, "Path Selection Metric ID: 0x%02X",
1291 cfg[1]);
Johannes Berg2a519312009-02-10 21:25:55 +01001292 iwe.u.data.length = strlen(buf);
1293 current_ev = iwe_stream_add_point(info, current_ev,
1294 end_buf,
1295 &iwe, buf);
Rui Paulo76aa5e72009-11-18 18:22:59 +00001296 sprintf(buf, "Congestion Control Mode ID: 0x%02X",
1297 cfg[2]);
Johannes Berg2a519312009-02-10 21:25:55 +01001298 iwe.u.data.length = strlen(buf);
1299 current_ev = iwe_stream_add_point(info, current_ev,
1300 end_buf,
1301 &iwe, buf);
Rui Paulo76aa5e72009-11-18 18:22:59 +00001302 sprintf(buf, "Synchronization ID: 0x%02X", cfg[3]);
Johannes Berg2a519312009-02-10 21:25:55 +01001303 iwe.u.data.length = strlen(buf);
1304 current_ev = iwe_stream_add_point(info, current_ev,
1305 end_buf,
1306 &iwe, buf);
Rui Paulo76aa5e72009-11-18 18:22:59 +00001307 sprintf(buf, "Authentication ID: 0x%02X", cfg[4]);
1308 iwe.u.data.length = strlen(buf);
1309 current_ev = iwe_stream_add_point(info, current_ev,
1310 end_buf,
1311 &iwe, buf);
1312 sprintf(buf, "Formation Info: 0x%02X", cfg[5]);
1313 iwe.u.data.length = strlen(buf);
1314 current_ev = iwe_stream_add_point(info, current_ev,
1315 end_buf,
1316 &iwe, buf);
1317 sprintf(buf, "Capabilities: 0x%02X", cfg[6]);
Johannes Berg2a519312009-02-10 21:25:55 +01001318 iwe.u.data.length = strlen(buf);
1319 current_ev = iwe_stream_add_point(info, current_ev,
1320 end_buf,
1321 &iwe, buf);
1322 kfree(buf);
1323 break;
1324 case WLAN_EID_SUPP_RATES:
1325 case WLAN_EID_EXT_SUPP_RATES:
1326 /* display all supported rates in readable format */
1327 p = current_ev + iwe_stream_lcp_len(info);
1328
1329 memset(&iwe, 0, sizeof(iwe));
1330 iwe.cmd = SIOCGIWRATE;
1331 /* Those two flags are ignored... */
1332 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1333
1334 for (i = 0; i < ie[1]; i++) {
1335 iwe.u.bitrate.value =
1336 ((ie[i + 2] & 0x7f) * 500000);
1337 p = iwe_stream_add_value(info, current_ev, p,
1338 end_buf, &iwe, IW_EV_PARAM_LEN);
1339 }
1340 current_ev = p;
1341 break;
1342 }
1343 rem -= ie[1] + 2;
1344 ie += ie[1] + 2;
1345 }
1346
Joe Perchesf64f9e72009-11-29 16:55:45 -08001347 if (bss->pub.capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS) ||
1348 ismesh) {
Johannes Berg2a519312009-02-10 21:25:55 +01001349 memset(&iwe, 0, sizeof(iwe));
1350 iwe.cmd = SIOCGIWMODE;
1351 if (ismesh)
1352 iwe.u.mode = IW_MODE_MESH;
1353 else if (bss->pub.capability & WLAN_CAPABILITY_ESS)
1354 iwe.u.mode = IW_MODE_MASTER;
1355 else
1356 iwe.u.mode = IW_MODE_ADHOC;
1357 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
1358 &iwe, IW_EV_UINT_LEN);
1359 }
1360
1361 buf = kmalloc(30, GFP_ATOMIC);
1362 if (buf) {
1363 memset(&iwe, 0, sizeof(iwe));
1364 iwe.cmd = IWEVCUSTOM;
1365 sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->pub.tsf));
1366 iwe.u.data.length = strlen(buf);
1367 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
1368 &iwe, buf);
1369 memset(&iwe, 0, sizeof(iwe));
1370 iwe.cmd = IWEVCUSTOM;
Dan Williamscb3a8ee2009-02-11 17:14:43 -05001371 sprintf(buf, " Last beacon: %ums ago",
1372 elapsed_jiffies_msecs(bss->ts));
Johannes Berg2a519312009-02-10 21:25:55 +01001373 iwe.u.data.length = strlen(buf);
1374 current_ev = iwe_stream_add_point(info, current_ev,
1375 end_buf, &iwe, buf);
1376 kfree(buf);
1377 }
1378
1379 ieee80211_scan_add_ies(info, &bss->pub, &current_ev, end_buf);
1380
1381 return current_ev;
1382}
1383
1384
1385static int ieee80211_scan_results(struct cfg80211_registered_device *dev,
1386 struct iw_request_info *info,
1387 char *buf, size_t len)
1388{
1389 char *current_ev = buf;
1390 char *end_buf = buf + len;
1391 struct cfg80211_internal_bss *bss;
1392
1393 spin_lock_bh(&dev->bss_lock);
1394 cfg80211_bss_expire(dev);
1395
1396 list_for_each_entry(bss, &dev->bss_list, list) {
1397 if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
1398 spin_unlock_bh(&dev->bss_lock);
1399 return -E2BIG;
1400 }
Johannes Berg77965c92009-02-18 18:45:06 +01001401 current_ev = ieee80211_bss(&dev->wiphy, info, bss,
1402 current_ev, end_buf);
Johannes Berg2a519312009-02-10 21:25:55 +01001403 }
1404 spin_unlock_bh(&dev->bss_lock);
1405 return current_ev - buf;
1406}
1407
1408
1409int cfg80211_wext_giwscan(struct net_device *dev,
1410 struct iw_request_info *info,
1411 struct iw_point *data, char *extra)
1412{
1413 struct cfg80211_registered_device *rdev;
1414 int res;
1415
1416 if (!netif_running(dev))
1417 return -ENETDOWN;
1418
Johannes Berg463d0182009-07-14 00:33:35 +02001419 rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex);
Johannes Berg2a519312009-02-10 21:25:55 +01001420
1421 if (IS_ERR(rdev))
1422 return PTR_ERR(rdev);
1423
1424 if (rdev->scan_req) {
1425 res = -EAGAIN;
1426 goto out;
1427 }
1428
1429 res = ieee80211_scan_results(rdev, info, extra, data->length);
1430 data->length = 0;
1431 if (res >= 0) {
1432 data->length = res;
1433 res = 0;
1434 }
1435
1436 out:
Johannes Berg4d0c8ae2009-07-07 03:56:09 +02001437 cfg80211_unlock_rdev(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01001438 return res;
1439}
Johannes Bergba44cb72009-04-20 18:49:39 +02001440EXPORT_SYMBOL_GPL(cfg80211_wext_giwscan);
Johannes Berg2a519312009-02-10 21:25:55 +01001441#endif