config_file.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045
  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 "includes.h"
  15. #ifndef CONFIG_NATIVE_WINDOWS
  16. #include <grp.h>
  17. #endif /* CONFIG_NATIVE_WINDOWS */
  18. #include "common.h"
  19. #include "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 "wpa.h"
  25. #include "config.h"
  26. extern struct wpa_driver_ops *wpa_drivers[];
  27. #ifndef CONFIG_NO_VLAN
  28. static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
  29. const char *fname)
  30. {
  31. FILE *f;
  32. char buf[128], *pos, *pos2;
  33. int line = 0, vlan_id;
  34. struct hostapd_vlan *vlan;
  35. f = fopen(fname, "r");
  36. if (!f) {
  37. wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname);
  38. return -1;
  39. }
  40. while (fgets(buf, sizeof(buf), f)) {
  41. line++;
  42. if (buf[0] == '#')
  43. continue;
  44. pos = buf;
  45. while (*pos != '\0') {
  46. if (*pos == '\n') {
  47. *pos = '\0';
  48. break;
  49. }
  50. pos++;
  51. }
  52. if (buf[0] == '\0')
  53. continue;
  54. if (buf[0] == '*') {
  55. vlan_id = VLAN_ID_WILDCARD;
  56. pos = buf + 1;
  57. } else {
  58. vlan_id = strtol(buf, &pos, 10);
  59. if (buf == pos || vlan_id < 1 ||
  60. vlan_id > MAX_VLAN_ID) {
  61. wpa_printf(MSG_ERROR, "Invalid VLAN ID at "
  62. "line %d in '%s'", line, fname);
  63. fclose(f);
  64. return -1;
  65. }
  66. }
  67. while (*pos == ' ' || *pos == '\t')
  68. pos++;
  69. pos2 = pos;
  70. while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
  71. pos2++;
  72. *pos2 = '\0';
  73. if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
  74. wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d "
  75. "in '%s'", line, fname);
  76. fclose(f);
  77. return -1;
  78. }
  79. vlan = os_malloc(sizeof(*vlan));
  80. if (vlan == NULL) {
  81. wpa_printf(MSG_ERROR, "Out of memory while reading "
  82. "VLAN interfaces from '%s'", fname);
  83. fclose(f);
  84. return -1;
  85. }
  86. os_memset(vlan, 0, sizeof(*vlan));
  87. vlan->vlan_id = vlan_id;
  88. os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
  89. if (bss->vlan_tail)
  90. bss->vlan_tail->next = vlan;
  91. else
  92. bss->vlan = vlan;
  93. bss->vlan_tail = vlan;
  94. }
  95. fclose(f);
  96. return 0;
  97. }
  98. #endif /* CONFIG_NO_VLAN */
  99. static int hostapd_acl_comp(const void *a, const void *b)
  100. {
  101. const struct mac_acl_entry *aa = a;
  102. const struct mac_acl_entry *bb = b;
  103. return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
  104. }
  105. static int hostapd_config_read_maclist(const char *fname,
  106. struct mac_acl_entry **acl, int *num)
  107. {
  108. FILE *f;
  109. char buf[128], *pos;
  110. int line = 0;
  111. u8 addr[ETH_ALEN];
  112. struct mac_acl_entry *newacl;
  113. int vlan_id;
  114. if (!fname)
  115. return 0;
  116. f = fopen(fname, "r");
  117. if (!f) {
  118. wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
  119. return -1;
  120. }
  121. while (fgets(buf, sizeof(buf), f)) {
  122. line++;
  123. if (buf[0] == '#')
  124. continue;
  125. pos = buf;
  126. while (*pos != '\0') {
  127. if (*pos == '\n') {
  128. *pos = '\0';
  129. break;
  130. }
  131. pos++;
  132. }
  133. if (buf[0] == '\0')
  134. continue;
  135. if (hwaddr_aton(buf, addr)) {
  136. wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
  137. "line %d in '%s'", buf, line, fname);
  138. fclose(f);
  139. return -1;
  140. }
  141. vlan_id = 0;
  142. pos = buf;
  143. while (*pos != '\0' && *pos != ' ' && *pos != '\t')
  144. pos++;
  145. while (*pos == ' ' || *pos == '\t')
  146. pos++;
  147. if (*pos != '\0')
  148. vlan_id = atoi(pos);
  149. newacl = os_realloc(*acl, (*num + 1) * sizeof(**acl));
  150. if (newacl == NULL) {
  151. wpa_printf(MSG_ERROR, "MAC list reallocation failed");
  152. fclose(f);
  153. return -1;
  154. }
  155. *acl = newacl;
  156. os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
  157. (*acl)[*num].vlan_id = vlan_id;
  158. (*num)++;
  159. }
  160. fclose(f);
  161. qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
  162. return 0;
  163. }
  164. #ifdef EAP_SERVER
  165. static int hostapd_config_read_eap_user(const char *fname,
  166. struct hostapd_bss_config *conf)
  167. {
  168. FILE *f;
  169. char buf[512], *pos, *start, *pos2;
  170. int line = 0, ret = 0, num_methods;
  171. struct hostapd_eap_user *user, *tail = NULL;
  172. if (!fname)
  173. return 0;
  174. f = fopen(fname, "r");
  175. if (!f) {
  176. wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
  177. return -1;
  178. }
  179. /* Lines: "user" METHOD,METHOD2 "password" (password optional) */
  180. while (fgets(buf, sizeof(buf), f)) {
  181. line++;
  182. if (buf[0] == '#')
  183. continue;
  184. pos = buf;
  185. while (*pos != '\0') {
  186. if (*pos == '\n') {
  187. *pos = '\0';
  188. break;
  189. }
  190. pos++;
  191. }
  192. if (buf[0] == '\0')
  193. continue;
  194. user = NULL;
  195. if (buf[0] != '"' && buf[0] != '*') {
  196. wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
  197. "start) on line %d in '%s'", line, fname);
  198. goto failed;
  199. }
  200. user = os_zalloc(sizeof(*user));
  201. if (user == NULL) {
  202. wpa_printf(MSG_ERROR, "EAP user allocation failed");
  203. goto failed;
  204. }
  205. user->force_version = -1;
  206. if (buf[0] == '*') {
  207. pos = buf;
  208. } else {
  209. pos = buf + 1;
  210. start = pos;
  211. while (*pos != '"' && *pos != '\0')
  212. pos++;
  213. if (*pos == '\0') {
  214. wpa_printf(MSG_ERROR, "Invalid EAP identity "
  215. "(no \" in end) on line %d in '%s'",
  216. line, fname);
  217. goto failed;
  218. }
  219. user->identity = os_malloc(pos - start);
  220. if (user->identity == NULL) {
  221. wpa_printf(MSG_ERROR, "Failed to allocate "
  222. "memory for EAP identity");
  223. goto failed;
  224. }
  225. os_memcpy(user->identity, start, pos - start);
  226. user->identity_len = pos - start;
  227. if (pos[0] == '"' && pos[1] == '*') {
  228. user->wildcard_prefix = 1;
  229. pos++;
  230. }
  231. }
  232. pos++;
  233. while (*pos == ' ' || *pos == '\t')
  234. pos++;
  235. if (*pos == '\0') {
  236. wpa_printf(MSG_ERROR, "No EAP method on line %d in "
  237. "'%s'", line, fname);
  238. goto failed;
  239. }
  240. start = pos;
  241. while (*pos != ' ' && *pos != '\t' && *pos != '\0')
  242. pos++;
  243. if (*pos == '\0') {
  244. pos = NULL;
  245. } else {
  246. *pos = '\0';
  247. pos++;
  248. }
  249. num_methods = 0;
  250. while (*start) {
  251. char *pos3 = os_strchr(start, ',');
  252. if (pos3) {
  253. *pos3++ = '\0';
  254. }
  255. user->methods[num_methods].method =
  256. eap_server_get_type(
  257. start,
  258. &user->methods[num_methods].vendor);
  259. if (user->methods[num_methods].vendor ==
  260. EAP_VENDOR_IETF &&
  261. user->methods[num_methods].method == EAP_TYPE_NONE)
  262. {
  263. if (os_strcmp(start, "TTLS-PAP") == 0) {
  264. user->ttls_auth |= EAP_TTLS_AUTH_PAP;
  265. goto skip_eap;
  266. }
  267. if (os_strcmp(start, "TTLS-CHAP") == 0) {
  268. user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
  269. goto skip_eap;
  270. }
  271. if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
  272. user->ttls_auth |=
  273. EAP_TTLS_AUTH_MSCHAP;
  274. goto skip_eap;
  275. }
  276. if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
  277. user->ttls_auth |=
  278. EAP_TTLS_AUTH_MSCHAPV2;
  279. goto skip_eap;
  280. }
  281. wpa_printf(MSG_ERROR, "Unsupported EAP type "
  282. "'%s' on line %d in '%s'",
  283. start, line, fname);
  284. goto failed;
  285. }
  286. num_methods++;
  287. if (num_methods >= EAP_USER_MAX_METHODS)
  288. break;
  289. skip_eap:
  290. if (pos3 == NULL)
  291. break;
  292. start = pos3;
  293. }
  294. if (num_methods == 0 && user->ttls_auth == 0) {
  295. wpa_printf(MSG_ERROR, "No EAP types configured on "
  296. "line %d in '%s'", line, fname);
  297. goto failed;
  298. }
  299. if (pos == NULL)
  300. goto done;
  301. while (*pos == ' ' || *pos == '\t')
  302. pos++;
  303. if (*pos == '\0')
  304. goto done;
  305. if (os_strncmp(pos, "[ver=0]", 7) == 0) {
  306. user->force_version = 0;
  307. goto done;
  308. }
  309. if (os_strncmp(pos, "[ver=1]", 7) == 0) {
  310. user->force_version = 1;
  311. goto done;
  312. }
  313. if (os_strncmp(pos, "[2]", 3) == 0) {
  314. user->phase2 = 1;
  315. goto done;
  316. }
  317. if (*pos == '"') {
  318. pos++;
  319. start = pos;
  320. while (*pos != '"' && *pos != '\0')
  321. pos++;
  322. if (*pos == '\0') {
  323. wpa_printf(MSG_ERROR, "Invalid EAP password "
  324. "(no \" in end) on line %d in '%s'",
  325. line, fname);
  326. goto failed;
  327. }
  328. user->password = os_malloc(pos - start);
  329. if (user->password == NULL) {
  330. wpa_printf(MSG_ERROR, "Failed to allocate "
  331. "memory for EAP password");
  332. goto failed;
  333. }
  334. os_memcpy(user->password, start, pos - start);
  335. user->password_len = pos - start;
  336. pos++;
  337. } else if (os_strncmp(pos, "hash:", 5) == 0) {
  338. pos += 5;
  339. pos2 = pos;
  340. while (*pos2 != '\0' && *pos2 != ' ' &&
  341. *pos2 != '\t' && *pos2 != '#')
  342. pos2++;
  343. if (pos2 - pos != 32) {
  344. wpa_printf(MSG_ERROR, "Invalid password hash "
  345. "on line %d in '%s'", line, fname);
  346. goto failed;
  347. }
  348. user->password = os_malloc(16);
  349. if (user->password == NULL) {
  350. wpa_printf(MSG_ERROR, "Failed to allocate "
  351. "memory for EAP password hash");
  352. goto failed;
  353. }
  354. if (hexstr2bin(pos, user->password, 16) < 0) {
  355. wpa_printf(MSG_ERROR, "Invalid hash password "
  356. "on line %d in '%s'", line, fname);
  357. goto failed;
  358. }
  359. user->password_len = 16;
  360. user->password_hash = 1;
  361. pos = pos2;
  362. } else {
  363. pos2 = pos;
  364. while (*pos2 != '\0' && *pos2 != ' ' &&
  365. *pos2 != '\t' && *pos2 != '#')
  366. pos2++;
  367. if ((pos2 - pos) & 1) {
  368. wpa_printf(MSG_ERROR, "Invalid hex password "
  369. "on line %d in '%s'", line, fname);
  370. goto failed;
  371. }
  372. user->password = os_malloc((pos2 - pos) / 2);
  373. if (user->password == NULL) {
  374. wpa_printf(MSG_ERROR, "Failed to allocate "
  375. "memory for EAP password");
  376. goto failed;
  377. }
  378. if (hexstr2bin(pos, user->password,
  379. (pos2 - pos) / 2) < 0) {
  380. wpa_printf(MSG_ERROR, "Invalid hex password "
  381. "on line %d in '%s'", line, fname);
  382. goto failed;
  383. }
  384. user->password_len = (pos2 - pos) / 2;
  385. pos = pos2;
  386. }
  387. while (*pos == ' ' || *pos == '\t')
  388. pos++;
  389. if (os_strncmp(pos, "[2]", 3) == 0) {
  390. user->phase2 = 1;
  391. }
  392. done:
  393. if (tail == NULL) {
  394. tail = conf->eap_user = user;
  395. } else {
  396. tail->next = user;
  397. tail = user;
  398. }
  399. continue;
  400. failed:
  401. if (user) {
  402. os_free(user->password);
  403. os_free(user->identity);
  404. os_free(user);
  405. }
  406. ret = -1;
  407. break;
  408. }
  409. fclose(f);
  410. return ret;
  411. }
  412. #endif /* EAP_SERVER */
  413. #ifndef CONFIG_NO_RADIUS
  414. static int
  415. hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
  416. int *num_server, const char *val, int def_port,
  417. struct hostapd_radius_server **curr_serv)
  418. {
  419. struct hostapd_radius_server *nserv;
  420. int ret;
  421. static int server_index = 1;
  422. nserv = os_realloc(*server, (*num_server + 1) * sizeof(*nserv));
  423. if (nserv == NULL)
  424. return -1;
  425. *server = nserv;
  426. nserv = &nserv[*num_server];
  427. (*num_server)++;
  428. (*curr_serv) = nserv;
  429. os_memset(nserv, 0, sizeof(*nserv));
  430. nserv->port = def_port;
  431. ret = hostapd_parse_ip_addr(val, &nserv->addr);
  432. nserv->index = server_index++;
  433. return ret;
  434. }
  435. #endif /* CONFIG_NO_RADIUS */
  436. static int hostapd_config_parse_key_mgmt(int line, const char *value)
  437. {
  438. int val = 0, last;
  439. char *start, *end, *buf;
  440. buf = os_strdup(value);
  441. if (buf == NULL)
  442. return -1;
  443. start = buf;
  444. while (*start != '\0') {
  445. while (*start == ' ' || *start == '\t')
  446. start++;
  447. if (*start == '\0')
  448. break;
  449. end = start;
  450. while (*end != ' ' && *end != '\t' && *end != '\0')
  451. end++;
  452. last = *end == '\0';
  453. *end = '\0';
  454. if (os_strcmp(start, "WPA-PSK") == 0)
  455. val |= WPA_KEY_MGMT_PSK;
  456. else if (os_strcmp(start, "WPA-EAP") == 0)
  457. val |= WPA_KEY_MGMT_IEEE8021X;
  458. #ifdef CONFIG_IEEE80211R
  459. else if (os_strcmp(start, "FT-PSK") == 0)
  460. val |= WPA_KEY_MGMT_FT_PSK;
  461. else if (os_strcmp(start, "FT-EAP") == 0)
  462. val |= WPA_KEY_MGMT_FT_IEEE8021X;
  463. #endif /* CONFIG_IEEE80211R */
  464. #ifdef CONFIG_IEEE80211W
  465. else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
  466. val |= WPA_KEY_MGMT_PSK_SHA256;
  467. else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
  468. val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
  469. #endif /* CONFIG_IEEE80211W */
  470. else {
  471. wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
  472. line, start);
  473. os_free(buf);
  474. return -1;
  475. }
  476. if (last)
  477. break;
  478. start = end + 1;
  479. }
  480. os_free(buf);
  481. if (val == 0) {
  482. wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
  483. "configured.", line);
  484. return -1;
  485. }
  486. return val;
  487. }
  488. static int hostapd_config_parse_cipher(int line, const char *value)
  489. {
  490. int val = 0, last;
  491. char *start, *end, *buf;
  492. buf = os_strdup(value);
  493. if (buf == NULL)
  494. return -1;
  495. start = buf;
  496. while (*start != '\0') {
  497. while (*start == ' ' || *start == '\t')
  498. start++;
  499. if (*start == '\0')
  500. break;
  501. end = start;
  502. while (*end != ' ' && *end != '\t' && *end != '\0')
  503. end++;
  504. last = *end == '\0';
  505. *end = '\0';
  506. if (os_strcmp(start, "CCMP") == 0)
  507. val |= WPA_CIPHER_CCMP;
  508. else if (os_strcmp(start, "TKIP") == 0)
  509. val |= WPA_CIPHER_TKIP;
  510. else if (os_strcmp(start, "WEP104") == 0)
  511. val |= WPA_CIPHER_WEP104;
  512. else if (os_strcmp(start, "WEP40") == 0)
  513. val |= WPA_CIPHER_WEP40;
  514. else if (os_strcmp(start, "NONE") == 0)
  515. val |= WPA_CIPHER_NONE;
  516. else {
  517. wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
  518. line, start);
  519. os_free(buf);
  520. return -1;
  521. }
  522. if (last)
  523. break;
  524. start = end + 1;
  525. }
  526. os_free(buf);
  527. if (val == 0) {
  528. wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
  529. line);
  530. return -1;
  531. }
  532. return val;
  533. }
  534. static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
  535. char *val)
  536. {
  537. size_t len = os_strlen(val);
  538. if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
  539. return -1;
  540. if (val[0] == '"') {
  541. if (len < 2 || val[len - 1] != '"')
  542. return -1;
  543. len -= 2;
  544. wep->key[keyidx] = os_malloc(len);
  545. if (wep->key[keyidx] == NULL)
  546. return -1;
  547. os_memcpy(wep->key[keyidx], val + 1, len);
  548. wep->len[keyidx] = len;
  549. } else {
  550. if (len & 1)
  551. return -1;
  552. len /= 2;
  553. wep->key[keyidx] = os_malloc(len);
  554. if (wep->key[keyidx] == NULL)
  555. return -1;
  556. wep->len[keyidx] = len;
  557. if (hexstr2bin(val, wep->key[keyidx], len) < 0)
  558. return -1;
  559. }
  560. wep->keys_set++;
  561. return 0;
  562. }
  563. static int hostapd_parse_rates(int **rate_list, char *val)
  564. {
  565. int *list;
  566. int count;
  567. char *pos, *end;
  568. os_free(*rate_list);
  569. *rate_list = NULL;
  570. pos = val;
  571. count = 0;
  572. while (*pos != '\0') {
  573. if (*pos == ' ')
  574. count++;
  575. pos++;
  576. }
  577. list = os_malloc(sizeof(int) * (count + 2));
  578. if (list == NULL)
  579. return -1;
  580. pos = val;
  581. count = 0;
  582. while (*pos != '\0') {
  583. end = os_strchr(pos, ' ');
  584. if (end)
  585. *end = '\0';
  586. list[count++] = atoi(pos);
  587. if (!end)
  588. break;
  589. pos = end + 1;
  590. }
  591. list[count] = -1;
  592. *rate_list = list;
  593. return 0;
  594. }
  595. static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
  596. {
  597. struct hostapd_bss_config *bss;
  598. if (*ifname == '\0')
  599. return -1;
  600. bss = os_realloc(conf->bss, (conf->num_bss + 1) *
  601. sizeof(struct hostapd_bss_config));
  602. if (bss == NULL) {
  603. wpa_printf(MSG_ERROR, "Failed to allocate memory for "
  604. "multi-BSS entry");
  605. return -1;
  606. }
  607. conf->bss = bss;
  608. bss = &(conf->bss[conf->num_bss]);
  609. os_memset(bss, 0, sizeof(*bss));
  610. bss->radius = os_zalloc(sizeof(*bss->radius));
  611. if (bss->radius == NULL) {
  612. wpa_printf(MSG_ERROR, "Failed to allocate memory for "
  613. "multi-BSS RADIUS data");
  614. return -1;
  615. }
  616. conf->num_bss++;
  617. conf->last_bss = bss;
  618. hostapd_config_defaults_bss(bss);
  619. os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
  620. os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
  621. return 0;
  622. }
  623. /* convert floats with one decimal place to value*10 int, i.e.,
  624. * "1.5" will return 15 */
  625. static int hostapd_config_read_int10(const char *value)
  626. {
  627. int i, d;
  628. char *pos;
  629. i = atoi(value);
  630. pos = os_strchr(value, '.');
  631. d = 0;
  632. if (pos) {
  633. pos++;
  634. if (*pos >= '0' && *pos <= '9')
  635. d = *pos - '0';
  636. }
  637. return i * 10 + d;
  638. }
  639. static int valid_cw(int cw)
  640. {
  641. return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
  642. cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
  643. }
  644. enum {
  645. IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
  646. IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
  647. IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
  648. IEEE80211_TX_QUEUE_DATA3 = 3, /* used for EDCA AC_BK data */
  649. IEEE80211_TX_QUEUE_DATA4 = 4,
  650. IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
  651. IEEE80211_TX_QUEUE_BEACON = 7
  652. };
  653. static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
  654. char *val)
  655. {
  656. int num;
  657. char *pos;
  658. struct hostapd_tx_queue_params *queue;
  659. /* skip 'tx_queue_' prefix */
  660. pos = name + 9;
  661. if (os_strncmp(pos, "data", 4) == 0 &&
  662. pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
  663. num = pos[4] - '0';
  664. pos += 6;
  665. } else if (os_strncmp(pos, "after_beacon_", 13) == 0) {
  666. num = IEEE80211_TX_QUEUE_AFTER_BEACON;
  667. pos += 13;
  668. } else if (os_strncmp(pos, "beacon_", 7) == 0) {
  669. num = IEEE80211_TX_QUEUE_BEACON;
  670. pos += 7;
  671. } else {
  672. wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
  673. return -1;
  674. }
  675. queue = &conf->tx_queue[num];
  676. if (os_strcmp(pos, "aifs") == 0) {
  677. queue->aifs = atoi(val);
  678. if (queue->aifs < 0 || queue->aifs > 255) {
  679. wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
  680. queue->aifs);
  681. return -1;
  682. }
  683. } else if (os_strcmp(pos, "cwmin") == 0) {
  684. queue->cwmin = atoi(val);
  685. if (!valid_cw(queue->cwmin)) {
  686. wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
  687. queue->cwmin);
  688. return -1;
  689. }
  690. } else if (os_strcmp(pos, "cwmax") == 0) {
  691. queue->cwmax = atoi(val);
  692. if (!valid_cw(queue->cwmax)) {
  693. wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
  694. queue->cwmax);
  695. return -1;
  696. }
  697. } else if (os_strcmp(pos, "burst") == 0) {
  698. queue->burst = hostapd_config_read_int10(val);
  699. } else {
  700. wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
  701. return -1;
  702. }
  703. queue->configured = 1;
  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 ((bss->wpa_key_mgmt &
  936. (WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X)) &&
  937. (bss->nas_identifier == NULL ||
  938. os_strlen(bss->nas_identifier) < 1 ||
  939. os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
  940. wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
  941. "nas_identifier to be configured as a 1..48 octet "
  942. "string");
  943. return -1;
  944. }
  945. #endif /* CONFIG_IEEE80211R */
  946. #ifdef CONFIG_IEEE80211N
  947. if (conf->ieee80211n && bss->wpa &&
  948. !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
  949. !(bss->rsn_pairwise & WPA_CIPHER_CCMP)) {
  950. wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
  951. "requires CCMP to be enabled");
  952. return -1;
  953. }
  954. #endif /* CONFIG_IEEE80211N */
  955. return 0;
  956. }
  957. static int hostapd_config_check(struct hostapd_config *conf)
  958. {
  959. size_t i;
  960. if (conf->ieee80211d && (!conf->country[0] || !conf->country[1])) {
  961. wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
  962. "setting the country_code");
  963. return -1;
  964. }
  965. for (i = 0; i < conf->num_bss; i++) {
  966. if (hostapd_config_check_bss(&conf->bss[i], conf))
  967. return -1;
  968. }
  969. return 0;
  970. }
  971. /**
  972. * hostapd_config_read - Read and parse a configuration file
  973. * @fname: Configuration file name (including path, if needed)
  974. * Returns: Allocated configuration data structure
  975. */
  976. struct hostapd_config * hostapd_config_read(const char *fname)
  977. {
  978. struct hostapd_config *conf;
  979. struct hostapd_bss_config *bss;
  980. FILE *f;
  981. char buf[256], *pos;
  982. int line = 0;
  983. int errors = 0;
  984. int pairwise;
  985. size_t i;
  986. f = fopen(fname, "r");
  987. if (f == NULL) {
  988. wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
  989. "for reading.", fname);
  990. return NULL;
  991. }
  992. conf = hostapd_config_defaults();
  993. if (conf == NULL) {
  994. fclose(f);
  995. return NULL;
  996. }
  997. /* set default driver based on configuration */
  998. conf->driver = wpa_drivers[0];
  999. if (conf->driver == NULL) {
  1000. wpa_printf(MSG_ERROR, "No driver wrappers registered!");
  1001. hostapd_config_free(conf);
  1002. return NULL;
  1003. }
  1004. bss = conf->last_bss = conf->bss;
  1005. while (fgets(buf, sizeof(buf), f)) {
  1006. bss = conf->last_bss;
  1007. line++;
  1008. if (buf[0] == '#')
  1009. continue;
  1010. pos = buf;
  1011. while (*pos != '\0') {
  1012. if (*pos == '\n') {
  1013. *pos = '\0';
  1014. break;
  1015. }
  1016. pos++;
  1017. }
  1018. if (buf[0] == '\0')
  1019. continue;
  1020. pos = os_strchr(buf, '=');
  1021. if (pos == NULL) {
  1022. wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
  1023. line, buf);
  1024. errors++;
  1025. continue;
  1026. }
  1027. *pos = '\0';
  1028. pos++;
  1029. if (os_strcmp(buf, "interface") == 0) {
  1030. os_strlcpy(conf->bss[0].iface, pos,
  1031. sizeof(conf->bss[0].iface));
  1032. } else if (os_strcmp(buf, "bridge") == 0) {
  1033. os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
  1034. } else if (os_strcmp(buf, "driver") == 0) {
  1035. int j;
  1036. /* clear to get error below if setting is invalid */
  1037. conf->driver = NULL;
  1038. for (j = 0; wpa_drivers[j]; j++) {
  1039. if (os_strcmp(pos, wpa_drivers[j]->name) == 0)
  1040. {
  1041. conf->driver = wpa_drivers[j];
  1042. break;
  1043. }
  1044. }
  1045. if (conf->driver == NULL) {
  1046. wpa_printf(MSG_ERROR, "Line %d: invalid/"
  1047. "unknown driver '%s'", line, pos);
  1048. errors++;
  1049. }
  1050. } else if (os_strcmp(buf, "debug") == 0) {
  1051. wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
  1052. "configuration variable is not used "
  1053. "anymore", line);
  1054. } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
  1055. bss->logger_syslog_level = atoi(pos);
  1056. } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
  1057. bss->logger_stdout_level = atoi(pos);
  1058. } else if (os_strcmp(buf, "logger_syslog") == 0) {
  1059. bss->logger_syslog = atoi(pos);
  1060. } else if (os_strcmp(buf, "logger_stdout") == 0) {
  1061. bss->logger_stdout = atoi(pos);
  1062. } else if (os_strcmp(buf, "dump_file") == 0) {
  1063. bss->dump_log_name = os_strdup(pos);
  1064. } else if (os_strcmp(buf, "ssid") == 0) {
  1065. bss->ssid.ssid_len = os_strlen(pos);
  1066. if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
  1067. bss->ssid.ssid_len < 1) {
  1068. wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
  1069. "'%s'", line, pos);
  1070. errors++;
  1071. } else {
  1072. os_memcpy(bss->ssid.ssid, pos,
  1073. bss->ssid.ssid_len);
  1074. bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
  1075. bss->ssid.ssid_set = 1;
  1076. }
  1077. } else if (os_strcmp(buf, "macaddr_acl") == 0) {
  1078. bss->macaddr_acl = atoi(pos);
  1079. if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
  1080. bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
  1081. bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
  1082. wpa_printf(MSG_ERROR, "Line %d: unknown "
  1083. "macaddr_acl %d",
  1084. line, bss->macaddr_acl);
  1085. }
  1086. } else if (os_strcmp(buf, "accept_mac_file") == 0) {
  1087. if (hostapd_config_read_maclist(pos, &bss->accept_mac,
  1088. &bss->num_accept_mac))
  1089. {
  1090. wpa_printf(MSG_ERROR, "Line %d: Failed to "
  1091. "read accept_mac_file '%s'",
  1092. line, pos);
  1093. errors++;
  1094. }
  1095. } else if (os_strcmp(buf, "deny_mac_file") == 0) {
  1096. if (hostapd_config_read_maclist(pos, &bss->deny_mac,
  1097. &bss->num_deny_mac)) {
  1098. wpa_printf(MSG_ERROR, "Line %d: Failed to "
  1099. "read deny_mac_file '%s'",
  1100. line, pos);
  1101. errors++;
  1102. }
  1103. } else if (os_strcmp(buf, "wds_sta") == 0) {
  1104. bss->wds_sta = atoi(pos);
  1105. } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
  1106. bss->ap_max_inactivity = atoi(pos);
  1107. } else if (os_strcmp(buf, "country_code") == 0) {
  1108. os_memcpy(conf->country, pos, 2);
  1109. /* FIX: make this configurable */
  1110. conf->country[2] = ' ';
  1111. } else if (os_strcmp(buf, "ieee80211d") == 0) {
  1112. conf->ieee80211d = atoi(pos);
  1113. } else if (os_strcmp(buf, "ieee8021x") == 0) {
  1114. bss->ieee802_1x = atoi(pos);
  1115. } else if (os_strcmp(buf, "eapol_version") == 0) {
  1116. bss->eapol_version = atoi(pos);
  1117. if (bss->eapol_version < 1 ||
  1118. bss->eapol_version > 2) {
  1119. wpa_printf(MSG_ERROR, "Line %d: invalid EAPOL "
  1120. "version (%d): '%s'.",
  1121. line, bss->eapol_version, pos);
  1122. errors++;
  1123. } else
  1124. wpa_printf(MSG_DEBUG, "eapol_version=%d",
  1125. bss->eapol_version);
  1126. #ifdef EAP_SERVER
  1127. } else if (os_strcmp(buf, "eap_authenticator") == 0) {
  1128. bss->eap_server = atoi(pos);
  1129. wpa_printf(MSG_ERROR, "Line %d: obsolete "
  1130. "eap_authenticator used; this has been "
  1131. "renamed to eap_server", line);
  1132. } else if (os_strcmp(buf, "eap_server") == 0) {
  1133. bss->eap_server = atoi(pos);
  1134. } else if (os_strcmp(buf, "eap_user_file") == 0) {
  1135. if (hostapd_config_read_eap_user(pos, bss))
  1136. errors++;
  1137. } else if (os_strcmp(buf, "ca_cert") == 0) {
  1138. os_free(bss->ca_cert);
  1139. bss->ca_cert = os_strdup(pos);
  1140. } else if (os_strcmp(buf, "server_cert") == 0) {
  1141. os_free(bss->server_cert);
  1142. bss->server_cert = os_strdup(pos);
  1143. } else if (os_strcmp(buf, "private_key") == 0) {
  1144. os_free(bss->private_key);
  1145. bss->private_key = os_strdup(pos);
  1146. } else if (os_strcmp(buf, "private_key_passwd") == 0) {
  1147. os_free(bss->private_key_passwd);
  1148. bss->private_key_passwd = os_strdup(pos);
  1149. } else if (os_strcmp(buf, "check_crl") == 0) {
  1150. bss->check_crl = atoi(pos);
  1151. } else if (os_strcmp(buf, "dh_file") == 0) {
  1152. os_free(bss->dh_file);
  1153. bss->dh_file = os_strdup(pos);
  1154. #ifdef EAP_SERVER_FAST
  1155. } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
  1156. os_free(bss->pac_opaque_encr_key);
  1157. bss->pac_opaque_encr_key = os_malloc(16);
  1158. if (bss->pac_opaque_encr_key == NULL) {
  1159. wpa_printf(MSG_ERROR, "Line %d: No memory for "
  1160. "pac_opaque_encr_key", line);
  1161. errors++;
  1162. } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
  1163. 16)) {
  1164. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1165. "pac_opaque_encr_key", line);
  1166. errors++;
  1167. }
  1168. } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
  1169. size_t idlen = os_strlen(pos);
  1170. if (idlen & 1) {
  1171. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1172. "eap_fast_a_id", line);
  1173. errors++;
  1174. } else {
  1175. os_free(bss->eap_fast_a_id);
  1176. bss->eap_fast_a_id = os_malloc(idlen / 2);
  1177. if (bss->eap_fast_a_id == NULL ||
  1178. hexstr2bin(pos, bss->eap_fast_a_id,
  1179. idlen / 2)) {
  1180. wpa_printf(MSG_ERROR, "Line %d: "
  1181. "Failed to parse "
  1182. "eap_fast_a_id", line);
  1183. errors++;
  1184. } else
  1185. bss->eap_fast_a_id_len = idlen / 2;
  1186. }
  1187. } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
  1188. os_free(bss->eap_fast_a_id_info);
  1189. bss->eap_fast_a_id_info = os_strdup(pos);
  1190. } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
  1191. bss->eap_fast_prov = atoi(pos);
  1192. } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
  1193. bss->pac_key_lifetime = atoi(pos);
  1194. } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
  1195. bss->pac_key_refresh_time = atoi(pos);
  1196. #endif /* EAP_SERVER_FAST */
  1197. #ifdef EAP_SERVER_SIM
  1198. } else if (os_strcmp(buf, "eap_sim_db") == 0) {
  1199. os_free(bss->eap_sim_db);
  1200. bss->eap_sim_db = os_strdup(pos);
  1201. } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
  1202. bss->eap_sim_aka_result_ind = atoi(pos);
  1203. #endif /* EAP_SERVER_SIM */
  1204. #ifdef EAP_SERVER_TNC
  1205. } else if (os_strcmp(buf, "tnc") == 0) {
  1206. bss->tnc = atoi(pos);
  1207. #endif /* EAP_SERVER_TNC */
  1208. #endif /* EAP_SERVER */
  1209. } else if (os_strcmp(buf, "eap_message") == 0) {
  1210. char *term;
  1211. bss->eap_req_id_text = os_strdup(pos);
  1212. if (bss->eap_req_id_text == NULL) {
  1213. wpa_printf(MSG_ERROR, "Line %d: Failed to "
  1214. "allocate memory for "
  1215. "eap_req_id_text", line);
  1216. errors++;
  1217. continue;
  1218. }
  1219. bss->eap_req_id_text_len =
  1220. os_strlen(bss->eap_req_id_text);
  1221. term = os_strstr(bss->eap_req_id_text, "\\0");
  1222. if (term) {
  1223. *term++ = '\0';
  1224. os_memmove(term, term + 1,
  1225. bss->eap_req_id_text_len -
  1226. (term - bss->eap_req_id_text) - 1);
  1227. bss->eap_req_id_text_len--;
  1228. }
  1229. } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
  1230. bss->default_wep_key_len = atoi(pos);
  1231. if (bss->default_wep_key_len > 13) {
  1232. wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
  1233. "key len %lu (= %lu bits)", line,
  1234. (unsigned long)
  1235. bss->default_wep_key_len,
  1236. (unsigned long)
  1237. bss->default_wep_key_len * 8);
  1238. errors++;
  1239. }
  1240. } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
  1241. bss->individual_wep_key_len = atoi(pos);
  1242. if (bss->individual_wep_key_len < 0 ||
  1243. bss->individual_wep_key_len > 13) {
  1244. wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
  1245. "key len %d (= %d bits)", line,
  1246. bss->individual_wep_key_len,
  1247. bss->individual_wep_key_len * 8);
  1248. errors++;
  1249. }
  1250. } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
  1251. bss->wep_rekeying_period = atoi(pos);
  1252. if (bss->wep_rekeying_period < 0) {
  1253. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1254. "period %d",
  1255. line, bss->wep_rekeying_period);
  1256. errors++;
  1257. }
  1258. } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
  1259. bss->eap_reauth_period = atoi(pos);
  1260. if (bss->eap_reauth_period < 0) {
  1261. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1262. "period %d",
  1263. line, bss->eap_reauth_period);
  1264. errors++;
  1265. }
  1266. } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
  1267. bss->eapol_key_index_workaround = atoi(pos);
  1268. #ifdef CONFIG_IAPP
  1269. } else if (os_strcmp(buf, "iapp_interface") == 0) {
  1270. bss->ieee802_11f = 1;
  1271. os_strlcpy(bss->iapp_iface, pos,
  1272. sizeof(bss->iapp_iface));
  1273. #endif /* CONFIG_IAPP */
  1274. } else if (os_strcmp(buf, "own_ip_addr") == 0) {
  1275. if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
  1276. wpa_printf(MSG_ERROR, "Line %d: invalid IP "
  1277. "address '%s'", line, pos);
  1278. errors++;
  1279. }
  1280. } else if (os_strcmp(buf, "nas_identifier") == 0) {
  1281. bss->nas_identifier = os_strdup(pos);
  1282. #ifndef CONFIG_NO_RADIUS
  1283. } else if (os_strcmp(buf, "auth_server_addr") == 0) {
  1284. if (hostapd_config_read_radius_addr(
  1285. &bss->radius->auth_servers,
  1286. &bss->radius->num_auth_servers, pos, 1812,
  1287. &bss->radius->auth_server)) {
  1288. wpa_printf(MSG_ERROR, "Line %d: invalid IP "
  1289. "address '%s'", line, pos);
  1290. errors++;
  1291. }
  1292. } else if (bss->radius->auth_server &&
  1293. os_strcmp(buf, "auth_server_port") == 0) {
  1294. bss->radius->auth_server->port = atoi(pos);
  1295. } else if (bss->radius->auth_server &&
  1296. os_strcmp(buf, "auth_server_shared_secret") == 0) {
  1297. int len = os_strlen(pos);
  1298. if (len == 0) {
  1299. /* RFC 2865, Ch. 3 */
  1300. wpa_printf(MSG_ERROR, "Line %d: empty shared "
  1301. "secret is not allowed.", line);
  1302. errors++;
  1303. }
  1304. bss->radius->auth_server->shared_secret =
  1305. (u8 *) os_strdup(pos);
  1306. bss->radius->auth_server->shared_secret_len = len;
  1307. } else if (os_strcmp(buf, "acct_server_addr") == 0) {
  1308. if (hostapd_config_read_radius_addr(
  1309. &bss->radius->acct_servers,
  1310. &bss->radius->num_acct_servers, pos, 1813,
  1311. &bss->radius->acct_server)) {
  1312. wpa_printf(MSG_ERROR, "Line %d: invalid IP "
  1313. "address '%s'", line, pos);
  1314. errors++;
  1315. }
  1316. } else if (bss->radius->acct_server &&
  1317. os_strcmp(buf, "acct_server_port") == 0) {
  1318. bss->radius->acct_server->port = atoi(pos);
  1319. } else if (bss->radius->acct_server &&
  1320. os_strcmp(buf, "acct_server_shared_secret") == 0) {
  1321. int len = os_strlen(pos);
  1322. if (len == 0) {
  1323. /* RFC 2865, Ch. 3 */
  1324. wpa_printf(MSG_ERROR, "Line %d: empty shared "
  1325. "secret is not allowed.", line);
  1326. errors++;
  1327. }
  1328. bss->radius->acct_server->shared_secret =
  1329. (u8 *) os_strdup(pos);
  1330. bss->radius->acct_server->shared_secret_len = len;
  1331. } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
  1332. 0) {
  1333. bss->radius->retry_primary_interval = atoi(pos);
  1334. } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
  1335. {
  1336. bss->acct_interim_interval = atoi(pos);
  1337. #endif /* CONFIG_NO_RADIUS */
  1338. } else if (os_strcmp(buf, "auth_algs") == 0) {
  1339. bss->auth_algs = atoi(pos);
  1340. if (bss->auth_algs == 0) {
  1341. wpa_printf(MSG_ERROR, "Line %d: no "
  1342. "authentication algorithms allowed",
  1343. line);
  1344. errors++;
  1345. }
  1346. } else if (os_strcmp(buf, "max_num_sta") == 0) {
  1347. bss->max_num_sta = atoi(pos);
  1348. if (bss->max_num_sta < 0 ||
  1349. bss->max_num_sta > MAX_STA_COUNT) {
  1350. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1351. "max_num_sta=%d; allowed range "
  1352. "0..%d", line, bss->max_num_sta,
  1353. MAX_STA_COUNT);
  1354. errors++;
  1355. }
  1356. } else if (os_strcmp(buf, "wpa") == 0) {
  1357. bss->wpa = atoi(pos);
  1358. } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
  1359. bss->wpa_group_rekey = atoi(pos);
  1360. } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
  1361. bss->wpa_strict_rekey = atoi(pos);
  1362. } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
  1363. bss->wpa_gmk_rekey = atoi(pos);
  1364. } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
  1365. bss->wpa_ptk_rekey = atoi(pos);
  1366. } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
  1367. int len = os_strlen(pos);
  1368. if (len < 8 || len > 63) {
  1369. wpa_printf(MSG_ERROR, "Line %d: invalid WPA "
  1370. "passphrase length %d (expected "
  1371. "8..63)", line, len);
  1372. errors++;
  1373. } else {
  1374. os_free(bss->ssid.wpa_passphrase);
  1375. bss->ssid.wpa_passphrase = os_strdup(pos);
  1376. }
  1377. } else if (os_strcmp(buf, "wpa_psk") == 0) {
  1378. os_free(bss->ssid.wpa_psk);
  1379. bss->ssid.wpa_psk =
  1380. os_zalloc(sizeof(struct hostapd_wpa_psk));
  1381. if (bss->ssid.wpa_psk == NULL)
  1382. errors++;
  1383. else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
  1384. PMK_LEN) ||
  1385. pos[PMK_LEN * 2] != '\0') {
  1386. wpa_printf(MSG_ERROR, "Line %d: Invalid PSK "
  1387. "'%s'.", line, pos);
  1388. errors++;
  1389. } else {
  1390. bss->ssid.wpa_psk->group = 1;
  1391. }
  1392. } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
  1393. os_free(bss->ssid.wpa_psk_file);
  1394. bss->ssid.wpa_psk_file = os_strdup(pos);
  1395. if (!bss->ssid.wpa_psk_file) {
  1396. wpa_printf(MSG_ERROR, "Line %d: allocation "
  1397. "failed", line);
  1398. errors++;
  1399. }
  1400. } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
  1401. bss->wpa_key_mgmt =
  1402. hostapd_config_parse_key_mgmt(line, pos);
  1403. if (bss->wpa_key_mgmt == -1)
  1404. errors++;
  1405. } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
  1406. bss->wpa_pairwise =
  1407. hostapd_config_parse_cipher(line, pos);
  1408. if (bss->wpa_pairwise == -1 ||
  1409. bss->wpa_pairwise == 0)
  1410. errors++;
  1411. else if (bss->wpa_pairwise &
  1412. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
  1413. WPA_CIPHER_WEP104)) {
  1414. wpa_printf(MSG_ERROR, "Line %d: unsupported "
  1415. "pairwise cipher suite '%s'",
  1416. bss->wpa_pairwise, pos);
  1417. errors++;
  1418. }
  1419. } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
  1420. bss->rsn_pairwise =
  1421. hostapd_config_parse_cipher(line, pos);
  1422. if (bss->rsn_pairwise == -1 ||
  1423. bss->rsn_pairwise == 0)
  1424. errors++;
  1425. else if (bss->rsn_pairwise &
  1426. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
  1427. WPA_CIPHER_WEP104)) {
  1428. wpa_printf(MSG_ERROR, "Line %d: unsupported "
  1429. "pairwise cipher suite '%s'",
  1430. bss->rsn_pairwise, pos);
  1431. errors++;
  1432. }
  1433. #ifdef CONFIG_RSN_PREAUTH
  1434. } else if (os_strcmp(buf, "rsn_preauth") == 0) {
  1435. bss->rsn_preauth = atoi(pos);
  1436. } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
  1437. bss->rsn_preauth_interfaces = os_strdup(pos);
  1438. #endif /* CONFIG_RSN_PREAUTH */
  1439. #ifdef CONFIG_PEERKEY
  1440. } else if (os_strcmp(buf, "peerkey") == 0) {
  1441. bss->peerkey = atoi(pos);
  1442. #endif /* CONFIG_PEERKEY */
  1443. #ifdef CONFIG_IEEE80211R
  1444. } else if (os_strcmp(buf, "mobility_domain") == 0) {
  1445. if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
  1446. hexstr2bin(pos, bss->mobility_domain,
  1447. MOBILITY_DOMAIN_ID_LEN) != 0) {
  1448. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1449. "mobility_domain '%s'", line, pos);
  1450. errors++;
  1451. continue;
  1452. }
  1453. } else if (os_strcmp(buf, "r1_key_holder") == 0) {
  1454. if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
  1455. hexstr2bin(pos, bss->r1_key_holder,
  1456. FT_R1KH_ID_LEN) != 0) {
  1457. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1458. "r1_key_holder '%s'", line, pos);
  1459. errors++;
  1460. continue;
  1461. }
  1462. } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
  1463. bss->r0_key_lifetime = atoi(pos);
  1464. } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
  1465. bss->reassociation_deadline = atoi(pos);
  1466. } else if (os_strcmp(buf, "r0kh") == 0) {
  1467. if (add_r0kh(bss, pos) < 0) {
  1468. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1469. "r0kh '%s'", line, pos);
  1470. errors++;
  1471. continue;
  1472. }
  1473. } else if (os_strcmp(buf, "r1kh") == 0) {
  1474. if (add_r1kh(bss, pos) < 0) {
  1475. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1476. "r1kh '%s'", line, pos);
  1477. errors++;
  1478. continue;
  1479. }
  1480. } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
  1481. bss->pmk_r1_push = atoi(pos);
  1482. #endif /* CONFIG_IEEE80211R */
  1483. #ifndef CONFIG_NO_CTRL_IFACE
  1484. } else if (os_strcmp(buf, "ctrl_interface") == 0) {
  1485. os_free(bss->ctrl_interface);
  1486. bss->ctrl_interface = os_strdup(pos);
  1487. } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
  1488. #ifndef CONFIG_NATIVE_WINDOWS
  1489. struct group *grp;
  1490. char *endp;
  1491. const char *group = pos;
  1492. grp = getgrnam(group);
  1493. if (grp) {
  1494. bss->ctrl_interface_gid = grp->gr_gid;
  1495. bss->ctrl_interface_gid_set = 1;
  1496. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
  1497. " (from group name '%s')",
  1498. bss->ctrl_interface_gid, group);
  1499. continue;
  1500. }
  1501. /* Group name not found - try to parse this as gid */
  1502. bss->ctrl_interface_gid = strtol(group, &endp, 10);
  1503. if (*group == '\0' || *endp != '\0') {
  1504. wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
  1505. "'%s'", line, group);
  1506. errors++;
  1507. continue;
  1508. }
  1509. bss->ctrl_interface_gid_set = 1;
  1510. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
  1511. bss->ctrl_interface_gid);
  1512. #endif /* CONFIG_NATIVE_WINDOWS */
  1513. #endif /* CONFIG_NO_CTRL_IFACE */
  1514. #ifdef RADIUS_SERVER
  1515. } else if (os_strcmp(buf, "radius_server_clients") == 0) {
  1516. os_free(bss->radius_server_clients);
  1517. bss->radius_server_clients = os_strdup(pos);
  1518. } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
  1519. bss->radius_server_auth_port = atoi(pos);
  1520. } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
  1521. bss->radius_server_ipv6 = atoi(pos);
  1522. #endif /* RADIUS_SERVER */
  1523. } else if (os_strcmp(buf, "test_socket") == 0) {
  1524. os_free(bss->test_socket);
  1525. bss->test_socket = os_strdup(pos);
  1526. } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
  1527. bss->use_pae_group_addr = atoi(pos);
  1528. } else if (os_strcmp(buf, "hw_mode") == 0) {
  1529. if (os_strcmp(pos, "a") == 0)
  1530. conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
  1531. else if (os_strcmp(pos, "b") == 0)
  1532. conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
  1533. else if (os_strcmp(pos, "g") == 0)
  1534. conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
  1535. else {
  1536. wpa_printf(MSG_ERROR, "Line %d: unknown "
  1537. "hw_mode '%s'", line, pos);
  1538. errors++;
  1539. }
  1540. } else if (os_strcmp(buf, "channel") == 0) {
  1541. conf->channel = atoi(pos);
  1542. } else if (os_strcmp(buf, "beacon_int") == 0) {
  1543. int val = atoi(pos);
  1544. /* MIB defines range as 1..65535, but very small values
  1545. * cause problems with the current implementation.
  1546. * Since it is unlikely that this small numbers are
  1547. * useful in real life scenarios, do not allow beacon
  1548. * period to be set below 15 TU. */
  1549. if (val < 15 || val > 65535) {
  1550. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1551. "beacon_int %d (expected "
  1552. "15..65535)", line, val);
  1553. errors++;
  1554. } else
  1555. conf->beacon_int = val;
  1556. } else if (os_strcmp(buf, "dtim_period") == 0) {
  1557. bss->dtim_period = atoi(pos);
  1558. if (bss->dtim_period < 1 || bss->dtim_period > 255) {
  1559. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1560. "dtim_period %d",
  1561. line, bss->dtim_period);
  1562. errors++;
  1563. }
  1564. } else if (os_strcmp(buf, "rts_threshold") == 0) {
  1565. conf->rts_threshold = atoi(pos);
  1566. if (conf->rts_threshold < 0 ||
  1567. conf->rts_threshold > 2347) {
  1568. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1569. "rts_threshold %d",
  1570. line, conf->rts_threshold);
  1571. errors++;
  1572. }
  1573. } else if (os_strcmp(buf, "fragm_threshold") == 0) {
  1574. conf->fragm_threshold = atoi(pos);
  1575. if (conf->fragm_threshold < 256 ||
  1576. conf->fragm_threshold > 2346) {
  1577. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1578. "fragm_threshold %d",
  1579. line, conf->fragm_threshold);
  1580. errors++;
  1581. }
  1582. } else if (os_strcmp(buf, "send_probe_response") == 0) {
  1583. int val = atoi(pos);
  1584. if (val != 0 && val != 1) {
  1585. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1586. "send_probe_response %d (expected "
  1587. "0 or 1)", line, val);
  1588. } else
  1589. conf->send_probe_response = val;
  1590. } else if (os_strcmp(buf, "supported_rates") == 0) {
  1591. if (hostapd_parse_rates(&conf->supported_rates, pos)) {
  1592. wpa_printf(MSG_ERROR, "Line %d: invalid rate "
  1593. "list", line);
  1594. errors++;
  1595. }
  1596. } else if (os_strcmp(buf, "basic_rates") == 0) {
  1597. if (hostapd_parse_rates(&conf->basic_rates, pos)) {
  1598. wpa_printf(MSG_ERROR, "Line %d: invalid rate "
  1599. "list", line);
  1600. errors++;
  1601. }
  1602. } else if (os_strcmp(buf, "preamble") == 0) {
  1603. if (atoi(pos))
  1604. conf->preamble = SHORT_PREAMBLE;
  1605. else
  1606. conf->preamble = LONG_PREAMBLE;
  1607. } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
  1608. bss->ignore_broadcast_ssid = atoi(pos);
  1609. } else if (os_strcmp(buf, "wep_default_key") == 0) {
  1610. bss->ssid.wep.idx = atoi(pos);
  1611. if (bss->ssid.wep.idx > 3) {
  1612. wpa_printf(MSG_ERROR, "Invalid "
  1613. "wep_default_key index %d",
  1614. bss->ssid.wep.idx);
  1615. errors++;
  1616. }
  1617. } else if (os_strcmp(buf, "wep_key0") == 0 ||
  1618. os_strcmp(buf, "wep_key1") == 0 ||
  1619. os_strcmp(buf, "wep_key2") == 0 ||
  1620. os_strcmp(buf, "wep_key3") == 0) {
  1621. if (hostapd_config_read_wep(&bss->ssid.wep,
  1622. buf[7] - '0', pos)) {
  1623. wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
  1624. "key '%s'", line, buf);
  1625. errors++;
  1626. }
  1627. #ifndef CONFIG_NO_VLAN
  1628. } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
  1629. bss->ssid.dynamic_vlan = atoi(pos);
  1630. } else if (os_strcmp(buf, "vlan_file") == 0) {
  1631. if (hostapd_config_read_vlan_file(bss, pos)) {
  1632. wpa_printf(MSG_ERROR, "Line %d: failed to "
  1633. "read VLAN file '%s'", line, pos);
  1634. errors++;
  1635. }
  1636. #ifdef CONFIG_FULL_DYNAMIC_VLAN
  1637. } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
  1638. bss->ssid.vlan_tagged_interface = os_strdup(pos);
  1639. #endif /* CONFIG_FULL_DYNAMIC_VLAN */
  1640. #endif /* CONFIG_NO_VLAN */
  1641. } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
  1642. conf->ap_table_max_size = atoi(pos);
  1643. } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
  1644. conf->ap_table_expiration_time = atoi(pos);
  1645. } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
  1646. if (hostapd_config_tx_queue(conf, buf, pos)) {
  1647. wpa_printf(MSG_ERROR, "Line %d: invalid TX "
  1648. "queue item", line);
  1649. errors++;
  1650. }
  1651. } else if (os_strcmp(buf, "wme_enabled") == 0 ||
  1652. os_strcmp(buf, "wmm_enabled") == 0) {
  1653. bss->wmm_enabled = atoi(pos);
  1654. } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
  1655. os_strncmp(buf, "wmm_ac_", 7) == 0) {
  1656. if (hostapd_config_wmm_ac(conf, buf, pos)) {
  1657. wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
  1658. "ac item", line);
  1659. errors++;
  1660. }
  1661. } else if (os_strcmp(buf, "bss") == 0) {
  1662. if (hostapd_config_bss(conf, pos)) {
  1663. wpa_printf(MSG_ERROR, "Line %d: invalid bss "
  1664. "item", line);
  1665. errors++;
  1666. }
  1667. } else if (os_strcmp(buf, "bssid") == 0) {
  1668. if (hwaddr_aton(pos, bss->bssid)) {
  1669. wpa_printf(MSG_ERROR, "Line %d: invalid bssid "
  1670. "item", line);
  1671. errors++;
  1672. }
  1673. #ifdef CONFIG_IEEE80211W
  1674. } else if (os_strcmp(buf, "ieee80211w") == 0) {
  1675. bss->ieee80211w = atoi(pos);
  1676. } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
  1677. bss->assoc_sa_query_max_timeout = atoi(pos);
  1678. if (bss->assoc_sa_query_max_timeout == 0) {
  1679. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1680. "assoc_sa_query_max_timeout", line);
  1681. errors++;
  1682. }
  1683. } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0)
  1684. {
  1685. bss->assoc_sa_query_retry_timeout = atoi(pos);
  1686. if (bss->assoc_sa_query_retry_timeout == 0) {
  1687. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1688. "assoc_sa_query_retry_timeout",
  1689. line);
  1690. errors++;
  1691. }
  1692. #endif /* CONFIG_IEEE80211W */
  1693. #ifdef CONFIG_IEEE80211N
  1694. } else if (os_strcmp(buf, "ieee80211n") == 0) {
  1695. conf->ieee80211n = atoi(pos);
  1696. } else if (os_strcmp(buf, "ht_capab") == 0) {
  1697. if (hostapd_config_ht_capab(conf, pos) < 0) {
  1698. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1699. "ht_capab", line);
  1700. errors++;
  1701. }
  1702. #endif /* CONFIG_IEEE80211N */
  1703. } else if (os_strcmp(buf, "max_listen_interval") == 0) {
  1704. bss->max_listen_interval = atoi(pos);
  1705. } else if (os_strcmp(buf, "okc") == 0) {
  1706. bss->okc = atoi(pos);
  1707. #ifdef CONFIG_WPS
  1708. } else if (os_strcmp(buf, "wps_state") == 0) {
  1709. bss->wps_state = atoi(pos);
  1710. if (bss->wps_state < 0 || bss->wps_state > 2) {
  1711. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1712. "wps_state", line);
  1713. errors++;
  1714. }
  1715. } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
  1716. bss->ap_setup_locked = atoi(pos);
  1717. } else if (os_strcmp(buf, "uuid") == 0) {
  1718. if (uuid_str2bin(pos, bss->uuid)) {
  1719. wpa_printf(MSG_ERROR, "Line %d: invalid UUID",
  1720. line);
  1721. errors++;
  1722. }
  1723. } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
  1724. os_free(bss->wps_pin_requests);
  1725. bss->wps_pin_requests = os_strdup(pos);
  1726. } else if (os_strcmp(buf, "device_name") == 0) {
  1727. if (os_strlen(pos) > 32) {
  1728. wpa_printf(MSG_ERROR, "Line %d: Too long "
  1729. "device_name", line);
  1730. errors++;
  1731. }
  1732. os_free(bss->device_name);
  1733. bss->device_name = os_strdup(pos);
  1734. } else if (os_strcmp(buf, "manufacturer") == 0) {
  1735. if (os_strlen(pos) > 64) {
  1736. wpa_printf(MSG_ERROR, "Line %d: Too long "
  1737. "manufacturer", line);
  1738. errors++;
  1739. }
  1740. os_free(bss->manufacturer);
  1741. bss->manufacturer = os_strdup(pos);
  1742. } else if (os_strcmp(buf, "model_name") == 0) {
  1743. if (os_strlen(pos) > 32) {
  1744. wpa_printf(MSG_ERROR, "Line %d: Too long "
  1745. "model_name", line);
  1746. errors++;
  1747. }
  1748. os_free(bss->model_name);
  1749. bss->model_name = os_strdup(pos);
  1750. } else if (os_strcmp(buf, "model_number") == 0) {
  1751. if (os_strlen(pos) > 32) {
  1752. wpa_printf(MSG_ERROR, "Line %d: Too long "
  1753. "model_number", line);
  1754. errors++;
  1755. }
  1756. os_free(bss->model_number);
  1757. bss->model_number = os_strdup(pos);
  1758. } else if (os_strcmp(buf, "serial_number") == 0) {
  1759. if (os_strlen(pos) > 32) {
  1760. wpa_printf(MSG_ERROR, "Line %d: Too long "
  1761. "serial_number", line);
  1762. errors++;
  1763. }
  1764. os_free(bss->serial_number);
  1765. bss->serial_number = os_strdup(pos);
  1766. } else if (os_strcmp(buf, "device_type") == 0) {
  1767. os_free(bss->device_type);
  1768. bss->device_type = os_strdup(pos);
  1769. } else if (os_strcmp(buf, "config_methods") == 0) {
  1770. os_free(bss->config_methods);
  1771. bss->config_methods = os_strdup(pos);
  1772. } else if (os_strcmp(buf, "os_version") == 0) {
  1773. if (hexstr2bin(pos, bss->os_version, 4)) {
  1774. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1775. "os_version", line);
  1776. errors++;
  1777. }
  1778. } else if (os_strcmp(buf, "ap_pin") == 0) {
  1779. os_free(bss->ap_pin);
  1780. bss->ap_pin = os_strdup(pos);
  1781. } else if (os_strcmp(buf, "skip_cred_build") == 0) {
  1782. bss->skip_cred_build = atoi(pos);
  1783. } else if (os_strcmp(buf, "extra_cred") == 0) {
  1784. os_free(bss->extra_cred);
  1785. bss->extra_cred =
  1786. (u8 *) os_readfile(pos, &bss->extra_cred_len);
  1787. if (bss->extra_cred == NULL) {
  1788. wpa_printf(MSG_ERROR, "Line %d: could not "
  1789. "read Credentials from '%s'",
  1790. line, pos);
  1791. errors++;
  1792. }
  1793. } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
  1794. bss->wps_cred_processing = atoi(pos);
  1795. } else if (os_strcmp(buf, "ap_settings") == 0) {
  1796. os_free(bss->ap_settings);
  1797. bss->ap_settings =
  1798. (u8 *) os_readfile(pos, &bss->ap_settings_len);
  1799. if (bss->ap_settings == NULL) {
  1800. wpa_printf(MSG_ERROR, "Line %d: could not "
  1801. "read AP Settings from '%s'",
  1802. line, pos);
  1803. errors++;
  1804. }
  1805. } else if (os_strcmp(buf, "upnp_iface") == 0) {
  1806. bss->upnp_iface = os_strdup(pos);
  1807. } else if (os_strcmp(buf, "friendly_name") == 0) {
  1808. os_free(bss->friendly_name);
  1809. bss->friendly_name = os_strdup(pos);
  1810. } else if (os_strcmp(buf, "manufacturer_url") == 0) {
  1811. os_free(bss->manufacturer_url);
  1812. bss->manufacturer_url = os_strdup(pos);
  1813. } else if (os_strcmp(buf, "model_description") == 0) {
  1814. os_free(bss->model_description);
  1815. bss->model_description = os_strdup(pos);
  1816. } else if (os_strcmp(buf, "model_url") == 0) {
  1817. os_free(bss->model_url);
  1818. bss->model_url = os_strdup(pos);
  1819. } else if (os_strcmp(buf, "upc") == 0) {
  1820. os_free(bss->upc);
  1821. bss->upc = os_strdup(pos);
  1822. #endif /* CONFIG_WPS */
  1823. } else {
  1824. wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
  1825. "item '%s'", line, buf);
  1826. errors++;
  1827. }
  1828. }
  1829. fclose(f);
  1830. for (i = 0; i < conf->num_bss; i++) {
  1831. bss = &conf->bss[i];
  1832. if (bss->individual_wep_key_len == 0) {
  1833. /* individual keys are not use; can use key idx0 for
  1834. * broadcast keys */
  1835. bss->broadcast_key_idx_min = 0;
  1836. }
  1837. /* Select group cipher based on the enabled pairwise cipher
  1838. * suites */
  1839. pairwise = 0;
  1840. if (bss->wpa & 1)
  1841. pairwise |= bss->wpa_pairwise;
  1842. if (bss->wpa & 2) {
  1843. if (bss->rsn_pairwise == 0)
  1844. bss->rsn_pairwise = bss->wpa_pairwise;
  1845. pairwise |= bss->rsn_pairwise;
  1846. }
  1847. if (pairwise & WPA_CIPHER_TKIP)
  1848. bss->wpa_group = WPA_CIPHER_TKIP;
  1849. else
  1850. bss->wpa_group = WPA_CIPHER_CCMP;
  1851. bss->radius->auth_server = bss->radius->auth_servers;
  1852. bss->radius->acct_server = bss->radius->acct_servers;
  1853. if (bss->wpa && bss->ieee802_1x) {
  1854. bss->ssid.security_policy = SECURITY_WPA;
  1855. } else if (bss->wpa) {
  1856. bss->ssid.security_policy = SECURITY_WPA_PSK;
  1857. } else if (bss->ieee802_1x) {
  1858. bss->ssid.security_policy = SECURITY_IEEE_802_1X;
  1859. bss->ssid.wep.default_len = bss->default_wep_key_len;
  1860. } else if (bss->ssid.wep.keys_set)
  1861. bss->ssid.security_policy = SECURITY_STATIC_WEP;
  1862. else
  1863. bss->ssid.security_policy = SECURITY_PLAINTEXT;
  1864. }
  1865. if (hostapd_config_check(conf))
  1866. errors++;
  1867. if (errors) {
  1868. wpa_printf(MSG_ERROR, "%d errors found in configuration file "
  1869. "'%s'", errors, fname);
  1870. hostapd_config_free(conf);
  1871. conf = NULL;
  1872. }
  1873. return conf;
  1874. }