config_file.c 61 KB

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