[PATCH] PR: Prefer STA operating channel for ranging channel selection
Emily Xia
xiayucheng at google.com
Tue Dec 1 22:06:15 PST 2026
pr_choose_best_channel() selects the common operating class with the
highest bandwidth and then always uses the first channel of that
operating class. It does not consider the channel on which the device
is already associated, so ranging often ends up on a different channel
than the STA-AP link. This forces multi-channel operation in firmware,
which adds latency and hurts ranging reliability.
Record the frequencies used by infrastructure station links (including
all MLO links sharing the radio) in struct pr_pasn_ranging_params when
PASN for proximity ranging is triggered. In pr_choose_best_channel(),
keep the existing maximum bandwidth selection and then prefer a channel
that matches one of these frequencies among the operating classes that
have that maximum bandwidth. Channels are compared by frequency so that
a channel number shared between the 5 GHz and 6 GHz bands cannot match
the wrong band.
Ranging accuracy is not traded for avoiding multi-channel operation: an
operating class with a lower bandwidth is never selected because of the
station frequency. If no channel with the maximum bandwidth matches, the
previous behavior of using the first channel is retained.
Signed-off-by: Emily Xia <xiayucheng at google.com>
---
src/common/proximity_ranging.c | 43 +++++++++++++++++++++++++++++++---
src/common/proximity_ranging.h | 4 ++++
wpa_supplicant/pr_supplicant.c | 33 ++++++++++++++++++++++++++
3 files changed, 77 insertions(+), 3 deletions(-)
diff --git a/src/common/proximity_ranging.c b/src/common/proximity_ranging.c
index 890ea993b..132451ad3 100644
--- a/src/common/proximity_ranging.c
+++ b/src/common/proximity_ranging.c
@@ -1376,12 +1376,14 @@ static void pr_process_op_mode(const u8 *caps, size_t caps_len,
static void pr_choose_best_channel(struct pr_channels *common_channel,
+ const struct pr_pasn_ranging_params *params,
u8 *op_class, u8 *op_channel)
{
int bw;
int max_bw = 0;
const struct oper_class_map *map;
- size_t i;
+ size_t i, j;
+ unsigned int k, num_sta_freqs = 0;
if (!common_channel || !common_channel->op_classes ||
!common_channel->op_class[0].channels) {
@@ -1405,6 +1407,39 @@ static void pr_choose_best_channel(struct pr_channels *common_channel,
}
}
+ if (params) {
+ num_sta_freqs = params->num_sta_freqs;
+ if (num_sta_freqs > PR_MAX_STA_FREQS)
+ num_sta_freqs = PR_MAX_STA_FREQS;
+ }
+
+ for (i = 0; num_sta_freqs && i < common_channel->op_classes; i++) {
+ const struct pr_op_class *op = &common_channel->op_class[i];
+
+ map = get_oper_class(NULL, op->op_class);
+ if (!map || oper_class_bw_to_int(map) != max_bw)
+ continue;
+
+ for (j = 0; j < op->channels; j++) {
+ int freq = ieee80211_chan_to_freq(NULL, op->op_class,
+ op->channel[j]);
+
+ if (freq <= 0)
+ continue;
+ for (k = 0; k < num_sta_freqs; k++) {
+ if (freq != params->sta_freqs[k])
+ continue;
+ *op_class = op->op_class;
+ *op_channel = op->channel[j];
+ wpa_printf(MSG_DEBUG,
+ "PR: Prefer station operating frequency %d MHz",
+ freq);
+ goto done;
+ }
+ }
+ }
+
+done:
wpa_printf(MSG_DEBUG,
"PR: Choose the operating class: %u, operating channel: %u",
*op_class, *op_channel);
@@ -1526,7 +1561,8 @@ static u8 pr_pasn_get_best_op_mode(struct pr_data *pr, u8 peer_supp_roles,
pr_copy_channels(&res_op_mode->channels, &common_chan,
pr->cfg->support_6ghz);
} else {
- pr_choose_best_channel(&common_chan, &op_class, &op_channel);
+ pr_choose_best_channel(&common_chan, pr->pr_pasn_params,
+ &op_class, &op_channel);
if (!op_class || !op_channel) {
wpa_printf(MSG_DEBUG,
"PR: Couldn't choose a common channel for ranging in ISTA role");
@@ -1626,7 +1662,8 @@ static u8 pr_pasn_get_final_op_mode(struct pr_data *pr, u8 supp_roles,
return PR_NEGOTIATION_FAIL;
}
- pr_choose_best_channel(&common_chan, &op_class, &op_channel);
+ pr_choose_best_channel(&common_chan, pr->pr_pasn_params, &op_class,
+ &op_channel);
if (!op_class || !op_channel) {
wpa_printf(MSG_INFO,
"PR: Couldn't choose a common channel for ranging");
diff --git a/src/common/proximity_ranging.h b/src/common/proximity_ranging.h
index 6ce9f6922..9b86461c8 100644
--- a/src/common/proximity_ranging.h
+++ b/src/common/proximity_ranging.h
@@ -39,6 +39,8 @@ struct ieee80211_mgmt;
*/
#define PR_MAX_PEER 100
+#define PR_MAX_STA_FREQS 4
+
/*
* Proximity Ranging negotiation status
* Proximity Ranging Implementation Considerations for P2P Operation D1.8,
@@ -364,6 +366,8 @@ struct pr_pasn_ranging_params {
u32 continuous_ranging_session_time;
int forced_pr_freq;
+ int sta_freqs[PR_MAX_STA_FREQS];
+ unsigned int num_sta_freqs;
u8 ranging_op_class;
u16 channel_width; /* channel width in MHz (20/40/80/160/320) */
u8 format_bw;
diff --git a/wpa_supplicant/pr_supplicant.c b/wpa_supplicant/pr_supplicant.c
index 391e4ef33..856d9a248 100644
--- a/wpa_supplicant/pr_supplicant.c
+++ b/wpa_supplicant/pr_supplicant.c
@@ -1632,6 +1632,38 @@ wpas_pr_validate_ranging_request(struct wpa_supplicant *wpa_s,
}
+static void wpas_pr_set_sta_freqs(struct wpa_supplicant *wpa_s,
+ struct pr_pasn_ranging_params *params)
+{
+ struct wpa_used_freq_data *freqs;
+ unsigned int len = wpa_s->num_multichan_concurrent;
+ int i, num;
+
+ params->num_sta_freqs = 0;
+ os_memset(params->sta_freqs, 0, sizeof(params->sta_freqs));
+
+ if (!len)
+ return;
+
+ freqs = os_calloc(len, sizeof(*freqs));
+ if (!freqs)
+ return;
+
+ num = get_shared_radio_freqs_data(wpa_s, freqs, len, false);
+ for (i = 0; i < num && params->num_sta_freqs < PR_MAX_STA_FREQS; i++) {
+ if (freqs[i].freq <= 0 ||
+ !(freqs[i].flags & WPA_FREQ_USED_BY_INFRA_STATION))
+ continue;
+ wpa_printf(MSG_DEBUG,
+ "PR PASN: Station operating frequency hint %d MHz",
+ freqs[i].freq);
+ params->sta_freqs[params->num_sta_freqs++] = freqs[i].freq;
+ }
+
+ os_free(freqs);
+}
+
+
/**
* wpas_pr_pasn_trigger - Entry point to trigger PASN authentication for PR
*/
@@ -1685,6 +1717,7 @@ int wpas_pr_pasn_trigger(struct wpa_supplicant *wpa_s,
os_memcpy(pr->pr_pasn_params, pr_pasn_params,
sizeof(*pr->pr_pasn_params));
+ wpas_pr_set_sta_freqs(wpa_s, pr->pr_pasn_params);
/* Ensure peer device entry exists before setting credentials */
if (pr_pasn_params->pmk_len > 0 ||
--
2.56.1.911.g883d8bcb20-goog
More information about the Hostap
mailing list