config_file.c 78 KB

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