config_file.c 98 KB

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