3 * Also see comments in public header file and longer explanation below.
5 * Copyright (c) 2005, 2006 Johannes Berg <johannes@sipsolutions.net>
6 * Joseph Jezak <josejx@gentoo.org>
7 * Larry Finger <Larry.Finger@lwfinger.net>
8 * Danny van Dyk <kugelfang@gentoo.org>
9 * Michael Buesch <mbuesch@freenet.de>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 * The full GNU General Public License is included in this distribution in the
25 * file called COPYING.
28 #include "ieee80211softmac_priv.h"
31 * Each event has associated to it
32 * - an event type (see constants in public header)
33 * - an event context (see below)
34 * - the function to be called
35 * - a context (extra parameter to call the function with)
36 * - and the softmac struct
38 * The event context is private and can only be used from
39 * within this module. Its meaning varies with the event
41 * SCAN_FINISHED: no special meaning
47 * AUTH_TIMEOUT: a pointer to the network struct
49 * Code within this module can use the event context to be only
50 * called when the event is true for that specific context
52 * If the event context is NULL, then the notification is always called,
53 * regardless of the event context. The event context is not passed to
54 * the callback, it is assumed that the context suffices.
56 * You can also use the event context only by setting the event type
57 * to -1 (private use only), in which case you'll be notified
58 * whenever the event context matches.
61 static char *event_descriptions[IEEE80211SOFTMAC_EVENT_LAST+1] = {
65 "associating timed out",
67 "authenticating failed",
68 "authenticating timed out",
69 "associating failed because no suitable network was found",
75 ieee80211softmac_notify_callback(void *d)
77 struct ieee80211softmac_event event = *(struct ieee80211softmac_event*) d;
80 event.fun(event.mac->dev, event.context);
84 ieee80211softmac_notify_internal(struct ieee80211softmac_device *mac,
85 int event, void *event_context, notify_function_ptr fun, void *context, gfp_t gfp_mask)
87 struct ieee80211softmac_event *eventptr;
90 if (event < -1 || event > IEEE80211SOFTMAC_EVENT_LAST)
96 eventptr = kmalloc(sizeof(struct ieee80211softmac_event), gfp_mask);
100 eventptr->event_type = event;
101 INIT_WORK(&eventptr->work, ieee80211softmac_notify_callback, eventptr);
103 eventptr->context = context;
105 eventptr->event_context = event_context;
107 spin_lock_irqsave(&mac->lock, flags);
108 list_add(&eventptr->list, &mac->events);
109 spin_unlock_irqrestore(&mac->lock, flags);
115 ieee80211softmac_notify_gfp(struct net_device *dev,
116 int event, notify_function_ptr fun, void *context, gfp_t gfp_mask)
118 struct ieee80211softmac_device *mac = ieee80211_priv(dev);
120 if (event < 0 || event > IEEE80211SOFTMAC_EVENT_LAST)
123 return ieee80211softmac_notify_internal(mac, event, NULL, fun, context, gfp_mask);
125 EXPORT_SYMBOL_GPL(ieee80211softmac_notify_gfp);
127 /* private -- calling all callbacks that were specified */
129 ieee80211softmac_call_events_locked(struct ieee80211softmac_device *mac, int event, void *event_ctx)
131 struct ieee80211softmac_event *eventptr, *tmp;
132 struct ieee80211softmac_network *network;
135 union iwreq_data wrqu;
140 case IEEE80211SOFTMAC_EVENT_ASSOCIATED:
141 network = (struct ieee80211softmac_network *)event_ctx;
142 wrqu.data.length = 0;
144 memcpy(wrqu.ap_addr.sa_data, &network->bssid[0], ETH_ALEN);
145 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
146 we_event = SIOCGIWAP;
148 case IEEE80211SOFTMAC_EVENT_DISASSOCIATED:
149 wrqu.data.length = 0;
151 memset(&wrqu, '\0', sizeof (union iwreq_data));
152 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
153 we_event = SIOCGIWAP;
155 case IEEE80211SOFTMAC_EVENT_SCAN_FINISHED:
156 wrqu.data.length = 0;
158 memset(&wrqu, '\0', sizeof (union iwreq_data));
159 we_event = SIOCGIWSCAN;
162 msg = event_descriptions[event];
163 wrqu.data.length = strlen(msg);
164 we_event = IWEVCUSTOM;
167 wireless_send_event(mac->dev, we_event, &wrqu, msg);
170 if (!list_empty(&mac->events))
171 list_for_each_entry_safe(eventptr, tmp, &mac->events, list) {
172 if ((eventptr->event_type == event || eventptr->event_type == -1)
173 && (eventptr->event_context == NULL || eventptr->event_context == event_ctx)) {
174 list_del(&eventptr->list);
175 schedule_work(&eventptr->work);
181 ieee80211softmac_call_events(struct ieee80211softmac_device *mac, int event, void *event_ctx)
185 spin_lock_irqsave(&mac->lock, flags);
186 ieee80211softmac_call_events_locked(mac, event, event_ctx);
188 spin_unlock_irqrestore(&mac->lock, flags);