config_file.c 81 KB

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