diff options
author | Johannes Berg <johannes@sipsolutions.net> | 2009-02-10 15:26:00 -0500 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2009-02-13 13:45:58 -0500 |
commit | 00d3f14cf9f12c21428121026a5e1d5f65926447 (patch) | |
tree | e5f355deef7b9ebb5b3bf65f9d589bd2a1cfbafa /net/mac80211/scan.c | |
parent | 79420f09e76e8e1dd1149d6ce9c20e06cbb5802a (diff) |
mac80211: use cfg80211s BSS infrastructure
Remove all the code from mac80211 to keep track of BSSes
and use the cfg80211-provided code completely.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'net/mac80211/scan.c')
-rw-r--r-- | net/mac80211/scan.c | 253 |
1 files changed, 18 insertions, 235 deletions
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c index fc88e2e2f923..f883ab9f1e6e 100644 --- a/net/mac80211/scan.c +++ b/net/mac80211/scan.c | |||
@@ -12,10 +12,7 @@ | |||
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 | * figure out how to avoid that the "current BSS" expires | ||
17 | * use cfg80211's BSS handling | ||
18 | */ | ||
19 | 16 | ||
20 | #include <linux/wireless.h> | 17 | #include <linux/wireless.h> |
21 | #include <linux/if_arp.h> | 18 | #include <linux/if_arp.h> |
@@ -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 | static 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 * |
@@ -228,7 +62,7 @@ ieee80211_bss_info_update(struct ieee80211_local *local, | |||
228 | bool beacon) | 62 | bool beacon) |
229 | { | 63 | { |
230 | struct ieee80211_bss *bss; | 64 | struct ieee80211_bss *bss; |
231 | int clen, freq = channel->center_freq; | 65 | int clen; |
232 | enum cfg80211_signal_type sigtype = CFG80211_SIGNAL_TYPE_NONE; | 66 | enum cfg80211_signal_type sigtype = CFG80211_SIGNAL_TYPE_NONE; |
233 | s32 signal = 0; | 67 | s32 signal = 0; |
234 | 68 | ||
@@ -240,39 +74,14 @@ ieee80211_bss_info_update(struct ieee80211_local *local, | |||
240 | signal = (rx_status->signal * 100) / local->hw.max_signal; | 74 | signal = (rx_status->signal * 100) / local->hw.max_signal; |
241 | } | 75 | } |
242 | 76 | ||
243 | cfg80211_put_bss( | 77 | bss = (void *)cfg80211_inform_bss_frame(local->hw.wiphy, channel, |
244 | cfg80211_inform_bss_frame(local->hw.wiphy, channel, | 78 | mgmt, len, signal, sigtype, |
245 | mgmt, len, signal, sigtype, | 79 | GFP_ATOMIC); |
246 | GFP_ATOMIC)); | ||
247 | 80 | ||
248 | #ifdef CONFIG_MAC80211_MESH | 81 | if (!bss) |
249 | if (elems->mesh_config) | 82 | return NULL; |
250 | bss = ieee80211_rx_mesh_bss_get(local, elems->mesh_id, | 83 | |
251 | elems->mesh_id_len, elems->mesh_config, freq); | 84 | bss->cbss.free_priv = ieee80211_rx_bss_free; |
252 | else | ||
253 | #endif | ||
254 | bss = ieee80211_rx_bss_get(local, mgmt->bssid, freq, | ||
255 | elems->ssid, elems->ssid_len); | ||
256 | if (!bss) { | ||
257 | #ifdef CONFIG_MAC80211_MESH | ||
258 | if (elems->mesh_config) | ||
259 | bss = ieee80211_rx_mesh_bss_add(local, elems->mesh_id, | ||
260 | elems->mesh_id_len, elems->mesh_config, | ||
261 | elems->mesh_config_len, freq); | ||
262 | else | ||
263 | #endif | ||
264 | bss = ieee80211_rx_bss_add(local, mgmt->bssid, freq, | ||
265 | elems->ssid, elems->ssid_len); | ||
266 | if (!bss) | ||
267 | return NULL; | ||
268 | } else { | ||
269 | #if 0 | ||
270 | /* TODO: order by RSSI? */ | ||
271 | spin_lock_bh(&local->bss_lock); | ||
272 | list_move_tail(&bss->list, &local->bss_list); | ||
273 | spin_unlock_bh(&local->bss_lock); | ||
274 | #endif | ||
275 | } | ||
276 | 85 | ||
277 | /* save the ERP value so that it is available at association time */ | 86 | /* save the ERP value so that it is available at association time */ |
278 | if (elems->erp_info && elems->erp_info_len >= 1) { | 87 | if (elems->erp_info && elems->erp_info_len >= 1) { |
@@ -280,9 +89,6 @@ ieee80211_bss_info_update(struct ieee80211_local *local, | |||
280 | bss->has_erp_value = 1; | 89 | bss->has_erp_value = 1; |
281 | } | 90 | } |
282 | 91 | ||
283 | bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int); | ||
284 | bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info); | ||
285 | |||
286 | if (elems->tim) { | 92 | if (elems->tim) { |
287 | struct ieee80211_tim_ie *tim_ie = | 93 | struct ieee80211_tim_ie *tim_ie = |
288 | (struct ieee80211_tim_ie *)elems->tim; | 94 | (struct ieee80211_tim_ie *)elems->tim; |
@@ -311,34 +117,11 @@ ieee80211_bss_info_update(struct ieee80211_local *local, | |||
311 | bss->supp_rates_len += clen; | 117 | bss->supp_rates_len += clen; |
312 | } | 118 | } |
313 | 119 | ||
314 | bss->band = rx_status->band; | ||
315 | |||
316 | bss->timestamp = le64_to_cpu(mgmt->u.beacon.timestamp); | ||
317 | bss->last_update = jiffies; | ||
318 | bss->signal = rx_status->signal; | ||
319 | bss->noise = rx_status->noise; | ||
320 | bss->qual = rx_status->qual; | ||
321 | bss->wmm_used = elems->wmm_param || elems->wmm_info; | 120 | bss->wmm_used = elems->wmm_param || elems->wmm_info; |
322 | 121 | ||
323 | if (!beacon) | 122 | if (!beacon) |
324 | bss->last_probe_resp = jiffies; | 123 | bss->last_probe_resp = jiffies; |
325 | 124 | ||
326 | /* | ||
327 | * For probe responses, or if we don't have any information yet, | ||
328 | * use the IEs from the beacon. | ||
329 | */ | ||
330 | if (!bss->ies || !beacon) { | ||
331 | if (bss->ies == NULL || bss->ies_len < elems->total_len) { | ||
332 | kfree(bss->ies); | ||
333 | bss->ies = kmalloc(elems->total_len, GFP_ATOMIC); | ||
334 | } | ||
335 | if (bss->ies) { | ||
336 | memcpy(bss->ies, elems->ie_start, elems->total_len); | ||
337 | bss->ies_len = elems->total_len; | ||
338 | } else | ||
339 | bss->ies_len = 0; | ||
340 | } | ||
341 | |||
342 | return bss; | 125 | return bss; |
343 | } | 126 | } |
344 | 127 | ||
@@ -350,7 +133,7 @@ void ieee80211_rx_bss_remove(struct ieee80211_sub_if_data *sdata, u8 *bssid, | |||
350 | 133 | ||
351 | bss = ieee80211_rx_bss_get(local, bssid, freq, ssid, ssid_len); | 134 | bss = ieee80211_rx_bss_get(local, bssid, freq, ssid, ssid_len); |
352 | if (bss) { | 135 | if (bss) { |
353 | atomic_dec(&bss->users); | 136 | cfg80211_unlink_bss(local->hw.wiphy, (void *)bss); |
354 | ieee80211_rx_bss_put(local, bss); | 137 | ieee80211_rx_bss_put(local, bss); |
355 | } | 138 | } |
356 | } | 139 | } |