[MAC80211]: Add mac80211 wireless stack.
Jiri Benc [Sat, 5 May 2007 18:45:53 +0000 (11:45 -0700)]
Add mac80211, the IEEE 802.11 software MAC layer.

Signed-off-by: Jiri Benc <jbenc@suse.cz>
Signed-off-by: John W. Linville <linville@tuxdriver.com>

34 files changed:
include/net/mac80211.h [new file with mode: 0644]
net/Kconfig
net/Makefile
net/mac80211/Kconfig [new file with mode: 0644]
net/mac80211/Makefile [new file with mode: 0644]
net/mac80211/aes_ccm.c [new file with mode: 0644]
net/mac80211/aes_ccm.h [new file with mode: 0644]
net/mac80211/hostapd_ioctl.h [new file with mode: 0644]
net/mac80211/ieee80211.c [new file with mode: 0644]
net/mac80211/ieee80211_cfg.c [new file with mode: 0644]
net/mac80211/ieee80211_cfg.h [new file with mode: 0644]
net/mac80211/ieee80211_common.h [new file with mode: 0644]
net/mac80211/ieee80211_i.h [new file with mode: 0644]
net/mac80211/ieee80211_iface.c [new file with mode: 0644]
net/mac80211/ieee80211_ioctl.c [new file with mode: 0644]
net/mac80211/ieee80211_key.h [new file with mode: 0644]
net/mac80211/ieee80211_led.c [new file with mode: 0644]
net/mac80211/ieee80211_led.h [new file with mode: 0644]
net/mac80211/ieee80211_rate.c [new file with mode: 0644]
net/mac80211/ieee80211_rate.h [new file with mode: 0644]
net/mac80211/ieee80211_sta.c [new file with mode: 0644]
net/mac80211/michael.c [new file with mode: 0644]
net/mac80211/michael.h [new file with mode: 0644]
net/mac80211/rc80211_simple.c [new file with mode: 0644]
net/mac80211/sta_info.c [new file with mode: 0644]
net/mac80211/sta_info.h [new file with mode: 0644]
net/mac80211/tkip.c [new file with mode: 0644]
net/mac80211/tkip.h [new file with mode: 0644]
net/mac80211/wep.c [new file with mode: 0644]
net/mac80211/wep.h [new file with mode: 0644]
net/mac80211/wme.c [new file with mode: 0644]
net/mac80211/wme.h [new file with mode: 0644]
net/mac80211/wpa.c [new file with mode: 0644]
net/mac80211/wpa.h [new file with mode: 0644]

diff --git a/include/net/mac80211.h b/include/net/mac80211.h
new file mode 100644 (file)
index 0000000..a7f122b
--- /dev/null
@@ -0,0 +1,1045 @@
+/*
+ * Low-level hardware driver -- IEEE 802.11 driver (80211.o) interface
+ * Copyright 2002-2005, Devicescape Software, Inc.
+ * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef MAC80211_H
+#define MAC80211_H
+
+#include <linux/kernel.h>
+#include <linux/if_ether.h>
+#include <linux/skbuff.h>
+#include <linux/wireless.h>
+#include <linux/device.h>
+#include <linux/ieee80211.h>
+#include <net/wireless.h>
+#include <net/cfg80211.h>
+
+/* Note! Only ieee80211_tx_status_irqsafe() and ieee80211_rx_irqsafe() can be
+ * called in hardware interrupt context. The low-level driver must not call any
+ * other functions in hardware interrupt context. If there is a need for such
+ * call, the low-level driver should first ACK the interrupt and perform the
+ * IEEE 802.11 code call after this, e.g., from a scheduled tasklet (in
+ * software interrupt context).
+ */
+
+/*
+ * Frame format used when passing frame between low-level hardware drivers
+ * and IEEE 802.11 driver the same as used in the wireless media, i.e.,
+ * buffers start with IEEE 802.11 header and include the same octets that
+ * are sent over air.
+ *
+ * If hardware uses IEEE 802.3 headers (and perform 802.3 <-> 802.11
+ * conversion in firmware), upper layer 802.11 code needs to be changed to
+ * support this.
+ *
+ * If the receive frame format is not the same as the real frame sent
+ * on the wireless media (e.g., due to padding etc.), upper layer 802.11 code
+ * could be updated to provide support for such format assuming this would
+ * optimize the performance, e.g., by removing need to re-allocation and
+ * copying of the data.
+ */
+
+#define IEEE80211_CHAN_W_SCAN 0x00000001
+#define IEEE80211_CHAN_W_ACTIVE_SCAN 0x00000002
+#define IEEE80211_CHAN_W_IBSS 0x00000004
+
+/* Channel information structure. Low-level driver is expected to fill in chan,
+ * freq, and val fields. Other fields will be filled in by 80211.o based on
+ * hostapd information and low-level driver does not need to use them. The
+ * limits for each channel will be provided in 'struct ieee80211_conf' when
+ * configuring the low-level driver with hw->config callback. If a device has
+ * a default regulatory domain, IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED
+ * can be set to let the driver configure all fields */
+struct ieee80211_channel {
+       short chan; /* channel number (IEEE 802.11) */
+       short freq; /* frequency in MHz */
+       int val; /* hw specific value for the channel */
+       int flag; /* flag for hostapd use (IEEE80211_CHAN_*) */
+       unsigned char power_level;
+       unsigned char antenna_max;
+};
+
+#define IEEE80211_RATE_ERP 0x00000001
+#define IEEE80211_RATE_BASIC 0x00000002
+#define IEEE80211_RATE_PREAMBLE2 0x00000004
+#define IEEE80211_RATE_SUPPORTED 0x00000010
+#define IEEE80211_RATE_OFDM 0x00000020
+#define IEEE80211_RATE_CCK 0x00000040
+#define IEEE80211_RATE_TURBO 0x00000080
+#define IEEE80211_RATE_MANDATORY 0x00000100
+
+#define IEEE80211_RATE_CCK_2 (IEEE80211_RATE_CCK | IEEE80211_RATE_PREAMBLE2)
+#define IEEE80211_RATE_MODULATION(f) \
+       (f & (IEEE80211_RATE_CCK | IEEE80211_RATE_OFDM))
+
+/* Low-level driver should set PREAMBLE2, OFDM, CCK, and TURBO flags.
+ * BASIC, SUPPORTED, ERP, and MANDATORY flags are set in 80211.o based on the
+ * configuration. */
+struct ieee80211_rate {
+       int rate; /* rate in 100 kbps */
+       int val; /* hw specific value for the rate */
+       int flags; /* IEEE80211_RATE_ flags */
+       int val2; /* hw specific value for the rate when using short preamble
+                  * (only when IEEE80211_RATE_PREAMBLE2 flag is set, i.e., for
+                  * 2, 5.5, and 11 Mbps) */
+       signed char min_rssi_ack;
+       unsigned char min_rssi_ack_delta;
+
+       /* following fields are set by 80211.o and need not be filled by the
+        * low-level driver */
+       int rate_inv; /* inverse of the rate (LCM(all rates) / rate) for
+                      * optimizing channel utilization estimates */
+};
+
+/* 802.11g is backwards-compatible with 802.11b, so a wlan card can
+ * actually be both in 11b and 11g modes at the same time. */
+enum {
+       MODE_IEEE80211A, /* IEEE 802.11a */
+       MODE_IEEE80211B, /* IEEE 802.11b only */
+       MODE_ATHEROS_TURBO, /* Atheros Turbo mode (2x.11a at 5 GHz) */
+       MODE_IEEE80211G, /* IEEE 802.11g (and 802.11b compatibility) */
+       MODE_ATHEROS_TURBOG, /* Atheros Turbo mode (2x.11g at 2.4 GHz) */
+
+       /* keep last */
+       NUM_IEEE80211_MODES
+};
+
+struct ieee80211_hw_mode {
+       int mode; /* MODE_IEEE80211... */
+       int num_channels; /* Number of channels (below) */
+       struct ieee80211_channel *channels; /* Array of supported channels */
+       int num_rates; /* Number of rates (below) */
+       struct ieee80211_rate *rates; /* Array of supported rates */
+
+       struct list_head list; /* Internal, don't touch */
+};
+
+struct ieee80211_tx_queue_params {
+       int aifs; /* 0 .. 255; -1 = use default */
+       int cw_min; /* 2^n-1: 1, 3, 7, .. , 1023; 0 = use default */
+       int cw_max; /* 2^n-1: 1, 3, 7, .. , 1023; 0 = use default */
+       int burst_time; /* maximum burst time in 0.1 ms (i.e., 10 = 1 ms);
+                        * 0 = disabled */
+};
+
+struct ieee80211_tx_queue_stats_data {
+       unsigned int len; /* num packets in queue */
+       unsigned int limit; /* queue len (soft) limit */
+       unsigned int count; /* total num frames sent */
+};
+
+enum {
+       IEEE80211_TX_QUEUE_DATA0,
+       IEEE80211_TX_QUEUE_DATA1,
+       IEEE80211_TX_QUEUE_DATA2,
+       IEEE80211_TX_QUEUE_DATA3,
+       IEEE80211_TX_QUEUE_DATA4,
+       IEEE80211_TX_QUEUE_SVP,
+
+       NUM_TX_DATA_QUEUES,
+
+/* due to stupidity in the sub-ioctl userspace interface, the items in
+ * this struct need to have fixed values. As soon as it is removed, we can
+ * fix these entries. */
+       IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
+       IEEE80211_TX_QUEUE_BEACON = 7
+};
+
+struct ieee80211_tx_queue_stats {
+       struct ieee80211_tx_queue_stats_data data[NUM_TX_DATA_QUEUES];
+};
+
+struct ieee80211_low_level_stats {
+       unsigned int dot11ACKFailureCount;
+       unsigned int dot11RTSFailureCount;
+       unsigned int dot11FCSErrorCount;
+       unsigned int dot11RTSSuccessCount;
+};
+
+/* Transmit control fields. This data structure is passed to low-level driver
+ * with each TX frame. The low-level driver is responsible for configuring
+ * the hardware to use given values (depending on what is supported). */
+#define HW_KEY_IDX_INVALID -1
+
+struct ieee80211_tx_control {
+       int tx_rate; /* Transmit rate, given as the hw specific value for the
+                     * rate (from struct ieee80211_rate) */
+       int rts_cts_rate; /* Transmit rate for RTS/CTS frame, given as the hw
+                          * specific value for the rate (from
+                          * struct ieee80211_rate) */
+
+#define IEEE80211_TXCTL_REQ_TX_STATUS  (1<<0)/* request TX status callback for
+                                               * this frame */
+#define IEEE80211_TXCTL_DO_NOT_ENCRYPT (1<<1) /* send this frame without
+                                               * encryption; e.g., for EAPOL
+                                               * frames */
+#define IEEE80211_TXCTL_USE_RTS_CTS    (1<<2) /* use RTS-CTS before sending
+                                               * frame */
+#define IEEE80211_TXCTL_USE_CTS_PROTECT        (1<<3) /* use CTS protection for the
+                                               * frame (e.g., for combined
+                                               * 802.11g / 802.11b networks) */
+#define IEEE80211_TXCTL_NO_ACK         (1<<4) /* tell the low level not to
+                                               * wait for an ack */
+#define IEEE80211_TXCTL_RATE_CTRL_PROBE        (1<<5)
+#define IEEE80211_TXCTL_CLEAR_DST_MASK (1<<6)
+#define IEEE80211_TXCTL_REQUEUE                (1<<7)
+#define IEEE80211_TXCTL_FIRST_FRAGMENT (1<<8) /* this is a first fragment of
+                                               * the frame */
+#define IEEE80211_TXCTL_TKIP_NEW_PHASE1_KEY (1<<9)
+       u32 flags;                             /* tx control flags defined
+                                               * above */
+       u8 retry_limit;         /* 1 = only first attempt, 2 = one retry, .. */
+       u8 power_level;         /* per-packet transmit power level, in dBm */
+       u8 antenna_sel_tx;      /* 0 = default/diversity, 1 = Ant0, 2 = Ant1 */
+       s8 key_idx;             /* -1 = do not encrypt, >= 0 keyidx from
+                                * hw->set_key() */
+       u8 icv_len;             /* length of the ICV/MIC field in octets */
+       u8 iv_len;              /* length of the IV field in octets */
+       u8 tkip_key[16];        /* generated phase2/phase1 key for hw TKIP */
+       u8 queue;               /* hardware queue to use for this frame;
+                                * 0 = highest, hw->queues-1 = lowest */
+       u8 sw_retry_attempt;    /* number of times hw has tried to
+                                * transmit frame (not incl. hw retries) */
+
+       struct ieee80211_rate *rate;            /* internal 80211.o rate */
+       struct ieee80211_rate *rts_rate;        /* internal 80211.o rate
+                                                * for RTS/CTS */
+       int alt_retry_rate; /* retry rate for the last retries, given as the
+                            * hw specific value for the rate (from
+                            * struct ieee80211_rate). To be used to limit
+                            * packet dropping when probing higher rates, if hw
+                            * supports multiple retry rates. -1 = not used */
+       int type;       /* internal */
+       int ifindex;    /* internal */
+};
+
+/* Receive status. The low-level driver should provide this information
+ * (the subset supported by hardware) to the 802.11 code with each received
+ * frame. */
+struct ieee80211_rx_status {
+       u64 mactime;
+       int freq; /* receive frequency in Mhz */
+       int channel;
+       int phymode;
+       int ssi;
+       int signal; /* used as qual in statistics reporting */
+       int noise;
+       int antenna;
+       int rate;
+#define RX_FLAG_MMIC_ERROR     (1<<0)
+#define RX_FLAG_DECRYPTED      (1<<1)
+#define RX_FLAG_RADIOTAP       (1<<2)
+       int flag;
+};
+
+/* Transmit status. The low-level driver should provide this information
+ * (the subset supported by hardware) to the 802.11 code for each transmit
+ * frame. */
+struct ieee80211_tx_status {
+       /* copied ieee80211_tx_control structure */
+       struct ieee80211_tx_control control;
+
+#define IEEE80211_TX_STATUS_TX_FILTERED        (1<<0)
+#define IEEE80211_TX_STATUS_ACK                (1<<1) /* whether the TX frame was ACKed */
+       u32 flags;              /* tx staus flags defined above */
+
+       int ack_signal; /* measured signal strength of the ACK frame */
+       int excessive_retries;
+       int retry_count;
+
+       int queue_length;      /* information about TX queue */
+       int queue_number;
+};
+
+
+/**
+ * struct ieee80211_conf - configuration of the device
+ *
+ * This struct indicates how the driver shall configure the hardware.
+ *
+ * @radio_enabled: when zero, driver is required to switch off the radio.
+ */
+struct ieee80211_conf {
+       int channel;                    /* IEEE 802.11 channel number */
+       int freq;                       /* MHz */
+       int channel_val;                /* hw specific value for the channel */
+
+       int phymode;                    /* MODE_IEEE80211A, .. */
+       struct ieee80211_channel *chan;
+       struct ieee80211_hw_mode *mode;
+       unsigned int regulatory_domain;
+       int radio_enabled;
+
+       int beacon_int;
+
+#define IEEE80211_CONF_SHORT_SLOT_TIME (1<<0) /* use IEEE 802.11g Short Slot
+                                               * Time */
+#define IEEE80211_CONF_SSID_HIDDEN     (1<<1) /* do not broadcast the ssid */
+#define IEEE80211_CONF_RADIOTAP                (1<<2) /* use radiotap if supported
+                                                 check this bit at RX time */
+       u32 flags;                      /* configuration flags defined above */
+
+       u8 power_level;                 /* transmit power limit for current
+                                        * regulatory domain; in dBm */
+       u8 antenna_max;                 /* maximum antenna gain */
+       short tx_power_reduction; /* in 0.1 dBm */
+
+       /* 0 = default/diversity, 1 = Ant0, 2 = Ant1 */
+       u8 antenna_sel_tx;
+       u8 antenna_sel_rx;
+
+       int antenna_def;
+       int antenna_mode;
+
+       /* Following five fields are used for IEEE 802.11H */
+       unsigned int radar_detect;
+       unsigned int spect_mgmt;
+       /* All following fields are currently unused. */
+       unsigned int quiet_duration; /* duration of quiet period */
+       unsigned int quiet_offset; /* how far into the beacon is the quiet
+                                   * period */
+       unsigned int quiet_period;
+       u8 radar_firpwr_threshold;
+       u8 radar_rssi_threshold;
+       u8 pulse_height_threshold;
+       u8 pulse_rssi_threshold;
+       u8 pulse_inband_threshold;
+};
+
+/**
+ * enum ieee80211_if_types - types of 802.11 network interfaces
+ *
+ * @IEEE80211_IF_TYPE_AP: interface in AP mode.
+ * @IEEE80211_IF_TYPE_MGMT: special interface for communication with hostap
+ *     daemon. Drivers should never see this type.
+ * @IEEE80211_IF_TYPE_STA: interface in STA (client) mode.
+ * @IEEE80211_IF_TYPE_IBSS: interface in IBSS (ad-hoc) mode.
+ * @IEEE80211_IF_TYPE_MNTR: interface in monitor (rfmon) mode.
+ * @IEEE80211_IF_TYPE_WDS: interface in WDS mode.
+ * @IEEE80211_IF_TYPE_VLAN: not used.
+ */
+enum ieee80211_if_types {
+       IEEE80211_IF_TYPE_AP = 0x00000000,
+       IEEE80211_IF_TYPE_MGMT = 0x00000001,
+       IEEE80211_IF_TYPE_STA = 0x00000002,
+       IEEE80211_IF_TYPE_IBSS = 0x00000003,
+       IEEE80211_IF_TYPE_MNTR = 0x00000004,
+       IEEE80211_IF_TYPE_WDS = 0x5A580211,
+       IEEE80211_IF_TYPE_VLAN = 0x00080211,
+};
+
+/**
+ * struct ieee80211_if_init_conf - initial configuration of an interface
+ *
+ * @if_id: internal interface ID. This number has no particular meaning to
+ *     drivers and the only allowed usage is to pass it to
+ *     ieee80211_beacon_get() and ieee80211_get_buffered_bc() functions.
+ *     This field is not valid for monitor interfaces
+ *     (interfaces of %IEEE80211_IF_TYPE_MNTR type).
+ * @type: one of &enum ieee80211_if_types constants. Determines the type of
+ *     added/removed interface.
+ * @mac_addr: pointer to MAC address of the interface. This pointer is valid
+ *     until the interface is removed (i.e. it cannot be used after
+ *     remove_interface() callback was called for this interface).
+ *
+ * This structure is used in add_interface() and remove_interface()
+ * callbacks of &struct ieee80211_hw.
+ */
+struct ieee80211_if_init_conf {
+       int if_id;
+       int type;
+       void *mac_addr;
+};
+
+/**
+ * struct ieee80211_if_conf - configuration of an interface
+ *
+ * @type: type of the interface. This is always the same as was specified in
+ *     &struct ieee80211_if_init_conf. The type of an interface never changes
+ *     during the life of the interface; this field is present only for
+ *     convenience.
+ * @bssid: BSSID of the network we are associated to/creating.
+ * @ssid: used (together with @ssid_len) by drivers for hardware that
+ *     generate beacons independently. The pointer is valid only during the
+ *     config_interface() call, so copy the value somewhere if you need
+ *     it.
+ * @ssid_len: length of the @ssid field.
+ * @generic_elem: used (together with @generic_elem_len) by drivers for
+ *     hardware that generate beacons independently. The pointer is valid
+ *     only during the config_interface() call, so copy the value somewhere
+ *     if you need it.
+ * @generic_elem_len: length of the generic element.
+ * @beacon: beacon template. Valid only if @host_gen_beacon_template in
+ *     &struct ieee80211_hw is set. The driver is responsible of freeing
+ *     the sk_buff.
+ * @beacon_control: tx_control for the beacon template, this field is only
+ *     valid when the @beacon field was set.
+ *
+ * This structure is passed to the config_interface() callback of
+ * &struct ieee80211_hw.
+ */
+struct ieee80211_if_conf {
+       int type;
+       u8 *bssid;
+       u8 *ssid;
+       size_t ssid_len;
+       u8 *generic_elem;
+       size_t generic_elem_len;
+       struct sk_buff *beacon;
+       struct ieee80211_tx_control *beacon_control;
+};
+
+typedef enum { ALG_NONE, ALG_WEP, ALG_TKIP, ALG_CCMP, ALG_NULL }
+ieee80211_key_alg;
+
+
+struct ieee80211_key_conf {
+
+       int hw_key_idx;                 /* filled + used by low-level driver */
+       ieee80211_key_alg alg;
+       int keylen;
+
+#define IEEE80211_KEY_FORCE_SW_ENCRYPT (1<<0) /* to be cleared by low-level
+                                                driver */
+#define IEEE80211_KEY_DEFAULT_TX_KEY   (1<<1) /* This key is the new default TX
+                                                key (used only for broadcast
+                                                keys). */
+#define IEEE80211_KEY_DEFAULT_WEP_ONLY (1<<2) /* static WEP is the only
+                                                configured security policy;
+                                                this allows some low-level
+                                                drivers to determine when
+                                                hwaccel can be used */
+       u32 flags; /* key configuration flags defined above */
+
+       s8 keyidx;                      /* WEP key index */
+       u8 key[0];
+};
+
+#define IEEE80211_SEQ_COUNTER_RX       0
+#define IEEE80211_SEQ_COUNTER_TX       1
+
+typedef enum {
+       SET_KEY, DISABLE_KEY, REMOVE_ALL_KEYS,
+} set_key_cmd;
+
+/* This is driver-visible part of the per-hw state the stack keeps. */
+struct ieee80211_hw {
+       /* points to the cfg80211 wiphy for this piece. Note
+        * that you must fill in the perm_addr and dev fields
+        * of this structure, use the macros provided below. */
+       struct wiphy *wiphy;
+
+       /* assigned by mac80211, don't write */
+       struct ieee80211_conf conf;
+
+       /* Single thread workqueue available for driver use
+        * Allocated by mac80211 on registration */
+       struct workqueue_struct *workqueue;
+
+       /* Pointer to the private area that was
+        * allocated with this struct for you. */
+       void *priv;
+
+       /* The rest is information about your hardware */
+
+       /* TODO: frame_type 802.11/802.3, sw_encryption requirements */
+
+       /* Some wireless LAN chipsets generate beacons in the hardware/firmware
+        * and others rely on host generated beacons. This option is used to
+        * configure the upper layer IEEE 802.11 module to generate beacons.
+        * The low-level driver can use ieee80211_beacon_get() to fetch the
+        * next beacon frame. */
+#define IEEE80211_HW_HOST_GEN_BEACON (1<<0)
+
+       /* The device needs to be supplied with a beacon template only. */
+#define IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE (1<<1)
+
+       /* Some devices handle decryption internally and do not
+        * indicate whether the frame was encrypted (unencrypted frames
+        * will be dropped by the hardware, unless specifically allowed
+        * through) */
+#define IEEE80211_HW_DEVICE_HIDES_WEP (1<<2)
+
+       /* Whether RX frames passed to ieee80211_rx() include FCS in the end */
+#define IEEE80211_HW_RX_INCLUDES_FCS (1<<3)
+
+       /* Some wireless LAN chipsets buffer broadcast/multicast frames for
+        * power saving stations in the hardware/firmware and others rely on
+        * the host system for such buffering. This option is used to
+        * configure the IEEE 802.11 upper layer to buffer broadcast/multicast
+        * frames when there are power saving stations so that low-level driver
+        * can fetch them with ieee80211_get_buffered_bc(). */
+#define IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING (1<<4)
+
+#define IEEE80211_HW_WEP_INCLUDE_IV (1<<5)
+
+       /* will data nullfunc frames get proper TX status callback */
+#define IEEE80211_HW_DATA_NULLFUNC_ACK (1<<6)
+
+       /* Force software encryption for TKIP packets if WMM is enabled. */
+#define IEEE80211_HW_NO_TKIP_WMM_HWACCEL (1<<7)
+
+       /* Some devices handle Michael MIC internally and do not include MIC in
+        * the received packets passed up. device_strips_mic must be set
+        * for such devices. The 'encryption' frame control bit is expected to
+        * be still set in the IEEE 802.11 header with this option unlike with
+        * the device_hides_wep configuration option.
+        */
+#define IEEE80211_HW_DEVICE_STRIPS_MIC (1<<8)
+
+       /* Device is capable of performing full monitor mode even during
+        * normal operation. */
+#define IEEE80211_HW_MONITOR_DURING_OPER (1<<9)
+
+       /* Device does not need BSSID filter set to broadcast in order to
+        * receive all probe responses while scanning */
+#define IEEE80211_HW_NO_PROBE_FILTERING (1<<10)
+
+       /* Channels are already configured to the default regulatory domain
+        * specified in the device's EEPROM */
+#define IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED (1<<11)
+
+       /* calculate Michael MIC for an MSDU when doing hwcrypto */
+#define IEEE80211_HW_TKIP_INCLUDE_MMIC (1<<12)
+       /* Do TKIP phase1 key mixing in stack to support cards only do
+        * phase2 key mixing when doing hwcrypto */
+#define IEEE80211_HW_TKIP_REQ_PHASE1_KEY (1<<13)
+       /* Do TKIP phase1 and phase2 key mixing in stack and send the generated
+        * per-packet RC4 key with each TX frame when doing hwcrypto */
+#define IEEE80211_HW_TKIP_REQ_PHASE2_KEY (1<<14)
+
+       u32 flags;                      /* hardware flags defined above */
+
+       /* Set to the size of a needed device specific skb headroom for TX skbs. */
+       unsigned int extra_tx_headroom;
+
+       /* This is the time in us to change channels
+        */
+       int channel_change_time;
+       /* Maximum values for various statistics.
+        * Leave at 0 to indicate no support. Use negative numbers for dBm. */
+       s8 max_rssi;
+       s8 max_signal;
+       s8 max_noise;
+
+       /* Number of available hardware TX queues for data packets.
+        * WMM requires at least four queues. */
+       int queues;
+};
+
+static inline void SET_IEEE80211_DEV(struct ieee80211_hw *hw, struct device *dev)
+{
+       set_wiphy_dev(hw->wiphy, dev);
+}
+
+static inline void SET_IEEE80211_PERM_ADDR(struct ieee80211_hw *hw, u8 *addr)
+{
+       memcpy(hw->wiphy->perm_addr, addr, ETH_ALEN);
+}
+
+/* Configuration block used by the low-level driver to tell the 802.11 code
+ * about supported hardware features and to pass function pointers to callback
+ * functions. */
+struct ieee80211_ops {
+       /* Handler that 802.11 module calls for each transmitted frame.
+        * skb contains the buffer starting from the IEEE 802.11 header.
+        * The low-level driver should send the frame out based on
+        * configuration in the TX control data.
+        * Must be atomic. */
+       int (*tx)(struct ieee80211_hw *hw, struct sk_buff *skb,
+                 struct ieee80211_tx_control *control);
+
+       /* Handler for performing hardware reset. */
+       int (*reset)(struct ieee80211_hw *hw);
+
+       /* Handler that is called when any netdevice attached to the hardware
+        * device is set UP for the first time. This can be used, e.g., to
+        * enable interrupts and beacon sending. */
+       int (*open)(struct ieee80211_hw *hw);
+
+       /* Handler that is called when the last netdevice attached to the
+        * hardware device is set DOWN. This can be used, e.g., to disable
+        * interrupts and beacon sending. */
+       int (*stop)(struct ieee80211_hw *hw);
+
+       /* Handler for asking a driver if a new interface can be added (or,
+        * more exactly, set UP). If the handler returns zero, the interface
+        * is added. Driver should perform any initialization it needs prior
+        * to returning zero. By returning non-zero addition of the interface
+        * is inhibited. Unless monitor_during_oper is set, it is guaranteed
+        * that monitor interfaces and normal interfaces are mutually
+        * exclusive. The open() handler is called after add_interface()
+        * if this is the first device added. At least one of the open()
+        * open() and add_interface() callbacks has to be assigned. If
+        * add_interface() is NULL, one STA interface is permitted only. */
+       int (*add_interface)(struct ieee80211_hw *hw,
+                            struct ieee80211_if_init_conf *conf);
+
+       /* Notify a driver that an interface is going down. The stop() handler
+        * is called prior to this if this is a last interface. */
+       void (*remove_interface)(struct ieee80211_hw *hw,
+                                struct ieee80211_if_init_conf *conf);
+
+       /* Handler for configuration requests. IEEE 802.11 code calls this
+        * function to change hardware configuration, e.g., channel. */
+       int (*config)(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
+
+       /* Handler for configuration requests related to interfaces (e.g.
+        * BSSID). */
+       int (*config_interface)(struct ieee80211_hw *hw,
+                               int if_id, struct ieee80211_if_conf *conf);
+
+       /* ieee80211 drivers do not have access to the &struct net_device
+        * that is (are) connected with their device. Hence (and because
+        * we need to combine the multicast lists and flags for multiple
+        * virtual interfaces), they cannot assign set_multicast_list.
+        * The parameters here replace dev->flags and dev->mc_count,
+        * dev->mc_list is replaced by calling ieee80211_get_mc_list_item.
+        * Must be atomic. */
+       void (*set_multicast_list)(struct ieee80211_hw *hw,
+                                  unsigned short flags, int mc_count);
+
+       /* Set TIM bit handler. If the hardware/firmware takes care of beacon
+        * generation, IEEE 802.11 code uses this function to tell the
+        * low-level to set (or clear if set==0) TIM bit for the given aid. If
+        * host system is used to generate beacons, this handler is not used
+        * and low-level driver should set it to NULL.
+        * Must be atomic. */
+       int (*set_tim)(struct ieee80211_hw *hw, int aid, int set);
+
+       /* Set encryption key. IEEE 802.11 module calls this function to set
+        * encryption keys. addr is ff:ff:ff:ff:ff:ff for default keys and
+        * station hwaddr for individual keys. aid of the station is given
+        * to help low-level driver in selecting which key->hw_key_idx to use
+        * for this key. TX control data will use the hw_key_idx selected by
+        * the low-level driver.
+        * Must be atomic. */
+       int (*set_key)(struct ieee80211_hw *hw, set_key_cmd cmd,
+                      u8 *addr, struct ieee80211_key_conf *key, int aid);
+
+       /* Set TX key index for default/broadcast keys. This is needed in cases
+        * where wlan card is doing full WEP/TKIP encapsulation (wep_include_iv
+        * is not set), in other cases, this function pointer can be set to
+        * NULL since the IEEE 802. 11 module takes care of selecting the key
+        * index for each TX frame. */
+       int (*set_key_idx)(struct ieee80211_hw *hw, int idx);
+
+       /* Enable/disable IEEE 802.1X. This item requests wlan card to pass
+        * unencrypted EAPOL-Key frames even when encryption is configured.
+        * If the wlan card does not require such a configuration, this
+        * function pointer can be set to NULL. */
+       int (*set_ieee8021x)(struct ieee80211_hw *hw, int use_ieee8021x);
+
+       /* Set port authorization state (IEEE 802.1X PAE) to be authorized
+        * (authorized=1) or unauthorized (authorized=0). This function can be
+        * used if the wlan hardware or low-level driver implements PAE.
+        * 80211.o module will anyway filter frames based on authorization
+        * state, so this function pointer can be NULL if low-level driver does
+        * not require event notification about port state changes.
+        * Currently unused. */
+       int (*set_port_auth)(struct ieee80211_hw *hw, u8 *addr,
+                            int authorized);
+
+       /* Ask the hardware to service the scan request, no need to start
+        * the scan state machine in stack. */
+       int (*hw_scan)(struct ieee80211_hw *hw, u8 *ssid, size_t len);
+
+       /* return low-level statistics */
+       int (*get_stats)(struct ieee80211_hw *hw,
+                        struct ieee80211_low_level_stats *stats);
+
+       /* For devices that generate their own beacons and probe response
+        * or association responses this updates the state of privacy_invoked
+        * returns 0 for success or an error number */
+       int (*set_privacy_invoked)(struct ieee80211_hw *hw,
+                                  int privacy_invoked);
+
+       /* For devices that have internal sequence counters, allow 802.11
+        * code to access the current value of a counter */
+       int (*get_sequence_counter)(struct ieee80211_hw *hw,
+                                   u8* addr, u8 keyidx, u8 txrx,
+                                   u32* iv32, u16* iv16);
+
+       /* Configuration of RTS threshold (if device needs it) */
+       int (*set_rts_threshold)(struct ieee80211_hw *hw, u32 value);
+
+       /* Configuration of fragmentation threshold.
+        * Assign this if the device does fragmentation by itself,
+        * if this method is assigned then the stack will not do
+        * fragmentation. */
+       int (*set_frag_threshold)(struct ieee80211_hw *hw, u32 value);
+
+       /* Configuration of retry limits (if device needs it) */
+       int (*set_retry_limit)(struct ieee80211_hw *hw,
+                              u32 short_retry, u32 long_retr);
+
+       /* Number of STAs in STA table notification (NULL = disabled).
+        * Must be atomic. */
+       void (*sta_table_notification)(struct ieee80211_hw *hw,
+                                      int num_sta);
+
+       /* Configure TX queue parameters (EDCF (aifs, cw_min, cw_max),
+        * bursting) for a hardware TX queue.
+        * queue = IEEE80211_TX_QUEUE_*.
+        * Must be atomic. */
+       int (*conf_tx)(struct ieee80211_hw *hw, int queue,
+                      const struct ieee80211_tx_queue_params *params);
+
+       /* Get statistics of the current TX queue status. This is used to get
+        * number of currently queued packets (queue length), maximum queue
+        * size (limit), and total number of packets sent using each TX queue
+        * (count).
+        * Currently unused. */
+       int (*get_tx_stats)(struct ieee80211_hw *hw,
+                           struct ieee80211_tx_queue_stats *stats);
+
+       /* Get the current TSF timer value from firmware/hardware. Currently,
+        * this is only used for IBSS mode debugging and, as such, is not a
+        * required function.
+        * Must be atomic. */
+       u64 (*get_tsf)(struct ieee80211_hw *hw);
+
+       /* Reset the TSF timer and allow firmware/hardware to synchronize with
+        * other STAs in the IBSS. This is only used in IBSS mode. This
+        * function is optional if the firmware/hardware takes full care of
+        * TSF synchronization. */
+       void (*reset_tsf)(struct ieee80211_hw *hw);
+
+       /* Setup beacon data for IBSS beacons. Unlike access point (Master),
+        * IBSS uses a fixed beacon frame which is configured using this
+        * function. This handler is required only for IBSS mode. */
+       int (*beacon_update)(struct ieee80211_hw *hw,
+                            struct sk_buff *skb,
+                            struct ieee80211_tx_control *control);
+
+       /* Determine whether the last IBSS beacon was sent by us. This is
+        * needed only for IBSS mode and the result of this function is used to
+        * determine whether to reply to Probe Requests. */
+       int (*tx_last_beacon)(struct ieee80211_hw *hw);
+};
+
+/* Allocate a new hardware device. This must be called once for each
+ * hardware device. The returned pointer must be used to refer to this
+ * device when calling other functions. 802.11 code allocates a private data
+ * area for the low-level driver. The size of this area is given as
+ * priv_data_len.
+ */
+struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
+                                       const struct ieee80211_ops *ops);
+
+/* Register hardware device to the IEEE 802.11 code and kernel. Low-level
+ * drivers must call this function before using any other IEEE 802.11
+ * function except ieee80211_register_hwmode. */
+int ieee80211_register_hw(struct ieee80211_hw *hw);
+
+/* driver can use this and ieee80211_get_rx_led_name to get the
+ * name of the registered LEDs after ieee80211_register_hw
+ * was called.
+ * This is useful to set the default trigger on the LED class
+ * device that your driver should export for each LED the device
+ * has, that way the default behaviour will be as expected but
+ * the user can still change it/turn off the LED etc.
+ */
+#ifdef CONFIG_MAC80211_LEDS
+extern char *__ieee80211_get_tx_led_name(struct ieee80211_hw *hw);
+extern char *__ieee80211_get_rx_led_name(struct ieee80211_hw *hw);
+#endif
+static inline char *ieee80211_get_tx_led_name(struct ieee80211_hw *hw)
+{
+#ifdef CONFIG_MAC80211_LEDS
+       return __ieee80211_get_tx_led_name(hw);
+#else
+       return NULL;
+#endif
+}
+
+static inline char *ieee80211_get_rx_led_name(struct ieee80211_hw *hw)
+{
+#ifdef CONFIG_MAC80211_LEDS
+       return __ieee80211_get_rx_led_name(hw);
+#else
+       return NULL;
+#endif
+}
+
+/* Register a new hardware PHYMODE capability to the stack. */
+int ieee80211_register_hwmode(struct ieee80211_hw *hw,
+                             struct ieee80211_hw_mode *mode);
+
+/* Unregister a hardware device. This function instructs 802.11 code to free
+ * allocated resources and unregister netdevices from the kernel. */
+void ieee80211_unregister_hw(struct ieee80211_hw *hw);
+
+/* Free everything that was allocated including private data of a driver. */
+void ieee80211_free_hw(struct ieee80211_hw *hw);
+
+/* Receive frame callback function. The low-level driver uses this function to
+ * send received frames to the IEEE 802.11 code. Receive buffer (skb) must
+ * start with IEEE 802.11 header. */
+void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
+                   struct ieee80211_rx_status *status);
+void ieee80211_rx_irqsafe(struct ieee80211_hw *hw,
+                         struct sk_buff *skb,
+                         struct ieee80211_rx_status *status);
+
+/* Transmit status callback function. The low-level driver must call this
+ * function to report transmit status for all the TX frames that had
+ * req_tx_status set in the transmit control fields. In addition, this should
+ * be called at least for all unicast frames to provide information for TX rate
+ * control algorithm. In order to maintain all statistics, this function is
+ * recommended to be called after each frame, including multicast/broadcast, is
+ * sent. */
+void ieee80211_tx_status(struct ieee80211_hw *hw,
+                        struct sk_buff *skb,
+                        struct ieee80211_tx_status *status);
+void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
+                                struct sk_buff *skb,
+                                struct ieee80211_tx_status *status);
+
+/**
+ * ieee80211_beacon_get - beacon generation function
+ * @hw: pointer obtained from ieee80211_alloc_hw().
+ * @if_id: interface ID from &struct ieee80211_if_init_conf.
+ * @control: will be filled with information needed to send this beacon.
+ *
+ * If the beacon frames are generated by the host system (i.e., not in
+ * hardware/firmware), the low-level driver uses this function to receive
+ * the next beacon frame from the 802.11 code. The low-level is responsible
+ * for calling this function before beacon data is needed (e.g., based on
+ * hardware interrupt). Returned skb is used only once and low-level driver
+ * is responsible of freeing it.
+ */
+struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
+                                    int if_id,
+                                    struct ieee80211_tx_control *control);
+
+/**
+ * ieee80211_rts_get - RTS frame generation function
+ * @hw: pointer obtained from ieee80211_alloc_hw().
+ * @frame: pointer to the frame that is going to be protected by the RTS.
+ * @frame_len: the frame length (in octets).
+ * @frame_txctl: &struct ieee80211_tx_control of the frame.
+ * @rts: The buffer where to store the RTS frame.
+ *
+ * If the RTS frames are generated by the host system (i.e., not in
+ * hardware/firmware), the low-level driver uses this function to receive
+ * the next RTS frame from the 802.11 code. The low-level is responsible
+ * for calling this function before and RTS frame is needed.
+ */
+void ieee80211_rts_get(struct ieee80211_hw *hw,
+                      const void *frame, size_t frame_len,
+                      const struct ieee80211_tx_control *frame_txctl,
+                      struct ieee80211_rts *rts);
+
+/**
+ * ieee80211_rts_duration - Get the duration field for an RTS frame
+ * @hw: pointer obtained from ieee80211_alloc_hw().
+ * @frame_len: the length of the frame that is going to be protected by the RTS.
+ * @frame_txctl: &struct ieee80211_tx_control of the frame.
+ *
+ * If the RTS is generated in firmware, but the host system must provide
+ * the duration field, the low-level driver uses this function to receive
+ * the duration field value in little-endian byteorder.
+ */
+__le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
+                             size_t frame_len,
+                             const struct ieee80211_tx_control *frame_txctl);
+
+/**
+ * ieee80211_ctstoself_get - CTS-to-self frame generation function
+ * @hw: pointer obtained from ieee80211_alloc_hw().
+ * @frame: pointer to the frame that is going to be protected by the CTS-to-self.
+ * @frame_len: the frame length (in octets).
+ * @frame_txctl: &struct ieee80211_tx_control of the frame.
+ * @cts: The buffer where to store the CTS-to-self frame.
+ *
+ * If the CTS-to-self frames are generated by the host system (i.e., not in
+ * hardware/firmware), the low-level driver uses this function to receive
+ * the next CTS-to-self frame from the 802.11 code. The low-level is responsible
+ * for calling this function before and CTS-to-self frame is needed.
+ */
+void ieee80211_ctstoself_get(struct ieee80211_hw *hw,
+                            const void *frame, size_t frame_len,
+                            const struct ieee80211_tx_control *frame_txctl,
+                            struct ieee80211_cts *cts);
+
+/**
+ * ieee80211_ctstoself_duration - Get the duration field for a CTS-to-self frame
+ * @hw: pointer obtained from ieee80211_alloc_hw().
+ * @frame_len: the length of the frame that is going to be protected by the CTS-to-self.
+ * @frame_txctl: &struct ieee80211_tx_control of the frame.
+ *
+ * If the CTS-to-self is generated in firmware, but the host system must provide
+ * the duration field, the low-level driver uses this function to receive
+ * the duration field value in little-endian byteorder.
+ */
+__le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
+                                   size_t frame_len,
+                                   const struct ieee80211_tx_control *frame_txctl);
+
+/**
+ * ieee80211_generic_frame_duration - Calculate the duration field for a frame
+ * @hw: pointer obtained from ieee80211_alloc_hw().
+ * @frame_len: the length of the frame.
+ * @rate: the rate (in 100kbps) at which the frame is going to be transmitted.
+ *
+ * Calculate the duration field of some generic frame, given its
+ * length and transmission rate (in 100kbps).
+ */
+__le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
+                                       size_t frame_len,
+                                       int rate);
+
+/**
+ * ieee80211_get_buffered_bc - accessing buffered broadcast and multicast frames
+ * @hw: pointer as obtained from ieee80211_alloc_hw().
+ * @if_id: interface ID from &struct ieee80211_if_init_conf.
+ * @control: will be filled with information needed to send returned frame.
+ *
+ * Function for accessing buffered broadcast and multicast frames. If
+ * hardware/firmware does not implement buffering of broadcast/multicast
+ * frames when power saving is used, 802.11 code buffers them in the host
+ * memory. The low-level driver uses this function to fetch next buffered
+ * frame. In most cases, this is used when generating beacon frame. This
+ * function returns a pointer to the next buffered skb or NULL if no more
+ * buffered frames are available.
+ *
+ * Note: buffered frames are returned only after DTIM beacon frame was
+ * generated with ieee80211_beacon_get() and the low-level driver must thus
+ * call ieee80211_beacon_get() first. ieee80211_get_buffered_bc() returns
+ * NULL if the previous generated beacon was not DTIM, so the low-level driver
+ * does not need to check for DTIM beacons separately and should be able to
+ * use common code for all beacons.
+ */
+struct sk_buff *
+ieee80211_get_buffered_bc(struct ieee80211_hw *hw, int if_id,
+                         struct ieee80211_tx_control *control);
+
+/* Low level drivers that have their own MLME and MAC indicate
+ * the aid for an associating station with this call */
+int ieee80211_set_aid_for_sta(struct ieee80211_hw *hw,
+                             u8 *peer_address, u16 aid);
+
+
+/* Given an sk_buff with a raw 802.11 header at the data pointer this function
+ * returns the 802.11 header length in bytes (not including encryption
+ * headers). If the data in the sk_buff is too short to contain a valid 802.11
+ * header the function returns 0.
+ */
+int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb);
+
+/* Like ieee80211_get_hdrlen_from_skb() but takes a FC in CPU order. */
+int ieee80211_get_hdrlen(u16 fc);
+
+/**
+ * ieee80211_wake_queue - wake specific queue
+ * @hw: pointer as obtained from ieee80211_alloc_hw().
+ * @queue: queue number (counted from zero).
+ *
+ * Drivers should use this function instead of netif_wake_queue.
+ */
+void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue);
+
+/**
+ * ieee80211_stop_queue - stop specific queue
+ * @hw: pointer as obtained from ieee80211_alloc_hw().
+ * @queue: queue number (counted from zero).
+ *
+ * Drivers should use this function instead of netif_stop_queue.
+ */
+void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue);
+
+/**
+ * ieee80211_start_queues - start all queues
+ * @hw: pointer to as obtained from ieee80211_alloc_hw().
+ *
+ * Drivers should use this function instead of netif_start_queue.
+ */
+void ieee80211_start_queues(struct ieee80211_hw *hw);
+
+/**
+ * ieee80211_stop_queues - stop all queues
+ * @hw: pointer as obtained from ieee80211_alloc_hw().
+ *
+ * Drivers should use this function instead of netif_stop_queue.
+ */
+void ieee80211_stop_queues(struct ieee80211_hw *hw);
+
+/**
+ * ieee80211_wake_queues - wake all queues
+ * @hw: pointer as obtained from ieee80211_alloc_hw().
+ *
+ * Drivers should use this function instead of netif_wake_queue.
+ */
+void ieee80211_wake_queues(struct ieee80211_hw *hw);
+
+/**
+ * ieee80211_get_mc_list_item - iteration over items in multicast list
+ * @hw: pointer as obtained from ieee80211_alloc_hw().
+ * @prev: value returned by previous call to ieee80211_get_mc_list_item() or
+ *     NULL to start a new iteration.
+ * @ptr: pointer to buffer of void * type for internal usage of
+ *     ieee80211_get_mc_list_item().
+ *
+ * Iterates over items in multicast list of given device. To get the first
+ * item, pass NULL in @prev and in *@ptr. In subsequent calls, pass the
+ * value returned by previous call in @prev. Don't alter *@ptr during
+ * iteration. When there are no more items, NULL is returned.
+ */
+struct dev_mc_list *
+ieee80211_get_mc_list_item(struct ieee80211_hw *hw,
+                          struct dev_mc_list *prev,
+                          void **ptr);
+
+/* called by driver to notify scan status completed */
+void ieee80211_scan_completed(struct ieee80211_hw *hw);
+
+/* Function to indicate Radar Detection. The low level driver must call this
+ * function to indicate the presence of radar in the current channel.
+ * Additionally the radar type also could be sent */
+int  ieee80211_radar_status(struct ieee80211_hw *hw, int channel,
+                           int radar, int radar_type);
+
+/* return a pointer to the source address (SA) */
+static inline u8 *ieee80211_get_SA(struct ieee80211_hdr *hdr)
+{
+       u8 *raw = (u8 *) hdr;
+       u8 tofrom = (*(raw+1)) & 3; /* get the TODS and FROMDS bits */
+
+       switch (tofrom) {
+               case 2:
+                       return hdr->addr3;
+               case 3:
+                       return hdr->addr4;
+       }
+       return hdr->addr2;
+}
+
+/* return a pointer to the destination address (DA) */
+static inline u8 *ieee80211_get_DA(struct ieee80211_hdr *hdr)
+{
+       u8 *raw = (u8 *) hdr;
+       u8 to_ds = (*(raw+1)) & 1; /* get the TODS bit */
+
+       if (to_ds)
+               return hdr->addr3;
+       return hdr->addr1;
+}
+
+static inline int ieee80211_get_morefrag(struct ieee80211_hdr *hdr)
+{
+       return (le16_to_cpu(hdr->frame_control) &
+               IEEE80211_FCTL_MOREFRAGS) != 0;
+}
+
+#define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
+#define MAC_ARG(x) ((u8*)(x))[0], ((u8*)(x))[1], ((u8*)(x))[2], \
+                  ((u8*)(x))[3], ((u8*)(x))[4], ((u8*)(x))[5]
+
+#endif /* MAC80211_H */
index 2fc8e77..5b22278 100644 (file)
@@ -220,6 +220,7 @@ config FIB_RULES
 menu "Wireless"
 
 source "net/wireless/Kconfig"
+source "net/mac80211/Kconfig"
 source "net/ieee80211/Kconfig"
 
 endmenu
index 6b74d41..9fdb60c 100644 (file)
@@ -45,6 +45,8 @@ obj-$(CONFIG_ECONET)          += econet/
 obj-$(CONFIG_VLAN_8021Q)       += 8021q/
 obj-$(CONFIG_IP_DCCP)          += dccp/
 obj-$(CONFIG_IP_SCTP)          += sctp/
+obj-y                          += wireless/
+obj-$(CONFIG_MAC80211)         += mac80211/
 obj-$(CONFIG_IEEE80211)                += ieee80211/
 obj-$(CONFIG_TIPC)             += tipc/
 obj-$(CONFIG_NETLABEL)         += netlabel/
@@ -53,5 +55,3 @@ obj-$(CONFIG_IUCV)            += iucv/
 ifeq ($(CONFIG_NET),y)
 obj-$(CONFIG_SYSCTL)           += sysctl_net.o
 endif
-
-obj-y                          += wireless/
diff --git a/net/mac80211/Kconfig b/net/mac80211/Kconfig
new file mode 100644 (file)
index 0000000..d761b53
--- /dev/null
@@ -0,0 +1,69 @@
+config MAC80211
+       tristate "Generic IEEE 802.11 Networking Stack (mac80211)"
+       depends on EXPERIMENTAL
+       select CRYPTO
+       select CRYPTO_ECB
+       select CRYPTO_ARC4
+       select CRYPTO_AES
+       select CRC32
+       select WIRELESS_EXT
+       select CFG80211
+       select NET_SCH_FIFO
+       ---help---
+       This option enables the hardware independent IEEE 802.11
+       networking stack.
+
+config MAC80211_LEDS
+       bool "Enable LED triggers"
+       depends on MAC80211 && LEDS_TRIGGERS
+       ---help---
+       This option enables a few LED triggers for different
+       packet receive/transmit events.
+
+config MAC80211_DEBUG
+       bool "Enable debugging output"
+       depends on MAC80211
+       ---help---
+         This option will enable debug tracing output for the
+         ieee80211 network stack.
+
+         If you are not trying to debug or develop the ieee80211
+         subsystem, you most likely want to say N here.
+
+config MAC80211_VERBOSE_DEBUG
+       bool "Verbose debugging output"
+       depends on MAC80211_DEBUG
+
+config MAC80211_LOWTX_FRAME_DUMP
+       bool "Debug frame dumping"
+       depends on MAC80211_DEBUG
+       ---help---
+         Selecting this option will cause the stack to
+         print a message for each frame that is handed
+         to the lowlevel driver for transmission. This
+         message includes all MAC addresses and the
+         frame control field.
+
+         If unsure, say N and insert the debugging code
+         you require into the driver you are debugging.
+
+config TKIP_DEBUG
+       bool "TKIP debugging"
+       depends on MAC80211_DEBUG
+
+config MAC80211_DEBUG_COUNTERS
+       bool "Extra statistics for TX/RX debugging"
+       depends on MAC80211_DEBUG
+
+config MAC80211_IBSS_DEBUG
+       bool "Support for IBSS testing"
+       depends on MAC80211_DEBUG
+       ---help---
+         Say Y here if you intend to debug the IBSS code.
+
+config MAC80211_VERBOSE_PS_DEBUG
+       bool "Verbose powersave mode debugging"
+       depends on MAC80211_DEBUG
+       ---help---
+         Say Y here to print out verbose powersave
+         mode debug messages.
diff --git a/net/mac80211/Makefile b/net/mac80211/Makefile
new file mode 100644 (file)
index 0000000..79dea99
--- /dev/null
@@ -0,0 +1,19 @@
+obj-$(CONFIG_MAC80211) += mac80211.o rc80211_simple.o
+
+mac80211-objs-$(CONFIG_MAC80211_LEDS) += ieee80211_led.o
+
+mac80211-objs := \
+       ieee80211.o \
+       ieee80211_ioctl.o \
+       sta_info.o \
+       wep.o \
+       wpa.o \
+       ieee80211_sta.o \
+       ieee80211_iface.o \
+       ieee80211_rate.o \
+       michael.o \
+       tkip.o \
+       aes_ccm.o \
+       wme.o \
+       ieee80211_cfg.o \
+       $(mac80211-objs-y)
diff --git a/net/mac80211/aes_ccm.c b/net/mac80211/aes_ccm.c
new file mode 100644 (file)
index 0000000..e55569b
--- /dev/null
@@ -0,0 +1,155 @@
+/*
+ * Copyright 2003-2004, Instant802 Networks, Inc.
+ * Copyright 2005-2006, Devicescape Software, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/types.h>
+#include <linux/crypto.h>
+#include <linux/err.h>
+#include <asm/scatterlist.h>
+
+#include <net/mac80211.h>
+#include "ieee80211_key.h"
+#include "aes_ccm.h"
+
+
+static void ieee80211_aes_encrypt(struct crypto_cipher *tfm,
+                                 const u8 pt[16], u8 ct[16])
+{
+       crypto_cipher_encrypt_one(tfm, ct, pt);
+}
+
+
+static inline void aes_ccm_prepare(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
+                                  u8 *b, u8 *s_0, u8 *a)
+{
+       int i;
+
+       ieee80211_aes_encrypt(tfm, b_0, b);
+
+       /* Extra Authenticate-only data (always two AES blocks) */
+       for (i = 0; i < AES_BLOCK_LEN; i++)
+               aad[i] ^= b[i];
+       ieee80211_aes_encrypt(tfm, aad, b);
+
+       aad += AES_BLOCK_LEN;
+
+       for (i = 0; i < AES_BLOCK_LEN; i++)
+               aad[i] ^= b[i];
+       ieee80211_aes_encrypt(tfm, aad, a);
+
+       /* Mask out bits from auth-only-b_0 */
+       b_0[0] &= 0x07;
+
+       /* S_0 is used to encrypt T (= MIC) */
+       b_0[14] = 0;
+       b_0[15] = 0;
+       ieee80211_aes_encrypt(tfm, b_0, s_0);
+}
+
+
+void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *scratch,
+                              u8 *b_0, u8 *aad, u8 *data, size_t data_len,
+                              u8 *cdata, u8 *mic)
+{
+       int i, j, last_len, num_blocks;
+       u8 *pos, *cpos, *b, *s_0, *e;
+
+       b = scratch;
+       s_0 = scratch + AES_BLOCK_LEN;
+       e = scratch + 2 * AES_BLOCK_LEN;
+
+       num_blocks = (data_len + AES_BLOCK_LEN - 1) / AES_BLOCK_LEN;
+       last_len = data_len % AES_BLOCK_LEN;
+       aes_ccm_prepare(tfm, b_0, aad, b, s_0, b);
+
+       /* Process payload blocks */
+       pos = data;
+       cpos = cdata;
+       for (j = 1; j <= num_blocks; j++) {
+               int blen = (j == num_blocks && last_len) ?
+                       last_len : AES_BLOCK_LEN;
+
+               /* Authentication followed by encryption */
+               for (i = 0; i < blen; i++)
+                       b[i] ^= pos[i];
+               ieee80211_aes_encrypt(tfm, b, b);
+
+               b_0[14] = (j >> 8) & 0xff;
+               b_0[15] = j & 0xff;
+               ieee80211_aes_encrypt(tfm, b_0, e);
+               for (i = 0; i < blen; i++)
+                       *cpos++ = *pos++ ^ e[i];
+       }
+
+       for (i = 0; i < CCMP_MIC_LEN; i++)
+               mic[i] = b[i] ^ s_0[i];
+}
+
+
+int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *scratch,
+                             u8 *b_0, u8 *aad, u8 *cdata, size_t data_len,
+                             u8 *mic, u8 *data)
+{
+       int i, j, last_len, num_blocks;
+       u8 *pos, *cpos, *b, *s_0, *a;
+
+       b = scratch;
+       s_0 = scratch + AES_BLOCK_LEN;
+       a = scratch + 2 * AES_BLOCK_LEN;
+
+       num_blocks = (data_len + AES_BLOCK_LEN - 1) / AES_BLOCK_LEN;
+       last_len = data_len % AES_BLOCK_LEN;
+       aes_ccm_prepare(tfm, b_0, aad, b, s_0, a);
+
+       /* Process payload blocks */
+       cpos = cdata;
+       pos = data;
+       for (j = 1; j <= num_blocks; j++) {
+               int blen = (j == num_blocks && last_len) ?
+                       last_len : AES_BLOCK_LEN;
+
+               /* Decryption followed by authentication */
+               b_0[14] = (j >> 8) & 0xff;
+               b_0[15] = j & 0xff;
+               ieee80211_aes_encrypt(tfm, b_0, b);
+               for (i = 0; i < blen; i++) {
+                       *pos = *cpos++ ^ b[i];
+                       a[i] ^= *pos++;
+               }
+
+               ieee80211_aes_encrypt(tfm, a, a);
+       }
+
+       for (i = 0; i < CCMP_MIC_LEN; i++) {
+               if ((mic[i] ^ s_0[i]) != a[i])
+                       return -1;
+       }
+
+       return 0;
+}
+
+
+struct crypto_cipher * ieee80211_aes_key_setup_encrypt(const u8 key[])
+{
+       struct crypto_cipher *tfm;
+
+       tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
+       if (IS_ERR(tfm))
+               return NULL;
+
+       crypto_cipher_setkey(tfm, key, ALG_CCMP_KEY_LEN);
+
+       return tfm;
+}
+
+
+void ieee80211_aes_key_free(struct crypto_cipher *tfm)
+{
+       if (tfm)
+               crypto_free_cipher(tfm);
+}
diff --git a/net/mac80211/aes_ccm.h b/net/mac80211/aes_ccm.h
new file mode 100644 (file)
index 0000000..885f190
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2003-2004, Instant802 Networks, Inc.
+ * Copyright 2006, Devicescape Software, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef AES_CCM_H
+#define AES_CCM_H
+
+#include <linux/crypto.h>
+
+#define AES_BLOCK_LEN 16
+
+struct crypto_cipher * ieee80211_aes_key_setup_encrypt(const u8 key[]);
+void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *scratch,
+                              u8 *b_0, u8 *aad, u8 *data, size_t data_len,
+                              u8 *cdata, u8 *mic);
+int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *scratch,
+                             u8 *b_0, u8 *aad, u8 *cdata, size_t data_len,
+                             u8 *mic, u8 *data);
+void ieee80211_aes_key_free(struct crypto_cipher *tfm);
+
+#endif /* AES_CCM_H */
diff --git a/net/mac80211/hostapd_ioctl.h b/net/mac80211/hostapd_ioctl.h
new file mode 100644 (file)
index 0000000..34fa128
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * Host AP (software wireless LAN access point) user space daemon for
+ * Host AP kernel driver
+ * Copyright 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
+ * Copyright 2002-2004, Instant802 Networks, Inc.
+ * Copyright 2005, Devicescape Software, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef HOSTAPD_IOCTL_H
+#define HOSTAPD_IOCTL_H
+
+#ifdef __KERNEL__
+#include <linux/types.h>
+#endif /* __KERNEL__ */
+
+#define PRISM2_IOCTL_PRISM2_PARAM (SIOCIWFIRSTPRIV + 0)
+#define PRISM2_IOCTL_GET_PRISM2_PARAM (SIOCIWFIRSTPRIV + 1)
+#define PRISM2_IOCTL_HOSTAPD (SIOCIWFIRSTPRIV + 3)
+
+/* PRISM2_IOCTL_PRISM2_PARAM ioctl() subtypes:
+ * This table is no longer added to, the whole sub-ioctl
+ * mess shall be deleted completely. */
+enum {
+       PRISM2_PARAM_IEEE_802_1X = 23,
+       PRISM2_PARAM_ANTSEL_TX = 24,
+       PRISM2_PARAM_ANTSEL_RX = 25,
+
+       /* Instant802 additions */
+       PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES = 1001,
+       PRISM2_PARAM_DROP_UNENCRYPTED = 1002,
+       PRISM2_PARAM_PREAMBLE = 1003,
+       PRISM2_PARAM_SHORT_SLOT_TIME = 1006,
+       PRISM2_PARAM_NEXT_MODE = 1008,
+       PRISM2_PARAM_CLEAR_KEYS = 1009,
+       PRISM2_PARAM_RADIO_ENABLED = 1010,
+       PRISM2_PARAM_ANTENNA_MODE = 1013,
+       PRISM2_PARAM_STAT_TIME = 1016,
+       PRISM2_PARAM_STA_ANTENNA_SEL = 1017,
+       PRISM2_PARAM_FORCE_UNICAST_RATE = 1018,
+       PRISM2_PARAM_RATE_CTRL_NUM_UP = 1019,
+       PRISM2_PARAM_RATE_CTRL_NUM_DOWN = 1020,
+       PRISM2_PARAM_MAX_RATECTRL_RATE = 1021,
+       PRISM2_PARAM_TX_POWER_REDUCTION = 1022,
+       PRISM2_PARAM_KEY_TX_RX_THRESHOLD = 1024,
+       PRISM2_PARAM_DEFAULT_WEP_ONLY = 1026,
+       PRISM2_PARAM_WIFI_WME_NOACK_TEST = 1033,
+       PRISM2_PARAM_SCAN_FLAGS = 1035,
+       PRISM2_PARAM_HW_MODES = 1036,
+       PRISM2_PARAM_CREATE_IBSS = 1037,
+       PRISM2_PARAM_WMM_ENABLED = 1038,
+       PRISM2_PARAM_MIXED_CELL = 1039,
+       PRISM2_PARAM_RADAR_DETECT = 1043,
+       PRISM2_PARAM_SPECTRUM_MGMT = 1044,
+};
+
+enum {
+       IEEE80211_KEY_MGMT_NONE = 0,
+       IEEE80211_KEY_MGMT_IEEE8021X = 1,
+       IEEE80211_KEY_MGMT_WPA_PSK = 2,
+       IEEE80211_KEY_MGMT_WPA_EAP = 3,
+};
+
+
+/* Data structures used for get_hw_features ioctl */
+struct hostapd_ioctl_hw_modes_hdr {
+       int mode;
+       int num_channels;
+       int num_rates;
+};
+
+struct ieee80211_channel_data {
+       short chan; /* channel number (IEEE 802.11) */
+       short freq; /* frequency in MHz */
+       int flag; /* flag for hostapd use (IEEE80211_CHAN_*) */
+};
+
+struct ieee80211_rate_data {
+       int rate; /* rate in 100 kbps */
+       int flags; /* IEEE80211_RATE_ flags */
+};
+
+
+/* ADD_IF, REMOVE_IF, and UPDATE_IF 'type' argument */
+enum {
+       HOSTAP_IF_WDS = 1, HOSTAP_IF_VLAN = 2, HOSTAP_IF_BSS = 3,
+       HOSTAP_IF_STA = 4
+};
+
+struct hostapd_if_wds {
+       u8 remote_addr[ETH_ALEN];
+};
+
+struct hostapd_if_vlan {
+       u8 id;
+};
+
+struct hostapd_if_bss {
+       u8 bssid[ETH_ALEN];
+};
+
+struct hostapd_if_sta {
+};
+
+#endif /* HOSTAPD_IOCTL_H */
diff --git a/net/mac80211/ieee80211.c b/net/mac80211/ieee80211.c
new file mode 100644 (file)
index 0000000..48a832d
--- /dev/null
@@ -0,0 +1,4970 @@
+/*
+ * Copyright 2002-2005, Instant802 Networks, Inc.
+ * Copyright 2005-2006, Devicescape Software, Inc.
+ * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <net/mac80211.h>
+#include <net/ieee80211_radiotap.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/netdevice.h>
+#include <linux/types.h>
+#include <linux/slab.h>
+#include <linux/skbuff.h>
+#include <linux/etherdevice.h>
+#include <linux/if_arp.h>
+#include <linux/wireless.h>
+#include <linux/rtnetlink.h>
+#include <net/iw_handler.h>
+#include <linux/compiler.h>
+#include <linux/bitmap.h>
+#include <net/cfg80211.h>
+
+#include "ieee80211_common.h"
+#include "ieee80211_i.h"
+#include "ieee80211_rate.h"
+#include "wep.h"
+#include "wpa.h"
+#include "tkip.h"
+#include "wme.h"
+#include "aes_ccm.h"
+#include "ieee80211_led.h"
+#include "ieee80211_cfg.h"
+
+/* privid for wiphys to determine whether they belong to us or not */
+void *mac80211_wiphy_privid = &mac80211_wiphy_privid;
+
+/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
+/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
+static const unsigned char rfc1042_header[] =
+       { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
+
+/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
+static const unsigned char bridge_tunnel_header[] =
+       { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
+
+/* No encapsulation header if EtherType < 0x600 (=length) */
+static const unsigned char eapol_header[] =
+       { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x88, 0x8e };
+
+
+static inline void ieee80211_include_sequence(struct ieee80211_sub_if_data *sdata,
+                                             struct ieee80211_hdr *hdr)
+{
+       /* Set the sequence number for this frame. */
+       hdr->seq_ctrl = cpu_to_le16(sdata->sequence);
+
+       /* Increase the sequence number. */
+       sdata->sequence = (sdata->sequence + 0x10) & IEEE80211_SCTL_SEQ;
+}
+
+struct ieee80211_key_conf *
+ieee80211_key_data2conf(struct ieee80211_local *local,
+                       const struct ieee80211_key *data)
+{
+       struct ieee80211_key_conf *conf;
+
+       conf = kmalloc(sizeof(*conf) + data->keylen, GFP_ATOMIC);
+       if (!conf)
+               return NULL;
+
+       conf->hw_key_idx = data->hw_key_idx;
+       conf->alg = data->alg;
+       conf->keylen = data->keylen;
+       conf->flags = 0;
+       if (data->force_sw_encrypt)
+               conf->flags |= IEEE80211_KEY_FORCE_SW_ENCRYPT;
+       conf->keyidx = data->keyidx;
+       if (data->default_tx_key)
+               conf->flags |= IEEE80211_KEY_DEFAULT_TX_KEY;
+       if (local->default_wep_only)
+               conf->flags |= IEEE80211_KEY_DEFAULT_WEP_ONLY;
+       memcpy(conf->key, data->key, data->keylen);
+
+       return conf;
+}
+
+struct ieee80211_key *ieee80211_key_alloc(struct ieee80211_sub_if_data *sdata,
+                                         int idx, size_t key_len, gfp_t flags)
+{
+       struct ieee80211_key *key;
+
+       key = kzalloc(sizeof(struct ieee80211_key) + key_len, flags);
+       if (!key)
+               return NULL;
+       kref_init(&key->kref);
+       return key;
+}
+
+static void ieee80211_key_release(struct kref *kref)
+{
+       struct ieee80211_key *key;
+
+       key = container_of(kref, struct ieee80211_key, kref);
+       if (key->alg == ALG_CCMP)
+               ieee80211_aes_key_free(key->u.ccmp.tfm);
+       kfree(key);
+}
+
+void ieee80211_key_free(struct ieee80211_key *key)
+{
+       if (key)
+               kref_put(&key->kref, ieee80211_key_release);
+}
+
+static int rate_list_match(const int *rate_list, int rate)
+{
+       int i;
+
+       if (!rate_list)
+               return 0;
+
+       for (i = 0; rate_list[i] >= 0; i++)
+               if (rate_list[i] == rate)
+                       return 1;
+
+       return 0;
+}
+
+
+void ieee80211_prepare_rates(struct ieee80211_local *local,
+                            struct ieee80211_hw_mode *mode)
+{
+       int i;
+
+       for (i = 0; i < mode->num_rates; i++) {
+               struct ieee80211_rate *rate = &mode->rates[i];
+
+               rate->flags &= ~(IEEE80211_RATE_SUPPORTED |
+                                IEEE80211_RATE_BASIC);
+
+               if (local->supp_rates[mode->mode]) {
+                       if (!rate_list_match(local->supp_rates[mode->mode],
+                                            rate->rate))
+                               continue;
+               }
+
+               rate->flags |= IEEE80211_RATE_SUPPORTED;
+
+               /* Use configured basic rate set if it is available. If not,
+                * use defaults that are sane for most cases. */
+               if (local->basic_rates[mode->mode]) {
+                       if (rate_list_match(local->basic_rates[mode->mode],
+                                           rate->rate))
+                               rate->flags |= IEEE80211_RATE_BASIC;
+               } else switch (mode->mode) {
+               case MODE_IEEE80211A:
+                       if (rate->rate == 60 || rate->rate == 120 ||
+                           rate->rate == 240)
+                               rate->flags |= IEEE80211_RATE_BASIC;
+                       break;
+               case MODE_IEEE80211B:
+                       if (rate->rate == 10 || rate->rate == 20)
+                               rate->flags |= IEEE80211_RATE_BASIC;
+                       break;
+               case MODE_ATHEROS_TURBO:
+                       if (rate->rate == 120 || rate->rate == 240 ||
+                           rate->rate == 480)
+                               rate->flags |= IEEE80211_RATE_BASIC;
+                       break;
+               case MODE_IEEE80211G:
+                       if (rate->rate == 10 || rate->rate == 20 ||
+                           rate->rate == 55 || rate->rate == 110)
+                               rate->flags |= IEEE80211_RATE_BASIC;
+                       break;
+               }
+
+               /* Set ERP and MANDATORY flags based on phymode */
+               switch (mode->mode) {
+               case MODE_IEEE80211A:
+                       if (rate->rate == 60 || rate->rate == 120 ||
+                           rate->rate == 240)
+                               rate->flags |= IEEE80211_RATE_MANDATORY;
+                       break;
+               case MODE_IEEE80211B:
+                       if (rate->rate == 10)
+                               rate->flags |= IEEE80211_RATE_MANDATORY;
+                       break;
+               case MODE_ATHEROS_TURBO:
+                       break;
+               case MODE_IEEE80211G:
+                       if (rate->rate == 10 || rate->rate == 20 ||
+                           rate->rate == 55 || rate->rate == 110 ||
+                           rate->rate == 60 || rate->rate == 120 ||
+                           rate->rate == 240)
+                               rate->flags |= IEEE80211_RATE_MANDATORY;
+                       break;
+               }
+               if (ieee80211_is_erp_rate(mode->mode, rate->rate))
+                       rate->flags |= IEEE80211_RATE_ERP;
+       }
+}
+
+
+static void ieee80211_key_threshold_notify(struct net_device *dev,
+                                          struct ieee80211_key *key,
+                                          struct sta_info *sta)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct sk_buff *skb;
+       struct ieee80211_msg_key_notification *msg;
+
+       /* if no one will get it anyway, don't even allocate it.
+        * unlikely because this is only relevant for APs
+        * where the device must be open... */
+       if (unlikely(!local->apdev))
+               return;
+
+       skb = dev_alloc_skb(sizeof(struct ieee80211_frame_info) +
+                           sizeof(struct ieee80211_msg_key_notification));
+       if (!skb)
+               return;
+
+       skb_reserve(skb, sizeof(struct ieee80211_frame_info));
+       msg = (struct ieee80211_msg_key_notification *)
+               skb_put(skb, sizeof(struct ieee80211_msg_key_notification));
+       msg->tx_rx_count = key->tx_rx_count;
+       memcpy(msg->ifname, dev->name, IFNAMSIZ);
+       if (sta)
+               memcpy(msg->addr, sta->addr, ETH_ALEN);
+       else
+               memset(msg->addr, 0xff, ETH_ALEN);
+
+       key->tx_rx_count = 0;
+
+       ieee80211_rx_mgmt(local, skb, NULL,
+                         ieee80211_msg_key_threshold_notification);
+}
+
+
+static u8 * ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len)
+{
+       u16 fc;
+
+       if (len < 24)
+               return NULL;
+
+       fc = le16_to_cpu(hdr->frame_control);
+
+       switch (fc & IEEE80211_FCTL_FTYPE) {
+       case IEEE80211_FTYPE_DATA:
+               switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
+               case IEEE80211_FCTL_TODS:
+                       return hdr->addr1;
+               case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
+                       return NULL;
+               case IEEE80211_FCTL_FROMDS:
+                       return hdr->addr2;
+               case 0:
+                       return hdr->addr3;
+               }
+               break;
+       case IEEE80211_FTYPE_MGMT:
+               return hdr->addr3;
+       case IEEE80211_FTYPE_CTL:
+               if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)
+                       return hdr->addr1;
+               else
+                       return NULL;
+       }
+
+       return NULL;
+}
+
+int ieee80211_get_hdrlen(u16 fc)
+{
+       int hdrlen = 24;
+
+       switch (fc & IEEE80211_FCTL_FTYPE) {
+       case IEEE80211_FTYPE_DATA:
+               if ((fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))
+                       hdrlen = 30; /* Addr4 */
+               /*
+                * The QoS Control field is two bytes and its presence is
+                * indicated by the IEEE80211_STYPE_QOS_DATA bit. Add 2 to
+                * hdrlen if that bit is set.
+                * This works by masking out the bit and shifting it to
+                * bit position 1 so the result has the value 0 or 2.
+                */
+               hdrlen += (fc & IEEE80211_STYPE_QOS_DATA)
+                               >> (ilog2(IEEE80211_STYPE_QOS_DATA)-1);
+               break;
+       case IEEE80211_FTYPE_CTL:
+               /*
+                * ACK and CTS are 10 bytes, all others 16. To see how
+                * to get this condition consider
+                *   subtype mask:   0b0000000011110000 (0x00F0)
+                *   ACK subtype:    0b0000000011010000 (0x00D0)
+                *   CTS subtype:    0b0000000011000000 (0x00C0)
+                *   bits that matter:         ^^^      (0x00E0)
+                *   value of those: 0b0000000011000000 (0x00C0)
+                */
+               if ((fc & 0xE0) == 0xC0)
+                       hdrlen = 10;
+               else
+                       hdrlen = 16;
+               break;
+       }
+
+       return hdrlen;
+}
+EXPORT_SYMBOL(ieee80211_get_hdrlen);
+
+int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
+{
+       const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *) skb->data;
+       int hdrlen;
+
+       if (unlikely(skb->len < 10))
+               return 0;
+       hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control));
+       if (unlikely(hdrlen > skb->len))
+               return 0;
+       return hdrlen;
+}
+EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
+
+static int ieee80211_get_radiotap_len(struct sk_buff *skb)
+{
+       struct ieee80211_radiotap_header *hdr =
+               (struct ieee80211_radiotap_header *) skb->data;
+
+       return le16_to_cpu(hdr->it_len);
+}
+
+#ifdef CONFIG_MAC80211_LOWTX_FRAME_DUMP
+static void ieee80211_dump_frame(const char *ifname, const char *title,
+                                const struct sk_buff *skb)
+{
+       const struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
+       u16 fc;
+       int hdrlen;
+
+       printk(KERN_DEBUG "%s: %s (len=%d)", ifname, title, skb->len);
+       if (skb->len < 4) {
+               printk("\n");
+               return;
+       }
+
+       fc = le16_to_cpu(hdr->frame_control);
+       hdrlen = ieee80211_get_hdrlen(fc);
+       if (hdrlen > skb->len)
+               hdrlen = skb->len;
+       if (hdrlen >= 4)
+               printk(" FC=0x%04x DUR=0x%04x",
+                      fc, le16_to_cpu(hdr->duration_id));
+       if (hdrlen >= 10)
+               printk(" A1=" MAC_FMT, MAC_ARG(hdr->addr1));
+       if (hdrlen >= 16)
+               printk(" A2=" MAC_FMT, MAC_ARG(hdr->addr2));
+       if (hdrlen >= 24)
+               printk(" A3=" MAC_FMT, MAC_ARG(hdr->addr3));
+       if (hdrlen >= 30)
+               printk(" A4=" MAC_FMT, MAC_ARG(hdr->addr4));
+       printk("\n");
+}
+#else /* CONFIG_MAC80211_LOWTX_FRAME_DUMP */
+static inline void ieee80211_dump_frame(const char *ifname, const char *title,
+                                       struct sk_buff *skb)
+{
+}
+#endif /* CONFIG_MAC80211_LOWTX_FRAME_DUMP */
+
+
+static int ieee80211_is_eapol(const struct sk_buff *skb)
+{
+       const struct ieee80211_hdr *hdr;
+       u16 fc;
+       int hdrlen;
+
+       if (unlikely(skb->len < 10))
+               return 0;
+
+       hdr = (const struct ieee80211_hdr *) skb->data;
+       fc = le16_to_cpu(hdr->frame_control);
+
+       if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
+               return 0;
+
+       hdrlen = ieee80211_get_hdrlen(fc);
+
+       if (unlikely(skb->len >= hdrlen + sizeof(eapol_header) &&
+                    memcmp(skb->data + hdrlen, eapol_header,
+                           sizeof(eapol_header)) == 0))
+               return 1;
+
+       return 0;
+}
+
+
+static ieee80211_txrx_result
+ieee80211_tx_h_rate_ctrl(struct ieee80211_txrx_data *tx)
+{
+       struct rate_control_extra extra;
+
+       memset(&extra, 0, sizeof(extra));
+       extra.mode = tx->u.tx.mode;
+       extra.mgmt_data = tx->sdata &&
+               tx->sdata->type == IEEE80211_IF_TYPE_MGMT;
+       extra.ethertype = tx->ethertype;
+
+       tx->u.tx.rate = rate_control_get_rate(tx->local, tx->dev, tx->skb,
+                                             &extra);
+       if (unlikely(extra.probe != NULL)) {
+               tx->u.tx.control->flags |= IEEE80211_TXCTL_RATE_CTRL_PROBE;
+               tx->u.tx.probe_last_frag = 1;
+               tx->u.tx.control->alt_retry_rate = tx->u.tx.rate->val;
+               tx->u.tx.rate = extra.probe;
+       } else {
+               tx->u.tx.control->alt_retry_rate = -1;
+       }
+       if (!tx->u.tx.rate)
+               return TXRX_DROP;
+       if (tx->u.tx.mode->mode == MODE_IEEE80211G &&
+           tx->local->cts_protect_erp_frames && tx->fragmented &&
+           extra.nonerp) {
+               tx->u.tx.last_frag_rate = tx->u.tx.rate;
+               tx->u.tx.probe_last_frag = extra.probe ? 1 : 0;
+
+               tx->u.tx.rate = extra.nonerp;
+               tx->u.tx.control->rate = extra.nonerp;
+               tx->u.tx.control->flags &= ~IEEE80211_TXCTL_RATE_CTRL_PROBE;
+       } else {
+               tx->u.tx.last_frag_rate = tx->u.tx.rate;
+               tx->u.tx.control->rate = tx->u.tx.rate;
+       }
+       tx->u.tx.control->tx_rate = tx->u.tx.rate->val;
+       if ((tx->u.tx.rate->flags & IEEE80211_RATE_PREAMBLE2) &&
+           tx->local->short_preamble &&
+           (!tx->sta || (tx->sta->flags & WLAN_STA_SHORT_PREAMBLE))) {
+               tx->u.tx.short_preamble = 1;
+               tx->u.tx.control->tx_rate = tx->u.tx.rate->val2;
+       }
+
+       return TXRX_CONTINUE;
+}
+
+
+static ieee80211_txrx_result
+ieee80211_tx_h_select_key(struct ieee80211_txrx_data *tx)
+{
+       if (tx->sta)
+               tx->u.tx.control->key_idx = tx->sta->key_idx_compression;
+       else
+               tx->u.tx.control->key_idx = HW_KEY_IDX_INVALID;
+
+       if (unlikely(tx->u.tx.control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT))
+               tx->key = NULL;
+       else if (tx->sta && tx->sta->key)
+               tx->key = tx->sta->key;
+       else if (tx->sdata->default_key)
+               tx->key = tx->sdata->default_key;
+       else if (tx->sdata->drop_unencrypted &&
+                !(tx->sdata->eapol && ieee80211_is_eapol(tx->skb))) {
+               I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted);
+               return TXRX_DROP;
+       } else
+               tx->key = NULL;
+
+       if (tx->key) {
+               tx->key->tx_rx_count++;
+               if (unlikely(tx->local->key_tx_rx_threshold &&
+                            tx->key->tx_rx_count >
+                            tx->local->key_tx_rx_threshold)) {
+                       ieee80211_key_threshold_notify(tx->dev, tx->key,
+                                                      tx->sta);
+               }
+       }
+
+       return TXRX_CONTINUE;
+}
+
+
+static ieee80211_txrx_result
+ieee80211_tx_h_fragment(struct ieee80211_txrx_data *tx)
+{
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
+       size_t hdrlen, per_fragm, num_fragm, payload_len, left;
+       struct sk_buff **frags, *first, *frag;
+       int i;
+       u16 seq;
+       u8 *pos;
+       int frag_threshold = tx->local->fragmentation_threshold;
+
+       if (!tx->fragmented)
+               return TXRX_CONTINUE;
+
+       first = tx->skb;
+
+       hdrlen = ieee80211_get_hdrlen(tx->fc);
+       payload_len = first->len - hdrlen;
+       per_fragm = frag_threshold - hdrlen - FCS_LEN;
+       num_fragm = (payload_len + per_fragm - 1) / per_fragm;
+
+       frags = kzalloc(num_fragm * sizeof(struct sk_buff *), GFP_ATOMIC);
+       if (!frags)
+               goto fail;
+
+       hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
+       seq = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ;
+       pos = first->data + hdrlen + per_fragm;
+       left = payload_len - per_fragm;
+       for (i = 0; i < num_fragm - 1; i++) {
+               struct ieee80211_hdr *fhdr;
+               size_t copylen;
+
+               if (left <= 0)
+                       goto fail;
+
+               /* reserve enough extra head and tail room for possible
+                * encryption */
+               frag = frags[i] =
+                       dev_alloc_skb(tx->local->hw.extra_tx_headroom +
+                                     frag_threshold +
+                                     IEEE80211_ENCRYPT_HEADROOM +
+                                     IEEE80211_ENCRYPT_TAILROOM);
+               if (!frag)
+                       goto fail;
+               /* Make sure that all fragments use the same priority so
+                * that they end up using the same TX queue */
+               frag->priority = first->priority;
+               skb_reserve(frag, tx->local->hw.extra_tx_headroom +
+                       IEEE80211_ENCRYPT_HEADROOM);
+               fhdr = (struct ieee80211_hdr *) skb_put(frag, hdrlen);
+               memcpy(fhdr, first->data, hdrlen);
+               if (i == num_fragm - 2)
+                       fhdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREFRAGS);
+               fhdr->seq_ctrl = cpu_to_le16(seq | ((i + 1) & IEEE80211_SCTL_FRAG));
+               copylen = left > per_fragm ? per_fragm : left;
+               memcpy(skb_put(frag, copylen), pos, copylen);
+
+               pos += copylen;
+               left -= copylen;
+       }
+       skb_trim(first, hdrlen + per_fragm);
+
+       tx->u.tx.num_extra_frag = num_fragm - 1;
+       tx->u.tx.extra_frag = frags;
+
+       return TXRX_CONTINUE;
+
+ fail:
+       printk(KERN_DEBUG "%s: failed to fragment frame\n", tx->dev->name);
+       if (frags) {
+               for (i = 0; i < num_fragm - 1; i++)
+                       if (frags[i])
+                               dev_kfree_skb(frags[i]);
+               kfree(frags);
+       }
+       I802_DEBUG_INC(tx->local->tx_handlers_drop_fragment);
+       return TXRX_DROP;
+}
+
+
+static int wep_encrypt_skb(struct ieee80211_txrx_data *tx, struct sk_buff *skb)
+{
+       if (tx->key->force_sw_encrypt) {
+               if (ieee80211_wep_encrypt(tx->local, skb, tx->key))
+                       return -1;
+       } else {
+               tx->u.tx.control->key_idx = tx->key->hw_key_idx;
+               if (tx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) {
+                       if (ieee80211_wep_add_iv(tx->local, skb, tx->key) ==
+                           NULL)
+                               return -1;
+               }
+       }
+       return 0;
+}
+
+
+void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx)
+{
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
+
+       hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
+       if (tx->u.tx.extra_frag) {
+               struct ieee80211_hdr *fhdr;
+               int i;
+               for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
+                       fhdr = (struct ieee80211_hdr *)
+                               tx->u.tx.extra_frag[i]->data;
+                       fhdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
+               }
+       }
+}
+
+
+static ieee80211_txrx_result
+ieee80211_tx_h_wep_encrypt(struct ieee80211_txrx_data *tx)
+{
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
+       u16 fc;
+
+       fc = le16_to_cpu(hdr->frame_control);
+
+       if (!tx->key || tx->key->alg != ALG_WEP ||
+           ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
+            ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
+             (fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)))
+               return TXRX_CONTINUE;
+
+       tx->u.tx.control->iv_len = WEP_IV_LEN;
+       tx->u.tx.control->icv_len = WEP_ICV_LEN;
+       ieee80211_tx_set_iswep(tx);
+
+       if (wep_encrypt_skb(tx, tx->skb) < 0) {
+               I802_DEBUG_INC(tx->local->tx_handlers_drop_wep);
+               return TXRX_DROP;
+       }
+
+       if (tx->u.tx.extra_frag) {
+               int i;
+               for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
+                       if (wep_encrypt_skb(tx, tx->u.tx.extra_frag[i]) < 0) {
+                               I802_DEBUG_INC(tx->local->
+                                              tx_handlers_drop_wep);
+                               return TXRX_DROP;
+                       }
+               }
+       }
+
+       return TXRX_CONTINUE;
+}
+
+
+static int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
+                                   int rate, int erp, int short_preamble)
+{
+       int dur;
+
+       /* calculate duration (in microseconds, rounded up to next higher
+        * integer if it includes a fractional microsecond) to send frame of
+        * len bytes (does not include FCS) at the given rate. Duration will
+        * also include SIFS.
+        *
+        * rate is in 100 kbps, so divident is multiplied by 10 in the
+        * DIV_ROUND_UP() operations.
+        */
+
+       if (local->hw.conf.phymode == MODE_IEEE80211A || erp ||
+           local->hw.conf.phymode == MODE_ATHEROS_TURBO) {
+               /*
+                * OFDM:
+                *
+                * N_DBPS = DATARATE x 4
+                * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
+                *      (16 = SIGNAL time, 6 = tail bits)
+                * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
+                *
+                * T_SYM = 4 usec
+                * 802.11a - 17.5.2: aSIFSTime = 16 usec
+                * 802.11g - 19.8.4: aSIFSTime = 10 usec +
+                *      signal ext = 6 usec
+                */
+               /* FIX: Atheros Turbo may have different (shorter) duration? */
+               dur = 16; /* SIFS + signal ext */
+               dur += 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */
+               dur += 4; /* 17.3.2.3: T_SIGNAL = 4 usec */
+               dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10,
+                                       4 * rate); /* T_SYM x N_SYM */
+       } else {
+               /*
+                * 802.11b or 802.11g with 802.11b compatibility:
+                * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
+                * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
+                *
+                * 802.11 (DS): 15.3.3, 802.11b: 18.3.4
+                * aSIFSTime = 10 usec
+                * aPreambleLength = 144 usec or 72 usec with short preamble
+                * aPLCPHeaderLength = 48 usec or 24 usec with short preamble
+                */
+               dur = 10; /* aSIFSTime = 10 usec */
+               dur += short_preamble ? (72 + 24) : (144 + 48);
+
+               dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate);
+       }
+
+       return dur;
+}
+
+
+/* Exported duration function for driver use */
+__le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
+                                       size_t frame_len, int rate)
+{
+       struct ieee80211_local *local = hw_to_local(hw);
+       u16 dur;
+       int erp;
+
+       erp = ieee80211_is_erp_rate(hw->conf.phymode, rate);
+       dur = ieee80211_frame_duration(local, frame_len, rate,
+                                      erp, local->short_preamble);
+
+       return cpu_to_le16(dur);
+}
+EXPORT_SYMBOL(ieee80211_generic_frame_duration);
+
+
+static u16 ieee80211_duration(struct ieee80211_txrx_data *tx, int group_addr,
+                             int next_frag_len)
+{
+       int rate, mrate, erp, dur, i;
+       struct ieee80211_rate *txrate = tx->u.tx.rate;
+       struct ieee80211_local *local = tx->local;
+       struct ieee80211_hw_mode *mode = tx->u.tx.mode;
+
+       erp = txrate->flags & IEEE80211_RATE_ERP;
+
+       /*
+        * data and mgmt (except PS Poll):
+        * - during CFP: 32768
+        * - during contention period:
+        *   if addr1 is group address: 0
+        *   if more fragments = 0 and addr1 is individual address: time to
+        *      transmit one ACK plus SIFS
+        *   if more fragments = 1 and addr1 is individual address: time to
+        *      transmit next fragment plus 2 x ACK plus 3 x SIFS
+        *
+        * IEEE 802.11, 9.6:
+        * - control response frame (CTS or ACK) shall be transmitted using the
+        *   same rate as the immediately previous frame in the frame exchange
+        *   sequence, if this rate belongs to the PHY mandatory rates, or else
+        *   at the highest possible rate belonging to the PHY rates in the
+        *   BSSBasicRateSet
+        */
+
+       if ((tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) {
+               /* TODO: These control frames are not currently sent by
+                * 80211.o, but should they be implemented, this function
+                * needs to be updated to support duration field calculation.
+                *
+                * RTS: time needed to transmit pending data/mgmt frame plus
+                *    one CTS frame plus one ACK frame plus 3 x SIFS
+                * CTS: duration of immediately previous RTS minus time
+                *    required to transmit CTS and its SIFS
+                * ACK: 0 if immediately previous directed data/mgmt had
+                *    more=0, with more=1 duration in ACK frame is duration
+                *    from previous frame minus time needed to transmit ACK
+                *    and its SIFS
+                * PS Poll: BIT(15) | BIT(14) | aid
+                */
+               return 0;
+       }
+
+       /* data/mgmt */
+       if (0 /* FIX: data/mgmt during CFP */)
+               return 32768;
+
+       if (group_addr) /* Group address as the destination - no ACK */
+               return 0;
+
+       /* Individual destination address:
+        * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes)
+        * CTS and ACK frames shall be transmitted using the highest rate in
+        * basic rate set that is less than or equal to the rate of the
+        * immediately previous frame and that is using the same modulation
+        * (CCK or OFDM). If no basic rate set matches with these requirements,
+        * the highest mandatory rate of the PHY that is less than or equal to
+        * the rate of the previous frame is used.
+        * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
+        */
+       rate = -1;
+       mrate = 10; /* use 1 Mbps if everything fails */
+       for (i = 0; i < mode->num_rates; i++) {
+               struct ieee80211_rate *r = &mode->rates[i];
+               if (r->rate > txrate->rate)
+                       break;
+
+               if (IEEE80211_RATE_MODULATION(txrate->flags) !=
+                   IEEE80211_RATE_MODULATION(r->flags))
+                       continue;
+
+               if (r->flags & IEEE80211_RATE_BASIC)
+                       rate = r->rate;
+               else if (r->flags & IEEE80211_RATE_MANDATORY)
+                       mrate = r->rate;
+       }
+       if (rate == -1) {
+               /* No matching basic rate found; use highest suitable mandatory
+                * PHY rate */
+               rate = mrate;
+       }
+
+       /* Time needed to transmit ACK
+        * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
+        * to closest integer */
+
+       dur = ieee80211_frame_duration(local, 10, rate, erp,
+                                      local->short_preamble);
+
+       if (next_frag_len) {
+               /* Frame is fragmented: duration increases with time needed to
+                * transmit next fragment plus ACK and 2 x SIFS. */
+               dur *= 2; /* ACK + SIFS */
+               /* next fragment */
+               dur += ieee80211_frame_duration(local, next_frag_len,
+                                               txrate->rate, erp,
+                                               local->short_preamble);
+       }
+
+       return dur;
+}
+
+
+static ieee80211_txrx_result
+ieee80211_tx_h_misc(struct ieee80211_txrx_data *tx)
+{
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
+       u16 dur;
+       struct ieee80211_tx_control *control = tx->u.tx.control;
+       struct ieee80211_hw_mode *mode = tx->u.tx.mode;
+
+       if (!is_multicast_ether_addr(hdr->addr1)) {
+               if (tx->skb->len + FCS_LEN > tx->local->rts_threshold &&
+                   tx->local->rts_threshold < IEEE80211_MAX_RTS_THRESHOLD) {
+                       control->flags |= IEEE80211_TXCTL_USE_RTS_CTS;
+                       control->retry_limit =
+                               tx->local->long_retry_limit;
+               } else {
+                       control->retry_limit =
+                               tx->local->short_retry_limit;
+               }
+       } else {
+               control->retry_limit = 1;
+       }
+
+       if (tx->fragmented) {
+               /* Do not use multiple retry rates when sending fragmented
+                * frames.
+                * TODO: The last fragment could still use multiple retry
+                * rates. */
+               control->alt_retry_rate = -1;
+       }
+
+       /* Use CTS protection for unicast frames sent using extended rates if
+        * there are associated non-ERP stations and RTS/CTS is not configured
+        * for the frame. */
+       if (mode->mode == MODE_IEEE80211G &&
+           (tx->u.tx.rate->flags & IEEE80211_RATE_ERP) &&
+           tx->u.tx.unicast &&
+           tx->local->cts_protect_erp_frames &&
+           !(control->flags & IEEE80211_TXCTL_USE_RTS_CTS))
+               control->flags |= IEEE80211_TXCTL_USE_CTS_PROTECT;
+
+       /* Setup duration field for the first fragment of the frame. Duration
+        * for remaining fragments will be updated when they are being sent
+        * to low-level driver in ieee80211_tx(). */
+       dur = ieee80211_duration(tx, is_multicast_ether_addr(hdr->addr1),
+                                tx->fragmented ? tx->u.tx.extra_frag[0]->len :
+                                0);
+       hdr->duration_id = cpu_to_le16(dur);
+
+       if ((control->flags & IEEE80211_TXCTL_USE_RTS_CTS) ||
+           (control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) {
+               struct ieee80211_rate *rate;
+
+               /* Do not use multiple retry rates when using RTS/CTS */
+               control->alt_retry_rate = -1;
+
+               /* Use min(data rate, max base rate) as CTS/RTS rate */
+               rate = tx->u.tx.rate;
+               while (rate > mode->rates &&
+                      !(rate->flags & IEEE80211_RATE_BASIC))
+                       rate--;
+
+               control->rts_cts_rate = rate->val;
+               control->rts_rate = rate;
+       }
+
+       if (tx->sta) {
+               tx->sta->tx_packets++;
+               tx->sta->tx_fragments++;
+               tx->sta->tx_bytes += tx->skb->len;
+               if (tx->u.tx.extra_frag) {
+                       int i;
+                       tx->sta->tx_fragments += tx->u.tx.num_extra_frag;
+                       for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
+                               tx->sta->tx_bytes +=
+                                       tx->u.tx.extra_frag[i]->len;
+                       }
+               }
+       }
+
+       return TXRX_CONTINUE;
+}
+
+
+static ieee80211_txrx_result
+ieee80211_tx_h_check_assoc(struct ieee80211_txrx_data *tx)
+{
+#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
+       struct sk_buff *skb = tx->skb;
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
+#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
+       u32 sta_flags;
+
+       if (unlikely(tx->local->sta_scanning != 0) &&
+           ((tx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
+            (tx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PROBE_REQ))
+               return TXRX_DROP;
+
+       if (tx->u.tx.ps_buffered)
+               return TXRX_CONTINUE;
+
+       sta_flags = tx->sta ? tx->sta->flags : 0;
+
+       if (likely(tx->u.tx.unicast)) {
+               if (unlikely(!(sta_flags & WLAN_STA_ASSOC) &&
+                            tx->sdata->type != IEEE80211_IF_TYPE_IBSS &&
+                            (tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) {
+#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
+                       printk(KERN_DEBUG "%s: dropped data frame to not "
+                              "associated station " MAC_FMT "\n",
+                              tx->dev->name, MAC_ARG(hdr->addr1));
+#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
+                       I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
+                       return TXRX_DROP;
+               }
+       } else {
+               if (unlikely((tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
+                            tx->local->num_sta == 0 &&
+                            !tx->local->allow_broadcast_always &&
+                            tx->sdata->type != IEEE80211_IF_TYPE_IBSS)) {
+                       /*
+                        * No associated STAs - no need to send multicast
+                        * frames.
+                        */
+                       return TXRX_DROP;
+               }
+               return TXRX_CONTINUE;
+       }
+
+       if (unlikely(!tx->u.tx.mgmt_interface && tx->sdata->ieee802_1x &&
+                    !(sta_flags & WLAN_STA_AUTHORIZED))) {
+#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
+               printk(KERN_DEBUG "%s: dropped frame to " MAC_FMT
+                      " (unauthorized port)\n", tx->dev->name,
+                      MAC_ARG(hdr->addr1));
+#endif
+               I802_DEBUG_INC(tx->local->tx_handlers_drop_unauth_port);
+               return TXRX_DROP;
+       }
+
+       return TXRX_CONTINUE;
+}
+
+static ieee80211_txrx_result
+ieee80211_tx_h_sequence(struct ieee80211_txrx_data *tx)
+{
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
+
+       if (ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control)) >= 24)
+               ieee80211_include_sequence(tx->sdata, hdr);
+
+       return TXRX_CONTINUE;
+}
+
+/* This function is called whenever the AP is about to exceed the maximum limit
+ * of buffered frames for power saving STAs. This situation should not really
+ * happen often during normal operation, so dropping the oldest buffered packet
+ * from each queue should be OK to make some room for new frames. */
+static void purge_old_ps_buffers(struct ieee80211_local *local)
+{
+       int total = 0, purged = 0;
+       struct sk_buff *skb;
+       struct ieee80211_sub_if_data *sdata;
+       struct sta_info *sta;
+
+       read_lock(&local->sub_if_lock);
+       list_for_each_entry(sdata, &local->sub_if_list, list) {
+               struct ieee80211_if_ap *ap;
+               if (sdata->dev == local->mdev ||
+                   sdata->type != IEEE80211_IF_TYPE_AP)
+                       continue;
+               ap = &sdata->u.ap;
+               skb = skb_dequeue(&ap->ps_bc_buf);
+               if (skb) {
+                       purged++;
+                       dev_kfree_skb(skb);
+               }
+               total += skb_queue_len(&ap->ps_bc_buf);
+       }
+       read_unlock(&local->sub_if_lock);
+
+       spin_lock_bh(&local->sta_lock);
+       list_for_each_entry(sta, &local->sta_list, list) {
+               skb = skb_dequeue(&sta->ps_tx_buf);
+               if (skb) {
+                       purged++;
+                       dev_kfree_skb(skb);
+               }
+               total += skb_queue_len(&sta->ps_tx_buf);
+       }
+       spin_unlock_bh(&local->sta_lock);
+
+       local->total_ps_buffered = total;
+       printk(KERN_DEBUG "%s: PS buffers full - purged %d frames\n",
+              local->mdev->name, purged);
+}
+
+
+static inline ieee80211_txrx_result
+ieee80211_tx_h_multicast_ps_buf(struct ieee80211_txrx_data *tx)
+{
+       /* broadcast/multicast frame */
+       /* If any of the associated stations is in power save mode,
+        * the frame is buffered to be sent after DTIM beacon frame */
+       if ((tx->local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING) &&
+           tx->sdata->type != IEEE80211_IF_TYPE_WDS &&
+           tx->sdata->bss && atomic_read(&tx->sdata->bss->num_sta_ps) &&
+           !(tx->fc & IEEE80211_FCTL_ORDER)) {
+               if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
+                       purge_old_ps_buffers(tx->local);
+               if (skb_queue_len(&tx->sdata->bss->ps_bc_buf) >=
+                   AP_MAX_BC_BUFFER) {
+                       if (net_ratelimit()) {
+                               printk(KERN_DEBUG "%s: BC TX buffer full - "
+                                      "dropping the oldest frame\n",
+                                      tx->dev->name);
+                       }
+                       dev_kfree_skb(skb_dequeue(&tx->sdata->bss->ps_bc_buf));
+               } else
+                       tx->local->total_ps_buffered++;
+               skb_queue_tail(&tx->sdata->bss->ps_bc_buf, tx->skb);
+               return TXRX_QUEUED;
+       }
+
+       return TXRX_CONTINUE;
+}
+
+
+static inline ieee80211_txrx_result
+ieee80211_tx_h_unicast_ps_buf(struct ieee80211_txrx_data *tx)
+{
+       struct sta_info *sta = tx->sta;
+
+       if (unlikely(!sta ||
+                    ((tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT &&
+                     (tx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP)))
+               return TXRX_CONTINUE;
+
+       if (unlikely((sta->flags & WLAN_STA_PS) && !sta->pspoll)) {
+               struct ieee80211_tx_packet_data *pkt_data;
+#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
+               printk(KERN_DEBUG "STA " MAC_FMT " aid %d: PS buffer (entries "
+                      "before %d)\n",
+                      MAC_ARG(sta->addr), sta->aid,
+                      skb_queue_len(&sta->ps_tx_buf));
+#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
+               sta->flags |= WLAN_STA_TIM;
+               if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
+                       purge_old_ps_buffers(tx->local);
+               if (skb_queue_len(&sta->ps_tx_buf) >= STA_MAX_TX_BUFFER) {
+                       struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf);
+                       if (net_ratelimit()) {
+                               printk(KERN_DEBUG "%s: STA " MAC_FMT " TX "
+                                      "buffer full - dropping oldest frame\n",
+                                      tx->dev->name, MAC_ARG(sta->addr));
+                       }
+                       dev_kfree_skb(old);
+               } else
+                       tx->local->total_ps_buffered++;
+               /* Queue frame to be sent after STA sends an PS Poll frame */
+               if (skb_queue_empty(&sta->ps_tx_buf)) {
+                       if (tx->local->ops->set_tim)
+                               tx->local->ops->set_tim(local_to_hw(tx->local),
+                                                      sta->aid, 1);
+                       if (tx->sdata->bss)
+                               bss_tim_set(tx->local, tx->sdata->bss, sta->aid);
+               }
+               pkt_data = (struct ieee80211_tx_packet_data *)tx->skb->cb;
+               pkt_data->jiffies = jiffies;
+               skb_queue_tail(&sta->ps_tx_buf, tx->skb);
+               return TXRX_QUEUED;
+       }
+#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
+       else if (unlikely(sta->flags & WLAN_STA_PS)) {
+               printk(KERN_DEBUG "%s: STA " MAC_FMT " in PS mode, but pspoll "
+                      "set -> send frame\n", tx->dev->name,
+                      MAC_ARG(sta->addr));
+       }
+#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
+       sta->pspoll = 0;
+
+       return TXRX_CONTINUE;
+}
+
+
+static ieee80211_txrx_result
+ieee80211_tx_h_ps_buf(struct ieee80211_txrx_data *tx)
+{
+       if (unlikely(tx->u.tx.ps_buffered))
+               return TXRX_CONTINUE;
+
+       if (tx->u.tx.unicast)
+               return ieee80211_tx_h_unicast_ps_buf(tx);
+       else
+               return ieee80211_tx_h_multicast_ps_buf(tx);
+}
+
+
+static void inline
+__ieee80211_tx_prepare(struct ieee80211_txrx_data *tx,
+                      struct sk_buff *skb,
+                      struct net_device *dev,
+                      struct ieee80211_tx_control *control)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
+       int hdrlen;
+
+       memset(tx, 0, sizeof(*tx));
+       tx->skb = skb;
+       tx->dev = dev; /* use original interface */
+       tx->local = local;
+       tx->sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+       tx->sta = sta_info_get(local, hdr->addr1);
+       tx->fc = le16_to_cpu(hdr->frame_control);
+       control->power_level = local->hw.conf.power_level;
+       tx->u.tx.control = control;
+       tx->u.tx.unicast = !is_multicast_ether_addr(hdr->addr1);
+       if (is_multicast_ether_addr(hdr->addr1))
+               control->flags |= IEEE80211_TXCTL_NO_ACK;
+       else
+               control->flags &= ~IEEE80211_TXCTL_NO_ACK;
+       tx->fragmented = local->fragmentation_threshold <
+               IEEE80211_MAX_FRAG_THRESHOLD && tx->u.tx.unicast &&
+               skb->len + FCS_LEN > local->fragmentation_threshold &&
+               (!local->ops->set_frag_threshold);
+       if (!tx->sta)
+               control->flags |= IEEE80211_TXCTL_CLEAR_DST_MASK;
+       else if (tx->sta->clear_dst_mask) {
+               control->flags |= IEEE80211_TXCTL_CLEAR_DST_MASK;
+               tx->sta->clear_dst_mask = 0;
+       }
+       control->antenna_sel_tx = local->hw.conf.antenna_sel_tx;
+       if (local->sta_antenna_sel != STA_ANTENNA_SEL_AUTO && tx->sta)
+               control->antenna_sel_tx = tx->sta->antenna_sel_tx;
+       hdrlen = ieee80211_get_hdrlen(tx->fc);
+       if (skb->len > hdrlen + sizeof(rfc1042_header) + 2) {
+               u8 *pos = &skb->data[hdrlen + sizeof(rfc1042_header)];
+               tx->ethertype = (pos[0] << 8) | pos[1];
+       }
+       control->flags |= IEEE80211_TXCTL_FIRST_FRAGMENT;
+
+}
+
+static int inline is_ieee80211_device(struct net_device *dev,
+                                     struct net_device *master)
+{
+       return (wdev_priv(dev->ieee80211_ptr) ==
+               wdev_priv(master->ieee80211_ptr));
+}
+
+/* Device in tx->dev has a reference added; use dev_put(tx->dev) when
+ * finished with it. */
+static int inline ieee80211_tx_prepare(struct ieee80211_txrx_data *tx,
+                                      struct sk_buff *skb,
+                                      struct net_device *mdev,
+                                      struct ieee80211_tx_control *control)
+{
+       struct ieee80211_tx_packet_data *pkt_data;
+       struct net_device *dev;
+
+       pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
+       dev = dev_get_by_index(pkt_data->ifindex);
+       if (unlikely(dev && !is_ieee80211_device(dev, mdev))) {
+               dev_put(dev);
+               dev = NULL;
+       }
+       if (unlikely(!dev))
+               return -ENODEV;
+       __ieee80211_tx_prepare(tx, skb, dev, control);
+       return 0;
+}
+
+static inline int __ieee80211_queue_stopped(const struct ieee80211_local *local,
+                                           int queue)
+{
+       return test_bit(IEEE80211_LINK_STATE_XOFF, &local->state[queue]);
+}
+
+static inline int __ieee80211_queue_pending(const struct ieee80211_local *local,
+                                           int queue)
+{
+       return test_bit(IEEE80211_LINK_STATE_PENDING, &local->state[queue]);
+}
+
+#define IEEE80211_TX_OK                0
+#define IEEE80211_TX_AGAIN     1
+#define IEEE80211_TX_FRAG_AGAIN        2
+
+static int __ieee80211_tx(struct ieee80211_local *local, struct sk_buff *skb,
+                         struct ieee80211_txrx_data *tx)
+{
+       struct ieee80211_tx_control *control = tx->u.tx.control;
+       int ret, i;
+
+       if (!ieee80211_qdisc_installed(local->mdev) &&
+           __ieee80211_queue_stopped(local, 0)) {
+               netif_stop_queue(local->mdev);
+               return IEEE80211_TX_AGAIN;
+       }
+       if (skb) {
+               ieee80211_dump_frame(local->mdev->name, "TX to low-level driver", skb);
+               ret = local->ops->tx(local_to_hw(local), skb, control);
+               if (ret)
+                       return IEEE80211_TX_AGAIN;
+               local->mdev->trans_start = jiffies;
+               ieee80211_led_tx(local, 1);
+       }
+       if (tx->u.tx.extra_frag) {
+               control->flags &= ~(IEEE80211_TXCTL_USE_RTS_CTS |
+                                   IEEE80211_TXCTL_USE_CTS_PROTECT |
+                                   IEEE80211_TXCTL_CLEAR_DST_MASK |
+                                   IEEE80211_TXCTL_FIRST_FRAGMENT);
+               for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
+                       if (!tx->u.tx.extra_frag[i])
+                               continue;
+                       if (__ieee80211_queue_stopped(local, control->queue))
+                               return IEEE80211_TX_FRAG_AGAIN;
+                       if (i == tx->u.tx.num_extra_frag) {
+                               control->tx_rate = tx->u.tx.last_frag_hwrate;
+                               control->rate = tx->u.tx.last_frag_rate;
+                               if (tx->u.tx.probe_last_frag)
+                                       control->flags |=
+                                               IEEE80211_TXCTL_RATE_CTRL_PROBE;
+                               else
+                                       control->flags &=
+                                               ~IEEE80211_TXCTL_RATE_CTRL_PROBE;
+                       }
+
+                       ieee80211_dump_frame(local->mdev->name,
+                                            "TX to low-level driver",
+                                            tx->u.tx.extra_frag[i]);
+                       ret = local->ops->tx(local_to_hw(local),
+                                           tx->u.tx.extra_frag[i],
+                                           control);
+                       if (ret)
+                               return IEEE80211_TX_FRAG_AGAIN;
+                       local->mdev->trans_start = jiffies;
+                       ieee80211_led_tx(local, 1);
+                       tx->u.tx.extra_frag[i] = NULL;
+               }
+               kfree(tx->u.tx.extra_frag);
+               tx->u.tx.extra_frag = NULL;
+       }
+       return IEEE80211_TX_OK;
+}
+
+static int ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
+                       struct ieee80211_tx_control *control, int mgmt)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct sta_info *sta;
+       ieee80211_tx_handler *handler;
+       struct ieee80211_txrx_data tx;
+       ieee80211_txrx_result res = TXRX_DROP;
+       int ret, i;
+
+       WARN_ON(__ieee80211_queue_pending(local, control->queue));
+
+       if (unlikely(skb->len < 10)) {
+               dev_kfree_skb(skb);
+               return 0;
+       }
+
+       __ieee80211_tx_prepare(&tx, skb, dev, control);
+       sta = tx.sta;
+       tx.u.tx.mgmt_interface = mgmt;
+       tx.u.tx.mode = local->hw.conf.mode;
+
+       for (handler = local->tx_handlers; *handler != NULL; handler++) {
+               res = (*handler)(&tx);
+               if (res != TXRX_CONTINUE)
+                       break;
+       }
+
+       skb = tx.skb; /* handlers are allowed to change skb */
+
+       if (sta)
+               sta_info_put(sta);
+
+       if (unlikely(res == TXRX_DROP)) {
+               I802_DEBUG_INC(local->tx_handlers_drop);
+               goto drop;
+       }
+
+       if (unlikely(res == TXRX_QUEUED)) {
+               I802_DEBUG_INC(local->tx_handlers_queued);
+               return 0;
+       }
+
+       if (tx.u.tx.extra_frag) {
+               for (i = 0; i < tx.u.tx.num_extra_frag; i++) {
+                       int next_len, dur;
+                       struct ieee80211_hdr *hdr =
+                               (struct ieee80211_hdr *)
+                               tx.u.tx.extra_frag[i]->data;
+
+                       if (i + 1 < tx.u.tx.num_extra_frag) {
+                               next_len = tx.u.tx.extra_frag[i + 1]->len;
+                       } else {
+                               next_len = 0;
+                               tx.u.tx.rate = tx.u.tx.last_frag_rate;
+                               tx.u.tx.last_frag_hwrate = tx.u.tx.rate->val;
+                       }
+                       dur = ieee80211_duration(&tx, 0, next_len);
+                       hdr->duration_id = cpu_to_le16(dur);
+               }
+       }
+
+retry:
+       ret = __ieee80211_tx(local, skb, &tx);
+       if (ret) {
+               struct ieee80211_tx_stored_packet *store =
+                       &local->pending_packet[control->queue];
+
+               if (ret == IEEE80211_TX_FRAG_AGAIN)
+                       skb = NULL;
+               set_bit(IEEE80211_LINK_STATE_PENDING,
+                       &local->state[control->queue]);
+               smp_mb();
+               /* When the driver gets out of buffers during sending of
+                * fragments and calls ieee80211_stop_queue, there is
+                * a small window between IEEE80211_LINK_STATE_XOFF and
+                * IEEE80211_LINK_STATE_PENDING flags are set. If a buffer
+                * gets available in that window (i.e. driver calls
+                * ieee80211_wake_queue), we would end up with ieee80211_tx
+                * called with IEEE80211_LINK_STATE_PENDING. Prevent this by
+                * continuing transmitting here when that situation is
+                * possible to have happened. */
+               if (!__ieee80211_queue_stopped(local, control->queue)) {
+                       clear_bit(IEEE80211_LINK_STATE_PENDING,
+                                 &local->state[control->queue]);
+                       goto retry;
+               }
+               memcpy(&store->control, control,
+                      sizeof(struct ieee80211_tx_control));
+               store->skb = skb;
+               store->extra_frag = tx.u.tx.extra_frag;
+               store->num_extra_frag = tx.u.tx.num_extra_frag;
+               store->last_frag_hwrate = tx.u.tx.last_frag_hwrate;
+               store->last_frag_rate = tx.u.tx.last_frag_rate;
+               store->last_frag_rate_ctrl_probe = tx.u.tx.probe_last_frag;
+       }
+       return 0;
+
+ drop:
+       if (skb)
+               dev_kfree_skb(skb);
+       for (i = 0; i < tx.u.tx.num_extra_frag; i++)
+               if (tx.u.tx.extra_frag[i])
+                       dev_kfree_skb(tx.u.tx.extra_frag[i]);
+       kfree(tx.u.tx.extra_frag);
+       return 0;
+}
+
+static void ieee80211_tx_pending(unsigned long data)
+{
+       struct ieee80211_local *local = (struct ieee80211_local *)data;
+       struct net_device *dev = local->mdev;
+       struct ieee80211_tx_stored_packet *store;
+       struct ieee80211_txrx_data tx;
+       int i, ret, reschedule = 0;
+
+       netif_tx_lock_bh(dev);
+       for (i = 0; i < local->hw.queues; i++) {
+               if (__ieee80211_queue_stopped(local, i))
+                       continue;
+               if (!__ieee80211_queue_pending(local, i)) {
+                       reschedule = 1;
+                       continue;
+               }
+               store = &local->pending_packet[i];
+               tx.u.tx.control = &store->control;
+               tx.u.tx.extra_frag = store->extra_frag;
+               tx.u.tx.num_extra_frag = store->num_extra_frag;
+               tx.u.tx.last_frag_hwrate = store->last_frag_hwrate;
+               tx.u.tx.last_frag_rate = store->last_frag_rate;
+               tx.u.tx.probe_last_frag = store->last_frag_rate_ctrl_probe;
+               ret = __ieee80211_tx(local, store->skb, &tx);
+               if (ret) {
+                       if (ret == IEEE80211_TX_FRAG_AGAIN)
+                               store->skb = NULL;
+               } else {
+                       clear_bit(IEEE80211_LINK_STATE_PENDING,
+                                 &local->state[i]);
+                       reschedule = 1;
+               }
+       }
+       netif_tx_unlock_bh(dev);
+       if (reschedule) {
+               if (!ieee80211_qdisc_installed(dev)) {
+                       if (!__ieee80211_queue_stopped(local, 0))
+                               netif_wake_queue(dev);
+               } else
+                       netif_schedule(dev);
+       }
+}
+
+static void ieee80211_clear_tx_pending(struct ieee80211_local *local)
+{
+       int i, j;
+       struct ieee80211_tx_stored_packet *store;
+
+       for (i = 0; i < local->hw.queues; i++) {
+               if (!__ieee80211_queue_pending(local, i))
+                       continue;
+               store = &local->pending_packet[i];
+               kfree_skb(store->skb);
+               for (j = 0; j < store->num_extra_frag; j++)
+                       kfree_skb(store->extra_frag[j]);
+               kfree(store->extra_frag);
+               clear_bit(IEEE80211_LINK_STATE_PENDING, &local->state[i]);
+       }
+}
+
+static int ieee80211_master_start_xmit(struct sk_buff *skb,
+                                      struct net_device *dev)
+{
+       struct ieee80211_tx_control control;
+       struct ieee80211_tx_packet_data *pkt_data;
+       struct net_device *odev = NULL;
+       struct ieee80211_sub_if_data *osdata;
+       int headroom;
+       int ret;
+
+       /*
+        * copy control out of the skb so other people can use skb->cb
+        */
+       pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
+       memset(&control, 0, sizeof(struct ieee80211_tx_control));
+
+       if (pkt_data->ifindex)
+               odev = dev_get_by_index(pkt_data->ifindex);
+       if (unlikely(odev && !is_ieee80211_device(odev, dev))) {
+               dev_put(odev);
+               odev = NULL;
+       }
+       if (unlikely(!odev)) {
+#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
+               printk(KERN_DEBUG "%s: Discarded packet with nonexistent "
+                      "originating device\n", dev->name);
+#endif
+               dev_kfree_skb(skb);
+               return 0;
+       }
+       osdata = IEEE80211_DEV_TO_SUB_IF(odev);
+
+       headroom = osdata->local->hw.extra_tx_headroom +
+               IEEE80211_ENCRYPT_HEADROOM;
+       if (skb_headroom(skb) < headroom) {
+               if (pskb_expand_head(skb, headroom, 0, GFP_ATOMIC)) {
+                       dev_kfree_skb(skb);
+                       return 0;
+               }
+       }
+
+       control.ifindex = odev->ifindex;
+       control.type = osdata->type;
+       if (pkt_data->req_tx_status)
+               control.flags |= IEEE80211_TXCTL_REQ_TX_STATUS;
+       if (pkt_data->do_not_encrypt)
+               control.flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT;
+       if (pkt_data->requeue)
+               control.flags |= IEEE80211_TXCTL_REQUEUE;
+       control.queue = pkt_data->queue;
+
+       ret = ieee80211_tx(odev, skb, &control,
+                          control.type == IEEE80211_IF_TYPE_MGMT);
+       dev_put(odev);
+
+       return ret;
+}
+
+
+/**
+ * ieee80211_subif_start_xmit - netif start_xmit function for Ethernet-type
+ * subinterfaces (wlan#, WDS, and VLAN interfaces)
+ * @skb: packet to be sent
+ * @dev: incoming interface
+ *
+ * Returns: 0 on success (and frees skb in this case) or 1 on failure (skb will
+ * not be freed, and caller is responsible for either retrying later or freeing
+ * skb).
+ *
+ * This function takes in an Ethernet header and encapsulates it with suitable
+ * IEEE 802.11 header based on which interface the packet is coming in. The
+ * encapsulated packet will then be passed to master interface, wlan#.11, for
+ * transmission (through low-level driver).
+ */
+static int ieee80211_subif_start_xmit(struct sk_buff *skb,
+                                     struct net_device *dev)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_tx_packet_data *pkt_data;
+       struct ieee80211_sub_if_data *sdata;
+       int ret = 1, head_need;
+       u16 ethertype, hdrlen, fc;
+       struct ieee80211_hdr hdr;
+       const u8 *encaps_data;
+       int encaps_len, skip_header_bytes;
+       int nh_pos, h_pos, no_encrypt = 0;
+       struct sta_info *sta;
+
+       sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+       if (unlikely(skb->len < ETH_HLEN)) {
+               printk(KERN_DEBUG "%s: short skb (len=%d)\n",
+                      dev->name, skb->len);
+               ret = 0;
+               goto fail;
+       }
+
+       nh_pos = skb_network_header(skb) - skb->data;
+       h_pos = skb_transport_header(skb) - skb->data;
+
+       /* convert Ethernet header to proper 802.11 header (based on
+        * operation mode) */
+       ethertype = (skb->data[12] << 8) | skb->data[13];
+       /* TODO: handling for 802.1x authorized/unauthorized port */
+       fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA;
+
+       if (likely(sdata->type == IEEE80211_IF_TYPE_AP ||
+                  sdata->type == IEEE80211_IF_TYPE_VLAN)) {
+               fc |= IEEE80211_FCTL_FROMDS;
+               /* DA BSSID SA */
+               memcpy(hdr.addr1, skb->data, ETH_ALEN);
+               memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
+               memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
+               hdrlen = 24;
+       } else if (sdata->type == IEEE80211_IF_TYPE_WDS) {
+               fc |= IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS;
+               /* RA TA DA SA */
+               memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN);
+               memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
+               memcpy(hdr.addr3, skb->data, ETH_ALEN);
+               memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
+               hdrlen = 30;
+       } else if (sdata->type == IEEE80211_IF_TYPE_STA) {
+               fc |= IEEE80211_FCTL_TODS;
+               /* BSSID SA DA */
+               memcpy(hdr.addr1, sdata->u.sta.bssid, ETH_ALEN);
+               memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
+               memcpy(hdr.addr3, skb->data, ETH_ALEN);
+               hdrlen = 24;
+       } else if (sdata->type == IEEE80211_IF_TYPE_IBSS) {
+               /* DA SA BSSID */
+               memcpy(hdr.addr1, skb->data, ETH_ALEN);
+               memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
+               memcpy(hdr.addr3, sdata->u.sta.bssid, ETH_ALEN);
+               hdrlen = 24;
+       } else {
+               ret = 0;
+               goto fail;
+       }
+
+       /* receiver is QoS enabled, use a QoS type frame */
+       sta = sta_info_get(local, hdr.addr1);
+       if (sta) {
+               if (sta->flags & WLAN_STA_WME) {
+                       fc |= IEEE80211_STYPE_QOS_DATA;
+                       hdrlen += 2;
+               }
+               sta_info_put(sta);
+       }
+
+       hdr.frame_control = cpu_to_le16(fc);
+       hdr.duration_id = 0;
+       hdr.seq_ctrl = 0;
+
+       skip_header_bytes = ETH_HLEN;
+       if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
+               encaps_data = bridge_tunnel_header;
+               encaps_len = sizeof(bridge_tunnel_header);
+               skip_header_bytes -= 2;
+       } else if (ethertype >= 0x600) {
+               encaps_data = rfc1042_header;
+               encaps_len = sizeof(rfc1042_header);
+               skip_header_bytes -= 2;
+       } else {
+               encaps_data = NULL;
+               encaps_len = 0;
+       }
+
+       skb_pull(skb, skip_header_bytes);
+       nh_pos -= skip_header_bytes;
+       h_pos -= skip_header_bytes;
+
+       /* TODO: implement support for fragments so that there is no need to
+        * reallocate and copy payload; it might be enough to support one
+        * extra fragment that would be copied in the beginning of the frame
+        * data.. anyway, it would be nice to include this into skb structure
+        * somehow
+        *
+        * There are few options for this:
+        * use skb->cb as an extra space for 802.11 header
+        * allocate new buffer if not enough headroom
+        * make sure that there is enough headroom in every skb by increasing
+        * build in headroom in __dev_alloc_skb() (linux/skbuff.h) and
+        * alloc_skb() (net/core/skbuff.c)
+        */
+       head_need = hdrlen + encaps_len + local->hw.extra_tx_headroom;
+       head_need -= skb_headroom(skb);
+
+       /* We are going to modify skb data, so make a copy of it if happens to
+        * be cloned. This could happen, e.g., with Linux bridge code passing
+        * us broadcast frames. */
+
+       if (head_need > 0 || skb_cloned(skb)) {
+#if 0
+               printk(KERN_DEBUG "%s: need to reallocate buffer for %d bytes "
+                      "of headroom\n", dev->name, head_need);
+#endif
+
+               if (skb_cloned(skb))
+                       I802_DEBUG_INC(local->tx_expand_skb_head_cloned);
+               else
+                       I802_DEBUG_INC(local->tx_expand_skb_head);
+               /* Since we have to reallocate the buffer, make sure that there
+                * is enough room for possible WEP IV/ICV and TKIP (8 bytes
+                * before payload and 12 after). */
+               if (pskb_expand_head(skb, (head_need > 0 ? head_need + 8 : 8),
+                                    12, GFP_ATOMIC)) {
+                       printk(KERN_DEBUG "%s: failed to reallocate TX buffer"
+                              "\n", dev->name);
+                       goto fail;
+               }
+       }
+
+       if (encaps_data) {
+               memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
+               nh_pos += encaps_len;
+               h_pos += encaps_len;
+       }
+       memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
+       nh_pos += hdrlen;
+       h_pos += hdrlen;
+
+       pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
+       memset(pkt_data, 0, sizeof(struct ieee80211_tx_packet_data));
+       pkt_data->ifindex = sdata->dev->ifindex;
+       pkt_data->mgmt_iface = (sdata->type == IEEE80211_IF_TYPE_MGMT);
+       pkt_data->do_not_encrypt = no_encrypt;
+
+       skb->dev = local->mdev;
+       sdata->stats.tx_packets++;
+       sdata->stats.tx_bytes += skb->len;
+
+       /* Update skb pointers to various headers since this modified frame
+        * is going to go through Linux networking code that may potentially
+        * need things like pointer to IP header. */
+       skb_set_mac_header(skb, 0);
+       skb_set_network_header(skb, nh_pos);
+       skb_set_transport_header(skb, h_pos);
+
+       dev->trans_start = jiffies;
+       dev_queue_xmit(skb);
+
+       return 0;
+
+ fail:
+       if (!ret)
+               dev_kfree_skb(skb);
+
+       return ret;
+}
+
+
+/*
+ * This is the transmit routine for the 802.11 type interfaces
+ * called by upper layers of the linux networking
+ * stack when it has a frame to transmit
+ */
+static int
+ieee80211_mgmt_start_xmit(struct sk_buff *skb, struct net_device *dev)
+{
+       struct ieee80211_sub_if_data *sdata;
+       struct ieee80211_tx_packet_data *pkt_data;
+       struct ieee80211_hdr *hdr;
+       u16 fc;
+
+       sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+
+       if (skb->len < 10) {
+               dev_kfree_skb(skb);
+               return 0;
+       }
+
+       if (skb_headroom(skb) < sdata->local->hw.extra_tx_headroom) {
+               if (pskb_expand_head(skb,
+                   sdata->local->hw.extra_tx_headroom, 0, GFP_ATOMIC)) {
+                       dev_kfree_skb(skb);
+                       return 0;
+               }
+       }
+
+       hdr = (struct ieee80211_hdr *) skb->data;
+       fc = le16_to_cpu(hdr->frame_control);
+
+       pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
+       memset(pkt_data, 0, sizeof(struct ieee80211_tx_packet_data));
+       pkt_data->ifindex = sdata->dev->ifindex;
+       pkt_data->mgmt_iface = (sdata->type == IEEE80211_IF_TYPE_MGMT);
+
+       skb->priority = 20; /* use hardcoded priority for mgmt TX queue */
+       skb->dev = sdata->local->mdev;
+
+       /*
+        * We're using the protocol field of the the frame control header
+        * to request TX callback for hostapd. BIT(1) is checked.
+        */
+       if ((fc & BIT(1)) == BIT(1)) {
+               pkt_data->req_tx_status = 1;
+               fc &= ~BIT(1);
+               hdr->frame_control = cpu_to_le16(fc);
+       }
+
+       pkt_data->do_not_encrypt = !(fc & IEEE80211_FCTL_PROTECTED);
+
+       sdata->stats.tx_packets++;
+       sdata->stats.tx_bytes += skb->len;
+
+       dev_queue_xmit(skb);
+
+       return 0;
+}
+
+
+static void ieee80211_beacon_add_tim(struct ieee80211_local *local,
+                                    struct ieee80211_if_ap *bss,
+                                    struct sk_buff *skb)
+{
+       u8 *pos, *tim;
+       int aid0 = 0;
+       int i, have_bits = 0, n1, n2;
+
+       /* Generate bitmap for TIM only if there are any STAs in power save
+        * mode. */
+       spin_lock_bh(&local->sta_lock);
+       if (atomic_read(&bss->num_sta_ps) > 0)
+               /* in the hope that this is faster than
+                * checking byte-for-byte */
+               have_bits = !bitmap_empty((unsigned long*)bss->tim,
+                                         IEEE80211_MAX_AID+1);
+
+       if (bss->dtim_count == 0)
+               bss->dtim_count = bss->dtim_period - 1;
+       else
+               bss->dtim_count--;
+
+       tim = pos = (u8 *) skb_put(skb, 6);
+       *pos++ = WLAN_EID_TIM;
+       *pos++ = 4;
+       *pos++ = bss->dtim_count;
+       *pos++ = bss->dtim_period;
+
+       if (bss->dtim_count == 0 && !skb_queue_empty(&bss->ps_bc_buf))
+               aid0 = 1;
+
+       if (have_bits) {
+               /* Find largest even number N1 so that bits numbered 1 through
+                * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
+                * (N2 + 1) x 8 through 2007 are 0. */
+               n1 = 0;
+               for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) {
+                       if (bss->tim[i]) {
+                               n1 = i & 0xfe;
+                               break;
+                       }
+               }
+               n2 = n1;
+               for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) {
+                       if (bss->tim[i]) {
+                               n2 = i;
+                               break;
+                       }
+               }
+
+               /* Bitmap control */
+               *pos++ = n1 | aid0;
+               /* Part Virt Bitmap */
+               memcpy(pos, bss->tim + n1, n2 - n1 + 1);
+
+               tim[1] = n2 - n1 + 4;
+               skb_put(skb, n2 - n1);
+       } else {
+               *pos++ = aid0; /* Bitmap control */
+               *pos++ = 0; /* Part Virt Bitmap */
+       }
+       spin_unlock_bh(&local->sta_lock);
+}
+
+
+struct sk_buff * ieee80211_beacon_get(struct ieee80211_hw *hw, int if_id,
+                                     struct ieee80211_tx_control *control)
+{
+       struct ieee80211_local *local = hw_to_local(hw);
+       struct sk_buff *skb;
+       struct net_device *bdev;
+       struct ieee80211_sub_if_data *sdata = NULL;
+       struct ieee80211_if_ap *ap = NULL;
+       struct ieee80211_rate *rate;
+       struct rate_control_extra extra;
+       u8 *b_head, *b_tail;
+       int bh_len, bt_len;
+
+       bdev = dev_get_by_index(if_id);
+       if (bdev) {
+               sdata = IEEE80211_DEV_TO_SUB_IF(bdev);
+               ap = &sdata->u.ap;
+               dev_put(bdev);
+       }
+
+       if (!ap || sdata->type != IEEE80211_IF_TYPE_AP ||
+           !ap->beacon_head) {
+#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
+               if (net_ratelimit())
+                       printk(KERN_DEBUG "no beacon data avail for idx=%d "
+                              "(%s)\n", if_id, bdev ? bdev->name : "N/A");
+#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
+               return NULL;
+       }
+
+       /* Assume we are generating the normal beacon locally */
+       b_head = ap->beacon_head;
+       b_tail = ap->beacon_tail;
+       bh_len = ap->beacon_head_len;
+       bt_len = ap->beacon_tail_len;
+
+       skb = dev_alloc_skb(local->hw.extra_tx_headroom +
+               bh_len + bt_len + 256 /* maximum TIM len */);
+       if (!skb)
+               return NULL;
+
+       skb_reserve(skb, local->hw.extra_tx_headroom);
+       memcpy(skb_put(skb, bh_len), b_head, bh_len);
+
+       ieee80211_include_sequence(sdata, (struct ieee80211_hdr *)skb->data);
+
+       ieee80211_beacon_add_tim(local, ap, skb);
+
+       if (b_tail) {
+               memcpy(skb_put(skb, bt_len), b_tail, bt_len);
+       }
+
+       if (control) {
+               memset(&extra, 0, sizeof(extra));
+               extra.mode = local->oper_hw_mode;
+
+               rate = rate_control_get_rate(local, local->mdev, skb, &extra);
+               if (!rate) {
+                       if (net_ratelimit()) {
+                               printk(KERN_DEBUG "%s: ieee80211_beacon_get: no rate "
+                                      "found\n", local->mdev->name);
+                       }
+                       dev_kfree_skb(skb);
+                       return NULL;
+               }
+
+               control->tx_rate = (local->short_preamble &&
+                                   (rate->flags & IEEE80211_RATE_PREAMBLE2)) ?
+                       rate->val2 : rate->val;
+               control->antenna_sel_tx = local->hw.conf.antenna_sel_tx;
+               control->power_level = local->hw.conf.power_level;
+               control->flags |= IEEE80211_TXCTL_NO_ACK;
+               control->retry_limit = 1;
+               control->flags |= IEEE80211_TXCTL_CLEAR_DST_MASK;
+       }
+
+       ap->num_beacons++;
+       return skb;
+}
+EXPORT_SYMBOL(ieee80211_beacon_get);
+
+__le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
+                             size_t frame_len,
+                             const struct ieee80211_tx_control *frame_txctl)
+{
+       struct ieee80211_local *local = hw_to_local(hw);
+       struct ieee80211_rate *rate;
+       int short_preamble = local->short_preamble;
+       int erp;
+       u16 dur;
+
+       rate = frame_txctl->rts_rate;
+       erp = !!(rate->flags & IEEE80211_RATE_ERP);
+
+       /* CTS duration */
+       dur = ieee80211_frame_duration(local, 10, rate->rate,
+                                      erp, short_preamble);
+       /* Data frame duration */
+       dur += ieee80211_frame_duration(local, frame_len, rate->rate,
+                                       erp, short_preamble);
+       /* ACK duration */
+       dur += ieee80211_frame_duration(local, 10, rate->rate,
+                                       erp, short_preamble);
+
+       return cpu_to_le16(dur);
+}
+EXPORT_SYMBOL(ieee80211_rts_duration);
+
+
+__le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
+                                   size_t frame_len,
+                                   const struct ieee80211_tx_control *frame_txctl)
+{
+       struct ieee80211_local *local = hw_to_local(hw);
+       struct ieee80211_rate *rate;
+       int short_preamble = local->short_preamble;
+       int erp;
+       u16 dur;
+
+       rate = frame_txctl->rts_rate;
+       erp = !!(rate->flags & IEEE80211_RATE_ERP);
+
+       /* Data frame duration */
+       dur = ieee80211_frame_duration(local, frame_len, rate->rate,
+                                      erp, short_preamble);
+       if (!(frame_txctl->flags & IEEE80211_TXCTL_NO_ACK)) {
+               /* ACK duration */
+               dur += ieee80211_frame_duration(local, 10, rate->rate,
+                                               erp, short_preamble);
+       }
+
+       return cpu_to_le16(dur);
+}
+EXPORT_SYMBOL(ieee80211_ctstoself_duration);
+
+void ieee80211_rts_get(struct ieee80211_hw *hw,
+                      const void *frame, size_t frame_len,
+                      const struct ieee80211_tx_control *frame_txctl,
+                      struct ieee80211_rts *rts)
+{
+       const struct ieee80211_hdr *hdr = frame;
+       u16 fctl;
+
+       fctl = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS;
+       rts->frame_control = cpu_to_le16(fctl);
+       rts->duration = ieee80211_rts_duration(hw, frame_len, frame_txctl);
+       memcpy(rts->ra, hdr->addr1, sizeof(rts->ra));
+       memcpy(rts->ta, hdr->addr2, sizeof(rts->ta));
+}
+EXPORT_SYMBOL(ieee80211_rts_get);
+
+void ieee80211_ctstoself_get(struct ieee80211_hw *hw,
+                            const void *frame, size_t frame_len,
+                            const struct ieee80211_tx_control *frame_txctl,
+                            struct ieee80211_cts *cts)
+{
+       const struct ieee80211_hdr *hdr = frame;
+       u16 fctl;
+
+       fctl = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS;
+       cts->frame_control = cpu_to_le16(fctl);
+       cts->duration = ieee80211_ctstoself_duration(hw, frame_len, frame_txctl);
+       memcpy(cts->ra, hdr->addr1, sizeof(cts->ra));
+}
+EXPORT_SYMBOL(ieee80211_ctstoself_get);
+
+struct sk_buff *
+ieee80211_get_buffered_bc(struct ieee80211_hw *hw, int if_id,
+                         struct ieee80211_tx_control *control)
+{
+       struct ieee80211_local *local = hw_to_local(hw);
+       struct sk_buff *skb;
+       struct sta_info *sta;
+       ieee80211_tx_handler *handler;
+       struct ieee80211_txrx_data tx;
+       ieee80211_txrx_result res = TXRX_DROP;
+       struct net_device *bdev;
+       struct ieee80211_sub_if_data *sdata;
+       struct ieee80211_if_ap *bss = NULL;
+
+       bdev = dev_get_by_index(if_id);
+       if (bdev) {
+               sdata = IEEE80211_DEV_TO_SUB_IF(bdev);
+               bss = &sdata->u.ap;
+               dev_put(bdev);
+       }
+       if (!bss || sdata->type != IEEE80211_IF_TYPE_AP || !bss->beacon_head)
+               return NULL;
+
+       if (bss->dtim_count != 0)
+               return NULL; /* send buffered bc/mc only after DTIM beacon */
+       memset(control, 0, sizeof(*control));
+       while (1) {
+               skb = skb_dequeue(&bss->ps_bc_buf);
+               if (!skb)
+                       return NULL;
+               local->total_ps_buffered--;
+
+               if (!skb_queue_empty(&bss->ps_bc_buf) && skb->len >= 2) {
+                       struct ieee80211_hdr *hdr =
+                               (struct ieee80211_hdr *) skb->data;
+                       /* more buffered multicast/broadcast frames ==> set
+                        * MoreData flag in IEEE 802.11 header to inform PS
+                        * STAs */
+                       hdr->frame_control |=
+                               cpu_to_le16(IEEE80211_FCTL_MOREDATA);
+               }
+
+               if (ieee80211_tx_prepare(&tx, skb, local->mdev, control) == 0)
+                       break;
+               dev_kfree_skb_any(skb);
+       }
+       sta = tx.sta;
+       tx.u.tx.ps_buffered = 1;
+
+       for (handler = local->tx_handlers; *handler != NULL; handler++) {
+               res = (*handler)(&tx);
+               if (res == TXRX_DROP || res == TXRX_QUEUED)
+                       break;
+       }
+       dev_put(tx.dev);
+       skb = tx.skb; /* handlers are allowed to change skb */
+
+       if (res == TXRX_DROP) {
+               I802_DEBUG_INC(local->tx_handlers_drop);
+               dev_kfree_skb(skb);
+               skb = NULL;
+       } else if (res == TXRX_QUEUED) {
+               I802_DEBUG_INC(local->tx_handlers_queued);
+               skb = NULL;
+       }
+
+       if (sta)
+               sta_info_put(sta);
+
+       return skb;
+}
+EXPORT_SYMBOL(ieee80211_get_buffered_bc);
+
+static int __ieee80211_if_config(struct net_device *dev,
+                                struct sk_buff *beacon,
+                                struct ieee80211_tx_control *control)
+{
+       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_if_conf conf;
+       static u8 scan_bssid[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
+
+       if (!local->ops->config_interface || !netif_running(dev))
+               return 0;
+
+       memset(&conf, 0, sizeof(conf));
+       conf.type = sdata->type;
+       if (sdata->type == IEEE80211_IF_TYPE_STA ||
+           sdata->type == IEEE80211_IF_TYPE_IBSS) {
+               if (local->sta_scanning &&
+                   local->scan_dev == dev)
+                       conf.bssid = scan_bssid;
+               else
+                       conf.bssid = sdata->u.sta.bssid;
+               conf.ssid = sdata->u.sta.ssid;
+               conf.ssid_len = sdata->u.sta.ssid_len;
+               conf.generic_elem = sdata->u.sta.extra_ie;
+               conf.generic_elem_len = sdata->u.sta.extra_ie_len;
+       } else if (sdata->type == IEEE80211_IF_TYPE_AP) {
+               conf.ssid = sdata->u.ap.ssid;
+               conf.ssid_len = sdata->u.ap.ssid_len;
+               conf.generic_elem = sdata->u.ap.generic_elem;
+               conf.generic_elem_len = sdata->u.ap.generic_elem_len;
+               conf.beacon = beacon;
+               conf.beacon_control = control;
+       }
+       return local->ops->config_interface(local_to_hw(local),
+                                          dev->ifindex, &conf);
+}
+
+int ieee80211_if_config(struct net_device *dev)
+{
+       return __ieee80211_if_config(dev, NULL, NULL);
+}
+
+int ieee80211_if_config_beacon(struct net_device *dev)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_tx_control control;
+       struct sk_buff *skb;
+
+       if (!(local->hw.flags & IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE))
+               return 0;
+       skb = ieee80211_beacon_get(local_to_hw(local), dev->ifindex, &control);
+       if (!skb)
+               return -ENOMEM;
+       return __ieee80211_if_config(dev, skb, &control);
+}
+
+int ieee80211_hw_config(struct ieee80211_local *local)
+{
+       struct ieee80211_hw_mode *mode;
+       struct ieee80211_channel *chan;
+       int ret = 0;
+
+       if (local->sta_scanning) {
+               chan = local->scan_channel;
+               mode = local->scan_hw_mode;
+       } else {
+               chan = local->oper_channel;
+               mode = local->oper_hw_mode;
+       }
+
+       local->hw.conf.channel = chan->chan;
+       local->hw.conf.channel_val = chan->val;
+       local->hw.conf.power_level = chan->power_level;
+       local->hw.conf.freq = chan->freq;
+       local->hw.conf.phymode = mode->mode;
+       local->hw.conf.antenna_max = chan->antenna_max;
+       local->hw.conf.chan = chan;
+       local->hw.conf.mode = mode;
+
+#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
+       printk(KERN_DEBUG "HW CONFIG: channel=%d freq=%d "
+              "phymode=%d\n", local->hw.conf.channel, local->hw.conf.freq,
+              local->hw.conf.phymode);
+#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
+
+       if (local->ops->config)
+               ret = local->ops->config(local_to_hw(local), &local->hw.conf);
+
+       return ret;
+}
+
+
+static int ieee80211_change_mtu(struct net_device *dev, int new_mtu)
+{
+       /* FIX: what would be proper limits for MTU?
+        * This interface uses 802.3 frames. */
+       if (new_mtu < 256 || new_mtu > IEEE80211_MAX_DATA_LEN - 24 - 6) {
+               printk(KERN_WARNING "%s: invalid MTU %d\n",
+                      dev->name, new_mtu);
+               return -EINVAL;
+       }
+
+#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
+       printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
+#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
+       dev->mtu = new_mtu;
+       return 0;
+}
+
+
+static int ieee80211_change_mtu_apdev(struct net_device *dev, int new_mtu)
+{
+       /* FIX: what would be proper limits for MTU?
+        * This interface uses 802.11 frames. */
+       if (new_mtu < 256 || new_mtu > IEEE80211_MAX_DATA_LEN) {
+               printk(KERN_WARNING "%s: invalid MTU %d\n",
+                      dev->name, new_mtu);
+               return -EINVAL;
+       }
+
+#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
+       printk(KERN_DEBUG "%s: setting MTU %d\n", dev->name, new_mtu);
+#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
+       dev->mtu = new_mtu;
+       return 0;
+}
+
+enum netif_tx_lock_class {
+       TX_LOCK_NORMAL,
+       TX_LOCK_MASTER,
+};
+
+static inline void netif_tx_lock_nested(struct net_device *dev, int subclass)
+{
+       spin_lock_nested(&dev->_xmit_lock, subclass);
+       dev->xmit_lock_owner = smp_processor_id();
+}
+
+static void ieee80211_set_multicast_list(struct net_device *dev)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+       unsigned short flags;
+
+       netif_tx_lock_nested(local->mdev, TX_LOCK_MASTER);
+       if (((dev->flags & IFF_ALLMULTI) != 0) ^ (sdata->allmulti != 0)) {
+               if (sdata->allmulti) {
+                       sdata->allmulti = 0;
+                       local->iff_allmultis--;
+               } else {
+                       sdata->allmulti = 1;
+                       local->iff_allmultis++;
+               }
+       }
+       if (((dev->flags & IFF_PROMISC) != 0) ^ (sdata->promisc != 0)) {
+               if (sdata->promisc) {
+                       sdata->promisc = 0;
+                       local->iff_promiscs--;
+               } else {
+                       sdata->promisc = 1;
+                       local->iff_promiscs++;
+               }
+       }
+       if (dev->mc_count != sdata->mc_count) {
+               local->mc_count = local->mc_count - sdata->mc_count +
+                                 dev->mc_count;
+               sdata->mc_count = dev->mc_count;
+       }
+       if (local->ops->set_multicast_list) {
+               flags = local->mdev->flags;
+               if (local->iff_allmultis)
+                       flags |= IFF_ALLMULTI;
+               if (local->iff_promiscs)
+                       flags |= IFF_PROMISC;
+               read_lock(&local->sub_if_lock);
+               local->ops->set_multicast_list(local_to_hw(local), flags,
+                                             local->mc_count);
+               read_unlock(&local->sub_if_lock);
+       }
+       netif_tx_unlock(local->mdev);
+}
+
+struct dev_mc_list *ieee80211_get_mc_list_item(struct ieee80211_hw *hw,
+                                              struct dev_mc_list *prev,
+                                              void **ptr)
+{
+       struct ieee80211_local *local = hw_to_local(hw);
+       struct ieee80211_sub_if_data *sdata = *ptr;
+       struct dev_mc_list *mc;
+
+       if (!prev) {
+               WARN_ON(sdata);
+               sdata = NULL;
+       }
+       if (!prev || !prev->next) {
+               if (sdata)
+                       sdata = list_entry(sdata->list.next,
+                                          struct ieee80211_sub_if_data, list);
+               else
+                       sdata = list_entry(local->sub_if_list.next,
+                                          struct ieee80211_sub_if_data, list);
+               if (&sdata->list != &local->sub_if_list)
+                       mc = sdata->dev->mc_list;
+               else
+                       mc = NULL;
+       } else
+               mc = prev->next;
+
+       *ptr = sdata;
+       return mc;
+}
+EXPORT_SYMBOL(ieee80211_get_mc_list_item);
+
+static struct net_device_stats *ieee80211_get_stats(struct net_device *dev)
+{
+       struct ieee80211_sub_if_data *sdata;
+       sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+       return &(sdata->stats);
+}
+
+static void ieee80211_if_shutdown(struct net_device *dev)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+
+       ASSERT_RTNL();
+       switch (sdata->type) {
+       case IEEE80211_IF_TYPE_STA:
+       case IEEE80211_IF_TYPE_IBSS:
+               sdata->u.sta.state = IEEE80211_DISABLED;
+               del_timer_sync(&sdata->u.sta.timer);
+               skb_queue_purge(&sdata->u.sta.skb_queue);
+               if (!local->ops->hw_scan &&
+                   local->scan_dev == sdata->dev) {
+                       local->sta_scanning = 0;
+                       cancel_delayed_work(&local->scan_work);
+               }
+               flush_workqueue(local->hw.workqueue);
+               break;
+       }
+}
+
+static inline int identical_mac_addr_allowed(int type1, int type2)
+{
+       return (type1 == IEEE80211_IF_TYPE_MNTR ||
+               type2 == IEEE80211_IF_TYPE_MNTR ||
+               (type1 == IEEE80211_IF_TYPE_AP &&
+                type2 == IEEE80211_IF_TYPE_WDS) ||
+               (type1 == IEEE80211_IF_TYPE_WDS &&
+                (type2 == IEEE80211_IF_TYPE_WDS ||
+                 type2 == IEEE80211_IF_TYPE_AP)) ||
+               (type1 == IEEE80211_IF_TYPE_AP &&
+                type2 == IEEE80211_IF_TYPE_VLAN) ||
+               (type1 == IEEE80211_IF_TYPE_VLAN &&
+                (type2 == IEEE80211_IF_TYPE_AP ||
+                 type2 == IEEE80211_IF_TYPE_VLAN)));
+}
+
+static int ieee80211_master_open(struct net_device *dev)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_sub_if_data *sdata;
+       int res = -EOPNOTSUPP;
+
+       read_lock(&local->sub_if_lock);
+       list_for_each_entry(sdata, &local->sub_if_list, list) {
+               if (sdata->dev != dev && netif_running(sdata->dev)) {
+                       res = 0;
+                       break;
+               }
+       }
+       read_unlock(&local->sub_if_lock);
+       return res;
+}
+
+static int ieee80211_master_stop(struct net_device *dev)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_sub_if_data *sdata;
+
+       read_lock(&local->sub_if_lock);
+       list_for_each_entry(sdata, &local->sub_if_list, list)
+               if (sdata->dev != dev && netif_running(sdata->dev))
+                       dev_close(sdata->dev);
+       read_unlock(&local->sub_if_lock);
+
+       return 0;
+}
+
+static int ieee80211_mgmt_open(struct net_device *dev)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+
+       if (!netif_running(local->mdev))
+               return -EOPNOTSUPP;
+       return 0;
+}
+
+static int ieee80211_mgmt_stop(struct net_device *dev)
+{
+       return 0;
+}
+
+/* Check if running monitor interfaces should go to a "soft monitor" mode
+ * and switch them if necessary. */
+static inline void ieee80211_start_soft_monitor(struct ieee80211_local *local)
+{
+       struct ieee80211_if_init_conf conf;
+
+       if (local->open_count && local->open_count == local->monitors &&
+           !(local->hw.flags & IEEE80211_HW_MONITOR_DURING_OPER) &&
+           local->ops->remove_interface) {
+               conf.if_id = -1;
+               conf.type = IEEE80211_IF_TYPE_MNTR;
+               conf.mac_addr = NULL;
+               local->ops->remove_interface(local_to_hw(local), &conf);
+       }
+}
+
+/* Check if running monitor interfaces should go to a "hard monitor" mode
+ * and switch them if necessary. */
+static void ieee80211_start_hard_monitor(struct ieee80211_local *local)
+{
+       struct ieee80211_if_init_conf conf;
+
+       if (local->open_count && local->open_count == local->monitors &&
+           !(local->hw.flags & IEEE80211_HW_MONITOR_DURING_OPER) &&
+           local->ops->add_interface) {
+               conf.if_id = -1;
+               conf.type = IEEE80211_IF_TYPE_MNTR;
+               conf.mac_addr = NULL;
+               local->ops->add_interface(local_to_hw(local), &conf);
+       }
+}
+
+static int ieee80211_open(struct net_device *dev)
+{
+       struct ieee80211_sub_if_data *sdata, *nsdata;
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_if_init_conf conf;
+       int res;
+
+       sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+       read_lock(&local->sub_if_lock);
+       list_for_each_entry(nsdata, &local->sub_if_list, list) {
+               struct net_device *ndev = nsdata->dev;
+
+               if (ndev != dev && ndev != local->mdev && netif_running(ndev) &&
+                   compare_ether_addr(dev->dev_addr, ndev->dev_addr) == 0 &&
+                   !identical_mac_addr_allowed(sdata->type, nsdata->type)) {
+                       read_unlock(&local->sub_if_lock);
+                       return -ENOTUNIQ;
+               }
+       }
+       read_unlock(&local->sub_if_lock);
+
+       if (sdata->type == IEEE80211_IF_TYPE_WDS &&
+           is_zero_ether_addr(sdata->u.wds.remote_addr))
+               return -ENOLINK;
+
+       if (sdata->type == IEEE80211_IF_TYPE_MNTR && local->open_count &&
+           !(local->hw.flags & IEEE80211_HW_MONITOR_DURING_OPER)) {
+               /* run the interface in a "soft monitor" mode */
+               local->monitors++;
+               local->open_count++;
+               local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
+               return 0;
+       }
+       ieee80211_start_soft_monitor(local);
+
+       if (local->ops->add_interface) {
+               conf.if_id = dev->ifindex;
+               conf.type = sdata->type;
+               conf.mac_addr = dev->dev_addr;
+               res = local->ops->add_interface(local_to_hw(local), &conf);
+               if (res) {
+                       if (sdata->type == IEEE80211_IF_TYPE_MNTR)
+                               ieee80211_start_hard_monitor(local);
+                       return res;
+               }
+       } else {
+               if (sdata->type != IEEE80211_IF_TYPE_STA)
+                       return -EOPNOTSUPP;
+               if (local->open_count > 0)
+                       return -ENOBUFS;
+       }
+
+       if (local->open_count == 0) {
+               res = 0;
+               tasklet_enable(&local->tx_pending_tasklet);
+               tasklet_enable(&local->tasklet);
+               if (local->ops->open)
+                       res = local->ops->open(local_to_hw(local));
+               if (res == 0) {
+                       res = dev_open(local->mdev);
+                       if (res) {
+                               if (local->ops->stop)
+                                       local->ops->stop(local_to_hw(local));
+                       } else {
+                               res = ieee80211_hw_config(local);
+                               if (res && local->ops->stop)
+                                       local->ops->stop(local_to_hw(local));
+                               else if (!res && local->apdev)
+                                       dev_open(local->apdev);
+                       }
+               }
+               if (res) {
+                       if (local->ops->remove_interface)
+                               local->ops->remove_interface(local_to_hw(local),
+                                                           &conf);
+                       return res;
+               }
+       }
+       local->open_count++;
+
+       if (sdata->type == IEEE80211_IF_TYPE_MNTR) {
+               local->monitors++;
+               local->hw.conf.flags |= IEEE80211_CONF_RADIOTAP;
+       } else
+               ieee80211_if_config(dev);
+
+       if (sdata->type == IEEE80211_IF_TYPE_STA &&
+           !local->user_space_mlme)
+               netif_carrier_off(dev);
+
+       netif_start_queue(dev);
+       return 0;
+}
+
+
+static int ieee80211_stop(struct net_device *dev)
+{
+       struct ieee80211_sub_if_data *sdata;
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+
+       sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+
+       if (sdata->type == IEEE80211_IF_TYPE_MNTR &&
+           local->open_count > 1 &&
+           !(local->hw.flags & IEEE80211_HW_MONITOR_DURING_OPER)) {
+               /* remove "soft monitor" interface */
+               local->open_count--;
+               local->monitors--;
+               if (!local->monitors)
+                       local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
+               return 0;
+       }
+
+       netif_stop_queue(dev);
+       ieee80211_if_shutdown(dev);
+
+       if (sdata->type == IEEE80211_IF_TYPE_MNTR) {
+               local->monitors--;
+               if (!local->monitors)
+                       local->hw.conf.flags &= ~IEEE80211_CONF_RADIOTAP;
+       }
+
+       local->open_count--;
+       if (local->open_count == 0) {
+               if (netif_running(local->mdev))
+                       dev_close(local->mdev);
+               if (local->apdev)
+                       dev_close(local->apdev);
+               if (local->ops->stop)
+                       local->ops->stop(local_to_hw(local));
+               tasklet_disable(&local->tx_pending_tasklet);
+               tasklet_disable(&local->tasklet);
+       }
+       if (local->ops->remove_interface) {
+               struct ieee80211_if_init_conf conf;
+
+               conf.if_id = dev->ifindex;
+               conf.type = sdata->type;
+               conf.mac_addr = dev->dev_addr;
+               local->ops->remove_interface(local_to_hw(local), &conf);
+       }
+
+       ieee80211_start_hard_monitor(local);
+
+       return 0;
+}
+
+
+static int header_parse_80211(struct sk_buff *skb, unsigned char *haddr)
+{
+       memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); /* addr2 */
+       return ETH_ALEN;
+}
+
+static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
+{
+       return compare_ether_addr(raddr, addr) == 0 ||
+              is_broadcast_ether_addr(raddr);
+}
+
+
+static ieee80211_txrx_result
+ieee80211_rx_h_data(struct ieee80211_txrx_data *rx)
+{
+       struct net_device *dev = rx->dev;
+       struct ieee80211_local *local = rx->local;
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
+       u16 fc, hdrlen, ethertype;
+       u8 *payload;
+       u8 dst[ETH_ALEN];
+       u8 src[ETH_ALEN];
+       struct sk_buff *skb = rx->skb, *skb2;
+       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+
+       fc = rx->fc;
+       if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA))
+               return TXRX_CONTINUE;
+
+       if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
+               return TXRX_DROP;
+
+       hdrlen = ieee80211_get_hdrlen(fc);
+
+       /* convert IEEE 802.11 header + possible LLC headers into Ethernet
+        * header
+        * IEEE 802.11 address fields:
+        * ToDS FromDS Addr1 Addr2 Addr3 Addr4
+        *   0     0   DA    SA    BSSID n/a
+        *   0     1   DA    BSSID SA    n/a
+        *   1     0   BSSID SA    DA    n/a
+        *   1     1   RA    TA    DA    SA
+        */
+
+       switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
+       case IEEE80211_FCTL_TODS:
+               /* BSSID SA DA */
+               memcpy(dst, hdr->addr3, ETH_ALEN);
+               memcpy(src, hdr->addr2, ETH_ALEN);
+
+               if (unlikely(sdata->type != IEEE80211_IF_TYPE_AP &&
+                            sdata->type != IEEE80211_IF_TYPE_VLAN)) {
+                       printk(KERN_DEBUG "%s: dropped ToDS frame (BSSID="
+                              MAC_FMT " SA=" MAC_FMT " DA=" MAC_FMT ")\n",
+                              dev->name, MAC_ARG(hdr->addr1),
+                              MAC_ARG(hdr->addr2), MAC_ARG(hdr->addr3));
+                       return TXRX_DROP;
+               }
+               break;
+       case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
+               /* RA TA DA SA */
+               memcpy(dst, hdr->addr3, ETH_ALEN);
+               memcpy(src, hdr->addr4, ETH_ALEN);
+
+               if (unlikely(sdata->type != IEEE80211_IF_TYPE_WDS)) {
+                       printk(KERN_DEBUG "%s: dropped FromDS&ToDS frame (RA="
+                              MAC_FMT " TA=" MAC_FMT " DA=" MAC_FMT " SA="
+                              MAC_FMT ")\n",
+                              rx->dev->name, MAC_ARG(hdr->addr1),
+                              MAC_ARG(hdr->addr2), MAC_ARG(hdr->addr3),
+                              MAC_ARG(hdr->addr4));
+                       return TXRX_DROP;
+               }
+               break;
+       case IEEE80211_FCTL_FROMDS:
+               /* DA BSSID SA */
+               memcpy(dst, hdr->addr1, ETH_ALEN);
+               memcpy(src, hdr->addr3, ETH_ALEN);
+
+               if (sdata->type != IEEE80211_IF_TYPE_STA) {
+                       return TXRX_DROP;
+               }
+               break;
+       case 0:
+               /* DA SA BSSID */
+               memcpy(dst, hdr->addr1, ETH_ALEN);
+               memcpy(src, hdr->addr2, ETH_ALEN);
+
+               if (sdata->type != IEEE80211_IF_TYPE_IBSS) {
+                       if (net_ratelimit()) {
+                               printk(KERN_DEBUG "%s: dropped IBSS frame (DA="
+                                      MAC_FMT " SA=" MAC_FMT " BSSID=" MAC_FMT
+                                      ")\n",
+                                      dev->name, MAC_ARG(hdr->addr1),
+                                      MAC_ARG(hdr->addr2),
+                                      MAC_ARG(hdr->addr3));
+                       }
+                       return TXRX_DROP;
+               }
+               break;
+       }
+
+       payload = skb->data + hdrlen;
+
+       if (unlikely(skb->len - hdrlen < 8)) {
+               if (net_ratelimit()) {
+                       printk(KERN_DEBUG "%s: RX too short data frame "
+                              "payload\n", dev->name);
+               }
+               return TXRX_DROP;
+       }
+
+       ethertype = (payload[6] << 8) | payload[7];
+
+       if (likely((compare_ether_addr(payload, rfc1042_header) == 0 &&
+                   ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
+                  compare_ether_addr(payload, bridge_tunnel_header) == 0)) {
+               /* remove RFC1042 or Bridge-Tunnel encapsulation and
+                * replace EtherType */
+               skb_pull(skb, hdrlen + 6);
+               memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
+               memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
+       } else {
+               struct ethhdr *ehdr;
+               __be16 len;
+               skb_pull(skb, hdrlen);
+               len = htons(skb->len);
+               ehdr = (struct ethhdr *) skb_push(skb, sizeof(struct ethhdr));
+               memcpy(ehdr->h_dest, dst, ETH_ALEN);
+               memcpy(ehdr->h_source, src, ETH_ALEN);
+               ehdr->h_proto = len;
+       }
+       skb->dev = dev;
+
+       skb2 = NULL;
+
+       sdata->stats.rx_packets++;
+       sdata->stats.rx_bytes += skb->len;
+
+       if (local->bridge_packets && (sdata->type == IEEE80211_IF_TYPE_AP
+           || sdata->type == IEEE80211_IF_TYPE_VLAN) && rx->u.rx.ra_match) {
+               if (is_multicast_ether_addr(skb->data)) {
+                       /* send multicast frames both to higher layers in
+                        * local net stack and back to the wireless media */
+                       skb2 = skb_copy(skb, GFP_ATOMIC);
+                       if (!skb2)
+                               printk(KERN_DEBUG "%s: failed to clone "
+                                      "multicast frame\n", dev->name);
+               } else {
+                       struct sta_info *dsta;
+                       dsta = sta_info_get(local, skb->data);
+                       if (dsta && !dsta->dev) {
+                               printk(KERN_DEBUG "Station with null dev "
+                                      "structure!\n");
+                       } else if (dsta && dsta->dev == dev) {
+                               /* Destination station is associated to this
+                                * AP, so send the frame directly to it and
+                                * do not pass the frame to local net stack.
+                                */
+                               skb2 = skb;
+                               skb = NULL;
+                       }
+                       if (dsta)
+                               sta_info_put(dsta);
+               }
+       }
+
+       if (skb) {
+               /* deliver to local stack */
+               skb->protocol = eth_type_trans(skb, dev);
+               memset(skb->cb, 0, sizeof(skb->cb));
+               netif_rx(skb);
+       }
+
+       if (skb2) {
+               /* send to wireless media */
+               skb2->protocol = __constant_htons(ETH_P_802_3);
+               skb_set_network_header(skb2, 0);
+               skb_set_mac_header(skb2, 0);
+               dev_queue_xmit(skb2);
+       }
+
+       return TXRX_QUEUED;
+}
+
+
+static struct ieee80211_rate *
+ieee80211_get_rate(struct ieee80211_local *local, int phymode, int hw_rate)
+{
+       struct ieee80211_hw_mode *mode;
+       int r;
+
+       list_for_each_entry(mode, &local->modes_list, list) {
+               if (mode->mode != phymode)
+                       continue;
+               for (r = 0; r < mode->num_rates; r++) {
+                       struct ieee80211_rate *rate = &mode->rates[r];
+                       if (rate->val == hw_rate ||
+                           (rate->flags & IEEE80211_RATE_PREAMBLE2 &&
+                            rate->val2 == hw_rate))
+                               return rate;
+               }
+       }
+
+       return NULL;
+}
+
+static void
+ieee80211_fill_frame_info(struct ieee80211_local *local,
+                         struct ieee80211_frame_info *fi,
+                         struct ieee80211_rx_status *status)
+{
+       if (status) {
+               struct timespec ts;
+               struct ieee80211_rate *rate;
+
+               jiffies_to_timespec(jiffies, &ts);
+               fi->hosttime = cpu_to_be64((u64) ts.tv_sec * 1000000 +
+                                          ts.tv_nsec / 1000);
+               fi->mactime = cpu_to_be64(status->mactime);
+               switch (status->phymode) {
+               case MODE_IEEE80211A:
+                       fi->phytype = htonl(ieee80211_phytype_ofdm_dot11_a);
+                       break;
+               case MODE_IEEE80211B:
+                       fi->phytype = htonl(ieee80211_phytype_dsss_dot11_b);
+                       break;
+               case MODE_IEEE80211G:
+                       fi->phytype = htonl(ieee80211_phytype_pbcc_dot11_g);
+                       break;
+               case MODE_ATHEROS_TURBO:
+                       fi->phytype =
+                               htonl(ieee80211_phytype_dsss_dot11_turbo);
+                       break;
+               default:
+                       fi->phytype = htonl(0xAAAAAAAA);
+                       break;
+               }
+               fi->channel = htonl(status->channel);
+               rate = ieee80211_get_rate(local, status->phymode,
+                                         status->rate);
+               if (rate) {
+                       fi->datarate = htonl(rate->rate);
+                       if (rate->flags & IEEE80211_RATE_PREAMBLE2) {
+                               if (status->rate == rate->val)
+                                       fi->preamble = htonl(2); /* long */
+                               else if (status->rate == rate->val2)
+                                       fi->preamble = htonl(1); /* short */
+                       } else
+                               fi->preamble = htonl(0);
+               } else {
+                       fi->datarate = htonl(0);
+                       fi->preamble = htonl(0);
+               }
+
+               fi->antenna = htonl(status->antenna);
+               fi->priority = htonl(0xffffffff); /* no clue */
+               fi->ssi_type = htonl(ieee80211_ssi_raw);
+               fi->ssi_signal = htonl(status->ssi);
+               fi->ssi_noise = 0x00000000;
+               fi->encoding = 0;
+       } else {
+               /* clear everything because we really don't know.
+                * the msg_type field isn't present on monitor frames
+                * so we don't know whether it will be present or not,
+                * but it's ok to not clear it since it'll be assigned
+                * anyway */
+               memset(fi, 0, sizeof(*fi) - sizeof(fi->msg_type));
+
+               fi->ssi_type = htonl(ieee80211_ssi_none);
+       }
+       fi->version = htonl(IEEE80211_FI_VERSION);
+       fi->length = cpu_to_be32(sizeof(*fi) - sizeof(fi->msg_type));
+}
+
+/* this routine is actually not just for this, but also
+ * for pushing fake 'management' frames into userspace.
+ * it shall be replaced by a netlink-based system. */
+void
+ieee80211_rx_mgmt(struct ieee80211_local *local, struct sk_buff *skb,
+                 struct ieee80211_rx_status *status, u32 msg_type)
+{
+       struct ieee80211_frame_info *fi;
+       const size_t hlen = sizeof(struct ieee80211_frame_info);
+       struct ieee80211_sub_if_data *sdata;
+
+       skb->dev = local->apdev;
+
+       sdata = IEEE80211_DEV_TO_SUB_IF(local->apdev);
+
+       if (skb_headroom(skb) < hlen) {
+               I802_DEBUG_INC(local->rx_expand_skb_head);
+               if (pskb_expand_head(skb, hlen, 0, GFP_ATOMIC)) {
+                       dev_kfree_skb(skb);
+                       return;
+               }
+       }
+
+       fi = (struct ieee80211_frame_info *) skb_push(skb, hlen);
+
+       ieee80211_fill_frame_info(local, fi, status);
+       fi->msg_type = htonl(msg_type);
+
+       sdata->stats.rx_packets++;
+       sdata->stats.rx_bytes += skb->len;
+
+       skb_set_mac_header(skb, 0);
+       skb->ip_summed = CHECKSUM_UNNECESSARY;
+       skb->pkt_type = PACKET_OTHERHOST;
+       skb->protocol = htons(ETH_P_802_2);
+       memset(skb->cb, 0, sizeof(skb->cb));
+       netif_rx(skb);
+}
+
+static void
+ieee80211_rx_monitor(struct net_device *dev, struct sk_buff *skb,
+                    struct ieee80211_rx_status *status)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_sub_if_data *sdata;
+       struct ieee80211_rate *rate;
+       struct ieee80211_rtap_hdr {
+               struct ieee80211_radiotap_header hdr;
+               u8 flags;
+               u8 rate;
+               __le16 chan_freq;
+               __le16 chan_flags;
+               u8 antsignal;
+       } __attribute__ ((packed)) *rthdr;
+
+       skb->dev = dev;
+
+       sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+
+       if (status->flag & RX_FLAG_RADIOTAP)
+               goto out;
+
+       if (skb_headroom(skb) < sizeof(*rthdr)) {
+               I802_DEBUG_INC(local->rx_expand_skb_head);
+               if (pskb_expand_head(skb, sizeof(*rthdr), 0, GFP_ATOMIC)) {
+                       dev_kfree_skb(skb);
+                       return;
+               }
+       }
+
+       rthdr = (struct ieee80211_rtap_hdr *) skb_push(skb, sizeof(*rthdr));
+       memset(rthdr, 0, sizeof(*rthdr));
+       rthdr->hdr.it_len = cpu_to_le16(sizeof(*rthdr));
+       rthdr->hdr.it_present =
+               cpu_to_le32((1 << IEEE80211_RADIOTAP_FLAGS) |
+                           (1 << IEEE80211_RADIOTAP_RATE) |
+                           (1 << IEEE80211_RADIOTAP_CHANNEL) |
+                           (1 << IEEE80211_RADIOTAP_DB_ANTSIGNAL));
+       rthdr->flags = local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS ?
+                      IEEE80211_RADIOTAP_F_FCS : 0;
+       rate = ieee80211_get_rate(local, status->phymode, status->rate);
+       if (rate)
+               rthdr->rate = rate->rate / 5;
+       rthdr->chan_freq = cpu_to_le16(status->freq);
+       rthdr->chan_flags =
+               status->phymode == MODE_IEEE80211A ?
+               cpu_to_le16(IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ) :
+               cpu_to_le16(IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ);
+       rthdr->antsignal = status->ssi;
+
+ out:
+       sdata->stats.rx_packets++;
+       sdata->stats.rx_bytes += skb->len;
+
+       skb_set_mac_header(skb, 0);
+       skb->ip_summed = CHECKSUM_UNNECESSARY;
+       skb->pkt_type = PACKET_OTHERHOST;
+       skb->protocol = htons(ETH_P_802_2);
+       memset(skb->cb, 0, sizeof(skb->cb));
+       netif_rx(skb);
+}
+
+int ieee80211_radar_status(struct ieee80211_hw *hw, int channel,
+                          int radar, int radar_type)
+{
+       struct sk_buff *skb;
+       struct ieee80211_radar_info *msg;
+       struct ieee80211_local *local = hw_to_local(hw);
+
+       if (!local->apdev)
+               return 0;
+
+       skb = dev_alloc_skb(sizeof(struct ieee80211_frame_info) +
+                           sizeof(struct ieee80211_radar_info));
+
+       if (!skb)
+               return -ENOMEM;
+       skb_reserve(skb, sizeof(struct ieee80211_frame_info));
+
+       msg = (struct ieee80211_radar_info *)
+               skb_put(skb, sizeof(struct ieee80211_radar_info));
+       msg->channel = channel;
+       msg->radar = radar;
+       msg->radar_type = radar_type;
+
+       ieee80211_rx_mgmt(local, skb, NULL, ieee80211_msg_radar);
+       return 0;
+}
+EXPORT_SYMBOL(ieee80211_radar_status);
+
+int ieee80211_set_aid_for_sta(struct ieee80211_hw *hw, u8 *peer_address,
+                             u16 aid)
+{
+       struct sk_buff *skb;
+       struct ieee80211_msg_set_aid_for_sta *msg;
+       struct ieee80211_local *local = hw_to_local(hw);
+
+       /* unlikely because if this event only happens for APs,
+        * which require an open ap device. */
+       if (unlikely(!local->apdev))
+               return 0;
+
+       skb = dev_alloc_skb(sizeof(struct ieee80211_frame_info) +
+                           sizeof(struct ieee80211_msg_set_aid_for_sta));
+
+       if (!skb)
+               return -ENOMEM;
+       skb_reserve(skb, sizeof(struct ieee80211_frame_info));
+
+       msg = (struct ieee80211_msg_set_aid_for_sta *)
+               skb_put(skb, sizeof(struct ieee80211_msg_set_aid_for_sta));
+       memcpy(msg->sta_address, peer_address, ETH_ALEN);
+       msg->aid = aid;
+
+       ieee80211_rx_mgmt(local, skb, NULL, ieee80211_msg_set_aid_for_sta);
+       return 0;
+}
+EXPORT_SYMBOL(ieee80211_set_aid_for_sta);
+
+static void ap_sta_ps_start(struct net_device *dev, struct sta_info *sta)
+{
+       struct ieee80211_sub_if_data *sdata;
+       sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
+
+       if (sdata->bss)
+               atomic_inc(&sdata->bss->num_sta_ps);
+       sta->flags |= WLAN_STA_PS;
+       sta->pspoll = 0;
+#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
+       printk(KERN_DEBUG "%s: STA " MAC_FMT " aid %d enters power "
+              "save mode\n", dev->name, MAC_ARG(sta->addr), sta->aid);
+#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
+}
+
+
+static int ap_sta_ps_end(struct net_device *dev, struct sta_info *sta)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct sk_buff *skb;
+       int sent = 0;
+       struct ieee80211_sub_if_data *sdata;
+       struct ieee80211_tx_packet_data *pkt_data;
+
+       sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
+       if (sdata->bss)
+               atomic_dec(&sdata->bss->num_sta_ps);
+       sta->flags &= ~(WLAN_STA_PS | WLAN_STA_TIM);
+       sta->pspoll = 0;
+       if (!skb_queue_empty(&sta->ps_tx_buf)) {
+               if (local->ops->set_tim)
+                       local->ops->set_tim(local_to_hw(local), sta->aid, 0);
+               if (sdata->bss)
+                       bss_tim_clear(local, sdata->bss, sta->aid);
+       }
+#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
+       printk(KERN_DEBUG "%s: STA " MAC_FMT " aid %d exits power "
+              "save mode\n", dev->name, MAC_ARG(sta->addr), sta->aid);
+#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
+       /* Send all buffered frames to the station */
+       while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
+               pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
+               sent++;
+               pkt_data->requeue = 1;
+               dev_queue_xmit(skb);
+       }
+       while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
+               pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
+               local->total_ps_buffered--;
+               sent++;
+#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
+               printk(KERN_DEBUG "%s: STA " MAC_FMT " aid %d send PS frame "
+                      "since STA not sleeping anymore\n", dev->name,
+                      MAC_ARG(sta->addr), sta->aid);
+#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
+               pkt_data->requeue = 1;
+               dev_queue_xmit(skb);
+       }
+
+       return sent;
+}
+
+
+static ieee80211_txrx_result
+ieee80211_rx_h_ps_poll(struct ieee80211_txrx_data *rx)
+{
+       struct sk_buff *skb;
+       int no_pending_pkts;
+
+       if (likely(!rx->sta ||
+                  (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_CTL ||
+                  (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PSPOLL ||
+                  !rx->u.rx.ra_match))
+               return TXRX_CONTINUE;
+
+       skb = skb_dequeue(&rx->sta->tx_filtered);
+       if (!skb) {
+               skb = skb_dequeue(&rx->sta->ps_tx_buf);
+               if (skb)
+                       rx->local->total_ps_buffered--;
+       }
+       no_pending_pkts = skb_queue_empty(&rx->sta->tx_filtered) &&
+               skb_queue_empty(&rx->sta->ps_tx_buf);
+
+       if (skb) {
+               struct ieee80211_hdr *hdr =
+                       (struct ieee80211_hdr *) skb->data;
+
+               /* tell TX path to send one frame even though the STA may
+                * still remain is PS mode after this frame exchange */
+               rx->sta->pspoll = 1;
+
+#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
+               printk(KERN_DEBUG "STA " MAC_FMT " aid %d: PS Poll (entries "
+                      "after %d)\n",
+                      MAC_ARG(rx->sta->addr), rx->sta->aid,
+                      skb_queue_len(&rx->sta->ps_tx_buf));
+#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
+
+               /* Use MoreData flag to indicate whether there are more
+                * buffered frames for this STA */
+               if (no_pending_pkts) {
+                       hdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
+                       rx->sta->flags &= ~WLAN_STA_TIM;
+               } else
+                       hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
+
+               dev_queue_xmit(skb);
+
+               if (no_pending_pkts) {
+                       if (rx->local->ops->set_tim)
+                               rx->local->ops->set_tim(local_to_hw(rx->local),
+                                                      rx->sta->aid, 0);
+                       if (rx->sdata->bss)
+                               bss_tim_clear(rx->local, rx->sdata->bss, rx->sta->aid);
+               }
+#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
+       } else if (!rx->u.rx.sent_ps_buffered) {
+               printk(KERN_DEBUG "%s: STA " MAC_FMT " sent PS Poll even "
+                      "though there is no buffered frames for it\n",
+                      rx->dev->name, MAC_ARG(rx->sta->addr));
+#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
+
+       }
+
+       /* Free PS Poll skb here instead of returning TXRX_DROP that would
+        * count as an dropped frame. */
+       dev_kfree_skb(rx->skb);
+
+       return TXRX_QUEUED;
+}
+
+
+static inline struct ieee80211_fragment_entry *
+ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
+                        unsigned int frag, unsigned int seq, int rx_queue,
+                        struct sk_buff **skb)
+{
+       struct ieee80211_fragment_entry *entry;
+       int idx;
+
+       idx = sdata->fragment_next;
+       entry = &sdata->fragments[sdata->fragment_next++];
+       if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
+               sdata->fragment_next = 0;
+
+       if (!skb_queue_empty(&entry->skb_list)) {
+#ifdef CONFIG_MAC80211_DEBUG
+               struct ieee80211_hdr *hdr =
+                       (struct ieee80211_hdr *) entry->skb_list.next->data;
+               printk(KERN_DEBUG "%s: RX reassembly removed oldest "
+                      "fragment entry (idx=%d age=%lu seq=%d last_frag=%d "
+                      "addr1=" MAC_FMT " addr2=" MAC_FMT "\n",
+                      sdata->dev->name, idx,
+                      jiffies - entry->first_frag_time, entry->seq,
+                      entry->last_frag, MAC_ARG(hdr->addr1),
+                      MAC_ARG(hdr->addr2));
+#endif /* CONFIG_MAC80211_DEBUG */
+               __skb_queue_purge(&entry->skb_list);
+       }
+
+       __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
+       *skb = NULL;
+       entry->first_frag_time = jiffies;
+       entry->seq = seq;
+       entry->rx_queue = rx_queue;
+       entry->last_frag = frag;
+       entry->ccmp = 0;
+       entry->extra_len = 0;
+
+       return entry;
+}
+
+
+static inline struct ieee80211_fragment_entry *
+ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
+                         u16 fc, unsigned int frag, unsigned int seq,
+                         int rx_queue, struct ieee80211_hdr *hdr)
+{
+       struct ieee80211_fragment_entry *entry;
+       int i, idx;
+
+       idx = sdata->fragment_next;
+       for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
+               struct ieee80211_hdr *f_hdr;
+               u16 f_fc;
+
+               idx--;
+               if (idx < 0)
+                       idx = IEEE80211_FRAGMENT_MAX - 1;
+
+               entry = &sdata->fragments[idx];
+               if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
+                   entry->rx_queue != rx_queue ||
+                   entry->last_frag + 1 != frag)
+                       continue;
+
+               f_hdr = (struct ieee80211_hdr *) entry->skb_list.next->data;
+               f_fc = le16_to_cpu(f_hdr->frame_control);
+
+               if ((fc & IEEE80211_FCTL_FTYPE) != (f_fc & IEEE80211_FCTL_FTYPE) ||
+                   compare_ether_addr(hdr->addr1, f_hdr->addr1) != 0 ||
+                   compare_ether_addr(hdr->addr2, f_hdr->addr2) != 0)
+                       continue;
+
+               if (entry->first_frag_time + 2 * HZ < jiffies) {
+                       __skb_queue_purge(&entry->skb_list);
+                       continue;
+               }
+               return entry;
+       }
+
+       return NULL;
+}
+
+
+static ieee80211_txrx_result
+ieee80211_rx_h_defragment(struct ieee80211_txrx_data *rx)
+{
+       struct ieee80211_hdr *hdr;
+       u16 sc;
+       unsigned int frag, seq;
+       struct ieee80211_fragment_entry *entry;
+       struct sk_buff *skb;
+
+       hdr = (struct ieee80211_hdr *) rx->skb->data;
+       sc = le16_to_cpu(hdr->seq_ctrl);
+       frag = sc & IEEE80211_SCTL_FRAG;
+
+       if (likely((!(rx->fc & IEEE80211_FCTL_MOREFRAGS) && frag == 0) ||
+                  (rx->skb)->len < 24 ||
+                  is_multicast_ether_addr(hdr->addr1))) {
+               /* not fragmented */
+               goto out;
+       }
+       I802_DEBUG_INC(rx->local->rx_handlers_fragments);
+
+       seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
+
+       if (frag == 0) {
+               /* This is the first fragment of a new frame. */
+               entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
+                                                rx->u.rx.queue, &(rx->skb));
+               if (rx->key && rx->key->alg == ALG_CCMP &&
+                   (rx->fc & IEEE80211_FCTL_PROTECTED)) {
+                       /* Store CCMP PN so that we can verify that the next
+                        * fragment has a sequential PN value. */
+                       entry->ccmp = 1;
+                       memcpy(entry->last_pn,
+                              rx->key->u.ccmp.rx_pn[rx->u.rx.queue],
+                              CCMP_PN_LEN);
+               }
+               return TXRX_QUEUED;
+       }
+
+       /* This is a fragment for a frame that should already be pending in
+        * fragment cache. Add this fragment to the end of the pending entry.
+        */
+       entry = ieee80211_reassemble_find(rx->sdata, rx->fc, frag, seq,
+                                         rx->u.rx.queue, hdr);
+       if (!entry) {
+               I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
+               return TXRX_DROP;
+       }
+
+       /* Verify that MPDUs within one MSDU have sequential PN values.
+        * (IEEE 802.11i, 8.3.3.4.5) */
+       if (entry->ccmp) {
+               int i;
+               u8 pn[CCMP_PN_LEN], *rpn;
+               if (!rx->key || rx->key->alg != ALG_CCMP)
+                       return TXRX_DROP;
+               memcpy(pn, entry->last_pn, CCMP_PN_LEN);
+               for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
+                       pn[i]++;
+                       if (pn[i])
+                               break;
+               }
+               rpn = rx->key->u.ccmp.rx_pn[rx->u.rx.queue];
+               if (memcmp(pn, rpn, CCMP_PN_LEN) != 0) {
+                       printk(KERN_DEBUG "%s: defrag: CCMP PN not sequential"
+                              " A2=" MAC_FMT " PN=%02x%02x%02x%02x%02x%02x "
+                              "(expected %02x%02x%02x%02x%02x%02x)\n",
+                              rx->dev->name, MAC_ARG(hdr->addr2),
+                              rpn[0], rpn[1], rpn[2], rpn[3], rpn[4], rpn[5],
+                              pn[0], pn[1], pn[2], pn[3], pn[4], pn[5]);
+                       return TXRX_DROP;
+               }
+               memcpy(entry->last_pn, pn, CCMP_PN_LEN);
+       }
+
+       skb_pull(rx->skb, ieee80211_get_hdrlen(rx->fc));
+       __skb_queue_tail(&entry->skb_list, rx->skb);
+       entry->last_frag = frag;
+       entry->extra_len += rx->skb->len;
+       if (rx->fc & IEEE80211_FCTL_MOREFRAGS) {
+               rx->skb = NULL;
+               return TXRX_QUEUED;
+       }
+
+       rx->skb = __skb_dequeue(&entry->skb_list);
+       if (skb_tailroom(rx->skb) < entry->extra_len) {
+               I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
+               if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
+                                             GFP_ATOMIC))) {
+                       I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
+                       __skb_queue_purge(&entry->skb_list);
+                       return TXRX_DROP;
+               }
+       }
+       while ((skb = __skb_dequeue(&entry->skb_list)))
+               memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
+
+       /* Complete frame has been reassembled - process it now */
+       rx->fragmented = 1;
+
+ out:
+       if (rx->sta)
+               rx->sta->rx_packets++;
+       if (is_multicast_ether_addr(hdr->addr1))
+               rx->local->dot11MulticastReceivedFrameCount++;
+       else
+               ieee80211_led_rx(rx->local);
+       return TXRX_CONTINUE;
+}
+
+
+static ieee80211_txrx_result
+ieee80211_rx_h_monitor(struct ieee80211_txrx_data *rx)
+{
+       if (rx->sdata->type == IEEE80211_IF_TYPE_MNTR) {
+               ieee80211_rx_monitor(rx->dev, rx->skb, rx->u.rx.status);
+               return TXRX_QUEUED;
+       }
+
+       if (rx->u.rx.status->flag & RX_FLAG_RADIOTAP)
+               skb_pull(rx->skb, ieee80211_get_radiotap_len(rx->skb));
+
+       return TXRX_CONTINUE;
+}
+
+
+static ieee80211_txrx_result
+ieee80211_rx_h_check(struct ieee80211_txrx_data *rx)
+{
+       struct ieee80211_hdr *hdr;
+       int always_sta_key;
+       hdr = (struct ieee80211_hdr *) rx->skb->data;
+
+       /* Drop duplicate 802.11 retransmissions (IEEE 802.11 Chap. 9.2.9) */
+       if (rx->sta && !is_multicast_ether_addr(hdr->addr1)) {
+               if (unlikely(rx->fc & IEEE80211_FCTL_RETRY &&
+                            rx->sta->last_seq_ctrl[rx->u.rx.queue] ==
+                            hdr->seq_ctrl)) {
+                       if (rx->u.rx.ra_match) {
+                               rx->local->dot11FrameDuplicateCount++;
+                               rx->sta->num_duplicates++;
+                       }
+                       return TXRX_DROP;
+               } else
+                       rx->sta->last_seq_ctrl[rx->u.rx.queue] = hdr->seq_ctrl;
+       }
+
+       if ((rx->local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) &&
+           rx->skb->len > FCS_LEN)
+               skb_trim(rx->skb, rx->skb->len - FCS_LEN);
+
+       if (unlikely(rx->skb->len < 16)) {
+               I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
+               return TXRX_DROP;
+       }
+
+       if (!rx->u.rx.ra_match)
+               rx->skb->pkt_type = PACKET_OTHERHOST;
+       else if (compare_ether_addr(rx->dev->dev_addr, hdr->addr1) == 0)
+               rx->skb->pkt_type = PACKET_HOST;
+       else if (is_multicast_ether_addr(hdr->addr1)) {
+               if (is_broadcast_ether_addr(hdr->addr1))
+                       rx->skb->pkt_type = PACKET_BROADCAST;
+               else
+                       rx->skb->pkt_type = PACKET_MULTICAST;
+       } else
+               rx->skb->pkt_type = PACKET_OTHERHOST;
+
+       /* Drop disallowed frame classes based on STA auth/assoc state;
+        * IEEE 802.11, Chap 5.5.
+        *
+        * 80211.o does filtering only based on association state, i.e., it
+        * drops Class 3 frames from not associated stations. hostapd sends
+        * deauth/disassoc frames when needed. In addition, hostapd is
+        * responsible for filtering on both auth and assoc states.
+        */
+       if (unlikely(((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA ||
+                     ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL &&
+                      (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)) &&
+                    rx->sdata->type != IEEE80211_IF_TYPE_IBSS &&
+                    (!rx->sta || !(rx->sta->flags & WLAN_STA_ASSOC)))) {
+               if ((!(rx->fc & IEEE80211_FCTL_FROMDS) &&
+                    !(rx->fc & IEEE80211_FCTL_TODS) &&
+                    (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)
+                   || !rx->u.rx.ra_match) {
+                       /* Drop IBSS frames and frames for other hosts
+                        * silently. */
+                       return TXRX_DROP;
+               }
+
+               if (!rx->local->apdev)
+                       return TXRX_DROP;
+
+               ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status,
+                                 ieee80211_msg_sta_not_assoc);
+               return TXRX_QUEUED;
+       }
+
+       if (rx->sdata->type == IEEE80211_IF_TYPE_STA)
+               always_sta_key = 0;
+       else
+               always_sta_key = 1;
+
+       if (rx->sta && rx->sta->key && always_sta_key) {
+               rx->key = rx->sta->key;
+       } else {
+               if (rx->sta && rx->sta->key)
+                       rx->key = rx->sta->key;
+               else
+                       rx->key = rx->sdata->default_key;
+
+               if ((rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) &&
+                   rx->fc & IEEE80211_FCTL_PROTECTED) {
+                       int keyidx = ieee80211_wep_get_keyidx(rx->skb);
+
+                       if (keyidx >= 0 && keyidx < NUM_DEFAULT_KEYS &&
+                           (!rx->sta || !rx->sta->key || keyidx > 0))
+                               rx->key = rx->sdata->keys[keyidx];
+
+                       if (!rx->key) {
+                               if (!rx->u.rx.ra_match)
+                                       return TXRX_DROP;
+                               printk(KERN_DEBUG "%s: RX WEP frame with "
+                                      "unknown keyidx %d (A1=" MAC_FMT " A2="
+                                      MAC_FMT " A3=" MAC_FMT ")\n",
+                                      rx->dev->name, keyidx,
+                                      MAC_ARG(hdr->addr1),
+                                      MAC_ARG(hdr->addr2),
+                                      MAC_ARG(hdr->addr3));
+                               if (!rx->local->apdev)
+                                       return TXRX_DROP;
+                               ieee80211_rx_mgmt(
+                                       rx->local, rx->skb, rx->u.rx.status,
+                                       ieee80211_msg_wep_frame_unknown_key);
+                               return TXRX_QUEUED;
+                       }
+               }
+       }
+
+       if (rx->fc & IEEE80211_FCTL_PROTECTED && rx->key && rx->u.rx.ra_match) {
+               rx->key->tx_rx_count++;
+               if (unlikely(rx->local->key_tx_rx_threshold &&
+                            rx->key->tx_rx_count >
+                            rx->local->key_tx_rx_threshold)) {
+                       ieee80211_key_threshold_notify(rx->dev, rx->key,
+                                                      rx->sta);
+               }
+       }
+
+       return TXRX_CONTINUE;
+}
+
+
+static ieee80211_txrx_result
+ieee80211_rx_h_sta_process(struct ieee80211_txrx_data *rx)
+{
+       struct sta_info *sta = rx->sta;
+       struct net_device *dev = rx->dev;
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
+
+       if (!sta)
+               return TXRX_CONTINUE;
+
+       /* Update last_rx only for IBSS packets which are for the current
+        * BSSID to avoid keeping the current IBSS network alive in cases where
+        * other STAs are using different BSSID. */
+       if (rx->sdata->type == IEEE80211_IF_TYPE_IBSS) {
+               u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len);
+               if (compare_ether_addr(bssid, rx->sdata->u.sta.bssid) == 0)
+                       sta->last_rx = jiffies;
+       } else
+       if (!is_multicast_ether_addr(hdr->addr1) ||
+           rx->sdata->type == IEEE80211_IF_TYPE_STA) {
+               /* Update last_rx only for unicast frames in order to prevent
+                * the Probe Request frames (the only broadcast frames from a
+                * STA in infrastructure mode) from keeping a connection alive.
+                */
+               sta->last_rx = jiffies;
+       }
+
+       if (!rx->u.rx.ra_match)
+               return TXRX_CONTINUE;
+
+       sta->rx_fragments++;
+       sta->rx_bytes += rx->skb->len;
+       sta->last_rssi = (sta->last_rssi * 15 +
+                         rx->u.rx.status->ssi) / 16;
+       sta->last_signal = (sta->last_signal * 15 +
+                           rx->u.rx.status->signal) / 16;
+       sta->last_noise = (sta->last_noise * 15 +
+                          rx->u.rx.status->noise) / 16;
+
+       if (!(rx->fc & IEEE80211_FCTL_MOREFRAGS)) {
+               /* Change STA power saving mode only in the end of a frame
+                * exchange sequence */
+               if ((sta->flags & WLAN_STA_PS) && !(rx->fc & IEEE80211_FCTL_PM))
+                       rx->u.rx.sent_ps_buffered += ap_sta_ps_end(dev, sta);
+               else if (!(sta->flags & WLAN_STA_PS) &&
+                        (rx->fc & IEEE80211_FCTL_PM))
+                       ap_sta_ps_start(dev, sta);
+       }
+
+       /* Drop data::nullfunc frames silently, since they are used only to
+        * control station power saving mode. */
+       if ((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
+           (rx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_NULLFUNC) {
+               I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
+               /* Update counter and free packet here to avoid counting this
+                * as a dropped packed. */
+               sta->rx_packets++;
+               dev_kfree_skb(rx->skb);
+               return TXRX_QUEUED;
+       }
+
+       return TXRX_CONTINUE;
+} /* ieee80211_rx_h_sta_process */
+
+
+static ieee80211_txrx_result
+ieee80211_rx_h_wep_weak_iv_detection(struct ieee80211_txrx_data *rx)
+{
+       if (!rx->sta || !(rx->fc & IEEE80211_FCTL_PROTECTED) ||
+           (rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
+           !rx->key || rx->key->alg != ALG_WEP || !rx->u.rx.ra_match)
+               return TXRX_CONTINUE;
+
+       /* Check for weak IVs, if hwaccel did not remove IV from the frame */
+       if ((rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) ||
+           rx->key->force_sw_encrypt) {
+               u8 *iv = ieee80211_wep_is_weak_iv(rx->skb, rx->key);
+               if (iv) {
+                       rx->sta->wep_weak_iv_count++;
+               }
+       }
+
+       return TXRX_CONTINUE;
+}
+
+
+static ieee80211_txrx_result
+ieee80211_rx_h_wep_decrypt(struct ieee80211_txrx_data *rx)
+{
+       /* If the device handles decryption totally, skip this test */
+       if (rx->local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP)
+               return TXRX_CONTINUE;
+
+       if ((rx->key && rx->key->alg != ALG_WEP) ||
+           !(rx->fc & IEEE80211_FCTL_PROTECTED) ||
+           ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
+            ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
+             (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)))
+               return TXRX_CONTINUE;
+
+       if (!rx->key) {
+               printk(KERN_DEBUG "%s: RX WEP frame, but no key set\n",
+                      rx->dev->name);
+               return TXRX_DROP;
+       }
+
+       if (!(rx->u.rx.status->flag & RX_FLAG_DECRYPTED) ||
+           rx->key->force_sw_encrypt) {
+               if (ieee80211_wep_decrypt(rx->local, rx->skb, rx->key)) {
+                       printk(KERN_DEBUG "%s: RX WEP frame, decrypt "
+                              "failed\n", rx->dev->name);
+                       return TXRX_DROP;
+               }
+       } else if (rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) {
+               ieee80211_wep_remove_iv(rx->local, rx->skb, rx->key);
+               /* remove ICV */
+               skb_trim(rx->skb, rx->skb->len - 4);
+       }
+
+       return TXRX_CONTINUE;
+}
+
+
+static ieee80211_txrx_result
+ieee80211_rx_h_802_1x_pae(struct ieee80211_txrx_data *rx)
+{
+       if (rx->sdata->eapol && ieee80211_is_eapol(rx->skb) &&
+           rx->sdata->type != IEEE80211_IF_TYPE_STA && rx->u.rx.ra_match) {
+               /* Pass both encrypted and unencrypted EAPOL frames to user
+                * space for processing. */
+               if (!rx->local->apdev)
+                       return TXRX_DROP;
+               ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status,
+                                 ieee80211_msg_normal);
+               return TXRX_QUEUED;
+       }
+
+       if (unlikely(rx->sdata->ieee802_1x &&
+                    (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
+                    (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC &&
+                    (!rx->sta || !(rx->sta->flags & WLAN_STA_AUTHORIZED)) &&
+                    !ieee80211_is_eapol(rx->skb))) {
+#ifdef CONFIG_MAC80211_DEBUG
+               struct ieee80211_hdr *hdr =
+                       (struct ieee80211_hdr *) rx->skb->data;
+               printk(KERN_DEBUG "%s: dropped frame from " MAC_FMT
+                      " (unauthorized port)\n", rx->dev->name,
+                      MAC_ARG(hdr->addr2));
+#endif /* CONFIG_MAC80211_DEBUG */
+               return TXRX_DROP;
+       }
+
+       return TXRX_CONTINUE;
+}
+
+
+static ieee80211_txrx_result
+ieee80211_rx_h_drop_unencrypted(struct ieee80211_txrx_data *rx)
+{
+       /*  If the device handles decryption totally, skip this test */
+       if (rx->local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP)
+               return TXRX_CONTINUE;
+
+       /* Drop unencrypted frames if key is set. */
+       if (unlikely(!(rx->fc & IEEE80211_FCTL_PROTECTED) &&
+                    (rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
+                    (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_NULLFUNC &&
+                    (rx->key || rx->sdata->drop_unencrypted) &&
+                    (rx->sdata->eapol == 0 ||
+                     !ieee80211_is_eapol(rx->skb)))) {
+               printk(KERN_DEBUG "%s: RX non-WEP frame, but expected "
+                      "encryption\n", rx->dev->name);
+               return TXRX_DROP;
+       }
+       return TXRX_CONTINUE;
+}
+
+
+static ieee80211_txrx_result
+ieee80211_rx_h_mgmt(struct ieee80211_txrx_data *rx)
+{
+       struct ieee80211_sub_if_data *sdata;
+
+       if (!rx->u.rx.ra_match)
+               return TXRX_DROP;
+
+       sdata = IEEE80211_DEV_TO_SUB_IF(rx->dev);
+       if ((sdata->type == IEEE80211_IF_TYPE_STA ||
+            sdata->type == IEEE80211_IF_TYPE_IBSS) &&
+           !rx->local->user_space_mlme) {
+               ieee80211_sta_rx_mgmt(rx->dev, rx->skb, rx->u.rx.status);
+       } else {
+               /* Management frames are sent to hostapd for processing */
+               if (!rx->local->apdev)
+                       return TXRX_DROP;
+               ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status,
+                                 ieee80211_msg_normal);
+       }
+       return TXRX_QUEUED;
+}
+
+
+static ieee80211_txrx_result
+ieee80211_rx_h_passive_scan(struct ieee80211_txrx_data *rx)
+{
+       struct ieee80211_local *local = rx->local;
+       struct sk_buff *skb = rx->skb;
+
+       if (unlikely(local->sta_scanning != 0)) {
+               ieee80211_sta_rx_scan(rx->dev, skb, rx->u.rx.status);
+               return TXRX_QUEUED;
+       }
+
+       if (unlikely(rx->u.rx.in_scan)) {
+               /* scanning finished during invoking of handlers */
+               I802_DEBUG_INC(local->rx_handlers_drop_passive_scan);
+               return TXRX_DROP;
+       }
+
+       return TXRX_CONTINUE;
+}
+
+
+static void ieee80211_rx_michael_mic_report(struct net_device *dev,
+                                           struct ieee80211_hdr *hdr,
+                                           struct sta_info *sta,
+                                           struct ieee80211_txrx_data *rx)
+{
+       int keyidx, hdrlen;
+
+       hdrlen = ieee80211_get_hdrlen_from_skb(rx->skb);
+       if (rx->skb->len >= hdrlen + 4)
+               keyidx = rx->skb->data[hdrlen + 3] >> 6;
+       else
+               keyidx = -1;
+
+       /* TODO: verify that this is not triggered by fragmented
+        * frames (hw does not verify MIC for them). */
+       printk(KERN_DEBUG "%s: TKIP hwaccel reported Michael MIC "
+              "failure from " MAC_FMT " to " MAC_FMT " keyidx=%d\n",
+              dev->name, MAC_ARG(hdr->addr2), MAC_ARG(hdr->addr1), keyidx);
+
+       if (!sta) {
+               /* Some hardware versions seem to generate incorrect
+                * Michael MIC reports; ignore them to avoid triggering
+                * countermeasures. */
+               printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
+                      "error for unknown address " MAC_FMT "\n",
+                      dev->name, MAC_ARG(hdr->addr2));
+               goto ignore;
+       }
+
+       if (!(rx->fc & IEEE80211_FCTL_PROTECTED)) {
+               printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
+                      "error for a frame with no ISWEP flag (src "
+                      MAC_FMT ")\n", dev->name, MAC_ARG(hdr->addr2));
+               goto ignore;
+       }
+
+       if ((rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) &&
+           rx->sdata->type == IEEE80211_IF_TYPE_AP) {
+               keyidx = ieee80211_wep_get_keyidx(rx->skb);
+               /* AP with Pairwise keys support should never receive Michael
+                * MIC errors for non-zero keyidx because these are reserved
+                * for group keys and only the AP is sending real multicast
+                * frames in BSS. */
+               if (keyidx) {
+                       printk(KERN_DEBUG "%s: ignored Michael MIC error for "
+                              "a frame with non-zero keyidx (%d) (src " MAC_FMT
+                              ")\n", dev->name, keyidx, MAC_ARG(hdr->addr2));
+                       goto ignore;
+               }
+       }
+
+       if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
+           ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
+            (rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)) {
+               printk(KERN_DEBUG "%s: ignored spurious Michael MIC "
+                      "error for a frame that cannot be encrypted "
+                      "(fc=0x%04x) (src " MAC_FMT ")\n",
+                      dev->name, rx->fc, MAC_ARG(hdr->addr2));
+               goto ignore;
+       }
+
+       do {
+               union iwreq_data wrqu;
+               char *buf = kmalloc(128, GFP_ATOMIC);
+               if (!buf)
+                       break;
+
+               /* TODO: needed parameters: count, key type, TSC */
+               sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
+                       "keyid=%d %scast addr=" MAC_FMT ")",
+                       keyidx, hdr->addr1[0] & 0x01 ? "broad" : "uni",
+                       MAC_ARG(hdr->addr2));
+               memset(&wrqu, 0, sizeof(wrqu));
+               wrqu.data.length = strlen(buf);
+               wireless_send_event(rx->dev, IWEVCUSTOM, &wrqu, buf);
+               kfree(buf);
+       } while (0);
+
+       /* TODO: consider verifying the MIC error report with software
+        * implementation if we get too many spurious reports from the
+        * hardware. */
+       if (!rx->local->apdev)
+               goto ignore;
+       ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status,
+                         ieee80211_msg_michael_mic_failure);
+       return;
+
+ ignore:
+       dev_kfree_skb(rx->skb);
+       rx->skb = NULL;
+}
+
+static inline ieee80211_txrx_result __ieee80211_invoke_rx_handlers(
+                               struct ieee80211_local *local,
+                               ieee80211_rx_handler *handlers,
+                               struct ieee80211_txrx_data *rx,
+                               struct sta_info *sta)
+{
+       ieee80211_rx_handler *handler;
+       ieee80211_txrx_result res = TXRX_DROP;
+
+       for (handler = handlers; *handler != NULL; handler++) {
+               res = (*handler)(rx);
+               if (res != TXRX_CONTINUE) {
+                       if (res == TXRX_DROP) {
+                               I802_DEBUG_INC(local->rx_handlers_drop);
+                               if (sta)
+                                       sta->rx_dropped++;
+                       }
+                       if (res == TXRX_QUEUED)
+                               I802_DEBUG_INC(local->rx_handlers_queued);
+                       break;
+               }
+       }
+
+       if (res == TXRX_DROP) {
+               dev_kfree_skb(rx->skb);
+       }
+       return res;
+}
+
+static inline void ieee80211_invoke_rx_handlers(struct ieee80211_local *local,
+                                               ieee80211_rx_handler *handlers,
+                                               struct ieee80211_txrx_data *rx,
+                                               struct sta_info *sta)
+{
+       if (__ieee80211_invoke_rx_handlers(local, handlers, rx, sta) ==
+           TXRX_CONTINUE)
+               dev_kfree_skb(rx->skb);
+}
+
+/*
+ * This is the receive path handler. It is called by a low level driver when an
+ * 802.11 MPDU is received from the hardware.
+ */
+void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
+                   struct ieee80211_rx_status *status)
+{
+       struct ieee80211_local *local = hw_to_local(hw);
+       struct ieee80211_sub_if_data *sdata;
+       struct sta_info *sta;
+       struct ieee80211_hdr *hdr;
+       struct ieee80211_txrx_data rx;
+       u16 type;
+       int multicast;
+       int radiotap_len = 0;
+
+       if (status->flag & RX_FLAG_RADIOTAP) {
+               radiotap_len = ieee80211_get_radiotap_len(skb);
+               skb_pull(skb, radiotap_len);
+       }
+
+       hdr = (struct ieee80211_hdr *) skb->data;
+       memset(&rx, 0, sizeof(rx));
+       rx.skb = skb;
+       rx.local = local;
+
+       rx.u.rx.status = status;
+       rx.fc = skb->len >= 2 ? le16_to_cpu(hdr->frame_control) : 0;
+       type = rx.fc & IEEE80211_FCTL_FTYPE;
+       if (type == IEEE80211_FTYPE_DATA || type == IEEE80211_FTYPE_MGMT)
+               local->dot11ReceivedFragmentCount++;
+       multicast = is_multicast_ether_addr(hdr->addr1);
+
+       if (skb->len >= 16)
+               sta = rx.sta = sta_info_get(local, hdr->addr2);
+       else
+               sta = rx.sta = NULL;
+
+       if (sta) {
+               rx.dev = sta->dev;
+               rx.sdata = IEEE80211_DEV_TO_SUB_IF(rx.dev);
+       }
+
+       if ((status->flag & RX_FLAG_MMIC_ERROR)) {
+               ieee80211_rx_michael_mic_report(local->mdev, hdr, sta, &rx);
+               goto end;
+       }
+
+       if (unlikely(local->sta_scanning))
+               rx.u.rx.in_scan = 1;
+
+       if (__ieee80211_invoke_rx_handlers(local, local->rx_pre_handlers, &rx,
+                                          sta) != TXRX_CONTINUE)
+               goto end;
+       skb = rx.skb;
+
+       skb_push(skb, radiotap_len);
+       if (sta && !sta->assoc_ap && !(sta->flags & WLAN_STA_WDS) &&
+           !local->iff_promiscs && !multicast) {
+               rx.u.rx.ra_match = 1;
+               ieee80211_invoke_rx_handlers(local, local->rx_handlers, &rx,
+                                            sta);
+       } else {
+               struct ieee80211_sub_if_data *prev = NULL;
+               struct sk_buff *skb_new;
+               u8 *bssid = ieee80211_get_bssid(hdr, skb->len - radiotap_len);
+
+               read_lock(&local->sub_if_lock);
+               list_for_each_entry(sdata, &local->sub_if_list, list) {
+                       rx.u.rx.ra_match = 1;
+                       switch (sdata->type) {
+                       case IEEE80211_IF_TYPE_STA:
+                               if (!bssid)
+                                       continue;
+                               if (!ieee80211_bssid_match(bssid,
+                                                       sdata->u.sta.bssid)) {
+                                       if (!rx.u.rx.in_scan)
+                                               continue;
+                                       rx.u.rx.ra_match = 0;
+                               } else if (!multicast &&
+                                          compare_ether_addr(sdata->dev->dev_addr,
+                                                             hdr->addr1) != 0) {
+                                       if (!sdata->promisc)
+                                               continue;
+                                       rx.u.rx.ra_match = 0;
+                               }
+                               break;
+                       case IEEE80211_IF_TYPE_IBSS:
+                               if (!bssid)
+                                       continue;
+                               if (!ieee80211_bssid_match(bssid,
+                                                       sdata->u.sta.bssid)) {
+                                       if (!rx.u.rx.in_scan)
+                                               continue;
+                                       rx.u.rx.ra_match = 0;
+                               } else if (!multicast &&
+                                          compare_ether_addr(sdata->dev->dev_addr,
+                                                             hdr->addr1) != 0) {
+                                       if (!sdata->promisc)
+                                               continue;
+                                       rx.u.rx.ra_match = 0;
+                               } else if (!sta)
+                                       sta = rx.sta =
+                                               ieee80211_ibss_add_sta(sdata->dev,
+                                                                      skb, bssid,
+                                                                      hdr->addr2);
+                               break;
+                       case IEEE80211_IF_TYPE_AP:
+                               if (!bssid) {
+                                       if (compare_ether_addr(sdata->dev->dev_addr,
+                                                              hdr->addr1) != 0)
+                                               continue;
+                               } else if (!ieee80211_bssid_match(bssid,
+                                                       sdata->dev->dev_addr)) {
+                                       if (!rx.u.rx.in_scan)
+                                               continue;
+                                       rx.u.rx.ra_match = 0;
+                               }
+                               if (sdata->dev == local->mdev &&
+                                   !rx.u.rx.in_scan)
+                                       /* do not receive anything via
+                                        * master device when not scanning */
+                                       continue;
+                               break;
+                       case IEEE80211_IF_TYPE_WDS:
+                               if (bssid ||
+                                   (rx.fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
+                                       continue;
+                               if (compare_ether_addr(sdata->u.wds.remote_addr,
+                                                      hdr->addr2) != 0)
+                                       continue;
+                               break;
+                       }
+
+                       if (prev) {
+                               skb_new = skb_copy(skb, GFP_ATOMIC);
+                               if (!skb_new) {
+                                       if (net_ratelimit())
+                                               printk(KERN_DEBUG "%s: failed to copy "
+                                                      "multicast frame for %s",
+                                                      local->mdev->name, prev->dev->name);
+                                       continue;
+                               }
+                               rx.skb = skb_new;
+                               rx.dev = prev->dev;
+                               rx.sdata = prev;
+                               ieee80211_invoke_rx_handlers(local,
+                                                            local->rx_handlers,
+                                                            &rx, sta);
+                       }
+                       prev = sdata;
+               }
+               if (prev) {
+                       rx.skb = skb;
+                       rx.dev = prev->dev;
+                       rx.sdata = prev;
+                       ieee80211_invoke_rx_handlers(local, local->rx_handlers,
+                                                    &rx, sta);
+               } else
+                       dev_kfree_skb(skb);
+               read_unlock(&local->sub_if_lock);
+       }
+
+  end:
+       if (sta)
+               sta_info_put(sta);
+}
+EXPORT_SYMBOL(__ieee80211_rx);
+
+static ieee80211_txrx_result
+ieee80211_tx_h_load_stats(struct ieee80211_txrx_data *tx)
+{
+       struct ieee80211_local *local = tx->local;
+       struct ieee80211_hw_mode *mode = tx->u.tx.mode;
+       struct sk_buff *skb = tx->skb;
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
+       u32 load = 0, hdrtime;
+
+       /* TODO: this could be part of tx_status handling, so that the number
+        * of retries would be known; TX rate should in that case be stored
+        * somewhere with the packet */
+
+       /* Estimate total channel use caused by this frame */
+
+       /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
+        * 1 usec = 1/8 * (1080 / 10) = 13.5 */
+
+       if (mode->mode == MODE_IEEE80211A ||
+           mode->mode == MODE_ATHEROS_TURBO ||
+           mode->mode == MODE_ATHEROS_TURBOG ||
+           (mode->mode == MODE_IEEE80211G &&
+            tx->u.tx.rate->flags & IEEE80211_RATE_ERP))
+               hdrtime = CHAN_UTIL_HDR_SHORT;
+       else
+               hdrtime = CHAN_UTIL_HDR_LONG;
+
+       load = hdrtime;
+       if (!is_multicast_ether_addr(hdr->addr1))
+               load += hdrtime;
+
+       if (tx->u.tx.control->flags & IEEE80211_TXCTL_USE_RTS_CTS)
+               load += 2 * hdrtime;
+       else if (tx->u.tx.control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)
+               load += hdrtime;
+
+       load += skb->len * tx->u.tx.rate->rate_inv;
+
+       if (tx->u.tx.extra_frag) {
+               int i;
+               for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
+                       load += 2 * hdrtime;
+                       load += tx->u.tx.extra_frag[i]->len *
+                               tx->u.tx.rate->rate;
+               }
+       }
+
+       /* Divide channel_use by 8 to avoid wrapping around the counter */
+       load >>= CHAN_UTIL_SHIFT;
+       local->channel_use_raw += load;
+       if (tx->sta)
+               tx->sta->channel_use_raw += load;
+       tx->sdata->channel_use_raw += load;
+
+       return TXRX_CONTINUE;
+}
+
+
+static ieee80211_txrx_result
+ieee80211_rx_h_load_stats(struct ieee80211_txrx_data *rx)
+{
+       struct ieee80211_local *local = rx->local;
+       struct sk_buff *skb = rx->skb;
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
+       u32 load = 0, hdrtime;
+       struct ieee80211_rate *rate;
+       struct ieee80211_hw_mode *mode = local->hw.conf.mode;
+       int i;
+
+       /* Estimate total channel use caused by this frame */
+
+       if (unlikely(mode->num_rates < 0))
+               return TXRX_CONTINUE;
+
+       rate = &mode->rates[0];
+       for (i = 0; i < mode->num_rates; i++) {
+               if (mode->rates[i].val == rx->u.rx.status->rate) {
+                       rate = &mode->rates[i];
+                       break;
+               }
+       }
+
+       /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
+        * 1 usec = 1/8 * (1080 / 10) = 13.5 */
+
+       if (mode->mode == MODE_IEEE80211A ||
+           mode->mode == MODE_ATHEROS_TURBO ||
+           mode->mode == MODE_ATHEROS_TURBOG ||
+           (mode->mode == MODE_IEEE80211G &&
+            rate->flags & IEEE80211_RATE_ERP))
+               hdrtime = CHAN_UTIL_HDR_SHORT;
+       else
+               hdrtime = CHAN_UTIL_HDR_LONG;
+
+       load = hdrtime;
+       if (!is_multicast_ether_addr(hdr->addr1))
+               load += hdrtime;
+
+       load += skb->len * rate->rate_inv;
+
+       /* Divide channel_use by 8 to avoid wrapping around the counter */
+       load >>= CHAN_UTIL_SHIFT;
+       local->channel_use_raw += load;
+       if (rx->sta)
+               rx->sta->channel_use_raw += load;
+       rx->u.rx.load = load;
+
+       return TXRX_CONTINUE;
+}
+
+static ieee80211_txrx_result
+ieee80211_rx_h_if_stats(struct ieee80211_txrx_data *rx)
+{
+       rx->sdata->channel_use_raw += rx->u.rx.load;
+       return TXRX_CONTINUE;
+}
+
+static void ieee80211_stat_refresh(unsigned long data)
+{
+       struct ieee80211_local *local = (struct ieee80211_local *) data;
+       struct sta_info *sta;
+       struct ieee80211_sub_if_data *sdata;
+
+       if (!local->stat_time)
+               return;
+
+       /* go through all stations */
+       spin_lock_bh(&local->sta_lock);
+       list_for_each_entry(sta, &local->sta_list, list) {
+               sta->channel_use = (sta->channel_use_raw / local->stat_time) /
+                       CHAN_UTIL_PER_10MS;
+               sta->channel_use_raw = 0;
+       }
+       spin_unlock_bh(&local->sta_lock);
+
+       /* go through all subinterfaces */
+       read_lock(&local->sub_if_lock);
+       list_for_each_entry(sdata, &local->sub_if_list, list) {
+               sdata->channel_use = (sdata->channel_use_raw /
+                                     local->stat_time) / CHAN_UTIL_PER_10MS;
+               sdata->channel_use_raw = 0;
+       }
+       read_unlock(&local->sub_if_lock);
+
+       /* hardware interface */
+       local->channel_use = (local->channel_use_raw /
+                             local->stat_time) / CHAN_UTIL_PER_10MS;
+       local->channel_use_raw = 0;
+
+       local->stat_timer.expires = jiffies + HZ * local->stat_time / 100;
+       add_timer(&local->stat_timer);
+}
+
+
+/* This is a version of the rx handler that can be called from hard irq
+ * context. Post the skb on the queue and schedule the tasklet */
+void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb,
+                         struct ieee80211_rx_status *status)
+{
+       struct ieee80211_local *local = hw_to_local(hw);
+
+       BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
+
+       skb->dev = local->mdev;
+       /* copy status into skb->cb for use by tasklet */
+       memcpy(skb->cb, status, sizeof(*status));
+       skb->pkt_type = IEEE80211_RX_MSG;
+       skb_queue_tail(&local->skb_queue, skb);
+       tasklet_schedule(&local->tasklet);
+}
+EXPORT_SYMBOL(ieee80211_rx_irqsafe);
+
+void ieee80211_tx_status_irqsafe(struct ieee80211_hw *hw,
+                                struct sk_buff *skb,
+                                struct ieee80211_tx_status *status)
+{
+       struct ieee80211_local *local = hw_to_local(hw);
+       struct ieee80211_tx_status *saved;
+       int tmp;
+
+       skb->dev = local->mdev;
+       saved = kmalloc(sizeof(struct ieee80211_tx_status), GFP_ATOMIC);
+       if (unlikely(!saved)) {
+               if (net_ratelimit())
+                       printk(KERN_WARNING "%s: Not enough memory, "
+                              "dropping tx status", skb->dev->name);
+               /* should be dev_kfree_skb_irq, but due to this function being
+                * named _irqsafe instead of just _irq we can't be sure that
+                * people won't call it from non-irq contexts */
+               dev_kfree_skb_any(skb);
+               return;
+       }
+       memcpy(saved, status, sizeof(struct ieee80211_tx_status));
+       /* copy pointer to saved status into skb->cb for use by tasklet */
+       memcpy(skb->cb, &saved, sizeof(saved));
+
+       skb->pkt_type = IEEE80211_TX_STATUS_MSG;
+       skb_queue_tail(status->control.flags & IEEE80211_TXCTL_REQ_TX_STATUS ?
+                      &local->skb_queue : &local->skb_queue_unreliable, skb);
+       tmp = skb_queue_len(&local->skb_queue) +
+               skb_queue_len(&local->skb_queue_unreliable);
+       while (tmp > IEEE80211_IRQSAFE_QUEUE_LIMIT &&
+              (skb = skb_dequeue(&local->skb_queue_unreliable))) {
+               memcpy(&saved, skb->cb, sizeof(saved));
+               kfree(saved);
+               dev_kfree_skb_irq(skb);
+               tmp--;
+               I802_DEBUG_INC(local->tx_status_drop);
+       }
+       tasklet_schedule(&local->tasklet);
+}
+EXPORT_SYMBOL(ieee80211_tx_status_irqsafe);
+
+static void ieee80211_tasklet_handler(unsigned long data)
+{
+       struct ieee80211_local *local = (struct ieee80211_local *) data;
+       struct sk_buff *skb;
+       struct ieee80211_rx_status rx_status;
+       struct ieee80211_tx_status *tx_status;
+
+       while ((skb = skb_dequeue(&local->skb_queue)) ||
+              (skb = skb_dequeue(&local->skb_queue_unreliable))) {
+               switch (skb->pkt_type) {
+               case IEEE80211_RX_MSG:
+                       /* status is in skb->cb */
+                       memcpy(&rx_status, skb->cb, sizeof(rx_status));
+                       /* Clear skb->type in order to not confuse kernel
+                        * netstack. */
+                       skb->pkt_type = 0;
+                       __ieee80211_rx(local_to_hw(local), skb, &rx_status);
+                       break;
+               case IEEE80211_TX_STATUS_MSG:
+                       /* get pointer to saved status out of skb->cb */
+                       memcpy(&tx_status, skb->cb, sizeof(tx_status));
+                       skb->pkt_type = 0;
+                       ieee80211_tx_status(local_to_hw(local),
+                                           skb, tx_status);
+                       kfree(tx_status);
+                       break;
+               default: /* should never get here! */
+                       printk(KERN_ERR "%s: Unknown message type (%d)\n",
+                              local->mdev->name, skb->pkt_type);
+                       dev_kfree_skb(skb);
+                       break;
+               }
+       }
+}
+
+
+/* Remove added headers (e.g., QoS control), encryption header/MIC, etc. to
+ * make a prepared TX frame (one that has been given to hw) to look like brand
+ * new IEEE 802.11 frame that is ready to go through TX processing again.
+ * Also, tx_packet_data in cb is restored from tx_control. */
+static void ieee80211_remove_tx_extra(struct ieee80211_local *local,
+                                     struct ieee80211_key *key,
+                                     struct sk_buff *skb,
+                                     struct ieee80211_tx_control *control)
+{
+       int hdrlen, iv_len, mic_len;
+       struct ieee80211_tx_packet_data *pkt_data;
+
+       pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
+       pkt_data->ifindex = control->ifindex;
+       pkt_data->mgmt_iface = (control->type == IEEE80211_IF_TYPE_MGMT);
+       pkt_data->req_tx_status = !!(control->flags & IEEE80211_TXCTL_REQ_TX_STATUS);
+       pkt_data->do_not_encrypt = !!(control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT);
+       pkt_data->requeue = !!(control->flags & IEEE80211_TXCTL_REQUEUE);
+       pkt_data->queue = control->queue;
+
+       hdrlen = ieee80211_get_hdrlen_from_skb(skb);
+
+       if (!key)
+               goto no_key;
+
+       switch (key->alg) {
+       case ALG_WEP:
+               iv_len = WEP_IV_LEN;
+               mic_len = WEP_ICV_LEN;
+               break;
+       case ALG_TKIP:
+               iv_len = TKIP_IV_LEN;
+               mic_len = TKIP_ICV_LEN;
+               break;
+       case ALG_CCMP:
+               iv_len = CCMP_HDR_LEN;
+               mic_len = CCMP_MIC_LEN;
+               break;
+       default:
+               goto no_key;
+       }
+
+       if (skb->len >= mic_len && key->force_sw_encrypt)
+               skb_trim(skb, skb->len - mic_len);
+       if (skb->len >= iv_len && skb->len > hdrlen) {
+               memmove(skb->data + iv_len, skb->data, hdrlen);
+               skb_pull(skb, iv_len);
+       }
+
+no_key:
+       {
+               struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
+               u16 fc = le16_to_cpu(hdr->frame_control);
+               if ((fc & 0x8C) == 0x88) /* QoS Control Field */ {
+                       fc &= ~IEEE80211_STYPE_QOS_DATA;
+                       hdr->frame_control = cpu_to_le16(fc);
+                       memmove(skb->data + 2, skb->data, hdrlen - 2);
+                       skb_pull(skb, 2);
+               }
+       }
+}
+
+
+void ieee80211_tx_status(struct ieee80211_hw *hw, struct sk_buff *skb,
+                        struct ieee80211_tx_status *status)
+{
+       struct sk_buff *skb2;
+       struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
+       struct ieee80211_local *local = hw_to_local(hw);
+       u16 frag, type;
+       u32 msg_type;
+
+       if (!status) {
+               printk(KERN_ERR
+                      "%s: ieee80211_tx_status called with NULL status\n",
+                      local->mdev->name);
+               dev_kfree_skb(skb);
+               return;
+       }
+
+       if (status->excessive_retries) {
+               struct sta_info *sta;
+               sta = sta_info_get(local, hdr->addr1);
+               if (sta) {
+                       if (sta->flags & WLAN_STA_PS) {
+                               /* The STA is in power save mode, so assume
+                                * that this TX packet failed because of that.
+                                */
+                               status->excessive_retries = 0;
+                               status->flags |= IEEE80211_TX_STATUS_TX_FILTERED;
+                       }
+                       sta_info_put(sta);
+               }
+       }
+
+       if (status->flags & IEEE80211_TX_STATUS_TX_FILTERED) {
+               struct sta_info *sta;
+               sta = sta_info_get(local, hdr->addr1);
+               if (sta) {
+                       sta->tx_filtered_count++;
+
+                       /* Clear the TX filter mask for this STA when sending
+                        * the next packet. If the STA went to power save mode,
+                        * this will happen when it is waking up for the next
+                        * time. */
+                       sta->clear_dst_mask = 1;
+
+                       /* TODO: Is the WLAN_STA_PS flag always set here or is
+                        * the race between RX and TX status causing some
+                        * packets to be filtered out before 80211.o gets an
+                        * update for PS status? This seems to be the case, so
+                        * no changes are likely to be needed. */
+                       if (sta->flags & WLAN_STA_PS &&
+                           skb_queue_len(&sta->tx_filtered) <
+                           STA_MAX_TX_BUFFER) {
+                               ieee80211_remove_tx_extra(local, sta->key,
+                                                         skb,
+                                                         &status->control);
+                               skb_queue_tail(&sta->tx_filtered, skb);
+                       } else if (!(sta->flags & WLAN_STA_PS) &&
+                                  !(status->control.flags & IEEE80211_TXCTL_REQUEUE)) {
+                               /* Software retry the packet once */
+                               status->control.flags |= IEEE80211_TXCTL_REQUEUE;
+                               ieee80211_remove_tx_extra(local, sta->key,
+                                                         skb,
+                                                         &status->control);
+                               dev_queue_xmit(skb);
+                       } else {
+                               if (net_ratelimit()) {
+                                       printk(KERN_DEBUG "%s: dropped TX "
+                                              "filtered frame queue_len=%d "
+                                              "PS=%d @%lu\n",
+                                              local->mdev->name,
+                                              skb_queue_len(
+                                                      &sta->tx_filtered),
+                                              !!(sta->flags & WLAN_STA_PS),
+                                              jiffies);
+                               }
+                               dev_kfree_skb(skb);
+                       }
+                       sta_info_put(sta);
+                       return;
+               }
+       } else {
+               /* FIXME: STUPID to call this with both local and local->mdev */
+               rate_control_tx_status(local, local->mdev, skb, status);
+       }
+
+       ieee80211_led_tx(local, 0);
+
+       /* SNMP counters
+        * Fragments are passed to low-level drivers as separate skbs, so these
+        * are actually fragments, not frames. Update frame counters only for
+        * the first fragment of the frame. */
+
+       frag = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_FRAG;
+       type = le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_FTYPE;
+
+       if (status->flags & IEEE80211_TX_STATUS_ACK) {
+               if (frag == 0) {
+                       local->dot11TransmittedFrameCount++;
+                       if (is_multicast_ether_addr(hdr->addr1))
+                               local->dot11MulticastTransmittedFrameCount++;
+                       if (status->retry_count > 0)
+                               local->dot11RetryCount++;
+                       if (status->retry_count > 1)
+                               local->dot11MultipleRetryCount++;
+               }
+
+               /* This counter shall be incremented for an acknowledged MPDU
+                * with an individual address in the address 1 field or an MPDU
+                * with a multicast address in the address 1 field of type Data
+                * or Management. */
+               if (!is_multicast_ether_addr(hdr->addr1) ||
+                   type == IEEE80211_FTYPE_DATA ||
+                   type == IEEE80211_FTYPE_MGMT)
+                       local->dot11TransmittedFragmentCount++;
+       } else {
+               if (frag == 0)
+                       local->dot11FailedCount++;
+       }
+
+       if (!(status->control.flags & IEEE80211_TXCTL_REQ_TX_STATUS)
+           || unlikely(!local->apdev)) {
+               dev_kfree_skb(skb);
+               return;
+       }
+
+       msg_type = (status->flags & IEEE80211_TX_STATUS_ACK) ?
+               ieee80211_msg_tx_callback_ack : ieee80211_msg_tx_callback_fail;
+
+       /* skb was the original skb used for TX. Clone it and give the clone
+        * to netif_rx(). Free original skb. */
+       skb2 = skb_copy(skb, GFP_ATOMIC);
+       if (!skb2) {
+               dev_kfree_skb(skb);
+               return;
+       }
+       dev_kfree_skb(skb);
+       skb = skb2;
+
+       /* Send frame to hostapd */
+       ieee80211_rx_mgmt(local, skb, NULL, msg_type);
+}
+EXPORT_SYMBOL(ieee80211_tx_status);
+
+/* TODO: implement register/unregister functions for adding TX/RX handlers
+ * into ordered list */
+
+/* rx_pre handlers don't have dev and sdata fields available in
+ * ieee80211_txrx_data */
+static ieee80211_rx_handler ieee80211_rx_pre_handlers[] =
+{
+       ieee80211_rx_h_parse_qos,
+       ieee80211_rx_h_load_stats,
+       NULL
+};
+
+static ieee80211_rx_handler ieee80211_rx_handlers[] =
+{
+       ieee80211_rx_h_if_stats,
+       ieee80211_rx_h_monitor,
+       ieee80211_rx_h_passive_scan,
+       ieee80211_rx_h_check,
+       ieee80211_rx_h_sta_process,
+       ieee80211_rx_h_ccmp_decrypt,
+       ieee80211_rx_h_tkip_decrypt,
+       ieee80211_rx_h_wep_weak_iv_detection,
+       ieee80211_rx_h_wep_decrypt,
+       ieee80211_rx_h_defragment,
+       ieee80211_rx_h_ps_poll,
+       ieee80211_rx_h_michael_mic_verify,
+       /* this must be after decryption - so header is counted in MPDU mic
+        * must be before pae and data, so QOS_DATA format frames
+        * are not passed to user space by these functions
+        */
+       ieee80211_rx_h_remove_qos_control,
+       ieee80211_rx_h_802_1x_pae,
+       ieee80211_rx_h_drop_unencrypted,
+       ieee80211_rx_h_data,
+       ieee80211_rx_h_mgmt,
+       NULL
+};
+
+static ieee80211_tx_handler ieee80211_tx_handlers[] =
+{
+       ieee80211_tx_h_check_assoc,
+       ieee80211_tx_h_sequence,
+       ieee80211_tx_h_ps_buf,
+       ieee80211_tx_h_select_key,
+       ieee80211_tx_h_michael_mic_add,
+       ieee80211_tx_h_fragment,
+       ieee80211_tx_h_tkip_encrypt,
+       ieee80211_tx_h_ccmp_encrypt,
+       ieee80211_tx_h_wep_encrypt,
+       ieee80211_tx_h_rate_ctrl,
+       ieee80211_tx_h_misc,
+       ieee80211_tx_h_load_stats,
+       NULL
+};
+
+
+int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+       struct sta_info *sta;
+
+       if (compare_ether_addr(remote_addr, sdata->u.wds.remote_addr) == 0)
+               return 0;
+
+       /* Create STA entry for the new peer */
+       sta = sta_info_add(local, dev, remote_addr, GFP_KERNEL);
+       if (!sta)
+               return -ENOMEM;
+       sta_info_put(sta);
+
+       /* Remove STA entry for the old peer */
+       sta = sta_info_get(local, sdata->u.wds.remote_addr);
+       if (sta) {
+               sta_info_put(sta);
+               sta_info_free(sta, 0);
+       } else {
+               printk(KERN_DEBUG "%s: could not find STA entry for WDS link "
+                      "peer " MAC_FMT "\n",
+                      dev->name, MAC_ARG(sdata->u.wds.remote_addr));
+       }
+
+       /* Update WDS link data */
+       memcpy(&sdata->u.wds.remote_addr, remote_addr, ETH_ALEN);
+
+       return 0;
+}
+
+/* Must not be called for mdev and apdev */
+void ieee80211_if_setup(struct net_device *dev)
+{
+       ether_setup(dev);
+       dev->hard_start_xmit = ieee80211_subif_start_xmit;
+       dev->wireless_handlers = &ieee80211_iw_handler_def;
+       dev->set_multicast_list = ieee80211_set_multicast_list;
+       dev->change_mtu = ieee80211_change_mtu;
+       dev->get_stats = ieee80211_get_stats;
+       dev->open = ieee80211_open;
+       dev->stop = ieee80211_stop;
+       dev->uninit = ieee80211_if_reinit;
+       dev->destructor = ieee80211_if_free;
+}
+
+void ieee80211_if_mgmt_setup(struct net_device *dev)
+{
+       ether_setup(dev);
+       dev->hard_start_xmit = ieee80211_mgmt_start_xmit;
+       dev->change_mtu = ieee80211_change_mtu_apdev;
+       dev->get_stats = ieee80211_get_stats;
+       dev->open = ieee80211_mgmt_open;
+       dev->stop = ieee80211_mgmt_stop;
+       dev->type = ARPHRD_IEEE80211_PRISM;
+       dev->hard_header_parse = header_parse_80211;
+       dev->uninit = ieee80211_if_reinit;
+       dev->destructor = ieee80211_if_free;
+}
+
+int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
+                                const char *name)
+{
+       struct rate_control_ref *ref, *old;
+
+       ASSERT_RTNL();
+       if (local->open_count || netif_running(local->mdev) ||
+           (local->apdev && netif_running(local->apdev)))
+               return -EBUSY;
+
+       ref = rate_control_alloc(name, local);
+       if (!ref) {
+               printk(KERN_WARNING "%s: Failed to select rate control "
+                      "algorithm\n", local->mdev->name);
+               return -ENOENT;
+       }
+
+       old = local->rate_ctrl;
+       local->rate_ctrl = ref;
+       if (old) {
+               rate_control_put(old);
+               sta_info_flush(local, NULL);
+       }
+
+       printk(KERN_DEBUG "%s: Selected rate control "
+              "algorithm '%s'\n", local->mdev->name,
+              ref->ops->name);
+
+
+       return 0;
+}
+
+static void rate_control_deinitialize(struct ieee80211_local *local)
+{
+       struct rate_control_ref *ref;
+
+       ref = local->rate_ctrl;
+       local->rate_ctrl = NULL;
+       rate_control_put(ref);
+}
+
+struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
+                                       const struct ieee80211_ops *ops)
+{
+       struct net_device *mdev;
+       struct ieee80211_local *local;
+       struct ieee80211_sub_if_data *sdata;
+       int priv_size;
+       struct wiphy *wiphy;
+
+       /* Ensure 32-byte alignment of our private data and hw private data.
+        * We use the wiphy priv data for both our ieee80211_local and for
+        * the driver's private data
+        *
+        * In memory it'll be like this:
+        *
+        * +-------------------------+
+        * | struct wiphy           |
+        * +-------------------------+
+        * | struct ieee80211_local  |
+        * +-------------------------+
+        * | driver's private data   |
+        * +-------------------------+
+        *
+        */
+       priv_size = ((sizeof(struct ieee80211_local) +
+                     NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST) +
+                   priv_data_len;
+
+       wiphy = wiphy_new(&mac80211_config_ops, priv_size);
+
+       if (!wiphy)
+               return NULL;
+
+       wiphy->privid = mac80211_wiphy_privid;
+
+       local = wiphy_priv(wiphy);
+       local->hw.wiphy = wiphy;
+
+       local->hw.priv = (char *)local +
+                        ((sizeof(struct ieee80211_local) +
+                          NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
+
+       local->ops = ops;
+
+       /* for now, mdev needs sub_if_data :/ */
+       mdev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
+                           "wmaster%d", ether_setup);
+       if (!mdev) {
+               wiphy_free(wiphy);
+               return NULL;
+       }
+
+       sdata = IEEE80211_DEV_TO_SUB_IF(mdev);
+       mdev->ieee80211_ptr = &sdata->wdev;
+       sdata->wdev.wiphy = wiphy;
+
+       local->hw.queues = 1; /* default */
+
+       local->mdev = mdev;
+       local->rx_pre_handlers = ieee80211_rx_pre_handlers;
+       local->rx_handlers = ieee80211_rx_handlers;
+       local->tx_handlers = ieee80211_tx_handlers;
+
+       local->bridge_packets = 1;
+
+       local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
+       local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
+       local->short_retry_limit = 7;
+       local->long_retry_limit = 4;
+       local->hw.conf.radio_enabled = 1;
+       local->rate_ctrl_num_up = RATE_CONTROL_NUM_UP;
+       local->rate_ctrl_num_down = RATE_CONTROL_NUM_DOWN;
+
+       local->enabled_modes = (unsigned int) -1;
+
+       INIT_LIST_HEAD(&local->modes_list);
+
+       rwlock_init(&local->sub_if_lock);
+       INIT_LIST_HEAD(&local->sub_if_list);
+
+       INIT_DELAYED_WORK(&local->scan_work, ieee80211_sta_scan_work);
+       init_timer(&local->stat_timer);
+       local->stat_timer.function = ieee80211_stat_refresh;
+       local->stat_timer.data = (unsigned long) local;
+       ieee80211_rx_bss_list_init(mdev);
+
+       sta_info_init(local);
+
+       mdev->hard_start_xmit = ieee80211_master_start_xmit;
+       mdev->open = ieee80211_master_open;
+       mdev->stop = ieee80211_master_stop;
+       mdev->type = ARPHRD_IEEE80211;
+       mdev->hard_header_parse = header_parse_80211;
+
+       sdata->type = IEEE80211_IF_TYPE_AP;
+       sdata->dev = mdev;
+       sdata->local = local;
+       sdata->u.ap.force_unicast_rateidx = -1;
+       sdata->u.ap.max_ratectrl_rateidx = -1;
+       ieee80211_if_sdata_init(sdata);
+       list_add_tail(&sdata->list, &local->sub_if_list);
+
+       tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
+                    (unsigned long)local);
+       tasklet_disable(&local->tx_pending_tasklet);
+
+       tasklet_init(&local->tasklet,
+                    ieee80211_tasklet_handler,
+                    (unsigned long) local);
+       tasklet_disable(&local->tasklet);
+
+       skb_queue_head_init(&local->skb_queue);
+       skb_queue_head_init(&local->skb_queue_unreliable);
+
+       return local_to_hw(local);
+}
+EXPORT_SYMBOL(ieee80211_alloc_hw);
+
+int ieee80211_register_hw(struct ieee80211_hw *hw)
+{
+       struct ieee80211_local *local = hw_to_local(hw);
+       const char *name;
+       int result;
+
+       result = wiphy_register(local->hw.wiphy);
+       if (result < 0)
+               return result;
+
+       name = wiphy_dev(local->hw.wiphy)->driver->name;
+       local->hw.workqueue = create_singlethread_workqueue(name);
+       if (!local->hw.workqueue) {
+               result = -ENOMEM;
+               goto fail_workqueue;
+       }
+
+       local->hw.conf.beacon_int = 1000;
+
+       local->wstats_flags |= local->hw.max_rssi ?
+                              IW_QUAL_LEVEL_UPDATED : IW_QUAL_LEVEL_INVALID;
+       local->wstats_flags |= local->hw.max_signal ?
+                              IW_QUAL_QUAL_UPDATED : IW_QUAL_QUAL_INVALID;
+       local->wstats_flags |= local->hw.max_noise ?
+                              IW_QUAL_NOISE_UPDATED : IW_QUAL_NOISE_INVALID;
+       if (local->hw.max_rssi < 0 || local->hw.max_noise < 0)
+               local->wstats_flags |= IW_QUAL_DBM;
+
+       result = sta_info_start(local);
+       if (result < 0)
+               goto fail_sta_info;
+
+       rtnl_lock();
+       result = dev_alloc_name(local->mdev, local->mdev->name);
+       if (result < 0)
+               goto fail_dev;
+
+       memcpy(local->mdev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
+       SET_NETDEV_DEV(local->mdev, wiphy_dev(local->hw.wiphy));
+
+       result = register_netdevice(local->mdev);
+       if (result < 0)
+               goto fail_dev;
+
+       result = ieee80211_init_rate_ctrl_alg(local, NULL);
+       if (result < 0) {
+               printk(KERN_DEBUG "%s: Failed to initialize rate control "
+                      "algorithm\n", local->mdev->name);
+               goto fail_rate;
+       }
+
+       result = ieee80211_wep_init(local);
+
+       if (result < 0) {
+               printk(KERN_DEBUG "%s: Failed to initialize wep\n",
+                      local->mdev->name);
+               goto fail_wep;
+       }
+
+       ieee80211_install_qdisc(local->mdev);
+
+       /* add one default STA interface */
+       result = ieee80211_if_add(local->mdev, "wlan%d", NULL,
+                                 IEEE80211_IF_TYPE_STA);
+       if (result)
+               printk(KERN_WARNING "%s: Failed to add default virtual iface\n",
+                      local->mdev->name);
+
+       local->reg_state = IEEE80211_DEV_REGISTERED;
+       rtnl_unlock();
+
+       ieee80211_led_init(local);
+
+       return 0;
+
+fail_wep:
+       rate_control_deinitialize(local);
+fail_rate:
+       unregister_netdevice(local->mdev);
+fail_dev:
+       rtnl_unlock();
+       sta_info_stop(local);
+fail_sta_info:
+       destroy_workqueue(local->hw.workqueue);
+fail_workqueue:
+       wiphy_unregister(local->hw.wiphy);
+       return result;
+}
+EXPORT_SYMBOL(ieee80211_register_hw);
+
+int ieee80211_register_hwmode(struct ieee80211_hw *hw,
+                             struct ieee80211_hw_mode *mode)
+{
+       struct ieee80211_local *local = hw_to_local(hw);
+       struct ieee80211_rate *rate;
+       int i;
+
+       INIT_LIST_HEAD(&mode->list);
+       list_add_tail(&mode->list, &local->modes_list);
+
+       local->hw_modes |= (1 << mode->mode);
+       for (i = 0; i < mode->num_rates; i++) {
+               rate = &(mode->rates[i]);
+               rate->rate_inv = CHAN_UTIL_RATE_LCM / rate->rate;
+       }
+       ieee80211_prepare_rates(local, mode);
+
+       if (!local->oper_hw_mode) {
+               /* Default to this mode */
+               local->hw.conf.phymode = mode->mode;
+               local->oper_hw_mode = local->scan_hw_mode = mode;
+               local->oper_channel = local->scan_channel = &mode->channels[0];
+               local->hw.conf.mode = local->oper_hw_mode;
+               local->hw.conf.chan = local->oper_channel;
+       }
+
+       if (!(hw->flags & IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED))
+               ieee80211_init_client(local->mdev);
+
+       return 0;
+}
+EXPORT_SYMBOL(ieee80211_register_hwmode);
+
+void ieee80211_unregister_hw(struct ieee80211_hw *hw)
+{
+       struct ieee80211_local *local = hw_to_local(hw);
+       struct ieee80211_sub_if_data *sdata, *tmp;
+       struct list_head tmp_list;
+       int i;
+
+       tasklet_kill(&local->tx_pending_tasklet);
+       tasklet_kill(&local->tasklet);
+
+       rtnl_lock();
+
+       BUG_ON(local->reg_state != IEEE80211_DEV_REGISTERED);
+
+       local->reg_state = IEEE80211_DEV_UNREGISTERED;
+       if (local->apdev)
+               ieee80211_if_del_mgmt(local);
+
+       write_lock_bh(&local->sub_if_lock);
+       list_replace_init(&local->sub_if_list, &tmp_list);
+       write_unlock_bh(&local->sub_if_lock);
+
+       list_for_each_entry_safe(sdata, tmp, &tmp_list, list)
+               __ieee80211_if_del(local, sdata);
+
+       rtnl_unlock();
+
+       if (local->stat_time)
+               del_timer_sync(&local->stat_timer);
+
+       ieee80211_rx_bss_list_deinit(local->mdev);
+       ieee80211_clear_tx_pending(local);
+       sta_info_stop(local);
+       rate_control_deinitialize(local);
+
+       for (i = 0; i < NUM_IEEE80211_MODES; i++) {
+               kfree(local->supp_rates[i]);
+               kfree(local->basic_rates[i]);
+       }
+
+       if (skb_queue_len(&local->skb_queue)
+                       || skb_queue_len(&local->skb_queue_unreliable))
+               printk(KERN_WARNING "%s: skb_queue not empty\n",
+                      local->mdev->name);
+       skb_queue_purge(&local->skb_queue);
+       skb_queue_purge(&local->skb_queue_unreliable);
+
+       destroy_workqueue(local->hw.workqueue);
+       wiphy_unregister(local->hw.wiphy);
+       ieee80211_wep_free(local);
+       ieee80211_led_exit(local);
+}
+EXPORT_SYMBOL(ieee80211_unregister_hw);
+
+void ieee80211_free_hw(struct ieee80211_hw *hw)
+{
+       struct ieee80211_local *local = hw_to_local(hw);
+
+       ieee80211_if_free(local->mdev);
+       wiphy_free(local->hw.wiphy);
+}
+EXPORT_SYMBOL(ieee80211_free_hw);
+
+void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
+{
+       struct ieee80211_local *local = hw_to_local(hw);
+
+       if (test_and_clear_bit(IEEE80211_LINK_STATE_XOFF,
+                              &local->state[queue])) {
+               if (test_bit(IEEE80211_LINK_STATE_PENDING,
+                            &local->state[queue]))
+                       tasklet_schedule(&local->tx_pending_tasklet);
+               else
+                       if (!ieee80211_qdisc_installed(local->mdev)) {
+                               if (queue == 0)
+                                       netif_wake_queue(local->mdev);
+                       } else
+                               __netif_schedule(local->mdev);
+       }
+}
+EXPORT_SYMBOL(ieee80211_wake_queue);
+
+void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue)
+{
+       struct ieee80211_local *local = hw_to_local(hw);
+
+       if (!ieee80211_qdisc_installed(local->mdev) && queue == 0)
+               netif_stop_queue(local->mdev);
+       set_bit(IEEE80211_LINK_STATE_XOFF, &local->state[queue]);
+}
+EXPORT_SYMBOL(ieee80211_stop_queue);
+
+void ieee80211_start_queues(struct ieee80211_hw *hw)
+{
+       struct ieee80211_local *local = hw_to_local(hw);
+       int i;
+
+       for (i = 0; i < local->hw.queues; i++)
+               clear_bit(IEEE80211_LINK_STATE_XOFF, &local->state[i]);
+       if (!ieee80211_qdisc_installed(local->mdev))
+               netif_start_queue(local->mdev);
+}
+EXPORT_SYMBOL(ieee80211_start_queues);
+
+void ieee80211_stop_queues(struct ieee80211_hw *hw)
+{
+       int i;
+
+       for (i = 0; i < hw->queues; i++)
+               ieee80211_stop_queue(hw, i);
+}
+EXPORT_SYMBOL(ieee80211_stop_queues);
+
+void ieee80211_wake_queues(struct ieee80211_hw *hw)
+{
+       int i;
+
+       for (i = 0; i < hw->queues; i++)
+               ieee80211_wake_queue(hw, i);
+}
+EXPORT_SYMBOL(ieee80211_wake_queues);
+
+struct net_device_stats *ieee80211_dev_stats(struct net_device *dev)
+{
+       struct ieee80211_sub_if_data *sdata;
+       sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+       return &sdata->stats;
+}
+
+static int __init ieee80211_init(void)
+{
+       struct sk_buff *skb;
+       int ret;
+
+       BUILD_BUG_ON(sizeof(struct ieee80211_tx_packet_data) > sizeof(skb->cb));
+
+       ret = ieee80211_wme_register();
+       if (ret) {
+               printk(KERN_DEBUG "ieee80211_init: failed to "
+                      "initialize WME (err=%d)\n", ret);
+               return ret;
+       }
+
+       return 0;
+}
+
+
+static void __exit ieee80211_exit(void)
+{
+       ieee80211_wme_unregister();
+}
+
+
+module_init(ieee80211_init);
+module_exit(ieee80211_exit);
+
+MODULE_DESCRIPTION("IEEE 802.11 subsystem");
+MODULE_LICENSE("GPL");
diff --git a/net/mac80211/ieee80211_cfg.c b/net/mac80211/ieee80211_cfg.c
new file mode 100644 (file)
index 0000000..509096e
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * mac80211 configuration hooks for cfg80211
+ *
+ * Copyright 2006      Johannes Berg <johannes@sipsolutions.net>
+ *
+ * This file is GPLv2 as found in COPYING.
+ */
+
+#include <linux/nl80211.h>
+#include <linux/rtnetlink.h>
+#include <net/cfg80211.h>
+#include "ieee80211_i.h"
+#include "ieee80211_cfg.h"
+
+static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
+                              unsigned int type)
+{
+       struct ieee80211_local *local = wiphy_priv(wiphy);
+       int itype;
+
+       if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
+               return -ENODEV;
+
+       switch (type) {
+       case NL80211_IFTYPE_UNSPECIFIED:
+               itype = IEEE80211_IF_TYPE_STA;
+               break;
+       case NL80211_IFTYPE_ADHOC:
+               itype = IEEE80211_IF_TYPE_IBSS;
+               break;
+       case NL80211_IFTYPE_STATION:
+               itype = IEEE80211_IF_TYPE_STA;
+               break;
+       case NL80211_IFTYPE_MONITOR:
+               itype = IEEE80211_IF_TYPE_MNTR;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return ieee80211_if_add(local->mdev, name, NULL, itype);
+}
+
+static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
+{
+       struct ieee80211_local *local = wiphy_priv(wiphy);
+       struct net_device *dev;
+       char *name;
+
+       if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
+               return -ENODEV;
+
+       dev = dev_get_by_index(ifindex);
+       if (!dev)
+               return 0;
+
+       name = dev->name;
+       dev_put(dev);
+
+       return ieee80211_if_remove(local->mdev, name, -1);
+}
+
+struct cfg80211_ops mac80211_config_ops = {
+       .add_virtual_intf = ieee80211_add_iface,
+       .del_virtual_intf = ieee80211_del_iface,
+};
diff --git a/net/mac80211/ieee80211_cfg.h b/net/mac80211/ieee80211_cfg.h
new file mode 100644 (file)
index 0000000..85ed2c9
--- /dev/null
@@ -0,0 +1,9 @@
+/*
+ * mac80211 configuration hooks for cfg80211
+ */
+#ifndef __IEEE80211_CFG_H
+#define __IEEE80211_CFG_H
+
+extern struct cfg80211_ops mac80211_config_ops;
+
+#endif /* __IEEE80211_CFG_H */
diff --git a/net/mac80211/ieee80211_common.h b/net/mac80211/ieee80211_common.h
new file mode 100644 (file)
index 0000000..b9a73e7
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * IEEE 802.11 driver (80211.o) -- hostapd interface
+ * Copyright 2002-2004, Instant802 Networks, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef IEEE80211_COMMON_H
+#define IEEE80211_COMMON_H
+
+#include <linux/types.h>
+
+/*
+ * This is common header information with user space. It is used on all
+ * frames sent to wlan#ap interface.
+ */
+
+#define IEEE80211_FI_VERSION 0x80211001
+
+struct ieee80211_frame_info {
+       __be32 version;
+       __be32 length;
+       __be64 mactime;
+       __be64 hosttime;
+       __be32 phytype;
+       __be32 channel;
+       __be32 datarate;
+       __be32 antenna;
+       __be32 priority;
+       __be32 ssi_type;
+       __be32 ssi_signal;
+       __be32 ssi_noise;
+       __be32 preamble;
+       __be32 encoding;
+
+       /* Note: this structure is otherwise identical to capture format used
+        * in linux-wlan-ng, but this additional field is used to provide meta
+        * data about the frame to hostapd. This was the easiest method for
+        * providing this information, but this might change in the future. */
+       __be32 msg_type;
+} __attribute__ ((packed));
+
+
+enum ieee80211_msg_type {
+       ieee80211_msg_normal = 0,
+       ieee80211_msg_tx_callback_ack = 1,
+       ieee80211_msg_tx_callback_fail = 2,
+       ieee80211_msg_passive_scan = 3,
+       ieee80211_msg_wep_frame_unknown_key = 4,
+       ieee80211_msg_michael_mic_failure = 5,
+       /* hole at 6, was monitor but never sent to userspace */
+       ieee80211_msg_sta_not_assoc = 7,
+       ieee80211_msg_set_aid_for_sta = 8 /* used by Intersil MVC driver */,
+       ieee80211_msg_key_threshold_notification = 9,
+       ieee80211_msg_radar = 11,
+};
+
+struct ieee80211_msg_set_aid_for_sta {
+       char    sta_address[ETH_ALEN];
+       u16     aid;
+};
+
+struct ieee80211_msg_key_notification {
+       int tx_rx_count;
+       char ifname[IFNAMSIZ];
+       u8 addr[ETH_ALEN]; /* ff:ff:ff:ff:ff:ff for broadcast keys */
+};
+
+
+enum ieee80211_phytype {
+       ieee80211_phytype_fhss_dot11_97  = 1,
+       ieee80211_phytype_dsss_dot11_97  = 2,
+       ieee80211_phytype_irbaseband     = 3,
+       ieee80211_phytype_dsss_dot11_b   = 4,
+       ieee80211_phytype_pbcc_dot11_b   = 5,
+       ieee80211_phytype_ofdm_dot11_g   = 6,
+       ieee80211_phytype_pbcc_dot11_g   = 7,
+       ieee80211_phytype_ofdm_dot11_a   = 8,
+       ieee80211_phytype_dsss_dot11_turbog = 255,
+       ieee80211_phytype_dsss_dot11_turbo = 256,
+};
+
+enum ieee80211_ssi_type {
+       ieee80211_ssi_none = 0,
+       ieee80211_ssi_norm = 1, /* normalized, 0-1000 */
+       ieee80211_ssi_dbm = 2,
+       ieee80211_ssi_raw = 3, /* raw SSI */
+};
+
+struct ieee80211_radar_info {
+               int channel;
+               int radar;
+               int radar_type;
+};
+
+#endif /* IEEE80211_COMMON_H */
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
new file mode 100644 (file)
index 0000000..ae94d64
--- /dev/null
@@ -0,0 +1,671 @@
+/*
+ * Copyright 2002-2005, Instant802 Networks, Inc.
+ * Copyright 2005, Devicescape Software, Inc.
+ * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef IEEE80211_I_H
+#define IEEE80211_I_H
+
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/if_ether.h>
+#include <linux/interrupt.h>
+#include <linux/list.h>
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+#include <linux/workqueue.h>
+#include <linux/types.h>
+#include <linux/spinlock.h>
+#include <net/wireless.h>
+#include "ieee80211_key.h"
+#include "sta_info.h"
+
+/* ieee80211.o internal definitions, etc. These are not included into
+ * low-level drivers. */
+
+#ifndef ETH_P_PAE
+#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
+#endif /* ETH_P_PAE */
+
+#define WLAN_FC_DATA_PRESENT(fc) (((fc) & 0x4c) == 0x08)
+
+struct ieee80211_local;
+
+#define BIT(x) (1 << (x))
+
+#define IEEE80211_ALIGN32_PAD(a) ((4 - ((a) & 3)) & 3)
+
+/* Maximum number of broadcast/multicast frames to buffer when some of the
+ * associated stations are using power saving. */
+#define AP_MAX_BC_BUFFER 128
+
+/* Maximum number of frames buffered to all STAs, including multicast frames.
+ * Note: increasing this limit increases the potential memory requirement. Each
+ * frame can be up to about 2 kB long. */
+#define TOTAL_MAX_TX_BUFFER 512
+
+/* Required encryption head and tailroom */
+#define IEEE80211_ENCRYPT_HEADROOM 8
+#define IEEE80211_ENCRYPT_TAILROOM 12
+
+/* IEEE 802.11 (Ch. 9.5 Defragmentation) requires support for concurrent
+ * reception of at least three fragmented frames. This limit can be increased
+ * by changing this define, at the cost of slower frame reassembly and
+ * increased memory use (about 2 kB of RAM per entry). */
+#define IEEE80211_FRAGMENT_MAX 4
+
+struct ieee80211_fragment_entry {
+       unsigned long first_frag_time;
+       unsigned int seq;
+       unsigned int rx_queue;
+       unsigned int last_frag;
+       unsigned int extra_len;
+       struct sk_buff_head skb_list;
+       int ccmp; /* Whether fragments were encrypted with CCMP */
+       u8 last_pn[6]; /* PN of the last fragment if CCMP was used */
+};
+
+
+struct ieee80211_sta_bss {
+       struct list_head list;
+       struct ieee80211_sta_bss *hnext;
+       atomic_t users;
+
+       u8 bssid[ETH_ALEN];
+       u8 ssid[IEEE80211_MAX_SSID_LEN];
+       size_t ssid_len;
+       u16 capability; /* host byte order */
+       int hw_mode;
+       int channel;
+       int freq;
+       int rssi, signal, noise;
+       u8 *wpa_ie;
+       size_t wpa_ie_len;
+       u8 *rsn_ie;
+       size_t rsn_ie_len;
+       u8 *wmm_ie;
+       size_t wmm_ie_len;
+#define IEEE80211_MAX_SUPP_RATES 32
+       u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
+       size_t supp_rates_len;
+       int beacon_int;
+       u64 timestamp;
+
+       int probe_resp;
+       unsigned long last_update;
+
+};
+
+
+typedef enum {
+       TXRX_CONTINUE, TXRX_DROP, TXRX_QUEUED
+} ieee80211_txrx_result;
+
+struct ieee80211_txrx_data {
+       struct sk_buff *skb;
+       struct net_device *dev;
+       struct ieee80211_local *local;
+       struct ieee80211_sub_if_data *sdata;
+       struct sta_info *sta;
+       u16 fc, ethertype;
+       struct ieee80211_key *key;
+       unsigned int fragmented:1; /* whether the MSDU was fragmented */
+       union {
+               struct {
+                       struct ieee80211_tx_control *control;
+                       unsigned int unicast:1;
+                       unsigned int ps_buffered:1;
+                       unsigned int short_preamble:1;
+                       unsigned int probe_last_frag:1;
+                       struct ieee80211_hw_mode *mode;
+                       struct ieee80211_rate *rate;
+                       /* use this rate (if set) for last fragment; rate can
+                        * be set to lower rate for the first fragments, e.g.,
+                        * when using CTS protection with IEEE 802.11g. */
+                       struct ieee80211_rate *last_frag_rate;
+                       int last_frag_hwrate;
+                       int mgmt_interface;
+
+                       /* Extra fragments (in addition to the first fragment
+                        * in skb) */
+                       int num_extra_frag;
+                       struct sk_buff **extra_frag;
+               } tx;
+               struct {
+                       struct ieee80211_rx_status *status;
+                       int sent_ps_buffered;
+                       int queue;
+                       int load;
+                       unsigned int in_scan:1;
+                       /* frame is destined to interface currently processed
+                        * (including multicast frames) */
+                       unsigned int ra_match:1;
+               } rx;
+       } u;
+};
+
+/* Stored in sk_buff->cb */
+struct ieee80211_tx_packet_data {
+       int ifindex;
+       unsigned long jiffies;
+       unsigned int req_tx_status:1;
+       unsigned int do_not_encrypt:1;
+       unsigned int requeue:1;
+       unsigned int mgmt_iface:1;
+       unsigned int queue:4;
+};
+
+struct ieee80211_tx_stored_packet {
+       struct ieee80211_tx_control control;
+       struct sk_buff *skb;
+       int num_extra_frag;
+       struct sk_buff **extra_frag;
+       int last_frag_rateidx;
+       int last_frag_hwrate;
+       struct ieee80211_rate *last_frag_rate;
+       unsigned int last_frag_rate_ctrl_probe:1;
+};
+
+typedef ieee80211_txrx_result (*ieee80211_tx_handler)
+(struct ieee80211_txrx_data *tx);
+
+typedef ieee80211_txrx_result (*ieee80211_rx_handler)
+(struct ieee80211_txrx_data *rx);
+
+struct ieee80211_if_ap {
+       u8 *beacon_head, *beacon_tail;
+       int beacon_head_len, beacon_tail_len;
+
+       u8 ssid[IEEE80211_MAX_SSID_LEN];
+       size_t ssid_len;
+       u8 *generic_elem;
+       size_t generic_elem_len;
+
+       /* yes, this looks ugly, but guarantees that we can later use
+        * bitmap_empty :)
+        * NB: don't ever use set_bit, use bss_tim_set/bss_tim_clear! */
+       u8 tim[sizeof(unsigned long) * BITS_TO_LONGS(IEEE80211_MAX_AID + 1)];
+       atomic_t num_sta_ps; /* number of stations in PS mode */
+       struct sk_buff_head ps_bc_buf;
+       int dtim_period, dtim_count;
+       int force_unicast_rateidx; /* forced TX rateidx for unicast frames */
+       int max_ratectrl_rateidx; /* max TX rateidx for rate control */
+       int num_beacons; /* number of TXed beacon frames for this BSS */
+};
+
+struct ieee80211_if_wds {
+       u8 remote_addr[ETH_ALEN];
+       struct sta_info *sta;
+};
+
+struct ieee80211_if_vlan {
+       u8 id;
+};
+
+struct ieee80211_if_sta {
+       enum {
+               IEEE80211_DISABLED, IEEE80211_AUTHENTICATE,
+               IEEE80211_ASSOCIATE, IEEE80211_ASSOCIATED,
+               IEEE80211_IBSS_SEARCH, IEEE80211_IBSS_JOINED
+       } state;
+       struct timer_list timer;
+       struct work_struct work;
+       u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN];
+       u8 ssid[IEEE80211_MAX_SSID_LEN];
+       size_t ssid_len;
+       u16 aid;
+       u16 ap_capab, capab;
+       u8 *extra_ie; /* to be added to the end of AssocReq */
+       size_t extra_ie_len;
+
+       /* The last AssocReq/Resp IEs */
+       u8 *assocreq_ies, *assocresp_ies;
+       size_t assocreq_ies_len, assocresp_ies_len;
+
+       int auth_tries, assoc_tries;
+
+       unsigned int ssid_set:1;
+       unsigned int bssid_set:1;
+       unsigned int prev_bssid_set:1;
+       unsigned int authenticated:1;
+       unsigned int associated:1;
+       unsigned int probereq_poll:1;
+       unsigned int use_protection:1;
+       unsigned int create_ibss:1;
+       unsigned int mixed_cell:1;
+       unsigned int wmm_enabled:1;
+       unsigned int auto_ssid_sel:1;
+       unsigned int auto_bssid_sel:1;
+       unsigned int auto_channel_sel:1;
+#define IEEE80211_STA_REQ_SCAN 0
+#define IEEE80211_STA_REQ_AUTH 1
+#define IEEE80211_STA_REQ_RUN  2
+       unsigned long request;
+       struct sk_buff_head skb_queue;
+
+       int key_mgmt;
+       unsigned long last_probe;
+
+#define IEEE80211_AUTH_ALG_OPEN BIT(0)
+#define IEEE80211_AUTH_ALG_SHARED_KEY BIT(1)
+#define IEEE80211_AUTH_ALG_LEAP BIT(2)
+       unsigned int auth_algs; /* bitfield of allowed auth algs */
+       int auth_alg; /* currently used IEEE 802.11 authentication algorithm */
+       int auth_transaction;
+
+       unsigned long ibss_join_req;
+       struct sk_buff *probe_resp; /* ProbeResp template for IBSS */
+       u32 supp_rates_bits;
+
+       int wmm_last_param_set;
+};
+
+
+struct ieee80211_sub_if_data {
+       struct list_head list;
+       unsigned int type;
+
+       struct wireless_dev wdev;
+
+       struct net_device *dev;
+       struct ieee80211_local *local;
+
+       int mc_count;
+       unsigned int allmulti:1;
+       unsigned int promisc:1;
+
+       struct net_device_stats stats;
+       int drop_unencrypted;
+       int eapol; /* 0 = process EAPOL frames as normal data frames,
+                   * 1 = send EAPOL frames through wlan#ap to hostapd
+                   *     (default) */
+       int ieee802_1x; /* IEEE 802.1X PAE - drop packet to/from unauthorized
+                        * port */
+
+       u16 sequence;
+
+       /* Fragment table for host-based reassembly */
+       struct ieee80211_fragment_entry fragments[IEEE80211_FRAGMENT_MAX];
+       unsigned int fragment_next;
+
+#define NUM_DEFAULT_KEYS 4
+       struct ieee80211_key *keys[NUM_DEFAULT_KEYS];
+       struct ieee80211_key *default_key;
+
+       struct ieee80211_if_ap *bss; /* BSS that this device belongs to */
+
+       union {
+               struct ieee80211_if_ap ap;
+               struct ieee80211_if_wds wds;
+               struct ieee80211_if_vlan vlan;
+               struct ieee80211_if_sta sta;
+       } u;
+       int channel_use;
+       int channel_use_raw;
+};
+
+#define IEEE80211_DEV_TO_SUB_IF(dev) netdev_priv(dev)
+
+enum {
+       IEEE80211_RX_MSG        = 1,
+       IEEE80211_TX_STATUS_MSG = 2,
+};
+
+struct ieee80211_local {
+       /* embed the driver visible part.
+        * don't cast (use the static inlines below), but we keep
+        * it first anyway so they become a no-op */
+       struct ieee80211_hw hw;
+
+       const struct ieee80211_ops *ops;
+
+       /* List of registered struct ieee80211_hw_mode */
+       struct list_head modes_list;
+
+       struct net_device *mdev; /* wmaster# - "master" 802.11 device */
+       struct net_device *apdev; /* wlan#ap - management frames (hostapd) */
+       int open_count;
+       int monitors;
+       struct iw_statistics wstats;
+       u8 wstats_flags;
+
+       enum {
+               IEEE80211_DEV_UNINITIALIZED = 0,
+               IEEE80211_DEV_REGISTERED,
+               IEEE80211_DEV_UNREGISTERED,
+       } reg_state;
+
+       /* Tasklet and skb queue to process calls from IRQ mode. All frames
+        * added to skb_queue will be processed, but frames in
+        * skb_queue_unreliable may be dropped if the total length of these
+        * queues increases over the limit. */
+#define IEEE80211_IRQSAFE_QUEUE_LIMIT 128
+       struct tasklet_struct tasklet;
+       struct sk_buff_head skb_queue;
+       struct sk_buff_head skb_queue_unreliable;
+
+       /* Station data structures */
+       spinlock_t sta_lock; /* mutex for STA data structures */
+       int num_sta; /* number of stations in sta_list */
+       struct list_head sta_list;
+       struct list_head deleted_sta_list;
+       struct sta_info *sta_hash[STA_HASH_SIZE];
+       struct timer_list sta_cleanup;
+
+       unsigned long state[NUM_TX_DATA_QUEUES];
+       struct ieee80211_tx_stored_packet pending_packet[NUM_TX_DATA_QUEUES];
+       struct tasklet_struct tx_pending_tasklet;
+
+       int mc_count;   /* total count of multicast entries in all interfaces */
+       int iff_allmultis, iff_promiscs;
+                       /* number of interfaces with corresponding IFF_ flags */
+
+       struct rate_control_ref *rate_ctrl;
+
+       int next_mode; /* MODE_IEEE80211*
+                       * The mode preference for next channel change. This is
+                       * used to select .11g vs. .11b channels (or 4.9 GHz vs.
+                       * .11a) when the channel number is not unique. */
+
+       /* Supported and basic rate filters for different modes. These are
+        * pointers to -1 terminated lists and rates in 100 kbps units. */
+       int *supp_rates[NUM_IEEE80211_MODES];
+       int *basic_rates[NUM_IEEE80211_MODES];
+
+       int rts_threshold;
+       int cts_protect_erp_frames;
+       int fragmentation_threshold;
+       int short_retry_limit; /* dot11ShortRetryLimit */
+       int long_retry_limit; /* dot11LongRetryLimit */
+       int short_preamble; /* use short preamble with IEEE 802.11b */
+
+       struct crypto_blkcipher *wep_tx_tfm;
+       struct crypto_blkcipher *wep_rx_tfm;
+       u32 wep_iv;
+       int key_tx_rx_threshold; /* number of times any key can be used in TX
+                                 * or RX before generating a rekey
+                                 * notification; 0 = notification disabled. */
+
+       int bridge_packets; /* bridge packets between associated stations and
+                            * deliver multicast frames both back to wireless
+                            * media and to the local net stack */
+
+       ieee80211_rx_handler *rx_pre_handlers;
+       ieee80211_rx_handler *rx_handlers;
+       ieee80211_tx_handler *tx_handlers;
+
+       rwlock_t sub_if_lock; /* Protects sub_if_list. Cannot be taken under
+                              * sta_bss_lock or sta_lock. */
+       struct list_head sub_if_list;
+       int sta_scanning;
+       int scan_channel_idx;
+       enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state;
+       unsigned long last_scan_completed;
+       struct delayed_work scan_work;
+       struct net_device *scan_dev;
+       struct ieee80211_channel *oper_channel, *scan_channel;
+       struct ieee80211_hw_mode *oper_hw_mode, *scan_hw_mode;
+       u8 scan_ssid[IEEE80211_MAX_SSID_LEN];
+       size_t scan_ssid_len;
+       struct list_head sta_bss_list;
+       struct ieee80211_sta_bss *sta_bss_hash[STA_HASH_SIZE];
+       spinlock_t sta_bss_lock;
+#define IEEE80211_SCAN_MATCH_SSID BIT(0)
+#define IEEE80211_SCAN_WPA_ONLY BIT(1)
+#define IEEE80211_SCAN_EXTRA_INFO BIT(2)
+       int scan_flags;
+
+       /* SNMP counters */
+       /* dot11CountersTable */
+       u32 dot11TransmittedFragmentCount;
+       u32 dot11MulticastTransmittedFrameCount;
+       u32 dot11FailedCount;
+       u32 dot11RetryCount;
+       u32 dot11MultipleRetryCount;
+       u32 dot11FrameDuplicateCount;
+       u32 dot11ReceivedFragmentCount;
+       u32 dot11MulticastReceivedFrameCount;
+       u32 dot11TransmittedFrameCount;
+       u32 dot11WEPUndecryptableCount;
+
+#ifdef CONFIG_MAC80211_LEDS
+       int tx_led_counter, rx_led_counter;
+       struct led_trigger *tx_led, *rx_led;
+       char tx_led_name[32], rx_led_name[32];
+#endif
+
+       u32 channel_use;
+       u32 channel_use_raw;
+       u32 stat_time;
+       struct timer_list stat_timer;
+
+       enum {
+               STA_ANTENNA_SEL_AUTO = 0,
+               STA_ANTENNA_SEL_SW_CTRL = 1,
+               STA_ANTENNA_SEL_SW_CTRL_DEBUG = 2
+       } sta_antenna_sel;
+
+       int rate_ctrl_num_up, rate_ctrl_num_down;
+
+#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
+       /* TX/RX handler statistics */
+       unsigned int tx_handlers_drop;
+       unsigned int tx_handlers_queued;
+       unsigned int tx_handlers_drop_unencrypted;
+       unsigned int tx_handlers_drop_fragment;
+       unsigned int tx_handlers_drop_wep;
+       unsigned int tx_handlers_drop_not_assoc;
+       unsigned int tx_handlers_drop_unauth_port;
+       unsigned int rx_handlers_drop;
+       unsigned int rx_handlers_queued;
+       unsigned int rx_handlers_drop_nullfunc;
+       unsigned int rx_handlers_drop_defrag;
+       unsigned int rx_handlers_drop_short;
+       unsigned int rx_handlers_drop_passive_scan;
+       unsigned int tx_expand_skb_head;
+       unsigned int tx_expand_skb_head_cloned;
+       unsigned int rx_expand_skb_head;
+       unsigned int rx_expand_skb_head2;
+       unsigned int rx_handlers_fragments;
+       unsigned int tx_status_drop;
+       unsigned int wme_rx_queue[NUM_RX_DATA_QUEUES];
+       unsigned int wme_tx_queue[NUM_RX_DATA_QUEUES];
+#define I802_DEBUG_INC(c) (c)++
+#else /* CONFIG_MAC80211_DEBUG_COUNTERS */
+#define I802_DEBUG_INC(c) do { } while (0)
+#endif /* CONFIG_MAC80211_DEBUG_COUNTERS */
+
+
+       int default_wep_only; /* only default WEP keys are used with this
+                              * interface; this is used to decide when hwaccel
+                              * can be used with default keys */
+       int total_ps_buffered; /* total number of all buffered unicast and
+                               * multicast packets for power saving stations
+                               */
+       int allow_broadcast_always; /* whether to allow TX of broadcast frames
+                                    * even when there are no associated STAs
+                                    */
+
+       int wifi_wme_noack_test;
+       unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */
+
+       unsigned int enabled_modes; /* bitfield of allowed modes;
+                                     * (1 << MODE_*) */
+       unsigned int hw_modes; /* bitfield of supported hardware modes;
+                               * (1 << MODE_*) */
+
+       int user_space_mlme;
+};
+
+static inline struct ieee80211_local *hw_to_local(
+       struct ieee80211_hw *hw)
+{
+       return container_of(hw, struct ieee80211_local, hw);
+}
+
+static inline struct ieee80211_hw *local_to_hw(
+       struct ieee80211_local *local)
+{
+       return &local->hw;
+}
+
+enum ieee80211_link_state_t {
+       IEEE80211_LINK_STATE_XOFF = 0,
+       IEEE80211_LINK_STATE_PENDING,
+};
+
+struct sta_attribute {
+       struct attribute attr;
+       ssize_t (*show)(const struct sta_info *, char *buf);
+       ssize_t (*store)(struct sta_info *, const char *buf, size_t count);
+};
+
+static inline void __bss_tim_set(struct ieee80211_if_ap *bss, int aid)
+{
+       /*
+        * This format has ben mandated by the IEEE specifications,
+        * so this line may not be changed to use the __set_bit() format.
+        */
+       bss->tim[(aid)/8] |= 1<<((aid) % 8);
+}
+
+static inline void bss_tim_set(struct ieee80211_local *local,
+                              struct ieee80211_if_ap *bss, int aid)
+{
+       spin_lock_bh(&local->sta_lock);
+       __bss_tim_set(bss, aid);
+       spin_unlock_bh(&local->sta_lock);
+}
+
+static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, int aid)
+{
+       /*
+        * This format has ben mandated by the IEEE specifications,
+        * so this line may not be changed to use the __clear_bit() format.
+        */
+       bss->tim[(aid)/8] &= !(1<<((aid) % 8));
+}
+
+static inline void bss_tim_clear(struct ieee80211_local *local,
+                                struct ieee80211_if_ap *bss, int aid)
+{
+       spin_lock_bh(&local->sta_lock);
+       __bss_tim_clear(bss, aid);
+       spin_unlock_bh(&local->sta_lock);
+}
+
+/**
+ * ieee80211_is_erp_rate - Check if a rate is an ERP rate
+ * @phymode: The PHY-mode for this rate (MODE_IEEE80211...)
+ * @rate: Transmission rate to check, in 100 kbps
+ *
+ * Check if a given rate is an Extended Rate PHY (ERP) rate.
+ */
+static inline int ieee80211_is_erp_rate(int phymode, int rate)
+{
+       if (phymode == MODE_IEEE80211G) {
+               if (rate != 10 && rate != 20 &&
+                   rate != 55 && rate != 110)
+                       return 1;
+       }
+       return 0;
+}
+
+/* ieee80211.c */
+int ieee80211_hw_config(struct ieee80211_local *local);
+int ieee80211_if_config(struct net_device *dev);
+int ieee80211_if_config_beacon(struct net_device *dev);
+struct ieee80211_key_conf *
+ieee80211_key_data2conf(struct ieee80211_local *local,
+                       const struct ieee80211_key *data);
+struct ieee80211_key *ieee80211_key_alloc(struct ieee80211_sub_if_data *sdata,
+                                         int idx, size_t key_len, gfp_t flags);
+void ieee80211_key_free(struct ieee80211_key *key);
+void ieee80211_rx_mgmt(struct ieee80211_local *local, struct sk_buff *skb,
+                      struct ieee80211_rx_status *status, u32 msg_type);
+void ieee80211_prepare_rates(struct ieee80211_local *local,
+                            struct ieee80211_hw_mode *mode);
+void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx);
+int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr);
+void ieee80211_if_setup(struct net_device *dev);
+void ieee80211_if_mgmt_setup(struct net_device *dev);
+int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
+                                const char *name);
+struct net_device_stats *ieee80211_dev_stats(struct net_device *dev);
+
+/* ieee80211_ioctl.c */
+extern const struct iw_handler_def ieee80211_iw_handler_def;
+
+void ieee80211_update_default_wep_only(struct ieee80211_local *local);
+
+
+/* Least common multiple of the used rates (in 100 kbps). This is used to
+ * calculate rate_inv values for each rate so that only integers are needed. */
+#define CHAN_UTIL_RATE_LCM 95040
+/* 1 usec is 1/8 * (95040/10) = 1188 */
+#define CHAN_UTIL_PER_USEC 1188
+/* Amount of bits to shift the result right to scale the total utilization
+ * to values that will not wrap around 32-bit integers. */
+#define CHAN_UTIL_SHIFT 9
+/* Theoretical maximum of channel utilization counter in 10 ms (stat_time=1):
+ * (CHAN_UTIL_PER_USEC * 10000) >> CHAN_UTIL_SHIFT = 23203. So dividing the
+ * raw value with about 23 should give utilization in 10th of a percentage
+ * (1/1000). However, utilization is only estimated and not all intervals
+ * between frames etc. are calculated. 18 seems to give numbers that are closer
+ * to the real maximum. */
+#define CHAN_UTIL_PER_10MS 18
+#define CHAN_UTIL_HDR_LONG (202 * CHAN_UTIL_PER_USEC)
+#define CHAN_UTIL_HDR_SHORT (40 * CHAN_UTIL_PER_USEC)
+
+
+/* ieee80211_ioctl.c */
+int ieee80211_set_compression(struct ieee80211_local *local,
+                             struct net_device *dev, struct sta_info *sta);
+int ieee80211_init_client(struct net_device *dev);
+int ieee80211_set_channel(struct ieee80211_local *local, int channel, int freq);
+/* ieee80211_sta.c */
+void ieee80211_sta_timer(unsigned long data);
+void ieee80211_sta_work(struct work_struct *work);
+void ieee80211_sta_scan_work(struct work_struct *work);
+void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
+                          struct ieee80211_rx_status *rx_status);
+int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len);
+int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len);
+int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid);
+int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len);
+void ieee80211_sta_req_auth(struct net_device *dev,
+                           struct ieee80211_if_sta *ifsta);
+int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len);
+void ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
+                          struct ieee80211_rx_status *rx_status);
+void ieee80211_rx_bss_list_init(struct net_device *dev);
+void ieee80211_rx_bss_list_deinit(struct net_device *dev);
+int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len);
+struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
+                                        struct sk_buff *skb, u8 *bssid,
+                                        u8 *addr);
+int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason);
+int ieee80211_sta_disassociate(struct net_device *dev, u16 reason);
+
+/* ieee80211_iface.c */
+int ieee80211_if_add(struct net_device *dev, const char *name,
+                    struct net_device **new_dev, int type);
+void ieee80211_if_set_type(struct net_device *dev, int type);
+void ieee80211_if_reinit(struct net_device *dev);
+void __ieee80211_if_del(struct ieee80211_local *local,
+                       struct ieee80211_sub_if_data *sdata);
+int ieee80211_if_remove(struct net_device *dev, const char *name, int id);
+void ieee80211_if_free(struct net_device *dev);
+void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata);
+int ieee80211_if_add_mgmt(struct ieee80211_local *local);
+void ieee80211_if_del_mgmt(struct ieee80211_local *local);
+
+/* for wiphy privid */
+extern void *mac80211_wiphy_privid;
+
+#endif /* IEEE80211_I_H */
diff --git a/net/mac80211/ieee80211_iface.c b/net/mac80211/ieee80211_iface.c
new file mode 100644 (file)
index 0000000..64267d4
--- /dev/null
@@ -0,0 +1,344 @@
+/*
+ * Copyright 2002-2005, Instant802 Networks, Inc.
+ * Copyright 2005-2006, Devicescape Software, Inc.
+ * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/kernel.h>
+#include <linux/if_arp.h>
+#include <linux/netdevice.h>
+#include <linux/rtnetlink.h>
+#include <net/mac80211.h>
+#include "ieee80211_i.h"
+#include "sta_info.h"
+
+void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata)
+{
+       int i;
+
+       /* Default values for sub-interface parameters */
+       sdata->drop_unencrypted = 0;
+       sdata->eapol = 1;
+       for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
+               skb_queue_head_init(&sdata->fragments[i].skb_list);
+}
+
+static void ieee80211_if_sdata_deinit(struct ieee80211_sub_if_data *sdata)
+{
+       int i;
+
+       for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
+               __skb_queue_purge(&sdata->fragments[i].skb_list);
+       }
+}
+
+/* Must be called with rtnl lock held. */
+int ieee80211_if_add(struct net_device *dev, const char *name,
+                    struct net_device **new_dev, int type)
+{
+       struct net_device *ndev;
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_sub_if_data *sdata = NULL;
+       int ret;
+
+       ASSERT_RTNL();
+       ndev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
+                           name, ieee80211_if_setup);
+       if (!ndev)
+               return -ENOMEM;
+
+       ret = dev_alloc_name(ndev, ndev->name);
+       if (ret < 0)
+               goto fail;
+
+       memcpy(ndev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
+       ndev->base_addr = dev->base_addr;
+       ndev->irq = dev->irq;
+       ndev->mem_start = dev->mem_start;
+       ndev->mem_end = dev->mem_end;
+       SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy));
+
+       sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
+       ndev->ieee80211_ptr = &sdata->wdev;
+       sdata->wdev.wiphy = local->hw.wiphy;
+       sdata->type = IEEE80211_IF_TYPE_AP;
+       sdata->dev = ndev;
+       sdata->local = local;
+       ieee80211_if_sdata_init(sdata);
+
+       ret = register_netdevice(ndev);
+       if (ret)
+               goto fail;
+
+       ieee80211_if_set_type(ndev, type);
+
+       write_lock_bh(&local->sub_if_lock);
+       if (unlikely(local->reg_state == IEEE80211_DEV_UNREGISTERED)) {
+               write_unlock_bh(&local->sub_if_lock);
+               __ieee80211_if_del(local, sdata);
+               return -ENODEV;
+       }
+       list_add(&sdata->list, &local->sub_if_list);
+       if (new_dev)
+               *new_dev = ndev;
+       write_unlock_bh(&local->sub_if_lock);
+
+       ieee80211_update_default_wep_only(local);
+
+       return 0;
+
+fail:
+       free_netdev(ndev);
+       return ret;
+}
+
+int ieee80211_if_add_mgmt(struct ieee80211_local *local)
+{
+       struct net_device *ndev;
+       struct ieee80211_sub_if_data *nsdata;
+       int ret;
+
+       ASSERT_RTNL();
+
+       ndev = alloc_netdev(sizeof(struct ieee80211_sub_if_data), "wmgmt%d",
+                           ieee80211_if_mgmt_setup);
+       if (!ndev)
+               return -ENOMEM;
+       ret = dev_alloc_name(ndev, ndev->name);
+       if (ret < 0)
+               goto fail;
+
+       memcpy(ndev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
+       SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy));
+
+       nsdata = IEEE80211_DEV_TO_SUB_IF(ndev);
+       ndev->ieee80211_ptr = &nsdata->wdev;
+       nsdata->wdev.wiphy = local->hw.wiphy;
+       nsdata->type = IEEE80211_IF_TYPE_MGMT;
+       nsdata->dev = ndev;
+       nsdata->local = local;
+       ieee80211_if_sdata_init(nsdata);
+
+       ret = register_netdevice(ndev);
+       if (ret)
+               goto fail;
+
+       if (local->open_count > 0)
+               dev_open(ndev);
+       local->apdev = ndev;
+       return 0;
+
+fail:
+       free_netdev(ndev);
+       return ret;
+}
+
+void ieee80211_if_del_mgmt(struct ieee80211_local *local)
+{
+       struct net_device *apdev;
+
+       ASSERT_RTNL();
+       apdev = local->apdev;
+       local->apdev = NULL;
+       unregister_netdevice(apdev);
+}
+
+void ieee80211_if_set_type(struct net_device *dev, int type)
+{
+       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+
+       sdata->type = type;
+       switch (type) {
+       case IEEE80211_IF_TYPE_WDS:
+               sdata->bss = NULL;
+               break;
+       case IEEE80211_IF_TYPE_VLAN:
+               break;
+       case IEEE80211_IF_TYPE_AP:
+               sdata->u.ap.dtim_period = 2;
+               sdata->u.ap.force_unicast_rateidx = -1;
+               sdata->u.ap.max_ratectrl_rateidx = -1;
+               skb_queue_head_init(&sdata->u.ap.ps_bc_buf);
+               sdata->bss = &sdata->u.ap;
+               break;
+       case IEEE80211_IF_TYPE_STA:
+       case IEEE80211_IF_TYPE_IBSS: {
+               struct ieee80211_sub_if_data *msdata;
+               struct ieee80211_if_sta *ifsta;
+
+               ifsta = &sdata->u.sta;
+               INIT_WORK(&ifsta->work, ieee80211_sta_work);
+               setup_timer(&ifsta->timer, ieee80211_sta_timer,
+                           (unsigned long) sdata);
+               skb_queue_head_init(&ifsta->skb_queue);
+
+               ifsta->capab = WLAN_CAPABILITY_ESS;
+               ifsta->auth_algs = IEEE80211_AUTH_ALG_OPEN |
+                       IEEE80211_AUTH_ALG_SHARED_KEY;
+               ifsta->create_ibss = 1;
+               ifsta->wmm_enabled = 1;
+               ifsta->auto_channel_sel = 1;
+               ifsta->auto_bssid_sel = 1;
+
+               msdata = IEEE80211_DEV_TO_SUB_IF(sdata->local->mdev);
+               sdata->bss = &msdata->u.ap;
+               break;
+       }
+       case IEEE80211_IF_TYPE_MNTR:
+               dev->type = ARPHRD_IEEE80211_RADIOTAP;
+               break;
+       default:
+               printk(KERN_WARNING "%s: %s: Unknown interface type 0x%x",
+                      dev->name, __FUNCTION__, type);
+       }
+       ieee80211_update_default_wep_only(local);
+}
+
+/* Must be called with rtnl lock held. */
+void ieee80211_if_reinit(struct net_device *dev)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+       struct sta_info *sta;
+       int i;
+
+       ASSERT_RTNL();
+       ieee80211_if_sdata_deinit(sdata);
+       for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
+               if (!sdata->keys[i])
+                       continue;
+#if 0
+               /* The interface is down at the moment, so there is not
+                * really much point in disabling the keys at this point. */
+               memset(addr, 0xff, ETH_ALEN);
+               if (local->ops->set_key)
+                       local->ops->set_key(local_to_hw(local), DISABLE_KEY, addr,
+                                           local->keys[i], 0);
+#endif
+               ieee80211_key_free(sdata->keys[i]);
+               sdata->keys[i] = NULL;
+       }
+
+       switch (sdata->type) {
+       case IEEE80211_IF_TYPE_AP: {
+               /* Remove all virtual interfaces that use this BSS
+                * as their sdata->bss */
+               struct ieee80211_sub_if_data *tsdata, *n;
+               LIST_HEAD(tmp_list);
+
+               write_lock_bh(&local->sub_if_lock);
+               list_for_each_entry_safe(tsdata, n, &local->sub_if_list, list) {
+                       if (tsdata != sdata && tsdata->bss == &sdata->u.ap) {
+                               printk(KERN_DEBUG "%s: removing virtual "
+                                      "interface %s because its BSS interface"
+                                      " is being removed\n",
+                                      sdata->dev->name, tsdata->dev->name);
+                               list_move_tail(&tsdata->list, &tmp_list);
+                       }
+               }
+               write_unlock_bh(&local->sub_if_lock);
+
+               list_for_each_entry_safe(tsdata, n, &tmp_list, list)
+                       __ieee80211_if_del(local, tsdata);
+
+               kfree(sdata->u.ap.beacon_head);
+               kfree(sdata->u.ap.beacon_tail);
+               kfree(sdata->u.ap.generic_elem);
+
+               if (dev != local->mdev) {
+                       struct sk_buff *skb;
+                       while ((skb = skb_dequeue(&sdata->u.ap.ps_bc_buf))) {
+                               local->total_ps_buffered--;
+                               dev_kfree_skb(skb);
+                       }
+               }
+
+               break;
+       }
+       case IEEE80211_IF_TYPE_WDS:
+               sta = sta_info_get(local, sdata->u.wds.remote_addr);
+               if (sta) {
+                       sta_info_put(sta);
+                       sta_info_free(sta, 0);
+               } else {
+#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
+                       printk(KERN_DEBUG "%s: Someone had deleted my STA "
+                              "entry for the WDS link\n", dev->name);
+#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
+               }
+               break;
+       case IEEE80211_IF_TYPE_STA:
+       case IEEE80211_IF_TYPE_IBSS:
+               kfree(sdata->u.sta.extra_ie);
+               sdata->u.sta.extra_ie = NULL;
+               kfree(sdata->u.sta.assocreq_ies);
+               sdata->u.sta.assocreq_ies = NULL;
+               kfree(sdata->u.sta.assocresp_ies);
+               sdata->u.sta.assocresp_ies = NULL;
+               if (sdata->u.sta.probe_resp) {
+                       dev_kfree_skb(sdata->u.sta.probe_resp);
+                       sdata->u.sta.probe_resp = NULL;
+               }
+
+               break;
+       case IEEE80211_IF_TYPE_MNTR:
+               dev->type = ARPHRD_ETHER;
+               break;
+       }
+
+       /* remove all STAs that are bound to this virtual interface */
+       sta_info_flush(local, dev);
+
+       memset(&sdata->u, 0, sizeof(sdata->u));
+       ieee80211_if_sdata_init(sdata);
+}
+
+/* Must be called with rtnl lock held. */
+void __ieee80211_if_del(struct ieee80211_local *local,
+                       struct ieee80211_sub_if_data *sdata)
+{
+       struct net_device *dev = sdata->dev;
+
+       unregister_netdevice(dev);
+       /* Except master interface, the net_device will be freed by
+        * net_device->destructor (i. e. ieee80211_if_free). */
+}
+
+/* Must be called with rtnl lock held. */
+int ieee80211_if_remove(struct net_device *dev, const char *name, int id)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_sub_if_data *sdata, *n;
+
+       ASSERT_RTNL();
+
+       write_lock_bh(&local->sub_if_lock);
+       list_for_each_entry_safe(sdata, n, &local->sub_if_list, list) {
+               if ((sdata->type == id || id == -1) &&
+                   strcmp(name, sdata->dev->name) == 0 &&
+                   sdata->dev != local->mdev) {
+                       list_del(&sdata->list);
+                       write_unlock_bh(&local->sub_if_lock);
+                       __ieee80211_if_del(local, sdata);
+                       ieee80211_update_default_wep_only(local);
+                       return 0;
+               }
+       }
+       write_unlock_bh(&local->sub_if_lock);
+       return -ENODEV;
+}
+
+void ieee80211_if_free(struct net_device *dev)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+
+       /* local->apdev must be NULL when freeing management interface */
+       BUG_ON(dev == local->apdev);
+       ieee80211_if_sdata_deinit(sdata);
+       free_netdev(dev);
+}
diff --git a/net/mac80211/ieee80211_ioctl.c b/net/mac80211/ieee80211_ioctl.c
new file mode 100644 (file)
index 0000000..73909ec
--- /dev/null
@@ -0,0 +1,1806 @@
+/*
+ * Copyright 2002-2005, Instant802 Networks, Inc.
+ * Copyright 2005-2006, Devicescape Software, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/netdevice.h>
+#include <linux/types.h>
+#include <linux/slab.h>
+#include <linux/skbuff.h>
+#include <linux/etherdevice.h>
+#include <linux/if_arp.h>
+#include <linux/wireless.h>
+#include <net/iw_handler.h>
+#include <asm/uaccess.h>
+
+#include <net/mac80211.h>
+#include "ieee80211_i.h"
+#include "hostapd_ioctl.h"
+#include "ieee80211_rate.h"
+#include "wpa.h"
+#include "aes_ccm.h"
+
+static int ieee80211_regdom = 0x10; /* FCC */
+module_param(ieee80211_regdom, int, 0444);
+MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain; 64=MKK");
+
+/*
+ * If firmware is upgraded by the vendor, additional channels can be used based
+ * on the new Japanese regulatory rules. This is indicated by setting
+ * ieee80211_japan_5ghz module parameter to one when loading the 80211 kernel
+ * module.
+ */
+static int ieee80211_japan_5ghz /* = 0 */;
+module_param(ieee80211_japan_5ghz, int, 0444);
+MODULE_PARM_DESC(ieee80211_japan_5ghz, "Vendor-updated firmware for 5 GHz");
+
+static void ieee80211_set_hw_encryption(struct net_device *dev,
+                                       struct sta_info *sta, u8 addr[ETH_ALEN],
+                                       struct ieee80211_key *key)
+{
+       struct ieee80211_key_conf *keyconf = NULL;
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+
+       /* default to sw encryption; this will be cleared by low-level
+        * driver if the hw supports requested encryption */
+       if (key)
+               key->force_sw_encrypt = 1;
+
+       if (key && local->ops->set_key &&
+           (keyconf = ieee80211_key_data2conf(local, key))) {
+               if (local->ops->set_key(local_to_hw(local), SET_KEY, addr,
+                                      keyconf, sta ? sta->aid : 0)) {
+                       key->force_sw_encrypt = 1;
+                       key->hw_key_idx = HW_KEY_IDX_INVALID;
+               } else {
+                       key->force_sw_encrypt =
+                               !!(keyconf->flags & IEEE80211_KEY_FORCE_SW_ENCRYPT);
+                       key->hw_key_idx =
+                               keyconf->hw_key_idx;
+
+               }
+       }
+       kfree(keyconf);
+}
+
+
+static int ieee80211_set_encryption(struct net_device *dev, u8 *sta_addr,
+                                   int idx, int alg, int set_tx_key,
+                                   const u8 *_key, size_t key_len)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       int ret = 0;
+       struct sta_info *sta;
+       struct ieee80211_key *key, *old_key;
+       int try_hwaccel = 1;
+       struct ieee80211_key_conf *keyconf;
+       struct ieee80211_sub_if_data *sdata;
+
+       sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+
+       if (is_broadcast_ether_addr(sta_addr)) {
+               sta = NULL;
+               if (idx >= NUM_DEFAULT_KEYS) {
+                       printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
+                              dev->name, idx);
+                       return -EINVAL;
+               }
+               key = sdata->keys[idx];
+
+               /* TODO: consider adding hwaccel support for these; at least
+                * Atheros key cache should be able to handle this since AP is
+                * only transmitting frames with default keys. */
+               /* FIX: hw key cache can be used when only one virtual
+                * STA is associated with each AP. If more than one STA
+                * is associated to the same AP, software encryption
+                * must be used. This should be done automatically
+                * based on configured station devices. For the time
+                * being, this can be only set at compile time. */
+       } else {
+               set_tx_key = 0;
+               if (idx != 0) {
+                       printk(KERN_DEBUG "%s: set_encrypt - non-zero idx for "
+                              "individual key\n", dev->name);
+                       return -EINVAL;
+               }
+
+               sta = sta_info_get(local, sta_addr);
+               if (!sta) {
+#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
+                       printk(KERN_DEBUG "%s: set_encrypt - unknown addr "
+                              MAC_FMT "\n",
+                              dev->name, MAC_ARG(sta_addr));
+#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
+
+                       return -ENOENT;
+               }
+
+               key = sta->key;
+       }
+
+       /* FIX:
+        * Cannot configure default hwaccel keys with WEP algorithm, if
+        * any of the virtual interfaces is using static WEP
+        * configuration because hwaccel would otherwise try to decrypt
+        * these frames.
+        *
+        * For now, just disable WEP hwaccel for broadcast when there is
+        * possibility of conflict with default keys. This can maybe later be
+        * optimized by using non-default keys (at least with Atheros ar521x).
+        */
+       if (!sta && alg == ALG_WEP && !local->default_wep_only &&
+           sdata->type != IEEE80211_IF_TYPE_IBSS &&
+           sdata->type != IEEE80211_IF_TYPE_AP) {
+               try_hwaccel = 0;
+       }
+
+       if (local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP) {
+               /* Software encryption cannot be used with devices that hide
+                * encryption from the host system, so always try to use
+                * hardware acceleration with such devices. */
+               try_hwaccel = 1;
+       }
+
+       if ((local->hw.flags & IEEE80211_HW_NO_TKIP_WMM_HWACCEL) &&
+           alg == ALG_TKIP) {
+               if (sta && (sta->flags & WLAN_STA_WME)) {
+               /* Hardware does not support hwaccel with TKIP when using WMM.
+                */
+                       try_hwaccel = 0;
+               }
+               else if (sdata->type == IEEE80211_IF_TYPE_STA) {
+                       sta = sta_info_get(local, sdata->u.sta.bssid);
+                       if (sta) {
+                               if (sta->flags & WLAN_STA_WME) {
+                                       try_hwaccel = 0;
+                               }
+                               sta_info_put(sta);
+                               sta = NULL;
+                       }
+               }
+       }
+
+       if (alg == ALG_NONE) {
+               keyconf = NULL;
+               if (try_hwaccel && key &&
+                   key->hw_key_idx != HW_KEY_IDX_INVALID &&
+                   local->ops->set_key &&
+                   (keyconf = ieee80211_key_data2conf(local, key)) != NULL &&
+                   local->ops->set_key(local_to_hw(local), DISABLE_KEY,
+                                      sta_addr, keyconf, sta ? sta->aid : 0)) {
+                       printk(KERN_DEBUG "%s: set_encrypt - low-level disable"
+                              " failed\n", dev->name);
+                       ret = -EINVAL;
+               }
+               kfree(keyconf);
+
+               if (set_tx_key || sdata->default_key == key)
+                       sdata->default_key = NULL;
+               if (sta)
+                       sta->key = NULL;
+               else
+                       sdata->keys[idx] = NULL;
+               ieee80211_key_free(key);
+               key = NULL;
+       } else {
+               old_key = key;
+               key = ieee80211_key_alloc(sta ? NULL : sdata, idx, key_len,
+                                         GFP_KERNEL);
+               if (!key) {
+                       ret = -ENOMEM;
+                       goto err_out;
+               }
+
+               /* default to sw encryption; low-level driver sets these if the
+                * requested encryption is supported */
+               key->hw_key_idx = HW_KEY_IDX_INVALID;
+               key->force_sw_encrypt = 1;
+
+               key->alg = alg;
+               key->keyidx = idx;
+               key->keylen = key_len;
+               memcpy(key->key, _key, key_len);
+               if (set_tx_key)
+                       key->default_tx_key = 1;
+
+               if (alg == ALG_CCMP) {
+                       /* Initialize AES key state here as an optimization
+                        * so that it does not need to be initialized for every
+                        * packet. */
+                       key->u.ccmp.tfm = ieee80211_aes_key_setup_encrypt(
+                               key->key);
+                       if (!key->u.ccmp.tfm) {
+                               ret = -ENOMEM;
+                               goto err_free;
+                       }
+               }
+
+               if (set_tx_key || sdata->default_key == old_key)
+                       sdata->default_key = NULL;
+               if (sta)
+                       sta->key = key;
+               else
+                       sdata->keys[idx] = key;
+               ieee80211_key_free(old_key);
+
+               if (try_hwaccel &&
+                   (alg == ALG_WEP || alg == ALG_TKIP || alg == ALG_CCMP))
+                       ieee80211_set_hw_encryption(dev, sta, sta_addr, key);
+       }
+
+       if (set_tx_key || (!sta && !sdata->default_key && key)) {
+               sdata->default_key = key;
+
+               if (local->ops->set_key_idx &&
+                   local->ops->set_key_idx(local_to_hw(local), idx))
+                       printk(KERN_DEBUG "%s: failed to set TX key idx for "
+                              "low-level driver\n", dev->name);
+       }
+
+       if (sta)
+               sta_info_put(sta);
+
+       return 0;
+
+err_free:
+       ieee80211_key_free(key);
+err_out:
+       if (sta)
+               sta_info_put(sta);
+       return ret;
+}
+
+static int ieee80211_ioctl_siwgenie(struct net_device *dev,
+                                   struct iw_request_info *info,
+                                   struct iw_point *data, char *extra)
+{
+       struct ieee80211_sub_if_data *sdata;
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+
+       if (local->user_space_mlme)
+               return -EOPNOTSUPP;
+
+       sdata = IEEE80211_DEV_TO_SUB_IF(dev);
+       if (sdata->type == IEEE80211_IF_TYPE_STA ||
+           sdata->type == IEEE80211_IF_TYPE_IBSS) {
+               int ret = ieee80211_sta_set_extra_ie(dev, extra, data->length);
+               if (ret)
+                       return ret;
+               sdata->u.sta.auto_bssid_sel = 0;
+               ieee80211_sta_req_auth(dev, &sdata->u.sta);
+               return 0;
+       }
+
+       if (sdata->type == IEEE80211_IF_TYPE_AP) {
+               kfree(sdata->u.ap.generic_elem);
+               sdata->u.ap.generic_elem = kmalloc(data->length, GFP_KERNEL);
+               if (!sdata->u.ap.generic_elem)
+                       return -ENOMEM;
+               memcpy(sdata->u.ap.generic_elem, extra, data->length);
+               sdata->u.ap.generic_elem_len = data->length;
+               return ieee80211_if_config(dev);
+       }
+       return -EOPNOTSUPP;
+}
+
+static int ieee80211_ioctl_set_radio_enabled(struct net_device *dev,
+                                            int val)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+       struct ieee80211_conf *conf = &local->hw.conf;
+
+       conf->radio_enabled = val;
+       return ieee80211_hw_config(wdev_priv(dev->ieee80211_ptr));
+}
+
+static int ieee80211_ioctl_giwname(struct net_device *dev,
+                                  struct iw_request_info *info,
+                                  char *name, char *extra)
+{
+       struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
+
+       switch (local->hw.conf.phymode) {
+       case MODE_IEEE80211A:
+               strcpy(name, "IEEE 802.11a");
+               break;
+       case MODE_IEEE80211B:
+               strcpy(name, "IEEE 802.11b");
+               break;
+       case MODE_IEEE80211G:
+               strcpy(name, "IEEE 802.11g");
+               break;
+       case MODE_ATHEROS_TURBO:
+               strcpy(name, "5GHz Turbo");
+               break;
+       default:
+               strcpy(name, "IEEE 802.11");
+               break;
+       }
+
+       return 0;
+}
+
+
+static int ieee80211_ioctl_giwrange(struct net_device *dev,
+                   &n