Skip to content

Commit

Permalink
lib80211: absorb crypto bits from net/ieee80211
Browse files Browse the repository at this point in the history
These bits are shared already between ipw2x00 and hostap, and could
probably be shared both more cleanly and with other drivers.  This
commit simply relocates the code to lib80211 and adjusts the drivers
appropriately.

Signed-off-by: John W. Linville <[email protected]>
  • Loading branch information
linvjw committed Nov 21, 2008
1 parent dfe1baf commit 274bfb8
Show file tree
Hide file tree
Showing 30 changed files with 680 additions and 694 deletions.
6 changes: 4 additions & 2 deletions drivers/net/wireless/hostap/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ config HOSTAP
tristate "IEEE 802.11 for Host AP (Prism2/2.5/3 and WEP/TKIP/CCMP)"
depends on WLAN_80211
select WIRELESS_EXT
select IEEE80211
select IEEE80211_CRYPT_WEP
select LIB80211
select LIB80211_CRYPT_WEP
select LIB80211_CRYPT_TKIP
select LIB80211_CRYPT_CCMP
---help---
Shared driver code for IEEE 802.11b wireless cards based on
Intersil Prism2/2.5/3 chipset. This driver supports so called
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/hostap/hostap.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void ap_control_flush_macs(struct mac_restrictions *mac_restrictions);
int ap_control_kick_mac(struct ap_data *ap, struct net_device *dev, u8 *mac);
void ap_control_kickall(struct ap_data *ap);
void * ap_crypt_get_ptrs(struct ap_data *ap, u8 *addr, int permanent,
struct ieee80211_crypt_data ***crypt);
struct lib80211_crypt_data ***crypt);
int prism2_ap_get_sta_qual(local_info_t *local, struct sockaddr addr[],
struct iw_quality qual[], int buf_size,
int aplist);
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/hostap/hostap_80211.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define HOSTAP_80211_H

#include <linux/types.h>
#include <net/ieee80211_crypt.h>
#include <net/ieee80211.h>

struct hostap_ieee80211_mgmt {
__le16 frame_control;
Expand Down
10 changes: 5 additions & 5 deletions drivers/net/wireless/hostap/hostap_80211_rx.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <linux/etherdevice.h>
#include <net/ieee80211_crypt.h>
#include <net/lib80211.h>

#include "hostap_80211.h"
#include "hostap.h"
Expand Down Expand Up @@ -649,7 +649,7 @@ static int hostap_is_eapol_frame(local_info_t *local, struct sk_buff *skb)
/* Called only as a tasklet (software IRQ) */
static int
hostap_rx_frame_decrypt(local_info_t *local, struct sk_buff *skb,
struct ieee80211_crypt_data *crypt)
struct lib80211_crypt_data *crypt)
{
struct ieee80211_hdr_4addr *hdr;
int res, hdrlen;
Expand Down Expand Up @@ -687,7 +687,7 @@ hostap_rx_frame_decrypt(local_info_t *local, struct sk_buff *skb,
/* Called only as a tasklet (software IRQ) */
static int
hostap_rx_frame_decrypt_msdu(local_info_t *local, struct sk_buff *skb,
int keyidx, struct ieee80211_crypt_data *crypt)
int keyidx, struct lib80211_crypt_data *crypt)
{
struct ieee80211_hdr_4addr *hdr;
int res, hdrlen;
Expand Down Expand Up @@ -733,7 +733,7 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
int from_assoc_ap = 0;
u8 dst[ETH_ALEN];
u8 src[ETH_ALEN];
struct ieee80211_crypt_data *crypt = NULL;
struct lib80211_crypt_data *crypt = NULL;
void *sta = NULL;
int keyidx = 0;

Expand Down Expand Up @@ -785,7 +785,7 @@ void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
int idx = 0;
if (skb->len >= hdrlen + 3)
idx = skb->data[hdrlen + 3] >> 6;
crypt = local->crypt[idx];
crypt = local->crypt_info.crypt[idx];
sta = NULL;

/* Use station specific key to override default keys if the
Expand Down
8 changes: 5 additions & 3 deletions drivers/net/wireless/hostap/hostap_80211_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ int hostap_mgmt_start_xmit(struct sk_buff *skb, struct net_device *dev)

/* Called only from software IRQ */
static struct sk_buff * hostap_tx_encrypt(struct sk_buff *skb,
struct ieee80211_crypt_data *crypt)
struct lib80211_crypt_data *crypt)
{
struct hostap_interface *iface;
local_info_t *local;
Expand Down Expand Up @@ -405,7 +405,7 @@ int hostap_master_start_xmit(struct sk_buff *skb, struct net_device *dev)
if (local->host_encrypt) {
/* Set crypt to default algorithm and key; will be replaced in
* AP code if STA has own alg/key */
tx.crypt = local->crypt[local->tx_keyidx];
tx.crypt = local->crypt_info.crypt[local->crypt_info.tx_keyidx];
tx.host_encrypt = 1;
} else {
tx.crypt = NULL;
Expand Down Expand Up @@ -487,7 +487,9 @@ int hostap_master_start_xmit(struct sk_buff *skb, struct net_device *dev)

if (tx.crypt && (!tx.crypt->ops || !tx.crypt->ops->encrypt_mpdu))
tx.crypt = NULL;
else if ((tx.crypt || local->crypt[local->tx_keyidx]) && !no_encrypt) {
else if ((tx.crypt ||
local->crypt_info.crypt[local->crypt_info.tx_keyidx]) &&
!no_encrypt) {
/* Add ISWEP flag both for firmware and host based encryption
*/
fc |= IEEE80211_FCTL_PROTECTED;
Expand Down
12 changes: 6 additions & 6 deletions drivers/net/wireless/hostap/hostap_ap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ static void prism2_check_tx_rates(struct sta_info *sta)

static void ap_crypt_init(struct ap_data *ap)
{
ap->crypt = ieee80211_get_crypto_ops("WEP");
ap->crypt = lib80211_get_crypto_ops("WEP");

if (ap->crypt) {
if (ap->crypt->init) {
Expand All @@ -1224,7 +1224,7 @@ static void ap_crypt_init(struct ap_data *ap)

if (ap->crypt == NULL) {
printk(KERN_WARNING "AP could not initialize WEP: load module "
"ieee80211_crypt_wep.ko\n");
"lib80211_crypt_wep.ko\n");
}
}

Expand Down Expand Up @@ -1293,7 +1293,7 @@ static void handle_authen(local_info_t *local, struct sk_buff *skb,
__le16 *pos;
u16 resp = WLAN_STATUS_SUCCESS, fc;
struct sta_info *sta = NULL;
struct ieee80211_crypt_data *crypt;
struct lib80211_crypt_data *crypt;
char *txt = "";

len = skb->len - IEEE80211_MGMT_HDR_LEN;
Expand All @@ -1319,7 +1319,7 @@ static void handle_authen(local_info_t *local, struct sk_buff *skb,
int idx = 0;
if (skb->len >= hdrlen + 3)
idx = skb->data[hdrlen + 3] >> 6;
crypt = local->crypt[idx];
crypt = local->crypt_info.crypt[idx];
}

pos = (__le16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
Expand Down Expand Up @@ -3065,7 +3065,7 @@ ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
/* Called only as a tasklet (software IRQ) */
int hostap_handle_sta_crypto(local_info_t *local,
struct ieee80211_hdr_4addr *hdr,
struct ieee80211_crypt_data **crypt,
struct lib80211_crypt_data **crypt,
void **sta_ptr)
{
struct sta_info *sta;
Expand Down Expand Up @@ -3213,7 +3213,7 @@ void hostap_update_rates(local_info_t *local)


void * ap_crypt_get_ptrs(struct ap_data *ap, u8 *addr, int permanent,
struct ieee80211_crypt_data ***crypt)
struct lib80211_crypt_data ***crypt)
{
struct sta_info *sta;

Expand Down
8 changes: 4 additions & 4 deletions drivers/net/wireless/hostap/hostap_ap.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct sta_info {
u32 tx_since_last_failure;
u32 tx_consecutive_exc;

struct ieee80211_crypt_data *crypt;
struct lib80211_crypt_data *crypt;

int ap; /* whether this station is an AP */

Expand Down Expand Up @@ -209,7 +209,7 @@ struct ap_data {

/* WEP operations for generating challenges to be used with shared key
* authentication */
struct ieee80211_crypto_ops *crypt;
struct lib80211_crypto_ops *crypt;
void *crypt_priv;
#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
};
Expand All @@ -229,7 +229,7 @@ typedef enum {
struct hostap_tx_data {
struct sk_buff *skb;
int host_encrypt;
struct ieee80211_crypt_data *crypt;
struct lib80211_crypt_data *crypt;
void *sta_ptr;
};
ap_tx_ret hostap_handle_sta_tx(local_info_t *local, struct hostap_tx_data *tx);
Expand All @@ -244,7 +244,7 @@ ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
struct hostap_80211_rx_status *rx_stats,
int wds);
int hostap_handle_sta_crypto(local_info_t *local, struct ieee80211_hdr_4addr *hdr,
struct ieee80211_crypt_data **crypt,
struct lib80211_crypt_data **crypt,
void **sta_ptr);
int hostap_is_sta_assoc(struct ap_data *ap, u8 *sta_addr);
int hostap_is_sta_authorized(struct ap_data *ap, u8 *sta_addr);
Expand Down
36 changes: 20 additions & 16 deletions drivers/net/wireless/hostap/hostap_hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include <linux/wireless.h>
#include <net/iw_handler.h>
#include <net/ieee80211.h>
#include <net/ieee80211_crypt.h>
#include <net/lib80211.h>
#include <asm/irq.h>

#include "hostap_80211.h"
Expand Down Expand Up @@ -2791,11 +2791,12 @@ static void prism2_check_sta_fw_version(local_info_t *local)
static void prism2_crypt_deinit_entries(local_info_t *local, int force)
{
struct list_head *ptr, *n;
struct ieee80211_crypt_data *entry;
struct lib80211_crypt_data *entry;

for (ptr = local->crypt_deinit_list.next, n = ptr->next;
ptr != &local->crypt_deinit_list; ptr = n, n = ptr->next) {
entry = list_entry(ptr, struct ieee80211_crypt_data, list);
for (ptr = local->crypt_info.crypt_deinit_list.next, n = ptr->next;
ptr != &local->crypt_info.crypt_deinit_list;
ptr = n, n = ptr->next) {
entry = list_entry(ptr, struct lib80211_crypt_data, list);

if (atomic_read(&entry->refcnt) != 0 && !force)
continue;
Expand All @@ -2816,11 +2817,11 @@ static void prism2_crypt_deinit_handler(unsigned long data)

spin_lock_irqsave(&local->lock, flags);
prism2_crypt_deinit_entries(local, 0);
if (!list_empty(&local->crypt_deinit_list)) {
if (!list_empty(&local->crypt_info.crypt_deinit_list)) {
printk(KERN_DEBUG "%s: entries remaining in delayed crypt "
"deletion list\n", local->dev->name);
local->crypt_deinit_timer.expires = jiffies + HZ;
add_timer(&local->crypt_deinit_timer);
local->crypt_info.crypt_deinit_timer.expires = jiffies + HZ;
add_timer(&local->crypt_info.crypt_deinit_timer);
}
spin_unlock_irqrestore(&local->lock, flags);

Expand Down Expand Up @@ -3250,10 +3251,13 @@ while (0)

INIT_LIST_HEAD(&local->cmd_queue);
init_waitqueue_head(&local->hostscan_wq);
INIT_LIST_HEAD(&local->crypt_deinit_list);
init_timer(&local->crypt_deinit_timer);
local->crypt_deinit_timer.data = (unsigned long) local;
local->crypt_deinit_timer.function = prism2_crypt_deinit_handler;

local->crypt_info.name = dev->name;
local->crypt_info.lock = &local->lock;
INIT_LIST_HEAD(&local->crypt_info.crypt_deinit_list);
init_timer(&local->crypt_info.crypt_deinit_timer);
local->crypt_info.crypt_deinit_timer.data = (unsigned long) local;
local->crypt_info.crypt_deinit_timer.function = prism2_crypt_deinit_handler;

init_timer(&local->passive_scan_timer);
local->passive_scan_timer.data = (unsigned long) local;
Expand Down Expand Up @@ -3354,8 +3358,8 @@ static void prism2_free_local_data(struct net_device *dev)

flush_scheduled_work();

if (timer_pending(&local->crypt_deinit_timer))
del_timer(&local->crypt_deinit_timer);
if (timer_pending(&local->crypt_info.crypt_deinit_timer))
del_timer(&local->crypt_info.crypt_deinit_timer);
prism2_crypt_deinit_entries(local, 1);

if (timer_pending(&local->passive_scan_timer))
Expand All @@ -3374,12 +3378,12 @@ static void prism2_free_local_data(struct net_device *dev)
prism2_callback(local, PRISM2_CALLBACK_DISABLE);

for (i = 0; i < WEP_KEYS; i++) {
struct ieee80211_crypt_data *crypt = local->crypt[i];
struct lib80211_crypt_data *crypt = local->crypt_info.crypt[i];
if (crypt) {
if (crypt->ops)
crypt->ops->deinit(crypt->priv);
kfree(crypt);
local->crypt[i] = NULL;
local->crypt_info.crypt[i] = NULL;
}
}

Expand Down
Loading

0 comments on commit 274bfb8

Please sign in to comment.