diff mbox

[1/3] wpa_supplicant: abort scan after removing all networks

Message ID 1351502021-10795-1-git-send-email-david.spinadel@intel.com
State Changes Requested
Headers show

Commit Message

Spinadel, David Oct. 29, 2012, 9:13 a.m. UTC
From: David Spinadel <david.spinadel@intel.com>

Change-Id: I737848dabed49d961985845f2e86f717c2926f0c
Reviewed-on: http://git-mwg.jer.intel.com/gerrit/3585
Reviewed-by: Jenkins
Tested-by: Jenkins
Reviewed-by: Max Stepanov <Max.Stepanov@intel.com>
Tested-by: Max Stepanov <Max.Stepanov@intel.com>
Signed-off-by: David Spinadel <david.spinadel@intel.com>
---
 wpa_supplicant/ctrl_iface.c             |    7 +++++++
 wpa_supplicant/dbus/dbus_new_handlers.c |    8 ++++++++
 wpa_supplicant/dbus/dbus_old_handlers.c |    5 +++++
 wpa_supplicant/wps_supplicant.c         |    5 +++++
 4 files changed, 25 insertions(+), 0 deletions(-)

Comments

Eyal Shapira Oct. 30, 2012, 7:21 a.m. UTC | #1
On 29 October 2012 11:13,  <david.spinadel@intel.com> wrote:
> From: David Spinadel <david.spinadel@intel.com>
>
> Change-Id: I737848dabed49d961985845f2e86f717c2926f0c
> Reviewed-on: http://git-mwg.jer.intel.com/gerrit/3585
> Reviewed-by: Jenkins
> Tested-by: Jenkins
> Reviewed-by: Max Stepanov <Max.Stepanov@intel.com>
> Tested-by: Max Stepanov <Max.Stepanov@intel.com>
> Signed-off-by: David Spinadel <david.spinadel@intel.com>
> ---
>  wpa_supplicant/ctrl_iface.c             |    7 +++++++
>  wpa_supplicant/dbus/dbus_new_handlers.c |    8 ++++++++
>  wpa_supplicant/dbus/dbus_old_handlers.c |    5 +++++
>  wpa_supplicant/wps_supplicant.c         |    5 +++++
>  4 files changed, 25 insertions(+), 0 deletions(-)
>
> diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
> index 0351241..d1a5cf6 100644
> --- a/wpa_supplicant/ctrl_iface.c
> +++ b/wpa_supplicant/ctrl_iface.c
> @@ -2224,6 +2224,8 @@ static int wpa_supplicant_ctrl_iface_remove_network(
>         /* cmd: "<network id>" or "all" */
>         if (os_strcmp(cmd, "all") == 0) {
>                 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
> +               wpa_supplicant_cancel_sched_scan(wpa_s);
> +               wpa_supplicant_cancel_scan(wpa_s);
>                 ssid = wpa_s->conf->ssid;
>                 while (ssid) {
>                         struct wpa_ssid *remove_ssid = ssid;
> @@ -2281,6 +2283,11 @@ static int wpa_supplicant_ctrl_iface_remove_network(
>                 return -1;
>         }
>
> +       if (!wpa_s->conf->ssid) {
> +               wpa_supplicant_cancel_sched_scan(wpa_s);
> +               wpa_supplicant_cancel_scan(wpa_s);
> +       }
> +
>         return 0;
>  }
>
> diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c
> index 00378be..b0f0d0e 100644
> --- a/wpa_supplicant/dbus/dbus_new_handlers.c
> +++ b/wpa_supplicant/dbus/dbus_new_handlers.c
> @@ -1525,6 +1525,11 @@ DBusMessage * wpas_dbus_handler_remove_network(DBusMessage *message,
>                 wpa_supplicant_deauthenticate(wpa_s,
>                                               WLAN_REASON_DEAUTH_LEAVING);
>
> +       if (!wpa_s->conf->ssid) {
> +               wpa_supplicant_cancel_sched_scan(wpa_s);
> +               wpa_supplicant_cancel_scan(wpa_s);
> +       }
> +
>  out:
>         os_free(iface);
>         os_free(net_id);
> @@ -1562,6 +1567,9 @@ static void remove_network(void *arg, struct wpa_ssid *ssid)
>  DBusMessage * wpas_dbus_handler_remove_all_networks(
>         DBusMessage *message, struct wpa_supplicant *wpa_s)
>  {
> +       wpa_supplicant_cancel_sched_scan(wpa_s);
> +       wpa_supplicant_cancel_scan(wpa_s);
> +
>         /* NB: could check for failure and return an error */
>         wpa_config_foreach_network(wpa_s->conf, remove_network, wpa_s);
>         return NULL;
> diff --git a/wpa_supplicant/dbus/dbus_old_handlers.c b/wpa_supplicant/dbus/dbus_old_handlers.c
> index e217a72..ff60f6e 100644
> --- a/wpa_supplicant/dbus/dbus_old_handlers.c
> +++ b/wpa_supplicant/dbus/dbus_old_handlers.c
> @@ -870,6 +870,11 @@ DBusMessage * wpas_dbus_iface_remove_network(DBusMessage *message,
>                                               WLAN_REASON_DEAUTH_LEAVING);
>         reply = wpas_dbus_new_success_reply(message);
>
> +       if (!wpa_s->conf->ssid) {
> +               wpa_supplicant_cancel_sched_scan(wpa_s);
> +               wpa_supplicant_cancel_scan(wpa_s);
> +       }
> +
>  out:
>         os_free(iface);
>         os_free(net_id);
> diff --git a/wpa_supplicant/wps_supplicant.c b/wpa_supplicant/wps_supplicant.c
> index 41aa5db..87ea320 100644
> --- a/wpa_supplicant/wps_supplicant.c
> +++ b/wpa_supplicant/wps_supplicant.c
> @@ -759,6 +759,11 @@ static void wpas_clear_wps(struct wpa_supplicant *wpa_s)
>         }
>
>         wpas_wps_clear_ap_info(wpa_s);
> +
> +       if (!wpa_s->conf->ssid) {
> +               wpa_supplicant_cancel_sched_scan(wpa_s);
> +               wpa_supplicant_cancel_scan(wpa_s);
> +       }
>  }

wpa_supplicant_scan wouldn't do anything if you haven't got any
enabled networks so the cancel_scan() is a bit moot. no ?

Regarding sched scan, I think the more correct behavior is to restart
sched scan whenever the enabled networks list change (e.g.
enable/disable/remove)
as otherwise we'd continue to sched scan a non relevant list of SSIDs.
This would also take care of removing all networks given
that we bail out in wpa_supplicant_req_sched_scan if there aren't any
enabled networks.
I have some internal patches on our tree doing something like this but
they need some work to be rebased on the latetest master.
If we agree that's a better approach I can rebase them and submit.
Spinadel, David Oct. 30, 2012, 7:43 a.m. UTC | #2
About scan - you are right, but I did it just to be clear here.
Regarding sched scan, I did think about this option. I'm not sure it's better to reschedule scan wherever network list is changed, because maybe it's better to send some redundant probe requests than rescheduling new scan. If you still think rescheduling is better, so go ahead with your patch when removing or disabling a network. In case of enabling  there is other my patches.

Thanks,
David 

> -----Original Message-----
> From: eshapira@gmail.com [mailto:eshapira@gmail.com] On Behalf Of Eyal
> Shapira
> Sent: Tuesday, October 30, 2012 09:22
> To: Spinadel, David
> Cc: hostap@lists.shmoo.com
> Subject: Re: [PATCH 1/3] wpa_supplicant: abort scan after removing all
> networks
> 
> On 29 October 2012 11:13,  <david.spinadel@intel.com> wrote:
> > From: David Spinadel <david.spinadel@intel.com>
> >
> > Change-Id: I737848dabed49d961985845f2e86f717c2926f0c
> > Reviewed-on: http://git-mwg.jer.intel.com/gerrit/3585
> > Reviewed-by: Jenkins
> > Tested-by: Jenkins
> > Reviewed-by: Max Stepanov <Max.Stepanov@intel.com>
> > Tested-by: Max Stepanov <Max.Stepanov@intel.com>
> > Signed-off-by: David Spinadel <david.spinadel@intel.com>
> > ---
> >  wpa_supplicant/ctrl_iface.c             |    7 +++++++
> >  wpa_supplicant/dbus/dbus_new_handlers.c |    8 ++++++++
> >  wpa_supplicant/dbus/dbus_old_handlers.c |    5 +++++
> >  wpa_supplicant/wps_supplicant.c         |    5 +++++
> >  4 files changed, 25 insertions(+), 0 deletions(-)
> >
> > diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
> > index 0351241..d1a5cf6 100644
> > --- a/wpa_supplicant/ctrl_iface.c
> > +++ b/wpa_supplicant/ctrl_iface.c
> > @@ -2224,6 +2224,8 @@ static int
> wpa_supplicant_ctrl_iface_remove_network(
> >         /* cmd: "<network id>" or "all" */
> >         if (os_strcmp(cmd, "all") == 0) {
> >                 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK
> > all");
> > +               wpa_supplicant_cancel_sched_scan(wpa_s);
> > +               wpa_supplicant_cancel_scan(wpa_s);
> >                 ssid = wpa_s->conf->ssid;
> >                 while (ssid) {
> >                         struct wpa_ssid *remove_ssid = ssid; @@
> > -2281,6 +2283,11 @@ static int
> wpa_supplicant_ctrl_iface_remove_network(
> >                 return -1;
> >         }
> >
> > +       if (!wpa_s->conf->ssid) {
> > +               wpa_supplicant_cancel_sched_scan(wpa_s);
> > +               wpa_supplicant_cancel_scan(wpa_s);
> > +       }
> > +
> >         return 0;
> >  }
> >
> > diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c
> > b/wpa_supplicant/dbus/dbus_new_handlers.c
> > index 00378be..b0f0d0e 100644
> > --- a/wpa_supplicant/dbus/dbus_new_handlers.c
> > +++ b/wpa_supplicant/dbus/dbus_new_handlers.c
> > @@ -1525,6 +1525,11 @@ DBusMessage *
> wpas_dbus_handler_remove_network(DBusMessage *message,
> >                 wpa_supplicant_deauthenticate(wpa_s,
> >
> > WLAN_REASON_DEAUTH_LEAVING);
> >
> > +       if (!wpa_s->conf->ssid) {
> > +               wpa_supplicant_cancel_sched_scan(wpa_s);
> > +               wpa_supplicant_cancel_scan(wpa_s);
> > +       }
> > +
> >  out:
> >         os_free(iface);
> >         os_free(net_id);
> > @@ -1562,6 +1567,9 @@ static void remove_network(void *arg, struct
> > wpa_ssid *ssid)  DBusMessage *
> wpas_dbus_handler_remove_all_networks(
> >         DBusMessage *message, struct wpa_supplicant *wpa_s)  {
> > +       wpa_supplicant_cancel_sched_scan(wpa_s);
> > +       wpa_supplicant_cancel_scan(wpa_s);
> > +
> >         /* NB: could check for failure and return an error */
> >         wpa_config_foreach_network(wpa_s->conf, remove_network,
> wpa_s);
> >         return NULL;
> > diff --git a/wpa_supplicant/dbus/dbus_old_handlers.c
> > b/wpa_supplicant/dbus/dbus_old_handlers.c
> > index e217a72..ff60f6e 100644
> > --- a/wpa_supplicant/dbus/dbus_old_handlers.c
> > +++ b/wpa_supplicant/dbus/dbus_old_handlers.c
> > @@ -870,6 +870,11 @@ DBusMessage *
> wpas_dbus_iface_remove_network(DBusMessage *message,
> >                                               WLAN_REASON_DEAUTH_LEAVING);
> >         reply = wpas_dbus_new_success_reply(message);
> >
> > +       if (!wpa_s->conf->ssid) {
> > +               wpa_supplicant_cancel_sched_scan(wpa_s);
> > +               wpa_supplicant_cancel_scan(wpa_s);
> > +       }
> > +
> >  out:
> >         os_free(iface);
> >         os_free(net_id);
> > diff --git a/wpa_supplicant/wps_supplicant.c
> > b/wpa_supplicant/wps_supplicant.c index 41aa5db..87ea320 100644
> > --- a/wpa_supplicant/wps_supplicant.c
> > +++ b/wpa_supplicant/wps_supplicant.c
> > @@ -759,6 +759,11 @@ static void wpas_clear_wps(struct wpa_supplicant
> *wpa_s)
> >         }
> >
> >         wpas_wps_clear_ap_info(wpa_s);
> > +
> > +       if (!wpa_s->conf->ssid) {
> > +               wpa_supplicant_cancel_sched_scan(wpa_s);
> > +               wpa_supplicant_cancel_scan(wpa_s);
> > +       }
> >  }
> 
> wpa_supplicant_scan wouldn't do anything if you haven't got any enabled
> networks so the cancel_scan() is a bit moot. no ?
> 
> Regarding sched scan, I think the more correct behavior is to restart sched
> scan whenever the enabled networks list change (e.g.
> enable/disable/remove)
> as otherwise we'd continue to sched scan a non relevant list of SSIDs.
> This would also take care of removing all networks given that we bail out in
> wpa_supplicant_req_sched_scan if there aren't any enabled networks.
> I have some internal patches on our tree doing something like this but they
> need some work to be rebased on the latetest master.
> If we agree that's a better approach I can rebase them and submit.
---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
Eyal Shapira Oct. 30, 2012, 8:36 a.m. UTC | #3
On 30 October 2012 09:43, Spinadel, David <david.spinadel@intel.com> wrote:
> About scan - you are right, but I did it just to be clear here.
> Regarding sched scan, I did think about this option. I'm not sure it's better to reschedule scan wherever network list is changed, because maybe it's better to send some redundant probe requests than rescheduling new scan. If you still think rescheduling is better, so go ahead with your patch when removing or disabling a network. In case of enabling  there is other my patches.
>

In our case, sched scan can go on for a long time and continues while
the host is suspended.
Sending 16 probes (in case of our maximal 16 SSIDs it's actually even
32 as each one is transmitted twice)
vs. just 1 has an impact on power (due to additional Tx as well as
longer dwell time we set in case there are more probes).
That's why I think it's good to restart the sched scan.

About enable - yep, you handle it already correctly.

Thanks,
Eyal

> Thanks,
> David
>
>> -----Original Message-----
>> From: eshapira@gmail.com [mailto:eshapira@gmail.com] On Behalf Of Eyal
>> Shapira
>> Sent: Tuesday, October 30, 2012 09:22
>> To: Spinadel, David
>> Cc: hostap@lists.shmoo.com
>> Subject: Re: [PATCH 1/3] wpa_supplicant: abort scan after removing all
>> networks
>>
>> On 29 October 2012 11:13,  <david.spinadel@intel.com> wrote:
>> > From: David Spinadel <david.spinadel@intel.com>
>> >
>> > Change-Id: I737848dabed49d961985845f2e86f717c2926f0c
>> > Reviewed-on: http://git-mwg.jer.intel.com/gerrit/3585
>> > Reviewed-by: Jenkins
>> > Tested-by: Jenkins
>> > Reviewed-by: Max Stepanov <Max.Stepanov@intel.com>
>> > Tested-by: Max Stepanov <Max.Stepanov@intel.com>
>> > Signed-off-by: David Spinadel <david.spinadel@intel.com>
>> > ---
>> >  wpa_supplicant/ctrl_iface.c             |    7 +++++++
>> >  wpa_supplicant/dbus/dbus_new_handlers.c |    8 ++++++++
>> >  wpa_supplicant/dbus/dbus_old_handlers.c |    5 +++++
>> >  wpa_supplicant/wps_supplicant.c         |    5 +++++
>> >  4 files changed, 25 insertions(+), 0 deletions(-)
>> >
>> > diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
>> > index 0351241..d1a5cf6 100644
>> > --- a/wpa_supplicant/ctrl_iface.c
>> > +++ b/wpa_supplicant/ctrl_iface.c
>> > @@ -2224,6 +2224,8 @@ static int
>> wpa_supplicant_ctrl_iface_remove_network(
>> >         /* cmd: "<network id>" or "all" */
>> >         if (os_strcmp(cmd, "all") == 0) {
>> >                 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK
>> > all");
>> > +               wpa_supplicant_cancel_sched_scan(wpa_s);
>> > +               wpa_supplicant_cancel_scan(wpa_s);
>> >                 ssid = wpa_s->conf->ssid;
>> >                 while (ssid) {
>> >                         struct wpa_ssid *remove_ssid = ssid; @@
>> > -2281,6 +2283,11 @@ static int
>> wpa_supplicant_ctrl_iface_remove_network(
>> >                 return -1;
>> >         }
>> >
>> > +       if (!wpa_s->conf->ssid) {
>> > +               wpa_supplicant_cancel_sched_scan(wpa_s);
>> > +               wpa_supplicant_cancel_scan(wpa_s);
>> > +       }
>> > +
>> >         return 0;
>> >  }
>> >
>> > diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c
>> > b/wpa_supplicant/dbus/dbus_new_handlers.c
>> > index 00378be..b0f0d0e 100644
>> > --- a/wpa_supplicant/dbus/dbus_new_handlers.c
>> > +++ b/wpa_supplicant/dbus/dbus_new_handlers.c
>> > @@ -1525,6 +1525,11 @@ DBusMessage *
>> wpas_dbus_handler_remove_network(DBusMessage *message,
>> >                 wpa_supplicant_deauthenticate(wpa_s,
>> >
>> > WLAN_REASON_DEAUTH_LEAVING);
>> >
>> > +       if (!wpa_s->conf->ssid) {
>> > +               wpa_supplicant_cancel_sched_scan(wpa_s);
>> > +               wpa_supplicant_cancel_scan(wpa_s);
>> > +       }
>> > +
>> >  out:
>> >         os_free(iface);
>> >         os_free(net_id);
>> > @@ -1562,6 +1567,9 @@ static void remove_network(void *arg, struct
>> > wpa_ssid *ssid)  DBusMessage *
>> wpas_dbus_handler_remove_all_networks(
>> >         DBusMessage *message, struct wpa_supplicant *wpa_s)  {
>> > +       wpa_supplicant_cancel_sched_scan(wpa_s);
>> > +       wpa_supplicant_cancel_scan(wpa_s);
>> > +
>> >         /* NB: could check for failure and return an error */
>> >         wpa_config_foreach_network(wpa_s->conf, remove_network,
>> wpa_s);
>> >         return NULL;
>> > diff --git a/wpa_supplicant/dbus/dbus_old_handlers.c
>> > b/wpa_supplicant/dbus/dbus_old_handlers.c
>> > index e217a72..ff60f6e 100644
>> > --- a/wpa_supplicant/dbus/dbus_old_handlers.c
>> > +++ b/wpa_supplicant/dbus/dbus_old_handlers.c
>> > @@ -870,6 +870,11 @@ DBusMessage *
>> wpas_dbus_iface_remove_network(DBusMessage *message,
>> >                                               WLAN_REASON_DEAUTH_LEAVING);
>> >         reply = wpas_dbus_new_success_reply(message);
>> >
>> > +       if (!wpa_s->conf->ssid) {
>> > +               wpa_supplicant_cancel_sched_scan(wpa_s);
>> > +               wpa_supplicant_cancel_scan(wpa_s);
>> > +       }
>> > +
>> >  out:
>> >         os_free(iface);
>> >         os_free(net_id);
>> > diff --git a/wpa_supplicant/wps_supplicant.c
>> > b/wpa_supplicant/wps_supplicant.c index 41aa5db..87ea320 100644
>> > --- a/wpa_supplicant/wps_supplicant.c
>> > +++ b/wpa_supplicant/wps_supplicant.c
>> > @@ -759,6 +759,11 @@ static void wpas_clear_wps(struct wpa_supplicant
>> *wpa_s)
>> >         }
>> >
>> >         wpas_wps_clear_ap_info(wpa_s);
>> > +
>> > +       if (!wpa_s->conf->ssid) {
>> > +               wpa_supplicant_cancel_sched_scan(wpa_s);
>> > +               wpa_supplicant_cancel_scan(wpa_s);
>> > +       }
>> >  }
>>
>> wpa_supplicant_scan wouldn't do anything if you haven't got any enabled
>> networks so the cancel_scan() is a bit moot. no ?
>>
>> Regarding sched scan, I think the more correct behavior is to restart sched
>> scan whenever the enabled networks list change (e.g.
>> enable/disable/remove)
>> as otherwise we'd continue to sched scan a non relevant list of SSIDs.
>> This would also take care of removing all networks given that we bail out in
>> wpa_supplicant_req_sched_scan if there aren't any enabled networks.
>> I have some internal patches on our tree doing something like this but they
>> need some work to be rebased on the latetest master.
>> If we agree that's a better approach I can rebase them and submit.
> ---------------------------------------------------------------------
> Intel Israel (74) Limited
>
> This e-mail and any attachments may contain confidential material for
> the sole use of the intended recipient(s). Any review or distribution
> by others is strictly prohibited. If you are not the intended
> recipient, please contact the sender and delete all copies.
>
Spinadel, David Oct. 30, 2012, 9:42 a.m. UTC | #4
> In our case, sched scan can go on for a long time and continues while the host
> is suspended.
> Sending 16 probes (in case of our maximal 16 SSIDs it's actually even
> 32 as each one is transmitted twice)
> vs. just 1 has an impact on power (due to additional Tx as well as longer dwell
> time we set in case there are more probes).
> That's why I think it's good to restart the sched scan.
Ok, I completely agree, will wait your patch.
Thanks,
David 

---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
Jouni Malinen Nov. 3, 2012, 3:41 p.m. UTC | #5
On Tue, Oct 30, 2012 at 09:42:55AM +0000, Spinadel, David wrote:
> > In our case, sched scan can go on for a long time and continues while the host
> > is suspended.
> > Sending 16 probes (in case of our maximal 16 SSIDs it's actually even
> > 32 as each one is transmitted twice)
> > vs. just 1 has an impact on power (due to additional Tx as well as longer dwell
> > time we set in case there are more probes).
> > That's why I think it's good to restart the sched scan.
> Ok, I completely agree, will wait your patch.

Just to confirm I understood the thread correctly.. I'm assuming this is
referring to the full set (three patches) instead of just 1/3. I'm
currently waiting for the alternative patch before applying any of
these.
Eyal Shapira Nov. 3, 2012, 4:44 p.m. UTC | #6
On 3 November 2012 17:41, Jouni Malinen <j@w1.fi> wrote:
> On Tue, Oct 30, 2012 at 09:42:55AM +0000, Spinadel, David wrote:
>> > In our case, sched scan can go on for a long time and continues while the host
>> > is suspended.
>> > Sending 16 probes (in case of our maximal 16 SSIDs it's actually even
>> > 32 as each one is transmitted twice)
>> > vs. just 1 has an impact on power (due to additional Tx as well as longer dwell
>> > time we set in case there are more probes).
>> > That's why I think it's good to restart the sched scan.
>> Ok, I completely agree, will wait your patch.
>
> Just to confirm I understood the thread correctly.. I'm assuming this is
> referring to the full set (three patches) instead of just 1/3. I'm
> currently waiting for the alternative patch before applying any of
> these.
>
Actually I think David's patches 2/3 and 3/3 regarding enable_network
are ok (wrt restarting sched scan when
a new network is enabled) and I don't want me to keep you from applying them.

My suggestion was to replace patch 1/3 regarding the remove network
and I'll try to get these
worked out later today or max tomorrow.

Thanks,
Eyal
diff mbox

Patch

diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index 0351241..d1a5cf6 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -2224,6 +2224,8 @@  static int wpa_supplicant_ctrl_iface_remove_network(
 	/* cmd: "<network id>" or "all" */
 	if (os_strcmp(cmd, "all") == 0) {
 		wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
+		wpa_supplicant_cancel_sched_scan(wpa_s);
+		wpa_supplicant_cancel_scan(wpa_s);
 		ssid = wpa_s->conf->ssid;
 		while (ssid) {
 			struct wpa_ssid *remove_ssid = ssid;
@@ -2281,6 +2283,11 @@  static int wpa_supplicant_ctrl_iface_remove_network(
 		return -1;
 	}
 
+	if (!wpa_s->conf->ssid) {
+		wpa_supplicant_cancel_sched_scan(wpa_s);
+		wpa_supplicant_cancel_scan(wpa_s);
+	}
+
 	return 0;
 }
 
diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c
index 00378be..b0f0d0e 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers.c
+++ b/wpa_supplicant/dbus/dbus_new_handlers.c
@@ -1525,6 +1525,11 @@  DBusMessage * wpas_dbus_handler_remove_network(DBusMessage *message,
 		wpa_supplicant_deauthenticate(wpa_s,
 					      WLAN_REASON_DEAUTH_LEAVING);
 
+	if (!wpa_s->conf->ssid) {
+		wpa_supplicant_cancel_sched_scan(wpa_s);
+		wpa_supplicant_cancel_scan(wpa_s);
+	}
+
 out:
 	os_free(iface);
 	os_free(net_id);
@@ -1562,6 +1567,9 @@  static void remove_network(void *arg, struct wpa_ssid *ssid)
 DBusMessage * wpas_dbus_handler_remove_all_networks(
 	DBusMessage *message, struct wpa_supplicant *wpa_s)
 {
+	wpa_supplicant_cancel_sched_scan(wpa_s);
+	wpa_supplicant_cancel_scan(wpa_s);
+
 	/* NB: could check for failure and return an error */
 	wpa_config_foreach_network(wpa_s->conf, remove_network, wpa_s);
 	return NULL;
diff --git a/wpa_supplicant/dbus/dbus_old_handlers.c b/wpa_supplicant/dbus/dbus_old_handlers.c
index e217a72..ff60f6e 100644
--- a/wpa_supplicant/dbus/dbus_old_handlers.c
+++ b/wpa_supplicant/dbus/dbus_old_handlers.c
@@ -870,6 +870,11 @@  DBusMessage * wpas_dbus_iface_remove_network(DBusMessage *message,
 					      WLAN_REASON_DEAUTH_LEAVING);
 	reply = wpas_dbus_new_success_reply(message);
 
+	if (!wpa_s->conf->ssid) {
+		wpa_supplicant_cancel_sched_scan(wpa_s);
+		wpa_supplicant_cancel_scan(wpa_s);
+	}
+
 out:
 	os_free(iface);
 	os_free(net_id);
diff --git a/wpa_supplicant/wps_supplicant.c b/wpa_supplicant/wps_supplicant.c
index 41aa5db..87ea320 100644
--- a/wpa_supplicant/wps_supplicant.c
+++ b/wpa_supplicant/wps_supplicant.c
@@ -759,6 +759,11 @@  static void wpas_clear_wps(struct wpa_supplicant *wpa_s)
 	}
 
 	wpas_wps_clear_ap_info(wpa_s);
+
+	if (!wpa_s->conf->ssid) {
+		wpa_supplicant_cancel_sched_scan(wpa_s);
+		wpa_supplicant_cancel_scan(wpa_s);
+	}
 }