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