diff options
Diffstat (limited to 'net/mac80211/scan.c')
-rw-r--r-- | net/mac80211/scan.c | 763 |
1 files changed, 198 insertions, 565 deletions
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c index f5c7c3371929..3bf9839f5916 100644 --- a/net/mac80211/scan.c +++ b/net/mac80211/scan.c | |||
@@ -12,14 +12,11 @@ | |||
12 | * published by the Free Software Foundation. | 12 | * published by the Free Software Foundation. |
13 | */ | 13 | */ |
14 | 14 | ||
15 | /* TODO: | 15 | /* TODO: figure out how to avoid that the "current BSS" expires */ |
16 | * order BSS list by RSSI(?) ("quality of AP") | ||
17 | * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE, | ||
18 | * SSID) | ||
19 | */ | ||
20 | 16 | ||
21 | #include <linux/wireless.h> | 17 | #include <linux/wireless.h> |
22 | #include <linux/if_arp.h> | 18 | #include <linux/if_arp.h> |
19 | #include <linux/rtnetlink.h> | ||
23 | #include <net/mac80211.h> | 20 | #include <net/mac80211.h> |
24 | #include <net/iw_handler.h> | 21 | #include <net/iw_handler.h> |
25 | 22 | ||
@@ -30,192 +27,29 @@ | |||
30 | #define IEEE80211_CHANNEL_TIME (HZ / 33) | 27 | #define IEEE80211_CHANNEL_TIME (HZ / 33) |
31 | #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5) | 28 | #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5) |
32 | 29 | ||
33 | void ieee80211_rx_bss_list_init(struct ieee80211_local *local) | ||
34 | { | ||
35 | spin_lock_init(&local->bss_lock); | ||
36 | INIT_LIST_HEAD(&local->bss_list); | ||
37 | } | ||
38 | |||
39 | void ieee80211_rx_bss_list_deinit(struct ieee80211_local *local) | ||
40 | { | ||
41 | struct ieee80211_bss *bss, *tmp; | ||
42 | |||
43 | list_for_each_entry_safe(bss, tmp, &local->bss_list, list) | ||
44 | ieee80211_rx_bss_put(local, bss); | ||
45 | } | ||
46 | |||
47 | struct ieee80211_bss * | 30 | struct ieee80211_bss * |
48 | ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq, | 31 | ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq, |
49 | u8 *ssid, u8 ssid_len) | 32 | u8 *ssid, u8 ssid_len) |
50 | { | 33 | { |
51 | struct ieee80211_bss *bss; | 34 | return (void *)cfg80211_get_bss(local->hw.wiphy, |
52 | 35 | ieee80211_get_channel(local->hw.wiphy, | |
53 | spin_lock_bh(&local->bss_lock); | 36 | freq), |
54 | bss = local->bss_hash[STA_HASH(bssid)]; | 37 | bssid, ssid, ssid_len, |
55 | while (bss) { | 38 | 0, 0); |
56 | if (!bss_mesh_cfg(bss) && | ||
57 | !memcmp(bss->bssid, bssid, ETH_ALEN) && | ||
58 | bss->freq == freq && | ||
59 | bss->ssid_len == ssid_len && | ||
60 | (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) { | ||
61 | atomic_inc(&bss->users); | ||
62 | break; | ||
63 | } | ||
64 | bss = bss->hnext; | ||
65 | } | ||
66 | spin_unlock_bh(&local->bss_lock); | ||
67 | return bss; | ||
68 | } | ||
69 | |||
70 | /* Caller must hold local->bss_lock */ | ||
71 | static void __ieee80211_rx_bss_hash_add(struct ieee80211_local *local, | ||
72 | struct ieee80211_bss *bss) | ||
73 | { | ||
74 | u8 hash_idx; | ||
75 | |||
76 | if (bss_mesh_cfg(bss)) | ||
77 | hash_idx = mesh_id_hash(bss_mesh_id(bss), | ||
78 | bss_mesh_id_len(bss)); | ||
79 | else | ||
80 | hash_idx = STA_HASH(bss->bssid); | ||
81 | |||
82 | bss->hnext = local->bss_hash[hash_idx]; | ||
83 | local->bss_hash[hash_idx] = bss; | ||
84 | } | ||
85 | |||
86 | /* Caller must hold local->bss_lock */ | ||
87 | static void __ieee80211_rx_bss_hash_del(struct ieee80211_local *local, | ||
88 | struct ieee80211_bss *bss) | ||
89 | { | ||
90 | struct ieee80211_bss *b, *prev = NULL; | ||
91 | b = local->bss_hash[STA_HASH(bss->bssid)]; | ||
92 | while (b) { | ||
93 | if (b == bss) { | ||
94 | if (!prev) | ||
95 | local->bss_hash[STA_HASH(bss->bssid)] = | ||
96 | bss->hnext; | ||
97 | else | ||
98 | prev->hnext = bss->hnext; | ||
99 | break; | ||
100 | } | ||
101 | prev = b; | ||
102 | b = b->hnext; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | struct ieee80211_bss * | ||
107 | ieee80211_rx_bss_add(struct ieee80211_local *local, u8 *bssid, int freq, | ||
108 | u8 *ssid, u8 ssid_len) | ||
109 | { | ||
110 | struct ieee80211_bss *bss; | ||
111 | |||
112 | bss = kzalloc(sizeof(*bss), GFP_ATOMIC); | ||
113 | if (!bss) | ||
114 | return NULL; | ||
115 | atomic_set(&bss->users, 2); | ||
116 | memcpy(bss->bssid, bssid, ETH_ALEN); | ||
117 | bss->freq = freq; | ||
118 | if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) { | ||
119 | memcpy(bss->ssid, ssid, ssid_len); | ||
120 | bss->ssid_len = ssid_len; | ||
121 | } | ||
122 | |||
123 | spin_lock_bh(&local->bss_lock); | ||
124 | /* TODO: order by RSSI? */ | ||
125 | list_add_tail(&bss->list, &local->bss_list); | ||
126 | __ieee80211_rx_bss_hash_add(local, bss); | ||
127 | spin_unlock_bh(&local->bss_lock); | ||
128 | return bss; | ||
129 | } | ||
130 | |||
131 | #ifdef CONFIG_MAC80211_MESH | ||
132 | static struct ieee80211_bss * | ||
133 | ieee80211_rx_mesh_bss_get(struct ieee80211_local *local, u8 *mesh_id, int mesh_id_len, | ||
134 | u8 *mesh_cfg, int freq) | ||
135 | { | ||
136 | struct ieee80211_bss *bss; | ||
137 | |||
138 | spin_lock_bh(&local->bss_lock); | ||
139 | bss = local->bss_hash[mesh_id_hash(mesh_id, mesh_id_len)]; | ||
140 | while (bss) { | ||
141 | if (bss_mesh_cfg(bss) && | ||
142 | !memcmp(bss_mesh_cfg(bss), mesh_cfg, MESH_CFG_CMP_LEN) && | ||
143 | bss->freq == freq && | ||
144 | mesh_id_len == bss->mesh_id_len && | ||
145 | (mesh_id_len == 0 || !memcmp(bss->mesh_id, mesh_id, | ||
146 | mesh_id_len))) { | ||
147 | atomic_inc(&bss->users); | ||
148 | break; | ||
149 | } | ||
150 | bss = bss->hnext; | ||
151 | } | ||
152 | spin_unlock_bh(&local->bss_lock); | ||
153 | return bss; | ||
154 | } | 39 | } |
155 | 40 | ||
156 | static struct ieee80211_bss * | 41 | static void ieee80211_rx_bss_free(struct cfg80211_bss *cbss) |
157 | ieee80211_rx_mesh_bss_add(struct ieee80211_local *local, u8 *mesh_id, int mesh_id_len, | ||
158 | u8 *mesh_cfg, int mesh_config_len, int freq) | ||
159 | { | 42 | { |
160 | struct ieee80211_bss *bss; | 43 | struct ieee80211_bss *bss = (void *)cbss; |
161 | |||
162 | if (mesh_config_len != IEEE80211_MESH_CONFIG_LEN) | ||
163 | return NULL; | ||
164 | |||
165 | bss = kzalloc(sizeof(*bss), GFP_ATOMIC); | ||
166 | if (!bss) | ||
167 | return NULL; | ||
168 | |||
169 | bss->mesh_cfg = kmalloc(MESH_CFG_CMP_LEN, GFP_ATOMIC); | ||
170 | if (!bss->mesh_cfg) { | ||
171 | kfree(bss); | ||
172 | return NULL; | ||
173 | } | ||
174 | |||
175 | if (mesh_id_len && mesh_id_len <= IEEE80211_MAX_MESH_ID_LEN) { | ||
176 | bss->mesh_id = kmalloc(mesh_id_len, GFP_ATOMIC); | ||
177 | if (!bss->mesh_id) { | ||
178 | kfree(bss->mesh_cfg); | ||
179 | kfree(bss); | ||
180 | return NULL; | ||
181 | } | ||
182 | memcpy(bss->mesh_id, mesh_id, mesh_id_len); | ||
183 | } | ||
184 | |||
185 | atomic_set(&bss->users, 2); | ||
186 | memcpy(bss->mesh_cfg, mesh_cfg, MESH_CFG_CMP_LEN); | ||
187 | bss->mesh_id_len = mesh_id_len; | ||
188 | bss->freq = freq; | ||
189 | spin_lock_bh(&local->bss_lock); | ||
190 | /* TODO: order by RSSI? */ | ||
191 | list_add_tail(&bss->list, &local->bss_list); | ||
192 | __ieee80211_rx_bss_hash_add(local, bss); | ||
193 | spin_unlock_bh(&local->bss_lock); | ||
194 | return bss; | ||
195 | } | ||
196 | #endif | ||
197 | 44 | ||
198 | static void ieee80211_rx_bss_free(struct ieee80211_bss *bss) | ||
199 | { | ||
200 | kfree(bss->ies); | ||
201 | kfree(bss_mesh_id(bss)); | 45 | kfree(bss_mesh_id(bss)); |
202 | kfree(bss_mesh_cfg(bss)); | 46 | kfree(bss_mesh_cfg(bss)); |
203 | kfree(bss); | ||
204 | } | 47 | } |
205 | 48 | ||
206 | void ieee80211_rx_bss_put(struct ieee80211_local *local, | 49 | void ieee80211_rx_bss_put(struct ieee80211_local *local, |
207 | struct ieee80211_bss *bss) | 50 | struct ieee80211_bss *bss) |
208 | { | 51 | { |
209 | local_bh_disable(); | 52 | cfg80211_put_bss((struct cfg80211_bss *)bss); |
210 | if (!atomic_dec_and_lock(&bss->users, &local->bss_lock)) { | ||
211 | local_bh_enable(); | ||
212 | return; | ||
213 | } | ||
214 | |||
215 | __ieee80211_rx_bss_hash_del(local, bss); | ||
216 | list_del(&bss->list); | ||
217 | spin_unlock_bh(&local->bss_lock); | ||
218 | ieee80211_rx_bss_free(bss); | ||
219 | } | 53 | } |
220 | 54 | ||
221 | struct ieee80211_bss * | 55 | struct ieee80211_bss * |
@@ -224,39 +58,25 @@ ieee80211_bss_info_update(struct ieee80211_local *local, | |||
224 | struct ieee80211_mgmt *mgmt, | 58 | struct ieee80211_mgmt *mgmt, |
225 | size_t len, | 59 | size_t len, |
226 | struct ieee802_11_elems *elems, | 60 | struct ieee802_11_elems *elems, |
227 | int freq, bool beacon) | 61 | struct ieee80211_channel *channel, |
62 | bool beacon) | ||
228 | { | 63 | { |
229 | struct ieee80211_bss *bss; | 64 | struct ieee80211_bss *bss; |
230 | int clen; | 65 | int clen; |
66 | s32 signal = 0; | ||
231 | 67 | ||
232 | #ifdef CONFIG_MAC80211_MESH | 68 | if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) |
233 | if (elems->mesh_config) | 69 | signal = rx_status->signal * 100; |
234 | bss = ieee80211_rx_mesh_bss_get(local, elems->mesh_id, | 70 | else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) |
235 | elems->mesh_id_len, elems->mesh_config, freq); | 71 | signal = (rx_status->signal * 100) / local->hw.max_signal; |
236 | else | 72 | |
237 | #endif | 73 | bss = (void *)cfg80211_inform_bss_frame(local->hw.wiphy, channel, |
238 | bss = ieee80211_rx_bss_get(local, mgmt->bssid, freq, | 74 | mgmt, len, signal, GFP_ATOMIC); |
239 | elems->ssid, elems->ssid_len); | 75 | |
240 | if (!bss) { | 76 | if (!bss) |
241 | #ifdef CONFIG_MAC80211_MESH | 77 | return NULL; |
242 | if (elems->mesh_config) | 78 | |
243 | bss = ieee80211_rx_mesh_bss_add(local, elems->mesh_id, | 79 | bss->cbss.free_priv = ieee80211_rx_bss_free; |
244 | elems->mesh_id_len, elems->mesh_config, | ||
245 | elems->mesh_config_len, freq); | ||
246 | else | ||
247 | #endif | ||
248 | bss = ieee80211_rx_bss_add(local, mgmt->bssid, freq, | ||
249 | elems->ssid, elems->ssid_len); | ||
250 | if (!bss) | ||
251 | return NULL; | ||
252 | } else { | ||
253 | #if 0 | ||
254 | /* TODO: order by RSSI? */ | ||
255 | spin_lock_bh(&local->bss_lock); | ||
256 | list_move_tail(&bss->list, &local->bss_list); | ||
257 | spin_unlock_bh(&local->bss_lock); | ||
258 | #endif | ||
259 | } | ||
260 | 80 | ||
261 | /* save the ERP value so that it is available at association time */ | 81 | /* save the ERP value so that it is available at association time */ |
262 | if (elems->erp_info && elems->erp_info_len >= 1) { | 82 | if (elems->erp_info && elems->erp_info_len >= 1) { |
@@ -264,9 +84,6 @@ ieee80211_bss_info_update(struct ieee80211_local *local, | |||
264 | bss->has_erp_value = 1; | 84 | bss->has_erp_value = 1; |
265 | } | 85 | } |
266 | 86 | ||
267 | bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int); | ||
268 | bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info); | ||
269 | |||
270 | if (elems->tim) { | 87 | if (elems->tim) { |
271 | struct ieee80211_tim_ie *tim_ie = | 88 | struct ieee80211_tim_ie *tim_ie = |
272 | (struct ieee80211_tim_ie *)elems->tim; | 89 | (struct ieee80211_tim_ie *)elems->tim; |
@@ -295,37 +112,27 @@ ieee80211_bss_info_update(struct ieee80211_local *local, | |||
295 | bss->supp_rates_len += clen; | 112 | bss->supp_rates_len += clen; |
296 | } | 113 | } |
297 | 114 | ||
298 | bss->band = rx_status->band; | ||
299 | |||
300 | bss->timestamp = le64_to_cpu(mgmt->u.beacon.timestamp); | ||
301 | bss->last_update = jiffies; | ||
302 | bss->signal = rx_status->signal; | ||
303 | bss->noise = rx_status->noise; | ||
304 | bss->qual = rx_status->qual; | ||
305 | bss->wmm_used = elems->wmm_param || elems->wmm_info; | 115 | bss->wmm_used = elems->wmm_param || elems->wmm_info; |
306 | 116 | ||
307 | if (!beacon) | 117 | if (!beacon) |
308 | bss->last_probe_resp = jiffies; | 118 | bss->last_probe_resp = jiffies; |
309 | 119 | ||
310 | /* | ||
311 | * For probe responses, or if we don't have any information yet, | ||
312 | * use the IEs from the beacon. | ||
313 | */ | ||
314 | if (!bss->ies || !beacon) { | ||
315 | if (bss->ies == NULL || bss->ies_len < elems->total_len) { | ||
316 | kfree(bss->ies); | ||
317 | bss->ies = kmalloc(elems->total_len, GFP_ATOMIC); | ||
318 | } | ||
319 | if (bss->ies) { | ||
320 | memcpy(bss->ies, elems->ie_start, elems->total_len); | ||
321 | bss->ies_len = elems->total_len; | ||
322 | } else | ||
323 | bss->ies_len = 0; | ||
324 | } | ||
325 | |||
326 | return bss; | 120 | return bss; |
327 | } | 121 | } |
328 | 122 | ||
123 | void ieee80211_rx_bss_remove(struct ieee80211_sub_if_data *sdata, u8 *bssid, | ||
124 | int freq, u8 *ssid, u8 ssid_len) | ||
125 | { | ||
126 | struct ieee80211_bss *bss; | ||
127 | struct ieee80211_local *local = sdata->local; | ||
128 | |||
129 | bss = ieee80211_rx_bss_get(local, bssid, freq, ssid, ssid_len); | ||
130 | if (bss) { | ||
131 | cfg80211_unlink_bss(local->hw.wiphy, (void *)bss); | ||
132 | ieee80211_rx_bss_put(local, bss); | ||
133 | } | ||
134 | } | ||
135 | |||
329 | ieee80211_rx_result | 136 | ieee80211_rx_result |
330 | ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, | 137 | ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, |
331 | struct ieee80211_rx_status *rx_status) | 138 | struct ieee80211_rx_status *rx_status) |
@@ -387,7 +194,7 @@ ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, | |||
387 | 194 | ||
388 | bss = ieee80211_bss_info_update(sdata->local, rx_status, | 195 | bss = ieee80211_bss_info_update(sdata->local, rx_status, |
389 | mgmt, skb->len, &elems, | 196 | mgmt, skb->len, &elems, |
390 | freq, beacon); | 197 | channel, beacon); |
391 | if (bss) | 198 | if (bss) |
392 | ieee80211_rx_bss_put(sdata->local, bss); | 199 | ieee80211_rx_bss_put(sdata->local, bss); |
393 | 200 | ||
@@ -395,56 +202,94 @@ ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, | |||
395 | return RX_QUEUED; | 202 | return RX_QUEUED; |
396 | } | 203 | } |
397 | 204 | ||
398 | static void ieee80211_send_nullfunc(struct ieee80211_local *local, | 205 | void ieee80211_scan_failed(struct ieee80211_local *local) |
399 | struct ieee80211_sub_if_data *sdata, | ||
400 | int powersave) | ||
401 | { | 206 | { |
402 | struct sk_buff *skb; | 207 | if (WARN_ON(!local->scan_req)) |
403 | struct ieee80211_hdr *nullfunc; | ||
404 | __le16 fc; | ||
405 | |||
406 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24); | ||
407 | if (!skb) { | ||
408 | printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc " | ||
409 | "frame\n", sdata->dev->name); | ||
410 | return; | 208 | return; |
209 | |||
210 | /* notify cfg80211 about the failed scan */ | ||
211 | if (local->scan_req != &local->int_scan_req) | ||
212 | cfg80211_scan_done(local->scan_req, true); | ||
213 | |||
214 | local->scan_req = NULL; | ||
215 | } | ||
216 | |||
217 | /* | ||
218 | * inform AP that we will go to sleep so that it will buffer the frames | ||
219 | * while we scan | ||
220 | */ | ||
221 | static void ieee80211_scan_ps_enable(struct ieee80211_sub_if_data *sdata) | ||
222 | { | ||
223 | struct ieee80211_local *local = sdata->local; | ||
224 | bool ps = false; | ||
225 | |||
226 | /* FIXME: what to do when local->pspolling is true? */ | ||
227 | |||
228 | del_timer_sync(&local->dynamic_ps_timer); | ||
229 | cancel_work_sync(&local->dynamic_ps_enable_work); | ||
230 | |||
231 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { | ||
232 | ps = true; | ||
233 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; | ||
234 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); | ||
235 | } | ||
236 | |||
237 | if (!ps || !(local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) | ||
238 | /* | ||
239 | * If power save was enabled, no need to send a nullfunc | ||
240 | * frame because AP knows that we are sleeping. But if the | ||
241 | * hardware is creating the nullfunc frame for power save | ||
242 | * status (ie. IEEE80211_HW_PS_NULLFUNC_STACK is not | ||
243 | * enabled) and power save was enabled, the firmware just | ||
244 | * sent a null frame with power save disabled. So we need | ||
245 | * to send a new nullfunc frame to inform the AP that we | ||
246 | * are again sleeping. | ||
247 | */ | ||
248 | ieee80211_send_nullfunc(local, sdata, 1); | ||
249 | } | ||
250 | |||
251 | /* inform AP that we are awake again, unless power save is enabled */ | ||
252 | static void ieee80211_scan_ps_disable(struct ieee80211_sub_if_data *sdata) | ||
253 | { | ||
254 | struct ieee80211_local *local = sdata->local; | ||
255 | |||
256 | if (!local->powersave) | ||
257 | ieee80211_send_nullfunc(local, sdata, 0); | ||
258 | else { | ||
259 | /* | ||
260 | * In !IEEE80211_HW_PS_NULLFUNC_STACK case the hardware | ||
261 | * will send a nullfunc frame with the powersave bit set | ||
262 | * even though the AP already knows that we are sleeping. | ||
263 | * This could be avoided by sending a null frame with power | ||
264 | * save bit disabled before enabling the power save, but | ||
265 | * this doesn't gain anything. | ||
266 | * | ||
267 | * When IEEE80211_HW_PS_NULLFUNC_STACK is enabled, no need | ||
268 | * to send a nullfunc frame because AP already knows that | ||
269 | * we are sleeping, let's just enable power save mode in | ||
270 | * hardware. | ||
271 | */ | ||
272 | local->hw.conf.flags |= IEEE80211_CONF_PS; | ||
273 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); | ||
411 | } | 274 | } |
412 | skb_reserve(skb, local->hw.extra_tx_headroom); | ||
413 | |||
414 | nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24); | ||
415 | memset(nullfunc, 0, 24); | ||
416 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | | ||
417 | IEEE80211_FCTL_TODS); | ||
418 | if (powersave) | ||
419 | fc |= cpu_to_le16(IEEE80211_FCTL_PM); | ||
420 | nullfunc->frame_control = fc; | ||
421 | memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN); | ||
422 | memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN); | ||
423 | memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN); | ||
424 | |||
425 | ieee80211_tx_skb(sdata, skb, 0); | ||
426 | } | 275 | } |
427 | 276 | ||
428 | void ieee80211_scan_completed(struct ieee80211_hw *hw) | 277 | void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted) |
429 | { | 278 | { |
430 | struct ieee80211_local *local = hw_to_local(hw); | 279 | struct ieee80211_local *local = hw_to_local(hw); |
431 | struct ieee80211_sub_if_data *sdata; | 280 | struct ieee80211_sub_if_data *sdata; |
432 | union iwreq_data wrqu; | ||
433 | 281 | ||
434 | if (WARN_ON(!local->hw_scanning && !local->sw_scanning)) | 282 | if (WARN_ON(!local->hw_scanning && !local->sw_scanning)) |
435 | return; | 283 | return; |
436 | 284 | ||
437 | local->last_scan_completed = jiffies; | 285 | if (WARN_ON(!local->scan_req)) |
438 | memset(&wrqu, 0, sizeof(wrqu)); | 286 | return; |
439 | 287 | ||
440 | /* | 288 | if (local->scan_req != &local->int_scan_req) |
441 | * local->scan_sdata could have been NULLed by the interface | 289 | cfg80211_scan_done(local->scan_req, aborted); |
442 | * down code in case we were scanning on an interface that is | 290 | local->scan_req = NULL; |
443 | * being taken down. | 291 | |
444 | */ | 292 | local->last_scan_completed = jiffies; |
445 | sdata = local->scan_sdata; | ||
446 | if (sdata) | ||
447 | wireless_send_event(sdata->dev, SIOCGIWSCAN, &wrqu, NULL); | ||
448 | 293 | ||
449 | if (local->hw_scanning) { | 294 | if (local->hw_scanning) { |
450 | local->hw_scanning = false; | 295 | local->hw_scanning = false; |
@@ -472,34 +317,46 @@ void ieee80211_scan_completed(struct ieee80211_hw *hw) | |||
472 | netif_addr_unlock(local->mdev); | 317 | netif_addr_unlock(local->mdev); |
473 | netif_tx_unlock_bh(local->mdev); | 318 | netif_tx_unlock_bh(local->mdev); |
474 | 319 | ||
475 | rcu_read_lock(); | 320 | if (local->ops->sw_scan_complete) |
476 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { | 321 | local->ops->sw_scan_complete(local_to_hw(local)); |
322 | |||
323 | mutex_lock(&local->iflist_mtx); | ||
324 | list_for_each_entry(sdata, &local->interfaces, list) { | ||
325 | if (!netif_running(sdata->dev)) | ||
326 | continue; | ||
327 | |||
477 | /* Tell AP we're back */ | 328 | /* Tell AP we're back */ |
478 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { | 329 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
479 | if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) { | 330 | if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED) { |
480 | ieee80211_send_nullfunc(local, sdata, 0); | 331 | ieee80211_scan_ps_disable(sdata); |
481 | netif_tx_wake_all_queues(sdata->dev); | 332 | netif_tx_wake_all_queues(sdata->dev); |
482 | } | 333 | } |
483 | } else | 334 | } else |
484 | netif_tx_wake_all_queues(sdata->dev); | 335 | netif_tx_wake_all_queues(sdata->dev); |
336 | |||
337 | /* re-enable beaconing */ | ||
338 | if (sdata->vif.type == NL80211_IFTYPE_AP || | ||
339 | sdata->vif.type == NL80211_IFTYPE_ADHOC || | ||
340 | sdata->vif.type == NL80211_IFTYPE_MESH_POINT) | ||
341 | ieee80211_if_config(sdata, | ||
342 | IEEE80211_IFCC_BEACON_ENABLED); | ||
485 | } | 343 | } |
486 | rcu_read_unlock(); | 344 | mutex_unlock(&local->iflist_mtx); |
487 | 345 | ||
488 | done: | 346 | done: |
489 | ieee80211_mlme_notify_scan_completed(local); | 347 | ieee80211_mlme_notify_scan_completed(local); |
348 | ieee80211_ibss_notify_scan_completed(local); | ||
490 | ieee80211_mesh_notify_scan_completed(local); | 349 | ieee80211_mesh_notify_scan_completed(local); |
491 | } | 350 | } |
492 | EXPORT_SYMBOL(ieee80211_scan_completed); | 351 | EXPORT_SYMBOL(ieee80211_scan_completed); |
493 | 352 | ||
494 | |||
495 | void ieee80211_scan_work(struct work_struct *work) | 353 | void ieee80211_scan_work(struct work_struct *work) |
496 | { | 354 | { |
497 | struct ieee80211_local *local = | 355 | struct ieee80211_local *local = |
498 | container_of(work, struct ieee80211_local, scan_work.work); | 356 | container_of(work, struct ieee80211_local, scan_work.work); |
499 | struct ieee80211_sub_if_data *sdata = local->scan_sdata; | 357 | struct ieee80211_sub_if_data *sdata = local->scan_sdata; |
500 | struct ieee80211_supported_band *sband; | ||
501 | struct ieee80211_channel *chan; | 358 | struct ieee80211_channel *chan; |
502 | int skip; | 359 | int skip, i; |
503 | unsigned long next_delay = 0; | 360 | unsigned long next_delay = 0; |
504 | 361 | ||
505 | /* | 362 | /* |
@@ -510,33 +367,13 @@ void ieee80211_scan_work(struct work_struct *work) | |||
510 | 367 | ||
511 | switch (local->scan_state) { | 368 | switch (local->scan_state) { |
512 | case SCAN_SET_CHANNEL: | 369 | case SCAN_SET_CHANNEL: |
513 | /* | ||
514 | * Get current scan band. scan_band may be IEEE80211_NUM_BANDS | ||
515 | * after we successfully scanned the last channel of the last | ||
516 | * band (and the last band is supported by the hw) | ||
517 | */ | ||
518 | if (local->scan_band < IEEE80211_NUM_BANDS) | ||
519 | sband = local->hw.wiphy->bands[local->scan_band]; | ||
520 | else | ||
521 | sband = NULL; | ||
522 | |||
523 | /* | ||
524 | * If we are at an unsupported band and have more bands | ||
525 | * left to scan, advance to the next supported one. | ||
526 | */ | ||
527 | while (!sband && local->scan_band < IEEE80211_NUM_BANDS - 1) { | ||
528 | local->scan_band++; | ||
529 | sband = local->hw.wiphy->bands[local->scan_band]; | ||
530 | local->scan_channel_idx = 0; | ||
531 | } | ||
532 | |||
533 | /* if no more bands/channels left, complete scan */ | 370 | /* if no more bands/channels left, complete scan */ |
534 | if (!sband || local->scan_channel_idx >= sband->n_channels) { | 371 | if (local->scan_channel_idx >= local->scan_req->n_channels) { |
535 | ieee80211_scan_completed(local_to_hw(local)); | 372 | ieee80211_scan_completed(local_to_hw(local), false); |
536 | return; | 373 | return; |
537 | } | 374 | } |
538 | skip = 0; | 375 | skip = 0; |
539 | chan = &sband->channels[local->scan_channel_idx]; | 376 | chan = local->scan_req->channels[local->scan_channel_idx]; |
540 | 377 | ||
541 | if (chan->flags & IEEE80211_CHAN_DISABLED || | 378 | if (chan->flags & IEEE80211_CHAN_DISABLED || |
542 | (sdata->vif.type == NL80211_IFTYPE_ADHOC && | 379 | (sdata->vif.type == NL80211_IFTYPE_ADHOC && |
@@ -552,15 +389,6 @@ void ieee80211_scan_work(struct work_struct *work) | |||
552 | 389 | ||
553 | /* advance state machine to next channel/band */ | 390 | /* advance state machine to next channel/band */ |
554 | local->scan_channel_idx++; | 391 | local->scan_channel_idx++; |
555 | if (local->scan_channel_idx >= sband->n_channels) { | ||
556 | /* | ||
557 | * scan_band may end up == IEEE80211_NUM_BANDS, but | ||
558 | * we'll catch that case above and complete the scan | ||
559 | * if that is the case. | ||
560 | */ | ||
561 | local->scan_band++; | ||
562 | local->scan_channel_idx = 0; | ||
563 | } | ||
564 | 392 | ||
565 | if (skip) | 393 | if (skip) |
566 | break; | 394 | break; |
@@ -573,10 +401,15 @@ void ieee80211_scan_work(struct work_struct *work) | |||
573 | next_delay = IEEE80211_PASSIVE_CHANNEL_TIME; | 401 | next_delay = IEEE80211_PASSIVE_CHANNEL_TIME; |
574 | local->scan_state = SCAN_SET_CHANNEL; | 402 | local->scan_state = SCAN_SET_CHANNEL; |
575 | 403 | ||
576 | if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN) | 404 | if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN || |
405 | !local->scan_req->n_ssids) | ||
577 | break; | 406 | break; |
578 | ieee80211_send_probe_req(sdata, NULL, local->scan_ssid, | 407 | for (i = 0; i < local->scan_req->n_ssids; i++) |
579 | local->scan_ssid_len); | 408 | ieee80211_send_probe_req( |
409 | sdata, NULL, | ||
410 | local->scan_req->ssids[i].ssid, | ||
411 | local->scan_req->ssids[i].ssid_len, | ||
412 | local->scan_req->ie, local->scan_req->ie_len); | ||
580 | next_delay = IEEE80211_CHANNEL_TIME; | 413 | next_delay = IEEE80211_CHANNEL_TIME; |
581 | break; | 414 | break; |
582 | } | 415 | } |
@@ -587,14 +420,19 @@ void ieee80211_scan_work(struct work_struct *work) | |||
587 | 420 | ||
588 | 421 | ||
589 | int ieee80211_start_scan(struct ieee80211_sub_if_data *scan_sdata, | 422 | int ieee80211_start_scan(struct ieee80211_sub_if_data *scan_sdata, |
590 | u8 *ssid, size_t ssid_len) | 423 | struct cfg80211_scan_request *req) |
591 | { | 424 | { |
592 | struct ieee80211_local *local = scan_sdata->local; | 425 | struct ieee80211_local *local = scan_sdata->local; |
593 | struct ieee80211_sub_if_data *sdata; | 426 | struct ieee80211_sub_if_data *sdata; |
594 | 427 | ||
595 | if (ssid_len > IEEE80211_MAX_SSID_LEN) | 428 | if (!req) |
596 | return -EINVAL; | 429 | return -EINVAL; |
597 | 430 | ||
431 | if (local->scan_req && local->scan_req != req) | ||
432 | return -EBUSY; | ||
433 | |||
434 | local->scan_req = req; | ||
435 | |||
598 | /* MLME-SCAN.request (page 118) page 144 (11.1.3.1) | 436 | /* MLME-SCAN.request (page 118) page 144 (11.1.3.1) |
599 | * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS | 437 | * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS |
600 | * BSSID: MACAddress | 438 | * BSSID: MACAddress |
@@ -622,7 +460,7 @@ int ieee80211_start_scan(struct ieee80211_sub_if_data *scan_sdata, | |||
622 | int rc; | 460 | int rc; |
623 | 461 | ||
624 | local->hw_scanning = true; | 462 | local->hw_scanning = true; |
625 | rc = local->ops->hw_scan(local_to_hw(local), ssid, ssid_len); | 463 | rc = local->ops->hw_scan(local_to_hw(local), req); |
626 | if (rc) { | 464 | if (rc) { |
627 | local->hw_scanning = false; | 465 | local->hw_scanning = false; |
628 | return rc; | 466 | return rc; |
@@ -631,29 +469,49 @@ int ieee80211_start_scan(struct ieee80211_sub_if_data *scan_sdata, | |||
631 | return 0; | 469 | return 0; |
632 | } | 470 | } |
633 | 471 | ||
472 | /* | ||
473 | * Hardware/driver doesn't support hw_scan, so use software | ||
474 | * scanning instead. First send a nullfunc frame with power save | ||
475 | * bit on so that AP will buffer the frames for us while we are not | ||
476 | * listening, then send probe requests to each channel and wait for | ||
477 | * the responses. After all channels are scanned, tune back to the | ||
478 | * original channel and send a nullfunc frame with power save bit | ||
479 | * off to trigger the AP to send us all the buffered frames. | ||
480 | * | ||
481 | * Note that while local->sw_scanning is true everything else but | ||
482 | * nullfunc frames and probe requests will be dropped in | ||
483 | * ieee80211_tx_h_check_assoc(). | ||
484 | */ | ||
634 | local->sw_scanning = true; | 485 | local->sw_scanning = true; |
486 | if (local->ops->sw_scan_start) | ||
487 | local->ops->sw_scan_start(local_to_hw(local)); | ||
488 | |||
489 | mutex_lock(&local->iflist_mtx); | ||
490 | list_for_each_entry(sdata, &local->interfaces, list) { | ||
491 | if (!netif_running(sdata->dev)) | ||
492 | continue; | ||
493 | |||
494 | /* disable beaconing */ | ||
495 | if (sdata->vif.type == NL80211_IFTYPE_AP || | ||
496 | sdata->vif.type == NL80211_IFTYPE_ADHOC || | ||
497 | sdata->vif.type == NL80211_IFTYPE_MESH_POINT) | ||
498 | ieee80211_if_config(sdata, | ||
499 | IEEE80211_IFCC_BEACON_ENABLED); | ||
635 | 500 | ||
636 | rcu_read_lock(); | ||
637 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { | ||
638 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { | 501 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
639 | if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) { | 502 | if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED) { |
640 | netif_tx_stop_all_queues(sdata->dev); | 503 | netif_tx_stop_all_queues(sdata->dev); |
641 | ieee80211_send_nullfunc(local, sdata, 1); | 504 | ieee80211_scan_ps_enable(sdata); |
642 | } | 505 | } |
643 | } else | 506 | } else |
644 | netif_tx_stop_all_queues(sdata->dev); | 507 | netif_tx_stop_all_queues(sdata->dev); |
645 | } | 508 | } |
646 | rcu_read_unlock(); | 509 | mutex_unlock(&local->iflist_mtx); |
647 | 510 | ||
648 | if (ssid) { | ||
649 | local->scan_ssid_len = ssid_len; | ||
650 | memcpy(local->scan_ssid, ssid, ssid_len); | ||
651 | } else | ||
652 | local->scan_ssid_len = 0; | ||
653 | local->scan_state = SCAN_SET_CHANNEL; | 511 | local->scan_state = SCAN_SET_CHANNEL; |
654 | local->scan_channel_idx = 0; | 512 | local->scan_channel_idx = 0; |
655 | local->scan_band = IEEE80211_BAND_2GHZ; | ||
656 | local->scan_sdata = scan_sdata; | 513 | local->scan_sdata = scan_sdata; |
514 | local->scan_req = req; | ||
657 | 515 | ||
658 | netif_addr_lock_bh(local->mdev); | 516 | netif_addr_lock_bh(local->mdev); |
659 | local->filter_flags |= FIF_BCN_PRBRESP_PROMISC; | 517 | local->filter_flags |= FIF_BCN_PRBRESP_PROMISC; |
@@ -673,13 +531,21 @@ int ieee80211_start_scan(struct ieee80211_sub_if_data *scan_sdata, | |||
673 | 531 | ||
674 | 532 | ||
675 | int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata, | 533 | int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata, |
676 | u8 *ssid, size_t ssid_len) | 534 | struct cfg80211_scan_request *req) |
677 | { | 535 | { |
678 | struct ieee80211_local *local = sdata->local; | 536 | struct ieee80211_local *local = sdata->local; |
679 | struct ieee80211_if_sta *ifsta; | 537 | struct ieee80211_if_managed *ifmgd; |
538 | |||
539 | if (!req) | ||
540 | return -EINVAL; | ||
541 | |||
542 | if (local->scan_req && local->scan_req != req) | ||
543 | return -EBUSY; | ||
544 | |||
545 | local->scan_req = req; | ||
680 | 546 | ||
681 | if (sdata->vif.type != NL80211_IFTYPE_STATION) | 547 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
682 | return ieee80211_start_scan(sdata, ssid, ssid_len); | 548 | return ieee80211_start_scan(sdata, req); |
683 | 549 | ||
684 | /* | 550 | /* |
685 | * STA has a state machine that might need to defer scanning | 551 | * STA has a state machine that might need to defer scanning |
@@ -693,242 +559,9 @@ int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata, | |||
693 | return -EBUSY; | 559 | return -EBUSY; |
694 | } | 560 | } |
695 | 561 | ||
696 | ifsta = &sdata->u.sta; | 562 | ifmgd = &sdata->u.mgd; |
697 | 563 | set_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request); | |
698 | ifsta->scan_ssid_len = ssid_len; | 564 | queue_work(local->hw.workqueue, &ifmgd->work); |
699 | if (ssid_len) | ||
700 | memcpy(ifsta->scan_ssid, ssid, ssid_len); | ||
701 | set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request); | ||
702 | queue_work(local->hw.workqueue, &ifsta->work); | ||
703 | 565 | ||
704 | return 0; | 566 | return 0; |
705 | } | 567 | } |
706 | |||
707 | |||
708 | static void ieee80211_scan_add_ies(struct iw_request_info *info, | ||
709 | struct ieee80211_bss *bss, | ||
710 | char **current_ev, char *end_buf) | ||
711 | { | ||
712 | u8 *pos, *end, *next; | ||
713 | struct iw_event iwe; | ||
714 | |||
715 | if (bss == NULL || bss->ies == NULL) | ||
716 | return; | ||
717 | |||
718 | /* | ||
719 | * If needed, fragment the IEs buffer (at IE boundaries) into short | ||
720 | * enough fragments to fit into IW_GENERIC_IE_MAX octet messages. | ||
721 | */ | ||
722 | pos = bss->ies; | ||
723 | end = pos + bss->ies_len; | ||
724 | |||
725 | while (end - pos > IW_GENERIC_IE_MAX) { | ||
726 | next = pos + 2 + pos[1]; | ||
727 | while (next + 2 + next[1] - pos < IW_GENERIC_IE_MAX) | ||
728 | next = next + 2 + next[1]; | ||
729 | |||
730 | memset(&iwe, 0, sizeof(iwe)); | ||
731 | iwe.cmd = IWEVGENIE; | ||
732 | iwe.u.data.length = next - pos; | ||
733 | *current_ev = iwe_stream_add_point(info, *current_ev, | ||
734 | end_buf, &iwe, pos); | ||
735 | |||
736 | pos = next; | ||
737 | } | ||
738 | |||
739 | if (end > pos) { | ||
740 | memset(&iwe, 0, sizeof(iwe)); | ||
741 | iwe.cmd = IWEVGENIE; | ||
742 | iwe.u.data.length = end - pos; | ||
743 | *current_ev = iwe_stream_add_point(info, *current_ev, | ||
744 | end_buf, &iwe, pos); | ||
745 | } | ||
746 | } | ||
747 | |||
748 | |||
749 | static char * | ||
750 | ieee80211_scan_result(struct ieee80211_local *local, | ||
751 | struct iw_request_info *info, | ||
752 | struct ieee80211_bss *bss, | ||
753 | char *current_ev, char *end_buf) | ||
754 | { | ||
755 | struct iw_event iwe; | ||
756 | char *buf; | ||
757 | |||
758 | if (time_after(jiffies, | ||
759 | bss->last_update + IEEE80211_SCAN_RESULT_EXPIRE)) | ||
760 | return current_ev; | ||
761 | |||
762 | memset(&iwe, 0, sizeof(iwe)); | ||
763 | iwe.cmd = SIOCGIWAP; | ||
764 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; | ||
765 | memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN); | ||
766 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, | ||
767 | IW_EV_ADDR_LEN); | ||
768 | |||
769 | memset(&iwe, 0, sizeof(iwe)); | ||
770 | iwe.cmd = SIOCGIWESSID; | ||
771 | if (bss_mesh_cfg(bss)) { | ||
772 | iwe.u.data.length = bss_mesh_id_len(bss); | ||
773 | iwe.u.data.flags = 1; | ||
774 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | ||
775 | &iwe, bss_mesh_id(bss)); | ||
776 | } else { | ||
777 | iwe.u.data.length = bss->ssid_len; | ||
778 | iwe.u.data.flags = 1; | ||
779 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | ||
780 | &iwe, bss->ssid); | ||
781 | } | ||
782 | |||
783 | if (bss->capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS) | ||
784 | || bss_mesh_cfg(bss)) { | ||
785 | memset(&iwe, 0, sizeof(iwe)); | ||
786 | iwe.cmd = SIOCGIWMODE; | ||
787 | if (bss_mesh_cfg(bss)) | ||
788 | iwe.u.mode = IW_MODE_MESH; | ||
789 | else if (bss->capability & WLAN_CAPABILITY_ESS) | ||
790 | iwe.u.mode = IW_MODE_MASTER; | ||
791 | else | ||
792 | iwe.u.mode = IW_MODE_ADHOC; | ||
793 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, | ||
794 | &iwe, IW_EV_UINT_LEN); | ||
795 | } | ||
796 | |||
797 | memset(&iwe, 0, sizeof(iwe)); | ||
798 | iwe.cmd = SIOCGIWFREQ; | ||
799 | iwe.u.freq.m = ieee80211_frequency_to_channel(bss->freq); | ||
800 | iwe.u.freq.e = 0; | ||
801 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, | ||
802 | IW_EV_FREQ_LEN); | ||
803 | |||
804 | memset(&iwe, 0, sizeof(iwe)); | ||
805 | iwe.cmd = SIOCGIWFREQ; | ||
806 | iwe.u.freq.m = bss->freq; | ||
807 | iwe.u.freq.e = 6; | ||
808 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, | ||
809 | IW_EV_FREQ_LEN); | ||
810 | memset(&iwe, 0, sizeof(iwe)); | ||
811 | iwe.cmd = IWEVQUAL; | ||
812 | iwe.u.qual.qual = bss->qual; | ||
813 | iwe.u.qual.level = bss->signal; | ||
814 | iwe.u.qual.noise = bss->noise; | ||
815 | iwe.u.qual.updated = local->wstats_flags; | ||
816 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, &iwe, | ||
817 | IW_EV_QUAL_LEN); | ||
818 | |||
819 | memset(&iwe, 0, sizeof(iwe)); | ||
820 | iwe.cmd = SIOCGIWENCODE; | ||
821 | if (bss->capability & WLAN_CAPABILITY_PRIVACY) | ||
822 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; | ||
823 | else | ||
824 | iwe.u.data.flags = IW_ENCODE_DISABLED; | ||
825 | iwe.u.data.length = 0; | ||
826 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | ||
827 | &iwe, ""); | ||
828 | |||
829 | ieee80211_scan_add_ies(info, bss, ¤t_ev, end_buf); | ||
830 | |||
831 | if (bss->supp_rates_len > 0) { | ||
832 | /* display all supported rates in readable format */ | ||
833 | char *p = current_ev + iwe_stream_lcp_len(info); | ||
834 | int i; | ||
835 | |||
836 | memset(&iwe, 0, sizeof(iwe)); | ||
837 | iwe.cmd = SIOCGIWRATE; | ||
838 | /* Those two flags are ignored... */ | ||
839 | iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0; | ||
840 | |||
841 | for (i = 0; i < bss->supp_rates_len; i++) { | ||
842 | iwe.u.bitrate.value = ((bss->supp_rates[i] & | ||
843 | 0x7f) * 500000); | ||
844 | p = iwe_stream_add_value(info, current_ev, p, | ||
845 | end_buf, &iwe, IW_EV_PARAM_LEN); | ||
846 | } | ||
847 | current_ev = p; | ||
848 | } | ||
849 | |||
850 | buf = kmalloc(30, GFP_ATOMIC); | ||
851 | if (buf) { | ||
852 | memset(&iwe, 0, sizeof(iwe)); | ||
853 | iwe.cmd = IWEVCUSTOM; | ||
854 | sprintf(buf, "tsf=%016llx", (unsigned long long)(bss->timestamp)); | ||
855 | iwe.u.data.length = strlen(buf); | ||
856 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, | ||
857 | &iwe, buf); | ||
858 | memset(&iwe, 0, sizeof(iwe)); | ||
859 | iwe.cmd = IWEVCUSTOM; | ||
860 | sprintf(buf, " Last beacon: %dms ago", | ||
861 | jiffies_to_msecs(jiffies - bss->last_update)); | ||
862 | iwe.u.data.length = strlen(buf); | ||
863 | current_ev = iwe_stream_add_point(info, current_ev, | ||
864 | end_buf, &iwe, buf); | ||
865 | kfree(buf); | ||
866 | } | ||
867 | |||
868 | if (bss_mesh_cfg(bss)) { | ||
869 | u8 *cfg = bss_mesh_cfg(bss); | ||
870 | buf = kmalloc(50, GFP_ATOMIC); | ||
871 | if (buf) { | ||
872 | memset(&iwe, 0, sizeof(iwe)); | ||
873 | iwe.cmd = IWEVCUSTOM; | ||
874 | sprintf(buf, "Mesh network (version %d)", cfg[0]); | ||
875 | iwe.u.data.length = strlen(buf); | ||
876 | current_ev = iwe_stream_add_point(info, current_ev, | ||
877 | end_buf, | ||
878 | &iwe, buf); | ||
879 | sprintf(buf, "Path Selection Protocol ID: " | ||
880 | "0x%02X%02X%02X%02X", cfg[1], cfg[2], cfg[3], | ||
881 | cfg[4]); | ||
882 | iwe.u.data.length = strlen(buf); | ||
883 | current_ev = iwe_stream_add_point(info, current_ev, | ||
884 | end_buf, | ||
885 | &iwe, buf); | ||
886 | sprintf(buf, "Path Selection Metric ID: " | ||
887 | "0x%02X%02X%02X%02X", cfg[5], cfg[6], cfg[7], | ||
888 | cfg[8]); | ||
889 | iwe.u.data.length = strlen(buf); | ||
890 | current_ev = iwe_stream_add_point(info, current_ev, | ||
891 | end_buf, | ||
892 | &iwe, buf); | ||
893 | sprintf(buf, "Congestion Control Mode ID: " | ||
894 | "0x%02X%02X%02X%02X", cfg[9], cfg[10], | ||
895 | cfg[11], cfg[12]); | ||
896 | iwe.u.data.length = strlen(buf); | ||
897 | current_ev = iwe_stream_add_point(info, current_ev, | ||
898 | end_buf, | ||
899 | &iwe, buf); | ||
900 | sprintf(buf, "Channel Precedence: " | ||
901 | "0x%02X%02X%02X%02X", cfg[13], cfg[14], | ||
902 | cfg[15], cfg[16]); | ||
903 | iwe.u.data.length = strlen(buf); | ||
904 | current_ev = iwe_stream_add_point(info, current_ev, | ||
905 | end_buf, | ||
906 | &iwe, buf); | ||
907 | kfree(buf); | ||
908 | } | ||
909 | } | ||
910 | |||
911 | return current_ev; | ||
912 | } | ||
913 | |||
914 | |||
915 | int ieee80211_scan_results(struct ieee80211_local *local, | ||
916 | struct iw_request_info *info, | ||
917 | char *buf, size_t len) | ||
918 | { | ||
919 | char *current_ev = buf; | ||
920 | char *end_buf = buf + len; | ||
921 | struct ieee80211_bss *bss; | ||
922 | |||
923 | spin_lock_bh(&local->bss_lock); | ||
924 | list_for_each_entry(bss, &local->bss_list, list) { | ||
925 | if (buf + len - current_ev <= IW_EV_ADDR_LEN) { | ||
926 | spin_unlock_bh(&local->bss_lock); | ||
927 | return -E2BIG; | ||
928 | } | ||
929 | current_ev = ieee80211_scan_result(local, info, bss, | ||
930 | current_ev, end_buf); | ||
931 | } | ||
932 | spin_unlock_bh(&local->bss_lock); | ||
933 | return current_ev - buf; | ||
934 | } | ||