config_file.c 104 KB

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