]> git.ipfire.org Git - thirdparty/hostap.git/blobdiff - src/drivers/driver_wext.c
Get rid of duplicated cipher suite and AKM definitions
[thirdparty/hostap.git] / src / drivers / driver_wext.c
index 7c383f3f13c4d6e519d857f34fcc95ebee92c2e2..e5734bddc34a82d6b93bb30a1b0fd80e143ad293 100644 (file)
@@ -2,14 +2,8 @@
  * Driver interaction with generic Linux Wireless Extensions
  * Copyright (c) 2003-2010, Jouni Malinen <j@w1.fi>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
  *
  * This file implements a driver interface for the Linux Wireless Extensions.
  * When used with WE-18 or newer, this interface can be used as-is with number
@@ -25,7 +19,7 @@
 #include <fcntl.h>
 #include <net/if_arp.h>
 
-#include "wireless_copy.h"
+#include "linux_wext.h"
 #include "common.h"
 #include "eloop.h"
 #include "common/ieee802_11_defs.h"
@@ -37,7 +31,6 @@
 #include "driver.h"
 #include "driver_wext.h"
 
-
 static int wpa_driver_wext_flush_pmkid(void *priv);
 static int wpa_driver_wext_get_range(void *priv);
 static int wpa_driver_wext_finish_drv_init(struct wpa_driver_wext_data *drv);
@@ -497,11 +490,9 @@ static void wpa_driver_wext_event_wireless(struct wpa_driver_wext_data *drv,
                                           "IWEVCUSTOM length");
                                return;
                        }
-                       buf = os_malloc(iwe->u.data.length + 1);
+                       buf = dup_binstr(custom, iwe->u.data.length);
                        if (buf == NULL)
                                return;
-                       os_memcpy(buf, custom, iwe->u.data.length);
-                       buf[iwe->u.data.length] = '\0';
                        wpa_driver_wext_event_wireless_custom(drv->ctx, buf);
                        os_free(buf);
                        break;
@@ -564,10 +555,28 @@ static void wpa_driver_wext_event_link(struct wpa_driver_wext_data *drv,
                   del ? "removed" : "added");
 
        if (os_strcmp(drv->ifname, event.interface_status.ifname) == 0) {
-               if (del)
+               if (del) {
+                       if (drv->if_removed) {
+                               wpa_printf(MSG_DEBUG, "WEXT: if_removed "
+                                          "already set - ignore event");
+                               return;
+                       }
                        drv->if_removed = 1;
-               else
+               } else {
+                       if (if_nametoindex(drv->ifname) == 0) {
+                               wpa_printf(MSG_DEBUG, "WEXT: Interface %s "
+                                          "does not exist - ignore "
+                                          "RTM_NEWLINK",
+                                          drv->ifname);
+                               return;
+                       }
+                       if (!drv->if_removed) {
+                               wpa_printf(MSG_DEBUG, "WEXT: if_removed "
+                                          "already cleared - ignore event");
+                               return;
+                       }
                        drv->if_removed = 0;
+               }
        }
 
        wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
@@ -623,6 +632,7 @@ static void wpa_driver_wext_event_rtm_newlink(void *ctx, struct ifinfomsg *ifi,
        struct wpa_driver_wext_data *drv = ctx;
        int attrlen, rta_len;
        struct rtattr *attr;
+       char namebuf[IFNAMSIZ];
 
        if (!wpa_driver_wext_own_ifindex(drv, ifi->ifi_index, buf, len)) {
                wpa_printf(MSG_DEBUG, "Ignore event for foreign ifindex %d",
@@ -645,9 +655,25 @@ static void wpa_driver_wext_event_rtm_newlink(void *ctx, struct ifinfomsg *ifi,
        }
 
        if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) {
-               wpa_printf(MSG_DEBUG, "WEXT: Interface up");
-               drv->if_disabled = 0;
-               wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL);
+               if (if_indextoname(ifi->ifi_index, namebuf) &&
+                   linux_iface_up(drv->ioctl_sock, drv->ifname) == 0) {
+                       wpa_printf(MSG_DEBUG, "WEXT: Ignore interface up "
+                                  "event since interface %s is down",
+                                  namebuf);
+               } else if (if_nametoindex(drv->ifname) == 0) {
+                       wpa_printf(MSG_DEBUG, "WEXT: Ignore interface up "
+                                  "event since interface %s does not exist",
+                                  drv->ifname);
+               } else if (drv->if_removed) {
+                       wpa_printf(MSG_DEBUG, "WEXT: Ignore interface up "
+                                  "event since interface %s is marked "
+                                  "removed", drv->ifname);
+               } else {
+                       wpa_printf(MSG_DEBUG, "WEXT: Interface up");
+                       drv->if_disabled = 0;
+                       wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED,
+                                            NULL);
+               }
        }
 
        /*
@@ -1368,8 +1394,8 @@ static void wpa_driver_wext_add_scan_entry(struct wpa_scan_results *res,
        if (data->ie)
                os_memcpy(pos, data->ie, data->ie_len);
 
-       tmp = os_realloc(res->res,
-                        (res->num + 1) * sizeof(struct wpa_scan_res *));
+       tmp = os_realloc_array(res->res, res->num + 1,
+                              sizeof(struct wpa_scan_res *));
        if (tmp == NULL) {
                os_free(r);
                return;
@@ -1529,6 +1555,7 @@ static int wpa_driver_wext_get_range(void *priv)
                }
                drv->capa.enc |= WPA_DRIVER_CAPA_ENC_WEP40 |
                        WPA_DRIVER_CAPA_ENC_WEP104;
+               drv->capa.enc |= WPA_DRIVER_CAPA_ENC_WEP128;
                if (range->enc_capa & IW_ENC_CAPA_CIPHER_TKIP)
                        drv->capa.enc |= WPA_DRIVER_CAPA_ENC_TKIP;
                if (range->enc_capa & IW_ENC_CAPA_CIPHER_CCMP)
@@ -1824,10 +1851,8 @@ static void wpa_driver_wext_disconnect(struct wpa_driver_wext_data *drv)
 {
        struct iwreq iwr;
        const u8 null_bssid[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
-#ifndef ANDROID
        u8 ssid[32];
        int i;
-#endif /* ANDROID */
 
        /*
         * Only force-disconnect when the card is in infrastructure mode,
@@ -1848,7 +1873,6 @@ static void wpa_driver_wext_disconnect(struct wpa_driver_wext_data *drv)
                                   "selection on disconnect");
                }
 
-#ifndef ANDROID
                if (drv->cfg80211) {
                        /*
                         * cfg80211 supports SIOCSIWMLME commands, so there is
@@ -1874,7 +1898,6 @@ static void wpa_driver_wext_disconnect(struct wpa_driver_wext_data *drv)
                        wpa_printf(MSG_DEBUG, "WEXT: Failed to set bogus "
                                   "SSID to disconnect");
                }
-#endif /* ANDROID */
        }
 }
 
@@ -1891,18 +1914,6 @@ static int wpa_driver_wext_deauthenticate(void *priv, const u8 *addr,
 }
 
 
-static int wpa_driver_wext_disassociate(void *priv, const u8 *addr,
-                                       int reason_code)
-{
-       struct wpa_driver_wext_data *drv = priv;
-       int ret;
-       wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
-       ret = wpa_driver_wext_mlme(drv, addr, IW_MLME_DISASSOC, reason_code);
-       wpa_driver_wext_disconnect(drv);
-       return ret;
-}
-
-
 static int wpa_driver_wext_set_gen_ie(void *priv, const u8 *ie,
                                      size_t ie_len)
 {
@@ -1927,15 +1938,15 @@ static int wpa_driver_wext_set_gen_ie(void *priv, const u8 *ie,
 int wpa_driver_wext_cipher2wext(int cipher)
 {
        switch (cipher) {
-       case CIPHER_NONE:
+       case WPA_CIPHER_NONE:
                return IW_AUTH_CIPHER_NONE;
-       case CIPHER_WEP40:
+       case WPA_CIPHER_WEP40:
                return IW_AUTH_CIPHER_WEP40;
-       case CIPHER_TKIP:
+       case WPA_CIPHER_TKIP:
                return IW_AUTH_CIPHER_TKIP;
-       case CIPHER_CCMP:
+       case WPA_CIPHER_CCMP:
                return IW_AUTH_CIPHER_CCMP;
-       case CIPHER_WEP104:
+       case WPA_CIPHER_WEP104:
                return IW_AUTH_CIPHER_WEP104;
        default:
                return 0;
@@ -1946,10 +1957,10 @@ int wpa_driver_wext_cipher2wext(int cipher)
 int wpa_driver_wext_keymgmt2wext(int keymgmt)
 {
        switch (keymgmt) {
-       case KEY_MGMT_802_1X:
-       case KEY_MGMT_802_1X_NO_WPA:
+       case WPA_KEY_MGMT_IEEE8021X:
+       case WPA_KEY_MGMT_IEEE8021X_NO_WPA:
                return IW_AUTH_KEY_MGMT_802_1X;
-       case KEY_MGMT_PSK:
+       case WPA_KEY_MGMT_PSK:
                return IW_AUTH_KEY_MGMT_PSK;
        default:
                return 0;
@@ -2066,9 +2077,9 @@ int wpa_driver_wext_associate(void *priv,
        if (wpa_driver_wext_set_auth_param(drv,
                                           IW_AUTH_KEY_MGMT, value) < 0)
                ret = -1;
-       value = params->key_mgmt_suite != KEY_MGMT_NONE ||
-               params->pairwise_suite != CIPHER_NONE ||
-               params->group_suite != CIPHER_NONE ||
+       value = params->key_mgmt_suite != WPA_KEY_MGMT_NONE ||
+               params->pairwise_suite != WPA_CIPHER_NONE ||
+               params->group_suite != WPA_CIPHER_NONE ||
                params->wpa_ie_len;
        if (wpa_driver_wext_set_auth_param(drv,
                                           IW_AUTH_PRIVACY_INVOKED, value) < 0)
@@ -2077,8 +2088,8 @@ int wpa_driver_wext_associate(void *priv,
        /* Allow unencrypted EAPOL messages even if pairwise keys are set when
         * not using WPA. IEEE 802.1X specifies that these frames are not
         * encrypted, but WPA encrypts them when pairwise keys are in use. */
-       if (params->key_mgmt_suite == KEY_MGMT_802_1X ||
-           params->key_mgmt_suite == KEY_MGMT_PSK)
+       if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
+           params->key_mgmt_suite == WPA_KEY_MGMT_PSK)
                allow_unencrypted_eapol = 0;
        else
                allow_unencrypted_eapol = 1;
@@ -2315,7 +2326,6 @@ const struct wpa_driver_ops wpa_driver_wext_ops = {
        .scan2 = wpa_driver_wext_scan,
        .get_scan_results2 = wpa_driver_wext_get_scan_results,
        .deauthenticate = wpa_driver_wext_deauthenticate,
-       .disassociate = wpa_driver_wext_disassociate,
        .associate = wpa_driver_wext_associate,
        .init = wpa_driver_wext_init,
        .deinit = wpa_driver_wext_deinit,