mac80211: add the work-in-progress IBSS HT patch, with some minor fixes
[openwrt.git] / package / hostapd / patches / 350-hostap_multicall_fix.patch
1 --- a/src/drivers/driver_hostap.c
2 +++ b/src/drivers/driver_hostap.c
3 @@ -22,9 +22,6 @@
4 #include "eloop.h"
5 #include "driver_hostap.h"
6
7 -
8 -#ifdef HOSTAPD
9 -
10 #include <net/if_arp.h>
11 #include <netpacket/packet.h>
12
13 @@ -42,10 +39,16 @@
14 static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
15
16 struct hostap_driver_data {
17 + void *wext; /* private data for driver_wext */
18 + void *ctx;
19 + char ifname[IFNAMSIZ + 1];
20 + int sock;
21 + int current_mode; /* infra/adhoc */
22 +
23 +#ifdef HOSTAPD
24 struct hostapd_data *hapd;
25
26 char iface[IFNAMSIZ + 1];
27 - int sock; /* raw packet socket for driver access */
28 int ioctl_sock; /* socket for ioctl() use */
29 struct netlink_data *netlink;
30
31 @@ -55,9 +58,11 @@ struct hostap_driver_data {
32 size_t generic_ie_len;
33 u8 *wps_ie;
34 size_t wps_ie_len;
35 +#endif
36 };
37
38
39 +#ifdef HOSTAPD
40 static int hostapd_ioctl(void *priv, struct prism2_hostapd_param *param,
41 int len);
42 static int hostap_set_iface_flags(void *priv, int dev_up);
43 @@ -400,65 +405,6 @@ static int hostapd_ioctl(void *priv, str
44 }
45
46
47 -static int wpa_driver_hostap_set_key(const char *ifname, void *priv,
48 - enum wpa_alg alg, const u8 *addr,
49 - int key_idx, int set_tx,
50 - const u8 *seq, size_t seq_len,
51 - const u8 *key, size_t key_len)
52 -{
53 - struct hostap_driver_data *drv = priv;
54 - struct prism2_hostapd_param *param;
55 - u8 *buf;
56 - size_t blen;
57 - int ret = 0;
58 -
59 - blen = sizeof(*param) + key_len;
60 - buf = os_zalloc(blen);
61 - if (buf == NULL)
62 - return -1;
63 -
64 - param = (struct prism2_hostapd_param *) buf;
65 - param->cmd = PRISM2_SET_ENCRYPTION;
66 - if (addr == NULL)
67 - memset(param->sta_addr, 0xff, ETH_ALEN);
68 - else
69 - memcpy(param->sta_addr, addr, ETH_ALEN);
70 - switch (alg) {
71 - case WPA_ALG_NONE:
72 - os_strlcpy((char *) param->u.crypt.alg, "NONE",
73 - HOSTAP_CRYPT_ALG_NAME_LEN);
74 - break;
75 - case WPA_ALG_WEP:
76 - os_strlcpy((char *) param->u.crypt.alg, "WEP",
77 - HOSTAP_CRYPT_ALG_NAME_LEN);
78 - break;
79 - case WPA_ALG_TKIP:
80 - os_strlcpy((char *) param->u.crypt.alg, "TKIP",
81 - HOSTAP_CRYPT_ALG_NAME_LEN);
82 - break;
83 - case WPA_ALG_CCMP:
84 - os_strlcpy((char *) param->u.crypt.alg, "CCMP",
85 - HOSTAP_CRYPT_ALG_NAME_LEN);
86 - break;
87 - default:
88 - os_free(buf);
89 - return -1;
90 - }
91 - param->u.crypt.flags = set_tx ? HOSTAP_CRYPT_FLAG_SET_TX_KEY : 0;
92 - param->u.crypt.idx = key_idx;
93 - param->u.crypt.key_len = key_len;
94 - memcpy((u8 *) (param + 1), key, key_len);
95 -
96 - if (hostapd_ioctl(drv, param, blen)) {
97 - printf("Failed to set encryption.\n");
98 - ret = -1;
99 - }
100 - free(buf);
101 -
102 - return ret;
103 -}
104 -
105 -
106 static int hostap_get_seqnum(const char *ifname, void *priv, const u8 *addr,
107 int idx, u8 *seq)
108 {
109 @@ -1126,21 +1072,9 @@ static struct hostapd_hw_modes * hostap_
110 return mode;
111 }
112
113 -#else /* HOSTAPD */
114 -
115 -struct wpa_driver_hostap_data {
116 - void *wext; /* private data for driver_wext */
117 - void *ctx;
118 - char ifname[IFNAMSIZ + 1];
119 - int sock;
120 - int current_mode; /* infra/adhoc */
121 -};
122 -
123 -
124 -static int wpa_driver_hostap_set_auth_alg(void *priv, int auth_alg);
125 -
126 +#endif /* HOSTAPD */
127
128 -static int hostapd_ioctl(struct wpa_driver_hostap_data *drv,
129 +static int wpa_hostapd_ioctl(struct hostap_driver_data *drv,
130 struct prism2_hostapd_param *param,
131 int len, int show_err)
132 {
133 @@ -1162,7 +1096,12 @@ static int hostapd_ioctl(struct wpa_driv
134 }
135
136
137 -static int wpa_driver_hostap_set_wpa_ie(struct wpa_driver_hostap_data *drv,
138 +#if !defined(NO_SUPPLICANT)
139 +
140 +static int wpa_driver_hostap_set_auth_alg(void *priv, int auth_alg);
141 +
142 +
143 +static int wpa_driver_hostap_set_wpa_ie(struct hostap_driver_data *drv,
144 const u8 *wpa_ie, size_t wpa_ie_len)
145 {
146 struct prism2_hostapd_param *param;
147 @@ -1178,7 +1117,7 @@ static int wpa_driver_hostap_set_wpa_ie(
148 param->cmd = PRISM2_HOSTAPD_SET_GENERIC_ELEMENT;
149 param->u.generic_elem.len = wpa_ie_len;
150 os_memcpy(param->u.generic_elem.data, wpa_ie, wpa_ie_len);
151 - res = hostapd_ioctl(drv, param, blen, 1);
152 + res = wpa_hostapd_ioctl(drv, param, blen, 1);
153
154 os_free(param);
155
156 @@ -1186,7 +1125,7 @@ static int wpa_driver_hostap_set_wpa_ie(
157 }
158
159
160 -static int prism2param(struct wpa_driver_hostap_data *drv, int param,
161 +static int prism2param(struct hostap_driver_data *drv, int param,
162 int value)
163 {
164 struct iwreq iwr;
165 @@ -1208,7 +1147,7 @@ static int prism2param(struct wpa_driver
166
167 static int wpa_driver_hostap_set_wpa(void *priv, int enabled)
168 {
169 - struct wpa_driver_hostap_data *drv = priv;
170 + struct hostap_driver_data *drv = priv;
171 int ret = 0;
172
173 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
174 @@ -1224,125 +1163,15 @@ static int wpa_driver_hostap_set_wpa(voi
175 }
176
177
178 -static void show_set_key_error(struct prism2_hostapd_param *param)
179 -{
180 - switch (param->u.crypt.err) {
181 - case HOSTAP_CRYPT_ERR_UNKNOWN_ALG:
182 - wpa_printf(MSG_INFO, "Unknown algorithm '%s'.",
183 - param->u.crypt.alg);
184 - wpa_printf(MSG_INFO, "You may need to load kernel module to "
185 - "register that algorithm.");
186 - wpa_printf(MSG_INFO, "E.g., 'modprobe hostap_crypt_wep' for "
187 - "WEP.");
188 - break;
189 - case HOSTAP_CRYPT_ERR_UNKNOWN_ADDR:
190 - wpa_printf(MSG_INFO, "Unknown address " MACSTR ".",
191 - MAC2STR(param->sta_addr));
192 - break;
193 - case HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED:
194 - wpa_printf(MSG_INFO, "Crypt algorithm initialization failed.");
195 - break;
196 - case HOSTAP_CRYPT_ERR_KEY_SET_FAILED:
197 - wpa_printf(MSG_INFO, "Key setting failed.");
198 - break;
199 - case HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED:
200 - wpa_printf(MSG_INFO, "TX key index setting failed.");
201 - break;
202 - case HOSTAP_CRYPT_ERR_CARD_CONF_FAILED:
203 - wpa_printf(MSG_INFO, "Card configuration failed.");
204 - break;
205 - }
206 -}
207 -
208 -
209 -static int wpa_driver_hostap_set_key(const char *ifname, void *priv,
210 - enum wpa_alg alg, const u8 *addr,
211 - int key_idx, int set_tx,
212 - const u8 *seq, size_t seq_len,
213 - const u8 *key, size_t key_len)
214 -{
215 - struct wpa_driver_hostap_data *drv = priv;
216 - struct prism2_hostapd_param *param;
217 - u8 *buf;
218 - size_t blen;
219 - int ret = 0;
220 - char *alg_name;
221 -
222 - switch (alg) {
223 - case WPA_ALG_NONE:
224 - alg_name = "none";
225 - break;
226 - case WPA_ALG_WEP:
227 - alg_name = "WEP";
228 - break;
229 - case WPA_ALG_TKIP:
230 - alg_name = "TKIP";
231 - break;
232 - case WPA_ALG_CCMP:
233 - alg_name = "CCMP";
234 - break;
235 - default:
236 - return -1;
237 - }
238 -
239 - wpa_printf(MSG_DEBUG, "%s: alg=%s key_idx=%d set_tx=%d seq_len=%lu "
240 - "key_len=%lu", __FUNCTION__, alg_name, key_idx, set_tx,
241 - (unsigned long) seq_len, (unsigned long) key_len);
242 -
243 - if (seq_len > 8)
244 - return -2;
245 -
246 - blen = sizeof(*param) + key_len;
247 - buf = os_zalloc(blen);
248 - if (buf == NULL)
249 - return -1;
250 -
251 - param = (struct prism2_hostapd_param *) buf;
252 - param->cmd = PRISM2_SET_ENCRYPTION;
253 - /* TODO: In theory, STA in client mode can use five keys; four default
254 - * keys for receiving (with keyidx 0..3) and one individual key for
255 - * both transmitting and receiving (keyidx 0) _unicast_ packets. Now,
256 - * keyidx 0 is reserved for this unicast use and default keys can only
257 - * use keyidx 1..3 (i.e., default key with keyidx 0 is not supported).
258 - * This should be fine for more or less all cases, but for completeness
259 - * sake, the driver could be enhanced to support the missing key. */
260 -#if 0
261 - if (addr == NULL)
262 - os_memset(param->sta_addr, 0xff, ETH_ALEN);
263 - else
264 - os_memcpy(param->sta_addr, addr, ETH_ALEN);
265 -#else
266 - os_memset(param->sta_addr, 0xff, ETH_ALEN);
267 -#endif
268 - os_strlcpy((char *) param->u.crypt.alg, alg_name,
269 - HOSTAP_CRYPT_ALG_NAME_LEN);
270 - param->u.crypt.flags = set_tx ? HOSTAP_CRYPT_FLAG_SET_TX_KEY : 0;
271 - param->u.crypt.idx = key_idx;
272 - if (seq)
273 - os_memcpy(param->u.crypt.seq, seq, seq_len);
274 - param->u.crypt.key_len = key_len;
275 - os_memcpy((u8 *) (param + 1), key, key_len);
276 -
277 - if (hostapd_ioctl(drv, param, blen, 1)) {
278 - wpa_printf(MSG_WARNING, "Failed to set encryption.");
279 - show_set_key_error(param);
280 - ret = -1;
281 - }
282 - os_free(buf);
283 -
284 - return ret;
285 -}
286 -
287 -
288 static int wpa_driver_hostap_set_countermeasures(void *priv, int enabled)
289 {
290 - struct wpa_driver_hostap_data *drv = priv;
291 + struct hostap_driver_data *drv = priv;
292 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
293 return prism2param(drv, PRISM2_PARAM_TKIP_COUNTERMEASURES, enabled);
294 }
295
296
297 -static int wpa_driver_hostap_reset(struct wpa_driver_hostap_data *drv,
298 +static int wpa_driver_hostap_reset(struct hostap_driver_data *drv,
299 int type)
300 {
301 struct iwreq iwr;
302 @@ -1363,7 +1192,7 @@ static int wpa_driver_hostap_reset(struc
303 }
304
305
306 -static int wpa_driver_hostap_mlme(struct wpa_driver_hostap_data *drv,
307 +static int wpa_driver_hostap_mlme(struct hostap_driver_data *drv,
308 const u8 *addr, int cmd, int reason_code)
309 {
310 struct prism2_hostapd_param param;
311 @@ -1378,7 +1207,7 @@ static int wpa_driver_hostap_mlme(struct
312 os_memcpy(param.sta_addr, addr, ETH_ALEN);
313 param.u.mlme.cmd = cmd;
314 param.u.mlme.reason_code = reason_code;
315 - ret = hostapd_ioctl(drv, &param, sizeof(param), 1);
316 + ret = wpa_hostapd_ioctl(drv, &param, sizeof(param), 1);
317 if (ret == 0) {
318 os_sleep(0, 100000);
319 ret = wpa_driver_hostap_reset(drv, 2);
320 @@ -1390,7 +1219,7 @@ static int wpa_driver_hostap_mlme(struct
321 static int wpa_driver_hostap_deauthenticate(void *priv, const u8 *addr,
322 int reason_code)
323 {
324 - struct wpa_driver_hostap_data *drv = priv;
325 + struct hostap_driver_data *drv = priv;
326 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
327 return wpa_driver_hostap_mlme(drv, addr, MLME_STA_DEAUTH,
328 reason_code);
329 @@ -1400,7 +1229,7 @@ static int wpa_driver_hostap_deauthentic
330 static int wpa_driver_hostap_disassociate(void *priv, const u8 *addr,
331 int reason_code)
332 {
333 - struct wpa_driver_hostap_data *drv = priv;
334 + struct hostap_driver_data *drv = priv;
335 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
336 return wpa_driver_hostap_mlme(drv, addr, MLME_STA_DISASSOC,
337 reason_code);
338 @@ -1411,7 +1240,7 @@ static int
339 wpa_driver_hostap_associate(void *priv,
340 struct wpa_driver_associate_params *params)
341 {
342 - struct wpa_driver_hostap_data *drv = priv;
343 + struct hostap_driver_data *drv = priv;
344 int ret = 0;
345 int allow_unencrypted_eapol;
346
347 @@ -1475,7 +1304,7 @@ wpa_driver_hostap_associate(void *priv,
348 static int wpa_driver_hostap_scan(void *priv,
349 struct wpa_driver_scan_params *params)
350 {
351 - struct wpa_driver_hostap_data *drv = priv;
352 + struct hostap_driver_data *drv = priv;
353 struct prism2_hostapd_param param;
354 int ret;
355 const u8 *ssid = params->ssids[0].ssid;
356 @@ -1496,7 +1325,7 @@ static int wpa_driver_hostap_scan(void *
357 param.cmd = PRISM2_HOSTAPD_SCAN_REQ;
358 param.u.scan_req.ssid_len = ssid_len;
359 os_memcpy(param.u.scan_req.ssid, ssid, ssid_len);
360 - ret = hostapd_ioctl(drv, &param, sizeof(param), 1);
361 + ret = wpa_hostapd_ioctl(drv, &param, sizeof(param), 1);
362
363 /* Not all drivers generate "scan completed" wireless event, so try to
364 * read results after a timeout. */
365 @@ -1511,7 +1340,7 @@ static int wpa_driver_hostap_scan(void *
366
367 static int wpa_driver_hostap_set_auth_alg(void *priv, int auth_alg)
368 {
369 - struct wpa_driver_hostap_data *drv = priv;
370 + struct hostap_driver_data *drv = priv;
371 int algs = 0;
372
373 if (auth_alg & WPA_AUTH_ALG_OPEN)
374 @@ -1529,35 +1358,35 @@ static int wpa_driver_hostap_set_auth_al
375
376 static int wpa_driver_hostap_get_bssid(void *priv, u8 *bssid)
377 {
378 - struct wpa_driver_hostap_data *drv = priv;
379 + struct hostap_driver_data *drv = priv;
380 return wpa_driver_wext_get_bssid(drv->wext, bssid);
381 }
382
383
384 static int wpa_driver_hostap_get_ssid(void *priv, u8 *ssid)
385 {
386 - struct wpa_driver_hostap_data *drv = priv;
387 + struct hostap_driver_data *drv = priv;
388 return wpa_driver_wext_get_ssid(drv->wext, ssid);
389 }
390
391
392 static struct wpa_scan_results * wpa_driver_hostap_get_scan_results(void *priv)
393 {
394 - struct wpa_driver_hostap_data *drv = priv;
395 + struct hostap_driver_data *drv = priv;
396 return wpa_driver_wext_get_scan_results(drv->wext);
397 }
398
399
400 static int wpa_driver_hostap_set_operstate(void *priv, int state)
401 {
402 - struct wpa_driver_hostap_data *drv = priv;
403 + struct hostap_driver_data *drv = priv;
404 return wpa_driver_wext_set_operstate(drv->wext, state);
405 }
406
407
408 static void * wpa_driver_hostap_init(void *ctx, const char *ifname)
409 {
410 - struct wpa_driver_hostap_data *drv;
411 + struct hostap_driver_data *drv;
412
413 drv = os_zalloc(sizeof(*drv));
414 if (drv == NULL)
415 @@ -1597,14 +1426,120 @@ static void * wpa_driver_hostap_init(voi
416
417 static void wpa_driver_hostap_deinit(void *priv)
418 {
419 - struct wpa_driver_hostap_data *drv = priv;
420 + struct hostap_driver_data *drv = priv;
421 wpa_driver_hostap_set_wpa(drv, 0);
422 wpa_driver_wext_deinit(drv->wext);
423 close(drv->sock);
424 os_free(drv);
425 }
426
427 -#endif /* HOSTAPD */
428 +#endif
429 +
430 +
431 +static void show_set_key_error(struct prism2_hostapd_param *param)
432 +{
433 + switch (param->u.crypt.err) {
434 + case HOSTAP_CRYPT_ERR_UNKNOWN_ALG:
435 + wpa_printf(MSG_INFO, "Unknown algorithm '%s'.",
436 + param->u.crypt.alg);
437 + wpa_printf(MSG_INFO, "You may need to load kernel module to "
438 + "register that algorithm.");
439 + wpa_printf(MSG_INFO, "E.g., 'modprobe hostap_crypt_wep' for "
440 + "WEP.");
441 + break;
442 + case HOSTAP_CRYPT_ERR_UNKNOWN_ADDR:
443 + wpa_printf(MSG_INFO, "Unknown address " MACSTR ".",
444 + MAC2STR(param->sta_addr));
445 + break;
446 + case HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED:
447 + wpa_printf(MSG_INFO, "Crypt algorithm initialization failed.");
448 + break;
449 + case HOSTAP_CRYPT_ERR_KEY_SET_FAILED:
450 + wpa_printf(MSG_INFO, "Key setting failed.");
451 + break;
452 + case HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED:
453 + wpa_printf(MSG_INFO, "TX key index setting failed.");
454 + break;
455 + case HOSTAP_CRYPT_ERR_CARD_CONF_FAILED:
456 + wpa_printf(MSG_INFO, "Card configuration failed.");
457 + break;
458 + }
459 +}
460 +
461 +
462 +static int wpa_driver_hostap_set_key(const char *ifname, void *priv,
463 + enum wpa_alg alg, const u8 *addr,
464 + int key_idx, int set_tx,
465 + const u8 *seq, size_t seq_len,
466 + const u8 *key, size_t key_len)
467 +{
468 + struct hostap_driver_data *drv = priv;
469 + struct prism2_hostapd_param *param;
470 + u8 *buf;
471 + size_t blen;
472 + int ret = 0;
473 + char *alg_name;
474 +
475 + switch (alg) {
476 + case WPA_ALG_NONE:
477 + alg_name = "none";
478 + break;
479 + case WPA_ALG_WEP:
480 + alg_name = "WEP";
481 + break;
482 + case WPA_ALG_TKIP:
483 + alg_name = "TKIP";
484 + break;
485 + case WPA_ALG_CCMP:
486 + alg_name = "CCMP";
487 + break;
488 + default:
489 + return -1;
490 + }
491 +
492 + wpa_printf(MSG_DEBUG, "%s: alg=%s key_idx=%d set_tx=%d seq_len=%lu "
493 + "key_len=%lu", __FUNCTION__, alg_name, key_idx, set_tx,
494 + (unsigned long) seq_len, (unsigned long) key_len);
495 +
496 + if (seq_len > 8)
497 + return -2;
498 +
499 + blen = sizeof(*param) + key_len;
500 + buf = os_zalloc(blen);
501 + if (buf == NULL)
502 + return -1;
503 +
504 + param = (struct prism2_hostapd_param *) buf;
505 + param->cmd = PRISM2_SET_ENCRYPTION;
506 + /* TODO: In theory, STA in client mode can use five keys; four default
507 + * keys for receiving (with keyidx 0..3) and one individual key for
508 + * both transmitting and receiving (keyidx 0) _unicast_ packets. Now,
509 + * keyidx 0 is reserved for this unicast use and default keys can only
510 + * use keyidx 1..3 (i.e., default key with keyidx 0 is not supported).
511 + * This should be fine for more or less all cases, but for completeness
512 + * sake, the driver could be enhanced to support the missing key. */
513 + if (addr == NULL)
514 + os_memset(param->sta_addr, 0xff, ETH_ALEN);
515 + else
516 + os_memcpy(param->sta_addr, addr, ETH_ALEN);
517 + os_strlcpy((char *) param->u.crypt.alg, alg_name,
518 + HOSTAP_CRYPT_ALG_NAME_LEN);
519 + param->u.crypt.flags = set_tx ? HOSTAP_CRYPT_FLAG_SET_TX_KEY : 0;
520 + param->u.crypt.idx = key_idx;
521 + if (seq)
522 + os_memcpy(param->u.crypt.seq, seq, seq_len);
523 + param->u.crypt.key_len = key_len;
524 + os_memcpy((u8 *) (param + 1), key, key_len);
525 +
526 + if (wpa_hostapd_ioctl(drv, param, blen, 1)) {
527 + wpa_printf(MSG_WARNING, "Failed to set encryption.");
528 + show_set_key_error(param);
529 + ret = -1;
530 + }
531 + os_free(buf);
532 +
533 + return ret;
534 +}
535
536
537 const struct wpa_driver_ops wpa_driver_hostap_ops = {
538 @@ -1632,7 +1567,8 @@ const struct wpa_driver_ops wpa_driver_h
539 .sta_clear_stats = hostap_sta_clear_stats,
540 .get_hw_feature_data = hostap_get_hw_feature_data,
541 .set_ap_wps_ie = hostap_set_ap_wps_ie,
542 -#else /* HOSTAPD */
543 +#endif /* HOSTAPD */
544 +#if !defined(NO_SUPPLICANT)
545 .get_bssid = wpa_driver_hostap_get_bssid,
546 .get_ssid = wpa_driver_hostap_get_ssid,
547 .set_countermeasures = wpa_driver_hostap_set_countermeasures,
548 @@ -1644,5 +1580,5 @@ const struct wpa_driver_ops wpa_driver_h
549 .init = wpa_driver_hostap_init,
550 .deinit = wpa_driver_hostap_deinit,
551 .set_operstate = wpa_driver_hostap_set_operstate,
552 -#endif /* HOSTAPD */
553 +#endif
554 };
This page took 0.061329 seconds and 5 git commands to generate.