Commit 370121e5 authored by Johannes Berg's avatar Johannes Berg Committed by John W. Linville

[PATCH] wireless: Add softmac layer to the kernel

Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 1c2e0275
#ifndef IEEE80211SOFTMAC_H_
#define IEEE80211SOFTMAC_H_
#include <linux/kernel.h>
#include <linux/spinlock.h>
#include <linux/workqueue.h>
#include <linux/list.h>
#include <net/ieee80211.h>
/* Once the API is considered more or less stable,
* this should be incremented on API incompatible changes.
*/
#define IEEE80211SOFTMAC_API 0
#define IEEE80211SOFTMAC_MAX_RATES_LEN 8
#define IEEE80211SOFTMAC_MAX_EX_RATES_LEN 255
struct ieee80211softmac_ratesinfo {
u8 count;
u8 rates[IEEE80211SOFTMAC_MAX_RATES_LEN + IEEE80211SOFTMAC_MAX_EX_RATES_LEN];
};
/* internal structures */
struct ieee80211softmac_network;
struct ieee80211softmac_scaninfo;
struct ieee80211softmac_essid {
u8 len;
char data[IW_ESSID_MAX_SIZE+1];
};
struct ieee80211softmac_wpa {
char *IE;
int IElen;
int IEbuflen;
};
/*
* Information about association
*
* Do we need a lock for this?
* We only ever use this structure inlined
* into our global struct. I've used its lock,
* but maybe we need a local one here?
*/
struct ieee80211softmac_assoc_info {
/*
* This is the requested ESSID. It is written
* only by the WX handlers.
*
*/
struct ieee80211softmac_essid req_essid;
/*
* the ESSID of the network we're currently
* associated (or trying) to. This is
* updated to the network's actual ESSID
* even if the requested ESSID was 'ANY'
*/
struct ieee80211softmac_essid associate_essid;
/* BSSID we're trying to associate to */
char bssid[ETH_ALEN];
/* some flags.
* static_essid is valid if the essid is constant,
* this is for use by the wx handlers only.
*
* associating is true, if the network has been
* auth'ed on and we are in the process of associating.
*
* bssvalid is true if we found a matching network
* and saved it's BSSID into the bssid above.
*/
u8 static_essid:1,
associating:1,
bssvalid:1;
/* Scan retries remaining */
int scan_retry;
struct work_struct work;
struct work_struct timeout;
};
enum {
IEEE80211SOFTMAC_AUTH_OPEN_REQUEST = 1,
IEEE80211SOFTMAC_AUTH_OPEN_RESPONSE = 2,
};
enum {
IEEE80211SOFTMAC_AUTH_SHARED_REQUEST = 1,
IEEE80211SOFTMAC_AUTH_SHARED_CHALLENGE = 2,
IEEE80211SOFTMAC_AUTH_SHARED_RESPONSE = 3,
IEEE80211SOFTMAC_AUTH_SHARED_PASS = 4,
};
/* We should make these tunable
* AUTH_TIMEOUT seems really long, but that's what it is in BSD */
#define IEEE80211SOFTMAC_AUTH_TIMEOUT (12 * HZ)
#define IEEE80211SOFTMAC_AUTH_RETRY_LIMIT 5
#define IEEE80211SOFTMAC_ASSOC_SCAN_RETRY_LIMIT 3
struct ieee80211softmac_txrates {
/* The Bit-Rate to be used for multicast frames. */
u8 mcast_rate;
/* The Bit-Rate to be used for multicast fallback
* (If the device supports fallback and hardware-retry)
*/
u8 mcast_fallback;
/* The Bit-Rate to be used for any other (normal) data packet. */
u8 default_rate;
/* The Bit-Rate to be used for default fallback
* (If the device supports fallback and hardware-retry)
*/
u8 default_fallback;
};
/* Bits for txrates_change callback. */
#define IEEE80211SOFTMAC_TXRATECHG_DEFAULT (1 << 0) /* default_rate */
#define IEEE80211SOFTMAC_TXRATECHG_DEFAULT_FBACK (1 << 1) /* default_fallback */
#define IEEE80211SOFTMAC_TXRATECHG_MCAST (1 << 2) /* mcast_rate */
#define IEEE80211SOFTMAC_TXRATECHG_MCAST_FBACK (1 << 3) /* mcast_fallback */
struct ieee80211softmac_device {
/* 802.11 structure for data stuff */
struct ieee80211_device *ieee;
struct net_device *dev;
/* only valid if associated, then holds the Association ID */
u16 association_id;
/* the following methods are callbacks that the driver
* using this framework has to assign
*/
/* always assign these */
void (*set_bssid_filter)(struct net_device *dev, const u8 *bssid);
void (*set_channel)(struct net_device *dev, u8 channel);
/* assign if you need it, informational only */
void (*link_change)(struct net_device *dev);
/* If the hardware can do scanning, assign _all_ three of these callbacks.
* When the scan finishes, call ieee80211softmac_scan_finished().
*/
/* when called, start_scan is guaranteed to not be called again
* until you call ieee80211softmac_scan_finished.
* Return 0 if scanning could start, error otherwise.
* SOFTMAC AUTHORS: don't call this, use ieee80211softmac_start_scan */
int (*start_scan)(struct net_device *dev);
/* this should block until after ieee80211softmac_scan_finished was called
* SOFTMAC AUTHORS: don't call this, use ieee80211softmac_wait_for_scan */
void (*wait_for_scan)(struct net_device *dev);
/* stop_scan aborts a scan, but is asynchronous.
* if you want to wait for it too, use wait_for_scan
* SOFTMAC AUTHORS: don't call this, use ieee80211softmac_stop_scan */
void (*stop_scan)(struct net_device *dev);
/* we'll need something about beacons here too, for AP or ad-hoc modes */
/* Transmission rates to be used by the driver.
* The SoftMAC figures out the best possible rates.
* The driver just needs to read them.
*/
struct ieee80211softmac_txrates txrates;
/* If the driver needs to do stuff on TX rate changes, assign this callback. */
void (*txrates_change)(struct net_device *dev,
u32 changes, /* see IEEE80211SOFTMAC_TXRATECHG flags */
const struct ieee80211softmac_txrates *rates_before_change);
/* private stuff follows */
/* this lock protects this structure */
spinlock_t lock;
/* couple of flags */
u8 scanning:1, /* protects scanning from being done multiple times at once */
associated:1;
/* workquere for scannning, ... */
struct workqueue_struct *workqueue;
struct ieee80211softmac_scaninfo *scaninfo;
struct ieee80211softmac_assoc_info associnfo;
struct list_head auth_queue;
struct list_head events;
struct ieee80211softmac_ratesinfo ratesinfo;
int txrate_badness;
/* WPA stuff */
struct ieee80211softmac_wpa wpa;
/* we need to keep a list of network structs we copied */
struct list_head network_list;
/* This must be the last item so that it points to the data
* allocated beyond this structure by alloc_ieee80211 */
u8 priv[0];
};
extern void ieee80211softmac_scan_finished(struct ieee80211softmac_device *sm);
static inline void * ieee80211softmac_priv(struct net_device *dev)
{
return ((struct ieee80211softmac_device *)ieee80211_priv(dev))->priv;
}
extern struct net_device * alloc_ieee80211softmac(int sizeof_priv);
extern void free_ieee80211softmac(struct net_device *dev);
/* Call this function if you detect a lost TX fragment.
* (If the device indicates failure of ACK RX, for example.)
* It is wise to call this function if you are able to detect lost packets,
* because it contributes to the TX Rates auto adjustment.
*/
extern void ieee80211softmac_fragment_lost(struct net_device *dev,
u16 wireless_sequence_number);
/* Call this function before _start to tell the softmac what rates
* the hw supports. The rates parameter is copied, so you can
* free it right after calling this function.
* Note that the rates need to be sorted. */
extern void ieee80211softmac_set_rates(struct net_device *dev, u8 count, u8 *rates);
/* Start the SoftMAC. Call this after you initialized the device
* and it is ready to run.
*/
extern void ieee80211softmac_start(struct net_device *dev);
/* Stop the SoftMAC. Call this before you shutdown the device. */
extern void ieee80211softmac_stop(struct net_device *dev);
/*
* Event system
*/
/* valid event types */
#define IEEE80211SOFTMAC_EVENT_ANY -1 /*private use only*/
#define IEEE80211SOFTMAC_EVENT_SCAN_FINISHED 0
#define IEEE80211SOFTMAC_EVENT_ASSOCIATED 1
#define IEEE80211SOFTMAC_EVENT_ASSOCIATE_FAILED 2
#define IEEE80211SOFTMAC_EVENT_ASSOCIATE_TIMEOUT 3
#define IEEE80211SOFTMAC_EVENT_AUTHENTICATED 4
#define IEEE80211SOFTMAC_EVENT_AUTH_FAILED 5
#define IEEE80211SOFTMAC_EVENT_AUTH_TIMEOUT 6
#define IEEE80211SOFTMAC_EVENT_ASSOCIATE_NET_NOT_FOUND 7
/* keep this updated! */
#define IEEE80211SOFTMAC_EVENT_LAST 7
/*
* If you want to be notified of certain events, you can call
* ieee80211softmac_notify[_atomic] with
* - event set to one of the constants below
* - fun set to a function pointer of the appropriate type
* - context set to the context data you want passed
* The return value is 0, or an error.
*/
typedef void (*notify_function_ptr)(struct net_device *dev, void *context);
#define ieee80211softmac_notify(dev, event, fun, context) ieee80211softmac_notify_gfp(dev, event, fun, context, GFP_KERNEL);
#define ieee80211softmac_notify_atomic(dev, event, fun, context) ieee80211softmac_notify_gfp(dev, event, fun, context, GFP_ATOMIC);
extern int ieee80211softmac_notify_gfp(struct net_device *dev,
int event, notify_function_ptr fun, void *context, gfp_t gfp_mask);
/* To clear pending work (for ifconfig down, etc.) */
extern void
ieee80211softmac_clear_pending_work(struct ieee80211softmac_device *sm);
#endif /* IEEE80211SOFTMAC_H_ */
#ifndef _IEEE80211SOFTMAC_WX_H
#define _IEEE80211SOFTMAC_WX_H
#include <net/ieee80211softmac.h>
#include <net/iw_handler.h>
extern int
ieee80211softmac_wx_trigger_scan(struct net_device *net_dev,
struct iw_request_info *info,
union iwreq_data *data,
char *extra);
extern int
ieee80211softmac_wx_get_scan_results(struct net_device *net_dev,
struct iw_request_info *info,
union iwreq_data *data,
char *extra);
extern int
ieee80211softmac_wx_set_essid(struct net_device *net_dev,
struct iw_request_info *info,
union iwreq_data *data,
char *extra);
extern int
ieee80211softmac_wx_get_essid(struct net_device *net_dev,
struct iw_request_info *info,
union iwreq_data *data,
char *extra);
extern int
ieee80211softmac_wx_set_rate(struct net_device *net_dev,
struct iw_request_info *info,
union iwreq_data *data,
char *extra);
extern int
ieee80211softmac_wx_get_rate(struct net_device *net_dev,
struct iw_request_info *info,
union iwreq_data *data,
char *extra);
extern int
ieee80211softmac_wx_get_wap(struct net_device *net_dev,
struct iw_request_info *info,
union iwreq_data *data,
char *extra);
extern int
ieee80211softmac_wx_set_wap(struct net_device *net_dev,
struct iw_request_info *info,
union iwreq_data *data,
char *extra);
extern int
ieee80211softmac_wx_set_genie(struct net_device *dev,
struct iw_request_info *info,
union iwreq_data *wrqu,
char *extra);
extern int
ieee80211softmac_wx_get_genie(struct net_device *dev,
struct iw_request_info *info,
union iwreq_data *wrqu,
char *extra);
#endif /* _IEEE80211SOFTMAC_WX */
......@@ -66,3 +66,4 @@ config IEEE80211_CRYPT_TKIP
This can be compiled as a modules and it will be called
"ieee80211_crypt_tkip".
source "net/ieee80211/softmac/Kconfig"
config IEEE80211_SOFTMAC
tristate "Software MAC add-on to the IEEE 802.11 networking stack"
---help---
This option enables the hardware independent software MAC addon
for the IEEE 802.11 networking stack.
config IEEE80211_SOFTMAC_DEBUG
bool "Enable full debugging output"
depends on IEEE80211_SOFTMAC
obj-$(CONFIG_IEEE80211_SOFTMAC) := ieee80211softmac.o
ieee80211softmac-objs := \
ieee80211softmac_io.o \
ieee80211softmac_auth.o \
ieee80211softmac_module.o \
ieee80211softmac_scan.o \
ieee80211softmac_wx.o \
ieee80211softmac_assoc.o \
ieee80211softmac_event.o
This diff is collapsed.
This diff is collapsed.
#include "ieee80211softmac_priv.h"
/*
* Event system
* Also see comments in public header file
*
* Each event has associated to it
* - an event type (see constants in public header)
* - an event context (see below)
* - the function to be called
* - a context (extra parameter to call the function with)
* - and the softmac struct
*
* The event context is private and can only be used from
* within this module. Its meaning varies with the event
* type:
* SCAN_FINISHED: no special meaning
* ASSOCIATED,
* ASSOCIATE_FAILED,
* ASSOCIATE_TIMEOUT,
* AUTHENTICATED,
* AUTH_FAILED,
* AUTH_TIMEOUT: a pointer to the network struct
* ...
* Code within this module can use the event context to be only
* called when the event is true for that specific context
* as per above table.
* If the event context is NULL, then the notification is always called,
* regardless of the event context. The event context is not passed to
* the callback, it is assumed that the context suffices.
*
* You can also use the event context only by setting the event type
* to -1 (private use only), in which case you'll be notified
* whenever the event context matches.
*/
static char *event_descriptions[IEEE80211SOFTMAC_EVENT_LAST+1] = {
"scan finished",
"associated",
"associating failed",
"associating timed out",
"authenticated",
"authenticating failed",
"authenticating timed out",
"associating failed because no suitable network was found",
};
static void
ieee80211softmac_notify_callback(void *d)
{
struct ieee80211softmac_event event = *(struct ieee80211softmac_event*) d;
kfree(d);
event.fun(event.mac->dev, event.context);
}
int
ieee80211softmac_notify_internal(struct ieee80211softmac_device *mac,
int event, void *event_context, notify_function_ptr fun, void *context, gfp_t gfp_mask)
{
struct ieee80211softmac_event *eventptr;
unsigned long flags;
if (event < -1 || event > IEEE80211SOFTMAC_EVENT_LAST)
return -ENOSYS;
if (!fun)
return -EINVAL;
eventptr = kmalloc(sizeof(struct ieee80211softmac_event), gfp_mask);
if (!eventptr)
return -ENOMEM;
eventptr->event_type = event;
INIT_WORK(&eventptr->work, ieee80211softmac_notify_callback, eventptr);
eventptr->fun = fun;
eventptr->context = context;
eventptr->mac = mac;
eventptr->event_context = event_context;
spin_lock_irqsave(&mac->lock, flags);
list_add(&eventptr->list, &mac->events);
spin_unlock_irqrestore(&mac->lock, flags);
return 0;
}
int
ieee80211softmac_notify_gfp(struct net_device *dev,
int event, notify_function_ptr fun, void *context, gfp_t gfp_mask)
{
struct ieee80211softmac_device *mac = ieee80211_priv(dev);
if (event < 0 || event > IEEE80211SOFTMAC_EVENT_LAST)
return -ENOSYS;
return ieee80211softmac_notify_internal(mac, event, NULL, fun, context, gfp_mask);
}
EXPORT_SYMBOL_GPL(ieee80211softmac_notify_gfp);
/* private -- calling all callbacks that were specified */
void
ieee80211softmac_call_events_locked(struct ieee80211softmac_device *mac, int event, void *event_ctx)
{
struct ieee80211softmac_event *eventptr, *tmp;
union iwreq_data wrqu;
char *msg;
if (event >= 0) {
msg = event_descriptions[event];
wrqu.data.length = strlen(msg);
wireless_send_event(mac->dev, IWEVCUSTOM, &wrqu, msg);
}
if (!list_empty(&mac->events))
list_for_each_entry_safe(eventptr, tmp, &mac->events, list) {
if ((eventptr->event_type == event || eventptr->event_type == -1)
&& (eventptr->event_context == NULL || eventptr->event_context == event_ctx)) {
list_del(&eventptr->list);
queue_work(mac->workqueue, &eventptr->work);
}
}
}
void
ieee80211softmac_call_events(struct ieee80211softmac_device *mac, int event, void *event_ctx)
{
unsigned long flags;
spin_lock_irqsave(&mac->lock, flags);
ieee80211softmac_call_events_locked(mac, event, event_ctx);
spin_unlock_irqrestore(&mac->lock, flags);
}
This diff is collapsed.
This diff is collapsed.
#ifndef IEEE80211SOFTMAC_PRIV_H_
#define IEEE80211SOFTMAC_PRIV_H_
#include <net/ieee80211softmac.h>
#include <net/ieee80211softmac_wx.h>
#include <linux/kernel.h>
#include <linux/stringify.h>
#define PFX "SoftMAC: "
#ifdef assert
# undef assert
#endif
#ifdef CONFIG_IEEE80211_SOFTMAC_DEBUG
#define assert(expr) \
do { \
if (unlikely(!(expr))) { \
printkl(KERN_ERR PFX "ASSERTION FAILED (%s) at: %s:%d:%s()\n", #expr, \
__FILE__, __LINE__, __FUNCTION__); \
} \
} while (0)
#else
#define assert(expr) do {} while (0)
#endif
/* rate limited printk(). */
#ifdef printkl
# undef printkl
#endif
#define printkl(f, x...) do { if (printk_ratelimit()) printk(f ,##x); } while (0)
/* rate limited printk() for debugging */
#ifdef dprintkl
# undef dprintkl
#endif
#ifdef CONFIG_IEEE80211_SOFTMAC_DEBUG
# define dprintkl printkl
#else
# define dprintkl(f, x...) do { /* nothing */ } while (0)
#endif
/* debugging printk() */
#ifdef dprintk
# undef dprintk
#endif
#ifdef CONFIG_IEEE80211_SOFTMAC_DEBUG
# define dprintk(f, x...) do { printk(f ,##x); } while (0)
#else
# define dprintk(f, x...) do { /* nothing */ } while (0)
#endif
#ifdef function_enter
# undef function_enter
#endif
#ifdef CONFIG_IEEE80211_SOFTMAC_DEBUG
# define function_enter() do { printk(KERN_DEBUG PFX "%s:%d:%s()\n", __FILE__, __LINE__, __FUNCTION__); } while (0)
#else
# define function_enter() do { /* nothing */ } while (0)
#endif
/* private definitions and prototypes */
/*** prototypes from _scan.c */
void ieee80211softmac_scan(void *sm);
/* for internal use if scanning is needed */
int ieee80211softmac_start_scan(struct ieee80211softmac_device *mac);
void ieee80211softmac_stop_scan(struct ieee80211softmac_device *mac);
void ieee80211softmac_wait_for_scan(struct ieee80211softmac_device *mac);
/* for use by _module.c to assign to the callbacks */
int ieee80211softmac_start_scan_implementation(struct net_device *dev);
void ieee80211softmac_stop_scan_implementation(struct net_device *dev);
void ieee80211softmac_wait_for_scan_implementation(struct net_device *dev);
/*** Network prototypes from _module.c */
struct ieee80211softmac_network * ieee80211softmac_create_network(
struct ieee80211softmac_device *mac, struct ieee80211_network *net);
void ieee80211softmac_add_network_locked(struct ieee80211softmac_device *mac,
struct ieee80211softmac_network *net);
void ieee80211softmac_add_network(struct ieee80211softmac_device *mac,
struct ieee80211softmac_network *net);
void ieee80211softmac_del_network_locked(struct ieee80211softmac_device *mac,
struct ieee80211softmac_network *net);
void ieee80211softmac_del_network(struct ieee80211softmac_device *mac,
struct ieee80211softmac_network *net);
struct ieee80211softmac_network * ieee80211softmac_get_network_by_bssid_locked(
struct ieee80211softmac_device *mac, u8 *ea);
struct ieee80211softmac_network * ieee80211softmac_get_network_by_bssid(
struct ieee80211softmac_device *mac, u8 *ea);
struct ieee80211softmac_network * ieee80211softmac_get_network_by_ssid_locked(
struct ieee80211softmac_device *mac, u8 *ssid, u8 ssid_len);
struct ieee80211softmac_network * ieee80211softmac_get_network_by_ssid(
struct ieee80211softmac_device *mac, u8 *ssid, u8 ssid_len);
/* Rates related */
u8 ieee80211softmac_lower_rate_delta(struct ieee80211softmac_device *mac, u8 rate, int delta);
static inline u8 lower_rate(struct ieee80211softmac_device *mac, u8 rate) {
return ieee80211softmac_lower_rate_delta(mac, rate, 1);
}
static inline u8 get_fallback_rate(struct ieee80211softmac_device *mac, u8 rate)
{
return ieee80211softmac_lower_rate_delta(mac, rate, 2);
}
/*** prototypes from _io.c */
int ieee80211softmac_send_mgt_frame(struct ieee80211softmac_device *mac,
void* ptrarg, u32 type, u32 arg);
/*** prototypes from _auth.c */
/* do these have to go into the public header? */
int ieee80211softmac_auth_req(struct ieee80211softmac_device *mac, struct ieee80211softmac_network *net);
int ieee80211softmac_deauth_req(struct ieee80211softmac_device *mac, struct ieee80211softmac_network *net, int reason);
/* for use by _module.c to assign to the callbacks */
int ieee80211softmac_auth_resp(struct net_device *dev, struct ieee80211_auth *auth);
int ieee80211softmac_deauth_resp(struct net_device *dev, struct ieee80211_auth *auth);
/*** prototypes from _assoc.c */
void ieee80211softmac_assoc_work(void *d);
int ieee80211softmac_handle_assoc_response(struct net_device * dev,
struct ieee80211_assoc_response * resp,
struct ieee80211_network * network);
int ieee80211softmac_handle_disassoc(struct net_device * dev,
struct ieee80211_disassoc * disassoc);
void ieee80211softmac_assoc_timeout(void *d);
/* some helper functions */
static inline int ieee80211softmac_scan_handlers_check_self(struct ieee80211softmac_device *sm)
{
return (sm->start_scan == ieee80211softmac_start_scan_implementation) &&
(sm->stop_scan == ieee80211softmac_stop_scan_implementation) &&
(sm->wait_for_scan == ieee80211softmac_wait_for_scan_implementation);
}
static inline int ieee80211softmac_scan_sanity_check(struct ieee80211softmac_device *sm)
{
return ((sm->start_scan != ieee80211softmac_start_scan_implementation) &&
(sm->stop_scan != ieee80211softmac_stop_scan_implementation) &&
(sm->wait_for_scan != ieee80211softmac_wait_for_scan_implementation)
) || ieee80211softmac_scan_handlers_check_self(sm);
}
#define IEEE80211SOFTMAC_PROBE_DELAY HZ/2
#define IEEE80211SOFTMAC_WORKQUEUE_NAME_LEN (17 + IFNAMSIZ)
struct ieee80211softmac_network {
struct list_head list; /* List */
/* Network information copied from ieee80211_network */
u8 bssid[ETH_ALEN];
u8 channel;
struct ieee80211softmac_essid essid;
struct ieee80211softmac_ratesinfo supported_rates;
/* SoftMAC specific */
u16 authenticating:1, /* Status Flags */
authenticated:1,
auth_desynced_once:1;
u16 capabilities; /* Capabilities bitfield */
u8 challenge_len; /* Auth Challenge length */
char *challenge; /* Challenge Text */
};
/* structure used to keep track of networks we're auth'ing to */
struct ieee80211softmac_auth_queue_item {
struct list_head list; /* List head */
struct ieee80211softmac_network *net; /* Network to auth */
struct ieee80211softmac_device *mac; /* SoftMAC device */
u8 retry; /* Retry limit */
u8 state; /* Auth State */
struct work_struct work; /* Work queue */
};
/* scanning information */
struct ieee80211softmac_scaninfo {
u8 current_channel_idx,
number_channels;
struct ieee80211_channel *channels;
u8 started:1,
stop:1;
u8 skip_flags;
struct completion finished;
struct work_struct softmac_scan;
};
/* private event struct */
struct ieee80211softmac_event {
struct list_head list;
int event_type;
void *event_context;
struct work_struct work;
notify_function_ptr fun;
void *context;
struct ieee80211softmac_device *mac;
};
void ieee80211softmac_call_events(struct ieee80211softmac_device *mac, int event, void *event_context);
void ieee80211softmac_call_events_locked(struct ieee80211softmac_device *mac, int event, void *event_context);
int ieee80211softmac_notify_internal(struct ieee80211softmac_device *mac,
int event, void *event_context, notify_function_ptr fun, void *context, gfp_t gfp_mask);
#endif /* IEEE80211SOFTMAC_PRIV_H_ */
/*
* Scanning routines.
*
* These are not exported because they're assigned to the function pointers.
*/
#include <linux/completion.h>
#include "ieee80211softmac_priv.h"
/* internal, use to trigger scanning if needed.
* Returns -EBUSY if already scanning,
* result of start_scan otherwise */
int
ieee80211softmac_start_scan(struct ieee80211softmac_device *sm)
{
unsigned long flags;
int ret;
spin_lock_irqsave(&sm->lock, flags);
if (sm->scanning)
{
spin_unlock_irqrestore(&sm->lock, flags);
return -EINPROGRESS;
}
sm->scanning = 1;
spin_unlock_irqrestore(&sm->lock, flags);
ret = sm->start_scan(sm->dev);
if (ret) {
spin_lock_irqsave(&sm->lock, flags);
sm->scanning = 0;
spin_unlock_irqrestore(&sm->lock, flags);
}
return ret;
}
void
ieee80211softmac_stop_scan(struct ieee80211softmac_device *sm)
{
unsigned long flags;
spin_lock_irqsave(&sm->lock, flags);
if (!sm->scanning) {
spin_unlock_irqrestore(&sm->lock, flags);
return;
}
spin_unlock_irqrestore(&sm->lock, flags);
sm->stop_scan(sm->dev);
}
void
ieee80211softmac_wait_for_scan(struct ieee80211softmac_device *sm)
{
unsigned long flags;
spin_lock_irqsave(&sm->lock, flags);
if (!sm->scanning) {
spin_unlock_irqrestore(&sm->lock, flags);
return;
}
spin_unlock_irqrestore(&sm->lock, flags);
sm->wait_for_scan(sm->dev);
}
/* internal scanning implementation follows */
void ieee80211softmac_scan(void *d)
{
int invalid_channel;
u8 current_channel_idx;
struct ieee80211softmac_device *sm = (struct ieee80211softmac_device *)d;
struct ieee80211softmac_scaninfo *si = sm->scaninfo;
unsigned long flags;
while (!(si->stop) && (si->current_channel_idx < si->number_channels)) {
current_channel_idx = si->current_channel_idx;
si->current_channel_idx++; /* go to the next channel */
invalid_channel = (si->skip_flags & si->channels[current_channel_idx].flags);
if (!invalid_channel) {
sm->set_channel(sm->dev, si->channels[current_channel_idx].channel);
//TODO: Probe the channel
// FIXME make this user configurable (active/passive)
if(ieee80211softmac_send_mgt_frame(sm, NULL, IEEE80211_STYPE_PROBE_REQ, 0))
printkl(KERN_DEBUG PFX "Sending Probe Request Failed\n");
/* also send directed management frame for the network we're looking for */
// TODO: is this if correct, or should we do this only if scanning from assoc request?
if (sm->associnfo.req_essid.len)
ieee80211softmac_send_mgt_frame(sm, &sm->associnfo.req_essid, IEEE80211_STYPE_PROBE_REQ, 0);
queue_delayed_work(sm->workqueue, &si->softmac_scan, IEEE80211SOFTMAC_PROBE_DELAY);
return;
} else {
dprintk(PFX "Not probing Channel %d (not allowed here)\n", si->channels[current_channel_idx].channel);
}
}
spin_lock_irqsave(&sm->lock, flags);
cancel_delayed_work(&si->softmac_scan);
si->started = 0;
spin_unlock_irqrestore(&sm->lock, flags);
dprintk(PFX "Scanning finished\n");
ieee80211softmac_scan_finished(sm);
complete_all(&sm->scaninfo->finished);
}
static inline struct ieee80211softmac_scaninfo *allocate_scaninfo(struct ieee80211softmac_device *mac)
{
/* ugh. can we call this without having the spinlock held? */
struct ieee80211softmac_scaninfo *info = kmalloc(sizeof(struct ieee80211softmac_scaninfo), GFP_ATOMIC);
if (unlikely(!info))
return NULL;
INIT_WORK(&info->softmac_scan, ieee80211softmac_scan, mac);
init_completion(&info->finished);
return info;
}
int ieee80211softmac_start_scan_implementation(struct net_device *dev)
{
struct ieee80211softmac_device *sm = ieee80211_priv(dev);
unsigned long flags;
if (!(dev->flags & IFF_UP))
return -ENODEV;
assert(ieee80211softmac_scan_handlers_check_self(sm));
if (!ieee80211softmac_scan_handlers_check_self(sm))
return -EINVAL;
spin_lock_irqsave(&sm->lock, flags);
/* it looks like we need to hold the lock here
* to make sure we don't allocate two of these... */
if (unlikely(!sm->scaninfo))
sm->scaninfo = allocate_scaninfo(sm);
if (unlikely(!sm->scaninfo)) {
spin_unlock_irqrestore(&sm->lock, flags);
return -ENOMEM;
}
sm->scaninfo->skip_flags = IEEE80211_CH_INVALID;
if (0 /* not scanning in IEEE802.11b */)//TODO
sm->scaninfo->skip_flags |= IEEE80211_CH_B_ONLY;
if (0 /* IEEE802.11a */) {//TODO
sm->scaninfo->channels = sm->ieee->geo.a;
sm->scaninfo->number_channels = sm->ieee->geo.a_channels;
} else {
sm->scaninfo->channels = sm->ieee->geo.bg;
sm->scaninfo->number_channels = sm->ieee->geo.bg_channels;
}
dprintk(PFX "Start scanning with channel: %d\n", sm->scaninfo->channels[0].channel);
dprintk(PFX "Scanning %d channels\n", sm->scaninfo->number_channels);
sm->scaninfo->current_channel_idx = 0;
sm->scaninfo->started = 1;
INIT_COMPLETION(sm->scaninfo->finished);
queue_work(sm->workqueue, &sm->scaninfo->softmac_scan);
spin_unlock_irqrestore(&sm->lock, flags);
return 0;
}
void ieee80211softmac_stop_scan_implementation(struct net_device *dev)
{
struct ieee80211softmac_device *sm = ieee80211_priv(dev);
unsigned long flags;
assert(ieee80211softmac_scan_handlers_check_self(sm));
if (!ieee80211softmac_scan_handlers_check_self(sm))
return;
spin_lock_irqsave(&sm->lock, flags);
assert(sm->scaninfo != NULL);
if (sm->scaninfo) {
if (sm->scaninfo->started)
sm->scaninfo->stop = 1;
else
complete_all(&sm->scaninfo->finished);
}
spin_unlock_irqrestore(&sm->lock, flags);
}
void ieee80211softmac_wait_for_scan_implementation(struct net_device *dev)
{
struct ieee80211softmac_device *sm = ieee80211_priv(dev);
unsigned long flags;
assert(ieee80211softmac_scan_handlers_check_self(sm));
if (!ieee80211softmac_scan_handlers_check_self(sm))
return;
spin_lock_irqsave(&sm->lock, flags);
if (!sm->scaninfo->started) {
spin_unlock_irqrestore(&sm->lock, flags);
return;
}
spin_unlock_irqrestore(&sm->lock, flags);
wait_for_completion(&sm->scaninfo->finished);
}
/* this is what drivers (that do scanning) call when they're done */
void ieee80211softmac_scan_finished(struct ieee80211softmac_device *sm)
{
unsigned long flags;
spin_lock_irqsave(&sm->lock, flags);
sm->scanning = 0;
spin_unlock_irqrestore(&sm->lock, flags);
ieee80211softmac_call_events(sm, IEEE80211SOFTMAC_EVENT_SCAN_FINISHED, NULL);
}
EXPORT_SYMBOL_GPL(ieee80211softmac_scan_finished);
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment