b62fb3f201bd31919562af8a0a6aae09fd2f3f58
[openwrt/svn-archive/archive.git] / package / hostapd / patches / 310-madwifi_merge.patch
1 --- a/src/drivers/driver_madwifi.c
2 +++ b/src/drivers/driver_madwifi.c
3 @@ -71,7 +71,6 @@
4
5 #define WPA_KEY_RSC_LEN 8
6
7 -#ifdef HOSTAPD
8
9 #include "priv_netlink.h"
10 #include "netlink.h"
11 @@ -82,17 +81,22 @@
12 struct madwifi_driver_data {
13 struct hostapd_data *hapd; /* back pointer */
14
15 - char iface[IFNAMSIZ + 1];
16 + void *wext; /* private data for driver_wext */
17 + void *ctx;
18 + char ifname[IFNAMSIZ + 1];
19 + int ioctl_sock; /* socket for ioctl() use */
20 +
21 +#ifdef HOSTAPD
22 int ifindex;
23 struct l2_packet_data *sock_xmit; /* raw packet xmit socket */
24 struct l2_packet_data *sock_recv; /* raw packet recv socket */
25 - int ioctl_sock; /* socket for ioctl() use */
26 struct netlink_data *netlink;
27 int we_version;
28 u8 acct_mac[ETH_ALEN];
29 struct hostap_sta_driver_data acct_data;
30
31 struct l2_packet_data *sock_raw; /* raw 802.11 management frames */
32 +#endif
33 };
34
35 static int madwifi_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
36 @@ -105,7 +109,7 @@ set80211priv(struct madwifi_driver_data
37 int do_inline = len < IFNAMSIZ;
38
39 memset(&iwr, 0, sizeof(iwr));
40 - os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
41 + os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
42 #ifdef IEEE80211_IOCTL_FILTERFRAME
43 /* FILTERFRAME must be NOT inline, regardless of size. */
44 if (op == IEEE80211_IOCTL_FILTERFRAME)
45 @@ -206,7 +210,7 @@ set80211param(struct madwifi_driver_data
46 struct iwreq iwr;
47
48 memset(&iwr, 0, sizeof(iwr));
49 - os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
50 + os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
51 iwr.u.mode = op;
52 memcpy(iwr.u.name+sizeof(__u32), &arg, sizeof(arg));
53
54 @@ -233,6 +237,7 @@ ether_sprintf(const u8 *addr)
55 }
56 #endif /* CONFIG_NO_STDOUT_DEBUG */
57
58 +#ifdef HOSTAPD
59 /*
60 * Configure WPA parameters.
61 */
62 @@ -395,7 +400,7 @@ madwifi_sta_set_flags(void *priv, const
63 return madwifi_set_sta_authorized(priv, addr, 0);
64 return 0;
65 }
66 -
67 +#endif /* HOSTAPD */
68 static int
69 madwifi_del_key(void *priv, const u8 *addr, int key_idx)
70 {
71 @@ -407,28 +412,20 @@ madwifi_del_key(void *priv, const u8 *ad
72 __func__, ether_sprintf(addr), key_idx);
73
74 memset(&wk, 0, sizeof(wk));
75 + wk.idk_keyix = key_idx;
76 if (addr != NULL) {
77 memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
78 - wk.idk_keyix = (u8) IEEE80211_KEYIX_NONE;
79 - } else {
80 - wk.idk_keyix = key_idx;
81 - }
82 -
83 - ret = set80211priv(drv, IEEE80211_IOCTL_DELKEY, &wk, sizeof(wk));
84 - if (ret < 0) {
85 - wpa_printf(MSG_DEBUG, "%s: Failed to delete key (addr %s"
86 - " key_idx %d)", __func__, ether_sprintf(addr),
87 - key_idx);
88 }
89
90 - return ret;
91 + set80211priv(drv, IEEE80211_IOCTL_DELKEY, &wk, sizeof(wk));
92 + return 0;
93 }
94
95 static int
96 -wpa_driver_madwifi_set_key(const char *ifname, void *priv, enum wpa_alg alg,
97 - const u8 *addr, int key_idx, int set_tx,
98 - const u8 *seq, size_t seq_len,
99 - const u8 *key, size_t key_len)
100 +madwifi_set_key(const char *ifname, void *priv, enum wpa_alg alg,
101 + const u8 *addr, int key_idx, int set_tx,
102 + const u8 *seq, size_t seq_len,
103 + const u8 *key, size_t key_len)
104 {
105 struct madwifi_driver_data *drv = priv;
106 struct ieee80211req_key wk;
107 @@ -462,10 +459,14 @@ wpa_driver_madwifi_set_key(const char *i
108 memset(&wk, 0, sizeof(wk));
109 wk.ik_type = cipher;
110 wk.ik_flags = IEEE80211_KEY_RECV | IEEE80211_KEY_XMIT;
111 +
112 if (addr == NULL) {
113 memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
114 wk.ik_keyix = key_idx;
115 wk.ik_flags |= IEEE80211_KEY_DEFAULT;
116 + } else if (!memcmp(addr, "\xff\xff\xff\xff\xff\xff", ETH_ALEN)) {
117 + wk.ik_flags |= IEEE80211_KEY_GROUP;
118 + memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
119 } else {
120 memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
121 wk.ik_keyix = IEEE80211_KEYIX_NONE;
122 @@ -485,6 +486,7 @@ wpa_driver_madwifi_set_key(const char *i
123 }
124
125
126 +#ifdef HOSTAPD
127 static int
128 madwifi_get_seqnum(const char *ifname, void *priv, const u8 *addr, int idx,
129 u8 *seq)
130 @@ -591,7 +593,7 @@ madwifi_read_sta_driver_data(void *priv,
131
132 memset(data, 0, sizeof(*data));
133 snprintf(buf, sizeof(buf), "/proc/net/madwifi/%s/" MACSTR,
134 - drv->iface, MAC2STR(addr));
135 + drv->ifname, MAC2STR(addr));
136
137 f = fopen(buf, "r");
138 if (!f) {
139 @@ -757,7 +759,7 @@ static int madwifi_receive_probe_req(str
140 if (ret)
141 return ret;
142
143 - drv->sock_raw = l2_packet_init(drv->iface, NULL, ETH_P_80211_RAW,
144 + drv->sock_raw = l2_packet_init(drv->ifname, NULL, ETH_P_80211_RAW,
145 madwifi_raw_receive, drv, 1);
146 if (drv->sock_raw == NULL)
147 return -1;
148 @@ -1017,7 +1019,7 @@ madwifi_get_we_version(struct madwifi_dr
149 return -1;
150
151 memset(&iwr, 0, sizeof(iwr));
152 - os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
153 + os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
154 iwr.u.data.pointer = (caddr_t) range;
155 iwr.u.data.length = buflen;
156
157 @@ -1134,17 +1136,17 @@ madwifi_init(struct hostapd_data *hapd,
158 perror("socket[PF_INET,SOCK_DGRAM]");
159 goto bad;
160 }
161 - memcpy(drv->iface, params->ifname, sizeof(drv->iface));
162 + memcpy(drv->ifname, params->ifname, sizeof(drv->ifname));
163
164 memset(&ifr, 0, sizeof(ifr));
165 - os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
166 + os_strlcpy(ifr.ifr_name, drv->ifname, sizeof(ifr.ifr_name));
167 if (ioctl(drv->ioctl_sock, SIOCGIFINDEX, &ifr) != 0) {
168 perror("ioctl(SIOCGIFINDEX)");
169 goto bad;
170 }
171 drv->ifindex = ifr.ifr_ifindex;
172
173 - drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL,
174 + drv->sock_xmit = l2_packet_init(drv->ifname, NULL, ETH_P_EAPOL,
175 handle_read, drv, 1);
176 if (drv->sock_xmit == NULL)
177 goto bad;
178 @@ -1158,7 +1160,7 @@ madwifi_init(struct hostapd_data *hapd,
179 1);
180 if (drv->sock_recv == NULL)
181 goto bad;
182 - } else if (linux_br_get(brname, drv->iface) == 0) {
183 + } else if (linux_br_get(brname, drv->ifname) == 0) {
184 wpa_printf(MSG_DEBUG, "Interface in bridge %s; configure for "
185 "EAPOL receive", brname);
186 drv->sock_recv = l2_packet_init(brname, NULL, ETH_P_EAPOL,
187 @@ -1169,7 +1171,7 @@ madwifi_init(struct hostapd_data *hapd,
188 drv->sock_recv = drv->sock_xmit;
189
190 memset(&iwr, 0, sizeof(iwr));
191 - os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
192 + os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
193
194 iwr.u.mode = IW_MODE_MASTER;
195
196 @@ -1180,7 +1182,7 @@ madwifi_init(struct hostapd_data *hapd,
197 }
198
199 /* mark down during setup */
200 - linux_set_iface_flags(drv->ioctl_sock, drv->iface, 0);
201 + linux_set_iface_flags(drv->ioctl_sock, drv->ifname, 0);
202 madwifi_set_privacy(drv, 0); /* default to no privacy */
203
204 madwifi_receive_probe_req(drv);
205 @@ -1206,7 +1208,7 @@ madwifi_deinit(void *priv)
206 struct madwifi_driver_data *drv = priv;
207
208 netlink_deinit(drv->netlink);
209 - (void) linux_set_iface_flags(drv->ioctl_sock, drv->iface, 0);
210 + (void) linux_set_iface_flags(drv->ioctl_sock, drv->ifname, 0);
211 if (drv->ioctl_sock >= 0)
212 close(drv->ioctl_sock);
213 if (drv->sock_recv != NULL && drv->sock_recv != drv->sock_xmit)
214 @@ -1225,7 +1227,7 @@ madwifi_set_ssid(void *priv, const u8 *b
215 struct iwreq iwr;
216
217 memset(&iwr, 0, sizeof(iwr));
218 - os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
219 + os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
220 iwr.u.essid.flags = 1; /* SSID active */
221 iwr.u.essid.pointer = (caddr_t) buf;
222 iwr.u.essid.length = len + 1;
223 @@ -1246,7 +1248,7 @@ madwifi_get_ssid(void *priv, u8 *buf, in
224 int ret = 0;
225
226 memset(&iwr, 0, sizeof(iwr));
227 - os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
228 + os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
229 iwr.u.essid.pointer = (caddr_t) buf;
230 iwr.u.essid.length = len;
231
232 @@ -1271,140 +1273,19 @@ static int
233 madwifi_commit(void *priv)
234 {
235 struct madwifi_driver_data *drv = priv;
236 - return linux_set_iface_flags(drv->ioctl_sock, drv->iface, 1);
237 + return linux_set_iface_flags(drv->ioctl_sock, drv->ifname, 1);
238 }
239
240 -#else /* HOSTAPD */
241 +#endif /* HOSTAPD */
242
243 -struct wpa_driver_madwifi_data {
244 - void *wext; /* private data for driver_wext */
245 - void *ctx;
246 - char ifname[IFNAMSIZ + 1];
247 - int sock;
248 -};
249 +#if !defined(NO_SUPPLICANT)
250
251 static int wpa_driver_madwifi_set_auth_alg(void *priv, int auth_alg);
252 static int wpa_driver_madwifi_set_probe_req_ie(void *priv, const u8 *ies,
253 size_t ies_len);
254
255 -
256 -static int
257 -set80211priv(struct wpa_driver_madwifi_data *drv, int op, void *data, int len,
258 - int show_err)
259 -{
260 - struct iwreq iwr;
261 -
262 - os_memset(&iwr, 0, sizeof(iwr));
263 - os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
264 - if (len < IFNAMSIZ &&
265 - op != IEEE80211_IOCTL_SET_APPIEBUF) {
266 - /*
267 - * Argument data fits inline; put it there.
268 - */
269 - os_memcpy(iwr.u.name, data, len);
270 - } else {
271 - /*
272 - * Argument data too big for inline transfer; setup a
273 - * parameter block instead; the kernel will transfer
274 - * the data for the driver.
275 - */
276 - iwr.u.data.pointer = data;
277 - iwr.u.data.length = len;
278 - }
279 -
280 - if (ioctl(drv->sock, op, &iwr) < 0) {
281 - if (show_err) {
282 -#ifdef MADWIFI_NG
283 - int first = IEEE80211_IOCTL_SETPARAM;
284 - int last = IEEE80211_IOCTL_KICKMAC;
285 - static const char *opnames[] = {
286 - "ioctl[IEEE80211_IOCTL_SETPARAM]",
287 - "ioctl[IEEE80211_IOCTL_GETPARAM]",
288 - "ioctl[IEEE80211_IOCTL_SETMODE]",
289 - "ioctl[IEEE80211_IOCTL_GETMODE]",
290 - "ioctl[IEEE80211_IOCTL_SETWMMPARAMS]",
291 - "ioctl[IEEE80211_IOCTL_GETWMMPARAMS]",
292 - "ioctl[IEEE80211_IOCTL_SETCHANLIST]",
293 - "ioctl[IEEE80211_IOCTL_GETCHANLIST]",
294 - "ioctl[IEEE80211_IOCTL_CHANSWITCH]",
295 - NULL,
296 - "ioctl[IEEE80211_IOCTL_SET_APPIEBUF]",
297 - "ioctl[IEEE80211_IOCTL_GETSCANRESULTS]",
298 - NULL,
299 - "ioctl[IEEE80211_IOCTL_GETCHANINFO]",
300 - "ioctl[IEEE80211_IOCTL_SETOPTIE]",
301 - "ioctl[IEEE80211_IOCTL_GETOPTIE]",
302 - "ioctl[IEEE80211_IOCTL_SETMLME]",
303 - NULL,
304 - "ioctl[IEEE80211_IOCTL_SETKEY]",
305 - NULL,
306 - "ioctl[IEEE80211_IOCTL_DELKEY]",
307 - NULL,
308 - "ioctl[IEEE80211_IOCTL_ADDMAC]",
309 - NULL,
310 - "ioctl[IEEE80211_IOCTL_DELMAC]",
311 - NULL,
312 - "ioctl[IEEE80211_IOCTL_WDSMAC]",
313 - NULL,
314 - "ioctl[IEEE80211_IOCTL_WDSDELMAC]",
315 - NULL,
316 - "ioctl[IEEE80211_IOCTL_KICKMAC]",
317 - };
318 -#else /* MADWIFI_NG */
319 - int first = IEEE80211_IOCTL_SETPARAM;
320 - int last = IEEE80211_IOCTL_CHANLIST;
321 - static const char *opnames[] = {
322 - "ioctl[IEEE80211_IOCTL_SETPARAM]",
323 - "ioctl[IEEE80211_IOCTL_GETPARAM]",
324 - "ioctl[IEEE80211_IOCTL_SETKEY]",
325 - "ioctl[IEEE80211_IOCTL_GETKEY]",
326 - "ioctl[IEEE80211_IOCTL_DELKEY]",
327 - NULL,
328 - "ioctl[IEEE80211_IOCTL_SETMLME]",
329 - NULL,
330 - "ioctl[IEEE80211_IOCTL_SETOPTIE]",
331 - "ioctl[IEEE80211_IOCTL_GETOPTIE]",
332 - "ioctl[IEEE80211_IOCTL_ADDMAC]",
333 - NULL,
334 - "ioctl[IEEE80211_IOCTL_DELMAC]",
335 - NULL,
336 - "ioctl[IEEE80211_IOCTL_CHANLIST]",
337 - };
338 -#endif /* MADWIFI_NG */
339 - int idx = op - first;
340 - if (first <= op && op <= last &&
341 - idx < (int) (sizeof(opnames) / sizeof(opnames[0]))
342 - && opnames[idx])
343 - perror(opnames[idx]);
344 - else
345 - perror("ioctl[unknown???]");
346 - }
347 - return -1;
348 - }
349 - return 0;
350 -}
351 -
352 -static int
353 -set80211param(struct wpa_driver_madwifi_data *drv, int op, int arg,
354 - int show_err)
355 -{
356 - struct iwreq iwr;
357 -
358 - os_memset(&iwr, 0, sizeof(iwr));
359 - os_strlcpy(iwr.ifr_name, drv->ifname, IFNAMSIZ);
360 - iwr.u.mode = op;
361 - os_memcpy(iwr.u.name+sizeof(u32), &arg, sizeof(arg));
362 -
363 - if (ioctl(drv->sock, IEEE80211_IOCTL_SETPARAM, &iwr) < 0) {
364 - if (show_err)
365 - perror("ioctl[IEEE80211_IOCTL_SETPARAM]");
366 - return -1;
367 - }
368 - return 0;
369 -}
370 -
371 static int
372 -wpa_driver_madwifi_set_wpa_ie(struct wpa_driver_madwifi_data *drv,
373 +wpa_driver_madwifi_set_wpa_ie(struct madwifi_driver_data *drv,
374 const u8 *wpa_ie, size_t wpa_ie_len)
375 {
376 struct iwreq iwr;
377 @@ -1415,7 +1296,7 @@ wpa_driver_madwifi_set_wpa_ie(struct wpa
378 iwr.u.data.pointer = (void *) wpa_ie;
379 iwr.u.data.length = wpa_ie_len;
380
381 - if (ioctl(drv->sock, IEEE80211_IOCTL_SETOPTIE, &iwr) < 0) {
382 + if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_SETOPTIE, &iwr) < 0) {
383 perror("ioctl[IEEE80211_IOCTL_SETOPTIE]");
384 return -1;
385 }
386 @@ -1423,156 +1304,51 @@ wpa_driver_madwifi_set_wpa_ie(struct wpa
387 }
388
389 static int
390 -wpa_driver_madwifi_del_key(struct wpa_driver_madwifi_data *drv, int key_idx,
391 - const u8 *addr)
392 -{
393 - struct ieee80211req_del_key wk;
394 -
395 - wpa_printf(MSG_DEBUG, "%s: keyidx=%d", __FUNCTION__, key_idx);
396 - os_memset(&wk, 0, sizeof(wk));
397 - wk.idk_keyix = key_idx;
398 - if (addr != NULL)
399 - os_memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
400 -
401 - return set80211priv(drv, IEEE80211_IOCTL_DELKEY, &wk, sizeof(wk), 1);
402 -}
403 -
404 -static int
405 -wpa_driver_madwifi_set_key(const char *ifname, void *priv, enum wpa_alg alg,
406 - const u8 *addr, int key_idx, int set_tx,
407 - const u8 *seq, size_t seq_len,
408 - const u8 *key, size_t key_len)
409 -{
410 - struct wpa_driver_madwifi_data *drv = priv;
411 - struct ieee80211req_key wk;
412 - char *alg_name;
413 - u_int8_t cipher;
414 -
415 - if (alg == WPA_ALG_NONE)
416 - return wpa_driver_madwifi_del_key(drv, key_idx, addr);
417 -
418 - switch (alg) {
419 - case WPA_ALG_WEP:
420 - if (addr == NULL || os_memcmp(addr, "\xff\xff\xff\xff\xff\xff",
421 - ETH_ALEN) == 0) {
422 - /*
423 - * madwifi did not seem to like static WEP key
424 - * configuration with IEEE80211_IOCTL_SETKEY, so use
425 - * Linux wireless extensions ioctl for this.
426 - */
427 - return wpa_driver_wext_set_key(ifname, drv->wext, alg,
428 - addr, key_idx, set_tx,
429 - seq, seq_len,
430 - key, key_len);
431 - }
432 - alg_name = "WEP";
433 - cipher = IEEE80211_CIPHER_WEP;
434 - break;
435 - case WPA_ALG_TKIP:
436 - alg_name = "TKIP";
437 - cipher = IEEE80211_CIPHER_TKIP;
438 - break;
439 - case WPA_ALG_CCMP:
440 - alg_name = "CCMP";
441 - cipher = IEEE80211_CIPHER_AES_CCM;
442 - break;
443 - default:
444 - wpa_printf(MSG_DEBUG, "%s: unknown/unsupported algorithm %d",
445 - __FUNCTION__, alg);
446 - return -1;
447 - }
448 -
449 - wpa_printf(MSG_DEBUG, "%s: alg=%s key_idx=%d set_tx=%d seq_len=%lu "
450 - "key_len=%lu", __FUNCTION__, alg_name, key_idx, set_tx,
451 - (unsigned long) seq_len, (unsigned long) key_len);
452 -
453 - if (seq_len > sizeof(u_int64_t)) {
454 - wpa_printf(MSG_DEBUG, "%s: seq_len %lu too big",
455 - __FUNCTION__, (unsigned long) seq_len);
456 - return -2;
457 - }
458 - if (key_len > sizeof(wk.ik_keydata)) {
459 - wpa_printf(MSG_DEBUG, "%s: key length %lu too big",
460 - __FUNCTION__, (unsigned long) key_len);
461 - return -3;
462 - }
463 -
464 - os_memset(&wk, 0, sizeof(wk));
465 - wk.ik_type = cipher;
466 - wk.ik_flags = IEEE80211_KEY_RECV;
467 - if (addr == NULL ||
468 - os_memcmp(addr, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) == 0)
469 - wk.ik_flags |= IEEE80211_KEY_GROUP;
470 - if (set_tx) {
471 - wk.ik_flags |= IEEE80211_KEY_XMIT | IEEE80211_KEY_DEFAULT;
472 - os_memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
473 - } else
474 - os_memset(wk.ik_macaddr, 0, IEEE80211_ADDR_LEN);
475 - wk.ik_keyix = key_idx;
476 - wk.ik_keylen = key_len;
477 -#ifdef WORDS_BIGENDIAN
478 - {
479 - size_t i;
480 - u8 tmp[WPA_KEY_RSC_LEN];
481 - os_memset(tmp, 0, sizeof(tmp));
482 - for (i = 0; i < seq_len; i++)
483 - tmp[WPA_KEY_RSC_LEN - i - 1] = seq[i];
484 - os_memcpy(&wk.ik_keyrsc, tmp, WPA_KEY_RSC_LEN);
485 - }
486 -#else /* WORDS_BIGENDIAN */
487 - os_memcpy(&wk.ik_keyrsc, seq, seq_len);
488 -#endif /* WORDS_BIGENDIAN */
489 - os_memcpy(wk.ik_keydata, key, key_len);
490 -
491 - return set80211priv(drv, IEEE80211_IOCTL_SETKEY, &wk, sizeof(wk), 1);
492 -}
493 -
494 -static int
495 wpa_driver_madwifi_set_countermeasures(void *priv, int enabled)
496 {
497 - struct wpa_driver_madwifi_data *drv = priv;
498 + struct madwifi_driver_data *drv = priv;
499 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
500 - return set80211param(drv, IEEE80211_PARAM_COUNTERMEASURES, enabled, 1);
501 + return set80211param(drv, IEEE80211_PARAM_COUNTERMEASURES, enabled);
502 }
503
504 static int
505 wpa_driver_madwifi_deauthenticate(void *priv, const u8 *addr, int reason_code)
506 {
507 - struct wpa_driver_madwifi_data *drv = priv;
508 + struct madwifi_driver_data *drv = priv;
509 struct ieee80211req_mlme mlme;
510
511 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
512 mlme.im_op = IEEE80211_MLME_DEAUTH;
513 mlme.im_reason = reason_code;
514 os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
515 - return set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme), 1);
516 + return set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
517 }
518
519 static int
520 wpa_driver_madwifi_disassociate(void *priv, const u8 *addr, int reason_code)
521 {
522 - struct wpa_driver_madwifi_data *drv = priv;
523 + struct madwifi_driver_data *drv = priv;
524 struct ieee80211req_mlme mlme;
525
526 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
527 mlme.im_op = IEEE80211_MLME_DISASSOC;
528 mlme.im_reason = reason_code;
529 os_memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
530 - return set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme), 1);
531 + return set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
532 }
533
534 static int
535 wpa_driver_madwifi_associate(void *priv,
536 struct wpa_driver_associate_params *params)
537 {
538 - struct wpa_driver_madwifi_data *drv = priv;
539 + struct madwifi_driver_data *drv = priv;
540 struct ieee80211req_mlme mlme;
541 int ret = 0, privacy = 1;
542
543 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
544
545 if (set80211param(drv, IEEE80211_PARAM_DROPUNENCRYPTED,
546 - params->drop_unencrypted, 1) < 0)
547 + params->drop_unencrypted) < 0)
548 ret = -1;
549 if (wpa_driver_madwifi_set_auth_alg(drv, params->auth_alg) < 0)
550 ret = -1;
551 @@ -1595,12 +1371,12 @@ wpa_driver_madwifi_associate(void *priv,
552 params->wpa_ie_len == 0)
553 privacy = 0;
554
555 - if (set80211param(drv, IEEE80211_PARAM_PRIVACY, privacy, 1) < 0)
556 + if (set80211param(drv, IEEE80211_PARAM_PRIVACY, privacy) < 0)
557 ret = -1;
558
559 if (params->wpa_ie_len &&
560 set80211param(drv, IEEE80211_PARAM_WPA,
561 - params->wpa_ie[0] == WLAN_EID_RSN ? 2 : 1, 1) < 0)
562 + params->wpa_ie[0] == WLAN_EID_RSN ? 2 : 1) < 0)
563 ret = -1;
564
565 if (params->bssid == NULL) {
566 @@ -1608,14 +1384,14 @@ wpa_driver_madwifi_associate(void *priv,
567 * roaming */
568 /* FIX: this does not seem to work; would probably need to
569 * change something in the driver */
570 - if (set80211param(drv, IEEE80211_PARAM_ROAMING, 0, 1) < 0)
571 + if (set80211param(drv, IEEE80211_PARAM_ROAMING, 0) < 0)
572 ret = -1;
573
574 if (wpa_driver_wext_set_ssid(drv->wext, params->ssid,
575 params->ssid_len) < 0)
576 ret = -1;
577 } else {
578 - if (set80211param(drv, IEEE80211_PARAM_ROAMING, 2, 1) < 0)
579 + if (set80211param(drv, IEEE80211_PARAM_ROAMING, 2) < 0)
580 ret = -1;
581 if (wpa_driver_wext_set_ssid(drv->wext, params->ssid,
582 params->ssid_len) < 0)
583 @@ -1624,7 +1400,7 @@ wpa_driver_madwifi_associate(void *priv,
584 mlme.im_op = IEEE80211_MLME_ASSOC;
585 os_memcpy(mlme.im_macaddr, params->bssid, IEEE80211_ADDR_LEN);
586 if (set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme,
587 - sizeof(mlme), 1) < 0) {
588 + sizeof(mlme)) < 0) {
589 wpa_printf(MSG_DEBUG, "%s: SETMLME[ASSOC] failed",
590 __func__);
591 ret = -1;
592 @@ -1637,7 +1413,7 @@ wpa_driver_madwifi_associate(void *priv,
593 static int
594 wpa_driver_madwifi_set_auth_alg(void *priv, int auth_alg)
595 {
596 - struct wpa_driver_madwifi_data *drv = priv;
597 + struct madwifi_driver_data *drv = priv;
598 int authmode;
599
600 if ((auth_alg & WPA_AUTH_ALG_OPEN) &&
601 @@ -1648,13 +1424,13 @@ wpa_driver_madwifi_set_auth_alg(void *pr
602 else
603 authmode = IEEE80211_AUTH_OPEN;
604
605 - return set80211param(drv, IEEE80211_PARAM_AUTHMODE, authmode, 1);
606 + return set80211param(drv, IEEE80211_PARAM_AUTHMODE, authmode);
607 }
608
609 static int
610 wpa_driver_madwifi_scan(void *priv, struct wpa_driver_scan_params *params)
611 {
612 - struct wpa_driver_madwifi_data *drv = priv;
613 + struct madwifi_driver_data *drv = priv;
614 struct iwreq iwr;
615 int ret = 0;
616 const u8 *ssid = params->ssids[0].ssid;
617 @@ -1672,7 +1448,7 @@ wpa_driver_madwifi_scan(void *priv, stru
618 if (wpa_driver_wext_set_ssid(drv->wext, ssid, ssid_len) < 0)
619 ret = -1;
620
621 - if (ioctl(drv->sock, SIOCSIWSCAN, &iwr) < 0) {
622 + if (ioctl(drv->ioctl_sock, SIOCSIWSCAN, &iwr) < 0) {
623 perror("ioctl[SIOCSIWSCAN]");
624 ret = -1;
625 }
626 @@ -1694,14 +1470,14 @@ wpa_driver_madwifi_scan(void *priv, stru
627
628 static int wpa_driver_madwifi_get_bssid(void *priv, u8 *bssid)
629 {
630 - struct wpa_driver_madwifi_data *drv = priv;
631 + struct madwifi_driver_data *drv = priv;
632 return wpa_driver_wext_get_bssid(drv->wext, bssid);
633 }
634
635
636 static int wpa_driver_madwifi_get_ssid(void *priv, u8 *ssid)
637 {
638 - struct wpa_driver_madwifi_data *drv = priv;
639 + struct madwifi_driver_data *drv = priv;
640 return wpa_driver_wext_get_ssid(drv->wext, ssid);
641 }
642
643 @@ -1709,14 +1485,16 @@ static int wpa_driver_madwifi_get_ssid(v
644 static struct wpa_scan_results *
645 wpa_driver_madwifi_get_scan_results(void *priv)
646 {
647 - struct wpa_driver_madwifi_data *drv = priv;
648 + struct madwifi_driver_data *drv = priv;
649 return wpa_driver_wext_get_scan_results(drv->wext);
650 }
651
652
653 static int wpa_driver_madwifi_set_operstate(void *priv, int state)
654 {
655 - struct wpa_driver_madwifi_data *drv = priv;
656 + struct madwifi_driver_data *drv = priv;
657 + if (!drv->wext)
658 + return 0;
659 return wpa_driver_wext_set_operstate(drv->wext, state);
660 }
661
662 @@ -1737,7 +1515,7 @@ static int wpa_driver_madwifi_set_probe_
663
664 ret = set80211priv(priv, IEEE80211_IOCTL_SET_APPIEBUF, probe_req_ie,
665 sizeof(struct ieee80211req_getset_appiebuf) +
666 - ies_len, 1);
667 + ies_len);
668
669 os_free(probe_req_ie);
670
671 @@ -1747,7 +1525,7 @@ static int wpa_driver_madwifi_set_probe_
672
673 static void * wpa_driver_madwifi_init(void *ctx, const char *ifname)
674 {
675 - struct wpa_driver_madwifi_data *drv;
676 + struct madwifi_driver_data *drv;
677
678 drv = os_zalloc(sizeof(*drv));
679 if (drv == NULL)
680 @@ -1758,17 +1536,17 @@ static void * wpa_driver_madwifi_init(vo
681
682 drv->ctx = ctx;
683 os_strlcpy(drv->ifname, ifname, sizeof(drv->ifname));
684 - drv->sock = socket(PF_INET, SOCK_DGRAM, 0);
685 - if (drv->sock < 0)
686 + drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
687 + if (drv->ioctl_sock < 0)
688 goto fail2;
689
690 - if (set80211param(drv, IEEE80211_PARAM_ROAMING, 2, 1) < 0) {
691 + if (set80211param(drv, IEEE80211_PARAM_ROAMING, 2) < 0) {
692 wpa_printf(MSG_DEBUG, "%s: failed to set wpa_supplicant-based "
693 "roaming", __FUNCTION__);
694 goto fail3;
695 }
696
697 - if (set80211param(drv, IEEE80211_PARAM_WPA, 3, 1) < 0) {
698 + if (set80211param(drv, IEEE80211_PARAM_WPA, 3) < 0) {
699 wpa_printf(MSG_DEBUG, "%s: failed to enable WPA support",
700 __FUNCTION__);
701 goto fail3;
702 @@ -1777,7 +1555,7 @@ static void * wpa_driver_madwifi_init(vo
703 return drv;
704
705 fail3:
706 - close(drv->sock);
707 + close(drv->ioctl_sock);
708 fail2:
709 wpa_driver_wext_deinit(drv->wext);
710 fail:
711 @@ -1788,38 +1566,37 @@ fail:
712
713 static void wpa_driver_madwifi_deinit(void *priv)
714 {
715 - struct wpa_driver_madwifi_data *drv = priv;
716 + struct madwifi_driver_data *drv = priv;
717
718 if (wpa_driver_madwifi_set_wpa_ie(drv, NULL, 0) < 0) {
719 wpa_printf(MSG_DEBUG, "%s: failed to clear WPA IE",
720 __FUNCTION__);
721 }
722 - if (set80211param(drv, IEEE80211_PARAM_ROAMING, 0, 1) < 0) {
723 + if (set80211param(drv, IEEE80211_PARAM_ROAMING, 0) < 0) {
724 wpa_printf(MSG_DEBUG, "%s: failed to enable driver-based "
725 "roaming", __FUNCTION__);
726 }
727 - if (set80211param(drv, IEEE80211_PARAM_PRIVACY, 0, 1) < 0) {
728 + if (set80211param(drv, IEEE80211_PARAM_PRIVACY, 0) < 0) {
729 wpa_printf(MSG_DEBUG, "%s: failed to disable forced Privacy "
730 "flag", __FUNCTION__);
731 }
732 - if (set80211param(drv, IEEE80211_PARAM_WPA, 0, 1) < 0) {
733 + if (set80211param(drv, IEEE80211_PARAM_WPA, 0) < 0) {
734 wpa_printf(MSG_DEBUG, "%s: failed to disable WPA",
735 __FUNCTION__);
736 }
737
738 wpa_driver_wext_deinit(drv->wext);
739
740 - close(drv->sock);
741 + close(drv->ioctl_sock);
742 os_free(drv);
743 }
744
745 -#endif /* HOSTAPD */
746 -
747 +#endif
748
749 const struct wpa_driver_ops wpa_driver_madwifi_ops = {
750 .name = "madwifi",
751 .desc = "MADWIFI 802.11 support (Atheros, etc.)",
752 - .set_key = wpa_driver_madwifi_set_key,
753 + .set_key = madwifi_set_key,
754 #ifdef HOSTAPD
755 .hapd_init = madwifi_init,
756 .hapd_deinit = madwifi_deinit,
757 @@ -1839,7 +1616,8 @@ const struct wpa_driver_ops wpa_driver_m
758 .sta_clear_stats = madwifi_sta_clear_stats,
759 .commit = madwifi_commit,
760 .set_ap_wps_ie = madwifi_set_ap_wps_ie,
761 -#else /* HOSTAPD */
762 +#endif /* HOSTAPD */
763 +#if !defined(NO_SUPPLICANT)
764 .get_bssid = wpa_driver_madwifi_get_bssid,
765 .get_ssid = wpa_driver_madwifi_get_ssid,
766 .init = wpa_driver_madwifi_init,
767 @@ -1851,5 +1629,5 @@ const struct wpa_driver_ops wpa_driver_m
768 .disassociate = wpa_driver_madwifi_disassociate,
769 .associate = wpa_driver_madwifi_associate,
770 .set_operstate = wpa_driver_madwifi_set_operstate,
771 -#endif /* HOSTAPD */
772 +#endif
773 };
774 --- a/src/drivers/drivers.mak
775 +++ b/src/drivers/drivers.mak
776 @@ -168,8 +168,8 @@ DRV_WPA_OBJS += ../src/drivers/driver_ro
777 endif
778
779 ifdef CONFIG_WIRELESS_EXTENSION
780 -DRV_WPA_CFLAGS += -DCONFIG_WIRELESS_EXTENSION
781 -DRV_WPA_OBJS += ../src/drivers/driver_wext.o
782 +DRV_CFLAGS += -DCONFIG_WIRELESS_EXTENSION
783 +DRV_OBJS += ../src/drivers/driver_wext.o
784 NEED_RFKILL=y
785 endif
786