commit 4170c1e14088b0879c1021b7bc13e83ff0a8b0c5
parent 8a6d4543ab29f4e70e0e641c50afbd125534e8d4
Author: illiliti <illiliti@protonmail.com>
Date: Sat, 28 Jan 2023 06:55:22 +0300
Merge tag '2.2'
Release 2.2
Diffstat:
24 files changed, 904 insertions(+), 173 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,11 @@
+ver 2.2:
+ Fix issue with handling FT and multiple roaming scans.
+ Fix issue with handling multiple wiphy registrations.
+ Fix issue with with EAP-PEAP session resumption.
+ Add support for using PTK rekeying in AP mode.
+ Add support for setting country IE in AP mode.
+ Add support for setting WMM parameter IE in AP mode.
+
ver 2.1:
Fix issue with handling FT-over-DS action.
Fix issue with handling scan and 6 GHz support check.
diff --git a/configure.ac b/configure.ac
@@ -1,5 +1,5 @@
AC_PREREQ([2.69])
-AC_INIT([iwd],[2.1])
+AC_INIT([iwd],[2.2])
AC_CONFIG_HEADERS(config.h)
AC_CONFIG_AUX_DIR(build-aux)
@@ -268,7 +268,7 @@ if (test "${enable_external_ell}" = "yes"); then
test "${enable_monitor}" != "no" ||
test "${enable_wired}" = "yes" ||
test "${enable_hwsim}" = "yes"); then
- ell_min_version="0.55"
+ ell_min_version="0.56"
else
ell_min_version="0.5"
fi
diff --git a/monitor/nlmon.c b/monitor/nlmon.c
@@ -494,7 +494,7 @@ static void print_ie_country(unsigned int level, const char *label,
if (code[i + 2] < 32)
print_attr(level + 1, "%27c (air propagation "
"time %2d µs)", ' ', 3 * code[i + 2]);
- } else {
+ } else if (code[i] != 0) {
print_attr(level + 1, "First channel %3d number of "
"channels %2d max tx power %2d dBm",
code[i], code[i + 1], code[i + 2]);
diff --git a/src/ap.c b/src/ap.c
@@ -72,6 +72,7 @@ struct ap_state {
uint8_t psk[32];
enum band_freq band;
uint8_t channel;
+ struct band_chandef chandef;
uint8_t *authorized_macs;
unsigned int authorized_macs_num;
char wsc_name[33];
@@ -105,12 +106,16 @@ struct ap_state {
struct l_dbus_message *scan_pending;
struct l_queue *networks;
+ struct l_timeout *rekey_timeout;
+ unsigned int rekey_time;
+
bool started : 1;
bool gtk_set : 1;
bool netconfig_set_addr4 : 1;
bool in_event : 1;
bool free_pending : 1;
bool scanning : 1;
+ bool supports_ht : 1;
};
struct sta_state {
@@ -135,6 +140,10 @@ struct sta_state {
bool wsc_v2;
struct l_dhcp_lease *ip_alloc_lease;
bool ip_alloc_sent;
+ uint64_t rekey_time;
+
+ bool ht_support : 1;
+ bool ht_greenfield : 1;
};
struct ap_wsc_pbc_probe_record {
@@ -340,6 +349,11 @@ static void ap_reset(struct ap_state *ap)
l_queue_destroy(ap->networks, l_free);
ap->networks = NULL;
}
+
+ if (ap->rekey_timeout) {
+ l_timeout_remove(ap->rekey_timeout);
+ ap->rekey_timeout = NULL;
+ }
}
static bool ap_event_done(struct ap_state *ap, bool prev_in_event)
@@ -372,6 +386,8 @@ static bool ap_event(struct ap_state *ap, enum ap_event_type event,
return ap_event_done(ap, prev);
}
+static void ap_check_rekeys(struct ap_state *ap);
+
static void ap_del_station(struct sta_state *sta, uint16_t reason,
bool disassociate)
{
@@ -434,6 +450,93 @@ static void ap_del_station(struct sta_state *sta, uint16_t reason,
ap_event_done(ap, prev);
}
+
+ /*
+ * Set the rekey time to zero which will skip this station when
+ * determining the next rekey.
+ */
+ sta->rekey_time = 0;
+ ap_check_rekeys(ap);
+}
+
+static void ap_start_rekey(struct ap_state *ap, struct sta_state *sta)
+{
+ l_debug("Rekey STA "MAC, MAC_STR(sta->addr));
+
+ eapol_start(sta->sm);
+}
+
+static void ap_rekey_timeout(struct l_timeout *timeout, void *user_data)
+{
+ struct ap_state *ap = user_data;
+
+ ap_check_rekeys(ap);
+}
+
+/*
+ * Used to check/start any rekeys which are due and reset the rekey timer to the
+ * next soonest station needing a rekey.
+ *
+ * TODO: Could adapt this to also take into account the next GTK rekey and
+ * service that as well. But GTK rekeys are not yet supported in AP mode.
+ */
+static void ap_check_rekeys(struct ap_state *ap)
+{
+ const struct l_queue_entry *e;
+ uint64_t now = l_time_now();
+ uint64_t next = 0;
+
+ if (!ap->rekey_time)
+ return;
+
+ /* Find the station(s) that need a rekey and start it */
+ for (e = l_queue_get_entries(ap->sta_states); e; e = e->next) {
+ struct sta_state *sta = e->data;
+
+ if (!sta->associated || !sta->rsna || sta->rekey_time == 0)
+ continue;
+
+ if (l_time_before(now, sta->rekey_time)) {
+ uint64_t diff = l_time_diff(now, sta->rekey_time);
+
+ /* Finding the next rekey time */
+ if (next < diff)
+ next = diff;
+
+ continue;
+ }
+
+ ap_start_rekey(ap, sta);
+ }
+
+ /*
+ * Set the next rekey to the station needing it the soonest, or remove
+ * if a single station and wait until the rekey is complete to reset
+ * the timer.
+ */
+ if (next)
+ l_timeout_modify(ap->rekey_timeout, l_time_to_secs(next));
+ else {
+ l_timeout_remove(ap->rekey_timeout);
+ ap->rekey_timeout = NULL;
+ }
+}
+
+static void ap_set_sta_rekey_timer(struct ap_state *ap, struct sta_state *sta)
+{
+ if (!ap->rekey_time)
+ return;
+
+ sta->rekey_time = l_time_now() + ap->rekey_time - 1;
+
+ /*
+ * First/only station authenticated, set rekey timer. Any more stations
+ * will just set their rekey time and be serviced by the single callback
+ */
+ if (!ap->rekey_timeout)
+ ap->rekey_timeout = l_timeout_create(
+ l_time_to_secs(ap->rekey_time),
+ ap_rekey_timeout, ap, NULL);
}
static bool ap_sta_match_addr(const void *a, const void *b)
@@ -474,6 +577,8 @@ static void ap_new_rsna(struct sta_state *sta)
sta->rsna = true;
+ ap_set_sta_rekey_timer(ap, sta);
+
event_data.mac = sta->addr;
event_data.assoc_ies = sta->assoc_ies;
event_data.assoc_ies_len = sta->assoc_ies_len;
@@ -802,6 +907,29 @@ static size_t ap_write_wsc_ie(struct ap_state *ap,
return len;
}
+static size_t ap_build_supported_rates(struct ap_state *ap,
+ uint8_t *rates)
+{
+ uint32_t minr, maxr, count, r;
+
+ minr = l_uintset_find_min(ap->rates);
+ maxr = l_uintset_find_max(ap->rates);
+ count = 0;
+ for (r = minr; r <= maxr && count < 8; r++)
+ if (l_uintset_contains(ap->rates, r)) {
+ uint8_t flag = 0;
+
+ /* Mark only the lowest rate as Basic Rate */
+ if (count == 0)
+ flag = 0x80;
+
+ *rates++ = r | flag;
+ count++;
+ }
+
+ return count;
+}
+
static size_t ap_get_extra_ies_len(struct ap_state *ap,
enum mpdu_management_subtype type,
const struct mmpdu_header *client_frame,
@@ -811,6 +939,9 @@ static size_t ap_get_extra_ies_len(struct ap_state *ap,
len += ap_get_wsc_ie_len(ap, type, client_frame, client_frame_len);
+ if (ap->supports_ht)
+ len += 26;
+
if (ap->ops->get_extra_ies_len)
len += ap->ops->get_extra_ies_len(type, client_frame,
client_frame_len,
@@ -819,6 +950,67 @@ static size_t ap_get_extra_ies_len(struct ap_state *ap,
return len;
}
+/* WMM Specification 2.2.2 WMM Parameter Element */
+struct ap_wmm_ac_record {
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+ uint8_t aifsn : 4;
+ uint8_t acm : 1;
+ uint8_t aci : 2;
+ uint8_t reserved : 1;
+ uint8_t ecw_min : 4;
+ uint8_t ecw_max : 4;
+#elif defined (__BIG_ENDIAN_BITFIELD)
+ uint8_t reserved : 1;
+ uint8_t aci : 2;
+ uint8_t acm : 1;
+ uint8_t aifsn : 4;
+ uint8_t ecw_max : 4;
+ uint8_t ecw_min : 4;
+#else
+#error "Please fix <asm/byteorder.h"
+#endif
+ __le16 txop_limit;
+} __attribute__((packed));
+
+static size_t ap_write_wmm_ies(struct ap_state *ap, uint8_t *out_buf)
+{
+ unsigned int i;
+ struct wiphy *wiphy = netdev_get_wiphy(ap->netdev);
+
+ /*
+ * Linux kernel requires APs include WMM Information element if
+ * supporting HT/VHT/etc.
+ *
+ * The only value we can actually get from the kernel is UAPSD. The
+ * remaining values (AC parameter records) are made up or defaults
+ * defined in the WMM spec are used.
+ */
+ *out_buf++ = IE_TYPE_VENDOR_SPECIFIC;
+ *out_buf++ = 24;
+ memcpy(out_buf, microsoft_oui, sizeof(microsoft_oui));
+ out_buf += sizeof(microsoft_oui);
+ *out_buf++ = 2; /* WMM OUI Type */
+ *out_buf++ = 1; /* WMM Parameter subtype */
+ *out_buf++ = 1; /* WMM Version */
+ *out_buf++ = wiphy_supports_uapsd(wiphy) ? 1 << 7 : 0;
+ *out_buf++ = 0; /* reserved */
+
+ for (i = 0; i < 4; i++) {
+ struct ap_wmm_ac_record ac = { 0 };
+
+ ac.aifsn = 2;
+ ac.acm = 0;
+ ac.aci = i;
+ ac.ecw_min = 1;
+ ac.ecw_max = 15;
+ l_put_le16(0, &ac.txop_limit);
+
+ memcpy(out_buf + (i * 4), &ac, sizeof(struct ap_wmm_ac_record));
+ }
+
+ return 26;
+}
+
static size_t ap_write_extra_ies(struct ap_state *ap,
enum mpdu_management_subtype type,
const struct mmpdu_header *client_frame,
@@ -830,6 +1022,9 @@ static size_t ap_write_extra_ies(struct ap_state *ap,
len += ap_write_wsc_ie(ap, type, client_frame, client_frame_len,
out_buf + len);
+ if (ap->supports_ht)
+ len += ap_write_wmm_ies(ap, out_buf + len);
+
if (ap->ops->write_extra_ies)
len += ap->ops->write_extra_ies(type,
client_frame, client_frame_len,
@@ -838,6 +1033,66 @@ static size_t ap_write_extra_ies(struct ap_state *ap,
return len;
}
+static size_t ap_build_ht_capability(struct ap_state *ap, uint8_t *buf)
+{
+ struct wiphy *wiphy = netdev_get_wiphy(ap->netdev);
+ size_t ht_capa_len;
+ const uint8_t *ht_capa = wiphy_get_ht_capabilities(wiphy, ap->band,
+ &ht_capa_len);
+
+ memcpy(buf, ht_capa, ht_capa_len);
+
+ return ht_capa_len;
+}
+
+static size_t ap_build_ht_operation(struct ap_state *ap, uint8_t *buf)
+{
+ const struct l_queue_entry *e;
+ unsigned int non_ht = false;
+ unsigned int non_greenfield = false;
+
+ memset(buf, 0, 22);
+ *buf++ = ap->channel;
+
+ /*
+ * If 40MHz set 'Secondary Channel Offset' (bits 0-1) to above/below
+ * and set 'STA Channel Width' (bit 2) to indicate non-20Mhz.
+ */
+ if (ap->chandef.channel_width == BAND_CHANDEF_WIDTH_20)
+ goto check_stas;
+ else if (ap->chandef.frequency < ap->chandef.center1_frequency)
+ *buf |= 1 & 0x3;
+ else
+ *buf |= 3 & 0x3;
+
+ *buf |= 1 << 2;
+
+check_stas:
+ for (e = l_queue_get_entries(ap->sta_states); e; e = e->next) {
+ struct sta_state *sta = e->data;
+
+ if (!sta->associated)
+ continue;
+
+ if (!sta->ht_support)
+ non_ht = true;
+ else if (!sta->ht_greenfield)
+ non_greenfield = true;
+ }
+
+ if (non_greenfield)
+ set_bit(buf, 10);
+
+ if (non_ht)
+ set_bit(buf, 12);
+
+ /*
+ * TODO: Basic MCS set for all associated STAs
+ */
+
+ return 22;
+}
+
/*
* Build a Beacon frame or a Probe Response frame's header and body until
* the TIM IE. Except for the optional TIM IE which is inserted by the
@@ -858,8 +1113,7 @@ static size_t ap_build_beacon_pr_head(struct ap_state *ap,
struct mmpdu_header *mpdu = (void *) out_buf;
uint16_t capability = IE_BSS_CAP_ESS | IE_BSS_CAP_PRIVACY;
const uint8_t *bssid = netdev_get_address(ap->netdev);
- uint32_t minr, maxr, count, r;
- uint8_t *rates;
+ size_t len;
struct ie_tlv_builder builder;
memset(mpdu, 0, 36); /* Zero out header + non-IE fields */
@@ -884,49 +1138,146 @@ static size_t ap_build_beacon_pr_head(struct ap_state *ap,
/* Supported Rates IE */
ie_tlv_builder_next(&builder, IE_TYPE_SUPPORTED_RATES);
- rates = ie_tlv_builder_get_data(&builder);
-
- minr = l_uintset_find_min(ap->rates);
- maxr = l_uintset_find_max(ap->rates);
- count = 0;
- for (r = minr; r <= maxr && count < 8; r++)
- if (l_uintset_contains(ap->rates, r)) {
- uint8_t flag = 0;
-
- /* Mark only the lowest rate as Basic Rate */
- if (count == 0)
- flag = 0x80;
-
- *rates++ = r | flag;
- count++;
- }
-
- ie_tlv_builder_set_length(&builder, count);
+ len = ap_build_supported_rates(ap, ie_tlv_builder_get_data(&builder));
+ ie_tlv_builder_set_length(&builder, len);
/* DSSS Parameter Set IE for DSSS, HR, ERP and HT PHY rates */
ie_tlv_builder_next(&builder, IE_TYPE_DSSS_PARAMETER_SET);
ie_tlv_builder_set_data(&builder, &ap->channel, 1);
+ if (ap->supports_ht) {
+ ie_tlv_builder_next(&builder, IE_TYPE_HT_CAPABILITIES);
+ len = ap_build_ht_capability(ap,
+ ie_tlv_builder_get_data(&builder));
+ ie_tlv_builder_set_length(&builder, len);
+
+ ie_tlv_builder_next(&builder, IE_TYPE_HT_OPERATION);
+ len = ap_build_ht_operation(ap,
+ ie_tlv_builder_get_data(&builder));
+ ie_tlv_builder_set_length(&builder, len);
+ }
+
ie_tlv_builder_finalize(&builder, &out_len);
return 36 + out_len;
}
+static size_t ap_build_country_ie(struct ap_state *ap, uint8_t *out_buf,
+ size_t buf_len)
+{
+ size_t len;
+ size_t i;
+ int spacing;
+ uint8_t *pos = out_buf;
+ uint8_t nchans = 1;
+ struct wiphy *wiphy = netdev_get_wiphy(ap->netdev);
+ const struct band_freq_attrs *last = NULL;
+ const struct band_freq_attrs *list = wiphy_get_frequency_info_list(
+ wiphy, ap->band, &len);
+
+ if (!list || wiphy_country_is_unknown(wiphy))
+ return 0;
+
+ if (L_WARN_ON(buf_len < 5))
+ goto no_space;
+
+ *pos++ = IE_TYPE_COUNTRY;
+ /* length not yet known */
+ pos++;
+
+ wiphy_get_reg_domain_country(wiphy, (char *)pos);
+ pos += 2;
+ *pos++ = ' ';
+
+ buf_len -= 5;
+
+ if (ap->band == BAND_FREQ_2_4_GHZ)
+ spacing = 1;
+ else
+ spacing = 4;
+
+ /*
+ * Construct a list of subband triplet entries. Each entry contains a
+ * starting channel and a number of channels which are spaced evenly
+ * and use the same TX power. Any deviation from this results in a new
+ * channel group.
+ *
+ * TODO: 6Ghz requires operating triplets, not subband triplets.
+ */
+ for (i = 0; i < len; i++) {
+ const struct band_freq_attrs *attr = &list[i];
+
+ if (!attr->supported || attr->disabled)
+ continue;
+
+ if (!last) {
+ /* Room for one complete triplet */
+ if (L_WARN_ON(buf_len < 3))
+ goto no_space;
+
+ *pos++ = i;
+ last = attr;
+ continue;
+ }
+
+ if (spacing != attr - last ||
+ attr->tx_power != last->tx_power) {
+ /* finish current group */
+ *pos++ = nchans;
+ *pos++ = last->tx_power;
+ buf_len -= 3;
+
+ /* start a new group */
+ if (L_WARN_ON(buf_len < 3))
+ goto no_space;
+
+ *pos++ = i;
+ nchans = 1;
+ } else
+ nchans++;
+
+ last = attr;
+ }
+
+ /* finish final group */
+ *pos++ = nchans;
+ *pos++ = last->tx_power;
+
+ len = pos - out_buf - 2;
+
+ /* Pad to even byte */
+ if (len & 1) {
+ if (L_WARN_ON(buf_len < 1))
+ goto no_space;
+
+ *pos++ = 0;
+ len++;
+ }
+
+ out_buf[1] = len;
+
+ return out_buf[1] + 2;
+
+no_space:
+ return 0;
+}
+
/* Beacon / Probe Response frame portion after the TIM IE */
static size_t ap_build_beacon_pr_tail(struct ap_state *ap,
enum mpdu_management_subtype stype,
const struct mmpdu_header *req,
- size_t req_len, uint8_t *out_buf)
+ size_t req_len, uint8_t *out_buf,
+ size_t buf_len)
{
size_t len;
struct ie_rsn_info rsn;
- /* TODO: Country IE between TIM IE and RSNE */
+ len = ap_build_country_ie(ap, out_buf, buf_len);
/* RSNE */
ap_set_rsn_info(ap, &rsn);
- if (!ie_build_rsne(&rsn, out_buf))
+ if (!ie_build_rsne(&rsn, out_buf + len))
return 0;
- len = 2 + out_buf[1];
+ len += 2 + out_buf[len + 1];
len += ap_write_extra_ies(ap, stype, req, req_len, out_buf + len);
return len;
@@ -944,11 +1295,11 @@ void ap_update_beacon(struct ap_state *ap)
{
struct l_genl_msg *cmd;
uint8_t head[256];
- L_AUTO_FREE_VAR(uint8_t *, tail) =
- l_malloc(256 + ap_get_extra_ies_len(ap,
+ size_t tail_len = 256 + ap_get_extra_ies_len(ap,
MPDU_MANAGEMENT_SUBTYPE_BEACON,
- NULL, 0));
- size_t head_len, tail_len;
+ NULL, 0);
+ L_AUTO_FREE_VAR(uint8_t *, tail) = malloc(tail_len);
+ size_t head_len;
uint64_t wdev_id = netdev_get_wdev_id(ap->netdev);
static const uint8_t bcast_addr[6] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff
@@ -960,7 +1311,7 @@ void ap_update_beacon(struct ap_state *ap)
head_len = ap_build_beacon_pr_head(ap, MPDU_MANAGEMENT_SUBTYPE_BEACON,
bcast_addr, head, sizeof(head));
tail_len = ap_build_beacon_pr_tail(ap, MPDU_MANAGEMENT_SUBTYPE_BEACON,
- NULL, 0, tail);
+ NULL, 0, tail, tail_len);
if (L_WARN_ON(!head_len || !tail_len))
return;
@@ -1121,6 +1472,9 @@ static void ap_handshake_event(struct handshake_state *hs,
sta->hs->go_ip_addr = IP4_FROM_STR(own_addr_str);
break;
}
+ case HANDSHAKE_EVENT_REKEY_COMPLETE:
+ ap_set_sta_rekey_timer(ap, sta);
+ return;
default:
break;
}
@@ -1540,8 +1894,8 @@ static uint32_t ap_assoc_resp(struct ap_state *ap, struct sta_state *sta,
struct mmpdu_header *mpdu = (void *) mpdu_buf;
struct mmpdu_association_response *resp;
size_t ies_len = 0;
+ size_t len;
uint16_t capability = IE_BSS_CAP_ESS | IE_BSS_CAP_PRIVACY;
- uint32_t r, minr, maxr, count;
memset(mpdu, 0, sizeof(*mpdu));
@@ -1561,23 +1915,21 @@ static uint32_t ap_assoc_resp(struct ap_state *ap, struct sta_state *sta,
/* Supported Rates IE */
resp->ies[ies_len++] = IE_TYPE_SUPPORTED_RATES;
+ len = ap_build_supported_rates(ap, resp->ies + ies_len + 1);
+ resp->ies[ies_len++] = len;
+ ies_len += len;
- minr = l_uintset_find_min(ap->rates);
- maxr = l_uintset_find_max(ap->rates);
- count = 0;
- for (r = minr; r <= maxr && count < 8; r++)
- if (l_uintset_contains(ap->rates, r)) {
- uint8_t flag = 0;
-
- /* Mark only the lowest rate as Basic Rate */
- if (count == 0)
- flag = 0x80;
-
- resp->ies[ies_len + 1 + count++] = r | flag;
- }
+ if (ap->supports_ht) {
+ resp->ies[ies_len++] = IE_TYPE_HT_CAPABILITIES;
+ len = ap_build_ht_capability(ap, resp->ies + ies_len + 1);
+ resp->ies[ies_len++] = len;
+ ies_len += len;
- resp->ies[ies_len++] = count;
- ies_len += count;
+ resp->ies[ies_len++] = IE_TYPE_HT_OPERATION;
+ len = ap_build_ht_operation(ap, resp->ies + ies_len + 1);
+ resp->ies[ies_len++] = len;
+ ies_len += len;
+ }
ies_len += ap_write_extra_ies(ap, stype, req, req_len,
resp->ies + ies_len);
@@ -1784,6 +2136,17 @@ static void ap_assoc_reassoc(struct sta_state *sta, bool reassoc,
fils_ip_req = true;
break;
+ case IE_TYPE_HT_CAPABILITIES:
+ if (ie_tlv_iter_get_length(&iter) != 26) {
+ err = MMPDU_REASON_CODE_INVALID_IE;
+ goto bad_frame;
+ }
+
+ if (test_bit(ie_tlv_iter_get_data(&iter), 4))
+ sta->ht_greenfield = true;
+
+ sta->ht_support = true;
+ break;
}
if (!rates || !ssid || (!wsc_data && !rsn) ||
@@ -2135,7 +2498,7 @@ static void ap_probe_req_cb(const struct mmpdu_header *hdr, const void *body,
len += ap_build_beacon_pr_tail(ap,
MPDU_MANAGEMENT_SUBTYPE_PROBE_RESPONSE,
hdr, body + body_len - (void *) hdr,
- resp + len);
+ resp + len, resp_len - len);
ap_send_mgmt_frame(ap, (struct mmpdu_header *) resp, len,
ap_probe_resp_cb, NULL);
@@ -2392,11 +2755,11 @@ static struct l_genl_msg *ap_build_cmd_start_ap(struct ap_state *ap)
struct l_genl_msg *cmd;
uint8_t head[256];
- L_AUTO_FREE_VAR(uint8_t *, tail) =
- l_malloc(256 + ap_get_extra_ies_len(ap,
+ size_t tail_len = 256 + ap_get_extra_ies_len(ap,
MPDU_MANAGEMENT_SUBTYPE_BEACON,
- NULL, 0));
- size_t head_len, tail_len;
+ NULL, 0);
+ L_AUTO_FREE_VAR(uint8_t *, tail) = l_malloc(tail_len);
+ size_t head_len;
uint32_t dtim_period = 3;
uint32_t ifindex = netdev_get_ifindex(ap->netdev);
@@ -2409,8 +2772,6 @@ static struct l_genl_msg *ap_build_cmd_start_ap(struct ap_state *ap)
uint32_t nl_akm = CRYPTO_AKM_PSK;
uint32_t wpa_version = NL80211_WPA_VERSION_2;
uint32_t auth_type = NL80211_AUTHTYPE_OPEN_SYSTEM;
- uint32_t ch_freq = band_channel_to_freq(ap->channel, ap->band);
- uint32_t ch_width = NL80211_CHAN_WIDTH_20;
unsigned int i;
static const uint8_t bcast_addr[6] = {
@@ -2427,7 +2788,7 @@ static struct l_genl_msg *ap_build_cmd_start_ap(struct ap_state *ap)
head_len = ap_build_beacon_pr_head(ap, MPDU_MANAGEMENT_SUBTYPE_BEACON,
bcast_addr, head, sizeof(head));
tail_len = ap_build_beacon_pr_tail(ap, MPDU_MANAGEMENT_SUBTYPE_BEACON,
- NULL, 0, tail);
+ NULL, 0, tail, tail_len);
if (!head_len || !tail_len)
return NULL;
@@ -2458,8 +2819,13 @@ static struct l_genl_msg *ap_build_cmd_start_ap(struct ap_state *ap)
l_genl_msg_append_attr(cmd, NL80211_ATTR_WPA_VERSIONS, 4, &wpa_version);
l_genl_msg_append_attr(cmd, NL80211_ATTR_AKM_SUITES, 4, &nl_akm);
l_genl_msg_append_attr(cmd, NL80211_ATTR_AUTH_TYPE, 4, &auth_type);
- l_genl_msg_append_attr(cmd, NL80211_ATTR_WIPHY_FREQ, 4, &ch_freq);
- l_genl_msg_append_attr(cmd, NL80211_ATTR_CHANNEL_WIDTH, 4, &ch_width);
+ l_genl_msg_append_attr(cmd, NL80211_ATTR_WIPHY_FREQ, 4,
+ &ap->chandef.frequency);
+ l_genl_msg_append_attr(cmd, NL80211_ATTR_CHANNEL_WIDTH, 4,
+ &ap->chandef.channel_width);
+ if (ap->chandef.center1_frequency)
+ l_genl_msg_append_attr(cmd, NL80211_ATTR_CENTER_FREQ1, 4,
+ &ap->chandef.center1_frequency);
if (wiphy_supports_probe_resp_offload(wiphy)) {
uint8_t probe_resp[head_len + tail_len];
@@ -2470,7 +2836,8 @@ static struct l_genl_msg *ap_build_cmd_start_ap(struct ap_state *ap)
zero_addr, ptr, sizeof(probe_resp));
ptr += ap_build_beacon_pr_tail(ap,
MPDU_MANAGEMENT_SUBTYPE_PROBE_RESPONSE,
- NULL, 0, ptr);
+ NULL, 0, ptr, sizeof(probe_resp) -
+ (ptr - probe_resp));
l_genl_msg_append_attr(cmd, NL80211_ATTR_PROBE_RESP,
ptr - probe_resp, probe_resp);
@@ -2627,6 +2994,9 @@ static void ap_handle_new_station(struct ap_state *ap, struct l_genl_msg *msg)
l_queue_push_tail(ap->sta_states, sta);
+ if (ap->supports_ht)
+ ap_update_beacon(ap);
+
msg = nl80211_build_set_station_unauthorized(
netdev_get_ifindex(ap->netdev), mac);
@@ -3195,6 +3565,32 @@ static bool ap_validate_band_channel(struct ap_state *ap)
l_error("AP frequency %u disabled or unsupported", freq);
return false;
}
+
+ if (ap->supports_ht) {
+ if (band_freq_to_ht_chandef(freq, attr, &ap->chandef) < 0) {
+ /*
+ * This is unlikely ever to fail since there are no
+ * 20Mhz restrictions, but just in case fall back to
+ * non-HT.
+ */
+ ap->supports_ht = false;
+
+ l_warn("AP could not find HT chandef for frequency %u"
+ " using 20Mhz no-HT", freq);
+
+ goto no_ht;
+ }
+ } else {
+no_ht:
+ ap->chandef.frequency = freq;
+ ap->chandef.channel_width = BAND_CHANDEF_WIDTH_20NOHT;
+ }
+
+ l_debug("AP using frequency %u and channel width %s",
+ ap->chandef.frequency,
+ band_chandef_width_to_string(
+ ap->chandef.channel_width));
+
return true;
}
@@ -3263,6 +3659,9 @@ static int ap_load_config(struct ap_state *ap, const struct l_settings *config,
ap->band = BAND_FREQ_2_4_GHZ;
}
+ ap->supports_ht = wiphy_get_ht_capabilities(wiphy, ap->band,
+ NULL) != NULL;
+
if (!ap_validate_band_channel(ap)) {
l_error("AP Band and Channel combination invalid");
return -EINVAL;
@@ -3332,6 +3731,19 @@ static int ap_load_config(struct ap_state *ap, const struct l_settings *config,
l_strfreev(strvval);
}
+ if (l_settings_has_key(config, "General", "RekeyTimeout")) {
+ unsigned int uintval;
+
+ if (!l_settings_get_uint(config, "General",
+ "RekeyTimeout", &uintval)) {
+ l_error("AP [General].RekeyTimeout is not valid");
+ return -EINVAL;
+ }
+
+ ap->rekey_time = uintval * L_USEC_PER_SEC;
+ } else
+ ap->rekey_time = 0;
+
/*
* Since 5GHz won't ever support only CCK rates we can ignore this
* setting on that band.
@@ -3660,6 +4072,9 @@ bool ap_station_disconnect(struct ap_state *ap, const uint8_t *mac,
if (!sta)
return false;
+ if (ap->supports_ht)
+ ap_update_beacon(ap);
+
ap_del_station(sta, reason, false);
ap_sta_free(sta);
return true;
diff --git a/src/band.c b/src/band.c
@@ -1194,8 +1194,97 @@ int oci_from_chandef(const struct band_chandef *own, uint8_t oci[static 3])
return -ENOENT;
}
+/* Find an HT chandef for the frequency */
+int band_freq_to_ht_chandef(uint32_t freq, const struct band_freq_attrs *attr,
+ struct band_chandef *chandef)
+{
+ enum band_freq band;
+ enum band_chandef_width width;
+ unsigned int i;
+ const struct operating_class_info *best = NULL;
+
+ if (attr->disabled || !attr->supported)
+ return -EINVAL;
+
+ if (!band_freq_to_channel(freq, &band))
+ return -EINVAL;
+
+ for (i = 0; i < L_ARRAY_SIZE(e4_operating_classes); i++) {
+ const struct operating_class_info *info =
+ &e4_operating_classes[i];
+ enum band_chandef_width w;
+
+ if (e4_has_frequency(info, freq) < 0)
+ continue;
+
+ /* Any restrictions for this channel width? */
+ switch (info->channel_spacing) {
+ case 20:
+ w = BAND_CHANDEF_WIDTH_20;
+ break;
+ case 40:
+ w = BAND_CHANDEF_WIDTH_40;
+
+ /* 6GHz remove the upper/lower 40mhz channel concept */
+ if (band == BAND_FREQ_6_GHZ)
+ break;
+
+ if (info->flags & PRIMARY_CHANNEL_UPPER &&
+ attr->no_ht40_plus)
+ continue;
+
+ if (info->flags & PRIMARY_CHANNEL_LOWER &&
+ attr->no_ht40_minus)
+ continue;
+
+ break;
+ default:
+ continue;
+ }
+
+ if (!best || best->channel_spacing < info->channel_spacing) {
+ best = info;
+ width = w;
+ }
+ }
+
+ if (!best)
+ return -ENOENT;
+
+ chandef->frequency = freq;
+ chandef->channel_width = width;
+
+ /*
+ * Choose a secondary channel frequency:
+ * - 20mhz no secondary
+ * - 40mhz we can base the selection off the channel flags, either
+ * higher or lower.
+ */
+ switch (width) {
+ case BAND_CHANDEF_WIDTH_20:
+ return 0;
+ case BAND_CHANDEF_WIDTH_40:
+ if (band == BAND_FREQ_6_GHZ)
+ return 0;
+
+ if (best->flags & PRIMARY_CHANNEL_UPPER)
+ chandef->center1_frequency = freq - 10;
+ else
+ chandef->center1_frequency = freq + 10;
+
+ return 0;
+ default:
+ /* Should never happen */
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
uint8_t band_freq_to_channel(uint32_t freq, enum band_freq *out_band)
{
+ unsigned int i;
+ enum band_freq band = 0;
uint32_t channel = 0;
if (freq >= 2412 && freq <= 2484) {
@@ -1210,10 +1299,8 @@ uint8_t band_freq_to_channel(uint32_t freq, enum band_freq *out_band)
channel /= 5;
}
- if (out_band)
- *out_band = BAND_FREQ_2_4_GHZ;
-
- return channel;
+ band = BAND_FREQ_2_4_GHZ;
+ goto check_e4;
}
if (freq >= 5005 && freq < 5900) {
@@ -1222,10 +1309,9 @@ uint8_t band_freq_to_channel(uint32_t freq, enum band_freq *out_band)
channel = (freq - 5000) / 5;
- if (out_band)
- *out_band = BAND_FREQ_5_GHZ;
+ band = BAND_FREQ_5_GHZ;
- return channel;
+ goto check_e4;
}
if (freq >= 4905 && freq < 5000) {
@@ -1234,10 +1320,9 @@ uint8_t band_freq_to_channel(uint32_t freq, enum band_freq *out_band)
channel = (freq - 4000) / 5;
- if (out_band)
- *out_band = BAND_FREQ_5_GHZ;
+ band = BAND_FREQ_5_GHZ;
- return channel;
+ goto check_e4;
}
if (freq > 5950 && freq <= 7115) {
@@ -1246,17 +1331,31 @@ uint8_t band_freq_to_channel(uint32_t freq, enum band_freq *out_band)
channel = (freq - 5950) / 5;
- if (out_band)
- *out_band = BAND_FREQ_6_GHZ;
+ band = BAND_FREQ_6_GHZ;
- return channel;
+ goto check_e4;
}
if (freq == 5935) {
- if (out_band)
- *out_band = BAND_FREQ_6_GHZ;
+ band = BAND_FREQ_6_GHZ;
+ channel = 2;
+ }
- return 2;
+ if (!band || !channel)
+ return 0;
+
+check_e4:
+ for (i = 0; i < L_ARRAY_SIZE(e4_operating_classes); i++) {
+ const struct operating_class_info *info =
+ &e4_operating_classes[i];
+
+ if (e4_has_frequency(info, freq) == 0 ||
+ e4_has_ccfi(info, freq) == 0) {
+ if (out_band)
+ *out_band = band;
+
+ return channel;
+ }
}
return 0;
@@ -1264,26 +1363,33 @@ uint8_t band_freq_to_channel(uint32_t freq, enum band_freq *out_band)
uint32_t band_channel_to_freq(uint8_t channel, enum band_freq band)
{
+ unsigned int i;
+ uint32_t freq = 0;
+
if (band == BAND_FREQ_2_4_GHZ) {
if (channel >= 1 && channel <= 13)
- return 2407 + 5 * channel;
+ freq = 2407 + 5 * channel;
+ else if (channel == 14)
+ freq = 2484;
- if (channel == 14)
- return 2484;
+ goto check_e4;
}
if (band == BAND_FREQ_5_GHZ) {
if (channel >= 1 && channel <= 179)
- return 5000 + 5 * channel;
+ freq = 5000 + 5 * channel;
+ else if (channel >= 181 && channel <= 199)
+ freq = 4000 + 5 * channel;
- if (channel >= 181 && channel <= 199)
- return 4000 + 5 * channel;
+ goto check_e4;
}
if (band == BAND_FREQ_6_GHZ) {
/* operating class 136 */
- if (channel == 2)
- return 5935;
+ if (channel == 2) {
+ freq = 5935;
+ goto check_e4;
+ }
/* Channels increment by 4, starting with 1 */
if (channel % 4 != 1)
@@ -1293,7 +1399,17 @@ uint32_t band_channel_to_freq(uint8_t channel, enum band_freq band)
return 0;
/* operating classes 131, 132, 133, 134, 135 */
- return 5950 + 5 * channel;
+ freq = 5950 + 5 * channel;
+ }
+
+check_e4:
+ for (i = 0; i < L_ARRAY_SIZE(e4_operating_classes); i++) {
+ const struct operating_class_info *info =
+ &e4_operating_classes[i];
+
+ if (e4_has_frequency(info, freq) == 0 ||
+ e4_has_ccfi(info, freq) == 0)
+ return freq;
}
return 0;
@@ -1422,3 +1538,23 @@ enum band_freq band_oper_class_to_band(const uint8_t *country,
else
return 0;
}
+
+const char *band_chandef_width_to_string(enum band_chandef_width width)
+{
+ switch (width) {
+ case BAND_CHANDEF_WIDTH_20NOHT:
+ return "20MHz (no-HT)";
+ case BAND_CHANDEF_WIDTH_20:
+ return "20MHz";
+ case BAND_CHANDEF_WIDTH_40:
+ return "40MHz";
+ case BAND_CHANDEF_WIDTH_80:
+ return "80MHz";
+ case BAND_CHANDEF_WIDTH_80P80:
+ return "80+80MHz";
+ case BAND_CHANDEF_WIDTH_160:
+ return "160MHz";
+ }
+
+ return NULL;
+}
diff --git a/src/band.h b/src/band.h
@@ -56,9 +56,15 @@ struct band_he_capabilities {
};
struct band_freq_attrs {
+ uint8_t tx_power;
bool supported : 1;
bool disabled : 1;
bool no_ir : 1;
+ bool no_ht40_plus : 1;
+ bool no_ht40_minus : 1;
+ bool no_80mhz : 1;
+ bool no_160mhz : 1;
+ bool no_he : 1;
} __attribute__ ((packed));
struct band {
@@ -72,6 +78,7 @@ struct band {
bool vht_supported : 1;
uint8_t ht_mcs_set[16];
uint8_t ht_capabilities[2];
+ uint8_t ht_ampdu_params;
bool ht_supported : 1;
uint16_t supported_rates_len;
uint8_t supported_rates[];
@@ -95,6 +102,8 @@ int band_estimate_nonht_rate(const struct band *band,
const uint8_t *supported_rates,
const uint8_t *ext_supported_rates,
int32_t rssi, uint64_t *out_data_rate);
+int band_freq_to_ht_chandef(uint32_t freq, const struct band_freq_attrs *attr,
+ struct band_chandef *chandef);
int oci_to_frequency(uint32_t operating_class, uint32_t channel);
@@ -105,3 +114,4 @@ uint8_t band_freq_to_channel(uint32_t freq, enum band_freq *out_band);
uint32_t band_channel_to_freq(uint8_t channel, enum band_freq band);
enum band_freq band_oper_class_to_band(const uint8_t *country,
uint8_t oper_class);
+const char *band_chandef_width_to_string(enum band_chandef_width width);
diff --git a/src/eap-peap.c b/src/eap-peap.c
@@ -468,7 +468,8 @@ static void eap_extensions_handle_request(struct eap_state *eap,
}
static bool eap_peap_tunnel_ready(struct eap_state *eap,
- const char *peer_identity)
+ const char *peer_identity,
+ bool resumed)
{
struct peap_state *peap_state = eap_tls_common_get_variant_data(eap);
@@ -480,6 +481,15 @@ static bool eap_peap_tunnel_ready(struct eap_state *eap,
*/
eap_discard_success_and_failure(eap, true);
+ /*
+ * In case of a resumed session, the server will typically not run
+ * phase2 methods at all, but will instead send a result TLV right
+ * away. Treat this like a successful phase2. In case the server
+ * does proceed with phase2, the success/failure state will be updated.
+ */
+ if (resumed)
+ eap_method_success(peap_state->phase2);
+
/* MSK, EMSK and challenge derivation */
eap_tls_common_tunnel_prf_get_bytes(eap, true, "client EAP encryption",
peap_state->key, 128);
diff --git a/src/eap-tls-common.c b/src/eap-tls-common.c
@@ -244,6 +244,7 @@ static void eap_tls_tunnel_ready(const char *peer_identity, void *user_data)
{
struct eap_state *eap = user_data;
struct eap_tls_state *eap_tls = eap_get_data(eap);
+ bool resumed = l_tls_get_session_resumed(eap_tls->tunnel);
if (eap_tls->ca_cert && !peer_identity) {
l_error("%s: TLS did not verify AP identity",
@@ -264,7 +265,7 @@ static void eap_tls_tunnel_ready(const char *peer_identity, void *user_data)
if (!eap_tls->variant_ops->tunnel_ready)
return;
- if (!eap_tls->variant_ops->tunnel_ready(eap, peer_identity))
+ if (!eap_tls->variant_ops->tunnel_ready(eap, peer_identity, resumed))
l_tls_close(eap_tls->tunnel);
}
diff --git a/src/eap-tls-common.h b/src/eap-tls-common.h
@@ -33,7 +33,8 @@ enum eap_tls_version {
struct eap_tls_variant_ops {
enum eap_tls_version version_max_supported;
- bool (*tunnel_ready)(struct eap_state *eap, const char *peer_identity);
+ bool (*tunnel_ready)(struct eap_state *eap, const char *peer_identity,
+ bool resumed);
bool (*tunnel_handle_request)(struct eap_state *eap,
const uint8_t *data, size_t data_len);
void (*reset)(void *variant_data);
diff --git a/src/eap-tls.c b/src/eap-tls.c
@@ -35,7 +35,8 @@
#include "src/eap-tls-common.h"
static bool eap_tls_tunnel_ready(struct eap_state *eap,
- const char *peer_identity)
+ const char *peer_identity,
+ bool resumed)
{
uint8_t msk_emsk[128];
uint8_t iv[64];
diff --git a/src/eap-ttls.c b/src/eap-ttls.c
@@ -902,7 +902,8 @@ static const struct phase2_method_ops phase2_eap_ops = {
};
static bool eap_ttls_tunnel_ready(struct eap_state *eap,
- const char *peer_identity)
+ const char *peer_identity,
+ bool resumed)
{
struct phase2_method *phase2 = eap_tls_common_get_variant_data(eap);
uint8_t msk_emsk[128];
diff --git a/src/eapol.c b/src/eapol.c
@@ -512,8 +512,7 @@ bool eapol_verify_ptk_2_of_4(const struct eapol_key *ek, bool ptk_complete)
if (!ek->key_mic)
return false;
- if (ek->secure != ptk_complete)
- return false;
+ L_WARN_ON(ek->secure != ptk_complete);
if (ek->encrypted_key_data)
return false;
@@ -766,11 +765,12 @@ struct eapol_key *eapol_create_ptk_2_of_4(
size_t extra_len,
const uint8_t *extra_data,
bool is_wpa,
- size_t mic_len)
+ size_t mic_len,
+ bool secure)
{
- return eapol_create_common(protocol, version, false, key_replay_counter,
- snonce, extra_len, extra_data, 1,
- is_wpa, mic_len);
+ return eapol_create_common(protocol, version, secure,
+ key_replay_counter, snonce, extra_len,
+ extra_data, 1, is_wpa, mic_len);
}
struct eapol_key *eapol_create_ptk_4_of_4(
@@ -1086,8 +1086,6 @@ static void eapol_send_ptk_1_of_4(struct eapol_sm *sm)
handshake_state_new_anonce(sm->handshake);
- sm->handshake->ptk_complete = false;
-
sm->replay_counter++;
memset(ek, 0, EAPOL_FRAME_LEN(sm->mic_len));
@@ -1111,6 +1109,13 @@ static void eapol_send_ptk_1_of_4(struct eapol_sm *sm)
eapol_key_data_append(ek, sm->mic_len, HANDSHAKE_KDE_PMKID, pmkid, 16);
+ if (sm->handshake->ptk_complete) {
+ sm->rekey = true;
+ sm->handshake->ptk_complete = false;
+ }
+
+ ek->secure = sm->rekey;
+
ek->header.packet_len = L_CPU_TO_BE16(EAPOL_FRAME_LEN(sm->mic_len) +
EAPOL_KEY_DATA_LEN(ek, sm->mic_len) - 4);
@@ -1326,7 +1331,8 @@ static void eapol_handle_ptk_1_of_4(struct eapol_sm *sm,
ek->key_descriptor_version,
L_BE64_TO_CPU(ek->key_replay_counter),
sm->handshake->snonce, ies_len, ies,
- sm->handshake->wpa_ie, sm->mic_len);
+ sm->handshake->wpa_ie, sm->mic_len,
+ sm->rekey);
kck = handshake_state_get_kck(sm->handshake);
@@ -1553,7 +1559,7 @@ static void eapol_handle_ptk_2_of_4(struct eapol_sm *sm,
l_debug("ifindex=%u", sm->handshake->ifindex);
- if (!eapol_verify_ptk_2_of_4(ek, sm->handshake->ptk_complete))
+ if (!eapol_verify_ptk_2_of_4(ek, sm->rekey))
return;
if (L_BE64_TO_CPU(ek->key_replay_counter) != sm->replay_counter)
@@ -1605,12 +1611,18 @@ static void eapol_handle_ptk_2_of_4(struct eapol_sm *sm,
sm->handshake->support_ip_allocation = ip_req_kde != NULL;
}
+ /*
+ * If the snonce is already set don't reset the retry counter as this
+ * is a rekey. To be safe take the most recent snonce (in this frame)
+ * in case the station created a new one.
+ */
+ if (!sm->handshake->have_snonce)
+ sm->frame_retry = 0;
+
memcpy(sm->handshake->snonce, ek->key_nonce,
sizeof(sm->handshake->snonce));
sm->handshake->have_snonce = true;
- sm->frame_retry = 0;
-
eapol_ptk_3_of_4_retry(NULL, sm);
}
@@ -2444,6 +2456,8 @@ static void eapol_eap_complete_cb(enum eap_result result, void *user_data)
/* sm->mic_len will have been set in eapol_eap_results_cb */
+ sm->frame_retry = 0;
+
/* Kick off 4-Way Handshake */
eapol_ptk_1_of_4_retry(NULL, sm);
}
@@ -2835,6 +2849,8 @@ bool eapol_start(struct eapol_sm *sm)
if (L_WARN_ON(!sm->handshake->have_pmk))
return false;
+ sm->frame_retry = 0;
+
/* Kick off handshake */
eapol_ptk_1_of_4_retry(NULL, sm);
}
diff --git a/src/eapol.h b/src/eapol.h
@@ -83,7 +83,8 @@ struct eapol_key *eapol_create_ptk_2_of_4(
size_t extra_len,
const uint8_t *extra_data,
bool is_wpa,
- size_t mic_len);
+ size_t mic_len,
+ bool secure);
struct eapol_key *eapol_create_ptk_4_of_4(
enum eapol_protocol_version protocol,
diff --git a/src/handshake.h b/src/handshake.h
@@ -60,6 +60,7 @@ enum handshake_event {
HANDSHAKE_EVENT_EAP_NOTIFY,
HANDSHAKE_EVENT_TRANSITION_DISABLE,
HANDSHAKE_EVENT_P2P_IP_REQUEST,
+ HANDSHAKE_EVENT_REKEY_COMPLETE,
};
typedef void (*handshake_event_func_t)(struct handshake_state *hs,
diff --git a/src/iwd.ap.rst b/src/iwd.ap.rst
@@ -67,6 +67,12 @@ The group ``[General]`` contains general AP configuration.
ensure the country is set, and that the desired frequency/channel is
unrestricted.
+ * - RekeyTimeout
+ - Timeout for PTK rekeys (seconds)
+
+ The time interval at which the AP starts a rekey for a given station. If
+ not provided a default value of 0 is used (rekeying is disabled).
+
Network Authentication Settings
-------------------------------
diff --git a/src/manager.c b/src/manager.c
@@ -320,13 +320,18 @@ static void manager_setup_cmd_done(void *user_data)
static void manager_del_interface_cb(struct l_genl_msg *msg, void *user_data)
{
struct wiphy_setup_state *state = user_data;
+ int err;
l_debug("");
if (state->aborted)
return;
- if (l_genl_msg_get_error(msg) < 0) {
+ err = l_genl_msg_get_error(msg);
+
+ if (err == -ENODEV)
+ return;
+ else if (err < 0) {
l_error("DEL_INTERFACE failed: %s",
strerror(-l_genl_msg_get_error(msg)));
state->use_default = true;
diff --git a/src/netconfig.c b/src/netconfig.c
@@ -413,7 +413,7 @@ mdns:
}
if (!success)
- goto check_config;
+ goto route_priority;
}
if (!mdns && mdns_global) {
@@ -426,7 +426,10 @@ mdns:
}
}
-check_config:
+route_priority:
+ l_netconfig_set_route_priority(netconfig->nc, ROUTE_PRIORITY_OFFSET);
+ l_netconfig_set_optimistic_dad_enabled(netconfig->nc, true);
+
if (!l_netconfig_check_config(netconfig->nc)) {
l_error("netconfig: Invalid configuration");
success = false;
@@ -734,9 +737,6 @@ struct netconfig *netconfig_new(uint32_t ifindex)
l_icmp6_client_set_debug(icmp6, do_debug, "[ICMPv6] ", NULL);
}
- l_netconfig_set_route_priority(netconfig->nc, ROUTE_PRIORITY_OFFSET);
- l_netconfig_set_optimistic_dad_enabled(netconfig->nc, true);
-
return netconfig;
}
diff --git a/src/netdev.c b/src/netdev.c
@@ -1469,8 +1469,13 @@ static void netdev_setting_keys_failed(struct netdev_handshake_state *nhs,
static void try_handshake_complete(struct netdev_handshake_state *nhs)
{
- if (nhs->ptk_installed && nhs->gtk_installed && nhs->igtk_installed &&
- !nhs->complete) {
+ if (nhs->ptk_installed && nhs->gtk_installed && nhs->igtk_installed) {
+ if (nhs->complete) {
+ handshake_event(&nhs->super,
+ HANDSHAKE_EVENT_REKEY_COMPLETE);
+ return;
+ }
+
nhs->complete = true;
if (handshake_event(&nhs->super, HANDSHAKE_EVENT_COMPLETE))
@@ -2024,6 +2029,8 @@ static void netdev_set_tk(struct handshake_state *hs, uint8_t key_index,
const uint8_t *addr = netdev_choose_key_address(nhs);
int err;
+ nhs->ptk_installed = false;
+
/*
* WPA1 does the group handshake after the 4-way finishes so we can't
* rely on the gtk/igtk being set immediately after the ptk. Since
diff --git a/src/nl80211util.c b/src/nl80211util.c
@@ -533,6 +533,24 @@ int nl80211_parse_supported_frequencies(struct l_genl_attr *band_freqs,
case NL80211_FREQUENCY_ATTR_NO_IR:
freq_attr.no_ir = true;
break;
+ case NL80211_FREQUENCY_ATTR_NO_HT40_MINUS:
+ freq_attr.no_ht40_minus = true;
+ break;
+ case NL80211_FREQUENCY_ATTR_NO_HT40_PLUS:
+ freq_attr.no_ht40_plus = true;
+ break;
+ case NL80211_FREQUENCY_ATTR_NO_80MHZ:
+ freq_attr.no_80mhz = true;
+ break;
+ case NL80211_FREQUENCY_ATTR_NO_160MHZ:
+ freq_attr.no_160mhz = true;
+ break;
+ case NL80211_FREQUENCY_ATTR_NO_HE:
+ freq_attr.no_he = true;
+ break;
+ case NL80211_FREQUENCY_ATTR_MAX_TX_POWER:
+ freq_attr.tx_power = *((uint32_t *) data) / 100;
+ break;
}
}
diff --git a/src/station.c b/src/station.c
@@ -1017,6 +1017,7 @@ static void station_handshake_event(struct handshake_state *hs,
case HANDSHAKE_EVENT_SETTING_KEYS_FAILED:
case HANDSHAKE_EVENT_EAP_NOTIFY:
case HANDSHAKE_EVENT_P2P_IP_REQUEST:
+ case HANDSHAKE_EVENT_REKEY_COMPLETE:
/*
* currently we don't care about any other events. The
* netdev_connect_cb will notify us when the connection is
@@ -2305,6 +2306,11 @@ static bool station_fast_transition(struct station *station,
vendor_ies = network_info_get_extra_ies(info, bss, &iov_elems);
handshake_state_set_vendor_ies(hs, vendor_ies, iov_elems);
+ if (station->roam_trigger_timeout) {
+ l_timeout_remove(station->roam_trigger_timeout);
+ station->roam_trigger_timeout = NULL;
+ }
+
/* Both ft_action/ft_authenticate will gate the associate work item */
if ((hs->mde[4] & 1))
ft_action(netdev_get_ifindex(station->netdev),
@@ -2707,6 +2713,29 @@ static void station_start_roam(struct station *station)
station_roam_failed(station);
}
+static bool station_cannot_roam(struct station *station)
+{
+ const struct l_settings *config = iwd_get_config();
+ bool disabled;
+
+ /*
+ * Disable roaming with hardware that can roam automatically. Note this
+ * is now required for recent kernels which have CQM event support on
+ * this type of hardware (e.g. brcmfmac).
+ */
+ if (wiphy_supports_firmware_roam(station->wiphy))
+ return true;
+
+ if (!l_settings_get_bool(config, "Scan", "DisableRoamingScan",
+ &disabled))
+ disabled = false;
+
+ return disabled || station->preparing_roam ||
+ station->state == STATION_STATE_ROAMING ||
+ station->state == STATION_STATE_FT_ROAMING ||
+ station->ft_work.id;
+}
+
static void station_roam_trigger_cb(struct l_timeout *timeout, void *user_data)
{
struct station *station = user_data;
@@ -2716,6 +2745,9 @@ static void station_roam_trigger_cb(struct l_timeout *timeout, void *user_data)
l_timeout_remove(station->roam_trigger_timeout);
station->roam_trigger_timeout = NULL;
+ if (station_cannot_roam(station))
+ return;
+
station_start_roam(station);
}
@@ -2741,28 +2773,6 @@ static void station_roam_timeout_rearm(struct station *station, int seconds)
station, NULL);
}
-static bool station_cannot_roam(struct station *station)
-{
- const struct l_settings *config = iwd_get_config();
- bool disabled;
-
- /*
- * Disable roaming with hardware that can roam automatically. Note this
- * is now required for recent kernels which have CQM event support on
- * this type of hardware (e.g. brcmfmac).
- */
- if (wiphy_supports_firmware_roam(station->wiphy))
- return true;
-
- if (!l_settings_get_bool(config, "Scan", "DisableRoamingScan",
- &disabled))
- disabled = false;
-
- return disabled || station->preparing_roam ||
- station->state == STATION_STATE_ROAMING ||
- station->state == STATION_STATE_FT_ROAMING;
-}
-
#define WNM_REQUEST_MODE_PREFERRED_CANDIDATE_LIST (1 << 0)
#define WNM_REQUEST_MODE_DISASSOCIATION_IMMINENT (1 << 2)
#define WNM_REQUEST_MODE_TERMINATION_IMMINENT (1 << 3)
diff --git a/src/wiphy.c b/src/wiphy.c
@@ -105,8 +105,6 @@ struct wiphy {
uint16_t supported_iftypes;
uint16_t supported_ciphers;
struct scan_freq_set *supported_freqs;
- struct scan_freq_set *disabled_freqs;
- struct scan_freq_set *pending_freqs;
struct band *band_2g;
struct band *band_5g;
struct band *band_6g;
@@ -139,6 +137,7 @@ struct wiphy {
bool registered : 1;
bool self_managed : 1;
bool ap_probe_resp_offload : 1;
+ bool supports_uapsd : 1;
};
static struct l_queue *wiphy_list = NULL;
@@ -345,7 +344,6 @@ static struct wiphy *wiphy_new(uint32_t id)
wiphy->id = id;
wiphy->supported_freqs = scan_freq_set_new();
- wiphy->disabled_freqs = scan_freq_set_new();
watchlist_init(&wiphy->state_watches, NULL);
wiphy->extended_capabilities[0] = IE_TYPE_EXTENDED_CAPABILITIES;
wiphy->extended_capabilities[1] = EXT_CAP_LEN;
@@ -393,7 +391,6 @@ static void wiphy_free(void *data)
}
scan_freq_set_free(wiphy->supported_freqs);
- scan_freq_set_free(wiphy->disabled_freqs);
watchlist_destroy(&wiphy->state_watches);
l_free(wiphy->model_str);
l_free(wiphy->vendor_str);
@@ -491,11 +488,6 @@ const struct scan_freq_set *wiphy_get_supported_freqs(
return wiphy->supported_freqs;
}
-const struct scan_freq_set *wiphy_get_disabled_freqs(const struct wiphy *wiphy)
-{
- return wiphy->disabled_freqs;
-}
-
static struct band *wiphy_get_band(const struct wiphy *wiphy, enum band_freq band)
{
switch (band) {
@@ -534,6 +526,23 @@ const struct band_freq_attrs *wiphy_get_frequency_info(
return attr;
}
+const struct band_freq_attrs *wiphy_get_frequency_info_list(
+ const struct wiphy *wiphy,
+ enum band_freq band,
+ size_t *size)
+{
+ struct band *bandp;
+
+ bandp = wiphy_get_band(wiphy, band);
+ if (!bandp)
+ return NULL;
+
+ if (size)
+ *size = bandp->freqs_len;
+
+ return bandp->freq_attrs;
+}
+
bool wiphy_band_is_disabled(const struct wiphy *wiphy, enum band_freq band)
{
struct band_freq_attrs attr;
@@ -919,6 +928,47 @@ bool wiphy_country_is_unknown(struct wiphy *wiphy)
(cc[0] == 'X' && cc[1] == 'X'));
}
+bool wiphy_supports_uapsd(const struct wiphy *wiphy)
+{
+ return wiphy->supports_uapsd;
+}
+
+const uint8_t *wiphy_get_ht_capabilities(const struct wiphy *wiphy,
+ enum band_freq band,
+ size_t *size)
+{
+ static uint8_t ht_capa[26];
+ const struct band *bandp = wiphy_get_band(wiphy, band);
+
+ if (!bandp)
+ return NULL;
+
+ if (!bandp->ht_supported)
+ return NULL;
+
+ memset(ht_capa, 0, sizeof(ht_capa));
+
+ /*
+ * The kernel segments the HT capabilities element into multiple
+ * attributes. For convenience on the caller just combine them and
+ * return the full IE rather than adding 3 separate getters. This also
+ * provides a way to check if HT is supported.
+ */
+ memcpy(ht_capa, bandp->ht_capabilities, 2);
+ ht_capa[2] = bandp->ht_ampdu_params;
+ memcpy(ht_capa + 3, bandp->ht_mcs_set, 16);
+
+ /*
+ * TODO: HT Extended capabilities, beamforming, and ASEL capabilities
+ * are not available to get from the kernel, leave as zero.
+ */
+
+ if (size)
+ *size = sizeof(ht_capa);
+
+ return ht_capa;
+}
+
int wiphy_estimate_data_rate(struct wiphy *wiphy,
const void *ies, uint16_t ies_len,
const struct scan_bss *bss,
@@ -1626,6 +1676,23 @@ static void parse_supported_bands(struct wiphy *wiphy,
memcpy(band->ht_capabilities, data, len);
band->ht_supported = true;
break;
+ /*
+ * AMPDU factor/density are part of A-MPDU Parameters,
+ * 802.11-2020 Section 9.4.2.55.3.
+ */
+ case NL80211_BAND_ATTR_HT_AMPDU_FACTOR:
+ if (L_WARN_ON(len != 1))
+ continue;
+
+ band->ht_ampdu_params |= l_get_u8(data) & 0x3;
+ break;
+ case NL80211_BAND_ATTR_HT_AMPDU_DENSITY:
+ if (L_WARN_ON(len != 1))
+ continue;
+
+ band->ht_ampdu_params |=
+ (l_get_u8(data) & 0x7) << 2;
+ break;
case NL80211_BAND_ATTR_IFTYPE_DATA:
if (!l_genl_attr_recurse(&attr, &nested))
continue;
@@ -1786,6 +1853,9 @@ static void wiphy_parse_attributes(struct wiphy *wiphy,
case NL80211_ATTR_PROBE_RESP_OFFLOAD:
wiphy->ap_probe_resp_offload = true;
break;
+ case NL80211_ATTR_SUPPORT_AP_UAPSD:
+ wiphy->supports_uapsd = true;
+ break;
}
}
}
@@ -2009,9 +2079,6 @@ static void wiphy_dump_done(void *user_data)
if (wiphy) {
wiphy->dump_id = 0;
- scan_freq_set_free(wiphy->disabled_freqs);
- wiphy->disabled_freqs = wiphy->pending_freqs;
- wiphy->pending_freqs = NULL;
WATCHLIST_NOTIFY(&wiphy->state_watches,
wiphy_state_watch_func_t, wiphy,
@@ -2025,13 +2092,9 @@ static void wiphy_dump_done(void *user_data)
for (e = l_queue_get_entries(wiphy_list); e; e = e->next) {
wiphy = e->data;
- if (!wiphy->pending_freqs || wiphy->self_managed)
+ if (wiphy->self_managed)
continue;
- scan_freq_set_free(wiphy->disabled_freqs);
- wiphy->disabled_freqs = wiphy->pending_freqs;
- wiphy->pending_freqs = NULL;
-
WATCHLIST_NOTIFY(&wiphy->state_watches,
wiphy_state_watch_func_t, wiphy,
WIPHY_STATE_WATCH_EVENT_REGDOM_DONE);
@@ -2101,33 +2164,18 @@ static void wiphy_dump_callback(struct l_genl_msg *msg,
static bool wiphy_cancel_last_dump(struct wiphy *wiphy)
{
- const struct l_queue_entry *e;
unsigned int id = 0;
/*
* Zero command ID to signal that wiphy_dump_done doesn't need to do
- * anything. For a self-managed wiphy just free/NULL pending_freqs. For
- * a global dump each wiphy needs to be checked and dealt with.
+ * anything.
*/
if (wiphy && wiphy->dump_id) {
id = wiphy->dump_id;
wiphy->dump_id = 0;
-
- scan_freq_set_free(wiphy->pending_freqs);
- wiphy->pending_freqs = NULL;
} else if (!wiphy && wiphy_dump_id) {
id = wiphy_dump_id;
wiphy_dump_id = 0;
-
- for (e = l_queue_get_entries(wiphy_list); e; e = e->next) {
- struct wiphy *w = e->data;
-
- if (!w->pending_freqs || w->self_managed)
- continue;
-
- scan_freq_set_free(w->pending_freqs);
- w->pending_freqs = NULL;
- }
}
if (id) {
@@ -2172,7 +2220,6 @@ static void wiphy_dump_after_regdom(struct wiphy *wiphy)
/* Limited dump so just emit the event for this wiphy */
if (wiphy) {
wiphy->dump_id = id;
- wiphy->pending_freqs = scan_freq_set_new();
if (no_start_event)
return;
@@ -2192,8 +2239,6 @@ static void wiphy_dump_after_regdom(struct wiphy *wiphy)
if (w->self_managed)
continue;
- w->pending_freqs = scan_freq_set_new();
-
if (no_start_event)
continue;
@@ -2285,6 +2330,15 @@ static void wiphy_get_reg_domain(struct wiphy *wiphy)
void wiphy_create_complete(struct wiphy *wiphy)
{
+ /*
+ * With really bad timing two wiphy dumps can occur (initial and a
+ * NEW_WIPHY event) and actually register twice. Ignoring/preventing the
+ * second dump is problematic since it _could_ be a legitimate event so
+ * instead just prevent it from registering twice.
+ */
+ if (wiphy->registered)
+ return;
+
wiphy_register(wiphy);
if (l_memeqzero(wiphy->permanent_addr, 6)) {
diff --git a/src/wiphy.h b/src/wiphy.h
@@ -100,11 +100,15 @@ const char *wiphy_get_path(struct wiphy *wiphy);
uint32_t wiphy_get_supported_bands(struct wiphy *wiphy);
const struct scan_freq_set *wiphy_get_supported_freqs(
const struct wiphy *wiphy);
-const struct scan_freq_set *wiphy_get_disabled_freqs(const struct wiphy *wiphy);
const struct band_freq_attrs *wiphy_get_frequency_info(
const struct wiphy *wiphy,
uint32_t freq);
+const struct band_freq_attrs *wiphy_get_frequency_info_list(
+ const struct wiphy *wiphy,
+ enum band_freq band,
+ size_t *size);
+
bool wiphy_band_is_disabled(const struct wiphy *wiphy, enum band_freq band);
bool wiphy_supports_probe_resp_offload(struct wiphy *wiphy);
@@ -138,7 +142,11 @@ const uint8_t *wiphy_get_rm_enabled_capabilities(struct wiphy *wiphy);
bool wiphy_get_rsnxe(const struct wiphy *wiphy, uint8_t *buf, size_t len);
void wiphy_get_reg_domain_country(struct wiphy *wiphy, char *out);
bool wiphy_country_is_unknown(struct wiphy *wiphy);
+bool wiphy_supports_uapsd(const struct wiphy *wiphy);
+const uint8_t *wiphy_get_ht_capabilities(const struct wiphy *wiphy,
+ enum band_freq band,
+ size_t *size);
void wiphy_generate_random_address(struct wiphy *wiphy, uint8_t addr[static 6]);
void wiphy_generate_address_from_ssid(struct wiphy *wiphy, const char *ssid,
uint8_t addr[static 6]);
diff --git a/unit/test-band.c b/unit/test-band.c
@@ -644,12 +644,32 @@ static void test_6ghz_freqs(const void *data)
uint32_t i;
enum band_freq band;
- for (i = 5955; i < 7115; i += 5) {
+ for (i = 5955; i < 7115; i += 20) {
assert(band_freq_to_channel(i, &band) != 0);
assert(band == BAND_FREQ_6_GHZ);
}
}
+static void test_conversions(const void *data)
+{
+ /*
+ * Test a few invalid channels/frequencies that appear valid but are
+ * not in the E-4 table. The checks in band.c seem to cover 2.4Ghz and
+ * 6Ghz very well since there are no gaps, but the 5GHz band has some
+ * segmentation.
+ */
+
+ /* Gap in 5GHz channels between 68 and 96 */
+ assert(!band_channel_to_freq(72, BAND_FREQ_5_GHZ));
+ assert(!band_freq_to_channel(5360, NULL));
+
+ /* Invalid channel using 4000mhz starting frequency */
+ assert(!band_channel_to_freq(183, BAND_FREQ_5_GHZ));
+ assert(!band_freq_to_channel(4915, NULL));
+
+ assert(!band_channel_to_freq(192, BAND_FREQ_5_GHZ));
+}
+
int main(int argc, char *argv[])
{
l_test_init(&argc, &argv);
@@ -715,5 +735,7 @@ int main(int argc, char *argv[])
l_test_add("/band/6ghz/channels", test_6ghz_channels, NULL);
l_test_add("/band/6ghz/freq", test_6ghz_freqs, NULL);
+ l_test_add("/band/conversions", test_conversions, NULL);
+
return l_test_run();
}
diff --git a/unit/test-eapol.c b/unit/test-eapol.c
@@ -1793,7 +1793,7 @@ static void eapol_4way_test(const void *data)
eapol_key_test_4.key_replay_counter,
snonce, eapol_key_test_4.key_data_len,
eapol_key_data_4 + EAPOL_FRAME_LEN(16),
- false, 16);
+ false, 16, false);
assert(frame);
assert(eapol_calculate_mic(IE_RSN_AKM_SUITE_PSK, ptk, frame,
mic, 16));
@@ -1878,7 +1878,7 @@ static void eapol_wpa2_handshake_test(const void *data)
eapol_key_test_8.key_replay_counter,
snonce, eapol_key_test_8.key_data_len,
eapol_key_data_8 + EAPOL_FRAME_LEN(16),
- false, 16);
+ false, 16, false);
assert(frame);
assert(eapol_calculate_mic(IE_RSN_AKM_SUITE_PSK, ptk, frame,
mic, 16));
@@ -2008,7 +2008,7 @@ static void eapol_wpa_handshake_test(const void *data)
eapol_key_test_14.key_replay_counter,
snonce, eapol_key_test_14.key_data_len,
eapol_key_data_14 + EAPOL_FRAME_LEN(16),
- true, 16);
+ true, 16, false);
assert(frame);
assert(eapol_calculate_mic(IE_RSN_AKM_SUITE_PSK, ptk, frame,
mic, 16));