f09739bfc129732663261efec4206d5b2cf19aa5
[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,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,25 @@ 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 + if (avp->iv_state != IEEE80211_S_INIT)
140 + ieee80211_stop(avp->iv_dev);
141 + ic->ic_vap_delete(avp);
142 + }
143
144 IEEE80211_CANCEL_TQUEUE(&vap->iv_stajoin1tq);
145 IEEE80211_LOCK_IRQ(ic);
146 - TAILQ_REMOVE(&ic->ic_vaps, vap, iv_next);
147 + if (vap->iv_wdsnode)
148 + ieee80211_unref_node(&vap->iv_wdsnode);
149 + if ((vap->iv_opmode == IEEE80211_M_WDS) &&
150 + (vap->iv_master != NULL))
151 + TAILQ_REMOVE(&vap->iv_master->iv_wdslinks, vap, iv_wdsnext);
152 + else
153 + TAILQ_REMOVE(&ic->ic_vaps, vap, iv_next);
154 +
155 if (TAILQ_EMPTY(&ic->ic_vaps)) /* reset to supported mode */
156 ic->ic_opmode = IEEE80211_M_STA;
157 IEEE80211_UNLOCK_IRQ(ic);
158 --- a/net80211/ieee80211_ioctl.h
159 +++ b/net80211/ieee80211_ioctl.h
160 @@ -474,7 +474,7 @@ struct ieee80211req {
161 #define IEEE80211_IOC_DTIM_PERIOD 52 /* DTIM period (beacons) */
162 #define IEEE80211_IOC_BEACON_INTERVAL 53 /* beacon interval (ms) */
163 #define IEEE80211_IOC_ADDMAC 54 /* add sta to MAC ACL table */
164 -#define IEEE80211_IOC_DELMAC 55 /* del sta from MAC ACL table */
165 +#define IEEE80211_IOC_SETMAC 55 /* set interface wds mac addr */
166 #define IEEE80211_IOC_FF 56 /* ATH fast frames (on, off) */
167 #define IEEE80211_IOC_TURBOP 57 /* ATH turbo' (on, off) */
168 #define IEEE80211_IOC_APPIEBUF 58 /* IE in the management frame */
169 @@ -552,8 +552,8 @@ struct ieee80211req_scan_result {
170 #define IEEE80211_IOCTL_HALMAP (SIOCIWFIRSTPRIV+21)
171 #define IEEE80211_IOCTL_ADDMAC (SIOCIWFIRSTPRIV+22)
172 #define IEEE80211_IOCTL_DELMAC (SIOCIWFIRSTPRIV+24)
173 -#define IEEE80211_IOCTL_WDSADDMAC (SIOCIWFIRSTPRIV+26)
174 -#define IEEE80211_IOCTL_WDSDELMAC (SIOCIWFIRSTPRIV+28)
175 +#define IEEE80211_IOCTL_WDSADDMAC (SIOCIWFIRSTPRIV+25)
176 +#define IEEE80211_IOCTL_WDSSETMAC (SIOCIWFIRSTPRIV+26)
177 #define IEEE80211_IOCTL_KICKMAC (SIOCIWFIRSTPRIV+30)
178 #define IEEE80211_IOCTL_SETSCANLIST (SIOCIWFIRSTPRIV+31)
179
180 --- a/net80211/ieee80211_linux.h
181 +++ b/net80211/ieee80211_linux.h
182 @@ -650,5 +650,5 @@ struct ifreq;
183 int ieee80211_ioctl_create_vap(struct ieee80211com *, struct ifreq *,
184 struct net_device *);
185 struct ieee80211vap *ieee80211_create_vap(struct ieee80211com *, char *,
186 - struct net_device *, int, int);
187 + struct net_device *, int, int, struct ieee80211vap *);
188 #endif /* _NET80211_IEEE80211_LINUX_H_ */
189 --- a/net80211/ieee80211_var.h
190 +++ b/net80211/ieee80211_var.h
191 @@ -187,6 +187,12 @@ struct ieee80211vap {
192 struct ieee80211_proc_entry *iv_proc_entries;
193 struct vlan_group *iv_vlgrp; /* vlan group state */
194
195 + /* list of wds links */
196 + TAILQ_HEAD(, ieee80211vap) iv_wdslinks;
197 + TAILQ_ENTRY(ieee80211vap) iv_wdsnext;
198 + struct ieee80211vap *iv_master;
199 + struct ieee80211_node *iv_wdsnode;
200 +
201 TAILQ_ENTRY(ieee80211vap) iv_next; /* list of vap instances */
202 struct ieee80211com *iv_ic; /* back ptr to common state */
203 u_int32_t iv_debug; /* debug msg flags */
204 @@ -447,7 +453,7 @@ struct ieee80211com {
205 atomic_t ic_node_counter;
206 /* Virtual AP create/delete */
207 struct ieee80211vap *(*ic_vap_create)(struct ieee80211com *,
208 - const char *, int, int, struct net_device *);
209 + const char *, int, int, struct net_device *, struct ieee80211vap *);
210 void (*ic_vap_delete)(struct ieee80211vap *);
211
212 /* Send/recv 802.11 management frame */
213 @@ -703,7 +709,7 @@ MALLOC_DECLARE(M_80211_VAP);
214 int ieee80211_ifattach(struct ieee80211com *);
215 void ieee80211_ifdetach(struct ieee80211com *);
216 int ieee80211_vap_setup(struct ieee80211com *, struct net_device *,
217 - const char *, int, int);
218 + const char *, int, int, struct ieee80211vap *);
219 int ieee80211_vap_attach(struct ieee80211vap *, ifm_change_cb_t, ifm_stat_cb_t);
220 void ieee80211_vap_detach(struct ieee80211vap *);
221 void ieee80211_mark_dfs(struct ieee80211com *, struct ieee80211_channel *);
222 --- a/net80211/ieee80211_wireless.c
223 +++ b/net80211/ieee80211_wireless.c
224 @@ -2190,7 +2190,7 @@ ieee80211_setupxr(struct ieee80211vap *v
225 ieee80211_scan_flush(ic); /* NB: could optimize */
226
227 if (!(xrvap = ic->ic_vap_create(ic, name, IEEE80211_M_HOSTAP,
228 - IEEE80211_VAP_XR | IEEE80211_CLONE_BSSID, dev)))
229 + IEEE80211_VAP_XR | IEEE80211_CLONE_BSSID, dev, NULL)))
230 return;
231
232 /* We use iv_xrvap to link to the parent VAP as well */
233 @@ -3801,74 +3801,54 @@ ieee80211_ioctl_setmlme(struct net_devic
234 return 0;
235 }
236
237 +#define WDSNAME ".wds%d"
238 static int
239 -ieee80211_ioctl_wdsmac(struct net_device *dev, struct iw_request_info *info,
240 +ieee80211_ioctl_wdsaddmac(struct net_device *dev, struct iw_request_info *info,
241 void *w, char *extra)
242 {
243 struct ieee80211vap *vap = dev->priv;
244 struct sockaddr *sa = (struct sockaddr *)extra;
245 + struct ieee80211com *ic = vap->iv_ic;
246 + struct ieee80211vap *avp;
247 + char *name;
248
249 - if (!IEEE80211_ADDR_NULL(vap->wds_mac)) {
250 - printk("%s: Failed to add WDS MAC: " MAC_FMT "\n", dev->name,
251 - MAC_ADDR(sa->sa_data));
252 - printk("%s: Device already has WDS mac address attached,"
253 - " remove first\n", dev->name);
254 - return -1;
255 - }
256 -
257 - memcpy(vap->wds_mac, sa->sa_data, IEEE80211_ADDR_LEN);
258 + if (vap->iv_opmode != IEEE80211_M_HOSTAP)
259 + return -EINVAL;
260
261 - printk("%s: Added WDS MAC: " MAC_FMT "\n", dev->name,
262 - MAC_ADDR(vap->wds_mac));
263 + name = kmalloc(strlen(vap->iv_dev->name) + sizeof(WDSNAME) + 1, GFP_KERNEL);
264 + if (!name)
265 + return -ENOMEM;
266
267 - if (IS_UP(vap->iv_dev)) {
268 - /* Force us back to scan state to force us to go back through RUN
269 - * state and create/pin the WDS peer node into memory. */
270 - return ieee80211_new_state(vap, IEEE80211_S_SCAN, 0);
271 - }
272 + strcpy(name, vap->iv_dev->name);
273 + strcat(name, WDSNAME);
274 + avp = ieee80211_create_vap(ic, name, ic->ic_dev, IEEE80211_M_WDS, 0, vap);
275 + kfree(name);
276 + if (!avp)
277 + return -ENOMEM;
278
279 + memcpy(avp->wds_mac, sa->sa_data, IEEE80211_ADDR_LEN);
280 return 0;
281 }
282 +#undef WDSNAME
283
284 static int
285 -ieee80211_ioctl_wdsdelmac(struct net_device *dev, struct iw_request_info *info,
286 +ieee80211_ioctl_wdssetmac(struct net_device *dev, struct iw_request_info *info,
287 void *w, char *extra)
288 {
289 struct ieee80211vap *vap = dev->priv;
290 struct sockaddr *sa = (struct sockaddr *)extra;
291 - struct ieee80211com *ic = vap->iv_ic;
292 - struct ieee80211_node *wds_ni;
293
294 - /* WDS Mac address filed already? */
295 - if (IEEE80211_ADDR_NULL(vap->wds_mac))
296 - return 0;
297 + if (vap->iv_opmode != IEEE80211_M_WDS)
298 + return -EINVAL;
299
300 - /* Compare suplied MAC address with WDS MAC of this interface
301 - * remove when mac address is known
302 - */
303 - if (memcmp(vap->wds_mac, sa->sa_data, IEEE80211_ADDR_LEN) == 0) {
304 - if (IS_UP(vap->iv_dev)) {
305 - wds_ni = ieee80211_find_txnode(vap, vap->wds_mac);
306 - if (wds_ni != NULL) {
307 - /* Release reference created by find node */
308 - ieee80211_unref_node(&wds_ni);
309 - /* Release reference created by transition to RUN state,
310 - * [pinning peer node into the table] */
311 - ieee80211_unref_node(&wds_ni);
312 - }
313 - }
314 - memset(vap->wds_mac, 0x00, IEEE80211_ADDR_LEN);
315 - if (IS_UP(vap->iv_dev)) {
316 - /* This leaves a dead WDS node, until started again */
317 - return ic->ic_reset(ic->ic_dev);
318 - }
319 - return 0;
320 + memcpy(vap->wds_mac, sa->sa_data, IEEE80211_ADDR_LEN);
321 + if (IS_UP(vap->iv_dev)) {
322 + /* Force us back to scan state to force us to go back through RUN
323 + * state and create/pin the WDS peer node into memory. */
324 + return ieee80211_new_state(vap, IEEE80211_S_SCAN, 0);
325 }
326
327 - printk("%s: WDS MAC address " MAC_FMT " is not known by this interface\n",
328 - dev->name, MAC_ADDR(sa->sa_data));
329 -
330 - return -1;
331 + return 0;
332 }
333
334 /*
335 @@ -5391,8 +5371,8 @@ static const struct iw_priv_args ieee802
336 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "kickmac"},
337 { IEEE80211_IOCTL_WDSADDMAC,
338 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,"wds_add" },
339 - { IEEE80211_IOCTL_WDSDELMAC,
340 - IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,"wds_del" },
341 + { IEEE80211_IOCTL_WDSSETMAC,
342 + IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0,"wds_set" },
343 { IEEE80211_IOCTL_SETCHANLIST,
344 IW_PRIV_TYPE_CHANLIST | IW_PRIV_SIZE_FIXED, 0,"setchanlist" },
345 { IEEE80211_IOCTL_GETCHANLIST,
346 @@ -5884,8 +5864,8 @@ static const iw_handler ieee80211_priv_h
347 #endif
348 set_priv(IEEE80211_IOCTL_ADDMAC, ieee80211_ioctl_addmac),
349 set_priv(IEEE80211_IOCTL_DELMAC, ieee80211_ioctl_delmac),
350 - set_priv(IEEE80211_IOCTL_WDSADDMAC, ieee80211_ioctl_wdsmac),
351 - set_priv(IEEE80211_IOCTL_WDSDELMAC, ieee80211_ioctl_wdsdelmac),
352 + set_priv(IEEE80211_IOCTL_WDSADDMAC, ieee80211_ioctl_wdsaddmac),
353 + set_priv(IEEE80211_IOCTL_WDSSETMAC, ieee80211_ioctl_wdssetmac),
354 set_priv(IEEE80211_IOCTL_KICKMAC, ieee80211_ioctl_kickmac),
355 set_priv(IEEE80211_IOCTL_SETSCANLIST, ieee80211_ioctl_setscanlist),
356 #ifdef ATH_REVERSE_ENGINEERING
357 @@ -5956,7 +5936,7 @@ ieee80211_ioctl_create_vap(struct ieee80
358
359 strncpy(name, cp.icp_name, sizeof(name));
360
361 - vap = ieee80211_create_vap(ic, name, mdev, cp.icp_opmode, cp.icp_flags);
362 + vap = ieee80211_create_vap(ic, name, mdev, cp.icp_opmode, cp.icp_flags, NULL);
363 if (vap == NULL)
364 return -EIO;
365
366 @@ -5973,9 +5953,9 @@ EXPORT_SYMBOL(ieee80211_ioctl_create_vap
367 */
368 struct ieee80211vap*
369 ieee80211_create_vap(struct ieee80211com *ic, char *name,
370 - struct net_device *mdev, int opmode, int opflags)
371 + struct net_device *mdev, int opmode, int opflags, struct ieee80211vap *master)
372 {
373 - return ic->ic_vap_create(ic, name, opmode, opflags, mdev);
374 + return ic->ic_vap_create(ic, name, opmode, opflags, mdev, master);
375 }
376 EXPORT_SYMBOL(ieee80211_create_vap);
377
378 --- a/net80211/ieee80211_input.c
379 +++ b/net80211/ieee80211_input.c
380 @@ -199,8 +199,9 @@ ieee80211_input(struct ieee80211vap * va
381 {
382 #define HAS_SEQ(type) ((type & 0x4) == 0)
383 struct ieee80211_node * ni = ni_or_null;
384 - struct ieee80211com *ic = vap->iv_ic;
385 - struct net_device *dev = vap->iv_dev;
386 + struct ieee80211com *ic;
387 + struct net_device *dev;
388 + struct ieee80211_node *ni_wds = NULL;
389 struct ieee80211_frame *wh;
390 struct ieee80211_key *key;
391 struct ether_header *eh;
392 @@ -212,6 +213,19 @@ ieee80211_input(struct ieee80211vap * va
393 u_int8_t *bssid;
394 u_int16_t rxseq;
395
396 + type = -1; /* undefined */
397 +
398 + if (!vap)
399 + goto out;
400 +
401 + ic = vap->iv_ic;
402 + if (!ic)
403 + goto out;
404 +
405 + dev = vap->iv_dev;
406 + if (!dev)
407 + goto out;
408 +
409 /* initialize ni as in the previous API */
410 if (ni_or_null == NULL) {
411 /* This function does not 'own' vap->iv_bss, so we cannot
412 @@ -227,7 +241,6 @@ ieee80211_input(struct ieee80211vap * va
413
414 /* XXX adjust device in sk_buff? */
415
416 - type = -1; /* undefined */
417 /*
418 * In monitor mode, send everything directly to bpf.
419 * Also do not process frames w/o i_addr2 any further.
420 @@ -545,11 +558,11 @@ ieee80211_input(struct ieee80211vap * va
421 * the node table for the packet source address (addr4).
422 * If not, add one.
423 */
424 +
425 /* XXX: Useless node mgmt API; make better */
426 - if (dir == IEEE80211_FC1_DIR_DSTODS) {
427 - struct ieee80211_node_table *nt;
428 + if ((dir == IEEE80211_FC1_DIR_DSTODS) && !vap->iv_wdsnode && !ni_wds) {
429 + struct ieee80211_node_table *nt = &ic->ic_sta;
430 struct ieee80211_frame_addr4 *wh4;
431 - struct ieee80211_node *ni_wds;
432
433 if (!(vap->iv_flags_ext & IEEE80211_FEXT_WDS)) {
434 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT,
435 @@ -557,7 +570,6 @@ ieee80211_input(struct ieee80211vap * va
436 goto err;
437 }
438 wh4 = (struct ieee80211_frame_addr4 *)skb->data;
439 - nt = &ic->ic_sta;
440 ni_wds = ieee80211_find_wds_node(nt, wh4->i_addr4);
441 /* Last call increments ref count if !NULL */
442 if ((ni_wds != NULL) && (ni_wds != ni)) {
443 @@ -3084,8 +3096,7 @@ ieee80211_recv_mgmt(struct ieee80211vap
444 (vap->iv_opmode == IEEE80211_M_STA && ni->ni_associd) ||
445 (vap->iv_opmode == IEEE80211_M_IBSS) ||
446 ((subtype == IEEE80211_FC0_SUBTYPE_BEACON) &&
447 - (vap->iv_opmode == IEEE80211_M_HOSTAP) &&
448 - (ic->ic_protmode != IEEE80211_PROT_NONE)))) {
449 + (vap->iv_opmode == IEEE80211_M_HOSTAP)))) {
450 vap->iv_stats.is_rx_mgtdiscard++;
451 return;
452 }
453 @@ -3471,13 +3482,54 @@ ieee80211_recv_mgmt(struct ieee80211vap
454 */
455 if (ic->ic_flags & IEEE80211_F_SCAN) {
456 ieee80211_add_scan(vap, &scan, wh, subtype, rssi, rtsf);
457 - return;
458 }
459 - if ((vap->iv_opmode == IEEE80211_M_IBSS) &&
460 - (scan.capinfo & IEEE80211_CAPINFO_IBSS)) {
461 + /* NB: Behavior of WDS-Link and Ad-Hoc is very similar here:
462 + * When we receive a beacon that belongs to the AP that we're
463 + * connected to, use it to refresh the local node info.
464 + * If no node is found, go through the vap's wds link table
465 + * and try to find the sub-vap that is interested in this address
466 + */
467 + if (((vap->iv_opmode == IEEE80211_M_IBSS) &&
468 + (scan.capinfo & IEEE80211_CAPINFO_IBSS)) ||
469 + (((vap->iv_opmode == IEEE80211_M_HOSTAP) ||
470 + (vap->iv_opmode == IEEE80211_M_WDS)) &&
471 + (scan.capinfo & IEEE80211_CAPINFO_ESS))) {
472 + struct ieee80211vap *avp = NULL;
473 +
474 + IEEE80211_LOCK_IRQ(vap->iv_ic);
475 + if (vap->iv_opmode == IEEE80211_M_HOSTAP) {
476 + int found = 0;
477 +
478 + TAILQ_FOREACH(avp, &vap->iv_wdslinks, iv_wdsnext) {
479 + if (!memcmp(avp->wds_mac, wh->i_addr2, IEEE80211_ADDR_LEN)) {
480 + if (avp->iv_state != IEEE80211_S_RUN)
481 + continue;
482 + found = 1;
483 + break;
484 + }
485 + }
486 + if (!found)
487 + break;
488 +
489 + ni = ni_or_null = avp->iv_wdsnode;
490 + } else if (vap->iv_opmode == IEEE80211_M_WDS) {
491 + ni = ni_or_null = vap->iv_wdsnode;
492 + }
493 + IEEE80211_UNLOCK_IRQ(vap->iv_ic);
494 +
495 +
496 if (ni_or_null == NULL) {
497 - /* Create a new entry in the neighbor table. */
498 - ni = ieee80211_add_neighbor(vap, wh, &scan);
499 + if (avp) {
500 + IEEE80211_LOCK_IRQ(ic);
501 + ni = ieee80211_add_neighbor(avp, wh, &scan);
502 + /* force assoc */
503 + ni->ni_associd |= 0xc000;
504 + avp->iv_wdsnode = ieee80211_ref_node(ni);
505 + IEEE80211_UNLOCK_IRQ(ic);
506 + } else if (vap->iv_opmode == IEEE80211_M_IBSS) {
507 + /* Create a new entry in the neighbor table. */
508 + ni = ieee80211_add_neighbor(vap, wh, &scan);
509 + }
510 } else {
511 /*
512 * Copy data from beacon to neighbor table.
513 @@ -3490,6 +3542,7 @@ ieee80211_recv_mgmt(struct ieee80211vap
514 IEEE80211_ADDR_COPY(ni->ni_bssid, wh->i_addr3);
515 memcpy(ni->ni_tstamp.data, scan.tstamp,
516 sizeof(ni->ni_tstamp));
517 + ni->ni_inact = ni->ni_inact_reload;
518 ni->ni_intval =
519 IEEE80211_BINTVAL_SANITISE(scan.bintval);
520 ni->ni_capinfo = scan.capinfo;
521 --- a/net80211/ieee80211_node.c
522 +++ b/net80211/ieee80211_node.c
523 @@ -831,12 +831,18 @@ node_table_leave_locked(struct ieee80211
524 LIST_REMOVE(ni, ni_hash);
525 }
526 ni->ni_table = NULL;
527 + if (ni->ni_vap->iv_wdsnode == ni) {
528 +#ifdef IEEE80211_DEBUG_REFCNT
529 + ieee80211_unref_node_debug(&ni->ni_vap->iv_wdsnode, func, line);
530 +#else
531 + ieee80211_unref_node(&ni->ni_vap->iv_wdsnode);
532 +#endif
533 + }
534 #ifdef IEEE80211_DEBUG_REFCNT
535 ieee80211_unref_node_debug(&ni, func, line);
536 #else
537 ieee80211_unref_node(&ni);
538 #endif
539 -
540 }
541
542 /* This is overridden by ath_node_alloc in ath/if_ath.c, and so
543 @@ -1553,22 +1559,39 @@ ieee80211_find_rxnode(struct ieee80211co
544 ((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) == IEEE80211_FC0_SUBTYPE_PS_POLL)
545 struct ieee80211_node_table *nt;
546 struct ieee80211_node *ni;
547 + struct ieee80211vap *vap, *avp;
548 + const u_int8_t *addr;
549 +
550 + if (IS_CTL(wh) && !IS_PSPOLL(wh) /*&& !IS_RTS(ah)*/)
551 + addr = wh->i_addr1;
552 + else
553 + addr = wh->i_addr2;
554 +
555 + if (IEEE80211_IS_MULTICAST(addr))
556 + return NULL;
557
558 /* XXX check ic_bss first in station mode */
559 /* XXX 4-address frames? */
560 nt = &ic->ic_sta;
561 IEEE80211_NODE_TABLE_LOCK_IRQ(nt);
562 - if (IS_CTL(wh) && !IS_PSPOLL(wh) /*&& !IS_RTS(ah)*/)
563 -#ifdef IEEE80211_DEBUG_REFCNT
564 - ni = ieee80211_find_node_locked_debug(nt, wh->i_addr1, func, line);
565 -#else
566 - ni = ieee80211_find_node_locked(nt, wh->i_addr1);
567 -#endif
568 - else
569 + if ((wh->i_fc[1] & IEEE80211_FC1_DIR_MASK) == IEEE80211_FC1_DIR_DSTODS) {
570 + TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
571 + TAILQ_FOREACH(avp, &vap->iv_wdslinks, iv_wdsnext) {
572 + if (!IEEE80211_ADDR_EQ(addr, avp->wds_mac))
573 + continue;
574 +
575 + if (avp->iv_wdsnode)
576 + return ieee80211_ref_node(avp->iv_wdsnode);
577 + else
578 + return NULL;
579 + }
580 + }
581 + }
582 +
583 #ifdef IEEE80211_DEBUG_REFCNT
584 - ni = ieee80211_find_node_locked_debug(nt, wh->i_addr2, func, line);
585 + ni = ieee80211_find_node_locked_debug(nt, addr, func, line);
586 #else
587 - ni = ieee80211_find_node_locked(nt, wh->i_addr2);
588 + ni = ieee80211_find_node_locked(nt, addr);
589 #endif
590 IEEE80211_NODE_TABLE_UNLOCK_IRQ(nt);
591
592 @@ -1596,9 +1619,19 @@ ieee80211_find_txnode_debug(struct ieee8
593 ieee80211_find_txnode(struct ieee80211vap *vap, const u_int8_t *mac)
594 #endif
595 {
596 + struct ieee80211com *ic = vap->iv_ic;
597 struct ieee80211_node_table *nt;
598 struct ieee80211_node *ni = NULL;
599
600 + IEEE80211_LOCK_IRQ(ic);
601 + if (vap->iv_opmode == IEEE80211_M_WDS) {
602 + if (vap->iv_wdsnode)
603 + return ieee80211_ref_node(vap->iv_wdsnode);
604 + else
605 + return NULL;
606 + }
607 + IEEE80211_UNLOCK_IRQ(ic);
608 +
609 /*
610 * The destination address should be in the node table
611 * unless we are operating in station mode or this is a
612 @@ -1669,6 +1702,11 @@ ieee80211_free_node(struct ieee80211_nod
613 {
614 struct ieee80211vap *vap = ni->ni_vap;
615
616 + IEEE80211_LOCK_IRQ(ni->ni_ic);
617 + if (vap && ni == vap->iv_wdsnode)
618 + vap->iv_wdsnode = NULL;
619 + IEEE80211_UNLOCK_IRQ(ni->ni_ic);
620 +
621 atomic_dec(&ni->ni_ic->ic_node_counter);
622 node_print_message(IEEE80211_MSG_NODE|IEEE80211_MSG_NODE_REF,
623 1 /* show counter */,
624 @@ -1781,22 +1819,6 @@ restart:
625 jiffies > ni->ni_rxfragstamp + HZ) {
626 ieee80211_dev_kfree_skb(&ni->ni_rxfrag);
627 }
628 - /*
629 - * Special case ourself; we may be idle for extended periods
630 - * of time and regardless reclaiming our state is wrong.
631 - * Special case a WDS link: it may be dead or idle, but it is
632 - * never ok to reclaim it, as this will block transmissions
633 - * and nobody will recreate the node when the WDS peer is
634 - * available again. */
635 - if ((ni == ni->ni_vap->iv_bss) ||
636 - (ni->ni_vap->iv_opmode == IEEE80211_M_WDS &&
637 - !memcmp(ni->ni_macaddr, ni->ni_vap->wds_mac, ETH_ALEN)))
638 - {
639 - /* NB: don't permit it to go negative */
640 - if (ni->ni_inact > 0)
641 - ni->ni_inact--;
642 - continue;
643 - }
644 ni->ni_inact--;
645 if (ni->ni_associd != 0 || isadhoc) {
646 struct ieee80211vap *vap = ni->ni_vap;
647 --- a/net80211/ieee80211_output.c
648 +++ b/net80211/ieee80211_output.c
649 @@ -246,10 +246,7 @@ ieee80211_hardstart(struct sk_buff *skb,
650 * things like power save.
651 */
652 eh = (struct ether_header *)skb->data;
653 - if (vap->iv_opmode == IEEE80211_M_WDS)
654 - ni = ieee80211_find_txnode(vap, vap->wds_mac);
655 - else
656 - ni = ieee80211_find_txnode(vap, eh->ether_dhost);
657 + ni = ieee80211_find_txnode(vap, eh->ether_dhost);
658 if (ni == NULL) {
659 /* NB: ieee80211_find_txnode does stat+msg */
660 goto bad;
661 @@ -788,7 +785,7 @@ ieee80211_encap(struct ieee80211_node *n
662 break;
663 case IEEE80211_M_WDS:
664 use4addr = 1;
665 - ismulticast = IEEE80211_IS_MULTICAST(ni->ni_macaddr);
666 + ismulticast = 0;
667 break;
668 case IEEE80211_M_HOSTAP:
669 if (!IEEE80211_IS_MULTICAST(eh.ether_dhost) &&
670 @@ -973,7 +970,7 @@ ieee80211_encap(struct ieee80211_node *n
671 break;
672 case IEEE80211_M_WDS:
673 wh->i_fc[1] = IEEE80211_FC1_DIR_DSTODS;
674 - IEEE80211_ADDR_COPY(wh->i_addr1, ni->ni_macaddr);
675 + IEEE80211_ADDR_COPY(wh->i_addr1, vap->wds_mac);
676 IEEE80211_ADDR_COPY(wh->i_addr2, vap->iv_myaddr);
677 IEEE80211_ADDR_COPY(wh->i_addr3, eh.ether_dhost);
678 IEEE80211_ADDR_COPY(WH4(wh)->i_addr4, eh.ether_shost);
679 --- a/tools/athkey.c
680 +++ b/tools/athkey.c
681 @@ -118,7 +118,7 @@ set80211priv(const char *dev, int op, vo
682 IOCTL_ERR(IEEE80211_IOCTL_ADDMAC),
683 IOCTL_ERR(IEEE80211_IOCTL_DELMAC),
684 IOCTL_ERR(IEEE80211_IOCTL_WDSADDMAC),
685 - IOCTL_ERR(IEEE80211_IOCTL_WDSDELMAC),
686 + IOCTL_ERR(IEEE80211_IOCTL_WDSSETMAC),
687 IOCTL_ERR(IEEE80211_IOCTL_READREG),
688 IOCTL_ERR(IEEE80211_IOCTL_WRITEREG),
689 };
690 --- a/tools/athchans.c
691 +++ b/tools/athchans.c
692 @@ -118,7 +118,7 @@ set80211priv(const char *dev, int op, vo
693 IOCTL_ERR(IEEE80211_IOCTL_ADDMAC),
694 IOCTL_ERR(IEEE80211_IOCTL_DELMAC),
695 IOCTL_ERR(IEEE80211_IOCTL_WDSADDMAC),
696 - IOCTL_ERR(IEEE80211_IOCTL_WDSDELMAC),
697 + IOCTL_ERR(IEEE80211_IOCTL_WDSSETMAC),
698 IOCTL_ERR(IEEE80211_IOCTL_READREG),
699 IOCTL_ERR(IEEE80211_IOCTL_WRITEREG),
700 };
701 --- a/tools/wlanconfig.c
702 +++ b/tools/wlanconfig.c
703 @@ -968,7 +968,7 @@ do80211priv(struct iwreq *iwr, const cha
704 IOCTL_ERR(IEEE80211_IOCTL_ADDMAC),
705 IOCTL_ERR(IEEE80211_IOCTL_DELMAC),
706 IOCTL_ERR(IEEE80211_IOCTL_WDSADDMAC),
707 - IOCTL_ERR(IEEE80211_IOCTL_WDSDELMAC),
708 + IOCTL_ERR(IEEE80211_IOCTL_WDSSETMAC),
709 IOCTL_ERR(IEEE80211_IOCTL_READREG),
710 IOCTL_ERR(IEEE80211_IOCTL_WRITEREG),
711 };
712 --- a/net80211/ieee80211_proto.c
713 +++ b/net80211/ieee80211_proto.c
714 @@ -1090,7 +1090,7 @@ ieee80211_open(struct net_device *dev)
715 void
716 ieee80211_start_running(struct ieee80211com *ic)
717 {
718 - struct ieee80211vap *vap;
719 + struct ieee80211vap *vap, *avp;
720 struct net_device *dev;
721
722 /* XXX locking */
723 @@ -1099,6 +1099,13 @@ ieee80211_start_running(struct ieee80211
724 /* NB: avoid recursion */
725 if ((dev->flags & IFF_UP) && !(dev->flags & IFF_RUNNING))
726 ieee80211_open(dev);
727 +
728 + TAILQ_FOREACH(avp, &vap->iv_wdslinks, iv_wdsnext) {
729 + dev = avp->iv_dev;
730 + /* NB: avoid recursion */
731 + if ((dev->flags & IFF_UP) && !(dev->flags & IFF_RUNNING))
732 + ieee80211_open(dev);
733 + }
734 }
735 }
736 EXPORT_SYMBOL(ieee80211_start_running);
737 @@ -1116,11 +1123,21 @@ ieee80211_stop(struct net_device *dev)
738 struct ieee80211vap *vap = dev->priv;
739 struct ieee80211com *ic = vap->iv_ic;
740 struct net_device *parent = ic->ic_dev;
741 + struct ieee80211vap *avp;
742
743 IEEE80211_DPRINTF(vap,
744 IEEE80211_MSG_STATE | IEEE80211_MSG_DEBUG,
745 "%s\n", "stop running");
746
747 + if (vap->iv_wdsnode)
748 + ieee80211_unref_node(&vap->iv_wdsnode);
749 +
750 + /* stop wds interfaces */
751 + TAILQ_FOREACH(avp, &vap->iv_wdslinks, iv_next) {
752 + if (avp->iv_state != IEEE80211_S_INIT)
753 + ieee80211_stop(avp->iv_dev);
754 + }
755 +
756 ieee80211_new_state(vap, IEEE80211_S_INIT, -1);
757 if (dev->flags & IFF_RUNNING) {
758 dev->flags &= ~IFF_RUNNING; /* mark us stopped */
759 @@ -1148,7 +1165,7 @@ EXPORT_SYMBOL(ieee80211_stop);
760 void
761 ieee80211_stop_running(struct ieee80211com *ic)
762 {
763 - struct ieee80211vap *vap;
764 + struct ieee80211vap *vap, *avp;
765 struct net_device *dev;
766
767 /* XXX locking */
768 @@ -1156,6 +1173,12 @@ ieee80211_stop_running(struct ieee80211c
769 dev = vap->iv_dev;
770 if (dev->flags & IFF_RUNNING) /* NB: avoid recursion */
771 ieee80211_stop(dev);
772 +
773 + TAILQ_FOREACH(avp, &vap->iv_wdslinks, iv_wdsnext) {
774 + dev = avp->iv_dev;
775 + if (dev->flags & IFF_RUNNING) /* NB: avoid recursion */
776 + ieee80211_stop(dev);
777 + }
778 }
779 }
780 EXPORT_SYMBOL(ieee80211_stop_running);
781 @@ -1557,57 +1580,12 @@ __ieee80211_newstate(struct ieee80211vap
782 switch (ostate) {
783 case IEEE80211_S_INIT:
784 if (vap->iv_opmode == IEEE80211_M_MONITOR ||
785 - vap->iv_opmode == IEEE80211_M_WDS ||
786 vap->iv_opmode == IEEE80211_M_HOSTAP) {
787 /*
788 * Already have a channel; bypass the
789 * scan and startup immediately.
790 */
791 ieee80211_create_ibss(vap, ic->ic_curchan);
792 -
793 - /* In WDS mode, allocate and initialize peer node. */
794 - if (vap->iv_opmode == IEEE80211_M_WDS) {
795 - /* XXX: This is horribly non-atomic. */
796 - struct ieee80211_node *wds_ni =
797 - ieee80211_find_node(&ic->ic_sta,
798 - vap->wds_mac);
799 -
800 - if (wds_ni == NULL) {
801 - wds_ni = ieee80211_alloc_node_table(
802 - vap,
803 - vap->wds_mac);
804 - if (wds_ni != NULL) {
805 - ieee80211_add_wds_addr(
806 - &ic->ic_sta,
807 - wds_ni,
808 - vap->wds_mac,
809 - 1);
810 - ieee80211_ref_node(wds_ni); /* pin in memory */
811 - }
812 - else
813 - IEEE80211_DPRINTF(
814 - vap,
815 - IEEE80211_MSG_NODE,
816 - "%s: Unable to "
817 - "allocate node for "
818 - "WDS: " MAC_FMT "\n",
819 - __func__,
820 - MAC_ADDR(
821 - vap->wds_mac)
822 - );
823 - }
824 -
825 - if (wds_ni != NULL) {
826 - ieee80211_node_authorize(wds_ni);
827 - wds_ni->ni_chan =
828 - vap->iv_bss->ni_chan;
829 - wds_ni->ni_capinfo =
830 - ni->ni_capinfo;
831 - wds_ni->ni_associd = 1;
832 - wds_ni->ni_ath_flags =
833 - vap->iv_ath_cap;
834 - }
835 - }
836 break;
837 }
838 /* fall thru... */
839 @@ -1808,6 +1786,10 @@ ieee80211_newstate(struct ieee80211vap *
840 ieee80211_state_name[dstate]);
841
842 ieee80211_update_link_status(vap, nstate, ostate);
843 +
844 + if ((nstate != IEEE80211_S_RUN) && vap->iv_wdsnode)
845 + ieee80211_unref_node(&vap->iv_wdsnode);
846 +
847 switch (nstate) {
848 case IEEE80211_S_AUTH:
849 case IEEE80211_S_ASSOC: