diff options
author | Johannes Berg <johannes@sipsolutions.net> | 2008-09-08 11:44:27 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2008-09-11 15:53:37 -0400 |
commit | 5484e23749e78d5a4f56928efaf3c4b0d862b7a6 (patch) | |
tree | ccfcde072487419d0bf32a88bc8314380d17f1bf /net/mac80211/mlme.c | |
parent | 98c8fccfaea838e62ffde2f2e44568844e0e5472 (diff) |
mac80211: move BSS handling to scan code
This moves all the BSS list handling out of mlme.c to scan.c,
no further changes except fixing kzalloc/atomic_inc/atomic_inc
to kzalloc/atomic_set(2).
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'net/mac80211/mlme.c')
-rw-r--r-- | net/mac80211/mlme.c | 310 |
1 files changed, 3 insertions, 307 deletions
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, |