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