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