bsd: Get rid of printf size_t warnings with 64-bit builds
[wpasupplicant] / hostapd / ieee802_1x.c
index 839f7e0..722956a 100644 (file)
@@ -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)
 {
@@ -219,8 +220,8 @@ ieee802_1x_group_alloc(struct hostapd_data *hapd, const char *ifname)
        wpa_hexdump_key(MSG_DEBUG, "Default WEP key (dynamic VLAN)",
                        key->key[key->idx], key->len[key->idx]);
 
-       if (hostapd_set_encryption(ifname, hapd, "WEP", NULL, key->idx,
-                                  key->key[key->idx], key->len[key->idx], 1))
+       if (hostapd_set_key(ifname, hapd, WPA_ALG_WEP, NULL, key->idx, 1,
+                           NULL, 0, key->key[key->idx], key->len[key->idx]))
                printf("Could not set dynamic VLAN WEP encryption key.\n");
 
        hostapd_set_ieee8021x(ifname, hapd, 1);
@@ -279,13 +280,17 @@ 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_authenticator *eapol = hapd->eapol_auth;
        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 +298,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,9 +309,11 @@ 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) {
-               ieee802_1x_tx_key_one(hapd, sta, hapd->default_wep_key_idx, 1,
-                                     hapd->default_wep_key,
+       } else
+#endif /* CONFIG_NO_VLAN */
+       if (eapol->default_wep_key) {
+               ieee802_1x_tx_key_one(hapd, sta, eapol->default_wep_key_idx, 1,
+                                     eapol->default_wep_key,
                                      hapd->conf->default_wep_key_len);
        }
 
@@ -328,10 +336,9 @@ void ieee802_1x_tx_key(struct hostapd_data *hapd, struct sta_info *sta)
 
                /* TODO: set encryption in TX callback, i.e., only after STA
                 * has ACKed EAPOL-Key frame */
-               if (hostapd_set_encryption(hapd->conf->iface, hapd, "WEP",
-                                          sta->addr, 0, ikey,
-                                          hapd->conf->individual_wep_key_len,
-                                          1)) {
+               if (hostapd_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP,
+                                   sta->addr, 0, 1, NULL, 0, ikey,
+                                   hapd->conf->individual_wep_key_len)) {
                        wpa_printf(MSG_ERROR, "Could not set individual WEP "
                                   "encryption.");
                }
@@ -740,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
@@ -822,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
@@ -901,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;
@@ -956,10 +924,10 @@ void ieee802_1x_free_station(struct sta_info *sta)
                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);
 }
 
@@ -1101,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;
@@ -1299,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);
@@ -1319,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);
 
@@ -1456,22 +1426,24 @@ void ieee802_1x_dump_state(FILE *f, const char *prefix, struct sta_info *sta)
 
 static int ieee802_1x_rekey_broadcast(struct hostapd_data *hapd)
 {
+       struct eapol_authenticator *eapol = hapd->eapol_auth;
+
        if (hapd->conf->default_wep_key_len < 1)
                return 0;
 
-       os_free(hapd->default_wep_key);
-       hapd->default_wep_key = os_malloc(hapd->conf->default_wep_key_len);
-       if (hapd->default_wep_key == NULL ||
-           os_get_random(hapd->default_wep_key,
+       os_free(eapol->default_wep_key);
+       eapol->default_wep_key = os_malloc(hapd->conf->default_wep_key_len);
+       if (eapol->default_wep_key == NULL ||
+           os_get_random(eapol->default_wep_key,
                          hapd->conf->default_wep_key_len)) {
                printf("Could not generate random WEP key.\n");
-               os_free(hapd->default_wep_key);
-               hapd->default_wep_key = NULL;
+               os_free(eapol->default_wep_key);
+               eapol->default_wep_key = NULL;
                return -1;
        }
 
        wpa_hexdump_key(MSG_DEBUG, "IEEE 802.1X: New default WEP key",
-                       hapd->default_wep_key,
+                       eapol->default_wep_key,
                        hapd->conf->default_wep_key_len);
 
        return 0;
@@ -1492,36 +1464,37 @@ static int ieee802_1x_sta_key_available(struct hostapd_data *hapd,
 static void ieee802_1x_rekey(void *eloop_ctx, void *timeout_ctx)
 {
        struct hostapd_data *hapd = eloop_ctx;
+       struct eapol_authenticator *eapol = hapd->eapol_auth;
 
-       if (hapd->default_wep_key_idx >= 3)
-               hapd->default_wep_key_idx =
+       if (eapol->default_wep_key_idx >= 3)
+               eapol->default_wep_key_idx =
                        hapd->conf->individual_wep_key_len > 0 ? 1 : 0;
        else
-               hapd->default_wep_key_idx++;
+               eapol->default_wep_key_idx++;
 
        wpa_printf(MSG_DEBUG, "IEEE 802.1X: New default WEP key index %d",
-                  hapd->default_wep_key_idx);
+                  eapol->default_wep_key_idx);
                      
        if (ieee802_1x_rekey_broadcast(hapd)) {
                hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
                               HOSTAPD_LEVEL_WARNING, "failed to generate a "
                               "new broadcast key");
-               os_free(hapd->default_wep_key);
-               hapd->default_wep_key = NULL;
+               os_free(eapol->default_wep_key);
+               eapol->default_wep_key = NULL;
                return;
        }
 
        /* TODO: Could setup key for RX here, but change default TX keyid only
         * after new broadcast key has been sent to all stations. */
-       if (hostapd_set_encryption(hapd->conf->iface, hapd, "WEP", NULL,
-                                  hapd->default_wep_key_idx,
-                                  hapd->default_wep_key,
-                                  hapd->conf->default_wep_key_len, 1)) {
+       if (hostapd_set_key(hapd->conf->iface, hapd, WPA_ALG_WEP, NULL,
+                           eapol->default_wep_key_idx, 1, NULL, 0,
+                           eapol->default_wep_key,
+                           hapd->conf->default_wep_key_len)) {
                hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE8021X,
                               HOSTAPD_LEVEL_WARNING, "failed to configure a "
                               "new broadcast key");
-               os_free(hapd->default_wep_key);
-               hapd->default_wep_key = NULL;
+               os_free(eapol->default_wep_key);
+               eapol->default_wep_key = NULL;
                return;
        }
 
@@ -1617,6 +1590,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;
 
@@ -1635,6 +1609,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 */
 }
 
 
@@ -1719,12 +1694,12 @@ int ieee802_1x_init(struct hostapd_data *hapd)
                hostapd_set_privacy(hapd, 1);
 
                for (i = 0; i < 4; i++)
-                       hostapd_set_encryption(hapd->conf->iface, hapd,
-                                              "none", NULL, i, NULL, 0, 0);
+                       hostapd_set_key(hapd->conf->iface, hapd, WPA_ALG_NONE,
+                                       NULL, i, 0, NULL, 0, NULL, 0);
 
                ieee802_1x_rekey(hapd, NULL);
 
-               if (hapd->default_wep_key == NULL)
+               if (hapd->eapol_auth->default_wep_key == NULL)
                        return -1;
        }