config_file.c 55 KB

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