[PATCH] use PHY parameters from dbus or config for dbus command GroupAdd
Jintao Lin
jintaolin at chromium.org
Mon Dec 18 10:11:46 PST 2023
This change uses the PHY parameters from config or the value passed in
from the dbus API for P2P dbus command GroupAdd instead of using the
hard coded values to be inline with the method provided with wpa_cli.
This change also fixes a wrong parameter order when calling
wpas_p2p_group_add_persistent.
Signed-off-by: Jintao Lin <jintaolin at chromium.org>
---
doc/dbus.doxygen | 7 ++++
src/common/wpa_common.c | 31 ++++++++++++++
src/common/wpa_common.h | 1 +
wpa_supplicant/ctrl_iface.c | 37 +++--------------
wpa_supplicant/dbus/dbus_new_handlers_p2p.c | 46 ++++++++++++++++++---
5 files changed, 86 insertions(+), 36 deletions(-)
diff --git a/doc/dbus.doxygen b/doc/dbus.doxygen
index 17d4df06a..ee3b0ca2c 100644
--- a/doc/dbus.doxygen
+++ b/doc/dbus.doxygen
@@ -1600,6 +1600,13 @@ Interface for performing P2P (Wi-Fi Peer-to-Peer) P2P Device operations.
<tr><td>persistent_group_object</td><td>o</td><td></td><td>no</td></tr>
<tr><td>frequency</td><td>i</td><td>Operating frequency in MHz</td><td>no</td></tr>
<tr><td>retry_limit</td><td>i</td><td>Optional limit on the number of scan attempts to join a group</td><td>no</td></tr>
+ <tr><td>ht40</td><td>b</td><td></td><td>no</td></tr>
+ <tr><td>vht</td><td>b</td><td></td><td>no</td></tr>
+ <tr><td>he</td><td>b</td><td></td><td>no</td></tr>
+ <tr><td>edmg</td><td>b</td><td></td><td>no</td></tr>
+ <tr><td>allow_6ghz</td><td>b</td><td></td><td>no</td></tr>
+ <tr><td>freq2</td><td>i</td><td>Center frequency for freq2 when operates in 80MHz + 80MHz mode</td><td>no</td></tr>
+ <tr><td>max_oper_chwidth</td><td>i</td><td>Max operating channel width(20, 40, 80, 160, 320)</td><td>no</td></tr>
</table>
</dd>
</dl>
diff --git a/src/common/wpa_common.c b/src/common/wpa_common.c
index d897e0eca..da2e2ad5b 100644
--- a/src/common/wpa_common.c
+++ b/src/common/wpa_common.c
@@ -3767,6 +3767,37 @@ int wpa_parse_kde_ies(const u8 *buf, size_t len, struct wpa_eapol_ie_parse *ie)
return ret;
}
+/**
+ * wpa_parse_chwidth - Parse channel width
+ * @chwidth: Channel width integer
+ * @freq2: Value for frequency 2. 0 is not used
+ * Returns: enum oper_chan_width, -1 on failure
+ */
+int wpa_parse_chwidth(int chwidth, int freq2)
+{
+ if (freq2 < 0)
+ return -1;
+ if (freq2)
+ return CONF_OPER_CHWIDTH_80P80MHZ;
+
+ switch (chwidth) {
+ case 0:
+ case 20:
+ case 40:
+ return CONF_OPER_CHWIDTH_USE_HT;
+ case 80:
+ return CONF_OPER_CHWIDTH_80MHZ;
+ case 160:
+ return CONF_OPER_CHWIDTH_160MHZ;
+ case 320:
+ return CONF_OPER_CHWIDTH_320MHZ;
+ default:
+ wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d",
+ chwidth);
+ return -1;
+ }
+}
+
#ifdef CONFIG_PASN
diff --git a/src/common/wpa_common.h b/src/common/wpa_common.h
index 1269bf95d..dd0069462 100644
--- a/src/common/wpa_common.h
+++ b/src/common/wpa_common.h
@@ -733,6 +733,7 @@ int wpa_cipher_put_suites(u8 *pos, int ciphers);
int wpa_pick_pairwise_cipher(int ciphers, int none_allowed);
int wpa_pick_group_cipher(int ciphers);
int wpa_parse_cipher(const char *value);
+int wpa_parse_chwidth(int chwidth, int freq2);
int wpa_write_ciphers(char *start, char *end, int ciphers, const char *delim);
int wpa_select_ap_group_cipher(int wpa, int wpa_pairwise, int rsn_pairwise);
unsigned int wpa_mic_len(int akmp, size_t pmk_len);
diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index f3ea97e6f..314dafd58 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -18,6 +18,7 @@
#include "common/version.h"
#include "common/ieee802_11_defs.h"
#include "common/ieee802_11_common.h"
+#include "common/wpa_common.h"
#include "common/wpa_ctrl.h"
#ifdef CONFIG_DPP
#include "common/dpp.h"
@@ -6289,32 +6290,6 @@ static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
}
-static int parse_freq(int chwidth, int freq2)
-{
- if (freq2 < 0)
- return -1;
- if (freq2)
- return CONF_OPER_CHWIDTH_80P80MHZ;
-
- switch (chwidth) {
- case 0:
- case 20:
- case 40:
- return CONF_OPER_CHWIDTH_USE_HT;
- case 80:
- return CONF_OPER_CHWIDTH_80MHZ;
- case 160:
- return CONF_OPER_CHWIDTH_160MHZ;
- case 320:
- return CONF_OPER_CHWIDTH_320MHZ;
- default:
- wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d",
- chwidth);
- return -1;
- }
-}
-
-
static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
char *buf, size_t buflen)
{
@@ -6408,7 +6383,7 @@ static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
if (pos2)
chwidth = atoi(pos2 + 18);
- max_oper_chwidth = parse_freq(chwidth, freq2);
+ max_oper_chwidth = wpa_parse_chwidth(chwidth, freq2);
if (max_oper_chwidth < 0)
return -1;
@@ -7062,7 +7037,7 @@ static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
if (pos)
chwidth = atoi(pos + 18);
- max_oper_chwidth = parse_freq(chwidth, freq2);
+ max_oper_chwidth = wpa_parse_chwidth(chwidth, freq2);
if (max_oper_chwidth < 0)
return -1;
@@ -7138,8 +7113,8 @@ static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
return -1;
}
- return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq,
- vht_center_freq2, 0, ht40, vht,
+ return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0,
+ vht_center_freq2, ht40, vht,
vht_chwidth, he, edmg,
NULL, 0, 0, allow_6ghz, 0,
go_bssid);
@@ -7217,7 +7192,7 @@ static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
}
#endif /* CONFIG_ACS */
- max_oper_chwidth = parse_freq(chwidth, freq2);
+ max_oper_chwidth = wpa_parse_chwidth(chwidth, freq2);
if (max_oper_chwidth < 0)
return -1;
diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
index a178d879e..ad5d47462 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
+++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
@@ -21,6 +21,7 @@
#include "dbus_dict_helpers.h"
#include "p2p/p2p.h"
#include "common/ieee802_11_defs.h"
+#include "common/wpa_common.h"
#include "ap/hostapd.h"
#include "ap/ap_config.h"
#include "ap/wps_hostapd.h"
@@ -360,6 +361,12 @@ DBusMessage * wpas_dbus_handler_p2p_group_add(DBusMessage *message,
unsigned int group_id = 0;
struct wpa_ssid *ssid;
u8 go_bssid_buf[ETH_ALEN], *go_bssid = NULL;
+ bool allow_6ghz = false;
+ int vht = wpa_s->conf->p2p_go_vht;
+ int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
+ int he = wpa_s->conf->p2p_go_he;
+ int edmg = wpa_s->conf->p2p_go_edmg;
+ int max_oper_chwidth, chwidth = 0, freq2 = 0;
dbus_message_iter_init(message, &iter);
@@ -392,6 +399,28 @@ DBusMessage * wpas_dbus_handler_p2p_group_add(DBusMessage *message,
if (hwaddr_aton(entry.str_value, go_bssid_buf))
goto inv_args_clear;
go_bssid = go_bssid_buf;
+ } else if (os_strcmp(entry.key, "ht40") == 0 &&
+ entry.type == DBUS_TYPE_BOOLEAN) {
+ ht40 = entry.bool_value;
+ } else if (os_strcmp(entry.key, "vht") == 0 &&
+ entry.type == DBUS_TYPE_BOOLEAN) {
+ vht = entry.bool_value;
+ ht40 |= vht;
+ } else if (os_strcmp(entry.key, "he") == 0 &&
+ entry.type == DBUS_TYPE_BOOLEAN) {
+ he = entry.bool_value;
+ } else if (os_strcmp(entry.key, "edmg") == 0 &&
+ entry.type == DBUS_TYPE_BOOLEAN) {
+ edmg = entry.bool_value;
+ } else if (os_strcmp(entry.key, "allow_6ghz") == 0 &&
+ entry.type == DBUS_TYPE_BOOLEAN) {
+ allow_6ghz = entry.bool_value;
+ } else if (os_strcmp(entry.key, "freq2") == 0 &&
+ entry.type == DBUS_TYPE_INT32) {
+ freq2 = entry.int32_value;
+ } else if (os_strcmp(entry.key, "max_oper_chwidth") == 0 &&
+ entry.type == DBUS_TYPE_INT32) {
+ chwidth = entry.int32_value;
} else {
goto inv_args_clear;
}
@@ -399,6 +428,13 @@ DBusMessage * wpas_dbus_handler_p2p_group_add(DBusMessage *message,
wpa_dbus_dict_entry_clear(&entry);
}
+ max_oper_chwidth = wpa_parse_chwidth(chwidth, freq2);
+ if (max_oper_chwidth < 0)
+ goto inv_args;
+
+ if (allow_6ghz && chwidth == 40)
+ max_oper_chwidth = CONF_OPER_CHWIDTH_40MHZ_6GHZ;
+
wpa_s = wpa_s->global->p2p_init_wpa_s;
if (!wpa_s) {
reply = wpas_dbus_error_no_p2p_mgmt_iface(message);
@@ -437,17 +473,17 @@ DBusMessage * wpas_dbus_handler_p2p_group_add(DBusMessage *message,
if (ssid == NULL || ssid->disabled != 2)
goto inv_args;
- if (wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0, 0, 0,
- 0, 0, 0, 0, NULL, 0, 0,
- false, retry_limit,
+ if (wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0,
+ freq2, ht40, vht, max_oper_chwidth, he,
+ edmg, NULL, 0, 0, allow_6ghz, retry_limit,
go_bssid)) {
reply = wpas_dbus_error_unknown_error(
message,
"Failed to reinvoke a persistent group");
goto out;
}
- } else if (wpas_p2p_group_add(wpa_s, persistent_group, freq, 0, 0, 0,
- 0, 0, 0, false))
+ } else if (wpas_p2p_group_add(wpa_s, persistent_group, freq, freq2, ht40,
+ vht, max_oper_chwidth, he, edmg, allow_6ghz))
goto inv_args;
out:
--
2.43.0.472.g3155946c3a-goog
More information about the Hostap
mailing list