[package] hostapd: Fix hostap driver for multicall binary builds
[openwrt/svn-archive/archive.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 @@ -399,65 +404,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 @@ -1125,21 +1071,14 @@ 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 +#endif /* HOSTAPD */
123
124 +#if !defined(NO_SUPPLICANT)
125
126 static int wpa_driver_hostap_set_auth_alg(void *priv, int auth_alg);
127
128
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)
133 {
134 @@ -1161,7 +1100,7 @@ static int hostapd_ioctl(struct wpa_driv
135 }
136
137
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)
141 {
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);
149
150 os_free(param);
151
152 @@ -1185,7 +1124,7 @@ static int wpa_driver_hostap_set_wpa_ie(
153 }
154
155
156 -static int prism2param(struct wpa_driver_hostap_data *drv, int param,
157 +static int prism2param(struct hostap_driver_data *drv, int param,
158 int value)
159 {
160 struct iwreq iwr;
161 @@ -1207,7 +1146,7 @@ static int prism2param(struct wpa_driver
162
163 static int wpa_driver_hostap_set_wpa(void *priv, int enabled)
164 {
165 - struct wpa_driver_hostap_data *drv = priv;
166 + struct hostap_driver_data *drv = priv;
167 int ret = 0;
168
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)
173 {
174 - struct wpa_driver_hostap_data *drv = priv;
175 + struct hostap_driver_data *drv = priv;
176 struct prism2_hostapd_param *param;
177 u8 *buf;
178 size_t blen;
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. */
183 -#if 0
184 if (addr == NULL)
185 os_memset(param->sta_addr, 0xff, ETH_ALEN);
186 else
187 os_memcpy(param->sta_addr, addr, ETH_ALEN);
188 -#else
189 - os_memset(param->sta_addr, 0xff, ETH_ALEN);
190 -#endif
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);
197
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);
202 ret = -1;
203 @@ -1335,13 +1270,13 @@ static int wpa_driver_hostap_set_key(con
204
205 static int wpa_driver_hostap_set_countermeasures(void *priv, int enabled)
206 {
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);
211 }
212
213
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,
216 int type)
217 {
218 struct iwreq iwr;
219 @@ -1362,7 +1297,7 @@ static int wpa_driver_hostap_reset(struc
220 }
221
222
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)
226 {
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, &param, sizeof(param), 1);
233 + ret = wpa_hostapd_ioctl(drv, &param, sizeof(param), 1);
234 if (ret == 0) {
235 os_sleep(0, 100000);
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,
239 int reason_code)
240 {
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,
245 reason_code);
246 @@ -1399,7 +1334,7 @@ static int wpa_driver_hostap_deauthentic
247 static int wpa_driver_hostap_disassociate(void *priv, const u8 *addr,
248 int reason_code)
249 {
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,
254 reason_code);
255 @@ -1410,7 +1345,7 @@ static int
256 wpa_driver_hostap_associate(void *priv,
257 struct wpa_driver_associate_params *params)
258 {
259 - struct wpa_driver_hostap_data *drv = priv;
260 + struct hostap_driver_data *drv = priv;
261 int ret = 0;
262 int allow_unencrypted_eapol;
263
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)
267 {
268 - struct wpa_driver_hostap_data *drv = priv;
269 + struct hostap_driver_data *drv = priv;
270 struct prism2_hostapd_param param;
271 int ret;
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, &param, sizeof(param), 1);
278 + ret = wpa_hostapd_ioctl(drv, &param, sizeof(param), 1);
279
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 *
283
284 static int wpa_driver_hostap_set_auth_alg(void *priv, int auth_alg)
285 {
286 - struct wpa_driver_hostap_data *drv = priv;
287 + struct hostap_driver_data *drv = priv;
288 int algs = 0;
289
290 if (auth_alg & WPA_AUTH_ALG_OPEN)
291 @@ -1528,35 +1463,35 @@ static int wpa_driver_hostap_set_auth_al
292
293 static int wpa_driver_hostap_get_bssid(void *priv, u8 *bssid)
294 {
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);
298 }
299
300
301 static int wpa_driver_hostap_get_ssid(void *priv, u8 *ssid)
302 {
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);
306 }
307
308
309 static struct wpa_scan_results * wpa_driver_hostap_get_scan_results(void *priv)
310 {
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);
314 }
315
316
317 static int wpa_driver_hostap_set_operstate(void *priv, int state)
318 {
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);
322 }
323
324
325 static void * wpa_driver_hostap_init(void *ctx, const char *ifname)
326 {
327 - struct wpa_driver_hostap_data *drv;
328 + struct hostap_driver_data *drv;
329
330 drv = os_zalloc(sizeof(*drv));
331 if (drv == NULL)
332 @@ -1596,14 +1531,14 @@ static void * wpa_driver_hostap_init(voi
333
334 static void wpa_driver_hostap_deinit(void *priv)
335 {
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);
340 close(drv->sock);
341 os_free(drv);
342 }
343
344 -#endif /* HOSTAPD */
345 +#endif
346
347
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,
353 -#else /* HOSTAPD */
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 */
364 +#endif
365 };