config.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413
  1. /*
  2. * hostapd / Configuration file
  3. * Copyright (c) 2003-2008, Jouni Malinen <j@w1.fi>
  4. * Copyright (c) 2007-2008, Intel Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Alternatively, this software may be distributed under the terms of BSD
  11. * license.
  12. *
  13. * See README and COPYING for more details.
  14. */
  15. #include "includes.h"
  16. #ifndef CONFIG_NATIVE_WINDOWS
  17. #include <grp.h>
  18. #endif /* CONFIG_NATIVE_WINDOWS */
  19. #include "hostapd.h"
  20. #include "driver.h"
  21. #include "sha1.h"
  22. #include "eap_server/eap.h"
  23. #include "radius/radius_client.h"
  24. #include "wpa_common.h"
  25. #include "wpa.h"
  26. #include "uuid.h"
  27. #include "eap_common/eap_wsc_common.h"
  28. #define MAX_STA_COUNT 2007
  29. extern struct wpa_driver_ops *hostapd_drivers[];
  30. static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
  31. const char *fname)
  32. {
  33. FILE *f;
  34. char buf[128], *pos, *pos2;
  35. int line = 0, vlan_id;
  36. struct hostapd_vlan *vlan;
  37. f = fopen(fname, "r");
  38. if (!f) {
  39. printf("VLAN file '%s' not readable.\n", fname);
  40. return -1;
  41. }
  42. while (fgets(buf, sizeof(buf), f)) {
  43. line++;
  44. if (buf[0] == '#')
  45. continue;
  46. pos = buf;
  47. while (*pos != '\0') {
  48. if (*pos == '\n') {
  49. *pos = '\0';
  50. break;
  51. }
  52. pos++;
  53. }
  54. if (buf[0] == '\0')
  55. continue;
  56. if (buf[0] == '*') {
  57. vlan_id = VLAN_ID_WILDCARD;
  58. pos = buf + 1;
  59. } else {
  60. vlan_id = strtol(buf, &pos, 10);
  61. if (buf == pos || vlan_id < 1 ||
  62. vlan_id > MAX_VLAN_ID) {
  63. printf("Invalid VLAN ID at line %d in '%s'\n",
  64. line, fname);
  65. fclose(f);
  66. return -1;
  67. }
  68. }
  69. while (*pos == ' ' || *pos == '\t')
  70. pos++;
  71. pos2 = pos;
  72. while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
  73. pos2++;
  74. *pos2 = '\0';
  75. if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
  76. printf("Invalid VLAN ifname at line %d in '%s'\n",
  77. line, fname);
  78. fclose(f);
  79. return -1;
  80. }
  81. vlan = os_malloc(sizeof(*vlan));
  82. if (vlan == NULL) {
  83. printf("Out of memory while reading VLAN interfaces "
  84. "from '%s'\n", fname);
  85. fclose(f);
  86. return -1;
  87. }
  88. os_memset(vlan, 0, sizeof(*vlan));
  89. vlan->vlan_id = vlan_id;
  90. os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
  91. if (bss->vlan_tail)
  92. bss->vlan_tail->next = vlan;
  93. else
  94. bss->vlan = vlan;
  95. bss->vlan_tail = vlan;
  96. }
  97. fclose(f);
  98. return 0;
  99. }
  100. static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
  101. {
  102. struct hostapd_vlan *vlan, *prev;
  103. vlan = bss->vlan;
  104. prev = NULL;
  105. while (vlan) {
  106. prev = vlan;
  107. vlan = vlan->next;
  108. os_free(prev);
  109. }
  110. bss->vlan = NULL;
  111. }
  112. /* convert floats with one decimal place to value*10 int, i.e.,
  113. * "1.5" will return 15 */
  114. static int hostapd_config_read_int10(const char *value)
  115. {
  116. int i, d;
  117. char *pos;
  118. i = atoi(value);
  119. pos = os_strchr(value, '.');
  120. d = 0;
  121. if (pos) {
  122. pos++;
  123. if (*pos >= '0' && *pos <= '9')
  124. d = *pos - '0';
  125. }
  126. return i * 10 + d;
  127. }
  128. static void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
  129. {
  130. bss->logger_syslog_level = HOSTAPD_LEVEL_INFO;
  131. bss->logger_stdout_level = HOSTAPD_LEVEL_INFO;
  132. bss->logger_syslog = (unsigned int) -1;
  133. bss->logger_stdout = (unsigned int) -1;
  134. bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
  135. bss->wep_rekeying_period = 300;
  136. /* use key0 in individual key and key1 in broadcast key */
  137. bss->broadcast_key_idx_min = 1;
  138. bss->broadcast_key_idx_max = 2;
  139. bss->eap_reauth_period = 3600;
  140. bss->wpa_group_rekey = 600;
  141. bss->wpa_gmk_rekey = 86400;
  142. bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
  143. bss->wpa_pairwise = WPA_CIPHER_TKIP;
  144. bss->wpa_group = WPA_CIPHER_TKIP;
  145. bss->rsn_pairwise = 0;
  146. bss->max_num_sta = MAX_STA_COUNT;
  147. bss->dtim_period = 2;
  148. bss->radius_server_auth_port = 1812;
  149. bss->ap_max_inactivity = AP_MAX_INACTIVITY;
  150. bss->eapol_version = EAPOL_VERSION;
  151. bss->max_listen_interval = 65535;
  152. #ifdef CONFIG_IEEE80211W
  153. bss->assoc_ping_timeout = 1000;
  154. bss->assoc_ping_attempts = 3;
  155. #endif /* CONFIG_IEEE80211W */
  156. #ifdef EAP_FAST
  157. /* both anonymous and authenticated provisioning */
  158. bss->eap_fast_prov = 3;
  159. bss->pac_key_lifetime = 7 * 24 * 60 * 60;
  160. bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
  161. #endif /* EAP_FAST */
  162. }
  163. static struct hostapd_config * hostapd_config_defaults(void)
  164. {
  165. struct hostapd_config *conf;
  166. struct hostapd_bss_config *bss;
  167. int i;
  168. const int aCWmin = 15, aCWmax = 1024;
  169. const struct hostapd_wme_ac_params ac_bk =
  170. { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
  171. const struct hostapd_wme_ac_params ac_be =
  172. { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
  173. const struct hostapd_wme_ac_params ac_vi = /* video traffic */
  174. { aCWmin >> 1, aCWmin, 2, 3000 / 32, 1 };
  175. const struct hostapd_wme_ac_params ac_vo = /* voice traffic */
  176. { aCWmin >> 2, aCWmin >> 1, 2, 1500 / 32, 1 };
  177. conf = os_zalloc(sizeof(*conf));
  178. bss = os_zalloc(sizeof(*bss));
  179. if (conf == NULL || bss == NULL) {
  180. printf("Failed to allocate memory for configuration data.\n");
  181. os_free(conf);
  182. os_free(bss);
  183. return NULL;
  184. }
  185. /* set default driver based on configuration */
  186. conf->driver = hostapd_drivers[0];
  187. if (conf->driver == NULL) {
  188. printf("No driver wrappers registered!\n");
  189. os_free(conf);
  190. os_free(bss);
  191. return NULL;
  192. }
  193. bss->radius = os_zalloc(sizeof(*bss->radius));
  194. if (bss->radius == NULL) {
  195. os_free(conf);
  196. os_free(bss);
  197. return NULL;
  198. }
  199. hostapd_config_defaults_bss(bss);
  200. conf->num_bss = 1;
  201. conf->bss = bss;
  202. conf->beacon_int = 100;
  203. conf->rts_threshold = -1; /* use driver default: 2347 */
  204. conf->fragm_threshold = -1; /* user driver default: 2346 */
  205. conf->send_probe_response = 1;
  206. conf->bridge_packets = INTERNAL_BRIDGE_DO_NOT_CONTROL;
  207. os_memcpy(conf->country, "US ", 3);
  208. for (i = 0; i < NUM_TX_QUEUES; i++)
  209. conf->tx_queue[i].aifs = -1; /* use hw default */
  210. conf->wme_ac_params[0] = ac_be;
  211. conf->wme_ac_params[1] = ac_bk;
  212. conf->wme_ac_params[2] = ac_vi;
  213. conf->wme_ac_params[3] = ac_vo;
  214. #ifdef CONFIG_IEEE80211N
  215. SET_2BIT_LE16(&conf->ht_capab,
  216. HT_CAP_INFO_MIMO_PWR_SAVE_OFFSET,
  217. MIMO_PWR_NO_LIMIT_ON_MIMO_SEQS);
  218. conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
  219. #endif /* CONFIG_IEEE80211N */
  220. return conf;
  221. }
  222. int hostapd_mac_comp(const void *a, const void *b)
  223. {
  224. return os_memcmp(a, b, sizeof(macaddr));
  225. }
  226. int hostapd_mac_comp_empty(const void *a)
  227. {
  228. macaddr empty = { 0 };
  229. return os_memcmp(a, empty, sizeof(macaddr));
  230. }
  231. static int hostapd_acl_comp(const void *a, const void *b)
  232. {
  233. const struct mac_acl_entry *aa = a;
  234. const struct mac_acl_entry *bb = b;
  235. return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
  236. }
  237. static int hostapd_config_read_maclist(const char *fname,
  238. struct mac_acl_entry **acl, int *num)
  239. {
  240. FILE *f;
  241. char buf[128], *pos;
  242. int line = 0;
  243. u8 addr[ETH_ALEN];
  244. struct mac_acl_entry *newacl;
  245. int vlan_id;
  246. if (!fname)
  247. return 0;
  248. f = fopen(fname, "r");
  249. if (!f) {
  250. printf("MAC list file '%s' not found.\n", fname);
  251. return -1;
  252. }
  253. while (fgets(buf, sizeof(buf), f)) {
  254. line++;
  255. if (buf[0] == '#')
  256. continue;
  257. pos = buf;
  258. while (*pos != '\0') {
  259. if (*pos == '\n') {
  260. *pos = '\0';
  261. break;
  262. }
  263. pos++;
  264. }
  265. if (buf[0] == '\0')
  266. continue;
  267. if (hwaddr_aton(buf, addr)) {
  268. printf("Invalid MAC address '%s' at line %d in '%s'\n",
  269. buf, line, fname);
  270. fclose(f);
  271. return -1;
  272. }
  273. vlan_id = 0;
  274. pos = buf;
  275. while (*pos != '\0' && *pos != ' ' && *pos != '\t')
  276. pos++;
  277. while (*pos == ' ' || *pos == '\t')
  278. pos++;
  279. if (*pos != '\0')
  280. vlan_id = atoi(pos);
  281. newacl = os_realloc(*acl, (*num + 1) * sizeof(**acl));
  282. if (newacl == NULL) {
  283. printf("MAC list reallocation failed\n");
  284. fclose(f);
  285. return -1;
  286. }
  287. *acl = newacl;
  288. os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
  289. (*acl)[*num].vlan_id = vlan_id;
  290. (*num)++;
  291. }
  292. fclose(f);
  293. qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
  294. return 0;
  295. }
  296. static int hostapd_config_read_wpa_psk(const char *fname,
  297. struct hostapd_ssid *ssid)
  298. {
  299. FILE *f;
  300. char buf[128], *pos;
  301. int line = 0, ret = 0, len, ok;
  302. u8 addr[ETH_ALEN];
  303. struct hostapd_wpa_psk *psk;
  304. if (!fname)
  305. return 0;
  306. f = fopen(fname, "r");
  307. if (!f) {
  308. printf("WPA PSK file '%s' not found.\n", fname);
  309. return -1;
  310. }
  311. while (fgets(buf, sizeof(buf), f)) {
  312. line++;
  313. if (buf[0] == '#')
  314. continue;
  315. pos = buf;
  316. while (*pos != '\0') {
  317. if (*pos == '\n') {
  318. *pos = '\0';
  319. break;
  320. }
  321. pos++;
  322. }
  323. if (buf[0] == '\0')
  324. continue;
  325. if (hwaddr_aton(buf, addr)) {
  326. printf("Invalid MAC address '%s' on line %d in '%s'\n",
  327. buf, line, fname);
  328. ret = -1;
  329. break;
  330. }
  331. psk = os_zalloc(sizeof(*psk));
  332. if (psk == NULL) {
  333. printf("WPA PSK allocation failed\n");
  334. ret = -1;
  335. break;
  336. }
  337. if (is_zero_ether_addr(addr))
  338. psk->group = 1;
  339. else
  340. os_memcpy(psk->addr, addr, ETH_ALEN);
  341. pos = buf + 17;
  342. if (pos == '\0') {
  343. printf("No PSK on line %d in '%s'\n", line, fname);
  344. os_free(psk);
  345. ret = -1;
  346. break;
  347. }
  348. pos++;
  349. ok = 0;
  350. len = os_strlen(pos);
  351. if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
  352. ok = 1;
  353. else if (len >= 8 && len < 64) {
  354. pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
  355. 4096, psk->psk, PMK_LEN);
  356. ok = 1;
  357. }
  358. if (!ok) {
  359. printf("Invalid PSK '%s' on line %d in '%s'\n",
  360. pos, line, fname);
  361. os_free(psk);
  362. ret = -1;
  363. break;
  364. }
  365. psk->next = ssid->wpa_psk;
  366. ssid->wpa_psk = psk;
  367. }
  368. fclose(f);
  369. return ret;
  370. }
  371. int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
  372. {
  373. struct hostapd_ssid *ssid = &conf->ssid;
  374. if (ssid->wpa_passphrase != NULL) {
  375. if (ssid->wpa_psk != NULL) {
  376. printf("Warning: both WPA PSK and passphrase set. "
  377. "Using passphrase.\n");
  378. os_free(ssid->wpa_psk);
  379. }
  380. ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
  381. if (ssid->wpa_psk == NULL) {
  382. printf("Unable to alloc space for PSK\n");
  383. return -1;
  384. }
  385. wpa_hexdump_ascii(MSG_DEBUG, "SSID",
  386. (u8 *) ssid->ssid, ssid->ssid_len);
  387. wpa_hexdump_ascii(MSG_DEBUG, "PSK (ASCII passphrase)",
  388. (u8 *) ssid->wpa_passphrase,
  389. os_strlen(ssid->wpa_passphrase));
  390. pbkdf2_sha1(ssid->wpa_passphrase,
  391. ssid->ssid, ssid->ssid_len,
  392. 4096, ssid->wpa_psk->psk, PMK_LEN);
  393. wpa_hexdump(MSG_DEBUG, "PSK (from passphrase)",
  394. ssid->wpa_psk->psk, PMK_LEN);
  395. ssid->wpa_psk->group = 1;
  396. os_memset(ssid->wpa_passphrase, 0,
  397. os_strlen(ssid->wpa_passphrase));
  398. os_free(ssid->wpa_passphrase);
  399. ssid->wpa_passphrase = NULL;
  400. }
  401. if (ssid->wpa_psk_file) {
  402. if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file,
  403. &conf->ssid))
  404. return -1;
  405. }
  406. return 0;
  407. }
  408. #ifdef EAP_SERVER
  409. static int hostapd_config_read_eap_user(const char *fname,
  410. struct hostapd_bss_config *conf)
  411. {
  412. FILE *f;
  413. char buf[512], *pos, *start, *pos2;
  414. int line = 0, ret = 0, num_methods;
  415. struct hostapd_eap_user *user, *tail = NULL;
  416. if (!fname)
  417. return 0;
  418. f = fopen(fname, "r");
  419. if (!f) {
  420. printf("EAP user file '%s' not found.\n", fname);
  421. return -1;
  422. }
  423. /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
  424. while (fgets(buf, sizeof(buf), f)) {
  425. line++;
  426. if (buf[0] == '#')
  427. continue;
  428. pos = buf;
  429. while (*pos != '\0') {
  430. if (*pos == '\n') {
  431. *pos = '\0';
  432. break;
  433. }
  434. pos++;
  435. }
  436. if (buf[0] == '\0')
  437. continue;
  438. user = NULL;
  439. if (buf[0] != '"' && buf[0] != '*') {
  440. printf("Invalid EAP identity (no \" in start) on "
  441. "line %d in '%s'\n", line, fname);
  442. goto failed;
  443. }
  444. user = os_zalloc(sizeof(*user));
  445. if (user == NULL) {
  446. printf("EAP user allocation failed\n");
  447. goto failed;
  448. }
  449. user->force_version = -1;
  450. if (buf[0] == '*') {
  451. pos = buf;
  452. } else {
  453. pos = buf + 1;
  454. start = pos;
  455. while (*pos != '"' && *pos != '\0')
  456. pos++;
  457. if (*pos == '\0') {
  458. printf("Invalid EAP identity (no \" in end) on"
  459. " line %d in '%s'\n", line, fname);
  460. goto failed;
  461. }
  462. user->identity = os_malloc(pos - start);
  463. if (user->identity == NULL) {
  464. printf("Failed to allocate memory for EAP "
  465. "identity\n");
  466. goto failed;
  467. }
  468. os_memcpy(user->identity, start, pos - start);
  469. user->identity_len = pos - start;
  470. if (pos[0] == '"' && pos[1] == '*') {
  471. user->wildcard_prefix = 1;
  472. pos++;
  473. }
  474. }
  475. pos++;
  476. while (*pos == ' ' || *pos == '\t')
  477. pos++;
  478. if (*pos == '\0') {
  479. printf("No EAP method on line %d in '%s'\n",
  480. line, fname);
  481. goto failed;
  482. }
  483. start = pos;
  484. while (*pos != ' ' && *pos != '\t' && *pos != '\0')
  485. pos++;
  486. if (*pos == '\0') {
  487. pos = NULL;
  488. } else {
  489. *pos = '\0';
  490. pos++;
  491. }
  492. num_methods = 0;
  493. while (*start) {
  494. char *pos3 = os_strchr(start, ',');
  495. if (pos3) {
  496. *pos3++ = '\0';
  497. }
  498. user->methods[num_methods].method =
  499. eap_server_get_type(
  500. start,
  501. &user->methods[num_methods].vendor);
  502. if (user->methods[num_methods].vendor ==
  503. EAP_VENDOR_IETF &&
  504. user->methods[num_methods].method == EAP_TYPE_NONE)
  505. {
  506. if (os_strcmp(start, "TTLS-PAP") == 0) {
  507. user->ttls_auth |= EAP_TTLS_AUTH_PAP;
  508. goto skip_eap;
  509. }
  510. if (os_strcmp(start, "TTLS-CHAP") == 0) {
  511. user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
  512. goto skip_eap;
  513. }
  514. if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
  515. user->ttls_auth |=
  516. EAP_TTLS_AUTH_MSCHAP;
  517. goto skip_eap;
  518. }
  519. if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
  520. user->ttls_auth |=
  521. EAP_TTLS_AUTH_MSCHAPV2;
  522. goto skip_eap;
  523. }
  524. printf("Unsupported EAP type '%s' on line %d "
  525. "in '%s'\n", start, line, fname);
  526. goto failed;
  527. }
  528. num_methods++;
  529. if (num_methods >= EAP_USER_MAX_METHODS)
  530. break;
  531. skip_eap:
  532. if (pos3 == NULL)
  533. break;
  534. start = pos3;
  535. }
  536. if (num_methods == 0 && user->ttls_auth == 0) {
  537. printf("No EAP types configured on line %d in '%s'\n",
  538. line, fname);
  539. goto failed;
  540. }
  541. if (pos == NULL)
  542. goto done;
  543. while (*pos == ' ' || *pos == '\t')
  544. pos++;
  545. if (*pos == '\0')
  546. goto done;
  547. if (os_strncmp(pos, "[ver=0]", 7) == 0) {
  548. user->force_version = 0;
  549. goto done;
  550. }
  551. if (os_strncmp(pos, "[ver=1]", 7) == 0) {
  552. user->force_version = 1;
  553. goto done;
  554. }
  555. if (os_strncmp(pos, "[2]", 3) == 0) {
  556. user->phase2 = 1;
  557. goto done;
  558. }
  559. if (*pos == '"') {
  560. pos++;
  561. start = pos;
  562. while (*pos != '"' && *pos != '\0')
  563. pos++;
  564. if (*pos == '\0') {
  565. printf("Invalid EAP password (no \" in end) "
  566. "on line %d in '%s'\n", line, fname);
  567. goto failed;
  568. }
  569. user->password = os_malloc(pos - start);
  570. if (user->password == NULL) {
  571. printf("Failed to allocate memory for EAP "
  572. "password\n");
  573. goto failed;
  574. }
  575. os_memcpy(user->password, start, pos - start);
  576. user->password_len = pos - start;
  577. pos++;
  578. } else if (os_strncmp(pos, "hash:", 5) == 0) {
  579. pos += 5;
  580. pos2 = pos;
  581. while (*pos2 != '\0' && *pos2 != ' ' &&
  582. *pos2 != '\t' && *pos2 != '#')
  583. pos2++;
  584. if (pos2 - pos != 32) {
  585. printf("Invalid password hash on line %d in "
  586. "'%s'\n", line, fname);
  587. goto failed;
  588. }
  589. user->password = os_malloc(16);
  590. if (user->password == NULL) {
  591. printf("Failed to allocate memory for EAP "
  592. "password hash\n");
  593. goto failed;
  594. }
  595. if (hexstr2bin(pos, user->password, 16) < 0) {
  596. printf("Invalid hash password on line %d in "
  597. "'%s'\n", line, fname);
  598. goto failed;
  599. }
  600. user->password_len = 16;
  601. user->password_hash = 1;
  602. pos = pos2;
  603. } else {
  604. pos2 = pos;
  605. while (*pos2 != '\0' && *pos2 != ' ' &&
  606. *pos2 != '\t' && *pos2 != '#')
  607. pos2++;
  608. if ((pos2 - pos) & 1) {
  609. printf("Invalid hex password on line %d in "
  610. "'%s'\n", line, fname);
  611. goto failed;
  612. }
  613. user->password = os_malloc((pos2 - pos) / 2);
  614. if (user->password == NULL) {
  615. printf("Failed to allocate memory for EAP "
  616. "password\n");
  617. goto failed;
  618. }
  619. if (hexstr2bin(pos, user->password,
  620. (pos2 - pos) / 2) < 0) {
  621. printf("Invalid hex password on line %d in "
  622. "'%s'\n", line, fname);
  623. goto failed;
  624. }
  625. user->password_len = (pos2 - pos) / 2;
  626. pos = pos2;
  627. }
  628. while (*pos == ' ' || *pos == '\t')
  629. pos++;
  630. if (os_strncmp(pos, "[2]", 3) == 0) {
  631. user->phase2 = 1;
  632. }
  633. done:
  634. if (tail == NULL) {
  635. tail = conf->eap_user = user;
  636. } else {
  637. tail->next = user;
  638. tail = user;
  639. }
  640. continue;
  641. failed:
  642. if (user) {
  643. os_free(user->password);
  644. os_free(user->identity);
  645. os_free(user);
  646. }
  647. ret = -1;
  648. break;
  649. }
  650. fclose(f);
  651. return ret;
  652. }
  653. #endif /* EAP_SERVER */
  654. static int
  655. hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
  656. int *num_server, const char *val, int def_port,
  657. struct hostapd_radius_server **curr_serv)
  658. {
  659. struct hostapd_radius_server *nserv;
  660. int ret;
  661. static int server_index = 1;
  662. nserv = os_realloc(*server, (*num_server + 1) * sizeof(*nserv));
  663. if (nserv == NULL)
  664. return -1;
  665. *server = nserv;
  666. nserv = &nserv[*num_server];
  667. (*num_server)++;
  668. (*curr_serv) = nserv;
  669. os_memset(nserv, 0, sizeof(*nserv));
  670. nserv->port = def_port;
  671. ret = hostapd_parse_ip_addr(val, &nserv->addr);
  672. nserv->index = server_index++;
  673. return ret;
  674. }
  675. static int hostapd_config_parse_key_mgmt(int line, const char *value)
  676. {
  677. int val = 0, last;
  678. char *start, *end, *buf;
  679. buf = os_strdup(value);
  680. if (buf == NULL)
  681. return -1;
  682. start = buf;
  683. while (start != '\0') {
  684. while (*start == ' ' || *start == '\t')
  685. start++;
  686. if (*start == '\0')
  687. break;
  688. end = start;
  689. while (*end != ' ' && *end != '\t' && *end != '\0')
  690. end++;
  691. last = *end == '\0';
  692. *end = '\0';
  693. if (os_strcmp(start, "WPA-PSK") == 0)
  694. val |= WPA_KEY_MGMT_PSK;
  695. else if (os_strcmp(start, "WPA-EAP") == 0)
  696. val |= WPA_KEY_MGMT_IEEE8021X;
  697. #ifdef CONFIG_IEEE80211R
  698. else if (os_strcmp(start, "FT-PSK") == 0)
  699. val |= WPA_KEY_MGMT_FT_PSK;
  700. else if (os_strcmp(start, "FT-EAP") == 0)
  701. val |= WPA_KEY_MGMT_FT_IEEE8021X;
  702. #endif /* CONFIG_IEEE80211R */
  703. #ifdef CONFIG_IEEE80211W
  704. else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
  705. val |= WPA_KEY_MGMT_PSK_SHA256;
  706. else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
  707. val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
  708. #endif /* CONFIG_IEEE80211W */
  709. else {
  710. printf("Line %d: invalid key_mgmt '%s'\n",
  711. line, start);
  712. os_free(buf);
  713. return -1;
  714. }
  715. if (last)
  716. break;
  717. start = end + 1;
  718. }
  719. os_free(buf);
  720. if (val == 0) {
  721. printf("Line %d: no key_mgmt values configured.\n", line);
  722. return -1;
  723. }
  724. return val;
  725. }
  726. static int hostapd_config_parse_cipher(int line, const char *value)
  727. {
  728. int val = 0, last;
  729. char *start, *end, *buf;
  730. buf = os_strdup(value);
  731. if (buf == NULL)
  732. return -1;
  733. start = buf;
  734. while (start != '\0') {
  735. while (*start == ' ' || *start == '\t')
  736. start++;
  737. if (*start == '\0')
  738. break;
  739. end = start;
  740. while (*end != ' ' && *end != '\t' && *end != '\0')
  741. end++;
  742. last = *end == '\0';
  743. *end = '\0';
  744. if (os_strcmp(start, "CCMP") == 0)
  745. val |= WPA_CIPHER_CCMP;
  746. else if (os_strcmp(start, "TKIP") == 0)
  747. val |= WPA_CIPHER_TKIP;
  748. else if (os_strcmp(start, "WEP104") == 0)
  749. val |= WPA_CIPHER_WEP104;
  750. else if (os_strcmp(start, "WEP40") == 0)
  751. val |= WPA_CIPHER_WEP40;
  752. else if (os_strcmp(start, "NONE") == 0)
  753. val |= WPA_CIPHER_NONE;
  754. else {
  755. printf("Line %d: invalid cipher '%s'.", line, start);
  756. os_free(buf);
  757. return -1;
  758. }
  759. if (last)
  760. break;
  761. start = end + 1;
  762. }
  763. os_free(buf);
  764. if (val == 0) {
  765. printf("Line %d: no cipher values configured.", line);
  766. return -1;
  767. }
  768. return val;
  769. }
  770. static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
  771. struct hostapd_config *conf)
  772. {
  773. if (bss->ieee802_1x && !bss->eap_server &&
  774. !bss->radius->auth_servers) {
  775. printf("Invalid IEEE 802.1X configuration (no EAP "
  776. "authenticator configured).\n");
  777. return -1;
  778. }
  779. if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
  780. bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
  781. bss->ssid.wpa_psk_file == NULL) {
  782. printf("WPA-PSK enabled, but PSK or passphrase is not "
  783. "configured.\n");
  784. return -1;
  785. }
  786. if (hostapd_mac_comp_empty(bss->bssid) != 0) {
  787. size_t i;
  788. for (i = 0; i < conf->num_bss; i++) {
  789. if ((&conf->bss[i] != bss) &&
  790. (hostapd_mac_comp(conf->bss[i].bssid,
  791. bss->bssid) == 0)) {
  792. printf("Duplicate BSSID " MACSTR
  793. " on interface '%s' and '%s'.\n",
  794. MAC2STR(bss->bssid),
  795. conf->bss[i].iface, bss->iface);
  796. return -1;
  797. }
  798. }
  799. }
  800. #ifdef CONFIG_IEEE80211R
  801. if ((bss->wpa_key_mgmt &
  802. (WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X)) &&
  803. (bss->nas_identifier == NULL ||
  804. os_strlen(bss->nas_identifier) < 1 ||
  805. os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
  806. printf("FT (IEEE 802.11r) requires nas_identifier to be "
  807. "configured as a 1..48 octet string\n");
  808. return -1;
  809. }
  810. #endif /* CONFIG_IEEE80211R */
  811. return 0;
  812. }
  813. static int hostapd_config_check(struct hostapd_config *conf)
  814. {
  815. size_t i;
  816. for (i = 0; i < conf->num_bss; i++) {
  817. if (hostapd_config_check_bss(&conf->bss[i], conf))
  818. return -1;
  819. }
  820. return 0;
  821. }
  822. static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
  823. char *val)
  824. {
  825. size_t len = os_strlen(val);
  826. if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
  827. return -1;
  828. if (val[0] == '"') {
  829. if (len < 2 || val[len - 1] != '"')
  830. return -1;
  831. len -= 2;
  832. wep->key[keyidx] = os_malloc(len);
  833. if (wep->key[keyidx] == NULL)
  834. return -1;
  835. os_memcpy(wep->key[keyidx], val + 1, len);
  836. wep->len[keyidx] = len;
  837. } else {
  838. if (len & 1)
  839. return -1;
  840. len /= 2;
  841. wep->key[keyidx] = os_malloc(len);
  842. if (wep->key[keyidx] == NULL)
  843. return -1;
  844. wep->len[keyidx] = len;
  845. if (hexstr2bin(val, wep->key[keyidx], len) < 0)
  846. return -1;
  847. }
  848. wep->keys_set++;
  849. return 0;
  850. }
  851. static int hostapd_parse_rates(int **rate_list, char *val)
  852. {
  853. int *list;
  854. int count;
  855. char *pos, *end;
  856. os_free(*rate_list);
  857. *rate_list = NULL;
  858. pos = val;
  859. count = 0;
  860. while (*pos != '\0') {
  861. if (*pos == ' ')
  862. count++;
  863. pos++;
  864. }
  865. list = os_malloc(sizeof(int) * (count + 2));
  866. if (list == NULL)
  867. return -1;
  868. pos = val;
  869. count = 0;
  870. while (*pos != '\0') {
  871. end = os_strchr(pos, ' ');
  872. if (end)
  873. *end = '\0';
  874. list[count++] = atoi(pos);
  875. if (!end)
  876. break;
  877. pos = end + 1;
  878. }
  879. list[count] = -1;
  880. *rate_list = list;
  881. return 0;
  882. }
  883. static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
  884. {
  885. struct hostapd_bss_config *bss;
  886. if (*ifname == '\0')
  887. return -1;
  888. bss = os_realloc(conf->bss, (conf->num_bss + 1) *
  889. sizeof(struct hostapd_bss_config));
  890. if (bss == NULL) {
  891. printf("Failed to allocate memory for multi-BSS entry\n");
  892. return -1;
  893. }
  894. conf->bss = bss;
  895. bss = &(conf->bss[conf->num_bss]);
  896. os_memset(bss, 0, sizeof(*bss));
  897. bss->radius = os_zalloc(sizeof(*bss->radius));
  898. if (bss->radius == NULL) {
  899. printf("Failed to allocate memory for multi-BSS RADIUS "
  900. "data\n");
  901. return -1;
  902. }
  903. conf->num_bss++;
  904. conf->last_bss = bss;
  905. hostapd_config_defaults_bss(bss);
  906. os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
  907. os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
  908. return 0;
  909. }
  910. static int valid_cw(int cw)
  911. {
  912. return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
  913. cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
  914. }
  915. enum {
  916. IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
  917. IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
  918. IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
  919. IEEE80211_TX_QUEUE_DATA3 = 3, /* used for EDCA AC_BK data */
  920. IEEE80211_TX_QUEUE_DATA4 = 4,
  921. IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
  922. IEEE80211_TX_QUEUE_BEACON = 7
  923. };
  924. static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
  925. char *val)
  926. {
  927. int num;
  928. char *pos;
  929. struct hostapd_tx_queue_params *queue;
  930. /* skip 'tx_queue_' prefix */
  931. pos = name + 9;
  932. if (os_strncmp(pos, "data", 4) == 0 &&
  933. pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
  934. num = pos[4] - '0';
  935. pos += 6;
  936. } else if (os_strncmp(pos, "after_beacon_", 13) == 0) {
  937. num = IEEE80211_TX_QUEUE_AFTER_BEACON;
  938. pos += 13;
  939. } else if (os_strncmp(pos, "beacon_", 7) == 0) {
  940. num = IEEE80211_TX_QUEUE_BEACON;
  941. pos += 7;
  942. } else {
  943. printf("Unknown tx_queue name '%s'\n", pos);
  944. return -1;
  945. }
  946. queue = &conf->tx_queue[num];
  947. if (os_strcmp(pos, "aifs") == 0) {
  948. queue->aifs = atoi(val);
  949. if (queue->aifs < 0 || queue->aifs > 255) {
  950. printf("Invalid AIFS value %d\n", queue->aifs);
  951. return -1;
  952. }
  953. } else if (os_strcmp(pos, "cwmin") == 0) {
  954. queue->cwmin = atoi(val);
  955. if (!valid_cw(queue->cwmin)) {
  956. printf("Invalid cwMin value %d\n", queue->cwmin);
  957. return -1;
  958. }
  959. } else if (os_strcmp(pos, "cwmax") == 0) {
  960. queue->cwmax = atoi(val);
  961. if (!valid_cw(queue->cwmax)) {
  962. printf("Invalid cwMax value %d\n", queue->cwmax);
  963. return -1;
  964. }
  965. } else if (os_strcmp(pos, "burst") == 0) {
  966. queue->burst = hostapd_config_read_int10(val);
  967. } else {
  968. printf("Unknown tx_queue field '%s'\n", pos);
  969. return -1;
  970. }
  971. queue->configured = 1;
  972. return 0;
  973. }
  974. static int hostapd_config_wme_ac(struct hostapd_config *conf, char *name,
  975. char *val)
  976. {
  977. int num, v;
  978. char *pos;
  979. struct hostapd_wme_ac_params *ac;
  980. /* skip 'wme_ac_' prefix */
  981. pos = name + 7;
  982. if (os_strncmp(pos, "be_", 3) == 0) {
  983. num = 0;
  984. pos += 3;
  985. } else if (os_strncmp(pos, "bk_", 3) == 0) {
  986. num = 1;
  987. pos += 3;
  988. } else if (os_strncmp(pos, "vi_", 3) == 0) {
  989. num = 2;
  990. pos += 3;
  991. } else if (os_strncmp(pos, "vo_", 3) == 0) {
  992. num = 3;
  993. pos += 3;
  994. } else {
  995. printf("Unknown wme name '%s'\n", pos);
  996. return -1;
  997. }
  998. ac = &conf->wme_ac_params[num];
  999. if (os_strcmp(pos, "aifs") == 0) {
  1000. v = atoi(val);
  1001. if (v < 1 || v > 255) {
  1002. printf("Invalid AIFS value %d\n", v);
  1003. return -1;
  1004. }
  1005. ac->aifs = v;
  1006. } else if (os_strcmp(pos, "cwmin") == 0) {
  1007. v = atoi(val);
  1008. if (v < 0 || v > 12) {
  1009. printf("Invalid cwMin value %d\n", v);
  1010. return -1;
  1011. }
  1012. ac->cwmin = v;
  1013. } else if (os_strcmp(pos, "cwmax") == 0) {
  1014. v = atoi(val);
  1015. if (v < 0 || v > 12) {
  1016. printf("Invalid cwMax value %d\n", v);
  1017. return -1;
  1018. }
  1019. ac->cwmax = v;
  1020. } else if (os_strcmp(pos, "txop_limit") == 0) {
  1021. v = atoi(val);
  1022. if (v < 0 || v > 0xffff) {
  1023. printf("Invalid txop value %d\n", v);
  1024. return -1;
  1025. }
  1026. ac->txopLimit = v;
  1027. } else if (os_strcmp(pos, "acm") == 0) {
  1028. v = atoi(val);
  1029. if (v < 0 || v > 1) {
  1030. printf("Invalid acm value %d\n", v);
  1031. return -1;
  1032. }
  1033. ac->admission_control_mandatory = v;
  1034. } else {
  1035. printf("Unknown wme_ac_ field '%s'\n", pos);
  1036. return -1;
  1037. }
  1038. return 0;
  1039. }
  1040. #ifdef CONFIG_IEEE80211R
  1041. static int add_r0kh(struct hostapd_bss_config *bss, char *value)
  1042. {
  1043. struct ft_remote_r0kh *r0kh;
  1044. char *pos, *next;
  1045. r0kh = os_zalloc(sizeof(*r0kh));
  1046. if (r0kh == NULL)
  1047. return -1;
  1048. /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
  1049. pos = value;
  1050. next = os_strchr(pos, ' ');
  1051. if (next)
  1052. *next++ = '\0';
  1053. if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
  1054. printf("Invalid R0KH MAC address: '%s'\n", pos);
  1055. os_free(r0kh);
  1056. return -1;
  1057. }
  1058. pos = next;
  1059. next = os_strchr(pos, ' ');
  1060. if (next)
  1061. *next++ = '\0';
  1062. if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
  1063. printf("Invalid R0KH-ID: '%s'\n", pos);
  1064. os_free(r0kh);
  1065. return -1;
  1066. }
  1067. r0kh->id_len = next - pos - 1;
  1068. os_memcpy(r0kh->id, pos, r0kh->id_len);
  1069. pos = next;
  1070. if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
  1071. printf("Invalid R0KH key: '%s'\n", pos);
  1072. os_free(r0kh);
  1073. return -1;
  1074. }
  1075. r0kh->next = bss->r0kh_list;
  1076. bss->r0kh_list = r0kh;
  1077. return 0;
  1078. }
  1079. static int add_r1kh(struct hostapd_bss_config *bss, char *value)
  1080. {
  1081. struct ft_remote_r1kh *r1kh;
  1082. char *pos, *next;
  1083. r1kh = os_zalloc(sizeof(*r1kh));
  1084. if (r1kh == NULL)
  1085. return -1;
  1086. /* 02:01:02:03:04:05 02:01:02:03:04:05
  1087. * 000102030405060708090a0b0c0d0e0f */
  1088. pos = value;
  1089. next = os_strchr(pos, ' ');
  1090. if (next)
  1091. *next++ = '\0';
  1092. if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
  1093. printf("Invalid R1KH MAC address: '%s'\n", pos);
  1094. os_free(r1kh);
  1095. return -1;
  1096. }
  1097. pos = next;
  1098. next = os_strchr(pos, ' ');
  1099. if (next)
  1100. *next++ = '\0';
  1101. if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
  1102. printf("Invalid R1KH-ID: '%s'\n", pos);
  1103. os_free(r1kh);
  1104. return -1;
  1105. }
  1106. pos = next;
  1107. if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
  1108. printf("Invalid R1KH key: '%s'\n", pos);
  1109. os_free(r1kh);
  1110. return -1;
  1111. }
  1112. r1kh->next = bss->r1kh_list;
  1113. bss->r1kh_list = r1kh;
  1114. return 0;
  1115. }
  1116. #endif /* CONFIG_IEEE80211R */
  1117. struct hostapd_config * hostapd_config_read(const char *fname)
  1118. {
  1119. struct hostapd_config *conf;
  1120. struct hostapd_bss_config *bss;
  1121. FILE *f;
  1122. char buf[256], *pos;
  1123. int line = 0;
  1124. int errors = 0;
  1125. int pairwise;
  1126. size_t i;
  1127. f = fopen(fname, "r");
  1128. if (f == NULL) {
  1129. printf("Could not open configuration file '%s' for reading.\n",
  1130. fname);
  1131. return NULL;
  1132. }
  1133. conf = hostapd_config_defaults();
  1134. if (conf == NULL) {
  1135. fclose(f);
  1136. return NULL;
  1137. }
  1138. bss = conf->last_bss = conf->bss;
  1139. while (fgets(buf, sizeof(buf), f)) {
  1140. bss = conf->last_bss;
  1141. line++;
  1142. if (buf[0] == '#')
  1143. continue;
  1144. pos = buf;
  1145. while (*pos != '\0') {
  1146. if (*pos == '\n') {
  1147. *pos = '\0';
  1148. break;
  1149. }
  1150. pos++;
  1151. }
  1152. if (buf[0] == '\0')
  1153. continue;
  1154. pos = os_strchr(buf, '=');
  1155. if (pos == NULL) {
  1156. printf("Line %d: invalid line '%s'\n", line, buf);
  1157. errors++;
  1158. continue;
  1159. }
  1160. *pos = '\0';
  1161. pos++;
  1162. if (os_strcmp(buf, "interface") == 0) {
  1163. os_strlcpy(conf->bss[0].iface, pos,
  1164. sizeof(conf->bss[0].iface));
  1165. } else if (os_strcmp(buf, "bridge") == 0) {
  1166. os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
  1167. } else if (os_strcmp(buf, "driver") == 0) {
  1168. int i;
  1169. /* clear to get error below if setting is invalid */
  1170. conf->driver = NULL;
  1171. for (i = 0; hostapd_drivers[i]; i++) {
  1172. if (os_strcmp(pos, hostapd_drivers[i]->name) ==
  1173. 0) {
  1174. conf->driver = hostapd_drivers[i];
  1175. break;
  1176. }
  1177. }
  1178. if (conf->driver == NULL) {
  1179. printf("Line %d: invalid/unknown driver "
  1180. "'%s'\n", line, pos);
  1181. errors++;
  1182. }
  1183. } else if (os_strcmp(buf, "debug") == 0) {
  1184. wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
  1185. "configuration variable is not used "
  1186. "anymore", line);
  1187. } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
  1188. bss->logger_syslog_level = atoi(pos);
  1189. } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
  1190. bss->logger_stdout_level = atoi(pos);
  1191. } else if (os_strcmp(buf, "logger_syslog") == 0) {
  1192. bss->logger_syslog = atoi(pos);
  1193. } else if (os_strcmp(buf, "logger_stdout") == 0) {
  1194. bss->logger_stdout = atoi(pos);
  1195. } else if (os_strcmp(buf, "dump_file") == 0) {
  1196. bss->dump_log_name = os_strdup(pos);
  1197. } else if (os_strcmp(buf, "ssid") == 0) {
  1198. bss->ssid.ssid_len = os_strlen(pos);
  1199. if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
  1200. bss->ssid.ssid_len < 1) {
  1201. printf("Line %d: invalid SSID '%s'\n", line,
  1202. pos);
  1203. errors++;
  1204. } else {
  1205. os_memcpy(bss->ssid.ssid, pos,
  1206. bss->ssid.ssid_len);
  1207. bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
  1208. bss->ssid.ssid_set = 1;
  1209. }
  1210. } else if (os_strcmp(buf, "macaddr_acl") == 0) {
  1211. bss->macaddr_acl = atoi(pos);
  1212. if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
  1213. bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
  1214. bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
  1215. printf("Line %d: unknown macaddr_acl %d\n",
  1216. line, bss->macaddr_acl);
  1217. }
  1218. } else if (os_strcmp(buf, "accept_mac_file") == 0) {
  1219. if (hostapd_config_read_maclist(pos, &bss->accept_mac,
  1220. &bss->num_accept_mac))
  1221. {
  1222. printf("Line %d: Failed to read "
  1223. "accept_mac_file '%s'\n",
  1224. line, pos);
  1225. errors++;
  1226. }
  1227. } else if (os_strcmp(buf, "deny_mac_file") == 0) {
  1228. if (hostapd_config_read_maclist(pos, &bss->deny_mac,
  1229. &bss->num_deny_mac))
  1230. {
  1231. printf("Line %d: Failed to read "
  1232. "deny_mac_file '%s'\n",
  1233. line, pos);
  1234. errors++;
  1235. }
  1236. } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
  1237. bss->ap_max_inactivity = atoi(pos);
  1238. } else if (os_strcmp(buf, "country_code") == 0) {
  1239. os_memcpy(conf->country, pos, 2);
  1240. /* FIX: make this configurable */
  1241. conf->country[2] = ' ';
  1242. } else if (os_strcmp(buf, "ieee80211d") == 0) {
  1243. conf->ieee80211d = atoi(pos);
  1244. } else if (os_strcmp(buf, "ieee8021x") == 0) {
  1245. bss->ieee802_1x = atoi(pos);
  1246. } else if (os_strcmp(buf, "eapol_version") == 0) {
  1247. bss->eapol_version = atoi(pos);
  1248. if (bss->eapol_version < 1 ||
  1249. bss->eapol_version > 2) {
  1250. printf("Line %d: invalid EAPOL "
  1251. "version (%d): '%s'.\n",
  1252. line, bss->eapol_version, pos);
  1253. errors++;
  1254. } else
  1255. wpa_printf(MSG_DEBUG, "eapol_version=%d",
  1256. bss->eapol_version);
  1257. #ifdef EAP_SERVER
  1258. } else if (os_strcmp(buf, "eap_authenticator") == 0) {
  1259. bss->eap_server = atoi(pos);
  1260. printf("Line %d: obsolete eap_authenticator used; "
  1261. "this has been renamed to eap_server\n", line);
  1262. } else if (os_strcmp(buf, "eap_server") == 0) {
  1263. bss->eap_server = atoi(pos);
  1264. } else if (os_strcmp(buf, "eap_user_file") == 0) {
  1265. if (hostapd_config_read_eap_user(pos, bss))
  1266. errors++;
  1267. } else if (os_strcmp(buf, "ca_cert") == 0) {
  1268. os_free(bss->ca_cert);
  1269. bss->ca_cert = os_strdup(pos);
  1270. } else if (os_strcmp(buf, "server_cert") == 0) {
  1271. os_free(bss->server_cert);
  1272. bss->server_cert = os_strdup(pos);
  1273. } else if (os_strcmp(buf, "private_key") == 0) {
  1274. os_free(bss->private_key);
  1275. bss->private_key = os_strdup(pos);
  1276. } else if (os_strcmp(buf, "private_key_passwd") == 0) {
  1277. os_free(bss->private_key_passwd);
  1278. bss->private_key_passwd = os_strdup(pos);
  1279. } else if (os_strcmp(buf, "check_crl") == 0) {
  1280. bss->check_crl = atoi(pos);
  1281. } else if (os_strcmp(buf, "dh_file") == 0) {
  1282. os_free(bss->dh_file);
  1283. bss->dh_file = os_strdup(pos);
  1284. #ifdef EAP_FAST
  1285. } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
  1286. os_free(bss->pac_opaque_encr_key);
  1287. bss->pac_opaque_encr_key = os_malloc(16);
  1288. if (bss->pac_opaque_encr_key == NULL) {
  1289. printf("Line %d: No memory for "
  1290. "pac_opque_encr_key\n", line);
  1291. errors++;
  1292. } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
  1293. 16)) {
  1294. printf("Line %d: Invalid pac_opque_encr_key\n",
  1295. line);
  1296. errors++;
  1297. }
  1298. } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
  1299. size_t idlen = os_strlen(pos);
  1300. if (idlen & 1) {
  1301. printf("Line %d: Invalid eap_fast_a_id\n",
  1302. line);
  1303. errors++;
  1304. } else {
  1305. os_free(bss->eap_fast_a_id);
  1306. bss->eap_fast_a_id = os_malloc(idlen / 2);
  1307. if (bss->eap_fast_a_id == NULL ||
  1308. hexstr2bin(pos, bss->eap_fast_a_id,
  1309. idlen / 2)) {
  1310. printf("Line %d: Failed to parse "
  1311. "eap_fast_a_id\n", line);
  1312. errors++;
  1313. } else
  1314. bss->eap_fast_a_id_len = idlen / 2;
  1315. }
  1316. } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
  1317. os_free(bss->eap_fast_a_id_info);
  1318. bss->eap_fast_a_id_info = os_strdup(pos);
  1319. } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
  1320. bss->eap_fast_prov = atoi(pos);
  1321. } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
  1322. bss->pac_key_lifetime = atoi(pos);
  1323. } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
  1324. bss->pac_key_refresh_time = atoi(pos);
  1325. #endif /* EAP_FAST */
  1326. #ifdef EAP_SIM
  1327. } else if (os_strcmp(buf, "eap_sim_db") == 0) {
  1328. os_free(bss->eap_sim_db);
  1329. bss->eap_sim_db = os_strdup(pos);
  1330. } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
  1331. bss->eap_sim_aka_result_ind = atoi(pos);
  1332. #endif /* EAP_SIM */
  1333. #ifdef EAP_TNC
  1334. } else if (os_strcmp(buf, "tnc") == 0) {
  1335. bss->tnc = atoi(pos);
  1336. #endif /* EAP_TNC */
  1337. #endif /* EAP_SERVER */
  1338. } else if (os_strcmp(buf, "eap_message") == 0) {
  1339. char *term;
  1340. bss->eap_req_id_text = os_strdup(pos);
  1341. if (bss->eap_req_id_text == NULL) {
  1342. printf("Line %d: Failed to allocate memory "
  1343. "for eap_req_id_text\n", line);
  1344. errors++;
  1345. continue;
  1346. }
  1347. bss->eap_req_id_text_len =
  1348. os_strlen(bss->eap_req_id_text);
  1349. term = os_strstr(bss->eap_req_id_text, "\\0");
  1350. if (term) {
  1351. *term++ = '\0';
  1352. os_memmove(term, term + 1,
  1353. bss->eap_req_id_text_len -
  1354. (term - bss->eap_req_id_text) - 1);
  1355. bss->eap_req_id_text_len--;
  1356. }
  1357. } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
  1358. bss->default_wep_key_len = atoi(pos);
  1359. if (bss->default_wep_key_len > 13) {
  1360. printf("Line %d: invalid WEP key len %lu "
  1361. "(= %lu bits)\n", line,
  1362. (unsigned long)
  1363. bss->default_wep_key_len,
  1364. (unsigned long)
  1365. bss->default_wep_key_len * 8);
  1366. errors++;
  1367. }
  1368. } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
  1369. bss->individual_wep_key_len = atoi(pos);
  1370. if (bss->individual_wep_key_len < 0 ||
  1371. bss->individual_wep_key_len > 13) {
  1372. printf("Line %d: invalid WEP key len %d "
  1373. "(= %d bits)\n", line,
  1374. bss->individual_wep_key_len,
  1375. bss->individual_wep_key_len * 8);
  1376. errors++;
  1377. }
  1378. } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
  1379. bss->wep_rekeying_period = atoi(pos);
  1380. if (bss->wep_rekeying_period < 0) {
  1381. printf("Line %d: invalid period %d\n",
  1382. line, bss->wep_rekeying_period);
  1383. errors++;
  1384. }
  1385. } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
  1386. bss->eap_reauth_period = atoi(pos);
  1387. if (bss->eap_reauth_period < 0) {
  1388. printf("Line %d: invalid period %d\n",
  1389. line, bss->eap_reauth_period);
  1390. errors++;
  1391. }
  1392. } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
  1393. bss->eapol_key_index_workaround = atoi(pos);
  1394. #ifdef CONFIG_IAPP
  1395. } else if (os_strcmp(buf, "iapp_interface") == 0) {
  1396. bss->ieee802_11f = 1;
  1397. os_strlcpy(bss->iapp_iface, pos,
  1398. sizeof(bss->iapp_iface));
  1399. #endif /* CONFIG_IAPP */
  1400. } else if (os_strcmp(buf, "own_ip_addr") == 0) {
  1401. if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
  1402. printf("Line %d: invalid IP address '%s'\n",
  1403. line, pos);
  1404. errors++;
  1405. }
  1406. } else if (os_strcmp(buf, "nas_identifier") == 0) {
  1407. bss->nas_identifier = os_strdup(pos);
  1408. } else if (os_strcmp(buf, "auth_server_addr") == 0) {
  1409. if (hostapd_config_read_radius_addr(
  1410. &bss->radius->auth_servers,
  1411. &bss->radius->num_auth_servers, pos, 1812,
  1412. &bss->radius->auth_server)) {
  1413. printf("Line %d: invalid IP address '%s'\n",
  1414. line, pos);
  1415. errors++;
  1416. }
  1417. } else if (bss->radius->auth_server &&
  1418. os_strcmp(buf, "auth_server_port") == 0) {
  1419. bss->radius->auth_server->port = atoi(pos);
  1420. } else if (bss->radius->auth_server &&
  1421. os_strcmp(buf, "auth_server_shared_secret") == 0) {
  1422. int len = os_strlen(pos);
  1423. if (len == 0) {
  1424. /* RFC 2865, Ch. 3 */
  1425. printf("Line %d: empty shared secret is not "
  1426. "allowed.\n", line);
  1427. errors++;
  1428. }
  1429. bss->radius->auth_server->shared_secret =
  1430. (u8 *) os_strdup(pos);
  1431. bss->radius->auth_server->shared_secret_len = len;
  1432. } else if (os_strcmp(buf, "acct_server_addr") == 0) {
  1433. if (hostapd_config_read_radius_addr(
  1434. &bss->radius->acct_servers,
  1435. &bss->radius->num_acct_servers, pos, 1813,
  1436. &bss->radius->acct_server)) {
  1437. printf("Line %d: invalid IP address '%s'\n",
  1438. line, pos);
  1439. errors++;
  1440. }
  1441. } else if (bss->radius->acct_server &&
  1442. os_strcmp(buf, "acct_server_port") == 0) {
  1443. bss->radius->acct_server->port = atoi(pos);
  1444. } else if (bss->radius->acct_server &&
  1445. os_strcmp(buf, "acct_server_shared_secret") == 0) {
  1446. int len = os_strlen(pos);
  1447. if (len == 0) {
  1448. /* RFC 2865, Ch. 3 */
  1449. printf("Line %d: empty shared secret is not "
  1450. "allowed.\n", line);
  1451. errors++;
  1452. }
  1453. bss->radius->acct_server->shared_secret =
  1454. (u8 *) os_strdup(pos);
  1455. bss->radius->acct_server->shared_secret_len = len;
  1456. } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
  1457. 0) {
  1458. bss->radius->retry_primary_interval = atoi(pos);
  1459. } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
  1460. {
  1461. bss->radius->acct_interim_interval = atoi(pos);
  1462. } else if (os_strcmp(buf, "auth_algs") == 0) {
  1463. bss->auth_algs = atoi(pos);
  1464. if (bss->auth_algs == 0) {
  1465. printf("Line %d: no authentication algorithms "
  1466. "allowed\n",
  1467. line);
  1468. errors++;
  1469. }
  1470. } else if (os_strcmp(buf, "max_num_sta") == 0) {
  1471. bss->max_num_sta = atoi(pos);
  1472. if (bss->max_num_sta < 0 ||
  1473. bss->max_num_sta > MAX_STA_COUNT) {
  1474. printf("Line %d: Invalid max_num_sta=%d; "
  1475. "allowed range 0..%d\n", line,
  1476. bss->max_num_sta, MAX_STA_COUNT);
  1477. errors++;
  1478. }
  1479. } else if (os_strcmp(buf, "wpa") == 0) {
  1480. bss->wpa = atoi(pos);
  1481. } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
  1482. bss->wpa_group_rekey = atoi(pos);
  1483. } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
  1484. bss->wpa_strict_rekey = atoi(pos);
  1485. } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
  1486. bss->wpa_gmk_rekey = atoi(pos);
  1487. } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
  1488. bss->wpa_ptk_rekey = atoi(pos);
  1489. } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
  1490. int len = os_strlen(pos);
  1491. if (len < 8 || len > 63) {
  1492. printf("Line %d: invalid WPA passphrase length"
  1493. " %d (expected 8..63)\n", line, len);
  1494. errors++;
  1495. } else {
  1496. os_free(bss->ssid.wpa_passphrase);
  1497. bss->ssid.wpa_passphrase = os_strdup(pos);
  1498. }
  1499. } else if (os_strcmp(buf, "wpa_psk") == 0) {
  1500. os_free(bss->ssid.wpa_psk);
  1501. bss->ssid.wpa_psk =
  1502. os_zalloc(sizeof(struct hostapd_wpa_psk));
  1503. if (bss->ssid.wpa_psk == NULL)
  1504. errors++;
  1505. else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
  1506. PMK_LEN) ||
  1507. pos[PMK_LEN * 2] != '\0') {
  1508. printf("Line %d: Invalid PSK '%s'.\n", line,
  1509. pos);
  1510. errors++;
  1511. } else {
  1512. bss->ssid.wpa_psk->group = 1;
  1513. }
  1514. } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
  1515. os_free(bss->ssid.wpa_psk_file);
  1516. bss->ssid.wpa_psk_file = os_strdup(pos);
  1517. if (!bss->ssid.wpa_psk_file) {
  1518. printf("Line %d: allocation failed\n", line);
  1519. errors++;
  1520. }
  1521. } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
  1522. bss->wpa_key_mgmt =
  1523. hostapd_config_parse_key_mgmt(line, pos);
  1524. if (bss->wpa_key_mgmt == -1)
  1525. errors++;
  1526. } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
  1527. bss->wpa_pairwise =
  1528. hostapd_config_parse_cipher(line, pos);
  1529. if (bss->wpa_pairwise == -1 ||
  1530. bss->wpa_pairwise == 0)
  1531. errors++;
  1532. else if (bss->wpa_pairwise &
  1533. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
  1534. WPA_CIPHER_WEP104)) {
  1535. printf("Line %d: unsupported pairwise "
  1536. "cipher suite '%s'\n",
  1537. bss->wpa_pairwise, pos);
  1538. errors++;
  1539. }
  1540. } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
  1541. bss->rsn_pairwise =
  1542. hostapd_config_parse_cipher(line, pos);
  1543. if (bss->rsn_pairwise == -1 ||
  1544. bss->rsn_pairwise == 0)
  1545. errors++;
  1546. else if (bss->rsn_pairwise &
  1547. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
  1548. WPA_CIPHER_WEP104)) {
  1549. printf("Line %d: unsupported pairwise "
  1550. "cipher suite '%s'\n",
  1551. bss->rsn_pairwise, pos);
  1552. errors++;
  1553. }
  1554. #ifdef CONFIG_RSN_PREAUTH
  1555. } else if (os_strcmp(buf, "rsn_preauth") == 0) {
  1556. bss->rsn_preauth = atoi(pos);
  1557. } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
  1558. bss->rsn_preauth_interfaces = os_strdup(pos);
  1559. #endif /* CONFIG_RSN_PREAUTH */
  1560. #ifdef CONFIG_PEERKEY
  1561. } else if (os_strcmp(buf, "peerkey") == 0) {
  1562. bss->peerkey = atoi(pos);
  1563. #endif /* CONFIG_PEERKEY */
  1564. #ifdef CONFIG_IEEE80211R
  1565. } else if (os_strcmp(buf, "mobility_domain") == 0) {
  1566. if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
  1567. hexstr2bin(pos, bss->mobility_domain,
  1568. MOBILITY_DOMAIN_ID_LEN) != 0) {
  1569. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1570. "mobility_domain '%s'", line, pos);
  1571. errors++;
  1572. continue;
  1573. }
  1574. } else if (os_strcmp(buf, "r1_key_holder") == 0) {
  1575. if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
  1576. hexstr2bin(pos, bss->r1_key_holder,
  1577. FT_R1KH_ID_LEN) != 0) {
  1578. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1579. "r1_key_holder '%s'", line, pos);
  1580. errors++;
  1581. continue;
  1582. }
  1583. } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
  1584. bss->r0_key_lifetime = atoi(pos);
  1585. } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
  1586. bss->reassociation_deadline = atoi(pos);
  1587. } else if (os_strcmp(buf, "r0kh") == 0) {
  1588. if (add_r0kh(bss, pos) < 0) {
  1589. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1590. "r0kh '%s'", line, pos);
  1591. errors++;
  1592. continue;
  1593. }
  1594. } else if (os_strcmp(buf, "r1kh") == 0) {
  1595. if (add_r1kh(bss, pos) < 0) {
  1596. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1597. "r1kh '%s'", line, pos);
  1598. errors++;
  1599. continue;
  1600. }
  1601. } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
  1602. bss->pmk_r1_push = atoi(pos);
  1603. #endif /* CONFIG_IEEE80211R */
  1604. } else if (os_strcmp(buf, "ctrl_interface") == 0) {
  1605. os_free(bss->ctrl_interface);
  1606. bss->ctrl_interface = os_strdup(pos);
  1607. } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
  1608. #ifndef CONFIG_NATIVE_WINDOWS
  1609. struct group *grp;
  1610. char *endp;
  1611. const char *group = pos;
  1612. grp = getgrnam(group);
  1613. if (grp) {
  1614. bss->ctrl_interface_gid = grp->gr_gid;
  1615. bss->ctrl_interface_gid_set = 1;
  1616. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
  1617. " (from group name '%s')",
  1618. bss->ctrl_interface_gid, group);
  1619. continue;
  1620. }
  1621. /* Group name not found - try to parse this as gid */
  1622. bss->ctrl_interface_gid = strtol(group, &endp, 10);
  1623. if (*group == '\0' || *endp != '\0') {
  1624. wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
  1625. "'%s'", line, group);
  1626. errors++;
  1627. continue;
  1628. }
  1629. bss->ctrl_interface_gid_set = 1;
  1630. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
  1631. bss->ctrl_interface_gid);
  1632. #endif /* CONFIG_NATIVE_WINDOWS */
  1633. #ifdef RADIUS_SERVER
  1634. } else if (os_strcmp(buf, "radius_server_clients") == 0) {
  1635. os_free(bss->radius_server_clients);
  1636. bss->radius_server_clients = os_strdup(pos);
  1637. } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
  1638. bss->radius_server_auth_port = atoi(pos);
  1639. } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
  1640. bss->radius_server_ipv6 = atoi(pos);
  1641. #endif /* RADIUS_SERVER */
  1642. } else if (os_strcmp(buf, "test_socket") == 0) {
  1643. os_free(bss->test_socket);
  1644. bss->test_socket = os_strdup(pos);
  1645. } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
  1646. bss->use_pae_group_addr = atoi(pos);
  1647. } else if (os_strcmp(buf, "hw_mode") == 0) {
  1648. if (os_strcmp(pos, "a") == 0)
  1649. conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
  1650. else if (os_strcmp(pos, "b") == 0)
  1651. conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
  1652. else if (os_strcmp(pos, "g") == 0)
  1653. conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
  1654. else {
  1655. printf("Line %d: unknown hw_mode '%s'\n",
  1656. line, pos);
  1657. errors++;
  1658. }
  1659. } else if (os_strcmp(buf, "channel") == 0) {
  1660. conf->channel = atoi(pos);
  1661. } else if (os_strcmp(buf, "beacon_int") == 0) {
  1662. int val = atoi(pos);
  1663. /* MIB defines range as 1..65535, but very small values
  1664. * cause problems with the current implementation.
  1665. * Since it is unlikely that this small numbers are
  1666. * useful in real life scenarios, do not allow beacon
  1667. * period to be set below 15 TU. */
  1668. if (val < 15 || val > 65535) {
  1669. printf("Line %d: invalid beacon_int %d "
  1670. "(expected 15..65535)\n",
  1671. line, val);
  1672. errors++;
  1673. } else
  1674. conf->beacon_int = val;
  1675. } else if (os_strcmp(buf, "dtim_period") == 0) {
  1676. bss->dtim_period = atoi(pos);
  1677. if (bss->dtim_period < 1 || bss->dtim_period > 255) {
  1678. printf("Line %d: invalid dtim_period %d\n",
  1679. line, bss->dtim_period);
  1680. errors++;
  1681. }
  1682. } else if (os_strcmp(buf, "rts_threshold") == 0) {
  1683. conf->rts_threshold = atoi(pos);
  1684. if (conf->rts_threshold < 0 ||
  1685. conf->rts_threshold > 2347) {
  1686. printf("Line %d: invalid rts_threshold %d\n",
  1687. line, conf->rts_threshold);
  1688. errors++;
  1689. }
  1690. } else if (os_strcmp(buf, "fragm_threshold") == 0) {
  1691. conf->fragm_threshold = atoi(pos);
  1692. if (conf->fragm_threshold < 256 ||
  1693. conf->fragm_threshold > 2346) {
  1694. printf("Line %d: invalid fragm_threshold %d\n",
  1695. line, conf->fragm_threshold);
  1696. errors++;
  1697. }
  1698. } else if (os_strcmp(buf, "send_probe_response") == 0) {
  1699. int val = atoi(pos);
  1700. if (val != 0 && val != 1) {
  1701. printf("Line %d: invalid send_probe_response "
  1702. "%d (expected 0 or 1)\n", line, val);
  1703. } else
  1704. conf->send_probe_response = val;
  1705. } else if (os_strcmp(buf, "supported_rates") == 0) {
  1706. if (hostapd_parse_rates(&conf->supported_rates, pos)) {
  1707. printf("Line %d: invalid rate list\n", line);
  1708. errors++;
  1709. }
  1710. } else if (os_strcmp(buf, "basic_rates") == 0) {
  1711. if (hostapd_parse_rates(&conf->basic_rates, pos)) {
  1712. printf("Line %d: invalid rate list\n", line);
  1713. errors++;
  1714. }
  1715. } else if (os_strcmp(buf, "preamble") == 0) {
  1716. if (atoi(pos))
  1717. conf->preamble = SHORT_PREAMBLE;
  1718. else
  1719. conf->preamble = LONG_PREAMBLE;
  1720. } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
  1721. bss->ignore_broadcast_ssid = atoi(pos);
  1722. } else if (os_strcmp(buf, "bridge_packets") == 0) {
  1723. conf->bridge_packets = atoi(pos);
  1724. } else if (os_strcmp(buf, "wep_default_key") == 0) {
  1725. bss->ssid.wep.idx = atoi(pos);
  1726. if (bss->ssid.wep.idx > 3) {
  1727. printf("Invalid wep_default_key index %d\n",
  1728. bss->ssid.wep.idx);
  1729. errors++;
  1730. }
  1731. } else if (os_strcmp(buf, "wep_key0") == 0 ||
  1732. os_strcmp(buf, "wep_key1") == 0 ||
  1733. os_strcmp(buf, "wep_key2") == 0 ||
  1734. os_strcmp(buf, "wep_key3") == 0) {
  1735. if (hostapd_config_read_wep(&bss->ssid.wep,
  1736. buf[7] - '0', pos)) {
  1737. printf("Line %d: invalid WEP key '%s'\n",
  1738. line, buf);
  1739. errors++;
  1740. }
  1741. } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
  1742. bss->ssid.dynamic_vlan = atoi(pos);
  1743. } else if (os_strcmp(buf, "vlan_file") == 0) {
  1744. if (hostapd_config_read_vlan_file(bss, pos)) {
  1745. printf("Line %d: failed to read VLAN file "
  1746. "'%s'\n", line, pos);
  1747. errors++;
  1748. }
  1749. #ifdef CONFIG_FULL_DYNAMIC_VLAN
  1750. } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
  1751. bss->ssid.vlan_tagged_interface = os_strdup(pos);
  1752. #endif /* CONFIG_FULL_DYNAMIC_VLAN */
  1753. } else if (os_strcmp(buf, "passive_scan_interval") == 0) {
  1754. conf->passive_scan_interval = atoi(pos);
  1755. } else if (os_strcmp(buf, "passive_scan_listen") == 0) {
  1756. conf->passive_scan_listen = atoi(pos);
  1757. } else if (os_strcmp(buf, "passive_scan_mode") == 0) {
  1758. conf->passive_scan_mode = atoi(pos);
  1759. } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
  1760. conf->ap_table_max_size = atoi(pos);
  1761. } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
  1762. conf->ap_table_expiration_time = atoi(pos);
  1763. } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
  1764. if (hostapd_config_tx_queue(conf, buf, pos)) {
  1765. printf("Line %d: invalid TX queue item\n",
  1766. line);
  1767. errors++;
  1768. }
  1769. } else if (os_strcmp(buf, "wme_enabled") == 0) {
  1770. bss->wme_enabled = atoi(pos);
  1771. } else if (os_strncmp(buf, "wme_ac_", 7) == 0) {
  1772. if (hostapd_config_wme_ac(conf, buf, pos)) {
  1773. printf("Line %d: invalid wme ac item\n",
  1774. line);
  1775. errors++;
  1776. }
  1777. } else if (os_strcmp(buf, "bss") == 0) {
  1778. if (hostapd_config_bss(conf, pos)) {
  1779. printf("Line %d: invalid bss item\n", line);
  1780. errors++;
  1781. }
  1782. } else if (os_strcmp(buf, "bssid") == 0) {
  1783. if (bss == conf->bss &&
  1784. (!conf->driver || !conf->driver->init_bssid)) {
  1785. printf("Line %d: bssid item not allowed "
  1786. "for the default interface and this "
  1787. "driver\n", line);
  1788. errors++;
  1789. } else if (hwaddr_aton(pos, bss->bssid)) {
  1790. printf("Line %d: invalid bssid item\n", line);
  1791. errors++;
  1792. }
  1793. #ifdef CONFIG_IEEE80211W
  1794. } else if (os_strcmp(buf, "ieee80211w") == 0) {
  1795. bss->ieee80211w = atoi(pos);
  1796. } else if (os_strcmp(buf, "assoc_ping_timeout") == 0) {
  1797. bss->assoc_ping_timeout = atoi(pos);
  1798. if (bss->assoc_ping_timeout == 0) {
  1799. printf("Line %d: invalid assoc_ping_timeout\n",
  1800. line);
  1801. errors++;
  1802. }
  1803. } else if (os_strcmp(buf, "assoc_ping_attempts") == 0) {
  1804. bss->assoc_ping_timeout = atoi(pos);
  1805. if (bss->assoc_ping_timeout == 0) {
  1806. printf("Line %d: invalid assoc_ping_attempts "
  1807. "(valid range: 1..255)\n",
  1808. line);
  1809. errors++;
  1810. }
  1811. #endif /* CONFIG_IEEE80211W */
  1812. #ifdef CONFIG_IEEE80211N
  1813. } else if (os_strcmp(buf, "ieee80211n") == 0) {
  1814. conf->ieee80211n = atoi(pos);
  1815. #endif /* CONFIG_IEEE80211N */
  1816. } else if (os_strcmp(buf, "max_listen_interval") == 0) {
  1817. bss->max_listen_interval = atoi(pos);
  1818. } else if (os_strcmp(buf, "okc") == 0) {
  1819. bss->okc = atoi(pos);
  1820. #ifdef CONFIG_WPS
  1821. } else if (os_strcmp(buf, "wps_state") == 0) {
  1822. bss->wps_state = atoi(pos);
  1823. if (bss->wps_state < 0 || bss->wps_state > 2) {
  1824. printf("Line %d: invalid wps_state\n", line);
  1825. errors++;
  1826. }
  1827. } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
  1828. bss->ap_setup_locked = atoi(pos);
  1829. } else if (os_strcmp(buf, "uuid") == 0) {
  1830. if (uuid_str2bin(pos, bss->uuid)) {
  1831. printf("Line %d: invalid UUID\n", line);
  1832. errors++;
  1833. }
  1834. } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
  1835. bss->wps_pin_requests = os_strdup(pos);
  1836. } else if (os_strcmp(buf, "device_name") == 0) {
  1837. bss->device_name = os_strdup(pos);
  1838. } else if (os_strcmp(buf, "manufacturer") == 0) {
  1839. bss->manufacturer = os_strdup(pos);
  1840. } else if (os_strcmp(buf, "model_name") == 0) {
  1841. bss->model_name = os_strdup(pos);
  1842. } else if (os_strcmp(buf, "model_number") == 0) {
  1843. bss->model_number = os_strdup(pos);
  1844. } else if (os_strcmp(buf, "serial_number") == 0) {
  1845. bss->serial_number = os_strdup(pos);
  1846. } else if (os_strcmp(buf, "device_type") == 0) {
  1847. bss->device_type = os_strdup(pos);
  1848. } else if (os_strcmp(buf, "config_methods") == 0) {
  1849. bss->config_methods = os_strdup(pos);
  1850. } else if (os_strcmp(buf, "os_version") == 0) {
  1851. if (hexstr2bin(pos, bss->os_version, 4)) {
  1852. printf("Line %d: invalid os_version\n", line);
  1853. errors++;
  1854. }
  1855. } else if (os_strcmp(buf, "ap_pin") == 0) {
  1856. bss->ap_pin = os_strdup(pos);
  1857. #endif /* CONFIG_WPS */
  1858. } else {
  1859. printf("Line %d: unknown configuration item '%s'\n",
  1860. line, buf);
  1861. errors++;
  1862. }
  1863. }
  1864. fclose(f);
  1865. if (bss->individual_wep_key_len == 0) {
  1866. /* individual keys are not use; can use key idx0 for broadcast
  1867. * keys */
  1868. bss->broadcast_key_idx_min = 0;
  1869. }
  1870. /* Select group cipher based on the enabled pairwise cipher suites */
  1871. pairwise = 0;
  1872. if (bss->wpa & 1)
  1873. pairwise |= bss->wpa_pairwise;
  1874. if (bss->wpa & 2) {
  1875. if (bss->rsn_pairwise == 0)
  1876. bss->rsn_pairwise = bss->wpa_pairwise;
  1877. pairwise |= bss->rsn_pairwise;
  1878. }
  1879. if (pairwise & WPA_CIPHER_TKIP)
  1880. bss->wpa_group = WPA_CIPHER_TKIP;
  1881. else
  1882. bss->wpa_group = WPA_CIPHER_CCMP;
  1883. for (i = 0; i < conf->num_bss; i++) {
  1884. bss = &conf->bss[i];
  1885. bss->radius->auth_server = bss->radius->auth_servers;
  1886. bss->radius->acct_server = bss->radius->acct_servers;
  1887. if (bss->wpa && bss->ieee802_1x) {
  1888. bss->ssid.security_policy = SECURITY_WPA;
  1889. } else if (bss->wpa) {
  1890. bss->ssid.security_policy = SECURITY_WPA_PSK;
  1891. } else if (bss->ieee802_1x) {
  1892. bss->ssid.security_policy = SECURITY_IEEE_802_1X;
  1893. bss->ssid.wep.default_len = bss->default_wep_key_len;
  1894. } else if (bss->ssid.wep.keys_set)
  1895. bss->ssid.security_policy = SECURITY_STATIC_WEP;
  1896. else
  1897. bss->ssid.security_policy = SECURITY_PLAINTEXT;
  1898. }
  1899. if (hostapd_config_check(conf))
  1900. errors++;
  1901. if (errors) {
  1902. printf("%d errors found in configuration file '%s'\n",
  1903. errors, fname);
  1904. hostapd_config_free(conf);
  1905. conf = NULL;
  1906. }
  1907. return conf;
  1908. }
  1909. int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b)
  1910. {
  1911. int i;
  1912. if (a->idx != b->idx || a->default_len != b->default_len)
  1913. return 1;
  1914. for (i = 0; i < NUM_WEP_KEYS; i++)
  1915. if (a->len[i] != b->len[i] ||
  1916. os_memcmp(a->key[i], b->key[i], a->len[i]) != 0)
  1917. return 1;
  1918. return 0;
  1919. }
  1920. static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
  1921. int num_servers)
  1922. {
  1923. int i;
  1924. for (i = 0; i < num_servers; i++) {
  1925. os_free(servers[i].shared_secret);
  1926. }
  1927. os_free(servers);
  1928. }
  1929. static void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
  1930. {
  1931. os_free(user->identity);
  1932. os_free(user->password);
  1933. os_free(user);
  1934. }
  1935. static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
  1936. {
  1937. int i;
  1938. for (i = 0; i < NUM_WEP_KEYS; i++) {
  1939. os_free(keys->key[i]);
  1940. keys->key[i] = NULL;
  1941. }
  1942. }
  1943. static void hostapd_config_free_bss(struct hostapd_bss_config *conf)
  1944. {
  1945. struct hostapd_wpa_psk *psk, *prev;
  1946. struct hostapd_eap_user *user, *prev_user;
  1947. if (conf == NULL)
  1948. return;
  1949. psk = conf->ssid.wpa_psk;
  1950. while (psk) {
  1951. prev = psk;
  1952. psk = psk->next;
  1953. os_free(prev);
  1954. }
  1955. os_free(conf->ssid.wpa_passphrase);
  1956. os_free(conf->ssid.wpa_psk_file);
  1957. #ifdef CONFIG_FULL_DYNAMIC_VLAN
  1958. os_free(conf->ssid.vlan_tagged_interface);
  1959. #endif /* CONFIG_FULL_DYNAMIC_VLAN */
  1960. user = conf->eap_user;
  1961. while (user) {
  1962. prev_user = user;
  1963. user = user->next;
  1964. hostapd_config_free_eap_user(prev_user);
  1965. }
  1966. os_free(conf->dump_log_name);
  1967. os_free(conf->eap_req_id_text);
  1968. os_free(conf->accept_mac);
  1969. os_free(conf->deny_mac);
  1970. os_free(conf->nas_identifier);
  1971. hostapd_config_free_radius(conf->radius->auth_servers,
  1972. conf->radius->num_auth_servers);
  1973. hostapd_config_free_radius(conf->radius->acct_servers,
  1974. conf->radius->num_acct_servers);
  1975. os_free(conf->rsn_preauth_interfaces);
  1976. os_free(conf->ctrl_interface);
  1977. os_free(conf->ca_cert);
  1978. os_free(conf->server_cert);
  1979. os_free(conf->private_key);
  1980. os_free(conf->private_key_passwd);
  1981. os_free(conf->dh_file);
  1982. os_free(conf->pac_opaque_encr_key);
  1983. os_free(conf->eap_fast_a_id);
  1984. os_free(conf->eap_fast_a_id_info);
  1985. os_free(conf->eap_sim_db);
  1986. os_free(conf->radius_server_clients);
  1987. os_free(conf->test_socket);
  1988. os_free(conf->radius);
  1989. hostapd_config_free_vlan(conf);
  1990. if (conf->ssid.dyn_vlan_keys) {
  1991. struct hostapd_ssid *ssid = &conf->ssid;
  1992. size_t i;
  1993. for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
  1994. if (ssid->dyn_vlan_keys[i] == NULL)
  1995. continue;
  1996. hostapd_config_free_wep(ssid->dyn_vlan_keys[i]);
  1997. os_free(ssid->dyn_vlan_keys[i]);
  1998. }
  1999. os_free(ssid->dyn_vlan_keys);
  2000. ssid->dyn_vlan_keys = NULL;
  2001. }
  2002. #ifdef CONFIG_IEEE80211R
  2003. {
  2004. struct ft_remote_r0kh *r0kh, *r0kh_prev;
  2005. struct ft_remote_r1kh *r1kh, *r1kh_prev;
  2006. r0kh = conf->r0kh_list;
  2007. conf->r0kh_list = NULL;
  2008. while (r0kh) {
  2009. r0kh_prev = r0kh;
  2010. r0kh = r0kh->next;
  2011. os_free(r0kh_prev);
  2012. }
  2013. r1kh = conf->r1kh_list;
  2014. conf->r1kh_list = NULL;
  2015. while (r1kh) {
  2016. r1kh_prev = r1kh;
  2017. r1kh = r1kh->next;
  2018. os_free(r1kh_prev);
  2019. }
  2020. }
  2021. #endif /* CONFIG_IEEE80211R */
  2022. #ifdef CONFIG_WPS
  2023. os_free(conf->wps_pin_requests);
  2024. os_free(conf->device_name);
  2025. os_free(conf->manufacturer);
  2026. os_free(conf->model_name);
  2027. os_free(conf->model_number);
  2028. os_free(conf->serial_number);
  2029. os_free(conf->device_type);
  2030. os_free(conf->config_methods);
  2031. os_free(conf->ap_pin);
  2032. #endif /* CONFIG_WPS */
  2033. }
  2034. void hostapd_config_free(struct hostapd_config *conf)
  2035. {
  2036. size_t i;
  2037. if (conf == NULL)
  2038. return;
  2039. for (i = 0; i < conf->num_bss; i++)
  2040. hostapd_config_free_bss(&conf->bss[i]);
  2041. os_free(conf->bss);
  2042. os_free(conf);
  2043. }
  2044. /* Perform a binary search for given MAC address from a pre-sorted list.
  2045. * Returns 1 if address is in the list or 0 if not. */
  2046. int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
  2047. const u8 *addr, int *vlan_id)
  2048. {
  2049. int start, end, middle, res;
  2050. start = 0;
  2051. end = num_entries - 1;
  2052. while (start <= end) {
  2053. middle = (start + end) / 2;
  2054. res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
  2055. if (res == 0) {
  2056. if (vlan_id)
  2057. *vlan_id = list[middle].vlan_id;
  2058. return 1;
  2059. }
  2060. if (res < 0)
  2061. start = middle + 1;
  2062. else
  2063. end = middle - 1;
  2064. }
  2065. return 0;
  2066. }
  2067. int hostapd_rate_found(int *list, int rate)
  2068. {
  2069. int i;
  2070. if (list == NULL)
  2071. return 0;
  2072. for (i = 0; list[i] >= 0; i++)
  2073. if (list[i] == rate)
  2074. return 1;
  2075. return 0;
  2076. }
  2077. const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
  2078. {
  2079. struct hostapd_vlan *v = vlan;
  2080. while (v) {
  2081. if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
  2082. return v->ifname;
  2083. v = v->next;
  2084. }
  2085. return NULL;
  2086. }
  2087. const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
  2088. const u8 *addr, const u8 *prev_psk)
  2089. {
  2090. struct hostapd_wpa_psk *psk;
  2091. int next_ok = prev_psk == NULL;
  2092. for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
  2093. if (next_ok &&
  2094. (psk->group || os_memcmp(psk->addr, addr, ETH_ALEN) == 0))
  2095. return psk->psk;
  2096. if (psk->psk == prev_psk)
  2097. next_ok = 1;
  2098. }
  2099. return NULL;
  2100. }
  2101. const struct hostapd_eap_user *
  2102. hostapd_get_eap_user(const struct hostapd_bss_config *conf, const u8 *identity,
  2103. size_t identity_len, int phase2)
  2104. {
  2105. struct hostapd_eap_user *user = conf->eap_user;
  2106. #ifdef CONFIG_WPS
  2107. if (conf->wps_state && identity_len == WSC_ID_ENROLLEE_LEN &&
  2108. os_memcmp(identity, WSC_ID_ENROLLEE, WSC_ID_ENROLLEE_LEN) == 0) {
  2109. static struct hostapd_eap_user wsc_enrollee;
  2110. os_memset(&wsc_enrollee, 0, sizeof(wsc_enrollee));
  2111. wsc_enrollee.methods[0].method = eap_server_get_type(
  2112. "WSC", &wsc_enrollee.methods[0].vendor);
  2113. return &wsc_enrollee;
  2114. }
  2115. if (conf->wps_state && conf->ap_pin &&
  2116. identity_len == WSC_ID_REGISTRAR_LEN &&
  2117. os_memcmp(identity, WSC_ID_REGISTRAR, WSC_ID_REGISTRAR_LEN) == 0) {
  2118. static struct hostapd_eap_user wsc_registrar;
  2119. os_memset(&wsc_registrar, 0, sizeof(wsc_registrar));
  2120. wsc_registrar.methods[0].method = eap_server_get_type(
  2121. "WSC", &wsc_registrar.methods[0].vendor);
  2122. wsc_registrar.password = (u8 *) conf->ap_pin;
  2123. wsc_registrar.password_len = os_strlen(conf->ap_pin);
  2124. return &wsc_registrar;
  2125. }
  2126. #endif /* CONFIG_WPS */
  2127. while (user) {
  2128. if (!phase2 && user->identity == NULL) {
  2129. /* Wildcard match */
  2130. break;
  2131. }
  2132. if (user->phase2 == !!phase2 && user->wildcard_prefix &&
  2133. identity_len >= user->identity_len &&
  2134. os_memcmp(user->identity, identity, user->identity_len) ==
  2135. 0) {
  2136. /* Wildcard prefix match */
  2137. break;
  2138. }
  2139. if (user->phase2 == !!phase2 &&
  2140. user->identity_len == identity_len &&
  2141. os_memcmp(user->identity, identity, identity_len) == 0)
  2142. break;
  2143. user = user->next;
  2144. }
  2145. return user;
  2146. }