config_file.c 89 KB

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