LCOV - code coverage report
Current view: top level - hostapd - config_file.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1388943092 Lines: 1015 1956 51.9 %
Date: 2014-01-05 Functions: 22 32 68.8 %
Branches: 709 1492 47.5 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * hostapd / Configuration file parser
       3                 :            :  * Copyright (c) 2003-2013, 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 "utils/includes.h"
      10                 :            : #ifndef CONFIG_NATIVE_WINDOWS
      11                 :            : #include <grp.h>
      12                 :            : #endif /* CONFIG_NATIVE_WINDOWS */
      13                 :            : 
      14                 :            : #include "utils/common.h"
      15                 :            : #include "utils/uuid.h"
      16                 :            : #include "common/ieee802_11_defs.h"
      17                 :            : #include "drivers/driver.h"
      18                 :            : #include "eap_server/eap.h"
      19                 :            : #include "radius/radius_client.h"
      20                 :            : #include "ap/wpa_auth.h"
      21                 :            : #include "ap/ap_config.h"
      22                 :            : #include "config_file.h"
      23                 :            : 
      24                 :            : 
      25                 :            : #ifndef CONFIG_NO_VLAN
      26                 :          0 : static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
      27                 :            :                                          const char *fname)
      28                 :            : {
      29                 :            :         FILE *f;
      30                 :            :         char buf[128], *pos, *pos2;
      31                 :          0 :         int line = 0, vlan_id;
      32                 :            :         struct hostapd_vlan *vlan;
      33                 :            : 
      34                 :          0 :         f = fopen(fname, "r");
      35         [ #  # ]:          0 :         if (!f) {
      36                 :          0 :                 wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname);
      37                 :          0 :                 return -1;
      38                 :            :         }
      39                 :            : 
      40         [ #  # ]:          0 :         while (fgets(buf, sizeof(buf), f)) {
      41                 :          0 :                 line++;
      42                 :            : 
      43         [ #  # ]:          0 :                 if (buf[0] == '#')
      44                 :          0 :                         continue;
      45                 :          0 :                 pos = buf;
      46         [ #  # ]:          0 :                 while (*pos != '\0') {
      47         [ #  # ]:          0 :                         if (*pos == '\n') {
      48                 :          0 :                                 *pos = '\0';
      49                 :          0 :                                 break;
      50                 :            :                         }
      51                 :          0 :                         pos++;
      52                 :            :                 }
      53         [ #  # ]:          0 :                 if (buf[0] == '\0')
      54                 :          0 :                         continue;
      55                 :            : 
      56         [ #  # ]:          0 :                 if (buf[0] == '*') {
      57                 :          0 :                         vlan_id = VLAN_ID_WILDCARD;
      58                 :          0 :                         pos = buf + 1;
      59                 :            :                 } else {
      60                 :          0 :                         vlan_id = strtol(buf, &pos, 10);
      61 [ #  # ][ #  # ]:          0 :                         if (buf == pos || vlan_id < 1 ||
                 [ #  # ]
      62                 :            :                             vlan_id > MAX_VLAN_ID) {
      63                 :          0 :                                 wpa_printf(MSG_ERROR, "Invalid VLAN ID at "
      64                 :            :                                            "line %d in '%s'", line, fname);
      65                 :          0 :                                 fclose(f);
      66                 :          0 :                                 return -1;
      67                 :            :                         }
      68                 :            :                 }
      69                 :            : 
      70 [ #  # ][ #  # ]:          0 :                 while (*pos == ' ' || *pos == '\t')
      71                 :          0 :                         pos++;
      72                 :          0 :                 pos2 = pos;
      73 [ #  # ][ #  # ]:          0 :                 while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
                 [ #  # ]
      74                 :          0 :                         pos2++;
      75                 :          0 :                 *pos2 = '\0';
      76 [ #  # ][ #  # ]:          0 :                 if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
      77                 :          0 :                         wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d "
      78                 :            :                                    "in '%s'", line, fname);
      79                 :          0 :                         fclose(f);
      80                 :          0 :                         return -1;
      81                 :            :                 }
      82                 :            : 
      83                 :          0 :                 vlan = os_zalloc(sizeof(*vlan));
      84         [ #  # ]:          0 :                 if (vlan == NULL) {
      85                 :          0 :                         wpa_printf(MSG_ERROR, "Out of memory while reading "
      86                 :            :                                    "VLAN interfaces from '%s'", fname);
      87                 :          0 :                         fclose(f);
      88                 :          0 :                         return -1;
      89                 :            :                 }
      90                 :            : 
      91                 :          0 :                 vlan->vlan_id = vlan_id;
      92                 :          0 :                 os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
      93                 :          0 :                 vlan->next = bss->vlan;
      94                 :          0 :                 bss->vlan = vlan;
      95                 :            :         }
      96                 :            : 
      97                 :          0 :         fclose(f);
      98                 :            : 
      99                 :          0 :         return 0;
     100                 :            : }
     101                 :            : #endif /* CONFIG_NO_VLAN */
     102                 :            : 
     103                 :            : 
     104                 :          0 : static int hostapd_acl_comp(const void *a, const void *b)
     105                 :            : {
     106                 :          0 :         const struct mac_acl_entry *aa = a;
     107                 :          0 :         const struct mac_acl_entry *bb = b;
     108                 :          0 :         return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
     109                 :            : }
     110                 :            : 
     111                 :            : 
     112                 :          0 : static int hostapd_config_read_maclist(const char *fname,
     113                 :            :                                        struct mac_acl_entry **acl, int *num)
     114                 :            : {
     115                 :            :         FILE *f;
     116                 :            :         char buf[128], *pos;
     117                 :          0 :         int line = 0;
     118                 :            :         u8 addr[ETH_ALEN];
     119                 :            :         struct mac_acl_entry *newacl;
     120                 :            :         int vlan_id;
     121                 :            : 
     122         [ #  # ]:          0 :         if (!fname)
     123                 :          0 :                 return 0;
     124                 :            : 
     125                 :          0 :         f = fopen(fname, "r");
     126         [ #  # ]:          0 :         if (!f) {
     127                 :          0 :                 wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
     128                 :          0 :                 return -1;
     129                 :            :         }
     130                 :            : 
     131         [ #  # ]:          0 :         while (fgets(buf, sizeof(buf), f)) {
     132                 :          0 :                 line++;
     133                 :            : 
     134         [ #  # ]:          0 :                 if (buf[0] == '#')
     135                 :          0 :                         continue;
     136                 :          0 :                 pos = buf;
     137         [ #  # ]:          0 :                 while (*pos != '\0') {
     138         [ #  # ]:          0 :                         if (*pos == '\n') {
     139                 :          0 :                                 *pos = '\0';
     140                 :          0 :                                 break;
     141                 :            :                         }
     142                 :          0 :                         pos++;
     143                 :            :                 }
     144         [ #  # ]:          0 :                 if (buf[0] == '\0')
     145                 :          0 :                         continue;
     146                 :            : 
     147         [ #  # ]:          0 :                 if (hwaddr_aton(buf, addr)) {
     148                 :          0 :                         wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
     149                 :            :                                    "line %d in '%s'", buf, line, fname);
     150                 :          0 :                         fclose(f);
     151                 :          0 :                         return -1;
     152                 :            :                 }
     153                 :            : 
     154                 :          0 :                 vlan_id = 0;
     155                 :          0 :                 pos = buf;
     156 [ #  # ][ #  # ]:          0 :                 while (*pos != '\0' && *pos != ' ' && *pos != '\t')
                 [ #  # ]
     157                 :          0 :                         pos++;
     158 [ #  # ][ #  # ]:          0 :                 while (*pos == ' ' || *pos == '\t')
     159                 :          0 :                         pos++;
     160         [ #  # ]:          0 :                 if (*pos != '\0')
     161                 :          0 :                         vlan_id = atoi(pos);
     162                 :            : 
     163                 :          0 :                 newacl = os_realloc_array(*acl, *num + 1, sizeof(**acl));
     164         [ #  # ]:          0 :                 if (newacl == NULL) {
     165                 :          0 :                         wpa_printf(MSG_ERROR, "MAC list reallocation failed");
     166                 :          0 :                         fclose(f);
     167                 :          0 :                         return -1;
     168                 :            :                 }
     169                 :            : 
     170                 :          0 :                 *acl = newacl;
     171                 :          0 :                 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
     172                 :          0 :                 (*acl)[*num].vlan_id = vlan_id;
     173                 :          0 :                 (*num)++;
     174                 :            :         }
     175                 :            : 
     176                 :          0 :         fclose(f);
     177                 :            : 
     178                 :          0 :         qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
     179                 :            : 
     180                 :          0 :         return 0;
     181                 :            : }
     182                 :            : 
     183                 :            : 
     184                 :            : #ifdef EAP_SERVER
     185                 :          1 : static int hostapd_config_read_eap_user(const char *fname,
     186                 :            :                                         struct hostapd_bss_config *conf)
     187                 :            : {
     188                 :            :         FILE *f;
     189                 :            :         char buf[512], *pos, *start, *pos2;
     190                 :          1 :         int line = 0, ret = 0, num_methods;
     191                 :          1 :         struct hostapd_eap_user *user, *tail = NULL;
     192                 :            : 
     193         [ -  + ]:          1 :         if (!fname)
     194                 :          0 :                 return 0;
     195                 :            : 
     196         [ -  + ]:          1 :         if (os_strncmp(fname, "sqlite:", 7) == 0) {
     197                 :          0 :                 os_free(conf->eap_user_sqlite);
     198                 :          0 :                 conf->eap_user_sqlite = os_strdup(fname + 7);
     199                 :          0 :                 return 0;
     200                 :            :         }
     201                 :            : 
     202                 :          1 :         f = fopen(fname, "r");
     203         [ -  + ]:          1 :         if (!f) {
     204                 :          0 :                 wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
     205                 :          0 :                 return -1;
     206                 :            :         }
     207                 :            : 
     208                 :            :         /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
     209         [ +  + ]:         39 :         while (fgets(buf, sizeof(buf), f)) {
     210                 :         38 :                 line++;
     211                 :            : 
     212         [ -  + ]:         38 :                 if (buf[0] == '#')
     213                 :          0 :                         continue;
     214                 :         38 :                 pos = buf;
     215         [ +  - ]:        929 :                 while (*pos != '\0') {
     216         [ +  + ]:        929 :                         if (*pos == '\n') {
     217                 :         38 :                                 *pos = '\0';
     218                 :         38 :                                 break;
     219                 :            :                         }
     220                 :        891 :                         pos++;
     221                 :            :                 }
     222         [ +  + ]:         38 :                 if (buf[0] == '\0')
     223                 :          4 :                         continue;
     224                 :            : 
     225                 :         34 :                 user = NULL;
     226                 :            : 
     227 [ +  + ][ -  + ]:         34 :                 if (buf[0] != '"' && buf[0] != '*') {
     228                 :          0 :                         wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
     229                 :            :                                    "start) on line %d in '%s'", line, fname);
     230                 :          0 :                         goto failed;
     231                 :            :                 }
     232                 :            : 
     233                 :         34 :                 user = os_zalloc(sizeof(*user));
     234         [ -  + ]:         34 :                 if (user == NULL) {
     235                 :          0 :                         wpa_printf(MSG_ERROR, "EAP user allocation failed");
     236                 :          0 :                         goto failed;
     237                 :            :                 }
     238                 :         34 :                 user->force_version = -1;
     239                 :            : 
     240         [ +  + ]:         34 :                 if (buf[0] == '*') {
     241                 :          1 :                         pos = buf;
     242                 :            :                 } else {
     243                 :         33 :                         pos = buf + 1;
     244                 :         33 :                         start = pos;
     245 [ +  + ][ +  - ]:        216 :                         while (*pos != '"' && *pos != '\0')
     246                 :        183 :                                 pos++;
     247         [ -  + ]:         33 :                         if (*pos == '\0') {
     248                 :          0 :                                 wpa_printf(MSG_ERROR, "Invalid EAP identity "
     249                 :            :                                            "(no \" in end) on line %d in '%s'",
     250                 :            :                                            line, fname);
     251                 :          0 :                                 goto failed;
     252                 :            :                         }
     253                 :            : 
     254                 :         33 :                         user->identity = os_malloc(pos - start);
     255         [ -  + ]:         33 :                         if (user->identity == NULL) {
     256                 :          0 :                                 wpa_printf(MSG_ERROR, "Failed to allocate "
     257                 :            :                                            "memory for EAP identity");
     258                 :          0 :                                 goto failed;
     259                 :            :                         }
     260                 :         33 :                         os_memcpy(user->identity, start, pos - start);
     261                 :         33 :                         user->identity_len = pos - start;
     262                 :            : 
     263 [ +  - ][ +  + ]:         33 :                         if (pos[0] == '"' && pos[1] == '*') {
     264                 :         18 :                                 user->wildcard_prefix = 1;
     265                 :         18 :                                 pos++;
     266                 :            :                         }
     267                 :            :                 }
     268                 :         34 :                 pos++;
     269 [ -  + ][ +  + ]:         87 :                 while (*pos == ' ' || *pos == '\t')
     270                 :         53 :                         pos++;
     271                 :            : 
     272         [ -  + ]:         34 :                 if (*pos == '\0') {
     273                 :          0 :                         wpa_printf(MSG_ERROR, "No EAP method on line %d in "
     274                 :            :                                    "'%s'", line, fname);
     275                 :          0 :                         goto failed;
     276                 :            :                 }
     277                 :            : 
     278                 :         34 :                 start = pos;
     279 [ +  - ][ +  + ]:        234 :                 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
                 [ +  + ]
     280                 :        200 :                         pos++;
     281         [ +  + ]:         34 :                 if (*pos == '\0') {
     282                 :         10 :                         pos = NULL;
     283                 :            :                 } else {
     284                 :         24 :                         *pos = '\0';
     285                 :         24 :                         pos++;
     286                 :            :                 }
     287                 :         34 :                 num_methods = 0;
     288         [ +  - ]:         42 :                 while (*start) {
     289                 :         42 :                         char *pos3 = os_strchr(start, ',');
     290         [ +  + ]:         42 :                         if (pos3) {
     291                 :          8 :                                 *pos3++ = '\0';
     292                 :            :                         }
     293                 :         42 :                         user->methods[num_methods].method =
     294                 :         42 :                                 eap_server_get_type(
     295                 :            :                                         start,
     296                 :            :                                         &user->methods[num_methods].vendor);
     297         [ +  + ]:         42 :                         if (user->methods[num_methods].vendor ==
     298         [ +  + ]:         41 :                             EAP_VENDOR_IETF &&
     299                 :         41 :                             user->methods[num_methods].method == EAP_TYPE_NONE)
     300                 :            :                         {
     301         [ +  + ]:          5 :                                 if (os_strcmp(start, "TTLS-PAP") == 0) {
     302                 :          1 :                                         user->ttls_auth |= EAP_TTLS_AUTH_PAP;
     303                 :          1 :                                         goto skip_eap;
     304                 :            :                                 }
     305         [ +  + ]:          4 :                                 if (os_strcmp(start, "TTLS-CHAP") == 0) {
     306                 :          1 :                                         user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
     307                 :          1 :                                         goto skip_eap;
     308                 :            :                                 }
     309         [ +  + ]:          3 :                                 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
     310                 :          1 :                                         user->ttls_auth |=
     311                 :            :                                                 EAP_TTLS_AUTH_MSCHAP;
     312                 :          1 :                                         goto skip_eap;
     313                 :            :                                 }
     314         [ +  - ]:          2 :                                 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
     315                 :          2 :                                         user->ttls_auth |=
     316                 :            :                                                 EAP_TTLS_AUTH_MSCHAPV2;
     317                 :          2 :                                         goto skip_eap;
     318                 :            :                                 }
     319                 :          0 :                                 wpa_printf(MSG_ERROR, "Unsupported EAP type "
     320                 :            :                                            "'%s' on line %d in '%s'",
     321                 :            :                                            start, line, fname);
     322                 :          0 :                                 goto failed;
     323                 :            :                         }
     324                 :            : 
     325                 :         37 :                         num_methods++;
     326         [ -  + ]:         37 :                         if (num_methods >= EAP_MAX_METHODS)
     327                 :          0 :                                 break;
     328                 :            :                 skip_eap:
     329         [ +  + ]:         42 :                         if (pos3 == NULL)
     330                 :         34 :                                 break;
     331                 :          8 :                         start = pos3;
     332                 :            :                 }
     333 [ +  + ][ -  + ]:         34 :                 if (num_methods == 0 && user->ttls_auth == 0) {
     334                 :          0 :                         wpa_printf(MSG_ERROR, "No EAP types configured on "
     335                 :            :                                    "line %d in '%s'", line, fname);
     336                 :          0 :                         goto failed;
     337                 :            :                 }
     338                 :            : 
     339         [ +  + ]:         34 :                 if (pos == NULL)
     340                 :         10 :                         goto done;
     341                 :            : 
     342 [ -  + ][ -  + ]:         24 :                 while (*pos == ' ' || *pos == '\t')
     343                 :          0 :                         pos++;
     344         [ -  + ]:         24 :                 if (*pos == '\0')
     345                 :          0 :                         goto done;
     346                 :            : 
     347         [ -  + ]:         24 :                 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
     348                 :          0 :                         user->force_version = 0;
     349                 :          0 :                         goto done;
     350                 :            :                 }
     351                 :            : 
     352         [ -  + ]:         24 :                 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
     353                 :          0 :                         user->force_version = 1;
     354                 :          0 :                         goto done;
     355                 :            :                 }
     356                 :            : 
     357         [ +  + ]:         24 :                 if (os_strncmp(pos, "[2]", 3) == 0) {
     358                 :         10 :                         user->phase2 = 1;
     359                 :         10 :                         goto done;
     360                 :            :                 }
     361                 :            : 
     362         [ +  + ]:         14 :                 if (*pos == '"') {
     363                 :         10 :                         pos++;
     364                 :         10 :                         start = pos;
     365 [ +  + ][ +  - ]:        117 :                         while (*pos != '"' && *pos != '\0')
     366                 :        107 :                                 pos++;
     367         [ -  + ]:         10 :                         if (*pos == '\0') {
     368                 :          0 :                                 wpa_printf(MSG_ERROR, "Invalid EAP password "
     369                 :            :                                            "(no \" in end) on line %d in '%s'",
     370                 :            :                                            line, fname);
     371                 :          0 :                                 goto failed;
     372                 :            :                         }
     373                 :            : 
     374                 :         10 :                         user->password = os_malloc(pos - start);
     375         [ -  + ]:         10 :                         if (user->password == NULL) {
     376                 :          0 :                                 wpa_printf(MSG_ERROR, "Failed to allocate "
     377                 :            :                                            "memory for EAP password");
     378                 :          0 :                                 goto failed;
     379                 :            :                         }
     380                 :         10 :                         os_memcpy(user->password, start, pos - start);
     381                 :         10 :                         user->password_len = pos - start;
     382                 :            : 
     383                 :         10 :                         pos++;
     384         [ +  + ]:          4 :                 } else if (os_strncmp(pos, "hash:", 5) == 0) {
     385                 :          1 :                         pos += 5;
     386                 :          1 :                         pos2 = pos;
     387 [ +  - ][ +  - ]:         33 :                         while (*pos2 != '\0' && *pos2 != ' ' &&
                 [ +  + ]
     388         [ +  - ]:         32 :                                *pos2 != '\t' && *pos2 != '#')
     389                 :         32 :                                 pos2++;
     390         [ -  + ]:          1 :                         if (pos2 - pos != 32) {
     391                 :          0 :                                 wpa_printf(MSG_ERROR, "Invalid password hash "
     392                 :            :                                            "on line %d in '%s'", line, fname);
     393                 :          0 :                                 goto failed;
     394                 :            :                         }
     395                 :          1 :                         user->password = os_malloc(16);
     396         [ -  + ]:          1 :                         if (user->password == NULL) {
     397                 :          0 :                                 wpa_printf(MSG_ERROR, "Failed to allocate "
     398                 :            :                                            "memory for EAP password hash");
     399                 :          0 :                                 goto failed;
     400                 :            :                         }
     401         [ -  + ]:          1 :                         if (hexstr2bin(pos, user->password, 16) < 0) {
     402                 :          0 :                                 wpa_printf(MSG_ERROR, "Invalid hash password "
     403                 :            :                                            "on line %d in '%s'", line, fname);
     404                 :          0 :                                 goto failed;
     405                 :            :                         }
     406                 :          1 :                         user->password_len = 16;
     407                 :          1 :                         user->password_hash = 1;
     408                 :          1 :                         pos = pos2;
     409                 :            :                 } else {
     410                 :          3 :                         pos2 = pos;
     411 [ +  + ][ +  - ]:        131 :                         while (*pos2 != '\0' && *pos2 != ' ' &&
                 [ +  - ]
     412         [ +  - ]:        128 :                                *pos2 != '\t' && *pos2 != '#')
     413                 :        128 :                                 pos2++;
     414         [ -  + ]:          3 :                         if ((pos2 - pos) & 1) {
     415                 :          0 :                                 wpa_printf(MSG_ERROR, "Invalid hex password "
     416                 :            :                                            "on line %d in '%s'", line, fname);
     417                 :          0 :                                 goto failed;
     418                 :            :                         }
     419                 :          3 :                         user->password = os_malloc((pos2 - pos) / 2);
     420         [ -  + ]:          3 :                         if (user->password == NULL) {
     421                 :          0 :                                 wpa_printf(MSG_ERROR, "Failed to allocate "
     422                 :            :                                            "memory for EAP password");
     423                 :          0 :                                 goto failed;
     424                 :            :                         }
     425         [ -  + ]:          3 :                         if (hexstr2bin(pos, user->password,
     426                 :          3 :                                        (pos2 - pos) / 2) < 0) {
     427                 :          0 :                                 wpa_printf(MSG_ERROR, "Invalid hex password "
     428                 :            :                                            "on line %d in '%s'", line, fname);
     429                 :          0 :                                 goto failed;
     430                 :            :                         }
     431                 :          3 :                         user->password_len = (pos2 - pos) / 2;
     432                 :          3 :                         pos = pos2;
     433                 :            :                 }
     434                 :            : 
     435 [ -  + ][ +  + ]:         20 :                 while (*pos == ' ' || *pos == '\t')
     436                 :          6 :                         pos++;
     437         [ +  + ]:         14 :                 if (os_strncmp(pos, "[2]", 3) == 0) {
     438                 :          6 :                         user->phase2 = 1;
     439                 :            :                 }
     440                 :            : 
     441                 :            :         done:
     442         [ +  + ]:         34 :                 if (tail == NULL) {
     443                 :          1 :                         tail = conf->eap_user = user;
     444                 :            :                 } else {
     445                 :         33 :                         tail->next = user;
     446                 :         33 :                         tail = user;
     447                 :            :                 }
     448                 :         34 :                 continue;
     449                 :            : 
     450                 :            :         failed:
     451         [ #  # ]:          0 :                 if (user) {
     452                 :          0 :                         os_free(user->password);
     453                 :          0 :                         os_free(user->identity);
     454                 :          0 :                         os_free(user);
     455                 :            :                 }
     456                 :          0 :                 ret = -1;
     457                 :          0 :                 break;
     458                 :            :         }
     459                 :            : 
     460                 :          1 :         fclose(f);
     461                 :            : 
     462                 :          1 :         return ret;
     463                 :            : }
     464                 :            : #endif /* EAP_SERVER */
     465                 :            : 
     466                 :            : 
     467                 :            : #ifndef CONFIG_NO_RADIUS
     468                 :            : static int
     469                 :         82 : hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
     470                 :            :                                 int *num_server, const char *val, int def_port,
     471                 :            :                                 struct hostapd_radius_server **curr_serv)
     472                 :            : {
     473                 :            :         struct hostapd_radius_server *nserv;
     474                 :            :         int ret;
     475                 :            :         static int server_index = 1;
     476                 :            : 
     477                 :         82 :         nserv = os_realloc_array(*server, *num_server + 1, sizeof(*nserv));
     478         [ -  + ]:         82 :         if (nserv == NULL)
     479                 :          0 :                 return -1;
     480                 :            : 
     481                 :         82 :         *server = nserv;
     482                 :         82 :         nserv = &nserv[*num_server];
     483                 :         82 :         (*num_server)++;
     484                 :         82 :         (*curr_serv) = nserv;
     485                 :            : 
     486                 :         82 :         os_memset(nserv, 0, sizeof(*nserv));
     487                 :         82 :         nserv->port = def_port;
     488                 :         82 :         ret = hostapd_parse_ip_addr(val, &nserv->addr);
     489                 :         82 :         nserv->index = server_index++;
     490                 :            : 
     491                 :         82 :         return ret;
     492                 :            : }
     493                 :            : 
     494                 :            : 
     495                 :            : static struct hostapd_radius_attr *
     496                 :          0 : hostapd_parse_radius_attr(const char *value)
     497                 :            : {
     498                 :            :         const char *pos;
     499                 :            :         char syntax;
     500                 :            :         struct hostapd_radius_attr *attr;
     501                 :            :         size_t len;
     502                 :            : 
     503                 :          0 :         attr = os_zalloc(sizeof(*attr));
     504         [ #  # ]:          0 :         if (attr == NULL)
     505                 :          0 :                 return NULL;
     506                 :            : 
     507                 :          0 :         attr->type = atoi(value);
     508                 :            : 
     509                 :          0 :         pos = os_strchr(value, ':');
     510         [ #  # ]:          0 :         if (pos == NULL) {
     511                 :          0 :                 attr->val = wpabuf_alloc(1);
     512         [ #  # ]:          0 :                 if (attr->val == NULL) {
     513                 :          0 :                         os_free(attr);
     514                 :          0 :                         return NULL;
     515                 :            :                 }
     516                 :          0 :                 wpabuf_put_u8(attr->val, 0);
     517                 :          0 :                 return attr;
     518                 :            :         }
     519                 :            : 
     520                 :          0 :         pos++;
     521 [ #  # ][ #  # ]:          0 :         if (pos[0] == '\0' || pos[1] != ':') {
     522                 :          0 :                 os_free(attr);
     523                 :          0 :                 return NULL;
     524                 :            :         }
     525                 :          0 :         syntax = *pos++;
     526                 :          0 :         pos++;
     527                 :            : 
     528   [ #  #  #  # ]:          0 :         switch (syntax) {
     529                 :            :         case 's':
     530                 :          0 :                 attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
     531                 :          0 :                 break;
     532                 :            :         case 'x':
     533                 :          0 :                 len = os_strlen(pos);
     534         [ #  # ]:          0 :                 if (len & 1)
     535                 :          0 :                         break;
     536                 :          0 :                 len /= 2;
     537                 :          0 :                 attr->val = wpabuf_alloc(len);
     538         [ #  # ]:          0 :                 if (attr->val == NULL)
     539                 :          0 :                         break;
     540         [ #  # ]:          0 :                 if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
     541                 :          0 :                         wpabuf_free(attr->val);
     542                 :          0 :                         os_free(attr);
     543                 :          0 :                         return NULL;
     544                 :            :                 }
     545                 :          0 :                 break;
     546                 :            :         case 'd':
     547                 :          0 :                 attr->val = wpabuf_alloc(4);
     548         [ #  # ]:          0 :                 if (attr->val)
     549                 :          0 :                         wpabuf_put_be32(attr->val, atoi(pos));
     550                 :          0 :                 break;
     551                 :            :         default:
     552                 :          0 :                 os_free(attr);
     553                 :          0 :                 return NULL;
     554                 :            :         }
     555                 :            : 
     556         [ #  # ]:          0 :         if (attr->val == NULL) {
     557                 :          0 :                 os_free(attr);
     558                 :          0 :                 return NULL;
     559                 :            :         }
     560                 :            : 
     561                 :          0 :         return attr;
     562                 :            : }
     563                 :            : 
     564                 :            : 
     565                 :          0 : static int hostapd_parse_das_client(struct hostapd_bss_config *bss,
     566                 :            :                                     const char *val)
     567                 :            : {
     568                 :            :         char *secret;
     569                 :            : 
     570                 :          0 :         secret = os_strchr(val, ' ');
     571         [ #  # ]:          0 :         if (secret == NULL)
     572                 :          0 :                 return -1;
     573                 :            : 
     574                 :          0 :         secret++;
     575                 :            : 
     576         [ #  # ]:          0 :         if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr))
     577                 :          0 :                 return -1;
     578                 :            : 
     579                 :          0 :         os_free(bss->radius_das_shared_secret);
     580                 :          0 :         bss->radius_das_shared_secret = (u8 *) os_strdup(secret);
     581         [ #  # ]:          0 :         if (bss->radius_das_shared_secret == NULL)
     582                 :          0 :                 return -1;
     583                 :          0 :         bss->radius_das_shared_secret_len = os_strlen(secret);
     584                 :            : 
     585                 :          0 :         return 0;
     586                 :            : }
     587                 :            : #endif /* CONFIG_NO_RADIUS */
     588                 :            : 
     589                 :            : 
     590                 :        150 : static int hostapd_config_parse_key_mgmt(int line, const char *value)
     591                 :            : {
     592                 :        150 :         int val = 0, last;
     593                 :            :         char *start, *end, *buf;
     594                 :            : 
     595                 :        150 :         buf = os_strdup(value);
     596         [ -  + ]:        150 :         if (buf == NULL)
     597                 :          0 :                 return -1;
     598                 :        150 :         start = buf;
     599                 :            : 
     600         [ +  - ]:        153 :         while (*start != '\0') {
     601 [ -  + ][ -  + ]:        153 :                 while (*start == ' ' || *start == '\t')
     602                 :          0 :                         start++;
     603         [ -  + ]:        153 :                 if (*start == '\0')
     604                 :          0 :                         break;
     605                 :        153 :                 end = start;
     606 [ +  + ][ +  - ]:       1227 :                 while (*end != ' ' && *end != '\t' && *end != '\0')
                 [ +  + ]
     607                 :       1074 :                         end++;
     608                 :        153 :                 last = *end == '\0';
     609                 :        153 :                 *end = '\0';
     610         [ +  + ]:        153 :                 if (os_strcmp(start, "WPA-PSK") == 0)
     611                 :         53 :                         val |= WPA_KEY_MGMT_PSK;
     612         [ +  + ]:        100 :                 else if (os_strcmp(start, "WPA-EAP") == 0)
     613                 :         75 :                         val |= WPA_KEY_MGMT_IEEE8021X;
     614                 :            : #ifdef CONFIG_IEEE80211R
     615         [ +  + ]:         25 :                 else if (os_strcmp(start, "FT-PSK") == 0)
     616                 :         10 :                         val |= WPA_KEY_MGMT_FT_PSK;
     617         [ +  + ]:         15 :                 else if (os_strcmp(start, "FT-EAP") == 0)
     618                 :          2 :                         val |= WPA_KEY_MGMT_FT_IEEE8021X;
     619                 :            : #endif /* CONFIG_IEEE80211R */
     620                 :            : #ifdef CONFIG_IEEE80211W
     621         [ +  + ]:         13 :                 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
     622                 :          4 :                         val |= WPA_KEY_MGMT_PSK_SHA256;
     623         [ +  + ]:          9 :                 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
     624                 :          1 :                         val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
     625                 :            : #endif /* CONFIG_IEEE80211W */
     626                 :            : #ifdef CONFIG_SAE
     627         [ +  + ]:          8 :                 else if (os_strcmp(start, "SAE") == 0)
     628                 :          4 :                         val |= WPA_KEY_MGMT_SAE;
     629         [ +  - ]:          4 :                 else if (os_strcmp(start, "FT-SAE") == 0)
     630                 :          4 :                         val |= WPA_KEY_MGMT_FT_SAE;
     631                 :            : #endif /* CONFIG_SAE */
     632                 :            :                 else {
     633                 :          0 :                         wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
     634                 :            :                                    line, start);
     635                 :          0 :                         os_free(buf);
     636                 :          0 :                         return -1;
     637                 :            :                 }
     638                 :            : 
     639         [ +  + ]:        153 :                 if (last)
     640                 :        150 :                         break;
     641                 :          3 :                 start = end + 1;
     642                 :            :         }
     643                 :            : 
     644                 :        150 :         os_free(buf);
     645         [ -  + ]:        150 :         if (val == 0) {
     646                 :          0 :                 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
     647                 :            :                            "configured.", line);
     648                 :          0 :                 return -1;
     649                 :            :         }
     650                 :            : 
     651                 :        150 :         return val;
     652                 :            : }
     653                 :            : 
     654                 :            : 
     655                 :        155 : static int hostapd_config_parse_cipher(int line, const char *value)
     656                 :            : {
     657                 :        155 :         int val = wpa_parse_cipher(value);
     658         [ -  + ]:        155 :         if (val < 0) {
     659                 :          0 :                 wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
     660                 :            :                            line, value);
     661                 :          0 :                 return -1;
     662                 :            :         }
     663         [ -  + ]:        155 :         if (val == 0) {
     664                 :          0 :                 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
     665                 :            :                            line);
     666                 :          0 :                 return -1;
     667                 :            :         }
     668                 :        155 :         return val;
     669                 :            : }
     670                 :            : 
     671                 :            : 
     672                 :          1 : static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
     673                 :            :                                    char *val)
     674                 :            : {
     675                 :          1 :         size_t len = os_strlen(val);
     676                 :            : 
     677 [ +  - ][ +  - ]:          1 :         if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
                 [ -  + ]
     678                 :          0 :                 return -1;
     679                 :            : 
     680         [ +  - ]:          1 :         if (val[0] == '"') {
     681 [ +  - ][ -  + ]:          1 :                 if (len < 2 || val[len - 1] != '"')
     682                 :          0 :                         return -1;
     683                 :          1 :                 len -= 2;
     684                 :          1 :                 wep->key[keyidx] = os_malloc(len);
     685         [ -  + ]:          1 :                 if (wep->key[keyidx] == NULL)
     686                 :          0 :                         return -1;
     687                 :          1 :                 os_memcpy(wep->key[keyidx], val + 1, len);
     688                 :          1 :                 wep->len[keyidx] = len;
     689                 :            :         } else {
     690         [ #  # ]:          0 :                 if (len & 1)
     691                 :          0 :                         return -1;
     692                 :          0 :                 len /= 2;
     693                 :          0 :                 wep->key[keyidx] = os_malloc(len);
     694         [ #  # ]:          0 :                 if (wep->key[keyidx] == NULL)
     695                 :          0 :                         return -1;
     696                 :          0 :                 wep->len[keyidx] = len;
     697         [ #  # ]:          0 :                 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
     698                 :          0 :                         return -1;
     699                 :            :         }
     700                 :            : 
     701                 :          1 :         wep->keys_set++;
     702                 :            : 
     703                 :          1 :         return 0;
     704                 :            : }
     705                 :            : 
     706                 :            : 
     707                 :          2 : static int hostapd_parse_intlist(int **int_list, char *val)
     708                 :            : {
     709                 :            :         int *list;
     710                 :            :         int count;
     711                 :            :         char *pos, *end;
     712                 :            : 
     713                 :          2 :         os_free(*int_list);
     714                 :          2 :         *int_list = NULL;
     715                 :            : 
     716                 :          2 :         pos = val;
     717                 :          2 :         count = 0;
     718         [ +  + ]:         31 :         while (*pos != '\0') {
     719         [ +  + ]:         29 :                 if (*pos == ' ')
     720                 :          9 :                         count++;
     721                 :         29 :                 pos++;
     722                 :            :         }
     723                 :            : 
     724                 :          2 :         list = os_malloc(sizeof(int) * (count + 2));
     725         [ -  + ]:          2 :         if (list == NULL)
     726                 :          0 :                 return -1;
     727                 :          2 :         pos = val;
     728                 :          2 :         count = 0;
     729         [ +  - ]:         11 :         while (*pos != '\0') {
     730                 :         11 :                 end = os_strchr(pos, ' ');
     731         [ +  + ]:         11 :                 if (end)
     732                 :          9 :                         *end = '\0';
     733                 :            : 
     734                 :         11 :                 list[count++] = atoi(pos);
     735         [ +  + ]:         11 :                 if (!end)
     736                 :          2 :                         break;
     737                 :          9 :                 pos = end + 1;
     738                 :            :         }
     739                 :          2 :         list[count] = -1;
     740                 :            : 
     741                 :          2 :         *int_list = list;
     742                 :          2 :         return 0;
     743                 :            : }
     744                 :            : 
     745                 :            : 
     746                 :         10 : static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
     747                 :            : {
     748                 :            :         struct hostapd_bss_config **all, *bss;
     749                 :            : 
     750         [ -  + ]:         10 :         if (*ifname == '\0')
     751                 :          0 :                 return -1;
     752                 :            : 
     753                 :         10 :         all = os_realloc_array(conf->bss, conf->num_bss + 1,
     754                 :            :                                sizeof(struct hostapd_bss_config *));
     755         [ -  + ]:         10 :         if (all == NULL) {
     756                 :          0 :                 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
     757                 :            :                            "multi-BSS entry");
     758                 :          0 :                 return -1;
     759                 :            :         }
     760                 :         10 :         conf->bss = all;
     761                 :            : 
     762                 :         10 :         bss = os_zalloc(sizeof(*bss));
     763         [ -  + ]:         10 :         if (bss == NULL)
     764                 :          0 :                 return -1;
     765                 :         10 :         bss->radius = os_zalloc(sizeof(*bss->radius));
     766         [ -  + ]:         10 :         if (bss->radius == NULL) {
     767                 :          0 :                 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
     768                 :            :                            "multi-BSS RADIUS data");
     769                 :          0 :                 os_free(bss);
     770                 :          0 :                 return -1;
     771                 :            :         }
     772                 :            : 
     773                 :         10 :         conf->bss[conf->num_bss++] = bss;
     774                 :         10 :         conf->last_bss = bss;
     775                 :            : 
     776                 :         10 :         hostapd_config_defaults_bss(bss);
     777                 :         10 :         os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
     778                 :         10 :         os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
     779                 :            : 
     780                 :         10 :         return 0;
     781                 :            : }
     782                 :            : 
     783                 :            : 
     784                 :            : /* convert floats with one decimal place to value*10 int, i.e.,
     785                 :            :  * "1.5" will return 15 */
     786                 :          0 : static int hostapd_config_read_int10(const char *value)
     787                 :            : {
     788                 :            :         int i, d;
     789                 :            :         char *pos;
     790                 :            : 
     791                 :          0 :         i = atoi(value);
     792                 :          0 :         pos = os_strchr(value, '.');
     793                 :          0 :         d = 0;
     794         [ #  # ]:          0 :         if (pos) {
     795                 :          0 :                 pos++;
     796 [ #  # ][ #  # ]:          0 :                 if (*pos >= '0' && *pos <= '9')
     797                 :          0 :                         d = *pos - '0';
     798                 :            :         }
     799                 :            : 
     800                 :          0 :         return i * 10 + d;
     801                 :            : }
     802                 :            : 
     803                 :            : 
     804                 :          0 : static int valid_cw(int cw)
     805                 :            : {
     806 [ #  # ][ #  # ]:          0 :         return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     807 [ #  # ][ #  # ]:          0 :                 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
         [ #  # ][ #  # ]
     808                 :            : }
     809                 :            : 
     810                 :            : 
     811                 :            : enum {
     812                 :            :         IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
     813                 :            :         IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
     814                 :            :         IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
     815                 :            :         IEEE80211_TX_QUEUE_DATA3 = 3 /* used for EDCA AC_BK data */
     816                 :            : };
     817                 :            : 
     818                 :          0 : static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
     819                 :            :                                    char *val)
     820                 :            : {
     821                 :            :         int num;
     822                 :            :         char *pos;
     823                 :            :         struct hostapd_tx_queue_params *queue;
     824                 :            : 
     825                 :            :         /* skip 'tx_queue_' prefix */
     826                 :          0 :         pos = name + 9;
     827 [ #  # ][ #  # ]:          0 :         if (os_strncmp(pos, "data", 4) == 0 &&
     828 [ #  # ][ #  # ]:          0 :             pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
     829                 :          0 :                 num = pos[4] - '0';
     830                 :          0 :                 pos += 6;
     831 [ #  # ][ #  # ]:          0 :         } else if (os_strncmp(pos, "after_beacon_", 13) == 0 ||
     832                 :          0 :                    os_strncmp(pos, "beacon_", 7) == 0) {
     833                 :          0 :                 wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
     834                 :          0 :                 return 0;
     835                 :            :         } else {
     836                 :          0 :                 wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
     837                 :          0 :                 return -1;
     838                 :            :         }
     839                 :            : 
     840         [ #  # ]:          0 :         if (num >= NUM_TX_QUEUES) {
     841                 :            :                 /* for backwards compatibility, do not trigger failure */
     842                 :          0 :                 wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
     843                 :          0 :                 return 0;
     844                 :            :         }
     845                 :            : 
     846                 :          0 :         queue = &conf->tx_queue[num];
     847                 :            : 
     848         [ #  # ]:          0 :         if (os_strcmp(pos, "aifs") == 0) {
     849                 :          0 :                 queue->aifs = atoi(val);
     850 [ #  # ][ #  # ]:          0 :                 if (queue->aifs < 0 || queue->aifs > 255) {
     851                 :          0 :                         wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
     852                 :            :                                    queue->aifs);
     853                 :          0 :                         return -1;
     854                 :            :                 }
     855         [ #  # ]:          0 :         } else if (os_strcmp(pos, "cwmin") == 0) {
     856                 :          0 :                 queue->cwmin = atoi(val);
     857         [ #  # ]:          0 :                 if (!valid_cw(queue->cwmin)) {
     858                 :          0 :                         wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
     859                 :            :                                    queue->cwmin);
     860                 :          0 :                         return -1;
     861                 :            :                 }
     862         [ #  # ]:          0 :         } else if (os_strcmp(pos, "cwmax") == 0) {
     863                 :          0 :                 queue->cwmax = atoi(val);
     864         [ #  # ]:          0 :                 if (!valid_cw(queue->cwmax)) {
     865                 :          0 :                         wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
     866                 :            :                                    queue->cwmax);
     867                 :          0 :                         return -1;
     868                 :            :                 }
     869         [ #  # ]:          0 :         } else if (os_strcmp(pos, "burst") == 0) {
     870                 :          0 :                 queue->burst = hostapd_config_read_int10(val);
     871                 :            :         } else {
     872                 :          0 :                 wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
     873                 :          0 :                 return -1;
     874                 :            :         }
     875                 :            : 
     876                 :          0 :         return 0;
     877                 :            : }
     878                 :            : 
     879                 :            : 
     880                 :            : #ifdef CONFIG_IEEE80211R
     881                 :         32 : static int add_r0kh(struct hostapd_bss_config *bss, char *value)
     882                 :            : {
     883                 :            :         struct ft_remote_r0kh *r0kh;
     884                 :            :         char *pos, *next;
     885                 :            : 
     886                 :         32 :         r0kh = os_zalloc(sizeof(*r0kh));
     887         [ -  + ]:         32 :         if (r0kh == NULL)
     888                 :          0 :                 return -1;
     889                 :            : 
     890                 :            :         /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
     891                 :         32 :         pos = value;
     892                 :         32 :         next = os_strchr(pos, ' ');
     893         [ +  - ]:         32 :         if (next)
     894                 :         32 :                 *next++ = '\0';
     895 [ +  - ][ -  + ]:         32 :         if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
     896                 :          0 :                 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
     897                 :          0 :                 os_free(r0kh);
     898                 :          0 :                 return -1;
     899                 :            :         }
     900                 :            : 
     901                 :         32 :         pos = next;
     902                 :         32 :         next = os_strchr(pos, ' ');
     903         [ +  - ]:         32 :         if (next)
     904                 :         32 :                 *next++ = '\0';
     905 [ +  - ][ -  + ]:         32 :         if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
     906                 :          0 :                 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
     907                 :          0 :                 os_free(r0kh);
     908                 :          0 :                 return -1;
     909                 :            :         }
     910                 :         32 :         r0kh->id_len = next - pos - 1;
     911                 :         32 :         os_memcpy(r0kh->id, pos, r0kh->id_len);
     912                 :            : 
     913                 :         32 :         pos = next;
     914         [ -  + ]:         32 :         if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
     915                 :          0 :                 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
     916                 :          0 :                 os_free(r0kh);
     917                 :          0 :                 return -1;
     918                 :            :         }
     919                 :            : 
     920                 :         32 :         r0kh->next = bss->r0kh_list;
     921                 :         32 :         bss->r0kh_list = r0kh;
     922                 :            : 
     923                 :         32 :         return 0;
     924                 :            : }
     925                 :            : 
     926                 :            : 
     927                 :         16 : static int add_r1kh(struct hostapd_bss_config *bss, char *value)
     928                 :            : {
     929                 :            :         struct ft_remote_r1kh *r1kh;
     930                 :            :         char *pos, *next;
     931                 :            : 
     932                 :         16 :         r1kh = os_zalloc(sizeof(*r1kh));
     933         [ -  + ]:         16 :         if (r1kh == NULL)
     934                 :          0 :                 return -1;
     935                 :            : 
     936                 :            :         /* 02:01:02:03:04:05 02:01:02:03:04:05
     937                 :            :          * 000102030405060708090a0b0c0d0e0f */
     938                 :         16 :         pos = value;
     939                 :         16 :         next = os_strchr(pos, ' ');
     940         [ +  - ]:         16 :         if (next)
     941                 :         16 :                 *next++ = '\0';
     942 [ +  - ][ -  + ]:         16 :         if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
     943                 :          0 :                 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
     944                 :          0 :                 os_free(r1kh);
     945                 :          0 :                 return -1;
     946                 :            :         }
     947                 :            : 
     948                 :         16 :         pos = next;
     949                 :         16 :         next = os_strchr(pos, ' ');
     950         [ +  - ]:         16 :         if (next)
     951                 :         16 :                 *next++ = '\0';
     952 [ +  - ][ -  + ]:         16 :         if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
     953                 :          0 :                 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
     954                 :          0 :                 os_free(r1kh);
     955                 :          0 :                 return -1;
     956                 :            :         }
     957                 :            : 
     958                 :         16 :         pos = next;
     959         [ -  + ]:         16 :         if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
     960                 :          0 :                 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
     961                 :          0 :                 os_free(r1kh);
     962                 :          0 :                 return -1;
     963                 :            :         }
     964                 :            : 
     965                 :         16 :         r1kh->next = bss->r1kh_list;
     966                 :         16 :         bss->r1kh_list = r1kh;
     967                 :            : 
     968                 :         16 :         return 0;
     969                 :            : }
     970                 :            : #endif /* CONFIG_IEEE80211R */
     971                 :            : 
     972                 :            : 
     973                 :            : #ifdef CONFIG_IEEE80211N
     974                 :         10 : static int hostapd_config_ht_capab(struct hostapd_config *conf,
     975                 :            :                                    const char *capab)
     976                 :            : {
     977         [ -  + ]:         10 :         if (os_strstr(capab, "[LDPC]"))
     978                 :          0 :                 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
     979         [ +  + ]:         10 :         if (os_strstr(capab, "[HT40-]")) {
     980                 :          1 :                 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
     981                 :          1 :                 conf->secondary_channel = -1;
     982                 :            :         }
     983         [ +  + ]:         10 :         if (os_strstr(capab, "[HT40+]")) {
     984                 :          9 :                 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
     985                 :          9 :                 conf->secondary_channel = 1;
     986                 :            :         }
     987         [ -  + ]:         10 :         if (os_strstr(capab, "[SMPS-STATIC]")) {
     988                 :          0 :                 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
     989                 :          0 :                 conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
     990                 :            :         }
     991         [ -  + ]:         10 :         if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
     992                 :          0 :                 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
     993                 :          0 :                 conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
     994                 :            :         }
     995         [ -  + ]:         10 :         if (os_strstr(capab, "[GF]"))
     996                 :          0 :                 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
     997         [ -  + ]:         10 :         if (os_strstr(capab, "[SHORT-GI-20]"))
     998                 :          0 :                 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
     999         [ -  + ]:         10 :         if (os_strstr(capab, "[SHORT-GI-40]"))
    1000                 :          0 :                 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
    1001         [ -  + ]:         10 :         if (os_strstr(capab, "[TX-STBC]"))
    1002                 :          0 :                 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
    1003         [ -  + ]:         10 :         if (os_strstr(capab, "[RX-STBC1]")) {
    1004                 :          0 :                 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
    1005                 :          0 :                 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
    1006                 :            :         }
    1007         [ -  + ]:         10 :         if (os_strstr(capab, "[RX-STBC12]")) {
    1008                 :          0 :                 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
    1009                 :          0 :                 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
    1010                 :            :         }
    1011         [ -  + ]:         10 :         if (os_strstr(capab, "[RX-STBC123]")) {
    1012                 :          0 :                 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
    1013                 :          0 :                 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
    1014                 :            :         }
    1015         [ -  + ]:         10 :         if (os_strstr(capab, "[DELAYED-BA]"))
    1016                 :          0 :                 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
    1017         [ -  + ]:         10 :         if (os_strstr(capab, "[MAX-AMSDU-7935]"))
    1018                 :          0 :                 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
    1019         [ -  + ]:         10 :         if (os_strstr(capab, "[DSSS_CCK-40]"))
    1020                 :          0 :                 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
    1021         [ -  + ]:         10 :         if (os_strstr(capab, "[PSMP]"))
    1022                 :          0 :                 conf->ht_capab |= HT_CAP_INFO_PSMP_SUPP;
    1023         [ -  + ]:         10 :         if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
    1024                 :          0 :                 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
    1025                 :            : 
    1026                 :         10 :         return 0;
    1027                 :            : }
    1028                 :            : #endif /* CONFIG_IEEE80211N */
    1029                 :            : 
    1030                 :            : 
    1031                 :            : #ifdef CONFIG_IEEE80211AC
    1032                 :          0 : static int hostapd_config_vht_capab(struct hostapd_config *conf,
    1033                 :            :                                     const char *capab)
    1034                 :            : {
    1035         [ #  # ]:          0 :         if (os_strstr(capab, "[MAX-MPDU-7991]"))
    1036                 :          0 :                 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991;
    1037         [ #  # ]:          0 :         if (os_strstr(capab, "[MAX-MPDU-11454]"))
    1038                 :          0 :                 conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454;
    1039         [ #  # ]:          0 :         if (os_strstr(capab, "[VHT160]"))
    1040                 :          0 :                 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
    1041         [ #  # ]:          0 :         if (os_strstr(capab, "[VHT160-80PLUS80]"))
    1042                 :          0 :                 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
    1043         [ #  # ]:          0 :         if (os_strstr(capab, "[VHT160-80PLUS80]"))
    1044                 :          0 :                 conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
    1045         [ #  # ]:          0 :         if (os_strstr(capab, "[RXLDPC]"))
    1046                 :          0 :                 conf->vht_capab |= VHT_CAP_RXLDPC;
    1047         [ #  # ]:          0 :         if (os_strstr(capab, "[SHORT-GI-80]"))
    1048                 :          0 :                 conf->vht_capab |= VHT_CAP_SHORT_GI_80;
    1049         [ #  # ]:          0 :         if (os_strstr(capab, "[SHORT-GI-160]"))
    1050                 :          0 :                 conf->vht_capab |= VHT_CAP_SHORT_GI_160;
    1051         [ #  # ]:          0 :         if (os_strstr(capab, "[TX-STBC-2BY1]"))
    1052                 :          0 :                 conf->vht_capab |= VHT_CAP_TXSTBC;
    1053         [ #  # ]:          0 :         if (os_strstr(capab, "[RX-STBC-1]"))
    1054                 :          0 :                 conf->vht_capab |= VHT_CAP_RXSTBC_1;
    1055         [ #  # ]:          0 :         if (os_strstr(capab, "[RX-STBC-12]"))
    1056                 :          0 :                 conf->vht_capab |= VHT_CAP_RXSTBC_2;
    1057         [ #  # ]:          0 :         if (os_strstr(capab, "[RX-STBC-123]"))
    1058                 :          0 :                 conf->vht_capab |= VHT_CAP_RXSTBC_3;
    1059         [ #  # ]:          0 :         if (os_strstr(capab, "[RX-STBC-1234]"))
    1060                 :          0 :                 conf->vht_capab |= VHT_CAP_RXSTBC_4;
    1061         [ #  # ]:          0 :         if (os_strstr(capab, "[SU-BEAMFORMER]"))
    1062                 :          0 :                 conf->vht_capab |= VHT_CAP_SU_BEAMFORMER_CAPABLE;
    1063         [ #  # ]:          0 :         if (os_strstr(capab, "[SU-BEAMFORMEE]"))
    1064                 :          0 :                 conf->vht_capab |= VHT_CAP_SU_BEAMFORMEE_CAPABLE;
    1065 [ #  # ][ #  # ]:          0 :         if (os_strstr(capab, "[BF-ANTENNA-2]") &&
    1066                 :          0 :             (conf->vht_capab & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
    1067                 :          0 :                 conf->vht_capab |= (1 << VHT_CAP_BEAMFORMEE_STS_OFFSET);
    1068 [ #  # ][ #  # ]:          0 :         if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") &&
    1069                 :          0 :             (conf->vht_capab & VHT_CAP_SU_BEAMFORMER_CAPABLE))
    1070                 :          0 :                 conf->vht_capab |= (1 << VHT_CAP_SOUNDING_DIMENSION_OFFSET);
    1071         [ #  # ]:          0 :         if (os_strstr(capab, "[MU-BEAMFORMER]"))
    1072                 :          0 :                 conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
    1073         [ #  # ]:          0 :         if (os_strstr(capab, "[MU-BEAMFORMEE]"))
    1074                 :          0 :                 conf->vht_capab |= VHT_CAP_MU_BEAMFORMEE_CAPABLE;
    1075         [ #  # ]:          0 :         if (os_strstr(capab, "[VHT-TXOP-PS]"))
    1076                 :          0 :                 conf->vht_capab |= VHT_CAP_VHT_TXOP_PS;
    1077         [ #  # ]:          0 :         if (os_strstr(capab, "[HTC-VHT]"))
    1078                 :          0 :                 conf->vht_capab |= VHT_CAP_HTC_VHT;
    1079         [ #  # ]:          0 :         if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP0]"))
    1080                 :          0 :                 conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT;
    1081 [ #  # ][ #  # ]:          0 :         if (os_strstr(capab, "[VHT-LINK-ADAPT2]") &&
    1082                 :          0 :             (conf->vht_capab & VHT_CAP_HTC_VHT))
    1083                 :          0 :                 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB;
    1084 [ #  # ][ #  # ]:          0 :         if (os_strstr(capab, "[VHT-LINK-ADAPT3]") &&
    1085                 :          0 :             (conf->vht_capab & VHT_CAP_HTC_VHT))
    1086                 :          0 :                 conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
    1087         [ #  # ]:          0 :         if (os_strstr(capab, "[RX-ANTENNA-PATTERN]"))
    1088                 :          0 :                 conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN;
    1089         [ #  # ]:          0 :         if (os_strstr(capab, "[TX-ANTENNA-PATTERN]"))
    1090                 :          0 :                 conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN;
    1091                 :          0 :         return 0;
    1092                 :            : }
    1093                 :            : #endif /* CONFIG_IEEE80211AC */
    1094                 :            : 
    1095                 :            : 
    1096                 :            : #ifdef CONFIG_INTERWORKING
    1097                 :        158 : static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
    1098                 :            :                                     int line)
    1099                 :            : {
    1100                 :        158 :         size_t len = os_strlen(pos);
    1101                 :            :         u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
    1102                 :            : 
    1103                 :            :         struct hostapd_roaming_consortium *rc;
    1104                 :            : 
    1105 [ +  - ][ +  - ]:        316 :         if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
           [ +  -  -  + ]
    1106                 :        158 :             hexstr2bin(pos, oi, len / 2)) {
    1107                 :          0 :                 wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
    1108                 :            :                            "'%s'", line, pos);
    1109                 :          0 :                 return -1;
    1110                 :            :         }
    1111                 :        158 :         len /= 2;
    1112                 :            : 
    1113                 :        158 :         rc = os_realloc_array(bss->roaming_consortium,
    1114                 :        158 :                               bss->roaming_consortium_count + 1,
    1115                 :            :                               sizeof(struct hostapd_roaming_consortium));
    1116         [ -  + ]:        158 :         if (rc == NULL)
    1117                 :          0 :                 return -1;
    1118                 :            : 
    1119                 :        158 :         os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
    1120                 :        158 :         rc[bss->roaming_consortium_count].len = len;
    1121                 :            : 
    1122                 :        158 :         bss->roaming_consortium = rc;
    1123                 :        158 :         bss->roaming_consortium_count++;
    1124                 :            : 
    1125                 :        158 :         return 0;
    1126                 :            : }
    1127                 :            : 
    1128                 :            : 
    1129                 :        100 : static int parse_lang_string(struct hostapd_lang_string **array,
    1130                 :            :                              unsigned int *count, char *pos)
    1131                 :            : {
    1132                 :        100 :         char *sep, *str = NULL;
    1133                 :            :         size_t clen, nlen, slen;
    1134                 :            :         struct hostapd_lang_string *ls;
    1135                 :        100 :         int ret = -1;
    1136                 :            : 
    1137 [ +  - ][ -  + ]:        100 :         if (*pos == '"' || (*pos == 'P' && pos[1] == '"')) {
                 [ #  # ]
    1138                 :          0 :                 str = wpa_config_parse_string(pos, &slen);
    1139         [ #  # ]:          0 :                 if (!str)
    1140                 :          0 :                         return -1;
    1141                 :          0 :                 pos = str;
    1142                 :            :         }
    1143                 :            : 
    1144                 :        100 :         sep = os_strchr(pos, ':');
    1145         [ -  + ]:        100 :         if (sep == NULL)
    1146                 :          0 :                 goto fail;
    1147                 :        100 :         *sep++ = '\0';
    1148                 :            : 
    1149                 :        100 :         clen = os_strlen(pos);
    1150 [ +  - ][ +  - ]:        100 :         if (clen < 2 || clen > sizeof(ls->lang))
    1151                 :            :                 goto fail;
    1152                 :        100 :         nlen = os_strlen(sep);
    1153         [ -  + ]:        100 :         if (nlen > 252)
    1154                 :          0 :                 goto fail;
    1155                 :            : 
    1156                 :        100 :         ls = os_realloc_array(*array, *count + 1,
    1157                 :            :                               sizeof(struct hostapd_lang_string));
    1158         [ -  + ]:        100 :         if (ls == NULL)
    1159                 :          0 :                 goto fail;
    1160                 :            : 
    1161                 :        100 :         *array = ls;
    1162                 :        100 :         ls = &(*array)[*count];
    1163                 :        100 :         (*count)++;
    1164                 :            : 
    1165                 :        100 :         os_memset(ls->lang, 0, sizeof(ls->lang));
    1166                 :        100 :         os_memcpy(ls->lang, pos, clen);
    1167                 :        100 :         ls->name_len = nlen;
    1168                 :        100 :         os_memcpy(ls->name, sep, nlen);
    1169                 :            : 
    1170                 :        100 :         ret = 0;
    1171                 :            : fail:
    1172                 :        100 :         os_free(str);
    1173                 :        100 :         return ret;
    1174                 :            : }
    1175                 :            : 
    1176                 :            : 
    1177                 :         82 : static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
    1178                 :            :                             int line)
    1179                 :            : {
    1180         [ -  + ]:         82 :         if (parse_lang_string(&bss->venue_name, &bss->venue_name_count, pos)) {
    1181                 :          0 :                 wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
    1182                 :            :                            line, pos);
    1183                 :          0 :                 return -1;
    1184                 :            :         }
    1185                 :         82 :         return 0;
    1186                 :            : }
    1187                 :            : 
    1188                 :            : 
    1189                 :         41 : static int parse_3gpp_cell_net(struct hostapd_bss_config *bss, char *buf,
    1190                 :            :                                int line)
    1191                 :            : {
    1192                 :            :         size_t count;
    1193                 :            :         char *pos;
    1194                 :         41 :         u8 *info = NULL, *ipos;
    1195                 :            : 
    1196                 :            :         /* format: <MCC1,MNC1>[;<MCC2,MNC2>][;...] */
    1197                 :            : 
    1198                 :         41 :         count = 1;
    1199         [ +  + ]:        312 :         for (pos = buf; *pos; pos++) {
    1200 [ +  + ][ -  + ]:        271 :                 if ((*pos < '0' && *pos > '9') && *pos != ';' && *pos != ',')
         [ #  # ][ #  # ]
    1201                 :          0 :                         goto fail;
    1202         [ +  + ]:        271 :                 if (*pos == ';')
    1203                 :          3 :                         count++;
    1204                 :            :         }
    1205         [ -  + ]:         41 :         if (1 + count * 3 > 0x7f)
    1206                 :          0 :                 goto fail;
    1207                 :            : 
    1208                 :         41 :         info = os_zalloc(2 + 3 + count * 3);
    1209         [ -  + ]:         41 :         if (info == NULL)
    1210                 :          0 :                 return -1;
    1211                 :            : 
    1212                 :         41 :         ipos = info;
    1213                 :         41 :         *ipos++ = 0; /* GUD - Version 1 */
    1214                 :         41 :         *ipos++ = 3 + count * 3; /* User Data Header Length (UDHL) */
    1215                 :         41 :         *ipos++ = 0; /* PLMN List IEI */
    1216                 :            :         /* ext(b8) | Length of PLMN List value contents(b7..1) */
    1217                 :         41 :         *ipos++ = 1 + count * 3;
    1218                 :         41 :         *ipos++ = count; /* Number of PLMNs */
    1219                 :            : 
    1220                 :         41 :         pos = buf;
    1221 [ +  + ][ +  - ]:         85 :         while (pos && *pos) {
    1222                 :            :                 char *mcc, *mnc;
    1223                 :            :                 size_t mnc_len;
    1224                 :            : 
    1225                 :         44 :                 mcc = pos;
    1226                 :         44 :                 mnc = os_strchr(pos, ',');
    1227         [ -  + ]:         44 :                 if (mnc == NULL)
    1228                 :          0 :                         goto fail;
    1229                 :         44 :                 *mnc++ = '\0';
    1230                 :         44 :                 pos = os_strchr(mnc, ';');
    1231         [ +  + ]:         44 :                 if (pos)
    1232                 :          3 :                         *pos++ = '\0';
    1233                 :            : 
    1234                 :         44 :                 mnc_len = os_strlen(mnc);
    1235 [ +  - ][ +  + ]:         44 :                 if (os_strlen(mcc) != 3 || (mnc_len != 2 && mnc_len != 3))
                 [ +  - ]
    1236                 :            :                         goto fail;
    1237                 :            : 
    1238                 :            :                 /* BC coded MCC,MNC */
    1239                 :            :                 /* MCC digit 2 | MCC digit 1 */
    1240                 :         44 :                 *ipos++ = ((mcc[1] - '0') << 4) | (mcc[0] - '0');
    1241                 :            :                 /* MNC digit 3 | MCC digit 3 */
    1242         [ +  + ]:         44 :                 *ipos++ = (((mnc_len == 2) ? 0xf0 : ((mnc[2] - '0') << 4))) |
    1243                 :         44 :                         (mcc[2] - '0');
    1244                 :            :                 /* MNC digit 2 | MNC digit 1 */
    1245                 :         44 :                 *ipos++ = ((mnc[1] - '0') << 4) | (mnc[0] - '0');
    1246                 :            :         }
    1247                 :            : 
    1248                 :         41 :         os_free(bss->anqp_3gpp_cell_net);
    1249                 :         41 :         bss->anqp_3gpp_cell_net = info;
    1250                 :         41 :         bss->anqp_3gpp_cell_net_len = 2 + 3 + 3 * count;
    1251                 :         41 :         wpa_hexdump(MSG_MSGDUMP, "3GPP Cellular Network information",
    1252                 :         41 :                     bss->anqp_3gpp_cell_net, bss->anqp_3gpp_cell_net_len);
    1253                 :            : 
    1254                 :         41 :         return 0;
    1255                 :            : 
    1256                 :            : fail:
    1257                 :          0 :         wpa_printf(MSG_ERROR, "Line %d: Invalid anqp_3gpp_cell_net: %s",
    1258                 :            :                    line, buf);
    1259                 :          0 :         os_free(info);
    1260                 :         41 :         return -1;
    1261                 :            : }
    1262                 :            : 
    1263                 :            : 
    1264                 :         73 : static int parse_nai_realm(struct hostapd_bss_config *bss, char *buf, int line)
    1265                 :            : {
    1266                 :            :         struct hostapd_nai_realm_data *realm;
    1267                 :            :         size_t i, j, len;
    1268                 :            :         int *offsets;
    1269                 :            :         char *pos, *end, *rpos;
    1270                 :            : 
    1271                 :         73 :         offsets = os_calloc(bss->nai_realm_count * MAX_NAI_REALMS,
    1272                 :            :                             sizeof(int));
    1273         [ -  + ]:         73 :         if (offsets == NULL)
    1274                 :          0 :                 return -1;
    1275                 :            : 
    1276         [ +  + ]:        106 :         for (i = 0; i < bss->nai_realm_count; i++) {
    1277                 :         33 :                 realm = &bss->nai_realm_data[i];
    1278         [ +  + ]:        363 :                 for (j = 0; j < MAX_NAI_REALMS; j++) {
    1279         [ +  + ]:        330 :                         offsets[i * MAX_NAI_REALMS + j] =
    1280                 :        330 :                                 realm->realm[j] ?
    1281                 :         33 :                                 realm->realm[j] - realm->realm_buf : -1;
    1282                 :            :                 }
    1283                 :            :         }
    1284                 :            : 
    1285                 :         73 :         realm = os_realloc_array(bss->nai_realm_data, bss->nai_realm_count + 1,
    1286                 :            :                                  sizeof(struct hostapd_nai_realm_data));
    1287         [ -  + ]:         73 :         if (realm == NULL) {
    1288                 :          0 :                 os_free(offsets);
    1289                 :          0 :                 return -1;
    1290                 :            :         }
    1291                 :         73 :         bss->nai_realm_data = realm;
    1292                 :            : 
    1293                 :            :         /* patch the pointers after realloc */
    1294         [ +  + ]:        106 :         for (i = 0; i < bss->nai_realm_count; i++) {
    1295                 :         33 :                 realm = &bss->nai_realm_data[i];
    1296         [ +  + ]:        363 :                 for (j = 0; j < MAX_NAI_REALMS; j++) {
    1297                 :        330 :                         int offs = offsets[i * MAX_NAI_REALMS + j];
    1298         [ +  + ]:        330 :                         if (offs >= 0)
    1299                 :         33 :                                 realm->realm[j] = realm->realm_buf + offs;
    1300                 :            :                         else
    1301                 :        297 :                                 realm->realm[j] = NULL;
    1302                 :            :                 }
    1303                 :            :         }
    1304                 :         73 :         os_free(offsets);
    1305                 :            : 
    1306                 :         73 :         realm = &bss->nai_realm_data[bss->nai_realm_count];
    1307                 :         73 :         os_memset(realm, 0, sizeof(*realm));
    1308                 :            : 
    1309                 :         73 :         pos = buf;
    1310                 :         73 :         realm->encoding = atoi(pos);
    1311                 :         73 :         pos = os_strchr(pos, ',');
    1312         [ -  + ]:         73 :         if (pos == NULL)
    1313                 :          0 :                 goto fail;
    1314                 :         73 :         pos++;
    1315                 :            : 
    1316                 :         73 :         end = os_strchr(pos, ',');
    1317         [ +  + ]:         73 :         if (end) {
    1318                 :         42 :                 len = end - pos;
    1319                 :         42 :                 *end = '\0';
    1320                 :            :         } else {
    1321                 :         31 :                 len = os_strlen(pos);
    1322                 :            :         }
    1323                 :            : 
    1324         [ -  + ]:         73 :         if (len > MAX_NAI_REALMLEN) {
    1325                 :          0 :                 wpa_printf(MSG_ERROR, "Too long a realm string (%d > max %d "
    1326                 :            :                            "characters)", (int) len, MAX_NAI_REALMLEN);
    1327                 :          0 :                 goto fail;
    1328                 :            :         }
    1329                 :         73 :         os_memcpy(realm->realm_buf, pos, len);
    1330                 :            : 
    1331         [ +  + ]:         73 :         if (end)
    1332                 :         42 :                 pos = end + 1;
    1333                 :            :         else
    1334                 :         31 :                 pos = NULL;
    1335                 :            : 
    1336 [ +  + ][ +  - ]:        105 :         while (pos && *pos) {
    1337                 :            :                 struct hostapd_nai_realm_eap *eap;
    1338                 :            : 
    1339         [ -  + ]:         74 :                 if (realm->eap_method_count >= MAX_NAI_EAP_METHODS) {
    1340                 :          0 :                         wpa_printf(MSG_ERROR, "Too many EAP methods");
    1341                 :          0 :                         goto fail;
    1342                 :            :                 }
    1343                 :            : 
    1344                 :         74 :                 eap = &realm->eap_method[realm->eap_method_count];
    1345                 :         74 :                 realm->eap_method_count++;
    1346                 :            : 
    1347                 :         74 :                 end = os_strchr(pos, ',');
    1348         [ +  + ]:         74 :                 if (end == NULL)
    1349                 :         42 :                         end = pos + os_strlen(pos);
    1350                 :            : 
    1351                 :         74 :                 eap->eap_method = atoi(pos);
    1352                 :            :                 for (;;) {
    1353                 :        182 :                         pos = os_strchr(pos, '[');
    1354 [ +  + ][ +  + ]:        182 :                         if (pos == NULL || pos > end)
    1355                 :            :                                 break;
    1356                 :        108 :                         pos++;
    1357         [ -  + ]:        108 :                         if (eap->num_auths >= MAX_NAI_AUTH_TYPES) {
    1358                 :          0 :                                 wpa_printf(MSG_ERROR, "Too many auth params");
    1359                 :          0 :                                 goto fail;
    1360                 :            :                         }
    1361                 :        108 :                         eap->auth_id[eap->num_auths] = atoi(pos);
    1362                 :        108 :                         pos = os_strchr(pos, ':');
    1363 [ +  - ][ +  - ]:        108 :                         if (pos == NULL || pos > end)
    1364                 :            :                                 goto fail;
    1365                 :        108 :                         pos++;
    1366                 :        108 :                         eap->auth_val[eap->num_auths] = atoi(pos);
    1367                 :        108 :                         pos = os_strchr(pos, ']');
    1368 [ +  - ][ +  - ]:        108 :                         if (pos == NULL || pos > end)
    1369                 :            :                                 goto fail;
    1370                 :        108 :                         pos++;
    1371                 :        108 :                         eap->num_auths++;
    1372                 :        108 :                 }
    1373                 :            : 
    1374         [ +  + ]:         74 :                 if (*end != ',')
    1375                 :         42 :                         break;
    1376                 :            : 
    1377                 :         32 :                 pos = end + 1;
    1378                 :            :         }
    1379                 :            : 
    1380                 :            :         /* Split realm list into null terminated realms */
    1381                 :         73 :         rpos = realm->realm_buf;
    1382                 :         73 :         i = 0;
    1383         [ +  - ]:         75 :         while (*rpos) {
    1384         [ -  + ]:         75 :                 if (i >= MAX_NAI_REALMS) {
    1385                 :          0 :                         wpa_printf(MSG_ERROR, "Too many realms");
    1386                 :          0 :                         goto fail;
    1387                 :            :                 }
    1388                 :         75 :                 realm->realm[i++] = rpos;
    1389                 :         75 :                 rpos = os_strchr(rpos, ';');
    1390         [ +  + ]:         75 :                 if (rpos == NULL)
    1391                 :         73 :                         break;
    1392                 :          2 :                 *rpos++ = '\0';
    1393                 :            :         }
    1394                 :            : 
    1395                 :         73 :         bss->nai_realm_count++;
    1396                 :            : 
    1397                 :         73 :         return 0;
    1398                 :            : 
    1399                 :            : fail:
    1400                 :          0 :         wpa_printf(MSG_ERROR, "Line %d: invalid nai_realm '%s'", line, buf);
    1401                 :         73 :         return -1;
    1402                 :            : }
    1403                 :            : 
    1404                 :            : 
    1405                 :          1 : static int parse_qos_map_set(struct hostapd_bss_config *bss,
    1406                 :            :                              char *buf, int line)
    1407                 :            : {
    1408                 :          1 :         u8 qos_map_set[16 + 2 * 21], count = 0;
    1409                 :          1 :         char *pos = buf;
    1410                 :            :         int val;
    1411                 :            : 
    1412                 :            :         for (;;) {
    1413         [ -  + ]:         20 :                 if (count == sizeof(qos_map_set)) {
    1414                 :          0 :                         wpa_printf(MSG_ERROR, "Line %d: Too many qos_map_set "
    1415                 :            :                                    "parameters '%s'", line, buf);
    1416                 :          0 :                         return -1;
    1417                 :            :                 }
    1418                 :            : 
    1419                 :         20 :                 val = atoi(pos);
    1420 [ -  + ][ +  - ]:         20 :                 if (val > 255 || val < 0) {
    1421                 :          0 :                         wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set "
    1422                 :            :                                    "'%s'", line, buf);
    1423                 :          0 :                         return -1;
    1424                 :            :                 }
    1425                 :            : 
    1426                 :         20 :                 qos_map_set[count++] = val;
    1427                 :         20 :                 pos = os_strchr(pos, ',');
    1428         [ +  + ]:         20 :                 if (!pos)
    1429                 :          1 :                         break;
    1430                 :         19 :                 pos++;
    1431                 :         19 :         }
    1432                 :            : 
    1433 [ +  - ][ -  + ]:          1 :         if (count < 16 || count & 1) {
    1434                 :          0 :                 wpa_printf(MSG_ERROR, "Line %d: Invalid qos_map_set '%s'",
    1435                 :            :                            line, buf);
    1436                 :          0 :                 return -1;
    1437                 :            :         }
    1438                 :            : 
    1439                 :          1 :         os_memcpy(bss->qos_map_set, qos_map_set, count);
    1440                 :          1 :         bss->qos_map_set_len = count;
    1441                 :            : 
    1442                 :          1 :         return 0;
    1443                 :            : }
    1444                 :            : 
    1445                 :            : #endif /* CONFIG_INTERWORKING */
    1446                 :            : 
    1447                 :            : 
    1448                 :            : #ifdef CONFIG_HS20
    1449                 :        123 : static int hs20_parse_conn_capab(struct hostapd_bss_config *bss, char *buf,
    1450                 :            :                                  int line)
    1451                 :            : {
    1452                 :            :         u8 *conn_cap;
    1453                 :            :         char *pos;
    1454                 :            : 
    1455         [ -  + ]:        123 :         if (bss->hs20_connection_capability_len >= 0xfff0)
    1456                 :          0 :                 return -1;
    1457                 :            : 
    1458                 :        123 :         conn_cap = os_realloc(bss->hs20_connection_capability,
    1459                 :        123 :                               bss->hs20_connection_capability_len + 4);
    1460         [ -  + ]:        123 :         if (conn_cap == NULL)
    1461                 :          0 :                 return -1;
    1462                 :            : 
    1463                 :        123 :         bss->hs20_connection_capability = conn_cap;
    1464                 :        123 :         conn_cap += bss->hs20_connection_capability_len;
    1465                 :        123 :         pos = buf;
    1466                 :        123 :         conn_cap[0] = atoi(pos);
    1467                 :        123 :         pos = os_strchr(pos, ':');
    1468         [ -  + ]:        123 :         if (pos == NULL)
    1469                 :          0 :                 return -1;
    1470                 :        123 :         pos++;
    1471                 :        123 :         WPA_PUT_LE16(conn_cap + 1, atoi(pos));
    1472                 :        123 :         pos = os_strchr(pos, ':');
    1473         [ -  + ]:        123 :         if (pos == NULL)
    1474                 :          0 :                 return -1;
    1475                 :        123 :         pos++;
    1476                 :        123 :         conn_cap[3] = atoi(pos);
    1477                 :        123 :         bss->hs20_connection_capability_len += 4;
    1478                 :            : 
    1479                 :        123 :         return 0;
    1480                 :            : }
    1481                 :            : 
    1482                 :            : 
    1483                 :         41 : static int hs20_parse_wan_metrics(struct hostapd_bss_config *bss, char *buf,
    1484                 :            :                                   int line)
    1485                 :            : {
    1486                 :            :         u8 *wan_metrics;
    1487                 :            :         char *pos;
    1488                 :            : 
    1489                 :            :         /* <WAN Info>:<DL Speed>:<UL Speed>:<DL Load>:<UL Load>:<LMD> */
    1490                 :            : 
    1491                 :         41 :         wan_metrics = os_zalloc(13);
    1492         [ -  + ]:         41 :         if (wan_metrics == NULL)
    1493                 :          0 :                 return -1;
    1494                 :            : 
    1495                 :         41 :         pos = buf;
    1496                 :            :         /* WAN Info */
    1497         [ -  + ]:         41 :         if (hexstr2bin(pos, wan_metrics, 1) < 0)
    1498                 :          0 :                 goto fail;
    1499                 :         41 :         pos += 2;
    1500         [ -  + ]:         41 :         if (*pos != ':')
    1501                 :          0 :                 goto fail;
    1502                 :         41 :         pos++;
    1503                 :            : 
    1504                 :            :         /* Downlink Speed */
    1505                 :         41 :         WPA_PUT_LE32(wan_metrics + 1, atoi(pos));
    1506                 :         41 :         pos = os_strchr(pos, ':');
    1507         [ -  + ]:         41 :         if (pos == NULL)
    1508                 :          0 :                 goto fail;
    1509                 :         41 :         pos++;
    1510                 :            : 
    1511                 :            :         /* Uplink Speed */
    1512                 :         41 :         WPA_PUT_LE32(wan_metrics + 5, atoi(pos));
    1513                 :         41 :         pos = os_strchr(pos, ':');
    1514         [ -  + ]:         41 :         if (pos == NULL)
    1515                 :          0 :                 goto fail;
    1516                 :         41 :         pos++;
    1517                 :            : 
    1518                 :            :         /* Downlink Load */
    1519                 :         41 :         wan_metrics[9] = atoi(pos);
    1520                 :         41 :         pos = os_strchr(pos, ':');
    1521         [ -  + ]:         41 :         if (pos == NULL)
    1522                 :          0 :                 goto fail;
    1523                 :         41 :         pos++;
    1524                 :            : 
    1525                 :            :         /* Uplink Load */
    1526                 :         41 :         wan_metrics[10] = atoi(pos);
    1527                 :         41 :         pos = os_strchr(pos, ':');
    1528         [ -  + ]:         41 :         if (pos == NULL)
    1529                 :          0 :                 goto fail;
    1530                 :         41 :         pos++;
    1531                 :            : 
    1532                 :            :         /* LMD */
    1533                 :         41 :         WPA_PUT_LE16(wan_metrics + 11, atoi(pos));
    1534                 :            : 
    1535                 :         41 :         os_free(bss->hs20_wan_metrics);
    1536                 :         41 :         bss->hs20_wan_metrics = wan_metrics;
    1537                 :            : 
    1538                 :         41 :         return 0;
    1539                 :            : 
    1540                 :            : fail:
    1541                 :          0 :         wpa_printf(MSG_ERROR, "Line %d: Invalid hs20_wan_metrics '%s'",
    1542                 :            :                    line, pos);
    1543                 :          0 :         os_free(wan_metrics);
    1544                 :         41 :         return -1;
    1545                 :            : }
    1546                 :            : 
    1547                 :            : 
    1548                 :         18 : static int hs20_parse_oper_friendly_name(struct hostapd_bss_config *bss,
    1549                 :            :                                          char *pos, int line)
    1550                 :            : {
    1551         [ -  + ]:         18 :         if (parse_lang_string(&bss->hs20_oper_friendly_name,
    1552                 :            :                               &bss->hs20_oper_friendly_name_count, pos)) {
    1553                 :          0 :                 wpa_printf(MSG_ERROR, "Line %d: Invalid "
    1554                 :            :                            "hs20_oper_friendly_name '%s'", line, pos);
    1555                 :          0 :                 return -1;
    1556                 :            :         }
    1557                 :         18 :         return 0;
    1558                 :            : }
    1559                 :            : #endif /* CONFIG_HS20 */
    1560                 :            : 
    1561                 :            : 
    1562                 :            : #ifdef CONFIG_WPS_NFC
    1563                 :          0 : static struct wpabuf * hostapd_parse_bin(const char *buf)
    1564                 :            : {
    1565                 :            :         size_t len;
    1566                 :            :         struct wpabuf *ret;
    1567                 :            : 
    1568                 :          0 :         len = os_strlen(buf);
    1569         [ #  # ]:          0 :         if (len & 0x01)
    1570                 :          0 :                 return NULL;
    1571                 :          0 :         len /= 2;
    1572                 :            : 
    1573                 :          0 :         ret = wpabuf_alloc(len);
    1574         [ #  # ]:          0 :         if (ret == NULL)
    1575                 :          0 :                 return NULL;
    1576                 :            : 
    1577         [ #  # ]:          0 :         if (hexstr2bin(buf, wpabuf_put(ret, len), len)) {
    1578                 :          0 :                 wpabuf_free(ret);
    1579                 :          0 :                 return NULL;
    1580                 :            :         }
    1581                 :            : 
    1582                 :          0 :         return ret;
    1583                 :            : }
    1584                 :            : #endif /* CONFIG_WPS_NFC */
    1585                 :            : 
    1586                 :            : 
    1587                 :       3896 : static int hostapd_config_fill(struct hostapd_config *conf,
    1588                 :            :                                struct hostapd_bss_config *bss,
    1589                 :            :                                char *buf, char *pos, int line)
    1590                 :            : {
    1591                 :       3896 :         int errors = 0;
    1592                 :            : 
    1593                 :            :         {
    1594         [ +  + ]:       3896 :                 if (os_strcmp(buf, "interface") == 0) {
    1595                 :         23 :                         os_strlcpy(conf->bss[0]->iface, pos,
    1596                 :            :                                    sizeof(conf->bss[0]->iface));
    1597         [ -  + ]:       3873 :                 } else if (os_strcmp(buf, "bridge") == 0) {
    1598                 :          0 :                         os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
    1599         [ -  + ]:       3873 :                 } else if (os_strcmp(buf, "vlan_bridge") == 0) {
    1600                 :          0 :                         os_strlcpy(bss->vlan_bridge, pos,
    1601                 :            :                                    sizeof(bss->vlan_bridge));
    1602         [ -  + ]:       3873 :                 } else if (os_strcmp(buf, "wds_bridge") == 0) {
    1603                 :          0 :                         os_strlcpy(bss->wds_bridge, pos,
    1604                 :            :                                    sizeof(bss->wds_bridge));
    1605         [ +  + ]:       3873 :                 } else if (os_strcmp(buf, "driver") == 0) {
    1606                 :            :                         int j;
    1607                 :            :                         /* clear to get error below if setting is invalid */
    1608                 :        217 :                         conf->driver = NULL;
    1609         [ +  - ]:        219 :                         for (j = 0; wpa_drivers[j]; j++) {
    1610         [ +  + ]:        219 :                                 if (os_strcmp(pos, wpa_drivers[j]->name) == 0)
    1611                 :            :                                 {
    1612                 :        217 :                                         conf->driver = wpa_drivers[j];
    1613                 :        217 :                                         break;
    1614                 :            :                                 }
    1615                 :            :                         }
    1616         [ -  + ]:        217 :                         if (conf->driver == NULL) {
    1617                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid/"
    1618                 :            :                                            "unknown driver '%s'", line, pos);
    1619                 :          0 :                                 errors++;
    1620                 :            :                         }
    1621         [ -  + ]:       3656 :                 } else if (os_strcmp(buf, "debug") == 0) {
    1622                 :          0 :                         wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
    1623                 :            :                                    "configuration variable is not used "
    1624                 :            :                                    "anymore", line);
    1625         [ -  + ]:       3656 :                 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
    1626                 :          0 :                         bss->logger_syslog_level = atoi(pos);
    1627         [ +  + ]:       3656 :                 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
    1628                 :        193 :                         bss->logger_stdout_level = atoi(pos);
    1629         [ -  + ]:       3463 :                 } else if (os_strcmp(buf, "logger_syslog") == 0) {
    1630                 :          0 :                         bss->logger_syslog = atoi(pos);
    1631         [ +  + ]:       3463 :                 } else if (os_strcmp(buf, "logger_stdout") == 0) {
    1632                 :        193 :                         bss->logger_stdout = atoi(pos);
    1633         [ -  + ]:       3270 :                 } else if (os_strcmp(buf, "dump_file") == 0) {
    1634                 :          0 :                         wpa_printf(MSG_INFO, "Line %d: DEPRECATED: 'dump_file' configuration variable is not used anymore",
    1635                 :            :                                    line);
    1636         [ +  + ]:       3270 :                 } else if (os_strcmp(buf, "ssid") == 0) {
    1637                 :        227 :                         bss->ssid.ssid_len = os_strlen(pos);
    1638 [ +  - ][ -  + ]:        227 :                         if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
    1639                 :        227 :                             bss->ssid.ssid_len < 1) {
    1640                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
    1641                 :            :                                            "'%s'", line, pos);
    1642                 :          0 :                                 errors++;
    1643                 :            :                         } else {
    1644                 :        227 :                                 os_memcpy(bss->ssid.ssid, pos,
    1645                 :            :                                           bss->ssid.ssid_len);
    1646                 :        227 :                                 bss->ssid.ssid_set = 1;
    1647                 :            :                         }
    1648         [ -  + ]:       3043 :                 } else if (os_strcmp(buf, "ssid2") == 0) {
    1649                 :            :                         size_t slen;
    1650                 :          0 :                         char *str = wpa_config_parse_string(pos, &slen);
    1651 [ #  # ][ #  # ]:          0 :                         if (str == NULL || slen < 1 ||
                 [ #  # ]
    1652                 :          0 :                                    slen > HOSTAPD_MAX_SSID_LEN) {
    1653                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
    1654                 :            :                                            "'%s'", line, pos);
    1655                 :          0 :                                 errors++;
    1656                 :            :                         } else {
    1657                 :          0 :                                 os_memcpy(bss->ssid.ssid, str, slen);
    1658                 :          0 :                                 bss->ssid.ssid_len = slen;
    1659                 :          0 :                                 bss->ssid.ssid_set = 1;
    1660                 :            :                         }
    1661                 :          0 :                         os_free(str);
    1662         [ -  + ]:       3043 :                 } else if (os_strcmp(buf, "utf8_ssid") == 0) {
    1663                 :          0 :                         bss->ssid.utf8_ssid = atoi(pos) > 0;
    1664         [ -  + ]:       3043 :                 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
    1665                 :          0 :                         bss->macaddr_acl = atoi(pos);
    1666 [ #  # ][ #  # ]:          0 :                         if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
    1667         [ #  # ]:          0 :                             bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
    1668                 :          0 :                             bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
    1669                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: unknown "
    1670                 :            :                                            "macaddr_acl %d",
    1671                 :          0 :                                            line, bss->macaddr_acl);
    1672                 :            :                         }
    1673         [ -  + ]:       3043 :                 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
    1674         [ #  # ]:          0 :                         if (hostapd_config_read_maclist(pos, &bss->accept_mac,
    1675                 :            :                                                         &bss->num_accept_mac))
    1676                 :            :                         {
    1677                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Failed to "
    1678                 :            :                                            "read accept_mac_file '%s'",
    1679                 :            :                                            line, pos);
    1680                 :          0 :                                 errors++;
    1681                 :            :                         }
    1682         [ -  + ]:       3043 :                 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
    1683         [ #  # ]:          0 :                         if (hostapd_config_read_maclist(pos, &bss->deny_mac,
    1684                 :            :                                                         &bss->num_deny_mac)) {
    1685                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Failed to "
    1686                 :            :                                            "read deny_mac_file '%s'",
    1687                 :            :                                            line, pos);
    1688                 :          0 :                                 errors++;
    1689                 :            :                         }
    1690         [ -  + ]:       3043 :                 } else if (os_strcmp(buf, "wds_sta") == 0) {
    1691                 :          0 :                         bss->wds_sta = atoi(pos);
    1692         [ -  + ]:       3043 :                 } else if (os_strcmp(buf, "start_disabled") == 0) {
    1693                 :          0 :                         bss->start_disabled = atoi(pos);
    1694         [ -  + ]:       3043 :                 } else if (os_strcmp(buf, "ap_isolate") == 0) {
    1695                 :          0 :                         bss->isolate = atoi(pos);
    1696         [ -  + ]:       3043 :                 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
    1697                 :          0 :                         bss->ap_max_inactivity = atoi(pos);
    1698         [ -  + ]:       3043 :                 } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
    1699                 :          0 :                         bss->skip_inactivity_poll = atoi(pos);
    1700         [ -  + ]:       3043 :                 } else if (os_strcmp(buf, "country_code") == 0) {
    1701                 :          0 :                         os_memcpy(conf->country, pos, 2);
    1702                 :            :                         /* FIX: make this configurable */
    1703                 :          0 :                         conf->country[2] = ' ';
    1704         [ -  + ]:       3043 :                 } else if (os_strcmp(buf, "ieee80211d") == 0) {
    1705                 :          0 :                         conf->ieee80211d = atoi(pos);
    1706         [ -  + ]:       3043 :                 } else if (os_strcmp(buf, "ieee80211h") == 0) {
    1707                 :          0 :                         conf->ieee80211h = atoi(pos);
    1708         [ +  + ]:       3043 :                 } else if (os_strcmp(buf, "ieee8021x") == 0) {
    1709                 :         81 :                         bss->ieee802_1x = atoi(pos);
    1710         [ -  + ]:       2962 :                 } else if (os_strcmp(buf, "eapol_version") == 0) {
    1711                 :          0 :                         bss->eapol_version = atoi(pos);
    1712 [ #  # ][ #  # ]:          0 :                         if (bss->eapol_version < 1 ||
    1713                 :          0 :                             bss->eapol_version > 2) {
    1714                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid EAPOL "
    1715                 :            :                                            "version (%d): '%s'.",
    1716                 :            :                                            line, bss->eapol_version, pos);
    1717                 :          0 :                                 errors++;
    1718                 :            :                         } else
    1719                 :          0 :                                 wpa_printf(MSG_DEBUG, "eapol_version=%d",
    1720                 :            :                                            bss->eapol_version);
    1721                 :            : #ifdef EAP_SERVER
    1722         [ -  + ]:       2962 :                 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
    1723                 :          0 :                         bss->eap_server = atoi(pos);
    1724                 :          0 :                         wpa_printf(MSG_ERROR, "Line %d: obsolete "
    1725                 :            :                                    "eap_authenticator used; this has been "
    1726                 :            :                                    "renamed to eap_server", line);
    1727         [ +  + ]:       2962 :                 } else if (os_strcmp(buf, "eap_server") == 0) {
    1728                 :         35 :                         bss->eap_server = atoi(pos);
    1729         [ +  + ]:       2927 :                 } else if (os_strcmp(buf, "eap_user_file") == 0) {
    1730         [ -  + ]:          1 :                         if (hostapd_config_read_eap_user(pos, bss))
    1731                 :          0 :                                 errors++;
    1732         [ +  + ]:       2926 :                 } else if (os_strcmp(buf, "ca_cert") == 0) {
    1733                 :          1 :                         os_free(bss->ca_cert);
    1734                 :          1 :                         bss->ca_cert = os_strdup(pos);
    1735         [ +  + ]:       2925 :                 } else if (os_strcmp(buf, "server_cert") == 0) {
    1736                 :          1 :                         os_free(bss->server_cert);
    1737                 :          1 :                         bss->server_cert = os_strdup(pos);
    1738         [ +  + ]:       2924 :                 } else if (os_strcmp(buf, "private_key") == 0) {
    1739                 :          1 :                         os_free(bss->private_key);
    1740                 :          1 :                         bss->private_key = os_strdup(pos);
    1741         [ -  + ]:       2923 :                 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
    1742                 :          0 :                         os_free(bss->private_key_passwd);
    1743                 :          0 :                         bss->private_key_passwd = os_strdup(pos);
    1744         [ -  + ]:       2923 :                 } else if (os_strcmp(buf, "check_crl") == 0) {
    1745                 :          0 :                         bss->check_crl = atoi(pos);
    1746         [ -  + ]:       2923 :                 } else if (os_strcmp(buf, "ocsp_stapling_response") == 0) {
    1747                 :          0 :                         os_free(bss->ocsp_stapling_response);
    1748                 :          0 :                         bss->ocsp_stapling_response = os_strdup(pos);
    1749         [ +  + ]:       2923 :                 } else if (os_strcmp(buf, "dh_file") == 0) {
    1750                 :          1 :                         os_free(bss->dh_file);
    1751                 :          1 :                         bss->dh_file = os_strdup(pos);
    1752         [ +  + ]:       2922 :                 } else if (os_strcmp(buf, "fragment_size") == 0) {
    1753                 :          1 :                         bss->fragment_size = atoi(pos);
    1754                 :            : #ifdef EAP_SERVER_FAST
    1755         [ +  + ]:       2921 :                 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
    1756                 :          1 :                         os_free(bss->pac_opaque_encr_key);
    1757                 :          1 :                         bss->pac_opaque_encr_key = os_malloc(16);
    1758         [ -  + ]:          1 :                         if (bss->pac_opaque_encr_key == NULL) {
    1759                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: No memory for "
    1760                 :            :                                            "pac_opaque_encr_key", line);
    1761                 :          0 :                                 errors++;
    1762         [ -  + ]:          1 :                         } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
    1763                 :            :                                               16)) {
    1764                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Invalid "
    1765                 :            :                                            "pac_opaque_encr_key", line);
    1766                 :          0 :                                 errors++;
    1767                 :            :                         }
    1768         [ +  + ]:       2920 :                 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
    1769                 :          1 :                         size_t idlen = os_strlen(pos);
    1770         [ -  + ]:          1 :                         if (idlen & 1) {
    1771                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Invalid "
    1772                 :            :                                            "eap_fast_a_id", line);
    1773                 :          0 :                                 errors++;
    1774                 :            :                         } else {
    1775                 :          1 :                                 os_free(bss->eap_fast_a_id);
    1776                 :          1 :                                 bss->eap_fast_a_id = os_malloc(idlen / 2);
    1777   [ +  -  -  + ]:          2 :                                 if (bss->eap_fast_a_id == NULL ||
    1778                 :          1 :                                     hexstr2bin(pos, bss->eap_fast_a_id,
    1779                 :            :                                                idlen / 2)) {
    1780                 :          0 :                                         wpa_printf(MSG_ERROR, "Line %d: "
    1781                 :            :                                                    "Failed to parse "
    1782                 :            :                                                    "eap_fast_a_id", line);
    1783                 :          0 :                                         errors++;
    1784                 :            :                                 } else
    1785                 :          1 :                                         bss->eap_fast_a_id_len = idlen / 2;
    1786                 :            :                         }
    1787         [ +  + ]:       2919 :                 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
    1788                 :          1 :                         os_free(bss->eap_fast_a_id_info);
    1789                 :          1 :                         bss->eap_fast_a_id_info = os_strdup(pos);
    1790         [ -  + ]:       2918 :                 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
    1791                 :          0 :                         bss->eap_fast_prov = atoi(pos);
    1792         [ -  + ]:       2918 :                 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
    1793                 :          0 :                         bss->pac_key_lifetime = atoi(pos);
    1794         [ -  + ]:       2918 :                 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
    1795                 :          0 :                         bss->pac_key_refresh_time = atoi(pos);
    1796                 :            : #endif /* EAP_SERVER_FAST */
    1797                 :            : #ifdef EAP_SERVER_SIM
    1798         [ +  + ]:       2918 :                 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
    1799                 :          1 :                         os_free(bss->eap_sim_db);
    1800                 :          1 :                         bss->eap_sim_db = os_strdup(pos);
    1801         [ +  + ]:       2917 :                 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
    1802                 :          1 :                         bss->eap_sim_aka_result_ind = atoi(pos);
    1803                 :            : #endif /* EAP_SERVER_SIM */
    1804                 :            : #ifdef EAP_SERVER_TNC
    1805         [ -  + ]:       2916 :                 } else if (os_strcmp(buf, "tnc") == 0) {
    1806                 :          0 :                         bss->tnc = atoi(pos);
    1807                 :            : #endif /* EAP_SERVER_TNC */
    1808                 :            : #ifdef EAP_SERVER_PWD
    1809         [ -  + ]:       2916 :                 } else if (os_strcmp(buf, "pwd_group") == 0) {
    1810                 :          0 :                         bss->pwd_group = atoi(pos);
    1811                 :            : #endif /* EAP_SERVER_PWD */
    1812                 :            : #endif /* EAP_SERVER */
    1813         [ -  + ]:       2916 :                 } else if (os_strcmp(buf, "eap_message") == 0) {
    1814                 :            :                         char *term;
    1815                 :          0 :                         bss->eap_req_id_text = os_strdup(pos);
    1816         [ #  # ]:          0 :                         if (bss->eap_req_id_text == NULL) {
    1817                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Failed to "
    1818                 :            :                                            "allocate memory for "
    1819                 :            :                                            "eap_req_id_text", line);
    1820                 :          0 :                                 errors++;
    1821                 :          0 :                                 return errors;
    1822                 :            :                         }
    1823                 :          0 :                         bss->eap_req_id_text_len =
    1824                 :          0 :                                 os_strlen(bss->eap_req_id_text);
    1825                 :          0 :                         term = os_strstr(bss->eap_req_id_text, "\\0");
    1826         [ #  # ]:          0 :                         if (term) {
    1827                 :          0 :                                 *term++ = '\0';
    1828                 :          0 :                                 os_memmove(term, term + 1,
    1829                 :            :                                            bss->eap_req_id_text_len -
    1830                 :            :                                            (term - bss->eap_req_id_text) - 1);
    1831                 :          0 :                                 bss->eap_req_id_text_len--;
    1832                 :            :                         }
    1833         [ +  + ]:       2916 :                 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
    1834                 :          2 :                         bss->default_wep_key_len = atoi(pos);
    1835         [ -  + ]:          2 :                         if (bss->default_wep_key_len > 13) {
    1836                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
    1837                 :            :                                            "key len %lu (= %lu bits)", line,
    1838                 :            :                                            (unsigned long)
    1839                 :            :                                            bss->default_wep_key_len,
    1840                 :            :                                            (unsigned long)
    1841                 :          0 :                                            bss->default_wep_key_len * 8);
    1842                 :          0 :                                 errors++;
    1843                 :            :                         }
    1844         [ +  + ]:       2914 :                 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
    1845                 :          2 :                         bss->individual_wep_key_len = atoi(pos);
    1846 [ -  + ][ +  - ]:          2 :                         if (bss->individual_wep_key_len < 0 ||
    1847                 :          2 :                             bss->individual_wep_key_len > 13) {
    1848                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
    1849                 :            :                                            "key len %d (= %d bits)", line,
    1850                 :            :                                            bss->individual_wep_key_len,
    1851                 :          0 :                                            bss->individual_wep_key_len * 8);
    1852                 :          0 :                                 errors++;
    1853                 :            :                         }
    1854         [ -  + ]:       2912 :                 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
    1855                 :          0 :                         bss->wep_rekeying_period = atoi(pos);
    1856         [ #  # ]:          0 :                         if (bss->wep_rekeying_period < 0) {
    1857                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
    1858                 :            :                                            "period %d",
    1859                 :            :                                            line, bss->wep_rekeying_period);
    1860                 :          0 :                                 errors++;
    1861                 :            :                         }
    1862         [ -  + ]:       2912 :                 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
    1863                 :          0 :                         bss->eap_reauth_period = atoi(pos);
    1864         [ #  # ]:          0 :                         if (bss->eap_reauth_period < 0) {
    1865                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
    1866                 :            :                                            "period %d",
    1867                 :            :                                            line, bss->eap_reauth_period);
    1868                 :          0 :                                 errors++;
    1869                 :            :                         }
    1870         [ -  + ]:       2912 :                 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
    1871                 :          0 :                         bss->eapol_key_index_workaround = atoi(pos);
    1872                 :            : #ifdef CONFIG_IAPP
    1873                 :            :                 } else if (os_strcmp(buf, "iapp_interface") == 0) {
    1874                 :            :                         bss->ieee802_11f = 1;
    1875                 :            :                         os_strlcpy(bss->iapp_iface, pos,
    1876                 :            :                                    sizeof(bss->iapp_iface));
    1877                 :            : #endif /* CONFIG_IAPP */
    1878         [ -  + ]:       2912 :                 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
    1879         [ #  # ]:          0 :                         if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
    1880                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
    1881                 :            :                                            "address '%s'", line, pos);
    1882                 :          0 :                                 errors++;
    1883                 :            :                         }
    1884         [ +  + ]:       2912 :                 } else if (os_strcmp(buf, "nas_identifier") == 0) {
    1885                 :         54 :                         bss->nas_identifier = os_strdup(pos);
    1886                 :            : #ifndef CONFIG_NO_RADIUS
    1887         [ +  + ]:       2858 :                 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
    1888         [ -  + ]:         81 :                         if (hostapd_config_read_radius_addr(
    1889                 :         81 :                                     &bss->radius->auth_servers,
    1890                 :         81 :                                     &bss->radius->num_auth_servers, pos, 1812,
    1891                 :         81 :                                     &bss->radius->auth_server)) {
    1892                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
    1893                 :            :                                            "address '%s'", line, pos);
    1894                 :          0 :                                 errors++;
    1895                 :            :                         }
    1896 [ +  + ][ +  + ]:       2777 :                 } else if (bss->radius->auth_server &&
    1897                 :       1257 :                            os_strcmp(buf, "auth_server_port") == 0) {
    1898                 :         81 :                         bss->radius->auth_server->port = atoi(pos);
    1899 [ +  + ][ +  + ]:       2696 :                 } else if (bss->radius->auth_server &&
    1900                 :         81 :                            os_strcmp(buf, "auth_server_shared_secret") == 0) {
    1901                 :         81 :                         int len = os_strlen(pos);
    1902         [ -  + ]:         81 :                         if (len == 0) {
    1903                 :            :                                 /* RFC 2865, Ch. 3 */
    1904                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: empty shared "
    1905                 :            :                                            "secret is not allowed.", line);
    1906                 :          0 :                                 errors++;
    1907                 :            :                         }
    1908                 :        162 :                         bss->radius->auth_server->shared_secret =
    1909                 :         81 :                                 (u8 *) os_strdup(pos);
    1910                 :         81 :                         bss->radius->auth_server->shared_secret_len = len;
    1911         [ +  + ]:       2615 :                 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
    1912         [ -  + ]:          1 :                         if (hostapd_config_read_radius_addr(
    1913                 :          1 :                                     &bss->radius->acct_servers,
    1914                 :          1 :                                     &bss->radius->num_acct_servers, pos, 1813,
    1915                 :          1 :                                     &bss->radius->acct_server)) {
    1916                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
    1917                 :            :                                            "address '%s'", line, pos);
    1918                 :          0 :                                 errors++;
    1919                 :            :                         }
    1920 [ +  + ][ +  + ]:       2614 :                 } else if (bss->radius->acct_server &&
    1921                 :          2 :                            os_strcmp(buf, "acct_server_port") == 0) {
    1922                 :          1 :                         bss->radius->acct_server->port = atoi(pos);
    1923 [ +  + ][ +  - ]:       2613 :                 } else if (bss->radius->acct_server &&
    1924                 :          1 :                            os_strcmp(buf, "acct_server_shared_secret") == 0) {
    1925                 :          1 :                         int len = os_strlen(pos);
    1926         [ -  + ]:          1 :                         if (len == 0) {
    1927                 :            :                                 /* RFC 2865, Ch. 3 */
    1928                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: empty shared "
    1929                 :            :                                            "secret is not allowed.", line);
    1930                 :          0 :                                 errors++;
    1931                 :            :                         }
    1932                 :          2 :                         bss->radius->acct_server->shared_secret =
    1933                 :          1 :                                 (u8 *) os_strdup(pos);
    1934                 :          1 :                         bss->radius->acct_server->shared_secret_len = len;
    1935         [ -  + ]:       2612 :                 } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
    1936                 :            :                            0) {
    1937                 :          0 :                         bss->radius->retry_primary_interval = atoi(pos);
    1938         [ -  + ]:       2612 :                 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
    1939                 :            :                 {
    1940                 :          0 :                         bss->acct_interim_interval = atoi(pos);
    1941         [ -  + ]:       2612 :                 } else if (os_strcmp(buf, "radius_request_cui") == 0) {
    1942                 :          0 :                         bss->radius_request_cui = atoi(pos);
    1943         [ -  + ]:       2612 :                 } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
    1944                 :            :                         struct hostapd_radius_attr *attr, *a;
    1945                 :          0 :                         attr = hostapd_parse_radius_attr(pos);
    1946         [ #  # ]:          0 :                         if (attr == NULL) {
    1947                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
    1948                 :            :                                            "radius_auth_req_attr", line);
    1949                 :          0 :                                 errors++;
    1950         [ #  # ]:          0 :                         } else if (bss->radius_auth_req_attr == NULL) {
    1951                 :          0 :                                 bss->radius_auth_req_attr = attr;
    1952                 :            :                         } else {
    1953                 :          0 :                                 a = bss->radius_auth_req_attr;
    1954         [ #  # ]:          0 :                                 while (a->next)
    1955                 :          0 :                                         a = a->next;
    1956                 :          0 :                                 a->next = attr;
    1957                 :            :                         }
    1958         [ -  + ]:       2612 :                 } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
    1959                 :            :                         struct hostapd_radius_attr *attr, *a;
    1960                 :          0 :                         attr = hostapd_parse_radius_attr(pos);
    1961         [ #  # ]:          0 :                         if (attr == NULL) {
    1962                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
    1963                 :            :                                            "radius_acct_req_attr", line);
    1964                 :          0 :                                 errors++;
    1965         [ #  # ]:          0 :                         } else if (bss->radius_acct_req_attr == NULL) {
    1966                 :          0 :                                 bss->radius_acct_req_attr = attr;
    1967                 :            :                         } else {
    1968                 :          0 :                                 a = bss->radius_acct_req_attr;
    1969         [ #  # ]:          0 :                                 while (a->next)
    1970                 :          0 :                                         a = a->next;
    1971                 :          0 :                                 a->next = attr;
    1972                 :            :                         }
    1973         [ -  + ]:       2612 :                 } else if (os_strcmp(buf, "radius_das_port") == 0) {
    1974                 :          0 :                         bss->radius_das_port = atoi(pos);
    1975         [ -  + ]:       2612 :                 } else if (os_strcmp(buf, "radius_das_client") == 0) {
    1976         [ #  # ]:          0 :                         if (hostapd_parse_das_client(bss, pos) < 0) {
    1977                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
    1978                 :            :                                            "DAS client", line);
    1979                 :          0 :                                 errors++;
    1980                 :            :                         }
    1981         [ -  + ]:       2612 :                 } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
    1982                 :          0 :                         bss->radius_das_time_window = atoi(pos);
    1983         [ -  + ]:       2612 :                 } else if (os_strcmp(buf, "radius_das_require_event_timestamp")
    1984                 :            :                            == 0) {
    1985                 :          0 :                         bss->radius_das_require_event_timestamp = atoi(pos);
    1986                 :            : #endif /* CONFIG_NO_RADIUS */
    1987         [ -  + ]:       2612 :                 } else if (os_strcmp(buf, "auth_algs") == 0) {
    1988                 :          0 :                         bss->auth_algs = atoi(pos);
    1989         [ #  # ]:          0 :                         if (bss->auth_algs == 0) {
    1990                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: no "
    1991                 :            :                                            "authentication algorithms allowed",
    1992                 :            :                                            line);
    1993                 :          0 :                                 errors++;
    1994                 :            :                         }
    1995         [ -  + ]:       2612 :                 } else if (os_strcmp(buf, "max_num_sta") == 0) {
    1996                 :          0 :                         bss->max_num_sta = atoi(pos);
    1997 [ #  # ][ #  # ]:          0 :                         if (bss->max_num_sta < 0 ||
    1998                 :          0 :                             bss->max_num_sta > MAX_STA_COUNT) {
    1999                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Invalid "
    2000                 :            :                                            "max_num_sta=%d; allowed range "
    2001                 :            :                                            "0..%d", line, bss->max_num_sta,
    2002                 :            :                                            MAX_STA_COUNT);
    2003                 :          0 :                                 errors++;
    2004                 :            :                         }
    2005         [ +  + ]:       2612 :                 } else if (os_strcmp(buf, "wpa") == 0) {
    2006                 :        150 :                         bss->wpa = atoi(pos);
    2007         [ -  + ]:       2462 :                 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
    2008                 :          0 :                         bss->wpa_group_rekey = atoi(pos);
    2009         [ -  + ]:       2462 :                 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
    2010                 :          0 :                         bss->wpa_strict_rekey = atoi(pos);
    2011         [ -  + ]:       2462 :                 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
    2012                 :          0 :                         bss->wpa_gmk_rekey = atoi(pos);
    2013         [ -  + ]:       2462 :                 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
    2014                 :          0 :                         bss->wpa_ptk_rekey = atoi(pos);
    2015         [ +  + ]:       2462 :                 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
    2016                 :         74 :                         int len = os_strlen(pos);
    2017 [ +  - ][ -  + ]:         74 :                         if (len < 8 || len > 63) {
    2018                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid WPA "
    2019                 :            :                                            "passphrase length %d (expected "
    2020                 :            :                                            "8..63)", line, len);
    2021                 :          0 :                                 errors++;
    2022                 :            :                         } else {
    2023                 :         74 :                                 os_free(bss->ssid.wpa_passphrase);
    2024                 :         74 :                                 bss->ssid.wpa_passphrase = os_strdup(pos);
    2025         [ +  - ]:         74 :                                 if (bss->ssid.wpa_passphrase) {
    2026                 :         74 :                                         os_free(bss->ssid.wpa_psk);
    2027                 :         74 :                                         bss->ssid.wpa_psk = NULL;
    2028                 :         74 :                                         bss->ssid.wpa_passphrase_set = 1;
    2029                 :            :                                 }
    2030                 :            :                         }
    2031         [ -  + ]:       2388 :                 } else if (os_strcmp(buf, "wpa_psk") == 0) {
    2032                 :          0 :                         os_free(bss->ssid.wpa_psk);
    2033                 :          0 :                         bss->ssid.wpa_psk =
    2034                 :          0 :                                 os_zalloc(sizeof(struct hostapd_wpa_psk));
    2035         [ #  # ]:          0 :                         if (bss->ssid.wpa_psk == NULL)
    2036                 :          0 :                                 errors++;
    2037         [ #  # ]:          0 :                         else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
    2038         [ #  # ]:          0 :                                             PMK_LEN) ||
    2039                 :          0 :                                  pos[PMK_LEN * 2] != '\0') {
    2040                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK "
    2041                 :            :                                            "'%s'.", line, pos);
    2042                 :          0 :                                 errors++;
    2043                 :            :                         } else {
    2044                 :          0 :                                 bss->ssid.wpa_psk->group = 1;
    2045                 :          0 :                                 os_free(bss->ssid.wpa_passphrase);
    2046                 :          0 :                                 bss->ssid.wpa_passphrase = NULL;
    2047                 :          0 :                                 bss->ssid.wpa_psk_set = 1;
    2048                 :            :                         }
    2049         [ -  + ]:       2388 :                 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
    2050                 :          0 :                         os_free(bss->ssid.wpa_psk_file);
    2051                 :          0 :                         bss->ssid.wpa_psk_file = os_strdup(pos);
    2052         [ #  # ]:          0 :                         if (!bss->ssid.wpa_psk_file) {
    2053                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: allocation "
    2054                 :            :                                            "failed", line);
    2055                 :          0 :                                 errors++;
    2056                 :            :                         }
    2057         [ +  + ]:       2388 :                 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
    2058                 :        150 :                         bss->wpa_key_mgmt =
    2059                 :        150 :                                 hostapd_config_parse_key_mgmt(line, pos);
    2060         [ -  + ]:        150 :                         if (bss->wpa_key_mgmt == -1)
    2061                 :          0 :                                 errors++;
    2062         [ -  + ]:       2238 :                 } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
    2063                 :          0 :                         bss->wpa_psk_radius = atoi(pos);
    2064 [ #  # ][ #  # ]:          0 :                         if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
    2065         [ #  # ]:          0 :                             bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
    2066                 :          0 :                             bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) {
    2067                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: unknown "
    2068                 :            :                                            "wpa_psk_radius %d",
    2069                 :          0 :                                            line, bss->wpa_psk_radius);
    2070                 :          0 :                                 errors++;
    2071                 :            :                         }
    2072         [ +  + ]:       2238 :                 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
    2073                 :          7 :                         bss->wpa_pairwise =
    2074                 :          7 :                                 hostapd_config_parse_cipher(line, pos);
    2075 [ -  + ][ +  - ]:          7 :                         if (bss->wpa_pairwise == -1 ||
    2076                 :          7 :                             bss->wpa_pairwise == 0)
    2077                 :          0 :                                 errors++;
    2078         [ -  + ]:          7 :                         else if (bss->wpa_pairwise &
    2079                 :            :                                  (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
    2080                 :            :                                   WPA_CIPHER_WEP104)) {
    2081                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: unsupported "
    2082                 :            :                                            "pairwise cipher suite '%s'",
    2083                 :            :                                            bss->wpa_pairwise, pos);
    2084                 :          7 :                                 errors++;
    2085                 :            :                         }
    2086         [ +  + ]:       2231 :                 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
    2087                 :        148 :                         bss->rsn_pairwise =
    2088                 :        148 :                                 hostapd_config_parse_cipher(line, pos);
    2089 [ -  + ][ +  - ]:        148 :                         if (bss->rsn_pairwise == -1 ||
    2090                 :        148 :                             bss->rsn_pairwise == 0)
    2091                 :          0 :                                 errors++;
    2092         [ -  + ]:        148 :                         else if (bss->rsn_pairwise &
    2093                 :            :                                  (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
    2094                 :            :                                   WPA_CIPHER_WEP104)) {
    2095                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: unsupported "
    2096                 :            :                                            "pairwise cipher suite '%s'",
    2097                 :            :                                            bss->rsn_pairwise, pos);
    2098                 :        148 :                                 errors++;
    2099                 :            :                         }
    2100                 :            : #ifdef CONFIG_RSN_PREAUTH
    2101         [ -  + ]:       2083 :                 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
    2102                 :          0 :                         bss->rsn_preauth = atoi(pos);
    2103         [ -  + ]:       2083 :                 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
    2104                 :          0 :                         bss->rsn_preauth_interfaces = os_strdup(pos);
    2105                 :            : #endif /* CONFIG_RSN_PREAUTH */
    2106                 :            : #ifdef CONFIG_PEERKEY
    2107         [ +  + ]:       2083 :                 } else if (os_strcmp(buf, "peerkey") == 0) {
    2108                 :          1 :                         bss->peerkey = atoi(pos);
    2109                 :            : #endif /* CONFIG_PEERKEY */
    2110                 :            : #ifdef CONFIG_IEEE80211R
    2111         [ +  + ]:       2082 :                 } else if (os_strcmp(buf, "mobility_domain") == 0) {
    2112   [ +  -  -  + ]:         32 :                         if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
    2113                 :         16 :                             hexstr2bin(pos, bss->mobility_domain,
    2114                 :            :                                        MOBILITY_DOMAIN_ID_LEN) != 0) {
    2115                 :          0 :                                 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
    2116                 :            :                                            "mobility_domain '%s'", line, pos);
    2117                 :          0 :                                 errors++;
    2118                 :          0 :                                 return errors;
    2119                 :            :                         }
    2120         [ +  + ]:       2066 :                 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
    2121   [ +  -  -  + ]:         32 :                         if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
    2122                 :         16 :                             hexstr2bin(pos, bss->r1_key_holder,
    2123                 :            :                                        FT_R1KH_ID_LEN) != 0) {
    2124                 :          0 :                                 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
    2125                 :            :                                            "r1_key_holder '%s'", line, pos);
    2126                 :          0 :                                 errors++;
    2127                 :          0 :                                 return errors;
    2128                 :            :                         }
    2129         [ +  + ]:       2050 :                 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
    2130                 :         16 :                         bss->r0_key_lifetime = atoi(pos);
    2131         [ +  + ]:       2034 :                 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
    2132                 :         16 :                         bss->reassociation_deadline = atoi(pos);
    2133         [ +  + ]:       2018 :                 } else if (os_strcmp(buf, "r0kh") == 0) {
    2134         [ -  + ]:         32 :                         if (add_r0kh(bss, pos) < 0) {
    2135                 :          0 :                                 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
    2136                 :            :                                            "r0kh '%s'", line, pos);
    2137                 :          0 :                                 errors++;
    2138                 :          0 :                                 return errors;
    2139                 :            :                         }
    2140         [ +  + ]:       1986 :                 } else if (os_strcmp(buf, "r1kh") == 0) {
    2141         [ -  + ]:         16 :                         if (add_r1kh(bss, pos) < 0) {
    2142                 :          0 :                                 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
    2143                 :            :                                            "r1kh '%s'", line, pos);
    2144                 :          0 :                                 errors++;
    2145                 :          0 :                                 return errors;
    2146                 :            :                         }
    2147         [ +  + ]:       1970 :                 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
    2148                 :         16 :                         bss->pmk_r1_push = atoi(pos);
    2149         [ -  + ]:       1954 :                 } else if (os_strcmp(buf, "ft_over_ds") == 0) {
    2150                 :          0 :                         bss->ft_over_ds = atoi(pos);
    2151                 :            : #endif /* CONFIG_IEEE80211R */
    2152                 :            : #ifndef CONFIG_NO_CTRL_IFACE
    2153         [ +  + ]:       1954 :                 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
    2154                 :         29 :                         os_free(bss->ctrl_interface);
    2155                 :         29 :                         bss->ctrl_interface = os_strdup(pos);
    2156         [ -  + ]:       1925 :                 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
    2157                 :            : #ifndef CONFIG_NATIVE_WINDOWS
    2158                 :            :                         struct group *grp;
    2159                 :            :                         char *endp;
    2160                 :          0 :                         const char *group = pos;
    2161                 :            : 
    2162                 :          0 :                         grp = getgrnam(group);
    2163         [ #  # ]:          0 :                         if (grp) {
    2164                 :          0 :                                 bss->ctrl_interface_gid = grp->gr_gid;
    2165                 :          0 :                                 bss->ctrl_interface_gid_set = 1;
    2166                 :          0 :                                 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
    2167                 :            :                                            " (from group name '%s')",
    2168                 :            :                                            bss->ctrl_interface_gid, group);
    2169                 :          0 :                                 return errors;
    2170                 :            :                         }
    2171                 :            : 
    2172                 :            :                         /* Group name not found - try to parse this as gid */
    2173                 :          0 :                         bss->ctrl_interface_gid = strtol(group, &endp, 10);
    2174 [ #  # ][ #  # ]:          0 :                         if (*group == '\0' || *endp != '\0') {
    2175                 :          0 :                                 wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
    2176                 :            :                                            "'%s'", line, group);
    2177                 :          0 :                                 errors++;
    2178                 :          0 :                                 return errors;
    2179                 :            :                         }
    2180                 :          0 :                         bss->ctrl_interface_gid_set = 1;
    2181                 :          0 :                         wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
    2182                 :            :                                    bss->ctrl_interface_gid);
    2183                 :            : #endif /* CONFIG_NATIVE_WINDOWS */
    2184                 :            : #endif /* CONFIG_NO_CTRL_IFACE */
    2185                 :            : #ifdef RADIUS_SERVER
    2186         [ +  + ]:       1925 :                 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
    2187                 :          1 :                         os_free(bss->radius_server_clients);
    2188                 :          1 :                         bss->radius_server_clients = os_strdup(pos);
    2189         [ -  + ]:       1924 :                 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
    2190                 :          0 :                         bss->radius_server_auth_port = atoi(pos);
    2191         [ -  + ]:       1924 :                 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
    2192                 :          0 :                         bss->radius_server_ipv6 = atoi(pos);
    2193                 :            : #endif /* RADIUS_SERVER */
    2194         [ -  + ]:       1924 :                 } else if (os_strcmp(buf, "test_socket") == 0) {
    2195                 :          0 :                         os_free(bss->test_socket);
    2196                 :          0 :                         bss->test_socket = os_strdup(pos);
    2197         [ -  + ]:       1924 :                 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
    2198                 :          0 :                         bss->use_pae_group_addr = atoi(pos);
    2199         [ +  + ]:       1924 :                 } else if (os_strcmp(buf, "hw_mode") == 0) {
    2200         [ -  + ]:        216 :                         if (os_strcmp(pos, "a") == 0)
    2201                 :          0 :                                 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
    2202         [ -  + ]:        216 :                         else if (os_strcmp(pos, "b") == 0)
    2203                 :          0 :                                 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
    2204         [ +  - ]:        216 :                         else if (os_strcmp(pos, "g") == 0)
    2205                 :        216 :                                 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
    2206         [ #  # ]:          0 :                         else if (os_strcmp(pos, "ad") == 0)
    2207                 :          0 :                                 conf->hw_mode = HOSTAPD_MODE_IEEE80211AD;
    2208                 :            :                         else {
    2209                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: unknown "
    2210                 :            :                                            "hw_mode '%s'", line, pos);
    2211                 :          0 :                                 errors++;
    2212                 :            :                         }
    2213         [ -  + ]:       1708 :                 } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
    2214         [ #  # ]:          0 :                         if (os_strcmp(pos, "a") == 0)
    2215                 :          0 :                                 bss->wps_rf_bands = WPS_RF_50GHZ;
    2216 [ #  # ][ #  # ]:          0 :                         else if (os_strcmp(pos, "g") == 0 ||
    2217                 :          0 :                                  os_strcmp(pos, "b") == 0)
    2218                 :          0 :                                 bss->wps_rf_bands = WPS_RF_24GHZ;
    2219 [ #  # ][ #  # ]:          0 :                         else if (os_strcmp(pos, "ag") == 0 ||
    2220                 :          0 :                                  os_strcmp(pos, "ga") == 0)
    2221                 :          0 :                                 bss->wps_rf_bands =
    2222                 :            :                                         WPS_RF_24GHZ | WPS_RF_50GHZ;
    2223                 :            :                         else {
    2224                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: unknown "
    2225                 :            :                                            "wps_rf_band '%s'", line, pos);
    2226                 :          0 :                                 errors++;
    2227                 :            :                         }
    2228         [ +  + ]:       1708 :                 } else if (os_strcmp(buf, "channel") == 0) {
    2229         [ -  + ]:        227 :                         if (os_strcmp(pos, "acs_survey") == 0) {
    2230                 :            : #ifndef CONFIG_ACS
    2231                 :            :                                 wpa_printf(MSG_ERROR, "Line %d: tries to enable ACS but CONFIG_ACS disabled",
    2232                 :            :                                            line);
    2233                 :            :                                 errors++;
    2234                 :            : #endif /* CONFIG_ACS */
    2235                 :          0 :                                 conf->channel = 0;
    2236                 :            :                         } else
    2237                 :        227 :                                 conf->channel = atoi(pos);
    2238         [ -  + ]:       1481 :                 } else if (os_strcmp(buf, "beacon_int") == 0) {
    2239                 :          0 :                         int val = atoi(pos);
    2240                 :            :                         /* MIB defines range as 1..65535, but very small values
    2241                 :            :                          * cause problems with the current implementation.
    2242                 :            :                          * Since it is unlikely that this small numbers are
    2243                 :            :                          * useful in real life scenarios, do not allow beacon
    2244                 :            :                          * period to be set below 15 TU. */
    2245 [ #  # ][ #  # ]:          0 :                         if (val < 15 || val > 65535) {
    2246                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
    2247                 :            :                                            "beacon_int %d (expected "
    2248                 :            :                                            "15..65535)", line, val);
    2249                 :          0 :                                 errors++;
    2250                 :            :                         } else
    2251                 :          0 :                                 conf->beacon_int = val;
    2252                 :            : #ifdef CONFIG_ACS
    2253         [ -  + ]:       1481 :                 } else if (os_strcmp(buf, "acs_num_scans") == 0) {
    2254                 :          0 :                         int val = atoi(pos);
    2255 [ #  # ][ #  # ]:          0 :                         if (val <= 0 || val > 100) {
    2256                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid acs_num_scans %d (expected 1..100)",
    2257                 :            :                                            line, val);
    2258                 :          0 :                                 errors++;
    2259                 :            :                         } else
    2260                 :          0 :                                 conf->acs_num_scans = val;
    2261                 :            : #endif /* CONFIG_ACS */
    2262         [ -  + ]:       1481 :                 } else if (os_strcmp(buf, "dtim_period") == 0) {
    2263                 :          0 :                         bss->dtim_period = atoi(pos);
    2264 [ #  # ][ #  # ]:          0 :                         if (bss->dtim_period < 1 || bss->dtim_period > 255) {
    2265                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
    2266                 :            :                                            "dtim_period %d",
    2267                 :            :                                            line, bss->dtim_period);
    2268                 :          0 :                                 errors++;
    2269                 :            :                         }
    2270         [ -  + ]:       1481 :                 } else if (os_strcmp(buf, "rts_threshold") == 0) {
    2271                 :          0 :                         conf->rts_threshold = atoi(pos);
    2272 [ #  # ][ #  # ]:          0 :                         if (conf->rts_threshold < 0 ||
    2273                 :          0 :                             conf->rts_threshold > 2347) {
    2274                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
    2275                 :            :                                            "rts_threshold %d",
    2276                 :            :                                            line, conf->rts_threshold);
    2277                 :          0 :                                 errors++;
    2278                 :            :                         }
    2279         [ -  + ]:       1481 :                 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
    2280                 :          0 :                         conf->fragm_threshold = atoi(pos);
    2281 [ #  # ][ #  # ]:          0 :                         if (conf->fragm_threshold < 256 ||
    2282                 :          0 :                             conf->fragm_threshold > 2346) {
    2283                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
    2284                 :            :                                            "fragm_threshold %d",
    2285                 :            :                                            line, conf->fragm_threshold);
    2286                 :          0 :                                 errors++;
    2287                 :            :                         }
    2288         [ -  + ]:       1481 :                 } else if (os_strcmp(buf, "send_probe_response") == 0) {
    2289                 :          0 :                         int val = atoi(pos);
    2290 [ #  # ][ #  # ]:          0 :                         if (val != 0 && val != 1) {
    2291                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
    2292                 :            :                                            "send_probe_response %d (expected "
    2293                 :            :                                            "0 or 1)", line, val);
    2294                 :            :                         } else
    2295                 :          0 :                                 conf->send_probe_response = val;
    2296         [ -  + ]:       1481 :                 } else if (os_strcmp(buf, "supported_rates") == 0) {
    2297         [ #  # ]:          0 :                         if (hostapd_parse_intlist(&conf->supported_rates, pos))
    2298                 :            :                         {
    2299                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
    2300                 :            :                                            "list", line);
    2301                 :          0 :                                 errors++;
    2302                 :            :                         }
    2303         [ -  + ]:       1481 :                 } else if (os_strcmp(buf, "basic_rates") == 0) {
    2304         [ #  # ]:          0 :                         if (hostapd_parse_intlist(&conf->basic_rates, pos)) {
    2305                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
    2306                 :            :                                            "list", line);
    2307                 :          0 :                                 errors++;
    2308                 :            :                         }
    2309         [ -  + ]:       1481 :                 } else if (os_strcmp(buf, "preamble") == 0) {
    2310         [ #  # ]:          0 :                         if (atoi(pos))
    2311                 :          0 :                                 conf->preamble = SHORT_PREAMBLE;
    2312                 :            :                         else
    2313                 :          0 :                                 conf->preamble = LONG_PREAMBLE;
    2314         [ -  + ]:       1481 :                 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
    2315                 :          0 :                         bss->ignore_broadcast_ssid = atoi(pos);
    2316         [ -  + ]:       1481 :                 } else if (os_strcmp(buf, "wep_default_key") == 0) {
    2317                 :          0 :                         bss->ssid.wep.idx = atoi(pos);
    2318         [ #  # ]:          0 :                         if (bss->ssid.wep.idx > 3) {
    2319                 :          0 :                                 wpa_printf(MSG_ERROR, "Invalid "
    2320                 :            :                                            "wep_default_key index %d",
    2321                 :          0 :                                            bss->ssid.wep.idx);
    2322                 :          0 :                                 errors++;
    2323                 :            :                         }
    2324 [ +  + ][ +  - ]:       1481 :                 } else if (os_strcmp(buf, "wep_key0") == 0 ||
    2325         [ +  - ]:       1480 :                            os_strcmp(buf, "wep_key1") == 0 ||
    2326         [ -  + ]:       1480 :                            os_strcmp(buf, "wep_key2") == 0 ||
    2327                 :       1480 :                            os_strcmp(buf, "wep_key3") == 0) {
    2328         [ -  + ]:          1 :                         if (hostapd_config_read_wep(&bss->ssid.wep,
    2329                 :          1 :                                                     buf[7] - '0', pos)) {
    2330                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
    2331                 :            :                                            "key '%s'", line, buf);
    2332                 :          0 :                                 errors++;
    2333                 :            :                         }
    2334                 :            : #ifndef CONFIG_NO_VLAN
    2335         [ -  + ]:       1480 :                 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
    2336                 :          0 :                         bss->ssid.dynamic_vlan = atoi(pos);
    2337         [ -  + ]:       1480 :                 } else if (os_strcmp(buf, "vlan_file") == 0) {
    2338         [ #  # ]:          0 :                         if (hostapd_config_read_vlan_file(bss, pos)) {
    2339                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: failed to "
    2340                 :            :                                            "read VLAN file '%s'", line, pos);
    2341                 :          0 :                                 errors++;
    2342                 :            :                         }
    2343         [ -  + ]:       1480 :                 } else if (os_strcmp(buf, "vlan_naming") == 0) {
    2344                 :          0 :                         bss->ssid.vlan_naming = atoi(pos);
    2345 [ #  # ][ #  # ]:          0 :                         if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END ||
    2346                 :          0 :                             bss->ssid.vlan_naming < 0) {
    2347                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
    2348                 :            :                                            "naming scheme %d", line,
    2349                 :            :                                            bss->ssid.vlan_naming);
    2350                 :          0 :                                 errors++;
    2351                 :            :                         }
    2352                 :            : #ifdef CONFIG_FULL_DYNAMIC_VLAN
    2353         [ -  + ]:       1480 :                 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
    2354                 :          0 :                         bss->ssid.vlan_tagged_interface = os_strdup(pos);
    2355                 :            : #endif /* CONFIG_FULL_DYNAMIC_VLAN */
    2356                 :            : #endif /* CONFIG_NO_VLAN */
    2357         [ -  + ]:       1480 :                 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
    2358                 :          0 :                         conf->ap_table_max_size = atoi(pos);
    2359         [ -  + ]:       1480 :                 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
    2360                 :          0 :                         conf->ap_table_expiration_time = atoi(pos);
    2361         [ -  + ]:       1480 :                 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
    2362         [ #  # ]:          0 :                         if (hostapd_config_tx_queue(conf, buf, pos)) {
    2363                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid TX "
    2364                 :            :                                            "queue item", line);
    2365                 :          0 :                                 errors++;
    2366                 :            :                         }
    2367 [ +  - ][ -  + ]:       1480 :                 } else if (os_strcmp(buf, "wme_enabled") == 0 ||
    2368                 :       1480 :                            os_strcmp(buf, "wmm_enabled") == 0) {
    2369                 :          0 :                         bss->wmm_enabled = atoi(pos);
    2370         [ -  + ]:       1480 :                 } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
    2371                 :          0 :                         bss->wmm_uapsd = atoi(pos);
    2372 [ +  - ][ +  + ]:       1480 :                 } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
    2373                 :       1480 :                            os_strncmp(buf, "wmm_ac_", 7) == 0) {
    2374         [ -  + ]:         20 :                         if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf,
    2375                 :            :                                                   pos)) {
    2376                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
    2377                 :            :                                            "ac item", line);
    2378                 :          0 :                                 errors++;
    2379                 :            :                         }
    2380         [ +  + ]:       1460 :                 } else if (os_strcmp(buf, "bss") == 0) {
    2381         [ -  + ]:         10 :                         if (hostapd_config_bss(conf, pos)) {
    2382                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid bss "
    2383                 :            :                                            "item", line);
    2384                 :          0 :                                 errors++;
    2385                 :            :                         }
    2386         [ +  + ]:       1450 :                 } else if (os_strcmp(buf, "bssid") == 0) {
    2387         [ -  + ]:         26 :                         if (hwaddr_aton(pos, bss->bssid)) {
    2388                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid bssid "
    2389                 :            :                                            "item", line);
    2390                 :          0 :                                 errors++;
    2391                 :            :                         }
    2392                 :            : #ifdef CONFIG_IEEE80211W
    2393         [ +  + ]:       1424 :                 } else if (os_strcmp(buf, "ieee80211w") == 0) {
    2394                 :         51 :                         bss->ieee80211w = atoi(pos);
    2395         [ -  + ]:       1373 :                 } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
    2396                 :          0 :                         bss->assoc_sa_query_max_timeout = atoi(pos);
    2397         [ #  # ]:          0 :                         if (bss->assoc_sa_query_max_timeout == 0) {
    2398                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
    2399                 :            :                                            "assoc_sa_query_max_timeout", line);
    2400                 :          0 :                                 errors++;
    2401                 :            :                         }
    2402         [ -  + ]:       1373 :                 } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0)
    2403                 :            :                 {
    2404                 :          0 :                         bss->assoc_sa_query_retry_timeout = atoi(pos);
    2405         [ #  # ]:          0 :                         if (bss->assoc_sa_query_retry_timeout == 0) {
    2406                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
    2407                 :            :                                            "assoc_sa_query_retry_timeout",
    2408                 :            :                                            line);
    2409                 :          0 :                                 errors++;
    2410                 :            :                         }
    2411                 :            : #endif /* CONFIG_IEEE80211W */
    2412                 :            : #ifdef CONFIG_IEEE80211N
    2413         [ +  + ]:       1373 :                 } else if (os_strcmp(buf, "ieee80211n") == 0) {
    2414                 :        216 :                         conf->ieee80211n = atoi(pos);
    2415         [ +  + ]:       1157 :                 } else if (os_strcmp(buf, "ht_capab") == 0) {
    2416         [ -  + ]:         10 :                         if (hostapd_config_ht_capab(conf, pos) < 0) {
    2417                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
    2418                 :            :                                            "ht_capab", line);
    2419                 :          0 :                                 errors++;
    2420                 :            :                         }
    2421         [ -  + ]:       1147 :                 } else if (os_strcmp(buf, "require_ht") == 0) {
    2422                 :          0 :                         conf->require_ht = atoi(pos);
    2423         [ -  + ]:       1147 :                 } else if (os_strcmp(buf, "obss_interval") == 0) {
    2424                 :          0 :                         conf->obss_interval = atoi(pos);
    2425                 :            : #endif /* CONFIG_IEEE80211N */
    2426                 :            : #ifdef CONFIG_IEEE80211AC
    2427         [ -  + ]:       1147 :                 } else if (os_strcmp(buf, "ieee80211ac") == 0) {
    2428                 :          0 :                         conf->ieee80211ac = atoi(pos);
    2429         [ -  + ]:       1147 :                 } else if (os_strcmp(buf, "vht_capab") == 0) {
    2430         [ #  # ]:          0 :                         if (hostapd_config_vht_capab(conf, pos) < 0) {
    2431                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
    2432                 :            :                                            "vht_capab", line);
    2433                 :          0 :                                 errors++;
    2434                 :            :                         }
    2435         [ -  + ]:       1147 :                 } else if (os_strcmp(buf, "require_vht") == 0) {
    2436                 :          0 :                         conf->require_vht = atoi(pos);
    2437         [ -  + ]:       1147 :                 } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) {
    2438                 :          0 :                         conf->vht_oper_chwidth = atoi(pos);
    2439         [ -  + ]:       1147 :                 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0)
    2440                 :            :                 {
    2441                 :          0 :                         conf->vht_oper_centr_freq_seg0_idx = atoi(pos);
    2442         [ -  + ]:       1147 :                 } else if (os_strcmp(buf, "vht_oper_centr_freq_seg1_idx") == 0)
    2443                 :            :                 {
    2444                 :          0 :                         conf->vht_oper_centr_freq_seg1_idx = atoi(pos);
    2445                 :            : #endif /* CONFIG_IEEE80211AC */
    2446         [ -  + ]:       1147 :                 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
    2447                 :          0 :                         bss->max_listen_interval = atoi(pos);
    2448         [ -  + ]:       1147 :                 } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
    2449                 :          0 :                         bss->disable_pmksa_caching = atoi(pos);
    2450         [ +  + ]:       1147 :                 } else if (os_strcmp(buf, "okc") == 0) {
    2451                 :          2 :                         bss->okc = atoi(pos);
    2452                 :            : #ifdef CONFIG_WPS
    2453         [ +  + ]:       1145 :                 } else if (os_strcmp(buf, "wps_state") == 0) {
    2454                 :         34 :                         bss->wps_state = atoi(pos);
    2455 [ -  + ][ +  - ]:         34 :                         if (bss->wps_state < 0 || bss->wps_state > 2) {
    2456                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
    2457                 :            :                                            "wps_state", line);
    2458                 :          0 :                                 errors++;
    2459                 :            :                         }
    2460         [ +  + ]:       1111 :                 } else if (os_strcmp(buf, "wps_independent") == 0) {
    2461                 :          2 :                         bss->wps_independent = atoi(pos);
    2462         [ -  + ]:       1109 :                 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
    2463                 :          0 :                         bss->ap_setup_locked = atoi(pos);
    2464         [ +  + ]:       1109 :                 } else if (os_strcmp(buf, "uuid") == 0) {
    2465         [ -  + ]:          4 :                         if (uuid_str2bin(pos, bss->uuid)) {
    2466                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid UUID",
    2467                 :            :                                            line);
    2468                 :          0 :                                 errors++;
    2469                 :            :                         }
    2470         [ -  + ]:       1105 :                 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
    2471                 :          0 :                         os_free(bss->wps_pin_requests);
    2472                 :          0 :                         bss->wps_pin_requests = os_strdup(pos);
    2473         [ +  + ]:       1105 :                 } else if (os_strcmp(buf, "device_name") == 0) {
    2474         [ -  + ]:          4 :                         if (os_strlen(pos) > 32) {
    2475                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Too long "
    2476                 :            :                                            "device_name", line);
    2477                 :          0 :                                 errors++;
    2478                 :            :                         }
    2479                 :          4 :                         os_free(bss->device_name);
    2480                 :          4 :                         bss->device_name = os_strdup(pos);
    2481         [ +  + ]:       1101 :                 } else if (os_strcmp(buf, "manufacturer") == 0) {
    2482         [ -  + ]:          4 :                         if (os_strlen(pos) > 64) {
    2483                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Too long "
    2484                 :            :                                            "manufacturer", line);
    2485                 :          0 :                                 errors++;
    2486                 :            :                         }
    2487                 :          4 :                         os_free(bss->manufacturer);
    2488                 :          4 :                         bss->manufacturer = os_strdup(pos);
    2489         [ +  + ]:       1097 :                 } else if (os_strcmp(buf, "model_name") == 0) {
    2490         [ -  + ]:          4 :                         if (os_strlen(pos) > 32) {
    2491                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Too long "
    2492                 :            :                                            "model_name", line);
    2493                 :          0 :                                 errors++;
    2494                 :            :                         }
    2495                 :          4 :                         os_free(bss->model_name);
    2496                 :          4 :                         bss->model_name = os_strdup(pos);
    2497         [ +  + ]:       1093 :                 } else if (os_strcmp(buf, "model_number") == 0) {
    2498         [ -  + ]:          4 :                         if (os_strlen(pos) > 32) {
    2499                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Too long "
    2500                 :            :                                            "model_number", line);
    2501                 :          0 :                                 errors++;
    2502                 :            :                         }
    2503                 :          4 :                         os_free(bss->model_number);
    2504                 :          4 :                         bss->model_number = os_strdup(pos);
    2505         [ +  + ]:       1089 :                 } else if (os_strcmp(buf, "serial_number") == 0) {
    2506         [ -  + ]:          4 :                         if (os_strlen(pos) > 32) {
    2507                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Too long "
    2508                 :            :                                            "serial_number", line);
    2509                 :          0 :                                 errors++;
    2510                 :            :                         }
    2511                 :          4 :                         os_free(bss->serial_number);
    2512                 :          4 :                         bss->serial_number = os_strdup(pos);
    2513         [ +  + ]:       1085 :                 } else if (os_strcmp(buf, "device_type") == 0) {
    2514         [ -  + ]:          4 :                         if (wps_dev_type_str2bin(pos, bss->device_type))
    2515                 :          0 :                                 errors++;
    2516         [ +  + ]:       1081 :                 } else if (os_strcmp(buf, "config_methods") == 0) {
    2517                 :          4 :                         os_free(bss->config_methods);
    2518                 :          4 :                         bss->config_methods = os_strdup(pos);
    2519         [ +  + ]:       1077 :                 } else if (os_strcmp(buf, "os_version") == 0) {
    2520         [ -  + ]:          4 :                         if (hexstr2bin(pos, bss->os_version, 4)) {
    2521                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
    2522                 :            :                                            "os_version", line);
    2523                 :          0 :                                 errors++;
    2524                 :            :                         }
    2525         [ +  + ]:       1073 :                 } else if (os_strcmp(buf, "ap_pin") == 0) {
    2526                 :          7 :                         os_free(bss->ap_pin);
    2527                 :          7 :                         bss->ap_pin = os_strdup(pos);
    2528         [ -  + ]:       1066 :                 } else if (os_strcmp(buf, "skip_cred_build") == 0) {
    2529                 :          0 :                         bss->skip_cred_build = atoi(pos);
    2530         [ -  + ]:       1066 :                 } else if (os_strcmp(buf, "extra_cred") == 0) {
    2531                 :          0 :                         os_free(bss->extra_cred);
    2532                 :          0 :                         bss->extra_cred =
    2533                 :          0 :                                 (u8 *) os_readfile(pos, &bss->extra_cred_len);
    2534         [ #  # ]:          0 :                         if (bss->extra_cred == NULL) {
    2535                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: could not "
    2536                 :            :                                            "read Credentials from '%s'",
    2537                 :            :                                            line, pos);
    2538                 :          0 :                                 errors++;
    2539                 :            :                         }
    2540         [ -  + ]:       1066 :                 } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
    2541                 :          0 :                         bss->wps_cred_processing = atoi(pos);
    2542         [ -  + ]:       1066 :                 } else if (os_strcmp(buf, "ap_settings") == 0) {
    2543                 :          0 :                         os_free(bss->ap_settings);
    2544                 :          0 :                         bss->ap_settings =
    2545                 :          0 :                                 (u8 *) os_readfile(pos, &bss->ap_settings_len);
    2546         [ #  # ]:          0 :                         if (bss->ap_settings == NULL) {
    2547                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: could not "
    2548                 :            :                                            "read AP Settings from '%s'",
    2549                 :            :                                            line, pos);
    2550                 :          0 :                                 errors++;
    2551                 :            :                         }
    2552         [ +  + ]:       1066 :                 } else if (os_strcmp(buf, "upnp_iface") == 0) {
    2553                 :          4 :                         bss->upnp_iface = os_strdup(pos);
    2554         [ -  + ]:       1062 :                 } else if (os_strcmp(buf, "friendly_name") == 0) {
    2555                 :          0 :                         os_free(bss->friendly_name);
    2556                 :          0 :                         bss->friendly_name = os_strdup(pos);
    2557         [ -  + ]:       1062 :                 } else if (os_strcmp(buf, "manufacturer_url") == 0) {
    2558                 :          0 :                         os_free(bss->manufacturer_url);
    2559                 :          0 :                         bss->manufacturer_url = os_strdup(pos);
    2560         [ -  + ]:       1062 :                 } else if (os_strcmp(buf, "model_description") == 0) {
    2561                 :          0 :                         os_free(bss->model_description);
    2562                 :          0 :                         bss->model_description = os_strdup(pos);
    2563         [ -  + ]:       1062 :                 } else if (os_strcmp(buf, "model_url") == 0) {
    2564                 :          0 :                         os_free(bss->model_url);
    2565                 :          0 :                         bss->model_url = os_strdup(pos);
    2566         [ -  + ]:       1062 :                 } else if (os_strcmp(buf, "upc") == 0) {
    2567                 :          0 :                         os_free(bss->upc);
    2568                 :          0 :                         bss->upc = os_strdup(pos);
    2569         [ -  + ]:       1062 :                 } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
    2570                 :          0 :                         bss->pbc_in_m1 = atoi(pos);
    2571         [ +  + ]:       1062 :                 } else if (os_strcmp(buf, "server_id") == 0) {
    2572                 :          1 :                         os_free(bss->server_id);
    2573                 :          1 :                         bss->server_id = os_strdup(pos);
    2574                 :            : #ifdef CONFIG_WPS_NFC
    2575         [ -  + ]:       1061 :                 } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
    2576                 :          0 :                         bss->wps_nfc_dev_pw_id = atoi(pos);
    2577 [ #  # ][ #  # ]:          0 :                         if (bss->wps_nfc_dev_pw_id < 0x10 ||
    2578                 :          0 :                             bss->wps_nfc_dev_pw_id > 0xffff) {
    2579                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Invalid "
    2580                 :            :                                            "wps_nfc_dev_pw_id value", line);
    2581                 :          0 :                                 errors++;
    2582                 :            :                         }
    2583                 :          0 :                         bss->wps_nfc_pw_from_config = 1;
    2584         [ -  + ]:       1061 :                 } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
    2585                 :          0 :                         wpabuf_free(bss->wps_nfc_dh_pubkey);
    2586                 :          0 :                         bss->wps_nfc_dh_pubkey = hostapd_parse_bin(pos);
    2587                 :          0 :                         bss->wps_nfc_pw_from_config = 1;
    2588         [ -  + ]:       1061 :                 } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
    2589                 :          0 :                         wpabuf_free(bss->wps_nfc_dh_privkey);
    2590                 :          0 :                         bss->wps_nfc_dh_privkey = hostapd_parse_bin(pos);
    2591                 :          0 :                         bss->wps_nfc_pw_from_config = 1;
    2592         [ -  + ]:       1061 :                 } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
    2593                 :          0 :                         wpabuf_free(bss->wps_nfc_dev_pw);
    2594                 :          0 :                         bss->wps_nfc_dev_pw = hostapd_parse_bin(pos);
    2595                 :          0 :                         bss->wps_nfc_pw_from_config = 1;
    2596                 :            : #endif /* CONFIG_WPS_NFC */
    2597                 :            : #endif /* CONFIG_WPS */
    2598                 :            : #ifdef CONFIG_P2P_MANAGER
    2599         [ -  + ]:       1061 :                 } else if (os_strcmp(buf, "manage_p2p") == 0) {
    2600                 :          0 :                         int manage = atoi(pos);
    2601         [ #  # ]:          0 :                         if (manage)
    2602                 :          0 :                                 bss->p2p |= P2P_MANAGE;
    2603                 :            :                         else
    2604                 :          0 :                                 bss->p2p &= ~P2P_MANAGE;
    2605         [ -  + ]:       1061 :                 } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
    2606         [ #  # ]:          0 :                         if (atoi(pos))
    2607                 :          0 :                                 bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
    2608                 :            :                         else
    2609                 :          0 :                                 bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
    2610                 :            : #endif /* CONFIG_P2P_MANAGER */
    2611         [ -  + ]:       1061 :                 } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
    2612                 :          0 :                         bss->disassoc_low_ack = atoi(pos);
    2613         [ -  + ]:       1061 :                 } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
    2614                 :          0 :                         int val = atoi(pos);
    2615         [ #  # ]:          0 :                         if (val)
    2616                 :          0 :                                 bss->tdls |= TDLS_PROHIBIT;
    2617                 :            :                         else
    2618                 :          0 :                                 bss->tdls &= ~TDLS_PROHIBIT;
    2619         [ -  + ]:       1061 :                 } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
    2620                 :          0 :                         int val = atoi(pos);
    2621         [ #  # ]:          0 :                         if (val)
    2622                 :          0 :                                 bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
    2623                 :            :                         else
    2624                 :          0 :                                 bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
    2625                 :            : #ifdef CONFIG_RSN_TESTING
    2626                 :            :                 } else if (os_strcmp(buf, "rsn_testing") == 0) {
    2627                 :            :                         extern int rsn_testing;
    2628                 :            :                         rsn_testing = atoi(pos);
    2629                 :            : #endif /* CONFIG_RSN_TESTING */
    2630         [ +  + ]:       1061 :                 } else if (os_strcmp(buf, "time_advertisement") == 0) {
    2631                 :          6 :                         bss->time_advertisement = atoi(pos);
    2632         [ +  + ]:       1055 :                 } else if (os_strcmp(buf, "time_zone") == 0) {
    2633                 :          6 :                         size_t tz_len = os_strlen(pos);
    2634 [ +  - ][ -  + ]:          6 :                         if (tz_len < 4 || tz_len > 255) {
    2635                 :          0 :                                 wpa_printf(MSG_DEBUG, "Line %d: invalid "
    2636                 :            :                                            "time_zone", line);
    2637                 :          0 :                                 errors++;
    2638                 :          0 :                                 return errors;
    2639                 :            :                         }
    2640                 :          6 :                         os_free(bss->time_zone);
    2641                 :          6 :                         bss->time_zone = os_strdup(pos);
    2642         [ -  + ]:          6 :                         if (bss->time_zone == NULL)
    2643                 :          0 :                                 errors++;
    2644                 :            : #ifdef CONFIG_WNM
    2645         [ +  + ]:       1049 :                 } else if (os_strcmp(buf, "wnm_sleep_mode") == 0) {
    2646                 :          6 :                         bss->wnm_sleep_mode = atoi(pos);
    2647         [ +  + ]:       1043 :                 } else if (os_strcmp(buf, "bss_transition") == 0) {
    2648                 :          7 :                         bss->bss_transition = atoi(pos);
    2649                 :            : #endif /* CONFIG_WNM */
    2650                 :            : #ifdef CONFIG_INTERWORKING
    2651         [ +  + ]:       1036 :                 } else if (os_strcmp(buf, "interworking") == 0) {
    2652                 :         41 :                         bss->interworking = atoi(pos);
    2653         [ +  + ]:        995 :                 } else if (os_strcmp(buf, "access_network_type") == 0) {
    2654                 :         41 :                         bss->access_network_type = atoi(pos);
    2655 [ -  + ][ +  - ]:         41 :                         if (bss->access_network_type < 0 ||
    2656                 :         41 :                             bss->access_network_type > 15) {
    2657                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
    2658                 :            :                                            "access_network_type", line);
    2659                 :          0 :                                 errors++;
    2660                 :            :                         }
    2661         [ +  + ]:        954 :                 } else if (os_strcmp(buf, "internet") == 0) {
    2662                 :         41 :                         bss->internet = atoi(pos);
    2663         [ +  + ]:        913 :                 } else if (os_strcmp(buf, "asra") == 0) {
    2664                 :         41 :                         bss->asra = atoi(pos);
    2665         [ +  + ]:        872 :                 } else if (os_strcmp(buf, "esr") == 0) {
    2666                 :         41 :                         bss->esr = atoi(pos);
    2667         [ +  + ]:        831 :                 } else if (os_strcmp(buf, "uesa") == 0) {
    2668                 :         41 :                         bss->uesa = atoi(pos);
    2669         [ +  + ]:        790 :                 } else if (os_strcmp(buf, "venue_group") == 0) {
    2670                 :         40 :                         bss->venue_group = atoi(pos);
    2671                 :         40 :                         bss->venue_info_set = 1;
    2672         [ +  + ]:        750 :                 } else if (os_strcmp(buf, "venue_type") == 0) {
    2673                 :         40 :                         bss->venue_type = atoi(pos);
    2674                 :         40 :                         bss->venue_info_set = 1;
    2675         [ +  + ]:        710 :                 } else if (os_strcmp(buf, "hessid") == 0) {
    2676         [ -  + ]:         29 :                         if (hwaddr_aton(pos, bss->hessid)) {
    2677                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
    2678                 :            :                                            "hessid", line);
    2679                 :          0 :                                 errors++;
    2680                 :            :                         }
    2681         [ +  + ]:        681 :                 } else if (os_strcmp(buf, "roaming_consortium") == 0) {
    2682         [ -  + ]:        158 :                         if (parse_roaming_consortium(bss, pos, line) < 0)
    2683                 :          0 :                                 errors++;
    2684         [ +  + ]:        523 :                 } else if (os_strcmp(buf, "venue_name") == 0) {
    2685         [ -  + ]:         82 :                         if (parse_venue_name(bss, pos, line) < 0)
    2686                 :          0 :                                 errors++;
    2687         [ +  + ]:        441 :                 } else if (os_strcmp(buf, "network_auth_type") == 0) {
    2688                 :            :                         u8 auth_type;
    2689                 :            :                         u16 redirect_url_len;
    2690         [ -  + ]:          9 :                         if (hexstr2bin(pos, &auth_type, 1)) {
    2691                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Invalid "
    2692                 :            :                                            "network_auth_type '%s'",
    2693                 :            :                                            line, pos);
    2694                 :          0 :                                 errors++;
    2695                 :          0 :                                 return errors;
    2696                 :            :                         }
    2697 [ +  - ][ +  - ]:          9 :                         if (auth_type == 0 || auth_type == 2)
    2698                 :          9 :                                 redirect_url_len = os_strlen(pos + 2);
    2699                 :            :                         else
    2700                 :          0 :                                 redirect_url_len = 0;
    2701                 :          9 :                         os_free(bss->network_auth_type);
    2702                 :          9 :                         bss->network_auth_type =
    2703                 :          9 :                                 os_malloc(redirect_url_len + 3 + 1);
    2704         [ -  + ]:          9 :                         if (bss->network_auth_type == NULL) {
    2705                 :          0 :                                 errors++;
    2706                 :          0 :                                 return errors;
    2707                 :            :                         }
    2708                 :          9 :                         *bss->network_auth_type = auth_type;
    2709                 :          9 :                         WPA_PUT_LE16(bss->network_auth_type + 1,
    2710                 :            :                                      redirect_url_len);
    2711         [ +  - ]:          9 :                         if (redirect_url_len)
    2712                 :          9 :                                 os_memcpy(bss->network_auth_type + 3,
    2713                 :            :                                           pos + 2, redirect_url_len);
    2714                 :          9 :                         bss->network_auth_type_len = 3 + redirect_url_len;
    2715         [ +  + ]:        432 :                 } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
    2716         [ -  + ]:          9 :                         if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1))
    2717                 :            :                         {
    2718                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Invalid "
    2719                 :            :                                            "ipaddr_type_availability '%s'",
    2720                 :            :                                            line, pos);
    2721                 :          0 :                                 bss->ipaddr_type_configured = 0;
    2722                 :          0 :                                 errors++;
    2723                 :          0 :                                 return errors;
    2724                 :            :                         }
    2725                 :          9 :                         bss->ipaddr_type_configured = 1;
    2726         [ +  + ]:        423 :                 } else if (os_strcmp(buf, "domain_name") == 0) {
    2727                 :         40 :                         int j, num_domains, domain_len, domain_list_len = 0;
    2728                 :            :                         char *tok_start, *tok_prev;
    2729                 :            :                         u8 *domain_list, *domain_ptr;
    2730                 :            : 
    2731                 :         40 :                         domain_list_len = os_strlen(pos) + 1;
    2732                 :         40 :                         domain_list = os_malloc(domain_list_len);
    2733         [ -  + ]:         40 :                         if (domain_list == NULL) {
    2734                 :          0 :                                 errors++;
    2735                 :          0 :                                 return errors;
    2736                 :            :                         }
    2737                 :            : 
    2738                 :         40 :                         domain_ptr = domain_list;
    2739                 :         40 :                         tok_prev = pos;
    2740                 :         40 :                         num_domains = 1;
    2741         [ +  + ]:         74 :                         while ((tok_prev = os_strchr(tok_prev, ','))) {
    2742                 :         34 :                                 num_domains++;
    2743                 :         34 :                                 tok_prev++;
    2744                 :            :                         }
    2745                 :         40 :                         tok_prev = pos;
    2746         [ +  + ]:        114 :                         for (j = 0; j < num_domains; j++) {
    2747                 :         74 :                                 tok_start = os_strchr(tok_prev, ',');
    2748         [ +  + ]:         74 :                                 if (tok_start) {
    2749                 :         34 :                                         domain_len = tok_start - tok_prev;
    2750                 :         34 :                                         *domain_ptr = domain_len;
    2751                 :         34 :                                         os_memcpy(domain_ptr + 1, tok_prev,
    2752                 :            :                                                   domain_len);
    2753                 :         34 :                                         domain_ptr += domain_len + 1;
    2754                 :         34 :                                         tok_prev = ++tok_start;
    2755                 :            :                                 } else {
    2756                 :         40 :                                         domain_len = os_strlen(tok_prev);
    2757                 :         40 :                                         *domain_ptr = domain_len;
    2758                 :         40 :                                         os_memcpy(domain_ptr + 1, tok_prev,
    2759                 :            :                                                   domain_len);
    2760                 :         40 :                                         domain_ptr += domain_len + 1;
    2761                 :            :                                 }
    2762                 :            :                         }
    2763                 :            : 
    2764                 :         40 :                         os_free(bss->domain_name);
    2765                 :         40 :                         bss->domain_name = domain_list;
    2766                 :         40 :                         bss->domain_name_len = domain_list_len;
    2767         [ +  + ]:        383 :                 } else if (os_strcmp(buf, "anqp_3gpp_cell_net") == 0) {
    2768         [ -  + ]:         41 :                         if (parse_3gpp_cell_net(bss, pos, line) < 0)
    2769                 :          0 :                                 errors++;
    2770         [ +  + ]:        342 :                 } else if (os_strcmp(buf, "nai_realm") == 0) {
    2771         [ -  + ]:         73 :                         if (parse_nai_realm(bss, pos, line) < 0)
    2772                 :          0 :                                 errors++;
    2773         [ -  + ]:        269 :                 } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
    2774                 :          0 :                         bss->gas_frag_limit = atoi(pos);
    2775         [ +  + ]:        269 :                 } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
    2776                 :          1 :                         bss->gas_comeback_delay = atoi(pos);
    2777         [ +  + ]:        268 :                 } else if (os_strcmp(buf, "qos_map_set") == 0) {
    2778         [ -  + ]:          1 :                         if (parse_qos_map_set(bss, pos, line) < 0)
    2779                 :          0 :                                 errors++;
    2780                 :            : #endif /* CONFIG_INTERWORKING */
    2781                 :            : #ifdef CONFIG_RADIUS_TEST
    2782                 :            :                 } else if (os_strcmp(buf, "dump_msk_file") == 0) {
    2783                 :            :                         os_free(bss->dump_msk_file);
    2784                 :            :                         bss->dump_msk_file = os_strdup(pos);
    2785                 :            : #endif /* CONFIG_RADIUS_TEST */
    2786                 :            : #ifdef CONFIG_HS20
    2787         [ +  + ]:        267 :                 } else if (os_strcmp(buf, "hs20") == 0) {
    2788                 :         41 :                         bss->hs20 = atoi(pos);
    2789         [ -  + ]:        226 :                 } else if (os_strcmp(buf, "disable_dgaf") == 0) {
    2790                 :          0 :                         bss->disable_dgaf = atoi(pos);
    2791         [ +  + ]:        226 :                 } else if (os_strcmp(buf, "hs20_oper_friendly_name") == 0) {
    2792         [ -  + ]:         18 :                         if (hs20_parse_oper_friendly_name(bss, pos, line) < 0)
    2793                 :          0 :                                 errors++;
    2794         [ +  + ]:        208 :                 } else if (os_strcmp(buf, "hs20_wan_metrics") == 0) {
    2795         [ -  + ]:         41 :                         if (hs20_parse_wan_metrics(bss, pos, line) < 0) {
    2796                 :          0 :                                 errors++;
    2797                 :          0 :                                 return errors;
    2798                 :            :                         }
    2799         [ +  + ]:        167 :                 } else if (os_strcmp(buf, "hs20_conn_capab") == 0) {
    2800         [ -  + ]:        123 :                         if (hs20_parse_conn_capab(bss, pos, line) < 0) {
    2801                 :          0 :                                 errors++;
    2802                 :          0 :                                 return errors;
    2803                 :            :                         }
    2804         [ +  + ]:         44 :                 } else if (os_strcmp(buf, "hs20_operating_class") == 0) {
    2805                 :            :                         u8 *oper_class;
    2806                 :            :                         size_t oper_class_len;
    2807                 :         41 :                         oper_class_len = os_strlen(pos);
    2808 [ +  - ][ -  + ]:         41 :                         if (oper_class_len < 2 || (oper_class_len & 0x01)) {
    2809                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Invalid "
    2810                 :            :                                            "hs20_operating_class '%s'",
    2811                 :            :                                            line, pos);
    2812                 :          0 :                                 errors++;
    2813                 :          0 :                                 return errors;
    2814                 :            :                         }
    2815                 :         41 :                         oper_class_len /= 2;
    2816                 :         41 :                         oper_class = os_malloc(oper_class_len);
    2817         [ -  + ]:         41 :                         if (oper_class == NULL) {
    2818                 :          0 :                                 errors++;
    2819                 :          0 :                                 return errors;
    2820                 :            :                         }
    2821         [ -  + ]:         41 :                         if (hexstr2bin(pos, oper_class, oper_class_len)) {
    2822                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Invalid "
    2823                 :            :                                            "hs20_operating_class '%s'",
    2824                 :            :                                            line, pos);
    2825                 :          0 :                                 os_free(oper_class);
    2826                 :          0 :                                 errors++;
    2827                 :          0 :                                 return errors;
    2828                 :            :                         }
    2829                 :         41 :                         os_free(bss->hs20_operating_class);
    2830                 :         41 :                         bss->hs20_operating_class = oper_class;
    2831                 :         41 :                         bss->hs20_operating_class_len = oper_class_len;
    2832                 :            : #endif /* CONFIG_HS20 */
    2833                 :            : #ifdef CONFIG_TESTING_OPTIONS
    2834                 :            : #define PARSE_TEST_PROBABILITY(_val)                                    \
    2835                 :            :                 } else if (os_strcmp(buf, #_val) == 0) {                \
    2836                 :            :                         char *end;                                      \
    2837                 :            :                                                                         \
    2838                 :            :                         conf->_val = strtod(pos, &end);                  \
    2839                 :            :                         if (*end || conf->_val < 0.0d ||          \
    2840                 :            :                             conf->_val > 1.0d) {                  \
    2841                 :            :                                 wpa_printf(MSG_ERROR,                   \
    2842                 :            :                                            "Line %d: Invalid value '%s'", \
    2843                 :            :                                            line, pos);                  \
    2844                 :            :                                 errors++;                               \
    2845                 :            :                                 return errors;                          \
    2846                 :            :                         }
    2847 [ -  + ][ #  # ]:          3 :                 PARSE_TEST_PROBABILITY(ignore_probe_probability)
         [ #  # ][ #  # ]
    2848 [ -  + ][ #  # ]:          3 :                 PARSE_TEST_PROBABILITY(ignore_auth_probability)
         [ #  # ][ #  # ]
    2849 [ -  + ][ #  # ]:          3 :                 PARSE_TEST_PROBABILITY(ignore_assoc_probability)
         [ #  # ][ #  # ]
    2850 [ -  + ][ #  # ]:          3 :                 PARSE_TEST_PROBABILITY(ignore_reassoc_probability)
         [ #  # ][ #  # ]
    2851 [ -  + ][ #  # ]:          3 :                 PARSE_TEST_PROBABILITY(corrupt_gtk_rekey_mic_probability)
         [ #  # ][ #  # ]
    2852         [ -  + ]:          3 :                 } else if (os_strcmp(buf, "bss_load_test") == 0) {
    2853                 :          0 :                         WPA_PUT_LE16(bss->bss_load_test, atoi(pos));
    2854                 :          0 :                         pos = os_strchr(pos, ':');
    2855         [ #  # ]:          0 :                         if (pos == NULL) {
    2856                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Invalid "
    2857                 :            :                                            "bss_load_test", line);
    2858                 :          0 :                                 return 1;
    2859                 :            :                         }
    2860                 :          0 :                         pos++;
    2861                 :          0 :                         bss->bss_load_test[2] = atoi(pos);
    2862                 :          0 :                         pos = os_strchr(pos, ':');
    2863         [ #  # ]:          0 :                         if (pos == NULL) {
    2864                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Invalid "
    2865                 :            :                                            "bss_load_test", line);
    2866                 :          0 :                                 return 1;
    2867                 :            :                         }
    2868                 :          0 :                         pos++;
    2869                 :          0 :                         WPA_PUT_LE16(&bss->bss_load_test[3], atoi(pos));
    2870                 :          0 :                         bss->bss_load_test_set = 1;
    2871                 :            : #endif /* CONFIG_TESTING_OPTIONS */
    2872         [ -  + ]:          3 :                 } else if (os_strcmp(buf, "vendor_elements") == 0) {
    2873                 :            :                         struct wpabuf *elems;
    2874                 :          0 :                         size_t len = os_strlen(pos);
    2875         [ #  # ]:          0 :                         if (len & 0x01) {
    2876                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Invalid "
    2877                 :            :                                            "vendor_elements '%s'", line, pos);
    2878                 :          0 :                                 return 1;
    2879                 :            :                         }
    2880                 :          0 :                         len /= 2;
    2881         [ #  # ]:          0 :                         if (len == 0) {
    2882                 :          0 :                                 wpabuf_free(bss->vendor_elements);
    2883                 :          0 :                                 bss->vendor_elements = NULL;
    2884                 :          0 :                                 return 0;
    2885                 :            :                         }
    2886                 :            : 
    2887                 :          0 :                         elems = wpabuf_alloc(len);
    2888         [ #  # ]:          0 :                         if (elems == NULL)
    2889                 :          0 :                                 return 1;
    2890                 :            : 
    2891         [ #  # ]:          0 :                         if (hexstr2bin(pos, wpabuf_put(elems, len), len)) {
    2892                 :          0 :                                 wpabuf_free(elems);
    2893                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Invalid "
    2894                 :            :                                            "vendor_elements '%s'", line, pos);
    2895                 :          0 :                                 return 1;
    2896                 :            :                         }
    2897                 :            : 
    2898                 :          0 :                         wpabuf_free(bss->vendor_elements);
    2899                 :          0 :                         bss->vendor_elements = elems;
    2900         [ +  + ]:          3 :                 } else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0) {
    2901                 :          1 :                         bss->sae_anti_clogging_threshold = atoi(pos);
    2902         [ +  - ]:          2 :                 } else if (os_strcmp(buf, "sae_groups") == 0) {
    2903         [ -  + ]:          2 :                         if (hostapd_parse_intlist(&bss->sae_groups, pos)) {
    2904                 :          0 :                                 wpa_printf(MSG_ERROR, "Line %d: Invalid "
    2905                 :            :                                            "sae_groups value '%s'", line, pos);
    2906                 :          0 :                                 return 1;
    2907                 :            :                         }
    2908                 :            :                 } else {
    2909                 :          0 :                         wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
    2910                 :            :                                    "item '%s'", line, buf);
    2911                 :          0 :                         errors++;
    2912                 :            :                 }
    2913                 :            :         }
    2914                 :            : 
    2915                 :       3896 :         return errors;
    2916                 :            : }
    2917                 :            : 
    2918                 :            : 
    2919                 :            : /**
    2920                 :            :  * hostapd_config_read - Read and parse a configuration file
    2921                 :            :  * @fname: Configuration file name (including path, if needed)
    2922                 :            :  * Returns: Allocated configuration data structure
    2923                 :            :  */
    2924                 :         24 : struct hostapd_config * hostapd_config_read(const char *fname)
    2925                 :            : {
    2926                 :            :         struct hostapd_config *conf;
    2927                 :            :         struct hostapd_bss_config *bss;
    2928                 :            :         FILE *f;
    2929                 :            :         char buf[512], *pos;
    2930                 :         24 :         int line = 0;
    2931                 :         24 :         int errors = 0;
    2932                 :            :         size_t i;
    2933                 :            : 
    2934                 :         24 :         f = fopen(fname, "r");
    2935         [ -  + ]:         24 :         if (f == NULL) {
    2936                 :          0 :                 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
    2937                 :            :                            "for reading.", fname);
    2938                 :          0 :                 return NULL;
    2939                 :            :         }
    2940                 :            : 
    2941                 :         24 :         conf = hostapd_config_defaults();
    2942         [ -  + ]:         24 :         if (conf == NULL) {
    2943                 :          0 :                 fclose(f);
    2944                 :          0 :                 return NULL;
    2945                 :            :         }
    2946                 :            : 
    2947                 :            :         /* set default driver based on configuration */
    2948                 :         24 :         conf->driver = wpa_drivers[0];
    2949         [ -  + ]:         24 :         if (conf->driver == NULL) {
    2950                 :          0 :                 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
    2951                 :          0 :                 hostapd_config_free(conf);
    2952                 :          0 :                 fclose(f);
    2953                 :          0 :                 return NULL;
    2954                 :            :         }
    2955                 :            : 
    2956                 :         24 :         bss = conf->last_bss = conf->bss[0];
    2957                 :            : 
    2958         [ +  + ]:        335 :         while (fgets(buf, sizeof(buf), f)) {
    2959                 :        311 :                 bss = conf->last_bss;
    2960                 :        311 :                 line++;
    2961                 :            : 
    2962         [ -  + ]:        311 :                 if (buf[0] == '#')
    2963                 :          0 :                         continue;
    2964                 :        311 :                 pos = buf;
    2965         [ +  - ]:       4211 :                 while (*pos != '\0') {
    2966         [ +  + ]:       4211 :                         if (*pos == '\n') {
    2967                 :        311 :                                 *pos = '\0';
    2968                 :        311 :                                 break;
    2969                 :            :                         }
    2970                 :       3900 :                         pos++;
    2971                 :            :                 }
    2972         [ +  + ]:        311 :                 if (buf[0] == '\0')
    2973                 :         78 :                         continue;
    2974                 :            : 
    2975                 :        233 :                 pos = os_strchr(buf, '=');
    2976         [ -  + ]:        233 :                 if (pos == NULL) {
    2977                 :          0 :                         wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
    2978                 :            :                                    line, buf);
    2979                 :          0 :                         errors++;
    2980                 :          0 :                         continue;
    2981                 :            :                 }
    2982                 :        233 :                 *pos = '\0';
    2983                 :        233 :                 pos++;
    2984                 :        233 :                 errors += hostapd_config_fill(conf, bss, buf, pos, line);
    2985                 :            :         }
    2986                 :            : 
    2987                 :         24 :         fclose(f);
    2988                 :            : 
    2989         [ +  + ]:         54 :         for (i = 0; i < conf->num_bss; i++)
    2990                 :         30 :                 hostapd_set_security_params(conf->bss[i]);
    2991                 :            : 
    2992         [ -  + ]:         24 :         if (hostapd_config_check(conf))
    2993                 :          0 :                 errors++;
    2994                 :            : 
    2995                 :            : #ifndef WPA_IGNORE_CONFIG_ERRORS
    2996         [ -  + ]:         24 :         if (errors) {
    2997                 :          0 :                 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
    2998                 :            :                            "'%s'", errors, fname);
    2999                 :          0 :                 hostapd_config_free(conf);
    3000                 :          0 :                 conf = NULL;
    3001                 :            :         }
    3002                 :            : #endif /* WPA_IGNORE_CONFIG_ERRORS */
    3003                 :            : 
    3004                 :         24 :         return conf;
    3005                 :            : }
    3006                 :            : 
    3007                 :            : 
    3008                 :       3663 : int hostapd_set_iface(struct hostapd_config *conf,
    3009                 :            :                       struct hostapd_bss_config *bss, char *field, char *value)
    3010                 :            : {
    3011                 :            :         int errors;
    3012                 :            :         size_t i;
    3013                 :            : 
    3014                 :       3663 :         errors = hostapd_config_fill(conf, bss, field, value, 0);
    3015         [ -  + ]:       3663 :         if (errors) {
    3016                 :          0 :                 wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
    3017                 :            :                            "to value '%s'", field, value);
    3018                 :          0 :                 return -1;
    3019                 :            :         }
    3020                 :            : 
    3021         [ +  + ]:       7334 :         for (i = 0; i < conf->num_bss; i++)
    3022                 :       3671 :                 hostapd_set_security_params(conf->bss[i]);
    3023                 :            : 
    3024         [ -  + ]:       3663 :         if (hostapd_config_check(conf)) {
    3025                 :          0 :                 wpa_printf(MSG_ERROR, "Configuration check failed");
    3026                 :          0 :                 return -1;
    3027                 :            :         }
    3028                 :            : 
    3029                 :       3663 :         return 0;
    3030                 :            : }

Generated by: LCOV version 1.9