LCOV - code coverage report
Current view: top level - wpa_supplicant - bgscan.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1401264779 Lines: 34 44 77.3 %
Date: 2014-05-28 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /*
       2             :  * WPA Supplicant - background scan and roaming interface
       3             :  * Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
       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 "wpa_supplicant_i.h"
      13             : #include "config_ssid.h"
      14             : #include "bgscan.h"
      15             : 
      16             : #ifdef CONFIG_BGSCAN_SIMPLE
      17             : extern const struct bgscan_ops bgscan_simple_ops;
      18             : #endif /* CONFIG_BGSCAN_SIMPLE */
      19             : #ifdef CONFIG_BGSCAN_LEARN
      20             : extern const struct bgscan_ops bgscan_learn_ops;
      21             : #endif /* CONFIG_BGSCAN_LEARN */
      22             : 
      23             : static const struct bgscan_ops * bgscan_modules[] = {
      24             : #ifdef CONFIG_BGSCAN_SIMPLE
      25             :         &bgscan_simple_ops,
      26             : #endif /* CONFIG_BGSCAN_SIMPLE */
      27             : #ifdef CONFIG_BGSCAN_LEARN
      28             :         &bgscan_learn_ops,
      29             : #endif /* CONFIG_BGSCAN_LEARN */
      30             :         NULL
      31             : };
      32             : 
      33             : 
      34           4 : int bgscan_init(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
      35             :                 const char *name)
      36             : {
      37             :         const char *params;
      38             :         size_t nlen;
      39             :         int i;
      40           4 :         const struct bgscan_ops *ops = NULL;
      41             : 
      42           4 :         bgscan_deinit(wpa_s);
      43           4 :         if (name == NULL)
      44           0 :                 return -1;
      45             : 
      46           4 :         params = os_strchr(name, ':');
      47           4 :         if (params == NULL) {
      48           0 :                 params = "";
      49           0 :                 nlen = os_strlen(name);
      50             :         } else {
      51           4 :                 nlen = params - name;
      52           4 :                 params++;
      53             :         }
      54             : 
      55           6 :         for (i = 0; bgscan_modules[i]; i++) {
      56           6 :                 if (os_strncmp(name, bgscan_modules[i]->name, nlen) == 0) {
      57           4 :                         ops = bgscan_modules[i];
      58           4 :                         break;
      59             :                 }
      60             :         }
      61             : 
      62           4 :         if (ops == NULL) {
      63           0 :                 wpa_printf(MSG_ERROR, "bgscan: Could not find module "
      64             :                            "matching the parameter '%s'", name);
      65           0 :                 return -1;
      66             :         }
      67             : 
      68           4 :         wpa_s->bgscan_priv = ops->init(wpa_s, params, ssid);
      69           4 :         if (wpa_s->bgscan_priv == NULL)
      70           0 :                 return -1;
      71           4 :         wpa_s->bgscan = ops;
      72           4 :         wpa_printf(MSG_DEBUG, "bgscan: Initialized module '%s' with "
      73             :                    "parameters '%s'", ops->name, params);
      74             : 
      75           4 :         return 0;
      76             : }
      77             : 
      78             : 
      79          90 : void bgscan_deinit(struct wpa_supplicant *wpa_s)
      80             : {
      81          90 :         if (wpa_s->bgscan && wpa_s->bgscan_priv) {
      82           4 :                 wpa_printf(MSG_DEBUG, "bgscan: Deinitializing module '%s'",
      83           4 :                            wpa_s->bgscan->name);
      84           4 :                 wpa_s->bgscan->deinit(wpa_s->bgscan_priv);
      85           4 :                 wpa_s->bgscan = NULL;
      86           4 :                 wpa_s->bgscan_priv = NULL;
      87             :         }
      88          90 : }
      89             : 
      90             : 
      91        1052 : int bgscan_notify_scan(struct wpa_supplicant *wpa_s,
      92             :                        struct wpa_scan_results *scan_res)
      93             : {
      94        1052 :         if (wpa_s->bgscan && wpa_s->bgscan_priv)
      95          10 :                 return wpa_s->bgscan->notify_scan(wpa_s->bgscan_priv,
      96             :                                                   scan_res);
      97        1042 :         return 0;
      98             : }
      99             : 
     100             : 
     101           0 : void bgscan_notify_beacon_loss(struct wpa_supplicant *wpa_s)
     102             : {
     103           0 :         if (wpa_s->bgscan && wpa_s->bgscan_priv)
     104           0 :                 wpa_s->bgscan->notify_beacon_loss(wpa_s->bgscan_priv);
     105           0 : }
     106             : 
     107             : 
     108           4 : void bgscan_notify_signal_change(struct wpa_supplicant *wpa_s, int above,
     109             :                                  int current_signal, int current_noise,
     110             :                                  int current_txrate)
     111             : {
     112           4 :         if (wpa_s->bgscan && wpa_s->bgscan_priv)
     113           4 :                 wpa_s->bgscan->notify_signal_change(wpa_s->bgscan_priv, above,
     114             :                                                     current_signal,
     115             :                                                     current_noise,
     116             :                                                     current_txrate);
     117           4 : }

Generated by: LCOV version 1.10