| Johannes Berg | 4855d25 | 2006-01-12 21:12:59 +0100 | [diff] [blame] | 1 | /* | 
|  | 2 | * This file contains the softmac's authentication logic. | 
|  | 3 | * | 
| Johannes Berg | 7985905 | 2006-01-31 19:31:41 +0100 | [diff] [blame] | 4 | * Copyright (c) 2005, 2006 Johannes Berg <johannes@sipsolutions.net> | 
|  | 5 | *                          Joseph Jezak <josejx@gentoo.org> | 
|  | 6 | *                          Larry Finger <Larry.Finger@lwfinger.net> | 
|  | 7 | *                          Danny van Dyk <kugelfang@gentoo.org> | 
|  | 8 | *                          Michael Buesch <mbuesch@freenet.de> | 
| Johannes Berg | 4855d25 | 2006-01-12 21:12:59 +0100 | [diff] [blame] | 9 | * | 
|  | 10 | * This program is free software; you can redistribute it and/or modify it | 
|  | 11 | * under the terms of version 2 of the GNU General Public License as | 
|  | 12 | * published by the Free Software Foundation. | 
|  | 13 | * | 
|  | 14 | * This program is distributed in the hope that it will be useful, but WITHOUT | 
|  | 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 
|  | 16 | * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for | 
|  | 17 | * more details. | 
|  | 18 | * | 
|  | 19 | * You should have received a copy of the GNU General Public License | 
|  | 20 | * along with this program; if not, write to the Free Software | 
|  | 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA | 
|  | 22 | * | 
|  | 23 | * The full GNU General Public License is included in this distribution in the | 
|  | 24 | * file called COPYING. | 
|  | 25 | */ | 
|  | 26 |  | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 27 | #include "ieee80211softmac_priv.h" | 
|  | 28 |  | 
| David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 29 | static void ieee80211softmac_auth_queue(struct work_struct *work); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 30 |  | 
|  | 31 | /* Queues an auth request to the desired AP */ | 
|  | 32 | int | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 33 | ieee80211softmac_auth_req(struct ieee80211softmac_device *mac, | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 34 | struct ieee80211softmac_network *net) | 
|  | 35 | { | 
|  | 36 | struct ieee80211softmac_auth_queue_item *auth; | 
|  | 37 | unsigned long flags; | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 38 | DECLARE_MAC_BUF(mac2); | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 39 |  | 
| Joseph Jezak | cb74c43 | 2006-06-11 12:00:37 -0400 | [diff] [blame] | 40 | if (net->authenticating || net->authenticated) | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 41 | return 0; | 
| Joseph Jezak | cb74c43 | 2006-06-11 12:00:37 -0400 | [diff] [blame] | 42 | net->authenticating = 1; | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 43 |  | 
|  | 44 | /* Add the network if it's not already added */ | 
|  | 45 | ieee80211softmac_add_network(mac, net); | 
|  | 46 |  | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 47 | dprintk(KERN_NOTICE PFX "Queueing Authentication Request to %s\n", print_mac(mac2, net->bssid)); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 48 | /* Queue the auth request */ | 
|  | 49 | auth = (struct ieee80211softmac_auth_queue_item *) | 
|  | 50 | kmalloc(sizeof(struct ieee80211softmac_auth_queue_item), GFP_KERNEL); | 
|  | 51 | if(auth == NULL) | 
|  | 52 | return -ENOMEM; | 
|  | 53 |  | 
|  | 54 | auth->net = net; | 
|  | 55 | auth->mac = mac; | 
|  | 56 | auth->retry = IEEE80211SOFTMAC_AUTH_RETRY_LIMIT; | 
|  | 57 | auth->state = IEEE80211SOFTMAC_AUTH_OPEN_REQUEST; | 
| David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 58 | INIT_DELAYED_WORK(&auth->work, ieee80211softmac_auth_queue); | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 59 |  | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 60 | /* Lock (for list) */ | 
|  | 61 | spin_lock_irqsave(&mac->lock, flags); | 
|  | 62 |  | 
|  | 63 | /* add to list */ | 
|  | 64 | list_add_tail(&auth->list, &mac->auth_queue); | 
| Johannes Berg | 501d857 | 2007-10-03 18:14:23 -0700 | [diff] [blame] | 65 | queue_delayed_work(mac->wq, &auth->work, 0); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 66 | spin_unlock_irqrestore(&mac->lock, flags); | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 67 |  | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 68 | return 0; | 
|  | 69 | } | 
|  | 70 |  | 
|  | 71 |  | 
|  | 72 | /* Sends an auth request to the desired AP and handles timeouts */ | 
|  | 73 | static void | 
| David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 74 | ieee80211softmac_auth_queue(struct work_struct *work) | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 75 | { | 
|  | 76 | struct ieee80211softmac_device *mac; | 
|  | 77 | struct ieee80211softmac_auth_queue_item *auth; | 
|  | 78 | struct ieee80211softmac_network *net; | 
|  | 79 | unsigned long flags; | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 80 | DECLARE_MAC_BUF(mac2); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 81 |  | 
| David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 82 | auth = container_of(work, struct ieee80211softmac_auth_queue_item, | 
|  | 83 | work.work); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 84 | net = auth->net; | 
|  | 85 | mac = auth->mac; | 
|  | 86 |  | 
|  | 87 | if(auth->retry > 0) { | 
|  | 88 | /* Switch to correct channel for this network */ | 
|  | 89 | mac->set_channel(mac->dev, net->channel); | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 90 |  | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 91 | /* Lock and set flags */ | 
|  | 92 | spin_lock_irqsave(&mac->lock, flags); | 
| Daniel Drake | d57336e | 2006-04-30 22:09:07 +0100 | [diff] [blame] | 93 | if (unlikely(!mac->running)) { | 
|  | 94 | /* Prevent reschedule on workqueue flush */ | 
|  | 95 | spin_unlock_irqrestore(&mac->lock, flags); | 
|  | 96 | return; | 
|  | 97 | } | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 98 | net->authenticated = 0; | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 99 | /* add a timeout call so we eventually give up waiting for an auth reply */ | 
| Johannes Berg | 501d857 | 2007-10-03 18:14:23 -0700 | [diff] [blame] | 100 | queue_delayed_work(mac->wq, &auth->work, IEEE80211SOFTMAC_AUTH_TIMEOUT); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 101 | auth->retry--; | 
|  | 102 | spin_unlock_irqrestore(&mac->lock, flags); | 
|  | 103 | if (ieee80211softmac_send_mgt_frame(mac, auth->net, IEEE80211_STYPE_AUTH, auth->state)) | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 104 | dprintk(KERN_NOTICE PFX "Sending Authentication Request to %s failed (this shouldn't happen, wait for the timeout).\n", | 
|  | 105 | print_mac(mac2, net->bssid)); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 106 | else | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 107 | dprintk(KERN_NOTICE PFX "Sent Authentication Request to %s.\n", print_mac(mac2, net->bssid)); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 108 | return; | 
|  | 109 | } | 
|  | 110 |  | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 111 | printkl(KERN_WARNING PFX "Authentication timed out with %s\n", print_mac(mac2, net->bssid)); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 112 | /* Remove this item from the queue */ | 
|  | 113 | spin_lock_irqsave(&mac->lock, flags); | 
| Daniel Drake | 76ea4c7 | 2006-06-01 15:34:26 +0100 | [diff] [blame] | 114 | net->authenticating = 0; | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 115 | ieee80211softmac_call_events_locked(mac, IEEE80211SOFTMAC_EVENT_AUTH_TIMEOUT, net); | 
|  | 116 | cancel_delayed_work(&auth->work); /* just to make sure... */ | 
|  | 117 | list_del(&auth->list); | 
|  | 118 | spin_unlock_irqrestore(&mac->lock, flags); | 
|  | 119 | /* Free it */ | 
|  | 120 | kfree(auth); | 
|  | 121 | } | 
|  | 122 |  | 
| Daniel Drake | 345f6b8 | 2006-07-11 23:16:34 +0100 | [diff] [blame] | 123 | /* Sends a response to an auth challenge (for shared key auth). */ | 
|  | 124 | static void | 
| David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 125 | ieee80211softmac_auth_challenge_response(struct work_struct *work) | 
| Daniel Drake | 345f6b8 | 2006-07-11 23:16:34 +0100 | [diff] [blame] | 126 | { | 
| David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 127 | struct ieee80211softmac_auth_queue_item *aq = | 
|  | 128 | container_of(work, struct ieee80211softmac_auth_queue_item, | 
|  | 129 | work.work); | 
| Daniel Drake | 345f6b8 | 2006-07-11 23:16:34 +0100 | [diff] [blame] | 130 |  | 
|  | 131 | /* Send our response */ | 
|  | 132 | ieee80211softmac_send_mgt_frame(aq->mac, aq->net, IEEE80211_STYPE_AUTH, aq->state); | 
|  | 133 | } | 
|  | 134 |  | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 135 | /* Handle the auth response from the AP | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 136 | * This should be registered with ieee80211 as handle_auth | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 137 | */ | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 138 | int | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 139 | ieee80211softmac_auth_resp(struct net_device *dev, struct ieee80211_auth *auth) | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 140 | { | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 141 |  | 
|  | 142 | struct list_head *list_ptr; | 
|  | 143 | struct ieee80211softmac_device *mac = ieee80211_priv(dev); | 
|  | 144 | struct ieee80211softmac_auth_queue_item *aq = NULL; | 
|  | 145 | struct ieee80211softmac_network *net = NULL; | 
|  | 146 | unsigned long flags; | 
|  | 147 | u8 * data; | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 148 | DECLARE_MAC_BUF(mac2); | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 149 |  | 
| Daniel Drake | d57336e | 2006-04-30 22:09:07 +0100 | [diff] [blame] | 150 | if (unlikely(!mac->running)) | 
|  | 151 | return -ENODEV; | 
|  | 152 |  | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 153 | /* Find correct auth queue item */ | 
|  | 154 | spin_lock_irqsave(&mac->lock, flags); | 
|  | 155 | list_for_each(list_ptr, &mac->auth_queue) { | 
|  | 156 | aq = list_entry(list_ptr, struct ieee80211softmac_auth_queue_item, list); | 
|  | 157 | net = aq->net; | 
|  | 158 | if (!memcmp(net->bssid, auth->header.addr2, ETH_ALEN)) | 
|  | 159 | break; | 
|  | 160 | else | 
|  | 161 | aq = NULL; | 
|  | 162 | } | 
|  | 163 | spin_unlock_irqrestore(&mac->lock, flags); | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 164 |  | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 165 | /* Make sure that we've got an auth queue item for this request */ | 
|  | 166 | if(aq == NULL) | 
|  | 167 | { | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 168 | dprintkl(KERN_DEBUG PFX "Authentication response received from %s but no queue item exists.\n", print_mac(mac2, auth->header.addr2)); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 169 | /* Error #? */ | 
|  | 170 | return -1; | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 171 | } | 
|  | 172 |  | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 173 | /* Check for out of order authentication */ | 
|  | 174 | if(!net->authenticating) | 
|  | 175 | { | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 176 | dprintkl(KERN_DEBUG PFX "Authentication response received from %s but did not request authentication.\n",print_mac(mac2, auth->header.addr2)); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 177 | return -1; | 
|  | 178 | } | 
|  | 179 |  | 
|  | 180 | /* Parse the auth packet */ | 
| Al Viro | c414e84 | 2007-12-29 04:58:39 -0500 | [diff] [blame] | 181 | switch(le16_to_cpu(auth->algorithm)) { | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 182 | case WLAN_AUTH_OPEN: | 
|  | 183 | /* Check the status code of the response */ | 
|  | 184 |  | 
| Al Viro | c414e84 | 2007-12-29 04:58:39 -0500 | [diff] [blame] | 185 | switch(le16_to_cpu(auth->status)) { | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 186 | case WLAN_STATUS_SUCCESS: | 
|  | 187 | /* Update the status to Authenticated */ | 
|  | 188 | spin_lock_irqsave(&mac->lock, flags); | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 189 | net->authenticating = 0; | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 190 | net->authenticated = 1; | 
|  | 191 | spin_unlock_irqrestore(&mac->lock, flags); | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 192 |  | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 193 | /* Send event */ | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 194 | printkl(KERN_NOTICE PFX "Open Authentication completed with %s\n", print_mac(mac2, net->bssid)); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 195 | ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_AUTHENTICATED, net); | 
|  | 196 | break; | 
|  | 197 | default: | 
|  | 198 | /* Lock and reset flags */ | 
|  | 199 | spin_lock_irqsave(&mac->lock, flags); | 
|  | 200 | net->authenticated = 0; | 
|  | 201 | net->authenticating = 0; | 
|  | 202 | spin_unlock_irqrestore(&mac->lock, flags); | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 203 |  | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 204 | printkl(KERN_NOTICE PFX "Open Authentication with %s failed, error code: %i\n", | 
|  | 205 | print_mac(mac2, net->bssid), le16_to_cpup(&auth->status)); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 206 | /* Count the error? */ | 
|  | 207 | break; | 
|  | 208 | } | 
|  | 209 | goto free_aq; | 
|  | 210 | break; | 
|  | 211 | case WLAN_AUTH_SHARED_KEY: | 
|  | 212 | /* Figure out where we are in the process */ | 
| Al Viro | c414e84 | 2007-12-29 04:58:39 -0500 | [diff] [blame] | 213 | switch(le16_to_cpu(auth->transaction)) { | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 214 | case IEEE80211SOFTMAC_AUTH_SHARED_CHALLENGE: | 
|  | 215 | /* Check to make sure we have a challenge IE */ | 
|  | 216 | data = (u8 *)auth->info_element; | 
| Daniel Drake | 345f6b8 | 2006-07-11 23:16:34 +0100 | [diff] [blame] | 217 | if (*data++ != MFIE_TYPE_CHALLENGE) { | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 218 | printkl(KERN_NOTICE PFX "Shared Key Authentication failed due to a missing challenge.\n"); | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 219 | break; | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 220 | } | 
|  | 221 | /* Save the challenge */ | 
|  | 222 | spin_lock_irqsave(&mac->lock, flags); | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 223 | net->challenge_len = *data++; | 
| Daniel Drake | 345f6b8 | 2006-07-11 23:16:34 +0100 | [diff] [blame] | 224 | if (net->challenge_len > WLAN_AUTH_CHALLENGE_LEN) | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 225 | net->challenge_len = WLAN_AUTH_CHALLENGE_LEN; | 
| Arnaldo Carvalho de Melo | 571d6ee | 2006-11-21 01:26:49 -0200 | [diff] [blame] | 226 | kfree(net->challenge); | 
|  | 227 | net->challenge = kmemdup(data, net->challenge_len, | 
|  | 228 | GFP_ATOMIC); | 
|  | 229 | if (net->challenge == NULL) { | 
|  | 230 | printkl(KERN_NOTICE PFX "Shared Key " | 
|  | 231 | "Authentication failed due to " | 
|  | 232 | "memory shortage.\n"); | 
|  | 233 | spin_unlock_irqrestore(&mac->lock, flags); | 
|  | 234 | break; | 
|  | 235 | } | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 236 | aq->state = IEEE80211SOFTMAC_AUTH_SHARED_RESPONSE; | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 237 |  | 
| Daniel Drake | 345f6b8 | 2006-07-11 23:16:34 +0100 | [diff] [blame] | 238 | /* We reuse the work struct from the auth request here. | 
|  | 239 | * It is safe to do so as each one is per-request, and | 
|  | 240 | * at this point (dealing with authentication response) | 
|  | 241 | * we have obviously already sent the initial auth | 
|  | 242 | * request. */ | 
|  | 243 | cancel_delayed_work(&aq->work); | 
| David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 244 | INIT_DELAYED_WORK(&aq->work, &ieee80211softmac_auth_challenge_response); | 
| Johannes Berg | 501d857 | 2007-10-03 18:14:23 -0700 | [diff] [blame] | 245 | queue_delayed_work(mac->wq, &aq->work, 0); | 
| Daniel Drake | 345f6b8 | 2006-07-11 23:16:34 +0100 | [diff] [blame] | 246 | spin_unlock_irqrestore(&mac->lock, flags); | 
| Daniel Drake | 76ea4c7 | 2006-06-01 15:34:26 +0100 | [diff] [blame] | 247 | return 0; | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 248 | case IEEE80211SOFTMAC_AUTH_SHARED_PASS: | 
| Daniel Drake | 76ea4c7 | 2006-06-01 15:34:26 +0100 | [diff] [blame] | 249 | kfree(net->challenge); | 
|  | 250 | net->challenge = NULL; | 
|  | 251 | net->challenge_len = 0; | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 252 | /* Check the status code of the response */ | 
|  | 253 | switch(auth->status) { | 
|  | 254 | case WLAN_STATUS_SUCCESS: | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 255 | /* Update the status to Authenticated */ | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 256 | spin_lock_irqsave(&mac->lock, flags); | 
|  | 257 | net->authenticating = 0; | 
|  | 258 | net->authenticated = 1; | 
|  | 259 | spin_unlock_irqrestore(&mac->lock, flags); | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 260 | printkl(KERN_NOTICE PFX "Shared Key Authentication completed with %s\n", | 
|  | 261 | print_mac(mac2, net->bssid)); | 
| Daniel Drake | 76ea4c7 | 2006-06-01 15:34:26 +0100 | [diff] [blame] | 262 | ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_AUTHENTICATED, net); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 263 | break; | 
|  | 264 | default: | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 265 | printkl(KERN_NOTICE PFX "Shared Key Authentication with %s failed, error code: %i\n", | 
|  | 266 | print_mac(mac2, net->bssid), le16_to_cpup(&auth->status)); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 267 | /* Lock and reset flags */ | 
|  | 268 | spin_lock_irqsave(&mac->lock, flags); | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 269 | net->authenticating = 0; | 
|  | 270 | net->authenticated = 0; | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 271 | spin_unlock_irqrestore(&mac->lock, flags); | 
|  | 272 | /* Count the error? */ | 
|  | 273 | break; | 
|  | 274 | } | 
|  | 275 | goto free_aq; | 
|  | 276 | break; | 
|  | 277 | default: | 
|  | 278 | printkl(KERN_WARNING PFX "Unhandled Authentication Step: %i\n", auth->transaction); | 
|  | 279 | break; | 
|  | 280 | } | 
|  | 281 | goto free_aq; | 
|  | 282 | break; | 
|  | 283 | default: | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 284 | /* ERROR */ | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 285 | goto free_aq; | 
|  | 286 | break; | 
|  | 287 | } | 
|  | 288 | return 0; | 
|  | 289 | free_aq: | 
|  | 290 | /* Cancel the timeout */ | 
|  | 291 | spin_lock_irqsave(&mac->lock, flags); | 
|  | 292 | cancel_delayed_work(&aq->work); | 
|  | 293 | /* Remove this item from the queue */ | 
|  | 294 | list_del(&aq->list); | 
|  | 295 | spin_unlock_irqrestore(&mac->lock, flags); | 
|  | 296 |  | 
|  | 297 | /* Free it */ | 
|  | 298 | kfree(aq); | 
|  | 299 | return 0; | 
|  | 300 | } | 
|  | 301 |  | 
|  | 302 | /* | 
|  | 303 | * Handle deauthorization | 
|  | 304 | */ | 
| Johannes Berg | 714e1a5 | 2006-01-04 21:06:28 +0100 | [diff] [blame] | 305 | static void | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 306 | ieee80211softmac_deauth_from_net(struct ieee80211softmac_device *mac, | 
|  | 307 | struct ieee80211softmac_network *net) | 
|  | 308 | { | 
|  | 309 | struct ieee80211softmac_auth_queue_item *aq = NULL; | 
|  | 310 | struct list_head *list_ptr; | 
|  | 311 | unsigned long flags; | 
|  | 312 |  | 
| Daniel Drake | 6d92f83 | 2006-05-01 22:23:27 +0100 | [diff] [blame] | 313 | /* deauthentication implies disassociation */ | 
|  | 314 | ieee80211softmac_disassoc(mac); | 
|  | 315 |  | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 316 | /* Lock and reset status flags */ | 
|  | 317 | spin_lock_irqsave(&mac->lock, flags); | 
|  | 318 | net->authenticating = 0; | 
|  | 319 | net->authenticated = 0; | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 320 |  | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 321 | /* Find correct auth queue item, if it exists */ | 
|  | 322 | list_for_each(list_ptr, &mac->auth_queue) { | 
|  | 323 | aq = list_entry(list_ptr, struct ieee80211softmac_auth_queue_item, list); | 
|  | 324 | if (!memcmp(net->bssid, aq->net->bssid, ETH_ALEN)) | 
|  | 325 | break; | 
|  | 326 | else | 
|  | 327 | aq = NULL; | 
|  | 328 | } | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 329 |  | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 330 | /* Cancel pending work */ | 
|  | 331 | if(aq != NULL) | 
|  | 332 | /* Not entirely safe?  What about running work? */ | 
|  | 333 | cancel_delayed_work(&aq->work); | 
|  | 334 |  | 
|  | 335 | /* Free our network ref */ | 
|  | 336 | ieee80211softmac_del_network_locked(mac, net); | 
|  | 337 | if(net->challenge != NULL) | 
|  | 338 | kfree(net->challenge); | 
|  | 339 | kfree(net); | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 340 |  | 
| Johannes Berg | 2dd5080 | 2006-01-06 18:11:23 +0100 | [diff] [blame] | 341 | /* can't transmit data right now... */ | 
|  | 342 | netif_carrier_off(mac->dev); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 343 | spin_unlock_irqrestore(&mac->lock, flags); | 
| Ulrich Kunitz | 2b50c24 | 2006-12-03 16:32:00 +0100 | [diff] [blame] | 344 |  | 
|  | 345 | ieee80211softmac_try_reassoc(mac); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 346 | } | 
|  | 347 |  | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 348 | /* | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 349 | * Sends a deauth request to the desired AP | 
|  | 350 | */ | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 351 | int | 
|  | 352 | ieee80211softmac_deauth_req(struct ieee80211softmac_device *mac, | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 353 | struct ieee80211softmac_network *net, int reason) | 
|  | 354 | { | 
|  | 355 | int ret; | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 356 |  | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 357 | /* Make sure the network is authenticated */ | 
|  | 358 | if (!net->authenticated) | 
|  | 359 | { | 
| Larry Finger | 5398d59 | 2006-11-04 13:29:50 -0600 | [diff] [blame] | 360 | dprintkl(KERN_DEBUG PFX "Can't send deauthentication packet, network is not authenticated.\n"); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 361 | /* Error okay? */ | 
|  | 362 | return -EPERM; | 
|  | 363 | } | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 364 |  | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 365 | /* Send the de-auth packet */ | 
|  | 366 | if((ret = ieee80211softmac_send_mgt_frame(mac, net, IEEE80211_STYPE_DEAUTH, reason))) | 
|  | 367 | return ret; | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 368 |  | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 369 | ieee80211softmac_deauth_from_net(mac, net); | 
|  | 370 | return 0; | 
|  | 371 | } | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 372 |  | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 373 | /* | 
|  | 374 | * This should be registered with ieee80211 as handle_deauth | 
|  | 375 | */ | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 376 | int | 
| Johannes Berg | b10c991 | 2006-01-31 19:48:06 +0100 | [diff] [blame] | 377 | ieee80211softmac_deauth_resp(struct net_device *dev, struct ieee80211_deauth *deauth) | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 378 | { | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 379 |  | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 380 | struct ieee80211softmac_network *net = NULL; | 
|  | 381 | struct ieee80211softmac_device *mac = ieee80211_priv(dev); | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 382 | DECLARE_MAC_BUF(mac2); | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 383 |  | 
| Daniel Drake | d57336e | 2006-04-30 22:09:07 +0100 | [diff] [blame] | 384 | if (unlikely(!mac->running)) | 
|  | 385 | return -ENODEV; | 
|  | 386 |  | 
| Johannes Berg | b10c991 | 2006-01-31 19:48:06 +0100 | [diff] [blame] | 387 | if (!deauth) { | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 388 | dprintk("deauth without deauth packet. eek!\n"); | 
|  | 389 | return 0; | 
|  | 390 | } | 
|  | 391 |  | 
| Johannes Berg | b10c991 | 2006-01-31 19:48:06 +0100 | [diff] [blame] | 392 | net = ieee80211softmac_get_network_by_bssid(mac, deauth->header.addr2); | 
| YOSHIFUJI Hideaki | 6426565 | 2007-02-09 23:24:46 +0900 | [diff] [blame] | 393 |  | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 394 | if (net == NULL) { | 
| Joe Perches | 0795af5 | 2007-10-03 17:59:30 -0700 | [diff] [blame] | 395 | dprintkl(KERN_DEBUG PFX "Received deauthentication packet from %s, but that network is unknown.\n", | 
|  | 396 | print_mac(mac2, deauth->header.addr2)); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 397 | return 0; | 
|  | 398 | } | 
|  | 399 |  | 
|  | 400 | /* Make sure the network is authenticated */ | 
|  | 401 | if(!net->authenticated) | 
|  | 402 | { | 
| Larry Finger | 5398d59 | 2006-11-04 13:29:50 -0600 | [diff] [blame] | 403 | dprintkl(KERN_DEBUG PFX "Can't perform deauthentication, network is not authenticated.\n"); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 404 | /* Error okay? */ | 
|  | 405 | return -EPERM; | 
|  | 406 | } | 
|  | 407 |  | 
|  | 408 | ieee80211softmac_deauth_from_net(mac, net); | 
| Daniel Drake | 995c992 | 2006-04-30 19:49:30 +0100 | [diff] [blame] | 409 |  | 
|  | 410 | /* let's try to re-associate */ | 
| Johannes Berg | 501d857 | 2007-10-03 18:14:23 -0700 | [diff] [blame] | 411 | queue_delayed_work(mac->wq, &mac->associnfo.work, 0); | 
| Johannes Berg | 370121e | 2006-01-04 16:32:16 +0100 | [diff] [blame] | 412 | return 0; | 
|  | 413 | } |