1 --- a/src/drivers/driver_hostap.c
2 +++ b/src/drivers/driver_hostap.c
5 #include "driver_hostap.h"
10 #include <net/if_arp.h>
11 #include <netpacket/packet.h>
14 static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
16 struct hostap_driver_data {
17 + void *wext; /* private data for driver_wext */
19 + char ifname[IFNAMSIZ + 1];
21 + int current_mode; /* infra/adhoc */
24 struct hostapd_data *hapd;
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;
31 @@ -55,9 +58,11 @@ struct hostap_driver_data {
32 size_t generic_ie_len;
40 static int hostapd_ioctl(void *priv, struct prism2_hostapd_param *param,
42 static int hostap_set_iface_flags(void *priv, int dev_up);
43 @@ -400,65 +405,6 @@ static int hostapd_ioctl(void *priv, str
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)
53 - struct hostap_driver_data *drv = priv;
54 - struct prism2_hostapd_param *param;
59 - blen = sizeof(*param) + key_len;
60 - buf = os_zalloc(blen);
64 - param = (struct prism2_hostapd_param *) buf;
65 - param->cmd = PRISM2_SET_ENCRYPTION;
67 - memset(param->sta_addr, 0xff, ETH_ALEN);
69 - memcpy(param->sta_addr, addr, ETH_ALEN);
72 - os_strlcpy((char *) param->u.crypt.alg, "NONE",
73 - HOSTAP_CRYPT_ALG_NAME_LEN);
76 - os_strlcpy((char *) param->u.crypt.alg, "WEP",
77 - HOSTAP_CRYPT_ALG_NAME_LEN);
80 - os_strlcpy((char *) param->u.crypt.alg, "TKIP",
81 - HOSTAP_CRYPT_ALG_NAME_LEN);
84 - os_strlcpy((char *) param->u.crypt.alg, "CCMP",
85 - HOSTAP_CRYPT_ALG_NAME_LEN);
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);
96 - if (hostapd_ioctl(drv, param, blen)) {
97 - printf("Failed to set encryption.\n");
106 static int hostap_get_seqnum(const char *ifname, void *priv, const u8 *addr,
109 @@ -1126,21 +1072,9 @@ static struct hostapd_hw_modes * hostap_
115 -struct wpa_driver_hostap_data {
116 - void *wext; /* private data for driver_wext */
118 - char ifname[IFNAMSIZ + 1];
120 - int current_mode; /* infra/adhoc */
124 -static int wpa_driver_hostap_set_auth_alg(void *priv, int auth_alg);
126 +#endif /* HOSTAPD */
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)
133 @@ -1162,7 +1096,12 @@ static int hostapd_ioctl(struct wpa_driv
137 -static int wpa_driver_hostap_set_wpa_ie(struct wpa_driver_hostap_data *drv,
138 +#if !defined(NO_SUPPLICANT)
140 +static int wpa_driver_hostap_set_auth_alg(void *priv, int auth_alg);
143 +static int wpa_driver_hostap_set_wpa_ie(struct hostap_driver_data *drv,
144 const u8 *wpa_ie, size_t wpa_ie_len)
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);
156 @@ -1186,7 +1125,7 @@ static int wpa_driver_hostap_set_wpa_ie(
160 -static int prism2param(struct wpa_driver_hostap_data *drv, int param,
161 +static int prism2param(struct hostap_driver_data *drv, int param,
165 @@ -1208,7 +1147,7 @@ static int prism2param(struct wpa_driver
167 static int wpa_driver_hostap_set_wpa(void *priv, int enabled)
169 - struct wpa_driver_hostap_data *drv = priv;
170 + struct hostap_driver_data *drv = priv;
173 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
174 @@ -1224,125 +1163,15 @@ static int wpa_driver_hostap_set_wpa(voi
178 -static void show_set_key_error(struct prism2_hostapd_param *param)
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 "
189 - case HOSTAP_CRYPT_ERR_UNKNOWN_ADDR:
190 - wpa_printf(MSG_INFO, "Unknown address " MACSTR ".",
191 - MAC2STR(param->sta_addr));
193 - case HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED:
194 - wpa_printf(MSG_INFO, "Crypt algorithm initialization failed.");
196 - case HOSTAP_CRYPT_ERR_KEY_SET_FAILED:
197 - wpa_printf(MSG_INFO, "Key setting failed.");
199 - case HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED:
200 - wpa_printf(MSG_INFO, "TX key index setting failed.");
202 - case HOSTAP_CRYPT_ERR_CARD_CONF_FAILED:
203 - wpa_printf(MSG_INFO, "Card configuration failed.");
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)
215 - struct wpa_driver_hostap_data *drv = priv;
216 - struct prism2_hostapd_param *param;
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);
246 - blen = sizeof(*param) + key_len;
247 - buf = os_zalloc(blen);
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. */
262 - os_memset(param->sta_addr, 0xff, ETH_ALEN);
264 - os_memcpy(param->sta_addr, addr, ETH_ALEN);
266 - os_memset(param->sta_addr, 0xff, ETH_ALEN);
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;
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);
277 - if (hostapd_ioctl(drv, param, blen, 1)) {
278 - wpa_printf(MSG_WARNING, "Failed to set encryption.");
279 - show_set_key_error(param);
288 static int wpa_driver_hostap_set_countermeasures(void *priv, int enabled)
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);
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,
302 @@ -1363,7 +1192,7 @@ static int wpa_driver_hostap_reset(struc
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)
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, ¶m, sizeof(param), 1);
316 + ret = wpa_hostapd_ioctl(drv, ¶m, sizeof(param), 1);
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,
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,
329 @@ -1400,7 +1229,7 @@ static int wpa_driver_hostap_deauthentic
330 static int wpa_driver_hostap_disassociate(void *priv, const u8 *addr,
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,
338 @@ -1411,7 +1240,7 @@ static int
339 wpa_driver_hostap_associate(void *priv,
340 struct wpa_driver_associate_params *params)
342 - struct wpa_driver_hostap_data *drv = priv;
343 + struct hostap_driver_data *drv = priv;
345 int allow_unencrypted_eapol;
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)
351 - struct wpa_driver_hostap_data *drv = priv;
352 + struct hostap_driver_data *drv = priv;
353 struct prism2_hostapd_param param;
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, ¶m, sizeof(param), 1);
361 + ret = wpa_hostapd_ioctl(drv, ¶m, sizeof(param), 1);
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 *
367 static int wpa_driver_hostap_set_auth_alg(void *priv, int auth_alg)
369 - struct wpa_driver_hostap_data *drv = priv;
370 + struct hostap_driver_data *drv = priv;
373 if (auth_alg & WPA_AUTH_ALG_OPEN)
374 @@ -1529,35 +1358,35 @@ static int wpa_driver_hostap_set_auth_al
376 static int wpa_driver_hostap_get_bssid(void *priv, u8 *bssid)
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);
384 static int wpa_driver_hostap_get_ssid(void *priv, u8 *ssid)
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);
392 static struct wpa_scan_results * wpa_driver_hostap_get_scan_results(void *priv)
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);
400 static int wpa_driver_hostap_set_operstate(void *priv, int state)
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);
408 static void * wpa_driver_hostap_init(void *ctx, const char *ifname)
410 - struct wpa_driver_hostap_data *drv;
411 + struct hostap_driver_data *drv;
413 drv = os_zalloc(sizeof(*drv));
415 @@ -1597,14 +1426,120 @@ static void * wpa_driver_hostap_init(voi
417 static void wpa_driver_hostap_deinit(void *priv)
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);
427 -#endif /* HOSTAPD */
431 +static void show_set_key_error(struct prism2_hostapd_param *param)
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 "
442 + case HOSTAP_CRYPT_ERR_UNKNOWN_ADDR:
443 + wpa_printf(MSG_INFO, "Unknown address " MACSTR ".",
444 + MAC2STR(param->sta_addr));
446 + case HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED:
447 + wpa_printf(MSG_INFO, "Crypt algorithm initialization failed.");
449 + case HOSTAP_CRYPT_ERR_KEY_SET_FAILED:
450 + wpa_printf(MSG_INFO, "Key setting failed.");
452 + case HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED:
453 + wpa_printf(MSG_INFO, "TX key index setting failed.");
455 + case HOSTAP_CRYPT_ERR_CARD_CONF_FAILED:
456 + wpa_printf(MSG_INFO, "Card configuration failed.");
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)
468 + struct hostap_driver_data *drv = priv;
469 + struct prism2_hostapd_param *param;
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);
499 + blen = sizeof(*param) + key_len;
500 + buf = os_zalloc(blen);
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. */
514 + os_memset(param->sta_addr, 0xff, ETH_ALEN);
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;
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);
526 + if (wpa_hostapd_ioctl(drv, param, blen, 1)) {
527 + wpa_printf(MSG_WARNING, "Failed to set encryption.");
528 + show_set_key_error(param);
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,
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 */