config_file.c 73 KB

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