config_file.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242
  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_key_mgmt & WPA_KEY_MGMT_PSK) &&
  914. bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
  915. bss->ssid.wpa_psk_file == NULL) {
  916. wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
  917. "is not configured.");
  918. return -1;
  919. }
  920. if (hostapd_mac_comp_empty(bss->bssid) != 0) {
  921. size_t i;
  922. for (i = 0; i < conf->num_bss; i++) {
  923. if ((&conf->bss[i] != bss) &&
  924. (hostapd_mac_comp(conf->bss[i].bssid,
  925. bss->bssid) == 0)) {
  926. wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
  927. " on interface '%s' and '%s'.",
  928. MAC2STR(bss->bssid),
  929. conf->bss[i].iface, bss->iface);
  930. return -1;
  931. }
  932. }
  933. }
  934. #ifdef CONFIG_IEEE80211R
  935. if (wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
  936. (bss->nas_identifier == NULL ||
  937. os_strlen(bss->nas_identifier) < 1 ||
  938. os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
  939. wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
  940. "nas_identifier to be configured as a 1..48 octet "
  941. "string");
  942. return -1;
  943. }
  944. #endif /* CONFIG_IEEE80211R */
  945. #ifdef CONFIG_IEEE80211N
  946. if (conf->ieee80211n &&
  947. bss->ssid.security_policy == SECURITY_STATIC_WEP) {
  948. bss->disable_11n = 1;
  949. wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
  950. "allowed, disabling HT capabilities");
  951. }
  952. if (conf->ieee80211n && bss->wpa &&
  953. !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
  954. !(bss->rsn_pairwise & WPA_CIPHER_CCMP)) {
  955. bss->disable_11n = 1;
  956. wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
  957. "requires CCMP to be enabled, disabling HT "
  958. "capabilities");
  959. }
  960. #endif /* CONFIG_IEEE80211N */
  961. #ifdef CONFIG_WPS2
  962. if (bss->wps_state && bss->ignore_broadcast_ssid) {
  963. wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
  964. "configuration forced WPS to be disabled");
  965. bss->wps_state = 0;
  966. }
  967. if (bss->wps_state && bss->ssid.wep.keys_set && bss->wpa == 0) {
  968. wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
  969. "disabled");
  970. bss->wps_state = 0;
  971. }
  972. #endif /* CONFIG_WPS2 */
  973. return 0;
  974. }
  975. static int hostapd_config_check(struct hostapd_config *conf)
  976. {
  977. size_t i;
  978. if (conf->ieee80211d && (!conf->country[0] || !conf->country[1])) {
  979. wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
  980. "setting the country_code");
  981. return -1;
  982. }
  983. for (i = 0; i < conf->num_bss; i++) {
  984. if (hostapd_config_check_bss(&conf->bss[i], conf))
  985. return -1;
  986. }
  987. return 0;
  988. }
  989. #ifdef CONFIG_INTERWORKING
  990. static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
  991. int line)
  992. {
  993. size_t len = os_strlen(pos);
  994. u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
  995. struct hostapd_roaming_consortium *rc;
  996. if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
  997. hexstr2bin(pos, oi, len / 2)) {
  998. wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
  999. "'%s'", line, pos);
  1000. return -1;
  1001. }
  1002. len /= 2;
  1003. rc = os_realloc(bss->roaming_consortium,
  1004. sizeof(struct hostapd_roaming_consortium) *
  1005. (bss->roaming_consortium_count + 1));
  1006. if (rc == NULL)
  1007. return -1;
  1008. os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
  1009. rc[bss->roaming_consortium_count].len = len;
  1010. bss->roaming_consortium = rc;
  1011. bss->roaming_consortium_count++;
  1012. return 0;
  1013. }
  1014. #endif /* CONFIG_INTERWORKING */
  1015. /**
  1016. * hostapd_config_read - Read and parse a configuration file
  1017. * @fname: Configuration file name (including path, if needed)
  1018. * Returns: Allocated configuration data structure
  1019. */
  1020. struct hostapd_config * hostapd_config_read(const char *fname)
  1021. {
  1022. struct hostapd_config *conf;
  1023. struct hostapd_bss_config *bss;
  1024. FILE *f;
  1025. char buf[256], *pos;
  1026. int line = 0;
  1027. int errors = 0;
  1028. int pairwise;
  1029. size_t i;
  1030. f = fopen(fname, "r");
  1031. if (f == NULL) {
  1032. wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
  1033. "for reading.", fname);
  1034. return NULL;
  1035. }
  1036. conf = hostapd_config_defaults();
  1037. if (conf == NULL) {
  1038. fclose(f);
  1039. return NULL;
  1040. }
  1041. /* set default driver based on configuration */
  1042. conf->driver = wpa_drivers[0];
  1043. if (conf->driver == NULL) {
  1044. wpa_printf(MSG_ERROR, "No driver wrappers registered!");
  1045. hostapd_config_free(conf);
  1046. fclose(f);
  1047. return NULL;
  1048. }
  1049. bss = conf->last_bss = conf->bss;
  1050. while (fgets(buf, sizeof(buf), f)) {
  1051. bss = conf->last_bss;
  1052. line++;
  1053. if (buf[0] == '#')
  1054. continue;
  1055. pos = buf;
  1056. while (*pos != '\0') {
  1057. if (*pos == '\n') {
  1058. *pos = '\0';
  1059. break;
  1060. }
  1061. pos++;
  1062. }
  1063. if (buf[0] == '\0')
  1064. continue;
  1065. pos = os_strchr(buf, '=');
  1066. if (pos == NULL) {
  1067. wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
  1068. line, buf);
  1069. errors++;
  1070. continue;
  1071. }
  1072. *pos = '\0';
  1073. pos++;
  1074. if (os_strcmp(buf, "interface") == 0) {
  1075. os_strlcpy(conf->bss[0].iface, pos,
  1076. sizeof(conf->bss[0].iface));
  1077. } else if (os_strcmp(buf, "bridge") == 0) {
  1078. os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
  1079. } else if (os_strcmp(buf, "wds_bridge") == 0) {
  1080. os_strlcpy(bss->wds_bridge, pos,
  1081. sizeof(bss->wds_bridge));
  1082. } else if (os_strcmp(buf, "driver") == 0) {
  1083. int j;
  1084. /* clear to get error below if setting is invalid */
  1085. conf->driver = NULL;
  1086. for (j = 0; wpa_drivers[j]; j++) {
  1087. if (os_strcmp(pos, wpa_drivers[j]->name) == 0)
  1088. {
  1089. conf->driver = wpa_drivers[j];
  1090. break;
  1091. }
  1092. }
  1093. if (conf->driver == NULL) {
  1094. wpa_printf(MSG_ERROR, "Line %d: invalid/"
  1095. "unknown driver '%s'", line, pos);
  1096. errors++;
  1097. }
  1098. } else if (os_strcmp(buf, "debug") == 0) {
  1099. wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
  1100. "configuration variable is not used "
  1101. "anymore", line);
  1102. } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
  1103. bss->logger_syslog_level = atoi(pos);
  1104. } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
  1105. bss->logger_stdout_level = atoi(pos);
  1106. } else if (os_strcmp(buf, "logger_syslog") == 0) {
  1107. bss->logger_syslog = atoi(pos);
  1108. } else if (os_strcmp(buf, "logger_stdout") == 0) {
  1109. bss->logger_stdout = atoi(pos);
  1110. } else if (os_strcmp(buf, "dump_file") == 0) {
  1111. bss->dump_log_name = os_strdup(pos);
  1112. } else if (os_strcmp(buf, "ssid") == 0) {
  1113. bss->ssid.ssid_len = os_strlen(pos);
  1114. if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
  1115. bss->ssid.ssid_len < 1) {
  1116. wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
  1117. "'%s'", line, pos);
  1118. errors++;
  1119. } else {
  1120. os_memcpy(bss->ssid.ssid, pos,
  1121. bss->ssid.ssid_len);
  1122. bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
  1123. bss->ssid.ssid_set = 1;
  1124. }
  1125. } else if (os_strcmp(buf, "macaddr_acl") == 0) {
  1126. bss->macaddr_acl = atoi(pos);
  1127. if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
  1128. bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
  1129. bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
  1130. wpa_printf(MSG_ERROR, "Line %d: unknown "
  1131. "macaddr_acl %d",
  1132. line, bss->macaddr_acl);
  1133. }
  1134. } else if (os_strcmp(buf, "accept_mac_file") == 0) {
  1135. if (hostapd_config_read_maclist(pos, &bss->accept_mac,
  1136. &bss->num_accept_mac))
  1137. {
  1138. wpa_printf(MSG_ERROR, "Line %d: Failed to "
  1139. "read accept_mac_file '%s'",
  1140. line, pos);
  1141. errors++;
  1142. }
  1143. } else if (os_strcmp(buf, "deny_mac_file") == 0) {
  1144. if (hostapd_config_read_maclist(pos, &bss->deny_mac,
  1145. &bss->num_deny_mac)) {
  1146. wpa_printf(MSG_ERROR, "Line %d: Failed to "
  1147. "read deny_mac_file '%s'",
  1148. line, pos);
  1149. errors++;
  1150. }
  1151. } else if (os_strcmp(buf, "wds_sta") == 0) {
  1152. bss->wds_sta = atoi(pos);
  1153. } else if (os_strcmp(buf, "ap_isolate") == 0) {
  1154. bss->isolate = atoi(pos);
  1155. } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
  1156. bss->ap_max_inactivity = atoi(pos);
  1157. } else if (os_strcmp(buf, "country_code") == 0) {
  1158. os_memcpy(conf->country, pos, 2);
  1159. /* FIX: make this configurable */
  1160. conf->country[2] = ' ';
  1161. } else if (os_strcmp(buf, "ieee80211d") == 0) {
  1162. conf->ieee80211d = atoi(pos);
  1163. } else if (os_strcmp(buf, "ieee8021x") == 0) {
  1164. bss->ieee802_1x = atoi(pos);
  1165. } else if (os_strcmp(buf, "eapol_version") == 0) {
  1166. bss->eapol_version = atoi(pos);
  1167. if (bss->eapol_version < 1 ||
  1168. bss->eapol_version > 2) {
  1169. wpa_printf(MSG_ERROR, "Line %d: invalid EAPOL "
  1170. "version (%d): '%s'.",
  1171. line, bss->eapol_version, pos);
  1172. errors++;
  1173. } else
  1174. wpa_printf(MSG_DEBUG, "eapol_version=%d",
  1175. bss->eapol_version);
  1176. #ifdef EAP_SERVER
  1177. } else if (os_strcmp(buf, "eap_authenticator") == 0) {
  1178. bss->eap_server = atoi(pos);
  1179. wpa_printf(MSG_ERROR, "Line %d: obsolete "
  1180. "eap_authenticator used; this has been "
  1181. "renamed to eap_server", line);
  1182. } else if (os_strcmp(buf, "eap_server") == 0) {
  1183. bss->eap_server = atoi(pos);
  1184. } else if (os_strcmp(buf, "eap_user_file") == 0) {
  1185. if (hostapd_config_read_eap_user(pos, bss))
  1186. errors++;
  1187. } else if (os_strcmp(buf, "ca_cert") == 0) {
  1188. os_free(bss->ca_cert);
  1189. bss->ca_cert = os_strdup(pos);
  1190. } else if (os_strcmp(buf, "server_cert") == 0) {
  1191. os_free(bss->server_cert);
  1192. bss->server_cert = os_strdup(pos);
  1193. } else if (os_strcmp(buf, "private_key") == 0) {
  1194. os_free(bss->private_key);
  1195. bss->private_key = os_strdup(pos);
  1196. } else if (os_strcmp(buf, "private_key_passwd") == 0) {
  1197. os_free(bss->private_key_passwd);
  1198. bss->private_key_passwd = os_strdup(pos);
  1199. } else if (os_strcmp(buf, "check_crl") == 0) {
  1200. bss->check_crl = atoi(pos);
  1201. } else if (os_strcmp(buf, "dh_file") == 0) {
  1202. os_free(bss->dh_file);
  1203. bss->dh_file = os_strdup(pos);
  1204. } else if (os_strcmp(buf, "fragment_size") == 0) {
  1205. bss->fragment_size = atoi(pos);
  1206. #ifdef EAP_SERVER_FAST
  1207. } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
  1208. os_free(bss->pac_opaque_encr_key);
  1209. bss->pac_opaque_encr_key = os_malloc(16);
  1210. if (bss->pac_opaque_encr_key == NULL) {
  1211. wpa_printf(MSG_ERROR, "Line %d: No memory for "
  1212. "pac_opaque_encr_key", line);
  1213. errors++;
  1214. } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
  1215. 16)) {
  1216. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1217. "pac_opaque_encr_key", line);
  1218. errors++;
  1219. }
  1220. } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
  1221. size_t idlen = os_strlen(pos);
  1222. if (idlen & 1) {
  1223. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1224. "eap_fast_a_id", line);
  1225. errors++;
  1226. } else {
  1227. os_free(bss->eap_fast_a_id);
  1228. bss->eap_fast_a_id = os_malloc(idlen / 2);
  1229. if (bss->eap_fast_a_id == NULL ||
  1230. hexstr2bin(pos, bss->eap_fast_a_id,
  1231. idlen / 2)) {
  1232. wpa_printf(MSG_ERROR, "Line %d: "
  1233. "Failed to parse "
  1234. "eap_fast_a_id", line);
  1235. errors++;
  1236. } else
  1237. bss->eap_fast_a_id_len = idlen / 2;
  1238. }
  1239. } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
  1240. os_free(bss->eap_fast_a_id_info);
  1241. bss->eap_fast_a_id_info = os_strdup(pos);
  1242. } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
  1243. bss->eap_fast_prov = atoi(pos);
  1244. } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
  1245. bss->pac_key_lifetime = atoi(pos);
  1246. } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
  1247. bss->pac_key_refresh_time = atoi(pos);
  1248. #endif /* EAP_SERVER_FAST */
  1249. #ifdef EAP_SERVER_SIM
  1250. } else if (os_strcmp(buf, "eap_sim_db") == 0) {
  1251. os_free(bss->eap_sim_db);
  1252. bss->eap_sim_db = os_strdup(pos);
  1253. } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
  1254. bss->eap_sim_aka_result_ind = atoi(pos);
  1255. #endif /* EAP_SERVER_SIM */
  1256. #ifdef EAP_SERVER_TNC
  1257. } else if (os_strcmp(buf, "tnc") == 0) {
  1258. bss->tnc = atoi(pos);
  1259. #endif /* EAP_SERVER_TNC */
  1260. #ifdef EAP_SERVER_PWD
  1261. } else if (os_strcmp(buf, "pwd_group") == 0) {
  1262. bss->pwd_group = atoi(pos);
  1263. #endif /* EAP_SERVER_PWD */
  1264. #endif /* EAP_SERVER */
  1265. } else if (os_strcmp(buf, "eap_message") == 0) {
  1266. char *term;
  1267. bss->eap_req_id_text = os_strdup(pos);
  1268. if (bss->eap_req_id_text == NULL) {
  1269. wpa_printf(MSG_ERROR, "Line %d: Failed to "
  1270. "allocate memory for "
  1271. "eap_req_id_text", line);
  1272. errors++;
  1273. continue;
  1274. }
  1275. bss->eap_req_id_text_len =
  1276. os_strlen(bss->eap_req_id_text);
  1277. term = os_strstr(bss->eap_req_id_text, "\\0");
  1278. if (term) {
  1279. *term++ = '\0';
  1280. os_memmove(term, term + 1,
  1281. bss->eap_req_id_text_len -
  1282. (term - bss->eap_req_id_text) - 1);
  1283. bss->eap_req_id_text_len--;
  1284. }
  1285. } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
  1286. bss->default_wep_key_len = atoi(pos);
  1287. if (bss->default_wep_key_len > 13) {
  1288. wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
  1289. "key len %lu (= %lu bits)", line,
  1290. (unsigned long)
  1291. bss->default_wep_key_len,
  1292. (unsigned long)
  1293. bss->default_wep_key_len * 8);
  1294. errors++;
  1295. }
  1296. } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
  1297. bss->individual_wep_key_len = atoi(pos);
  1298. if (bss->individual_wep_key_len < 0 ||
  1299. bss->individual_wep_key_len > 13) {
  1300. wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
  1301. "key len %d (= %d bits)", line,
  1302. bss->individual_wep_key_len,
  1303. bss->individual_wep_key_len * 8);
  1304. errors++;
  1305. }
  1306. } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
  1307. bss->wep_rekeying_period = atoi(pos);
  1308. if (bss->wep_rekeying_period < 0) {
  1309. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1310. "period %d",
  1311. line, bss->wep_rekeying_period);
  1312. errors++;
  1313. }
  1314. } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
  1315. bss->eap_reauth_period = atoi(pos);
  1316. if (bss->eap_reauth_period < 0) {
  1317. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1318. "period %d",
  1319. line, bss->eap_reauth_period);
  1320. errors++;
  1321. }
  1322. } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
  1323. bss->eapol_key_index_workaround = atoi(pos);
  1324. #ifdef CONFIG_IAPP
  1325. } else if (os_strcmp(buf, "iapp_interface") == 0) {
  1326. bss->ieee802_11f = 1;
  1327. os_strlcpy(bss->iapp_iface, pos,
  1328. sizeof(bss->iapp_iface));
  1329. #endif /* CONFIG_IAPP */
  1330. } else if (os_strcmp(buf, "own_ip_addr") == 0) {
  1331. if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
  1332. wpa_printf(MSG_ERROR, "Line %d: invalid IP "
  1333. "address '%s'", line, pos);
  1334. errors++;
  1335. }
  1336. } else if (os_strcmp(buf, "nas_identifier") == 0) {
  1337. bss->nas_identifier = os_strdup(pos);
  1338. #ifndef CONFIG_NO_RADIUS
  1339. } else if (os_strcmp(buf, "auth_server_addr") == 0) {
  1340. if (hostapd_config_read_radius_addr(
  1341. &bss->radius->auth_servers,
  1342. &bss->radius->num_auth_servers, pos, 1812,
  1343. &bss->radius->auth_server)) {
  1344. wpa_printf(MSG_ERROR, "Line %d: invalid IP "
  1345. "address '%s'", line, pos);
  1346. errors++;
  1347. }
  1348. } else if (bss->radius->auth_server &&
  1349. os_strcmp(buf, "auth_server_port") == 0) {
  1350. bss->radius->auth_server->port = atoi(pos);
  1351. } else if (bss->radius->auth_server &&
  1352. os_strcmp(buf, "auth_server_shared_secret") == 0) {
  1353. int len = os_strlen(pos);
  1354. if (len == 0) {
  1355. /* RFC 2865, Ch. 3 */
  1356. wpa_printf(MSG_ERROR, "Line %d: empty shared "
  1357. "secret is not allowed.", line);
  1358. errors++;
  1359. }
  1360. bss->radius->auth_server->shared_secret =
  1361. (u8 *) os_strdup(pos);
  1362. bss->radius->auth_server->shared_secret_len = len;
  1363. } else if (os_strcmp(buf, "acct_server_addr") == 0) {
  1364. if (hostapd_config_read_radius_addr(
  1365. &bss->radius->acct_servers,
  1366. &bss->radius->num_acct_servers, pos, 1813,
  1367. &bss->radius->acct_server)) {
  1368. wpa_printf(MSG_ERROR, "Line %d: invalid IP "
  1369. "address '%s'", line, pos);
  1370. errors++;
  1371. }
  1372. } else if (bss->radius->acct_server &&
  1373. os_strcmp(buf, "acct_server_port") == 0) {
  1374. bss->radius->acct_server->port = atoi(pos);
  1375. } else if (bss->radius->acct_server &&
  1376. os_strcmp(buf, "acct_server_shared_secret") == 0) {
  1377. int len = os_strlen(pos);
  1378. if (len == 0) {
  1379. /* RFC 2865, Ch. 3 */
  1380. wpa_printf(MSG_ERROR, "Line %d: empty shared "
  1381. "secret is not allowed.", line);
  1382. errors++;
  1383. }
  1384. bss->radius->acct_server->shared_secret =
  1385. (u8 *) os_strdup(pos);
  1386. bss->radius->acct_server->shared_secret_len = len;
  1387. } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
  1388. 0) {
  1389. bss->radius->retry_primary_interval = atoi(pos);
  1390. } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
  1391. {
  1392. bss->acct_interim_interval = atoi(pos);
  1393. #endif /* CONFIG_NO_RADIUS */
  1394. } else if (os_strcmp(buf, "auth_algs") == 0) {
  1395. bss->auth_algs = atoi(pos);
  1396. if (bss->auth_algs == 0) {
  1397. wpa_printf(MSG_ERROR, "Line %d: no "
  1398. "authentication algorithms allowed",
  1399. line);
  1400. errors++;
  1401. }
  1402. } else if (os_strcmp(buf, "max_num_sta") == 0) {
  1403. bss->max_num_sta = atoi(pos);
  1404. if (bss->max_num_sta < 0 ||
  1405. bss->max_num_sta > MAX_STA_COUNT) {
  1406. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1407. "max_num_sta=%d; allowed range "
  1408. "0..%d", line, bss->max_num_sta,
  1409. MAX_STA_COUNT);
  1410. errors++;
  1411. }
  1412. } else if (os_strcmp(buf, "wpa") == 0) {
  1413. bss->wpa = atoi(pos);
  1414. } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
  1415. bss->wpa_group_rekey = atoi(pos);
  1416. } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
  1417. bss->wpa_strict_rekey = atoi(pos);
  1418. } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
  1419. bss->wpa_gmk_rekey = atoi(pos);
  1420. } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
  1421. bss->wpa_ptk_rekey = atoi(pos);
  1422. } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
  1423. int len = os_strlen(pos);
  1424. if (len < 8 || len > 63) {
  1425. wpa_printf(MSG_ERROR, "Line %d: invalid WPA "
  1426. "passphrase length %d (expected "
  1427. "8..63)", line, len);
  1428. errors++;
  1429. } else {
  1430. os_free(bss->ssid.wpa_passphrase);
  1431. bss->ssid.wpa_passphrase = os_strdup(pos);
  1432. }
  1433. } else if (os_strcmp(buf, "wpa_psk") == 0) {
  1434. os_free(bss->ssid.wpa_psk);
  1435. bss->ssid.wpa_psk =
  1436. os_zalloc(sizeof(struct hostapd_wpa_psk));
  1437. if (bss->ssid.wpa_psk == NULL)
  1438. errors++;
  1439. else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
  1440. PMK_LEN) ||
  1441. pos[PMK_LEN * 2] != '\0') {
  1442. wpa_printf(MSG_ERROR, "Line %d: Invalid PSK "
  1443. "'%s'.", line, pos);
  1444. errors++;
  1445. } else {
  1446. bss->ssid.wpa_psk->group = 1;
  1447. }
  1448. } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
  1449. os_free(bss->ssid.wpa_psk_file);
  1450. bss->ssid.wpa_psk_file = os_strdup(pos);
  1451. if (!bss->ssid.wpa_psk_file) {
  1452. wpa_printf(MSG_ERROR, "Line %d: allocation "
  1453. "failed", line);
  1454. errors++;
  1455. }
  1456. } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
  1457. bss->wpa_key_mgmt =
  1458. hostapd_config_parse_key_mgmt(line, pos);
  1459. if (bss->wpa_key_mgmt == -1)
  1460. errors++;
  1461. } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
  1462. bss->wpa_pairwise =
  1463. hostapd_config_parse_cipher(line, pos);
  1464. if (bss->wpa_pairwise == -1 ||
  1465. bss->wpa_pairwise == 0)
  1466. errors++;
  1467. else if (bss->wpa_pairwise &
  1468. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
  1469. WPA_CIPHER_WEP104)) {
  1470. wpa_printf(MSG_ERROR, "Line %d: unsupported "
  1471. "pairwise cipher suite '%s'",
  1472. bss->wpa_pairwise, pos);
  1473. errors++;
  1474. }
  1475. } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
  1476. bss->rsn_pairwise =
  1477. hostapd_config_parse_cipher(line, pos);
  1478. if (bss->rsn_pairwise == -1 ||
  1479. bss->rsn_pairwise == 0)
  1480. errors++;
  1481. else if (bss->rsn_pairwise &
  1482. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
  1483. WPA_CIPHER_WEP104)) {
  1484. wpa_printf(MSG_ERROR, "Line %d: unsupported "
  1485. "pairwise cipher suite '%s'",
  1486. bss->rsn_pairwise, pos);
  1487. errors++;
  1488. }
  1489. #ifdef CONFIG_RSN_PREAUTH
  1490. } else if (os_strcmp(buf, "rsn_preauth") == 0) {
  1491. bss->rsn_preauth = atoi(pos);
  1492. } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
  1493. bss->rsn_preauth_interfaces = os_strdup(pos);
  1494. #endif /* CONFIG_RSN_PREAUTH */
  1495. #ifdef CONFIG_PEERKEY
  1496. } else if (os_strcmp(buf, "peerkey") == 0) {
  1497. bss->peerkey = atoi(pos);
  1498. #endif /* CONFIG_PEERKEY */
  1499. #ifdef CONFIG_IEEE80211R
  1500. } else if (os_strcmp(buf, "mobility_domain") == 0) {
  1501. if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
  1502. hexstr2bin(pos, bss->mobility_domain,
  1503. MOBILITY_DOMAIN_ID_LEN) != 0) {
  1504. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1505. "mobility_domain '%s'", line, pos);
  1506. errors++;
  1507. continue;
  1508. }
  1509. } else if (os_strcmp(buf, "r1_key_holder") == 0) {
  1510. if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
  1511. hexstr2bin(pos, bss->r1_key_holder,
  1512. FT_R1KH_ID_LEN) != 0) {
  1513. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1514. "r1_key_holder '%s'", line, pos);
  1515. errors++;
  1516. continue;
  1517. }
  1518. } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
  1519. bss->r0_key_lifetime = atoi(pos);
  1520. } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
  1521. bss->reassociation_deadline = atoi(pos);
  1522. } else if (os_strcmp(buf, "r0kh") == 0) {
  1523. if (add_r0kh(bss, pos) < 0) {
  1524. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1525. "r0kh '%s'", line, pos);
  1526. errors++;
  1527. continue;
  1528. }
  1529. } else if (os_strcmp(buf, "r1kh") == 0) {
  1530. if (add_r1kh(bss, pos) < 0) {
  1531. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1532. "r1kh '%s'", line, pos);
  1533. errors++;
  1534. continue;
  1535. }
  1536. } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
  1537. bss->pmk_r1_push = atoi(pos);
  1538. } else if (os_strcmp(buf, "ft_over_ds") == 0) {
  1539. bss->ft_over_ds = atoi(pos);
  1540. #endif /* CONFIG_IEEE80211R */
  1541. #ifndef CONFIG_NO_CTRL_IFACE
  1542. } else if (os_strcmp(buf, "ctrl_interface") == 0) {
  1543. os_free(bss->ctrl_interface);
  1544. bss->ctrl_interface = os_strdup(pos);
  1545. } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
  1546. #ifndef CONFIG_NATIVE_WINDOWS
  1547. struct group *grp;
  1548. char *endp;
  1549. const char *group = pos;
  1550. grp = getgrnam(group);
  1551. if (grp) {
  1552. bss->ctrl_interface_gid = grp->gr_gid;
  1553. bss->ctrl_interface_gid_set = 1;
  1554. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
  1555. " (from group name '%s')",
  1556. bss->ctrl_interface_gid, group);
  1557. continue;
  1558. }
  1559. /* Group name not found - try to parse this as gid */
  1560. bss->ctrl_interface_gid = strtol(group, &endp, 10);
  1561. if (*group == '\0' || *endp != '\0') {
  1562. wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
  1563. "'%s'", line, group);
  1564. errors++;
  1565. continue;
  1566. }
  1567. bss->ctrl_interface_gid_set = 1;
  1568. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
  1569. bss->ctrl_interface_gid);
  1570. #endif /* CONFIG_NATIVE_WINDOWS */
  1571. #endif /* CONFIG_NO_CTRL_IFACE */
  1572. #ifdef RADIUS_SERVER
  1573. } else if (os_strcmp(buf, "radius_server_clients") == 0) {
  1574. os_free(bss->radius_server_clients);
  1575. bss->radius_server_clients = os_strdup(pos);
  1576. } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
  1577. bss->radius_server_auth_port = atoi(pos);
  1578. } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
  1579. bss->radius_server_ipv6 = atoi(pos);
  1580. #endif /* RADIUS_SERVER */
  1581. } else if (os_strcmp(buf, "test_socket") == 0) {
  1582. os_free(bss->test_socket);
  1583. bss->test_socket = os_strdup(pos);
  1584. } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
  1585. bss->use_pae_group_addr = atoi(pos);
  1586. } else if (os_strcmp(buf, "hw_mode") == 0) {
  1587. if (os_strcmp(pos, "a") == 0)
  1588. conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
  1589. else if (os_strcmp(pos, "b") == 0)
  1590. conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
  1591. else if (os_strcmp(pos, "g") == 0)
  1592. conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
  1593. else {
  1594. wpa_printf(MSG_ERROR, "Line %d: unknown "
  1595. "hw_mode '%s'", line, pos);
  1596. errors++;
  1597. }
  1598. } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
  1599. if (os_strcmp(pos, "a") == 0)
  1600. bss->wps_rf_bands = WPS_RF_50GHZ;
  1601. else if (os_strcmp(pos, "g") == 0 ||
  1602. os_strcmp(pos, "b") == 0)
  1603. bss->wps_rf_bands = WPS_RF_24GHZ;
  1604. else if (os_strcmp(pos, "ag") == 0 ||
  1605. os_strcmp(pos, "ga") == 0)
  1606. bss->wps_rf_bands =
  1607. WPS_RF_24GHZ | WPS_RF_50GHZ;
  1608. else {
  1609. wpa_printf(MSG_ERROR, "Line %d: unknown "
  1610. "wps_rf_band '%s'", line, pos);
  1611. errors++;
  1612. }
  1613. } else if (os_strcmp(buf, "channel") == 0) {
  1614. conf->channel = atoi(pos);
  1615. } else if (os_strcmp(buf, "beacon_int") == 0) {
  1616. int val = atoi(pos);
  1617. /* MIB defines range as 1..65535, but very small values
  1618. * cause problems with the current implementation.
  1619. * Since it is unlikely that this small numbers are
  1620. * useful in real life scenarios, do not allow beacon
  1621. * period to be set below 15 TU. */
  1622. if (val < 15 || val > 65535) {
  1623. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1624. "beacon_int %d (expected "
  1625. "15..65535)", line, val);
  1626. errors++;
  1627. } else
  1628. conf->beacon_int = val;
  1629. } else if (os_strcmp(buf, "dtim_period") == 0) {
  1630. bss->dtim_period = atoi(pos);
  1631. if (bss->dtim_period < 1 || bss->dtim_period > 255) {
  1632. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1633. "dtim_period %d",
  1634. line, bss->dtim_period);
  1635. errors++;
  1636. }
  1637. } else if (os_strcmp(buf, "rts_threshold") == 0) {
  1638. conf->rts_threshold = atoi(pos);
  1639. if (conf->rts_threshold < 0 ||
  1640. conf->rts_threshold > 2347) {
  1641. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1642. "rts_threshold %d",
  1643. line, conf->rts_threshold);
  1644. errors++;
  1645. }
  1646. } else if (os_strcmp(buf, "fragm_threshold") == 0) {
  1647. conf->fragm_threshold = atoi(pos);
  1648. if (conf->fragm_threshold < 256 ||
  1649. conf->fragm_threshold > 2346) {
  1650. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1651. "fragm_threshold %d",
  1652. line, conf->fragm_threshold);
  1653. errors++;
  1654. }
  1655. } else if (os_strcmp(buf, "send_probe_response") == 0) {
  1656. int val = atoi(pos);
  1657. if (val != 0 && val != 1) {
  1658. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1659. "send_probe_response %d (expected "
  1660. "0 or 1)", line, val);
  1661. } else
  1662. conf->send_probe_response = val;
  1663. } else if (os_strcmp(buf, "supported_rates") == 0) {
  1664. if (hostapd_parse_rates(&conf->supported_rates, pos)) {
  1665. wpa_printf(MSG_ERROR, "Line %d: invalid rate "
  1666. "list", line);
  1667. errors++;
  1668. }
  1669. } else if (os_strcmp(buf, "basic_rates") == 0) {
  1670. if (hostapd_parse_rates(&conf->basic_rates, pos)) {
  1671. wpa_printf(MSG_ERROR, "Line %d: invalid rate "
  1672. "list", line);
  1673. errors++;
  1674. }
  1675. } else if (os_strcmp(buf, "preamble") == 0) {
  1676. if (atoi(pos))
  1677. conf->preamble = SHORT_PREAMBLE;
  1678. else
  1679. conf->preamble = LONG_PREAMBLE;
  1680. } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
  1681. bss->ignore_broadcast_ssid = atoi(pos);
  1682. } else if (os_strcmp(buf, "wep_default_key") == 0) {
  1683. bss->ssid.wep.idx = atoi(pos);
  1684. if (bss->ssid.wep.idx > 3) {
  1685. wpa_printf(MSG_ERROR, "Invalid "
  1686. "wep_default_key index %d",
  1687. bss->ssid.wep.idx);
  1688. errors++;
  1689. }
  1690. } else if (os_strcmp(buf, "wep_key0") == 0 ||
  1691. os_strcmp(buf, "wep_key1") == 0 ||
  1692. os_strcmp(buf, "wep_key2") == 0 ||
  1693. os_strcmp(buf, "wep_key3") == 0) {
  1694. if (hostapd_config_read_wep(&bss->ssid.wep,
  1695. buf[7] - '0', pos)) {
  1696. wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
  1697. "key '%s'", line, buf);
  1698. errors++;
  1699. }
  1700. #ifndef CONFIG_NO_VLAN
  1701. } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
  1702. bss->ssid.dynamic_vlan = atoi(pos);
  1703. } else if (os_strcmp(buf, "vlan_file") == 0) {
  1704. if (hostapd_config_read_vlan_file(bss, pos)) {
  1705. wpa_printf(MSG_ERROR, "Line %d: failed to "
  1706. "read VLAN file '%s'", line, pos);
  1707. errors++;
  1708. }
  1709. #ifdef CONFIG_FULL_DYNAMIC_VLAN
  1710. } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
  1711. bss->ssid.vlan_tagged_interface = os_strdup(pos);
  1712. #endif /* CONFIG_FULL_DYNAMIC_VLAN */
  1713. #endif /* CONFIG_NO_VLAN */
  1714. } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
  1715. conf->ap_table_max_size = atoi(pos);
  1716. } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
  1717. conf->ap_table_expiration_time = atoi(pos);
  1718. } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
  1719. if (hostapd_config_tx_queue(conf, buf, pos)) {
  1720. wpa_printf(MSG_ERROR, "Line %d: invalid TX "
  1721. "queue item", line);
  1722. errors++;
  1723. }
  1724. } else if (os_strcmp(buf, "wme_enabled") == 0 ||
  1725. os_strcmp(buf, "wmm_enabled") == 0) {
  1726. bss->wmm_enabled = atoi(pos);
  1727. } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
  1728. bss->wmm_uapsd = atoi(pos);
  1729. } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
  1730. os_strncmp(buf, "wmm_ac_", 7) == 0) {
  1731. if (hostapd_config_wmm_ac(conf, buf, pos)) {
  1732. wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
  1733. "ac item", line);
  1734. errors++;
  1735. }
  1736. } else if (os_strcmp(buf, "bss") == 0) {
  1737. if (hostapd_config_bss(conf, pos)) {
  1738. wpa_printf(MSG_ERROR, "Line %d: invalid bss "
  1739. "item", line);
  1740. errors++;
  1741. }
  1742. } else if (os_strcmp(buf, "bssid") == 0) {
  1743. if (hwaddr_aton(pos, bss->bssid)) {
  1744. wpa_printf(MSG_ERROR, "Line %d: invalid bssid "
  1745. "item", line);
  1746. errors++;
  1747. }
  1748. #ifdef CONFIG_IEEE80211W
  1749. } else if (os_strcmp(buf, "ieee80211w") == 0) {
  1750. bss->ieee80211w = atoi(pos);
  1751. } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
  1752. bss->assoc_sa_query_max_timeout = atoi(pos);
  1753. if (bss->assoc_sa_query_max_timeout == 0) {
  1754. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1755. "assoc_sa_query_max_timeout", line);
  1756. errors++;
  1757. }
  1758. } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0)
  1759. {
  1760. bss->assoc_sa_query_retry_timeout = atoi(pos);
  1761. if (bss->assoc_sa_query_retry_timeout == 0) {
  1762. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1763. "assoc_sa_query_retry_timeout",
  1764. line);
  1765. errors++;
  1766. }
  1767. #endif /* CONFIG_IEEE80211W */
  1768. #ifdef CONFIG_IEEE80211N
  1769. } else if (os_strcmp(buf, "ieee80211n") == 0) {
  1770. conf->ieee80211n = atoi(pos);
  1771. } else if (os_strcmp(buf, "ht_capab") == 0) {
  1772. if (hostapd_config_ht_capab(conf, pos) < 0) {
  1773. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1774. "ht_capab", line);
  1775. errors++;
  1776. }
  1777. } else if (os_strcmp(buf, "require_ht") == 0) {
  1778. conf->require_ht = atoi(pos);
  1779. #endif /* CONFIG_IEEE80211N */
  1780. } else if (os_strcmp(buf, "max_listen_interval") == 0) {
  1781. bss->max_listen_interval = atoi(pos);
  1782. } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
  1783. bss->disable_pmksa_caching = atoi(pos);
  1784. } else if (os_strcmp(buf, "okc") == 0) {
  1785. bss->okc = atoi(pos);
  1786. #ifdef CONFIG_WPS
  1787. } else if (os_strcmp(buf, "wps_state") == 0) {
  1788. bss->wps_state = atoi(pos);
  1789. if (bss->wps_state < 0 || bss->wps_state > 2) {
  1790. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1791. "wps_state", line);
  1792. errors++;
  1793. }
  1794. } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
  1795. bss->ap_setup_locked = atoi(pos);
  1796. } else if (os_strcmp(buf, "uuid") == 0) {
  1797. if (uuid_str2bin(pos, bss->uuid)) {
  1798. wpa_printf(MSG_ERROR, "Line %d: invalid UUID",
  1799. line);
  1800. errors++;
  1801. }
  1802. } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
  1803. os_free(bss->wps_pin_requests);
  1804. bss->wps_pin_requests = os_strdup(pos);
  1805. } else if (os_strcmp(buf, "device_name") == 0) {
  1806. if (os_strlen(pos) > 32) {
  1807. wpa_printf(MSG_ERROR, "Line %d: Too long "
  1808. "device_name", line);
  1809. errors++;
  1810. }
  1811. os_free(bss->device_name);
  1812. bss->device_name = os_strdup(pos);
  1813. } else if (os_strcmp(buf, "manufacturer") == 0) {
  1814. if (os_strlen(pos) > 64) {
  1815. wpa_printf(MSG_ERROR, "Line %d: Too long "
  1816. "manufacturer", line);
  1817. errors++;
  1818. }
  1819. os_free(bss->manufacturer);
  1820. bss->manufacturer = os_strdup(pos);
  1821. } else if (os_strcmp(buf, "model_name") == 0) {
  1822. if (os_strlen(pos) > 32) {
  1823. wpa_printf(MSG_ERROR, "Line %d: Too long "
  1824. "model_name", line);
  1825. errors++;
  1826. }
  1827. os_free(bss->model_name);
  1828. bss->model_name = os_strdup(pos);
  1829. } else if (os_strcmp(buf, "model_number") == 0) {
  1830. if (os_strlen(pos) > 32) {
  1831. wpa_printf(MSG_ERROR, "Line %d: Too long "
  1832. "model_number", line);
  1833. errors++;
  1834. }
  1835. os_free(bss->model_number);
  1836. bss->model_number = os_strdup(pos);
  1837. } else if (os_strcmp(buf, "serial_number") == 0) {
  1838. if (os_strlen(pos) > 32) {
  1839. wpa_printf(MSG_ERROR, "Line %d: Too long "
  1840. "serial_number", line);
  1841. errors++;
  1842. }
  1843. os_free(bss->serial_number);
  1844. bss->serial_number = os_strdup(pos);
  1845. } else if (os_strcmp(buf, "device_type") == 0) {
  1846. if (wps_dev_type_str2bin(pos, bss->device_type))
  1847. errors++;
  1848. } else if (os_strcmp(buf, "config_methods") == 0) {
  1849. os_free(bss->config_methods);
  1850. bss->config_methods = os_strdup(pos);
  1851. } else if (os_strcmp(buf, "os_version") == 0) {
  1852. if (hexstr2bin(pos, bss->os_version, 4)) {
  1853. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1854. "os_version", line);
  1855. errors++;
  1856. }
  1857. } else if (os_strcmp(buf, "ap_pin") == 0) {
  1858. os_free(bss->ap_pin);
  1859. bss->ap_pin = os_strdup(pos);
  1860. } else if (os_strcmp(buf, "skip_cred_build") == 0) {
  1861. bss->skip_cred_build = atoi(pos);
  1862. } else if (os_strcmp(buf, "extra_cred") == 0) {
  1863. os_free(bss->extra_cred);
  1864. bss->extra_cred =
  1865. (u8 *) os_readfile(pos, &bss->extra_cred_len);
  1866. if (bss->extra_cred == NULL) {
  1867. wpa_printf(MSG_ERROR, "Line %d: could not "
  1868. "read Credentials from '%s'",
  1869. line, pos);
  1870. errors++;
  1871. }
  1872. } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
  1873. bss->wps_cred_processing = atoi(pos);
  1874. } else if (os_strcmp(buf, "ap_settings") == 0) {
  1875. os_free(bss->ap_settings);
  1876. bss->ap_settings =
  1877. (u8 *) os_readfile(pos, &bss->ap_settings_len);
  1878. if (bss->ap_settings == NULL) {
  1879. wpa_printf(MSG_ERROR, "Line %d: could not "
  1880. "read AP Settings from '%s'",
  1881. line, pos);
  1882. errors++;
  1883. }
  1884. } else if (os_strcmp(buf, "upnp_iface") == 0) {
  1885. bss->upnp_iface = os_strdup(pos);
  1886. } else if (os_strcmp(buf, "friendly_name") == 0) {
  1887. os_free(bss->friendly_name);
  1888. bss->friendly_name = os_strdup(pos);
  1889. } else if (os_strcmp(buf, "manufacturer_url") == 0) {
  1890. os_free(bss->manufacturer_url);
  1891. bss->manufacturer_url = os_strdup(pos);
  1892. } else if (os_strcmp(buf, "model_description") == 0) {
  1893. os_free(bss->model_description);
  1894. bss->model_description = os_strdup(pos);
  1895. } else if (os_strcmp(buf, "model_url") == 0) {
  1896. os_free(bss->model_url);
  1897. bss->model_url = os_strdup(pos);
  1898. } else if (os_strcmp(buf, "upc") == 0) {
  1899. os_free(bss->upc);
  1900. bss->upc = os_strdup(pos);
  1901. } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
  1902. bss->pbc_in_m1 = atoi(pos);
  1903. #endif /* CONFIG_WPS */
  1904. #ifdef CONFIG_P2P_MANAGER
  1905. } else if (os_strcmp(buf, "manage_p2p") == 0) {
  1906. int manage = atoi(pos);
  1907. if (manage)
  1908. bss->p2p |= P2P_MANAGE;
  1909. else
  1910. bss->p2p &= ~P2P_MANAGE;
  1911. } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
  1912. if (atoi(pos))
  1913. bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
  1914. else
  1915. bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
  1916. #endif /* CONFIG_P2P_MANAGER */
  1917. } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
  1918. bss->disassoc_low_ack = atoi(pos);
  1919. } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
  1920. int val = atoi(pos);
  1921. if (val)
  1922. bss->tdls |= TDLS_PROHIBIT;
  1923. else
  1924. bss->tdls &= ~TDLS_PROHIBIT;
  1925. } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
  1926. int val = atoi(pos);
  1927. if (val)
  1928. bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
  1929. else
  1930. bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
  1931. #ifdef CONFIG_RSN_TESTING
  1932. } else if (os_strcmp(buf, "rsn_testing") == 0) {
  1933. extern int rsn_testing;
  1934. rsn_testing = atoi(pos);
  1935. #endif /* CONFIG_RSN_TESTING */
  1936. } else if (os_strcmp(buf, "time_advertisement") == 0) {
  1937. bss->time_advertisement = atoi(pos);
  1938. } else if (os_strcmp(buf, "time_zone") == 0) {
  1939. size_t tz_len = os_strlen(pos);
  1940. if (tz_len < 4 || tz_len > 255) {
  1941. wpa_printf(MSG_DEBUG, "Line %d: invalid "
  1942. "time_zone", line);
  1943. errors++;
  1944. continue;
  1945. }
  1946. os_free(bss->time_zone);
  1947. bss->time_zone = os_strdup(pos);
  1948. if (bss->time_zone == NULL)
  1949. errors++;
  1950. #ifdef CONFIG_INTERWORKING
  1951. } else if (os_strcmp(buf, "interworking") == 0) {
  1952. bss->interworking = atoi(pos);
  1953. } else if (os_strcmp(buf, "access_network_type") == 0) {
  1954. bss->access_network_type = atoi(pos);
  1955. if (bss->access_network_type < 0 ||
  1956. bss->access_network_type > 15) {
  1957. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1958. "access_network_type", line);
  1959. errors++;
  1960. }
  1961. } else if (os_strcmp(buf, "internet") == 0) {
  1962. bss->internet = atoi(pos);
  1963. } else if (os_strcmp(buf, "asra") == 0) {
  1964. bss->asra = atoi(pos);
  1965. } else if (os_strcmp(buf, "esr") == 0) {
  1966. bss->esr = atoi(pos);
  1967. } else if (os_strcmp(buf, "uesa") == 0) {
  1968. bss->uesa = atoi(pos);
  1969. } else if (os_strcmp(buf, "venue_group") == 0) {
  1970. bss->venue_group = atoi(pos);
  1971. bss->venue_info_set = 1;
  1972. } else if (os_strcmp(buf, "venue_type") == 0) {
  1973. bss->venue_type = atoi(pos);
  1974. bss->venue_info_set = 1;
  1975. } else if (os_strcmp(buf, "hessid") == 0) {
  1976. if (hwaddr_aton(pos, bss->hessid)) {
  1977. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1978. "hessid", line);
  1979. errors++;
  1980. }
  1981. } else if (os_strcmp(buf, "roaming_consortium") == 0) {
  1982. if (parse_roaming_consortium(bss, pos, line) < 0)
  1983. errors++;
  1984. #endif /* CONFIG_INTERWORKING */
  1985. #ifdef CONFIG_RADIUS_TEST
  1986. } else if (os_strcmp(buf, "dump_msk_file") == 0) {
  1987. os_free(bss->dump_msk_file);
  1988. bss->dump_msk_file = os_strdup(pos);
  1989. #endif /* CONFIG_RADIUS_TEST */
  1990. } else {
  1991. wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
  1992. "item '%s'", line, buf);
  1993. errors++;
  1994. }
  1995. }
  1996. fclose(f);
  1997. for (i = 0; i < conf->num_bss; i++) {
  1998. bss = &conf->bss[i];
  1999. if (bss->individual_wep_key_len == 0) {
  2000. /* individual keys are not use; can use key idx0 for
  2001. * broadcast keys */
  2002. bss->broadcast_key_idx_min = 0;
  2003. }
  2004. /* Select group cipher based on the enabled pairwise cipher
  2005. * suites */
  2006. pairwise = 0;
  2007. if (bss->wpa & 1)
  2008. pairwise |= bss->wpa_pairwise;
  2009. if (bss->wpa & 2) {
  2010. if (bss->rsn_pairwise == 0)
  2011. bss->rsn_pairwise = bss->wpa_pairwise;
  2012. pairwise |= bss->rsn_pairwise;
  2013. }
  2014. if (pairwise & WPA_CIPHER_TKIP)
  2015. bss->wpa_group = WPA_CIPHER_TKIP;
  2016. else
  2017. bss->wpa_group = WPA_CIPHER_CCMP;
  2018. bss->radius->auth_server = bss->radius->auth_servers;
  2019. bss->radius->acct_server = bss->radius->acct_servers;
  2020. if (bss->wpa && bss->ieee802_1x) {
  2021. bss->ssid.security_policy = SECURITY_WPA;
  2022. } else if (bss->wpa) {
  2023. bss->ssid.security_policy = SECURITY_WPA_PSK;
  2024. } else if (bss->ieee802_1x) {
  2025. int cipher = WPA_CIPHER_NONE;
  2026. bss->ssid.security_policy = SECURITY_IEEE_802_1X;
  2027. bss->ssid.wep.default_len = bss->default_wep_key_len;
  2028. if (bss->default_wep_key_len)
  2029. cipher = bss->default_wep_key_len >= 13 ?
  2030. WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
  2031. bss->wpa_group = cipher;
  2032. bss->wpa_pairwise = cipher;
  2033. bss->rsn_pairwise = cipher;
  2034. } else if (bss->ssid.wep.keys_set) {
  2035. int cipher = WPA_CIPHER_WEP40;
  2036. if (bss->ssid.wep.len[0] >= 13)
  2037. cipher = WPA_CIPHER_WEP104;
  2038. bss->ssid.security_policy = SECURITY_STATIC_WEP;
  2039. bss->wpa_group = cipher;
  2040. bss->wpa_pairwise = cipher;
  2041. bss->rsn_pairwise = cipher;
  2042. } else {
  2043. bss->ssid.security_policy = SECURITY_PLAINTEXT;
  2044. bss->wpa_group = WPA_CIPHER_NONE;
  2045. bss->wpa_pairwise = WPA_CIPHER_NONE;
  2046. bss->rsn_pairwise = WPA_CIPHER_NONE;
  2047. }
  2048. }
  2049. if (hostapd_config_check(conf))
  2050. errors++;
  2051. #ifndef WPA_IGNORE_CONFIG_ERRORS
  2052. if (errors) {
  2053. wpa_printf(MSG_ERROR, "%d errors found in configuration file "
  2054. "'%s'", errors, fname);
  2055. hostapd_config_free(conf);
  2056. conf = NULL;
  2057. }
  2058. #endif /* WPA_IGNORE_CONFIG_ERRORS */
  2059. return conf;
  2060. }