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 @@ -399,65 +404,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 @@ -1125,21 +1071,14 @@ 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 */
122 +#endif /* HOSTAPD */
124 +#if !defined(NO_SUPPLICANT)
126 static int wpa_driver_hostap_set_auth_alg(void *priv, int auth_alg);
129 -static int hostapd_ioctl(struct wpa_driver_hostap_data *drv,
130 +static int wpa_hostapd_ioctl(struct hostap_driver_data *drv,
131 struct prism2_hostapd_param *param,
132 int len, int show_err)
134 @@ -1161,7 +1100,7 @@ static int hostapd_ioctl(struct wpa_driv
138 -static int wpa_driver_hostap_set_wpa_ie(struct wpa_driver_hostap_data *drv,
139 +static int wpa_driver_hostap_set_wpa_ie(struct hostap_driver_data *drv,
140 const u8 *wpa_ie, size_t wpa_ie_len)
142 struct prism2_hostapd_param *param;
143 @@ -1177,7 +1116,7 @@ static int wpa_driver_hostap_set_wpa_ie(
144 param->cmd = PRISM2_HOSTAPD_SET_GENERIC_ELEMENT;
145 param->u.generic_elem.len = wpa_ie_len;
146 os_memcpy(param->u.generic_elem.data, wpa_ie, wpa_ie_len);
147 - res = hostapd_ioctl(drv, param, blen, 1);
148 + res = wpa_hostapd_ioctl(drv, param, blen, 1);
152 @@ -1185,7 +1124,7 @@ static int wpa_driver_hostap_set_wpa_ie(
156 -static int prism2param(struct wpa_driver_hostap_data *drv, int param,
157 +static int prism2param(struct hostap_driver_data *drv, int param,
161 @@ -1207,7 +1146,7 @@ static int prism2param(struct wpa_driver
163 static int wpa_driver_hostap_set_wpa(void *priv, int enabled)
165 - struct wpa_driver_hostap_data *drv = priv;
166 + struct hostap_driver_data *drv = priv;
169 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
170 @@ -1260,7 +1199,7 @@ static int wpa_driver_hostap_set_key(con
171 const u8 *seq, size_t seq_len,
172 const u8 *key, size_t key_len)
174 - struct wpa_driver_hostap_data *drv = priv;
175 + struct hostap_driver_data *drv = priv;
176 struct prism2_hostapd_param *param;
179 @@ -1305,14 +1244,10 @@ static int wpa_driver_hostap_set_key(con
180 * use keyidx 1..3 (i.e., default key with keyidx 0 is not supported).
181 * This should be fine for more or less all cases, but for completeness
182 * sake, the driver could be enhanced to support the missing key. */
185 os_memset(param->sta_addr, 0xff, ETH_ALEN);
187 os_memcpy(param->sta_addr, addr, ETH_ALEN);
189 - os_memset(param->sta_addr, 0xff, ETH_ALEN);
191 os_strlcpy((char *) param->u.crypt.alg, alg_name,
192 HOSTAP_CRYPT_ALG_NAME_LEN);
193 param->u.crypt.flags = set_tx ? HOSTAP_CRYPT_FLAG_SET_TX_KEY : 0;
194 @@ -1322,7 +1257,7 @@ static int wpa_driver_hostap_set_key(con
195 param->u.crypt.key_len = key_len;
196 os_memcpy((u8 *) (param + 1), key, key_len);
198 - if (hostapd_ioctl(drv, param, blen, 1)) {
199 + if (wpa_hostapd_ioctl(drv, param, blen, 1)) {
200 wpa_printf(MSG_WARNING, "Failed to set encryption.");
201 show_set_key_error(param);
203 @@ -1335,13 +1270,13 @@ static int wpa_driver_hostap_set_key(con
205 static int wpa_driver_hostap_set_countermeasures(void *priv, int enabled)
207 - struct wpa_driver_hostap_data *drv = priv;
208 + struct hostap_driver_data *drv = priv;
209 wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
210 return prism2param(drv, PRISM2_PARAM_TKIP_COUNTERMEASURES, enabled);
214 -static int wpa_driver_hostap_reset(struct wpa_driver_hostap_data *drv,
215 +static int wpa_driver_hostap_reset(struct hostap_driver_data *drv,
219 @@ -1362,7 +1297,7 @@ static int wpa_driver_hostap_reset(struc
223 -static int wpa_driver_hostap_mlme(struct wpa_driver_hostap_data *drv,
224 +static int wpa_driver_hostap_mlme(struct hostap_driver_data *drv,
225 const u8 *addr, int cmd, int reason_code)
227 struct prism2_hostapd_param param;
228 @@ -1377,7 +1312,7 @@ static int wpa_driver_hostap_mlme(struct
229 os_memcpy(param.sta_addr, addr, ETH_ALEN);
230 param.u.mlme.cmd = cmd;
231 param.u.mlme.reason_code = reason_code;
232 - ret = hostapd_ioctl(drv, ¶m, sizeof(param), 1);
233 + ret = wpa_hostapd_ioctl(drv, ¶m, sizeof(param), 1);
236 ret = wpa_driver_hostap_reset(drv, 2);
237 @@ -1389,7 +1324,7 @@ static int wpa_driver_hostap_mlme(struct
238 static int wpa_driver_hostap_deauthenticate(void *priv, const u8 *addr,
241 - struct wpa_driver_hostap_data *drv = priv;
242 + struct hostap_driver_data *drv = priv;
243 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
244 return wpa_driver_hostap_mlme(drv, addr, MLME_STA_DEAUTH,
246 @@ -1399,7 +1334,7 @@ static int wpa_driver_hostap_deauthentic
247 static int wpa_driver_hostap_disassociate(void *priv, const u8 *addr,
250 - struct wpa_driver_hostap_data *drv = priv;
251 + struct hostap_driver_data *drv = priv;
252 wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
253 return wpa_driver_hostap_mlme(drv, addr, MLME_STA_DISASSOC,
255 @@ -1410,7 +1345,7 @@ static int
256 wpa_driver_hostap_associate(void *priv,
257 struct wpa_driver_associate_params *params)
259 - struct wpa_driver_hostap_data *drv = priv;
260 + struct hostap_driver_data *drv = priv;
262 int allow_unencrypted_eapol;
264 @@ -1474,7 +1409,7 @@ wpa_driver_hostap_associate(void *priv,
265 static int wpa_driver_hostap_scan(void *priv,
266 struct wpa_driver_scan_params *params)
268 - struct wpa_driver_hostap_data *drv = priv;
269 + struct hostap_driver_data *drv = priv;
270 struct prism2_hostapd_param param;
272 const u8 *ssid = params->ssids[0].ssid;
273 @@ -1495,7 +1430,7 @@ static int wpa_driver_hostap_scan(void *
274 param.cmd = PRISM2_HOSTAPD_SCAN_REQ;
275 param.u.scan_req.ssid_len = ssid_len;
276 os_memcpy(param.u.scan_req.ssid, ssid, ssid_len);
277 - ret = hostapd_ioctl(drv, ¶m, sizeof(param), 1);
278 + ret = wpa_hostapd_ioctl(drv, ¶m, sizeof(param), 1);
280 /* Not all drivers generate "scan completed" wireless event, so try to
281 * read results after a timeout. */
282 @@ -1510,7 +1445,7 @@ static int wpa_driver_hostap_scan(void *
284 static int wpa_driver_hostap_set_auth_alg(void *priv, int auth_alg)
286 - struct wpa_driver_hostap_data *drv = priv;
287 + struct hostap_driver_data *drv = priv;
290 if (auth_alg & WPA_AUTH_ALG_OPEN)
291 @@ -1528,35 +1463,35 @@ static int wpa_driver_hostap_set_auth_al
293 static int wpa_driver_hostap_get_bssid(void *priv, u8 *bssid)
295 - struct wpa_driver_hostap_data *drv = priv;
296 + struct hostap_driver_data *drv = priv;
297 return wpa_driver_wext_get_bssid(drv->wext, bssid);
301 static int wpa_driver_hostap_get_ssid(void *priv, u8 *ssid)
303 - struct wpa_driver_hostap_data *drv = priv;
304 + struct hostap_driver_data *drv = priv;
305 return wpa_driver_wext_get_ssid(drv->wext, ssid);
309 static struct wpa_scan_results * wpa_driver_hostap_get_scan_results(void *priv)
311 - struct wpa_driver_hostap_data *drv = priv;
312 + struct hostap_driver_data *drv = priv;
313 return wpa_driver_wext_get_scan_results(drv->wext);
317 static int wpa_driver_hostap_set_operstate(void *priv, int state)
319 - struct wpa_driver_hostap_data *drv = priv;
320 + struct hostap_driver_data *drv = priv;
321 return wpa_driver_wext_set_operstate(drv->wext, state);
325 static void * wpa_driver_hostap_init(void *ctx, const char *ifname)
327 - struct wpa_driver_hostap_data *drv;
328 + struct hostap_driver_data *drv;
330 drv = os_zalloc(sizeof(*drv));
332 @@ -1596,14 +1531,14 @@ static void * wpa_driver_hostap_init(voi
334 static void wpa_driver_hostap_deinit(void *priv)
336 - struct wpa_driver_hostap_data *drv = priv;
337 + struct hostap_driver_data *drv = priv;
338 wpa_driver_hostap_set_wpa(drv, 0);
339 wpa_driver_wext_deinit(drv->wext);
344 -#endif /* HOSTAPD */
348 const struct wpa_driver_ops wpa_driver_hostap_ops = {
349 @@ -1631,7 +1566,8 @@ const struct wpa_driver_ops wpa_driver_h
350 .sta_clear_stats = hostap_sta_clear_stats,
351 .get_hw_feature_data = hostap_get_hw_feature_data,
352 .set_ap_wps_ie = hostap_set_ap_wps_ie,
354 +#endif /* HOSTAPD */
355 +#if !defined(NO_SUPPLICANT)
356 .get_bssid = wpa_driver_hostap_get_bssid,
357 .get_ssid = wpa_driver_hostap_get_ssid,
358 .set_countermeasures = wpa_driver_hostap_set_countermeasures,
359 @@ -1643,5 +1579,5 @@ const struct wpa_driver_ops wpa_driver_h
360 .init = wpa_driver_hostap_init,
361 .deinit = wpa_driver_hostap_deinit,
362 .set_operstate = wpa_driver_hostap_set_operstate,
363 -#endif /* HOSTAPD */