]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
P2P: Update listen and operating channel from P2P D-Bus
authorJayant Sane <jayant.sane@intel.com>
Sat, 25 Jun 2011 09:08:43 +0000 (12:08 +0300)
committerJouni Malinen <j@w1.fi>
Sat, 25 Jun 2011 09:08:43 +0000 (12:08 +0300)
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 <jean-michelx.bachot@intel.com>
Signed-off-by: Jayant Sane <jayant.sane@intel.com>
src/p2p/p2p.c
src/p2p/p2p.h
wpa_supplicant/config.h
wpa_supplicant/dbus/dbus_new_handlers_p2p.c
wpa_supplicant/p2p_supplicant.c

index 380db64778cad8dea74cb636f2909aa7b4d202de..191099a5c5cf4194eecbffc6a853c5fcf075351b 100644 (file)
@@ -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)
 {
index 28357b59444a625421738d3a200a83ddfc1fca24..db816a62cafe04ae51df35ff5a79293b45da0544 100644 (file)
@@ -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 */
index c370362114ebfcaa8b458899efb4b8dfc67d6682..10abdad51111588f98187d0a7d67029250e6476d 100644 (file)
@@ -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
index 61f41b85504a350046909d7de54bfda897902e22..3fec3083ba827d23eb313c862d2c23038f65b6b3 100644 (file)
@@ -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)
index d4ec261bb0eeee826f0afa2f39987467d76891a6..550173a2fc842a57aacec70cd0a024e9ac4dab3e 100644 (file)
@@ -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);
+       }
 }