Detach ctrl_iface monitor if the client socket is removed
[wpasupplicant] / hostapd / ieee802_1x.c
index 350c542..3430f2d 100644 (file)
@@ -27,7 +27,7 @@
 #include "wpa.h"
 #include "preauth.h"
 #include "pmksa_cache.h"
-#include "driver.h"
+#include "driver_i.h"
 #include "hw_features.h"
 #include "eap_server/eap.h"
 #include "ieee802_11_defs.h"
@@ -185,6 +185,7 @@ static void ieee802_1x_tx_key_one(struct hostapd_data *hapd,
 }
 
 
+#ifndef CONFIG_NO_VLAN
 static struct hostapd_wep_keys *
 ieee802_1x_group_alloc(struct hostapd_data *hapd, const char *ifname)
 {
@@ -279,13 +280,16 @@ ieee802_1x_get_group(struct hostapd_data *hapd, struct hostapd_ssid *ssid,
 
        return ssid->dyn_vlan_keys[vlan_id];
 }
+#endif /* CONFIG_NO_VLAN */
 
 
 void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
 {
-       struct hostapd_wep_keys *key = NULL;
        struct eapol_state_machine *sm = sta->eapol_sm;
+#ifndef CONFIG_NO_VLAN
+       struct hostapd_wep_keys *key = NULL;
        int vlan_id;
+#endif /* CONFIG_NO_VLAN */
 
        if (sm == NULL || !sm->eap_if->eapKeyData)
                return;
@@ -293,6 +297,7 @@ void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
        wpa_printf(MSG_DEBUG, "IEEE 802.1X: Sending EAPOL-Key(s) to " MACSTR,
                   MAC2STR(sta->addr));
 
+#ifndef CONFIG_NO_VLAN
        vlan_id = sta->vlan_id;
        if (vlan_id < 0 || vlan_id > MAX_VLAN_ID)
                vlan_id = 0;
@@ -303,7 +308,9 @@ void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
                        ieee802_1x_tx_key_one(hapd, sta, key->idx, 1,
                                              key->key[key->idx],
                                              key->len[key->idx]);
-       } else if (hapd->default_wep_key) {
+       } else
+#endif /* CONFIG_NO_VLAN */
+       if (hapd->default_wep_key) {
                ieee802_1x_tx_key_one(hapd, sta, hapd->default_wep_key_idx, 1,
                                      hapd->default_wep_key,
                                      hapd->conf->default_wep_key_len);
@@ -371,6 +378,7 @@ int radius_sta_rate(struct hostapd_data *hapd, struct sta_info *sta)
 }
 
 
+#ifndef CONFIG_NO_RADIUS
 static void ieee802_1x_learn_identity(struct hostapd_data *hapd,
                                      struct eapol_state_machine *sm,
                                      const u8 *eap, size_t len)
@@ -541,6 +549,7 @@ static void ieee802_1x_encapsulate_radius(struct hostapd_data *hapd,
        radius_msg_free(msg);
        os_free(msg);
 }
+#endif /* CONFIG_NO_RADIUS */
 
 
 char *eap_type_text(u8 type)
@@ -647,7 +656,15 @@ static void handle_eap(struct hostapd_data *hapd, struct sta_info *sta,
 }
 
 
-/* Process the EAPOL frames from the Supplicant */
+/**
+ * ieee802_1x_receive - Process the EAPOL frames from the Supplicant
+ * @hapd: hostapd BSS data
+ * @sa: Source address (sender of the EAPOL frame)
+ * @buf: EAPOL frame
+ * @len: Length of buf in octets
+ *
+ * This function is called for each incoming EAPOL frame from the interface
+ */
 void ieee802_1x_receive(struct hostapd_data *hapd, const u8 *sa, const u8 *buf,
                        size_t len)
 {
@@ -664,8 +681,9 @@ void ieee802_1x_receive(struct hostapd_data *hapd, const u8 *sa, const u8 *buf,
        wpa_printf(MSG_DEBUG, "IEEE 802.1X: %lu bytes from " MACSTR,
                   (unsigned long) len, MAC2STR(sa));
        sta = ap_get_sta(hapd, sa);
-       if (!sta) {
-               printf("   no station information available\n");
+       if (!sta || !(sta->flags & WLAN_STA_ASSOC)) {
+               wpa_printf(MSG_DEBUG, "IEEE 802.1X data frame from not "
+                          "associated STA");
                return;
        }
 
@@ -729,6 +747,8 @@ void ieee802_1x_receive(struct hostapd_data *hapd, const u8 *sa, const u8 *buf,
                        sta->eapol_sm->flags |= EAPOL_SM_WAIT_START;
                }
 #endif /* CONFIG_WPS */
+
+               sta->eapol_sm->eap_if->portEnabled = TRUE;
        }
 
        /* since we support version 1, we can ignore version field and proceed
@@ -796,6 +816,14 @@ void ieee802_1x_receive(struct hostapd_data *hapd, const u8 *sa, const u8 *buf,
 }
 
 
+/**
+ * ieee802_1x_new_station - Start IEEE 802.1X authentication
+ * @hapd: hostapd BSS data
+ * @sta: The station
+ *
+ * This function is called to start IEEE 802.1X authentication when a new
+ * station completes IEEE 802.11 association.
+ */
 void ieee802_1x_new_station(struct hostapd_data *hapd, struct sta_info *sta)
 {
        struct rsn_pmksa_cache_entry *pmksa;
@@ -803,7 +831,7 @@ void ieee802_1x_new_station(struct hostapd_data *hapd, struct sta_info *sta)
        int force_1x = 0;
 
 #ifdef CONFIG_WPS
-       if (hapd->conf->wps_state &&
+       if (hapd->conf->wps_state && hapd->conf->wpa &&
            (sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS))) {
                /*
                 * Need to enable IEEE 802.1X/EAPOL state machines for possible
@@ -882,47 +910,6 @@ void ieee802_1x_new_station(struct hostapd_data *hapd, struct sta_info *sta)
 }
 
 
-void ieee802_1x_free_radius_class(struct radius_class_data *class)
-{
-       size_t i;
-       if (class == NULL)
-               return;
-       for (i = 0; i < class->count; i++)
-               os_free(class->attr[i].data);
-       os_free(class->attr);
-       class->attr = NULL;
-       class->count = 0;
-}
-
-
-int ieee802_1x_copy_radius_class(struct radius_class_data *dst,
-                                const struct radius_class_data *src)
-{
-       size_t i;
-
-       if (src->attr == NULL)
-               return 0;
-
-       dst->attr = os_zalloc(src->count * sizeof(struct radius_attr_data));
-       if (dst->attr == NULL)
-               return -1;
-
-       dst->count = 0;
-
-       for (i = 0; i < src->count; i++) {
-               dst->attr[i].data = os_malloc(src->attr[i].len);
-               if (dst->attr[i].data == NULL)
-                       break;
-               dst->count++;
-               os_memcpy(dst->attr[i].data, src->attr[i].data,
-                         src->attr[i].len);
-               dst->attr[i].len = src->attr[i].len;
-       }
-
-       return 0;
-}
-
-
 void ieee802_1x_free_station(struct sta_info *sta)
 {
        struct eapol_state_machine *sm = sta->eapol_sm;
@@ -932,17 +919,20 @@ void ieee802_1x_free_station(struct sta_info *sta)
 
        sta->eapol_sm = NULL;
 
+#ifndef CONFIG_NO_RADIUS
        if (sm->last_recv_radius) {
                radius_msg_free(sm->last_recv_radius);
                os_free(sm->last_recv_radius);
        }
+       radius_free_class(&sm->radius_class);
+#endif /* CONFIG_NO_RADIUS */
 
        os_free(sm->identity);
-       ieee802_1x_free_radius_class(&sm->radius_class);
        eapol_auth_free(sm);
 }
 
 
+#ifndef CONFIG_NO_RADIUS
 static void ieee802_1x_decapsulate_radius(struct hostapd_data *hapd,
                                          struct sta_info *sta)
 {
@@ -1026,7 +1016,8 @@ static void ieee802_1x_decapsulate_radius(struct hostapd_data *hapd,
 static void ieee802_1x_get_keys(struct hostapd_data *hapd,
                                struct sta_info *sta, struct radius_msg *msg,
                                struct radius_msg *req,
-                               u8 *shared_secret, size_t shared_secret_len)
+                               const u8 *shared_secret,
+                               size_t shared_secret_len)
 {
        struct radius_ms_mppe_keys *keys;
        struct eapol_state_machine *sm = sta->eapol_sm;
@@ -1078,7 +1069,7 @@ static void ieee802_1x_store_radius_class(struct hostapd_data *hapd,
            sm == NULL)
                return;
 
-       ieee802_1x_free_radius_class(&sm->radius_class);
+       radius_free_class(&sm->radius_class);
        count = radius_msg_count_attr(msg, RADIUS_ATTR_CLASS, 1);
        if (count <= 0)
                return;
@@ -1186,10 +1177,18 @@ ieee802_1x_search_radius_identifier(struct hostapd_data *hapd, u8 identifier)
 }
 
 
-/* Process the RADIUS frames from Authentication Server */
+/**
+ * ieee802_1x_receive_auth - Process RADIUS frames from Authentication Server
+ * @msg: RADIUS response message
+ * @req: RADIUS request message
+ * @shared_secret: RADIUS shared secret
+ * @shared_secret_len: Length of shared_secret in octets
+ * @data: Context data (struct hostapd_data *)
+ * Returns: Processing status
+ */
 static RadiusRxResult
 ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
-                       u8 *shared_secret, size_t shared_secret_len,
+                       const u8 *shared_secret, size_t shared_secret_len,
                        void *data)
 {
        struct hostapd_data *hapd = data;
@@ -1268,6 +1267,7 @@ ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
        case RADIUS_CODE_ACCESS_ACCEPT:
                if (sta->ssid->dynamic_vlan == DYNAMIC_VLAN_DISABLED)
                        sta->vlan_id = 0;
+#ifndef CONFIG_NO_VLAN
                else {
                        old_vlanid = sta->vlan_id;
                        sta->vlan_id = radius_msg_get_vlanid(msg);
@@ -1288,6 +1288,7 @@ ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
                                       "ID in Access-Accept");
                        break;
                }
+#endif /* CONFIG_NO_VLAN */
 
                ap_sta_bind_vlan(hapd, sta, old_vlanid);
 
@@ -1346,6 +1347,7 @@ ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
 
        return RADIUS_RX_QUEUED;
 }
+#endif /* CONFIG_NO_RADIUS */
 
 
 void ieee802_1x_abort_auth(struct hostapd_data *hapd, struct sta_info *sta)
@@ -1357,11 +1359,13 @@ void ieee802_1x_abort_auth(struct hostapd_data *hapd, struct sta_info *sta)
        hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE8021X,
                       HOSTAPD_LEVEL_DEBUG, "aborting authentication");
 
+#ifndef CONFIG_NO_RADIUS
        if (sm->last_recv_radius) {
                radius_msg_free(sm->last_recv_radius);
                os_free(sm->last_recv_radius);
                sm->last_recv_radius = NULL;
        }
+#endif /* CONFIG_NO_RADIUS */
 
        if (sm->eap_if->eapTimeout) {
                /*
@@ -1510,10 +1514,12 @@ static void ieee802_1x_eapol_send(void *ctx, void *sta_ctx, u8 type,
 static void ieee802_1x_aaa_send(void *ctx, void *sta_ctx,
                                const u8 *data, size_t datalen)
 {
+#ifndef CONFIG_NO_RADIUS
        struct hostapd_data *hapd = ctx;
        struct sta_info *sta = sta_ctx;
 
        ieee802_1x_encapsulate_radius(hapd, sta, data, datalen);
+#endif /* CONFIG_NO_RADIUS */
 }
 
 
@@ -1581,6 +1587,7 @@ static int ieee802_1x_sta_entry_alive(void *ctx, const u8 *addr)
 static void ieee802_1x_logger(void *ctx, const u8 *addr,
                              eapol_logger_level level, const char *txt)
 {
+#ifndef CONFIG_NO_HOSTAPD_LOGGER
        struct hostapd_data *hapd = ctx;
        int hlevel;
 
@@ -1599,6 +1606,7 @@ static void ieee802_1x_logger(void *ctx, const u8 *addr,
 
        hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE8021X, hlevel, "%s",
                       txt);
+#endif /* CONFIG_NO_HOSTAPD_LOGGER */
 }
 
 
@@ -1673,9 +1681,11 @@ int ieee802_1x_init(struct hostapd_data *hapd)
            hostapd_set_ieee8021x(hapd->conf->iface, hapd, 1))
                return -1;
 
+#ifndef CONFIG_NO_RADIUS
        if (radius_client_register(hapd->radius, RADIUS_AUTH,
                                   ieee802_1x_receive_auth, hapd))
                return -1;
+#endif /* CONFIG_NO_RADIUS */
 
        if (hapd->conf->default_wep_key_len) {
                hostapd_set_privacy(hapd, 1);
@@ -1717,7 +1727,7 @@ int ieee802_1x_reconfig(struct hostapd_data *hapd,
 
 
 int ieee802_1x_tx_status(struct hostapd_data *hapd, struct sta_info *sta,
-                        u8 *buf, size_t len, int ack)
+                        const u8 *buf, size_t len, int ack)
 {
        struct ieee80211_hdr *hdr;
        struct ieee802_1x_hdr *xhdr;