]>
Commit | Line | Data |
---|---|---|
2a519311 JB |
1 | /* |
2 | * cfg80211 scan result handling | |
3 | * | |
4 | * Copyright 2008 Johannes Berg <[email protected]> | |
5 | */ | |
6 | #include <linux/kernel.h> | |
5a0e3ad6 | 7 | #include <linux/slab.h> |
2a519311 JB |
8 | #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> | |
262eb9b2 | 15 | #include <net/cfg80211-wext.h> |
2a519311 JB |
16 | #include <net/iw_handler.h> |
17 | #include "core.h" | |
18 | #include "nl80211.h" | |
a9a11622 | 19 | #include "wext-compat.h" |
e35e4d28 | 20 | #include "rdev-ops.h" |
2a519311 | 21 | |
776b3580 JB |
22 | /** |
23 | * DOC: BSS tree/list structure | |
24 | * | |
25 | * At the top level, the BSS list is kept in both a list in each | |
26 | * registered device (@bss_list) as well as an RB-tree for faster | |
27 | * lookup. In the RB-tree, entries can be looked up using their | |
28 | * channel, MESHID, MESHCONF (for MBSSes) or channel, BSSID, SSID | |
29 | * for other BSSes. | |
30 | * | |
31 | * Due to the possibility of hidden SSIDs, there's a second level | |
32 | * structure, the "hidden_list" and "hidden_beacon_bss" pointer. | |
33 | * The hidden_list connects all BSSes belonging to a single AP | |
34 | * that has a hidden SSID, and connects beacon and probe response | |
35 | * entries. For a probe response entry for a hidden SSID, the | |
36 | * hidden_beacon_bss pointer points to the BSS struct holding the | |
37 | * beacon's information. | |
38 | * | |
39 | * Reference counting is done for all these references except for | |
40 | * the hidden_list, so that a beacon BSS struct that is otherwise | |
41 | * not referenced has one reference for being on the bss_list and | |
42 | * one for each probe response entry that points to it using the | |
43 | * hidden_beacon_bss pointer. When a BSS struct that has such a | |
44 | * pointer is get/put, the refcount update is also propagated to | |
45 | * the referenced struct, this ensure that it cannot get removed | |
46 | * while somebody is using the probe response version. | |
47 | * | |
48 | * Note that the hidden_beacon_bss pointer never changes, due to | |
49 | * the reference counting. Therefore, no locking is needed for | |
50 | * it. | |
51 | * | |
52 | * Also note that the hidden_beacon_bss pointer is only relevant | |
53 | * if the driver uses something other than the IEs, e.g. private | |
54 | * data stored stored in the BSS struct, since the beacon IEs are | |
55 | * also linked into the probe response struct. | |
56 | */ | |
57 | ||
f9616e0f | 58 | #define IEEE80211_SCAN_RESULT_EXPIRE (30 * HZ) |
2a519311 | 59 | |
776b3580 | 60 | static void bss_free(struct cfg80211_internal_bss *bss) |
e8e27c66 | 61 | { |
9caf0364 | 62 | struct cfg80211_bss_ies *ies; |
b629ea3d JB |
63 | |
64 | if (WARN_ON(atomic_read(&bss->hold))) | |
65 | return; | |
66 | ||
9caf0364 | 67 | ies = (void *)rcu_access_pointer(bss->pub.beacon_ies); |
776b3580 | 68 | if (ies && !bss->pub.hidden_beacon_bss) |
9caf0364 JB |
69 | kfree_rcu(ies, rcu_head); |
70 | ies = (void *)rcu_access_pointer(bss->pub.proberesp_ies); | |
71 | if (ies) | |
72 | kfree_rcu(ies, rcu_head); | |
e8e27c66 | 73 | |
776b3580 JB |
74 | /* |
75 | * This happens when the module is removed, it doesn't | |
76 | * really matter any more save for completeness | |
77 | */ | |
78 | if (!list_empty(&bss->hidden_list)) | |
79 | list_del(&bss->hidden_list); | |
80 | ||
e8e27c66 AK |
81 | kfree(bss); |
82 | } | |
83 | ||
776b3580 JB |
84 | static inline void bss_ref_get(struct cfg80211_registered_device *dev, |
85 | struct cfg80211_internal_bss *bss) | |
0532d4f1 | 86 | { |
776b3580 JB |
87 | lockdep_assert_held(&dev->bss_lock); |
88 | ||
89 | bss->refcount++; | |
90 | if (bss->pub.hidden_beacon_bss) { | |
91 | bss = container_of(bss->pub.hidden_beacon_bss, | |
92 | struct cfg80211_internal_bss, | |
93 | pub); | |
94 | bss->refcount++; | |
95 | } | |
0532d4f1 JB |
96 | } |
97 | ||
776b3580 JB |
98 | static inline void bss_ref_put(struct cfg80211_registered_device *dev, |
99 | struct cfg80211_internal_bss *bss) | |
0532d4f1 | 100 | { |
776b3580 JB |
101 | lockdep_assert_held(&dev->bss_lock); |
102 | ||
103 | if (bss->pub.hidden_beacon_bss) { | |
104 | struct cfg80211_internal_bss *hbss; | |
105 | hbss = container_of(bss->pub.hidden_beacon_bss, | |
106 | struct cfg80211_internal_bss, | |
107 | pub); | |
108 | hbss->refcount--; | |
109 | if (hbss->refcount == 0) | |
110 | bss_free(hbss); | |
111 | } | |
112 | bss->refcount--; | |
113 | if (bss->refcount == 0) | |
114 | bss_free(bss); | |
0532d4f1 JB |
115 | } |
116 | ||
776b3580 | 117 | static bool __cfg80211_unlink_bss(struct cfg80211_registered_device *dev, |
e8e27c66 AK |
118 | struct cfg80211_internal_bss *bss) |
119 | { | |
4b1af479 JB |
120 | lockdep_assert_held(&dev->bss_lock); |
121 | ||
776b3580 JB |
122 | if (!list_empty(&bss->hidden_list)) { |
123 | /* | |
124 | * don't remove the beacon entry if it has | |
125 | * probe responses associated with it | |
126 | */ | |
127 | if (!bss->pub.hidden_beacon_bss) | |
128 | return false; | |
129 | /* | |
130 | * if it's a probe response entry break its | |
131 | * link to the other entries in the group | |
132 | */ | |
133 | list_del_init(&bss->hidden_list); | |
134 | } | |
135 | ||
e8e27c66 AK |
136 | list_del_init(&bss->list); |
137 | rb_erase(&bss->rbn, &dev->bss_tree); | |
776b3580 JB |
138 | bss_ref_put(dev, bss); |
139 | return true; | |
e8e27c66 AK |
140 | } |
141 | ||
15d6030b SL |
142 | static void __cfg80211_bss_expire(struct cfg80211_registered_device *dev, |
143 | unsigned long expire_time) | |
144 | { | |
145 | struct cfg80211_internal_bss *bss, *tmp; | |
146 | bool expired = false; | |
147 | ||
4b1af479 JB |
148 | lockdep_assert_held(&dev->bss_lock); |
149 | ||
15d6030b SL |
150 | list_for_each_entry_safe(bss, tmp, &dev->bss_list, list) { |
151 | if (atomic_read(&bss->hold)) | |
152 | continue; | |
153 | if (!time_after(expire_time, bss->ts)) | |
154 | continue; | |
155 | ||
776b3580 JB |
156 | if (__cfg80211_unlink_bss(dev, bss)) |
157 | expired = true; | |
15d6030b SL |
158 | } |
159 | ||
160 | if (expired) | |
161 | dev->bss_generation++; | |
162 | } | |
163 | ||
01a0ac41 | 164 | void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev, bool leak) |
2a519311 | 165 | { |
667503dd | 166 | struct cfg80211_scan_request *request; |
fd014284 | 167 | struct wireless_dev *wdev; |
3d23e349 | 168 | #ifdef CONFIG_CFG80211_WEXT |
2a519311 JB |
169 | union iwreq_data wrqu; |
170 | #endif | |
171 | ||
01a0ac41 JB |
172 | ASSERT_RDEV_LOCK(rdev); |
173 | ||
667503dd JB |
174 | request = rdev->scan_req; |
175 | ||
01a0ac41 JB |
176 | if (!request) |
177 | return; | |
178 | ||
fd014284 | 179 | wdev = request->wdev; |
2a519311 | 180 | |
6829c878 JB |
181 | /* |
182 | * This must be before sending the other events! | |
183 | * Otherwise, wpa_supplicant gets completely confused with | |
184 | * wext events. | |
185 | */ | |
fd014284 JB |
186 | if (wdev->netdev) |
187 | cfg80211_sme_scan_done(wdev->netdev); | |
6829c878 | 188 | |
15d6030b | 189 | if (request->aborted) { |
fd014284 | 190 | nl80211_send_scan_aborted(rdev, wdev); |
15d6030b SL |
191 | } else { |
192 | if (request->flags & NL80211_SCAN_FLAG_FLUSH) { | |
193 | /* flush entries from previous scans */ | |
194 | spin_lock_bh(&rdev->bss_lock); | |
195 | __cfg80211_bss_expire(rdev, request->scan_start); | |
196 | spin_unlock_bh(&rdev->bss_lock); | |
197 | } | |
fd014284 | 198 | nl80211_send_scan_done(rdev, wdev); |
15d6030b | 199 | } |
2a519311 | 200 | |
3d23e349 | 201 | #ifdef CONFIG_CFG80211_WEXT |
fd014284 | 202 | if (wdev->netdev && !request->aborted) { |
2a519311 JB |
203 | memset(&wrqu, 0, sizeof(wrqu)); |
204 | ||
fd014284 | 205 | wireless_send_event(wdev->netdev, SIOCGIWSCAN, &wrqu, NULL); |
2a519311 JB |
206 | } |
207 | #endif | |
208 | ||
fd014284 JB |
209 | if (wdev->netdev) |
210 | dev_put(wdev->netdev); | |
2a519311 | 211 | |
36e6fea8 | 212 | rdev->scan_req = NULL; |
01a0ac41 JB |
213 | |
214 | /* | |
215 | * OK. If this is invoked with "leak" then we can't | |
216 | * free this ... but we've cleaned it up anyway. The | |
217 | * driver failed to call the scan_done callback, so | |
218 | * all bets are off, it might still be trying to use | |
219 | * the scan request or not ... if it accesses the dev | |
220 | * in there (it shouldn't anyway) then it may crash. | |
221 | */ | |
222 | if (!leak) | |
223 | kfree(request); | |
2a519311 | 224 | } |
667503dd | 225 | |
36e6fea8 JB |
226 | void __cfg80211_scan_done(struct work_struct *wk) |
227 | { | |
228 | struct cfg80211_registered_device *rdev; | |
229 | ||
230 | rdev = container_of(wk, struct cfg80211_registered_device, | |
231 | scan_done_wk); | |
232 | ||
233 | cfg80211_lock_rdev(rdev); | |
01a0ac41 | 234 | ___cfg80211_scan_done(rdev, false); |
36e6fea8 JB |
235 | cfg80211_unlock_rdev(rdev); |
236 | } | |
237 | ||
667503dd JB |
238 | void cfg80211_scan_done(struct cfg80211_scan_request *request, bool aborted) |
239 | { | |
4ee3e063 | 240 | trace_cfg80211_scan_done(request, aborted); |
667503dd JB |
241 | WARN_ON(request != wiphy_to_dev(request->wiphy)->scan_req); |
242 | ||
243 | request->aborted = aborted; | |
e60d7443 | 244 | queue_work(cfg80211_wq, &wiphy_to_dev(request->wiphy)->scan_done_wk); |
667503dd | 245 | } |
2a519311 JB |
246 | EXPORT_SYMBOL(cfg80211_scan_done); |
247 | ||
807f8a8c LC |
248 | void __cfg80211_sched_scan_results(struct work_struct *wk) |
249 | { | |
250 | struct cfg80211_registered_device *rdev; | |
15d6030b | 251 | struct cfg80211_sched_scan_request *request; |
807f8a8c LC |
252 | |
253 | rdev = container_of(wk, struct cfg80211_registered_device, | |
254 | sched_scan_results_wk); | |
255 | ||
15d6030b SL |
256 | request = rdev->sched_scan_req; |
257 | ||
c10841ca | 258 | mutex_lock(&rdev->sched_scan_mtx); |
807f8a8c LC |
259 | |
260 | /* we don't have sched_scan_req anymore if the scan is stopping */ | |
15d6030b SL |
261 | if (request) { |
262 | if (request->flags & NL80211_SCAN_FLAG_FLUSH) { | |
263 | /* flush entries from previous scans */ | |
264 | spin_lock_bh(&rdev->bss_lock); | |
265 | __cfg80211_bss_expire(rdev, request->scan_start); | |
266 | spin_unlock_bh(&rdev->bss_lock); | |
267 | request->scan_start = | |
268 | jiffies + msecs_to_jiffies(request->interval); | |
269 | } | |
270 | nl80211_send_sched_scan_results(rdev, request->dev); | |
271 | } | |
807f8a8c | 272 | |
c10841ca | 273 | mutex_unlock(&rdev->sched_scan_mtx); |
807f8a8c LC |
274 | } |
275 | ||
276 | void cfg80211_sched_scan_results(struct wiphy *wiphy) | |
277 | { | |
4ee3e063 | 278 | trace_cfg80211_sched_scan_results(wiphy); |
807f8a8c LC |
279 | /* ignore if we're not scanning */ |
280 | if (wiphy_to_dev(wiphy)->sched_scan_req) | |
281 | queue_work(cfg80211_wq, | |
282 | &wiphy_to_dev(wiphy)->sched_scan_results_wk); | |
283 | } | |
284 | EXPORT_SYMBOL(cfg80211_sched_scan_results); | |
285 | ||
85a9994a | 286 | void cfg80211_sched_scan_stopped(struct wiphy *wiphy) |
807f8a8c | 287 | { |
85a9994a | 288 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
807f8a8c | 289 | |
4ee3e063 BL |
290 | trace_cfg80211_sched_scan_stopped(wiphy); |
291 | ||
c10841ca | 292 | mutex_lock(&rdev->sched_scan_mtx); |
807f8a8c | 293 | __cfg80211_stop_sched_scan(rdev, true); |
c10841ca | 294 | mutex_unlock(&rdev->sched_scan_mtx); |
807f8a8c | 295 | } |
807f8a8c LC |
296 | EXPORT_SYMBOL(cfg80211_sched_scan_stopped); |
297 | ||
298 | int __cfg80211_stop_sched_scan(struct cfg80211_registered_device *rdev, | |
299 | bool driver_initiated) | |
300 | { | |
807f8a8c LC |
301 | struct net_device *dev; |
302 | ||
c10841ca | 303 | lockdep_assert_held(&rdev->sched_scan_mtx); |
807f8a8c LC |
304 | |
305 | if (!rdev->sched_scan_req) | |
1a84ff75 | 306 | return -ENOENT; |
807f8a8c LC |
307 | |
308 | dev = rdev->sched_scan_req->dev; | |
309 | ||
85a9994a | 310 | if (!driver_initiated) { |
e35e4d28 | 311 | int err = rdev_sched_scan_stop(rdev, dev); |
85a9994a LC |
312 | if (err) |
313 | return err; | |
314 | } | |
807f8a8c LC |
315 | |
316 | nl80211_send_sched_scan(rdev, dev, NL80211_CMD_SCHED_SCAN_STOPPED); | |
317 | ||
318 | kfree(rdev->sched_scan_req); | |
319 | rdev->sched_scan_req = NULL; | |
320 | ||
3b4670ff | 321 | return 0; |
807f8a8c LC |
322 | } |
323 | ||
cb3a8eec DW |
324 | void cfg80211_bss_age(struct cfg80211_registered_device *dev, |
325 | unsigned long age_secs) | |
326 | { | |
327 | struct cfg80211_internal_bss *bss; | |
328 | unsigned long age_jiffies = msecs_to_jiffies(age_secs * MSEC_PER_SEC); | |
329 | ||
2ca813ad | 330 | spin_lock_bh(&dev->bss_lock); |
915de2ff | 331 | list_for_each_entry(bss, &dev->bss_list, list) |
cb3a8eec | 332 | bss->ts -= age_jiffies; |
2ca813ad | 333 | spin_unlock_bh(&dev->bss_lock); |
cb3a8eec DW |
334 | } |
335 | ||
2a519311 JB |
336 | void cfg80211_bss_expire(struct cfg80211_registered_device *dev) |
337 | { | |
15d6030b | 338 | __cfg80211_bss_expire(dev, jiffies - IEEE80211_SCAN_RESULT_EXPIRE); |
2a519311 JB |
339 | } |
340 | ||
c21dbf92 | 341 | const u8 *cfg80211_find_ie(u8 eid, const u8 *ies, int len) |
2a519311 | 342 | { |
c21dbf92 | 343 | while (len > 2 && ies[0] != eid) { |
2a519311 JB |
344 | len -= ies[1] + 2; |
345 | ies += ies[1] + 2; | |
346 | } | |
347 | if (len < 2) | |
348 | return NULL; | |
349 | if (len < 2 + ies[1]) | |
350 | return NULL; | |
351 | return ies; | |
352 | } | |
c21dbf92 | 353 | EXPORT_SYMBOL(cfg80211_find_ie); |
2a519311 | 354 | |
0c28ec58 EP |
355 | const u8 *cfg80211_find_vendor_ie(unsigned int oui, u8 oui_type, |
356 | const u8 *ies, int len) | |
357 | { | |
358 | struct ieee80211_vendor_ie *ie; | |
359 | const u8 *pos = ies, *end = ies + len; | |
360 | int ie_oui; | |
361 | ||
362 | while (pos < end) { | |
363 | pos = cfg80211_find_ie(WLAN_EID_VENDOR_SPECIFIC, pos, | |
364 | end - pos); | |
365 | if (!pos) | |
366 | return NULL; | |
367 | ||
0c28ec58 | 368 | ie = (struct ieee80211_vendor_ie *)pos; |
6719429d LC |
369 | |
370 | /* make sure we can access ie->len */ | |
371 | BUILD_BUG_ON(offsetof(struct ieee80211_vendor_ie, len) != 1); | |
372 | ||
373 | if (ie->len < sizeof(*ie)) | |
374 | goto cont; | |
375 | ||
0c28ec58 EP |
376 | ie_oui = ie->oui[0] << 16 | ie->oui[1] << 8 | ie->oui[2]; |
377 | if (ie_oui == oui && ie->oui_type == oui_type) | |
378 | return pos; | |
6719429d | 379 | cont: |
0c28ec58 EP |
380 | pos += 2 + ie->len; |
381 | } | |
382 | return NULL; | |
383 | } | |
384 | EXPORT_SYMBOL(cfg80211_find_vendor_ie); | |
385 | ||
915de2ff | 386 | static bool is_bss(struct cfg80211_bss *a, const u8 *bssid, |
2a519311 JB |
387 | const u8 *ssid, size_t ssid_len) |
388 | { | |
9caf0364 | 389 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
390 | const u8 *ssidie; |
391 | ||
ac422d3c | 392 | if (bssid && !ether_addr_equal(a->bssid, bssid)) |
2a519311 JB |
393 | return false; |
394 | ||
79420f09 JB |
395 | if (!ssid) |
396 | return true; | |
397 | ||
9caf0364 JB |
398 | ies = rcu_access_pointer(a->ies); |
399 | if (!ies) | |
400 | return false; | |
401 | ssidie = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len); | |
2a519311 JB |
402 | if (!ssidie) |
403 | return false; | |
404 | if (ssidie[1] != ssid_len) | |
405 | return false; | |
406 | return memcmp(ssidie + 2, ssid, ssid_len) == 0; | |
407 | } | |
408 | ||
4593c4cb JB |
409 | /** |
410 | * enum bss_compare_mode - BSS compare mode | |
411 | * @BSS_CMP_REGULAR: regular compare mode (for insertion and normal find) | |
412 | * @BSS_CMP_HIDE_ZLEN: find hidden SSID with zero-length mode | |
413 | * @BSS_CMP_HIDE_NUL: find hidden SSID with NUL-ed out mode | |
414 | */ | |
415 | enum bss_compare_mode { | |
416 | BSS_CMP_REGULAR, | |
417 | BSS_CMP_HIDE_ZLEN, | |
418 | BSS_CMP_HIDE_NUL, | |
419 | }; | |
420 | ||
dd9dfb9f | 421 | static int cmp_bss(struct cfg80211_bss *a, |
5622f5bb | 422 | struct cfg80211_bss *b, |
4593c4cb | 423 | enum bss_compare_mode mode) |
dd9dfb9f | 424 | { |
9caf0364 | 425 | const struct cfg80211_bss_ies *a_ies, *b_ies; |
3af6341c JB |
426 | const u8 *ie1 = NULL; |
427 | const u8 *ie2 = NULL; | |
5622f5bb | 428 | int i, r; |
dd9dfb9f | 429 | |
3af6341c JB |
430 | if (a->channel != b->channel) |
431 | return b->channel->center_freq - a->channel->center_freq; | |
dd9dfb9f | 432 | |
9caf0364 JB |
433 | a_ies = rcu_access_pointer(a->ies); |
434 | if (!a_ies) | |
435 | return -1; | |
436 | b_ies = rcu_access_pointer(b->ies); | |
437 | if (!b_ies) | |
438 | return 1; | |
439 | ||
3af6341c JB |
440 | if (WLAN_CAPABILITY_IS_STA_BSS(a->capability)) |
441 | ie1 = cfg80211_find_ie(WLAN_EID_MESH_ID, | |
442 | a_ies->data, a_ies->len); | |
443 | if (WLAN_CAPABILITY_IS_STA_BSS(b->capability)) | |
444 | ie2 = cfg80211_find_ie(WLAN_EID_MESH_ID, | |
445 | b_ies->data, b_ies->len); | |
446 | if (ie1 && ie2) { | |
447 | int mesh_id_cmp; | |
448 | ||
449 | if (ie1[1] == ie2[1]) | |
450 | mesh_id_cmp = memcmp(ie1 + 2, ie2 + 2, ie1[1]); | |
451 | else | |
452 | mesh_id_cmp = ie2[1] - ie1[1]; | |
453 | ||
454 | ie1 = cfg80211_find_ie(WLAN_EID_MESH_CONFIG, | |
455 | a_ies->data, a_ies->len); | |
456 | ie2 = cfg80211_find_ie(WLAN_EID_MESH_CONFIG, | |
457 | b_ies->data, b_ies->len); | |
458 | if (ie1 && ie2) { | |
459 | if (mesh_id_cmp) | |
460 | return mesh_id_cmp; | |
461 | if (ie1[1] != ie2[1]) | |
462 | return ie2[1] - ie1[1]; | |
463 | return memcmp(ie1 + 2, ie2 + 2, ie1[1]); | |
464 | } | |
465 | } | |
466 | ||
467 | /* | |
468 | * we can't use compare_ether_addr here since we need a < > operator. | |
469 | * The binary return value of compare_ether_addr isn't enough | |
470 | */ | |
471 | r = memcmp(a->bssid, b->bssid, sizeof(a->bssid)); | |
472 | if (r) | |
473 | return r; | |
474 | ||
9caf0364 JB |
475 | ie1 = cfg80211_find_ie(WLAN_EID_SSID, a_ies->data, a_ies->len); |
476 | ie2 = cfg80211_find_ie(WLAN_EID_SSID, b_ies->data, b_ies->len); | |
dd9dfb9f | 477 | |
5622f5bb JB |
478 | if (!ie1 && !ie2) |
479 | return 0; | |
480 | ||
f94f8b16 | 481 | /* |
5622f5bb JB |
482 | * Note that with "hide_ssid", the function returns a match if |
483 | * the already-present BSS ("b") is a hidden SSID beacon for | |
484 | * the new BSS ("a"). | |
f94f8b16 | 485 | */ |
dd9dfb9f DT |
486 | |
487 | /* sort missing IE before (left of) present IE */ | |
488 | if (!ie1) | |
489 | return -1; | |
490 | if (!ie2) | |
491 | return 1; | |
492 | ||
4593c4cb JB |
493 | switch (mode) { |
494 | case BSS_CMP_HIDE_ZLEN: | |
495 | /* | |
496 | * In ZLEN mode we assume the BSS entry we're | |
497 | * looking for has a zero-length SSID. So if | |
498 | * the one we're looking at right now has that, | |
499 | * return 0. Otherwise, return the difference | |
500 | * in length, but since we're looking for the | |
501 | * 0-length it's really equivalent to returning | |
502 | * the length of the one we're looking at. | |
503 | * | |
504 | * No content comparison is needed as we assume | |
505 | * the content length is zero. | |
506 | */ | |
507 | return ie2[1]; | |
508 | case BSS_CMP_REGULAR: | |
509 | default: | |
510 | /* sort by length first, then by contents */ | |
511 | if (ie1[1] != ie2[1]) | |
512 | return ie2[1] - ie1[1]; | |
5622f5bb | 513 | return memcmp(ie1 + 2, ie2 + 2, ie1[1]); |
4593c4cb JB |
514 | case BSS_CMP_HIDE_NUL: |
515 | if (ie1[1] != ie2[1]) | |
516 | return ie2[1] - ie1[1]; | |
517 | /* this is equivalent to memcmp(zeroes, ie2 + 2, len) */ | |
518 | for (i = 0; i < ie2[1]; i++) | |
519 | if (ie2[i + 2]) | |
520 | return -1; | |
521 | return 0; | |
522 | } | |
dd9dfb9f DT |
523 | } |
524 | ||
2a519311 JB |
525 | struct cfg80211_bss *cfg80211_get_bss(struct wiphy *wiphy, |
526 | struct ieee80211_channel *channel, | |
527 | const u8 *bssid, | |
79420f09 JB |
528 | const u8 *ssid, size_t ssid_len, |
529 | u16 capa_mask, u16 capa_val) | |
2a519311 JB |
530 | { |
531 | struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy); | |
532 | struct cfg80211_internal_bss *bss, *res = NULL; | |
ccb6c136 | 533 | unsigned long now = jiffies; |
2a519311 | 534 | |
4ee3e063 BL |
535 | trace_cfg80211_get_bss(wiphy, channel, bssid, ssid, ssid_len, capa_mask, |
536 | capa_val); | |
537 | ||
2a519311 JB |
538 | spin_lock_bh(&dev->bss_lock); |
539 | ||
540 | list_for_each_entry(bss, &dev->bss_list, list) { | |
79420f09 JB |
541 | if ((bss->pub.capability & capa_mask) != capa_val) |
542 | continue; | |
2a519311 JB |
543 | if (channel && bss->pub.channel != channel) |
544 | continue; | |
ccb6c136 JB |
545 | /* Don't get expired BSS structs */ |
546 | if (time_after(now, bss->ts + IEEE80211_SCAN_RESULT_EXPIRE) && | |
547 | !atomic_read(&bss->hold)) | |
548 | continue; | |
2a519311 JB |
549 | if (is_bss(&bss->pub, bssid, ssid, ssid_len)) { |
550 | res = bss; | |
776b3580 | 551 | bss_ref_get(dev, res); |
2a519311 JB |
552 | break; |
553 | } | |
554 | } | |
555 | ||
556 | spin_unlock_bh(&dev->bss_lock); | |
557 | if (!res) | |
558 | return NULL; | |
4ee3e063 | 559 | trace_cfg80211_return_bss(&res->pub); |
2a519311 JB |
560 | return &res->pub; |
561 | } | |
562 | EXPORT_SYMBOL(cfg80211_get_bss); | |
563 | ||
2a519311 JB |
564 | static void rb_insert_bss(struct cfg80211_registered_device *dev, |
565 | struct cfg80211_internal_bss *bss) | |
566 | { | |
567 | struct rb_node **p = &dev->bss_tree.rb_node; | |
568 | struct rb_node *parent = NULL; | |
569 | struct cfg80211_internal_bss *tbss; | |
570 | int cmp; | |
571 | ||
572 | while (*p) { | |
573 | parent = *p; | |
574 | tbss = rb_entry(parent, struct cfg80211_internal_bss, rbn); | |
575 | ||
4593c4cb | 576 | cmp = cmp_bss(&bss->pub, &tbss->pub, BSS_CMP_REGULAR); |
2a519311 JB |
577 | |
578 | if (WARN_ON(!cmp)) { | |
579 | /* will sort of leak this BSS */ | |
580 | return; | |
581 | } | |
582 | ||
583 | if (cmp < 0) | |
584 | p = &(*p)->rb_left; | |
585 | else | |
586 | p = &(*p)->rb_right; | |
587 | } | |
588 | ||
589 | rb_link_node(&bss->rbn, parent, p); | |
590 | rb_insert_color(&bss->rbn, &dev->bss_tree); | |
591 | } | |
592 | ||
593 | static struct cfg80211_internal_bss * | |
594 | rb_find_bss(struct cfg80211_registered_device *dev, | |
5622f5bb | 595 | struct cfg80211_internal_bss *res, |
4593c4cb | 596 | enum bss_compare_mode mode) |
dd9dfb9f DT |
597 | { |
598 | struct rb_node *n = dev->bss_tree.rb_node; | |
599 | struct cfg80211_internal_bss *bss; | |
600 | int r; | |
601 | ||
602 | while (n) { | |
603 | bss = rb_entry(n, struct cfg80211_internal_bss, rbn); | |
4593c4cb | 604 | r = cmp_bss(&res->pub, &bss->pub, mode); |
dd9dfb9f DT |
605 | |
606 | if (r == 0) | |
607 | return bss; | |
608 | else if (r < 0) | |
609 | n = n->rb_left; | |
610 | else | |
611 | n = n->rb_right; | |
612 | } | |
613 | ||
614 | return NULL; | |
615 | } | |
616 | ||
776b3580 JB |
617 | static bool cfg80211_combine_bsses(struct cfg80211_registered_device *dev, |
618 | struct cfg80211_internal_bss *new) | |
dd9dfb9f | 619 | { |
9caf0364 | 620 | const struct cfg80211_bss_ies *ies; |
776b3580 JB |
621 | struct cfg80211_internal_bss *bss; |
622 | const u8 *ie; | |
623 | int i, ssidlen; | |
624 | u8 fold = 0; | |
9caf0364 | 625 | |
776b3580 | 626 | ies = rcu_access_pointer(new->pub.beacon_ies); |
9caf0364 | 627 | if (WARN_ON(!ies)) |
776b3580 | 628 | return false; |
dd9dfb9f | 629 | |
776b3580 JB |
630 | ie = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len); |
631 | if (!ie) { | |
632 | /* nothing to do */ | |
633 | return true; | |
634 | } | |
635 | ||
636 | ssidlen = ie[1]; | |
637 | for (i = 0; i < ssidlen; i++) | |
638 | fold |= ie[2 + i]; | |
639 | ||
640 | if (fold) { | |
641 | /* not a hidden SSID */ | |
642 | return true; | |
643 | } | |
644 | ||
645 | /* This is the bad part ... */ | |
646 | ||
647 | list_for_each_entry(bss, &dev->bss_list, list) { | |
648 | if (!ether_addr_equal(bss->pub.bssid, new->pub.bssid)) | |
649 | continue; | |
650 | if (bss->pub.channel != new->pub.channel) | |
651 | continue; | |
652 | if (rcu_access_pointer(bss->pub.beacon_ies)) | |
653 | continue; | |
654 | ies = rcu_access_pointer(bss->pub.ies); | |
655 | if (!ies) | |
656 | continue; | |
657 | ie = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len); | |
658 | if (!ie) | |
659 | continue; | |
660 | if (ssidlen && ie[1] != ssidlen) | |
661 | continue; | |
662 | /* that would be odd ... */ | |
663 | if (bss->pub.beacon_ies) | |
664 | continue; | |
665 | if (WARN_ON_ONCE(bss->pub.hidden_beacon_bss)) | |
666 | continue; | |
667 | if (WARN_ON_ONCE(!list_empty(&bss->hidden_list))) | |
668 | list_del(&bss->hidden_list); | |
669 | /* combine them */ | |
670 | list_add(&bss->hidden_list, &new->hidden_list); | |
671 | bss->pub.hidden_beacon_bss = &new->pub; | |
672 | new->refcount += bss->refcount; | |
673 | rcu_assign_pointer(bss->pub.beacon_ies, | |
674 | new->pub.beacon_ies); | |
675 | } | |
676 | ||
677 | return true; | |
dd9dfb9f DT |
678 | } |
679 | ||
2a519311 JB |
680 | static struct cfg80211_internal_bss * |
681 | cfg80211_bss_update(struct cfg80211_registered_device *dev, | |
9caf0364 | 682 | struct cfg80211_internal_bss *tmp) |
2a519311 JB |
683 | { |
684 | struct cfg80211_internal_bss *found = NULL; | |
2a519311 | 685 | |
9caf0364 | 686 | if (WARN_ON(!tmp->pub.channel)) |
2a519311 | 687 | return NULL; |
2a519311 | 688 | |
9caf0364 | 689 | tmp->ts = jiffies; |
2a519311 | 690 | |
2a519311 JB |
691 | spin_lock_bh(&dev->bss_lock); |
692 | ||
9caf0364 JB |
693 | if (WARN_ON(!rcu_access_pointer(tmp->pub.ies))) { |
694 | spin_unlock_bh(&dev->bss_lock); | |
695 | return NULL; | |
696 | } | |
697 | ||
4593c4cb | 698 | found = rb_find_bss(dev, tmp, BSS_CMP_REGULAR); |
2a519311 | 699 | |
cd1658f5 | 700 | if (found) { |
9caf0364 | 701 | found->pub.beacon_interval = tmp->pub.beacon_interval; |
9caf0364 JB |
702 | found->pub.signal = tmp->pub.signal; |
703 | found->pub.capability = tmp->pub.capability; | |
704 | found->ts = tmp->ts; | |
cd1658f5 | 705 | |
34a6eddb | 706 | /* Update IEs */ |
9caf0364 JB |
707 | if (rcu_access_pointer(tmp->pub.proberesp_ies)) { |
708 | const struct cfg80211_bss_ies *old; | |
709 | ||
710 | old = rcu_access_pointer(found->pub.proberesp_ies); | |
cd1658f5 | 711 | |
9caf0364 JB |
712 | rcu_assign_pointer(found->pub.proberesp_ies, |
713 | tmp->pub.proberesp_ies); | |
34a6eddb | 714 | /* Override possible earlier Beacon frame IEs */ |
9caf0364 JB |
715 | rcu_assign_pointer(found->pub.ies, |
716 | tmp->pub.proberesp_ies); | |
717 | if (old) | |
718 | kfree_rcu((struct cfg80211_bss_ies *)old, | |
719 | rcu_head); | |
720 | } else if (rcu_access_pointer(tmp->pub.beacon_ies)) { | |
9537f227 | 721 | const struct cfg80211_bss_ies *old; |
776b3580 JB |
722 | struct cfg80211_internal_bss *bss; |
723 | ||
724 | if (found->pub.hidden_beacon_bss && | |
725 | !list_empty(&found->hidden_list)) { | |
726 | /* | |
727 | * The found BSS struct is one of the probe | |
728 | * response members of a group, but we're | |
729 | * receiving a beacon (beacon_ies in the tmp | |
730 | * bss is used). This can only mean that the | |
731 | * AP changed its beacon from not having an | |
732 | * SSID to showing it, which is confusing so | |
733 | * drop this information. | |
734 | */ | |
735 | goto drop; | |
736 | } | |
915de2ff | 737 | |
9caf0364 | 738 | old = rcu_access_pointer(found->pub.beacon_ies); |
9caf0364 JB |
739 | |
740 | rcu_assign_pointer(found->pub.beacon_ies, | |
741 | tmp->pub.beacon_ies); | |
01123e23 SN |
742 | |
743 | /* Override IEs if they were from a beacon before */ | |
9537f227 | 744 | if (old == rcu_access_pointer(found->pub.ies)) |
9caf0364 JB |
745 | rcu_assign_pointer(found->pub.ies, |
746 | tmp->pub.beacon_ies); | |
cd1658f5 | 747 | |
776b3580 JB |
748 | /* Assign beacon IEs to all sub entries */ |
749 | list_for_each_entry(bss, &found->hidden_list, | |
750 | hidden_list) { | |
751 | const struct cfg80211_bss_ies *ies; | |
752 | ||
753 | ies = rcu_access_pointer(bss->pub.beacon_ies); | |
754 | WARN_ON(ies != old); | |
755 | ||
756 | rcu_assign_pointer(bss->pub.beacon_ies, | |
757 | tmp->pub.beacon_ies); | |
758 | } | |
759 | ||
9caf0364 JB |
760 | if (old) |
761 | kfree_rcu((struct cfg80211_bss_ies *)old, | |
762 | rcu_head); | |
763 | } | |
2a519311 | 764 | } else { |
9caf0364 | 765 | struct cfg80211_internal_bss *new; |
dd9dfb9f | 766 | struct cfg80211_internal_bss *hidden; |
9caf0364 | 767 | struct cfg80211_bss_ies *ies; |
dd9dfb9f | 768 | |
9caf0364 JB |
769 | /* |
770 | * create a copy -- the "res" variable that is passed in | |
771 | * is allocated on the stack since it's not needed in the | |
772 | * more common case of an update | |
773 | */ | |
774 | new = kzalloc(sizeof(*new) + dev->wiphy.bss_priv_size, | |
775 | GFP_ATOMIC); | |
776 | if (!new) { | |
777 | ies = (void *)rcu_dereference(tmp->pub.beacon_ies); | |
778 | if (ies) | |
779 | kfree_rcu(ies, rcu_head); | |
780 | ies = (void *)rcu_dereference(tmp->pub.proberesp_ies); | |
781 | if (ies) | |
782 | kfree_rcu(ies, rcu_head); | |
776b3580 | 783 | goto drop; |
9caf0364 JB |
784 | } |
785 | memcpy(new, tmp, sizeof(*new)); | |
776b3580 JB |
786 | new->refcount = 1; |
787 | INIT_LIST_HEAD(&new->hidden_list); | |
788 | ||
789 | if (rcu_access_pointer(tmp->pub.proberesp_ies)) { | |
790 | hidden = rb_find_bss(dev, tmp, BSS_CMP_HIDE_ZLEN); | |
791 | if (!hidden) | |
792 | hidden = rb_find_bss(dev, tmp, | |
793 | BSS_CMP_HIDE_NUL); | |
794 | if (hidden) { | |
795 | new->pub.hidden_beacon_bss = &hidden->pub; | |
796 | list_add(&new->hidden_list, | |
797 | &hidden->hidden_list); | |
798 | hidden->refcount++; | |
799 | rcu_assign_pointer(new->pub.beacon_ies, | |
800 | hidden->pub.beacon_ies); | |
801 | } | |
802 | } else { | |
803 | /* | |
804 | * Ok so we found a beacon, and don't have an entry. If | |
805 | * it's a beacon with hidden SSID, we might be in for an | |
806 | * expensive search for any probe responses that should | |
807 | * be grouped with this beacon for updates ... | |
808 | */ | |
809 | if (!cfg80211_combine_bsses(dev, new)) { | |
810 | kfree(new); | |
811 | goto drop; | |
812 | } | |
813 | } | |
814 | ||
9caf0364 JB |
815 | list_add_tail(&new->list, &dev->bss_list); |
816 | rb_insert_bss(dev, new); | |
817 | found = new; | |
2a519311 JB |
818 | } |
819 | ||
820 | dev->bss_generation++; | |
776b3580 | 821 | bss_ref_get(dev, found); |
2a519311 JB |
822 | spin_unlock_bh(&dev->bss_lock); |
823 | ||
2a519311 | 824 | return found; |
776b3580 JB |
825 | drop: |
826 | spin_unlock_bh(&dev->bss_lock); | |
827 | return NULL; | |
2a519311 JB |
828 | } |
829 | ||
0172bb75 JB |
830 | static struct ieee80211_channel * |
831 | cfg80211_get_bss_channel(struct wiphy *wiphy, const u8 *ie, size_t ielen, | |
832 | struct ieee80211_channel *channel) | |
833 | { | |
834 | const u8 *tmp; | |
835 | u32 freq; | |
836 | int channel_number = -1; | |
837 | ||
838 | tmp = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ie, ielen); | |
839 | if (tmp && tmp[1] == 1) { | |
840 | channel_number = tmp[2]; | |
841 | } else { | |
842 | tmp = cfg80211_find_ie(WLAN_EID_HT_OPERATION, ie, ielen); | |
843 | if (tmp && tmp[1] >= sizeof(struct ieee80211_ht_operation)) { | |
844 | struct ieee80211_ht_operation *htop = (void *)(tmp + 2); | |
845 | ||
846 | channel_number = htop->primary_chan; | |
847 | } | |
848 | } | |
849 | ||
850 | if (channel_number < 0) | |
851 | return channel; | |
852 | ||
853 | freq = ieee80211_channel_to_frequency(channel_number, channel->band); | |
854 | channel = ieee80211_get_channel(wiphy, freq); | |
855 | if (!channel) | |
856 | return NULL; | |
857 | if (channel->flags & IEEE80211_CHAN_DISABLED) | |
858 | return NULL; | |
859 | return channel; | |
860 | } | |
861 | ||
06aa7afa JK |
862 | struct cfg80211_bss* |
863 | cfg80211_inform_bss(struct wiphy *wiphy, | |
864 | struct ieee80211_channel *channel, | |
7b8bcff2 JB |
865 | const u8 *bssid, u64 tsf, u16 capability, |
866 | u16 beacon_interval, const u8 *ie, size_t ielen, | |
06aa7afa JK |
867 | s32 signal, gfp_t gfp) |
868 | { | |
9caf0364 JB |
869 | struct cfg80211_bss_ies *ies; |
870 | struct cfg80211_internal_bss tmp = {}, *res; | |
06aa7afa JK |
871 | |
872 | if (WARN_ON(!wiphy)) | |
873 | return NULL; | |
874 | ||
22fe88d3 | 875 | if (WARN_ON(wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC && |
06aa7afa JK |
876 | (signal < 0 || signal > 100))) |
877 | return NULL; | |
878 | ||
0172bb75 JB |
879 | channel = cfg80211_get_bss_channel(wiphy, ie, ielen, channel); |
880 | if (!channel) | |
881 | return NULL; | |
882 | ||
9caf0364 JB |
883 | memcpy(tmp.pub.bssid, bssid, ETH_ALEN); |
884 | tmp.pub.channel = channel; | |
885 | tmp.pub.signal = signal; | |
9caf0364 JB |
886 | tmp.pub.beacon_interval = beacon_interval; |
887 | tmp.pub.capability = capability; | |
34a6eddb JM |
888 | /* |
889 | * Since we do not know here whether the IEs are from a Beacon or Probe | |
890 | * Response frame, we need to pick one of the options and only use it | |
891 | * with the driver that does not provide the full Beacon/Probe Response | |
892 | * frame. Use Beacon frame pointer to avoid indicating that this should | |
50521aa8 | 893 | * override the IEs pointer should we have received an earlier |
9caf0364 | 894 | * indication of Probe Response data. |
34a6eddb | 895 | */ |
9caf0364 JB |
896 | ies = kmalloc(sizeof(*ies) + ielen, gfp); |
897 | if (!ies) | |
898 | return NULL; | |
899 | ies->len = ielen; | |
8cef2c9d | 900 | ies->tsf = tsf; |
9caf0364 | 901 | memcpy(ies->data, ie, ielen); |
06aa7afa | 902 | |
9caf0364 JB |
903 | rcu_assign_pointer(tmp.pub.beacon_ies, ies); |
904 | rcu_assign_pointer(tmp.pub.ies, ies); | |
06aa7afa | 905 | |
9caf0364 | 906 | res = cfg80211_bss_update(wiphy_to_dev(wiphy), &tmp); |
06aa7afa JK |
907 | if (!res) |
908 | return NULL; | |
909 | ||
910 | if (res->pub.capability & WLAN_CAPABILITY_ESS) | |
911 | regulatory_hint_found_beacon(wiphy, channel, gfp); | |
912 | ||
4ee3e063 | 913 | trace_cfg80211_return_bss(&res->pub); |
06aa7afa JK |
914 | /* cfg80211_bss_update gives us a referenced result */ |
915 | return &res->pub; | |
916 | } | |
917 | EXPORT_SYMBOL(cfg80211_inform_bss); | |
918 | ||
2a519311 JB |
919 | struct cfg80211_bss * |
920 | cfg80211_inform_bss_frame(struct wiphy *wiphy, | |
921 | struct ieee80211_channel *channel, | |
922 | struct ieee80211_mgmt *mgmt, size_t len, | |
77965c97 | 923 | s32 signal, gfp_t gfp) |
2a519311 | 924 | { |
9caf0364 JB |
925 | struct cfg80211_internal_bss tmp = {}, *res; |
926 | struct cfg80211_bss_ies *ies; | |
2a519311 JB |
927 | size_t ielen = len - offsetof(struct ieee80211_mgmt, |
928 | u.probe_resp.variable); | |
bef9bacc | 929 | |
0172bb75 JB |
930 | BUILD_BUG_ON(offsetof(struct ieee80211_mgmt, u.probe_resp.variable) != |
931 | offsetof(struct ieee80211_mgmt, u.beacon.variable)); | |
932 | ||
4ee3e063 BL |
933 | trace_cfg80211_inform_bss_frame(wiphy, channel, mgmt, len, signal); |
934 | ||
bef9bacc MK |
935 | if (WARN_ON(!mgmt)) |
936 | return NULL; | |
937 | ||
938 | if (WARN_ON(!wiphy)) | |
939 | return NULL; | |
2a519311 | 940 | |
22fe88d3 | 941 | if (WARN_ON(wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC && |
768be59f | 942 | (signal < 0 || signal > 100))) |
2a519311 JB |
943 | return NULL; |
944 | ||
bef9bacc | 945 | if (WARN_ON(len < offsetof(struct ieee80211_mgmt, u.probe_resp.variable))) |
2a519311 JB |
946 | return NULL; |
947 | ||
0172bb75 JB |
948 | channel = cfg80211_get_bss_channel(wiphy, mgmt->u.beacon.variable, |
949 | ielen, channel); | |
950 | if (!channel) | |
951 | return NULL; | |
952 | ||
9caf0364 JB |
953 | ies = kmalloc(sizeof(*ies) + ielen, gfp); |
954 | if (!ies) | |
2a519311 | 955 | return NULL; |
9caf0364 | 956 | ies->len = ielen; |
8cef2c9d | 957 | ies->tsf = le64_to_cpu(mgmt->u.probe_resp.timestamp); |
9caf0364 | 958 | memcpy(ies->data, mgmt->u.probe_resp.variable, ielen); |
2a519311 | 959 | |
9caf0364 JB |
960 | if (ieee80211_is_probe_resp(mgmt->frame_control)) |
961 | rcu_assign_pointer(tmp.pub.proberesp_ies, ies); | |
962 | else | |
963 | rcu_assign_pointer(tmp.pub.beacon_ies, ies); | |
964 | rcu_assign_pointer(tmp.pub.ies, ies); | |
965 | ||
966 | memcpy(tmp.pub.bssid, mgmt->bssid, ETH_ALEN); | |
967 | tmp.pub.channel = channel; | |
968 | tmp.pub.signal = signal; | |
9caf0364 JB |
969 | tmp.pub.beacon_interval = le16_to_cpu(mgmt->u.probe_resp.beacon_int); |
970 | tmp.pub.capability = le16_to_cpu(mgmt->u.probe_resp.capab_info); | |
971 | ||
972 | res = cfg80211_bss_update(wiphy_to_dev(wiphy), &tmp); | |
2a519311 JB |
973 | if (!res) |
974 | return NULL; | |
975 | ||
e38f8a7a LR |
976 | if (res->pub.capability & WLAN_CAPABILITY_ESS) |
977 | regulatory_hint_found_beacon(wiphy, channel, gfp); | |
978 | ||
4ee3e063 | 979 | trace_cfg80211_return_bss(&res->pub); |
2a519311 JB |
980 | /* cfg80211_bss_update gives us a referenced result */ |
981 | return &res->pub; | |
982 | } | |
983 | EXPORT_SYMBOL(cfg80211_inform_bss_frame); | |
984 | ||
5b112d3d | 985 | void cfg80211_ref_bss(struct wiphy *wiphy, struct cfg80211_bss *pub) |
4c0c0b75 | 986 | { |
776b3580 | 987 | struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy); |
4c0c0b75 JB |
988 | struct cfg80211_internal_bss *bss; |
989 | ||
990 | if (!pub) | |
991 | return; | |
992 | ||
993 | bss = container_of(pub, struct cfg80211_internal_bss, pub); | |
776b3580 JB |
994 | |
995 | spin_lock_bh(&dev->bss_lock); | |
996 | bss_ref_get(dev, bss); | |
997 | spin_unlock_bh(&dev->bss_lock); | |
4c0c0b75 JB |
998 | } |
999 | EXPORT_SYMBOL(cfg80211_ref_bss); | |
1000 | ||
5b112d3d | 1001 | void cfg80211_put_bss(struct wiphy *wiphy, struct cfg80211_bss *pub) |
2a519311 | 1002 | { |
776b3580 | 1003 | struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy); |
2a519311 JB |
1004 | struct cfg80211_internal_bss *bss; |
1005 | ||
1006 | if (!pub) | |
1007 | return; | |
1008 | ||
1009 | bss = container_of(pub, struct cfg80211_internal_bss, pub); | |
776b3580 JB |
1010 | |
1011 | spin_lock_bh(&dev->bss_lock); | |
1012 | bss_ref_put(dev, bss); | |
1013 | spin_unlock_bh(&dev->bss_lock); | |
2a519311 JB |
1014 | } |
1015 | EXPORT_SYMBOL(cfg80211_put_bss); | |
1016 | ||
d491af19 JB |
1017 | void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *pub) |
1018 | { | |
1019 | struct cfg80211_registered_device *dev = wiphy_to_dev(wiphy); | |
1020 | struct cfg80211_internal_bss *bss; | |
1021 | ||
1022 | if (WARN_ON(!pub)) | |
1023 | return; | |
1024 | ||
1025 | bss = container_of(pub, struct cfg80211_internal_bss, pub); | |
1026 | ||
1027 | spin_lock_bh(&dev->bss_lock); | |
3207390a | 1028 | if (!list_empty(&bss->list)) { |
776b3580 JB |
1029 | if (__cfg80211_unlink_bss(dev, bss)) |
1030 | dev->bss_generation++; | |
3207390a | 1031 | } |
d491af19 | 1032 | spin_unlock_bh(&dev->bss_lock); |
d491af19 JB |
1033 | } |
1034 | EXPORT_SYMBOL(cfg80211_unlink_bss); | |
1035 | ||
3d23e349 | 1036 | #ifdef CONFIG_CFG80211_WEXT |
2a519311 JB |
1037 | int cfg80211_wext_siwscan(struct net_device *dev, |
1038 | struct iw_request_info *info, | |
1039 | union iwreq_data *wrqu, char *extra) | |
1040 | { | |
1041 | struct cfg80211_registered_device *rdev; | |
1042 | struct wiphy *wiphy; | |
1043 | struct iw_scan_req *wreq = NULL; | |
65486c8b | 1044 | struct cfg80211_scan_request *creq = NULL; |
2a519311 JB |
1045 | int i, err, n_channels = 0; |
1046 | enum ieee80211_band band; | |
1047 | ||
1048 | if (!netif_running(dev)) | |
1049 | return -ENETDOWN; | |
1050 | ||
b2e3abdc HS |
1051 | if (wrqu->data.length == sizeof(struct iw_scan_req)) |
1052 | wreq = (struct iw_scan_req *)extra; | |
1053 | ||
463d0183 | 1054 | rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex); |
2a519311 JB |
1055 | |
1056 | if (IS_ERR(rdev)) | |
1057 | return PTR_ERR(rdev); | |
1058 | ||
1059 | if (rdev->scan_req) { | |
1060 | err = -EBUSY; | |
1061 | goto out; | |
1062 | } | |
1063 | ||
1064 | wiphy = &rdev->wiphy; | |
1065 | ||
b2e3abdc HS |
1066 | /* Determine number of channels, needed to allocate creq */ |
1067 | if (wreq && wreq->num_channels) | |
1068 | n_channels = wreq->num_channels; | |
1069 | else { | |
1070 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) | |
1071 | if (wiphy->bands[band]) | |
1072 | n_channels += wiphy->bands[band]->n_channels; | |
1073 | } | |
2a519311 JB |
1074 | |
1075 | creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) + | |
1076 | n_channels * sizeof(void *), | |
1077 | GFP_ATOMIC); | |
1078 | if (!creq) { | |
1079 | err = -ENOMEM; | |
1080 | goto out; | |
1081 | } | |
1082 | ||
1083 | creq->wiphy = wiphy; | |
fd014284 | 1084 | creq->wdev = dev->ieee80211_ptr; |
5ba63533 JB |
1085 | /* SSIDs come after channels */ |
1086 | creq->ssids = (void *)&creq->channels[n_channels]; | |
2a519311 JB |
1087 | creq->n_channels = n_channels; |
1088 | creq->n_ssids = 1; | |
15d6030b | 1089 | creq->scan_start = jiffies; |
2a519311 | 1090 | |
b2e3abdc | 1091 | /* translate "Scan on frequencies" request */ |
2a519311 JB |
1092 | i = 0; |
1093 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
1094 | int j; | |
584991dc | 1095 | |
2a519311 JB |
1096 | if (!wiphy->bands[band]) |
1097 | continue; | |
584991dc | 1098 | |
2a519311 | 1099 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
584991dc JB |
1100 | /* ignore disabled channels */ |
1101 | if (wiphy->bands[band]->channels[j].flags & | |
1102 | IEEE80211_CHAN_DISABLED) | |
1103 | continue; | |
b2e3abdc HS |
1104 | |
1105 | /* If we have a wireless request structure and the | |
1106 | * wireless request specifies frequencies, then search | |
1107 | * for the matching hardware channel. | |
1108 | */ | |
1109 | if (wreq && wreq->num_channels) { | |
1110 | int k; | |
1111 | int wiphy_freq = wiphy->bands[band]->channels[j].center_freq; | |
1112 | for (k = 0; k < wreq->num_channels; k++) { | |
a4e7b730 | 1113 | int wext_freq = cfg80211_wext_freq(wiphy, &wreq->channel_list[k]); |
b2e3abdc HS |
1114 | if (wext_freq == wiphy_freq) |
1115 | goto wext_freq_found; | |
1116 | } | |
1117 | goto wext_freq_not_found; | |
1118 | } | |
1119 | ||
1120 | wext_freq_found: | |
2a519311 JB |
1121 | creq->channels[i] = &wiphy->bands[band]->channels[j]; |
1122 | i++; | |
b2e3abdc | 1123 | wext_freq_not_found: ; |
2a519311 JB |
1124 | } |
1125 | } | |
8862dc5f HS |
1126 | /* No channels found? */ |
1127 | if (!i) { | |
1128 | err = -EINVAL; | |
1129 | goto out; | |
1130 | } | |
2a519311 | 1131 | |
b2e3abdc HS |
1132 | /* Set real number of channels specified in creq->channels[] */ |
1133 | creq->n_channels = i; | |
2a519311 | 1134 | |
b2e3abdc HS |
1135 | /* translate "Scan for SSID" request */ |
1136 | if (wreq) { | |
2a519311 | 1137 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { |
65486c8b JB |
1138 | if (wreq->essid_len > IEEE80211_MAX_SSID_LEN) { |
1139 | err = -EINVAL; | |
1140 | goto out; | |
1141 | } | |
2a519311 JB |
1142 | memcpy(creq->ssids[0].ssid, wreq->essid, wreq->essid_len); |
1143 | creq->ssids[0].ssid_len = wreq->essid_len; | |
1144 | } | |
1145 | if (wreq->scan_type == IW_SCAN_TYPE_PASSIVE) | |
1146 | creq->n_ssids = 0; | |
1147 | } | |
1148 | ||
34850ab2 | 1149 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
1150 | if (wiphy->bands[i]) |
1151 | creq->rates[i] = (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 | 1152 | |
2a519311 | 1153 | rdev->scan_req = creq; |
e35e4d28 | 1154 | err = rdev_scan(rdev, creq); |
2a519311 JB |
1155 | if (err) { |
1156 | rdev->scan_req = NULL; | |
65486c8b | 1157 | /* creq will be freed below */ |
463d0183 | 1158 | } else { |
fd014284 | 1159 | nl80211_send_scan_start(rdev, dev->ieee80211_ptr); |
65486c8b JB |
1160 | /* creq now owned by driver */ |
1161 | creq = NULL; | |
463d0183 JB |
1162 | dev_hold(dev); |
1163 | } | |
2a519311 | 1164 | out: |
65486c8b | 1165 | kfree(creq); |
4d0c8aea | 1166 | cfg80211_unlock_rdev(rdev); |
2a519311 JB |
1167 | return err; |
1168 | } | |
ba44cb72 | 1169 | EXPORT_SYMBOL_GPL(cfg80211_wext_siwscan); |
2a519311 JB |
1170 | |
1171 | static void ieee80211_scan_add_ies(struct iw_request_info *info, | |
9caf0364 | 1172 | const struct cfg80211_bss_ies *ies, |
2a519311 JB |
1173 | char **current_ev, char *end_buf) |
1174 | { | |
9caf0364 | 1175 | const u8 *pos, *end, *next; |
2a519311 JB |
1176 | struct iw_event iwe; |
1177 | ||
9caf0364 | 1178 | if (!ies) |
2a519311 JB |
1179 | return; |
1180 | ||
1181 | /* | |
1182 | * If needed, fragment the IEs buffer (at IE boundaries) into short | |
1183 | * enough fragments to fit into IW_GENERIC_IE_MAX octet messages. | |
1184 | */ | |
9caf0364 JB |
1185 | pos = ies->data; |
1186 | end = pos + ies->len; | |
2a519311 JB |
1187 | |
1188 | while (end - pos > IW_GENERIC_IE_MAX) { | |
1189 | next = pos + 2 + pos[1]; | |
1190 | while (next + 2 + next[1] - pos < IW_GENERIC_IE_MAX) | |
1191 | next = next + 2 + next[1]; | |
1192 | ||
1193 | memset(&iwe, 0, sizeof(iwe)); | |
1194 | iwe.cmd = IWEVGENIE; | |
1195 | iwe.u.data.length = next - pos; | |
1196 | *current_ev = iwe_stream_add_point(info, *current_ev, | |
9caf0364 JB |
1197 | end_buf, &iwe, |
1198 | (void *)pos); | |
2a519311 JB |
1199 | |
1200 | pos = next; | |
1201 | } | |
1202 | ||
1203 | if (end > pos) { | |
1204 | memset(&iwe, 0, sizeof(iwe)); | |
1205 | iwe.cmd = IWEVGENIE; | |
1206 | iwe.u.data.length = end - pos; | |
1207 | *current_ev = iwe_stream_add_point(info, *current_ev, | |
9caf0364 JB |
1208 | end_buf, &iwe, |
1209 | (void *)pos); | |
2a519311 JB |
1210 | } |
1211 | } | |
1212 | ||
2a519311 | 1213 | static char * |
77965c97 JB |
1214 | ieee80211_bss(struct wiphy *wiphy, struct iw_request_info *info, |
1215 | struct cfg80211_internal_bss *bss, char *current_ev, | |
1216 | char *end_buf) | |
2a519311 | 1217 | { |
9caf0364 | 1218 | const struct cfg80211_bss_ies *ies; |
2a519311 | 1219 | struct iw_event iwe; |
9caf0364 | 1220 | const u8 *ie; |
2a519311 | 1221 | u8 *buf, *cfg, *p; |
9caf0364 | 1222 | int rem, i, sig; |
2a519311 JB |
1223 | bool ismesh = false; |
1224 | ||
1225 | memset(&iwe, 0, sizeof(iwe)); | |
1226 | iwe.cmd = SIOCGIWAP; | |
1227 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; | |
1228 | memcpy(iwe.u.ap_addr.sa_data, bss->pub.bssid, ETH_ALEN); | |
1229 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, | |
1230 | IW_EV_ADDR_LEN); | |
1231 | ||
1232 | memset(&iwe, 0, sizeof(iwe)); | |
1233 | iwe.cmd = SIOCGIWFREQ; | |
1234 | iwe.u.freq.m = ieee80211_frequency_to_channel(bss->pub.channel->center_freq); | |
1235 | iwe.u.freq.e = 0; | |
1236 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, | |
1237 | IW_EV_FREQ_LEN); | |
1238 | ||
1239 | memset(&iwe, 0, sizeof(iwe)); | |
1240 | iwe.cmd = SIOCGIWFREQ; | |
1241 | iwe.u.freq.m = bss->pub.channel->center_freq; | |
1242 | iwe.u.freq.e = 6; | |
1243 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, | |
1244 | IW_EV_FREQ_LEN); | |
1245 | ||
77965c97 | 1246 | if (wiphy->signal_type != CFG80211_SIGNAL_TYPE_NONE) { |
2a519311 JB |
1247 | memset(&iwe, 0, sizeof(iwe)); |
1248 | iwe.cmd = IWEVQUAL; | |
1249 | iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED | | |
1250 | IW_QUAL_NOISE_INVALID | | |
a77b8552 | 1251 | IW_QUAL_QUAL_UPDATED; |
77965c97 | 1252 | switch (wiphy->signal_type) { |
2a519311 | 1253 | case CFG80211_SIGNAL_TYPE_MBM: |
a77b8552 JB |
1254 | sig = bss->pub.signal / 100; |
1255 | iwe.u.qual.level = sig; | |
2a519311 | 1256 | iwe.u.qual.updated |= IW_QUAL_DBM; |
a77b8552 JB |
1257 | if (sig < -110) /* rather bad */ |
1258 | sig = -110; | |
1259 | else if (sig > -40) /* perfect */ | |
1260 | sig = -40; | |
1261 | /* will give a range of 0 .. 70 */ | |
1262 | iwe.u.qual.qual = sig + 110; | |
2a519311 JB |
1263 | break; |
1264 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
1265 | iwe.u.qual.level = bss->pub.signal; | |
a77b8552 JB |
1266 | /* will give range 0 .. 100 */ |
1267 | iwe.u.qual.qual = bss->pub.signal; | |
2a519311 JB |
1268 | break; |
1269 | default: | |
1270 | /* not reached */ | |
1271 | break; | |
1272 | } | |
1273 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, | |
1274 | &iwe, IW_EV_QUAL_LEN); | |
1275 | } | |
1276 | ||
1277 | memset(&iwe, 0, sizeof(iwe)); | |
1278 | iwe.cmd = SIOCGIWENCODE; | |
1279 | if (bss->pub.capability & WLAN_CAPABILITY_PRIVACY) | |
1280 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; | |
1281 | else | |
1282 | iwe.u.data.flags = IW_ENCODE_DISABLED; | |
1283 | iwe.u.data.length = 0; | |
1284 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | |
1285 | &iwe, ""); | |
1286 | ||
9caf0364 JB |
1287 | rcu_read_lock(); |
1288 | ies = rcu_dereference(bss->pub.ies); | |
83c7aa1a JB |
1289 | rem = ies->len; |
1290 | ie = ies->data; | |
9caf0364 | 1291 | |
83c7aa1a | 1292 | while (rem >= 2) { |
2a519311 JB |
1293 | /* invalid data */ |
1294 | if (ie[1] > rem - 2) | |
1295 | break; | |
1296 | ||
1297 | switch (ie[0]) { | |
1298 | case WLAN_EID_SSID: | |
1299 | memset(&iwe, 0, sizeof(iwe)); | |
1300 | iwe.cmd = SIOCGIWESSID; | |
1301 | iwe.u.data.length = ie[1]; | |
1302 | iwe.u.data.flags = 1; | |
1303 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | |
9caf0364 | 1304 | &iwe, (u8 *)ie + 2); |
2a519311 JB |
1305 | break; |
1306 | case WLAN_EID_MESH_ID: | |
1307 | memset(&iwe, 0, sizeof(iwe)); | |
1308 | iwe.cmd = SIOCGIWESSID; | |
1309 | iwe.u.data.length = ie[1]; | |
1310 | iwe.u.data.flags = 1; | |
1311 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | |
9caf0364 | 1312 | &iwe, (u8 *)ie + 2); |
2a519311 JB |
1313 | break; |
1314 | case WLAN_EID_MESH_CONFIG: | |
1315 | ismesh = true; | |
136cfa28 | 1316 | if (ie[1] != sizeof(struct ieee80211_meshconf_ie)) |
2a519311 JB |
1317 | break; |
1318 | buf = kmalloc(50, GFP_ATOMIC); | |
1319 | if (!buf) | |
1320 | break; | |
9caf0364 | 1321 | cfg = (u8 *)ie + 2; |
2a519311 JB |
1322 | memset(&iwe, 0, sizeof(iwe)); |
1323 | iwe.cmd = IWEVCUSTOM; | |
76aa5e70 RP |
1324 | sprintf(buf, "Mesh Network Path Selection Protocol ID: " |
1325 | "0x%02X", cfg[0]); | |
2a519311 JB |
1326 | iwe.u.data.length = strlen(buf); |
1327 | current_ev = iwe_stream_add_point(info, current_ev, | |
1328 | end_buf, | |
1329 | &iwe, buf); | |
76aa5e70 RP |
1330 | sprintf(buf, "Path Selection Metric ID: 0x%02X", |
1331 | cfg[1]); | |
2a519311 JB |
1332 | iwe.u.data.length = strlen(buf); |
1333 | current_ev = iwe_stream_add_point(info, current_ev, | |
1334 | end_buf, | |
1335 | &iwe, buf); | |
76aa5e70 RP |
1336 | sprintf(buf, "Congestion Control Mode ID: 0x%02X", |
1337 | cfg[2]); | |
2a519311 JB |
1338 | iwe.u.data.length = strlen(buf); |
1339 | current_ev = iwe_stream_add_point(info, current_ev, | |
1340 | end_buf, | |
1341 | &iwe, buf); | |
76aa5e70 | 1342 | sprintf(buf, "Synchronization ID: 0x%02X", cfg[3]); |
2a519311 JB |
1343 | iwe.u.data.length = strlen(buf); |
1344 | current_ev = iwe_stream_add_point(info, current_ev, | |
1345 | end_buf, | |
1346 | &iwe, buf); | |
76aa5e70 RP |
1347 | sprintf(buf, "Authentication ID: 0x%02X", cfg[4]); |
1348 | iwe.u.data.length = strlen(buf); | |
1349 | current_ev = iwe_stream_add_point(info, current_ev, | |
1350 | end_buf, | |
1351 | &iwe, buf); | |
1352 | sprintf(buf, "Formation Info: 0x%02X", cfg[5]); | |
1353 | iwe.u.data.length = strlen(buf); | |
1354 | current_ev = iwe_stream_add_point(info, current_ev, | |
1355 | end_buf, | |
1356 | &iwe, buf); | |
1357 | sprintf(buf, "Capabilities: 0x%02X", cfg[6]); | |
2a519311 JB |
1358 | iwe.u.data.length = strlen(buf); |
1359 | current_ev = iwe_stream_add_point(info, current_ev, | |
1360 | end_buf, | |
1361 | &iwe, buf); | |
1362 | kfree(buf); | |
1363 | break; | |
1364 | case WLAN_EID_SUPP_RATES: | |
1365 | case WLAN_EID_EXT_SUPP_RATES: | |
1366 | /* display all supported rates in readable format */ | |
1367 | p = current_ev + iwe_stream_lcp_len(info); | |
1368 | ||
1369 | memset(&iwe, 0, sizeof(iwe)); | |
1370 | iwe.cmd = SIOCGIWRATE; | |
1371 | /* Those two flags are ignored... */ | |
1372 | iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; | |
1373 | ||
1374 | for (i = 0; i < ie[1]; i++) { | |
1375 | iwe.u.bitrate.value = | |
1376 | ((ie[i + 2] & 0x7f) * 500000); | |
1377 | p = iwe_stream_add_value(info, current_ev, p, | |
1378 | end_buf, &iwe, IW_EV_PARAM_LEN); | |
1379 | } | |
1380 | current_ev = p; | |
1381 | break; | |
1382 | } | |
1383 | rem -= ie[1] + 2; | |
1384 | ie += ie[1] + 2; | |
1385 | } | |
1386 | ||
f64f9e71 JP |
1387 | if (bss->pub.capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS) || |
1388 | ismesh) { | |
2a519311 JB |
1389 | memset(&iwe, 0, sizeof(iwe)); |
1390 | iwe.cmd = SIOCGIWMODE; | |
1391 | if (ismesh) | |
1392 | iwe.u.mode = IW_MODE_MESH; | |
1393 | else if (bss->pub.capability & WLAN_CAPABILITY_ESS) | |
1394 | iwe.u.mode = IW_MODE_MASTER; | |
1395 | else | |
1396 | iwe.u.mode = IW_MODE_ADHOC; | |
1397 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, | |
1398 | &iwe, IW_EV_UINT_LEN); | |
1399 | } | |
1400 | ||
c49dc900 | 1401 | buf = kmalloc(31, GFP_ATOMIC); |
2a519311 JB |
1402 | if (buf) { |
1403 | memset(&iwe, 0, sizeof(iwe)); | |
1404 | iwe.cmd = IWEVCUSTOM; | |
8cef2c9d | 1405 | sprintf(buf, "tsf=%016llx", (unsigned long long)(ies->tsf)); |
2a519311 JB |
1406 | iwe.u.data.length = strlen(buf); |
1407 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | |
1408 | &iwe, buf); | |
1409 | memset(&iwe, 0, sizeof(iwe)); | |
1410 | iwe.cmd = IWEVCUSTOM; | |
cb3a8eec DW |
1411 | sprintf(buf, " Last beacon: %ums ago", |
1412 | elapsed_jiffies_msecs(bss->ts)); | |
2a519311 JB |
1413 | iwe.u.data.length = strlen(buf); |
1414 | current_ev = iwe_stream_add_point(info, current_ev, | |
1415 | end_buf, &iwe, buf); | |
1416 | kfree(buf); | |
1417 | } | |
1418 | ||
9caf0364 JB |
1419 | ieee80211_scan_add_ies(info, ies, ¤t_ev, end_buf); |
1420 | rcu_read_unlock(); | |
2a519311 JB |
1421 | |
1422 | return current_ev; | |
1423 | } | |
1424 | ||
1425 | ||
1426 | static int ieee80211_scan_results(struct cfg80211_registered_device *dev, | |
1427 | struct iw_request_info *info, | |
1428 | char *buf, size_t len) | |
1429 | { | |
1430 | char *current_ev = buf; | |
1431 | char *end_buf = buf + len; | |
1432 | struct cfg80211_internal_bss *bss; | |
1433 | ||
1434 | spin_lock_bh(&dev->bss_lock); | |
1435 | cfg80211_bss_expire(dev); | |
1436 | ||
1437 | list_for_each_entry(bss, &dev->bss_list, list) { | |
1438 | if (buf + len - current_ev <= IW_EV_ADDR_LEN) { | |
1439 | spin_unlock_bh(&dev->bss_lock); | |
1440 | return -E2BIG; | |
1441 | } | |
77965c97 JB |
1442 | current_ev = ieee80211_bss(&dev->wiphy, info, bss, |
1443 | current_ev, end_buf); | |
2a519311 JB |
1444 | } |
1445 | spin_unlock_bh(&dev->bss_lock); | |
1446 | return current_ev - buf; | |
1447 | } | |
1448 | ||
1449 | ||
1450 | int cfg80211_wext_giwscan(struct net_device *dev, | |
1451 | struct iw_request_info *info, | |
1452 | struct iw_point *data, char *extra) | |
1453 | { | |
1454 | struct cfg80211_registered_device *rdev; | |
1455 | int res; | |
1456 | ||
1457 | if (!netif_running(dev)) | |
1458 | return -ENETDOWN; | |
1459 | ||
463d0183 | 1460 | rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex); |
2a519311 JB |
1461 | |
1462 | if (IS_ERR(rdev)) | |
1463 | return PTR_ERR(rdev); | |
1464 | ||
1465 | if (rdev->scan_req) { | |
1466 | res = -EAGAIN; | |
1467 | goto out; | |
1468 | } | |
1469 | ||
1470 | res = ieee80211_scan_results(rdev, info, extra, data->length); | |
1471 | data->length = 0; | |
1472 | if (res >= 0) { | |
1473 | data->length = res; | |
1474 | res = 0; | |
1475 | } | |
1476 | ||
1477 | out: | |
4d0c8aea | 1478 | cfg80211_unlock_rdev(rdev); |
2a519311 JB |
1479 | return res; |
1480 | } | |
ba44cb72 | 1481 | EXPORT_SYMBOL_GPL(cfg80211_wext_giwscan); |
2a519311 | 1482 | #endif |