Signed-off-by: Johannes Berg --- src/p2p/p2p.c | 6 ++++++ src/p2p/p2p.h | 9 +++++++++ wpa_supplicant/notify.c | 4 ++++ wpa_supplicant/notify.h | 1 + wpa_supplicant/p2p_supplicant.c | 8 ++++++++ 5 files changed, 28 insertions(+), 0 deletions(-) diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c index 2ce3f97..159bc0c 100644 --- a/src/p2p/p2p.c +++ b/src/p2p/p2p.c @@ -116,7 +116,13 @@ void p2p_set_state(struct p2p_data *p2p, int new_state) { wpa_msg(p2p->cfg->msg_ctx, MSG_DEBUG, "P2P: State %s -> %s", p2p_state_txt(p2p->state), p2p_state_txt(new_state)); + + if (p2p->state == new_state) + return; + p2p->state = new_state; + + p2p->cfg->state_changed(p2p->cfg->cb_ctx, new_state); } diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h index 58f8571..3218f4b 100644 --- a/src/p2p/p2p.h +++ b/src/p2p/p2p.h @@ -388,6 +388,15 @@ struct p2p_config { void (*stop_listen)(void *ctx); /** + * state_changed - State has changed + * @ctx: Callback context from cb_ctx + * @state: New state + * + * This callback is used to inform that state machine progressed + */ + void (*state_changed)(void *ctx, int state); + + /** * get_noa - Get current Notice of Absence attribute payload * @ctx: Callback context from cb_ctx * @interface_addr: P2P Interface Address of the GO diff --git a/wpa_supplicant/notify.c b/wpa_supplicant/notify.c index eef0d97..a202ba4 100644 --- a/wpa_supplicant/notify.c +++ b/wpa_supplicant/notify.c @@ -347,6 +347,10 @@ void wpas_notify_resume(struct wpa_global *global) } #ifdef CONFIG_P2P +void wpas_notify_p2p_state_changed(struct wpa_supplicant *wpa_s, int state) +{ +} + void wpas_notify_p2p_device_found(struct wpa_supplicant *wpa_s, const u8 *dev_addr, int new_device) { diff --git a/wpa_supplicant/notify.h b/wpa_supplicant/notify.h index 5fa15b8..e2d0663 100644 --- a/wpa_supplicant/notify.h +++ b/wpa_supplicant/notify.h @@ -78,6 +78,7 @@ void wpas_notify_debug_show_keys_changed(struct wpa_global *global); void wpas_notify_suspend(struct wpa_global *global); void wpas_notify_resume(struct wpa_global *global); +void wpas_notify_p2p_state_changed(struct wpa_supplicant *wpa_s, int state); void wpas_notify_p2p_device_found(struct wpa_supplicant *wpa_s, const u8 *dev_addr, int new_device); #endif /* NOTIFY_H */ diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index 3e60762..2f9a186 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -1189,6 +1189,13 @@ static void wpas_stop_listen(void *ctx) wpa_drv_probe_req_report(wpa_s, 0); } +static void wpas_state_changed(void *ctx, int state) +{ + struct wpa_supplicant *wpa_s = ctx; + + wpas_notify_p2p_state_changed(wpa_s, state); +} + static int wpas_send_probe_resp(void *ctx, const struct wpabuf *buf) { @@ -2321,6 +2328,7 @@ int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s) p2p.dev_found = wpas_dev_found; p2p.start_listen = wpas_start_listen; p2p.stop_listen = wpas_stop_listen; + p2p.state_changed = wpas_state_changed; p2p.send_probe_resp = wpas_send_probe_resp; p2p.sd_request = wpas_sd_request; p2p.sd_response = wpas_sd_response; -- 1.7.2.3