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

          Line data    Source code
       1             : /*
       2             :  * WPA Supplicant - auto scan exponential module
       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 "wpa_supplicant_i.h"
      13             : #include "autoscan.h"
      14             : 
      15             : struct autoscan_exponential_data {
      16             :         struct wpa_supplicant *wpa_s;
      17             :         int base;
      18             :         int limit;
      19             :         int interval;
      20             : };
      21             : 
      22             : 
      23             : static int
      24           1 : autoscan_exponential_get_params(struct autoscan_exponential_data *data,
      25             :                                 const char *params)
      26             : {
      27             :         const char *pos;
      28             : 
      29           1 :         if (params == NULL)
      30           0 :                 return -1;
      31             : 
      32           1 :         data->base = atoi(params);
      33             : 
      34           1 :         pos = os_strchr(params, ':');
      35           1 :         if (pos == NULL)
      36           0 :                 return -1;
      37             : 
      38           1 :         pos++;
      39           1 :         data->limit = atoi(pos);
      40             : 
      41           1 :         return 0;
      42             : }
      43             : 
      44             : 
      45           1 : static void * autoscan_exponential_init(struct wpa_supplicant *wpa_s,
      46             :                                         const char *params)
      47             : {
      48             :         struct autoscan_exponential_data *data;
      49             : 
      50           1 :         data = os_zalloc(sizeof(struct autoscan_exponential_data));
      51           1 :         if (data == NULL)
      52           0 :                 return NULL;
      53             : 
      54           1 :         if (autoscan_exponential_get_params(data, params) < 0) {
      55           0 :                 os_free(data);
      56           0 :                 return NULL;
      57             :         }
      58             : 
      59           1 :         wpa_printf(MSG_DEBUG, "autoscan exponential: base exponential is %d "
      60             :                    "and limit is %d", data->base, data->limit);
      61             : 
      62           1 :         data->wpa_s = wpa_s;
      63             : 
      64           1 :         return data;
      65             : }
      66             : 
      67             : 
      68           1 : static void autoscan_exponential_deinit(void *priv)
      69             : {
      70           1 :         struct autoscan_exponential_data *data = priv;
      71             : 
      72           1 :         os_free(data);
      73           1 : }
      74             : 
      75             : 
      76           3 : static int autoscan_exponential_notify_scan(void *priv,
      77             :                                             struct wpa_scan_results *scan_res)
      78             : {
      79           3 :         struct autoscan_exponential_data *data = priv;
      80             : 
      81           3 :         wpa_printf(MSG_DEBUG, "autoscan exponential: scan result "
      82             :                    "notification");
      83             : 
      84           3 :         if (data->interval >= data->limit)
      85           0 :                 return data->limit;
      86             : 
      87           3 :         if (data->interval <= 0)
      88           1 :                 data->interval = data->base;
      89             :         else {
      90           2 :                 data->interval = data->interval * data->base;
      91           2 :                 if (data->interval > data->limit)
      92           0 :                         return data->limit;
      93             :         }
      94             : 
      95           3 :         return data->interval;
      96             : }
      97             : 
      98             : 
      99             : const struct autoscan_ops autoscan_exponential_ops = {
     100             :         .name = "exponential",
     101             :         .init = autoscan_exponential_init,
     102             :         .deinit = autoscan_exponential_deinit,
     103             :         .notify_scan = autoscan_exponential_notify_scan,
     104             : };

Generated by: LCOV version 1.10