From b5c9da8db3c3fa981c9236d918d46a56a1766ffd Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 15 Oct 2010 18:55:22 +0300 Subject: [PATCH] P2P: Add mechanism for updating P2P channel list based on driver events This allows P2P channel list to be updated whenever the driver changes its list of allowed channels, e.g., based on country code from scan results. --- src/drivers/driver.h | 11 ++++++++++- src/p2p/p2p.c | 7 +++++++ src/p2p/p2p.h | 2 ++ wpa_supplicant/events.c | 5 +++++ wpa_supplicant/p2p_supplicant.c | 18 ++++++++++++++++++ wpa_supplicant/p2p_supplicant.h | 1 + 6 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/drivers/driver.h b/src/drivers/driver.h index 90b3902b4..9a0b7be03 100644 --- a/src/drivers/driver.h +++ b/src/drivers/driver.h @@ -2203,7 +2203,16 @@ enum wpa_event_type { * This event is used to indicate that the interface was disabled, * e.g., due to rfkill. */ - EVENT_INTERFACE_DISABLED + EVENT_INTERFACE_DISABLED, + + /** + * EVENT_CHANNEL_LIST_CHANGED - Channel list changed + * + * This event is used to indicate that the channel list has changed, + * e.g., because of a regulatory domain change triggered by scan + * results including an AP advertising a country code. + */ + EVENT_CHANNEL_LIST_CHANGED }; diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c index 122c12177..81a2a8e1d 100644 --- a/src/p2p/p2p.c +++ b/src/p2p/p2p.c @@ -3036,3 +3036,10 @@ void p2p_set_intra_bss_dist(struct p2p_data *p2p, int enabled) enabled ? "enabled" : "disabled"); p2p->cfg->p2p_intra_bss = enabled; } + + +void p2p_update_channel_list(struct p2p_data *p2p, struct p2p_channels *chan) +{ + wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: Update channel list"); + os_memcpy(&p2p->cfg->channels, chan, sizeof(struct p2p_channels)); +} diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h index 502ad8de7..af5f9b580 100644 --- a/src/p2p/p2p.h +++ b/src/p2p/p2p.h @@ -1263,4 +1263,6 @@ void p2p_set_intra_bss_dist(struct p2p_data *p2p, int enabled); */ int p2p_supported_freq(struct p2p_data *p2p, unsigned int freq); +void p2p_update_channel_list(struct p2p_data *p2p, struct p2p_channels *chan); + #endif /* P2P_H */ diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c index 602f992c2..76ee93b22 100644 --- a/wpa_supplicant/events.c +++ b/wpa_supplicant/events.c @@ -1829,6 +1829,11 @@ void wpa_supplicant_event(void *ctx, enum wpa_event_type event, wpa_supplicant_mark_disassoc(wpa_s); wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); break; + case EVENT_CHANNEL_LIST_CHANGED: +#ifdef CONFIG_P2P + wpas_p2p_update_channel_list(wpa_s); +#endif /* CONFIG_P2P */ + break; default: wpa_printf(MSG_INFO, "Unknown event %d", event); break; diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index 79b769149..f57e50c94 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -3599,3 +3599,21 @@ int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant *wpa_s) wpas_group_formation_completed(wpa_s, 0); return 1; } + + +void wpas_p2p_update_channel_list(struct wpa_supplicant *wpa_s) +{ + struct p2p_channels chan; + + if (wpa_s->global == NULL || wpa_s->global->p2p == NULL) + return; + + os_memset(&chan, 0, sizeof(chan)); + if (wpas_p2p_setup_channels(wpa_s, &chan)) { + wpa_printf(MSG_ERROR, "P2P: Failed to update supported " + "channel list"); + return; + } + + p2p_update_channel_list(wpa_s->global->p2p, &chan); +} diff --git a/wpa_supplicant/p2p_supplicant.h b/wpa_supplicant/p2p_supplicant.h index 363293af7..73c6e1a57 100644 --- a/wpa_supplicant/p2p_supplicant.h +++ b/wpa_supplicant/p2p_supplicant.h @@ -113,5 +113,6 @@ int wpas_p2p_set_cross_connect(struct wpa_supplicant *wpa_s, int enabled); void wpas_p2p_notif_connected(struct wpa_supplicant *wpa_s); void wpas_p2p_notif_disconnected(struct wpa_supplicant *wpa_s); int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant *wpa_s); +void wpas_p2p_update_channel_list(struct wpa_supplicant *wpa_s); #endif /* P2P_SUPPLICANT_H */