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