1 #include "ieee80211softmac_priv.h"
5 * Also see comments in public header file
7 * Each event has associated to it
8 * - an event type (see constants in public header)
9 * - an event context (see below)
10 * - the function to be called
11 * - a context (extra parameter to call the function with)
12 * - and the softmac struct
14 * The event context is private and can only be used from
15 * within this module. Its meaning varies with the event
17 * SCAN_FINISHED: no special meaning
23 * AUTH_TIMEOUT: a pointer to the network struct
25 * Code within this module can use the event context to be only
26 * called when the event is true for that specific context
28 * If the event context is NULL, then the notification is always called,
29 * regardless of the event context. The event context is not passed to
30 * the callback, it is assumed that the context suffices.
32 * You can also use the event context only by setting the event type
33 * to -1 (private use only), in which case you'll be notified
34 * whenever the event context matches.
37 static char *event_descriptions[IEEE80211SOFTMAC_EVENT_LAST+1] = {
41 "associating timed out",
43 "authenticating failed",
44 "authenticating timed out",
45 "associating failed because no suitable network was found",
50 ieee80211softmac_notify_callback(void *d)
52 struct ieee80211softmac_event event = *(struct ieee80211softmac_event*) d;
55 event.fun(event.mac->dev, event.context);
59 ieee80211softmac_notify_internal(struct ieee80211softmac_device *mac,
60 int event, void *event_context, notify_function_ptr fun, void *context, gfp_t gfp_mask)
62 struct ieee80211softmac_event *eventptr;
65 if (event < -1 || event > IEEE80211SOFTMAC_EVENT_LAST)
71 eventptr = kmalloc(sizeof(struct ieee80211softmac_event), gfp_mask);
75 eventptr->event_type = event;
76 INIT_WORK(&eventptr->work, ieee80211softmac_notify_callback, eventptr);
78 eventptr->context = context;
80 eventptr->event_context = event_context;
82 spin_lock_irqsave(&mac->lock, flags);
83 list_add(&eventptr->list, &mac->events);
84 spin_unlock_irqrestore(&mac->lock, flags);
90 ieee80211softmac_notify_gfp(struct net_device *dev,
91 int event, notify_function_ptr fun, void *context, gfp_t gfp_mask)
93 struct ieee80211softmac_device *mac = ieee80211_priv(dev);
95 if (event < 0 || event > IEEE80211SOFTMAC_EVENT_LAST)
98 return ieee80211softmac_notify_internal(mac, event, NULL, fun, context, gfp_mask);
100 EXPORT_SYMBOL_GPL(ieee80211softmac_notify_gfp);
102 /* private -- calling all callbacks that were specified */
104 ieee80211softmac_call_events_locked(struct ieee80211softmac_device *mac, int event, void *event_ctx)
106 struct ieee80211softmac_event *eventptr, *tmp;
107 union iwreq_data wrqu;
111 msg = event_descriptions[event];
112 wrqu.data.length = strlen(msg);
113 wireless_send_event(mac->dev, IWEVCUSTOM, &wrqu, msg);
116 if (!list_empty(&mac->events))
117 list_for_each_entry_safe(eventptr, tmp, &mac->events, list) {
118 if ((eventptr->event_type == event || eventptr->event_type == -1)
119 && (eventptr->event_context == NULL || eventptr->event_context == event_ctx)) {
120 list_del(&eventptr->list);
121 queue_work(mac->workqueue, &eventptr->work);
127 ieee80211softmac_call_events(struct ieee80211softmac_device *mac, int event, void *event_ctx)
131 spin_lock_irqsave(&mac->lock, flags);
132 ieee80211softmac_call_events_locked(mac, event, event_ctx);
134 spin_unlock_irqrestore(&mac->lock, flags);