config_file.c 62 KB

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