LCOV - code coverage report
Current view: top level - wpa_supplicant - autoscan.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1443382998 Lines: 54 56 96.4 %
Date: 2015-09-27 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :  * WPA Supplicant - auto scan
       3             :  * Copyright (c) 2012, Intel Corporation. All rights reserved.
       4             :  *
       5             :  * This software may be distributed under the terms of the BSD license.
       6             :  * See README for more details.
       7             :  */
       8             : 
       9             : #include "includes.h"
      10             : 
      11             : #include "common.h"
      12             : #include "config.h"
      13             : #include "wpa_supplicant_i.h"
      14             : #include "bss.h"
      15             : #include "scan.h"
      16             : #include "autoscan.h"
      17             : 
      18             : #ifdef CONFIG_AUTOSCAN_EXPONENTIAL
      19             : extern const struct autoscan_ops autoscan_exponential_ops;
      20             : #endif /* CONFIG_AUTOSCAN_EXPONENTIAL */
      21             : 
      22             : #ifdef CONFIG_AUTOSCAN_PERIODIC
      23             : extern const struct autoscan_ops autoscan_periodic_ops;
      24             : #endif /* CONFIG_AUTOSCAN_PERIODIC */
      25             : 
      26             : static const struct autoscan_ops * autoscan_modules[] = {
      27             : #ifdef CONFIG_AUTOSCAN_EXPONENTIAL
      28             :         &autoscan_exponential_ops,
      29             : #endif /* CONFIG_AUTOSCAN_EXPONENTIAL */
      30             : #ifdef CONFIG_AUTOSCAN_PERIODIC
      31             :         &autoscan_periodic_ops,
      32             : #endif /* CONFIG_AUTOSCAN_PERIODIC */
      33             :         NULL
      34             : };
      35             : 
      36             : 
      37          12 : static void request_scan(struct wpa_supplicant *wpa_s)
      38             : {
      39          12 :         wpa_s->scan_req = MANUAL_SCAN_REQ;
      40             : 
      41          12 :         if (wpa_supplicant_req_sched_scan(wpa_s))
      42          12 :                 wpa_supplicant_req_scan(wpa_s, wpa_s->scan_interval, 0);
      43          12 : }
      44             : 
      45             : 
      46       10123 : int autoscan_init(struct wpa_supplicant *wpa_s, int req_scan)
      47             : {
      48       10123 :         const char *name = wpa_s->conf->autoscan;
      49             :         const char *params;
      50             :         size_t nlen;
      51             :         int i;
      52       10123 :         const struct autoscan_ops *ops = NULL;
      53             : 
      54       10123 :         if (wpa_s->autoscan && wpa_s->autoscan_priv)
      55           2 :                 return 0;
      56             : 
      57       10121 :         if (name == NULL)
      58       10114 :                 return 0;
      59             : 
      60           7 :         params = os_strchr(name, ':');
      61           7 :         if (params == NULL) {
      62           1 :                 params = "";
      63           1 :                 nlen = os_strlen(name);
      64             :         } else {
      65           6 :                 nlen = params - name;
      66           6 :                 params++;
      67             :         }
      68             : 
      69          14 :         for (i = 0; autoscan_modules[i]; i++) {
      70          13 :                 if (os_strncmp(name, autoscan_modules[i]->name, nlen) == 0) {
      71           6 :                         ops = autoscan_modules[i];
      72           6 :                         break;
      73             :                 }
      74             :         }
      75             : 
      76           7 :         if (ops == NULL) {
      77           1 :                 wpa_printf(MSG_ERROR, "autoscan: Could not find module "
      78             :                            "matching the parameter '%s'", name);
      79           1 :                 return -1;
      80             :         }
      81             : 
      82           6 :         wpa_s->autoscan_params = NULL;
      83             : 
      84           6 :         wpa_s->autoscan_priv = ops->init(wpa_s, params);
      85           6 :         if (wpa_s->autoscan_priv == NULL)
      86           0 :                 return -1;
      87           6 :         wpa_s->autoscan = ops;
      88             : 
      89           6 :         wpa_printf(MSG_DEBUG, "autoscan: Initialized module '%s' with "
      90             :                    "parameters '%s'", ops->name, params);
      91           6 :         if (!req_scan)
      92           1 :                 return 0;
      93             : 
      94             :         /*
      95             :          * Cancelling existing scan requests, if any.
      96             :          */
      97           5 :         wpa_supplicant_cancel_sched_scan(wpa_s);
      98           5 :         wpa_supplicant_cancel_scan(wpa_s);
      99             : 
     100             :         /*
     101             :          * Firing first scan, which will lead to call autoscan_notify_scan.
     102             :          */
     103           5 :         request_scan(wpa_s);
     104             : 
     105           5 :         return 0;
     106             : }
     107             : 
     108             : 
     109        3833 : void autoscan_deinit(struct wpa_supplicant *wpa_s)
     110             : {
     111        3833 :         if (wpa_s->autoscan && wpa_s->autoscan_priv) {
     112           6 :                 wpa_printf(MSG_DEBUG, "autoscan: Deinitializing module '%s'",
     113           6 :                            wpa_s->autoscan->name);
     114           6 :                 wpa_s->autoscan->deinit(wpa_s->autoscan_priv);
     115           6 :                 wpa_s->autoscan = NULL;
     116           6 :                 wpa_s->autoscan_priv = NULL;
     117             : 
     118           6 :                 wpa_s->scan_interval = 5;
     119           6 :                 wpa_s->sched_scan_interval = 0;
     120             :         }
     121        3833 : }
     122             : 
     123             : 
     124        2431 : int autoscan_notify_scan(struct wpa_supplicant *wpa_s,
     125             :                          struct wpa_scan_results *scan_res)
     126             : {
     127             :         int interval;
     128             : 
     129        2431 :         if (wpa_s->autoscan && wpa_s->autoscan_priv) {
     130           7 :                 interval = wpa_s->autoscan->notify_scan(wpa_s->autoscan_priv,
     131             :                                                         scan_res);
     132             : 
     133           7 :                 if (interval <= 0)
     134           0 :                         return -1;
     135             : 
     136           7 :                 wpa_s->scan_interval = interval;
     137           7 :                 wpa_s->sched_scan_interval = interval;
     138             : 
     139           7 :                 request_scan(wpa_s);
     140             :         }
     141             : 
     142        2431 :         return 0;
     143             : }

Generated by: LCOV version 1.10