[PATCH 6/6] P2P: update listen and operating channel from p2p dbus

Sane, Jayant jayant.sane
Thu Jun 9 09:41:05 PDT 2011


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
function.

Signed-off-by: Jean-Michel.Bachot <jean-michelx.bachot at intel.com>
Signed-off-by: Jayant Sane <jayant.sane at intel.com>
---
Note: This patch set applies on top of earlier submitted "DBus-add-support-for-P2P" series 
of patches

 src/p2p/p2p.c                               |   16 ++++++++
 src/p2p/p2p.h                               |   13 +++++++
 wpa_supplicant/config.h                     |    4 ++
 wpa_supplicant/dbus/dbus_new_handlers_p2p.c |   20 ++++++++--
 wpa_supplicant/p2p_supplicant.c             |   52 +++++++++++++++++++++++++++
 5 files changed, 101 insertions(+), 4 deletions(-)

diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c
index 063e04c..eee6fcb 100644
--- a/src/p2p/p2p.c
+++ b/src/p2p/p2p.c
@@ -3392,6 +3392,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 bfe7c57..41491b4 100644
--- a/src/p2p/p2p.h
+++ b/src/p2p/p2p.h
@@ -1496,4 +1496,17 @@ 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 operating channel and
+ * operating regulatory class
+ * @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
+ *
+ */
+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 c370362..a3fbbd7 100644
--- a/wpa_supplicant/config.h
+++ b/wpa_supplicant/config.h
@@ -44,6 +44,10 @@
 #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_REG_CLASS BIT(11)
+#define CFG_CHANGED_P2P_LISTEN_CHANNEL BIT(12)
+#define CFG_CHANGED_P2P_OPER_REG_CLASS BIT(13)
+#define CFG_CHANGED_P2P_OPER_CHANNEL BIT(14)
 
 /**
  * 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 48d776e..ff7adca 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
+++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c
@@ -858,20 +858,32 @@ 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;
+			wpa_s->conf->changed_parameters |=
+					CFG_CHANGED_P2P_LISTEN_REG_CLASS;
+		}
 
 		else if ((os_strcmp(entry.key, "ListenChannel") == 0) &&
-			 (entry.type == DBUS_TYPE_UINT32))
+			 (entry.type == DBUS_TYPE_UINT32)) {
 			wpa_s->conf->p2p_listen_channel = entry.uint32_value;
+			wpa_s->conf->changed_parameters |=
+					CFG_CHANGED_P2P_LISTEN_CHANNEL;
+		}
 
 		else if ((os_strcmp(entry.key, "OperRegClass") == 0) &&
-			 (entry.type == DBUS_TYPE_UINT32))
+			 (entry.type == DBUS_TYPE_UINT32)) {
 			wpa_s->conf->p2p_oper_reg_class = entry.uint32_value;
+			wpa_s->conf->changed_parameters |=
+					CFG_CHANGED_P2P_OPER_REG_CLASS;
+		}
 
 		else if ((os_strcmp(entry.key, "OperChannel") == 0) &&
-			 (entry.type == DBUS_TYPE_UINT32))
+			 (entry.type == DBUS_TYPE_UINT32)) {
 			wpa_s->conf->p2p_oper_channel = entry.uint32_value;
+			wpa_s->conf->changed_parameters |=
+					CFG_CHANGED_P2P_OPER_CHANNEL;
+		}
 
 		else if (os_strcmp(entry.key, "SsidPostfix") == 0) {
 			char *postfix;
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index 6233167..148336b 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -4035,6 +4035,58 @@ 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)
+	    || (wpa_s->conf->changed_parameters
+		& CFG_CHANGED_P2P_LISTEN_REG_CLASS)) {
+		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)
+	    || (wpa_s->conf->changed_parameters
+		& CFG_CHANGED_P2P_OPER_REG_CLASS)) {
+		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);
+	}
 }
 
 
-- 
1.7.1





More information about the Hostap mailing list