4 * These are not exported because they're assigned to the function pointers.
7 #include <linux/completion.h>
8 #include "ieee80211softmac_priv.h"
10 /* internal, use to trigger scanning if needed.
11 * Returns -EBUSY if already scanning,
12 * result of start_scan otherwise */
14 ieee80211softmac_start_scan(struct ieee80211softmac_device *sm)
19 spin_lock_irqsave(&sm->lock, flags);
22 spin_unlock_irqrestore(&sm->lock, flags);
26 spin_unlock_irqrestore(&sm->lock, flags);
28 ret = sm->start_scan(sm->dev);
30 spin_lock_irqsave(&sm->lock, flags);
32 spin_unlock_irqrestore(&sm->lock, flags);
38 ieee80211softmac_stop_scan(struct ieee80211softmac_device *sm)
42 spin_lock_irqsave(&sm->lock, flags);
45 spin_unlock_irqrestore(&sm->lock, flags);
49 spin_unlock_irqrestore(&sm->lock, flags);
50 sm->stop_scan(sm->dev);
54 ieee80211softmac_wait_for_scan(struct ieee80211softmac_device *sm)
58 spin_lock_irqsave(&sm->lock, flags);
61 spin_unlock_irqrestore(&sm->lock, flags);
65 spin_unlock_irqrestore(&sm->lock, flags);
66 sm->wait_for_scan(sm->dev);
70 /* internal scanning implementation follows */
71 void ieee80211softmac_scan(void *d)
74 u8 current_channel_idx;
75 struct ieee80211softmac_device *sm = (struct ieee80211softmac_device *)d;
76 struct ieee80211softmac_scaninfo *si = sm->scaninfo;
79 while (!(si->stop) && (si->current_channel_idx < si->number_channels)) {
80 current_channel_idx = si->current_channel_idx;
81 si->current_channel_idx++; /* go to the next channel */
83 invalid_channel = (si->skip_flags & si->channels[current_channel_idx].flags);
85 if (!invalid_channel) {
86 sm->set_channel(sm->dev, si->channels[current_channel_idx].channel);
87 //TODO: Probe the channel
88 // FIXME make this user configurable (active/passive)
89 if(ieee80211softmac_send_mgt_frame(sm, NULL, IEEE80211_STYPE_PROBE_REQ, 0))
90 printkl(KERN_DEBUG PFX "Sending Probe Request Failed\n");
92 /* also send directed management frame for the network we're looking for */
93 // TODO: is this if correct, or should we do this only if scanning from assoc request?
94 if (sm->associnfo.req_essid.len)
95 ieee80211softmac_send_mgt_frame(sm, &sm->associnfo.req_essid, IEEE80211_STYPE_PROBE_REQ, 0);
96 schedule_delayed_work(&si->softmac_scan, IEEE80211SOFTMAC_PROBE_DELAY);
99 dprintk(PFX "Not probing Channel %d (not allowed here)\n", si->channels[current_channel_idx].channel);
103 spin_lock_irqsave(&sm->lock, flags);
104 cancel_delayed_work(&si->softmac_scan);
106 spin_unlock_irqrestore(&sm->lock, flags);
108 dprintk(PFX "Scanning finished\n");
109 ieee80211softmac_scan_finished(sm);
110 complete_all(&sm->scaninfo->finished);
113 static inline struct ieee80211softmac_scaninfo *allocate_scaninfo(struct ieee80211softmac_device *mac)
115 /* ugh. can we call this without having the spinlock held? */
116 struct ieee80211softmac_scaninfo *info = kmalloc(sizeof(struct ieee80211softmac_scaninfo), GFP_ATOMIC);
119 INIT_WORK(&info->softmac_scan, ieee80211softmac_scan, mac);
120 init_completion(&info->finished);
124 int ieee80211softmac_start_scan_implementation(struct net_device *dev)
126 struct ieee80211softmac_device *sm = ieee80211_priv(dev);
129 if (!(dev->flags & IFF_UP))
132 assert(ieee80211softmac_scan_handlers_check_self(sm));
133 if (!ieee80211softmac_scan_handlers_check_self(sm))
136 spin_lock_irqsave(&sm->lock, flags);
137 /* it looks like we need to hold the lock here
138 * to make sure we don't allocate two of these... */
139 if (unlikely(!sm->scaninfo))
140 sm->scaninfo = allocate_scaninfo(sm);
141 if (unlikely(!sm->scaninfo)) {
142 spin_unlock_irqrestore(&sm->lock, flags);
146 sm->scaninfo->skip_flags = IEEE80211_CH_INVALID;
147 if (0 /* not scanning in IEEE802.11b */)//TODO
148 sm->scaninfo->skip_flags |= IEEE80211_CH_B_ONLY;
149 if (0 /* IEEE802.11a */) {//TODO
150 sm->scaninfo->channels = sm->ieee->geo.a;
151 sm->scaninfo->number_channels = sm->ieee->geo.a_channels;
153 sm->scaninfo->channels = sm->ieee->geo.bg;
154 sm->scaninfo->number_channels = sm->ieee->geo.bg_channels;
156 dprintk(PFX "Start scanning with channel: %d\n", sm->scaninfo->channels[0].channel);
157 dprintk(PFX "Scanning %d channels\n", sm->scaninfo->number_channels);
158 sm->scaninfo->current_channel_idx = 0;
159 sm->scaninfo->started = 1;
160 INIT_COMPLETION(sm->scaninfo->finished);
161 schedule_work(&sm->scaninfo->softmac_scan);
162 spin_unlock_irqrestore(&sm->lock, flags);
166 void ieee80211softmac_stop_scan_implementation(struct net_device *dev)
168 struct ieee80211softmac_device *sm = ieee80211_priv(dev);
171 assert(ieee80211softmac_scan_handlers_check_self(sm));
172 if (!ieee80211softmac_scan_handlers_check_self(sm))
175 spin_lock_irqsave(&sm->lock, flags);
176 assert(sm->scaninfo != NULL);
178 if (sm->scaninfo->started)
179 sm->scaninfo->stop = 1;
181 complete_all(&sm->scaninfo->finished);
183 spin_unlock_irqrestore(&sm->lock, flags);
186 void ieee80211softmac_wait_for_scan_implementation(struct net_device *dev)
188 struct ieee80211softmac_device *sm = ieee80211_priv(dev);
191 assert(ieee80211softmac_scan_handlers_check_self(sm));
192 if (!ieee80211softmac_scan_handlers_check_self(sm))
195 spin_lock_irqsave(&sm->lock, flags);
196 if (!sm->scaninfo->started) {
197 spin_unlock_irqrestore(&sm->lock, flags);
200 spin_unlock_irqrestore(&sm->lock, flags);
201 wait_for_completion(&sm->scaninfo->finished);
204 /* this is what drivers (that do scanning) call when they're done */
205 void ieee80211softmac_scan_finished(struct ieee80211softmac_device *sm)
209 spin_lock_irqsave(&sm->lock, flags);
211 spin_unlock_irqrestore(&sm->lock, flags);
213 ieee80211softmac_call_events(sm, IEEE80211SOFTMAC_EVENT_SCAN_FINISHED, NULL);
216 EXPORT_SYMBOL_GPL(ieee80211softmac_scan_finished);