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

Generated by: LCOV version 1.9