a5a3ca99bc02b7b89987e0005eeb989ef16d5270
[openwrt/svn-archive/archive.git] / package / madwifi / patches / 121-ibss_hostap.patch
1 diff -ur madwifi.old/ath/if_ath.c madwifi.dev/ath/if_ath.c
2 --- madwifi.old/ath/if_ath.c 2007-06-01 12:22:06.641518272 +0200
3 +++ madwifi.dev/ath/if_ath.c 2007-06-01 12:22:55.326117088 +0200
4 @@ -407,7 +407,6 @@
5 * and use the next two bits as the index of the VAP.
6 */
7 #define ATH_SET_VAP_BSSID_MASK(bssid_mask) ((bssid_mask)[0] &= ~(((ATH_BCBUF-1)<<2)|0x02))
8 -#define ATH_GET_VAP_ID(bssid) ((bssid)[0] >> 2)
9 #define ATH_SET_VAP_BSSID(bssid, id) \
10 do { \
11 if (id) \
12 @@ -1048,9 +1048,12 @@
13 ic_opmode = opmode;
14 break;
15 case IEEE80211_M_IBSS:
16 - if (sc->sc_nvaps != 0) /* only one */
17 - return NULL;
18 - ic_opmode = opmode;
19 + if (sc->sc_nvaps == 0) /* only one */
20 + ic_opmode = opmode;
21 + else
22 + ic_opmode = IEEE80211_M_HOSTAP;
23 +
24 + sc->sc_nibssvaps++;
25 break;
26 case IEEE80211_M_AHDEMO:
27 case IEEE80211_M_MONITOR:
28 @@ -1080,7 +1083,7 @@
29 return NULL;
30 }
31
32 - if (sc->sc_nvaps >= ATH_BCBUF) {
33 + if (sc->sc_nvaps + sc->sc_nibssvaps >= ATH_BCBUF) {
34 printk(KERN_WARNING "too many virtual ap's (already got %d)\n", sc->sc_nvaps);
35 return NULL;
36 }
37 @@ -1115,8 +1118,9 @@
38 */
39 if (opmode == IEEE80211_M_MONITOR)
40 dev->type = ARPHRD_IEEE80211_RADIOTAP;
41 - if ((flags & IEEE80211_CLONE_BSSID) &&
42 - sc->sc_nvaps != 0 && opmode != IEEE80211_M_WDS && sc->sc_hasbmask) {
43 + avp->av_bslot = -1;
44 + if ((flags & IEEE80211_CLONE_BSSID) && sc->sc_hasbmask &&
45 + (opmode == IEEE80211_M_HOSTAP || opmode == IEEE80211_M_IBSS)) {
46 struct ieee80211vap *v;
47 unsigned int id_mask, id;
48
49 @@ -1129,18 +1133,22 @@
50
51 /* do a full search to mark all the allocated VAPs */
52 id_mask = 0;
53 - TAILQ_FOREACH(v, &ic->ic_vaps, iv_next)
54 - id_mask |= (1 << ATH_GET_VAP_ID(v->iv_myaddr));
55 + TAILQ_FOREACH(v, &ic->ic_vaps, iv_next) {
56 + struct ath_vap *a = (struct ath_vap *) v->iv_dev->priv;
57 + if (a->av_bslot >= 0)
58 + id_mask |= (1 << a->av_bslot);
59 + }
60
61 - for (id = 0; id < ATH_BCBUF; id++) {
62 + /* IBSS mode has local always set, so don't hand out beacon slot 0 to an IBSS vap */
63 + for (id = (opmode == IEEE80211_M_IBSS ? 1 : 0); id < ATH_BCBUF; id++) {
64 /* get the first available slot */
65 if ((id_mask & (1 << id)) == 0) {
66 ATH_SET_VAP_BSSID(vap->iv_myaddr, id);
67 + avp->av_bslot = id;
68 break;
69 }
70 }
71 }
72 - avp->av_bslot = -1;
73 STAILQ_INIT(&avp->av_mcastq.axq_q);
74 ATH_TXQ_LOCK_INIT(&avp->av_mcastq);
75 if (opmode == IEEE80211_M_HOSTAP || opmode == IEEE80211_M_IBSS) {
76 @@ -1150,33 +1158,14 @@
77 */
78 avp->av_bcbuf = STAILQ_FIRST(&sc->sc_bbuf);
79 STAILQ_REMOVE_HEAD(&sc->sc_bbuf, bf_list);
80 - if (opmode == IEEE80211_M_HOSTAP || !sc->sc_hasveol) {
81 + if ((opmode == IEEE80211_M_IBSS) || (opmode == IEEE80211_M_HOSTAP) || !sc->sc_hasveol) {
82 unsigned int slot;
83 - /*
84 - * Assign the VAP to a beacon xmit slot. As
85 - * above, this cannot fail to find one.
86 - */
87 - avp->av_bslot = 0;
88 - for (slot = 0; slot < ATH_BCBUF; slot++)
89 - if (sc->sc_bslot[slot] == NULL) {
90 - /*
91 - * XXX hack, space out slots to better
92 - * deal with misses
93 - */
94 - if (slot + 1 < ATH_BCBUF &&
95 - sc->sc_bslot[slot+1] == NULL) {
96 - avp->av_bslot = slot + 1;
97 - break;
98 - }
99 - avp->av_bslot = slot;
100 - /* NB: keep looking for a double slot */
101 - }
102 KASSERT(sc->sc_bslot[avp->av_bslot] == NULL,
103 ("beacon slot %u not empty?", avp->av_bslot));
104 sc->sc_bslot[avp->av_bslot] = vap;
105 sc->sc_nbcnvaps++;
106 }
107 - if ((opmode == IEEE80211_M_HOSTAP) && (sc->sc_hastsfadd)) {
108 + if ((sc->sc_opmode == IEEE80211_M_HOSTAP) && (sc->sc_hastsfadd)) {
109 /*
110 * Multiple VAPs are to transmit beacons and we
111 * have h/w support for TSF adjusting; enable use
112 @@ -1286,7 +1275,9 @@
113 sc->sc_stagbeacons = 0;
114 }
115
116 - if (vap->iv_opmode == IEEE80211_M_STA) {
117 + if (vap->iv_opmode == IEEE80211_M_IBSS) {
118 + sc->sc_nibssvaps--;
119 + } else if (vap->iv_opmode == IEEE80211_M_STA) {
120 sc->sc_nstavaps--;
121 sc->sc_nostabeacons = 0;
122 } else if (vap->iv_opmode == IEEE80211_M_MONITOR)
123 @@ -3368,7 +3367,7 @@
124 ((ic->ic_opmode == IEEE80211_M_HOSTAP) &&
125 (ic->ic_protmode != IEEE80211_PROT_NONE)))
126 rfilt |= HAL_RX_FILTER_BEACON;
127 - if (sc->sc_nmonvaps > 0)
128 + if ((sc->sc_nmonvaps > 0) || ((sc->sc_nvaps > 0) && (sc->sc_nibssvaps > 0)))
129 rfilt |= (HAL_RX_FILTER_CONTROL | HAL_RX_FILTER_BEACON |
130 HAL_RX_FILTER_PROBEREQ | HAL_RX_FILTER_PROM);
131 return rfilt;
132 @@ -5809,12 +5801,20 @@
133 type = ieee80211_input(ni, skb, rs->rs_rssi, rs->rs_tstamp);
134 ieee80211_unref_node(&ni);
135 } else {
136 + const struct ieee80211_frame_min *wh = (const struct ieee80211_frame_min *) skb->data;
137 /*
138 * No key index or no entry, do a lookup and
139 * add the node to the mapping table if possible.
140 */
141 - ni = ieee80211_find_rxnode(ic,
142 - (const struct ieee80211_frame_min *) skb->data);
143 + if (((wh->i_fc[0] & IEEE80211_FC0_SUBTYPE_MASK) == IEEE80211_FC0_SUBTYPE_PROBE_REQ) &&
144 + (sc->sc_nibssvaps > 0))
145 + /* if this is a probe request, send it to all vaps
146 + * when looking up nodes, hostap will be preferred over ibss,
147 + * because ibss will catch all nodes */
148 + ni = NULL;
149 + else
150 + ni = ieee80211_find_rxnode(ic, (const struct ieee80211_frame_min *) skb->data);
151 +
152 if (ni != NULL) {
153 struct ath_node *an = ATH_NODE(ni);
154 ieee80211_keyix_t keyix;
155 diff -ur madwifi.old/ath/if_athvar.h madwifi.dev/ath/if_athvar.h
156 --- madwifi.old/ath/if_athvar.h 2007-06-01 12:22:06.642518120 +0200
157 +++ madwifi.dev/ath/if_athvar.h 2007-06-01 12:21:54.640342728 +0200
158 @@ -199,7 +199,7 @@
159 #define ATH_RXBUF 40 /* number of RX buffers */
160 #define ATH_TXBUF 200 /* number of TX buffers */
161
162 -#define ATH_BCBUF 4 /* number of beacon buffers */
163 +#define ATH_BCBUF 8 /* number of beacon buffers */
164
165 /* free buffer threshold to restart net dev */
166 #define ATH_TXBUF_FREE_THRESHOLD (ATH_TXBUF / 20)
167 @@ -594,6 +594,7 @@
168 u_int16_t sc_nvaps; /* # of active virtual ap's */
169 u_int8_t sc_nstavaps; /* # of active station vaps */
170 u_int8_t sc_nmonvaps; /* # of monitor vaps */
171 + u_int8_t sc_nibssvaps; /* # of active ibss vaps */
172 u_int8_t sc_nbcnvaps; /* # of vaps sending beacons */
173 u_int sc_fftxqmin; /* aggregation threshold */
174 HAL_INT sc_imask; /* interrupt mask copy */
175 diff -ur madwifi.old/net80211/ieee80211_beacon.c madwifi.dev/net80211/ieee80211_beacon.c
176 --- madwifi.old/net80211/ieee80211_beacon.c 2007-06-01 12:22:06.642518120 +0200
177 +++ madwifi.dev/net80211/ieee80211_beacon.c 2007-06-01 12:21:54.640342728 +0200
178 @@ -111,7 +111,7 @@
179 bo->bo_tim = frm;
180
181 /* IBSS/TIM */
182 - if (vap->iv_opmode == IEEE80211_M_IBSS) {
183 + if (ic->ic_opmode == IEEE80211_M_IBSS) {
184 *frm++ = IEEE80211_ELEMID_IBSSPARMS;
185 *frm++ = 2;
186 *frm++ = 0; *frm++ = 0; /* TODO: ATIM window */
187 diff -ur madwifi.old/net80211/ieee80211_input.c madwifi.dev/net80211/ieee80211_input.c
188 --- madwifi.old/net80211/ieee80211_input.c 2007-06-01 12:22:06.645517664 +0200
189 +++ madwifi.dev/net80211/ieee80211_input.c 2007-06-01 12:21:54.642342424 +0200
190 @@ -2953,7 +2953,13 @@
191 return;
192 }
193 if (ni == vap->iv_bss) {
194 - if (vap->iv_opmode == IEEE80211_M_IBSS) {
195 + /* this probe request may have been sent to all vaps
196 + * to give each a chance of creating a node for this.
197 + * important for hostap+ibss mode */
198 + ni = ieee80211_find_rxnode(ic, (const struct ieee80211_frame_min *) skb->data);
199 + if (ni) {
200 + allocbs = 0;
201 + } else if (vap->iv_opmode == IEEE80211_M_IBSS) {
202 /*
203 * XXX Cannot tell if the sender is operating
204 * in ibss mode. But we need a new node to
205 @@ -2962,12 +2968,13 @@
206 */
207 ni = ieee80211_fakeup_adhoc_node(vap,
208 wh->i_addr2);
209 + allocbs = 1;
210 } else {
211 ni = ieee80211_dup_bss(vap, wh->i_addr2, 1);
212 + allocbs = 1;
213 }
214 if (ni == NULL)
215 return;
216 - allocbs = 1;
217 }
218
219 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_INPUT, wh->i_addr2,
220 diff -ur madwifi.old/net80211/ieee80211_node.c madwifi.dev/net80211/ieee80211_node.c
221 --- madwifi.old/net80211/ieee80211_node.c 2007-06-01 12:22:06.646517512 +0200
222 +++ madwifi.dev/net80211/ieee80211_node.c 2007-06-01 12:21:54.644342120 +0200
223 @@ -1082,8 +1082,25 @@
224 IEEE80211_NODE_TABLE_LOCK_ASSERT(nt);
225
226 hash = IEEE80211_NODE_HASH(macaddr);
227 +
228 + /* look for non-ibss nodes first */
229 LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) {
230 - if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr)) {
231 + if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr) && ni->ni_vap->iv_opmode != IEEE80211_M_IBSS) {
232 + ieee80211_ref_node(ni); /* mark referenced */
233 +#ifdef IEEE80211_DEBUG_REFCNT
234 + IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,
235 + "%s (%s:%u) %p<%s> refcnt %d\n", __func__,
236 + func, line,
237 + ni, ether_sprintf(ni->ni_macaddr),
238 + ieee80211_node_refcnt(ni));
239 +#endif
240 + return ni;
241 + }
242 + }
243 +
244 + /* now look for ibss nodes */
245 + LIST_FOREACH(ni, &nt->nt_hash[hash], ni_hash) {
246 + if (IEEE80211_ADDR_EQ(ni->ni_macaddr, macaddr) && ni->ni_vap->iv_opmode == IEEE80211_M_IBSS) {
247 ieee80211_ref_node(ni); /* mark referenced */
248 #ifdef IEEE80211_DEBUG_REFCNT
249 IEEE80211_DPRINTF(ni->ni_vap, IEEE80211_MSG_NODE,