config_file.c 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679
  1. /*
  2. * hostapd / Configuration file parser
  3. * Copyright (c) 2003-2012, 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_array(*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_array(*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. static struct hostapd_radius_attr *
  431. hostapd_parse_radius_attr(const char *value)
  432. {
  433. const char *pos;
  434. char syntax;
  435. struct hostapd_radius_attr *attr;
  436. size_t len;
  437. attr = os_zalloc(sizeof(*attr));
  438. if (attr == NULL)
  439. return NULL;
  440. attr->type = atoi(value);
  441. pos = os_strchr(value, ':');
  442. if (pos == NULL) {
  443. attr->val = wpabuf_alloc(1);
  444. if (attr->val == NULL) {
  445. os_free(attr);
  446. return NULL;
  447. }
  448. wpabuf_put_u8(attr->val, 0);
  449. return attr;
  450. }
  451. pos++;
  452. if (pos[0] == '\0' || pos[1] != ':') {
  453. os_free(attr);
  454. return NULL;
  455. }
  456. syntax = *pos++;
  457. pos++;
  458. switch (syntax) {
  459. case 's':
  460. attr->val = wpabuf_alloc_copy(pos, os_strlen(pos));
  461. break;
  462. case 'x':
  463. len = os_strlen(pos);
  464. if (len & 1)
  465. break;
  466. len /= 2;
  467. attr->val = wpabuf_alloc(len);
  468. if (attr->val == NULL)
  469. break;
  470. if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) {
  471. wpabuf_free(attr->val);
  472. os_free(attr);
  473. return NULL;
  474. }
  475. break;
  476. case 'd':
  477. attr->val = wpabuf_alloc(4);
  478. if (attr->val)
  479. wpabuf_put_be32(attr->val, atoi(pos));
  480. break;
  481. default:
  482. os_free(attr);
  483. return NULL;
  484. }
  485. if (attr->val == NULL) {
  486. os_free(attr);
  487. return NULL;
  488. }
  489. return attr;
  490. }
  491. static int hostapd_parse_das_client(struct hostapd_bss_config *bss,
  492. const char *val)
  493. {
  494. char *secret;
  495. secret = os_strchr(val, ' ');
  496. if (secret == NULL)
  497. return -1;
  498. secret++;
  499. if (hostapd_parse_ip_addr(val, &bss->radius_das_client_addr))
  500. return -1;
  501. os_free(bss->radius_das_shared_secret);
  502. bss->radius_das_shared_secret = (u8 *) os_strdup(secret);
  503. if (bss->radius_das_shared_secret == NULL)
  504. return -1;
  505. bss->radius_das_shared_secret_len = os_strlen(secret);
  506. return 0;
  507. }
  508. #endif /* CONFIG_NO_RADIUS */
  509. static int hostapd_config_parse_key_mgmt(int line, const char *value)
  510. {
  511. int val = 0, last;
  512. char *start, *end, *buf;
  513. buf = os_strdup(value);
  514. if (buf == NULL)
  515. return -1;
  516. start = buf;
  517. while (*start != '\0') {
  518. while (*start == ' ' || *start == '\t')
  519. start++;
  520. if (*start == '\0')
  521. break;
  522. end = start;
  523. while (*end != ' ' && *end != '\t' && *end != '\0')
  524. end++;
  525. last = *end == '\0';
  526. *end = '\0';
  527. if (os_strcmp(start, "WPA-PSK") == 0)
  528. val |= WPA_KEY_MGMT_PSK;
  529. else if (os_strcmp(start, "WPA-EAP") == 0)
  530. val |= WPA_KEY_MGMT_IEEE8021X;
  531. #ifdef CONFIG_IEEE80211R
  532. else if (os_strcmp(start, "FT-PSK") == 0)
  533. val |= WPA_KEY_MGMT_FT_PSK;
  534. else if (os_strcmp(start, "FT-EAP") == 0)
  535. val |= WPA_KEY_MGMT_FT_IEEE8021X;
  536. #endif /* CONFIG_IEEE80211R */
  537. #ifdef CONFIG_IEEE80211W
  538. else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
  539. val |= WPA_KEY_MGMT_PSK_SHA256;
  540. else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
  541. val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
  542. #endif /* CONFIG_IEEE80211W */
  543. else {
  544. wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
  545. line, start);
  546. os_free(buf);
  547. return -1;
  548. }
  549. if (last)
  550. break;
  551. start = end + 1;
  552. }
  553. os_free(buf);
  554. if (val == 0) {
  555. wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
  556. "configured.", line);
  557. return -1;
  558. }
  559. return val;
  560. }
  561. static int hostapd_config_parse_cipher(int line, const char *value)
  562. {
  563. int val = 0, last;
  564. char *start, *end, *buf;
  565. buf = os_strdup(value);
  566. if (buf == NULL)
  567. return -1;
  568. start = buf;
  569. while (*start != '\0') {
  570. while (*start == ' ' || *start == '\t')
  571. start++;
  572. if (*start == '\0')
  573. break;
  574. end = start;
  575. while (*end != ' ' && *end != '\t' && *end != '\0')
  576. end++;
  577. last = *end == '\0';
  578. *end = '\0';
  579. if (os_strcmp(start, "CCMP") == 0)
  580. val |= WPA_CIPHER_CCMP;
  581. else if (os_strcmp(start, "TKIP") == 0)
  582. val |= WPA_CIPHER_TKIP;
  583. else if (os_strcmp(start, "WEP104") == 0)
  584. val |= WPA_CIPHER_WEP104;
  585. else if (os_strcmp(start, "WEP40") == 0)
  586. val |= WPA_CIPHER_WEP40;
  587. else if (os_strcmp(start, "NONE") == 0)
  588. val |= WPA_CIPHER_NONE;
  589. else {
  590. wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
  591. line, start);
  592. os_free(buf);
  593. return -1;
  594. }
  595. if (last)
  596. break;
  597. start = end + 1;
  598. }
  599. os_free(buf);
  600. if (val == 0) {
  601. wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
  602. line);
  603. return -1;
  604. }
  605. return val;
  606. }
  607. static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
  608. char *val)
  609. {
  610. size_t len = os_strlen(val);
  611. if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
  612. return -1;
  613. if (val[0] == '"') {
  614. if (len < 2 || val[len - 1] != '"')
  615. return -1;
  616. len -= 2;
  617. wep->key[keyidx] = os_malloc(len);
  618. if (wep->key[keyidx] == NULL)
  619. return -1;
  620. os_memcpy(wep->key[keyidx], val + 1, len);
  621. wep->len[keyidx] = len;
  622. } else {
  623. if (len & 1)
  624. return -1;
  625. len /= 2;
  626. wep->key[keyidx] = os_malloc(len);
  627. if (wep->key[keyidx] == NULL)
  628. return -1;
  629. wep->len[keyidx] = len;
  630. if (hexstr2bin(val, wep->key[keyidx], len) < 0)
  631. return -1;
  632. }
  633. wep->keys_set++;
  634. return 0;
  635. }
  636. static int hostapd_parse_rates(int **rate_list, char *val)
  637. {
  638. int *list;
  639. int count;
  640. char *pos, *end;
  641. os_free(*rate_list);
  642. *rate_list = NULL;
  643. pos = val;
  644. count = 0;
  645. while (*pos != '\0') {
  646. if (*pos == ' ')
  647. count++;
  648. pos++;
  649. }
  650. list = os_malloc(sizeof(int) * (count + 2));
  651. if (list == NULL)
  652. return -1;
  653. pos = val;
  654. count = 0;
  655. while (*pos != '\0') {
  656. end = os_strchr(pos, ' ');
  657. if (end)
  658. *end = '\0';
  659. list[count++] = atoi(pos);
  660. if (!end)
  661. break;
  662. pos = end + 1;
  663. }
  664. list[count] = -1;
  665. *rate_list = list;
  666. return 0;
  667. }
  668. static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
  669. {
  670. struct hostapd_bss_config *bss;
  671. if (*ifname == '\0')
  672. return -1;
  673. bss = os_realloc_array(conf->bss, conf->num_bss + 1,
  674. sizeof(struct hostapd_bss_config));
  675. if (bss == NULL) {
  676. wpa_printf(MSG_ERROR, "Failed to allocate memory for "
  677. "multi-BSS entry");
  678. return -1;
  679. }
  680. conf->bss = bss;
  681. bss = &(conf->bss[conf->num_bss]);
  682. os_memset(bss, 0, sizeof(*bss));
  683. bss->radius = os_zalloc(sizeof(*bss->radius));
  684. if (bss->radius == NULL) {
  685. wpa_printf(MSG_ERROR, "Failed to allocate memory for "
  686. "multi-BSS RADIUS data");
  687. return -1;
  688. }
  689. conf->num_bss++;
  690. conf->last_bss = bss;
  691. hostapd_config_defaults_bss(bss);
  692. os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
  693. os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
  694. return 0;
  695. }
  696. /* convert floats with one decimal place to value*10 int, i.e.,
  697. * "1.5" will return 15 */
  698. static int hostapd_config_read_int10(const char *value)
  699. {
  700. int i, d;
  701. char *pos;
  702. i = atoi(value);
  703. pos = os_strchr(value, '.');
  704. d = 0;
  705. if (pos) {
  706. pos++;
  707. if (*pos >= '0' && *pos <= '9')
  708. d = *pos - '0';
  709. }
  710. return i * 10 + d;
  711. }
  712. static int valid_cw(int cw)
  713. {
  714. return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
  715. cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
  716. }
  717. enum {
  718. IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
  719. IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
  720. IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
  721. IEEE80211_TX_QUEUE_DATA3 = 3 /* used for EDCA AC_BK data */
  722. };
  723. static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
  724. char *val)
  725. {
  726. int num;
  727. char *pos;
  728. struct hostapd_tx_queue_params *queue;
  729. /* skip 'tx_queue_' prefix */
  730. pos = name + 9;
  731. if (os_strncmp(pos, "data", 4) == 0 &&
  732. pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
  733. num = pos[4] - '0';
  734. pos += 6;
  735. } else if (os_strncmp(pos, "after_beacon_", 13) == 0 ||
  736. os_strncmp(pos, "beacon_", 7) == 0) {
  737. wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
  738. return 0;
  739. } else {
  740. wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
  741. return -1;
  742. }
  743. if (num >= NUM_TX_QUEUES) {
  744. /* for backwards compatibility, do not trigger failure */
  745. wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
  746. return 0;
  747. }
  748. queue = &conf->tx_queue[num];
  749. if (os_strcmp(pos, "aifs") == 0) {
  750. queue->aifs = atoi(val);
  751. if (queue->aifs < 0 || queue->aifs > 255) {
  752. wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
  753. queue->aifs);
  754. return -1;
  755. }
  756. } else if (os_strcmp(pos, "cwmin") == 0) {
  757. queue->cwmin = atoi(val);
  758. if (!valid_cw(queue->cwmin)) {
  759. wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
  760. queue->cwmin);
  761. return -1;
  762. }
  763. } else if (os_strcmp(pos, "cwmax") == 0) {
  764. queue->cwmax = atoi(val);
  765. if (!valid_cw(queue->cwmax)) {
  766. wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
  767. queue->cwmax);
  768. return -1;
  769. }
  770. } else if (os_strcmp(pos, "burst") == 0) {
  771. queue->burst = hostapd_config_read_int10(val);
  772. } else {
  773. wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
  774. return -1;
  775. }
  776. return 0;
  777. }
  778. #ifdef CONFIG_IEEE80211R
  779. static int add_r0kh(struct hostapd_bss_config *bss, char *value)
  780. {
  781. struct ft_remote_r0kh *r0kh;
  782. char *pos, *next;
  783. r0kh = os_zalloc(sizeof(*r0kh));
  784. if (r0kh == NULL)
  785. return -1;
  786. /* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
  787. pos = value;
  788. next = os_strchr(pos, ' ');
  789. if (next)
  790. *next++ = '\0';
  791. if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
  792. wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
  793. os_free(r0kh);
  794. return -1;
  795. }
  796. pos = next;
  797. next = os_strchr(pos, ' ');
  798. if (next)
  799. *next++ = '\0';
  800. if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
  801. wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
  802. os_free(r0kh);
  803. return -1;
  804. }
  805. r0kh->id_len = next - pos - 1;
  806. os_memcpy(r0kh->id, pos, r0kh->id_len);
  807. pos = next;
  808. if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
  809. wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
  810. os_free(r0kh);
  811. return -1;
  812. }
  813. r0kh->next = bss->r0kh_list;
  814. bss->r0kh_list = r0kh;
  815. return 0;
  816. }
  817. static int add_r1kh(struct hostapd_bss_config *bss, char *value)
  818. {
  819. struct ft_remote_r1kh *r1kh;
  820. char *pos, *next;
  821. r1kh = os_zalloc(sizeof(*r1kh));
  822. if (r1kh == NULL)
  823. return -1;
  824. /* 02:01:02:03:04:05 02:01:02:03:04:05
  825. * 000102030405060708090a0b0c0d0e0f */
  826. pos = value;
  827. next = os_strchr(pos, ' ');
  828. if (next)
  829. *next++ = '\0';
  830. if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
  831. wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
  832. os_free(r1kh);
  833. return -1;
  834. }
  835. pos = next;
  836. next = os_strchr(pos, ' ');
  837. if (next)
  838. *next++ = '\0';
  839. if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
  840. wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
  841. os_free(r1kh);
  842. return -1;
  843. }
  844. pos = next;
  845. if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
  846. wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
  847. os_free(r1kh);
  848. return -1;
  849. }
  850. r1kh->next = bss->r1kh_list;
  851. bss->r1kh_list = r1kh;
  852. return 0;
  853. }
  854. #endif /* CONFIG_IEEE80211R */
  855. #ifdef CONFIG_IEEE80211N
  856. static int hostapd_config_ht_capab(struct hostapd_config *conf,
  857. const char *capab)
  858. {
  859. if (os_strstr(capab, "[LDPC]"))
  860. conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
  861. if (os_strstr(capab, "[HT40-]")) {
  862. conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
  863. conf->secondary_channel = -1;
  864. }
  865. if (os_strstr(capab, "[HT40+]")) {
  866. conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
  867. conf->secondary_channel = 1;
  868. }
  869. if (os_strstr(capab, "[SMPS-STATIC]")) {
  870. conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
  871. conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
  872. }
  873. if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
  874. conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
  875. conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
  876. }
  877. if (os_strstr(capab, "[GF]"))
  878. conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
  879. if (os_strstr(capab, "[SHORT-GI-20]"))
  880. conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
  881. if (os_strstr(capab, "[SHORT-GI-40]"))
  882. conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
  883. if (os_strstr(capab, "[TX-STBC]"))
  884. conf->ht_capab |= HT_CAP_INFO_TX_STBC;
  885. if (os_strstr(capab, "[RX-STBC1]")) {
  886. conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
  887. conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
  888. }
  889. if (os_strstr(capab, "[RX-STBC12]")) {
  890. conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
  891. conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
  892. }
  893. if (os_strstr(capab, "[RX-STBC123]")) {
  894. conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
  895. conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
  896. }
  897. if (os_strstr(capab, "[DELAYED-BA]"))
  898. conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
  899. if (os_strstr(capab, "[MAX-AMSDU-7935]"))
  900. conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
  901. if (os_strstr(capab, "[DSSS_CCK-40]"))
  902. conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
  903. if (os_strstr(capab, "[PSMP]"))
  904. conf->ht_capab |= HT_CAP_INFO_PSMP_SUPP;
  905. if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
  906. conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
  907. return 0;
  908. }
  909. #endif /* CONFIG_IEEE80211N */
  910. #ifdef CONFIG_IEEE80211AC
  911. static int hostapd_config_vht_capab(struct hostapd_config *conf,
  912. const char *capab)
  913. {
  914. if (os_strstr(capab, "[MAX-MPDU-7991]"))
  915. conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_7991;
  916. if (os_strstr(capab, "[MAX-MPDU-11454]"))
  917. conf->vht_capab |= VHT_CAP_MAX_MPDU_LENGTH_11454;
  918. if (os_strstr(capab, "[VHT160]"))
  919. conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
  920. if (os_strstr(capab, "[VHT160-80PLUS80]"))
  921. conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
  922. if (os_strstr(capab, "[VHT160-80PLUS80]"))
  923. conf->vht_capab |= VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
  924. if (os_strstr(capab, "[RXLDPC]"))
  925. conf->vht_capab |= VHT_CAP_RXLDPC;
  926. if (os_strstr(capab, "[SHORT-GI-80]"))
  927. conf->vht_capab |= VHT_CAP_SHORT_GI_80;
  928. if (os_strstr(capab, "[SHORT-GI-160]"))
  929. conf->vht_capab |= VHT_CAP_SHORT_GI_160;
  930. if (os_strstr(capab, "[TX-STBC-2BY1]"))
  931. conf->vht_capab |= VHT_CAP_TXSTBC;
  932. if (os_strstr(capab, "[RX-STBC-1]"))
  933. conf->vht_capab |= VHT_CAP_RXSTBC_1;
  934. if (os_strstr(capab, "[RX-STBC-12]"))
  935. conf->vht_capab |= VHT_CAP_RXSTBC_2;
  936. if (os_strstr(capab, "[RX-STBC-123]"))
  937. conf->vht_capab |= VHT_CAP_RXSTBC_3;
  938. if (os_strstr(capab, "[RX-STBC-1234]"))
  939. conf->vht_capab |= VHT_CAP_RXSTBC_4;
  940. if (os_strstr(capab, "[SU-BEAMFORMER]"))
  941. conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
  942. if (os_strstr(capab, "[SU-BEAMFORMEE]"))
  943. conf->vht_capab |= VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  944. if (os_strstr(capab, "[BF-ANTENNA-2]") &&
  945. (conf->vht_capab & VHT_CAP_MU_BEAMFORMER_CAPABLE))
  946. conf->vht_capab |= VHT_CAP_BEAMFORMER_ANTENNAS_MAX;
  947. if (os_strstr(capab, "[SOUNDING-DIMENSION-2]") &&
  948. (conf->vht_capab & VHT_CAP_MU_BEAMFORMER_CAPABLE))
  949. conf->vht_capab |= VHT_CAP_SOUNDING_DIMENTION_MAX;
  950. if (os_strstr(capab, "[MU-BEAMFORMER]"))
  951. conf->vht_capab |= VHT_CAP_MU_BEAMFORMER_CAPABLE;
  952. if (os_strstr(capab, "[MU-BEAMFORMEE]"))
  953. conf->vht_capab |= VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  954. if (os_strstr(capab, "[VHT-TXOP-PS]"))
  955. conf->vht_capab |= VHT_CAP_VHT_TXOP_PS;
  956. if (os_strstr(capab, "[HTC-VHT]"))
  957. conf->vht_capab |= VHT_CAP_HTC_VHT;
  958. if (os_strstr(capab, "[MAX-A-MPDU-LEN-EXP0]"))
  959. conf->vht_capab |= VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT;
  960. if (os_strstr(capab, "[VHT-LINK-ADAPT2]") &&
  961. (conf->vht_capab & VHT_CAP_HTC_VHT))
  962. conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB;
  963. if (os_strstr(capab, "[VHT-LINK-ADAPT3]") &&
  964. (conf->vht_capab & VHT_CAP_HTC_VHT))
  965. conf->vht_capab |= VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB;
  966. if (os_strstr(capab, "[RX-ANTENNA-PATTERN]"))
  967. conf->vht_capab |= VHT_CAP_RX_ANTENNA_PATTERN;
  968. if (os_strstr(capab, "[TX-ANTENNA-PATTERN]"))
  969. conf->vht_capab |= VHT_CAP_TX_ANTENNA_PATTERN;
  970. return 0;
  971. }
  972. #endif /* CONFIG_IEEE80211AC */
  973. static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
  974. struct hostapd_config *conf)
  975. {
  976. if (bss->ieee802_1x && !bss->eap_server &&
  977. !bss->radius->auth_servers) {
  978. wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
  979. "EAP authenticator configured).");
  980. return -1;
  981. }
  982. if (bss->wpa && bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
  983. bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
  984. wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
  985. "RADIUS checking (macaddr_acl=2) enabled.");
  986. return -1;
  987. }
  988. if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
  989. bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
  990. bss->ssid.wpa_psk_file == NULL &&
  991. (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
  992. bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
  993. wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
  994. "is not configured.");
  995. return -1;
  996. }
  997. if (hostapd_mac_comp_empty(bss->bssid) != 0) {
  998. size_t i;
  999. for (i = 0; i < conf->num_bss; i++) {
  1000. if ((&conf->bss[i] != bss) &&
  1001. (hostapd_mac_comp(conf->bss[i].bssid,
  1002. bss->bssid) == 0)) {
  1003. wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
  1004. " on interface '%s' and '%s'.",
  1005. MAC2STR(bss->bssid),
  1006. conf->bss[i].iface, bss->iface);
  1007. return -1;
  1008. }
  1009. }
  1010. }
  1011. #ifdef CONFIG_IEEE80211R
  1012. if (wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
  1013. (bss->nas_identifier == NULL ||
  1014. os_strlen(bss->nas_identifier) < 1 ||
  1015. os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
  1016. wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
  1017. "nas_identifier to be configured as a 1..48 octet "
  1018. "string");
  1019. return -1;
  1020. }
  1021. #endif /* CONFIG_IEEE80211R */
  1022. #ifdef CONFIG_IEEE80211N
  1023. if (conf->ieee80211n && conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
  1024. bss->disable_11n = 1;
  1025. wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
  1026. "allowed, disabling HT capabilites");
  1027. }
  1028. if (conf->ieee80211n &&
  1029. bss->ssid.security_policy == SECURITY_STATIC_WEP) {
  1030. bss->disable_11n = 1;
  1031. wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
  1032. "allowed, disabling HT capabilities");
  1033. }
  1034. if (conf->ieee80211n && bss->wpa &&
  1035. !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
  1036. !(bss->rsn_pairwise & WPA_CIPHER_CCMP)) {
  1037. bss->disable_11n = 1;
  1038. wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
  1039. "requires CCMP to be enabled, disabling HT "
  1040. "capabilities");
  1041. }
  1042. #endif /* CONFIG_IEEE80211N */
  1043. #ifdef CONFIG_WPS2
  1044. if (bss->wps_state && bss->ignore_broadcast_ssid) {
  1045. wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
  1046. "configuration forced WPS to be disabled");
  1047. bss->wps_state = 0;
  1048. }
  1049. if (bss->wps_state && bss->ssid.wep.keys_set && bss->wpa == 0) {
  1050. wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
  1051. "disabled");
  1052. bss->wps_state = 0;
  1053. }
  1054. if (bss->wps_state && bss->wpa &&
  1055. (!(bss->wpa & 2) ||
  1056. !(bss->rsn_pairwise & WPA_CIPHER_CCMP))) {
  1057. wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
  1058. "WPA2/CCMP forced WPS to be disabled");
  1059. bss->wps_state = 0;
  1060. }
  1061. #endif /* CONFIG_WPS2 */
  1062. #ifdef CONFIG_HS20
  1063. if (bss->hs20 &&
  1064. (!(bss->wpa & 2) ||
  1065. !(bss->rsn_pairwise & WPA_CIPHER_CCMP))) {
  1066. wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
  1067. "configuration is required for Hotspot 2.0 "
  1068. "functionality");
  1069. return -1;
  1070. }
  1071. #endif /* CONFIG_HS20 */
  1072. return 0;
  1073. }
  1074. static int hostapd_config_check(struct hostapd_config *conf)
  1075. {
  1076. size_t i;
  1077. if (conf->ieee80211d && (!conf->country[0] || !conf->country[1])) {
  1078. wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
  1079. "setting the country_code");
  1080. return -1;
  1081. }
  1082. for (i = 0; i < conf->num_bss; i++) {
  1083. if (hostapd_config_check_bss(&conf->bss[i], conf))
  1084. return -1;
  1085. }
  1086. return 0;
  1087. }
  1088. #ifdef CONFIG_INTERWORKING
  1089. static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
  1090. int line)
  1091. {
  1092. size_t len = os_strlen(pos);
  1093. u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
  1094. struct hostapd_roaming_consortium *rc;
  1095. if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
  1096. hexstr2bin(pos, oi, len / 2)) {
  1097. wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
  1098. "'%s'", line, pos);
  1099. return -1;
  1100. }
  1101. len /= 2;
  1102. rc = os_realloc_array(bss->roaming_consortium,
  1103. bss->roaming_consortium_count + 1,
  1104. sizeof(struct hostapd_roaming_consortium));
  1105. if (rc == NULL)
  1106. return -1;
  1107. os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
  1108. rc[bss->roaming_consortium_count].len = len;
  1109. bss->roaming_consortium = rc;
  1110. bss->roaming_consortium_count++;
  1111. return 0;
  1112. }
  1113. static int parse_venue_name(struct hostapd_bss_config *bss, char *pos,
  1114. int line)
  1115. {
  1116. char *sep;
  1117. size_t clen, nlen;
  1118. struct hostapd_venue_name *vn;
  1119. sep = os_strchr(pos, ':');
  1120. if (sep == NULL)
  1121. goto fail;
  1122. *sep++ = '\0';
  1123. clen = os_strlen(pos);
  1124. if (clen < 2)
  1125. goto fail;
  1126. nlen = os_strlen(sep);
  1127. if (nlen > 252)
  1128. goto fail;
  1129. vn = os_realloc_array(bss->venue_name, bss->venue_name_count + 1,
  1130. sizeof(struct hostapd_venue_name));
  1131. if (vn == NULL)
  1132. return -1;
  1133. bss->venue_name = vn;
  1134. vn = &bss->venue_name[bss->venue_name_count];
  1135. bss->venue_name_count++;
  1136. os_memset(vn->lang, 0, sizeof(vn->lang));
  1137. os_memcpy(vn->lang, pos, clen);
  1138. vn->name_len = nlen;
  1139. os_memcpy(vn->name, sep, nlen);
  1140. return 0;
  1141. fail:
  1142. wpa_printf(MSG_ERROR, "Line %d: Invalid venue_name '%s'",
  1143. line, pos);
  1144. return -1;
  1145. }
  1146. #endif /* CONFIG_INTERWORKING */
  1147. #ifdef CONFIG_WPS_NFC
  1148. static struct wpabuf * hostapd_parse_bin(const char *buf)
  1149. {
  1150. size_t len;
  1151. struct wpabuf *ret;
  1152. len = os_strlen(buf);
  1153. if (len & 0x01)
  1154. return NULL;
  1155. len /= 2;
  1156. ret = wpabuf_alloc(len);
  1157. if (ret == NULL)
  1158. return NULL;
  1159. if (hexstr2bin(buf, wpabuf_put(ret, len), len)) {
  1160. wpabuf_free(ret);
  1161. return NULL;
  1162. }
  1163. return ret;
  1164. }
  1165. #endif /* CONFIG_WPS_NFC */
  1166. static int hostapd_config_fill(struct hostapd_config *conf,
  1167. struct hostapd_bss_config *bss,
  1168. char *buf, char *pos, int line)
  1169. {
  1170. int errors = 0;
  1171. {
  1172. if (os_strcmp(buf, "interface") == 0) {
  1173. os_strlcpy(conf->bss[0].iface, pos,
  1174. sizeof(conf->bss[0].iface));
  1175. } else if (os_strcmp(buf, "bridge") == 0) {
  1176. os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
  1177. } else if (os_strcmp(buf, "wds_bridge") == 0) {
  1178. os_strlcpy(bss->wds_bridge, pos,
  1179. sizeof(bss->wds_bridge));
  1180. } else if (os_strcmp(buf, "driver") == 0) {
  1181. int j;
  1182. /* clear to get error below if setting is invalid */
  1183. conf->driver = NULL;
  1184. for (j = 0; wpa_drivers[j]; j++) {
  1185. if (os_strcmp(pos, wpa_drivers[j]->name) == 0)
  1186. {
  1187. conf->driver = wpa_drivers[j];
  1188. break;
  1189. }
  1190. }
  1191. if (conf->driver == NULL) {
  1192. wpa_printf(MSG_ERROR, "Line %d: invalid/"
  1193. "unknown driver '%s'", line, pos);
  1194. errors++;
  1195. }
  1196. } else if (os_strcmp(buf, "debug") == 0) {
  1197. wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
  1198. "configuration variable is not used "
  1199. "anymore", line);
  1200. } else if (os_strcmp(buf, "logger_syslog_level") == 0) {
  1201. bss->logger_syslog_level = atoi(pos);
  1202. } else if (os_strcmp(buf, "logger_stdout_level") == 0) {
  1203. bss->logger_stdout_level = atoi(pos);
  1204. } else if (os_strcmp(buf, "logger_syslog") == 0) {
  1205. bss->logger_syslog = atoi(pos);
  1206. } else if (os_strcmp(buf, "logger_stdout") == 0) {
  1207. bss->logger_stdout = atoi(pos);
  1208. } else if (os_strcmp(buf, "dump_file") == 0) {
  1209. bss->dump_log_name = os_strdup(pos);
  1210. } else if (os_strcmp(buf, "ssid") == 0) {
  1211. bss->ssid.ssid_len = os_strlen(pos);
  1212. if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
  1213. bss->ssid.ssid_len < 1) {
  1214. wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
  1215. "'%s'", line, pos);
  1216. errors++;
  1217. } else {
  1218. os_memcpy(bss->ssid.ssid, pos,
  1219. bss->ssid.ssid_len);
  1220. bss->ssid.ssid_set = 1;
  1221. }
  1222. } else if (os_strcmp(buf, "ssid2") == 0) {
  1223. size_t slen;
  1224. char *str = wpa_config_parse_string(pos, &slen);
  1225. if (str == NULL || slen < 1 ||
  1226. slen > HOSTAPD_MAX_SSID_LEN) {
  1227. wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
  1228. "'%s'", line, pos);
  1229. errors++;
  1230. } else {
  1231. os_memcpy(bss->ssid.ssid, str, slen);
  1232. bss->ssid.ssid_len = slen;
  1233. bss->ssid.ssid_set = 1;
  1234. }
  1235. os_free(str);
  1236. } else if (os_strcmp(buf, "macaddr_acl") == 0) {
  1237. bss->macaddr_acl = atoi(pos);
  1238. if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
  1239. bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
  1240. bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
  1241. wpa_printf(MSG_ERROR, "Line %d: unknown "
  1242. "macaddr_acl %d",
  1243. line, bss->macaddr_acl);
  1244. }
  1245. } else if (os_strcmp(buf, "accept_mac_file") == 0) {
  1246. if (hostapd_config_read_maclist(pos, &bss->accept_mac,
  1247. &bss->num_accept_mac))
  1248. {
  1249. wpa_printf(MSG_ERROR, "Line %d: Failed to "
  1250. "read accept_mac_file '%s'",
  1251. line, pos);
  1252. errors++;
  1253. }
  1254. } else if (os_strcmp(buf, "deny_mac_file") == 0) {
  1255. if (hostapd_config_read_maclist(pos, &bss->deny_mac,
  1256. &bss->num_deny_mac)) {
  1257. wpa_printf(MSG_ERROR, "Line %d: Failed to "
  1258. "read deny_mac_file '%s'",
  1259. line, pos);
  1260. errors++;
  1261. }
  1262. } else if (os_strcmp(buf, "wds_sta") == 0) {
  1263. bss->wds_sta = atoi(pos);
  1264. } else if (os_strcmp(buf, "ap_isolate") == 0) {
  1265. bss->isolate = atoi(pos);
  1266. } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
  1267. bss->ap_max_inactivity = atoi(pos);
  1268. } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
  1269. bss->skip_inactivity_poll = atoi(pos);
  1270. } else if (os_strcmp(buf, "country_code") == 0) {
  1271. os_memcpy(conf->country, pos, 2);
  1272. /* FIX: make this configurable */
  1273. conf->country[2] = ' ';
  1274. } else if (os_strcmp(buf, "ieee80211d") == 0) {
  1275. conf->ieee80211d = atoi(pos);
  1276. } else if (os_strcmp(buf, "ieee8021x") == 0) {
  1277. bss->ieee802_1x = atoi(pos);
  1278. } else if (os_strcmp(buf, "eapol_version") == 0) {
  1279. bss->eapol_version = atoi(pos);
  1280. if (bss->eapol_version < 1 ||
  1281. bss->eapol_version > 2) {
  1282. wpa_printf(MSG_ERROR, "Line %d: invalid EAPOL "
  1283. "version (%d): '%s'.",
  1284. line, bss->eapol_version, pos);
  1285. errors++;
  1286. } else
  1287. wpa_printf(MSG_DEBUG, "eapol_version=%d",
  1288. bss->eapol_version);
  1289. #ifdef EAP_SERVER
  1290. } else if (os_strcmp(buf, "eap_authenticator") == 0) {
  1291. bss->eap_server = atoi(pos);
  1292. wpa_printf(MSG_ERROR, "Line %d: obsolete "
  1293. "eap_authenticator used; this has been "
  1294. "renamed to eap_server", line);
  1295. } else if (os_strcmp(buf, "eap_server") == 0) {
  1296. bss->eap_server = atoi(pos);
  1297. } else if (os_strcmp(buf, "eap_user_file") == 0) {
  1298. if (hostapd_config_read_eap_user(pos, bss))
  1299. errors++;
  1300. } else if (os_strcmp(buf, "ca_cert") == 0) {
  1301. os_free(bss->ca_cert);
  1302. bss->ca_cert = os_strdup(pos);
  1303. } else if (os_strcmp(buf, "server_cert") == 0) {
  1304. os_free(bss->server_cert);
  1305. bss->server_cert = os_strdup(pos);
  1306. } else if (os_strcmp(buf, "private_key") == 0) {
  1307. os_free(bss->private_key);
  1308. bss->private_key = os_strdup(pos);
  1309. } else if (os_strcmp(buf, "private_key_passwd") == 0) {
  1310. os_free(bss->private_key_passwd);
  1311. bss->private_key_passwd = os_strdup(pos);
  1312. } else if (os_strcmp(buf, "check_crl") == 0) {
  1313. bss->check_crl = atoi(pos);
  1314. } else if (os_strcmp(buf, "dh_file") == 0) {
  1315. os_free(bss->dh_file);
  1316. bss->dh_file = os_strdup(pos);
  1317. } else if (os_strcmp(buf, "fragment_size") == 0) {
  1318. bss->fragment_size = atoi(pos);
  1319. #ifdef EAP_SERVER_FAST
  1320. } else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
  1321. os_free(bss->pac_opaque_encr_key);
  1322. bss->pac_opaque_encr_key = os_malloc(16);
  1323. if (bss->pac_opaque_encr_key == NULL) {
  1324. wpa_printf(MSG_ERROR, "Line %d: No memory for "
  1325. "pac_opaque_encr_key", line);
  1326. errors++;
  1327. } else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
  1328. 16)) {
  1329. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1330. "pac_opaque_encr_key", line);
  1331. errors++;
  1332. }
  1333. } else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
  1334. size_t idlen = os_strlen(pos);
  1335. if (idlen & 1) {
  1336. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1337. "eap_fast_a_id", line);
  1338. errors++;
  1339. } else {
  1340. os_free(bss->eap_fast_a_id);
  1341. bss->eap_fast_a_id = os_malloc(idlen / 2);
  1342. if (bss->eap_fast_a_id == NULL ||
  1343. hexstr2bin(pos, bss->eap_fast_a_id,
  1344. idlen / 2)) {
  1345. wpa_printf(MSG_ERROR, "Line %d: "
  1346. "Failed to parse "
  1347. "eap_fast_a_id", line);
  1348. errors++;
  1349. } else
  1350. bss->eap_fast_a_id_len = idlen / 2;
  1351. }
  1352. } else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
  1353. os_free(bss->eap_fast_a_id_info);
  1354. bss->eap_fast_a_id_info = os_strdup(pos);
  1355. } else if (os_strcmp(buf, "eap_fast_prov") == 0) {
  1356. bss->eap_fast_prov = atoi(pos);
  1357. } else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
  1358. bss->pac_key_lifetime = atoi(pos);
  1359. } else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
  1360. bss->pac_key_refresh_time = atoi(pos);
  1361. #endif /* EAP_SERVER_FAST */
  1362. #ifdef EAP_SERVER_SIM
  1363. } else if (os_strcmp(buf, "eap_sim_db") == 0) {
  1364. os_free(bss->eap_sim_db);
  1365. bss->eap_sim_db = os_strdup(pos);
  1366. } else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
  1367. bss->eap_sim_aka_result_ind = atoi(pos);
  1368. #endif /* EAP_SERVER_SIM */
  1369. #ifdef EAP_SERVER_TNC
  1370. } else if (os_strcmp(buf, "tnc") == 0) {
  1371. bss->tnc = atoi(pos);
  1372. #endif /* EAP_SERVER_TNC */
  1373. #ifdef EAP_SERVER_PWD
  1374. } else if (os_strcmp(buf, "pwd_group") == 0) {
  1375. bss->pwd_group = atoi(pos);
  1376. #endif /* EAP_SERVER_PWD */
  1377. #endif /* EAP_SERVER */
  1378. } else if (os_strcmp(buf, "eap_message") == 0) {
  1379. char *term;
  1380. bss->eap_req_id_text = os_strdup(pos);
  1381. if (bss->eap_req_id_text == NULL) {
  1382. wpa_printf(MSG_ERROR, "Line %d: Failed to "
  1383. "allocate memory for "
  1384. "eap_req_id_text", line);
  1385. errors++;
  1386. return errors;
  1387. }
  1388. bss->eap_req_id_text_len =
  1389. os_strlen(bss->eap_req_id_text);
  1390. term = os_strstr(bss->eap_req_id_text, "\\0");
  1391. if (term) {
  1392. *term++ = '\0';
  1393. os_memmove(term, term + 1,
  1394. bss->eap_req_id_text_len -
  1395. (term - bss->eap_req_id_text) - 1);
  1396. bss->eap_req_id_text_len--;
  1397. }
  1398. } else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
  1399. bss->default_wep_key_len = atoi(pos);
  1400. if (bss->default_wep_key_len > 13) {
  1401. wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
  1402. "key len %lu (= %lu bits)", line,
  1403. (unsigned long)
  1404. bss->default_wep_key_len,
  1405. (unsigned long)
  1406. bss->default_wep_key_len * 8);
  1407. errors++;
  1408. }
  1409. } else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
  1410. bss->individual_wep_key_len = atoi(pos);
  1411. if (bss->individual_wep_key_len < 0 ||
  1412. bss->individual_wep_key_len > 13) {
  1413. wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
  1414. "key len %d (= %d bits)", line,
  1415. bss->individual_wep_key_len,
  1416. bss->individual_wep_key_len * 8);
  1417. errors++;
  1418. }
  1419. } else if (os_strcmp(buf, "wep_rekey_period") == 0) {
  1420. bss->wep_rekeying_period = atoi(pos);
  1421. if (bss->wep_rekeying_period < 0) {
  1422. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1423. "period %d",
  1424. line, bss->wep_rekeying_period);
  1425. errors++;
  1426. }
  1427. } else if (os_strcmp(buf, "eap_reauth_period") == 0) {
  1428. bss->eap_reauth_period = atoi(pos);
  1429. if (bss->eap_reauth_period < 0) {
  1430. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1431. "period %d",
  1432. line, bss->eap_reauth_period);
  1433. errors++;
  1434. }
  1435. } else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
  1436. bss->eapol_key_index_workaround = atoi(pos);
  1437. #ifdef CONFIG_IAPP
  1438. } else if (os_strcmp(buf, "iapp_interface") == 0) {
  1439. bss->ieee802_11f = 1;
  1440. os_strlcpy(bss->iapp_iface, pos,
  1441. sizeof(bss->iapp_iface));
  1442. #endif /* CONFIG_IAPP */
  1443. } else if (os_strcmp(buf, "own_ip_addr") == 0) {
  1444. if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
  1445. wpa_printf(MSG_ERROR, "Line %d: invalid IP "
  1446. "address '%s'", line, pos);
  1447. errors++;
  1448. }
  1449. } else if (os_strcmp(buf, "nas_identifier") == 0) {
  1450. bss->nas_identifier = os_strdup(pos);
  1451. #ifndef CONFIG_NO_RADIUS
  1452. } else if (os_strcmp(buf, "auth_server_addr") == 0) {
  1453. if (hostapd_config_read_radius_addr(
  1454. &bss->radius->auth_servers,
  1455. &bss->radius->num_auth_servers, pos, 1812,
  1456. &bss->radius->auth_server)) {
  1457. wpa_printf(MSG_ERROR, "Line %d: invalid IP "
  1458. "address '%s'", line, pos);
  1459. errors++;
  1460. }
  1461. } else if (bss->radius->auth_server &&
  1462. os_strcmp(buf, "auth_server_port") == 0) {
  1463. bss->radius->auth_server->port = atoi(pos);
  1464. } else if (bss->radius->auth_server &&
  1465. os_strcmp(buf, "auth_server_shared_secret") == 0) {
  1466. int len = os_strlen(pos);
  1467. if (len == 0) {
  1468. /* RFC 2865, Ch. 3 */
  1469. wpa_printf(MSG_ERROR, "Line %d: empty shared "
  1470. "secret is not allowed.", line);
  1471. errors++;
  1472. }
  1473. bss->radius->auth_server->shared_secret =
  1474. (u8 *) os_strdup(pos);
  1475. bss->radius->auth_server->shared_secret_len = len;
  1476. } else if (os_strcmp(buf, "acct_server_addr") == 0) {
  1477. if (hostapd_config_read_radius_addr(
  1478. &bss->radius->acct_servers,
  1479. &bss->radius->num_acct_servers, pos, 1813,
  1480. &bss->radius->acct_server)) {
  1481. wpa_printf(MSG_ERROR, "Line %d: invalid IP "
  1482. "address '%s'", line, pos);
  1483. errors++;
  1484. }
  1485. } else if (bss->radius->acct_server &&
  1486. os_strcmp(buf, "acct_server_port") == 0) {
  1487. bss->radius->acct_server->port = atoi(pos);
  1488. } else if (bss->radius->acct_server &&
  1489. os_strcmp(buf, "acct_server_shared_secret") == 0) {
  1490. int len = os_strlen(pos);
  1491. if (len == 0) {
  1492. /* RFC 2865, Ch. 3 */
  1493. wpa_printf(MSG_ERROR, "Line %d: empty shared "
  1494. "secret is not allowed.", line);
  1495. errors++;
  1496. }
  1497. bss->radius->acct_server->shared_secret =
  1498. (u8 *) os_strdup(pos);
  1499. bss->radius->acct_server->shared_secret_len = len;
  1500. } else if (os_strcmp(buf, "radius_retry_primary_interval") ==
  1501. 0) {
  1502. bss->radius->retry_primary_interval = atoi(pos);
  1503. } else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
  1504. {
  1505. bss->acct_interim_interval = atoi(pos);
  1506. } else if (os_strcmp(buf, "radius_request_cui") == 0) {
  1507. bss->radius_request_cui = atoi(pos);
  1508. } else if (os_strcmp(buf, "radius_auth_req_attr") == 0) {
  1509. struct hostapd_radius_attr *attr, *a;
  1510. attr = hostapd_parse_radius_attr(pos);
  1511. if (attr == NULL) {
  1512. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1513. "radius_auth_req_attr", line);
  1514. errors++;
  1515. } else if (bss->radius_auth_req_attr == NULL) {
  1516. bss->radius_auth_req_attr = attr;
  1517. } else {
  1518. a = bss->radius_auth_req_attr;
  1519. while (a->next)
  1520. a = a->next;
  1521. a->next = attr;
  1522. }
  1523. } else if (os_strcmp(buf, "radius_acct_req_attr") == 0) {
  1524. struct hostapd_radius_attr *attr, *a;
  1525. attr = hostapd_parse_radius_attr(pos);
  1526. if (attr == NULL) {
  1527. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1528. "radius_acct_req_attr", line);
  1529. errors++;
  1530. } else if (bss->radius_acct_req_attr == NULL) {
  1531. bss->radius_acct_req_attr = attr;
  1532. } else {
  1533. a = bss->radius_acct_req_attr;
  1534. while (a->next)
  1535. a = a->next;
  1536. a->next = attr;
  1537. }
  1538. } else if (os_strcmp(buf, "radius_das_port") == 0) {
  1539. bss->radius_das_port = atoi(pos);
  1540. } else if (os_strcmp(buf, "radius_das_client") == 0) {
  1541. if (hostapd_parse_das_client(bss, pos) < 0) {
  1542. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1543. "DAS client", line);
  1544. errors++;
  1545. }
  1546. } else if (os_strcmp(buf, "radius_das_time_window") == 0) {
  1547. bss->radius_das_time_window = atoi(pos);
  1548. } else if (os_strcmp(buf, "radius_das_require_event_timestamp")
  1549. == 0) {
  1550. bss->radius_das_require_event_timestamp = atoi(pos);
  1551. #endif /* CONFIG_NO_RADIUS */
  1552. } else if (os_strcmp(buf, "auth_algs") == 0) {
  1553. bss->auth_algs = atoi(pos);
  1554. if (bss->auth_algs == 0) {
  1555. wpa_printf(MSG_ERROR, "Line %d: no "
  1556. "authentication algorithms allowed",
  1557. line);
  1558. errors++;
  1559. }
  1560. } else if (os_strcmp(buf, "max_num_sta") == 0) {
  1561. bss->max_num_sta = atoi(pos);
  1562. if (bss->max_num_sta < 0 ||
  1563. bss->max_num_sta > MAX_STA_COUNT) {
  1564. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  1565. "max_num_sta=%d; allowed range "
  1566. "0..%d", line, bss->max_num_sta,
  1567. MAX_STA_COUNT);
  1568. errors++;
  1569. }
  1570. } else if (os_strcmp(buf, "wpa") == 0) {
  1571. bss->wpa = atoi(pos);
  1572. } else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
  1573. bss->wpa_group_rekey = atoi(pos);
  1574. } else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
  1575. bss->wpa_strict_rekey = atoi(pos);
  1576. } else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
  1577. bss->wpa_gmk_rekey = atoi(pos);
  1578. } else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
  1579. bss->wpa_ptk_rekey = atoi(pos);
  1580. } else if (os_strcmp(buf, "wpa_passphrase") == 0) {
  1581. int len = os_strlen(pos);
  1582. if (len < 8 || len > 63) {
  1583. wpa_printf(MSG_ERROR, "Line %d: invalid WPA "
  1584. "passphrase length %d (expected "
  1585. "8..63)", line, len);
  1586. errors++;
  1587. } else {
  1588. os_free(bss->ssid.wpa_passphrase);
  1589. bss->ssid.wpa_passphrase = os_strdup(pos);
  1590. os_free(bss->ssid.wpa_psk);
  1591. bss->ssid.wpa_psk = NULL;
  1592. }
  1593. } else if (os_strcmp(buf, "wpa_psk") == 0) {
  1594. os_free(bss->ssid.wpa_psk);
  1595. bss->ssid.wpa_psk =
  1596. os_zalloc(sizeof(struct hostapd_wpa_psk));
  1597. if (bss->ssid.wpa_psk == NULL)
  1598. errors++;
  1599. else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
  1600. PMK_LEN) ||
  1601. pos[PMK_LEN * 2] != '\0') {
  1602. wpa_printf(MSG_ERROR, "Line %d: Invalid PSK "
  1603. "'%s'.", line, pos);
  1604. errors++;
  1605. } else {
  1606. bss->ssid.wpa_psk->group = 1;
  1607. os_free(bss->ssid.wpa_passphrase);
  1608. bss->ssid.wpa_passphrase = NULL;
  1609. }
  1610. } else if (os_strcmp(buf, "wpa_psk_file") == 0) {
  1611. os_free(bss->ssid.wpa_psk_file);
  1612. bss->ssid.wpa_psk_file = os_strdup(pos);
  1613. if (!bss->ssid.wpa_psk_file) {
  1614. wpa_printf(MSG_ERROR, "Line %d: allocation "
  1615. "failed", line);
  1616. errors++;
  1617. }
  1618. } else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
  1619. bss->wpa_key_mgmt =
  1620. hostapd_config_parse_key_mgmt(line, pos);
  1621. if (bss->wpa_key_mgmt == -1)
  1622. errors++;
  1623. } else if (os_strcmp(buf, "wpa_psk_radius") == 0) {
  1624. bss->wpa_psk_radius = atoi(pos);
  1625. if (bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
  1626. bss->wpa_psk_radius != PSK_RADIUS_ACCEPTED &&
  1627. bss->wpa_psk_radius != PSK_RADIUS_REQUIRED) {
  1628. wpa_printf(MSG_ERROR, "Line %d: unknown "
  1629. "wpa_psk_radius %d",
  1630. line, bss->wpa_psk_radius);
  1631. errors++;
  1632. }
  1633. } else if (os_strcmp(buf, "wpa_pairwise") == 0) {
  1634. bss->wpa_pairwise =
  1635. hostapd_config_parse_cipher(line, pos);
  1636. if (bss->wpa_pairwise == -1 ||
  1637. bss->wpa_pairwise == 0)
  1638. errors++;
  1639. else if (bss->wpa_pairwise &
  1640. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
  1641. WPA_CIPHER_WEP104)) {
  1642. wpa_printf(MSG_ERROR, "Line %d: unsupported "
  1643. "pairwise cipher suite '%s'",
  1644. bss->wpa_pairwise, pos);
  1645. errors++;
  1646. }
  1647. } else if (os_strcmp(buf, "rsn_pairwise") == 0) {
  1648. bss->rsn_pairwise =
  1649. hostapd_config_parse_cipher(line, pos);
  1650. if (bss->rsn_pairwise == -1 ||
  1651. bss->rsn_pairwise == 0)
  1652. errors++;
  1653. else if (bss->rsn_pairwise &
  1654. (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
  1655. WPA_CIPHER_WEP104)) {
  1656. wpa_printf(MSG_ERROR, "Line %d: unsupported "
  1657. "pairwise cipher suite '%s'",
  1658. bss->rsn_pairwise, pos);
  1659. errors++;
  1660. }
  1661. #ifdef CONFIG_RSN_PREAUTH
  1662. } else if (os_strcmp(buf, "rsn_preauth") == 0) {
  1663. bss->rsn_preauth = atoi(pos);
  1664. } else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
  1665. bss->rsn_preauth_interfaces = os_strdup(pos);
  1666. #endif /* CONFIG_RSN_PREAUTH */
  1667. #ifdef CONFIG_PEERKEY
  1668. } else if (os_strcmp(buf, "peerkey") == 0) {
  1669. bss->peerkey = atoi(pos);
  1670. #endif /* CONFIG_PEERKEY */
  1671. #ifdef CONFIG_IEEE80211R
  1672. } else if (os_strcmp(buf, "mobility_domain") == 0) {
  1673. if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
  1674. hexstr2bin(pos, bss->mobility_domain,
  1675. MOBILITY_DOMAIN_ID_LEN) != 0) {
  1676. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1677. "mobility_domain '%s'", line, pos);
  1678. errors++;
  1679. return errors;
  1680. }
  1681. } else if (os_strcmp(buf, "r1_key_holder") == 0) {
  1682. if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
  1683. hexstr2bin(pos, bss->r1_key_holder,
  1684. FT_R1KH_ID_LEN) != 0) {
  1685. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1686. "r1_key_holder '%s'", line, pos);
  1687. errors++;
  1688. return errors;
  1689. }
  1690. } else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
  1691. bss->r0_key_lifetime = atoi(pos);
  1692. } else if (os_strcmp(buf, "reassociation_deadline") == 0) {
  1693. bss->reassociation_deadline = atoi(pos);
  1694. } else if (os_strcmp(buf, "r0kh") == 0) {
  1695. if (add_r0kh(bss, pos) < 0) {
  1696. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1697. "r0kh '%s'", line, pos);
  1698. errors++;
  1699. return errors;
  1700. }
  1701. } else if (os_strcmp(buf, "r1kh") == 0) {
  1702. if (add_r1kh(bss, pos) < 0) {
  1703. wpa_printf(MSG_DEBUG, "Line %d: Invalid "
  1704. "r1kh '%s'", line, pos);
  1705. errors++;
  1706. return errors;
  1707. }
  1708. } else if (os_strcmp(buf, "pmk_r1_push") == 0) {
  1709. bss->pmk_r1_push = atoi(pos);
  1710. } else if (os_strcmp(buf, "ft_over_ds") == 0) {
  1711. bss->ft_over_ds = atoi(pos);
  1712. #endif /* CONFIG_IEEE80211R */
  1713. #ifndef CONFIG_NO_CTRL_IFACE
  1714. } else if (os_strcmp(buf, "ctrl_interface") == 0) {
  1715. os_free(bss->ctrl_interface);
  1716. bss->ctrl_interface = os_strdup(pos);
  1717. } else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
  1718. #ifndef CONFIG_NATIVE_WINDOWS
  1719. struct group *grp;
  1720. char *endp;
  1721. const char *group = pos;
  1722. grp = getgrnam(group);
  1723. if (grp) {
  1724. bss->ctrl_interface_gid = grp->gr_gid;
  1725. bss->ctrl_interface_gid_set = 1;
  1726. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
  1727. " (from group name '%s')",
  1728. bss->ctrl_interface_gid, group);
  1729. return errors;
  1730. }
  1731. /* Group name not found - try to parse this as gid */
  1732. bss->ctrl_interface_gid = strtol(group, &endp, 10);
  1733. if (*group == '\0' || *endp != '\0') {
  1734. wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
  1735. "'%s'", line, group);
  1736. errors++;
  1737. return errors;
  1738. }
  1739. bss->ctrl_interface_gid_set = 1;
  1740. wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
  1741. bss->ctrl_interface_gid);
  1742. #endif /* CONFIG_NATIVE_WINDOWS */
  1743. #endif /* CONFIG_NO_CTRL_IFACE */
  1744. #ifdef RADIUS_SERVER
  1745. } else if (os_strcmp(buf, "radius_server_clients") == 0) {
  1746. os_free(bss->radius_server_clients);
  1747. bss->radius_server_clients = os_strdup(pos);
  1748. } else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
  1749. bss->radius_server_auth_port = atoi(pos);
  1750. } else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
  1751. bss->radius_server_ipv6 = atoi(pos);
  1752. #endif /* RADIUS_SERVER */
  1753. } else if (os_strcmp(buf, "test_socket") == 0) {
  1754. os_free(bss->test_socket);
  1755. bss->test_socket = os_strdup(pos);
  1756. } else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
  1757. bss->use_pae_group_addr = atoi(pos);
  1758. } else if (os_strcmp(buf, "hw_mode") == 0) {
  1759. if (os_strcmp(pos, "a") == 0)
  1760. conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
  1761. else if (os_strcmp(pos, "b") == 0)
  1762. conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
  1763. else if (os_strcmp(pos, "g") == 0)
  1764. conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
  1765. else {
  1766. wpa_printf(MSG_ERROR, "Line %d: unknown "
  1767. "hw_mode '%s'", line, pos);
  1768. errors++;
  1769. }
  1770. } else if (os_strcmp(buf, "wps_rf_bands") == 0) {
  1771. if (os_strcmp(pos, "a") == 0)
  1772. bss->wps_rf_bands = WPS_RF_50GHZ;
  1773. else if (os_strcmp(pos, "g") == 0 ||
  1774. os_strcmp(pos, "b") == 0)
  1775. bss->wps_rf_bands = WPS_RF_24GHZ;
  1776. else if (os_strcmp(pos, "ag") == 0 ||
  1777. os_strcmp(pos, "ga") == 0)
  1778. bss->wps_rf_bands =
  1779. WPS_RF_24GHZ | WPS_RF_50GHZ;
  1780. else {
  1781. wpa_printf(MSG_ERROR, "Line %d: unknown "
  1782. "wps_rf_band '%s'", line, pos);
  1783. errors++;
  1784. }
  1785. } else if (os_strcmp(buf, "channel") == 0) {
  1786. conf->channel = atoi(pos);
  1787. } else if (os_strcmp(buf, "beacon_int") == 0) {
  1788. int val = atoi(pos);
  1789. /* MIB defines range as 1..65535, but very small values
  1790. * cause problems with the current implementation.
  1791. * Since it is unlikely that this small numbers are
  1792. * useful in real life scenarios, do not allow beacon
  1793. * period to be set below 15 TU. */
  1794. if (val < 15 || val > 65535) {
  1795. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1796. "beacon_int %d (expected "
  1797. "15..65535)", line, val);
  1798. errors++;
  1799. } else
  1800. conf->beacon_int = val;
  1801. } else if (os_strcmp(buf, "dtim_period") == 0) {
  1802. bss->dtim_period = atoi(pos);
  1803. if (bss->dtim_period < 1 || bss->dtim_period > 255) {
  1804. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1805. "dtim_period %d",
  1806. line, bss->dtim_period);
  1807. errors++;
  1808. }
  1809. } else if (os_strcmp(buf, "rts_threshold") == 0) {
  1810. conf->rts_threshold = atoi(pos);
  1811. if (conf->rts_threshold < 0 ||
  1812. conf->rts_threshold > 2347) {
  1813. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1814. "rts_threshold %d",
  1815. line, conf->rts_threshold);
  1816. errors++;
  1817. }
  1818. } else if (os_strcmp(buf, "fragm_threshold") == 0) {
  1819. conf->fragm_threshold = atoi(pos);
  1820. if (conf->fragm_threshold < 256 ||
  1821. conf->fragm_threshold > 2346) {
  1822. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1823. "fragm_threshold %d",
  1824. line, conf->fragm_threshold);
  1825. errors++;
  1826. }
  1827. } else if (os_strcmp(buf, "send_probe_response") == 0) {
  1828. int val = atoi(pos);
  1829. if (val != 0 && val != 1) {
  1830. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1831. "send_probe_response %d (expected "
  1832. "0 or 1)", line, val);
  1833. } else
  1834. conf->send_probe_response = val;
  1835. } else if (os_strcmp(buf, "supported_rates") == 0) {
  1836. if (hostapd_parse_rates(&conf->supported_rates, pos)) {
  1837. wpa_printf(MSG_ERROR, "Line %d: invalid rate "
  1838. "list", line);
  1839. errors++;
  1840. }
  1841. } else if (os_strcmp(buf, "basic_rates") == 0) {
  1842. if (hostapd_parse_rates(&conf->basic_rates, pos)) {
  1843. wpa_printf(MSG_ERROR, "Line %d: invalid rate "
  1844. "list", line);
  1845. errors++;
  1846. }
  1847. } else if (os_strcmp(buf, "preamble") == 0) {
  1848. if (atoi(pos))
  1849. conf->preamble = SHORT_PREAMBLE;
  1850. else
  1851. conf->preamble = LONG_PREAMBLE;
  1852. } else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
  1853. bss->ignore_broadcast_ssid = atoi(pos);
  1854. } else if (os_strcmp(buf, "wep_default_key") == 0) {
  1855. bss->ssid.wep.idx = atoi(pos);
  1856. if (bss->ssid.wep.idx > 3) {
  1857. wpa_printf(MSG_ERROR, "Invalid "
  1858. "wep_default_key index %d",
  1859. bss->ssid.wep.idx);
  1860. errors++;
  1861. }
  1862. } else if (os_strcmp(buf, "wep_key0") == 0 ||
  1863. os_strcmp(buf, "wep_key1") == 0 ||
  1864. os_strcmp(buf, "wep_key2") == 0 ||
  1865. os_strcmp(buf, "wep_key3") == 0) {
  1866. if (hostapd_config_read_wep(&bss->ssid.wep,
  1867. buf[7] - '0', pos)) {
  1868. wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
  1869. "key '%s'", line, buf);
  1870. errors++;
  1871. }
  1872. #ifndef CONFIG_NO_VLAN
  1873. } else if (os_strcmp(buf, "dynamic_vlan") == 0) {
  1874. bss->ssid.dynamic_vlan = atoi(pos);
  1875. } else if (os_strcmp(buf, "vlan_file") == 0) {
  1876. if (hostapd_config_read_vlan_file(bss, pos)) {
  1877. wpa_printf(MSG_ERROR, "Line %d: failed to "
  1878. "read VLAN file '%s'", line, pos);
  1879. errors++;
  1880. }
  1881. } else if (os_strcmp(buf, "vlan_naming") == 0) {
  1882. bss->ssid.vlan_naming = atoi(pos);
  1883. if (bss->ssid.vlan_naming >= DYNAMIC_VLAN_NAMING_END ||
  1884. bss->ssid.vlan_naming < 0) {
  1885. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1886. "naming scheme %d", line,
  1887. bss->ssid.vlan_naming);
  1888. errors++;
  1889. }
  1890. #ifdef CONFIG_FULL_DYNAMIC_VLAN
  1891. } else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
  1892. bss->ssid.vlan_tagged_interface = os_strdup(pos);
  1893. #endif /* CONFIG_FULL_DYNAMIC_VLAN */
  1894. #endif /* CONFIG_NO_VLAN */
  1895. } else if (os_strcmp(buf, "ap_table_max_size") == 0) {
  1896. conf->ap_table_max_size = atoi(pos);
  1897. } else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
  1898. conf->ap_table_expiration_time = atoi(pos);
  1899. } else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
  1900. if (hostapd_config_tx_queue(conf, buf, pos)) {
  1901. wpa_printf(MSG_ERROR, "Line %d: invalid TX "
  1902. "queue item", line);
  1903. errors++;
  1904. }
  1905. } else if (os_strcmp(buf, "wme_enabled") == 0 ||
  1906. os_strcmp(buf, "wmm_enabled") == 0) {
  1907. bss->wmm_enabled = atoi(pos);
  1908. } else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
  1909. bss->wmm_uapsd = atoi(pos);
  1910. } else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
  1911. os_strncmp(buf, "wmm_ac_", 7) == 0) {
  1912. if (hostapd_config_wmm_ac(conf->wmm_ac_params, buf,
  1913. pos)) {
  1914. wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
  1915. "ac item", line);
  1916. errors++;
  1917. }
  1918. } else if (os_strcmp(buf, "bss") == 0) {
  1919. if (hostapd_config_bss(conf, pos)) {
  1920. wpa_printf(MSG_ERROR, "Line %d: invalid bss "
  1921. "item", line);
  1922. errors++;
  1923. }
  1924. } else if (os_strcmp(buf, "bssid") == 0) {
  1925. if (hwaddr_aton(pos, bss->bssid)) {
  1926. wpa_printf(MSG_ERROR, "Line %d: invalid bssid "
  1927. "item", line);
  1928. errors++;
  1929. }
  1930. #ifdef CONFIG_IEEE80211W
  1931. } else if (os_strcmp(buf, "ieee80211w") == 0) {
  1932. bss->ieee80211w = atoi(pos);
  1933. } else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
  1934. bss->assoc_sa_query_max_timeout = atoi(pos);
  1935. if (bss->assoc_sa_query_max_timeout == 0) {
  1936. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1937. "assoc_sa_query_max_timeout", line);
  1938. errors++;
  1939. }
  1940. } else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0)
  1941. {
  1942. bss->assoc_sa_query_retry_timeout = atoi(pos);
  1943. if (bss->assoc_sa_query_retry_timeout == 0) {
  1944. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1945. "assoc_sa_query_retry_timeout",
  1946. line);
  1947. errors++;
  1948. }
  1949. #endif /* CONFIG_IEEE80211W */
  1950. #ifdef CONFIG_IEEE80211N
  1951. } else if (os_strcmp(buf, "ieee80211n") == 0) {
  1952. conf->ieee80211n = atoi(pos);
  1953. } else if (os_strcmp(buf, "ht_capab") == 0) {
  1954. if (hostapd_config_ht_capab(conf, pos) < 0) {
  1955. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1956. "ht_capab", line);
  1957. errors++;
  1958. }
  1959. } else if (os_strcmp(buf, "require_ht") == 0) {
  1960. conf->require_ht = atoi(pos);
  1961. #endif /* CONFIG_IEEE80211N */
  1962. #ifdef CONFIG_IEEE80211AC
  1963. } else if (os_strcmp(buf, "ieee80211ac") == 0) {
  1964. conf->ieee80211ac = atoi(pos);
  1965. } else if (os_strcmp(buf, "vht_capab") == 0) {
  1966. if (hostapd_config_vht_capab(conf, pos) < 0) {
  1967. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1968. "vht_capab", line);
  1969. errors++;
  1970. }
  1971. } else if (os_strcmp(buf, "require_vht") == 0) {
  1972. conf->require_vht = atoi(pos);
  1973. } else if (os_strcmp(buf, "vht_oper_chwidth") == 0) {
  1974. conf->vht_oper_chwidth = atoi(pos);
  1975. } else if (os_strcmp(buf, "vht_oper_centr_freq_seg0_idx") == 0)
  1976. {
  1977. conf->vht_oper_centr_freq_seg0_idx = atoi(pos);
  1978. #endif /* CONFIG_IEEE80211AC */
  1979. } else if (os_strcmp(buf, "max_listen_interval") == 0) {
  1980. bss->max_listen_interval = atoi(pos);
  1981. } else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
  1982. bss->disable_pmksa_caching = atoi(pos);
  1983. } else if (os_strcmp(buf, "okc") == 0) {
  1984. bss->okc = atoi(pos);
  1985. #ifdef CONFIG_WPS
  1986. } else if (os_strcmp(buf, "wps_state") == 0) {
  1987. bss->wps_state = atoi(pos);
  1988. if (bss->wps_state < 0 || bss->wps_state > 2) {
  1989. wpa_printf(MSG_ERROR, "Line %d: invalid "
  1990. "wps_state", line);
  1991. errors++;
  1992. }
  1993. } else if (os_strcmp(buf, "ap_setup_locked") == 0) {
  1994. bss->ap_setup_locked = atoi(pos);
  1995. } else if (os_strcmp(buf, "uuid") == 0) {
  1996. if (uuid_str2bin(pos, bss->uuid)) {
  1997. wpa_printf(MSG_ERROR, "Line %d: invalid UUID",
  1998. line);
  1999. errors++;
  2000. }
  2001. } else if (os_strcmp(buf, "wps_pin_requests") == 0) {
  2002. os_free(bss->wps_pin_requests);
  2003. bss->wps_pin_requests = os_strdup(pos);
  2004. } else if (os_strcmp(buf, "device_name") == 0) {
  2005. if (os_strlen(pos) > 32) {
  2006. wpa_printf(MSG_ERROR, "Line %d: Too long "
  2007. "device_name", line);
  2008. errors++;
  2009. }
  2010. os_free(bss->device_name);
  2011. bss->device_name = os_strdup(pos);
  2012. } else if (os_strcmp(buf, "manufacturer") == 0) {
  2013. if (os_strlen(pos) > 64) {
  2014. wpa_printf(MSG_ERROR, "Line %d: Too long "
  2015. "manufacturer", line);
  2016. errors++;
  2017. }
  2018. os_free(bss->manufacturer);
  2019. bss->manufacturer = os_strdup(pos);
  2020. } else if (os_strcmp(buf, "model_name") == 0) {
  2021. if (os_strlen(pos) > 32) {
  2022. wpa_printf(MSG_ERROR, "Line %d: Too long "
  2023. "model_name", line);
  2024. errors++;
  2025. }
  2026. os_free(bss->model_name);
  2027. bss->model_name = os_strdup(pos);
  2028. } else if (os_strcmp(buf, "model_number") == 0) {
  2029. if (os_strlen(pos) > 32) {
  2030. wpa_printf(MSG_ERROR, "Line %d: Too long "
  2031. "model_number", line);
  2032. errors++;
  2033. }
  2034. os_free(bss->model_number);
  2035. bss->model_number = os_strdup(pos);
  2036. } else if (os_strcmp(buf, "serial_number") == 0) {
  2037. if (os_strlen(pos) > 32) {
  2038. wpa_printf(MSG_ERROR, "Line %d: Too long "
  2039. "serial_number", line);
  2040. errors++;
  2041. }
  2042. os_free(bss->serial_number);
  2043. bss->serial_number = os_strdup(pos);
  2044. } else if (os_strcmp(buf, "device_type") == 0) {
  2045. if (wps_dev_type_str2bin(pos, bss->device_type))
  2046. errors++;
  2047. } else if (os_strcmp(buf, "config_methods") == 0) {
  2048. os_free(bss->config_methods);
  2049. bss->config_methods = os_strdup(pos);
  2050. } else if (os_strcmp(buf, "os_version") == 0) {
  2051. if (hexstr2bin(pos, bss->os_version, 4)) {
  2052. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2053. "os_version", line);
  2054. errors++;
  2055. }
  2056. } else if (os_strcmp(buf, "ap_pin") == 0) {
  2057. os_free(bss->ap_pin);
  2058. bss->ap_pin = os_strdup(pos);
  2059. } else if (os_strcmp(buf, "skip_cred_build") == 0) {
  2060. bss->skip_cred_build = atoi(pos);
  2061. } else if (os_strcmp(buf, "extra_cred") == 0) {
  2062. os_free(bss->extra_cred);
  2063. bss->extra_cred =
  2064. (u8 *) os_readfile(pos, &bss->extra_cred_len);
  2065. if (bss->extra_cred == NULL) {
  2066. wpa_printf(MSG_ERROR, "Line %d: could not "
  2067. "read Credentials from '%s'",
  2068. line, pos);
  2069. errors++;
  2070. }
  2071. } else if (os_strcmp(buf, "wps_cred_processing") == 0) {
  2072. bss->wps_cred_processing = atoi(pos);
  2073. } else if (os_strcmp(buf, "ap_settings") == 0) {
  2074. os_free(bss->ap_settings);
  2075. bss->ap_settings =
  2076. (u8 *) os_readfile(pos, &bss->ap_settings_len);
  2077. if (bss->ap_settings == NULL) {
  2078. wpa_printf(MSG_ERROR, "Line %d: could not "
  2079. "read AP Settings from '%s'",
  2080. line, pos);
  2081. errors++;
  2082. }
  2083. } else if (os_strcmp(buf, "upnp_iface") == 0) {
  2084. bss->upnp_iface = os_strdup(pos);
  2085. } else if (os_strcmp(buf, "friendly_name") == 0) {
  2086. os_free(bss->friendly_name);
  2087. bss->friendly_name = os_strdup(pos);
  2088. } else if (os_strcmp(buf, "manufacturer_url") == 0) {
  2089. os_free(bss->manufacturer_url);
  2090. bss->manufacturer_url = os_strdup(pos);
  2091. } else if (os_strcmp(buf, "model_description") == 0) {
  2092. os_free(bss->model_description);
  2093. bss->model_description = os_strdup(pos);
  2094. } else if (os_strcmp(buf, "model_url") == 0) {
  2095. os_free(bss->model_url);
  2096. bss->model_url = os_strdup(pos);
  2097. } else if (os_strcmp(buf, "upc") == 0) {
  2098. os_free(bss->upc);
  2099. bss->upc = os_strdup(pos);
  2100. } else if (os_strcmp(buf, "pbc_in_m1") == 0) {
  2101. bss->pbc_in_m1 = atoi(pos);
  2102. #ifdef CONFIG_WPS_NFC
  2103. } else if (os_strcmp(buf, "wps_nfc_dev_pw_id") == 0) {
  2104. bss->wps_nfc_dev_pw_id = atoi(pos);
  2105. if (bss->wps_nfc_dev_pw_id < 0x10 ||
  2106. bss->wps_nfc_dev_pw_id > 0xffff) {
  2107. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2108. "wps_nfc_dev_pw_id value", line);
  2109. errors++;
  2110. }
  2111. } else if (os_strcmp(buf, "wps_nfc_dh_pubkey") == 0) {
  2112. wpabuf_free(bss->wps_nfc_dh_pubkey);
  2113. bss->wps_nfc_dh_pubkey = hostapd_parse_bin(pos);
  2114. } else if (os_strcmp(buf, "wps_nfc_dh_privkey") == 0) {
  2115. wpabuf_free(bss->wps_nfc_dh_privkey);
  2116. bss->wps_nfc_dh_privkey = hostapd_parse_bin(pos);
  2117. } else if (os_strcmp(buf, "wps_nfc_dev_pw") == 0) {
  2118. wpabuf_free(bss->wps_nfc_dev_pw);
  2119. bss->wps_nfc_dev_pw = hostapd_parse_bin(pos);
  2120. #endif /* CONFIG_WPS_NFC */
  2121. #endif /* CONFIG_WPS */
  2122. #ifdef CONFIG_P2P_MANAGER
  2123. } else if (os_strcmp(buf, "manage_p2p") == 0) {
  2124. int manage = atoi(pos);
  2125. if (manage)
  2126. bss->p2p |= P2P_MANAGE;
  2127. else
  2128. bss->p2p &= ~P2P_MANAGE;
  2129. } else if (os_strcmp(buf, "allow_cross_connection") == 0) {
  2130. if (atoi(pos))
  2131. bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
  2132. else
  2133. bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
  2134. #endif /* CONFIG_P2P_MANAGER */
  2135. } else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
  2136. bss->disassoc_low_ack = atoi(pos);
  2137. } else if (os_strcmp(buf, "tdls_prohibit") == 0) {
  2138. int val = atoi(pos);
  2139. if (val)
  2140. bss->tdls |= TDLS_PROHIBIT;
  2141. else
  2142. bss->tdls &= ~TDLS_PROHIBIT;
  2143. } else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
  2144. int val = atoi(pos);
  2145. if (val)
  2146. bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
  2147. else
  2148. bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
  2149. #ifdef CONFIG_RSN_TESTING
  2150. } else if (os_strcmp(buf, "rsn_testing") == 0) {
  2151. extern int rsn_testing;
  2152. rsn_testing = atoi(pos);
  2153. #endif /* CONFIG_RSN_TESTING */
  2154. } else if (os_strcmp(buf, "time_advertisement") == 0) {
  2155. bss->time_advertisement = atoi(pos);
  2156. } else if (os_strcmp(buf, "time_zone") == 0) {
  2157. size_t tz_len = os_strlen(pos);
  2158. if (tz_len < 4 || tz_len > 255) {
  2159. wpa_printf(MSG_DEBUG, "Line %d: invalid "
  2160. "time_zone", line);
  2161. errors++;
  2162. return errors;
  2163. }
  2164. os_free(bss->time_zone);
  2165. bss->time_zone = os_strdup(pos);
  2166. if (bss->time_zone == NULL)
  2167. errors++;
  2168. #ifdef CONFIG_INTERWORKING
  2169. } else if (os_strcmp(buf, "interworking") == 0) {
  2170. bss->interworking = atoi(pos);
  2171. } else if (os_strcmp(buf, "access_network_type") == 0) {
  2172. bss->access_network_type = atoi(pos);
  2173. if (bss->access_network_type < 0 ||
  2174. bss->access_network_type > 15) {
  2175. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2176. "access_network_type", line);
  2177. errors++;
  2178. }
  2179. } else if (os_strcmp(buf, "internet") == 0) {
  2180. bss->internet = atoi(pos);
  2181. } else if (os_strcmp(buf, "asra") == 0) {
  2182. bss->asra = atoi(pos);
  2183. } else if (os_strcmp(buf, "esr") == 0) {
  2184. bss->esr = atoi(pos);
  2185. } else if (os_strcmp(buf, "uesa") == 0) {
  2186. bss->uesa = atoi(pos);
  2187. } else if (os_strcmp(buf, "venue_group") == 0) {
  2188. bss->venue_group = atoi(pos);
  2189. bss->venue_info_set = 1;
  2190. } else if (os_strcmp(buf, "venue_type") == 0) {
  2191. bss->venue_type = atoi(pos);
  2192. bss->venue_info_set = 1;
  2193. } else if (os_strcmp(buf, "hessid") == 0) {
  2194. if (hwaddr_aton(pos, bss->hessid)) {
  2195. wpa_printf(MSG_ERROR, "Line %d: invalid "
  2196. "hessid", line);
  2197. errors++;
  2198. }
  2199. } else if (os_strcmp(buf, "roaming_consortium") == 0) {
  2200. if (parse_roaming_consortium(bss, pos, line) < 0)
  2201. errors++;
  2202. } else if (os_strcmp(buf, "venue_name") == 0) {
  2203. if (parse_venue_name(bss, pos, line) < 0)
  2204. errors++;
  2205. } else if (os_strcmp(buf, "network_auth_type") == 0) {
  2206. u8 auth_type;
  2207. u16 redirect_url_len;
  2208. if (hexstr2bin(pos, &auth_type, 1)) {
  2209. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2210. "network_auth_type '%s'",
  2211. line, pos);
  2212. errors++;
  2213. return errors;
  2214. }
  2215. if (auth_type == 0 || auth_type == 2)
  2216. redirect_url_len = os_strlen(pos + 2);
  2217. else
  2218. redirect_url_len = 0;
  2219. os_free(bss->network_auth_type);
  2220. bss->network_auth_type =
  2221. os_malloc(redirect_url_len + 3 + 1);
  2222. if (bss->network_auth_type == NULL) {
  2223. errors++;
  2224. return errors;
  2225. }
  2226. *bss->network_auth_type = auth_type;
  2227. WPA_PUT_LE16(bss->network_auth_type + 1,
  2228. redirect_url_len);
  2229. if (redirect_url_len)
  2230. os_memcpy(bss->network_auth_type + 3,
  2231. pos + 2, redirect_url_len);
  2232. bss->network_auth_type_len = 3 + redirect_url_len;
  2233. } else if (os_strcmp(buf, "ipaddr_type_availability") == 0) {
  2234. if (hexstr2bin(pos, &bss->ipaddr_type_availability, 1))
  2235. {
  2236. wpa_printf(MSG_ERROR, "Line %d: Invalid "
  2237. "ipaddr_type_availability '%s'",
  2238. line, pos);
  2239. bss->ipaddr_type_configured = 0;
  2240. errors++;
  2241. return errors;
  2242. }
  2243. bss->ipaddr_type_configured = 1;
  2244. } else if (os_strcmp(buf, "domain_name") == 0) {
  2245. int j, num_domains, domain_len, domain_list_len = 0;
  2246. char *tok_start, *tok_prev;
  2247. u8 *domain_list, *domain_ptr;
  2248. domain_list_len = os_strlen(pos) + 1;
  2249. domain_list = os_malloc(domain_list_len);
  2250. if (domain_list == NULL) {
  2251. errors++;
  2252. return errors;
  2253. }
  2254. domain_ptr = domain_list;
  2255. tok_prev = pos;
  2256. num_domains = 1;
  2257. while ((tok_prev = os_strchr(tok_prev, ','))) {
  2258. num_domains++;
  2259. tok_prev++;
  2260. }
  2261. tok_prev = pos;
  2262. for (j = 0; j < num_domains; j++) {
  2263. tok_start = os_strchr(tok_prev, ',');
  2264. if (tok_start) {
  2265. domain_len = tok_start - tok_prev;
  2266. *domain_ptr = domain_len;
  2267. os_memcpy(domain_ptr + 1, tok_prev,
  2268. domain_len);
  2269. domain_ptr += domain_len + 1;
  2270. tok_prev = ++tok_start;
  2271. } else {
  2272. domain_len = os_strlen(tok_prev);
  2273. *domain_ptr = domain_len;
  2274. os_memcpy(domain_ptr + 1, tok_prev,
  2275. domain_len);
  2276. domain_ptr += domain_len + 1;
  2277. }
  2278. }
  2279. os_free(bss->domain_name);
  2280. bss->domain_name = domain_list;
  2281. bss->domain_name_len = domain_list_len;
  2282. } else if (os_strcmp(buf, "gas_frag_limit") == 0) {
  2283. bss->gas_frag_limit = atoi(pos);
  2284. } else if (os_strcmp(buf, "gas_comeback_delay") == 0) {
  2285. bss->gas_comeback_delay = atoi(pos);
  2286. #endif /* CONFIG_INTERWORKING */
  2287. #ifdef CONFIG_RADIUS_TEST
  2288. } else if (os_strcmp(buf, "dump_msk_file") == 0) {
  2289. os_free(bss->dump_msk_file);
  2290. bss->dump_msk_file = os_strdup(pos);
  2291. #endif /* CONFIG_RADIUS_TEST */
  2292. #ifdef CONFIG_HS20
  2293. } else if (os_strcmp(buf, "hs20") == 0) {
  2294. bss->hs20 = atoi(pos);
  2295. } else if (os_strcmp(buf, "disable_dgaf") == 0) {
  2296. bss->disable_dgaf = atoi(pos);
  2297. #endif /* CONFIG_HS20 */
  2298. } else {
  2299. wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
  2300. "item '%s'", line, buf);
  2301. errors++;
  2302. }
  2303. }
  2304. return errors;
  2305. }
  2306. static void hostapd_set_security_params(struct hostapd_bss_config *bss)
  2307. {
  2308. int pairwise;
  2309. if (bss->individual_wep_key_len == 0) {
  2310. /* individual keys are not use; can use key idx0 for
  2311. * broadcast keys */
  2312. bss->broadcast_key_idx_min = 0;
  2313. }
  2314. /* Select group cipher based on the enabled pairwise cipher
  2315. * suites */
  2316. pairwise = 0;
  2317. if (bss->wpa & 1)
  2318. pairwise |= bss->wpa_pairwise;
  2319. if (bss->wpa & 2) {
  2320. if (bss->rsn_pairwise == 0)
  2321. bss->rsn_pairwise = bss->wpa_pairwise;
  2322. pairwise |= bss->rsn_pairwise;
  2323. }
  2324. if (pairwise & WPA_CIPHER_TKIP)
  2325. bss->wpa_group = WPA_CIPHER_TKIP;
  2326. else
  2327. bss->wpa_group = WPA_CIPHER_CCMP;
  2328. bss->radius->auth_server = bss->radius->auth_servers;
  2329. bss->radius->acct_server = bss->radius->acct_servers;
  2330. if (bss->wpa && bss->ieee802_1x) {
  2331. bss->ssid.security_policy = SECURITY_WPA;
  2332. } else if (bss->wpa) {
  2333. bss->ssid.security_policy = SECURITY_WPA_PSK;
  2334. } else if (bss->ieee802_1x) {
  2335. int cipher = WPA_CIPHER_NONE;
  2336. bss->ssid.security_policy = SECURITY_IEEE_802_1X;
  2337. bss->ssid.wep.default_len = bss->default_wep_key_len;
  2338. if (bss->default_wep_key_len)
  2339. cipher = bss->default_wep_key_len >= 13 ?
  2340. WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
  2341. bss->wpa_group = cipher;
  2342. bss->wpa_pairwise = cipher;
  2343. bss->rsn_pairwise = cipher;
  2344. } else if (bss->ssid.wep.keys_set) {
  2345. int cipher = WPA_CIPHER_WEP40;
  2346. if (bss->ssid.wep.len[0] >= 13)
  2347. cipher = WPA_CIPHER_WEP104;
  2348. bss->ssid.security_policy = SECURITY_STATIC_WEP;
  2349. bss->wpa_group = cipher;
  2350. bss->wpa_pairwise = cipher;
  2351. bss->rsn_pairwise = cipher;
  2352. } else {
  2353. bss->ssid.security_policy = SECURITY_PLAINTEXT;
  2354. bss->wpa_group = WPA_CIPHER_NONE;
  2355. bss->wpa_pairwise = WPA_CIPHER_NONE;
  2356. bss->rsn_pairwise = WPA_CIPHER_NONE;
  2357. }
  2358. }
  2359. /**
  2360. * hostapd_config_read - Read and parse a configuration file
  2361. * @fname: Configuration file name (including path, if needed)
  2362. * Returns: Allocated configuration data structure
  2363. */
  2364. struct hostapd_config * hostapd_config_read(const char *fname)
  2365. {
  2366. struct hostapd_config *conf;
  2367. struct hostapd_bss_config *bss;
  2368. FILE *f;
  2369. char buf[512], *pos;
  2370. int line = 0;
  2371. int errors = 0;
  2372. size_t i;
  2373. f = fopen(fname, "r");
  2374. if (f == NULL) {
  2375. wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
  2376. "for reading.", fname);
  2377. return NULL;
  2378. }
  2379. conf = hostapd_config_defaults();
  2380. if (conf == NULL) {
  2381. fclose(f);
  2382. return NULL;
  2383. }
  2384. /* set default driver based on configuration */
  2385. conf->driver = wpa_drivers[0];
  2386. if (conf->driver == NULL) {
  2387. wpa_printf(MSG_ERROR, "No driver wrappers registered!");
  2388. hostapd_config_free(conf);
  2389. fclose(f);
  2390. return NULL;
  2391. }
  2392. bss = conf->last_bss = conf->bss;
  2393. while (fgets(buf, sizeof(buf), f)) {
  2394. bss = conf->last_bss;
  2395. line++;
  2396. if (buf[0] == '#')
  2397. continue;
  2398. pos = buf;
  2399. while (*pos != '\0') {
  2400. if (*pos == '\n') {
  2401. *pos = '\0';
  2402. break;
  2403. }
  2404. pos++;
  2405. }
  2406. if (buf[0] == '\0')
  2407. continue;
  2408. pos = os_strchr(buf, '=');
  2409. if (pos == NULL) {
  2410. wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
  2411. line, buf);
  2412. errors++;
  2413. continue;
  2414. }
  2415. *pos = '\0';
  2416. pos++;
  2417. errors += hostapd_config_fill(conf, bss, buf, pos, line);
  2418. }
  2419. fclose(f);
  2420. for (i = 0; i < conf->num_bss; i++)
  2421. hostapd_set_security_params(&conf->bss[i]);
  2422. if (hostapd_config_check(conf))
  2423. errors++;
  2424. #ifndef WPA_IGNORE_CONFIG_ERRORS
  2425. if (errors) {
  2426. wpa_printf(MSG_ERROR, "%d errors found in configuration file "
  2427. "'%s'", errors, fname);
  2428. hostapd_config_free(conf);
  2429. conf = NULL;
  2430. }
  2431. #endif /* WPA_IGNORE_CONFIG_ERRORS */
  2432. return conf;
  2433. }
  2434. int hostapd_set_iface(struct hostapd_config *conf,
  2435. struct hostapd_bss_config *bss, char *field, char *value)
  2436. {
  2437. int errors;
  2438. size_t i;
  2439. errors = hostapd_config_fill(conf, bss, field, value, 0);
  2440. if (errors) {
  2441. wpa_printf(MSG_INFO, "Failed to set configuration field '%s' "
  2442. "to value '%s'", field, value);
  2443. return -1;
  2444. }
  2445. for (i = 0; i < conf->num_bss; i++)
  2446. hostapd_set_security_params(&conf->bss[i]);
  2447. if (hostapd_config_check(conf)) {
  2448. wpa_printf(MSG_ERROR, "Configuration check failed");
  2449. return -1;
  2450. }
  2451. return 0;
  2452. }