config_file.c 100 KB

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