ee0a2de5bbc18a7e544bd57d766cf9158f012a75
[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 @@
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 @@
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 @@
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 @@
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 @@
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 + ic_opmode = ic->ic_opmode;
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 @@
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 @@ -4201,8 +4203,7 @@
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 @@
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 @@ -396,7 +396,7 @@
92
93 int
94 ieee80211_vap_setup(struct ieee80211com *ic, struct net_device *dev,
95 - const char *name, int opmode, int flags)
96 + const char *name, int opmode, int flags, struct ieee80211vap *master)
97 {
98 #define IEEE80211_C_OPMODE \
99 (IEEE80211_C_IBSS | IEEE80211_C_HOSTAP | IEEE80211_C_AHDEMO | \
100 @@ -510,9 +510,18 @@
101
102 vap->iv_monitor_crc_errors = 0;
103 vap->iv_monitor_phy_errors = 0;
104 + TAILQ_INIT(&vap->iv_wdslinks);
105
106 - IEEE80211_ADDR_COPY(vap->iv_myaddr, ic->ic_myaddr);
107 - IEEE80211_ADDR_COPY(vap->iv_bssid, ic->ic_myaddr);
108 + if (master && (vap->iv_opmode == IEEE80211_M_WDS)) {
109 + vap->iv_master = master;
110 + TAILQ_INSERT_TAIL(&master->iv_wdslinks, vap, iv_wdsnext);
111 + /* use the same BSSID as the master interface */
112 + IEEE80211_ADDR_COPY(vap->iv_myaddr, vap->iv_master->iv_myaddr);
113 + IEEE80211_ADDR_COPY(vap->iv_bssid, vap->iv_master->iv_myaddr);
114 + } else {
115 + IEEE80211_ADDR_COPY(vap->iv_myaddr, ic->ic_myaddr);
116 + IEEE80211_ADDR_COPY(vap->iv_bssid, ic->ic_myaddr);
117 + }
118 /* NB: Defer setting dev_addr so driver can override */
119
120 ieee80211_crypto_vattach(vap);
121 @@ -547,7 +556,8 @@
122 ifmedia_set(&vap->iv_media, imr.ifm_active);
123
124 IEEE80211_LOCK_IRQ(ic);
125 - TAILQ_INSERT_TAIL(&ic->ic_vaps, vap, iv_next);
126 + if (vap->iv_opmode != IEEE80211_M_WDS)
127 + TAILQ_INSERT_TAIL(&ic->ic_vaps, vap, iv_next);
128 IEEE80211_UNLOCK_IRQ(ic);
129
130 IEEE80211_ADDR_COPY(dev->dev_addr, vap->iv_myaddr);
131 @@ -579,10 +589,24 @@
132 {
133 struct ieee80211com *ic = vap->iv_ic;
134 struct net_device *dev = vap->iv_dev;
135 + struct ieee80211vap *avp;
136 +
137 + /* Drop all WDS links that belong to this vap */
138 + while ((avp = TAILQ_FIRST(&vap->iv_wdslinks)) != NULL) {
139 + ieee80211_stop(avp->iv_dev);
140 + ic->ic_vap_delete(avp);
141 + }
142
143 IEEE80211_CANCEL_TQUEUE(&vap->iv_stajoin1tq);
144 IEEE80211_LOCK_IRQ(ic);
145 - TAILQ_REMOVE(&ic->ic_vaps, vap, iv_next);
146 + if (vap->iv_wdsnode)
147 + ieee80211_unref_node(&vap->iv_wdsnode);
148 + if ((vap->iv_opmode == IEEE80211_M_WDS) &&
149 + (vap->iv_master != NULL))
150 + TAILQ_REMOVE(&vap->iv_master->iv_wdslinks, vap, iv_wdsnext);
151 + else
152 + TAILQ_REMOVE(&ic->ic_vaps, vap, iv_next);
153 +
154 if (TAILQ_EMPTY(&ic->ic_vaps)) /* reset to supported mode */
155 ic->ic_opmode = IEEE80211_M_STA;
156 IEEE80211_UNLOCK_IRQ(ic);
157 --- a/net80211/ieee80211_ioctl.h
158 +++ b/net80211/ieee80211_ioctl.h
159 @@ -474,7 +474,7 @@
160 #define IEEE80211_IOC_DTIM_PERIOD 52 /* DTIM period (beacons) */
161 #define IEEE80211_IOC_BEACON_INTERVAL 53 /* beacon interval (ms) */
162 #define IEEE80211_IOC_ADDMAC 54 /* add sta to MAC ACL table */
163 -#define IEEE80211_IOC_DELMAC 55 /* del sta from MAC ACL table */
164 +#define IEEE80211_IOC_SETMAC 55 /* set interface wds mac addr */
165 #define IEEE80211_IOC_FF 56 /* ATH fast frames (on, off) */
166 #define IEEE80211_IOC_TURBOP 57 /* ATH turbo' (on, off) */
167 #define IEEE80211_IOC_APPIEBUF 58 /* IE in the management frame */
168 @@ -552,8 +552,8 @@
169 #define IEEE80211_IOCTL_HALMAP (SIOCIWFIRSTPRIV+21)
170 #define IEEE80211_IOCTL_ADDMAC (SIOCIWFIRSTPRIV+22)
171 #define IEEE80211_IOCTL_DELMAC (SIOCIWFIRSTPRIV+24)
172 -#define IEEE80211_IOCTL_WDSADDMAC (SIOCIWFIRSTPRIV+26)
173 -#define IEEE80211_IOCTL_WDSDELMAC (SIOCIWFIRSTPRIV+28)
174 +#define IEEE80211_IOCTL_WDSADDMAC (SIOCIWFIRSTPRIV+25)
175 +#define IEEE80211_IOCTL_WDSSETMAC (SIOCIWFIRSTPRIV+26)
176 #define IEEE80211_IOCTL_KICKMAC (SIOCIWFIRSTPRIV+30)
177 #define IEEE80211_IOCTL_SETSCANLIST (SIOCIWFIRSTPRIV+31)
178
179 --- a/net80211/ieee80211_linux.h
180 +++ b/net80211/ieee80211_linux.h
181 @@ -650,5 +650,5 @@
182 int ieee80211_ioctl_create_vap(struct ieee80211com *, struct ifreq *,
183 struct net_device *);
184 struct ieee80211vap *ieee80211_create_vap(struct ieee80211com *, char *,
185 - struct net_device *, int, int);
186 + struct net_device *, int, int, struct ieee80211vap *);
187 #endif /* _NET80211_IEEE80211_LINUX_H_ */
188 --- a/net80211/ieee80211_var.h
189 +++ b/net80211/ieee80211_var.h
190 @@ -187,6 +187,12 @@
191 struct ieee80211_proc_entry *iv_proc_entries;
192 struct vlan_group *iv_vlgrp; /* vlan group state */
193
194 + /* list of wds links */
195 + TAILQ_HEAD(, ieee80211vap) iv_wdslinks;
196 + TAILQ_ENTRY(ieee80211vap) iv_wdsnext;
197 + struct ieee80211vap *iv_master;
198 + struct ieee80211_node *iv_wdsnode;
199 +
200 TAILQ_ENTRY(ieee80211vap) iv_next; /* list of vap instances */
201 struct ieee80211com *iv_ic; /* back ptr to common state */
202 u_int32_t iv_debug; /* debug msg flags */
203 @@ -447,7 +453,7 @@
204 atomic_t ic_node_counter;
205 /* Virtual AP create/delete */
206 struct ieee80211vap *(*ic_vap_create)(struct ieee80211com *,
207 - const char *, int, int, struct net_device *);
208 + const char *, int, int, struct net_device *, struct ieee80211vap *);
209 void (*ic_vap_delete)(struct ieee80211vap *);
210
211 /* Send/recv 802.11 management frame */
212 @@ -703,7 +709,7 @@
213 int ieee80211_ifattach(struct ieee80211com *);
214 void ieee80211_ifdetach(struct ieee80211com *);
215 int ieee80211_vap_setup(struct ieee80211com *, struct net_device *,
216 - const char *, int, int);
217 + const char *, int, int, struct ieee80211vap *);
218 int ieee80211_vap_attach(struct ieee80211vap *, ifm_change_cb_t, ifm_stat_cb_t);
219 void ieee80211_vap_detach(struct ieee80211vap *);
220 void ieee80211_mark_dfs(struct ieee80211com *, struct ieee80211_channel *);
221 --- a/net80211/ieee80211_wireless.c
222 +++ b/net80211/ieee80211_wireless.c
223 @@ -2190,7 +2190,7 @@
224 ieee80211_scan_flush(ic); /* NB: could optimize */
225
226 if (!(xrvap = ic->ic_vap_create(ic, name, IEEE80211_M_HOSTAP,
227 - IEEE80211_VAP_XR | IEEE80211_CLONE_BSSID, dev)))
228 + IEEE80211_VAP_XR | IEEE80211_CLONE_BSSID, dev, NULL)))
229 return;
230
231 /* We use iv_xrvap to link to the parent VAP as well */
232 @@ -3801,74 +3801,51 @@
233 return 0;
234 }
235
236 +#define WDSNAME ".wds%d"
237 static int
238 -ieee80211_ioctl_wdsmac(struct net_device *dev, struct iw_request_info *info,
239 +ieee80211_ioctl_wdsaddmac(struct net_device *dev, struct iw_request_info *info,
240 void *w, char *extra)
241 {
242 struct ieee80211vap *vap = dev->priv;
243 struct sockaddr *sa = (struct sockaddr *)extra;
244 + struct ieee80211com *ic = vap->iv_ic;
245 + struct ieee80211vap *avp;
246 + char *name;
247
248 - if (!IEEE80211_ADDR_NULL(vap->wds_mac)) {
249 - printk("%s: Failed to add WDS MAC: " MAC_FMT "\n", dev->name,
250 - MAC_ADDR(sa->sa_data));
251 - printk("%s: Device already has WDS mac address attached,"
252 - " remove first\n", dev->name);
253 - return -1;
254 - }
255 -
256 - memcpy(vap->wds_mac, sa->sa_data, IEEE80211_ADDR_LEN);
257 -
258 - printk("%s: Added WDS MAC: " MAC_FMT "\n", dev->name,
259 - MAC_ADDR(vap->wds_mac));
260 + name = kmalloc(strlen(vap->iv_dev->name) + sizeof(WDSNAME) + 1, GFP_KERNEL);
261 + if (!name)
262 + return -ENOMEM;
263
264 - if (IS_UP(vap->iv_dev)) {
265 - /* Force us back to scan state to force us to go back through RUN
266 - * state and create/pin the WDS peer node into memory. */
267 - return ieee80211_new_state(vap, IEEE80211_S_SCAN, 0);
268 - }
269 + strcpy(name, vap->iv_dev->name);
270 + strcat(name, WDSNAME);
271 + avp = ieee80211_create_vap(ic, name, ic->ic_dev, IEEE80211_M_WDS, 0, vap);
272 + kfree(name);
273 + if (!avp)
274 + return -ENOMEM;
275
276 + memcpy(avp->wds_mac, sa->sa_data, IEEE80211_ADDR_LEN);
277 return 0;
278 }
279 +#undef WDSNAME
280
281 static int
282 -ieee80211_ioctl_wdsdelmac(struct net_device *dev, struct iw_request_info *info,
283 +ieee80211_ioctl_wdssetmac(struct net_device *dev, struct iw_request_info *info,
284 void *w, char *extra)
285 {
286 struct ieee80211vap *vap = dev->priv;
287 struct sockaddr *sa = (struct sockaddr *)extra;
288 - struct ieee80211com *ic = vap->iv_ic;
289 - struct ieee80211_node *wds_ni;
290
291 - /* WDS Mac address filed already? */
292 - if (IEEE80211_ADDR_NULL(vap->wds_mac))
293 - return 0;
294 + if (vap->iv_opmode != IEEE80211_M_WDS)
295 + return -EINVAL;
296
297 - /* Compare suplied MAC address with WDS MAC of this interface
298 - * remove when mac address is known
299 - */
300 - if (memcmp(vap->wds_mac, sa->sa_data, IEEE80211_ADDR_LEN) == 0) {
301 - if (IS_UP(vap->iv_dev)) {
302 - wds_ni = ieee80211_find_txnode(vap, vap->wds_mac);
303 - if (wds_ni != NULL) {
304 - /* Release reference created by find node */
305 - ieee80211_unref_node(&wds_ni);
306 - /* Release reference created by transition to RUN state,
307 - * [pinning peer node into the table] */
308 - ieee80211_unref_node(&wds_ni);
309 - }
310 - }
311 - memset(vap->wds_mac, 0x00, IEEE80211_ADDR_LEN);
312 - if (IS_UP(vap->iv_dev)) {
313 - /* This leaves a dead WDS node, until started again */
314 - return ic->ic_reset(ic->ic_dev);
315 - }
316 - return 0;
317 + memcpy(vap->wds_mac, sa->sa_data, IEEE80211_ADDR_LEN);
318 + if (IS_UP(vap->iv_dev)) {
319 + /* Force us back to scan state to force us to go back through RUN
320 + * state and create/pin the WDS peer node into memory. */
321 + return ieee80211_new_state(vap, IEEE80211_S_SCAN, 0);
322 }
323
324 - printk("%s: WDS MAC address " MAC_FMT " is not known by this interface\n",
325 - dev->name, MAC_ADDR(sa->sa_data));
326 -
327 - return -1;
328 + return 0;
329 }
330
331 /*
332 @@ -5391,8 +5368,8 @@
333 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "kickmac"},
334 { IEEE80211_IOCTL_WDSADDMAC,
335 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,"wds_add" },
336 - { IEEE80211_IOCTL_WDSDELMAC,
337 - IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,"wds_del" },
338 + { IEEE80211_IOCTL_WDSSETMAC,
339 + IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,"wds_set" },
340 { IEEE80211_IOCTL_SETCHANLIST,
341 IW_PRIV_TYPE_CHANLIST | IW_PRIV_SIZE_FIXED, 0,"setchanlist" },
342 { IEEE80211_IOCTL_GETCHANLIST,
343 @@ -5884,8 +5861,8 @@
344 #endif
345 set_priv(IEEE80211_IOCTL_ADDMAC, ieee80211_ioctl_addmac),
346 set_priv(IEEE80211_IOCTL_DELMAC, ieee80211_ioctl_delmac),
347 - set_priv(IEEE80211_IOCTL_WDSADDMAC, ieee80211_ioctl_wdsmac),
348 - set_priv(IEEE80211_IOCTL_WDSDELMAC, ieee80211_ioctl_wdsdelmac),
349 + set_priv(IEEE80211_IOCTL_WDSADDMAC, ieee80211_ioctl_wdsaddmac),
350 + set_priv(IEEE80211_IOCTL_WDSSETMAC, ieee80211_ioctl_wdssetmac),
351 set_priv(IEEE80211_IOCTL_KICKMAC, ieee80211_ioctl_kickmac),
352 set_priv(IEEE80211_IOCTL_SETSCANLIST, ieee80211_ioctl_setscanlist),
353 #ifdef ATH_REVERSE_ENGINEERING
354 @@ -5956,7 +5933,7 @@
355
356 strncpy(name, cp.icp_name, sizeof(name));
357
358 - vap = ieee80211_create_vap(ic, name, mdev, cp.icp_opmode, cp.icp_flags);
359 + vap = ieee80211_create_vap(ic, name, mdev, cp.icp_opmode, cp.icp_flags, NULL);
360 if (vap == NULL)
361 return -EIO;
362
363 @@ -5973,9 +5950,9 @@
364 */
365 struct ieee80211vap*
366 ieee80211_create_vap(struct ieee80211com *ic, char *name,
367 - struct net_device *mdev, int opmode, int opflags)
368 + struct net_device *mdev, int opmode, int opflags, struct ieee80211vap *master)
369 {
370 - return ic->ic_vap_create(ic, name, opmode, opflags, mdev);
371 + return ic->ic_vap_create(ic, name, opmode, opflags, mdev, master);
372 }
373 EXPORT_SYMBOL(ieee80211_create_vap);
374
375 --- a/net80211/ieee80211_input.c
376 +++ b/net80211/ieee80211_input.c
377 @@ -201,6 +201,7 @@
378 struct ieee80211_node * ni = ni_or_null;
379 struct ieee80211com *ic = vap->iv_ic;
380 struct net_device *dev = vap->iv_dev;
381 + struct ieee80211_node *ni_wds = NULL;
382 struct ieee80211_frame *wh;
383 struct ieee80211_key *key;
384 struct ether_header *eh;
385 @@ -545,11 +546,29 @@
386 * the node table for the packet source address (addr4).
387 * If not, add one.
388 */
389 - /* XXX: Useless node mgmt API; make better */
390 +
391 + /* check for wds link first */
392 if (dir == IEEE80211_FC1_DIR_DSTODS) {
393 - struct ieee80211_node_table *nt;
394 + struct ieee80211vap *avp;
395 +
396 + TAILQ_FOREACH(avp, &vap->iv_wdslinks, iv_wdsnext) {
397 + if (!memcmp(avp->wds_mac, wh->i_addr2, IEEE80211_ADDR_LEN)) {
398 + IEEE80211_LOCK_IRQ(ni->ni_ic);
399 + ni_wds = avp->iv_wdsnode;
400 + IEEE80211_UNLOCK_IRQ(ni->ni_ic);
401 + break;
402 + }
403 + }
404 + if (ni_wds != NULL) {
405 + ieee80211_unref_node(&ni);
406 + ni = ieee80211_ref_node(ni_wds);
407 + }
408 + }
409 +
410 + /* XXX: Useless node mgmt API; make better */
411 + if ((dir == IEEE80211_FC1_DIR_DSTODS) && !ni_wds) {
412 + struct ieee80211_node_table *nt = &ic->ic_sta;
413 struct ieee80211_frame_addr4 *wh4;
414 - struct ieee80211_node *ni_wds;
415
416 if (!(vap->iv_flags_ext & IEEE80211_FEXT_WDS)) {
417 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
418 @@ -557,7 +576,6 @@
419 goto err;
420 }
421 wh4 = (struct ieee80211_frame_addr4 *)skb->data;
422 - nt = &ic->ic_sta;
423 ni_wds = ieee80211_find_wds_node(nt, wh4->i_addr4);
424 /* Last call increments ref count if !NULL */
425 if ((ni_wds != NULL) && (ni_wds != ni)) {
426 @@ -3084,8 +3102,7 @@
427 (vap->iv_opmode == IEEE80211_M_STA && ni->ni_associd) ||
428 (vap->iv_opmode == IEEE80211_M_IBSS) ||
429 ((subtype == IEEE80211_FC0_SUBTYPE_BEACON) &&
430 - (vap->iv_opmode == IEEE80211_M_HOSTAP) &&
431 - (ic->ic_protmode != IEEE80211_PROT_NONE)))) {
432 + (vap->iv_opmode == IEEE80211_M_HOSTAP)))) {
433 vap->iv_stats.is_rx_mgtdiscard++;
434 return;
435 }
436 @@ -3471,13 +3488,53 @@
437 */
438 if (ic->ic_flags & IEEE80211_F_SCAN) {
439 ieee80211_add_scan(vap, &scan, wh, subtype, rssi, rtsf);
440 - return;
441 }
442 - if ((vap->iv_opmode == IEEE80211_M_IBSS) &&
443 - (scan.capinfo & IEEE80211_CAPINFO_IBSS)) {
444 + /* NB: Behavior of WDS-Link and Ad-Hoc is very similar here:
445 + * When we receive a beacon that belongs to the AP that we're
446 + * connected to, use it to refresh the local node info.
447 + * If no node is found, go through the vap's wds link table
448 + * and try to find the sub-vap that is interested in this address
449 + */
450 + if (((vap->iv_opmode == IEEE80211_M_IBSS) &&
451 + (scan.capinfo & IEEE80211_CAPINFO_IBSS)) ||
452 + (((vap->iv_opmode == IEEE80211_M_HOSTAP) ||
453 + (vap->iv_opmode == IEEE80211_M_WDS)) &&
454 + (scan.capinfo & IEEE80211_CAPINFO_ESS))) {
455 + struct ieee80211vap *avp = NULL;
456 +
457 + IEEE80211_LOCK_IRQ(vap->iv_ic);
458 + if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
459 + int found = 0;
460 +
461 + TAILQ_FOREACH(avp, &vap->iv_wdslinks, iv_wdsnext) {
462 + if (!memcmp(avp->wds_mac, wh->i_addr2, IEEE80211_ADDR_LEN)) {
463 + found = 1;
464 + break;
465 + }
466 + }
467 + if (found) {
468 + if (!avp->iv_wdsnode)
469 + break;
470 + ni = ni_or_null = avp->iv_wdsnode;
471 + } else {
472 + avp = NULL;
473 + }
474 + }
475 + IEEE80211_UNLOCK_IRQ(vap->iv_ic);
476 +
477 +
478 if (ni_or_null == NULL) {
479 - /* Create a new entry in the neighbor table. */
480 - ni = ieee80211_add_neighbor(vap, wh, &scan);
481 + if (avp) {
482 + IEEE80211_LOCK_IRQ(ic);
483 + ni = ieee80211_add_neighbor(avp, wh, &scan);
484 + /* force assoc */
485 + ni->ni_associd |= 0xc000;
486 + avp->iv_wdsnode = ieee80211_ref_node(ni);
487 + IEEE80211_UNLOCK_IRQ(ic);
488 + } else if (vap->iv_opmode == IEEE80211_M_IBSS) {
489 + /* Create a new entry in the neighbor table. */
490 + ni = ieee80211_add_neighbor(vap, wh, &scan);
491 + }
492 } else {
493 /*
494 * Copy data from beacon to neighbor table.
495 @@ -3490,6 +3547,7 @@
496 IEEE80211_ADDR_COPY(ni->ni_bssid, wh->i_addr3);
497 memcpy(ni->ni_tstamp.data, scan.tstamp,
498 sizeof(ni->ni_tstamp));
499 + ni->ni_inact = ni->ni_inact_reload;
500 ni->ni_intval =
501 IEEE80211_BINTVAL_SANITISE(scan.bintval);
502 ni->ni_capinfo = scan.capinfo;
503 --- a/net80211/ieee80211_node.c
504 +++ b/net80211/ieee80211_node.c
505 @@ -1553,22 +1553,24 @@
506 ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) == IEEE80211_FC0_SUBTYPE_PS_POLL)
507 struct ieee80211_node_table *nt;
508 struct ieee80211_node *ni;
509 + u_int8_t *addr;
510 +
511 + if (IS_CTL(wh) && !IS_PSPOLL(wh) /*&& !IS_RTS(ah)*/)
512 + addr = wh->i_addr1;
513 + else
514 + addr = wh->i_addr2;
515 +
516 + if (IEEE80211_IS_MULTICAST(addr))
517 + return NULL;
518
519 /* XXX check ic_bss first in station mode */
520 /* XXX 4-address frames? */
521 nt = &ic->ic_sta;
522 IEEE80211_NODE_TABLE_LOCK_IRQ(nt);
523 - if (IS_CTL(wh) && !IS_PSPOLL(wh) /*&& !IS_RTS(ah)*/)
524 #ifdef IEEE80211_DEBUG_REFCNT
525 - ni = ieee80211_find_node_locked_debug(nt, wh->i_addr1, func, line);
526 + ni = ieee80211_find_node_locked_debug(nt, addr, func, line);
527 #else
528 - ni = ieee80211_find_node_locked(nt, wh->i_addr1);
529 -#endif
530 - else
531 -#ifdef IEEE80211_DEBUG_REFCNT
532 - ni = ieee80211_find_node_locked_debug(nt, wh->i_addr2, func, line);
533 -#else
534 - ni = ieee80211_find_node_locked(nt, wh->i_addr2);
535 + ni = ieee80211_find_node_locked(nt, addr);
536 #endif
537 IEEE80211_NODE_TABLE_UNLOCK_IRQ(nt);
538
539 @@ -1669,6 +1671,11 @@
540 {
541 struct ieee80211vap *vap = ni->ni_vap;
542
543 + IEEE80211_LOCK_IRQ(ni->ni_ic);
544 + if (vap && ni == vap->iv_wdsnode)
545 + vap->iv_wdsnode = NULL;
546 + IEEE80211_UNLOCK_IRQ(ni->ni_ic);
547 +
548 atomic_dec(&ni->ni_ic->ic_node_counter);
549 node_print_message(IEEE80211_MSG_NODE|IEEE80211_MSG_NODE_REF,
550 1 /* show counter */,
551 @@ -1781,22 +1788,6 @@
552 jiffies > ni->ni_rxfragstamp + HZ) {
553 ieee80211_dev_kfree_skb(&ni->ni_rxfrag);
554 }
555 - /*
556 - * Special case ourself; we may be idle for extended periods
557 - * of time and regardless reclaiming our state is wrong.
558 - * Special case a WDS link: it may be dead or idle, but it is
559 - * never ok to reclaim it, as this will block transmissions
560 - * and nobody will recreate the node when the WDS peer is
561 - * available again. */
562 - if ((ni == ni->ni_vap->iv_bss) ||
563 - (ni->ni_vap->iv_opmode == IEEE80211_M_WDS &&
564 - !memcmp(ni->ni_macaddr, ni->ni_vap->wds_mac, ETH_ALEN)))
565 - {
566 - /* NB: don't permit it to go negative */
567 - if (ni->ni_inact > 0)
568 - ni->ni_inact--;
569 - continue;
570 - }
571 ni->ni_inact--;
572 if (ni->ni_associd != 0 || isadhoc) {
573 struct ieee80211vap *vap = ni->ni_vap;
574 --- a/net80211/ieee80211_output.c
575 +++ b/net80211/ieee80211_output.c
576 @@ -246,10 +246,16 @@
577 * things like power save.
578 */
579 eh = (struct ether_header *)skb->data;
580 - if (vap->iv_opmode == IEEE80211_M_WDS)
581 - ni = ieee80211_find_txnode(vap, vap->wds_mac);
582 - else
583 + if (vap->iv_opmode == IEEE80211_M_WDS) {
584 + IEEE80211_LOCK_IRQ(ic);
585 + ni = vap->iv_wdsnode;
586 + IEEE80211_UNLOCK_IRQ(ic);
587 + if (!ni)
588 + goto bad;
589 + ni = ieee80211_ref_node(vap->iv_wdsnode);
590 + } else {
591 ni = ieee80211_find_txnode(vap, eh->ether_dhost);
592 + }
593 if (ni == NULL) {
594 /* NB: ieee80211_find_txnode does stat+msg */
595 goto bad;
596 @@ -788,7 +794,7 @@
597 break;
598 case IEEE80211_M_WDS:
599 use4addr = 1;
600 - ismulticast = IEEE80211_IS_MULTICAST(ni->ni_macaddr);
601 + ismulticast = 0;
602 break;
603 case IEEE80211_M_HOSTAP:
604 if (!IEEE80211_IS_MULTICAST(eh.ether_dhost) &&
605 @@ -973,7 +979,7 @@
606 break;
607 case IEEE80211_M_WDS:
608 wh->i_fc[1] = IEEE80211_FC1_DIR_DSTODS;
609 - IEEE80211_ADDR_COPY(wh->i_addr1, ni->ni_macaddr);
610 + IEEE80211_ADDR_COPY(wh->i_addr1, vap->wds_mac);
611 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
612 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_dhost);
613 IEEE80211_ADDR_COPY(WH4(wh)->i_addr4, eh.ether_shost);
614 --- a/tools/athkey.c
615 +++ b/tools/athkey.c
616 @@ -118,7 +118,7 @@
617 IOCTL_ERR(IEEE80211_IOCTL_ADDMAC),
618 IOCTL_ERR(IEEE80211_IOCTL_DELMAC),
619 IOCTL_ERR(IEEE80211_IOCTL_WDSADDMAC),
620 - IOCTL_ERR(IEEE80211_IOCTL_WDSDELMAC),
621 + IOCTL_ERR(IEEE80211_IOCTL_WDSSETMAC),
622 IOCTL_ERR(IEEE80211_IOCTL_READREG),
623 IOCTL_ERR(IEEE80211_IOCTL_WRITEREG),
624 };
625 --- a/tools/athchans.c
626 +++ b/tools/athchans.c
627 @@ -118,7 +118,7 @@
628 IOCTL_ERR(IEEE80211_IOCTL_ADDMAC),
629 IOCTL_ERR(IEEE80211_IOCTL_DELMAC),
630 IOCTL_ERR(IEEE80211_IOCTL_WDSADDMAC),
631 - IOCTL_ERR(IEEE80211_IOCTL_WDSDELMAC),
632 + IOCTL_ERR(IEEE80211_IOCTL_WDSSETMAC),
633 IOCTL_ERR(IEEE80211_IOCTL_READREG),
634 IOCTL_ERR(IEEE80211_IOCTL_WRITEREG),
635 };
636 --- a/tools/wlanconfig.c
637 +++ b/tools/wlanconfig.c
638 @@ -968,7 +968,7 @@
639 IOCTL_ERR(IEEE80211_IOCTL_ADDMAC),
640 IOCTL_ERR(IEEE80211_IOCTL_DELMAC),
641 IOCTL_ERR(IEEE80211_IOCTL_WDSADDMAC),
642 - IOCTL_ERR(IEEE80211_IOCTL_WDSDELMAC),
643 + IOCTL_ERR(IEEE80211_IOCTL_WDSSETMAC),
644 IOCTL_ERR(IEEE80211_IOCTL_READREG),
645 IOCTL_ERR(IEEE80211_IOCTL_WRITEREG),
646 };
647 --- a/net80211/ieee80211_proto.c
648 +++ b/net80211/ieee80211_proto.c
649 @@ -1557,57 +1557,12 @@
650 switch (ostate) {
651 case IEEE80211_S_INIT:
652 if (vap->iv_opmode == IEEE80211_M_MONITOR ||
653 - vap->iv_opmode == IEEE80211_M_WDS ||
654 vap->iv_opmode == IEEE80211_M_HOSTAP) {
655 /*
656 * Already have a channel; bypass the
657 * scan and startup immediately.
658 */
659 ieee80211_create_ibss(vap, ic->ic_curchan);
660 -
661 - /* In WDS mode, allocate and initialize peer node. */
662 - if (vap->iv_opmode == IEEE80211_M_WDS) {
663 - /* XXX: This is horribly non-atomic. */
664 - struct ieee80211_node *wds_ni =
665 - ieee80211_find_node(&ic->ic_sta,
666 - vap->wds_mac);
667 -
668 - if (wds_ni == NULL) {
669 - wds_ni = ieee80211_alloc_node_table(
670 - vap,
671 - vap->wds_mac);
672 - if (wds_ni != NULL) {
673 - ieee80211_add_wds_addr(
674 - &ic->ic_sta,
675 - wds_ni,
676 - vap->wds_mac,
677 - 1);
678 - ieee80211_ref_node(wds_ni); /* pin in memory */
679 - }
680 - else
681 - IEEE80211_DPRINTF(
682 - vap,
683 - IEEE80211_MSG_NODE,
684 - "%s: Unable to "
685 - "allocate node for "
686 - "WDS: " MAC_FMT "\n",
687 - __func__,
688 - MAC_ADDR(
689 - vap->wds_mac)
690 - );
691 - }
692 -
693 - if (wds_ni != NULL) {
694 - ieee80211_node_authorize(wds_ni);
695 - wds_ni->ni_chan =
696 - vap->iv_bss->ni_chan;
697 - wds_ni->ni_capinfo =
698 - ni->ni_capinfo;
699 - wds_ni->ni_associd = 1;
700 - wds_ni->ni_ath_flags =
701 - vap->iv_ath_cap;
702 - }
703 - }
704 break;
705 }
706 /* fall thru... */