2 * WPA Supplicant - driver interaction with Linux ipw2100/2200 drivers
3 * Copyright (c) 2005 Zhu Yi <yi.zhu@intel.com>
4 * Copyright (c) 2004 Lubomir Gelo <lgelo@cnc.sk>
5 * Copyright (c) 2003-2004, Jouni Malinen <j@w1.fi>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * Alternatively, this software may be distributed under the terms of BSD
14 * See README and COPYING for more details.
16 * Please note that ipw2100/2200 drivers change to use generic Linux wireless
17 * extensions if the kernel includes support for WE-18 or newer (Linux 2.6.13
18 * or newer). driver_wext.c should be used in those cases.
22 #include <sys/ioctl.h>
24 #include "wireless_copy.h"
27 #include "driver_wext.h"
29 struct wpa_driver_ipw_data
{
30 void *wext
; /* private data for driver_wext */
32 char ifname
[IFNAMSIZ
+ 1];
36 /* following definitions must be kept in sync with ipw2100.c and ipw2200.c */
38 #define IPW_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
40 #define IPW_CMD_SET_WPA_PARAM 1
41 #define IPW_CMD_SET_WPA_IE 2
42 #define IPW_CMD_SET_ENCRYPTION 3
43 #define IPW_CMD_MLME 4
45 #define IPW_PARAM_WPA_ENABLED 1
46 #define IPW_PARAM_TKIP_COUNTERMEASURES 2
47 #define IPW_PARAM_DROP_UNENCRYPTED 3
48 #define IPW_PARAM_PRIVACY_INVOKED 4
49 #define IPW_PARAM_AUTH_ALGS 5
50 #define IPW_PARAM_IEEE_802_1X 6
52 #define IPW_MLME_STA_DEAUTH 1
53 #define IPW_MLME_STA_DISASSOC 2
55 #define IPW_CRYPT_ERR_UNKNOWN_ALG 2
56 #define IPW_CRYPT_ERR_UNKNOWN_ADDR 3
57 #define IPW_CRYPT_ERR_CRYPT_INIT_FAILED 4
58 #define IPW_CRYPT_ERR_KEY_SET_FAILED 5
59 #define IPW_CRYPT_ERR_TX_KEY_SET_FAILED 6
60 #define IPW_CRYPT_ERR_CARD_CONF_FAILED 7
62 #define IPW_CRYPT_ALG_NAME_LEN 16
66 u8 sta_addr
[ETH_ALEN
];
82 u8 alg
[IPW_CRYPT_ALG_NAME_LEN
];
94 /* end of ipw2100.c and ipw2200.c code */
96 static int wpa_driver_ipw_set_auth_alg(void *priv
, int auth_alg
);
98 static int ipw_ioctl(struct wpa_driver_ipw_data
*drv
,
99 struct ipw_param
*param
, int len
, int show_err
)
103 os_memset(&iwr
, 0, sizeof(iwr
));
104 os_strlcpy(iwr
.ifr_name
, drv
->ifname
, IFNAMSIZ
);
105 iwr
.u
.data
.pointer
= (caddr_t
) param
;
106 iwr
.u
.data
.length
= len
;
108 if (ioctl(drv
->sock
, IPW_IOCTL_WPA_SUPPLICANT
, &iwr
) < 0) {
111 perror("ioctl[IPW_IOCTL_WPA_SUPPLICANT]");
119 static void ipw_show_set_key_error(struct ipw_param
*param
)
121 switch (param
->u
.crypt
.err
) {
122 case IPW_CRYPT_ERR_UNKNOWN_ALG
:
123 wpa_printf(MSG_INFO
, "Unknown algorithm '%s'.",
125 wpa_printf(MSG_INFO
, "You may need to load kernel module to "
126 "register that algorithm.");
127 wpa_printf(MSG_INFO
, "E.g., 'modprobe ieee80211_crypt_wep' for"
130 case IPW_CRYPT_ERR_UNKNOWN_ADDR
:
131 wpa_printf(MSG_INFO
, "Unknown address " MACSTR
".",
132 MAC2STR(param
->sta_addr
));
134 case IPW_CRYPT_ERR_CRYPT_INIT_FAILED
:
135 wpa_printf(MSG_INFO
, "Crypt algorithm initialization failed.");
137 case IPW_CRYPT_ERR_KEY_SET_FAILED
:
138 wpa_printf(MSG_INFO
, "Key setting failed.");
140 case IPW_CRYPT_ERR_TX_KEY_SET_FAILED
:
141 wpa_printf(MSG_INFO
, "TX key index setting failed.");
143 case IPW_CRYPT_ERR_CARD_CONF_FAILED
:
144 wpa_printf(MSG_INFO
, "Card configuration failed.");
150 static int ipw_set_wpa_ie(struct wpa_driver_ipw_data
*drv
,
151 const u8
*wpa_ie
, size_t wpa_ie_len
)
153 struct ipw_param
*param
;
155 size_t blen
= sizeof(*param
) + wpa_ie_len
;
157 param
= os_zalloc(blen
);
161 param
->cmd
= IPW_CMD_SET_WPA_IE
;
162 param
->u
.wpa_ie
.len
= wpa_ie_len
;
163 os_memcpy(param
->u
.wpa_ie
.data
, wpa_ie
, wpa_ie_len
);
165 ret
= ipw_ioctl(drv
, param
, blen
, 1);
172 static int ipw_set_wpa_param(struct wpa_driver_ipw_data
*drv
, u8 name
,
175 struct ipw_param param
;
177 os_memset(¶m
, 0, sizeof(param
));
178 param
.cmd
= IPW_CMD_SET_WPA_PARAM
;
179 param
.u
.wpa_param
.name
= name
;
180 param
.u
.wpa_param
.value
= value
;
182 return ipw_ioctl(drv
, ¶m
, sizeof(param
), 1);
186 static int ipw_mlme(struct wpa_driver_ipw_data
*drv
, const u8
*addr
,
189 struct ipw_param param
;
191 os_memset(¶m
, 0, sizeof(param
));
192 os_memcpy(param
.sta_addr
, addr
, ETH_ALEN
);
193 param
.cmd
= IPW_CMD_MLME
;
194 param
.u
.mlme
.command
= cmd
;
195 param
.u
.mlme
.reason_code
= reason
;
197 return ipw_ioctl(drv
, ¶m
, sizeof(param
), 1);
201 static int wpa_driver_ipw_set_wpa(void *priv
, int enabled
)
203 struct wpa_driver_ipw_data
*drv
= priv
;
206 wpa_printf(MSG_DEBUG
, "%s: enabled=%d", __FUNCTION__
, enabled
);
208 if (!enabled
&& ipw_set_wpa_ie(drv
, NULL
, 0) < 0)
211 if (ipw_set_wpa_param(drv
, IPW_PARAM_WPA_ENABLED
, enabled
) < 0)
218 static int wpa_driver_ipw_set_key(const char *ifname
, void *priv
,
219 enum wpa_alg alg
, const u8
*addr
,
220 int key_idx
, int set_tx
,
221 const u8
*seq
, size_t seq_len
,
222 const u8
*key
, size_t key_len
)
224 struct wpa_driver_ipw_data
*drv
= priv
;
225 struct ipw_param
*param
;
248 wpa_printf(MSG_DEBUG
, "%s: alg=%s key_idx=%d set_tx=%d seq_len=%lu "
249 "key_len=%lu", __FUNCTION__
, alg_name
, key_idx
, set_tx
,
250 (unsigned long) seq_len
, (unsigned long) key_len
);
255 blen
= sizeof(*param
) + key_len
;
256 buf
= os_zalloc(blen
);
260 param
= (struct ipw_param
*) buf
;
261 param
->cmd
= IPW_CMD_SET_ENCRYPTION
;
262 os_memset(param
->sta_addr
, 0xff, ETH_ALEN
);
263 os_strlcpy((char *) param
->u
.crypt
.alg
, alg_name
,
264 IPW_CRYPT_ALG_NAME_LEN
);
265 param
->u
.crypt
.set_tx
= set_tx
? 1 : 0;
266 param
->u
.crypt
.idx
= key_idx
;
267 os_memcpy(param
->u
.crypt
.seq
, seq
, seq_len
);
268 param
->u
.crypt
.key_len
= key_len
;
269 os_memcpy((u8
*) (param
+ 1), key
, key_len
);
271 if (ipw_ioctl(drv
, param
, blen
, 1)) {
272 wpa_printf(MSG_WARNING
, "Failed to set encryption.");
273 ipw_show_set_key_error(param
);
282 static int wpa_driver_ipw_set_countermeasures(void *priv
, int enabled
)
284 struct wpa_driver_ipw_data
*drv
= priv
;
285 wpa_printf(MSG_DEBUG
, "%s: enabled=%d", __FUNCTION__
, enabled
);
286 return ipw_set_wpa_param(drv
, IPW_PARAM_TKIP_COUNTERMEASURES
,
292 static int wpa_driver_ipw_set_drop_unencrypted(void *priv
, int enabled
)
294 struct wpa_driver_ipw_data
*drv
= priv
;
295 wpa_printf(MSG_DEBUG
, "%s: enabled=%d", __FUNCTION__
, enabled
);
296 return ipw_set_wpa_param(drv
, IPW_PARAM_DROP_UNENCRYPTED
,
301 static int wpa_driver_ipw_deauthenticate(void *priv
, const u8
*addr
,
304 struct wpa_driver_ipw_data
*drv
= priv
;
305 return ipw_mlme(drv
, addr
, IPW_MLME_STA_DEAUTH
, reason_code
);
309 static int wpa_driver_ipw_disassociate(void *priv
, const u8
*addr
,
312 struct wpa_driver_ipw_data
*drv
= priv
;
313 return ipw_mlme(drv
, addr
, IPW_MLME_STA_DISASSOC
, reason_code
);
318 wpa_driver_ipw_associate(void *priv
, struct wpa_driver_associate_params
*params
)
320 struct wpa_driver_ipw_data
*drv
= priv
;
322 int unencrypted_eapol
;
324 if (wpa_driver_ipw_set_auth_alg(drv
, params
->auth_alg
) < 0)
326 if (wpa_driver_ipw_set_drop_unencrypted(drv
, params
->drop_unencrypted
)
329 if (ipw_set_wpa_ie(drv
, params
->wpa_ie
, params
->wpa_ie_len
) < 0)
331 if (wpa_driver_wext_set_ssid(drv
->wext
, params
->ssid
,
332 params
->ssid_len
) < 0)
334 if (wpa_driver_wext_set_bssid(drv
->wext
, params
->bssid
) < 0)
337 if (params
->key_mgmt_suite
== KEY_MGMT_802_1X
||
338 params
->key_mgmt_suite
== KEY_MGMT_PSK
)
339 unencrypted_eapol
= 0;
341 unencrypted_eapol
= 1;
343 if (ipw_set_wpa_param(drv
, IPW_PARAM_IEEE_802_1X
,
344 unencrypted_eapol
) < 0) {
345 wpa_printf(MSG_DEBUG
, "ipw: Failed to configure "
346 "ieee_802_1x param");
353 static int wpa_driver_ipw_set_auth_alg(void *priv
, int auth_alg
)
355 struct wpa_driver_ipw_data
*drv
= priv
;
358 if (auth_alg
& WPA_AUTH_ALG_OPEN
)
360 if (auth_alg
& WPA_AUTH_ALG_SHARED
)
362 if (auth_alg
& WPA_AUTH_ALG_LEAP
)
365 algs
= 1; /* at least one algorithm should be set */
367 wpa_printf(MSG_DEBUG
, "%s: auth_alg=0x%x", __FUNCTION__
, algs
);
368 return ipw_set_wpa_param(drv
, IPW_PARAM_AUTH_ALGS
, algs
);
372 static int wpa_driver_ipw_get_bssid(void *priv
, u8
*bssid
)
374 struct wpa_driver_ipw_data
*drv
= priv
;
375 return wpa_driver_wext_get_bssid(drv
->wext
, bssid
);
379 static int wpa_driver_ipw_get_ssid(void *priv
, u8
*ssid
)
381 struct wpa_driver_ipw_data
*drv
= priv
;
382 return wpa_driver_wext_get_ssid(drv
->wext
, ssid
);
386 static int wpa_driver_ipw_scan(void *priv
,
387 struct wpa_driver_scan_params
*params
)
389 struct wpa_driver_ipw_data
*drv
= priv
;
390 return wpa_driver_wext_scan(drv
->wext
, params
);
394 static struct wpa_scan_results
* wpa_driver_ipw_get_scan_results(void *priv
)
396 struct wpa_driver_ipw_data
*drv
= priv
;
397 return wpa_driver_wext_get_scan_results(drv
->wext
);
401 static int wpa_driver_ipw_set_operstate(void *priv
, int state
)
403 struct wpa_driver_ipw_data
*drv
= priv
;
404 return wpa_driver_wext_set_operstate(drv
->wext
, state
);
408 static void * wpa_driver_ipw_init(void *ctx
, const char *ifname
)
410 struct wpa_driver_ipw_data
*drv
;
413 wpa_printf(MSG_DEBUG
, "%s is called", __FUNCTION__
);
414 drv
= os_zalloc(sizeof(*drv
));
417 drv
->wext
= wpa_driver_wext_init(ctx
, ifname
);
418 if (drv
->wext
== NULL
) {
423 ver
= wpa_driver_wext_get_version(drv
->wext
);
425 wpa_printf(MSG_WARNING
, "Linux wireless extensions version %d "
427 wpa_printf(MSG_WARNING
, "ipw2x00 driver uses driver_wext "
428 "(-Dwext) instead of driver_ipw.");
432 os_strlcpy(drv
->ifname
, ifname
, sizeof(drv
->ifname
));
433 drv
->sock
= socket(PF_INET
, SOCK_DGRAM
, 0);
435 wpa_driver_wext_deinit(drv
->wext
);
440 wpa_driver_ipw_set_wpa(drv
, 1);
446 static void wpa_driver_ipw_deinit(void *priv
)
448 struct wpa_driver_ipw_data
*drv
= priv
;
449 wpa_driver_ipw_set_wpa(drv
, 0);
450 wpa_driver_wext_deinit(drv
->wext
);
456 const struct wpa_driver_ops wpa_driver_ipw_ops
= {
458 .desc
= "Intel ipw2100/2200 driver (old; use wext with Linux 2.6.13 "
460 .get_bssid
= wpa_driver_ipw_get_bssid
,
461 .get_ssid
= wpa_driver_ipw_get_ssid
,
462 .set_key
= wpa_driver_ipw_set_key
,
463 .set_countermeasures
= wpa_driver_ipw_set_countermeasures
,
464 .scan2
= wpa_driver_ipw_scan
,
465 .get_scan_results2
= wpa_driver_ipw_get_scan_results
,
466 .deauthenticate
= wpa_driver_ipw_deauthenticate
,
467 .disassociate
= wpa_driver_ipw_disassociate
,
468 .associate
= wpa_driver_ipw_associate
,
469 .init
= wpa_driver_ipw_init
,
470 .deinit
= wpa_driver_ipw_deinit
,
471 .set_operstate
= wpa_driver_ipw_set_operstate
,