[PATCH] PR: Use preferred op_class and channel for PASN channel selection
Emily Xia
xiayucheng at google.com
Sun Nov 8 21:50:25 PST 2026
Currently the channel for proximity ranging is always selected
automatically from the common channel set using the best available
option. This gives no control to the caller over which operating class
or channel is used for ranging.
Add preferred_op_class and preferred_channel fields to
struct pr_pasn_ranging_params and support configuring them via
PR_PASN_START (preferred_op_class=<val> and preferred_channel=<val>).
When set, pr_get_preferred_channel() first checks for an exact match of
(preferred_op_class, preferred_channel) in the common channel set so
the caller's requested bandwidth is honored. Otherwise, it falls back
to selecting the highest bandwidth op_class in the common channel set
that contains preferred_channel within the same band (matching
is_6ghz_op_class() when preferred_op_class is provided). If the
preferred channel is not present in the common channel set, automatic
channel selection is used as a fallback.
Signed-off-by: Peddolla Harshavardhan Reddy <peddolla.reddy at oss.qualcomm.com>
Signed-off-by: Emily Xia <xiayucheng at google.com>
---
src/common/proximity_ranging.c | 118 ++++++++++++++++++++++++++++++++-
src/common/proximity_ranging.h | 2 +
wpa_supplicant/ctrl_iface.c | 4 ++
3 files changed, 121 insertions(+), 3 deletions(-)
diff --git a/src/common/proximity_ranging.c b/src/common/proximity_ranging.c
index b614693fa..f83a08569 100644
--- a/src/common/proximity_ranging.c
+++ b/src/common/proximity_ranging.c
@@ -609,6 +609,77 @@ static void pr_channels_intersect(const struct pr_channels *a,
}
}
+
+static bool pr_is_channel_in_list(const struct pr_channels *chan,
+ u8 op_class, u8 channel)
+{
+ size_t i, j;
+
+ for (i = 0; i < chan->op_classes; i++) {
+ if (chan->op_class[i].op_class != op_class)
+ continue;
+ for (j = 0; j < chan->op_class[i].channels; j++) {
+ if (chan->op_class[i].channel[j] == channel)
+ return true;
+ }
+ }
+ return false;
+}
+
+
+static bool pr_get_preferred_channel(u8 preferred_op_class,
+ u8 preferred_channel,
+ const struct pr_channels *common_chan,
+ u8 *op_class, u8 *op_channel)
+{
+ size_t i, j;
+ const struct oper_class_map *map;
+ u8 best_op_class = 0;
+ int best_bw = 0;
+
+ if (!preferred_channel || !common_chan || !op_class || !op_channel)
+ return false;
+
+ if (preferred_op_class &&
+ pr_is_channel_in_list(common_chan, preferred_op_class,
+ preferred_channel)) {
+ *op_class = preferred_op_class;
+ *op_channel = preferred_channel;
+ return true;
+ }
+
+ /* Fall back to picking the highest bandwidth op_class in common_chan
+ * containing preferred_channel within the same band.
+ */
+ for (i = 0; i < common_chan->op_classes; i++) {
+ const struct pr_op_class *op = &common_chan->op_class[i];
+
+ for (j = 0; j < op->channels; j++) {
+ if (op->channel[j] != preferred_channel)
+ continue;
+ if (preferred_op_class &&
+ is_6ghz_op_class(op->op_class) !=
+ is_6ghz_op_class(preferred_op_class))
+ break;
+ map = get_oper_class(NULL, op->op_class);
+ if (!map)
+ break;
+ if (oper_class_bw_to_int(map) > best_bw) {
+ best_bw = oper_class_bw_to_int(map);
+ best_op_class = op->op_class;
+ }
+ break;
+ }
+ }
+
+ if (!best_op_class)
+ return false;
+
+ *op_class = best_op_class;
+ *op_channel = preferred_channel;
+ return true;
+}
+
#endif /* CONFIG_PASN */
@@ -1409,6 +1480,7 @@ static u8 pr_pasn_get_best_op_mode(struct pr_data *pr, u8 peer_supp_roles,
int status = PR_NEGOTIATION_FAIL;
u8 op_class = 0, op_channel = 0;
bool own_ista_support = false, own_rsta_support = false;
+ bool preferred_found;
if (op_mode->protocol_type &
(PR_NTB_SECURE_LTF_BASED_RANGING | PR_NTB_OPEN_BASED_RANGING)) {
@@ -1510,11 +1582,25 @@ static u8 pr_pasn_get_best_op_mode(struct pr_data *pr, u8 peer_supp_roles,
res_op_mode->protocol_type = ranging_type;
os_memcpy(res_op_mode->country, pr->cfg->country, 3);
- if (res_op_mode->role == PR_RSTA_SUPPORT) {
+ preferred_found = pr->pr_pasn_params &&
+ (pr->pr_pasn_params->preferred_op_class ||
+ pr->pr_pasn_params->preferred_channel) &&
+ pr_get_preferred_channel(pr->pr_pasn_params->preferred_op_class,
+ pr->pr_pasn_params->preferred_channel,
+ &common_chan, &op_class, &op_channel);
+
+ if (!preferred_found && res_op_mode->role == PR_RSTA_SUPPORT) {
pr_copy_channels(&res_op_mode->channels, &common_chan,
pr->cfg->support_6ghz);
} else {
- pr_choose_best_channel(&common_chan, &op_class, &op_channel);
+ if (preferred_found) {
+ wpa_printf(MSG_DEBUG,
+ "PR: Using preferred op_class=%u, channel=%u",
+ op_class, op_channel);
+ } else {
+ pr_choose_best_channel(&common_chan, &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");
@@ -1614,7 +1700,18 @@ 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);
+ if (pr->pr_pasn_params &&
+ (pr->pr_pasn_params->preferred_op_class ||
+ pr->pr_pasn_params->preferred_channel) &&
+ pr_get_preferred_channel(pr->pr_pasn_params->preferred_op_class,
+ pr->pr_pasn_params->preferred_channel,
+ &common_chan, &op_class, &op_channel)) {
+ wpa_printf(MSG_DEBUG,
+ "PR: Using preferred op_class=%u, channel=%u",
+ op_class, op_channel);
+ } else {
+ pr_choose_best_channel(&common_chan, &op_class, &op_channel);
+ }
if (!op_class || !op_channel) {
wpa_printf(MSG_INFO,
"PR: Couldn't choose a common channel for ranging");
@@ -1647,6 +1744,7 @@ static int pr_prepare_pasn_pr_elem(struct pr_data *pr, struct wpabuf *extra_ies,
struct operation_mode op_mode;
struct pr_channels op_channels;
u8 forced_op_class = 0, forced_op_channel = 0;
+ u8 pref_op_class = 0, pref_op_channel = 0;
enum hostapd_hw_mode hw_mode;
buf = wpabuf_alloc(1000);
@@ -1674,6 +1772,20 @@ static int pr_prepare_pasn_pr_elem(struct pr_data *pr, struct wpabuf *extra_ies,
return -1;
}
+ if (pr->pr_pasn_params &&
+ (pr->pr_pasn_params->preferred_op_class ||
+ pr->pr_pasn_params->preferred_channel) &&
+ !forced_pr_freq) {
+ pref_op_class = pr->pr_pasn_params->preferred_op_class;
+ pref_op_channel = pr->pr_pasn_params->preferred_channel;
+ if (pref_op_class &&
+ !pr_is_channel_in_list(&op_channels, pref_op_class,
+ pref_op_channel))
+ wpa_printf(MSG_DEBUG,
+ "PR: preferred op_class %u, channel %u is not present in device channel list, ignoring",
+ pref_op_class, pref_op_channel);
+ }
+
os_memset(&op_mode, 0, sizeof(struct operation_mode));
op_mode.role = ranging_role;
op_mode.protocol_type = ranging_type;
diff --git a/src/common/proximity_ranging.h b/src/common/proximity_ranging.h
index 6ce9f6922..da4cca84a 100644
--- a/src/common/proximity_ranging.h
+++ b/src/common/proximity_ranging.h
@@ -364,6 +364,8 @@ struct pr_pasn_ranging_params {
u32 continuous_ranging_session_time;
int forced_pr_freq;
+ u8 preferred_op_class;
+ u8 preferred_channel;
u8 ranging_op_class;
u16 channel_width; /* channel width in MHz (20/40/80/160/320) */
u8 format_bw;
diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index 56535fd4e..fd52d449f 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -11725,6 +11725,10 @@ static int wpas_ctrl_iface_pr_pasn_start(struct wpa_supplicant *wpa_s,
params.auth_mode = atoi(token + 5);
} else if (os_strncmp(token, "forced_pr_freq=", 15) == 0) {
params.forced_pr_freq = atoi(token + 15);
+ } else if (os_strncmp(token, "preferred_op_class=", 19) == 0) {
+ params.preferred_op_class = atoi(token + 19);
+ } else if (os_strncmp(token, "preferred_channel=", 18) == 0) {
+ params.preferred_channel = atoi(token + 18);
} else if (os_strncmp(token, "num_bursts_exp=", 15) == 0) {
params.num_bursts_exp = atoi(token + 15);
} else if (os_strncmp(token, "ftmr_retries=", 13) == 0) {
--
2.56.0.455.g6c5a503b38-goog
More information about the Hostap
mailing list