config_file.c 84 KB

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