Move background scanning check to libdhcpcd so that in the future we can
authorRoy Marples <roy@marples.name>
Sun, 8 Mar 2015 11:17:17 +0000 (11:17 +0000)
committerRoy Marples <roy@marples.name>
Sun, 8 Mar 2015 11:17:17 +0000 (11:17 +0000)
detect if the driver/interface actually supports it. This should be possible
on BSD.

If the interface is down, run a background scan always as this won't
disconnect.

configure
src/dhcpcd-curses/dhcpcd-curses.c
src/dhcpcd-gtk/main.c
src/dhcpcd-gtk/menu.c
src/dhcpcd-qt/dhcpcd-qt.pro
src/dhcpcd-qt/dhcpcd-ssid.cpp
src/dhcpcd-qt/dhcpcd-wi.cpp
src/dhcpcd-qt/dhcpcd-wi.h
src/libdhcpcd/dhcpcd.h
src/libdhcpcd/wpa.c

index a1140b22754d7384d5f517527d0473af8d059333..3a0713a8d28c1864a80d266aea125eb14eab3c61 100755 (executable)
--- a/configure
+++ b/configure
@@ -252,23 +252,6 @@ else
        echo "CFLAGS+=  -DNDEBUG" >>$CONFIG_MK
 fi
 
-printf "OS supports background scanning ... "
-# Most OS's don't support background scanning
-case "$OS" in
-       linux*|freebsd*)
-               BGSCAN=true;;
-       *)      BGSCAN=false;;
-esac
-printf "%s ... " "$OS"
-if $BGSCAN; then
-       echo "yes"
-       echo "CFLAGS+=  -DBG_SCAN" >> $CONFIG_MK
-       QMAKE_CONFIG="$QMAKE_CONFIG CONFIG+=build_bgscan"
-else
-       echo "no"
-fi
-
-
 # Add CPPFLAGS and CFLAGS to CC for testing features
 XCC="$CC `$SED -n -e 's/CPPLAGS+=*\(.*\)/\1/p' $CONFIG_MK`"
 XCC="$XCC `$SED -n -e 's/CFLAGS+=*\(.*\)/\1/p' $CONFIG_MK`"
index c957a52df855e6fcf476df9826f3e9f0e9d69478..7c4d0834353588b8c7107775ae5c584546d2c3e6 100644 (file)
@@ -419,7 +419,6 @@ wpa_status_cb(DHCPCD_WPA *wpa, const char *status, void *arg)
        }
 }
 
-#ifdef BG_SCAN
 static void
 bg_scan(void *arg)
 {
@@ -428,9 +427,11 @@ bg_scan(void *arg)
        DHCPCD_WPA *wpa;
 
        TAILQ_FOREACH(w, &ctx->wi_scans, next) {
-               if (w->interface->wireless && w->interface->up) {
+               if (w->interface->wireless& w->interface->up) {
                        wpa = dhcpcd_wpa_find(ctx->con, w->interface->ifname);
-                       if (wpa)
+                       if (wpa &&
+                           (!w->interface->up ||
+                           dhcpcd_wpa_can_background_scan(wpa)))
                                dhcpcd_wpa_scan(wpa);
                }
        }
@@ -438,7 +439,6 @@ bg_scan(void *arg)
        eloop_timeout_add_msec(ctx->eloop, DHCPCD_WPA_SCAN_SHORT,
            bg_scan, ctx);
 }
-#endif
 
 static void
 signal_handler(int sig)
@@ -555,10 +555,8 @@ main(void)
        dhcpcd_wpa_set_status_callback(ctx.con, wpa_status_cb, &ctx);
 
        eloop_timeout_add_sec(ctx.eloop, 0, try_open, &ctx);
-#ifdef BG_SCAN
        eloop_timeout_add_msec(ctx.eloop, DHCPCD_WPA_SCAN_SHORT,
            bg_scan, &ctx);
-#endif
        eloop_start(ctx.eloop);
 
        /* Un-resgister the callbacks to avoid spam on close */
index 3ae2192e317bd376b9ff4cfc7c39445ba0b08d89..f30b2521f7df606b6d8c81e7d8d494aa91c77d45 100644 (file)
@@ -673,7 +673,6 @@ dhcpcd_wpa_status_cb(DHCPCD_WPA *wpa, const char *status, _unused void *data)
        }
 }
 
-#ifdef BG_SCAN
 static gboolean
 bgscan(gpointer data)
 {
@@ -685,14 +684,15 @@ bgscan(gpointer data)
        TAILQ_FOREACH(w, &wi_scans, next) {
                if (w->interface->wireless) {
                        wpa = dhcpcd_wpa_find(con, w->interface->ifname);
-                       if (wpa)
+                       if (wpa &&
+                           (!w->interface->up ||
+                           dhcpcd_wpa_can_background_scan(wpa)))
                                dhcpcd_wpa_scan(wpa);
                }
        }
 
        return TRUE;
 }
-#endif
 
 int
 main(int argc, char *argv[])
@@ -734,9 +734,7 @@ main(int argc, char *argv[])
                g_timeout_add(DHCPCD_RETRYOPEN, dhcpcd_try_open, con);
 
        menu_init(status_icon, con);
-#ifdef BG_SCAN
        g_timeout_add(DHCPCD_WPA_SCAN_LONG, bgscan, con);
-#endif
 
        gtk_main();
        dhcpcd_close(con);
index 959e776549246c07e06e1024750f737396ce507e..c2a102eadb9cf8e13ee167954a5224e0729084e9 100644 (file)
@@ -32,9 +32,7 @@ static const char *copyright = "Copyright (c) 2009-2014 Roy Marples";
 static GtkStatusIcon *sicon;
 static GtkWidget *menu;
 static GtkAboutDialog *about;
-#ifdef BG_SCAN
 static guint bgscan_timer;
-#endif
 
 static void
 on_pref(_unused GObject *o, gpointer data)
@@ -322,12 +320,10 @@ menu_abort(void)
        WI_SCAN *wis;
        WI_MENU *wim;
 
-#ifdef BG_SCAN
        if (bgscan_timer) {
                g_source_remove(bgscan_timer);
                bgscan_timer = 0;
        }
-#endif
 
        TAILQ_FOREACH(wis, &wi_scans, next) {
                wis->ifmenu = NULL;
@@ -345,7 +341,6 @@ menu_abort(void)
        }
 }
 
-#ifdef BG_SCAN
 static gboolean
 menu_bgscan(gpointer data)
 {
@@ -362,14 +357,15 @@ menu_bgscan(gpointer data)
        TAILQ_FOREACH(w, &wi_scans, next) {
                if (w->interface->wireless && w->interface->up) {
                        wpa = dhcpcd_wpa_find(con, w->interface->ifname);
-                       if (wpa)
+                       if (wpa &&
+                           (!w->interface->up ||
+                           dhcpcd_wpa_can_background_scan(wpa)))
                                dhcpcd_wpa_scan(wpa);
                }
        }
 
        return TRUE;
 }
-#endif
 
 static void
 on_activate(GtkStatusIcon *icon)
@@ -409,10 +405,8 @@ on_activate(GtkStatusIcon *icon)
                    gtk_status_icon_position_menu, icon,
                    1, gtk_get_current_event_time());
 
-#ifdef BG_SCAN
                bgscan_timer = g_timeout_add(DHCPCD_WPA_SCAN_SHORT,
                    menu_bgscan, dhcpcd_if_connection(w->interface));
-#endif
        }
 }
 
index 0030047ca94bbd203a6fdcf54f7771fcea9af690..369800ac16e4b053afa534f4a513a3ad45c1ea18 100644 (file)
@@ -18,10 +18,6 @@ INCLUDEPATH+=                ../libdhcpcd/
 
 LIBS+=                 -L../libdhcpcd ../libdhcpcd/libdhcpcd.a
 
-build_bgscan {
-       DEFINES+=       BG_SCAN
-}
-
 has_libintl {
        LIBS +=         -lintl
 }
index fec48a74e50f9c01b7aaca518bb31ef8c79fa4d4..4a06ea5db1e866b4adf4f3ee9b44fed8c38c5134 100644 (file)
@@ -74,7 +74,6 @@ DhcpcdSsid::DhcpcdSsid(DhcpcdWi *parent, DHCPCD_WI_SCAN *scan)
 
 QString DhcpcdSsid::getPsk(bool *ok)
 {
-       int r;
 
        exec();
        if (result() == QDialog::Rejected) {
index 260938bcbe0fe3264ae148c694401857b515e0a5..427f268151df291fb4951bff411039848837346e 100644 (file)
@@ -54,9 +54,7 @@ DhcpcdWi::DhcpcdWi(DhcpcdQt *parent, DHCPCD_WPA *wpa)
 
        notifier = NULL;
        pingTimer = NULL;
-#ifdef BG_SCAN
        scanTimer = NULL;
-#endif
 }
 
 DhcpcdWi::~DhcpcdWi()
@@ -87,13 +85,11 @@ DhcpcdWi::~DhcpcdWi()
                ssid = NULL;
        }
 
-#ifdef BG_SCAN
        if (scanTimer) {
                scanTimer->stop();
                scanTimer->deleteLater();
                scanTimer = NULL;
        }
-#endif
 
        dhcpcd_wi_scans_free(scans);
 }
@@ -197,10 +193,8 @@ void DhcpcdWi::createMenu1(QMenu *menu)
        DHCPCD_WI_SCAN *scan;
        QAction *before;
 
-#ifdef BG_SCAN
        connect(menu, SIGNAL(aboutToShow()), this, SLOT(menuShown()));
        connect(menu, SIGNAL(aboutToHide()), this, SLOT(menuHidden()));
-#endif
 
        i = dhcpcd_wpa_if(wpa);
        for (scan = scans; scan; scan = scan->next) {
@@ -257,11 +251,9 @@ bool DhcpcdWi::open()
        pingTimer = new QTimer(this);
        connect(pingTimer, SIGNAL(timeout()), this, SLOT(ping()));
        pingTimer->start(DHCPCD_WPA_PING);
-#ifdef BG_SCAN
        scanTimer = new QTimer(this);
        connect(scanTimer, SIGNAL(timeout()), this, SLOT(scan()));
        scanTimer->start(DHCPCD_WPA_SCAN_LONG);
-#endif
        return true;
 }
 
@@ -341,11 +333,13 @@ void DhcpcdWi::connectSsid(DHCPCD_WI_SCAN *scan)
            errt);
 }
 
-#ifdef BG_SCAN
 void DhcpcdWi::scan()
 {
+       DHCPCD_IF *i;
 
-       dhcpcd_wpa_scan(wpa);
+       i = dhcpcd_wpa_if(wpa);
+       if (!i->up || dhcpcd_wpa_can_background_scan(wpa))
+               dhcpcd_wpa_scan(wpa);
 }
 
 void DhcpcdWi::menuHidden()
@@ -365,4 +359,3 @@ void DhcpcdWi::menuShown()
                scanTimer->start(DHCPCD_WPA_SCAN_SHORT);
        }
 }
-#endif
index 55d158bf5236665395b8500eb638b498d000d547..a4690e67dd6202b1b06b33ba33662e9ed54ee5de 100644 (file)
@@ -61,11 +61,9 @@ private slots:
        void dispatch();
        void ping();
        void connectSsid(DHCPCD_WI_SCAN *scan);
-#ifdef BG_SCAN
        void scan();
        void menuHidden();
        void menuShown();
-#endif
 
 private:
        DhcpcdQt *dhcpcdQt;
@@ -75,9 +73,7 @@ private:
 
        QSocketNotifier *notifier;
        QTimer *pingTimer;
-#ifdef BG_SCAN
        QTimer *scanTimer;
-#endif
 
        QMenu *menu;
        void createMenuItem(QMenu *menu, DHCPCD_WI_SCAN *scan,
index 11e64d3734d57db358e9d5297c000a46f1e39410..1abd3b53f9fcefb8aece68f569eb98b293c39774 100644 (file)
@@ -247,6 +247,7 @@ bool dhcpcd_wpa_command(DHCPCD_WPA *, const char *);
 bool dhcpcd_wpa_command_arg(DHCPCD_WPA *, const char *, const char *);
 
 bool dhcpcd_wpa_ping(DHCPCD_WPA *);
+bool dhcpcd_wpa_can_background_scan(DHCPCD_WPA *);
 bool dhcpcd_wpa_scan(DHCPCD_WPA *);
 bool dhcpcd_wpa_reconfigure(DHCPCD_WPA *);
 bool dhcpcd_wpa_reassociate(DHCPCD_WPA *);
index 0d5da72e4c40f251c31f855546157a1c6ae5f51c..59b6e2d7df28a06c551e9e54c46aec922624cdc8 100644 (file)
@@ -173,6 +173,18 @@ dhcpcd_attach_detach(DHCPCD_WPA *wpa, bool attach)
 }
 
 bool
+dhcpcd_wpa_can_background_scan(DHCPCD_WPA *wpa)
+{
+
+       wpa = NULL; /* BSD will use this moving forwards */
+#ifdef __linux__
+       return true;
+#else
+       return false;
+#endif
+}
+
+bool
 dhcpcd_wpa_scan(DHCPCD_WPA *wpa)
 {