1 #include "ieee80211softmac_priv.h"
6 * Before you can associate, you have to authenticate.
10 /* Sends out an association request to the desired AP */
12 ieee80211softmac_assoc(struct ieee80211softmac_device
*mac
, struct ieee80211softmac_network
*net
)
16 /* Switch to correct channel for this network */
17 mac
->set_channel(mac
->dev
, net
->channel
);
19 /* Send association request */
20 ieee80211softmac_send_mgt_frame(mac
, net
, IEEE80211_STYPE_ASSOC_REQ
, 0);
22 dprintk(KERN_INFO PFX
"sent association request!\n");
24 /* Change the state to associating */
25 spin_lock_irqsave(&mac
->lock
, flags
);
26 mac
->associnfo
.associating
= 1;
27 mac
->associated
= 0; /* just to make sure */
28 spin_unlock_irqrestore(&mac
->lock
, flags
);
30 /* Set a timer for timeout */
31 /* FIXME: make timeout configurable */
32 queue_delayed_work(mac
->workqueue
, &mac
->associnfo
.timeout
, 5 * HZ
);
36 ieee80211softmac_assoc_timeout(void *d
)
38 struct ieee80211softmac_device
*mac
= (struct ieee80211softmac_device
*)d
;
43 spin_lock_irqsave(&mac
->lock
, flags
);
44 /* we might race against ieee80211softmac_handle_assoc_response,
45 * so make sure only one of us does something */
46 if (!mac
->associnfo
.associating
) {
47 spin_unlock_irqrestore(&mac
->lock
, flags
);
50 mac
->associnfo
.associating
= 0;
51 mac
->associnfo
.bssvalid
= 0;
53 spin_unlock_irqrestore(&mac
->lock
, flags
);
55 dprintk(KERN_INFO PFX
"assoc request timed out!\n");
56 /* FIXME: we need to know the network here. that requires a bit of restructuring */
57 ieee80211softmac_call_events(mac
, IEEE80211SOFTMAC_EVENT_ASSOCIATE_TIMEOUT
, NULL
);
61 ieee80211softmac_reassoc(struct ieee80211softmac_device
*mac
)
67 /* Sends out a disassociation request to the desired AP */
69 ieee80211softmac_disassoc(struct ieee80211softmac_device
*mac
, u16 reason
)
72 struct ieee80211softmac_network
*found
;
75 if (mac
->associnfo
.bssvalid
&& mac
->associated
) {
76 found
= ieee80211softmac_get_network_by_bssid(mac
, mac
->associnfo
.bssid
);
78 ieee80211softmac_send_mgt_frame(mac
, found
, IEEE80211_STYPE_DISASSOC
, reason
);
79 } else if (mac
->associnfo
.associating
) {
80 cancel_delayed_work(&mac
->associnfo
.timeout
);
83 /* Change our state */
84 spin_lock_irqsave(&mac
->lock
, flags
);
85 /* Do NOT clear bssvalid as that will break ieee80211softmac_assoc_work! */
87 mac
->associnfo
.associating
= 0;
88 spin_unlock_irqrestore(&mac
->lock
, flags
);
92 we_support_all_basic_rates(struct ieee80211softmac_device
*mac
, u8
*from
, u8 from_len
)
94 int idx
, search
, found
;
97 for (idx
= 0; idx
< (from_len
); idx
++) {
99 if (!(rate
& IEEE80211_BASIC_RATE_MASK
))
102 rate
&= ~IEEE80211_BASIC_RATE_MASK
;
103 for (search
= 0; search
< mac
->ratesinfo
.count
; search
++) {
104 search_rate
= mac
->ratesinfo
.rates
[search
];
105 search_rate
&= ~IEEE80211_BASIC_RATE_MASK
;
106 if (rate
== search_rate
) {
118 network_matches_request(struct ieee80211softmac_device
*mac
, struct ieee80211_network
*net
)
120 /* we cannot associate to networks whose name we don't know */
121 if (ieee80211_is_empty_essid(net
->ssid
, net
->ssid_len
))
123 /* do not associate to a network whose BSSBasicRateSet we cannot support */
124 if (!we_support_all_basic_rates(mac
, net
->rates
, net
->rates_len
))
126 /* do we really need to check the ex rates? */
127 if (!we_support_all_basic_rates(mac
, net
->rates_ex
, net
->rates_ex_len
))
130 /* if 'ANY' network requested, take any that doesn't have privacy enabled */
131 if (mac
->associnfo
.req_essid
.len
== 0
132 && !(net
->capability
& WLAN_CAPABILITY_PRIVACY
))
134 if (net
->ssid_len
!= mac
->associnfo
.req_essid
.len
)
136 if (!memcmp(net
->ssid
, mac
->associnfo
.req_essid
.data
, mac
->associnfo
.req_essid
.len
))
142 ieee80211softmac_assoc_notify(struct net_device
*dev
, void *context
)
144 struct ieee80211softmac_device
*mac
= ieee80211_priv(dev
);
145 ieee80211softmac_assoc_work((void*)mac
);
148 /* This function is called to handle userspace requests (asynchronously) */
150 ieee80211softmac_assoc_work(void *d
)
152 struct ieee80211softmac_device
*mac
= (struct ieee80211softmac_device
*)d
;
153 struct ieee80211softmac_network
*found
= NULL
;
154 struct ieee80211_network
*net
= NULL
, *best
= NULL
;
161 ieee80211softmac_disassoc(mac
, WLAN_REASON_DISASSOC_STA_HAS_LEFT
);
163 /* try to find the requested network in our list, if we found one already */
164 if (mac
->associnfo
.bssvalid
)
165 found
= ieee80211softmac_get_network_by_bssid(mac
, mac
->associnfo
.bssid
);
167 /* Search the ieee80211 networks for this network if we didn't find it */
170 spin_lock_irqsave(&mac
->ieee
->lock
, flags
);
171 list_for_each_entry(net
, &mac
->ieee
->network_list
, list
) {
172 /* we're supposed to find the network with
173 * the best signal here, as we're asked to join
174 * any network with a specific ESSID, and many
175 * different ones could have that.
177 * I'll for now implement just finding one at all
179 * We also should take into account the rateset
180 * here to find the best BSSID to try.
182 if (network_matches_request(mac
, net
)) {
187 /* we already had a matching network, so
188 * compare their properties to get the
189 * better of the two ... (see above)
196 /* if we unlock here, we might get interrupted and the `best'
197 * pointer could go stale */
199 found
= ieee80211softmac_create_network(mac
, best
);
200 /* if found is still NULL, then we got -ENOMEM somewhere */
202 ieee80211softmac_add_network(mac
, found
);
204 spin_unlock_irqrestore(&mac
->ieee
->lock
, flags
);
208 if (mac
->associnfo
.scan_retry
> 0) {
209 spin_lock_irqsave(&mac
->lock
, flags
);
210 mac
->associnfo
.scan_retry
--;
211 spin_unlock_irqrestore(&mac
->lock
, flags
);
213 /* We know of no such network. Let's scan.
214 * NB: this also happens if we had no memory to copy the network info...
215 * Maybe we can hope to have more memory after scanning finishes ;)
217 dprintk(KERN_INFO PFX
"Associate: Network not known, trying to initiate scan: ");
218 ieee80211softmac_notify(mac
->dev
, IEEE80211SOFTMAC_EVENT_SCAN_FINISHED
, ieee80211softmac_assoc_notify
, NULL
);
219 if (ieee80211softmac_start_scan(mac
))
220 dprintk("failed.\n");
226 spin_lock_irqsave(&mac
->lock
, flags
);
227 mac
->associnfo
.associating
= 0;
229 spin_unlock_irqrestore(&mac
->lock
, flags
);
231 dprintk(KERN_INFO PFX
"Unable to find network after scan!\n");
232 ieee80211softmac_call_events(mac
, IEEE80211SOFTMAC_EVENT_ASSOCIATE_NET_NOT_FOUND
, NULL
);
237 mac
->associnfo
.bssvalid
= 1;
238 memcpy(mac
->associnfo
.bssid
, found
->bssid
, ETH_ALEN
);
239 /* copy the ESSID for displaying it */
240 mac
->associnfo
.associate_essid
.len
= found
->essid
.len
;
241 memcpy(mac
->associnfo
.associate_essid
.data
, found
->essid
.data
, IW_ESSID_MAX_SIZE
+ 1);
243 /* we found a network! authenticate (if necessary) and associate to it. */
244 if (!found
->authenticated
) {
245 /* This relies on the fact that _auth_req only queues the work,
246 * otherwise adding the notification would be racy. */
247 if (!ieee80211softmac_auth_req(mac
, found
)) {
248 dprintk(KERN_INFO PFX
"cannot associate without being authenticated, requested authentication\n");
249 ieee80211softmac_notify_internal(mac
, IEEE80211SOFTMAC_EVENT_ANY
, found
, ieee80211softmac_assoc_notify
, NULL
, GFP_KERNEL
);
251 printkl(KERN_WARNING PFX
"Not authenticated, but requesting authentication failed. Giving up to associate\n");
252 ieee80211softmac_call_events(mac
, IEEE80211SOFTMAC_EVENT_ASSOCIATE_FAILED
, found
);
256 /* finally! now we can start associating */
257 ieee80211softmac_assoc(mac
, found
);
260 /* call this to do whatever is necessary when we're associated */
262 ieee80211softmac_associated(struct ieee80211softmac_device
*mac
,
263 struct ieee80211_assoc_response
* resp
,
264 struct ieee80211softmac_network
*net
)
266 mac
->associnfo
.associating
= 0;
268 if (mac
->set_bssid_filter
)
269 mac
->set_bssid_filter(mac
->dev
, net
->bssid
);
270 memcpy(mac
->ieee
->bssid
, net
->bssid
, ETH_ALEN
);
271 mac
->dev
->flags
|= IFF_RUNNING
;
273 mac
->association_id
= le16_to_cpup(&resp
->aid
);
276 /* received frame handling functions */
278 ieee80211softmac_handle_assoc_response(struct net_device
* dev
,
279 struct ieee80211_assoc_response
* resp
,
280 struct ieee80211_network
* _ieee80211_network_do_not_use
)
282 /* NOTE: the network parameter has to be ignored by
283 * this code because it is the ieee80211's pointer
284 * to the struct, not ours (we made a copy)
286 struct ieee80211softmac_device
*mac
= ieee80211_priv(dev
);
287 u16 status
= le16_to_cpup(&resp
->status
);
288 struct ieee80211softmac_network
*network
= NULL
;
291 spin_lock_irqsave(&mac
->lock
, flags
);
293 if (!mac
->associnfo
.associating
) {
294 /* we race against the timeout function, so make sure
295 * only one of us can do work */
296 spin_unlock_irqrestore(&mac
->lock
, flags
);
299 network
= ieee80211softmac_get_network_by_bssid_locked(mac
, resp
->header
.addr3
);
301 /* someone sending us things without us knowing him? Ignore. */
303 dprintk(KERN_INFO PFX
"Received unrequested assocation response from " MAC_FMT
"\n", MAC_ARG(resp
->header
.addr3
));
304 spin_unlock_irqrestore(&mac
->lock
, flags
);
308 /* now that we know it was for us, we can cancel the timeout */
309 cancel_delayed_work(&mac
->associnfo
.timeout
);
313 dprintk(KERN_INFO PFX
"associated!\n");
314 ieee80211softmac_associated(mac
, resp
, network
);
315 ieee80211softmac_call_events_locked(mac
, IEEE80211SOFTMAC_EVENT_ASSOCIATED
, network
);
317 case WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH
:
318 if (!network
->auth_desynced_once
) {
319 /* there seem to be a few rare cases where our view of
320 * the world is obscured, or buggy APs that don't DEAUTH
321 * us properly. So we handle that, but allow it only once.
323 printkl(KERN_INFO PFX
"We were not authenticated during association, retrying...\n");
324 network
->authenticated
= 0;
325 /* we don't want to do this more than once ... */
326 network
->auth_desynced_once
= 1;
327 queue_work(mac
->workqueue
, &mac
->associnfo
.work
);
331 dprintk(KERN_INFO PFX
"associating failed (reason: 0x%x)!\n", status
);
332 mac
->associnfo
.associating
= 0;
333 mac
->associnfo
.bssvalid
= 0;
335 ieee80211softmac_call_events_locked(mac
, IEEE80211SOFTMAC_EVENT_ASSOCIATE_FAILED
, network
);
338 spin_unlock_irqrestore(&mac
->lock
, flags
);
343 ieee80211softmac_handle_disassoc(struct net_device
* dev
,
344 struct ieee80211_disassoc
*disassoc
)
346 struct ieee80211softmac_device
*mac
= ieee80211_priv(dev
);
348 dprintk(KERN_INFO PFX
"got disassoc frame\n");
350 spin_lock_irqsave(&mac
->lock
, flags
);
351 mac
->associnfo
.bssvalid
= 0;
353 spin_unlock_irqrestore(&mac
->lock
, flags
);