From 2463ba70e298dd4dcae382c7596204085d0448ad Mon Sep 17 00:00:00 2001 From: Jayant Sane Date: Sat, 25 Jun 2011 12:08:43 +0300 Subject: [PATCH] P2P: Update listen and operating channel from P2P D-Bus Some P2PDevice properties were not updated in p2p->cfg structure: reg_class, channel, op_reg_class, and op_channel. Hence, update p2p->cfg parameters through p2p core calls in wpas_p2p_update_config(). Signed-off-by: Jean-Michel.Bachot Signed-off-by: Jayant Sane --- src/p2p/p2p.c | 16 +++++++ src/p2p/p2p.h | 11 +++++ wpa_supplicant/config.h | 2 + wpa_supplicant/dbus/dbus_new_handlers_p2p.c | 28 ++++++------ wpa_supplicant/p2p_supplicant.c | 48 +++++++++++++++++++++ 5 files changed, 93 insertions(+), 12 deletions(-) diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c index 380db6477..191099a5c 100644 --- a/src/p2p/p2p.c +++ b/src/p2p/p2p.c @@ -3428,6 +3428,22 @@ int p2p_set_ssid_postfix(struct p2p_data *p2p, const u8 *postfix, size_t len) } +int p2p_set_oper_channel(struct p2p_data *p2p, u8 op_reg_class, u8 op_channel, + int cfg_op_channel) +{ + if (p2p_channel_to_freq(p2p->cfg->country, op_reg_class, op_channel) + < 0) + return -1; + + wpa_msg(p2p->cfg->msg_ctx, MSG_INFO, "P2P: Set Operating channel: " + "reg_class %u channel %u", op_reg_class, op_channel); + p2p->cfg->op_reg_class = op_reg_class; + p2p->cfg->op_channel = op_channel; + p2p->cfg->cfg_op_channel = cfg_op_channel; + return 0; +} + + int p2p_get_interface_addr(struct p2p_data *p2p, const u8 *dev_addr, u8 *iface_addr) { diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h index 28357b594..db816a62c 100644 --- a/src/p2p/p2p.h +++ b/src/p2p/p2p.h @@ -1496,4 +1496,15 @@ void p2p_remove_wps_vendor_extensions(struct p2p_data *p2p); int p2p_add_wps_vendor_extension(struct p2p_data *p2p, const struct wpabuf *vendor_ext); +/** + * p2p_set_oper_channel - Set the P2P operating channel + * @p2p: P2P module context from p2p_init() + * @op_reg_class: Operating regulatory class to set + * @op_channel: operating channel to set + * @cfg_op_channel : Whether op_channel is hardcoded in configuration + * Returns: 0 on success, -1 on failure + */ +int p2p_set_oper_channel(struct p2p_data *p2p, u8 op_reg_class, u8 op_channel, + int cfg_op_channel); + #endif /* P2P_H */ diff --git a/wpa_supplicant/config.h b/wpa_supplicant/config.h index c37036211..10abdad51 100644 --- a/wpa_supplicant/config.h +++ b/wpa_supplicant/config.h @@ -44,6 +44,8 @@ #define CFG_CHANGED_WPS_STRING BIT(8) #define CFG_CHANGED_P2P_INTRA_BSS BIT(9) #define CFG_CHANGED_VENDOR_EXTENSION BIT(10) +#define CFG_CHANGED_P2P_LISTEN_CHANNEL BIT(11) +#define CFG_CHANGED_P2P_OPER_CHANNEL BIT(12) /** * struct wpa_config - wpa_supplicant configuration data diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c index 61f41b855..3fec3083b 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c +++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c @@ -876,22 +876,26 @@ DBusMessage *wpas_dbus_setter_p2p_device_properties(DBusMessage * message, wpa_s->conf->persistent_reconnect = entry.bool_value; else if ((os_strcmp(entry.key, "ListenRegClass") == 0) && - (entry.type == DBUS_TYPE_UINT32)) + (entry.type == DBUS_TYPE_UINT32)) { wpa_s->conf->p2p_listen_reg_class = entry.uint32_value; - - else if ((os_strcmp(entry.key, "ListenChannel") == 0) && - (entry.type == DBUS_TYPE_UINT32)) + wpa_s->conf->changed_parameters |= + CFG_CHANGED_P2P_LISTEN_CHANNEL; + } else if ((os_strcmp(entry.key, "ListenChannel") == 0) && + (entry.type == DBUS_TYPE_UINT32)) { wpa_s->conf->p2p_listen_channel = entry.uint32_value; - - else if ((os_strcmp(entry.key, "OperRegClass") == 0) && - (entry.type == DBUS_TYPE_UINT32)) + wpa_s->conf->changed_parameters |= + CFG_CHANGED_P2P_LISTEN_CHANNEL; + } else if ((os_strcmp(entry.key, "OperRegClass") == 0) && + (entry.type == DBUS_TYPE_UINT32)) { wpa_s->conf->p2p_oper_reg_class = entry.uint32_value; - - else if ((os_strcmp(entry.key, "OperChannel") == 0) && - (entry.type == DBUS_TYPE_UINT32)) + wpa_s->conf->changed_parameters |= + CFG_CHANGED_P2P_OPER_CHANNEL; + } else if ((os_strcmp(entry.key, "OperChannel") == 0) && + (entry.type == DBUS_TYPE_UINT32)) { wpa_s->conf->p2p_oper_channel = entry.uint32_value; - - else if (os_strcmp(entry.key, "SsidPostfix") == 0) { + wpa_s->conf->changed_parameters |= + CFG_CHANGED_P2P_OPER_CHANNEL; + } else if (os_strcmp(entry.key, "SsidPostfix") == 0) { char *postfix; if (entry.type != DBUS_TYPE_STRING) diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index d4ec261bb..550173a2f 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -4011,6 +4011,54 @@ void wpas_p2p_update_config(struct wpa_supplicant *wpa_s) if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_INTRA_BSS) p2p_set_intra_bss_dist(p2p, wpa_s->conf->p2p_intra_bss); + + if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_LISTEN_CHANNEL) { + u8 reg_class, channel; + int ret; + unsigned int r; + if (wpa_s->conf->p2p_listen_reg_class && + wpa_s->conf->p2p_listen_channel) { + reg_class = wpa_s->conf->p2p_listen_reg_class; + channel = wpa_s->conf->p2p_listen_channel; + } else { + reg_class = 81; + /* + * Pick one of the social channels randomly as the + * listen channel. + */ + os_get_random((u8 *) &r, sizeof(r)); + channel = 1 + (r % 3) * 5; + } + ret = p2p_set_listen_channel(p2p, reg_class, channel); + if (ret) + wpa_printf(MSG_ERROR, "P2P: Own listen channel update " + "failed: %d", ret); + } + if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_OPER_CHANNEL) { + u8 op_reg_class, op_channel, cfg_op_channel; + int ret = 0; + unsigned int r; + if (wpa_s->conf->p2p_oper_reg_class && + wpa_s->conf->p2p_oper_channel) { + op_reg_class = wpa_s->conf->p2p_oper_reg_class; + op_channel = wpa_s->conf->p2p_oper_channel; + cfg_op_channel = 1; + } else { + op_reg_class = 81; + /* + * Use random operation channel from (1, 6, 11) + *if no other preference is indicated. + */ + os_get_random((u8 *) &r, sizeof(r)); + op_channel = 1 + (r % 3) * 5; + cfg_op_channel = 0; + } + ret = p2p_set_oper_channel(p2p, op_reg_class, op_channel, + cfg_op_channel); + if (ret) + wpa_printf(MSG_ERROR, "P2P: Own oper channel update " + "failed: %d", ret); + } }