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 <jean-michelx.bachot@intel.com>
Signed-off-by: Jayant Sane <jayant.sane@intel.com>
This commit is contained in:
Jayant Sane 2011-06-25 12:08:43 +03:00 committed by Jouni Malinen
parent 3734552f15
commit 2463ba70e2
5 changed files with 93 additions and 12 deletions

View 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)
{

View 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 */

View 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

View 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)

View 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);
}
}