config.c

Go to the documentation of this file.
00001 
00017 #include "includes.h"
00018 #ifndef CONFIG_NATIVE_WINDOWS
00019 #include <grp.h>
00020 #endif /* CONFIG_NATIVE_WINDOWS */
00021 
00022 #include "hostapd.h"
00023 #include "drivers/driver.h"
00024 #include "sha1.h"
00025 #include "eap_server/eap.h"
00026 #include "radius/radius_client.h"
00027 #include "wpa_common.h"
00028 #include "wpa.h"
00029 #include "uuid.h"
00030 #include "eap_common/eap_wsc_common.h"
00031 #include "sta_info.h"
00032 #include "config.h"
00033 
00034 
00035 #define MAX_STA_COUNT 2007
00036 
00037 extern struct wpa_driver_ops *wpa_drivers[];
00038 
00039 
00040 #ifndef CONFIG_NO_VLAN
00041 static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
00042                                          const char *fname)
00043 {
00044         FILE *f;
00045         char buf[128], *pos, *pos2;
00046         int line = 0, vlan_id;
00047         struct hostapd_vlan *vlan;
00048 
00049         f = fopen(fname, "r");
00050         if (!f) {
00051                 wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname);
00052                 return -1;
00053         }
00054 
00055         while (fgets(buf, sizeof(buf), f)) {
00056                 line++;
00057 
00058                 if (buf[0] == '#')
00059                         continue;
00060                 pos = buf;
00061                 while (*pos != '\0') {
00062                         if (*pos == '\n') {
00063                                 *pos = '\0';
00064                                 break;
00065                         }
00066                         pos++;
00067                 }
00068                 if (buf[0] == '\0')
00069                         continue;
00070 
00071                 if (buf[0] == '*') {
00072                         vlan_id = VLAN_ID_WILDCARD;
00073                         pos = buf + 1;
00074                 } else {
00075                         vlan_id = strtol(buf, &pos, 10);
00076                         if (buf == pos || vlan_id < 1 ||
00077                             vlan_id > MAX_VLAN_ID) {
00078                                 wpa_printf(MSG_ERROR, "Invalid VLAN ID at "
00079                                            "line %d in '%s'", line, fname);
00080                                 fclose(f);
00081                                 return -1;
00082                         }
00083                 }
00084 
00085                 while (*pos == ' ' || *pos == '\t')
00086                         pos++;
00087                 pos2 = pos;
00088                 while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
00089                         pos2++;
00090                 *pos2 = '\0';
00091                 if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
00092                         wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d "
00093                                    "in '%s'", line, fname);
00094                         fclose(f);
00095                         return -1;
00096                 }
00097 
00098                 vlan = os_malloc(sizeof(*vlan));
00099                 if (vlan == NULL) {
00100                         wpa_printf(MSG_ERROR, "Out of memory while reading "
00101                                    "VLAN interfaces from '%s'", fname);
00102                         fclose(f);
00103                         return -1;
00104                 }
00105 
00106                 os_memset(vlan, 0, sizeof(*vlan));
00107                 vlan->vlan_id = vlan_id;
00108                 os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
00109                 if (bss->vlan_tail)
00110                         bss->vlan_tail->next = vlan;
00111                 else
00112                         bss->vlan = vlan;
00113                 bss->vlan_tail = vlan;
00114         }
00115 
00116         fclose(f);
00117 
00118         return 0;
00119 }
00120 #endif /* CONFIG_NO_VLAN */
00121 
00122 
00123 static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
00124 {
00125         struct hostapd_vlan *vlan, *prev;
00126 
00127         vlan = bss->vlan;
00128         prev = NULL;
00129         while (vlan) {
00130                 prev = vlan;
00131                 vlan = vlan->next;
00132                 os_free(prev);
00133         }
00134 
00135         bss->vlan = NULL;
00136 }
00137 
00138 
00139 /* convert floats with one decimal place to value*10 int, i.e.,
00140  * "1.5" will return 15 */
00141 static int hostapd_config_read_int10(const char *value)
00142 {
00143         int i, d;
00144         char *pos;
00145 
00146         i = atoi(value);
00147         pos = os_strchr(value, '.');
00148         d = 0;
00149         if (pos) {
00150                 pos++;
00151                 if (*pos >= '0' && *pos <= '9')
00152                         d = *pos - '0';
00153         }
00154 
00155         return i * 10 + d;
00156 }
00157 
00158 
00159 static void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
00160 {
00161         bss->logger_syslog_level = HOSTAPD_LEVEL_INFO;
00162         bss->logger_stdout_level = HOSTAPD_LEVEL_INFO;
00163         bss->logger_syslog = (unsigned int) -1;
00164         bss->logger_stdout = (unsigned int) -1;
00165 
00166         bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
00167 
00168         bss->wep_rekeying_period = 300;
00169         /* use key0 in individual key and key1 in broadcast key */
00170         bss->broadcast_key_idx_min = 1;
00171         bss->broadcast_key_idx_max = 2;
00172         bss->eap_reauth_period = 3600;
00173 
00174         bss->wpa_group_rekey = 600;
00175         bss->wpa_gmk_rekey = 86400;
00176         bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
00177         bss->wpa_pairwise = WPA_CIPHER_TKIP;
00178         bss->wpa_group = WPA_CIPHER_TKIP;
00179         bss->rsn_pairwise = 0;
00180 
00181         bss->max_num_sta = MAX_STA_COUNT;
00182 
00183         bss->dtim_period = 2;
00184 
00185         bss->radius_server_auth_port = 1812;
00186         bss->ap_max_inactivity = AP_MAX_INACTIVITY;
00187         bss->eapol_version = EAPOL_VERSION;
00188 
00189         bss->max_listen_interval = 65535;
00190 
00191 #ifdef CONFIG_IEEE80211W
00192         bss->assoc_sa_query_max_timeout = 1000;
00193         bss->assoc_sa_query_retry_timeout = 201;
00194 #endif /* CONFIG_IEEE80211W */
00195 #ifdef EAP_SERVER_FAST
00196          /* both anonymous and authenticated provisioning */
00197         bss->eap_fast_prov = 3;
00198         bss->pac_key_lifetime = 7 * 24 * 60 * 60;
00199         bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
00200 #endif /* EAP_SERVER_FAST */
00201 }
00202 
00203 
00204 struct hostapd_config * hostapd_config_defaults(void)
00205 {
00206         struct hostapd_config *conf;
00207         struct hostapd_bss_config *bss;
00208         int i;
00209         const int aCWmin = 15, aCWmax = 1024;
00210         const struct hostapd_wmm_ac_params ac_bk =
00211                 { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
00212         const struct hostapd_wmm_ac_params ac_be =
00213                 { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
00214         const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
00215                 { aCWmin >> 1, aCWmin, 2, 3000 / 32, 1 };
00216         const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
00217                 { aCWmin >> 2, aCWmin >> 1, 2, 1500 / 32, 1 };
00218 
00219         conf = os_zalloc(sizeof(*conf));
00220         bss = os_zalloc(sizeof(*bss));
00221         if (conf == NULL || bss == NULL) {
00222                 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
00223                            "configuration data.");
00224                 os_free(conf);
00225                 os_free(bss);
00226                 return NULL;
00227         }
00228 
00229         /* set default driver based on configuration */
00230         conf->driver = wpa_drivers[0];
00231         if (conf->driver == NULL) {
00232                 wpa_printf(MSG_ERROR, "No driver wrappers registered!");
00233                 os_free(conf);
00234                 os_free(bss);
00235                 return NULL;
00236         }
00237 
00238         bss->radius = os_zalloc(sizeof(*bss->radius));
00239         if (bss->radius == NULL) {
00240                 os_free(conf);
00241                 os_free(bss);
00242                 return NULL;
00243         }
00244 
00245         hostapd_config_defaults_bss(bss);
00246 
00247         conf->num_bss = 1;
00248         conf->bss = bss;
00249 
00250         conf->beacon_int = 100;
00251         conf->rts_threshold = -1; /* use driver default: 2347 */
00252         conf->fragm_threshold = -1; /* user driver default: 2346 */
00253         conf->send_probe_response = 1;
00254         conf->bridge_packets = INTERNAL_BRIDGE_DO_NOT_CONTROL;
00255 
00256         for (i = 0; i < NUM_TX_QUEUES; i++)
00257                 conf->tx_queue[i].aifs = -1; /* use hw default */
00258 
00259         conf->wmm_ac_params[0] = ac_be;
00260         conf->wmm_ac_params[1] = ac_bk;
00261         conf->wmm_ac_params[2] = ac_vi;
00262         conf->wmm_ac_params[3] = ac_vo;
00263 
00264 #ifdef CONFIG_IEEE80211N
00265         conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
00266 #endif /* CONFIG_IEEE80211N */
00267 
00268         return conf;
00269 }
00270 
00271 
00272 int hostapd_mac_comp(const void *a, const void *b)
00273 {
00274         return os_memcmp(a, b, sizeof(macaddr));
00275 }
00276 
00277 
00278 int hostapd_mac_comp_empty(const void *a)
00279 {
00280         macaddr empty = { 0 };
00281         return os_memcmp(a, empty, sizeof(macaddr));
00282 }
00283 
00284 
00285 static int hostapd_acl_comp(const void *a, const void *b)
00286 {
00287         const struct mac_acl_entry *aa = a;
00288         const struct mac_acl_entry *bb = b;
00289         return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
00290 }
00291 
00292 
00293 static int hostapd_config_read_maclist(const char *fname,
00294                                        struct mac_acl_entry **acl, int *num)
00295 {
00296         FILE *f;
00297         char buf[128], *pos;
00298         int line = 0;
00299         u8 addr[ETH_ALEN];
00300         struct mac_acl_entry *newacl;
00301         int vlan_id;
00302 
00303         if (!fname)
00304                 return 0;
00305 
00306         f = fopen(fname, "r");
00307         if (!f) {
00308                 wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
00309                 return -1;
00310         }
00311 
00312         while (fgets(buf, sizeof(buf), f)) {
00313                 line++;
00314 
00315                 if (buf[0] == '#')
00316                         continue;
00317                 pos = buf;
00318                 while (*pos != '\0') {
00319                         if (*pos == '\n') {
00320                                 *pos = '\0';
00321                                 break;
00322                         }
00323                         pos++;
00324                 }
00325                 if (buf[0] == '\0')
00326                         continue;
00327 
00328                 if (hwaddr_aton(buf, addr)) {
00329                         wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
00330                                    "line %d in '%s'", buf, line, fname);
00331                         fclose(f);
00332                         return -1;
00333                 }
00334 
00335                 vlan_id = 0;
00336                 pos = buf;
00337                 while (*pos != '\0' && *pos != ' ' && *pos != '\t')
00338                         pos++;
00339                 while (*pos == ' ' || *pos == '\t')
00340                         pos++;
00341                 if (*pos != '\0')
00342                         vlan_id = atoi(pos);
00343 
00344                 newacl = os_realloc(*acl, (*num + 1) * sizeof(**acl));
00345                 if (newacl == NULL) {
00346                         wpa_printf(MSG_ERROR, "MAC list reallocation failed");
00347                         fclose(f);
00348                         return -1;
00349                 }
00350 
00351                 *acl = newacl;
00352                 os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
00353                 (*acl)[*num].vlan_id = vlan_id;
00354                 (*num)++;
00355         }
00356 
00357         fclose(f);
00358 
00359         qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
00360 
00361         return 0;
00362 }
00363 
00364 
00365 static int hostapd_config_read_wpa_psk(const char *fname,
00366                                        struct hostapd_ssid *ssid)
00367 {
00368         FILE *f;
00369         char buf[128], *pos;
00370         int line = 0, ret = 0, len, ok;
00371         u8 addr[ETH_ALEN];
00372         struct hostapd_wpa_psk *psk;
00373 
00374         if (!fname)
00375                 return 0;
00376 
00377         f = fopen(fname, "r");
00378         if (!f) {
00379                 wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
00380                 return -1;
00381         }
00382 
00383         while (fgets(buf, sizeof(buf), f)) {
00384                 line++;
00385 
00386                 if (buf[0] == '#')
00387                         continue;
00388                 pos = buf;
00389                 while (*pos != '\0') {
00390                         if (*pos == '\n') {
00391                                 *pos = '\0';
00392                                 break;
00393                         }
00394                         pos++;
00395                 }
00396                 if (buf[0] == '\0')
00397                         continue;
00398 
00399                 if (hwaddr_aton(buf, addr)) {
00400                         wpa_printf(MSG_ERROR, "Invalid MAC address '%s' on "
00401                                    "line %d in '%s'", buf, line, fname);
00402                         ret = -1;
00403                         break;
00404                 }
00405 
00406                 psk = os_zalloc(sizeof(*psk));
00407                 if (psk == NULL) {
00408                         wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
00409                         ret = -1;
00410                         break;
00411                 }
00412                 if (is_zero_ether_addr(addr))
00413                         psk->group = 1;
00414                 else
00415                         os_memcpy(psk->addr, addr, ETH_ALEN);
00416 
00417                 pos = buf + 17;
00418                 if (*pos == '\0') {
00419                         wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
00420                                    line, fname);
00421                         os_free(psk);
00422                         ret = -1;
00423                         break;
00424                 }
00425                 pos++;
00426 
00427                 ok = 0;
00428                 len = os_strlen(pos);
00429                 if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
00430                         ok = 1;
00431                 else if (len >= 8 && len < 64) {
00432                         pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
00433                                     4096, psk->psk, PMK_LEN);
00434                         ok = 1;
00435                 }
00436                 if (!ok) {
00437                         wpa_printf(MSG_ERROR, "Invalid PSK '%s' on line %d in "
00438                                    "'%s'", pos, line, fname);
00439                         os_free(psk);
00440                         ret = -1;
00441                         break;
00442                 }
00443 
00444                 psk->next = ssid->wpa_psk;
00445                 ssid->wpa_psk = psk;
00446         }
00447 
00448         fclose(f);
00449 
00450         return ret;
00451 }
00452 
00453 
00454 int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
00455 {
00456         struct hostapd_ssid *ssid = &conf->ssid;
00457 
00458         if (ssid->wpa_passphrase != NULL) {
00459                 if (ssid->wpa_psk != NULL) {
00460                         wpa_printf(MSG_ERROR, "Warning: both WPA PSK and "
00461                                    "passphrase set. Using passphrase.");
00462                         os_free(ssid->wpa_psk);
00463                 }
00464                 ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
00465                 if (ssid->wpa_psk == NULL) {
00466                         wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
00467                         return -1;
00468                 }
00469                 wpa_hexdump_ascii(MSG_DEBUG, "SSID",
00470                                   (u8 *) ssid->ssid, ssid->ssid_len);
00471                 wpa_hexdump_ascii(MSG_DEBUG, "PSK (ASCII passphrase)",
00472                                   (u8 *) ssid->wpa_passphrase,
00473                                   os_strlen(ssid->wpa_passphrase));
00474                 pbkdf2_sha1(ssid->wpa_passphrase,
00475                             ssid->ssid, ssid->ssid_len,
00476                             4096, ssid->wpa_psk->psk, PMK_LEN);
00477                 wpa_hexdump(MSG_DEBUG, "PSK (from passphrase)",
00478                             ssid->wpa_psk->psk, PMK_LEN);
00479                 ssid->wpa_psk->group = 1;
00480         }
00481 
00482         if (ssid->wpa_psk_file) {
00483                 if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file,
00484                                                 &conf->ssid))
00485                         return -1;
00486         }
00487 
00488         return 0;
00489 }
00490 
00491 
00492 #ifdef EAP_SERVER
00493 static int hostapd_config_read_eap_user(const char *fname,
00494                                         struct hostapd_bss_config *conf)
00495 {
00496         FILE *f;
00497         char buf[512], *pos, *start, *pos2;
00498         int line = 0, ret = 0, num_methods;
00499         struct hostapd_eap_user *user, *tail = NULL;
00500 
00501         if (!fname)
00502                 return 0;
00503 
00504         f = fopen(fname, "r");
00505         if (!f) {
00506                 wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
00507                 return -1;
00508         }
00509 
00510         /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
00511         while (fgets(buf, sizeof(buf), f)) {
00512                 line++;
00513 
00514                 if (buf[0] == '#')
00515                         continue;
00516                 pos = buf;
00517                 while (*pos != '\0') {
00518                         if (*pos == '\n') {
00519                                 *pos = '\0';
00520                                 break;
00521                         }
00522                         pos++;
00523                 }
00524                 if (buf[0] == '\0')
00525                         continue;
00526 
00527                 user = NULL;
00528 
00529                 if (buf[0] != '"' && buf[0] != '*') {
00530                         wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
00531                                    "start) on line %d in '%s'", line, fname);
00532                         goto failed;
00533                 }
00534 
00535                 user = os_zalloc(sizeof(*user));
00536                 if (user == NULL) {
00537                         wpa_printf(MSG_ERROR, "EAP user allocation failed");
00538                         goto failed;
00539                 }
00540                 user->force_version = -1;
00541 
00542                 if (buf[0] == '*') {
00543                         pos = buf;
00544                 } else {
00545                         pos = buf + 1;
00546                         start = pos;
00547                         while (*pos != '"' && *pos != '\0')
00548                                 pos++;
00549                         if (*pos == '\0') {
00550                                 wpa_printf(MSG_ERROR, "Invalid EAP identity "
00551                                            "(no \" in end) on line %d in '%s'",
00552                                            line, fname);
00553                                 goto failed;
00554                         }
00555 
00556                         user->identity = os_malloc(pos - start);
00557                         if (user->identity == NULL) {
00558                                 wpa_printf(MSG_ERROR, "Failed to allocate "
00559                                            "memory for EAP identity");
00560                                 goto failed;
00561                         }
00562                         os_memcpy(user->identity, start, pos - start);
00563                         user->identity_len = pos - start;
00564 
00565                         if (pos[0] == '"' && pos[1] == '*') {
00566                                 user->wildcard_prefix = 1;
00567                                 pos++;
00568                         }
00569                 }
00570                 pos++;
00571                 while (*pos == ' ' || *pos == '\t')
00572                         pos++;
00573 
00574                 if (*pos == '\0') {
00575                         wpa_printf(MSG_ERROR, "No EAP method on line %d in "
00576                                    "'%s'", line, fname);
00577                         goto failed;
00578                 }
00579 
00580                 start = pos;
00581                 while (*pos != ' ' && *pos != '\t' && *pos != '\0')
00582                         pos++;
00583                 if (*pos == '\0') {
00584                         pos = NULL;
00585                 } else {
00586                         *pos = '\0';
00587                         pos++;
00588                 }
00589                 num_methods = 0;
00590                 while (*start) {
00591                         char *pos3 = os_strchr(start, ',');
00592                         if (pos3) {
00593                                 *pos3++ = '\0';
00594                         }
00595                         user->methods[num_methods].method =
00596                                 eap_server_get_type(
00597                                         start,
00598                                         &user->methods[num_methods].vendor);
00599                         if (user->methods[num_methods].vendor ==
00600                             EAP_VENDOR_IETF &&
00601                             user->methods[num_methods].method == EAP_TYPE_NONE)
00602                         {
00603                                 if (os_strcmp(start, "TTLS-PAP") == 0) {
00604                                         user->ttls_auth |= EAP_TTLS_AUTH_PAP;
00605                                         goto skip_eap;
00606                                 }
00607                                 if (os_strcmp(start, "TTLS-CHAP") == 0) {
00608                                         user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
00609                                         goto skip_eap;
00610                                 }
00611                                 if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
00612                                         user->ttls_auth |=
00613                                                 EAP_TTLS_AUTH_MSCHAP;
00614                                         goto skip_eap;
00615                                 }
00616                                 if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
00617                                         user->ttls_auth |=
00618                                                 EAP_TTLS_AUTH_MSCHAPV2;
00619                                         goto skip_eap;
00620                                 }
00621                                 wpa_printf(MSG_ERROR, "Unsupported EAP type "
00622                                            "'%s' on line %d in '%s'",
00623                                            start, line, fname);
00624                                 goto failed;
00625                         }
00626 
00627                         num_methods++;
00628                         if (num_methods >= EAP_USER_MAX_METHODS)
00629                                 break;
00630                 skip_eap:
00631                         if (pos3 == NULL)
00632                                 break;
00633                         start = pos3;
00634                 }
00635                 if (num_methods == 0 && user->ttls_auth == 0) {
00636                         wpa_printf(MSG_ERROR, "No EAP types configured on "
00637                                    "line %d in '%s'", line, fname);
00638                         goto failed;
00639                 }
00640 
00641                 if (pos == NULL)
00642                         goto done;
00643 
00644                 while (*pos == ' ' || *pos == '\t')
00645                         pos++;
00646                 if (*pos == '\0')
00647                         goto done;
00648 
00649                 if (os_strncmp(pos, "[ver=0]", 7) == 0) {
00650                         user->force_version = 0;
00651                         goto done;
00652                 }
00653 
00654                 if (os_strncmp(pos, "[ver=1]", 7) == 0) {
00655                         user->force_version = 1;
00656                         goto done;
00657                 }
00658 
00659                 if (os_strncmp(pos, "[2]", 3) == 0) {
00660                         user->phase2 = 1;
00661                         goto done;
00662                 }
00663 
00664                 if (*pos == '"') {
00665                         pos++;
00666                         start = pos;
00667                         while (*pos != '"' && *pos != '\0')
00668                                 pos++;
00669                         if (*pos == '\0') {
00670                                 wpa_printf(MSG_ERROR, "Invalid EAP password "
00671                                            "(no \" in end) on line %d in '%s'",
00672                                            line, fname);
00673                                 goto failed;
00674                         }
00675 
00676                         user->password = os_malloc(pos - start);
00677                         if (user->password == NULL) {
00678                                 wpa_printf(MSG_ERROR, "Failed to allocate "
00679                                            "memory for EAP password");
00680                                 goto failed;
00681                         }
00682                         os_memcpy(user->password, start, pos - start);
00683                         user->password_len = pos - start;
00684 
00685                         pos++;
00686                 } else if (os_strncmp(pos, "hash:", 5) == 0) {
00687                         pos += 5;
00688                         pos2 = pos;
00689                         while (*pos2 != '\0' && *pos2 != ' ' &&
00690                                *pos2 != '\t' && *pos2 != '#')
00691                                 pos2++;
00692                         if (pos2 - pos != 32) {
00693                                 wpa_printf(MSG_ERROR, "Invalid password hash "
00694                                            "on line %d in '%s'", line, fname);
00695                                 goto failed;
00696                         }
00697                         user->password = os_malloc(16);
00698                         if (user->password == NULL) {
00699                                 wpa_printf(MSG_ERROR, "Failed to allocate "
00700                                            "memory for EAP password hash");
00701                                 goto failed;
00702                         }
00703                         if (hexstr2bin(pos, user->password, 16) < 0) {
00704                                 wpa_printf(MSG_ERROR, "Invalid hash password "
00705                                            "on line %d in '%s'", line, fname);
00706                                 goto failed;
00707                         }
00708                         user->password_len = 16;
00709                         user->password_hash = 1;
00710                         pos = pos2;
00711                 } else {
00712                         pos2 = pos;
00713                         while (*pos2 != '\0' && *pos2 != ' ' &&
00714                                *pos2 != '\t' && *pos2 != '#')
00715                                 pos2++;
00716                         if ((pos2 - pos) & 1) {
00717                                 wpa_printf(MSG_ERROR, "Invalid hex password "
00718                                            "on line %d in '%s'", line, fname);
00719                                 goto failed;
00720                         }
00721                         user->password = os_malloc((pos2 - pos) / 2);
00722                         if (user->password == NULL) {
00723                                 wpa_printf(MSG_ERROR, "Failed to allocate "
00724                                            "memory for EAP password");
00725                                 goto failed;
00726                         }
00727                         if (hexstr2bin(pos, user->password,
00728                                        (pos2 - pos) / 2) < 0) {
00729                                 wpa_printf(MSG_ERROR, "Invalid hex password "
00730                                            "on line %d in '%s'", line, fname);
00731                                 goto failed;
00732                         }
00733                         user->password_len = (pos2 - pos) / 2;
00734                         pos = pos2;
00735                 }
00736 
00737                 while (*pos == ' ' || *pos == '\t')
00738                         pos++;
00739                 if (os_strncmp(pos, "[2]", 3) == 0) {
00740                         user->phase2 = 1;
00741                 }
00742 
00743         done:
00744                 if (tail == NULL) {
00745                         tail = conf->eap_user = user;
00746                 } else {
00747                         tail->next = user;
00748                         tail = user;
00749                 }
00750                 continue;
00751 
00752         failed:
00753                 if (user) {
00754                         os_free(user->password);
00755                         os_free(user->identity);
00756                         os_free(user);
00757                 }
00758                 ret = -1;
00759                 break;
00760         }
00761 
00762         fclose(f);
00763 
00764         return ret;
00765 }
00766 #endif /* EAP_SERVER */
00767 
00768 
00769 #ifndef CONFIG_NO_RADIUS
00770 static int
00771 hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
00772                                 int *num_server, const char *val, int def_port,
00773                                 struct hostapd_radius_server **curr_serv)
00774 {
00775         struct hostapd_radius_server *nserv;
00776         int ret;
00777         static int server_index = 1;
00778 
00779         nserv = os_realloc(*server, (*num_server + 1) * sizeof(*nserv));
00780         if (nserv == NULL)
00781                 return -1;
00782 
00783         *server = nserv;
00784         nserv = &nserv[*num_server];
00785         (*num_server)++;
00786         (*curr_serv) = nserv;
00787 
00788         os_memset(nserv, 0, sizeof(*nserv));
00789         nserv->port = def_port;
00790         ret = hostapd_parse_ip_addr(val, &nserv->addr);
00791         nserv->index = server_index++;
00792 
00793         return ret;
00794 }
00795 #endif /* CONFIG_NO_RADIUS */
00796 
00797 
00798 static int hostapd_config_parse_key_mgmt(int line, const char *value)
00799 {
00800         int val = 0, last;
00801         char *start, *end, *buf;
00802 
00803         buf = os_strdup(value);
00804         if (buf == NULL)
00805                 return -1;
00806         start = buf;
00807 
00808         while (*start != '\0') {
00809                 while (*start == ' ' || *start == '\t')
00810                         start++;
00811                 if (*start == '\0')
00812                         break;
00813                 end = start;
00814                 while (*end != ' ' && *end != '\t' && *end != '\0')
00815                         end++;
00816                 last = *end == '\0';
00817                 *end = '\0';
00818                 if (os_strcmp(start, "WPA-PSK") == 0)
00819                         val |= WPA_KEY_MGMT_PSK;
00820                 else if (os_strcmp(start, "WPA-EAP") == 0)
00821                         val |= WPA_KEY_MGMT_IEEE8021X;
00822 #ifdef CONFIG_IEEE80211R
00823                 else if (os_strcmp(start, "FT-PSK") == 0)
00824                         val |= WPA_KEY_MGMT_FT_PSK;
00825                 else if (os_strcmp(start, "FT-EAP") == 0)
00826                         val |= WPA_KEY_MGMT_FT_IEEE8021X;
00827 #endif /* CONFIG_IEEE80211R */
00828 #ifdef CONFIG_IEEE80211W
00829                 else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
00830                         val |= WPA_KEY_MGMT_PSK_SHA256;
00831                 else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
00832                         val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
00833 #endif /* CONFIG_IEEE80211W */
00834                 else {
00835                         wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
00836                                    line, start);
00837                         os_free(buf);
00838                         return -1;
00839                 }
00840 
00841                 if (last)
00842                         break;
00843                 start = end + 1;
00844         }
00845 
00846         os_free(buf);
00847         if (val == 0) {
00848                 wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
00849                            "configured.", line);
00850                 return -1;
00851         }
00852 
00853         return val;
00854 }
00855 
00856 
00857 static int hostapd_config_parse_cipher(int line, const char *value)
00858 {
00859         int val = 0, last;
00860         char *start, *end, *buf;
00861 
00862         buf = os_strdup(value);
00863         if (buf == NULL)
00864                 return -1;
00865         start = buf;
00866 
00867         while (*start != '\0') {
00868                 while (*start == ' ' || *start == '\t')
00869                         start++;
00870                 if (*start == '\0')
00871                         break;
00872                 end = start;
00873                 while (*end != ' ' && *end != '\t' && *end != '\0')
00874                         end++;
00875                 last = *end == '\0';
00876                 *end = '\0';
00877                 if (os_strcmp(start, "CCMP") == 0)
00878                         val |= WPA_CIPHER_CCMP;
00879                 else if (os_strcmp(start, "TKIP") == 0)
00880                         val |= WPA_CIPHER_TKIP;
00881                 else if (os_strcmp(start, "WEP104") == 0)
00882                         val |= WPA_CIPHER_WEP104;
00883                 else if (os_strcmp(start, "WEP40") == 0)
00884                         val |= WPA_CIPHER_WEP40;
00885                 else if (os_strcmp(start, "NONE") == 0)
00886                         val |= WPA_CIPHER_NONE;
00887                 else {
00888                         wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
00889                                    line, start);
00890                         os_free(buf);
00891                         return -1;
00892                 }
00893 
00894                 if (last)
00895                         break;
00896                 start = end + 1;
00897         }
00898         os_free(buf);
00899 
00900         if (val == 0) {
00901                 wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
00902                            line);
00903                 return -1;
00904         }
00905         return val;
00906 }
00907 
00908 
00909 static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
00910                                     struct hostapd_config *conf)
00911 {
00912         if (bss->ieee802_1x && !bss->eap_server &&
00913             !bss->radius->auth_servers) {
00914                 wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
00915                            "EAP authenticator configured).");
00916                 return -1;
00917         }
00918 
00919         if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
00920             bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
00921             bss->ssid.wpa_psk_file == NULL) {
00922                 wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
00923                            "is not configured.");
00924                 return -1;
00925         }
00926 
00927         if (hostapd_mac_comp_empty(bss->bssid) != 0) {
00928                 size_t i;
00929 
00930                 for (i = 0; i < conf->num_bss; i++) {
00931                         if ((&conf->bss[i] != bss) &&
00932                             (hostapd_mac_comp(conf->bss[i].bssid,
00933                                               bss->bssid) == 0)) {
00934                                 wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
00935                                            " on interface '%s' and '%s'.",
00936                                            MAC2STR(bss->bssid),
00937                                            conf->bss[i].iface, bss->iface);
00938                                 return -1;
00939                         }
00940                 }
00941         }
00942 
00943 #ifdef CONFIG_IEEE80211R
00944         if ((bss->wpa_key_mgmt &
00945              (WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X)) &&
00946             (bss->nas_identifier == NULL ||
00947              os_strlen(bss->nas_identifier) < 1 ||
00948              os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
00949                 wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
00950                            "nas_identifier to be configured as a 1..48 octet "
00951                            "string");
00952                 return -1;
00953         }
00954 #endif /* CONFIG_IEEE80211R */
00955 
00956 #ifdef CONFIG_IEEE80211N
00957         if (conf->ieee80211n && bss->wpa &&
00958             !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
00959             !(bss->rsn_pairwise & WPA_CIPHER_CCMP)) {
00960                 wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
00961                            "requires CCMP to be enabled");
00962                 return -1;
00963         }
00964 #endif /* CONFIG_IEEE80211N */
00965 
00966         return 0;
00967 }
00968 
00969 
00970 static int hostapd_config_check(struct hostapd_config *conf)
00971 {
00972         size_t i;
00973 
00974         if (conf->ieee80211d && (!conf->country[0] || !conf->country[1])) {
00975                 wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
00976                            "setting the country_code");
00977                 return -1;
00978         }
00979 
00980         for (i = 0; i < conf->num_bss; i++) {
00981                 if (hostapd_config_check_bss(&conf->bss[i], conf))
00982                         return -1;
00983         }
00984 
00985         return 0;
00986 }
00987 
00988 
00989 static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
00990                                    char *val)
00991 {
00992         size_t len = os_strlen(val);
00993 
00994         if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
00995                 return -1;
00996 
00997         if (val[0] == '"') {
00998                 if (len < 2 || val[len - 1] != '"')
00999                         return -1;
01000                 len -= 2;
01001                 wep->key[keyidx] = os_malloc(len);
01002                 if (wep->key[keyidx] == NULL)
01003                         return -1;
01004                 os_memcpy(wep->key[keyidx], val + 1, len);
01005                 wep->len[keyidx] = len;
01006         } else {
01007                 if (len & 1)
01008                         return -1;
01009                 len /= 2;
01010                 wep->key[keyidx] = os_malloc(len);
01011                 if (wep->key[keyidx] == NULL)
01012                         return -1;
01013                 wep->len[keyidx] = len;
01014                 if (hexstr2bin(val, wep->key[keyidx], len) < 0)
01015                         return -1;
01016         }
01017 
01018         wep->keys_set++;
01019 
01020         return 0;
01021 }
01022 
01023 
01024 static int hostapd_parse_rates(int **rate_list, char *val)
01025 {
01026         int *list;
01027         int count;
01028         char *pos, *end;
01029 
01030         os_free(*rate_list);
01031         *rate_list = NULL;
01032 
01033         pos = val;
01034         count = 0;
01035         while (*pos != '\0') {
01036                 if (*pos == ' ')
01037                         count++;
01038                 pos++;
01039         }
01040 
01041         list = os_malloc(sizeof(int) * (count + 2));
01042         if (list == NULL)
01043                 return -1;
01044         pos = val;
01045         count = 0;
01046         while (*pos != '\0') {
01047                 end = os_strchr(pos, ' ');
01048                 if (end)
01049                         *end = '\0';
01050 
01051                 list[count++] = atoi(pos);
01052                 if (!end)
01053                         break;
01054                 pos = end + 1;
01055         }
01056         list[count] = -1;
01057 
01058         *rate_list = list;
01059         return 0;
01060 }
01061 
01062 
01063 static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
01064 {
01065         struct hostapd_bss_config *bss;
01066 
01067         if (*ifname == '\0')
01068                 return -1;
01069 
01070         bss = os_realloc(conf->bss, (conf->num_bss + 1) *
01071                          sizeof(struct hostapd_bss_config));
01072         if (bss == NULL) {
01073                 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
01074                            "multi-BSS entry");
01075                 return -1;
01076         }
01077         conf->bss = bss;
01078 
01079         bss = &(conf->bss[conf->num_bss]);
01080         os_memset(bss, 0, sizeof(*bss));
01081         bss->radius = os_zalloc(sizeof(*bss->radius));
01082         if (bss->radius == NULL) {
01083                 wpa_printf(MSG_ERROR, "Failed to allocate memory for "
01084                            "multi-BSS RADIUS data");
01085                 return -1;
01086         }
01087 
01088         conf->num_bss++;
01089         conf->last_bss = bss;
01090 
01091         hostapd_config_defaults_bss(bss);
01092         os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
01093         os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
01094 
01095         return 0;
01096 }
01097 
01098 
01099 static int valid_cw(int cw)
01100 {
01101         return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
01102                 cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
01103 }
01104 
01105 
01106 enum {
01107         IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
01108         IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
01109         IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
01110         IEEE80211_TX_QUEUE_DATA3 = 3, /* used for EDCA AC_BK data */
01111         IEEE80211_TX_QUEUE_DATA4 = 4,
01112         IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
01113         IEEE80211_TX_QUEUE_BEACON = 7
01114 };
01115 
01116 static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
01117                                    char *val)
01118 {
01119         int num;
01120         char *pos;
01121         struct hostapd_tx_queue_params *queue;
01122 
01123         /* skip 'tx_queue_' prefix */
01124         pos = name + 9;
01125         if (os_strncmp(pos, "data", 4) == 0 &&
01126             pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
01127                 num = pos[4] - '0';
01128                 pos += 6;
01129         } else if (os_strncmp(pos, "after_beacon_", 13) == 0) {
01130                 num = IEEE80211_TX_QUEUE_AFTER_BEACON;
01131                 pos += 13;
01132         } else if (os_strncmp(pos, "beacon_", 7) == 0) {
01133                 num = IEEE80211_TX_QUEUE_BEACON;
01134                 pos += 7;
01135         } else {
01136                 wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
01137                 return -1;
01138         }
01139 
01140         queue = &conf->tx_queue[num];
01141 
01142         if (os_strcmp(pos, "aifs") == 0) {
01143                 queue->aifs = atoi(val);
01144                 if (queue->aifs < 0 || queue->aifs > 255) {
01145                         wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
01146                                    queue->aifs);
01147                         return -1;
01148                 }
01149         } else if (os_strcmp(pos, "cwmin") == 0) {
01150                 queue->cwmin = atoi(val);
01151                 if (!valid_cw(queue->cwmin)) {
01152                         wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
01153                                    queue->cwmin);
01154                         return -1;
01155                 }
01156         } else if (os_strcmp(pos, "cwmax") == 0) {
01157                 queue->cwmax = atoi(val);
01158                 if (!valid_cw(queue->cwmax)) {
01159                         wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
01160                                    queue->cwmax);
01161                         return -1;
01162                 }
01163         } else if (os_strcmp(pos, "burst") == 0) {
01164                 queue->burst = hostapd_config_read_int10(val);
01165         } else {
01166                 wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
01167                 return -1;
01168         }
01169 
01170         queue->configured = 1;
01171 
01172         return 0;
01173 }
01174 
01175 
01176 static int hostapd_config_wmm_ac(struct hostapd_config *conf, char *name,
01177                                  char *val)
01178 {
01179         int num, v;
01180         char *pos;
01181         struct hostapd_wmm_ac_params *ac;
01182 
01183         /* skip 'wme_ac_' or 'wmm_ac_' prefix */
01184         pos = name + 7;
01185         if (os_strncmp(pos, "be_", 3) == 0) {
01186                 num = 0;
01187                 pos += 3;
01188         } else if (os_strncmp(pos, "bk_", 3) == 0) {
01189                 num = 1;
01190                 pos += 3;
01191         } else if (os_strncmp(pos, "vi_", 3) == 0) {
01192                 num = 2;
01193                 pos += 3;
01194         } else if (os_strncmp(pos, "vo_", 3) == 0) {
01195                 num = 3;
01196                 pos += 3;
01197         } else {
01198                 wpa_printf(MSG_ERROR, "Unknown WMM name '%s'", pos);
01199                 return -1;
01200         }
01201 
01202         ac = &conf->wmm_ac_params[num];
01203 
01204         if (os_strcmp(pos, "aifs") == 0) {
01205                 v = atoi(val);
01206                 if (v < 1 || v > 255) {
01207                         wpa_printf(MSG_ERROR, "Invalid AIFS value %d", v);
01208                         return -1;
01209                 }
01210                 ac->aifs = v;
01211         } else if (os_strcmp(pos, "cwmin") == 0) {
01212                 v = atoi(val);
01213                 if (v < 0 || v > 12) {
01214                         wpa_printf(MSG_ERROR, "Invalid cwMin value %d", v);
01215                         return -1;
01216                 }
01217                 ac->cwmin = v;
01218         } else if (os_strcmp(pos, "cwmax") == 0) {
01219                 v = atoi(val);
01220                 if (v < 0 || v > 12) {
01221                         wpa_printf(MSG_ERROR, "Invalid cwMax value %d", v);
01222                         return -1;
01223                 }
01224                 ac->cwmax = v;
01225         } else if (os_strcmp(pos, "txop_limit") == 0) {
01226                 v = atoi(val);
01227                 if (v < 0 || v > 0xffff) {
01228                         wpa_printf(MSG_ERROR, "Invalid txop value %d", v);
01229                         return -1;
01230                 }
01231                 ac->txop_limit = v;
01232         } else if (os_strcmp(pos, "acm") == 0) {
01233                 v = atoi(val);
01234                 if (v < 0 || v > 1) {
01235                         wpa_printf(MSG_ERROR, "Invalid acm value %d", v);
01236                         return -1;
01237                 }
01238                 ac->admission_control_mandatory = v;
01239         } else {
01240                 wpa_printf(MSG_ERROR, "Unknown wmm_ac_ field '%s'", pos);
01241                 return -1;
01242         }
01243 
01244         return 0;
01245 }
01246 
01247 
01248 #ifdef CONFIG_IEEE80211R
01249 static int add_r0kh(struct hostapd_bss_config *bss, char *value)
01250 {
01251         struct ft_remote_r0kh *r0kh;
01252         char *pos, *next;
01253 
01254         r0kh = os_zalloc(sizeof(*r0kh));
01255         if (r0kh == NULL)
01256                 return -1;
01257 
01258         /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
01259         pos = value;
01260         next = os_strchr(pos, ' ');
01261         if (next)
01262                 *next++ = '\0';
01263         if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
01264                 wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
01265                 os_free(r0kh);
01266                 return -1;
01267         }
01268 
01269         pos = next;
01270         next = os_strchr(pos, ' ');
01271         if (next)
01272                 *next++ = '\0';
01273         if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
01274                 wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
01275                 os_free(r0kh);
01276                 return -1;
01277         }
01278         r0kh->id_len = next - pos - 1;
01279         os_memcpy(r0kh->id, pos, r0kh->id_len);
01280 
01281         pos = next;
01282         if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
01283                 wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
01284                 os_free(r0kh);
01285                 return -1;
01286         }
01287 
01288         r0kh->next = bss->r0kh_list;
01289         bss->r0kh_list = r0kh;
01290 
01291         return 0;
01292 }
01293 
01294 
01295 static int add_r1kh(struct hostapd_bss_config *bss, char *value)
01296 {
01297         struct ft_remote_r1kh *r1kh;
01298         char *pos, *next;
01299 
01300         r1kh = os_zalloc(sizeof(*r1kh));
01301         if (r1kh == NULL)
01302                 return -1;
01303 
01304         /* 02:01:02:03:04:05 02:01:02:03:04:05
01305          * 000102030405060708090a0b0c0d0e0f */
01306         pos = value;
01307         next = os_strchr(pos, ' ');
01308         if (next)
01309                 *next++ = '\0';
01310         if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
01311                 wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
01312                 os_free(r1kh);
01313                 return -1;
01314         }
01315 
01316         pos = next;
01317         next = os_strchr(pos, ' ');
01318         if (next)
01319                 *next++ = '\0';
01320         if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
01321                 wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
01322                 os_free(r1kh);
01323                 return -1;
01324         }
01325 
01326         pos = next;
01327         if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
01328                 wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
01329                 os_free(r1kh);
01330                 return -1;
01331         }
01332 
01333         r1kh->next = bss->r1kh_list;
01334         bss->r1kh_list = r1kh;
01335 
01336         return 0;
01337 }
01338 #endif /* CONFIG_IEEE80211R */
01339 
01340 
01341 #ifdef CONFIG_IEEE80211N
01342 static int hostapd_config_ht_capab(struct hostapd_config *conf,
01343                                    const char *capab)
01344 {
01345         if (os_strstr(capab, "[LDPC]"))
01346                 conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
01347         if (os_strstr(capab, "[HT40-]")) {
01348                 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
01349                 conf->secondary_channel = -1;
01350         }
01351         if (os_strstr(capab, "[HT40+]")) {
01352                 conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
01353                 conf->secondary_channel = 1;
01354         }
01355         if (os_strstr(capab, "[SMPS-STATIC]")) {
01356                 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
01357                 conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
01358         }
01359         if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
01360                 conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
01361                 conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
01362         }
01363         if (os_strstr(capab, "[GF]"))
01364                 conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
01365         if (os_strstr(capab, "[SHORT-GI-20]"))
01366                 conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
01367         if (os_strstr(capab, "[SHORT-GI-40]"))
01368                 conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
01369         if (os_strstr(capab, "[TX-STBC]"))
01370                 conf->ht_capab |= HT_CAP_INFO_TX_STBC;
01371         if (os_strstr(capab, "[RX-STBC1]")) {
01372                 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
01373                 conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
01374         }
01375         if (os_strstr(capab, "[RX-STBC12]")) {
01376                 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
01377                 conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
01378         }
01379         if (os_strstr(capab, "[RX-STBC123]")) {
01380                 conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
01381                 conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
01382         }
01383         if (os_strstr(capab, "[DELAYED-BA]"))
01384                 conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
01385         if (os_strstr(capab, "[MAX-AMSDU-7935]"))
01386                 conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
01387         if (os_strstr(capab, "[DSSS_CCK-40]"))
01388                 conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
01389         if (os_strstr(capab, "[PSMP]"))
01390                 conf->ht_capab |= HT_CAP_INFO_PSMP_SUPP;
01391         if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
01392                 conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
01393 
01394         return 0;
01395 }
01396 #endif /* CONFIG_IEEE80211N */
01397 
01398 
01405 struct hostapd_config * hostapd_config_read(const char *fname)
01406 {
01407         struct hostapd_config *conf;
01408         struct hostapd_bss_config *bss;
01409         FILE *f;
01410         char buf[256], *pos;
01411         int line = 0;
01412         int errors = 0;
01413         int pairwise;
01414         size_t i;
01415 
01416         f = fopen(fname, "r");
01417         if (f == NULL) {
01418                 wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
01419                            "for reading.", fname);
01420                 return NULL;
01421         }
01422 
01423         conf = hostapd_config_defaults();
01424         if (conf == NULL) {
01425                 fclose(f);
01426                 return NULL;
01427         }
01428         bss = conf->last_bss = conf->bss;
01429 
01430         while (fgets(buf, sizeof(buf), f)) {
01431                 bss = conf->last_bss;
01432                 line++;
01433 
01434                 if (buf[0] == '#')
01435                         continue;
01436                 pos = buf;
01437                 while (*pos != '\0') {
01438                         if (*pos == '\n') {
01439                                 *pos = '\0';
01440                                 break;
01441                         }
01442                         pos++;
01443                 }
01444                 if (buf[0] == '\0')
01445                         continue;
01446 
01447                 pos = os_strchr(buf, '=');
01448                 if (pos == NULL) {
01449                         wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
01450                                    line, buf);
01451                         errors++;
01452                         continue;
01453                 }
01454                 *pos = '\0';
01455                 pos++;
01456 
01457                 if (os_strcmp(buf, "interface") == 0) {
01458                         os_strlcpy(conf->bss[0].iface, pos,
01459                                    sizeof(conf->bss[0].iface));
01460                 } else if (os_strcmp(buf, "bridge") == 0) {
01461                         os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
01462                 } else if (os_strcmp(buf, "driver") == 0) {
01463                         int j;
01464                         /* clear to get error below if setting is invalid */
01465                         conf->driver = NULL;
01466                         for (j = 0; wpa_drivers[j]; j++) {
01467                                 if (os_strcmp(pos, wpa_drivers[j]->name) == 0)
01468                                 {
01469                                         conf->driver = wpa_drivers[j];
01470                                         break;
01471                                 }
01472                         }
01473                         if (conf->driver == NULL) {
01474                                 wpa_printf(MSG_ERROR, "Line %d: invalid/"
01475                                            "unknown driver '%s'", line, pos);
01476                                 errors++;
01477                         }
01478                 } else if (os_strcmp(buf, "debug") == 0) {
01479                         wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
01480                                    "configuration variable is not used "
01481                                    "anymore", line);
01482                 } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
01483                         bss->logger_syslog_level = atoi(pos);
01484                 } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
01485                         bss->logger_stdout_level = atoi(pos);
01486                 } else if (os_strcmp(buf, "logger_syslog") == 0) {
01487                         bss->logger_syslog = atoi(pos);
01488                 } else if (os_strcmp(buf, "logger_stdout") == 0) {
01489                         bss->logger_stdout = atoi(pos);
01490                 } else if (os_strcmp(buf, "dump_file") == 0) {
01491                         bss->dump_log_name = os_strdup(pos);
01492                 } else if (os_strcmp(buf, "ssid") == 0) {
01493                         bss->ssid.ssid_len = os_strlen(pos);
01494                         if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
01495                             bss->ssid.ssid_len < 1) {
01496                                 wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
01497                                            "'%s'", line, pos);
01498                                 errors++;
01499                         } else {
01500                                 os_memcpy(bss->ssid.ssid, pos,
01501                                           bss->ssid.ssid_len);
01502                                 bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
01503                                 bss->ssid.ssid_set = 1;
01504                         }
01505                 } else if (os_strcmp(buf, "macaddr_acl") == 0) {
01506                         bss->macaddr_acl = atoi(pos);
01507                         if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
01508                             bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
01509                             bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
01510                                 wpa_printf(MSG_ERROR, "Line %d: unknown "
01511                                            "macaddr_acl %d",
01512                                            line, bss->macaddr_acl);
01513                         }
01514                 } else if (os_strcmp(buf, "accept_mac_file") == 0) {
01515                         if (hostapd_config_read_maclist(pos, &bss->accept_mac,
01516                                                         &bss->num_accept_mac))
01517                         {
01518                                 wpa_printf(MSG_ERROR, "Line %d: Failed to "
01519                                            "read accept_mac_file '%s'",
01520                                            line, pos);
01521                                 errors++;
01522                         }
01523                 } else if (os_strcmp(buf, "deny_mac_file") == 0) {
01524                         if (hostapd_config_read_maclist(pos, &bss->deny_mac,
01525                                                         &bss->num_deny_mac)) {
01526                                 wpa_printf(MSG_ERROR, "Line %d: Failed to "
01527                                            "read deny_mac_file '%s'",
01528                                            line, pos);
01529                                 errors++;
01530                         }
01531                 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
01532                         bss->ap_max_inactivity = atoi(pos);
01533                 } else if (os_strcmp(buf, "country_code") == 0) {
01534                         os_memcpy(conf->country, pos, 2);
01535                         /* FIX: make this configurable */
01536                         conf->country[2] = ' ';
01537                 } else if (os_strcmp(buf, "ieee80211d") == 0) {
01538                         conf->ieee80211d = atoi(pos);
01539                 } else if (os_strcmp(buf, "ieee8021x") == 0) {
01540                         bss->ieee802_1x = atoi(pos);
01541                 } else if (os_strcmp(buf, "eapol_version") == 0) {
01542                         bss->eapol_version = atoi(pos);
01543                         if (bss->eapol_version < 1 ||
01544                             bss->eapol_version > 2) {
01545                                 wpa_printf(MSG_ERROR, "Line %d: invalid EAPOL "
01546                                            "version (%d): '%s'.",
01547                                            line, bss->eapol_version, pos);
01548                                 errors++;
01549                         } else
01550                                 wpa_printf(MSG_DEBUG, "eapol_version=%d",
01551                                            bss->eapol_version);
01552 #ifdef EAP_SERVER
01553                 } else if (os_strcmp(buf, "eap_authenticator") == 0) {
01554                         bss->eap_server = atoi(pos);
01555                         wpa_printf(MSG_ERROR, "Line %d: obsolete "
01556                                    "eap_authenticator used; this has been "
01557                                    "renamed to eap_server", line);
01558                 } else if (os_strcmp(buf, "eap_server") == 0) {
01559                         bss->eap_server = atoi(pos);
01560                 } else if (os_strcmp(buf, "eap_user_file") == 0) {
01561                         if (hostapd_config_read_eap_user(pos, bss))
01562                                 errors++;
01563                 } else if (os_strcmp(buf, "ca_cert") == 0) {
01564                         os_free(bss->ca_cert);
01565                         bss->ca_cert = os_strdup(pos);
01566                 } else if (os_strcmp(buf, "server_cert") == 0) {
01567                         os_free(bss->server_cert);
01568                         bss->server_cert = os_strdup(pos);
01569                 } else if (os_strcmp(buf, "private_key") == 0) {
01570                         os_free(bss->private_key);
01571                         bss->private_key = os_strdup(pos);
01572                 } else if (os_strcmp(buf, "private_key_passwd") == 0) {
01573                         os_free(bss->private_key_passwd);
01574                         bss->private_key_passwd = os_strdup(pos);
01575                 } else if (os_strcmp(buf, "check_crl") == 0) {
01576                         bss->check_crl = atoi(pos);
01577                 } else if (os_strcmp(buf, "dh_file") == 0) {
01578                         os_free(bss->dh_file);
01579                         bss->dh_file = os_strdup(pos);
01580 #ifdef EAP_SERVER_FAST
01581                 } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
01582                         os_free(bss->pac_opaque_encr_key);
01583                         bss->pac_opaque_encr_key = os_malloc(16);
01584                         if (bss->pac_opaque_encr_key == NULL) {
01585                                 wpa_printf(MSG_ERROR, "Line %d: No memory for "
01586                                            "pac_opaque_encr_key", line);
01587                                 errors++;
01588                         } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
01589                                               16)) {
01590                                 wpa_printf(MSG_ERROR, "Line %d: Invalid "
01591                                            "pac_opaque_encr_key", line);
01592                                 errors++;
01593                         }
01594                 } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
01595                         size_t idlen = os_strlen(pos);
01596                         if (idlen & 1) {
01597                                 wpa_printf(MSG_ERROR, "Line %d: Invalid "
01598                                            "eap_fast_a_id", line);
01599                                 errors++;
01600                         } else {
01601                                 os_free(bss->eap_fast_a_id);
01602                                 bss->eap_fast_a_id = os_malloc(idlen / 2);
01603                                 if (bss->eap_fast_a_id == NULL ||
01604                                     hexstr2bin(pos, bss->eap_fast_a_id,
01605                                                idlen / 2)) {
01606                                         wpa_printf(MSG_ERROR, "Line %d: "
01607                                                    "Failed to parse "
01608                                                    "eap_fast_a_id", line);
01609                                         errors++;
01610                                 } else
01611                                         bss->eap_fast_a_id_len = idlen / 2;
01612                         }
01613                 } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
01614                         os_free(bss->eap_fast_a_id_info);
01615                         bss->eap_fast_a_id_info = os_strdup(pos);
01616                 } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
01617                         bss->eap_fast_prov = atoi(pos);
01618                 } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
01619                         bss->pac_key_lifetime = atoi(pos);
01620                 } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
01621                         bss->pac_key_refresh_time = atoi(pos);
01622 #endif /* EAP_SERVER_FAST */
01623 #ifdef EAP_SERVER_SIM
01624                 } else if (os_strcmp(buf, "eap_sim_db") == 0) {
01625                         os_free(bss->eap_sim_db);
01626                         bss->eap_sim_db = os_strdup(pos);
01627                 } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
01628                         bss->eap_sim_aka_result_ind = atoi(pos);
01629 #endif /* EAP_SERVER_SIM */
01630 #ifdef EAP_SERVER_TNC
01631                 } else if (os_strcmp(buf, "tnc") == 0) {
01632                         bss->tnc = atoi(pos);
01633 #endif /* EAP_SERVER_TNC */
01634 #endif /* EAP_SERVER */
01635                 } else if (os_strcmp(buf, "eap_message") == 0) {
01636                         char *term;
01637                         bss->eap_req_id_text = os_strdup(pos);
01638                         if (bss->eap_req_id_text == NULL) {
01639                                 wpa_printf(MSG_ERROR, "Line %d: Failed to "
01640                                            "allocate memory for "
01641                                            "eap_req_id_text", line);
01642                                 errors++;
01643                                 continue;
01644                         }
01645                         bss->eap_req_id_text_len =
01646                                 os_strlen(bss->eap_req_id_text);
01647                         term = os_strstr(bss->eap_req_id_text, "\\0");
01648                         if (term) {
01649                                 *term++ = '\0';
01650                                 os_memmove(term, term + 1,
01651                                            bss->eap_req_id_text_len -
01652                                            (term - bss->eap_req_id_text) - 1);
01653                                 bss->eap_req_id_text_len--;
01654                         }
01655                 } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
01656                         bss->default_wep_key_len = atoi(pos);
01657                         if (bss->default_wep_key_len > 13) {
01658                                 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
01659                                            "key len %lu (= %lu bits)", line,
01660                                            (unsigned long)
01661                                            bss->default_wep_key_len,
01662                                            (unsigned long)
01663                                            bss->default_wep_key_len * 8);
01664                                 errors++;
01665                         }
01666                 } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
01667                         bss->individual_wep_key_len = atoi(pos);
01668                         if (bss->individual_wep_key_len < 0 ||
01669                             bss->individual_wep_key_len > 13) {
01670                                 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
01671                                            "key len %d (= %d bits)", line,
01672                                            bss->individual_wep_key_len,
01673                                            bss->individual_wep_key_len * 8);
01674                                 errors++;
01675                         }
01676                 } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
01677                         bss->wep_rekeying_period = atoi(pos);
01678                         if (bss->wep_rekeying_period < 0) {
01679                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
01680                                            "period %d",
01681                                            line, bss->wep_rekeying_period);
01682                                 errors++;
01683                         }
01684                 } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
01685                         bss->eap_reauth_period = atoi(pos);
01686                         if (bss->eap_reauth_period < 0) {
01687                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
01688                                            "period %d",
01689                                            line, bss->eap_reauth_period);
01690                                 errors++;
01691                         }
01692                 } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
01693                         bss->eapol_key_index_workaround = atoi(pos);
01694 #ifdef CONFIG_IAPP
01695                 } else if (os_strcmp(buf, "iapp_interface") == 0) {
01696                         bss->ieee802_11f = 1;
01697                         os_strlcpy(bss->iapp_iface, pos,
01698                                    sizeof(bss->iapp_iface));
01699 #endif /* CONFIG_IAPP */
01700                 } else if (os_strcmp(buf, "own_ip_addr") == 0) {
01701                         if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
01702                                 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
01703                                            "address '%s'", line, pos);
01704                                 errors++;
01705                         }
01706                 } else if (os_strcmp(buf, "nas_identifier") == 0) {
01707                         bss->nas_identifier = os_strdup(pos);
01708 #ifndef CONFIG_NO_RADIUS
01709                 } else if (os_strcmp(buf, "auth_server_addr") == 0) {
01710                         if (hostapd_config_read_radius_addr(
01711                                     &bss->radius->auth_servers,
01712                                     &bss->radius->num_auth_servers, pos, 1812,
01713                                     &bss->radius->auth_server)) {
01714                                 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
01715                                            "address '%s'", line, pos);
01716                                 errors++;
01717                         }
01718                 } else if (bss->radius->auth_server &&
01719                            os_strcmp(buf, "auth_server_port") == 0) {
01720                         bss->radius->auth_server->port = atoi(pos);
01721                 } else if (bss->radius->auth_server &&
01722                            os_strcmp(buf, "auth_server_shared_secret") == 0) {
01723                         int len = os_strlen(pos);
01724                         if (len == 0) {
01725                                 /* RFC 2865, Ch. 3 */
01726                                 wpa_printf(MSG_ERROR, "Line %d: empty shared "
01727                                            "secret is not allowed.", line);
01728                                 errors++;
01729                         }
01730                         bss->radius->auth_server->shared_secret =
01731                                 (u8 *) os_strdup(pos);
01732                         bss->radius->auth_server->shared_secret_len = len;
01733                 } else if (os_strcmp(buf, "acct_server_addr") == 0) {
01734                         if (hostapd_config_read_radius_addr(
01735                                     &bss->radius->acct_servers,
01736                                     &bss->radius->num_acct_servers, pos, 1813,
01737                                     &bss->radius->acct_server)) {
01738                                 wpa_printf(MSG_ERROR, "Line %d: invalid IP "
01739                                            "address '%s'", line, pos);
01740                                 errors++;
01741                         }
01742                 } else if (bss->radius->acct_server &&
01743                            os_strcmp(buf, "acct_server_port") == 0) {
01744                         bss->radius->acct_server->port = atoi(pos);
01745                 } else if (bss->radius->acct_server &&
01746                            os_strcmp(buf, "acct_server_shared_secret") == 0) {
01747                         int len = os_strlen(pos);
01748                         if (len == 0) {
01749                                 /* RFC 2865, Ch. 3 */
01750                                 wpa_printf(MSG_ERROR, "Line %d: empty shared "
01751                                            "secret is not allowed.", line);
01752                                 errors++;
01753                         }
01754                         bss->radius->acct_server->shared_secret =
01755                                 (u8 *) os_strdup(pos);
01756                         bss->radius->acct_server->shared_secret_len = len;
01757                 } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
01758                            0) {
01759                         bss->radius->retry_primary_interval = atoi(pos);
01760                 } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
01761                 {
01762                         bss->radius->acct_interim_interval = atoi(pos);
01763 #endif /* CONFIG_NO_RADIUS */
01764                 } else if (os_strcmp(buf, "auth_algs") == 0) {
01765                         bss->auth_algs = atoi(pos);
01766                         if (bss->auth_algs == 0) {
01767                                 wpa_printf(MSG_ERROR, "Line %d: no "
01768                                            "authentication algorithms allowed",
01769                                            line);
01770                                 errors++;
01771                         }
01772                 } else if (os_strcmp(buf, "max_num_sta") == 0) {
01773                         bss->max_num_sta = atoi(pos);
01774                         if (bss->max_num_sta < 0 ||
01775                             bss->max_num_sta > MAX_STA_COUNT) {
01776                                 wpa_printf(MSG_ERROR, "Line %d: Invalid "
01777                                            "max_num_sta=%d; allowed range "
01778                                            "0..%d", line, bss->max_num_sta,
01779                                            MAX_STA_COUNT);
01780                                 errors++;
01781                         }
01782                 } else if (os_strcmp(buf, "wpa") == 0) {
01783                         bss->wpa = atoi(pos);
01784                 } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
01785                         bss->wpa_group_rekey = atoi(pos);
01786                 } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
01787                         bss->wpa_strict_rekey = atoi(pos);
01788                 } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
01789                         bss->wpa_gmk_rekey = atoi(pos);
01790                 } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
01791                         bss->wpa_ptk_rekey = atoi(pos);
01792                 } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
01793                         int len = os_strlen(pos);
01794                         if (len < 8 || len > 63) {
01795                                 wpa_printf(MSG_ERROR, "Line %d: invalid WPA "
01796                                            "passphrase length %d (expected "
01797                                            "8..63)", line, len);
01798                                 errors++;
01799                         } else {
01800                                 os_free(bss->ssid.wpa_passphrase);
01801                                 bss->ssid.wpa_passphrase = os_strdup(pos);
01802                         }
01803                 } else if (os_strcmp(buf, "wpa_psk") == 0) {
01804                         os_free(bss->ssid.wpa_psk);
01805                         bss->ssid.wpa_psk =
01806                                 os_zalloc(sizeof(struct hostapd_wpa_psk));
01807                         if (bss->ssid.wpa_psk == NULL)
01808                                 errors++;
01809                         else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
01810                                             PMK_LEN) ||
01811                                  pos[PMK_LEN * 2] != '\0') {
01812                                 wpa_printf(MSG_ERROR, "Line %d: Invalid PSK "
01813                                            "'%s'.", line, pos);
01814                                 errors++;
01815                         } else {
01816                                 bss->ssid.wpa_psk->group = 1;
01817                         }
01818                 } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
01819                         os_free(bss->ssid.wpa_psk_file);
01820                         bss->ssid.wpa_psk_file = os_strdup(pos);
01821                         if (!bss->ssid.wpa_psk_file) {
01822                                 wpa_printf(MSG_ERROR, "Line %d: allocation "
01823                                            "failed", line);
01824                                 errors++;
01825                         }
01826                 } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
01827                         bss->wpa_key_mgmt =
01828                                 hostapd_config_parse_key_mgmt(line, pos);
01829                         if (bss->wpa_key_mgmt == -1)
01830                                 errors++;
01831                 } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
01832                         bss->wpa_pairwise =
01833                                 hostapd_config_parse_cipher(line, pos);
01834                         if (bss->wpa_pairwise == -1 ||
01835                             bss->wpa_pairwise == 0)
01836                                 errors++;
01837                         else if (bss->wpa_pairwise &
01838                                  (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
01839                                   WPA_CIPHER_WEP104)) {
01840                                 wpa_printf(MSG_ERROR, "Line %d: unsupported "
01841                                            "pairwise cipher suite '%s'",
01842                                            bss->wpa_pairwise, pos);
01843                                 errors++;
01844                         }
01845                 } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
01846                         bss->rsn_pairwise =
01847                                 hostapd_config_parse_cipher(line, pos);
01848                         if (bss->rsn_pairwise == -1 ||
01849                             bss->rsn_pairwise == 0)
01850                                 errors++;
01851                         else if (bss->rsn_pairwise &
01852                                  (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
01853                                   WPA_CIPHER_WEP104)) {
01854                                 wpa_printf(MSG_ERROR, "Line %d: unsupported "
01855                                            "pairwise cipher suite '%s'",
01856                                            bss->rsn_pairwise, pos);
01857                                 errors++;
01858                         }
01859 #ifdef CONFIG_RSN_PREAUTH
01860                 } else if (os_strcmp(buf, "rsn_preauth") == 0) {
01861                         bss->rsn_preauth = atoi(pos);
01862                 } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
01863                         bss->rsn_preauth_interfaces = os_strdup(pos);
01864 #endif /* CONFIG_RSN_PREAUTH */
01865 #ifdef CONFIG_PEERKEY
01866                 } else if (os_strcmp(buf, "peerkey") == 0) {
01867                         bss->peerkey = atoi(pos);
01868 #endif /* CONFIG_PEERKEY */
01869 #ifdef CONFIG_IEEE80211R
01870                 } else if (os_strcmp(buf, "mobility_domain") == 0) {
01871                         if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
01872                             hexstr2bin(pos, bss->mobility_domain,
01873                                        MOBILITY_DOMAIN_ID_LEN) != 0) {
01874                                 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
01875                                            "mobility_domain '%s'", line, pos);
01876                                 errors++;
01877                                 continue;
01878                         }
01879                 } else if (os_strcmp(buf, "r1_key_holder") == 0) {
01880                         if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
01881                             hexstr2bin(pos, bss->r1_key_holder,
01882                                        FT_R1KH_ID_LEN) != 0) {
01883                                 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
01884                                            "r1_key_holder '%s'", line, pos);
01885                                 errors++;
01886                                 continue;
01887                         }
01888                 } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
01889                         bss->r0_key_lifetime = atoi(pos);
01890                 } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
01891                         bss->reassociation_deadline = atoi(pos);
01892                 } else if (os_strcmp(buf, "r0kh") == 0) {
01893                         if (add_r0kh(bss, pos) < 0) {
01894                                 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
01895                                            "r0kh '%s'", line, pos);
01896                                 errors++;
01897                                 continue;
01898                         }
01899                 } else if (os_strcmp(buf, "r1kh") == 0) {
01900                         if (add_r1kh(bss, pos) < 0) {
01901                                 wpa_printf(MSG_DEBUG, "Line %d: Invalid "
01902                                            "r1kh '%s'", line, pos);
01903                                 errors++;
01904                                 continue;
01905                         }
01906                 } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
01907                         bss->pmk_r1_push = atoi(pos);
01908 #endif /* CONFIG_IEEE80211R */
01909 #ifndef CONFIG_NO_CTRL_IFACE
01910                 } else if (os_strcmp(buf, "ctrl_interface") == 0) {
01911                         os_free(bss->ctrl_interface);
01912                         bss->ctrl_interface = os_strdup(pos);
01913                 } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
01914 #ifndef CONFIG_NATIVE_WINDOWS
01915                         struct group *grp;
01916                         char *endp;
01917                         const char *group = pos;
01918 
01919                         grp = getgrnam(group);
01920                         if (grp) {
01921                                 bss->ctrl_interface_gid = grp->gr_gid;
01922                                 bss->ctrl_interface_gid_set = 1;
01923                                 wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
01924                                            " (from group name '%s')",
01925                                            bss->ctrl_interface_gid, group);
01926                                 continue;
01927                         }
01928 
01929                         /* Group name not found - try to parse this as gid */
01930                         bss->ctrl_interface_gid = strtol(group, &endp, 10);
01931                         if (*group == '\0' || *endp != '\0') {
01932                                 wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
01933                                            "'%s'", line, group);
01934                                 errors++;
01935                                 continue;
01936                         }
01937                         bss->ctrl_interface_gid_set = 1;
01938                         wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
01939                                    bss->ctrl_interface_gid);
01940 #endif /* CONFIG_NATIVE_WINDOWS */
01941 #endif /* CONFIG_NO_CTRL_IFACE */
01942 #ifdef RADIUS_SERVER
01943                 } else if (os_strcmp(buf, "radius_server_clients") == 0) {
01944                         os_free(bss->radius_server_clients);
01945                         bss->radius_server_clients = os_strdup(pos);
01946                 } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
01947                         bss->radius_server_auth_port = atoi(pos);
01948                 } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
01949                         bss->radius_server_ipv6 = atoi(pos);
01950 #endif /* RADIUS_SERVER */
01951                 } else if (os_strcmp(buf, "test_socket") == 0) {
01952                         os_free(bss->test_socket);
01953                         bss->test_socket = os_strdup(pos);
01954                 } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
01955                         bss->use_pae_group_addr = atoi(pos);
01956                 } else if (os_strcmp(buf, "hw_mode") == 0) {
01957                         if (os_strcmp(pos, "a") == 0)
01958                                 conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
01959                         else if (os_strcmp(pos, "b") == 0)
01960                                 conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
01961                         else if (os_strcmp(pos, "g") == 0)
01962                                 conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
01963                         else {
01964                                 wpa_printf(MSG_ERROR, "Line %d: unknown "
01965                                            "hw_mode '%s'", line, pos);
01966                                 errors++;
01967                         }
01968                 } else if (os_strcmp(buf, "channel") == 0) {
01969                         conf->channel = atoi(pos);
01970                 } else if (os_strcmp(buf, "beacon_int") == 0) {
01971                         int val = atoi(pos);
01972                         /* MIB defines range as 1..65535, but very small values
01973                          * cause problems with the current implementation.
01974                          * Since it is unlikely that this small numbers are
01975                          * useful in real life scenarios, do not allow beacon
01976                          * period to be set below 15 TU. */
01977                         if (val < 15 || val > 65535) {
01978                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
01979                                            "beacon_int %d (expected "
01980                                            "15..65535)", line, val);
01981                                 errors++;
01982                         } else
01983                                 conf->beacon_int = val;
01984                 } else if (os_strcmp(buf, "dtim_period") == 0) {
01985                         bss->dtim_period = atoi(pos);
01986                         if (bss->dtim_period < 1 || bss->dtim_period > 255) {
01987                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
01988                                            "dtim_period %d",
01989                                            line, bss->dtim_period);
01990                                 errors++;
01991                         }
01992                 } else if (os_strcmp(buf, "rts_threshold") == 0) {
01993                         conf->rts_threshold = atoi(pos);
01994                         if (conf->rts_threshold < 0 ||
01995                             conf->rts_threshold > 2347) {
01996                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
01997                                            "rts_threshold %d",
01998                                            line, conf->rts_threshold);
01999                                 errors++;
02000                         }
02001                 } else if (os_strcmp(buf, "fragm_threshold") == 0) {
02002                         conf->fragm_threshold = atoi(pos);
02003                         if (conf->fragm_threshold < 256 ||
02004                             conf->fragm_threshold > 2346) {
02005                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
02006                                            "fragm_threshold %d",
02007                                            line, conf->fragm_threshold);
02008                                 errors++;
02009                         }
02010                 } else if (os_strcmp(buf, "send_probe_response") == 0) {
02011                         int val = atoi(pos);
02012                         if (val != 0 && val != 1) {
02013                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
02014                                            "send_probe_response %d (expected "
02015                                            "0 or 1)", line, val);
02016                         } else
02017                                 conf->send_probe_response = val;
02018                 } else if (os_strcmp(buf, "supported_rates") == 0) {
02019                         if (hostapd_parse_rates(&conf->supported_rates, pos)) {
02020                                 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
02021                                            "list", line);
02022                                 errors++;
02023                         }
02024                 } else if (os_strcmp(buf, "basic_rates") == 0) {
02025                         if (hostapd_parse_rates(&conf->basic_rates, pos)) {
02026                                 wpa_printf(MSG_ERROR, "Line %d: invalid rate "
02027                                            "list", line);
02028                                 errors++;
02029                         }
02030                 } else if (os_strcmp(buf, "preamble") == 0) {
02031                         if (atoi(pos))
02032                                 conf->preamble = SHORT_PREAMBLE;
02033                         else
02034                                 conf->preamble = LONG_PREAMBLE;
02035                 } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
02036                         bss->ignore_broadcast_ssid = atoi(pos);
02037                 } else if (os_strcmp(buf, "bridge_packets") == 0) {
02038                         conf->bridge_packets = atoi(pos);
02039                 } else if (os_strcmp(buf, "wep_default_key") == 0) {
02040                         bss->ssid.wep.idx = atoi(pos);
02041                         if (bss->ssid.wep.idx > 3) {
02042                                 wpa_printf(MSG_ERROR, "Invalid "
02043                                            "wep_default_key index %d",
02044                                            bss->ssid.wep.idx);
02045                                 errors++;
02046                         }
02047                 } else if (os_strcmp(buf, "wep_key0") == 0 ||
02048                            os_strcmp(buf, "wep_key1") == 0 ||
02049                            os_strcmp(buf, "wep_key2") == 0 ||
02050                            os_strcmp(buf, "wep_key3") == 0) {
02051                         if (hostapd_config_read_wep(&bss->ssid.wep,
02052                                                     buf[7] - '0', pos)) {
02053                                 wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
02054                                            "key '%s'", line, buf);
02055                                 errors++;
02056                         }
02057 #ifndef CONFIG_NO_VLAN
02058                 } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
02059                         bss->ssid.dynamic_vlan = atoi(pos);
02060                 } else if (os_strcmp(buf, "vlan_file") == 0) {
02061                         if (hostapd_config_read_vlan_file(bss, pos)) {
02062                                 wpa_printf(MSG_ERROR, "Line %d: failed to "
02063                                            "read VLAN file '%s'", line, pos);
02064                                 errors++;
02065                         }
02066 #ifdef CONFIG_FULL_DYNAMIC_VLAN
02067                 } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
02068                         bss->ssid.vlan_tagged_interface = os_strdup(pos);
02069 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
02070 #endif /* CONFIG_NO_VLAN */
02071                 } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
02072                         conf->ap_table_max_size = atoi(pos);
02073                 } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
02074                         conf->ap_table_expiration_time = atoi(pos);
02075                 } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
02076                         if (hostapd_config_tx_queue(conf, buf, pos)) {
02077                                 wpa_printf(MSG_ERROR, "Line %d: invalid TX "
02078                                            "queue item", line);
02079                                 errors++;
02080                         }
02081                 } else if (os_strcmp(buf, "wme_enabled") == 0 ||
02082                            os_strcmp(buf, "wmm_enabled") == 0) {
02083                         bss->wmm_enabled = atoi(pos);
02084                 } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
02085                            os_strncmp(buf, "wmm_ac_", 7) == 0) {
02086                         if (hostapd_config_wmm_ac(conf, buf, pos)) {
02087                                 wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
02088                                            "ac item", line);
02089                                 errors++;
02090                         }
02091                 } else if (os_strcmp(buf, "bss") == 0) {
02092                         if (hostapd_config_bss(conf, pos)) {
02093                                 wpa_printf(MSG_ERROR, "Line %d: invalid bss "
02094                                            "item", line);
02095                                 errors++;
02096                         }
02097                 } else if (os_strcmp(buf, "bssid") == 0) {
02098                         if (hwaddr_aton(pos, bss->bssid)) {
02099                                 wpa_printf(MSG_ERROR, "Line %d: invalid bssid "
02100                                            "item", line);
02101                                 errors++;
02102                         }
02103 #ifdef CONFIG_IEEE80211W
02104                 } else if (os_strcmp(buf, "ieee80211w") == 0) {
02105                         bss->ieee80211w = atoi(pos);
02106                 } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
02107                         bss->assoc_sa_query_max_timeout = atoi(pos);
02108                         if (bss->assoc_sa_query_max_timeout == 0) {
02109                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
02110                                            "assoc_sa_query_max_timeout", line);
02111                                 errors++;
02112                         }
02113                 } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0)
02114                 {
02115                         bss->assoc_sa_query_retry_timeout = atoi(pos);
02116                         if (bss->assoc_sa_query_retry_timeout == 0) {
02117                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
02118                                            "assoc_sa_query_retry_timeout",
02119                                            line);
02120                                 errors++;
02121                         }
02122 #endif /* CONFIG_IEEE80211W */
02123 #ifdef CONFIG_IEEE80211N
02124                 } else if (os_strcmp(buf, "ieee80211n") == 0) {
02125                         conf->ieee80211n = atoi(pos);
02126                 } else if (os_strcmp(buf, "ht_capab") == 0) {
02127                         if (hostapd_config_ht_capab(conf, pos) < 0) {
02128                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
02129                                            "ht_capab", line);
02130                                 errors++;
02131                         }
02132 #endif /* CONFIG_IEEE80211N */
02133                 } else if (os_strcmp(buf, "max_listen_interval") == 0) {
02134                         bss->max_listen_interval = atoi(pos);
02135                 } else if (os_strcmp(buf, "okc") == 0) {
02136                         bss->okc = atoi(pos);
02137 #ifdef CONFIG_WPS
02138                 } else if (os_strcmp(buf, "wps_state") == 0) {
02139                         bss->wps_state = atoi(pos);
02140                         if (bss->wps_state < 0 || bss->wps_state > 2) {
02141                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
02142                                            "wps_state", line);
02143                                 errors++;
02144                         }
02145                 } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
02146                         bss->ap_setup_locked = atoi(pos);
02147                 } else if (os_strcmp(buf, "uuid") == 0) {
02148                         if (uuid_str2bin(pos, bss->uuid)) {
02149                                 wpa_printf(MSG_ERROR, "Line %d: invalid UUID",
02150                                            line);
02151                                 errors++;
02152                         }
02153                 } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
02154                         os_free(bss->wps_pin_requests);
02155                         bss->wps_pin_requests = os_strdup(pos);
02156                 } else if (os_strcmp(buf, "device_name") == 0) {
02157                         if (os_strlen(pos) > 32) {
02158                                 wpa_printf(MSG_ERROR, "Line %d: Too long "
02159                                            "device_name", line);
02160                                 errors++;
02161                         }
02162                         os_free(bss->device_name);
02163                         bss->device_name = os_strdup(pos);
02164                 } else if (os_strcmp(buf, "manufacturer") == 0) {
02165                         if (os_strlen(pos) > 64) {
02166                                 wpa_printf(MSG_ERROR, "Line %d: Too long "
02167                                            "manufacturer", line);
02168                                 errors++;
02169                         }
02170                         os_free(bss->manufacturer);
02171                         bss->manufacturer = os_strdup(pos);
02172                 } else if (os_strcmp(buf, "model_name") == 0) {
02173                         if (os_strlen(pos) > 32) {
02174                                 wpa_printf(MSG_ERROR, "Line %d: Too long "
02175                                            "model_name", line);
02176                                 errors++;
02177                         }
02178                         os_free(bss->model_name);
02179                         bss->model_name = os_strdup(pos);
02180                 } else if (os_strcmp(buf, "model_number") == 0) {
02181                         if (os_strlen(pos) > 32) {
02182                                 wpa_printf(MSG_ERROR, "Line %d: Too long "
02183                                            "model_number", line);
02184                                 errors++;
02185                         }
02186                         os_free(bss->model_number);
02187                         bss->model_number = os_strdup(pos);
02188                 } else if (os_strcmp(buf, "serial_number") == 0) {
02189                         if (os_strlen(pos) > 32) {
02190                                 wpa_printf(MSG_ERROR, "Line %d: Too long "
02191                                            "serial_number", line);
02192                                 errors++;
02193                         }
02194                         os_free(bss->serial_number);
02195                         bss->serial_number = os_strdup(pos);
02196                 } else if (os_strcmp(buf, "device_type") == 0) {
02197                         os_free(bss->device_type);
02198                         bss->device_type = os_strdup(pos);
02199                 } else if (os_strcmp(buf, "config_methods") == 0) {
02200                         os_free(bss->config_methods);
02201                         bss->config_methods = os_strdup(pos);
02202                 } else if (os_strcmp(buf, "os_version") == 0) {
02203                         if (hexstr2bin(pos, bss->os_version, 4)) {
02204                                 wpa_printf(MSG_ERROR, "Line %d: invalid "
02205                                            "os_version", line);
02206                                 errors++;
02207                         }
02208                 } else if (os_strcmp(buf, "ap_pin") == 0) {
02209                         os_free(bss->ap_pin);
02210                         bss->ap_pin = os_strdup(pos);
02211                 } else if (os_strcmp(buf, "skip_cred_build") == 0) {
02212                         bss->skip_cred_build = atoi(pos);
02213                 } else if (os_strcmp(buf, "extra_cred") == 0) {
02214                         os_free(bss->extra_cred);
02215                         bss->extra_cred =
02216                                 (u8 *) os_readfile(pos, &bss->extra_cred_len);
02217                         if (bss->extra_cred == NULL) {
02218                                 wpa_printf(MSG_ERROR, "Line %d: could not "
02219                                            "read Credentials from '%s'",
02220                                            line, pos);
02221                                 errors++;
02222                         }
02223                 } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
02224                         bss->wps_cred_processing = atoi(pos);
02225                 } else if (os_strcmp(buf, "ap_settings") == 0) {
02226                         os_free(bss->ap_settings);
02227                         bss->ap_settings =
02228                                 (u8 *) os_readfile(pos, &bss->ap_settings_len);
02229                         if (bss->ap_settings == NULL) {
02230                                 wpa_printf(MSG_ERROR, "Line %d: could not "
02231                                            "read AP Settings from '%s'",
02232                                            line, pos);
02233                                 errors++;
02234                         }
02235                 } else if (os_strcmp(buf, "upnp_iface") == 0) {
02236                         bss->upnp_iface = os_strdup(pos);
02237                 } else if (os_strcmp(buf, "friendly_name") == 0) {
02238                         os_free(bss->friendly_name);
02239                         bss->friendly_name = os_strdup(pos);
02240                 } else if (os_strcmp(buf, "manufacturer_url") == 0) {
02241                         os_free(bss->manufacturer_url);
02242                         bss->manufacturer_url = os_strdup(pos);
02243                 } else if (os_strcmp(buf, "model_description") == 0) {
02244                         os_free(bss->model_description);
02245                         bss->model_description = os_strdup(pos);
02246                 } else if (os_strcmp(buf, "model_url") == 0) {
02247                         os_free(bss->model_url);
02248                         bss->model_url = os_strdup(pos);
02249                 } else if (os_strcmp(buf, "upc") == 0) {
02250                         os_free(bss->upc);
02251                         bss->upc = os_strdup(pos);
02252 #endif /* CONFIG_WPS */
02253                 } else {
02254                         wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
02255                                    "item '%s'", line, buf);
02256                         errors++;
02257                 }
02258         }
02259 
02260         fclose(f);
02261 
02262         for (i = 0; i < conf->num_bss; i++) {
02263                 bss = &conf->bss[i];
02264 
02265                 if (bss->individual_wep_key_len == 0) {
02266                         /* individual keys are not use; can use key idx0 for
02267                          * broadcast keys */
02268                         bss->broadcast_key_idx_min = 0;
02269                 }
02270 
02271                 /* Select group cipher based on the enabled pairwise cipher
02272                  * suites */
02273                 pairwise = 0;
02274                 if (bss->wpa & 1)
02275                         pairwise |= bss->wpa_pairwise;
02276                 if (bss->wpa & 2) {
02277                         if (bss->rsn_pairwise == 0)
02278                                 bss->rsn_pairwise = bss->wpa_pairwise;
02279                         pairwise |= bss->rsn_pairwise;
02280                 }
02281                 if (pairwise & WPA_CIPHER_TKIP)
02282                         bss->wpa_group = WPA_CIPHER_TKIP;
02283                 else
02284                         bss->wpa_group = WPA_CIPHER_CCMP;
02285 
02286                 bss->radius->auth_server = bss->radius->auth_servers;
02287                 bss->radius->acct_server = bss->radius->acct_servers;
02288 
02289                 if (bss->wpa && bss->ieee802_1x) {
02290                         bss->ssid.security_policy = SECURITY_WPA;
02291                 } else if (bss->wpa) {
02292                         bss->ssid.security_policy = SECURITY_WPA_PSK;
02293                 } else if (bss->ieee802_1x) {
02294                         bss->ssid.security_policy = SECURITY_IEEE_802_1X;
02295                         bss->ssid.wep.default_len = bss->default_wep_key_len;
02296                 } else if (bss->ssid.wep.keys_set)
02297                         bss->ssid.security_policy = SECURITY_STATIC_WEP;
02298                 else
02299                         bss->ssid.security_policy = SECURITY_PLAINTEXT;
02300         }
02301 
02302         if (hostapd_config_check(conf))
02303                 errors++;
02304 
02305         if (errors) {
02306                 wpa_printf(MSG_ERROR, "%d errors found in configuration file "
02307                            "'%s'", errors, fname);
02308                 hostapd_config_free(conf);
02309                 conf = NULL;
02310         }
02311 
02312         return conf;
02313 }
02314 
02315 
02316 int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b)
02317 {
02318         int i;
02319 
02320         if (a->idx != b->idx || a->default_len != b->default_len)
02321                 return 1;
02322         for (i = 0; i < NUM_WEP_KEYS; i++)
02323                 if (a->len[i] != b->len[i] ||
02324                     os_memcmp(a->key[i], b->key[i], a->len[i]) != 0)
02325                         return 1;
02326         return 0;
02327 }
02328 
02329 
02330 static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
02331                                        int num_servers)
02332 {
02333         int i;
02334 
02335         for (i = 0; i < num_servers; i++) {
02336                 os_free(servers[i].shared_secret);
02337         }
02338         os_free(servers);
02339 }
02340 
02341 
02342 static void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
02343 {
02344         os_free(user->identity);
02345         os_free(user->password);
02346         os_free(user);
02347 }
02348 
02349 
02350 static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
02351 {
02352         int i;
02353         for (i = 0; i < NUM_WEP_KEYS; i++) {
02354                 os_free(keys->key[i]);
02355                 keys->key[i] = NULL;
02356         }
02357 }
02358 
02359 
02360 static void hostapd_config_free_bss(struct hostapd_bss_config *conf)
02361 {
02362         struct hostapd_wpa_psk *psk, *prev;
02363         struct hostapd_eap_user *user, *prev_user;
02364 
02365         if (conf == NULL)
02366                 return;
02367 
02368         psk = conf->ssid.wpa_psk;
02369         while (psk) {
02370                 prev = psk;
02371                 psk = psk->next;
02372                 os_free(prev);
02373         }
02374 
02375         os_free(conf->ssid.wpa_passphrase);
02376         os_free(conf->ssid.wpa_psk_file);
02377 #ifdef CONFIG_FULL_DYNAMIC_VLAN
02378         os_free(conf->ssid.vlan_tagged_interface);
02379 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
02380 
02381         user = conf->eap_user;
02382         while (user) {
02383                 prev_user = user;
02384                 user = user->next;
02385                 hostapd_config_free_eap_user(prev_user);
02386         }
02387 
02388         os_free(conf->dump_log_name);
02389         os_free(conf->eap_req_id_text);
02390         os_free(conf->accept_mac);
02391         os_free(conf->deny_mac);
02392         os_free(conf->nas_identifier);
02393         hostapd_config_free_radius(conf->radius->auth_servers,
02394                                    conf->radius->num_auth_servers);
02395         hostapd_config_free_radius(conf->radius->acct_servers,
02396                                    conf->radius->num_acct_servers);
02397         os_free(conf->rsn_preauth_interfaces);
02398         os_free(conf->ctrl_interface);
02399         os_free(conf->ca_cert);
02400         os_free(conf->server_cert);
02401         os_free(conf->private_key);
02402         os_free(conf->private_key_passwd);
02403         os_free(conf->dh_file);
02404         os_free(conf->pac_opaque_encr_key);
02405         os_free(conf->eap_fast_a_id);
02406         os_free(conf->eap_fast_a_id_info);
02407         os_free(conf->eap_sim_db);
02408         os_free(conf->radius_server_clients);
02409         os_free(conf->test_socket);
02410         os_free(conf->radius);
02411         hostapd_config_free_vlan(conf);
02412         if (conf->ssid.dyn_vlan_keys) {
02413                 struct hostapd_ssid *ssid = &conf->ssid;
02414                 size_t i;
02415                 for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
02416                         if (ssid->dyn_vlan_keys[i] == NULL)
02417                                 continue;
02418                         hostapd_config_free_wep(ssid->dyn_vlan_keys[i]);
02419                         os_free(ssid->dyn_vlan_keys[i]);
02420                 }
02421                 os_free(ssid->dyn_vlan_keys);
02422                 ssid->dyn_vlan_keys = NULL;
02423         }
02424 
02425 #ifdef CONFIG_IEEE80211R
02426         {
02427                 struct ft_remote_r0kh *r0kh, *r0kh_prev;
02428                 struct ft_remote_r1kh *r1kh, *r1kh_prev;
02429 
02430                 r0kh = conf->r0kh_list;
02431                 conf->r0kh_list = NULL;
02432                 while (r0kh) {
02433                         r0kh_prev = r0kh;
02434                         r0kh = r0kh->next;
02435                         os_free(r0kh_prev);
02436                 }
02437 
02438                 r1kh = conf->r1kh_list;
02439                 conf->r1kh_list = NULL;
02440                 while (r1kh) {
02441                         r1kh_prev = r1kh;
02442                         r1kh = r1kh->next;
02443                         os_free(r1kh_prev);
02444                 }
02445         }
02446 #endif /* CONFIG_IEEE80211R */
02447 
02448 #ifdef CONFIG_WPS
02449         os_free(conf->wps_pin_requests);
02450         os_free(conf->device_name);
02451         os_free(conf->manufacturer);
02452         os_free(conf->model_name);
02453         os_free(conf->model_number);
02454         os_free(conf->serial_number);
02455         os_free(conf->device_type);
02456         os_free(conf->config_methods);
02457         os_free(conf->ap_pin);
02458         os_free(conf->extra_cred);
02459         os_free(conf->ap_settings);
02460         os_free(conf->upnp_iface);
02461         os_free(conf->friendly_name);
02462         os_free(conf->manufacturer_url);
02463         os_free(conf->model_description);
02464         os_free(conf->model_url);
02465         os_free(conf->upc);
02466 #endif /* CONFIG_WPS */
02467 }
02468 
02469 
02475 void hostapd_config_free(struct hostapd_config *conf)
02476 {
02477         size_t i;
02478 
02479         if (conf == NULL)
02480                 return;
02481 
02482         for (i = 0; i < conf->num_bss; i++)
02483                 hostapd_config_free_bss(&conf->bss[i]);
02484         os_free(conf->bss);
02485 
02486         os_free(conf);
02487 }
02488 
02489 
02501 int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
02502                           const u8 *addr, int *vlan_id)
02503 {
02504         int start, end, middle, res;
02505 
02506         start = 0;
02507         end = num_entries - 1;
02508 
02509         while (start <= end) {
02510                 middle = (start + end) / 2;
02511                 res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
02512                 if (res == 0) {
02513                         if (vlan_id)
02514                                 *vlan_id = list[middle].vlan_id;
02515                         return 1;
02516                 }
02517                 if (res < 0)
02518                         start = middle + 1;
02519                 else
02520                         end = middle - 1;
02521         }
02522 
02523         return 0;
02524 }
02525 
02526 
02527 int hostapd_rate_found(int *list, int rate)
02528 {
02529         int i;
02530 
02531         if (list == NULL)
02532                 return 0;
02533 
02534         for (i = 0; list[i] >= 0; i++)
02535                 if (list[i] == rate)
02536                         return 1;
02537 
02538         return 0;
02539 }
02540 
02541 
02542 const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
02543 {
02544         struct hostapd_vlan *v = vlan;
02545         while (v) {
02546                 if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
02547                         return v->ifname;
02548                 v = v->next;
02549         }
02550         return NULL;
02551 }
02552 
02553 
02554 const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
02555                            const u8 *addr, const u8 *prev_psk)
02556 {
02557         struct hostapd_wpa_psk *psk;
02558         int next_ok = prev_psk == NULL;
02559 
02560         for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
02561                 if (next_ok &&
02562                     (psk->group || os_memcmp(psk->addr, addr, ETH_ALEN) == 0))
02563                         return psk->psk;
02564 
02565                 if (psk->psk == prev_psk)
02566                         next_ok = 1;
02567         }
02568 
02569         return NULL;
02570 }
02571 
02572 
02573 const struct hostapd_eap_user *
02574 hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
02575                      size_t identity_len, int phase2)
02576 {
02577         struct hostapd_eap_user *user = conf->eap_user;
02578 
02579 #ifdef CONFIG_WPS
02580         if (conf->wps_state && identity_len == WSC_ID_ENROLLEE_LEN &&
02581             os_memcmp(identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN) == 0) {
02582                 static struct hostapd_eap_user wsc_enrollee;
02583                 os_memset(&wsc_enrollee, 0, sizeof(wsc_enrollee));
02584                 wsc_enrollee.methods[0].method = eap_server_get_type(
02585                         "WSC", &wsc_enrollee.methods[0].vendor);
02586                 return &wsc_enrollee;
02587         }
02588 
02589         if (conf->wps_state && conf->ap_pin &&
02590             identity_len == WSC_ID_REGISTRAR_LEN &&
02591             os_memcmp(identity, WSC_ID_REGISTRAR, WSC_ID_REGISTRAR_LEN) == 0) {
02592                 static struct hostapd_eap_user wsc_registrar;
02593                 os_memset(&wsc_registrar, 0, sizeof(wsc_registrar));
02594                 wsc_registrar.methods[0].method = eap_server_get_type(
02595                         "WSC", &wsc_registrar.methods[0].vendor);
02596                 wsc_registrar.password = (u8 *) conf->ap_pin;
02597                 wsc_registrar.password_len = os_strlen(conf->ap_pin);
02598                 return &wsc_registrar;
02599         }
02600 #endif /* CONFIG_WPS */
02601 
02602         while (user) {
02603                 if (!phase2 && user->identity == NULL) {
02604                         /* Wildcard match */
02605                         break;
02606                 }
02607 
02608                 if (user->phase2 == !!phase2 && user->wildcard_prefix &&
02609                     identity_len >= user->identity_len &&
02610                     os_memcmp(user->identity, identity, user->identity_len) ==
02611                     0) {
02612                         /* Wildcard prefix match */
02613                         break;
02614                 }
02615 
02616                 if (user->phase2 == !!phase2 &&
02617                     user->identity_len == identity_len &&
02618                     os_memcmp(user->identity, identity, identity_len) == 0)
02619                         break;
02620                 user = user->next;
02621         }
02622 
02623         return user;
02624 }
02625 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Sat Nov 21 23:16:47 2009 for hostapd by  doxygen 1.6.1