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