diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/mac80211/ieee80211_i.h | 6 | ||||
-rw-r--r-- | net/mac80211/mlme.c | 310 | ||||
-rw-r--r-- | net/mac80211/scan.c | 305 |
3 files changed, 313 insertions, 308 deletions
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 4753ed3f3f10..792c09ca08e3 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h | |||
@@ -944,6 +944,12 @@ ieee80211_bss_info_update(struct ieee80211_local *local, | |||
944 | size_t len, | 944 | size_t len, |
945 | struct ieee802_11_elems *elems, | 945 | struct ieee802_11_elems *elems, |
946 | int freq, bool beacon); | 946 | int freq, bool beacon); |
947 | struct ieee80211_sta_bss * | ||
948 | ieee80211_rx_bss_add(struct ieee80211_local *local, u8 *bssid, int freq, | ||
949 | u8 *ssid, u8 ssid_len); | ||
950 | struct ieee80211_sta_bss * | ||
951 | ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq, | ||
952 | u8 *ssid, u8 ssid_len); | ||
947 | void ieee80211_rx_bss_put(struct ieee80211_local *local, | 953 | void ieee80211_rx_bss_put(struct ieee80211_local *local, |
948 | struct ieee80211_sta_bss *bss); | 954 | struct ieee80211_sta_bss *bss); |
949 | 955 | ||
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c index 1708a3d1cd38..be3292bfabe3 100644 --- a/net/mac80211/mlme.c +++ b/net/mac80211/mlme.c | |||
@@ -11,11 +11,6 @@ | |||
11 | * published by the Free Software Foundation. | 11 | * published by the Free Software Foundation. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | /* TODO: | ||
15 | * order BSS list by RSSI(?) ("quality of AP") | ||
16 | * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE, | ||
17 | * SSID) | ||
18 | */ | ||
19 | #include <linux/delay.h> | 14 | #include <linux/delay.h> |
20 | #include <linux/if_ether.h> | 15 | #include <linux/if_ether.h> |
21 | #include <linux/skbuff.h> | 16 | #include <linux/skbuff.h> |
@@ -67,195 +62,10 @@ | |||
67 | #define IEEE80211_MIN_AMPDU_BUF 0x8 | 62 | #define IEEE80211_MIN_AMPDU_BUF 0x8 |
68 | #define IEEE80211_MAX_AMPDU_BUF 0x40 | 63 | #define IEEE80211_MAX_AMPDU_BUF 0x40 |
69 | 64 | ||
70 | /* BSS handling */ | 65 | /* utils */ |
71 | static struct ieee80211_sta_bss * | 66 | static int ecw2cw(int ecw) |
72 | ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq, | ||
73 | u8 *ssid, u8 ssid_len) | ||
74 | { | ||
75 | struct ieee80211_sta_bss *bss; | ||
76 | |||
77 | spin_lock_bh(&local->sta_bss_lock); | ||
78 | bss = local->sta_bss_hash[STA_HASH(bssid)]; | ||
79 | while (bss) { | ||
80 | if (!bss_mesh_cfg(bss) && | ||
81 | !memcmp(bss->bssid, bssid, ETH_ALEN) && | ||
82 | bss->freq == freq && | ||
83 | bss->ssid_len == ssid_len && | ||
84 | (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) { | ||
85 | atomic_inc(&bss->users); | ||
86 | break; | ||
87 | } | ||
88 | bss = bss->hnext; | ||
89 | } | ||
90 | spin_unlock_bh(&local->sta_bss_lock); | ||
91 | return bss; | ||
92 | } | ||
93 | |||
94 | /* Caller must hold local->sta_bss_lock */ | ||
95 | static void __ieee80211_rx_bss_hash_add(struct ieee80211_local *local, | ||
96 | struct ieee80211_sta_bss *bss) | ||
97 | { | ||
98 | u8 hash_idx; | ||
99 | |||
100 | if (bss_mesh_cfg(bss)) | ||
101 | hash_idx = mesh_id_hash(bss_mesh_id(bss), | ||
102 | bss_mesh_id_len(bss)); | ||
103 | else | ||
104 | hash_idx = STA_HASH(bss->bssid); | ||
105 | |||
106 | bss->hnext = local->sta_bss_hash[hash_idx]; | ||
107 | local->sta_bss_hash[hash_idx] = bss; | ||
108 | } | ||
109 | |||
110 | /* Caller must hold local->sta_bss_lock */ | ||
111 | static void __ieee80211_rx_bss_hash_del(struct ieee80211_local *local, | ||
112 | struct ieee80211_sta_bss *bss) | ||
113 | { | ||
114 | struct ieee80211_sta_bss *b, *prev = NULL; | ||
115 | b = local->sta_bss_hash[STA_HASH(bss->bssid)]; | ||
116 | while (b) { | ||
117 | if (b == bss) { | ||
118 | if (!prev) | ||
119 | local->sta_bss_hash[STA_HASH(bss->bssid)] = | ||
120 | bss->hnext; | ||
121 | else | ||
122 | prev->hnext = bss->hnext; | ||
123 | break; | ||
124 | } | ||
125 | prev = b; | ||
126 | b = b->hnext; | ||
127 | } | ||
128 | } | ||
129 | |||
130 | static struct ieee80211_sta_bss * | ||
131 | ieee80211_rx_bss_add(struct ieee80211_local *local, u8 *bssid, int freq, | ||
132 | u8 *ssid, u8 ssid_len) | ||
133 | { | ||
134 | struct ieee80211_sta_bss *bss; | ||
135 | |||
136 | bss = kzalloc(sizeof(*bss), GFP_ATOMIC); | ||
137 | if (!bss) | ||
138 | return NULL; | ||
139 | atomic_inc(&bss->users); | ||
140 | atomic_inc(&bss->users); | ||
141 | memcpy(bss->bssid, bssid, ETH_ALEN); | ||
142 | bss->freq = freq; | ||
143 | if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) { | ||
144 | memcpy(bss->ssid, ssid, ssid_len); | ||
145 | bss->ssid_len = ssid_len; | ||
146 | } | ||
147 | |||
148 | spin_lock_bh(&local->sta_bss_lock); | ||
149 | /* TODO: order by RSSI? */ | ||
150 | list_add_tail(&bss->list, &local->sta_bss_list); | ||
151 | __ieee80211_rx_bss_hash_add(local, bss); | ||
152 | spin_unlock_bh(&local->sta_bss_lock); | ||
153 | return bss; | ||
154 | } | ||
155 | |||
156 | #ifdef CONFIG_MAC80211_MESH | ||
157 | static struct ieee80211_sta_bss * | ||
158 | ieee80211_rx_mesh_bss_get(struct ieee80211_local *local, u8 *mesh_id, int mesh_id_len, | ||
159 | u8 *mesh_cfg, int freq) | ||
160 | { | ||
161 | struct ieee80211_sta_bss *bss; | ||
162 | |||
163 | spin_lock_bh(&local->sta_bss_lock); | ||
164 | bss = local->sta_bss_hash[mesh_id_hash(mesh_id, mesh_id_len)]; | ||
165 | while (bss) { | ||
166 | if (bss_mesh_cfg(bss) && | ||
167 | !memcmp(bss_mesh_cfg(bss), mesh_cfg, MESH_CFG_CMP_LEN) && | ||
168 | bss->freq == freq && | ||
169 | mesh_id_len == bss->mesh_id_len && | ||
170 | (mesh_id_len == 0 || !memcmp(bss->mesh_id, mesh_id, | ||
171 | mesh_id_len))) { | ||
172 | atomic_inc(&bss->users); | ||
173 | break; | ||
174 | } | ||
175 | bss = bss->hnext; | ||
176 | } | ||
177 | spin_unlock_bh(&local->sta_bss_lock); | ||
178 | return bss; | ||
179 | } | ||
180 | |||
181 | static struct ieee80211_sta_bss * | ||
182 | ieee80211_rx_mesh_bss_add(struct ieee80211_local *local, u8 *mesh_id, int mesh_id_len, | ||
183 | u8 *mesh_cfg, int mesh_config_len, int freq) | ||
184 | { | ||
185 | struct ieee80211_sta_bss *bss; | ||
186 | |||
187 | if (mesh_config_len != MESH_CFG_LEN) | ||
188 | return NULL; | ||
189 | |||
190 | bss = kzalloc(sizeof(*bss), GFP_ATOMIC); | ||
191 | if (!bss) | ||
192 | return NULL; | ||
193 | |||
194 | bss->mesh_cfg = kmalloc(MESH_CFG_CMP_LEN, GFP_ATOMIC); | ||
195 | if (!bss->mesh_cfg) { | ||
196 | kfree(bss); | ||
197 | return NULL; | ||
198 | } | ||
199 | |||
200 | if (mesh_id_len && mesh_id_len <= IEEE80211_MAX_MESH_ID_LEN) { | ||
201 | bss->mesh_id = kmalloc(mesh_id_len, GFP_ATOMIC); | ||
202 | if (!bss->mesh_id) { | ||
203 | kfree(bss->mesh_cfg); | ||
204 | kfree(bss); | ||
205 | return NULL; | ||
206 | } | ||
207 | memcpy(bss->mesh_id, mesh_id, mesh_id_len); | ||
208 | } | ||
209 | |||
210 | atomic_inc(&bss->users); | ||
211 | atomic_inc(&bss->users); | ||
212 | memcpy(bss->mesh_cfg, mesh_cfg, MESH_CFG_CMP_LEN); | ||
213 | bss->mesh_id_len = mesh_id_len; | ||
214 | bss->freq = freq; | ||
215 | spin_lock_bh(&local->sta_bss_lock); | ||
216 | /* TODO: order by RSSI? */ | ||
217 | list_add_tail(&bss->list, &local->sta_bss_list); | ||
218 | __ieee80211_rx_bss_hash_add(local, bss); | ||
219 | spin_unlock_bh(&local->sta_bss_lock); | ||
220 | return bss; | ||
221 | } | ||
222 | #endif | ||
223 | |||
224 | static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss) | ||
225 | { | ||
226 | kfree(bss->ies); | ||
227 | kfree(bss_mesh_id(bss)); | ||
228 | kfree(bss_mesh_cfg(bss)); | ||
229 | kfree(bss); | ||
230 | } | ||
231 | |||
232 | void ieee80211_rx_bss_put(struct ieee80211_local *local, | ||
233 | struct ieee80211_sta_bss *bss) | ||
234 | { | ||
235 | local_bh_disable(); | ||
236 | if (!atomic_dec_and_lock(&bss->users, &local->sta_bss_lock)) { | ||
237 | local_bh_enable(); | ||
238 | return; | ||
239 | } | ||
240 | |||
241 | __ieee80211_rx_bss_hash_del(local, bss); | ||
242 | list_del(&bss->list); | ||
243 | spin_unlock_bh(&local->sta_bss_lock); | ||
244 | ieee80211_rx_bss_free(bss); | ||
245 | } | ||
246 | |||
247 | void ieee80211_rx_bss_list_init(struct ieee80211_local *local) | ||
248 | { | ||
249 | spin_lock_init(&local->sta_bss_lock); | ||
250 | INIT_LIST_HEAD(&local->sta_bss_list); | ||
251 | } | ||
252 | |||
253 | void ieee80211_rx_bss_list_deinit(struct ieee80211_local *local) | ||
254 | { | 67 | { |
255 | struct ieee80211_sta_bss *bss, *tmp; | 68 | return (1 << ecw) - 1; |
256 | |||
257 | list_for_each_entry_safe(bss, tmp, &local->sta_bss_list, list) | ||
258 | ieee80211_rx_bss_put(local, bss); | ||
259 | } | 69 | } |
260 | 70 | ||
261 | static u8 *ieee80211_bss_get_ie(struct ieee80211_sta_bss *bss, u8 ie) | 71 | static u8 *ieee80211_bss_get_ie(struct ieee80211_sta_bss *bss, u8 ie) |
@@ -278,12 +88,6 @@ static u8 *ieee80211_bss_get_ie(struct ieee80211_sta_bss *bss, u8 ie) | |||
278 | return NULL; | 88 | return NULL; |
279 | } | 89 | } |
280 | 90 | ||
281 | /* utils */ | ||
282 | static int ecw2cw(int ecw) | ||
283 | { | ||
284 | return (1 << ecw) - 1; | ||
285 | } | ||
286 | |||
287 | /* frame sending functions */ | 91 | /* frame sending functions */ |
288 | void ieee80211_sta_tx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, | 92 | void ieee80211_sta_tx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, |
289 | int encrypt) | 93 | int encrypt) |
@@ -2442,114 +2246,6 @@ static u64 ieee80211_sta_get_mandatory_rates(struct ieee80211_local *local, | |||
2442 | return mandatory_rates; | 2246 | return mandatory_rates; |
2443 | } | 2247 | } |
2444 | 2248 | ||
2445 | struct ieee80211_sta_bss * | ||
2446 | ieee80211_bss_info_update(struct ieee80211_local *local, | ||
2447 | struct ieee80211_rx_status *rx_status, | ||
2448 | struct ieee80211_mgmt *mgmt, | ||
2449 | size_t len, | ||
2450 | struct ieee802_11_elems *elems, | ||
2451 | int freq, bool beacon) | ||
2452 | { | ||
2453 | struct ieee80211_sta_bss *bss; | ||
2454 | int clen; | ||
2455 | |||
2456 | #ifdef CONFIG_MAC80211_MESH | ||
2457 | if (elems->mesh_config) | ||
2458 | bss = ieee80211_rx_mesh_bss_get(local, elems->mesh_id, | ||
2459 | elems->mesh_id_len, elems->mesh_config, freq); | ||
2460 | else | ||
2461 | #endif | ||
2462 | bss = ieee80211_rx_bss_get(local, mgmt->bssid, freq, | ||
2463 | elems->ssid, elems->ssid_len); | ||
2464 | if (!bss) { | ||
2465 | #ifdef CONFIG_MAC80211_MESH | ||
2466 | if (elems->mesh_config) | ||
2467 | bss = ieee80211_rx_mesh_bss_add(local, elems->mesh_id, | ||
2468 | elems->mesh_id_len, elems->mesh_config, | ||
2469 | elems->mesh_config_len, freq); | ||
2470 | else | ||
2471 | #endif | ||
2472 | bss = ieee80211_rx_bss_add(local, mgmt->bssid, freq, | ||
2473 | elems->ssid, elems->ssid_len); | ||
2474 | if (!bss) | ||
2475 | return NULL; | ||
2476 | } else { | ||
2477 | #if 0 | ||
2478 | /* TODO: order by RSSI? */ | ||
2479 | spin_lock_bh(&local->sta_bss_lock); | ||
2480 | list_move_tail(&bss->list, &local->sta_bss_list); | ||
2481 | spin_unlock_bh(&local->sta_bss_lock); | ||
2482 | #endif | ||
2483 | } | ||
2484 | |||
2485 | /* save the ERP value so that it is available at association time */ | ||
2486 | if (elems->erp_info && elems->erp_info_len >= 1) { | ||
2487 | bss->erp_value = elems->erp_info[0]; | ||
2488 | bss->has_erp_value = 1; | ||
2489 | } | ||
2490 | |||
2491 | bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int); | ||
2492 | bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info); | ||
2493 | |||
2494 | if (elems->tim) { | ||
2495 | struct ieee80211_tim_ie *tim_ie = | ||
2496 | (struct ieee80211_tim_ie *)elems->tim; | ||
2497 | bss->dtim_period = tim_ie->dtim_period; | ||
2498 | } | ||
2499 | |||
2500 | /* set default value for buggy APs */ | ||
2501 | if (!elems->tim || bss->dtim_period == 0) | ||
2502 | bss->dtim_period = 1; | ||
2503 | |||
2504 | bss->supp_rates_len = 0; | ||
2505 | if (elems->supp_rates) { | ||
2506 | clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; | ||
2507 | if (clen > elems->supp_rates_len) | ||
2508 | clen = elems->supp_rates_len; | ||
2509 | memcpy(&bss->supp_rates[bss->supp_rates_len], elems->supp_rates, | ||
2510 | clen); | ||
2511 | bss->supp_rates_len += clen; | ||
2512 | } | ||
2513 | if (elems->ext_supp_rates) { | ||
2514 | clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; | ||
2515 | if (clen > elems->ext_supp_rates_len) | ||
2516 | clen = elems->ext_supp_rates_len; | ||
2517 | memcpy(&bss->supp_rates[bss->supp_rates_len], | ||
2518 | elems->ext_supp_rates, clen); | ||
2519 | bss->supp_rates_len += clen; | ||
2520 | } | ||
2521 | |||
2522 | bss->band = rx_status->band; | ||
2523 | |||
2524 | bss->timestamp = le64_to_cpu(mgmt->u.beacon.timestamp); | ||
2525 | bss->last_update = jiffies; | ||
2526 | bss->signal = rx_status->signal; | ||
2527 | bss->noise = rx_status->noise; | ||
2528 | bss->qual = rx_status->qual; | ||
2529 | bss->wmm_used = elems->wmm_param || elems->wmm_info; | ||
2530 | |||
2531 | if (!beacon) | ||
2532 | bss->last_probe_resp = jiffies; | ||
2533 | |||
2534 | /* | ||
2535 | * For probe responses, or if we don't have any information yet, | ||
2536 | * use the IEs from the beacon. | ||
2537 | */ | ||
2538 | if (!bss->ies || !beacon) { | ||
2539 | if (bss->ies == NULL || bss->ies_len < elems->total_len) { | ||
2540 | kfree(bss->ies); | ||
2541 | bss->ies = kmalloc(elems->total_len, GFP_ATOMIC); | ||
2542 | } | ||
2543 | if (bss->ies) { | ||
2544 | memcpy(bss->ies, elems->ie_start, elems->total_len); | ||
2545 | bss->ies_len = elems->total_len; | ||
2546 | } else | ||
2547 | bss->ies_len = 0; | ||
2548 | } | ||
2549 | |||
2550 | return bss; | ||
2551 | } | ||
2552 | |||
2553 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, | 2249 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, |
2554 | struct ieee80211_mgmt *mgmt, | 2250 | struct ieee80211_mgmt *mgmt, |
2555 | size_t len, | 2251 | size_t len, |
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c index 2848ba3a08e3..1beefb5ad6fb 100644 --- a/net/mac80211/scan.c +++ b/net/mac80211/scan.c | |||
@@ -1,5 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * BSS client mode implementation | 2 | * Scanning implementation |
3 | * | ||
3 | * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi> | 4 | * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi> |
4 | * Copyright 2004, Instant802 Networks, Inc. | 5 | * Copyright 2004, Instant802 Networks, Inc. |
5 | * Copyright 2005, Devicescape Software, Inc. | 6 | * Copyright 2005, Devicescape Software, Inc. |
@@ -11,17 +12,319 @@ | |||
11 | * published by the Free Software Foundation. | 12 | * published by the Free Software Foundation. |
12 | */ | 13 | */ |
13 | 14 | ||
15 | /* TODO: | ||
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 | |||
14 | #include <linux/wireless.h> | 21 | #include <linux/wireless.h> |
15 | #include <linux/if_arp.h> | 22 | #include <linux/if_arp.h> |
16 | #include <net/mac80211.h> | 23 | #include <net/mac80211.h> |
17 | #include <net/iw_handler.h> | 24 | #include <net/iw_handler.h> |
18 | 25 | ||
19 | #include "ieee80211_i.h" | 26 | #include "ieee80211_i.h" |
27 | #include "mesh.h" | ||
20 | 28 | ||
21 | #define IEEE80211_PROBE_DELAY (HZ / 33) | 29 | #define IEEE80211_PROBE_DELAY (HZ / 33) |
22 | #define IEEE80211_CHANNEL_TIME (HZ / 33) | 30 | #define IEEE80211_CHANNEL_TIME (HZ / 33) |
23 | #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5) | 31 | #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5) |
24 | 32 | ||
33 | void ieee80211_rx_bss_list_init(struct ieee80211_local *local) | ||
34 | { | ||
35 | spin_lock_init(&local->sta_bss_lock); | ||
36 | INIT_LIST_HEAD(&local->sta_bss_list); | ||
37 | } | ||
38 | |||
39 | void ieee80211_rx_bss_list_deinit(struct ieee80211_local *local) | ||
40 | { | ||
41 | struct ieee80211_sta_bss *bss, *tmp; | ||
42 | |||
43 | list_for_each_entry_safe(bss, tmp, &local->sta_bss_list, list) | ||
44 | ieee80211_rx_bss_put(local, bss); | ||
45 | } | ||
46 | |||
47 | struct ieee80211_sta_bss * | ||
48 | ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq, | ||
49 | u8 *ssid, u8 ssid_len) | ||
50 | { | ||
51 | struct ieee80211_sta_bss *bss; | ||
52 | |||
53 | spin_lock_bh(&local->sta_bss_lock); | ||
54 | bss = local->sta_bss_hash[STA_HASH(bssid)]; | ||
55 | while (bss) { | ||
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->sta_bss_lock); | ||
67 | return bss; | ||
68 | } | ||
69 | |||
70 | /* Caller must hold local->sta_bss_lock */ | ||
71 | static void __ieee80211_rx_bss_hash_add(struct ieee80211_local *local, | ||
72 | struct ieee80211_sta_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->sta_bss_hash[hash_idx]; | ||
83 | local->sta_bss_hash[hash_idx] = bss; | ||
84 | } | ||
85 | |||
86 | /* Caller must hold local->sta_bss_lock */ | ||
87 | static void __ieee80211_rx_bss_hash_del(struct ieee80211_local *local, | ||
88 | struct ieee80211_sta_bss *bss) | ||
89 | { | ||
90 | struct ieee80211_sta_bss *b, *prev = NULL; | ||
91 | b = local->sta_bss_hash[STA_HASH(bss->bssid)]; | ||
92 | while (b) { | ||
93 | if (b == bss) { | ||
94 | if (!prev) | ||
95 | local->sta_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_sta_bss * | ||
107 | ieee80211_rx_bss_add(struct ieee80211_local *local, u8 *bssid, int freq, | ||
108 | u8 *ssid, u8 ssid_len) | ||
109 | { | ||
110 | struct ieee80211_sta_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->sta_bss_lock); | ||
124 | /* TODO: order by RSSI? */ | ||
125 | list_add_tail(&bss->list, &local->sta_bss_list); | ||
126 | __ieee80211_rx_bss_hash_add(local, bss); | ||
127 | spin_unlock_bh(&local->sta_bss_lock); | ||
128 | return bss; | ||
129 | } | ||
130 | |||
131 | #ifdef CONFIG_MAC80211_MESH | ||
132 | static struct ieee80211_sta_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_sta_bss *bss; | ||
137 | |||
138 | spin_lock_bh(&local->sta_bss_lock); | ||
139 | bss = local->sta_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->sta_bss_lock); | ||
153 | return bss; | ||
154 | } | ||
155 | |||
156 | static struct ieee80211_sta_bss * | ||
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 | { | ||
160 | struct ieee80211_sta_bss *bss; | ||
161 | |||
162 | if (mesh_config_len != MESH_CFG_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->sta_bss_lock); | ||
190 | /* TODO: order by RSSI? */ | ||
191 | list_add_tail(&bss->list, &local->sta_bss_list); | ||
192 | __ieee80211_rx_bss_hash_add(local, bss); | ||
193 | spin_unlock_bh(&local->sta_bss_lock); | ||
194 | return bss; | ||
195 | } | ||
196 | #endif | ||
197 | |||
198 | static void ieee80211_rx_bss_free(struct ieee80211_sta_bss *bss) | ||
199 | { | ||
200 | kfree(bss->ies); | ||
201 | kfree(bss_mesh_id(bss)); | ||
202 | kfree(bss_mesh_cfg(bss)); | ||
203 | kfree(bss); | ||
204 | } | ||
205 | |||
206 | void ieee80211_rx_bss_put(struct ieee80211_local *local, | ||
207 | struct ieee80211_sta_bss *bss) | ||
208 | { | ||
209 | local_bh_disable(); | ||
210 | if (!atomic_dec_and_lock(&bss->users, &local->sta_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->sta_bss_lock); | ||
218 | ieee80211_rx_bss_free(bss); | ||
219 | } | ||
220 | |||
221 | struct ieee80211_sta_bss * | ||
222 | ieee80211_bss_info_update(struct ieee80211_local *local, | ||
223 | struct ieee80211_rx_status *rx_status, | ||
224 | struct ieee80211_mgmt *mgmt, | ||
225 | size_t len, | ||
226 | struct ieee802_11_elems *elems, | ||
227 | int freq, bool beacon) | ||
228 | { | ||
229 | struct ieee80211_sta_bss *bss; | ||
230 | int clen; | ||
231 | |||
232 | #ifdef CONFIG_MAC80211_MESH | ||
233 | if (elems->mesh_config) | ||
234 | bss = ieee80211_rx_mesh_bss_get(local, elems->mesh_id, | ||
235 | elems->mesh_id_len, elems->mesh_config, freq); | ||
236 | else | ||
237 | #endif | ||
238 | bss = ieee80211_rx_bss_get(local, mgmt->bssid, freq, | ||
239 | elems->ssid, elems->ssid_len); | ||
240 | if (!bss) { | ||
241 | #ifdef CONFIG_MAC80211_MESH | ||
242 | if (elems->mesh_config) | ||
243 | bss = ieee80211_rx_mesh_bss_add(local, elems->mesh_id, | ||
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->sta_bss_lock); | ||
256 | list_move_tail(&bss->list, &local->sta_bss_list); | ||
257 | spin_unlock_bh(&local->sta_bss_lock); | ||
258 | #endif | ||
259 | } | ||
260 | |||
261 | /* save the ERP value so that it is available at association time */ | ||
262 | if (elems->erp_info && elems->erp_info_len >= 1) { | ||
263 | bss->erp_value = elems->erp_info[0]; | ||
264 | bss->has_erp_value = 1; | ||
265 | } | ||
266 | |||
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) { | ||
271 | struct ieee80211_tim_ie *tim_ie = | ||
272 | (struct ieee80211_tim_ie *)elems->tim; | ||
273 | bss->dtim_period = tim_ie->dtim_period; | ||
274 | } | ||
275 | |||
276 | /* set default value for buggy APs */ | ||
277 | if (!elems->tim || bss->dtim_period == 0) | ||
278 | bss->dtim_period = 1; | ||
279 | |||
280 | bss->supp_rates_len = 0; | ||
281 | if (elems->supp_rates) { | ||
282 | clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; | ||
283 | if (clen > elems->supp_rates_len) | ||
284 | clen = elems->supp_rates_len; | ||
285 | memcpy(&bss->supp_rates[bss->supp_rates_len], elems->supp_rates, | ||
286 | clen); | ||
287 | bss->supp_rates_len += clen; | ||
288 | } | ||
289 | if (elems->ext_supp_rates) { | ||
290 | clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; | ||
291 | if (clen > elems->ext_supp_rates_len) | ||
292 | clen = elems->ext_supp_rates_len; | ||
293 | memcpy(&bss->supp_rates[bss->supp_rates_len], | ||
294 | elems->ext_supp_rates, clen); | ||
295 | bss->supp_rates_len += clen; | ||
296 | } | ||
297 | |||
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; | ||
306 | |||
307 | if (!beacon) | ||
308 | bss->last_probe_resp = jiffies; | ||
309 | |||
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; | ||
327 | } | ||
25 | 328 | ||
26 | ieee80211_rx_result | 329 | ieee80211_rx_result |
27 | ieee80211_sta_rx_scan(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, | 330 | ieee80211_sta_rx_scan(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, |