static int hostapd_setup_encryption(hostapd *hapd) { if (HOSTAPD_DEBUG_COND(HOSTAPD_DEBUG_MINIMAL)) hostapd_hexdump("Default WEP key", hapd->default_wep_key, hapd->conf->default_wep_key_len); hostapd_set_encryption(hapd->driver.data, "none", NULL, 0, NULL, 0); if (hostapd_set_encryption(hapd->driver.data, "WEP", NULL, hapd->default_wep_key_idx, hapd->default_wep_key, hapd->conf->default_wep_key_len)) { printf("Could not set WEP encryption.\n"); return -1; } /* Setup rekeying timer. */ if (hapd->conf->wep_rekeying_period > 0 && (hapd->default_wep_key || hapd->conf->individual_wep_key_len > 0) && eloop_register_timeout(hapd->conf->wep_rekeying_period, 0, hostapd_rotate_wep, hapd, NULL)) { printf("Couldn't set rekeying timer.\n"); return -1; } return 0; }
/* The rekeying function: generate a new broadcast WEP key, rotate * the key index, and direct Key Transmit State Machines of all of the * authenticators to send a new key to the authenticated stations. */ static void hostapd_rotate_wep(void *eloop_ctx, void *timeout_ctx) { struct sta_info *s; hostapd *hapd = eloop_ctx; if (hapd->default_wep_key) free(hapd->default_wep_key); if (hapd->default_wep_key_idx >= 3) hapd->default_wep_key_idx = hapd->conf->individual_wep_key_len > 0 ? 1 : 0; else hapd->default_wep_key_idx++; hostapd_set_broadcast_wep(hapd); for (s = hapd->sta_list; s != NULL; s = s->next) ieee802_1x_notify_key_available(s->eapol_sm, 1); if (HOSTAPD_DEBUG_COND(HOSTAPD_DEBUG_MINIMAL)) { hostapd_hexdump("New WEP key generated", hapd->default_wep_key, hapd->conf->default_wep_key_len); } /* 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->driver.data, "WEP", NULL, hapd->default_wep_key_idx, hapd->default_wep_key, hapd->conf->default_wep_key_len)) { printf("Could not set WEP encryption.\n"); } if (hapd->conf->wep_rekeying_period > 0) eloop_register_timeout(hapd->conf->wep_rekeying_period, 0, hostapd_rotate_wep, hapd, NULL); }
int vlan_setup_encryption_dyn(struct hostapd_data *hapd, struct hostapd_ssid *mssid, const char *dyn_vlan) { int i; if (dyn_vlan == NULL) return 0; /* Static WEP keys are set here; IEEE 802.1X and WPA uses their own * functions for setting up dynamic broadcast keys. */ for (i = 0; i < 4; i++) { if (mssid->wep.key[i] && hostapd_set_encryption(dyn_vlan, hapd, "WEP", NULL, i, mssid->wep.key[i], mssid->wep.len[i], i == mssid->wep.idx)) { printf("VLAN: Could not set WEP encryption for " "dynamic VLAN.\n"); return -1; } } return 0; }