fix a rare wds related noderef issue
[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 + 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 @@ 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 @@ -396,7 +396,7 @@ EXPORT_SYMBOL(ieee80211_ifdetach);
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 @@ ieee80211_vap_setup(struct ieee80211com
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 @@ ieee80211_vap_attach(struct ieee80211vap
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 @@ ieee80211_vap_detach(struct ieee80211vap
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 @@ struct ieee80211req {
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 @@ struct ieee80211req_scan_result {
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 @@ struct ifreq;
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 @@ struct ieee80211vap {
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 @@ struct ieee80211com {
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 @@ MALLOC_DECLARE(M_80211_VAP);
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 @@ ieee80211_setupxr(struct ieee80211vap *v
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 @@ ieee80211_ioctl_setmlme(struct net_devic
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 @@ static const struct iw_priv_args ieee802
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 @@ static const iw_handler ieee80211_priv_h
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 @@ ieee80211_ioctl_create_vap(struct ieee80
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 @@ EXPORT_SYMBOL(ieee80211_ioctl_create_vap
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 @@ ieee80211_input(struct ieee80211vap * va
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,30 @@ ieee80211_input(struct ieee80211vap * va
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 + if (ni_or_null == NULL)
406 + ieee80211_unref_node(&ni);
407 + ni = ieee80211_ref_node(ni_wds);
408 + }
409 + }
410 +
411 + /* XXX: Useless node mgmt API; make better */
412 + if ((dir == IEEE80211_FC1_DIR_DSTODS) && !ni_wds) {
413 + struct ieee80211_node_table *nt = &ic->ic_sta;
414 struct ieee80211_frame_addr4 *wh4;
415 - struct ieee80211_node *ni_wds;
416
417 if (!(vap->iv_flags_ext & IEEE80211_FEXT_WDS)) {
418 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
419 @@ -557,7 +577,6 @@ ieee80211_input(struct ieee80211vap * va
420 goto err;
421 }
422 wh4 = (struct ieee80211_frame_addr4 *)skb->data;
423 - nt = &ic->ic_sta;
424 ni_wds = ieee80211_find_wds_node(nt, wh4->i_addr4);
425 /* Last call increments ref count if !NULL */
426 if ((ni_wds != NULL) && (ni_wds != ni)) {
427 @@ -3084,8 +3103,7 @@ ieee80211_recv_mgmt(struct ieee80211vap
428 (vap->iv_opmode == IEEE80211_M_STA && ni->ni_associd) ||
429 (vap->iv_opmode == IEEE80211_M_IBSS) ||
430 ((subtype == IEEE80211_FC0_SUBTYPE_BEACON) &&
431 - (vap->iv_opmode == IEEE80211_M_HOSTAP) &&
432 - (ic->ic_protmode != IEEE80211_PROT_NONE)))) {
433 + (vap->iv_opmode == IEEE80211_M_HOSTAP)))) {
434 vap->iv_stats.is_rx_mgtdiscard++;
435 return;
436 }
437 @@ -3471,13 +3489,53 @@ ieee80211_recv_mgmt(struct ieee80211vap
438 */
439 if (ic->ic_flags & IEEE80211_F_SCAN) {
440 ieee80211_add_scan(vap, &scan, wh, subtype, rssi, rtsf);
441 - return;
442 }
443 - if ((vap->iv_opmode == IEEE80211_M_IBSS) &&
444 - (scan.capinfo & IEEE80211_CAPINFO_IBSS)) {
445 + /* NB: Behavior of WDS-Link and Ad-Hoc is very similar here:
446 + * When we receive a beacon that belongs to the AP that we're
447 + * connected to, use it to refresh the local node info.
448 + * If no node is found, go through the vap's wds link table
449 + * and try to find the sub-vap that is interested in this address
450 + */
451 + if (((vap->iv_opmode == IEEE80211_M_IBSS) &&
452 + (scan.capinfo & IEEE80211_CAPINFO_IBSS)) ||
453 + (((vap->iv_opmode == IEEE80211_M_HOSTAP) ||
454 + (vap->iv_opmode == IEEE80211_M_WDS)) &&
455 + (scan.capinfo & IEEE80211_CAPINFO_ESS))) {
456 + struct ieee80211vap *avp = NULL;
457 +
458 + IEEE80211_LOCK_IRQ(vap->iv_ic);
459 + if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
460 + int found = 0;
461 +
462 + TAILQ_FOREACH(avp, &vap->iv_wdslinks, iv_wdsnext) {
463 + if (!memcmp(avp->wds_mac, wh->i_addr2, IEEE80211_ADDR_LEN)) {
464 + found = 1;
465 + break;
466 + }
467 + }
468 + if (found) {
469 + if (!avp->iv_wdsnode)
470 + break;
471 + ni = ni_or_null = avp->iv_wdsnode;
472 + } else {
473 + avp = NULL;
474 + }
475 + }
476 + IEEE80211_UNLOCK_IRQ(vap->iv_ic);
477 +
478 +
479 if (ni_or_null == NULL) {
480 - /* Create a new entry in the neighbor table. */
481 - ni = ieee80211_add_neighbor(vap, wh, &scan);
482 + if (avp) {
483 + IEEE80211_LOCK_IRQ(ic);
484 + ni = ieee80211_add_neighbor(avp, wh, &scan);
485 + /* force assoc */
486 + ni->ni_associd |= 0xc000;
487 + avp->iv_wdsnode = ieee80211_ref_node(ni);
488 + IEEE80211_UNLOCK_IRQ(ic);
489 + } else if (vap->iv_opmode == IEEE80211_M_IBSS) {
490 + /* Create a new entry in the neighbor table. */
491 + ni = ieee80211_add_neighbor(vap, wh, &scan);
492 + }
493 } else {
494 /*
495 * Copy data from beacon to neighbor table.
496 @@ -3490,6 +3548,7 @@ ieee80211_recv_mgmt(struct ieee80211vap
497 IEEE80211_ADDR_COPY(ni->ni_bssid, wh->i_addr3);
498 memcpy(ni->ni_tstamp.data, scan.tstamp,
499 sizeof(ni->ni_tstamp));
500 + ni->ni_inact = ni->ni_inact_reload;
501 ni->ni_intval =
502 IEEE80211_BINTVAL_SANITISE(scan.bintval);
503 ni->ni_capinfo = scan.capinfo;
504 --- a/net80211/ieee80211_node.c
505 +++ b/net80211/ieee80211_node.c
506 @@ -1553,22 +1553,24 @@ ieee80211_find_rxnode(struct ieee80211co
507 ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) == IEEE80211_FC0_SUBTYPE_PS_POLL)
508 struct ieee80211_node_table *nt;
509 struct ieee80211_node *ni;
510 + const u_int8_t *addr;
511 +
512 + if (IS_CTL(wh) && !IS_PSPOLL(wh) /*&& !IS_RTS(ah)*/)
513 + addr = wh->i_addr1;
514 + else
515 + addr = wh->i_addr2;
516 +
517 + if (IEEE80211_IS_MULTICAST(addr))
518 + return NULL;
519
520 /* XXX check ic_bss first in station mode */
521 /* XXX 4-address frames? */
522 nt = &ic->ic_sta;
523 IEEE80211_NODE_TABLE_LOCK_IRQ(nt);
524 - if (IS_CTL(wh) && !IS_PSPOLL(wh) /*&& !IS_RTS(ah)*/)
525 #ifdef IEEE80211_DEBUG_REFCNT
526 - ni = ieee80211_find_node_locked_debug(nt, wh->i_addr1, func, line);
527 + ni = ieee80211_find_node_locked_debug(nt, addr, func, line);
528 #else
529 - ni = ieee80211_find_node_locked(nt, wh->i_addr1);
530 -#endif
531 - else
532 -#ifdef IEEE80211_DEBUG_REFCNT
533 - ni = ieee80211_find_node_locked_debug(nt, wh->i_addr2, func, line);
534 -#else
535 - ni = ieee80211_find_node_locked(nt, wh->i_addr2);
536 + ni = ieee80211_find_node_locked(nt, addr);
537 #endif
538 IEEE80211_NODE_TABLE_UNLOCK_IRQ(nt);
539
540 @@ -1669,6 +1671,11 @@ ieee80211_free_node(struct ieee80211_nod
541 {
542 struct ieee80211vap *vap = ni->ni_vap;
543
544 + IEEE80211_LOCK_IRQ(ni->ni_ic);
545 + if (vap && ni == vap->iv_wdsnode)
546 + vap->iv_wdsnode = NULL;
547 + IEEE80211_UNLOCK_IRQ(ni->ni_ic);
548 +
549 atomic_dec(&ni->ni_ic->ic_node_counter);
550 node_print_message(IEEE80211_MSG_NODE|IEEE80211_MSG_NODE_REF,
551 1 /* show counter */,
552 @@ -1781,22 +1788,6 @@ restart:
553 jiffies > ni->ni_rxfragstamp + HZ) {
554 ieee80211_dev_kfree_skb(&ni->ni_rxfrag);
555 }
556 - /*
557 - * Special case ourself; we may be idle for extended periods
558 - * of time and regardless reclaiming our state is wrong.
559 - * Special case a WDS link: it may be dead or idle, but it is
560 - * never ok to reclaim it, as this will block transmissions
561 - * and nobody will recreate the node when the WDS peer is
562 - * available again. */
563 - if ((ni == ni->ni_vap->iv_bss) ||
564 - (ni->ni_vap->iv_opmode == IEEE80211_M_WDS &&
565 - !memcmp(ni->ni_macaddr, ni->ni_vap->wds_mac, ETH_ALEN)))
566 - {
567 - /* NB: don't permit it to go negative */
568 - if (ni->ni_inact > 0)
569 - ni->ni_inact--;
570 - continue;
571 - }
572 ni->ni_inact--;
573 if (ni->ni_associd != 0 || isadhoc) {
574 struct ieee80211vap *vap = ni->ni_vap;
575 --- a/net80211/ieee80211_output.c
576 +++ b/net80211/ieee80211_output.c
577 @@ -246,10 +246,16 @@ ieee80211_hardstart(struct sk_buff *skb,
578 * things like power save.
579 */
580 eh = (struct ether_header *)skb->data;
581 - if (vap->iv_opmode == IEEE80211_M_WDS)
582 - ni = ieee80211_find_txnode(vap, vap->wds_mac);
583 - else
584 + if (vap->iv_opmode == IEEE80211_M_WDS) {
585 + IEEE80211_LOCK_IRQ(ic);
586 + ni = vap->iv_wdsnode;
587 + IEEE80211_UNLOCK_IRQ(ic);
588 + if (!ni)
589 + goto bad;
590 + ni = ieee80211_ref_node(vap->iv_wdsnode);
591 + } else {
592 ni = ieee80211_find_txnode(vap, eh->ether_dhost);
593 + }
594 if (ni == NULL) {
595 /* NB: ieee80211_find_txnode does stat+msg */
596 goto bad;
597 @@ -788,7 +794,7 @@ ieee80211_encap(struct ieee80211_node *n
598 break;
599 case IEEE80211_M_WDS:
600 use4addr = 1;
601 - ismulticast = IEEE80211_IS_MULTICAST(ni->ni_macaddr);
602 + ismulticast = 0;
603 break;
604 case IEEE80211_M_HOSTAP:
605 if (!IEEE80211_IS_MULTICAST(eh.ether_dhost) &&
606 @@ -973,7 +979,7 @@ ieee80211_encap(struct ieee80211_node *n
607 break;
608 case IEEE80211_M_WDS:
609 wh->i_fc[1] = IEEE80211_FC1_DIR_DSTODS;
610 - IEEE80211_ADDR_COPY(wh->i_addr1, ni->ni_macaddr);
611 + IEEE80211_ADDR_COPY(wh->i_addr1, vap->wds_mac);
612 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
613 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_dhost);
614 IEEE80211_ADDR_COPY(WH4(wh)->i_addr4, eh.ether_shost);
615 --- a/tools/athkey.c
616 +++ b/tools/athkey.c
617 @@ -118,7 +118,7 @@ set80211priv(const char *dev, int op, vo
618 IOCTL_ERR(IEEE80211_IOCTL_ADDMAC),
619 IOCTL_ERR(IEEE80211_IOCTL_DELMAC),
620 IOCTL_ERR(IEEE80211_IOCTL_WDSADDMAC),
621 - IOCTL_ERR(IEEE80211_IOCTL_WDSDELMAC),
622 + IOCTL_ERR(IEEE80211_IOCTL_WDSSETMAC),
623 IOCTL_ERR(IEEE80211_IOCTL_READREG),
624 IOCTL_ERR(IEEE80211_IOCTL_WRITEREG),
625 };
626 --- a/tools/athchans.c
627 +++ b/tools/athchans.c
628 @@ -118,7 +118,7 @@ set80211priv(const char *dev, int op, vo
629 IOCTL_ERR(IEEE80211_IOCTL_ADDMAC),
630 IOCTL_ERR(IEEE80211_IOCTL_DELMAC),
631 IOCTL_ERR(IEEE80211_IOCTL_WDSADDMAC),
632 - IOCTL_ERR(IEEE80211_IOCTL_WDSDELMAC),
633 + IOCTL_ERR(IEEE80211_IOCTL_WDSSETMAC),
634 IOCTL_ERR(IEEE80211_IOCTL_READREG),
635 IOCTL_ERR(IEEE80211_IOCTL_WRITEREG),
636 };
637 --- a/tools/wlanconfig.c
638 +++ b/tools/wlanconfig.c
639 @@ -968,7 +968,7 @@ do80211priv(struct iwreq *iwr, const cha
640 IOCTL_ERR(IEEE80211_IOCTL_ADDMAC),
641 IOCTL_ERR(IEEE80211_IOCTL_DELMAC),
642 IOCTL_ERR(IEEE80211_IOCTL_WDSADDMAC),
643 - IOCTL_ERR(IEEE80211_IOCTL_WDSDELMAC),
644 + IOCTL_ERR(IEEE80211_IOCTL_WDSSETMAC),
645 IOCTL_ERR(IEEE80211_IOCTL_READREG),
646 IOCTL_ERR(IEEE80211_IOCTL_WRITEREG),
647 };
648 --- a/net80211/ieee80211_proto.c
649 +++ b/net80211/ieee80211_proto.c
650 @@ -1557,57 +1557,12 @@ __ieee80211_newstate(struct ieee80211vap
651 switch (ostate) {
652 case IEEE80211_S_INIT:
653 if (vap->iv_opmode == IEEE80211_M_MONITOR ||
654 - vap->iv_opmode == IEEE80211_M_WDS ||
655 vap->iv_opmode == IEEE80211_M_HOSTAP) {
656 /*
657 * Already have a channel; bypass the
658 * scan and startup immediately.
659 */
660 ieee80211_create_ibss(vap, ic->ic_curchan);
661 -
662 - /* In WDS mode, allocate and initialize peer node. */
663 - if (vap->iv_opmode == IEEE80211_M_WDS) {
664 - /* XXX: This is horribly non-atomic. */
665 - struct ieee80211_node *wds_ni =
666 - ieee80211_find_node(&ic->ic_sta,
667 - vap->wds_mac);
668 -
669 - if (wds_ni == NULL) {
670 - wds_ni = ieee80211_alloc_node_table(
671 - vap,
672 - vap->wds_mac);
673 - if (wds_ni != NULL) {
674 - ieee80211_add_wds_addr(
675 - &ic->ic_sta,
676 - wds_ni,
677 - vap->wds_mac,
678 - 1);
679 - ieee80211_ref_node(wds_ni); /* pin in memory */
680 - }
681 - else
682 - IEEE80211_DPRINTF(
683 - vap,
684 - IEEE80211_MSG_NODE,
685 - "%s: Unable to "
686 - "allocate node for "
687 - "WDS: " MAC_FMT "\n",
688 - __func__,
689 - MAC_ADDR(
690 - vap->wds_mac)
691 - );
692 - }
693 -
694 - if (wds_ni != NULL) {
695 - ieee80211_node_authorize(wds_ni);
696 - wds_ni->ni_chan =
697 - vap->iv_bss->ni_chan;
698 - wds_ni->ni_capinfo =
699 - ni->ni_capinfo;
700 - wds_ni->ni_associd = 1;
701 - wds_ni->ni_ath_flags =
702 - vap->iv_ath_cap;
703 - }
704 - }
705 break;
706 }
707 /* fall thru... */