d1f255d6c7cde3264619b9e842ffeb6b6e9ff58f
[openwrt/openwrt.git] / package / madwifi / patches / 370-wdsvap.patch
1 --- a/ath/if_ath.c
2 +++ b/ath/if_ath.c
3 @@ -124,7 +124,7 @@ enum {
4 };
5
6 static struct ieee80211vap *ath_vap_create(struct ieee80211com *,
7 - const char *, int, int, struct net_device *);
8 + const char *, int, int, struct net_device *, struct ieee80211vap *);
9 static void ath_vap_delete(struct ieee80211vap *);
10 static int ath_init(struct net_device *);
11 static int ath_set_ack_bitrate(struct ath_softc *, int);
12 @@ -1123,8 +1123,6 @@ ath_attach(u_int16_t devid, struct net_d
13 autocreatemode = IEEE80211_M_IBSS;
14 else if (!strcmp(autocreate, "ahdemo"))
15 autocreatemode = IEEE80211_M_AHDEMO;
16 - else if (!strcmp(autocreate, "wds"))
17 - autocreatemode = IEEE80211_M_WDS;
18 else if (!strcmp(autocreate, "monitor"))
19 autocreatemode = IEEE80211_M_MONITOR;
20 else {
21 @@ -1137,7 +1135,7 @@ ath_attach(u_int16_t devid, struct net_d
22 if (autocreatemode != -1) {
23 rtnl_lock();
24 vap = ieee80211_create_vap(ic, "ath%d", dev,
25 - autocreatemode, 0);
26 + autocreatemode, 0, NULL);
27 rtnl_unlock();
28 if (vap == NULL)
29 EPRINTF(sc, "Autocreation of %s VAP failed.", autocreate);
30 @@ -1230,14 +1228,14 @@ ath_detach(struct net_device *dev)
31
32 static struct ieee80211vap *
33 ath_vap_create(struct ieee80211com *ic, const char *name,
34 - int opmode, int flags, struct net_device *mdev)
35 + int opmode, int flags, struct net_device *mdev, struct ieee80211vap *master)
36 {
37 struct ath_softc *sc = ic->ic_dev->priv;
38 struct ath_hal *ah = sc->sc_ah;
39 struct net_device *dev;
40 struct ath_vap *avp;
41 struct ieee80211vap *vap;
42 - int ic_opmode;
43 + int ic_opmode = IEEE80211_M_STA;
44
45 if (ic->ic_dev->flags & IFF_RUNNING) {
46 /* needs to disable hardware too */
47 @@ -1271,8 +1269,12 @@ ath_vap_create(struct ieee80211com *ic,
48 } else
49 ic_opmode = opmode;
50 break;
51 - case IEEE80211_M_HOSTAP:
52 case IEEE80211_M_WDS:
53 + ic_opmode = ic->ic_opmode;
54 + if (!master)
55 + return NULL;
56 + break;
57 + case IEEE80211_M_HOSTAP:
58 /* permit multiple APs and/or WDS links */
59 /* XXX sta+ap for repeater/bridge application */
60 if ((sc->sc_nvaps != 0) && (ic->ic_opmode == IEEE80211_M_STA))
61 @@ -1304,7 +1306,7 @@ ath_vap_create(struct ieee80211com *ic,
62 }
63
64 avp = dev->priv;
65 - ieee80211_vap_setup(ic, dev, name, opmode, flags);
66 + ieee80211_vap_setup(ic, dev, name, opmode, flags, master);
67 /* override with driver methods */
68 vap = &avp->av_vap;
69 avp->av_newstate = vap->iv_newstate;
70 @@ -4209,8 +4211,7 @@ ath_calcrxfilter(struct ath_softc *sc)
71 if (ic->ic_opmode == IEEE80211_M_STA ||
72 sc->sc_opmode == HAL_M_IBSS || /* NB: AHDEMO too */
73 (sc->sc_nostabeacons) || sc->sc_scanning ||
74 - ((ic->ic_opmode == IEEE80211_M_HOSTAP) &&
75 - (ic->ic_protmode != IEEE80211_PROT_NONE)))
76 + (ic->ic_opmode == IEEE80211_M_HOSTAP))
77 rfilt |= HAL_RX_FILTER_BEACON;
78 if (sc->sc_nmonvaps > 0)
79 rfilt |= (HAL_RX_FILTER_CONTROL | HAL_RX_FILTER_BEACON |
80 @@ -9030,8 +9031,6 @@ ath_calibrate(unsigned long arg)
81 * set sc->beacons if we might need to restart
82 * them after ath_reset. */
83 if (!sc->sc_beacons &&
84 - (TAILQ_FIRST(&ic->ic_vaps)->iv_opmode !=
85 - IEEE80211_M_WDS) &&
86 !txcont_was_active &&
87 !sc->sc_dfs_cac) {
88 sc->sc_beacons = 1;
89 --- a/net80211/ieee80211.c
90 +++ b/net80211/ieee80211.c
91 @@ -373,10 +373,25 @@ void
92 ieee80211_ifdetach(struct ieee80211com *ic)
93 {
94 struct ieee80211vap *vap;
95 + int count;
96 +
97 + /* bring down all vaps */
98 + TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
99 + ieee80211_stop(vap->iv_dev);
100 + }
101 +
102 + /* wait for all subifs to disappear */
103 + do {
104 + schedule();
105 + rtnl_lock();
106 + count = ic->ic_subifs;
107 + rtnl_unlock();
108 + } while (count > 0);
109
110 rtnl_lock();
111 - while ((vap = TAILQ_FIRST(&ic->ic_vaps)) != NULL)
112 + while ((vap = TAILQ_FIRST(&ic->ic_vaps)) != NULL) {
113 ic->ic_vap_delete(vap);
114 + }
115 rtnl_unlock();
116
117 del_timer(&ic->ic_dfs_excl_timer);
118 @@ -396,7 +411,7 @@ EXPORT_SYMBOL(ieee80211_ifdetach);
119
120 int
121 ieee80211_vap_setup(struct ieee80211com *ic, struct net_device *dev,
122 - const char *name, int opmode, int flags)
123 + const char *name, int opmode, int flags, struct ieee80211vap *master)
124 {
125 #define IEEE80211_C_OPMODE \
126 (IEEE80211_C_IBSS | IEEE80211_C_HOSTAP | IEEE80211_C_AHDEMO | \
127 @@ -510,9 +525,18 @@ ieee80211_vap_setup(struct ieee80211com
128
129 vap->iv_monitor_crc_errors = 0;
130 vap->iv_monitor_phy_errors = 0;
131 + TAILQ_INIT(&vap->iv_wdslinks);
132
133 - IEEE80211_ADDR_COPY(vap->iv_myaddr, ic->ic_myaddr);
134 - IEEE80211_ADDR_COPY(vap->iv_bssid, ic->ic_myaddr);
135 + if (master && (vap->iv_opmode == IEEE80211_M_WDS)) {
136 + vap->iv_master = master;
137 + TAILQ_INSERT_TAIL(&master->iv_wdslinks, vap, iv_wdsnext);
138 + /* use the same BSSID as the master interface */
139 + IEEE80211_ADDR_COPY(vap->iv_myaddr, vap->iv_master->iv_myaddr);
140 + IEEE80211_ADDR_COPY(vap->iv_bssid, vap->iv_master->iv_myaddr);
141 + } else {
142 + IEEE80211_ADDR_COPY(vap->iv_myaddr, ic->ic_myaddr);
143 + IEEE80211_ADDR_COPY(vap->iv_bssid, ic->ic_myaddr);
144 + }
145 /* NB: Defer setting dev_addr so driver can override */
146
147 ieee80211_crypto_vattach(vap);
148 @@ -547,7 +571,8 @@ ieee80211_vap_attach(struct ieee80211vap
149 ifmedia_set(&vap->iv_media, imr.ifm_active);
150
151 IEEE80211_LOCK_IRQ(ic);
152 - TAILQ_INSERT_TAIL(&ic->ic_vaps, vap, iv_next);
153 + if (vap->iv_opmode != IEEE80211_M_WDS)
154 + TAILQ_INSERT_TAIL(&ic->ic_vaps, vap, iv_next);
155 IEEE80211_UNLOCK_IRQ(ic);
156
157 IEEE80211_ADDR_COPY(dev->dev_addr, vap->iv_myaddr);
158 @@ -579,10 +604,27 @@ ieee80211_vap_detach(struct ieee80211vap
159 {
160 struct ieee80211com *ic = vap->iv_ic;
161 struct net_device *dev = vap->iv_dev;
162 + struct ieee80211vap *avp;
163 +
164 + /* Drop all WDS links that belong to this vap */
165 + while ((avp = TAILQ_FIRST(&vap->iv_wdslinks)) != NULL) {
166 + if (avp->iv_state != IEEE80211_S_INIT)
167 + ieee80211_stop(avp->iv_dev);
168 + ic->ic_vap_delete(avp);
169 + }
170
171 IEEE80211_CANCEL_TQUEUE(&vap->iv_stajoin1tq);
172 IEEE80211_LOCK_IRQ(ic);
173 - TAILQ_REMOVE(&ic->ic_vaps, vap, iv_next);
174 + if (vap->iv_wdsnode) {
175 + vap->iv_wdsnode->ni_subif = NULL;
176 + ieee80211_unref_node(&vap->iv_wdsnode);
177 + }
178 + if ((vap->iv_opmode == IEEE80211_M_WDS) &&
179 + (vap->iv_master != NULL))
180 + TAILQ_REMOVE(&vap->iv_master->iv_wdslinks, vap, iv_wdsnext);
181 + else
182 + TAILQ_REMOVE(&ic->ic_vaps, vap, iv_next);
183 +
184 if (TAILQ_EMPTY(&ic->ic_vaps)) /* reset to supported mode */
185 ic->ic_opmode = IEEE80211_M_STA;
186 IEEE80211_UNLOCK_IRQ(ic);
187 --- a/net80211/ieee80211_ioctl.h
188 +++ b/net80211/ieee80211_ioctl.h
189 @@ -474,7 +474,7 @@ struct ieee80211req {
190 #define IEEE80211_IOC_DTIM_PERIOD 52 /* DTIM period (beacons) */
191 #define IEEE80211_IOC_BEACON_INTERVAL 53 /* beacon interval (ms) */
192 #define IEEE80211_IOC_ADDMAC 54 /* add sta to MAC ACL table */
193 -#define IEEE80211_IOC_DELMAC 55 /* del sta from MAC ACL table */
194 +#define IEEE80211_IOC_SETMAC 55 /* set interface wds mac addr */
195 #define IEEE80211_IOC_FF 56 /* ATH fast frames (on, off) */
196 #define IEEE80211_IOC_TURBOP 57 /* ATH turbo' (on, off) */
197 #define IEEE80211_IOC_APPIEBUF 58 /* IE in the management frame */
198 @@ -552,8 +552,8 @@ struct ieee80211req_scan_result {
199 #define IEEE80211_IOCTL_HALMAP (SIOCIWFIRSTPRIV+21)
200 #define IEEE80211_IOCTL_ADDMAC (SIOCIWFIRSTPRIV+22)
201 #define IEEE80211_IOCTL_DELMAC (SIOCIWFIRSTPRIV+24)
202 -#define IEEE80211_IOCTL_WDSADDMAC (SIOCIWFIRSTPRIV+26)
203 -#define IEEE80211_IOCTL_WDSDELMAC (SIOCIWFIRSTPRIV+28)
204 +#define IEEE80211_IOCTL_WDSADDMAC (SIOCIWFIRSTPRIV+25)
205 +#define IEEE80211_IOCTL_WDSSETMAC (SIOCIWFIRSTPRIV+26)
206 #define IEEE80211_IOCTL_KICKMAC (SIOCIWFIRSTPRIV+30)
207 #define IEEE80211_IOCTL_SETSCANLIST (SIOCIWFIRSTPRIV+31)
208
209 @@ -649,6 +649,7 @@ enum {
210 IEEE80211_PARAM_BGSCAN_THRESH = 79, /* bg scan rssi threshold */
211 IEEE80211_PARAM_RSSI_DIS_THR = 80, /* rssi threshold for disconnection */
212 IEEE80211_PARAM_RSSI_DIS_COUNT = 81, /* counter for rssi threshold */
213 + IEEE80211_PARAM_WDS_SEP = 82, /* move wds stations into separate interfaces */
214 };
215
216 #define SIOCG80211STATS (SIOCDEVPRIVATE+2)
217 --- a/net80211/ieee80211_linux.h
218 +++ b/net80211/ieee80211_linux.h
219 @@ -81,6 +81,12 @@ set_quality(struct iw_quality *iq, u_int
220 #endif
221 }
222
223 +#ifndef container_of
224 +#define container_of(ptr, type, member) ({ \
225 + const typeof( ((type *)0)->member ) *__mptr = (ptr); \
226 + (type *)( (char *)__mptr - offsetof(type,member) );})
227 +#endif
228 +
229 /*
230 * Task deferral
231 *
232 @@ -113,6 +119,29 @@ typedef void *IEEE80211_TQUEUE_ARG;
233
234 #define IEEE80211_RESCHEDULE schedule
235
236 +#include <linux/sched.h>
237 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,41)
238 +#include <linux/tqueue.h>
239 +#define work_struct tq_struct
240 +#define schedule_work(t) schedule_task((t))
241 +#define flush_scheduled_work() flush_scheduled_tasks()
242 +#define IEEE80211_INIT_WORK(t, f) do { \
243 + memset((t), 0, sizeof(struct tq_struct)); \
244 + (t)->routine = (void (*)(void*)) (f); \
245 + (t)->data=(void *) (t); \
246 +} while (0)
247 +#else
248 +#include <linux/workqueue.h>
249 +
250 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
251 +#define IEEE80211_INIT_WORK(_t, _f) INIT_WORK((_t), (void (*)(void *))(_f), (_t));
252 +#else
253 +#define IEEE80211_INIT_WORK(_t, _f) INIT_WORK((_t), (_f));
254 +#endif
255 +
256 +#endif /* KERNEL_VERSION < 2.5.41 */
257 +
258 +
259 /* Locking */
260 /* NB: beware, spin_is_locked() is not usefully defined for !(DEBUG || SMP)
261 * because spinlocks do not exist in this configuration. Instead IRQs
262 @@ -167,6 +196,14 @@ typedef spinlock_t ieee80211com_lock_t;
263 IEEE80211_VAPS_LOCK_ASSERT(_ic); \
264 spin_unlock_bh(&(_ic)->ic_vapslock); \
265 } while (0)
266 +#define IEEE80211_VAPS_LOCK_IRQ(_ic) do { \
267 + unsigned long __ilockflags; \
268 + IEEE80211_VAPS_LOCK_CHECK(_ic); \
269 + spin_lock_irqsave(&(_ic)->ic_vapslock, __ilockflags);
270 +#define IEEE80211_VAPS_UNLOCK_IRQ(_ic) \
271 + IEEE80211_VAPS_LOCK_ASSERT(_ic); \
272 + spin_unlock_irqrestore(&(_ic)->ic_vapslock, __ilockflags); \
273 +} while (0)
274
275 #if (defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)) && defined(spin_is_locked)
276 #define IEEE80211_VAPS_LOCK_ASSERT(_ic) \
277 @@ -650,5 +687,5 @@ struct ifreq;
278 int ieee80211_ioctl_create_vap(struct ieee80211com *, struct ifreq *,
279 struct net_device *);
280 struct ieee80211vap *ieee80211_create_vap(struct ieee80211com *, char *,
281 - struct net_device *, int, int);
282 + struct net_device *, int, int, struct ieee80211vap *);
283 #endif /* _NET80211_IEEE80211_LINUX_H_ */
284 --- a/net80211/ieee80211_var.h
285 +++ b/net80211/ieee80211_var.h
286 @@ -187,6 +187,12 @@ struct ieee80211vap {
287 struct ieee80211_proc_entry *iv_proc_entries;
288 struct vlan_group *iv_vlgrp; /* vlan group state */
289
290 + /* list of wds links */
291 + TAILQ_HEAD(, ieee80211vap) iv_wdslinks;
292 + TAILQ_ENTRY(ieee80211vap) iv_wdsnext;
293 + struct ieee80211vap *iv_master;
294 + struct ieee80211_node *iv_wdsnode;
295 +
296 TAILQ_ENTRY(ieee80211vap) iv_next; /* list of vap instances */
297 struct ieee80211com *iv_ic; /* back ptr to common state */
298 u_int32_t iv_debug; /* debug msg flags */
299 @@ -316,6 +322,7 @@ struct ieee80211com {
300 u_int8_t ic_myaddr[IEEE80211_ADDR_LEN];
301 struct timer_list ic_inact; /* mgmt/inactivity timer */
302
303 + unsigned int ic_subifs;
304 u_int32_t ic_flags; /* state flags */
305 u_int32_t ic_flags_ext; /* extension of state flags */
306 u_int32_t ic_caps; /* capabilities */
307 @@ -447,7 +454,7 @@ struct ieee80211com {
308 atomic_t ic_node_counter;
309 /* Virtual AP create/delete */
310 struct ieee80211vap *(*ic_vap_create)(struct ieee80211com *,
311 - const char *, int, int, struct net_device *);
312 + const char *, int, int, struct net_device *, struct ieee80211vap *);
313 void (*ic_vap_delete)(struct ieee80211vap *);
314
315 /* Send/recv 802.11 management frame */
316 @@ -619,6 +626,7 @@ MALLOC_DECLARE(M_80211_VAP);
317 #define IEEE80211_FEXT_DROPUNENC_EAPOL 0x00000800 /* CONF: drop unencrypted eapol frames */
318 #define IEEE80211_FEXT_APPIE_UPDATE 0x00001000 /* STATE: beacon APP IE updated */
319 #define IEEE80211_FEXT_BGSCAN_THR 0x00002000 /* bgscan due to low rssi */
320 +#define IEEE80211_FEXT_WDSSEP 0x00004000 /* move wds clients into separate interfaces */
321
322 #define IEEE80211_COM_UAPSD_ENABLE(_ic) ((_ic)->ic_flags_ext |= IEEE80211_FEXT_UAPSD)
323 #define IEEE80211_COM_UAPSD_DISABLE(_ic) ((_ic)->ic_flags_ext &= ~IEEE80211_FEXT_UAPSD)
324 @@ -703,7 +711,7 @@ MALLOC_DECLARE(M_80211_VAP);
325 int ieee80211_ifattach(struct ieee80211com *);
326 void ieee80211_ifdetach(struct ieee80211com *);
327 int ieee80211_vap_setup(struct ieee80211com *, struct net_device *,
328 - const char *, int, int);
329 + const char *, int, int, struct ieee80211vap *);
330 int ieee80211_vap_attach(struct ieee80211vap *, ifm_change_cb_t, ifm_stat_cb_t);
331 void ieee80211_vap_detach(struct ieee80211vap *);
332 void ieee80211_mark_dfs(struct ieee80211com *, struct ieee80211_channel *);
333 --- a/net80211/ieee80211_wireless.c
334 +++ b/net80211/ieee80211_wireless.c
335 @@ -2190,7 +2190,7 @@ ieee80211_setupxr(struct ieee80211vap *v
336 ieee80211_scan_flush(ic); /* NB: could optimize */
337
338 if (!(xrvap = ic->ic_vap_create(ic, name, IEEE80211_M_HOSTAP,
339 - IEEE80211_VAP_XR | IEEE80211_CLONE_BSSID, dev)))
340 + IEEE80211_VAP_XR | IEEE80211_CLONE_BSSID, dev, NULL)))
341 return;
342
343 /* We use iv_xrvap to link to the parent VAP as well */
344 @@ -2867,6 +2867,14 @@ ieee80211_ioctl_setparam(struct net_devi
345 else
346 vap->iv_minrateindex = 0;
347 break;
348 + case IEEE80211_PARAM_WDS_SEP:
349 + if (vap->iv_opmode != IEEE80211_M_HOSTAP)
350 + retv = -EINVAL;
351 + else if (value)
352 + vap->iv_flags_ext |= IEEE80211_FEXT_WDSSEP;
353 + else
354 + vap->iv_flags_ext &= ~IEEE80211_FEXT_WDSSEP;
355 + break;
356 #ifdef ATH_REVERSE_ENGINEERING
357 case IEEE80211_PARAM_DUMPREGS:
358 ieee80211_dump_registers(dev, info, w, extra);
359 @@ -3223,6 +3231,9 @@ ieee80211_ioctl_getparam(struct net_devi
360 case IEEE80211_PARAM_MINRATE:
361 param[0] = vap->iv_minrateindex;
362 break;
363 + case IEEE80211_PARAM_WDS_SEP:
364 + param[0] = !!(vap->iv_flags_ext & IEEE80211_FEXT_WDSSEP);
365 + break;
366 default:
367 return -EOPNOTSUPP;
368 }
369 @@ -3801,74 +3812,54 @@ ieee80211_ioctl_setmlme(struct net_devic
370 return 0;
371 }
372
373 +#define WDSNAME ".wds%d"
374 static int
375 -ieee80211_ioctl_wdsmac(struct net_device *dev, struct iw_request_info *info,
376 +ieee80211_ioctl_wdsaddmac(struct net_device *dev, struct iw_request_info *info,
377 void *w, char *extra)
378 {
379 struct ieee80211vap *vap = dev->priv;
380 struct sockaddr *sa = (struct sockaddr *)extra;
381 + struct ieee80211com *ic = vap->iv_ic;
382 + struct ieee80211vap *avp;
383 + char *name;
384
385 - if (!IEEE80211_ADDR_NULL(vap->wds_mac)) {
386 - printk("%s: Failed to add WDS MAC: " MAC_FMT "\n", dev->name,
387 - MAC_ADDR(sa->sa_data));
388 - printk("%s: Device already has WDS mac address attached,"
389 - " remove first\n", dev->name);
390 - return -1;
391 - }
392 -
393 - memcpy(vap->wds_mac, sa->sa_data, IEEE80211_ADDR_LEN);
394 + if (vap->iv_opmode != IEEE80211_M_HOSTAP)
395 + return -EINVAL;
396
397 - printk("%s: Added WDS MAC: " MAC_FMT "\n", dev->name,
398 - MAC_ADDR(vap->wds_mac));
399 + name = kmalloc(strlen(vap->iv_dev->name) + sizeof(WDSNAME) + 1, GFP_KERNEL);
400 + if (!name)
401 + return -ENOMEM;
402
403 - if (IS_UP(vap->iv_dev)) {
404 - /* Force us back to scan state to force us to go back through RUN
405 - * state and create/pin the WDS peer node into memory. */
406 - return ieee80211_new_state(vap, IEEE80211_S_SCAN, 0);
407 - }
408 + strcpy(name, vap->iv_dev->name);
409 + strcat(name, WDSNAME);
410 + avp = ieee80211_create_vap(ic, name, ic->ic_dev, IEEE80211_M_WDS, 0, vap);
411 + kfree(name);
412 + if (!avp)
413 + return -ENOMEM;
414
415 + memcpy(avp->wds_mac, sa->sa_data, IEEE80211_ADDR_LEN);
416 return 0;
417 }
418 +#undef WDSNAME
419
420 static int
421 -ieee80211_ioctl_wdsdelmac(struct net_device *dev, struct iw_request_info *info,
422 +ieee80211_ioctl_wdssetmac(struct net_device *dev, struct iw_request_info *info,
423 void *w, char *extra)
424 {
425 struct ieee80211vap *vap = dev->priv;
426 struct sockaddr *sa = (struct sockaddr *)extra;
427 - struct ieee80211com *ic = vap->iv_ic;
428 - struct ieee80211_node *wds_ni;
429
430 - /* WDS Mac address filed already? */
431 - if (IEEE80211_ADDR_NULL(vap->wds_mac))
432 - return 0;
433 + if (vap->iv_opmode != IEEE80211_M_WDS)
434 + return -EINVAL;
435
436 - /* Compare suplied MAC address with WDS MAC of this interface
437 - * remove when mac address is known
438 - */
439 - if (memcmp(vap->wds_mac, sa->sa_data, IEEE80211_ADDR_LEN) == 0) {
440 - if (IS_UP(vap->iv_dev)) {
441 - wds_ni = ieee80211_find_txnode(vap, vap->wds_mac);
442 - if (wds_ni != NULL) {
443 - /* Release reference created by find node */
444 - ieee80211_unref_node(&wds_ni);
445 - /* Release reference created by transition to RUN state,
446 - * [pinning peer node into the table] */
447 - ieee80211_unref_node(&wds_ni);
448 - }
449 - }
450 - memset(vap->wds_mac, 0x00, IEEE80211_ADDR_LEN);
451 - if (IS_UP(vap->iv_dev)) {
452 - /* This leaves a dead WDS node, until started again */
453 - return ic->ic_reset(ic->ic_dev);
454 - }
455 - return 0;
456 + memcpy(vap->wds_mac, sa->sa_data, IEEE80211_ADDR_LEN);
457 + if (IS_UP(vap->iv_dev)) {
458 + /* Force us back to scan state to force us to go back through RUN
459 + * state and create/pin the WDS peer node into memory. */
460 + return ieee80211_new_state(vap, IEEE80211_S_SCAN, 0);
461 }
462
463 - printk("%s: WDS MAC address " MAC_FMT " is not known by this interface\n",
464 - dev->name, MAC_ADDR(sa->sa_data));
465 -
466 - return -1;
467 + return 0;
468 }
469
470 /*
471 @@ -4470,6 +4461,8 @@ get_sta_space(void *arg, struct ieee8021
472 struct ieee80211vap *vap = ni->ni_vap;
473 size_t ielen;
474
475 + if (req->vap->iv_wdsnode && ni->ni_subif)
476 + vap = ni->ni_subif;
477 if (vap != req->vap && vap != req->vap->iv_xrvap) /* only entries for this vap */
478 return;
479 if ((vap->iv_opmode == IEEE80211_M_HOSTAP ||
480 @@ -4489,6 +4482,8 @@ get_sta_info(void *arg, struct ieee80211
481 size_t ielen, len;
482 u_int8_t *cp;
483
484 + if (req->vap->iv_wdsnode && ni->ni_subif)
485 + vap = ni->ni_subif;
486 if (vap != req->vap && vap != req->vap->iv_xrvap) /* only entries for this vap (or) xrvap */
487 return;
488 if ((vap->iv_opmode == IEEE80211_M_HOSTAP ||
489 @@ -5391,8 +5386,8 @@ static const struct iw_priv_args ieee802
490 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "kickmac"},
491 { IEEE80211_IOCTL_WDSADDMAC,
492 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,"wds_add" },
493 - { IEEE80211_IOCTL_WDSDELMAC,
494 - IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,"wds_del" },
495 + { IEEE80211_IOCTL_WDSSETMAC,
496 + IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,"wds_set" },
497 { IEEE80211_IOCTL_SETCHANLIST,
498 IW_PRIV_TYPE_CHANLIST | IW_PRIV_SIZE_FIXED, 0,"setchanlist" },
499 { IEEE80211_IOCTL_GETCHANLIST,
500 @@ -5790,6 +5785,10 @@ static const struct iw_priv_args ieee802
501 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_minrate"},
502 { IEEE80211_IOCTL_SETSCANLIST,
503 IW_PRIV_TYPE_CHAR | 255, 0, "setscanlist"},
504 + { IEEE80211_PARAM_WDS_SEP,
505 + IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wdssep"},
506 + { IEEE80211_PARAM_WDS_SEP,
507 + 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_wdssep"},
508
509 #ifdef ATH_REVERSE_ENGINEERING
510 /*
511 @@ -5884,8 +5883,8 @@ static const iw_handler ieee80211_priv_h
512 #endif
513 set_priv(IEEE80211_IOCTL_ADDMAC, ieee80211_ioctl_addmac),
514 set_priv(IEEE80211_IOCTL_DELMAC, ieee80211_ioctl_delmac),
515 - set_priv(IEEE80211_IOCTL_WDSADDMAC, ieee80211_ioctl_wdsmac),
516 - set_priv(IEEE80211_IOCTL_WDSDELMAC, ieee80211_ioctl_wdsdelmac),
517 + set_priv(IEEE80211_IOCTL_WDSADDMAC, ieee80211_ioctl_wdsaddmac),
518 + set_priv(IEEE80211_IOCTL_WDSSETMAC, ieee80211_ioctl_wdssetmac),
519 set_priv(IEEE80211_IOCTL_KICKMAC, ieee80211_ioctl_kickmac),
520 set_priv(IEEE80211_IOCTL_SETSCANLIST, ieee80211_ioctl_setscanlist),
521 #ifdef ATH_REVERSE_ENGINEERING
522 @@ -5913,6 +5912,8 @@ static int
523 ieee80211_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
524 {
525 struct ieee80211vap *vap = dev->priv;
526 + struct ieee80211com *ic = vap->iv_ic;
527 + struct ieee80211_node *ni;
528
529 switch (cmd) {
530 case SIOCG80211STATS:
531 @@ -5921,8 +5922,20 @@ ieee80211_ioctl(struct net_device *dev,
532 case SIOC80211IFDESTROY:
533 if (!capable(CAP_NET_ADMIN))
534 return -EPERM;
535 + /* drop all node subifs */
536 + TAILQ_FOREACH(ni, &ic->ic_sta.nt_node, ni_list) {
537 + struct ieee80211vap *avp = ni->ni_subif;
538 +
539 + if (ni->ni_vap != vap)
540 + continue;
541 + if (!avp)
542 + continue;
543 + ni->ni_subif = NULL;
544 + ieee80211_stop(avp->iv_dev);
545 + ic->ic_vap_delete(avp);
546 + }
547 ieee80211_stop(vap->iv_dev); /* force state before cleanup */
548 - vap->iv_ic->ic_vap_delete(vap);
549 + ic->ic_vap_delete(vap);
550 return 0;
551 case IEEE80211_IOCTL_GETKEY:
552 return ieee80211_ioctl_getkey(dev, (struct iwreq *) ifr);
553 @@ -5956,7 +5969,7 @@ ieee80211_ioctl_create_vap(struct ieee80
554
555 strncpy(name, cp.icp_name, sizeof(name));
556
557 - vap = ieee80211_create_vap(ic, name, mdev, cp.icp_opmode, cp.icp_flags);
558 + vap = ieee80211_create_vap(ic, name, mdev, cp.icp_opmode, cp.icp_flags, NULL);
559 if (vap == NULL)
560 return -EIO;
561
562 @@ -5973,9 +5986,9 @@ EXPORT_SYMBOL(ieee80211_ioctl_create_vap
563 */
564 struct ieee80211vap*
565 ieee80211_create_vap(struct ieee80211com *ic, char *name,
566 - struct net_device *mdev, int opmode, int opflags)
567 + struct net_device *mdev, int opmode, int opflags, struct ieee80211vap *master)
568 {
569 - return ic->ic_vap_create(ic, name, opmode, opflags, mdev);
570 + return ic->ic_vap_create(ic, name, opmode, opflags, mdev, master);
571 }
572 EXPORT_SYMBOL(ieee80211_create_vap);
573
574 --- a/net80211/ieee80211_input.c
575 +++ b/net80211/ieee80211_input.c
576 @@ -199,8 +199,10 @@ ieee80211_input(struct ieee80211vap * va
577 {
578 #define HAS_SEQ(type) ((type & 0x4) == 0)
579 struct ieee80211_node * ni = ni_or_null;
580 - struct ieee80211com *ic = vap->iv_ic;
581 - struct net_device *dev = vap->iv_dev;
582 + struct ieee80211com *ic;
583 + struct net_device *dev;
584 + struct ieee80211_node *ni_wds = NULL;
585 + struct net_device_stats *stats;
586 struct ieee80211_frame *wh;
587 struct ieee80211_key *key;
588 struct ether_header *eh;
589 @@ -212,6 +214,19 @@ ieee80211_input(struct ieee80211vap * va
590 u_int8_t *bssid;
591 u_int16_t rxseq;
592
593 + type = -1; /* undefined */
594 +
595 + if (!vap)
596 + goto out;
597 +
598 + ic = vap->iv_ic;
599 + if (!ic)
600 + goto out;
601 +
602 + dev = vap->iv_dev;
603 + if (!dev)
604 + goto out;
605 +
606 /* initialize ni as in the previous API */
607 if (ni_or_null == NULL) {
608 /* This function does not 'own' vap->iv_bss, so we cannot
609 @@ -227,7 +242,6 @@ ieee80211_input(struct ieee80211vap * va
610
611 /* XXX adjust device in sk_buff? */
612
613 - type = -1; /* undefined */
614 /*
615 * In monitor mode, send everything directly to bpf.
616 * Also do not process frames w/o i_addr2 any further.
617 @@ -434,7 +448,7 @@ ieee80211_input(struct ieee80211vap * va
618
619 switch (type) {
620 case IEEE80211_FC0_TYPE_DATA:
621 - hdrspace = ieee80211_hdrspace(ic, wh);
622 + hdrspace = ieee80211_hdrsize(wh);
623 if (skb->len < hdrspace) {
624 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
625 wh, "data", "too short: len %u, expecting %u",
626 @@ -444,16 +458,24 @@ ieee80211_input(struct ieee80211vap * va
627 }
628 switch (vap->iv_opmode) {
629 case IEEE80211_M_STA:
630 - if ((dir != IEEE80211_FC1_DIR_FROMDS) &&
631 - (!((vap->iv_flags_ext & IEEE80211_FEXT_WDS) &&
632 - (dir == IEEE80211_FC1_DIR_DSTODS)))) {
633 + switch(dir) {
634 + case IEEE80211_FC1_DIR_FROMDS:
635 + break;
636 + case IEEE80211_FC1_DIR_DSTODS:
637 + if (vap->iv_flags_ext & IEEE80211_FEXT_WDS)
638 + break;
639 + default:
640 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY,
641 wh, "data", "invalid dir 0x%x", dir);
642 vap->iv_stats.is_rx_wrongdir++;
643 goto out;
644 }
645
646 - if (IEEE80211_IS_MULTICAST(wh->i_addr1)) {
647 + if (IEEE80211_IS_MULTICAST(wh->i_addr1)) {
648 + /* ignore 3-addr mcast if we're WDS STA */
649 + if (vap->iv_flags_ext & IEEE80211_FEXT_WDS)
650 + goto out;
651 +
652 /* Discard multicast if IFF_MULTICAST not set */
653 if ((0 != memcmp(wh->i_addr3, dev->broadcast, ETH_ALEN)) &&
654 (0 == (dev->flags & IFF_MULTICAST))) {
655 @@ -481,24 +503,10 @@ ieee80211_input(struct ieee80211vap * va
656 vap->iv_stats.is_rx_mcastecho++;
657 goto out;
658 }
659 - /*
660 - * if it is brodcasted by me on behalf of
661 - * a station behind me, drop it.
662 - */
663 - if (vap->iv_flags_ext & IEEE80211_FEXT_WDS) {
664 - struct ieee80211_node_table *nt;
665 - struct ieee80211_node *ni_wds;
666 - nt = &ic->ic_sta;
667 - ni_wds = ieee80211_find_wds_node(nt, wh->i_addr3);
668 - if (ni_wds) {
669 - ieee80211_unref_node(&ni_wds);
670 - IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
671 - wh, NULL, "%s",
672 - "multicast echo originated from node behind me");
673 - vap->iv_stats.is_rx_mcastecho++;
674 - goto out;
675 - }
676 - }
677 + } else {
678 + /* Same BSSID, but not meant for us to receive */
679 + if (!IEEE80211_ADDR_EQ(wh->i_addr1, vap->iv_myaddr))
680 + goto out;
681 }
682 break;
683 case IEEE80211_M_IBSS:
684 @@ -540,16 +548,28 @@ ieee80211_input(struct ieee80211vap * va
685 vap->iv_stats.is_rx_notassoc++;
686 goto err;
687 }
688 +
689 /*
690 * If we're a 4 address packet, make sure we have an entry in
691 * the node table for the packet source address (addr4).
692 * If not, add one.
693 */
694 + /* check for wds link first */
695 + if ((dir == IEEE80211_FC1_DIR_DSTODS) && !ni->ni_subif) {
696 + if (vap->iv_flags_ext & IEEE80211_FEXT_WDSSEP) {
697 + ieee80211_wds_addif(ni);
698 + /* we must drop frames here until the interface has
699 + * been fully separated, otherwise a bridge might get
700 + * confused */
701 + goto err;
702 + }
703 + }
704 +
705 /* XXX: Useless node mgmt API; make better */
706 - if (dir == IEEE80211_FC1_DIR_DSTODS) {
707 - struct ieee80211_node_table *nt;
708 + if ((dir == IEEE80211_FC1_DIR_DSTODS) && !vap->iv_wdsnode &&
709 + !ni_wds && !ni->ni_subif) {
710 + struct ieee80211_node_table *nt = &ic->ic_sta;
711 struct ieee80211_frame_addr4 *wh4;
712 - struct ieee80211_node *ni_wds;
713
714 if (!(vap->iv_flags_ext & IEEE80211_FEXT_WDS)) {
715 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
716 @@ -557,7 +577,6 @@ ieee80211_input(struct ieee80211vap * va
717 goto err;
718 }
719 wh4 = (struct ieee80211_frame_addr4 *)skb->data;
720 - nt = &ic->ic_sta;
721 ni_wds = ieee80211_find_wds_node(nt, wh4->i_addr4);
722 /* Last call increments ref count if !NULL */
723 if ((ni_wds != NULL) && (ni_wds != ni)) {
724 @@ -608,6 +627,11 @@ ieee80211_input(struct ieee80211vap * va
725 goto out;
726 }
727
728 + /* check if there is any data left */
729 + hdrspace = ieee80211_hdrspace(ic, wh);
730 + if (skb->len < hdrspace)
731 + goto out;
732 +
733 /*
734 * Handle privacy requirements. Note that we
735 * must not be preempted from here until after
736 @@ -680,8 +704,12 @@ ieee80211_input(struct ieee80211vap * va
737 if (! accept_data_frame(vap, ni, key, skb, eh))
738 goto out;
739
740 - vap->iv_devstats.rx_packets++;
741 - vap->iv_devstats.rx_bytes += skb->len;
742 + if (ni->ni_subif && ((eh)->ether_type != __constant_htons(ETHERTYPE_PAE)))
743 + stats = &ni->ni_subif->iv_devstats;
744 + else
745 + stats = &vap->iv_devstats;
746 + stats->rx_packets++;
747 + stats->rx_bytes += skb->len;
748 IEEE80211_NODE_STAT(ni, rx_data);
749 IEEE80211_NODE_STAT_ADD(ni, rx_bytes, skb->len);
750 ic->ic_lastdata = jiffies;
751 @@ -1114,6 +1142,17 @@ ieee80211_deliver_data(struct ieee80211_
752 dev = vap->iv_xrvap->iv_dev;
753 #endif
754
755 + /* if the node has a wds subif, move data frames there,
756 + * but keep EAP traffic on the master */
757 + if (ni->ni_subif && ((eh)->ether_type != __constant_htons(ETHERTYPE_PAE))) {
758 + if (ni->ni_vap == ni->ni_subif) {
759 + ieee80211_dev_kfree_skb(&skb);
760 + } else {
761 + vap = ni->ni_subif;
762 + dev = vap->iv_dev;
763 + }
764 + }
765 +
766 /* perform as a bridge within the vap */
767 /* XXX intra-vap bridging only */
768 if (vap->iv_opmode == IEEE80211_M_HOSTAP &&
769 @@ -1139,7 +1178,16 @@ ieee80211_deliver_data(struct ieee80211_
770 if (ni1 != NULL) {
771 if (ni1->ni_vap == vap &&
772 ieee80211_node_is_authorized(ni1) &&
773 + !ni1->ni_subif &&
774 ni1 != vap->iv_bss) {
775 +
776 + /* tried to bridge to a subif, drop the packet */
777 + if (ni->ni_subif) {
778 + ieee80211_unref_node(&ni1);
779 + ieee80211_dev_kfree_skb(&skb);
780 + return;
781 + }
782 +
783 skb1 = skb;
784 skb = NULL;
785 }
786 @@ -3084,8 +3132,7 @@ ieee80211_recv_mgmt(struct ieee80211vap
787 (vap->iv_opmode == IEEE80211_M_STA && ni->ni_associd) ||
788 (vap->iv_opmode == IEEE80211_M_IBSS) ||
789 ((subtype == IEEE80211_FC0_SUBTYPE_BEACON) &&
790 - (vap->iv_opmode == IEEE80211_M_HOSTAP) &&
791 - (ic->ic_protmode != IEEE80211_PROT_NONE)))) {
792 + (vap->iv_opmode == IEEE80211_M_HOSTAP)))) {
793 vap->iv_stats.is_rx_mgtdiscard++;
794 return;
795 }
796 @@ -3471,13 +3518,54 @@ ieee80211_recv_mgmt(struct ieee80211vap
797 */
798 if (ic->ic_flags & IEEE80211_F_SCAN) {
799 ieee80211_add_scan(vap, &scan, wh, subtype, rssi, rtsf);
800 - return;
801 }
802 - if ((vap->iv_opmode == IEEE80211_M_IBSS) &&
803 - (scan.capinfo & IEEE80211_CAPINFO_IBSS)) {
804 + /* NB: Behavior of WDS-Link and Ad-Hoc is very similar here:
805 + * When we receive a beacon that belongs to the AP that we're
806 + * connected to, use it to refresh the local node info.
807 + * If no node is found, go through the vap's wds link table
808 + * and try to find the sub-vap that is interested in this address
809 + */
810 + if (((vap->iv_opmode == IEEE80211_M_IBSS) &&
811 + (scan.capinfo & IEEE80211_CAPINFO_IBSS)) ||
812 + (((vap->iv_opmode == IEEE80211_M_HOSTAP) ||
813 + (vap->iv_opmode == IEEE80211_M_WDS)) &&
814 + (scan.capinfo & IEEE80211_CAPINFO_ESS))) {
815 + struct ieee80211vap *avp = NULL;
816 +
817 + IEEE80211_LOCK_IRQ(vap->iv_ic);
818 + if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
819 + int found = 0;
820 +
821 + TAILQ_FOREACH(avp, &vap->iv_wdslinks, iv_wdsnext) {
822 + if (!memcmp(avp->wds_mac, wh->i_addr2, IEEE80211_ADDR_LEN)) {
823 + if (avp->iv_state != IEEE80211_S_RUN)
824 + continue;
825 + found = 1;
826 + break;
827 + }
828 + }
829 + if (!found)
830 + break;
831 +
832 + ni = ni_or_null = avp->iv_wdsnode;
833 + } else if (vap->iv_opmode == IEEE80211_M_WDS) {
834 + ni = ni_or_null = vap->iv_wdsnode;
835 + }
836 + IEEE80211_UNLOCK_IRQ(vap->iv_ic);
837 +
838 +
839 if (ni_or_null == NULL) {
840 - /* Create a new entry in the neighbor table. */
841 - ni = ieee80211_add_neighbor(vap, wh, &scan);
842 + if (avp) {
843 + IEEE80211_LOCK_IRQ(ic);
844 + ni = ieee80211_add_neighbor(avp, wh, &scan);
845 + /* force assoc */
846 + ni->ni_associd |= 0xc000;
847 + avp->iv_wdsnode = ieee80211_ref_node(ni);
848 + IEEE80211_UNLOCK_IRQ(ic);
849 + } else if (vap->iv_opmode == IEEE80211_M_IBSS) {
850 + /* Create a new entry in the neighbor table. */
851 + ni = ieee80211_add_neighbor(vap, wh, &scan);
852 + }
853 } else {
854 /*
855 * Copy data from beacon to neighbor table.
856 @@ -3490,6 +3578,7 @@ ieee80211_recv_mgmt(struct ieee80211vap
857 IEEE80211_ADDR_COPY(ni->ni_bssid, wh->i_addr3);
858 memcpy(ni->ni_tstamp.data, scan.tstamp,
859 sizeof(ni->ni_tstamp));
860 + ni->ni_inact = ni->ni_inact_reload;
861 ni->ni_intval =
862 IEEE80211_BINTVAL_SANITISE(scan.bintval);
863 ni->ni_capinfo = scan.capinfo;
864 --- a/net80211/ieee80211_node.c
865 +++ b/net80211/ieee80211_node.c
866 @@ -47,6 +47,7 @@
867 #include <linux/netdevice.h>
868 #include <linux/etherdevice.h>
869 #include <linux/random.h>
870 +#include <linux/rtnetlink.h>
871
872 #include "if_media.h"
873
874 @@ -236,7 +237,11 @@ void
875 ieee80211_node_vdetach(struct ieee80211vap *vap)
876 {
877 struct ieee80211com *ic = vap->iv_ic;
878 + struct ieee80211_node *ni;
879
880 + ni = vap->iv_wdsnode;
881 + if (ni)
882 + ni->ni_subif = NULL;
883 ieee80211_node_table_reset(&ic->ic_sta, vap);
884 if (vap->iv_bss != NULL) {
885 ieee80211_unref_node(&vap->iv_bss);
886 @@ -831,12 +836,18 @@ node_table_leave_locked(struct ieee80211
887 LIST_REMOVE(ni, ni_hash);
888 }
889 ni->ni_table = NULL;
890 + if (ni->ni_vap->iv_wdsnode == ni) {
891 +#ifdef IEEE80211_DEBUG_REFCNT
892 + ieee80211_unref_node_debug(&ni->ni_vap->iv_wdsnode, func, line);
893 +#else
894 + ieee80211_unref_node(&ni->ni_vap->iv_wdsnode);
895 +#endif
896 + }
897 #ifdef IEEE80211_DEBUG_REFCNT
898 ieee80211_unref_node_debug(&ni, func, line);
899 #else
900 ieee80211_unref_node(&ni);
901 #endif
902 -
903 }
904
905 /* This is overridden by ath_node_alloc in ath/if_ath.c, and so
906 @@ -1134,6 +1145,62 @@ ieee80211_alloc_node(struct ieee80211vap
907 return ni;
908 }
909
910 +#define WDSIFNAME ".sta%d"
911 +static void
912 +ieee80211_wds_do_addif(struct work_struct *work)
913 +{
914 + struct ieee80211_node *ni = container_of(work, struct ieee80211_node, ni_create);
915 + struct ieee80211vap *vap = ni->ni_vap;
916 + struct ieee80211com *ic = vap->iv_ic;
917 + struct ieee80211vap *avp = NULL;
918 + char *name;
919 +
920 + rtnl_lock();
921 + /* did we get cancelled by the destroy call? */
922 + if (!ni->ni_subif)
923 + goto done;
924 +
925 + ni->ni_subif = NULL;
926 + name = kmalloc(strlen(vap->iv_dev->name) + sizeof(WDSIFNAME) + 1, GFP_KERNEL);
927 + if (!name)
928 + goto done;
929 +
930 + strcpy(name, vap->iv_dev->name);
931 + strcat(name, WDSIFNAME);
932 + avp = ieee80211_create_vap(ic, name, ic->ic_dev, IEEE80211_M_WDS, 0, vap);
933 + kfree(name);
934 + if (!avp)
935 + goto done;
936 +
937 + memcpy(avp->wds_mac, ni->ni_bssid, IEEE80211_ADDR_LEN);
938 + avp->iv_wdsnode = ieee80211_ref_node(ni);
939 + ni->ni_subif = avp;
940 + ic->ic_subifs++;
941 +
942 +done:
943 + if (avp) {
944 + IEEE80211_VAPS_LOCK_IRQ(ic);
945 + avp->iv_newstate(vap, IEEE80211_S_RUN, -1);
946 + IEEE80211_VAPS_UNLOCK_IRQ(ic);
947 + }
948 + rtnl_unlock();
949 + ieee80211_unref_node(&ni);
950 +}
951 +#undef WDSIFNAME
952 +
953 +void ieee80211_wds_addif(struct ieee80211_node *ni)
954 +{
955 + /* check if the node is split out already,
956 + * or if we're in progress of setting up a new interface already */
957 + if (ni->ni_subif)
958 + return;
959 +
960 + ieee80211_ref_node(ni);
961 + ni->ni_subif = ni->ni_vap;
962 + IEEE80211_INIT_WORK(&ni->ni_create, ieee80211_wds_do_addif);
963 + schedule_work(&ni->ni_create);
964 +}
965 +
966 /* Add wds address to the node table */
967 int
968 #ifdef IEEE80211_DEBUG_REFCNT
969 @@ -1553,22 +1620,39 @@ ieee80211_find_rxnode(struct ieee80211co
970 ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) == IEEE80211_FC0_SUBTYPE_PS_POLL)
971 struct ieee80211_node_table *nt;
972 struct ieee80211_node *ni;
973 + struct ieee80211vap *vap, *avp;
974 + const u_int8_t *addr;
975 +
976 + if (IS_CTL(wh) && !IS_PSPOLL(wh) /*&& !IS_RTS(ah)*/)
977 + addr = wh->i_addr1;
978 + else
979 + addr = wh->i_addr2;
980 +
981 + if (IEEE80211_IS_MULTICAST(addr))
982 + return NULL;
983
984 /* XXX check ic_bss first in station mode */
985 /* XXX 4-address frames? */
986 nt = &ic->ic_sta;
987 IEEE80211_NODE_TABLE_LOCK_IRQ(nt);
988 - if (IS_CTL(wh) && !IS_PSPOLL(wh) /*&& !IS_RTS(ah)*/)
989 -#ifdef IEEE80211_DEBUG_REFCNT
990 - ni = ieee80211_find_node_locked_debug(nt, wh->i_addr1, func, line);
991 -#else
992 - ni = ieee80211_find_node_locked(nt, wh->i_addr1);
993 -#endif
994 - else
995 + if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS) {
996 + TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
997 + TAILQ_FOREACH(avp, &vap->iv_wdslinks, iv_wdsnext) {
998 + if (!IEEE80211_ADDR_EQ(addr, avp->wds_mac))
999 + continue;
1000 +
1001 + if (avp->iv_wdsnode)
1002 + return ieee80211_ref_node(avp->iv_wdsnode);
1003 + else
1004 + return NULL;
1005 + }
1006 + }
1007 + }
1008 +
1009 #ifdef IEEE80211_DEBUG_REFCNT
1010 - ni = ieee80211_find_node_locked_debug(nt, wh->i_addr2, func, line);
1011 + ni = ieee80211_find_node_locked_debug(nt, addr, func, line);
1012 #else
1013 - ni = ieee80211_find_node_locked(nt, wh->i_addr2);
1014 + ni = ieee80211_find_node_locked(nt, addr);
1015 #endif
1016 IEEE80211_NODE_TABLE_UNLOCK_IRQ(nt);
1017
1018 @@ -1596,9 +1680,19 @@ ieee80211_find_txnode_debug(struct ieee8
1019 ieee80211_find_txnode(struct ieee80211vap *vap, const u_int8_t *mac)
1020 #endif
1021 {
1022 + struct ieee80211com *ic = vap->iv_ic;
1023 struct ieee80211_node_table *nt;
1024 struct ieee80211_node *ni = NULL;
1025
1026 + IEEE80211_LOCK_IRQ(ic);
1027 + if (vap->iv_opmode == IEEE80211_M_WDS) {
1028 + if (vap->iv_wdsnode && (vap->iv_state == IEEE80211_S_RUN))
1029 + return ieee80211_ref_node(vap->iv_wdsnode);
1030 + else
1031 + return NULL;
1032 + }
1033 + IEEE80211_UNLOCK_IRQ(ic);
1034 +
1035 /*
1036 * The destination address should be in the node table
1037 * unless we are operating in station mode or this is a
1038 @@ -1669,6 +1763,11 @@ ieee80211_free_node(struct ieee80211_nod
1039 {
1040 struct ieee80211vap *vap = ni->ni_vap;
1041
1042 + IEEE80211_LOCK_IRQ(ni->ni_ic);
1043 + if (vap && ni == vap->iv_wdsnode)
1044 + vap->iv_wdsnode = NULL;
1045 + IEEE80211_UNLOCK_IRQ(ni->ni_ic);
1046 +
1047 atomic_dec(&ni->ni_ic->ic_node_counter);
1048 node_print_message(IEEE80211_MSG_NODE|IEEE80211_MSG_NODE_REF,
1049 1 /* show counter */,
1050 @@ -1781,22 +1880,6 @@ restart:
1051 jiffies > ni->ni_rxfragstamp + HZ) {
1052 ieee80211_dev_kfree_skb(&ni->ni_rxfrag);
1053 }
1054 - /*
1055 - * Special case ourself; we may be idle for extended periods
1056 - * of time and regardless reclaiming our state is wrong.
1057 - * Special case a WDS link: it may be dead or idle, but it is
1058 - * never ok to reclaim it, as this will block transmissions
1059 - * and nobody will recreate the node when the WDS peer is
1060 - * available again. */
1061 - if ((ni == ni->ni_vap->iv_bss) ||
1062 - (ni->ni_vap->iv_opmode == IEEE80211_M_WDS &&
1063 - !memcmp(ni->ni_macaddr, ni->ni_vap->wds_mac, ETH_ALEN)))
1064 - {
1065 - /* NB: don't permit it to go negative */
1066 - if (ni->ni_inact > 0)
1067 - ni->ni_inact--;
1068 - continue;
1069 - }
1070 ni->ni_inact--;
1071 if (ni->ni_associd != 0 || isadhoc) {
1072 struct ieee80211vap *vap = ni->ni_vap;
1073 @@ -2263,6 +2346,36 @@ ieee80211_node_leave_11g(struct ieee8021
1074 }
1075 }
1076
1077 +static void
1078 +ieee80211_subif_destroy(struct work_struct *work)
1079 +{
1080 + struct ieee80211_node *ni = container_of(work, struct ieee80211_node, ni_destroy);
1081 + struct ieee80211vap *vap;
1082 + struct ieee80211com *ic;
1083 +
1084 + rtnl_lock();
1085 + vap = ni->ni_subif;
1086 +
1087 + /* if addif is waiting for the timer to fire, cancel! */
1088 + if (vap == ni->ni_vap) {
1089 + ni->ni_subif = NULL;
1090 + goto done;
1091 + }
1092 +
1093 + if (!vap)
1094 + goto done;
1095 +
1096 + ic = vap->iv_ic;
1097 + ni->ni_subif = NULL;
1098 + ieee80211_stop(vap->iv_dev);
1099 + ic->ic_vap_delete(vap);
1100 + ic->ic_subifs--;
1101 +
1102 +done:
1103 + ieee80211_unref_node(&ni);
1104 + rtnl_unlock();
1105 +}
1106 +
1107 /*
1108 * Handle bookkeeping for a station/neighbor leaving
1109 * the bss when operating in ap or adhoc modes.
1110 @@ -2279,6 +2392,12 @@ ieee80211_node_leave(struct ieee80211_no
1111 ni, "station with aid %d leaves (refcnt %u)",
1112 IEEE80211_NODE_AID(ni), atomic_read(&ni->ni_refcnt));
1113
1114 + if (ni->ni_subif) {
1115 + ieee80211_ref_node(ni);
1116 + IEEE80211_INIT_WORK(&ni->ni_destroy, ieee80211_subif_destroy);
1117 + schedule_work(&ni->ni_destroy);
1118 + }
1119 +
1120 /* From this point onwards we can no longer find the node,
1121 * so no more references are generated
1122 */
1123 --- a/net80211/ieee80211_output.c
1124 +++ b/net80211/ieee80211_output.c
1125 @@ -246,15 +246,16 @@ ieee80211_hardstart(struct sk_buff *skb,
1126 * things like power save.
1127 */
1128 eh = (struct ether_header *)skb->data;
1129 - if (vap->iv_opmode == IEEE80211_M_WDS)
1130 - ni = ieee80211_find_txnode(vap, vap->wds_mac);
1131 - else
1132 - ni = ieee80211_find_txnode(vap, eh->ether_dhost);
1133 + ni = ieee80211_find_txnode(vap, eh->ether_dhost);
1134 if (ni == NULL) {
1135 /* NB: ieee80211_find_txnode does stat+msg */
1136 goto bad;
1137 }
1138
1139 + if (ni->ni_subif && (vap != ni->ni_subif) &&
1140 + ((eh)->ether_type != __constant_htons(ETHERTYPE_PAE)))
1141 + goto bad;
1142 +
1143 /* calculate priority so drivers can find the TX queue */
1144 if (ieee80211_classify(ni, skb)) {
1145 IEEE80211_NOTE(vap, IEEE80211_MSG_OUTPUT, ni,
1146 @@ -334,20 +335,33 @@ void ieee80211_parent_queue_xmit(struct
1147 * constructing a frame as it sets i_fc[1]; other bits can
1148 * then be or'd in.
1149 */
1150 -static void
1151 +static struct ieee80211_frame *
1152 ieee80211_send_setup(struct ieee80211vap *vap,
1153 struct ieee80211_node *ni,
1154 - struct ieee80211_frame *wh,
1155 + struct sk_buff *skb,
1156 int type,
1157 const u_int8_t sa[IEEE80211_ADDR_LEN],
1158 const u_int8_t da[IEEE80211_ADDR_LEN],
1159 const u_int8_t bssid[IEEE80211_ADDR_LEN])
1160 {
1161 #define WH4(wh) ((struct ieee80211_frame_addr4 *)wh)
1162 + struct ieee80211_frame *wh;
1163 + int len = sizeof(struct ieee80211_frame);
1164 + int opmode = vap->iv_opmode;
1165
1166 + if ((type & IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_DATA) {
1167 + if ((opmode == IEEE80211_M_STA) &&
1168 + (vap->iv_flags_ext & IEEE80211_FEXT_WDS))
1169 + opmode = IEEE80211_M_WDS;
1170 +
1171 + if (opmode == IEEE80211_M_WDS)
1172 + len = sizeof(struct ieee80211_frame_addr4);
1173 + }
1174 +
1175 + wh = (struct ieee80211_frame *)skb_push(skb, len);
1176 wh->i_fc[0] = IEEE80211_FC0_VERSION_0 | type;
1177 if ((type & IEEE80211_FC0_TYPE_MASK) == IEEE80211_FC0_TYPE_DATA) {
1178 - switch (vap->iv_opmode) {
1179 + switch (opmode) {
1180 case IEEE80211_M_STA:
1181 wh->i_fc[1] = IEEE80211_FC1_DIR_TODS;
1182 IEEE80211_ADDR_COPY(wh->i_addr1, bssid);
1183 @@ -389,6 +403,8 @@ ieee80211_send_setup(struct ieee80211vap
1184 *(__le16 *)&wh->i_seq[0] =
1185 htole16(ni->ni_txseqs[0] << IEEE80211_SEQ_SEQ_SHIFT);
1186 ni->ni_txseqs[0]++;
1187 +
1188 + return wh;
1189 #undef WH4
1190 }
1191
1192 @@ -410,9 +426,7 @@ ieee80211_mgmt_output(struct ieee80211_n
1193
1194 SKB_CB(skb)->ni = ni;
1195
1196 - wh = (struct ieee80211_frame *)
1197 - skb_push(skb, sizeof(struct ieee80211_frame));
1198 - ieee80211_send_setup(vap, ni, wh,
1199 + wh = ieee80211_send_setup(vap, ni, skb,
1200 IEEE80211_FC0_TYPE_MGT | type,
1201 vap->iv_myaddr, ni->ni_macaddr, vap->iv_bssid);
1202 /* XXX power management */
1203 @@ -458,6 +472,9 @@ ieee80211_send_nulldata(struct ieee80211
1204 struct ieee80211_frame *wh;
1205 u_int8_t *frm;
1206
1207 + if (ni->ni_subif)
1208 + vap = ni->ni_subif;
1209 +
1210 skb = ieee80211_getmgtframe(&frm, 0);
1211 if (skb == NULL) {
1212 /* XXX debug msg */
1213 @@ -466,9 +483,7 @@ ieee80211_send_nulldata(struct ieee80211
1214 return -ENOMEM;
1215 }
1216
1217 - wh = (struct ieee80211_frame *)
1218 - skb_push(skb, sizeof(struct ieee80211_frame));
1219 - ieee80211_send_setup(vap, ni, wh,
1220 + wh = ieee80211_send_setup(vap, ni, skb,
1221 IEEE80211_FC0_TYPE_DATA | IEEE80211_FC0_SUBTYPE_NODATA,
1222 vap->iv_myaddr, ni->ni_macaddr, vap->iv_bssid);
1223 /* NB: power management bit is never sent by an AP */
1224 @@ -506,6 +521,7 @@ ieee80211_send_qosnulldata(struct ieee80
1225 struct sk_buff *skb;
1226 struct ieee80211_qosframe *qwh;
1227 u_int8_t *frm;
1228 + u_int8_t *i_qos;
1229 int tid;
1230
1231 skb = ieee80211_getmgtframe(&frm, 2);
1232 @@ -517,11 +533,12 @@ ieee80211_send_qosnulldata(struct ieee80
1233 SKB_CB(skb)->ni = ieee80211_ref_node(ni);
1234
1235 skb->priority = ac;
1236 - qwh = (struct ieee80211_qosframe *)skb_push(skb, sizeof(struct ieee80211_qosframe));
1237
1238 - qwh = (struct ieee80211_qosframe *)skb->data;
1239 + /* grab a pointer to QoS control and also compensate for the header length
1240 + * difference between QoS and non-QoS frame */
1241 + i_qos = skb_push(skb, sizeof(struct ieee80211_qosframe) - sizeof(struct ieee80211_frame));
1242
1243 - ieee80211_send_setup(vap, ni, (struct ieee80211_frame *)qwh,
1244 + qwh = (struct ieee80211_qosframe *) ieee80211_send_setup(vap, ni, skb,
1245 IEEE80211_FC0_TYPE_DATA,
1246 vap->iv_myaddr, /* SA */
1247 ni->ni_macaddr, /* DA */
1248 @@ -535,10 +552,10 @@ ieee80211_send_qosnulldata(struct ieee80
1249
1250 /* map from access class/queue to 11e header priority value */
1251 tid = WME_AC_TO_TID(ac);
1252 - qwh->i_qos[0] = tid & IEEE80211_QOS_TID;
1253 + i_qos[0] = tid & IEEE80211_QOS_TID;
1254 if (ic->ic_wme.wme_wmeChanParams.cap_wmeParams[ac].wmep_noackPolicy)
1255 qwh->i_qos[0] |= (1 << IEEE80211_QOS_ACKPOLICY_S) & IEEE80211_QOS_ACKPOLICY;
1256 - qwh->i_qos[1] = 0;
1257 + i_qos[1] = 0;
1258
1259 IEEE80211_NODE_STAT(ni, tx_data);
1260
1261 @@ -780,6 +797,8 @@ ieee80211_encap(struct ieee80211_node *n
1262 hdrsize = sizeof(struct ieee80211_frame);
1263
1264 SKB_CB(skb)->auth_pkt = (eh.ether_type == __constant_htons(ETHERTYPE_PAE));
1265 + if (ni->ni_subif)
1266 + vap = ni->ni_subif;
1267
1268 switch (vap->iv_opmode) {
1269 case IEEE80211_M_IBSS:
1270 @@ -788,7 +807,7 @@ ieee80211_encap(struct ieee80211_node *n
1271 break;
1272 case IEEE80211_M_WDS:
1273 use4addr = 1;
1274 - ismulticast = IEEE80211_IS_MULTICAST(ni->ni_macaddr);
1275 + ismulticast = 0;
1276 break;
1277 case IEEE80211_M_HOSTAP:
1278 if (!IEEE80211_IS_MULTICAST(eh.ether_dhost) &&
1279 @@ -799,20 +818,9 @@ ieee80211_encap(struct ieee80211_node *n
1280 ismulticast = IEEE80211_IS_MULTICAST(eh.ether_dhost);
1281 break;
1282 case IEEE80211_M_STA:
1283 - if ((vap->iv_flags_ext & IEEE80211_FEXT_WDS) &&
1284 - !IEEE80211_ADDR_EQ(eh.ether_shost, vap->iv_myaddr)) {
1285 + if (vap->iv_flags_ext & IEEE80211_FEXT_WDS) {
1286 use4addr = 1;
1287 - ismulticast = IEEE80211_IS_MULTICAST(ni->ni_macaddr);
1288 - /* Add a WDS entry to the station VAP */
1289 - if (IEEE80211_IS_MULTICAST(eh.ether_dhost)) {
1290 - struct ieee80211_node_table *nt = &ic->ic_sta;
1291 - struct ieee80211_node *ni_wds
1292 - = ieee80211_find_wds_node(nt, eh.ether_shost);
1293 - if (ni_wds)
1294 - ieee80211_unref_node(&ni_wds);
1295 - else
1296 - ieee80211_add_wds_addr(nt, ni, eh.ether_shost, 0);
1297 - }
1298 + ismulticast = 0;
1299 } else
1300 ismulticast = IEEE80211_IS_MULTICAST(vap->iv_bssid);
1301 break;
1302 @@ -973,7 +981,7 @@ ieee80211_encap(struct ieee80211_node *n
1303 break;
1304 case IEEE80211_M_WDS:
1305 wh->i_fc[1] = IEEE80211_FC1_DIR_DSTODS;
1306 - IEEE80211_ADDR_COPY(wh->i_addr1, ni->ni_macaddr);
1307 + IEEE80211_ADDR_COPY(wh->i_addr1, vap->wds_mac);
1308 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
1309 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_dhost);
1310 IEEE80211_ADDR_COPY(WH4(wh)->i_addr4, eh.ether_shost);
1311 @@ -1683,9 +1691,7 @@ ieee80211_send_probereq(struct ieee80211
1312
1313 SKB_CB(skb)->ni = ieee80211_ref_node(ni);
1314
1315 - wh = (struct ieee80211_frame *)
1316 - skb_push(skb, sizeof(struct ieee80211_frame));
1317 - ieee80211_send_setup(vap, ni, wh,
1318 + wh = ieee80211_send_setup(vap, ni, skb,
1319 IEEE80211_FC0_TYPE_MGT | IEEE80211_FC0_SUBTYPE_PROBE_REQ,
1320 sa, da, bssid);
1321 /* XXX power management? */
1322 --- a/tools/athkey.c
1323 +++ b/tools/athkey.c
1324 @@ -118,7 +118,7 @@ set80211priv(const char *dev, int op, vo
1325 IOCTL_ERR(IEEE80211_IOCTL_ADDMAC),
1326 IOCTL_ERR(IEEE80211_IOCTL_DELMAC),
1327 IOCTL_ERR(IEEE80211_IOCTL_WDSADDMAC),
1328 - IOCTL_ERR(IEEE80211_IOCTL_WDSDELMAC),
1329 + IOCTL_ERR(IEEE80211_IOCTL_WDSSETMAC),
1330 IOCTL_ERR(IEEE80211_IOCTL_READREG),
1331 IOCTL_ERR(IEEE80211_IOCTL_WRITEREG),
1332 };
1333 --- a/tools/athchans.c
1334 +++ b/tools/athchans.c
1335 @@ -118,7 +118,7 @@ set80211priv(const char *dev, int op, vo
1336 IOCTL_ERR(IEEE80211_IOCTL_ADDMAC),
1337 IOCTL_ERR(IEEE80211_IOCTL_DELMAC),
1338 IOCTL_ERR(IEEE80211_IOCTL_WDSADDMAC),
1339 - IOCTL_ERR(IEEE80211_IOCTL_WDSDELMAC),
1340 + IOCTL_ERR(IEEE80211_IOCTL_WDSSETMAC),
1341 IOCTL_ERR(IEEE80211_IOCTL_READREG),
1342 IOCTL_ERR(IEEE80211_IOCTL_WRITEREG),
1343 };
1344 --- a/tools/wlanconfig.c
1345 +++ b/tools/wlanconfig.c
1346 @@ -968,7 +968,7 @@ do80211priv(struct iwreq *iwr, const cha
1347 IOCTL_ERR(IEEE80211_IOCTL_ADDMAC),
1348 IOCTL_ERR(IEEE80211_IOCTL_DELMAC),
1349 IOCTL_ERR(IEEE80211_IOCTL_WDSADDMAC),
1350 - IOCTL_ERR(IEEE80211_IOCTL_WDSDELMAC),
1351 + IOCTL_ERR(IEEE80211_IOCTL_WDSSETMAC),
1352 IOCTL_ERR(IEEE80211_IOCTL_READREG),
1353 IOCTL_ERR(IEEE80211_IOCTL_WRITEREG),
1354 };
1355 --- a/net80211/ieee80211_proto.c
1356 +++ b/net80211/ieee80211_proto.c
1357 @@ -1081,6 +1081,8 @@ ieee80211_init(struct net_device *dev, i
1358 int
1359 ieee80211_open(struct net_device *dev)
1360 {
1361 + struct ieee80211vap *vap = dev->priv;
1362 +
1363 return ieee80211_init(dev, 0);
1364 }
1365
1366 @@ -1090,7 +1092,7 @@ ieee80211_open(struct net_device *dev)
1367 void
1368 ieee80211_start_running(struct ieee80211com *ic)
1369 {
1370 - struct ieee80211vap *vap;
1371 + struct ieee80211vap *vap, *avp;
1372 struct net_device *dev;
1373
1374 /* XXX locking */
1375 @@ -1099,6 +1101,16 @@ ieee80211_start_running(struct ieee80211
1376 /* NB: avoid recursion */
1377 if ((dev->flags & IFF_UP) && !(dev->flags & IFF_RUNNING))
1378 ieee80211_open(dev);
1379 +
1380 + TAILQ_FOREACH(avp, &vap->iv_wdslinks, iv_wdsnext) {
1381 + if (avp->iv_wdsnode && avp->iv_wdsnode->ni_subif == avp)
1382 + continue;
1383 +
1384 + dev = avp->iv_dev;
1385 + /* NB: avoid recursion */
1386 + if ((dev->flags & IFF_UP) && !(dev->flags & IFF_RUNNING))
1387 + ieee80211_open(dev);
1388 + }
1389 }
1390 }
1391 EXPORT_SYMBOL(ieee80211_start_running);
1392 @@ -1116,11 +1128,43 @@ ieee80211_stop(struct net_device *dev)
1393 struct ieee80211vap *vap = dev->priv;
1394 struct ieee80211com *ic = vap->iv_ic;
1395 struct net_device *parent = ic->ic_dev;
1396 + struct ieee80211_node *tni, *ni;
1397 + struct ieee80211vap *avp;
1398
1399 IEEE80211_DPRINTF(vap,
1400 IEEE80211_MSG_STATE | IEEE80211_MSG_DEBUG,
1401 "%s\n", "stop running");
1402
1403 + if (vap->iv_wdsnode && !vap->iv_wdsnode->ni_subif)
1404 + ieee80211_unref_node(&vap->iv_wdsnode);
1405 +
1406 + /* stop wds interfaces */
1407 + TAILQ_FOREACH(avp, &vap->iv_wdslinks, iv_next) {
1408 + if (avp->iv_state != IEEE80211_S_INIT)
1409 + ieee80211_stop(avp->iv_dev);
1410 + }
1411 +
1412 + /* get rid of all wds nodes while we're still locked */
1413 + do {
1414 + ni = NULL;
1415 +
1416 + IEEE80211_NODE_TABLE_LOCK_IRQ(&ic->ic_sta);
1417 + TAILQ_FOREACH(tni, &ic->ic_sta.nt_node, ni_list) {
1418 + if (tni->ni_vap != vap)
1419 + continue;
1420 + if (!tni->ni_subif)
1421 + continue;
1422 + ni = tni;
1423 + break;
1424 + }
1425 + IEEE80211_NODE_TABLE_UNLOCK_IRQ(&ic->ic_sta);
1426 +
1427 + if (!ni)
1428 + break;
1429 +
1430 + ieee80211_node_leave(ni);
1431 + } while (1);
1432 +
1433 ieee80211_new_state(vap, IEEE80211_S_INIT, -1);
1434 if (dev->flags & IFF_RUNNING) {
1435 dev->flags &= ~IFF_RUNNING; /* mark us stopped */
1436 @@ -1148,7 +1192,7 @@ EXPORT_SYMBOL(ieee80211_stop);
1437 void
1438 ieee80211_stop_running(struct ieee80211com *ic)
1439 {
1440 - struct ieee80211vap *vap;
1441 + struct ieee80211vap *vap, *avp;
1442 struct net_device *dev;
1443
1444 /* XXX locking */
1445 @@ -1156,6 +1200,12 @@ ieee80211_stop_running(struct ieee80211c
1446 dev = vap->iv_dev;
1447 if (dev->flags & IFF_RUNNING) /* NB: avoid recursion */
1448 ieee80211_stop(dev);
1449 +
1450 + TAILQ_FOREACH(avp, &vap->iv_wdslinks, iv_wdsnext) {
1451 + dev = avp->iv_dev;
1452 + if (dev->flags & IFF_RUNNING) /* NB: avoid recursion */
1453 + ieee80211_stop(dev);
1454 + }
1455 }
1456 }
1457 EXPORT_SYMBOL(ieee80211_stop_running);
1458 @@ -1342,9 +1392,9 @@ ieee80211_new_state(struct ieee80211vap
1459 struct ieee80211com *ic = vap->iv_ic;
1460 int rc;
1461
1462 - IEEE80211_VAPS_LOCK_BH(ic);
1463 + IEEE80211_VAPS_LOCK_IRQ(ic);
1464 rc = vap->iv_newstate(vap, nstate, arg);
1465 - IEEE80211_VAPS_UNLOCK_BH(ic);
1466 + IEEE80211_VAPS_UNLOCK_IRQ(ic);
1467 return rc;
1468 }
1469
1470 @@ -1557,57 +1607,12 @@ __ieee80211_newstate(struct ieee80211vap
1471 switch (ostate) {
1472 case IEEE80211_S_INIT:
1473 if (vap->iv_opmode == IEEE80211_M_MONITOR ||
1474 - vap->iv_opmode == IEEE80211_M_WDS ||
1475 vap->iv_opmode == IEEE80211_M_HOSTAP) {
1476 /*
1477 * Already have a channel; bypass the
1478 * scan and startup immediately.
1479 */
1480 ieee80211_create_ibss(vap, ic->ic_curchan);
1481 -
1482 - /* In WDS mode, allocate and initialize peer node. */
1483 - if (vap->iv_opmode == IEEE80211_M_WDS) {
1484 - /* XXX: This is horribly non-atomic. */
1485 - struct ieee80211_node *wds_ni =
1486 - ieee80211_find_node(&ic->ic_sta,
1487 - vap->wds_mac);
1488 -
1489 - if (wds_ni == NULL) {
1490 - wds_ni = ieee80211_alloc_node_table(
1491 - vap,
1492 - vap->wds_mac);
1493 - if (wds_ni != NULL) {
1494 - ieee80211_add_wds_addr(
1495 - &ic->ic_sta,
1496 - wds_ni,
1497 - vap->wds_mac,
1498 - 1);
1499 - ieee80211_ref_node(wds_ni); /* pin in memory */
1500 - }
1501 - else
1502 - IEEE80211_DPRINTF(
1503 - vap,
1504 - IEEE80211_MSG_NODE,
1505 - "%s: Unable to "
1506 - "allocate node for "
1507 - "WDS: " MAC_FMT "\n",
1508 - __func__,
1509 - MAC_ADDR(
1510 - vap->wds_mac)
1511 - );
1512 - }
1513 -
1514 - if (wds_ni != NULL) {
1515 - ieee80211_node_authorize(wds_ni);
1516 - wds_ni->ni_chan =
1517 - vap->iv_bss->ni_chan;
1518 - wds_ni->ni_capinfo =
1519 - ni->ni_capinfo;
1520 - wds_ni->ni_associd = 1;
1521 - wds_ni->ni_ath_flags =
1522 - vap->iv_ath_cap;
1523 - }
1524 - }
1525 break;
1526 }
1527 /* fall thru... */
1528 @@ -1675,6 +1680,7 @@ __ieee80211_newstate(struct ieee80211vap
1529 */
1530 if (ni->ni_authmode != IEEE80211_AUTH_8021X)
1531 ieee80211_node_authorize(ni);
1532 +
1533 #ifdef ATH_SUPERG_XR
1534 /*
1535 * fire a timer to bring up XR vap if configured.
1536 @@ -1808,6 +1814,11 @@ ieee80211_newstate(struct ieee80211vap *
1537 ieee80211_state_name[dstate]);
1538
1539 ieee80211_update_link_status(vap, nstate, ostate);
1540 +
1541 + if ((nstate != IEEE80211_S_RUN) && vap->iv_wdsnode &&
1542 + !vap->iv_wdsnode->ni_subif)
1543 + ieee80211_unref_node(&vap->iv_wdsnode);
1544 +
1545 switch (nstate) {
1546 case IEEE80211_S_AUTH:
1547 case IEEE80211_S_ASSOC:
1548 @@ -1930,8 +1941,15 @@ ieee80211_newstate(struct ieee80211vap *
1549 if (ostate == IEEE80211_S_SCAN ||
1550 ostate == IEEE80211_S_AUTH ||
1551 ostate == IEEE80211_S_ASSOC) {
1552 +
1553 /* Transition (S_SCAN|S_AUTH|S_ASSOC) -> S_RUN */
1554 __ieee80211_newstate(vap, nstate, arg);
1555 +
1556 + /* if we're in wds, let the ap know that we're doing this */
1557 + if ((vap->iv_opmode == IEEE80211_M_STA) &&
1558 + (vap->iv_flags_ext & IEEE80211_FEXT_WDS))
1559 + ieee80211_send_nulldata(ieee80211_ref_node(vap->iv_bss));
1560 +
1561 /* Then bring up all other vaps pending on the scan */
1562 dstate = get_dominant_state(ic);
1563 if (dstate == IEEE80211_S_RUN) {
1564 --- a/ath/if_athvar.h
1565 +++ b/ath/if_athvar.h
1566 @@ -79,28 +79,6 @@ typedef void *TQUEUE_ARG;
1567 #define tasklet_enable(t) do { (void) t; local_bh_enable(); } while (0)
1568 #endif /* !DECLARE_TASKLET */
1569
1570 -#include <linux/sched.h>
1571 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,41)
1572 -#include <linux/tqueue.h>
1573 -#define work_struct tq_struct
1574 -#define schedule_work(t) schedule_task((t))
1575 -#define flush_scheduled_work() flush_scheduled_tasks()
1576 -#define ATH_INIT_WORK(t, f) do { \
1577 - memset((t), 0, sizeof(struct tq_struct)); \
1578 - (t)->routine = (void (*)(void*)) (f); \
1579 - (t)->data=(void *) (t); \
1580 -} while (0)
1581 -#else
1582 -#include <linux/workqueue.h>
1583 -
1584 -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
1585 -#define ATH_INIT_WORK(_t, _f) INIT_WORK((_t), (void (*)(void *))(_f), (_t));
1586 -#else
1587 -#define ATH_INIT_WORK(_t, _f) INIT_WORK((_t), (_f));
1588 -#endif
1589 -
1590 -#endif /* KERNEL_VERSION < 2.5.41 */
1591 -
1592 /*
1593 * Guess how the interrupt handler should work.
1594 */
1595 --- a/net80211/ieee80211_linux.c
1596 +++ b/net80211/ieee80211_linux.c
1597 @@ -145,7 +145,7 @@ ieee80211_getmgtframe(u_int8_t **frm, u_
1598 struct sk_buff *skb;
1599 u_int len;
1600
1601 - len = roundup(sizeof(struct ieee80211_frame) + pktlen, 4);
1602 + len = roundup(sizeof(struct ieee80211_frame_addr4) + pktlen, 4);
1603 #ifdef IEEE80211_DEBUG_REFCNT
1604 skb = ieee80211_dev_alloc_skb_debug(len + align - 1, func, line);
1605 #else
1606 @@ -161,7 +161,7 @@ ieee80211_getmgtframe(u_int8_t **frm, u_
1607 SKB_CB(skb)->flags = 0;
1608 SKB_CB(skb)->next = NULL;
1609
1610 - skb_reserve(skb, sizeof(struct ieee80211_frame));
1611 + skb_reserve(skb, sizeof(struct ieee80211_frame_addr4));
1612 *frm = skb_put(skb, pktlen);
1613 }
1614 return skb;
1615 --- a/net80211/ieee80211_node.h
1616 +++ b/net80211/ieee80211_node.h
1617 @@ -92,11 +92,13 @@ struct ath_softc;
1618 * the ieee80211com structure.
1619 */
1620 struct ieee80211_node {
1621 - struct ieee80211vap *ni_vap;
1622 + struct ieee80211vap *ni_vap, *ni_subif;
1623 struct ieee80211com *ni_ic;
1624 struct ieee80211_node_table *ni_table;
1625 TAILQ_ENTRY(ieee80211_node) ni_list;
1626 LIST_ENTRY(ieee80211_node) ni_hash;
1627 + struct work_struct ni_create; /* task for creating a subif */
1628 + struct work_struct ni_destroy; /* task for destroying a subif */
1629 atomic_t ni_refcnt;
1630 u_int ni_scangen; /* gen# for timeout scan */
1631 u_int8_t ni_authmode; /* authentication algorithm */
1632 @@ -430,5 +432,6 @@ void ieee80211_node_join(struct ieee8021
1633 void ieee80211_node_leave(struct ieee80211_node *);
1634 u_int8_t ieee80211_getrssi(struct ieee80211com *);
1635 int32_t ieee80211_get_node_count(struct ieee80211com *);
1636 +void ieee80211_wds_addif(struct ieee80211_node *ni);
1637 #endif /* _NET80211_IEEE80211_NODE_H_ */
1638