diff options
Diffstat (limited to 'net/ieee80211')
-rw-r--r-- | net/ieee80211/Kconfig | 1 | ||||
-rw-r--r-- | net/ieee80211/softmac/Kconfig | 9 | ||||
-rw-r--r-- | net/ieee80211/softmac/Makefile | 9 | ||||
-rw-r--r-- | net/ieee80211/softmac/ieee80211softmac_assoc.c | 356 | ||||
-rw-r--r-- | net/ieee80211/softmac/ieee80211softmac_auth.c | 348 | ||||
-rw-r--r-- | net/ieee80211/softmac/ieee80211softmac_event.c | 135 | ||||
-rw-r--r-- | net/ieee80211/softmac/ieee80211softmac_io.c | 474 | ||||
-rw-r--r-- | net/ieee80211/softmac/ieee80211softmac_module.c | 441 | ||||
-rw-r--r-- | net/ieee80211/softmac/ieee80211softmac_priv.h | 206 | ||||
-rw-r--r-- | net/ieee80211/softmac/ieee80211softmac_scan.c | 216 | ||||
-rw-r--r-- | net/ieee80211/softmac/ieee80211softmac_wx.c | 390 |
11 files changed, 2585 insertions, 0 deletions
diff --git a/net/ieee80211/Kconfig b/net/ieee80211/Kconfig index d18ccba3ea9..dbb08528ddf 100644 --- a/net/ieee80211/Kconfig +++ b/net/ieee80211/Kconfig @@ -66,3 +66,4 @@ config IEEE80211_CRYPT_TKIP This can be compiled as a modules and it will be called "ieee80211_crypt_tkip". +source "net/ieee80211/softmac/Kconfig" diff --git a/net/ieee80211/softmac/Kconfig b/net/ieee80211/softmac/Kconfig new file mode 100644 index 00000000000..8d425042591 --- /dev/null +++ b/net/ieee80211/softmac/Kconfig @@ -0,0 +1,9 @@ +config IEEE80211_SOFTMAC + tristate "Software MAC add-on to the IEEE 802.11 networking stack" + ---help--- + This option enables the hardware independent software MAC addon + for the IEEE 802.11 networking stack. + +config IEEE80211_SOFTMAC_DEBUG + bool "Enable full debugging output" + depends on IEEE80211_SOFTMAC diff --git a/net/ieee80211/softmac/Makefile b/net/ieee80211/softmac/Makefile new file mode 100644 index 00000000000..d8c416bdddd --- /dev/null +++ b/net/ieee80211/softmac/Makefile @@ -0,0 +1,9 @@ +obj-$(CONFIG_IEEE80211_SOFTMAC) := ieee80211softmac.o +ieee80211softmac-objs := \ + ieee80211softmac_io.o \ + ieee80211softmac_auth.o \ + ieee80211softmac_module.o \ + ieee80211softmac_scan.o \ + ieee80211softmac_wx.o \ + ieee80211softmac_assoc.o \ + ieee80211softmac_event.o diff --git a/net/ieee80211/softmac/ieee80211softmac_assoc.c b/net/ieee80211/softmac/ieee80211softmac_assoc.c new file mode 100644 index 00000000000..d491005d6cf --- /dev/null +++ b/net/ieee80211/softmac/ieee80211softmac_assoc.c @@ -0,0 +1,356 @@ +#include "ieee80211softmac_priv.h" + +/* + * Overview + * + * Before you can associate, you have to authenticate. + * + */ + +/* Sends out an association request to the desired AP */ +static void +ieee80211softmac_assoc(struct ieee80211softmac_device *mac, struct ieee80211softmac_network *net) +{ + unsigned long flags; + function_enter(); + /* Switch to correct channel for this network */ + mac->set_channel(mac->dev, net->channel); + + /* Send association request */ + ieee80211softmac_send_mgt_frame(mac, net, IEEE80211_STYPE_ASSOC_REQ, 0); + + dprintk(KERN_INFO PFX "sent association request!\n"); + + /* Change the state to associating */ + spin_lock_irqsave(&mac->lock, flags); + mac->associnfo.associating = 1; + mac->associated = 0; /* just to make sure */ + spin_unlock_irqrestore(&mac->lock, flags); + + /* Set a timer for timeout */ + /* FIXME: make timeout configurable */ + queue_delayed_work(mac->workqueue, &mac->associnfo.timeout, 5 * HZ); +} + +void +ieee80211softmac_assoc_timeout(void *d) +{ + struct ieee80211softmac_device *mac = (struct ieee80211softmac_device *)d; + unsigned long flags; + + function_enter(); + + spin_lock_irqsave(&mac->lock, flags); + /* we might race against ieee80211softmac_handle_assoc_response, + * so make sure only one of us does something */ + if (!mac->associnfo.associating) { + spin_unlock_irqrestore(&mac->lock, flags); + return; + } + mac->associnfo.associating = 0; + mac->associnfo.bssvalid = 0; + mac->associated = 0; + spin_unlock_irqrestore(&mac->lock, flags); + + dprintk(KERN_INFO PFX "assoc request timed out!\n"); + /* FIXME: we need to know the network here. that requires a bit of restructuring */ + ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_TIMEOUT, NULL); +} + +static void +ieee80211softmac_reassoc(struct ieee80211softmac_device *mac) +{ + function_enter(); +} + + +/* Sends out a disassociation request to the desired AP */ +static void +ieee80211softmac_disassoc(struct ieee80211softmac_device *mac, u16 reason) +{ + unsigned long flags; + struct ieee80211softmac_network *found; + function_enter(); + + if (mac->associnfo.bssvalid && mac->associated) { + found = ieee80211softmac_get_network_by_bssid(mac, mac->associnfo.bssid); + if (found) + ieee80211softmac_send_mgt_frame(mac, found, IEEE80211_STYPE_DISASSOC, reason); + } else if (mac->associnfo.associating) { + cancel_delayed_work(&mac->associnfo.timeout); + } + + /* Change our state */ + spin_lock_irqsave(&mac->lock, flags); + /* Do NOT clear bssvalid as that will break ieee80211softmac_assoc_work! */ + mac->associated = 0; + mac->associnfo.associating = 0; + spin_unlock_irqrestore(&mac->lock, flags); +} + +static inline int +we_support_all_basic_rates(struct ieee80211softmac_device *mac, u8 *from, u8 from_len) +{ + int idx, search, found; + u8 rate, search_rate; + + for (idx = 0; idx < (from_len); idx++) { + rate = (from)[idx]; + if (!(rate & IEEE80211_BASIC_RATE_MASK)) + continue; + found = 0; + rate &= ~IEEE80211_BASIC_RATE_MASK; + for (search = 0; search < mac->ratesinfo.count; search++) { + search_rate = mac->ratesinfo.rates[search]; + search_rate &= ~IEEE80211_BASIC_RATE_MASK; + if (rate == search_rate) { + found = 1; + break; + } + } + if (!found) + return 0; + } + return 1; +} + +static int +network_matches_request(struct ieee80211softmac_device *mac, struct ieee80211_network *net) +{ + /* we cannot associate to networks whose name we don't know */ + if (ieee80211_is_empty_essid(net->ssid, net->ssid_len)) + return 0; + /* do not associate to a network whose BSSBasicRateSet we cannot support */ + if (!we_support_all_basic_rates(mac, net->rates, net->rates_len)) + return 0; + /* do we really need to check the ex rates? */ + if (!we_support_all_basic_rates(mac, net->rates_ex, net->rates_ex_len)) + return 0; + + /* if 'ANY' network requested, take any that doesn't have privacy enabled */ + if (mac->associnfo.req_essid.len == 0 + && !(net->capability & WLAN_CAPABILITY_PRIVACY)) + return 1; + if (net->ssid_len != mac->associnfo.req_essid.len) + return 0; + if (!memcmp(net->ssid, mac->associnfo.req_essid.data, mac->associnfo.req_essid.len)) + return 1; + return 0; +} + +static void +ieee80211softmac_assoc_notify(struct net_device *dev, void *context) +{ + struct ieee80211softmac_device *mac = ieee80211_priv(dev); + ieee80211softmac_assoc_work((void*)mac); +} + +/* This function is called to handle userspace requests (asynchronously) */ +void +ieee80211softmac_assoc_work(void *d) +{ + struct ieee80211softmac_device *mac = (struct ieee80211softmac_device *)d; + struct ieee80211softmac_network *found = NULL; + struct ieee80211_network *net = NULL, *best = NULL; + unsigned long flags; + + function_enter(); + + /* meh */ + if (mac->associated) + ieee80211softmac_disassoc(mac, WLAN_REASON_DISASSOC_STA_HAS_LEFT); + + /* try to find the requested network in our list, if we found one already */ + if (mac->associnfo.bssvalid) + found = ieee80211softmac_get_network_by_bssid(mac, mac->associnfo.bssid); + + /* Search the ieee80211 networks for this network if we didn't find it */ + if (!found) + { + spin_lock_irqsave(&mac->ieee->lock, flags); + list_for_each_entry(net, &mac->ieee->network_list, list) { + /* we're supposed to find the network with + * the best signal here, as we're asked to join + * any network with a specific ESSID, and many + * different ones could have that. + * + * I'll for now implement just finding one at all + * + * We also should take into account the rateset + * here to find the best BSSID to try. + */ + if (network_matches_request(mac, net)) { + if (!best) { + best = net; + continue; + } + /* we already had a matching network, so + * compare their properties to get the + * better of the two ... (see above) + */ + /* TODO */ + /* for now, just */ + break; + } + } + /* if we unlock here, we might get interrupted and the `best' + * pointer could go stale */ + if (best) { + found = ieee80211softmac_create_network(mac, best); + /* if found is still NULL, then we got -ENOMEM somewhere */ + if (found) + ieee80211softmac_add_network(mac, found); + } + spin_unlock_irqrestore(&mac->ieee->lock, flags); + } + + if (!found) { + if (mac->associnfo.scan_retry > 0) { + spin_lock_irqsave(&mac->lock, flags); + mac->associnfo.scan_retry--; + spin_unlock_irqrestore(&mac->lock, flags); + + /* We know of no such network. Let's scan. + * NB: this also happens if we had no memory to copy the network info... + * Maybe we can hope to have more memory after scanning finishes ;) + */ + dprintk(KERN_INFO PFX "Associate: Network not known, trying to initiate scan: "); + ieee80211softmac_notify(mac->dev, IEEE80211SOFTMAC_EVENT_SCAN_FINISHED, ieee80211softmac_assoc_notify, NULL); + if (ieee80211softmac_start_scan(mac)) + dprintk("failed.\n"); + else + dprintk("ok.\n"); + return; + } + else { + spin_lock_irqsave(&mac->lock, flags); + mac->associnfo.associating = 0; + mac->associated = 0; + spin_unlock_irqrestore(&mac->lock, flags); + + dprintk(KERN_INFO PFX "Unable to find network after scan!\n"); + ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_NET_NOT_FOUND, NULL); + return; + } + } + + mac->associnfo.bssvalid = 1; + memcpy(mac->associnfo.bssid, found->bssid, ETH_ALEN); + /* copy the ESSID for displaying it */ + mac->associnfo.associate_essid.len = found->essid.len; + memcpy(mac->associnfo.associate_essid.data, found->essid.data, IW_ESSID_MAX_SIZE + 1); + + /* we found a network! authenticate (if necessary) and associate to it. */ + if (!found->authenticated) { + /* This relies on the fact that _auth_req only queues the work, + * otherwise adding the notification would be racy. */ + if (!ieee80211softmac_auth_req(mac, found)) { + dprintk(KERN_INFO PFX "cannot associate without being authenticated, requested authentication\n"); + ieee80211softmac_notify_internal(mac, IEEE80211SOFTMAC_EVENT_ANY, found, ieee80211softmac_assoc_notify, NULL, GFP_KERNEL); + } else { + printkl(KERN_WARNING PFX "Not authenticated, but requesting authentication failed. Giving up to associate\n"); + ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_FAILED, found); + } + return; + } + /* finally! now we can start associating */ + ieee80211softmac_assoc(mac, found); +} + +/* call this to do whatever is necessary when we're associated */ +static void +ieee80211softmac_associated(struct ieee80211softmac_device *mac, + struct ieee80211_assoc_response * resp, + struct ieee80211softmac_network *net) +{ + mac->associnfo.associating = 0; + mac->associated = 1; + if (mac->set_bssid_filter) + mac->set_bssid_filter(mac->dev, net->bssid); + memcpy(mac->ieee->bssid, net->bssid, ETH_ALEN); + mac->dev->flags |= IFF_RUNNING; + + mac->association_id = le16_to_cpup(&resp->aid); +} + +/* received frame handling functions */ +int +ieee80211softmac_handle_assoc_response(struct net_device * dev, + struct ieee80211_assoc_response * resp, + struct ieee80211_network * _ieee80211_network_do_not_use) +{ + /* NOTE: the network parameter has to be ignored by + * this code because it is the ieee80211's pointer + * to the struct, not ours (we made a copy) + */ + struct ieee80211softmac_device *mac = ieee80211_priv(dev); + u16 status = le16_to_cpup(&resp->status); + struct ieee80211softmac_network *network = NULL; + unsigned long flags; + + spin_lock_irqsave(&mac->lock, flags); + + if (!mac->associnfo.associating) { + /* we race against the timeout function, so make sure + * only one of us can do work */ + spin_unlock_irqrestore(&mac->lock, flags); + return 0; + } + network = ieee80211softmac_get_network_by_bssid_locked(mac, resp->header.addr3); + + /* someone sending us things without us knowing him? Ignore. */ + if (!network) { + dprintk(KERN_INFO PFX "Received unrequested assocation response from " MAC_FMT "\n", MAC_ARG(resp->header.addr3)); + spin_unlock_irqrestore(&mac->lock, flags); + return 0; + } + + /* now that we know it was for us, we can cancel the timeout */ + cancel_delayed_work(&mac->associnfo.timeout); + + switch (status) { + case 0: + dprintk(KERN_INFO PFX "associated!\n"); + ieee80211softmac_associated(mac, resp, network); + ieee80211softmac_call_events_locked(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATED, network); + break; + case WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH: + if (!network->auth_desynced_once) { + /* there seem to be a few rare cases where our view of + * the world is obscured, or buggy APs that don't DEAUTH + * us properly. So we handle that, but allow it only once. + */ + printkl(KERN_INFO PFX "We were not authenticated during association, retrying...\n"); + network->authenticated = 0; + /* we don't want to do this more than once ... */ + network->auth_desynced_once = 1; + queue_work(mac->workqueue, &mac->associnfo.work); + break; + } + default: + dprintk(KERN_INFO PFX "associating failed (reason: 0x%x)!\n", status); + mac->associnfo.associating = 0; + mac->associnfo.bssvalid = 0; + mac->associated = 0; + ieee80211softmac_call_events_locked(mac, IEEE80211SOFTMAC_EVENT_ASSOCIATE_FAILED, network); + } + + spin_unlock_irqrestore(&mac->lock, flags); + return 0; +} + +int +ieee80211softmac_handle_disassoc(struct net_device * dev, + struct ieee80211_disassoc *disassoc) +{ + struct ieee80211softmac_device *mac = ieee80211_priv(dev); + unsigned long flags; + dprintk(KERN_INFO PFX "got disassoc frame\n"); + + spin_lock_irqsave(&mac->lock, flags); + mac->associnfo.bssvalid = 0; + mac->associated = 0; + spin_unlock_irqrestore(&mac->lock, flags); + + return 0; +} diff --git a/net/ieee80211/softmac/ieee80211softmac_auth.c b/net/ieee80211/softmac/ieee80211softmac_auth.c new file mode 100644 index 00000000000..94cac14bc1d --- /dev/null +++ b/net/ieee80211/softmac/ieee80211softmac_auth.c @@ -0,0 +1,348 @@ +#include "ieee80211softmac_priv.h" + +static void ieee80211softmac_auth_queue(void *data); + +/* Queues an auth request to the desired AP */ +int +ieee80211softmac_auth_req(struct ieee80211softmac_device *mac, + struct ieee80211softmac_network *net) +{ + struct ieee80211softmac_auth_queue_item *auth; + unsigned long flags; + + function_enter(); + + if (net->authenticating) + return 0; + + /* Add the network if it's not already added */ + ieee80211softmac_add_network(mac, net); + + dprintk(KERN_NOTICE PFX "Queueing Authentication Request to "MAC_FMT"\n", MAC_ARG(net->bssid)); + /* Queue the auth request */ + auth = (struct ieee80211softmac_auth_queue_item *) + kmalloc(sizeof(struct ieee80211softmac_auth_queue_item), GFP_KERNEL); + if(auth == NULL) + return -ENOMEM; + + auth->net = net; + auth->mac = mac; + auth->retry = IEEE80211SOFTMAC_AUTH_RETRY_LIMIT; + auth->state = IEEE80211SOFTMAC_AUTH_OPEN_REQUEST; + INIT_WORK(&auth->work, &ieee80211softmac_auth_queue, (void *)auth); + + /* Lock (for list) */ + spin_lock_irqsave(&mac->lock, flags); + + /* add to list */ + list_add_tail(&auth->list, &mac->auth_queue); + queue_work(mac->workqueue, &auth->work); + spin_unlock_irqrestore(&mac->lock, flags); + + return 0; +} + + +/* Sends an auth request to the desired AP and handles timeouts */ +static void +ieee80211softmac_auth_queue(void *data) +{ + struct ieee80211softmac_device *mac; + struct ieee80211softmac_auth_queue_item *auth; + struct ieee80211softmac_network *net; + unsigned long flags; + + function_enter(); + + auth = (struct ieee80211softmac_auth_queue_item *)data; + net = auth->net; + mac = auth->mac; + + if(auth->retry > 0) { + /* Switch to correct channel for this network */ + mac->set_channel(mac->dev, net->channel); + + /* Lock and set flags */ + spin_lock_irqsave(&mac->lock, flags); + net->authenticated = 0; + net->authenticating = 1; + /* add a timeout call so we eventually give up waiting for an auth reply */ + queue_delayed_work(mac->workqueue, &auth->work, IEEE80211SOFTMAC_AUTH_TIMEOUT); + auth->retry--; + spin_unlock_irqrestore(&mac->lock, flags); + if (ieee80211softmac_send_mgt_frame(mac, auth->net, IEEE80211_STYPE_AUTH, auth->state)) + dprintk(KERN_NOTICE PFX "Sending Authentication Request to "MAC_FMT" failed (this shouldn't happen, wait for the timeout).\n", MAC_ARG(net->bssid)); + else + dprintk(KERN_NOTICE PFX "Sent Authentication Request to "MAC_FMT".\n", MAC_ARG(net->bssid)); + return; + } + + printkl(KERN_WARNING PFX "Authentication timed out with "MAC_FMT"\n", MAC_ARG(net->bssid)); + /* Remove this item from the queue */ + spin_lock_irqsave(&mac->lock, flags); + ieee80211softmac_call_events_locked(mac, IEEE80211SOFTMAC_EVENT_AUTH_TIMEOUT, net); + cancel_delayed_work(&auth->work); /* just to make sure... */ + list_del(&auth->list); + spin_unlock_irqrestore(&mac->lock, flags); + /* Free it */ + kfree(auth); +} + +/* Handle the auth response from the AP + * This should be registered with ieee80211 as handle_auth + */ +int +ieee80211softmac_auth_resp(struct net_device *dev, struct ieee80211_auth *auth) +{ + + struct list_head *list_ptr; + struct ieee80211softmac_device *mac = ieee80211_priv(dev); + struct ieee80211softmac_auth_queue_item *aq = NULL; + struct ieee80211softmac_network *net = NULL; + unsigned long flags; + u8 * data; + + function_enter(); + + /* Find correct auth queue item */ + spin_lock_irqsave(&mac->lock, flags); + list_for_each(list_ptr, &mac->auth_queue) { + aq = list_entry(list_ptr, struct ieee80211softmac_auth_queue_item, list); + net = aq->net; + if (!memcmp(net->bssid, auth->header.addr2, ETH_ALEN)) + break; + else + aq = NULL; + } + spin_unlock_irqrestore(&mac->lock, flags); + + /* Make sure that we've got an auth queue item for this request */ + if(aq == NULL) + { + printkl(KERN_DEBUG PFX "Authentication response received from "MAC_FMT" but no queue item exists.\n", MAC_ARG(auth->header.addr2)); + /* Error #? */ + return -1; + } + + /* Check for out of order authentication */ + if(!net->authenticating) + { + printkl(KERN_DEBUG PFX "Authentication response received from "MAC_FMT" but did not request authentication.\n",MAC_ARG(auth->header.addr2)); + return -1; + } + + /* Parse the auth packet */ + switch(auth->algorithm) { + case WLAN_AUTH_OPEN: + /* Check the status code of the response */ + + switch(auth->status) { + case WLAN_STATUS_SUCCESS: + /* Update the status to Authenticated */ + spin_lock_irqsave(&mac->lock, flags); + net->authenticating = 0; + net->authenticated = 1; + spin_unlock_irqrestore(&mac->lock, flags); + + /* Send event */ + printkl(KERN_NOTICE PFX "Open Authentication completed with "MAC_FMT"\n", MAC_ARG(net->bssid)); + ieee80211softmac_call_events(mac, IEEE80211SOFTMAC_EVENT_AUTHENTICATED, net); + break; + default: + /* Lock and reset flags */ + spin_lock_irqsave(&mac->lock, flags); + net->authenticated = 0; + net->authenticating = 0; + spin_unlock_irqrestore(&mac->lock, flags); + + printkl(KERN_NOTICE PFX "Open Authentication with "MAC_FMT" failed, error code: %i\n", + MAC_ARG(net->bssid), le16_to_cpup(&auth->status)); + /* Count the error? */ + break; + } + goto free_aq; + break; + case WLAN_AUTH_SHARED_KEY: + /* Figure out where we are in the process */ + switch(auth->transaction) { + case IEEE80211SOFTMAC_AUTH_SHARED_CHALLENGE: + /* Check to make sure we have a challenge IE */ + data = (u8 *)auth->info_element; + if(*data++ != MFIE_TYPE_CHALLENGE){ + printkl(KERN_NOTICE PFX "Shared Key Authentication failed due to a missing challenge.\n"); + break; + } + /* Save the challenge */ + spin_lock_irqsave(&mac->lock, flags); + net->challenge_len = *data++; + if(net->challenge_len > WLAN_AUTH_CHALLENGE_LEN) + net->challenge_len = WLAN_AUTH_CHALLENGE_LEN; + if(net->challenge != NULL) + kfree(net->challenge); + net->challenge = kmalloc(net->challenge_len, GFP_ATOMIC); + memcpy(net->challenge, data, net->challenge_len); + aq->state = IEEE80211SOFTMAC_AUTH_SHARED_RESPONSE; + spin_unlock_irqrestore(&mac->lock, flags); + + /* Switch to correct channel for this network */ + mac->set_channel(mac->dev, net->channel); + + /* Send our response (How to encrypt?) */ + ieee80211softmac_send_mgt_frame(mac, aq->net, IEEE80211_STYPE_AUTH, aq->state); + break; + case IEEE80211SOFTMAC_AUTH_SHARED_PASS: + /* Check the status code of the response */ + switch(auth->status) { + case WLAN_STATUS_SUCCESS: + /* Update the status to Authenticated */ + spin_lock_irqsave(&mac->lock, flags); + net->authenticating = 0; + net->authenticated = 1; + spin_unlock_irqrestore(&mac->lock, flags); + printkl(KERN_NOTICE PFX "Shared Key Authentication completed with "MAC_FMT"\n", + MAC_ARG(net->bssid)); + break; + default: + printkl(KERN_NOTICE PFX "Shared Key Authentication with "MAC_FMT" failed, error code: %i\n", + MAC_ARG(net->bssid), le16_to_cpup(&auth->status)); + /* Lock and reset flags */ + spin_lock_irqsave(&mac->lock, flags); + net->authenticating = 0; + net->authenticated = 0; + spin_unlock_irqrestore(&mac->lock, flags); + /* Count the error? */ + break; + } + goto free_aq; + break; + default: + printkl(KERN_WARNING PFX "Unhandled Authentication Step: %i\n", auth->transaction); + break; + } + goto free_aq; + break; + default: + /* ERROR */ + goto free_aq; + break; + } + return 0; +free_aq: + /* Cancel the timeout */ + spin_lock_irqsave(&mac->lock, flags); + cancel_delayed_work(&aq->work); + /* Remove this item from the queue */ + list_del(&aq->list); + spin_unlock_irqrestore(&mac->lock, flags); + + /* Free it */ + kfree(aq); + return 0; +} + +/* + * Handle deauthorization + */ +void +ieee80211softmac_deauth_from_net(struct ieee80211softmac_device *mac, + struct ieee80211softmac_network *net) +{ + struct ieee80211softmac_auth_queue_item *aq = NULL; + struct list_head *list_ptr; + unsigned long flags; + + function_enter(); + + /* Lock and reset status flags */ + spin_lock_irqsave(&mac->lock, flags); + net->authenticating = 0; + net->authenticated = 0; + + /* Find correct auth queue item, if it exists */ + list_for_each(list_ptr, &mac->auth_queue) { + aq = list_entry(list_ptr, struct ieee80211softmac_auth_queue_item, list); + if (!memcmp(net->bssid, aq->net->bssid, ETH_ALEN)) + break; + else + aq = NULL; + } + + /* Cancel pending work */ + if(aq != NULL) + /* Not entirely safe? What about running work? */ + cancel_delayed_work(&aq->work); + + /* Free our network ref */ + ieee80211softmac_del_network_locked(mac, net); + if(net->challenge != NULL) + kfree(net->challenge); + kfree(net); + + /* let's try to re-associate */ + queue_work(mac->workqueue, &mac->associnfo.work); + spin_unlock_irqrestore(&mac->lock, flags); +} + +/* + * Sends a deauth request to the desired AP + */ +int +ieee80211softmac_deauth_req(struct ieee80211softmac_device *mac, + struct ieee80211softmac_network *net, int reason) +{ + int ret; + + function_enter(); + + /* Make sure the network is authenticated */ + if (!net->authenticated) + { + printkl(KERN_DEBUG PFX "Can't send deauthentication packet, network is not authenticated.\n"); + /* Error okay? */ + return -EPERM; + } + + /* Send the de-auth packet */ + if((ret = ieee80211softmac_send_mgt_frame(mac, net, IEEE80211_STYPE_DEAUTH, reason))) + return ret; + + ieee80211softmac_deauth_from_net(mac, net); + return 0; +} + +/* + * This should be registered with ieee80211 as handle_deauth + */ +int +ieee80211softmac_deauth_resp(struct net_device *dev, struct ieee80211_auth *auth) +{ + + struct ieee80211softmac_network *net = NULL; + struct ieee80211softmac_device *mac = ieee80211_priv(dev); + + function_enter(); + + if (!auth) { + dprintk("deauth without deauth packet. eek!\n"); + return 0; + } + + net = ieee80211softmac_get_network_by_bssid(mac, auth->header.addr2); + + if (net == NULL) { + printkl(KERN_DEBUG PFX "Recieved deauthentication packet from "MAC_FMT", but that network is unknown.\n", + MAC_ARG(auth->header.addr2)); + return 0; + } + + /* Make sure the network is authenticated */ + if(!net->authenticated) + { + printkl(KERN_DEBUG PFX "Can't perform deauthentication, network is not authenticated.\n"); + /* Error okay? */ + return -EPERM; + } + + ieee80211softmac_deauth_from_net(mac, net); + return 0; +} diff --git a/net/ieee80211/softmac/ieee80211softmac_event.c b/net/ieee80211/softmac/ieee80211softmac_event.c new file mode 100644 index 00000000000..0d0a8327252 --- /dev/null +++ b/net/ieee80211/softmac/ieee80211softmac_event.c @@ -0,0 +1,135 @@ +#include "ieee80211softmac_priv.h" + +/* + * Event system + * Also see comments in public header file + * + * Each event has associated to it + * - an event type (see constants in public header) + * - an event context (see below) + * - the function to be called + * - a context (extra parameter to call the function with) + * - and the softmac struct + * + * The event context is private and can only be used from + * within this module. Its meaning varies with the event + * type: + * SCAN_FINISHED: no special meaning + * ASSOCIATED, + * ASSOCIATE_FAILED, + * ASSOCIATE_TIMEOUT, + * AUTHENTICATED, + * AUTH_FAILED, + * AUTH_TIMEOUT: a pointer to the network struct + * ... + * Code within this module can use the event context to be only + * called when the event is true for that specific context + * as per above table. + * If the event context is NULL, then the notification is always called, + * regardless of the event context. The event context is not passed to + * the callback, it is assumed that the context suffices. + * + * You can also use the event context only by setting the event type + * to -1 (private use only), in which case you'll be notified + * whenever the event context matches. + */ + +static char *event_descriptions[IEEE80211SOFTMAC_EVENT_LAST+1] = { + "scan finished", + "associated", + "associating failed", + "associating timed out", + "authenticated", + "authenticating failed", + "authenticating timed out", + "associating failed because no suitable network was found", +}; + + +static void +ieee80211softmac_notify_callback(void *d) +{ + struct ieee80211softmac_event event = *(struct ieee80211softmac_event*) d; + kfree(d); + + event.fun(event.mac->dev, event.context); +} + +int +ieee80211softmac_notify_internal(struct ieee80211softmac_device *mac, + int event, void *event_context, notify_function_ptr fun, void *context, gfp_t gfp_mask) +{ + struct ieee80211softmac_event *eventptr; + unsigned long flags; + + if (event < -1 || event > IEEE80211SOFTMAC_EVENT_LAST) + return -ENOSYS; + + if (!fun) + return -EINVAL; + + eventptr = kmalloc(sizeof(struct ieee80211softmac_event), gfp_mask); + if (!eventptr) + return -ENOMEM; + + eventptr->event_type = event; + INIT_WORK(&eventptr->work, ieee80211softmac_notify_callback, eventptr); + eventptr->fun = fun; + eventptr->context = context; + eventptr->mac = mac; + eventptr->event_context = event_context; + + spin_lock_irqsave(&mac->lock, flags); + list_add(&eventptr->list, &mac->events); + spin_unlock_irqrestore(&mac->lock, flags); + + return 0; +} + +int +ieee80211softmac_notify_gfp(struct net_device *dev, + int event, notify_function_ptr fun, void *context, gfp_t gfp_mask) +{ + struct ieee80211softmac_device *mac = ieee80211_priv(dev); + + if (event < 0 || event > IEEE80211SOFTMAC_EVENT_LAST) + return -ENOSYS; + + return ieee80211softmac_notify_internal(mac, event, NULL, fun, context, gfp_mask); +} +EXPORT_SYMBOL_GPL(ieee80211softmac_notify_gfp); + +/* private -- calling all callbacks that were specified */ +void +ieee80211softmac_call_events_locked(struct ieee80211softmac_device *mac, int event, void *event_ctx) +{ + struct ieee80211softmac_event *eventptr, *tmp; + union iwreq_data wrqu; + char *msg; + + if (event >= 0) { + msg = event_descriptions[event]; + wrqu.data.length = strlen(msg); + wireless_send_event(mac->dev, IWEVCUSTOM, &wrqu, msg); + } + + if (!list_empty(&mac->events)) + list_for_each_entry_safe(eventptr, tmp, &mac->events, list) { + if ((eventptr->event_type == event || eventptr->event_type == -1) + && (eventptr->event_context == NULL || eventptr->event_context == event_ctx)) { + list_del(&eventptr->list); + queue_work(mac->workqueue, &eventptr->work); + } + } +} + +void +ieee80211softmac_call_events(struct ieee80211softmac_device *mac, int event, void *event_ctx) +{ + unsigned long flags; + + spin_lock_irqsave(&mac->lock, flags); + ieee80211softmac_call_events_locked(mac, event, event_ctx); + + spin_unlock_irqrestore(&mac->lock, flags); +} diff --git a/net/ieee80211/softmac/ieee80211softmac_io.c b/net/ieee80211/softmac/ieee80211softmac_io.c new file mode 100644 index 00000000000..2cb3087197d --- /dev/null +++ b/net/ieee80211/softmac/ieee80211softmac_io.c @@ -0,0 +1,474 @@ +/* + * Some parts based on code from net80211 + * Copyright (c) 2001 Atsushi Onoe + * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "ieee80211softmac_priv.h" + +/* Helper functions for inserting data into the frames */ + +/* + * Adds an ESSID element to the frame + * + */ +static u8 * +ieee80211softmac_add_essid(u8 *dst, struct ieee80211softmac_essid *essid) +{ + if (essid) { + *dst++ = MFIE_TYPE_SSID; + *dst++ = essid->len; + memcpy(dst, essid->data, essid->len); + return dst+essid->len; + } else { + *dst++ = MFIE_TYPE_SSID; + *dst++ = 0; + return dst; + } +} + +/* Adds Supported Rates and if required Extended Rates Information Element + * to the frame, ASSUMES WE HAVE A SORTED LIST OF RATES */ +static u8 * +ieee80211softmac_frame_add_rates(u8 *dst, const struct ieee80211softmac_ratesinfo *r) +{ + int cck_len, ofdm_len; + *dst++ = MFIE_TYPE_RATES; + + for(cck_len=0; ieee80211_is_cck_rate(r->rates[cck_len]) && (cck_len < r->count);cck_len++); + + if(cck_len > IEEE80211SOFTMAC_MAX_RATES_LEN) + cck_len = IEEE80211SOFTMAC_MAX_RATES_LEN; + *dst++ = cck_len; + memcpy(dst, r->rates, cck_len); + dst += cck_len; + + if(cck_len < r->count){ + for (ofdm_len=0; ieee80211_is_ofdm_rate(r->rates[ofdm_len + cck_len]) && (ofdm_len + cck_len < r->count); ofdm_len++); + if (ofdm_len > 0) { + if (ofdm_len > IEEE80211SOFTMAC_MAX_EX_RATES_LEN) + ofdm_len = IEEE80211SOFTMAC_MAX_EX_RATES_LEN; + *dst++ = MFIE_TYPE_RATES_EX; + *dst++ = ofdm_len; + memcpy(dst, r->rates + cck_len, ofdm_len); + dst += ofdm_len; + } + } + return dst; +} + +/* Allocate a management frame */ +static u8 * +ieee80211softmac_alloc_mgt(u32 size) +{ + u8 * data; + + /* Add the header and FCS to the size */ + size = size + IEEE80211_3ADDR_LEN; + if(size > IEEE80211_DATA_LEN) + return NULL; + /* Allocate the frame */ + data = kmalloc(size, GFP_ATOMIC); + memset(data, 0, size); + return data; +} + +/* + * Add a 2 Address Header + */ |