LCOV - code coverage report
Current view: top level - wpa_supplicant - blacklist.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1393793999 Lines: 58 59 98.3 %
Date: 2014-03-02 Functions: 4 4 100.0 %
Branches: 29 30 96.7 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * wpa_supplicant - Temporary BSSID blacklist
       3                 :            :  * Copyright (c) 2003-2007, 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 "blacklist.h"
      14                 :            : 
      15                 :            : /**
      16                 :            :  * wpa_blacklist_get - Get the blacklist entry for a BSSID
      17                 :            :  * @wpa_s: Pointer to wpa_supplicant data
      18                 :            :  * @bssid: BSSID
      19                 :            :  * Returns: Matching blacklist entry for the BSSID or %NULL if not found
      20                 :            :  */
      21                 :       2233 : struct wpa_blacklist * wpa_blacklist_get(struct wpa_supplicant *wpa_s,
      22                 :            :                                          const u8 *bssid)
      23                 :            : {
      24                 :            :         struct wpa_blacklist *e;
      25                 :            : 
      26 [ +  + ][ +  + ]:       2233 :         if (wpa_s == NULL || bssid == NULL)
      27                 :          3 :                 return NULL;
      28                 :            : 
      29                 :       2230 :         e = wpa_s->blacklist;
      30         [ +  + ]:       2373 :         while (e) {
      31         [ +  + ]:        472 :                 if (os_memcmp(e->bssid, bssid, ETH_ALEN) == 0)
      32                 :        329 :                         return e;
      33                 :        143 :                 e = e->next;
      34                 :            :         }
      35                 :            : 
      36                 :       2233 :         return NULL;
      37                 :            : }
      38                 :            : 
      39                 :            : 
      40                 :            : /**
      41                 :            :  * wpa_blacklist_add - Add an BSSID to the blacklist
      42                 :            :  * @wpa_s: Pointer to wpa_supplicant data
      43                 :            :  * @bssid: BSSID to be added to the blacklist
      44                 :            :  * Returns: Current blacklist count on success, -1 on failure
      45                 :            :  *
      46                 :            :  * This function adds the specified BSSID to the blacklist or increases the
      47                 :            :  * blacklist count if the BSSID was already listed. It should be called when
      48                 :            :  * an association attempt fails either due to the selected BSS rejecting
      49                 :            :  * association or due to timeout.
      50                 :            :  *
      51                 :            :  * This blacklist is used to force %wpa_supplicant to go through all available
      52                 :            :  * BSSes before retrying to associate with an BSS that rejected or timed out
      53                 :            :  * association. It does not prevent the listed BSS from being used; it only
      54                 :            :  * changes the order in which they are tried.
      55                 :            :  */
      56                 :        700 : int wpa_blacklist_add(struct wpa_supplicant *wpa_s, const u8 *bssid)
      57                 :            : {
      58                 :            :         struct wpa_blacklist *e;
      59                 :            : 
      60 [ +  + ][ +  + ]:        700 :         if (wpa_s == NULL || bssid == NULL)
      61                 :          3 :                 return -1;
      62                 :            : 
      63                 :        697 :         e = wpa_blacklist_get(wpa_s, bssid);
      64         [ +  + ]:        697 :         if (e) {
      65                 :         25 :                 e->count++;
      66                 :         25 :                 wpa_printf(MSG_DEBUG, "BSSID " MACSTR " blacklist count "
      67                 :            :                            "incremented to %d",
      68                 :        150 :                            MAC2STR(bssid), e->count);
      69                 :         25 :                 return e->count;
      70                 :            :         }
      71                 :            : 
      72                 :        672 :         e = os_zalloc(sizeof(*e));
      73         [ -  + ]:        672 :         if (e == NULL)
      74                 :          0 :                 return -1;
      75                 :        672 :         os_memcpy(e->bssid, bssid, ETH_ALEN);
      76                 :        672 :         e->count = 1;
      77                 :        672 :         e->next = wpa_s->blacklist;
      78                 :        672 :         wpa_s->blacklist = e;
      79                 :        672 :         wpa_printf(MSG_DEBUG, "Added BSSID " MACSTR " into blacklist",
      80                 :       4032 :                    MAC2STR(bssid));
      81                 :            : 
      82                 :        700 :         return e->count;
      83                 :            : }
      84                 :            : 
      85                 :            : 
      86                 :            : /**
      87                 :            :  * wpa_blacklist_del - Remove an BSSID from the blacklist
      88                 :            :  * @wpa_s: Pointer to wpa_supplicant data
      89                 :            :  * @bssid: BSSID to be removed from the blacklist
      90                 :            :  * Returns: 0 on success, -1 on failure
      91                 :            :  */
      92                 :        606 : int wpa_blacklist_del(struct wpa_supplicant *wpa_s, const u8 *bssid)
      93                 :            : {
      94                 :        606 :         struct wpa_blacklist *e, *prev = NULL;
      95                 :            : 
      96 [ +  + ][ +  + ]:        606 :         if (wpa_s == NULL || bssid == NULL)
      97                 :          3 :                 return -1;
      98                 :            : 
      99                 :        603 :         e = wpa_s->blacklist;
     100         [ +  + ]:        626 :         while (e) {
     101         [ +  + ]:        140 :                 if (os_memcmp(e->bssid, bssid, ETH_ALEN) == 0) {
     102         [ +  + ]:        117 :                         if (prev == NULL) {
     103                 :        114 :                                 wpa_s->blacklist = e->next;
     104                 :            :                         } else {
     105                 :          3 :                                 prev->next = e->next;
     106                 :            :                         }
     107                 :        117 :                         wpa_printf(MSG_DEBUG, "Removed BSSID " MACSTR " from "
     108                 :        702 :                                    "blacklist", MAC2STR(bssid));
     109                 :        117 :                         os_free(e);
     110                 :        117 :                         return 0;
     111                 :            :                 }
     112                 :         23 :                 prev = e;
     113                 :         23 :                 e = e->next;
     114                 :            :         }
     115                 :        606 :         return -1;
     116                 :            : }
     117                 :            : 
     118                 :            : 
     119                 :            : /**
     120                 :            :  * wpa_blacklist_clear - Clear the blacklist of all entries
     121                 :            :  * @wpa_s: Pointer to wpa_supplicant data
     122                 :            :  */
     123                 :       1482 : void wpa_blacklist_clear(struct wpa_supplicant *wpa_s)
     124                 :            : {
     125                 :            :         struct wpa_blacklist *e, *prev;
     126                 :       1482 :         int max_count = 0;
     127                 :            : 
     128                 :       1482 :         e = wpa_s->blacklist;
     129                 :       1482 :         wpa_s->blacklist = NULL;
     130         [ +  + ]:       2037 :         while (e) {
     131         [ +  + ]:        555 :                 if (e->count > max_count)
     132                 :        537 :                         max_count = e->count;
     133                 :        555 :                 prev = e;
     134                 :        555 :                 e = e->next;
     135                 :        555 :                 wpa_printf(MSG_DEBUG, "Removed BSSID " MACSTR " from "
     136                 :       3330 :                            "blacklist (clear)", MAC2STR(prev->bssid));
     137                 :        555 :                 os_free(prev);
     138                 :            :         }
     139                 :            : 
     140                 :       1482 :         wpa_s->extra_blacklist_count += max_count;
     141                 :       1482 : }

Generated by: LCOV version 1.9